@qntx/wallet-chains 0.12.0 → 0.14.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 +13 -10
- package/dist/{account-ref-D2rW_qlI.mjs → account-ref-BFTeEyHt.mjs} +2 -2
- package/dist/{account-ref-D2rW_qlI.mjs.map → account-ref-BFTeEyHt.mjs.map} +1 -1
- package/dist/assemble-8GvNDony.mjs +405 -0
- package/dist/assemble-8GvNDony.mjs.map +1 -0
- package/dist/assemble-B3sO9Fvc.mjs +629 -0
- package/dist/assemble-B3sO9Fvc.mjs.map +1 -0
- package/dist/assemble-BdiPo0ZX.mjs +32 -0
- package/dist/assemble-BdiPo0ZX.mjs.map +1 -0
- package/dist/assets-sg2_Z3nZ.mjs +200 -0
- package/dist/assets-sg2_Z3nZ.mjs.map +1 -0
- package/dist/bitcoin-sign.d.mts +3 -0
- package/dist/bitcoin-sign.mjs +52 -18
- package/dist/bitcoin-sign.mjs.map +1 -1
- package/dist/bitcoin.d.mts +123 -7
- package/dist/bitcoin.mjs +162 -69
- package/dist/bitcoin.mjs.map +1 -1
- package/dist/evm-sign.d.mts +3 -1
- package/dist/evm-sign.mjs +25 -82
- package/dist/evm-sign.mjs.map +1 -1
- package/dist/evm.d.mts +252 -22
- package/dist/evm.mjs +2460 -448
- package/dist/evm.mjs.map +1 -1
- package/dist/families-BlgplKAJ.mjs +412 -0
- package/dist/families-BlgplKAJ.mjs.map +1 -0
- package/dist/index-CIRaHKpx.d.mts +941 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/networks.d.mts +29 -0
- package/dist/networks.mjs +245 -0
- package/dist/networks.mjs.map +1 -0
- package/dist/plan-wCnxHqRu.mjs +1311 -0
- package/dist/plan-wCnxHqRu.mjs.map +1 -0
- package/dist/solana-sign.d.mts +3 -0
- package/dist/solana-sign.mjs +23 -10
- package/dist/solana-sign.mjs.map +1 -1
- package/dist/solana.d.mts +136 -24
- package/dist/solana.mjs +1244 -63
- package/dist/solana.mjs.map +1 -1
- package/dist/src-CHB_z45M.mjs +387 -0
- package/dist/src-CHB_z45M.mjs.map +1 -0
- package/dist/tasks-7AFv3PQn.mjs +86 -0
- package/dist/tasks-7AFv3PQn.mjs.map +1 -0
- package/dist/token-call-DH22g8BL.mjs +914 -0
- package/dist/token-call-DH22g8BL.mjs.map +1 -0
- package/dist/tron-sign.d.mts +10 -0
- package/dist/tron-sign.mjs +36 -0
- package/dist/tron-sign.mjs.map +1 -0
- package/dist/tron.d.mts +328 -0
- package/dist/tron.mjs +1484 -0
- package/dist/tron.mjs.map +1 -0
- package/dist/typed-data-CE9h4U0F.d.mts +51 -0
- package/dist/typed-data-DRtKULsH.mjs +466 -0
- package/dist/typed-data-DRtKULsH.mjs.map +1 -0
- package/package.json +17 -10
- package/dist/index-DYwm4-Ec.d.mts +0 -256
- package/dist/message-ChhEZ0lx.mjs +0 -188
- package/dist/message-ChhEZ0lx.mjs.map +0 -1
- package/dist/src-8NZeEnrW.mjs +0 -67
- package/dist/src-8NZeEnrW.mjs.map +0 -1
- package/dist/typed-data-J5g2WemC.mjs +0 -227
- package/dist/typed-data-J5g2WemC.mjs.map +0 -1
package/dist/evm.mjs
CHANGED
|
@@ -1,191 +1,1705 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as requestBase } from "./account-ref-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { i as messageContent, r as messageBlindReason, s as displayExcerpt, t as ChainError } from "./src-CHB_z45M.mjs";
|
|
2
|
+
import { n as requestBase } from "./account-ref-BFTeEyHt.mjs";
|
|
3
|
+
import { n as evmTokenTable, r as lookupEvmToken, t as EVM_NATIVE_ASSET } from "./assets-sg2_Z3nZ.mjs";
|
|
4
|
+
import { a as decodeZeroX, c as orderAmount, d as PERMIT2_ADDRESS, f as allowanceChange, i as ZEROX_CHAINS, l as MAX_UINT160, n as recognizePermit, o as isZeroExSettler, r as ALLOWANCE_HOLDER, s as ORDER_ITEMS, t as decodeTokenCall, u as MAX_UINT256 } from "./token-call-DH22g8BL.mjs";
|
|
5
|
+
import { C as EVM_DELEGATION_PREFIX, D as checksumEvmAddress, E as encodeBatchExecute, O as evmAddressFromPublicKey, S as quantityBigInt, T as decodeBatchExecute, _ as canonicalHex, b as networkChainId, c as sameFields, d as typedDataFields, f as typedDataHasHiddenText, g as assertHex, h as typedDataUint, i as domainChainId, k as isEvmAddress, l as typedDataAddress, m as typedDataMessages, n as TYPED_FIELD_BUDGET, o as isTypedDataMessage, p as typedDataHashes, r as TYPED_FIELD_CODE_POINTS, s as parseTypedData, t as MAX_UINT48, u as typedDataBytes, v as isCanonicalHex, w as EVM_DELEGATOR, x as normalizeEvmTransaction, y as isRecord } from "./typed-data-DRtKULsH.mjs";
|
|
6
|
+
import { c as evmSigningPreimage, d as fiat24SessionMessage, f as fiat24Spender, l as FIAT24_CHAIN, m as isFiat24Contract, n as planEvm, o as evmAuthorization, p as hasFiat24Selector, s as evmEnvelope, t as assembleEvm, u as decodeFiat24 } from "./assemble-B3sO9Fvc.mjs";
|
|
7
|
+
import { withNativeAmountMeta } from "./networks.mjs";
|
|
8
|
+
import { t as RECOGNISED_FAMILIES } from "./families-BlgplKAJ.mjs";
|
|
9
|
+
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
10
|
+
import { bytesToHex, hexToBytes, utf8ToBytes } from "@noble/hashes/utils.js";
|
|
5
11
|
import * as AbiFunction from "ox/AbiFunction";
|
|
12
|
+
import * as AbiParameters from "ox/AbiParameters";
|
|
6
13
|
import * as Hex from "ox/Hex";
|
|
14
|
+
import * as TypedData from "ox/TypedData";
|
|
15
|
+
import * as ContractAddress from "ox/ContractAddress";
|
|
16
|
+
import * as Authorization from "ox/Authorization";
|
|
7
17
|
import * as PersonalMessage from "ox/PersonalMessage";
|
|
8
18
|
import * as Secp256k1 from "ox/Secp256k1";
|
|
9
19
|
import * as Signature from "ox/Signature";
|
|
10
20
|
import * as TxEnvelopeEip1559 from "ox/TxEnvelopeEip1559";
|
|
11
21
|
import * as TxEnvelopeEip2930 from "ox/TxEnvelopeEip2930";
|
|
22
|
+
import * as TxEnvelopeEip7702 from "ox/TxEnvelopeEip7702";
|
|
12
23
|
import * as TxEnvelopeLegacy from "ox/TxEnvelopeLegacy";
|
|
13
|
-
// src/evm/
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
// src/evm/across.ts
|
|
25
|
+
/**
|
|
26
|
+
* Across SpokePool proxies per origin chain — UUPS upgradeable, so the kernel recognises them by
|
|
27
|
+
* address only. Verified against the Across deployments registry on 2026-11-08.
|
|
28
|
+
*/
|
|
29
|
+
const ACROSS_SPOKEPOOLS = {
|
|
30
|
+
1: "0x5c7BCd6E7De5423a257D81B442095A1a6ced35C5",
|
|
31
|
+
10: "0x6f26Bf09B1C792e3228e5467807a900A503c0281",
|
|
32
|
+
56: "0x4e8E101924eDE233C13e2D8622DC8aED2872d505",
|
|
33
|
+
137: "0x9295ee1d8C5b022Be115A2AD3c30C72E34e7F096",
|
|
34
|
+
999: "0x35E63eA3eb0fb7A3bc543C71FB66412e1F6B0E04",
|
|
35
|
+
8453: "0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64",
|
|
36
|
+
42161: "0xe35e9842fceaCA96570B734083f4a58e8F7C5f2A",
|
|
37
|
+
43114: "0xFE9D541c92E4e90437C7152A00244886dE37a658",
|
|
38
|
+
11155111: "0x5ef6C01E11889d86803e0B23e3cB3F9E9d97B662"
|
|
39
|
+
};
|
|
40
|
+
/** Each pool's `wrappedNativeToken()` — read on-chain on 2026-11-08. */
|
|
41
|
+
const ACROSS_WRAPPED_NATIVE = {
|
|
42
|
+
1: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
43
|
+
10: "0x4200000000000000000000000000000000000006",
|
|
44
|
+
56: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
|
|
45
|
+
137: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
|
|
46
|
+
999: "0x5555555555555555555555555555555555555555",
|
|
47
|
+
8453: "0x4200000000000000000000000000000000000006",
|
|
48
|
+
42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
49
|
+
43114: "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
|
|
50
|
+
11155111: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14"
|
|
51
|
+
};
|
|
52
|
+
const DEPOSIT$1 = 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)");
|
|
53
|
+
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)");
|
|
54
|
+
/** Canonical-encoding decode like `tryCall` in decode.ts — undefined on any mismatch. */
|
|
55
|
+
const tryCall$4 = (fn, data) => {
|
|
56
|
+
const selector = AbiFunction.getSelector(fn);
|
|
57
|
+
if (!data.toLowerCase().startsWith(selector)) return;
|
|
58
|
+
try {
|
|
59
|
+
assertHex(data, "data");
|
|
60
|
+
const args = AbiFunction.decodeData(fn, data);
|
|
61
|
+
if (!Array.isArray(args)) return;
|
|
62
|
+
const reencoded = AbiFunction.encodeData(fn, args).toLowerCase();
|
|
63
|
+
return data.toLowerCase().startsWith(reencoded) ? args : void 0;
|
|
64
|
+
} catch {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
/** A bytes32 carrying an EVM address must be left-padded; anything else is a non-EVM target. */
|
|
69
|
+
const paddedAddress$1 = (value) => {
|
|
70
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(value)) return;
|
|
71
|
+
if (value.slice(2, 26) !== "000000000000000000000000") return;
|
|
72
|
+
return checksumEvmAddress(`0x${value.slice(26)}`);
|
|
73
|
+
};
|
|
74
|
+
const tokenAmount$1 = (table, chainId, token, amount) => {
|
|
75
|
+
const meta = table === void 0 ? void 0 : lookupEvmToken(table, chainId, token);
|
|
76
|
+
return meta === void 0 ? {
|
|
77
|
+
asset: token,
|
|
78
|
+
amount: amount.toString(10)
|
|
79
|
+
} : {
|
|
80
|
+
asset: token,
|
|
81
|
+
amount: amount.toString(10),
|
|
82
|
+
decimals: meta.decimals,
|
|
83
|
+
symbol: meta.symbol
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const argUint$2 = (args, index) => {
|
|
87
|
+
const v = args[index];
|
|
88
|
+
return typeof v === "bigint" ? v : typeof v === "number" ? BigInt(v) : void 0;
|
|
89
|
+
};
|
|
90
|
+
const argAddress$2 = (args, index) => {
|
|
91
|
+
const v = args[index];
|
|
92
|
+
return typeof v === "string" && /^0x[0-9a-fA-F]{40}$/.test(v) ? checksumEvmAddress(v) : void 0;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Decodes a `deposit`/`depositV3` to the chain's SpokePool — empty `message` only; bytes32 fields
|
|
96
|
+
* must carry left-padded EVM addresses (non-EVM destinations are not recognised). The deposit
|
|
97
|
+
* guarantees `outputAmount` on the destination chain or a refund to `depositor` after
|
|
98
|
+
* `fillDeadline`, so the intent's `minimumReceived` and `bridge` fields carry those terms.
|
|
99
|
+
*/
|
|
100
|
+
const decodeAcross = (chainId, call, table) => {
|
|
101
|
+
const pool = ACROSS_SPOKEPOOLS[chainId];
|
|
102
|
+
if (pool === void 0 || call.to === void 0 || call.to.toLowerCase() !== pool.toLowerCase()) return;
|
|
103
|
+
const v4 = tryCall$4(DEPOSIT$1, call.data);
|
|
104
|
+
const v3 = v4 === void 0 ? tryCall$4(DEPOSIT_V3, call.data) : void 0;
|
|
105
|
+
if (v4 === void 0 && v3 === void 0) return;
|
|
106
|
+
const args = v4 ?? v3 ?? [];
|
|
107
|
+
const [depositor, recipient, inputToken, outputToken] = [
|
|
108
|
+
0,
|
|
109
|
+
1,
|
|
110
|
+
2,
|
|
111
|
+
3
|
|
112
|
+
].map((i) => v4 === void 0 ? argAddress$2(args, i) : paddedAddress$1(args[i]));
|
|
113
|
+
if (depositor === void 0 || recipient === void 0 || inputToken === void 0 || outputToken === void 0) return;
|
|
114
|
+
const inputAmount = argUint$2(args, 4);
|
|
115
|
+
const outputAmount = argUint$2(args, 5);
|
|
116
|
+
const destinationChainId = argUint$2(args, 6);
|
|
117
|
+
const fillDeadline = argUint$2(args, 9);
|
|
118
|
+
const message = args.at(11);
|
|
119
|
+
if (inputAmount === void 0 || outputAmount === void 0 || destinationChainId === void 0 || fillDeadline === void 0 || message !== "0x") return;
|
|
120
|
+
const native = call.value > 0n && inputToken.toLowerCase() === (ACROSS_WRAPPED_NATIVE[chainId] ?? "").toLowerCase();
|
|
121
|
+
if (call.value > 0n && (!native || call.value !== inputAmount)) return;
|
|
122
|
+
return {
|
|
123
|
+
outflows: [{
|
|
124
|
+
to: pool,
|
|
125
|
+
amount: native ? {
|
|
126
|
+
asset: EVM_NATIVE_ASSET,
|
|
127
|
+
amount: call.value.toString(10)
|
|
128
|
+
} : tokenAmount$1(table, chainId, inputToken, inputAmount),
|
|
129
|
+
verified: true
|
|
130
|
+
}],
|
|
131
|
+
minimumReceived: [{
|
|
132
|
+
to: recipient,
|
|
133
|
+
amount: tokenAmount$1(table, Number(destinationChainId), outputToken, outputAmount),
|
|
134
|
+
verified: true
|
|
135
|
+
}],
|
|
136
|
+
bridge: {
|
|
137
|
+
destinationNetwork: `eip155:${destinationChainId.toString(10)}`,
|
|
138
|
+
fillDeadline: Number(fillDeadline),
|
|
139
|
+
refundTo: depositor
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
// src/evm/hyperliquid.ts
|
|
144
|
+
/**
|
|
145
|
+
* Recognition of Hyperliquid user-signed actions: EIP-712 documents under the
|
|
146
|
+
* `HyperliquidSignTransaction` domain (version "1", zero verifying contract) whose only struct is
|
|
147
|
+
* one `HyperliquidTransaction:<X>` type with exactly the field list nktkas's `<X>Types` constants
|
|
148
|
+
* declare (`src/api/exchange/_methods/*.ts` in @nktkas/hyperliquid 0.33.3; python `signing.py`'s
|
|
149
|
+
* `*_SIGN_TYPES` agree). Every signed field must parse strictly, else the document is left
|
|
150
|
+
* unclaimed and the family table blinds it as `typed-data-variant`.
|
|
151
|
+
*
|
|
152
|
+
* The user-signed types left unclaimed on purpose — all blind `typed-data-variant` via the
|
|
153
|
+
* "Hyperliquid" family row:
|
|
154
|
+
*
|
|
155
|
+
* - `ConvertToMultiSigUser` — hands account authority to a signer set given as JSON text (nktkas
|
|
156
|
+
* convertToMultiSigUser.ts:124)
|
|
157
|
+
* - `LinkStakingUser` (linkStakingUser.ts:106) and `StakingLinkDisableTradingUser`
|
|
158
|
+
* (stakingLinkDisableTradingUser.ts:105) — rebind trading authority to another address
|
|
159
|
+
* - `SendToEvmWithData` — carries an arbitrary `data` call (sendToEvmWithData.ts:110)
|
|
160
|
+
* - `UserDexAbstraction` (userDexAbstraction.ts:100), `UserPortfolioMargin`
|
|
161
|
+
* (userPortfolioMargin.ts:98) and `UserSetAbstraction` (userSetAbstraction.ts:101) — change how
|
|
162
|
+
* the account's orders and transfers are routed
|
|
163
|
+
* - `SendMultiSig` — the envelope signs only a bytes32 hash of the real action (python signing.py
|
|
164
|
+
* `MULTI_SIG_ENVELOPE_SIGN_TYPES`), the same commitment problem as L1
|
|
165
|
+
* - Any type with `payloadMultiSigUser`/`outerSigner` injected for inner multi-sig signatures — the
|
|
166
|
+
* field-list check fails (nktkas _userSigned.ts `signUserSignedInner`)
|
|
167
|
+
*
|
|
168
|
+
* The L1 trading actions are not user-signed data: they sign `Agent{source,connectionId}` under the
|
|
169
|
+
* `Exchange` domain where `connectionId` is a keccak of the msgpack action (nktkas _l1.ts) — a
|
|
170
|
+
* commitment no prompt can bound, blind `typed-data-commitment` via the "Hyperliquid L1" row.
|
|
171
|
+
*/
|
|
172
|
+
const ZERO_ADDRESS$1 = "0x0000000000000000000000000000000000000000";
|
|
173
|
+
const MAX_UINT64 = 2n ** 64n - 1n;
|
|
174
|
+
const EIP712_DOMAIN$1 = [
|
|
175
|
+
"string name",
|
|
176
|
+
"string version",
|
|
177
|
+
"uint256 chainId",
|
|
178
|
+
"address verifyingContract"
|
|
179
|
+
];
|
|
180
|
+
const PREFIX = "HyperliquidTransaction:";
|
|
181
|
+
const AMOUNT = /^[0-9]{1,15}(\.[0-9]{1,8})?$/;
|
|
182
|
+
const STRING_ADDRESS = /^0x[0-9a-f]{40}$/;
|
|
183
|
+
const TOKEN = /^[A-Za-z0-9]{1,16}:0x[0-9a-f]{32}$/;
|
|
184
|
+
const DEX_NAME = /^[A-Za-z0-9]{0,16}$/;
|
|
185
|
+
const FEE_RATE = /^[0-9]{1,3}(\.[0-9]{1,6})?%$/;
|
|
186
|
+
const AGENT_EXPIRY = / valid_until (\d{1,16})$/;
|
|
187
|
+
const amount$1 = (value) => typeof value === "string" && AMOUNT.test(value) ? value : void 0;
|
|
188
|
+
const stringAddress = (value) => typeof value === "string" && STRING_ADDRESS.test(value) ? checksumEvmAddress(value) : void 0;
|
|
189
|
+
const token = (value) => typeof value === "string" && TOKEN.test(value) ? value : void 0;
|
|
190
|
+
const dexName = (value) => typeof value === "string" && DEX_NAME.test(value) ? value : void 0;
|
|
191
|
+
const uint64 = (value) => typedDataUint(value, MAX_UINT64);
|
|
192
|
+
const boolean = (value) => typeof value === "boolean" ? value : void 0;
|
|
193
|
+
/**
|
|
194
|
+
* The agent name with its ` valid_until <ms>` suffix split off. The base must fit on one safe line
|
|
195
|
+
* — it is shown verbatim — at most 16 code points (the exchange's limit), free of unsafe code
|
|
196
|
+
* points and without "valid_until" inside it; `""` is a valid unnamed agent.
|
|
197
|
+
*/
|
|
198
|
+
const agentName = (value) => {
|
|
199
|
+
if (typeof value !== "string") return;
|
|
200
|
+
const expiry = AGENT_EXPIRY.exec(value);
|
|
201
|
+
const base = expiry === null ? value : value.slice(0, expiry.index);
|
|
202
|
+
const excerpt = displayExcerpt(base, 1, 16);
|
|
203
|
+
if (excerpt.omitted !== 0 || (excerpt.lines[0] ?? "") !== base || base.includes("valid_until")) return;
|
|
204
|
+
if (expiry === null) return { name: base };
|
|
205
|
+
const validUntil = Number(expiry[1]);
|
|
206
|
+
return validUntil <= Number.MAX_SAFE_INTEGER ? {
|
|
207
|
+
name: base,
|
|
208
|
+
validUntil
|
|
209
|
+
} : void 0;
|
|
210
|
+
};
|
|
211
|
+
const transferFields = (chain, message, kind) => {
|
|
212
|
+
const destination = stringAddress(message["destination"]);
|
|
213
|
+
const value = amount$1(message["amount"]);
|
|
214
|
+
return destination === void 0 || value === void 0 || uint64(message["time"]) === void 0 ? void 0 : {
|
|
215
|
+
kind,
|
|
216
|
+
chain,
|
|
217
|
+
destination,
|
|
218
|
+
amount: value
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
const stakingFields = (chain, message, kind) => {
|
|
222
|
+
const wei = uint64(message["wei"]);
|
|
223
|
+
return wei === void 0 || uint64(message["nonce"]) === void 0 ? void 0 : {
|
|
224
|
+
kind,
|
|
225
|
+
chain,
|
|
226
|
+
wei: wei.toString(10)
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
const DESCRIBED = [
|
|
230
|
+
{
|
|
231
|
+
suffix: "UsdSend",
|
|
232
|
+
fields: [
|
|
233
|
+
"string hyperliquidChain",
|
|
234
|
+
"string destination",
|
|
235
|
+
"string amount",
|
|
236
|
+
"uint64 time"
|
|
237
|
+
],
|
|
238
|
+
summary: "transfer",
|
|
239
|
+
verifiability: "full",
|
|
240
|
+
build: (chain, message) => transferFields(chain, message, "usd-send")
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
suffix: "Withdraw",
|
|
244
|
+
fields: [
|
|
245
|
+
"string hyperliquidChain",
|
|
246
|
+
"string destination",
|
|
247
|
+
"string amount",
|
|
248
|
+
"uint64 time"
|
|
249
|
+
],
|
|
250
|
+
summary: "transfer",
|
|
251
|
+
verifiability: "partial",
|
|
252
|
+
build: (chain, message) => transferFields(chain, message, "withdraw")
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
suffix: "SpotSend",
|
|
256
|
+
fields: [
|
|
257
|
+
"string hyperliquidChain",
|
|
258
|
+
"string destination",
|
|
259
|
+
"string token",
|
|
260
|
+
"string amount",
|
|
261
|
+
"uint64 time"
|
|
262
|
+
],
|
|
263
|
+
summary: "transfer",
|
|
264
|
+
verifiability: "partial",
|
|
265
|
+
build: (chain, message) => {
|
|
266
|
+
const destination = stringAddress(message["destination"]);
|
|
267
|
+
const asset = token(message["token"]);
|
|
268
|
+
const value = amount$1(message["amount"]);
|
|
269
|
+
return destination === void 0 || asset === void 0 || value === void 0 || uint64(message["time"]) === void 0 ? void 0 : {
|
|
270
|
+
kind: "spot-send",
|
|
271
|
+
chain,
|
|
272
|
+
destination,
|
|
273
|
+
token: asset,
|
|
274
|
+
amount: value
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
suffix: "UsdClassTransfer",
|
|
280
|
+
fields: [
|
|
281
|
+
"string hyperliquidChain",
|
|
282
|
+
"string amount",
|
|
283
|
+
"bool toPerp",
|
|
284
|
+
"uint64 nonce"
|
|
285
|
+
],
|
|
286
|
+
summary: "transfer",
|
|
287
|
+
verifiability: "full",
|
|
288
|
+
build: (chain, message) => {
|
|
289
|
+
const value = amount$1(message["amount"]);
|
|
290
|
+
const toPerp = boolean(message["toPerp"]);
|
|
291
|
+
return value === void 0 || toPerp === void 0 || uint64(message["nonce"]) === void 0 ? void 0 : {
|
|
292
|
+
kind: "usd-class-transfer",
|
|
293
|
+
chain,
|
|
294
|
+
amount: value,
|
|
295
|
+
toPerp
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
suffix: "SendAsset",
|
|
301
|
+
fields: [
|
|
302
|
+
"string hyperliquidChain",
|
|
303
|
+
"string destination",
|
|
304
|
+
"string sourceDex",
|
|
305
|
+
"string destinationDex",
|
|
306
|
+
"string token",
|
|
307
|
+
"string amount",
|
|
308
|
+
"string fromSubAccount",
|
|
309
|
+
"uint64 nonce"
|
|
310
|
+
],
|
|
311
|
+
summary: "transfer",
|
|
312
|
+
verifiability: "partial",
|
|
313
|
+
build: (chain, message) => {
|
|
314
|
+
const destination = stringAddress(message["destination"]);
|
|
315
|
+
const sourceDex = dexName(message["sourceDex"]);
|
|
316
|
+
const destinationDex = dexName(message["destinationDex"]);
|
|
317
|
+
const asset = token(message["token"]);
|
|
318
|
+
const value = amount$1(message["amount"]);
|
|
319
|
+
const subAccount = message["fromSubAccount"];
|
|
320
|
+
const fromSubAccount = subAccount === "" ? "" : stringAddress(subAccount);
|
|
321
|
+
return destination === void 0 || sourceDex === void 0 || destinationDex === void 0 || asset === void 0 || value === void 0 || fromSubAccount === void 0 || uint64(message["nonce"]) === void 0 ? void 0 : {
|
|
322
|
+
kind: "send-asset",
|
|
323
|
+
chain,
|
|
324
|
+
destination,
|
|
325
|
+
sourceDex,
|
|
326
|
+
destinationDex,
|
|
327
|
+
token: asset,
|
|
328
|
+
amount: value,
|
|
329
|
+
...fromSubAccount === "" ? {} : { fromSubAccount }
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
suffix: "CDeposit",
|
|
335
|
+
fields: [
|
|
336
|
+
"string hyperliquidChain",
|
|
337
|
+
"uint64 wei",
|
|
338
|
+
"uint64 nonce"
|
|
339
|
+
],
|
|
340
|
+
summary: "stake",
|
|
341
|
+
verifiability: "full",
|
|
342
|
+
build: (chain, message) => stakingFields(chain, message, "staking-deposit")
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
suffix: "CWithdraw",
|
|
346
|
+
fields: [
|
|
347
|
+
"string hyperliquidChain",
|
|
348
|
+
"uint64 wei",
|
|
349
|
+
"uint64 nonce"
|
|
350
|
+
],
|
|
351
|
+
summary: "stake",
|
|
352
|
+
verifiability: "full",
|
|
353
|
+
build: (chain, message) => stakingFields(chain, message, "staking-withdraw")
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
suffix: "TokenDelegate",
|
|
357
|
+
fields: [
|
|
358
|
+
"string hyperliquidChain",
|
|
359
|
+
"address validator",
|
|
360
|
+
"uint64 wei",
|
|
361
|
+
"bool isUndelegate",
|
|
362
|
+
"uint64 nonce"
|
|
363
|
+
],
|
|
364
|
+
summary: "stake",
|
|
365
|
+
verifiability: "partial",
|
|
366
|
+
build: (chain, message) => {
|
|
367
|
+
const validator = typedDataAddress(message["validator"]);
|
|
368
|
+
const wei = uint64(message["wei"]);
|
|
369
|
+
const undelegate = boolean(message["isUndelegate"]);
|
|
370
|
+
return validator === void 0 || wei === void 0 || undelegate === void 0 || uint64(message["nonce"]) === void 0 ? void 0 : {
|
|
371
|
+
kind: "token-delegate",
|
|
372
|
+
chain,
|
|
373
|
+
validator,
|
|
374
|
+
wei: wei.toString(10),
|
|
375
|
+
undelegate
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
suffix: "ApproveAgent",
|
|
381
|
+
fields: [
|
|
382
|
+
"string hyperliquidChain",
|
|
383
|
+
"address agentAddress",
|
|
384
|
+
"string agentName",
|
|
385
|
+
"uint64 nonce"
|
|
386
|
+
],
|
|
387
|
+
summary: "approve",
|
|
388
|
+
verifiability: "partial",
|
|
389
|
+
build: (chain, message) => {
|
|
390
|
+
const agent = typedDataAddress(message["agentAddress"]);
|
|
391
|
+
const name = agentName(message["agentName"]);
|
|
392
|
+
return agent === void 0 || name === void 0 || uint64(message["nonce"]) === void 0 ? void 0 : {
|
|
393
|
+
kind: "approve-agent",
|
|
394
|
+
chain,
|
|
395
|
+
agent,
|
|
396
|
+
name: name.name,
|
|
397
|
+
...name.validUntil === void 0 ? {} : { validUntil: name.validUntil }
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
suffix: "ApproveBuilderFee",
|
|
403
|
+
fields: [
|
|
404
|
+
"string hyperliquidChain",
|
|
405
|
+
"string maxFeeRate",
|
|
406
|
+
"address builder",
|
|
407
|
+
"uint64 nonce"
|
|
408
|
+
],
|
|
409
|
+
summary: "approve",
|
|
410
|
+
verifiability: "partial",
|
|
411
|
+
build: (chain, message) => {
|
|
412
|
+
const { maxFeeRate } = message;
|
|
413
|
+
const builder = typedDataAddress(message["builder"]);
|
|
414
|
+
return typeof maxFeeRate !== "string" || !FEE_RATE.test(maxFeeRate) || builder === void 0 || uint64(message["nonce"]) === void 0 ? void 0 : {
|
|
415
|
+
kind: "approve-builder-fee",
|
|
416
|
+
chain,
|
|
417
|
+
builder,
|
|
418
|
+
maxFeeRate
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
];
|
|
423
|
+
/**
|
|
424
|
+
* The Hyperliquid user-signed action a typed-data document signs, or `undefined` when the document
|
|
425
|
+
* is not exactly the described shape — every extra type, renamed or reordered field and unparsable
|
|
426
|
+
* value rejects the whole document, so what is described is exactly what is hashed. Message keys
|
|
427
|
+
* the type does not declare (the SDKs' `type`, `signatureChainId`) are not signed and are ignored
|
|
428
|
+
* here.
|
|
429
|
+
*/
|
|
430
|
+
function recognizeHyperliquid(json) {
|
|
431
|
+
const { types, primaryType, domain, message } = json;
|
|
432
|
+
if (domain["name"] !== "HyperliquidSignTransaction" || domain["version"] !== "1" || domainChainId(domain) === void 0 || typedDataAddress(domain["verifyingContract"])?.toLowerCase() !== ZERO_ADDRESS$1 || !sameFields(types, "EIP712Domain", EIP712_DOMAIN$1) || Object.keys(types).length !== 2 || types[primaryType] === void 0 || !primaryType.startsWith(PREFIX)) return;
|
|
433
|
+
const described = DESCRIBED.find((entry) => entry.suffix === primaryType.slice(23));
|
|
434
|
+
const chain = message["hyperliquidChain"];
|
|
435
|
+
if (described === void 0 || !sameFields(types, primaryType, described.fields) || chain !== "Mainnet" && chain !== "Testnet") return;
|
|
436
|
+
const action = described.build(chain, message);
|
|
437
|
+
return action === void 0 ? void 0 : {
|
|
438
|
+
action,
|
|
439
|
+
summary: described.summary,
|
|
440
|
+
verifiability: described.verifiability
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
// src/evm/polymarket.ts
|
|
444
|
+
const MAX_UINT256$1 = 2n ** 256n - 1n;
|
|
445
|
+
const ZERO_BYTES32 = `0x${"0".repeat(64)}`;
|
|
446
|
+
const EXCHANGES = [
|
|
447
|
+
{
|
|
448
|
+
chainId: 137,
|
|
449
|
+
address: "0xE111180000d2663C0091e4f400237545B87B996B",
|
|
450
|
+
version: "2",
|
|
451
|
+
name: "CTF Exchange",
|
|
452
|
+
outcomeToken: "0x4D97DCd97eC945f40cF65F87097ACe5EA0476045"
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
chainId: 137,
|
|
456
|
+
address: "0xe2222d279d744050d28e00520010520000310F59",
|
|
457
|
+
version: "2",
|
|
458
|
+
name: "Neg Risk CTF Exchange",
|
|
459
|
+
outcomeToken: "0x4D97DCd97eC945f40cF65F87097ACe5EA0476045"
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
chainId: 137,
|
|
463
|
+
address: "0xe3333700cA9d93003F00f0F71f8515005F6c00Aa",
|
|
464
|
+
version: "3",
|
|
465
|
+
name: "Exchange V3",
|
|
466
|
+
outcomeToken: "0x006F54F7f9A22e0000CC2AB60031000000ae9fEF"
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
chainId: 80002,
|
|
470
|
+
address: "0xE111180000d2663C0091e4f400237545B87B996B",
|
|
471
|
+
version: "2",
|
|
472
|
+
name: "CTF Exchange",
|
|
473
|
+
outcomeToken: "0x69308FB512518e39F9b16112fA8d994F4e2Bf8bB"
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
chainId: 80002,
|
|
477
|
+
address: "0xe2222d279d744050d28e00520010520000310F59",
|
|
478
|
+
version: "2",
|
|
479
|
+
name: "Neg Risk CTF Exchange",
|
|
480
|
+
outcomeToken: "0x69308FB512518e39F9b16112fA8d994F4e2Bf8bB"
|
|
481
|
+
}
|
|
482
|
+
];
|
|
483
|
+
const PUSD = "0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB";
|
|
484
|
+
const DECIMALS = 6;
|
|
485
|
+
const EIP712_DOMAIN = [
|
|
486
|
+
"string name",
|
|
487
|
+
"string version",
|
|
488
|
+
"uint256 chainId",
|
|
489
|
+
"address verifyingContract"
|
|
490
|
+
];
|
|
491
|
+
const EIP712_DOMAIN_AUTH = [
|
|
492
|
+
"string name",
|
|
493
|
+
"string version",
|
|
494
|
+
"uint256 chainId"
|
|
495
|
+
];
|
|
496
|
+
const ORDER_FIELDS$2 = [
|
|
497
|
+
"uint256 salt",
|
|
498
|
+
"address maker",
|
|
499
|
+
"address signer",
|
|
500
|
+
"uint256 tokenId",
|
|
501
|
+
"uint256 makerAmount",
|
|
502
|
+
"uint256 takerAmount",
|
|
503
|
+
"uint8 side",
|
|
504
|
+
"uint8 signatureType",
|
|
505
|
+
"uint256 timestamp",
|
|
506
|
+
"bytes32 metadata",
|
|
507
|
+
"bytes32 builder"
|
|
508
|
+
];
|
|
509
|
+
const TYPED_DATA_SIGN_FIELDS = [
|
|
510
|
+
"Order contents",
|
|
511
|
+
"string name",
|
|
512
|
+
"string version",
|
|
513
|
+
"uint256 chainId",
|
|
514
|
+
"address verifyingContract",
|
|
515
|
+
"bytes32 salt"
|
|
516
|
+
];
|
|
517
|
+
const CLOB_AUTH_FIELDS = [
|
|
518
|
+
"address address",
|
|
519
|
+
"string timestamp",
|
|
520
|
+
"uint256 nonce",
|
|
521
|
+
"string message"
|
|
522
|
+
];
|
|
523
|
+
const BATCH_FIELDS = [
|
|
524
|
+
"address wallet",
|
|
525
|
+
"uint256 nonce",
|
|
526
|
+
"uint256 deadline",
|
|
527
|
+
"Call[] calls"
|
|
528
|
+
];
|
|
529
|
+
const CALL_FIELDS = [
|
|
530
|
+
"address target",
|
|
531
|
+
"uint256 value",
|
|
532
|
+
"bytes data"
|
|
533
|
+
];
|
|
534
|
+
const CLOB_AUTH_MESSAGE = "This message attests that I control the given wallet";
|
|
535
|
+
const BATCH_CALLS_MAX = 8;
|
|
536
|
+
const BYTES32 = /^0x[0-9a-fA-F]{64}$/;
|
|
537
|
+
const bytes32 = (value) => typeof value === "string" && BYTES32.test(value) ? value.toLowerCase() : void 0;
|
|
538
|
+
const nonZero = (hex) => hex === ZERO_BYTES32 ? void 0 : hex;
|
|
539
|
+
const uint = (value) => typedDataUint(value, MAX_UINT256$1);
|
|
540
|
+
const sameAddress = (a, b) => a !== void 0 && b !== void 0 && a.toLowerCase() === b.toLowerCase();
|
|
541
|
+
/** The strict parse both `Order` and `TypedDataSign.contents` share. */
|
|
542
|
+
const orderValues = (message) => {
|
|
543
|
+
const maker = typedDataAddress(message["maker"]);
|
|
544
|
+
const signer = typedDataAddress(message["signer"]);
|
|
545
|
+
const tokenId = uint(message["tokenId"]);
|
|
546
|
+
const makerAmount = uint(message["makerAmount"]);
|
|
547
|
+
const takerAmount = uint(message["takerAmount"]);
|
|
548
|
+
const side = uint(message["side"]);
|
|
549
|
+
const signatureType = uint(message["signatureType"]);
|
|
550
|
+
const metadata = bytes32(message["metadata"]);
|
|
551
|
+
const builder = bytes32(message["builder"]);
|
|
552
|
+
if (maker === void 0 || signer === void 0 || tokenId === void 0 || makerAmount === void 0 || makerAmount === 0n || takerAmount === void 0 || takerAmount === 0n || side === void 0 || side > 1n || signatureType === void 0 || signatureType > 3n || uint(message["salt"]) === void 0 || uint(message["timestamp"]) === void 0 || metadata === void 0 || builder === void 0) return;
|
|
553
|
+
const meta = nonZero(metadata);
|
|
554
|
+
const code = nonZero(builder);
|
|
555
|
+
return {
|
|
556
|
+
maker,
|
|
557
|
+
signer,
|
|
558
|
+
tokenId: tokenId.toString(10),
|
|
559
|
+
side: side === 0n ? "buy" : "sell",
|
|
560
|
+
signatureType,
|
|
561
|
+
makerAmount,
|
|
562
|
+
takerAmount,
|
|
563
|
+
...meta === void 0 ? {} : { metadata: meta },
|
|
564
|
+
...code === void 0 ? {} : { builder: code }
|
|
565
|
+
};
|
|
566
|
+
};
|
|
567
|
+
const orderContent = (order, exchange, wallet) => {
|
|
568
|
+
const buy = order.side === "buy";
|
|
569
|
+
const pusd = {
|
|
570
|
+
asset: PUSD,
|
|
571
|
+
decimals: DECIMALS,
|
|
572
|
+
symbol: "pUSD"
|
|
573
|
+
};
|
|
574
|
+
const shares = {
|
|
575
|
+
asset: exchange.outcomeToken,
|
|
576
|
+
decimals: DECIMALS,
|
|
577
|
+
tokenId: order.tokenId
|
|
578
|
+
};
|
|
579
|
+
const give = buy ? {
|
|
580
|
+
...pusd,
|
|
581
|
+
amount: order.makerAmount.toString(10)
|
|
582
|
+
} : {
|
|
583
|
+
...shares,
|
|
584
|
+
amount: order.makerAmount.toString(10)
|
|
585
|
+
};
|
|
586
|
+
const receive = buy ? {
|
|
587
|
+
...shares,
|
|
588
|
+
amount: order.takerAmount.toString(10)
|
|
589
|
+
} : {
|
|
590
|
+
...pusd,
|
|
591
|
+
amount: order.takerAmount.toString(10)
|
|
592
|
+
};
|
|
593
|
+
const collateral = buy ? order.makerAmount : order.takerAmount;
|
|
594
|
+
const amount = buy ? order.takerAmount : order.makerAmount;
|
|
595
|
+
const price = collateral * 10n ** BigInt(DECIMALS) / amount;
|
|
596
|
+
return {
|
|
597
|
+
kind: "order",
|
|
598
|
+
exchange: {
|
|
599
|
+
address: exchange.address,
|
|
600
|
+
name: exchange.name,
|
|
601
|
+
version: exchange.version
|
|
602
|
+
},
|
|
603
|
+
side: order.side,
|
|
604
|
+
tokenId: order.tokenId,
|
|
605
|
+
maker: order.maker,
|
|
606
|
+
signer: order.signer,
|
|
607
|
+
wallet,
|
|
608
|
+
give,
|
|
609
|
+
receive,
|
|
610
|
+
price: {
|
|
611
|
+
amount: price.toString(10),
|
|
612
|
+
exact: price * amount === collateral * 10n ** BigInt(DECIMALS)
|
|
613
|
+
},
|
|
614
|
+
...order.builder === void 0 ? {} : { builder: order.builder },
|
|
615
|
+
...order.metadata === void 0 ? {} : { metadata: order.metadata }
|
|
616
|
+
};
|
|
617
|
+
};
|
|
618
|
+
/** The "Polymarket CTF Exchange" domain against the exchange allow-list. */
|
|
619
|
+
const exchangeDomain = (json) => {
|
|
620
|
+
const { domain, types } = json;
|
|
621
|
+
const chainId = domainChainId(domain);
|
|
622
|
+
if (domain["name"] !== "Polymarket CTF Exchange" || chainId === void 0 || !sameFields(types, "EIP712Domain", EIP712_DOMAIN)) return;
|
|
623
|
+
const verifying = typedDataAddress(domain["verifyingContract"]);
|
|
624
|
+
return EXCHANGES.find((row) => row.chainId === chainId && row.address.toLowerCase() === verifying?.toLowerCase() && row.version === domain["version"]);
|
|
625
|
+
};
|
|
626
|
+
const typeSet = (types, names) => Object.keys(types).length === names.length && names.every((name) => types[name] !== void 0);
|
|
627
|
+
const orderResult = (json, exchange, context) => {
|
|
628
|
+
if (json.primaryType !== "Order" || !typeSet(json.types, ["EIP712Domain", "Order"]) || !sameFields(json.types, "Order", ORDER_FIELDS$2)) return;
|
|
629
|
+
const order = orderValues(json.message);
|
|
630
|
+
if (order === void 0 || order.signatureType > 2n || !sameAddress(order.signer, context.signer) || order.signatureType === 0n && !sameAddress(order.maker, order.signer)) return;
|
|
631
|
+
const wallet = order.signatureType === 0n ? "account" : order.signatureType === 1n ? "proxy" : "safe";
|
|
632
|
+
const content = orderContent(order, exchange, wallet);
|
|
633
|
+
return {
|
|
634
|
+
content: { polymarket: content },
|
|
635
|
+
summary: "swap",
|
|
636
|
+
outflows: [{
|
|
637
|
+
to: exchange.address,
|
|
638
|
+
amount: content.give,
|
|
639
|
+
verified: content.give.asset === PUSD
|
|
640
|
+
}],
|
|
641
|
+
approvals: [],
|
|
642
|
+
verifiability: "partial"
|
|
643
|
+
};
|
|
644
|
+
};
|
|
645
|
+
const typedDataSignResult = (json, exchange) => {
|
|
646
|
+
if (json.primaryType !== "TypedDataSign" || !typeSet(json.types, [
|
|
647
|
+
"EIP712Domain",
|
|
648
|
+
"TypedDataSign",
|
|
649
|
+
"Order"
|
|
650
|
+
]) || !sameFields(json.types, "TypedDataSign", TYPED_DATA_SIGN_FIELDS) || !sameFields(json.types, "Order", ORDER_FIELDS$2)) return;
|
|
651
|
+
const { message } = json;
|
|
652
|
+
const wallet = typedDataAddress(message["verifyingContract"]);
|
|
653
|
+
const { contents } = message;
|
|
654
|
+
if (message["name"] !== "DepositWallet" || message["version"] !== "1" || wallet === void 0 || message["salt"] !== ZERO_BYTES32 || uint(message["chainId"]) !== BigInt(exchange.chainId) || !isTypedDataMessage(contents)) return;
|
|
655
|
+
const order = orderValues(contents);
|
|
656
|
+
if (order === void 0 || order.signatureType !== 3n || !sameAddress(order.signer, wallet) || !sameAddress(order.maker, wallet)) return;
|
|
657
|
+
const content = orderContent(order, exchange, "deposit-wallet");
|
|
658
|
+
return {
|
|
659
|
+
content: { polymarket: content },
|
|
660
|
+
summary: "swap",
|
|
661
|
+
outflows: [{
|
|
662
|
+
to: exchange.address,
|
|
663
|
+
amount: content.give,
|
|
664
|
+
verified: content.give.asset === PUSD
|
|
665
|
+
}],
|
|
666
|
+
approvals: [],
|
|
667
|
+
verifiability: "partial"
|
|
668
|
+
};
|
|
669
|
+
};
|
|
670
|
+
const clobAuthResult = (json, context) => {
|
|
671
|
+
const { types, domain, message } = json;
|
|
672
|
+
const chainId = domainChainId(domain);
|
|
673
|
+
if (json.primaryType !== "ClobAuth" || domain["name"] !== "ClobAuthDomain" || domain["version"] !== "1" || chainId !== 137 && chainId !== 80002 || !sameFields(types, "EIP712Domain", EIP712_DOMAIN_AUTH) || !typeSet(types, ["EIP712Domain", "ClobAuth"]) || !sameFields(types, "ClobAuth", CLOB_AUTH_FIELDS)) return;
|
|
674
|
+
const address = typedDataAddress(message["address"]);
|
|
675
|
+
const { timestamp } = message;
|
|
676
|
+
const nonce = uint(message["nonce"]);
|
|
677
|
+
if (address === void 0 || !sameAddress(address, context.signer) || message["message"] !== CLOB_AUTH_MESSAGE || typeof timestamp !== "string" || !/^[0-9]{1,12}$/.test(timestamp) || nonce === void 0) return;
|
|
678
|
+
return {
|
|
679
|
+
content: { polymarket: {
|
|
680
|
+
kind: "auth",
|
|
681
|
+
address,
|
|
682
|
+
timestamp: Number(timestamp),
|
|
683
|
+
nonce: nonce.toString(10)
|
|
684
|
+
} },
|
|
685
|
+
summary: "message",
|
|
686
|
+
outflows: [],
|
|
687
|
+
approvals: [],
|
|
688
|
+
verifiability: "partial"
|
|
689
|
+
};
|
|
690
|
+
};
|
|
691
|
+
const batchResult = (json, decodeCall) => {
|
|
692
|
+
const { types, domain, message } = json;
|
|
693
|
+
const chainId = domainChainId(domain);
|
|
694
|
+
const wallet = typedDataAddress(domain["verifyingContract"]);
|
|
695
|
+
if (json.primaryType !== "Batch" || domain["name"] !== "DepositWallet" || domain["version"] !== "1" || chainId !== 137 && chainId !== 80002 || wallet === void 0 || !sameFields(types, "EIP712Domain", EIP712_DOMAIN) || !typeSet(types, [
|
|
696
|
+
"EIP712Domain",
|
|
697
|
+
"Batch",
|
|
698
|
+
"Call"
|
|
699
|
+
]) || !sameFields(types, "Batch", BATCH_FIELDS) || !sameFields(types, "Call", CALL_FIELDS) || !sameAddress(typedDataAddress(message["wallet"]), wallet)) return;
|
|
700
|
+
const nonce = uint(message["nonce"]);
|
|
701
|
+
const deadline = typedDataUint(message["deadline"], MAX_UINT48);
|
|
702
|
+
const calls = typedDataMessages(message["calls"]);
|
|
703
|
+
if (nonce === void 0 || deadline === void 0 || calls === void 0 || calls.length === 0) return;
|
|
704
|
+
const batch = (decoded, blind) => ({
|
|
705
|
+
content: { polymarket: {
|
|
706
|
+
kind: "batch",
|
|
707
|
+
wallet,
|
|
708
|
+
nonce: nonce.toString(10),
|
|
709
|
+
deadline: Number(deadline),
|
|
710
|
+
calls: decoded
|
|
711
|
+
} },
|
|
712
|
+
summary: "batch",
|
|
713
|
+
outflows: decoded.flatMap((call) => call.outflows),
|
|
714
|
+
approvals: decoded.flatMap((call) => call.approvals),
|
|
715
|
+
verifiability: decoded.length === 0 || decoded.some((call) => call.verifiability === "opaque") ? "opaque" : decoded.some((call) => call.verifiability === "partial") ? "partial" : "full",
|
|
716
|
+
...blind === void 0 ? {} : { blind }
|
|
717
|
+
});
|
|
718
|
+
if (calls.length > BATCH_CALLS_MAX) return batch([], "typed-data-oversize");
|
|
719
|
+
const decoded = [];
|
|
720
|
+
for (const call of calls) {
|
|
721
|
+
const target = typedDataAddress(call["target"]);
|
|
722
|
+
const value = uint(call["value"]);
|
|
723
|
+
const data = typedDataBytes(call["data"]);
|
|
724
|
+
if (target === void 0 || value === void 0 || data === void 0) return;
|
|
725
|
+
decoded.push(decodeCall({
|
|
726
|
+
to: target,
|
|
727
|
+
value,
|
|
728
|
+
data
|
|
729
|
+
}, wallet));
|
|
730
|
+
}
|
|
731
|
+
return batch(decoded, decoded.find((call) => call.blind !== void 0)?.blind);
|
|
732
|
+
};
|
|
733
|
+
/**
|
|
734
|
+
* The Polymarket request a typed-data document signs, or `undefined` when the document is not one
|
|
735
|
+
* of the described shapes — the family rows then make it blind `typed-data-variant`.
|
|
736
|
+
*/
|
|
737
|
+
function recognizePolymarket(json, context, decodeCall) {
|
|
738
|
+
if (json.primaryType === "ClobAuth") return clobAuthResult(json, context);
|
|
739
|
+
if (json.primaryType === "Batch") return batchResult(json, decodeCall);
|
|
740
|
+
const exchange = exchangeDomain(json);
|
|
741
|
+
if (exchange === void 0) return;
|
|
742
|
+
return json.primaryType === "TypedDataSign" ? typedDataSignResult(json, exchange) : orderResult(json, exchange, context);
|
|
743
|
+
}
|
|
744
|
+
// src/evm/apps.ts
|
|
745
|
+
const recognizeApp = (json, context, decodeCall) => {
|
|
746
|
+
const hyperliquid = recognizeHyperliquid(json);
|
|
747
|
+
if (hyperliquid !== void 0) return {
|
|
748
|
+
content: { hyperliquid: hyperliquid.action },
|
|
749
|
+
summary: hyperliquid.summary,
|
|
750
|
+
outflows: [],
|
|
751
|
+
approvals: [],
|
|
752
|
+
warnings: [],
|
|
753
|
+
verifiability: hyperliquid.verifiability
|
|
754
|
+
};
|
|
755
|
+
const polymarket = recognizePolymarket(json, context, decodeCall);
|
|
756
|
+
return polymarket === void 0 ? void 0 : {
|
|
757
|
+
content: polymarket.content,
|
|
758
|
+
summary: polymarket.summary,
|
|
759
|
+
outflows: polymarket.outflows,
|
|
760
|
+
approvals: polymarket.approvals,
|
|
761
|
+
warnings: [],
|
|
762
|
+
verifiability: polymarket.verifiability,
|
|
763
|
+
...polymarket.blind === void 0 ? {} : { blind: polymarket.blind }
|
|
764
|
+
};
|
|
765
|
+
};
|
|
766
|
+
// src/evm/authority.ts
|
|
767
|
+
/**
|
|
768
|
+
* Recognition of account-authority documents — Morpho Blue `Authorization` and Aave v3
|
|
769
|
+
* `DelegationWithSig` — typed data that hands someone else power over the signer's account.
|
|
770
|
+
*
|
|
771
|
+
* Morpho Blue (morpho-org/morpho-blue@339a885 `src/libraries/ConstantsLib.sol`:
|
|
772
|
+
* `Authorization(address authorizer,address authorized,bool isAuthorized,uint256 nonce,uint256
|
|
773
|
+
* deadline)` under `EIP712Domain(uint256 chainId,address verifyingContract)`): `Morpho.sol`'s
|
|
774
|
+
* `setAuthorizationWithSig` recovers the signatory with ecrecover and requires
|
|
775
|
+
* `authorization.authorizer == signatory`, so the decoder requires `authorizer` to be the signer;
|
|
776
|
+
* an authorized account can withdraw, borrow and withdrawCollateral on the signer's behalf with an
|
|
777
|
+
* arbitrary receiver. The document decodes on ANY verifyingContract — the `verified` flag tells the
|
|
778
|
+
* prompt whether it is a deployment of the table below.
|
|
779
|
+
*
|
|
780
|
+
* Aave v3 (aave-dao/aave-v3-origin@8305565 `DebtTokenBase.sol`: `DelegationWithSig(address
|
|
781
|
+
* delegatee,uint256 value,uint256 nonce,uint256 deadline)` under the four-field domain at version
|
|
782
|
+
* `"1"`): `delegationWithSig` recovers the delegator from the signature — the signer is the
|
|
783
|
+
* delegator by construction — and sets `_borrowAllowances[delegator][delegatee] = value`. A
|
|
784
|
+
* variable-debt token of the table below is verified and its amount displayed in the underlying
|
|
785
|
+
* asset's units; any other contract is unverified and the amount stays raw.
|
|
786
|
+
*/
|
|
787
|
+
const MORPHO_BLUE = {
|
|
788
|
+
"1": "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
|
|
789
|
+
"10": "0xce95AfbB8EA029495c66020883F87aaE8864AF92",
|
|
790
|
+
"14": "0xF4346F5132e810f80a28487a79c7559d9797E8B0",
|
|
791
|
+
"25": "0xDF9a1DC07e5dEe5ccCCaBeC35e446C70fAF7434e",
|
|
792
|
+
"56": "0x01b0Bd309AA75547f7a37Ad7B1219A898E67a83a",
|
|
793
|
+
"100": "0xB74D4dd451E250bC325AFF0556D717e4E2351c66",
|
|
794
|
+
"130": "0x8f5ae9CddB9f68de460C77730b018Ae7E04a140A",
|
|
795
|
+
"137": "0x1bF0c2541F820E775182832f06c0B7Fc27A25f67",
|
|
796
|
+
"143": "0xD5D960E8C380B724a48AC59E2DfF1b2CB4a1eAee",
|
|
797
|
+
"146": "0xd6c916eB7542D0Ad3f18AEd0FCBD50C582cfa95f",
|
|
798
|
+
"196": "0xeb00C490E888286357dC5B0a35D37D9260D11Ab5",
|
|
799
|
+
"252": "0xa6030627d724bA78a59aCf43Be7550b4C5a0653b",
|
|
800
|
+
"480": "0xE741BC7c34758b4caE05062794E8Ae24978AF432",
|
|
801
|
+
"999": "0x68e37dE8d93d3496ae143F2E900490f6280C57cD",
|
|
802
|
+
"1329": "0xc9cDAc20FCeAAF616f7EB0bb6Cd2c69dcfa9094c",
|
|
803
|
+
"1672": "0x18573fA18fd17dDfD790B4a5B5b2977aad3b4Efb",
|
|
804
|
+
"1868": "0xE75Fc5eA6e74B824954349Ca351eb4e671ADA53a",
|
|
805
|
+
"43114": "0x895383274303AA19fe978AFB4Ac55C7f094f982C",
|
|
806
|
+
"42220": "0xd24ECdD8C1e0E57a4E26B1a7bbeAa3e95466A569",
|
|
807
|
+
"4326": "0x18120312A7cf44DcfEc6dCe5632a431579ED9100",
|
|
808
|
+
"8453": "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
|
|
809
|
+
"9745": "0x2fF74A46536f5c67ef5A42FD5B4e2Ed8A2cee249",
|
|
810
|
+
"57073": "0x857f3EefE8cbda3Bc49367C996cd664A880d3042",
|
|
811
|
+
"59144": "0x6B0D716aC0A45536172308e08fC2C40387262c9F",
|
|
812
|
+
"747474": "0xD50F2DffFd62f94Ee4AEd9ca05C61d0753268aBc",
|
|
813
|
+
"534352": "0x2d012EdbAdc37eDc2BC62791B666f9193FDF5a55",
|
|
814
|
+
"84532": "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
|
|
815
|
+
"11155111": "0xd011EE229E7459ba1ddd22631eF7bF528d424A14"
|
|
816
|
+
};
|
|
817
|
+
const AAVE_DEBT_TOKENS = {
|
|
818
|
+
"1": {
|
|
819
|
+
"0xeA51d7853EEFb32b6ee06b1C12E6dcCA88Be0fFE": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
820
|
+
"0x72E95b8931767C79bA4EeE721354d6E99a61D004": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
821
|
+
"0x6df1C1E379bC5a00a7b4C6e67A203333772f45A8": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
822
|
+
"0x9355032d747f1e08F8720CD01950E652eE15cdB7": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
823
|
+
"0x4139EcBe83d78ef5EFF0A6eDA6f894Be9D590FC7": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
824
|
+
"0x91b7d78BF92db564221f6B5AeE744D1727d1Dd1e": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
825
|
+
"0xeD90dE2D824Ee766c6Fd22E90b12e598f681dc9F": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
826
|
+
},
|
|
827
|
+
"10": {
|
|
828
|
+
"0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351": "0x4200000000000000000000000000000000000006",
|
|
829
|
+
"0x5D557B07776D12967914379C71a1310e917C7555": "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85"
|
|
830
|
+
},
|
|
831
|
+
"56": { "0x0E76414d433ddfe8004d2A7505d218874875a996": "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c" },
|
|
832
|
+
"137": {
|
|
833
|
+
"0x4a1c3aD6Ed28a636ee1751C69071f6be75DEb8B8": "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
|
|
834
|
+
"0xE701126012EC0290822eEA17B794454d1AF8b030": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359"
|
|
835
|
+
},
|
|
836
|
+
"143": { "0x9F555aB84C4e0a531B50283f09Dba7A97134c4e4": "0x754704Bc059F8C67012fEd69BC8A327a5aafb603" },
|
|
837
|
+
"146": {
|
|
838
|
+
"0x2273caBAd63b7D247A6b107E723c803fc49953A0": "0x29219dd400f2Bf60E5a23d13Be72B486D4038894",
|
|
839
|
+
"0xF6089B790Fbf8F4812a79a31CFAbeB00B06BA7BD": "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38"
|
|
840
|
+
},
|
|
841
|
+
"196": { "0x585Eb919387F82bc9B2B440C4F3D8615B079465A": "0xB6CEceAB302E2E4948951eE7843FC24E92933061" },
|
|
842
|
+
"324": { "0x0049250D15A8550c5a14Baa5AF5B662a93a525B9": "0x1d17CBcF0D6D143135aE902365D2E5e2A16538D4" },
|
|
843
|
+
"4326": { "0x09ADCCC7AF2aBD356c18A4CadF2e5cC250f300E9": "0x4200000000000000000000000000000000000006" },
|
|
844
|
+
"1868": { "0xC52375A5A04C0ABe5a6Ca5F3a344be2415EF54dB": "0x4200000000000000000000000000000000000006" },
|
|
845
|
+
"8453": {
|
|
846
|
+
"0x24e6e0795b3c7c71D965fCc4f371803d1c1DcA1E": "0x4200000000000000000000000000000000000006",
|
|
847
|
+
"0x59dca05b6c26dbd64b5381374aAaC5CD05644C28": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
848
|
+
},
|
|
849
|
+
"42161": {
|
|
850
|
+
"0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
851
|
+
"0xf611aEb5013fD2c0511c9CD55c7dc5C1140741A6": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"
|
|
852
|
+
},
|
|
853
|
+
"42220": {
|
|
854
|
+
"0xDbe517c0FA6467873B684eCcbED77217E471E862": "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
|
|
855
|
+
"0xE15324a9887999803b931Ac45aa89a94A9750052": "0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e",
|
|
856
|
+
"0xaEa37B42955De2Ba2E4AF6581E46349bCD3Ea2d6": "0x471EcE3750Da237f93B8E339c536989b8978a438"
|
|
857
|
+
},
|
|
858
|
+
"43114": {
|
|
859
|
+
"0xFCCf3cAbbe80101232d343252614b6A3eE81C989": "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
860
|
+
"0xfb00AC187a8Eb5AFAE4eACE434F493Eb62672df7": "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
|
|
861
|
+
"0x4a1c3aD6Ed28a636ee1751C69071f6be75DEb8B8": "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7"
|
|
862
|
+
},
|
|
863
|
+
"57073": {
|
|
864
|
+
"0xc1457AcfBaD2332b07B7651A4Da3176E8F3Bc9E4": "0x4200000000000000000000000000000000000006",
|
|
865
|
+
"0x305c03f74DBb8C6052b7667AaBEE21dC7c1f0B29": "0x2D270e6886d130D724215A266106e6832161EAEd"
|
|
866
|
+
},
|
|
867
|
+
"59144": { "0x63aB166e6E1b6Fb705b6ca23686FaD9705EB3534": "0x176211869cA2b568f2A7D4EE941E073a821EE1ff" },
|
|
868
|
+
"534352": { "0xfD7344CeB1Df9Cf238EcD667f4A6F99c6Ef44a56": "0x5300000000000000000000000000000000000004" }
|
|
869
|
+
};
|
|
870
|
+
/** `address` is the Morpho Blue deployment of `chainId` (the `morpho-blue` family claim). */
|
|
871
|
+
const isMorphoBlue = (chainId, address) => MORPHO_BLUE[String(chainId)]?.toLowerCase() === address.toLowerCase();
|
|
872
|
+
const MORPHO_DOMAIN = ["uint256 chainId", "address verifyingContract"];
|
|
873
|
+
const MORPHO_FIELDS = [
|
|
874
|
+
"address authorizer",
|
|
875
|
+
"address authorized",
|
|
876
|
+
"bool isAuthorized",
|
|
877
|
+
"uint256 nonce",
|
|
878
|
+
"uint256 deadline"
|
|
879
|
+
];
|
|
880
|
+
const AAVE_DOMAIN = [
|
|
881
|
+
"string name",
|
|
882
|
+
"string version",
|
|
883
|
+
"uint256 chainId",
|
|
884
|
+
"address verifyingContract"
|
|
885
|
+
];
|
|
886
|
+
const AAVE_FIELDS = [
|
|
887
|
+
"address delegatee",
|
|
888
|
+
"uint256 value",
|
|
889
|
+
"uint256 nonce",
|
|
890
|
+
"uint256 deadline"
|
|
891
|
+
];
|
|
892
|
+
const parseUint$1 = (value) => typedDataUint(value, MAX_UINT256);
|
|
893
|
+
const result$1 = (authority) => ({
|
|
894
|
+
content: { authority },
|
|
895
|
+
summary: "authorization",
|
|
896
|
+
outflows: [],
|
|
897
|
+
verifiability: "partial"
|
|
42
898
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
899
|
+
/**
|
|
900
|
+
* The authority the document grants, or `undefined` when the shape is not exactly a Morpho Blue
|
|
901
|
+
* `Authorization` bound to the signer or an Aave `DelegationWithSig` on `chainId`.
|
|
902
|
+
*/
|
|
903
|
+
function recognizeAuthority(json, chainId, table, signer) {
|
|
904
|
+
const { types, primaryType, message, domain } = json;
|
|
905
|
+
if (Object.keys(types).length !== 2 || domainChainId(domain) !== chainId) return;
|
|
906
|
+
const contract = typedDataAddress(domain["verifyingContract"]);
|
|
907
|
+
if (contract === void 0) return;
|
|
908
|
+
if (primaryType === "Authorization") {
|
|
909
|
+
if (!sameFields(types, "EIP712Domain", MORPHO_DOMAIN) || !sameFields(types, "Authorization", MORPHO_FIELDS)) return;
|
|
910
|
+
const authorizer = typedDataAddress(message["authorizer"]);
|
|
911
|
+
const authorized = typedDataAddress(message["authorized"]);
|
|
912
|
+
const { isAuthorized } = message;
|
|
913
|
+
const nonce = parseUint$1(message["nonce"]);
|
|
914
|
+
const deadline = parseUint$1(message["deadline"]);
|
|
915
|
+
if (authorizer === void 0 || authorizer.toLowerCase() !== signer.toLowerCase() || authorized === void 0 || typeof isAuthorized !== "boolean" || nonce === void 0 || deadline === void 0) return;
|
|
916
|
+
return result$1({
|
|
917
|
+
kind: "morpho",
|
|
918
|
+
contract,
|
|
919
|
+
verified: isMorphoBlue(chainId, contract),
|
|
920
|
+
authorized,
|
|
921
|
+
grant: isAuthorized,
|
|
922
|
+
...deadline <= MAX_UINT48 ? { deadline: Number(deadline) } : {}
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
if (primaryType === "DelegationWithSig") {
|
|
926
|
+
if (!sameFields(types, "EIP712Domain", AAVE_DOMAIN) || !sameFields(types, "DelegationWithSig", AAVE_FIELDS) || typeof domain["name"] !== "string" || domain["version"] !== "1") return;
|
|
927
|
+
const delegatee = typedDataAddress(message["delegatee"]);
|
|
928
|
+
const value = parseUint$1(message["value"]);
|
|
929
|
+
const nonce = parseUint$1(message["nonce"]);
|
|
930
|
+
const deadline = parseUint$1(message["deadline"]);
|
|
931
|
+
if (delegatee === void 0 || value === void 0 || nonce === void 0 || deadline === void 0) return;
|
|
932
|
+
const underlying = AAVE_DEBT_TOKENS[String(chainId)]?.[contract];
|
|
933
|
+
const listed = underlying === void 0 ? void 0 : lookupEvmToken(table, chainId, underlying);
|
|
934
|
+
const amount = underlying === void 0 ? {
|
|
935
|
+
asset: contract,
|
|
936
|
+
amount: value.toString()
|
|
937
|
+
} : {
|
|
938
|
+
asset: underlying,
|
|
939
|
+
amount: value.toString(),
|
|
940
|
+
...listed === void 0 ? {} : {
|
|
941
|
+
symbol: listed.symbol,
|
|
942
|
+
decimals: listed.decimals
|
|
943
|
+
}
|
|
944
|
+
};
|
|
945
|
+
return result$1({
|
|
946
|
+
kind: "aave-credit",
|
|
947
|
+
contract,
|
|
948
|
+
verified: underlying !== void 0,
|
|
949
|
+
delegatee,
|
|
950
|
+
amount,
|
|
951
|
+
unlimited: value === MAX_UINT256,
|
|
952
|
+
...deadline <= MAX_UINT48 ? { deadline: Number(deadline) } : {}
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
// src/evm/cctp.ts
|
|
957
|
+
/**
|
|
958
|
+
* CCTP TokenMessengerV2 `depositForBurnWithHook` deposits USDC into Hyperliquid via Circle's
|
|
959
|
+
* CctpForwarder on HyperEVM (destination domain 19). Only the Hyperliquid route is described — a
|
|
960
|
+
* call to the messenger on these chains that does not match it exactly is blind
|
|
961
|
+
* (`cctp-destination`): an unrecognised hook could send the burn anywhere.
|
|
962
|
+
*
|
|
963
|
+
* Verified on chain 2026-11-21 (code present).
|
|
964
|
+
*/
|
|
965
|
+
const CCTP_MESSENGERS = {
|
|
966
|
+
42161: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
|
|
967
|
+
421614: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA"
|
|
968
|
+
};
|
|
969
|
+
const CCTP_USDC = {
|
|
970
|
+
42161: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
971
|
+
421614: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d"
|
|
972
|
+
};
|
|
973
|
+
/** Circle's CctpForwarder on HyperEVM (999 mainnet, 998 testnet) — the mint recipient on domain 19. */
|
|
974
|
+
const CCTP_FORWARDERS = {
|
|
975
|
+
42161: "0xb21D281DEdb17AE5B501F6AA8256fe38C4e45757",
|
|
976
|
+
421614: "0x02e39ECb8368b41bF68FF99ff351aC9864e5E2a2"
|
|
977
|
+
};
|
|
978
|
+
const HYPERLIQUID_DOMAIN = 19;
|
|
979
|
+
const DEPOSIT_WITH_HOOK = AbiFunction.from("function depositForBurnWithHook(uint256 amount, uint32 destinationDomain, bytes32 mintRecipient, address burnToken, bytes32 destinationCaller, uint256 maxFee, uint32 minFinalityThreshold, bytes hookData)");
|
|
980
|
+
/** `call.to` is this chain's TokenMessengerV2 — the call is CCTP territory, described or blind. */
|
|
981
|
+
const isCctpMessenger = (chainId, to) => to !== void 0 && to.toLowerCase() === CCTP_MESSENGERS[chainId]?.toLowerCase();
|
|
982
|
+
/** Strict canonical decode — unlike Across, no calldata suffix is tolerated. */
|
|
983
|
+
const tryCall$3 = (fn, data) => {
|
|
984
|
+
if (!data.toLowerCase().startsWith(AbiFunction.getSelector(fn))) return;
|
|
985
|
+
try {
|
|
986
|
+
assertHex(data, "data");
|
|
987
|
+
const args = AbiFunction.decodeData(fn, data);
|
|
988
|
+
if (!Array.isArray(args)) return;
|
|
989
|
+
return AbiFunction.encodeData(fn, args).toLowerCase() === data.toLowerCase() ? args : void 0;
|
|
990
|
+
} catch {
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
const paddedAddress = (value) => {
|
|
995
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(value)) return;
|
|
996
|
+
if (value.slice(2, 26) !== "000000000000000000000000") return;
|
|
997
|
+
return checksumEvmAddress(`0x${value.slice(26)}`);
|
|
998
|
+
};
|
|
999
|
+
const FORWARD_PREFIX_HEX = "636374702d666f7277617264";
|
|
1000
|
+
/** The 56-byte Hyperliquid forward hook: tag, zeros, version 0, length 24, recipient, dex. */
|
|
1001
|
+
const decodeHook = (value, from) => {
|
|
1002
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{112}$/.test(value)) return;
|
|
1003
|
+
const hex = value.slice(2);
|
|
1004
|
+
if (!hex.startsWith(FORWARD_PREFIX_HEX)) return;
|
|
1005
|
+
if (hex.slice(24, 48) !== "000000000000000000000000") return;
|
|
1006
|
+
if (hex.slice(48, 56) !== "00000000" || hex.slice(56, 64) !== "00000018") return;
|
|
1007
|
+
const recipient = checksumEvmAddress(`0x${hex.slice(64, 104)}`);
|
|
1008
|
+
if (recipient.toLowerCase() !== from.toLowerCase()) return;
|
|
1009
|
+
const dex = hex.slice(104, 112);
|
|
1010
|
+
if (dex !== "00000000" && dex !== "ffffffff") return;
|
|
52
1011
|
return {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1012
|
+
recipient,
|
|
1013
|
+
dex: dex === "00000000" ? "perps" : "spot"
|
|
1014
|
+
};
|
|
1015
|
+
};
|
|
1016
|
+
/**
|
|
1017
|
+
* A fully described Hyperliquid deposit: the burn is bounded by `amount` USDC to this chain's
|
|
1018
|
+
* verified TokenMessengerV2, routed to the forwarder on domain 19, and the hook commits the
|
|
1019
|
+
* depositor's own address plus a perps/spot dex and a `maxFee` strictly below the amount.
|
|
1020
|
+
*/
|
|
1021
|
+
const decodeCctp = (chainId, call, from, table) => {
|
|
1022
|
+
const messenger = CCTP_MESSENGERS[chainId];
|
|
1023
|
+
const usdc = CCTP_USDC[chainId];
|
|
1024
|
+
const forwarder = CCTP_FORWARDERS[chainId];
|
|
1025
|
+
if (messenger === void 0 || usdc === void 0 || forwarder === void 0 || !isCctpMessenger(chainId, call.to) || call.value !== 0n) return;
|
|
1026
|
+
const args = tryCall$3(DEPOSIT_WITH_HOOK, call.data);
|
|
1027
|
+
if (args === void 0) return;
|
|
1028
|
+
const [amount, domain, mintRecipient, burnToken, destinationCaller, maxFee] = args;
|
|
1029
|
+
const burn = typeof burnToken === "string" && /^0x[0-9a-fA-F]{40}$/.test(burnToken) ? checksumEvmAddress(burnToken) : void 0;
|
|
1030
|
+
if (typeof amount !== "bigint" || typeof maxFee !== "bigint" || domain !== 19 || burn === void 0 || burn.toLowerCase() !== usdc.toLowerCase() || paddedAddress(mintRecipient)?.toLowerCase() !== forwarder.toLowerCase() || paddedAddress(destinationCaller)?.toLowerCase() !== forwarder.toLowerCase() || maxFee <= 0n || maxFee >= amount) return;
|
|
1031
|
+
const hook = decodeHook(args.at(7), from);
|
|
1032
|
+
if (hook === void 0) return;
|
|
1033
|
+
const meta = table === void 0 ? void 0 : lookupEvmToken(table, chainId, usdc);
|
|
1034
|
+
const amountOf = (v) => meta === void 0 ? {
|
|
1035
|
+
asset: usdc,
|
|
1036
|
+
amount: v.toString(10)
|
|
1037
|
+
} : {
|
|
1038
|
+
asset: usdc,
|
|
1039
|
+
amount: v.toString(10),
|
|
1040
|
+
decimals: meta.decimals,
|
|
1041
|
+
symbol: meta.symbol
|
|
1042
|
+
};
|
|
1043
|
+
return {
|
|
1044
|
+
outflows: [{
|
|
1045
|
+
to: messenger,
|
|
1046
|
+
amount: amountOf(amount),
|
|
1047
|
+
verified: true
|
|
1048
|
+
}],
|
|
1049
|
+
hyperliquidDeposit: {
|
|
1050
|
+
recipient: hook.recipient,
|
|
1051
|
+
dex: hook.dex,
|
|
1052
|
+
maxFee: amountOf(maxFee)
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
};
|
|
1056
|
+
/**
|
|
1057
|
+
* The chains the settlement's `domainSeparator()` was verified on
|
|
1058
|
+
* (vectors/chains/order-protocols.json).
|
|
1059
|
+
*/
|
|
1060
|
+
const GPV2_CHAINS = /* @__PURE__ */ new Set([
|
|
1061
|
+
1,
|
|
1062
|
+
10,
|
|
1063
|
+
56,
|
|
1064
|
+
100,
|
|
1065
|
+
130,
|
|
1066
|
+
137,
|
|
1067
|
+
143,
|
|
1068
|
+
5e3,
|
|
1069
|
+
8453,
|
|
1070
|
+
9745,
|
|
1071
|
+
42161,
|
|
1072
|
+
43114,
|
|
1073
|
+
59144
|
|
1074
|
+
]);
|
|
1075
|
+
/** `Order`'s field list, verbatim from `GPv2Order.sol`'s TYPE_HASH comment. */
|
|
1076
|
+
const ORDER_FIELDS$1 = [
|
|
1077
|
+
"address sellToken",
|
|
1078
|
+
"address buyToken",
|
|
1079
|
+
"address receiver",
|
|
1080
|
+
"uint256 sellAmount",
|
|
1081
|
+
"uint256 buyAmount",
|
|
1082
|
+
"uint32 validTo",
|
|
1083
|
+
"bytes32 appData",
|
|
1084
|
+
"uint256 feeAmount",
|
|
1085
|
+
"string kind",
|
|
1086
|
+
"bool partiallyFillable",
|
|
1087
|
+
"string sellTokenBalance",
|
|
1088
|
+
"string buyTokenBalance"
|
|
1089
|
+
];
|
|
1090
|
+
const ZERO$2 = "0x0000000000000000000000000000000000000000";
|
|
1091
|
+
const BUY_ETH = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
1092
|
+
const KINDS = /* @__PURE__ */ new Set(["sell", "buy"]);
|
|
1093
|
+
const SELL_BALANCES = /* @__PURE__ */ new Set([
|
|
1094
|
+
"erc20",
|
|
1095
|
+
"external",
|
|
1096
|
+
"internal"
|
|
1097
|
+
]);
|
|
1098
|
+
const BUY_BALANCES = /* @__PURE__ */ new Set(["erc20", "internal"]);
|
|
1099
|
+
/** The order under the exact GPv2 signing domain, or `undefined` — a near miss of the claim. */
|
|
1100
|
+
const recognizeCow = (json, chainId, signer, table) => {
|
|
1101
|
+
const { domain, types, primaryType, message } = json;
|
|
1102
|
+
const verifying = typedDataAddress(domain["verifyingContract"]);
|
|
1103
|
+
if (domain["name"] !== "Gnosis Protocol" || domain["version"] !== "v2" || domainChainId(domain) !== chainId || verifying === void 0 || verifying.toLowerCase() !== "0x9008d19f58aabd9ed0d60971565aa8510560ab41" || !GPV2_CHAINS.has(chainId) || primaryType !== "Order" || Object.keys(types).length !== 2 || !sameFields(types, "EIP712Domain", [
|
|
1104
|
+
"string name",
|
|
1105
|
+
"string version",
|
|
1106
|
+
"uint256 chainId",
|
|
1107
|
+
"address verifyingContract"
|
|
1108
|
+
]) || !sameFields(types, "Order", ORDER_FIELDS$1) || typeof message["kind"] !== "string" || !KINDS.has(message["kind"]) || typeof message["sellTokenBalance"] !== "string" || !SELL_BALANCES.has(message["sellTokenBalance"]) || typeof message["buyTokenBalance"] !== "string" || !BUY_BALANCES.has(message["buyTokenBalance"]) || typeof message["partiallyFillable"] !== "boolean") return;
|
|
1109
|
+
const sellToken = typedDataAddress(message["sellToken"]);
|
|
1110
|
+
const buyToken = typedDataAddress(message["buyToken"]);
|
|
1111
|
+
const receiver = typedDataAddress(message["receiver"]);
|
|
1112
|
+
const sellAmount = typedDataUint(message["sellAmount"], MAX_UINT256);
|
|
1113
|
+
const buyAmount = typedDataUint(message["buyAmount"], MAX_UINT256);
|
|
1114
|
+
const feeAmount = typedDataUint(message["feeAmount"], MAX_UINT256);
|
|
1115
|
+
const validTo = typedDataUint(message["validTo"], 2n ** 32n - 1n);
|
|
1116
|
+
if (sellToken === void 0 || buyToken === void 0 || sellToken.toLowerCase() === ZERO$2 || sellToken.toLowerCase() === BUY_ETH || buyToken.toLowerCase() === ZERO$2 || receiver === void 0 || sellAmount === void 0 || buyAmount === void 0 || feeAmount === void 0 || validTo === void 0 || sellAmount + feeAmount > MAX_UINT256) return;
|
|
1117
|
+
return {
|
|
1118
|
+
protocol: "cow",
|
|
1119
|
+
maker: checksumEvmAddress(signer),
|
|
1120
|
+
give: orderAmount(sellToken, sellAmount + feeAmount, chainId, table),
|
|
1121
|
+
receive: [{
|
|
1122
|
+
recipient: receiver.toLowerCase() === ZERO$2 ? checksumEvmAddress(signer) : receiver,
|
|
1123
|
+
amount: orderAmount(buyToken, buyAmount, chainId, table, BUY_ETH)
|
|
1124
|
+
}],
|
|
1125
|
+
expiry: Number(validTo),
|
|
1126
|
+
partialFill: message["partiallyFillable"]
|
|
1127
|
+
};
|
|
1128
|
+
};
|
|
1129
|
+
// src/evm/eip3009.ts
|
|
1130
|
+
/**
|
|
1131
|
+
* Recognition of EIP-3009 authorizations — `TransferWithAuthorization`, `ReceiveWithAuthorization`
|
|
1132
|
+
* and `CancelAuthorization` as emitted by FiatToken (circlefin/stablecoin-evm@fc85788
|
|
1133
|
+
* `contracts/v2/EIP3009.sol`: the three TYPEHASH field lists).
|
|
1134
|
+
*
|
|
1135
|
+
* Binding rules beyond the field list: `types` is exactly `EIP712Domain` plus the one primary type,
|
|
1136
|
+
* the domain carries a `verifyingContract` (the token itself) and a `chainId` equal to the request
|
|
1137
|
+
* network's, and `from`/`authorizer` is the signer — FiatToken v2.2 checks the authorization with
|
|
1138
|
+
* `SignatureChecker.isValidSignatureNow(from, …)`, so a `from` that is an ERC-1271 contract wallet
|
|
1139
|
+
* could spend that contract's funds on this EOA's signature; anything else is a near miss
|
|
1140
|
+
* (`typed-data-variant`).
|
|
1141
|
+
*
|
|
1142
|
+
* `nonce` is a bytes32 one-time id the family owns — not a commitment, and not shown (the ERC-7730
|
|
1143
|
+
* registry descriptor marks it `visible: never`) except on `CancelAuthorization`, where it names
|
|
1144
|
+
* the authorization being cancelled.
|
|
1145
|
+
*/
|
|
1146
|
+
const TRANSFER_FIELDS = [
|
|
1147
|
+
"address from",
|
|
1148
|
+
"address to",
|
|
1149
|
+
"uint256 value",
|
|
1150
|
+
"uint256 validAfter",
|
|
1151
|
+
"uint256 validBefore",
|
|
1152
|
+
"bytes32 nonce"
|
|
1153
|
+
];
|
|
1154
|
+
const CANCEL_FIELDS = ["address authorizer", "bytes32 nonce"];
|
|
1155
|
+
const MAX_UINT48_SECONDS = 2n ** 48n;
|
|
1156
|
+
/**
|
|
1157
|
+
* The authorization the document grants, or `undefined` when the shape is not exactly one of the
|
|
1158
|
+
* FiatToken EIP-3009 primary types bound to the signer on `chainId`.
|
|
1159
|
+
*/
|
|
1160
|
+
function recognizeEip3009(json, chainId, table, signer) {
|
|
1161
|
+
const { types, primaryType, message, domain } = json;
|
|
1162
|
+
if (Object.keys(types).length !== 2 || domainChainId(domain) !== chainId) return;
|
|
1163
|
+
const token = typedDataAddress(domain["verifyingContract"]);
|
|
1164
|
+
if (token === void 0) return;
|
|
1165
|
+
const listed = lookupEvmToken(table, chainId, token);
|
|
1166
|
+
const amount = (value) => listed === void 0 ? {
|
|
1167
|
+
asset: token,
|
|
1168
|
+
amount: value.toString()
|
|
1169
|
+
} : {
|
|
1170
|
+
asset: token,
|
|
1171
|
+
amount: value.toString(),
|
|
1172
|
+
symbol: listed.symbol,
|
|
1173
|
+
decimals: listed.decimals
|
|
1174
|
+
};
|
|
1175
|
+
const isSigner = (candidate) => candidate !== void 0 && candidate.toLowerCase() === signer.toLowerCase();
|
|
1176
|
+
if (primaryType === "TransferWithAuthorization" || primaryType === "ReceiveWithAuthorization") {
|
|
1177
|
+
if (!sameFields(types, primaryType, TRANSFER_FIELDS)) return;
|
|
1178
|
+
const from = typedDataAddress(message["from"]);
|
|
1179
|
+
const to = typedDataAddress(message["to"]);
|
|
1180
|
+
const value = typedDataUint(message["value"], MAX_UINT256);
|
|
1181
|
+
const validAfter = typedDataUint(message["validAfter"], MAX_UINT256);
|
|
1182
|
+
const validBefore = typedDataUint(message["validBefore"], MAX_UINT256);
|
|
1183
|
+
const nonce = typedDataBytes(message["nonce"]);
|
|
1184
|
+
if (!isSigner(from) || to === void 0 || value === void 0 || validAfter === void 0 || validAfter >= MAX_UINT48_SECONDS || validBefore === void 0 || nonce === void 0 || nonce.length !== 66) return;
|
|
1185
|
+
return {
|
|
1186
|
+
content: { authorization: {
|
|
1187
|
+
kind: primaryType === "TransferWithAuthorization" ? "transfer" : "receive",
|
|
1188
|
+
to,
|
|
1189
|
+
amount: amount(value),
|
|
1190
|
+
validAfter: Number(validAfter),
|
|
1191
|
+
...validBefore < MAX_UINT48_SECONDS ? { validBefore: Number(validBefore) } : {}
|
|
1192
|
+
} },
|
|
1193
|
+
summary: "transfer",
|
|
1194
|
+
outflows: [{
|
|
1195
|
+
to,
|
|
1196
|
+
amount: amount(value),
|
|
1197
|
+
verified: listed !== void 0
|
|
1198
|
+
}],
|
|
1199
|
+
verifiability: listed === void 0 ? "partial" : "full"
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
if (primaryType === "CancelAuthorization") {
|
|
1203
|
+
if (!sameFields(types, primaryType, CANCEL_FIELDS)) return;
|
|
1204
|
+
const authorizer = typedDataAddress(message["authorizer"]);
|
|
1205
|
+
const nonce = typedDataBytes(message["nonce"]);
|
|
1206
|
+
if (!isSigner(authorizer) || nonce === void 0 || nonce.length !== 66) return;
|
|
1207
|
+
return {
|
|
1208
|
+
content: { authorization: {
|
|
1209
|
+
kind: "cancel",
|
|
1210
|
+
token,
|
|
1211
|
+
nonce: nonce.toLowerCase()
|
|
1212
|
+
} },
|
|
1213
|
+
summary: "message",
|
|
1214
|
+
outflows: [],
|
|
1215
|
+
verifiability: "full"
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
// src/evm/seaport.ts
|
|
1220
|
+
/** Seaport 1.5 and 1.6 deployments, lowercase for a checksum-insensitive compare. */
|
|
1221
|
+
const SEAPORT_CONTRACTS = /* @__PURE__ */ new Set(["0x0000000000000068f116a894984e2db1123eb395", "0x00000000000000adc04c56bf30ac9d3c0aaf14dc"]);
|
|
1222
|
+
/** Seaport `itemType` values 0–5; an item type outside the list is not recognized. */
|
|
1223
|
+
const ITEM_KINDS = [
|
|
1224
|
+
"native",
|
|
1225
|
+
"erc20",
|
|
1226
|
+
"erc721",
|
|
1227
|
+
"erc1155",
|
|
1228
|
+
"erc721-criteria",
|
|
1229
|
+
"erc1155-criteria"
|
|
1230
|
+
];
|
|
1231
|
+
const ITEM_FIELDS = [
|
|
1232
|
+
"uint8 itemType",
|
|
1233
|
+
"address token",
|
|
1234
|
+
"uint256 identifierOrCriteria",
|
|
1235
|
+
"uint256 startAmount",
|
|
1236
|
+
"uint256 endAmount"
|
|
1237
|
+
];
|
|
1238
|
+
const typesMatch = (types) => Object.keys(types).filter((name) => name !== "EIP712Domain").length === 3 && sameFields(types, "OrderComponents", [
|
|
1239
|
+
"address offerer",
|
|
1240
|
+
"address zone",
|
|
1241
|
+
"OfferItem[] offer",
|
|
1242
|
+
"ConsiderationItem[] consideration",
|
|
1243
|
+
"uint8 orderType",
|
|
1244
|
+
"uint256 startTime",
|
|
1245
|
+
"uint256 endTime",
|
|
1246
|
+
"bytes32 zoneHash",
|
|
1247
|
+
"uint256 salt",
|
|
1248
|
+
"bytes32 conduitKey",
|
|
1249
|
+
"uint256 counter"
|
|
1250
|
+
]) && sameFields(types, "OfferItem", ITEM_FIELDS) && sameFields(types, "ConsiderationItem", [...ITEM_FIELDS, "address recipient"]);
|
|
1251
|
+
const amount = (kind, token, value, identifier, chainId, table) => {
|
|
1252
|
+
if (kind === "native") return {
|
|
1253
|
+
asset: EVM_NATIVE_ASSET,
|
|
1254
|
+
amount: value.toString(10)
|
|
1255
|
+
};
|
|
1256
|
+
if (kind === "erc20") {
|
|
1257
|
+
const found = lookupEvmToken(table, chainId, token);
|
|
1258
|
+
return {
|
|
56
1259
|
asset: token,
|
|
57
1260
|
amount: value.toString(10),
|
|
58
|
-
...
|
|
59
|
-
symbol:
|
|
60
|
-
decimals:
|
|
1261
|
+
...found === void 0 ? {} : {
|
|
1262
|
+
symbol: found.symbol,
|
|
1263
|
+
decimals: found.decimals
|
|
61
1264
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
if (kind === "erc721" || kind === "erc1155") return {
|
|
1268
|
+
asset: token,
|
|
1269
|
+
amount: value.toString(10),
|
|
1270
|
+
tokenId: identifier.toString(10)
|
|
1271
|
+
};
|
|
1272
|
+
return {
|
|
1273
|
+
asset: token,
|
|
1274
|
+
amount: value.toString(10)
|
|
67
1275
|
};
|
|
68
1276
|
};
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
1277
|
+
const item = (message, chainId, table) => {
|
|
1278
|
+
const itemType = typedDataUint(message["itemType"], 255n);
|
|
1279
|
+
const token = typedDataAddress(message["token"]);
|
|
1280
|
+
const identifier = typedDataUint(message["identifierOrCriteria"], MAX_UINT256);
|
|
1281
|
+
const start = typedDataUint(message["startAmount"], MAX_UINT256);
|
|
1282
|
+
const end = typedDataUint(message["endAmount"], MAX_UINT256);
|
|
1283
|
+
const kind = itemType === void 0 ? void 0 : ITEM_KINDS[Number(itemType)];
|
|
1284
|
+
if (token === void 0 || identifier === void 0 || start === void 0 || end === void 0 || kind === void 0) return;
|
|
1285
|
+
return {
|
|
1286
|
+
kind,
|
|
1287
|
+
token,
|
|
1288
|
+
identifier: identifier.toString(10),
|
|
1289
|
+
startAmount: amount(kind, token, start, identifier, chainId, table),
|
|
1290
|
+
endAmount: amount(kind, token, end, identifier, chainId, table)
|
|
1291
|
+
};
|
|
1292
|
+
};
|
|
1293
|
+
const all = (list, build) => {
|
|
1294
|
+
const built = list?.map(build);
|
|
1295
|
+
return built === void 0 || built.some((entry) => entry === void 0) ? void 0 : built.filter((entry) => entry !== void 0);
|
|
1296
|
+
};
|
|
89
1297
|
/**
|
|
90
|
-
* The
|
|
91
|
-
* recognized
|
|
1298
|
+
* The Seaport order a typed-data document signs, or `undefined` when its shape is not exactly the
|
|
1299
|
+
* recognized one. `chainId` is the request network's, used for the built-in token table.
|
|
92
1300
|
*/
|
|
93
|
-
function
|
|
1301
|
+
function recognizeSeaport(json, chainId, table) {
|
|
94
1302
|
const { types, primaryType, message, domain } = json;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
1303
|
+
if (primaryType !== "OrderComponents" || !typesMatch(types)) return;
|
|
1304
|
+
const verifying = typedDataAddress(domain["verifyingContract"]);
|
|
1305
|
+
if (domain["name"] !== "Seaport" || verifying === void 0 || !SEAPORT_CONTRACTS.has(verifying.toLowerCase())) return;
|
|
1306
|
+
const offerer = typedDataAddress(message["offerer"]);
|
|
1307
|
+
const zone = typedDataAddress(message["zone"]);
|
|
1308
|
+
const startTime = typedDataUint(message["startTime"], MAX_UINT256);
|
|
1309
|
+
const endTime = typedDataUint(message["endTime"], MAX_UINT256);
|
|
1310
|
+
const offer = all(typedDataMessages(message["offer"]), (entry) => item(entry, chainId, table));
|
|
1311
|
+
const consideration = all(typedDataMessages(message["consideration"]), (entry) => {
|
|
1312
|
+
const base = item(entry, chainId, table);
|
|
1313
|
+
const recipient = typedDataAddress(entry["recipient"]);
|
|
1314
|
+
return base === void 0 || recipient === void 0 ? void 0 : {
|
|
1315
|
+
...base,
|
|
1316
|
+
recipient
|
|
1317
|
+
};
|
|
1318
|
+
});
|
|
1319
|
+
if (offerer === void 0 || zone === void 0 || startTime === void 0 || endTime === void 0 || offer === void 0 || consideration === void 0) return;
|
|
1320
|
+
return {
|
|
1321
|
+
offerer,
|
|
1322
|
+
zone,
|
|
1323
|
+
startTime: startTime <= MAX_UINT48 ? Number(startTime) : void 0,
|
|
1324
|
+
endTime: endTime <= MAX_UINT48 ? Number(endTime) : void 0,
|
|
1325
|
+
offer,
|
|
1326
|
+
consideration
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
// src/evm/families.ts
|
|
1330
|
+
/**
|
|
1331
|
+
* The EVM interpreters of the family-claim table (src/families.ts): a request a decoded family
|
|
1332
|
+
* claims but which the decoder did not decode is blind with the row's reason.
|
|
1333
|
+
*/
|
|
1334
|
+
/**
|
|
1335
|
+
* The claim an undecoded call into `to` makes on `chainId`: the Fiat24 row's callee is a pinned
|
|
1336
|
+
* contract or a Fiat24-specific selector in `data`; a listed token's claim is the token table.
|
|
1337
|
+
*/
|
|
1338
|
+
const callNearMiss = (to, chainId, table, data) => RECOGNISED_FAMILIES.find((row) => {
|
|
1339
|
+
if (row.claim.surface !== "evm.call") return false;
|
|
1340
|
+
return row.claim.callee === "fiat24" ? isFiat24Contract(chainId, to) || hasFiat24Selector(data) : lookupEvmToken(table, chainId, to) !== void 0;
|
|
1341
|
+
})?.nearMiss;
|
|
1342
|
+
/**
|
|
1343
|
+
* The claim a personal message's text makes: an exact, case-sensitive leading sentence of a
|
|
1344
|
+
* family's grant message. A grant-shaped text claims the family even though the wallet builds
|
|
1345
|
+
* grants only through its own structured request.
|
|
1346
|
+
*/
|
|
1347
|
+
const personalMessageNearMiss = (text) => RECOGNISED_FAMILIES.find((row) => row.claim.surface === "evm.personal-message" && row.claim.prefixes.some((prefix) => text.startsWith(prefix)))?.nearMiss;
|
|
1348
|
+
/**
|
|
1349
|
+
* The claim an unrecognised typed-data document makes: a family primary type, or a verifying
|
|
1350
|
+
* contract of Permit2, a canonical Seaport deployment or a listed token (case-insensitive).
|
|
1351
|
+
*/
|
|
1352
|
+
const typedDataNearMiss = (json, chainId, table) => {
|
|
1353
|
+
const verifying = typedDataAddress(json.domain["verifyingContract"]);
|
|
1354
|
+
return RECOGNISED_FAMILIES.find((row) => {
|
|
1355
|
+
const { claim } = row;
|
|
1356
|
+
if (claim.surface !== "evm.typed-data") return false;
|
|
1357
|
+
if ("contracts" in claim) {
|
|
1358
|
+
const contract = verifying?.toLowerCase();
|
|
1359
|
+
return json.domain["name"] === claim.domainName || contract !== void 0 && claim.contracts.some((address) => address.toLowerCase() === contract);
|
|
110
1360
|
}
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
1361
|
+
if ("domainName" in claim) return json.domain["name"] === claim.domainName && (claim.primaryType === void 0 || claim.primaryType.test(json.primaryType));
|
|
1362
|
+
if ("primaryType" in claim) return claim.primaryType.test(json.primaryType);
|
|
1363
|
+
if (verifying === void 0) return false;
|
|
1364
|
+
const contract = verifying.toLowerCase();
|
|
1365
|
+
return claim.verifyingContract === "permit2" && contract === "0x000000000022D473030F116dDEE9F6B43aC78BA3".toLowerCase() || claim.verifyingContract === "seaport" && SEAPORT_CONTRACTS.has(contract) || claim.verifyingContract === "morpho-blue" && isMorphoBlue(chainId, contract) || claim.verifyingContract === "token-table" && lookupEvmToken(table, chainId, verifying) !== void 0;
|
|
1366
|
+
})?.nearMiss;
|
|
1367
|
+
};
|
|
1368
|
+
const FARCASTER_CHAIN_ID = 10;
|
|
1369
|
+
const DOMAIN_FIELDS$1 = [
|
|
1370
|
+
"string name",
|
|
1371
|
+
"string version",
|
|
1372
|
+
"uint256 chainId",
|
|
1373
|
+
"address verifyingContract"
|
|
1374
|
+
];
|
|
1375
|
+
const ADD_FIELDS = [
|
|
1376
|
+
"address owner",
|
|
1377
|
+
"uint32 keyType",
|
|
1378
|
+
"bytes key",
|
|
1379
|
+
"uint8 metadataType",
|
|
1380
|
+
"bytes metadata",
|
|
1381
|
+
"uint256 nonce",
|
|
1382
|
+
"uint256 deadline"
|
|
1383
|
+
];
|
|
1384
|
+
const REQUEST_FIELDS = [
|
|
1385
|
+
"uint256 requestFid",
|
|
1386
|
+
"bytes key",
|
|
1387
|
+
"uint256 deadline"
|
|
1388
|
+
];
|
|
1389
|
+
const KEY_METADATA = [{
|
|
1390
|
+
type: "tuple",
|
|
1391
|
+
components: [
|
|
1392
|
+
{
|
|
1393
|
+
name: "requestFid",
|
|
1394
|
+
type: "uint256"
|
|
1395
|
+
},
|
|
1396
|
+
{
|
|
1397
|
+
name: "requestSigner",
|
|
1398
|
+
type: "address"
|
|
1399
|
+
},
|
|
1400
|
+
{
|
|
1401
|
+
name: "signature",
|
|
1402
|
+
type: "bytes"
|
|
1403
|
+
},
|
|
1404
|
+
{
|
|
1405
|
+
name: "deadline",
|
|
1406
|
+
type: "uint256"
|
|
120
1407
|
}
|
|
1408
|
+
]
|
|
1409
|
+
}];
|
|
1410
|
+
const isUint = (value, max, expected) => typedDataUint(value, max) === expected;
|
|
1411
|
+
const parseUint = (value) => typedDataUint(value, 2n ** 256n - 1n);
|
|
1412
|
+
const isKey = (value) => {
|
|
1413
|
+
const bytes = typedDataBytes(value);
|
|
1414
|
+
return bytes !== void 0 && Hex.size(bytes) === 32;
|
|
1415
|
+
};
|
|
1416
|
+
const isKeyMetadata = (value) => typeof value === "object" && value !== null && "requestFid" in value && typeof value.requestFid === "bigint" && "requestSigner" in value && typedDataAddress(value.requestSigner) !== void 0 && "signature" in value && typedDataBytes(value.signature) !== void 0 && "deadline" in value && typeof value.deadline === "bigint";
|
|
1417
|
+
const decodeKeyMetadata = (bytes) => {
|
|
1418
|
+
try {
|
|
1419
|
+
const decoded = AbiParameters.decode(KEY_METADATA, bytes);
|
|
1420
|
+
const tuple = Array.isArray(decoded) ? decoded[0] : void 0;
|
|
1421
|
+
if (!isKeyMetadata(tuple) || AbiParameters.encode(KEY_METADATA, [tuple]).toLowerCase() !== bytes.toLowerCase()) return;
|
|
1422
|
+
return tuple;
|
|
1423
|
+
} catch {
|
|
121
1424
|
return;
|
|
122
1425
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
1426
|
+
};
|
|
1427
|
+
const result = (farcaster, summary) => ({
|
|
1428
|
+
content: { farcaster },
|
|
1429
|
+
summary,
|
|
1430
|
+
outflows: [],
|
|
1431
|
+
verifiability: "partial"
|
|
1432
|
+
});
|
|
1433
|
+
/**
|
|
1434
|
+
* The Farcaster signer-key document, or `undefined` when the shape is not exactly a KeyGateway
|
|
1435
|
+
* `Add` bound to the signer or a `SignedKeyRequest` — on the OP Mainnet deployment.
|
|
1436
|
+
*/
|
|
1437
|
+
const recognizeFarcaster = (json, chainId, signer) => {
|
|
1438
|
+
const { types, primaryType, domain, message } = json;
|
|
1439
|
+
if (chainId !== FARCASTER_CHAIN_ID || domainChainId(domain) !== chainId || domain["version"] !== "1" || Object.keys(domain).length !== 4 || Object.keys(types).length !== 2 || !sameFields(types, "EIP712Domain", DOMAIN_FIELDS$1)) return;
|
|
1440
|
+
const contract = typedDataAddress(domain["verifyingContract"]);
|
|
1441
|
+
if (contract === void 0) return;
|
|
1442
|
+
if (primaryType === "Add" && domain["name"] === "Farcaster KeyGateway" && contract === "0x00000000fC56947c7E7183f8Ca4B62398CaAdf0B") {
|
|
1443
|
+
if (!sameFields(types, "Add", ADD_FIELDS)) return;
|
|
1444
|
+
const owner = typedDataAddress(message["owner"]);
|
|
1445
|
+
const { key } = message;
|
|
1446
|
+
const metadata = typedDataBytes(message["metadata"]);
|
|
1447
|
+
const nonce = parseUint(message["nonce"]);
|
|
1448
|
+
const deadline = parseUint(message["deadline"]);
|
|
1449
|
+
if (owner === void 0 || owner.toLowerCase() !== signer.toLowerCase() || !isUint(message["keyType"], 2n ** 32n - 1n, 1n) || !isKey(key) || !isUint(message["metadataType"], 2n ** 8n - 1n, 1n) || metadata === void 0 || nonce === void 0 || deadline === void 0) return;
|
|
1450
|
+
const app = decodeKeyMetadata(metadata);
|
|
1451
|
+
if (app === void 0) return;
|
|
1452
|
+
return result({
|
|
1453
|
+
kind: "add",
|
|
1454
|
+
key,
|
|
1455
|
+
requestFid: app.requestFid.toString(),
|
|
1456
|
+
...deadline <= MAX_UINT48 ? { deadline: Number(deadline) } : {}
|
|
1457
|
+
}, "authorization");
|
|
1458
|
+
}
|
|
1459
|
+
if (primaryType === "SignedKeyRequest" && domain["name"] === "Farcaster SignedKeyRequestValidator" && contract === "0x00000000FC700472606ED4fA22623Acf62c60553") {
|
|
1460
|
+
if (!sameFields(types, "SignedKeyRequest", REQUEST_FIELDS)) return;
|
|
1461
|
+
const requestFid = parseUint(message["requestFid"]);
|
|
1462
|
+
const { key } = message;
|
|
1463
|
+
const deadline = parseUint(message["deadline"]);
|
|
1464
|
+
if (requestFid === void 0 || !isKey(key) || deadline === void 0) return;
|
|
1465
|
+
return result({
|
|
1466
|
+
kind: "request",
|
|
1467
|
+
key,
|
|
1468
|
+
requestFid: requestFid.toString(),
|
|
1469
|
+
...deadline <= MAX_UINT48 ? { deadline: Number(deadline) } : {}
|
|
1470
|
+
}, "message");
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
// src/evm/grants.ts
|
|
1474
|
+
/** MetaMask Delegation Framework v1.3.0 DelegationManager — the same address on every chain. */
|
|
1475
|
+
const DELEGATION_MANAGER = "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3";
|
|
1476
|
+
/** ERC-4337 EntryPoint v0.8 — the same address on every chain. */
|
|
1477
|
+
const ENTRY_POINT_V08 = "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108";
|
|
1478
|
+
/**
|
|
1479
|
+
* Typed data whose domain targets an execution context over the signer's account turns a signature
|
|
1480
|
+
* into execution rights: a Delegation the DelegationManager redeems, a PackedUserOperation the
|
|
1481
|
+
* EntryPoint runs for a delegated 7702 account, or an action the account's own EIP-712 domain
|
|
1482
|
+
* authorizes. A generic typed-data request must never produce such a signature.
|
|
1483
|
+
*/
|
|
1484
|
+
const assertNoExecutionGrant = (domain, signer) => {
|
|
1485
|
+
const target = domain["verifyingContract"];
|
|
1486
|
+
if (typeof target !== "string" || !isEvmAddress(target)) return;
|
|
1487
|
+
const lower = target.toLowerCase();
|
|
1488
|
+
if (lower === signer.toLowerCase()) throw new ChainError("invalid-request", "typed data addressed to your own account is refused");
|
|
1489
|
+
if (lower === "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3".toLowerCase()) throw new ChainError("invalid-request", "typed data addressed to the DelegationManager is refused");
|
|
1490
|
+
if (lower === "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108".toLowerCase()) throw new ChainError("invalid-request", "typed data addressed to the EntryPoint is refused");
|
|
1491
|
+
};
|
|
1492
|
+
// src/evm/lido.ts
|
|
1493
|
+
/** The Lido contracts the kernel recognises by address — Ethereum mainnet only. */
|
|
1494
|
+
const LIDO_CHAIN = 1;
|
|
1495
|
+
const LIDO_STETH = "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84";
|
|
1496
|
+
const LIDO_WSTETH = "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0";
|
|
1497
|
+
const LIDO_QUEUE = "0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1";
|
|
1498
|
+
const SUBMIT = AbiFunction.from("function submit(address referral) payable");
|
|
1499
|
+
const REQUEST = AbiFunction.from("function requestWithdrawals(uint256[] amounts, address owner)");
|
|
1500
|
+
const REQUEST_WSTETH = AbiFunction.from("function requestWithdrawalsWstETH(uint256[] amounts, address owner)");
|
|
1501
|
+
const REQUEST_PERMIT = AbiFunction.from("function requestWithdrawalsWithPermit(uint256[] amounts, address owner, (uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) permit)");
|
|
1502
|
+
const REQUEST_WSTETH_PERMIT = AbiFunction.from("function requestWithdrawalsWstETHWithPermit(uint256[] amounts, address owner, (uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) permit)");
|
|
1503
|
+
const CLAIM = AbiFunction.from("function claimWithdrawals(uint256[] requestIds, uint256[] hints)");
|
|
1504
|
+
const ZERO$1 = "0x0000000000000000000000000000000000000000";
|
|
1505
|
+
/** Canonical-encoding decode like `tryCall` in decode.ts — undefined on any mismatch. */
|
|
1506
|
+
const tryCall$2 = (fn, data) => {
|
|
1507
|
+
const selector = AbiFunction.getSelector(fn);
|
|
1508
|
+
if (!data.toLowerCase().startsWith(selector)) return;
|
|
1509
|
+
try {
|
|
1510
|
+
assertHex(data, "data");
|
|
1511
|
+
const args = AbiFunction.decodeData(fn, data);
|
|
1512
|
+
if (!Array.isArray(args)) return;
|
|
1513
|
+
return AbiFunction.encodeData(fn, args).toLowerCase() === data.toLowerCase() ? args : void 0;
|
|
1514
|
+
} catch {
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
const argAddress$1 = (args, index) => {
|
|
1519
|
+
const value = args[index];
|
|
1520
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(value)) throw new ChainError("invalid-request", "decoded argument is not an address");
|
|
1521
|
+
return checksumEvmAddress(value);
|
|
1522
|
+
};
|
|
1523
|
+
const argList$1 = (args, index) => {
|
|
1524
|
+
const value = args[index];
|
|
1525
|
+
if (!Array.isArray(value) || !value.every((v) => typeof v === "bigint")) throw new ChainError("invalid-request", "decoded argument is not a uint256 array");
|
|
1526
|
+
return value;
|
|
1527
|
+
};
|
|
1528
|
+
const tokenAmount = (token, amount, table) => {
|
|
1529
|
+
const known = lookupEvmToken(table, 1, token);
|
|
1530
|
+
return {
|
|
1531
|
+
asset: token,
|
|
1532
|
+
amount: amount.toString(10),
|
|
1533
|
+
...known === void 0 ? {} : {
|
|
1534
|
+
symbol: known.symbol,
|
|
1535
|
+
decimals: known.decimals
|
|
1536
|
+
}
|
|
144
1537
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
1538
|
+
};
|
|
1539
|
+
const tokenFlow = (token, to, amount, table) => ({
|
|
1540
|
+
to,
|
|
1541
|
+
amount: tokenAmount(token, amount, table),
|
|
1542
|
+
verified: lookupEvmToken(table, 1, token) !== void 0
|
|
1543
|
+
});
|
|
1544
|
+
/**
|
|
1545
|
+
* Lido staking on Ethereum mainnet: `submit` to stETH, the four withdrawal-request forms and
|
|
1546
|
+
* `claimWithdrawals` on the queue. The minted stETH shares and the checkpointed claim amounts
|
|
1547
|
+
* cannot be read exactly from calldata, so every recognised call is verifiability-partial. `caller`
|
|
1548
|
+
* is the account the call runs as — msg.sender at the queue (the signer for a transaction, the Safe
|
|
1549
|
+
* or deposit wallet for an inner call); a zero owner resolves to it.
|
|
1550
|
+
*/
|
|
1551
|
+
const decodeLido = (chainId, call, caller, table) => {
|
|
1552
|
+
if (chainId !== 1 || call.to === void 0) return;
|
|
1553
|
+
const to = call.to.toLowerCase();
|
|
1554
|
+
if (to === "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84".toLowerCase() && call.value > 0n) {
|
|
1555
|
+
if (tryCall$2(SUBMIT, call.data) !== void 0) return {
|
|
1556
|
+
outflows: [{
|
|
1557
|
+
to: LIDO_STETH,
|
|
1558
|
+
amount: {
|
|
1559
|
+
asset: EVM_NATIVE_ASSET,
|
|
1560
|
+
amount: call.value.toString(10)
|
|
1561
|
+
},
|
|
1562
|
+
verified: true
|
|
1563
|
+
}],
|
|
1564
|
+
staking: [{
|
|
1565
|
+
kind: "lido-submit",
|
|
1566
|
+
amount: {
|
|
1567
|
+
asset: EVM_NATIVE_ASSET,
|
|
1568
|
+
amount: call.value.toString(10)
|
|
1569
|
+
},
|
|
1570
|
+
receive: tokenAmount(LIDO_STETH, call.value, table)
|
|
1571
|
+
}]
|
|
1572
|
+
};
|
|
1573
|
+
return;
|
|
1574
|
+
}
|
|
1575
|
+
if (to !== "0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1".toLowerCase()) return;
|
|
1576
|
+
for (const [fn, token] of [
|
|
1577
|
+
[REQUEST, LIDO_STETH],
|
|
1578
|
+
[REQUEST_WSTETH, LIDO_WSTETH],
|
|
1579
|
+
[REQUEST_PERMIT, LIDO_STETH],
|
|
1580
|
+
[REQUEST_WSTETH_PERMIT, LIDO_WSTETH]
|
|
1581
|
+
]) {
|
|
1582
|
+
const args = tryCall$2(fn, call.data);
|
|
1583
|
+
if (args === void 0) continue;
|
|
1584
|
+
const total = argList$1(args, 0).reduce((sum, amount) => sum + amount, 0n);
|
|
1585
|
+
const raw = argAddress$1(args, 1);
|
|
1586
|
+
const owner = raw === ZERO$1 ? caller : raw;
|
|
1587
|
+
const action = {
|
|
1588
|
+
kind: "lido-request",
|
|
1589
|
+
token,
|
|
1590
|
+
amount: tokenAmount(token, total, table),
|
|
1591
|
+
owner
|
|
1592
|
+
};
|
|
1593
|
+
return {
|
|
1594
|
+
outflows: owner.toLowerCase() === caller.toLowerCase() ? [] : [tokenFlow(token, owner, total, table)],
|
|
1595
|
+
staking: [action]
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
const claimArgs = tryCall$2(CLAIM, call.data);
|
|
1599
|
+
if (claimArgs !== void 0) {
|
|
1600
|
+
const requestIds = argList$1(claimArgs, 0).map((id) => id.toString(10));
|
|
1601
|
+
argList$1(claimArgs, 1);
|
|
1602
|
+
return {
|
|
1603
|
+
outflows: [],
|
|
1604
|
+
staking: [{
|
|
1605
|
+
kind: "lido-claim",
|
|
1606
|
+
requestIds
|
|
1607
|
+
}]
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
// src/evm/oneinch.ts
|
|
1612
|
+
/**
|
|
1613
|
+
* Decoding of 1inch Limit Order Protocol v4 orders signed at an Aggregation Router v6. The `Order`
|
|
1614
|
+
* type is verbatim from `contracts/OrderLib.sol` in 1inch/limit-order-protocol at tag 4.0.0
|
|
1615
|
+
* (https://github.com/1inch/limit-order-protocol/blob/c8be9c67247880bd6ec88cf7ad2e040a16a483f2/contracts/OrderLib.sol);
|
|
1616
|
+
* the router domains `{name: "1inch Aggregation Router", version: "6", chainId, verifyingContract}`
|
|
1617
|
+
* were verified by on-chain `eip712Domain()` probed in vectors/chains/order-protocols.json. The LOP
|
|
1618
|
+
* signs only ERC-20 assets — the zero address and the `0xeeee…` pseudo-address other protocols use
|
|
1619
|
+
* as a native marker are malformed here.
|
|
1620
|
+
*
|
|
1621
|
+
* `makerTraits` (bit layout in `contracts/libraries/MakerTraitsLib.sol`) decides whether anything
|
|
1622
|
+
* unsigned can change the order's bounds. Rejected — anything set makes the document a near miss:
|
|
1623
|
+
* HAS_EXTENSION (249) and PRE_/POST_INTERACTION_CALL (252/251), which let an extension hidden in
|
|
1624
|
+
* `salt` run arbitrary code (Fusion orders always carry an extension, so they stay blind);
|
|
1625
|
+
* UNWRAP_WETH (247), which changes what the receiver actually gets; the spare bit 253 and the
|
|
1626
|
+
* undefined range 200..246. The remaining flags (NO_PARTIAL_FILLS, ALLOW_MULTIPLE_FILLS,
|
|
1627
|
+
* NEED_CHECK_EPOCH_MANAGER, USE_PERMIT2) only constrain how the order fills, not its bounds.
|
|
1628
|
+
*/
|
|
1629
|
+
/** `Order`'s field list, verbatim from OrderLib.sol. */
|
|
1630
|
+
const ORDER_FIELDS = [
|
|
1631
|
+
"uint256 salt",
|
|
1632
|
+
"address maker",
|
|
1633
|
+
"address receiver",
|
|
1634
|
+
"address makerAsset",
|
|
1635
|
+
"address takerAsset",
|
|
1636
|
+
"uint256 makingAmount",
|
|
1637
|
+
"uint256 takingAmount",
|
|
1638
|
+
"uint256 makerTraits"
|
|
1639
|
+
];
|
|
1640
|
+
const V6_ROUTER = "0x111111125421ca6dc452d289314280a0f8842a65";
|
|
1641
|
+
const V6_ZKSYNC_ROUTER = "0x6fd4383cb451173d5f9304f041c7bcbf27d561ff";
|
|
1642
|
+
const V6_CHAINS = /* @__PURE__ */ new Set([
|
|
1643
|
+
1,
|
|
1644
|
+
10,
|
|
1645
|
+
25,
|
|
1646
|
+
56,
|
|
1647
|
+
100,
|
|
1648
|
+
130,
|
|
1649
|
+
137,
|
|
1650
|
+
143,
|
|
1651
|
+
146,
|
|
1652
|
+
8217,
|
|
1653
|
+
8453,
|
|
1654
|
+
42161,
|
|
1655
|
+
43114,
|
|
1656
|
+
59144
|
|
1657
|
+
]);
|
|
1658
|
+
const v6Router = (chainId) => chainId === 324 ? V6_ZKSYNC_ROUTER : V6_CHAINS.has(chainId) ? V6_ROUTER : void 0;
|
|
1659
|
+
const UNWRAP_WETH = 1n << 247n;
|
|
1660
|
+
const HAS_EXTENSION = 1n << 249n;
|
|
1661
|
+
const POST_INTERACTION_CALL = 1n << 251n;
|
|
1662
|
+
const PRE_INTERACTION_CALL = 1n << 252n;
|
|
1663
|
+
const SPARE_BIT_253 = 1n << 253n;
|
|
1664
|
+
const UNDEFINED_200_246 = (1n << 47n) - 1n << 200n;
|
|
1665
|
+
const REJECTED = UNWRAP_WETH | HAS_EXTENSION | POST_INTERACTION_CALL | PRE_INTERACTION_CALL | SPARE_BIT_253 | UNDEFINED_200_246;
|
|
1666
|
+
const NO_PARTIAL_FILLS = 1n << 255n;
|
|
1667
|
+
const ALLOWED_SENDER = (1n << 80n) - 1n;
|
|
1668
|
+
const EXPIRATION = (1n << 40n) - 1n << 80n;
|
|
1669
|
+
const ZERO = "0x0000000000000000000000000000000000000000";
|
|
1670
|
+
const PSEUDO_NATIVE = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
1671
|
+
/** The order under the exact Aggregation Router v6 domain, or `undefined` — a near miss. */
|
|
1672
|
+
const recognizeOneinch = (json, chainId, table) => {
|
|
1673
|
+
const { domain, types, primaryType, message } = json;
|
|
1674
|
+
const verifying = typedDataAddress(domain["verifyingContract"]);
|
|
1675
|
+
const router = v6Router(chainId);
|
|
1676
|
+
if (domain["name"] !== "1inch Aggregation Router" || domain["version"] !== "6" || domainChainId(domain) !== chainId || router === void 0 || verifying === void 0 || verifying.toLowerCase() !== router || primaryType !== "Order" || Object.keys(types).length !== 2 || !sameFields(types, "EIP712Domain", [
|
|
1677
|
+
"string name",
|
|
1678
|
+
"string version",
|
|
1679
|
+
"uint256 chainId",
|
|
1680
|
+
"address verifyingContract"
|
|
1681
|
+
]) || !sameFields(types, "Order", ORDER_FIELDS)) return;
|
|
1682
|
+
const maker = typedDataAddress(message["maker"]);
|
|
1683
|
+
const receiver = typedDataAddress(message["receiver"]);
|
|
1684
|
+
const makerAsset = typedDataAddress(message["makerAsset"]);
|
|
1685
|
+
const takerAsset = typedDataAddress(message["takerAsset"]);
|
|
1686
|
+
const makingAmount = typedDataUint(message["makingAmount"], MAX_UINT256);
|
|
1687
|
+
const takingAmount = typedDataUint(message["takingAmount"], MAX_UINT256);
|
|
1688
|
+
const traits = typedDataUint(message["makerTraits"], MAX_UINT256);
|
|
1689
|
+
if (maker === void 0 || receiver === void 0 || makerAsset === void 0 || takerAsset === void 0 || makingAmount === void 0 || takingAmount === void 0 || traits === void 0 || typedDataUint(message["salt"], MAX_UINT256) === void 0 || makerAsset.toLowerCase() === ZERO || makerAsset.toLowerCase() === PSEUDO_NATIVE || takerAsset.toLowerCase() === ZERO || takerAsset.toLowerCase() === PSEUDO_NATIVE || (traits & REJECTED) !== 0n) return;
|
|
1690
|
+
const expiry = (traits & EXPIRATION) >> 80n;
|
|
1691
|
+
const allowed = traits & ALLOWED_SENDER;
|
|
1692
|
+
return {
|
|
1693
|
+
protocol: "1inch",
|
|
1694
|
+
maker,
|
|
1695
|
+
give: orderAmount(makerAsset, makingAmount, chainId, table),
|
|
1696
|
+
receive: [{
|
|
1697
|
+
recipient: receiver.toLowerCase() === ZERO ? maker : receiver,
|
|
1698
|
+
amount: orderAmount(takerAsset, takingAmount, chainId, table)
|
|
1699
|
+
}],
|
|
1700
|
+
...expiry === 0n ? {} : { expiry: Number(expiry) },
|
|
1701
|
+
partialFill: (traits & NO_PARTIAL_FILLS) === 0n,
|
|
1702
|
+
...allowed === 0n ? {} : { allowedSender: `0x${allowed.toString(16).padStart(20, "0")}` }
|
|
189
1703
|
};
|
|
190
1704
|
};
|
|
191
1705
|
// src/evm/safe.ts
|
|
@@ -217,6 +1731,8 @@ const SAFE_TX = [
|
|
|
217
1731
|
"uint256 nonce"
|
|
218
1732
|
];
|
|
219
1733
|
const MULTISEND = AbiFunction.from("function multiSend(bytes transactions)");
|
|
1734
|
+
/** The zero address: `gasToken` zero pays the refund in the chain's native asset. */
|
|
1735
|
+
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
220
1736
|
/**
|
|
221
1737
|
* Packed MultiSend entries (`uint8 operation, address to, uint256 value, uint256 dataLength, bytes
|
|
222
1738
|
* data` repeated). `undefined` when `data` is not a `multiSend(bytes)` call, a byte is truncated or
|
|
@@ -257,9 +1773,10 @@ const multiSendEntries = (data) => {
|
|
|
257
1773
|
/**
|
|
258
1774
|
* The Safe transaction a typed-data document signs, or `undefined` when its shape is not exactly
|
|
259
1775
|
* the recognized one. `decode` decodes one inner call (the transaction rules without a fee); the
|
|
260
|
-
* caller injects it bound to the request's network and token table
|
|
1776
|
+
* caller injects it bound to the request's network and token table, and receives the Safe address —
|
|
1777
|
+
* a call to it runs the Safe's own code.
|
|
261
1778
|
*/
|
|
262
|
-
function recognizeSafe(json, decode) {
|
|
1779
|
+
function recognizeSafe(json, context, decode) {
|
|
263
1780
|
const { types, primaryType, message, domain } = json;
|
|
264
1781
|
if (primaryType !== "SafeTx" || !sameFields(types, "SafeTx", SAFE_TX)) return;
|
|
265
1782
|
const safe = typedDataAddress(domain["verifyingContract"]);
|
|
@@ -275,11 +1792,41 @@ function recognizeSafe(json, decode) {
|
|
|
275
1792
|
const nonce = typedDataUint(message["nonce"], MAX_UINT256);
|
|
276
1793
|
if (safe === void 0 || to === void 0 || value === void 0 || data === void 0 || operation === void 0 || operation > 1n || safeTxGas === void 0 || baseGas === void 0 || gasPrice === void 0 || gasToken === void 0 || refundReceiver === void 0 || nonce === void 0) return;
|
|
277
1794
|
const inner = operation === 1n && SAFE_MULTISEND_CALL_ONLY.has(to.toLowerCase()) ? multiSendEntries(data) : void 0;
|
|
278
|
-
const calls =
|
|
1795
|
+
const calls = operation === 1n && inner === void 0 ? [{
|
|
1796
|
+
family: "evm",
|
|
1797
|
+
network: context.network,
|
|
1798
|
+
summary: "contract-call",
|
|
1799
|
+
outflows: [],
|
|
1800
|
+
approvals: [],
|
|
1801
|
+
fee: void 0,
|
|
1802
|
+
warnings: [],
|
|
1803
|
+
verifiability: "opaque",
|
|
1804
|
+
blind: "safe-delegatecall",
|
|
1805
|
+
contract: {
|
|
1806
|
+
address: to,
|
|
1807
|
+
created: false,
|
|
1808
|
+
selector: data.slice(0, 10).toLowerCase()
|
|
1809
|
+
}
|
|
1810
|
+
}] : (inner ?? [{
|
|
279
1811
|
to,
|
|
280
1812
|
value,
|
|
281
1813
|
data
|
|
282
|
-
}]).map(decode);
|
|
1814
|
+
}]).map((call) => decode(call, safe));
|
|
1815
|
+
const refundAsset = (v) => {
|
|
1816
|
+
if (gasToken === ZERO_ADDRESS) return {
|
|
1817
|
+
asset: EVM_NATIVE_ASSET,
|
|
1818
|
+
amount: v.toString(10)
|
|
1819
|
+
};
|
|
1820
|
+
const found = lookupEvmToken(context.table, context.chainId, gasToken);
|
|
1821
|
+
return {
|
|
1822
|
+
asset: gasToken,
|
|
1823
|
+
amount: v.toString(10),
|
|
1824
|
+
...found === void 0 ? {} : {
|
|
1825
|
+
symbol: found.symbol,
|
|
1826
|
+
decimals: found.decimals
|
|
1827
|
+
}
|
|
1828
|
+
};
|
|
1829
|
+
};
|
|
283
1830
|
return {
|
|
284
1831
|
safe: {
|
|
285
1832
|
safe,
|
|
@@ -290,134 +1837,141 @@ function recognizeSafe(json, decode) {
|
|
|
290
1837
|
data,
|
|
291
1838
|
calls,
|
|
292
1839
|
...gasPrice > 0n ? { refund: {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
1840
|
+
...refundReceiver === ZERO_ADDRESS ? {} : { receiver: refundReceiver },
|
|
1841
|
+
gasPrice: refundAsset(gasPrice),
|
|
1842
|
+
amount: refundAsset((baseGas + safeTxGas) * gasPrice)
|
|
296
1843
|
} } : {}
|
|
297
1844
|
},
|
|
298
1845
|
multisend: inner !== void 0
|
|
299
1846
|
};
|
|
300
1847
|
}
|
|
301
|
-
// src/evm/
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
"
|
|
307
|
-
"
|
|
308
|
-
"erc721",
|
|
309
|
-
"erc1155",
|
|
310
|
-
"erc721-criteria",
|
|
311
|
-
"erc1155-criteria"
|
|
1848
|
+
// src/evm/snapshot.ts
|
|
1849
|
+
const DOMAIN_FIELDS = ["string name", "string version"];
|
|
1850
|
+
const VOTE_FIELDS = [
|
|
1851
|
+
"string from",
|
|
1852
|
+
"string space",
|
|
1853
|
+
"uint64 timestamp",
|
|
1854
|
+
"string proposal"
|
|
312
1855
|
];
|
|
313
|
-
const
|
|
314
|
-
"
|
|
315
|
-
"
|
|
316
|
-
"
|
|
317
|
-
"uint256 startAmount",
|
|
318
|
-
"uint256 endAmount"
|
|
1856
|
+
const VOTE_TAIL = [
|
|
1857
|
+
"string reason",
|
|
1858
|
+
"string app",
|
|
1859
|
+
"string metadata"
|
|
319
1860
|
];
|
|
320
|
-
const
|
|
321
|
-
"
|
|
322
|
-
"
|
|
323
|
-
"
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
"
|
|
327
|
-
"
|
|
328
|
-
"
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
]
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
1861
|
+
const VOTE_CHOICE = [
|
|
1862
|
+
"uint32 choice",
|
|
1863
|
+
"uint32[] choice",
|
|
1864
|
+
"string choice"
|
|
1865
|
+
];
|
|
1866
|
+
const ALIAS_FIELDS = [
|
|
1867
|
+
"address from",
|
|
1868
|
+
"address alias",
|
|
1869
|
+
"uint64 timestamp"
|
|
1870
|
+
];
|
|
1871
|
+
const recognizeSnapshot = (json, signer) => {
|
|
1872
|
+
const { types, primaryType, domain, message } = json;
|
|
1873
|
+
if (domain["name"] !== "snapshot" || domain["version"] !== "0.1.4" || Object.keys(domain).length !== 2 || Object.keys(types).length !== 2 || !sameFields(types, "EIP712Domain", DOMAIN_FIELDS)) return;
|
|
1874
|
+
if (primaryType === "Vote" && VOTE_CHOICE.some((choice) => sameFields(types, "Vote", [
|
|
1875
|
+
...VOTE_FIELDS,
|
|
1876
|
+
choice,
|
|
1877
|
+
...VOTE_TAIL
|
|
1878
|
+
]))) return { kind: "vote" };
|
|
1879
|
+
if (primaryType === "Alias" && sameFields(types, "Alias", ALIAS_FIELDS)) {
|
|
1880
|
+
const from = typedDataAddress(message["from"]);
|
|
1881
|
+
const alias = typedDataAddress(message["alias"]);
|
|
1882
|
+
if (from === void 0 || from.toLowerCase() !== signer.toLowerCase() || alias === void 0) return;
|
|
342
1883
|
return {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
1884
|
+
kind: "alias",
|
|
1885
|
+
content: { authority: {
|
|
1886
|
+
kind: "snapshot-alias",
|
|
1887
|
+
alias
|
|
1888
|
+
} },
|
|
1889
|
+
summary: "authorization",
|
|
1890
|
+
outflows: [],
|
|
1891
|
+
verifiability: "partial"
|
|
349
1892
|
};
|
|
350
1893
|
}
|
|
351
|
-
return {
|
|
352
|
-
asset: token,
|
|
353
|
-
amount: value.toString(10)
|
|
354
|
-
};
|
|
355
1894
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
1895
|
+
// src/evm/wrapped-native.ts
|
|
1896
|
+
/**
|
|
1897
|
+
* Wrapped natives — WETH9-style contracts listed in the token table with role "wrapped-native".
|
|
1898
|
+
* `deposit()` mints the token to the caller for exactly msg.value and `withdraw(uint256)` burns the
|
|
1899
|
+
* token and returns the coin, so both describe as a swap whose other side is exact — verifiability
|
|
1900
|
+
* "full".
|
|
1901
|
+
*/
|
|
1902
|
+
const DEPOSIT = AbiFunction.from("function deposit() payable");
|
|
1903
|
+
const WITHDRAW = AbiFunction.from("function withdraw(uint256 wad)");
|
|
1904
|
+
/** Canonical-encoding decode like `tryCall` in lido.ts — undefined on any mismatch. */
|
|
1905
|
+
const tryCall$1 = (fn, data) => {
|
|
1906
|
+
const selector = AbiFunction.getSelector(fn);
|
|
1907
|
+
if (!data.toLowerCase().startsWith(selector)) return;
|
|
1908
|
+
try {
|
|
1909
|
+
assertHex(data, "data");
|
|
1910
|
+
const args = AbiFunction.decodeData(fn, data);
|
|
1911
|
+
if (!Array.isArray(args)) return;
|
|
1912
|
+
return AbiFunction.encodeData(fn, args).toLowerCase() === data.toLowerCase() ? args : void 0;
|
|
1913
|
+
} catch {
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
371
1916
|
};
|
|
372
|
-
const
|
|
373
|
-
const
|
|
374
|
-
|
|
1917
|
+
const argUint$1 = (args, index) => {
|
|
1918
|
+
const value = args[index];
|
|
1919
|
+
if (typeof value !== "bigint") throw new ChainError("invalid-request", "decoded argument is not an integer");
|
|
1920
|
+
return value;
|
|
375
1921
|
};
|
|
376
1922
|
/**
|
|
377
|
-
*
|
|
378
|
-
*
|
|
1923
|
+
* `caller` is the account the call runs as — msg.sender at `call.to`: the signer for a transaction
|
|
1924
|
+
* or batch call, the Safe or deposit wallet for an inner call. Minted or withdrawn assets go to
|
|
1925
|
+
* it.
|
|
379
1926
|
*/
|
|
380
|
-
|
|
381
|
-
const
|
|
382
|
-
if (
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
1927
|
+
const decodeWrappedNative = (chainId, call, caller, table) => {
|
|
1928
|
+
const token = call.to === void 0 ? void 0 : lookupEvmToken(table, chainId, call.to);
|
|
1929
|
+
if (call.to === void 0 || token?.role !== "wrapped-native") return;
|
|
1930
|
+
if (call.data.toLowerCase() === AbiFunction.getSelector(DEPOSIT)) return {
|
|
1931
|
+
outflows: [{
|
|
1932
|
+
to: call.to,
|
|
1933
|
+
amount: {
|
|
1934
|
+
asset: EVM_NATIVE_ASSET,
|
|
1935
|
+
amount: call.value.toString(10)
|
|
1936
|
+
},
|
|
1937
|
+
verified: true
|
|
1938
|
+
}],
|
|
1939
|
+
minimumReceived: [{
|
|
1940
|
+
to: caller,
|
|
1941
|
+
amount: {
|
|
1942
|
+
asset: call.to,
|
|
1943
|
+
amount: call.value.toString(10),
|
|
1944
|
+
symbol: token.symbol,
|
|
1945
|
+
decimals: token.decimals
|
|
1946
|
+
}
|
|
1947
|
+
}]
|
|
1948
|
+
};
|
|
1949
|
+
const args = tryCall$1(WITHDRAW, call.data);
|
|
1950
|
+
if (args === void 0 || call.value !== 0n) return;
|
|
1951
|
+
const wad = argUint$1(args, 0);
|
|
399
1952
|
return {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
1953
|
+
outflows: [{
|
|
1954
|
+
to: call.to,
|
|
1955
|
+
amount: {
|
|
1956
|
+
asset: call.to,
|
|
1957
|
+
amount: wad.toString(10),
|
|
1958
|
+
symbol: token.symbol,
|
|
1959
|
+
decimals: token.decimals
|
|
1960
|
+
},
|
|
1961
|
+
verified: true
|
|
1962
|
+
}],
|
|
1963
|
+
minimumReceived: [{
|
|
1964
|
+
to: caller,
|
|
1965
|
+
amount: {
|
|
1966
|
+
asset: EVM_NATIVE_ASSET,
|
|
1967
|
+
amount: wad.toString(10)
|
|
1968
|
+
}
|
|
1969
|
+
}]
|
|
406
1970
|
};
|
|
407
|
-
}
|
|
1971
|
+
};
|
|
408
1972
|
// src/evm/decode.ts
|
|
409
|
-
const ERC20_TRANSFER = AbiFunction.from("function transfer(address to, uint256 amount)");
|
|
410
|
-
const ERC20_APPROVE = AbiFunction.from("function approve(address spender, uint256 amount)");
|
|
411
|
-
const ERC20_INCREASE = AbiFunction.from("function increaseAllowance(address spender, uint256 amount)");
|
|
412
|
-
const ERC20_DECREASE = AbiFunction.from("function decreaseAllowance(address spender, uint256 subtractedValue)");
|
|
413
|
-
const SET_APPROVAL_FOR_ALL = AbiFunction.from("function setApprovalForAll(address operator, bool approved)");
|
|
414
1973
|
const PERMIT2_APPROVE = AbiFunction.from("function approve(address token, address spender, uint160 amount, uint48 expiration)");
|
|
415
1974
|
const PERMIT2_LOCKDOWN = AbiFunction.from("function lockdown((address token, address spender)[] approvals)");
|
|
416
|
-
const ERC721_SAFE_FROM_DATA = AbiFunction.from("function safeTransferFrom(address from, address to, uint256 tokenId, bytes data)");
|
|
417
|
-
const ERC1155_SAFE_BATCH_FROM = AbiFunction.from("function safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] amounts, bytes data)");
|
|
418
|
-
const ERC721_TRANSFER_FROM = AbiFunction.from("function transferFrom(address from, address to, uint256 tokenId)");
|
|
419
|
-
const ERC721_SAFE_FROM = AbiFunction.from("function safeTransferFrom(address from, address to, uint256 tokenId)");
|
|
420
|
-
const ERC1155_SAFE_FROM = AbiFunction.from("function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes data)");
|
|
421
1975
|
const argAddress = (args, index) => {
|
|
422
1976
|
const value = args[index];
|
|
423
1977
|
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(value)) throw new ChainError("invalid-request", "decoded argument is not an address");
|
|
@@ -451,35 +2005,12 @@ const weiAmount = (wei, symbol, decimals) => ({
|
|
|
451
2005
|
...symbol === void 0 ? {} : { symbol },
|
|
452
2006
|
...decimals === void 0 ? {} : { decimals }
|
|
453
2007
|
});
|
|
454
|
-
const feeWei = (tx) => quantityBigInt(tx.gas, "tx.gas") * (tx.type === "eip1559" ? quantityBigInt(tx.maxFeePerGas, "tx.maxFeePerGas") : quantityBigInt(tx.gasPrice, "tx.gasPrice"));
|
|
2008
|
+
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
2009
|
const nativeOutflow = (value, to) => [{
|
|
456
2010
|
to,
|
|
457
2011
|
amount: weiAmount(value),
|
|
458
2012
|
verified: true
|
|
459
2013
|
}];
|
|
460
|
-
const tokenFlow = (target, to, amount, chainId, table) => {
|
|
461
|
-
const token = lookupEvmToken(table, chainId, target);
|
|
462
|
-
return {
|
|
463
|
-
flows: [{
|
|
464
|
-
to,
|
|
465
|
-
amount: {
|
|
466
|
-
asset: target,
|
|
467
|
-
amount: amount.toString(10),
|
|
468
|
-
...token === void 0 ? {} : {
|
|
469
|
-
symbol: token.symbol,
|
|
470
|
-
decimals: token.decimals
|
|
471
|
-
}
|
|
472
|
-
},
|
|
473
|
-
verified: token !== void 0
|
|
474
|
-
}],
|
|
475
|
-
verified: token !== void 0
|
|
476
|
-
};
|
|
477
|
-
};
|
|
478
|
-
const argBool = (args, index) => {
|
|
479
|
-
const value = args[index];
|
|
480
|
-
if (typeof value !== "boolean") throw new ChainError("invalid-request", "decoded argument is not a bool");
|
|
481
|
-
return value;
|
|
482
|
-
};
|
|
483
2014
|
const argList = (args, index) => {
|
|
484
2015
|
const value = args[index];
|
|
485
2016
|
if (!Array.isArray(value)) throw new ChainError("invalid-request", "decoded argument is not an array");
|
|
@@ -492,56 +2023,114 @@ const argSeconds = (args, index) => {
|
|
|
492
2023
|
};
|
|
493
2024
|
const pairField = (pair, key) => {
|
|
494
2025
|
const value = typeof pair === "object" && pair !== null ? Reflect.get(pair, key) : "";
|
|
495
|
-
|
|
2026
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(value)) throw new ChainError("invalid-request", "decoded argument is not an address");
|
|
2027
|
+
return checksumEvmAddress(value);
|
|
496
2028
|
};
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
amount: {
|
|
500
|
-
asset,
|
|
501
|
-
amount: id.toString(10)
|
|
502
|
-
},
|
|
503
|
-
verified: false
|
|
504
|
-
}];
|
|
505
|
-
/**
|
|
506
|
-
* The call rules shared by a whole transaction and a Safe's inner calls: the same selector table
|
|
507
|
-
* produces the intent; `fee` is `undefined` for a call that is not itself a transaction.
|
|
508
|
-
*/
|
|
509
|
-
const decodeCall = (call, network, fee, table) => {
|
|
2029
|
+
/** A call into a protocol the decoder models in full, native value included. */
|
|
2030
|
+
const protocolIntent = (call, { network, fee, table, signer, self }) => {
|
|
510
2031
|
const chainId = networkChainId(network);
|
|
511
|
-
const data = call.data.toLowerCase();
|
|
512
2032
|
const base = {
|
|
513
2033
|
family: "evm",
|
|
514
2034
|
network,
|
|
515
2035
|
approvals: [],
|
|
516
2036
|
warnings: []
|
|
517
2037
|
};
|
|
518
|
-
|
|
519
|
-
|
|
2038
|
+
const fiat24 = decodeFiat24(chainId, call, table);
|
|
2039
|
+
if (fiat24 !== void 0) {
|
|
2040
|
+
if (fiat24 === "claimed") {
|
|
2041
|
+
const reason = callNearMiss(call.to ?? "", chainId, table, call.data);
|
|
2042
|
+
return {
|
|
2043
|
+
...base,
|
|
2044
|
+
summary: "contract-call",
|
|
2045
|
+
outflows: call.value > 0n ? nativeOutflow(call.value, call.to ?? "") : [],
|
|
2046
|
+
fee,
|
|
2047
|
+
verifiability: "opaque",
|
|
2048
|
+
...reason === void 0 ? {} : { blind: reason }
|
|
2049
|
+
};
|
|
2050
|
+
}
|
|
2051
|
+
const { decoded } = fiat24;
|
|
2052
|
+
return {
|
|
520
2053
|
...base,
|
|
521
|
-
summary:
|
|
522
|
-
outflows:
|
|
2054
|
+
summary: decoded.summary,
|
|
2055
|
+
outflows: decoded.outflows,
|
|
2056
|
+
warnings: decoded.warnings,
|
|
2057
|
+
...decoded.fiat24 === void 0 ? {} : { fiat24: decoded.fiat24 },
|
|
523
2058
|
fee,
|
|
524
|
-
verifiability: "
|
|
2059
|
+
verifiability: "partial"
|
|
525
2060
|
};
|
|
2061
|
+
}
|
|
2062
|
+
const zeroX = decodeZeroX(chainId, call, table);
|
|
2063
|
+
if (zeroX !== void 0) {
|
|
2064
|
+
const { summary, outflows, approvals, verifiability, minimumReceived } = zeroX;
|
|
526
2065
|
return {
|
|
527
2066
|
...base,
|
|
528
|
-
summary
|
|
529
|
-
outflows
|
|
2067
|
+
summary,
|
|
2068
|
+
outflows,
|
|
2069
|
+
approvals,
|
|
2070
|
+
...minimumReceived === void 0 ? {} : { minimumReceived },
|
|
530
2071
|
fee,
|
|
531
|
-
verifiability
|
|
2072
|
+
verifiability
|
|
532
2073
|
};
|
|
533
2074
|
}
|
|
534
|
-
const
|
|
535
|
-
if (
|
|
536
|
-
|
|
537
|
-
|
|
2075
|
+
const across = decodeAcross(chainId, call, table);
|
|
2076
|
+
if (across !== void 0) return {
|
|
2077
|
+
...base,
|
|
2078
|
+
summary: "bridge",
|
|
2079
|
+
outflows: across.outflows,
|
|
2080
|
+
minimumReceived: across.minimumReceived,
|
|
2081
|
+
bridge: across.bridge,
|
|
2082
|
+
fee,
|
|
2083
|
+
verifiability: "partial"
|
|
2084
|
+
};
|
|
2085
|
+
if (isCctpMessenger(chainId, call.to)) {
|
|
2086
|
+
const cctp = decodeCctp(chainId, call, signer, table);
|
|
2087
|
+
if (cctp !== void 0) return {
|
|
538
2088
|
...base,
|
|
539
2089
|
summary: "transfer",
|
|
540
|
-
outflows:
|
|
2090
|
+
outflows: cctp.outflows,
|
|
2091
|
+
hyperliquidDeposit: cctp.hyperliquidDeposit,
|
|
2092
|
+
fee,
|
|
2093
|
+
verifiability: "partial"
|
|
2094
|
+
};
|
|
2095
|
+
return {
|
|
2096
|
+
...base,
|
|
2097
|
+
summary: "contract-call",
|
|
2098
|
+
outflows: call.value > 0n ? nativeOutflow(call.value, call.to ?? "") : [],
|
|
541
2099
|
fee,
|
|
542
|
-
verifiability:
|
|
2100
|
+
verifiability: "opaque",
|
|
2101
|
+
blind: "cctp-destination"
|
|
543
2102
|
};
|
|
544
2103
|
}
|
|
2104
|
+
const lido = decodeLido(chainId, call, self, table);
|
|
2105
|
+
if (lido !== void 0) return {
|
|
2106
|
+
...base,
|
|
2107
|
+
summary: "stake",
|
|
2108
|
+
outflows: lido.outflows,
|
|
2109
|
+
staking: lido.staking,
|
|
2110
|
+
fee,
|
|
2111
|
+
verifiability: "partial"
|
|
2112
|
+
};
|
|
2113
|
+
const wrapped = decodeWrappedNative(chainId, call, self, table);
|
|
2114
|
+
if (wrapped !== void 0) return {
|
|
2115
|
+
...base,
|
|
2116
|
+
summary: "swap",
|
|
2117
|
+
outflows: wrapped.outflows,
|
|
2118
|
+
approvals: [],
|
|
2119
|
+
minimumReceived: wrapped.minimumReceived,
|
|
2120
|
+
fee,
|
|
2121
|
+
verifiability: "full"
|
|
2122
|
+
};
|
|
2123
|
+
};
|
|
2124
|
+
/** The token-standard selectors, else an opaque call. None of them accounts for native value. */
|
|
2125
|
+
const standardIntent = (call, { network, fee, table }) => {
|
|
2126
|
+
const chainId = networkChainId(network);
|
|
2127
|
+
const data = call.data.toLowerCase();
|
|
2128
|
+
const base = {
|
|
2129
|
+
family: "evm",
|
|
2130
|
+
network,
|
|
2131
|
+
approvals: [],
|
|
2132
|
+
warnings: []
|
|
2133
|
+
};
|
|
545
2134
|
const partial = (summary, outflows, approvals) => ({
|
|
546
2135
|
...base,
|
|
547
2136
|
summary,
|
|
@@ -563,43 +2152,15 @@ const decodeCall = (call, network, fee, table) => {
|
|
|
563
2152
|
const lockdownArgs = tryCall(PERMIT2_LOCKDOWN, data);
|
|
564
2153
|
if (lockdownArgs !== void 0) return partial("approve", [], argList(lockdownArgs, 0).map((pair) => allowanceChange(pairField(pair, "token"), pairField(pair, "spender"), 0n, "set", MAX_UINT160, chainId, table, { via: "permit2" })));
|
|
565
2154
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if (operatorArgs !== void 0) return partial("approve", [], [{
|
|
576
|
-
kind: "operator",
|
|
577
|
-
asset: token,
|
|
578
|
-
spender: argAddress(operatorArgs, 0),
|
|
579
|
-
approved: argBool(operatorArgs, 1),
|
|
580
|
-
verified: false
|
|
581
|
-
}]);
|
|
582
|
-
const transferFromArgs = tryCall(ERC721_TRANSFER_FROM, data);
|
|
583
|
-
if (transferFromArgs !== void 0) {
|
|
584
|
-
const to = argAddress(transferFromArgs, 1);
|
|
585
|
-
const id = argUint(transferFromArgs, 2);
|
|
586
|
-
if (lookupEvmToken(table, chainId, token) !== void 0) return partial("transfer", tokenFlow(token, to, id, chainId, table).flows, []);
|
|
587
|
-
return partial("transfer", nftFlow(token, to, id), []);
|
|
588
|
-
}
|
|
589
|
-
for (const fn of [ERC721_SAFE_FROM, ERC721_SAFE_FROM_DATA]) {
|
|
590
|
-
const args = tryCall(fn, data);
|
|
591
|
-
if (args !== void 0) return partial("transfer", nftFlow(token, argAddress(args, 1), argUint(args, 2)), []);
|
|
592
|
-
}
|
|
593
|
-
const erc1155Args = tryCall(ERC1155_SAFE_FROM, data);
|
|
594
|
-
if (erc1155Args !== void 0) return partial("transfer", nftFlow(token, argAddress(erc1155Args, 1), argUint(erc1155Args, 2)), []);
|
|
595
|
-
const batchArgs = tryCall(ERC1155_SAFE_BATCH_FROM, data);
|
|
596
|
-
if (batchArgs !== void 0) {
|
|
597
|
-
const ids = argList(batchArgs, 2);
|
|
598
|
-
if (ids.length > 0 && ids.length === argList(batchArgs, 3).length) {
|
|
599
|
-
const to = argAddress(batchArgs, 1);
|
|
600
|
-
return partial("transfer", ids.flatMap((id) => nftFlow(token, to, argUint([id], 0))), []);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
2155
|
+
const tokenCall = decodeTokenCall(token, data, chainId, table);
|
|
2156
|
+
if (tokenCall !== void 0) return {
|
|
2157
|
+
...base,
|
|
2158
|
+
summary: tokenCall.summary,
|
|
2159
|
+
outflows: tokenCall.outflows,
|
|
2160
|
+
approvals: tokenCall.approvals,
|
|
2161
|
+
fee,
|
|
2162
|
+
verifiability: tokenCall.verifiability
|
|
2163
|
+
};
|
|
603
2164
|
return {
|
|
604
2165
|
...base,
|
|
605
2166
|
summary: "contract-call",
|
|
@@ -608,13 +2169,167 @@ const decodeCall = (call, network, fee, table) => {
|
|
|
608
2169
|
verifiability: "opaque"
|
|
609
2170
|
};
|
|
610
2171
|
};
|
|
611
|
-
|
|
2172
|
+
/**
|
|
2173
|
+
* Labels allowance approvals whose spender is a Fiat24 contract and raises the card-pull and
|
|
2174
|
+
* unlimited warnings. Runs on every decoded call, so batch and Safe inner calls get labelled the
|
|
2175
|
+
* same way.
|
|
2176
|
+
*/
|
|
2177
|
+
const labelFiat24Spenders = (intent, chainId) => {
|
|
2178
|
+
const extra = [];
|
|
2179
|
+
let labelled = false;
|
|
2180
|
+
const approvals = intent.approvals.map((change) => {
|
|
2181
|
+
if (change.kind !== "allowance") return change;
|
|
2182
|
+
const role = fiat24Spender(chainId, change.spender);
|
|
2183
|
+
if (role === void 0) return change;
|
|
2184
|
+
if (role === "card" && change.change !== "decrease" && BigInt(change.amount.amount) > 0n) extra.push({
|
|
2185
|
+
kind: "fiat24-card-pull",
|
|
2186
|
+
message: "card"
|
|
2187
|
+
});
|
|
2188
|
+
if (change.unlimited) extra.push({
|
|
2189
|
+
kind: "fiat24-unlimited-approval",
|
|
2190
|
+
level: "danger",
|
|
2191
|
+
message: role
|
|
2192
|
+
});
|
|
2193
|
+
labelled = true;
|
|
2194
|
+
return {
|
|
2195
|
+
...change,
|
|
2196
|
+
fiat24Spender: role
|
|
2197
|
+
};
|
|
2198
|
+
});
|
|
2199
|
+
return labelled ? {
|
|
2200
|
+
...intent,
|
|
2201
|
+
approvals,
|
|
2202
|
+
warnings: [...intent.warnings, ...extra]
|
|
2203
|
+
} : intent;
|
|
2204
|
+
};
|
|
2205
|
+
/**
|
|
2206
|
+
* The call rules shared by a whole transaction and a Safe's inner calls: the same selector table
|
|
2207
|
+
* produces the intent; `fee` is `undefined` for a call that is not itself a transaction. Native
|
|
2208
|
+
* value sent along with calldata is always an outflow to the contract that receives it.
|
|
2209
|
+
*/
|
|
2210
|
+
const decodeCall = (call, context) => {
|
|
2211
|
+
if (call.data === "0x" && call.to !== void 0) return {
|
|
2212
|
+
family: "evm",
|
|
2213
|
+
network: context.network,
|
|
2214
|
+
summary: "transfer",
|
|
2215
|
+
outflows: nativeOutflow(call.value, call.to),
|
|
2216
|
+
approvals: [],
|
|
2217
|
+
fee: context.fee,
|
|
2218
|
+
warnings: [],
|
|
2219
|
+
verifiability: "full"
|
|
2220
|
+
};
|
|
2221
|
+
const address = call.to ?? call.created;
|
|
2222
|
+
const token = call.to === void 0 ? void 0 : lookupEvmToken(context.table, networkChainId(context.network), call.to);
|
|
2223
|
+
const contract = address === void 0 ? {} : { contract: {
|
|
2224
|
+
address,
|
|
2225
|
+
created: call.to === void 0,
|
|
2226
|
+
...call.to === void 0 ? {} : { selector: call.data.slice(0, 10).toLowerCase() },
|
|
2227
|
+
...token === void 0 ? {} : { symbol: token.symbol }
|
|
2228
|
+
} };
|
|
2229
|
+
if (call.to !== void 0 && call.to.toLowerCase() === context.self.toLowerCase()) return {
|
|
2230
|
+
family: "evm",
|
|
2231
|
+
network: context.network,
|
|
2232
|
+
summary: "contract-call",
|
|
2233
|
+
outflows: call.value > 0n ? nativeOutflow(call.value, call.to ?? "") : [],
|
|
2234
|
+
approvals: [],
|
|
2235
|
+
fee: context.fee,
|
|
2236
|
+
warnings: [],
|
|
2237
|
+
verifiability: "opaque",
|
|
2238
|
+
blind: "account-code",
|
|
2239
|
+
...contract
|
|
2240
|
+
};
|
|
2241
|
+
const protocol = protocolIntent(call, context);
|
|
2242
|
+
if (protocol !== void 0) return labelFiat24Spenders({
|
|
2243
|
+
...protocol,
|
|
2244
|
+
...contract
|
|
2245
|
+
}, networkChainId(context.network));
|
|
2246
|
+
const standard = standardIntent(call, context);
|
|
2247
|
+
const nearMiss = standard.verifiability === "opaque" && call.to !== void 0 ? callNearMiss(call.to, networkChainId(context.network), context.table, call.data) : void 0;
|
|
2248
|
+
return labelFiat24Spenders({
|
|
2249
|
+
...standard,
|
|
2250
|
+
...contract,
|
|
2251
|
+
...nearMiss === void 0 ? {} : { blind: nearMiss },
|
|
2252
|
+
outflows: call.value > 0n && address !== void 0 ? [...nativeOutflow(call.value, address), ...standard.outflows] : standard.outflows
|
|
2253
|
+
}, networkChainId(context.network));
|
|
2254
|
+
};
|
|
2255
|
+
/** The delegation field a request carries, present iff the transaction is eip7702. */
|
|
2256
|
+
const delegationOf = (tx) => {
|
|
2257
|
+
if (tx.type !== "eip7702") return;
|
|
2258
|
+
return tx.authorization.address === "0x0000000000000000000000000000000000000000" ? { kind: "revoke" } : {
|
|
2259
|
+
kind: "set",
|
|
2260
|
+
delegator: EVM_DELEGATOR.address,
|
|
2261
|
+
name: EVM_DELEGATOR.name,
|
|
2262
|
+
version: EVM_DELEGATOR.version
|
|
2263
|
+
};
|
|
2264
|
+
};
|
|
2265
|
+
const weakest = (intents) => intents.some((i) => i.verifiability === "opaque") ? "opaque" : intents.some((i) => i.verifiability === "partial") ? "partial" : "full";
|
|
2266
|
+
/** The address a contract creation from `signer` at `nonce` deploys to (CREATE). */
|
|
2267
|
+
const createdAddress = (signer, nonce) => {
|
|
2268
|
+
assertHex(signer, "signer");
|
|
2269
|
+
return checksumEvmAddress(ContractAddress.fromCreate({
|
|
2270
|
+
from: signer,
|
|
2271
|
+
nonce: BigInt(nonce)
|
|
2272
|
+
}));
|
|
2273
|
+
};
|
|
2274
|
+
const decodeTransaction = (request, signer, table) => {
|
|
612
2275
|
const { tx } = request;
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
2276
|
+
const fee = { max: weiAmount(feeWei(tx)) };
|
|
2277
|
+
const delegation = delegationOf(tx);
|
|
2278
|
+
const isSelf = tx.to !== void 0 && tx.to.toLowerCase() === signer.toLowerCase() && BigInt(tx.value) === 0n;
|
|
2279
|
+
if (isSelf && tx.data === "0x") return {
|
|
2280
|
+
family: "evm",
|
|
2281
|
+
network: request.network,
|
|
2282
|
+
outflows: [],
|
|
2283
|
+
approvals: [],
|
|
2284
|
+
fee,
|
|
2285
|
+
warnings: [],
|
|
2286
|
+
verifiability: "full",
|
|
2287
|
+
...delegation === void 0 ? {} : { delegation },
|
|
2288
|
+
summary: tx.type === "eip7702" ? "authorization" : "transfer"
|
|
2289
|
+
};
|
|
2290
|
+
const calls = isSelf ? decodeBatchExecute(tx.data) : void 0;
|
|
2291
|
+
const context = {
|
|
2292
|
+
network: request.network,
|
|
2293
|
+
table,
|
|
2294
|
+
signer,
|
|
2295
|
+
self: signer
|
|
2296
|
+
};
|
|
2297
|
+
if (calls !== void 0 && calls.length > 0) {
|
|
2298
|
+
const decoded = calls.map((call) => decodeCall(call, {
|
|
2299
|
+
...context,
|
|
2300
|
+
fee: void 0
|
|
2301
|
+
}));
|
|
2302
|
+
const minimumReceived = decoded.flatMap((d) => d.minimumReceived ?? []);
|
|
2303
|
+
const staking = decoded.flatMap((d) => d.staking ?? []);
|
|
2304
|
+
const blind = decoded.find((call) => call.blind !== void 0)?.blind;
|
|
2305
|
+
return {
|
|
2306
|
+
family: "evm",
|
|
2307
|
+
network: request.network,
|
|
2308
|
+
warnings: decoded.flatMap((d) => d.warnings),
|
|
2309
|
+
fee,
|
|
2310
|
+
summary: "batch",
|
|
2311
|
+
calls: decoded,
|
|
2312
|
+
outflows: decoded.flatMap((d) => d.outflows),
|
|
2313
|
+
approvals: decoded.flatMap((d) => d.approvals),
|
|
2314
|
+
...staking.length === 0 ? {} : { staking },
|
|
2315
|
+
...minimumReceived.length === 0 ? {} : { minimumReceived },
|
|
2316
|
+
verifiability: weakest(decoded),
|
|
2317
|
+
...blind === void 0 ? {} : { blind },
|
|
2318
|
+
...delegation === void 0 ? {} : { delegation }
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
return {
|
|
2322
|
+
...decodeCall({
|
|
2323
|
+
to: tx.to,
|
|
2324
|
+
...tx.to === void 0 ? { created: createdAddress(signer, tx.nonce) } : {},
|
|
2325
|
+
value: quantityBigInt(tx.value, "tx.value"),
|
|
2326
|
+
data: tx.data
|
|
2327
|
+
}, {
|
|
2328
|
+
...context,
|
|
2329
|
+
fee
|
|
2330
|
+
}),
|
|
2331
|
+
...delegation === void 0 ? {} : { delegation }
|
|
2332
|
+
};
|
|
618
2333
|
};
|
|
619
2334
|
/** The five EIP-712 domain fields a wallet shows; anything malformed is left out. */
|
|
620
2335
|
const displayDomain = (domain) => {
|
|
@@ -628,77 +2343,135 @@ const displayDomain = (domain) => {
|
|
|
628
2343
|
...typeof salt === "string" ? { salt } : {}
|
|
629
2344
|
};
|
|
630
2345
|
};
|
|
631
|
-
/**
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
signIn
|
|
643
|
-
};
|
|
644
|
-
} catch {
|
|
645
|
-
return {
|
|
646
|
-
kind: "bytes",
|
|
647
|
-
hex: `0x${[...bytes].map((b) => b.toString(16).padStart(2, "0")).join("")}`
|
|
648
|
-
};
|
|
649
|
-
}
|
|
2346
|
+
/**
|
|
2347
|
+
* The blind reason for a typed-data request, if any. Shown content is never truncated — an order
|
|
2348
|
+
* with more items than the prompt lists, or a document over the leaf budget, would silently
|
|
2349
|
+
* authorise what it hides, so it blinds the request instead. `unclaimed` is the blind the caller
|
|
2350
|
+
* computed for a document no recognised family decoded.
|
|
2351
|
+
*/
|
|
2352
|
+
const typedDataBlind = (safe, seaport, app, unclaimed) => {
|
|
2353
|
+
if (safe !== void 0) return safe.safe.calls.find((call) => call.blind !== void 0)?.blind ?? (safe.safe.refund === void 0 ? void 0 : "safe-refund-unbounded");
|
|
2354
|
+
if (seaport !== void 0) return seaport.offer.length > 8 || seaport.consideration.length > 8 ? "typed-data-oversize" : void 0;
|
|
2355
|
+
if (app !== void 0) return app.blind;
|
|
2356
|
+
return unclaimed;
|
|
650
2357
|
};
|
|
651
2358
|
/** What the signer can guarantee about this request (WD-065). */
|
|
652
|
-
const verifiabilityEvm = (request) => decodeEvm(request).verifiability;
|
|
2359
|
+
const verifiabilityEvm = (request, signer) => decodeEvm(request, signer).verifiability;
|
|
653
2360
|
/**
|
|
654
|
-
* Decodes a normalized request into a DisplayIntent.
|
|
655
|
-
*
|
|
2361
|
+
* Decodes a normalized request into a DisplayIntent. `signer` is the address of the signing
|
|
2362
|
+
* account; the token table parameter is for tests.
|
|
656
2363
|
*/
|
|
657
|
-
const decodeEvm = (request, table = evmTokenTable) => {
|
|
658
|
-
if (request.kind === "evm.transaction") return decodeTransaction(request, table);
|
|
659
|
-
if (request.kind === "evm.personal-message")
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
2364
|
+
const decodeEvm = (request, signer, table = evmTokenTable) => {
|
|
2365
|
+
if (request.kind === "evm.transaction") return withNativeAmountMeta(decodeTransaction(request, signer, table), request.network, EVM_NATIVE_ASSET, 18);
|
|
2366
|
+
if (request.kind === "evm.personal-message") {
|
|
2367
|
+
const content = messageContent(request.message, "evm");
|
|
2368
|
+
const blind = (content.kind === "text" ? personalMessageNearMiss(content.text) : void 0) ?? messageBlindReason(content);
|
|
2369
|
+
return {
|
|
2370
|
+
family: "evm",
|
|
2371
|
+
network: request.network,
|
|
2372
|
+
summary: "message",
|
|
2373
|
+
outflows: [],
|
|
2374
|
+
approvals: [],
|
|
2375
|
+
fee: void 0,
|
|
2376
|
+
warnings: [],
|
|
2377
|
+
message: content,
|
|
2378
|
+
verifiability: "opaque",
|
|
2379
|
+
...blind === void 0 ? {} : { blind }
|
|
2380
|
+
};
|
|
2381
|
+
}
|
|
2382
|
+
if (request.kind === "evm.fiat24-session") {
|
|
2383
|
+
const chainId = networkChainId(request.network);
|
|
2384
|
+
return {
|
|
2385
|
+
family: "evm",
|
|
2386
|
+
network: request.network,
|
|
2387
|
+
summary: "message",
|
|
2388
|
+
outflows: [],
|
|
2389
|
+
approvals: [],
|
|
2390
|
+
fee: void 0,
|
|
2391
|
+
warnings: [],
|
|
2392
|
+
message: {
|
|
2393
|
+
kind: "text",
|
|
2394
|
+
text: fiat24SessionMessage(chainId, request.tokenId, request.deadline)
|
|
2395
|
+
},
|
|
2396
|
+
fiat24: {
|
|
2397
|
+
kind: "session-grant",
|
|
2398
|
+
account: request.tokenId,
|
|
2399
|
+
deadline: request.deadline
|
|
2400
|
+
},
|
|
2401
|
+
verifiability: "partial"
|
|
2402
|
+
};
|
|
2403
|
+
}
|
|
670
2404
|
if (request.kind !== "evm.typed-data") throw new ChainError("unsupported", `unsupported sign request kind: ${request.kind}`);
|
|
671
2405
|
const { json } = parseTypedData(request.typedData);
|
|
2406
|
+
assertNoExecutionGrant(json.domain, signer);
|
|
672
2407
|
const chainId = networkChainId(request.network);
|
|
673
|
-
const permit = recognizePermit(json, chainId, table);
|
|
674
|
-
const
|
|
675
|
-
const
|
|
2408
|
+
const permit = recognizePermit(json, chainId, table, signer);
|
|
2409
|
+
const claimed = permit === void 0 ? recognizeEip3009(json, chainId, table, signer) ?? recognizeAuthority(json, chainId, table, signer) ?? recognizeFarcaster(json, chainId, signer) : void 0;
|
|
2410
|
+
const seaport = permit === void 0 && claimed === void 0 ? recognizeSeaport(json, chainId, table) : void 0;
|
|
2411
|
+
const safe = permit === void 0 && claimed === void 0 && seaport === void 0 ? recognizeSafe(json, {
|
|
2412
|
+
network: request.network,
|
|
2413
|
+
chainId,
|
|
2414
|
+
table
|
|
2415
|
+
}, (call, safeAddress) => decodeCall(call, {
|
|
2416
|
+
network: request.network,
|
|
2417
|
+
fee: void 0,
|
|
2418
|
+
table,
|
|
2419
|
+
signer,
|
|
2420
|
+
self: safeAddress
|
|
2421
|
+
})) : void 0;
|
|
2422
|
+
const app = permit === void 0 && claimed === void 0 && seaport === void 0 && safe === void 0 ? recognizeApp(json, {
|
|
2423
|
+
network: request.network,
|
|
2424
|
+
chainId,
|
|
2425
|
+
table,
|
|
2426
|
+
signer
|
|
2427
|
+
}, (call, self) => decodeCall(call, {
|
|
2428
|
+
network: request.network,
|
|
2429
|
+
fee: void 0,
|
|
2430
|
+
table,
|
|
2431
|
+
signer,
|
|
2432
|
+
self
|
|
2433
|
+
})) : void 0;
|
|
2434
|
+
const order = permit === void 0 && claimed === void 0 ? seaport === void 0 && safe === void 0 && app === void 0 ? recognizeCow(json, chainId, signer, table) ?? recognizeOneinch(json, chainId, table) : void 0 : permit?.order;
|
|
2435
|
+
const snapshot = permit === void 0 && claimed === void 0 && seaport === void 0 && safe === void 0 && app === void 0 && order === void 0 ? recognizeSnapshot(json, signer) : void 0;
|
|
2436
|
+
const unclaimed = permit === void 0 && claimed === void 0 && seaport === void 0 && safe === void 0 && app === void 0 && order === void 0 && snapshot === void 0;
|
|
2437
|
+
const recognized = claimed ?? (snapshot?.kind === "alias" ? snapshot : void 0);
|
|
2438
|
+
const nearMiss = unclaimed ? typedDataNearMiss(json, chainId, table) : void 0;
|
|
2439
|
+
const shown = unclaimed || snapshot?.kind === "vote" ? typedDataFields(json) : void 0;
|
|
2440
|
+
const fields = shown?.fields;
|
|
2441
|
+
const unclaimedBlind = nearMiss ?? (unclaimed || snapshot?.kind === "vote" ? shown === void 0 ? "typed-data-oversize" : unclaimed && shown.hasCommitment ? "typed-data-commitment" : void 0 : void 0);
|
|
2442
|
+
const blind = permit?.blind ?? typedDataBlind(safe, seaport, app, unclaimedBlind) ?? (typedDataHasHiddenText(json) ? "message-bytes" : void 0);
|
|
676
2443
|
const message = {
|
|
677
2444
|
kind: "typed-data",
|
|
678
2445
|
primaryType: json.primaryType,
|
|
679
2446
|
domain: displayDomain(json.domain),
|
|
680
2447
|
data: json.message,
|
|
681
2448
|
...seaport === void 0 ? {} : { seaport },
|
|
682
|
-
...
|
|
2449
|
+
...order === void 0 ? {} : { order },
|
|
2450
|
+
...safe === void 0 ? {} : { safe: safe.safe },
|
|
2451
|
+
...app === void 0 ? {} : app.content,
|
|
2452
|
+
...recognized === void 0 ? {} : recognized.content,
|
|
2453
|
+
...fields === void 0 ? {} : { fields },
|
|
2454
|
+
...permit?.fields === void 0 ? {} : { fields: permit.fields }
|
|
683
2455
|
};
|
|
684
|
-
const summary = seaport
|
|
685
|
-
return {
|
|
2456
|
+
const summary = recognized?.summary ?? (order !== void 0 || seaport !== void 0 ? "swap" : safe === void 0 ? permit === void 0 ? app?.summary ?? "message" : "approve" : safe.multisend ? "batch" : safe.safe.calls[0]?.summary ?? "contract-call");
|
|
2457
|
+
return withNativeAmountMeta({
|
|
686
2458
|
family: "evm",
|
|
687
2459
|
network: request.network,
|
|
688
2460
|
summary,
|
|
689
|
-
outflows: [],
|
|
690
|
-
approvals: permit?.approvals ?? [],
|
|
2461
|
+
outflows: recognized?.outflows ?? app?.outflows ?? [],
|
|
2462
|
+
approvals: permit?.approvals ?? app?.approvals ?? [],
|
|
691
2463
|
fee: void 0,
|
|
692
|
-
warnings: permit?.warnings ?? [],
|
|
2464
|
+
warnings: permit?.warnings ?? app?.warnings ?? [],
|
|
693
2465
|
message,
|
|
694
|
-
verifiability: permit === void 0 ? "opaque" : "partial"
|
|
695
|
-
|
|
2466
|
+
verifiability: recognized?.verifiability ?? app?.verifiability ?? (permit === void 0 && order === void 0 ? "opaque" : "partial"),
|
|
2467
|
+
...blind === void 0 ? {} : { blind }
|
|
2468
|
+
}, request.network, EVM_NATIVE_ASSET, 18);
|
|
696
2469
|
};
|
|
697
2470
|
// src/evm/recover.ts
|
|
698
2471
|
/**
|
|
699
|
-
* Signer recovery for `chain.sign` results: the host re-derives the signer address
|
|
700
|
-
*
|
|
701
|
-
* kernel returning someone else's signature fails closed.
|
|
2472
|
+
* Signer recovery for `chain.sign` results: the host re-derives the signer address of the requested
|
|
2473
|
+
* transaction, message or typed data and compares it with the account's `wallet.accounts` address —
|
|
2474
|
+
* a kernel returning someone else's signature, or a signature over other content, fails closed.
|
|
702
2475
|
*/
|
|
703
2476
|
function assertEip1559Hex(hex) {
|
|
704
2477
|
if (!hex.startsWith("0x02")) throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
|
|
@@ -706,6 +2479,9 @@ function assertEip1559Hex(hex) {
|
|
|
706
2479
|
function assertEip2930Hex(hex) {
|
|
707
2480
|
if (!hex.startsWith("0x01")) throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
|
|
708
2481
|
}
|
|
2482
|
+
function assertEip7702Hex(hex) {
|
|
2483
|
+
if (!hex.startsWith("0x04")) throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
|
|
2484
|
+
}
|
|
709
2485
|
const signatureOf = (env) => {
|
|
710
2486
|
const { r, s, yParity } = env;
|
|
711
2487
|
if (r === void 0 || s === void 0 || yParity === void 0) throw new ChainError("invalid-request", "envelope carries no signature");
|
|
@@ -715,47 +2491,66 @@ const signatureOf = (env) => {
|
|
|
715
2491
|
yParity
|
|
716
2492
|
});
|
|
717
2493
|
};
|
|
718
|
-
/**
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
2494
|
+
/**
|
|
2495
|
+
* The transaction signature and, for EIP-7702, the authorization signature a signed envelope
|
|
2496
|
+
* carries.
|
|
2497
|
+
*/
|
|
2498
|
+
const signaturesOf = (hex) => {
|
|
2499
|
+
if (hex.startsWith("0x04")) {
|
|
2500
|
+
assertEip7702Hex(hex);
|
|
2501
|
+
const env = TxEnvelopeEip7702.deserialize(hex);
|
|
2502
|
+
const auths = env.authorizationList ?? [];
|
|
2503
|
+
const [auth] = auths;
|
|
2504
|
+
if (auths.length !== 1 || auth === void 0) throw new ChainError("invalid-request", "authorization does not match the request");
|
|
2505
|
+
return {
|
|
2506
|
+
signature: signatureOf(env),
|
|
2507
|
+
authorization: Signature.from(auth)
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
if (hex.startsWith("0x02")) {
|
|
723
2511
|
assertEip1559Hex(hex);
|
|
724
|
-
|
|
725
|
-
const payload = TxEnvelopeEip1559.getSignPayload(env);
|
|
726
|
-
return Secp256k1.recoverAddress({
|
|
727
|
-
payload,
|
|
728
|
-
signature: signatureOf(env)
|
|
729
|
-
});
|
|
2512
|
+
return { signature: signatureOf(TxEnvelopeEip1559.deserialize(hex)) };
|
|
730
2513
|
}
|
|
731
|
-
if (
|
|
2514
|
+
if (hex.startsWith("0x01")) {
|
|
732
2515
|
assertEip2930Hex(hex);
|
|
733
|
-
|
|
734
|
-
const payload = TxEnvelopeEip2930.getSignPayload(env);
|
|
735
|
-
return Secp256k1.recoverAddress({
|
|
736
|
-
payload,
|
|
737
|
-
signature: signatureOf(env)
|
|
738
|
-
});
|
|
2516
|
+
return { signature: signatureOf(TxEnvelopeEip2930.deserialize(hex)) };
|
|
739
2517
|
}
|
|
740
2518
|
try {
|
|
741
|
-
|
|
742
|
-
const payload = TxEnvelopeLegacy.getSignPayload(env);
|
|
743
|
-
return Secp256k1.recoverAddress({
|
|
744
|
-
payload,
|
|
745
|
-
signature: signatureOf(env)
|
|
746
|
-
});
|
|
2519
|
+
return { signature: signatureOf(TxEnvelopeLegacy.deserialize(hex)) };
|
|
747
2520
|
} catch {
|
|
748
2521
|
throw new ChainError("invalid-request", "unrecognized signed transaction envelope");
|
|
749
2522
|
}
|
|
750
2523
|
};
|
|
751
2524
|
/**
|
|
2525
|
+
* The signer of `signedTransaction`, which must be exactly `request.tx` under its signature: the
|
|
2526
|
+
* envelope is rebuilt from the request, re-serialized with the returned signatures and compared
|
|
2527
|
+
* byte for byte, so a valid signature by the account over any other transaction is refused.
|
|
2528
|
+
*/
|
|
2529
|
+
const signerFromEnvelope = (signedTransaction, request) => {
|
|
2530
|
+
const hex = Hex.fromBytes(signedTransaction);
|
|
2531
|
+
const { signature, authorization } = signaturesOf(hex);
|
|
2532
|
+
const expected = evmEnvelope(request.tx, authorization);
|
|
2533
|
+
if (expected.serialize(signature).toLowerCase() !== hex) throw new ChainError("invalid-request", "the signed transaction does not match the request");
|
|
2534
|
+
const signer = Secp256k1.recoverAddress({
|
|
2535
|
+
payload: expected.payload,
|
|
2536
|
+
signature
|
|
2537
|
+
});
|
|
2538
|
+
if (request.tx.type === "eip7702" && authorization !== void 0) {
|
|
2539
|
+
if (Secp256k1.recoverAddress({
|
|
2540
|
+
payload: Authorization.getSignPayload(evmAuthorization(request.tx)),
|
|
2541
|
+
signature: authorization
|
|
2542
|
+
}).toLowerCase() !== signer.toLowerCase()) throw new ChainError("invalid-request", "authorization signer is not the account");
|
|
2543
|
+
}
|
|
2544
|
+
return signer;
|
|
2545
|
+
};
|
|
2546
|
+
/**
|
|
752
2547
|
* The EIP-55 address that produced `result` for `request` — a `chain.sign` round-trip check
|
|
753
2548
|
* (`{kind:"evm.transaction",signedTransaction}` | `{kind,signature}`).
|
|
754
2549
|
*/
|
|
755
2550
|
const recoverEvmSigner = (request, result) => {
|
|
756
2551
|
if (request.kind === "evm.transaction") {
|
|
757
2552
|
if (result.signedTransaction === void 0) throw new ChainError("invalid-request", "expected a signed transaction");
|
|
758
|
-
return signerFromEnvelope(result.signedTransaction);
|
|
2553
|
+
return signerFromEnvelope(result.signedTransaction, request);
|
|
759
2554
|
}
|
|
760
2555
|
if (result.signature === void 0 || result.signature.length !== 65) throw new ChainError("invalid-request", "expected a 65-byte signature");
|
|
761
2556
|
const signature = Signature.from(result.signature);
|
|
@@ -766,6 +2561,14 @@ const recoverEvmSigner = (request, result) => {
|
|
|
766
2561
|
signature
|
|
767
2562
|
});
|
|
768
2563
|
}
|
|
2564
|
+
if (request.kind === "evm.fiat24-session") {
|
|
2565
|
+
const message = fiat24SessionMessage(networkChainId(request.network), request.tokenId, request.deadline);
|
|
2566
|
+
const payload = PersonalMessage.getSignPayload(Hex.fromBytes(utf8ToBytes(message)));
|
|
2567
|
+
return Secp256k1.recoverAddress({
|
|
2568
|
+
payload,
|
|
2569
|
+
signature
|
|
2570
|
+
});
|
|
2571
|
+
}
|
|
769
2572
|
if (request.kind === "evm.typed-data") {
|
|
770
2573
|
const { json } = parseTypedData(request.typedData);
|
|
771
2574
|
const payload = TypedData.getSignPayload(json);
|
|
@@ -776,6 +2579,202 @@ const recoverEvmSigner = (request, result) => {
|
|
|
776
2579
|
}
|
|
777
2580
|
throw new ChainError("unsupported", `cannot recover a signer for ${request.kind}`);
|
|
778
2581
|
};
|
|
2582
|
+
// src/evm/msgpack.ts
|
|
2583
|
+
const utf8 = new TextEncoder();
|
|
2584
|
+
function concat(...chunks) {
|
|
2585
|
+
let length = 0;
|
|
2586
|
+
for (const chunk of chunks) length += chunk.length;
|
|
2587
|
+
const out = new Uint8Array(length);
|
|
2588
|
+
let offset = 0;
|
|
2589
|
+
for (const chunk of chunks) {
|
|
2590
|
+
out.set(chunk, offset);
|
|
2591
|
+
offset += chunk.length;
|
|
2592
|
+
}
|
|
2593
|
+
return out;
|
|
2594
|
+
}
|
|
2595
|
+
const u16be = (value) => {
|
|
2596
|
+
const out = /* @__PURE__ */ new Uint8Array(2);
|
|
2597
|
+
new DataView(out.buffer).setUint16(0, value);
|
|
2598
|
+
return out;
|
|
2599
|
+
};
|
|
2600
|
+
const u32be = (value) => {
|
|
2601
|
+
const out = /* @__PURE__ */ new Uint8Array(4);
|
|
2602
|
+
new DataView(out.buffer).setUint32(0, value);
|
|
2603
|
+
return out;
|
|
2604
|
+
};
|
|
2605
|
+
const i64be = (value) => {
|
|
2606
|
+
const out = /* @__PURE__ */ new Uint8Array(8);
|
|
2607
|
+
new DataView(out.buffer).setBigInt64(0, value);
|
|
2608
|
+
return out;
|
|
2609
|
+
};
|
|
2610
|
+
const u64be = (value) => {
|
|
2611
|
+
const out = /* @__PURE__ */ new Uint8Array(8);
|
|
2612
|
+
new DataView(out.buffer).setBigUint64(0, value);
|
|
2613
|
+
return out;
|
|
2614
|
+
};
|
|
2615
|
+
/** Safe integers only — the L1 schemas bound every numeric field well inside them. */
|
|
2616
|
+
function packInt(value) {
|
|
2617
|
+
if (!Number.isSafeInteger(value)) throw new ChainError("invalid-request", "unreachable: non-integer msgpack field");
|
|
2618
|
+
if (value >= 0) {
|
|
2619
|
+
if (value <= 127) return new Uint8Array([value]);
|
|
2620
|
+
if (value <= 255) return new Uint8Array([204, value]);
|
|
2621
|
+
if (value <= 65535) return concat(new Uint8Array([205]), u16be(value));
|
|
2622
|
+
if (value <= 4294967295) return concat(new Uint8Array([206]), u32be(value));
|
|
2623
|
+
return concat(new Uint8Array([207]), u64be(BigInt(value)));
|
|
2624
|
+
}
|
|
2625
|
+
if (value >= -32) return new Uint8Array([value + 256]);
|
|
2626
|
+
if (value >= -128) return new Uint8Array([208, value + 256]);
|
|
2627
|
+
if (value >= -32768) return concat(new Uint8Array([209]), u16be(value + 65536));
|
|
2628
|
+
if (value >= -2147483648) return concat(new Uint8Array([210]), u32be(value + 4294967296));
|
|
2629
|
+
return concat(new Uint8Array([211]), i64be(BigInt(value)));
|
|
2630
|
+
}
|
|
2631
|
+
function packStr(value) {
|
|
2632
|
+
const bytes = utf8.encode(value);
|
|
2633
|
+
const { length } = bytes;
|
|
2634
|
+
if (length < 32) return concat(new Uint8Array([160 | length]), bytes);
|
|
2635
|
+
if (length < 256) return concat(new Uint8Array([217, length]), bytes);
|
|
2636
|
+
if (length < 65536) return concat(new Uint8Array([218]), u16be(length), bytes);
|
|
2637
|
+
return concat(new Uint8Array([219]), u32be(length), bytes);
|
|
2638
|
+
}
|
|
2639
|
+
function packBool(value) {
|
|
2640
|
+
return new Uint8Array([value ? 195 : 194]);
|
|
2641
|
+
}
|
|
2642
|
+
function packArray(items) {
|
|
2643
|
+
return concat(items.length < 16 ? new Uint8Array([144 | items.length]) : items.length < 65536 ? concat(new Uint8Array([220]), u16be(items.length)) : (() => {
|
|
2644
|
+
throw new ChainError("invalid-request", "unreachable: msgpack array over 65535 items");
|
|
2645
|
+
})(), ...items);
|
|
2646
|
+
}
|
|
2647
|
+
function packMap(entries) {
|
|
2648
|
+
return concat(entries.length < 16 ? new Uint8Array([128 | entries.length]) : entries.length < 65536 ? concat(new Uint8Array([222]), u16be(entries.length)) : (() => {
|
|
2649
|
+
throw new ChainError("invalid-request", "unreachable: msgpack map over 65535 entries");
|
|
2650
|
+
})(), ...entries.flatMap(([key, value]) => [packStr(key), value]));
|
|
2651
|
+
}
|
|
2652
|
+
// src/evm/hyperliquid-l1.ts
|
|
2653
|
+
/** The order-wire map, H2-T order: a,b,p,s,r,t,c? — `c` only when present. */
|
|
2654
|
+
const orderWire = (order) => {
|
|
2655
|
+
const t = "limit" in order.t ? packMap([["limit", packMap([["tif", packStr(order.t.limit.tif)]])]]) : packMap([["trigger", packMap([
|
|
2656
|
+
["isMarket", packBool(order.t.trigger.isMarket)],
|
|
2657
|
+
["triggerPx", packStr(order.t.trigger.triggerPx)],
|
|
2658
|
+
["tpsl", packStr(order.t.trigger.tpsl)]
|
|
2659
|
+
])]]);
|
|
2660
|
+
const entries = [
|
|
2661
|
+
["a", packInt(order.a)],
|
|
2662
|
+
["b", packBool(order.b)],
|
|
2663
|
+
["p", packStr(order.p)],
|
|
2664
|
+
["s", packStr(order.s)],
|
|
2665
|
+
["r", packBool(order.r)],
|
|
2666
|
+
["t", t]
|
|
2667
|
+
];
|
|
2668
|
+
if (order.c !== void 0) entries.push(["c", packStr(order.c)]);
|
|
2669
|
+
return packMap(entries);
|
|
2670
|
+
};
|
|
2671
|
+
const packOid = (oid) => typeof oid === "number" ? packInt(oid) : packStr(oid);
|
|
2672
|
+
const optFlag = (entries, key, flag) => {
|
|
2673
|
+
if (flag !== void 0) entries.push([key, packBool(flag)]);
|
|
2674
|
+
return packMap(entries);
|
|
2675
|
+
};
|
|
2676
|
+
function encodeL1Action(action) {
|
|
2677
|
+
switch (action.type) {
|
|
2678
|
+
case "order": {
|
|
2679
|
+
const entries = [
|
|
2680
|
+
["type", packStr("order")],
|
|
2681
|
+
["orders", packArray(action.orders.map(orderWire))],
|
|
2682
|
+
["grouping", packStr(action.grouping)]
|
|
2683
|
+
];
|
|
2684
|
+
if (action.builder !== void 0) entries.push(["builder", packMap([["b", packStr(action.builder.b)], ["f", packInt(action.builder.f)]])]);
|
|
2685
|
+
return packMap(entries);
|
|
2686
|
+
}
|
|
2687
|
+
case "cancel": {
|
|
2688
|
+
const entries = [["type", packStr("cancel")], ["cancels", packArray(action.cancels.map((cancel) => packMap([["a", packInt(cancel.a)], ["o", packInt(cancel.o)]])))]];
|
|
2689
|
+
return optFlag(entries, "f", action.f);
|
|
2690
|
+
}
|
|
2691
|
+
case "cancelByCloid": {
|
|
2692
|
+
const entries = [["type", packStr("cancelByCloid")], ["cancels", packArray(action.cancels.map((cancel) => packMap([["asset", packInt(cancel.asset)], ["cloid", packStr(cancel.cloid)]])))]];
|
|
2693
|
+
return optFlag(entries, "f", action.f);
|
|
2694
|
+
}
|
|
2695
|
+
case "modify": {
|
|
2696
|
+
const entries = [
|
|
2697
|
+
["type", packStr("modify")],
|
|
2698
|
+
["oid", packOid(action.oid)],
|
|
2699
|
+
["order", orderWire(action.order)]
|
|
2700
|
+
];
|
|
2701
|
+
return optFlag(entries, "a", action.a);
|
|
2702
|
+
}
|
|
2703
|
+
case "batchModify": {
|
|
2704
|
+
const entries = [["type", packStr("batchModify")], ["modifies", packArray(action.modifies.map((modify) => packMap([["oid", packOid(modify.oid)], ["order", orderWire(modify.order)]])))]];
|
|
2705
|
+
return optFlag(entries, "a", action.a);
|
|
2706
|
+
}
|
|
2707
|
+
case "updateLeverage": return packMap([
|
|
2708
|
+
["type", packStr("updateLeverage")],
|
|
2709
|
+
["asset", packInt(action.asset)],
|
|
2710
|
+
["isCross", packBool(action.isCross)],
|
|
2711
|
+
["leverage", packInt(action.leverage)]
|
|
2712
|
+
]);
|
|
2713
|
+
case "updateIsolatedMargin": return packMap([
|
|
2714
|
+
["type", packStr("updateIsolatedMargin")],
|
|
2715
|
+
["asset", packInt(action.asset)],
|
|
2716
|
+
["isBuy", packBool(action.isBuy)],
|
|
2717
|
+
["ntli", packInt(action.ntli)]
|
|
2718
|
+
]);
|
|
2719
|
+
case "twapCancel": return packMap([
|
|
2720
|
+
["type", packStr("twapCancel")],
|
|
2721
|
+
["a", packInt(action.a)],
|
|
2722
|
+
["t", packInt(action.t)]
|
|
2723
|
+
]);
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
function l1ConnectionId(args) {
|
|
2727
|
+
const packed = encodeL1Action(args.action);
|
|
2728
|
+
const vault = args.vaultAddress === void 0 ? new Uint8Array([0]) : concat(new Uint8Array([1]), hexToBytes(args.vaultAddress.slice(2)));
|
|
2729
|
+
const expiry = args.expiresAfter === void 0 ? /* @__PURE__ */ new Uint8Array(0) : concat(new Uint8Array([0]), u64be(BigInt(args.expiresAfter)));
|
|
2730
|
+
return keccak_256(concat(packed, u64be(BigInt(args.nonce)), vault, expiry));
|
|
2731
|
+
}
|
|
2732
|
+
function phantomAgentTypedData(connectionId, network) {
|
|
2733
|
+
return JSON.stringify({
|
|
2734
|
+
types: {
|
|
2735
|
+
EIP712Domain: [
|
|
2736
|
+
{
|
|
2737
|
+
name: "name",
|
|
2738
|
+
type: "string"
|
|
2739
|
+
},
|
|
2740
|
+
{
|
|
2741
|
+
name: "version",
|
|
2742
|
+
type: "string"
|
|
2743
|
+
},
|
|
2744
|
+
{
|
|
2745
|
+
name: "chainId",
|
|
2746
|
+
type: "uint256"
|
|
2747
|
+
},
|
|
2748
|
+
{
|
|
2749
|
+
name: "verifyingContract",
|
|
2750
|
+
type: "address"
|
|
2751
|
+
}
|
|
2752
|
+
],
|
|
2753
|
+
Agent: [{
|
|
2754
|
+
name: "source",
|
|
2755
|
+
type: "string"
|
|
2756
|
+
}, {
|
|
2757
|
+
name: "connectionId",
|
|
2758
|
+
type: "bytes32"
|
|
2759
|
+
}]
|
|
2760
|
+
},
|
|
2761
|
+
primaryType: "Agent",
|
|
2762
|
+
domain: {
|
|
2763
|
+
name: "Exchange",
|
|
2764
|
+
version: "1",
|
|
2765
|
+
chainId: 1337,
|
|
2766
|
+
verifyingContract: "0x0000000000000000000000000000000000000000"
|
|
2767
|
+
},
|
|
2768
|
+
message: {
|
|
2769
|
+
source: network === "Mainnet" ? "a" : "b",
|
|
2770
|
+
connectionId: `0x${bytesToHex(connectionId)}`
|
|
2771
|
+
}
|
|
2772
|
+
});
|
|
2773
|
+
}
|
|
2774
|
+
/** The phantom-agent typed-data JSON an L1 `params` signs, shared by kernel and host. */
|
|
2775
|
+
function hyperliquidL1Document(params, network) {
|
|
2776
|
+
return phantomAgentTypedData(l1ConnectionId(params), network);
|
|
2777
|
+
}
|
|
779
2778
|
// src/evm/index.ts
|
|
780
2779
|
/**
|
|
781
2780
|
* Normalizes a SignRequest for the EVM family: exact key sets, chainId vs the CAIP-2 `network`,
|
|
@@ -805,6 +2804,19 @@ const normalizeEvm = (request) => {
|
|
|
805
2804
|
message
|
|
806
2805
|
};
|
|
807
2806
|
}
|
|
2807
|
+
if (request["kind"] === "evm.fiat24-session") {
|
|
2808
|
+
if (chainId !== 42161) throw new ChainError("unsupported", `fiat24 sessions exist only on eip155:${FIAT24_CHAIN}`);
|
|
2809
|
+
const { tokenId, deadline } = request;
|
|
2810
|
+
if (typeof tokenId !== "string" || !/^[1-9][0-9]*$/.test(tokenId) || BigInt(tokenId) > MAX_UINT256) throw new ChainError("invalid-request", "fiat24-session tokenId is not a canonical id");
|
|
2811
|
+
if (typeof deadline !== "number" || !Number.isSafeInteger(deadline) || deadline < 1) throw new ChainError("invalid-request", "fiat24-session deadline must be a positive integer");
|
|
2812
|
+
return {
|
|
2813
|
+
kind: "evm.fiat24-session",
|
|
2814
|
+
network,
|
|
2815
|
+
account,
|
|
2816
|
+
tokenId,
|
|
2817
|
+
deadline
|
|
2818
|
+
};
|
|
2819
|
+
}
|
|
808
2820
|
if (request["kind"] === "evm.typed-data") {
|
|
809
2821
|
const { typedData } = request;
|
|
810
2822
|
if (typeof typedData !== "string") throw new ChainError("invalid-request", "typed-data payload must be the JSON source string");
|
|
@@ -820,6 +2832,6 @@ const normalizeEvm = (request) => {
|
|
|
820
2832
|
}
|
|
821
2833
|
throw new ChainError("unsupported", `unsupported sign request kind: ${request["kind"]}`);
|
|
822
2834
|
};
|
|
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 };
|
|
2835
|
+
export { ACROSS_SPOKEPOOLS, ACROSS_WRAPPED_NATIVE, ALLOWANCE_HOLDER, CCTP_FORWARDERS, CCTP_MESSENGERS, CCTP_USDC, DELEGATION_MANAGER, ENTRY_POINT_V08, EVM_DELEGATION_PREFIX, EVM_DELEGATOR, EVM_NATIVE_ASSET, FIAT24_CHAIN, HYPERLIQUID_DOMAIN, LIDO_CHAIN, LIDO_QUEUE, LIDO_STETH, LIDO_WSTETH, MAX_UINT256, ORDER_ITEMS, PERMIT2_ADDRESS, SAFE_MULTISEND_CALL_ONLY, TYPED_FIELD_BUDGET, TYPED_FIELD_CODE_POINTS, ZEROX_CHAINS, assembleEvm, assertNoExecutionGrant, canonicalHex, checksumEvmAddress, decodeAcross, decodeBatchExecute, decodeEvm, decodeZeroX, encodeBatchExecute, evmAddressFromPublicKey, evmSigningPreimage, evmTokenTable, fiat24SessionMessage, hyperliquidL1Document, isCanonicalHex, isEvmAddress, isZeroExSettler, lookupEvmToken, networkChainId, normalizeEvm, normalizeEvmTransaction, parseTypedData, planEvm, recoverEvmSigner, typedDataFields, typedDataHashes, verifiabilityEvm };
|
|
824
2836
|
|
|
825
2837
|
//# sourceMappingURL=evm.mjs.map
|