@cleave-protocol/ai-sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -23,19 +23,1133 @@ __export(index_exports, {
23
23
  CleaveApiError: () => CleaveApiError,
24
24
  DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
25
25
  DEFAULT_TIMEOUT_MS: () => DEFAULT_TIMEOUT_MS,
26
+ checkGetGas: () => checkGetGas,
27
+ checkPlanSwap: () => checkPlanSwap,
26
28
  cleaveTools: () => cleaveTools,
27
29
  findToken: () => findToken,
28
30
  getGas: () => getGas,
29
31
  planSwap: () => planSwap,
32
+ screenGetGas: () => screenGetGas,
33
+ screenPlanSwap: () => screenPlanSwap,
30
34
  trackSwap: () => trackSwap
31
35
  });
32
36
  module.exports = __toCommonJS(index_exports);
33
37
 
34
38
  var import_ai = require("ai");
35
39
 
40
+ var import_sha3 = require("@noble/hashes/sha3");
41
+ var import_utils = require("@noble/hashes/utils");
42
+
43
+ var ALLOWLIST = {
44
+ "version": "2026-11-02.5",
45
+ "nativeSentinel": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
46
+ "acrossHandler": "0x0F7Ae28dE1C8532170AD4ee566B5801485c13a0E",
47
+ "referral": {
48
+ "sameChainBps": 0,
49
+ "crossChainBps": 1,
50
+ "stablecoinBps": 0
51
+ },
52
+ "gas": {
53
+ "factory": "0x129f934211510b8C0Ac0ef07366f5dba92477c36",
54
+ "feeRecipient": "0x94a58bf17B32521259F5Ce5A9aa27Ee4a056323B",
55
+ "swap": {
56
+ "template": "0x122d0a1e55d6Cd966c906AB27C4C74e7a3B9eD79",
57
+ "versionTag": "0x9744c579ec32e4534ef3d6f2e0b49f87a1a014cc10f07a491df0e2ad2272dcc4",
58
+ "initCodeHash": "0xc76e4cbffcdff814308300ace2e74aca62fff95bb80571c64768e66352297672"
59
+ },
60
+ "cross_chain": {
61
+ "template": "0x9484F3f4930C0eF1b573a7062BAfF37E451f9035",
62
+ "versionTag": "0x3ecb2a726296395d5f34da76ea67f3d19c3d2970e1d33a394f758a7fcc87a008",
63
+ "initCodeHash": "0x3a228bdeea8677d726e9ef8c8cf180f15bbfd119e3bd09caf2ce894668e12ede"
64
+ }
65
+ },
66
+ "chains": {
67
+ "1": {
68
+ "name": "Ethereum",
69
+ "usdc": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
70
+ "usdcDecimals": 6,
71
+ "wrappedNative": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
72
+ "nativeSymbol": "ETH",
73
+ "wrappedSymbol": "WETH",
74
+ "composer": "0x436Ac858fD25706a8380b8AFb38Bc7538B852409",
75
+ "houseReferrer": "0x69d3661ac6935a33D59b8A6964f0523182A5ae7d",
76
+ "stablecoins": [
77
+ "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
78
+ "0xdAC17F958D2ee523a2206206994597C13D831ec7"
79
+ ],
80
+ "stargateRailId": "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404",
81
+ "gasDeliveryShell": "0xed10296A4B2F4E51674E4dEdCA1f53Dd9e0259f4",
82
+ "gasPay": {
83
+ "routerV3": "0x30809f82f8Df91e976B02F09dc64E0da8eFB1e92",
84
+ "acrossUsdcAdapter": "0xdf88ef691b8eD60F61660fB5Ae937c405aB6415A",
85
+ "railId": "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916"
86
+ },
87
+ "targets": {
88
+ "0x016750b998AaB0b4b07AA6a2276335053A798758": {
89
+ "role": "swap_shell",
90
+ "selectors": {
91
+ "0xab33b1ec": "swapWithBlob"
92
+ }
93
+ },
94
+ "0x5AfF91027390f731058AcC15E0A3F927b250c9FE": {
95
+ "role": "measured_shell",
96
+ "selectors": {
97
+ "0xe0b7822f": "swapMeasuredWithBlobV1"
98
+ }
99
+ },
100
+ "0x30809f82f8Df91e976B02F09dc64E0da8eFB1e92": {
101
+ "role": "router_v3",
102
+ "selectors": {
103
+ "0x84022178": "crossChainSwap",
104
+ "0xf79eec2e": "crossChainSwapNative",
105
+ "0x9edd28ad": "bridgeToken"
106
+ }
107
+ },
108
+ "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2": {
109
+ "role": "wrapped_native",
110
+ "selectors": {
111
+ "0xd0e30db0": "deposit",
112
+ "0x2e1a7d4d": "withdraw"
113
+ }
114
+ },
115
+ "0x5c7BCd6E7De5423a257D81B442095A1a6ced35C5": {
116
+ "role": "across_spoke_pool",
117
+ "selectors": {
118
+ "0xad5425c6": "deposit"
119
+ }
120
+ },
121
+ "0x97CCDBea4632140639aD5eA9b944aa034eb15fD4": {
122
+ "role": "across_periphery_native_only",
123
+ "selectors": {
124
+ "0x609ea081": "depositNative"
125
+ }
126
+ }
127
+ },
128
+ "lanes": {
129
+ "10": {
130
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 10,
131
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 10,
132
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 10,
133
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 10,
134
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30111,
135
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 2
136
+ },
137
+ "56": {
138
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 56,
139
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 56,
140
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 56,
141
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30102
142
+ },
143
+ "137": {
144
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 137,
145
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 137,
146
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 137,
147
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 137,
148
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30109,
149
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 7
150
+ },
151
+ "8453": {
152
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 8453,
153
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 8453,
154
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 8453,
155
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30184,
156
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 6
157
+ },
158
+ "42161": {
159
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 42161,
160
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 42161,
161
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 42161,
162
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 42161,
163
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30110,
164
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 3
165
+ }
166
+ }
167
+ },
168
+ "10": {
169
+ "name": "Optimism",
170
+ "usdc": "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
171
+ "usdcDecimals": 6,
172
+ "wrappedNative": "0x4200000000000000000000000000000000000006",
173
+ "nativeSymbol": "ETH",
174
+ "wrappedSymbol": "WETH",
175
+ "composer": "0xAB708AEd94a07B9da06D92b4796988ee6eD0D32c",
176
+ "houseReferrer": "0x69d3661ac6935a33D59b8A6964f0523182A5ae7d",
177
+ "stablecoins": [
178
+ "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
179
+ "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58"
180
+ ],
181
+ "stargateRailId": "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404",
182
+ "gasDeliveryShell": "0xe46A542F395eB64d482BCf504c529cdb05D70878",
183
+ "gasPay": {
184
+ "routerV3": "0x34FCCA283211224877F89F814eeA0a3a912fd354",
185
+ "acrossUsdcAdapter": "0x28A4501fBb3d8A72Dc7A49Fbf262910d391659eE",
186
+ "railId": "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916"
187
+ },
188
+ "targets": {
189
+ "0xb08F28a3575805ee1E3729fc19Ab7E869CBAF563": {
190
+ "role": "swap_shell",
191
+ "selectors": {
192
+ "0xab33b1ec": "swapWithBlob"
193
+ }
194
+ },
195
+ "0x003d4C95756608Ed4C11C5d0Ad9ca4c4076cAF20": {
196
+ "role": "measured_shell",
197
+ "selectors": {
198
+ "0xe0b7822f": "swapMeasuredWithBlobV1"
199
+ }
200
+ },
201
+ "0x34FCCA283211224877F89F814eeA0a3a912fd354": {
202
+ "role": "router_v3",
203
+ "selectors": {
204
+ "0x84022178": "crossChainSwap",
205
+ "0xf79eec2e": "crossChainSwapNative",
206
+ "0x9edd28ad": "bridgeToken"
207
+ }
208
+ },
209
+ "0x4200000000000000000000000000000000000006": {
210
+ "role": "wrapped_native",
211
+ "selectors": {
212
+ "0xd0e30db0": "deposit",
213
+ "0x2e1a7d4d": "withdraw"
214
+ }
215
+ },
216
+ "0x6f26Bf09B1C792e3228e5467807a900A503c0281": {
217
+ "role": "across_spoke_pool",
218
+ "selectors": {
219
+ "0xad5425c6": "deposit"
220
+ }
221
+ },
222
+ "0x97CCDBea4632140639aD5eA9b944aa034eb15fD4": {
223
+ "role": "across_periphery_native_only",
224
+ "selectors": {
225
+ "0x609ea081": "depositNative"
226
+ }
227
+ }
228
+ },
229
+ "lanes": {
230
+ "1": {
231
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 1,
232
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 1,
233
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 1,
234
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 1,
235
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30101,
236
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 0
237
+ },
238
+ "56": {
239
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 56,
240
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 56,
241
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 56,
242
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30102
243
+ },
244
+ "137": {
245
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 137,
246
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 137,
247
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 137,
248
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 137,
249
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30109,
250
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 7
251
+ },
252
+ "8453": {
253
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 8453,
254
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 8453,
255
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 8453,
256
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30184,
257
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 6
258
+ },
259
+ "42161": {
260
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 42161,
261
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 42161,
262
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 42161,
263
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 42161,
264
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30110,
265
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 3
266
+ }
267
+ }
268
+ },
269
+ "56": {
270
+ "name": "BNB Chain",
271
+ "usdc": "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
272
+ "usdcDecimals": 18,
273
+ "wrappedNative": "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
274
+ "nativeSymbol": "BNB",
275
+ "wrappedSymbol": "WBNB",
276
+ "composer": "0xE242F3DeB6B8d9e76e93b0bf5e461B12a722e86E",
277
+ "houseReferrer": "0x69d3661ac6935a33D59b8A6964f0523182A5ae7d",
278
+ "stablecoins": [
279
+ "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
280
+ "0x55d398326f99059fF775485246999027B3197955"
281
+ ],
282
+ "stargateRailId": "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404",
283
+ "gasDeliveryShell": "0xe648D17e146C736A7296BA72260fB2ed5bb58c99",
284
+ "gasPay": null,
285
+ "targets": {
286
+ "0x48dD089939C9a29211e7De9417e91A141D37F697": {
287
+ "role": "swap_shell",
288
+ "selectors": {
289
+ "0xab33b1ec": "swapWithBlob"
290
+ }
291
+ },
292
+ "0xC269a4F4dEbD4036597ee830349d824D5bA9ca7E": {
293
+ "role": "measured_shell",
294
+ "selectors": {
295
+ "0xe0b7822f": "swapMeasuredWithBlobV1"
296
+ }
297
+ },
298
+ "0x02ED7CD8D60768797328B098ce0df2fa99db6f23": {
299
+ "role": "router_v3",
300
+ "selectors": {
301
+ "0x84022178": "crossChainSwap",
302
+ "0xf79eec2e": "crossChainSwapNative",
303
+ "0x9edd28ad": "bridgeToken"
304
+ }
305
+ },
306
+ "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c": {
307
+ "role": "wrapped_native",
308
+ "selectors": {
309
+ "0xd0e30db0": "deposit",
310
+ "0x2e1a7d4d": "withdraw"
311
+ }
312
+ },
313
+ "0x4e8E101924eDE233C13e2D8622DC8aED2872d505": {
314
+ "role": "across_spoke_pool",
315
+ "selectors": {
316
+ "0xad5425c6": "deposit"
317
+ }
318
+ },
319
+ "0x97CCDBea4632140639aD5eA9b944aa034eb15fD4": {
320
+ "role": "across_periphery_native_only",
321
+ "selectors": {
322
+ "0x609ea081": "depositNative"
323
+ }
324
+ }
325
+ },
326
+ "lanes": {
327
+ "1": {
328
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 1,
329
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 1,
330
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 1,
331
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30101
332
+ },
333
+ "10": {
334
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 10,
335
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 10,
336
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 10,
337
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30111
338
+ },
339
+ "137": {
340
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 137,
341
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 137,
342
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 137,
343
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30109
344
+ },
345
+ "8453": {
346
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 8453,
347
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 8453,
348
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 8453,
349
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30184
350
+ },
351
+ "42161": {
352
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 42161,
353
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 42161,
354
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 42161,
355
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30110
356
+ }
357
+ }
358
+ },
359
+ "137": {
360
+ "name": "Polygon",
361
+ "usdc": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
362
+ "usdcDecimals": 6,
363
+ "wrappedNative": "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
364
+ "nativeSymbol": "POL",
365
+ "wrappedSymbol": "WPOL",
366
+ "composer": "0x6Cbc5c7AA249EDD719001786b6e0a07D44027693",
367
+ "houseReferrer": "0x69d3661ac6935a33D59b8A6964f0523182A5ae7d",
368
+ "stablecoins": [
369
+ "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
370
+ "0xc2132D05D31c914a87C6611C10748AEb04B58e8F"
371
+ ],
372
+ "stargateRailId": "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404",
373
+ "gasDeliveryShell": "0x02ED7CD8D60768797328B098ce0df2fa99db6f23",
374
+ "gasPay": {
375
+ "routerV3": "0xEa0E8caE2dba07D3BC828f42fd6219fF93ddCe97",
376
+ "acrossUsdcAdapter": "0x25b14009e495D781D2180d3E3B3a86050967dd2A",
377
+ "railId": "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916"
378
+ },
379
+ "targets": {
380
+ "0x5b4a223D8489a3b97d4EBe8fE93C6A7aC3Ec1AD6": {
381
+ "role": "swap_shell",
382
+ "selectors": {
383
+ "0xab33b1ec": "swapWithBlob"
384
+ }
385
+ },
386
+ "0xA06eE4d57A2E6ea9213Ab4Bce2C055fD09BB43A1": {
387
+ "role": "measured_shell",
388
+ "selectors": {
389
+ "0xe0b7822f": "swapMeasuredWithBlobV1"
390
+ }
391
+ },
392
+ "0xEa0E8caE2dba07D3BC828f42fd6219fF93ddCe97": {
393
+ "role": "router_v3",
394
+ "selectors": {
395
+ "0x84022178": "crossChainSwap",
396
+ "0xf79eec2e": "crossChainSwapNative",
397
+ "0x9edd28ad": "bridgeToken"
398
+ }
399
+ },
400
+ "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270": {
401
+ "role": "wrapped_native",
402
+ "selectors": {
403
+ "0xd0e30db0": "deposit",
404
+ "0x2e1a7d4d": "withdraw"
405
+ }
406
+ },
407
+ "0x9295ee1d8C5b022Be115A2AD3c30C72E34e7F096": {
408
+ "role": "across_spoke_pool",
409
+ "selectors": {
410
+ "0xad5425c6": "deposit"
411
+ }
412
+ },
413
+ "0x97CCDBea4632140639aD5eA9b944aa034eb15fD4": {
414
+ "role": "across_periphery_native_only",
415
+ "selectors": {
416
+ "0x609ea081": "depositNative"
417
+ }
418
+ }
419
+ },
420
+ "lanes": {
421
+ "1": {
422
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 1,
423
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 1,
424
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 1,
425
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 1,
426
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30101,
427
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 0
428
+ },
429
+ "10": {
430
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 10,
431
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 10,
432
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 10,
433
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 10,
434
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30111,
435
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 2
436
+ },
437
+ "56": {
438
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 56,
439
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 56,
440
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 56,
441
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30102
442
+ },
443
+ "8453": {
444
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 8453,
445
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 8453,
446
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 8453,
447
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30184,
448
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 6
449
+ },
450
+ "42161": {
451
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 42161,
452
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 42161,
453
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 42161,
454
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 42161,
455
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30110,
456
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 3
457
+ }
458
+ }
459
+ },
460
+ "8453": {
461
+ "name": "Base",
462
+ "usdc": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
463
+ "usdcDecimals": 6,
464
+ "wrappedNative": "0x4200000000000000000000000000000000000006",
465
+ "nativeSymbol": "ETH",
466
+ "wrappedSymbol": "WETH",
467
+ "composer": "0x58b73b40b5ED797833955397dF989AA2DEdD50A4",
468
+ "houseReferrer": "0x69d3661ac6935a33D59b8A6964f0523182A5ae7d",
469
+ "stablecoins": [
470
+ "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
471
+ "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2"
472
+ ],
473
+ "stargateRailId": "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404",
474
+ "gasDeliveryShell": "0x3A4569133c21013bbBc99a733FB891A7fffafD9a",
475
+ "gasPay": {
476
+ "routerV3": "0x545fef65c37ECEE32309d879ABafaa959E9F114C",
477
+ "acrossUsdcAdapter": "0x1000517094c532f0e4fF0E61fC6cD33daea2E64f",
478
+ "railId": "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916"
479
+ },
480
+ "targets": {
481
+ "0xb08F28a3575805ee1E3729fc19Ab7E869CBAF563": {
482
+ "role": "swap_shell",
483
+ "selectors": {
484
+ "0xab33b1ec": "swapWithBlob"
485
+ }
486
+ },
487
+ "0x003d4C95756608Ed4C11C5d0Ad9ca4c4076cAF20": {
488
+ "role": "measured_shell",
489
+ "selectors": {
490
+ "0xe0b7822f": "swapMeasuredWithBlobV1"
491
+ }
492
+ },
493
+ "0x545fef65c37ECEE32309d879ABafaa959E9F114C": {
494
+ "role": "router_v3",
495
+ "selectors": {
496
+ "0x84022178": "crossChainSwap",
497
+ "0xf79eec2e": "crossChainSwapNative",
498
+ "0x9edd28ad": "bridgeToken"
499
+ }
500
+ },
501
+ "0x4200000000000000000000000000000000000006": {
502
+ "role": "wrapped_native",
503
+ "selectors": {
504
+ "0xd0e30db0": "deposit",
505
+ "0x2e1a7d4d": "withdraw"
506
+ }
507
+ },
508
+ "0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64": {
509
+ "role": "across_spoke_pool",
510
+ "selectors": {
511
+ "0xad5425c6": "deposit"
512
+ }
513
+ },
514
+ "0x97CCDBea4632140639aD5eA9b944aa034eb15fD4": {
515
+ "role": "across_periphery_native_only",
516
+ "selectors": {
517
+ "0x609ea081": "depositNative"
518
+ }
519
+ }
520
+ },
521
+ "lanes": {
522
+ "1": {
523
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 1,
524
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 1,
525
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 1,
526
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30101,
527
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 0
528
+ },
529
+ "10": {
530
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 10,
531
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 10,
532
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 10,
533
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30111,
534
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 2
535
+ },
536
+ "56": {
537
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 56,
538
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 56,
539
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 56,
540
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30102
541
+ },
542
+ "137": {
543
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 137,
544
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 137,
545
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 137,
546
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30109,
547
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 7
548
+ },
549
+ "42161": {
550
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 42161,
551
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 42161,
552
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 42161,
553
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30110,
554
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 3
555
+ }
556
+ }
557
+ },
558
+ "42161": {
559
+ "name": "Arbitrum",
560
+ "usdc": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
561
+ "usdcDecimals": 6,
562
+ "wrappedNative": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
563
+ "nativeSymbol": "ETH",
564
+ "wrappedSymbol": "WETH",
565
+ "composer": "0xe484191bfF3e4DED3520d1D8e0fcf098CAef4cE4",
566
+ "houseReferrer": "0x69d3661ac6935a33D59b8A6964f0523182A5ae7d",
567
+ "stablecoins": [
568
+ "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
569
+ "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"
570
+ ],
571
+ "stargateRailId": "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404",
572
+ "gasDeliveryShell": "0x02ED7CD8D60768797328B098ce0df2fa99db6f23",
573
+ "gasPay": {
574
+ "routerV3": "0xEa0E8caE2dba07D3BC828f42fd6219fF93ddCe97",
575
+ "acrossUsdcAdapter": "0x25b14009e495D781D2180d3E3B3a86050967dd2A",
576
+ "railId": "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916"
577
+ },
578
+ "targets": {
579
+ "0x4052700f83324Be5710d187b7bbEa9837DfFa8fc": {
580
+ "role": "swap_shell",
581
+ "selectors": {
582
+ "0xab33b1ec": "swapWithBlob"
583
+ }
584
+ },
585
+ "0x78D851D8BC6A9b9739549E7515Bf02D6394E1794": {
586
+ "role": "measured_shell",
587
+ "selectors": {
588
+ "0xe0b7822f": "swapMeasuredWithBlobV1"
589
+ }
590
+ },
591
+ "0xEa0E8caE2dba07D3BC828f42fd6219fF93ddCe97": {
592
+ "role": "router_v3",
593
+ "selectors": {
594
+ "0x84022178": "crossChainSwap",
595
+ "0xf79eec2e": "crossChainSwapNative",
596
+ "0x9edd28ad": "bridgeToken"
597
+ }
598
+ },
599
+ "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1": {
600
+ "role": "wrapped_native",
601
+ "selectors": {
602
+ "0xd0e30db0": "deposit",
603
+ "0x2e1a7d4d": "withdraw"
604
+ }
605
+ },
606
+ "0xe35e9842fceaCA96570B734083f4a58e8F7C5f2A": {
607
+ "role": "across_spoke_pool",
608
+ "selectors": {
609
+ "0xad5425c6": "deposit"
610
+ }
611
+ },
612
+ "0x97CCDBea4632140639aD5eA9b944aa034eb15fD4": {
613
+ "role": "across_periphery_native_only",
614
+ "selectors": {
615
+ "0x609ea081": "depositNative"
616
+ }
617
+ }
618
+ },
619
+ "lanes": {
620
+ "1": {
621
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 1,
622
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 1,
623
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 1,
624
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 1,
625
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30101,
626
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 0
627
+ },
628
+ "10": {
629
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 10,
630
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 10,
631
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 10,
632
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 10,
633
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30111,
634
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 2
635
+ },
636
+ "56": {
637
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 56,
638
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 56,
639
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 56,
640
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30102
641
+ },
642
+ "137": {
643
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 137,
644
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 137,
645
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 137,
646
+ "0x61a012ca05dbda272441751b0a350f6bbf2996f752862f4eba3fce9c7e8a89e6": 137,
647
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30109,
648
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 7
649
+ },
650
+ "8453": {
651
+ "0xf6c86ecb0564cd8d732c9d68c369fbc03a0c351db7419e70be166d26a2ed4916": 8453,
652
+ "0xa28bababc0e2b0c1c28d78d20a75d5ef0afd16dc155828d76a2bf6b97805d328": 8453,
653
+ "0xcadb263249f9536655ea392f5245afe7bf96a0ed7ff0095bb817c6a77c9b8d84": 8453,
654
+ "0xb247d4fab2445d0279df94160c242cb8298d9aea57aa6b6af3c9dfddce2d1404": 30184,
655
+ "0xed0f0a3ae066b02930027c7cc065548bade2974a98f517699d023130faa00e23": 6
656
+ }
657
+ }
658
+ }
659
+ }
660
+ };
661
+
662
+ var low = (a) => a.toLowerCase();
663
+ var NATIVE = low(ALLOWLIST.nativeSentinel);
664
+ var HANDLER = low(ALLOWLIST.acrossHandler);
665
+ var FACTORY = low(ALLOWLIST.gas.factory);
666
+ var FEE_RECIPIENT = low(ALLOWLIST.gas.feeRecipient);
667
+ var ZERO_ADDRESS = `0x${"0".repeat(40)}`;
668
+ var CHAINS = new Map(
669
+ Object.entries(ALLOWLIST.chains).map(([id, c]) => [
670
+ Number(id),
671
+ {
672
+ usdc: low(c.usdc),
673
+ usdcDecimals: c.usdcDecimals,
674
+ wrappedNative: low(c.wrappedNative),
675
+ symbols: /* @__PURE__ */ new Map([
676
+ ["usdc", low(c.usdc)],
677
+ [low(c.nativeSymbol), NATIVE],
678
+ [low(c.wrappedSymbol), low(c.wrappedNative)]
679
+ ]),
680
+ composer: low(c.composer),
681
+ houseReferrer: low(c.houseReferrer),
682
+ stablecoins: new Set(c.stablecoins.map(low)),
683
+ stargateRailId: low(c.stargateRailId),
684
+ deliveryShell: low(c.gasDeliveryShell),
685
+ gasPay: c.gasPay === null ? null : { routerV3: low(c.gasPay.routerV3), acrossUsdcAdapter: low(c.gasPay.acrossUsdcAdapter), railId: low(c.gasPay.railId) },
686
+ targets: new Map(Object.entries(c.targets).map(([a, t]) => [low(a), { role: t.role, selectors: new Set(Object.keys(t.selectors)) }])),
687
+ spokePool: Object.entries(c.targets).find(([, t]) => t.role === "across_spoke_pool")?.[0].toLowerCase() ?? null,
688
+ lanes: new Map(Object.entries(c.lanes).map(([to, rails]) => [Number(to), new Map(Object.entries(rails).map(([r, d]) => [low(r), BigInt(d)]))]))
689
+ }
690
+ ])
691
+ );
692
+ var MAX_UINT = (1n << 256n) - 1n;
693
+ var HALF_UINT = 1n << 255n;
694
+ var ADDRESS = /^0x[0-9a-fA-F]{40}$/;
695
+ var HEX_DATA = /^0x(?:[0-9a-fA-F]{2})*$/;
696
+ var HEX_QUANTITY = /^0x[0-9a-fA-F]{1,64}$/;
697
+ var BYTES32 = /^0x[0-9a-fA-F]{64}$/;
698
+ var DECIMAL_INT = /^[0-9]{1,78}$/;
699
+ var DECIMAL = /^([0-9]{1,30})(?:\.([0-9]{1,30}))?$/;
700
+ var APPROVE = "0x095ea7b3";
701
+ var SWAP = "0xab33b1ec";
702
+ var MEASURED = "0xe0b7822f";
703
+ var CROSS = "0x84022178";
704
+ var CROSS_NATIVE = "0xf79eec2e";
705
+ var BRIDGE = "0x9edd28ad";
706
+ var DEPOSIT = "0xd0e30db0";
707
+ var WITHDRAW = "0x2e1a7d4d";
708
+ var SPOKE_DEPOSIT = "0xad5425c6";
709
+ var DEPOSIT_NATIVE = "0x609ea081";
710
+ var SAME_CHAIN = /* @__PURE__ */ new Set([SWAP, MEASURED, DEPOSIT, WITHDRAW]);
711
+ var PULLS = {
712
+ [SWAP]: { token: 0, pulled: [2] },
713
+ [MEASURED]: { token: 0, pulled: [9] },
714
+ [CROSS]: { token: 0, pulled: [2, 9] },
715
+ [BRIDGE]: { token: 0, pulled: [1] },
716
+ [SPOKE_DEPOSIT]: { token: 2, pulled: [4] }
717
+ };
718
+ var AMOUNT_IN = { [SWAP]: 2, [MEASURED]: 2, [CROSS]: 2, [CROSS_NATIVE]: 2, [BRIDGE]: 1, [SPOKE_DEPOSIT]: 4, [DEPOSIT_NATIVE]: 4, [WITHDRAW]: 0 };
719
+ var REFERRAL = { [SWAP]: [6, 7], [MEASURED]: [6, 7], [CROSS]: [6, 7], [CROSS_NATIVE]: [6, 7], [BRIDGE]: [7, 8] };
720
+ var NATIVE_TOKEN = { [SWAP]: 0, [MEASURED]: 0, [CROSS]: 0, [CROSS_NATIVE]: 0, [DEPOSIT_NATIVE]: 3 };
721
+ var ERC20_ONLY = /* @__PURE__ */ new Set([CROSS, BRIDGE, SPOKE_DEPOSIT, WITHDRAW]);
722
+ var WETH_AS_ERC20 = { [SWAP]: 8, [MEASURED]: 8 };
723
+ var RAIL_WORD = { [CROSS]: 12, [CROSS_NATIVE]: 12, [BRIDGE]: 2 };
724
+ var MIN_OUT = { [SWAP]: [3], [MEASURED]: [3, 10], [CROSS]: [3, 16], [CROSS_NATIVE]: [3, 16], [BRIDGE]: [6], [SPOKE_DEPOSIT]: [5], [DEPOSIT_NATIVE]: [6] };
725
+ var SWAP_ORDER = [
726
+ ["chainId", "uint"],
727
+ ["token", "address"],
728
+ ["shell", "address"],
729
+ ["amount", "uint"],
730
+ ["fee", "uint"],
731
+ ["feeRecipient", "address"],
732
+ ["maxProtocolFeeBps", "uint"],
733
+ ["refundTo", "address"],
734
+ ["recipient", "address"],
735
+ ["minOut", "uint"],
736
+ ["deadline", "uint"],
737
+ ["quoteId", "bytes32"]
738
+ ];
739
+ var ACROSS_ORDER = [
740
+ ["chainId", "uint"],
741
+ ["token", "address"],
742
+ ["router", "address"],
743
+ ["railId", "bytes32"],
744
+ ["adapter", "address"],
745
+ ["dstChainId", "uint"],
746
+ ["dstToken", "address"],
747
+ ["dstDecimals", "uint8"],
748
+ ["handler", "address"],
749
+ ["dstShell", "address"],
750
+ ["dstWrappedNative", "address"],
751
+ ["amount", "uint"],
752
+ ["fee", "uint"],
753
+ ["feeRecipient", "address"],
754
+ ["maxProtocolFeeBps", "uint"],
755
+ ["relayFee", "uint"],
756
+ ["refundTo", "address"],
757
+ ["recipient", "address"],
758
+ ["outputAmount", "uint"],
759
+ ["minOut", "uint"],
760
+ ["messageHash", "bytes32"],
761
+ ["deadline", "uint"],
762
+ ["quoteId", "bytes32"]
763
+ ];
764
+ var AUTH_FIELDS = [
765
+ ["from", "address"],
766
+ ["to", "address"],
767
+ ["value", "uint256"],
768
+ ["validAfter", "uint256"],
769
+ ["validBefore", "uint256"],
770
+ ["nonce", "bytes32"]
771
+ ];
772
+ var Refusal = class {
773
+ constructor(rule, message) {
774
+ this.rule = rule;
775
+ this.message = message;
776
+ }
777
+ rule;
778
+ message;
779
+ };
780
+ function fail(rule, message) {
781
+ throw new Refusal(rule, message);
782
+ }
783
+ function guard(run) {
784
+ let current = "P1";
785
+ try {
786
+ run((rule) => {
787
+ current = rule;
788
+ });
789
+ return { ok: true };
790
+ } catch (err) {
791
+ const r = err instanceof Refusal ? err : new Refusal(current, "the answer is malformed");
792
+ return { ok: false, rule: r.rule, message: `${r.rule}: ${r.message}` };
793
+ }
794
+ }
795
+ var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
796
+ function object(v, rule, what) {
797
+ return isObject(v) ? v : fail(rule, `${what} is missing`);
798
+ }
799
+ function address(v, rule, what) {
800
+ return typeof v === "string" && ADDRESS.test(v) ? low(v) : fail(rule, `${what} is not an address`);
801
+ }
802
+ function integer(v, rule, what) {
803
+ if (typeof v === "number" && Number.isSafeInteger(v) && v >= 0) return BigInt(v);
804
+ if (typeof v === "string" && DECIMAL_INT.test(v)) {
805
+ const n = BigInt(v);
806
+ if (n <= MAX_UINT) return n;
807
+ }
808
+ return fail(rule, `${what} is not an unsigned integer`);
809
+ }
810
+ function quantity(v, rule, what) {
811
+ return typeof v === "string" && HEX_QUANTITY.test(v) ? BigInt(v) : fail(rule, `${what} is not a hex quantity`);
812
+ }
813
+ function bytes32(v, rule, what) {
814
+ return typeof v === "string" && BYTES32.test(v) ? low(v) : fail(rule, `${what} is not 32 bytes`);
815
+ }
816
+ function units(v, decimals, rule, what) {
817
+ const m = typeof v === "string" ? DECIMAL.exec(v) : null;
818
+ const frac = m?.[2] ?? "";
819
+ if (m === null || frac.length > decimals) return fail(rule, `${what} is not a decimal amount`);
820
+ return BigInt(m[1]) * 10n ** BigInt(decimals) + BigInt(frac.padEnd(decimals, "0") || "0");
821
+ }
822
+ function normalDecimal(v, rule, what) {
823
+ const m = typeof v === "string" ? DECIMAL.exec(v) : null;
824
+ if (m === null) return fail(rule, `${what} is not a decimal amount`);
825
+ const frac = (m[2] ?? "").replace(/0+$/, "");
826
+ return `${BigInt(m[1])}${frac === "" ? "" : `.${frac}`}`;
827
+ }
828
+ function word(data, k, rule, what) {
829
+ const w = data.slice(10 + 64 * k, 74 + 64 * k);
830
+ return w.length === 64 ? w : fail(rule, `${what} is missing from the calldata`);
831
+ }
832
+ function wordInt(data, k, rule, what) {
833
+ return BigInt(`0x${word(data, k, rule, what)}`);
834
+ }
835
+ function wordAddress(data, k, rule, what) {
836
+ const w = word(data, k, rule, what);
837
+ return w.startsWith("0".repeat(24)) ? `0x${w.slice(24)}` : fail(rule, `${what} is not an address`);
838
+ }
839
+ function sameChain(v, chainId) {
840
+ return typeof v === "number" && v === chainId || typeof v === "string" && DECIMAL_INT.test(v) && BigInt(v) === BigInt(chainId);
841
+ }
842
+ var keccakHex = (hex) => `0x${(0, import_utils.bytesToHex)((0, import_sha3.keccak_256)((0, import_utils.hexToBytes)(hex.slice(2))))}`;
843
+ function checkPlanSwap(request, body) {
844
+ return guard((at) => {
845
+ at("P1");
846
+ const fromChainId = request.fromChainId;
847
+ const toChainId = request.toChainId ?? fromChainId;
848
+ const wallet = address(request.wallet, "P1", "wallet");
849
+ const calls = Array.isArray(body.calls) ? body.calls : fail("P1", "calls are missing");
850
+ if (body.blocked === true) {
851
+ if (calls.length > 0) fail("P1", "a blocked plan carries calls");
852
+ return;
853
+ }
854
+ if (calls.length === 0) fail("P1", "the plan has no calls");
855
+ const parsed = calls.map((raw, i) => {
856
+ const c = object(raw, "P1", `call ${i}`);
857
+ if (!sameChain(c.chainId, fromChainId)) fail("P1", `call ${i} is for another chain`);
858
+ if (address(c.from, "P1", `call ${i} from`) !== wallet) fail("P1", `call ${i} is from another wallet`);
859
+ const to = address(c.to, "P1", `call ${i} to`);
860
+ const data = typeof c.data === "string" && HEX_DATA.test(c.data) && c.data.length >= 10 ? low(c.data) : fail("P1", `call ${i} data is malformed`);
861
+ return { to, data, value: quantity(c.value, "P1", `call ${i} value`) };
862
+ });
863
+ const main = parsed[parsed.length - 1];
864
+ const selector = main.data.slice(0, 10);
865
+ at("P2");
866
+ const chain2 = CHAINS.get(fromChainId) ?? fail("P2", "the chain is not on the allowlist");
867
+ const target = chain2.targets.get(main.to) ?? fail("P2", "the main call's target is not on the allowlist");
868
+ if (!target.selectors.has(selector)) fail("P2", "the main call's function is not allowed on its target");
869
+ if (SAME_CHAIN.has(selector) !== (toChainId === fromChainId)) fail("P2", "the main call does not fit the route");
870
+ at("P3");
871
+ const send = object(body.send, "P3", "send");
872
+ if (!sameChain(send.chainId, fromChainId)) fail("P3", "send is on another chain");
873
+ const token2 = address(send.token, "P3", "send.token");
874
+ const sellToken = request.sellToken.trim();
875
+ const pinned = ADDRESS.test(sellToken) ? low(sellToken) : chain2.symbols.get(low(sellToken)) ?? null;
876
+ if (pinned !== null && pinned !== token2) fail("P3", "send.token is not the sell token");
877
+ if (normalDecimal(send.amount, "P3", "send.amount") !== normalDecimal(request.amount, "P3", "amount")) fail("P3", "send.amount is not the requested amount");
878
+ const native = token2 === NATIVE;
879
+ const approves = parsed.slice(0, -1);
880
+ if (approves.length > 2) fail("P3", "more than two calls come before the main call");
881
+ const approved = approves.map((a, i) => {
882
+ if (!a.data.startsWith(APPROVE) || a.data.length !== 138 || a.value !== 0n) fail("P3", `call ${i} is not a plain approve`);
883
+ if (native || a.to !== token2) fail("P3", `call ${i} approves another token`);
884
+ if (wordAddress(a.data, 0, "P3", "spender") !== main.to) fail("P3", `call ${i} approves another spender`);
885
+ const amount2 = wordInt(a.data, 1, "P3", "approve amount");
886
+ if (amount2 >= HALF_UINT) fail("P3", `call ${i} is an unlimited approve`);
887
+ return amount2;
888
+ });
889
+ const last = approved[approved.length - 1];
890
+ if (last === 0n) fail("P3", "the last approve is zero");
891
+ if (approved.length === 2 && approved[0] !== 0n) fail("P3", "only approve(0) may come before the approve");
892
+ at("P4");
893
+ const pulls = PULLS[selector];
894
+ if (pulls === void 0) {
895
+ if (approves.length > 0) fail("P4", "this function takes no approve");
896
+ if (selector === WITHDRAW ? main.to !== token2 : !native) fail("P4", "the main call spends another token");
897
+ } else if (!native) {
898
+ if (wordAddress(main.data, pulls.token, "P4", "token") !== token2) fail("P4", "the main call spends another token");
899
+ const pulled = pulls.pulled.map((k) => wordInt(main.data, k, "P4", "amount")).reduce((a, b) => a > b ? a : b);
900
+ if (last !== void 0 && pulled !== last) fail("P4", "the main call pulls another amount than approved");
901
+ if (pulled > 2n * wordInt(main.data, AMOUNT_IN[selector], "P4", "amountIn")) fail("P4", "the main call pulls more than twice its input");
902
+ }
903
+ if (native && ERC20_ONLY.has(selector)) fail("P4", "a native sell cannot use this function");
904
+ const mode = WETH_AS_ERC20[selector];
905
+ if (mode !== void 0 && native && wordInt(main.data, mode, "P4", "native mode") !== 0n) fail("P4", "the main call spends the wrapped token, not the native coin");
906
+ if ((selector === CROSS || selector === CROSS_NATIVE) && wordInt(main.data, 8, "P4", "native mode") !== 1n) fail("P4", "the router swap is not encoded as the backend encodes it");
907
+ const wrappedWord = NATIVE_TOKEN[selector];
908
+ if (native && wrappedWord !== void 0 && wordAddress(main.data, wrappedWord, "P4", "token") !== chain2.wrappedNative) fail("P4", "the main call spends another token");
909
+ const decimals = native || token2 === chain2.wrappedNative ? 18 : token2 === chain2.usdc ? chain2.usdcDecimals : null;
910
+ const inWord = AMOUNT_IN[selector];
911
+ if (decimals !== null && inWord !== void 0 && wordInt(main.data, inWord, "P4", "amountIn") !== units(request.amount, decimals, "P4", "amount")) fail("P4", "the main call sells another amount than requested");
912
+ for (const k of MIN_OUT[selector] ?? []) if (wordInt(main.data, k, "P4", "minimum") === 0n) fail("P4", "the main call has no minimum");
913
+ at("P5");
914
+ const fees = body.fees === void 0 ? [] : Array.isArray(body.fees) ? body.fees : fail("P5", "fees are malformed");
915
+ let value = native ? units(send.amount, 18, "P5", "send.amount") : 0n;
916
+ const messaging = fees.map((f) => object(f, "P5", "fee")).filter((f) => f.kind === "native_messaging");
917
+ if (messaging.length > 1) fail("P5", "more than one native messaging fee");
918
+ for (const fee of messaging) {
919
+ const railWord = RAIL_WORD[selector];
920
+ if (railWord === void 0 || `0x${word(main.data, railWord, "P5", "railId")}` !== chain2.stargateRailId) fail("P5", "only the Stargate rail takes a native messaging fee");
921
+ value += units(fee.amount, 18, "P5", "fee amount");
922
+ }
923
+ if (main.value !== value) fail("P5", "the main call sends another native value");
924
+ const referral = REFERRAL[selector];
925
+ if (referral !== void 0) {
926
+ const referrer = wordAddress(main.data, referral[0], "P5", "referrer");
927
+ const bps = wordInt(main.data, referral[1], "P5", "referral fee");
928
+ const free = [ZERO_ADDRESS, BigInt(SAME_CHAIN.has(selector) ? ALLOWLIST.referral.sameChainBps : ALLOWLIST.referral.stablecoinBps)];
929
+ const house = [chain2.houseReferrer, BigInt(ALLOWLIST.referral.crossChainBps)];
930
+ const dst2 = CHAINS.get(toChainId);
931
+ const receive = isObject(body.receive) ? body.receive : null;
932
+ const buyToken2 = request.buyToken.trim();
933
+ const tokenOut = typeof receive?.token === "string" && ADDRESS.test(receive.token) ? low(receive.token) : ADDRESS.test(buyToken2) ? low(buyToken2) : dst2?.symbols.get(low(buyToken2)) ?? null;
934
+ const stableIn = chain2.stablecoins.has(token2);
935
+ const allowed = SAME_CHAIN.has(selector) ? [free] : !stableIn ? [house] : tokenOut === null ? [free, house] : [dst2?.stablecoins.has(tokenOut) === true ? free : house];
936
+ if (!allowed.some(([a, b]) => a === referrer && b === bps)) fail("P5", "the referral fee goes to another address or has another size");
937
+ }
938
+ at("P6");
939
+ const recipient = request.recipient === void 0 ? wallet : address(request.recipient, "P6", "recipient");
940
+ const composer = toChainId === fromChainId ? null : CHAINS.get(toChainId)?.composer ?? null;
941
+ const arrives = (a) => a === recipient || a === HANDLER || a === composer;
942
+ const at6 = (k, what) => wordAddress(main.data, k, "P6", what);
943
+ const lane = (railWord, dstWord) => {
944
+ const dstId = chain2.lanes.get(toChainId)?.get(`0x${word(main.data, railWord, "P6", "railId")}`);
945
+ if (dstId === void 0 || wordInt(main.data, dstWord, "P6", "destination") !== dstId) fail("P6", "the transfer goes to another chain");
946
+ };
947
+ const dst = CHAINS.get(toChainId);
948
+ const buyToken = request.buyToken.trim();
949
+ const out = ADDRESS.test(buyToken) ? low(buyToken) : dst?.symbols.get(low(buyToken)) ?? null;
950
+ const outWord = out === null ? null : out === NATIVE ? dst?.wrappedNative ?? null : out;
951
+ const output = (k) => {
952
+ if (outWord !== null && at6(k, "output token") !== outWord) fail("P6", "the main call delivers another token");
953
+ };
954
+ const destination = (k) => {
955
+ if (wordInt(main.data, k, "P6", "destination") !== BigInt(toChainId)) fail("P6", "the transfer goes to another chain");
956
+ };
957
+ switch (selector) {
958
+ case SWAP:
959
+ case MEASURED:
960
+ if (at6(5, "recipient") !== recipient) fail("P6", "the swap pays another recipient");
961
+ output(1);
962
+ if (!native) {
963
+ const flag = wordInt(main.data, 8, "P6", "native output");
964
+ if (out !== null ? flag !== (out === NATIVE ? 0n : 1n) : flag === 0n && at6(1, "output token") !== chain2.wrappedNative) fail("P6", "the main call delivers another token");
965
+ }
966
+ break;
967
+ case CROSS:
968
+ case CROSS_NATIVE:
969
+ if (at6(5, "source recipient") !== main.to) fail("P6", "the source swap pays out of the router");
970
+ if (!arrives(at6(14, "recipient"))) fail("P6", "the transfer pays another recipient");
971
+ if (at6(15, "refund recipient") !== wallet) fail("P6", "refunds go to another address");
972
+ lane(12, 13);
973
+ break;
974
+ case BRIDGE:
975
+ if (!arrives(at6(4, "recipient"))) fail("P6", "the transfer pays another recipient");
976
+ if (at6(5, "refund recipient") !== wallet) fail("P6", "refunds go to another address");
977
+ lane(2, 3);
978
+ break;
979
+ case SPOKE_DEPOSIT:
980
+ if (at6(0, "depositor") !== wallet) fail("P6", "refunds go to another address");
981
+ if (![recipient, HANDLER].includes(at6(1, "recipient"))) fail("P6", "the transfer pays another recipient");
982
+ destination(6);
983
+ output(3);
984
+ break;
985
+ case DEPOSIT_NATIVE:
986
+ if (at6(0, "spoke pool") !== chain2.spokePool) fail("P6", "the deposit goes to another pool");
987
+ if (at6(1, "depositor") !== wallet) fail("P6", "refunds go to another address");
988
+ if (![recipient, HANDLER].includes(at6(2, "recipient"))) fail("P6", "the transfer pays another recipient");
989
+ destination(7);
990
+ output(5);
991
+ break;
992
+ case DEPOSIT:
993
+ case WITHDRAW:
994
+ if (recipient !== wallet) fail("P6", "wrapping pays the wallet, not the recipient");
995
+ if (out !== null && out !== (selector === DEPOSIT ? chain2.wrappedNative : NATIVE)) fail("P6", "the main call delivers another token");
996
+ break;
997
+ default:
998
+ fail("P6", "the main call has no recipient rule");
999
+ }
1000
+ });
1001
+ }
1002
+ function encodeOrder(order, fields) {
1003
+ const keys = Object.keys(order);
1004
+ if (keys.length !== fields.length || !fields.every(([name]) => keys.includes(name))) fail("G4", "the order has other fields");
1005
+ return fields.map(([name, type]) => {
1006
+ const v = order[name];
1007
+ if (type === "address") return address(v, "G4", `order.${name}`).slice(2).padStart(64, "0");
1008
+ if (type === "bytes32") return bytes32(v, "G4", `order.${name}`).slice(2);
1009
+ const n = integer(v, "G4", `order.${name}`);
1010
+ if (type === "uint8" && n > 255n) fail("G4", `order.${name} is out of range`);
1011
+ return n.toString(16).padStart(64, "0");
1012
+ }).join("");
1013
+ }
1014
+ var toDst = (amount2, from, to) => to >= from ? amount2 * 10n ** BigInt(to - from) : amount2 / 10n ** BigInt(from - to);
1015
+ var GAS_SKEW_SEC = 120;
1016
+ function checkGetGas(request, body, nowSec = Math.floor(Date.now() / 1e3)) {
1017
+ return guard((at) => {
1018
+ if (request.offer !== void 0) return;
1019
+ at("G1");
1020
+ const payChainId = request.payChainId ?? fail("G1", "the request has no pay chain");
1021
+ const chainId = request.chainId ?? fail("G1", "the request has no delivery chain");
1022
+ const pay = CHAINS.get(payChainId);
1023
+ const gasPay = pay?.gasPay ?? fail("G1", "the pay chain is not on the allowlist");
1024
+ const usdc = pay.usdc;
1025
+ const payDecimals = pay.usdcDecimals;
1026
+ const wallet = request.wallet === void 0 ? null : address(request.wallet, "G1", "wallet");
1027
+ if (wallet !== null && body.typedData === void 0) fail("G1", "the offer has no authorization to sign");
1028
+ const typed = body.typedData === void 0 ? null : object(body.typedData, "G1", "typedData");
1029
+ const message = typed === null ? null : object(typed.message, "G1", "typedData.message");
1030
+ if (typed !== null && message !== null) {
1031
+ if (typed.primaryType !== "ReceiveWithAuthorization") fail("G1", "the authorization is not ReceiveWithAuthorization");
1032
+ const types = object(typed.types, "G1", "typedData.types");
1033
+ const fields = Array.isArray(types.ReceiveWithAuthorization) ? types.ReceiveWithAuthorization : fail("G1", "the authorization type is missing");
1034
+ if (fields.length !== AUTH_FIELDS.length || !fields.every((f, i) => isObject(f) && f.name === AUTH_FIELDS[i]?.[0] && f.type === AUTH_FIELDS[i]?.[1])) fail("G1", "the authorization type has other fields");
1035
+ const domain = object(typed.domain, "G1", "typedData.domain");
1036
+ if (Object.keys(domain).length !== 4 || domain.name !== "USD Coin" || domain.version !== "2") fail("G1", "the domain is not USD Coin version 2");
1037
+ if (!sameChain(domain.chainId, payChainId)) fail("G1", "the domain is on another chain");
1038
+ if (address(domain.verifyingContract, "G1", "verifyingContract") !== usdc) fail("G1", "the authorization is for another token");
1039
+ if (wallet === null || address(message.from, "G1", "message.from") !== wallet) fail("G1", "the authorization is from another wallet");
1040
+ if (integer(message.validAfter, "G1", "validAfter") !== 0n) fail("G1", "validAfter is not 0");
1041
+ }
1042
+ at("G2");
1043
+ const order = object(body.order, "G2", "order");
1044
+ const amount2 = units(request.amount, payDecimals, "G2", "amount");
1045
+ if (integer(order.amount, "G2", "order.amount") !== amount2) fail("G2", "the order amount is not the requested amount");
1046
+ if (message !== null && integer(message.value, "G2", "message.value") !== amount2) fail("G2", "the authorization moves another amount");
1047
+ const deadline = integer(order.deadline, "G2", "order.deadline");
1048
+ if (message !== null && integer(message.validBefore, "G2", "validBefore") > deadline) fail("G2", "the authorization outlives the order");
1049
+ if (deadline > BigInt(nowSec + (payChainId === chainId && payChainId !== 1 ? 900 : 1200) + GAS_SKEW_SEC)) fail("G2", "the order deadline is too far away");
1050
+ if (integer(order.chainId, "G2", "order.chainId") !== BigInt(payChainId)) fail("G2", "the order is on another chain");
1051
+ if (address(order.token, "G2", "order.token") !== usdc) fail("G2", "the order takes another token");
1052
+ const recipient = address(request.recipient, "G2", "recipient");
1053
+ if (address(order.recipient, "G2", "order.recipient") !== recipient) fail("G2", "the order pays another recipient");
1054
+ const swap = payChainId === chainId;
1055
+ const refundTo = request.refundTo !== void 0 ? address(request.refundTo, "G2", "refundTo") : wallet ?? (swap ? recipient : fail("G2", "the order has no refund address"));
1056
+ if (address(order.refundTo, "G2", "order.refundTo") !== refundTo) fail("G2", "the order refunds another address");
1057
+ const fee = integer(order.fee, "G2", "order.fee");
1058
+ if (fee >= amount2) fail("G2", "the fee takes the whole amount");
1059
+ if (fee !== units(object(body.fee, "G2", "fee").usdc, payDecimals, "G2", "fee.usdc")) fail("G2", "the order fee is not the fee shown");
1060
+ const minOut = integer(order.minOut, "G2", "order.minOut");
1061
+ if (minOut === 0n || minOut !== integer(object(body.receive, "G2", "receive").minimumWei, "G2", "receive.minimumWei")) fail("G2", "the order minimum is not the minimum shown");
1062
+ const dst = CHAINS.get(chainId) ?? fail("G2", "the delivery chain is not on the allowlist");
1063
+ if (!swap) {
1064
+ const relayFee = integer(order.relayFee, "G2", "order.relayFee");
1065
+ if (relayFee * 2n > amount2 - fee) fail("G2", "the relay fee is above half the amount");
1066
+ if (integer(order.outputAmount, "G2", "order.outputAmount") !== toDst(amount2 - fee - relayFee, payDecimals, dst.usdcDecimals)) fail("G2", "the bridged amount is not the amount after fees");
1067
+ }
1068
+ at("G3");
1069
+ if (body.kind !== (swap ? "swap" : "cross_chain")) fail("G3", "the order is of another kind");
1070
+ if (body.payChainId !== payChainId || body.chainId !== chainId) fail("G3", "the offer is for other chains");
1071
+ const spec = swap ? ALLOWLIST.gas.swap : ALLOWLIST.gas.cross_chain;
1072
+ if (address(body.factory, "G3", "factory") !== FACTORY) fail("G3", "the factory is not the pinned one");
1073
+ if (address(body.template, "G3", "template") !== low(spec.template)) fail("G3", "the template is not the pinned one");
1074
+ const pinned = (name, want) => {
1075
+ if (address(order[name], "G3", `order.${name}`) !== want) fail("G3", `order.${name} is not the pinned one`);
1076
+ };
1077
+ pinned("feeRecipient", FEE_RECIPIENT);
1078
+ if (integer(order.maxProtocolFeeBps, "G3", "order.maxProtocolFeeBps") !== 0n) fail("G3", "the order allows a protocol fee");
1079
+ if (swap) pinned("shell", dst.deliveryShell);
1080
+ else {
1081
+ pinned("router", gasPay.routerV3);
1082
+ pinned("adapter", gasPay.acrossUsdcAdapter);
1083
+ pinned("handler", HANDLER);
1084
+ pinned("dstToken", dst.usdc);
1085
+ pinned("dstShell", dst.deliveryShell);
1086
+ pinned("dstWrappedNative", dst.wrappedNative);
1087
+ const railId = bytes32(order.railId, "G3", "order.railId");
1088
+ if (railId !== gasPay.railId || pay.lanes.get(chainId)?.has(railId) !== true) fail("G3", "order.railId is not the pinned one");
1089
+ if (integer(order.dstChainId, "G3", "order.dstChainId") !== BigInt(chainId)) fail("G3", "the order delivers on another chain");
1090
+ if (integer(order.dstDecimals, "G3", "order.dstDecimals") !== BigInt(dst.usdcDecimals)) fail("G3", "order.dstDecimals is not the pinned one");
1091
+ }
1092
+ at("G4");
1093
+ const orderHash = keccakHex(`${low(spec.versionTag)}${encodeOrder(order, swap ? SWAP_ORDER : ACROSS_ORDER)}`);
1094
+ if (bytes32(body.orderHash, "G4", "orderHash") !== orderHash) fail("G4", "orderHash does not match the order");
1095
+ const payTo = `0x${keccakHex(`0xff${FACTORY.slice(2)}${orderHash.slice(2)}${low(spec.initCodeHash).slice(2)}`).slice(26)}`;
1096
+ if (address(body.payTo, "G4", "payTo") !== payTo) fail("G4", "payTo does not match the order");
1097
+ if (message !== null) {
1098
+ if (bytes32(message.nonce, "G4", "message.nonce") !== orderHash) fail("G4", "the authorization nonce is not the order hash");
1099
+ if (address(message.to, "G4", "message.to") !== payTo) fail("G4", "the authorization pays another address");
1100
+ }
1101
+ });
1102
+ }
1103
+ var PLAN_KEYS = ["requestId", "blocked", "requiresConfirmation", "route", "send", "pullsAtMost", "receive", "fees", "notices", "quotedAt", "validUntil", "calls", "next"];
1104
+ var CALL_KEYS = ["chainId", "from", "to", "data", "value"];
1105
+ var OFFER_KEYS = ["offer", "kind", "payChainId", "chainId", "payTo", "factory", "template", "order", "blob", "hubs", "message", "orderHash", "outcome", "pay", "fee", "receive", "deadline", "refundTo", "typedData", "etaSec", "verify"];
1106
+ var SUBMIT_KEYS = ["requestId", "state", "payTo", "deadline"];
1107
+ var ERROR_KEYS = ["code", "reason", "message", "detail", "retryable", "retryAfterSec", "suggestion", "notices"];
1108
+ var DOMAIN_KEYS = ["name", "version", "chainId", "verifyingContract"];
1109
+ var MESSAGE_KEYS = AUTH_FIELDS.map(([name]) => name);
1110
+ function pick(source, keys) {
1111
+ const out = {};
1112
+ for (const k of keys) if (k in source) out[k] = source[k];
1113
+ return out;
1114
+ }
1115
+ function apiRefusal(body) {
1116
+ if (!isObject(body.error)) return null;
1117
+ return { ...pick(body, ["apiVersion", "requestId"]), error: pick(body.error, ERROR_KEYS) };
1118
+ }
1119
+ function addressRefusal(message) {
1120
+ return { error: { code: "address_not_allowed", message, retryable: false } };
1121
+ }
1122
+ function screenPlanSwap(request, body) {
1123
+ const refusal = apiRefusal(body);
1124
+ if (refusal !== null) return refusal;
1125
+ const result = checkPlanSwap(request, body);
1126
+ if (!result.ok) return addressRefusal(result.message);
1127
+ const out = pick(body, PLAN_KEYS);
1128
+ out.calls = body.calls.map((c) => pick(c, CALL_KEYS));
1129
+ return out;
1130
+ }
1131
+ function screenGetGas(request, body, nowSec) {
1132
+ const refusal = apiRefusal(body);
1133
+ if (refusal !== null) return refusal;
1134
+ const result = checkGetGas(request, body, nowSec);
1135
+ if (!result.ok) return addressRefusal(result.message);
1136
+ if (request.offer !== void 0) return pick(body, SUBMIT_KEYS);
1137
+ const out = pick(body, OFFER_KEYS);
1138
+ if (isObject(body.typedData)) {
1139
+ const t = body.typedData;
1140
+ out.typedData = {
1141
+ domain: pick(t.domain, DOMAIN_KEYS),
1142
+ types: { ReceiveWithAuthorization: t.types.ReceiveWithAuthorization.map((f) => pick(f, ["name", "type"])) },
1143
+ primaryType: t.primaryType,
1144
+ message: pick(t.message, MESSAGE_KEYS)
1145
+ };
1146
+ }
1147
+ return out;
1148
+ }
1149
+
36
1150
  var DEFAULT_BASE_URL = "https://api.cleave.fi";
