@anywalletkit/protocol-swap2-0x 0.1.6 → 0.3.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 +31 -6
  2. package/dist/activity.cjs +4 -3
  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 +16 -2
  8. package/dist/chains.cjs.map +1 -1
  9. package/dist/chains.d.cts +26 -6
  10. package/dist/chains.d.ts +26 -6
  11. package/dist/chains.js +5 -1
  12. package/dist/{chunk-ALMGGQS4.js → chunk-ABT2WYBK.js} +6 -6
  13. package/dist/{chunk-ALMGGQS4.js.map → chunk-ABT2WYBK.js.map} +1 -1
  14. package/dist/{chunk-CWZCAJBY.js → chunk-AMZ5DXN2.js} +17 -3
  15. package/dist/chunk-AMZ5DXN2.js.map +1 -0
  16. package/dist/{chunk-AX4RNHWE.js → chunk-KYVRMBZG.js} +2 -2
  17. package/dist/{chunk-RLNXMQJH.js → chunk-S2RUUV3X.js} +16 -6
  18. package/dist/chunk-S2RUUV3X.js.map +1 -0
  19. package/dist/{chunk-QFOKBJXP.js → chunk-V4HUFBY2.js} +5 -5
  20. package/dist/chunk-V4HUFBY2.js.map +1 -0
  21. package/dist/{chunk-NK3PQGI4.js → chunk-YHRPT6BS.js} +20 -5
  22. package/dist/chunk-YHRPT6BS.js.map +1 -0
  23. package/dist/index.cjs +46 -10
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +3 -3
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.js +16 -6
  28. package/dist/protocol.cjs +40 -9
  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 -9
  34. package/dist/provider.cjs.map +1 -1
  35. package/dist/provider.d.cts +13 -6
  36. package/dist/provider.d.ts +13 -6
  37. package/dist/provider.js +6 -4
  38. package/dist/remote.cjs +34 -9
  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 +20 -4
  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 +6 -6
  52. package/dist/chunk-CWZCAJBY.js.map +0 -1
  53. package/dist/chunk-NK3PQGI4.js.map +0 -1
  54. package/dist/chunk-QFOKBJXP.js.map +0 -1
  55. package/dist/chunk-RLNXMQJH.js.map +0 -1
  56. /package/dist/{chunk-AX4RNHWE.js.map → chunk-KYVRMBZG.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { CrossChainProvider, Quote, UnsignedTx } from '@anywalletkit/protocol-swap2-core/types';
2
2
  import { ZeroExChain } from './chains.cjs';
3
- import { f as SettlerResolver, v as RpcUrls } from './settler-KDFcfsKv.cjs';
3
+ import { f as SettlerResolver, x as RpcUrls } from './settler-CeJFLW5t.cjs';
4
4
  import '@anywalletkit/protocol-swap2-core/errors';
5
5
  import '@anywalletkit/protocol-swap2-core/util';
6
6
 
@@ -63,6 +63,13 @@ declare function zeroExFees(response: Record<string, unknown>, gas: {
63
63
  fees: Fee[];
64
64
  networkFeeKnown: boolean;
65
65
  } | string;
66
+ /**
67
+ * A quote's `gasEstimate`: 0x's own gas figure for the call — `transaction.gas` on a live quote, `gas` on an indicative
68
+ * price — as canonical digits, read the way the gas limit and the network fee read it (decimal digits only). Undefined
69
+ * when 0x states none, zero, a figure in another notation, or one past the contract's ten digits: no figure is made up.
70
+ * 0x calls it the gas limit to send with; measured against the gas the call used, it runs high (see the README).
71
+ */
72
+ declare function zeroExGasEstimate(gas: unknown): string | undefined;
66
73
  /** What {@link zeroExProvider} returns: a swap2 provider, plus the Settler resolver it reads through (for signing policies, `zeroExKnownSpenders`). */
67
74
  type ZeroExProvider = CrossChainProvider & {
68
75
  readonly ownGasEstimate: true;
@@ -71,14 +78,14 @@ type ZeroExProvider = CrossChainProvider & {
71
78
  declare function zeroExProvider(config: ZeroExProviderConfig): ZeroExProvider;
72
79
  /**
73
80
  * The device's last check before the engine signs a 0x swap, run by the `preflightDeposit` of both providers (in remote
74
- * mode before the backend's own preflight is asked): the transaction must be the quoted one, and its target must still
75
- * be a Settler the registry names now — a fresh read through `resolver` (the device's own RPC), so a Settler paused,
76
- * replaced or removed since the quote (on the review screen, during an approval) is refused here, with nothing signed
77
- * or sent.
81
+ * mode before the backend's own preflight is asked): the transaction must be the quoted one, its gas limit (when it
82
+ * carries one) within the chain's cap, and its target must still be a Settler the registry names now — a fresh read
83
+ * through `resolver` (the device's own RPC), so a Settler paused, replaced or removed since the quote (on the review
84
+ * screen, during an approval) is refused here, with nothing signed or sent.
78
85
  */
79
86
  declare function zeroExPreflightDeposit(quote: Quote, tx: UnsignedTx, ctx: {
80
87
  chains: Readonly<Record<number, ZeroExChain>>;
81
88
  resolver: SettlerResolver;
82
89
  }): Promise<void>;
83
90
 
84
- export { ZEROEX_DEFAULT_BASE_URL, ZEROEX_PROVIDER, type ZeroExProvider, type ZeroExProviderConfig, zeroExFees, zeroExPreflightDeposit, zeroExProvider };
91
+ export { ZEROEX_DEFAULT_BASE_URL, ZEROEX_PROVIDER, type ZeroExProvider, type ZeroExProviderConfig, zeroExFees, zeroExGasEstimate, zeroExPreflightDeposit, zeroExProvider };
@@ -1,6 +1,6 @@
1
1
  import { CrossChainProvider, Quote, UnsignedTx } from '@anywalletkit/protocol-swap2-core/types';
2
2
  import { ZeroExChain } from './chains.js';
3
- import { f as SettlerResolver, v as RpcUrls } from './settler-BpRGkBVV.js';
3
+ import { f as SettlerResolver, x as RpcUrls } from './settler-DBLrnepW.js';
4
4
  import '@anywalletkit/protocol-swap2-core/errors';
5
5
  import '@anywalletkit/protocol-swap2-core/util';
6
6
 
@@ -63,6 +63,13 @@ declare function zeroExFees(response: Record<string, unknown>, gas: {
63
63
  fees: Fee[];
64
64
  networkFeeKnown: boolean;
65
65
  } | string;
66
+ /**
67
+ * A quote's `gasEstimate`: 0x's own gas figure for the call — `transaction.gas` on a live quote, `gas` on an indicative
68
+ * price — as canonical digits, read the way the gas limit and the network fee read it (decimal digits only). Undefined
69
+ * when 0x states none, zero, a figure in another notation, or one past the contract's ten digits: no figure is made up.
70
+ * 0x calls it the gas limit to send with; measured against the gas the call used, it runs high (see the README).
71
+ */
72
+ declare function zeroExGasEstimate(gas: unknown): string | undefined;
66
73
  /** What {@link zeroExProvider} returns: a swap2 provider, plus the Settler resolver it reads through (for signing policies, `zeroExKnownSpenders`). */
67
74
  type ZeroExProvider = CrossChainProvider & {
68
75
  readonly ownGasEstimate: true;
@@ -71,14 +78,14 @@ type ZeroExProvider = CrossChainProvider & {
71
78
  declare function zeroExProvider(config: ZeroExProviderConfig): ZeroExProvider;
72
79
  /**
73
80
  * The device's last check before the engine signs a 0x swap, run by the `preflightDeposit` of both providers (in remote
74
- * mode before the backend's own preflight is asked): the transaction must be the quoted one, and its target must still
75
- * be a Settler the registry names now — a fresh read through `resolver` (the device's own RPC), so a Settler paused,
76
- * replaced or removed since the quote (on the review screen, during an approval) is refused here, with nothing signed
77
- * or sent.
81
+ * mode before the backend's own preflight is asked): the transaction must be the quoted one, its gas limit (when it
82
+ * carries one) within the chain's cap, and its target must still be a Settler the registry names now — a fresh read
83
+ * through `resolver` (the device's own RPC), so a Settler paused, replaced or removed since the quote (on the review
84
+ * screen, during an approval) is refused here, with nothing signed or sent.
78
85
  */
79
86
  declare function zeroExPreflightDeposit(quote: Quote, tx: UnsignedTx, ctx: {
80
87
  chains: Readonly<Record<number, ZeroExChain>>;
81
88
  resolver: SettlerResolver;
82
89
  }): Promise<void>;
83
90
 
84
- export { ZEROEX_DEFAULT_BASE_URL, ZEROEX_PROVIDER, type ZeroExProvider, type ZeroExProviderConfig, zeroExFees, zeroExPreflightDeposit, zeroExProvider };
91
+ export { ZEROEX_DEFAULT_BASE_URL, ZEROEX_PROVIDER, type ZeroExProvider, type ZeroExProviderConfig, zeroExFees, zeroExGasEstimate, zeroExPreflightDeposit, zeroExProvider };
package/dist/provider.js CHANGED
@@ -2,16 +2,18 @@ import {
2
2
  ZEROEX_DEFAULT_BASE_URL,
3
3
  ZEROEX_PROVIDER,
4
4
  zeroExFees,
5
+ zeroExGasEstimate,
5
6
  zeroExPreflightDeposit,
6
7
  zeroExProvider
7
- } from "./chunk-RLNXMQJH.js";
8
- import "./chunk-QFOKBJXP.js";
9
- import "./chunk-NK3PQGI4.js";
10
- import "./chunk-CWZCAJBY.js";
8
+ } from "./chunk-S2RUUV3X.js";
9
+ import "./chunk-V4HUFBY2.js";
10
+ import "./chunk-YHRPT6BS.js";
11
+ import "./chunk-AMZ5DXN2.js";
11
12
  export {
12
13
  ZEROEX_DEFAULT_BASE_URL,
13
14
  ZEROEX_PROVIDER,
14
15
  zeroExFees,
16
+ zeroExGasEstimate,
15
17
  zeroExPreflightDeposit,
16
18
  zeroExProvider
17
19
  };
package/dist/remote.cjs CHANGED
@@ -43,14 +43,17 @@ var ZEROEX_PERMIT2 = import_util.PERMIT2_ADDRESS;
43
43
  var ZEROEX_SETTLER_REGISTRY = "0x00000000000004533Fe15556B1E086BB1A72cEae";
44
44
  var ZEROEX_TAKER_FEATURE = 2;
45
45
  var ZEROEX_NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
46
+ var ZEROEX_GAS_CAP_CEILING = 30000000n;
47
+ var isZeroExGasCap = (v) => typeof v === "bigint" && v >= 1n && v <= ZEROEX_GAS_CAP_CEILING;
46
48
  var ZEROEX_SETTLER_NONCE_MARGIN = 2;
47
49
  var ZEROEX_SETTLER_MAX_NONCE = 1024;
48
- var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative });
50
+ var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce, maxGasLimit) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative, ...maxGasLimit !== void 0 ? { maxGasLimit } : {} });
49
51
  var ZEROEX_CHAINS = Object.freeze({
50
52
  1: chain("Ethereum", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 22, 21),
51
53
  10: chain("Optimism", "0x4200000000000000000000000000000000000006", 22, 21),
52
54
  56: chain("BNB Smart Chain", "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", 24, 23),
53
55
  137: chain("Polygon", "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", 21, 20),
56
+ 143: chain("Monad", "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A", 12, 11, 15000000n),
54
57
  8453: chain("Base", "0x4200000000000000000000000000000000000006", 23, 22),
55
58
  42161: chain("Arbitrum", "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", 21, 20),
56
59
  43114: chain("Avalanche", "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", 21, 20)
@@ -79,7 +82,16 @@ function zeroExChains(overrides) {
79
82
  if (!Number.isSafeInteger(previous) || previous < 1 || previous > newest) {
80
83
  throw new Error(`zeroex: chain ${id} pins no previous live Settler deployment (previousLiveNonce, 1 to its newestLiveNonce)`);
81
84
  }
82
- out[id] = Object.freeze({ name: entry.name, registry: entry.registry, newestLiveNonce: newest, previousLiveNonce: previous, ...entry.wrappedNative ? { wrappedNative: entry.wrappedNative } : {} });
85
+ const gasCap = entry.maxGasLimit;
86
+ 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}`);
87
+ out[id] = Object.freeze({
88
+ name: entry.name,
89
+ registry: entry.registry,
90
+ newestLiveNonce: newest,
91
+ previousLiveNonce: previous,
92
+ ...entry.wrappedNative ? { wrappedNative: entry.wrappedNative } : {},
93
+ ...gasCap !== void 0 ? { maxGasLimit: gasCap } : {}
94
+ });
83
95
  }
84
96
  return Object.freeze(out);
85
97
  }
@@ -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;
@@ -428,7 +451,9 @@ async function zeroExPreflightDeposit(quote, tx, ctx) {
428
451
  throw (0, import_errors2.refusal)("policy_refused", "zeroex: the transaction is not the quoted swap. Nothing was sent; refresh the quote.");
429
452
  }
430
453
  const chainId = typeof quote.intentId === "string" ? Number(quote.intentId.split(":")[1]) : NaN;
431
- if (!zeroExChain(ctx.chains, chainId)) throw (0, import_errors2.refusal)("policy_refused", "zeroex: the quote names no chain this provider serves. Nothing was sent.");
454
+ const chain2 = zeroExChain(ctx.chains, chainId);
455
+ if (!chain2) throw (0, import_errors2.refusal)("policy_refused", "zeroex: the quote names no chain this provider serves. Nothing was sent.");
456
+ checkZeroExGasLimit(tx.gasLimit, chain2, chainId);
432
457
  const settlers = await ctx.resolver.resolve(chainId, { fresh: true });
433
458
  if (!settlers.some((s) => same2(s, quoted.to))) {
434
459
  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.");
@@ -567,7 +592,7 @@ function zeroExRemoteProvider(options) {
567
592
  });
568
593
  return {
569
594
  ...inner,
570
- describeActivity: describeZeroExActivity,
595
+ describeActivity: (tx, ctx) => describeZeroExActivity(tx, ctx, pins.chains),
571
596
  // The quoted gas limit is the backend's word: every call goes out with the account's own estimate.
572
597
  ownGasEstimate: true,
573
598
  settlerResolver: pins.resolver,