@glacislabs/stablegenie-zerodelta 3.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,7 +12,7 @@ submits silently. Every ZeroDelta quote is re-validated (`assertQuoteMatchesSele
12
12
  planned transaction is re-decoded before signing (`validatePlannedTransaction`), and the settling
13
13
  transaction is confirmed on-chain in a trusted realm (`verifySubmittedTx`).
14
14
 
15
- Supported chains: Ethereum, Optimism, Arbitrum, Base, Ink, Unichain, Plasma, Sonic.
15
+ Supported chains: Ethereum, Optimism, Arbitrum, Base, Ink, Unichain, Plasma, Sonic, Plume.
16
16
  Supported assets: USDC, USDT, USDE, XAUT. (Card/fiat rails are roadmap, not shipped.)
17
17
 
18
18
  ## Install (React host)
@@ -1,4 +1,4 @@
1
- import { symbolKey, normalizeDecimalText, parseUnitsDecimal, SUPPORTED_CHAIN_IDS, tokenEnabled, isDeliverable, assetDecimals, findToken, formatUnits, createEngine, routeNativeValue, checkNativeFee, nativeFeeShortLabel, nativeSymbol, nativeFeeShortMessage, allowanceCovers, validatePlannedTransaction, SUPPORTED_ASSETS, BUNDLED_RPC } from './chunk-AZPTL3KD.js';
1
+ import { symbolKey, normalizeDecimalText, parseUnitsDecimal, SUPPORTED_CHAIN_IDS, tokenEnabled, isDeliverable, assetDecimals, findToken, formatUnits, createEngine, routeNativeValue, checkNativeFee, nativeFeeShortLabel, nativeSymbol, nativeFeeShortMessage, allowanceCovers, validatePlannedTransaction, SUPPORTED_ASSETS, BUNDLED_RPC } from './chunk-OOURZ5DL.js';
2
2
  import { createContext, useMemo, useState, useEffect, useRef, useCallback, useId, createElement, useContext } from 'react';
3
3
  import { createRoot } from 'react-dom/client';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -1095,9 +1095,10 @@ var CHAIN_LABELS = {
1095
1095
  8453: "Base",
1096
1096
  9745: "Plasma",
1097
1097
  57073: "Ink",
1098
- 42161: "Arbitrum"
1098
+ 42161: "Arbitrum",
1099
+ 98866: "Plume"
1099
1100
  };
1100
- var SUPPORTED_CHAINS = [1, 10, 42161, 8453, 57073, 130, 9745, 146];
1101
+ var SUPPORTED_CHAINS = [1, 10, 42161, 8453, 57073, 130, 9745, 146, 98866];
1101
1102
  var SUPPORTED_ASSETS2 = ["USDC", "USDT", "USDE", "XAUT"];
1102
1103
  function Button(props) {
1103
1104
  const soft = !!props.softDisabled && !props.disabled;
@@ -1296,7 +1297,8 @@ var CHAIN_SHORT = {
1296
1297
  8453: "BASE",
1297
1298
  9745: "PLS",
1298
1299
  57073: "INK",
1299
- 42161: "ARB"
1300
+ 42161: "ARB",
1301
+ 98866: "PLM"
1300
1302
  };
1301
1303
  function isHttpsUrl(u) {
1302
1304
  return typeof u === "string" && /^https:\/\//i.test(u);
@@ -1,12 +1,13 @@
1
1
  // src/core/constants.ts
2
2
  var DEFAULT_WIDGET_API_BASE = "/api/widget/v1";
3
- var SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([1, 10, 42161, 8453, 57073, 130, 9745, 146]);
3
+ var SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([1, 10, 42161, 8453, 57073, 130, 9745, 146, 98866]);
4
4
  var SUPPORTED_ASSETS = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE", "XAUT"]);
5
5
  var API_CACHE_TTL_MS = 6e4;
6
6
  var MAX_QUOTE_CANDIDATES = 8;
7
7
  var QUOTE_BUFFER_BPS = 50;
8
8
  var LZ_FEE_BUFFER_BPS = 1500n;
9
- var SUBMIT_ORDER_SELECTOR = "0xbbd71141";
9
+ var SUBMIT_ORDER_SELECTOR = "0xaf439ecd";
10
+ var NO_PARTNER_ID = `0x${"0".repeat(64)}`;
10
11
  var ERC20_APPROVE_SELECTOR = "0x095ea7b3";
11
12
  var ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
12
13
  var ERC20_ALLOWANCE_SELECTOR = "0xdd62ed3e";
@@ -15,22 +16,24 @@ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
15
16
  var PREVIEW_OWNER = "0x1111111111111111111111111111111111111111";
16
17
  var CANONICAL_DECIMALS = { USDC: 6, USDT: 6, USDE: 18, XAUT: 6 };
17
18
  var CANONICAL_ESCROW = Object.freeze({
18
- 1: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
19
- // Ethereum — impl 0x49d173C4AbC90B3665D691f1FF2064eb9732A743
20
- 10: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
21
- // Optimism — impl 0xB47eCBa71039694D28E76C482aC2bE34d5faC22A
22
- 130: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
23
- // Unichain — impl 0xA9B1bBF52EF242aa4b9a8018bfD48fe64BbDfD03
24
- 146: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
25
- // Sonic — impl 0x4c66dECff081Cf282af4C7f9CA436CB7b46A700d
26
- 8453: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
27
- // Base — impl 0x70E37bF2c258015DAB7FE26942185D0362ebEd46
28
- 9745: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
29
- // Plasma — impl 0x70168A99722f3041ceff211C4E505e8732ee965D
30
- 57073: "0x46A3219c357C2E50129d4839058FCFD421789aE7",
31
- // Ink — impl 0x8A9e68864f476DA577e948cb61Cedffe7e17b562
32
- 42161: "0x46A3219c357C2E50129d4839058FCFD421789aE7"
33
- // Arbitrum — impl 0x453B00aeB8c7dDBaff10f2812A0bA7dc88DdbC35
19
+ 1: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
20
+ // Ethereum
21
+ 10: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
22
+ // Optimism
23
+ 130: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
24
+ // Unichain
25
+ 146: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
26
+ // Sonic
27
+ 8453: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
28
+ // Base
29
+ 9745: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
30
+ // Plasma
31
+ 57073: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
32
+ // Ink
33
+ 42161: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
34
+ // Arbitrum
35
+ 98866: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40"
36
+ // Plume
34
37
  });
35
38
  var MAX_LZ_MSG_VALUE_WEI = 10n ** 18n;
36
39
  var MAX_LZ_MSG_VALUE_WEI_BY_CHAIN = {};
@@ -52,7 +55,8 @@ var BUNDLED_NATIVE_SYMBOL = {
52
55
  146: "S",
53
56
  8453: "ETH",
54
57
  57073: "ETH",
55
- 42161: "ETH"
58
+ 42161: "ETH",
59
+ 98866: "PLUME"
56
60
  };
57
61
  var BUNDLED_RPC = {
58
62
  1: "https://ethereum-rpc.publicnode.com",
@@ -62,7 +66,8 @@ var BUNDLED_RPC = {
62
66
  8453: "https://mainnet.base.org",
63
67
  9745: "https://rpc.plasma.to",
64
68
  57073: "https://rpc-gel.inkonchain.com",
65
- 42161: "https://arb1.arbitrum.io/rpc"
69
+ 42161: "https://arb1.arbitrum.io/rpc",
70
+ 98866: "https://rpc.plume.org"
66
71
  };
67
72
 
68
73
  // src/core/address.ts
@@ -154,13 +159,25 @@ function uintWord(value) {
154
159
  if (hex.length > 64) throw new Error("uint256 value is too large.");
155
160
  return hex.padStart(64, "0");
156
161
  }
162
+ var MAX_UINT64 = (1n << 64n) - 1n;
163
+ function uint64Word(value) {
164
+ const n = BigInt(value || 0);
165
+ if (n < 0n) throw new Error("Cannot encode a negative uint64.");
166
+ if (n > MAX_UINT64) throw new Error("uint64 value is too large.");
167
+ return n.toString(16).padStart(64, "0");
168
+ }
169
+ function bytes32Word(value) {
170
+ const hex = strip0x(value);
171
+ if (!/^[a-fA-F0-9]{64}$/.test(hex)) throw new Error("bytes32 value must be exactly 32 bytes of hex.");
172
+ return hex.toLowerCase();
173
+ }
157
174
  function addressWord(address) {
158
175
  return strip0x(assertAddress(address, "Address")).padStart(64, "0");
159
176
  }
160
177
  function bytesPayload(value) {
161
178
  const hex = strip0x(value || "0x");
162
- if (hex.length % 2) throw new Error("Order data has an odd-length hex payload; refusing to encode.");
163
- if (!/^[a-fA-F0-9]*$/.test(hex)) throw new Error("Order data is not valid hex.");
179
+ if (hex.length % 2) throw new Error("Bytes payload has an odd-length hex value; refusing to encode.");
180
+ if (!/^[a-fA-F0-9]*$/.test(hex)) throw new Error("Bytes payload is not valid hex.");
164
181
  const byteLength = hex.length / 2;
165
182
  const paddedLength = Math.ceil(hex.length / 64) * 64;
166
183
  return `${uintWord(byteLength)}${hex.padEnd(paddedLength, "0")}`;
@@ -177,19 +194,96 @@ function encodeAllowance(owner, spender) {
177
194
  function encodeBalanceOf(account) {
178
195
  return `${ERC20_BALANCEOF_SELECTOR}${addressWord(account)}`;
179
196
  }
180
- function encodeSubmitOrder(order) {
181
- const tupleHead = [
197
+ var ORDER_HEAD_WORDS = 9n;
198
+ var ORDER_HEAD_BYTES = ORDER_HEAD_WORDS * 32n;
199
+ function encodeOrderTuple(order) {
200
+ const askToken = bytesPayload(order.askToken);
201
+ const receiver = bytesPayload(order.destinationReceiver);
202
+ const receiverOffset = ORDER_HEAD_BYTES + BigInt(askToken.length / 2);
203
+ const head = [
182
204
  addressWord(order.owner),
183
205
  addressWord(order.bidToken),
184
206
  uintWord(order.bidTokenAmount),
185
- addressWord(order.askToken),
207
+ uintWord(ORDER_HEAD_BYTES),
186
208
  uintWord(order.askTokenAmount),
187
- addressWord(order.destinationReceiver),
188
- uintWord(order.destinationChainId),
189
- uintWord(order.deadline),
190
- uintWord(9n * 32n)
209
+ uintWord(receiverOffset),
210
+ uint64Word(order.destinationChainId),
211
+ uint64Word(order.executionChainId),
212
+ uint64Word(order.deadline)
191
213
  ].join("");
192
- return `0x${SUBMIT_ORDER_SELECTOR.slice(2)}${uintWord(32)}${tupleHead}${bytesPayload(order.data || "0x")}`;
214
+ return `${head}${askToken}${receiver}`;
215
+ }
216
+ function encodeSubmitOrder(orders, partnerId = NO_PARTNER_ID) {
217
+ if (!orders.length) throw new Error("Cannot encode an empty order request array.");
218
+ const tuples = orders.map(encodeOrderTuple);
219
+ let offset = 32n * BigInt(tuples.length);
220
+ const offsets = tuples.map((tuple) => {
221
+ const word = uintWord(offset);
222
+ offset += BigInt(tuple.length / 2);
223
+ return word;
224
+ }).join("");
225
+ return `0x${SUBMIT_ORDER_SELECTOR.slice(2)}${uintWord(64)}${bytes32Word(partnerId)}${uintWord(tuples.length)}${offsets}${tuples.join("")}`;
226
+ }
227
+ var EVM_BYTES_PAYLOAD_BYTES = 64;
228
+ var EVM_ORDER_TUPLE_BYTES = Number(ORDER_HEAD_BYTES) + 2 * EVM_BYTES_PAYLOAD_BYTES;
229
+ var MAX_DECODED_ORDERS = 16;
230
+ function decodeSubmitOrderCalldata(data) {
231
+ const hex = strip0x(String(data || "")).toLowerCase();
232
+ if (hex.length < 8 || hex.length % 2 !== 0 || !/^[a-f0-9]*$/.test(hex)) return null;
233
+ if (`0x${hex.slice(0, 8)}` !== SUBMIT_ORDER_SELECTOR) return null;
234
+ const body = hex.slice(8);
235
+ const totalBytes = body.length / 2;
236
+ const word = (byteOffset) => {
237
+ if (!Number.isSafeInteger(byteOffset) || byteOffset < 0 || byteOffset + 32 > totalBytes) return null;
238
+ return BigInt(`0x${body.slice(byteOffset * 2, byteOffset * 2 + 64)}`);
239
+ };
240
+ const addressAt = (byteOffset) => {
241
+ const w = word(byteOffset);
242
+ if (w === null || w >= 1n << 160n) return null;
243
+ return `0x${w.toString(16).padStart(40, "0")}`;
244
+ };
245
+ const uint64At = (byteOffset) => {
246
+ const w = word(byteOffset);
247
+ return w === null || w > MAX_UINT64 ? null : w;
248
+ };
249
+ const evmBytesAt = (byteOffset) => {
250
+ const len = word(byteOffset);
251
+ if (len !== 20n) return null;
252
+ const content = body.slice((byteOffset + 32) * 2, (byteOffset + 64) * 2);
253
+ if (content.length !== 64 || !content.endsWith("0".repeat(24))) return null;
254
+ return `0x${content.slice(0, 40)}`;
255
+ };
256
+ if (word(0) !== 64n) return null;
257
+ if (word(32) === null) return null;
258
+ const partnerId = `0x${body.slice(64, 128)}`;
259
+ const count = word(64);
260
+ if (count === null || count < 1n || count > BigInt(MAX_DECODED_ORDERS)) return null;
261
+ const n = Number(count);
262
+ const arrayBase = 96;
263
+ if (totalBytes !== arrayBase + 32 * n + EVM_ORDER_TUPLE_BYTES * n) return null;
264
+ const orders = [];
265
+ for (let i = 0; i < n; i += 1) {
266
+ const rel = word(arrayBase + i * 32);
267
+ if (rel === null || rel !== BigInt(32 * n + EVM_ORDER_TUPLE_BYTES * i)) return null;
268
+ const base = arrayBase + Number(rel);
269
+ const owner = addressAt(base);
270
+ const bidToken = addressAt(base + 32);
271
+ const bidTokenAmount = word(base + 64);
272
+ const askOffset = word(base + 96);
273
+ const askTokenAmount = word(base + 128);
274
+ const receiverOffset = word(base + 160);
275
+ const destinationChainId = uint64At(base + 192);
276
+ const executionChainId = uint64At(base + 224);
277
+ const deadline = uint64At(base + 256);
278
+ if (owner === null || bidToken === null || bidTokenAmount === null || askTokenAmount === null || destinationChainId === null || executionChainId === null || deadline === null || askOffset !== ORDER_HEAD_BYTES || receiverOffset !== ORDER_HEAD_BYTES + BigInt(EVM_BYTES_PAYLOAD_BYTES)) {
279
+ return null;
280
+ }
281
+ const askToken = evmBytesAt(base + Number(askOffset));
282
+ const destinationReceiver = evmBytesAt(base + Number(receiverOffset));
283
+ if (askToken === null || destinationReceiver === null) return null;
284
+ orders.push({ owner, bidToken, bidTokenAmount, askToken, askTokenAmount, destinationReceiver, destinationChainId, executionChainId, deadline });
285
+ }
286
+ return { partnerId, orders };
193
287
  }
194
288
  function toHexQuantity(value) {
195
289
  const n = BigInt(value || 0);
@@ -380,7 +474,7 @@ async function solveExactOut({ option, destination, destinationToken, payer, fet
380
474
  estimatedDuration: 0,
381
475
  gasCostSource: "0",
382
476
  gasCostDest: "0",
383
- orderRequest: null
477
+ orderRequests: null
384
478
  },
385
479
  youPayRaw: targetRaw.toString(),
386
480
  recipientReceivesRaw: targetRaw.toString(),
@@ -492,9 +586,13 @@ async function solveExactIn({ option, destination, destinationToken, payer, fetc
492
586
  }
493
587
 
494
588
  // src/core/order.ts
495
- function normalizeOrderRequest(order, payer, destination) {
589
+ var DEFAULT_DEADLINE_SECONDS = 1800;
590
+ var MAX_DEADLINE_SECONDS = 60 * 60;
591
+ function normalizeOrderRequest(order, payer, destination, fallbackExecutionChainId, deadlineOverride) {
496
592
  const apiDeadline = Number(order.deadline);
497
- const deadline = Number.isFinite(apiDeadline) && apiDeadline > 0 ? String(order.deadline) : String(Math.floor(Date.now() / 1e3) + 1800);
593
+ const deadline = deadlineOverride ?? (Number.isFinite(apiDeadline) && apiDeadline > 0 ? String(order.deadline) : String(Math.floor(Date.now() / 1e3) + DEFAULT_DEADLINE_SECONDS));
594
+ const executionChainId = String(order.executionChainId || fallbackExecutionChainId || "0");
595
+ if (!/^\d+$/.test(executionChainId) || BigInt(executionChainId) <= 0n) throw new Error("ZeroDelta quote did not include an execution chain.");
498
596
  return {
499
597
  owner: assertAddress(order.owner || payer, "Order owner"),
500
598
  bidToken: assertAddress(order.bidToken, "Bid token"),
@@ -503,26 +601,40 @@ function normalizeOrderRequest(order, payer, destination) {
503
601
  askTokenAmount: String(order.askTokenAmount || "0"),
504
602
  destinationReceiver: assertAddress(order.destinationReceiver || destination.address, "Destination receiver"),
505
603
  destinationChainId: String(order.destinationChainId || destination.chainId),
506
- deadline,
507
- data: order.data || "0x"
604
+ executionChainId,
605
+ deadline
508
606
  };
509
607
  }
510
- function assertQuoteMatchesSelection({ quote, order, option, destinationToken, destination, payer, result }) {
608
+ function normalizeOrderRequests(requests, payer, destination, fallbackExecutionChainId) {
609
+ if (!requests.length) throw new Error("ZeroDelta quote did not include any order requests.");
610
+ return requests.map(
611
+ (request, index) => index === 0 ? normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId) : normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId, String(request.deadline || "0"))
612
+ );
613
+ }
614
+ function assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result }) {
615
+ const list = orders?.length ? orders : [order];
616
+ const sourceOrder = list[0];
617
+ const finalOrder = list[list.length - 1];
511
618
  const now = Math.floor(Date.now() / 1e3);
512
- const deadline = Number(order.deadline || 0);
513
- if (normalizeAddress(order.owner) !== normalizeAddress(payer)) {
514
- throw new Error("ZeroDelta quote returned an owner that does not match the connected wallet.");
515
- }
516
- if (normalizeAddress(order.destinationReceiver) !== normalizeAddress(destination.address)) {
517
- throw new Error("ZeroDelta quote returned a receiver that does not match the detected destination.");
619
+ const deadline = Number(sourceOrder.deadline || 0);
620
+ for (const current of list) {
621
+ if (normalizeAddress(current.owner) !== normalizeAddress(payer)) {
622
+ throw new Error("ZeroDelta quote returned an owner that does not match the connected wallet.");
623
+ }
624
+ if (normalizeAddress(current.destinationReceiver) !== normalizeAddress(destination.address)) {
625
+ throw new Error("ZeroDelta quote returned a receiver that does not match the detected destination.");
626
+ }
627
+ if (!/^\d+$/.test(current.executionChainId || "") || BigInt(current.executionChainId) <= 0n) {
628
+ throw new Error("ZeroDelta quote returned an order without an execution chain.");
629
+ }
518
630
  }
519
- if (normalizeAddress(order.bidToken) !== normalizeAddress(option.address)) {
631
+ if (normalizeAddress(sourceOrder.bidToken) !== normalizeAddress(option.address)) {
520
632
  throw new Error("ZeroDelta quote returned a bid token that does not match the selected route.");
521
633
  }
522
- if (normalizeAddress(order.askToken) !== normalizeAddress(destinationToken.address)) {
634
+ if (normalizeAddress(finalOrder.askToken) !== normalizeAddress(destinationToken.address)) {
523
635
  throw new Error("ZeroDelta quote returned an ask token that does not match the destination asset.");
524
636
  }
525
- if (Number(order.destinationChainId) !== Number(destination.chainId) || Number(quote.toChainId) !== Number(destination.chainId)) {
637
+ if (Number(finalOrder.destinationChainId) !== Number(destination.chainId) || Number(quote.toChainId) !== Number(destination.chainId)) {
526
638
  throw new Error("ZeroDelta quote returned a destination chain that does not match the payment request.");
527
639
  }
528
640
  if (Number(quote.fromChainId) !== Number(option.chainId)) {
@@ -531,24 +643,38 @@ function assertQuoteMatchesSelection({ quote, order, option, destinationToken, d
531
643
  if (symbolKey(quote.fromToken) !== option.symbolKey || symbolKey(quote.toToken) !== symbolKey(destinationToken.symbol)) {
532
644
  throw new Error("ZeroDelta quote returned token symbols that do not match the selected route.");
533
645
  }
534
- if (BigInt(order.bidTokenAmount || "0") !== BigInt(result.youPayRaw || "0")) {
646
+ if (BigInt(sourceOrder.bidTokenAmount || "0") !== BigInt(result.youPayRaw || "0")) {
535
647
  throw new Error("ZeroDelta quote returned a bid amount that does not match the displayed payment amount.");
536
648
  }
537
- if (BigInt(order.askTokenAmount || "0") !== BigInt(quote.toAmount || "0")) {
649
+ if (BigInt(finalOrder.askTokenAmount || "0") !== BigInt(quote.toAmount || "0")) {
538
650
  throw new Error("ZeroDelta quote returned an ask amount that does not match the quoted output.");
539
651
  }
540
- if (BigInt(order.askTokenAmount || "0") <= 0n || BigInt(quote.toAmount || "0") <= 0n) {
652
+ if (BigInt(finalOrder.askTokenAmount || "0") <= 0n || BigInt(quote.toAmount || "0") <= 0n) {
541
653
  throw new Error("ZeroDelta quote returned a non-positive output amount.");
542
654
  }
543
- if (BigInt(order.askTokenAmount || "0") < BigInt(result.targetRaw || "0")) {
655
+ if (BigInt(finalOrder.askTokenAmount || "0") < BigInt(result.targetRaw || "0")) {
544
656
  throw new Error("ZeroDelta quote would not cover the requested destination amount.");
545
657
  }
546
- if (BigInt(order.askTokenAmount || "0") < BigInt(result.recipientReceivesRaw || "0")) {
658
+ if (BigInt(finalOrder.askTokenAmount || "0") < BigInt(result.recipientReceivesRaw || "0")) {
547
659
  throw new Error("ZeroDelta order guarantees less than the displayed receive amount.");
548
660
  }
549
- if (!Number.isFinite(deadline) || deadline <= now || deadline > now + 60 * 60) {
661
+ if (!Number.isFinite(deadline) || deadline <= now || deadline > now + MAX_DEADLINE_SECONDS) {
550
662
  throw new Error("ZeroDelta quote deadline is invalid or too far in the future.");
551
663
  }
664
+ for (let index = 1; index < list.length; index += 1) {
665
+ const previous = list[index - 1];
666
+ const current = list[index];
667
+ if (normalizeAddress(previous.askToken) !== normalizeAddress(current.bidToken)) {
668
+ throw new Error("ZeroDelta chained quote returned disconnected order tokens.");
669
+ }
670
+ if (Number(previous.destinationChainId) !== Number(current.executionChainId)) {
671
+ throw new Error("ZeroDelta chained quote returned disconnected execution chains.");
672
+ }
673
+ const followupDeadline = Number(current.deadline || 0);
674
+ if (followupDeadline !== 0 && (!Number.isFinite(followupDeadline) || followupDeadline <= now || followupDeadline > now + MAX_DEADLINE_SECONDS)) {
675
+ throw new Error("ZeroDelta chained quote returned an invalid follow-up deadline.");
676
+ }
677
+ }
552
678
  }
553
679
 
554
680
  // src/core/route.ts
@@ -615,11 +741,13 @@ async function buildRoute({ option, destination, destinationToken, chains, payer
615
741
  }
616
742
  };
617
743
  }
618
- if (!quote.orderRequest) throw new Error("ZeroDelta quote did not include an order request.");
744
+ const requestList = quote.orderRequests?.length ? quote.orderRequests : quote.orderRequest ? [quote.orderRequest] : [];
745
+ if (!requestList.length) throw new Error("ZeroDelta quote did not include an order request.");
619
746
  const sourceChain = chainById(chains, option.chainId);
620
747
  const escrow = checkEscrow(option.chainId, quote.escrowAddress, sourceChain?.escrowContract);
621
- const order = normalizeOrderRequest(quote.orderRequest, payer, destination);
622
- assertQuoteMatchesSelection({ quote, order, option, destinationToken, destination, payer, result });
748
+ const orders = normalizeOrderRequests(requestList, payer, destination, quote.executionChainId);
749
+ const order = orders[0];
750
+ assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result });
623
751
  const needsNativeFee = requiresNativeBridgeFee(quote, option);
624
752
  if (needsNativeFee) {
625
753
  let rawFee;
@@ -680,7 +808,7 @@ async function buildRoute({ option, destination, destinationToken, chains, payer
680
808
  label: "Submit ZeroDelta order",
681
809
  chainId: option.chainId,
682
810
  to: escrow,
683
- data: encodeSubmitOrder(order),
811
+ data: encodeSubmitOrder(orders),
684
812
  value: toHexQuantity(valueRaw),
685
813
  escrow,
686
814
  amountRaw: order.bidTokenAmount
@@ -1120,7 +1248,12 @@ function validatePlannedTransaction(tx, route, expectedRecipient) {
1120
1248
  if (tx.kind === "submitOrder") {
1121
1249
  const expected = planMsgValueHex(route);
1122
1250
  if (expected === null || value !== lower(expected)) return false;
1123
- return selector === "0xbbd71141" && isHexAddress(tx.escrow) && lower(tx.to) === lower(tx.escrow);
1251
+ if (selector !== SUBMIT_ORDER_SELECTOR || !isHexAddress(tx.escrow) || lower(tx.to) !== lower(tx.escrow)) return false;
1252
+ const decoded = decodeSubmitOrderCalldata(data);
1253
+ if (!decoded) return false;
1254
+ const first = decoded.orders[0];
1255
+ const last = decoded.orders[decoded.orders.length - 1];
1256
+ return decoded.partnerId === NO_PARTNER_ID && lower(first.bidToken) === lower(route.source.tokenAddress) && rawEquals(first.bidTokenAmount, tx.amountRaw) && lower(last.askToken) === lower(route.receive.tokenAddress) && Number(last.destinationChainId) === Number(route.receive.chainId) && lower(last.destinationReceiver) === lower(expectedRecipient);
1124
1257
  }
1125
1258
  return false;
1126
1259
  }
@@ -1137,7 +1270,7 @@ async function allowanceCovers(tx, account, ethCall) {
1137
1270
  // src/core/intent-schema.ts
1138
1271
  var STABLEGENIE_INTENT_VERSION = 1;
1139
1272
  var STABLEGENIE_INTENT_TTL_MS = 5 * 60 * 1e3;
1140
- var STABLEGENIE_SUPPORTED_CHAIN_IDS = Object.freeze([1, 10, 130, 146, 8453, 9745, 57073, 42161]);
1273
+ var STABLEGENIE_SUPPORTED_CHAIN_IDS = Object.freeze([1, 10, 130, 146, 8453, 9745, 57073, 42161, 98866]);
1141
1274
  var STABLEGENIE_SUPPORTED_ASSETS = Object.freeze(["USDC", "USDE", "USDT", "XAUT"]);
1142
1275
  var stableGenieIntentSchema = {
1143
1276
  type: "object",
@@ -1493,4 +1626,4 @@ function createEngine(config = {}) {
1493
1626
  };
1494
1627
  }
1495
1628
 
1496
- export { API_CACHE_TTL_MS, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, DEFAULT_WIDGET_API_BASE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, LZ_FEE_BUFFER_BPS, MAX_LZ_MSG_VALUE_WEI, MAX_LZ_MSG_VALUE_WEI_BY_CHAIN, MAX_QUOTE_CANDIDATES, MAX_SAME_CLASS_PAY_BPS, PREVIEW_OWNER, QUOTE_BUFFER_BPS, SAME_CLASS_STABLE, STABLEGENIE_INTENT_TTL_MS, STABLEGENIE_INTENT_VERSION, STABLEGENIE_SUPPORTED_ASSETS, STABLEGENIE_SUPPORTED_CHAIN_IDS, SUBMIT_ORDER_SELECTOR, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, ZERO_ADDRESS, addressWord, allowanceCovers, apiError, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetDecimals, buildPayOptions, buildRoute, buildSwapPlan, bytesPayload, canAttachApiKey, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, classifyQuoteError, createApiClient, createEngine, createVerifier, encodeAllowance, encodeApprove, encodeBalanceOf, encodeSubmitOrder, encodeTransfer, fetchPaymentPlan, finalOf, findToken, formatNative, formatUnits, isAddress, isDeliverable, isHexAddress, isHexData, isHexQuantity, isLayerZeroRoute, maxNativeFeeWei, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeOrderRequest, parseAllowedApiBase, parseUnitsDecimal, planErrorSummary, planMsgValueHex, quoteSwapPreview, registryRpc, requiresNativeBridgeFee, resolveApiBase, resolveConfig, resolveSwapReceiver, routeNativeValue, scaleDecimals, solveExactIn, solveExactOut, stableGenieIntentSchema, strip0x, symbolKey, toHexQuantity, tokenEnabled, txMatchesPlan, uintWord, validateDestination, validatePlannedTransaction, validateSwap };
1629
+ export { API_CACHE_TTL_MS, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, DEFAULT_WIDGET_API_BASE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, LZ_FEE_BUFFER_BPS, MAX_LZ_MSG_VALUE_WEI, MAX_LZ_MSG_VALUE_WEI_BY_CHAIN, MAX_QUOTE_CANDIDATES, MAX_SAME_CLASS_PAY_BPS, MAX_UINT64, NO_PARTNER_ID, PREVIEW_OWNER, QUOTE_BUFFER_BPS, SAME_CLASS_STABLE, STABLEGENIE_INTENT_TTL_MS, STABLEGENIE_INTENT_VERSION, STABLEGENIE_SUPPORTED_ASSETS, STABLEGENIE_SUPPORTED_CHAIN_IDS, SUBMIT_ORDER_SELECTOR, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, ZERO_ADDRESS, addressWord, allowanceCovers, apiError, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetDecimals, buildPayOptions, buildRoute, buildSwapPlan, bytes32Word, bytesPayload, canAttachApiKey, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, classifyQuoteError, createApiClient, createEngine, createVerifier, decodeSubmitOrderCalldata, encodeAllowance, encodeApprove, encodeBalanceOf, encodeSubmitOrder, encodeTransfer, fetchPaymentPlan, finalOf, findToken, formatNative, formatUnits, isAddress, isDeliverable, isHexAddress, isHexData, isHexQuantity, isLayerZeroRoute, maxNativeFeeWei, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeOrderRequest, normalizeOrderRequests, parseAllowedApiBase, parseUnitsDecimal, planErrorSummary, planMsgValueHex, quoteSwapPreview, registryRpc, requiresNativeBridgeFee, resolveApiBase, resolveConfig, resolveSwapReceiver, routeNativeValue, scaleDecimals, solveExactIn, solveExactOut, stableGenieIntentSchema, strip0x, symbolKey, toHexQuantity, tokenEnabled, txMatchesPlan, uint64Word, uintWord, validateDestination, validatePlannedTransaction, validateSwap };