@anywalletkit/protocol-swap2-0x 0.1.5 → 0.2.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.
Files changed (56) hide show
  1. package/README.md +12 -6
  2. package/dist/activity.cjs +11 -10
  3. package/dist/activity.cjs.map +1 -1
  4. package/dist/activity.d.cts +6 -1
  5. package/dist/activity.d.ts +6 -1
  6. package/dist/activity.js +3 -3
  7. package/dist/chains.cjs +23 -9
  8. package/dist/chains.cjs.map +1 -1
  9. package/dist/chains.d.cts +26 -5
  10. package/dist/chains.d.ts +26 -5
  11. package/dist/chains.js +5 -1
  12. package/dist/{chunk-MMOBCJEO.js → chunk-AMZ5DXN2.js} +24 -10
  13. package/dist/chunk-AMZ5DXN2.js.map +1 -0
  14. package/dist/{chunk-R7VDTSDK.js → chunk-PLQSYP6W.js} +9 -6
  15. package/dist/chunk-PLQSYP6W.js.map +1 -0
  16. package/dist/{chunk-WP7CUXWT.js → chunk-SAI3RXOP.js} +6 -6
  17. package/dist/{chunk-WP7CUXWT.js.map → chunk-SAI3RXOP.js.map} +1 -1
  18. package/dist/{chunk-HDMLWKPW.js → chunk-V4HUFBY2.js} +5 -5
  19. package/dist/chunk-V4HUFBY2.js.map +1 -0
  20. package/dist/{chunk-7VM4FURF.js → chunk-VPQZVV5O.js} +2 -2
  21. package/dist/{chunk-VSYAAW22.js → chunk-YHRPT6BS.js} +20 -5
  22. package/dist/chunk-YHRPT6BS.js.map +1 -0
  23. package/dist/index.cjs +46 -17
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +2 -2
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +14 -6
  28. package/dist/protocol.cjs +41 -16
  29. package/dist/protocol.cjs.map +1 -1
  30. package/dist/protocol.d.cts +1 -1
  31. package/dist/protocol.d.ts +1 -1
  32. package/dist/protocol.js +5 -5
  33. package/dist/provider.cjs +41 -16
  34. package/dist/provider.cjs.map +1 -1
  35. package/dist/provider.d.cts +5 -5
  36. package/dist/provider.d.ts +5 -5
  37. package/dist/provider.js +4 -4
  38. package/dist/remote.cjs +41 -16
  39. package/dist/remote.cjs.map +1 -1
  40. package/dist/remote.d.cts +1 -1
  41. package/dist/remote.d.ts +1 -1
  42. package/dist/remote.js +5 -5
  43. package/dist/{settler-KDFcfsKv.d.cts → settler-CeJFLW5t.d.cts} +21 -4
  44. package/dist/{settler-BpRGkBVV.d.ts → settler-DBLrnepW.d.ts} +21 -4
  45. package/dist/settler.cjs +27 -11
  46. package/dist/settler.cjs.map +1 -1
  47. package/dist/settler.d.cts +1 -1
  48. package/dist/settler.d.ts +1 -1
  49. package/dist/settler.js +6 -2
  50. package/module.json +1 -0
  51. package/package.json +4 -4
  52. package/dist/chunk-HDMLWKPW.js.map +0 -1
  53. package/dist/chunk-MMOBCJEO.js.map +0 -1
  54. package/dist/chunk-R7VDTSDK.js.map +0 -1
  55. package/dist/chunk-VSYAAW22.js.map +0 -1
  56. /package/dist/{chunk-7VM4FURF.js.map → chunk-VPQZVV5O.js.map} +0 -0
@@ -3,7 +3,7 @@ import { SingleProviderSwap2 } from '@anywalletkit/protocol-swap2-core/swap2/sin
3
3
  import { Swap2EngineConfig, Swap2Account } from '@anywalletkit/protocol-swap2-core/swap2/base';