37
1151
  var DEFAULT_TIMEOUT_MS = 3e4;
38
- var USER_AGENT = `cleave-ai-sdk/${"0.1.0"}`;
1152
+ var USER_AGENT = `cleave-ai-sdk/${"0.1.1"}`;
39
1153
  var CleaveApiError = class extends Error {
40
1154
  status;
41
1155
  requestId;
@@ -52,6 +1166,9 @@ function untilAborted(signal) {
52
1166
  else signal.addEventListener("abort", () => reject(signal.reason), { once: true });
53
1167
  });
54
1168
  }
1169
+ function httpError(status) {
1170
+ return { error: { code: "http_error", message: `HTTP ${status}`, retryable: status >= 500 || status === 429 } };
1171
+ }
55
1172
  async function callTool(endpoint, input, options, abortSignal) {
56
1173
  const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
57
1174
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
@@ -76,17 +1193,19 @@ async function callTool(endpoint, input, options, abortSignal) {
76
1193
  try {
77
1194
  body = JSON.parse(text);
78
1195
  } catch (err) {
1196
+ if (!response.ok) return httpError(response.status);
79
1197
  throw new CleaveApiError(`Cleave API answered HTTP ${response.status} without a JSON body`, response.status, requestId, { cause: err });
80
1198
  }
81
- if (typeof body !== "object" || body === null || Array.isArray(body)) throw new CleaveApiError(`Cleave API answered HTTP ${response.status} without a JSON object`, response.status, requestId);
82
- if (!response.ok && !("error" in body)) throw new CleaveApiError(`Cleave API answered HTTP ${response.status} without an error body`, response.status, requestId);
1199
+ const isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1200
+ if (!response.ok) return isObject2(body) && isObject2(body.error) ? body : httpError(response.status);
1201
+ if (!isObject2(body)) throw new CleaveApiError(`Cleave API answered HTTP ${response.status} without a JSON object`, response.status, requestId);
83
1202
  return body;
84
1203
  }
85
1204
 
86
1205
  var import_v4 = require("zod/v4");
87
1206
  var CHAIN_IDS = [1, 10, 56, 137, 8453, 42161];
88
1207
  var chain = (description) => import_v4.z.literal(CHAIN_IDS).meta({ type: "integer" }).describe(description);
89
- var address = (description) => import_v4.z.string().regex(/^0x[0-9a-fA-F]{40}$/).describe(description);
1208
+ var address2 = (description) => import_v4.z.string().regex(/^0x[0-9a-fA-F]{40}$/).describe(description);
90
1209
  var token = (description) => import_v4.z.string().min(1).max(64).describe(description);
91
1210
  var amount = (description) => import_v4.z.string().regex(/^[0-9]+(\.[0-9]+)?$/).describe(description);
92
1211
  var planSwapInput = import_v4.z.strictObject({
@@ -95,8 +1214,8 @@ var planSwapInput = import_v4.z.strictObject({
95
1214
  sellToken: token("The token to sell: a listed symbol or a contract address"),
96
1215
  buyToken: token("The token to receive: a listed symbol or a contract address"),
97
1216
  amount: amount('Decimal amount of sellToken in token units, such as "25.5"'),
98
- wallet: address("The wallet that signs and pays"),
99
- recipient: address("Who receives; defaults to wallet").optional(),
1217
+ wallet: address2("The wallet that signs and pays"),
1218
+ recipient: address2("Who receives; defaults to wallet").optional(),
100
1219
  maxSlippageBps: import_v4.z.number().int().min(0).max(5e3).describe("Slippage limit in basis points, 0 to 5000").optional()
101
1220
  });
102
1221
  var trackSwapInput = import_v4.z.strictObject({
@@ -111,29 +1230,29 @@ var findTokenInput = import_v4.z.strictObject({
111
1230
  var getGasInput = import_v4.z.strictObject({
112
1231
  payChainId: chain("Chain id the USDC is paid on (first call)").optional(),
113
1232
  chainId: chain("Chain id the native coin is delivered on (first call)").optional(),
114
- recipient: address("Who receives the native coin (first call)").optional(),
1233
+ recipient: address2("Who receives the native coin (first call)").optional(),
115
1234
  amount: amount('USDC to pay, as a decimal string such as "5" (first call)').optional(),
116
- wallet: address("The paying wallet; with it, the offer carries the authorization to sign. Required on the second call").optional(),
117
- refundTo: address("Where a refund goes on the pay chain (first call)").optional(),
1235
+ wallet: address2("The paying wallet; with it, the offer carries the authorization to sign. Required on the second call").optional(),
1236
+ refundTo: address2("Where a refund goes on the pay chain (first call)").optional(),
118
1237
  offer: import_v4.z.string().min(1).max(4096).describe("The offer string from the first call (second call)").optional(),
119
1238
  signature: import_v4.z.string().regex(/^0x[0-9a-fA-F]+$/).describe("The wallet's signature of the offer's typedData (second call)").optional()
120
1239
  });
121
1240
 
122
1241
  var DESCRIPTIONS = {
123
- planSwap: "Plans a token swap on one chain, a cross-chain swap or bridge, or a native-gas top-up on Ethereum, Arbitrum, Base, BNB Chain, Polygon or Optimism, and returns unsigned transactions for the given wallet to sign. It fits when the user wants to exchange tokens, move them between these chains, or get ETH, BNB or POL for gas. It sends nothing and moves no funds. The answer leads with blocking notices and warnings, then gives the route's outcome kind (exact or at least a minimum; with a swap on arrival, the token, else a named fallback; where a transfer can go unfilled, a refund of the bridged token on the source chain hours later), every third-party cost except network gas, the expected time, validUntil and the calls in signing order. A blocking notice returns no calls; a warning, or a recipient other than the wallet, sets requiresConfirmation, and the connection's settings can turn either into a refusal. Calls sent after validUntil are stale: they can revert or, on some routes, end in a refund hours later. Amounts are decimal strings in token units; tokens are listed symbols or contract addresses; the recipient defaults to the wallet. Limits set in the connection (a pinned wallet, a per-plan USD cap, listed tokens only) bound every argument. For an ambiguous symbol, cleave_find_token lists the candidates; after sending, cleave_track_swap reports progress. A wallet with no gas can get it with cleave_get_gas.",
1242
+ planSwap: "Plans a token swap on one chain, a cross-chain swap or bridge, or a native-gas top-up on Ethereum, Arbitrum, Base, BNB Chain, Polygon or Optimism, and returns unsigned transactions for the given wallet to sign. It fits when the user wants to exchange tokens, move them between these chains, or get ETH, BNB or POL for gas. It sends nothing and moves no funds. The answer leads with blocking notices and warnings, then gives the route's outcome kind (an exact amount or one that can vary; with a swap on arrival, the token, else a named fallback; where a transfer can go unfilled, a refund of the bridged token on the source chain hours later), every third-party cost except network gas, the expected time, validUntil and the calls in signing order. A blocking notice returns no calls; a warning, or a recipient other than the wallet, sets requiresConfirmation. Calls sent after validUntil are stale: they can revert or, on some routes, end in a refund hours later. Amounts are decimal strings in token units; tokens are listed symbols or contract addresses; the recipient defaults to the wallet. The token to receive must be on Cleave's token list. For an ambiguous symbol, cleave_find_token lists the candidates; after sending, cleave_track_swap reports progress. A wallet with no gas can get it with cleave_get_gas.",
124
1243
  trackSwap: "Reports the status of a swap, bridge or gas top-up that was planned with cleave_plan_swap and then sent, or ordered with cleave_get_gas: its state (for example pending, in flight, delivered, refund pending or refunded), what arrived against the plan and on which chain, and the next action or when to check again. It takes the chain and transaction hash, plus the plan's requestId when known, or for a gas top-up the requestId alone; a transaction to a contract outside Cleave's published list is reported as such. It fits when the user asks whether such a transfer arrived, and before any re-send, because re-sending a plan that is still in flight can pay twice. It reports states only and returns no transactions.",
125
1244
  findToken: "Finds a token by symbol or contract address on Ethereum, Arbitrum, Base, BNB Chain, Polygon or Optimism and returns its address, decimals and whether it is on Cleave's token list, with a flag when it resembles a listed token. A symbol shared by several listed tokens returns every candidate by address instead of picking one. An unlisted token is found only by its address and comes back flagged, without a name or symbol. It fits before cleave_plan_swap when the user names a token by symbol and the address is unknown.",
126
- getGas: "Gets native gas (ETH, BNB or POL) on Ethereum, Arbitrum, Base, BNB Chain, Polygon or Optimism for a wallet that holds USDC on Ethereum, Arbitrum, Base, Optimism or Polygon but has no gas to send transactions. Called with the paying chain, the receiving chain, the recipient and a USDC amount, it returns an offer: the fee, the minimum native amount, the deadline, the order and one USDC authorization for the wallet to sign; signing costs no gas. Called again with the offer and the signature, it passes the signed order to Cleave's relayer, which executes it through a contract made for that one order, and returns a requestId for cleave_track_swap. On one chain the recipient gets at least the minimum or nothing moves; from another chain it gets the native coin at the minimum, else USDC on arrival if the arrival swap fails. An order not executed by its deadline is refunded to the refund address, or, if paid from another chain and not filled, refunded hours later. When the wallet already holds some gas, cleave_plan_swap plans a swap to the native coin."
1245
+ getGas: "Gets native gas (ETH, BNB or POL) on Ethereum, Arbitrum, Base, BNB Chain, Polygon or Optimism for a wallet that holds USDC on Ethereum, Arbitrum, Base, Optimism or Polygon but has no gas to send transactions. Called with the paying chain, the receiving chain, the recipient and a USDC amount, it returns an offer: the fee, the minimum native amount, the deadline, the order and one USDC authorization for the wallet to sign; signing costs no gas. Called again with the offer and the signature, it passes the signed order to Cleave's relayer, which executes it through a contract made for that one order, and returns a requestId for cleave_track_swap. On one chain the order swaps the USDC to the native coin for the recipient; from another chain it bridges the USDC and swaps it on arrival, delivering USDC instead if that swap fails. An order not executed by its deadline is refunded to the refund address, or, if paid from another chain and not filled, refunded hours later. When the wallet already holds some gas, cleave_plan_swap plans a swap to the native coin."
127
1246
  };
128
1247
  var NAMES = " In this package, cleave_plan_swap, cleave_track_swap, cleave_find_token and cleave_get_gas are the tools planSwap, trackSwap, findToken and getGas.";
129
- var PLAN_SUFFIX = " This package has no connection settings, and the token to receive must be on Cleave's token list. Before any wallet signs, show the user the warnings, recipient, amounts and slippage, and get their confirmation. Do not raise slippage above the default 50 bps without the user's consent.";
1248
+ var PLAN_SUFFIX = " Before any wallet signs, show the user the warnings, recipient, amounts and slippage, and get their confirmation. Do not raise slippage above the default 50 bps without the user's consent.";
130
1249
  var GAS_SUFFIX = " If a submission fails or times out, the order may still have been accepted: track g:<payChainId>:<orderHash> before signing a new offer.";
131
1250
  function planSwap(options = {}) {
132
1251
  return (0, import_ai.tool)({
133
1252
  title: "Plan a swap, bridge or gas top-up",
134
1253
  description: DESCRIPTIONS.planSwap + PLAN_SUFFIX + NAMES,
135
1254
  inputSchema: planSwapInput,
136
- execute: (input, { abortSignal }) => callTool("plan_swap", input, options, abortSignal)
1255
+ execute: async (input, { abortSignal }) => screenPlanSwap(input, await callTool("plan_swap", input, options, abortSignal))
137
1256
  });
138
1257
  }
139
1258
  function trackSwap(options = {}) {
@@ -158,7 +1277,7 @@ function getGas(options = {}) {
158
1277
  description: DESCRIPTIONS.getGas + GAS_SUFFIX + NAMES,
159
1278
  inputSchema: getGasInput,
160
1279
  needsApproval: options.getGasApproval === false ? false : (input) => input.signature !== void 0,
161
- execute: (input, { abortSignal }) => callTool("get_gas", input, options, abortSignal)
1280
+ execute: async (input, { abortSignal }) => screenGetGas(input, await callTool("get_gas", input, options, abortSignal))
162
1281
  });
163
1282
  }
164
1283
  function cleaveTools(options = {}) {
@@ -169,9 +1288,13 @@ function cleaveTools(options = {}) {
169
1288
  CleaveApiError,
170
1289
  DEFAULT_BASE_URL,
171
1290
  DEFAULT_TIMEOUT_MS,
1291
+ checkGetGas,
1292
+ checkPlanSwap,
172
1293
  cleaveTools,
173
1294
  findToken,
174
1295
  getGas,
175
1296
  planSwap,
1297
+ screenGetGas,
1298
+ screenPlanSwap,
176
1299
  trackSwap
177
1300
  });