@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.
- package/README.md +31 -6
- package/dist/activity.cjs +4 -3
- package/dist/activity.cjs.map +1 -1
- package/dist/activity.d.cts +6 -1
- package/dist/activity.d.ts +6 -1
- package/dist/activity.js +3 -3
- package/dist/chains.cjs +16 -2
- package/dist/chains.cjs.map +1 -1
- package/dist/chains.d.cts +26 -6
- package/dist/chains.d.ts +26 -6
- package/dist/chains.js +5 -1
- package/dist/{chunk-ALMGGQS4.js → chunk-ABT2WYBK.js} +6 -6
- package/dist/{chunk-ALMGGQS4.js.map → chunk-ABT2WYBK.js.map} +1 -1
- package/dist/{chunk-CWZCAJBY.js → chunk-AMZ5DXN2.js} +17 -3
- package/dist/chunk-AMZ5DXN2.js.map +1 -0
- package/dist/{chunk-AX4RNHWE.js → chunk-KYVRMBZG.js} +2 -2
- package/dist/{chunk-RLNXMQJH.js → chunk-S2RUUV3X.js} +16 -6
- package/dist/chunk-S2RUUV3X.js.map +1 -0
- package/dist/{chunk-QFOKBJXP.js → chunk-V4HUFBY2.js} +5 -5
- package/dist/chunk-V4HUFBY2.js.map +1 -0
- package/dist/{chunk-NK3PQGI4.js → chunk-YHRPT6BS.js} +20 -5
- package/dist/chunk-YHRPT6BS.js.map +1 -0
- package/dist/index.cjs +46 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +16 -6
- package/dist/protocol.cjs +40 -9
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +1 -1
- package/dist/protocol.d.ts +1 -1
- package/dist/protocol.js +5 -5
- package/dist/provider.cjs +41 -9
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +13 -6
- package/dist/provider.d.ts +13 -6
- package/dist/provider.js +6 -4
- package/dist/remote.cjs +34 -9
- package/dist/remote.cjs.map +1 -1
- package/dist/remote.d.cts +1 -1
- package/dist/remote.d.ts +1 -1
- package/dist/remote.js +5 -5
- package/dist/{settler-KDFcfsKv.d.cts → settler-CeJFLW5t.d.cts} +21 -4
- package/dist/{settler-BpRGkBVV.d.ts → settler-DBLrnepW.d.ts} +21 -4
- package/dist/settler.cjs +20 -4
- package/dist/settler.cjs.map +1 -1
- package/dist/settler.d.cts +1 -1
- package/dist/settler.d.ts +1 -1
- package/dist/settler.js +6 -2
- package/module.json +1 -0
- package/package.json +6 -6
- package/dist/chunk-CWZCAJBY.js.map +0 -1
- package/dist/chunk-NK3PQGI4.js.map +0 -1
- package/dist/chunk-QFOKBJXP.js.map +0 -1
- package/dist/chunk-RLNXMQJH.js.map +0 -1
- /package/dist/{chunk-AX4RNHWE.js.map → chunk-KYVRMBZG.js.map} +0 -0
package/dist/chains.d.cts
CHANGED
|
@@ -33,7 +33,20 @@ interface ZeroExChain {
|
|
|
33
33
|
previousLiveNonce: number;
|
|
34
34
|
/** Wrapped native token; native ↔ wrapped pairs are refused up front (0x answers them with a call to this token, not a Settler). */
|
|
35
35
|
wrappedNative?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The most gas a 0x swap on this chain may be given (the padded limit: 0x's `transaction.gas` × 1.2 + 20,000), for a
|
|
38
|
+
* chain where Settler swaps need more than the cap every other chain keeps (`ZEROEX_MAX_GAS_LIMIT`, 6,000,000). A
|
|
39
|
+
* bigint, 1…{@link ZEROEX_GAS_CAP_CEILING}; absent: that default. In the default table only Monad sets one (15,000,000).
|
|
40
|
+
*/
|
|
41
|
+
maxGasLimit?: bigint;
|
|
36
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The highest gas cap a chain table entry may set ({@link ZeroExChain.maxGasLimit}): Monad's per-transaction gas limit,
|
|
45
|
+
* 30,000,000. Config can raise a chain's cap up to it, never remove the bound.
|
|
46
|
+
*/
|
|
47
|
+
declare const ZEROEX_GAS_CAP_CEILING = 30000000n;
|
|
48
|
+
/** Whether `v` is a gas cap a chain table entry may set: a bigint from 1 to {@link ZEROEX_GAS_CAP_CEILING}. */
|
|
49
|
+
declare const isZeroExGasCap: (v: unknown) => v is bigint;
|
|
37
50
|
/**
|
|
38
51
|
* Deployments of the taker feature a token sale (Permit2) may use past {@link ZeroExChain.newestLiveNonce}: room for
|
|
39
52
|
* 0x's next Settlers (about one a month per chain) before the pin must be raised. Within it the device relies on the
|
|
@@ -45,16 +58,23 @@ declare const ZEROEX_SETTLER_NONCE_MARGIN = 2;
|
|
|
45
58
|
/** The highest {@link ZeroExChain.newestLiveNonce} a chain table may pin. */
|
|
46
59
|
declare const ZEROEX_SETTLER_MAX_NONCE = 1024;
|
|
47
60
|
/**
|
|
48
|
-
* The default chain table (EVM chain id → entry). The
|
|
49
|
-
*
|
|
50
|
-
*
|
|
61
|
+
* The default chain table (EVM chain id → entry). The two numbers are the taker Settler deployments the registry named
|
|
62
|
+
* as current and previous when pinned (2026-11-25, after 0x's 2026-11-24 Settler release; `pnpm verify:live`: both
|
|
63
|
+
* have code). Monad (143) joined in 0.2.0 from the same reads: deployment 12, made on 2026-11-24, and 11; its wrapped
|
|
64
|
+
* native is WMON, the one 0x names as `wnative` there. Monad is also the one chain with a gas cap of its own,
|
|
65
|
+
* 15,000,000 (every other chain keeps `ZEROEX_MAX_GAS_LIMIT`, 6,000,000): its gas grows with the size of the sale, 0x
|
|
66
|
+
* splitting a large one across many pools (about 1.6 times Base's on a $25 swap, 6,140,730 for 1,000,000 MON → AUSD on
|
|
67
|
+
* 2026-11-26), so under one 6,000,000 cap 0x sales of MON from about $10,000 were refused (README). The engine
|
|
68
|
+
* never sends the quoted limit, so the cap only decides which quotes are refused.
|
|
51
69
|
*/
|
|
52
70
|
declare const ZEROEX_CHAINS: Readonly<Record<number, ZeroExChain>>;
|
|
53
71
|
/**
|
|
54
72
|
* The chain table in force: the defaults with `overrides` merged over them (an entry replaces the default for that
|
|
55
|
-
* chain id, `null` removes the chain). An entry whose registry or wrapped native is not an address,
|
|
73
|
+
* chain id, `null` removes the chain). An entry whose registry or wrapped native is not an address, whose pins are
|
|
56
74
|
* missing or out of order (`newestLiveNonce` 1…{@link ZEROEX_SETTLER_MAX_NONCE}, `previousLiveNonce` 1…newestLiveNonce),
|
|
57
|
-
*
|
|
75
|
+
* or whose gas cap is given but is not a bigint from 1 to {@link ZEROEX_GAS_CAP_CEILING} (`maxGasLimit`), throws — a
|
|
76
|
+
* typo here would move the root of every check. An entry replaces the default whole: one without `maxGasLimit` has the
|
|
77
|
+
* default cap, Monad's included.
|
|
58
78
|
*/
|
|
59
79
|
declare function zeroExChains(overrides?: Readonly<Record<number, ZeroExChain | null>>): Readonly<Record<number, ZeroExChain>>;
|
|
60
80
|
/** The EVM chain id of a CAIP-2 `eip155:<id>` string, or `NaN`. */
|
|
@@ -62,4 +82,4 @@ declare function zeroExChainId(caip2: string): number;
|
|
|
62
82
|
/** Own-property lookup (a chain id like `constructor` must not resolve to anything). */
|
|
63
83
|
declare function zeroExChain(chains: Readonly<Record<number, ZeroExChain>>, chainId: number): ZeroExChain | undefined;
|
|
64
84
|
|
|
65
|
-
export { ZEROEX_ALLOWANCE_HOLDER, ZEROEX_CHAINS, ZEROEX_NATIVE, ZEROEX_PERMIT2, ZEROEX_SETTLER_MAX_NONCE, ZEROEX_SETTLER_NONCE_MARGIN, ZEROEX_SETTLER_REGISTRY, ZEROEX_TAKER_FEATURE, type ZeroExChain, zeroExChain, zeroExChainId, zeroExChains };
|
|
85
|
+
export { ZEROEX_ALLOWANCE_HOLDER, ZEROEX_CHAINS, ZEROEX_GAS_CAP_CEILING, ZEROEX_NATIVE, ZEROEX_PERMIT2, ZEROEX_SETTLER_MAX_NONCE, ZEROEX_SETTLER_NONCE_MARGIN, ZEROEX_SETTLER_REGISTRY, ZEROEX_TAKER_FEATURE, type ZeroExChain, isZeroExGasCap, zeroExChain, zeroExChainId, zeroExChains };
|
package/dist/chains.d.ts
CHANGED
|
@@ -33,7 +33,20 @@ interface ZeroExChain {
|
|
|
33
33
|
previousLiveNonce: number;
|
|
34
34
|
/** Wrapped native token; native ↔ wrapped pairs are refused up front (0x answers them with a call to this token, not a Settler). */
|
|
35
35
|
wrappedNative?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The most gas a 0x swap on this chain may be given (the padded limit: 0x's `transaction.gas` × 1.2 + 20,000), for a
|
|
38
|
+
* chain where Settler swaps need more than the cap every other chain keeps (`ZEROEX_MAX_GAS_LIMIT`, 6,000,000). A
|
|
39
|
+
* bigint, 1…{@link ZEROEX_GAS_CAP_CEILING}; absent: that default. In the default table only Monad sets one (15,000,000).
|
|
40
|
+
*/
|
|
41
|
+
maxGasLimit?: bigint;
|
|
36
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The highest gas cap a chain table entry may set ({@link ZeroExChain.maxGasLimit}): Monad's per-transaction gas limit,
|
|
45
|
+
* 30,000,000. Config can raise a chain's cap up to it, never remove the bound.
|
|
46
|
+
*/
|
|
47
|
+
declare const ZEROEX_GAS_CAP_CEILING = 30000000n;
|
|
48
|
+
/** Whether `v` is a gas cap a chain table entry may set: a bigint from 1 to {@link ZEROEX_GAS_CAP_CEILING}. */
|
|
49
|
+
declare const isZeroExGasCap: (v: unknown) => v is bigint;
|
|
37
50
|
/**
|
|
38
51
|
* Deployments of the taker feature a token sale (Permit2) may use past {@link ZeroExChain.newestLiveNonce}: room for
|
|
39
52
|
* 0x's next Settlers (about one a month per chain) before the pin must be raised. Within it the device relies on the
|
|
@@ -45,16 +58,23 @@ declare const ZEROEX_SETTLER_NONCE_MARGIN = 2;
|
|
|
45
58
|
/** The highest {@link ZeroExChain.newestLiveNonce} a chain table may pin. */
|
|
46
59
|
declare const ZEROEX_SETTLER_MAX_NONCE = 1024;
|
|
47
60
|
/**
|
|
48
|
-
* The default chain table (EVM chain id → entry). The
|
|
49
|
-
*
|
|
50
|
-
*
|
|
61
|
+
* The default chain table (EVM chain id → entry). The two numbers are the taker Settler deployments the registry named
|
|
62
|
+
* as current and previous when pinned (2026-11-25, after 0x's 2026-11-24 Settler release; `pnpm verify:live`: both
|
|
63
|
+
* have code). Monad (143) joined in 0.2.0 from the same reads: deployment 12, made on 2026-11-24, and 11; its wrapped
|
|
64
|
+
* native is WMON, the one 0x names as `wnative` there. Monad is also the one chain with a gas cap of its own,
|
|
65
|
+
* 15,000,000 (every other chain keeps `ZEROEX_MAX_GAS_LIMIT`, 6,000,000): its gas grows with the size of the sale, 0x
|
|
66
|
+
* splitting a large one across many pools (about 1.6 times Base's on a $25 swap, 6,140,730 for 1,000,000 MON → AUSD on
|
|
67
|
+
* 2026-11-26), so under one 6,000,000 cap 0x sales of MON from about $10,000 were refused (README). The engine
|
|
68
|
+
* never sends the quoted limit, so the cap only decides which quotes are refused.
|
|
51
69
|
*/
|
|
52
70
|
declare const ZEROEX_CHAINS: Readonly<Record<number, ZeroExChain>>;
|
|
53
71
|
/**
|
|
54
72
|
* The chain table in force: the defaults with `overrides` merged over them (an entry replaces the default for that
|
|
55
|
-
* chain id, `null` removes the chain). An entry whose registry or wrapped native is not an address,
|
|
73
|
+
* chain id, `null` removes the chain). An entry whose registry or wrapped native is not an address, whose pins are
|
|
56
74
|
* missing or out of order (`newestLiveNonce` 1…{@link ZEROEX_SETTLER_MAX_NONCE}, `previousLiveNonce` 1…newestLiveNonce),
|
|
57
|
-
*
|
|
75
|
+
* or whose gas cap is given but is not a bigint from 1 to {@link ZEROEX_GAS_CAP_CEILING} (`maxGasLimit`), throws — a
|
|
76
|
+
* typo here would move the root of every check. An entry replaces the default whole: one without `maxGasLimit` has the
|
|
77
|
+
* default cap, Monad's included.
|
|
58
78
|
*/
|
|
59
79
|
declare function zeroExChains(overrides?: Readonly<Record<number, ZeroExChain | null>>): Readonly<Record<number, ZeroExChain>>;
|
|
60
80
|
/** The EVM chain id of a CAIP-2 `eip155:<id>` string, or `NaN`. */
|
|
@@ -62,4 +82,4 @@ declare function zeroExChainId(caip2: string): number;
|
|
|
62
82
|
/** Own-property lookup (a chain id like `constructor` must not resolve to anything). */
|
|
63
83
|
declare function zeroExChain(chains: Readonly<Record<number, ZeroExChain>>, chainId: number): ZeroExChain | undefined;
|
|
64
84
|
|
|
65
|
-
export { ZEROEX_ALLOWANCE_HOLDER, ZEROEX_CHAINS, ZEROEX_NATIVE, ZEROEX_PERMIT2, ZEROEX_SETTLER_MAX_NONCE, ZEROEX_SETTLER_NONCE_MARGIN, ZEROEX_SETTLER_REGISTRY, ZEROEX_TAKER_FEATURE, type ZeroExChain, zeroExChain, zeroExChainId, zeroExChains };
|
|
85
|
+
export { ZEROEX_ALLOWANCE_HOLDER, ZEROEX_CHAINS, ZEROEX_GAS_CAP_CEILING, ZEROEX_NATIVE, ZEROEX_PERMIT2, ZEROEX_SETTLER_MAX_NONCE, ZEROEX_SETTLER_NONCE_MARGIN, ZEROEX_SETTLER_REGISTRY, ZEROEX_TAKER_FEATURE, type ZeroExChain, isZeroExGasCap, zeroExChain, zeroExChainId, zeroExChains };
|
package/dist/chains.js
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ZEROEX_ALLOWANCE_HOLDER,
|
|
3
3
|
ZEROEX_CHAINS,
|
|
4
|
+
ZEROEX_GAS_CAP_CEILING,
|
|
4
5
|
ZEROEX_NATIVE,
|
|
5
6
|
ZEROEX_PERMIT2,
|
|
6
7
|
ZEROEX_SETTLER_MAX_NONCE,
|
|
7
8
|
ZEROEX_SETTLER_NONCE_MARGIN,
|
|
8
9
|
ZEROEX_SETTLER_REGISTRY,
|
|
9
10
|
ZEROEX_TAKER_FEATURE,
|
|
11
|
+
isZeroExGasCap,
|
|
10
12
|
zeroExChain,
|
|
11
13
|
zeroExChainId,
|
|
12
14
|
zeroExChains
|
|
13
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-AMZ5DXN2.js";
|
|
14
16
|
export {
|
|
15
17
|
ZEROEX_ALLOWANCE_HOLDER,
|
|
16
18
|
ZEROEX_CHAINS,
|
|
19
|
+
ZEROEX_GAS_CAP_CEILING,
|
|
17
20
|
ZEROEX_NATIVE,
|
|
18
21
|
ZEROEX_PERMIT2,
|
|
19
22
|
ZEROEX_SETTLER_MAX_NONCE,
|
|
20
23
|
ZEROEX_SETTLER_NONCE_MARGIN,
|
|
21
24
|
ZEROEX_SETTLER_REGISTRY,
|
|
22
25
|
ZEROEX_TAKER_FEATURE,
|
|
26
|
+
isZeroExGasCap,
|
|
23
27
|
zeroExChain,
|
|
24
28
|
zeroExChainId,
|
|
25
29
|
zeroExChains
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ZEROEX_PROVIDER,
|
|
3
3
|
zeroExPreflightDeposit
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-S2RUUV3X.js";
|
|
5
5
|
import {
|
|
6
6
|
describeZeroExActivity
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-V4HUFBY2.js";
|
|
8
8
|
import {
|
|
9
9
|
ZEROEX_MAX_NATIVE_QUOTE_SECONDS,
|
|
10
10
|
checkZeroExTransaction,
|
|
11
11
|
createSettlerResolver,
|
|
12
12
|
isZeroExNative
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-YHRPT6BS.js";
|
|
14
14
|
import {
|
|
15
15
|
ZEROEX_NATIVE,
|
|
16
16
|
ZEROEX_PERMIT2,
|
|
17
17
|
zeroExChain,
|
|
18
18
|
zeroExChainId,
|
|
19
19
|
zeroExChains
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-AMZ5DXN2.js";
|
|
21
21
|
|
|
22
22
|
// src/remote.ts
|
|
23
23
|
import { getAddress } from "viem";
|
|
@@ -156,7 +156,7 @@ function zeroExRemoteProvider(options) {
|
|
|
156
156
|
});
|
|
157
157
|
return {
|
|
158
158
|
...inner,
|
|
159
|
-
describeActivity: describeZeroExActivity,
|
|
159
|
+
describeActivity: (tx, ctx) => describeZeroExActivity(tx, ctx, pins.chains),
|
|
160
160
|
// The quoted gas limit is the backend's word: every call goes out with the account's own estimate.
|
|
161
161
|
ownGasEstimate: true,
|
|
162
162
|
settlerResolver: pins.resolver,
|
|
@@ -204,4 +204,4 @@ export {
|
|
|
204
204
|
zeroExRemoteProvider,
|
|
205
205
|
zeroExKnownSpenders
|
|
206
206
|
};
|
|
207
|
-
//# sourceMappingURL=chunk-
|
|
207
|
+
//# sourceMappingURL=chunk-ABT2WYBK.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/remote.ts"],"sourcesContent":["/**\n * The app's side of 0x when the API key stays on a server.\n *\n * `zeroExRemoteProvider({baseUrl, rpcUrls})` forwards quotes and builds to your backend (which runs\n * `zeroExProvider` with the key) and checks, on the device, everything that comes back before the\n * engine signs: the Settler from the on-chain registry read through the app's own RPC, the\n * transaction and the Permit2 payload held to the request the app itself sent\n * ({@link zeroExVerifyQuote} on the quote, {@link zeroExVerifyBuild} on the build), and, right\n * before the broadcast, the registry read once more ({@link zeroExPreflightDeposit}) ahead of the\n * backend's own preflight. The backend is what these checks guard against; it never names its own\n * Settler, spender, recipient or minimum.\n *\n * Every text the verifiers return is classified (`zeroExPins.reasonOf`, CS-13), so a remote stub's\n * refusal carries its `Swap2RefusalReason`; the app's own malformed request stays unclassified.\n */\nimport {getAddress} from \"viem\";\nimport {refusalNotes, refusalOf, type Swap2RefusalReason} from \"@anywalletkit/protocol-swap2-core/errors\";\nimport {remoteProvider, type RemoteProviderOptions} from \"@anywalletkit/protocol-swap2-core/remote\";\nimport {sourceAssetOf} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {slippageFloor} from \"@anywalletkit/protocol-swap2-core/validate\";\nimport type {CrossChainProvider, Quote, QuoteParams, RemotePins, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {describeZeroExActivity} from \"./activity.js\";\nimport {ZEROEX_NATIVE, ZEROEX_PERMIT2, zeroExChain, zeroExChainId, zeroExChains, type ZeroExChain} from \"./chains.js\";\nimport {ZEROEX_PROVIDER, zeroExPreflightDeposit} from \"./provider.js\";\nimport type {RpcUrls} from \"./rpc.js\";\nimport {ZEROEX_MAX_NATIVE_QUOTE_SECONDS, checkZeroExTransaction, createSettlerResolver, isZeroExNative, type SettlerResolver} from \"./settler.js\";\n\nconst ADDRESS = /^0x[0-9a-fA-F]{40}$/;\nconst same = (a: string, b: string): boolean => a.length === b.length && a.toLowerCase() === b.toLowerCase();\nconst uint = (v: unknown): bigint | null => (typeof v === \"string\" && /^[0-9]{1,78}$/.test(v) ? BigInt(v) : null);\nconst message = (e: unknown, fallback: string): string => (e instanceof Error ? e.message.replace(/^zeroex: /, \"\") : fallback);\n\n/** The reason behind each text {@link zeroExVerifyQuote} / {@link zeroExVerifyBuild} return (`zeroExPins.reasonOf`). */\nconst notes = refusalNotes();\n/** A verifier's answer: the text, its reason remembered (none: the app's own malformed request). */\nconst note = (text: string, reason?: Swap2RefusalReason): string =>\n // Noted without a valid reason, a text is unclassified (and forgets any earlier classification of the same text).\n notes.note(text, reason ?? ({} as Swap2RefusalReason));\n/** A refusal raised by the checks: its text without the prefix, and the reason it carries. */\nconst noteError = (e: unknown, fallback: string): string => note(message(e, fallback), refusalOf(e)?.reason ?? \"policy_refused\");\n\n/** The reason a text from {@link zeroExVerifyQuote} or {@link zeroExVerifyBuild} carries; undefined for any other text. */\nexport const zeroExRefusalReason = (text: string) => notes.reasonOf(text);\n\nexport interface ZeroExVerifyContext {\n /** The chain table in force. */\n chains: Readonly<Record<number, ZeroExChain>>;\n /** Settlers the app resolved from the registry for a chain (never the backend's word). */\n settlers(chainId: number): readonly string[];\n /** The most slippage accepted when the request named none, bps. Default 50 — the provider's own default. */\n defaultSlippageBps?: number | undefined;\n /** Clock (tests). */\n nowMs?: number | undefined;\n}\n\n/**\n * A remote 0x quote, held to the request the app sent. Null when it passes, the reason otherwise.\n *\n * An indicative quote (`dry`) carries no transaction and only its amounts are checked. A live quote must carry one,\n * and it goes through {@link checkZeroExTransaction} with an expectation built only from `params`: the sell token and\n * amount, the buy token, the app's recipient, the quote's minimum (itself held to the requested slippage and floor),\n * the chain's pins and the Settlers the app resolved. It may stay valid no longer than its Permit2 deadline (a token\n * sale) or {@link ZEROEX_MAX_NATIVE_QUOTE_SECONDS} from now (a native-coin sale).\n */\nexport function zeroExVerifyQuote(params: QuoteParams, quote: Quote, ctx: ZeroExVerifyContext): string | null {\n if (quote.provider !== ZEROEX_PROVIDER) return note(\"the quote is not a 0x quote\", \"policy_refused\");\n if (params.sourceChain !== params.destChain) return note(\"0x swaps stay on one chain\", \"unsupported_pair\");\n const chainId = zeroExChainId(params.sourceChain);\n const chain = zeroExChain(ctx.chains, chainId);\n if (!chain) return note(\"the chain is not in the 0x chain table\", \"unsupported_pair\");\n if (quote.intentId.replace(/~[0-9a-f]{32}$/, \"\").split(\":\").slice(0, 2).join(\":\") !== `zeroex:${chainId}`) return note(\"the intent id does not name this chain\", \"policy_refused\");\n const src = sourceAssetOf(params);\n if (!src) return note(\"unknown source token\");\n if (src.contract && !ADDRESS.test(src.contract)) return note(\"the source token is not an EVM address\");\n if (typeof params.destToken !== \"string\" || !ADDRESS.test(params.destToken)) return note(\"the destination token is not an EVM address\");\n const sellToken = src.contract ? getAddress(src.contract) : ZEROEX_NATIVE;\n const buyToken = isZeroExNative(params.destToken) ? ZEROEX_NATIVE : getAddress(params.destToken);\n\n const amountIn = uint(params.amountIn);\n const quotedIn = uint(quote.sourceAmount);\n const dest = uint(quote.destAmount);\n const min = uint(quote.minDestAmount);\n if (amountIn === null || quotedIn === null || dest === null || min === null) return note(\"the quote's amounts are not integers\", amountIn === null ? undefined : \"upstream_unavailable\");\n if (quotedIn !== amountIn) return note(`the quote spends ${quotedIn}, not the ${amountIn} input`, \"policy_refused\");\n if (min <= 0n || min > dest) return note(\"the quoted minimum is not between zero and the quoted output\", \"price_check_failed\");\n const bps = params.slippageBps ?? ctx.defaultSlippageBps ?? 50;\n if (!Number.isInteger(bps) || bps < 0 || bps >= 10_000) return note(\"invalid slippage\");\n if (min < slippageFloor(dest, bps)) return note(`the quoted minimum ${min} is below ${bps} bps of the quoted output`, \"price_check_failed\");\n if (params.minAmountOut !== undefined) {\n const floor = uint(params.minAmountOut);\n if (floor === null || min < floor) return note(`the quoted minimum ${min} is below the caller's floor`, floor === null ? undefined : \"price_check_failed\");\n }\n\n const tx = quote.txRequest;\n const dry = params.dry !== false;\n if (!tx) return dry ? null : note(\"a live quote carries no transaction\", \"upstream_unavailable\");\n if (dry) return note(\"an indicative quote carries a transaction\", \"policy_refused\");\n if (tx.serializedTx !== undefined || tx.nativeFee !== undefined) return note(\"the quote carries more than a Settler call\", \"policy_refused\");\n if (typeof params.destAddress !== \"string\" || !ADDRESS.test(params.destAddress)) return note(\"a live quote needs the recipient\", \"recipient_mismatch\");\n try {\n const checked = checkZeroExTransaction(tx, {\n chainId,\n chain,\n settlers: ctx.settlers(chainId),\n sellToken,\n buyToken,\n sellAmount: amountIn,\n recipient: params.destAddress,\n minBuyAmount: min,\n ...(ctx.nowMs !== undefined ? {nowMs: ctx.nowMs} : {}),\n });\n // The quote must lapse before the signature it asks for does; a native sale, which signs nothing, within a short window.\n if (checked.permit2 && !(Number.isFinite(quote.validUntilMs) && BigInt(Math.ceil(quote.validUntilMs)) <= checked.permit2.deadline * 1000n)) return note(\"the quote outlives its Permit2 deadline\", \"policy_refused\");\n if (!checked.permit2 && !(Number.isFinite(quote.validUntilMs) && quote.validUntilMs <= (ctx.nowMs ?? Date.now()) + ZEROEX_MAX_NATIVE_QUOTE_SECONDS * 1000)) {\n return note(`the native-coin sale's quote is valid for more than ${ZEROEX_MAX_NATIVE_QUOTE_SECONDS} s`, \"policy_refused\");\n }\n } catch (e) {\n return noteError(e, \"the transaction is refused\");\n }\n return null;\n}\n\n/**\n * A remote 0x build, held to its quote and to the request: the built transaction must be the quote's own (target,\n * data, value, chain, allowance target, Permit2 payload), and that quote must pass {@link zeroExVerifyQuote} again\n * against Settlers read from the registry just now. Without the request (`params`) nothing can be checked: refused.\n */\nexport async function zeroExVerifyBuild(quote: Quote, tx: UnsignedTx, params: QuoteParams | undefined, ctx: ZeroExVerifyContext & {resolver: SettlerResolver}): Promise<string | null> {\n if (!params) return note(\"the request this quote answered is not known to the app\", \"policy_refused\");\n const quoted = quote.txRequest;\n if (!quoted?.to || !quoted.data) return note(\"the quote carries no transaction\", \"policy_refused\");\n if (\n typeof tx.to !== \"string\" || typeof tx.data !== \"string\" || !same(tx.to, quoted.to) || !same(tx.data, quoted.data) ||\n uint(tx.value || \"0\") === null || uint(tx.value || \"0\") !== uint(quoted.value ?? \"0\") ||\n (tx.chainId !== undefined && tx.chainId !== quoted.chainId) ||\n tx.approvalAddress !== quoted.approvalAddress || tx.permit2Transfer !== quoted.permit2Transfer || tx.gasLimit !== quoted.gasLimit ||\n tx.serializedTx !== undefined || tx.typedData !== undefined || tx.memo !== undefined\n ) {\n return note(\"the built transaction is not the quoted swap\", \"policy_refused\");\n }\n let settlers: readonly string[];\n try {\n settlers = await ctx.resolver.resolve(zeroExChainId(params.sourceChain), {fresh: true});\n } catch (e) {\n return noteError(e, \"the 0x Settler cannot be resolved\");\n }\n return zeroExVerifyQuote({...params, dry: false}, quote, {...ctx, settlers: () => settlers});\n}\n\nexport interface ZeroExPinsConfig {\n chains?: Readonly<Record<number, ZeroExChain | null>> | undefined;\n /** JSON-RPC endpoints per EVM chain id — the app's own, for the Settler registry read. */\n rpcUrls?: RpcUrls | undefined;\n settlerMaxAgeMs?: number | undefined;\n settlerResolver?: SettlerResolver | undefined;\n /** The most slippage accepted when a request names none, bps. Default 50; keep it in step with the backend's default. */\n defaultSlippageBps?: number | undefined;\n}\n\n/**\n * The app's pins for a remote 0x provider. Unlike a provider with one fixed router, the call target is whatever the\n * registry names now, so the pins hold a resolver: `callTargets` answers from its last fresh read (empty until one is\n * made — use {@link zeroExRemoteProvider}, which reads before every live quote and build), `spenders` is canonical\n * Permit2 and nothing else. `reasonOf` classifies every text the verifiers return.\n *\n * For a signing policy's known Permit2 spenders (wallet-evm `describeTypedData({knownSpenders})`, a kit allowlist)\n * use {@link zeroExKnownSpenders} with the provider the app swaps through: the Settler rotates, so no static table can\n * hold it, and a fresh `zeroExPins()` has a resolver of its own that has read nothing yet.\n */\nexport function zeroExPins(config: ZeroExPinsConfig = {}): RemotePins & {resolver: SettlerResolver; chains: Readonly<Record<number, ZeroExChain>>} {\n const chains = zeroExChains(config.chains);\n const resolver = config.settlerResolver ?? createSettlerResolver({chains, rpcUrls: config.rpcUrls, maxAgeMs: config.settlerMaxAgeMs});\n const ctx: ZeroExVerifyContext = {chains, settlers: (chainId) => resolver.known(chainId), defaultSlippageBps: config.defaultSlippageBps};\n return Object.freeze({\n resolver,\n chains,\n callTargets: (chain: string): readonly string[] => (zeroExChain(chains, zeroExChainId(chain)) ? resolver.known(zeroExChainId(chain)) : []),\n spenders: (chain: string): readonly string[] => (zeroExChain(chains, zeroExChainId(chain)) ? [ZEROEX_PERMIT2] : []),\n verifyQuote: (params: QuoteParams, quote: Quote) => zeroExVerifyQuote(params, quote, ctx),\n verifyBuild: (quote: Quote, tx: UnsignedTx, params?: QuoteParams) => zeroExVerifyBuild(quote, tx, params, {...ctx, resolver}),\n reasonOf: zeroExRefusalReason,\n });\n}\n\nexport interface ZeroExRemoteOptions extends ZeroExPinsConfig, Pick<RemoteProviderOptions, \"baseUrl\" | \"enabled\" | \"fetchImpl\" | \"headers\" | \"timeoutMs\" | \"allowInsecureBaseUrl\"> {}\n\n/** What {@link zeroExRemoteProvider} returns: a remote swap2 provider, plus the Settler resolver it reads through. */\nexport type ZeroExRemoteProvider = CrossChainProvider & {readonly ownGasEstimate: true; readonly settlerResolver: SettlerResolver};\n\n/** How long a live quote's Settler set stays a call target after the quote, at most (its own `validUntilMs` first). */\nconst QUOTED_SET_MAX_MS = 120_000;\n\n/**\n * 0x through your backend: `remoteProvider` with {@link zeroExPins}, plus the registry reads the pins need — the\n * Settler is resolved through the app's RPC before a live quote is asked for (and once more, fresh, if the backend\n * quotes a Settler the app has not seen yet), and the quote is held to exactly that set, however long the backend\n * takes to answer; right before the broadcast `preflightDeposit` reads the registry again on the device and refuses a\n * Settler no longer in it ({@link zeroExPreflightDeposit}), then asks the backend's preflight. Indicative quotes need\n * no RPC. `settlerResolver` is the resolver it reads through (signing policies: {@link zeroExKnownSpenders}).\n */\nexport function zeroExRemoteProvider(options: ZeroExRemoteOptions): ZeroExRemoteProvider {\n const pins = zeroExPins(options);\n const served = (caip2: string): boolean => !!zeroExChain(pins.chains, zeroExChainId(caip2));\n // The Settlers each live quote request was resolved against, by request: the verifier holds the backend's answer to\n // that set, not to whatever the resolver's cache holds once the backend answered (its max age may pass meanwhile).\n const checkedAgainst = new WeakMap<QuoteParams, readonly string[]>();\n // …and, per chain, while that quote may still be used: the router's pin check (callTargets) runs after the answer too.\n const quoted = new Map<number, {settlers: readonly string[]; untilMs: number}>();\n const callTargets = (chain: string): readonly string[] => {\n const chainId = zeroExChainId(chain);\n const known = pins.callTargets(chain);\n const held = quoted.get(chainId);\n if (!held || held.untilMs < Date.now() || !zeroExChain(pins.chains, chainId)) return known;\n return [...known, ...held.settlers.filter((s) => !known.some((k) => same(k, s)))];\n };\n const verifyCtx: ZeroExVerifyContext = {chains: pins.chains, settlers: (chainId) => pins.resolver.known(chainId), defaultSlippageBps: options.defaultSlippageBps};\n const inner = remoteProvider({\n name: ZEROEX_PROVIDER,\n baseUrl: options.baseUrl,\n supportsSameChain: true,\n supportsChain: served,\n supportsChainPair: (from, to) => from === to && served(from),\n supportsRoute: (from, to) => from.chain === to.chain && served(from.chain),\n callTargets,\n spenders: pins.spenders,\n verifyQuote: (params, quote) => {\n const set = checkedAgainst.get(params);\n return zeroExVerifyQuote(params, quote, set ? {...verifyCtx, settlers: () => set} : verifyCtx);\n },\n verifyBuild: pins.verifyBuild!,\n reasonOf: pins.reasonOf!,\n ...(options.enabled ? {enabled: options.enabled} : {}),\n ...(options.fetchImpl ? {fetchImpl: options.fetchImpl} : {}),\n ...(options.headers ? {headers: options.headers} : {}),\n ...(options.timeoutMs !== undefined ? {timeoutMs: options.timeoutMs} : {}),\n ...(options.allowInsecureBaseUrl !== undefined ? {allowInsecureBaseUrl: options.allowInsecureBaseUrl} : {}),\n });\n return {\n ...inner,\n describeActivity: describeZeroExActivity,\n // The quoted gas limit is the backend's word: every call goes out with the account's own estimate.\n ownGasEstimate: true,\n settlerResolver: pins.resolver,\n // The backend's preflight is its own word: the device reads the registry first (a Settler paused, replaced or\n // removed while the user was on the review screen is refused here, nothing sent), then asks the backend.\n async preflightDeposit(quote: Quote, tx: UnsignedTx): Promise<void> {\n await zeroExPreflightDeposit(quote, tx, {chains: pins.chains, resolver: pins.resolver});\n await inner.preflightDeposit!(quote, tx);\n },\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n if (params.dry !== false) return inner.getQuote(params, signal);\n const chainId = zeroExChainId(params.sourceChain);\n const ask = async (settlers: readonly string[]): Promise<Quote | null> => {\n checkedAgainst.set(params, settlers);\n const q = await inner.getQuote(params, signal);\n if (q) quoted.set(chainId, {settlers, untilMs: Math.min(Number.isFinite(q.validUntilMs) ? q.validUntilMs : 0, Date.now() + QUOTED_SET_MAX_MS)});\n return q;\n };\n const before = await pins.resolver.resolve(chainId);\n try {\n return await ask(before);\n } catch (e) {\n // A Settler the app has not seen: read the registry again and, only if it changed, ask once more.\n if (!(e instanceof Error) || !/is not a 0x Settler from the on-chain registry/.test(e.message)) throw e;\n const after = await pins.resolver.resolve(chainId, {fresh: true});\n if (after.length === before.length && after.every((s, i) => same(s, before[i]!))) throw e;\n return ask(after);\n }\n },\n };\n}\n\n/**\n * The 0x Settlers a signing policy should know as Permit2 spenders on `chainId`, labelled — the `knownSpenders` of\n * wallet-evm's `describeTypedData`, and the addresses a kit allowlist needs next to Permit2 and the token. Pass the\n * provider the app swaps through (`zeroExRemoteProvider` / `zeroExProvider`, or its `settlerResolver`): the set is the\n * one that resolver read from the registry, cached for its max age and read again after it. Empty when the registry\n * cannot be read: the permit is then described as a grant to an unknown spender, never silently trusted.\n *\n * ```ts\n * const zeroex = zeroExRemoteProvider({baseUrl, rpcUrls});\n * describeTypedData(typed, {chainId: 8453, account, knownSpenders: await zeroExKnownSpenders(zeroex, 8453)});\n * ```\n */\nexport async function zeroExKnownSpenders(source: SettlerResolver | {readonly settlerResolver: SettlerResolver}, chainId: number, label = \"0x Settler\"): Promise<Record<string, string>> {\n const resolver = \"settlerResolver\" in source ? source.settlerResolver : source;\n try {\n return Object.fromEntries((await resolver.resolve(chainId)).map((settler) => [settler, label]));\n } catch {\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAeA,SAAQ,kBAAiB;AACzB,SAAQ,cAAc,iBAAyC;AAC/D,SAAQ,sBAAiD;AACzD,SAAQ,qBAAoB;AAC5B,SAAQ,qBAAoB;AAQ5B,IAAM,UAAU;AAChB,IAAM,OAAO,CAAC,GAAW,MAAuB,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,MAAM,EAAE,YAAY;AAC3G,IAAM,OAAO,CAAC,MAA+B,OAAO,MAAM,YAAY,gBAAgB,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI;AAC5G,IAAM,UAAU,CAAC,GAAY,aAA8B,aAAa,QAAQ,EAAE,QAAQ,QAAQ,aAAa,EAAE,IAAI;AAGrH,IAAM,QAAQ,aAAa;AAE3B,IAAM,OAAO,CAAC,MAAc;AAAA;AAAA,EAE1B,MAAM,KAAK,MAAM,UAAW,CAAC,CAAwB;AAAA;AAEvD,IAAM,YAAY,CAAC,GAAY,aAA6B,KAAK,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAAC,GAAG,UAAU,gBAAgB;AAGxH,IAAM,sBAAsB,CAAC,SAAiB,MAAM,SAAS,IAAI;AAsBjE,SAAS,kBAAkB,QAAqB,OAAc,KAAyC;AAC5G,MAAI,MAAM,aAAa,gBAAiB,QAAO,KAAK,+BAA+B,gBAAgB;AACnG,MAAI,OAAO,gBAAgB,OAAO,UAAW,QAA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\n * `zeroExRemoteProvider({baseUrl, rpcUrls})` forwards quotes and builds to your backend (which runs\n * `zeroExProvider` with the key) and checks, on the device, everything that comes back before the\n * engine signs: the Settler from the on-chain registry read through the app's own RPC, the\n * transaction and the Permit2 payload held to the request the app itself sent\n * ({@link zeroExVerifyQuote} on the quote, {@link zeroExVerifyBuild} on the build), and, right\n * before the broadcast, the registry read once more ({@link zeroExPreflightDeposit}) ahead of the\n * backend's own preflight. The backend is what these checks guard against; it never names its own\n * Settler, spender, recipient or minimum.\n *\n * Every text the verifiers return is classified (`zeroExPins.reasonOf`, CS-13), so a remote stub's\n * refusal carries its `Swap2RefusalReason`; the app's own malformed request stays unclassified.\n */\nimport {getAddress} from \"viem\";\nimport {refusalNotes, refusalOf, type Swap2RefusalReason} from \"@anywalletkit/protocol-swap2-core/errors\";\nimport {remoteProvider, type RemoteProviderOptions} from \"@anywalletkit/protocol-swap2-core/remote\";\nimport {sourceAssetOf} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {slippageFloor} from \"@anywalletkit/protocol-swap2-core/validate\";\nimport type {CrossChainProvider, Quote, QuoteParams, RemotePins, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {describeZeroExActivity} from \"./activity.js\";\nimport {ZEROEX_NATIVE, ZEROEX_PERMIT2, zeroExChain, zeroExChainId, zeroExChains, type ZeroExChain} from \"./chains.js\";\nimport {ZEROEX_PROVIDER, zeroExPreflightDeposit} from \"./provider.js\";\nimport type {RpcUrls} from \"./rpc.js\";\nimport {ZEROEX_MAX_NATIVE_QUOTE_SECONDS, checkZeroExTransaction, createSettlerResolver, isZeroExNative, type SettlerResolver} from \"./settler.js\";\n\nconst ADDRESS = /^0x[0-9a-fA-F]{40}$/;\nconst same = (a: string, b: string): boolean => a.length === b.length && a.toLowerCase() === b.toLowerCase();\nconst uint = (v: unknown): bigint | null => (typeof v === \"string\" && /^[0-9]{1,78}$/.test(v) ? BigInt(v) : null);\nconst message = (e: unknown, fallback: string): string => (e instanceof Error ? e.message.replace(/^zeroex: /, \"\") : fallback);\n\n/** The reason behind each text {@link zeroExVerifyQuote} / {@link zeroExVerifyBuild} return (`zeroExPins.reasonOf`). */\nconst notes = refusalNotes();\n/** A verifier's answer: the text, its reason remembered (none: the app's own malformed request). */\nconst note = (text: string, reason?: Swap2RefusalReason): string =>\n // Noted without a valid reason, a text is unclassified (and forgets any earlier classification of the same text).\n notes.note(text, reason ?? ({} as Swap2RefusalReason));\n/** A refusal raised by the checks: its text without the prefix, and the reason it carries. */\nconst noteError = (e: unknown, fallback: string): string => note(message(e, fallback), refusalOf(e)?.reason ?? \"policy_refused\");\n\n/** The reason a text from {@link zeroExVerifyQuote} or {@link zeroExVerifyBuild} carries; undefined for any other text. */\nexport const zeroExRefusalReason = (text: string) => notes.reasonOf(text);\n\nexport interface ZeroExVerifyContext {\n /** The chain table in force. */\n chains: Readonly<Record<number, ZeroExChain>>;\n /** Settlers the app resolved from the registry for a chain (never the backend's word). */\n settlers(chainId: number): readonly string[];\n /** The most slippage accepted when the request named none, bps. Default 50 — the provider's own default. */\n defaultSlippageBps?: number | undefined;\n /** Clock (tests). */\n nowMs?: number | undefined;\n}\n\n/**\n * A remote 0x quote, held to the request the app sent. Null when it passes, the reason otherwise.\n *\n * An indicative quote (`dry`) carries no transaction and only its amounts are checked. A live quote must carry one,\n * and it goes through {@link checkZeroExTransaction} with an expectation built only from `params`: the sell token and\n * amount, the buy token, the app's recipient, the quote's minimum (itself held to the requested slippage and floor),\n * the chain's pins and the Settlers the app resolved. It may stay valid no longer than its Permit2 deadline (a token\n * sale) or {@link ZEROEX_MAX_NATIVE_QUOTE_SECONDS} from now (a native-coin sale).\n */\nexport function zeroExVerifyQuote(params: QuoteParams, quote: Quote, ctx: ZeroExVerifyContext): string | null {\n if (quote.provider !== ZEROEX_PROVIDER) return note(\"the quote is not a 0x quote\", \"policy_refused\");\n if (params.sourceChain !== params.destChain) return note(\"0x swaps stay on one chain\", \"unsupported_pair\");\n const chainId = zeroExChainId(params.sourceChain);\n const chain = zeroExChain(ctx.chains, chainId);\n if (!chain) return note(\"the chain is not in the 0x chain table\", \"unsupported_pair\");\n if (quote.intentId.replace(/~[0-9a-f]{32}$/, \"\").split(\":\").slice(0, 2).join(\":\") !== `zeroex:${chainId}`) return note(\"the intent id does not name this chain\", \"policy_refused\");\n const src = sourceAssetOf(params);\n if (!src) return note(\"unknown source token\");\n if (src.contract && !ADDRESS.test(src.contract)) return note(\"the source token is not an EVM address\");\n if (typeof params.destToken !== \"string\" || !ADDRESS.test(params.destToken)) return note(\"the destination token is not an EVM address\");\n const sellToken = src.contract ? getAddress(src.contract) : ZEROEX_NATIVE;\n const buyToken = isZeroExNative(params.destToken) ? ZEROEX_NATIVE : getAddress(params.destToken);\n\n const amountIn = uint(params.amountIn);\n const quotedIn = uint(quote.sourceAmount);\n const dest = uint(quote.destAmount);\n const min = uint(quote.minDestAmount);\n if (amountIn === null || quotedIn === null || dest === null || min === null) return note(\"the quote's amounts are not integers\", amountIn === null ? undefined : \"upstream_unavailable\");\n if (quotedIn !== amountIn) return note(`the quote spends ${quotedIn}, not the ${amountIn} input`, \"policy_refused\");\n if (min <= 0n || min > dest) return note(\"the quoted minimum is not between zero and the quoted output\", \"price_check_failed\");\n const bps = params.slippageBps ?? ctx.defaultSlippageBps ?? 50;\n if (!Number.isInteger(bps) || bps < 0 || bps >= 10_000) return note(\"invalid slippage\");\n if (min < slippageFloor(dest, bps)) return note(`the quoted minimum ${min} is below ${bps} bps of the quoted output`, \"price_check_failed\");\n if (params.minAmountOut !== undefined) {\n const floor = uint(params.minAmountOut);\n if (floor === null || min < floor) return note(`the quoted minimum ${min} is below the caller's floor`, floor === null ? undefined : \"price_check_failed\");\n }\n\n const tx = quote.txRequest;\n const dry = params.dry !== false;\n if (!tx) return dry ? null : note(\"a live quote carries no transaction\", \"upstream_unavailable\");\n if (dry) return note(\"an indicative quote carries a transaction\", \"policy_refused\");\n if (tx.serializedTx !== undefined || tx.nativeFee !== undefined) return note(\"the quote carries more than a Settler call\", \"policy_refused\");\n if (typeof params.destAddress !== \"string\" || !ADDRESS.test(params.destAddress)) return note(\"a live quote needs the recipient\", \"recipient_mismatch\");\n try {\n const checked = checkZeroExTransaction(tx, {\n chainId,\n chain,\n settlers: ctx.settlers(chainId),\n sellToken,\n buyToken,\n sellAmount: amountIn,\n recipient: params.destAddress,\n minBuyAmount: min,\n ...(ctx.nowMs !== undefined ? {nowMs: ctx.nowMs} : {}),\n });\n // The quote must lapse before the signature it asks for does; a native sale, which signs nothing, within a short window.\n if (checked.permit2 && !(Number.isFinite(quote.validUntilMs) && BigInt(Math.ceil(quote.validUntilMs)) <= checked.permit2.deadline * 1000n)) return note(\"the quote outlives its Permit2 deadline\", \"policy_refused\");\n if (!checked.permit2 && !(Number.isFinite(quote.validUntilMs) && quote.validUntilMs <= (ctx.nowMs ?? Date.now()) + ZEROEX_MAX_NATIVE_QUOTE_SECONDS * 1000)) {\n return note(`the native-coin sale's quote is valid for more than ${ZEROEX_MAX_NATIVE_QUOTE_SECONDS} s`, \"policy_refused\");\n }\n } catch (e) {\n return noteError(e, \"the transaction is refused\");\n }\n return null;\n}\n\n/**\n * A remote 0x build, held to its quote and to the request: the built transaction must be the quote's own (target,\n * data, value, chain, allowance target, Permit2 payload), and that quote must pass {@link zeroExVerifyQuote} again\n * against Settlers read from the registry just now. Without the request (`params`) nothing can be checked: refused.\n */\nexport async function zeroExVerifyBuild(quote: Quote, tx: UnsignedTx, params: QuoteParams | undefined, ctx: ZeroExVerifyContext & {resolver: SettlerResolver}): Promise<string | null> {\n if (!params) return note(\"the request this quote answered is not known to the app\", \"policy_refused\");\n const quoted = quote.txRequest;\n if (!quoted?.to || !quoted.data) return note(\"the quote carries no transaction\", \"policy_refused\");\n if (\n typeof tx.to !== \"string\" || typeof tx.data !== \"string\" || !same(tx.to, quoted.to) || !same(tx.data, quoted.data) ||\n uint(tx.value || \"0\") === null || uint(tx.value || \"0\") !== uint(quoted.value ?? \"0\") ||\n (tx.chainId !== undefined && tx.chainId !== quoted.chainId) ||\n tx.approvalAddress !== quoted.approvalAddress || tx.permit2Transfer !== quoted.permit2Transfer || tx.gasLimit !== quoted.gasLimit ||\n tx.serializedTx !== undefined || tx.typedData !== undefined || tx.memo !== undefined\n ) {\n return note(\"the built transaction is not the quoted swap\", \"policy_refused\");\n }\n let settlers: readonly string[];\n try {\n settlers = await ctx.resolver.resolve(zeroExChainId(params.sourceChain), {fresh: true});\n } catch (e) {\n return noteError(e, \"the 0x Settler cannot be resolved\");\n }\n return zeroExVerifyQuote({...params, dry: false}, quote, {...ctx, settlers: () => settlers});\n}\n\nexport interface ZeroExPinsConfig {\n chains?: Readonly<Record<number, ZeroExChain | null>> | undefined;\n /** JSON-RPC endpoints per EVM chain id — the app's own, for the Settler registry read. */\n rpcUrls?: RpcUrls | undefined;\n settlerMaxAgeMs?: number | undefined;\n settlerResolver?: SettlerResolver | undefined;\n /** The most slippage accepted when a request names none, bps. Default 50; keep it in step with the backend's default. */\n defaultSlippageBps?: number | undefined;\n}\n\n/**\n * The app's pins for a remote 0x provider. Unlike a provider with one fixed router, the call target is whatever the\n * registry names now, so the pins hold a resolver: `callTargets` answers from its last fresh read (empty until one is\n * made — use {@link zeroExRemoteProvider}, which reads before every live quote and build), `spenders` is canonical\n * Permit2 and nothing else. `reasonOf` classifies every text the verifiers return.\n *\n * For a signing policy's known Permit2 spenders (wallet-evm `describeTypedData({knownSpenders})`, a kit allowlist)\n * use {@link zeroExKnownSpenders} with the provider the app swaps through: the Settler rotates, so no static table can\n * hold it, and a fresh `zeroExPins()` has a resolver of its own that has read nothing yet.\n */\nexport function zeroExPins(config: ZeroExPinsConfig = {}): RemotePins & {resolver: SettlerResolver; chains: Readonly<Record<number, ZeroExChain>>} {\n const chains = zeroExChains(config.chains);\n const resolver = config.settlerResolver ?? createSettlerResolver({chains, rpcUrls: config.rpcUrls, maxAgeMs: config.settlerMaxAgeMs});\n const ctx: ZeroExVerifyContext = {chains, settlers: (chainId) => resolver.known(chainId), defaultSlippageBps: config.defaultSlippageBps};\n return Object.freeze({\n resolver,\n chains,\n callTargets: (chain: string): readonly string[] => (zeroExChain(chains, zeroExChainId(chain)) ? resolver.known(zeroExChainId(chain)) : []),\n spenders: (chain: string): readonly string[] => (zeroExChain(chains, zeroExChainId(chain)) ? [ZEROEX_PERMIT2] : []),\n verifyQuote: (params: QuoteParams, quote: Quote) => zeroExVerifyQuote(params, quote, ctx),\n verifyBuild: (quote: Quote, tx: UnsignedTx, params?: QuoteParams) => zeroExVerifyBuild(quote, tx, params, {...ctx, resolver}),\n reasonOf: zeroExRefusalReason,\n });\n}\n\nexport interface ZeroExRemoteOptions extends ZeroExPinsConfig, Pick<RemoteProviderOptions, \"baseUrl\" | \"enabled\" | \"fetchImpl\" | \"headers\" | \"timeoutMs\" | \"allowInsecureBaseUrl\"> {}\n\n/** What {@link zeroExRemoteProvider} returns: a remote swap2 provider, plus the Settler resolver it reads through. */\nexport type ZeroExRemoteProvider = CrossChainProvider & {readonly ownGasEstimate: true; readonly settlerResolver: SettlerResolver};\n\n/** How long a live quote's Settler set stays a call target after the quote, at most (its own `validUntilMs` first). */\nconst QUOTED_SET_MAX_MS = 120_000;\n\n/**\n * 0x through your backend: `remoteProvider` with {@link zeroExPins}, plus the registry reads the pins need — the\n * Settler is resolved through the app's RPC before a live quote is asked for (and once more, fresh, if the backend\n * quotes a Settler the app has not seen yet), and the quote is held to exactly that set, however long the backend\n * takes to answer; right before the broadcast `preflightDeposit` reads the registry again on the device and refuses a\n * Settler no longer in it ({@link zeroExPreflightDeposit}), then asks the backend's preflight. Indicative quotes need\n * no RPC. `settlerResolver` is the resolver it reads through (signing policies: {@link zeroExKnownSpenders}).\n */\nexport function zeroExRemoteProvider(options: ZeroExRemoteOptions): ZeroExRemoteProvider {\n const pins = zeroExPins(options);\n const served = (caip2: string): boolean => !!zeroExChain(pins.chains, zeroExChainId(caip2));\n // The Settlers each live quote request was resolved against, by request: the verifier holds the backend's answer to\n // that set, not to whatever the resolver's cache holds once the backend answered (its max age may pass meanwhile).\n const checkedAgainst = new WeakMap<QuoteParams, readonly string[]>();\n // …and, per chain, while that quote may still be used: the router's pin check (callTargets) runs after the answer too.\n const quoted = new Map<number, {settlers: readonly string[]; untilMs: number}>();\n const callTargets = (chain: string): readonly string[] => {\n const chainId = zeroExChainId(chain);\n const known = pins.callTargets(chain);\n const held = quoted.get(chainId);\n if (!held || held.untilMs < Date.now() || !zeroExChain(pins.chains, chainId)) return known;\n return [...known, ...held.settlers.filter((s) => !known.some((k) => same(k, s)))];\n };\n const verifyCtx: ZeroExVerifyContext = {chains: pins.chains, settlers: (chainId) => pins.resolver.known(chainId), defaultSlippageBps: options.defaultSlippageBps};\n const inner = remoteProvider({\n name: ZEROEX_PROVIDER,\n baseUrl: options.baseUrl,\n supportsSameChain: true,\n supportsChain: served,\n supportsChainPair: (from, to) => from === to && served(from),\n supportsRoute: (from, to) => from.chain === to.chain && served(from.chain),\n callTargets,\n spenders: pins.spenders,\n verifyQuote: (params, quote) => {\n const set = checkedAgainst.get(params);\n return zeroExVerifyQuote(params, quote, set ? {...verifyCtx, settlers: () => set} : verifyCtx);\n },\n verifyBuild: pins.verifyBuild!,\n reasonOf: pins.reasonOf!,\n ...(options.enabled ? {enabled: options.enabled} : {}),\n ...(options.fetchImpl ? {fetchImpl: options.fetchImpl} : {}),\n ...(options.headers ? {headers: options.headers} : {}),\n ...(options.timeoutMs !== undefined ? {timeoutMs: options.timeoutMs} : {}),\n ...(options.allowInsecureBaseUrl !== undefined ? {allowInsecureBaseUrl: options.allowInsecureBaseUrl} : {}),\n });\n return {\n ...inner,\n describeActivity: (tx, ctx) => describeZeroExActivity(tx, ctx, pins.chains),\n // The quoted gas limit is the backend's word: every call goes out with the account's own estimate.\n ownGasEstimate: true,\n settlerResolver: pins.resolver,\n // The backend's preflight is its own word: the device reads the registry first (a Settler paused, replaced or\n // removed while the user was on the review screen is refused here, nothing sent), then asks the backend.\n async preflightDeposit(quote: Quote, tx: UnsignedTx): Promise<void> {\n await zeroExPreflightDeposit(quote, tx, {chains: pins.chains, resolver: pins.resolver});\n await inner.preflightDeposit!(quote, tx);\n },\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n if (params.dry !== false) return inner.getQuote(params, signal);\n const chainId = zeroExChainId(params.sourceChain);\n const ask = async (settlers: readonly string[]): Promise<Quote | null> => {\n checkedAgainst.set(params, settlers);\n const q = await inner.getQuote(params, signal);\n if (q) quoted.set(chainId, {settlers, untilMs: Math.min(Number.isFinite(q.validUntilMs) ? q.validUntilMs : 0, Date.now() + QUOTED_SET_MAX_MS)});\n return q;\n };\n const before = await pins.resolver.resolve(chainId);\n try {\n return await ask(before);\n } catch (e) {\n // A Settler the app has not seen: read the registry again and, only if it changed, ask once more.\n if (!(e instanceof Error) || !/is not a 0x Settler from the on-chain registry/.test(e.message)) throw e;\n const after = await pins.resolver.resolve(chainId, {fresh: true});\n if (after.length === before.length && after.every((s, i) => same(s, before[i]!))) throw e;\n return ask(after);\n }\n },\n };\n}\n\n/**\n * The 0x Settlers a signing policy should know as Permit2 spenders on `chainId`, labelled — the `knownSpenders` of\n * wallet-evm's `describeTypedData`, and the addresses a kit allowlist needs next to Permit2 and the token. Pass the\n * provider the app swaps through (`zeroExRemoteProvider` / `zeroExProvider`, or its `settlerResolver`): the set is the\n * one that resolver read from the registry, cached for its max age and read again after it. Empty when the registry\n * cannot be read: the permit is then described as a grant to an unknown spender, never silently trusted.\n *\n * ```ts\n * const zeroex = zeroExRemoteProvider({baseUrl, rpcUrls});\n * describeTypedData(typed, {chainId: 8453, account, knownSpenders: await zeroExKnownSpenders(zeroex, 8453)});\n * ```\n */\nexport async function zeroExKnownSpenders(source: SettlerResolver | {readonly settlerResolver: SettlerResolver}, chainId: number, label = \"0x Settler\"): Promise<Record<string, string>> {\n const resolver = \"settlerResolver\" in source ? source.settlerResolver : source;\n try {\n return Object.fromEntries((await resolver.resolve(chainId)).map((settler) => [settler, label]));\n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AO,IAAI,SAAS,EAAC,UAAU,SAAS,KAAK,IAAI,OAAO,SAAS,EAAE,YAAY,IAAI,EAAE,eAAe,GAAG,KAAK,IAAI,IAAI,iBAAiB,EAAC,CAAC;AAC9I,eAAO;AAAA,MACT;AACA,YAAM,SAAS,MAAM,KAAK,SAAS,QAAQ,OAAO;AAClD,UAAI;AACF,eAAO,MAAM,IAAI,MAAM;AAAA,MACzB,SAAS,GAAG;AAEV,YAAI,EAAE,aAAa,UAAU,CAAC,iDAAiD,KAAK,EAAE,OAAO,EAAG,OAAM;AACtG,cAAM,QAAQ,MAAM,KAAK,SAAS,QAAQ,SAAS,EAAC,OAAO,KAAI,CAAC;AAChE,YAAI,MAAM,WAAW,OAAO,UAAU,MAAM,MAAM,CAAC,GAAG,MAAM,KAAK,GAAG,OAAO,CAAC,CAAE,CAAC,EAAG,OAAM;AACxF,eAAO,IAAI,KAAK;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AACF;AAcA,eAAsB,oBAAoB,QAAuE,SAAiB,QAAQ,cAA+C;AACvL,QAAM,WAAW,qBAAqB,SAAS,OAAO,kBAAkB;AACxE,MAAI;AACF,WAAO,OAAO,aAAa,MAAM,SAAS,QAAQ,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,KAAK,CAAC,CAAC;AAAA,EAChG,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
|
@@ -5,14 +5,17 @@ var ZEROEX_SETTLER_REGISTRY = "0x00000000000004533Fe15556B1E086BB1A72cEae";
|
|
|
5
5
|
var ZEROEX_TAKER_FEATURE = 2;
|
|
6
6
|
var ZEROEX_NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
7
7
|
var ZEROEX_ALLOWANCE_HOLDER = "0x0000000000001fF3684f28c67538d4D072C22734";
|
|
8
|
+
var ZEROEX_GAS_CAP_CEILING = 30000000n;
|
|
9
|
+
var isZeroExGasCap = (v) => typeof v === "bigint" && v >= 1n && v <= ZEROEX_GAS_CAP_CEILING;
|
|
8
10
|
var ZEROEX_SETTLER_NONCE_MARGIN = 2;
|
|
9
11
|
var ZEROEX_SETTLER_MAX_NONCE = 1024;
|
|
10
|
-
var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative });
|
|
12
|
+
var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce, maxGasLimit) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative, ...maxGasLimit !== void 0 ? { maxGasLimit } : {} });
|
|
11
13
|
var ZEROEX_CHAINS = Object.freeze({
|
|
12
14
|
1: chain("Ethereum", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 22, 21),
|
|
13
15
|
10: chain("Optimism", "0x4200000000000000000000000000000000000006", 22, 21),
|
|
14
16
|
56: chain("BNB Smart Chain", "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", 24, 23),
|
|
15
17
|
137: chain("Polygon", "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", 21, 20),
|
|
18
|
+
143: chain("Monad", "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A", 12, 11, 15000000n),
|
|
16
19
|
8453: chain("Base", "0x4200000000000000000000000000000000000006", 23, 22),
|
|
17
20
|
42161: chain("Arbitrum", "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", 21, 20),
|
|
18
21
|
43114: chain("Avalanche", "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", 21, 20)
|
|
@@ -41,7 +44,16 @@ function zeroExChains(overrides) {
|
|
|
41
44
|
if (!Number.isSafeInteger(previous) || previous < 1 || previous > newest) {
|
|
42
45
|
throw new Error(`zeroex: chain ${id} pins no previous live Settler deployment (previousLiveNonce, 1 to its newestLiveNonce)`);
|
|
43
46
|
}
|
|
44
|
-
|
|
47
|
+
const gasCap = entry.maxGasLimit;
|
|
48
|
+
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}`);
|
|
49
|
+
out[id] = Object.freeze({
|
|
50
|
+
name: entry.name,
|
|
51
|
+
registry: entry.registry,
|
|
52
|
+
newestLiveNonce: newest,
|
|
53
|
+
previousLiveNonce: previous,
|
|
54
|
+
...entry.wrappedNative ? { wrappedNative: entry.wrappedNative } : {},
|
|
55
|
+
...gasCap !== void 0 ? { maxGasLimit: gasCap } : {}
|
|
56
|
+
});
|
|
45
57
|
}
|
|
46
58
|
return Object.freeze(out);
|
|
47
59
|
}
|
|
@@ -58,6 +70,8 @@ export {
|
|
|
58
70
|
ZEROEX_TAKER_FEATURE,
|
|
59
71
|
ZEROEX_NATIVE,
|
|
60
72
|
ZEROEX_ALLOWANCE_HOLDER,
|
|
73
|
+
ZEROEX_GAS_CAP_CEILING,
|
|
74
|
+
isZeroExGasCap,
|
|
61
75
|
ZEROEX_SETTLER_NONCE_MARGIN,
|
|
62
76
|
ZEROEX_SETTLER_MAX_NONCE,
|
|
63
77
|
ZEROEX_CHAINS,
|
|
@@ -65,4 +79,4 @@ export {
|
|
|
65
79
|
zeroExChainId,
|
|
66
80
|
zeroExChain
|
|
67
81
|
};
|
|
68
|
-
//# sourceMappingURL=chunk-
|
|
82
|
+
//# sourceMappingURL=chunk-AMZ5DXN2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/chains.ts"],"sourcesContent":["/**\n * Where 0x settles, per chain. Everything a swap is held to on the device starts from this table:\n * the Settler registry (read on-chain for the Settler in force), canonical Permit2, and the wrapped\n * native token (wrap/unwrap pairs are not 0x swaps and are left to the wrap provider).\n *\n * The table is config: `zeroExChains(config.chains)` merges an integrator's entries over these.\n */\nimport {PERMIT2_ADDRESS} from \"@anywalletkit/protocol-swap2-core/util\";\n\n/** Canonical Permit2 — the only allowance target and the only EIP-712 verifying contract this module accepts. */\nexport const ZEROEX_PERMIT2 = PERMIT2_ADDRESS;\n/**\n * The 0x Settler deployer/registry (ERC-721: `ownerOf(feature)` is the Settler in force for that feature,\n * `prev(feature)` the instance it replaced). Same address on every chain 0x deploys to.\n */\nexport const ZEROEX_SETTLER_REGISTRY = \"0x00000000000004533Fe15556B1E086BB1A72cEae\";\n/** Registry feature 2: taker-submitted Settlers — the ones a Permit2 quote is sent to by the taker itself. */\nexport const ZEROEX_TAKER_FEATURE = 2;\n/** How the 0x API (and Settler's slippage check) names the chain's native coin. */\nexport const ZEROEX_NATIVE = \"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE\";\n/** 0x's AllowanceHolder (the flow the docs recommend today). Not used by this module; pinned so it can be told apart. */\nexport const ZEROEX_ALLOWANCE_HOLDER = \"0x0000000000001fF3684f28c67538d4D072C22734\";\n\nexport interface ZeroExChain {\n /** Display name. */\n name: string;\n /** The Settler registry on this chain. */\n registry: string;\n /**\n * The taker Settler deployment (the registry's taker-feature nonce, see `zeroExSettlerAddress`) the registry named as\n * the one in force when the table was pinned. A native-coin sale is sent only to this deployment or to\n * {@link previousLiveNonce}: its value goes straight to the Settler's address, so that address must be a Settler that\n * was live then. A token sale (Permit2) may also go to the next {@link ZEROEX_SETTLER_NONCE_MARGIN} deployments once\n * they hold code. Anything newer is refused, clearly, until the pin is raised — the watch job reports every new\n * deployment (`ownerOf(2)` per chain in watch.json, `verify:live` on the canary). 1…{@link ZEROEX_SETTLER_MAX_NONCE}.\n */\n newestLiveNonce: number;\n /**\n * The deployment the registry named as the previous one (`prev(2)`) when the table was pinned: the oldest accepted.\n * An older Settler — a replaced one, whose code predates what the checks rely on — is refused as the one in force\n * and dropped as the previous one. 1…{@link newestLiveNonce} (equal to it on a chain with a single deployment).\n */\n previousLiveNonce: number;\n /** Wrapped native token; native ↔ wrapped pairs are refused up front (0x answers them with a call to this token, not a Settler). */\n wrappedNative?: string;\n /**\n * The most gas a 0x swap on this chain may be given (the padded limit: 0x's `transaction.gas` × 1.2 + 20,000), for a\n * chain where Settler swaps need more than the cap every other chain keeps (`ZEROEX_MAX_GAS_LIMIT`, 6,000,000). A\n * bigint, 1…{@link ZEROEX_GAS_CAP_CEILING}; absent: that default. In the default table only Monad sets one (15,000,000).\n */\n maxGasLimit?: bigint;\n}\n\n/**\n * The highest gas cap a chain table entry may set ({@link ZeroExChain.maxGasLimit}): Monad's per-transaction gas limit,\n * 30,000,000. Config can raise a chain's cap up to it, never remove the bound.\n */\nexport const ZEROEX_GAS_CAP_CEILING = 30_000_000n;\n/** Whether `v` is a gas cap a chain table entry may set: a bigint from 1 to {@link ZEROEX_GAS_CAP_CEILING}. */\nexport const isZeroExGasCap = (v: unknown): v is bigint => typeof v === \"bigint\" && v >= 1n && v <= ZEROEX_GAS_CAP_CEILING;\n\n/**\n * Deployments of the taker feature a token sale (Permit2) may use past {@link ZeroExChain.newestLiveNonce}: room for\n * 0x's next Settlers (about one a month per chain) before the pin must be raised. Within it the device relies on the\n * code check (a deployment that does not exist yet has no code) and on its RPC answering that check truthfully; a token\n * sale's permit can be spent only with the account itself as the caller, so a wrong answer costs nothing. Native-coin\n * sales get no margin: their value would be sent to the address as it is.\n */\nexport const ZEROEX_SETTLER_NONCE_MARGIN = 2;\n/** The highest {@link ZeroExChain.newestLiveNonce} a chain table may pin. */\nexport const ZEROEX_SETTLER_MAX_NONCE = 1024;\n\nconst chain = (name: string, wrappedNative: string, newestLiveNonce: number, previousLiveNonce: number, maxGasLimit?: bigint): ZeroExChain =>\n Object.freeze({name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative, ...(maxGasLimit !== undefined ? {maxGasLimit} : {})});\n\n/**\n * The default chain table (EVM chain id → entry). The two numbers are the taker Settler deployments the registry named\n * as current and previous when pinned (2026-11-25, after 0x's 2026-11-24 Settler release; `pnpm verify:live`: both\n * have code). Monad (143) joined in 0.2.0 from the same reads: deployment 12, made on 2026-11-24, and 11; its wrapped\n * native is WMON, the one 0x names as `wnative` there. Monad is also the one chain with a gas cap of its own,\n * 15,000,000 (every other chain keeps `ZEROEX_MAX_GAS_LIMIT`, 6,000,000): its gas grows with the size of the sale, 0x\n * splitting a large one across many pools (about 1.6 times Base's on a $25 swap, 6,140,730 for 1,000,000 MON → AUSD on\n * 2026-11-26), so under one 6,000,000 cap 0x sales of MON from about $10,000 were refused (README). The engine\n * never sends the quoted limit, so the cap only decides which quotes are refused.\n */\nexport const ZEROEX_CHAINS: Readonly<Record<number, ZeroExChain>> = Object.freeze({\n 1: chain(\"Ethereum\", \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\", 22, 21),\n 10: chain(\"Optimism\", \"0x4200000000000000000000000000000000000006\", 22, 21),\n 56: chain(\"BNB Smart Chain\", \"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c\", 24, 23),\n 137: chain(\"Polygon\", \"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270\", 21, 20),\n 143: chain(\"Monad\", \"0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A\", 12, 11, 15_000_000n),\n 8453: chain(\"Base\", \"0x4200000000000000000000000000000000000006\", 23, 22),\n 42161: chain(\"Arbitrum\", \"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1\", 21, 20),\n 43114: chain(\"Avalanche\", \"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7\", 21, 20),\n});\n\nconst ADDRESS = /^0x[0-9a-fA-F]{40}$/;\nconst ZERO_ADDRESS = /^0x0{40}$/;\n\n/**\n * The chain table in force: the defaults with `overrides` merged over them (an entry replaces the default for that\n * chain id, `null` removes the chain). An entry whose registry or wrapped native is not an address, whose pins are\n * missing or out of order (`newestLiveNonce` 1…{@link ZEROEX_SETTLER_MAX_NONCE}, `previousLiveNonce` 1…newestLiveNonce),\n * or whose gas cap is given but is not a bigint from 1 to {@link ZEROEX_GAS_CAP_CEILING} (`maxGasLimit`), throws — a\n * typo here would move the root of every check. An entry replaces the default whole: one without `maxGasLimit` has the\n * default cap, Monad's included.\n */\nexport function zeroExChains(overrides?: Readonly<Record<number, ZeroExChain | null>>): Readonly<Record<number, ZeroExChain>> {\n if (!overrides) return ZEROEX_CHAINS;\n const out: Record<number, ZeroExChain> = {...ZEROEX_CHAINS};\n for (const key of Object.keys(overrides)) {\n const id = Number(key);\n if (!Number.isSafeInteger(id) || id <= 0) throw new Error(`zeroex: chain id ${key.slice(0, 20)} is not a positive integer`);\n const entry = overrides[id];\n if (entry === null || entry === undefined) {\n delete out[id];\n continue;\n }\n if (typeof entry.name !== \"string\" || !entry.name) throw new Error(`zeroex: chain ${id} has no name`);\n if (typeof entry.registry !== \"string\" || !ADDRESS.test(entry.registry) || ZERO_ADDRESS.test(entry.registry)) throw new Error(`zeroex: chain ${id} names no Settler registry address`);\n if (entry.wrappedNative !== undefined && (typeof entry.wrappedNative !== \"string\" || !ADDRESS.test(entry.wrappedNative))) throw new Error(`zeroex: chain ${id} wrapped native is not an address`);\n const newest = entry.newestLiveNonce;\n const previous = entry.previousLiveNonce;\n if (!Number.isSafeInteger(newest) || newest < 1 || newest > ZEROEX_SETTLER_MAX_NONCE) {\n throw new Error(`zeroex: chain ${id} pins no newest live Settler deployment (newestLiveNonce, 1 to ${ZEROEX_SETTLER_MAX_NONCE})`);\n }\n if (!Number.isSafeInteger(previous) || previous < 1 || previous > newest) {\n throw new Error(`zeroex: chain ${id} pins no previous live Settler deployment (previousLiveNonce, 1 to its newestLiveNonce)`);\n }\n const gasCap = entry.maxGasLimit;\n if (gasCap !== undefined && !isZeroExGasCap(gasCap)) throw new Error(`zeroex: chain ${id} gas cap (maxGasLimit) is not a bigint from 1 to ${ZEROEX_GAS_CAP_CEILING}`);\n out[id] = Object.freeze({\n name: entry.name, registry: entry.registry, newestLiveNonce: newest, previousLiveNonce: previous,\n ...(entry.wrappedNative ? {wrappedNative: entry.wrappedNative} : {}), ...(gasCap !== undefined ? {maxGasLimit: gasCap} : {}),\n });\n }\n return Object.freeze(out);\n}\n\n/** The EVM chain id of a CAIP-2 `eip155:<id>` string, or `NaN`. */\nexport function zeroExChainId(caip2: string): number {\n return typeof caip2 === \"string\" && /^eip155:[1-9][0-9]{0,15}$/.test(caip2) ? Number(caip2.slice(7)) : NaN;\n}\n\n/** Own-property lookup (a chain id like `constructor` must not resolve to anything). */\nexport function zeroExChain(chains: Readonly<Record<number, ZeroExChain>>, chainId: number): ZeroExChain | undefined {\n return Number.isSafeInteger(chainId) && Object.prototype.hasOwnProperty.call(chains, chainId) ? chains[chainId] : undefined;\n}\n"],"mappings":";AAOA,SAAQ,uBAAsB;AAGvB,IAAM,iBAAiB;AAKvB,IAAM,0BAA0B;AAEhC,IAAM,uBAAuB;AAE7B,IAAM,gBAAgB;AAEtB,IAAM,0BAA0B;AAoChC,IAAM,yBAAyB;AAE/B,IAAM,iBAAiB,CAAC,MAA4B,OAAO,MAAM,YAAY,KAAK,MAAM,KAAK;AAS7F,IAAM,8BAA8B;AAEpC,IAAM,2BAA2B;AAExC,IAAM,QAAQ,CAAC,MAAc,eAAuB,iBAAyB,mBAA2B,gBACtG,OAAO,OAAO,EAAC,MAAM,UAAU,yBAAyB,iBAAiB,mBAAmB,eAAe,GAAI,gBAAgB,SAAY,EAAC,YAAW,IAAI,CAAC,EAAE,CAAC;AAY1J,IAAM,gBAAuD,OAAO,OAAO;AAAA,EAChF,GAAG,MAAM,YAAY,8CAA8C,IAAI,EAAE;AAAA,EACzE,IAAI,MAAM,YAAY,8CAA8C,IAAI,EAAE;AAAA,EAC1E,IAAI,MAAM,mBAAmB,8CAA8C,IAAI,EAAE;AAAA,EACjF,KAAK,MAAM,WAAW,8CAA8C,IAAI,EAAE;AAAA,EAC1E,KAAK,MAAM,SAAS,8CAA8C,IAAI,IAAI,SAAW;AAAA,EACrF,MAAM,MAAM,QAAQ,8CAA8C,IAAI,EAAE;AAAA,EACxE,OAAO,MAAM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,MAAM;AACrB,QAAI,WAAW,UAAa,CAAC,eAAe,MAAM,EAAG,OAAM,IAAI,MAAM,iBAAiB,EAAE,oDAAoD,sBAAsB,EAAE;AACpK,QAAI,EAAE,IAAI,OAAO,OAAO;AAAA,MACtB,MAAM,MAAM;AAAA,MAAM,UAAU,MAAM;AAAA,MAAU,iBAAiB;AAAA,MAAQ,mBAAmB;AAAA,MACxF,GAAI,MAAM,gBAAgB,EAAC,eAAe,MAAM,cAAa,IAAI,CAAC;AAAA,MAAI,GAAI,WAAW,SAAY,EAAC,aAAa,OAAM,IAAI,CAAC;AAAA,IAC5H,CAAC;AAAA,EACH;AACA,SAAO,OAAO,OAAO,GAAG;AAC1B;AAGO,SAAS,cAAc,OAAuB;AACnD,SAAO,OAAO,UAAU,YAAY,4BAA4B,KAAK,KAAK,IAAI,OAAO,MAAM,MAAM,CAAC,CAAC,IAAI;AACzG;AAGO,SAAS,YAAY,QAA+C,SAA0C;AACnH,SAAO,OAAO,cAAc,OAAO,KAAK,OAAO,UAAU,eAAe,KAAK,QAAQ,OAAO,IAAI,OAAO,OAAO,IAAI;AACpH;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
zeroExProvider
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-S2RUUV3X.js";
|
|
4
4
|
|
|
5
5
|
// src/protocol.ts
|
|
6
6
|
import { SingleProviderSwap2 } from "@anywalletkit/protocol-swap2-core/swap2/single";
|
|
@@ -21,4 +21,4 @@ var ZeroExSwap2Protocol = class extends SingleProviderSwap2 {
|
|
|
21
21
|
export {
|
|
22
22
|
ZeroExSwap2Protocol
|
|
23
23
|
};
|
|
24
|
-
//# sourceMappingURL=chunk-
|
|
24
|
+
//# sourceMappingURL=chunk-KYVRMBZG.js.map
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
describeZeroExActivity
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-V4HUFBY2.js";
|
|
4
4
|
import {
|
|
5
5
|
ZEROEX_MAX_NATIVE_QUOTE_SECONDS,
|
|
6
6
|
ZEROEX_NATIVE_QUOTE_SKEW_SECONDS,
|
|
7
|
+
checkZeroExGasLimit,
|
|
7
8
|
checkZeroExTransaction,
|
|
8
9
|
createSettlerResolver,
|
|
9
10
|
isZeroExNative,
|
|
10
11
|
rpcRequest,
|
|
11
12
|
rpcUrlsFor
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-YHRPT6BS.js";
|
|
13
14
|
import {
|
|
14
15
|
ZEROEX_NATIVE,
|
|
15
16
|
ZEROEX_PERMIT2,
|
|
16
17
|
zeroExChain,
|
|
17
18
|
zeroExChainId,
|
|
18
19
|
zeroExChains
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-AMZ5DXN2.js";
|
|
20
21
|
|
|
21
22
|
// src/provider.ts
|
|
22
23
|
import { getAddress, hashTypedData } from "viem";
|
|
@@ -129,6 +130,10 @@ function zeroExFees(response, gas) {
|
|
|
129
130
|
if (network !== null) out.push({ type: "network", amount: network.toString(), token: "native", included: false, description: "Estimated network fee (gas \xD7 gas price, as 0x reports it)" });
|
|
130
131
|
return { fees: out, networkFeeKnown: network !== null };
|
|
131
132
|
}
|
|
133
|
+
function zeroExGasEstimate(gas) {
|
|
134
|
+
const units = uint(gas);
|
|
135
|
+
return units !== null && units > 0n && units < 10000000000n ? units.toString() : void 0;
|
|
136
|
+
}
|
|
132
137
|
function taxBps(v) {
|
|
133
138
|
if (v === null || v === void 0) return null;
|
|
134
139
|
if (typeof v === "number" && Number.isFinite(v) && v >= 0) return v;
|
|
@@ -158,7 +163,7 @@ function zeroExProvider(config) {
|
|
|
158
163
|
};
|
|
159
164
|
return {
|
|
160
165
|
name: ZEROEX_PROVIDER,
|
|
161
|
-
describeActivity: describeZeroExActivity,
|
|
166
|
+
describeActivity: (tx, ctx) => describeZeroExActivity(tx, ctx, chains),
|
|
162
167
|
supportsSameChain: true,
|
|
163
168
|
// The quoted gas limit is the API's word: a native sale (like a Permit2 call) goes out with the account's own estimate.
|
|
164
169
|
ownGasEstimate: true,
|
|
@@ -301,6 +306,7 @@ function zeroExProvider(config) {
|
|
|
301
306
|
const tx = plain(transaction) ? transaction : void 0;
|
|
302
307
|
const parsedFees = zeroExFees(r, tx ? { gas: own(tx, "gas"), gasPrice: own(tx, "gasPrice") } : { gas: own(r, "gas"), gasPrice: own(r, "gasPrice") });
|
|
303
308
|
if (typeof parsedFees === "string") return refuse(parsedFees, parsedFees === UNASKED_INTEGRATOR_FEE ? "policy_refused" : "upstream_unavailable");
|
|
309
|
+
const gasEstimate = zeroExGasEstimate(tx ? own(tx, "gas") : own(r, "gas"));
|
|
304
310
|
const flags = [];
|
|
305
311
|
const issues = own(r, "issues");
|
|
306
312
|
if (plain(issues)) {
|
|
@@ -416,6 +422,7 @@ function zeroExProvider(config) {
|
|
|
416
422
|
minDestAmount: minBuyAmount.toString(),
|
|
417
423
|
feeUsd: 0,
|
|
418
424
|
fees: parsedFees.fees,
|
|
425
|
+
...gasEstimate !== void 0 ? { gasEstimate, gasEstimateSource: "venue" } : {},
|
|
419
426
|
etaSeconds: 15,
|
|
420
427
|
reliability: 0.96,
|
|
421
428
|
validUntilMs,
|
|
@@ -469,7 +476,9 @@ async function zeroExPreflightDeposit(quote, tx, ctx) {
|
|
|
469
476
|
throw refusal("policy_refused", "zeroex: the transaction is not the quoted swap. Nothing was sent; refresh the quote.");
|
|
470
477
|
}
|
|
471
478
|
const chainId = typeof quote.intentId === "string" ? Number(quote.intentId.split(":")[1]) : NaN;
|
|
472
|
-
|
|
479
|
+
const chain = zeroExChain(ctx.chains, chainId);
|
|
480
|
+
if (!chain) throw refusal("policy_refused", "zeroex: the quote names no chain this provider serves. Nothing was sent.");
|
|
481
|
+
checkZeroExGasLimit(tx.gasLimit, chain, chainId);
|
|
473
482
|
const settlers = await ctx.resolver.resolve(chainId, { fresh: true });
|
|
474
483
|
if (!settlers.some((s) => same(s, quoted.to))) {
|
|
475
484
|
throw refusal("vault_mismatch", "zeroex: the quoted 0x Settler is no longer in the on-chain registry. Nothing was sent; refresh the quote.");
|
|
@@ -492,7 +501,8 @@ export {
|
|
|
492
501
|
ZEROEX_PROVIDER,
|
|
493
502
|
ZEROEX_DEFAULT_BASE_URL,
|
|
494
503
|
zeroExFees,
|
|
504
|
+
zeroExGasEstimate,
|
|
495
505
|
zeroExProvider,
|
|
496
506
|
zeroExPreflightDeposit
|
|
497
507
|
};
|
|
498
|
-
//# sourceMappingURL=chunk-
|
|
508
|
+
//# sourceMappingURL=chunk-S2RUUV3X.js.map
|