@satora/swap 1.11.1 → 1.13.0
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/bitcoin-reader-electrum-2N4LJCGD.cjs +9 -0
- package/dist/{bitcoin-reader-electrum-VCQ5TQ44.cjs.map → bitcoin-reader-electrum-2N4LJCGD.cjs.map} +1 -1
- package/dist/bitcoin-reader-electrum-VLYRII3T.js +9 -0
- package/dist/bitcoin-reader-esplora-CAR4P52J.cjs +16 -0
- package/dist/bitcoin-reader-esplora-CAR4P52J.cjs.map +1 -0
- package/dist/{bitcoin-reader-esplora-CGPF4H5Y.js → bitcoin-reader-esplora-LC673MQT.js} +4 -2
- package/dist/{chunk-WQMAL2VD.js → chunk-34OYIFOU.js} +764 -141
- package/dist/chunk-34OYIFOU.js.map +1 -0
- package/dist/{chunk-4NVWIR74.cjs → chunk-3633KDTW.cjs} +1128 -505
- package/dist/chunk-3633KDTW.cjs.map +1 -0
- package/dist/{chunk-LSCRTQOS.js → chunk-CUYLQTRF.js} +15 -20
- package/dist/chunk-CUYLQTRF.js.map +1 -0
- package/dist/{chunk-INHFP222.cjs → chunk-CY5M5X6S.cjs} +28 -30
- package/dist/chunk-CY5M5X6S.cjs.map +1 -0
- package/dist/{chunk-JZTF4JNH.cjs → chunk-EI5ILLQ3.cjs} +2 -2
- package/dist/{chunk-JZTF4JNH.cjs.map → chunk-EI5ILLQ3.cjs.map} +1 -1
- package/dist/{chunk-5DQHR3RO.cjs → chunk-FJS6RGUR.cjs} +16 -21
- package/dist/chunk-FJS6RGUR.cjs.map +1 -0
- package/dist/{chunk-3ZMSZSAV.js → chunk-I2NF63VZ.js} +27 -29
- package/dist/chunk-I2NF63VZ.js.map +1 -0
- package/dist/{chunk-JHZHRY7S.js → chunk-K2Q4JWB6.js} +2 -2
- package/dist/{chunk-JHZHRY7S.js.map → chunk-K2Q4JWB6.js.map} +1 -1
- package/dist/{chunk-TT3J2OOS.js → chunk-KMBGRQS7.js} +5 -5
- package/dist/{chunk-TT3J2OOS.js.map → chunk-KMBGRQS7.js.map} +1 -1
- package/dist/{chunk-Q4TOBBAN.cjs → chunk-LZQZYSOZ.cjs} +5 -5
- package/dist/{chunk-Q4TOBBAN.cjs.map → chunk-LZQZYSOZ.cjs.map} +1 -1
- package/dist/delegate.cjs +2 -2
- package/dist/delegate.js +1 -1
- package/dist/{dist-SHY7I6SH.js → dist-3N76II5O.js} +16 -4
- package/dist/dist-KQINAMDC.cjs +406 -0
- package/dist/{dist-MHRQ5FFV.cjs.map → dist-KQINAMDC.cjs.map} +1 -1
- package/dist/{fundSwap-UBCHMUP4-BEMQNSFQ.cjs → fundSwap-2D4IPYU4-4NELKB3Q.cjs} +7 -7
- package/dist/{fundSwap-UBCHMUP4-BEMQNSFQ.cjs.map → fundSwap-2D4IPYU4-4NELKB3Q.cjs.map} +1 -1
- package/dist/{fundSwap-UBCHMUP4-WBLYE6MC.js → fundSwap-2D4IPYU4-CDM3WRUF.js} +3 -3
- package/dist/index.cjs +41 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -11
- package/dist/index.js.map +1 -1
- package/dist/node.cjs +26 -5
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +26 -5
- package/dist/node.js.map +1 -1
- package/dist/types/cjs/pure/api/client.d.cts +1 -0
- package/dist/types/cjs/pure/client.d.cts +44 -12
- package/dist/types/cjs/pure/compose-quote.d.cts +14 -1
- package/dist/types/cjs/pure/create/bitcoin-payout.d.cts +17 -0
- package/dist/types/cjs/pure/create/evm-to-arkade.d.cts +0 -5
- package/dist/types/cjs/pure/create/evm-to-lightning.d.cts +0 -8
- package/dist/types/cjs/pure/create/funding-terms.d.cts +2 -1
- package/dist/types/cjs/pure/create/index.d.cts +2 -1
- package/dist/types/cjs/pure/create/payment-safety.d.cts +2 -0
- package/dist/types/cjs/pure/create/payout-slippage.d.cts +29 -0
- package/dist/types/cjs/pure/create/spark-to-evm.d.cts +7 -0
- package/dist/types/cjs/pure/create/types.d.cts +102 -3
- package/dist/types/cjs/pure/esplora.d.cts +2 -0
- package/dist/types/cjs/pure/evm/funding-pins.d.cts +2 -0
- package/dist/types/cjs/pure/generated/api.d.cts +352 -2
- package/dist/types/cjs/pure/index.d.cts +6 -4
- package/dist/types/cjs/pure/refund/onchain.d.cts +4 -0
- package/dist/types/cjs/pure/storage/index.d.cts +1 -1
- package/dist/types/cjs/pure/storage/types.d.cts +22 -0
- package/dist/types/cjs/pure/swap-verification.d.cts +3 -1
- package/dist/types/cjs/pure/tokens.d.cts +5 -0
- package/dist/types/cjs/pure/types/chain.d.cts +2 -2
- package/dist/types/cjs/pure/types/index.d.cts +1 -0
- package/dist/types/cjs/pure/types/promo-code.d.cts +15 -0
- package/dist/types/cjs/pure/types/quote.d.cts +7 -0
- package/dist/types/cjs/pure/types/referral-fee.d.cts +8 -0
- package/dist/types/cjs/pure/version.d.cts +4 -4
- package/dist/types/cjs/swap/client.d.cts +2 -0
- package/dist/types/cjs/swap/contracts/bitcoin-reader-esplora.d.cts +5 -0
- package/dist/types/esm/pure/api/client.d.ts +1 -0
- package/dist/types/esm/pure/client.d.ts +44 -12
- package/dist/types/esm/pure/compose-quote.d.ts +14 -1
- package/dist/types/esm/pure/create/bitcoin-payout.d.ts +17 -0
- package/dist/types/esm/pure/create/evm-to-arkade.d.ts +0 -5
- package/dist/types/esm/pure/create/evm-to-lightning.d.ts +0 -8
- package/dist/types/esm/pure/create/funding-terms.d.ts +2 -1
- package/dist/types/esm/pure/create/index.d.ts +2 -1
- package/dist/types/esm/pure/create/payment-safety.d.ts +2 -0
- package/dist/types/esm/pure/create/payout-slippage.d.ts +29 -0
- package/dist/types/esm/pure/create/spark-to-evm.d.ts +7 -0
- package/dist/types/esm/pure/create/types.d.ts +102 -3
- package/dist/types/esm/pure/esplora.d.ts +2 -0
- package/dist/types/esm/pure/evm/funding-pins.d.ts +2 -0
- package/dist/types/esm/pure/generated/api.d.ts +352 -2
- package/dist/types/esm/pure/index.d.ts +6 -4
- package/dist/types/esm/pure/refund/onchain.d.ts +4 -0
- package/dist/types/esm/pure/storage/index.d.ts +1 -1
- package/dist/types/esm/pure/storage/types.d.ts +22 -0
- package/dist/types/esm/pure/swap-verification.d.ts +3 -1
- package/dist/types/esm/pure/tokens.d.ts +5 -0
- package/dist/types/esm/pure/types/chain.d.ts +2 -2
- package/dist/types/esm/pure/types/index.d.ts +1 -0
- package/dist/types/esm/pure/types/promo-code.d.ts +15 -0
- package/dist/types/esm/pure/types/quote.d.ts +7 -0
- package/dist/types/esm/pure/types/referral-fee.d.ts +8 -0
- package/dist/types/esm/pure/version.d.ts +4 -4
- package/dist/types/esm/swap/client.d.ts +2 -0
- package/dist/types/esm/swap/contracts/bitcoin-reader-esplora.d.ts +5 -0
- package/package.json +2 -2
- package/dist/bitcoin-reader-electrum-4PNSDHIA.js +0 -9
- package/dist/bitcoin-reader-electrum-VCQ5TQ44.cjs +0 -9
- package/dist/bitcoin-reader-esplora-6RH7S4BR.cjs +0 -14
- package/dist/bitcoin-reader-esplora-6RH7S4BR.cjs.map +0 -1
- package/dist/chunk-3ZMSZSAV.js.map +0 -1
- package/dist/chunk-4NVWIR74.cjs.map +0 -1
- package/dist/chunk-5DQHR3RO.cjs.map +0 -1
- package/dist/chunk-INHFP222.cjs.map +0 -1
- package/dist/chunk-LSCRTQOS.js.map +0 -1
- package/dist/chunk-WQMAL2VD.js.map +0 -1
- package/dist/dist-MHRQ5FFV.cjs +0 -394
- /package/dist/{bitcoin-reader-electrum-4PNSDHIA.js.map → bitcoin-reader-electrum-VLYRII3T.js.map} +0 -0
- /package/dist/{bitcoin-reader-esplora-CGPF4H5Y.js.map → bitcoin-reader-esplora-LC673MQT.js.map} +0 -0
- /package/dist/{dist-SHY7I6SH.js.map → dist-3N76II5O.js.map} +0 -0
- /package/dist/{fundSwap-UBCHMUP4-WBLYE6MC.js.map → fundSwap-2D4IPYU4-CDM3WRUF.js.map} +0 -0
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
var
|
|
42
|
+
var _chunkEI5ILLQ3cjs = require('./chunk-EI5ILLQ3.cjs');
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
|
|
@@ -115,7 +115,7 @@ var _chunkTNZW35XAcjs = require('./chunk-TNZW35XA.cjs');
|
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
|
|
118
|
-
var
|
|
118
|
+
var _chunkLZQZYSOZcjs = require('./chunk-LZQZYSOZ.cjs');
|
|
119
119
|
|
|
120
120
|
|
|
121
121
|
|
|
@@ -158,6 +158,7 @@ var _chunk5JR6AJ3Ycjs = require('./chunk-5JR6AJ3Y.cjs');
|
|
|
158
158
|
|
|
159
159
|
|
|
160
160
|
|
|
161
|
+
|
|
161
162
|
var _chunkRYZSWESUcjs = require('./chunk-RYZSWESU.cjs');
|
|
162
163
|
|
|
163
164
|
|
|
@@ -6848,8 +6849,8 @@ function removeTrailingSlash(url) {
|
|
|
6848
6849
|
}
|
|
6849
6850
|
function createApiClient(options) {
|
|
6850
6851
|
const headers = {
|
|
6851
|
-
"X-Lendaswap-Client":
|
|
6852
|
-
...
|
|
6852
|
+
"X-Lendaswap-Client": _chunkLZQZYSOZcjs.CLIENT_AGENT,
|
|
6853
|
+
..._chunkLZQZYSOZcjs.PROTOCOL_HEADERS,
|
|
6853
6854
|
..._nullishCoalesce(options.defaultHeaders, () => ( {}))
|
|
6854
6855
|
};
|
|
6855
6856
|
return createClient({
|
|
@@ -6862,7 +6863,7 @@ async function getVhtlcAmounts(params) {
|
|
|
6862
6863
|
const { vhtlcAddress, network, arkadeServerUrl } = params;
|
|
6863
6864
|
const decoded = _chunkBEW62OUTcjs.ArkAddress.decode(vhtlcAddress);
|
|
6864
6865
|
const pkScript = _chunkRYZSWESUcjs.hex.encode(decoded.pkScript);
|
|
6865
|
-
const serverUrl =
|
|
6866
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrl.call(void 0, network, arkadeServerUrl);
|
|
6866
6867
|
const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
|
|
6867
6868
|
const [spendableResult, spentResult, recoverableResult] = await Promise.all([
|
|
6868
6869
|
indexerProvider.getVtxos({ scripts: [pkScript], spendableOnly: true }),
|
|
@@ -6897,7 +6898,7 @@ function parseArkadeAddress(address2, network) {
|
|
|
6897
6898
|
throw new Error(`Invalid Arkade address: ${reason}`);
|
|
6898
6899
|
}
|
|
6899
6900
|
if (network !== void 0) {
|
|
6900
|
-
const expectedHrp =
|
|
6901
|
+
const expectedHrp = _chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, _chunkLZQZYSOZcjs.getNetworkName.call(void 0, network));
|
|
6901
6902
|
if (decoded.hrp !== expectedHrp) {
|
|
6902
6903
|
throw new Error(
|
|
6903
6904
|
`Arkade address has wrong network: expected "${expectedHrp}1..." prefix, got "${decoded.hrp}1..."`
|
|
@@ -7193,7 +7194,7 @@ function ensureBytes32(value) {
|
|
|
7193
7194
|
);
|
|
7194
7195
|
}
|
|
7195
7196
|
function keccak256Hex(input) {
|
|
7196
|
-
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0,
|
|
7197
|
+
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkEI5ILLQ3cjs.keccak_256.call(void 0, new TextEncoder().encode(input)))}`;
|
|
7197
7198
|
}
|
|
7198
7199
|
function encodeUint256(value) {
|
|
7199
7200
|
if (value < 0n) throw new Error("uint256 cannot be negative");
|
|
@@ -7323,7 +7324,7 @@ async function cctpFundSwap(context, params) {
|
|
|
7323
7324
|
const source = cctpMetaForChainId(signer.chainId);
|
|
7324
7325
|
const destination = cctpMetaForChainId(settlementChain.id);
|
|
7325
7326
|
const minFinalityThreshold = finalityForChainId(signer.chainId);
|
|
7326
|
-
const { accountAddress: smartAccountAddress } = await
|
|
7327
|
+
const { accountAddress: smartAccountAddress } = await _chunkEI5ILLQ3cjs.createSwapSmartAccountClient.call(void 0, {
|
|
7327
7328
|
signer: ownerSigner,
|
|
7328
7329
|
aa: context.aa,
|
|
7329
7330
|
chain: settlementChain
|
|
@@ -7350,14 +7351,14 @@ async function cctpFundSwap(context, params) {
|
|
|
7350
7351
|
_optionalChain([onProgress, 'optionalCall', _29 => _29({ phase: "burning", burnTxHash })]);
|
|
7351
7352
|
burnTxHash = await confirmBurn(signer, burnTxHash, onBurn);
|
|
7352
7353
|
_optionalChain([onProgress, 'optionalCall', _30 => _30({ phase: "attestation" })]);
|
|
7353
|
-
const { message, attestation } = await
|
|
7354
|
+
const { message, attestation } = await _chunkEI5ILLQ3cjs.fetchAttestation.call(void 0, {
|
|
7354
7355
|
sourceChain: source.name,
|
|
7355
7356
|
txHash: burnTxHash,
|
|
7356
7357
|
irisApiUrl,
|
|
7357
7358
|
signal
|
|
7358
7359
|
});
|
|
7359
7360
|
_optionalChain([onProgress, 'optionalCall', _31 => _31({ phase: "submitting" })]);
|
|
7360
|
-
const submit = await
|
|
7361
|
+
const submit = await _chunkEI5ILLQ3cjs.submitCctpInboundUserOp.call(void 0, context, {
|
|
7361
7362
|
swapId,
|
|
7362
7363
|
expected: params.expected,
|
|
7363
7364
|
signer: ownerSigner,
|
|
@@ -7410,7 +7411,7 @@ var CctpInboundClient = class {
|
|
|
7410
7411
|
aa: this.#aa,
|
|
7411
7412
|
chain: args.chain
|
|
7412
7413
|
};
|
|
7413
|
-
return
|
|
7414
|
+
return _chunkEI5ILLQ3cjs.createSwapSmartAccountClient.call(void 0, params);
|
|
7414
7415
|
}
|
|
7415
7416
|
/**
|
|
7416
7417
|
* Compose the 3-call UserOp batch (receiveMessage + USDC.approve +
|
|
@@ -7422,7 +7423,7 @@ var CctpInboundClient = class {
|
|
|
7422
7423
|
* which composes batch + send + wait-for-receipt.
|
|
7423
7424
|
*/
|
|
7424
7425
|
buildUserOpBatch(params) {
|
|
7425
|
-
return
|
|
7426
|
+
return _chunkEI5ILLQ3cjs.buildCctpInboundBatch.call(void 0, params);
|
|
7426
7427
|
}
|
|
7427
7428
|
/**
|
|
7428
7429
|
* End-to-end settlement UserOp: fetch calldata, build Kernel client,
|
|
@@ -7435,7 +7436,7 @@ var CctpInboundClient = class {
|
|
|
7435
7436
|
* caller's signer.
|
|
7436
7437
|
*/
|
|
7437
7438
|
submitUserOp(params) {
|
|
7438
|
-
return
|
|
7439
|
+
return _chunkEI5ILLQ3cjs.submitCctpInboundUserOp.call(void 0,
|
|
7439
7440
|
{ apiClient: this.#apiClient, aa: this.#aa },
|
|
7440
7441
|
{
|
|
7441
7442
|
...params,
|
|
@@ -7452,7 +7453,7 @@ var CctpInboundClient = class {
|
|
|
7452
7453
|
* paymaster-sponsored UserOp.
|
|
7453
7454
|
*/
|
|
7454
7455
|
submitBalanceUserOp(params) {
|
|
7455
|
-
return
|
|
7456
|
+
return _chunkEI5ILLQ3cjs.submitCctpInboundBalanceUserOp.call(void 0,
|
|
7456
7457
|
{ apiClient: this.#apiClient, aa: this.#aa },
|
|
7457
7458
|
{
|
|
7458
7459
|
...params,
|
|
@@ -7484,7 +7485,7 @@ var CctpInboundClient = class {
|
|
|
7484
7485
|
* `signal` (AbortSignal) to cancel early.
|
|
7485
7486
|
*/
|
|
7486
7487
|
waitForAttestation(options) {
|
|
7487
|
-
return
|
|
7488
|
+
return _chunkEI5ILLQ3cjs.fetchAttestation.call(void 0, options);
|
|
7488
7489
|
}
|
|
7489
7490
|
/**
|
|
7490
7491
|
* One-shot CCTP-inbound swap: approve + burn on the source chain,
|
|
@@ -7506,7 +7507,7 @@ _chunk5JR6AJ3Ycjs.init_utils.call(void 0, );
|
|
|
7506
7507
|
function deriveEvmAddress(secretKey) {
|
|
7507
7508
|
const keyBytes = typeof secretKey === "string" ? _chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, secretKey.replace(/^0x/, "")) : secretKey;
|
|
7508
7509
|
const uncompressedPubkey = _chunkBEW62OUTcjs.secp256k12.getPublicKey(keyBytes, false);
|
|
7509
|
-
const hash =
|
|
7510
|
+
const hash = _chunkEI5ILLQ3cjs.keccak_256.call(void 0, uncompressedPubkey.slice(1));
|
|
7510
7511
|
const addressBytes = hash.slice(12);
|
|
7511
7512
|
const addressHex2 = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, addressBytes);
|
|
7512
7513
|
return toChecksumAddress(addressHex2);
|
|
@@ -7537,11 +7538,11 @@ ${body.length}`
|
|
|
7537
7538
|
const whole = new Uint8Array(prefix.length + body.length);
|
|
7538
7539
|
whole.set(prefix, 0);
|
|
7539
7540
|
whole.set(body, prefix.length);
|
|
7540
|
-
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0,
|
|
7541
|
+
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkEI5ILLQ3cjs.keccak_256.call(void 0, whole))}`;
|
|
7541
7542
|
}
|
|
7542
7543
|
function toChecksumAddress(address2) {
|
|
7543
7544
|
const clean2 = address2.replace(/^0x/, "").toLowerCase();
|
|
7544
|
-
const hash = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0,
|
|
7545
|
+
const hash = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkEI5ILLQ3cjs.keccak_256.call(void 0, new TextEncoder().encode(clean2)));
|
|
7545
7546
|
let checksummed = "0x";
|
|
7546
7547
|
for (let i = 0; i < 40; i++) {
|
|
7547
7548
|
checksummed += parseInt(hash[i], 16) >= 8 ? clean2[i].toUpperCase() : clean2[i];
|
|
@@ -7550,7 +7551,7 @@ function toChecksumAddress(address2) {
|
|
|
7550
7551
|
}
|
|
7551
7552
|
var MAX_UINT256 = (1n << 256n) - 1n;
|
|
7552
7553
|
function signEip2612Permit(params) {
|
|
7553
|
-
const spender = _nullishCoalesce(params.spender, () => (
|
|
7554
|
+
const spender = _nullishCoalesce(params.spender, () => ( _chunkEI5ILLQ3cjs.PERMIT2_ADDRESS));
|
|
7554
7555
|
const digestParams = {
|
|
7555
7556
|
domainSeparator: params.domainSeparator,
|
|
7556
7557
|
owner: params.owner,
|
|
@@ -7559,7 +7560,7 @@ function signEip2612Permit(params) {
|
|
|
7559
7560
|
nonce: params.nonce,
|
|
7560
7561
|
deadline: params.deadline
|
|
7561
7562
|
};
|
|
7562
|
-
const digest =
|
|
7563
|
+
const digest = _chunkEI5ILLQ3cjs.buildEip2612PermitDigest.call(void 0, digestParams);
|
|
7563
7564
|
const sig = signEvmDigest(params.secretKey, digest);
|
|
7564
7565
|
return {
|
|
7565
7566
|
v: sig.v,
|
|
@@ -7584,14 +7585,14 @@ var USDC_DOMAIN_FIELDS = {
|
|
|
7584
7585
|
}
|
|
7585
7586
|
};
|
|
7586
7587
|
function keccak256Hex2(input) {
|
|
7587
|
-
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0,
|
|
7588
|
+
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkEI5ILLQ3cjs.keccak_256.call(void 0, new TextEncoder().encode(input)))}`;
|
|
7588
7589
|
}
|
|
7589
7590
|
function keccak256HexBytes(hexInput) {
|
|
7590
7591
|
const bytes = new Uint8Array(hexInput.length / 2);
|
|
7591
7592
|
for (let i = 0; i < bytes.length; i++) {
|
|
7592
7593
|
bytes[i] = parseInt(hexInput.slice(i * 2, i * 2 + 2), 16);
|
|
7593
7594
|
}
|
|
7594
|
-
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0,
|
|
7595
|
+
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkEI5ILLQ3cjs.keccak_256.call(void 0, bytes))}`;
|
|
7595
7596
|
}
|
|
7596
7597
|
function strip(hex2) {
|
|
7597
7598
|
return hex2.replace(/^0x/, "").toLowerCase();
|
|
@@ -7603,7 +7604,7 @@ function addressHex(address2) {
|
|
|
7603
7604
|
return address2.replace(/^0x/, "").toLowerCase().padStart(64, "0");
|
|
7604
7605
|
}
|
|
7605
7606
|
function signPermit2Witness(params) {
|
|
7606
|
-
const digest =
|
|
7607
|
+
const digest = _chunkEI5ILLQ3cjs.buildPermit2FundingDigest.call(void 0, params.funding);
|
|
7607
7608
|
const sig = signEvmDigest(params.secretKey, digest);
|
|
7608
7609
|
const r = sig.r.replace(/^0x/, "");
|
|
7609
7610
|
const s = sig.s.replace(/^0x/, "");
|
|
@@ -7655,7 +7656,7 @@ async function recoverCctpInbound(context, params) {
|
|
|
7655
7656
|
onProgress,
|
|
7656
7657
|
signal
|
|
7657
7658
|
} = params;
|
|
7658
|
-
const { client: aaClient, accountAddress } = await
|
|
7659
|
+
const { client: aaClient, accountAddress } = await _chunkEI5ILLQ3cjs.createSwapSmartAccountClient.call(void 0, { signer, aa: context.aa, chain });
|
|
7659
7660
|
const publicClient = _chunkK6TGBXTTcjs.createPublicClient.call(void 0, {
|
|
7660
7661
|
chain,
|
|
7661
7662
|
transport: _chunkK6TGBXTTcjs.http.call(void 0, _nullishCoalesce(context.aa.rpcUrl, () => ( context.aa.bundlerUrl)))
|
|
@@ -7666,7 +7667,7 @@ async function recoverCctpInbound(context, params) {
|
|
|
7666
7667
|
const usdcAddress = _chunkTKFOVRJRcjs.USDC_ADDRESSES.Arbitrum;
|
|
7667
7668
|
if (!cctpMessage || !cctpAttestation) {
|
|
7668
7669
|
_optionalChain([onProgress, 'optionalCall', _37 => _37({ phase: "attestation" })]);
|
|
7669
|
-
const fetched = await
|
|
7670
|
+
const fetched = await _chunkEI5ILLQ3cjs.fetchAttestation.call(void 0, {
|
|
7670
7671
|
sourceChain,
|
|
7671
7672
|
txHash: burnTxHash,
|
|
7672
7673
|
irisApiUrl,
|
|
@@ -7949,6 +7950,7 @@ var TBTC_ETHEREUM = "0x18084fbA666a33d37592fA2633fD49a74DD93a88";
|
|
|
7949
7950
|
var TBTC_ARBITRUM = "0x6c84a8f1c29108F47a79964b5Fe888D4f4D0dE40";
|
|
7950
7951
|
var Asset = {
|
|
7951
7952
|
// Bitcoin
|
|
7953
|
+
BTC_SPARK: { chain: "Spark", tokenId: "btc" },
|
|
7952
7954
|
BTC_LIGHTNING: { chain: "Lightning", tokenId: "btc" },
|
|
7953
7955
|
BTC_ARKADE: { chain: "Arkade", tokenId: "btc" },
|
|
7954
7956
|
BTC_ONCHAIN: { chain: "Bitcoin", tokenId: "btc" },
|
|
@@ -8039,7 +8041,7 @@ function isBtcOnchain(token) {
|
|
|
8039
8041
|
return token.chain.toLowerCase() === "bitcoin";
|
|
8040
8042
|
}
|
|
8041
8043
|
function isBtc(token) {
|
|
8042
|
-
return isLightning(token) || isArkade(token) || isBtcOnchain(token);
|
|
8044
|
+
return isSpark(token) || isLightning(token) || isArkade(token) || isBtcOnchain(token);
|
|
8043
8045
|
}
|
|
8044
8046
|
function isBtcPegged(token) {
|
|
8045
8047
|
const sym = token.symbol.toLowerCase();
|
|
@@ -8126,6 +8128,7 @@ function toChain(str) {
|
|
|
8126
8128
|
if (c === "arbitrum" || c === "42161") return "42161";
|
|
8127
8129
|
if (c === "rootstock" || c === "30") return "30";
|
|
8128
8130
|
if (c === "31") return "31";
|
|
8131
|
+
if (c === "spark") return "Spark";
|
|
8129
8132
|
if (c === "lightning") return "Lightning";
|
|
8130
8133
|
if (c === "arkade") return "Arkade";
|
|
8131
8134
|
if (c === "bitcoin") return "Bitcoin";
|
|
@@ -8183,6 +8186,9 @@ function getUsdt0BridgeTokens() {
|
|
|
8183
8186
|
}
|
|
8184
8187
|
return tokens;
|
|
8185
8188
|
}
|
|
8189
|
+
function isSpark(token) {
|
|
8190
|
+
return token.chain.toLowerCase() === "spark";
|
|
8191
|
+
}
|
|
8186
8192
|
function pivotForChain(chainConfig, chain) {
|
|
8187
8193
|
const entry = chainConfig.chains.find((c) => c.chain === chain);
|
|
8188
8194
|
if (!entry) return void 0;
|
|
@@ -8388,9 +8394,10 @@ async function composeBtcToEvm(params, deps) {
|
|
|
8388
8394
|
);
|
|
8389
8395
|
}
|
|
8390
8396
|
const { btcSats, evmSmallest, evmDecimals } = pivot;
|
|
8397
|
+
ensureWithinPromoCap(deps, btcSats);
|
|
8391
8398
|
let { bridgeFee } = pivot;
|
|
8392
8399
|
const networkFeeSats = baseNetworkFeeSats + pivot.bridgeNativeFeeSats;
|
|
8393
|
-
const effectiveFeePct = (
|
|
8400
|
+
const effectiveFeePct = baseFeePct(deps, pair.fee_percentage) + (_nullishCoalesce(deps.referralExtraFeeRate, () => ( 0)));
|
|
8394
8401
|
const FEE_SCALE = 10n ** 18n;
|
|
8395
8402
|
const feePctScaled = BigInt(Math.round(effectiveFeePct * Number(FEE_SCALE)));
|
|
8396
8403
|
const protocolFee = Number(btcSats * feePctScaled / FEE_SCALE);
|
|
@@ -8430,7 +8437,7 @@ async function composeBtcToEvm(params, deps) {
|
|
|
8430
8437
|
protocol_fee: protocolFee,
|
|
8431
8438
|
protocol_fee_rate: effectiveFeePct,
|
|
8432
8439
|
min_amount: pair.min_sats,
|
|
8433
|
-
max_amount: pair.max_sats,
|
|
8440
|
+
max_amount: maxSats(deps, pair.max_sats),
|
|
8434
8441
|
source_amount: btcSats.toString(),
|
|
8435
8442
|
// Source-pinned: `evmSmallest` is the delivered (fee-netted) DEX output, so
|
|
8436
8443
|
// gross it back up by the bridge fee — `target_amount` is the gross output
|
|
@@ -8442,7 +8449,8 @@ async function composeBtcToEvm(params, deps) {
|
|
|
8442
8449
|
target_amount: (params.sourceAmount != null ? grossTarget : evmSmallest).toString(),
|
|
8443
8450
|
net_source_amount: netSource.toString(),
|
|
8444
8451
|
net_target_amount: netTarget.toString(),
|
|
8445
|
-
bridge_fee: bridgeFee > 0n ? Number(bridgeFee) : void 0
|
|
8452
|
+
bridge_fee: bridgeFee > 0n ? Number(bridgeFee) : void 0,
|
|
8453
|
+
promo: deps.referralPromo
|
|
8446
8454
|
};
|
|
8447
8455
|
}
|
|
8448
8456
|
async function dexSourcePinned(btcSats, params, deps, btcPegged, pivotChainId, toToken, pivotScale) {
|
|
@@ -8551,7 +8559,8 @@ async function composeEvmToBtc(params, deps) {
|
|
|
8551
8559
|
);
|
|
8552
8560
|
}
|
|
8553
8561
|
const { btcSats, evmSmallest, evmDecimals, bridgeFee } = pivot;
|
|
8554
|
-
|
|
8562
|
+
ensureWithinPromoCap(deps, btcSats);
|
|
8563
|
+
const effectiveFeePct = baseFeePct(deps, pair.fee_percentage) + (_nullishCoalesce(deps.referralExtraFeeRate, () => ( 0)));
|
|
8555
8564
|
const FEE_SCALE = 10n ** 18n;
|
|
8556
8565
|
const feePctScaled = BigInt(Math.round(effectiveFeePct * Number(FEE_SCALE)));
|
|
8557
8566
|
const protocolFee = Number(btcSats * feePctScaled / FEE_SCALE);
|
|
@@ -8573,7 +8582,7 @@ async function composeEvmToBtc(params, deps) {
|
|
|
8573
8582
|
protocol_fee: protocolFee,
|
|
8574
8583
|
protocol_fee_rate: effectiveFeePct,
|
|
8575
8584
|
min_amount: pair.min_sats,
|
|
8576
|
-
max_amount: pair.max_sats,
|
|
8585
|
+
max_amount: maxSats(deps, pair.max_sats),
|
|
8577
8586
|
// EVM→BTC: the EVM source is the bridged side. The dex-quote already
|
|
8578
8587
|
// reports `evmSmallest` as the gross the user supplies (the inbound fee was
|
|
8579
8588
|
// folded onto it), so `source_amount` needs no adjustment — just surface
|
|
@@ -8582,7 +8591,8 @@ async function composeEvmToBtc(params, deps) {
|
|
|
8582
8591
|
target_amount: btcSats.toString(),
|
|
8583
8592
|
net_source_amount: netSource.toString(),
|
|
8584
8593
|
net_target_amount: netTarget.toString(),
|
|
8585
|
-
bridge_fee: bridgeFee > 0n ? Number(bridgeFee) : void 0
|
|
8594
|
+
bridge_fee: bridgeFee > 0n ? Number(bridgeFee) : void 0,
|
|
8595
|
+
promo: deps.referralPromo
|
|
8586
8596
|
};
|
|
8587
8597
|
}
|
|
8588
8598
|
async function dexEvmToBtcSourcePinned(evmSmallest, params, deps, btcPegged, pivotChainId, tokenChainId, pivotScale) {
|
|
@@ -8636,22 +8646,36 @@ function calculateExchangeRate(btcSats, evmSmallest, evmDecimals) {
|
|
|
8636
8646
|
frac = frac.replace(/0+$/, "");
|
|
8637
8647
|
return frac.length === 0 ? intPart.toString() : `${intPart}.${frac}`;
|
|
8638
8648
|
}
|
|
8649
|
+
function baseFeePct(deps, pairFeePct) {
|
|
8650
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([deps, 'access', _61 => _61.referralPromo, 'optionalAccess', _62 => _62.fee_rate]), () => ( deps.referralBaseFeeRate)), () => ( pairFeePct));
|
|
8651
|
+
}
|
|
8652
|
+
function ensureWithinPromoCap(deps, btcSats) {
|
|
8653
|
+
const promo = deps.referralPromo;
|
|
8654
|
+
if (promo && btcSats > BigInt(promo.max_amount_sats)) {
|
|
8655
|
+
throw new Error(
|
|
8656
|
+
`promo code only applies to swaps up to ${promo.max_amount_sats} sats`
|
|
8657
|
+
);
|
|
8658
|
+
}
|
|
8659
|
+
}
|
|
8660
|
+
function maxSats(deps, pairMaxSats) {
|
|
8661
|
+
return deps.referralPromo ? Math.max(pairMaxSats, deps.referralPromo.max_amount_sats) : pairMaxSats;
|
|
8662
|
+
}
|
|
8639
8663
|
_chunk5JR6AJ3Ycjs.init_sha2.call(void 0, );
|
|
8640
8664
|
_chunk5JR6AJ3Ycjs.init_utils.call(void 0, );
|
|
8641
8665
|
_chunkBEW62OUTcjs.init_bip32.call(void 0, );
|
|
8642
8666
|
function pbkdf2Init(hash, _password, _salt, _opts) {
|
|
8643
|
-
|
|
8644
|
-
const opts =
|
|
8667
|
+
_chunkLZQZYSOZcjs.ahash.call(void 0, hash);
|
|
8668
|
+
const opts = _chunkLZQZYSOZcjs.checkOpts.call(void 0, { dkLen: 32, asyncTick: 10 }, _opts);
|
|
8645
8669
|
const { c, dkLen, asyncTick } = opts;
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
|
|
8670
|
+
_chunkLZQZYSOZcjs.anumber.call(void 0, c, "c");
|
|
8671
|
+
_chunkLZQZYSOZcjs.anumber.call(void 0, dkLen, "dkLen");
|
|
8672
|
+
_chunkLZQZYSOZcjs.anumber.call(void 0, asyncTick, "asyncTick");
|
|
8649
8673
|
if (c < 1)
|
|
8650
8674
|
throw new Error("iterations (c) must be >= 1");
|
|
8651
|
-
const password =
|
|
8652
|
-
const salt =
|
|
8675
|
+
const password = _chunkLZQZYSOZcjs.kdfInputToBytes.call(void 0, _password, "password");
|
|
8676
|
+
const salt = _chunkLZQZYSOZcjs.kdfInputToBytes.call(void 0, _salt, "salt");
|
|
8653
8677
|
const DK = new Uint8Array(dkLen);
|
|
8654
|
-
const PRF =
|
|
8678
|
+
const PRF = _chunkLZQZYSOZcjs.hmac.create(hash, password);
|
|
8655
8679
|
const PRFSalt = PRF._cloneInto().update(salt);
|
|
8656
8680
|
return { c, dkLen, asyncTick, DK, PRF, PRFSalt };
|
|
8657
8681
|
}
|
|
@@ -8660,14 +8684,14 @@ function pbkdf2Output(PRF, PRFSalt, DK, prfW, u) {
|
|
|
8660
8684
|
PRFSalt.destroy();
|
|
8661
8685
|
if (prfW)
|
|
8662
8686
|
prfW.destroy();
|
|
8663
|
-
|
|
8687
|
+
_chunkLZQZYSOZcjs.clean.call(void 0, u);
|
|
8664
8688
|
return DK;
|
|
8665
8689
|
}
|
|
8666
8690
|
function pbkdf2(hash, password, salt, opts) {
|
|
8667
8691
|
const { c, dkLen, DK, PRF, PRFSalt } = pbkdf2Init(hash, password, salt, opts);
|
|
8668
8692
|
let prfW;
|
|
8669
8693
|
const arr = new Uint8Array(4);
|
|
8670
|
-
const view =
|
|
8694
|
+
const view = _chunkLZQZYSOZcjs.createView.call(void 0, arr);
|
|
8671
8695
|
const u = new Uint8Array(PRF.outputLen);
|
|
8672
8696
|
for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
|
|
8673
8697
|
const Ti = DK.subarray(pos, pos + PRF.outputLen);
|
|
@@ -8696,19 +8720,19 @@ function normalize(str) {
|
|
|
8696
8720
|
return { nfkd: norm, words };
|
|
8697
8721
|
}
|
|
8698
8722
|
function aentropy(ent) {
|
|
8699
|
-
|
|
8723
|
+
_chunkLZQZYSOZcjs.abytes.call(void 0, ent);
|
|
8700
8724
|
if (![16, 20, 24, 28, 32].includes(ent.length))
|
|
8701
8725
|
throw new Error("invalid entropy length");
|
|
8702
8726
|
}
|
|
8703
8727
|
function generateMnemonic(wordlist2, strength = 128) {
|
|
8704
|
-
|
|
8728
|
+
_chunkLZQZYSOZcjs.anumber.call(void 0, strength);
|
|
8705
8729
|
if (strength % 32 !== 0 || strength > 256)
|
|
8706
8730
|
throw new TypeError("Invalid entropy");
|
|
8707
|
-
return entropyToMnemonic(
|
|
8731
|
+
return entropyToMnemonic(_chunkLZQZYSOZcjs.randomBytes.call(void 0, strength / 8), wordlist2);
|
|
8708
8732
|
}
|
|
8709
8733
|
var calcChecksum = (entropy) => {
|
|
8710
8734
|
const bitsLeft = 8 - entropy.length / 4;
|
|
8711
|
-
return new Uint8Array([
|
|
8735
|
+
return new Uint8Array([_chunkLZQZYSOZcjs.sha2562.call(void 0, entropy)[0] >> bitsLeft << bitsLeft]);
|
|
8712
8736
|
};
|
|
8713
8737
|
function getCoder(wordlist2) {
|
|
8714
8738
|
if (!Array.isArray(wordlist2) || wordlist2.length !== 2048 || typeof wordlist2[0] !== "string")
|
|
@@ -8717,7 +8741,7 @@ function getCoder(wordlist2) {
|
|
|
8717
8741
|
if (typeof i !== "string")
|
|
8718
8742
|
throw new Error("wordlist: non-string element: " + i);
|
|
8719
8743
|
});
|
|
8720
|
-
return
|
|
8744
|
+
return _chunkLZQZYSOZcjs.utils.chain(_chunkLZQZYSOZcjs.utils.checksum(1, calcChecksum), _chunkLZQZYSOZcjs.utils.radix2(11, true), _chunkLZQZYSOZcjs.utils.alphabet(wordlist2));
|
|
8721
8745
|
}
|
|
8722
8746
|
function mnemonicToEntropy(mnemonic, wordlist2) {
|
|
8723
8747
|
const { words } = normalize(mnemonic);
|
|
@@ -8740,7 +8764,7 @@ function validateMnemonic(mnemonic, wordlist2) {
|
|
|
8740
8764
|
}
|
|
8741
8765
|
var psalt = (passphrase) => nfkd("mnemonic" + passphrase);
|
|
8742
8766
|
function mnemonicToSeedSync(mnemonic, passphrase = "") {
|
|
8743
|
-
return pbkdf2(
|
|
8767
|
+
return pbkdf2(_chunkLZQZYSOZcjs.sha512, normalize(mnemonic).nfkd, psalt(passphrase), { c: 2048, dkLen: 64 });
|
|
8744
8768
|
}
|
|
8745
8769
|
var wordlist = `abandon
|
|
8746
8770
|
ability
|
|
@@ -11058,12 +11082,12 @@ function parseXOnlyPubKey(pubKeyHex) {
|
|
|
11058
11082
|
);
|
|
11059
11083
|
}
|
|
11060
11084
|
function refundableVhtlc(params) {
|
|
11061
|
-
if (params.scriptVersion !== void 0 && params.scriptVersion !==
|
|
11085
|
+
if (params.scriptVersion !== void 0 && params.scriptVersion !== _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
|
|
11062
11086
|
throw new Error(
|
|
11063
11087
|
`Unsupported Arkade HTLC script version: ${params.scriptVersion}`
|
|
11064
11088
|
);
|
|
11065
11089
|
}
|
|
11066
|
-
return new (0,
|
|
11090
|
+
return new (0, _chunkLZQZYSOZcjs.StrictVhtlcScript)({
|
|
11067
11091
|
sender: parseXOnlyPubKey(params.senderPubKey),
|
|
11068
11092
|
receiver: parseXOnlyPubKey(params.receiverPubKey),
|
|
11069
11093
|
server: parseXOnlyPubKey(params.serverPubKey),
|
|
@@ -11114,8 +11138,8 @@ async function buildArkadeRefund(params) {
|
|
|
11114
11138
|
`Invalid hash lock length: expected 20 or 32, got ${hashLockBytes.length}`
|
|
11115
11139
|
);
|
|
11116
11140
|
}
|
|
11117
|
-
const networkName =
|
|
11118
|
-
const serverUrl =
|
|
11141
|
+
const networkName = _chunkLZQZYSOZcjs.getNetworkName.call(void 0, network);
|
|
11142
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
|
|
11119
11143
|
const arkProvider = new (0, _chunkBEW62OUTcjs.RestOperatorProvider)(serverUrl);
|
|
11120
11144
|
const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
|
|
11121
11145
|
const serverInfo = await arkProvider.getInfo();
|
|
@@ -11130,7 +11154,7 @@ async function buildArkadeRefund(params) {
|
|
|
11130
11154
|
unilateralRefundWithoutReceiverDelay,
|
|
11131
11155
|
scriptVersion: arkadeHtlcScriptVersion
|
|
11132
11156
|
});
|
|
11133
|
-
const hrp =
|
|
11157
|
+
const hrp = _chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, networkName);
|
|
11134
11158
|
const computedAddress = vhtlc.address(hrp, serverPkBytes);
|
|
11135
11159
|
const computedAddressStr = computedAddress.encode();
|
|
11136
11160
|
if (computedAddressStr !== vhtlcAddress) {
|
|
@@ -11215,6 +11239,65 @@ _chunkBEW62OUTcjs.init_secp256k12.call(void 0, );
|
|
|
11215
11239
|
_chunkBEW62OUTcjs.init_legacy2.call(void 0, );
|
|
11216
11240
|
_chunk5JR6AJ3Ycjs.init_sha2.call(void 0, );
|
|
11217
11241
|
_chunkRYZSWESUcjs.init_base.call(void 0, );
|
|
11242
|
+
var MAX_MONEY = 2100000000000000n;
|
|
11243
|
+
var MAX_PAYOUT_FEE_SATS = 100000n;
|
|
11244
|
+
function validateBitcoinPayout(payout, network) {
|
|
11245
|
+
if (typeof payout !== "object" || payout === null)
|
|
11246
|
+
throw new Error("A Bitcoin payout must be an object");
|
|
11247
|
+
if (!Array.isArray(payout.recipients) || payout.recipients.length < 1 || payout.recipients.length > 100)
|
|
11248
|
+
throw new Error("A Bitcoin payout needs 1\u2013100 recipients");
|
|
11249
|
+
const sats = (value) => {
|
|
11250
|
+
if (typeof value !== "string" || !/^[0-9]{1,16}$/.test(value))
|
|
11251
|
+
throw new Error("Payout amounts must be integer satoshi strings");
|
|
11252
|
+
const amount = BigInt(value);
|
|
11253
|
+
if (amount > MAX_MONEY) throw new Error("Payout exceeds Bitcoin supply");
|
|
11254
|
+
return amount;
|
|
11255
|
+
};
|
|
11256
|
+
const fee = sats(payout.feeSats);
|
|
11257
|
+
if (fee < 1n || fee > MAX_PAYOUT_FEE_SATS)
|
|
11258
|
+
throw new Error("Payout fee must be between 1 and 100,000 sats");
|
|
11259
|
+
let total = 0n;
|
|
11260
|
+
for (const recipient of payout.recipients) {
|
|
11261
|
+
let decoded;
|
|
11262
|
+
try {
|
|
11263
|
+
decoded = _chunkLZQZYSOZcjs.Address.call(void 0, network).decode(recipient.address);
|
|
11264
|
+
} catch (e5) {
|
|
11265
|
+
throw new Error(
|
|
11266
|
+
"Recipient address is not a valid address for this network"
|
|
11267
|
+
);
|
|
11268
|
+
}
|
|
11269
|
+
if (!decoded || !["pkh", "sh", "wpkh", "wsh", "tr"].includes(decoded.type))
|
|
11270
|
+
throw new Error("Unsupported Bitcoin recipient address");
|
|
11271
|
+
const amount = sats(recipient.amountSats);
|
|
11272
|
+
if (amount < 546n)
|
|
11273
|
+
throw new Error("Each recipient must receive at least 546 sats");
|
|
11274
|
+
total += amount;
|
|
11275
|
+
}
|
|
11276
|
+
if (total + fee > MAX_MONEY) throw new Error("Payout exceeds Bitcoin supply");
|
|
11277
|
+
return { total, fee };
|
|
11278
|
+
}
|
|
11279
|
+
function allocateBitcoinPayout(payout, funded, fee = BigInt(payout.feeSats)) {
|
|
11280
|
+
const amounts = payout.recipients.map((r) => BigInt(r.amountSats));
|
|
11281
|
+
const total = amounts.reduce((a, b) => a + b, 0n);
|
|
11282
|
+
const remainder = funded - total - fee;
|
|
11283
|
+
if (remainder < 0n)
|
|
11284
|
+
throw new Error(
|
|
11285
|
+
"Funded amount cannot cover the committed recipients and fee"
|
|
11286
|
+
);
|
|
11287
|
+
const shares = amounts.map((amount) => remainder * amount / total);
|
|
11288
|
+
let leftover = remainder - shares.reduce((a, b) => a + b, 0n);
|
|
11289
|
+
return {
|
|
11290
|
+
feeSats: fee.toString(),
|
|
11291
|
+
recipients: payout.recipients.map((recipient, index) => {
|
|
11292
|
+
const extra = leftover > 0n ? 1n : 0n;
|
|
11293
|
+
leftover -= extra;
|
|
11294
|
+
return {
|
|
11295
|
+
address: recipient.address,
|
|
11296
|
+
amountSats: (amounts[index] + shares[index] + extra).toString()
|
|
11297
|
+
};
|
|
11298
|
+
})
|
|
11299
|
+
};
|
|
11300
|
+
}
|
|
11218
11301
|
var NUMS_POINT = _chunkRYZSWESUcjs.hex.decode(
|
|
11219
11302
|
"0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"
|
|
11220
11303
|
);
|
|
@@ -11227,10 +11310,10 @@ var REGTEST_NETWORK = {
|
|
|
11227
11310
|
function getNetwork(network) {
|
|
11228
11311
|
switch (network) {
|
|
11229
11312
|
case "mainnet":
|
|
11230
|
-
return
|
|
11313
|
+
return _chunkLZQZYSOZcjs.NETWORK;
|
|
11231
11314
|
case "testnet":
|
|
11232
11315
|
case "signet":
|
|
11233
|
-
return
|
|
11316
|
+
return _chunkLZQZYSOZcjs.TEST_NETWORK;
|
|
11234
11317
|
case "regtest":
|
|
11235
11318
|
return REGTEST_NETWORK;
|
|
11236
11319
|
default:
|
|
@@ -11253,10 +11336,10 @@ function buildHashlockScript(hashLock, serverPubKey, btcHtlcScriptVersion = 1) {
|
|
|
11253
11336
|
hashLock,
|
|
11254
11337
|
"EQUAL"
|
|
11255
11338
|
];
|
|
11256
|
-
return
|
|
11339
|
+
return _chunkLZQZYSOZcjs.Script.encode(script);
|
|
11257
11340
|
}
|
|
11258
11341
|
function buildTimelockScript(userPubKey, refundLocktime) {
|
|
11259
|
-
return
|
|
11342
|
+
return _chunkLZQZYSOZcjs.Script.encode([
|
|
11260
11343
|
refundLocktime,
|
|
11261
11344
|
"CHECKLOCKTIMEVERIFY",
|
|
11262
11345
|
"DROP",
|
|
@@ -11274,7 +11357,7 @@ function buildHtlcTaprootInfo(hashLock, serverPubKey, userPubKey, refundLocktime
|
|
|
11274
11357
|
btcHtlcScriptVersion
|
|
11275
11358
|
);
|
|
11276
11359
|
const timelockScript = buildTimelockScript(userPubKey, refundLocktime);
|
|
11277
|
-
const p2tr2 =
|
|
11360
|
+
const p2tr2 = _chunkLZQZYSOZcjs.p2tr.call(void 0,
|
|
11278
11361
|
NUMS_POINT.slice(1),
|
|
11279
11362
|
// Remove the 02/03 prefix for x-only
|
|
11280
11363
|
[{ script: hashlockScript }, { script: timelockScript }],
|
|
@@ -11344,7 +11427,14 @@ function buildOnchainClaimTransaction(params) {
|
|
|
11344
11427
|
refundLocktime,
|
|
11345
11428
|
params.btcHtlcScriptVersion
|
|
11346
11429
|
);
|
|
11347
|
-
const
|
|
11430
|
+
const payout = params.bitcoinPayout;
|
|
11431
|
+
const validated = payout !== void 0 ? validateBitcoinPayout(payout, getNetwork(network)) : void 0;
|
|
11432
|
+
const fee = _nullishCoalesce(_optionalChain([validated, 'optionalAccess', _63 => _63.fee]), () => ( CLAIM_TX_VBYTES * BigInt(Math.ceil(feeRateSatPerVb))));
|
|
11433
|
+
const remainder = validated ? htlcAmount - validated.total - fee : 0n;
|
|
11434
|
+
if (validated && remainder < 0n)
|
|
11435
|
+
throw new Error(
|
|
11436
|
+
"Funded amount cannot cover the committed recipients and fee"
|
|
11437
|
+
);
|
|
11348
11438
|
if (fee >= htlcAmount) {
|
|
11349
11439
|
throw new Error(
|
|
11350
11440
|
`Fee (${fee} sats) exceeds HTLC amount (${htlcAmount} sats)`
|
|
@@ -11357,7 +11447,7 @@ function buildOnchainClaimTransaction(params) {
|
|
|
11357
11447
|
throw new Error("Failed to build tapLeafScript for hashlock");
|
|
11358
11448
|
}
|
|
11359
11449
|
const hashlockLeaf = tapLeafScript[0];
|
|
11360
|
-
const tx = new (0,
|
|
11450
|
+
const tx = new (0, _chunkLZQZYSOZcjs.Transaction2)({
|
|
11361
11451
|
allowUnknownOutputs: true,
|
|
11362
11452
|
allowUnknownInputs: true
|
|
11363
11453
|
});
|
|
@@ -11369,16 +11459,25 @@ function buildOnchainClaimTransaction(params) {
|
|
|
11369
11459
|
amount: htlcAmount
|
|
11370
11460
|
},
|
|
11371
11461
|
tapLeafScript: [hashlockLeaf],
|
|
11372
|
-
sequence: 4294967295
|
|
11462
|
+
sequence: validated ? 4294967293 : 4294967295
|
|
11373
11463
|
});
|
|
11374
|
-
|
|
11464
|
+
if (validated && payout) {
|
|
11465
|
+
for (const recipient of allocateBitcoinPayout(payout, htlcAmount, fee).recipients)
|
|
11466
|
+
tx.addOutputAddress(
|
|
11467
|
+
recipient.address,
|
|
11468
|
+
BigInt(recipient.amountSats),
|
|
11469
|
+
networkConfig
|
|
11470
|
+
);
|
|
11471
|
+
} else {
|
|
11472
|
+
tx.addOutputAddress(destinationAddress, claimAmount, networkConfig);
|
|
11473
|
+
}
|
|
11375
11474
|
const [controlBlockInfo, leafScriptWithVersion] = hashlockLeaf;
|
|
11376
11475
|
const leafScript = leafScriptWithVersion.slice(0, -1);
|
|
11377
11476
|
const leafVersion = leafScriptWithVersion[leafScriptWithVersion.length - 1];
|
|
11378
11477
|
const sighash = tx.preimageWitnessV1(
|
|
11379
11478
|
0,
|
|
11380
11479
|
[p2tr2.script],
|
|
11381
|
-
|
|
11480
|
+
_chunkLZQZYSOZcjs.SigHash.DEFAULT,
|
|
11382
11481
|
[htlcAmount],
|
|
11383
11482
|
void 0,
|
|
11384
11483
|
leafScript,
|
|
@@ -11397,13 +11496,34 @@ function buildOnchainClaimTransaction(params) {
|
|
|
11397
11496
|
tx.updateInput(0, {
|
|
11398
11497
|
finalScriptWitness: [preimageBytes, sig, leafScript, encodedControlBlock]
|
|
11399
11498
|
});
|
|
11499
|
+
if (validated && payout) {
|
|
11500
|
+
if (!Number.isFinite(feeRateSatPerVb) || feeRateSatPerVb <= 0)
|
|
11501
|
+
throw new Error("Fee rate must be a positive number of sat/vB");
|
|
11502
|
+
if (Number(fee) / tx.vsize < feeRateSatPerVb) {
|
|
11503
|
+
let required = BigInt(Math.ceil(tx.vsize * feeRateSatPerVb));
|
|
11504
|
+
if (Number(required - 1n) / tx.vsize >= feeRateSatPerVb) required -= 1n;
|
|
11505
|
+
if (required > MAX_PAYOUT_FEE_SATS)
|
|
11506
|
+
throw new Error(
|
|
11507
|
+
`A ${feeRateSatPerVb} sat/vB claim needs ${required} sats, above the ${MAX_PAYOUT_FEE_SATS}-sat payout fee cap`
|
|
11508
|
+
);
|
|
11509
|
+
if (htlcAmount - validated.total < required)
|
|
11510
|
+
throw new Error(
|
|
11511
|
+
`Surplus cannot cover the ${required}-sat fee for ${feeRateSatPerVb} sat/vB without reducing recipients`
|
|
11512
|
+
);
|
|
11513
|
+
return buildOnchainClaimTransaction({
|
|
11514
|
+
...params,
|
|
11515
|
+
bitcoinPayout: { ...payout, feeSats: required.toString() }
|
|
11516
|
+
});
|
|
11517
|
+
}
|
|
11518
|
+
}
|
|
11400
11519
|
const txHex = _chunkRYZSWESUcjs.hex.encode(tx.extract());
|
|
11401
11520
|
const txId = tx.id;
|
|
11402
|
-
const htlcAddress2 =
|
|
11521
|
+
const htlcAddress2 = _chunkLZQZYSOZcjs.Address.call(void 0, networkConfig).encode({
|
|
11403
11522
|
type: "tr",
|
|
11404
11523
|
pubkey: p2tr2.tweakedPubkey
|
|
11405
11524
|
});
|
|
11406
11525
|
return {
|
|
11526
|
+
vsize: tx.vsize,
|
|
11407
11527
|
txHex,
|
|
11408
11528
|
txId,
|
|
11409
11529
|
claimAmount,
|
|
@@ -11469,7 +11589,7 @@ function buildOnchainRefundTransaction(params) {
|
|
|
11469
11589
|
throw new Error("Failed to build tapLeafScript for timelock");
|
|
11470
11590
|
}
|
|
11471
11591
|
const timelockLeaf = tapLeafScript[1];
|
|
11472
|
-
const tx = new (0,
|
|
11592
|
+
const tx = new (0, _chunkLZQZYSOZcjs.Transaction2)({
|
|
11473
11593
|
allowUnknownOutputs: true,
|
|
11474
11594
|
allowUnknownInputs: true,
|
|
11475
11595
|
lockTime: refundLocktime
|
|
@@ -11490,7 +11610,7 @@ function buildOnchainRefundTransaction(params) {
|
|
|
11490
11610
|
tx.finalize();
|
|
11491
11611
|
const txHex = _chunkRYZSWESUcjs.hex.encode(tx.extract());
|
|
11492
11612
|
const txId = tx.id;
|
|
11493
|
-
const htlcAddress2 =
|
|
11613
|
+
const htlcAddress2 = _chunkLZQZYSOZcjs.Address.call(void 0, networkConfig).encode({
|
|
11494
11614
|
type: "tr",
|
|
11495
11615
|
pubkey: p2tr2.tweakedPubkey
|
|
11496
11616
|
});
|
|
@@ -11523,7 +11643,7 @@ function htlcAddress(hashLock, serverPubKey, userPubKey, refundLocktime, network
|
|
|
11523
11643
|
refundLocktime,
|
|
11524
11644
|
btcHtlcScriptVersion
|
|
11525
11645
|
);
|
|
11526
|
-
return
|
|
11646
|
+
return _chunkLZQZYSOZcjs.Address.call(void 0, getNetwork(network)).encode({
|
|
11527
11647
|
type: "tr",
|
|
11528
11648
|
pubkey: p2tr2.tweakedPubkey
|
|
11529
11649
|
});
|
|
@@ -11640,12 +11760,12 @@ function checkedLightningPaymentHash(options, data) {
|
|
|
11640
11760
|
}
|
|
11641
11761
|
function assertFundedVhtlc(response, addressField, address2, hash160, refundPublicKey, lockDescription) {
|
|
11642
11762
|
const swapId = response.id;
|
|
11643
|
-
if (response.arkade_htlc_script_version !==
|
|
11763
|
+
if (response.arkade_htlc_script_version !== _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
|
|
11644
11764
|
throw new SwapVerificationError(
|
|
11645
11765
|
`Swap ${swapId} uses Arkade HTLC script version ${response.arkade_htlc_script_version}, which this client cannot refund; do not fund it`,
|
|
11646
11766
|
{
|
|
11647
11767
|
field: "arkade_htlc_script_version",
|
|
11648
|
-
expected: String(
|
|
11768
|
+
expected: String(_chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT),
|
|
11649
11769
|
received: String(response.arkade_htlc_script_version),
|
|
11650
11770
|
swapId
|
|
11651
11771
|
}
|
|
@@ -11662,7 +11782,7 @@ function assertFundedVhtlc(response, addressField, address2, hash160, refundPubl
|
|
|
11662
11782
|
unilateralRefundDelay: response.unilateral_refund_delay,
|
|
11663
11783
|
unilateralRefundWithoutReceiverDelay: response.unilateral_refund_without_receiver_delay
|
|
11664
11784
|
});
|
|
11665
|
-
const expected = vhtlc.address(
|
|
11785
|
+
const expected = vhtlc.address(_chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, _chunkLZQZYSOZcjs.getNetworkName.call(void 0, response.network)), server).encode();
|
|
11666
11786
|
if (expected !== address2) {
|
|
11667
11787
|
throw new SwapVerificationError(
|
|
11668
11788
|
`Swap ${swapId}'s VHTLC address ${address2} does not lock to ${lockDescription} and this client's refund key (expected ${expected}); do not fund it`,
|
|
@@ -11706,12 +11826,12 @@ function assertHashLock(swapId, field, hashLock, accepted) {
|
|
|
11706
11826
|
}
|
|
11707
11827
|
function assertFundedHtlc(response, hashField, hashLock, serverPk, hash160, refundPublicKey, lockDescription) {
|
|
11708
11828
|
const swapId = response.id;
|
|
11709
|
-
if (response.btc_htlc_script_version !==
|
|
11829
|
+
if (response.btc_htlc_script_version !== _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT) {
|
|
11710
11830
|
throw new SwapVerificationError(
|
|
11711
11831
|
`Swap ${swapId} uses Bitcoin HTLC script version ${response.btc_htlc_script_version}, which this client cannot refund; do not fund it`,
|
|
11712
11832
|
{
|
|
11713
11833
|
field: "btc_htlc_script_version",
|
|
11714
|
-
expected: String(
|
|
11834
|
+
expected: String(_chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT),
|
|
11715
11835
|
received: String(response.btc_htlc_script_version),
|
|
11716
11836
|
swapId
|
|
11717
11837
|
}
|
|
@@ -11724,7 +11844,7 @@ function assertFundedHtlc(response, hashField, hashLock, serverPk, hash160, refu
|
|
|
11724
11844
|
{ field: hashField, expected: hash160, received: serverHash160, swapId }
|
|
11725
11845
|
);
|
|
11726
11846
|
}
|
|
11727
|
-
const name =
|
|
11847
|
+
const name = _chunkLZQZYSOZcjs.getNetworkName.call(void 0, response.network);
|
|
11728
11848
|
const network = name === "bitcoin" ? "mainnet" : name === "mutinynet" ? "signet" : name;
|
|
11729
11849
|
const binds = verifyHtlcAddress(
|
|
11730
11850
|
response.btc_htlc_address,
|
|
@@ -11797,6 +11917,9 @@ function recoveredKeysChange(stored, index, derivedPreimageHash) {
|
|
|
11797
11917
|
function unboundTerms(fresh, swapParams) {
|
|
11798
11918
|
try {
|
|
11799
11919
|
switch (fresh.direction) {
|
|
11920
|
+
case "spark_to_evm":
|
|
11921
|
+
assertSparkFunding(fresh, _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.preimageHash));
|
|
11922
|
+
break;
|
|
11800
11923
|
case "lightning_to_arkade":
|
|
11801
11924
|
case "lightning_to_evm":
|
|
11802
11925
|
case "lightning_to_bitcoin":
|
|
@@ -11878,6 +12001,7 @@ var PAYOUT_FIELD = {
|
|
|
11878
12001
|
arkade_to_evm: "target_evm_address",
|
|
11879
12002
|
bitcoin_to_evm: "target_evm_address",
|
|
11880
12003
|
lightning_to_evm: "target_evm_address",
|
|
12004
|
+
spark_to_evm: "target_evm_address",
|
|
11881
12005
|
evm_to_bitcoin: "target_btc_address",
|
|
11882
12006
|
lightning_to_bitcoin: "target_btc_address",
|
|
11883
12007
|
btc_to_arkade: "target_arkade_address",
|
|
@@ -11911,7 +12035,7 @@ function assertAddressEchoed(response, field, requested) {
|
|
|
11911
12035
|
function invoiceKey(invoice) {
|
|
11912
12036
|
try {
|
|
11913
12037
|
return paymentHashOf(invoice);
|
|
11914
|
-
} catch (
|
|
12038
|
+
} catch (e6) {
|
|
11915
12039
|
return invoice;
|
|
11916
12040
|
}
|
|
11917
12041
|
}
|
|
@@ -11931,6 +12055,15 @@ function withStoredTerms(stored, fresh, refused) {
|
|
|
11931
12055
|
if (field in before) kept[field] = before[field];
|
|
11932
12056
|
else if (condemned.includes(field)) delete kept[field];
|
|
11933
12057
|
}
|
|
12058
|
+
if (stored.response.direction === "spark_to_evm") {
|
|
12059
|
+
const original = stored.response;
|
|
12060
|
+
kept.funding = {
|
|
12061
|
+
...original.funding,
|
|
12062
|
+
payment_id: fresh.direction === "spark_to_evm" ? _nullishCoalesce(_optionalChain([fresh, 'access', _64 => _64.funding, 'optionalAccess', _65 => _65.payment_id]), () => ( original.funding.payment_id)) : original.funding.payment_id
|
|
12063
|
+
};
|
|
12064
|
+
kept.source_amount = original.source_amount;
|
|
12065
|
+
kept.network = original.network;
|
|
12066
|
+
}
|
|
11934
12067
|
return kept;
|
|
11935
12068
|
}
|
|
11936
12069
|
function swapTermsChange(stored, fresh) {
|
|
@@ -11954,6 +12087,30 @@ function swapTermsChange(stored, fresh) {
|
|
|
11954
12087
|
};
|
|
11955
12088
|
const payout = _nullishCoalesce(compare(["direction", "bridge_target_chain"], (value) => value), () => ( compare(PAYOUT_FIELDS, addressKey)));
|
|
11956
12089
|
if (payout) return payout;
|
|
12090
|
+
if (stored.response.direction === "spark_to_evm" && fresh.direction === "spark_to_evm") {
|
|
12091
|
+
const old = stored.response;
|
|
12092
|
+
if (old.funding.address !== fresh.funding.address)
|
|
12093
|
+
return changed(
|
|
12094
|
+
"funding.address",
|
|
12095
|
+
old.funding.address,
|
|
12096
|
+
fresh.funding.address
|
|
12097
|
+
);
|
|
12098
|
+
if (old.funding.expiry_duration_secs !== fresh.funding.expiry_duration_secs)
|
|
12099
|
+
return changed(
|
|
12100
|
+
"funding.expiry_duration_secs",
|
|
12101
|
+
String(old.funding.expiry_duration_secs),
|
|
12102
|
+
String(fresh.funding.expiry_duration_secs)
|
|
12103
|
+
);
|
|
12104
|
+
if (old.source_amount !== fresh.source_amount)
|
|
12105
|
+
return changed("source_amount", old.source_amount, fresh.source_amount);
|
|
12106
|
+
if (old.network !== fresh.network)
|
|
12107
|
+
return changed("network", old.network, fresh.network);
|
|
12108
|
+
try {
|
|
12109
|
+
assertSparkFunding(fresh, stored.preimageHash);
|
|
12110
|
+
} catch (error) {
|
|
12111
|
+
return error instanceof SwapVerificationError ? error : changed("funding", "valid native Spark terms", String(error));
|
|
12112
|
+
}
|
|
12113
|
+
}
|
|
11957
12114
|
if (EVM_SOURCED.has(stored.response.direction)) return void 0;
|
|
11958
12115
|
const difference = _nullishCoalesce(_nullishCoalesce(compare(HASH_FIELDS, normalizeHash), () => ( compare(ADDRESS_FIELDS, (address2) => address2.toLowerCase()))), () => ( compare(INVOICE_FIELDS, invoiceKey)));
|
|
11959
12116
|
if (difference) return difference;
|
|
@@ -11971,6 +12128,50 @@ function swapTermsChange(stored, fresh) {
|
|
|
11971
12128
|
}
|
|
11972
12129
|
return void 0;
|
|
11973
12130
|
}
|
|
12131
|
+
function assertSparkFunding(data, ownHash) {
|
|
12132
|
+
const fail = (field, expected, received) => {
|
|
12133
|
+
throw new SwapVerificationError("Invalid native Spark funding terms", {
|
|
12134
|
+
field,
|
|
12135
|
+
expected,
|
|
12136
|
+
received,
|
|
12137
|
+
swapId: data.id
|
|
12138
|
+
});
|
|
12139
|
+
};
|
|
12140
|
+
if (normalizeHash(data.hash_lock) !== normalizeHash(ownHash)) {
|
|
12141
|
+
fail("hash_lock", ownHash, data.hash_lock);
|
|
12142
|
+
}
|
|
12143
|
+
let prefix;
|
|
12144
|
+
try {
|
|
12145
|
+
prefix = _chunkRYZSWESUcjs.bech32m.decode(
|
|
12146
|
+
data.funding.address,
|
|
12147
|
+
1023
|
|
12148
|
+
).prefix;
|
|
12149
|
+
} catch (e7) {
|
|
12150
|
+
fail(
|
|
12151
|
+
"funding.address",
|
|
12152
|
+
"valid Spark bech32m address",
|
|
12153
|
+
data.funding.address
|
|
12154
|
+
);
|
|
12155
|
+
return;
|
|
12156
|
+
}
|
|
12157
|
+
const expectedPrefix = data.network === "bitcoin" ? "spark" : data.network === "regtest" ? "sparkrt" : void 0;
|
|
12158
|
+
if (!expectedPrefix || prefix !== expectedPrefix)
|
|
12159
|
+
fail(
|
|
12160
|
+
"funding.address",
|
|
12161
|
+
_nullishCoalesce(expectedPrefix, () => ( "supported Spark network")),
|
|
12162
|
+
prefix
|
|
12163
|
+
);
|
|
12164
|
+
if (!Number.isSafeInteger(data.funding.expiry_duration_secs) || data.funding.expiry_duration_secs <= 0) {
|
|
12165
|
+
fail(
|
|
12166
|
+
"funding.expiry_duration_secs",
|
|
12167
|
+
"positive safe integer",
|
|
12168
|
+
String(data.funding.expiry_duration_secs)
|
|
12169
|
+
);
|
|
12170
|
+
}
|
|
12171
|
+
if (!/^[1-9][0-9]*$/.test(data.source_amount) || BigInt(data.source_amount) > 18446744073709551615n) {
|
|
12172
|
+
fail("source_amount", "positive u64 sats", data.source_amount);
|
|
12173
|
+
}
|
|
12174
|
+
}
|
|
11974
12175
|
var MAX_RETRIES = 10;
|
|
11975
12176
|
var SKIP_COUNT = 10;
|
|
11976
12177
|
function isHashCollisionError(message) {
|
|
@@ -12013,7 +12214,7 @@ async function createArkadeToEvmSwapGeneric(options, ctx, claimingAddressOverrid
|
|
|
12013
12214
|
const claimingAddress = _nullishCoalesce(claimingAddressOverride, () => ( deriveEvmAddress(swapParams.secretKey)));
|
|
12014
12215
|
const body = {
|
|
12015
12216
|
hash_lock: hashLock,
|
|
12016
|
-
arkade_htlc_script_version:
|
|
12217
|
+
arkade_htlc_script_version: _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
|
|
12017
12218
|
refund_pk: refundPk,
|
|
12018
12219
|
user_id: userId,
|
|
12019
12220
|
claiming_address: claimingAddress,
|
|
@@ -12021,13 +12222,14 @@ async function createArkadeToEvmSwapGeneric(options, ctx, claimingAddressOverrid
|
|
|
12021
12222
|
token_address: options.tokenAddress,
|
|
12022
12223
|
evm_chain_id: options.evmChainId,
|
|
12023
12224
|
amount_in: options.sourceAmount ? Number(options.sourceAmount) : void 0,
|
|
12024
|
-
amount_out: _optionalChain([options, 'access',
|
|
12225
|
+
amount_out: _optionalChain([options, 'access', _66 => _66.targetAmount, 'optionalAccess', _67 => _67.toString, 'call', _68 => _68()]),
|
|
12025
12226
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12026
12227
|
extra_fees: options.extraFees,
|
|
12228
|
+
promo_code: options.promoCode,
|
|
12027
12229
|
gasless: _nullishCoalesce(options.gasless, () => ( true)),
|
|
12028
|
-
bridge_target_chain: _optionalChain([options, 'access',
|
|
12029
|
-
bridge_target_token_address: _optionalChain([options, 'access',
|
|
12030
|
-
bridge_recipient_setup: _optionalChain([options, 'access',
|
|
12230
|
+
bridge_target_chain: _optionalChain([options, 'access', _69 => _69.bridgeParams, 'optionalAccess', _70 => _70.targetChain]),
|
|
12231
|
+
bridge_target_token_address: _optionalChain([options, 'access', _71 => _71.bridgeParams, 'optionalAccess', _72 => _72.targetTokenAddress]),
|
|
12232
|
+
bridge_recipient_setup: _optionalChain([options, 'access', _73 => _73.bridgeParams, 'optionalAccess', _74 => _74.recipientSetup])
|
|
12031
12233
|
};
|
|
12032
12234
|
const { data, error } = await ctx.apiClient.POST("/swap/arkade/evm", {
|
|
12033
12235
|
body
|
|
@@ -12050,8 +12252,8 @@ async function createArkadeToEvmSwapGeneric(options, ctx, claimingAddressOverrid
|
|
|
12050
12252
|
},
|
|
12051
12253
|
options.targetAddress,
|
|
12052
12254
|
{
|
|
12053
|
-
recipient: _optionalChain([options, 'access',
|
|
12054
|
-
recipientWallet: _optionalChain([options, 'access',
|
|
12255
|
+
recipient: _optionalChain([options, 'access', _75 => _75.bridgeParams, 'optionalAccess', _76 => _76.recipient]),
|
|
12256
|
+
recipientWallet: _optionalChain([options, 'access', _77 => _77.bridgeParams, 'optionalAccess', _78 => _78.recipientWallet])
|
|
12055
12257
|
}
|
|
12056
12258
|
);
|
|
12057
12259
|
return { response: data, swapParams };
|
|
@@ -12087,9 +12289,10 @@ async function createArkadeToLightningSwap(options, ctx) {
|
|
|
12087
12289
|
target_amount_sats: options.targetAmountSats,
|
|
12088
12290
|
refund_pk: refundPk,
|
|
12089
12291
|
user_id: userId,
|
|
12090
|
-
arkade_htlc_script_version:
|
|
12292
|
+
arkade_htlc_script_version: _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
|
|
12091
12293
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12092
|
-
extra_fees: options.extraFees
|
|
12294
|
+
extra_fees: options.extraFees,
|
|
12295
|
+
promo_code: options.promoCode
|
|
12093
12296
|
};
|
|
12094
12297
|
const { data, error } = await ctx.apiClient.POST("/swap/arkade/lightning", {
|
|
12095
12298
|
body
|
|
@@ -12118,7 +12321,7 @@ async function createBitcoinToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12118
12321
|
const claimingAddress = _nullishCoalesce(claimingAddressOverride, () => ( deriveEvmAddress(swapParams.secretKey)));
|
|
12119
12322
|
const body = {
|
|
12120
12323
|
hash_lock: hashLock,
|
|
12121
|
-
btc_htlc_script_version:
|
|
12324
|
+
btc_htlc_script_version: _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
|
|
12122
12325
|
refund_pk: refundPk,
|
|
12123
12326
|
user_id: userId,
|
|
12124
12327
|
claiming_address: claimingAddress,
|
|
@@ -12126,13 +12329,14 @@ async function createBitcoinToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12126
12329
|
token_address: options.tokenAddress,
|
|
12127
12330
|
evm_chain_id: options.evmChainId,
|
|
12128
12331
|
amount_in: options.sourceAmount,
|
|
12129
|
-
amount_out: _optionalChain([options, 'access',
|
|
12332
|
+
amount_out: _optionalChain([options, 'access', _79 => _79.targetAmount, 'optionalAccess', _80 => _80.toString, 'call', _81 => _81()]),
|
|
12130
12333
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12131
12334
|
extra_fees: options.extraFees,
|
|
12335
|
+
promo_code: options.promoCode,
|
|
12132
12336
|
gasless: _nullishCoalesce(options.gasless, () => ( true)),
|
|
12133
|
-
bridge_target_chain: _optionalChain([options, 'access',
|
|
12134
|
-
bridge_target_token_address: _optionalChain([options, 'access',
|
|
12135
|
-
bridge_recipient_setup: _optionalChain([options, 'access',
|
|
12337
|
+
bridge_target_chain: _optionalChain([options, 'access', _82 => _82.bridgeParams, 'optionalAccess', _83 => _83.targetChain]),
|
|
12338
|
+
bridge_target_token_address: _optionalChain([options, 'access', _84 => _84.bridgeParams, 'optionalAccess', _85 => _85.targetTokenAddress]),
|
|
12339
|
+
bridge_recipient_setup: _optionalChain([options, 'access', _86 => _86.bridgeParams, 'optionalAccess', _87 => _87.recipientSetup])
|
|
12136
12340
|
};
|
|
12137
12341
|
const { data, error } = await ctx.apiClient.POST("/swap/bitcoin/evm", {
|
|
12138
12342
|
body
|
|
@@ -12155,8 +12359,8 @@ async function createBitcoinToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12155
12359
|
},
|
|
12156
12360
|
options.targetAddress,
|
|
12157
12361
|
{
|
|
12158
|
-
recipient: _optionalChain([options, 'access',
|
|
12159
|
-
recipientWallet: _optionalChain([options, 'access',
|
|
12362
|
+
recipient: _optionalChain([options, 'access', _88 => _88.bridgeParams, 'optionalAccess', _89 => _89.recipient]),
|
|
12363
|
+
recipientWallet: _optionalChain([options, 'access', _90 => _90.bridgeParams, 'optionalAccess', _91 => _91.recipientWallet])
|
|
12160
12364
|
}
|
|
12161
12365
|
);
|
|
12162
12366
|
return { response: data, swapParams };
|
|
@@ -12180,8 +12384,9 @@ async function createBitcoinToArkadeSwap(options, ctx) {
|
|
|
12180
12384
|
target_arkade_address: options.targetAddress,
|
|
12181
12385
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12182
12386
|
extra_fees: options.extraFees,
|
|
12183
|
-
|
|
12184
|
-
|
|
12387
|
+
promo_code: options.promoCode,
|
|
12388
|
+
btc_htlc_script_version: _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
|
|
12389
|
+
arkade_htlc_script_version: _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT
|
|
12185
12390
|
};
|
|
12186
12391
|
const { data, error } = await ctx.apiClient.POST("/swap/bitcoin/arkade", {
|
|
12187
12392
|
body
|
|
@@ -12235,9 +12440,10 @@ async function createBitcoinToLightningSwap(options, ctx) {
|
|
|
12235
12440
|
target_amount_sats: options.targetAmountSats,
|
|
12236
12441
|
refund_pk: refundPk,
|
|
12237
12442
|
user_id: userId,
|
|
12238
|
-
btc_htlc_script_version:
|
|
12443
|
+
btc_htlc_script_version: _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
|
|
12239
12444
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12240
|
-
extra_fees: options.extraFees
|
|
12445
|
+
extra_fees: options.extraFees,
|
|
12446
|
+
promo_code: options.promoCode
|
|
12241
12447
|
};
|
|
12242
12448
|
const { data, error } = await ctx.apiClient.POST("/swap/bitcoin/lightning", {
|
|
12243
12449
|
body
|
|
@@ -12257,11 +12463,13 @@ async function createBitcoinToLightningSwap(options, ctx) {
|
|
|
12257
12463
|
});
|
|
12258
12464
|
return { response: data, swapParams };
|
|
12259
12465
|
}
|
|
12260
|
-
function fundingTermsOf(data) {
|
|
12261
|
-
if (
|
|
12466
|
+
function fundingTermsOf(data, depositor) {
|
|
12467
|
+
if (depositor) assertAddressEchoed(data, "client_evm_address", depositor);
|
|
12468
|
+
if (!data.evm_chain_id || !data.evm_coordinator_address || !data.evm_htlc_address || !data.server_evm_address || !data.evm_refund_locktime || data.source_amount === void 0 || data.source_amount === null || !_optionalChain([data, 'access', _92 => _92.source_token, 'optionalAccess', _93 => _93.token_id])) {
|
|
12262
12469
|
return void 0;
|
|
12263
12470
|
}
|
|
12264
12471
|
return {
|
|
12472
|
+
depositor: _optionalChain([depositor, 'optionalAccess', _94 => _94.toLowerCase, 'call', _95 => _95()]),
|
|
12265
12473
|
chainId: data.evm_chain_id,
|
|
12266
12474
|
coordinator: data.evm_coordinator_address.toLowerCase(),
|
|
12267
12475
|
htlcAddress: data.evm_htlc_address.toLowerCase(),
|
|
@@ -12271,7 +12479,7 @@ function fundingTermsOf(data) {
|
|
|
12271
12479
|
timelock: data.evm_refund_locktime,
|
|
12272
12480
|
sourceToken: data.source_token.token_id.toLowerCase(),
|
|
12273
12481
|
sourceAmount: String(data.source_amount),
|
|
12274
|
-
lockToken: _optionalChain([data, 'access',
|
|
12482
|
+
lockToken: _optionalChain([data, 'access', _96 => _96.evm_htlc_token, 'optionalAccess', _97 => _97.toLowerCase, 'call', _98 => _98()])
|
|
12275
12483
|
};
|
|
12276
12484
|
}
|
|
12277
12485
|
async function createEvmToArkadeSwapGeneric(options, ctx) {
|
|
@@ -12281,7 +12489,7 @@ async function createEvmToArkadeSwapGeneric(options, ctx) {
|
|
|
12281
12489
|
const hashLock = `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.preimageHash)}`;
|
|
12282
12490
|
const receiverPk = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.publicKey);
|
|
12283
12491
|
const userId = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.userId);
|
|
12284
|
-
const userAddress = options.gasless ?
|
|
12492
|
+
const userAddress = options.gasless ? deriveEvmAddress(swapParams.secretKey) : options.userAddress;
|
|
12285
12493
|
const { data, error } = await ctx.apiClient.POST("/swap/evm/arkade", {
|
|
12286
12494
|
body: {
|
|
12287
12495
|
hash_lock: hashLock,
|
|
@@ -12295,10 +12503,11 @@ async function createEvmToArkadeSwapGeneric(options, ctx) {
|
|
|
12295
12503
|
amount_out: options.targetAmount ? Number(options.targetAmount) : void 0,
|
|
12296
12504
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12297
12505
|
extra_fees: options.extraFees,
|
|
12506
|
+
promo_code: options.promoCode,
|
|
12298
12507
|
gasless: _nullishCoalesce(options.gasless, () => ( false)),
|
|
12299
|
-
arkade_htlc_script_version:
|
|
12300
|
-
bridge_source_chain: _optionalChain([options, 'access',
|
|
12301
|
-
bridge_source_token_address: _optionalChain([options, 'access',
|
|
12508
|
+
arkade_htlc_script_version: _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
|
|
12509
|
+
bridge_source_chain: _optionalChain([options, 'access', _99 => _99.inboundBridgeParams, 'optionalAccess', _100 => _100.sourceChain]),
|
|
12510
|
+
bridge_source_token_address: _optionalChain([options, 'access', _101 => _101.inboundBridgeParams, 'optionalAccess', _102 => _102.sourceTokenAddress])
|
|
12302
12511
|
}
|
|
12303
12512
|
});
|
|
12304
12513
|
if (error) {
|
|
@@ -12317,22 +12526,88 @@ async function createEvmToArkadeSwapGeneric(options, ctx) {
|
|
|
12317
12526
|
},
|
|
12318
12527
|
options.targetAddress,
|
|
12319
12528
|
void 0,
|
|
12320
|
-
{ evmFundingTerms: fundingTermsOf(data) }
|
|
12529
|
+
{ evmFundingTerms: fundingTermsOf(data, userAddress) }
|
|
12321
12530
|
);
|
|
12322
12531
|
return { response: data, swapParams };
|
|
12323
12532
|
});
|
|
12324
12533
|
}
|
|
12534
|
+
var DUST = 546n;
|
|
12535
|
+
function tolerance(bps) {
|
|
12536
|
+
const value = _nullishCoalesce(bps, () => ( 0));
|
|
12537
|
+
if (!Number.isInteger(value) || value < 0 || value > 100)
|
|
12538
|
+
throw new Error("Payment slippage must be between 0 and 100 basis points");
|
|
12539
|
+
return BigInt(value);
|
|
12540
|
+
}
|
|
12541
|
+
function floorOf(amount, bps) {
|
|
12542
|
+
const loss = amount * bps / 10000n;
|
|
12543
|
+
return amount - (loss < amount - DUST ? loss : amount - DUST);
|
|
12544
|
+
}
|
|
12545
|
+
var NETWORKS = [
|
|
12546
|
+
_chunkLZQZYSOZcjs.NETWORK,
|
|
12547
|
+
_chunkLZQZYSOZcjs.TEST_NETWORK,
|
|
12548
|
+
{ ..._chunkLZQZYSOZcjs.TEST_NETWORK, bech32: "bcrt" }
|
|
12549
|
+
];
|
|
12550
|
+
function bitcoinNetworkOf(address2) {
|
|
12551
|
+
const network = NETWORKS.find((candidate) => {
|
|
12552
|
+
try {
|
|
12553
|
+
_chunkLZQZYSOZcjs.Address.call(void 0, candidate).decode(address2);
|
|
12554
|
+
return true;
|
|
12555
|
+
} catch (e8) {
|
|
12556
|
+
return false;
|
|
12557
|
+
}
|
|
12558
|
+
});
|
|
12559
|
+
if (!network) throw new Error("Invalid Bitcoin recovery address");
|
|
12560
|
+
return network;
|
|
12561
|
+
}
|
|
12562
|
+
function commitBitcoinPayment(request, network) {
|
|
12563
|
+
const bps = tolerance(request.maxSlippageBps);
|
|
12564
|
+
const nominal = {
|
|
12565
|
+
recipients: request.recipients.map((r) => ({ ...r })),
|
|
12566
|
+
feeSats: request.feeSats
|
|
12567
|
+
};
|
|
12568
|
+
const { total, fee } = validateBitcoinPayout(nominal, network);
|
|
12569
|
+
const payout = {
|
|
12570
|
+
recipients: nominal.recipients.map((r) => ({
|
|
12571
|
+
address: r.address,
|
|
12572
|
+
amountSats: floorOf(BigInt(r.amountSats), bps).toString()
|
|
12573
|
+
})),
|
|
12574
|
+
feeSats: nominal.feeSats
|
|
12575
|
+
};
|
|
12576
|
+
const floors = validateBitcoinPayout(payout, network);
|
|
12577
|
+
return {
|
|
12578
|
+
payout,
|
|
12579
|
+
minimumPayoutSats: floors.total + floors.fee,
|
|
12580
|
+
nominalSats: total + fee
|
|
12581
|
+
};
|
|
12582
|
+
}
|
|
12583
|
+
function minimumBitcoinPayout(request, network) {
|
|
12584
|
+
return commitBitcoinPayment(request, network).minimumPayoutSats;
|
|
12585
|
+
}
|
|
12325
12586
|
async function createEvmToBitcoinSwap(options, ctx) {
|
|
12587
|
+
let payment;
|
|
12588
|
+
if (options.bitcoinPayout !== void 0) {
|
|
12589
|
+
if (options.sourceAmount !== void 0)
|
|
12590
|
+
throw new Error("Payments require an exact target amount");
|
|
12591
|
+
const committed = commitBitcoinPayment(
|
|
12592
|
+
options.bitcoinPayout,
|
|
12593
|
+
bitcoinNetworkOf(options.targetAddress)
|
|
12594
|
+
);
|
|
12595
|
+
if (!Number.isSafeInteger(options.targetAmount) || committed.nominalSats !== BigInt(options.targetAmount))
|
|
12596
|
+
throw new Error(
|
|
12597
|
+
"Payment total must equal recipients plus the Bitcoin fee"
|
|
12598
|
+
);
|
|
12599
|
+
payment = committed;
|
|
12600
|
+
}
|
|
12326
12601
|
return retryOnHashCollision(ctx, async () => {
|
|
12327
12602
|
const swapParams = await ctx.deriveSwapParams();
|
|
12328
12603
|
const hashLock = `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.preimageHash)}`;
|
|
12329
12604
|
const claimPk = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.publicKey);
|
|
12330
12605
|
const userId = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.userId);
|
|
12331
|
-
const userAddress = options.gasless ?
|
|
12606
|
+
const userAddress = options.gasless ? deriveEvmAddress(swapParams.secretKey) : options.userAddress;
|
|
12332
12607
|
const { data, error } = await ctx.apiClient.POST("/swap/evm/bitcoin", {
|
|
12333
12608
|
body: {
|
|
12334
12609
|
hash_lock: hashLock,
|
|
12335
|
-
btc_htlc_script_version:
|
|
12610
|
+
btc_htlc_script_version: _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
|
|
12336
12611
|
claim_pk: claimPk,
|
|
12337
12612
|
user_id: userId,
|
|
12338
12613
|
token_address: options.tokenAddress,
|
|
@@ -12340,12 +12615,14 @@ async function createEvmToBitcoinSwap(options, ctx) {
|
|
|
12340
12615
|
user_address: userAddress,
|
|
12341
12616
|
target_address: options.targetAddress,
|
|
12342
12617
|
amount_in: options.sourceAmount ? options.sourceAmount.toString() : void 0,
|
|
12618
|
+
minimum_payout_sats: payment ? Number(payment.minimumPayoutSats) : void 0,
|
|
12343
12619
|
amount_out: options.targetAmount ? Number(options.targetAmount) : void 0,
|
|
12344
12620
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12345
12621
|
extra_fees: options.extraFees,
|
|
12622
|
+
promo_code: options.promoCode,
|
|
12346
12623
|
gasless: _nullishCoalesce(options.gasless, () => ( false)),
|
|
12347
|
-
bridge_source_chain: _optionalChain([options, 'access',
|
|
12348
|
-
bridge_source_token_address: _optionalChain([options, 'access',
|
|
12624
|
+
bridge_source_chain: _optionalChain([options, 'access', _103 => _103.inboundBridgeParams, 'optionalAccess', _104 => _104.sourceChain]),
|
|
12625
|
+
bridge_source_token_address: _optionalChain([options, 'access', _105 => _105.inboundBridgeParams, 'optionalAccess', _106 => _106.sourceTokenAddress])
|
|
12349
12626
|
}
|
|
12350
12627
|
});
|
|
12351
12628
|
if (error) {
|
|
@@ -12364,7 +12641,10 @@ async function createEvmToBitcoinSwap(options, ctx) {
|
|
|
12364
12641
|
},
|
|
12365
12642
|
options.targetAddress,
|
|
12366
12643
|
void 0,
|
|
12367
|
-
{
|
|
12644
|
+
{
|
|
12645
|
+
evmFundingTerms: fundingTermsOf(data, userAddress),
|
|
12646
|
+
bitcoinPayout: _optionalChain([payment, 'optionalAccess', _107 => _107.payout])
|
|
12647
|
+
}
|
|
12368
12648
|
);
|
|
12369
12649
|
return { response: data, swapParams };
|
|
12370
12650
|
});
|
|
@@ -12388,7 +12668,7 @@ async function createEvmToLightningSwap(options, ctx) {
|
|
|
12388
12668
|
}
|
|
12389
12669
|
const swapParams = await ctx.deriveSwapParams();
|
|
12390
12670
|
const userId = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.userId);
|
|
12391
|
-
const userAddress = options.gasless ?
|
|
12671
|
+
const userAddress = options.gasless ? deriveEvmAddress(swapParams.secretKey) : options.userAddress;
|
|
12392
12672
|
const { data, error } = await ctx.apiClient.POST("/swap/evm/lightning", {
|
|
12393
12673
|
body: {
|
|
12394
12674
|
lightning_invoice: options.lightningInvoice,
|
|
@@ -12402,9 +12682,10 @@ async function createEvmToLightningSwap(options, ctx) {
|
|
|
12402
12682
|
user_id: userId,
|
|
12403
12683
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12404
12684
|
extra_fees: options.extraFees,
|
|
12685
|
+
promo_code: options.promoCode,
|
|
12405
12686
|
gasless: _nullishCoalesce(options.gasless, () => ( false)),
|
|
12406
|
-
bridge_source_chain: _optionalChain([options, 'access',
|
|
12407
|
-
bridge_source_token_address: _optionalChain([options, 'access',
|
|
12687
|
+
bridge_source_chain: _optionalChain([options, 'access', _108 => _108.inboundBridgeParams, 'optionalAccess', _109 => _109.sourceChain]),
|
|
12688
|
+
bridge_source_token_address: _optionalChain([options, 'access', _110 => _110.inboundBridgeParams, 'optionalAccess', _111 => _111.sourceTokenAddress])
|
|
12408
12689
|
}
|
|
12409
12690
|
});
|
|
12410
12691
|
if (error) {
|
|
@@ -12423,7 +12704,10 @@ async function createEvmToLightningSwap(options, ctx) {
|
|
|
12423
12704
|
},
|
|
12424
12705
|
void 0,
|
|
12425
12706
|
void 0,
|
|
12426
|
-
{
|
|
12707
|
+
{
|
|
12708
|
+
lightningPaymentHash,
|
|
12709
|
+
evmFundingTerms: fundingTermsOf(data, userAddress)
|
|
12710
|
+
}
|
|
12427
12711
|
);
|
|
12428
12712
|
return { response: data, swapParams };
|
|
12429
12713
|
}
|
|
@@ -12446,9 +12730,10 @@ async function createLightningToArkadeSwap(options, ctx) {
|
|
|
12446
12730
|
source_amount_sats: options.sourceAmountSats,
|
|
12447
12731
|
target_amount_sats: options.targetAmountSats,
|
|
12448
12732
|
target_arkade_address: options.targetAddress,
|
|
12449
|
-
arkade_htlc_script_version:
|
|
12733
|
+
arkade_htlc_script_version: _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
|
|
12450
12734
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12451
12735
|
extra_fees: options.extraFees,
|
|
12736
|
+
promo_code: options.promoCode,
|
|
12452
12737
|
// `undefined` is omitted from the JSON body so the server applies its
|
|
12453
12738
|
// default; an explicit "" is sent to blank the invoice description.
|
|
12454
12739
|
invoice_description: options.invoiceDescription
|
|
@@ -12488,9 +12773,10 @@ async function createLightningToBitcoinSwap(options, ctx) {
|
|
|
12488
12773
|
source_amount_sats: options.sourceAmountSats,
|
|
12489
12774
|
target_amount_sats: options.targetAmountSats,
|
|
12490
12775
|
target_address: options.targetAddress,
|
|
12491
|
-
btc_htlc_script_version:
|
|
12776
|
+
btc_htlc_script_version: _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
|
|
12492
12777
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12493
12778
|
extra_fees: options.extraFees,
|
|
12779
|
+
promo_code: options.promoCode,
|
|
12494
12780
|
invoice_description: options.invoiceDescription
|
|
12495
12781
|
};
|
|
12496
12782
|
const { data, error } = await ctx.apiClient.POST(
|
|
@@ -12531,14 +12817,15 @@ async function createLightningToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12531
12817
|
token_address: options.tokenAddress,
|
|
12532
12818
|
evm_chain_id: options.evmChainId,
|
|
12533
12819
|
amount_in: options.sourceAmount,
|
|
12534
|
-
amount_out: _optionalChain([options, 'access',
|
|
12820
|
+
amount_out: _optionalChain([options, 'access', _112 => _112.targetAmount, 'optionalAccess', _113 => _113.toString, 'call', _114 => _114()]),
|
|
12535
12821
|
invoice_description: options.invoiceDescription,
|
|
12536
12822
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12537
12823
|
extra_fees: options.extraFees,
|
|
12824
|
+
promo_code: options.promoCode,
|
|
12538
12825
|
gasless: _nullishCoalesce(options.gasless, () => ( true)),
|
|
12539
|
-
bridge_target_chain: _optionalChain([options, 'access',
|
|
12540
|
-
bridge_target_token_address: _optionalChain([options, 'access',
|
|
12541
|
-
bridge_recipient_setup: _optionalChain([options, 'access',
|
|
12826
|
+
bridge_target_chain: _optionalChain([options, 'access', _115 => _115.bridgeParams, 'optionalAccess', _116 => _116.targetChain]),
|
|
12827
|
+
bridge_target_token_address: _optionalChain([options, 'access', _117 => _117.bridgeParams, 'optionalAccess', _118 => _118.targetTokenAddress]),
|
|
12828
|
+
bridge_recipient_setup: _optionalChain([options, 'access', _119 => _119.bridgeParams, 'optionalAccess', _120 => _120.recipientSetup])
|
|
12542
12829
|
};
|
|
12543
12830
|
const { data, error } = await ctx.apiClient.POST("/swap/lightning/evm", {
|
|
12544
12831
|
body
|
|
@@ -12561,13 +12848,83 @@ async function createLightningToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12561
12848
|
},
|
|
12562
12849
|
options.targetAddress,
|
|
12563
12850
|
{
|
|
12564
|
-
recipient: _optionalChain([options, 'access',
|
|
12565
|
-
recipientWallet: _optionalChain([options, 'access',
|
|
12851
|
+
recipient: _optionalChain([options, 'access', _121 => _121.bridgeParams, 'optionalAccess', _122 => _122.recipient]),
|
|
12852
|
+
recipientWallet: _optionalChain([options, 'access', _123 => _123.bridgeParams, 'optionalAccess', _124 => _124.recipientWallet])
|
|
12853
|
+
}
|
|
12854
|
+
);
|
|
12855
|
+
return { response: data, swapParams };
|
|
12856
|
+
});
|
|
12857
|
+
}
|
|
12858
|
+
async function createSparkToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
12859
|
+
if (options.sourceAmount == null === (options.targetAmount == null)) {
|
|
12860
|
+
throw new Error("Provide exactly one of sourceAmount or targetAmount");
|
|
12861
|
+
}
|
|
12862
|
+
if (options.sourceAmount != null && (!Number.isSafeInteger(options.sourceAmount) || options.sourceAmount <= 0)) {
|
|
12863
|
+
throw new Error("sourceAmount must be a positive safe integer in sats");
|
|
12864
|
+
}
|
|
12865
|
+
return retryOnHashCollision(ctx, async () => {
|
|
12866
|
+
const swapParams = await ctx.deriveSwapParams();
|
|
12867
|
+
const hashLock = `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.preimageHash)}`;
|
|
12868
|
+
const userId = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.userId);
|
|
12869
|
+
const claimingAddress = _nullishCoalesce(claimingAddressOverride, () => ( deriveEvmAddress(swapParams.secretKey)));
|
|
12870
|
+
const body = {
|
|
12871
|
+
hash_lock: hashLock,
|
|
12872
|
+
user_id: userId,
|
|
12873
|
+
claiming_address: claimingAddress,
|
|
12874
|
+
target_address: options.targetAddress,
|
|
12875
|
+
token_address: options.tokenAddress,
|
|
12876
|
+
evm_chain_id: options.evmChainId,
|
|
12877
|
+
amount_in: options.sourceAmount,
|
|
12878
|
+
amount_out: _optionalChain([options, 'access', _125 => _125.targetAmount, 'optionalAccess', _126 => _126.toString, 'call', _127 => _127()]),
|
|
12879
|
+
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12880
|
+
extra_fees: options.extraFees,
|
|
12881
|
+
promo_code: options.promoCode,
|
|
12882
|
+
gasless: _nullishCoalesce(options.gasless, () => ( true)),
|
|
12883
|
+
bridge_target_chain: _optionalChain([options, 'access', _128 => _128.bridgeParams, 'optionalAccess', _129 => _129.targetChain]),
|
|
12884
|
+
bridge_target_token_address: _optionalChain([options, 'access', _130 => _130.bridgeParams, 'optionalAccess', _131 => _131.targetTokenAddress]),
|
|
12885
|
+
bridge_recipient_setup: _optionalChain([options, 'access', _132 => _132.bridgeParams, 'optionalAccess', _133 => _133.recipientSetup])
|
|
12886
|
+
};
|
|
12887
|
+
const { data, error } = await ctx.apiClient.POST("/swap/spark/evm", {
|
|
12888
|
+
body
|
|
12889
|
+
});
|
|
12890
|
+
if (error) {
|
|
12891
|
+
throw new Error(`Failed to create swap: ${JSON.stringify(error)}`);
|
|
12892
|
+
}
|
|
12893
|
+
if (!data) {
|
|
12894
|
+
throw new Error("No swap data returned");
|
|
12895
|
+
}
|
|
12896
|
+
assertSparkFunding(data, hashLock);
|
|
12897
|
+
if (options.sourceAmount != null && BigInt(data.source_amount) !== BigInt(options.sourceAmount)) {
|
|
12898
|
+
throw new Error(
|
|
12899
|
+
"Native Spark source amount differs from the requested amount"
|
|
12900
|
+
);
|
|
12901
|
+
}
|
|
12902
|
+
assertAddressEchoed(data, "target_evm_address", options.targetAddress);
|
|
12903
|
+
assertAddressEchoed(data, "client_evm_address", claimingAddress);
|
|
12904
|
+
await ctx.storeSwap(
|
|
12905
|
+
data.id,
|
|
12906
|
+
swapParams,
|
|
12907
|
+
{
|
|
12908
|
+
...data,
|
|
12909
|
+
direction: "spark_to_evm"
|
|
12910
|
+
},
|
|
12911
|
+
options.targetAddress,
|
|
12912
|
+
{
|
|
12913
|
+
recipient: _optionalChain([options, 'access', _134 => _134.bridgeParams, 'optionalAccess', _135 => _135.recipient]),
|
|
12914
|
+
recipientWallet: _optionalChain([options, 'access', _136 => _136.bridgeParams, 'optionalAccess', _137 => _137.recipientWallet])
|
|
12566
12915
|
}
|
|
12567
12916
|
);
|
|
12568
12917
|
return { response: data, swapParams };
|
|
12569
12918
|
});
|
|
12570
12919
|
}
|
|
12920
|
+
function assertPaymentClaimWindow(network, refundLocktime, alreadySubmitted = false, now = Math.floor(Date.now() / 1e3)) {
|
|
12921
|
+
if (!Number.isFinite(refundLocktime))
|
|
12922
|
+
throw new Error("Invalid Bitcoin refund expiry");
|
|
12923
|
+
if (!alreadySubmitted && refundLocktime - now < (network === "mainnet" ? 600 : 30))
|
|
12924
|
+
throw new Error(
|
|
12925
|
+
"Too close to Bitcoin refund expiry to safely reveal the payment preimage"
|
|
12926
|
+
);
|
|
12927
|
+
}
|
|
12571
12928
|
_chunk5JR6AJ3Ycjs.init_sha2.call(void 0, );
|
|
12572
12929
|
_chunk5JR6AJ3Ycjs.init_utils.call(void 0, );
|
|
12573
12930
|
var REQUEST_TIMEOUT_MS = 5e3;
|
|
@@ -12586,10 +12943,10 @@ var REGTEST_NETWORK2 = {
|
|
|
12586
12943
|
function toBtcSignerNetwork(network) {
|
|
12587
12944
|
switch (network) {
|
|
12588
12945
|
case "mainnet":
|
|
12589
|
-
return
|
|
12946
|
+
return _chunkLZQZYSOZcjs.NETWORK;
|
|
12590
12947
|
case "testnet":
|
|
12591
12948
|
case "signet":
|
|
12592
|
-
return
|
|
12949
|
+
return _chunkLZQZYSOZcjs.TEST_NETWORK;
|
|
12593
12950
|
case "regtest":
|
|
12594
12951
|
return REGTEST_NETWORK2;
|
|
12595
12952
|
default:
|
|
@@ -12598,9 +12955,9 @@ function toBtcSignerNetwork(network) {
|
|
|
12598
12955
|
}
|
|
12599
12956
|
function addressToScriptHash(address2, network) {
|
|
12600
12957
|
const net = toBtcSignerNetwork(network);
|
|
12601
|
-
const decoded =
|
|
12958
|
+
const decoded = _chunkLZQZYSOZcjs.Address.call(void 0, net).decode(address2);
|
|
12602
12959
|
if (!decoded) throw new Error(`Unrecognised Bitcoin address: ${address2}`);
|
|
12603
|
-
const script =
|
|
12960
|
+
const script = _chunkLZQZYSOZcjs.OutScript.encode(decoded);
|
|
12604
12961
|
return _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunk5JR6AJ3Ycjs.sha256.call(void 0, script).reverse());
|
|
12605
12962
|
}
|
|
12606
12963
|
var ElectrumWsClient = class {
|
|
@@ -12619,7 +12976,7 @@ var ElectrumWsClient = class {
|
|
|
12619
12976
|
#closed = false;
|
|
12620
12977
|
constructor(url, opts) {
|
|
12621
12978
|
this.#url = url;
|
|
12622
|
-
this.#log = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
12979
|
+
this.#log = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _138 => _138.onLog]), () => ( (() => {
|
|
12623
12980
|
})));
|
|
12624
12981
|
}
|
|
12625
12982
|
/**
|
|
@@ -12692,7 +13049,7 @@ var ElectrumWsClient = class {
|
|
|
12692
13049
|
handlers.delete(onChange);
|
|
12693
13050
|
if (handlers.size > 0) return;
|
|
12694
13051
|
this.#scriptHashHandlers.delete(scripthash);
|
|
12695
|
-
if (_optionalChain([this, 'access',
|
|
13052
|
+
if (_optionalChain([this, 'access', _139 => _139.#socket, 'optionalAccess', _140 => _140.readyState]) === WebSocket.OPEN) {
|
|
12696
13053
|
this.request("blockchain.scripthash.unsubscribe", [scripthash]).catch(
|
|
12697
13054
|
() => {
|
|
12698
13055
|
}
|
|
@@ -12712,7 +13069,7 @@ var ElectrumWsClient = class {
|
|
|
12712
13069
|
}
|
|
12713
13070
|
async #ensureConnected() {
|
|
12714
13071
|
if (this.#closed) throw new Error("Electrum client closed");
|
|
12715
|
-
if (_optionalChain([this, 'access',
|
|
13072
|
+
if (_optionalChain([this, 'access', _141 => _141.#socket, 'optionalAccess', _142 => _142.readyState]) === WebSocket.OPEN) return;
|
|
12716
13073
|
this.#connecting ??= this.#connect().finally(() => {
|
|
12717
13074
|
this.#connecting = null;
|
|
12718
13075
|
});
|
|
@@ -12735,7 +13092,7 @@ var ElectrumWsClient = class {
|
|
|
12735
13092
|
);
|
|
12736
13093
|
try {
|
|
12737
13094
|
socket.close();
|
|
12738
|
-
} catch (
|
|
13095
|
+
} catch (e9) {
|
|
12739
13096
|
}
|
|
12740
13097
|
}, CONNECT_TIMEOUT_MS);
|
|
12741
13098
|
socket.addEventListener("open", () => {
|
|
@@ -12785,7 +13142,7 @@ var ElectrumWsClient = class {
|
|
|
12785
13142
|
if (socket && socket.readyState !== WebSocket.CLOSED) {
|
|
12786
13143
|
try {
|
|
12787
13144
|
socket.close();
|
|
12788
|
-
} catch (
|
|
13145
|
+
} catch (e10) {
|
|
12789
13146
|
}
|
|
12790
13147
|
}
|
|
12791
13148
|
for (const [id, pending] of this.#pending) {
|
|
@@ -12825,7 +13182,7 @@ var ElectrumWsClient = class {
|
|
|
12825
13182
|
#startPing() {
|
|
12826
13183
|
this.#stopPing();
|
|
12827
13184
|
this.#pingTimer = setInterval(() => {
|
|
12828
|
-
if (_optionalChain([this, 'access',
|
|
13185
|
+
if (_optionalChain([this, 'access', _143 => _143.#socket, 'optionalAccess', _144 => _144.readyState]) !== WebSocket.OPEN) return;
|
|
12829
13186
|
this.request("server.ping", []).catch(() => {
|
|
12830
13187
|
if (this.#socket && this.#socket.readyState === WebSocket.OPEN) {
|
|
12831
13188
|
this.#teardownSocket(new Error("Electrum keepalive timed out"));
|
|
@@ -12850,7 +13207,7 @@ var ElectrumWsClient = class {
|
|
|
12850
13207
|
let parsed;
|
|
12851
13208
|
try {
|
|
12852
13209
|
parsed = JSON.parse(trimmed);
|
|
12853
|
-
} catch (
|
|
13210
|
+
} catch (e11) {
|
|
12854
13211
|
continue;
|
|
12855
13212
|
}
|
|
12856
13213
|
if (parsed.id !== void 0 && parsed.id !== null) {
|
|
@@ -12908,11 +13265,11 @@ async function electrumFetchTransactionOutputs(client, txid) {
|
|
|
12908
13265
|
let rawHex;
|
|
12909
13266
|
try {
|
|
12910
13267
|
rawHex = await client.request("blockchain.transaction.get", [txid]);
|
|
12911
|
-
} catch (
|
|
13268
|
+
} catch (e12) {
|
|
12912
13269
|
return null;
|
|
12913
13270
|
}
|
|
12914
13271
|
try {
|
|
12915
|
-
const tx =
|
|
13272
|
+
const tx = _chunkLZQZYSOZcjs.Transaction2.fromRaw(_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, rawHex), {
|
|
12916
13273
|
allowUnknownOutputs: true,
|
|
12917
13274
|
allowUnknownInputs: true,
|
|
12918
13275
|
disableScriptCheck: true
|
|
@@ -12922,7 +13279,7 @@ async function electrumFetchTransactionOutputs(client, txid) {
|
|
|
12922
13279
|
vout.push({ value: Number(_nullishCoalesce(tx.getOutput(i).amount, () => ( 0n))) });
|
|
12923
13280
|
}
|
|
12924
13281
|
return { vout };
|
|
12925
|
-
} catch (
|
|
13282
|
+
} catch (e13) {
|
|
12926
13283
|
return null;
|
|
12927
13284
|
}
|
|
12928
13285
|
}
|
|
@@ -12935,7 +13292,7 @@ async function electrumBroadcastTransaction(client, txHex) {
|
|
|
12935
13292
|
}
|
|
12936
13293
|
async function electrumWaitForOutputByAddress(client, address2, network, timeoutMs, opts) {
|
|
12937
13294
|
const scripthash = addressToScriptHash(address2, network);
|
|
12938
|
-
const safetyRecheckMs = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
13295
|
+
const safetyRecheckMs = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _145 => _145.safetyRecheckMs]), () => ( 5e3));
|
|
12939
13296
|
return new Promise((resolve, reject) => {
|
|
12940
13297
|
let settled = false;
|
|
12941
13298
|
let deadlineTimer = null;
|
|
@@ -12960,7 +13317,7 @@ async function electrumWaitForOutputByAddress(client, address2, network, timeout
|
|
|
12960
13317
|
network
|
|
12961
13318
|
);
|
|
12962
13319
|
if (output) finish({ ok: output });
|
|
12963
|
-
} catch (
|
|
13320
|
+
} catch (e14) {
|
|
12964
13321
|
} finally {
|
|
12965
13322
|
checking = false;
|
|
12966
13323
|
}
|
|
@@ -13052,7 +13409,7 @@ async function fetchTransactionOutputs(esploraUrls, txid) {
|
|
|
13052
13409
|
}
|
|
13053
13410
|
return await response.json();
|
|
13054
13411
|
});
|
|
13055
|
-
} catch (
|
|
13412
|
+
} catch (e15) {
|
|
13056
13413
|
return null;
|
|
13057
13414
|
}
|
|
13058
13415
|
}
|
|
@@ -13073,7 +13430,7 @@ async function fetchFeeRateEstimate(esploraUrls, targetBlocks) {
|
|
|
13073
13430
|
}
|
|
13074
13431
|
return rate;
|
|
13075
13432
|
});
|
|
13076
|
-
} catch (
|
|
13433
|
+
} catch (e16) {
|
|
13077
13434
|
return void 0;
|
|
13078
13435
|
}
|
|
13079
13436
|
}
|
|
@@ -13145,6 +13502,23 @@ async function broadcastTransactionWithRetry(esploraUrls, txHex, retries = 5) {
|
|
|
13145
13502
|
}
|
|
13146
13503
|
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
13147
13504
|
}
|
|
13505
|
+
async function fetchMinimumRelayFeeRate(esploraUrls) {
|
|
13506
|
+
try {
|
|
13507
|
+
return await withFallback(esploraUrls, async (url) => {
|
|
13508
|
+
const response = await fetchWithTimeout(
|
|
13509
|
+
`${url}/v1/fees/recommended`,
|
|
13510
|
+
LOOKUP_TIMEOUT_MS
|
|
13511
|
+
);
|
|
13512
|
+
if (!response.ok) throw new Error("Relay policy unavailable");
|
|
13513
|
+
const { minimumFee } = await response.json();
|
|
13514
|
+
if (typeof minimumFee !== "number" || !Number.isFinite(minimumFee) || minimumFee < 0)
|
|
13515
|
+
throw new Error("Invalid relay policy");
|
|
13516
|
+
return minimumFee;
|
|
13517
|
+
});
|
|
13518
|
+
} catch (e17) {
|
|
13519
|
+
return void 0;
|
|
13520
|
+
}
|
|
13521
|
+
}
|
|
13148
13522
|
_chunk5JR6AJ3Ycjs.init_utils.call(void 0, );
|
|
13149
13523
|
var KERNEL_DELEGATION_TARGET = "0xd6CEDDe84be40893d153Be9d467CD6aD37875b28";
|
|
13150
13524
|
var KERNEL_VERSION = "0.3.3";
|
|
@@ -13181,7 +13555,7 @@ function kernelErc1271Digest(innerHash, account, chainId) {
|
|
|
13181
13555
|
concat(KERNEL_WRAPPER_TYPEHASH, bytes32(innerHash))
|
|
13182
13556
|
);
|
|
13183
13557
|
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0,
|
|
13184
|
-
|
|
13558
|
+
_chunkEI5ILLQ3cjs.keccak_256.call(void 0, concat(_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, "1901"), domainSeparator, structHash))
|
|
13185
13559
|
)}`;
|
|
13186
13560
|
}
|
|
13187
13561
|
function wrapKernelErc1271Signature(signature) {
|
|
@@ -13194,7 +13568,7 @@ function wrapKernelErc1271Signature(signature) {
|
|
|
13194
13568
|
return `0x${ERC1271_SUDO_MODE_PREFIX}${hex2}`;
|
|
13195
13569
|
}
|
|
13196
13570
|
function keccak(data) {
|
|
13197
|
-
return
|
|
13571
|
+
return _chunkEI5ILLQ3cjs.keccak_256.call(void 0, data);
|
|
13198
13572
|
}
|
|
13199
13573
|
function utf8(s) {
|
|
13200
13574
|
return new TextEncoder().encode(s);
|
|
@@ -13274,7 +13648,7 @@ function encodeNativeCreate(params) {
|
|
|
13274
13648
|
abi,
|
|
13275
13649
|
functionName: "create",
|
|
13276
13650
|
args: [
|
|
13277
|
-
`0x${
|
|
13651
|
+
`0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, params.preimageHash)}`,
|
|
13278
13652
|
params.claimAddress,
|
|
13279
13653
|
BigInt(params.timelock)
|
|
13280
13654
|
]
|
|
@@ -13291,10 +13665,10 @@ function buildNativeClaimTx(params) {
|
|
|
13291
13665
|
}
|
|
13292
13666
|
const preimage = params.preimage.startsWith("0x") ? params.preimage : `0x${params.preimage}`;
|
|
13293
13667
|
const amount = BigInt(swap.evm_expected_sats);
|
|
13294
|
-
const callsHash =
|
|
13668
|
+
const callsHash = _chunkEI5ILLQ3cjs.computeCoordinatorCallsHash.call(void 0, []);
|
|
13295
13669
|
const signature = signEvmDigest(
|
|
13296
13670
|
secretKey,
|
|
13297
|
-
|
|
13671
|
+
_chunkEI5ILLQ3cjs.buildNativeRedeemDigest.call(void 0, {
|
|
13298
13672
|
htlcAddress: swap.evm_htlc_address,
|
|
13299
13673
|
chainId: swap.evm_chain_id,
|
|
13300
13674
|
htlcVersion: swap.evm_htlc_version,
|
|
@@ -13304,7 +13678,7 @@ function buildNativeClaimTx(params) {
|
|
|
13304
13678
|
timelock: swap.evm_refund_locktime,
|
|
13305
13679
|
caller,
|
|
13306
13680
|
destination,
|
|
13307
|
-
sweepToken:
|
|
13681
|
+
sweepToken: _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS,
|
|
13308
13682
|
minAmountOut: amount,
|
|
13309
13683
|
callsHash
|
|
13310
13684
|
})
|
|
@@ -13320,7 +13694,7 @@ function buildNativeClaimTx(params) {
|
|
|
13320
13694
|
swap.server_evm_address,
|
|
13321
13695
|
BigInt(swap.evm_refund_locktime),
|
|
13322
13696
|
destination,
|
|
13323
|
-
|
|
13697
|
+
_chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS,
|
|
13324
13698
|
amount,
|
|
13325
13699
|
callsHash,
|
|
13326
13700
|
signature.v,
|
|
@@ -13330,7 +13704,7 @@ function buildNativeClaimTx(params) {
|
|
|
13330
13704
|
})
|
|
13331
13705
|
};
|
|
13332
13706
|
}
|
|
13333
|
-
var selector = (signature) =>
|
|
13707
|
+
var selector = (signature) => _chunkEI5ILLQ3cjs.keccak2562.call(void 0, new TextEncoder().encode(signature)).slice(0, 10);
|
|
13334
13708
|
var SHAPES = {
|
|
13335
13709
|
// HTLCCoordinator.refundTo: the coordinator is the lock's sender (v6).
|
|
13336
13710
|
refundTo: {
|
|
@@ -13395,22 +13769,22 @@ function decodeRefundCall(data) {
|
|
|
13395
13769
|
kind,
|
|
13396
13770
|
preimageHash: `0x${values.hash}`,
|
|
13397
13771
|
amount: _chunkTNZW35XAcjs.decodeUint256.call(void 0, values.amount),
|
|
13398
|
-
token: "token" in values ? address2("token") :
|
|
13772
|
+
token: "token" in values ? address2("token") : _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS.toLowerCase(),
|
|
13399
13773
|
sender: "sender" in values ? address2("sender") : void 0,
|
|
13400
13774
|
claimAddress: address2("claim"),
|
|
13401
13775
|
timelock: Number(timelock)
|
|
13402
13776
|
};
|
|
13403
13777
|
}
|
|
13404
13778
|
function encodeRefundCall(to, call) {
|
|
13405
|
-
const word2 = (hex2) =>
|
|
13779
|
+
const word2 = (hex2) => _chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, hex2);
|
|
13406
13780
|
const uint = (value) => BigInt(value).toString(16).padStart(64, "0");
|
|
13407
13781
|
switch (call.kind) {
|
|
13408
13782
|
case "refundTo":
|
|
13409
|
-
return { to, data:
|
|
13783
|
+
return { to, data: _chunkEI5ILLQ3cjs.encodeRefundTo.call(void 0, to, call).data };
|
|
13410
13784
|
case "nativeRefundTo":
|
|
13411
|
-
return { to, data:
|
|
13785
|
+
return { to, data: _chunkEI5ILLQ3cjs.encodeNativeRefundTo.call(void 0, to, call).data };
|
|
13412
13786
|
case "nativeRefund":
|
|
13413
|
-
return { to, data:
|
|
13787
|
+
return { to, data: _chunkEI5ILLQ3cjs.encodeHtlcNativeRefundCallData.call(void 0, to, call).data };
|
|
13414
13788
|
case "refundFor":
|
|
13415
13789
|
case "nativeRefundFor": {
|
|
13416
13790
|
if (call.sender === void 0) {
|
|
@@ -13458,12 +13832,12 @@ async function claimViaGasless(params) {
|
|
|
13458
13832
|
const targetTokenAddress = String(swap.target_token.token_id);
|
|
13459
13833
|
const needsDexSwap = targetTokenAddress.toLowerCase() !== wbtcAddress.toLowerCase();
|
|
13460
13834
|
const sweepToken = needsDexSwap ? targetTokenAddress : wbtcAddress;
|
|
13461
|
-
if (!needsDexSwap &&
|
|
13835
|
+
if (!needsDexSwap && _chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, callsHash) !== _chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, _chunkEI5ILLQ3cjs.computeCoordinatorCallsHash.call(void 0, []))) {
|
|
13462
13836
|
throw new Error(
|
|
13463
13837
|
"Refusing the server's claim: server calls on a direct claim"
|
|
13464
13838
|
);
|
|
13465
13839
|
}
|
|
13466
|
-
const digest =
|
|
13840
|
+
const digest = _chunkEI5ILLQ3cjs.buildRedeemDigest.call(void 0, {
|
|
13467
13841
|
htlcAddress: swap.evm_htlc_address,
|
|
13468
13842
|
chainId: swap.evm_chain_id,
|
|
13469
13843
|
preimage: secretHex,
|
|
@@ -13500,15 +13874,15 @@ function alreadyClaimedStatus(errorText) {
|
|
|
13500
13874
|
const match = /cannot claim a swap in (client_redeeming|client_redeemed|server_redeemed)/.exec(
|
|
13501
13875
|
errorText
|
|
13502
13876
|
);
|
|
13503
|
-
return _optionalChain([match, 'optionalAccess',
|
|
13877
|
+
return _optionalChain([match, 'optionalAccess', _146 => _146[1]]);
|
|
13504
13878
|
}
|
|
13505
13879
|
async function postClaim(baseUrl, swapId, body) {
|
|
13506
13880
|
const response = await fetch(`${baseUrl}/swap/${swapId}/claim-gasless`, {
|
|
13507
13881
|
method: "POST",
|
|
13508
13882
|
headers: {
|
|
13509
13883
|
"Content-Type": "application/json",
|
|
13510
|
-
"X-Lendaswap-Client":
|
|
13511
|
-
...
|
|
13884
|
+
"X-Lendaswap-Client": _chunkLZQZYSOZcjs.CLIENT_AGENT,
|
|
13885
|
+
..._chunkLZQZYSOZcjs.PROTOCOL_HEADERS
|
|
13512
13886
|
},
|
|
13513
13887
|
body: JSON.stringify(body)
|
|
13514
13888
|
});
|
|
@@ -13731,8 +14105,8 @@ async function buildArkadeClaim(params) {
|
|
|
13731
14105
|
`Preimage hash are not equal. '${_chunkRYZSWESUcjs.hex.encode(_chunkBEW62OUTcjs.ripemd1602.call(void 0, _chunkRYZSWESUcjs.hex.decode(preimageHash)))}' vs ${preimageHashBytesString}'`
|
|
13732
14106
|
);
|
|
13733
14107
|
}
|
|
13734
|
-
const networkName =
|
|
13735
|
-
const serverUrl =
|
|
14108
|
+
const networkName = _chunkLZQZYSOZcjs.getNetworkName.call(void 0, network);
|
|
14109
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
|
|
13736
14110
|
const arkProvider = new (0, _chunkBEW62OUTcjs.RestOperatorProvider)(serverUrl);
|
|
13737
14111
|
const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
|
|
13738
14112
|
const serverInfo = await arkProvider.getInfo();
|
|
@@ -13748,13 +14122,13 @@ async function buildArkadeClaim(params) {
|
|
|
13748
14122
|
unilateralRefundWithoutReceiverDelay
|
|
13749
14123
|
)
|
|
13750
14124
|
};
|
|
13751
|
-
if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !==
|
|
14125
|
+
if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !== _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
|
|
13752
14126
|
throw new Error(
|
|
13753
14127
|
`Unsupported Arkade HTLC script version: ${arkadeHtlcScriptVersion}`
|
|
13754
14128
|
);
|
|
13755
14129
|
}
|
|
13756
|
-
const vhtlc = new (0,
|
|
13757
|
-
const hrp =
|
|
14130
|
+
const vhtlc = new (0, _chunkLZQZYSOZcjs.StrictVhtlcScript)(vhtlcOptions);
|
|
14131
|
+
const hrp = _chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, networkName);
|
|
13758
14132
|
const computedAddress = vhtlc.address(hrp, serverPkBytes);
|
|
13759
14133
|
const computedAddressStr = computedAddress.encode();
|
|
13760
14134
|
if (computedAddressStr !== vhtlcAddress) {
|
|
@@ -13897,8 +14271,8 @@ async function continueArkadeClaim(params) {
|
|
|
13897
14271
|
`Preimage hash are not equal. '${_chunkRYZSWESUcjs.hex.encode(_chunkBEW62OUTcjs.ripemd1602.call(void 0, _chunkRYZSWESUcjs.hex.decode(preimageHash)))}' vs ${preimageHashBytesString}'`
|
|
13898
14272
|
);
|
|
13899
14273
|
}
|
|
13900
|
-
const networkName =
|
|
13901
|
-
const serverUrl =
|
|
14274
|
+
const networkName = _chunkLZQZYSOZcjs.getNetworkName.call(void 0, network);
|
|
14275
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
|
|
13902
14276
|
const arkProvider = new (0, _chunkBEW62OUTcjs.RestOperatorProvider)(serverUrl);
|
|
13903
14277
|
const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
|
|
13904
14278
|
const vhtlcOptions = {
|
|
@@ -13913,13 +14287,13 @@ async function continueArkadeClaim(params) {
|
|
|
13913
14287
|
unilateralRefundWithoutReceiverDelay
|
|
13914
14288
|
)
|
|
13915
14289
|
};
|
|
13916
|
-
if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !==
|
|
14290
|
+
if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !== _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
|
|
13917
14291
|
throw new Error(
|
|
13918
14292
|
`Unsupported Arkade HTLC script version: ${arkadeHtlcScriptVersion}`
|
|
13919
14293
|
);
|
|
13920
14294
|
}
|
|
13921
|
-
const vhtlc = new (0,
|
|
13922
|
-
const hrp =
|
|
14295
|
+
const vhtlc = new (0, _chunkLZQZYSOZcjs.StrictVhtlcScript)(vhtlcOptions);
|
|
14296
|
+
const hrp = _chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, networkName);
|
|
13923
14297
|
const computedAddress = vhtlc.address(hrp, serverPkBytes);
|
|
13924
14298
|
const computedAddressStr = computedAddress.encode();
|
|
13925
14299
|
if (computedAddressStr !== vhtlcAddress) {
|
|
@@ -13967,7 +14341,7 @@ async function continueArkadeClaim(params) {
|
|
|
13967
14341
|
amount: BigInt(v.value)
|
|
13968
14342
|
},
|
|
13969
14343
|
tapLeafScript: [claimLeafScript],
|
|
13970
|
-
sighashType:
|
|
14344
|
+
sighashType: _chunkLZQZYSOZcjs.SigHash.ALL
|
|
13971
14345
|
}));
|
|
13972
14346
|
const intentProof = _chunkBEW62OUTcjs.Proof.create(intentMessage, intentInputs);
|
|
13973
14347
|
for (let i = 0; i < vtxos.length; i++) {
|
|
@@ -14171,7 +14545,7 @@ async function claimNativeViaRifRelay(params) {
|
|
|
14171
14545
|
"/relay",
|
|
14172
14546
|
rifEnvelope(request, signature)
|
|
14173
14547
|
);
|
|
14174
|
-
const txHash = _nullishCoalesce(relayed.txHash, () => (
|
|
14548
|
+
const txHash = _nullishCoalesce(relayed.txHash, () => ( _chunkEI5ILLQ3cjs.keccak2562.call(void 0, relayed.signedTx)));
|
|
14175
14549
|
const receipt = await signer.waitForReceipt(txHash);
|
|
14176
14550
|
if (receipt.status !== "success") {
|
|
14177
14551
|
throw new Error(`RIF Relay claim transaction ${txHash} reverted.`);
|
|
@@ -14282,13 +14656,13 @@ function encodeNativeRedeem(p) {
|
|
|
14282
14656
|
return HTLC_NATIVE_REDEEM_SELECTOR + word(p.preimage) + word(p.amount) + word(p.sender) + word(p.timelock);
|
|
14283
14657
|
}
|
|
14284
14658
|
function rifSmartWalletAddress(relay, owner) {
|
|
14285
|
-
const salt =
|
|
14659
|
+
const salt = _chunkEI5ILLQ3cjs.keccak2562.call(void 0,
|
|
14286
14660
|
`0x${strip0x(owner).toLowerCase()}${"0".repeat(40)}${word(BigInt(RIF_SMART_WALLET_INDEX))}`
|
|
14287
14661
|
);
|
|
14288
|
-
const initCodeHash =
|
|
14662
|
+
const initCodeHash = _chunkEI5ILLQ3cjs.keccak2562.call(void 0,
|
|
14289
14663
|
`0x602d3d8160093d39f3363d3d373d3d3d3d363d73${strip0x(relay.smart_wallet_template).toLowerCase()}5af43d923d90803e602b57fd5bf3`
|
|
14290
14664
|
);
|
|
14291
|
-
const hash =
|
|
14665
|
+
const hash = _chunkEI5ILLQ3cjs.keccak2562.call(void 0,
|
|
14292
14666
|
`0xff${strip0x(relay.smart_wallet_factory).toLowerCase()}${strip0x(salt)}${strip0x(initCodeHash)}`
|
|
14293
14667
|
);
|
|
14294
14668
|
return `0x${hash.slice(-40)}`;
|
|
@@ -14330,7 +14704,7 @@ async function rifResponse(response, path) {
|
|
|
14330
14704
|
let body;
|
|
14331
14705
|
try {
|
|
14332
14706
|
body = JSON.parse(text);
|
|
14333
|
-
} catch (
|
|
14707
|
+
} catch (e18) {
|
|
14334
14708
|
throw new Error(
|
|
14335
14709
|
`RIF Relay ${path} answered ${response.status}: ${text.slice(0, 200)}`
|
|
14336
14710
|
);
|
|
@@ -14362,8 +14736,8 @@ function buildRedeemAndExecuteTx(params) {
|
|
|
14362
14736
|
const amount = BigInt(swap.evm_expected_sats);
|
|
14363
14737
|
const targetTokenAddress = String(swap.target_token.token_id);
|
|
14364
14738
|
const sweepToken = targetTokenAddress.toLowerCase() !== wbtcAddress.toLowerCase() ? targetTokenAddress : wbtcAddress;
|
|
14365
|
-
const callsHash =
|
|
14366
|
-
const digest =
|
|
14739
|
+
const callsHash = _chunkEI5ILLQ3cjs.computeCoordinatorCallsHash.call(void 0, calls);
|
|
14740
|
+
const digest = _chunkEI5ILLQ3cjs.buildRedeemDigest.call(void 0, {
|
|
14367
14741
|
htlcAddress: swap.evm_htlc_address,
|
|
14368
14742
|
chainId: swap.evm_chain_id,
|
|
14369
14743
|
preimage: secretHex,
|
|
@@ -14379,7 +14753,7 @@ function buildRedeemAndExecuteTx(params) {
|
|
|
14379
14753
|
htlcVersion: swap.evm_htlc_version
|
|
14380
14754
|
});
|
|
14381
14755
|
const sig = signEvmDigest(secretKey, digest);
|
|
14382
|
-
const { to, data } =
|
|
14756
|
+
const { to, data } = _chunkEI5ILLQ3cjs.encodeRedeemAndExecute.call(void 0, swap.evm_coordinator_address, {
|
|
14383
14757
|
preimage: secretHex,
|
|
14384
14758
|
amount,
|
|
14385
14759
|
token: wbtcAddress,
|
|
@@ -14399,7 +14773,7 @@ async function claimViaUserOp(params) {
|
|
|
14399
14773
|
const { secretKey, swap, aa } = params;
|
|
14400
14774
|
const { to, data } = buildRedeemAndExecuteTx(params);
|
|
14401
14775
|
const signer = keyToKernelOwnerSigner(secretKey, swap.evm_chain_id);
|
|
14402
|
-
const { client } = await
|
|
14776
|
+
const { client } = await _chunkEI5ILLQ3cjs.createSwapSmartAccountClient.call(void 0, {
|
|
14403
14777
|
signer,
|
|
14404
14778
|
aa,
|
|
14405
14779
|
chain: _chunk7BLTE6ETcjs.arbitrum
|
|
@@ -14453,7 +14827,7 @@ async function claimViaSigner(params) {
|
|
|
14453
14827
|
`Replacement transaction ${minedHash} was mined, but its claim could not yet be verified. Check the swap status or transaction before submitting another claim.`
|
|
14454
14828
|
);
|
|
14455
14829
|
}
|
|
14456
|
-
if (_optionalChain([mined, 'access',
|
|
14830
|
+
if (_optionalChain([mined, 'access', _147 => _147.to, 'optionalAccess', _148 => _148.toLowerCase, 'call', _149 => _149()]) !== tx.to.toLowerCase() || mined.from.toLowerCase() !== signer.address.toLowerCase() || mined.input.toLowerCase() !== tx.data.toLowerCase()) {
|
|
14457
14831
|
throw new Error(
|
|
14458
14832
|
"The wallet replaced or cancelled the claim transaction. The claim was not submitted; try again from the payout wallet."
|
|
14459
14833
|
);
|
|
@@ -14589,7 +14963,7 @@ function formatApiError(error) {
|
|
|
14589
14963
|
}
|
|
14590
14964
|
try {
|
|
14591
14965
|
return JSON.stringify(error);
|
|
14592
|
-
} catch (
|
|
14966
|
+
} catch (e19) {
|
|
14593
14967
|
}
|
|
14594
14968
|
}
|
|
14595
14969
|
return String(error);
|
|
@@ -14599,7 +14973,7 @@ function buildRefundScriptVhtlc(params) {
|
|
|
14599
14973
|
const lendaswapPkBytes = parseXOnlyPubKey3(params.lendaswapPubKey);
|
|
14600
14974
|
const serverPkBytes = parseXOnlyPubKey3(params.arkadeServerPubKey);
|
|
14601
14975
|
const preimageHashBytes = parsePreimageHash(params.hashLock);
|
|
14602
|
-
const networkName =
|
|
14976
|
+
const networkName = _chunkLZQZYSOZcjs.getNetworkName.call(void 0, params.network);
|
|
14603
14977
|
const options = {
|
|
14604
14978
|
sender: userPkBytes,
|
|
14605
14979
|
receiver: lendaswapPkBytes,
|
|
@@ -14612,13 +14986,13 @@ function buildRefundScriptVhtlc(params) {
|
|
|
14612
14986
|
params.unilateralRefundWithoutReceiverDelay
|
|
14613
14987
|
)
|
|
14614
14988
|
};
|
|
14615
|
-
if (params.arkadeHtlcScriptVersion !== void 0 && params.arkadeHtlcScriptVersion !==
|
|
14989
|
+
if (params.arkadeHtlcScriptVersion !== void 0 && params.arkadeHtlcScriptVersion !== _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
|
|
14616
14990
|
throw new Error(
|
|
14617
14991
|
`Unsupported Arkade HTLC script version: ${params.arkadeHtlcScriptVersion}`
|
|
14618
14992
|
);
|
|
14619
14993
|
}
|
|
14620
|
-
const vhtlc = new (0,
|
|
14621
|
-
const hrp =
|
|
14994
|
+
const vhtlc = new (0, _chunkLZQZYSOZcjs.StrictVhtlcScript)(options);
|
|
14995
|
+
const hrp = _chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, networkName);
|
|
14622
14996
|
const computedAddress = vhtlc.address(hrp, serverPkBytes).encode();
|
|
14623
14997
|
if (computedAddress !== params.vhtlcAddress) {
|
|
14624
14998
|
throw new Error(
|
|
@@ -14629,7 +15003,7 @@ function buildRefundScriptVhtlc(params) {
|
|
|
14629
15003
|
}
|
|
14630
15004
|
async function collabRefundArkadeToEvmOffchain(params) {
|
|
14631
15005
|
const { vhtlc, networkName } = buildRefundScriptVhtlc(params);
|
|
14632
|
-
const serverUrl =
|
|
15006
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrlByName.call(void 0,
|
|
14633
15007
|
networkName,
|
|
14634
15008
|
params.arkadeServerUrl
|
|
14635
15009
|
);
|
|
@@ -14715,7 +15089,7 @@ async function collabRefundArkadeToEvmOffchain(params) {
|
|
|
14715
15089
|
}
|
|
14716
15090
|
async function collabRefundArkadeToEvmDelegate(params) {
|
|
14717
15091
|
const { vhtlc, networkName } = buildRefundScriptVhtlc(params);
|
|
14718
|
-
const serverUrl =
|
|
15092
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrlByName.call(void 0,
|
|
14719
15093
|
networkName,
|
|
14720
15094
|
params.arkadeServerUrl
|
|
14721
15095
|
);
|
|
@@ -14730,13 +15104,13 @@ async function collabRefundArkadeToEvmDelegate(params) {
|
|
|
14730
15104
|
}
|
|
14731
15105
|
const cosignerPkHex = cosignerRes.data.cosigner_pk;
|
|
14732
15106
|
const btcNetwork = _chunkBEW62OUTcjs.networks[networkName];
|
|
14733
|
-
const forfeitDecoded =
|
|
15107
|
+
const forfeitDecoded = _chunkLZQZYSOZcjs.Address.call(void 0, btcNetwork).decode(serverInfo.forfeitAddress);
|
|
14734
15108
|
if (!forfeitDecoded) {
|
|
14735
15109
|
throw new Error(
|
|
14736
15110
|
`Unrecognised forfeit address: ${serverInfo.forfeitAddress}`
|
|
14737
15111
|
);
|
|
14738
15112
|
}
|
|
14739
|
-
const forfeitPkScript =
|
|
15113
|
+
const forfeitPkScript = _chunkLZQZYSOZcjs.OutScript.encode(forfeitDecoded);
|
|
14740
15114
|
const vhtlcPkScript = _chunkRYZSWESUcjs.hex.encode(vhtlc.pkScript);
|
|
14741
15115
|
const { vtxos: allVtxos } = await indexerProvider.getVtxos({
|
|
14742
15116
|
scripts: [vhtlcPkScript]
|
|
@@ -14769,7 +15143,7 @@ async function collabRefundArkadeToEvmDelegate(params) {
|
|
|
14769
15143
|
amount: BigInt(v.value)
|
|
14770
15144
|
},
|
|
14771
15145
|
tapLeafScript: [tapLeafScript],
|
|
14772
|
-
sighashType:
|
|
15146
|
+
sighashType: _chunkLZQZYSOZcjs.SigHash.ALL
|
|
14773
15147
|
}));
|
|
14774
15148
|
const intentProof = _chunkBEW62OUTcjs.Proof.create(intentMessage, intentInputs, [
|
|
14775
15149
|
{ script: destination.pkScript, amount: totalAmount }
|
|
@@ -14795,7 +15169,7 @@ async function collabRefundArkadeToEvmDelegate(params) {
|
|
|
14795
15169
|
amount: vtxoAmount
|
|
14796
15170
|
},
|
|
14797
15171
|
tapLeafScript: [tapLeafScript],
|
|
14798
|
-
sighashType:
|
|
15172
|
+
sighashType: _chunkLZQZYSOZcjs.SigHash.ALL_ANYONECANPAY
|
|
14799
15173
|
});
|
|
14800
15174
|
forfeitTx.addOutput({
|
|
14801
15175
|
script: forfeitPkScript,
|
|
@@ -14971,13 +15345,15 @@ function fromWireQuoteResponse(wire) {
|
|
|
14971
15345
|
target_amount: wire.target_amount,
|
|
14972
15346
|
net_source_amount: wire.net_source_amount,
|
|
14973
15347
|
net_target_amount: wire.net_target_amount,
|
|
14974
|
-
bridge_fee: _nullishCoalesce(wire.bridge_fee, () => ( void 0))
|
|
15348
|
+
bridge_fee: _nullishCoalesce(wire.bridge_fee, () => ( void 0)),
|
|
15349
|
+
promo: _nullishCoalesce(wire.promo, () => ( void 0))
|
|
14975
15350
|
};
|
|
14976
15351
|
}
|
|
14977
15352
|
function fromWireReferralFeeResponse(wire) {
|
|
14978
15353
|
return {
|
|
14979
15354
|
extra_fee_rate: wire.extra_fee_rate,
|
|
14980
15355
|
base_fee_rate: _nullishCoalesce(wire.base_fee_rate, () => ( void 0)),
|
|
15356
|
+
promo: _nullishCoalesce(wire.promo, () => ( void 0)),
|
|
14981
15357
|
referral_label: _nullishCoalesce(wire.referral_label, () => ( void 0))
|
|
14982
15358
|
};
|
|
14983
15359
|
}
|
|
@@ -15011,7 +15387,7 @@ function isValidTronAddress(address2) {
|
|
|
15011
15387
|
try {
|
|
15012
15388
|
tronAddressToBytes32(address2);
|
|
15013
15389
|
return true;
|
|
15014
|
-
} catch (
|
|
15390
|
+
} catch (e20) {
|
|
15015
15391
|
return false;
|
|
15016
15392
|
}
|
|
15017
15393
|
}
|
|
@@ -15045,7 +15421,7 @@ function createSwapStatusWatcher(baseUrl) {
|
|
|
15045
15421
|
let parsed;
|
|
15046
15422
|
try {
|
|
15047
15423
|
parsed = JSON.parse(evt.data);
|
|
15048
|
-
} catch (
|
|
15424
|
+
} catch (e21) {
|
|
15049
15425
|
return;
|
|
15050
15426
|
}
|
|
15051
15427
|
if ("data" in parsed && parsed.channel === "swap_status") {
|
|
@@ -15064,8 +15440,8 @@ function createSwapStatusWatcher(baseUrl) {
|
|
|
15064
15440
|
});
|
|
15065
15441
|
socket.addEventListener("error", () => {
|
|
15066
15442
|
try {
|
|
15067
|
-
_optionalChain([socket, 'optionalAccess',
|
|
15068
|
-
} catch (
|
|
15443
|
+
_optionalChain([socket, 'optionalAccess', _150 => _150.close, 'call', _151 => _151()]);
|
|
15444
|
+
} catch (e22) {
|
|
15069
15445
|
}
|
|
15070
15446
|
});
|
|
15071
15447
|
}
|
|
@@ -15082,7 +15458,7 @@ function createSwapStatusWatcher(baseUrl) {
|
|
|
15082
15458
|
}, delay);
|
|
15083
15459
|
}
|
|
15084
15460
|
function sendSubscribe(ids) {
|
|
15085
|
-
if (ids.length === 0 || _optionalChain([socket, 'optionalAccess',
|
|
15461
|
+
if (ids.length === 0 || _optionalChain([socket, 'optionalAccess', _152 => _152.readyState]) !== WebSocket.OPEN) return;
|
|
15086
15462
|
const frame = {
|
|
15087
15463
|
op: "subscribe",
|
|
15088
15464
|
channel: "swap_status",
|
|
@@ -15091,7 +15467,7 @@ function createSwapStatusWatcher(baseUrl) {
|
|
|
15091
15467
|
socket.send(JSON.stringify(frame));
|
|
15092
15468
|
}
|
|
15093
15469
|
function sendUnsubscribe(ids) {
|
|
15094
|
-
if (ids.length === 0 || _optionalChain([socket, 'optionalAccess',
|
|
15470
|
+
if (ids.length === 0 || _optionalChain([socket, 'optionalAccess', _153 => _153.readyState]) !== WebSocket.OPEN) return;
|
|
15095
15471
|
const frame = {
|
|
15096
15472
|
op: "unsubscribe",
|
|
15097
15473
|
channel: "swap_status",
|
|
@@ -15107,8 +15483,8 @@ function createSwapStatusWatcher(baseUrl) {
|
|
|
15107
15483
|
reconnectTimer = null;
|
|
15108
15484
|
}
|
|
15109
15485
|
try {
|
|
15110
|
-
_optionalChain([socket, 'optionalAccess',
|
|
15111
|
-
} catch (
|
|
15486
|
+
_optionalChain([socket, 'optionalAccess', _154 => _154.close, 'call', _155 => _155()]);
|
|
15487
|
+
} catch (e23) {
|
|
15112
15488
|
}
|
|
15113
15489
|
socket = null;
|
|
15114
15490
|
}
|
|
@@ -15224,7 +15600,7 @@ function checkedRefundContext(checked) {
|
|
|
15224
15600
|
};
|
|
15225
15601
|
}
|
|
15226
15602
|
function permit2RefundAddress(serverData, depositorAddress) {
|
|
15227
|
-
if (!
|
|
15603
|
+
if (!_chunkEI5ILLQ3cjs.depositorIsSender.call(void 0, serverData.htlc_kind, serverData.htlc_version)) {
|
|
15228
15604
|
return serverData.coordinator_address;
|
|
15229
15605
|
}
|
|
15230
15606
|
if (!depositorAddress) {
|
|
@@ -15235,8 +15611,8 @@ function permit2RefundAddress(serverData, depositorAddress) {
|
|
|
15235
15611
|
return depositorAddress;
|
|
15236
15612
|
}
|
|
15237
15613
|
function ensureRehashMatchesRequest(signature, paymentHash, params) {
|
|
15238
|
-
const signed = `0x${
|
|
15239
|
-
if (signed !== `0x${
|
|
15614
|
+
const signed = `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, signature.newPreimageHash)}`;
|
|
15615
|
+
if (signed !== `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, paymentHash)}`) {
|
|
15240
15616
|
throw new Error(
|
|
15241
15617
|
`The server signed a rehash to ${signed}, not to the invoice's payment hash ${paymentHash}`
|
|
15242
15618
|
);
|
|
@@ -15246,18 +15622,18 @@ function ensureRehashMatchesRequest(signature, paymentHash, params) {
|
|
|
15246
15622
|
`The server signed a rehash with timelock ${signature.newTimelock}, later than the advertised ${params.newTimelock}`
|
|
15247
15623
|
);
|
|
15248
15624
|
}
|
|
15249
|
-
if (signature.htlcAddress.toLowerCase() !== params.htlcAddress.toLowerCase() || `0x${
|
|
15625
|
+
if (signature.htlcAddress.toLowerCase() !== params.htlcAddress.toLowerCase() || `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, signature.preimageHash)}` !== `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, params.preimageHash)}`) {
|
|
15250
15626
|
throw new Error(
|
|
15251
15627
|
"The server signed a rehash for another lock than the swap's"
|
|
15252
15628
|
);
|
|
15253
15629
|
}
|
|
15254
15630
|
}
|
|
15255
15631
|
function ensureLockIsOwn(lock, named, what) {
|
|
15256
|
-
const native = lock.token ===
|
|
15632
|
+
const native = lock.token === _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
|
|
15257
15633
|
const mismatches = [
|
|
15258
15634
|
named.htlcAddress.toLowerCase() !== lock.htlcAddress.toLowerCase() && "htlc address",
|
|
15259
15635
|
named.chainId !== lock.chainId && "chain",
|
|
15260
|
-
`0x${
|
|
15636
|
+
`0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, named.preimageHash)}` !== lock.preimageHash && "preimage hash",
|
|
15261
15637
|
BigInt(named.amount) !== lock.amount && "amount",
|
|
15262
15638
|
// A native lock keys a zero asset word whatever the server calls it.
|
|
15263
15639
|
!native && named.token.toLowerCase() !== lock.token && "token",
|
|
@@ -15282,7 +15658,7 @@ function rehashCallData(signature) {
|
|
|
15282
15658
|
r: signature.r,
|
|
15283
15659
|
s: signature.s
|
|
15284
15660
|
};
|
|
15285
|
-
return signature.htlcKind === "native" ?
|
|
15661
|
+
return signature.htlcKind === "native" ? _chunkEI5ILLQ3cjs.encodeHtlcNativeRehashCallData.call(void 0, signature.htlcAddress, terms) : _chunkEI5ILLQ3cjs.encodeHtlcErc20RehashCallData.call(void 0, signature.htlcAddress, {
|
|
15286
15662
|
...terms,
|
|
15287
15663
|
token: signature.token
|
|
15288
15664
|
});
|
|
@@ -15296,7 +15672,7 @@ function refundBySigCallData(signature) {
|
|
|
15296
15672
|
r: signature.r,
|
|
15297
15673
|
s: signature.s
|
|
15298
15674
|
};
|
|
15299
|
-
return signature.htlcKind === "native" ?
|
|
15675
|
+
return signature.htlcKind === "native" ? _chunkEI5ILLQ3cjs.encodeHtlcNativeRefundBySigCallData.call(void 0, signature.htlcAddress, terms) : _chunkEI5ILLQ3cjs.encodeHtlcErc20RefundBySigCallData.call(void 0, signature.htlcAddress, {
|
|
15300
15676
|
...terms,
|
|
15301
15677
|
token: signature.token
|
|
15302
15678
|
});
|
|
@@ -15323,7 +15699,7 @@ async function sendCall(signer, call, label, options = {}) {
|
|
|
15323
15699
|
type: _chunkTNZW35XAcjs.txTypeFor.call(void 0, signer.chainId),
|
|
15324
15700
|
gas: await _chunkTNZW35XAcjs.gasLimitFor.call(void 0, signer, call, _nullishCoalesce(options.fallbackGas, () => ( REFUND_GAS)))
|
|
15325
15701
|
});
|
|
15326
|
-
await _optionalChain([options, 'access',
|
|
15702
|
+
await _optionalChain([options, 'access', _156 => _156.onSent, 'optionalCall', _157 => _157(sent)]);
|
|
15327
15703
|
const receipt = await signer.waitForReceipt(sent);
|
|
15328
15704
|
if (receipt.status !== "success") {
|
|
15329
15705
|
const reason = await _chunkTNZW35XAcjs.getRevertReason.call(void 0, signer, sent, receipt.blockNumber);
|
|
@@ -15340,8 +15716,8 @@ async function sendCall(signer, call, label, options = {}) {
|
|
|
15340
15716
|
async function isSameCall(signer, hash, call) {
|
|
15341
15717
|
try {
|
|
15342
15718
|
const tx = await signer.getTransaction(hash);
|
|
15343
|
-
return _optionalChain([tx, 'optionalAccess',
|
|
15344
|
-
} catch (
|
|
15719
|
+
return _optionalChain([tx, 'optionalAccess', _158 => _158.to, 'optionalAccess', _159 => _159.toLowerCase, 'call', _160 => _160()]) === call.to.toLowerCase() && tx.input.toLowerCase() === call.data.toLowerCase();
|
|
15720
|
+
} catch (e24) {
|
|
15345
15721
|
return false;
|
|
15346
15722
|
}
|
|
15347
15723
|
}
|
|
@@ -15358,10 +15734,10 @@ function dedupeTxids(txids) {
|
|
|
15358
15734
|
function clientHashLockOf(stored) {
|
|
15359
15735
|
switch (stored.response.direction) {
|
|
15360
15736
|
case "evm_to_lightning":
|
|
15361
|
-
return _optionalChain([stored, 'access',
|
|
15737
|
+
return _optionalChain([stored, 'access', _161 => _161.lightningPaymentHash, 'optionalAccess', _162 => _162.hash]);
|
|
15362
15738
|
case "evm_to_bitcoin":
|
|
15363
15739
|
case "evm_to_arkade":
|
|
15364
|
-
return stored.preimageHash ? `0x${
|
|
15740
|
+
return stored.preimageHash ? `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, stored.preimageHash)}` : void 0;
|
|
15365
15741
|
default:
|
|
15366
15742
|
return void 0;
|
|
15367
15743
|
}
|
|
@@ -15373,7 +15749,7 @@ function evmHashLockOf(swap) {
|
|
|
15373
15749
|
return hash;
|
|
15374
15750
|
}
|
|
15375
15751
|
function evmSourceLeg(stored) {
|
|
15376
|
-
const rehashes = _optionalChain([stored, 'access',
|
|
15752
|
+
const rehashes = _optionalChain([stored, 'access', _163 => _163.evmRehashes, 'optionalAccess', _164 => _164.length]) ? stored.evmRehashes : void 0;
|
|
15377
15753
|
const swap = stored.response;
|
|
15378
15754
|
return {
|
|
15379
15755
|
chainId: swap.evm_chain_id,
|
|
@@ -15383,9 +15759,9 @@ function evmSourceLeg(stored) {
|
|
|
15383
15759
|
// without it, and switches to the current hash once a rehash is
|
|
15384
15760
|
// confirmed). The funding tx's SwapCreated is under the first hash, and
|
|
15385
15761
|
// the rehashes are followed from there.
|
|
15386
|
-
hashLock: _nullishCoalesce(_nullishCoalesce(_optionalChain([rehashes, 'optionalAccess',
|
|
15762
|
+
hashLock: _nullishCoalesce(_nullishCoalesce(_optionalChain([rehashes, 'optionalAccess', _165 => _165[0], 'optionalAccess', _166 => _166.fromHashLock]), () => ( clientHashLockOf(stored))), () => ( (swap.direction === "evm_to_bitcoin" ? swap.evm_hash_lock : swap.hash_lock))),
|
|
15387
15763
|
claimAddress: swap.server_evm_address,
|
|
15388
|
-
timelock: _nullishCoalesce(_optionalChain([rehashes, 'optionalAccess',
|
|
15764
|
+
timelock: _nullishCoalesce(_optionalChain([rehashes, 'optionalAccess', _167 => _167.at, 'call', _168 => _168(-1), 'optionalAccess', _169 => _169.timelock]), () => ( swap.evm_refund_locktime)),
|
|
15389
15765
|
// This client's own record first, then the server's copy (which names
|
|
15390
15766
|
// the rehash tx once a rehash is confirmed; that one carries no
|
|
15391
15767
|
// SwapCreated and is skipped as unavailable).
|
|
@@ -15396,20 +15772,20 @@ function evmSourceLeg(stored) {
|
|
|
15396
15772
|
// Read from the creation terms first, which a server refresh cannot
|
|
15397
15773
|
// rewrite; a swap recorded before they named the version falls back to
|
|
15398
15774
|
// the server's copy.
|
|
15399
|
-
depositorIsSender: _optionalChain([stored, 'access',
|
|
15775
|
+
depositorIsSender: _optionalChain([stored, 'access', _170 => _170.evmFundingTerms, 'optionalAccess', _171 => _171.htlcVersion]) !== void 0 ? _chunkEI5ILLQ3cjs.depositorIsSender.call(void 0,
|
|
15400
15776
|
stored.evmFundingTerms.htlcKind,
|
|
15401
15777
|
stored.evmFundingTerms.htlcVersion
|
|
15402
|
-
) :
|
|
15778
|
+
) : _chunkEI5ILLQ3cjs.depositorIsSender.call(void 0, swap.evm_htlc_kind, swap.evm_htlc_version)
|
|
15403
15779
|
};
|
|
15404
15780
|
}
|
|
15405
15781
|
function isDirectNativeLock(terms) {
|
|
15406
|
-
return terms.htlcKind === "native" && terms.coordinator.toLowerCase() ===
|
|
15782
|
+
return terms.htlcKind === "native" && terms.coordinator.toLowerCase() === _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
|
|
15407
15783
|
}
|
|
15408
15784
|
function provesNoLockUnder(receipt, hashLock) {
|
|
15409
15785
|
if (receipt.logs === void 0) return false;
|
|
15410
|
-
const hash = `0x${
|
|
15786
|
+
const hash = `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, hashLock)}`;
|
|
15411
15787
|
return !receipt.logs.some(
|
|
15412
|
-
(log) => log.topics.some((topic) => `0x${
|
|
15788
|
+
(log) => log.topics.some((topic) => `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, topic)}` === hash) || _optionalChain([_chunkEI5ILLQ3cjs.decodeSwapCreatedLog.call(void 0, log), 'optionalAccess', _172 => _172.preimageHash]) === hash
|
|
15413
15789
|
);
|
|
15414
15790
|
}
|
|
15415
15791
|
var serializeAmountInput = (amount) => amount == null ? void 0 : amount.toString();
|
|
@@ -15425,7 +15801,8 @@ function satsToLightningOptions(options, sourceName) {
|
|
|
15425
15801
|
const kind = classifyLightningDestination(destination);
|
|
15426
15802
|
const common = {
|
|
15427
15803
|
referralCode: options.referralCode,
|
|
15428
|
-
extraFees: options.extraFees
|
|
15804
|
+
extraFees: options.extraFees,
|
|
15805
|
+
promoCode: options.promoCode
|
|
15429
15806
|
};
|
|
15430
15807
|
if (kind === "invoice") {
|
|
15431
15808
|
if (options.sourceAmount != null && options.targetAmount != null) {
|
|
@@ -15467,10 +15844,10 @@ var DEFAULT_ELECTRUM_WS_URLS = {
|
|
|
15467
15844
|
mainnet: "wss://electrs.satora.io"
|
|
15468
15845
|
};
|
|
15469
15846
|
function defaultAaConfig() {
|
|
15470
|
-
if (!
|
|
15847
|
+
if (!_chunkLZQZYSOZcjs.DEFAULT_AA_BUNDLER_URL) return void 0;
|
|
15471
15848
|
return {
|
|
15472
|
-
bundlerUrl:
|
|
15473
|
-
...
|
|
15849
|
+
bundlerUrl: _chunkLZQZYSOZcjs.DEFAULT_AA_BUNDLER_URL,
|
|
15850
|
+
..._chunkLZQZYSOZcjs.DEFAULT_AA_POLICY_ID ? { paymasterPolicyId: _chunkLZQZYSOZcjs.DEFAULT_AA_POLICY_ID } : {}
|
|
15474
15851
|
};
|
|
15475
15852
|
}
|
|
15476
15853
|
var ClientBuilder = class {
|
|
@@ -15725,9 +16102,9 @@ var ClientBuilder = class {
|
|
|
15725
16102
|
baseUrl: this.#baseUrl.replace(/\/+$/, ""),
|
|
15726
16103
|
referralCode: this.#referralCode,
|
|
15727
16104
|
defaultHeaders: this.#defaultHeaders,
|
|
15728
|
-
esploraUrl: Array.isArray(this.#esploraUrl) ? this.#esploraUrl.map((url) => url.replace(/\/+$/, "")) : _optionalChain([this, 'access',
|
|
15729
|
-
electrumWsUrl: _optionalChain([this, 'access',
|
|
15730
|
-
arkadeServerUrl: _optionalChain([this, 'access',
|
|
16105
|
+
esploraUrl: Array.isArray(this.#esploraUrl) ? this.#esploraUrl.map((url) => url.replace(/\/+$/, "")) : _optionalChain([this, 'access', _173 => _173.#esploraUrl, 'optionalAccess', _174 => _174.replace, 'call', _175 => _175(/\/+$/, "")]),
|
|
16106
|
+
electrumWsUrl: _optionalChain([this, 'access', _176 => _176.#electrumWsUrl, 'optionalAccess', _177 => _177.replace, 'call', _178 => _178(/\/+$/, "")]),
|
|
16107
|
+
arkadeServerUrl: _optionalChain([this, 'access', _179 => _179.#arkadeServerUrl, 'optionalAccess', _180 => _180.replace, 'call', _181 => _181(/\/+$/, "")]),
|
|
15731
16108
|
aa: _nullishCoalesce(this.#aa, () => ( defaultAaConfig())),
|
|
15732
16109
|
solanaRpcUrl: this.#solanaRpcUrl,
|
|
15733
16110
|
logger: this.#logger,
|
|
@@ -15756,6 +16133,7 @@ var Client = class _Client {
|
|
|
15756
16133
|
#composeStaticCache = /* @__PURE__ */ new Map();
|
|
15757
16134
|
#signerStorage;
|
|
15758
16135
|
#swapStorage;
|
|
16136
|
+
#ephemeralKeyIndex = 0;
|
|
15759
16137
|
#statusWatcher = null;
|
|
15760
16138
|
#cctpInbound = null;
|
|
15761
16139
|
#electrumWs = null;
|
|
@@ -15783,8 +16161,8 @@ var Client = class _Client {
|
|
|
15783
16161
|
}
|
|
15784
16162
|
#apiHeaders(extra) {
|
|
15785
16163
|
return {
|
|
15786
|
-
"X-Lendaswap-Client":
|
|
15787
|
-
...
|
|
16164
|
+
"X-Lendaswap-Client": _chunkLZQZYSOZcjs.CLIENT_AGENT,
|
|
16165
|
+
..._chunkLZQZYSOZcjs.PROTOCOL_HEADERS,
|
|
15788
16166
|
..._nullishCoalesce(this.#config.defaultHeaders, () => ( {})),
|
|
15789
16167
|
..._nullishCoalesce(extra, () => ( {}))
|
|
15790
16168
|
};
|
|
@@ -15810,11 +16188,11 @@ var Client = class _Client {
|
|
|
15810
16188
|
* Remove `onUpdate` from the given swap ids.
|
|
15811
16189
|
*/
|
|
15812
16190
|
unsubscribeFromSwaps(swapIds, onUpdate) {
|
|
15813
|
-
_optionalChain([this, 'access',
|
|
16191
|
+
_optionalChain([this, 'access', _182 => _182.#statusWatcher, 'optionalAccess', _183 => _183.unsubscribe, 'call', _184 => _184(swapIds, onUpdate)]);
|
|
15814
16192
|
}
|
|
15815
16193
|
/** Force-close the shared swap-status socket. */
|
|
15816
16194
|
closeSwapStatusSocket() {
|
|
15817
|
-
_optionalChain([this, 'access',
|
|
16195
|
+
_optionalChain([this, 'access', _185 => _185.#statusWatcher, 'optionalAccess', _186 => _186.close, 'call', _187 => _187()]);
|
|
15818
16196
|
this.#statusWatcher = null;
|
|
15819
16197
|
}
|
|
15820
16198
|
/**
|
|
@@ -15924,7 +16302,7 @@ var Client = class _Client {
|
|
|
15924
16302
|
* @returns The derived swap parameters.
|
|
15925
16303
|
*/
|
|
15926
16304
|
async deriveSwapParams() {
|
|
15927
|
-
let index =
|
|
16305
|
+
let index = this.#ephemeralKeyIndex++;
|
|
15928
16306
|
if (this.#signerStorage) {
|
|
15929
16307
|
index = await this.#signerStorage.incrementKeyIndex();
|
|
15930
16308
|
}
|
|
@@ -15944,8 +16322,8 @@ var Client = class _Client {
|
|
|
15944
16322
|
/**
|
|
15945
16323
|
* Get the deterministic EVM address for this SDK key.
|
|
15946
16324
|
*
|
|
15947
|
-
*
|
|
15948
|
-
*
|
|
16325
|
+
* Legacy wallet-level address. New gasless swaps use their own deposit
|
|
16326
|
+
* address; read it from the swap response or getSwapDepositorKey(swapId).
|
|
15949
16327
|
*
|
|
15950
16328
|
* @returns Checksummed EVM address (0x-prefixed).
|
|
15951
16329
|
*/
|
|
@@ -16004,7 +16382,7 @@ var Client = class _Client {
|
|
|
16004
16382
|
* caller falls back to probing.
|
|
16005
16383
|
*/
|
|
16006
16384
|
#delegationHintFor(swap, depositor, hint) {
|
|
16007
|
-
const hinted = _optionalChain([swap, 'access',
|
|
16385
|
+
const hinted = _optionalChain([swap, 'access', _188 => _188.client_evm_address, 'optionalAccess', _189 => _189.toLowerCase, 'call', _190 => _190()]);
|
|
16008
16386
|
return hinted && hinted === depositor.toLowerCase() ? hint : void 0;
|
|
16009
16387
|
}
|
|
16010
16388
|
async #isKernelDelegated(address2, chainId, serverHint) {
|
|
@@ -16018,7 +16396,7 @@ var Client = class _Client {
|
|
|
16018
16396
|
);
|
|
16019
16397
|
}
|
|
16020
16398
|
if (chainId !== AA_CHAIN_ID) return false;
|
|
16021
|
-
const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access',
|
|
16399
|
+
const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _191 => _191.#config, 'access', _192 => _192.aa, 'optionalAccess', _193 => _193.rpcUrl]), () => ( _optionalChain([this, 'access', _194 => _194.#config, 'access', _195 => _195.aa, 'optionalAccess', _196 => _196.bundlerUrl])));
|
|
16022
16400
|
if (!rpcUrl) return false;
|
|
16023
16401
|
const { createPublicClient: createPublicClient2, http: http2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./_esm-4ZKYBBIE-D33574DC.cjs")));
|
|
16024
16402
|
const publicClient = createPublicClient2({ transport: http2(rpcUrl) });
|
|
@@ -16047,39 +16425,35 @@ var Client = class _Client {
|
|
|
16047
16425
|
*/
|
|
16048
16426
|
#getClaimEvmSigningKey(storedSwap) {
|
|
16049
16427
|
const swapKey = storedSwap.secretKey;
|
|
16050
|
-
const clientAddress = _optionalChain([storedSwap, 'access',
|
|
16428
|
+
const clientAddress = _optionalChain([storedSwap, 'access', _197 => _197.response, 'access', _198 => _198.client_evm_address, 'optionalAccess', _199 => _199.toLowerCase, 'call', _200 => _200()]);
|
|
16051
16429
|
if (swapKey && clientAddress && clientAddress === deriveEvmAddress(swapKey).toLowerCase()) {
|
|
16052
16430
|
return swapKey;
|
|
16053
16431
|
}
|
|
16054
16432
|
return this.#getEvmSigningKey();
|
|
16055
16433
|
}
|
|
16434
|
+
async #getFundingEvmSigningKey(storedSwap, gasless) {
|
|
16435
|
+
const depositor = _optionalChain([storedSwap, 'access', _201 => _201.evmFundingTerms, 'optionalAccess', _202 => _202.depositor]);
|
|
16436
|
+
if (depositor) {
|
|
16437
|
+
const { privateKey } = await this.getSwapDepositorKey(storedSwap.swapId);
|
|
16438
|
+
if (deriveEvmAddress(privateKey).toLowerCase() !== depositor.toLowerCase()) {
|
|
16439
|
+
throw new Error("Funding key does not match the pinned depositor.");
|
|
16440
|
+
}
|
|
16441
|
+
return privateKey;
|
|
16442
|
+
}
|
|
16443
|
+
return gasless ? this.#getCollabRefundEvmSigningKey(storedSwap) : this.#getEvmSigningKey();
|
|
16444
|
+
}
|
|
16056
16445
|
/**
|
|
16057
16446
|
* Select the SDK-controlled EVM key that matches the swap's recorded depositor.
|
|
16058
16447
|
*
|
|
16059
|
-
*
|
|
16060
|
-
*
|
|
16448
|
+
* New gasless EVM-sourced swaps use their per-swap key; existing swaps
|
|
16449
|
+
* may still use the deterministic wallet-level EVM key. Non-gasless SDK-funded
|
|
16061
16450
|
* swaps still use the per-swap key even though client_evm_address may point at
|
|
16062
16451
|
* the user's wallet rather than the later Permit2 depositor.
|
|
16063
16452
|
*/
|
|
16064
|
-
#getCollabRefundEvmSigningKey(storedSwap,
|
|
16065
|
-
|
|
16066
|
-
|
|
16067
|
-
|
|
16068
|
-
return swapKey;
|
|
16069
|
-
}
|
|
16070
|
-
const deterministicKey = this.#getEvmSigningKey();
|
|
16071
|
-
const deterministicAddress = deriveEvmAddress(deterministicKey);
|
|
16072
|
-
const swapAddress = deriveEvmAddress(swapKey);
|
|
16073
|
-
const clientAddress = _optionalChain([response, 'access', _180 => _180.client_evm_address, 'optionalAccess', _181 => _181.toLowerCase, 'call', _182 => _182()]);
|
|
16074
|
-
if (clientAddress === deterministicAddress.toLowerCase() || !clientAddress) {
|
|
16075
|
-
return deterministicKey;
|
|
16076
|
-
}
|
|
16077
|
-
if (clientAddress === swapAddress.toLowerCase()) {
|
|
16078
|
-
return swapKey;
|
|
16079
|
-
}
|
|
16080
|
-
throw new Error(
|
|
16081
|
-
`Cannot sign for this swap with an SDK-controlled key: swap depositor is ${_nullishCoalesce(response.client_evm_address, () => ( "unknown"))}, but SDK-controlled addresses are ${deterministicAddress} (current gasless key) and ${swapAddress} (legacy per-swap key). Use ${walletMethod} with the depositor wallet instead.`
|
|
16082
|
-
);
|
|
16453
|
+
async #getCollabRefundEvmSigningKey(storedSwap, _walletMethod = "collabRefundEvmWithSigner") {
|
|
16454
|
+
if (!_optionalChain([storedSwap, 'access', _203 => _203.evmFundingTerms, 'optionalAccess', _204 => _204.depositor]) && !storedSwap.response.gasless && storedSwap.evmDepositorKeyIndex === void 0 && !storedSwap.evmDepositorSecretKey)
|
|
16455
|
+
return storedSwap.secretKey;
|
|
16456
|
+
return (await this.getSwapDepositorKey(storedSwap.swapId)).privateKey;
|
|
16083
16457
|
}
|
|
16084
16458
|
/**
|
|
16085
16459
|
* Gets the current key index from storage.
|
|
@@ -16233,7 +16607,7 @@ var Client = class _Client {
|
|
|
16233
16607
|
"chain-config",
|
|
16234
16608
|
() => this.getChainConfig()
|
|
16235
16609
|
);
|
|
16236
|
-
return _optionalChain([config, 'access',
|
|
16610
|
+
return _optionalChain([config, 'access', _205 => _205.chains, 'access', _206 => _206.find, 'call', _207 => _207((c) => String(c.chain) === String(chainId)), 'optionalAccess', _208 => _208.rif_relay]);
|
|
16237
16611
|
}
|
|
16238
16612
|
/**
|
|
16239
16613
|
* The claim address of a native lock on a chain that claims through RIF
|
|
@@ -16263,7 +16637,11 @@ var Client = class _Client {
|
|
|
16263
16637
|
async getReferralFee(params) {
|
|
16264
16638
|
const { data, error } = await this.#apiClient.GET("/referral-fee", {
|
|
16265
16639
|
params: {
|
|
16266
|
-
query: {
|
|
16640
|
+
query: {
|
|
16641
|
+
ref: params.referralCode,
|
|
16642
|
+
extra_fees: params.extraFees,
|
|
16643
|
+
promo_code: params.promoCode
|
|
16644
|
+
}
|
|
16267
16645
|
}
|
|
16268
16646
|
});
|
|
16269
16647
|
if (error || !data) {
|
|
@@ -16334,12 +16712,14 @@ var Client = class _Client {
|
|
|
16334
16712
|
...params,
|
|
16335
16713
|
referralCode: _nullishCoalesce(params.referralCode, () => ( this.#config.referralCode))
|
|
16336
16714
|
};
|
|
16337
|
-
const
|
|
16715
|
+
const fetchReferralFee = () => this.getReferralFee({
|
|
16716
|
+
referralCode: params.referralCode,
|
|
16717
|
+
extraFees: params.extraFees,
|
|
16718
|
+
promoCode: params.promoCode
|
|
16719
|
+
});
|
|
16720
|
+
const referralFee = params.promoCode != null ? fetchReferralFee() : params.referralCode != null || params.extraFees != null ? this.#composeStatic(
|
|
16338
16721
|
`referral-fee|${_nullishCoalesce(params.referralCode, () => ( ""))}|${_nullishCoalesce(params.extraFees, () => ( ""))}`,
|
|
16339
|
-
|
|
16340
|
-
referralCode: params.referralCode,
|
|
16341
|
-
extraFees: params.extraFees
|
|
16342
|
-
})
|
|
16722
|
+
fetchReferralFee
|
|
16343
16723
|
) : Promise.resolve(void 0);
|
|
16344
16724
|
const [swapPairs, networkFees, chainConfig, referral] = await Promise.all([
|
|
16345
16725
|
this.#composeStatic("swap-pairs", () => this.getSwapPairs()),
|
|
@@ -16351,8 +16731,9 @@ var Client = class _Client {
|
|
|
16351
16731
|
swapPairs,
|
|
16352
16732
|
networkFees,
|
|
16353
16733
|
chainConfig,
|
|
16354
|
-
referralExtraFeeRate: _optionalChain([referral, 'optionalAccess',
|
|
16355
|
-
referralBaseFeeRate: _optionalChain([referral, 'optionalAccess',
|
|
16734
|
+
referralExtraFeeRate: _optionalChain([referral, 'optionalAccess', _209 => _209.extra_fee_rate]),
|
|
16735
|
+
referralBaseFeeRate: _optionalChain([referral, 'optionalAccess', _210 => _210.base_fee_rate]),
|
|
16736
|
+
referralPromo: _optionalChain([referral, 'optionalAccess', _211 => _211.promo]),
|
|
16356
16737
|
getDexQuote: (p) => this.getDexQuote(p)
|
|
16357
16738
|
});
|
|
16358
16739
|
}
|
|
@@ -16426,6 +16807,7 @@ var Client = class _Client {
|
|
|
16426
16807
|
// Per-call referral wins; fall back to the client default.
|
|
16427
16808
|
referralCode: _nullishCoalesce(params.referralCode, () => ( this.#config.referralCode)),
|
|
16428
16809
|
extraFees: params.extraFees,
|
|
16810
|
+
promoCode: params.promoCode,
|
|
16429
16811
|
bridgeRecipientSetup: params.bridgeRecipientSetup
|
|
16430
16812
|
});
|
|
16431
16813
|
} catch (err) {
|
|
@@ -16479,7 +16861,8 @@ var Client = class _Client {
|
|
|
16479
16861
|
target_amount_sats: params.targetAmountSats,
|
|
16480
16862
|
// Per-call referral wins; fall back to the client default.
|
|
16481
16863
|
ref: _nullishCoalesce(params.referralCode, () => ( this.#config.referralCode)),
|
|
16482
|
-
extra_fees: params.extraFees
|
|
16864
|
+
extra_fees: params.extraFees,
|
|
16865
|
+
promo_code: params.promoCode
|
|
16483
16866
|
}
|
|
16484
16867
|
}
|
|
16485
16868
|
});
|
|
@@ -16504,7 +16887,8 @@ var Client = class _Client {
|
|
|
16504
16887
|
protocolFeeRate: data.protocol_fee_rate,
|
|
16505
16888
|
minAmountSats: data.min_amount_sats,
|
|
16506
16889
|
maxAmountSats: data.max_amount_sats,
|
|
16507
|
-
exchangeRate: data.exchange_rate
|
|
16890
|
+
exchangeRate: data.exchange_rate,
|
|
16891
|
+
promo: _nullishCoalesce(data.promo, () => ( void 0))
|
|
16508
16892
|
};
|
|
16509
16893
|
}
|
|
16510
16894
|
/**
|
|
@@ -16532,7 +16916,8 @@ var Client = class _Client {
|
|
|
16532
16916
|
lnurl: kind === "lnurl" ? destination : void 0,
|
|
16533
16917
|
targetAmountSats,
|
|
16534
16918
|
referralCode: params.referralCode,
|
|
16535
|
-
extraFees: params.extraFees
|
|
16919
|
+
extraFees: params.extraFees,
|
|
16920
|
+
promoCode: params.promoCode
|
|
16536
16921
|
});
|
|
16537
16922
|
const sourceAmountOut = evmSource ? q.sourceAmount : sourcePinned ? q.sourceAmount : String(q.targetAmountSats);
|
|
16538
16923
|
const targetAmountOut = !evmSource && sourcePinned ? q.sourceAmount : String(q.targetAmountSats);
|
|
@@ -16547,7 +16932,8 @@ var Client = class _Client {
|
|
|
16547
16932
|
source_amount: sourceAmountOut,
|
|
16548
16933
|
target_amount: targetAmountOut,
|
|
16549
16934
|
net_source_amount: q.sourceAmount,
|
|
16550
|
-
net_target_amount: String(q.targetAmountSats)
|
|
16935
|
+
net_target_amount: String(q.targetAmountSats),
|
|
16936
|
+
promo: q.promo
|
|
16551
16937
|
};
|
|
16552
16938
|
}
|
|
16553
16939
|
/**
|
|
@@ -16640,7 +17026,8 @@ var Client = class _Client {
|
|
|
16640
17026
|
// Per-call referralCode wins; fall back to the client config default
|
|
16641
17027
|
// (set via withReferralCode / withOrgCode).
|
|
16642
17028
|
ref: _nullishCoalesce(params.referralCode, () => ( this.#config.referralCode)),
|
|
16643
|
-
extra_fees: params.extraFees
|
|
17029
|
+
extra_fees: params.extraFees,
|
|
17030
|
+
promo_code: params.promoCode
|
|
16644
17031
|
};
|
|
16645
17032
|
const { data, error } = await this.#apiClient.GET("/quote", {
|
|
16646
17033
|
params: {
|
|
@@ -16693,7 +17080,7 @@ var Client = class _Client {
|
|
|
16693
17080
|
if (comparableId(data.id) !== comparableId(id)) {
|
|
16694
17081
|
throw new Error(`Requested swap ${id}, but server returned ${data.id}`);
|
|
16695
17082
|
}
|
|
16696
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
17083
|
+
if (_optionalChain([options, 'optionalAccess', _212 => _212.updateStorage]) && this.#swapStorage) {
|
|
16697
17084
|
const stored = await this.#swapStorage.get(id);
|
|
16698
17085
|
const changed = stored ? swapTermsChange(stored, data) : void 0;
|
|
16699
17086
|
if (stored && changed) {
|
|
@@ -16862,6 +17249,35 @@ var Client = class _Client {
|
|
|
16862
17249
|
storedSwaps.push(stored);
|
|
16863
17250
|
}
|
|
16864
17251
|
}
|
|
17252
|
+
if (this.#swapStorage) {
|
|
17253
|
+
const recovered = await this.#swapStorage.getAll();
|
|
17254
|
+
for (const current of recovered) {
|
|
17255
|
+
if (_optionalChain([current, 'access', _213 => _213.evmFundingTerms, 'optionalAccess', _214 => _214.depositor]) || current.evmDepositorSecretKey)
|
|
17256
|
+
continue;
|
|
17257
|
+
const response = current.response;
|
|
17258
|
+
if (response.gasless !== false || !response.client_evm_address)
|
|
17259
|
+
continue;
|
|
17260
|
+
const predecessor = recovered.find(
|
|
17261
|
+
(candidate) => candidate.swapId !== current.swapId && ["clientrefunded", "clientrefundedserverrefunded"].includes(
|
|
17262
|
+
candidate.response.status
|
|
17263
|
+
) && candidate.keyIndex < current.keyIndex && deriveEvmAddress(
|
|
17264
|
+
this.deriveSwapParamsAtIndex(candidate.keyIndex).secretKey
|
|
17265
|
+
).toLowerCase() === deriveEvmAddress(candidate.secretKey).toLowerCase() && deriveEvmAddress(candidate.secretKey).toLowerCase() === response.client_evm_address.toLowerCase()
|
|
17266
|
+
);
|
|
17267
|
+
if (predecessor) {
|
|
17268
|
+
const updated = {
|
|
17269
|
+
...current,
|
|
17270
|
+
evmDepositorSecretKey: predecessor.secretKey,
|
|
17271
|
+
evmDepositorKeyIndex: predecessor.keyIndex
|
|
17272
|
+
};
|
|
17273
|
+
await this.#swapStorage.store(updated);
|
|
17274
|
+
const index = storedSwaps.findIndex(
|
|
17275
|
+
(swap) => swap.swapId === current.swapId
|
|
17276
|
+
);
|
|
17277
|
+
if (index >= 0) storedSwaps[index] = updated;
|
|
17278
|
+
}
|
|
17279
|
+
}
|
|
17280
|
+
}
|
|
16865
17281
|
const currentKeyIndex = await this.getKeyIndex();
|
|
16866
17282
|
const nextKeyIndex = Math.max(currentKeyIndex, data.next_index);
|
|
16867
17283
|
if (nextKeyIndex !== currentKeyIndex) {
|
|
@@ -17015,7 +17431,7 @@ var Client = class _Client {
|
|
|
17015
17431
|
}
|
|
17016
17432
|
const swap = storedSwap.response;
|
|
17017
17433
|
const secret = storedSwap.preimage;
|
|
17018
|
-
if (swap.direction === "arkade_to_evm" || swap.direction === "bitcoin_to_evm" || swap.direction === "lightning_to_evm") {
|
|
17434
|
+
if (swap.direction === "arkade_to_evm" || swap.direction === "bitcoin_to_evm" || swap.direction === "lightning_to_evm" || swap.direction === "spark_to_evm") {
|
|
17019
17435
|
const evmSwap = swap;
|
|
17020
17436
|
const bridgeTargetChain = evmSwap.bridge_target_chain;
|
|
17021
17437
|
const isSolanaBridge = bridgeTargetChain === "Solana";
|
|
@@ -17027,15 +17443,15 @@ var Client = class _Client {
|
|
|
17027
17443
|
message: "Gasless claim failed: no target address found. This swap may have been created before target address storage was implemented."
|
|
17028
17444
|
};
|
|
17029
17445
|
}
|
|
17030
|
-
const bridgeRecipient = _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
17031
|
-
const bridgeRecipientWallet = _optionalChain([options, 'optionalAccess',
|
|
17446
|
+
const bridgeRecipient = _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _215 => _215.bridgeRecipient]), () => ( storedSwap.bridgeRecipient)), () => ( (isTronBridge ? storedPayoutTarget(storedSwap) : void 0)));
|
|
17447
|
+
const bridgeRecipientWallet = _optionalChain([options, 'optionalAccess', _216 => _216.bridgeRecipient]) !== void 0 ? _optionalChain([options, 'optionalAccess', _217 => _217.bridgeRecipientWallet]) : storedSwap.bridgeRecipientWallet;
|
|
17032
17448
|
if (isSolanaBridge && !bridgeRecipient) {
|
|
17033
17449
|
return {
|
|
17034
17450
|
success: false,
|
|
17035
17451
|
message: "Solana bridge claim requires `bridgeRecipient` (the recipient's USDC ATA) in claim options. Derive it via `deriveSolanaUsdcAta` before calling claim."
|
|
17036
17452
|
};
|
|
17037
17453
|
}
|
|
17038
|
-
const gaslessResult = (swap.evm_chain_id === 30 || swap.evm_chain_id === 31) && _optionalChain([options, 'optionalAccess',
|
|
17454
|
+
const gaslessResult = (swap.evm_chain_id === 30 || swap.evm_chain_id === 31) && _optionalChain([options, 'optionalAccess', _218 => _218.signer]) ? await this.claimEvmWithSigner(id, options.signer, {
|
|
17039
17455
|
bridgeRecipient,
|
|
17040
17456
|
bridgeRecipientWallet
|
|
17041
17457
|
}) : await this.claimViaGasless(id, destination, {
|
|
@@ -17087,7 +17503,7 @@ var Client = class _Client {
|
|
|
17087
17503
|
const swap = await this.getSwap(id, {
|
|
17088
17504
|
updateStorage: true
|
|
17089
17505
|
});
|
|
17090
|
-
if (swap.direction !== "arkade_to_evm" && swap.direction !== "bitcoin_to_evm" && swap.direction !== "lightning_to_evm") {
|
|
17506
|
+
if (swap.direction !== "arkade_to_evm" && swap.direction !== "bitcoin_to_evm" && swap.direction !== "lightning_to_evm" && swap.direction !== "spark_to_evm") {
|
|
17091
17507
|
throw new Error(
|
|
17092
17508
|
`Expected an EVM-targeted swap (arkade_to_evm, bitcoin_to_evm or lightning_to_evm), got ${swap.direction}.`
|
|
17093
17509
|
);
|
|
@@ -17275,7 +17691,7 @@ var Client = class _Client {
|
|
|
17275
17691
|
}
|
|
17276
17692
|
/** Whether an EVM claim can use the existing automatic sponsorship path. */
|
|
17277
17693
|
canSponsorClaim(swap) {
|
|
17278
|
-
return (swap.direction === "arkade_to_evm" || swap.direction === "bitcoin_to_evm" || swap.direction === "lightning_to_evm") && swap.evm_chain_id !== 30 && swap.evm_chain_id !== 31;
|
|
17694
|
+
return (swap.direction === "arkade_to_evm" || swap.direction === "bitcoin_to_evm" || swap.direction === "lightning_to_evm" || swap.direction === "spark_to_evm") && swap.evm_chain_id !== 30 && swap.evm_chain_id !== 31;
|
|
17279
17695
|
}
|
|
17280
17696
|
/**
|
|
17281
17697
|
* Claims through the existing server relay or configured Arbitrum UserOp.
|
|
@@ -17367,7 +17783,7 @@ var Client = class _Client {
|
|
|
17367
17783
|
const targetTokenAddress = String(swap.target_token.token_id);
|
|
17368
17784
|
const needsDexSwap = targetTokenAddress.toLowerCase() !== swap.wbtc_address.toLowerCase();
|
|
17369
17785
|
let dexCalldata;
|
|
17370
|
-
if (needsDexSwap && _optionalChain([responseData, 'optionalAccess',
|
|
17786
|
+
if (needsDexSwap && _optionalChain([responseData, 'optionalAccess', _219 => _219.dex_calldata])) {
|
|
17371
17787
|
dexCalldata = {
|
|
17372
17788
|
to: responseData.dex_calldata.to,
|
|
17373
17789
|
data: responseData.dex_calldata.data,
|
|
@@ -17415,7 +17831,7 @@ var Client = class _Client {
|
|
|
17415
17831
|
* ```
|
|
17416
17832
|
*/
|
|
17417
17833
|
async claimArkade(id, options) {
|
|
17418
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
17834
|
+
if (!_optionalChain([options, 'optionalAccess', _220 => _220.destinationAddress])) {
|
|
17419
17835
|
return {
|
|
17420
17836
|
success: false,
|
|
17421
17837
|
message: 'Destination address is required for Arkade claims. Provide it via the options parameter: { destinationAddress: "ark1..." }'
|
|
@@ -17501,7 +17917,7 @@ var Client = class _Client {
|
|
|
17501
17917
|
electrum,
|
|
17502
17918
|
fundTxid
|
|
17503
17919
|
);
|
|
17504
|
-
if (_optionalChain([txData, 'optionalAccess',
|
|
17920
|
+
if (_optionalChain([txData, 'optionalAccess', _221 => _221.vout, 'optionalAccess', _222 => _222[fundVout]])) {
|
|
17505
17921
|
return {
|
|
17506
17922
|
txid: fundTxid,
|
|
17507
17923
|
vout: fundVout,
|
|
@@ -17537,7 +17953,7 @@ var Client = class _Client {
|
|
|
17537
17953
|
async #findOnchainHtlcOutputEsplora(esploraUrls, address2, fundTxid, fundVout) {
|
|
17538
17954
|
if (fundTxid && fundVout !== void 0) {
|
|
17539
17955
|
const txData = await fetchTransactionOutputs(esploraUrls, fundTxid);
|
|
17540
|
-
if (_optionalChain([txData, 'optionalAccess',
|
|
17956
|
+
if (_optionalChain([txData, 'optionalAccess', _223 => _223.vout, 'optionalAccess', _224 => _224[fundVout]])) {
|
|
17541
17957
|
return {
|
|
17542
17958
|
txid: fundTxid,
|
|
17543
17959
|
vout: fundVout,
|
|
@@ -17692,8 +18108,8 @@ var Client = class _Client {
|
|
|
17692
18108
|
try {
|
|
17693
18109
|
const result = await continueArkadeClaim({
|
|
17694
18110
|
...claimParams,
|
|
17695
|
-
destinationAddress: _optionalChain([options, 'optionalAccess',
|
|
17696
|
-
arkadeServerUrl: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
18111
|
+
destinationAddress: _optionalChain([options, 'optionalAccess', _225 => _225.destinationAddress]),
|
|
18112
|
+
arkadeServerUrl: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _226 => _226.arkadeServerUrl]), () => ( this.#config.arkadeServerUrl)),
|
|
17697
18113
|
logger: this.#config.logger,
|
|
17698
18114
|
logLevel: this.#config.logLevel
|
|
17699
18115
|
});
|
|
@@ -17811,7 +18227,7 @@ var Client = class _Client {
|
|
|
17811
18227
|
*/
|
|
17812
18228
|
async #claimArkadeDelegate(swapId, params, options) {
|
|
17813
18229
|
try {
|
|
17814
|
-
const result = await
|
|
18230
|
+
const result = await _chunkLZQZYSOZcjs.delegateClaim.call(void 0, {
|
|
17815
18231
|
...params,
|
|
17816
18232
|
destinationAddress: options.destinationAddress,
|
|
17817
18233
|
lendaswapApiUrl: this.#config.baseUrl,
|
|
@@ -17884,10 +18300,10 @@ var Client = class _Client {
|
|
|
17884
18300
|
}
|
|
17885
18301
|
if (direction === "evm_to_arkade" || direction === "evm_to_bitcoin" || direction === "evm_to_lightning") {
|
|
17886
18302
|
const evmOptions = options;
|
|
17887
|
-
if (_optionalChain([evmOptions, 'optionalAccess',
|
|
18303
|
+
if (_optionalChain([evmOptions, 'optionalAccess', _227 => _227.collaborative])) {
|
|
17888
18304
|
return this.#collabRefundEvm(id);
|
|
17889
18305
|
}
|
|
17890
|
-
return this.#buildEvmSourceRefund(id, storedSwap, _optionalChain([evmOptions, 'optionalAccess',
|
|
18306
|
+
return this.#buildEvmSourceRefund(id, storedSwap, _optionalChain([evmOptions, 'optionalAccess', _228 => _228.signer]));
|
|
17891
18307
|
}
|
|
17892
18308
|
return {
|
|
17893
18309
|
success: false,
|
|
@@ -17981,7 +18397,7 @@ var Client = class _Client {
|
|
|
17981
18397
|
}
|
|
17982
18398
|
const btcFundTxid = swap.btc_fund_txid;
|
|
17983
18399
|
const btcFundVout = swap.btc_fund_vout;
|
|
17984
|
-
const waitForFundingMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
18400
|
+
const waitForFundingMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _229 => _229.waitForFundingMs]), () => ( 3e4));
|
|
17985
18401
|
const htlcOutput = await this.#waitForOnchainHtlcOutput(
|
|
17986
18402
|
esploraUrls,
|
|
17987
18403
|
network,
|
|
@@ -17996,16 +18412,51 @@ var Client = class _Client {
|
|
|
17996
18412
|
message: `Could not find UTXO at HTLC address ${btcHtlcAddress} after waiting ${waitForFundingMs}ms. The server may not have funded the HTLC yet.`
|
|
17997
18413
|
};
|
|
17998
18414
|
}
|
|
17999
|
-
const
|
|
18000
|
-
if (
|
|
18415
|
+
const bitcoinPayout = storedSwap.bitcoinPayout;
|
|
18416
|
+
if (bitcoinPayout !== void 0 && _optionalChain([options, 'optionalAccess', _230 => _230.destinationAddress])) {
|
|
18417
|
+
return {
|
|
18418
|
+
success: false,
|
|
18419
|
+
message: "This swap pays stored Bitcoin recipients; destinationAddress cannot override them."
|
|
18420
|
+
};
|
|
18421
|
+
}
|
|
18422
|
+
const destinationAddress = bitcoinPayout !== void 0 ? "" : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _231 => _231.destinationAddress]), () => ( storedPayoutTarget(storedSwap)));
|
|
18423
|
+
if (bitcoinPayout === void 0 && !destinationAddress) {
|
|
18001
18424
|
return {
|
|
18002
18425
|
success: false,
|
|
18003
18426
|
message: 'Destination address is required to claim BTC. Provide it via options: { destinationAddress: "bc1p..." }'
|
|
18004
18427
|
};
|
|
18005
18428
|
}
|
|
18006
|
-
|
|
18429
|
+
let feeRateSatPerVb = await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _232 => _232.feeRateSatPerVb]), async () => ( Math.max(2, await _asyncNullishCoalesce(await fetchFeeRateEstimate(esploraUrls, 2), async () => ( 0)))));
|
|
18430
|
+
if (bitcoinPayout !== void 0) {
|
|
18431
|
+
const requested = _optionalChain([options, 'optionalAccess', _233 => _233.feeRateSatPerVb]);
|
|
18432
|
+
if (requested !== void 0 && (!Number.isFinite(requested) || requested <= 0))
|
|
18433
|
+
return {
|
|
18434
|
+
success: false,
|
|
18435
|
+
message: "Failed to build claim transaction: Fee rate must be a positive number of sat/vB"
|
|
18436
|
+
};
|
|
18437
|
+
const relayFloor = await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _234 => _234.minimumRelayFeeRateSatPerVb]), async () => ( (network === "regtest" ? 0 : await fetchMinimumRelayFeeRate(esploraUrls))));
|
|
18438
|
+
if (relayFloor === void 0 || !Number.isFinite(relayFloor) || relayFloor < 0)
|
|
18439
|
+
return {
|
|
18440
|
+
success: false,
|
|
18441
|
+
message: "Could not verify Bitcoin relay policy. Retry when the explorer is available or supply minimumRelayFeeRateSatPerVb."
|
|
18442
|
+
};
|
|
18443
|
+
feeRateSatPerVb = Math.max(feeRateSatPerVb, relayFloor);
|
|
18444
|
+
try {
|
|
18445
|
+
assertPaymentClaimWindow(
|
|
18446
|
+
network,
|
|
18447
|
+
btcRefundLocktime,
|
|
18448
|
+
!!storedSwap.bitcoinClaimBroadcast
|
|
18449
|
+
);
|
|
18450
|
+
} catch (error) {
|
|
18451
|
+
return {
|
|
18452
|
+
success: false,
|
|
18453
|
+
message: error instanceof Error ? error.message : String(error)
|
|
18454
|
+
};
|
|
18455
|
+
}
|
|
18456
|
+
}
|
|
18007
18457
|
try {
|
|
18008
18458
|
const result = buildOnchainClaimTransaction({
|
|
18459
|
+
bitcoinPayout,
|
|
18009
18460
|
fundingTxId: htlcOutput.txid,
|
|
18010
18461
|
fundingVout: htlcOutput.vout,
|
|
18011
18462
|
htlcAmount: htlcOutput.amount,
|
|
@@ -18015,17 +18466,26 @@ var Client = class _Client {
|
|
|
18015
18466
|
userSecretKey: storedSwap.secretKey,
|
|
18016
18467
|
preimage: storedSwap.preimage,
|
|
18017
18468
|
refundLocktime: btcRefundLocktime,
|
|
18018
|
-
|
|
18469
|
+
// Unused when a payout is stored; checked above otherwise.
|
|
18470
|
+
destinationAddress: _nullishCoalesce(destinationAddress, () => ( "")),
|
|
18019
18471
|
feeRateSatPerVb,
|
|
18020
18472
|
network,
|
|
18021
18473
|
btcHtlcScriptVersion
|
|
18022
18474
|
});
|
|
18023
18475
|
try {
|
|
18476
|
+
if (bitcoinPayout !== void 0 && this.#swapStorage) {
|
|
18477
|
+
const latest = await this.#swapStorage.get(storedSwap.swapId);
|
|
18478
|
+
await this.#swapStorage.store({
|
|
18479
|
+
..._nullishCoalesce(latest, () => ( storedSwap)),
|
|
18480
|
+
// Once submitted, even a timeout can mean the preimage is public.
|
|
18481
|
+
bitcoinClaimBroadcast: result.txId
|
|
18482
|
+
});
|
|
18483
|
+
}
|
|
18024
18484
|
await this.#broadcastBtcTx(
|
|
18025
18485
|
esploraUrls,
|
|
18026
18486
|
network,
|
|
18027
18487
|
result.txHex,
|
|
18028
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
18488
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _235 => _235.broadcastRetries]), () => ( 5))
|
|
18029
18489
|
);
|
|
18030
18490
|
return {
|
|
18031
18491
|
success: true,
|
|
@@ -18055,7 +18515,7 @@ var Client = class _Client {
|
|
|
18055
18515
|
* @internal
|
|
18056
18516
|
*/
|
|
18057
18517
|
async #buildOnchainRefund(id, swap, options) {
|
|
18058
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
18518
|
+
if (!_optionalChain([options, 'optionalAccess', _236 => _236.destinationAddress])) {
|
|
18059
18519
|
return {
|
|
18060
18520
|
success: false,
|
|
18061
18521
|
message: 'Destination address is required for on-chain refunds. Provide it via the options parameter: { destinationAddress: "bc1q..." }'
|
|
@@ -18261,7 +18721,7 @@ network='${network}'`
|
|
|
18261
18721
|
* @internal
|
|
18262
18722
|
*/
|
|
18263
18723
|
async #buildArkadeRefund(id, swap, options) {
|
|
18264
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
18724
|
+
if (!_optionalChain([options, 'optionalAccess', _237 => _237.destinationAddress])) {
|
|
18265
18725
|
return {
|
|
18266
18726
|
success: false,
|
|
18267
18727
|
message: 'Destination address is required for Arkade refunds. Provide it via the options parameter: { destinationAddress: "ark1..." }'
|
|
@@ -18402,7 +18862,7 @@ network='${network}'`
|
|
|
18402
18862
|
*/
|
|
18403
18863
|
async #refundArkadeDelegate(params, options) {
|
|
18404
18864
|
try {
|
|
18405
|
-
const result = await
|
|
18865
|
+
const result = await _chunkLZQZYSOZcjs.delegateRefund.call(void 0, {
|
|
18406
18866
|
...params,
|
|
18407
18867
|
lendaswapApiUrl: this.#config.baseUrl,
|
|
18408
18868
|
arkadeServerUrl: _nullishCoalesce(options.arkadeServerUrl, () => ( this.#config.arkadeServerUrl)),
|
|
@@ -18497,7 +18957,7 @@ network='${network}'`
|
|
|
18497
18957
|
const call = decodeRefundCall(server.data);
|
|
18498
18958
|
const to = server.to.toLowerCase();
|
|
18499
18959
|
const htlc = leg.htlcAddress.toLowerCase();
|
|
18500
|
-
const coordinator = _optionalChain([leg, 'access',
|
|
18960
|
+
const coordinator = _optionalChain([leg, 'access', _238 => _238.coordinatorAddress, 'optionalAccess', _239 => _239.toLowerCase, 'call', _240 => _240()]);
|
|
18501
18961
|
const signer = check.signer;
|
|
18502
18962
|
let lockSender;
|
|
18503
18963
|
let recipient;
|
|
@@ -18518,7 +18978,7 @@ network='${network}'`
|
|
|
18518
18978
|
`The server's refund targets ${server.to}, not this swap's HTLC ${leg.htlcAddress}`
|
|
18519
18979
|
);
|
|
18520
18980
|
}
|
|
18521
|
-
lockSender = _optionalChain([signer, 'optionalAccess',
|
|
18981
|
+
lockSender = _optionalChain([signer, 'optionalAccess', _241 => _241.address, 'access', _242 => _242.toLowerCase, 'call', _243 => _243()]);
|
|
18522
18982
|
recipient = lockSender;
|
|
18523
18983
|
break;
|
|
18524
18984
|
case "refundTo":
|
|
@@ -18549,7 +19009,7 @@ network='${network}'`
|
|
|
18549
19009
|
const read = async (tx, what) => {
|
|
18550
19010
|
try {
|
|
18551
19011
|
return decodeCallWord(await signer.call(tx), what);
|
|
18552
|
-
} catch (
|
|
19012
|
+
} catch (e25) {
|
|
18553
19013
|
return void 0;
|
|
18554
19014
|
}
|
|
18555
19015
|
};
|
|
@@ -18563,7 +19023,7 @@ network='${network}'`
|
|
|
18563
19023
|
timelock: call.timelock
|
|
18564
19024
|
};
|
|
18565
19025
|
const active = await read(
|
|
18566
|
-
|
|
19026
|
+
_chunkEI5ILLQ3cjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms),
|
|
18567
19027
|
"isActive"
|
|
18568
19028
|
);
|
|
18569
19029
|
if (active === 0n) {
|
|
@@ -18573,7 +19033,7 @@ network='${network}'`
|
|
|
18573
19033
|
}
|
|
18574
19034
|
if (call.kind === "refundTo" || call.kind === "nativeRefundTo") {
|
|
18575
19035
|
const deposit = await read(
|
|
18576
|
-
|
|
19036
|
+
_chunkEI5ILLQ3cjs.encodeDepositsCallData.call(void 0, to, _chunkEI5ILLQ3cjs.htlcSwapKey.call(void 0, terms)),
|
|
18577
19037
|
"deposits"
|
|
18578
19038
|
);
|
|
18579
19039
|
if (deposit !== void 0) {
|
|
@@ -18614,10 +19074,10 @@ network='${network}'`
|
|
|
18614
19074
|
`Swap ${swapId} has no payment hash recorded by this client at creation (it was recovered, or created by an older SDK), so the server's hash lock cannot be checked; refusing to fund or move it. Refund it instead.`
|
|
18615
19075
|
);
|
|
18616
19076
|
}
|
|
18617
|
-
return `0x${
|
|
19077
|
+
return `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, stored.lightningPaymentHash.hash)}`;
|
|
18618
19078
|
}
|
|
18619
19079
|
if (direction === "evm_to_bitcoin" || direction === "evm_to_arkade") {
|
|
18620
|
-
return `0x${
|
|
19080
|
+
return `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, stored.preimageHash)}`;
|
|
18621
19081
|
}
|
|
18622
19082
|
throw new Error(`Swap ${swapId} is ${direction}, not EVM-sourced`);
|
|
18623
19083
|
}
|
|
@@ -18637,7 +19097,7 @@ network='${network}'`
|
|
|
18637
19097
|
}
|
|
18638
19098
|
#fundingExpectation(swapId, stored) {
|
|
18639
19099
|
const hashLock = this.#clientHashLock(swapId, stored);
|
|
18640
|
-
const terms = _optionalChain([stored, 'optionalAccess',
|
|
19100
|
+
const terms = _optionalChain([stored, 'optionalAccess', _244 => _244.evmFundingTerms]);
|
|
18641
19101
|
if (!terms) {
|
|
18642
19102
|
throw new Error(
|
|
18643
19103
|
`Swap ${swapId} has no funding terms recorded by this client at creation (it was recovered, or created by an older SDK), so the server's funding payload cannot be checked; refusing to fund it. Refund it instead.`
|
|
@@ -18664,7 +19124,7 @@ network='${network}'`
|
|
|
18664
19124
|
`Swap ${swapId} locks on chain ${terms.chainId}, not ${chainId}`
|
|
18665
19125
|
);
|
|
18666
19126
|
}
|
|
18667
|
-
return
|
|
19127
|
+
return _chunkEI5ILLQ3cjs.checkFundingPayload.call(void 0, terms, hashLock, payload, pins);
|
|
18668
19128
|
}
|
|
18669
19129
|
/** Throws unless `hash` is the one {@link #clientHashLock} fixed. */
|
|
18670
19130
|
async #ensureClientHashLock(swapId, hash, what) {
|
|
@@ -18672,7 +19132,7 @@ network='${network}'`
|
|
|
18672
19132
|
swapId,
|
|
18673
19133
|
await this.getStoredSwap(swapId)
|
|
18674
19134
|
);
|
|
18675
|
-
if (`0x${
|
|
19135
|
+
if (`0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, hash)}` !== expected) {
|
|
18676
19136
|
throw new Error(
|
|
18677
19137
|
`The server's ${what} locks under hash ${hash}, not this swap's ${expected}; refusing to sign or send it`
|
|
18678
19138
|
);
|
|
@@ -18710,7 +19170,7 @@ network='${network}'`
|
|
|
18710
19170
|
if (!this.#swapStorage) return;
|
|
18711
19171
|
try {
|
|
18712
19172
|
const stored = await this.#swapStorage.get(swapId);
|
|
18713
|
-
if (_optionalChain([stored, 'optionalAccess',
|
|
19173
|
+
if (_optionalChain([stored, 'optionalAccess', _245 => _245.evmFundTxid, 'optionalAccess', _246 => _246.toLowerCase, 'call', _247 => _247()]) !== txid.toLowerCase()) return;
|
|
18714
19174
|
await this.#swapStorage.store({
|
|
18715
19175
|
...stored,
|
|
18716
19176
|
evmFundTxid: void 0,
|
|
@@ -18734,16 +19194,29 @@ network='${network}'`
|
|
|
18734
19194
|
* browser wallet usually cannot. Otherwise the wallet itself is the owner.
|
|
18735
19195
|
* `hint` is appended to the error when neither is.
|
|
18736
19196
|
*/
|
|
18737
|
-
#depositorOwnerSigner(swapResponse, walletSigner, hint) {
|
|
18738
|
-
const
|
|
18739
|
-
|
|
18740
|
-
|
|
18741
|
-
}
|
|
18742
|
-
if (walletSigner && depositor === walletSigner.address.toLowerCase()) {
|
|
19197
|
+
async #depositorOwnerSigner(swapResponse, walletSigner, hint) {
|
|
19198
|
+
const stored = await this.getStoredSwap(swapResponse.id);
|
|
19199
|
+
const depositor = _optionalChain([(_nullishCoalesce(_optionalChain([stored, 'optionalAccess', _248 => _248.evmFundingTerms, 'optionalAccess', _249 => _249.depositor]), () => ( swapResponse.client_evm_address))), 'optionalAccess', _250 => _250.toLowerCase, 'call', _251 => _251()]);
|
|
19200
|
+
if (walletSigner && depositor === walletSigner.address.toLowerCase())
|
|
18743
19201
|
return walletSigner;
|
|
19202
|
+
if (depositor === this.getEvmAddress().toLowerCase())
|
|
19203
|
+
return keyToKernelOwnerSigner(
|
|
19204
|
+
this.#signer.deriveEvmKey().secretKey,
|
|
19205
|
+
42161
|
|
19206
|
+
);
|
|
19207
|
+
try {
|
|
19208
|
+
const { privateKey, address: address2 } = await this.getSwapDepositorKey(
|
|
19209
|
+
swapResponse.id
|
|
19210
|
+
);
|
|
19211
|
+
if (address2.toLowerCase() === depositor)
|
|
19212
|
+
return keyToKernelOwnerSigner(
|
|
19213
|
+
_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, privateKey.replace(/^0x/, "")),
|
|
19214
|
+
42161
|
|
19215
|
+
);
|
|
19216
|
+
} catch (e26) {
|
|
18744
19217
|
}
|
|
18745
19218
|
throw new Error(
|
|
18746
|
-
`Swap ${swapResponse.id} was created for
|
|
19219
|
+
`Swap ${swapResponse.id} was created for a depositor which is neither this client's key nor the given wallet; use refundEvmWithSigner.${hint ? ` ${hint}` : ""}`
|
|
18747
19220
|
);
|
|
18748
19221
|
}
|
|
18749
19222
|
/**
|
|
@@ -18807,7 +19280,7 @@ network='${network}'`
|
|
|
18807
19280
|
stored.secretKey ? deriveEvmAddress(stored.secretKey) : void 0
|
|
18808
19281
|
]);
|
|
18809
19282
|
const expectedDepositors = uniqueAddresses([
|
|
18810
|
-
_optionalChain([signer, 'optionalAccess',
|
|
19283
|
+
_optionalChain([signer, 'optionalAccess', _252 => _252.address]),
|
|
18811
19284
|
...sdkAddresses,
|
|
18812
19285
|
stored.response.client_evm_address
|
|
18813
19286
|
]);
|
|
@@ -18833,7 +19306,7 @@ network='${network}'`
|
|
|
18833
19306
|
expectedDepositors
|
|
18834
19307
|
});
|
|
18835
19308
|
const coordinatorProved = !leg.depositorIsSender && refund.sender !== signer.address.toLowerCase() && stored.evmCoordinatorAddress === void 0;
|
|
18836
|
-
if (fundTxid.toLowerCase() !== _optionalChain([stored, 'access',
|
|
19309
|
+
if (fundTxid.toLowerCase() !== _optionalChain([stored, 'access', _253 => _253.evmFundTxid, 'optionalAccess', _254 => _254.toLowerCase, 'call', _255 => _255()]) || coordinatorProved) {
|
|
18837
19310
|
await this.#recordEvmFunding(id, {
|
|
18838
19311
|
txid: fundTxid,
|
|
18839
19312
|
coordinatorAddress: coordinatorProved ? refund.sender : void 0
|
|
@@ -18892,7 +19365,7 @@ network='${network}'`
|
|
|
18892
19365
|
async #serverFundTxid(id) {
|
|
18893
19366
|
const fresh = await this.getSwap(id);
|
|
18894
19367
|
try {
|
|
18895
|
-
await _optionalChain([this, 'access',
|
|
19368
|
+
await _optionalChain([this, 'access', _256 => _256.#swapStorage, 'optionalAccess', _257 => _257.update, 'call', _258 => _258(id, fresh)]);
|
|
18896
19369
|
} catch (error) {
|
|
18897
19370
|
this.#logger.warn({
|
|
18898
19371
|
event: "client.refundSwap.refreshNotStored",
|
|
@@ -18905,7 +19378,7 @@ network='${network}'`
|
|
|
18905
19378
|
}
|
|
18906
19379
|
async #refundFromFundingTx(signer, leg) {
|
|
18907
19380
|
const self2 = signer.address.toLowerCase();
|
|
18908
|
-
const coordinator = _optionalChain([leg, 'access',
|
|
19381
|
+
const coordinator = _optionalChain([leg, 'access', _259 => _259.coordinatorAddress, 'optionalAccess', _260 => _260.toLowerCase, 'call', _261 => _261()]);
|
|
18909
19382
|
const senders = leg.depositorIsSender ? uniqueAddresses([self2, ...leg.expectedDepositors]) : coordinator === void 0 ? void 0 : [self2, coordinator];
|
|
18910
19383
|
const { created, terms, hashLock } = await this.#lockFromFundingTx(signer, {
|
|
18911
19384
|
...leg,
|
|
@@ -18913,14 +19386,14 @@ network='${network}'`
|
|
|
18913
19386
|
});
|
|
18914
19387
|
const active = decodeCallWord(
|
|
18915
19388
|
await signer.call(
|
|
18916
|
-
|
|
19389
|
+
_chunkEI5ILLQ3cjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms)
|
|
18917
19390
|
),
|
|
18918
19391
|
"isActive"
|
|
18919
19392
|
);
|
|
18920
19393
|
if (active === 0n) {
|
|
18921
19394
|
await this.#ensureSettled(signer, leg.htlcAddress, terms);
|
|
18922
19395
|
}
|
|
18923
|
-
const native = created.token ===
|
|
19396
|
+
const native = created.token === _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
|
|
18924
19397
|
if (leg.depositorIsSender) {
|
|
18925
19398
|
const { to: to2, data: data2 } = encodeRefundCall(leg.htlcAddress, {
|
|
18926
19399
|
kind: native ? "nativeRefundFor" : "refundFor",
|
|
@@ -18949,7 +19422,7 @@ network='${network}'`
|
|
|
18949
19422
|
if (!ownHtlc) {
|
|
18950
19423
|
const deposit = decodeCallWord(
|
|
18951
19424
|
await signer.call(
|
|
18952
|
-
|
|
19425
|
+
_chunkEI5ILLQ3cjs.encodeDepositsCallData.call(void 0, created.refundAddress, created.key)
|
|
18953
19426
|
),
|
|
18954
19427
|
"deposits"
|
|
18955
19428
|
);
|
|
@@ -18966,7 +19439,7 @@ network='${network}'`
|
|
|
18966
19439
|
}
|
|
18967
19440
|
recipient = depositor;
|
|
18968
19441
|
}
|
|
18969
|
-
const { to, data } = ownHtlc ? native ?
|
|
19442
|
+
const { to, data } = ownHtlc ? native ? _chunkEI5ILLQ3cjs.encodeHtlcNativeRefundCallData.call(void 0, leg.htlcAddress, terms) : _chunkEI5ILLQ3cjs.encodeHtlcErc20RefundCallData.call(void 0, leg.htlcAddress, terms) : native ? _chunkEI5ILLQ3cjs.encodeNativeRefundTo.call(void 0, created.refundAddress, terms) : _chunkEI5ILLQ3cjs.encodeRefundTo.call(void 0, created.refundAddress, terms);
|
|
18970
19443
|
return {
|
|
18971
19444
|
to,
|
|
18972
19445
|
data,
|
|
@@ -18983,7 +19456,7 @@ network='${network}'`
|
|
|
18983
19456
|
let known;
|
|
18984
19457
|
try {
|
|
18985
19458
|
known = await signer.getTransaction(leg.fundTxid);
|
|
18986
|
-
} catch (
|
|
19459
|
+
} catch (e27) {
|
|
18987
19460
|
known = null;
|
|
18988
19461
|
}
|
|
18989
19462
|
if (!known) {
|
|
@@ -19013,8 +19486,8 @@ network='${network}'`
|
|
|
19013
19486
|
"Reading the lock from the chain needs the funding receipt's logs, which this signer's waitForReceipt does not return"
|
|
19014
19487
|
);
|
|
19015
19488
|
}
|
|
19016
|
-
const hashLock = `0x${
|
|
19017
|
-
const matches =
|
|
19489
|
+
const hashLock = `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, leg.hashLock)}`;
|
|
19490
|
+
const matches = _chunkEI5ILLQ3cjs.findSwapCreated.call(void 0, receipt.logs, {
|
|
19018
19491
|
htlcAddress: leg.htlcAddress,
|
|
19019
19492
|
hashLock,
|
|
19020
19493
|
claimAddress: leg.claimAddress,
|
|
@@ -19047,13 +19520,13 @@ network='${network}'`
|
|
|
19047
19520
|
*/
|
|
19048
19521
|
async #ensureSettled(signer, htlcAddress2, terms) {
|
|
19049
19522
|
const state = await this.#swapState(signer, htlcAddress2, terms.key);
|
|
19050
|
-
if (state === void 0 || state ===
|
|
19523
|
+
if (state === void 0 || state === _chunkEI5ILLQ3cjs.HTLC_SWAP_STATE.Redeemed || state === _chunkEI5ILLQ3cjs.HTLC_SWAP_STATE.Refunded) {
|
|
19051
19524
|
throw new HtlcNotActiveError(
|
|
19052
19525
|
`The HTLC for hash lock ${terms.preimageHash} on ${htlcAddress2} is no longer active; it was already redeemed or refunded`
|
|
19053
19526
|
);
|
|
19054
19527
|
}
|
|
19055
19528
|
throw new Error(
|
|
19056
|
-
state ===
|
|
19529
|
+
state === _chunkEI5ILLQ3cjs.HTLC_SWAP_STATE.Rehashed ? `The HTLC for hash lock ${terms.preimageHash} on ${htlcAddress2} was rehashed to terms this client has no record of` : `No HTLC is open under hash lock ${terms.preimageHash} and timelock ${terms.timelock} on ${htlcAddress2}; this client's record of the lock is stale`
|
|
19057
19530
|
);
|
|
19058
19531
|
}
|
|
19059
19532
|
/**
|
|
@@ -19063,10 +19536,10 @@ network='${network}'`
|
|
|
19063
19536
|
async #swapState(signer, htlcAddress2, key) {
|
|
19064
19537
|
try {
|
|
19065
19538
|
return decodeCallWord(
|
|
19066
|
-
await signer.call(
|
|
19539
|
+
await signer.call(_chunkEI5ILLQ3cjs.encodeHtlcSwapsCallData.call(void 0, htlcAddress2, key)),
|
|
19067
19540
|
"swaps"
|
|
19068
19541
|
);
|
|
19069
|
-
} catch (
|
|
19542
|
+
} catch (e28) {
|
|
19070
19543
|
return void 0;
|
|
19071
19544
|
}
|
|
19072
19545
|
}
|
|
@@ -19098,12 +19571,12 @@ network='${network}'`
|
|
|
19098
19571
|
`Rehash tx ${txid} has no readable logs, so the lock's current terms cannot be verified from the chain`
|
|
19099
19572
|
);
|
|
19100
19573
|
}
|
|
19101
|
-
const moved =
|
|
19574
|
+
const moved = _chunkEI5ILLQ3cjs.findSwapRehashed.call(void 0, receipt.logs, {
|
|
19102
19575
|
htlcAddress: htlcAddress2,
|
|
19103
19576
|
key: terms.key
|
|
19104
19577
|
});
|
|
19105
19578
|
if (moved.length === 0) continue;
|
|
19106
|
-
const hashLock = `0x${
|
|
19579
|
+
const hashLock = `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, rehash.hashLock)}`;
|
|
19107
19580
|
if (moved.length !== 1 || moved[0].newPreimageHash !== hashLock) {
|
|
19108
19581
|
throw new Error(
|
|
19109
19582
|
`Rehash tx ${txid} moved the HTLC for hash lock ${terms.preimageHash} elsewhere than the recorded ${hashLock}`
|
|
@@ -19227,8 +19700,8 @@ network='${network}'`
|
|
|
19227
19700
|
callsHash: params.callsHash,
|
|
19228
19701
|
coordinatorVersion: params.coordinatorVersion
|
|
19229
19702
|
};
|
|
19230
|
-
const typedData =
|
|
19231
|
-
const digest =
|
|
19703
|
+
const typedData = _chunkEI5ILLQ3cjs.buildCollabRefundEvmTypedData.call(void 0, digestParams);
|
|
19704
|
+
const digest = _chunkEI5ILLQ3cjs.buildCollabRefundEvmDigest.call(void 0, digestParams);
|
|
19232
19705
|
return { typedData, digest, params };
|
|
19233
19706
|
}
|
|
19234
19707
|
/**
|
|
@@ -19243,12 +19716,12 @@ network='${network}'`
|
|
|
19243
19716
|
*/
|
|
19244
19717
|
async collabRefundEvmSwap(swapId) {
|
|
19245
19718
|
const storedSwap = await this.getStoredSwap(swapId);
|
|
19246
|
-
if (!_optionalChain([storedSwap, 'optionalAccess',
|
|
19719
|
+
if (!_optionalChain([storedSwap, 'optionalAccess', _262 => _262.secretKey])) {
|
|
19247
19720
|
throw new Error(
|
|
19248
19721
|
"No secret key found for this swap. Cannot sign collab refund."
|
|
19249
19722
|
);
|
|
19250
19723
|
}
|
|
19251
|
-
const evmKey = this.#getCollabRefundEvmSigningKey(storedSwap);
|
|
19724
|
+
const evmKey = await this.#getCollabRefundEvmSigningKey(storedSwap);
|
|
19252
19725
|
const { digest, params } = await this.buildCollabRefundEvmTypedData(swapId);
|
|
19253
19726
|
if (params.refundPath === "direct") {
|
|
19254
19727
|
return this.#collabRefundEvmSponsored(swapId, params, evmKey);
|
|
@@ -19385,7 +19858,7 @@ network='${network}'`
|
|
|
19385
19858
|
entryPointVersion: entryPoint.version,
|
|
19386
19859
|
userOperation: signed
|
|
19387
19860
|
});
|
|
19388
|
-
} catch (
|
|
19861
|
+
} catch (e29) {
|
|
19389
19862
|
computed = void 0;
|
|
19390
19863
|
}
|
|
19391
19864
|
await hooks.onSigned(computed);
|
|
@@ -19402,11 +19875,11 @@ network='${network}'`
|
|
|
19402
19875
|
} else {
|
|
19403
19876
|
userOpHash = await client.sendUserOperation({ calls });
|
|
19404
19877
|
}
|
|
19405
|
-
await _optionalChain([hooks, 'access',
|
|
19878
|
+
await _optionalChain([hooks, 'access', _263 => _263.onSubmitted, 'optionalCall', _264 => _264(userOpHash)]);
|
|
19406
19879
|
const { receipt, success, reason } = await client.waitForUserOperationReceipt({
|
|
19407
19880
|
hash: userOpHash
|
|
19408
19881
|
});
|
|
19409
|
-
await _optionalChain([hooks, 'access',
|
|
19882
|
+
await _optionalChain([hooks, 'access', _265 => _265.onIncluded, 'optionalCall', _266 => _266(receipt.transactionHash, userOpHash)]);
|
|
19410
19883
|
if (!success) {
|
|
19411
19884
|
throw new Error(
|
|
19412
19885
|
`Sponsored UserOp ${userOpHash} reverted on-chain${reason ? `: ${reason}` : ""}`
|
|
@@ -19627,7 +20100,7 @@ network='${network}'`
|
|
|
19627
20100
|
* no AA config, not included, or the bundler cannot be reached).
|
|
19628
20101
|
*/
|
|
19629
20102
|
async #pendingRehashTx(rehash) {
|
|
19630
|
-
const bundlerUrl = _optionalChain([this, 'access',
|
|
20103
|
+
const bundlerUrl = _optionalChain([this, 'access', _267 => _267.#config, 'access', _268 => _268.aa, 'optionalAccess', _269 => _269.bundlerUrl]);
|
|
19631
20104
|
if (!rehash.userOpHash || !bundlerUrl) return void 0;
|
|
19632
20105
|
try {
|
|
19633
20106
|
const response = await fetch(bundlerUrl, {
|
|
@@ -19641,8 +20114,8 @@ network='${network}'`
|
|
|
19641
20114
|
})
|
|
19642
20115
|
});
|
|
19643
20116
|
const json = await response.json();
|
|
19644
|
-
return _nullishCoalesce(_optionalChain([json, 'access',
|
|
19645
|
-
} catch (
|
|
20117
|
+
return _nullishCoalesce(_optionalChain([json, 'access', _270 => _270.result, 'optionalAccess', _271 => _271.receipt, 'optionalAccess', _272 => _272.transactionHash]), () => ( void 0));
|
|
20118
|
+
} catch (e30) {
|
|
19646
20119
|
return void 0;
|
|
19647
20120
|
}
|
|
19648
20121
|
}
|
|
@@ -19651,7 +20124,7 @@ network='${network}'`
|
|
|
19651
20124
|
if (!this.#swapStorage) return;
|
|
19652
20125
|
try {
|
|
19653
20126
|
const stored = await this.#swapStorage.get(swapId);
|
|
19654
|
-
const history = _optionalChain([stored, 'optionalAccess',
|
|
20127
|
+
const history = _optionalChain([stored, 'optionalAccess', _273 => _273.evmRehashes]);
|
|
19655
20128
|
if (!stored || !history) return;
|
|
19656
20129
|
let index = -1;
|
|
19657
20130
|
for (let i = history.length - 1; i >= 0; i--) {
|
|
@@ -19702,8 +20175,8 @@ network='${network}'`
|
|
|
19702
20175
|
}
|
|
19703
20176
|
const ownHash = this.#clientHashLock(swapId, stored);
|
|
19704
20177
|
const leg = evmSourceLeg(stored);
|
|
19705
|
-
const firstFrom = _optionalChain([leg, 'access',
|
|
19706
|
-
if (firstFrom !== void 0 && `0x${
|
|
20178
|
+
const firstFrom = _optionalChain([leg, 'access', _274 => _274.rehashes, 'optionalAccess', _275 => _275[0], 'optionalAccess', _276 => _276.fromHashLock]);
|
|
20179
|
+
if (firstFrom !== void 0 && `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, firstFrom)}` !== ownHash) {
|
|
19707
20180
|
throw new Error(
|
|
19708
20181
|
`The rehash history of swap ${swapId} starts from ${firstFrom}, not from the payment hash this client fixed (${ownHash})`
|
|
19709
20182
|
);
|
|
@@ -19728,7 +20201,7 @@ network='${network}'`
|
|
|
19728
20201
|
});
|
|
19729
20202
|
const active = decodeCallWord(
|
|
19730
20203
|
await reader.call(
|
|
19731
|
-
|
|
20204
|
+
_chunkEI5ILLQ3cjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms)
|
|
19732
20205
|
),
|
|
19733
20206
|
"isActive"
|
|
19734
20207
|
);
|
|
@@ -19761,7 +20234,7 @@ network='${network}'`
|
|
|
19761
20234
|
* does not read the chain. Arbitrum only, like the paymaster.
|
|
19762
20235
|
*/
|
|
19763
20236
|
async #aaChainReader(owner) {
|
|
19764
|
-
const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access',
|
|
20237
|
+
const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _277 => _277.#config, 'access', _278 => _278.aa, 'optionalAccess', _279 => _279.rpcUrl]), () => ( _optionalChain([this, 'access', _280 => _280.#config, 'access', _281 => _281.aa, 'optionalAccess', _282 => _282.bundlerUrl])));
|
|
19765
20238
|
if (!rpcUrl) {
|
|
19766
20239
|
throw new Error(
|
|
19767
20240
|
"A sponsored rehash reads the lock over the AA RPC; call `.withAa({ bundlerUrl, paymasterPolicyId })` on the ClientBuilder before `.build()`."
|
|
@@ -19812,12 +20285,12 @@ network='${network}'`
|
|
|
19812
20285
|
*/
|
|
19813
20286
|
async retrySwapWithInvoice(swapId, invoice) {
|
|
19814
20287
|
const storedSwap = await this.getStoredSwap(swapId);
|
|
19815
|
-
if (!_optionalChain([storedSwap, 'optionalAccess',
|
|
20288
|
+
if (!_optionalChain([storedSwap, 'optionalAccess', _283 => _283.secretKey])) {
|
|
19816
20289
|
throw new Error(
|
|
19817
20290
|
"No secret key found for this swap. Cannot authorize the rehash."
|
|
19818
20291
|
);
|
|
19819
20292
|
}
|
|
19820
|
-
const evmKey = this.#getCollabRefundEvmSigningKey(
|
|
20293
|
+
const evmKey = await this.#getCollabRefundEvmSigningKey(
|
|
19821
20294
|
storedSwap,
|
|
19822
20295
|
"retrySwapWithInvoiceWithSigner"
|
|
19823
20296
|
);
|
|
@@ -19845,8 +20318,8 @@ network='${network}'`
|
|
|
19845
20318
|
});
|
|
19846
20319
|
ensureRehashMatchesRequest(signature, paymentHash, params);
|
|
19847
20320
|
ensureLockIsOwn(lock, signature, "The server signed a rehash of");
|
|
19848
|
-
const newHash = `0x${
|
|
19849
|
-
const isThisPending = (entry) => entry.txid === "" && entry.userOpHash === void 0 && `0x${
|
|
20321
|
+
const newHash = `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, signature.newPreimageHash)}`;
|
|
20322
|
+
const isThisPending = (entry) => entry.txid === "" && entry.userOpHash === void 0 && `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, entry.hashLock)}` === newHash;
|
|
19850
20323
|
await this.#recordEvmRehash(swapId, signature, "");
|
|
19851
20324
|
let sending = false;
|
|
19852
20325
|
let signedHash;
|
|
@@ -19964,25 +20437,37 @@ network='${network}'`
|
|
|
19964
20437
|
updatedAt: Date.now(),
|
|
19965
20438
|
// The payout this client asked for; claims pay here, never to a
|
|
19966
20439
|
// server answer. Recovery rebuilding the swap keeps it.
|
|
19967
|
-
targetAddress: _nullishCoalesce(targetAddress, () => ( _optionalChain([existing, 'optionalAccess',
|
|
19968
|
-
|
|
19969
|
-
|
|
19970
|
-
|
|
19971
|
-
|
|
20440
|
+
targetAddress: _nullishCoalesce(targetAddress, () => ( _optionalChain([existing, 'optionalAccess', _284 => _284.targetAddress]))),
|
|
20441
|
+
bitcoinPayout: _nullishCoalesce(_optionalChain([commitments, 'optionalAccess', _285 => _285.bitcoinPayout]), () => ( _optionalChain([existing, 'optionalAccess', _286 => _286.bitcoinPayout]))),
|
|
20442
|
+
payRecipientNames: _optionalChain([existing, 'optionalAccess', _287 => _287.payRecipientNames]),
|
|
20443
|
+
payRequestedAmounts: _optionalChain([existing, 'optionalAccess', _288 => _288.payRequestedAmounts]),
|
|
20444
|
+
payUsdRate: _optionalChain([existing, 'optionalAccess', _289 => _289.payUsdRate]),
|
|
20445
|
+
bitcoinClaimBroadcast: _optionalChain([existing, 'optionalAccess', _290 => _290.bitcoinClaimBroadcast]),
|
|
20446
|
+
evmDepositorKeyIndex: _optionalChain([existing, 'optionalAccess', _291 => _291.evmDepositorKeyIndex]),
|
|
20447
|
+
evmDepositorSecretKey: _optionalChain([existing, 'optionalAccess', _292 => _292.evmDepositorSecretKey]),
|
|
20448
|
+
bridgeRecipient: _optionalChain([bridge, 'optionalAccess', _293 => _293.recipient]),
|
|
20449
|
+
bridgeRecipientWallet: _optionalChain([bridge, 'optionalAccess', _294 => _294.recipientWallet]),
|
|
20450
|
+
evmFundTxid: _optionalChain([existing, 'optionalAccess', _295 => _295.evmFundTxid]),
|
|
20451
|
+
evmFundingUserOpHash: _optionalChain([existing, 'optionalAccess', _296 => _296.evmFundingUserOpHash]),
|
|
19972
20452
|
// Fixed at creation and never taken from a server answer: recovery
|
|
19973
20453
|
// rebuilding the swap keeps it, and a fresh device has none.
|
|
19974
|
-
lightningPaymentHash: _nullishCoalesce(_optionalChain([commitments, 'optionalAccess',
|
|
19975
|
-
evmFundingTerms: _nullishCoalesce(_optionalChain([commitments, 'optionalAccess',
|
|
19976
|
-
evmCoordinatorAddress: _optionalChain([existing, 'optionalAccess',
|
|
20454
|
+
lightningPaymentHash: _nullishCoalesce(_optionalChain([commitments, 'optionalAccess', _297 => _297.lightningPaymentHash]), () => ( _optionalChain([existing, 'optionalAccess', _298 => _298.lightningPaymentHash]))),
|
|
20455
|
+
evmFundingTerms: _nullishCoalesce(_optionalChain([commitments, 'optionalAccess', _299 => _299.evmFundingTerms]), () => ( _optionalChain([existing, 'optionalAccess', _300 => _300.evmFundingTerms]))),
|
|
20456
|
+
evmCoordinatorAddress: _optionalChain([existing, 'optionalAccess', _301 => _301.evmCoordinatorAddress]),
|
|
19977
20457
|
// The rehashes this client sent are what let a refund find the lock
|
|
19978
20458
|
// that exists; the server's copy names only the current hash.
|
|
19979
|
-
evmRehashes: _optionalChain([existing, 'optionalAccess',
|
|
20459
|
+
evmRehashes: _optionalChain([existing, 'optionalAccess', _302 => _302.evmRehashes]),
|
|
19980
20460
|
// A CCTP-inbound burn is the only way to resume or recover once the
|
|
19981
20461
|
// USDC has left the source chain.
|
|
19982
|
-
cctpBurnTxid: _optionalChain([existing, 'optionalAccess',
|
|
19983
|
-
cctpBurnLastValidBlockHeight: _optionalChain([existing, 'optionalAccess',
|
|
20462
|
+
cctpBurnTxid: _optionalChain([existing, 'optionalAccess', _303 => _303.cctpBurnTxid]),
|
|
20463
|
+
cctpBurnLastValidBlockHeight: _optionalChain([existing, 'optionalAccess', _304 => _304.cctpBurnLastValidBlockHeight])
|
|
19984
20464
|
};
|
|
19985
20465
|
await this.#swapStorage.store(storedSwap);
|
|
20466
|
+
if (storedSwap.bitcoinPayout) {
|
|
20467
|
+
const persisted = await this.#swapStorage.get(swapId);
|
|
20468
|
+
if (JSON.stringify(_optionalChain([persisted, 'optionalAccess', _305 => _305.bitcoinPayout])) !== JSON.stringify(storedSwap.bitcoinPayout))
|
|
20469
|
+
throw new Error("Swap storage did not preserve the payment recipients");
|
|
20470
|
+
}
|
|
19986
20471
|
}
|
|
19987
20472
|
/**
|
|
19988
20473
|
* Creates a swap by routing to the correct direction-specific method
|
|
@@ -20020,9 +20505,13 @@ network='${network}'`
|
|
|
20020
20505
|
}
|
|
20021
20506
|
const sourceAsset = "token_id" in src ? { chain: src.chain, token_id: src.token_id } : { chain: src.chain, token_id: src.tokenId };
|
|
20022
20507
|
const targetAsset = "token_id" in tgt ? { chain: tgt.chain, token_id: tgt.token_id } : { chain: tgt.chain, token_id: tgt.tokenId };
|
|
20508
|
+
if (options.bitcoinPayout && (!this.#swapStorage || !isBtcOnchain(targetAsset)))
|
|
20509
|
+
throw new Error(
|
|
20510
|
+
"Bitcoin payments require persistent storage and a Bitcoin onchain target"
|
|
20511
|
+
);
|
|
20023
20512
|
if (isTronToken(sourceAsset.chain))
|
|
20024
20513
|
throw new Error("Tron is a payout-only destination");
|
|
20025
|
-
const isTronTarget = isTronToken(targetAsset.chain) || _optionalChain([options, 'access',
|
|
20514
|
+
const isTronTarget = isTronToken(targetAsset.chain) || _optionalChain([options, 'access', _306 => _306.bridgeParams, 'optionalAccess', _307 => _307.targetChain]) === "Tron";
|
|
20026
20515
|
if (isTronTarget) {
|
|
20027
20516
|
if (isTronToken(targetAsset.chain) && targetAsset.token_id !== USDT0_ADDRESSES.Tron) {
|
|
20028
20517
|
throw new Error("Tron payouts require native USDT");
|
|
@@ -20062,7 +20551,7 @@ network='${network}'`
|
|
|
20062
20551
|
if (isTronTarget && bridgeParams) {
|
|
20063
20552
|
bridgeParams = { ...bridgeParams, recipient: options.targetAddress };
|
|
20064
20553
|
}
|
|
20065
|
-
const cctpPayout = !options.bridgeParams && bridgeParams != null && _optionalChain([bridgeParams, 'access',
|
|
20554
|
+
const cctpPayout = !options.bridgeParams && bridgeParams != null && _optionalChain([bridgeParams, 'access', _308 => _308.targetTokenAddress, 'optionalAccess', _309 => _309.toLowerCase, 'call', _310 => _310()]) === _optionalChain([_chunkTKFOVRJRcjs.USDC_ADDRESSES, 'access', _311 => _311[bridgeParams.targetChain], 'optionalAccess', _312 => _312.toLowerCase, 'call', _313 => _313()]);
|
|
20066
20555
|
if (cctpPayout && options.sourceAmount != null) {
|
|
20067
20556
|
const quote = await this.getQuote({
|
|
20068
20557
|
sourceChain: sourceAsset.chain,
|
|
@@ -20072,11 +20561,12 @@ network='${network}'`
|
|
|
20072
20561
|
sourceAmount: options.sourceAmount,
|
|
20073
20562
|
referralCode: options.referralCode,
|
|
20074
20563
|
extraFees: options.extraFees,
|
|
20564
|
+
promoCode: options.promoCode,
|
|
20075
20565
|
bridgeRecipientSetup: options.bridgeRecipientSetup
|
|
20076
20566
|
});
|
|
20077
20567
|
if (BigInt(quote.net_target_amount) <= 0n) {
|
|
20078
20568
|
throw new Error(
|
|
20079
|
-
`Amount too small to bridge to ${_optionalChain([bridgeParams, 'optionalAccess',
|
|
20569
|
+
`Amount too small to bridge to ${_optionalChain([bridgeParams, 'optionalAccess', _314 => _314.targetChain])}: the CCTP fee (${_nullishCoalesce(quote.bridge_fee, () => ( "unknown"))} USDC units) leaves nothing to deliver. Increase the amount.`
|
|
20080
20570
|
);
|
|
20081
20571
|
}
|
|
20082
20572
|
}
|
|
@@ -20114,6 +20604,11 @@ network='${network}'`
|
|
|
20114
20604
|
sourceChain = "42161";
|
|
20115
20605
|
sourceTokenId = _chunkTKFOVRJRcjs.USDC_ADDRESSES.Arbitrum;
|
|
20116
20606
|
}
|
|
20607
|
+
if (options.bitcoinPayout && !isEvmSwapSource(sourceChain, sourceTokenId)) {
|
|
20608
|
+
throw new Error(
|
|
20609
|
+
"Bitcoin payments require an EVM or bridged USDC funding source"
|
|
20610
|
+
);
|
|
20611
|
+
}
|
|
20117
20612
|
if (isArkade(sourceAsset) && isEvmToken(targetChain)) {
|
|
20118
20613
|
return this.createArkadeToEvmSwapGeneric({
|
|
20119
20614
|
targetAddress: options.targetAddress,
|
|
@@ -20123,6 +20618,7 @@ network='${network}'`
|
|
|
20123
20618
|
targetAmount: options.targetAmount ? BigInt(options.targetAmount) : void 0,
|
|
20124
20619
|
referralCode: options.referralCode,
|
|
20125
20620
|
extraFees: options.extraFees,
|
|
20621
|
+
promoCode: options.promoCode,
|
|
20126
20622
|
bridgeParams
|
|
20127
20623
|
});
|
|
20128
20624
|
}
|
|
@@ -20148,7 +20644,8 @@ network='${network}'`
|
|
|
20148
20644
|
...options.sourceAmount != null ? { sourceAmountSats: Number(options.sourceAmount) } : { targetAmountSats: Number(options.targetAmount) },
|
|
20149
20645
|
targetAddress: options.targetAddress,
|
|
20150
20646
|
referralCode: options.referralCode,
|
|
20151
|
-
extraFees: options.extraFees
|
|
20647
|
+
extraFees: options.extraFees,
|
|
20648
|
+
promoCode: options.promoCode
|
|
20152
20649
|
});
|
|
20153
20650
|
}
|
|
20154
20651
|
if (isLightning(sourceAsset) && isBtcOnchain(targetAsset)) {
|
|
@@ -20161,7 +20658,8 @@ network='${network}'`
|
|
|
20161
20658
|
...options.sourceAmount != null ? { sourceAmountSats: Number(options.sourceAmount) } : { targetAmountSats: Number(options.targetAmount) },
|
|
20162
20659
|
targetAddress: options.targetAddress,
|
|
20163
20660
|
referralCode: options.referralCode,
|
|
20164
|
-
extraFees: options.extraFees
|
|
20661
|
+
extraFees: options.extraFees,
|
|
20662
|
+
promoCode: options.promoCode
|
|
20165
20663
|
});
|
|
20166
20664
|
}
|
|
20167
20665
|
if (isLightning(sourceAsset) && isEvmToken(targetChain)) {
|
|
@@ -20178,6 +20676,25 @@ network='${network}'`
|
|
|
20178
20676
|
targetAmount: options.targetAmount == null ? void 0 : BigInt(options.targetAmount),
|
|
20179
20677
|
referralCode: options.referralCode,
|
|
20180
20678
|
extraFees: options.extraFees,
|
|
20679
|
+
promoCode: options.promoCode,
|
|
20680
|
+
bridgeParams
|
|
20681
|
+
});
|
|
20682
|
+
}
|
|
20683
|
+
if (sourceAsset.chain === "Spark" && isEvmToken(targetChain)) {
|
|
20684
|
+
if (options.sourceAmount == null === (options.targetAmount == null)) {
|
|
20685
|
+
throw new Error(
|
|
20686
|
+
"Provide exactly one of sourceAmount (sats on Spark) or targetAmount (token units to receive) for Spark \u2192 EVM swaps"
|
|
20687
|
+
);
|
|
20688
|
+
}
|
|
20689
|
+
return this.createSparkToEvmSwap({
|
|
20690
|
+
targetAddress: options.targetAddress,
|
|
20691
|
+
tokenAddress,
|
|
20692
|
+
evmChainId: Number(targetChain),
|
|
20693
|
+
sourceAmount: options.sourceAmount == null ? void 0 : Number(options.sourceAmount),
|
|
20694
|
+
targetAmount: options.targetAmount == null ? void 0 : BigInt(options.targetAmount),
|
|
20695
|
+
referralCode: options.referralCode,
|
|
20696
|
+
extraFees: options.extraFees,
|
|
20697
|
+
promoCode: options.promoCode,
|
|
20181
20698
|
bridgeParams
|
|
20182
20699
|
});
|
|
20183
20700
|
}
|
|
@@ -20190,6 +20707,7 @@ network='${network}'`
|
|
|
20190
20707
|
targetAmount: options.targetAmount == null ? void 0 : BigInt(options.targetAmount),
|
|
20191
20708
|
referralCode: options.referralCode,
|
|
20192
20709
|
extraFees: options.extraFees,
|
|
20710
|
+
promoCode: options.promoCode,
|
|
20193
20711
|
bridgeParams
|
|
20194
20712
|
});
|
|
20195
20713
|
}
|
|
@@ -20203,7 +20721,8 @@ network='${network}'`
|
|
|
20203
20721
|
satsReceive: Number(options.targetAmount),
|
|
20204
20722
|
targetAddress: options.targetAddress,
|
|
20205
20723
|
referralCode: options.referralCode,
|
|
20206
|
-
extraFees: options.extraFees
|
|
20724
|
+
extraFees: options.extraFees,
|
|
20725
|
+
promoCode: options.promoCode
|
|
20207
20726
|
});
|
|
20208
20727
|
}
|
|
20209
20728
|
if (isEvmSwapSource(sourceChain, sourceTokenId) && isLightning(targetAsset)) {
|
|
@@ -20220,6 +20739,7 @@ network='${network}'`
|
|
|
20220
20739
|
userAddress: options.userAddress,
|
|
20221
20740
|
referralCode: options.referralCode,
|
|
20222
20741
|
extraFees: options.extraFees,
|
|
20742
|
+
promoCode: options.promoCode,
|
|
20223
20743
|
gasless: options.gasless,
|
|
20224
20744
|
inboundBridgeParams
|
|
20225
20745
|
};
|
|
@@ -20269,6 +20789,7 @@ network='${network}'`
|
|
|
20269
20789
|
targetAmount: options.targetAmount == null ? void 0 : Number(options.targetAmount),
|
|
20270
20790
|
referralCode: options.referralCode,
|
|
20271
20791
|
extraFees: options.extraFees,
|
|
20792
|
+
promoCode: options.promoCode,
|
|
20272
20793
|
gasless: options.gasless,
|
|
20273
20794
|
inboundBridgeParams
|
|
20274
20795
|
});
|
|
@@ -20280,6 +20801,8 @@ network='${network}'`
|
|
|
20280
20801
|
);
|
|
20281
20802
|
}
|
|
20282
20803
|
return this.createEvmToBitcoinSwap({
|
|
20804
|
+
bitcoinPayout: options.bitcoinPayout,
|
|
20805
|
+
minimumRelayFeeRateSatPerVb: options.minimumRelayFeeRateSatPerVb,
|
|
20283
20806
|
tokenAddress: sourceTokenId,
|
|
20284
20807
|
evmChainId: Number(sourceChain),
|
|
20285
20808
|
userAddress: _nullishCoalesce(options.userAddress, () => ( "")),
|
|
@@ -20288,6 +20811,7 @@ network='${network}'`
|
|
|
20288
20811
|
targetAmount: options.targetAmount == null ? void 0 : Number(options.targetAmount),
|
|
20289
20812
|
referralCode: options.referralCode,
|
|
20290
20813
|
extraFees: options.extraFees,
|
|
20814
|
+
promoCode: options.promoCode,
|
|
20291
20815
|
gasless: options.gasless,
|
|
20292
20816
|
inboundBridgeParams
|
|
20293
20817
|
});
|
|
@@ -20475,6 +20999,13 @@ network='${network}'`
|
|
|
20475
20999
|
await this.#rifClaimAddress(options)
|
|
20476
21000
|
);
|
|
20477
21001
|
}
|
|
21002
|
+
async createSparkToEvmSwap(options) {
|
|
21003
|
+
return createSparkToEvmSwap(
|
|
21004
|
+
options,
|
|
21005
|
+
this.#getCreateContext(),
|
|
21006
|
+
await this.#rifClaimAddress(options)
|
|
21007
|
+
);
|
|
21008
|
+
}
|
|
20478
21009
|
// =========================================================================
|
|
20479
21010
|
// Swap Creation - Arkade to Lightning
|
|
20480
21011
|
// =========================================================================
|
|
@@ -20641,7 +21172,69 @@ network='${network}'`
|
|
|
20641
21172
|
* ```
|
|
20642
21173
|
*/
|
|
20643
21174
|
async createEvmToBitcoinSwap(options) {
|
|
20644
|
-
|
|
21175
|
+
if (options.bitcoinPayout && !this.#swapStorage)
|
|
21176
|
+
throw new Error("Bitcoin payments require persistent storage");
|
|
21177
|
+
const context = this.#getCreateContext();
|
|
21178
|
+
const created = await createEvmToBitcoinSwap(options, {
|
|
21179
|
+
...context,
|
|
21180
|
+
storeSwap: async (id, swapParams, response, target, bridge, commitments) => {
|
|
21181
|
+
if (options.bitcoinPayout) {
|
|
21182
|
+
const r = response;
|
|
21183
|
+
const network = r.network === "bitcoin" ? "mainnet" : r.network;
|
|
21184
|
+
assertPaymentClaimWindow(network, r.btc_refund_locktime);
|
|
21185
|
+
const urls = _nullishCoalesce(this.#config.esploraUrl, () => ( DEFAULT_ESPLORA_URLS[network]));
|
|
21186
|
+
const relayFloor = await _asyncNullishCoalesce(options.minimumRelayFeeRateSatPerVb, async () => ( (network === "regtest" ? 0 : await fetchMinimumRelayFeeRate(urls))));
|
|
21187
|
+
if (relayFloor === void 0 || !Number.isFinite(relayFloor) || relayFloor < 0)
|
|
21188
|
+
throw new Error(
|
|
21189
|
+
"Cannot verify Bitcoin relay policy before funding. Configure a relay-policy explorer or minimumRelayFeeRateSatPerVb."
|
|
21190
|
+
);
|
|
21191
|
+
const committed = _optionalChain([commitments, 'optionalAccess', _315 => _315.bitcoinPayout]);
|
|
21192
|
+
if (!committed) throw new Error("Payment commitments are missing");
|
|
21193
|
+
const minimum = BigInt(committed.feeSats) + committed.recipients.reduce(
|
|
21194
|
+
(sum, recipient) => sum + BigInt(recipient.amountSats),
|
|
21195
|
+
0n
|
|
21196
|
+
);
|
|
21197
|
+
try {
|
|
21198
|
+
buildOnchainClaimTransaction({
|
|
21199
|
+
fundingTxId: "00".repeat(32),
|
|
21200
|
+
fundingVout: 0,
|
|
21201
|
+
htlcAmount: minimum,
|
|
21202
|
+
hashLock: r.btc_hash_lock,
|
|
21203
|
+
userClaimPubKey: _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.publicKey).slice(2),
|
|
21204
|
+
serverRefundPubKey: r.btc_server_refund_pk.replace(
|
|
21205
|
+
/^(02|03)(?=[0-9a-fA-F]{64}$)/,
|
|
21206
|
+
""
|
|
21207
|
+
),
|
|
21208
|
+
userSecretKey: _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.secretKey),
|
|
21209
|
+
preimage: _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.preimage),
|
|
21210
|
+
refundLocktime: r.btc_refund_locktime,
|
|
21211
|
+
destinationAddress: options.targetAddress,
|
|
21212
|
+
bitcoinPayout: committed,
|
|
21213
|
+
// The builder needs a positive rate; regtest has no relay floor.
|
|
21214
|
+
feeRateSatPerVb: Math.max(relayFloor, Number.MIN_VALUE),
|
|
21215
|
+
network,
|
|
21216
|
+
btcHtlcScriptVersion: r.btc_htlc_script_version
|
|
21217
|
+
});
|
|
21218
|
+
} catch (error) {
|
|
21219
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
21220
|
+
if (message.startsWith("Surplus cannot cover"))
|
|
21221
|
+
throw new Error(
|
|
21222
|
+
`Bitcoin payment fee is below the relay minimum of ${relayFloor} sat/vB. Increase it before funding.`
|
|
21223
|
+
);
|
|
21224
|
+
throw error;
|
|
21225
|
+
}
|
|
21226
|
+
}
|
|
21227
|
+
await context.storeSwap(
|
|
21228
|
+
id,
|
|
21229
|
+
swapParams,
|
|
21230
|
+
response,
|
|
21231
|
+
target,
|
|
21232
|
+
bridge,
|
|
21233
|
+
commitments
|
|
21234
|
+
);
|
|
21235
|
+
}
|
|
21236
|
+
});
|
|
21237
|
+
return created;
|
|
20645
21238
|
}
|
|
20646
21239
|
// =========================================================================
|
|
20647
21240
|
// Coordinator Funding (EVM-to-BTC via DEX + HTLC)
|
|
@@ -20700,7 +21293,7 @@ network='${network}'`
|
|
|
20700
21293
|
swapId,
|
|
20701
21294
|
serverData,
|
|
20702
21295
|
chainId,
|
|
20703
|
-
_optionalChain([options, 'optionalAccess',
|
|
21296
|
+
_optionalChain([options, 'optionalAccess', _316 => _316.funding])
|
|
20704
21297
|
);
|
|
20705
21298
|
const nonceBytes = new Uint8Array(32);
|
|
20706
21299
|
crypto.getRandomValues(nonceBytes);
|
|
@@ -20709,9 +21302,12 @@ network='${network}'`
|
|
|
20709
21302
|
);
|
|
20710
21303
|
const deadline = BigInt(Math.floor(Date.now() / 1e3) + 30 * 60);
|
|
20711
21304
|
const sourceAmount = checked.sourceAmount;
|
|
20712
|
-
const evmKey = this.#
|
|
21305
|
+
const evmKey = await this.#getFundingEvmSigningKey(
|
|
21306
|
+
storedSwap,
|
|
21307
|
+
swap.gasless
|
|
21308
|
+
);
|
|
20713
21309
|
const depositorAddress = deriveEvmAddress(evmKey);
|
|
20714
|
-
const digest =
|
|
21310
|
+
const digest = _chunkEI5ILLQ3cjs.buildPermit2FundingDigest.call(void 0, {
|
|
20715
21311
|
chainId,
|
|
20716
21312
|
coordinatorAddress: checked.coordinator,
|
|
20717
21313
|
sourceToken: checked.sourceToken,
|
|
@@ -20745,7 +21341,7 @@ network='${network}'`
|
|
|
20745
21341
|
delegated
|
|
20746
21342
|
);
|
|
20747
21343
|
const calls = checked.calls;
|
|
20748
|
-
const encoded =
|
|
21344
|
+
const encoded = _chunkEI5ILLQ3cjs.encodeExecuteAndCreateWithPermit2.call(void 0, checked.coordinator, {
|
|
20749
21345
|
calls,
|
|
20750
21346
|
preimageHash: checked.preimageHash,
|
|
20751
21347
|
token: checked.lockToken,
|
|
@@ -20761,9 +21357,9 @@ network='${network}'`
|
|
|
20761
21357
|
const maxUint256 = BigInt(
|
|
20762
21358
|
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
|
20763
21359
|
);
|
|
20764
|
-
const approve =
|
|
21360
|
+
const approve = _chunkEI5ILLQ3cjs.encodeApproveCallData.call(void 0,
|
|
20765
21361
|
checked.sourceToken,
|
|
20766
|
-
|
|
21362
|
+
_chunkEI5ILLQ3cjs.PERMIT2_ADDRESS,
|
|
20767
21363
|
maxUint256
|
|
20768
21364
|
);
|
|
20769
21365
|
return {
|
|
@@ -20842,7 +21438,7 @@ network='${network}'`
|
|
|
20842
21438
|
swapId,
|
|
20843
21439
|
serverData,
|
|
20844
21440
|
chainId,
|
|
20845
|
-
_optionalChain([options, 'optionalAccess',
|
|
21441
|
+
_optionalChain([options, 'optionalAccess', _317 => _317.funding])
|
|
20846
21442
|
);
|
|
20847
21443
|
const nonceBytes = new Uint8Array(32);
|
|
20848
21444
|
crypto.getRandomValues(nonceBytes);
|
|
@@ -20870,7 +21466,7 @@ network='${network}'`
|
|
|
20870
21466
|
nonce,
|
|
20871
21467
|
deadline
|
|
20872
21468
|
};
|
|
20873
|
-
const typedData =
|
|
21469
|
+
const typedData = _chunkEI5ILLQ3cjs.buildPermit2TypedData.call(void 0, fundingParams);
|
|
20874
21470
|
return {
|
|
20875
21471
|
coordinatorAddress: checked.coordinator,
|
|
20876
21472
|
/** The lock's sender: the depositor on HTLCErc20 v7 / HTLCNative v2, the coordinator before. */
|
|
@@ -20931,14 +21527,14 @@ network='${network}'`
|
|
|
20931
21527
|
*/
|
|
20932
21528
|
async fundSwap(swapId, signer, options) {
|
|
20933
21529
|
{
|
|
20934
|
-
const stored = await _optionalChain([this, 'access',
|
|
20935
|
-
const response = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async
|
|
21530
|
+
const stored = await _optionalChain([this, 'access', _318 => _318.#swapStorage, 'optionalAccess', _319 => _319.get, 'call', _320 => _320(swapId)]);
|
|
21531
|
+
const response = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async _321 => _321.response]), async () => ( await this.getSwap(swapId, { updateStorage: true })));
|
|
20936
21532
|
if ((response.direction === "evm_to_lightning" || response.direction === "evm_to_arkade" || response.direction === "evm_to_bitcoin") && response.evm_htlc_kind === "native") {
|
|
20937
21533
|
const txHash2 = await this.#fundNativeLock(
|
|
20938
21534
|
swapId,
|
|
20939
21535
|
response,
|
|
20940
21536
|
signer,
|
|
20941
|
-
_optionalChain([options, 'optionalAccess',
|
|
21537
|
+
_optionalChain([options, 'optionalAccess', _322 => _322.onQuote])
|
|
20942
21538
|
);
|
|
20943
21539
|
return { txHash: txHash2 };
|
|
20944
21540
|
}
|
|
@@ -20949,12 +21545,12 @@ network='${network}'`
|
|
|
20949
21545
|
}
|
|
20950
21546
|
}
|
|
20951
21547
|
if (isCctpOnlySource(signer.chainId)) {
|
|
20952
|
-
const stored = await _optionalChain([this, 'access',
|
|
20953
|
-
const swapResponse = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async
|
|
21548
|
+
const stored = await _optionalChain([this, 'access', _323 => _323.#swapStorage, 'optionalAccess', _324 => _324.get, 'call', _325 => _325(swapId)]);
|
|
21549
|
+
const swapResponse = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async _326 => _326.response]), async () => ( await this.getSwap(swapId, { updateStorage: true })));
|
|
20954
21550
|
const source = cctpMetaForChainId(signer.chainId);
|
|
20955
21551
|
const expected = {
|
|
20956
21552
|
...this.#fundingExpectation(swapId, stored),
|
|
20957
|
-
pins: _optionalChain([options, 'optionalAccess',
|
|
21553
|
+
pins: _optionalChain([options, 'optionalAccess', _327 => _327.funding])
|
|
20958
21554
|
};
|
|
20959
21555
|
await this.#ensureClientHashLock(
|
|
20960
21556
|
swapId,
|
|
@@ -20986,7 +21582,7 @@ network='${network}'`
|
|
|
20986
21582
|
}
|
|
20987
21583
|
const amount = BigInt(rawAmount);
|
|
20988
21584
|
const destination = cctpMetaForChainId(42161);
|
|
20989
|
-
const recordedBurn = _optionalChain([stored, 'optionalAccess',
|
|
21585
|
+
const recordedBurn = _optionalChain([stored, 'optionalAccess', _328 => _328.cctpBurnTxid]);
|
|
20990
21586
|
if (recordedBurn) {
|
|
20991
21587
|
const fresh = await this.getSwap(swapId, { updateStorage: true });
|
|
20992
21588
|
if (fresh.status !== "pending") {
|
|
@@ -20995,7 +21591,7 @@ network='${network}'`
|
|
|
20995
21591
|
);
|
|
20996
21592
|
}
|
|
20997
21593
|
}
|
|
20998
|
-
const maxFee = recordedBurn ? 0n : await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async
|
|
21594
|
+
const maxFee = recordedBurn ? 0n : await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _329 => _329.maxFee]), async () => ( computeCctpFastFee(
|
|
20999
21595
|
await getCachedCctpFee({
|
|
21000
21596
|
sourceDomain: source.domain,
|
|
21001
21597
|
destinationDomain: destination.domain
|
|
@@ -21006,7 +21602,7 @@ network='${network}'`
|
|
|
21006
21602
|
swapId,
|
|
21007
21603
|
expected,
|
|
21008
21604
|
signer,
|
|
21009
|
-
ownerSigner: this.#depositorOwnerSigner(
|
|
21605
|
+
ownerSigner: await this.#depositorOwnerSigner(
|
|
21010
21606
|
swapResponse,
|
|
21011
21607
|
signer,
|
|
21012
21608
|
"Create the swap with `gasless: true` to settle through the SDK's key."
|
|
@@ -21015,8 +21611,8 @@ network='${network}'`
|
|
|
21015
21611
|
onBurn: (burnTxHash) => this.#recordCctpBurn(swapId, burnTxHash),
|
|
21016
21612
|
amount,
|
|
21017
21613
|
maxFee,
|
|
21018
|
-
onProgress: _optionalChain([options, 'optionalAccess',
|
|
21019
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
21614
|
+
onProgress: _optionalChain([options, 'optionalAccess', _330 => _330.onProgress]),
|
|
21615
|
+
signal: _optionalChain([options, 'optionalAccess', _331 => _331.signal])
|
|
21020
21616
|
});
|
|
21021
21617
|
if (cctp.transactionHash) {
|
|
21022
21618
|
await this.#recordEvmFunding(swapId, { txid: cctp.transactionHash });
|
|
@@ -21027,14 +21623,14 @@ network='${network}'`
|
|
|
21027
21623
|
swapId,
|
|
21028
21624
|
signer.chainId,
|
|
21029
21625
|
signer.address,
|
|
21030
|
-
{ funding: _optionalChain([options, 'optionalAccess',
|
|
21626
|
+
{ funding: _optionalChain([options, 'optionalAccess', _332 => _332.funding]) }
|
|
21031
21627
|
);
|
|
21032
|
-
_optionalChain([options, 'optionalAccess',
|
|
21628
|
+
_optionalChain([options, 'optionalAccess', _333 => _333.onQuote, 'optionalCall', _334 => _334({
|
|
21033
21629
|
sourceAmount: funding.sourceAmount,
|
|
21034
21630
|
sourceTokenAddress: funding.sourceTokenAddress
|
|
21035
21631
|
})]);
|
|
21036
21632
|
const tokenAddress = funding.sourceTokenAddress;
|
|
21037
|
-
const permit2 =
|
|
21633
|
+
const permit2 = _chunkEI5ILLQ3cjs.PERMIT2_ADDRESS;
|
|
21038
21634
|
const balanceCall = _chunkTNZW35XAcjs.encodeBalanceOfCall.call(void 0, tokenAddress, signer.address);
|
|
21039
21635
|
const balanceResult = await signer.call({
|
|
21040
21636
|
to: balanceCall.to,
|
|
@@ -21077,10 +21673,10 @@ network='${network}'`
|
|
|
21077
21673
|
swapId,
|
|
21078
21674
|
signer.chainId,
|
|
21079
21675
|
signer.address,
|
|
21080
|
-
{ funding: _optionalChain([options, 'optionalAccess',
|
|
21676
|
+
{ funding: _optionalChain([options, 'optionalAccess', _335 => _335.funding]) }
|
|
21081
21677
|
);
|
|
21082
21678
|
if (freshFunding.sourceAmount !== funding.sourceAmount) {
|
|
21083
|
-
_optionalChain([options, 'optionalAccess',
|
|
21679
|
+
_optionalChain([options, 'optionalAccess', _336 => _336.onQuote, 'optionalCall', _337 => _337({
|
|
21084
21680
|
sourceAmount: freshFunding.sourceAmount,
|
|
21085
21681
|
sourceTokenAddress: freshFunding.sourceTokenAddress
|
|
21086
21682
|
})]);
|
|
@@ -21090,10 +21686,10 @@ network='${network}'`
|
|
|
21090
21686
|
if (/^0x[0-9a-fA-F]{128}0[01]$/.test(signature) && signer.getCode) {
|
|
21091
21687
|
try {
|
|
21092
21688
|
depositorCode = await signer.getCode(signer.address);
|
|
21093
|
-
} catch (
|
|
21689
|
+
} catch (e31) {
|
|
21094
21690
|
}
|
|
21095
21691
|
}
|
|
21096
|
-
const encoded =
|
|
21692
|
+
const encoded = _chunkEI5ILLQ3cjs.encodeExecuteAndCreateWithPermit2.call(void 0,
|
|
21097
21693
|
freshFunding.coordinatorAddress,
|
|
21098
21694
|
{
|
|
21099
21695
|
calls: freshFunding.calls,
|
|
@@ -21156,17 +21752,17 @@ network='${network}'`
|
|
|
21156
21752
|
* @returns The Arbitrum settlement tx hash (or UserOp hash) and the burn
|
|
21157
21753
|
*/
|
|
21158
21754
|
async fundSwapFromSolana(swapId, signer, options) {
|
|
21159
|
-
const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
21755
|
+
const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _338 => _338.rpcUrl]), () => ( this.#config.solanaRpcUrl));
|
|
21160
21756
|
if (!rpcUrl) {
|
|
21161
21757
|
throw new Error(
|
|
21162
21758
|
"Funding from Solana needs a Solana RPC URL. Pass `rpcUrl` or call `.withSolanaRpcUrl(url)` on the ClientBuilder."
|
|
21163
21759
|
);
|
|
21164
21760
|
}
|
|
21165
|
-
const stored = await _optionalChain([this, 'access',
|
|
21166
|
-
const swapResponse = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async
|
|
21761
|
+
const stored = await _optionalChain([this, 'access', _339 => _339.#swapStorage, 'optionalAccess', _340 => _340.get, 'call', _341 => _341(swapId)]);
|
|
21762
|
+
const swapResponse = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async _342 => _342.response]), async () => ( await this.getSwap(swapId, { updateStorage: true })));
|
|
21167
21763
|
const expected = {
|
|
21168
21764
|
...this.#fundingExpectation(swapId, stored),
|
|
21169
|
-
pins: _optionalChain([options, 'optionalAccess',
|
|
21765
|
+
pins: _optionalChain([options, 'optionalAccess', _343 => _343.funding])
|
|
21170
21766
|
};
|
|
21171
21767
|
await this.#ensureClientHashLock(
|
|
21172
21768
|
swapId,
|
|
@@ -21190,7 +21786,7 @@ network='${network}'`
|
|
|
21190
21786
|
);
|
|
21191
21787
|
}
|
|
21192
21788
|
const amount = BigInt(bridge.source_amount);
|
|
21193
|
-
const recordedBurn = _optionalChain([stored, 'optionalAccess',
|
|
21789
|
+
const recordedBurn = _optionalChain([stored, 'optionalAccess', _344 => _344.cctpBurnTxid]);
|
|
21194
21790
|
if (recordedBurn) {
|
|
21195
21791
|
const fresh = await this.getSwap(swapId, { updateStorage: true });
|
|
21196
21792
|
if (fresh.status !== "pending") {
|
|
@@ -21199,14 +21795,14 @@ network='${network}'`
|
|
|
21199
21795
|
);
|
|
21200
21796
|
}
|
|
21201
21797
|
}
|
|
21202
|
-
const maxFee = recordedBurn ? 0n : await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async
|
|
21798
|
+
const maxFee = recordedBurn ? 0n : await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _345 => _345.maxFee]), async () => ( computeCctpFastFee(
|
|
21203
21799
|
await getCachedCctpFee({
|
|
21204
21800
|
sourceDomain: _chunkTKFOVRJRcjs.CCTP_DOMAINS.Solana,
|
|
21205
21801
|
destinationDomain: _chunkTKFOVRJRcjs.CCTP_DOMAINS.Arbitrum
|
|
21206
21802
|
}),
|
|
21207
21803
|
amount
|
|
21208
21804
|
)));
|
|
21209
|
-
const { cctpFundSwapFromSolana } = await Promise.resolve().then(() => _interopRequireWildcard(require("./fundSwap-
|
|
21805
|
+
const { cctpFundSwapFromSolana } = await Promise.resolve().then(() => _interopRequireWildcard(require("./fundSwap-2D4IPYU4-4NELKB3Q.cjs")));
|
|
21210
21806
|
const { aa } = this.cctpInbound;
|
|
21211
21807
|
const cctp = await cctpFundSwapFromSolana(
|
|
21212
21808
|
{ apiClient: this.#apiClient, aa },
|
|
@@ -21214,20 +21810,20 @@ network='${network}'`
|
|
|
21214
21810
|
swapId,
|
|
21215
21811
|
expected,
|
|
21216
21812
|
signer,
|
|
21217
|
-
ownerSigner: this.#depositorOwnerSigner(
|
|
21813
|
+
ownerSigner: await this.#depositorOwnerSigner(
|
|
21218
21814
|
swapResponse,
|
|
21219
21815
|
void 0,
|
|
21220
21816
|
"A swap funded from Solana must be created with `gasless: true`."
|
|
21221
21817
|
),
|
|
21222
21818
|
rpcUrl,
|
|
21223
21819
|
burnSignature: recordedBurn,
|
|
21224
|
-
burnLastValidBlockHeight: _optionalChain([stored, 'optionalAccess',
|
|
21820
|
+
burnLastValidBlockHeight: _optionalChain([stored, 'optionalAccess', _346 => _346.cctpBurnLastValidBlockHeight]),
|
|
21225
21821
|
onBurn: (burnSignature, lastValidBlockHeight) => this.#recordCctpBurn(swapId, burnSignature, lastValidBlockHeight),
|
|
21226
21822
|
amount,
|
|
21227
21823
|
maxFee,
|
|
21228
|
-
priorityFeeMicroLamports: _optionalChain([options, 'optionalAccess',
|
|
21229
|
-
onProgress: _optionalChain([options, 'optionalAccess',
|
|
21230
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
21824
|
+
priorityFeeMicroLamports: _optionalChain([options, 'optionalAccess', _347 => _347.priorityFeeMicroLamports]),
|
|
21825
|
+
onProgress: _optionalChain([options, 'optionalAccess', _348 => _348.onProgress]),
|
|
21826
|
+
signal: _optionalChain([options, 'optionalAccess', _349 => _349.signal])
|
|
21231
21827
|
}
|
|
21232
21828
|
);
|
|
21233
21829
|
if (cctp.transactionHash) {
|
|
@@ -21245,7 +21841,7 @@ network='${network}'`
|
|
|
21245
21841
|
* `withSolanaRpcUrl` on the builder
|
|
21246
21842
|
*/
|
|
21247
21843
|
async getSolanaUsdcBalance(owner, options) {
|
|
21248
|
-
const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
21844
|
+
const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _350 => _350.rpcUrl]), () => ( this.#config.solanaRpcUrl));
|
|
21249
21845
|
if (!rpcUrl) {
|
|
21250
21846
|
throw new Error(
|
|
21251
21847
|
"Reading a Solana balance needs a Solana RPC URL. Pass `rpcUrl` or call `.withSolanaRpcUrl(url)` on the ClientBuilder."
|
|
@@ -21281,16 +21877,16 @@ network='${network}'`
|
|
|
21281
21877
|
`The server's swap names HTLC ${swap.evm_htlc_address}, claimer ${swap.server_evm_address} and timelock ${swap.evm_refund_locktime}, not the ${terms.htlcAddress}, ${terms.claimAddress} and ${terms.timelock} it was created with; refusing to fund it`
|
|
21282
21878
|
);
|
|
21283
21879
|
}
|
|
21284
|
-
_optionalChain([onQuote, 'optionalCall',
|
|
21880
|
+
_optionalChain([onQuote, 'optionalCall', _351 => _351({
|
|
21285
21881
|
sourceAmount: amount,
|
|
21286
|
-
sourceTokenAddress:
|
|
21882
|
+
sourceTokenAddress: _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS
|
|
21287
21883
|
})]);
|
|
21288
|
-
if (swap.evm_coordinator_address.toLowerCase() !==
|
|
21884
|
+
if (swap.evm_coordinator_address.toLowerCase() !== _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS) {
|
|
21289
21885
|
throw new Error(
|
|
21290
21886
|
"This legacy Rootstock swap requires coordinator funding. Create a new swap with the updated backend before funding."
|
|
21291
21887
|
);
|
|
21292
21888
|
}
|
|
21293
|
-
if (signer.address.toLowerCase() !== _optionalChain([swap, 'access',
|
|
21889
|
+
if (signer.address.toLowerCase() !== _optionalChain([swap, 'access', _352 => _352.client_evm_address, 'optionalAccess', _353 => _353.toLowerCase, 'call', _354 => _354()])) {
|
|
21294
21890
|
throw new Error(
|
|
21295
21891
|
"Connect the source wallet recorded on this swap to fund RBTC."
|
|
21296
21892
|
);
|
|
@@ -21315,13 +21911,13 @@ network='${network}'`
|
|
|
21315
21911
|
preimageHash: hashLock,
|
|
21316
21912
|
claimAddress: swap.server_evm_address,
|
|
21317
21913
|
lockSender: signer.address,
|
|
21318
|
-
token:
|
|
21914
|
+
token: _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS
|
|
21319
21915
|
};
|
|
21320
21916
|
await this.#ensureNativeFundingFailed(
|
|
21321
21917
|
swapId,
|
|
21322
21918
|
signer,
|
|
21323
21919
|
[
|
|
21324
|
-
await _asyncOptionalChain([(await this.getStoredSwap(swapId)), 'optionalAccess', async
|
|
21920
|
+
await _asyncOptionalChain([(await this.getStoredSwap(swapId)), 'optionalAccess', async _355 => _355.evmFundTxid]),
|
|
21325
21921
|
swap.evm_fund_txid
|
|
21326
21922
|
],
|
|
21327
21923
|
hashLock
|
|
@@ -21355,7 +21951,7 @@ network='${network}'`
|
|
|
21355
21951
|
let known;
|
|
21356
21952
|
try {
|
|
21357
21953
|
known = await signer.getTransaction(txid);
|
|
21358
|
-
} catch (
|
|
21954
|
+
} catch (e32) {
|
|
21359
21955
|
known = null;
|
|
21360
21956
|
}
|
|
21361
21957
|
if (!known) refuse("the node does not know and may still land");
|
|
@@ -21366,7 +21962,7 @@ network='${network}'`
|
|
|
21366
21962
|
FUNDING_RECEIPT_WAIT_MS,
|
|
21367
21963
|
`not mined within ${FUNDING_RECEIPT_WAIT_MS / 1e3}s`
|
|
21368
21964
|
);
|
|
21369
|
-
} catch (
|
|
21965
|
+
} catch (e33) {
|
|
21370
21966
|
return refuse("is not mined yet");
|
|
21371
21967
|
}
|
|
21372
21968
|
if (receipt.status !== "success") continue;
|
|
@@ -21390,7 +21986,7 @@ network='${network}'`
|
|
|
21390
21986
|
});
|
|
21391
21987
|
const receipt = await signer.waitForReceipt(txHash);
|
|
21392
21988
|
if (receipt.status !== "success") {
|
|
21393
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
21989
|
+
if (_optionalChain([options, 'optionalAccess', _356 => _356.forgetFailed])) await this.#forgetEvmFunding(swapId, txHash);
|
|
21394
21990
|
const reason = await _chunkTNZW35XAcjs.getRevertReason.call(void 0, signer, txHash, receipt.blockNumber);
|
|
21395
21991
|
throw new Error(`Funding transaction failed: ${reason}`);
|
|
21396
21992
|
}
|
|
@@ -21405,7 +22001,7 @@ network='${network}'`
|
|
|
21405
22001
|
});
|
|
21406
22002
|
created = !replaced || await isSameCall(signer, mined, sent);
|
|
21407
22003
|
} else {
|
|
21408
|
-
created =
|
|
22004
|
+
created = _chunkEI5ILLQ3cjs.findSwapCreated.call(void 0, receipt.logs, {
|
|
21409
22005
|
htlcAddress: expected.htlcAddress,
|
|
21410
22006
|
hashLock: expected.preimageHash,
|
|
21411
22007
|
claimAddress: expected.claimAddress,
|
|
@@ -21414,7 +22010,7 @@ network='${network}'`
|
|
|
21414
22010
|
}).length > 0;
|
|
21415
22011
|
}
|
|
21416
22012
|
if (!created && replaced) {
|
|
21417
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
22013
|
+
if (_optionalChain([options, 'optionalAccess', _357 => _357.forgetFailed]) && provesNoLockUnder(receipt, expected.preimageHash)) {
|
|
21418
22014
|
await this.#forgetEvmFunding(swapId, txHash);
|
|
21419
22015
|
}
|
|
21420
22016
|
throw new Error(
|
|
@@ -21604,7 +22200,7 @@ network='${network}'`
|
|
|
21604
22200
|
}
|
|
21605
22201
|
async #actualRefundTransfer(oldSwap, smartAccountAddress) {
|
|
21606
22202
|
const txHash = oldSwap.evm_claim_txid;
|
|
21607
|
-
const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access',
|
|
22203
|
+
const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _358 => _358.#config, 'access', _359 => _359.aa, 'optionalAccess', _360 => _360.rpcUrl]), () => ( _optionalChain([this, 'access', _361 => _361.#config, 'access', _362 => _362.aa, 'optionalAccess', _363 => _363.bundlerUrl])));
|
|
21608
22204
|
if (!txHash || !rpcUrl) return null;
|
|
21609
22205
|
const { createPublicClient: createPublicClient2, http: http2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./_esm-4ZKYBBIE-D33574DC.cjs")));
|
|
21610
22206
|
const { arbitrum: arbitrum2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./chains-D6LHJZMI-AAYKXZGC.cjs")));
|
|
@@ -21617,13 +22213,13 @@ network='${network}'`
|
|
|
21617
22213
|
receipt = await publicClient.getTransactionReceipt({
|
|
21618
22214
|
hash: txHash
|
|
21619
22215
|
});
|
|
21620
|
-
} catch (
|
|
22216
|
+
} catch (e34) {
|
|
21621
22217
|
return null;
|
|
21622
22218
|
}
|
|
21623
22219
|
const transferTopic = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
|
21624
22220
|
const paddedRecipient = smartAccountAddress.replace(/^0x/i, "").toLowerCase().padStart(64, "0");
|
|
21625
22221
|
const transfers = receipt.logs.filter(
|
|
21626
|
-
(log) => _optionalChain([log, 'access',
|
|
22222
|
+
(log) => _optionalChain([log, 'access', _364 => _364.topics, 'access', _365 => _365[0], 'optionalAccess', _366 => _366.toLowerCase, 'call', _367 => _367()]) === transferTopic && _optionalChain([log, 'access', _368 => _368.topics, 'access', _369 => _369[2], 'optionalAccess', _370 => _370.replace, 'call', _371 => _371(/^0x/i, ""), 'access', _372 => _372.toLowerCase, 'call', _373 => _373()]) === paddedRecipient
|
|
21627
22223
|
).map((log) => ({
|
|
21628
22224
|
tokenAddress: log.address,
|
|
21629
22225
|
amount: BigInt(log.data).toString()
|
|
@@ -21660,7 +22256,7 @@ network='${network}'`
|
|
|
21660
22256
|
oldSwap
|
|
21661
22257
|
};
|
|
21662
22258
|
}
|
|
21663
|
-
const owner =
|
|
22259
|
+
const owner = await this.#depositorOwnerSigner(oldSwap, signer);
|
|
21664
22260
|
const { accountAddress } = await this.cctpInbound.createSmartAccountClient({
|
|
21665
22261
|
signer: owner
|
|
21666
22262
|
});
|
|
@@ -21710,8 +22306,8 @@ network='${network}'`
|
|
|
21710
22306
|
{
|
|
21711
22307
|
chain: refundChain,
|
|
21712
22308
|
address: actualRefund.tokenAddress,
|
|
21713
|
-
symbol: _nullishCoalesce(_optionalChain([actualMeta, 'optionalAccess',
|
|
21714
|
-
decimals: _nullishCoalesce(_optionalChain([actualMeta, 'optionalAccess',
|
|
22309
|
+
symbol: _nullishCoalesce(_optionalChain([actualMeta, 'optionalAccess', _374 => _374.symbol]), () => ( "ERC-20")),
|
|
22310
|
+
decimals: _nullishCoalesce(_optionalChain([actualMeta, 'optionalAccess', _375 => _375.decimals]), () => ( 18)),
|
|
21715
22311
|
amount: actualRefund.amount
|
|
21716
22312
|
}
|
|
21717
22313
|
] : [],
|
|
@@ -21765,17 +22361,11 @@ network='${network}'`
|
|
|
21765
22361
|
* address, an Arkade address, or for Lightning a BOLT11 invoice (its amount
|
|
21766
22362
|
* must be covered by the refund), a Lightning address or an LNURL.
|
|
21767
22363
|
* @param options.target - The payout type; defaults to the old swap's.
|
|
21768
|
-
* @param options.signer - A signer for
|
|
21769
|
-
*
|
|
21770
|
-
*
|
|
21771
|
-
* paymaster only sponsors funding from the depositor's account.
|
|
22364
|
+
* @param options.signer - A signer for the refunded deposit account. Defaults
|
|
22365
|
+
* to its SDK key. The continuation explicitly reuses that funded account
|
|
22366
|
+
* instead of allocating a new deposit address.
|
|
21772
22367
|
*/
|
|
21773
22368
|
async continueRefundedEvmSwap(oldSwapId, options) {
|
|
21774
|
-
if (options.signer && options.signer.address.toLowerCase() !== this.getEvmAddress().toLowerCase()) {
|
|
21775
|
-
throw new Error(
|
|
21776
|
-
`Cannot continue refunded swap ${oldSwapId} with signer ${options.signer.address}: a continuation is funded from this client's key (${this.getEvmAddress()}).`
|
|
21777
|
-
);
|
|
21778
|
-
}
|
|
21779
22369
|
const info = await this.getRefundedEvmSwapContinuation(
|
|
21780
22370
|
oldSwapId,
|
|
21781
22371
|
options.signer
|
|
@@ -21783,6 +22373,17 @@ network='${network}'`
|
|
|
21783
22373
|
if (!info.eligible || !info.token || !info.amount || !info.oldSwap) {
|
|
21784
22374
|
throw new Error(_nullishCoalesce(info.reason, () => ( "Refunded swap cannot be continued.")));
|
|
21785
22375
|
}
|
|
22376
|
+
if (options.signer && options.signer.address.toLowerCase() !== _optionalChain([info, 'access', _376 => _376.smartAccountAddress, 'optionalAccess', _377 => _377.toLowerCase, 'call', _378 => _378()])) {
|
|
22377
|
+
throw new Error(
|
|
22378
|
+
"Continuation must be funded from this client's key or the recorded depositor"
|
|
22379
|
+
);
|
|
22380
|
+
}
|
|
22381
|
+
const original = await this.getSwapDepositorKey(oldSwapId).catch(
|
|
22382
|
+
(error) => {
|
|
22383
|
+
if (!options.signer) throw error;
|
|
22384
|
+
return void 0;
|
|
22385
|
+
}
|
|
22386
|
+
);
|
|
21786
22387
|
const target = _nullishCoalesce(options.target, () => ( {
|
|
21787
22388
|
evm_to_arkade: "arkade",
|
|
21788
22389
|
evm_to_bitcoin: "bitcoin",
|
|
@@ -21793,7 +22394,7 @@ network='${network}'`
|
|
|
21793
22394
|
tokenAddress: info.token.address,
|
|
21794
22395
|
evmChainId: 42161,
|
|
21795
22396
|
userAddress: _nullishCoalesce(info.smartAccountAddress, () => ( "")),
|
|
21796
|
-
gasless:
|
|
22397
|
+
gasless: false
|
|
21797
22398
|
};
|
|
21798
22399
|
let created;
|
|
21799
22400
|
if (target === "arkade") {
|
|
@@ -21819,6 +22420,18 @@ network='${network}'`
|
|
|
21819
22420
|
);
|
|
21820
22421
|
}
|
|
21821
22422
|
const newSwapId = created.response.id;
|
|
22423
|
+
if (this.#swapStorage) {
|
|
22424
|
+
const next = await this.getStoredSwap(newSwapId);
|
|
22425
|
+
const sharedAddress = deriveEvmAddress(
|
|
22426
|
+
this.#getEvmSigningKey()
|
|
22427
|
+
).toLowerCase();
|
|
22428
|
+
if (next && original && original.address.toLowerCase() !== sharedAddress)
|
|
22429
|
+
await this.#swapStorage.store({
|
|
22430
|
+
...next,
|
|
22431
|
+
evmDepositorKeyIndex: original.keyIndex,
|
|
22432
|
+
evmDepositorSecretKey: original.privateKey
|
|
22433
|
+
});
|
|
22434
|
+
}
|
|
21822
22435
|
const submitted = await this.cctpInbound.submitBalanceUserOp({
|
|
21823
22436
|
swapId: newSwapId,
|
|
21824
22437
|
// The new swap's own hash and terms, recorded when it was just
|
|
@@ -21830,7 +22443,7 @@ network='${network}'`
|
|
|
21830
22443
|
),
|
|
21831
22444
|
pins: options.funding
|
|
21832
22445
|
},
|
|
21833
|
-
signer:
|
|
22446
|
+
signer: await this.#depositorOwnerSigner(info.oldSwap, options.signer),
|
|
21834
22447
|
expectedMaxSourceAmount: sourceAmount
|
|
21835
22448
|
});
|
|
21836
22449
|
if (submitted.transactionHash) {
|
|
@@ -21877,20 +22490,7 @@ network='${network}'`
|
|
|
21877
22490
|
`Sponsored refunds run on Arbitrum only; swap ${swapId} is on chain ${chainId}. Use refundEvmWithSigner.`
|
|
21878
22491
|
);
|
|
21879
22492
|
}
|
|
21880
|
-
const
|
|
21881
|
-
let owner;
|
|
21882
|
-
if (_optionalChain([depositor, 'optionalAccess', _337 => _337.toLowerCase, 'call', _338 => _338()]) === this.getEvmAddress().toLowerCase()) {
|
|
21883
|
-
owner = this.#keyOwnerSigner();
|
|
21884
|
-
} else if (gasless && _optionalChain([depositor, 'optionalAccess', _339 => _339.toLowerCase, 'call', _340 => _340()]) === deriveEvmAddress(stored.secretKey).toLowerCase()) {
|
|
21885
|
-
owner = keyToKernelOwnerSigner(
|
|
21886
|
-
_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, stored.secretKey.replace(/^0x/, "")),
|
|
21887
|
-
42161
|
|
21888
|
-
);
|
|
21889
|
-
} else {
|
|
21890
|
-
throw new Error(
|
|
21891
|
-
`Swap ${swapId} was funded by ${depositor}, not this client's key; only gasless swaps can be refunded sponsored. Refund it with \`refundEvmWithSigner\` from that wallet.`
|
|
21892
|
-
);
|
|
21893
|
-
}
|
|
22493
|
+
const owner = await this.#depositorOwnerSigner(stored.response);
|
|
21894
22494
|
const result = await this.refundSwap(swapId);
|
|
21895
22495
|
if (!result.evmRefundData) {
|
|
21896
22496
|
throw new Error(
|
|
@@ -21908,19 +22508,15 @@ network='${network}'`
|
|
|
21908
22508
|
const refund = result.evmRefundData;
|
|
21909
22509
|
return this.#sponsoredUserOp(
|
|
21910
22510
|
owner,
|
|
21911
|
-
(account) =>
|
|
22511
|
+
(account) => _chunkEI5ILLQ3cjs.refundForAsOwnRefund.call(void 0, refund, account)
|
|
21912
22512
|
);
|
|
21913
22513
|
}
|
|
21914
|
-
/** This client's key as the Kernel owner on Arbitrum. */
|
|
21915
|
-
#keyOwnerSigner() {
|
|
21916
|
-
return keyToKernelOwnerSigner(this.#signer.deriveEvmKey().secretKey, 42161);
|
|
21917
|
-
}
|
|
21918
22514
|
/**
|
|
21919
22515
|
* An `eth_call` over the AA RPC, for reads on an account this client owns
|
|
21920
22516
|
* with its key (whose signer does not read the chain).
|
|
21921
22517
|
*/
|
|
21922
22518
|
async #aaRpcCall() {
|
|
21923
|
-
const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access',
|
|
22519
|
+
const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _379 => _379.#config, 'access', _380 => _380.aa, 'optionalAccess', _381 => _381.rpcUrl]), () => ( _optionalChain([this, 'access', _382 => _382.#config, 'access', _383 => _383.aa, 'optionalAccess', _384 => _384.bundlerUrl])));
|
|
21924
22520
|
if (!rpcUrl) {
|
|
21925
22521
|
throw new Error(
|
|
21926
22522
|
"Reading a refunded balance without a signer requires AA config (`.withAa(...)`)."
|
|
@@ -21961,7 +22557,7 @@ network='${network}'`
|
|
|
21961
22557
|
`Gasless funding on chain ${chainId} is submitted by this SDK as a sponsored UserOp and requires AA config. Call \`.withAa({ bundlerUrl, paymasterPolicyId })\` on the ClientBuilder before \`.build()\`.`
|
|
21962
22558
|
);
|
|
21963
22559
|
}
|
|
21964
|
-
if (!_optionalChain([this, 'access',
|
|
22560
|
+
if (!_optionalChain([this, 'access', _385 => _385.#config, 'access', _386 => _386.aa, 'access', _387 => _387.paymasterPolicyId, 'optionalAccess', _388 => _388.trim, 'call', _389 => _389()])) {
|
|
21965
22561
|
if (this.#config.aa.allowSelfPaidFunding) return { mode: "self-paid" };
|
|
21966
22562
|
throw new Error(
|
|
21967
22563
|
"Sponsored funding requires a paymasterPolicyId. Self-paid local tests must explicitly set allowSelfPaidFunding and prefund the account with ETH."
|
|
@@ -22041,7 +22637,7 @@ network='${network}'`
|
|
|
22041
22637
|
swapId,
|
|
22042
22638
|
serverData,
|
|
22043
22639
|
chainId,
|
|
22044
|
-
_optionalChain([options, 'optionalAccess',
|
|
22640
|
+
_optionalChain([options, 'optionalAccess', _390 => _390.funding])
|
|
22045
22641
|
);
|
|
22046
22642
|
const nonceBytes = new Uint8Array(32);
|
|
22047
22643
|
crypto.getRandomValues(nonceBytes);
|
|
@@ -22050,9 +22646,12 @@ network='${network}'`
|
|
|
22050
22646
|
);
|
|
22051
22647
|
const deadline = BigInt(Math.floor(Date.now() / 1e3) + 30 * 60);
|
|
22052
22648
|
const sourceAmount = checked.sourceAmount;
|
|
22053
|
-
const evmKey = this.#
|
|
22649
|
+
const evmKey = await this.#getFundingEvmSigningKey(
|
|
22650
|
+
storedSwap,
|
|
22651
|
+
swap.gasless
|
|
22652
|
+
);
|
|
22054
22653
|
const depositorAddress = deriveEvmAddress(evmKey);
|
|
22055
|
-
const digest =
|
|
22654
|
+
const digest = _chunkEI5ILLQ3cjs.buildPermit2FundingDigest.call(void 0, {
|
|
22056
22655
|
chainId,
|
|
22057
22656
|
coordinatorAddress: checked.coordinator,
|
|
22058
22657
|
sourceToken: checked.sourceToken,
|
|
@@ -22086,14 +22685,14 @@ network='${network}'`
|
|
|
22086
22685
|
delegated
|
|
22087
22686
|
);
|
|
22088
22687
|
let eip2612Permit;
|
|
22089
|
-
if (_optionalChain([serverData, 'access',
|
|
22688
|
+
if (_optionalChain([serverData, 'access', _391 => _391.eip2612, 'optionalAccess', _392 => _392.supported]) && !serverData.eip2612.already_approved) {
|
|
22090
22689
|
const maxUint256 = BigInt(
|
|
22091
22690
|
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
|
22092
22691
|
);
|
|
22093
|
-
const eip2612Digest =
|
|
22692
|
+
const eip2612Digest = _chunkEI5ILLQ3cjs.buildEip2612PermitDigest.call(void 0, {
|
|
22094
22693
|
domainSeparator: serverData.eip2612.domain_separator,
|
|
22095
22694
|
owner: depositorAddress,
|
|
22096
|
-
spender:
|
|
22695
|
+
spender: _chunkEI5ILLQ3cjs.PERMIT2_ADDRESS,
|
|
22097
22696
|
value: maxUint256,
|
|
22098
22697
|
nonce: serverData.eip2612.nonce,
|
|
22099
22698
|
deadline
|
|
@@ -22166,7 +22765,7 @@ network='${network}'`
|
|
|
22166
22765
|
if (!this.#swapStorage)
|
|
22167
22766
|
throw new Error("Sponsored funding requires swap storage");
|
|
22168
22767
|
if (stored.evmFundingUserOpHash) {
|
|
22169
|
-
const key2 = this.#gaslessDepositorKey(swapId, stored, swap);
|
|
22768
|
+
const key2 = await this.#gaslessDepositorKey(swapId, stored, swap);
|
|
22170
22769
|
const { client } = await this.cctpInbound.createSmartAccountClient({
|
|
22171
22770
|
signer: keyToKernelOwnerSigner(
|
|
22172
22771
|
_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, key2.replace(/^0x/, "")),
|
|
@@ -22194,7 +22793,7 @@ network='${network}'`
|
|
|
22194
22793
|
}
|
|
22195
22794
|
const expected = {
|
|
22196
22795
|
...this.#fundingExpectation(swapId, stored),
|
|
22197
|
-
pins: _optionalChain([options, 'optionalAccess',
|
|
22796
|
+
pins: _optionalChain([options, 'optionalAccess', _393 => _393.funding])
|
|
22198
22797
|
};
|
|
22199
22798
|
if (expected.terms.chainId !== AA_CHAIN_ID) {
|
|
22200
22799
|
throw new Error(
|
|
@@ -22206,7 +22805,7 @@ network='${network}'`
|
|
|
22206
22805
|
const { arbitrum: arbitrum2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./chains-D6LHJZMI-AAYKXZGC.cjs")));
|
|
22207
22806
|
const rpc = createPublicClient2({
|
|
22208
22807
|
chain: arbitrum2,
|
|
22209
|
-
transport: http2(_nullishCoalesce(_optionalChain([this, 'access',
|
|
22808
|
+
transport: http2(_nullishCoalesce(_optionalChain([this, 'access', _394 => _394.#config, 'access', _395 => _395.aa, 'optionalAccess', _396 => _396.rpcUrl]), () => ( _optionalChain([this, 'access', _397 => _397.#config, 'access', _398 => _398.aa, 'optionalAccess', _399 => _399.bundlerUrl]))))
|
|
22210
22809
|
});
|
|
22211
22810
|
const receipt = await rpc.getTransactionReceipt({
|
|
22212
22811
|
hash: stored.evmFundTxid
|
|
@@ -22219,8 +22818,10 @@ network='${network}'`
|
|
|
22219
22818
|
if (receipt.status === "reverted") {
|
|
22220
22819
|
await this.#forgetEvmFunding(swapId, stored.evmFundTxid);
|
|
22221
22820
|
} else if (receipt.status === "success" && receipt.logs !== void 0) {
|
|
22222
|
-
const sender = (_nullishCoalesce(expected.terms.htlcVersion, () => ( 0))) >= 7 ? deriveEvmAddress(
|
|
22223
|
-
|
|
22821
|
+
const sender = (_nullishCoalesce(expected.terms.htlcVersion, () => ( 0))) >= 7 ? deriveEvmAddress(
|
|
22822
|
+
await this.#gaslessDepositorKey(swapId, stored, swap)
|
|
22823
|
+
) : expected.terms.coordinator;
|
|
22824
|
+
const locks = _chunkEI5ILLQ3cjs.findSwapCreated.call(void 0, receipt.logs, {
|
|
22224
22825
|
htlcAddress: expected.terms.htlcAddress,
|
|
22225
22826
|
hashLock: expected.hashLock,
|
|
22226
22827
|
claimAddress: expected.terms.claimAddress,
|
|
@@ -22244,7 +22845,7 @@ network='${network}'`
|
|
|
22244
22845
|
);
|
|
22245
22846
|
}
|
|
22246
22847
|
}
|
|
22247
|
-
const key = this.#gaslessDepositorKey(swapId, stored, swap);
|
|
22848
|
+
const key = await this.#gaslessDepositorKey(swapId, stored, swap);
|
|
22248
22849
|
const owner = keyToKernelOwnerSigner(
|
|
22249
22850
|
_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, key.replace(/^0x/, "")),
|
|
22250
22851
|
AA_CHAIN_ID
|
|
@@ -22272,7 +22873,7 @@ network='${network}'`
|
|
|
22272
22873
|
return { txHash };
|
|
22273
22874
|
}
|
|
22274
22875
|
async #setFundingUserOp(swapId, hash) {
|
|
22275
|
-
const current = await _optionalChain([this, 'access',
|
|
22876
|
+
const current = await _optionalChain([this, 'access', _400 => _400.#swapStorage, 'optionalAccess', _401 => _401.get, 'call', _402 => _402(swapId)]);
|
|
22276
22877
|
if (!current || !this.#swapStorage)
|
|
22277
22878
|
throw new Error("Cannot persist funding operation");
|
|
22278
22879
|
await this.#swapStorage.store({
|
|
@@ -22288,18 +22889,23 @@ network='${network}'`
|
|
|
22288
22889
|
* account, so a depositor this SDK does not control cannot be funded
|
|
22289
22890
|
* here.
|
|
22290
22891
|
*/
|
|
22291
|
-
#gaslessDepositorKey(swapId, stored, swap) {
|
|
22292
|
-
const depositor = _optionalChain([
|
|
22293
|
-
|
|
22294
|
-
|
|
22295
|
-
|
|
22296
|
-
|
|
22297
|
-
|
|
22298
|
-
|
|
22892
|
+
async #gaslessDepositorKey(swapId, stored, swap) {
|
|
22893
|
+
const depositor = _optionalChain([(_nullishCoalesce(_optionalChain([stored, 'access', _403 => _403.evmFundingTerms, 'optionalAccess', _404 => _404.depositor]), () => ( swap.client_evm_address))), 'optionalAccess', _405 => _405.toLowerCase, 'call', _406 => _406()]);
|
|
22894
|
+
if (!depositor) return this.#getEvmSigningKey();
|
|
22895
|
+
let key;
|
|
22896
|
+
try {
|
|
22897
|
+
key = (await this.getSwapDepositorKey(swapId)).privateKey.replace(
|
|
22898
|
+
/^0x/,
|
|
22899
|
+
""
|
|
22900
|
+
);
|
|
22901
|
+
} catch (e35) {
|
|
22902
|
+
key = void 0;
|
|
22299
22903
|
}
|
|
22300
|
-
|
|
22301
|
-
|
|
22302
|
-
|
|
22904
|
+
if (!key || deriveEvmAddress(key).toLowerCase() !== depositor)
|
|
22905
|
+
throw new Error(
|
|
22906
|
+
`Cannot fund swap ${swapId} sponsored: its depositor ${depositor} is not an SDK-controlled account. Fund it from that wallet with fundSwap.`
|
|
22907
|
+
);
|
|
22908
|
+
return key;
|
|
22303
22909
|
}
|
|
22304
22910
|
/**
|
|
22305
22911
|
* Get the ephemeral depositor key for a gasless swap funded swap.
|
|
@@ -22330,29 +22936,40 @@ network='${network}'`
|
|
|
22330
22936
|
);
|
|
22331
22937
|
}
|
|
22332
22938
|
const response = storedSwap.response;
|
|
22333
|
-
const depositor = _optionalChain([
|
|
22939
|
+
const depositor = _optionalChain([(_nullishCoalesce(_optionalChain([storedSwap, 'access', _407 => _407.evmFundingTerms, 'optionalAccess', _408 => _408.depositor]), () => ( response.client_evm_address))), 'optionalAccess', _409 => _409.toLowerCase, 'call', _410 => _410()]);
|
|
22334
22940
|
const sharedKey = this.#getEvmSigningKey();
|
|
22335
|
-
const
|
|
22336
|
-
|
|
22337
|
-
|
|
22338
|
-
|
|
22339
|
-
|
|
22340
|
-
|
|
22941
|
+
const indexedKey = storedSwap.evmDepositorKeyIndex !== void 0 ? _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0,
|
|
22942
|
+
this.deriveSwapParamsAtIndex(storedSwap.evmDepositorKeyIndex).secretKey
|
|
22943
|
+
) : void 0;
|
|
22944
|
+
const candidates = [
|
|
22945
|
+
storedSwap.secretKey,
|
|
22946
|
+
...storedSwap.evmDepositorSecretKey ? [storedSwap.evmDepositorSecretKey] : [],
|
|
22947
|
+
...indexedKey ? [indexedKey] : [],
|
|
22948
|
+
sharedKey
|
|
22949
|
+
];
|
|
22950
|
+
const matched = depositor ? candidates.find(
|
|
22951
|
+
(key) => deriveEvmAddress(key).toLowerCase() === depositor
|
|
22952
|
+
) : void 0;
|
|
22953
|
+
if (depositor && !matched && (response.gasless || _optionalChain([storedSwap, 'access', _411 => _411.evmFundingTerms, 'optionalAccess', _412 => _412.depositor])))
|
|
22341
22954
|
throw new Error(
|
|
22342
|
-
`Cannot export a deposit key for swap ${swapId}: depositor ${
|
|
22955
|
+
`Cannot export a deposit key for swap ${swapId}: no SDK key for its recorded depositor ${depositor}, which is not an SDK-controlled account. Restore the original deposit account or use its wallet.`
|
|
22343
22956
|
);
|
|
22344
|
-
|
|
22957
|
+
const evmKey = _nullishCoalesce(matched, () => ( sharedKey));
|
|
22345
22958
|
const privateKey = evmKey.startsWith("0x") ? evmKey : `0x${evmKey}`;
|
|
22346
22959
|
const address2 = deriveEvmAddress(evmKey);
|
|
22347
|
-
return {
|
|
22960
|
+
return {
|
|
22961
|
+
privateKey,
|
|
22962
|
+
address: address2,
|
|
22963
|
+
keyIndex: deriveEvmAddress(storedSwap.secretKey).toLowerCase() === address2.toLowerCase() ? storedSwap.keyIndex : indexedKey && deriveEvmAddress(indexedKey).toLowerCase() === address2.toLowerCase() ? storedSwap.evmDepositorKeyIndex : void 0
|
|
22964
|
+
};
|
|
22348
22965
|
}
|
|
22349
22966
|
/**
|
|
22350
22967
|
* Wallet-level variant of {@link getSwapDepositorKey} — returns the
|
|
22351
22968
|
* deterministic EVM signing key for this wallet without requiring a
|
|
22352
22969
|
* specific swap to be stored locally.
|
|
22353
22970
|
*
|
|
22354
|
-
*
|
|
22355
|
-
* per-swap
|
|
22971
|
+
* Only for legacy wallet-level deposits (`m/44'/60'/0'/0/0`).
|
|
22972
|
+
* Use getSwapDepositorKey for per-swap deposits. Intended for recovery tools
|
|
22356
22973
|
* where the user supplies the burn details manually and a per-swap
|
|
22357
22974
|
* record may no longer exist (e.g. fresh device, cleared site data).
|
|
22358
22975
|
*/
|
|
@@ -22391,7 +23008,7 @@ network='${network}'`
|
|
|
22391
23008
|
if (!sourceChain) {
|
|
22392
23009
|
throw new Error(`Swap ${swapId} is not a CCTP-inbound swap.`);
|
|
22393
23010
|
}
|
|
22394
|
-
const burnTxHash = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
23011
|
+
const burnTxHash = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _413 => _413.burnTxHash]), () => ( stored.cctpBurnTxid));
|
|
22395
23012
|
if (!burnTxHash) {
|
|
22396
23013
|
throw new Error(
|
|
22397
23014
|
`No CCTP burn is recorded for swap ${swapId}; pass it as \`burnTxHash\`.`
|
|
@@ -22400,15 +23017,15 @@ network='${network}'`
|
|
|
22400
23017
|
return recoverCctpInbound(
|
|
22401
23018
|
{ aa: this.#config.aa },
|
|
22402
23019
|
{
|
|
22403
|
-
signer: this.#depositorOwnerSigner(
|
|
23020
|
+
signer: await this.#depositorOwnerSigner(
|
|
22404
23021
|
stored.response,
|
|
22405
|
-
_optionalChain([options, 'optionalAccess',
|
|
23022
|
+
_optionalChain([options, 'optionalAccess', _414 => _414.ownerSigner])
|
|
22406
23023
|
),
|
|
22407
23024
|
burnTxHash,
|
|
22408
23025
|
sourceChain,
|
|
22409
23026
|
recipient,
|
|
22410
|
-
onProgress: _optionalChain([options, 'optionalAccess',
|
|
22411
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
23027
|
+
onProgress: _optionalChain([options, 'optionalAccess', _415 => _415.onProgress]),
|
|
23028
|
+
signal: _optionalChain([options, 'optionalAccess', _416 => _416.signal])
|
|
22412
23029
|
}
|
|
22413
23030
|
);
|
|
22414
23031
|
}
|
|
@@ -22552,14 +23169,14 @@ function b64Encode(u) {
|
|
|
22552
23169
|
return btoa(bin);
|
|
22553
23170
|
}
|
|
22554
23171
|
function isP2tr(script) {
|
|
22555
|
-
return _optionalChain([script, 'optionalAccess',
|
|
23172
|
+
return _optionalChain([script, 'optionalAccess', _417 => _417.length]) === 34 && script[0] === 81 && script[1] === 32;
|
|
22556
23173
|
}
|
|
22557
23174
|
function parseEscrowPsbt(psbt) {
|
|
22558
23175
|
const lenient = _chunkBEW62OUTcjs.Transaction2.fromPSBT(psbt, { disableScriptCheck: true });
|
|
22559
23176
|
let stripped = false;
|
|
22560
23177
|
for (let i = 0; i < lenient.inputsLength; i++) {
|
|
22561
23178
|
const input = lenient.getInput(i);
|
|
22562
|
-
if (input.witnessScript && isP2tr(_optionalChain([input, 'access',
|
|
23179
|
+
if (input.witnessScript && isP2tr(_optionalChain([input, 'access', _418 => _418.witnessUtxo, 'optionalAccess', _419 => _419.script]))) {
|
|
22563
23180
|
lenient.updateInput(i, { witnessScript: void 0 }, true);
|
|
22564
23181
|
stripped = true;
|
|
22565
23182
|
}
|
|
@@ -22691,11 +23308,11 @@ var IdbWalletStorage = class {
|
|
|
22691
23308
|
}
|
|
22692
23309
|
async getMnemonic() {
|
|
22693
23310
|
const record = await this.#db.wallet.get(MNEMONIC_KEY);
|
|
22694
|
-
if (_optionalChain([record, 'optionalAccess',
|
|
23311
|
+
if (_optionalChain([record, 'optionalAccess', _420 => _420.value])) {
|
|
22695
23312
|
return record.value;
|
|
22696
23313
|
}
|
|
22697
23314
|
const v2Wallet = await readV2Wallet();
|
|
22698
|
-
if (!_optionalChain([v2Wallet, 'optionalAccess',
|
|
23315
|
+
if (!_optionalChain([v2Wallet, 'optionalAccess', _421 => _421.mnemonic])) {
|
|
22699
23316
|
return null;
|
|
22700
23317
|
}
|
|
22701
23318
|
await this.setMnemonic(v2Wallet.mnemonic);
|
|
@@ -22710,7 +23327,7 @@ var IdbWalletStorage = class {
|
|
|
22710
23327
|
}
|
|
22711
23328
|
async getKeyIndex() {
|
|
22712
23329
|
const record = await this.#db.wallet.get(KEY_INDEX_KEY);
|
|
22713
|
-
return _nullishCoalesce(_optionalChain([record, 'optionalAccess',
|
|
23330
|
+
return _nullishCoalesce(_optionalChain([record, 'optionalAccess', _422 => _422.value]), () => ( 0));
|
|
22714
23331
|
}
|
|
22715
23332
|
async setKeyIndex(index) {
|
|
22716
23333
|
await this.#db.wallet.put({ key: KEY_INDEX_KEY, value: index });
|
|
@@ -22718,7 +23335,7 @@ var IdbWalletStorage = class {
|
|
|
22718
23335
|
async incrementKeyIndex() {
|
|
22719
23336
|
return this.#db.transaction("rw", this.#db.wallet, async () => {
|
|
22720
23337
|
const record = await this.#db.wallet.get(KEY_INDEX_KEY);
|
|
22721
|
-
const current = _nullishCoalesce(_optionalChain([record, 'optionalAccess',
|
|
23338
|
+
const current = _nullishCoalesce(_optionalChain([record, 'optionalAccess', _423 => _423.value]), () => ( 0));
|
|
22722
23339
|
await this.#db.wallet.put({ key: KEY_INDEX_KEY, value: current + 1 });
|
|
22723
23340
|
return current;
|
|
22724
23341
|
});
|
|
@@ -22774,7 +23391,7 @@ function readV2Wallet() {
|
|
|
22774
23391
|
}
|
|
22775
23392
|
const request = indexedDB.open(V2_DB_NAME);
|
|
22776
23393
|
request.onupgradeneeded = () => {
|
|
22777
|
-
_optionalChain([request, 'access',
|
|
23394
|
+
_optionalChain([request, 'access', _424 => _424.transaction, 'optionalAccess', _425 => _425.abort, 'call', _426 => _426()]);
|
|
22778
23395
|
};
|
|
22779
23396
|
request.onerror = () => {
|
|
22780
23397
|
resolve(null);
|
|
@@ -22806,7 +23423,7 @@ function readV2Wallet() {
|
|
|
22806
23423
|
db.close();
|
|
22807
23424
|
resolve(null);
|
|
22808
23425
|
};
|
|
22809
|
-
} catch (
|
|
23426
|
+
} catch (e36) {
|
|
22810
23427
|
db.close();
|
|
22811
23428
|
resolve(null);
|
|
22812
23429
|
}
|
|
@@ -22999,10 +23616,16 @@ async function getUsdPrices(tokens, options = {}) {
|
|
|
22999
23616
|
|
|
23000
23617
|
|
|
23001
23618
|
|
|
23002
|
-
|
|
23619
|
+
|
|
23620
|
+
|
|
23621
|
+
|
|
23622
|
+
|
|
23623
|
+
|
|
23624
|
+
|
|
23625
|
+
exports.createApiClient = createApiClient; exports.getVhtlcAmounts = getVhtlcAmounts; exports.parseArkadeAddress = parseArkadeAddress; exports.isValidArkadeAddress = isValidArkadeAddress; exports.invoicePaymentHash = invoicePaymentHash; exports.invoiceAmountMsat = invoiceAmountMsat; exports.fetchCctpFee = fetchCctpFee; exports.computeCctpFastFee = computeCctpFastFee; exports.addressToBytes32 = addressToBytes32; exports.bytes32ToAddress = bytes32ToAddress; exports.getDomain = getDomain; exports.needsBridge = needsBridge; exports.isValidSolanaAddress = isValidSolanaAddress; exports.solanaAddressToBytes32 = solanaAddressToBytes32; exports.approveAndBurn = approveAndBurn; exports.encodeDepositForBurn = encodeDepositForBurn; exports.CHAIN_ID_TO_CCTP_NAME = CHAIN_ID_TO_CCTP_NAME; exports.DIRECT_SOURCE_CHAIN_IDS = DIRECT_SOURCE_CHAIN_IDS; exports.isCctpOnlySource = isCctpOnlySource; exports.CCTP_STANDARD_ONLY_CHAIN_IDS = CCTP_STANDARD_ONLY_CHAIN_IDS; exports.finalityForChainId = finalityForChainId; exports.cctpMetaForChainId = cctpMetaForChainId; exports.CCTP_VIEM_CHAINS = CCTP_VIEM_CHAINS; exports.getCctpViemChain = getCctpViemChain; exports.getCctpViemChainByName = getCctpViemChainByName; exports.cctpFundSwap = cctpFundSwap; exports.CctpInboundClient = CctpInboundClient; exports.deriveEvmAddress = deriveEvmAddress; exports.signEvmDigest = signEvmDigest; exports.signEvmMessage = signEvmMessage; exports.MAX_UINT256 = MAX_UINT256; exports.signEip2612Permit = signEip2612Permit; exports.buildDomainSeparator = buildDomainSeparator; exports.USDC_DOMAIN_FIELDS = USDC_DOMAIN_FIELDS; exports.signPermit2Witness = signPermit2Witness; exports.recoverCctpInbound = recoverCctpInbound; exports.LZ_EIDS = LZ_EIDS; exports.USDT0_ADDRESSES = USDT0_ADDRESSES; exports.trackMessage = trackMessage; exports.getMessageStatus = getMessageStatus; exports.getExplorerUrl = getExplorerUrl; exports.getEid = getEid; exports.needsBridge2 = needsBridge2; exports.Asset = Asset; exports.BTC_LIGHTNING = BTC_LIGHTNING; exports.BTC_ARKADE = BTC_ARKADE; exports.BTC_ONCHAIN = BTC_ONCHAIN; exports.BTC_LIGHTNING_INFO = BTC_LIGHTNING_INFO; exports.BTC_ARKADE_INFO = BTC_ARKADE_INFO; exports.BTC_ONCHAIN_INFO = BTC_ONCHAIN_INFO; exports.isLightning = isLightning; exports.isArkade = isArkade; exports.isBtcOnchain = isBtcOnchain; exports.isBtc = isBtc; exports.isBtcPegged = isBtcPegged; exports.isEvmToken = isEvmToken; exports.isSourceEvmChain = isSourceEvmChain; exports.isBridgeOnlyChain = isBridgeOnlyChain; exports.isNativeLockTarget = isNativeLockTarget; exports.isEvmSwapSource = isEvmSwapSource; exports.isTronToken = isTronToken; exports.isCctpRoutedUsdcTarget = isCctpRoutedUsdcTarget; exports.isBridgedTarget = isBridgedTarget; exports.isSolanaToken = isSolanaToken; exports.isCctpUsdc = isCctpUsdc; exports.isEthereumToken = isEthereumToken; exports.isPolygonToken = isPolygonToken; exports.isArbitrumToken = isArbitrumToken; exports.isBaseToken = isBaseToken; exports.isOptimismToken = isOptimismToken; exports.isAvalancheToken = isAvalancheToken; exports.isLineaToken = isLineaToken; exports.isSonicToken = isSonicToken; exports.toChain = toChain; exports.toChainName = toChainName; exports.getBridgeTargetChain = getBridgeTargetChain; exports.getCctpBridgeTokens = getCctpBridgeTokens; exports.getUsdt0BridgeTokens = getUsdt0BridgeTokens; exports.isSpark = isSpark; exports.Signer = Signer; exports.validateBitcoinPayout = validateBitcoinPayout; exports.allocateBitcoinPayout = allocateBitcoinPayout; exports.computeHash160 = computeHash160; exports.buildOnchainClaimTransaction = buildOnchainClaimTransaction; exports.buildOnchainRefundTransaction = buildOnchainRefundTransaction; exports.verifyHtlcAddress = verifyHtlcAddress; exports.SwapVerificationError = SwapVerificationError; exports.bitcoinNetworkOf = bitcoinNetworkOf; exports.commitBitcoinPayment = commitBitcoinPayment; exports.minimumBitcoinPayout = minimumBitcoinPayout; exports.addressToScriptHash = addressToScriptHash; exports.ElectrumWsClient = ElectrumWsClient; exports.electrumFindOutputByAddress = electrumFindOutputByAddress; exports.electrumFetchTransactionOutputs = electrumFetchTransactionOutputs; exports.electrumBroadcastTransaction = electrumBroadcastTransaction; exports.electrumWaitForOutputByAddress = electrumWaitForOutputByAddress; exports.KERNEL_DELEGATION_TARGET = KERNEL_DELEGATION_TARGET; exports.parseEip7702Delegation = parseEip7702Delegation; exports.isKernelDelegation = isKernelDelegation; exports.kernelErc1271Digest = kernelErc1271Digest; exports.wrapKernelErc1271Signature = wrapKernelErc1271Signature; exports.buildArkadeClaim = buildArkadeClaim; exports.RIF_SMART_WALLET_INDEX = RIF_SMART_WALLET_INDEX; exports.rifSmartWalletAddress = rifSmartWalletAddress; exports.rifSmartWallet = rifSmartWallet; exports.WalletClaimRequiredError = WalletClaimRequiredError; exports.SWAP_STORAGE_VERSION = SWAP_STORAGE_VERSION; exports.InMemoryWalletStorage = InMemoryWalletStorage; exports.InMemorySwapStorage = InMemorySwapStorage; exports.inMemoryStorageFactory = inMemoryStorageFactory; exports.tronAddressToBytes32 = tronAddressToBytes32; exports.isValidTronAddress = isValidTronAddress; exports.RehashNotRecordedError = RehashNotRecordedError; exports.rehashAuthorizationMessage = rehashAuthorizationMessage; exports.DEFAULT_ELECTRUM_WS_URLS = DEFAULT_ELECTRUM_WS_URLS; exports.ClientBuilder = ClientBuilder; exports.Client = Client; exports.signEscrowArkTx = signEscrowArkTx; exports.signEscrowCheckpoints = signEscrowCheckpoints; exports.signEscrowDelegate = signEscrowDelegate; exports.getArkTxid = getArkTxid; exports.computeExchangeRate = computeExchangeRate; exports.calculateTargetAmount = calculateTargetAmount; exports.calculateSourceAmount = calculateSourceAmount; exports.IdbWalletStorage = IdbWalletStorage; exports.IdbSwapStorage = IdbSwapStorage; exports.idbStorageFactory = idbStorageFactory; exports.getUsdPrices = getUsdPrices;
|
|
23003
23626
|
/*! Bundled license information:
|
|
23004
23627
|
|
|
23005
23628
|
@scure/bip39/index.js:
|
|
23006
23629
|
(*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
23007
23630
|
*/
|
|
23008
|
-
//# sourceMappingURL=chunk-
|
|
23631
|
+
//# sourceMappingURL=chunk-3633KDTW.cjs.map
|