@satora/swap 1.12.0 → 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-YBQPH7NH.js → chunk-34OYIFOU.js} +506 -113
- package/dist/chunk-34OYIFOU.js.map +1 -0
- package/dist/{chunk-EL4FUZJO.cjs → chunk-3633KDTW.cjs} +879 -486
- 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-KECPPSZL.js → chunk-KMBGRQS7.js} +5 -5
- package/dist/{chunk-KECPPSZL.js.map → chunk-KMBGRQS7.js.map} +1 -1
- package/dist/{chunk-QJ4EK6UG.cjs → chunk-LZQZYSOZ.cjs} +5 -5
- package/dist/{chunk-QJ4EK6UG.cjs.map → chunk-LZQZYSOZ.cjs.map} +1 -1
- package/dist/delegate.cjs +2 -2
- package/dist/delegate.js +1 -1
- package/dist/{dist-Y3ZVHXAJ.js → dist-3N76II5O.js} +14 -4
- package/dist/dist-KQINAMDC.cjs +406 -0
- package/dist/{dist-R6DUJG36.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 +30 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -8
- 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/client.d.cts +14 -9
- 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/payment-safety.d.cts +2 -0
- package/dist/types/cjs/pure/create/payout-slippage.d.cts +29 -0
- package/dist/types/cjs/pure/create/types.d.cts +9 -1
- 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 +78 -0
- package/dist/types/cjs/pure/index.d.cts +3 -1
- 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/version.d.cts +4 -4
- package/dist/types/cjs/swap/contracts/bitcoin-reader-esplora.d.cts +5 -0
- package/dist/types/esm/pure/client.d.ts +14 -9
- 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/payment-safety.d.ts +2 -0
- package/dist/types/esm/pure/create/payout-slippage.d.ts +29 -0
- package/dist/types/esm/pure/create/types.d.ts +9 -1
- 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 +78 -0
- package/dist/types/esm/pure/index.d.ts +3 -1
- 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/version.d.ts +4 -4
- package/dist/types/esm/swap/contracts/bitcoin-reader-esplora.d.ts +5 -0
- package/package.json +1 -1
- 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-5DQHR3RO.cjs.map +0 -1
- package/dist/chunk-EL4FUZJO.cjs.map +0 -1
- package/dist/chunk-INHFP222.cjs.map +0 -1
- package/dist/chunk-LSCRTQOS.js.map +0 -1
- package/dist/chunk-YBQPH7NH.js.map +0 -1
- package/dist/dist-R6DUJG36.cjs +0 -396
- /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-Y3ZVHXAJ.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
|
|
|
@@ -6849,8 +6849,8 @@ function removeTrailingSlash(url) {
|
|
|
6849
6849
|
}
|
|
6850
6850
|
function createApiClient(options) {
|
|
6851
6851
|
const headers = {
|
|
6852
|
-
"X-Lendaswap-Client":
|
|
6853
|
-
...
|
|
6852
|
+
"X-Lendaswap-Client": _chunkLZQZYSOZcjs.CLIENT_AGENT,
|
|
6853
|
+
..._chunkLZQZYSOZcjs.PROTOCOL_HEADERS,
|
|
6854
6854
|
..._nullishCoalesce(options.defaultHeaders, () => ( {}))
|
|
6855
6855
|
};
|
|
6856
6856
|
return createClient({
|
|
@@ -6863,7 +6863,7 @@ async function getVhtlcAmounts(params) {
|
|
|
6863
6863
|
const { vhtlcAddress, network, arkadeServerUrl } = params;
|
|
6864
6864
|
const decoded = _chunkBEW62OUTcjs.ArkAddress.decode(vhtlcAddress);
|
|
6865
6865
|
const pkScript = _chunkRYZSWESUcjs.hex.encode(decoded.pkScript);
|
|
6866
|
-
const serverUrl =
|
|
6866
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrl.call(void 0, network, arkadeServerUrl);
|
|
6867
6867
|
const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
|
|
6868
6868
|
const [spendableResult, spentResult, recoverableResult] = await Promise.all([
|
|
6869
6869
|
indexerProvider.getVtxos({ scripts: [pkScript], spendableOnly: true }),
|
|
@@ -6898,7 +6898,7 @@ function parseArkadeAddress(address2, network) {
|
|
|
6898
6898
|
throw new Error(`Invalid Arkade address: ${reason}`);
|
|
6899
6899
|
}
|
|
6900
6900
|
if (network !== void 0) {
|
|
6901
|
-
const expectedHrp =
|
|
6901
|
+
const expectedHrp = _chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, _chunkLZQZYSOZcjs.getNetworkName.call(void 0, network));
|
|
6902
6902
|
if (decoded.hrp !== expectedHrp) {
|
|
6903
6903
|
throw new Error(
|
|
6904
6904
|
`Arkade address has wrong network: expected "${expectedHrp}1..." prefix, got "${decoded.hrp}1..."`
|
|
@@ -7194,7 +7194,7 @@ function ensureBytes32(value) {
|
|
|
7194
7194
|
);
|
|
7195
7195
|
}
|
|
7196
7196
|
function keccak256Hex(input) {
|
|
7197
|
-
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)))}`;
|
|
7198
7198
|
}
|
|
7199
7199
|
function encodeUint256(value) {
|
|
7200
7200
|
if (value < 0n) throw new Error("uint256 cannot be negative");
|
|
@@ -7324,7 +7324,7 @@ async function cctpFundSwap(context, params) {
|
|
|
7324
7324
|
const source = cctpMetaForChainId(signer.chainId);
|
|
7325
7325
|
const destination = cctpMetaForChainId(settlementChain.id);
|
|
7326
7326
|
const minFinalityThreshold = finalityForChainId(signer.chainId);
|
|
7327
|
-
const { accountAddress: smartAccountAddress } = await
|
|
7327
|
+
const { accountAddress: smartAccountAddress } = await _chunkEI5ILLQ3cjs.createSwapSmartAccountClient.call(void 0, {
|
|
7328
7328
|
signer: ownerSigner,
|
|
7329
7329
|
aa: context.aa,
|
|
7330
7330
|
chain: settlementChain
|
|
@@ -7351,14 +7351,14 @@ async function cctpFundSwap(context, params) {
|
|
|
7351
7351
|
_optionalChain([onProgress, 'optionalCall', _29 => _29({ phase: "burning", burnTxHash })]);
|
|
7352
7352
|
burnTxHash = await confirmBurn(signer, burnTxHash, onBurn);
|
|
7353
7353
|
_optionalChain([onProgress, 'optionalCall', _30 => _30({ phase: "attestation" })]);
|
|
7354
|
-
const { message, attestation } = await
|
|
7354
|
+
const { message, attestation } = await _chunkEI5ILLQ3cjs.fetchAttestation.call(void 0, {
|
|
7355
7355
|
sourceChain: source.name,
|
|
7356
7356
|
txHash: burnTxHash,
|
|
7357
7357
|
irisApiUrl,
|
|
7358
7358
|
signal
|
|
7359
7359
|
});
|
|
7360
7360
|
_optionalChain([onProgress, 'optionalCall', _31 => _31({ phase: "submitting" })]);
|
|
7361
|
-
const submit = await
|
|
7361
|
+
const submit = await _chunkEI5ILLQ3cjs.submitCctpInboundUserOp.call(void 0, context, {
|
|
7362
7362
|
swapId,
|
|
7363
7363
|
expected: params.expected,
|
|
7364
7364
|
signer: ownerSigner,
|
|
@@ -7411,7 +7411,7 @@ var CctpInboundClient = class {
|
|
|
7411
7411
|
aa: this.#aa,
|
|
7412
7412
|
chain: args.chain
|
|
7413
7413
|
};
|
|
7414
|
-
return
|
|
7414
|
+
return _chunkEI5ILLQ3cjs.createSwapSmartAccountClient.call(void 0, params);
|
|
7415
7415
|
}
|
|
7416
7416
|
/**
|
|
7417
7417
|
* Compose the 3-call UserOp batch (receiveMessage + USDC.approve +
|
|
@@ -7423,7 +7423,7 @@ var CctpInboundClient = class {
|
|
|
7423
7423
|
* which composes batch + send + wait-for-receipt.
|
|
7424
7424
|
*/
|
|
7425
7425
|
buildUserOpBatch(params) {
|
|
7426
|
-
return
|
|
7426
|
+
return _chunkEI5ILLQ3cjs.buildCctpInboundBatch.call(void 0, params);
|
|
7427
7427
|
}
|
|
7428
7428
|
/**
|
|
7429
7429
|
* End-to-end settlement UserOp: fetch calldata, build Kernel client,
|
|
@@ -7436,7 +7436,7 @@ var CctpInboundClient = class {
|
|
|
7436
7436
|
* caller's signer.
|
|
7437
7437
|
*/
|
|
7438
7438
|
submitUserOp(params) {
|
|
7439
|
-
return
|
|
7439
|
+
return _chunkEI5ILLQ3cjs.submitCctpInboundUserOp.call(void 0,
|
|
7440
7440
|
{ apiClient: this.#apiClient, aa: this.#aa },
|
|
7441
7441
|
{
|
|
7442
7442
|
...params,
|
|
@@ -7453,7 +7453,7 @@ var CctpInboundClient = class {
|
|
|
7453
7453
|
* paymaster-sponsored UserOp.
|
|
7454
7454
|
*/
|
|
7455
7455
|
submitBalanceUserOp(params) {
|
|
7456
|
-
return
|
|
7456
|
+
return _chunkEI5ILLQ3cjs.submitCctpInboundBalanceUserOp.call(void 0,
|
|
7457
7457
|
{ apiClient: this.#apiClient, aa: this.#aa },
|
|
7458
7458
|
{
|
|
7459
7459
|
...params,
|
|
@@ -7485,7 +7485,7 @@ var CctpInboundClient = class {
|
|
|
7485
7485
|
* `signal` (AbortSignal) to cancel early.
|
|
7486
7486
|
*/
|
|
7487
7487
|
waitForAttestation(options) {
|
|
7488
|
-
return
|
|
7488
|
+
return _chunkEI5ILLQ3cjs.fetchAttestation.call(void 0, options);
|
|
7489
7489
|
}
|
|
7490
7490
|
/**
|
|
7491
7491
|
* One-shot CCTP-inbound swap: approve + burn on the source chain,
|
|
@@ -7507,7 +7507,7 @@ _chunk5JR6AJ3Ycjs.init_utils.call(void 0, );
|
|
|
7507
7507
|
function deriveEvmAddress(secretKey) {
|
|
7508
7508
|
const keyBytes = typeof secretKey === "string" ? _chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, secretKey.replace(/^0x/, "")) : secretKey;
|
|
7509
7509
|
const uncompressedPubkey = _chunkBEW62OUTcjs.secp256k12.getPublicKey(keyBytes, false);
|
|
7510
|
-
const hash =
|
|
7510
|
+
const hash = _chunkEI5ILLQ3cjs.keccak_256.call(void 0, uncompressedPubkey.slice(1));
|
|
7511
7511
|
const addressBytes = hash.slice(12);
|
|
7512
7512
|
const addressHex2 = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, addressBytes);
|
|
7513
7513
|
return toChecksumAddress(addressHex2);
|
|
@@ -7538,11 +7538,11 @@ ${body.length}`
|
|
|
7538
7538
|
const whole = new Uint8Array(prefix.length + body.length);
|
|
7539
7539
|
whole.set(prefix, 0);
|
|
7540
7540
|
whole.set(body, prefix.length);
|
|
7541
|
-
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0,
|
|
7541
|
+
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkEI5ILLQ3cjs.keccak_256.call(void 0, whole))}`;
|
|
7542
7542
|
}
|
|
7543
7543
|
function toChecksumAddress(address2) {
|
|
7544
7544
|
const clean2 = address2.replace(/^0x/, "").toLowerCase();
|
|
7545
|
-
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)));
|
|
7546
7546
|
let checksummed = "0x";
|
|
7547
7547
|
for (let i = 0; i < 40; i++) {
|
|
7548
7548
|
checksummed += parseInt(hash[i], 16) >= 8 ? clean2[i].toUpperCase() : clean2[i];
|
|
@@ -7551,7 +7551,7 @@ function toChecksumAddress(address2) {
|
|
|
7551
7551
|
}
|
|
7552
7552
|
var MAX_UINT256 = (1n << 256n) - 1n;
|
|
7553
7553
|
function signEip2612Permit(params) {
|
|
7554
|
-
const spender = _nullishCoalesce(params.spender, () => (
|
|
7554
|
+
const spender = _nullishCoalesce(params.spender, () => ( _chunkEI5ILLQ3cjs.PERMIT2_ADDRESS));
|
|
7555
7555
|
const digestParams = {
|
|
7556
7556
|
domainSeparator: params.domainSeparator,
|
|
7557
7557
|
owner: params.owner,
|
|
@@ -7560,7 +7560,7 @@ function signEip2612Permit(params) {
|
|
|
7560
7560
|
nonce: params.nonce,
|
|
7561
7561
|
deadline: params.deadline
|
|
7562
7562
|
};
|
|
7563
|
-
const digest =
|
|
7563
|
+
const digest = _chunkEI5ILLQ3cjs.buildEip2612PermitDigest.call(void 0, digestParams);
|
|
7564
7564
|
const sig = signEvmDigest(params.secretKey, digest);
|
|
7565
7565
|
return {
|
|
7566
7566
|
v: sig.v,
|
|
@@ -7585,14 +7585,14 @@ var USDC_DOMAIN_FIELDS = {
|
|
|
7585
7585
|
}
|
|
7586
7586
|
};
|
|
7587
7587
|
function keccak256Hex2(input) {
|
|
7588
|
-
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)))}`;
|
|
7589
7589
|
}
|
|
7590
7590
|
function keccak256HexBytes(hexInput) {
|
|
7591
7591
|
const bytes = new Uint8Array(hexInput.length / 2);
|
|
7592
7592
|
for (let i = 0; i < bytes.length; i++) {
|
|
7593
7593
|
bytes[i] = parseInt(hexInput.slice(i * 2, i * 2 + 2), 16);
|
|
7594
7594
|
}
|
|
7595
|
-
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0,
|
|
7595
|
+
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkEI5ILLQ3cjs.keccak_256.call(void 0, bytes))}`;
|
|
7596
7596
|
}
|
|
7597
7597
|
function strip(hex2) {
|
|
7598
7598
|
return hex2.replace(/^0x/, "").toLowerCase();
|
|
@@ -7604,7 +7604,7 @@ function addressHex(address2) {
|
|
|
7604
7604
|
return address2.replace(/^0x/, "").toLowerCase().padStart(64, "0");
|
|
7605
7605
|
}
|
|
7606
7606
|
function signPermit2Witness(params) {
|
|
7607
|
-
const digest =
|
|
7607
|
+
const digest = _chunkEI5ILLQ3cjs.buildPermit2FundingDigest.call(void 0, params.funding);
|
|
7608
7608
|
const sig = signEvmDigest(params.secretKey, digest);
|
|
7609
7609
|
const r = sig.r.replace(/^0x/, "");
|
|
7610
7610
|
const s = sig.s.replace(/^0x/, "");
|
|
@@ -7656,7 +7656,7 @@ async function recoverCctpInbound(context, params) {
|
|
|
7656
7656
|
onProgress,
|
|
7657
7657
|
signal
|
|
7658
7658
|
} = params;
|
|
7659
|
-
const { client: aaClient, accountAddress } = await
|
|
7659
|
+
const { client: aaClient, accountAddress } = await _chunkEI5ILLQ3cjs.createSwapSmartAccountClient.call(void 0, { signer, aa: context.aa, chain });
|
|
7660
7660
|
const publicClient = _chunkK6TGBXTTcjs.createPublicClient.call(void 0, {
|
|
7661
7661
|
chain,
|
|
7662
7662
|
transport: _chunkK6TGBXTTcjs.http.call(void 0, _nullishCoalesce(context.aa.rpcUrl, () => ( context.aa.bundlerUrl)))
|
|
@@ -7667,7 +7667,7 @@ async function recoverCctpInbound(context, params) {
|
|
|
7667
7667
|
const usdcAddress = _chunkTKFOVRJRcjs.USDC_ADDRESSES.Arbitrum;
|
|
7668
7668
|
if (!cctpMessage || !cctpAttestation) {
|
|
7669
7669
|
_optionalChain([onProgress, 'optionalCall', _37 => _37({ phase: "attestation" })]);
|
|
7670
|
-
const fetched = await
|
|
7670
|
+
const fetched = await _chunkEI5ILLQ3cjs.fetchAttestation.call(void 0, {
|
|
7671
7671
|
sourceChain,
|
|
7672
7672
|
txHash: burnTxHash,
|
|
7673
7673
|
irisApiUrl,
|
|
@@ -8664,18 +8664,18 @@ _chunk5JR6AJ3Ycjs.init_sha2.call(void 0, );
|
|
|
8664
8664
|
_chunk5JR6AJ3Ycjs.init_utils.call(void 0, );
|
|
8665
8665
|
_chunkBEW62OUTcjs.init_bip32.call(void 0, );
|
|
8666
8666
|
function pbkdf2Init(hash, _password, _salt, _opts) {
|
|
8667
|
-
|
|
8668
|
-
const opts =
|
|
8667
|
+
_chunkLZQZYSOZcjs.ahash.call(void 0, hash);
|
|
8668
|
+
const opts = _chunkLZQZYSOZcjs.checkOpts.call(void 0, { dkLen: 32, asyncTick: 10 }, _opts);
|
|
8669
8669
|
const { c, dkLen, asyncTick } = opts;
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8670
|
+
_chunkLZQZYSOZcjs.anumber.call(void 0, c, "c");
|
|
8671
|
+
_chunkLZQZYSOZcjs.anumber.call(void 0, dkLen, "dkLen");
|
|
8672
|
+
_chunkLZQZYSOZcjs.anumber.call(void 0, asyncTick, "asyncTick");
|
|
8673
8673
|
if (c < 1)
|
|
8674
8674
|
throw new Error("iterations (c) must be >= 1");
|
|
8675
|
-
const password =
|
|
8676
|
-
const salt =
|
|
8675
|
+
const password = _chunkLZQZYSOZcjs.kdfInputToBytes.call(void 0, _password, "password");
|
|
8676
|
+
const salt = _chunkLZQZYSOZcjs.kdfInputToBytes.call(void 0, _salt, "salt");
|
|
8677
8677
|
const DK = new Uint8Array(dkLen);
|
|
8678
|
-
const PRF =
|
|
8678
|
+
const PRF = _chunkLZQZYSOZcjs.hmac.create(hash, password);
|
|
8679
8679
|
const PRFSalt = PRF._cloneInto().update(salt);
|
|
8680
8680
|
return { c, dkLen, asyncTick, DK, PRF, PRFSalt };
|
|
8681
8681
|
}
|
|
@@ -8684,14 +8684,14 @@ function pbkdf2Output(PRF, PRFSalt, DK, prfW, u) {
|
|
|
8684
8684
|
PRFSalt.destroy();
|
|
8685
8685
|
if (prfW)
|
|
8686
8686
|
prfW.destroy();
|
|
8687
|
-
|
|
8687
|
+
_chunkLZQZYSOZcjs.clean.call(void 0, u);
|
|
8688
8688
|
return DK;
|
|
8689
8689
|
}
|
|
8690
8690
|
function pbkdf2(hash, password, salt, opts) {
|
|
8691
8691
|
const { c, dkLen, DK, PRF, PRFSalt } = pbkdf2Init(hash, password, salt, opts);
|
|
8692
8692
|
let prfW;
|
|
8693
8693
|
const arr = new Uint8Array(4);
|
|
8694
|
-
const view =
|
|
8694
|
+
const view = _chunkLZQZYSOZcjs.createView.call(void 0, arr);
|
|
8695
8695
|
const u = new Uint8Array(PRF.outputLen);
|
|
8696
8696
|
for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
|
|
8697
8697
|
const Ti = DK.subarray(pos, pos + PRF.outputLen);
|
|
@@ -8720,19 +8720,19 @@ function normalize(str) {
|
|
|
8720
8720
|
return { nfkd: norm, words };
|
|
8721
8721
|
}
|
|
8722
8722
|
function aentropy(ent) {
|
|
8723
|
-
|
|
8723
|
+
_chunkLZQZYSOZcjs.abytes.call(void 0, ent);
|
|
8724
8724
|
if (![16, 20, 24, 28, 32].includes(ent.length))
|
|
8725
8725
|
throw new Error("invalid entropy length");
|
|
8726
8726
|
}
|
|
8727
8727
|
function generateMnemonic(wordlist2, strength = 128) {
|
|
8728
|
-
|
|
8728
|
+
_chunkLZQZYSOZcjs.anumber.call(void 0, strength);
|
|
8729
8729
|
if (strength % 32 !== 0 || strength > 256)
|
|
8730
8730
|
throw new TypeError("Invalid entropy");
|
|
8731
|
-
return entropyToMnemonic(
|
|
8731
|
+
return entropyToMnemonic(_chunkLZQZYSOZcjs.randomBytes.call(void 0, strength / 8), wordlist2);
|
|
8732
8732
|
}
|
|
8733
8733
|
var calcChecksum = (entropy) => {
|
|
8734
8734
|
const bitsLeft = 8 - entropy.length / 4;
|
|
8735
|
-
return new Uint8Array([
|
|
8735
|
+
return new Uint8Array([_chunkLZQZYSOZcjs.sha2562.call(void 0, entropy)[0] >> bitsLeft << bitsLeft]);
|
|
8736
8736
|
};
|
|
8737
8737
|
function getCoder(wordlist2) {
|
|
8738
8738
|
if (!Array.isArray(wordlist2) || wordlist2.length !== 2048 || typeof wordlist2[0] !== "string")
|
|
@@ -8741,7 +8741,7 @@ function getCoder(wordlist2) {
|
|
|
8741
8741
|
if (typeof i !== "string")
|
|
8742
8742
|
throw new Error("wordlist: non-string element: " + i);
|
|
8743
8743
|
});
|
|
8744
|
-
return
|
|
8744
|
+
return _chunkLZQZYSOZcjs.utils.chain(_chunkLZQZYSOZcjs.utils.checksum(1, calcChecksum), _chunkLZQZYSOZcjs.utils.radix2(11, true), _chunkLZQZYSOZcjs.utils.alphabet(wordlist2));
|
|
8745
8745
|
}
|
|
8746
8746
|
function mnemonicToEntropy(mnemonic, wordlist2) {
|
|
8747
8747
|
const { words } = normalize(mnemonic);
|
|
@@ -8764,7 +8764,7 @@ function validateMnemonic(mnemonic, wordlist2) {
|
|
|
8764
8764
|
}
|
|
8765
8765
|
var psalt = (passphrase) => nfkd("mnemonic" + passphrase);
|
|
8766
8766
|
function mnemonicToSeedSync(mnemonic, passphrase = "") {
|
|
8767
|
-
return pbkdf2(
|
|
8767
|
+
return pbkdf2(_chunkLZQZYSOZcjs.sha512, normalize(mnemonic).nfkd, psalt(passphrase), { c: 2048, dkLen: 64 });
|
|
8768
8768
|
}
|
|
8769
8769
|
var wordlist = `abandon
|
|
8770
8770
|
ability
|
|
@@ -11082,12 +11082,12 @@ function parseXOnlyPubKey(pubKeyHex) {
|
|
|
11082
11082
|
);
|
|
11083
11083
|
}
|
|
11084
11084
|
function refundableVhtlc(params) {
|
|
11085
|
-
if (params.scriptVersion !== void 0 && params.scriptVersion !==
|
|
11085
|
+
if (params.scriptVersion !== void 0 && params.scriptVersion !== _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
|
|
11086
11086
|
throw new Error(
|
|
11087
11087
|
`Unsupported Arkade HTLC script version: ${params.scriptVersion}`
|
|
11088
11088
|
);
|
|
11089
11089
|
}
|
|
11090
|
-
return new (0,
|
|
11090
|
+
return new (0, _chunkLZQZYSOZcjs.StrictVhtlcScript)({
|
|
11091
11091
|
sender: parseXOnlyPubKey(params.senderPubKey),
|
|
11092
11092
|
receiver: parseXOnlyPubKey(params.receiverPubKey),
|
|
11093
11093
|
server: parseXOnlyPubKey(params.serverPubKey),
|
|
@@ -11138,8 +11138,8 @@ async function buildArkadeRefund(params) {
|
|
|
11138
11138
|
`Invalid hash lock length: expected 20 or 32, got ${hashLockBytes.length}`
|
|
11139
11139
|
);
|
|
11140
11140
|
}
|
|
11141
|
-
const networkName =
|
|
11142
|
-
const serverUrl =
|
|
11141
|
+
const networkName = _chunkLZQZYSOZcjs.getNetworkName.call(void 0, network);
|
|
11142
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
|
|
11143
11143
|
const arkProvider = new (0, _chunkBEW62OUTcjs.RestOperatorProvider)(serverUrl);
|
|
11144
11144
|
const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
|
|
11145
11145
|
const serverInfo = await arkProvider.getInfo();
|
|
@@ -11154,7 +11154,7 @@ async function buildArkadeRefund(params) {
|
|
|
11154
11154
|
unilateralRefundWithoutReceiverDelay,
|
|
11155
11155
|
scriptVersion: arkadeHtlcScriptVersion
|
|
11156
11156
|
});
|
|
11157
|
-
const hrp =
|
|
11157
|
+
const hrp = _chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, networkName);
|
|
11158
11158
|
const computedAddress = vhtlc.address(hrp, serverPkBytes);
|
|
11159
11159
|
const computedAddressStr = computedAddress.encode();
|
|
11160
11160
|
if (computedAddressStr !== vhtlcAddress) {
|
|
@@ -11239,6 +11239,65 @@ _chunkBEW62OUTcjs.init_secp256k12.call(void 0, );
|
|
|
11239
11239
|
_chunkBEW62OUTcjs.init_legacy2.call(void 0, );
|
|
11240
11240
|
_chunk5JR6AJ3Ycjs.init_sha2.call(void 0, );
|
|
11241
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
|
+
}
|
|
11242
11301
|
var NUMS_POINT = _chunkRYZSWESUcjs.hex.decode(
|
|
11243
11302
|
"0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"
|
|
11244
11303
|
);
|
|
@@ -11251,10 +11310,10 @@ var REGTEST_NETWORK = {
|
|
|
11251
11310
|
function getNetwork(network) {
|
|
11252
11311
|
switch (network) {
|
|
11253
11312
|
case "mainnet":
|
|
11254
|
-
return
|
|
11313
|
+
return _chunkLZQZYSOZcjs.NETWORK;
|
|
11255
11314
|
case "testnet":
|
|
11256
11315
|
case "signet":
|
|
11257
|
-
return
|
|
11316
|
+
return _chunkLZQZYSOZcjs.TEST_NETWORK;
|
|
11258
11317
|
case "regtest":
|
|
11259
11318
|
return REGTEST_NETWORK;
|
|
11260
11319
|
default:
|
|
@@ -11277,10 +11336,10 @@ function buildHashlockScript(hashLock, serverPubKey, btcHtlcScriptVersion = 1) {
|
|
|
11277
11336
|
hashLock,
|
|
11278
11337
|
"EQUAL"
|
|
11279
11338
|
];
|
|
11280
|
-
return
|
|
11339
|
+
return _chunkLZQZYSOZcjs.Script.encode(script);
|
|
11281
11340
|
}
|
|
11282
11341
|
function buildTimelockScript(userPubKey, refundLocktime) {
|
|
11283
|
-
return
|
|
11342
|
+
return _chunkLZQZYSOZcjs.Script.encode([
|
|
11284
11343
|
refundLocktime,
|
|
11285
11344
|
"CHECKLOCKTIMEVERIFY",
|
|
11286
11345
|
"DROP",
|
|
@@ -11298,7 +11357,7 @@ function buildHtlcTaprootInfo(hashLock, serverPubKey, userPubKey, refundLocktime
|
|
|
11298
11357
|
btcHtlcScriptVersion
|
|
11299
11358
|
);
|
|
11300
11359
|
const timelockScript = buildTimelockScript(userPubKey, refundLocktime);
|
|
11301
|
-
const p2tr2 =
|
|
11360
|
+
const p2tr2 = _chunkLZQZYSOZcjs.p2tr.call(void 0,
|
|
11302
11361
|
NUMS_POINT.slice(1),
|
|
11303
11362
|
// Remove the 02/03 prefix for x-only
|
|
11304
11363
|
[{ script: hashlockScript }, { script: timelockScript }],
|
|
@@ -11368,7 +11427,14 @@ function buildOnchainClaimTransaction(params) {
|
|
|
11368
11427
|
refundLocktime,
|
|
11369
11428
|
params.btcHtlcScriptVersion
|
|
11370
11429
|
);
|
|
11371
|
-
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
|
+
);
|
|
11372
11438
|
if (fee >= htlcAmount) {
|
|
11373
11439
|
throw new Error(
|
|
11374
11440
|
`Fee (${fee} sats) exceeds HTLC amount (${htlcAmount} sats)`
|
|
@@ -11381,7 +11447,7 @@ function buildOnchainClaimTransaction(params) {
|
|
|
11381
11447
|
throw new Error("Failed to build tapLeafScript for hashlock");
|
|
11382
11448
|
}
|
|
11383
11449
|
const hashlockLeaf = tapLeafScript[0];
|
|
11384
|
-
const tx = new (0,
|
|
11450
|
+
const tx = new (0, _chunkLZQZYSOZcjs.Transaction2)({
|
|
11385
11451
|
allowUnknownOutputs: true,
|
|
11386
11452
|
allowUnknownInputs: true
|
|
11387
11453
|
});
|
|
@@ -11393,16 +11459,25 @@ function buildOnchainClaimTransaction(params) {
|
|
|
11393
11459
|
amount: htlcAmount
|
|
11394
11460
|
},
|
|
11395
11461
|
tapLeafScript: [hashlockLeaf],
|
|
11396
|
-
sequence: 4294967295
|
|
11462
|
+
sequence: validated ? 4294967293 : 4294967295
|
|
11397
11463
|
});
|
|
11398
|
-
|
|
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
|
+
}
|
|
11399
11474
|
const [controlBlockInfo, leafScriptWithVersion] = hashlockLeaf;
|
|
11400
11475
|
const leafScript = leafScriptWithVersion.slice(0, -1);
|
|
11401
11476
|
const leafVersion = leafScriptWithVersion[leafScriptWithVersion.length - 1];
|
|
11402
11477
|
const sighash = tx.preimageWitnessV1(
|
|
11403
11478
|
0,
|
|
11404
11479
|
[p2tr2.script],
|
|
11405
|
-
|
|
11480
|
+
_chunkLZQZYSOZcjs.SigHash.DEFAULT,
|
|
11406
11481
|
[htlcAmount],
|
|
11407
11482
|
void 0,
|
|
11408
11483
|
leafScript,
|
|
@@ -11421,13 +11496,34 @@ function buildOnchainClaimTransaction(params) {
|
|
|
11421
11496
|
tx.updateInput(0, {
|
|
11422
11497
|
finalScriptWitness: [preimageBytes, sig, leafScript, encodedControlBlock]
|
|
11423
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
|
+
}
|
|
11424
11519
|
const txHex = _chunkRYZSWESUcjs.hex.encode(tx.extract());
|
|
11425
11520
|
const txId = tx.id;
|
|
11426
|
-
const htlcAddress2 =
|
|
11521
|
+
const htlcAddress2 = _chunkLZQZYSOZcjs.Address.call(void 0, networkConfig).encode({
|
|
11427
11522
|
type: "tr",
|
|
11428
11523
|
pubkey: p2tr2.tweakedPubkey
|
|
11429
11524
|
});
|
|
11430
11525
|
return {
|
|
11526
|
+
vsize: tx.vsize,
|
|
11431
11527
|
txHex,
|
|
11432
11528
|
txId,
|
|
11433
11529
|
claimAmount,
|
|
@@ -11493,7 +11589,7 @@ function buildOnchainRefundTransaction(params) {
|
|
|
11493
11589
|
throw new Error("Failed to build tapLeafScript for timelock");
|
|
11494
11590
|
}
|
|
11495
11591
|
const timelockLeaf = tapLeafScript[1];
|
|
11496
|
-
const tx = new (0,
|
|
11592
|
+
const tx = new (0, _chunkLZQZYSOZcjs.Transaction2)({
|
|
11497
11593
|
allowUnknownOutputs: true,
|
|
11498
11594
|
allowUnknownInputs: true,
|
|
11499
11595
|
lockTime: refundLocktime
|
|
@@ -11514,7 +11610,7 @@ function buildOnchainRefundTransaction(params) {
|
|
|
11514
11610
|
tx.finalize();
|
|
11515
11611
|
const txHex = _chunkRYZSWESUcjs.hex.encode(tx.extract());
|
|
11516
11612
|
const txId = tx.id;
|
|
11517
|
-
const htlcAddress2 =
|
|
11613
|
+
const htlcAddress2 = _chunkLZQZYSOZcjs.Address.call(void 0, networkConfig).encode({
|
|
11518
11614
|
type: "tr",
|
|
11519
11615
|
pubkey: p2tr2.tweakedPubkey
|
|
11520
11616
|
});
|
|
@@ -11547,7 +11643,7 @@ function htlcAddress(hashLock, serverPubKey, userPubKey, refundLocktime, network
|
|
|
11547
11643
|
refundLocktime,
|
|
11548
11644
|
btcHtlcScriptVersion
|
|
11549
11645
|
);
|
|
11550
|
-
return
|
|
11646
|
+
return _chunkLZQZYSOZcjs.Address.call(void 0, getNetwork(network)).encode({
|
|
11551
11647
|
type: "tr",
|
|
11552
11648
|
pubkey: p2tr2.tweakedPubkey
|
|
11553
11649
|
});
|
|
@@ -11664,12 +11760,12 @@ function checkedLightningPaymentHash(options, data) {
|
|
|
11664
11760
|
}
|
|
11665
11761
|
function assertFundedVhtlc(response, addressField, address2, hash160, refundPublicKey, lockDescription) {
|
|
11666
11762
|
const swapId = response.id;
|
|
11667
|
-
if (response.arkade_htlc_script_version !==
|
|
11763
|
+
if (response.arkade_htlc_script_version !== _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
|
|
11668
11764
|
throw new SwapVerificationError(
|
|
11669
11765
|
`Swap ${swapId} uses Arkade HTLC script version ${response.arkade_htlc_script_version}, which this client cannot refund; do not fund it`,
|
|
11670
11766
|
{
|
|
11671
11767
|
field: "arkade_htlc_script_version",
|
|
11672
|
-
expected: String(
|
|
11768
|
+
expected: String(_chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT),
|
|
11673
11769
|
received: String(response.arkade_htlc_script_version),
|
|
11674
11770
|
swapId
|
|
11675
11771
|
}
|
|
@@ -11686,7 +11782,7 @@ function assertFundedVhtlc(response, addressField, address2, hash160, refundPubl
|
|
|
11686
11782
|
unilateralRefundDelay: response.unilateral_refund_delay,
|
|
11687
11783
|
unilateralRefundWithoutReceiverDelay: response.unilateral_refund_without_receiver_delay
|
|
11688
11784
|
});
|
|
11689
|
-
const expected = vhtlc.address(
|
|
11785
|
+
const expected = vhtlc.address(_chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, _chunkLZQZYSOZcjs.getNetworkName.call(void 0, response.network)), server).encode();
|
|
11690
11786
|
if (expected !== address2) {
|
|
11691
11787
|
throw new SwapVerificationError(
|
|
11692
11788
|
`Swap ${swapId}'s VHTLC address ${address2} does not lock to ${lockDescription} and this client's refund key (expected ${expected}); do not fund it`,
|
|
@@ -11730,12 +11826,12 @@ function assertHashLock(swapId, field, hashLock, accepted) {
|
|
|
11730
11826
|
}
|
|
11731
11827
|
function assertFundedHtlc(response, hashField, hashLock, serverPk, hash160, refundPublicKey, lockDescription) {
|
|
11732
11828
|
const swapId = response.id;
|
|
11733
|
-
if (response.btc_htlc_script_version !==
|
|
11829
|
+
if (response.btc_htlc_script_version !== _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT) {
|
|
11734
11830
|
throw new SwapVerificationError(
|
|
11735
11831
|
`Swap ${swapId} uses Bitcoin HTLC script version ${response.btc_htlc_script_version}, which this client cannot refund; do not fund it`,
|
|
11736
11832
|
{
|
|
11737
11833
|
field: "btc_htlc_script_version",
|
|
11738
|
-
expected: String(
|
|
11834
|
+
expected: String(_chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT),
|
|
11739
11835
|
received: String(response.btc_htlc_script_version),
|
|
11740
11836
|
swapId
|
|
11741
11837
|
}
|
|
@@ -11748,7 +11844,7 @@ function assertFundedHtlc(response, hashField, hashLock, serverPk, hash160, refu
|
|
|
11748
11844
|
{ field: hashField, expected: hash160, received: serverHash160, swapId }
|
|
11749
11845
|
);
|
|
11750
11846
|
}
|
|
11751
|
-
const name =
|
|
11847
|
+
const name = _chunkLZQZYSOZcjs.getNetworkName.call(void 0, response.network);
|
|
11752
11848
|
const network = name === "bitcoin" ? "mainnet" : name === "mutinynet" ? "signet" : name;
|
|
11753
11849
|
const binds = verifyHtlcAddress(
|
|
11754
11850
|
response.btc_htlc_address,
|
|
@@ -11939,7 +12035,7 @@ function assertAddressEchoed(response, field, requested) {
|
|
|
11939
12035
|
function invoiceKey(invoice) {
|
|
11940
12036
|
try {
|
|
11941
12037
|
return paymentHashOf(invoice);
|
|
11942
|
-
} catch (
|
|
12038
|
+
} catch (e6) {
|
|
11943
12039
|
return invoice;
|
|
11944
12040
|
}
|
|
11945
12041
|
}
|
|
@@ -11963,7 +12059,7 @@ function withStoredTerms(stored, fresh, refused) {
|
|
|
11963
12059
|
const original = stored.response;
|
|
11964
12060
|
kept.funding = {
|
|
11965
12061
|
...original.funding,
|
|
11966
|
-
payment_id: fresh.direction === "spark_to_evm" ? _nullishCoalesce(_optionalChain([fresh, 'access',
|
|
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
|
|
11967
12063
|
};
|
|
11968
12064
|
kept.source_amount = original.source_amount;
|
|
11969
12065
|
kept.network = original.network;
|
|
@@ -12050,7 +12146,7 @@ function assertSparkFunding(data, ownHash) {
|
|
|
12050
12146
|
data.funding.address,
|
|
12051
12147
|
1023
|
|
12052
12148
|
).prefix;
|
|
12053
|
-
} catch (
|
|
12149
|
+
} catch (e7) {
|
|
12054
12150
|
fail(
|
|
12055
12151
|
"funding.address",
|
|
12056
12152
|
"valid Spark bech32m address",
|
|
@@ -12118,7 +12214,7 @@ async function createArkadeToEvmSwapGeneric(options, ctx, claimingAddressOverrid
|
|
|
12118
12214
|
const claimingAddress = _nullishCoalesce(claimingAddressOverride, () => ( deriveEvmAddress(swapParams.secretKey)));
|
|
12119
12215
|
const body = {
|
|
12120
12216
|
hash_lock: hashLock,
|
|
12121
|
-
arkade_htlc_script_version:
|
|
12217
|
+
arkade_htlc_script_version: _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
|
|
12122
12218
|
refund_pk: refundPk,
|
|
12123
12219
|
user_id: userId,
|
|
12124
12220
|
claiming_address: claimingAddress,
|
|
@@ -12126,14 +12222,14 @@ async function createArkadeToEvmSwapGeneric(options, ctx, claimingAddressOverrid
|
|
|
12126
12222
|
token_address: options.tokenAddress,
|
|
12127
12223
|
evm_chain_id: options.evmChainId,
|
|
12128
12224
|
amount_in: options.sourceAmount ? Number(options.sourceAmount) : void 0,
|
|
12129
|
-
amount_out: _optionalChain([options, 'access',
|
|
12225
|
+
amount_out: _optionalChain([options, 'access', _66 => _66.targetAmount, 'optionalAccess', _67 => _67.toString, 'call', _68 => _68()]),
|
|
12130
12226
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12131
12227
|
extra_fees: options.extraFees,
|
|
12132
12228
|
promo_code: options.promoCode,
|
|
12133
12229
|
gasless: _nullishCoalesce(options.gasless, () => ( true)),
|
|
12134
|
-
bridge_target_chain: _optionalChain([options, 'access',
|
|
12135
|
-
bridge_target_token_address: _optionalChain([options, 'access',
|
|
12136
|
-
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])
|
|
12137
12233
|
};
|
|
12138
12234
|
const { data, error } = await ctx.apiClient.POST("/swap/arkade/evm", {
|
|
12139
12235
|
body
|
|
@@ -12156,8 +12252,8 @@ async function createArkadeToEvmSwapGeneric(options, ctx, claimingAddressOverrid
|
|
|
12156
12252
|
},
|
|
12157
12253
|
options.targetAddress,
|
|
12158
12254
|
{
|
|
12159
|
-
recipient: _optionalChain([options, 'access',
|
|
12160
|
-
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])
|
|
12161
12257
|
}
|
|
12162
12258
|
);
|
|
12163
12259
|
return { response: data, swapParams };
|
|
@@ -12193,7 +12289,7 @@ async function createArkadeToLightningSwap(options, ctx) {
|
|
|
12193
12289
|
target_amount_sats: options.targetAmountSats,
|
|
12194
12290
|
refund_pk: refundPk,
|
|
12195
12291
|
user_id: userId,
|
|
12196
|
-
arkade_htlc_script_version:
|
|
12292
|
+
arkade_htlc_script_version: _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
|
|
12197
12293
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12198
12294
|
extra_fees: options.extraFees,
|
|
12199
12295
|
promo_code: options.promoCode
|
|
@@ -12225,7 +12321,7 @@ async function createBitcoinToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12225
12321
|
const claimingAddress = _nullishCoalesce(claimingAddressOverride, () => ( deriveEvmAddress(swapParams.secretKey)));
|
|
12226
12322
|
const body = {
|
|
12227
12323
|
hash_lock: hashLock,
|
|
12228
|
-
btc_htlc_script_version:
|
|
12324
|
+
btc_htlc_script_version: _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
|
|
12229
12325
|
refund_pk: refundPk,
|
|
12230
12326
|
user_id: userId,
|
|
12231
12327
|
claiming_address: claimingAddress,
|
|
@@ -12233,14 +12329,14 @@ async function createBitcoinToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12233
12329
|
token_address: options.tokenAddress,
|
|
12234
12330
|
evm_chain_id: options.evmChainId,
|
|
12235
12331
|
amount_in: options.sourceAmount,
|
|
12236
|
-
amount_out: _optionalChain([options, 'access',
|
|
12332
|
+
amount_out: _optionalChain([options, 'access', _79 => _79.targetAmount, 'optionalAccess', _80 => _80.toString, 'call', _81 => _81()]),
|
|
12237
12333
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12238
12334
|
extra_fees: options.extraFees,
|
|
12239
12335
|
promo_code: options.promoCode,
|
|
12240
12336
|
gasless: _nullishCoalesce(options.gasless, () => ( true)),
|
|
12241
|
-
bridge_target_chain: _optionalChain([options, 'access',
|
|
12242
|
-
bridge_target_token_address: _optionalChain([options, 'access',
|
|
12243
|
-
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])
|
|
12244
12340
|
};
|
|
12245
12341
|
const { data, error } = await ctx.apiClient.POST("/swap/bitcoin/evm", {
|
|
12246
12342
|
body
|
|
@@ -12263,8 +12359,8 @@ async function createBitcoinToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12263
12359
|
},
|
|
12264
12360
|
options.targetAddress,
|
|
12265
12361
|
{
|
|
12266
|
-
recipient: _optionalChain([options, 'access',
|
|
12267
|
-
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])
|
|
12268
12364
|
}
|
|
12269
12365
|
);
|
|
12270
12366
|
return { response: data, swapParams };
|
|
@@ -12289,8 +12385,8 @@ async function createBitcoinToArkadeSwap(options, ctx) {
|
|
|
12289
12385
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12290
12386
|
extra_fees: options.extraFees,
|
|
12291
12387
|
promo_code: options.promoCode,
|
|
12292
|
-
btc_htlc_script_version:
|
|
12293
|
-
arkade_htlc_script_version:
|
|
12388
|
+
btc_htlc_script_version: _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
|
|
12389
|
+
arkade_htlc_script_version: _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT
|
|
12294
12390
|
};
|
|
12295
12391
|
const { data, error } = await ctx.apiClient.POST("/swap/bitcoin/arkade", {
|
|
12296
12392
|
body
|
|
@@ -12344,7 +12440,7 @@ async function createBitcoinToLightningSwap(options, ctx) {
|
|
|
12344
12440
|
target_amount_sats: options.targetAmountSats,
|
|
12345
12441
|
refund_pk: refundPk,
|
|
12346
12442
|
user_id: userId,
|
|
12347
|
-
btc_htlc_script_version:
|
|
12443
|
+
btc_htlc_script_version: _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
|
|
12348
12444
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12349
12445
|
extra_fees: options.extraFees,
|
|
12350
12446
|
promo_code: options.promoCode
|
|
@@ -12367,11 +12463,13 @@ async function createBitcoinToLightningSwap(options, ctx) {
|
|
|
12367
12463
|
});
|
|
12368
12464
|
return { response: data, swapParams };
|
|
12369
12465
|
}
|
|
12370
|
-
function fundingTermsOf(data) {
|
|
12371
|
-
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])) {
|
|
12372
12469
|
return void 0;
|
|
12373
12470
|
}
|
|
12374
12471
|
return {
|
|
12472
|
+
depositor: _optionalChain([depositor, 'optionalAccess', _94 => _94.toLowerCase, 'call', _95 => _95()]),
|
|
12375
12473
|
chainId: data.evm_chain_id,
|
|
12376
12474
|
coordinator: data.evm_coordinator_address.toLowerCase(),
|
|
12377
12475
|
htlcAddress: data.evm_htlc_address.toLowerCase(),
|
|
@@ -12381,7 +12479,7 @@ function fundingTermsOf(data) {
|
|
|
12381
12479
|
timelock: data.evm_refund_locktime,
|
|
12382
12480
|
sourceToken: data.source_token.token_id.toLowerCase(),
|
|
12383
12481
|
sourceAmount: String(data.source_amount),
|
|
12384
|
-
lockToken: _optionalChain([data, 'access',
|
|
12482
|
+
lockToken: _optionalChain([data, 'access', _96 => _96.evm_htlc_token, 'optionalAccess', _97 => _97.toLowerCase, 'call', _98 => _98()])
|
|
12385
12483
|
};
|
|
12386
12484
|
}
|
|
12387
12485
|
async function createEvmToArkadeSwapGeneric(options, ctx) {
|
|
@@ -12391,7 +12489,7 @@ async function createEvmToArkadeSwapGeneric(options, ctx) {
|
|
|
12391
12489
|
const hashLock = `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.preimageHash)}`;
|
|
12392
12490
|
const receiverPk = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.publicKey);
|
|
12393
12491
|
const userId = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.userId);
|
|
12394
|
-
const userAddress = options.gasless ?
|
|
12492
|
+
const userAddress = options.gasless ? deriveEvmAddress(swapParams.secretKey) : options.userAddress;
|
|
12395
12493
|
const { data, error } = await ctx.apiClient.POST("/swap/evm/arkade", {
|
|
12396
12494
|
body: {
|
|
12397
12495
|
hash_lock: hashLock,
|
|
@@ -12407,9 +12505,9 @@ async function createEvmToArkadeSwapGeneric(options, ctx) {
|
|
|
12407
12505
|
extra_fees: options.extraFees,
|
|
12408
12506
|
promo_code: options.promoCode,
|
|
12409
12507
|
gasless: _nullishCoalesce(options.gasless, () => ( false)),
|
|
12410
|
-
arkade_htlc_script_version:
|
|
12411
|
-
bridge_source_chain: _optionalChain([options, 'access',
|
|
12412
|
-
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])
|
|
12413
12511
|
}
|
|
12414
12512
|
});
|
|
12415
12513
|
if (error) {
|
|
@@ -12428,22 +12526,88 @@ async function createEvmToArkadeSwapGeneric(options, ctx) {
|
|
|
12428
12526
|
},
|
|
12429
12527
|
options.targetAddress,
|
|
12430
12528
|
void 0,
|
|
12431
|
-
{ evmFundingTerms: fundingTermsOf(data) }
|
|
12529
|
+
{ evmFundingTerms: fundingTermsOf(data, userAddress) }
|
|
12432
12530
|
);
|
|
12433
12531
|
return { response: data, swapParams };
|
|
12434
12532
|
});
|
|
12435
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
|
+
}
|
|
12436
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
|
+
}
|
|
12437
12601
|
return retryOnHashCollision(ctx, async () => {
|
|
12438
12602
|
const swapParams = await ctx.deriveSwapParams();
|
|
12439
12603
|
const hashLock = `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.preimageHash)}`;
|
|
12440
12604
|
const claimPk = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.publicKey);
|
|
12441
12605
|
const userId = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.userId);
|
|
12442
|
-
const userAddress = options.gasless ?
|
|
12606
|
+
const userAddress = options.gasless ? deriveEvmAddress(swapParams.secretKey) : options.userAddress;
|
|
12443
12607
|
const { data, error } = await ctx.apiClient.POST("/swap/evm/bitcoin", {
|
|
12444
12608
|
body: {
|
|
12445
12609
|
hash_lock: hashLock,
|
|
12446
|
-
btc_htlc_script_version:
|
|
12610
|
+
btc_htlc_script_version: _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
|
|
12447
12611
|
claim_pk: claimPk,
|
|
12448
12612
|
user_id: userId,
|
|
12449
12613
|
token_address: options.tokenAddress,
|
|
@@ -12451,13 +12615,14 @@ async function createEvmToBitcoinSwap(options, ctx) {
|
|
|
12451
12615
|
user_address: userAddress,
|
|
12452
12616
|
target_address: options.targetAddress,
|
|
12453
12617
|
amount_in: options.sourceAmount ? options.sourceAmount.toString() : void 0,
|
|
12618
|
+
minimum_payout_sats: payment ? Number(payment.minimumPayoutSats) : void 0,
|
|
12454
12619
|
amount_out: options.targetAmount ? Number(options.targetAmount) : void 0,
|
|
12455
12620
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12456
12621
|
extra_fees: options.extraFees,
|
|
12457
12622
|
promo_code: options.promoCode,
|
|
12458
12623
|
gasless: _nullishCoalesce(options.gasless, () => ( false)),
|
|
12459
|
-
bridge_source_chain: _optionalChain([options, 'access',
|
|
12460
|
-
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])
|
|
12461
12626
|
}
|
|
12462
12627
|
});
|
|
12463
12628
|
if (error) {
|
|
@@ -12476,7 +12641,10 @@ async function createEvmToBitcoinSwap(options, ctx) {
|
|
|
12476
12641
|
},
|
|
12477
12642
|
options.targetAddress,
|
|
12478
12643
|
void 0,
|
|
12479
|
-
{
|
|
12644
|
+
{
|
|
12645
|
+
evmFundingTerms: fundingTermsOf(data, userAddress),
|
|
12646
|
+
bitcoinPayout: _optionalChain([payment, 'optionalAccess', _107 => _107.payout])
|
|
12647
|
+
}
|
|
12480
12648
|
);
|
|
12481
12649
|
return { response: data, swapParams };
|
|
12482
12650
|
});
|
|
@@ -12500,7 +12668,7 @@ async function createEvmToLightningSwap(options, ctx) {
|
|
|
12500
12668
|
}
|
|
12501
12669
|
const swapParams = await ctx.deriveSwapParams();
|
|
12502
12670
|
const userId = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, swapParams.userId);
|
|
12503
|
-
const userAddress = options.gasless ?
|
|
12671
|
+
const userAddress = options.gasless ? deriveEvmAddress(swapParams.secretKey) : options.userAddress;
|
|
12504
12672
|
const { data, error } = await ctx.apiClient.POST("/swap/evm/lightning", {
|
|
12505
12673
|
body: {
|
|
12506
12674
|
lightning_invoice: options.lightningInvoice,
|
|
@@ -12516,8 +12684,8 @@ async function createEvmToLightningSwap(options, ctx) {
|
|
|
12516
12684
|
extra_fees: options.extraFees,
|
|
12517
12685
|
promo_code: options.promoCode,
|
|
12518
12686
|
gasless: _nullishCoalesce(options.gasless, () => ( false)),
|
|
12519
|
-
bridge_source_chain: _optionalChain([options, 'access',
|
|
12520
|
-
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])
|
|
12521
12689
|
}
|
|
12522
12690
|
});
|
|
12523
12691
|
if (error) {
|
|
@@ -12536,7 +12704,10 @@ async function createEvmToLightningSwap(options, ctx) {
|
|
|
12536
12704
|
},
|
|
12537
12705
|
void 0,
|
|
12538
12706
|
void 0,
|
|
12539
|
-
{
|
|
12707
|
+
{
|
|
12708
|
+
lightningPaymentHash,
|
|
12709
|
+
evmFundingTerms: fundingTermsOf(data, userAddress)
|
|
12710
|
+
}
|
|
12540
12711
|
);
|
|
12541
12712
|
return { response: data, swapParams };
|
|
12542
12713
|
}
|
|
@@ -12559,7 +12730,7 @@ async function createLightningToArkadeSwap(options, ctx) {
|
|
|
12559
12730
|
source_amount_sats: options.sourceAmountSats,
|
|
12560
12731
|
target_amount_sats: options.targetAmountSats,
|
|
12561
12732
|
target_arkade_address: options.targetAddress,
|
|
12562
|
-
arkade_htlc_script_version:
|
|
12733
|
+
arkade_htlc_script_version: _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
|
|
12563
12734
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12564
12735
|
extra_fees: options.extraFees,
|
|
12565
12736
|
promo_code: options.promoCode,
|
|
@@ -12602,7 +12773,7 @@ async function createLightningToBitcoinSwap(options, ctx) {
|
|
|
12602
12773
|
source_amount_sats: options.sourceAmountSats,
|
|
12603
12774
|
target_amount_sats: options.targetAmountSats,
|
|
12604
12775
|
target_address: options.targetAddress,
|
|
12605
|
-
btc_htlc_script_version:
|
|
12776
|
+
btc_htlc_script_version: _chunkLZQZYSOZcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
|
|
12606
12777
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12607
12778
|
extra_fees: options.extraFees,
|
|
12608
12779
|
promo_code: options.promoCode,
|
|
@@ -12646,15 +12817,15 @@ async function createLightningToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12646
12817
|
token_address: options.tokenAddress,
|
|
12647
12818
|
evm_chain_id: options.evmChainId,
|
|
12648
12819
|
amount_in: options.sourceAmount,
|
|
12649
|
-
amount_out: _optionalChain([options, 'access',
|
|
12820
|
+
amount_out: _optionalChain([options, 'access', _112 => _112.targetAmount, 'optionalAccess', _113 => _113.toString, 'call', _114 => _114()]),
|
|
12650
12821
|
invoice_description: options.invoiceDescription,
|
|
12651
12822
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12652
12823
|
extra_fees: options.extraFees,
|
|
12653
12824
|
promo_code: options.promoCode,
|
|
12654
12825
|
gasless: _nullishCoalesce(options.gasless, () => ( true)),
|
|
12655
|
-
bridge_target_chain: _optionalChain([options, 'access',
|
|
12656
|
-
bridge_target_token_address: _optionalChain([options, 'access',
|
|
12657
|
-
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])
|
|
12658
12829
|
};
|
|
12659
12830
|
const { data, error } = await ctx.apiClient.POST("/swap/lightning/evm", {
|
|
12660
12831
|
body
|
|
@@ -12677,8 +12848,8 @@ async function createLightningToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12677
12848
|
},
|
|
12678
12849
|
options.targetAddress,
|
|
12679
12850
|
{
|
|
12680
|
-
recipient: _optionalChain([options, 'access',
|
|
12681
|
-
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])
|
|
12682
12853
|
}
|
|
12683
12854
|
);
|
|
12684
12855
|
return { response: data, swapParams };
|
|
@@ -12704,14 +12875,14 @@ async function createSparkToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12704
12875
|
token_address: options.tokenAddress,
|
|
12705
12876
|
evm_chain_id: options.evmChainId,
|
|
12706
12877
|
amount_in: options.sourceAmount,
|
|
12707
|
-
amount_out: _optionalChain([options, 'access',
|
|
12878
|
+
amount_out: _optionalChain([options, 'access', _125 => _125.targetAmount, 'optionalAccess', _126 => _126.toString, 'call', _127 => _127()]),
|
|
12708
12879
|
referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
|
|
12709
12880
|
extra_fees: options.extraFees,
|
|
12710
12881
|
promo_code: options.promoCode,
|
|
12711
12882
|
gasless: _nullishCoalesce(options.gasless, () => ( true)),
|
|
12712
|
-
bridge_target_chain: _optionalChain([options, 'access',
|
|
12713
|
-
bridge_target_token_address: _optionalChain([options, 'access',
|
|
12714
|
-
bridge_recipient_setup: _optionalChain([options, 'access',
|
|
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])
|
|
12715
12886
|
};
|
|
12716
12887
|
const { data, error } = await ctx.apiClient.POST("/swap/spark/evm", {
|
|
12717
12888
|
body
|
|
@@ -12739,13 +12910,21 @@ async function createSparkToEvmSwap(options, ctx, claimingAddressOverride) {
|
|
|
12739
12910
|
},
|
|
12740
12911
|
options.targetAddress,
|
|
12741
12912
|
{
|
|
12742
|
-
recipient: _optionalChain([options, 'access',
|
|
12743
|
-
recipientWallet: _optionalChain([options, 'access',
|
|
12913
|
+
recipient: _optionalChain([options, 'access', _134 => _134.bridgeParams, 'optionalAccess', _135 => _135.recipient]),
|
|
12914
|
+
recipientWallet: _optionalChain([options, 'access', _136 => _136.bridgeParams, 'optionalAccess', _137 => _137.recipientWallet])
|
|
12744
12915
|
}
|
|
12745
12916
|
);
|
|
12746
12917
|
return { response: data, swapParams };
|
|
12747
12918
|
});
|
|
12748
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
|
+
}
|
|
12749
12928
|
_chunk5JR6AJ3Ycjs.init_sha2.call(void 0, );
|
|
12750
12929
|
_chunk5JR6AJ3Ycjs.init_utils.call(void 0, );
|
|
12751
12930
|
var REQUEST_TIMEOUT_MS = 5e3;
|
|
@@ -12764,10 +12943,10 @@ var REGTEST_NETWORK2 = {
|
|
|
12764
12943
|
function toBtcSignerNetwork(network) {
|
|
12765
12944
|
switch (network) {
|
|
12766
12945
|
case "mainnet":
|
|
12767
|
-
return
|
|
12946
|
+
return _chunkLZQZYSOZcjs.NETWORK;
|
|
12768
12947
|
case "testnet":
|
|
12769
12948
|
case "signet":
|
|
12770
|
-
return
|
|
12949
|
+
return _chunkLZQZYSOZcjs.TEST_NETWORK;
|
|
12771
12950
|
case "regtest":
|
|
12772
12951
|
return REGTEST_NETWORK2;
|
|
12773
12952
|
default:
|
|
@@ -12776,9 +12955,9 @@ function toBtcSignerNetwork(network) {
|
|
|
12776
12955
|
}
|
|
12777
12956
|
function addressToScriptHash(address2, network) {
|
|
12778
12957
|
const net = toBtcSignerNetwork(network);
|
|
12779
|
-
const decoded =
|
|
12958
|
+
const decoded = _chunkLZQZYSOZcjs.Address.call(void 0, net).decode(address2);
|
|
12780
12959
|
if (!decoded) throw new Error(`Unrecognised Bitcoin address: ${address2}`);
|
|
12781
|
-
const script =
|
|
12960
|
+
const script = _chunkLZQZYSOZcjs.OutScript.encode(decoded);
|
|
12782
12961
|
return _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunk5JR6AJ3Ycjs.sha256.call(void 0, script).reverse());
|
|
12783
12962
|
}
|
|
12784
12963
|
var ElectrumWsClient = class {
|
|
@@ -12797,7 +12976,7 @@ var ElectrumWsClient = class {
|
|
|
12797
12976
|
#closed = false;
|
|
12798
12977
|
constructor(url, opts) {
|
|
12799
12978
|
this.#url = url;
|
|
12800
|
-
this.#log = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
12979
|
+
this.#log = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _138 => _138.onLog]), () => ( (() => {
|
|
12801
12980
|
})));
|
|
12802
12981
|
}
|
|
12803
12982
|
/**
|
|
@@ -12870,7 +13049,7 @@ var ElectrumWsClient = class {
|
|
|
12870
13049
|
handlers.delete(onChange);
|
|
12871
13050
|
if (handlers.size > 0) return;
|
|
12872
13051
|
this.#scriptHashHandlers.delete(scripthash);
|
|
12873
|
-
if (_optionalChain([this, 'access',
|
|
13052
|
+
if (_optionalChain([this, 'access', _139 => _139.#socket, 'optionalAccess', _140 => _140.readyState]) === WebSocket.OPEN) {
|
|
12874
13053
|
this.request("blockchain.scripthash.unsubscribe", [scripthash]).catch(
|
|
12875
13054
|
() => {
|
|
12876
13055
|
}
|
|
@@ -12890,7 +13069,7 @@ var ElectrumWsClient = class {
|
|
|
12890
13069
|
}
|
|
12891
13070
|
async #ensureConnected() {
|
|
12892
13071
|
if (this.#closed) throw new Error("Electrum client closed");
|
|
12893
|
-
if (_optionalChain([this, 'access',
|
|
13072
|
+
if (_optionalChain([this, 'access', _141 => _141.#socket, 'optionalAccess', _142 => _142.readyState]) === WebSocket.OPEN) return;
|
|
12894
13073
|
this.#connecting ??= this.#connect().finally(() => {
|
|
12895
13074
|
this.#connecting = null;
|
|
12896
13075
|
});
|
|
@@ -12913,7 +13092,7 @@ var ElectrumWsClient = class {
|
|
|
12913
13092
|
);
|
|
12914
13093
|
try {
|
|
12915
13094
|
socket.close();
|
|
12916
|
-
} catch (
|
|
13095
|
+
} catch (e9) {
|
|
12917
13096
|
}
|
|
12918
13097
|
}, CONNECT_TIMEOUT_MS);
|
|
12919
13098
|
socket.addEventListener("open", () => {
|
|
@@ -12963,7 +13142,7 @@ var ElectrumWsClient = class {
|
|
|
12963
13142
|
if (socket && socket.readyState !== WebSocket.CLOSED) {
|
|
12964
13143
|
try {
|
|
12965
13144
|
socket.close();
|
|
12966
|
-
} catch (
|
|
13145
|
+
} catch (e10) {
|
|
12967
13146
|
}
|
|
12968
13147
|
}
|
|
12969
13148
|
for (const [id, pending] of this.#pending) {
|
|
@@ -13003,7 +13182,7 @@ var ElectrumWsClient = class {
|
|
|
13003
13182
|
#startPing() {
|
|
13004
13183
|
this.#stopPing();
|
|
13005
13184
|
this.#pingTimer = setInterval(() => {
|
|
13006
|
-
if (_optionalChain([this, 'access',
|
|
13185
|
+
if (_optionalChain([this, 'access', _143 => _143.#socket, 'optionalAccess', _144 => _144.readyState]) !== WebSocket.OPEN) return;
|
|
13007
13186
|
this.request("server.ping", []).catch(() => {
|
|
13008
13187
|
if (this.#socket && this.#socket.readyState === WebSocket.OPEN) {
|
|
13009
13188
|
this.#teardownSocket(new Error("Electrum keepalive timed out"));
|
|
@@ -13028,7 +13207,7 @@ var ElectrumWsClient = class {
|
|
|
13028
13207
|
let parsed;
|
|
13029
13208
|
try {
|
|
13030
13209
|
parsed = JSON.parse(trimmed);
|
|
13031
|
-
} catch (
|
|
13210
|
+
} catch (e11) {
|
|
13032
13211
|
continue;
|
|
13033
13212
|
}
|
|
13034
13213
|
if (parsed.id !== void 0 && parsed.id !== null) {
|
|
@@ -13086,11 +13265,11 @@ async function electrumFetchTransactionOutputs(client, txid) {
|
|
|
13086
13265
|
let rawHex;
|
|
13087
13266
|
try {
|
|
13088
13267
|
rawHex = await client.request("blockchain.transaction.get", [txid]);
|
|
13089
|
-
} catch (
|
|
13268
|
+
} catch (e12) {
|
|
13090
13269
|
return null;
|
|
13091
13270
|
}
|
|
13092
13271
|
try {
|
|
13093
|
-
const tx =
|
|
13272
|
+
const tx = _chunkLZQZYSOZcjs.Transaction2.fromRaw(_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, rawHex), {
|
|
13094
13273
|
allowUnknownOutputs: true,
|
|
13095
13274
|
allowUnknownInputs: true,
|
|
13096
13275
|
disableScriptCheck: true
|
|
@@ -13100,7 +13279,7 @@ async function electrumFetchTransactionOutputs(client, txid) {
|
|
|
13100
13279
|
vout.push({ value: Number(_nullishCoalesce(tx.getOutput(i).amount, () => ( 0n))) });
|
|
13101
13280
|
}
|
|
13102
13281
|
return { vout };
|
|
13103
|
-
} catch (
|
|
13282
|
+
} catch (e13) {
|
|
13104
13283
|
return null;
|
|
13105
13284
|
}
|
|
13106
13285
|
}
|
|
@@ -13113,7 +13292,7 @@ async function electrumBroadcastTransaction(client, txHex) {
|
|
|
13113
13292
|
}
|
|
13114
13293
|
async function electrumWaitForOutputByAddress(client, address2, network, timeoutMs, opts) {
|
|
13115
13294
|
const scripthash = addressToScriptHash(address2, network);
|
|
13116
|
-
const safetyRecheckMs = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
13295
|
+
const safetyRecheckMs = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _145 => _145.safetyRecheckMs]), () => ( 5e3));
|
|
13117
13296
|
return new Promise((resolve, reject) => {
|
|
13118
13297
|
let settled = false;
|
|
13119
13298
|
let deadlineTimer = null;
|
|
@@ -13138,7 +13317,7 @@ async function electrumWaitForOutputByAddress(client, address2, network, timeout
|
|
|
13138
13317
|
network
|
|
13139
13318
|
);
|
|
13140
13319
|
if (output) finish({ ok: output });
|
|
13141
|
-
} catch (
|
|
13320
|
+
} catch (e14) {
|
|
13142
13321
|
} finally {
|
|
13143
13322
|
checking = false;
|
|
13144
13323
|
}
|
|
@@ -13230,7 +13409,7 @@ async function fetchTransactionOutputs(esploraUrls, txid) {
|
|
|
13230
13409
|
}
|
|
13231
13410
|
return await response.json();
|
|
13232
13411
|
});
|
|
13233
|
-
} catch (
|
|
13412
|
+
} catch (e15) {
|
|
13234
13413
|
return null;
|
|
13235
13414
|
}
|
|
13236
13415
|
}
|
|
@@ -13251,7 +13430,7 @@ async function fetchFeeRateEstimate(esploraUrls, targetBlocks) {
|
|
|
13251
13430
|
}
|
|
13252
13431
|
return rate;
|
|
13253
13432
|
});
|
|
13254
|
-
} catch (
|
|
13433
|
+
} catch (e16) {
|
|
13255
13434
|
return void 0;
|
|
13256
13435
|
}
|
|
13257
13436
|
}
|
|
@@ -13323,6 +13502,23 @@ async function broadcastTransactionWithRetry(esploraUrls, txHex, retries = 5) {
|
|
|
13323
13502
|
}
|
|
13324
13503
|
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
13325
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
|
+
}
|
|
13326
13522
|
_chunk5JR6AJ3Ycjs.init_utils.call(void 0, );
|
|
13327
13523
|
var KERNEL_DELEGATION_TARGET = "0xd6CEDDe84be40893d153Be9d467CD6aD37875b28";
|
|
13328
13524
|
var KERNEL_VERSION = "0.3.3";
|
|
@@ -13359,7 +13555,7 @@ function kernelErc1271Digest(innerHash, account, chainId) {
|
|
|
13359
13555
|
concat(KERNEL_WRAPPER_TYPEHASH, bytes32(innerHash))
|
|
13360
13556
|
);
|
|
13361
13557
|
return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0,
|
|
13362
|
-
|
|
13558
|
+
_chunkEI5ILLQ3cjs.keccak_256.call(void 0, concat(_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, "1901"), domainSeparator, structHash))
|
|
13363
13559
|
)}`;
|
|
13364
13560
|
}
|
|
13365
13561
|
function wrapKernelErc1271Signature(signature) {
|
|
@@ -13372,7 +13568,7 @@ function wrapKernelErc1271Signature(signature) {
|
|
|
13372
13568
|
return `0x${ERC1271_SUDO_MODE_PREFIX}${hex2}`;
|
|
13373
13569
|
}
|
|
13374
13570
|
function keccak(data) {
|
|
13375
|
-
return
|
|
13571
|
+
return _chunkEI5ILLQ3cjs.keccak_256.call(void 0, data);
|
|
13376
13572
|
}
|
|
13377
13573
|
function utf8(s) {
|
|
13378
13574
|
return new TextEncoder().encode(s);
|
|
@@ -13452,7 +13648,7 @@ function encodeNativeCreate(params) {
|
|
|
13452
13648
|
abi,
|
|
13453
13649
|
functionName: "create",
|
|
13454
13650
|
args: [
|
|
13455
|
-
`0x${
|
|
13651
|
+
`0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, params.preimageHash)}`,
|
|
13456
13652
|
params.claimAddress,
|
|
13457
13653
|
BigInt(params.timelock)
|
|
13458
13654
|
]
|
|
@@ -13469,10 +13665,10 @@ function buildNativeClaimTx(params) {
|
|
|
13469
13665
|
}
|
|
13470
13666
|
const preimage = params.preimage.startsWith("0x") ? params.preimage : `0x${params.preimage}`;
|
|
13471
13667
|
const amount = BigInt(swap.evm_expected_sats);
|
|
13472
|
-
const callsHash =
|
|
13668
|
+
const callsHash = _chunkEI5ILLQ3cjs.computeCoordinatorCallsHash.call(void 0, []);
|
|
13473
13669
|
const signature = signEvmDigest(
|
|
13474
13670
|
secretKey,
|
|
13475
|
-
|
|
13671
|
+
_chunkEI5ILLQ3cjs.buildNativeRedeemDigest.call(void 0, {
|
|
13476
13672
|
htlcAddress: swap.evm_htlc_address,
|
|
13477
13673
|
chainId: swap.evm_chain_id,
|
|
13478
13674
|
htlcVersion: swap.evm_htlc_version,
|
|
@@ -13482,7 +13678,7 @@ function buildNativeClaimTx(params) {
|
|
|
13482
13678
|
timelock: swap.evm_refund_locktime,
|
|
13483
13679
|
caller,
|
|
13484
13680
|
destination,
|
|
13485
|
-
sweepToken:
|
|
13681
|
+
sweepToken: _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS,
|
|
13486
13682
|
minAmountOut: amount,
|
|
13487
13683
|
callsHash
|
|
13488
13684
|
})
|
|
@@ -13498,7 +13694,7 @@ function buildNativeClaimTx(params) {
|
|
|
13498
13694
|
swap.server_evm_address,
|
|
13499
13695
|
BigInt(swap.evm_refund_locktime),
|
|
13500
13696
|
destination,
|
|
13501
|
-
|
|
13697
|
+
_chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS,
|
|
13502
13698
|
amount,
|
|
13503
13699
|
callsHash,
|
|
13504
13700
|
signature.v,
|
|
@@ -13508,7 +13704,7 @@ function buildNativeClaimTx(params) {
|
|
|
13508
13704
|
})
|
|
13509
13705
|
};
|
|
13510
13706
|
}
|
|
13511
|
-
var selector = (signature) =>
|
|
13707
|
+
var selector = (signature) => _chunkEI5ILLQ3cjs.keccak2562.call(void 0, new TextEncoder().encode(signature)).slice(0, 10);
|
|
13512
13708
|
var SHAPES = {
|
|
13513
13709
|
// HTLCCoordinator.refundTo: the coordinator is the lock's sender (v6).
|
|
13514
13710
|
refundTo: {
|
|
@@ -13573,22 +13769,22 @@ function decodeRefundCall(data) {
|
|
|
13573
13769
|
kind,
|
|
13574
13770
|
preimageHash: `0x${values.hash}`,
|
|
13575
13771
|
amount: _chunkTNZW35XAcjs.decodeUint256.call(void 0, values.amount),
|
|
13576
|
-
token: "token" in values ? address2("token") :
|
|
13772
|
+
token: "token" in values ? address2("token") : _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS.toLowerCase(),
|
|
13577
13773
|
sender: "sender" in values ? address2("sender") : void 0,
|
|
13578
13774
|
claimAddress: address2("claim"),
|
|
13579
13775
|
timelock: Number(timelock)
|
|
13580
13776
|
};
|
|
13581
13777
|
}
|
|
13582
13778
|
function encodeRefundCall(to, call) {
|
|
13583
|
-
const word2 = (hex2) =>
|
|
13779
|
+
const word2 = (hex2) => _chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, hex2);
|
|
13584
13780
|
const uint = (value) => BigInt(value).toString(16).padStart(64, "0");
|
|
13585
13781
|
switch (call.kind) {
|
|
13586
13782
|
case "refundTo":
|
|
13587
|
-
return { to, data:
|
|
13783
|
+
return { to, data: _chunkEI5ILLQ3cjs.encodeRefundTo.call(void 0, to, call).data };
|
|
13588
13784
|
case "nativeRefundTo":
|
|
13589
|
-
return { to, data:
|
|
13785
|
+
return { to, data: _chunkEI5ILLQ3cjs.encodeNativeRefundTo.call(void 0, to, call).data };
|
|
13590
13786
|
case "nativeRefund":
|
|
13591
|
-
return { to, data:
|
|
13787
|
+
return { to, data: _chunkEI5ILLQ3cjs.encodeHtlcNativeRefundCallData.call(void 0, to, call).data };
|
|
13592
13788
|
case "refundFor":
|
|
13593
13789
|
case "nativeRefundFor": {
|
|
13594
13790
|
if (call.sender === void 0) {
|
|
@@ -13636,12 +13832,12 @@ async function claimViaGasless(params) {
|
|
|
13636
13832
|
const targetTokenAddress = String(swap.target_token.token_id);
|
|
13637
13833
|
const needsDexSwap = targetTokenAddress.toLowerCase() !== wbtcAddress.toLowerCase();
|
|
13638
13834
|
const sweepToken = needsDexSwap ? targetTokenAddress : wbtcAddress;
|
|
13639
|
-
if (!needsDexSwap &&
|
|
13835
|
+
if (!needsDexSwap && _chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, callsHash) !== _chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, _chunkEI5ILLQ3cjs.computeCoordinatorCallsHash.call(void 0, []))) {
|
|
13640
13836
|
throw new Error(
|
|
13641
13837
|
"Refusing the server's claim: server calls on a direct claim"
|
|
13642
13838
|
);
|
|
13643
13839
|
}
|
|
13644
|
-
const digest =
|
|
13840
|
+
const digest = _chunkEI5ILLQ3cjs.buildRedeemDigest.call(void 0, {
|
|
13645
13841
|
htlcAddress: swap.evm_htlc_address,
|
|
13646
13842
|
chainId: swap.evm_chain_id,
|
|
13647
13843
|
preimage: secretHex,
|
|
@@ -13678,15 +13874,15 @@ function alreadyClaimedStatus(errorText) {
|
|
|
13678
13874
|
const match = /cannot claim a swap in (client_redeeming|client_redeemed|server_redeemed)/.exec(
|
|
13679
13875
|
errorText
|
|
13680
13876
|
);
|
|
13681
|
-
return _optionalChain([match, 'optionalAccess',
|
|
13877
|
+
return _optionalChain([match, 'optionalAccess', _146 => _146[1]]);
|
|
13682
13878
|
}
|
|
13683
13879
|
async function postClaim(baseUrl, swapId, body) {
|
|
13684
13880
|
const response = await fetch(`${baseUrl}/swap/${swapId}/claim-gasless`, {
|
|
13685
13881
|
method: "POST",
|
|
13686
13882
|
headers: {
|
|
13687
13883
|
"Content-Type": "application/json",
|
|
13688
|
-
"X-Lendaswap-Client":
|
|
13689
|
-
...
|
|
13884
|
+
"X-Lendaswap-Client": _chunkLZQZYSOZcjs.CLIENT_AGENT,
|
|
13885
|
+
..._chunkLZQZYSOZcjs.PROTOCOL_HEADERS
|
|
13690
13886
|
},
|
|
13691
13887
|
body: JSON.stringify(body)
|
|
13692
13888
|
});
|
|
@@ -13909,8 +14105,8 @@ async function buildArkadeClaim(params) {
|
|
|
13909
14105
|
`Preimage hash are not equal. '${_chunkRYZSWESUcjs.hex.encode(_chunkBEW62OUTcjs.ripemd1602.call(void 0, _chunkRYZSWESUcjs.hex.decode(preimageHash)))}' vs ${preimageHashBytesString}'`
|
|
13910
14106
|
);
|
|
13911
14107
|
}
|
|
13912
|
-
const networkName =
|
|
13913
|
-
const serverUrl =
|
|
14108
|
+
const networkName = _chunkLZQZYSOZcjs.getNetworkName.call(void 0, network);
|
|
14109
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
|
|
13914
14110
|
const arkProvider = new (0, _chunkBEW62OUTcjs.RestOperatorProvider)(serverUrl);
|
|
13915
14111
|
const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
|
|
13916
14112
|
const serverInfo = await arkProvider.getInfo();
|
|
@@ -13926,13 +14122,13 @@ async function buildArkadeClaim(params) {
|
|
|
13926
14122
|
unilateralRefundWithoutReceiverDelay
|
|
13927
14123
|
)
|
|
13928
14124
|
};
|
|
13929
|
-
if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !==
|
|
14125
|
+
if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !== _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
|
|
13930
14126
|
throw new Error(
|
|
13931
14127
|
`Unsupported Arkade HTLC script version: ${arkadeHtlcScriptVersion}`
|
|
13932
14128
|
);
|
|
13933
14129
|
}
|
|
13934
|
-
const vhtlc = new (0,
|
|
13935
|
-
const hrp =
|
|
14130
|
+
const vhtlc = new (0, _chunkLZQZYSOZcjs.StrictVhtlcScript)(vhtlcOptions);
|
|
14131
|
+
const hrp = _chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, networkName);
|
|
13936
14132
|
const computedAddress = vhtlc.address(hrp, serverPkBytes);
|
|
13937
14133
|
const computedAddressStr = computedAddress.encode();
|
|
13938
14134
|
if (computedAddressStr !== vhtlcAddress) {
|
|
@@ -14075,8 +14271,8 @@ async function continueArkadeClaim(params) {
|
|
|
14075
14271
|
`Preimage hash are not equal. '${_chunkRYZSWESUcjs.hex.encode(_chunkBEW62OUTcjs.ripemd1602.call(void 0, _chunkRYZSWESUcjs.hex.decode(preimageHash)))}' vs ${preimageHashBytesString}'`
|
|
14076
14272
|
);
|
|
14077
14273
|
}
|
|
14078
|
-
const networkName =
|
|
14079
|
-
const serverUrl =
|
|
14274
|
+
const networkName = _chunkLZQZYSOZcjs.getNetworkName.call(void 0, network);
|
|
14275
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
|
|
14080
14276
|
const arkProvider = new (0, _chunkBEW62OUTcjs.RestOperatorProvider)(serverUrl);
|
|
14081
14277
|
const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
|
|
14082
14278
|
const vhtlcOptions = {
|
|
@@ -14091,13 +14287,13 @@ async function continueArkadeClaim(params) {
|
|
|
14091
14287
|
unilateralRefundWithoutReceiverDelay
|
|
14092
14288
|
)
|
|
14093
14289
|
};
|
|
14094
|
-
if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !==
|
|
14290
|
+
if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !== _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
|
|
14095
14291
|
throw new Error(
|
|
14096
14292
|
`Unsupported Arkade HTLC script version: ${arkadeHtlcScriptVersion}`
|
|
14097
14293
|
);
|
|
14098
14294
|
}
|
|
14099
|
-
const vhtlc = new (0,
|
|
14100
|
-
const hrp =
|
|
14295
|
+
const vhtlc = new (0, _chunkLZQZYSOZcjs.StrictVhtlcScript)(vhtlcOptions);
|
|
14296
|
+
const hrp = _chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, networkName);
|
|
14101
14297
|
const computedAddress = vhtlc.address(hrp, serverPkBytes);
|
|
14102
14298
|
const computedAddressStr = computedAddress.encode();
|
|
14103
14299
|
if (computedAddressStr !== vhtlcAddress) {
|
|
@@ -14145,7 +14341,7 @@ async function continueArkadeClaim(params) {
|
|
|
14145
14341
|
amount: BigInt(v.value)
|
|
14146
14342
|
},
|
|
14147
14343
|
tapLeafScript: [claimLeafScript],
|
|
14148
|
-
sighashType:
|
|
14344
|
+
sighashType: _chunkLZQZYSOZcjs.SigHash.ALL
|
|
14149
14345
|
}));
|
|
14150
14346
|
const intentProof = _chunkBEW62OUTcjs.Proof.create(intentMessage, intentInputs);
|
|
14151
14347
|
for (let i = 0; i < vtxos.length; i++) {
|
|
@@ -14349,7 +14545,7 @@ async function claimNativeViaRifRelay(params) {
|
|
|
14349
14545
|
"/relay",
|
|
14350
14546
|
rifEnvelope(request, signature)
|
|
14351
14547
|
);
|
|
14352
|
-
const txHash = _nullishCoalesce(relayed.txHash, () => (
|
|
14548
|
+
const txHash = _nullishCoalesce(relayed.txHash, () => ( _chunkEI5ILLQ3cjs.keccak2562.call(void 0, relayed.signedTx)));
|
|
14353
14549
|
const receipt = await signer.waitForReceipt(txHash);
|
|
14354
14550
|
if (receipt.status !== "success") {
|
|
14355
14551
|
throw new Error(`RIF Relay claim transaction ${txHash} reverted.`);
|
|
@@ -14460,13 +14656,13 @@ function encodeNativeRedeem(p) {
|
|
|
14460
14656
|
return HTLC_NATIVE_REDEEM_SELECTOR + word(p.preimage) + word(p.amount) + word(p.sender) + word(p.timelock);
|
|
14461
14657
|
}
|
|
14462
14658
|
function rifSmartWalletAddress(relay, owner) {
|
|
14463
|
-
const salt =
|
|
14659
|
+
const salt = _chunkEI5ILLQ3cjs.keccak2562.call(void 0,
|
|
14464
14660
|
`0x${strip0x(owner).toLowerCase()}${"0".repeat(40)}${word(BigInt(RIF_SMART_WALLET_INDEX))}`
|
|
14465
14661
|
);
|
|
14466
|
-
const initCodeHash =
|
|
14662
|
+
const initCodeHash = _chunkEI5ILLQ3cjs.keccak2562.call(void 0,
|
|
14467
14663
|
`0x602d3d8160093d39f3363d3d373d3d3d3d363d73${strip0x(relay.smart_wallet_template).toLowerCase()}5af43d923d90803e602b57fd5bf3`
|
|
14468
14664
|
);
|
|
14469
|
-
const hash =
|
|
14665
|
+
const hash = _chunkEI5ILLQ3cjs.keccak2562.call(void 0,
|
|
14470
14666
|
`0xff${strip0x(relay.smart_wallet_factory).toLowerCase()}${strip0x(salt)}${strip0x(initCodeHash)}`
|
|
14471
14667
|
);
|
|
14472
14668
|
return `0x${hash.slice(-40)}`;
|
|
@@ -14508,7 +14704,7 @@ async function rifResponse(response, path) {
|
|
|
14508
14704
|
let body;
|
|
14509
14705
|
try {
|
|
14510
14706
|
body = JSON.parse(text);
|
|
14511
|
-
} catch (
|
|
14707
|
+
} catch (e18) {
|
|
14512
14708
|
throw new Error(
|
|
14513
14709
|
`RIF Relay ${path} answered ${response.status}: ${text.slice(0, 200)}`
|
|
14514
14710
|
);
|
|
@@ -14540,8 +14736,8 @@ function buildRedeemAndExecuteTx(params) {
|
|
|
14540
14736
|
const amount = BigInt(swap.evm_expected_sats);
|
|
14541
14737
|
const targetTokenAddress = String(swap.target_token.token_id);
|
|
14542
14738
|
const sweepToken = targetTokenAddress.toLowerCase() !== wbtcAddress.toLowerCase() ? targetTokenAddress : wbtcAddress;
|
|
14543
|
-
const callsHash =
|
|
14544
|
-
const digest =
|
|
14739
|
+
const callsHash = _chunkEI5ILLQ3cjs.computeCoordinatorCallsHash.call(void 0, calls);
|
|
14740
|
+
const digest = _chunkEI5ILLQ3cjs.buildRedeemDigest.call(void 0, {
|
|
14545
14741
|
htlcAddress: swap.evm_htlc_address,
|
|
14546
14742
|
chainId: swap.evm_chain_id,
|
|
14547
14743
|
preimage: secretHex,
|
|
@@ -14557,7 +14753,7 @@ function buildRedeemAndExecuteTx(params) {
|
|
|
14557
14753
|
htlcVersion: swap.evm_htlc_version
|
|
14558
14754
|
});
|
|
14559
14755
|
const sig = signEvmDigest(secretKey, digest);
|
|
14560
|
-
const { to, data } =
|
|
14756
|
+
const { to, data } = _chunkEI5ILLQ3cjs.encodeRedeemAndExecute.call(void 0, swap.evm_coordinator_address, {
|
|
14561
14757
|
preimage: secretHex,
|
|
14562
14758
|
amount,
|
|
14563
14759
|
token: wbtcAddress,
|
|
@@ -14577,7 +14773,7 @@ async function claimViaUserOp(params) {
|
|
|
14577
14773
|
const { secretKey, swap, aa } = params;
|
|
14578
14774
|
const { to, data } = buildRedeemAndExecuteTx(params);
|
|
14579
14775
|
const signer = keyToKernelOwnerSigner(secretKey, swap.evm_chain_id);
|
|
14580
|
-
const { client } = await
|
|
14776
|
+
const { client } = await _chunkEI5ILLQ3cjs.createSwapSmartAccountClient.call(void 0, {
|
|
14581
14777
|
signer,
|
|
14582
14778
|
aa,
|
|
14583
14779
|
chain: _chunk7BLTE6ETcjs.arbitrum
|
|
@@ -14631,7 +14827,7 @@ async function claimViaSigner(params) {
|
|
|
14631
14827
|
`Replacement transaction ${minedHash} was mined, but its claim could not yet be verified. Check the swap status or transaction before submitting another claim.`
|
|
14632
14828
|
);
|
|
14633
14829
|
}
|
|
14634
|
-
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()) {
|
|
14635
14831
|
throw new Error(
|
|
14636
14832
|
"The wallet replaced or cancelled the claim transaction. The claim was not submitted; try again from the payout wallet."
|
|
14637
14833
|
);
|
|
@@ -14767,7 +14963,7 @@ function formatApiError(error) {
|
|
|
14767
14963
|
}
|
|
14768
14964
|
try {
|
|
14769
14965
|
return JSON.stringify(error);
|
|
14770
|
-
} catch (
|
|
14966
|
+
} catch (e19) {
|
|
14771
14967
|
}
|
|
14772
14968
|
}
|
|
14773
14969
|
return String(error);
|
|
@@ -14777,7 +14973,7 @@ function buildRefundScriptVhtlc(params) {
|
|
|
14777
14973
|
const lendaswapPkBytes = parseXOnlyPubKey3(params.lendaswapPubKey);
|
|
14778
14974
|
const serverPkBytes = parseXOnlyPubKey3(params.arkadeServerPubKey);
|
|
14779
14975
|
const preimageHashBytes = parsePreimageHash(params.hashLock);
|
|
14780
|
-
const networkName =
|
|
14976
|
+
const networkName = _chunkLZQZYSOZcjs.getNetworkName.call(void 0, params.network);
|
|
14781
14977
|
const options = {
|
|
14782
14978
|
sender: userPkBytes,
|
|
14783
14979
|
receiver: lendaswapPkBytes,
|
|
@@ -14790,13 +14986,13 @@ function buildRefundScriptVhtlc(params) {
|
|
|
14790
14986
|
params.unilateralRefundWithoutReceiverDelay
|
|
14791
14987
|
)
|
|
14792
14988
|
};
|
|
14793
|
-
if (params.arkadeHtlcScriptVersion !== void 0 && params.arkadeHtlcScriptVersion !==
|
|
14989
|
+
if (params.arkadeHtlcScriptVersion !== void 0 && params.arkadeHtlcScriptVersion !== _chunkLZQZYSOZcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
|
|
14794
14990
|
throw new Error(
|
|
14795
14991
|
`Unsupported Arkade HTLC script version: ${params.arkadeHtlcScriptVersion}`
|
|
14796
14992
|
);
|
|
14797
14993
|
}
|
|
14798
|
-
const vhtlc = new (0,
|
|
14799
|
-
const hrp =
|
|
14994
|
+
const vhtlc = new (0, _chunkLZQZYSOZcjs.StrictVhtlcScript)(options);
|
|
14995
|
+
const hrp = _chunkLZQZYSOZcjs.getNetworkHrp.call(void 0, networkName);
|
|
14800
14996
|
const computedAddress = vhtlc.address(hrp, serverPkBytes).encode();
|
|
14801
14997
|
if (computedAddress !== params.vhtlcAddress) {
|
|
14802
14998
|
throw new Error(
|
|
@@ -14807,7 +15003,7 @@ function buildRefundScriptVhtlc(params) {
|
|
|
14807
15003
|
}
|
|
14808
15004
|
async function collabRefundArkadeToEvmOffchain(params) {
|
|
14809
15005
|
const { vhtlc, networkName } = buildRefundScriptVhtlc(params);
|
|
14810
|
-
const serverUrl =
|
|
15006
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrlByName.call(void 0,
|
|
14811
15007
|
networkName,
|
|
14812
15008
|
params.arkadeServerUrl
|
|
14813
15009
|
);
|
|
@@ -14893,7 +15089,7 @@ async function collabRefundArkadeToEvmOffchain(params) {
|
|
|
14893
15089
|
}
|
|
14894
15090
|
async function collabRefundArkadeToEvmDelegate(params) {
|
|
14895
15091
|
const { vhtlc, networkName } = buildRefundScriptVhtlc(params);
|
|
14896
|
-
const serverUrl =
|
|
15092
|
+
const serverUrl = _chunkLZQZYSOZcjs.resolveArkadeServerUrlByName.call(void 0,
|
|
14897
15093
|
networkName,
|
|
14898
15094
|
params.arkadeServerUrl
|
|
14899
15095
|
);
|
|
@@ -14908,13 +15104,13 @@ async function collabRefundArkadeToEvmDelegate(params) {
|
|
|
14908
15104
|
}
|
|
14909
15105
|
const cosignerPkHex = cosignerRes.data.cosigner_pk;
|
|
14910
15106
|
const btcNetwork = _chunkBEW62OUTcjs.networks[networkName];
|
|
14911
|
-
const forfeitDecoded =
|
|
15107
|
+
const forfeitDecoded = _chunkLZQZYSOZcjs.Address.call(void 0, btcNetwork).decode(serverInfo.forfeitAddress);
|
|
14912
15108
|
if (!forfeitDecoded) {
|
|
14913
15109
|
throw new Error(
|
|
14914
15110
|
`Unrecognised forfeit address: ${serverInfo.forfeitAddress}`
|
|
14915
15111
|
);
|
|
14916
15112
|
}
|
|
14917
|
-
const forfeitPkScript =
|
|
15113
|
+
const forfeitPkScript = _chunkLZQZYSOZcjs.OutScript.encode(forfeitDecoded);
|
|
14918
15114
|
const vhtlcPkScript = _chunkRYZSWESUcjs.hex.encode(vhtlc.pkScript);
|
|
14919
15115
|
const { vtxos: allVtxos } = await indexerProvider.getVtxos({
|
|
14920
15116
|
scripts: [vhtlcPkScript]
|
|
@@ -14947,7 +15143,7 @@ async function collabRefundArkadeToEvmDelegate(params) {
|
|
|
14947
15143
|
amount: BigInt(v.value)
|
|
14948
15144
|
},
|
|
14949
15145
|
tapLeafScript: [tapLeafScript],
|
|
14950
|
-
sighashType:
|
|
15146
|
+
sighashType: _chunkLZQZYSOZcjs.SigHash.ALL
|
|
14951
15147
|
}));
|
|
14952
15148
|
const intentProof = _chunkBEW62OUTcjs.Proof.create(intentMessage, intentInputs, [
|
|
14953
15149
|
{ script: destination.pkScript, amount: totalAmount }
|
|
@@ -14973,7 +15169,7 @@ async function collabRefundArkadeToEvmDelegate(params) {
|
|
|
14973
15169
|
amount: vtxoAmount
|
|
14974
15170
|
},
|
|
14975
15171
|
tapLeafScript: [tapLeafScript],
|
|
14976
|
-
sighashType:
|
|
15172
|
+
sighashType: _chunkLZQZYSOZcjs.SigHash.ALL_ANYONECANPAY
|
|
14977
15173
|
});
|
|
14978
15174
|
forfeitTx.addOutput({
|
|
14979
15175
|
script: forfeitPkScript,
|
|
@@ -15191,7 +15387,7 @@ function isValidTronAddress(address2) {
|
|
|
15191
15387
|
try {
|
|
15192
15388
|
tronAddressToBytes32(address2);
|
|
15193
15389
|
return true;
|
|
15194
|
-
} catch (
|
|
15390
|
+
} catch (e20) {
|
|
15195
15391
|
return false;
|
|
15196
15392
|
}
|
|
15197
15393
|
}
|
|
@@ -15225,7 +15421,7 @@ function createSwapStatusWatcher(baseUrl) {
|
|
|
15225
15421
|
let parsed;
|
|
15226
15422
|
try {
|
|
15227
15423
|
parsed = JSON.parse(evt.data);
|
|
15228
|
-
} catch (
|
|
15424
|
+
} catch (e21) {
|
|
15229
15425
|
return;
|
|
15230
15426
|
}
|
|
15231
15427
|
if ("data" in parsed && parsed.channel === "swap_status") {
|
|
@@ -15244,8 +15440,8 @@ function createSwapStatusWatcher(baseUrl) {
|
|
|
15244
15440
|
});
|
|
15245
15441
|
socket.addEventListener("error", () => {
|
|
15246
15442
|
try {
|
|
15247
|
-
_optionalChain([socket, 'optionalAccess',
|
|
15248
|
-
} catch (
|
|
15443
|
+
_optionalChain([socket, 'optionalAccess', _150 => _150.close, 'call', _151 => _151()]);
|
|
15444
|
+
} catch (e22) {
|
|
15249
15445
|
}
|
|
15250
15446
|
});
|
|
15251
15447
|
}
|
|
@@ -15262,7 +15458,7 @@ function createSwapStatusWatcher(baseUrl) {
|
|
|
15262
15458
|
}, delay);
|
|
15263
15459
|
}
|
|
15264
15460
|
function sendSubscribe(ids) {
|
|
15265
|
-
if (ids.length === 0 || _optionalChain([socket, 'optionalAccess',
|
|
15461
|
+
if (ids.length === 0 || _optionalChain([socket, 'optionalAccess', _152 => _152.readyState]) !== WebSocket.OPEN) return;
|
|
15266
15462
|
const frame = {
|
|
15267
15463
|
op: "subscribe",
|
|
15268
15464
|
channel: "swap_status",
|
|
@@ -15271,7 +15467,7 @@ function createSwapStatusWatcher(baseUrl) {
|
|
|
15271
15467
|
socket.send(JSON.stringify(frame));
|
|
15272
15468
|
}
|
|
15273
15469
|
function sendUnsubscribe(ids) {
|
|
15274
|
-
if (ids.length === 0 || _optionalChain([socket, 'optionalAccess',
|
|
15470
|
+
if (ids.length === 0 || _optionalChain([socket, 'optionalAccess', _153 => _153.readyState]) !== WebSocket.OPEN) return;
|
|
15275
15471
|
const frame = {
|
|
15276
15472
|
op: "unsubscribe",
|
|
15277
15473
|
channel: "swap_status",
|
|
@@ -15287,8 +15483,8 @@ function createSwapStatusWatcher(baseUrl) {
|
|
|
15287
15483
|
reconnectTimer = null;
|
|
15288
15484
|
}
|
|
15289
15485
|
try {
|
|
15290
|
-
_optionalChain([socket, 'optionalAccess',
|
|
15291
|
-
} catch (
|
|
15486
|
+
_optionalChain([socket, 'optionalAccess', _154 => _154.close, 'call', _155 => _155()]);
|
|
15487
|
+
} catch (e23) {
|
|
15292
15488
|
}
|
|
15293
15489
|
socket = null;
|
|
15294
15490
|
}
|
|
@@ -15404,7 +15600,7 @@ function checkedRefundContext(checked) {
|
|
|
15404
15600
|
};
|
|
15405
15601
|
}
|
|
15406
15602
|
function permit2RefundAddress(serverData, depositorAddress) {
|
|
15407
|
-
if (!
|
|
15603
|
+
if (!_chunkEI5ILLQ3cjs.depositorIsSender.call(void 0, serverData.htlc_kind, serverData.htlc_version)) {
|
|
15408
15604
|
return serverData.coordinator_address;
|
|
15409
15605
|
}
|
|
15410
15606
|
if (!depositorAddress) {
|
|
@@ -15415,8 +15611,8 @@ function permit2RefundAddress(serverData, depositorAddress) {
|
|
|
15415
15611
|
return depositorAddress;
|
|
15416
15612
|
}
|
|
15417
15613
|
function ensureRehashMatchesRequest(signature, paymentHash, params) {
|
|
15418
|
-
const signed = `0x${
|
|
15419
|
-
if (signed !== `0x${
|
|
15614
|
+
const signed = `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, signature.newPreimageHash)}`;
|
|
15615
|
+
if (signed !== `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, paymentHash)}`) {
|
|
15420
15616
|
throw new Error(
|
|
15421
15617
|
`The server signed a rehash to ${signed}, not to the invoice's payment hash ${paymentHash}`
|
|
15422
15618
|
);
|
|
@@ -15426,18 +15622,18 @@ function ensureRehashMatchesRequest(signature, paymentHash, params) {
|
|
|
15426
15622
|
`The server signed a rehash with timelock ${signature.newTimelock}, later than the advertised ${params.newTimelock}`
|
|
15427
15623
|
);
|
|
15428
15624
|
}
|
|
15429
|
-
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)}`) {
|
|
15430
15626
|
throw new Error(
|
|
15431
15627
|
"The server signed a rehash for another lock than the swap's"
|
|
15432
15628
|
);
|
|
15433
15629
|
}
|
|
15434
15630
|
}
|
|
15435
15631
|
function ensureLockIsOwn(lock, named, what) {
|
|
15436
|
-
const native = lock.token ===
|
|
15632
|
+
const native = lock.token === _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
|
|
15437
15633
|
const mismatches = [
|
|
15438
15634
|
named.htlcAddress.toLowerCase() !== lock.htlcAddress.toLowerCase() && "htlc address",
|
|
15439
15635
|
named.chainId !== lock.chainId && "chain",
|
|
15440
|
-
`0x${
|
|
15636
|
+
`0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, named.preimageHash)}` !== lock.preimageHash && "preimage hash",
|
|
15441
15637
|
BigInt(named.amount) !== lock.amount && "amount",
|
|
15442
15638
|
// A native lock keys a zero asset word whatever the server calls it.
|
|
15443
15639
|
!native && named.token.toLowerCase() !== lock.token && "token",
|
|
@@ -15462,7 +15658,7 @@ function rehashCallData(signature) {
|
|
|
15462
15658
|
r: signature.r,
|
|
15463
15659
|
s: signature.s
|
|
15464
15660
|
};
|
|
15465
|
-
return signature.htlcKind === "native" ?
|
|
15661
|
+
return signature.htlcKind === "native" ? _chunkEI5ILLQ3cjs.encodeHtlcNativeRehashCallData.call(void 0, signature.htlcAddress, terms) : _chunkEI5ILLQ3cjs.encodeHtlcErc20RehashCallData.call(void 0, signature.htlcAddress, {
|
|
15466
15662
|
...terms,
|
|
15467
15663
|
token: signature.token
|
|
15468
15664
|
});
|
|
@@ -15476,7 +15672,7 @@ function refundBySigCallData(signature) {
|
|
|
15476
15672
|
r: signature.r,
|
|
15477
15673
|
s: signature.s
|
|
15478
15674
|
};
|
|
15479
|
-
return signature.htlcKind === "native" ?
|
|
15675
|
+
return signature.htlcKind === "native" ? _chunkEI5ILLQ3cjs.encodeHtlcNativeRefundBySigCallData.call(void 0, signature.htlcAddress, terms) : _chunkEI5ILLQ3cjs.encodeHtlcErc20RefundBySigCallData.call(void 0, signature.htlcAddress, {
|
|
15480
15676
|
...terms,
|
|
15481
15677
|
token: signature.token
|
|
15482
15678
|
});
|
|
@@ -15503,7 +15699,7 @@ async function sendCall(signer, call, label, options = {}) {
|
|
|
15503
15699
|
type: _chunkTNZW35XAcjs.txTypeFor.call(void 0, signer.chainId),
|
|
15504
15700
|
gas: await _chunkTNZW35XAcjs.gasLimitFor.call(void 0, signer, call, _nullishCoalesce(options.fallbackGas, () => ( REFUND_GAS)))
|
|
15505
15701
|
});
|
|
15506
|
-
await _optionalChain([options, 'access',
|
|
15702
|
+
await _optionalChain([options, 'access', _156 => _156.onSent, 'optionalCall', _157 => _157(sent)]);
|
|
15507
15703
|
const receipt = await signer.waitForReceipt(sent);
|
|
15508
15704
|
if (receipt.status !== "success") {
|
|
15509
15705
|
const reason = await _chunkTNZW35XAcjs.getRevertReason.call(void 0, signer, sent, receipt.blockNumber);
|
|
@@ -15520,8 +15716,8 @@ async function sendCall(signer, call, label, options = {}) {
|
|
|
15520
15716
|
async function isSameCall(signer, hash, call) {
|
|
15521
15717
|
try {
|
|
15522
15718
|
const tx = await signer.getTransaction(hash);
|
|
15523
|
-
return _optionalChain([tx, 'optionalAccess',
|
|
15524
|
-
} 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) {
|
|
15525
15721
|
return false;
|
|
15526
15722
|
}
|
|
15527
15723
|
}
|
|
@@ -15538,10 +15734,10 @@ function dedupeTxids(txids) {
|
|
|
15538
15734
|
function clientHashLockOf(stored) {
|
|
15539
15735
|
switch (stored.response.direction) {
|
|
15540
15736
|
case "evm_to_lightning":
|
|
15541
|
-
return _optionalChain([stored, 'access',
|
|
15737
|
+
return _optionalChain([stored, 'access', _161 => _161.lightningPaymentHash, 'optionalAccess', _162 => _162.hash]);
|
|
15542
15738
|
case "evm_to_bitcoin":
|
|
15543
15739
|
case "evm_to_arkade":
|
|
15544
|
-
return stored.preimageHash ? `0x${
|
|
15740
|
+
return stored.preimageHash ? `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, stored.preimageHash)}` : void 0;
|
|
15545
15741
|
default:
|
|
15546
15742
|
return void 0;
|
|
15547
15743
|
}
|
|
@@ -15553,7 +15749,7 @@ function evmHashLockOf(swap) {
|
|
|
15553
15749
|
return hash;
|
|
15554
15750
|
}
|
|
15555
15751
|
function evmSourceLeg(stored) {
|
|
15556
|
-
const rehashes = _optionalChain([stored, 'access',
|
|
15752
|
+
const rehashes = _optionalChain([stored, 'access', _163 => _163.evmRehashes, 'optionalAccess', _164 => _164.length]) ? stored.evmRehashes : void 0;
|
|
15557
15753
|
const swap = stored.response;
|
|
15558
15754
|
return {
|
|
15559
15755
|
chainId: swap.evm_chain_id,
|
|
@@ -15563,9 +15759,9 @@ function evmSourceLeg(stored) {
|
|
|
15563
15759
|
// without it, and switches to the current hash once a rehash is
|
|
15564
15760
|
// confirmed). The funding tx's SwapCreated is under the first hash, and
|
|
15565
15761
|
// the rehashes are followed from there.
|
|
15566
|
-
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))),
|
|
15567
15763
|
claimAddress: swap.server_evm_address,
|
|
15568
|
-
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)),
|
|
15569
15765
|
// This client's own record first, then the server's copy (which names
|
|
15570
15766
|
// the rehash tx once a rehash is confirmed; that one carries no
|
|
15571
15767
|
// SwapCreated and is skipped as unavailable).
|
|
@@ -15576,20 +15772,20 @@ function evmSourceLeg(stored) {
|
|
|
15576
15772
|
// Read from the creation terms first, which a server refresh cannot
|
|
15577
15773
|
// rewrite; a swap recorded before they named the version falls back to
|
|
15578
15774
|
// the server's copy.
|
|
15579
|
-
depositorIsSender: _optionalChain([stored, 'access',
|
|
15775
|
+
depositorIsSender: _optionalChain([stored, 'access', _170 => _170.evmFundingTerms, 'optionalAccess', _171 => _171.htlcVersion]) !== void 0 ? _chunkEI5ILLQ3cjs.depositorIsSender.call(void 0,
|
|
15580
15776
|
stored.evmFundingTerms.htlcKind,
|
|
15581
15777
|
stored.evmFundingTerms.htlcVersion
|
|
15582
|
-
) :
|
|
15778
|
+
) : _chunkEI5ILLQ3cjs.depositorIsSender.call(void 0, swap.evm_htlc_kind, swap.evm_htlc_version)
|
|
15583
15779
|
};
|
|
15584
15780
|
}
|
|
15585
15781
|
function isDirectNativeLock(terms) {
|
|
15586
|
-
return terms.htlcKind === "native" && terms.coordinator.toLowerCase() ===
|
|
15782
|
+
return terms.htlcKind === "native" && terms.coordinator.toLowerCase() === _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
|
|
15587
15783
|
}
|
|
15588
15784
|
function provesNoLockUnder(receipt, hashLock) {
|
|
15589
15785
|
if (receipt.logs === void 0) return false;
|
|
15590
|
-
const hash = `0x${
|
|
15786
|
+
const hash = `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, hashLock)}`;
|
|
15591
15787
|
return !receipt.logs.some(
|
|
15592
|
-
(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
|
|
15593
15789
|
);
|
|
15594
15790
|
}
|
|
15595
15791
|
var serializeAmountInput = (amount) => amount == null ? void 0 : amount.toString();
|
|
@@ -15648,10 +15844,10 @@ var DEFAULT_ELECTRUM_WS_URLS = {
|
|
|
15648
15844
|
mainnet: "wss://electrs.satora.io"
|
|
15649
15845
|
};
|
|
15650
15846
|
function defaultAaConfig() {
|
|
15651
|
-
if (!
|
|
15847
|
+
if (!_chunkLZQZYSOZcjs.DEFAULT_AA_BUNDLER_URL) return void 0;
|
|
15652
15848
|
return {
|
|
15653
|
-
bundlerUrl:
|
|
15654
|
-
...
|
|
15849
|
+
bundlerUrl: _chunkLZQZYSOZcjs.DEFAULT_AA_BUNDLER_URL,
|
|
15850
|
+
..._chunkLZQZYSOZcjs.DEFAULT_AA_POLICY_ID ? { paymasterPolicyId: _chunkLZQZYSOZcjs.DEFAULT_AA_POLICY_ID } : {}
|
|
15655
15851
|
};
|
|
15656
15852
|
}
|
|
15657
15853
|
var ClientBuilder = class {
|
|
@@ -15906,9 +16102,9 @@ var ClientBuilder = class {
|
|
|
15906
16102
|
baseUrl: this.#baseUrl.replace(/\/+$/, ""),
|
|
15907
16103
|
referralCode: this.#referralCode,
|
|
15908
16104
|
defaultHeaders: this.#defaultHeaders,
|
|
15909
|
-
esploraUrl: Array.isArray(this.#esploraUrl) ? this.#esploraUrl.map((url) => url.replace(/\/+$/, "")) : _optionalChain([this, 'access',
|
|
15910
|
-
electrumWsUrl: _optionalChain([this, 'access',
|
|
15911
|
-
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(/\/+$/, "")]),
|
|
15912
16108
|
aa: _nullishCoalesce(this.#aa, () => ( defaultAaConfig())),
|
|
15913
16109
|
solanaRpcUrl: this.#solanaRpcUrl,
|
|
15914
16110
|
logger: this.#logger,
|
|
@@ -15937,6 +16133,7 @@ var Client = class _Client {
|
|
|
15937
16133
|
#composeStaticCache = /* @__PURE__ */ new Map();
|
|
15938
16134
|
#signerStorage;
|
|
15939
16135
|
#swapStorage;
|
|
16136
|
+
#ephemeralKeyIndex = 0;
|
|
15940
16137
|
#statusWatcher = null;
|
|
15941
16138
|
#cctpInbound = null;
|
|
15942
16139
|
#electrumWs = null;
|
|
@@ -15964,8 +16161,8 @@ var Client = class _Client {
|
|
|
15964
16161
|
}
|
|
15965
16162
|
#apiHeaders(extra) {
|
|
15966
16163
|
return {
|
|
15967
|
-
"X-Lendaswap-Client":
|
|
15968
|
-
...
|
|
16164
|
+
"X-Lendaswap-Client": _chunkLZQZYSOZcjs.CLIENT_AGENT,
|
|
16165
|
+
..._chunkLZQZYSOZcjs.PROTOCOL_HEADERS,
|
|
15969
16166
|
..._nullishCoalesce(this.#config.defaultHeaders, () => ( {})),
|
|
15970
16167
|
..._nullishCoalesce(extra, () => ( {}))
|
|
15971
16168
|
};
|
|
@@ -15991,11 +16188,11 @@ var Client = class _Client {
|
|
|
15991
16188
|
* Remove `onUpdate` from the given swap ids.
|
|
15992
16189
|
*/
|
|
15993
16190
|
unsubscribeFromSwaps(swapIds, onUpdate) {
|
|
15994
|
-
_optionalChain([this, 'access',
|
|
16191
|
+
_optionalChain([this, 'access', _182 => _182.#statusWatcher, 'optionalAccess', _183 => _183.unsubscribe, 'call', _184 => _184(swapIds, onUpdate)]);
|
|
15995
16192
|
}
|
|
15996
16193
|
/** Force-close the shared swap-status socket. */
|
|
15997
16194
|
closeSwapStatusSocket() {
|
|
15998
|
-
_optionalChain([this, 'access',
|
|
16195
|
+
_optionalChain([this, 'access', _185 => _185.#statusWatcher, 'optionalAccess', _186 => _186.close, 'call', _187 => _187()]);
|
|
15999
16196
|
this.#statusWatcher = null;
|
|
16000
16197
|
}
|
|
16001
16198
|
/**
|
|
@@ -16105,7 +16302,7 @@ var Client = class _Client {
|
|
|
16105
16302
|
* @returns The derived swap parameters.
|
|
16106
16303
|
*/
|
|
16107
16304
|
async deriveSwapParams() {
|
|
16108
|
-
let index =
|
|
16305
|
+
let index = this.#ephemeralKeyIndex++;
|
|
16109
16306
|
if (this.#signerStorage) {
|
|
16110
16307
|
index = await this.#signerStorage.incrementKeyIndex();
|
|
16111
16308
|
}
|
|
@@ -16125,8 +16322,8 @@ var Client = class _Client {
|
|
|
16125
16322
|
/**
|
|
16126
16323
|
* Get the deterministic EVM address for this SDK key.
|
|
16127
16324
|
*
|
|
16128
|
-
*
|
|
16129
|
-
*
|
|
16325
|
+
* Legacy wallet-level address. New gasless swaps use their own deposit
|
|
16326
|
+
* address; read it from the swap response or getSwapDepositorKey(swapId).
|
|
16130
16327
|
*
|
|
16131
16328
|
* @returns Checksummed EVM address (0x-prefixed).
|
|
16132
16329
|
*/
|
|
@@ -16185,7 +16382,7 @@ var Client = class _Client {
|
|
|
16185
16382
|
* caller falls back to probing.
|
|
16186
16383
|
*/
|
|
16187
16384
|
#delegationHintFor(swap, depositor, hint) {
|
|
16188
|
-
const hinted = _optionalChain([swap, 'access',
|
|
16385
|
+
const hinted = _optionalChain([swap, 'access', _188 => _188.client_evm_address, 'optionalAccess', _189 => _189.toLowerCase, 'call', _190 => _190()]);
|
|
16189
16386
|
return hinted && hinted === depositor.toLowerCase() ? hint : void 0;
|
|
16190
16387
|
}
|
|
16191
16388
|
async #isKernelDelegated(address2, chainId, serverHint) {
|
|
@@ -16199,7 +16396,7 @@ var Client = class _Client {
|
|
|
16199
16396
|
);
|
|
16200
16397
|
}
|
|
16201
16398
|
if (chainId !== AA_CHAIN_ID) return false;
|
|
16202
|
-
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])));
|
|
16203
16400
|
if (!rpcUrl) return false;
|
|
16204
16401
|
const { createPublicClient: createPublicClient2, http: http2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./_esm-4ZKYBBIE-D33574DC.cjs")));
|
|
16205
16402
|
const publicClient = createPublicClient2({ transport: http2(rpcUrl) });
|
|
@@ -16228,39 +16425,35 @@ var Client = class _Client {
|
|
|
16228
16425
|
*/
|
|
16229
16426
|
#getClaimEvmSigningKey(storedSwap) {
|
|
16230
16427
|
const swapKey = storedSwap.secretKey;
|
|
16231
|
-
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()]);
|
|
16232
16429
|
if (swapKey && clientAddress && clientAddress === deriveEvmAddress(swapKey).toLowerCase()) {
|
|
16233
16430
|
return swapKey;
|
|
16234
16431
|
}
|
|
16235
16432
|
return this.#getEvmSigningKey();
|
|
16236
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
|
+
}
|
|
16237
16445
|
/**
|
|
16238
16446
|
* Select the SDK-controlled EVM key that matches the swap's recorded depositor.
|
|
16239
16447
|
*
|
|
16240
|
-
*
|
|
16241
|
-
*
|
|
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
|
|
16242
16450
|
* swaps still use the per-swap key even though client_evm_address may point at
|
|
16243
16451
|
* the user's wallet rather than the later Permit2 depositor.
|
|
16244
16452
|
*/
|
|
16245
|
-
#getCollabRefundEvmSigningKey(storedSwap,
|
|
16246
|
-
|
|
16247
|
-
|
|
16248
|
-
|
|
16249
|
-
return swapKey;
|
|
16250
|
-
}
|
|
16251
|
-
const deterministicKey = this.#getEvmSigningKey();
|
|
16252
|
-
const deterministicAddress = deriveEvmAddress(deterministicKey);
|
|
16253
|
-
const swapAddress = deriveEvmAddress(swapKey);
|
|
16254
|
-
const clientAddress = _optionalChain([response, 'access', _197 => _197.client_evm_address, 'optionalAccess', _198 => _198.toLowerCase, 'call', _199 => _199()]);
|
|
16255
|
-
if (clientAddress === deterministicAddress.toLowerCase() || !clientAddress) {
|
|
16256
|
-
return deterministicKey;
|
|
16257
|
-
}
|
|
16258
|
-
if (clientAddress === swapAddress.toLowerCase()) {
|
|
16259
|
-
return swapKey;
|
|
16260
|
-
}
|
|
16261
|
-
throw new Error(
|
|
16262
|
-
`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.`
|
|
16263
|
-
);
|
|
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;
|
|
16264
16457
|
}
|
|
16265
16458
|
/**
|
|
16266
16459
|
* Gets the current key index from storage.
|
|
@@ -16414,7 +16607,7 @@ var Client = class _Client {
|
|
|
16414
16607
|
"chain-config",
|
|
16415
16608
|
() => this.getChainConfig()
|
|
16416
16609
|
);
|
|
16417
|
-
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]);
|
|
16418
16611
|
}
|
|
16419
16612
|
/**
|
|
16420
16613
|
* The claim address of a native lock on a chain that claims through RIF
|
|
@@ -16538,9 +16731,9 @@ var Client = class _Client {
|
|
|
16538
16731
|
swapPairs,
|
|
16539
16732
|
networkFees,
|
|
16540
16733
|
chainConfig,
|
|
16541
|
-
referralExtraFeeRate: _optionalChain([referral, 'optionalAccess',
|
|
16542
|
-
referralBaseFeeRate: _optionalChain([referral, 'optionalAccess',
|
|
16543
|
-
referralPromo: _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]),
|
|
16544
16737
|
getDexQuote: (p) => this.getDexQuote(p)
|
|
16545
16738
|
});
|
|
16546
16739
|
}
|
|
@@ -16887,7 +17080,7 @@ var Client = class _Client {
|
|
|
16887
17080
|
if (comparableId(data.id) !== comparableId(id)) {
|
|
16888
17081
|
throw new Error(`Requested swap ${id}, but server returned ${data.id}`);
|
|
16889
17082
|
}
|
|
16890
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
17083
|
+
if (_optionalChain([options, 'optionalAccess', _212 => _212.updateStorage]) && this.#swapStorage) {
|
|
16891
17084
|
const stored = await this.#swapStorage.get(id);
|
|
16892
17085
|
const changed = stored ? swapTermsChange(stored, data) : void 0;
|
|
16893
17086
|
if (stored && changed) {
|
|
@@ -17056,6 +17249,35 @@ var Client = class _Client {
|
|
|
17056
17249
|
storedSwaps.push(stored);
|
|
17057
17250
|
}
|
|
17058
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
|
+
}
|
|
17059
17281
|
const currentKeyIndex = await this.getKeyIndex();
|
|
17060
17282
|
const nextKeyIndex = Math.max(currentKeyIndex, data.next_index);
|
|
17061
17283
|
if (nextKeyIndex !== currentKeyIndex) {
|
|
@@ -17221,15 +17443,15 @@ var Client = class _Client {
|
|
|
17221
17443
|
message: "Gasless claim failed: no target address found. This swap may have been created before target address storage was implemented."
|
|
17222
17444
|
};
|
|
17223
17445
|
}
|
|
17224
|
-
const bridgeRecipient = _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
17225
|
-
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;
|
|
17226
17448
|
if (isSolanaBridge && !bridgeRecipient) {
|
|
17227
17449
|
return {
|
|
17228
17450
|
success: false,
|
|
17229
17451
|
message: "Solana bridge claim requires `bridgeRecipient` (the recipient's USDC ATA) in claim options. Derive it via `deriveSolanaUsdcAta` before calling claim."
|
|
17230
17452
|
};
|
|
17231
17453
|
}
|
|
17232
|
-
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, {
|
|
17233
17455
|
bridgeRecipient,
|
|
17234
17456
|
bridgeRecipientWallet
|
|
17235
17457
|
}) : await this.claimViaGasless(id, destination, {
|
|
@@ -17561,7 +17783,7 @@ var Client = class _Client {
|
|
|
17561
17783
|
const targetTokenAddress = String(swap.target_token.token_id);
|
|
17562
17784
|
const needsDexSwap = targetTokenAddress.toLowerCase() !== swap.wbtc_address.toLowerCase();
|
|
17563
17785
|
let dexCalldata;
|
|
17564
|
-
if (needsDexSwap && _optionalChain([responseData, 'optionalAccess',
|
|
17786
|
+
if (needsDexSwap && _optionalChain([responseData, 'optionalAccess', _219 => _219.dex_calldata])) {
|
|
17565
17787
|
dexCalldata = {
|
|
17566
17788
|
to: responseData.dex_calldata.to,
|
|
17567
17789
|
data: responseData.dex_calldata.data,
|
|
@@ -17609,7 +17831,7 @@ var Client = class _Client {
|
|
|
17609
17831
|
* ```
|
|
17610
17832
|
*/
|
|
17611
17833
|
async claimArkade(id, options) {
|
|
17612
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
17834
|
+
if (!_optionalChain([options, 'optionalAccess', _220 => _220.destinationAddress])) {
|
|
17613
17835
|
return {
|
|
17614
17836
|
success: false,
|
|
17615
17837
|
message: 'Destination address is required for Arkade claims. Provide it via the options parameter: { destinationAddress: "ark1..." }'
|
|
@@ -17695,7 +17917,7 @@ var Client = class _Client {
|
|
|
17695
17917
|
electrum,
|
|
17696
17918
|
fundTxid
|
|
17697
17919
|
);
|
|
17698
|
-
if (_optionalChain([txData, 'optionalAccess',
|
|
17920
|
+
if (_optionalChain([txData, 'optionalAccess', _221 => _221.vout, 'optionalAccess', _222 => _222[fundVout]])) {
|
|
17699
17921
|
return {
|
|
17700
17922
|
txid: fundTxid,
|
|
17701
17923
|
vout: fundVout,
|
|
@@ -17731,7 +17953,7 @@ var Client = class _Client {
|
|
|
17731
17953
|
async #findOnchainHtlcOutputEsplora(esploraUrls, address2, fundTxid, fundVout) {
|
|
17732
17954
|
if (fundTxid && fundVout !== void 0) {
|
|
17733
17955
|
const txData = await fetchTransactionOutputs(esploraUrls, fundTxid);
|
|
17734
|
-
if (_optionalChain([txData, 'optionalAccess',
|
|
17956
|
+
if (_optionalChain([txData, 'optionalAccess', _223 => _223.vout, 'optionalAccess', _224 => _224[fundVout]])) {
|
|
17735
17957
|
return {
|
|
17736
17958
|
txid: fundTxid,
|
|
17737
17959
|
vout: fundVout,
|
|
@@ -17886,8 +18108,8 @@ var Client = class _Client {
|
|
|
17886
18108
|
try {
|
|
17887
18109
|
const result = await continueArkadeClaim({
|
|
17888
18110
|
...claimParams,
|
|
17889
|
-
destinationAddress: _optionalChain([options, 'optionalAccess',
|
|
17890
|
-
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)),
|
|
17891
18113
|
logger: this.#config.logger,
|
|
17892
18114
|
logLevel: this.#config.logLevel
|
|
17893
18115
|
});
|
|
@@ -18005,7 +18227,7 @@ var Client = class _Client {
|
|
|
18005
18227
|
*/
|
|
18006
18228
|
async #claimArkadeDelegate(swapId, params, options) {
|
|
18007
18229
|
try {
|
|
18008
|
-
const result = await
|
|
18230
|
+
const result = await _chunkLZQZYSOZcjs.delegateClaim.call(void 0, {
|
|
18009
18231
|
...params,
|
|
18010
18232
|
destinationAddress: options.destinationAddress,
|
|
18011
18233
|
lendaswapApiUrl: this.#config.baseUrl,
|
|
@@ -18078,10 +18300,10 @@ var Client = class _Client {
|
|
|
18078
18300
|
}
|
|
18079
18301
|
if (direction === "evm_to_arkade" || direction === "evm_to_bitcoin" || direction === "evm_to_lightning") {
|
|
18080
18302
|
const evmOptions = options;
|
|
18081
|
-
if (_optionalChain([evmOptions, 'optionalAccess',
|
|
18303
|
+
if (_optionalChain([evmOptions, 'optionalAccess', _227 => _227.collaborative])) {
|
|
18082
18304
|
return this.#collabRefundEvm(id);
|
|
18083
18305
|
}
|
|
18084
|
-
return this.#buildEvmSourceRefund(id, storedSwap, _optionalChain([evmOptions, 'optionalAccess',
|
|
18306
|
+
return this.#buildEvmSourceRefund(id, storedSwap, _optionalChain([evmOptions, 'optionalAccess', _228 => _228.signer]));
|
|
18085
18307
|
}
|
|
18086
18308
|
return {
|
|
18087
18309
|
success: false,
|
|
@@ -18175,7 +18397,7 @@ var Client = class _Client {
|
|
|
18175
18397
|
}
|
|
18176
18398
|
const btcFundTxid = swap.btc_fund_txid;
|
|
18177
18399
|
const btcFundVout = swap.btc_fund_vout;
|
|
18178
|
-
const waitForFundingMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
18400
|
+
const waitForFundingMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _229 => _229.waitForFundingMs]), () => ( 3e4));
|
|
18179
18401
|
const htlcOutput = await this.#waitForOnchainHtlcOutput(
|
|
18180
18402
|
esploraUrls,
|
|
18181
18403
|
network,
|
|
@@ -18190,16 +18412,51 @@ var Client = class _Client {
|
|
|
18190
18412
|
message: `Could not find UTXO at HTLC address ${btcHtlcAddress} after waiting ${waitForFundingMs}ms. The server may not have funded the HTLC yet.`
|
|
18191
18413
|
};
|
|
18192
18414
|
}
|
|
18193
|
-
const
|
|
18194
|
-
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) {
|
|
18195
18424
|
return {
|
|
18196
18425
|
success: false,
|
|
18197
18426
|
message: 'Destination address is required to claim BTC. Provide it via options: { destinationAddress: "bc1p..." }'
|
|
18198
18427
|
};
|
|
18199
18428
|
}
|
|
18200
|
-
|
|
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
|
+
}
|
|
18201
18457
|
try {
|
|
18202
18458
|
const result = buildOnchainClaimTransaction({
|
|
18459
|
+
bitcoinPayout,
|
|
18203
18460
|
fundingTxId: htlcOutput.txid,
|
|
18204
18461
|
fundingVout: htlcOutput.vout,
|
|
18205
18462
|
htlcAmount: htlcOutput.amount,
|
|
@@ -18209,17 +18466,26 @@ var Client = class _Client {
|
|
|
18209
18466
|
userSecretKey: storedSwap.secretKey,
|
|
18210
18467
|
preimage: storedSwap.preimage,
|
|
18211
18468
|
refundLocktime: btcRefundLocktime,
|
|
18212
|
-
|
|
18469
|
+
// Unused when a payout is stored; checked above otherwise.
|
|
18470
|
+
destinationAddress: _nullishCoalesce(destinationAddress, () => ( "")),
|
|
18213
18471
|
feeRateSatPerVb,
|
|
18214
18472
|
network,
|
|
18215
18473
|
btcHtlcScriptVersion
|
|
18216
18474
|
});
|
|
18217
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
|
+
}
|
|
18218
18484
|
await this.#broadcastBtcTx(
|
|
18219
18485
|
esploraUrls,
|
|
18220
18486
|
network,
|
|
18221
18487
|
result.txHex,
|
|
18222
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
18488
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _235 => _235.broadcastRetries]), () => ( 5))
|
|
18223
18489
|
);
|
|
18224
18490
|
return {
|
|
18225
18491
|
success: true,
|
|
@@ -18249,7 +18515,7 @@ var Client = class _Client {
|
|
|
18249
18515
|
* @internal
|
|
18250
18516
|
*/
|
|
18251
18517
|
async #buildOnchainRefund(id, swap, options) {
|
|
18252
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
18518
|
+
if (!_optionalChain([options, 'optionalAccess', _236 => _236.destinationAddress])) {
|
|
18253
18519
|
return {
|
|
18254
18520
|
success: false,
|
|
18255
18521
|
message: 'Destination address is required for on-chain refunds. Provide it via the options parameter: { destinationAddress: "bc1q..." }'
|
|
@@ -18455,7 +18721,7 @@ network='${network}'`
|
|
|
18455
18721
|
* @internal
|
|
18456
18722
|
*/
|
|
18457
18723
|
async #buildArkadeRefund(id, swap, options) {
|
|
18458
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
18724
|
+
if (!_optionalChain([options, 'optionalAccess', _237 => _237.destinationAddress])) {
|
|
18459
18725
|
return {
|
|
18460
18726
|
success: false,
|
|
18461
18727
|
message: 'Destination address is required for Arkade refunds. Provide it via the options parameter: { destinationAddress: "ark1..." }'
|
|
@@ -18596,7 +18862,7 @@ network='${network}'`
|
|
|
18596
18862
|
*/
|
|
18597
18863
|
async #refundArkadeDelegate(params, options) {
|
|
18598
18864
|
try {
|
|
18599
|
-
const result = await
|
|
18865
|
+
const result = await _chunkLZQZYSOZcjs.delegateRefund.call(void 0, {
|
|
18600
18866
|
...params,
|
|
18601
18867
|
lendaswapApiUrl: this.#config.baseUrl,
|
|
18602
18868
|
arkadeServerUrl: _nullishCoalesce(options.arkadeServerUrl, () => ( this.#config.arkadeServerUrl)),
|
|
@@ -18691,7 +18957,7 @@ network='${network}'`
|
|
|
18691
18957
|
const call = decodeRefundCall(server.data);
|
|
18692
18958
|
const to = server.to.toLowerCase();
|
|
18693
18959
|
const htlc = leg.htlcAddress.toLowerCase();
|
|
18694
|
-
const coordinator = _optionalChain([leg, 'access',
|
|
18960
|
+
const coordinator = _optionalChain([leg, 'access', _238 => _238.coordinatorAddress, 'optionalAccess', _239 => _239.toLowerCase, 'call', _240 => _240()]);
|
|
18695
18961
|
const signer = check.signer;
|
|
18696
18962
|
let lockSender;
|
|
18697
18963
|
let recipient;
|
|
@@ -18712,7 +18978,7 @@ network='${network}'`
|
|
|
18712
18978
|
`The server's refund targets ${server.to}, not this swap's HTLC ${leg.htlcAddress}`
|
|
18713
18979
|
);
|
|
18714
18980
|
}
|
|
18715
|
-
lockSender = _optionalChain([signer, 'optionalAccess',
|
|
18981
|
+
lockSender = _optionalChain([signer, 'optionalAccess', _241 => _241.address, 'access', _242 => _242.toLowerCase, 'call', _243 => _243()]);
|
|
18716
18982
|
recipient = lockSender;
|
|
18717
18983
|
break;
|
|
18718
18984
|
case "refundTo":
|
|
@@ -18743,7 +19009,7 @@ network='${network}'`
|
|
|
18743
19009
|
const read = async (tx, what) => {
|
|
18744
19010
|
try {
|
|
18745
19011
|
return decodeCallWord(await signer.call(tx), what);
|
|
18746
|
-
} catch (
|
|
19012
|
+
} catch (e25) {
|
|
18747
19013
|
return void 0;
|
|
18748
19014
|
}
|
|
18749
19015
|
};
|
|
@@ -18757,7 +19023,7 @@ network='${network}'`
|
|
|
18757
19023
|
timelock: call.timelock
|
|
18758
19024
|
};
|
|
18759
19025
|
const active = await read(
|
|
18760
|
-
|
|
19026
|
+
_chunkEI5ILLQ3cjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms),
|
|
18761
19027
|
"isActive"
|
|
18762
19028
|
);
|
|
18763
19029
|
if (active === 0n) {
|
|
@@ -18767,7 +19033,7 @@ network='${network}'`
|
|
|
18767
19033
|
}
|
|
18768
19034
|
if (call.kind === "refundTo" || call.kind === "nativeRefundTo") {
|
|
18769
19035
|
const deposit = await read(
|
|
18770
|
-
|
|
19036
|
+
_chunkEI5ILLQ3cjs.encodeDepositsCallData.call(void 0, to, _chunkEI5ILLQ3cjs.htlcSwapKey.call(void 0, terms)),
|
|
18771
19037
|
"deposits"
|
|
18772
19038
|
);
|
|
18773
19039
|
if (deposit !== void 0) {
|
|
@@ -18808,10 +19074,10 @@ network='${network}'`
|
|
|
18808
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.`
|
|
18809
19075
|
);
|
|
18810
19076
|
}
|
|
18811
|
-
return `0x${
|
|
19077
|
+
return `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, stored.lightningPaymentHash.hash)}`;
|
|
18812
19078
|
}
|
|
18813
19079
|
if (direction === "evm_to_bitcoin" || direction === "evm_to_arkade") {
|
|
18814
|
-
return `0x${
|
|
19080
|
+
return `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, stored.preimageHash)}`;
|
|
18815
19081
|
}
|
|
18816
19082
|
throw new Error(`Swap ${swapId} is ${direction}, not EVM-sourced`);
|
|
18817
19083
|
}
|
|
@@ -18831,7 +19097,7 @@ network='${network}'`
|
|
|
18831
19097
|
}
|
|
18832
19098
|
#fundingExpectation(swapId, stored) {
|
|
18833
19099
|
const hashLock = this.#clientHashLock(swapId, stored);
|
|
18834
|
-
const terms = _optionalChain([stored, 'optionalAccess',
|
|
19100
|
+
const terms = _optionalChain([stored, 'optionalAccess', _244 => _244.evmFundingTerms]);
|
|
18835
19101
|
if (!terms) {
|
|
18836
19102
|
throw new Error(
|
|
18837
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.`
|
|
@@ -18858,7 +19124,7 @@ network='${network}'`
|
|
|
18858
19124
|
`Swap ${swapId} locks on chain ${terms.chainId}, not ${chainId}`
|
|
18859
19125
|
);
|
|
18860
19126
|
}
|
|
18861
|
-
return
|
|
19127
|
+
return _chunkEI5ILLQ3cjs.checkFundingPayload.call(void 0, terms, hashLock, payload, pins);
|
|
18862
19128
|
}
|
|
18863
19129
|
/** Throws unless `hash` is the one {@link #clientHashLock} fixed. */
|
|
18864
19130
|
async #ensureClientHashLock(swapId, hash, what) {
|
|
@@ -18866,7 +19132,7 @@ network='${network}'`
|
|
|
18866
19132
|
swapId,
|
|
18867
19133
|
await this.getStoredSwap(swapId)
|
|
18868
19134
|
);
|
|
18869
|
-
if (`0x${
|
|
19135
|
+
if (`0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, hash)}` !== expected) {
|
|
18870
19136
|
throw new Error(
|
|
18871
19137
|
`The server's ${what} locks under hash ${hash}, not this swap's ${expected}; refusing to sign or send it`
|
|
18872
19138
|
);
|
|
@@ -18904,7 +19170,7 @@ network='${network}'`
|
|
|
18904
19170
|
if (!this.#swapStorage) return;
|
|
18905
19171
|
try {
|
|
18906
19172
|
const stored = await this.#swapStorage.get(swapId);
|
|
18907
|
-
if (_optionalChain([stored, 'optionalAccess',
|
|
19173
|
+
if (_optionalChain([stored, 'optionalAccess', _245 => _245.evmFundTxid, 'optionalAccess', _246 => _246.toLowerCase, 'call', _247 => _247()]) !== txid.toLowerCase()) return;
|
|
18908
19174
|
await this.#swapStorage.store({
|
|
18909
19175
|
...stored,
|
|
18910
19176
|
evmFundTxid: void 0,
|
|
@@ -18928,16 +19194,29 @@ network='${network}'`
|
|
|
18928
19194
|
* browser wallet usually cannot. Otherwise the wallet itself is the owner.
|
|
18929
19195
|
* `hint` is appended to the error when neither is.
|
|
18930
19196
|
*/
|
|
18931
|
-
#depositorOwnerSigner(swapResponse, walletSigner, hint) {
|
|
18932
|
-
const
|
|
18933
|
-
|
|
18934
|
-
|
|
18935
|
-
}
|
|
18936
|
-
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())
|
|
18937
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) {
|
|
18938
19217
|
}
|
|
18939
19218
|
throw new Error(
|
|
18940
|
-
`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}` : ""}`
|
|
18941
19220
|
);
|
|
18942
19221
|
}
|
|
18943
19222
|
/**
|
|
@@ -19001,7 +19280,7 @@ network='${network}'`
|
|
|
19001
19280
|
stored.secretKey ? deriveEvmAddress(stored.secretKey) : void 0
|
|
19002
19281
|
]);
|
|
19003
19282
|
const expectedDepositors = uniqueAddresses([
|
|
19004
|
-
_optionalChain([signer, 'optionalAccess',
|
|
19283
|
+
_optionalChain([signer, 'optionalAccess', _252 => _252.address]),
|
|
19005
19284
|
...sdkAddresses,
|
|
19006
19285
|
stored.response.client_evm_address
|
|
19007
19286
|
]);
|
|
@@ -19027,7 +19306,7 @@ network='${network}'`
|
|
|
19027
19306
|
expectedDepositors
|
|
19028
19307
|
});
|
|
19029
19308
|
const coordinatorProved = !leg.depositorIsSender && refund.sender !== signer.address.toLowerCase() && stored.evmCoordinatorAddress === void 0;
|
|
19030
|
-
if (fundTxid.toLowerCase() !== _optionalChain([stored, 'access',
|
|
19309
|
+
if (fundTxid.toLowerCase() !== _optionalChain([stored, 'access', _253 => _253.evmFundTxid, 'optionalAccess', _254 => _254.toLowerCase, 'call', _255 => _255()]) || coordinatorProved) {
|
|
19031
19310
|
await this.#recordEvmFunding(id, {
|
|
19032
19311
|
txid: fundTxid,
|
|
19033
19312
|
coordinatorAddress: coordinatorProved ? refund.sender : void 0
|
|
@@ -19086,7 +19365,7 @@ network='${network}'`
|
|
|
19086
19365
|
async #serverFundTxid(id) {
|
|
19087
19366
|
const fresh = await this.getSwap(id);
|
|
19088
19367
|
try {
|
|
19089
|
-
await _optionalChain([this, 'access',
|
|
19368
|
+
await _optionalChain([this, 'access', _256 => _256.#swapStorage, 'optionalAccess', _257 => _257.update, 'call', _258 => _258(id, fresh)]);
|
|
19090
19369
|
} catch (error) {
|
|
19091
19370
|
this.#logger.warn({
|
|
19092
19371
|
event: "client.refundSwap.refreshNotStored",
|
|
@@ -19099,7 +19378,7 @@ network='${network}'`
|
|
|
19099
19378
|
}
|
|
19100
19379
|
async #refundFromFundingTx(signer, leg) {
|
|
19101
19380
|
const self2 = signer.address.toLowerCase();
|
|
19102
|
-
const coordinator = _optionalChain([leg, 'access',
|
|
19381
|
+
const coordinator = _optionalChain([leg, 'access', _259 => _259.coordinatorAddress, 'optionalAccess', _260 => _260.toLowerCase, 'call', _261 => _261()]);
|
|
19103
19382
|
const senders = leg.depositorIsSender ? uniqueAddresses([self2, ...leg.expectedDepositors]) : coordinator === void 0 ? void 0 : [self2, coordinator];
|
|
19104
19383
|
const { created, terms, hashLock } = await this.#lockFromFundingTx(signer, {
|
|
19105
19384
|
...leg,
|
|
@@ -19107,14 +19386,14 @@ network='${network}'`
|
|
|
19107
19386
|
});
|
|
19108
19387
|
const active = decodeCallWord(
|
|
19109
19388
|
await signer.call(
|
|
19110
|
-
|
|
19389
|
+
_chunkEI5ILLQ3cjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms)
|
|
19111
19390
|
),
|
|
19112
19391
|
"isActive"
|
|
19113
19392
|
);
|
|
19114
19393
|
if (active === 0n) {
|
|
19115
19394
|
await this.#ensureSettled(signer, leg.htlcAddress, terms);
|
|
19116
19395
|
}
|
|
19117
|
-
const native = created.token ===
|
|
19396
|
+
const native = created.token === _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
|
|
19118
19397
|
if (leg.depositorIsSender) {
|
|
19119
19398
|
const { to: to2, data: data2 } = encodeRefundCall(leg.htlcAddress, {
|
|
19120
19399
|
kind: native ? "nativeRefundFor" : "refundFor",
|
|
@@ -19143,7 +19422,7 @@ network='${network}'`
|
|
|
19143
19422
|
if (!ownHtlc) {
|
|
19144
19423
|
const deposit = decodeCallWord(
|
|
19145
19424
|
await signer.call(
|
|
19146
|
-
|
|
19425
|
+
_chunkEI5ILLQ3cjs.encodeDepositsCallData.call(void 0, created.refundAddress, created.key)
|
|
19147
19426
|
),
|
|
19148
19427
|
"deposits"
|
|
19149
19428
|
);
|
|
@@ -19160,7 +19439,7 @@ network='${network}'`
|
|
|
19160
19439
|
}
|
|
19161
19440
|
recipient = depositor;
|
|
19162
19441
|
}
|
|
19163
|
-
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);
|
|
19164
19443
|
return {
|
|
19165
19444
|
to,
|
|
19166
19445
|
data,
|
|
@@ -19177,7 +19456,7 @@ network='${network}'`
|
|
|
19177
19456
|
let known;
|
|
19178
19457
|
try {
|
|
19179
19458
|
known = await signer.getTransaction(leg.fundTxid);
|
|
19180
|
-
} catch (
|
|
19459
|
+
} catch (e27) {
|
|
19181
19460
|
known = null;
|
|
19182
19461
|
}
|
|
19183
19462
|
if (!known) {
|
|
@@ -19207,8 +19486,8 @@ network='${network}'`
|
|
|
19207
19486
|
"Reading the lock from the chain needs the funding receipt's logs, which this signer's waitForReceipt does not return"
|
|
19208
19487
|
);
|
|
19209
19488
|
}
|
|
19210
|
-
const hashLock = `0x${
|
|
19211
|
-
const matches =
|
|
19489
|
+
const hashLock = `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, leg.hashLock)}`;
|
|
19490
|
+
const matches = _chunkEI5ILLQ3cjs.findSwapCreated.call(void 0, receipt.logs, {
|
|
19212
19491
|
htlcAddress: leg.htlcAddress,
|
|
19213
19492
|
hashLock,
|
|
19214
19493
|
claimAddress: leg.claimAddress,
|
|
@@ -19241,13 +19520,13 @@ network='${network}'`
|
|
|
19241
19520
|
*/
|
|
19242
19521
|
async #ensureSettled(signer, htlcAddress2, terms) {
|
|
19243
19522
|
const state = await this.#swapState(signer, htlcAddress2, terms.key);
|
|
19244
|
-
if (state === void 0 || state ===
|
|
19523
|
+
if (state === void 0 || state === _chunkEI5ILLQ3cjs.HTLC_SWAP_STATE.Redeemed || state === _chunkEI5ILLQ3cjs.HTLC_SWAP_STATE.Refunded) {
|
|
19245
19524
|
throw new HtlcNotActiveError(
|
|
19246
19525
|
`The HTLC for hash lock ${terms.preimageHash} on ${htlcAddress2} is no longer active; it was already redeemed or refunded`
|
|
19247
19526
|
);
|
|
19248
19527
|
}
|
|
19249
19528
|
throw new Error(
|
|
19250
|
-
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`
|
|
19251
19530
|
);
|
|
19252
19531
|
}
|
|
19253
19532
|
/**
|
|
@@ -19257,10 +19536,10 @@ network='${network}'`
|
|
|
19257
19536
|
async #swapState(signer, htlcAddress2, key) {
|
|
19258
19537
|
try {
|
|
19259
19538
|
return decodeCallWord(
|
|
19260
|
-
await signer.call(
|
|
19539
|
+
await signer.call(_chunkEI5ILLQ3cjs.encodeHtlcSwapsCallData.call(void 0, htlcAddress2, key)),
|
|
19261
19540
|
"swaps"
|
|
19262
19541
|
);
|
|
19263
|
-
} catch (
|
|
19542
|
+
} catch (e28) {
|
|
19264
19543
|
return void 0;
|
|
19265
19544
|
}
|
|
19266
19545
|
}
|
|
@@ -19292,12 +19571,12 @@ network='${network}'`
|
|
|
19292
19571
|
`Rehash tx ${txid} has no readable logs, so the lock's current terms cannot be verified from the chain`
|
|
19293
19572
|
);
|
|
19294
19573
|
}
|
|
19295
|
-
const moved =
|
|
19574
|
+
const moved = _chunkEI5ILLQ3cjs.findSwapRehashed.call(void 0, receipt.logs, {
|
|
19296
19575
|
htlcAddress: htlcAddress2,
|
|
19297
19576
|
key: terms.key
|
|
19298
19577
|
});
|
|
19299
19578
|
if (moved.length === 0) continue;
|
|
19300
|
-
const hashLock = `0x${
|
|
19579
|
+
const hashLock = `0x${_chunkEI5ILLQ3cjs.normalizeBytes32.call(void 0, rehash.hashLock)}`;
|
|
19301
19580
|
if (moved.length !== 1 || moved[0].newPreimageHash !== hashLock) {
|
|
19302
19581
|
throw new Error(
|
|
19303
19582
|
`Rehash tx ${txid} moved the HTLC for hash lock ${terms.preimageHash} elsewhere than the recorded ${hashLock}`
|
|
@@ -19421,8 +19700,8 @@ network='${network}'`
|
|
|
19421
19700
|
callsHash: params.callsHash,
|
|
19422
19701
|
coordinatorVersion: params.coordinatorVersion
|
|
19423
19702
|
};
|
|
19424
|
-
const typedData =
|
|
19425
|
-
const digest =
|
|
19703
|
+
const typedData = _chunkEI5ILLQ3cjs.buildCollabRefundEvmTypedData.call(void 0, digestParams);
|
|
19704
|
+
const digest = _chunkEI5ILLQ3cjs.buildCollabRefundEvmDigest.call(void 0, digestParams);
|
|
19426
19705
|
return { typedData, digest, params };
|
|
19427
19706
|
}
|
|
19428
19707
|
/**
|
|
@@ -19437,12 +19716,12 @@ network='${network}'`
|
|
|
19437
19716
|
*/
|
|
19438
19717
|
async collabRefundEvmSwap(swapId) {
|
|
19439
19718
|
const storedSwap = await this.getStoredSwap(swapId);
|
|
19440
|
-
if (!_optionalChain([storedSwap, 'optionalAccess',
|
|
19719
|
+
if (!_optionalChain([storedSwap, 'optionalAccess', _262 => _262.secretKey])) {
|
|
19441
19720
|
throw new Error(
|
|
19442
19721
|
"No secret key found for this swap. Cannot sign collab refund."
|
|
19443
19722
|
);
|
|
19444
19723
|
}
|
|
19445
|
-
const evmKey = this.#getCollabRefundEvmSigningKey(storedSwap);
|
|
19724
|
+
const evmKey = await this.#getCollabRefundEvmSigningKey(storedSwap);
|
|
19446
19725
|
const { digest, params } = await this.buildCollabRefundEvmTypedData(swapId);
|
|
19447
19726
|
if (params.refundPath === "direct") {
|
|
19448
19727
|
return this.#collabRefundEvmSponsored(swapId, params, evmKey);
|
|
@@ -19579,7 +19858,7 @@ network='${network}'`
|
|
|
19579
19858
|
entryPointVersion: entryPoint.version,
|
|
19580
19859
|
userOperation: signed
|
|
19581
19860
|
});
|
|
19582
|
-
} catch (
|
|
19861
|
+
} catch (e29) {
|
|
19583
19862
|
computed = void 0;
|
|
19584
19863
|
}
|
|
19585
19864
|
await hooks.onSigned(computed);
|
|
@@ -19596,11 +19875,11 @@ network='${network}'`
|
|
|
19596
19875
|
} else {
|
|
19597
19876
|
userOpHash = await client.sendUserOperation({ calls });
|
|
19598
19877
|
}
|
|
19599
|
-
await _optionalChain([hooks, 'access',
|
|
19878
|
+
await _optionalChain([hooks, 'access', _263 => _263.onSubmitted, 'optionalCall', _264 => _264(userOpHash)]);
|
|
19600
19879
|
const { receipt, success, reason } = await client.waitForUserOperationReceipt({
|
|
19601
19880
|
hash: userOpHash
|
|
19602
19881
|
});
|
|
19603
|
-
await _optionalChain([hooks, 'access',
|
|
19882
|
+
await _optionalChain([hooks, 'access', _265 => _265.onIncluded, 'optionalCall', _266 => _266(receipt.transactionHash, userOpHash)]);
|
|
19604
19883
|
if (!success) {
|
|
19605
19884
|
throw new Error(
|
|
19606
19885
|
`Sponsored UserOp ${userOpHash} reverted on-chain${reason ? `: ${reason}` : ""}`
|
|
@@ -19821,7 +20100,7 @@ network='${network}'`
|
|
|
19821
20100
|
* no AA config, not included, or the bundler cannot be reached).
|
|
19822
20101
|
*/
|
|
19823
20102
|
async #pendingRehashTx(rehash) {
|
|
19824
|
-
const bundlerUrl = _optionalChain([this, 'access',
|
|
20103
|
+
const bundlerUrl = _optionalChain([this, 'access', _267 => _267.#config, 'access', _268 => _268.aa, 'optionalAccess', _269 => _269.bundlerUrl]);
|
|
19825
20104
|
if (!rehash.userOpHash || !bundlerUrl) return void 0;
|
|
19826
20105
|
try {
|
|
19827
20106
|
const response = await fetch(bundlerUrl, {
|
|
@@ -19835,8 +20114,8 @@ network='${network}'`
|
|
|
19835
20114
|
})
|
|
19836
20115
|
});
|
|
19837
20116
|
const json = await response.json();
|
|
19838
|
-
return _nullishCoalesce(_optionalChain([json, 'access',
|
|
19839
|
-
} catch (
|
|
20117
|
+
return _nullishCoalesce(_optionalChain([json, 'access', _270 => _270.result, 'optionalAccess', _271 => _271.receipt, 'optionalAccess', _272 => _272.transactionHash]), () => ( void 0));
|
|
20118
|
+
} catch (e30) {
|
|
19840
20119
|
return void 0;
|
|
19841
20120
|
}
|
|
19842
20121
|
}
|
|
@@ -19845,7 +20124,7 @@ network='${network}'`
|
|
|
19845
20124
|
if (!this.#swapStorage) return;
|
|
19846
20125
|
try {
|
|
19847
20126
|
const stored = await this.#swapStorage.get(swapId);
|
|
19848
|
-
const history = _optionalChain([stored, 'optionalAccess',
|
|
20127
|
+
const history = _optionalChain([stored, 'optionalAccess', _273 => _273.evmRehashes]);
|
|
19849
20128
|
if (!stored || !history) return;
|
|
19850
20129
|
let index = -1;
|
|
19851
20130
|
for (let i = history.length - 1; i >= 0; i--) {
|
|
@@ -19896,8 +20175,8 @@ network='${network}'`
|
|
|
19896
20175
|
}
|
|
19897
20176
|
const ownHash = this.#clientHashLock(swapId, stored);
|
|
19898
20177
|
const leg = evmSourceLeg(stored);
|
|
19899
|
-
const firstFrom = _optionalChain([leg, 'access',
|
|
19900
|
-
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) {
|
|
19901
20180
|
throw new Error(
|
|
19902
20181
|
`The rehash history of swap ${swapId} starts from ${firstFrom}, not from the payment hash this client fixed (${ownHash})`
|
|
19903
20182
|
);
|
|
@@ -19922,7 +20201,7 @@ network='${network}'`
|
|
|
19922
20201
|
});
|
|
19923
20202
|
const active = decodeCallWord(
|
|
19924
20203
|
await reader.call(
|
|
19925
|
-
|
|
20204
|
+
_chunkEI5ILLQ3cjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms)
|
|
19926
20205
|
),
|
|
19927
20206
|
"isActive"
|
|
19928
20207
|
);
|
|
@@ -19955,7 +20234,7 @@ network='${network}'`
|
|
|
19955
20234
|
* does not read the chain. Arbitrum only, like the paymaster.
|
|
19956
20235
|
*/
|
|
19957
20236
|
async #aaChainReader(owner) {
|
|
19958
|
-
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])));
|
|
19959
20238
|
if (!rpcUrl) {
|
|
19960
20239
|
throw new Error(
|
|
19961
20240
|
"A sponsored rehash reads the lock over the AA RPC; call `.withAa({ bundlerUrl, paymasterPolicyId })` on the ClientBuilder before `.build()`."
|
|
@@ -20006,12 +20285,12 @@ network='${network}'`
|
|
|
20006
20285
|
*/
|
|
20007
20286
|
async retrySwapWithInvoice(swapId, invoice) {
|
|
20008
20287
|
const storedSwap = await this.getStoredSwap(swapId);
|
|
20009
|
-
if (!_optionalChain([storedSwap, 'optionalAccess',
|
|
20288
|
+
if (!_optionalChain([storedSwap, 'optionalAccess', _283 => _283.secretKey])) {
|
|
20010
20289
|
throw new Error(
|
|
20011
20290
|
"No secret key found for this swap. Cannot authorize the rehash."
|
|
20012
20291
|
);
|
|
20013
20292
|
}
|
|
20014
|
-
const evmKey = this.#getCollabRefundEvmSigningKey(
|
|
20293
|
+
const evmKey = await this.#getCollabRefundEvmSigningKey(
|
|
20015
20294
|
storedSwap,
|
|
20016
20295
|
"retrySwapWithInvoiceWithSigner"
|
|
20017
20296
|
);
|
|
@@ -20039,8 +20318,8 @@ network='${network}'`
|
|
|
20039
20318
|
});
|
|
20040
20319
|
ensureRehashMatchesRequest(signature, paymentHash, params);
|
|
20041
20320
|
ensureLockIsOwn(lock, signature, "The server signed a rehash of");
|
|
20042
|
-
const newHash = `0x${
|
|
20043
|
-
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;
|
|
20044
20323
|
await this.#recordEvmRehash(swapId, signature, "");
|
|
20045
20324
|
let sending = false;
|
|
20046
20325
|
let signedHash;
|
|
@@ -20158,25 +20437,37 @@ network='${network}'`
|
|
|
20158
20437
|
updatedAt: Date.now(),
|
|
20159
20438
|
// The payout this client asked for; claims pay here, never to a
|
|
20160
20439
|
// server answer. Recovery rebuilding the swap keeps it.
|
|
20161
|
-
targetAddress: _nullishCoalesce(targetAddress, () => ( _optionalChain([existing, 'optionalAccess',
|
|
20162
|
-
|
|
20163
|
-
|
|
20164
|
-
|
|
20165
|
-
|
|
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]),
|
|
20166
20452
|
// Fixed at creation and never taken from a server answer: recovery
|
|
20167
20453
|
// rebuilding the swap keeps it, and a fresh device has none.
|
|
20168
|
-
lightningPaymentHash: _nullishCoalesce(_optionalChain([commitments, 'optionalAccess',
|
|
20169
|
-
evmFundingTerms: _nullishCoalesce(_optionalChain([commitments, 'optionalAccess',
|
|
20170
|
-
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]),
|
|
20171
20457
|
// The rehashes this client sent are what let a refund find the lock
|
|
20172
20458
|
// that exists; the server's copy names only the current hash.
|
|
20173
|
-
evmRehashes: _optionalChain([existing, 'optionalAccess',
|
|
20459
|
+
evmRehashes: _optionalChain([existing, 'optionalAccess', _302 => _302.evmRehashes]),
|
|
20174
20460
|
// A CCTP-inbound burn is the only way to resume or recover once the
|
|
20175
20461
|
// USDC has left the source chain.
|
|
20176
|
-
cctpBurnTxid: _optionalChain([existing, 'optionalAccess',
|
|
20177
|
-
cctpBurnLastValidBlockHeight: _optionalChain([existing, 'optionalAccess',
|
|
20462
|
+
cctpBurnTxid: _optionalChain([existing, 'optionalAccess', _303 => _303.cctpBurnTxid]),
|
|
20463
|
+
cctpBurnLastValidBlockHeight: _optionalChain([existing, 'optionalAccess', _304 => _304.cctpBurnLastValidBlockHeight])
|
|
20178
20464
|
};
|
|
20179
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
|
+
}
|
|
20180
20471
|
}
|
|
20181
20472
|
/**
|
|
20182
20473
|
* Creates a swap by routing to the correct direction-specific method
|
|
@@ -20214,9 +20505,13 @@ network='${network}'`
|
|
|
20214
20505
|
}
|
|
20215
20506
|
const sourceAsset = "token_id" in src ? { chain: src.chain, token_id: src.token_id } : { chain: src.chain, token_id: src.tokenId };
|
|
20216
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
|
+
);
|
|
20217
20512
|
if (isTronToken(sourceAsset.chain))
|
|
20218
20513
|
throw new Error("Tron is a payout-only destination");
|
|
20219
|
-
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";
|
|
20220
20515
|
if (isTronTarget) {
|
|
20221
20516
|
if (isTronToken(targetAsset.chain) && targetAsset.token_id !== USDT0_ADDRESSES.Tron) {
|
|
20222
20517
|
throw new Error("Tron payouts require native USDT");
|
|
@@ -20256,7 +20551,7 @@ network='${network}'`
|
|
|
20256
20551
|
if (isTronTarget && bridgeParams) {
|
|
20257
20552
|
bridgeParams = { ...bridgeParams, recipient: options.targetAddress };
|
|
20258
20553
|
}
|
|
20259
|
-
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()]);
|
|
20260
20555
|
if (cctpPayout && options.sourceAmount != null) {
|
|
20261
20556
|
const quote = await this.getQuote({
|
|
20262
20557
|
sourceChain: sourceAsset.chain,
|
|
@@ -20271,7 +20566,7 @@ network='${network}'`
|
|
|
20271
20566
|
});
|
|
20272
20567
|
if (BigInt(quote.net_target_amount) <= 0n) {
|
|
20273
20568
|
throw new Error(
|
|
20274
|
-
`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.`
|
|
20275
20570
|
);
|
|
20276
20571
|
}
|
|
20277
20572
|
}
|
|
@@ -20309,6 +20604,11 @@ network='${network}'`
|
|
|
20309
20604
|
sourceChain = "42161";
|
|
20310
20605
|
sourceTokenId = _chunkTKFOVRJRcjs.USDC_ADDRESSES.Arbitrum;
|
|
20311
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
|
+
}
|
|
20312
20612
|
if (isArkade(sourceAsset) && isEvmToken(targetChain)) {
|
|
20313
20613
|
return this.createArkadeToEvmSwapGeneric({
|
|
20314
20614
|
targetAddress: options.targetAddress,
|
|
@@ -20501,6 +20801,8 @@ network='${network}'`
|
|
|
20501
20801
|
);
|
|
20502
20802
|
}
|
|
20503
20803
|
return this.createEvmToBitcoinSwap({
|
|
20804
|
+
bitcoinPayout: options.bitcoinPayout,
|
|
20805
|
+
minimumRelayFeeRateSatPerVb: options.minimumRelayFeeRateSatPerVb,
|
|
20504
20806
|
tokenAddress: sourceTokenId,
|
|
20505
20807
|
evmChainId: Number(sourceChain),
|
|
20506
20808
|
userAddress: _nullishCoalesce(options.userAddress, () => ( "")),
|
|
@@ -20870,7 +21172,69 @@ network='${network}'`
|
|
|
20870
21172
|
* ```
|
|
20871
21173
|
*/
|
|
20872
21174
|
async createEvmToBitcoinSwap(options) {
|
|
20873
|
-
|
|
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;
|
|
20874
21238
|
}
|
|
20875
21239
|
// =========================================================================
|
|
20876
21240
|
// Coordinator Funding (EVM-to-BTC via DEX + HTLC)
|
|
@@ -20929,7 +21293,7 @@ network='${network}'`
|
|
|
20929
21293
|
swapId,
|
|
20930
21294
|
serverData,
|
|
20931
21295
|
chainId,
|
|
20932
|
-
_optionalChain([options, 'optionalAccess',
|
|
21296
|
+
_optionalChain([options, 'optionalAccess', _316 => _316.funding])
|
|
20933
21297
|
);
|
|
20934
21298
|
const nonceBytes = new Uint8Array(32);
|
|
20935
21299
|
crypto.getRandomValues(nonceBytes);
|
|
@@ -20938,9 +21302,12 @@ network='${network}'`
|
|
|
20938
21302
|
);
|
|
20939
21303
|
const deadline = BigInt(Math.floor(Date.now() / 1e3) + 30 * 60);
|
|
20940
21304
|
const sourceAmount = checked.sourceAmount;
|
|
20941
|
-
const evmKey = this.#
|
|
21305
|
+
const evmKey = await this.#getFundingEvmSigningKey(
|
|
21306
|
+
storedSwap,
|
|
21307
|
+
swap.gasless
|
|
21308
|
+
);
|
|
20942
21309
|
const depositorAddress = deriveEvmAddress(evmKey);
|
|
20943
|
-
const digest =
|
|
21310
|
+
const digest = _chunkEI5ILLQ3cjs.buildPermit2FundingDigest.call(void 0, {
|
|
20944
21311
|
chainId,
|
|
20945
21312
|
coordinatorAddress: checked.coordinator,
|
|
20946
21313
|
sourceToken: checked.sourceToken,
|
|
@@ -20974,7 +21341,7 @@ network='${network}'`
|
|
|
20974
21341
|
delegated
|
|
20975
21342
|
);
|
|
20976
21343
|
const calls = checked.calls;
|
|
20977
|
-
const encoded =
|
|
21344
|
+
const encoded = _chunkEI5ILLQ3cjs.encodeExecuteAndCreateWithPermit2.call(void 0, checked.coordinator, {
|
|
20978
21345
|
calls,
|
|
20979
21346
|
preimageHash: checked.preimageHash,
|
|
20980
21347
|
token: checked.lockToken,
|
|
@@ -20990,9 +21357,9 @@ network='${network}'`
|
|
|
20990
21357
|
const maxUint256 = BigInt(
|
|
20991
21358
|
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
|
20992
21359
|
);
|
|
20993
|
-
const approve =
|
|
21360
|
+
const approve = _chunkEI5ILLQ3cjs.encodeApproveCallData.call(void 0,
|
|
20994
21361
|
checked.sourceToken,
|
|
20995
|
-
|
|
21362
|
+
_chunkEI5ILLQ3cjs.PERMIT2_ADDRESS,
|
|
20996
21363
|
maxUint256
|
|
20997
21364
|
);
|
|
20998
21365
|
return {
|
|
@@ -21071,7 +21438,7 @@ network='${network}'`
|
|
|
21071
21438
|
swapId,
|
|
21072
21439
|
serverData,
|
|
21073
21440
|
chainId,
|
|
21074
|
-
_optionalChain([options, 'optionalAccess',
|
|
21441
|
+
_optionalChain([options, 'optionalAccess', _317 => _317.funding])
|
|
21075
21442
|
);
|
|
21076
21443
|
const nonceBytes = new Uint8Array(32);
|
|
21077
21444
|
crypto.getRandomValues(nonceBytes);
|
|
@@ -21099,7 +21466,7 @@ network='${network}'`
|
|
|
21099
21466
|
nonce,
|
|
21100
21467
|
deadline
|
|
21101
21468
|
};
|
|
21102
|
-
const typedData =
|
|
21469
|
+
const typedData = _chunkEI5ILLQ3cjs.buildPermit2TypedData.call(void 0, fundingParams);
|
|
21103
21470
|
return {
|
|
21104
21471
|
coordinatorAddress: checked.coordinator,
|
|
21105
21472
|
/** The lock's sender: the depositor on HTLCErc20 v7 / HTLCNative v2, the coordinator before. */
|
|
@@ -21160,14 +21527,14 @@ network='${network}'`
|
|
|
21160
21527
|
*/
|
|
21161
21528
|
async fundSwap(swapId, signer, options) {
|
|
21162
21529
|
{
|
|
21163
|
-
const stored = await _optionalChain([this, 'access',
|
|
21164
|
-
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 })));
|
|
21165
21532
|
if ((response.direction === "evm_to_lightning" || response.direction === "evm_to_arkade" || response.direction === "evm_to_bitcoin") && response.evm_htlc_kind === "native") {
|
|
21166
21533
|
const txHash2 = await this.#fundNativeLock(
|
|
21167
21534
|
swapId,
|
|
21168
21535
|
response,
|
|
21169
21536
|
signer,
|
|
21170
|
-
_optionalChain([options, 'optionalAccess',
|
|
21537
|
+
_optionalChain([options, 'optionalAccess', _322 => _322.onQuote])
|
|
21171
21538
|
);
|
|
21172
21539
|
return { txHash: txHash2 };
|
|
21173
21540
|
}
|
|
@@ -21178,12 +21545,12 @@ network='${network}'`
|
|
|
21178
21545
|
}
|
|
21179
21546
|
}
|
|
21180
21547
|
if (isCctpOnlySource(signer.chainId)) {
|
|
21181
|
-
const stored = await _optionalChain([this, 'access',
|
|
21182
|
-
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 })));
|
|
21183
21550
|
const source = cctpMetaForChainId(signer.chainId);
|
|
21184
21551
|
const expected = {
|
|
21185
21552
|
...this.#fundingExpectation(swapId, stored),
|
|
21186
|
-
pins: _optionalChain([options, 'optionalAccess',
|
|
21553
|
+
pins: _optionalChain([options, 'optionalAccess', _327 => _327.funding])
|
|
21187
21554
|
};
|
|
21188
21555
|
await this.#ensureClientHashLock(
|
|
21189
21556
|
swapId,
|
|
@@ -21215,7 +21582,7 @@ network='${network}'`
|
|
|
21215
21582
|
}
|
|
21216
21583
|
const amount = BigInt(rawAmount);
|
|
21217
21584
|
const destination = cctpMetaForChainId(42161);
|
|
21218
|
-
const recordedBurn = _optionalChain([stored, 'optionalAccess',
|
|
21585
|
+
const recordedBurn = _optionalChain([stored, 'optionalAccess', _328 => _328.cctpBurnTxid]);
|
|
21219
21586
|
if (recordedBurn) {
|
|
21220
21587
|
const fresh = await this.getSwap(swapId, { updateStorage: true });
|
|
21221
21588
|
if (fresh.status !== "pending") {
|
|
@@ -21224,7 +21591,7 @@ network='${network}'`
|
|
|
21224
21591
|
);
|
|
21225
21592
|
}
|
|
21226
21593
|
}
|
|
21227
|
-
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(
|
|
21228
21595
|
await getCachedCctpFee({
|
|
21229
21596
|
sourceDomain: source.domain,
|
|
21230
21597
|
destinationDomain: destination.domain
|
|
@@ -21235,7 +21602,7 @@ network='${network}'`
|
|
|
21235
21602
|
swapId,
|
|
21236
21603
|
expected,
|
|
21237
21604
|
signer,
|
|
21238
|
-
ownerSigner: this.#depositorOwnerSigner(
|
|
21605
|
+
ownerSigner: await this.#depositorOwnerSigner(
|
|
21239
21606
|
swapResponse,
|
|
21240
21607
|
signer,
|
|
21241
21608
|
"Create the swap with `gasless: true` to settle through the SDK's key."
|
|
@@ -21244,8 +21611,8 @@ network='${network}'`
|
|
|
21244
21611
|
onBurn: (burnTxHash) => this.#recordCctpBurn(swapId, burnTxHash),
|
|
21245
21612
|
amount,
|
|
21246
21613
|
maxFee,
|
|
21247
|
-
onProgress: _optionalChain([options, 'optionalAccess',
|
|
21248
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
21614
|
+
onProgress: _optionalChain([options, 'optionalAccess', _330 => _330.onProgress]),
|
|
21615
|
+
signal: _optionalChain([options, 'optionalAccess', _331 => _331.signal])
|
|
21249
21616
|
});
|
|
21250
21617
|
if (cctp.transactionHash) {
|
|
21251
21618
|
await this.#recordEvmFunding(swapId, { txid: cctp.transactionHash });
|
|
@@ -21256,14 +21623,14 @@ network='${network}'`
|
|
|
21256
21623
|
swapId,
|
|
21257
21624
|
signer.chainId,
|
|
21258
21625
|
signer.address,
|
|
21259
|
-
{ funding: _optionalChain([options, 'optionalAccess',
|
|
21626
|
+
{ funding: _optionalChain([options, 'optionalAccess', _332 => _332.funding]) }
|
|
21260
21627
|
);
|
|
21261
|
-
_optionalChain([options, 'optionalAccess',
|
|
21628
|
+
_optionalChain([options, 'optionalAccess', _333 => _333.onQuote, 'optionalCall', _334 => _334({
|
|
21262
21629
|
sourceAmount: funding.sourceAmount,
|
|
21263
21630
|
sourceTokenAddress: funding.sourceTokenAddress
|
|
21264
21631
|
})]);
|
|
21265
21632
|
const tokenAddress = funding.sourceTokenAddress;
|
|
21266
|
-
const permit2 =
|
|
21633
|
+
const permit2 = _chunkEI5ILLQ3cjs.PERMIT2_ADDRESS;
|
|
21267
21634
|
const balanceCall = _chunkTNZW35XAcjs.encodeBalanceOfCall.call(void 0, tokenAddress, signer.address);
|
|
21268
21635
|
const balanceResult = await signer.call({
|
|
21269
21636
|
to: balanceCall.to,
|
|
@@ -21306,10 +21673,10 @@ network='${network}'`
|
|
|
21306
21673
|
swapId,
|
|
21307
21674
|
signer.chainId,
|
|
21308
21675
|
signer.address,
|
|
21309
|
-
{ funding: _optionalChain([options, 'optionalAccess',
|
|
21676
|
+
{ funding: _optionalChain([options, 'optionalAccess', _335 => _335.funding]) }
|
|
21310
21677
|
);
|
|
21311
21678
|
if (freshFunding.sourceAmount !== funding.sourceAmount) {
|
|
21312
|
-
_optionalChain([options, 'optionalAccess',
|
|
21679
|
+
_optionalChain([options, 'optionalAccess', _336 => _336.onQuote, 'optionalCall', _337 => _337({
|
|
21313
21680
|
sourceAmount: freshFunding.sourceAmount,
|
|
21314
21681
|
sourceTokenAddress: freshFunding.sourceTokenAddress
|
|
21315
21682
|
})]);
|
|
@@ -21319,10 +21686,10 @@ network='${network}'`
|
|
|
21319
21686
|
if (/^0x[0-9a-fA-F]{128}0[01]$/.test(signature) && signer.getCode) {
|
|
21320
21687
|
try {
|
|
21321
21688
|
depositorCode = await signer.getCode(signer.address);
|
|
21322
|
-
} catch (
|
|
21689
|
+
} catch (e31) {
|
|
21323
21690
|
}
|
|
21324
21691
|
}
|
|
21325
|
-
const encoded =
|
|
21692
|
+
const encoded = _chunkEI5ILLQ3cjs.encodeExecuteAndCreateWithPermit2.call(void 0,
|
|
21326
21693
|
freshFunding.coordinatorAddress,
|
|
21327
21694
|
{
|
|
21328
21695
|
calls: freshFunding.calls,
|
|
@@ -21385,17 +21752,17 @@ network='${network}'`
|
|
|
21385
21752
|
* @returns The Arbitrum settlement tx hash (or UserOp hash) and the burn
|
|
21386
21753
|
*/
|
|
21387
21754
|
async fundSwapFromSolana(swapId, signer, options) {
|
|
21388
|
-
const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
21755
|
+
const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _338 => _338.rpcUrl]), () => ( this.#config.solanaRpcUrl));
|
|
21389
21756
|
if (!rpcUrl) {
|
|
21390
21757
|
throw new Error(
|
|
21391
21758
|
"Funding from Solana needs a Solana RPC URL. Pass `rpcUrl` or call `.withSolanaRpcUrl(url)` on the ClientBuilder."
|
|
21392
21759
|
);
|
|
21393
21760
|
}
|
|
21394
|
-
const stored = await _optionalChain([this, 'access',
|
|
21395
|
-
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 })));
|
|
21396
21763
|
const expected = {
|
|
21397
21764
|
...this.#fundingExpectation(swapId, stored),
|
|
21398
|
-
pins: _optionalChain([options, 'optionalAccess',
|
|
21765
|
+
pins: _optionalChain([options, 'optionalAccess', _343 => _343.funding])
|
|
21399
21766
|
};
|
|
21400
21767
|
await this.#ensureClientHashLock(
|
|
21401
21768
|
swapId,
|
|
@@ -21419,7 +21786,7 @@ network='${network}'`
|
|
|
21419
21786
|
);
|
|
21420
21787
|
}
|
|
21421
21788
|
const amount = BigInt(bridge.source_amount);
|
|
21422
|
-
const recordedBurn = _optionalChain([stored, 'optionalAccess',
|
|
21789
|
+
const recordedBurn = _optionalChain([stored, 'optionalAccess', _344 => _344.cctpBurnTxid]);
|
|
21423
21790
|
if (recordedBurn) {
|
|
21424
21791
|
const fresh = await this.getSwap(swapId, { updateStorage: true });
|
|
21425
21792
|
if (fresh.status !== "pending") {
|
|
@@ -21428,14 +21795,14 @@ network='${network}'`
|
|
|
21428
21795
|
);
|
|
21429
21796
|
}
|
|
21430
21797
|
}
|
|
21431
|
-
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(
|
|
21432
21799
|
await getCachedCctpFee({
|
|
21433
21800
|
sourceDomain: _chunkTKFOVRJRcjs.CCTP_DOMAINS.Solana,
|
|
21434
21801
|
destinationDomain: _chunkTKFOVRJRcjs.CCTP_DOMAINS.Arbitrum
|
|
21435
21802
|
}),
|
|
21436
21803
|
amount
|
|
21437
21804
|
)));
|
|
21438
|
-
const { cctpFundSwapFromSolana } = await Promise.resolve().then(() => _interopRequireWildcard(require("./fundSwap-
|
|
21805
|
+
const { cctpFundSwapFromSolana } = await Promise.resolve().then(() => _interopRequireWildcard(require("./fundSwap-2D4IPYU4-4NELKB3Q.cjs")));
|
|
21439
21806
|
const { aa } = this.cctpInbound;
|
|
21440
21807
|
const cctp = await cctpFundSwapFromSolana(
|
|
21441
21808
|
{ apiClient: this.#apiClient, aa },
|
|
@@ -21443,20 +21810,20 @@ network='${network}'`
|
|
|
21443
21810
|
swapId,
|
|
21444
21811
|
expected,
|
|
21445
21812
|
signer,
|
|
21446
|
-
ownerSigner: this.#depositorOwnerSigner(
|
|
21813
|
+
ownerSigner: await this.#depositorOwnerSigner(
|
|
21447
21814
|
swapResponse,
|
|
21448
21815
|
void 0,
|
|
21449
21816
|
"A swap funded from Solana must be created with `gasless: true`."
|
|
21450
21817
|
),
|
|
21451
21818
|
rpcUrl,
|
|
21452
21819
|
burnSignature: recordedBurn,
|
|
21453
|
-
burnLastValidBlockHeight: _optionalChain([stored, 'optionalAccess',
|
|
21820
|
+
burnLastValidBlockHeight: _optionalChain([stored, 'optionalAccess', _346 => _346.cctpBurnLastValidBlockHeight]),
|
|
21454
21821
|
onBurn: (burnSignature, lastValidBlockHeight) => this.#recordCctpBurn(swapId, burnSignature, lastValidBlockHeight),
|
|
21455
21822
|
amount,
|
|
21456
21823
|
maxFee,
|
|
21457
|
-
priorityFeeMicroLamports: _optionalChain([options, 'optionalAccess',
|
|
21458
|
-
onProgress: _optionalChain([options, 'optionalAccess',
|
|
21459
|
-
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])
|
|
21460
21827
|
}
|
|
21461
21828
|
);
|
|
21462
21829
|
if (cctp.transactionHash) {
|
|
@@ -21474,7 +21841,7 @@ network='${network}'`
|
|
|
21474
21841
|
* `withSolanaRpcUrl` on the builder
|
|
21475
21842
|
*/
|
|
21476
21843
|
async getSolanaUsdcBalance(owner, options) {
|
|
21477
|
-
const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
21844
|
+
const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _350 => _350.rpcUrl]), () => ( this.#config.solanaRpcUrl));
|
|
21478
21845
|
if (!rpcUrl) {
|
|
21479
21846
|
throw new Error(
|
|
21480
21847
|
"Reading a Solana balance needs a Solana RPC URL. Pass `rpcUrl` or call `.withSolanaRpcUrl(url)` on the ClientBuilder."
|
|
@@ -21510,16 +21877,16 @@ network='${network}'`
|
|
|
21510
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`
|
|
21511
21878
|
);
|
|
21512
21879
|
}
|
|
21513
|
-
_optionalChain([onQuote, 'optionalCall',
|
|
21880
|
+
_optionalChain([onQuote, 'optionalCall', _351 => _351({
|
|
21514
21881
|
sourceAmount: amount,
|
|
21515
|
-
sourceTokenAddress:
|
|
21882
|
+
sourceTokenAddress: _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS
|
|
21516
21883
|
})]);
|
|
21517
|
-
if (swap.evm_coordinator_address.toLowerCase() !==
|
|
21884
|
+
if (swap.evm_coordinator_address.toLowerCase() !== _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS) {
|
|
21518
21885
|
throw new Error(
|
|
21519
21886
|
"This legacy Rootstock swap requires coordinator funding. Create a new swap with the updated backend before funding."
|
|
21520
21887
|
);
|
|
21521
21888
|
}
|
|
21522
|
-
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()])) {
|
|
21523
21890
|
throw new Error(
|
|
21524
21891
|
"Connect the source wallet recorded on this swap to fund RBTC."
|
|
21525
21892
|
);
|
|
@@ -21544,13 +21911,13 @@ network='${network}'`
|
|
|
21544
21911
|
preimageHash: hashLock,
|
|
21545
21912
|
claimAddress: swap.server_evm_address,
|
|
21546
21913
|
lockSender: signer.address,
|
|
21547
|
-
token:
|
|
21914
|
+
token: _chunkEI5ILLQ3cjs.NATIVE_TOKEN_ADDRESS
|
|
21548
21915
|
};
|
|
21549
21916
|
await this.#ensureNativeFundingFailed(
|
|
21550
21917
|
swapId,
|
|
21551
21918
|
signer,
|
|
21552
21919
|
[
|
|
21553
|
-
await _asyncOptionalChain([(await this.getStoredSwap(swapId)), 'optionalAccess', async
|
|
21920
|
+
await _asyncOptionalChain([(await this.getStoredSwap(swapId)), 'optionalAccess', async _355 => _355.evmFundTxid]),
|
|
21554
21921
|
swap.evm_fund_txid
|
|
21555
21922
|
],
|
|
21556
21923
|
hashLock
|
|
@@ -21584,7 +21951,7 @@ network='${network}'`
|
|
|
21584
21951
|
let known;
|
|
21585
21952
|
try {
|
|
21586
21953
|
known = await signer.getTransaction(txid);
|
|
21587
|
-
} catch (
|
|
21954
|
+
} catch (e32) {
|
|
21588
21955
|
known = null;
|
|
21589
21956
|
}
|
|
21590
21957
|
if (!known) refuse("the node does not know and may still land");
|
|
@@ -21595,7 +21962,7 @@ network='${network}'`
|
|
|
21595
21962
|
FUNDING_RECEIPT_WAIT_MS,
|
|
21596
21963
|
`not mined within ${FUNDING_RECEIPT_WAIT_MS / 1e3}s`
|
|
21597
21964
|
);
|
|
21598
|
-
} catch (
|
|
21965
|
+
} catch (e33) {
|
|
21599
21966
|
return refuse("is not mined yet");
|
|
21600
21967
|
}
|
|
21601
21968
|
if (receipt.status !== "success") continue;
|
|
@@ -21619,7 +21986,7 @@ network='${network}'`
|
|
|
21619
21986
|
});
|
|
21620
21987
|
const receipt = await signer.waitForReceipt(txHash);
|
|
21621
21988
|
if (receipt.status !== "success") {
|
|
21622
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
21989
|
+
if (_optionalChain([options, 'optionalAccess', _356 => _356.forgetFailed])) await this.#forgetEvmFunding(swapId, txHash);
|
|
21623
21990
|
const reason = await _chunkTNZW35XAcjs.getRevertReason.call(void 0, signer, txHash, receipt.blockNumber);
|
|
21624
21991
|
throw new Error(`Funding transaction failed: ${reason}`);
|
|
21625
21992
|
}
|
|
@@ -21634,7 +22001,7 @@ network='${network}'`
|
|
|
21634
22001
|
});
|
|
21635
22002
|
created = !replaced || await isSameCall(signer, mined, sent);
|
|
21636
22003
|
} else {
|
|
21637
|
-
created =
|
|
22004
|
+
created = _chunkEI5ILLQ3cjs.findSwapCreated.call(void 0, receipt.logs, {
|
|
21638
22005
|
htlcAddress: expected.htlcAddress,
|
|
21639
22006
|
hashLock: expected.preimageHash,
|
|
21640
22007
|
claimAddress: expected.claimAddress,
|
|
@@ -21643,7 +22010,7 @@ network='${network}'`
|
|
|
21643
22010
|
}).length > 0;
|
|
21644
22011
|
}
|
|
21645
22012
|
if (!created && replaced) {
|
|
21646
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
22013
|
+
if (_optionalChain([options, 'optionalAccess', _357 => _357.forgetFailed]) && provesNoLockUnder(receipt, expected.preimageHash)) {
|
|
21647
22014
|
await this.#forgetEvmFunding(swapId, txHash);
|
|
21648
22015
|
}
|
|
21649
22016
|
throw new Error(
|
|
@@ -21833,7 +22200,7 @@ network='${network}'`
|
|
|
21833
22200
|
}
|
|
21834
22201
|
async #actualRefundTransfer(oldSwap, smartAccountAddress) {
|
|
21835
22202
|
const txHash = oldSwap.evm_claim_txid;
|
|
21836
|
-
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])));
|
|
21837
22204
|
if (!txHash || !rpcUrl) return null;
|
|
21838
22205
|
const { createPublicClient: createPublicClient2, http: http2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./_esm-4ZKYBBIE-D33574DC.cjs")));
|
|
21839
22206
|
const { arbitrum: arbitrum2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./chains-D6LHJZMI-AAYKXZGC.cjs")));
|
|
@@ -21846,13 +22213,13 @@ network='${network}'`
|
|
|
21846
22213
|
receipt = await publicClient.getTransactionReceipt({
|
|
21847
22214
|
hash: txHash
|
|
21848
22215
|
});
|
|
21849
|
-
} catch (
|
|
22216
|
+
} catch (e34) {
|
|
21850
22217
|
return null;
|
|
21851
22218
|
}
|
|
21852
22219
|
const transferTopic = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
|
21853
22220
|
const paddedRecipient = smartAccountAddress.replace(/^0x/i, "").toLowerCase().padStart(64, "0");
|
|
21854
22221
|
const transfers = receipt.logs.filter(
|
|
21855
|
-
(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
|
|
21856
22223
|
).map((log) => ({
|
|
21857
22224
|
tokenAddress: log.address,
|
|
21858
22225
|
amount: BigInt(log.data).toString()
|
|
@@ -21889,7 +22256,7 @@ network='${network}'`
|
|
|
21889
22256
|
oldSwap
|
|
21890
22257
|
};
|
|
21891
22258
|
}
|
|
21892
|
-
const owner =
|
|
22259
|
+
const owner = await this.#depositorOwnerSigner(oldSwap, signer);
|
|
21893
22260
|
const { accountAddress } = await this.cctpInbound.createSmartAccountClient({
|
|
21894
22261
|
signer: owner
|
|
21895
22262
|
});
|
|
@@ -21939,8 +22306,8 @@ network='${network}'`
|
|
|
21939
22306
|
{
|
|
21940
22307
|
chain: refundChain,
|
|
21941
22308
|
address: actualRefund.tokenAddress,
|
|
21942
|
-
symbol: _nullishCoalesce(_optionalChain([actualMeta, 'optionalAccess',
|
|
21943
|
-
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)),
|
|
21944
22311
|
amount: actualRefund.amount
|
|
21945
22312
|
}
|
|
21946
22313
|
] : [],
|
|
@@ -21994,17 +22361,11 @@ network='${network}'`
|
|
|
21994
22361
|
* address, an Arkade address, or for Lightning a BOLT11 invoice (its amount
|
|
21995
22362
|
* must be covered by the refund), a Lightning address or an LNURL.
|
|
21996
22363
|
* @param options.target - The payout type; defaults to the old swap's.
|
|
21997
|
-
* @param options.signer - A signer for
|
|
21998
|
-
*
|
|
21999
|
-
*
|
|
22000
|
-
* 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.
|
|
22001
22367
|
*/
|
|
22002
22368
|
async continueRefundedEvmSwap(oldSwapId, options) {
|
|
22003
|
-
if (options.signer && options.signer.address.toLowerCase() !== this.getEvmAddress().toLowerCase()) {
|
|
22004
|
-
throw new Error(
|
|
22005
|
-
`Cannot continue refunded swap ${oldSwapId} with signer ${options.signer.address}: a continuation is funded from this client's key (${this.getEvmAddress()}).`
|
|
22006
|
-
);
|
|
22007
|
-
}
|
|
22008
22369
|
const info = await this.getRefundedEvmSwapContinuation(
|
|
22009
22370
|
oldSwapId,
|
|
22010
22371
|
options.signer
|
|
@@ -22012,6 +22373,17 @@ network='${network}'`
|
|
|
22012
22373
|
if (!info.eligible || !info.token || !info.amount || !info.oldSwap) {
|
|
22013
22374
|
throw new Error(_nullishCoalesce(info.reason, () => ( "Refunded swap cannot be continued.")));
|
|
22014
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
|
+
);
|
|
22015
22387
|
const target = _nullishCoalesce(options.target, () => ( {
|
|
22016
22388
|
evm_to_arkade: "arkade",
|
|
22017
22389
|
evm_to_bitcoin: "bitcoin",
|
|
@@ -22022,7 +22394,7 @@ network='${network}'`
|
|
|
22022
22394
|
tokenAddress: info.token.address,
|
|
22023
22395
|
evmChainId: 42161,
|
|
22024
22396
|
userAddress: _nullishCoalesce(info.smartAccountAddress, () => ( "")),
|
|
22025
|
-
gasless:
|
|
22397
|
+
gasless: false
|
|
22026
22398
|
};
|
|
22027
22399
|
let created;
|
|
22028
22400
|
if (target === "arkade") {
|
|
@@ -22048,6 +22420,18 @@ network='${network}'`
|
|
|
22048
22420
|
);
|
|
22049
22421
|
}
|
|
22050
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
|
+
}
|
|
22051
22435
|
const submitted = await this.cctpInbound.submitBalanceUserOp({
|
|
22052
22436
|
swapId: newSwapId,
|
|
22053
22437
|
// The new swap's own hash and terms, recorded when it was just
|
|
@@ -22059,7 +22443,7 @@ network='${network}'`
|
|
|
22059
22443
|
),
|
|
22060
22444
|
pins: options.funding
|
|
22061
22445
|
},
|
|
22062
|
-
signer:
|
|
22446
|
+
signer: await this.#depositorOwnerSigner(info.oldSwap, options.signer),
|
|
22063
22447
|
expectedMaxSourceAmount: sourceAmount
|
|
22064
22448
|
});
|
|
22065
22449
|
if (submitted.transactionHash) {
|
|
@@ -22106,20 +22490,7 @@ network='${network}'`
|
|
|
22106
22490
|
`Sponsored refunds run on Arbitrum only; swap ${swapId} is on chain ${chainId}. Use refundEvmWithSigner.`
|
|
22107
22491
|
);
|
|
22108
22492
|
}
|
|
22109
|
-
const
|
|
22110
|
-
let owner;
|
|
22111
|
-
if (_optionalChain([depositor, 'optionalAccess', _355 => _355.toLowerCase, 'call', _356 => _356()]) === this.getEvmAddress().toLowerCase()) {
|
|
22112
|
-
owner = this.#keyOwnerSigner();
|
|
22113
|
-
} else if (gasless && _optionalChain([depositor, 'optionalAccess', _357 => _357.toLowerCase, 'call', _358 => _358()]) === deriveEvmAddress(stored.secretKey).toLowerCase()) {
|
|
22114
|
-
owner = keyToKernelOwnerSigner(
|
|
22115
|
-
_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, stored.secretKey.replace(/^0x/, "")),
|
|
22116
|
-
42161
|
|
22117
|
-
);
|
|
22118
|
-
} else {
|
|
22119
|
-
throw new Error(
|
|
22120
|
-
`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.`
|
|
22121
|
-
);
|
|
22122
|
-
}
|
|
22493
|
+
const owner = await this.#depositorOwnerSigner(stored.response);
|
|
22123
22494
|
const result = await this.refundSwap(swapId);
|
|
22124
22495
|
if (!result.evmRefundData) {
|
|
22125
22496
|
throw new Error(
|
|
@@ -22137,19 +22508,15 @@ network='${network}'`
|
|
|
22137
22508
|
const refund = result.evmRefundData;
|
|
22138
22509
|
return this.#sponsoredUserOp(
|
|
22139
22510
|
owner,
|
|
22140
|
-
(account) =>
|
|
22511
|
+
(account) => _chunkEI5ILLQ3cjs.refundForAsOwnRefund.call(void 0, refund, account)
|
|
22141
22512
|
);
|
|
22142
22513
|
}
|
|
22143
|
-
/** This client's key as the Kernel owner on Arbitrum. */
|
|
22144
|
-
#keyOwnerSigner() {
|
|
22145
|
-
return keyToKernelOwnerSigner(this.#signer.deriveEvmKey().secretKey, 42161);
|
|
22146
|
-
}
|
|
22147
22514
|
/**
|
|
22148
22515
|
* An `eth_call` over the AA RPC, for reads on an account this client owns
|
|
22149
22516
|
* with its key (whose signer does not read the chain).
|
|
22150
22517
|
*/
|
|
22151
22518
|
async #aaRpcCall() {
|
|
22152
|
-
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])));
|
|
22153
22520
|
if (!rpcUrl) {
|
|
22154
22521
|
throw new Error(
|
|
22155
22522
|
"Reading a refunded balance without a signer requires AA config (`.withAa(...)`)."
|
|
@@ -22190,7 +22557,7 @@ network='${network}'`
|
|
|
22190
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()\`.`
|
|
22191
22558
|
);
|
|
22192
22559
|
}
|
|
22193
|
-
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()])) {
|
|
22194
22561
|
if (this.#config.aa.allowSelfPaidFunding) return { mode: "self-paid" };
|
|
22195
22562
|
throw new Error(
|
|
22196
22563
|
"Sponsored funding requires a paymasterPolicyId. Self-paid local tests must explicitly set allowSelfPaidFunding and prefund the account with ETH."
|
|
@@ -22270,7 +22637,7 @@ network='${network}'`
|
|
|
22270
22637
|
swapId,
|
|
22271
22638
|
serverData,
|
|
22272
22639
|
chainId,
|
|
22273
|
-
_optionalChain([options, 'optionalAccess',
|
|
22640
|
+
_optionalChain([options, 'optionalAccess', _390 => _390.funding])
|
|
22274
22641
|
);
|
|
22275
22642
|
const nonceBytes = new Uint8Array(32);
|
|
22276
22643
|
crypto.getRandomValues(nonceBytes);
|
|
@@ -22279,9 +22646,12 @@ network='${network}'`
|
|
|
22279
22646
|
);
|
|
22280
22647
|
const deadline = BigInt(Math.floor(Date.now() / 1e3) + 30 * 60);
|
|
22281
22648
|
const sourceAmount = checked.sourceAmount;
|
|
22282
|
-
const evmKey = this.#
|
|
22649
|
+
const evmKey = await this.#getFundingEvmSigningKey(
|
|
22650
|
+
storedSwap,
|
|
22651
|
+
swap.gasless
|
|
22652
|
+
);
|
|
22283
22653
|
const depositorAddress = deriveEvmAddress(evmKey);
|
|
22284
|
-
const digest =
|
|
22654
|
+
const digest = _chunkEI5ILLQ3cjs.buildPermit2FundingDigest.call(void 0, {
|
|
22285
22655
|
chainId,
|
|
22286
22656
|
coordinatorAddress: checked.coordinator,
|
|
22287
22657
|
sourceToken: checked.sourceToken,
|
|
@@ -22315,14 +22685,14 @@ network='${network}'`
|
|
|
22315
22685
|
delegated
|
|
22316
22686
|
);
|
|
22317
22687
|
let eip2612Permit;
|
|
22318
|
-
if (_optionalChain([serverData, 'access',
|
|
22688
|
+
if (_optionalChain([serverData, 'access', _391 => _391.eip2612, 'optionalAccess', _392 => _392.supported]) && !serverData.eip2612.already_approved) {
|
|
22319
22689
|
const maxUint256 = BigInt(
|
|
22320
22690
|
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
|
22321
22691
|
);
|
|
22322
|
-
const eip2612Digest =
|
|
22692
|
+
const eip2612Digest = _chunkEI5ILLQ3cjs.buildEip2612PermitDigest.call(void 0, {
|
|
22323
22693
|
domainSeparator: serverData.eip2612.domain_separator,
|
|
22324
22694
|
owner: depositorAddress,
|
|
22325
|
-
spender:
|
|
22695
|
+
spender: _chunkEI5ILLQ3cjs.PERMIT2_ADDRESS,
|
|
22326
22696
|
value: maxUint256,
|
|
22327
22697
|
nonce: serverData.eip2612.nonce,
|
|
22328
22698
|
deadline
|
|
@@ -22395,7 +22765,7 @@ network='${network}'`
|
|
|
22395
22765
|
if (!this.#swapStorage)
|
|
22396
22766
|
throw new Error("Sponsored funding requires swap storage");
|
|
22397
22767
|
if (stored.evmFundingUserOpHash) {
|
|
22398
|
-
const key2 = this.#gaslessDepositorKey(swapId, stored, swap);
|
|
22768
|
+
const key2 = await this.#gaslessDepositorKey(swapId, stored, swap);
|
|
22399
22769
|
const { client } = await this.cctpInbound.createSmartAccountClient({
|
|
22400
22770
|
signer: keyToKernelOwnerSigner(
|
|
22401
22771
|
_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, key2.replace(/^0x/, "")),
|
|
@@ -22423,7 +22793,7 @@ network='${network}'`
|
|
|
22423
22793
|
}
|
|
22424
22794
|
const expected = {
|
|
22425
22795
|
...this.#fundingExpectation(swapId, stored),
|
|
22426
|
-
pins: _optionalChain([options, 'optionalAccess',
|
|
22796
|
+
pins: _optionalChain([options, 'optionalAccess', _393 => _393.funding])
|
|
22427
22797
|
};
|
|
22428
22798
|
if (expected.terms.chainId !== AA_CHAIN_ID) {
|
|
22429
22799
|
throw new Error(
|
|
@@ -22435,7 +22805,7 @@ network='${network}'`
|
|
|
22435
22805
|
const { arbitrum: arbitrum2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./chains-D6LHJZMI-AAYKXZGC.cjs")));
|
|
22436
22806
|
const rpc = createPublicClient2({
|
|
22437
22807
|
chain: arbitrum2,
|
|
22438
|
-
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]))))
|
|
22439
22809
|
});
|
|
22440
22810
|
const receipt = await rpc.getTransactionReceipt({
|
|
22441
22811
|
hash: stored.evmFundTxid
|
|
@@ -22448,8 +22818,10 @@ network='${network}'`
|
|
|
22448
22818
|
if (receipt.status === "reverted") {
|
|
22449
22819
|
await this.#forgetEvmFunding(swapId, stored.evmFundTxid);
|
|
22450
22820
|
} else if (receipt.status === "success" && receipt.logs !== void 0) {
|
|
22451
|
-
const sender = (_nullishCoalesce(expected.terms.htlcVersion, () => ( 0))) >= 7 ? deriveEvmAddress(
|
|
22452
|
-
|
|
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, {
|
|
22453
22825
|
htlcAddress: expected.terms.htlcAddress,
|
|
22454
22826
|
hashLock: expected.hashLock,
|
|
22455
22827
|
claimAddress: expected.terms.claimAddress,
|
|
@@ -22473,7 +22845,7 @@ network='${network}'`
|
|
|
22473
22845
|
);
|
|
22474
22846
|
}
|
|
22475
22847
|
}
|
|
22476
|
-
const key = this.#gaslessDepositorKey(swapId, stored, swap);
|
|
22848
|
+
const key = await this.#gaslessDepositorKey(swapId, stored, swap);
|
|
22477
22849
|
const owner = keyToKernelOwnerSigner(
|
|
22478
22850
|
_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, key.replace(/^0x/, "")),
|
|
22479
22851
|
AA_CHAIN_ID
|
|
@@ -22501,7 +22873,7 @@ network='${network}'`
|
|
|
22501
22873
|
return { txHash };
|
|
22502
22874
|
}
|
|
22503
22875
|
async #setFundingUserOp(swapId, hash) {
|
|
22504
|
-
const current = await _optionalChain([this, 'access',
|
|
22876
|
+
const current = await _optionalChain([this, 'access', _400 => _400.#swapStorage, 'optionalAccess', _401 => _401.get, 'call', _402 => _402(swapId)]);
|
|
22505
22877
|
if (!current || !this.#swapStorage)
|
|
22506
22878
|
throw new Error("Cannot persist funding operation");
|
|
22507
22879
|
await this.#swapStorage.store({
|
|
@@ -22517,18 +22889,23 @@ network='${network}'`
|
|
|
22517
22889
|
* account, so a depositor this SDK does not control cannot be funded
|
|
22518
22890
|
* here.
|
|
22519
22891
|
*/
|
|
22520
|
-
#gaslessDepositorKey(swapId, stored, swap) {
|
|
22521
|
-
const depositor = _optionalChain([
|
|
22522
|
-
|
|
22523
|
-
|
|
22524
|
-
|
|
22525
|
-
|
|
22526
|
-
|
|
22527
|
-
|
|
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;
|
|
22528
22903
|
}
|
|
22529
|
-
|
|
22530
|
-
|
|
22531
|
-
|
|
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;
|
|
22532
22909
|
}
|
|
22533
22910
|
/**
|
|
22534
22911
|
* Get the ephemeral depositor key for a gasless swap funded swap.
|
|
@@ -22559,29 +22936,40 @@ network='${network}'`
|
|
|
22559
22936
|
);
|
|
22560
22937
|
}
|
|
22561
22938
|
const response = storedSwap.response;
|
|
22562
|
-
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()]);
|
|
22563
22940
|
const sharedKey = this.#getEvmSigningKey();
|
|
22564
|
-
const
|
|
22565
|
-
|
|
22566
|
-
|
|
22567
|
-
|
|
22568
|
-
|
|
22569
|
-
|
|
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])))
|
|
22570
22954
|
throw new Error(
|
|
22571
|
-
`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.`
|
|
22572
22956
|
);
|
|
22573
|
-
|
|
22957
|
+
const evmKey = _nullishCoalesce(matched, () => ( sharedKey));
|
|
22574
22958
|
const privateKey = evmKey.startsWith("0x") ? evmKey : `0x${evmKey}`;
|
|
22575
22959
|
const address2 = deriveEvmAddress(evmKey);
|
|
22576
|
-
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
|
+
};
|
|
22577
22965
|
}
|
|
22578
22966
|
/**
|
|
22579
22967
|
* Wallet-level variant of {@link getSwapDepositorKey} — returns the
|
|
22580
22968
|
* deterministic EVM signing key for this wallet without requiring a
|
|
22581
22969
|
* specific swap to be stored locally.
|
|
22582
22970
|
*
|
|
22583
|
-
*
|
|
22584
|
-
* 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
|
|
22585
22973
|
* where the user supplies the burn details manually and a per-swap
|
|
22586
22974
|
* record may no longer exist (e.g. fresh device, cleared site data).
|
|
22587
22975
|
*/
|
|
@@ -22620,7 +23008,7 @@ network='${network}'`
|
|
|
22620
23008
|
if (!sourceChain) {
|
|
22621
23009
|
throw new Error(`Swap ${swapId} is not a CCTP-inbound swap.`);
|
|
22622
23010
|
}
|
|
22623
|
-
const burnTxHash = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
23011
|
+
const burnTxHash = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _413 => _413.burnTxHash]), () => ( stored.cctpBurnTxid));
|
|
22624
23012
|
if (!burnTxHash) {
|
|
22625
23013
|
throw new Error(
|
|
22626
23014
|
`No CCTP burn is recorded for swap ${swapId}; pass it as \`burnTxHash\`.`
|
|
@@ -22629,15 +23017,15 @@ network='${network}'`
|
|
|
22629
23017
|
return recoverCctpInbound(
|
|
22630
23018
|
{ aa: this.#config.aa },
|
|
22631
23019
|
{
|
|
22632
|
-
signer: this.#depositorOwnerSigner(
|
|
23020
|
+
signer: await this.#depositorOwnerSigner(
|
|
22633
23021
|
stored.response,
|
|
22634
|
-
_optionalChain([options, 'optionalAccess',
|
|
23022
|
+
_optionalChain([options, 'optionalAccess', _414 => _414.ownerSigner])
|
|
22635
23023
|
),
|
|
22636
23024
|
burnTxHash,
|
|
22637
23025
|
sourceChain,
|
|
22638
23026
|
recipient,
|
|
22639
|
-
onProgress: _optionalChain([options, 'optionalAccess',
|
|
22640
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
23027
|
+
onProgress: _optionalChain([options, 'optionalAccess', _415 => _415.onProgress]),
|
|
23028
|
+
signal: _optionalChain([options, 'optionalAccess', _416 => _416.signal])
|
|
22641
23029
|
}
|
|
22642
23030
|
);
|
|
22643
23031
|
}
|
|
@@ -22781,14 +23169,14 @@ function b64Encode(u) {
|
|
|
22781
23169
|
return btoa(bin);
|
|
22782
23170
|
}
|
|
22783
23171
|
function isP2tr(script) {
|
|
22784
|
-
return _optionalChain([script, 'optionalAccess',
|
|
23172
|
+
return _optionalChain([script, 'optionalAccess', _417 => _417.length]) === 34 && script[0] === 81 && script[1] === 32;
|
|
22785
23173
|
}
|
|
22786
23174
|
function parseEscrowPsbt(psbt) {
|
|
22787
23175
|
const lenient = _chunkBEW62OUTcjs.Transaction2.fromPSBT(psbt, { disableScriptCheck: true });
|
|
22788
23176
|
let stripped = false;
|
|
22789
23177
|
for (let i = 0; i < lenient.inputsLength; i++) {
|
|
22790
23178
|
const input = lenient.getInput(i);
|
|
22791
|
-
if (input.witnessScript && isP2tr(_optionalChain([input, 'access',
|
|
23179
|
+
if (input.witnessScript && isP2tr(_optionalChain([input, 'access', _418 => _418.witnessUtxo, 'optionalAccess', _419 => _419.script]))) {
|
|
22792
23180
|
lenient.updateInput(i, { witnessScript: void 0 }, true);
|
|
22793
23181
|
stripped = true;
|
|
22794
23182
|
}
|
|
@@ -22920,11 +23308,11 @@ var IdbWalletStorage = class {
|
|
|
22920
23308
|
}
|
|
22921
23309
|
async getMnemonic() {
|
|
22922
23310
|
const record = await this.#db.wallet.get(MNEMONIC_KEY);
|
|
22923
|
-
if (_optionalChain([record, 'optionalAccess',
|
|
23311
|
+
if (_optionalChain([record, 'optionalAccess', _420 => _420.value])) {
|
|
22924
23312
|
return record.value;
|
|
22925
23313
|
}
|
|
22926
23314
|
const v2Wallet = await readV2Wallet();
|
|
22927
|
-
if (!_optionalChain([v2Wallet, 'optionalAccess',
|
|
23315
|
+
if (!_optionalChain([v2Wallet, 'optionalAccess', _421 => _421.mnemonic])) {
|
|
22928
23316
|
return null;
|
|
22929
23317
|
}
|
|
22930
23318
|
await this.setMnemonic(v2Wallet.mnemonic);
|
|
@@ -22939,7 +23327,7 @@ var IdbWalletStorage = class {
|
|
|
22939
23327
|
}
|
|
22940
23328
|
async getKeyIndex() {
|
|
22941
23329
|
const record = await this.#db.wallet.get(KEY_INDEX_KEY);
|
|
22942
|
-
return _nullishCoalesce(_optionalChain([record, 'optionalAccess',
|
|
23330
|
+
return _nullishCoalesce(_optionalChain([record, 'optionalAccess', _422 => _422.value]), () => ( 0));
|
|
22943
23331
|
}
|
|
22944
23332
|
async setKeyIndex(index) {
|
|
22945
23333
|
await this.#db.wallet.put({ key: KEY_INDEX_KEY, value: index });
|
|
@@ -22947,7 +23335,7 @@ var IdbWalletStorage = class {
|
|
|
22947
23335
|
async incrementKeyIndex() {
|
|
22948
23336
|
return this.#db.transaction("rw", this.#db.wallet, async () => {
|
|
22949
23337
|
const record = await this.#db.wallet.get(KEY_INDEX_KEY);
|
|
22950
|
-
const current = _nullishCoalesce(_optionalChain([record, 'optionalAccess',
|
|
23338
|
+
const current = _nullishCoalesce(_optionalChain([record, 'optionalAccess', _423 => _423.value]), () => ( 0));
|
|
22951
23339
|
await this.#db.wallet.put({ key: KEY_INDEX_KEY, value: current + 1 });
|
|
22952
23340
|
return current;
|
|
22953
23341
|
});
|
|
@@ -23003,7 +23391,7 @@ function readV2Wallet() {
|
|
|
23003
23391
|
}
|
|
23004
23392
|
const request = indexedDB.open(V2_DB_NAME);
|
|
23005
23393
|
request.onupgradeneeded = () => {
|
|
23006
|
-
_optionalChain([request, 'access',
|
|
23394
|
+
_optionalChain([request, 'access', _424 => _424.transaction, 'optionalAccess', _425 => _425.abort, 'call', _426 => _426()]);
|
|
23007
23395
|
};
|
|
23008
23396
|
request.onerror = () => {
|
|
23009
23397
|
resolve(null);
|
|
@@ -23035,7 +23423,7 @@ function readV2Wallet() {
|
|
|
23035
23423
|
db.close();
|
|
23036
23424
|
resolve(null);
|
|
23037
23425
|
};
|
|
23038
|
-
} catch (
|
|
23426
|
+
} catch (e36) {
|
|
23039
23427
|
db.close();
|
|
23040
23428
|
resolve(null);
|
|
23041
23429
|
}
|
|
@@ -23229,10 +23617,15 @@ async function getUsdPrices(tokens, options = {}) {
|
|
|
23229
23617
|
|
|
23230
23618
|
|
|
23231
23619
|
|
|
23232
|
-
|
|
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;
|
|
23233
23626
|
/*! Bundled license information:
|
|
23234
23627
|
|
|
23235
23628
|
@scure/bip39/index.js:
|
|
23236
23629
|
(*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
23237
23630
|
*/
|
|
23238
|
-
//# sourceMappingURL=chunk-
|
|
23631
|
+
//# sourceMappingURL=chunk-3633KDTW.cjs.map
|