@anywalletkit/protocol-swap2-stargate 0.0.0-stage → 0.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/LICENSE +202 -0
- package/README.md +502 -2
- package/dist/abi.cjs +91 -0
- package/dist/abi.cjs.map +1 -0
- package/dist/abi.d.cts +810 -0
- package/dist/abi.d.ts +810 -0
- package/dist/abi.js +13 -0
- package/dist/abi.js.map +1 -0
- package/dist/amounts.cjs +73 -0
- package/dist/amounts.cjs.map +1 -0
- package/dist/amounts.d.cts +21 -0
- package/dist/amounts.d.ts +21 -0
- package/dist/amounts.js +15 -0
- package/dist/amounts.js.map +1 -0
- package/dist/bus-Cdw8iwOv.d.cts +59 -0
- package/dist/bus-vAWqTAkq.d.ts +59 -0
- package/dist/bus.cjs +237 -0
- package/dist/bus.cjs.map +1 -0
- package/dist/bus.d.cts +4 -0
- package/dist/bus.d.ts +4 -0
- package/dist/bus.js +22 -0
- package/dist/bus.js.map +1 -0
- package/dist/chunk-3NTMZUAU.js +128 -0
- package/dist/chunk-3NTMZUAU.js.map +1 -0
- package/dist/chunk-4HU46QF2.js +256 -0
- package/dist/chunk-4HU46QF2.js.map +1 -0
- package/dist/chunk-4IDDRIE2.js +125 -0
- package/dist/chunk-4IDDRIE2.js.map +1 -0
- package/dist/chunk-EANM3EI3.js +71 -0
- package/dist/chunk-EANM3EI3.js.map +1 -0
- package/dist/chunk-ERC6LKMN.js +87 -0
- package/dist/chunk-ERC6LKMN.js.map +1 -0
- package/dist/chunk-FLAXDJPE.js +24 -0
- package/dist/chunk-FLAXDJPE.js.map +1 -0
- package/dist/chunk-N54YIG6T.js +33 -0
- package/dist/chunk-N54YIG6T.js.map +1 -0
- package/dist/chunk-OUGUX3JK.js +53 -0
- package/dist/chunk-OUGUX3JK.js.map +1 -0
- package/dist/chunk-PJXDMVW3.js +909 -0
- package/dist/chunk-PJXDMVW3.js.map +1 -0
- package/dist/chunk-QNVTQEOV.js +72 -0
- package/dist/chunk-QNVTQEOV.js.map +1 -0
- package/dist/chunk-UDJL7BUP.js +249 -0
- package/dist/chunk-UDJL7BUP.js.map +1 -0
- package/dist/chunk-YHHV3XHY.js +139 -0
- package/dist/chunk-YHHV3XHY.js.map +1 -0
- package/dist/compose-dex.cjs +148 -0
- package/dist/compose-dex.cjs.map +1 -0
- package/dist/compose-dex.d.cts +113 -0
- package/dist/compose-dex.d.ts +113 -0
- package/dist/compose-dex.js +25 -0
- package/dist/compose-dex.js.map +1 -0
- package/dist/compose-route.cjs +1019 -0
- package/dist/compose-route.cjs.map +1 -0
- package/dist/compose-route.d.cts +93 -0
- package/dist/compose-route.d.ts +93 -0
- package/dist/compose-route.js +45 -0
- package/dist/compose-route.js.map +1 -0
- package/dist/compose.cjs +287 -0
- package/dist/compose.cjs.map +1 -0
- package/dist/compose.d.cts +293 -0
- package/dist/compose.d.ts +293 -0
- package/dist/compose.js +30 -0
- package/dist/compose.js.map +1 -0
- package/dist/deployments.cjs +350 -0
- package/dist/deployments.cjs.map +1 -0
- package/dist/deployments.d.cts +12 -0
- package/dist/deployments.d.ts +12 -0
- package/dist/deployments.js +11 -0
- package/dist/deployments.js.map +1 -0
- package/dist/index.cjs +1862 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/native-drop.cjs +117 -0
- package/dist/native-drop.cjs.map +1 -0
- package/dist/native-drop.d.cts +13 -0
- package/dist/native-drop.d.ts +13 -0
- package/dist/native-drop.js +11 -0
- package/dist/native-drop.js.map +1 -0
- package/dist/pins.cjs +1618 -0
- package/dist/pins.cjs.map +1 -0
- package/dist/pins.d.cts +39 -0
- package/dist/pins.d.ts +39 -0
- package/dist/pins.js +21 -0
- package/dist/pins.js.map +1 -0
- package/dist/protocol.cjs +1851 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +24 -0
- package/dist/protocol.d.ts +24 -0
- package/dist/protocol.js +18 -0
- package/dist/protocol.js.map +1 -0
- package/dist/provider.cjs +1833 -0
- package/dist/provider.cjs.map +1 -0
- package/dist/provider.d.cts +30 -0
- package/dist/provider.d.ts +30 -0
- package/dist/provider.js +17 -0
- package/dist/provider.js.map +1 -0
- package/dist/quote-r1bA8XbO.d.cts +102 -0
- package/dist/quote-t7UJSxbU.d.ts +102 -0
- package/dist/quote.cjs +618 -0
- package/dist/quote.cjs.map +1 -0
- package/dist/quote.d.cts +3 -0
- package/dist/quote.d.ts +3 -0
- package/dist/quote.js +16 -0
- package/dist/quote.js.map +1 -0
- package/dist/registry.cjs +100 -0
- package/dist/registry.cjs.map +1 -0
- package/dist/registry.d.cts +42 -0
- package/dist/registry.d.ts +42 -0
- package/dist/registry.js +8 -0
- package/dist/registry.js.map +1 -0
- package/dist/tracking.cjs +1143 -0
- package/dist/tracking.cjs.map +1 -0
- package/dist/tracking.d.cts +57 -0
- package/dist/tracking.d.ts +57 -0
- package/dist/tracking.js +23 -0
- package/dist/tracking.js.map +1 -0
- package/package.json +134 -3
|
@@ -0,0 +1,1019 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/compose-route.ts
|
|
21
|
+
var compose_route_exports = {};
|
|
22
|
+
__export(compose_route_exports, {
|
|
23
|
+
COMPOSE_INTERMEDIATES: () => COMPOSE_INTERMEDIATES,
|
|
24
|
+
COMPOSE_SWAP_GAS: () => COMPOSE_SWAP_GAS,
|
|
25
|
+
STARGATE_COMPOSE_CHAIN: () => STARGATE_COMPOSE_CHAIN,
|
|
26
|
+
UNISWAP_V3_QUOTER_V2: () => UNISWAP_V3_QUOTER_V2,
|
|
27
|
+
checkStargateComposer: () => checkStargateComposer,
|
|
28
|
+
checkedStargateComposeQuote: () => checkedStargateComposeQuote,
|
|
29
|
+
createStargateComposer: () => createStargateComposer,
|
|
30
|
+
isStargateComposeIntent: () => isStargateComposeIntent,
|
|
31
|
+
parseStargateComposeIntent: () => parseStargateComposeIntent,
|
|
32
|
+
quoteStargateComposeSwap: () => quoteStargateComposeSwap,
|
|
33
|
+
stargateComposeIntentId: () => stargateComposeIntentId,
|
|
34
|
+
stargateComposeMessage: () => stargateComposeMessage,
|
|
35
|
+
stargateComposeProof: () => stargateComposeProof,
|
|
36
|
+
stargateComposeRetryGas: () => stargateComposeRetryGas,
|
|
37
|
+
stargateComposeSendParam: () => stargateComposeSendParam,
|
|
38
|
+
stargateComposeSwapCall: () => stargateComposeSwapCall
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(compose_route_exports);
|
|
41
|
+
var import_viem8 = require("viem");
|
|
42
|
+
|
|
43
|
+
// src/abi.ts
|
|
44
|
+
var import_viem = require("viem");
|
|
45
|
+
var EXECUTOR_ABI = (0, import_viem.parseAbi)([
|
|
46
|
+
"struct Origin { uint32 srcEid; bytes32 sender; uint64 nonce; }",
|
|
47
|
+
"struct NativeDropParams { address receiver; uint256 amount; }",
|
|
48
|
+
"function endpoint() view returns (address)",
|
|
49
|
+
"function localEid() view returns (uint32)",
|
|
50
|
+
"event NativeDropApplied(Origin origin, uint32 dstEid, address oapp, NativeDropParams[] params, bool[] success)"
|
|
51
|
+
]);
|
|
52
|
+
var ENDPOINT_ABI = (0, import_viem.parseAbi)([
|
|
53
|
+
"struct Origin { uint32 srcEid; bytes32 sender; uint64 nonce; }",
|
|
54
|
+
"function inboundPayloadHash(address receiver, uint32 srcEid, bytes32 sender, uint64 nonce) view returns (bytes32)",
|
|
55
|
+
"function lzReceive(Origin origin, address receiver, bytes32 guid, bytes message, bytes extraData) payable",
|
|
56
|
+
"event PacketSent(bytes encodedPayload, bytes options, address sendLibrary)",
|
|
57
|
+
"event PacketDelivered(Origin origin, address receiver)"
|
|
58
|
+
]);
|
|
59
|
+
var STARGATE_ABI = (0, import_viem.parseAbi)([
|
|
60
|
+
"struct SendParam { uint32 dstEid; bytes32 to; uint256 amountLD; uint256 minAmountLD; bytes extraOptions; bytes composeMsg; bytes oftCmd; }",
|
|
61
|
+
"struct MessagingFee { uint256 nativeFee; uint256 lzTokenFee; }",
|
|
62
|
+
"struct MessagingReceipt { bytes32 guid; uint64 nonce; MessagingFee fee; }",
|
|
63
|
+
"struct OFTLimit { uint256 minAmountLD; uint256 maxAmountLD; }",
|
|
64
|
+
"struct OFTFeeDetail { int256 feeAmountLD; string description; }",
|
|
65
|
+
"struct OFTReceipt { uint256 amountSentLD; uint256 amountReceivedLD; }",
|
|
66
|
+
"struct Ticket { uint72 ticketId; bytes passengerBytes; }",
|
|
67
|
+
"struct AddressConfig { address feeLib; address planner; address treasurer; address tokenMessaging; address creditMessaging; address lzToken; }",
|
|
68
|
+
"function token() view returns (address)",
|
|
69
|
+
"function sharedDecimals() view returns (uint8)",
|
|
70
|
+
"function approvalRequired() pure returns (bool)",
|
|
71
|
+
"function localEid() view returns (uint32)",
|
|
72
|
+
"function endpoint() view returns (address)",
|
|
73
|
+
"function status() view returns (uint8)",
|
|
74
|
+
"function stargateType() pure returns (uint8)",
|
|
75
|
+
"function paths(uint32 eid) view returns (uint64 credit)",
|
|
76
|
+
"function getAddressConfig() view returns (AddressConfig)",
|
|
77
|
+
"function quoteOFT(SendParam s) view returns (OFTLimit limit, OFTFeeDetail[] oftFeeDetails, OFTReceipt receipt)",
|
|
78
|
+
"function quoteSend(SendParam s, bool payInLzToken) view returns (MessagingFee fee)",
|
|
79
|
+
"function send(SendParam s, MessagingFee fee, address refundAddress) payable returns (MessagingReceipt msgReceipt, OFTReceipt oftReceipt)",
|
|
80
|
+
"function sendToken(SendParam s, MessagingFee fee, address refundAddress) payable returns (MessagingReceipt msgReceipt, OFTReceipt oftReceipt, Ticket ticket)",
|
|
81
|
+
"function unreceivedTokens(bytes32 guid, uint8 index) view returns (bytes32)",
|
|
82
|
+
"function retryReceiveToken(bytes32 guid, uint8 index, uint32 srcEid, address receiver, uint256 amountLD, bytes composeMsg)",
|
|
83
|
+
"event OFTSent(bytes32 indexed guid, uint32 dstEid, address indexed fromAddress, uint256 amountSentLD, uint256 amountReceivedLD)",
|
|
84
|
+
"event OFTReceived(bytes32 indexed guid, uint32 srcEid, address indexed toAddress, uint256 amountReceivedLD)",
|
|
85
|
+
"event UnreceivedTokenCached(bytes32 guid, uint8 index, uint32 srcEid, address receiver, uint256 amountLD, bytes composeMsg)"
|
|
86
|
+
]);
|
|
87
|
+
var TOKEN_MESSAGING_ABI = (0, import_viem.parseAbi)([
|
|
88
|
+
"error Bus_InvalidFare(bool nativeDrop)",
|
|
89
|
+
"struct MessagingFee { uint256 nativeFee; uint256 lzTokenFee; }",
|
|
90
|
+
"struct MessagingReceipt { bytes32 guid; uint64 nonce; MessagingFee fee; }",
|
|
91
|
+
"function assetIds(address stargateImpl) view returns (uint16)",
|
|
92
|
+
"function stargateImpls(uint16 assetId) view returns (address)",
|
|
93
|
+
"function peers(uint32 eid) view returns (bytes32)",
|
|
94
|
+
"function endpoint() view returns (address)",
|
|
95
|
+
"function nativeDropAmounts(uint32 eid) view returns (uint128)",
|
|
96
|
+
"function queueCapacity() view returns (uint16)",
|
|
97
|
+
"function busQueues(uint32 eid) view returns (uint8 maxNumPassengers, uint80 busFare, uint80 busAndNativeDropFare, uint16 qLength, uint72 nextTicketId)",
|
|
98
|
+
"function getPassengerHash(uint32 eid, uint16 index) view returns (bytes32)",
|
|
99
|
+
"function quoteDriveBus(uint32 dstEid, bytes passengers) view returns (MessagingFee fee)",
|
|
100
|
+
"function driveBus(uint32 dstEid, bytes passengers) payable returns (MessagingReceipt receipt)",
|
|
101
|
+
"event BusRode(uint32 dstEid, uint72 ticketId, uint80 fare, bytes passenger)",
|
|
102
|
+
"event BusDriven(uint32 dstEid, uint72 startTicketId, uint8 numPassengers, bytes32 guid)",
|
|
103
|
+
"event NativeDropApplied(address receiver, uint128 amount)",
|
|
104
|
+
"event NativeDropFailed(address receiver, uint128 amount)"
|
|
105
|
+
]);
|
|
106
|
+
|
|
107
|
+
// src/amounts.ts
|
|
108
|
+
var UINT64_MAX = (1n << 64n) - 1n;
|
|
109
|
+
var UINT256_MAX = (1n << 256n) - 1n;
|
|
110
|
+
function uint256(amount) {
|
|
111
|
+
if (typeof amount !== "bigint" || amount < 0n || amount > UINT256_MAX) throw new RangeError("stargate: amount must be uint256 bigint");
|
|
112
|
+
}
|
|
113
|
+
function conversionRate(localDecimals, sharedDecimals) {
|
|
114
|
+
if (!Number.isInteger(localDecimals) || !Number.isInteger(sharedDecimals) || sharedDecimals < 0 || localDecimals < sharedDecimals || localDecimals > 255 || localDecimals - sharedDecimals > 77) {
|
|
115
|
+
throw new RangeError("stargate: invalid local/shared decimals");
|
|
116
|
+
}
|
|
117
|
+
return 10n ** BigInt(localDecimals - sharedDecimals);
|
|
118
|
+
}
|
|
119
|
+
function splitSourceAmount(amountLD, localDecimals, sharedDecimals) {
|
|
120
|
+
uint256(amountLD);
|
|
121
|
+
const rate = conversionRate(localDecimals, sharedDecimals);
|
|
122
|
+
const amountSD = amountLD / rate;
|
|
123
|
+
if (amountSD > UINT64_MAX) throw new RangeError("stargate: shared amount exceeds uint64");
|
|
124
|
+
return { amountSD, sentLD: amountSD * rate, dustLD: amountLD % rate };
|
|
125
|
+
}
|
|
126
|
+
function destinationAmount(receivedSourceLD, sourceDecimals, destinationDecimals, sharedDecimals) {
|
|
127
|
+
const { amountSD, dustLD } = splitSourceAmount(receivedSourceLD, sourceDecimals, sharedDecimals);
|
|
128
|
+
if (dustLD !== 0n) throw new RangeError("stargate: quote receipt is not shared-decimal aligned");
|
|
129
|
+
const amount = amountSD * conversionRate(destinationDecimals, sharedDecimals);
|
|
130
|
+
uint256(amount);
|
|
131
|
+
return amount;
|
|
132
|
+
}
|
|
133
|
+
function sourceMinimum(minDestinationLD, sourceDecimals, destinationDecimals, sharedDecimals) {
|
|
134
|
+
uint256(minDestinationLD);
|
|
135
|
+
const destinationRate = conversionRate(destinationDecimals, sharedDecimals);
|
|
136
|
+
const minimumSD = (minDestinationLD + destinationRate - 1n) / destinationRate;
|
|
137
|
+
if (minimumSD > UINT64_MAX) throw new RangeError("stargate: minimum exceeds uint64 shared amount");
|
|
138
|
+
const minimumLD = minimumSD * conversionRate(sourceDecimals, sharedDecimals);
|
|
139
|
+
uint256(minimumLD);
|
|
140
|
+
return minimumLD;
|
|
141
|
+
}
|
|
142
|
+
function splitFeeDetails(details) {
|
|
143
|
+
let feeLD = 0n, rewardLD = 0n;
|
|
144
|
+
for (const { feeAmountLD } of details) {
|
|
145
|
+
if (typeof feeAmountLD !== "bigint" || feeAmountLD < -(1n << 255n) || feeAmountLD >= 1n << 255n) throw new RangeError("stargate: fee must be int256 bigint");
|
|
146
|
+
if (feeAmountLD < 0n) feeLD -= feeAmountLD;
|
|
147
|
+
else rewardLD += feeAmountLD;
|
|
148
|
+
}
|
|
149
|
+
return { feeLD, rewardLD };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/availability.ts
|
|
153
|
+
var STARGATE_BUS_RETIRED = "Stargate Bus is retired for new transfers; use Taxi";
|
|
154
|
+
function stargateChainCutoff(chain) {
|
|
155
|
+
return chain === "eip155:534352" ? Date.UTC(2026, 11, 8) : Infinity;
|
|
156
|
+
}
|
|
157
|
+
function stargateChainActive(chain, now = Date.now()) {
|
|
158
|
+
return now < stargateChainCutoff(chain);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/compose.ts
|
|
162
|
+
var import_viem5 = require("viem");
|
|
163
|
+
|
|
164
|
+
// src/rpc.ts
|
|
165
|
+
var import_viem2 = require("viem");
|
|
166
|
+
var StargateReadError = class extends Error {
|
|
167
|
+
constructor(message) {
|
|
168
|
+
super(`stargate: ${message}`);
|
|
169
|
+
this.name = "StargateReadError";
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
var auxiliaryAbi = (0, import_viem2.parseAbi)(["function decimals() view returns (uint8)", "function eid() view returns (uint32)"]);
|
|
173
|
+
var sameAddress = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
174
|
+
function assertStargate(condition, message) {
|
|
175
|
+
if (!condition) throw new StargateReadError(message);
|
|
176
|
+
}
|
|
177
|
+
function assertNotAborted(signal) {
|
|
178
|
+
if (signal?.aborted) throw new StargateReadError("request cancelled");
|
|
179
|
+
}
|
|
180
|
+
function stargateRpc(config) {
|
|
181
|
+
const urls = new Map(Object.entries(config.rpcUrls).map(([chain, value]) => {
|
|
182
|
+
const list = typeof value === "string" ? [value] : [...value];
|
|
183
|
+
assertStargate(list.length && list.every((url) => /^https?:\/\//.test(url)), "invalid RPC configuration");
|
|
184
|
+
return [chain, list];
|
|
185
|
+
}));
|
|
186
|
+
function client(chain, signal) {
|
|
187
|
+
const list = urls.get(chain);
|
|
188
|
+
assertStargate(list, `no RPC configured for ${chain}`);
|
|
189
|
+
assertNotAborted(signal);
|
|
190
|
+
const transport = (url) => (0, import_viem2.http)(url, { timeout: 12e3, retryCount: 0, ...config.fetchImpl ? { fetchFn: config.fetchImpl } : {}, ...signal ? { fetchOptions: { signal } } : {} });
|
|
191
|
+
return (0, import_viem2.createPublicClient)({ transport: list.length === 1 ? transport(list[0]) : (0, import_viem2.fallback)(list.map(transport), { retryCount: 0 }), ccipRead: false });
|
|
192
|
+
}
|
|
193
|
+
async function snapshot(c, chainId) {
|
|
194
|
+
const [actual, block] = await Promise.all([c.getChainId(), c.getBlock({ blockTag: "latest" })]);
|
|
195
|
+
assertStargate(actual === chainId, "RPC chain id mismatch");
|
|
196
|
+
assertStargate(block.hash && block.number !== null, "RPC returned an unmined block");
|
|
197
|
+
const now = BigInt(Math.floor(Date.now() / 1e3));
|
|
198
|
+
assertStargate(block.timestamp >= now - 300n && block.timestamp <= now + 60n, "RPC block is stale or in the future");
|
|
199
|
+
return Object.freeze({ number: block.number, hash: block.hash, timestamp: block.timestamp });
|
|
200
|
+
}
|
|
201
|
+
async function verify(c, d, peer, block) {
|
|
202
|
+
const at = { blockNumber: block.number };
|
|
203
|
+
const pool = { address: d.address, abi: STARGATE_ABI, ...at };
|
|
204
|
+
const messaging = { address: d.tokenMessaging, abi: TOKEN_MESSAGING_ABI, ...at };
|
|
205
|
+
const [token, shared, approval, eid, endpoint, status, kind, roles, assetId, implementation, messagingEndpoint, remotePeer, endpointEid, decimals] = await Promise.all([
|
|
206
|
+
c.readContract({ ...pool, functionName: "token" }),
|
|
207
|
+
c.readContract({ ...pool, functionName: "sharedDecimals" }),
|
|
208
|
+
c.readContract({ ...pool, functionName: "approvalRequired" }),
|
|
209
|
+
c.readContract({ ...pool, functionName: "localEid" }),
|
|
210
|
+
c.readContract({ ...pool, functionName: "endpoint" }),
|
|
211
|
+
c.readContract({ ...pool, functionName: "status" }),
|
|
212
|
+
c.readContract({ ...pool, functionName: "stargateType" }),
|
|
213
|
+
c.readContract({ ...pool, functionName: "getAddressConfig" }),
|
|
214
|
+
c.readContract({ ...messaging, functionName: "assetIds", args: [d.address] }),
|
|
215
|
+
c.readContract({ ...messaging, functionName: "stargateImpls", args: [d.assetId] }),
|
|
216
|
+
c.readContract({ ...messaging, functionName: "endpoint" }),
|
|
217
|
+
c.readContract({ ...messaging, functionName: "peers", args: [peer.eid] }),
|
|
218
|
+
c.readContract({ address: d.endpoint, abi: auxiliaryAbi, functionName: "eid", ...at }),
|
|
219
|
+
d.kind === "native" ? Promise.resolve(d.localDecimals) : c.readContract({ address: d.token, abi: auxiliaryAbi, functionName: "decimals", ...at })
|
|
220
|
+
]);
|
|
221
|
+
assertStargate(sameAddress(token, d.token) && shared === d.sharedDecimals && decimals === d.localDecimals && approval === d.approvalRequired && eid === d.eid && endpointEid === d.eid && sameAddress(endpoint, d.endpoint) && sameAddress(messagingEndpoint, d.endpoint) && sameAddress(roles.tokenMessaging, d.tokenMessaging) && assetId === d.assetId && sameAddress(implementation, d.address) && kind === (d.kind === "oft" ? 1 : 0), `deployment identity changed on ${d.chain}`);
|
|
222
|
+
assertStargate(status === 1, `deployment is not active on ${d.chain}`);
|
|
223
|
+
assertStargate(sameAddress(remotePeer, (0, import_viem2.pad)(peer.tokenMessaging, { size: 32 })), `messaging peer mismatch on ${d.chain}`);
|
|
224
|
+
}
|
|
225
|
+
async function unchanged(c, block) {
|
|
226
|
+
assertStargate((await c.getBlock({ blockNumber: block.number })).hash === block.hash, "block changed during quote");
|
|
227
|
+
}
|
|
228
|
+
return { has: (chain) => urls.has(chain), client, snapshot, verify, unchanged };
|
|
229
|
+
}
|
|
230
|
+
function safeReadError(error) {
|
|
231
|
+
return error instanceof StargateReadError ? error : new StargateReadError("RPC read, quote or decoding failed");
|
|
232
|
+
}
|
|
233
|
+
function nonzeroAddress(value) {
|
|
234
|
+
return /^0x[0-9a-fA-F]{40}$/.test(value) && !/^0x0{40}$/.test(value);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/registry.ts
|
|
238
|
+
var import_viem3 = require("viem");
|
|
239
|
+
function boundedInteger(value, max, name) {
|
|
240
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > max) throw new Error(`stargate registry: invalid ${name}`);
|
|
241
|
+
}
|
|
242
|
+
function address(value, nonzero) {
|
|
243
|
+
if (!(0, import_viem3.isAddress)(value) || nonzero && value.toLowerCase() === import_viem3.zeroAddress) throw new Error("stargate registry: invalid address");
|
|
244
|
+
return (0, import_viem3.getAddress)(value);
|
|
245
|
+
}
|
|
246
|
+
function createStargateRegistry(input, inputPaths) {
|
|
247
|
+
const ids = /* @__PURE__ */ new Map();
|
|
248
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
249
|
+
const contracts = /* @__PURE__ */ new Set();
|
|
250
|
+
const chains = /* @__PURE__ */ new Map();
|
|
251
|
+
const eids = /* @__PURE__ */ new Map();
|
|
252
|
+
const shared = /* @__PURE__ */ new Map();
|
|
253
|
+
const deployments2 = Object.freeze(input.map((raw) => {
|
|
254
|
+
boundedInteger(raw.chainId, Number.MAX_SAFE_INTEGER, "chainId");
|
|
255
|
+
boundedInteger(raw.eid, 4294967295, "eid");
|
|
256
|
+
boundedInteger(raw.assetId, 65535, "assetId");
|
|
257
|
+
if (raw.chain !== `eip155:${raw.chainId}`) throw new Error("stargate registry: chainId mismatch");
|
|
258
|
+
conversionRate(raw.localDecimals, raw.sharedDecimals);
|
|
259
|
+
if (!["pool", "oft", "native"].includes(raw.kind) || typeof raw.approvalRequired !== "boolean" || typeof raw.symbol !== "string" || !raw.symbol.trim()) throw new Error("stargate registry: malformed deployment");
|
|
260
|
+
const d = Object.freeze({ ...raw, token: address(raw.token, false), address: address(raw.address, true), tokenMessaging: address(raw.tokenMessaging, true), endpoint: address(raw.endpoint, true) });
|
|
261
|
+
if (d.kind === "native" !== (d.token === import_viem3.zeroAddress)) throw new Error("stargate registry: native token mismatch");
|
|
262
|
+
const identity = `${d.chain}:${d.assetId}`;
|
|
263
|
+
const tokenKey = `${d.chain}:${d.token.toLowerCase()}`;
|
|
264
|
+
const contractKey = `${d.chain}:${d.address.toLowerCase()}`;
|
|
265
|
+
if (ids.has(identity) || tokens.has(tokenKey) || contracts.has(contractKey)) throw new Error("stargate registry: duplicate deployment");
|
|
266
|
+
const chain = chains.get(d.chain);
|
|
267
|
+
if (chain && (chain.eid !== d.eid || chain.tokenMessaging !== d.tokenMessaging || chain.endpoint !== d.endpoint)) throw new Error("stargate registry: inconsistent chain messaging");
|
|
268
|
+
if (eids.has(d.eid) && eids.get(d.eid) !== d.chain) throw new Error("stargate registry: eid names multiple chains");
|
|
269
|
+
if (shared.has(d.assetId) && shared.get(d.assetId) !== d.sharedDecimals) throw new Error("stargate registry: incompatible shared decimals");
|
|
270
|
+
ids.set(identity, d);
|
|
271
|
+
tokens.set(tokenKey, d);
|
|
272
|
+
contracts.add(contractKey);
|
|
273
|
+
chains.set(d.chain, d);
|
|
274
|
+
eids.set(d.eid, d.chain);
|
|
275
|
+
shared.set(d.assetId, d.sharedDecimals);
|
|
276
|
+
return d;
|
|
277
|
+
}));
|
|
278
|
+
const pathKeys = /* @__PURE__ */ new Set();
|
|
279
|
+
const paths2 = Object.freeze(inputPaths.map((path) => {
|
|
280
|
+
if (path.source === path.destination || !chains.has(path.source) || !chains.has(path.destination)) throw new Error("stargate registry: invalid path");
|
|
281
|
+
const key = `${path.source}>${path.destination}`;
|
|
282
|
+
if (pathKeys.has(key)) throw new Error("stargate registry: duplicate path");
|
|
283
|
+
pathKeys.add(key);
|
|
284
|
+
return Object.freeze({ source: path.source, destination: path.destination });
|
|
285
|
+
}));
|
|
286
|
+
const lookup = (chain, token) => chains.has(chain) && (0, import_viem3.isAddress)(token, { strict: false }) ? tokens.get(`${chain}:${token.toLowerCase()}`) : void 0;
|
|
287
|
+
return Object.freeze({
|
|
288
|
+
deployments: deployments2,
|
|
289
|
+
paths: paths2,
|
|
290
|
+
find: lookup,
|
|
291
|
+
route(sourceChain, sourceToken, destinationChain, destinationToken) {
|
|
292
|
+
if (!pathKeys.has(`${sourceChain}>${destinationChain}`)) return void 0;
|
|
293
|
+
const source = lookup(sourceChain, sourceToken), destination = lookup(destinationChain, destinationToken);
|
|
294
|
+
return source && destination && source.assetId === destination.assetId ? { source, destination } : void 0;
|
|
295
|
+
},
|
|
296
|
+
callTargets: (chain) => Object.freeze(deployments2.filter((d) => d.chain === chain).map((d) => d.address)),
|
|
297
|
+
spenders: (chain) => Object.freeze(deployments2.filter((d) => d.chain === chain && d.kind !== "native" && d.approvalRequired).map((d) => d.address))
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// src/deployments.ts
|
|
302
|
+
var STARGATE_REGISTRY_EVIDENCE = Object.freeze({
|
|
303
|
+
"upstreamCommit": "414f47412123d7737520c6ba331c1376ec874a88",
|
|
304
|
+
"capturedAt": "2026-11-16T14:40:36.782Z",
|
|
305
|
+
"sha256": "ab4fba3cc845a3dcb8a804bffc6a53d7f7982bf974b45cec686095eefb70426f"
|
|
306
|
+
});
|
|
307
|
+
var deployments = [
|
|
308
|
+
{ "chain": "eip155:42161", "chainId": 42161, "eid": 30110, "assetId": 1, "symbol": "USDC", "token": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", "address": "0xe8CDF27AcD73a434D661C84887215F7598e7d0d3", "tokenMessaging": "0x19cFCE47eD54a88614648DC3f19A5980097007dD", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 6, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
309
|
+
{ "chain": "eip155:42161", "chainId": 42161, "eid": 30110, "assetId": 13, "symbol": "ETH", "token": "0x0000000000000000000000000000000000000000", "address": "0xA45B5130f36CDcA45667738e2a258AB09f4A5f7F", "tokenMessaging": "0x19cFCE47eD54a88614648DC3f19A5980097007dD", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 18, "sharedDecimals": 6, "kind": "native", "approvalRequired": true },
|
|
310
|
+
{ "chain": "eip155:43114", "chainId": 43114, "eid": 30106, "assetId": 1, "symbol": "USDC", "token": "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E", "address": "0x5634c4a5FEd09819E3c46D86A965Dd9447d86e47", "tokenMessaging": "0x17E450Be3Ba9557F2378E20d64AD417E59Ef9A34", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 6, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
311
|
+
{ "chain": "eip155:43114", "chainId": 43114, "eid": 30106, "assetId": 2, "symbol": "USDt", "token": "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7", "address": "0x12dC9256Acc9895B076f6638D628382881e62CeE", "tokenMessaging": "0x17E450Be3Ba9557F2378E20d64AD417E59Ef9A34", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 6, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
312
|
+
{ "chain": "eip155:8453", "chainId": 8453, "eid": 30184, "assetId": 1, "symbol": "USDC", "token": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "address": "0x27a16dc786820B16E5c9028b75B99F6f604b5d26", "tokenMessaging": "0x5634c4a5FEd09819E3c46D86A965Dd9447d86e47", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 6, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
313
|
+
{ "chain": "eip155:8453", "chainId": 8453, "eid": 30184, "assetId": 13, "symbol": "ETH", "token": "0x0000000000000000000000000000000000000000", "address": "0xdc181Bd607330aeeBEF6ea62e03e5e1Fb4B6F7C7", "tokenMessaging": "0x5634c4a5FEd09819E3c46D86A965Dd9447d86e47", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 18, "sharedDecimals": 6, "kind": "native", "approvalRequired": true },
|
|
314
|
+
{ "chain": "eip155:56", "chainId": 56, "eid": 30102, "assetId": 1, "symbol": "USDC", "token": "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d", "address": "0x962Bd449E630b0d928f308Ce63f1A21F02576057", "tokenMessaging": "0x6E3d884C96d640526F273C61dfcF08915eBd7e2B", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 18, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
315
|
+
{ "chain": "eip155:56", "chainId": 56, "eid": 30102, "assetId": 2, "symbol": "USDT", "token": "0x55d398326f99059fF775485246999027B3197955", "address": "0x138EB30f73BC423c6455C53df6D89CB01d9eBc63", "tokenMessaging": "0x6E3d884C96d640526F273C61dfcF08915eBd7e2B", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 18, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
316
|
+
{ "chain": "eip155:1", "chainId": 1, "eid": 30101, "assetId": 1, "symbol": "USDC", "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "address": "0xc026395860Db2d07ee33e05fE50ed7bD583189C7", "tokenMessaging": "0x6d6620eFa72948C5f68A3C8646d58C00d3f4A980", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 6, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
317
|
+
{ "chain": "eip155:1", "chainId": 1, "eid": 30101, "assetId": 2, "symbol": "USDT", "token": "0xdAC17F958D2ee523a2206206994597C13D831ec7", "address": "0x933597a323Eb81cAe705C5bC29985172fd5A3973", "tokenMessaging": "0x6d6620eFa72948C5f68A3C8646d58C00d3f4A980", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 6, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
318
|
+
{ "chain": "eip155:1", "chainId": 1, "eid": 30101, "assetId": 13, "symbol": "ETH", "token": "0x0000000000000000000000000000000000000000", "address": "0x77b2043768d28E9C9aB44E1aBfC95944bcE57931", "tokenMessaging": "0x6d6620eFa72948C5f68A3C8646d58C00d3f4A980", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 18, "sharedDecimals": 6, "kind": "native", "approvalRequired": true },
|
|
319
|
+
{ "chain": "eip155:14", "chainId": 14, "eid": 30295, "assetId": 1, "symbol": "USDC.e", "token": "0xFbDa5F676cB37624f28265A144A48B0d6e87d3b6", "address": "0x77C71633C34C3784ede189d74223122422492a0f", "tokenMessaging": "0x45d417612e177672958dC0537C45a8f8d754Ac2E", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 6, "sharedDecimals": 6, "kind": "oft", "approvalRequired": true },
|
|
320
|
+
{ "chain": "eip155:14", "chainId": 14, "eid": 30295, "assetId": 13, "symbol": "WETH", "token": "0x1502FA4be69d526124D453619276FacCab275d3D", "address": "0x8e8539e4CcD69123c623a106773F2b0cbbc58746", "tokenMessaging": "0x45d417612e177672958dC0537C45a8f8d754Ac2E", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 18, "sharedDecimals": 6, "kind": "oft", "approvalRequired": true },
|
|
321
|
+
{ "chain": "eip155:5000", "chainId": 5e3, "eid": 30181, "assetId": 1, "symbol": "USDC", "token": "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9", "address": "0xAc290Ad4e0c891FDc295ca4F0a6214cf6dC6acDC", "tokenMessaging": "0x41B491285A4f888F9f636cEc8a363AB9770a0AEF", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 6, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
322
|
+
{ "chain": "eip155:5000", "chainId": 5e3, "eid": 30181, "assetId": 13, "symbol": "WETH", "token": "0xdEAddEaDdeadDEadDEADDEAddEADDEAddead1111", "address": "0x4c1d3Fc3fC3c177c3b633427c2F769276c547463", "tokenMessaging": "0x41B491285A4f888F9f636cEc8a363AB9770a0AEF", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 18, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
323
|
+
{ "chain": "eip155:5000", "chainId": 5e3, "eid": 30181, "assetId": 22, "symbol": "mETH", "token": "0xcDA86A272531e8640cD7F1a92c01839911B90bb0", "address": "0xF7628d84a2BbD9bb9c8E686AC95BB5d55169F3F1", "tokenMessaging": "0x41B491285A4f888F9f636cEc8a363AB9770a0AEF", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 18, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
324
|
+
{ "chain": "eip155:10", "chainId": 10, "eid": 30111, "assetId": 1, "symbol": "USDC", "token": "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85", "address": "0xcE8CcA271Ebc0533920C83d39F417ED6A0abB7D0", "tokenMessaging": "0xF1fCb4CBd57B67d683972A59B6a7b1e2E8Bf27E6", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 6, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
325
|
+
{ "chain": "eip155:10", "chainId": 10, "eid": 30111, "assetId": 13, "symbol": "ETH", "token": "0x0000000000000000000000000000000000000000", "address": "0xe8CDF27AcD73a434D661C84887215F7598e7d0d3", "tokenMessaging": "0xF1fCb4CBd57B67d683972A59B6a7b1e2E8Bf27E6", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 18, "sharedDecimals": 6, "kind": "native", "approvalRequired": true },
|
|
326
|
+
{ "chain": "eip155:9745", "chainId": 9745, "eid": 30383, "assetId": 13, "symbol": "WETH", "token": "0x9895D81bB462A195b4922ED7De0e3ACD007c32CB", "address": "0x0cEb237E109eE22374a567c6b09F373C73FA4cBb", "tokenMessaging": "0x102d758f688a4C1C5a80b116bD945d4455460282", "endpoint": "0x6F475642a6e85809B1c36Fa62763669b1b48DD5B", "localDecimals": 18, "sharedDecimals": 6, "kind": "oft", "approvalRequired": true },
|
|
327
|
+
{ "chain": "eip155:98866", "chainId": 98866, "eid": 30370, "assetId": 13, "symbol": "WETH", "token": "0xca59cA09E5602fAe8B629DeE83FfA819741f14be", "address": "0x4683CE822272CD66CEa73F5F1f9f5cBcaEF4F066", "tokenMessaging": "0xf26d57bbE1D99561B13003783b5e040B71AdCb14", "endpoint": "0xC1b15d3B262bEeC0e3565C11C9e0F6134BdaCB36", "localDecimals": 18, "sharedDecimals": 6, "kind": "oft", "approvalRequired": true },
|
|
328
|
+
{ "chain": "eip155:137", "chainId": 137, "eid": 30109, "assetId": 1, "symbol": "USDC", "token": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359", "address": "0x9Aa02D4Fae7F58b8E8f34c66E756cC734DAc7fe4", "tokenMessaging": "0x6CE9bf8CDaB780416AD1fd87b318A077D2f50EaC", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 6, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
329
|
+
{ "chain": "eip155:534352", "chainId": 534352, "eid": 30214, "assetId": 13, "symbol": "ETH", "token": "0x0000000000000000000000000000000000000000", "address": "0xC2b638Cb5042c1B3c5d5C969361fB50569840583", "tokenMessaging": "0x4e422B0aCb2Bd7e3aC70B5c0E5eb806e86a94038", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 18, "sharedDecimals": 6, "kind": "native", "approvalRequired": true },
|
|
330
|
+
{ "chain": "eip155:1329", "chainId": 1329, "eid": 30280, "assetId": 13, "symbol": "WETH", "token": "0x160345fC359604fC6e70E3c5fAcbdE5F7A9342d8", "address": "0x5c386D85b1B82FD9Db681b9176C8a4248bb6345B", "tokenMessaging": "0x1502FA4be69d526124D453619276FacCab275d3D", "endpoint": "0x1a44076050125825900e736c501f859c50fE728c", "localDecimals": 18, "sharedDecimals": 6, "kind": "oft", "approvalRequired": true },
|
|
331
|
+
{ "chain": "eip155:146", "chainId": 146, "eid": 30332, "assetId": 1, "symbol": "USDC", "token": "0x29219dd400f2Bf60E5a23d13Be72B486D4038894", "address": "0xA272fFe20cFfe769CdFc4b63088DCD2C82a2D8F9", "tokenMessaging": "0x2086f755A6d9254045C257ea3d382ef854849B0f", "endpoint": "0x6F475642a6e85809B1c36Fa62763669b1b48DD5B", "localDecimals": 6, "sharedDecimals": 6, "kind": "pool", "approvalRequired": true },
|
|
332
|
+
{ "chain": "eip155:130", "chainId": 130, "eid": 30320, "assetId": 13, "symbol": "ETH", "token": "0x0000000000000000000000000000000000000000", "address": "0xe9aBA835f813ca05E50A6C0ce65D0D74390F7dE7", "tokenMessaging": "0xB1EeAD6959cb5bB9B20417d6689922523B2B86C3", "endpoint": "0x6F475642a6e85809B1c36Fa62763669b1b48DD5B", "localDecimals": 18, "sharedDecimals": 6, "kind": "native", "approvalRequired": true }
|
|
333
|
+
];
|
|
334
|
+
var paths = [
|
|
335
|
+
{ "source": "eip155:1", "destination": "eip155:10" },
|
|
336
|
+
{ "source": "eip155:1", "destination": "eip155:130" },
|
|
337
|
+
{ "source": "eip155:1", "destination": "eip155:1329" },
|
|
338
|
+
{ "source": "eip155:1", "destination": "eip155:137" },
|
|
339
|
+
{ "source": "eip155:1", "destination": "eip155:14" },
|
|
340
|
+
{ "source": "eip155:1", "destination": "eip155:146" },
|
|
341
|
+
{ "source": "eip155:1", "destination": "eip155:42161" },
|
|
342
|
+
{ "source": "eip155:1", "destination": "eip155:43114" },
|
|
343
|
+
{ "source": "eip155:1", "destination": "eip155:5000" },
|
|
344
|
+
{ "source": "eip155:1", "destination": "eip155:534352" },
|
|
345
|
+
{ "source": "eip155:1", "destination": "eip155:56" },
|
|
346
|
+
{ "source": "eip155:1", "destination": "eip155:8453" },
|
|
347
|
+
{ "source": "eip155:1", "destination": "eip155:9745" },
|
|
348
|
+
{ "source": "eip155:1", "destination": "eip155:98866" },
|
|
349
|
+
{ "source": "eip155:10", "destination": "eip155:1" },
|
|
350
|
+
{ "source": "eip155:10", "destination": "eip155:130" },
|
|
351
|
+
{ "source": "eip155:10", "destination": "eip155:1329" },
|
|
352
|
+
{ "source": "eip155:10", "destination": "eip155:137" },
|
|
353
|
+
{ "source": "eip155:10", "destination": "eip155:14" },
|
|
354
|
+
{ "source": "eip155:10", "destination": "eip155:146" },
|
|
355
|
+
{ "source": "eip155:10", "destination": "eip155:42161" },
|
|
356
|
+
{ "source": "eip155:10", "destination": "eip155:43114" },
|
|
357
|
+
{ "source": "eip155:10", "destination": "eip155:5000" },
|
|
358
|
+
{ "source": "eip155:10", "destination": "eip155:534352" },
|
|
359
|
+
{ "source": "eip155:10", "destination": "eip155:56" },
|
|
360
|
+
{ "source": "eip155:10", "destination": "eip155:8453" },
|
|
361
|
+
{ "source": "eip155:10", "destination": "eip155:9745" },
|
|
362
|
+
{ "source": "eip155:10", "destination": "eip155:98866" },
|
|
363
|
+
{ "source": "eip155:130", "destination": "eip155:1" },
|
|
364
|
+
{ "source": "eip155:130", "destination": "eip155:10" },
|
|
365
|
+
{ "source": "eip155:130", "destination": "eip155:1329" },
|
|
366
|
+
{ "source": "eip155:130", "destination": "eip155:137" },
|
|
367
|
+
{ "source": "eip155:130", "destination": "eip155:14" },
|
|
368
|
+
{ "source": "eip155:130", "destination": "eip155:146" },
|
|
369
|
+
{ "source": "eip155:130", "destination": "eip155:42161" },
|
|
370
|
+
{ "source": "eip155:130", "destination": "eip155:43114" },
|
|
371
|
+
{ "source": "eip155:130", "destination": "eip155:5000" },
|
|
372
|
+
{ "source": "eip155:130", "destination": "eip155:534352" },
|
|
373
|
+
{ "source": "eip155:130", "destination": "eip155:56" },
|
|
374
|
+
{ "source": "eip155:130", "destination": "eip155:8453" },
|
|
375
|
+
{ "source": "eip155:130", "destination": "eip155:9745" },
|
|
376
|
+
{ "source": "eip155:130", "destination": "eip155:98866" },
|
|
377
|
+
{ "source": "eip155:1329", "destination": "eip155:1" },
|
|
378
|
+
{ "source": "eip155:1329", "destination": "eip155:10" },
|
|
379
|
+
{ "source": "eip155:1329", "destination": "eip155:130" },
|
|
380
|
+
{ "source": "eip155:1329", "destination": "eip155:137" },
|
|
381
|
+
{ "source": "eip155:1329", "destination": "eip155:14" },
|
|
382
|
+
{ "source": "eip155:1329", "destination": "eip155:146" },
|
|
383
|
+
{ "source": "eip155:1329", "destination": "eip155:42161" },
|
|
384
|
+
{ "source": "eip155:1329", "destination": "eip155:43114" },
|
|
385
|
+
{ "source": "eip155:1329", "destination": "eip155:5000" },
|
|
386
|
+
{ "source": "eip155:1329", "destination": "eip155:534352" },
|
|
387
|
+
{ "source": "eip155:1329", "destination": "eip155:56" },
|
|
388
|
+
{ "source": "eip155:1329", "destination": "eip155:8453" },
|
|
389
|
+
{ "source": "eip155:1329", "destination": "eip155:9745" },
|
|
390
|
+
{ "source": "eip155:1329", "destination": "eip155:98866" },
|
|
391
|
+
{ "source": "eip155:137", "destination": "eip155:1" },
|
|
392
|
+
{ "source": "eip155:137", "destination": "eip155:10" },
|
|
393
|
+
{ "source": "eip155:137", "destination": "eip155:130" },
|
|
394
|
+
{ "source": "eip155:137", "destination": "eip155:1329" },
|
|
395
|
+
{ "source": "eip155:137", "destination": "eip155:14" },
|
|
396
|
+
{ "source": "eip155:137", "destination": "eip155:146" },
|
|
397
|
+
{ "source": "eip155:137", "destination": "eip155:42161" },
|
|
398
|
+
{ "source": "eip155:137", "destination": "eip155:43114" },
|
|
399
|
+
{ "source": "eip155:137", "destination": "eip155:5000" },
|
|
400
|
+
{ "source": "eip155:137", "destination": "eip155:534352" },
|
|
401
|
+
{ "source": "eip155:137", "destination": "eip155:56" },
|
|
402
|
+
{ "source": "eip155:137", "destination": "eip155:8453" },
|
|
403
|
+
{ "source": "eip155:137", "destination": "eip155:9745" },
|
|
404
|
+
{ "source": "eip155:137", "destination": "eip155:98866" },
|
|
405
|
+
{ "source": "eip155:14", "destination": "eip155:1" },
|
|
406
|
+
{ "source": "eip155:14", "destination": "eip155:10" },
|
|
407
|
+
{ "source": "eip155:14", "destination": "eip155:130" },
|
|
408
|
+
{ "source": "eip155:14", "destination": "eip155:1329" },
|
|
409
|
+
{ "source": "eip155:14", "destination": "eip155:137" },
|
|
410
|
+
{ "source": "eip155:14", "destination": "eip155:146" },
|
|
411
|
+
{ "source": "eip155:14", "destination": "eip155:42161" },
|
|
412
|
+
{ "source": "eip155:14", "destination": "eip155:43114" },
|
|
413
|
+
{ "source": "eip155:14", "destination": "eip155:5000" },
|
|
414
|
+
{ "source": "eip155:14", "destination": "eip155:534352" },
|
|
415
|
+
{ "source": "eip155:14", "destination": "eip155:56" },
|
|
416
|
+
{ "source": "eip155:14", "destination": "eip155:8453" },
|
|
417
|
+
{ "source": "eip155:14", "destination": "eip155:9745" },
|
|
418
|
+
{ "source": "eip155:14", "destination": "eip155:98866" },
|
|
419
|
+
{ "source": "eip155:146", "destination": "eip155:1" },
|
|
420
|
+
{ "source": "eip155:146", "destination": "eip155:10" },
|
|
421
|
+
{ "source": "eip155:146", "destination": "eip155:130" },
|
|
422
|
+
{ "source": "eip155:146", "destination": "eip155:1329" },
|
|
423
|
+
{ "source": "eip155:146", "destination": "eip155:137" },
|
|
424
|
+
{ "source": "eip155:146", "destination": "eip155:14" },
|
|
425
|
+
{ "source": "eip155:146", "destination": "eip155:42161" },
|
|
426
|
+
{ "source": "eip155:146", "destination": "eip155:43114" },
|
|
427
|
+
{ "source": "eip155:146", "destination": "eip155:5000" },
|
|
428
|
+
{ "source": "eip155:146", "destination": "eip155:534352" },
|
|
429
|
+
{ "source": "eip155:146", "destination": "eip155:56" },
|
|
430
|
+
{ "source": "eip155:146", "destination": "eip155:8453" },
|
|
431
|
+
{ "source": "eip155:146", "destination": "eip155:9745" },
|
|
432
|
+
{ "source": "eip155:146", "destination": "eip155:98866" },
|
|
433
|
+
{ "source": "eip155:42161", "destination": "eip155:1" },
|
|
434
|
+
{ "source": "eip155:42161", "destination": "eip155:10" },
|
|
435
|
+
{ "source": "eip155:42161", "destination": "eip155:130" },
|
|
436
|
+
{ "source": "eip155:42161", "destination": "eip155:1329" },
|
|
437
|
+
{ "source": "eip155:42161", "destination": "eip155:137" },
|
|
438
|
+
{ "source": "eip155:42161", "destination": "eip155:14" },
|
|
439
|
+
{ "source": "eip155:42161", "destination": "eip155:146" },
|
|
440
|
+
{ "source": "eip155:42161", "destination": "eip155:43114" },
|
|
441
|
+
{ "source": "eip155:42161", "destination": "eip155:5000" },
|
|
442
|
+
{ "source": "eip155:42161", "destination": "eip155:534352" },
|
|
443
|
+
{ "source": "eip155:42161", "destination": "eip155:56" },
|
|
444
|
+
{ "source": "eip155:42161", "destination": "eip155:8453" },
|
|
445
|
+
{ "source": "eip155:42161", "destination": "eip155:9745" },
|
|
446
|
+
{ "source": "eip155:42161", "destination": "eip155:98866" },
|
|
447
|
+
{ "source": "eip155:43114", "destination": "eip155:1" },
|
|
448
|
+
{ "source": "eip155:43114", "destination": "eip155:10" },
|
|
449
|
+
{ "source": "eip155:43114", "destination": "eip155:130" },
|
|
450
|
+
{ "source": "eip155:43114", "destination": "eip155:1329" },
|
|
451
|
+
{ "source": "eip155:43114", "destination": "eip155:137" },
|
|
452
|
+
{ "source": "eip155:43114", "destination": "eip155:14" },
|
|
453
|
+
{ "source": "eip155:43114", "destination": "eip155:146" },
|
|
454
|
+
{ "source": "eip155:43114", "destination": "eip155:42161" },
|
|
455
|
+
{ "source": "eip155:43114", "destination": "eip155:5000" },
|
|
456
|
+
{ "source": "eip155:43114", "destination": "eip155:534352" },
|
|
457
|
+
{ "source": "eip155:43114", "destination": "eip155:56" },
|
|
458
|
+
{ "source": "eip155:43114", "destination": "eip155:8453" },
|
|
459
|
+
{ "source": "eip155:43114", "destination": "eip155:9745" },
|
|
460
|
+
{ "source": "eip155:43114", "destination": "eip155:98866" },
|
|
461
|
+
{ "source": "eip155:5000", "destination": "eip155:1" },
|
|
462
|
+
{ "source": "eip155:5000", "destination": "eip155:10" },
|
|
463
|
+
{ "source": "eip155:5000", "destination": "eip155:130" },
|
|
464
|
+
{ "source": "eip155:5000", "destination": "eip155:1329" },
|
|
465
|
+
{ "source": "eip155:5000", "destination": "eip155:137" },
|
|
466
|
+
{ "source": "eip155:5000", "destination": "eip155:14" },
|
|
467
|
+
{ "source": "eip155:5000", "destination": "eip155:146" },
|
|
468
|
+
{ "source": "eip155:5000", "destination": "eip155:42161" },
|
|
469
|
+
{ "source": "eip155:5000", "destination": "eip155:43114" },
|
|
470
|
+
{ "source": "eip155:5000", "destination": "eip155:534352" },
|
|
471
|
+
{ "source": "eip155:5000", "destination": "eip155:56" },
|
|
472
|
+
{ "source": "eip155:5000", "destination": "eip155:8453" },
|
|
473
|
+
{ "source": "eip155:5000", "destination": "eip155:9745" },
|
|
474
|
+
{ "source": "eip155:5000", "destination": "eip155:98866" },
|
|
475
|
+
{ "source": "eip155:534352", "destination": "eip155:1" },
|
|
476
|
+
{ "source": "eip155:534352", "destination": "eip155:10" },
|
|
477
|
+
{ "source": "eip155:534352", "destination": "eip155:130" },
|
|
478
|
+
{ "source": "eip155:534352", "destination": "eip155:1329" },
|
|
479
|
+
{ "source": "eip155:534352", "destination": "eip155:137" },
|
|
480
|
+
{ "source": "eip155:534352", "destination": "eip155:14" },
|
|
481
|
+
{ "source": "eip155:534352", "destination": "eip155:146" },
|
|
482
|
+
{ "source": "eip155:534352", "destination": "eip155:42161" },
|
|
483
|
+
{ "source": "eip155:534352", "destination": "eip155:43114" },
|
|
484
|
+
{ "source": "eip155:534352", "destination": "eip155:5000" },
|
|
485
|
+
{ "source": "eip155:534352", "destination": "eip155:56" },
|
|
486
|
+
{ "source": "eip155:534352", "destination": "eip155:8453" },
|
|
487
|
+
{ "source": "eip155:534352", "destination": "eip155:9745" },
|
|
488
|
+
{ "source": "eip155:534352", "destination": "eip155:98866" },
|
|
489
|
+
{ "source": "eip155:56", "destination": "eip155:1" },
|
|
490
|
+
{ "source": "eip155:56", "destination": "eip155:10" },
|
|
491
|
+
{ "source": "eip155:56", "destination": "eip155:130" },
|
|
492
|
+
{ "source": "eip155:56", "destination": "eip155:1329" },
|
|
493
|
+
{ "source": "eip155:56", "destination": "eip155:137" },
|
|
494
|
+
{ "source": "eip155:56", "destination": "eip155:14" },
|
|
495
|
+
{ "source": "eip155:56", "destination": "eip155:146" },
|
|
496
|
+
{ "source": "eip155:56", "destination": "eip155:42161" },
|
|
497
|
+
{ "source": "eip155:56", "destination": "eip155:43114" },
|
|
498
|
+
{ "source": "eip155:56", "destination": "eip155:5000" },
|
|
499
|
+
{ "source": "eip155:56", "destination": "eip155:534352" },
|
|
500
|
+
{ "source": "eip155:56", "destination": "eip155:8453" },
|
|
501
|
+
{ "source": "eip155:56", "destination": "eip155:9745" },
|
|
502
|
+
{ "source": "eip155:56", "destination": "eip155:98866" },
|
|
503
|
+
{ "source": "eip155:8453", "destination": "eip155:1" },
|
|
504
|
+
{ "source": "eip155:8453", "destination": "eip155:10" },
|
|
505
|
+
{ "source": "eip155:8453", "destination": "eip155:130" },
|
|
506
|
+
{ "source": "eip155:8453", "destination": "eip155:1329" },
|
|
507
|
+
{ "source": "eip155:8453", "destination": "eip155:137" },
|
|
508
|
+
{ "source": "eip155:8453", "destination": "eip155:14" },
|
|
509
|
+
{ "source": "eip155:8453", "destination": "eip155:146" },
|
|
510
|
+
{ "source": "eip155:8453", "destination": "eip155:42161" },
|
|
511
|
+
{ "source": "eip155:8453", "destination": "eip155:43114" },
|
|
512
|
+
{ "source": "eip155:8453", "destination": "eip155:5000" },
|
|
513
|
+
{ "source": "eip155:8453", "destination": "eip155:534352" },
|
|
514
|
+
{ "source": "eip155:8453", "destination": "eip155:56" },
|
|
515
|
+
{ "source": "eip155:8453", "destination": "eip155:9745" },
|
|
516
|
+
{ "source": "eip155:8453", "destination": "eip155:98866" },
|
|
517
|
+
{ "source": "eip155:9745", "destination": "eip155:1" },
|
|
518
|
+
{ "source": "eip155:9745", "destination": "eip155:10" },
|
|
519
|
+
{ "source": "eip155:9745", "destination": "eip155:130" },
|
|
520
|
+
{ "source": "eip155:9745", "destination": "eip155:1329" },
|
|
521
|
+
{ "source": "eip155:9745", "destination": "eip155:137" },
|
|
522
|
+
{ "source": "eip155:9745", "destination": "eip155:14" },
|
|
523
|
+
{ "source": "eip155:9745", "destination": "eip155:146" },
|
|
524
|
+
{ "source": "eip155:9745", "destination": "eip155:42161" },
|
|
525
|
+
{ "source": "eip155:9745", "destination": "eip155:43114" },
|
|
526
|
+
{ "source": "eip155:9745", "destination": "eip155:5000" },
|
|
527
|
+
{ "source": "eip155:9745", "destination": "eip155:534352" },
|
|
528
|
+
{ "source": "eip155:9745", "destination": "eip155:56" },
|
|
529
|
+
{ "source": "eip155:9745", "destination": "eip155:8453" },
|
|
530
|
+
{ "source": "eip155:9745", "destination": "eip155:98866" },
|
|
531
|
+
{ "source": "eip155:98866", "destination": "eip155:1" },
|
|
532
|
+
{ "source": "eip155:98866", "destination": "eip155:10" },
|
|
533
|
+
{ "source": "eip155:98866", "destination": "eip155:130" },
|
|
534
|
+
{ "source": "eip155:98866", "destination": "eip155:1329" },
|
|
535
|
+
{ "source": "eip155:98866", "destination": "eip155:137" },
|
|
536
|
+
{ "source": "eip155:98866", "destination": "eip155:14" },
|
|
537
|
+
{ "source": "eip155:98866", "destination": "eip155:146" },
|
|
538
|
+
{ "source": "eip155:98866", "destination": "eip155:42161" },
|
|
539
|
+
{ "source": "eip155:98866", "destination": "eip155:43114" },
|
|
540
|
+
{ "source": "eip155:98866", "destination": "eip155:5000" },
|
|
541
|
+
{ "source": "eip155:98866", "destination": "eip155:534352" },
|
|
542
|
+
{ "source": "eip155:98866", "destination": "eip155:56" },
|
|
543
|
+
{ "source": "eip155:98866", "destination": "eip155:8453" },
|
|
544
|
+
{ "source": "eip155:98866", "destination": "eip155:9745" }
|
|
545
|
+
];
|
|
546
|
+
var stargateRegistry = createStargateRegistry(deployments, paths);
|
|
547
|
+
|
|
548
|
+
// src/quote.ts
|
|
549
|
+
var import_viem4 = require("viem");
|
|
550
|
+
var UINT64_MAX2 = (1n << 64n) - 1n;
|
|
551
|
+
var UINT256_MAX2 = (1n << 256n) - 1n;
|
|
552
|
+
function stargateComposeOptions(gas) {
|
|
553
|
+
assertStargate(typeof gas === "bigint" && gas > 0n && gas < 1n << 128n, "compose gas must be a positive uint128");
|
|
554
|
+
return (0, import_viem4.encodePacked)(["uint16", "uint8", "uint16", "uint8", "uint16", "uint128"], [3, 1, 19, 3, 0, gas]);
|
|
555
|
+
}
|
|
556
|
+
function taxiNativeDrop(amount, recipient) {
|
|
557
|
+
assertStargate(typeof amount === "bigint" && amount > 0n && amount < 1n << 128n, "native drop must be a positive uint128");
|
|
558
|
+
assertStargate(nonzeroAddress(recipient), "invalid native drop recipient");
|
|
559
|
+
return (0, import_viem4.encodePacked)(["uint16", "uint8", "uint16", "uint8", "uint128", "bytes32"], [3, 1, 49, 2, amount, (0, import_viem4.pad)(recipient, { size: 32 })]);
|
|
560
|
+
}
|
|
561
|
+
function createStargateQuoter(config) {
|
|
562
|
+
const registry = config.registry ?? stargateRegistry;
|
|
563
|
+
const rpc = stargateRpc(config);
|
|
564
|
+
const ttl = config.quoteTtlMs ?? 6e4;
|
|
565
|
+
const headroom = config.feeHeadroomBps ?? 2500;
|
|
566
|
+
assertStargate(Number.isSafeInteger(ttl) && ttl > 0 && ttl <= 3e5, "invalid quote lifetime");
|
|
567
|
+
assertStargate(Number.isInteger(headroom) && headroom >= 0 && headroom <= 1e4, "invalid messaging fee headroom");
|
|
568
|
+
function supportsRoute(sourceChain, sourceToken, destinationChain, destinationToken) {
|
|
569
|
+
return stargateChainActive(sourceChain) && stargateChainActive(destinationChain) && rpc.has(sourceChain) && rpc.has(destinationChain) && !!registry.route(sourceChain, sourceToken, destinationChain, destinationToken);
|
|
570
|
+
}
|
|
571
|
+
async function quote(input, signal) {
|
|
572
|
+
const request = { ...input, ...input.nativeDrop ? { nativeDrop: { ...input.nativeDrop } } : {} };
|
|
573
|
+
const started = Date.now();
|
|
574
|
+
try {
|
|
575
|
+
assertNotAborted(signal);
|
|
576
|
+
assertStargate(request.mode === "taxi" || request.mode === "bus", "invalid transport mode");
|
|
577
|
+
assertStargate(request.mode !== "bus", STARGATE_BUS_RETIRED);
|
|
578
|
+
assertStargate(stargateChainActive(request.sourceChain) && stargateChainActive(request.destinationChain), "chain support has ended for new transfers");
|
|
579
|
+
const route = registry.route(request.sourceChain, request.sourceToken, request.destinationChain, request.destinationToken);
|
|
580
|
+
assertStargate(route, "unsupported token route");
|
|
581
|
+
const { source, destination } = route;
|
|
582
|
+
assertStargate(nonzeroAddress(request.sender) && nonzeroAddress(request.recipient), "sender and recipient must be nonzero EVM addresses");
|
|
583
|
+
const sender = (0, import_viem4.getAddress)(request.sender), recipient = (0, import_viem4.getAddress)(request.recipient);
|
|
584
|
+
const slippage = request.slippageBps ?? 0;
|
|
585
|
+
assertStargate(Number.isInteger(slippage) && slippage >= 0 && slippage < 1e4, "invalid slippage");
|
|
586
|
+
const minimum = request.minimum ?? 0n;
|
|
587
|
+
assertStargate(typeof minimum === "bigint" && minimum >= 0n && minimum <= UINT256_MAX2, "invalid minimum");
|
|
588
|
+
const split = splitSourceAmount(request.amount, source.localDecimals, source.sharedDecimals);
|
|
589
|
+
assertStargate(split.amountSD > 0n, "amount is below shared-decimal precision");
|
|
590
|
+
const src = rpc.client(source.chain, signal), dst = rpc.client(destination.chain, signal);
|
|
591
|
+
const [sourceBlock, destinationBlock] = await Promise.all([rpc.snapshot(src, source.chainId), rpc.snapshot(dst, destination.chainId)]);
|
|
592
|
+
await Promise.all([rpc.verify(src, source, destination, sourceBlock), rpc.verify(dst, destination, source, destinationBlock)]);
|
|
593
|
+
assertNotAborted(signal);
|
|
594
|
+
const at = { address: source.address, abi: STARGATE_ABI, blockNumber: sourceBlock.number, account: sender };
|
|
595
|
+
const creditSD = await src.readContract({ ...at, functionName: "paths", args: [destination.eid] });
|
|
596
|
+
let extraOptions = "0x", nativeDrop = 0n;
|
|
597
|
+
const compose = request.compose;
|
|
598
|
+
assertStargate(!compose || !request.nativeDrop && slippage === 0 && minimum === 0n, "compose takes an exact bridge output without native drop");
|
|
599
|
+
if (request.nativeDrop) {
|
|
600
|
+
assertStargate("amount" in request.nativeDrop && !("bus" in request.nativeDrop), "Taxi requires an explicit native drop amount");
|
|
601
|
+
nativeDrop = request.nativeDrop.amount;
|
|
602
|
+
extraOptions = taxiNativeDrop(nativeDrop, recipient);
|
|
603
|
+
}
|
|
604
|
+
const probe = { dstEid: destination.eid, to: (0, import_viem4.pad)(recipient, { size: 32 }), amountLD: request.amount, minAmountLD: 0n, extraOptions, composeMsg: "0x", oftCmd: "0x" };
|
|
605
|
+
const [limit, details, receipt] = await src.readContract({ ...at, functionName: "quoteOFT", args: [probe] });
|
|
606
|
+
assertStargate(limit.minAmountLD <= split.sentLD && split.sentLD <= limit.maxAmountLD, "amount exceeds available OFT limits");
|
|
607
|
+
assertStargate(receipt.amountSentLD === split.sentLD, "quote clipped the exact input amount");
|
|
608
|
+
const received = destinationAmount(receipt.amountReceivedLD, source.localDecimals, destination.localDecimals, source.sharedDecimals);
|
|
609
|
+
assertStargate(received > 0n, "quote has no output");
|
|
610
|
+
const receivedSD = receipt.amountReceivedLD / conversionRate(source.localDecimals, source.sharedDecimals);
|
|
611
|
+
assertStargate(creditSD === UINT64_MAX2 || receivedSD <= creditSD, "insufficient credits for output including reward");
|
|
612
|
+
const fees = splitFeeDetails(details);
|
|
613
|
+
assertStargate(receipt.amountSentLD - fees.feeLD + fees.rewardLD === receipt.amountReceivedLD, "protocol fee accounting mismatch");
|
|
614
|
+
const slipFloor = (received * BigInt(1e4 - slippage) + 9999n) / 10000n;
|
|
615
|
+
const minAmountLD = sourceMinimum(minimum > slipFloor ? minimum : slipFloor, source.localDecimals, destination.localDecimals, source.sharedDecimals);
|
|
616
|
+
assertStargate(minAmountLD <= receipt.amountReceivedLD, "output is below the caller's minimum");
|
|
617
|
+
const sendParam = Object.freeze(compose ? { ...probe, minAmountLD, extraOptions: stargateComposeOptions(compose.gas), composeMsg: await compose.message(received, signal) } : { ...probe, minAmountLD });
|
|
618
|
+
assertNotAborted(signal);
|
|
619
|
+
const fee = await src.readContract({ ...at, functionName: "quoteSend", args: [sendParam, false] });
|
|
620
|
+
assertStargate(fee.lzTokenFee === 0n, "LZ token fees are unsupported");
|
|
621
|
+
const cap = fee.nativeFee + (fee.nativeFee * BigInt(headroom) + 9999n) / 10000n;
|
|
622
|
+
const nativeValue = cap + (source.kind === "native" ? request.amount : 0n);
|
|
623
|
+
assertStargate(nativeValue <= UINT256_MAX2, "native value overflow");
|
|
624
|
+
await Promise.all([rpc.unchanged(src, sourceBlock), rpc.unchanged(dst, destinationBlock)]);
|
|
625
|
+
assertNotAborted(signal);
|
|
626
|
+
const validUntilMs = Math.min(started + ttl, stargateChainCutoff(source.chain), stargateChainCutoff(destination.chain));
|
|
627
|
+
assertStargate(Date.now() < validUntilMs, "quote expired during RPC reads");
|
|
628
|
+
return Object.freeze({ mode: request.mode, source, destination, sender, recipient, sourceBlock, destinationBlock, requestedAmount: request.amount, sentAmount: split.sentLD, dust: split.dustLD, destinationAmount: received, minimumDestinationAmount: destinationAmount(minAmountLD, source.localDecimals, destination.localDecimals, source.sharedDecimals), protocolFee: fees.feeLD, protocolReward: fees.rewardLD, messagingFee: fee.nativeFee, messagingFeeCap: cap, nativeValue, nativeDrop, creditSD, sendParam, validUntilMs, liquidityReserved: false, etaSeconds: null, sourceGas: null, approvalGas: null });
|
|
629
|
+
} catch (error) {
|
|
630
|
+
throw safeReadError(error);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return Object.freeze({ supportsRoute, quote });
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// src/compose.ts
|
|
637
|
+
var COMPOSE_ABI = (0, import_viem5.parseAbi)([
|
|
638
|
+
"function composeQueue(address from, address to, bytes32 guid, uint16 index) view returns (bytes32)",
|
|
639
|
+
"function lzCompose(address from, address to, bytes32 guid, uint16 index, bytes message, bytes extraData) payable",
|
|
640
|
+
"event ComposeSent(address from, address to, bytes32 guid, uint16 index, bytes message)",
|
|
641
|
+
"event ComposeDelivered(address from, address to, bytes32 guid, uint16 index)"
|
|
642
|
+
]);
|
|
643
|
+
var LIFI_COMPOSE_ABI = (0, import_viem5.parseAbi)([
|
|
644
|
+
"function executor() view returns (address)",
|
|
645
|
+
"function endpointV2() view returns (address)",
|
|
646
|
+
"function tokenMessaging() view returns (address)",
|
|
647
|
+
"function recoverGas() view returns (uint256)",
|
|
648
|
+
"event LiFiTransferCompleted(bytes32 indexed transactionId, address receivingAssetId, address receiver, uint256 amount, uint256 timestamp)",
|
|
649
|
+
"event LiFiTransferRecovered(bytes32 indexed transactionId, address receivingAssetId, address receiver, uint256 amount, uint256 timestamp)",
|
|
650
|
+
"event AssetSwapped(bytes32 transactionId, address dex, address fromAssetId, address toAssetId, uint256 fromAmount, uint256 toAmount, uint256 timestamp)",
|
|
651
|
+
"event Transfer(address indexed from, address indexed to, uint256 value)"
|
|
652
|
+
]);
|
|
653
|
+
var LIFI_COMPOSE_PAYLOAD = (0, import_viem5.parseAbiParameters)("bytes32 transactionId, (address callTo, address approveTo, address sendingAssetId, address receivingAssetId, uint256 fromAmount, bytes callData, bool requiresDeposit)[] swaps, address receiver");
|
|
654
|
+
var LIFI_ETHEREUM_COMPOSER = Object.freeze({
|
|
655
|
+
chain: "eip155:1",
|
|
656
|
+
receiver: "0xB539B40793171211DCA8834da044fC14bCe64BDC",
|
|
657
|
+
executor: "0xd9B2Da9C45b118e4e93A004FB1452bCDB6cC0E88",
|
|
658
|
+
receiverCodeHash: "0x535b6e74e5bbb38e9a469de60ff2587cf498b92a99be01f34d20c37a77e4cea2",
|
|
659
|
+
executorCodeHash: "0xf937f13890d789171f0bcf3c558a64869105000b6771dc182ddc165bde92ddfe"
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
// src/compose-dex.ts
|
|
663
|
+
var import_viem6 = require("viem");
|
|
664
|
+
var COMPOSE_UNOSWAP_ABI = (0, import_viem6.parseAbi)(["function unoswap2(uint256 token, uint256 amount, uint256 minReturn, uint256 dex, uint256 dex2) returns (uint256)"]);
|
|
665
|
+
var COMPOSE_POOL_ABI = (0, import_viem6.parseAbi)([
|
|
666
|
+
"function token0() view returns (address)",
|
|
667
|
+
"function token1() view returns (address)",
|
|
668
|
+
"function fee() view returns (uint24)",
|
|
669
|
+
"function getPool(address tokenA, address tokenB, uint24 fee) view returns (address)"
|
|
670
|
+
]);
|
|
671
|
+
var COMPOSE_DEX_PINS = Object.freeze({
|
|
672
|
+
router: "0x111111125421cA6dc452d289314280a0f8842A65",
|
|
673
|
+
routerCodeHash: "0xa5a286be4b80006cc547d7e899871aa01a0e0551e2a509233375405f92098c2f",
|
|
674
|
+
factory: "0x1F98431c8aD98523631AE4a59f267346ea31F984",
|
|
675
|
+
factoryCodeHash: "0x4d7b8525cd5d14343fa67a732fba5b24cddba11620ca88392f4ec6c52f91fd69",
|
|
676
|
+
/** Observed four-byte suffix; its ownership/meaning is not an authorization signal. */
|
|
677
|
+
calldataSuffix: "2a94d114"
|
|
678
|
+
});
|
|
679
|
+
var UNOSWAP_FLAGS = Object.freeze({ V3: 1n << 253n, NO_WRAP: 1n << 251n, ZERO_FOR_ONE: 1n << 247n });
|
|
680
|
+
var ADDRESS = (1n << 160n) - 1n;
|
|
681
|
+
var { V3, NO_WRAP, ZERO_FOR_ONE } = UNOSWAP_FLAGS;
|
|
682
|
+
async function unoswap2V3Path(client, blockNumber, input, words, output) {
|
|
683
|
+
let current = input;
|
|
684
|
+
const pools = [], fees = [], tokens = [input];
|
|
685
|
+
for (const encoded of words) {
|
|
686
|
+
assertStargate(encoded >> 253n === 1n && (encoded & ~(ADDRESS | V3 | NO_WRAP | ZERO_FOR_ONE)) === 0n, "unsupported compose DEX flags");
|
|
687
|
+
const address2 = (0, import_viem6.getAddress)((0, import_viem6.toHex)(encoded & ADDRESS, { size: 20 }));
|
|
688
|
+
const at = { address: address2, abi: COMPOSE_POOL_ABI, blockNumber };
|
|
689
|
+
const [token0, token1, fee] = await Promise.all([
|
|
690
|
+
client.readContract({ ...at, functionName: "token0" }),
|
|
691
|
+
client.readContract({ ...at, functionName: "token1" }),
|
|
692
|
+
client.readContract({ ...at, functionName: "fee" })
|
|
693
|
+
]);
|
|
694
|
+
const canonical = await client.readContract({ address: COMPOSE_DEX_PINS.factory, abi: COMPOSE_POOL_ABI, functionName: "getPool", args: [token0, token1, fee], blockNumber });
|
|
695
|
+
assertStargate(sameAddress(canonical, address2) && address2 !== import_viem6.zeroAddress && !sameAddress(token0, token1), "unreviewed compose DEX pool");
|
|
696
|
+
const forward = (encoded & ZERO_FOR_ONE) !== 0n;
|
|
697
|
+
assertStargate(sameAddress(current, forward ? token0 : token1), "compose DEX path input mismatch");
|
|
698
|
+
current = forward ? token1 : token0;
|
|
699
|
+
pools.push(address2);
|
|
700
|
+
fees.push(fee);
|
|
701
|
+
tokens.push(current);
|
|
702
|
+
}
|
|
703
|
+
assertStargate(sameAddress(current, output), "compose DEX path output mismatch");
|
|
704
|
+
return Object.freeze({ pools: Object.freeze(pools), fees: Object.freeze(fees), tokens: Object.freeze(tokens) });
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// src/source-tx.ts
|
|
708
|
+
var import_viem7 = require("viem");
|
|
709
|
+
var import_swap2_assets = require("@anywalletkit/swap2-assets");
|
|
710
|
+
function stargateFees(source, protocolFee, cap) {
|
|
711
|
+
const nativeToken = (0, import_swap2_assets.ccAssetByToken)(source.chain, import_viem7.zeroAddress)?.assetId ?? import_viem7.zeroAddress;
|
|
712
|
+
return [
|
|
713
|
+
...protocolFee ? [{ type: "protocol", amount: String(protocolFee), token: source.kind === "native" ? nativeToken : source.token, included: true, description: "Stargate protocol fee, already deducted from output" }] : [],
|
|
714
|
+
{ type: "network", amount: String(cap), token: nativeToken, included: false, description: "Messaging fee cap; unused headroom is refunded. Source transaction gas is additional." }
|
|
715
|
+
];
|
|
716
|
+
}
|
|
717
|
+
function checkedStargateSource(q, source, destination, amount, routeId) {
|
|
718
|
+
assertStargate(stargateChainActive(source.chain) && stargateChainActive(destination.chain), "chain support has ended for new transfers");
|
|
719
|
+
const tx = q.txRequest;
|
|
720
|
+
assertStargate(q.provider === "stargate" && q.routeId === routeId && tx && tx.to && tx.data, "missing Stargate transaction");
|
|
721
|
+
assertStargate(q.depositAddress === "" && q.depositMemo === null && tx.serializedTx === void 0 && tx.gasLimit === void 0, "unexpected transaction fields");
|
|
722
|
+
assertStargate(sameAddress(tx.to, source.address) && tx.chainId === source.chainId && q.sourceAmount === String(amount), "quote identity mismatch");
|
|
723
|
+
assertStargate(Number.isFinite(q.validUntilMs) && q.validUntilMs > Date.now(), "quote expired");
|
|
724
|
+
assertStargate(typeof tx.nativeFee === "string" && /^(0|[1-9][0-9]{0,77})$/.test(tx.nativeFee), "invalid messaging fee cap");
|
|
725
|
+
const cap = BigInt(tx.nativeFee);
|
|
726
|
+
const value = cap + (source.kind === "native" ? amount : 0n);
|
|
727
|
+
assertStargate(value < 1n << 256n && tx.value === String(value), "native value mismatch");
|
|
728
|
+
assertStargate(source.kind !== "native" && source.approvalRequired ? !!tx.approvalAddress && sameAddress(tx.approvalAddress, source.address) : tx.approvalAddress === void 0, "approval spender mismatch");
|
|
729
|
+
return { tx: { ...tx, to: tx.to, data: tx.data }, cap };
|
|
730
|
+
}
|
|
731
|
+
function checkedStargateAccounting(q, source, destination, amount, cap, received) {
|
|
732
|
+
const pd = q.providerData;
|
|
733
|
+
assertStargate(pd && ["sentAmount", "dust", "protocolFee", "protocolReward", "messagingFee"].every((key) => /^(0|[1-9][0-9]{0,77})$/.test(pd[key] ?? "")), "missing amount accounting");
|
|
734
|
+
const split = splitSourceAmount(amount, source.localDecimals, source.sharedDecimals);
|
|
735
|
+
assertStargate(pd.sentAmount === String(split.sentLD) && pd.dust === String(split.dustLD), "dust accounting mismatch");
|
|
736
|
+
assertStargate(destinationAmount(split.sentLD - BigInt(pd.protocolFee) + BigInt(pd.protocolReward), source.localDecimals, destination.localDecimals, source.sharedDecimals) === received, "fee accounting mismatch");
|
|
737
|
+
assertStargate(BigInt(pd.messagingFee) <= cap, "messaging fee exceeds cap");
|
|
738
|
+
const fees = stargateFees(source, BigInt(pd.protocolFee), cap);
|
|
739
|
+
assertStargate(q.fees?.length === fees.length && fees.every((fee, index) => Object.entries(fee).every(([key, value]) => q.fees[index][key] === value)), "fee display mismatch");
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// src/compose-route.ts
|
|
743
|
+
var STARGATE_COMPOSE_CHAIN = "eip155:1";
|
|
744
|
+
var UNISWAP_V3_QUOTER_V2 = "0x61fFE014bA17989E743c5F6cB21bF9697530B21e";
|
|
745
|
+
var MULTICALL3 = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
746
|
+
var ONE_BATCH = 1 << 16;
|
|
747
|
+
var QUOTE_GROUP = 4;
|
|
748
|
+
var COMPOSE_INTERMEDIATES = Object.freeze([
|
|
749
|
+
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
750
|
+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
751
|
+
"0xdAC17F958D2ee523a2206206994597C13D831ec7"
|
|
752
|
+
]);
|
|
753
|
+
var FEE_TIERS = [100, 500, 3e3, 1e4];
|
|
754
|
+
var COMPOSE_SWAP_GAS = 400000n;
|
|
755
|
+
var MIN_SWAP_GAS = 250000n;
|
|
756
|
+
var MAX_COMPOSE_GAS = 2000000n;
|
|
757
|
+
var RETRY_OVERHEAD = 250000n;
|
|
758
|
+
var QUOTER_ABI = (0, import_viem8.parseAbi)(["function quoteExactInput(bytes path, uint256 amountIn) view returns (uint256 amountOut, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate)"]);
|
|
759
|
+
var ADDRESS2 = (1n << 160n) - 1n;
|
|
760
|
+
var { V3: V32, NO_WRAP: NO_WRAP2, ZERO_FOR_ONE: ZERO_FOR_ONE2 } = UNOSWAP_FLAGS;
|
|
761
|
+
var PREFIX = "stargate:2:compose";
|
|
762
|
+
var isStargateComposeIntent = (id) => id.startsWith(`${PREFIX}:`);
|
|
763
|
+
function stargateComposeIntentId(c) {
|
|
764
|
+
const b = c.bridge;
|
|
765
|
+
return [PREFIX, b.source.eid, b.destination.eid, b.source.assetId, b.sender.toLowerCase(), c.recipient.toLowerCase(), b.amount, b.minimum, c.finalToken.toLowerCase(), (0, import_viem8.toHex)(c.dex[0]), (0, import_viem8.toHex)(c.dex[1]), c.minReturn, c.gas, c.transactionId.toLowerCase()].join(":");
|
|
766
|
+
}
|
|
767
|
+
function parseStargateComposeIntent(id, registry) {
|
|
768
|
+
const fields = id.split("~", 1)[0].split(":");
|
|
769
|
+
const [tag, version, mode, srcEid, dstEid, assetId, sender, recipient, amountText, fromText, finalToken, dex0, dex1, minText, gasText, transactionId] = fields;
|
|
770
|
+
assertStargate(fields.length === 16 && `${tag}:${version}:${mode}` === PREFIX, "invalid compose intent identity");
|
|
771
|
+
assertStargate([srcEid, dstEid, assetId, amountText, fromText, minText, gasText].every((v) => typeof v === "string" && /^(0|[1-9][0-9]{0,77})$/.test(v)), "invalid compose intent amounts");
|
|
772
|
+
assertStargate([dex0, dex1].every((v) => typeof v === "string" && /^0x[1-9a-f][0-9a-f]{0,63}$/.test(v)) && /^0x[0-9a-f]{64}$/.test(transactionId ?? "") && BigInt(transactionId) !== 0n, "invalid compose intent fields");
|
|
773
|
+
assertStargate(sender && recipient && finalToken && nonzeroAddress(sender) && nonzeroAddress(recipient) && nonzeroAddress(finalToken), "invalid compose intent actors");
|
|
774
|
+
const source = registry.deployments.find((d) => String(d.eid) === srcEid && String(d.assetId) === assetId);
|
|
775
|
+
const destination = registry.deployments.find((d) => String(d.eid) === dstEid && String(d.assetId) === assetId);
|
|
776
|
+
assertStargate(source && destination && destination.chain === STARGATE_COMPOSE_CHAIN && source.kind !== "native" && destination.kind !== "native" && registry.route(source.chain, source.token, destination.chain, destination.token), "unreviewed compose route");
|
|
777
|
+
assertStargate(!sameAddress(finalToken, destination.token), "compose output equals the bridged asset");
|
|
778
|
+
const amount = BigInt(amountText), fromAmount = BigInt(fromText), minReturn = BigInt(minText), gas = BigInt(gasText);
|
|
779
|
+
assertStargate(splitSourceAmount(amount, source.localDecimals, source.sharedDecimals).amountSD > 0n && fromAmount > 0n && minReturn > 0n && minReturn < 1n << 256n && gas >= MIN_SWAP_GAS && gas <= MAX_COMPOSE_GAS, "invalid compose intent bounds");
|
|
780
|
+
assertStargate(destinationAmount(sourceMinimum(fromAmount, source.localDecimals, destination.localDecimals, source.sharedDecimals), source.localDecimals, destination.localDecimals, source.sharedDecimals) === fromAmount, "unaligned compose bridge amount");
|
|
781
|
+
const dex = [BigInt(dex0), BigInt(dex1)];
|
|
782
|
+
assertStargate(dex.every((w) => w >> 253n === 1n && (w & ~(ADDRESS2 | V32 | NO_WRAP2 | ZERO_FOR_ONE2)) === 0n && (w & ADDRESS2) !== 0n), "unsupported compose DEX word");
|
|
783
|
+
const bridge = Object.freeze({ source, destination, mode: "taxi", sender: (0, import_viem8.getAddress)(sender), recipient: LIFI_ETHEREUM_COMPOSER.receiver, amount, minimum: fromAmount, nativeDrop: 0n });
|
|
784
|
+
return Object.freeze({ bridge, recipient: (0, import_viem8.getAddress)(recipient), finalToken: (0, import_viem8.getAddress)(finalToken), dex: Object.freeze(dex), minReturn, gas, transactionId });
|
|
785
|
+
}
|
|
786
|
+
function stargateComposeSwapCall(c) {
|
|
787
|
+
return (0, import_viem8.encodeFunctionData)({ abi: COMPOSE_UNOSWAP_ABI, functionName: "unoswap2", args: [BigInt(c.bridge.destination.token), c.bridge.minimum, c.minReturn, c.dex[0], c.dex[1]] });
|
|
788
|
+
}
|
|
789
|
+
function stargateComposeMessage(c) {
|
|
790
|
+
const router = (0, import_viem8.getAddress)(COMPOSE_DEX_PINS.router);
|
|
791
|
+
return (0, import_viem8.encodeAbiParameters)(LIFI_COMPOSE_PAYLOAD, [c.transactionId, [{ callTo: router, approveTo: router, sendingAssetId: c.bridge.destination.token, receivingAssetId: c.finalToken, fromAmount: c.bridge.minimum, callData: stargateComposeSwapCall(c), requiresDeposit: true }], c.recipient]);
|
|
792
|
+
}
|
|
793
|
+
function stargateComposeSendParam(c) {
|
|
794
|
+
const { source, destination } = c.bridge;
|
|
795
|
+
return Object.freeze({
|
|
796
|
+
dstEid: destination.eid,
|
|
797
|
+
to: (0, import_viem8.pad)(LIFI_ETHEREUM_COMPOSER.receiver, { size: 32 }),
|
|
798
|
+
amountLD: c.bridge.amount,
|
|
799
|
+
minAmountLD: sourceMinimum(c.bridge.minimum, source.localDecimals, destination.localDecimals, source.sharedDecimals),
|
|
800
|
+
extraOptions: stargateComposeOptions(c.gas),
|
|
801
|
+
composeMsg: stargateComposeMessage(c),
|
|
802
|
+
oftCmd: "0x"
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
function stargateComposeProof(c, bridge) {
|
|
806
|
+
const composeMsg = stargateComposeMessage(c);
|
|
807
|
+
const message = (0, import_viem8.encodePacked)(["uint64", "uint32", "uint256", "bytes32", "bytes"], [bridge.nonce, c.bridge.source.eid, bridge.amount, (0, import_viem8.pad)(c.bridge.sender, { size: 32 }), composeMsg]);
|
|
808
|
+
return Object.freeze({
|
|
809
|
+
bridge,
|
|
810
|
+
transactionId: c.transactionId,
|
|
811
|
+
message,
|
|
812
|
+
messageHash: (0, import_viem8.keccak256)(message),
|
|
813
|
+
recipient: c.recipient,
|
|
814
|
+
finalToken: c.finalToken,
|
|
815
|
+
minimum: c.minReturn,
|
|
816
|
+
swap: Object.freeze({ callTo: (0, import_viem8.getAddress)(COMPOSE_DEX_PINS.router), fromAmount: c.bridge.minimum }),
|
|
817
|
+
executionSupported: true
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
function stargateComposeRetryGas(c, recoverGas) {
|
|
821
|
+
const floor = recoverGas + MIN_SWAP_GAS;
|
|
822
|
+
return (c.gas > floor ? c.gas : floor) + RETRY_OVERHEAD;
|
|
823
|
+
}
|
|
824
|
+
async function checkStargateComposer(client, destination, blockNumber) {
|
|
825
|
+
assertStargate(await client.getChainId() === 1 && destination.chain === STARGATE_COMPOSE_CHAIN, "wrong compose chain");
|
|
826
|
+
const pins = LIFI_ETHEREUM_COMPOSER;
|
|
827
|
+
for (const [address2, expected] of [[pins.receiver, pins.receiverCodeHash], [pins.executor, pins.executorCodeHash], [COMPOSE_DEX_PINS.router, COMPOSE_DEX_PINS.routerCodeHash], [COMPOSE_DEX_PINS.factory, COMPOSE_DEX_PINS.factoryCodeHash]]) {
|
|
828
|
+
const code = await client.getCode({ address: address2, blockNumber });
|
|
829
|
+
assertStargate(code && (0, import_viem8.keccak256)(code) === expected, "compose contract bytecode changed");
|
|
830
|
+
}
|
|
831
|
+
const at = { address: pins.receiver, abi: LIFI_COMPOSE_ABI, blockNumber };
|
|
832
|
+
const [executor, endpoint, messaging, recoverGas] = await Promise.all([
|
|
833
|
+
client.readContract({ ...at, functionName: "executor" }),
|
|
834
|
+
client.readContract({ ...at, functionName: "endpointV2" }),
|
|
835
|
+
client.readContract({ ...at, functionName: "tokenMessaging" }),
|
|
836
|
+
client.readContract({ ...at, functionName: "recoverGas" })
|
|
837
|
+
]);
|
|
838
|
+
assertStargate(sameAddress(executor, pins.executor) && sameAddress(endpoint, destination.endpoint) && sameAddress(messaging, destination.tokenMessaging), "composer wiring changed");
|
|
839
|
+
assertStargate(recoverGas + MIN_SWAP_GAS <= MAX_COMPOSE_GAS, "composer recovery reserve is out of range");
|
|
840
|
+
return { recoverGas };
|
|
841
|
+
}
|
|
842
|
+
async function quoteStargateComposeSwap(client, blockNumber, input, output, amount) {
|
|
843
|
+
const factory = (0, import_viem8.getAddress)(COMPOSE_DEX_PINS.factory);
|
|
844
|
+
const legs = COMPOSE_INTERMEDIATES.filter((mid) => !sameAddress(mid, input) && !sameAddress(mid, output)).flatMap((mid) => FEE_TIERS.flatMap((fee) => [[input, mid, fee], [mid, output, fee]]));
|
|
845
|
+
const pools = await client.multicall({
|
|
846
|
+
multicallAddress: MULTICALL3,
|
|
847
|
+
batchSize: ONE_BATCH,
|
|
848
|
+
blockNumber,
|
|
849
|
+
allowFailure: false,
|
|
850
|
+
contracts: legs.map(([a, b, fee]) => ({ address: factory, abi: COMPOSE_POOL_ABI, functionName: "getPool", args: [a, b, fee] }))
|
|
851
|
+
});
|
|
852
|
+
const pool = new Map(legs.map(([a, b, fee], i) => [`${a}:${b}:${fee}`, pools[i]]));
|
|
853
|
+
const paths2 = [];
|
|
854
|
+
for (const mid of COMPOSE_INTERMEDIATES) for (const f0 of FEE_TIERS) for (const f1 of FEE_TIERS) {
|
|
855
|
+
const p0 = pool.get(`${input}:${mid}:${f0}`), p1 = pool.get(`${mid}:${output}:${f1}`);
|
|
856
|
+
if (p0 && p1 && nonzeroAddress(p0) && nonzeroAddress(p1)) paths2.push({ mid, fees: [f0, f1], pools: [p0, p1] });
|
|
857
|
+
}
|
|
858
|
+
assertStargate(paths2.length, "no two-pool Uniswap V3 path for the requested output");
|
|
859
|
+
let best = -1, out = 0n;
|
|
860
|
+
for (let start = 0; start < paths2.length; start += QUOTE_GROUP) {
|
|
861
|
+
const group = paths2.slice(start, start + QUOTE_GROUP);
|
|
862
|
+
const quotes = await client.multicall({
|
|
863
|
+
multicallAddress: MULTICALL3,
|
|
864
|
+
batchSize: ONE_BATCH,
|
|
865
|
+
blockNumber,
|
|
866
|
+
allowFailure: true,
|
|
867
|
+
contracts: group.map((p2) => ({ address: UNISWAP_V3_QUOTER_V2, abi: QUOTER_ABI, functionName: "quoteExactInput", args: [(0, import_viem8.encodePacked)(["address", "uint24", "address", "uint24", "address"], [input, p2.fees[0], p2.mid, p2.fees[1], output]), amount] }))
|
|
868
|
+
});
|
|
869
|
+
quotes.forEach((q, i) => {
|
|
870
|
+
if (q.status === "success" && q.result[0] > out) {
|
|
871
|
+
out = q.result[0];
|
|
872
|
+
best = start + i;
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
assertStargate(best >= 0 && out > 0n, "no Uniswap V3 path can fill the bridged amount");
|
|
877
|
+
const p = paths2[best], word = (address2, from, to) => BigInt(address2) | V32 | (BigInt(from) < BigInt(to) ? ZERO_FOR_ONE2 : 0n);
|
|
878
|
+
return { dex: Object.freeze([word(p.pools[0], input, p.mid) | NO_WRAP2, word(p.pools[1], p.mid, output)]), amountOut: out };
|
|
879
|
+
}
|
|
880
|
+
async function quoteIntentPath(client, blockNumber, c) {
|
|
881
|
+
const { fees, tokens } = await unoswap2V3Path(client, blockNumber, c.bridge.destination.token, c.dex, c.finalToken);
|
|
882
|
+
const path = (0, import_viem8.encodePacked)(["address", "uint24", "address", "uint24", "address"], [tokens[0], fees[0], tokens[1], fees[1], tokens[2]]);
|
|
883
|
+
const [amountOut] = await client.readContract({ address: UNISWAP_V3_QUOTER_V2, abi: QUOTER_ABI, functionName: "quoteExactInput", args: [path, c.bridge.minimum], blockNumber });
|
|
884
|
+
return amountOut;
|
|
885
|
+
}
|
|
886
|
+
function checkedStargateComposeQuote(q, registry) {
|
|
887
|
+
const compose = parseStargateComposeIntent(q.intentId, registry), { source, destination, sender, amount, minimum } = compose.bridge;
|
|
888
|
+
const { tx, cap } = checkedStargateSource(q, source, destination, amount, "compose");
|
|
889
|
+
assertStargate(q.minDestAmount === String(compose.minReturn), "quote identity mismatch");
|
|
890
|
+
const sendParam = stargateComposeSendParam(compose);
|
|
891
|
+
const expected = (0, import_viem8.encodeFunctionData)({ abi: STARGATE_ABI, functionName: "sendToken", args: [sendParam, { nativeFee: cap, lzTokenFee: 0n }, sender] });
|
|
892
|
+
assertStargate(tx.data.toLowerCase() === expected.toLowerCase(), "calldata differs from the reviewed intent");
|
|
893
|
+
assertStargate(/^[0-9]{1,78}$/.test(q.destAmount) && BigInt(q.destAmount) >= compose.minReturn, "invalid quoted output");
|
|
894
|
+
checkedStargateAccounting(q, source, destination, amount, cap, minimum);
|
|
895
|
+
assertStargate(q.providerData.nativeDrop === "0", "native drop display mismatch");
|
|
896
|
+
return { compose, sendParam, cap, tx };
|
|
897
|
+
}
|
|
898
|
+
function createStargateComposer(config) {
|
|
899
|
+
const registry = config.registry ?? stargateRegistry;
|
|
900
|
+
const rpc = stargateRpc(config), quoter = createStargateQuoter(config);
|
|
901
|
+
const swapGas = config.compose?.swapGas ?? COMPOSE_SWAP_GAS;
|
|
902
|
+
assertStargate(typeof swapGas === "bigint" && swapGas >= MIN_SWAP_GAS && swapGas <= MAX_COMPOSE_GAS, "invalid compose swap gas");
|
|
903
|
+
const bridged = (chain, token) => {
|
|
904
|
+
const source = registry.find(chain, token);
|
|
905
|
+
const destination = source && registry.deployments.find((d) => d.chain === STARGATE_COMPOSE_CHAIN && d.assetId === source.assetId);
|
|
906
|
+
return source && destination && source.kind !== "native" && destination.kind !== "native" && registry.route(source.chain, source.token, destination.chain, destination.token) ? { source, destination } : void 0;
|
|
907
|
+
};
|
|
908
|
+
function supportsRoute(sourceChain, sourceToken, destinationChain, finalToken) {
|
|
909
|
+
const route = destinationChain === STARGATE_COMPOSE_CHAIN ? bridged(sourceChain, sourceToken) : void 0;
|
|
910
|
+
return !!route && nonzeroAddress(finalToken) && !sameAddress(finalToken, route.destination.token) && stargateChainActive(sourceChain) && stargateChainActive(STARGATE_COMPOSE_CHAIN) && rpc.has(sourceChain) && rpc.has(STARGATE_COMPOSE_CHAIN);
|
|
911
|
+
}
|
|
912
|
+
async function quote(request, signal) {
|
|
913
|
+
try {
|
|
914
|
+
const r = { ...request };
|
|
915
|
+
const route = bridged(r.sourceChain, r.sourceToken);
|
|
916
|
+
assertStargate(route && supportsRoute(r.sourceChain, r.sourceToken, STARGATE_COMPOSE_CHAIN, r.finalToken), "unsupported compose route");
|
|
917
|
+
assertStargate(nonzeroAddress(r.sender) && nonzeroAddress(r.recipient), "sender and recipient must be nonzero EVM addresses");
|
|
918
|
+
const slippage = r.slippageBps ?? 0, minimum = r.minimum ?? 0n;
|
|
919
|
+
assertStargate(Number.isInteger(slippage) && slippage >= 0 && slippage < 1e4 && typeof minimum === "bigint" && minimum >= 0n && minimum < 1n << 256n, "invalid slippage or minimum");
|
|
920
|
+
const { source, destination } = route, recipient = (0, import_viem8.getAddress)(r.recipient), finalToken = (0, import_viem8.getAddress)(r.finalToken);
|
|
921
|
+
const eth = rpc.client(STARGATE_COMPOSE_CHAIN, signal), block = await rpc.snapshot(eth, 1);
|
|
922
|
+
const { recoverGas } = await checkStargateComposer(eth, destination, block.number);
|
|
923
|
+
const gas = recoverGas + swapGas;
|
|
924
|
+
assertStargate(gas <= MAX_COMPOSE_GAS, "compose gas exceeds the cap");
|
|
925
|
+
const transactionId = (0, import_viem8.toHex)(globalThis.crypto.getRandomValues(new Uint8Array(32)));
|
|
926
|
+
let built, amountOut = 0n;
|
|
927
|
+
const q = await quoter.quote({
|
|
928
|
+
sourceChain: source.chain,
|
|
929
|
+
sourceToken: source.token,
|
|
930
|
+
destinationChain: destination.chain,
|
|
931
|
+
destinationToken: destination.token,
|
|
932
|
+
sender: r.sender,
|
|
933
|
+
recipient: LIFI_ETHEREUM_COMPOSER.receiver,
|
|
934
|
+
amount: r.amount,
|
|
935
|
+
mode: "taxi",
|
|
936
|
+
compose: { gas, async message(received, s) {
|
|
937
|
+
const swap = await quoteStargateComposeSwap(rpc.client(STARGATE_COMPOSE_CHAIN, s), block.number, destination.token, finalToken, received);
|
|
938
|
+
const floor = (swap.amountOut * BigInt(1e4 - slippage) + 9999n) / 10000n, minReturn = minimum > floor ? minimum : floor;
|
|
939
|
+
assertStargate(minReturn > 0n && minReturn <= swap.amountOut, "output is below the caller's minimum");
|
|
940
|
+
amountOut = swap.amountOut;
|
|
941
|
+
built = { bridge: { source, destination, mode: "taxi", sender: (0, import_viem8.getAddress)(r.sender), recipient: LIFI_ETHEREUM_COMPOSER.receiver, amount: r.amount, minimum: received, nativeDrop: 0n }, recipient, finalToken, dex: swap.dex, minReturn, gas, transactionId };
|
|
942
|
+
return stargateComposeMessage(built);
|
|
943
|
+
} }
|
|
944
|
+
}, signal);
|
|
945
|
+
assertStargate(built && q.minimumDestinationAmount === built.bridge.minimum && q.destinationAmount === built.bridge.minimum, "bridge output is not exact");
|
|
946
|
+
await rpc.unchanged(eth, block);
|
|
947
|
+
assertNotAborted(signal);
|
|
948
|
+
const intent = Object.freeze({ ...built, bridge: Object.freeze(built.bridge) });
|
|
949
|
+
const data = (0, import_viem8.encodeFunctionData)({ abi: STARGATE_ABI, functionName: "sendToken", args: [stargateComposeSendParam(intent), { nativeFee: q.messagingFeeCap, lzTokenFee: 0n }, q.sender] });
|
|
950
|
+
assertStargate(data === (0, import_viem8.encodeFunctionData)({ abi: STARGATE_ABI, functionName: "sendToken", args: [q.sendParam, { nativeFee: q.messagingFeeCap, lzTokenFee: 0n }, q.sender] }), "compose encoding drifted");
|
|
951
|
+
const out = {
|
|
952
|
+
provider: "stargate",
|
|
953
|
+
routeId: "compose",
|
|
954
|
+
intentId: stargateComposeIntentId(intent),
|
|
955
|
+
depositAddress: "",
|
|
956
|
+
depositMemo: null,
|
|
957
|
+
sourceAmount: String(r.amount),
|
|
958
|
+
destAmount: String(amountOut),
|
|
959
|
+
minDestAmount: String(intent.minReturn),
|
|
960
|
+
txRequest: { to: source.address, data, value: String(q.nativeValue), nativeFee: String(q.messagingFeeCap), chainId: source.chainId, ...source.approvalRequired ? { approvalAddress: source.address } : {} },
|
|
961
|
+
feeUsd: 0,
|
|
962
|
+
etaSeconds: null,
|
|
963
|
+
reliability: 0.85,
|
|
964
|
+
validUntilMs: q.validUntilMs,
|
|
965
|
+
fees: stargateFees(source, q.protocolFee, q.messagingFeeCap),
|
|
966
|
+
providerData: {
|
|
967
|
+
sentAmount: String(q.sentAmount),
|
|
968
|
+
dust: String(q.dust),
|
|
969
|
+
protocolFee: String(q.protocolFee),
|
|
970
|
+
protocolReward: String(q.protocolReward),
|
|
971
|
+
messagingFee: String(q.messagingFee),
|
|
972
|
+
nativeDrop: "0",
|
|
973
|
+
sourceBlock: String(q.sourceBlock.number),
|
|
974
|
+
sourceBlockHash: q.sourceBlock.hash,
|
|
975
|
+
destinationBlock: String(block.number),
|
|
976
|
+
destinationBlockHash: block.hash,
|
|
977
|
+
bridgedAmount: String(intent.bridge.minimum),
|
|
978
|
+
bridgedToken: destination.token,
|
|
979
|
+
composer: LIFI_ETHEREUM_COMPOSER.receiver,
|
|
980
|
+
composeGas: String(gas),
|
|
981
|
+
recoverGas: String(recoverGas),
|
|
982
|
+
liquidityReserved: "false",
|
|
983
|
+
feeUsdKnown: "false",
|
|
984
|
+
sourceGas: "unknown",
|
|
985
|
+
approvalGas: "unknown"
|
|
986
|
+
}
|
|
987
|
+
};
|
|
988
|
+
checkedStargateComposeQuote(out, registry);
|
|
989
|
+
return out;
|
|
990
|
+
} catch (error) {
|
|
991
|
+
throw safeReadError(error);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
async function verifyBuild(c, cap) {
|
|
995
|
+
const b = c.bridge;
|
|
996
|
+
const fresh = await quoter.quote({
|
|
997
|
+
sourceChain: b.source.chain,
|
|
998
|
+
sourceToken: b.source.token,
|
|
999
|
+
destinationChain: b.destination.chain,
|
|
1000
|
+
destinationToken: b.destination.token,
|
|
1001
|
+
sender: b.sender,
|
|
1002
|
+
recipient: b.recipient,
|
|
1003
|
+
amount: b.amount,
|
|
1004
|
+
mode: "taxi",
|
|
1005
|
+
compose: { gas: c.gas, message: async (received) => {
|
|
1006
|
+
assertStargate(received === b.minimum, "bridge output changed");
|
|
1007
|
+
return stargateComposeMessage(c);
|
|
1008
|
+
} }
|
|
1009
|
+
});
|
|
1010
|
+
assertStargate(fresh.messagingFee <= cap, "messaging fee exceeds the reviewed cap");
|
|
1011
|
+
const eth = rpc.client(STARGATE_COMPOSE_CHAIN), block = await rpc.snapshot(eth, 1);
|
|
1012
|
+
const { recoverGas } = await checkStargateComposer(eth, b.destination, block.number);
|
|
1013
|
+
assertStargate(c.gas >= recoverGas + MIN_SWAP_GAS, "compose gas no longer covers the swap");
|
|
1014
|
+
assertStargate(await quoteIntentPath(eth, block.number, c) >= c.minReturn, "destination price moved below the reviewed minimum");
|
|
1015
|
+
await rpc.unchanged(eth, block);
|
|
1016
|
+
}
|
|
1017
|
+
return Object.freeze({ supportsRoute, quote, verifyBuild });
|
|
1018
|
+
}
|
|
1019
|
+
//# sourceMappingURL=compose-route.cjs.map
|