4
4
  import '@anywalletkit/protocol-swap2-core/types';
5
5
  import './chains.cjs';
6
- import './settler-KDFcfsKv.cjs';
6
+ import './settler-CeJFLW5t.cjs';
7
7
  import '@anywalletkit/protocol-swap2-core/errors';
8
8
  import '@anywalletkit/protocol-swap2-core/util';
9
9
 
@@ -3,7 +3,7 @@ import { SingleProviderSwap2 } from '@anywalletkit/protocol-swap2-core/swap2/sin
3
3
  import { Swap2EngineConfig, Swap2Account } from '@anywalletkit/protocol-swap2-core/swap2/base';
4
4
  import '@anywalletkit/protocol-swap2-core/types';
5
5
  import './chains.js';
6
- import './settler-BpRGkBVV.js';
6
+ import './settler-DBLrnepW.js';
7
7
  import '@anywalletkit/protocol-swap2-core/errors';
8
8
  import '@anywalletkit/protocol-swap2-core/util';
9
9
 
package/dist/protocol.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  ZeroExSwap2Protocol
3
- } from "./chunk-7VM4FURF.js";
4
- import "./chunk-R7VDTSDK.js";
5
- import "./chunk-HDMLWKPW.js";
6
- import "./chunk-VSYAAW22.js";
7
- import "./chunk-MMOBCJEO.js";
3
+ } from "./chunk-VPQZVV5O.js";
4
+ import "./chunk-PLQSYP6W.js";
5
+ import "./chunk-V4HUFBY2.js";
6
+ import "./chunk-YHRPT6BS.js";
7
+ import "./chunk-AMZ5DXN2.js";
8
8
  export {
9
9
  ZeroExSwap2Protocol
10
10
  };
package/dist/provider.cjs CHANGED
@@ -42,17 +42,20 @@ var ZEROEX_PERMIT2 = import_util.PERMIT2_ADDRESS;
42
42
  var ZEROEX_SETTLER_REGISTRY = "0x00000000000004533Fe15556B1E086BB1A72cEae";
43
43
  var ZEROEX_TAKER_FEATURE = 2;
44
44
  var ZEROEX_NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
45
+ var ZEROEX_GAS_CAP_CEILING = 30000000n;
46
+ var isZeroExGasCap = (v) => typeof v === "bigint" && v >= 1n && v <= ZEROEX_GAS_CAP_CEILING;
45
47
  var ZEROEX_SETTLER_NONCE_MARGIN = 2;
46
48
  var ZEROEX_SETTLER_MAX_NONCE = 1024;
47
- var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative });
49
+ var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce, maxGasLimit) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative, ...maxGasLimit !== void 0 ? { maxGasLimit } : {} });
48
50
  var ZEROEX_CHAINS = Object.freeze({
49
- 1: chain("Ethereum", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 21, 20),
50
- 10: chain("Optimism", "0x4200000000000000000000000000000000000006", 21, 20),
51
- 56: chain("BNB Smart Chain", "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", 23, 22),
52
- 137: chain("Polygon", "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", 20, 19),
53
- 8453: chain("Base", "0x4200000000000000000000000000000000000006", 22, 21),
54
- 42161: chain("Arbitrum", "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", 20, 19),
55
- 43114: chain("Avalanche", "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", 20, 19)
51
+ 1: chain("Ethereum", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 22, 21),
52
+ 10: chain("Optimism", "0x4200000000000000000000000000000000000006", 22, 21),
53
+ 56: chain("BNB Smart Chain", "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", 24, 23),
54
+ 137: chain("Polygon", "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", 21, 20),
55
+ 143: chain("Monad", "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A", 12, 11, 15000000n),
56
+ 8453: chain("Base", "0x4200000000000000000000000000000000000006", 23, 22),
57
+ 42161: chain("Arbitrum", "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", 21, 20),
58
+ 43114: chain("Avalanche", "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", 21, 20)
56
59
  });
