Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"./starknet-functions": "./dist/functions/starknet/index.js"
},
"scripts": {
"prepare": "npm run build",
"clean": "rm -rf dist && rm -rf node_modules",
"build": "rm -rf dist && tsc",
"test": "jest",
Expand Down
6 changes: 4 additions & 2 deletions src/dlc-handlers/abstract-dlc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ export abstract class AbstractDLCHandler {
fundingTransactionID: string,
feeRecipient: string,
feeRateMultiplier?: number,
customFeeRate?: bigint
customFeeRate?: bigint,
destinationAddress?: string
): Promise<Transaction> {
const { fundingPayment, multisigPayment } = await this.createPaymentInformation(
vault.uuid,
Expand All @@ -200,7 +201,8 @@ export abstract class AbstractDLCHandler {
fundingPayment,
feeRate,
feeRecipient,
vault.btcRedeemFeeBasisPoints.toBigInt()
vault.btcRedeemFeeBasisPoints.toBigInt(),
destinationAddress
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/dlc-handlers/ledger-dlc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ export class LedgerDLCHandler extends AbstractDLCHandler {
fundingTransactionID: string,
feeRecipient: string,
feeRateMultiplier?: number,
customFeeRate?: bigint
customFeeRate?: bigint,
destinationAddress?: string
): Promise<Transaction> {
try {
const { fundingPayment, taprootDerivedPublicKey, multisigPayment } = await this.createPayment(
Expand All @@ -337,7 +338,8 @@ export class LedgerDLCHandler extends AbstractDLCHandler {
fundingPayment,
feeRate,
feeRecipient,
vault.btcRedeemFeeBasisPoints.toBigInt()
vault.btcRedeemFeeBasisPoints.toBigInt(),
destinationAddress
);

const withdrawTransactionSigningConfiguration = createBitcoinInputSigningConfiguration(
Expand Down
11 changes: 7 additions & 4 deletions src/functions/bitcoin/psbt-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,19 @@ export async function createDepositTransaction(
/**
* Creates a Withdraw Transaction to withdraw Bitcoin from a Vault.
* Uses the existing Vault's Funding Transaction ID to create the Withdraw Transaction.
* The specified amount of Bitcoin is sent to the User's Address.
* The specified amount of Bitcoin is sent to the User's Address (or custom destination if provided).
* The remaining amount is sent back to the Vault's Multisig Address.
*
* @param bitcoinBlockchainURL - The Bitcoin Blockchain URL used to fetch the Vault's Funding Transaction.
* @param bitcoinNetwork - The Bitcoin Network to use.
* @param withdrawAmount - The amount of Bitcoin to withdraw from the Vault.
* @param vaultTransactionID - The ID of the Vault Funding Transaction.
* @param multisigPayment - The Multisig Payment object created from the User's Taproot Public Key, the Attestor's Public Key, and the Unspendable Public Key committed to the Vault's UUID.
* @param withdrawPayment - The User's Payment object which will be used to receive the withdrawn Bitcoin.
* @param withdrawPayment - The User's Payment object which will be used to receive the withdrawn Bitcoin (if no custom destination is provided).
* @param feeRate - The Fee Rate to use for the Transaction.
* @param feeRecipient - The Fee Recipient's Public Key or Address.
* @param feeBasisPoints - The Fee Basis Points.
* @param destinationAddress - Optional custom destination address for the withdrawn Bitcoin. If not provided, uses the withdrawPayment address.
* @returns A Withdraw Transaction.
*/
export async function createWithdrawTransaction(
Expand All @@ -267,15 +268,17 @@ export async function createWithdrawTransaction(
withdrawPayment: P2Ret | P2TROut,
feeRate: bigint,
feeRecipient: string,
feeBasisPoints: bigint
feeBasisPoints: bigint,
destinationAddress?: string
): Promise<Transaction> {
const multisigAddress = multisigPayment.address;

if (!multisigAddress) {
throw new Error('Multisig Transaction is missing Address');
}

const withdrawAddress = withdrawPayment.address;
// Use custom destination address if provided, otherwise use the withdraw payment address
const withdrawAddress = destinationAddress ?? withdrawPayment.address;

if (!withdrawAddress) {
throw new Error('Withdraw Payment is missing Address');
Expand Down
Loading