@qntx/wallet-chains 0.11.0 → 0.13.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/dist/evm.mjs CHANGED
@@ -1,14 +1,18 @@
1
1
  import { n as parseSignIn, t as ChainError } from "./src-8NZeEnrW.mjs";
2
2
  import { n as requestBase } from "./account-ref-D2rW_qlI.mjs";
3
- import { _ as checksumEvmAddress, a as sameFields, c as typedDataMessages, d as canonicalHex, f as isCanonicalHex, g as quantityBigInt, h as normalizeEvmTransaction, i as parseTypedData, l as typedDataUint, m as networkChainId, n as domainChainId, o as typedDataAddress, p as isRecord, r as isTypedDataMessage, s as typedDataBytes, t as MAX_UINT48, u as assertHex, v as evmAddressFromPublicKey, y as isEvmAddress } from "./typed-data-J5g2WemC.mjs";
4
- import * as TypedData from "ox/TypedData";
3
+ import { C as isEvmAddress, S as evmAddressFromPublicKey, _ as EVM_DELEGATION_PREFIX, a as sameFields, b as encodeBatchExecute, c as typedDataMessages, d as canonicalHex, f as isCanonicalHex, g as quantityBigInt, h as normalizeEvmTransaction, i as parseTypedData, l as typedDataUint, m as networkChainId, n as domainChainId, o as typedDataAddress, p as isRecord, r as isTypedDataMessage, s as typedDataBytes, t as MAX_UINT48, u as assertHex, v as EVM_DELEGATOR, x as checksumEvmAddress, y as decodeBatchExecute } from "./typed-data-B4PJ1v8F.mjs";
4
+ import { keccak_256 } from "@noble/hashes/sha3.js";
5
+ import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
5
6
  import * as AbiFunction from "ox/AbiFunction";
6
7
  import * as Hex from "ox/Hex";
8
+ import * as TypedData from "ox/TypedData";
9
+ import * as Authorization from "ox/Authorization";
7
10
  import * as PersonalMessage from "ox/PersonalMessage";
8
11
  import * as Secp256k1 from "ox/Secp256k1";
9
12
  import * as Signature from "ox/Signature";
10
13
  import * as TxEnvelopeEip1559 from "ox/TxEnvelopeEip1559";
11
14
  import * as TxEnvelopeEip2930 from "ox/TxEnvelopeEip2930";
15
+ import * as TxEnvelopeEip7702 from "ox/TxEnvelopeEip7702";
12
16
  import * as TxEnvelopeLegacy from "ox/TxEnvelopeLegacy";
13
17
  // src/evm/assets.ts
14
18
  /** The native asset id in `AssetFlow` and simulated asset changes. */
@@ -66,6 +70,259 @@ const allowanceChange = (token, spender, value, change, max, chainId, table, ext
66
70
  verified: known !== void 0
67
71
  };
68
72
  };