57
60
  var ADDRESS = /^0x[0-9a-fA-F]{40}$/;
58
61
  var ZERO_ADDRESS = /^0x0{40}$/;
@@ -78,7 +81,16 @@ function zeroExChains(overrides) {
78
81
  if (!Number.isSafeInteger(previous) || previous < 1 || previous > newest) {
79
82
  throw new Error(`zeroex: chain ${id} pins no previous live Settler deployment (previousLiveNonce, 1 to its newestLiveNonce)`);
80
83
  }
81
- out[id] = Object.freeze({ name: entry.name, registry: entry.registry, newestLiveNonce: newest, previousLiveNonce: previous, ...entry.wrappedNative ? { wrappedNative: entry.wrappedNative } : {} });
84
+ const gasCap = entry.maxGasLimit;
85
+ if (gasCap !== void 0 && !isZeroExGasCap(gasCap)) throw new Error(`zeroex: chain ${id} gas cap (maxGasLimit) is not a bigint from 1 to ${ZEROEX_GAS_CAP_CEILING}`);
86
+ out[id] = Object.freeze({
87
+ name: entry.name,
88
+ registry: entry.registry,
89
+ newestLiveNonce: newest,
90
+ previousLiveNonce: previous,
91
+ ...entry.wrappedNative ? { wrappedNative: entry.wrappedNative } : {},
92
+ ...gasCap !== void 0 ? { maxGasLimit: gasCap } : {}
93
+ });
82
94
  }
83
95
  return Object.freeze(out);
84
96
  }
@@ -311,6 +323,19 @@ function decodeSettlerExecute(data) {
311
323
  return Object.freeze({ recipient, buyToken, minAmountOut, zidAndAffiliate, actions: Object.freeze(actions), bodyLength, word });
312
324
  }
313
325
  var ZEROEX_MAX_GAS_LIMIT = 6000000n;
