@anywalletkit/protocol-swap2-lifi 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -28,7 +28,8 @@ __export(src_exports, {
28
28
  describeLifiActivity: () => describeLifiActivity,
29
29
  lifi: () => lifi,
30
30
  lifiPins: () => lifiPins,
31
- lifiProvider: () => lifiProvider
31
+ lifiProvider: () => lifiProvider,
32
+ lifiVerifyQuote: () => lifiVerifyQuote
32
33
  });
33
34
  module.exports = __toCommonJS(src_exports);
34
35
 
@@ -100,144 +101,162 @@ var GENERIC_SWAPS = {
100
101
  var BRIDGE_INPUT_FEE_MAX_BPS = 100n;
101
102
  var kindOf = (asset) => /^0x0{40}$/i.test(asset) ? "native" : "erc20";
102
103
  var BRIDGE_CALLS = {
103
- "0x1fd8010c": { sourceSwaps: false },
104
+ "0x1fd8010c": { sourceSwaps: false, facet: "Across" },
104
105
  // startBridgeTokensViaAcross (AcrossFacet)
105
- "0x3a3f7332": { sourceSwaps: true },
106
+ "0x3a3f7332": { sourceSwaps: true, facet: "Across" },
106
107
  // swapAndStartBridgeTokensViaAcross (AcrossFacet)
107
- "0xa1f1ce43": { sourceSwaps: false },
108
+ "0xa1f1ce43": { sourceSwaps: false, facet: "AcrossV4" },
108
109
  // startBridgeTokensViaAcrossV4 (AcrossFacetV4)
109
- "0x1794958f": { sourceSwaps: true },
110
+ "0x1794958f": { sourceSwaps: true, facet: "AcrossV4" },
110
111
  // swapAndStartBridgeTokensViaAcrossV4 (AcrossFacetV4)
111
- "0x6a90d66e": { sourceSwaps: false },
112
+ "0x6a90d66e": { sourceSwaps: false, facet: "AcrossV4Swap" },
112
113
  // startBridgeTokensViaAcrossV4Swap (AcrossV4SwapFacet)
113
- "0x9b054bc4": { sourceSwaps: true },
114
+ "0x9b054bc4": { sourceSwaps: true, facet: "AcrossV4Swap" },
114
115
  // swapAndStartBridgeTokensViaAcrossV4Swap (AcrossV4SwapFacet)
115
- "0x6a51e9a9": { sourceSwaps: false },
116
+ "0x6a51e9a9": { sourceSwaps: false, facet: "AllBridge" },
116
117
  // startBridgeTokensViaAllBridge (AllBridgeFacet)
117
- "0x63267469": { sourceSwaps: true },
118
+ "0x63267469": { sourceSwaps: true, facet: "AllBridge" },
118
119
  // swapAndStartBridgeTokensViaAllBridge (AllBridgeFacet)
119
- "0xc9851d0b": { sourceSwaps: false },
120
+ "0xc9851d0b": { sourceSwaps: false, facet: "ArbitrumBridge" },
120
121
  // startBridgeTokensViaArbitrumBridge (ArbitrumBridgeFacet)
121
- "0x3cc9517b": { sourceSwaps: true },
122
+ "0x3cc9517b": { sourceSwaps: true, facet: "ArbitrumBridge" },
122
123
  // swapAndStartBridgeTokensViaArbitrumBridge (ArbitrumBridgeFacet)
123
- "0xe0a4201c": { sourceSwaps: false },
124
+ "0xe0a4201c": { sourceSwaps: false, facet: "CelerCircleBridge" },
124
125
  // startBridgeTokensViaCelerCircleBridge (CelerCircleBridgeFacet)
125
- "0x4f3b0759": { sourceSwaps: true },
126
+ "0x4f3b0759": { sourceSwaps: true, facet: "CelerCircleBridge" },
126
127
  // swapAndStartBridgeTokensViaCelerCircleBridge (CelerCircleBridgeFacet)
127
- "0x0315138f": { sourceSwaps: false },
128
+ "0x0315138f": { sourceSwaps: false, facet: "Centrifuge" },
128
129
  // startBridgeTokensViaCentrifuge (CentrifugeFacet)
129
- "0x8fd4d4dd": { sourceSwaps: true },
130
+ "0x8fd4d4dd": { sourceSwaps: true, facet: "Centrifuge" },
130
131
  // swapAndStartBridgeTokensViaCentrifuge (CentrifugeFacet)
131
- "0x0ad553b3": { sourceSwaps: false },
132
+ "0x0ad553b3": { sourceSwaps: false, facet: "Chainflip" },
132
133
  // startBridgeTokensViaChainflip (ChainflipFacet)
133
- "0xee3314a1": { sourceSwaps: true },
134
+ "0xee3314a1": { sourceSwaps: true, facet: "Chainflip" },
134
135
  // swapAndStartBridgeTokensViaChainflip (ChainflipFacet)
135
- "0x4004633e": { sourceSwaps: false },
136
- // startBridgeTokensViaDeBridgeDln (DeBridgeDlnFacet)
137
- "0x2c7d2db0": { sourceSwaps: true },
138
- // swapAndStartBridgeTokensViaDeBridgeDln (DeBridgeDlnFacet)
139
- "0xbff90b61": { sourceSwaps: false },
136
+ "0xbff90b61": { sourceSwaps: false, facet: "Eco" },
140
137
  // startBridgeTokensViaEco (EcoFacet)
141
- "0x762aea18": { sourceSwaps: true },
138
+ "0x762aea18": { sourceSwaps: true, facet: "Eco" },
142
139
  // swapAndStartBridgeTokensViaEco (EcoFacet)
143
- "0x678786ea": { sourceSwaps: false },
140
+ "0x678786ea": { sourceSwaps: false, facet: "Frax" },
144
141
  // startBridgeTokensViaFrax (FraxFacet)
145
- "0x07b8e4c7": { sourceSwaps: true },
142
+ "0x07b8e4c7": { sourceSwaps: true, facet: "Frax" },
146
143
  // swapAndStartBridgeTokensViaFrax (FraxFacet)
147
- "0x5f9af35d": { sourceSwaps: false },
148
- // startBridgeTokensViaGarden (GardenFacet)
149
- "0x76ad76fe": { sourceSwaps: true },
150
- // swapAndStartBridgeTokensViaGarden (GardenFacet)
151
- "0xfc5f1003": { sourceSwaps: false },
144
+ "0xfc5f1003": { sourceSwaps: false, facet: "GasZip" },
152
145
  // startBridgeTokensViaGasZip (GasZipFacet)
153
- "0x606326ff": { sourceSwaps: true },
146
+ "0x606326ff": { sourceSwaps: true, facet: "GasZip" },
154
147
  // swapAndStartBridgeTokensViaGasZip (GasZipFacet)
155
- "0x6f9206ba": { sourceSwaps: false },
148
+ "0x6f9206ba": { sourceSwaps: false, facet: "Glacis" },
156
149
  // startBridgeTokensViaGlacis (GlacisFacet)
157
- "0x9c4b6dd9": { sourceSwaps: true },
150
+ "0x9c4b6dd9": { sourceSwaps: true, facet: "Glacis" },
158
151
  // swapAndStartBridgeTokensViaGlacis (GlacisFacet)
159
- "0xf66fe519": { sourceSwaps: false },
152
+ "0xf66fe519": { sourceSwaps: false, facet: "GnosisBridge" },
160
153
  // startBridgeTokensViaGnosisBridge (GnosisBridgeFacet)
161
- "0x7bf96e0a": { sourceSwaps: true },
154
+ "0x7bf96e0a": { sourceSwaps: true, facet: "GnosisBridge" },
162
155
  // swapAndStartBridgeTokensViaGnosisBridge (GnosisBridgeFacet)
163
- "0xee9e98e0": { sourceSwaps: false },
156
+ "0xee9e98e0": { sourceSwaps: false, facet: "LayerSwap" },
164
157
  // startBridgeTokensViaLayerSwap (LayerSwapFacet)
165
- "0x4c279d6b": { sourceSwaps: true },
158
+ "0x4c279d6b": { sourceSwaps: true, facet: "LayerSwap" },
166
159
  // swapAndStartBridgeTokensViaLayerSwap (LayerSwapFacet)
167
- "0x7dbcf1d9": { sourceSwaps: false },
160
+ "0x7dbcf1d9": { sourceSwaps: false, facet: "LiFiIntentEscrowV2" },
168
161
  // startBridgeTokensViaLiFiIntentEscrowV2 (LiFiIntentEscrowFacetV2)
169
- "0x6d21c5df": { sourceSwaps: true },
162
+ "0x6d21c5df": { sourceSwaps: true, facet: "LiFiIntentEscrowV2" },
170
163
  // swapAndStartBridgeTokensViaLiFiIntentEscrowV2 (LiFiIntentEscrowFacetV2)
171
- "0x65782c4b": { sourceSwaps: false },
164
+ "0x65782c4b": { sourceSwaps: false, facet: "M0" },
172
165
  // startBridgeTokensViaM0 (M0Facet)
173
- "0xb9eaf86d": { sourceSwaps: true },
166
+ "0xb9eaf86d": { sourceSwaps: true, facet: "M0" },
174
167
  // swapAndStartBridgeTokensViaM0 (M0Facet)
175
- "0xb4875292": { sourceSwaps: false },
168
+ "0xb4875292": { sourceSwaps: false, facet: "Mayan" },
176
169
  // startBridgeTokensViaMayan (MayanFacet)
177
- "0x80c65808": { sourceSwaps: true },
170
+ "0x80c65808": { sourceSwaps: true, facet: "Mayan" },
178
171
  // swapAndStartBridgeTokensViaMayan (MayanFacet)
179
- "0x4213dfff": { sourceSwaps: false },
172
+ "0x4213dfff": { sourceSwaps: false, facet: "MegaETHBridge" },
180
173
  // startBridgeTokensViaMegaETHBridge (MegaETHBridgeFacet)
181
- "0x22256e89": { sourceSwaps: true },
174
+ "0x22256e89": { sourceSwaps: true, facet: "MegaETHBridge" },
182
175
  // swapAndStartBridgeTokensViaMegaETHBridge (MegaETHBridgeFacet)
183
- "0x4698f032": { sourceSwaps: false },
176
+ "0x4698f032": { sourceSwaps: false, facet: "NEARIntents" },
184
177
  // startBridgeTokensViaNEARIntents (NEARIntentsFacet)
185
- "0x02631b09": { sourceSwaps: true },
178
+ "0x02631b09": { sourceSwaps: true, facet: "NEARIntents" },
186
179
  // swapAndStartBridgeTokensViaNEARIntents (NEARIntentsFacet)
187
- "0x782621d8": { sourceSwaps: false },
180
+ "0x782621d8": { sourceSwaps: false, facet: "OmniBridge" },
188
181
  // startBridgeTokensViaOmniBridge (OmniBridgeFacet)
189
- "0x95726782": { sourceSwaps: true },
182
+ "0x95726782": { sourceSwaps: true, facet: "OmniBridge" },
190
183
  // swapAndStartBridgeTokensViaOmniBridge (OmniBridgeFacet)
191
- "0xce8a97a5": { sourceSwaps: false },
184
+ "0xce8a97a5": { sourceSwaps: false, facet: "OptimismBridge" },
192
185
  // startBridgeTokensViaOptimismBridge (OptimismBridgeFacet)
193
- "0x5bb5d448": { sourceSwaps: true },
186
+ "0x5bb5d448": { sourceSwaps: true, facet: "OptimismBridge" },
194
187
  // swapAndStartBridgeTokensViaOptimismBridge (OptimismBridgeFacet)
195
- "0xaf62c7d6": { sourceSwaps: false },
188
+ "0xaf62c7d6": { sourceSwaps: false, facet: "PolygonBridge" },
196
189
  // startBridgeTokensViaPolygonBridge (PolygonBridgeFacet)
197
- "0xb4f37581": { sourceSwaps: true },
190
+ "0xb4f37581": { sourceSwaps: true, facet: "PolygonBridge" },
198
191
  // swapAndStartBridgeTokensViaPolygonBridge (PolygonBridgeFacet)
199
- "0xf434d6ca": { sourceSwaps: false },
192
+ "0xf434d6ca": { sourceSwaps: false, facet: "PolymerCCTP" },
200
193
  // startBridgeTokensViaPolymerCCTP (PolymerCCTPFacet)
201
- "0x17917a4e": { sourceSwaps: true },
194
+ "0x17917a4e": { sourceSwaps: true, facet: "PolymerCCTP" },
202
195
  // swapAndStartBridgeTokensViaPolymerCCTP (PolymerCCTPFacet)
203
- "0x092e8fa4": { sourceSwaps: false },
204
- // startBridgeTokensViaRelayDepository (RelayDepositoryFacet)
205
- "0xa3443faa": { sourceSwaps: true },
206
- // swapAndStartBridgeTokensViaRelayDepository (RelayDepositoryFacet)
207
- "0x3f313808": { sourceSwaps: false },
208
- // startBridgeTokensViaSquid (SquidFacet)
209
- "0xa8f66666": { sourceSwaps: true },
210
- // swapAndStartBridgeTokensViaSquid (SquidFacet)
211
- "0x14d53077": { sourceSwaps: false },
196
+ "0x14d53077": { sourceSwaps: false, facet: "Stargate" },
212
197
  // startBridgeTokensViaStargate (StargateFacetV2)
213
- "0xa6010a66": { sourceSwaps: true },
198
+ "0xa6010a66": { sourceSwaps: true, facet: "Stargate" },
214
199
  // swapAndStartBridgeTokensViaStargate (StargateFacetV2)
215
- "0x0691ff78": { sourceSwaps: false },
200
+ "0x0691ff78": { sourceSwaps: false, facet: "Superset" },
216
201
  // startBridgeTokensViaSuperset (SupersetFacet)
217
- "0xf26e657f": { sourceSwaps: true },
202
+ "0xf26e657f": { sourceSwaps: true, facet: "Superset" },
218
203
  // swapAndStartBridgeTokensViaSuperset (SupersetFacet)
219
- "0xe23b7a08": { sourceSwaps: false },
220
- // startBridgeTokensViaSymbiosis (SymbiosisFacet)
221
- "0xc46059b2": { sourceSwaps: true },
222
- // swapAndStartBridgeTokensViaSymbiosis (SymbiosisFacet)
223
- "0x2541ec57": { sourceSwaps: false },
224
- // startBridgeTokensViaThorSwap (ThorSwapFacet)
225
- "0xad673d88": { sourceSwaps: true },
226
- // swapAndStartBridgeTokensViaThorSwap (ThorSwapFacet)
227
- "0x64261d58": { sourceSwaps: false },
204
+ "0x64261d58": { sourceSwaps: false, facet: "Unit" },
228
205
  // startBridgeTokensViaUnit (UnitFacet)
229
- "0x21a3af52": { sourceSwaps: true }
206
+ "0x21a3af52": { sourceSwaps: true, facet: "Unit" }
230
207
  // swapAndStartBridgeTokensViaUnit (UnitFacet)
231
208
  };
232
- var Reader = class {
209
+ var UNBOUND_BRIDGES = {
210
+ "0x092e8fa4": "Relay",
211
+ // startBridgeTokensViaRelayDepository
212
+ "0xa3443faa": "Relay",
213
+ // swapAndStartBridgeTokensViaRelayDepository
214
+ "0x5f9af35d": "Garden",
215
+ // startBridgeTokensViaGarden
216
+ "0x76ad76fe": "Garden",
217
+ // swapAndStartBridgeTokensViaGarden
218
+ "0x4004633e": "deBridge DLN",
219
+ // startBridgeTokensViaDeBridgeDln
220
+ "0x2c7d2db0": "deBridge DLN",
221
+ // swapAndStartBridgeTokensViaDeBridgeDln
222
+ "0x2541ec57": "ThorSwap",
223
+ // startBridgeTokensViaThorSwap
224
+ "0xad673d88": "ThorSwap",
225
+ // swapAndStartBridgeTokensViaThorSwap
226
+ "0x3f313808": "Squid",
227
+ // startBridgeTokensViaSquid
228
+ "0xa8f66666": "Squid",
229
+ // swapAndStartBridgeTokensViaSquid
230
+ "0xe23b7a08": "Symbiosis",
231
+ // startBridgeTokensViaSymbiosis
232
+ "0xc46059b2": "Symbiosis"
233
+ // swapAndStartBridgeTokensViaSymbiosis
234
+ };
235
+ var Reader = class _Reader {
233
236
  b;
234
- constructor(hex) {
235
- if (!/^0x([0-9a-fA-F]{2})*$/.test(hex)) throw new Error("not hex");
236
- this.b = Uint8Array.from(hex.slice(2).match(/../g) ?? [], (h) => Number.parseInt(h, 16));
237
+ constructor(src) {
238
+ if (typeof src !== "string") {
239
+ this.b = src;
240
+ return;
241
+ }
242
+ if (!/^0x([0-9a-fA-F]{2})*$/.test(src)) throw new Error("not hex");
243
+ this.b = Uint8Array.from(src.slice(2).match(/../g) ?? [], (h) => Number.parseInt(h, 16));
237
244
  }
238
245
  get length() {
239
246
  return this.b.length;
240
247
  }
248
+ /** `n` raw bytes at `at`, as 0x-hex. */
249
+ raw(at, n) {
250
+ if (at < 0 || at + n > this.b.length) throw new Error("out of bounds");
251
+ return `0x${Array.from(this.b.subarray(at, at + n), (x) => x.toString(16).padStart(2, "0")).join("")}`;
252
+ }
253
+ /** The `bytes` whose offset word sits at `head` (relative to `base`), as a reader over its contents only. */
254
+ bytes(base, head) {
255
+ const at = base + this.small(head);
256
+ const n = this.small(at);
257
+ if (at + 32 + n > this.b.length) throw new Error("bytes out of bounds");
258
+ return new _Reader(this.b.subarray(at + 32, at + 32 + n));
259
+ }
241
260
  word(at) {
242
261
  if (at < 0 || at + 32 > this.b.length) throw new Error("out of bounds");
243
262
  let v = 0n;
@@ -295,6 +314,79 @@ function checkSteps(steps, e, finalAsset) {
295
314
  if (!same(last.receivingAssetId, finalAsset)) return `delivers ${last.receivingAssetId}, not ${finalAsset}`;
296
315
  return null;
297
316
  }
317
+ var MAYAN_REFUND_AT = {
318
+ "0xa3a30834": 4 + 32 * 3,
319
+ // Swift v2 createOrderWithToken(tokenIn, amountIn, (payloadType, trader, destAddr, …), customPayload)
320
+ "0x6147435b": 4 + 32 * 3,
321
+ // Swift v2 createOrderWithSig: the same order tuple
322
+ "0xb866e173": 4,
323
+ // Swift createOrderWithEth((trader, tokenOut, …))
324
+ "0x8e8d142b": 4 + 32 * 2,
325
+ // Swift createOrderWithToken(tokenIn, amountIn, (trader, tokenOut, …))
326
+ "0x6111ad25": 4 + 32 * 9,
327
+ // MayanSwap swap(relayerFees, (mayanAddr, mayanChainId, auctionAddr, destAddr, destChainId, referrer, refundAddr), …)
328
+ "0x1eb1cff0": 4 + 32 * 9
329
+ // MayanSwap wrapAndSwapETH: the same recipient tuple
330
+ };
331
+ function mayanRefunds(r, at) {
332
+ const p = r.bytes(at, at + 32 * 2);
333
+ const pos = MAYAN_REFUND_AT[p.raw(0, 4)];
334
+ return pos === void 0 ? [] : [["the Mayan order's refund address", p.address(pos)]];
335
+ }
336
+ function chainflipRefunds(r, at) {
337
+ const p = r.bytes(at, at + 32 * 5);
338
+ if (p.length < 25 || p.raw(0, 1) !== "0x01") throw new Error("unknown Chainflip parameters");
339
+ return [["the Chainflip refund address", p.raw(5, 20)]];
340
+ }
341
+ function acrossSwapRefunds(r, at) {
342
+ const target = r.word(at);
343
+ const c = r.bytes(at, at + 32);
344
+ if (target === 0n) return [["the Across deposit's depositor", c.address(c.small(0)), true]];
345
+ if (target === 1n) {
346
+ const swap = c.small(0);
347
+ return [["the Across deposit's depositor", c.address(swap + c.small(swap + 64) + 96), true]];
348
+ }
349
+ if (target === 2n) return [["the sponsored OFT refund recipient", c.address(c.small(0) + 32), true]];
350
+ if (target === 3n) return [["the sponsored CCTP refund recipient", c.address(64), true]];
351
+ throw new Error("unknown Across Swap API target");
352
+ }
353
+ var FACET_DATA = {
354
+ AcrossV4: { refunds: [["refundAddress", 1]], zeroRefused: true },
355
+ // the SpokePool depositor: an expired deposit refunds the input there
356
+ AcrossV4Swap: { nested: acrossSwapRefunds },
357
+ Centrifuge: { inline: 2, refunds: [["refundRecipient", 1]], zeroRefused: true },
358
+ Chainflip: { nested: chainflipRefunds },
359
+ Eco: { refunds: [["refundRecipient", 5]], zeroRefused: true },
360
+ // the intent's creator, refunded its reward (the input) on expiry
361
+ Frax: { inline: 5, refunds: [["refundRecipient", 3]], zeroRefused: true },
362
+ Glacis: { inline: 4, refunds: [["refundAddress", 1]], zeroRefused: true },
363
+ LayerSwap: { refunds: [["refundRecipient", 2]], zeroRefused: true },
364
+ LiFiIntentEscrowV2: { refunds: [["depositAndRefundAddress", 2]], zeroRefused: true },
365
+ // the escrow order's user
366
+ M0: { inline: 7, refunds: [["refundRecipient", 1], ["orderOwner", 2]], zeroRefused: true },
367
+ // orderOwner gets a cancelled order back
368
+ Mayan: { refunds: [["refundRecipient", 7]], nested: mayanRefunds, zeroRefused: true },
369
+ NEARIntents: { refunds: [["refundRecipient", 6]], zeroRefused: true },
370
+ // also the 1Click quote's refundTo
371
+ PolymerCCTP: { refunds: [["refundRecipient", 5]], zeroRefused: true },
372
+ Stargate: { refunds: [["refundAddress", 4]] },
373
+ // (assetId, sendParams, fee.nativeFee, fee.lzTokenFee, refundAddress): LayerZero's fee refund
374
+ Superset: { refunds: [["refundAddress", 2], ["fallbackEoA", 3]], zeroRefused: true }
375
+ };
376
+ var NO_REFUND_FIELDS = /* @__PURE__ */ new Set(["Across", "AllBridge", "ArbitrumBridge", "CelerCircleBridge", "GasZip", "GnosisBridge", "MegaETHBridge", "OmniBridge", "OptimismBridge", "PolygonBridge", "Unit"]);
377
+ function refundMismatch(r, bridge, e) {
378
+ const spec = FACET_DATA[bridge.facet];
379
+ if (!spec) return NO_REFUND_FIELDS.has(bridge.facet) ? null : `no known refund layout for ${bridge.facet}`;
380
+ const slot = 4 + (bridge.sourceSwaps ? 64 : 32);
381
+ const at = spec.inline ? slot : 4 + r.small(slot);
382
+ const paid = (spec.refunds ?? []).map(([field, word]) => [`${bridge.facet} ${field}`, r.address(at + 32 * word), spec.zeroRefused === true]);
383
+ paid.push(...spec.nested?.(r, at) ?? []);
384
+ for (const [what, to, zeroRefused] of paid) {
385
+ if (zeroRefused && /^0x0{40}$/.test(to)) continue;
386
+ if (!same(to, e.sender) && !same(to, e.receiver)) return `${what} pays ${to}, neither the sender ${e.sender} nor the recipient`;
387
+ }
388
+ return null;
389
+ }
298
390
  function diamondCallMismatch(data, e) {
299
391
  let r;
300
392
  try {
@@ -319,6 +411,8 @@ function diamondCallMismatch(data, e) {
319
411
  }
320
412
  return checkSteps(steps, e, e.toToken);
321
413
  }
414
+ const unbound = UNBOUND_BRIDGES[selector];
415
+ if (unbound) return `${unbound} delivers to a recipient the transaction does not bind (an off-chain order or unchecked facet data)`;
322
416
  const bridge = BRIDGE_CALLS[selector];
323
417
  if (!bridge) return `unknown Diamond call ${selector}`;
324
418
  const head = r.small(4);
@@ -337,6 +431,8 @@ function diamondCallMismatch(data, e) {
337
431
  if (!e.evmDestination) return "the recipient on a non-EVM destination sits in bridge-specific data and cannot be checked here";
338
432
  if (!same(receiver, e.receiver)) return `pays ${receiver}, not ${e.receiver}`;
339
433
  if (hasSourceSwaps !== bridge.sourceSwaps) return `unknown Diamond call ${selector}`;
434
+ const refund = refundMismatch(r, bridge, e);
435
+ if (refund) return refund;
340
436
  if (hasSourceSwaps) {
341
437
  if (minAmount === 0n) return "bridges nothing after the source swaps";
342
438
  return checkSteps(swapsAt(r, 4, 4 + 32), e, sendingAssetId);
@@ -348,8 +444,98 @@ function diamondCallMismatch(data, e) {
348
444
  }
349
445
  }
350
446
 
351
- // src/provider.ts
447
+ // src/solana.ts
352
448
  var import_util2 = require("@anywalletkit/protocol-swap2-core/util");
449
+ var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
450
+ var MAYAN_ENTRY_PROGRAMS = /* @__PURE__ */ new Set([
451
+ "D8C8iW6zmoKg5TRr8nQ7h14TMWqQX8FiBdj2ju5MF3wa",
452
+ // CPI_PROXY_PROGRAM_ID
453
+ "BLZRi6frs4X4DNLw56V4EXai1b6QVESN1BhHBTYM9VcY",
454
+ // SWIFT_PROGRAM_ID
455
+ "mayan34VedncxdK2XobtvWFDXQASUTBXhUVzt2kKgny",
456
+ // SWIFT_V2_PROGRAM_ID
457
+ "dkpZqrxHFrhziEMQ931GLtfy11nFkCsfMftH9u6QwBU",
458
+ // MCTP_PROGRAM_ID
459
+ "Gx9rivpS3YR8pBFwMuP6omYqVxunpLvLkNn7ubNyuZZ5"
460
+ // FAST_MCTP_PROGRAM_ID
461
+ ]);
462
+ var SYSTEM_PROGRAM = "11111111111111111111111111111111";
463
+ var LIFI_SOLANA_FEE_WALLET = "34FKjAdVcTax2DHqV2XnbXa9J3zmyKcFuFKWbcmgxjgm";
464
+ function base58(bytes) {
465
+ let n = 0n;
466
+ for (const b of bytes) n = n << 8n | BigInt(b);
467
+ let out = "";
468
+ while (n > 0n) {
469
+ out = ALPHABET[Number(n % 58n)] + out;
470
+ n /= 58n;
471
+ }
472
+ for (const b of bytes) {
473
+ if (b !== 0) break;
474
+ out = `1${out}`;
475
+ }
476
+ return out;
477
+ }
478
+ var Cursor = class {
479
+ constructor(b) {
480
+ this.b = b;
481
+ }
482
+ b;
483
+ at = 0;
484
+ byte() {
485
+ if (this.at >= this.b.length) throw new Error("truncated");
486
+ return this.b[this.at++];
487
+ }
488
+ bytes(n) {
489
+ if (n < 0 || this.at + n > this.b.length) throw new Error("truncated");
490
+ const out = this.b.subarray(this.at, this.at + n);
491
+ this.at += n;
492
+ return out;
493
+ }
494
+ /** compact-u16 */
495
+ short() {
496
+ let v = 0;
497
+ for (let shift = 0; shift < 21; shift += 7) {
498
+ const b = this.byte();
499
+ v |= (b & 127) << shift;
500
+ if (!(b & 128)) return v;
501
+ }
502
+ throw new Error("bad length");
503
+ }
504
+ };
505
+ function solanaBridgeTxMismatch(base64, sender) {
506
+ const bytes = (0, import_util2.base64Bytes)(base64);
507
+ if (!bytes) return "the Solana transaction is not base64";
508
+ const c = new Cursor(bytes);
509
+ try {
510
+ c.bytes(64 * c.short());
511
+ const first = c.byte();
512
+ if ((first & 128) === 0) c.at--;
513
+ c.bytes(3);
514
+ const keys = Array.from({ length: c.short() }, () => base58(c.bytes(32)));
515
+ if (keys[0] !== sender) return `the Solana transaction is paid by ${keys[0] ?? "nobody"}, not the sender ${sender}`;
516
+ c.bytes(32);
517
+ let mayan = false;
518
+ const payees = [];
519
+ const n = c.short();
520
+ for (let i = 0; i < n; i++) {
521
+ const program = keys[c.byte()];
522
+ const accounts = Array.from(c.bytes(c.short()));
523
+ const data = c.bytes(c.short());
524
+ if (program !== void 0 && MAYAN_ENTRY_PROGRAMS.has(program)) mayan = true;
525
+ if (program === SYSTEM_PROGRAM && data.length === 12 && data[0] === 2 && data[1] === 0 && data[2] === 0 && data[3] === 0) {
526
+ const to = keys[accounts[1] ?? -1];
527
+ if (to !== void 0 && to !== sender && to !== LIFI_SOLANA_FEE_WALLET) payees.push(to);
528
+ }
529
+ }
530
+ return mayan && payees.length ? `the Solana transaction transfers SOL to ${payees[0]}, which is neither the sender nor LI.FI's fee wallet` : null;
531
+ } catch (err) {
532
+ return `the Solana transaction does not decode (${err instanceof Error ? err.message : String(err)})`;
533
+ }
534
+ }
535
+
536
+ // src/provider.ts
537
+ var import_util3 = require("@anywalletkit/protocol-swap2-core/util");
538
+ var import_validate = require("@anywalletkit/protocol-swap2-core/validate");
353
539
  var import_core = require("@anywalletkit/core");
354
540
  var DEFAULT_LIFI_BASE = "https://li.quest/v1";
355
541
  var LIFI_CHAIN = {
@@ -475,7 +661,7 @@ function trustMap(input, label) {
475
661
  }
476
662
  function lifiToken(params) {
477
663
  const sourceChain = params.sourceChain;
478
- const asset = (0, import_util2.sourceAssetOf)(params);
664
+ const asset = (0, import_util3.sourceAssetOf)(params);
479
665
  if (!asset) return null;
480
666
  if (asset.contract) return asset.contract;
481
667
  return isSolana(sourceChain) ? SOLANA_NATIVE : EVM_ZERO;
@@ -486,7 +672,8 @@ function headers(key) {
486
672
  return h;
487
673
  }
488
674
  var TOOL_KEY = /^[A-Za-z0-9_-]{1,64}$/;
489
- function routeOptions(body) {
675
+ var UNBOUND_TOOLS = Object.freeze(["relaydepository", "garden", "squid", "symbiosis"]);
676
+ function routeOptions(body, excluded) {
490
677
  const routes = body?.routes;
491
678
  if (!Array.isArray(routes)) return [];
492
679
  const out = [];
@@ -496,7 +683,7 @@ function routeOptions(body) {
496
683
  const cross = Array.isArray(step.includedSteps) ? step.includedSteps.find((i) => i?.type === "cross")?.tool : void 0;
497
684
  const tool = typeof cross === "string" ? cross : step.tool;
498
685
  const eta = step.estimate?.executionDuration;
499
- if (typeof tool !== "string" || !TOOL_KEY.test(tool) || typeof eta !== "number" || !Number.isFinite(eta) || eta < 0) continue;
686
+ if (typeof tool !== "string" || !TOOL_KEY.test(tool) || excluded.includes(tool) || typeof eta !== "number" || !Number.isFinite(eta) || eta < 0) continue;
500
687
  if (typeof r.toAmount !== "string" || typeof r.toAmountMin !== "string" || !/^\d{1,60}$/.test(r.toAmount) || !/^\d{1,60}$/.test(r.toAmountMin)) continue;
501
688
  out.push({
502
689
  tool,
@@ -582,12 +769,12 @@ function lifiProvider(config = {}) {
582
769
  fromAmount: params.amountIn,
583
770
  fromAddress,
584
771
  toAddress,
585
- options: { slippage: slippageBps / 1e4, ...integrator().trim() ? { integrator: integrator().trim() } : {} }
772
+ options: { slippage: slippageBps / 1e4, ...solanaSource ? {} : { bridges: { deny: UNBOUND_TOOLS } }, ...integrator().trim() ? { integrator: integrator().trim() } : {} }
586
773
  }),
587
- signal: signal ?? (0, import_util2.timeoutSignal)(8e3)
774
+ signal: signal ?? (0, import_util3.timeoutSignal)(8e3)
588
775
  });
589
776
  if (res.ok) {
590
- const options = routeOptions(await res.json());
777
+ const options = routeOptions(await res.json(), solanaSource ? [] : UNBOUND_TOOLS);
591
778
  if (options.length) choice = cleanChoice(config.chooseRoute(options, params));
592
779
  }
593
780
  } catch {
@@ -607,10 +794,11 @@ function lifiProvider(config = {}) {
607
794
  if (sentSlippage !== void 0) {
608
795
  url.searchParams.set("slippage", String(sentSlippage));
609
796
  }
610
- for (const t of choice?.allowBridges ?? []) url.searchParams.append("allowBridges", t);
611
- for (const t of choice?.denyBridges ?? []) url.searchParams.append("denyBridges", t);
797
+ const unbound = params.sourceChain !== params.destChain && !solanaSource ? UNBOUND_TOOLS : [];
798
+ for (const t of (choice?.allowBridges ?? []).filter((b) => solanaSource || !UNBOUND_TOOLS.includes(b))) url.searchParams.append("allowBridges", t);
799
+ for (const t of /* @__PURE__ */ new Set([...choice?.denyBridges ?? [], ...unbound])) url.searchParams.append("denyBridges", t);
612
800
  if (choice?.order) url.searchParams.set("order", choice.order);
613
- deadline = signal ? void 0 : (0, import_util2.timeoutSignal)(12e3);
801
+ deadline = signal ? void 0 : (0, import_util3.timeoutSignal)(12e3);
614
802
  const res = await fetch(url, { headers: headers(apiKey()), signal: signal ?? deadline });
615
803
  if (!res.ok && choice) {
616
804
  choice = null;
@@ -652,6 +840,10 @@ function lifiProvider(config = {}) {
652
840
  if (solanaSource) {
653
841
  if (!tr.data || tr.data.length < 64 || tr.data.length % 4 !== 0 || !BASE64.test(tr.data)) return reject("the Solana transaction is not base64");
654
842
  if (tr.to !== void 0 || tr.value !== void 0 || tr.gasLimit !== void 0) return reject("the Solana transaction carries EVM fields");
843
+ if (fromChain !== toChain) {
844
+ const why = solanaBridgeTxMismatch(tr.data, fromAddress);
845
+ if (why) return reject(why);
846
+ }
655
847
  } else if (!isHexData(tr.data) || !normalizeAddress(tr.to) || !normalizeAddress(tr.from) || tr.chainId !== expectedFromChain || !tr.value || !tr.gasLimit || !trustedAddress(params.sourceChain, tr.to, trustedTransactionTargets) || !sameAddress(tr.from, fromAddress)) return reject("the transaction is malformed or targets an untrusted contract");
656
848
  if (sentSlippage !== void 0 && (typeof action.slippage !== "number" || Math.abs(action.slippage - sentSlippage) > 1e-12)) return reject("the quote ignored the requested slippage");
657
849
  const sourceIsToken = fromToken !== EVM_ZERO && fromToken !== SOLANA_NATIVE;
@@ -689,7 +881,7 @@ function lifiProvider(config = {}) {
689
881
  if (sentSlippage !== void 0) {
690
882
  const dest = BigInt(est.toAmount);
691
883
  const min = BigInt(minDestAmount);
692
- if (dest > 0n && min < dest * BigInt(1e4 - slippageBps) / 10000n) {
884
+ if (dest > 0n && min < (0, import_validate.slippageFloor)(dest, slippageBps)) {
693
885
  const effective = (0, import_core.bigintToNumber)((dest - min) * 1000000n / dest) / 1e6;
694
886
  const requested = slippageBps / 1e4;
695
887
  const scaled = Math.floor(sentSlippage * requested / effective * 0.995 * 1e6) / 1e6;
@@ -718,6 +910,7 @@ function lifiProvider(config = {}) {
718
910
  toToken: expectedToToken,
719
911
  amountIn: BigInt(params.amountIn),
720
912
  receiver: toAddress,
913
+ sender: fromAddress,
721
914
  minOut: BigInt(minDestAmount),
722
915
  destChainId: BigInt(toChain),
723
916
  sameChain: fromChain === toChain,
@@ -736,6 +929,7 @@ function lifiProvider(config = {}) {
736
929
  sourceAmount: params.amountIn,
737
930
  destAmount: est.toAmount,
738
931
  minDestAmount,
932
+ ...Number.isInteger(action.toToken?.decimals) && action.toToken.decimals >= 0 && action.toToken.decimals <= 36 ? { destDecimals: action.toToken.decimals } : {},
739
933
  feeUsd,
740
934
  etaSeconds: est.executionDuration ?? 120,
741
935
  reliability: 0.97,
@@ -772,7 +966,7 @@ function lifiProvider(config = {}) {
772
966
  url.searchParams.set("txHash", ref.sourceTxHash);
773
967
  if (fromChain) url.searchParams.set("fromChain", fromChain);
774
968
  if (toChain) url.searchParams.set("toChain", toChain);
775
- const res = await fetch(url, { headers: headers(apiKey()), signal: (0, import_util2.timeoutSignal)(12e3) });
969
+ const res = await fetch(url, { headers: headers(apiKey()), signal: (0, import_util3.timeoutSignal)(12e3) });
776
970
  if (!res.ok) return { state: "pending" };
777
971
  const s = await res.json();
778
972
  const map = {
@@ -797,9 +991,62 @@ function lifiProvider(config = {}) {
797
991
  }
798
992
  };
799
993
  }
994
+ function lifiVerifyQuote(params, quote) {
995
+ const fromChain = LIFI_CHAIN[params.sourceChain];
996
+ const toChain = LIFI_CHAIN[params.destChain];
997
+ if (!fromChain || !toChain) return "not a LI.FI chain pair";
998
+ const tx = quote.txRequest;
999
+ if (!tx) return "the quote carries no transaction";
1000
+ if (isSolana(params.sourceChain)) {
1001
+ if (!tx.serializedTx || tx.data !== void 0 || tx.to !== void 0) return "a Solana source carries a serialized transaction only";
1002
+ return fromChain === toChain ? null : solanaBridgeTxMismatch(tx.serializedTx, params.refundAddress || (params.dry !== false ? SOLANA_PLACEHOLDER : ""));
1003
+ }
1004
+ if (!isHexData(tx.data) || !tx.to || tx.serializedTx !== void 0) return "the quote carries no Diamond call";
1005
+ if (!sameAddress(tx.to, diamondFor(params.sourceChain))) return `the call targets ${tx.to}, not the LI.FI Diamond`;
1006
+ if (tx.chainId !== void 0 && String(tx.chainId) !== fromChain) return `the call is for chain ${tx.chainId}, not ${fromChain}`;
1007
+ const fromToken = lifiToken(params);
1008
+ if (!fromToken) return `unknown source token ${params.sourceToken}`;
1009
+ const sourceIsToken = fromToken !== EVM_ZERO;
1010
+ const dry = params.dry !== false;
1011
+ const fromAddress = params.refundAddress || (dry ? EVM_PLACEHOLDER : "");
1012
+ const toAddress = params.destAddress || (dry ? fromAddress : "");
1013
+ if (!fromAddress || !toAddress) return "a live quote needs the sender and the recipient";
1014
+ let amountIn, minOut, value, nativeFee;
1015
+ try {
1016
+ amountIn = BigInt(params.amountIn);
1017
+ minOut = BigInt(quote.minDestAmount);
1018
+ value = BigInt(tx.value ?? "0");
1019
+ nativeFee = BigInt(tx.nativeFee ?? "0");
1020
+ } catch {
1021
+ return "the quote's amounts are not integers";
1022
+ }
1023
+ if (BigInt(quote.sourceAmount) !== amountIn) return `the quote spends ${quote.sourceAmount}, not the ${amountIn} input`;
1024
+ if (params.minAmountOut !== void 0 && minOut < BigInt(params.minAmountOut)) return `the quoted minimum ${minOut} is below the caller's floor ${params.minAmountOut}`;
1025
+ if (sourceIsToken) {
1026
+ if (value !== nativeFee) return "a token input attaches only its declared bridge fee";
1027
+ if (!tx.approvalAddress || !sameAddress(tx.approvalAddress, diamondFor(params.sourceChain))) return "a token input approves the LI.FI Diamond";
1028
+ } else {
1029
+ if (value < amountIn || value - amountIn !== nativeFee) return "a native input is paid as the input plus its declared bridge fee";
1030
+ if (tx.approvalAddress !== void 0) return "a native input approves nothing";
1031
+ }
1032
+ if (quote.intentId.replace(/~[0-9a-f]{32}$/, "") !== `lifi:${fromChain}:${toChain}`) return "the intent id does not name this route";
1033
+ const why = diamondCallMismatch(tx.data, {
1034
+ fromToken,
1035
+ toToken: nativeFor(params.destChain, params.destToken),
1036
+ amountIn,
1037
+ receiver: toAddress,
1038
+ sender: fromAddress,
1039
+ minOut,
1040
+ destChainId: BigInt(toChain),
1041
+ sameChain: fromChain === toChain,
1042
+ evmDestination: !isSolana(params.destChain)
1043
+ });
1044
+ return why ? `the transaction does not match the request: ${why}` : null;
1045
+ }
800
1046
  var lifiPins = Object.freeze({
801
1047
  callTargets: (chain) => /^eip155:[0-9]+$/.test(chain) ? [diamondFor(chain)] : [],
802
- spenders: (chain) => /^eip155:[0-9]+$/.test(chain) ? [diamondFor(chain)] : []
1048
+ spenders: (chain) => /^eip155:[0-9]+$/.test(chain) ? [diamondFor(chain)] : [],
1049
+ verifyQuote: lifiVerifyQuote
803
1050
  });
804
1051
 
805
1052
  // src/protocol.ts