@satora/swap 1.10.2 → 1.11.1

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.
Files changed (85) hide show
  1. package/dist/{chunk-K4BQUZC6.js → chunk-2AULREFC.js} +2 -2
  2. package/dist/chunk-2AULREFC.js.map +1 -0
  3. package/dist/{chunk-2LGHF7A3.cjs → chunk-4NVWIR74.cjs} +755 -439
  4. package/dist/chunk-4NVWIR74.cjs.map +1 -0
  5. package/dist/{chunk-HWK7LVVX.js → chunk-JHZHRY7S.js} +130 -51
  6. package/dist/chunk-JHZHRY7S.js.map +1 -0
  7. package/dist/{chunk-7GOXIT24.cjs → chunk-JZTF4JNH.cjs} +110 -31
  8. package/dist/chunk-JZTF4JNH.cjs.map +1 -0
  9. package/dist/{chunk-OJNQCRHU.cjs → chunk-Q4TOBBAN.cjs} +7 -7
  10. package/dist/{chunk-OJNQCRHU.cjs.map → chunk-Q4TOBBAN.cjs.map} +1 -1
  11. package/dist/{chunk-MYOGO44L.cjs → chunk-TNZW35XA.cjs} +2 -2
  12. package/dist/chunk-TNZW35XA.cjs.map +1 -0
  13. package/dist/{chunk-VBNBVJLB.js → chunk-TT3J2OOS.js} +8 -8
  14. package/dist/{chunk-VBNBVJLB.js.map → chunk-TT3J2OOS.js.map} +1 -1
  15. package/dist/{chunk-S4T4GK5G.js → chunk-WQMAL2VD.js} +391 -75
  16. package/dist/chunk-WQMAL2VD.js.map +1 -0
  17. package/dist/delegate.cjs +3 -3
  18. package/dist/delegate.js +2 -2
  19. package/dist/dist-MHRQ5FFV.cjs +394 -0
  20. package/dist/{dist-MMYSP6LP.cjs.map → dist-MHRQ5FFV.cjs.map} +1 -1
  21. package/dist/{dist-L5LHQNRK.js → dist-SHY7I6SH.js} +13 -13
  22. package/dist/{fundSwap-IUPFISXM-ON5IVSSZ.cjs → fundSwap-UBCHMUP4-BEMQNSFQ.cjs} +15 -15
  23. package/dist/{fundSwap-IUPFISXM-ON5IVSSZ.cjs.map → fundSwap-UBCHMUP4-BEMQNSFQ.cjs.map} +1 -1
  24. package/dist/{fundSwap-IUPFISXM-6IBPJ5O7.js → fundSwap-UBCHMUP4-WBLYE6MC.js} +11 -11
  25. package/dist/index.cjs +28 -24
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.js +17 -13
  28. package/dist/index.js.map +1 -1
  29. package/dist/node.cjs +11 -6
  30. package/dist/node.cjs.map +1 -1
  31. package/dist/node.js +11 -6
  32. package/dist/node.js.map +1 -1
  33. package/dist/types/cjs/pure/cctp/attestation.d.cts +5 -3
  34. package/dist/types/cjs/pure/cctp/types.d.cts +11 -2
  35. package/dist/types/cjs/pure/cctp-inbound/submit.d.cts +2 -0
  36. package/dist/types/cjs/pure/cctp-inbound/types.d.cts +5 -0
  37. package/dist/types/cjs/pure/cctp-inbound/userOp.d.cts +11 -0
  38. package/dist/types/cjs/pure/client.d.cts +61 -18
  39. package/dist/types/cjs/pure/create/arkade-to-lightning.d.cts +8 -0
  40. package/dist/types/cjs/pure/create/bitcoin-to-lightning.d.cts +8 -0
  41. package/dist/types/cjs/pure/create/types.d.cts +16 -4
  42. package/dist/types/cjs/pure/evm/coordinator.d.cts +4 -0
  43. package/dist/types/cjs/pure/evm/wallet.d.cts +4 -4
  44. package/dist/types/cjs/pure/generated/api.d.cts +102 -21
  45. package/dist/types/cjs/pure/redeem/arkade.d.cts +4 -1
  46. package/dist/types/cjs/pure/storage/types.d.cts +2 -0
  47. package/dist/types/cjs/pure/swap-verification.d.cts +12 -0
  48. package/dist/types/cjs/pure/tokens.d.cts +0 -6
  49. package/dist/types/cjs/pure/types/dex-quote.d.cts +9 -1
  50. package/dist/types/cjs/pure/version.d.cts +4 -4
  51. package/dist/types/cjs/swap/client.d.cts +2 -0
  52. package/dist/types/esm/pure/cctp/attestation.d.ts +5 -3
  53. package/dist/types/esm/pure/cctp/types.d.ts +11 -2
  54. package/dist/types/esm/pure/cctp-inbound/submit.d.ts +2 -0
  55. package/dist/types/esm/pure/cctp-inbound/types.d.ts +5 -0
  56. package/dist/types/esm/pure/cctp-inbound/userOp.d.ts +11 -0
  57. package/dist/types/esm/pure/client.d.ts +61 -18
  58. package/dist/types/esm/pure/create/arkade-to-lightning.d.ts +8 -0
  59. package/dist/types/esm/pure/create/bitcoin-to-lightning.d.ts +8 -0
  60. package/dist/types/esm/pure/create/types.d.ts +16 -4
  61. package/dist/types/esm/pure/evm/coordinator.d.ts +4 -0
  62. package/dist/types/esm/pure/evm/wallet.d.ts +4 -4
  63. package/dist/types/esm/pure/generated/api.d.ts +102 -21
  64. package/dist/types/esm/pure/redeem/arkade.d.ts +4 -1
  65. package/dist/types/esm/pure/storage/types.d.ts +2 -0
  66. package/dist/types/esm/pure/swap-verification.d.ts +12 -0
  67. package/dist/types/esm/pure/tokens.d.ts +0 -6
  68. package/dist/types/esm/pure/types/dex-quote.d.ts +9 -1
  69. package/dist/types/esm/pure/version.d.ts +4 -4
  70. package/dist/types/esm/swap/client.d.ts +2 -0
  71. package/dist/wallet-33OJRHX5-4VM7QDPO.cjs +31 -0
  72. package/dist/{wallet-THELKUYT-26NOFCTE.cjs.map → wallet-33OJRHX5-4VM7QDPO.cjs.map} +1 -1
  73. package/dist/{wallet-THELKUYT-TOHSMRGU.js → wallet-33OJRHX5-PR4S3NI3.js} +2 -2
  74. package/package.json +1 -1
  75. package/dist/chunk-2LGHF7A3.cjs.map +0 -1
  76. package/dist/chunk-7GOXIT24.cjs.map +0 -1
  77. package/dist/chunk-HWK7LVVX.js.map +0 -1
  78. package/dist/chunk-K4BQUZC6.js.map +0 -1
  79. package/dist/chunk-MYOGO44L.cjs.map +0 -1
  80. package/dist/chunk-S4T4GK5G.js.map +0 -1
  81. package/dist/dist-MMYSP6LP.cjs +0 -394
  82. package/dist/wallet-THELKUYT-26NOFCTE.cjs +0 -31
  83. /package/dist/{dist-L5LHQNRK.js.map → dist-SHY7I6SH.js.map} +0 -0
  84. /package/dist/{fundSwap-IUPFISXM-6IBPJ5O7.js.map → fundSwap-UBCHMUP4-WBLYE6MC.js.map} +0 -0
  85. /package/dist/{wallet-THELKUYT-TOHSMRGU.js.map → wallet-33OJRHX5-PR4S3NI3.js.map} +0 -0
