@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 +1 -1
- package/dist/{chunk-TR2XMP7X.js → chunk-NSH3PT2J.js} +6 -4
- package/dist/{chunk-AZPTL3KD.js → chunk-OOURZ5DL.js} +191 -58
- package/dist/core/index.cjs +196 -57
- package/dist/core/index.d.cts +60 -7
- package/dist/core/index.d.ts +60 -7
- package/dist/core/index.js +1 -1
- package/dist/index.cjs +195 -60
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{mount-BC5gY1X6.d.cts → mount-DNvmtX0y.d.cts} +1 -1
- package/dist/{mount-8nchcNbL.d.ts → mount-jxrT-DMe.d.ts} +1 -1
- package/dist/mount.cjs +195 -60
- package/dist/mount.d.cts +2 -2
- package/dist/mount.d.ts +2 -2
- package/dist/mount.js +2 -2
- package/dist/standalone.global.js +6 -6
- package/dist/{verify-DFTuQ2g3.d.cts → verify-7lk90Ado.d.cts} +11 -3
- package/dist/{verify-DFTuQ2g3.d.ts → verify-7lk90Ado.d.ts} +11 -3
- package/package.json +2 -1
package/dist/core/index.cjs
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
// src/core/constants.ts
|
|
4
4
|
var DEFAULT_WIDGET_API_BASE = "/api/widget/v1";
|
|
5
|
-
var SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([1, 10, 42161, 8453, 57073, 130, 9745, 146]);
|
|
5
|
+
var SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([1, 10, 42161, 8453, 57073, 130, 9745, 146, 98866]);
|
|
6
6
|
var SUPPORTED_ASSETS = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE", "XAUT"]);
|
|
7
7
|
var API_CACHE_TTL_MS = 6e4;
|
|
8
8
|
var MAX_QUOTE_CANDIDATES = 8;
|
|
9
9
|
var QUOTE_BUFFER_BPS = 50;
|
|
10
10
|
var LZ_FEE_BUFFER_BPS = 1500n;
|
|
11
|
-
var SUBMIT_ORDER_SELECTOR = "
|
|
11
|
+
var SUBMIT_ORDER_SELECTOR = "0xaf439ecd";
|
|
12
|
+
var NO_PARTNER_ID = `0x${"0".repeat(64)}`;
|
|
12
13
|
var ERC20_APPROVE_SELECTOR = "0x095ea7b3";
|
|
13
14
|
var ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
|
|
14
15
|
var ERC20_ALLOWANCE_SELECTOR = "0xdd62ed3e";
|
|
@@ -17,22 +18,24 @@ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
|
17
18
|
var PREVIEW_OWNER = "0x1111111111111111111111111111111111111111";
|
|
18
19
|
var CANONICAL_DECIMALS = { USDC: 6, USDT: 6, USDE: 18, XAUT: 6 };
|
|
19
20
|
var CANONICAL_ESCROW = Object.freeze({
|
|
20
|
-
1: "
|
|
21
|
-
// Ethereum
|
|
22
|
-
10: "
|
|
23
|
-
// Optimism
|
|
24
|
-
130: "
|
|
25
|
-
// Unichain
|
|
26
|
-
146: "
|
|
27
|
-
// Sonic
|
|
28
|
-
8453: "
|
|
29
|
-
// Base
|
|
30
|
-
9745: "
|
|
31
|
-
// Plasma
|
|
32
|
-
57073: "
|
|
33
|
-
// Ink
|
|
34
|
-
42161: "
|
|
35
|
-
// Arbitrum
|
|
21
|
+
1: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
22
|
+
// Ethereum
|
|
23
|
+
10: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
24
|
+
// Optimism
|
|
25
|
+
130: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
26
|
+
// Unichain
|
|
27
|
+
146: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
28
|
+
// Sonic
|
|
29
|
+
8453: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
30
|
+
// Base
|
|
31
|
+
9745: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
32
|
+
// Plasma
|
|
33
|
+
57073: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
34
|
+
// Ink
|
|
35
|
+
42161: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
36
|
+
// Arbitrum
|
|
37
|
+
98866: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40"
|
|
38
|
+
// Plume
|
|
36
39
|
});
|
|
37
40
|
var MAX_LZ_MSG_VALUE_WEI = 10n ** 18n;
|
|
38
41
|
var MAX_LZ_MSG_VALUE_WEI_BY_CHAIN = {};
|
|
@@ -54,7 +57,8 @@ var BUNDLED_NATIVE_SYMBOL = {
|
|
|
54
57
|
146: "S",
|
|
55
58
|
8453: "ETH",
|
|
56
59
|
57073: "ETH",
|
|
57
|
-
42161: "ETH"
|
|
60
|
+
42161: "ETH",
|
|
61
|
+
98866: "PLUME"
|
|
58
62
|
};
|
|
59
63
|
var BUNDLED_RPC = {
|
|
60
64
|
1: "https://ethereum-rpc.publicnode.com",
|
|
@@ -64,7 +68,8 @@ var BUNDLED_RPC = {
|
|
|
64
68
|
8453: "https://mainnet.base.org",
|
|
65
69
|
9745: "https://rpc.plasma.to",
|
|
66
70
|
57073: "https://rpc-gel.inkonchain.com",
|
|
67
|
-
42161: "https://arb1.arbitrum.io/rpc"
|
|
71
|
+
42161: "https://arb1.arbitrum.io/rpc",
|
|
72
|
+
98866: "https://rpc.plume.org"
|
|
68
73
|
};
|
|
69
74
|
|
|
70
75
|
// src/core/address.ts
|
|
@@ -156,13 +161,25 @@ function uintWord(value) {
|
|
|
156
161
|
if (hex.length > 64) throw new Error("uint256 value is too large.");
|
|
157
162
|
return hex.padStart(64, "0");
|
|
158
163
|
}
|
|
164
|
+
var MAX_UINT64 = (1n << 64n) - 1n;
|
|
165
|
+
function uint64Word(value) {
|
|
166
|
+
const n = BigInt(value || 0);
|
|
167
|
+
if (n < 0n) throw new Error("Cannot encode a negative uint64.");
|
|
168
|
+
if (n > MAX_UINT64) throw new Error("uint64 value is too large.");
|
|
169
|
+
return n.toString(16).padStart(64, "0");
|
|
170
|
+
}
|
|
171
|
+
function bytes32Word(value) {
|
|
172
|
+
const hex = strip0x(value);
|
|
173
|
+
if (!/^[a-fA-F0-9]{64}$/.test(hex)) throw new Error("bytes32 value must be exactly 32 bytes of hex.");
|
|
174
|
+
return hex.toLowerCase();
|
|
175
|
+
}
|
|
159
176
|
function addressWord(address) {
|
|
160
177
|
return strip0x(assertAddress(address, "Address")).padStart(64, "0");
|
|
161
178
|
}
|
|
162
179
|
function bytesPayload(value) {
|
|
163
180
|
const hex = strip0x(value || "0x");
|
|
164
|
-
if (hex.length % 2) throw new Error("
|
|
165
|
-
if (!/^[a-fA-F0-9]*$/.test(hex)) throw new Error("
|
|
181
|
+
if (hex.length % 2) throw new Error("Bytes payload has an odd-length hex value; refusing to encode.");
|
|
182
|
+
if (!/^[a-fA-F0-9]*$/.test(hex)) throw new Error("Bytes payload is not valid hex.");
|
|
166
183
|
const byteLength = hex.length / 2;
|
|
167
184
|
const paddedLength = Math.ceil(hex.length / 64) * 64;
|
|
168
185
|
return `${uintWord(byteLength)}${hex.padEnd(paddedLength, "0")}`;
|
|
@@ -179,19 +196,96 @@ function encodeAllowance(owner, spender) {
|
|
|
179
196
|
function encodeBalanceOf(account) {
|
|
180
197
|
return `${ERC20_BALANCEOF_SELECTOR}${addressWord(account)}`;
|
|
181
198
|
}
|
|
182
|
-
|
|
183
|
-
|
|
199
|
+
var ORDER_HEAD_WORDS = 9n;
|
|
200
|
+
var ORDER_HEAD_BYTES = ORDER_HEAD_WORDS * 32n;
|
|
201
|
+
function encodeOrderTuple(order) {
|
|
202
|
+
const askToken = bytesPayload(order.askToken);
|
|
203
|
+
const receiver = bytesPayload(order.destinationReceiver);
|
|
204
|
+
const receiverOffset = ORDER_HEAD_BYTES + BigInt(askToken.length / 2);
|
|
205
|
+
const head = [
|
|
184
206
|
addressWord(order.owner),
|
|
185
207
|
addressWord(order.bidToken),
|
|
186
208
|
uintWord(order.bidTokenAmount),
|
|
187
|
-
|
|
209
|
+
uintWord(ORDER_HEAD_BYTES),
|
|
188
210
|
uintWord(order.askTokenAmount),
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
211
|
+
uintWord(receiverOffset),
|
|
212
|
+
uint64Word(order.destinationChainId),
|
|
213
|
+
uint64Word(order.executionChainId),
|
|
214
|
+
uint64Word(order.deadline)
|
|
193
215
|
].join("");
|
|
194
|
-
return
|
|
216
|
+
return `${head}${askToken}${receiver}`;
|
|
217
|
+
}
|
|
218
|
+
function encodeSubmitOrder(orders, partnerId = NO_PARTNER_ID) {
|
|
219
|
+
if (!orders.length) throw new Error("Cannot encode an empty order request array.");
|
|
220
|
+
const tuples = orders.map(encodeOrderTuple);
|
|
221
|
+
let offset = 32n * BigInt(tuples.length);
|
|
222
|
+
const offsets = tuples.map((tuple) => {
|
|
223
|
+
const word = uintWord(offset);
|
|
224
|
+
offset += BigInt(tuple.length / 2);
|
|
225
|
+
return word;
|
|
226
|
+
}).join("");
|
|
227
|
+
return `0x${SUBMIT_ORDER_SELECTOR.slice(2)}${uintWord(64)}${bytes32Word(partnerId)}${uintWord(tuples.length)}${offsets}${tuples.join("")}`;
|
|
228
|
+
}
|
|
229
|
+
var EVM_BYTES_PAYLOAD_BYTES = 64;
|
|
230
|
+
var EVM_ORDER_TUPLE_BYTES = Number(ORDER_HEAD_BYTES) + 2 * EVM_BYTES_PAYLOAD_BYTES;
|
|
231
|
+
var MAX_DECODED_ORDERS = 16;
|
|
232
|
+
function decodeSubmitOrderCalldata(data) {
|
|
233
|
+
const hex = strip0x(String(data || "")).toLowerCase();
|
|
234
|
+
if (hex.length < 8 || hex.length % 2 !== 0 || !/^[a-f0-9]*$/.test(hex)) return null;
|
|
235
|
+
if (`0x${hex.slice(0, 8)}` !== SUBMIT_ORDER_SELECTOR) return null;
|
|
236
|
+
const body = hex.slice(8);
|
|
237
|
+
const totalBytes = body.length / 2;
|
|
238
|
+
const word = (byteOffset) => {
|
|
239
|
+
if (!Number.isSafeInteger(byteOffset) || byteOffset < 0 || byteOffset + 32 > totalBytes) return null;
|
|
240
|
+
return BigInt(`0x${body.slice(byteOffset * 2, byteOffset * 2 + 64)}`);
|
|
241
|
+
};
|
|
242
|
+
const addressAt = (byteOffset) => {
|
|
243
|
+
const w = word(byteOffset);
|
|
244
|
+
if (w === null || w >= 1n << 160n) return null;
|
|
245
|
+
return `0x${w.toString(16).padStart(40, "0")}`;
|
|
246
|
+
};
|
|
247
|
+
const uint64At = (byteOffset) => {
|
|
248
|
+
const w = word(byteOffset);
|
|
249
|
+
return w === null || w > MAX_UINT64 ? null : w;
|
|
250
|
+
};
|
|
251
|
+
const evmBytesAt = (byteOffset) => {
|
|
252
|
+
const len = word(byteOffset);
|
|
253
|
+
if (len !== 20n) return null;
|
|
254
|
+
const content = body.slice((byteOffset + 32) * 2, (byteOffset + 64) * 2);
|
|
255
|
+
if (content.length !== 64 || !content.endsWith("0".repeat(24))) return null;
|
|
256
|
+
return `0x${content.slice(0, 40)}`;
|
|
257
|
+
};
|
|
258
|
+
if (word(0) !== 64n) return null;
|
|
259
|
+
if (word(32) === null) return null;
|
|
260
|
+
const partnerId = `0x${body.slice(64, 128)}`;
|
|
261
|
+
const count = word(64);
|
|
262
|
+
if (count === null || count < 1n || count > BigInt(MAX_DECODED_ORDERS)) return null;
|
|
263
|
+
const n = Number(count);
|
|
264
|
+
const arrayBase = 96;
|
|
265
|
+
if (totalBytes !== arrayBase + 32 * n + EVM_ORDER_TUPLE_BYTES * n) return null;
|
|
266
|
+
const orders = [];
|
|
267
|
+
for (let i = 0; i < n; i += 1) {
|
|
268
|
+
const rel = word(arrayBase + i * 32);
|
|
269
|
+
if (rel === null || rel !== BigInt(32 * n + EVM_ORDER_TUPLE_BYTES * i)) return null;
|
|
270
|
+
const base = arrayBase + Number(rel);
|
|
271
|
+
const owner = addressAt(base);
|
|
272
|
+
const bidToken = addressAt(base + 32);
|
|
273
|
+
const bidTokenAmount = word(base + 64);
|
|
274
|
+
const askOffset = word(base + 96);
|
|
275
|
+
const askTokenAmount = word(base + 128);
|
|
276
|
+
const receiverOffset = word(base + 160);
|
|
277
|
+
const destinationChainId = uint64At(base + 192);
|
|
278
|
+
const executionChainId = uint64At(base + 224);
|
|
279
|
+
const deadline = uint64At(base + 256);
|
|
280
|
+
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)) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
const askToken = evmBytesAt(base + Number(askOffset));
|
|
284
|
+
const destinationReceiver = evmBytesAt(base + Number(receiverOffset));
|
|
285
|
+
if (askToken === null || destinationReceiver === null) return null;
|
|
286
|
+
orders.push({ owner, bidToken, bidTokenAmount, askToken, askTokenAmount, destinationReceiver, destinationChainId, executionChainId, deadline });
|
|
287
|
+
}
|
|
288
|
+
return { partnerId, orders };
|
|
195
289
|
}
|
|
196
290
|
function toHexQuantity(value) {
|
|
197
291
|
const n = BigInt(value || 0);
|
|
@@ -382,7 +476,7 @@ async function solveExactOut({ option, destination, destinationToken, payer, fet
|
|
|
382
476
|
estimatedDuration: 0,
|
|
383
477
|
gasCostSource: "0",
|
|
384
478
|
gasCostDest: "0",
|
|
385
|
-
|
|
479
|
+
orderRequests: null
|
|
386
480
|
},
|
|
387
481
|
youPayRaw: targetRaw.toString(),
|
|
388
482
|
recipientReceivesRaw: targetRaw.toString(),
|
|
@@ -494,9 +588,13 @@ async function solveExactIn({ option, destination, destinationToken, payer, fetc
|
|
|
494
588
|
}
|
|
495
589
|
|
|
496
590
|
// src/core/order.ts
|
|
497
|
-
|
|
591
|
+
var DEFAULT_DEADLINE_SECONDS = 1800;
|
|
592
|
+
var MAX_DEADLINE_SECONDS = 60 * 60;
|
|
593
|
+
function normalizeOrderRequest(order, payer, destination, fallbackExecutionChainId, deadlineOverride) {
|
|
498
594
|
const apiDeadline = Number(order.deadline);
|
|
499
|
-
const deadline = Number.isFinite(apiDeadline) && apiDeadline > 0 ? String(order.deadline) : String(Math.floor(Date.now() / 1e3) +
|
|
595
|
+
const deadline = deadlineOverride ?? (Number.isFinite(apiDeadline) && apiDeadline > 0 ? String(order.deadline) : String(Math.floor(Date.now() / 1e3) + DEFAULT_DEADLINE_SECONDS));
|
|
596
|
+
const executionChainId = String(order.executionChainId || fallbackExecutionChainId || "0");
|
|
597
|
+
if (!/^\d+$/.test(executionChainId) || BigInt(executionChainId) <= 0n) throw new Error("ZeroDelta quote did not include an execution chain.");
|
|
500
598
|
return {
|
|
501
599
|
owner: assertAddress(order.owner || payer, "Order owner"),
|
|
502
600
|
bidToken: assertAddress(order.bidToken, "Bid token"),
|
|
@@ -505,26 +603,40 @@ function normalizeOrderRequest(order, payer, destination) {
|
|
|
505
603
|
askTokenAmount: String(order.askTokenAmount || "0"),
|
|
506
604
|
destinationReceiver: assertAddress(order.destinationReceiver || destination.address, "Destination receiver"),
|
|
507
605
|
destinationChainId: String(order.destinationChainId || destination.chainId),
|
|
508
|
-
|
|
509
|
-
|
|
606
|
+
executionChainId,
|
|
607
|
+
deadline
|
|
510
608
|
};
|
|
511
609
|
}
|
|
512
|
-
function
|
|
610
|
+
function normalizeOrderRequests(requests, payer, destination, fallbackExecutionChainId) {
|
|
611
|
+
if (!requests.length) throw new Error("ZeroDelta quote did not include any order requests.");
|
|
612
|
+
return requests.map(
|
|
613
|
+
(request, index) => index === 0 ? normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId) : normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId, String(request.deadline || "0"))
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
function assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result }) {
|
|
617
|
+
const list = orders?.length ? orders : [order];
|
|
618
|
+
const sourceOrder = list[0];
|
|
619
|
+
const finalOrder = list[list.length - 1];
|
|
513
620
|
const now = Math.floor(Date.now() / 1e3);
|
|
514
|
-
const deadline = Number(
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
621
|
+
const deadline = Number(sourceOrder.deadline || 0);
|
|
622
|
+
for (const current of list) {
|
|
623
|
+
if (normalizeAddress(current.owner) !== normalizeAddress(payer)) {
|
|
624
|
+
throw new Error("ZeroDelta quote returned an owner that does not match the connected wallet.");
|
|
625
|
+
}
|
|
626
|
+
if (normalizeAddress(current.destinationReceiver) !== normalizeAddress(destination.address)) {
|
|
627
|
+
throw new Error("ZeroDelta quote returned a receiver that does not match the detected destination.");
|
|
628
|
+
}
|
|
629
|
+
if (!/^\d+$/.test(current.executionChainId || "") || BigInt(current.executionChainId) <= 0n) {
|
|
630
|
+
throw new Error("ZeroDelta quote returned an order without an execution chain.");
|
|
631
|
+
}
|
|
520
632
|
}
|
|
521
|
-
if (normalizeAddress(
|
|
633
|
+
if (normalizeAddress(sourceOrder.bidToken) !== normalizeAddress(option.address)) {
|
|
522
634
|
throw new Error("ZeroDelta quote returned a bid token that does not match the selected route.");
|
|
523
635
|
}
|
|
524
|
-
if (normalizeAddress(
|
|
636
|
+
if (normalizeAddress(finalOrder.askToken) !== normalizeAddress(destinationToken.address)) {
|
|
525
637
|
throw new Error("ZeroDelta quote returned an ask token that does not match the destination asset.");
|
|
526
638
|
}
|
|
527
|
-
if (Number(
|
|
639
|
+
if (Number(finalOrder.destinationChainId) !== Number(destination.chainId) || Number(quote.toChainId) !== Number(destination.chainId)) {
|
|
528
640
|
throw new Error("ZeroDelta quote returned a destination chain that does not match the payment request.");
|
|
529
641
|
}
|
|
530
642
|
if (Number(quote.fromChainId) !== Number(option.chainId)) {
|
|
@@ -533,24 +645,38 @@ function assertQuoteMatchesSelection({ quote, order, option, destinationToken, d
|
|
|
533
645
|
if (symbolKey(quote.fromToken) !== option.symbolKey || symbolKey(quote.toToken) !== symbolKey(destinationToken.symbol)) {
|
|
534
646
|
throw new Error("ZeroDelta quote returned token symbols that do not match the selected route.");
|
|
535
647
|
}
|
|
536
|
-
if (BigInt(
|
|
648
|
+
if (BigInt(sourceOrder.bidTokenAmount || "0") !== BigInt(result.youPayRaw || "0")) {
|
|
537
649
|
throw new Error("ZeroDelta quote returned a bid amount that does not match the displayed payment amount.");
|
|
538
650
|
}
|
|
539
|
-
if (BigInt(
|
|
651
|
+
if (BigInt(finalOrder.askTokenAmount || "0") !== BigInt(quote.toAmount || "0")) {
|
|
540
652
|
throw new Error("ZeroDelta quote returned an ask amount that does not match the quoted output.");
|
|
541
653
|
}
|
|
542
|
-
if (BigInt(
|
|
654
|
+
if (BigInt(finalOrder.askTokenAmount || "0") <= 0n || BigInt(quote.toAmount || "0") <= 0n) {
|
|
543
655
|
throw new Error("ZeroDelta quote returned a non-positive output amount.");
|
|
544
656
|
}
|
|
545
|
-
if (BigInt(
|
|
657
|
+
if (BigInt(finalOrder.askTokenAmount || "0") < BigInt(result.targetRaw || "0")) {
|
|
546
658
|
throw new Error("ZeroDelta quote would not cover the requested destination amount.");
|
|
547
659
|
}
|
|
548
|
-
if (BigInt(
|
|
660
|
+
if (BigInt(finalOrder.askTokenAmount || "0") < BigInt(result.recipientReceivesRaw || "0")) {
|
|
549
661
|
throw new Error("ZeroDelta order guarantees less than the displayed receive amount.");
|
|
550
662
|
}
|
|
551
|
-
if (!Number.isFinite(deadline) || deadline <= now || deadline > now +
|
|
663
|
+
if (!Number.isFinite(deadline) || deadline <= now || deadline > now + MAX_DEADLINE_SECONDS) {
|
|
552
664
|
throw new Error("ZeroDelta quote deadline is invalid or too far in the future.");
|
|
553
665
|
}
|
|
666
|
+
for (let index = 1; index < list.length; index += 1) {
|
|
667
|
+
const previous = list[index - 1];
|
|
668
|
+
const current = list[index];
|
|
669
|
+
if (normalizeAddress(previous.askToken) !== normalizeAddress(current.bidToken)) {
|
|
670
|
+
throw new Error("ZeroDelta chained quote returned disconnected order tokens.");
|
|
671
|
+
}
|
|
672
|
+
if (Number(previous.destinationChainId) !== Number(current.executionChainId)) {
|
|
673
|
+
throw new Error("ZeroDelta chained quote returned disconnected execution chains.");
|
|
674
|
+
}
|
|
675
|
+
const followupDeadline = Number(current.deadline || 0);
|
|
676
|
+
if (followupDeadline !== 0 && (!Number.isFinite(followupDeadline) || followupDeadline <= now || followupDeadline > now + MAX_DEADLINE_SECONDS)) {
|
|
677
|
+
throw new Error("ZeroDelta chained quote returned an invalid follow-up deadline.");
|
|
678
|
+
}
|
|
679
|
+
}
|
|
554
680
|
}
|
|
555
681
|
|
|
556
682
|
// src/core/route.ts
|
|
@@ -617,11 +743,13 @@ async function buildRoute({ option, destination, destinationToken, chains, payer
|
|
|
617
743
|
}
|
|
618
744
|
};
|
|
619
745
|
}
|
|
620
|
-
|
|
746
|
+
const requestList = quote.orderRequests?.length ? quote.orderRequests : quote.orderRequest ? [quote.orderRequest] : [];
|
|
747
|
+
if (!requestList.length) throw new Error("ZeroDelta quote did not include an order request.");
|
|
621
748
|
const sourceChain = chainById(chains, option.chainId);
|
|
622
749
|
const escrow = checkEscrow(option.chainId, quote.escrowAddress, sourceChain?.escrowContract);
|
|
623
|
-
const
|
|
624
|
-
|
|
750
|
+
const orders = normalizeOrderRequests(requestList, payer, destination, quote.executionChainId);
|
|
751
|
+
const order = orders[0];
|
|
752
|
+
assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result });
|
|
625
753
|
const needsNativeFee = requiresNativeBridgeFee(quote, option);
|
|
626
754
|
if (needsNativeFee) {
|
|
627
755
|
let rawFee;
|
|
@@ -682,7 +810,7 @@ async function buildRoute({ option, destination, destinationToken, chains, payer
|
|
|
682
810
|
label: "Submit ZeroDelta order",
|
|
683
811
|
chainId: option.chainId,
|
|
684
812
|
to: escrow,
|
|
685
|
-
data: encodeSubmitOrder(
|
|
813
|
+
data: encodeSubmitOrder(orders),
|
|
686
814
|
value: toHexQuantity(valueRaw),
|
|
687
815
|
escrow,
|
|
688
816
|
amountRaw: order.bidTokenAmount
|
|
@@ -1122,7 +1250,12 @@ function validatePlannedTransaction(tx, route, expectedRecipient) {
|
|
|
1122
1250
|
if (tx.kind === "submitOrder") {
|
|
1123
1251
|
const expected = planMsgValueHex(route);
|
|
1124
1252
|
if (expected === null || value !== lower(expected)) return false;
|
|
1125
|
-
|
|
1253
|
+
if (selector !== SUBMIT_ORDER_SELECTOR || !isHexAddress(tx.escrow) || lower(tx.to) !== lower(tx.escrow)) return false;
|
|
1254
|
+
const decoded = decodeSubmitOrderCalldata(data);
|
|
1255
|
+
if (!decoded) return false;
|
|
1256
|
+
const first = decoded.orders[0];
|
|
1257
|
+
const last = decoded.orders[decoded.orders.length - 1];
|
|
1258
|
+
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);
|
|
1126
1259
|
}
|
|
1127
1260
|
return false;
|
|
1128
1261
|
}
|
|
@@ -1139,7 +1272,7 @@ async function allowanceCovers(tx, account, ethCall) {
|
|
|
1139
1272
|
// src/core/intent-schema.ts
|
|
1140
1273
|
var STABLEGENIE_INTENT_VERSION = 1;
|
|
1141
1274
|
var STABLEGENIE_INTENT_TTL_MS = 5 * 60 * 1e3;
|
|
1142
|
-
var STABLEGENIE_SUPPORTED_CHAIN_IDS = Object.freeze([1, 10, 130, 146, 8453, 9745, 57073, 42161]);
|
|
1275
|
+
var STABLEGENIE_SUPPORTED_CHAIN_IDS = Object.freeze([1, 10, 130, 146, 8453, 9745, 57073, 42161, 98866]);
|
|
1143
1276
|
var STABLEGENIE_SUPPORTED_ASSETS = Object.freeze(["USDC", "USDE", "USDT", "XAUT"]);
|
|
1144
1277
|
var stableGenieIntentSchema = {
|
|
1145
1278
|
type: "object",
|
|
@@ -1511,6 +1644,8 @@ exports.MAX_LZ_MSG_VALUE_WEI = MAX_LZ_MSG_VALUE_WEI;
|
|
|
1511
1644
|
exports.MAX_LZ_MSG_VALUE_WEI_BY_CHAIN = MAX_LZ_MSG_VALUE_WEI_BY_CHAIN;
|
|
1512
1645
|
exports.MAX_QUOTE_CANDIDATES = MAX_QUOTE_CANDIDATES;
|
|
1513
1646
|
exports.MAX_SAME_CLASS_PAY_BPS = MAX_SAME_CLASS_PAY_BPS;
|
|
1647
|
+
exports.MAX_UINT64 = MAX_UINT64;
|
|
1648
|
+
exports.NO_PARTNER_ID = NO_PARTNER_ID;
|
|
1514
1649
|
exports.PREVIEW_OWNER = PREVIEW_OWNER;
|
|
1515
1650
|
exports.QUOTE_BUFFER_BPS = QUOTE_BUFFER_BPS;
|
|
1516
1651
|
exports.SAME_CLASS_STABLE = SAME_CLASS_STABLE;
|
|
@@ -1532,6 +1667,7 @@ exports.assetDecimals = assetDecimals;
|
|
|
1532
1667
|
exports.buildPayOptions = buildPayOptions;
|
|
1533
1668
|
exports.buildRoute = buildRoute;
|
|
1534
1669
|
exports.buildSwapPlan = buildSwapPlan;
|
|
1670
|
+
exports.bytes32Word = bytes32Word;
|
|
1535
1671
|
exports.bytesPayload = bytesPayload;
|
|
1536
1672
|
exports.canAttachApiKey = canAttachApiKey;
|
|
1537
1673
|
exports.chainById = chainById;
|
|
@@ -1543,6 +1679,7 @@ exports.classifyQuoteError = classifyQuoteError;
|
|
|
1543
1679
|
exports.createApiClient = createApiClient;
|
|
1544
1680
|
exports.createEngine = createEngine;
|
|
1545
1681
|
exports.createVerifier = createVerifier;
|
|
1682
|
+
exports.decodeSubmitOrderCalldata = decodeSubmitOrderCalldata;
|
|
1546
1683
|
exports.encodeAllowance = encodeAllowance;
|
|
1547
1684
|
exports.encodeApprove = encodeApprove;
|
|
1548
1685
|
exports.encodeBalanceOf = encodeBalanceOf;
|
|
@@ -1566,6 +1703,7 @@ exports.nativeSymbol = nativeSymbol;
|
|
|
1566
1703
|
exports.normalizeAddress = normalizeAddress;
|
|
1567
1704
|
exports.normalizeDecimalText = normalizeDecimalText;
|
|
1568
1705
|
exports.normalizeOrderRequest = normalizeOrderRequest;
|
|
1706
|
+
exports.normalizeOrderRequests = normalizeOrderRequests;
|
|
1569
1707
|
exports.parseAllowedApiBase = parseAllowedApiBase;
|
|
1570
1708
|
exports.parseUnitsDecimal = parseUnitsDecimal;
|
|
1571
1709
|
exports.planErrorSummary = planErrorSummary;
|
|
@@ -1586,6 +1724,7 @@ exports.symbolKey = symbolKey;
|
|
|
1586
1724
|
exports.toHexQuantity = toHexQuantity;
|
|
1587
1725
|
exports.tokenEnabled = tokenEnabled;
|
|
1588
1726
|
exports.txMatchesPlan = txMatchesPlan;
|
|
1727
|
+
exports.uint64Word = uint64Word;
|
|
1589
1728
|
exports.uintWord = uintWord;
|
|
1590
1729
|
exports.validateDestination = validateDestination;
|
|
1591
1730
|
exports.validatePlannedTransaction = validatePlannedTransaction;
|
package/dist/core/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as Token, Q as Quote, N as NormalizedOrder, b as PayOption, R as RouteResult, C as Chain, c as Route, F as FetchQuoteFn, d as SolveResult, O as OrderRequest, B as BalanceTarget, e as BalanceEntry, A as ApiClient, P as Plan, f as SwapInput, g as PlannedTx, h as Verifier, T as TxHistoryEntry, S as SanitizedTxEntry, E as EngineConfig } from '../verify-
|
|
2
|
-
export { i as Address, j as ApiError, D as Destination, H as Hex, k as PlannedTxKind, l as QuoteBlock, m as ResolvedConfig, n as TxPlan, V as VerifyResult, o as apiError, p as canAttachApiKey, q as classifyQuoteError, r as createApiClient, s as createVerifier, t as parseAllowedApiBase, u as registryRpc, v as resolveApiBase, w as resolveConfig, x as txMatchesPlan } from '../verify-
|
|
1
|
+
import { a as Token, Q as Quote, N as NormalizedOrder, b as PayOption, R as RouteResult, C as Chain, c as Route, F as FetchQuoteFn, d as SolveResult, O as OrderRequest, B as BalanceTarget, e as BalanceEntry, A as ApiClient, P as Plan, f as SwapInput, g as PlannedTx, h as Verifier, T as TxHistoryEntry, S as SanitizedTxEntry, E as EngineConfig } from '../verify-7lk90Ado.cjs';
|
|
2
|
+
export { i as Address, j as ApiError, D as Destination, H as Hex, k as PlannedTxKind, l as QuoteBlock, m as ResolvedConfig, n as TxPlan, V as VerifyResult, o as apiError, p as canAttachApiKey, q as classifyQuoteError, r as createApiClient, s as createVerifier, t as parseAllowedApiBase, u as registryRpc, v as resolveApiBase, w as resolveConfig, x as txMatchesPlan } from '../verify-7lk90Ado.cjs';
|
|
3
3
|
|
|
4
4
|
/** Default request base for the widget: the same-origin keyless custody proxy (server injects the
|
|
5
5
|
* ZeroDelta key). A host may override to `/api/v1` + an apiKey for the demo-first fallback path. */
|
|
@@ -10,7 +10,12 @@ declare const API_CACHE_TTL_MS = 60000;
|
|
|
10
10
|
declare const MAX_QUOTE_CANDIDATES = 8;
|
|
11
11
|
declare const QUOTE_BUFFER_BPS = 50;
|
|
12
12
|
declare const LZ_FEE_BUFFER_BPS = 1500n;
|
|
13
|
-
declare const SUBMIT_ORDER_SELECTOR = "
|
|
13
|
+
declare const SUBMIT_ORDER_SELECTOR = "0xaf439ecd";
|
|
14
|
+
/** `partnerId` for orders this widget submits — none. The escrow's only use of the argument is
|
|
15
|
+
* `if (partnerId != bytes32(0)) emit PartnerOrder(partnerId)`; there is no on-chain logic behind
|
|
16
|
+
* it and the gateway issues none, so zero is the value that MEANS "no attribution", not a
|
|
17
|
+
* placeholder. The pre-sign validator binds the encoded word to exactly this. */
|
|
18
|
+
declare const NO_PARTNER_ID: string;
|
|
14
19
|
declare const ERC20_APPROVE_SELECTOR = "0x095ea7b3";
|
|
15
20
|
declare const ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
|
|
16
21
|
declare const ERC20_ALLOWANCE_SELECTOR = "0xdd62ed3e";
|
|
@@ -44,13 +49,48 @@ declare function finalOf(quote: Quote | undefined | null): bigint;
|
|
|
44
49
|
|
|
45
50
|
declare function strip0x(value: unknown): string;
|
|
46
51
|
declare function uintWord(value: bigint | number | string): string;
|
|
52
|
+
declare const MAX_UINT64: bigint;
|
|
53
|
+
/** The escrow declares chain ids and the deadline as uint64. Solidity would silently truncate a
|
|
54
|
+
* wider value into a different chain / deadline, so refuse anything that does not fit. */
|
|
55
|
+
declare function uint64Word(value: bigint | number | string): string;
|
|
56
|
+
declare function bytes32Word(value: string): string;
|
|
47
57
|
declare function addressWord(address: string): string;
|
|
58
|
+
/** ABI `bytes` payload: length word + right-padded content. Used for the escrow's `bytes askToken`
|
|
59
|
+
* and `bytes destinationReceiver` (bytes rather than address so non-EVM destinations fit). */
|
|
48
60
|
declare function bytesPayload(value: string): string;
|
|
49
61
|
declare function encodeApprove(spender: string, amount: bigint | number | string): string;
|
|
50
62
|
declare function encodeTransfer(to: string, amount: bigint | number | string): string;
|
|
51
63
|
declare function encodeAllowance(owner: string, spender: string): string;
|
|
52
64
|
declare function encodeBalanceOf(account: string): string;
|
|
53
|
-
|
|
65
|
+
/**
|
|
66
|
+
* `submitOrder(OrderRequest[] requests, bytes32 partnerId)`.
|
|
67
|
+
* Layout: selector · [offset of `requests` = 0x40] · [partnerId] · [n] · [n element offsets,
|
|
68
|
+
* relative to the first element slot] · tuples. A chained quote is one signature / several legs,
|
|
69
|
+
* so the engine always encodes the whole `orderRequests` list the gateway returned.
|
|
70
|
+
*/
|
|
71
|
+
declare function encodeSubmitOrder(orders: NormalizedOrder[], partnerId?: string): string;
|
|
72
|
+
interface DecodedOrderRequest {
|
|
73
|
+
owner: string;
|
|
74
|
+
bidToken: string;
|
|
75
|
+
bidTokenAmount: bigint;
|
|
76
|
+
askToken: string;
|
|
77
|
+
askTokenAmount: bigint;
|
|
78
|
+
destinationReceiver: string;
|
|
79
|
+
destinationChainId: bigint;
|
|
80
|
+
executionChainId: bigint;
|
|
81
|
+
deadline: bigint;
|
|
82
|
+
}
|
|
83
|
+
interface DecodedSubmitOrder {
|
|
84
|
+
partnerId: string;
|
|
85
|
+
orders: DecodedOrderRequest[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Strict inverse of {@link encodeSubmitOrder}, for the pre-sign validator. Returns `null` on ANY
|
|
89
|
+
* deviation from the exact layout the engine produces — wrong selector, a non-canonical offset,
|
|
90
|
+
* a `bytes` member that is not a 20-byte address, trailing bytes — so a tampered plan cannot be
|
|
91
|
+
* "close enough". It deliberately decodes only what this widget signs, not the general ABI.
|
|
92
|
+
*/
|
|
93
|
+
declare function decodeSubmitOrderCalldata(data: string): DecodedSubmitOrder | null;
|
|
54
94
|
declare function toHexQuantity(value: bigint | number | string): string;
|
|
55
95
|
|
|
56
96
|
/**
|
|
@@ -143,10 +183,23 @@ declare function solveExactIn({ option, destination, destinationToken, payer, fe
|
|
|
143
183
|
declare function normalizeOrderRequest(order: OrderRequest, payer: string, destination: {
|
|
144
184
|
address: string;
|
|
145
185
|
chainId: number | string;
|
|
146
|
-
}): NormalizedOrder;
|
|
186
|
+
}, fallbackExecutionChainId?: number | string, deadlineOverride?: string): NormalizedOrder;
|
|
187
|
+
/**
|
|
188
|
+
* Normalize the whole `orderRequests` list of a quote. A chained (RWA) quote is one signature and
|
|
189
|
+
* several legs: leg 1 is the user's order and gets the client-side fills (owner, receiver, a fresh
|
|
190
|
+
* deadline); follow-up legs keep whatever deadline the gateway issued — `0` is its "no separate
|
|
191
|
+
* deadline" marker and must be forwarded verbatim, not replaced.
|
|
192
|
+
*/
|
|
193
|
+
declare function normalizeOrderRequests(requests: OrderRequest[], payer: string, destination: {
|
|
194
|
+
address: string;
|
|
195
|
+
chainId: number | string;
|
|
196
|
+
}, fallbackExecutionChainId?: number | string): NormalizedOrder[];
|
|
147
197
|
interface AssertQuoteArgs {
|
|
148
198
|
quote: Quote;
|
|
199
|
+
/** The first (user-signed) leg. Kept as a separate argument so single-leg callers stay simple. */
|
|
149
200
|
order: NormalizedOrder;
|
|
201
|
+
/** Every leg, first to last. Defaults to `[order]`. */
|
|
202
|
+
orders?: NormalizedOrder[];
|
|
150
203
|
option: PayOption;
|
|
151
204
|
destinationToken: Token;
|
|
152
205
|
destination: {
|
|
@@ -156,7 +209,7 @@ interface AssertQuoteArgs {
|
|
|
156
209
|
payer: string;
|
|
157
210
|
result: SolveResult;
|
|
158
211
|
}
|
|
159
|
-
declare function assertQuoteMatchesSelection({ quote, order, option, destinationToken, destination, payer, result }: AssertQuoteArgs): void;
|
|
212
|
+
declare function assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result }: AssertQuoteArgs): void;
|
|
160
213
|
|
|
161
214
|
interface BuildRouteArgs {
|
|
162
215
|
option: PayOption;
|
|
@@ -352,4 +405,4 @@ interface Engine {
|
|
|
352
405
|
/** Create an engine bound to a config. The 60s resource cache is per-engine. */
|
|
353
406
|
declare function createEngine(config?: EngineConfig): Engine;
|
|
354
407
|
|
|
355
|
-
export { API_CACHE_TTL_MS, ApiClient, type AssertQuoteArgs, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, BalanceEntry, type BalanceReader, BalanceTarget, type BuildPayOptionsArgs, type BuildRouteArgs, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, Chain, DEFAULT_WIDGET_API_BASE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, type Engine, EngineConfig, FetchQuoteFn, LZ_FEE_BUFFER_BPS, MAX_LZ_MSG_VALUE_WEI, MAX_LZ_MSG_VALUE_WEI_BY_CHAIN, MAX_QUOTE_CANDIDATES, MAX_SAME_CLASS_PAY_BPS, type NativeFeeCheck, NormalizedOrder, OrderRequest, PREVIEW_OWNER, PayOption, type PayRequest, type PaymentWalletContext, Plan, PlannedTx, QUOTE_BUFFER_BPS, Quote, Route, RouteResult, 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, SanitizedTxEntry, type SolveArgs, SolveResult, SwapInput, type SwapPreview, Token, TxHistoryEntry, type ValidatedSwap, Verifier, ZERO_ADDRESS, addressWord, allowanceCovers, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetDecimals, buildPayOptions, buildRoute, buildSwapPlan, bytesPayload, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, createEngine, encodeAllowance, encodeApprove, encodeBalanceOf, encodeSubmitOrder, encodeTransfer, fetchPaymentPlan, finalOf, findToken, formatNative, formatUnits, isAddress, isDeliverable, isHexAddress, isHexData, isHexQuantity, isLayerZeroRoute, maxNativeFeeWei, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeOrderRequest, parseUnitsDecimal, planErrorSummary, planMsgValueHex, quoteSwapPreview, requiresNativeBridgeFee, resolveSwapReceiver, routeNativeValue, scaleDecimals, solveExactIn, solveExactOut, stableGenieIntentSchema, strip0x, symbolKey, toHexQuantity, tokenEnabled, uintWord, validateDestination, validatePlannedTransaction, validateSwap };
|
|
408
|
+
export { API_CACHE_TTL_MS, ApiClient, type AssertQuoteArgs, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, BalanceEntry, type BalanceReader, BalanceTarget, type BuildPayOptionsArgs, type BuildRouteArgs, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, Chain, DEFAULT_WIDGET_API_BASE, type DecodedOrderRequest, type DecodedSubmitOrder, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, type Engine, EngineConfig, FetchQuoteFn, 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, type NativeFeeCheck, NormalizedOrder, OrderRequest, PREVIEW_OWNER, PayOption, type PayRequest, type PaymentWalletContext, Plan, PlannedTx, QUOTE_BUFFER_BPS, Quote, Route, RouteResult, 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, SanitizedTxEntry, type SolveArgs, SolveResult, SwapInput, type SwapPreview, Token, TxHistoryEntry, type ValidatedSwap, Verifier, ZERO_ADDRESS, addressWord, allowanceCovers, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetDecimals, buildPayOptions, buildRoute, buildSwapPlan, bytes32Word, bytesPayload, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, createEngine, 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, parseUnitsDecimal, planErrorSummary, planMsgValueHex, quoteSwapPreview, requiresNativeBridgeFee, resolveSwapReceiver, routeNativeValue, scaleDecimals, solveExactIn, solveExactOut, stableGenieIntentSchema, strip0x, symbolKey, toHexQuantity, tokenEnabled, uint64Word, uintWord, validateDestination, validatePlannedTransaction, validateSwap };
|