@anywalletkit/protocol-swap2-0x 0.0.0-stage → 0.1.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 (60) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +172 -2
  3. package/dist/activity.cjs +168 -0
  4. package/dist/activity.cjs.map +1 -0
  5. package/dist/activity.d.cts +18 -0
  6. package/dist/activity.d.ts +18 -0
  7. package/dist/activity.js +11 -0
  8. package/dist/activity.js.map +1 -0
  9. package/dist/chains.cjs +88 -0
  10. package/dist/chains.cjs.map +1 -0
  11. package/dist/chains.d.cts +64 -0
  12. package/dist/chains.d.ts +64 -0
  13. package/dist/chains.js +27 -0
  14. package/dist/chains.js.map +1 -0
  15. package/dist/chunk-AOJSV3QG.js +498 -0
  16. package/dist/chunk-AOJSV3QG.js.map +1 -0
  17. package/dist/chunk-F6QOUZC7.js +24 -0
  18. package/dist/chunk-F6QOUZC7.js.map +1 -0
  19. package/dist/chunk-HDMLWKPW.js +38 -0
  20. package/dist/chunk-HDMLWKPW.js.map +1 -0
  21. package/dist/chunk-MBQ2WFQW.js +207 -0
  22. package/dist/chunk-MBQ2WFQW.js.map +1 -0
  23. package/dist/chunk-MMOBCJEO.js +68 -0
  24. package/dist/chunk-MMOBCJEO.js.map +1 -0
  25. package/dist/chunk-VSYAAW22.js +323 -0
  26. package/dist/chunk-VSYAAW22.js.map +1 -0
  27. package/dist/index.cjs +1098 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +13 -0
  30. package/dist/index.d.ts +13 -0
  31. package/dist/index.js +102 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/protocol.cjs +879 -0
  34. package/dist/protocol.cjs.map +1 -0
  35. package/dist/protocol.d.cts +20 -0
  36. package/dist/protocol.d.ts +20 -0
  37. package/dist/protocol.js +11 -0
  38. package/dist/protocol.js.map +1 -0
  39. package/dist/provider.cjs +865 -0
  40. package/dist/provider.cjs.map +1 -0
  41. package/dist/provider.d.cts +84 -0
  42. package/dist/provider.d.ts +84 -0
  43. package/dist/provider.js +18 -0
  44. package/dist/provider.js.map +1 -0
  45. package/dist/remote.cjs +609 -0
  46. package/dist/remote.cjs.map +1 -0
  47. package/dist/remote.d.cts +93 -0
  48. package/dist/remote.d.ts +93 -0
  49. package/dist/remote.js +21 -0
  50. package/dist/remote.js.map +1 -0
  51. package/dist/settler-BpRGkBVV.d.ts +196 -0
  52. package/dist/settler-KDFcfsKv.d.cts +196 -0
  53. package/dist/settler.cjs +352 -0
  54. package/dist/settler.cjs.map +1 -0
  55. package/dist/settler.d.cts +4 -0
  56. package/dist/settler.d.ts +4 -0
  57. package/dist/settler.js +42 -0
  58. package/dist/settler.js.map +1 -0
  59. package/module.json +22 -0
  60. package/package.json +98 -3