73
+ // src/evm/across.ts
74
+ /**
75
+ * Across SpokePool proxies per origin chain — UUPS upgradeable, so the kernel recognises them by
76
+ * address only. Verified against the Across deployments registry on 2026-11-08.
77
+ */
78
+ const ACROSS_SPOKEPOOLS = {
79
+ 1: "0x5c7BCd6E7De5423a257D81B442095A1a6ced35C5",
80
+ 10: "0x6f26Bf09B1C792e3228e5467807a900A503c0281",
81
+ 56: "0x4e8E101924eDE233C13e2D8622DC8aED2872d505",
82
+ 137: "0x9295ee1d8C5b022Be115A2AD3c30C72E34e7F096",
83
+ 999: "0x35E63eA3eb0fb7A3bc543C71FB66412e1F6B0E04",
84
+ 8453: "0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64",
85
+ 42161: "0xe35e9842fceaCA96570B734083f4a58e8F7C5f2A",
86
+ 43114: "0xFE9D541c92E4e90437C7152A00244886dE37a658",
87
+ 11155111: "0x5ef6C01E11889d86803e0B23e3cB3F9E9d97B662"
88
+ };
89
+ /** Each pool's `wrappedNativeToken()` — read on-chain on 2026-11-08. */
90
+ const ACROSS_WRAPPED_NATIVE = {
91
+ 1: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
92
+ 10: "0x4200000000000000000000000000000000000006",
93
+ 56: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
94
+ 137: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
95
+ 999: "0x5555555555555555555555555555555555555555",
96
+ 8453: "0x4200000000000000000000000000000000000006",
97
+ 42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
98
+ 43114: "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
99
+ 11155111: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14"
100
+ };
101
+ const DEPOSIT = AbiFunction.from("function deposit(bytes32 depositor, bytes32 recipient, bytes32 inputToken, bytes32 outputToken, uint256 inputAmount, uint256 outputAmount, uint256 destinationChainId, bytes32 exclusiveRelayer, uint32 quoteTimestamp, uint32 fillDeadline, uint32 exclusivityParameter, bytes message)");
102
+ const DEPOSIT_V3 = AbiFunction.from("function depositV3(address depositor, address recipient, address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 destinationChainId, address exclusiveRelayer, uint32 quoteTimestamp, uint32 fillDeadline, uint32 exclusivityDeadline, bytes message)");
103
+ /** Canonical-encoding decode like `tryCall` in decode.ts — undefined on any mismatch. */
104
+ const tryCall$2 = (fn, data) => {
105
+ const selector = AbiFunction.getSelector(fn);
106
+ if (!data.toLowerCase().startsWith(selector)) return;
107
+ try {
108
+ assertHex(data, "data");
109
+ const args = AbiFunction.decodeData(fn, data);
110
+ if (!Array.isArray(args)) return;
111
+ const reencoded = AbiFunction.encodeData(fn, args).toLowerCase();
112
+ return data.toLowerCase().startsWith(reencoded) ? args : void 0;
113
+ } catch {
114
+ return;
115
+ }
116
+ };
117
+ /** A bytes32 carrying an EVM address must be left-padded; anything else is a non-EVM target. */
118
+ const paddedAddress = (value) => {
119
+ if (typeof value !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(value)) return;
120
+ if (value.slice(2, 26) !== "000000000000000000000000") return;
121
+ return checksumEvmAddress(`0x${value.slice(26)}`);
122
+ };
123
+ const tokenAmount$2 = (table, chainId, token, amount) => {
124
+ const meta = table === void 0 ? void 0 : lookupEvmToken(table, chainId, token);
125
+ return meta === void 0 ? {
126
+ asset: token,
127
+ amount: amount.toString(10)
128
+ } : {
129
+ asset: token,
130
+ amount: amount.toString(10),
131
+ decimals: meta.decimals,
132
+ symbol: meta.symbol
133
+ };
134
+ };
135
+ const argUint$1 = (args, index) => {
136
+ const v = args[index];
137
+ return typeof v === "bigint" ? v : typeof v === "number" ? BigInt(v) : void 0;
138
+ };
139
+ const argAddress$2 = (args, index) => {
140
+ const v = args[index];
141
+ return typeof v === "string" && /^0x[0-9a-fA-F]{40}$/.test(v) ? checksumEvmAddress(v) : void 0;
142
+ };
143
+ /**
144
+ * Decodes a `deposit`/`depositV3` to the chain's SpokePool — empty `message` only; bytes32 fields
145
+ * must carry left-padded EVM addresses (non-EVM destinations are not recognised). The deposit
146
+ * guarantees `outputAmount` on the destination chain or a refund to `depositor` after
147
+ * `fillDeadline`, so the intent's `minimumReceived` and `bridge` fields carry those terms.
148
+ */
149
+ const decodeAcross = (chainId, call, table) => {
150
+ const pool = ACROSS_SPOKEPOOLS[chainId];
151
+ if (pool === void 0 || call.to === void 0 || call.to.toLowerCase() !== pool.toLowerCase()) return;
152
+ const v4 = tryCall$2(DEPOSIT, call.data);
153
+ const v3 = v4 === void 0 ? tryCall$2(DEPOSIT_V3, call.data) : void 0;
154
+ if (v4 === void 0 && v3 === void 0) return;
155
+ const args = v4 ?? v3 ?? [];
156
+ const [depositor, recipient, inputToken, outputToken] = [
157
+ 0,
158
+ 1,
159
+ 2,
160
+ 3
161
+ ].map((i) => v4 === void 0 ? argAddress$2(args, i) : paddedAddress(args[i]));
162
+ if (depositor === void 0 || recipient === void 0 || inputToken === void 0 || outputToken === void 0) return;
163
+ const inputAmount = argUint$1(args, 4);
164
+ const outputAmount = argUint$1(args, 5);
165
+ const destinationChainId = argUint$1(args, 6);
166
+ const fillDeadline = argUint$1(args, 9);
167
+ const message = args.at(11);
168
+ if (inputAmount === void 0 || outputAmount === void 0 || destinationChainId === void 0 || fillDeadline === void 0 || message !== "0x") return;
169
+ return {
170
+ outflows: [{
171
+ to: pool,
172
+ amount: call.value > 0n && inputToken.toLowerCase() === (ACROSS_WRAPPED_NATIVE[chainId] ?? "").toLowerCase() ? {
173
+ asset: EVM_NATIVE_ASSET,
174
+ amount: call.value.toString(10)
175
+ } : tokenAmount$2(table, chainId, inputToken, inputAmount),
176
+ verified: true
177
+ }],
178
+ minimumReceived: [{
179
+ to: recipient,
180
+ amount: tokenAmount$2(table, Number(destinationChainId), outputToken, outputAmount),
181
+ verified: true
182
+ }],
183
+ bridge: {
184
+ destinationNetwork: `eip155:${destinationChainId.toString(10)}`,
185
+ fillDeadline: Number(fillDeadline),
186
+ refundTo: depositor
187
+ }
188
+ };
189
+ };
190
+ // src/evm/grants.ts
191
+ /** MetaMask Delegation Framework v1.3.0 DelegationManager — the same address on every chain. */
192
+ const DELEGATION_MANAGER = "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3";
193
+ /** ERC-4337 EntryPoint v0.8 — the same address on every chain. */
194
+ const ENTRY_POINT_V08 = "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108";
195
+ /**
196
+ * Typed data whose domain targets an execution context over the signer's account turns a signature
197
+ * into execution rights: a Delegation the DelegationManager redeems, a PackedUserOperation the
198
+ * EntryPoint runs for a delegated 7702 account, or an action the account's own EIP-712 domain
199
+ * authorizes. A generic typed-data request must never produce such a signature.
200
+ */
201
+ const assertNoExecutionGrant = (domain, signer) => {
202
+ const target = domain["verifyingContract"];
203
+ if (typeof target !== "string" || !isEvmAddress(target)) return;
204
+ const lower = target.toLowerCase();
205
+ if (lower === signer.toLowerCase()) throw new ChainError("invalid-request", "typed data addressed to your own account is refused");
206
+ if (lower === "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3".toLowerCase()) throw new ChainError("invalid-request", "typed data addressed to the DelegationManager is refused");
207
+ if (lower === "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108".toLowerCase()) throw new ChainError("invalid-request", "typed data addressed to the EntryPoint is refused");
208
+ };
209
+ // src/evm/lido.ts
210
+ /** The Lido contracts the kernel recognises by address — Ethereum mainnet only. */
211
+ const LIDO_CHAIN = 1;
212
+ const LIDO_STETH = "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84";
213
+ const LIDO_WSTETH = "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0";
214
+ const LIDO_QUEUE = "0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1";
215
+ const SUBMIT = AbiFunction.from("function submit(address referral) payable");
216
+ const REQUEST = AbiFunction.from("function requestWithdrawals(uint256[] amounts, address owner)");
217
+ const REQUEST_WSTETH = AbiFunction.from("function requestWithdrawalsWstETH(uint256[] amounts, address owner)");
218
+ const REQUEST_PERMIT = AbiFunction.from("function requestWithdrawalsWithPermit(uint256[] amounts, address owner, (uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) permit)");
219
+ const REQUEST_WSTETH_PERMIT = AbiFunction.from("function requestWithdrawalsWstETHWithPermit(uint256[] amounts, address owner, (uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) permit)");
220
+ const CLAIM = AbiFunction.from("function claimWithdrawals(uint256[] requestIds, uint256[] hints)");
221
+ const ZERO = "0x0000000000000000000000000000000000000000";
222
+ /** Canonical-encoding decode like `tryCall` in decode.ts — undefined on any mismatch. */
223
+ const tryCall$1 = (fn, data) => {
224
+ const selector = AbiFunction.getSelector(fn);
225
+ if (!data.toLowerCase().startsWith(selector)) return;
226
+ try {
227
+ assertHex(data, "data");
228
+ const args = AbiFunction.decodeData(fn, data);
229
+ if (!Array.isArray(args)) return;
230
+ return AbiFunction.encodeData(fn, args).toLowerCase() === data.toLowerCase() ? args : void 0;
231
+ } catch {
232
+ return;
233
+ }
234
+ };
235
+ const argAddress$1 = (args, index) => {
236
+ const value = args[index];
237
+ if (typeof value !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(value)) throw new ChainError("invalid-request", "decoded argument is not an address");
238
+ return checksumEvmAddress(value);
239
+ };
240
+ const argList$1 = (args, index) => {
241
+ const value = args[index];
242
+ if (!Array.isArray(value) || !value.every((v) => typeof v === "bigint")) throw new ChainError("invalid-request", "decoded argument is not a uint256 array");
243
+ return value;
244
+ };
245
+ const tokenAmount$1 = (token, amount, table) => {
246
+ const known = lookupEvmToken(table, 1, token);
247
+ return {
248
+ asset: token,
249
+ amount: amount.toString(10),
250
+ ...known === void 0 ? {} : {
251
+ symbol: known.symbol,
252
+ decimals: known.decimals
253
+ }
254
+ };
255
+ };
256
+ const tokenFlow$1 = (token, to, amount, table) => ({
257
+ to,
258
+ amount: tokenAmount$1(token, amount, table),
259
+ verified: lookupEvmToken(table, 1, token) !== void 0
260
+ });
261
+ /**
262
+ * Lido staking on Ethereum mainnet: `submit` to stETH, the four withdrawal-request forms and
263
+ * `claimWithdrawals` on the queue. The minted stETH shares and the checkpointed claim amounts
264
+ * cannot be read exactly from calldata, so every recognised call is verifiability-partial.
265
+ */
266
+ const decodeLido = (chainId, call, signer, table) => {
267
+ if (chainId !== 1 || call.to === void 0) return;
268
+ const to = call.to.toLowerCase();
269
+ if (to === "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84".toLowerCase() && call.value > 0n) {
270
+ if (tryCall$1(SUBMIT, call.data) !== void 0) return {
271
+ outflows: [{
272
+ to: LIDO_STETH,
273
+ amount: {
274
+ asset: EVM_NATIVE_ASSET,
275
+ amount: call.value.toString(10)
276
+ },
277
+ verified: true
278
+ }],
279
+ staking: [{
280
+ kind: "lido-submit",
281
+ amount: {
282
+ asset: EVM_NATIVE_ASSET,
283
+ amount: call.value.toString(10)
284
+ },
285
+ receive: tokenAmount$1(LIDO_STETH, call.value, table)
286
+ }]
287
+ };
288
+ return;
289
+ }
290
+ if (to !== "0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1".toLowerCase()) return;
291
+ for (const [fn, token] of [
292
+ [REQUEST, LIDO_STETH],
293
+ [REQUEST_WSTETH, LIDO_WSTETH],
294
+ [REQUEST_PERMIT, LIDO_STETH],
295
+ [REQUEST_WSTETH_PERMIT, LIDO_WSTETH]
296
+ ]) {
297
+ const args = tryCall$1(fn, call.data);
298
+ if (args === void 0) continue;
299
+ const total = argList$1(args, 0).reduce((sum, amount) => sum + amount, 0n);
300
+ const raw = argAddress$1(args, 1);
301
+ const owner = raw === ZERO ? signer : raw;
302
+ const action = {
303
+ kind: "lido-request",
304
+ token,
305
+ amount: tokenAmount$1(token, total, table),
306
+ owner
307
+ };
308
+ return {
309
+ outflows: owner.toLowerCase() === signer.toLowerCase() ? [] : [tokenFlow$1(token, owner, total, table)],
310
+ staking: [action]
311
+ };
312
+ }
313
+ const claimArgs = tryCall$1(CLAIM, call.data);
314
+ if (claimArgs !== void 0) {
315
+ const requestIds = argList$1(claimArgs, 0).map((id) => id.toString(10));
316
+ argList$1(claimArgs, 1);
317
+ return {
318
+ outflows: [],
319
+ staking: [{
320
+ kind: "lido-claim",
321
+ requestIds
322
+ }]
323
+ };
324
+ }
325
+ };
69
326
  // src/evm/permit.ts