326
+ function zeroExMaxGasLimit(chain2, chainId) {
327
+ const cap = chain2.maxGasLimit;
328
+ if (cap === void 0) return ZEROEX_MAX_GAS_LIMIT;
329
+ if (!isZeroExGasCap(cap)) throw refuse(`the chain table's gas cap${chainId !== void 0 ? ` for chain ${chainId}` : ""} is not a bigint from 1 to ${ZEROEX_GAS_CAP_CEILING}`);
330
+ return cap;
331
+ }
332
+ function checkZeroExGasLimit(gasLimit, chain2, chainId) {
333
+ const cap = zeroExMaxGasLimit(chain2, chainId);
334
+ if (gasLimit === void 0) return;
335
+ if (typeof gasLimit !== "string" || !/^[0-9]{1,12}$/.test(gasLimit) || BigInt(gasLimit) === 0n || BigInt(gasLimit) > cap) {
336
+ throw refuse(`the transaction asks for more gas than any 0x swap needs (its gas limit must be 1 to ${cap} on chain ${chainId})`, "policy_refused");
337
+ }
338
+ }
314
339
  function checkZeroExTransaction(tx, expected) {
315
340
  if (!Number.isSafeInteger(expected.chainId) || expected.chainId <= 0) throw refuse("the swap names no EVM chain");
316
341
  if (!ADDRESS2.test(expected.recipient) || ZERO_ADDRESS2.test(expected.recipient)) throw refuse("the swap names no recipient");
@@ -334,9 +359,7 @@ function checkZeroExTransaction(tx, expected) {
334
359
  if (value > 0n && deployment !== pin.newestLiveNonce && deployment !== pin.previousLiveNonce) {
335
360
  throw refuse(deployment > pin.newestLiveNonce ? `the swap sends native coin to Settler deployment ${deployment} (${to}) on chain ${expected.chainId}, newer than the newest one live when this module's chain table was pinned (${pin.newestLiveNonce}) \u2014 a native-coin sale goes only to a pinned Settler: update @anywalletkit/protocol-swap2-0x` : `the swap sends native coin to Settler deployment ${deployment} (${to}) on chain ${expected.chainId}, which was not live when this module's chain table was pinned (${pin.newestLiveNonce} and ${pin.previousLiveNonce} were) \u2014 a native-coin sale goes only to a pinned Settler`, "vault_mismatch");
336
361
  }
337
- if (tx.gasLimit !== void 0 && (typeof tx.gasLimit !== "string" || !/^[0-9]{1,12}$/.test(tx.gasLimit) || BigInt(tx.gasLimit) === 0n || BigInt(tx.gasLimit) > ZEROEX_MAX_GAS_LIMIT)) {
338
- throw refuse("the transaction asks for more gas than any 0x swap needs", "policy_refused");
339
- }
362
+ checkZeroExGasLimit(tx.gasLimit, pin, expected.chainId);
340
363
  if (typeof tx.data !== "string") throw refuse("the transaction has no data", "policy_refused");
341
364
  const execute = decodeSettlerExecute(tx.data);
342
365
  if (!same(execute.recipient, expected.recipient)) throw refuse(`the swap pays ${execute.recipient}, not the recipient of this swap`, "recipient_mismatch");
@@ -380,9 +403,9 @@ function checkZeroExTransaction(tx, expected) {
380
403
 
381
404
  // src/activity.ts
382
405
  var ZEROEX_MODULE = "@anywalletkit/protocol-swap2-0x";
383
- function describeZeroExActivity(tx, ctx) {
406
+ function describeZeroExActivity(tx, ctx, chains = ZEROEX_CHAINS) {
384
407
  const chainId = zeroExChainId(tx.chain);
385
- const chain2 = zeroExChain(ZEROEX_CHAINS, chainId);
408
+ const chain2 = zeroExChain(chains, chainId);
386
409
  if (!chain2) return null;
387
410
  if ((0, import_activity.callSelector)(tx) !== SETTLER_EXECUTE_SELECTOR) return null;
388
411
  const target = tx.call?.to ?? tx.to;
@@ -533,7 +556,7 @@ function zeroExProvider(config) {
533
556
  };
534
557
  return {
535
558
  name: ZEROEX_PROVIDER,
536
- describeActivity: describeZeroExActivity,
559
+ describeActivity: (tx, ctx) => describeZeroExActivity(tx, ctx, chains),
537
560
  supportsSameChain: true,
538
561
  // The quoted gas limit is the API's word: a native sale (like a Permit2 call) goes out with the account's own estimate.
539
562
  ownGasEstimate: true,
@@ -844,7 +867,9 @@ async function zeroExPreflightDeposit(quote, tx, ctx) {
844
867
  throw (0, import_errors2.refusal)("policy_refused", "zeroex: the transaction is not the quoted swap. Nothing was sent; refresh the quote.");
845
868
  }
846
869
  const chainId = typeof quote.intentId === "string" ? Number(quote.intentId.split(":")[1]) : NaN;
847
- if (!zeroExChain(ctx.chains, chainId)) throw (0, import_errors2.refusal)("policy_refused", "zeroex: the quote names no chain this provider serves. Nothing was sent.");
870
+ const chain2 = zeroExChain(ctx.chains, chainId);
871
+ if (!chain2) throw (0, import_errors2.refusal)("policy_refused", "zeroex: the quote names no chain this provider serves. Nothing was sent.");
872
+ checkZeroExGasLimit(tx.gasLimit, chain2, chainId);
848
873
  const settlers = await ctx.resolver.resolve(chainId, { fresh: true });
849
874
  if (!settlers.some((s) => same2(s, quoted.to))) {
850
875
  throw (0, import_errors2.refusal)("vault_mismatch", "zeroex: the quoted 0x Settler is no longer in the on-chain registry. Nothing was sent; refresh the quote.");