Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NUT-15] MultiPath Melt Quotes #232

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/CashuWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import {
type SendResponse,
type SerializedBlindedMessage,
type SwapPayload,
type Token
type Token,
MPPOption,
MeltQuoteOptions
} from './model/types/index.js';
import { SubscriptionCanceller } from './model/types/wallet/websocket.js';
import {
Expand Down Expand Up @@ -671,6 +673,44 @@ class CashuWallet {
return meltQuote;
}

/**
* Requests a multi path melt quote from the mint.
* @param invoice LN invoice that needs to get a fee estimate
* @param partialAmount the partial amount of the invoice's total to be paid by this instance
* @returns the mint will create and return a melt quote for the invoice with an amount and fee reserve
*/
async createMultiPathMeltQuote(
invoice: string,
partialAmount: number
): Promise<MeltQuoteResponse> {
const { supported, params } = this.mintInfo.isSupported(15);
if (!supported) {
throw new Error('Mint does not support NUT-15');
}
if (
!params?.filter((method) => {
if (method.method === 'bolt11' && method.unit === this.unit) {
return true;
}
}).length
) {
throw new Error(`Mint does not support MPP for bolt11 and ${this.unit}`);
}
const mppOption: MPPOption = {
amount: partialAmount
};
const meltOptions: MeltQuoteOptions = {
mpp: mppOption
};
const meltQuotePayload: MeltQuotePayload = {
unit: this._unit,
request: invoice,
options: meltOptions
};
const meltQuote = await this.mint.createMeltQuote(meltQuotePayload);
return meltQuote;
}

/**
* Return an existing melt quote from the mint.
* @param quote ID of the melt quote
Expand Down
18 changes: 18 additions & 0 deletions src/model/types/wallet/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ export type MeltQuotePayload = {
* Request to be melted to
*/
request: string;
/**
* Melt Quote options (e.g. multi-path payments NUT-15)
*/
options?: MeltQuoteOptions;
};

/**
* Melt quote specific options
*/
export type MeltQuoteOptions = {
mpp: MPPOption;
};

/**
* Multi path payments option
*/
export type MPPOption = {
amount: number;
};

/**
Expand Down
Loading