70
327
  const isMessage = isTypedDataMessage;
71
328
  const address = typedDataAddress;
@@ -405,6 +662,186 @@ function recognizeSeaport(json, chainId, table) {
405
662
  consideration
406
663
  };
407
664
  }
665
+ // src/evm/zerox.ts
666
+ /**
667
+ * The 0x AllowanceHolder (`exec`) is deployed at the same address on every chain the taker Settler
668
+ * supports. `exec` grants the caller a one-time allowance of `amount` of `token` to `operator`,
669
+ * then calls `target` with `data` (forwarding `msg.value`).
670
+ */
671
+ const ALLOWANCE_HOLDER = "0x0000000000001fF3684f28c67538d4D072C22734";
672
+ /** Chains whose AllowanceHolder + Settler deployment this decoder recognises. */
673
+ const ZEROX_CHAINS = /* @__PURE__ */ new Set([
674
+ 1,
675
+ 10,
676
+ 56,
677
+ 137,
678
+ 8453,
679
+ 999,
680
+ 42161,
681
+ 43114,
682
+ 11155111
683
+ ]);
684
+ const ZEROX_DEPLOYER = "0x00000000000004533Fe15556B1E086BB1A72cEae";
685
+ const SHIM_INIT_CODE_HASH = "0x3bf3f97f0be1e2c00023033eefeb4fc062ac552ff36778b17060d90b6764902f";
686
+ /** The native-token sentinel 0x uses in `exec`, and the bare zero address (same meaning). */
687
+ const NATIVE_SENTINEL = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
688
+ const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
689
+ const EXEC = AbiFunction.from("function exec(address operator, address token, uint256 amount, address payable target, bytes data)");
690
+ const SETTLER_EXECUTE = AbiFunction.from("function execute((address recipient, address buyToken, uint256 minAmountOut) slippage, bytes[] actions, bytes32 zid)");
691
+ const last20 = (hex) => `0x${hex.slice(-40)}`;
692
+ const addressBytes = (address) => hexToBytes(address.slice(2));
693
+ const bigIntBytes32 = (value) => hexToBytes(value.toString(16).padStart(64, "0"));
694
+ const keccakHex = (parts) => {
695
+ const total = parts.reduce((sum, part) => sum + part.length, 0);
696
+ const flat = new Uint8Array(total);
697
+ let offset = 0;
698
+ for (const part of parts) {
699
+ flat.set(part, offset);
700
+ offset += part.length;
701
+ }
702
+ return `0x${bytesToHex(keccak_256(flat))}`;
703
+ };
704
+ const FEATURE_TAKER = 2n;
705
+ /**
706
+ * Whether `address` is a taker-feature (2) 0x Settler on `chainId`. Settlers deploy as a CREATE2
707
+ * shim whose CREATE child is the contract: `salt = (feature << 128) | (chainId << 64) | nonce`,
708
+ * `shim = CREATE2(deployer, salt, initHash)`, `settler = CREATE(shim, 1)`. Settler is redeployed
709
+ * roughly monthly, so nonces 1..256 leave decades of headroom; the loop runs 512 keccaks and is
710
+ * only reached for an AllowanceHolder `exec`. Feature 5 (bridge) is deliberately not matched.
711
+ */
712
+ const isZeroExSettler = (chainId, address) => {
713
+ const want = address.toLowerCase();
714
+ const deployer = addressBytes(ZEROX_DEPLOYER);
715
+ const initHash = hexToBytes(SHIM_INIT_CODE_HASH.slice(2));
716
+ for (let nonce = 1; nonce <= 256; nonce++) {
717
+ const salt = bigIntBytes32(FEATURE_TAKER * 2n ** 128n + BigInt(chainId) * 2n ** 64n + BigInt(nonce));
718
+ const shim = addressBytes(last20(keccakHex([
719
+ new Uint8Array([255]),
720
+ deployer,
721
+ salt,
722
+ initHash
723
+ ])));
724
+ if (last20(keccakHex([
725
+ new Uint8Array([214, 148]),
726
+ shim,
727
+ new Uint8Array([1])
728
+ ])) === want) return true;
729
+ }
730
+ return false;
731
+ };
732
+ /** The canonical-decoded `exec` arguments, or `undefined` (selector mismatch or non-canonical). */
733
+ const decodeExec = (data) => {
734
+ if (!data.toLowerCase().startsWith("0x2213bc0b")) return;
735
+ try {
736
+ assertHex(data, "data");
737
+ const args = AbiFunction.decodeData(EXEC, data);
738
+ if (!Array.isArray(args) || args.length !== 5) return;
739
+ if (AbiFunction.encodeData(EXEC, args).toLowerCase() !== data.toLowerCase()) return;
740
+ const [operator, token, amount, target, inner] = args;
741
+ if (typeof operator !== "string" || typeof token !== "string" || typeof amount !== "bigint" || typeof target !== "string" || typeof inner !== "string") return;
742
+ return {
743
+ operator,
744
+ token,
745
+ amount,
746
+ target,
747
+ data: inner
748
+ };
749
+ } catch {
750
+ return;
751
+ }
752
+ };
753
+ const isSlippage = (value) => typeof value === "object" && value !== null && "recipient" in value && typeof value.recipient === "string" && "buyToken" in value && typeof value.buyToken === "string" && "minAmountOut" in value && typeof value.minAmountOut === "bigint";
754
+ /**
755
+ * The canonical-decoded `execute` slippage tuple, or `undefined` when the call is not a Settler
756
+ * execute.
757
+ */
758
+ const decodeSettlerExecute = (data) => {
759
+ if (!data.toLowerCase().startsWith("0x1fff991f")) return;
760
+ try {
761
+ assertHex(data, "data");
762
+ const args = AbiFunction.decodeData(SETTLER_EXECUTE, data);
763
+ if (!Array.isArray(args) || args.length !== 3) return;
764
+ if (AbiFunction.encodeData(SETTLER_EXECUTE, args).toLowerCase() !== data.toLowerCase()) return;
765
+ const [slippage] = args;
766
+ if (!isSlippage(slippage)) return;
767
+ return slippage;
768
+ } catch {
769
+ return;
770
+ }
771
+ };
772
+ const isNativeToken = (token) => token.toLowerCase() === NATIVE_SENTINEL || token.toLowerCase() === ZERO_ADDRESS;
773
+ const tokenAmount = (token, amount, chainId, table) => {
774
+ const known = lookupEvmToken(table, chainId, token);
775
+ return {
776
+ asset: checksumEvmAddress(token),
777
+ amount: amount.toString(10),
778
+ ...known === void 0 ? {} : {
779
+ symbol: known.symbol,
780
+ decimals: known.decimals
781
+ }
782
+ };
783
+ };
784
+ const nativeMinimum = (amount) => ({
785
+ asset: EVM_NATIVE_ASSET,
786
+ amount: amount.toString(10)
787
+ });
788
+ /**
789
+ * The `DisplayIntent` for a call to AllowanceHolder `exec` on a chain this decoder covers: a swap
790
+ * when the operator calls the taker Settler's own `execute` (operator == target, an on-chain
791
+ * Settler, a canonical inner call) and a generic one-time allowance otherwise. `undefined` when the
792
+ * call is not to AllowanceHolder or not `exec`.
793
+ */
794
+ const decodeZeroX = (chainId, call, table) => {
795
+ if (call.to === void 0 || call.to.toLowerCase() !== "0x0000000000001fF3684f28c67538d4D072C22734".toLowerCase() || !ZEROX_CHAINS.has(chainId)) return;
796
+ const exec = decodeExec(call.data);
797
+ if (exec === void 0) return;
798
+ const { operator, token, amount, target, data: inner } = exec;
799
+ const slippage = decodeSettlerExecute(inner);
800
+ if (operator.toLowerCase() === target.toLowerCase() && isZeroExSettler(chainId, target) && slippage !== void 0 && slippage !== void 0) {
801
+ let outflow;
802
+ if (isNativeToken(token)) {
803
+ if (amount === call.value && call.value > 0n) outflow = {
804
+ to: target,
805
+ amount: {
806
+ asset: EVM_NATIVE_ASSET,
807
+ amount: call.value.toString(10)
808
+ },
809
+ verified: true
810
+ };
811
+ } else if (call.value === 0n) outflow = {
812
+ to: target,
813
+ amount: tokenAmount(token, amount, chainId, table),
814
+ verified: lookupEvmToken(table, chainId, token) !== void 0
815
+ };
816
+ if (outflow !== void 0) {
817
+ const buyNative = isNativeToken(slippage.buyToken);
818
+ return {
819
+ summary: "swap",
820
+ outflows: [outflow],
821
+ approvals: [],
822
+ minimumReceived: [{
823
+ to: slippage.recipient,
824
+ amount: buyNative ? nativeMinimum(slippage.minAmountOut) : tokenAmount(slippage.buyToken, slippage.minAmountOut, chainId, table)
825
+ }],
826
+ verifiability: "partial"
827
+ };
828
+ }
829
+ }
830
+ const approvals = isNativeToken(token) ? [] : [allowanceChange(checksumEvmAddress(token), operator, amount, "transfer", MAX_UINT256, chainId, table, { via: "allowance-holder" })];
831
+ return {
832
+ summary: "contract-call",
833
+ outflows: call.value === 0n ? [] : [{
834
+ to: target,
835
+ amount: {
836
+ asset: EVM_NATIVE_ASSET,
837
+ amount: call.value.toString(10)
838
+ },
839
+ verified: true
840
+ }],
841
+ approvals,
842
+ verifiability: "partial"
843
+ };
844
+ };
408
845
  // src/evm/decode.ts
