@glacislabs/stablegenie-zerodelta 3.0.1 → 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-DH7QYQG4.js → chunk-NSH3PT2J.js} +247 -51
- package/dist/{chunk-VL5MWEY2.js → chunk-OOURZ5DL.js} +283 -80
- package/dist/core/index.cjs +288 -79
- package/dist/core/index.d.cts +68 -13
- package/dist/core/index.d.ts +68 -13
- package/dist/core/index.js +1 -1
- package/dist/index.cjs +528 -129
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{mount-yqXrDBLc.d.cts → mount-DNvmtX0y.d.cts} +1 -1
- package/dist/{mount-yTJi4VdA.d.ts → mount-jxrT-DMe.d.ts} +1 -1
- package/dist/mount.cjs +528 -129
- 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 +8 -8
- package/dist/{verify-CaO0OD4Z.d.cts → verify-7lk90Ado.d.cts} +20 -4
- package/dist/{verify-CaO0OD4Z.d.ts → verify-7lk90Ado.d.ts} +20 -4
- package/package.json +2 -1
package/dist/mount.cjs
CHANGED
|
@@ -13,13 +13,14 @@ function useMergedConfig(local) {
|
|
|
13
13
|
|
|
14
14
|
// src/core/constants.ts
|
|
15
15
|
var DEFAULT_WIDGET_API_BASE = "/api/widget/v1";
|
|
16
|
-
var SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([1, 10, 42161, 8453, 57073, 130, 9745, 146]);
|
|
16
|
+
var SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([1, 10, 42161, 8453, 57073, 130, 9745, 146, 98866]);
|
|
17
17
|
var SUPPORTED_ASSETS = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE", "XAUT"]);
|
|
18
18
|
var API_CACHE_TTL_MS = 6e4;
|
|
19
19
|
var MAX_QUOTE_CANDIDATES = 8;
|
|
20
20
|
var QUOTE_BUFFER_BPS = 50;
|
|
21
21
|
var LZ_FEE_BUFFER_BPS = 1500n;
|
|
22
|
-
var SUBMIT_ORDER_SELECTOR = "
|
|
22
|
+
var SUBMIT_ORDER_SELECTOR = "0xaf439ecd";
|
|
23
|
+
var NO_PARTNER_ID = `0x${"0".repeat(64)}`;
|
|
23
24
|
var ERC20_APPROVE_SELECTOR = "0x095ea7b3";
|
|
24
25
|
var ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
|
|
25
26
|
var ERC20_ALLOWANCE_SELECTOR = "0xdd62ed3e";
|
|
@@ -28,22 +29,24 @@ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
|
28
29
|
var PREVIEW_OWNER = "0x1111111111111111111111111111111111111111";
|
|
29
30
|
var CANONICAL_DECIMALS = { USDC: 6, USDT: 6, USDE: 18, XAUT: 6 };
|
|
30
31
|
var CANONICAL_ESCROW = Object.freeze({
|
|
31
|
-
1: "
|
|
32
|
-
// Ethereum
|
|
33
|
-
10: "
|
|
34
|
-
// Optimism
|
|
35
|
-
130: "
|
|
36
|
-
// Unichain
|
|
37
|
-
146: "
|
|
38
|
-
// Sonic
|
|
39
|
-
8453: "
|
|
40
|
-
// Base
|
|
41
|
-
9745: "
|
|
42
|
-
// Plasma
|
|
43
|
-
57073: "
|
|
44
|
-
// Ink
|
|
45
|
-
42161: "
|
|
46
|
-
// Arbitrum
|
|
32
|
+
1: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
33
|
+
// Ethereum
|
|
34
|
+
10: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
35
|
+
// Optimism
|
|
36
|
+
130: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
37
|
+
// Unichain
|
|
38
|
+
146: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
39
|
+
// Sonic
|
|
40
|
+
8453: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
41
|
+
// Base
|
|
42
|
+
9745: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
43
|
+
// Plasma
|
|
44
|
+
57073: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
45
|
+
// Ink
|
|
46
|
+
42161: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40",
|
|
47
|
+
// Arbitrum
|
|
48
|
+
98866: "0x5e25c8ABc19b88d6A7Ab0D805C77A34987a68b40"
|
|
49
|
+
// Plume
|
|
47
50
|
});
|
|
48
51
|
var MAX_LZ_MSG_VALUE_WEI = 10n ** 18n;
|
|
49
52
|
var MAX_LZ_MSG_VALUE_WEI_BY_CHAIN = {};
|
|
@@ -65,7 +68,8 @@ var BUNDLED_NATIVE_SYMBOL = {
|
|
|
65
68
|
146: "S",
|
|
66
69
|
8453: "ETH",
|
|
67
70
|
57073: "ETH",
|
|
68
|
-
42161: "ETH"
|
|
71
|
+
42161: "ETH",
|
|
72
|
+
98866: "PLUME"
|
|
69
73
|
};
|
|
70
74
|
var BUNDLED_RPC = {
|
|
71
75
|
1: "https://ethereum-rpc.publicnode.com",
|
|
@@ -75,7 +79,8 @@ var BUNDLED_RPC = {
|
|
|
75
79
|
8453: "https://mainnet.base.org",
|
|
76
80
|
9745: "https://rpc.plasma.to",
|
|
77
81
|
57073: "https://rpc-gel.inkonchain.com",
|
|
78
|
-
42161: "https://arb1.arbitrum.io/rpc"
|
|
82
|
+
42161: "https://arb1.arbitrum.io/rpc",
|
|
83
|
+
98866: "https://rpc.plume.org"
|
|
79
84
|
};
|
|
80
85
|
|
|
81
86
|
// src/core/address.ts
|
|
@@ -167,13 +172,25 @@ function uintWord(value) {
|
|
|
167
172
|
if (hex.length > 64) throw new Error("uint256 value is too large.");
|
|
168
173
|
return hex.padStart(64, "0");
|
|
169
174
|
}
|
|
175
|
+
var MAX_UINT64 = (1n << 64n) - 1n;
|
|
176
|
+
function uint64Word(value) {
|
|
177
|
+
const n = BigInt(value || 0);
|
|
178
|
+
if (n < 0n) throw new Error("Cannot encode a negative uint64.");
|
|
179
|
+
if (n > MAX_UINT64) throw new Error("uint64 value is too large.");
|
|
180
|
+
return n.toString(16).padStart(64, "0");
|
|
181
|
+
}
|
|
182
|
+
function bytes32Word(value) {
|
|
183
|
+
const hex = strip0x(value);
|
|
184
|
+
if (!/^[a-fA-F0-9]{64}$/.test(hex)) throw new Error("bytes32 value must be exactly 32 bytes of hex.");
|
|
185
|
+
return hex.toLowerCase();
|
|
186
|
+
}
|
|
170
187
|
function addressWord(address) {
|
|
171
188
|
return strip0x(assertAddress(address, "Address")).padStart(64, "0");
|
|
172
189
|
}
|
|
173
190
|
function bytesPayload(value) {
|
|
174
|
-
const hex = strip0x(value);
|
|
175
|
-
if (hex.length % 2) throw new Error("
|
|
176
|
-
if (!/^[a-fA-F0-9]*$/.test(hex)) throw new Error("
|
|
191
|
+
const hex = strip0x(value || "0x");
|
|
192
|
+
if (hex.length % 2) throw new Error("Bytes payload has an odd-length hex value; refusing to encode.");
|
|
193
|
+
if (!/^[a-fA-F0-9]*$/.test(hex)) throw new Error("Bytes payload is not valid hex.");
|
|
177
194
|
const byteLength = hex.length / 2;
|
|
178
195
|
const paddedLength = Math.ceil(hex.length / 64) * 64;
|
|
179
196
|
return `${uintWord(byteLength)}${hex.padEnd(paddedLength, "0")}`;
|
|
@@ -190,19 +207,96 @@ function encodeAllowance(owner, spender) {
|
|
|
190
207
|
function encodeBalanceOf(account) {
|
|
191
208
|
return `${ERC20_BALANCEOF_SELECTOR}${addressWord(account)}`;
|
|
192
209
|
}
|
|
193
|
-
|
|
194
|
-
|
|
210
|
+
var ORDER_HEAD_WORDS = 9n;
|
|
211
|
+
var ORDER_HEAD_BYTES = ORDER_HEAD_WORDS * 32n;
|
|
212
|
+
function encodeOrderTuple(order) {
|
|
213
|
+
const askToken = bytesPayload(order.askToken);
|
|
214
|
+
const receiver = bytesPayload(order.destinationReceiver);
|
|
215
|
+
const receiverOffset = ORDER_HEAD_BYTES + BigInt(askToken.length / 2);
|
|
216
|
+
const head = [
|
|
195
217
|
addressWord(order.owner),
|
|
196
218
|
addressWord(order.bidToken),
|
|
197
219
|
uintWord(order.bidTokenAmount),
|
|
198
|
-
|
|
220
|
+
uintWord(ORDER_HEAD_BYTES),
|
|
199
221
|
uintWord(order.askTokenAmount),
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
222
|
+
uintWord(receiverOffset),
|
|
223
|
+
uint64Word(order.destinationChainId),
|
|
224
|
+
uint64Word(order.executionChainId),
|
|
225
|
+
uint64Word(order.deadline)
|
|
204
226
|
].join("");
|
|
205
|
-
return
|
|
227
|
+
return `${head}${askToken}${receiver}`;
|
|
228
|
+
}
|
|
229
|
+
function encodeSubmitOrder(orders, partnerId = NO_PARTNER_ID) {
|
|
230
|
+
if (!orders.length) throw new Error("Cannot encode an empty order request array.");
|
|
231
|
+
const tuples = orders.map(encodeOrderTuple);
|
|
232
|
+
let offset = 32n * BigInt(tuples.length);
|
|
233
|
+
const offsets = tuples.map((tuple) => {
|
|
234
|
+
const word = uintWord(offset);
|
|
235
|
+
offset += BigInt(tuple.length / 2);
|
|
236
|
+
return word;
|
|
237
|
+
}).join("");
|
|
238
|
+
return `0x${SUBMIT_ORDER_SELECTOR.slice(2)}${uintWord(64)}${bytes32Word(partnerId)}${uintWord(tuples.length)}${offsets}${tuples.join("")}`;
|
|
239
|
+
}
|
|
240
|
+
var EVM_BYTES_PAYLOAD_BYTES = 64;
|
|
241
|
+
var EVM_ORDER_TUPLE_BYTES = Number(ORDER_HEAD_BYTES) + 2 * EVM_BYTES_PAYLOAD_BYTES;
|
|
242
|
+
var MAX_DECODED_ORDERS = 16;
|
|
243
|
+
function decodeSubmitOrderCalldata(data) {
|
|
244
|
+
const hex = strip0x(String(data || "")).toLowerCase();
|
|
245
|
+
if (hex.length < 8 || hex.length % 2 !== 0 || !/^[a-f0-9]*$/.test(hex)) return null;
|
|
246
|
+
if (`0x${hex.slice(0, 8)}` !== SUBMIT_ORDER_SELECTOR) return null;
|
|
247
|
+
const body = hex.slice(8);
|
|
248
|
+
const totalBytes = body.length / 2;
|
|
249
|
+
const word = (byteOffset) => {
|
|
250
|
+
if (!Number.isSafeInteger(byteOffset) || byteOffset < 0 || byteOffset + 32 > totalBytes) return null;
|
|
251
|
+
return BigInt(`0x${body.slice(byteOffset * 2, byteOffset * 2 + 64)}`);
|
|
252
|
+
};
|
|
253
|
+
const addressAt = (byteOffset) => {
|
|
254
|
+
const w = word(byteOffset);
|
|
255
|
+
if (w === null || w >= 1n << 160n) return null;
|
|
256
|
+
return `0x${w.toString(16).padStart(40, "0")}`;
|
|
257
|
+
};
|
|
258
|
+
const uint64At = (byteOffset) => {
|
|
259
|
+
const w = word(byteOffset);
|
|
260
|
+
return w === null || w > MAX_UINT64 ? null : w;
|
|
261
|
+
};
|
|
262
|
+
const evmBytesAt = (byteOffset) => {
|
|
263
|
+
const len = word(byteOffset);
|
|
264
|
+
if (len !== 20n) return null;
|
|
265
|
+
const content = body.slice((byteOffset + 32) * 2, (byteOffset + 64) * 2);
|
|
266
|
+
if (content.length !== 64 || !content.endsWith("0".repeat(24))) return null;
|
|
267
|
+
return `0x${content.slice(0, 40)}`;
|
|
268
|
+
};
|
|
269
|
+
if (word(0) !== 64n) return null;
|
|
270
|
+
if (word(32) === null) return null;
|
|
271
|
+
const partnerId = `0x${body.slice(64, 128)}`;
|
|
272
|
+
const count = word(64);
|
|
273
|
+
if (count === null || count < 1n || count > BigInt(MAX_DECODED_ORDERS)) return null;
|
|
274
|
+
const n = Number(count);
|
|
275
|
+
const arrayBase = 96;
|
|
276
|
+
if (totalBytes !== arrayBase + 32 * n + EVM_ORDER_TUPLE_BYTES * n) return null;
|
|
277
|
+
const orders = [];
|
|
278
|
+
for (let i = 0; i < n; i += 1) {
|
|
279
|
+
const rel = word(arrayBase + i * 32);
|
|
280
|
+
if (rel === null || rel !== BigInt(32 * n + EVM_ORDER_TUPLE_BYTES * i)) return null;
|
|
281
|
+
const base = arrayBase + Number(rel);
|
|
282
|
+
const owner = addressAt(base);
|
|
283
|
+
const bidToken = addressAt(base + 32);
|
|
284
|
+
const bidTokenAmount = word(base + 64);
|
|
285
|
+
const askOffset = word(base + 96);
|
|
286
|
+
const askTokenAmount = word(base + 128);
|
|
287
|
+
const receiverOffset = word(base + 160);
|
|
288
|
+
const destinationChainId = uint64At(base + 192);
|
|
289
|
+
const executionChainId = uint64At(base + 224);
|
|
290
|
+
const deadline = uint64At(base + 256);
|
|
291
|
+
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)) {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
const askToken = evmBytesAt(base + Number(askOffset));
|
|
295
|
+
const destinationReceiver = evmBytesAt(base + Number(receiverOffset));
|
|
296
|
+
if (askToken === null || destinationReceiver === null) return null;
|
|
297
|
+
orders.push({ owner, bidToken, bidTokenAmount, askToken, askTokenAmount, destinationReceiver, destinationChainId, executionChainId, deadline });
|
|
298
|
+
}
|
|
299
|
+
return { partnerId, orders };
|
|
206
300
|
}
|
|
207
301
|
function toHexQuantity(value) {
|
|
208
302
|
const n = BigInt(value || 0);
|
|
@@ -393,7 +487,7 @@ async function solveExactOut({ option, destination, destinationToken, payer, fet
|
|
|
393
487
|
estimatedDuration: 0,
|
|
394
488
|
gasCostSource: "0",
|
|
395
489
|
gasCostDest: "0",
|
|
396
|
-
|
|
490
|
+
orderRequests: null
|
|
397
491
|
},
|
|
398
492
|
youPayRaw: targetRaw.toString(),
|
|
399
493
|
recipientReceivesRaw: targetRaw.toString(),
|
|
@@ -505,9 +599,13 @@ async function solveExactIn({ option, destination, destinationToken, payer, fetc
|
|
|
505
599
|
}
|
|
506
600
|
|
|
507
601
|
// src/core/order.ts
|
|
508
|
-
|
|
602
|
+
var DEFAULT_DEADLINE_SECONDS = 1800;
|
|
603
|
+
var MAX_DEADLINE_SECONDS = 60 * 60;
|
|
604
|
+
function normalizeOrderRequest(order, payer, destination, fallbackExecutionChainId, deadlineOverride) {
|
|
509
605
|
const apiDeadline = Number(order.deadline);
|
|
510
|
-
const deadline = Number.isFinite(apiDeadline) && apiDeadline > 0 ? String(order.deadline) : String(Math.floor(Date.now() / 1e3) +
|
|
606
|
+
const deadline = deadlineOverride ?? (Number.isFinite(apiDeadline) && apiDeadline > 0 ? String(order.deadline) : String(Math.floor(Date.now() / 1e3) + DEFAULT_DEADLINE_SECONDS));
|
|
607
|
+
const executionChainId = String(order.executionChainId || fallbackExecutionChainId || "0");
|
|
608
|
+
if (!/^\d+$/.test(executionChainId) || BigInt(executionChainId) <= 0n) throw new Error("ZeroDelta quote did not include an execution chain.");
|
|
511
609
|
return {
|
|
512
610
|
owner: assertAddress(order.owner || payer, "Order owner"),
|
|
513
611
|
bidToken: assertAddress(order.bidToken, "Bid token"),
|
|
@@ -516,26 +614,40 @@ function normalizeOrderRequest(order, payer, destination) {
|
|
|
516
614
|
askTokenAmount: String(order.askTokenAmount || "0"),
|
|
517
615
|
destinationReceiver: assertAddress(order.destinationReceiver || destination.address, "Destination receiver"),
|
|
518
616
|
destinationChainId: String(order.destinationChainId || destination.chainId),
|
|
519
|
-
|
|
520
|
-
|
|
617
|
+
executionChainId,
|
|
618
|
+
deadline
|
|
521
619
|
};
|
|
522
620
|
}
|
|
523
|
-
function
|
|
621
|
+
function normalizeOrderRequests(requests, payer, destination, fallbackExecutionChainId) {
|
|
622
|
+
if (!requests.length) throw new Error("ZeroDelta quote did not include any order requests.");
|
|
623
|
+
return requests.map(
|
|
624
|
+
(request, index) => index === 0 ? normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId) : normalizeOrderRequest(request, payer, destination, fallbackExecutionChainId, String(request.deadline || "0"))
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
function assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result }) {
|
|
628
|
+
const list = orders?.length ? orders : [order];
|
|
629
|
+
const sourceOrder = list[0];
|
|
630
|
+
const finalOrder = list[list.length - 1];
|
|
524
631
|
const now = Math.floor(Date.now() / 1e3);
|
|
525
|
-
const deadline = Number(
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
632
|
+
const deadline = Number(sourceOrder.deadline || 0);
|
|
633
|
+
for (const current of list) {
|
|
634
|
+
if (normalizeAddress(current.owner) !== normalizeAddress(payer)) {
|
|
635
|
+
throw new Error("ZeroDelta quote returned an owner that does not match the connected wallet.");
|
|
636
|
+
}
|
|
637
|
+
if (normalizeAddress(current.destinationReceiver) !== normalizeAddress(destination.address)) {
|
|
638
|
+
throw new Error("ZeroDelta quote returned a receiver that does not match the detected destination.");
|
|
639
|
+
}
|
|
640
|
+
if (!/^\d+$/.test(current.executionChainId || "") || BigInt(current.executionChainId) <= 0n) {
|
|
641
|
+
throw new Error("ZeroDelta quote returned an order without an execution chain.");
|
|
642
|
+
}
|
|
531
643
|
}
|
|
532
|
-
if (normalizeAddress(
|
|
644
|
+
if (normalizeAddress(sourceOrder.bidToken) !== normalizeAddress(option.address)) {
|
|
533
645
|
throw new Error("ZeroDelta quote returned a bid token that does not match the selected route.");
|
|
534
646
|
}
|
|
535
|
-
if (normalizeAddress(
|
|
647
|
+
if (normalizeAddress(finalOrder.askToken) !== normalizeAddress(destinationToken.address)) {
|
|
536
648
|
throw new Error("ZeroDelta quote returned an ask token that does not match the destination asset.");
|
|
537
649
|
}
|
|
538
|
-
if (Number(
|
|
650
|
+
if (Number(finalOrder.destinationChainId) !== Number(destination.chainId) || Number(quote.toChainId) !== Number(destination.chainId)) {
|
|
539
651
|
throw new Error("ZeroDelta quote returned a destination chain that does not match the payment request.");
|
|
540
652
|
}
|
|
541
653
|
if (Number(quote.fromChainId) !== Number(option.chainId)) {
|
|
@@ -544,24 +656,38 @@ function assertQuoteMatchesSelection({ quote, order, option, destinationToken, d
|
|
|
544
656
|
if (symbolKey(quote.fromToken) !== option.symbolKey || symbolKey(quote.toToken) !== symbolKey(destinationToken.symbol)) {
|
|
545
657
|
throw new Error("ZeroDelta quote returned token symbols that do not match the selected route.");
|
|
546
658
|
}
|
|
547
|
-
if (BigInt(
|
|
659
|
+
if (BigInt(sourceOrder.bidTokenAmount || "0") !== BigInt(result.youPayRaw || "0")) {
|
|
548
660
|
throw new Error("ZeroDelta quote returned a bid amount that does not match the displayed payment amount.");
|
|
549
661
|
}
|
|
550
|
-
if (BigInt(
|
|
662
|
+
if (BigInt(finalOrder.askTokenAmount || "0") !== BigInt(quote.toAmount || "0")) {
|
|
551
663
|
throw new Error("ZeroDelta quote returned an ask amount that does not match the quoted output.");
|
|
552
664
|
}
|
|
553
|
-
if (BigInt(
|
|
665
|
+
if (BigInt(finalOrder.askTokenAmount || "0") <= 0n || BigInt(quote.toAmount || "0") <= 0n) {
|
|
554
666
|
throw new Error("ZeroDelta quote returned a non-positive output amount.");
|
|
555
667
|
}
|
|
556
|
-
if (BigInt(
|
|
668
|
+
if (BigInt(finalOrder.askTokenAmount || "0") < BigInt(result.targetRaw || "0")) {
|
|
557
669
|
throw new Error("ZeroDelta quote would not cover the requested destination amount.");
|
|
558
670
|
}
|
|
559
|
-
if (BigInt(
|
|
671
|
+
if (BigInt(finalOrder.askTokenAmount || "0") < BigInt(result.recipientReceivesRaw || "0")) {
|
|
560
672
|
throw new Error("ZeroDelta order guarantees less than the displayed receive amount.");
|
|
561
673
|
}
|
|
562
|
-
if (!Number.isFinite(deadline) || deadline <= now || deadline > now +
|
|
674
|
+
if (!Number.isFinite(deadline) || deadline <= now || deadline > now + MAX_DEADLINE_SECONDS) {
|
|
563
675
|
throw new Error("ZeroDelta quote deadline is invalid or too far in the future.");
|
|
564
676
|
}
|
|
677
|
+
for (let index = 1; index < list.length; index += 1) {
|
|
678
|
+
const previous = list[index - 1];
|
|
679
|
+
const current = list[index];
|
|
680
|
+
if (normalizeAddress(previous.askToken) !== normalizeAddress(current.bidToken)) {
|
|
681
|
+
throw new Error("ZeroDelta chained quote returned disconnected order tokens.");
|
|
682
|
+
}
|
|
683
|
+
if (Number(previous.destinationChainId) !== Number(current.executionChainId)) {
|
|
684
|
+
throw new Error("ZeroDelta chained quote returned disconnected execution chains.");
|
|
685
|
+
}
|
|
686
|
+
const followupDeadline = Number(current.deadline || 0);
|
|
687
|
+
if (followupDeadline !== 0 && (!Number.isFinite(followupDeadline) || followupDeadline <= now || followupDeadline > now + MAX_DEADLINE_SECONDS)) {
|
|
688
|
+
throw new Error("ZeroDelta chained quote returned an invalid follow-up deadline.");
|
|
689
|
+
}
|
|
690
|
+
}
|
|
565
691
|
}
|
|
566
692
|
|
|
567
693
|
// src/core/route.ts
|
|
@@ -628,11 +754,13 @@ async function buildRoute({ option, destination, destinationToken, chains, payer
|
|
|
628
754
|
}
|
|
629
755
|
};
|
|
630
756
|
}
|
|
631
|
-
|
|
757
|
+
const requestList = quote.orderRequests?.length ? quote.orderRequests : quote.orderRequest ? [quote.orderRequest] : [];
|
|
758
|
+
if (!requestList.length) throw new Error("ZeroDelta quote did not include an order request.");
|
|
632
759
|
const sourceChain = chainById(chains, option.chainId);
|
|
633
760
|
const escrow = checkEscrow(option.chainId, quote.escrowAddress, sourceChain?.escrowContract);
|
|
634
|
-
const
|
|
635
|
-
|
|
761
|
+
const orders = normalizeOrderRequests(requestList, payer, destination, quote.executionChainId);
|
|
762
|
+
const order = orders[0];
|
|
763
|
+
assertQuoteMatchesSelection({ quote, order, orders, option, destinationToken, destination, payer, result });
|
|
636
764
|
const needsNativeFee = requiresNativeBridgeFee(quote, option);
|
|
637
765
|
if (needsNativeFee) {
|
|
638
766
|
let rawFee;
|
|
@@ -693,7 +821,7 @@ async function buildRoute({ option, destination, destinationToken, chains, payer
|
|
|
693
821
|
label: "Submit ZeroDelta order",
|
|
694
822
|
chainId: option.chainId,
|
|
695
823
|
to: escrow,
|
|
696
|
-
data: encodeSubmitOrder(
|
|
824
|
+
data: encodeSubmitOrder(orders),
|
|
697
825
|
value: toHexQuantity(valueRaw),
|
|
698
826
|
escrow,
|
|
699
827
|
amountRaw: order.bidTokenAmount
|
|
@@ -869,6 +997,16 @@ function createApiClient(cfg) {
|
|
|
869
997
|
}
|
|
870
998
|
|
|
871
999
|
// src/core/plan.ts
|
|
1000
|
+
function optionBalanceKey(option) {
|
|
1001
|
+
return `${Number(option.chainId)}:${String(option.address || "").toLowerCase()}`;
|
|
1002
|
+
}
|
|
1003
|
+
function hasPositiveBalance(option, balances) {
|
|
1004
|
+
try {
|
|
1005
|
+
return BigInt(balances[optionBalanceKey(option)]?.raw ?? "0") > 0n;
|
|
1006
|
+
} catch {
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
872
1010
|
function validateDestination(destination) {
|
|
873
1011
|
assertAddress(destination.address, "Destination address");
|
|
874
1012
|
const chainId = Number(destination.chainId);
|
|
@@ -884,7 +1022,7 @@ function planErrorSummary(errors) {
|
|
|
884
1022
|
const unique = [...new Set(errors.map((error) => error?.message || String(error)).filter(Boolean))].slice(0, 3);
|
|
885
1023
|
return unique.length ? unique.join(" | ") : "No ZeroDelta route is currently available for this payment.";
|
|
886
1024
|
}
|
|
887
|
-
async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
1025
|
+
async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances) {
|
|
888
1026
|
validateDestination(request);
|
|
889
1027
|
assertAddress(payer, "Payer wallet");
|
|
890
1028
|
const [chains, tokens, routes] = await Promise.all([api.fetchChains(), api.fetchTokens(), api.fetchRoutes()]);
|
|
@@ -895,6 +1033,7 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
895
1033
|
};
|
|
896
1034
|
const destinationToken = findToken(tokens, destination.chainId, destination.asset);
|
|
897
1035
|
if (!destinationToken) throw new Error(`${destination.asset} is not enabled on ${chainNameOf(destination.chainId, chains)}.`);
|
|
1036
|
+
const allowedFunding = wallet.fundingAssets?.length ? new Set(wallet.fundingAssets.map(symbolKey)) : null;
|
|
898
1037
|
const options = buildPayOptions({
|
|
899
1038
|
invoiceAsset: destination.asset,
|
|
900
1039
|
invoiceChainId: destination.chainId,
|
|
@@ -902,14 +1041,25 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
902
1041
|
routes,
|
|
903
1042
|
chains,
|
|
904
1043
|
walletChainId: wallet?.chainId
|
|
905
|
-
});
|
|
1044
|
+
}).filter((option) => option.direct || !allowedFunding || allowedFunding.has(option.symbolKey));
|
|
906
1045
|
if (!options.length) throw new Error(`No enabled ZeroDelta funding assets can settle ${destination.asset} on ${chainNameOf(destination.chainId, chains)}.`);
|
|
1046
|
+
const balanceTargets = [];
|
|
1047
|
+
const seenTargets = /* @__PURE__ */ new Set();
|
|
1048
|
+
for (const option of options) {
|
|
1049
|
+
const key = optionBalanceKey(option);
|
|
1050
|
+
if (seenTargets.has(key)) continue;
|
|
1051
|
+
seenTargets.add(key);
|
|
1052
|
+
balanceTargets.push({ chainId: option.chainId, tokenAddress: option.address, decimals: option.decimals });
|
|
1053
|
+
}
|
|
1054
|
+
const walletBalances = readBalances ? await readBalances(payer, balanceTargets).catch(() => ({})) : {};
|
|
907
1055
|
const candidates = options.filter((option) => option.direct);
|
|
1056
|
+
const heldOptions = options.filter((option) => !option.direct && hasPositiveBalance(option, walletBalances));
|
|
1057
|
+
const heldKeys = new Set(heldOptions.map(optionBalanceKey));
|
|
908
1058
|
const seenChains = /* @__PURE__ */ new Set();
|
|
909
1059
|
const perChainBest = [];
|
|
910
1060
|
const leftovers = [];
|
|
911
1061
|
for (const option of options) {
|
|
912
|
-
if (option.direct) continue;
|
|
1062
|
+
if (option.direct || heldKeys.has(optionBalanceKey(option))) continue;
|
|
913
1063
|
if (seenChains.has(option.chainId)) {
|
|
914
1064
|
leftovers.push(option);
|
|
915
1065
|
} else {
|
|
@@ -917,7 +1067,7 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
917
1067
|
perChainBest.push(option);
|
|
918
1068
|
}
|
|
919
1069
|
}
|
|
920
|
-
for (const option of [...perChainBest, ...leftovers].slice(0, MAX_QUOTE_CANDIDATES)) {
|
|
1070
|
+
for (const option of [...heldOptions, ...perChainBest, ...leftovers].slice(0, MAX_QUOTE_CANDIDATES)) {
|
|
921
1071
|
candidates.push(option);
|
|
922
1072
|
}
|
|
923
1073
|
const routeErrors = [];
|
|
@@ -952,6 +1102,8 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}) {
|
|
|
952
1102
|
expiresAt: new Date(Date.now() + 2 * 60 * 1e3).toISOString(),
|
|
953
1103
|
apiBase: api.apiBase,
|
|
954
1104
|
routes: routesBuilt,
|
|
1105
|
+
fundingBalances: walletBalances,
|
|
1106
|
+
fundingAccount: payer.toLowerCase(),
|
|
955
1107
|
destination: {
|
|
956
1108
|
asset: destinationToken.symbol,
|
|
957
1109
|
chainId: destination.chainId,
|
|
@@ -1109,7 +1261,12 @@ function validatePlannedTransaction(tx, route, expectedRecipient) {
|
|
|
1109
1261
|
if (tx.kind === "submitOrder") {
|
|
1110
1262
|
const expected = planMsgValueHex(route);
|
|
1111
1263
|
if (expected === null || value !== lower(expected)) return false;
|
|
1112
|
-
|
|
1264
|
+
if (selector !== SUBMIT_ORDER_SELECTOR || !isHexAddress(tx.escrow) || lower(tx.to) !== lower(tx.escrow)) return false;
|
|
1265
|
+
const decoded = decodeSubmitOrderCalldata(data);
|
|
1266
|
+
if (!decoded) return false;
|
|
1267
|
+
const first = decoded.orders[0];
|
|
1268
|
+
const last = decoded.orders[decoded.orders.length - 1];
|
|
1269
|
+
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);
|
|
1113
1270
|
}
|
|
1114
1271
|
return false;
|
|
1115
1272
|
}
|
|
@@ -1180,6 +1337,23 @@ function createVerifier(api, fetchImpl, rpcOverrides = {}) {
|
|
|
1180
1337
|
const json = await response.json();
|
|
1181
1338
|
return json?.result ?? null;
|
|
1182
1339
|
}
|
|
1340
|
+
async function rpcBatchCall(rpcUrl, calls) {
|
|
1341
|
+
const response = await fetchImpl(rpcUrl, {
|
|
1342
|
+
method: "POST",
|
|
1343
|
+
headers: { "Content-Type": "application/json" },
|
|
1344
|
+
body: JSON.stringify(calls.map((call, index) => ({ jsonrpc: "2.0", id: index + 1, ...call }))),
|
|
1345
|
+
signal: AbortSignal.timeout(TX_VERIFY_FETCH_MS)
|
|
1346
|
+
});
|
|
1347
|
+
if (!response.ok) throw new Error(`RPC ${response.status}`);
|
|
1348
|
+
const json = await response.json();
|
|
1349
|
+
if (!Array.isArray(json)) throw new Error("RPC batch unsupported");
|
|
1350
|
+
const results = /* @__PURE__ */ new Map();
|
|
1351
|
+
for (const item of json) {
|
|
1352
|
+
const id = Number(item?.id);
|
|
1353
|
+
if (Number.isInteger(id) && Object.hasOwn(item || {}, "result")) results.set(id, item.result);
|
|
1354
|
+
}
|
|
1355
|
+
return results;
|
|
1356
|
+
}
|
|
1183
1357
|
async function payerNonceBaseline(chainId, account) {
|
|
1184
1358
|
if (!isAddress(account)) return null;
|
|
1185
1359
|
const rpcUrl = await chainRpcUrl(chainId);
|
|
@@ -1246,25 +1420,54 @@ function createVerifier(api, fetchImpl, rpcOverrides = {}) {
|
|
|
1246
1420
|
const out = {};
|
|
1247
1421
|
if (!isAddress(account) || !Array.isArray(targets) || !targets.length) return out;
|
|
1248
1422
|
const owner = normalizeAddress(account);
|
|
1249
|
-
const
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1423
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1424
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1425
|
+
for (const target of targets) {
|
|
1426
|
+
if (!target || !isAddress(target.tokenAddress)) continue;
|
|
1427
|
+
const key = `${Number(target.chainId)}:${String(target.tokenAddress).toLowerCase()}`;
|
|
1428
|
+
if (seen.has(key)) continue;
|
|
1429
|
+
seen.add(key);
|
|
1430
|
+
const chainId = Number(target.chainId);
|
|
1431
|
+
const group = groups.get(chainId) || [];
|
|
1432
|
+
group.push(target);
|
|
1433
|
+
groups.set(chainId, group);
|
|
1434
|
+
}
|
|
1435
|
+
function record(target, hex) {
|
|
1436
|
+
if (typeof hex !== "string" || !/^0x[0-9a-fA-F]*$/.test(hex)) return false;
|
|
1437
|
+
const raw = BigInt(hex || "0x0").toString();
|
|
1438
|
+
const key = `${Number(target.chainId)}:${String(target.tokenAddress).toLowerCase()}`;
|
|
1439
|
+
out[key] = { raw, formatted: formatUnits(raw, Number(target.decimals)) };
|
|
1440
|
+
return true;
|
|
1441
|
+
}
|
|
1442
|
+
async function readOne(rpcUrl, target) {
|
|
1443
|
+
try {
|
|
1444
|
+
const hex = await rpcCall(rpcUrl, "eth_call", [{ to: normalizeAddress(target.tokenAddress), data: encodeBalanceOf(owner) }, "latest"]);
|
|
1445
|
+
record(target, hex);
|
|
1446
|
+
} catch {
|
|
1265
1447
|
}
|
|
1266
1448
|
}
|
|
1267
|
-
|
|
1449
|
+
async function readGroup(chainId, group) {
|
|
1450
|
+
const rpcUrl = await balanceRpcUrl(chainId).catch(() => "");
|
|
1451
|
+
if (!rpcUrl) return;
|
|
1452
|
+
if (group.length === 1) return readOne(rpcUrl, group[0]);
|
|
1453
|
+
try {
|
|
1454
|
+
const results = await rpcBatchCall(
|
|
1455
|
+
rpcUrl,
|
|
1456
|
+
group.map((target) => ({
|
|
1457
|
+
method: "eth_call",
|
|
1458
|
+
params: [{ to: normalizeAddress(target.tokenAddress), data: encodeBalanceOf(owner) }, "latest"]
|
|
1459
|
+
}))
|
|
1460
|
+
);
|
|
1461
|
+
const missing = [];
|
|
1462
|
+
group.forEach((target, index) => {
|
|
1463
|
+
if (!record(target, results.get(index + 1))) missing.push(target);
|
|
1464
|
+
});
|
|
1465
|
+
await Promise.all(missing.map((target) => readOne(rpcUrl, target)));
|
|
1466
|
+
} catch {
|
|
1467
|
+
await Promise.all(group.map((target) => readOne(rpcUrl, target)));
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
await Promise.all([...groups.entries()].map(([chainId, group]) => readGroup(chainId, group)));
|
|
1268
1471
|
return out;
|
|
1269
1472
|
}
|
|
1270
1473
|
async function readNativeBalance(chainId, account) {
|
|
@@ -1366,7 +1569,7 @@ function createEngine(config = {}) {
|
|
|
1366
1569
|
fetchTokens: api.fetchTokens,
|
|
1367
1570
|
fetchRoutes: api.fetchRoutes,
|
|
1368
1571
|
fetchQuote: api.fetchQuote,
|
|
1369
|
-
fetchPaymentPlan: (request, payer, wallet) => fetchPaymentPlan(api, request, payer, wallet),
|
|
1572
|
+
fetchPaymentPlan: (request, payer, wallet) => fetchPaymentPlan(api, request, payer, wallet, verifier.readBalances),
|
|
1370
1573
|
quoteSwapPreview: (swap, owner) => quoteSwapPreview(api, swap, owner),
|
|
1371
1574
|
buildSwapPlan: (swap, payer, wallet) => buildSwapPlan(api, swap, payer, wallet),
|
|
1372
1575
|
payerNonceBaseline: verifier.payerNonceBaseline,
|
|
@@ -1875,7 +2078,7 @@ function useFlow(args) {
|
|
|
1875
2078
|
function balanceKey(chainId, tokenAddress) {
|
|
1876
2079
|
return `${Number(chainId)}:${String(tokenAddress || "").toLowerCase()}`;
|
|
1877
2080
|
}
|
|
1878
|
-
function useHoldings(engine, account, routes) {
|
|
2081
|
+
function useHoldings(engine, account, routes, initialBalances) {
|
|
1879
2082
|
const [balances, setBalances] = react.useState({});
|
|
1880
2083
|
const [loading, setLoading] = react.useState(false);
|
|
1881
2084
|
const reqId = react.useRef(0);
|
|
@@ -1900,19 +2103,32 @@ function useHoldings(engine, account, routes) {
|
|
|
1900
2103
|
return;
|
|
1901
2104
|
}
|
|
1902
2105
|
const id = ++reqId.current;
|
|
2106
|
+
const seeded = {};
|
|
2107
|
+
const missing = [];
|
|
2108
|
+
for (const target of targets) {
|
|
2109
|
+
const key = balanceKey(target.chainId, target.tokenAddress);
|
|
2110
|
+
const balance = initialBalances?.[key];
|
|
2111
|
+
if (balance) seeded[key] = balance;
|
|
2112
|
+
else missing.push(target);
|
|
2113
|
+
}
|
|
2114
|
+
setBalances(seeded);
|
|
2115
|
+
if (!missing.length) {
|
|
2116
|
+
setLoading(false);
|
|
2117
|
+
return;
|
|
2118
|
+
}
|
|
1903
2119
|
setLoading(true);
|
|
1904
2120
|
(async () => {
|
|
1905
2121
|
try {
|
|
1906
|
-
const res = await engine.readBalances(account,
|
|
2122
|
+
const res = await engine.readBalances(account, missing);
|
|
1907
2123
|
if (id !== reqId.current) return;
|
|
1908
|
-
setBalances(res);
|
|
2124
|
+
setBalances({ ...seeded, ...res });
|
|
1909
2125
|
} catch {
|
|
1910
|
-
if (id === reqId.current) setBalances(
|
|
2126
|
+
if (id === reqId.current) setBalances(seeded);
|
|
1911
2127
|
} finally {
|
|
1912
2128
|
if (id === reqId.current) setLoading(false);
|
|
1913
2129
|
}
|
|
1914
2130
|
})();
|
|
1915
|
-
}, [engine, account, targetsKey]);
|
|
2131
|
+
}, [engine, account, targetsKey, initialBalances]);
|
|
1916
2132
|
return { balances, loading };
|
|
1917
2133
|
}
|
|
1918
2134
|
|
|
@@ -2456,9 +2672,10 @@ var CHAIN_LABELS = {
|
|
|
2456
2672
|
8453: "Base",
|
|
2457
2673
|
9745: "Plasma",
|
|
2458
2674
|
57073: "Ink",
|
|
2459
|
-
42161: "Arbitrum"
|
|
2675
|
+
42161: "Arbitrum",
|
|
2676
|
+
98866: "Plume"
|
|
2460
2677
|
};
|
|
2461
|
-
var SUPPORTED_CHAINS = [1, 10, 42161, 8453, 57073, 130, 9745, 146];
|
|
2678
|
+
var SUPPORTED_CHAINS = [1, 10, 42161, 8453, 57073, 130, 9745, 146, 98866];
|
|
2462
2679
|
var SUPPORTED_ASSETS2 = ["USDC", "USDT", "USDE", "XAUT"];
|
|
2463
2680
|
function Button(props) {
|
|
2464
2681
|
const soft = !!props.softDisabled && !props.disabled;
|
|
@@ -2657,7 +2874,8 @@ var CHAIN_SHORT = {
|
|
|
2657
2874
|
8453: "BASE",
|
|
2658
2875
|
9745: "PLS",
|
|
2659
2876
|
57073: "INK",
|
|
2660
|
-
42161: "ARB"
|
|
2877
|
+
42161: "ARB",
|
|
2878
|
+
98866: "PLM"
|
|
2661
2879
|
};
|
|
2662
2880
|
function isHttpsUrl(u) {
|
|
2663
2881
|
return typeof u === "string" && /^https:\/\//i.test(u);
|
|
@@ -3051,7 +3269,21 @@ var addrEq = (a, b) => String(a || "").toLowerCase() === String(b || "").toLower
|
|
|
3051
3269
|
var chainName = (id) => id != null ? CHAIN_LABELS[id] || `Chain ${id}` : "";
|
|
3052
3270
|
var STABLES = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
|
|
3053
3271
|
function BankGlyph() {
|
|
3054
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3272
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3273
|
+
"svg",
|
|
3274
|
+
{
|
|
3275
|
+
width: "18",
|
|
3276
|
+
height: "18",
|
|
3277
|
+
viewBox: "0 0 24 24",
|
|
3278
|
+
fill: "none",
|
|
3279
|
+
stroke: "currentColor",
|
|
3280
|
+
strokeWidth: "2",
|
|
3281
|
+
strokeLinecap: "round",
|
|
3282
|
+
strokeLinejoin: "round",
|
|
3283
|
+
"aria-hidden": "true",
|
|
3284
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 10h18M5 10v8M10 10v8M14 10v8M19 10v8M3 19h18M12 3 3 8h18Z" })
|
|
3285
|
+
}
|
|
3286
|
+
);
|
|
3055
3287
|
}
|
|
3056
3288
|
function MerchantBankPayout(props) {
|
|
3057
3289
|
const bankName = props.account?.bankName?.trim() || "Bank account";
|
|
@@ -3078,25 +3310,81 @@ function MerchantBankPayout(props) {
|
|
|
3078
3310
|
] }) }) });
|
|
3079
3311
|
}
|
|
3080
3312
|
function CheckGlyph2() {
|
|
3081
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3313
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3314
|
+
"svg",
|
|
3315
|
+
{
|
|
3316
|
+
width: "20",
|
|
3317
|
+
height: "20",
|
|
3318
|
+
viewBox: "0 0 24 24",
|
|
3319
|
+
fill: "none",
|
|
3320
|
+
stroke: "currentColor",
|
|
3321
|
+
strokeWidth: "3",
|
|
3322
|
+
strokeLinecap: "round",
|
|
3323
|
+
strokeLinejoin: "round",
|
|
3324
|
+
"aria-hidden": "true",
|
|
3325
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5" })
|
|
3326
|
+
}
|
|
3327
|
+
);
|
|
3082
3328
|
}
|
|
3083
3329
|
function ArrowGlyph() {
|
|
3084
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3330
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3331
|
+
"svg",
|
|
3332
|
+
{
|
|
3333
|
+
width: "14",
|
|
3334
|
+
height: "14",
|
|
3335
|
+
viewBox: "0 0 24 24",
|
|
3336
|
+
fill: "none",
|
|
3337
|
+
stroke: "currentColor",
|
|
3338
|
+
strokeWidth: "2.4",
|
|
3339
|
+
strokeLinecap: "round",
|
|
3340
|
+
strokeLinejoin: "round",
|
|
3341
|
+
"aria-hidden": "true",
|
|
3342
|
+
children: [
|
|
3343
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 12h14" }),
|
|
3344
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "m13 6 6 6-6 6" })
|
|
3345
|
+
]
|
|
3346
|
+
}
|
|
3347
|
+
);
|
|
3088
3348
|
}
|
|
3089
3349
|
function ClockGlyph() {
|
|
3090
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3350
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3351
|
+
"svg",
|
|
3352
|
+
{
|
|
3353
|
+
width: "20",
|
|
3354
|
+
height: "20",
|
|
3355
|
+
viewBox: "0 0 24 24",
|
|
3356
|
+
fill: "none",
|
|
3357
|
+
stroke: "currentColor",
|
|
3358
|
+
strokeWidth: "2.2",
|
|
3359
|
+
strokeLinecap: "round",
|
|
3360
|
+
strokeLinejoin: "round",
|
|
3361
|
+
"aria-hidden": "true",
|
|
3362
|
+
children: [
|
|
3363
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "9" }),
|
|
3364
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 7v5l3 2" })
|
|
3365
|
+
]
|
|
3366
|
+
}
|
|
3367
|
+
);
|
|
3094
3368
|
}
|
|
3095
3369
|
function WalletGlyph() {
|
|
3096
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3370
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3371
|
+
"svg",
|
|
3372
|
+
{
|
|
3373
|
+
width: "16",
|
|
3374
|
+
height: "16",
|
|
3375
|
+
viewBox: "0 0 24 24",
|
|
3376
|
+
fill: "none",
|
|
3377
|
+
stroke: "currentColor",
|
|
3378
|
+
strokeWidth: "2",
|
|
3379
|
+
strokeLinecap: "round",
|
|
3380
|
+
strokeLinejoin: "round",
|
|
3381
|
+
"aria-hidden": "true",
|
|
3382
|
+
children: [
|
|
3383
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "3", y: "6", width: "18", height: "13", rx: "2" }),
|
|
3384
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M16 12h.01M3 9h18" })
|
|
3385
|
+
]
|
|
3386
|
+
}
|
|
3387
|
+
);
|
|
3100
3388
|
}
|
|
3101
3389
|
function LinkMenu(props) {
|
|
3102
3390
|
const [open, setOpen] = react.useState(false);
|
|
@@ -3207,7 +3495,13 @@ function IdentityLine(props) {
|
|
|
3207
3495
|
function PaymentIsland(props) {
|
|
3208
3496
|
injectStyles();
|
|
3209
3497
|
const config = useMergedConfig(props);
|
|
3210
|
-
const engine = useEngine({
|
|
3498
|
+
const engine = useEngine({
|
|
3499
|
+
apiBase: config.apiBase,
|
|
3500
|
+
apiKey: config.apiKey,
|
|
3501
|
+
trustedApiOrigin: config.trustedApiOrigin,
|
|
3502
|
+
rpcOverrides: config.rpcOverrides,
|
|
3503
|
+
onTransaction: config.onTransaction
|
|
3504
|
+
});
|
|
3211
3505
|
const wallet = useWallet(config.provider);
|
|
3212
3506
|
const kind = props.kind;
|
|
3213
3507
|
const isPay = kind === "pay";
|
|
@@ -3236,7 +3530,8 @@ function PaymentIsland(props) {
|
|
|
3236
3530
|
const normEx = normalizeDecimalText(exAmount);
|
|
3237
3531
|
const exAmountValid = /^\d+(\.\d+)?$/.test(normEx) && Number(normEx) > 0 && Number(normEx) <= 1e9;
|
|
3238
3532
|
const exQuotable = !rampMode && exAmountValid && Boolean(exFromChainId && exFromAsset && exToChainId && exToAsset);
|
|
3239
|
-
const
|
|
3533
|
+
const payFundingAssets = props.fundingAssets?.length ? props.fundingAssets : ["USDC", "USDT", "USDE"];
|
|
3534
|
+
const payParamsKey = `pay|${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}|${payFundingAssets.join(",")}`;
|
|
3240
3535
|
const exParamsKey = `${kind}|${mode}|${exFromChainId}|${exFromAsset}|${exToChainId}|${exToAsset}|${normEx}|${props.recipient ?? ""}`;
|
|
3241
3536
|
const flow = useFlow({
|
|
3242
3537
|
engine,
|
|
@@ -3246,7 +3541,20 @@ function PaymentIsland(props) {
|
|
|
3246
3541
|
// quote (and fire onQuote) for a payment whose CTA it never shows.
|
|
3247
3542
|
enabled: isPay ? Boolean(props.recipient && props.amount) && !bankSettlement : exQuotable,
|
|
3248
3543
|
paramsKey: isPay ? payParamsKey : exParamsKey,
|
|
3249
|
-
loadPlan: isPay ? (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
3544
|
+
loadPlan: isPay ? (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
3545
|
+
chainId,
|
|
3546
|
+
fundingAssets: payFundingAssets
|
|
3547
|
+
}) : (e, payer) => e.buildSwapPlan(
|
|
3548
|
+
{
|
|
3549
|
+
fromChainId: exFromChainId,
|
|
3550
|
+
toChainId: exToChainId,
|
|
3551
|
+
fromToken: exFromAsset,
|
|
3552
|
+
toToken: exToAsset,
|
|
3553
|
+
amountIn: normEx,
|
|
3554
|
+
recipient: props.recipient
|
|
3555
|
+
},
|
|
3556
|
+
payer
|
|
3557
|
+
),
|
|
3250
3558
|
recipientFor: (account) => isPay ? props.recipient : props.recipient || account,
|
|
3251
3559
|
onQuote: config.onQuote,
|
|
3252
3560
|
onSuccess: config.onSuccess,
|
|
@@ -3254,15 +3562,14 @@ function PaymentIsland(props) {
|
|
|
3254
3562
|
});
|
|
3255
3563
|
const [method, setMethod] = react.useState("stablecoin");
|
|
3256
3564
|
const parked = isPay && !isLiveMethod(method);
|
|
3257
|
-
const fundingSet = react.useMemo(
|
|
3258
|
-
() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
|
|
3259
|
-
[props.fundingAssets]
|
|
3260
|
-
);
|
|
3565
|
+
const fundingSet = react.useMemo(() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null, [props.fundingAssets]);
|
|
3261
3566
|
const visibleRoutes = react.useMemo(() => {
|
|
3262
3567
|
const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
|
|
3263
|
-
return isPay && method === "stablecoin" ? base.filter((r) => STABLES.has(r.source.asset)) : base;
|
|
3568
|
+
return isPay && method === "stablecoin" ? base.filter((r) => STABLES.has(symbolKey(r.source.asset))) : base;
|
|
3264
3569
|
}, [flow.routes, fundingSet, isPay, method]);
|
|
3265
|
-
const
|
|
3570
|
+
const paymentPlan = flow.plan;
|
|
3571
|
+
const prefetchedBalances = paymentPlan && paymentPlan.fundingAccount === wallet.account?.toLowerCase() ? paymentPlan.fundingBalances : void 0;
|
|
3572
|
+
const holdings = useHoldings(engine, wallet.account, flow.routes, prefetchedBalances);
|
|
3266
3573
|
const annotated = react.useMemo(
|
|
3267
3574
|
() => visibleRoutes.map((r) => {
|
|
3268
3575
|
const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
|
|
@@ -3357,7 +3664,15 @@ function PaymentIsland(props) {
|
|
|
3357
3664
|
if (seen.has(key)) continue;
|
|
3358
3665
|
seen.add(key);
|
|
3359
3666
|
const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq(t.address, r.source.tokenAddress));
|
|
3360
|
-
list.push(
|
|
3667
|
+
list.push(
|
|
3668
|
+
reg ?? {
|
|
3669
|
+
symbol: r.source.asset,
|
|
3670
|
+
name: r.source.asset,
|
|
3671
|
+
chainId: r.source.chainId,
|
|
3672
|
+
address: r.source.tokenAddress ?? "",
|
|
3673
|
+
decimals: r.source.decimals ?? 18
|
|
3674
|
+
}
|
|
3675
|
+
);
|
|
3361
3676
|
}
|
|
3362
3677
|
return list;
|
|
3363
3678
|
}, [visibleRoutes, registryTokens]);
|
|
@@ -3567,7 +3882,18 @@ function PaymentIsland(props) {
|
|
|
3567
3882
|
if (hist && wallet.account) {
|
|
3568
3883
|
body = /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory });
|
|
3569
3884
|
} else if (isPay && view === "select" && wallet.account) {
|
|
3570
|
-
body = /* @__PURE__ */ jsxRuntime.jsx(
|
|
3885
|
+
body = /* @__PURE__ */ jsxRuntime.jsx(
|
|
3886
|
+
TokenSelect,
|
|
3887
|
+
{
|
|
3888
|
+
title: "Pay with",
|
|
3889
|
+
chains: fundingChains,
|
|
3890
|
+
tokens: fundingTokens,
|
|
3891
|
+
balances: holdings.balances,
|
|
3892
|
+
optionStates,
|
|
3893
|
+
onBack: () => closeSelector(),
|
|
3894
|
+
onPick: pickFunding
|
|
3895
|
+
}
|
|
3896
|
+
);
|
|
3571
3897
|
} else if (!isPay && (view === "from" || view === "to")) {
|
|
3572
3898
|
const isFrom = view === "from";
|
|
3573
3899
|
const openerRef = isFrom ? exFromTileRef : exToTileRef;
|
|
@@ -3767,22 +4093,66 @@ function PaymentIsland(props) {
|
|
|
3767
4093
|
const islandVars = themeToVars(resolved);
|
|
3768
4094
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-wrap", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-island", "data-sg-mode": resolved.mode, "data-expanded": expanded, "data-status": flow.status, style: islandVars, children: [
|
|
3769
4095
|
pillFace,
|
|
3770
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-reveal", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-reveal-inner", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
4096
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-reveal", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-island-reveal-inner", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4097
|
+
"div",
|
|
4098
|
+
{
|
|
4099
|
+
className: "sg-island-body",
|
|
4100
|
+
id: panelId,
|
|
4101
|
+
ref: regionRef,
|
|
4102
|
+
role: "region",
|
|
4103
|
+
"aria-label": isPay ? "ZeroDelta Link checkout" : `ZeroDelta Link ${verb.present.toLowerCase()}`,
|
|
4104
|
+
tabIndex: -1,
|
|
4105
|
+
children: expanded ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4106
|
+
WidgetShell,
|
|
4107
|
+
{
|
|
4108
|
+
variant: "express",
|
|
4109
|
+
title: "ZeroDelta Link",
|
|
4110
|
+
theme: config.theme,
|
|
4111
|
+
heightPx: props.heightPx,
|
|
4112
|
+
brandSlot,
|
|
4113
|
+
walletSlot,
|
|
4114
|
+
children: [
|
|
4115
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sg-sr-only", role: "status", "aria-live": "polite", children: liveMsg }),
|
|
4116
|
+
body
|
|
4117
|
+
]
|
|
4118
|
+
}
|
|
4119
|
+
) : null
|
|
4120
|
+
}
|
|
4121
|
+
) }) })
|
|
3774
4122
|
] }) });
|
|
3775
4123
|
}
|
|
3776
4124
|
var STABLES2 = /* @__PURE__ */ new Set(["USDC", "USDT", "USDE"]);
|
|
4125
|
+
var DEFAULT_FUNDING_ASSETS = ["USDC", "USDT", "USDE"];
|
|
3777
4126
|
function CheckGlyph3() {
|
|
3778
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4127
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4128
|
+
"svg",
|
|
4129
|
+
{
|
|
4130
|
+
width: "20",
|
|
4131
|
+
height: "20",
|
|
4132
|
+
viewBox: "0 0 24 24",
|
|
4133
|
+
fill: "none",
|
|
4134
|
+
stroke: "currentColor",
|
|
4135
|
+
strokeWidth: "3",
|
|
4136
|
+
strokeLinecap: "round",
|
|
4137
|
+
strokeLinejoin: "round",
|
|
4138
|
+
"aria-hidden": "true",
|
|
4139
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5" })
|
|
4140
|
+
}
|
|
4141
|
+
);
|
|
3779
4142
|
}
|
|
3780
4143
|
var addrEq2 = (a, b) => String(a || "").toLowerCase() === String(b || "").toLowerCase();
|
|
3781
4144
|
function StableGeniePay(props) {
|
|
3782
4145
|
const config = useMergedConfig(props);
|
|
3783
|
-
const engine = useEngine({
|
|
4146
|
+
const engine = useEngine({
|
|
4147
|
+
apiBase: config.apiBase,
|
|
4148
|
+
apiKey: config.apiKey,
|
|
4149
|
+
trustedApiOrigin: config.trustedApiOrigin,
|
|
4150
|
+
rpcOverrides: config.rpcOverrides,
|
|
4151
|
+
onTransaction: config.onTransaction
|
|
4152
|
+
});
|
|
3784
4153
|
const wallet = useWallet(config.provider);
|
|
3785
|
-
const
|
|
4154
|
+
const planFundingAssets = props.fundingAssets?.length ? props.fundingAssets : DEFAULT_FUNDING_ASSETS;
|
|
4155
|
+
const paramsKey = `${props.recipient}|${props.toChainId}|${props.toAsset}|${props.amount}|${planFundingAssets.join(",")}`;
|
|
3786
4156
|
const flow = useFlow({
|
|
3787
4157
|
engine,
|
|
3788
4158
|
wallet,
|
|
@@ -3791,22 +4161,24 @@ function StableGeniePay(props) {
|
|
|
3791
4161
|
// network work here, or every quote / balance read fires twice and onQuote/onError double-fire.
|
|
3792
4162
|
enabled: Boolean(props.recipient && props.amount) && props.variant !== "pill",
|
|
3793
4163
|
paramsKey,
|
|
3794
|
-
loadPlan: (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
4164
|
+
loadPlan: (e, payer, chainId) => e.fetchPaymentPlan({ address: props.recipient, chainId: props.toChainId, asset: props.toAsset, amount: props.amount }, payer, {
|
|
4165
|
+
chainId,
|
|
4166
|
+
fundingAssets: planFundingAssets
|
|
4167
|
+
}),
|
|
3795
4168
|
recipientFor: () => props.recipient,
|
|
3796
4169
|
onQuote: config.onQuote,
|
|
3797
4170
|
onSuccess: config.onSuccess,
|
|
3798
4171
|
onError: config.onError
|
|
3799
4172
|
});
|
|
3800
4173
|
const [method, setMethod] = react.useState("stablecoin");
|
|
3801
|
-
const fundingSet = react.useMemo(
|
|
3802
|
-
() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null,
|
|
3803
|
-
[props.fundingAssets]
|
|
3804
|
-
);
|
|
4174
|
+
const fundingSet = react.useMemo(() => props.fundingAssets?.length ? new Set(props.fundingAssets.map((a) => a.toUpperCase())) : null, [props.fundingAssets]);
|
|
3805
4175
|
const visibleRoutes = react.useMemo(() => {
|
|
3806
4176
|
const base = fundingSet ? flow.routes.filter((r) => fundingSet.has(r.source.asset.toUpperCase()) || r.state === "DIRECT") : flow.routes;
|
|
3807
|
-
return method === "stablecoin" ? base.filter((r) => STABLES2.has(r.source.asset)) : base;
|
|
4177
|
+
return method === "stablecoin" ? base.filter((r) => STABLES2.has(symbolKey(r.source.asset))) : base;
|
|
3808
4178
|
}, [flow.routes, method, fundingSet]);
|
|
3809
|
-
const
|
|
4179
|
+
const paymentPlan = flow.plan;
|
|
4180
|
+
const prefetchedBalances = paymentPlan && paymentPlan.fundingAccount === wallet.account?.toLowerCase() ? paymentPlan.fundingBalances : void 0;
|
|
4181
|
+
const holdings = useHoldings(engine, wallet.account, flow.routes, prefetchedBalances);
|
|
3810
4182
|
const annotated = react.useMemo(
|
|
3811
4183
|
() => visibleRoutes.map((r) => {
|
|
3812
4184
|
const balance = holdings.balances[balanceKey(r.source.chainId, r.source.tokenAddress)];
|
|
@@ -3880,7 +4252,15 @@ function StableGeniePay(props) {
|
|
|
3880
4252
|
if (seen.has(key)) continue;
|
|
3881
4253
|
seen.add(key);
|
|
3882
4254
|
const reg = registryTokens.find((t) => Number(t.chainId) === r.source.chainId && addrEq2(t.address, r.source.tokenAddress));
|
|
3883
|
-
list.push(
|
|
4255
|
+
list.push(
|
|
4256
|
+
reg ?? {
|
|
4257
|
+
symbol: r.source.asset,
|
|
4258
|
+
name: r.source.asset,
|
|
4259
|
+
chainId: r.source.chainId,
|
|
4260
|
+
address: r.source.tokenAddress ?? "",
|
|
4261
|
+
decimals: r.source.decimals ?? 18
|
|
4262
|
+
}
|
|
4263
|
+
);
|
|
3884
4264
|
}
|
|
3885
4265
|
return list;
|
|
3886
4266
|
}, [visibleRoutes, registryTokens]);
|
|
@@ -3962,7 +4342,18 @@ function StableGeniePay(props) {
|
|
|
3962
4342
|
] })
|
|
3963
4343
|
] }) : void 0;
|
|
3964
4344
|
if (props.variant === "pill") return /* @__PURE__ */ jsxRuntime.jsx(PaymentIsland, { kind: "pay", ...props });
|
|
3965
|
-
return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, children: hist && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4345
|
+
return /* @__PURE__ */ jsxRuntime.jsx(WidgetShell, { title: config.title || "Complete payment", theme: config.theme, heightPx: props.heightPx, walletSlot, children: hist && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(TxHistoryPanel, { account: wallet.account, tokens: registryTokens, initialEntry: hist.entry ?? null, onBack: closeHistory }) : view === "select" && wallet.account ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4346
|
+
TokenSelect,
|
|
4347
|
+
{
|
|
4348
|
+
title: "Pay with",
|
|
4349
|
+
chains: fundingChains,
|
|
4350
|
+
tokens: fundingTokens,
|
|
4351
|
+
balances: holdings.balances,
|
|
4352
|
+
optionStates,
|
|
4353
|
+
onBack: closeSelector,
|
|
4354
|
+
onPick: pickFunding
|
|
4355
|
+
}
|
|
4356
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: !wallet.account ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sg-cta-wrap", children: [
|
|
3966
4357
|
/* @__PURE__ */ jsxRuntime.jsx(Button, { onClick: wallet.connect, busy: wallet.connecting, children: "Connect wallet" }),
|
|
3967
4358
|
wallet.error ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { tone: "error", children: wallet.error }) : null
|
|
3968
4359
|
] }) : flow.status === "success" || flow.status === "pending" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
@@ -4020,7 +4411,15 @@ function StableGeniePay(props) {
|
|
|
4020
4411
|
flow.status === "ready" && !visibleRoutes.length ? /* @__PURE__ */ jsxRuntime.jsx(StatusPanel, { children: "No funding route matches the accepted assets for this payment." }) : null
|
|
4021
4412
|
] }),
|
|
4022
4413
|
submitting ? /* @__PURE__ */ jsxRuntime.jsx(StepList, { steps: flow.steps }) : null,
|
|
4023
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4414
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "sg-cta-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4415
|
+
Button,
|
|
4416
|
+
{
|
|
4417
|
+
onClick: parked || !selectedVisible ? void 0 : flow.submit,
|
|
4418
|
+
busy: submitting,
|
|
4419
|
+
disabled: parked || !selectedVisible || flow.insufficient || !!flow.nativeShortfall || flow.status === "loading",
|
|
4420
|
+
children: payLabel
|
|
4421
|
+
}
|
|
4422
|
+
) })
|
|
4024
4423
|
] }) }) });
|
|
4025
4424
|
}
|
|
4026
4425
|
var chainOptions = SUPPORTED_CHAINS.map((c) => ({ value: c, label: CHAIN_LABELS[c] || `Chain ${c}` }));
|