@lendasat/lendaswap-sdk-pure 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +113 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +201 -15
- package/dist/client.js.map +1 -1
- package/dist/create/evm-to-lightning.d.ts.map +1 -1
- package/dist/create/evm-to-lightning.js +7 -1
- package/dist/create/evm-to-lightning.js.map +1 -1
- package/dist/create/types.d.ts +10 -3
- package/dist/create/types.d.ts.map +1 -1
- package/dist/evm/coordinator.d.ts +75 -0
- package/dist/evm/coordinator.d.ts.map +1 -1
- package/dist/evm/coordinator.js +98 -0
- package/dist/evm/coordinator.js.map +1 -1
- package/dist/evm/index.d.ts +1 -1
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +1 -1
- package/dist/evm/index.js.map +1 -1
- package/dist/evm/signing.d.ts.map +1 -1
- package/dist/evm/signing.js +9 -32
- package/dist/evm/signing.js.map +1 -1
- package/dist/generated/api.d.ts +237 -0
- package/dist/generated/api.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type ApiClient, type Chain, type GetSwapResponse, type QuoteResponse, type TokenInfos } from "./api/client.js";
|
|
2
2
|
import { type VhtlcAmounts } from "./arkade.js";
|
|
3
3
|
import { type ArkadeToEvmSwapOptions, type ArkadeToEvmSwapResult, type BitcoinToArkadeSwapOptions, type BitcoinToArkadeSwapResult, type BitcoinToEvmSwapOptions, type BitcoinToEvmSwapResult, type CreateSwapOptions, type CreateSwapResult, type EvmToArkadeSwapGenericOptions, type EvmToArkadeSwapGenericResult, type EvmToBitcoinSwapOptions, type EvmToBitcoinSwapResult, type EvmToLightningSwapGenericOptions, type EvmToLightningSwapGenericResult, type LightningToEvmSwapGenericOptions, type LightningToEvmSwapGenericResult } from "./create";
|
|
4
|
-
import { type Permit2SignedFundingCallData, type UnsignedPermit2FundingData } from "./evm";
|
|
4
|
+
import { type CollabRefundEvmTypedData, type Permit2SignedFundingCallData, type UnsignedPermit2FundingData } from "./evm";
|
|
5
5
|
import { type ClaimGaslessResult, type ClaimResult } from "./redeem/index.js";
|
|
6
6
|
import { Signer, type SwapParams } from "./signer/index.js";
|
|
7
7
|
import { type StoredSwap, type SwapStorage, type WalletStorage } from "./storage";
|
|
8
8
|
export type { ArkadeToEvmSwapOptions, ArkadeToEvmSwapResult, BitcoinToArkadeSwapOptions, BitcoinToArkadeSwapResult, BitcoinToEvmSwapOptions, BitcoinToEvmSwapResponse, BitcoinToEvmSwapResult, BtcToEvmSwapOptions, CreateSwapOptions, CreateSwapResult, EvmChain, EvmToArkadeSwapGenericOptions, EvmToArkadeSwapGenericResult, EvmToArkadeSwapOptions, EvmToArkadeSwapResult, EvmToBitcoinSwapOptions, EvmToBitcoinSwapResult, EvmToLightningSwapOptions, } from "./create/index.js";
|
|
9
|
-
export { buildEip2612PermitDigest, buildPermit2FundingDigest, buildRedeemCalls, buildRedeemDigest, type CoordinatorCall, type Eip2612PermitParams, type ExecuteAndCreateWithPermit2Params, encodeExecuteAndCreateWithPermit2, encodeRedeemAndExecute, encodeRefundAndExecute, encodeRefundTo, PERMIT2_ADDRESS, type Permit2FundingParams, type Permit2SignedFundingCallData, type RedeemAndExecuteCallData, type RedeemAndExecuteParams, type RedeemDigestParams, type RefundAndExecuteParams, type RefundToParams, } from "./evm/index.js";
|
|
9
|
+
export { buildCollabRefundEvmDigest, buildCollabRefundEvmTypedData, buildEip2612PermitDigest, buildPermit2FundingDigest, buildRedeemCalls, buildRedeemDigest, type CollabRefundEvmDigestParams, type CollabRefundEvmTypedData, type CoordinatorCall, type Eip2612PermitParams, type ExecuteAndCreateWithPermit2Params, encodeExecuteAndCreateWithPermit2, encodeRedeemAndExecute, encodeRefundAndExecute, encodeRefundTo, PERMIT2_ADDRESS, type Permit2FundingParams, type Permit2SignedFundingCallData, type RedeemAndExecuteCallData, type RedeemAndExecuteParams, type RedeemDigestParams, type RefundAndExecuteParams, type RefundToParams, } from "./evm/index.js";
|
|
10
10
|
export type { ClaimGaslessResult, ClaimResult, CoordinatorClaimData, EthereumClaimData, } from "./redeem/index.js";
|
|
11
11
|
/** A support agent's Nostr identity */
|
|
12
12
|
export interface SupportAgentInfo {
|
|
@@ -63,11 +63,61 @@ export interface ArkadeRefundOptions {
|
|
|
63
63
|
/** Options for EVM refund via coordinator */
|
|
64
64
|
export interface EvmRefundOptions {
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
66
|
+
* Settlement mode — what asset you receive:
|
|
67
67
|
* - "swap-back" (default): Swap WBTC back to original token via DEX
|
|
68
|
-
* - "direct": Return WBTC directly
|
|
68
|
+
* - "direct": Return WBTC directly
|
|
69
69
|
*/
|
|
70
70
|
mode?: "swap-back" | "direct";
|
|
71
|
+
/**
|
|
72
|
+
* Whether to use collaborative refund (server cosigns + submits, gasless, no timelock wait).
|
|
73
|
+
* When false/undefined, the refund requires timelock expiry and the caller submits the tx.
|
|
74
|
+
* @default false
|
|
75
|
+
*/
|
|
76
|
+
collaborative?: boolean;
|
|
77
|
+
}
|
|
78
|
+
/** Result of a collaborative EVM refund */
|
|
79
|
+
export interface CollabRefundEvmResult {
|
|
80
|
+
/** Swap ID */
|
|
81
|
+
id: string;
|
|
82
|
+
/** On-chain transaction hash */
|
|
83
|
+
txHash: string;
|
|
84
|
+
/** Success message */
|
|
85
|
+
message: string;
|
|
86
|
+
}
|
|
87
|
+
/** Parameters for building CollabRefund EIP-712 typed data (returned by getCollabRefundEvmParams) */
|
|
88
|
+
export interface CollabRefundEvmParams {
|
|
89
|
+
/** HTLCCoordinator contract address (EIP-712 verifyingContract) */
|
|
90
|
+
coordinatorAddress: string;
|
|
91
|
+
/** Server's signer EOA address (the `caller` field in the EIP-712 struct) */
|
|
92
|
+
serverSignerAddress: string;
|
|
93
|
+
/** Preimage hash (0x-prefixed, 32-byte hex) */
|
|
94
|
+
preimageHash: string;
|
|
95
|
+
/** WBTC amount locked in the HTLC (decimal string) */
|
|
96
|
+
amount: string;
|
|
97
|
+
/** WBTC token address */
|
|
98
|
+
token: string;
|
|
99
|
+
/** Claim address (server's EVM address) */
|
|
100
|
+
claimAddress: string;
|
|
101
|
+
/** HTLC timelock (unix timestamp) */
|
|
102
|
+
timelock: number;
|
|
103
|
+
/** EVM chain ID */
|
|
104
|
+
chainId: number;
|
|
105
|
+
/** Settlement mode: "direct" or "swap-back" */
|
|
106
|
+
mode: string;
|
|
107
|
+
/** Token the depositor receives (WBTC for direct, source token for swap-back) — the EIP-712 `sweepToken` field */
|
|
108
|
+
sweepToken: string;
|
|
109
|
+
/** Minimum output amount for the sweep — the EIP-712 `minAmountOut` field */
|
|
110
|
+
minAmountOut: string;
|
|
111
|
+
/** keccak256(abi.encode(calls)) for the exact calls array signed in CollabRefund */
|
|
112
|
+
callsHash: string;
|
|
113
|
+
/** Source token address (only present for swap-back) */
|
|
114
|
+
sourceTokenAddress?: string;
|
|
115
|
+
/** DEX calldata for swap-back (only present when mode=swap-back) */
|
|
116
|
+
dexCalldata?: {
|
|
117
|
+
to: string;
|
|
118
|
+
data: string;
|
|
119
|
+
value: string;
|
|
120
|
+
};
|
|
71
121
|
}
|
|
72
122
|
/** General refund options — the method picks the right variant based on swap type */
|
|
73
123
|
export type RefundOptions = OnchainRefundOptions | ArkadeRefundOptions | EvmRefundOptions;
|
|
@@ -571,6 +621,65 @@ export declare class Client {
|
|
|
571
621
|
* ```
|
|
572
622
|
*/
|
|
573
623
|
refundSwap(id: string, options?: RefundOptions): Promise<RefundResult>;
|
|
624
|
+
/**
|
|
625
|
+
* Fetches the EIP-712 parameters for collaborative EVM HTLC refund.
|
|
626
|
+
*
|
|
627
|
+
* Returns the addresses and values needed to build the `CollabRefund`
|
|
628
|
+
* EIP-712 typed data that the depositor signs.
|
|
629
|
+
*
|
|
630
|
+
* @param swapId - Swap ID
|
|
631
|
+
* @returns CollabRefund parameters
|
|
632
|
+
*/
|
|
633
|
+
getCollabRefundEvmParams(swapId: string, settlement?: "swap-back" | "direct"): Promise<CollabRefundEvmParams>;
|
|
634
|
+
/**
|
|
635
|
+
* Builds the EIP-712 typed data for collaborative EVM refund.
|
|
636
|
+
*
|
|
637
|
+
* The depositor signs this with their wallet (via `eth_signTypedData_v4`
|
|
638
|
+
* or the SDK's `signEvmDigest`) to authorize the server to submit the
|
|
639
|
+
* refund on-chain.
|
|
640
|
+
*
|
|
641
|
+
* @param swapId - Swap ID
|
|
642
|
+
* @param settlement - Settlement mode: "direct" (WBTC) or "swap-back" (original token via DEX)
|
|
643
|
+
* @returns Typed data and digest for signing
|
|
644
|
+
*/
|
|
645
|
+
buildCollabRefundEvmTypedData(swapId: string, settlement?: "swap-back" | "direct"): Promise<{
|
|
646
|
+
typedData: CollabRefundEvmTypedData;
|
|
647
|
+
digest: string;
|
|
648
|
+
params: CollabRefundEvmParams;
|
|
649
|
+
}>;
|
|
650
|
+
/**
|
|
651
|
+
* Performs a collaborative EVM refund using the SDK's embedded wallet.
|
|
652
|
+
*
|
|
653
|
+
* The SDK signs the EIP-712 `CollabRefund` digest with the depositor's
|
|
654
|
+
* derived EVM key and POSTs to the server, which cosigns and submits
|
|
655
|
+
* the transaction on-chain. Gasless for the client — no timelock wait.
|
|
656
|
+
*
|
|
657
|
+
* @param swapId - Swap ID
|
|
658
|
+
* @param settlement - Settlement mode: "direct" (WBTC) or "swap-back" (original token via DEX)
|
|
659
|
+
* @returns Refund result with transaction hash
|
|
660
|
+
*/
|
|
661
|
+
collabRefundEvmSwap(swapId: string, settlement?: "swap-back" | "direct"): Promise<CollabRefundEvmResult>;
|
|
662
|
+
/**
|
|
663
|
+
* Submits a pre-signed collaborative EVM refund.
|
|
664
|
+
*
|
|
665
|
+
* Use this when an external wallet (e.g. MetaMask) signs the EIP-712
|
|
666
|
+
* `CollabRefund` digest instead of the SDK's embedded key.
|
|
667
|
+
* Call {@link buildCollabRefundEvmTypedData} first to obtain the typed data
|
|
668
|
+
* for the wallet to sign, then pass the resulting signature here.
|
|
669
|
+
*
|
|
670
|
+
* @param swapId - Swap ID
|
|
671
|
+
* @param body - Signed refund request (signature + refund parameters)
|
|
672
|
+
* @returns Refund result with transaction hash
|
|
673
|
+
*/
|
|
674
|
+
submitCollabRefundEvm(swapId: string, body: {
|
|
675
|
+
v: number;
|
|
676
|
+
r: string;
|
|
677
|
+
s: string;
|
|
678
|
+
depositor_address: string;
|
|
679
|
+
mode: "direct" | "swap-back";
|
|
680
|
+
sweep_token?: string;
|
|
681
|
+
min_amount_out: string;
|
|
682
|
+
}): Promise<CollabRefundEvmResult>;
|
|
574
683
|
/**
|
|
575
684
|
* Creates a swap by routing to the correct direction-specific method
|
|
576
685
|
* based on `sourceAsset.chain` and `targetAsset.chain`.
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EAGd,KAAK,KAAK,EAKV,KAAK,eAAe,EAEpB,KAAK,aAAa,EAClB,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAE3B,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAQrB,KAAK,6BAA6B,EAClC,KAAK,4BAA4B,EACjC,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,gCAAgC,EACrC,KAAK,+BAA+B,EACpC,KAAK,gCAAgC,EACrC,KAAK,+BAA+B,EACrC,MAAM,UAAU,CAAC;AAGlB,OAAO,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src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inToEvmSwap, createEvmToArkadeSwapGeneric, createEvmToBitcoinSwap, createEvmToLightningSwapGeneric, createLightningToEvmSwapGeneric, } from "./create";
|
|
4
4
|
import { delegateClaim, delegateRefund } from "./delegate.js";
|
|
5
5
|
import { broadcastTransaction, findOutputByAddress } from "./esplora.js";
|
|
6
|
-
import { buildEip2612PermitDigest, buildPermit2FundingDigest, buildPermit2TypedData, encodeApproveCallData, encodeExecuteAndCreateWithPermit2, encodeHtlcErc20RefundCallData, PERMIT2_ADDRESS, signEvmDigest, } from "./evm";
|
|
6
|
+
import { buildCollabRefundEvmDigest, buildCollabRefundEvmTypedData, buildEip2612PermitDigest, buildPermit2FundingDigest, buildPermit2TypedData, encodeApproveCallData, encodeExecuteAndCreateWithPermit2, encodeHtlcErc20RefundCallData, PERMIT2_ADDRESS, signEvmDigest, } from "./evm";
|
|
7
7
|
import { buildArkadeClaim, claimViaGasless as gaslessClaim, claim as redeemClaim, } from "./redeem/index.js";
|
|
8
8
|
import { buildArkadeRefund, buildOnchainClaimTransaction, buildOnchainRefundTransaction, collabRefundDelegate, collabRefundOffchain, verifyHtlcAddress, } from "./refund";
|
|
9
9
|
import { bytesToHex, hexToBytes, Signer, } from "./signer/index.js";
|
|
10
10
|
import { SWAP_STORAGE_VERSION, } from "./storage";
|
|
11
11
|
import { isArkade, isBtcOnchain, isEvmToken, isLightning } from "./tokens.js";
|
|
12
12
|
// Re-export coordinator utilities for Arkade-to-EVM redeemAndExecute flow
|
|
13
|
-
export { buildEip2612PermitDigest, buildPermit2FundingDigest, buildRedeemCalls, buildRedeemDigest, encodeExecuteAndCreateWithPermit2, encodeRedeemAndExecute, encodeRefundAndExecute, encodeRefundTo, PERMIT2_ADDRESS, } from "./evm/index.js";
|
|
13
|
+
export { buildCollabRefundEvmDigest, buildCollabRefundEvmTypedData, buildEip2612PermitDigest, buildPermit2FundingDigest, buildRedeemCalls, buildRedeemDigest, encodeExecuteAndCreateWithPermit2, encodeRedeemAndExecute, encodeRefundAndExecute, encodeRefundTo, PERMIT2_ADDRESS, } from "./evm/index.js";
|
|
14
14
|
const DEFAULT_BASE_URL = "https://api.lendaswap.com/";
|
|
15
15
|
/** Default Esplora URLs by network */
|
|
16
16
|
const DEFAULT_ESPLORA_URLS = {
|
|
@@ -1033,20 +1033,22 @@ export class Client {
|
|
|
1033
1033
|
if (direction === "bitcoin_to_evm" || direction === "btc_to_arkade") {
|
|
1034
1034
|
return this.#buildOnchainRefund(id, swap, options);
|
|
1035
1035
|
}
|
|
1036
|
-
// EVM-sourced swaps
|
|
1037
|
-
if (direction === "evm_to_arkade"
|
|
1036
|
+
// EVM-sourced swaps: collaborative refund or timelock-based refund
|
|
1037
|
+
if (direction === "evm_to_arkade" ||
|
|
1038
|
+
direction === "evm_to_bitcoin" ||
|
|
1039
|
+
direction === "evm_to_lightning") {
|
|
1038
1040
|
const evmOptions = options;
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
return this.#buildEvmToLightningRefund(id, swap,
|
|
1041
|
+
const settlement = evmOptions?.mode ?? "swap-back";
|
|
1042
|
+
if (evmOptions?.collaborative) {
|
|
1043
|
+
return this.#collabRefundEvm(id, settlement);
|
|
1044
|
+
}
|
|
1045
|
+
if (direction === "evm_to_arkade") {
|
|
1046
|
+
return this.#buildEvmToArkadeRefund(id, swap, settlement);
|
|
1047
|
+
}
|
|
1048
|
+
if (direction === "evm_to_bitcoin") {
|
|
1049
|
+
return this.#buildEvmToBitcoinRefund(id, swap, settlement);
|
|
1050
|
+
}
|
|
1051
|
+
return this.#buildEvmToLightningRefund(id, swap, settlement);
|
|
1050
1052
|
}
|
|
1051
1053
|
return {
|
|
1052
1054
|
success: false,
|
|
@@ -1845,6 +1847,171 @@ export class Client {
|
|
|
1845
1847
|
};
|
|
1846
1848
|
}
|
|
1847
1849
|
// =========================================================================
|
|
1850
|
+
// Collaborative EVM Refund
|
|
1851
|
+
// =========================================================================
|
|
1852
|
+
/**
|
|
1853
|
+
* Fetches the EIP-712 parameters for collaborative EVM HTLC refund.
|
|
1854
|
+
*
|
|
1855
|
+
* Returns the addresses and values needed to build the `CollabRefund`
|
|
1856
|
+
* EIP-712 typed data that the depositor signs.
|
|
1857
|
+
*
|
|
1858
|
+
* @param swapId - Swap ID
|
|
1859
|
+
* @returns CollabRefund parameters
|
|
1860
|
+
*/
|
|
1861
|
+
async getCollabRefundEvmParams(swapId, settlement = "direct") {
|
|
1862
|
+
const response = await this.#apiClient.GET("/api/swap/{id}/collab-refund-evm/params", {
|
|
1863
|
+
params: {
|
|
1864
|
+
path: { id: swapId },
|
|
1865
|
+
query: { mode: settlement },
|
|
1866
|
+
},
|
|
1867
|
+
});
|
|
1868
|
+
if (response.error) {
|
|
1869
|
+
throw new Error(`Failed to fetch collab refund params: ${response.error.error || "Unknown error"}`);
|
|
1870
|
+
}
|
|
1871
|
+
const d = response.data;
|
|
1872
|
+
return {
|
|
1873
|
+
coordinatorAddress: d.coordinator_address,
|
|
1874
|
+
serverSignerAddress: d.server_signer_address,
|
|
1875
|
+
preimageHash: d.preimage_hash,
|
|
1876
|
+
amount: d.amount,
|
|
1877
|
+
token: d.token,
|
|
1878
|
+
claimAddress: d.claim_address,
|
|
1879
|
+
timelock: d.timelock,
|
|
1880
|
+
chainId: d.chain_id,
|
|
1881
|
+
mode: d.mode,
|
|
1882
|
+
sweepToken: d.sweep_token,
|
|
1883
|
+
minAmountOut: d.min_amount_out,
|
|
1884
|
+
callsHash: d.calls_hash,
|
|
1885
|
+
sourceTokenAddress: d.source_token_address ?? undefined,
|
|
1886
|
+
dexCalldata: d.dex_calldata
|
|
1887
|
+
? {
|
|
1888
|
+
to: d.dex_calldata.to,
|
|
1889
|
+
data: d.dex_calldata.data,
|
|
1890
|
+
value: d.dex_calldata.value,
|
|
1891
|
+
}
|
|
1892
|
+
: undefined,
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Builds the EIP-712 typed data for collaborative EVM refund.
|
|
1897
|
+
*
|
|
1898
|
+
* The depositor signs this with their wallet (via `eth_signTypedData_v4`
|
|
1899
|
+
* or the SDK's `signEvmDigest`) to authorize the server to submit the
|
|
1900
|
+
* refund on-chain.
|
|
1901
|
+
*
|
|
1902
|
+
* @param swapId - Swap ID
|
|
1903
|
+
* @param settlement - Settlement mode: "direct" (WBTC) or "swap-back" (original token via DEX)
|
|
1904
|
+
* @returns Typed data and digest for signing
|
|
1905
|
+
*/
|
|
1906
|
+
async buildCollabRefundEvmTypedData(swapId, settlement = "direct") {
|
|
1907
|
+
const params = await this.getCollabRefundEvmParams(swapId, settlement);
|
|
1908
|
+
const digestParams = {
|
|
1909
|
+
coordinatorAddress: params.coordinatorAddress,
|
|
1910
|
+
chainId: params.chainId,
|
|
1911
|
+
preimageHash: params.preimageHash,
|
|
1912
|
+
amount: BigInt(params.amount),
|
|
1913
|
+
token: params.token,
|
|
1914
|
+
claimAddress: params.claimAddress,
|
|
1915
|
+
timelock: params.timelock,
|
|
1916
|
+
caller: params.serverSignerAddress,
|
|
1917
|
+
sweepToken: params.sweepToken,
|
|
1918
|
+
minAmountOut: BigInt(params.minAmountOut),
|
|
1919
|
+
callsHash: params.callsHash,
|
|
1920
|
+
};
|
|
1921
|
+
const typedData = buildCollabRefundEvmTypedData(digestParams);
|
|
1922
|
+
const digest = buildCollabRefundEvmDigest(digestParams);
|
|
1923
|
+
return { typedData, digest, params };
|
|
1924
|
+
}
|
|
1925
|
+
/**
|
|
1926
|
+
* Performs a collaborative EVM refund using the SDK's embedded wallet.
|
|
1927
|
+
*
|
|
1928
|
+
* The SDK signs the EIP-712 `CollabRefund` digest with the depositor's
|
|
1929
|
+
* derived EVM key and POSTs to the server, which cosigns and submits
|
|
1930
|
+
* the transaction on-chain. Gasless for the client — no timelock wait.
|
|
1931
|
+
*
|
|
1932
|
+
* @param swapId - Swap ID
|
|
1933
|
+
* @param settlement - Settlement mode: "direct" (WBTC) or "swap-back" (original token via DEX)
|
|
1934
|
+
* @returns Refund result with transaction hash
|
|
1935
|
+
*/
|
|
1936
|
+
async collabRefundEvmSwap(swapId, settlement = "direct") {
|
|
1937
|
+
const { params, digest } = await this.buildCollabRefundEvmTypedData(swapId, settlement);
|
|
1938
|
+
// Sign using the SDK's stored EVM secret key for this swap
|
|
1939
|
+
const storedSwap = await this.getStoredSwap(swapId);
|
|
1940
|
+
if (!storedSwap?.secretKey) {
|
|
1941
|
+
throw new Error("No secret key found for this swap. Cannot sign collab refund.");
|
|
1942
|
+
}
|
|
1943
|
+
const sig = signEvmDigest(storedSwap.secretKey, digest);
|
|
1944
|
+
// Derive the on-chain depositor address (the key that funded the HTLC)
|
|
1945
|
+
const { deriveEvmAddress } = await import("./evm/signing.js");
|
|
1946
|
+
const depositorAddress = deriveEvmAddress(storedSwap.secretKey);
|
|
1947
|
+
// POST to the server
|
|
1948
|
+
const response = await this.#apiClient.POST("/api/swap/{id}/collab-refund-evm", {
|
|
1949
|
+
params: { path: { id: swapId } },
|
|
1950
|
+
body: {
|
|
1951
|
+
v: sig.v,
|
|
1952
|
+
r: sig.r,
|
|
1953
|
+
s: sig.s,
|
|
1954
|
+
depositor_address: depositorAddress,
|
|
1955
|
+
mode: settlement,
|
|
1956
|
+
sweep_token: params.sweepToken,
|
|
1957
|
+
min_amount_out: params.minAmountOut,
|
|
1958
|
+
},
|
|
1959
|
+
});
|
|
1960
|
+
if (response.error) {
|
|
1961
|
+
throw new Error(`Collaborative EVM refund failed: ${response.error.error || "Unknown error"}`);
|
|
1962
|
+
}
|
|
1963
|
+
return {
|
|
1964
|
+
id: response.data.id,
|
|
1965
|
+
txHash: response.data.tx_hash,
|
|
1966
|
+
message: response.data.message,
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
/**
|
|
1970
|
+
* Submits a pre-signed collaborative EVM refund.
|
|
1971
|
+
*
|
|
1972
|
+
* Use this when an external wallet (e.g. MetaMask) signs the EIP-712
|
|
1973
|
+
* `CollabRefund` digest instead of the SDK's embedded key.
|
|
1974
|
+
* Call {@link buildCollabRefundEvmTypedData} first to obtain the typed data
|
|
1975
|
+
* for the wallet to sign, then pass the resulting signature here.
|
|
1976
|
+
*
|
|
1977
|
+
* @param swapId - Swap ID
|
|
1978
|
+
* @param body - Signed refund request (signature + refund parameters)
|
|
1979
|
+
* @returns Refund result with transaction hash
|
|
1980
|
+
*/
|
|
1981
|
+
async submitCollabRefundEvm(swapId, body) {
|
|
1982
|
+
const response = await this.#apiClient.POST("/api/swap/{id}/collab-refund-evm", {
|
|
1983
|
+
params: { path: { id: swapId } },
|
|
1984
|
+
body,
|
|
1985
|
+
});
|
|
1986
|
+
if (response.error) {
|
|
1987
|
+
throw new Error(`Collaborative EVM refund failed: ${response.error.error || "Unknown error"}`);
|
|
1988
|
+
}
|
|
1989
|
+
return {
|
|
1990
|
+
id: response.data.id,
|
|
1991
|
+
txHash: response.data.tx_hash,
|
|
1992
|
+
message: response.data.message,
|
|
1993
|
+
};
|
|
1994
|
+
}
|
|
1995
|
+
/**
|
|
1996
|
+
* Collaborative EVM refund — internal method called by refundSwap.
|
|
1997
|
+
* @internal
|
|
1998
|
+
*/
|
|
1999
|
+
async #collabRefundEvm(id, settlement = "direct") {
|
|
2000
|
+
try {
|
|
2001
|
+
const result = await this.collabRefundEvmSwap(id, settlement);
|
|
2002
|
+
return {
|
|
2003
|
+
success: true,
|
|
2004
|
+
message: `${result.message} (tx: ${result.txHash})`,
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
catch (error) {
|
|
2008
|
+
return {
|
|
2009
|
+
success: false,
|
|
2010
|
+
message: `Collaborative EVM refund failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
// =========================================================================
|
|
1848
2015
|
// Swap Creation - BTC to EVM
|
|
1849
2016
|
// =========================================================================
|
|
1850
2017
|
/**
|
|
@@ -1991,6 +2158,25 @@ export class Client {
|
|
|
1991
2158
|
if (!options.userAddress && !options.gasless) {
|
|
1992
2159
|
throw new Error("userAddress is required for EVM → Lightning swaps (unless gasless)");
|
|
1993
2160
|
}
|
|
2161
|
+
// Detect whether targetAddress is a Lightning address (user@domain)
|
|
2162
|
+
// or a BOLT11 invoice (starts with ln...).
|
|
2163
|
+
const isAddress = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(options.targetAddress);
|
|
2164
|
+
if (isAddress) {
|
|
2165
|
+
if (options.targetAmount == null ||
|
|
2166
|
+
!Number.isFinite(options.targetAmount) ||
|
|
2167
|
+
options.targetAmount <= 0) {
|
|
2168
|
+
throw new Error("targetAmount (in sats) is required when using a Lightning address");
|
|
2169
|
+
}
|
|
2170
|
+
return this.createEvmToLightningSwapGeneric({
|
|
2171
|
+
lightningAddress: options.targetAddress,
|
|
2172
|
+
amountSats: options.targetAmount,
|
|
2173
|
+
evmChainId: Number(sourceChain),
|
|
2174
|
+
tokenAddress: sourceAsset.token_id,
|
|
2175
|
+
userAddress: options.userAddress ?? "",
|
|
2176
|
+
referralCode: options.referralCode,
|
|
2177
|
+
gasless: options.gasless,
|
|
2178
|
+
});
|
|
2179
|
+
}
|
|
1994
2180
|
return this.createEvmToLightningSwapGeneric({
|
|
1995
2181
|
lightningInvoice: options.targetAddress,
|
|
1996
2182
|
evmChainId: Number(sourceChain),
|