409
846
  const ERC20_TRANSFER = AbiFunction.from("function transfer(address to, uint256 amount)");
410
847
  const ERC20_APPROVE = AbiFunction.from("function approve(address spender, uint256 amount)");
@@ -451,7 +888,7 @@ const weiAmount = (wei, symbol, decimals) => ({
451
888
  ...symbol === void 0 ? {} : { symbol },
452
889
  ...decimals === void 0 ? {} : { decimals }
453
890
  });
454
- const feeWei = (tx) => quantityBigInt(tx.gas, "tx.gas") * (tx.type === "eip1559" ? quantityBigInt(tx.maxFeePerGas, "tx.maxFeePerGas") : quantityBigInt(tx.gasPrice, "tx.gasPrice"));
891
+ const feeWei = (tx) => quantityBigInt(tx.gas, "tx.gas") * (tx.type === "eip1559" || tx.type === "eip7702" ? quantityBigInt(tx.maxFeePerGas, "tx.maxFeePerGas") : quantityBigInt(tx.gasPrice, "tx.gasPrice"));
455
892
  const nativeOutflow = (value, to) => [{
456
893
  to,
457
894
  amount: weiAmount(value),
@@ -494,11 +931,12 @@ const pairField = (pair, key) => {
494
931
  const value = typeof pair === "object" && pair !== null ? Reflect.get(pair, key) : "";
495
932
  return argAddress([value], 0);
496
933
  };
497
- const nftFlow = (asset, to, id) => [{
934
+ const nftFlow = (asset, to, id, value = 1n) => [{
498
935
  to,
499
936
  amount: {
500
937
  asset,
501
- amount: id.toString(10)
938
+ amount: value.toString(10),
939
+ tokenId: id.toString(10)
502
940
  },
503
941
  verified: false
504
942
  }];
@@ -506,7 +944,7 @@ const nftFlow = (asset, to, id) => [{
506
944
  * The call rules shared by a whole transaction and a Safe's inner calls: the same selector table
507
945
  * produces the intent; `fee` is `undefined` for a call that is not itself a transaction.
508
946
  */
509
- const decodeCall = (call, network, fee, table) => {
947
+ const decodeCall = (call, network, fee, table, signer) => {
510
948
  const chainId = networkChainId(network);
511
949
  const data = call.data.toLowerCase();
512
950
  const base = {
@@ -531,6 +969,38 @@ const decodeCall = (call, network, fee, table) => {
531
969
  verifiability: "full"
532
970
  };
533
971
  }
972
+ const zeroX = decodeZeroX(chainId, call, table);
973
+ if (zeroX !== void 0) {
974
+ const { summary, outflows, approvals, verifiability, minimumReceived } = zeroX;
975
+ return {
976
+ ...base,
977
+ summary,
978
+ outflows,
979
+ approvals,
980
+ ...minimumReceived === void 0 ? {} : { minimumReceived },
981
+ fee,
982
+ verifiability
983
+ };
984
+ }
985
+ const across = decodeAcross(chainId, call, table);
986
+ if (across !== void 0) return {
987
+ ...base,
988
+ summary: "bridge",
989
+ outflows: across.outflows,
990
+ minimumReceived: across.minimumReceived,
991
+ bridge: across.bridge,
992
+ fee,
993
+ verifiability: "partial"
994
+ };
995
+ const lido = decodeLido(chainId, call, signer, table);
996
+ if (lido !== void 0) return {
997
+ ...base,
998
+ summary: "stake",
999
+ outflows: lido.outflows,
1000
+ staking: lido.staking,
1001
+ fee,
1002
+ verifiability: "partial"
1003
+ };
534
1004
  const transferArgs = tryCall(ERC20_TRANSFER, data);
535
1005
  if (transferArgs !== void 0) {
536
1006
  const { flows, verified } = tokenFlow(call.to ?? "", argAddress(transferArgs, 0), argUint(transferArgs, 1), chainId, table);
@@ -591,13 +1061,14 @@ const decodeCall = (call, network, fee, table) => {
591
1061
  if (args !== void 0) return partial("transfer", nftFlow(token, argAddress(args, 1), argUint(args, 2)), []);
592
1062
  }
593
1063
  const erc1155Args = tryCall(ERC1155_SAFE_FROM, data);
594
- if (erc1155Args !== void 0) return partial("transfer", nftFlow(token, argAddress(erc1155Args, 1), argUint(erc1155Args, 2)), []);
1064
+ if (erc1155Args !== void 0) return partial("transfer", nftFlow(token, argAddress(erc1155Args, 1), argUint(erc1155Args, 2), argUint(erc1155Args, 3)), []);
595
1065
  const batchArgs = tryCall(ERC1155_SAFE_BATCH_FROM, data);
596
1066
  if (batchArgs !== void 0) {
597
1067
  const ids = argList(batchArgs, 2);
598
- if (ids.length > 0 && ids.length === argList(batchArgs, 3).length) {
1068
+ const values = argList(batchArgs, 3);
1069
+ if (ids.length > 0 && ids.length === values.length) {
599
1070
  const to = argAddress(batchArgs, 1);
600
- return partial("transfer", ids.flatMap((id) => nftFlow(token, to, argUint([id], 0))), []);
1071
+ return partial("transfer", ids.flatMap((id, i) => nftFlow(token, to, argUint([id], 0), argUint([values[i] ?? 0n], 0))), []);
601
1072
  }
602
1073
  }
603
1074
  return {
@@ -608,13 +1079,63 @@ const decodeCall = (call, network, fee, table) => {
608
1079
  verifiability: "opaque"
609
1080
  };
610
1081
  };
611
- const decodeTransaction = (request, table) => {
1082
+ /** The delegation field a request carries, present iff the transaction is eip7702. */
1083
+ const delegationOf = (tx) => {
1084
+ if (tx.type !== "eip7702") return;
1085
+ return tx.authorization.address === "0x0000000000000000000000000000000000000000" ? { kind: "revoke" } : {
1086
+ kind: "set",
1087
+ delegator: EVM_DELEGATOR.address,
1088
+ name: EVM_DELEGATOR.name,
1089
+ version: EVM_DELEGATOR.version
1090
+ };
1091
+ };
1092
+ const weakest = (intents) => intents.some((i) => i.verifiability === "opaque") ? "opaque" : intents.some((i) => i.verifiability === "partial") ? "partial" : "full";
1093
+ const decodeTransaction = (request, signer, table) => {
612
1094
  const { tx } = request;
613
- return decodeCall({
1095
+ const fee = { max: weiAmount(feeWei(tx)) };
1096
+ const delegation = delegationOf(tx);
1097
+ const isSelf = tx.to !== void 0 && tx.to.toLowerCase() === signer.toLowerCase() && BigInt(tx.value) === 0n;
1098
+ if (isSelf && tx.data === "0x") return {
1099
+ family: "evm",
1100
+ network: request.network,
1101
+ outflows: [],
1102
+ approvals: [],
1103
+ fee,
1104
+ warnings: [],
1105
+ verifiability: "full",
1106
+ ...delegation === void 0 ? {} : { delegation },
1107
+ summary: tx.type === "eip7702" ? "authorization" : "transfer"
1108
+ };
1109
+ const calls = isSelf ? decodeBatchExecute(tx.data) : void 0;
1110
+ const intent = decodeCall({
614
1111
  to: tx.to,
615
1112
  value: quantityBigInt(tx.value, "tx.value"),
616
1113
  data: tx.data
617
- }, request.network, { max: weiAmount(feeWei(tx)) }, table);
1114
+ }, request.network, fee, table, signer);
1115
+ if (calls !== void 0 && calls.length > 0) {
1116
+ const decoded = calls.map((call) => decodeCall({
1117
+ to: call.to,
1118
+ value: call.value,
1119
+ data: call.data
1120
+ }, request.network, void 0, table, signer));
1121
+ const minimumReceived = decoded.flatMap((d) => d.minimumReceived ?? []);
1122
+ const staking = decoded.flatMap((d) => d.staking ?? []);
1123
+ return {
1124
+ ...intent,
1125
+ summary: "batch",
1126
+ calls: decoded,
1127
+ outflows: decoded.flatMap((d) => d.outflows),
1128
+ approvals: decoded.flatMap((d) => d.approvals),
1129
+ ...staking.length === 0 ? {} : { staking },
1130
+ ...minimumReceived.length === 0 ? {} : { minimumReceived },
1131
+ verifiability: weakest(decoded),
1132
+ ...delegation === void 0 ? {} : { delegation }
1133
+ };
1134
+ }
1135
+ return {
1136
+ ...intent,
1137
+ ...delegation === void 0 ? {} : { delegation }
1138
+ };
618
1139
  };
619
1140
  /** The five EIP-712 domain fields a wallet shows; anything malformed is left out. */
620
1141
  const displayDomain = (domain) => {
@@ -649,13 +1170,13 @@ const messageContent = (bytes) => {
649
1170
  }
650
1171
  };
651
1172
  /** What the signer can guarantee about this request (WD-065). */
652
- const verifiabilityEvm = (request) => decodeEvm(request).verifiability;
1173
+ const verifiabilityEvm = (request, signer) => decodeEvm(request, signer).verifiability;
653
1174
  /**
654
- * Decodes a normalized request into a DisplayIntent. The token table parameter is for tests;
655
- * production callers use the built-in table.
1175
+ * Decodes a normalized request into a DisplayIntent. `signer` is the address of the signing
1176
+ * account; the token table parameter is for tests.
656
1177
  */
657
- const decodeEvm = (request, table = evmTokenTable) => {
658
- if (request.kind === "evm.transaction") return decodeTransaction(request, table);
1178
+ const decodeEvm = (request, signer, table = evmTokenTable) => {
1179
+ if (request.kind === "evm.transaction") return decodeTransaction(request, signer, table);
659
1180
  if (request.kind === "evm.personal-message") return {
660
1181
  family: "evm",
661
1182
  network: request.network,
@@ -669,10 +1190,11 @@ const decodeEvm = (request, table = evmTokenTable) => {
669
1190
  };
670
1191
  if (request.kind !== "evm.typed-data") throw new ChainError("unsupported", `unsupported sign request kind: ${request.kind}`);
671
1192
  const { json } = parseTypedData(request.typedData);
1193
+ assertNoExecutionGrant(json.domain, signer);
672
1194
  const chainId = networkChainId(request.network);
673
1195
  const permit = recognizePermit(json, chainId, table);
674
1196
  const seaport = permit === void 0 ? recognizeSeaport(json, chainId, table) : void 0;
675
- const safe = permit === void 0 && seaport === void 0 ? recognizeSafe(json, (call) => decodeCall(call, request.network, void 0, table)) : void 0;
1197
+ const safe = permit === void 0 && seaport === void 0 ? recognizeSafe(json, (call) => decodeCall(call, request.network, void 0, table, signer)) : void 0;
676
1198
  const message = {
677
1199
  kind: "typed-data",
678
1200
  primaryType: json.primaryType,
@@ -706,6 +1228,9 @@ function assertEip1559Hex(hex) {
706
1228
  function assertEip2930Hex(hex) {
707
1229
  if (!hex.startsWith("0x01")) throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
708
1230
  }
1231
+ function assertEip7702Hex(hex) {
1232
+ if (!hex.startsWith("0x04")) throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
1233
+ }
709
1234
  const signatureOf = (env) => {
710
1235
  const { r, s, yParity } = env;
711
1236
  if (r === void 0 || s === void 0 || yParity === void 0) throw new ChainError("invalid-request", "envelope carries no signature");
@@ -716,9 +1241,33 @@ const signatureOf = (env) => {
716
1241
  });
717
1242
  };
718
1243
  /** Recover the signer's EIP-55 address from a serialized signed transaction envelope. */
719
- const signerFromEnvelope = (signedTransaction) => {
1244
+ const signerFromEnvelope = (signedTransaction, request) => {
720
1245
  const hex = Hex.fromBytes(signedTransaction);
721
1246
  const [tag] = signedTransaction;
1247
+ if (tag === 4) {
1248
+ assertEip7702Hex(hex);
1249
+ const env = TxEnvelopeEip7702.deserialize(hex);
1250
+ const payload = TxEnvelopeEip7702.getSignPayload(env);
1251
+ const signer = Secp256k1.recoverAddress({
1252
+ payload,
1253
+ signature: signatureOf(env)
1254
+ });
1255
+ const auths = env.authorizationList ?? [];
1256
+ const [auth] = auths;
1257
+ if (request === void 0 || request.tx.type !== "eip7702" || auths.length !== 1 || auth === void 0) throw new ChainError("invalid-request", "authorization does not match the request");
1258
+ const { address, chainId, nonce } = auth;
1259
+ const expected = request.tx.authorization.address;
1260
+ if (checksumEvmAddress(address) !== expected || chainId !== request.tx.chainId || nonce !== BigInt(request.tx.nonce + 1)) throw new ChainError("invalid-request", "authorization does not match the request");
1261
+ if (Secp256k1.recoverAddress({
1262
+ payload: Authorization.getSignPayload({
1263
+ address,
1264
+ chainId,
1265
+ nonce
1266
+ }),
1267
+ signature: Signature.from(auth)
1268
+ }).toLowerCase() !== signer.toLowerCase()) throw new ChainError("invalid-request", "authorization signer is not the account");
1269
+ return signer;
1270
+ }
722
1271
  if (tag === 2) {
723
1272
  assertEip1559Hex(hex);
724
1273
  const env = TxEnvelopeEip1559.deserialize(hex);
@@ -755,7 +1304,7 @@ const signerFromEnvelope = (signedTransaction) => {
755
1304
  const recoverEvmSigner = (request, result) => {
756
1305
  if (request.kind === "evm.transaction") {
757
1306
  if (result.signedTransaction === void 0) throw new ChainError("invalid-request", "expected a signed transaction");
758
- return signerFromEnvelope(result.signedTransaction);
1307
+ return signerFromEnvelope(result.signedTransaction, request);
759
1308
  }
760
1309
  if (result.signature === void 0 || result.signature.length !== 65) throw new ChainError("invalid-request", "expected a 65-byte signature");
761
1310
  const signature = Signature.from(result.signature);
@@ -820,6 +1369,6 @@ const normalizeEvm = (request) => {
820
1369
  }
821
1370
  throw new ChainError("unsupported", `unsupported sign request kind: ${request["kind"]}`);
822
1371
  };
823
- export { EVM_NATIVE_ASSET, PERMIT2_ADDRESS, SAFE_MULTISEND_CALL_ONLY, canonicalHex, checksumEvmAddress, decodeEvm, evmAddressFromPublicKey, evmTokenTable, isCanonicalHex, isEvmAddress, lookupEvmToken, networkChainId, normalizeEvm, normalizeEvmTransaction, parseTypedData, recoverEvmSigner, verifiabilityEvm };
1372
+ export { ACROSS_SPOKEPOOLS, ACROSS_WRAPPED_NATIVE, ALLOWANCE_HOLDER, DELEGATION_MANAGER, ENTRY_POINT_V08, EVM_DELEGATION_PREFIX, EVM_DELEGATOR, EVM_NATIVE_ASSET, LIDO_CHAIN, LIDO_QUEUE, LIDO_STETH, LIDO_WSTETH, MAX_UINT256, PERMIT2_ADDRESS, SAFE_MULTISEND_CALL_ONLY, ZEROX_CHAINS, assertNoExecutionGrant, canonicalHex, checksumEvmAddress, decodeAcross, decodeBatchExecute, decodeEvm, decodeZeroX, encodeBatchExecute, evmAddressFromPublicKey, evmTokenTable, isCanonicalHex, isEvmAddress, isZeroExSettler, lookupEvmToken, networkChainId, normalizeEvm, normalizeEvmTransaction, parseTypedData, recoverEvmSigner, verifiabilityEvm };
824
1373
 
825
1374
  //# sourceMappingURL=evm.mjs.map