@anywalletkit/protocol-swap2-0x 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +172 -2
- package/dist/activity.cjs +168 -0
- package/dist/activity.cjs.map +1 -0
- package/dist/activity.d.cts +18 -0
- package/dist/activity.d.ts +18 -0
- package/dist/activity.js +11 -0
- package/dist/activity.js.map +1 -0
- package/dist/chains.cjs +88 -0
- package/dist/chains.cjs.map +1 -0
- package/dist/chains.d.cts +64 -0
- package/dist/chains.d.ts +64 -0
- package/dist/chains.js +27 -0
- package/dist/chains.js.map +1 -0
- package/dist/chunk-AOJSV3QG.js +498 -0
- package/dist/chunk-AOJSV3QG.js.map +1 -0
- package/dist/chunk-F6QOUZC7.js +24 -0
- package/dist/chunk-F6QOUZC7.js.map +1 -0
- package/dist/chunk-HDMLWKPW.js +38 -0
- package/dist/chunk-HDMLWKPW.js.map +1 -0
- package/dist/chunk-MBQ2WFQW.js +207 -0
- package/dist/chunk-MBQ2WFQW.js.map +1 -0
- package/dist/chunk-MMOBCJEO.js +68 -0
- package/dist/chunk-MMOBCJEO.js.map +1 -0
- package/dist/chunk-VSYAAW22.js +323 -0
- package/dist/chunk-VSYAAW22.js.map +1 -0
- package/dist/index.cjs +1098 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +102 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.cjs +879 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +20 -0
- package/dist/protocol.d.ts +20 -0
- package/dist/protocol.js +11 -0
- package/dist/protocol.js.map +1 -0
- package/dist/provider.cjs +865 -0
- package/dist/provider.cjs.map +1 -0
- package/dist/provider.d.cts +84 -0
- package/dist/provider.d.ts +84 -0
- package/dist/provider.js +18 -0
- package/dist/provider.js.map +1 -0
- package/dist/remote.cjs +609 -0
- package/dist/remote.cjs.map +1 -0
- package/dist/remote.d.cts +93 -0
- package/dist/remote.d.ts +93 -0
- package/dist/remote.js +21 -0
- package/dist/remote.js.map +1 -0
- package/dist/settler-BpRGkBVV.d.ts +196 -0
- package/dist/settler-KDFcfsKv.d.cts +196 -0
- package/dist/settler.cjs +352 -0
- package/dist/settler.cjs.map +1 -0
- package/dist/settler.d.cts +4 -0
- package/dist/settler.d.ts +4 -0
- package/dist/settler.js +42 -0
- package/dist/settler.js.map +1 -0
- package/module.json +22 -0
- package/package.json +98 -3
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
zeroExProvider
|
|
3
|
+
} from "./chunk-AOJSV3QG.js";
|
|
4
|
+
|
|
5
|
+
// src/protocol.ts
|
|
6
|
+
import { SingleProviderSwap2 } from "@anywalletkit/protocol-swap2-core/swap2/single";
|
|
7
|
+
var ZeroExSwap2Protocol = class extends SingleProviderSwap2 {
|
|
8
|
+
provider;
|
|
9
|
+
constructor(account, config) {
|
|
10
|
+
super(account, config);
|
|
11
|
+
this.provider = zeroExProvider(config);
|
|
12
|
+
}
|
|
13
|
+
chainSupported(caip2) {
|
|
14
|
+
return this.provider.supportsChain?.(caip2) === true;
|
|
15
|
+
}
|
|
16
|
+
pairSupported(fromChain, toChain) {
|
|
17
|
+
return fromChain === toChain && this.chainSupported(fromChain);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
ZeroExSwap2Protocol
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=chunk-F6QOUZC7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts"],"sourcesContent":["import {SingleProviderSwap2} from \"@anywalletkit/protocol-swap2-core/swap2/single\";\nimport type {Swap2Account, Swap2EngineConfig} from \"@anywalletkit/protocol-swap2-core/swap2/base\";\nimport {zeroExProvider, type ZeroExProviderConfig} from \"./provider.js\";\n\nexport interface ZeroExSwap2Config extends Swap2EngineConfig, ZeroExProviderConfig {}\n\n/** 0x as a standalone swap2 protocol (same-chain swaps on one account). */\nexport class ZeroExSwap2Protocol extends SingleProviderSwap2 {\n protected readonly provider;\n constructor(account: Swap2Account | undefined, config: ZeroExSwap2Config) {\n super(account, config);\n this.provider = zeroExProvider(config);\n }\n protected override chainSupported(caip2: string): boolean {\n return this.provider.supportsChain?.(caip2) === true;\n }\n protected override pairSupported(fromChain: string, toChain: string): boolean {\n return fromChain === toChain && this.chainSupported(fromChain);\n }\n}\n"],"mappings":";;;;;AAAA,SAAQ,2BAA0B;AAO3B,IAAM,sBAAN,cAAkC,oBAAoB;AAAA,EACxC;AAAA,EACnB,YAAY,SAAmC,QAA2B;AACxE,UAAM,SAAS,MAAM;AACrB,SAAK,WAAW,eAAe,MAAM;AAAA,EACvC;AAAA,EACmB,eAAe,OAAwB;AACxD,WAAO,KAAK,SAAS,gBAAgB,KAAK,MAAM;AAAA,EAClD;AAAA,EACmB,cAAc,WAAmB,SAA0B;AAC5E,WAAO,cAAc,WAAW,KAAK,eAAe,SAAS;AAAA,EAC/D;AACF;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SETTLER_EXECUTE_SELECTOR,
|
|
3
|
+
decodeSettlerExecute,
|
|
4
|
+
zeroExSettlerNonce
|
|
5
|
+
} from "./chunk-VSYAAW22.js";
|
|
6
|
+
import {
|
|
7
|
+
ZEROEX_CHAINS,
|
|
8
|
+
ZEROEX_SETTLER_NONCE_MARGIN,
|
|
9
|
+
zeroExChain,
|
|
10
|
+
zeroExChainId
|
|
11
|
+
} from "./chunk-MMOBCJEO.js";
|
|
12
|
+
|
|
13
|
+
// src/activity.ts
|
|
14
|
+
import { callSelector, chainLabel, describeSwapLike } from "@anywalletkit/protocol-swap2-core/activity";
|
|
15
|
+
var ZEROEX_MODULE = "@anywalletkit/protocol-swap2-0x";
|
|
16
|
+
function describeZeroExActivity(tx, ctx) {
|
|
17
|
+
const chainId = zeroExChainId(tx.chain);
|
|
18
|
+
const chain = zeroExChain(ZEROEX_CHAINS, chainId);
|
|
19
|
+
if (!chain) return null;
|
|
20
|
+
if (callSelector(tx) !== SETTLER_EXECUTE_SELECTOR) return null;
|
|
21
|
+
const target = tx.call?.to ?? tx.to;
|
|
22
|
+
if (typeof target !== "string" || zeroExSettlerNonce(chainId, target, chain.registry, chain.newestLiveNonce + ZEROEX_SETTLER_NONCE_MARGIN) === null) return null;
|
|
23
|
+
const data = tx.call?.data;
|
|
24
|
+
if (typeof data === "string" && data.length > 10) {
|
|
25
|
+
try {
|
|
26
|
+
decodeSettlerExecute(data);
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return describeSwapLike(tx, ctx, { protocol: ZEROEX_MODULE, subtitle: `0x \xB7 ${chainLabel(tx.chain)}`, kind: "swap" });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
ZEROEX_MODULE,
|
|
36
|
+
describeZeroExActivity
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=chunk-HDMLWKPW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/activity.ts"],"sourcesContent":["/**\n * Activity recognition for 0x: a `Settler.execute` call to a 0x Settler on a chain the module serves\n * → `swap`, \"Swapped A → B\" from the owner's net transfers.\n *\n * 0x replaces its Settler contracts regularly (the registry names the one in force), so past swaps\n * were sent to addresses no pinned list can hold. Every Settler, past or present, is however an\n * address the registry deploys to (CREATE3, see `zeroExSettlerNonce`), which is computed offline: a\n * transaction is recognized by its target being one, by the method (`execute`, selector `0x1fff991f`)\n * and, when its calldata is there, by that calldata reading as a Settler call. A contract that only\n * copies the selector is not labelled a 0x swap. This only labels history; nothing is signed on it.\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {callSelector, chainLabel, describeSwapLike} from \"@anywalletkit/protocol-swap2-core/activity\";\nimport {ZEROEX_CHAINS, ZEROEX_SETTLER_NONCE_MARGIN, zeroExChain, zeroExChainId} from \"./chains.js\";\nimport {SETTLER_EXECUTE_SELECTOR, decodeSettlerExecute, zeroExSettlerNonce} from \"./settler.js\";\n\nexport const ZEROEX_MODULE = \"@anywalletkit/protocol-swap2-0x\";\n\nexport function describeZeroExActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n const chainId = zeroExChainId(tx.chain);\n const chain = zeroExChain(ZEROEX_CHAINS, chainId);\n if (!chain) return null;\n if (callSelector(tx) !== SETTLER_EXECUTE_SELECTOR) return null;\n const target = tx.call?.to ?? tx.to;\n // Any deployment up to the newest one the chain accepts (past swaps went to older Settlers too); bounded by the pin,\n // an address that is no Settler costs a few dozen derivations.\n if (typeof target !== \"string\" || zeroExSettlerNonce(chainId, target, chain.registry, chain.newestLiveNonce + ZEROEX_SETTLER_NONCE_MARGIN) === null) return null;\n const data = tx.call?.data;\n if (typeof data === \"string\" && data.length > 10) {\n try {\n decodeSettlerExecute(data);\n } catch {\n return null;\n }\n }\n return describeSwapLike(tx, ctx, {protocol: ZEROEX_MODULE, subtitle: `0x · ${chainLabel(tx.chain)}`, kind: \"swap\"});\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAQ,cAAc,YAAY,wBAAuB;AAIlD,IAAM,gBAAgB;AAEtB,SAAS,uBAAuB,IAAa,KAAmD;AACrG,QAAM,UAAU,cAAc,GAAG,KAAK;AACtC,QAAM,QAAQ,YAAY,eAAe,OAAO;AAChD,MAAI,CAAC,MAAO,QAAO;AACnB,MAAI,aAAa,EAAE,MAAM,yBAA0B,QAAO;AAC1D,QAAM,SAAS,GAAG,MAAM,MAAM,GAAG;AAGjC,MAAI,OAAO,WAAW,YAAY,mBAAmB,SAAS,QAAQ,MAAM,UAAU,MAAM,kBAAkB,2BAA2B,MAAM,KAAM,QAAO;AAC5J,QAAM,OAAO,GAAG,MAAM;AACtB,MAAI,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI;AAChD,QAAI;AACF,2BAAqB,IAAI;AAAA,IAC3B,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO,iBAAiB,IAAI,KAAK,EAAC,UAAU,eAAe,UAAU,WAAQ,WAAW,GAAG,KAAK,CAAC,IAAI,MAAM,OAAM,CAAC;AACpH;","names":[]}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ZEROEX_PROVIDER,
|
|
3
|
+
zeroExPreflightDeposit
|
|
4
|
+
} from "./chunk-AOJSV3QG.js";
|
|
5
|
+
import {
|
|
6
|
+
describeZeroExActivity
|
|
7
|
+
} from "./chunk-HDMLWKPW.js";
|
|
8
|
+
import {
|
|
9
|
+
ZEROEX_MAX_NATIVE_QUOTE_SECONDS,
|
|
10
|
+
checkZeroExTransaction,
|
|
11
|
+
createSettlerResolver,
|
|
12
|
+
isZeroExNative
|
|
13
|
+
} from "./chunk-VSYAAW22.js";
|
|
14
|
+
import {
|
|
15
|
+
ZEROEX_NATIVE,
|
|
16
|
+
ZEROEX_PERMIT2,
|
|
17
|
+
zeroExChain,
|
|
18
|
+
zeroExChainId,
|
|
19
|
+
zeroExChains
|
|
20
|
+
} from "./chunk-MMOBCJEO.js";
|
|
21
|
+
|
|
22
|
+
// src/remote.ts
|
|
23
|
+
import { getAddress } from "viem";
|
|
24
|
+
import { refusalNotes, refusalOf } from "@anywalletkit/protocol-swap2-core/errors";
|
|
25
|
+
import { remoteProvider } from "@anywalletkit/protocol-swap2-core/remote";
|
|
26
|
+
import { sourceAssetOf } from "@anywalletkit/protocol-swap2-core/util";
|
|
27
|
+
import { slippageFloor } from "@anywalletkit/protocol-swap2-core/validate";
|
|
28
|
+
var ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
29
|
+
var same = (a, b) => a.length === b.length && a.toLowerCase() === b.toLowerCase();
|
|
30
|
+
var uint = (v) => typeof v === "string" && /^[0-9]{1,78}$/.test(v) ? BigInt(v) : null;
|
|
31
|
+
var message = (e, fallback) => e instanceof Error ? e.message.replace(/^zeroex: /, "") : fallback;
|
|
32
|
+
var notes = refusalNotes();
|
|
33
|
+
var note = (text, reason) => (
|
|
34
|
+
// Noted without a valid reason, a text is unclassified (and forgets any earlier classification of the same text).
|
|
35
|
+
notes.note(text, reason ?? {})
|
|
36
|
+
);
|
|
37
|
+
var noteError = (e, fallback) => note(message(e, fallback), refusalOf(e)?.reason ?? "policy_refused");
|
|
38
|
+
var zeroExRefusalReason = (text) => notes.reasonOf(text);
|
|
39
|
+
function zeroExVerifyQuote(params, quote, ctx) {
|
|
40
|
+
if (quote.provider !== ZEROEX_PROVIDER) return note("the quote is not a 0x quote", "policy_refused");
|
|
41
|
+
if (params.sourceChain !== params.destChain) return note("0x swaps stay on one chain", "unsupported_pair");
|
|
42
|
+
const chainId = zeroExChainId(params.sourceChain);
|
|
43
|
+
const chain = zeroExChain(ctx.chains, chainId);
|
|
44
|
+
if (!chain) return note("the chain is not in the 0x chain table", "unsupported_pair");
|
|
45
|
+
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");
|
|
46
|
+
const src = sourceAssetOf(params);
|
|
47
|
+
if (!src) return note("unknown source token");
|
|
48
|
+
if (src.contract && !ADDRESS.test(src.contract)) return note("the source token is not an EVM address");
|
|
49
|
+
if (typeof params.destToken !== "string" || !ADDRESS.test(params.destToken)) return note("the destination token is not an EVM address");
|
|
50
|
+
const sellToken = src.contract ? getAddress(src.contract) : ZEROEX_NATIVE;
|
|
51
|
+
const buyToken = isZeroExNative(params.destToken) ? ZEROEX_NATIVE : getAddress(params.destToken);
|
|
52
|
+
const amountIn = uint(params.amountIn);
|
|
53
|
+
const quotedIn = uint(quote.sourceAmount);
|
|
54
|
+
const dest = uint(quote.destAmount);
|
|
55
|
+
const min = uint(quote.minDestAmount);
|
|
56
|
+
if (amountIn === null || quotedIn === null || dest === null || min === null) return note("the quote's amounts are not integers", amountIn === null ? void 0 : "upstream_unavailable");
|
|
57
|
+
if (quotedIn !== amountIn) return note(`the quote spends ${quotedIn}, not the ${amountIn} input`, "policy_refused");
|
|
58
|
+
if (min <= 0n || min > dest) return note("the quoted minimum is not between zero and the quoted output", "price_check_failed");
|
|
59
|
+
const bps = params.slippageBps ?? ctx.defaultSlippageBps ?? 50;
|
|
60
|
+
if (!Number.isInteger(bps) || bps < 0 || bps >= 1e4) return note("invalid slippage");
|
|
61
|
+
if (min < slippageFloor(dest, bps)) return note(`the quoted minimum ${min} is below ${bps} bps of the quoted output`, "price_check_failed");
|
|
62
|
+
if (params.minAmountOut !== void 0) {
|
|
63
|
+
const floor = uint(params.minAmountOut);
|
|
64
|
+
if (floor === null || min < floor) return note(`the quoted minimum ${min} is below the caller's floor`, floor === null ? void 0 : "price_check_failed");
|
|
65
|
+
}
|
|
66
|
+
const tx = quote.txRequest;
|
|
67
|
+
const dry = params.dry !== false;
|
|
68
|
+
if (!tx) return dry ? null : note("a live quote carries no transaction", "upstream_unavailable");
|
|
69
|
+
if (dry) return note("an indicative quote carries a transaction", "policy_refused");
|
|
70
|
+
if (tx.serializedTx !== void 0 || tx.nativeFee !== void 0) return note("the quote carries more than a Settler call", "policy_refused");
|
|
71
|
+
if (typeof params.destAddress !== "string" || !ADDRESS.test(params.destAddress)) return note("a live quote needs the recipient", "recipient_mismatch");
|
|
72
|
+
try {
|
|
73
|
+
const checked = checkZeroExTransaction(tx, {
|
|
74
|
+
chainId,
|
|
75
|
+
chain,
|
|
76
|
+
settlers: ctx.settlers(chainId),
|
|
77
|
+
sellToken,
|
|
78
|
+
buyToken,
|
|
79
|
+
sellAmount: amountIn,
|
|
80
|
+
recipient: params.destAddress,
|
|
81
|
+
minBuyAmount: min,
|
|
82
|
+
...ctx.nowMs !== void 0 ? { nowMs: ctx.nowMs } : {}
|
|
83
|
+
});
|
|
84
|
+
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");
|
|
85
|
+
if (!checked.permit2 && !(Number.isFinite(quote.validUntilMs) && quote.validUntilMs <= (ctx.nowMs ?? Date.now()) + ZEROEX_MAX_NATIVE_QUOTE_SECONDS * 1e3)) {
|
|
86
|
+
return note(`the native-coin sale's quote is valid for more than ${ZEROEX_MAX_NATIVE_QUOTE_SECONDS} s`, "policy_refused");
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
return noteError(e, "the transaction is refused");
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
async function zeroExVerifyBuild(quote, tx, params, ctx) {
|
|
94
|
+
if (!params) return note("the request this quote answered is not known to the app", "policy_refused");
|
|
95
|
+
const quoted = quote.txRequest;
|
|
96
|
+
if (!quoted?.to || !quoted.data) return note("the quote carries no transaction", "policy_refused");
|
|
97
|
+
if (typeof tx.to !== "string" || typeof tx.data !== "string" || !same(tx.to, quoted.to) || !same(tx.data, quoted.data) || uint(tx.value || "0") === null || uint(tx.value || "0") !== uint(quoted.value ?? "0") || tx.chainId !== void 0 && tx.chainId !== quoted.chainId || tx.approvalAddress !== quoted.approvalAddress || tx.permit2Transfer !== quoted.permit2Transfer || tx.gasLimit !== quoted.gasLimit || tx.serializedTx !== void 0 || tx.typedData !== void 0 || tx.memo !== void 0) {
|
|
98
|
+
return note("the built transaction is not the quoted swap", "policy_refused");
|
|
99
|
+
}
|
|
100
|
+
let settlers;
|
|
101
|
+
try {
|
|
102
|
+
settlers = await ctx.resolver.resolve(zeroExChainId(params.sourceChain), { fresh: true });
|
|
103
|
+
} catch (e) {
|
|
104
|
+
return noteError(e, "the 0x Settler cannot be resolved");
|
|
105
|
+
}
|
|
106
|
+
return zeroExVerifyQuote({ ...params, dry: false }, quote, { ...ctx, settlers: () => settlers });
|
|
107
|
+
}
|
|
108
|
+
function zeroExPins(config = {}) {
|
|
109
|
+
const chains = zeroExChains(config.chains);
|
|
110
|
+
const resolver = config.settlerResolver ?? createSettlerResolver({ chains, rpcUrls: config.rpcUrls, maxAgeMs: config.settlerMaxAgeMs });
|
|
111
|
+
const ctx = { chains, settlers: (chainId) => resolver.known(chainId), defaultSlippageBps: config.defaultSlippageBps };
|
|
112
|
+
return Object.freeze({
|
|
113
|
+
resolver,
|
|
114
|
+
chains,
|
|
115
|
+
callTargets: (chain) => zeroExChain(chains, zeroExChainId(chain)) ? resolver.known(zeroExChainId(chain)) : [],
|
|
116
|
+
spenders: (chain) => zeroExChain(chains, zeroExChainId(chain)) ? [ZEROEX_PERMIT2] : [],
|
|
117
|
+
verifyQuote: (params, quote) => zeroExVerifyQuote(params, quote, ctx),
|
|
118
|
+
verifyBuild: (quote, tx, params) => zeroExVerifyBuild(quote, tx, params, { ...ctx, resolver }),
|
|
119
|
+
reasonOf: zeroExRefusalReason
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
var QUOTED_SET_MAX_MS = 12e4;
|
|
123
|
+
function zeroExRemoteProvider(options) {
|
|
124
|
+
const pins = zeroExPins(options);
|
|
125
|
+
const served = (caip2) => !!zeroExChain(pins.chains, zeroExChainId(caip2));
|
|
126
|
+
const checkedAgainst = /* @__PURE__ */ new WeakMap();
|
|
127
|
+
const quoted = /* @__PURE__ */ new Map();
|
|
128
|
+
const callTargets = (chain) => {
|
|
129
|
+
const chainId = zeroExChainId(chain);
|
|
130
|
+
const known = pins.callTargets(chain);
|
|
131
|
+
const held = quoted.get(chainId);
|
|
132
|
+
if (!held || held.untilMs < Date.now() || !zeroExChain(pins.chains, chainId)) return known;
|
|
133
|
+
return [...known, ...held.settlers.filter((s) => !known.some((k) => same(k, s)))];
|
|
134
|
+
};
|
|
135
|
+
const verifyCtx = { chains: pins.chains, settlers: (chainId) => pins.resolver.known(chainId), defaultSlippageBps: options.defaultSlippageBps };
|
|
136
|
+
const inner = remoteProvider({
|
|
137
|
+
name: ZEROEX_PROVIDER,
|
|
138
|
+
baseUrl: options.baseUrl,
|
|
139
|
+
supportsSameChain: true,
|
|
140
|
+
supportsChain: served,
|
|
141
|
+
supportsChainPair: (from, to) => from === to && served(from),
|
|
142
|
+
supportsRoute: (from, to) => from.chain === to.chain && served(from.chain),
|
|
143
|
+
callTargets,
|
|
144
|
+
spenders: pins.spenders,
|
|
145
|
+
verifyQuote: (params, quote) => {
|
|
146
|
+
const set = checkedAgainst.get(params);
|
|
147
|
+
return zeroExVerifyQuote(params, quote, set ? { ...verifyCtx, settlers: () => set } : verifyCtx);
|
|
148
|
+
},
|
|
149
|
+
verifyBuild: pins.verifyBuild,
|
|
150
|
+
reasonOf: pins.reasonOf,
|
|
151
|
+
...options.enabled ? { enabled: options.enabled } : {},
|
|
152
|
+
...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {},
|
|
153
|
+
...options.headers ? { headers: options.headers } : {},
|
|
154
|
+
...options.timeoutMs !== void 0 ? { timeoutMs: options.timeoutMs } : {},
|
|
155
|
+
...options.allowInsecureBaseUrl !== void 0 ? { allowInsecureBaseUrl: options.allowInsecureBaseUrl } : {}
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
...inner,
|
|
159
|
+
describeActivity: describeZeroExActivity,
|
|
160
|
+
// The quoted gas limit is the backend's word: every call goes out with the account's own estimate.
|
|
161
|
+
ownGasEstimate: true,
|
|
162
|
+
settlerResolver: pins.resolver,
|
|
163
|
+
// The backend's preflight is its own word: the device reads the registry first (a Settler paused, replaced or
|
|
164
|
+
// removed while the user was on the review screen is refused here, nothing sent), then asks the backend.
|
|
165
|
+
async preflightDeposit(quote, tx) {
|
|
166
|
+
await zeroExPreflightDeposit(quote, tx, { chains: pins.chains, resolver: pins.resolver });
|
|
167
|
+
await inner.preflightDeposit(quote, tx);
|
|
168
|
+
},
|
|
169
|
+
async getQuote(params, signal) {
|
|
170
|
+
if (params.dry !== false) return inner.getQuote(params, signal);
|
|
171
|
+
const chainId = zeroExChainId(params.sourceChain);
|
|
172
|
+
const ask = async (settlers) => {
|
|
173
|
+
checkedAgainst.set(params, settlers);
|
|
174
|
+
const q = await inner.getQuote(params, signal);
|
|
175
|
+
if (q) quoted.set(chainId, { settlers, untilMs: Math.min(Number.isFinite(q.validUntilMs) ? q.validUntilMs : 0, Date.now() + QUOTED_SET_MAX_MS) });
|
|
176
|
+
return q;
|
|
177
|
+
};
|
|
178
|
+
const before = await pins.resolver.resolve(chainId);
|
|
179
|
+
try {
|
|
180
|
+
return await ask(before);
|
|
181
|
+
} catch (e) {
|
|
182
|
+
if (!(e instanceof Error) || !/is not a 0x Settler from the on-chain registry/.test(e.message)) throw e;
|
|
183
|
+
const after = await pins.resolver.resolve(chainId, { fresh: true });
|
|
184
|
+
if (after.length === before.length && after.every((s, i) => same(s, before[i]))) throw e;
|
|
185
|
+
return ask(after);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
async function zeroExKnownSpenders(source, chainId, label = "0x Settler") {
|
|
191
|
+
const resolver = "settlerResolver" in source ? source.settlerResolver : source;
|
|
192
|
+
try {
|
|
193
|
+
return Object.fromEntries((await resolver.resolve(chainId)).map((settler) => [settler, label]));
|
|
194
|
+
} catch {
|
|
195
|
+
return {};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export {
|
|
200
|
+
zeroExRefusalReason,
|
|
201
|
+
zeroExVerifyQuote,
|
|
202
|
+
zeroExVerifyBuild,
|
|
203
|
+
zeroExPins,
|
|
204
|
+
zeroExRemoteProvider,
|
|
205
|
+
zeroExKnownSpenders
|
|
206
|
+
};
|
|
207
|
+
//# sourceMappingURL=chunk-MBQ2WFQW.js.map
|
|
@@ -0,0 +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;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C;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":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/chains.ts
|
|
2
|
+
import { PERMIT2_ADDRESS } from "@anywalletkit/protocol-swap2-core/util";
|
|
3
|
+
var ZEROEX_PERMIT2 = PERMIT2_ADDRESS;
|
|
4
|
+
var ZEROEX_SETTLER_REGISTRY = "0x00000000000004533Fe15556B1E086BB1A72cEae";
|
|
5
|
+
var ZEROEX_TAKER_FEATURE = 2;
|
|
6
|
+
var ZEROEX_NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
7
|
+
var ZEROEX_ALLOWANCE_HOLDER = "0x0000000000001fF3684f28c67538d4D072C22734";
|
|
8
|
+
var ZEROEX_SETTLER_NONCE_MARGIN = 2;
|
|
9
|
+
var ZEROEX_SETTLER_MAX_NONCE = 1024;
|
|
10
|
+
var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative });
|
|
11
|
+
var ZEROEX_CHAINS = Object.freeze({
|
|
12
|
+
1: chain("Ethereum", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 21, 20),
|
|
13
|
+
10: chain("Optimism", "0x4200000000000000000000000000000000000006", 21, 20),
|
|
14
|
+
56: chain("BNB Smart Chain", "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", 23, 22),
|
|
15
|
+
137: chain("Polygon", "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", 20, 19),
|
|
16
|
+
8453: chain("Base", "0x4200000000000000000000000000000000000006", 22, 21),
|
|
17
|
+
42161: chain("Arbitrum", "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", 20, 19),
|
|
18
|
+
43114: chain("Avalanche", "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", 20, 19)
|
|
19
|
+
});
|
|
20
|
+
var ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
21
|
+
var ZERO_ADDRESS = /^0x0{40}$/;
|
|
22
|
+
function zeroExChains(overrides) {
|
|
23
|
+
if (!overrides) return ZEROEX_CHAINS;
|
|
24
|
+
const out = { ...ZEROEX_CHAINS };
|
|
25
|
+
for (const key of Object.keys(overrides)) {
|
|
26
|
+
const id = Number(key);
|
|
27
|
+
if (!Number.isSafeInteger(id) || id <= 0) throw new Error(`zeroex: chain id ${key.slice(0, 20)} is not a positive integer`);
|
|
28
|
+
const entry = overrides[id];
|
|
29
|
+
if (entry === null || entry === void 0) {
|
|
30
|
+
delete out[id];
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (typeof entry.name !== "string" || !entry.name) throw new Error(`zeroex: chain ${id} has no name`);
|
|
34
|
+
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`);
|
|
35
|
+
if (entry.wrappedNative !== void 0 && (typeof entry.wrappedNative !== "string" || !ADDRESS.test(entry.wrappedNative))) throw new Error(`zeroex: chain ${id} wrapped native is not an address`);
|
|
36
|
+
const newest = entry.newestLiveNonce;
|
|
37
|
+
const previous = entry.previousLiveNonce;
|
|
38
|
+
if (!Number.isSafeInteger(newest) || newest < 1 || newest > ZEROEX_SETTLER_MAX_NONCE) {
|
|
39
|
+
throw new Error(`zeroex: chain ${id} pins no newest live Settler deployment (newestLiveNonce, 1 to ${ZEROEX_SETTLER_MAX_NONCE})`);
|
|
40
|
+
}
|
|
41
|
+
if (!Number.isSafeInteger(previous) || previous < 1 || previous > newest) {
|
|
42
|
+
throw new Error(`zeroex: chain ${id} pins no previous live Settler deployment (previousLiveNonce, 1 to its newestLiveNonce)`);
|
|
43
|
+
}
|
|
44
|
+
out[id] = Object.freeze({ name: entry.name, registry: entry.registry, newestLiveNonce: newest, previousLiveNonce: previous, ...entry.wrappedNative ? { wrappedNative: entry.wrappedNative } : {} });
|
|
45
|
+
}
|
|
46
|
+
return Object.freeze(out);
|
|
47
|
+
}
|
|
48
|
+
function zeroExChainId(caip2) {
|
|
49
|
+
return typeof caip2 === "string" && /^eip155:[1-9][0-9]{0,15}$/.test(caip2) ? Number(caip2.slice(7)) : NaN;
|
|
50
|
+
}
|
|
51
|
+
function zeroExChain(chains, chainId) {
|
|
52
|
+
return Number.isSafeInteger(chainId) && Object.prototype.hasOwnProperty.call(chains, chainId) ? chains[chainId] : void 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
ZEROEX_PERMIT2,
|
|
57
|
+
ZEROEX_SETTLER_REGISTRY,
|
|
58
|
+
ZEROEX_TAKER_FEATURE,
|
|
59
|
+
ZEROEX_NATIVE,
|
|
60
|
+
ZEROEX_ALLOWANCE_HOLDER,
|
|
61
|
+
ZEROEX_SETTLER_NONCE_MARGIN,
|
|
62
|
+
ZEROEX_SETTLER_MAX_NONCE,
|
|
63
|
+
ZEROEX_CHAINS,
|
|
64
|
+
zeroExChains,
|
|
65
|
+
zeroExChainId,
|
|
66
|
+
zeroExChain
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=chunk-MMOBCJEO.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\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): ZeroExChain =>\n Object.freeze({name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative});\n\n/**\n * The default chain table (EVM chain id → entry). The last two arguments are the taker Settler deployments the\n * registry named as current and previous when pinned (2026-11-15, `pnpm verify:live`: both have code).\n */\nexport const ZEROEX_CHAINS: Readonly<Record<number, ZeroExChain>> = Object.freeze({\n 1: chain(\"Ethereum\", \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\", 21, 20),\n 10: chain(\"Optimism\", \"0x4200000000000000000000000000000000000006\", 21, 20),\n 56: chain(\"BNB Smart Chain\", \"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c\", 23, 22),\n 137: chain(\"Polygon\", \"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270\", 20, 19),\n 8453: chain(\"Base\", \"0x4200000000000000000000000000000000000006\", 22, 21),\n 42161: chain(\"Arbitrum\", \"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1\", 20, 19),\n 43114: chain(\"Avalanche\", \"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7\", 20, 19),\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, or whose pins are\n * missing or out of order (`newestLiveNonce` 1…{@link ZEROEX_SETTLER_MAX_NONCE}, `previousLiveNonce` 1…newestLiveNonce),\n * throws — a typo here would move the root of every check.\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 out[id] = Object.freeze({name: entry.name, registry: entry.registry, newestLiveNonce: newest, previousLiveNonce: previous, ...(entry.wrappedNative ? {wrappedNative: entry.wrappedNative} : {})});\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;AAiChC,IAAM,8BAA8B;AAEpC,IAAM,2BAA2B;AAExC,IAAM,QAAQ,CAAC,MAAc,eAAuB,iBAAyB,sBAC3E,OAAO,OAAO,EAAC,MAAM,UAAU,yBAAyB,iBAAiB,mBAAmB,cAAa,CAAC;AAMrG,IAAM,gBAAuD,OAAO,OAAO;AAAA,EAChF,GAAG,MAAM,YAAY,8CAA8C,IAAI,EAAE;AAAA,EACzE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