@@ -0,0 +1,196 @@
1
+ import { Swap2RefusalReason } from '@anywalletkit/protocol-swap2-core/errors';
2
+ import { Permit2Transfer } from '@anywalletkit/protocol-swap2-core/util';
3
+ import { ZeroExChain } from './chains.js';
4
+
5
+ type RpcUrls = Readonly<Record<number, readonly string[]>>;
6
+
7
+ /** `execute((address recipient, address buyToken, uint256 minAmountOut), bytes[] actions, bytes32 zidAndAffiliate)`. */
8
+ declare const SETTLER_EXECUTE_SELECTOR = "0x1fff991f";
9
+ /** `ownerOf(uint256)` on the registry: the Settler in force for a feature. */
10
+ declare const REGISTRY_OWNER_OF_SELECTOR = "0x6352211e";
11
+ /** `prev(uint128)` on the registry: the instance the current one replaced. */
12
+ declare const REGISTRY_PREV_SELECTOR = "0xe2603dc2";
13
+ /** `NATIVE_CHECK(uint256 deadline, uint256 msgValue)`: the action every native-coin sale opens with (no Permit2 involved). */
14
+ declare const SETTLER_NATIVE_CHECK_SELECTOR = "0xbd01c226";
15
+ /**
16
+ * The longest a 0x permit may stay valid from now. 0x signs five minutes ahead; the core reader allows an hour for any
17
+ * provider. A shorter window leaves less time for a permit that was published but not spent (its swap reverted).
18
+ */
19
+ declare const ZEROEX_MAX_PERMIT_SECONDS = 600;
20
+ /**
21
+ * The longest a native-coin sale's quote may stay valid from now. A token sale's quote is bounded by its permit's
22
+ * deadline; a native sale signs nothing, so its quote is bounded here instead: the transaction goes out within this
23
+ * window of the registry read it was checked against, or not at all.
24
+ */
25
+ declare const ZEROEX_MAX_NATIVE_QUOTE_SECONDS = 120;
26
+ /** How far inside {@link ZEROEX_MAX_NATIVE_QUOTE_SECONDS} a backend ends a native sale's quote, so an app whose clock runs behind the backend's still accepts it. */
27
+ declare const ZEROEX_NATIVE_QUOTE_SKEW_SECONDS = 30;
28
+ /**
29
+ * Settler actions through which a taker-submitted swap spends a Permit2 signature (`ISettlerActions.sol`), by
30
+ * selector. Every one starts `(address recipient, PermitTransferFrom permit, …)`, so the permit sits in argument
31
+ * words 1–4 (token, amount, nonce, deadline); `sigWord` is the head word holding the offset of `bytes sig`.
32
+ * `RFQ_VIP` (a maker-signed order) is left out on purpose: a quote that opens with it is refused.
33
+ */
34
+ declare const SETTLER_PERMIT_ACTIONS: Readonly<Record<string, {
35
+ name: string;
36
+ signature: string;
37
+ sigWord: number;
38
+ }>>;
39
+ /** A refusal from one of the checks in this file. The message is safe to show and starts `zeroex: `; `reason` classifies it (CS-13). */
40
+ declare class ZeroExTransactionError extends Error {
41
+ readonly reason?: Swap2RefusalReason;
42
+ constructor(why: string, reason?: Swap2RefusalReason);
43
+ }
44
+ /** The native coin, as the engine (zero address) or 0x (the `0xEeee…` sentinel) names it. */
45
+ declare const isZeroExNative: (token: string) => boolean;
46
+ /**
47
+ * keccak256 of the CREATE3 shim (PUSH0 variant) through which the registry deploys every Settler: the registry
48
+ * CREATE2s the shim with salt `feature << 128 | chainId << 64 | nonce`, and the shim CREATEs the Settler (nonce 1).
49
+ */
50
+ declare const ZEROEX_SETTLER_SHIM_INIT_HASH = "0x3bf3f97f0be1e2c00023033eefeb4fc062ac552ff36778b17060d90b6764902f";
51
+ /**
52
+ * How far past the newest deployment a chain accepts ({@link ZeroExChain.newestLiveNonce} plus the margin) the resolver
53
+ * still derives, only to tell "0x deployed a newer Settler than this module accepts" (refused until the pin is raised)
54
+ * from "not a 0x Settler at all".
55
+ */
56
+ declare const ZEROEX_SETTLER_LOOKAHEAD = 16;
57
+ /** The address the registry deploys taker-feature Settler number `nonce` to on `chainId` — computed, no network. */
58
+ declare function zeroExSettlerAddress(chainId: number, nonce: number, registry?: string): string;
59
+ /**
60
+ * Which deployment of the registry's taker feature `address` is on `chainId` (its nonce), or null when it is none of
61
+ * deployments 1…`maxNonce` — by default the newest one the default table accepts on the chain
62
+ * ({@link ZeroExChain.newestLiveNonce} plus {@link ZEROEX_SETTLER_NONCE_MARGIN}; a chain outside the table has none:
63
+ * null). An RPC (or an API) can therefore only ever name a contract 0x's own registry deployed as a Settler — never an
64
+ * arbitrary contract or account. Bounded by the pin, an address that is no Settler costs a few dozen derivations, not
65
+ * a thousand. Memoized per chain.
66
+ */
67
+ declare function zeroExSettlerNonce(chainId: number, address: string, registry?: string, maxNonce?: number): number | null;
68
+ interface SettlerResolverConfig {
69
+ /** The chain table (registry per chain). */
70
+ chains: Readonly<Record<number, ZeroExChain>>;
71
+ /** JSON-RPC endpoints per EVM chain id. Without one for a chain, its Settler cannot be resolved and live quotes are refused. */
72
+ rpcUrls?: RpcUrls | undefined;
73
+ /** How long a registry read is reused, ms. Default 5 minutes; a miss always triggers a fresh read. */
74
+ maxAgeMs?: number | undefined;
75
+ /** Clock (tests). */
76
+ now?: (() => number) | undefined;
77
+ }
78
+ interface SettlerResolver {
79
+ /** The Settlers a swap on `chainId` may call: the one in force, then the one it replaced (if any). Throws when the registry cannot be read or the feature is paused. */
80
+ resolve(chainId: number, options?: {
81
+ fresh?: boolean;
82
+ }): Promise<readonly string[]>;
83
+ /** The last resolved set while it is still fresh; empty otherwise. Never touches the network. */
84
+ known(chainId: number): readonly string[];
85
+ }
86
+ /**
87
+ * Reads the Settler in force from the registry and caches it per chain. The registry address comes from the chain
88
+ * table; the answer comes from the integrator's own RPC — that RPC is what this module trusts for "which contract
89
+ * is 0x's Settler right now", within hard bounds it cannot move: the answer must be a CREATE3 deployment of that
90
+ * registry, no older than the chain's pinned {@link ZeroExChain.previousLiveNonce} and no newer than its
91
+ * {@link ZeroExChain.newestLiveNonce} plus {@link ZEROEX_SETTLER_NONCE_MARGIN}, with code at the address (read through
92
+ * the same RPC). Which of these a native-coin sale may use is narrower still ({@link checkZeroExTransaction}).
93
+ */
94
+ declare function createSettlerResolver(config: SettlerResolverConfig): SettlerResolver;
95
+ interface SettlerAction {
96
+ /** 4-byte action selector, lowercase. */
97
+ selector: string;
98
+ /** Byte offset, inside the `execute` arguments, of the action's first argument word. */
99
+ argsStart: number;
100
+ /** The action's declared byte length (selector included). The first action of a Permit2 quote declares more than is there: its signature is appended later. */
101
+ declaredLength: number;
102
+ }
103
+ interface SettlerExecute {
104
+ /** Who Settler's slippage check pays. */
105
+ recipient: string;
106
+ /** The token that check measures (`0xEeee…` for the native coin). */
107
+ buyToken: string;
108
+ /** The least `recipient` receives, or the call reverts. */
109
+ minAmountOut: bigint;
110
+ /** 0x's trade id and affiliate tag (not checked). */
111
+ zidAndAffiliate: string;
112
+ actions: readonly SettlerAction[];
113
+ /** Bytes of arguments after the 4-byte method selector. */
114
+ bodyLength: number;
115
+ /** The argument word at byte `offset`, as 64 hex characters; throws when it is out of range. */
116
+ word(offset: number): string;
117
+ }
118
+ /**
119
+ * Read `Settler.execute(slippage, actions, zidAndAffiliate)` calldata. Strict where it matters (method, the static
120
+ * slippage tuple, the canonical position of the action array, every action inside the data) and tolerant where
121
+ * Settler is: the data need not be a multiple of 32 bytes, and the first action may declare a length that runs past
122
+ * the end (0x leaves room for the Permit2 signature there).
123
+ */
124
+ declare function decodeSettlerExecute(data: string): SettlerExecute;
125
+ /** What the user asked for — the only source of truth for the checks. */
126
+ interface ZeroExExpectation {
127
+ /** EVM chain id of the swap. */
128
+ chainId: number;
129
+ /**
130
+ * The chain's entry in the table in force: its pins bound the target (a token sale: `previousLiveNonce` up to
131
+ * `newestLiveNonce` plus the margin; a native-coin sale: exactly `newestLiveNonce` or `previousLiveNonce`). Default:
132
+ * the default table's entry for `chainId`.
133
+ */
134
+ chain?: ZeroExChain | undefined;
135
+ /** Settlers resolved from the registry for that chain ({@link SettlerResolver.resolve}). */
136
+ settlers: readonly string[];
137
+ /** The token sold: an ERC-20 address, or the zero address / `0xEeee…` for the native coin. */
138
+ sellToken: string;
139
+ /** The token bought, same convention. */
140
+ buyToken: string;
141
+ /** Exactly the input, base units. */
142
+ sellAmount: bigint;
143
+ /** Who must receive the output (the user's own address unless they named another). */
144
+ recipient: string;
145
+ /** The least the recipient must receive — the quote's minimum, already held to the requested slippage by the caller. */
146
+ minBuyAmount: bigint;
147
+ /** Clock for the Permit2 deadline (tests). */
148
+ nowMs?: number;
149
+ }
150
+ /** The transaction fields the checks read (a quote's `txRequest` or a built `UnsignedTx`). */
151
+ interface ZeroExTransaction {
152
+ to?: string | undefined;
153
+ data?: string | undefined;
154
+ value?: string | undefined;
155
+ chainId?: number | undefined;
156
+ approvalAddress?: string | undefined;
157
+ permit2Transfer?: string | undefined;
158
+ gasLimit?: string | undefined;
159
+ }
160
+ /**
161
+ * The most gas a 0x swap may be given. Unused gas is refunded, but a reverting route burns up to the limit, so a
162
+ * quote that asks for a block's worth is refused. Real Settler swaps sit well under 2 million.
163
+ */
164
+ declare const ZEROEX_MAX_GAS_LIMIT = 6000000n;
165
+ interface ZeroExCheckedTransaction {
166
+ execute: SettlerExecute;
167
+ /** The locally rebuilt Permit2 payload of a token sale; absent for a native-coin sale. */
168
+ permit2?: Permit2Transfer;
169
+ /** Name of the Settler action that spends the Permit2 signature (token sales). */
170
+ permitAction?: string;
171
+ }
172
+ /**
173
+ * Hold a 0x transaction to the request, or throw {@link ZeroExTransactionError}. Checked:
174
+ *
175
+ * 1. `to` is one of the registry's Settlers, and a deployment inside the chain's pinned window
176
+ * (`previousLiveNonce` … `newestLiveNonce` + {@link ZEROEX_SETTLER_NONCE_MARGIN}); `chainId`, when present, is the
177
+ * swap's chain.
178
+ * 2. `value` is the input for a native-coin sale and zero for a token sale; a sale that sends value goes only to the
179
+ * chain's `newestLiveNonce` or `previousLiveNonce` deployment — Settlers that were live when the table was pinned —
180
+ * never into the margin; a gas limit, when given, is at most {@link ZEROEX_MAX_GAS_LIMIT}.
181
+ * 3. The method is `execute`, and its slippage tuple names the expected recipient, the requested buy token and
182
+ * exactly the expected minimum (never zero).
183
+ * 4. Token sale: the allowance target is canonical Permit2; the Permit2 payload passes the core reader (Permit2
184
+ * domain on this chain, the sell token, exactly the input, this very Settler as spender) and is rebuilt locally,
185
+ * with a deadline at most {@link ZEROEX_MAX_PERMIT_SECONDS} away; the first action is a known Permit2-spending
186
+ * action carrying that same token, amount, nonce and deadline, and its signature slot points at the end of the
187
+ * data, where the signature is appended.
188
+ * 5. Native-coin sale: no allowance target, no Permit2 payload, and the first action is `NATIVE_CHECK` — the only
189
+ * place Settler would spend a Permit2 signature holds none.
190
+ *
191
+ * Not checked: the actions after the first (the route), the first action's own `recipient` (where Permit2 sends the
192
+ * input: the Settler or a pool) and `zidAndAffiliate`. Settler's slippage check bounds what they can do.
193
+ */
194
+ declare function checkZeroExTransaction(tx: ZeroExTransaction, expected: ZeroExExpectation): ZeroExCheckedTransaction;
195
+
196
+ export { REGISTRY_OWNER_OF_SELECTOR as R, SETTLER_EXECUTE_SELECTOR as S, ZEROEX_MAX_GAS_LIMIT as Z, REGISTRY_PREV_SELECTOR as a, SETTLER_NATIVE_CHECK_SELECTOR as b, SETTLER_PERMIT_ACTIONS as c, type SettlerAction as d, type SettlerExecute as e, type SettlerResolver as f, type SettlerResolverConfig as g, ZEROEX_MAX_NATIVE_QUOTE_SECONDS as h, ZEROEX_MAX_PERMIT_SECONDS as i, ZEROEX_NATIVE_QUOTE_SKEW_SECONDS as j, ZEROEX_SETTLER_LOOKAHEAD as k, ZEROEX_SETTLER_SHIM_INIT_HASH as l, type ZeroExCheckedTransaction as m, type ZeroExExpectation as n, type ZeroExTransaction as o, ZeroExTransactionError as p, checkZeroExTransaction as q, createSettlerResolver as r, decodeSettlerExecute as s, isZeroExNative as t, zeroExSettlerNonce as u, type RpcUrls as v, zeroExSettlerAddress as z };
@@ -0,0 +1,196 @@
1
+ import { Swap2RefusalReason } from '@anywalletkit/protocol-swap2-core/errors';
2
+ import { Permit2Transfer } from '@anywalletkit/protocol-swap2-core/util';
3
+ import { ZeroExChain } from './chains.cjs';
4
+
5
+ type RpcUrls = Readonly<Record<number, readonly string[]>>;
6
+
7
+ /** `execute((address recipient, address buyToken, uint256 minAmountOut), bytes[] actions, bytes32 zidAndAffiliate)`. */
8
+ declare const SETTLER_EXECUTE_SELECTOR = "0x1fff991f";
9
+ /** `ownerOf(uint256)` on the registry: the Settler in force for a feature. */
10
+ declare const REGISTRY_OWNER_OF_SELECTOR = "0x6352211e";
11
+ /** `prev(uint128)` on the registry: the instance the current one replaced. */
12
+ declare const REGISTRY_PREV_SELECTOR = "0xe2603dc2";
13
+ /** `NATIVE_CHECK(uint256 deadline, uint256 msgValue)`: the action every native-coin sale opens with (no Permit2 involved). */
14
+ declare const SETTLER_NATIVE_CHECK_SELECTOR = "0xbd01c226";
15
+ /**
16
+ * The longest a 0x permit may stay valid from now. 0x signs five minutes ahead; the core reader allows an hour for any
17
+ * provider. A shorter window leaves less time for a permit that was published but not spent (its swap reverted).
18
+ */
19
+ declare const ZEROEX_MAX_PERMIT_SECONDS = 600;
20
+ /**
21
+ * The longest a native-coin sale's quote may stay valid from now. A token sale's quote is bounded by its permit's
22
+ * deadline; a native sale signs nothing, so its quote is bounded here instead: the transaction goes out within this
23
+ * window of the registry read it was checked against, or not at all.
24
+ */
25
+ declare const ZEROEX_MAX_NATIVE_QUOTE_SECONDS = 120;
26
+ /** How far inside {@link ZEROEX_MAX_NATIVE_QUOTE_SECONDS} a backend ends a native sale's quote, so an app whose clock runs behind the backend's still accepts it. */
27
+ declare const ZEROEX_NATIVE_QUOTE_SKEW_SECONDS = 30;
28
+ /**
29
+ * Settler actions through which a taker-submitted swap spends a Permit2 signature (`ISettlerActions.sol`), by
30
+ * selector. Every one starts `(address recipient, PermitTransferFrom permit, …)`, so the permit sits in argument
31
+ * words 1–4 (token, amount, nonce, deadline); `sigWord` is the head word holding the offset of `bytes sig`.
32
+ * `RFQ_VIP` (a maker-signed order) is left out on purpose: a quote that opens with it is refused.
33
+ */
34
+ declare const SETTLER_PERMIT_ACTIONS: Readonly<Record<string, {
35
+ name: string;
36
+ signature: string;
37
+ sigWord: number;
38
+ }>>;
39
+ /** A refusal from one of the checks in this file. The message is safe to show and starts `zeroex: `; `reason` classifies it (CS-13). */
40
+ declare class ZeroExTransactionError extends Error {
41
+ readonly reason?: Swap2RefusalReason;
42
+ constructor(why: string, reason?: Swap2RefusalReason);
43
+ }
44
+ /** The native coin, as the engine (zero address) or 0x (the `0xEeee…` sentinel) names it. */
45
+ declare const isZeroExNative: (token: string) => boolean;
46
+ /**
47
+ * keccak256 of the CREATE3 shim (PUSH0 variant) through which the registry deploys every Settler: the registry
48
+ * CREATE2s the shim with salt `feature << 128 | chainId << 64 | nonce`, and the shim CREATEs the Settler (nonce 1).
49
+ */
50
+ declare const ZEROEX_SETTLER_SHIM_INIT_HASH = "0x3bf3f97f0be1e2c00023033eefeb4fc062ac552ff36778b17060d90b6764902f";
51
+ /**
52
+ * How far past the newest deployment a chain accepts ({@link ZeroExChain.newestLiveNonce} plus the margin) the resolver
53
+ * still derives, only to tell "0x deployed a newer Settler than this module accepts" (refused until the pin is raised)
54
+ * from "not a 0x Settler at all".
55
+ */
56
+ declare const ZEROEX_SETTLER_LOOKAHEAD = 16;
57
+ /** The address the registry deploys taker-feature Settler number `nonce` to on `chainId` — computed, no network. */
58
+ declare function zeroExSettlerAddress(chainId: number, nonce: number, registry?: string): string;
59
+ /**
60
+ * Which deployment of the registry's taker feature `address` is on `chainId` (its nonce), or null when it is none of
61
+ * deployments 1…`maxNonce` — by default the newest one the default table accepts on the chain
62
+ * ({@link ZeroExChain.newestLiveNonce} plus {@link ZEROEX_SETTLER_NONCE_MARGIN}; a chain outside the table has none:
63
+ * null). An RPC (or an API) can therefore only ever name a contract 0x's own registry deployed as a Settler — never an
64
+ * arbitrary contract or account. Bounded by the pin, an address that is no Settler costs a few dozen derivations, not
65
+ * a thousand. Memoized per chain.
66
+ */
67
+ declare function zeroExSettlerNonce(chainId: number, address: string, registry?: string, maxNonce?: number): number | null;
68
+ interface SettlerResolverConfig {
69
+ /** The chain table (registry per chain). */
70
+ chains: Readonly<Record<number, ZeroExChain>>;
71
+ /** JSON-RPC endpoints per EVM chain id. Without one for a chain, its Settler cannot be resolved and live quotes are refused. */
72
+ rpcUrls?: RpcUrls | undefined;
73
+ /** How long a registry read is reused, ms. Default 5 minutes; a miss always triggers a fresh read. */
74
+ maxAgeMs?: number | undefined;
75
+ /** Clock (tests). */
76
+ now?: (() => number) | undefined;
77
+ }
78
+ interface SettlerResolver {
79
+ /** The Settlers a swap on `chainId` may call: the one in force, then the one it replaced (if any). Throws when the registry cannot be read or the feature is paused. */
80
+ resolve(chainId: number, options?: {
81
+ fresh?: boolean;
82
+ }): Promise<readonly string[]>;
83
+ /** The last resolved set while it is still fresh; empty otherwise. Never touches the network. */
84
+ known(chainId: number): readonly string[];
85
+ }
86
+ /**
87
+ * Reads the Settler in force from the registry and caches it per chain. The registry address comes from the chain
88
+ * table; the answer comes from the integrator's own RPC — that RPC is what this module trusts for "which contract
89
+ * is 0x's Settler right now", within hard bounds it cannot move: the answer must be a CREATE3 deployment of that
90
+ * registry, no older than the chain's pinned {@link ZeroExChain.previousLiveNonce} and no newer than its
91
+ * {@link ZeroExChain.newestLiveNonce} plus {@link ZEROEX_SETTLER_NONCE_MARGIN}, with code at the address (read through
92
+ * the same RPC). Which of these a native-coin sale may use is narrower still ({@link checkZeroExTransaction}).
93
+ */
94
+ declare function createSettlerResolver(config: SettlerResolverConfig): SettlerResolver;
95
+ interface SettlerAction {
96
+ /** 4-byte action selector, lowercase. */
97
+ selector: string;
98
+ /** Byte offset, inside the `execute` arguments, of the action's first argument word. */
99
+ argsStart: number;
100
+ /** The action's declared byte length (selector included). The first action of a Permit2 quote declares more than is there: its signature is appended later. */
101
+ declaredLength: number;
102
+ }
103
+ interface SettlerExecute {
104
+ /** Who Settler's slippage check pays. */
105
+ recipient: string;
106
+ /** The token that check measures (`0xEeee…` for the native coin). */
107
+ buyToken: string;
108
+ /** The least `recipient` receives, or the call reverts. */
109
+ minAmountOut: bigint;
110
+ /** 0x's trade id and affiliate tag (not checked). */
111
+ zidAndAffiliate: string;
112
+ actions: readonly SettlerAction[];
113
+ /** Bytes of arguments after the 4-byte method selector. */
114
+ bodyLength: number;
115
+ /** The argument word at byte `offset`, as 64 hex characters; throws when it is out of range. */
116
+ word(offset: number): string;
117
+ }
118
+ /**
119
+ * Read `Settler.execute(slippage, actions, zidAndAffiliate)` calldata. Strict where it matters (method, the static
120
+ * slippage tuple, the canonical position of the action array, every action inside the data) and tolerant where
121
+ * Settler is: the data need not be a multiple of 32 bytes, and the first action may declare a length that runs past
122
+ * the end (0x leaves room for the Permit2 signature there).
123
+ */
124
+ declare function decodeSettlerExecute(data: string): SettlerExecute;
125
+ /** What the user asked for — the only source of truth for the checks. */
126
+ interface ZeroExExpectation {
127
+ /** EVM chain id of the swap. */
128
+ chainId: number;
129
+ /**
130
+ * The chain's entry in the table in force: its pins bound the target (a token sale: `previousLiveNonce` up to
131
+ * `newestLiveNonce` plus the margin; a native-coin sale: exactly `newestLiveNonce` or `previousLiveNonce`). Default:
132
+ * the default table's entry for `chainId`.
133
+ */
134
+ chain?: ZeroExChain | undefined;
135
+ /** Settlers resolved from the registry for that chain ({@link SettlerResolver.resolve}). */
136
+ settlers: readonly string[];
137
+ /** The token sold: an ERC-20 address, or the zero address / `0xEeee…` for the native coin. */
138
+ sellToken: string;
139
+ /** The token bought, same convention. */
140
+ buyToken: string;
141
+ /** Exactly the input, base units. */
142
+ sellAmount: bigint;
143
+ /** Who must receive the output (the user's own address unless they named another). */
144
+ recipient: string;
145
+ /** The least the recipient must receive — the quote's minimum, already held to the requested slippage by the caller. */
146
+ minBuyAmount: bigint;
147
+ /** Clock for the Permit2 deadline (tests). */
148
+ nowMs?: number;
149
+ }
150
+ /** The transaction fields the checks read (a quote's `txRequest` or a built `UnsignedTx`). */
151
+ interface ZeroExTransaction {
152
+ to?: string | undefined;
153
+ data?: string | undefined;
154
+ value?: string | undefined;
155
+ chainId?: number | undefined;
156
+ approvalAddress?: string | undefined;
157
+ permit2Transfer?: string | undefined;
158
+ gasLimit?: string | undefined;
159
+ }
160
+ /**
161
+ * The most gas a 0x swap may be given. Unused gas is refunded, but a reverting route burns up to the limit, so a
162
+ * quote that asks for a block's worth is refused. Real Settler swaps sit well under 2 million.
163
+ */
164
+ declare const ZEROEX_MAX_GAS_LIMIT = 6000000n;
165
+ interface ZeroExCheckedTransaction {
166
+ execute: SettlerExecute;
167
+ /** The locally rebuilt Permit2 payload of a token sale; absent for a native-coin sale. */
168
+ permit2?: Permit2Transfer;
169
+ /** Name of the Settler action that spends the Permit2 signature (token sales). */
170
+ permitAction?: string;
171
+ }
172
+ /**
173
+ * Hold a 0x transaction to the request, or throw {@link ZeroExTransactionError}. Checked:
174
+ *
175
+ * 1. `to` is one of the registry's Settlers, and a deployment inside the chain's pinned window
176
+ * (`previousLiveNonce` … `newestLiveNonce` + {@link ZEROEX_SETTLER_NONCE_MARGIN}); `chainId`, when present, is the
177
+ * swap's chain.
178
+ * 2. `value` is the input for a native-coin sale and zero for a token sale; a sale that sends value goes only to the
179
+ * chain's `newestLiveNonce` or `previousLiveNonce` deployment — Settlers that were live when the table was pinned —
180
+ * never into the margin; a gas limit, when given, is at most {@link ZEROEX_MAX_GAS_LIMIT}.
181
+ * 3. The method is `execute`, and its slippage tuple names the expected recipient, the requested buy token and
182
+ * exactly the expected minimum (never zero).
183
+ * 4. Token sale: the allowance target is canonical Permit2; the Permit2 payload passes the core reader (Permit2
184
+ * domain on this chain, the sell token, exactly the input, this very Settler as spender) and is rebuilt locally,
185
+ * with a deadline at most {@link ZEROEX_MAX_PERMIT_SECONDS} away; the first action is a known Permit2-spending
186
+ * action carrying that same token, amount, nonce and deadline, and its signature slot points at the end of the
187
+ * data, where the signature is appended.
188
+ * 5. Native-coin sale: no allowance target, no Permit2 payload, and the first action is `NATIVE_CHECK` — the only
189
+ * place Settler would spend a Permit2 signature holds none.
190
+ *
191
+ * Not checked: the actions after the first (the route), the first action's own `recipient` (where Permit2 sends the
192
+ * input: the Settler or a pool) and `zidAndAffiliate`. Settler's slippage check bounds what they can do.
193
+ */
194
+ declare function checkZeroExTransaction(tx: ZeroExTransaction, expected: ZeroExExpectation): ZeroExCheckedTransaction;
195
+
196
+ export { REGISTRY_OWNER_OF_SELECTOR as R, SETTLER_EXECUTE_SELECTOR as S, ZEROEX_MAX_GAS_LIMIT as Z, REGISTRY_PREV_SELECTOR as a, SETTLER_NATIVE_CHECK_SELECTOR as b, SETTLER_PERMIT_ACTIONS as c, type SettlerAction as d, type SettlerExecute as e, type SettlerResolver as f, type SettlerResolverConfig as g, ZEROEX_MAX_NATIVE_QUOTE_SECONDS as h, ZEROEX_MAX_PERMIT_SECONDS as i, ZEROEX_NATIVE_QUOTE_SKEW_SECONDS as j, ZEROEX_SETTLER_LOOKAHEAD as k, ZEROEX_SETTLER_SHIM_INIT_HASH as l, type ZeroExCheckedTransaction as m, type ZeroExExpectation as n, type ZeroExTransaction as o, ZeroExTransactionError as p, checkZeroExTransaction as q, createSettlerResolver as r, decodeSettlerExecute as s, isZeroExNative as t, zeroExSettlerNonce as u, type RpcUrls as v, zeroExSettlerAddress as z };