@@ -5,6 +5,39 @@ import {
5
5
  http,
6
6
  publicActions
7
7
  } from "./chunk-5XYV6L5B.js";
8
+ import {
9
+ arbitrum
10
+ } from "./chunk-LSMKNYFR.js";
11
+ import {
12
+ CCTP_DOMAINS,
13
+ IRIS_API_MAINNET,
14
+ MESSAGE_TRANSMITTER_V2
15
+ } from "./chunk-TERXFM2B.js";
16
+ import {
17
+ decodeUint256
18
+ } from "./chunk-2AULREFC.js";
19
+ import {
20
+ createSdkLogger
21
+ } from "./chunk-G6NZFSWU.js";
22
+ import {
23
+ abytes,
24
+ aexists,
25
+ anumber,
26
+ aoutput,
27
+ bytesToHex,
28
+ clean,
29
+ createHasher,
30
+ hexToBytes,
31
+ init_u64,
32
+ init_utils,
33
+ rotlBH,
34
+ rotlBL,
35
+ rotlSH,
36
+ rotlSL,
37
+ split,
38
+ swap32IfBE,
39
+ u32
40
+ } from "./chunk-QUHGKEK4.js";
8
41
  import {
9
42
  bundlerActions,
10
43
  createPaymasterClient,
@@ -26,9 +59,6 @@ import {
26
59
  simulateContract,
27
60
  zeroAddress
28
61
  } from "./chunk-YTHFGOS2.js";
29
- import {
30
- arbitrum
31
- } from "./chunk-LSMKNYFR.js";
32
62
  import {
33
63
  createNonceManager,
34
64
  domainSeparator,
@@ -44,17 +74,6 @@ import {
44
74
  validateTypedData,
45
75
  verifyAuthorization
46
76
  } from "./chunk-ZLR5FXRD.js";
47
- import {
48
- CCTP_DOMAINS,
49
- IRIS_API_MAINNET,
50
- MESSAGE_TRANSMITTER_V2
51
- } from "./chunk-TERXFM2B.js";
52
- import {
53
- decodeUint256
54
- } from "./chunk-K4BQUZC6.js";
55
- import {
56
- createSdkLogger
57
- } from "./chunk-G6NZFSWU.js";
58
77
  import {
59
78
  BaseError3,
60
79
  ContractFunctionRevertedError,
@@ -84,31 +103,12 @@ import {
84
103
  toFunctionSelector,
85
104
  toHex
86
105
  } from "./chunk-KFRNRKGA.js";
87
- import {
88
- abytes,
89
- aexists,
90
- anumber,
91
- aoutput,
92
- bytesToHex,
93
- clean,
94
- createHasher,
95
- hexToBytes,
96
- init_u64,
97
- init_utils,
98
- rotlBH,
99
- rotlBL,
100
- rotlSH,
101
- rotlSL,
102
- split,
103
- swap32IfBE,
104
- u32
105
- } from "./chunk-QUHGKEK4.js";
106
106
  import {
107
107
  __commonJS,
108
108
  __toESM
109
109
  } from "./chunk-Z4J6YUVR.js";
110
110
 
111
- // ../../../ts-pure-sdk/dist/chunk-JAM67C7P.js
111
+ // ../../../ts-pure-sdk/dist/chunk-5VUYBHVC.js
112
112
  var require_constants = __commonJS({
113
113
  "../ts-sdk/node_modules/.pnpm/semver@7.8.1/node_modules/semver/internal/constants.js"(exports, module) {
114
114
  var SEMVER_SPEC_VERSION = "2.0.0";
@@ -2066,13 +2066,14 @@ async function trackCctpMessage(options) {
2066
2066
  await sleep(pollIntervalMs, signal);
2067
2067
  continue;
2068
2068
  }
2069
- if ((msg.forwardState === "COMPLETE" || msg.forwardState === "CONFIRMED") && msg.forwardTxHash) {
2069
+ const deliveryTxHash = msg.forwardState ? (msg.forwardState === "COMPLETE" || msg.forwardState === "CONFIRMED") && msg.forwardTxHash : msg.destinationMintTxHash;
2070
+ if (deliveryTxHash) {
2070
2071
  emitStatus("COMPLETE");
2071
2072
  const cctpSentAmount = msg.decodedMessage?.decodedMessageBody?.amount;
2072
2073
  const cctpPaidFee = msg.decodedMessage?.decodedMessageBody?.feeExecuted;
2073
2074
  return {
2074
2075
  status: "COMPLETE",
2075
- forwardTxHash: msg.forwardTxHash,
2076
+ forwardTxHash: deliveryTxHash,
2076
2077
  amount: cctpSentAmount && cctpPaidFee ? (BigInt(cctpSentAmount) - BigInt(cctpPaidFee)).toString() : void 0,
2077
2078
  feeExecuted: msg.decodedMessage?.decodedMessageBody?.feeExecuted
2078
2079
  };
@@ -7866,6 +7867,22 @@ var EXECUTE_AND_CREATE_WITH_PERMIT2_SELECTOR = keccak2562(
7866
7867
  "executeAndCreateWithPermit2((address,uint256,bytes)[],bytes32,address,address,uint256,address,((address,uint256),uint256,uint256),bytes)"
7867
7868
  )
7868
7869
  ).slice(0, 10);
7870
+ function normalizePermit2Signature(signature, depositorCode) {
7871
+ if (depositorCode !== "0x") return signature;
7872
+ const hex = signature.startsWith("0x") ? signature.slice(2) : signature;
7873
+ if (!/^[0-9a-fA-F]+$/.test(hex) || hex.length !== 128 && hex.length !== 130) {
7874
+ throw new Error("Invalid Permit2 EOA signature: expected 64 or 65 bytes");
7875
+ }
7876
+ if (hex.length === 128) return signature;
7877
+ const v = Number.parseInt(hex.slice(-2), 16);
7878
+ if (v === 27 || v === 28) return signature;
7879
+ if (v !== 0 && v !== 1) {
7880
+ throw new Error(
7881
+ "Invalid Permit2 EOA signature: recovery byte must be 0, 1, 27 or 28"
7882
+ );
7883
+ }
7884
+ return signature.slice(0, -2) + (v + 27).toString(16);
7885
+ }
7869
7886
  function encodeExecuteAndCreateWithPermit2(coordinatorAddress, params) {
7870
7887
  const HEAD_WORDS = 11n;
7871
7888
  const preimageHash = normalizeBytes32(params.preimageHash);
@@ -7879,7 +7896,11 @@ function encodeExecuteAndCreateWithPermit2(coordinatorAddress, params) {
7879
7896
  const permitDeadline = encodeUint2562(params.deadline);
7880
7897
  const callsEncoded = encodeCalls(params.calls);
7881
7898
  const callsEncodedBytes = BigInt(callsEncoded.length / 2);
7882
- const sigClean = params.signature.startsWith("0x") ? params.signature.slice(2) : params.signature;
7899
+ const signature = normalizePermit2Signature(
7900
+ params.signature,
7901
+ params.depositorCode
7902
+ );
7903
+ const sigClean = signature.startsWith("0x") ? signature.slice(2) : signature;
7883
7904
  const sigLength = sigClean.length / 2;
7884
7905
  const sigPaddedLength = Math.ceil(sigLength / 32) * 32;
7885
7906
  const signatureEncoded = encodeUint2562(BigInt(sigLength)) + sigClean.padEnd(sigPaddedLength * 2, "0");
@@ -8185,23 +8206,29 @@ async function buildCctpInboundBatch(params) {
8185
8206
  value: 0n
8186
8207
  });
8187
8208
  }
8188
- const approveData = encodeFunctionData({
8189
- abi: ERC20_APPROVE_ABI,
8190
- functionName: "approve",
8191
- args: [PERMIT2_ADDRESS2, maxUint256]
8192
- });
8193
- calls.push({
8194
- to: checked.sourceToken,
8195
- data: approveData,
8196
- value: 0n
8197
- });
8209
+ const sourceAmount = checked.sourceAmount;
8210
+ const allowance = params.permit2Allowance;
8211
+ if (allowance === void 0 || allowance < sourceAmount) {
8212
+ const approve = (amount) => ({
8213
+ to: checked.sourceToken,
8214
+ data: encodeFunctionData({
8215
+ abi: ERC20_APPROVE_ABI,
8216
+ functionName: "approve",
8217
+ args: [PERMIT2_ADDRESS2, amount]
8218
+ }),
8219
+ value: 0n
8220
+ });
8221
+ if (allowance !== void 0 && allowance > 0n) {
8222
+ calls.push(approve(0n));
8223
+ }
8224
+ calls.push(approve(maxUint256));
8225
+ }
8198
8226
  const nonceBytes = new Uint8Array(32);
8199
8227
  crypto.getRandomValues(nonceBytes);
8200
8228
  const permit2Nonce = BigInt(
8201
8229
  `0x${Array.from(nonceBytes).map((b) => b.toString(16).padStart(2, "0")).join("")}`
8202
8230
  );
8203
8231
  const permit2Deadline = BigInt(Math.floor(Date.now() / 1e3) + 30 * 60);
8204
- const sourceAmount = checked.sourceAmount;
8205
8232
  const typedData = buildPermit2TypedData({
8206
8233
  chainId,
8207
8234
  coordinatorAddress: checked.coordinator,
@@ -8265,6 +8292,18 @@ async function buildCctpInboundBatch(params) {
8265
8292
  function addressToBytes32Hex(address) {
8266
8293
  return encodeAbiParameters([{ type: "address" }], [address]);
8267
8294
  }
8295
+ var ALLOWANCE_ABI = [
8296
+ {
8297
+ type: "function",
8298
+ name: "allowance",
8299
+ stateMutability: "view",
8300
+ inputs: [
8301
+ { name: "owner", type: "address" },
8302
+ { name: "spender", type: "address" }
8303
+ ],
8304
+ outputs: [{ name: "", type: "uint256" }]
8305
+ }
8306
+ ];
8268
8307
  function extractNonce(cctpMessage) {
8269
8308
  return `0x${cctpMessage.slice(26, 26 + 64)}`;
8270
8309
  }
@@ -8313,6 +8352,17 @@ async function sendBalanceUserOp(context, params) {
8313
8352
  chain,
8314
8353
  transport: http(aa.rpcUrl ?? aa.bundlerUrl)
8315
8354
  });
8355
+ let permit2Allowance;
8356
+ try {
8357
+ permit2Allowance = await publicClient.readContract({
8358
+ address: params.expected.terms.sourceToken,
8359
+ abi: ALLOWANCE_ABI,
8360
+ functionName: "allowance",
8361
+ args: [accountAddress, PERMIT2_ADDRESS2]
8362
+ });
8363
+ } catch {
8364
+ permit2Allowance = void 0;
8365
+ }
8316
8366
  const { calls } = await buildCctpInboundBatch({
8317
8367
  server,
8318
8368
  expected: params.expected,
@@ -8321,7 +8371,8 @@ async function sendBalanceUserOp(context, params) {
8321
8371
  cctpMessage: "0x",
8322
8372
  cctpAttestation: "0x",
8323
8373
  chainId: chain.id,
8324
- skipReceiveMessage: true
8374
+ skipReceiveMessage: true,
8375
+ permit2Allowance
8325
8376
  });
8326
8377
  if (preflightSimulate) {
8327
8378
  await simulateBatchCalls({
@@ -8332,7 +8383,35 @@ async function sendBalanceUserOp(context, params) {
8332
8383
  logLevel: params.logLevel
8333
8384
  });
8334
8385
  }
8335
- const userOpHash = await aaClient.sendUserOperation({ calls });
8386
+ let userOpHash;
8387
+ if (params.onSigned) {
8388
+ const { formatUserOperationRequest, getUserOperationHash: getUserOperationHash2 } = await import("./account-abstraction-XCNTC4D6-PLCCZSTC.js");
8389
+ const prepared = await aaClient.prepareUserOperation({ calls });
8390
+ const signed = {
8391
+ ...prepared,
8392
+ signature: await smartAccount.signUserOperation(prepared)
8393
+ };
8394
+ const entryPoint = smartAccount.entryPoint;
8395
+ userOpHash = getUserOperationHash2({
8396
+ chainId: chain.id,
8397
+ entryPointAddress: entryPoint.address,
8398
+ entryPointVersion: entryPoint.version,
8399
+ userOperation: signed
8400
+ });
8401
+ await params.onSigned(userOpHash);
8402
+ await aaClient.request(
8403
+ {
8404
+ method: "eth_sendUserOperation",
8405
+ params: [
8406
+ formatUserOperationRequest(signed),
8407
+ entryPoint.address
8408
+ ]
8409
+ },
8410
+ { retryCount: 0 }
8411
+ );
8412
+ } else {
8413
+ userOpHash = await aaClient.sendUserOperation({ calls });
8414
+ }
8336
8415
  if (noWait) {
8337
8416
  return { userOpHash, smartAccountAddress: accountAddress };
8338
8417
  }
@@ -8478,4 +8557,4 @@ export {
8478
8557
  submitCctpInboundBalanceUserOp,
8479
8558
  submitCctpInboundUserOp
8480
8559
  };
8481
- //# sourceMappingURL=chunk-HWK7LVVX.js.map
8560
+ //# sourceMappingURL=chunk-JHZHRY7S.js.map