@anywalletkit/protocol-swap2-usdt0 0.0.0-stage → 0.1.1
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 +95 -2
- package/dist/activity.cjs +124 -0
- package/dist/activity.cjs.map +1 -0
- package/dist/activity.d.cts +23 -0
- package/dist/activity.d.ts +23 -0
- package/dist/activity.js +14 -0
- package/dist/activity.js.map +1 -0
- package/dist/chunk-AGN4M7OO.js +56 -0
- package/dist/chunk-AGN4M7OO.js.map +1 -0
- package/dist/chunk-GYWVOGIV.js +341 -0
- package/dist/chunk-GYWVOGIV.js.map +1 -0
- package/dist/chunk-SFWB4C4U.js +68 -0
- package/dist/chunk-SFWB4C4U.js.map +1 -0
- package/dist/chunk-VFID5SVN.js +27 -0
- package/dist/chunk-VFID5SVN.js.map +1 -0
- package/dist/config.cjs +76 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +34 -0
- package/dist/config.d.ts +34 -0
- package/dist/config.js +15 -0
- package/dist/config.js.map +1 -0
- package/dist/index.cjs +485 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.cjs +472 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +17 -0
- package/dist/protocol.d.ts +17 -0
- package/dist/protocol.js +10 -0
- package/dist/protocol.js.map +1 -0
- package/dist/provider.cjs +458 -0
- package/dist/provider.cjs.map +1 -0
- package/dist/provider.d.cts +24 -0
- package/dist/provider.d.ts +24 -0
- package/dist/provider.js +13 -0
- package/dist/provider.js.map +1 -0
- package/module.json +26 -0
- package/package.json +86 -3
|
@@ -0,0 +1,472 @@
|
|
|
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/protocol.ts
|
|
21
|
+
var protocol_exports = {};
|
|
22
|
+
__export(protocol_exports, {
|
|
23
|
+
Usdt0Swap2Protocol: () => Usdt0Swap2Protocol
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(protocol_exports);
|
|
26
|
+
var import_single = require("@anywalletkit/protocol-swap2-core/swap2/single");
|
|
27
|
+
|
|
28
|
+
// src/config.ts
|
|
29
|
+
var import_util = require("@anywalletkit/protocol-swap2-core/util");
|
|
30
|
+
var LZ_ENDPOINT_A = "0x1a44076050125825900e736c501f859c50fE728c";
|
|
31
|
+
var LZ_ENDPOINT_B = "0x6F475642a6e85809B1c36Fa62763669b1b48DD5B";
|
|
32
|
+
var c = (chainId, eid, name, token, oft, endpoint, adapter = false) => ({
|
|
33
|
+
caip2: `eip155:${chainId}`,
|
|
34
|
+
chainId,
|
|
35
|
+
eid,
|
|
36
|
+
name,
|
|
37
|
+
token,
|
|
38
|
+
oft,
|
|
39
|
+
endpoint,
|
|
40
|
+
adapter
|
|
41
|
+
});
|
|
42
|
+
var USDT0_CHAINS = Object.freeze(Object.fromEntries([
|
|
43
|
+
c(1, 30101, "Ethereum", "0xdAC17F958D2ee523a2206206994597C13D831ec7", "0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee", LZ_ENDPOINT_A, true),
|
|
44
|
+
c(42161, 30110, "Arbitrum", "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", "0x14E4A1B13bf7F943c8ff7C51fb60FA964A298D92", LZ_ENDPOINT_A),
|
|
45
|
+
c(10, 30111, "OP Mainnet", "0x01bFF41798a0BcF287b996046Ca68b395DbC1071", "0xF03b4d9AC1D5d1E7c4cEf54C2A313b9fe051A0aD", LZ_ENDPOINT_A),
|
|
46
|
+
c(137, 30109, "Polygon PoS", "0xc2132D05D31c914a87C6611C10748AEb04B58e8F", "0x6BA10300f0DC58B7a1e4c0e41f5daBb7D7829e13", LZ_ENDPOINT_A),
|
|
47
|
+
c(999, 30367, "HyperEVM", "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb", "0x904861a24F30EC96ea7CFC3bE9EA4B476d237e98", "0x3A73033C0b1407574C76BdBAc67f126f6b4a9AA9"),
|
|
48
|
+
c(57073, 30339, "Ink", "0x0200C29006150606B650577BBE7B6248F58470c1", "0x1cB6De532588fCA4a21B7209DE7C456AF8434A65", "0xca29f3A6f966Cb2fc0dE625F8f325c0C46dbE958"),
|
|
49
|
+
c(80094, 30362, "Berachain", "0x779Ded0c9e1022225f8E0630b35a9b54bE713736", "0x3Dc96399109df5ceb2C226664A086140bD0379cB", LZ_ENDPOINT_B),
|
|
50
|
+
c(130, 30320, "Unichain", "0x9151434b16b9763660705744891fA906F660EcC5", "0xc07bE8994D035631c36fb4a89C918CeFB2f03EC3", LZ_ENDPOINT_B),
|
|
51
|
+
c(1329, 30280, "Sei", "0x9151434b16b9763660705744891fA906F660EcC5", "0x56Fe74A2e3b484b921c447357203431a3485CC60", LZ_ENDPOINT_A),
|
|
52
|
+
c(9745, 30383, "Plasma", "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb", "0x02ca37966753bDdDf11216B73B16C1dE756A7CF9", LZ_ENDPOINT_B),
|
|
53
|
+
c(143, 30390, "Monad", "0xe7cd86e13AC4309349F30B3435a9d337750fC82D", "0x9151434b16b9763660705744891fA906F660EcC5", LZ_ENDPOINT_B),
|
|
54
|
+
c(4326, 30398, "MegaETH", "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb", "0x9151434b16b9763660705744891fA906F660EcC5", LZ_ENDPOINT_B),
|
|
55
|
+
c(196, 30274, "X Layer", "0x779Ded0c9e1022225f8E0630b35a9b54bE713736", "0x94bcCa6BdfD6a61817aB0E960BfedE4984505554", LZ_ENDPOINT_A),
|
|
56
|
+
// 2026-10-20 (evm-chains-6 batch): docs.usdt0.to deployments, re-read on-chain (token(), approvalRequired() = false,
|
|
57
|
+
// sharedDecimals() = 6, endpoint(), peers(30110) = the Arbitrum OFT).
|
|
58
|
+
c(5e3, 30181, "Mantle", "0x779Ded0c9e1022225f8E0630b35a9b54bE713736", "0xcb768e263FB1C62214E7cab4AA8d036D76dc59CC", LZ_ENDPOINT_A),
|
|
59
|
+
c(2818, 30322, "Morph", "0xe7cd86e13AC4309349F30B3435a9d337750fC82D", "0xcb768e263FB1C62214E7cab4AA8d036D76dc59CC", LZ_ENDPOINT_B),
|
|
60
|
+
c(14, 30295, "Flare", "0xe7cd86e13AC4309349F30B3435a9d337750fC82D", "0x567287d2A9829215a37e3B88843d32f9221E7588", LZ_ENDPOINT_A)
|
|
61
|
+
].map((x) => [x.caip2, x])));
|
|
62
|
+
var USDT0_BY_EID = Object.freeze(
|
|
63
|
+
Object.fromEntries(Object.values(USDT0_CHAINS).map((x) => [x.eid, x]))
|
|
64
|
+
);
|
|
65
|
+
var LZ_SCAN_API = "https://scan.layerzero-api.com";
|
|
66
|
+
var USDT0_SYMBOLS = Object.freeze(["USDT0", "USDT", "USD\u20AE0", "USD\u20AE"]);
|
|
67
|
+
var usdt0 = {
|
|
68
|
+
supportsChain(chain) {
|
|
69
|
+
return (0, import_util.isEvm)(chain) && !!USDT0_CHAINS[`eip155:${(0, import_util.evmRef)(chain)}`];
|
|
70
|
+
},
|
|
71
|
+
supports(from, to) {
|
|
72
|
+
return from !== to && this.supportsChain(from) && this.supportsChain(to);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/provider.ts
|
|
77
|
+
var import_viem2 = require("viem");
|
|
78
|
+
|
|
79
|
+
// src/activity.ts
|
|
80
|
+
var import_activity = require("@anywalletkit/protocol-swap2-core/activity");
|
|
81
|
+
var import_viem = require("viem");
|
|
82
|
+
var SEND_ABI = (0, import_viem.parseAbi)([
|
|
83
|
+
"struct SendParam { uint32 dstEid; bytes32 to; uint256 amountLD; uint256 minAmountLD; bytes extraOptions; bytes composeMsg; bytes oftCmd; }",
|
|
84
|
+
"struct MessagingFee { uint256 nativeFee; uint256 lzTokenFee; }",
|
|
85
|
+
"function send(SendParam sp, MessagingFee fee, address refundAddress)"
|
|
86
|
+
]);
|
|
87
|
+
var USDT0_MODULE = "@anywalletkit/protocol-swap2-usdt0";
|
|
88
|
+
var USDT0_SEND = "0xc7c7f5b3";
|
|
89
|
+
var LZ_RECEIVE = "0x0c0c389e";
|
|
90
|
+
var ZERO = "0x0000000000000000000000000000000000000000";
|
|
91
|
+
function symbolFor(chain) {
|
|
92
|
+
return chain.adapter || [42161, 10, 137].includes(chain.chainId) ? "USDT" : "USDT0";
|
|
93
|
+
}
|
|
94
|
+
function sendDestination(tx) {
|
|
95
|
+
const data = tx.call?.data;
|
|
96
|
+
if (!data || data.length < 10 + 64 * 2) return null;
|
|
97
|
+
try {
|
|
98
|
+
const [sp] = (0, import_viem.decodeFunctionData)({ abi: SEND_ABI, data }).args;
|
|
99
|
+
return USDT0_BY_EID[sp.dstEid] ?? null;
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
var lc = (a) => a.toLowerCase();
|
|
105
|
+
function describeUsdt0Activity(tx, ctx) {
|
|
106
|
+
const chain = USDT0_CHAINS[tx.chain];
|
|
107
|
+
if (!chain) return null;
|
|
108
|
+
const subtitle = `USDT0 \xB7 ${(0, import_activity.chainLabel)(tx.chain)}`;
|
|
109
|
+
if ((0, import_activity.matchesCall)(tx, [chain.oft], [USDT0_SEND])) {
|
|
110
|
+
const dst = sendDestination(tx);
|
|
111
|
+
const item = (0, import_activity.describeSwapLike)(tx, ctx, { protocol: USDT0_MODULE, subtitle, kind: "bridge", outVerb: "Bridged" });
|
|
112
|
+
if (!item) return null;
|
|
113
|
+
const native = item.assetsOut.filter((a) => a.token === null).reduce((sum, a) => sum + a.amount, 0n);
|
|
114
|
+
item.assetsOut = item.assetsOut.filter((a) => a.token !== null);
|
|
115
|
+
if (native > 0n) item.fee = (item.fee ?? 0n) + native;
|
|
116
|
+
const srcSym = item.assetsOut[0]?.symbol ?? symbolFor(chain);
|
|
117
|
+
if (dst) {
|
|
118
|
+
item.title = `Bridged ${srcSym} \u2192 ${symbolFor(dst)}`;
|
|
119
|
+
item.subtitle = `USDT0 \xB7 ${(0, import_activity.chainLabel)(tx.chain)} \u2192 ${dst.name}`;
|
|
120
|
+
} else item.title = `Bridged ${srcSym}`;
|
|
121
|
+
return item;
|
|
122
|
+
}
|
|
123
|
+
if ((0, import_activity.matchesCall)(tx, [chain.endpoint], [LZ_RECEIVE])) {
|
|
124
|
+
return (0, import_activity.describeSwapLike)(tx, ctx, { protocol: USDT0_MODULE, subtitle, kind: "bridge", inSuffix: "via LayerZero" });
|
|
125
|
+
}
|
|
126
|
+
const called = (0, import_activity.calledContract)(tx);
|
|
127
|
+
if (called && called === lc(chain.token)) return null;
|
|
128
|
+
const own = new Set([...ctx.own].map(lc));
|
|
129
|
+
const origin = chain.adapter ? lc(chain.oft) : ZERO;
|
|
130
|
+
const delivered = tx.transfers.some((t) => t.token !== null && lc(t.token) === lc(chain.token) && lc(t.from) === origin && own.has(lc(t.to)));
|
|
131
|
+
if (!delivered || own.has(lc(tx.from))) return null;
|
|
132
|
+
return (0, import_activity.describeSwapLike)(tx, ctx, { protocol: USDT0_MODULE, subtitle, kind: "bridge", inSuffix: "via LayerZero", counterparty: chain.oft });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/provider.ts
|
|
136
|
+
var import_swap2_assets = require("@anywalletkit/swap2-assets");
|
|
137
|
+
var import_util2 = require("@anywalletkit/protocol-swap2-core/util");
|
|
138
|
+
var OFT_ABI = (0, import_viem2.parseAbi)([
|
|
139
|
+
"struct SendParam { uint32 dstEid; bytes32 to; uint256 amountLD; uint256 minAmountLD; bytes extraOptions; bytes composeMsg; bytes oftCmd; }",
|
|
140
|
+
"struct MessagingFee { uint256 nativeFee; uint256 lzTokenFee; }",
|
|
141
|
+
"struct OFTLimit { uint256 minAmountLD; uint256 maxAmountLD; }",
|
|
142
|
+
"struct OFTFeeDetail { int256 feeAmountLD; string description; }",
|
|
143
|
+
"struct OFTReceipt { uint256 amountSentLD; uint256 amountReceivedLD; }",
|
|
144
|
+
"struct MessagingReceipt { bytes32 guid; uint64 nonce; MessagingFee fee; }",
|
|
145
|
+
"function quoteSend(SendParam s, bool payInLzToken) view returns (MessagingFee)",
|
|
146
|
+
"function quoteOFT(SendParam s) view returns (OFTLimit, OFTFeeDetail[], OFTReceipt)",
|
|
147
|
+
"function send(SendParam s, MessagingFee fee, address refundAddress) payable returns (MessagingReceipt, OFTReceipt)",
|
|
148
|
+
"function token() view returns (address)",
|
|
149
|
+
"function approvalRequired() view returns (bool)",
|
|
150
|
+
"function peers(uint32 eid) view returns (bytes32)"
|
|
151
|
+
]);
|
|
152
|
+
var ENDPOINT_ABI = (0, import_viem2.parseAbi)([
|
|
153
|
+
"struct Origin { uint32 srcEid; bytes32 sender; uint64 nonce; }",
|
|
154
|
+
"function lzReceive(Origin origin, address receiver, bytes32 guid, bytes message, bytes extraData) payable"
|
|
155
|
+
]);
|
|
156
|
+
var EVM_PLACEHOLDER = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
157
|
+
var DEFAULT_QUOTE_TTL_MS = 6e4;
|
|
158
|
+
var RPC_TIMEOUT_MS = 12e3;
|
|
159
|
+
var SCAN_TIMEOUT_MS = 12e3;
|
|
160
|
+
var GAS_SEND = "450000";
|
|
161
|
+
var FEE_HEADROOM_BPS = 2500n;
|
|
162
|
+
var GAS_CLAIM = "300000";
|
|
163
|
+
var ZERO_B32 = `0x${"00".repeat(32)}`;
|
|
164
|
+
var same = (a, b) => !!a && a.toLowerCase() === b.toLowerCase();
|
|
165
|
+
var isHexData = (v) => typeof v === "string" && /^0x(?:[0-9a-fA-F]{2})*$/.test(v);
|
|
166
|
+
function tokenMatches(chain, symbolOrAddress) {
|
|
167
|
+
if (symbolOrAddress.startsWith("0x")) return same(symbolOrAddress, chain.token);
|
|
168
|
+
if (!USDT0_SYMBOLS.includes(symbolOrAddress.toUpperCase().replace("USD\u20AE", "USDT"))) return false;
|
|
169
|
+
const known = (0, import_swap2_assets.ccAsset)(chain.caip2, symbolOrAddress);
|
|
170
|
+
return !known || same(known.contract ?? "", chain.token);
|
|
171
|
+
}
|
|
172
|
+
function rpcSafeReason(err, chainName) {
|
|
173
|
+
const e = err;
|
|
174
|
+
const text = `${e?.shortMessage ?? ""}
|
|
175
|
+
${e?.message ?? String(err)}`;
|
|
176
|
+
if (/HttpRequestError|TimeoutError|RpcRequestError|WebSocketRequestError/.test(String(e?.name)) || /\bURL: |HTTP request failed|request timed out|took too long to respond/i.test(text)) {
|
|
177
|
+
return `usdt0: RPC for ${chainName} unavailable \u2014 try again`;
|
|
178
|
+
}
|
|
179
|
+
return (0, import_util2.redactUrls)(err instanceof Error ? err.message : String(err));
|
|
180
|
+
}
|
|
181
|
+
function usdt0Provider(config = {}) {
|
|
182
|
+
config = Object.freeze({ ...config });
|
|
183
|
+
const scan = (config.scanUrl ?? LZ_SCAN_API).replace(/\/+$/, "");
|
|
184
|
+
if (!/^https?:\/\//.test(scan)) throw new Error("usdt0: scanUrl must use http or https");
|
|
185
|
+
const quoteTtlMs = config.quoteTtlMs ?? DEFAULT_QUOTE_TTL_MS;
|
|
186
|
+
if (!Number.isInteger(quoteTtlMs) || quoteTtlMs <= 0 || quoteTtlMs > 3e5) throw new Error("usdt0: quoteTtlMs must be an integer between 1 and 300000");
|
|
187
|
+
const rpcUrls = Object.freeze({ ...config.rpcUrls ?? {} });
|
|
188
|
+
const doFetch = (input, init) => (config.fetchImpl ?? fetch)(input, init);
|
|
189
|
+
const client = (caip2) => {
|
|
190
|
+
const raw = rpcUrls[caip2];
|
|
191
|
+
const urls = typeof raw === "string" ? [raw] : [...raw ?? []];
|
|
192
|
+
if (urls.length === 0) return null;
|
|
193
|
+
const opts = { timeout: RPC_TIMEOUT_MS, ...config.fetchImpl ? { fetchFn: config.fetchImpl } : {} };
|
|
194
|
+
return (0, import_viem2.createPublicClient)({ transport: urls.length === 1 ? (0, import_viem2.http)(urls[0], opts) : (0, import_viem2.fallback)(urls.map((u) => (0, import_viem2.http)(u, opts))) });
|
|
195
|
+
};
|
|
196
|
+
const verified = /* @__PURE__ */ new Map();
|
|
197
|
+
function verifyChain(chain) {
|
|
198
|
+
let p = verified.get(chain.caip2);
|
|
199
|
+
if (!p) {
|
|
200
|
+
p = (async () => {
|
|
201
|
+
const c2 = client(chain.caip2);
|
|
202
|
+
if (!c2) throw new Error(`usdt0: no RPC for ${chain.caip2}`);
|
|
203
|
+
const [token, approval] = await Promise.all([
|
|
204
|
+
c2.readContract({ address: (0, import_viem2.getAddress)(chain.oft), abi: OFT_ABI, functionName: "token" }),
|
|
205
|
+
c2.readContract({ address: (0, import_viem2.getAddress)(chain.oft), abi: OFT_ABI, functionName: "approvalRequired" })
|
|
206
|
+
]);
|
|
207
|
+
if (!same(token, chain.token)) throw new Error(`usdt0: OFT ${chain.oft} on ${chain.name} reports token ${token}, expected ${chain.token}`);
|
|
208
|
+
if (approval !== chain.adapter) throw new Error(`usdt0: OFT ${chain.oft} on ${chain.name} reports approvalRequired=${String(approval)}, expected ${String(chain.adapter)}`);
|
|
209
|
+
})();
|
|
210
|
+
p.catch(() => verified.delete(chain.caip2));
|
|
211
|
+
verified.set(chain.caip2, p);
|
|
212
|
+
}
|
|
213
|
+
return p;
|
|
214
|
+
}
|
|
215
|
+
const peers = /* @__PURE__ */ new Map();
|
|
216
|
+
function verifyPeer(src, dst) {
|
|
217
|
+
const key = `${src.eid}>${dst.eid}`;
|
|
218
|
+
let p = peers.get(key);
|
|
219
|
+
if (!p) {
|
|
220
|
+
p = (async () => {
|
|
221
|
+
const c2 = client(src.caip2);
|
|
222
|
+
if (!c2) throw new Error(`usdt0: no RPC for ${src.caip2}`);
|
|
223
|
+
const peer = await c2.readContract({ address: (0, import_viem2.getAddress)(src.oft), abi: OFT_ABI, functionName: "peers", args: [dst.eid] });
|
|
224
|
+
if (!same(peer, (0, import_viem2.pad)((0, import_viem2.getAddress)(dst.oft), { size: 32 }))) throw new Error(`usdt0: ${src.name} OFT has no peer for ${dst.name} (eid ${dst.eid}) \u2014 route not wired`);
|
|
225
|
+
})();
|
|
226
|
+
p.catch(() => peers.delete(key));
|
|
227
|
+
peers.set(key, p);
|
|
228
|
+
}
|
|
229
|
+
return p;
|
|
230
|
+
}
|
|
231
|
+
function parseIntent(intentId) {
|
|
232
|
+
const [tag, s, d] = intentId.split(":");
|
|
233
|
+
if (tag !== "usdt0") return null;
|
|
234
|
+
const src = USDT0_BY_EID[Number(s)];
|
|
235
|
+
const dst = USDT0_BY_EID[Number(d)];
|
|
236
|
+
return src && dst && src !== dst ? { src, dst } : null;
|
|
237
|
+
}
|
|
238
|
+
const sendParam = (dstEid, recipient, amountLD, minAmountLD) => ({
|
|
239
|
+
dstEid,
|
|
240
|
+
to: (0, import_viem2.pad)((0, import_viem2.getAddress)(recipient), { size: 32 }),
|
|
241
|
+
amountLD,
|
|
242
|
+
minAmountLD,
|
|
243
|
+
extraOptions: "0x",
|
|
244
|
+
composeMsg: "0x",
|
|
245
|
+
oftCmd: "0x"
|
|
246
|
+
});
|
|
247
|
+
async function scanMessage(src, dst, sourceTxHash) {
|
|
248
|
+
const res = await doFetch(`${scan}/v1/messages/tx/${encodeURIComponent(sourceTxHash)}`, { headers: { accept: "application/json" }, signal: (0, import_util2.timeoutSignal)(SCAN_TIMEOUT_MS) });
|
|
249
|
+
if (res.status === 404) return null;
|
|
250
|
+
if (!res.ok) throw new Error(`usdt0: LayerZero Scan \u2192 ${res.status}`);
|
|
251
|
+
const body = await res.json();
|
|
252
|
+
const list = Array.isArray(body?.data) ? body.data : [];
|
|
253
|
+
if (list.length === 0) return null;
|
|
254
|
+
const m = list.find((x) => x.pathway?.srcEid === src.eid && x.pathway?.dstEid === dst.eid && same(x.pathway?.sender?.address, src.oft));
|
|
255
|
+
return m ?? "foreign";
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
name: "usdt0",
|
|
259
|
+
describeActivity: describeUsdt0Activity,
|
|
260
|
+
enabled: () => config.enabled ?? true,
|
|
261
|
+
supportsChain: (chain) => usdt0.supportsChain(chain) && client(chain) !== null,
|
|
262
|
+
supportsChainPair: (from, to) => usdt0.supports(from, to) && client(from) !== null,
|
|
263
|
+
supportsRoute(from, to) {
|
|
264
|
+
const src = USDT0_CHAINS[from.chain];
|
|
265
|
+
const dst = USDT0_CHAINS[to.chain];
|
|
266
|
+
if (!src || !dst || src === dst || client(from.chain) === null) return false;
|
|
267
|
+
return tokenMatches(src, from.token) && tokenMatches(dst, to.token);
|
|
268
|
+
},
|
|
269
|
+
async getQuote(params, signal) {
|
|
270
|
+
const refuse = (reason) => {
|
|
271
|
+
params.onRefusal?.(reason);
|
|
272
|
+
return null;
|
|
273
|
+
};
|
|
274
|
+
if (params.flex) return refuse("the amount is sealed into the calldata (no flexible deposits)");
|
|
275
|
+
const src = USDT0_CHAINS[params.sourceChain];
|
|
276
|
+
const dst = USDT0_CHAINS[params.destChain];
|
|
277
|
+
if (!src || !dst) return refuse("USDT0 is not deployed on this chain");
|
|
278
|
+
if (src === dst) return refuse("same-chain transfers are not a bridge");
|
|
279
|
+
if (!tokenMatches(src, params.sourceToken)) return refuse(`source token ${params.sourceToken} is not USDT0 (${src.token}) on ${src.name}`);
|
|
280
|
+
if (!tokenMatches(dst, params.destToken)) return refuse(`destination token ${params.destToken} is not USDT0 (${dst.token}) on ${dst.name}`);
|
|
281
|
+
if (!/^\d+$/.test(params.amountIn)) return refuse("amount must be a base-unit integer");
|
|
282
|
+
const amount = BigInt(params.amountIn);
|
|
283
|
+
if (amount <= 0n) return refuse("amount must be positive");
|
|
284
|
+
const recipient = params.destAddress || EVM_PLACEHOLDER;
|
|
285
|
+
if (!(0, import_viem2.isAddress)(recipient)) return refuse("destination must be an EVM address");
|
|
286
|
+
const refund = params.refundAddress || EVM_PLACEHOLDER;
|
|
287
|
+
if (!(0, import_viem2.isAddress)(refund)) return refuse("refund address must be an EVM address");
|
|
288
|
+
const c2 = client(src.caip2);
|
|
289
|
+
if (!c2) return refuse(`no RPC configured for ${src.caip2}`);
|
|
290
|
+
try {
|
|
291
|
+
await Promise.all([verifyChain(src), verifyPeer(src, dst)]);
|
|
292
|
+
const probe = sendParam(dst.eid, recipient, amount, 0n);
|
|
293
|
+
const [limit, feeDetails, receipt] = await c2.readContract({ address: (0, import_viem2.getAddress)(src.oft), abi: OFT_ABI, functionName: "quoteOFT", args: [probe] });
|
|
294
|
+
if (amount < limit.minAmountLD) return refuse(`amount ${amount} is below the OFT minimum ${limit.minAmountLD}`);
|
|
295
|
+
if (amount > limit.maxAmountLD) return refuse(`amount ${amount} exceeds the OFT maximum ${limit.maxAmountLD}`);
|
|
296
|
+
const received = receipt.amountReceivedLD;
|
|
297
|
+
if (received <= 0n) return refuse("amount is below the OFT dust threshold \u2014 nothing would arrive");
|
|
298
|
+
if (received > amount) return refuse("OFT reports more received than sent \u2014 refusing");
|
|
299
|
+
if (params.minAmountOut !== void 0 && received < BigInt(params.minAmountOut)) return refuse(`received ${received} is below the caller's floor ${params.minAmountOut}`);
|
|
300
|
+
const sp = sendParam(dst.eid, recipient, amount, received);
|
|
301
|
+
const fee = await c2.readContract({ address: (0, import_viem2.getAddress)(src.oft), abi: OFT_ABI, functionName: "quoteSend", args: [sp, false] });
|
|
302
|
+
if (fee.lzTokenFee !== 0n) return refuse("OFT asks for a fee in LZ token \u2014 unsupported");
|
|
303
|
+
const nativeFee = fee.nativeFee + fee.nativeFee * FEE_HEADROOM_BPS / 10000n;
|
|
304
|
+
const data = (0, import_viem2.encodeFunctionData)({ abi: OFT_ABI, functionName: "send", args: [sp, { nativeFee, lzTokenFee: 0n }, (0, import_viem2.getAddress)(refund)] });
|
|
305
|
+
const protocolFees = feeDetails.filter((f) => f.feeAmountLD > 0n).map((f) => ({ type: "protocol", amount: f.feeAmountLD.toString(), token: src.token, included: true, description: f.description || "OFT fee" }));
|
|
306
|
+
const feeUsd = protocolFees.reduce((a, f) => a + Number(f.amount) / 1e6, 0);
|
|
307
|
+
const eta = src.chainId === 1 ? 1e3 : 240;
|
|
308
|
+
return {
|
|
309
|
+
provider: "usdt0",
|
|
310
|
+
intentId: `usdt0:${src.eid}:${dst.eid}`,
|
|
311
|
+
depositAddress: "",
|
|
312
|
+
depositMemo: null,
|
|
313
|
+
txRequest: {
|
|
314
|
+
to: src.oft,
|
|
315
|
+
data,
|
|
316
|
+
value: nativeFee.toString(),
|
|
317
|
+
chainId: src.chainId,
|
|
318
|
+
gasLimit: GAS_SEND,
|
|
319
|
+
...src.adapter ? { approvalAddress: src.oft } : {},
|
|
320
|
+
...nativeFee > 0n ? { nativeFee: nativeFee.toString() } : {}
|
|
321
|
+
},
|
|
322
|
+
sourceAmount: amount.toString(),
|
|
323
|
+
destAmount: received.toString(),
|
|
324
|
+
minDestAmount: received.toString(),
|
|
325
|
+
feeUsd,
|
|
326
|
+
fees: protocolFees,
|
|
327
|
+
etaSeconds: eta,
|
|
328
|
+
reliability: 0.98,
|
|
329
|
+
validUntilMs: Date.now() + quoteTtlMs,
|
|
330
|
+
providerData: {
|
|
331
|
+
srcEid: String(src.eid),
|
|
332
|
+
dstEid: String(dst.eid),
|
|
333
|
+
oft: src.oft,
|
|
334
|
+
token: src.token,
|
|
335
|
+
recipient: (0, import_viem2.getAddress)(recipient),
|
|
336
|
+
refundAddress: (0, import_viem2.getAddress)(refund),
|
|
337
|
+
amountLD: amount.toString(),
|
|
338
|
+
minAmountLD: received.toString(),
|
|
339
|
+
nativeFee: nativeFee.toString()
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
} catch (err) {
|
|
343
|
+
return refuse(rpcSafeReason(err, src.name));
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
async buildDeposit(quote) {
|
|
347
|
+
const tx = quote.txRequest;
|
|
348
|
+
const parsed = parseIntent(quote.intentId);
|
|
349
|
+
if (!tx || !parsed) throw new Error("swap2: USDT0 quote has no transaction request");
|
|
350
|
+
return {
|
|
351
|
+
chain: parsed.src.caip2,
|
|
352
|
+
to: tx.to ?? "",
|
|
353
|
+
value: tx.value ?? "0",
|
|
354
|
+
...tx.data ? { data: tx.data } : {},
|
|
355
|
+
...tx.chainId !== void 0 ? { chainId: tx.chainId } : {},
|
|
356
|
+
...tx.gasLimit ? { gasLimit: tx.gasLimit } : {},
|
|
357
|
+
...tx.approvalAddress ? { approvalAddress: tx.approvalAddress } : {}
|
|
358
|
+
};
|
|
359
|
+
},
|
|
360
|
+
/**
|
|
361
|
+
* Right before signing: the target is the source OFT, the peer is still the
|
|
362
|
+
* destination OFT, and the CURRENT LayerZero fee still fits the sealed
|
|
363
|
+
* `msg.value` (quote + headroom) — the endpoint reverts a send that
|
|
364
|
+
* underpays, so a fee past the headroom means re-quote rather than a
|
|
365
|
+
* wasted broadcast.
|
|
366
|
+
*/
|
|
367
|
+
async preflightDeposit(quote, tx) {
|
|
368
|
+
const parsed = parseIntent(quote.intentId);
|
|
369
|
+
if (!parsed) throw new Error("usdt0: malformed intent id");
|
|
370
|
+
const { src, dst } = parsed;
|
|
371
|
+
if (!same(tx.to, src.oft)) throw new Error(`usdt0: deposit target ${tx.to} is not the ${src.name} OFT`);
|
|
372
|
+
const pd = quote.providerData ?? {};
|
|
373
|
+
if (!/^\d+$/.test(pd.amountLD ?? "") || !/^\d+$/.test(pd.minAmountLD ?? "") || !/^\d+$/.test(pd.nativeFee ?? "") || !(0, import_viem2.isAddress)(pd.recipient ?? "")) {
|
|
374
|
+
throw new Error("usdt0: quote carries no sealed send parameters");
|
|
375
|
+
}
|
|
376
|
+
const c2 = client(src.caip2);
|
|
377
|
+
if (!c2) throw new Error(`usdt0: no RPC for ${src.caip2}`);
|
|
378
|
+
const sp = sendParam(dst.eid, pd.recipient, BigInt(pd.amountLD), BigInt(pd.minAmountLD));
|
|
379
|
+
let fee;
|
|
380
|
+
try {
|
|
381
|
+
await Promise.all([verifyChain(src), verifyPeer(src, dst)]);
|
|
382
|
+
fee = await c2.readContract({ address: (0, import_viem2.getAddress)(src.oft), abi: OFT_ABI, functionName: "quoteSend", args: [sp, false] });
|
|
383
|
+
} catch (err) {
|
|
384
|
+
throw new Error(rpcSafeReason(err, src.name));
|
|
385
|
+
}
|
|
386
|
+
const sealed = BigInt(pd.nativeFee);
|
|
387
|
+
if (fee.nativeFee > sealed) throw new Error(`usdt0: LayerZero fee rose to ${fee.nativeFee} above the sealed ${sealed} (quote + ${FEE_HEADROOM_BPS / 100n} % headroom) \u2014 re-quote`);
|
|
388
|
+
if (BigInt(tx.value) !== sealed) throw new Error(`usdt0: transaction value ${tx.value} is not the quoted fee ${sealed}`);
|
|
389
|
+
},
|
|
390
|
+
async trackIntent(ref) {
|
|
391
|
+
const parsed = parseIntent(ref.intentId);
|
|
392
|
+
if (!parsed) return { state: "failed" };
|
|
393
|
+
const { src, dst } = parsed;
|
|
394
|
+
if (!ref.sourceTxHash) return { state: "pending" };
|
|
395
|
+
try {
|
|
396
|
+
const m = await scanMessage(src, dst, ref.sourceTxHash);
|
|
397
|
+
if (m === null) return { state: "pending", depositReceived: false };
|
|
398
|
+
if (m === "foreign") return { state: "failed" };
|
|
399
|
+
const name = (m.status?.name ?? "").toUpperCase();
|
|
400
|
+
const destHash = m.destination?.tx?.txHash;
|
|
401
|
+
if (name === "DELIVERED") return { state: "completed", depositReceived: true, ...destHash ? { destTxHash: destHash } : ref.destTxHash ? { destTxHash: ref.destTxHash } : {} };
|
|
402
|
+
if (name === "PAYLOAD_STORED") return { state: "action-required", depositReceived: true, claim: { chain: dst.caip2, ready: true } };
|
|
403
|
+
if (["FAILED", "APPLICATION_BURNED", "APPLICATION_SKIPPED", "UNRESOLVABLE_COMMAND", "MALFORMED_COMMAND"].includes(name)) return { state: "failed", depositReceived: true };
|
|
404
|
+
return { state: "pending", depositReceived: true };
|
|
405
|
+
} catch {
|
|
406
|
+
return { state: "pending" };
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
/**
|
|
410
|
+
* A delivery that reverted on the destination (PAYLOAD_STORED — out of
|
|
411
|
+
* executor gas, paused token) is retried by anyone through the endpoint:
|
|
412
|
+
* `lzReceive(origin, receiver, guid, message, extraData)` with the exact
|
|
413
|
+
* packet LayerZero Scan recorded. Null while nothing is stored.
|
|
414
|
+
*/
|
|
415
|
+
async buildClaim(ref) {
|
|
416
|
+
const parsed = parseIntent(ref.intentId);
|
|
417
|
+
if (!parsed || !ref.sourceTxHash) return null;
|
|
418
|
+
const { src, dst } = parsed;
|
|
419
|
+
const m = await scanMessage(src, dst, ref.sourceTxHash);
|
|
420
|
+
if (!m || m === "foreign" || (m.status?.name ?? "").toUpperCase() !== "PAYLOAD_STORED") return null;
|
|
421
|
+
const nonce = m.pathway?.nonce;
|
|
422
|
+
const guid = m.guid;
|
|
423
|
+
const message = m.source?.tx?.payload;
|
|
424
|
+
if (!Number.isInteger(nonce) || !isHexData(guid) || guid.length !== 66 || !isHexData(message) || message.length <= 2) {
|
|
425
|
+
throw new Error("usdt0: LayerZero Scan has no complete packet for the stored payload");
|
|
426
|
+
}
|
|
427
|
+
if (!same(m.pathway?.receiver?.address, dst.oft)) throw new Error("usdt0: stored payload is addressed to another receiver");
|
|
428
|
+
const valueRaw = m.source?.tx?.options?.lzReceive?.value ?? "0";
|
|
429
|
+
const value = /^\d+$/.test(valueRaw) ? valueRaw : "0";
|
|
430
|
+
return {
|
|
431
|
+
chain: dst.caip2,
|
|
432
|
+
to: dst.endpoint,
|
|
433
|
+
value,
|
|
434
|
+
data: (0, import_viem2.encodeFunctionData)({
|
|
435
|
+
abi: ENDPOINT_ABI,
|
|
436
|
+
functionName: "lzReceive",
|
|
437
|
+
args: [{ srcEid: src.eid, sender: (0, import_viem2.pad)((0, import_viem2.getAddress)(src.oft), { size: 32 }), nonce: BigInt(nonce) }, (0, import_viem2.getAddress)(dst.oft), guid, message, "0x"]
|
|
438
|
+
}),
|
|
439
|
+
chainId: dst.chainId,
|
|
440
|
+
gasLimit: GAS_CLAIM
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
var USDT0_STATUS_MAP = Object.freeze({
|
|
446
|
+
INFLIGHT: "pending",
|
|
447
|
+
CONFIRMING: "pending",
|
|
448
|
+
BLOCKED: "pending",
|
|
449
|
+
DELIVERED: "completed",
|
|
450
|
+
PAYLOAD_STORED: "action-required",
|
|
451
|
+
FAILED: "failed",
|
|
452
|
+
APPLICATION_BURNED: "failed",
|
|
453
|
+
APPLICATION_SKIPPED: "failed",
|
|
454
|
+
UNRESOLVABLE_COMMAND: "failed",
|
|
455
|
+
MALFORMED_COMMAND: "failed"
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
// src/protocol.ts
|
|
459
|
+
var Usdt0Swap2Protocol = class extends import_single.SingleProviderSwap2 {
|
|
460
|
+
provider;
|
|
461
|
+
constructor(account, config) {
|
|
462
|
+
super(account, config);
|
|
463
|
+
this.provider = usdt0Provider(config);
|
|
464
|
+
}
|
|
465
|
+
chainSupported(caip2) {
|
|
466
|
+
return usdt0.supportsChain(caip2);
|
|
467
|
+
}
|
|
468
|
+
pairSupported(fromChain, toChain) {
|
|
469
|
+
return usdt0.supports(fromChain, toChain);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
//# sourceMappingURL=protocol.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts","../src/config.ts","../src/provider.ts","../src/activity.ts"],"sourcesContent":["import {SingleProviderSwap2} from \"@anywalletkit/protocol-swap2-core/swap2/single\";\nimport type {Swap2Account, Swap2EngineConfig} from \"@anywalletkit/protocol-swap2-core/swap2/base\";\nimport {usdt0 as usdt0Cfg} from \"./config.js\";\nimport {usdt0Provider, type Usdt0ProviderConfig} from \"./provider.js\";\n\nexport interface Usdt0Swap2Config extends Swap2EngineConfig, Usdt0ProviderConfig {}\n\n/** Standalone USDT0 swap2: USDT / USDT0 between the LayerZero OFT deployments in one source transaction. */\nexport class Usdt0Swap2Protocol extends SingleProviderSwap2 {\n protected readonly provider;\n constructor(account: Swap2Account | undefined, config: Usdt0Swap2Config) {\n super(account, config);\n this.provider = usdt0Provider(config);\n }\n protected override chainSupported(caip2: string): boolean {\n return usdt0Cfg.supportsChain(caip2);\n }\n protected override pairSupported(fromChain: string, toChain: string): boolean {\n return usdt0Cfg.supports(fromChain, toChain);\n }\n}\n","// USDT0 — Tether's LayerZero OFT for USDT. Source: docs.usdt0.to\n// (technical-documentation/deployments, read 2026-10-20) — every row below was\n// then re-read on-chain over public RPCs the same day: the OFT's `token()` is\n// the listed token, `endpoint()` is the listed endpoint (and reports the\n// listed eid), `approvalRequired()` is true only for the Ethereum adapter,\n// `sharedDecimals()` = 6 everywhere, and `peers(eid)` are wired between the\n// chains. `oftVersion()` = (0x02e49c2c, 1) on all of them.\n//\n// Only chains the SDK ships (swap2-assets / wallet-evm) are listed. USDT0 is\n// also deployed on Conflux eSpace (1030, eid 30212), Flare (14, 30295),\n// Hedera (295, 30316), Mantle (5000, 30181), Morph (2818, 30322), Rootstock\n// (30, 30333), Stable (988, 30396), Tempo (4217, 30410), plus HyperCore, IOTA\n// and Stellar (non-EVM) — not wallet chains here, so not routable here.\nimport {evmRef, isEvm} from \"@anywalletkit/protocol-swap2-core/util\";\n\nexport interface Usdt0Chain {\n caip2: string;\n chainId: number;\n /** LayerZero V2 endpoint id. */\n eid: number;\n name: string;\n /** The ERC-20 the user holds: USDT on Ethereum, USDT0 elsewhere (6 decimals everywhere). */\n token: string;\n /**\n * The OFT contract `quoteSend` / `send` are called on. On Ethereum it is the\n * OFT *adapter* that locks USDT (`approvalRequired()` = true, approve the\n * token to it); elsewhere it is the OUpgradeable OFT that burns the caller's\n * USDT0 through the token's mint/burn role — no approval.\n */\n oft: string;\n /** LayerZero V2 EndpointV2 on that chain (`lzReceive` retries of a stored payload go here). */\n endpoint: string;\n /** True on Ethereum: the OFT is a lockbox adapter in front of plain USDT. */\n adapter: boolean;\n}\n\nconst LZ_ENDPOINT_A = \"0x1a44076050125825900e736c501f859c50fE728c\";\nconst LZ_ENDPOINT_B = \"0x6F475642a6e85809B1c36Fa62763669b1b48DD5B\";\n\nconst c = (chainId: number, eid: number, name: string, token: string, oft: string, endpoint: string, adapter = false): Usdt0Chain => ({\n caip2: `eip155:${chainId}`, chainId, eid, name, token, oft, endpoint, adapter,\n});\n\n/** CAIP-2 → USDT0 deployment. */\nexport const USDT0_CHAINS: Readonly<Record<string, Usdt0Chain>> = Object.freeze(Object.fromEntries([\n c(1, 30101, \"Ethereum\", \"0xdAC17F958D2ee523a2206206994597C13D831ec7\", \"0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee\", LZ_ENDPOINT_A, true),\n c(42161, 30110, \"Arbitrum\", \"0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9\", \"0x14E4A1B13bf7F943c8ff7C51fb60FA964A298D92\", LZ_ENDPOINT_A),\n c(10, 30111, \"OP Mainnet\", \"0x01bFF41798a0BcF287b996046Ca68b395DbC1071\", \"0xF03b4d9AC1D5d1E7c4cEf54C2A313b9fe051A0aD\", LZ_ENDPOINT_A),\n c(137, 30109, \"Polygon PoS\", \"0xc2132D05D31c914a87C6611C10748AEb04B58e8F\", \"0x6BA10300f0DC58B7a1e4c0e41f5daBb7D7829e13\", LZ_ENDPOINT_A),\n c(999, 30367, \"HyperEVM\", \"0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb\", \"0x904861a24F30EC96ea7CFC3bE9EA4B476d237e98\", \"0x3A73033C0b1407574C76BdBAc67f126f6b4a9AA9\"),\n c(57073, 30339, \"Ink\", \"0x0200C29006150606B650577BBE7B6248F58470c1\", \"0x1cB6De532588fCA4a21B7209DE7C456AF8434A65\", \"0xca29f3A6f966Cb2fc0dE625F8f325c0C46dbE958\"),\n c(80094, 30362, \"Berachain\", \"0x779Ded0c9e1022225f8E0630b35a9b54bE713736\", \"0x3Dc96399109df5ceb2C226664A086140bD0379cB\", LZ_ENDPOINT_B),\n c(130, 30320, \"Unichain\", \"0x9151434b16b9763660705744891fA906F660EcC5\", \"0xc07bE8994D035631c36fb4a89C918CeFB2f03EC3\", LZ_ENDPOINT_B),\n c(1329, 30280, \"Sei\", \"0x9151434b16b9763660705744891fA906F660EcC5\", \"0x56Fe74A2e3b484b921c447357203431a3485CC60\", LZ_ENDPOINT_A),\n c(9745, 30383, \"Plasma\", \"0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb\", \"0x02ca37966753bDdDf11216B73B16C1dE756A7CF9\", LZ_ENDPOINT_B),\n c(143, 30390, \"Monad\", \"0xe7cd86e13AC4309349F30B3435a9d337750fC82D\", \"0x9151434b16b9763660705744891fA906F660EcC5\", LZ_ENDPOINT_B),\n c(4326, 30398, \"MegaETH\", \"0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb\", \"0x9151434b16b9763660705744891fA906F660EcC5\", LZ_ENDPOINT_B),\n c(196, 30274, \"X Layer\", \"0x779Ded0c9e1022225f8E0630b35a9b54bE713736\", \"0x94bcCa6BdfD6a61817aB0E960BfedE4984505554\", LZ_ENDPOINT_A),\n // 2026-10-20 (evm-chains-6 batch): docs.usdt0.to deployments, re-read on-chain (token(), approvalRequired() = false,\n // sharedDecimals() = 6, endpoint(), peers(30110) = the Arbitrum OFT).\n c(5000, 30181, \"Mantle\", \"0x779Ded0c9e1022225f8E0630b35a9b54bE713736\", \"0xcb768e263FB1C62214E7cab4AA8d036D76dc59CC\", LZ_ENDPOINT_A),\n c(2818, 30322, \"Morph\", \"0xe7cd86e13AC4309349F30B3435a9d337750fC82D\", \"0xcb768e263FB1C62214E7cab4AA8d036D76dc59CC\", LZ_ENDPOINT_B),\n c(14, 30295, \"Flare\", \"0xe7cd86e13AC4309349F30B3435a9d337750fC82D\", \"0x567287d2A9829215a37e3B88843d32f9221E7588\", LZ_ENDPOINT_A),\n].map((x) => [x.caip2, x])));\n\n/** LayerZero eid → deployment. */\nexport const USDT0_BY_EID: Readonly<Record<number, Usdt0Chain>> = Object.freeze(\n Object.fromEntries(Object.values(USDT0_CHAINS).map((x) => [x.eid, x])),\n);\n\n/** LayerZero Scan — message status by source transaction hash. */\nexport const LZ_SCAN_API = \"https://scan.layerzero-api.com\";\n\n/** Token symbols the catalog uses for the same asset across chains. */\nexport const USDT0_SYMBOLS: readonly string[] = Object.freeze([\"USDT0\", \"USDT\", \"USD₮0\", \"USD₮\"]);\n\nexport const usdt0 = {\n supportsChain(chain: string): boolean {\n return isEvm(chain) && !!USDT0_CHAINS[`eip155:${evmRef(chain)}`];\n },\n supports(from: string, to: string): boolean {\n return from !== to && this.supportsChain(from) && this.supportsChain(to);\n },\n};\n","import {createPublicClient, encodeFunctionData, fallback, getAddress, http, isAddress, pad, parseAbi, type Hex} from \"viem\";\nimport {describeUsdt0Activity} from \"./activity.js\";\nimport {ccAsset} from \"@anywalletkit/swap2-assets\";\nimport {redactUrls, timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentState, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {LZ_SCAN_API, USDT0_BY_EID, USDT0_CHAINS, USDT0_SYMBOLS, usdt0 as usdt0Cfg, type Usdt0Chain} from \"./config.js\";\n\n/**\n * USDT0 — Tether's USDT as a LayerZero OFT. ONE source transaction:\n * `send(SendParam, MessagingFee, refund)` on the chain's OFT with the\n * LayerZero messaging fee as `msg.value`; LayerZero's DVNs verify and the\n * executor delivers on the destination (mint of USDT0, or unlock of USDT out\n * of the Ethereum adapter). No second user transaction in the normal case.\n *\n * - Quote = two `eth_call`s on the source OFT: `quoteOFT` for the limits,\n * protocol fees and the amount that really arrives after dust removal\n * (shared decimals = 6, so none today), then `quoteSend` for the native\n * fee with `minAmountLD` pinned to that received amount — the contract\n * reverts rather than deliver less. Both are sealed into the quote.\n * - `enforcedOptions` on every deployment already carry the executor gas\n * (type-3 options, lzReceive gas 80 000, read on-chain 2026-10-20), so\n * `extraOptions` stays empty; LayerZero Scan confirms deliveries ran on it.\n * - Ethereum locks USDT in an adapter (`approvalRequired()` = true →\n * `approvalAddress`); every other chain's OFT burns the caller's USDT0\n * itself (`approvalRequired()` = false → no approval at all).\n * - Every address in `config.ts` is re-read on-chain before the first quote\n * on a chain (`token()`, `approvalRequired()`) and per pair (`peers(dstEid)`\n * must be the destination OFT) — a mismatch refuses the route.\n * - Status: LayerZero Scan by source hash. DELIVERED carries the destination\n * hash; PAYLOAD_STORED (delivery reverted on the destination, funds safe)\n * becomes \"action-required\" with a `buildClaim` that retries\n * `EndpointV2.lzReceive` — anyone may call it, so the user can.\n */\n\nconst OFT_ABI = parseAbi([\n \"struct SendParam { uint32 dstEid; bytes32 to; uint256 amountLD; uint256 minAmountLD; bytes extraOptions; bytes composeMsg; bytes oftCmd; }\",\n \"struct MessagingFee { uint256 nativeFee; uint256 lzTokenFee; }\",\n \"struct OFTLimit { uint256 minAmountLD; uint256 maxAmountLD; }\",\n \"struct OFTFeeDetail { int256 feeAmountLD; string description; }\",\n \"struct OFTReceipt { uint256 amountSentLD; uint256 amountReceivedLD; }\",\n \"struct MessagingReceipt { bytes32 guid; uint64 nonce; MessagingFee fee; }\",\n \"function quoteSend(SendParam s, bool payInLzToken) view returns (MessagingFee)\",\n \"function quoteOFT(SendParam s) view returns (OFTLimit, OFTFeeDetail[], OFTReceipt)\",\n \"function send(SendParam s, MessagingFee fee, address refundAddress) payable returns (MessagingReceipt, OFTReceipt)\",\n \"function token() view returns (address)\",\n \"function approvalRequired() view returns (bool)\",\n \"function peers(uint32 eid) view returns (bytes32)\",\n]);\nconst ENDPOINT_ABI = parseAbi([\n \"struct Origin { uint32 srcEid; bytes32 sender; uint64 nonce; }\",\n \"function lzReceive(Origin origin, address receiver, bytes32 guid, bytes message, bytes extraData) payable\",\n]);\n\nconst EVM_PLACEHOLDER = \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\";\nconst DEFAULT_QUOTE_TTL_MS = 60_000;\nconst RPC_TIMEOUT_MS = 12_000;\nconst SCAN_TIMEOUT_MS = 12_000;\n/** A direct `send` used ~330k gas on Arbitrum and on the Ethereum adapter (2026-10-20 receipts). */\nconst GAS_SEND = \"450000\";\n/**\n * The LayerZero fee is quoted at quote time but paid at send time, and it moves\n * with source and destination gas (live: +1.7 % within a minute on Ethereum).\n * The sealed `msg.value` carries this headroom; EndpointV2 charges the current\n * fee and refunds the surplus to `refundAddress` (the trader) in the same\n * transaction, so the headroom costs nothing — it only avoids a re-quote.\n */\nconst FEE_HEADROOM_BPS = 2_500n;\n/** `lzReceive` retry of a stored payload: a mint plus the endpoint bookkeeping. */\nconst GAS_CLAIM = \"300000\";\nconst ZERO_B32 = `0x${\"00\".repeat(32)}` as Hex;\n\nexport interface Usdt0ProviderConfig {\n enabled?: boolean;\n /**\n * JSON-RPC URL(s) per CAIP-2 chain. REQUIRED for every chain the provider\n * should quote from: the fee and the received amount come from the OFT\n * itself. The destination RPC is optional (used for the stored-payload retry).\n */\n rpcUrls?: Readonly<Record<string, string | readonly string[]>>;\n /** LayerZero Scan base (default https://scan.layerzero-api.com). */\n scanUrl?: string;\n /** Local lifetime of a quote (default 60 s; the sealed fee is re-checked at preflight). */\n quoteTtlMs?: number;\n /** Injectable for tests (also used by the RPC transport). */\n fetchImpl?: typeof fetch;\n}\n\ninterface ScanMessage {\n pathway?: {srcEid?: number; dstEid?: number; sender?: {address?: string}; receiver?: {address?: string}; nonce?: number};\n source?: {status?: string; tx?: {txHash?: string; payload?: string; options?: {lzReceive?: {gas?: string; value?: string}}}};\n destination?: {status?: string; tx?: {txHash?: string}};\n guid?: string;\n status?: {name?: string; message?: string};\n}\n\nconst same = (a: string | undefined | null, b: string) => !!a && a.toLowerCase() === b.toLowerCase();\nconst isHexData = (v: unknown): v is Hex => typeof v === \"string\" && /^0x(?:[0-9a-fA-F]{2})*$/.test(v);\n\n/** Does the catalog symbol on `chain` name this deployment's token? (USDT on Ethereum/Polygon, USDT0 elsewhere.) */\nfunction tokenMatches(chain: Usdt0Chain, symbolOrAddress: string): boolean {\n if (symbolOrAddress.startsWith(\"0x\")) return same(symbolOrAddress, chain.token);\n if (!USDT0_SYMBOLS.includes(symbolOrAddress.toUpperCase().replace(\"USD₮\", \"USDT\"))) return false;\n const known = ccAsset(chain.caip2, symbolOrAddress);\n // A symbol the catalog binds to another contract (OP's legacy bridged USDT) is not the OFT token.\n return !known || same(known.contract ?? \"\", chain.token);\n}\n\n/**\n * A refusal / preflight error that may reach a client: an RPC transport failure\n * becomes a fixed reason (viem's HTTP / timeout errors carry `URL: …`, and a keyed\n * endpoint's key sits in that path — scan 2026-10-23 F8); anything else loses its URLs.\n */\nfunction rpcSafeReason(err: unknown, chainName: string): string {\n const e = err as {name?: string; shortMessage?: string; message?: string} | undefined;\n const text = `${e?.shortMessage ?? \"\"}\\n${e?.message ?? String(err)}`;\n if (/HttpRequestError|TimeoutError|RpcRequestError|WebSocketRequestError/.test(String(e?.name)) || /\\bURL: |HTTP request failed|request timed out|took too long to respond/i.test(text)) {\n return `usdt0: RPC for ${chainName} unavailable — try again`;\n }\n return redactUrls(err instanceof Error ? err.message : String(err));\n}\n\nexport function usdt0Provider(config: Usdt0ProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const scan = (config.scanUrl ?? LZ_SCAN_API).replace(/\\/+$/, \"\");\n if (!/^https?:\\/\\//.test(scan)) throw new Error(\"usdt0: scanUrl must use http or https\");\n const quoteTtlMs = config.quoteTtlMs ?? DEFAULT_QUOTE_TTL_MS;\n if (!Number.isInteger(quoteTtlMs) || quoteTtlMs <= 0 || quoteTtlMs > 300_000) throw new Error(\"usdt0: quoteTtlMs must be an integer between 1 and 300000\");\n const rpcUrls = Object.freeze({...(config.rpcUrls ?? {})});\n const doFetch: typeof fetch = (input, init) => (config.fetchImpl ?? fetch)(input, init);\n\n const client = (caip2: string) => {\n const raw = rpcUrls[caip2];\n const urls = typeof raw === \"string\" ? [raw] : [...(raw ?? [])];\n if (urls.length === 0) return null;\n const opts = {timeout: RPC_TIMEOUT_MS, ...(config.fetchImpl ? {fetchFn: config.fetchImpl} : {})} as never;\n return createPublicClient({transport: urls.length === 1 ? http(urls[0], opts) : fallback(urls.map((u) => http(u, opts)))});\n };\n\n /** Once per chain: the OFT really is the OFT of the listed token with the listed approval mode. */\n const verified = new Map<string, Promise<void>>();\n function verifyChain(chain: Usdt0Chain): Promise<void> {\n let p = verified.get(chain.caip2);\n if (!p) {\n p = (async () => {\n const c = client(chain.caip2);\n if (!c) throw new Error(`usdt0: no RPC for ${chain.caip2}`);\n const [token, approval] = await Promise.all([\n c.readContract({address: getAddress(chain.oft), abi: OFT_ABI, functionName: \"token\"}),\n c.readContract({address: getAddress(chain.oft), abi: OFT_ABI, functionName: \"approvalRequired\"}),\n ]);\n if (!same(token, chain.token)) throw new Error(`usdt0: OFT ${chain.oft} on ${chain.name} reports token ${token}, expected ${chain.token}`);\n if (approval !== chain.adapter) throw new Error(`usdt0: OFT ${chain.oft} on ${chain.name} reports approvalRequired=${String(approval)}, expected ${String(chain.adapter)}`);\n })();\n p.catch(() => verified.delete(chain.caip2));\n verified.set(chain.caip2, p);\n }\n return p;\n }\n\n /** Once per pair: the source OFT's peer for the destination eid is the destination OFT. */\n const peers = new Map<string, Promise<void>>();\n function verifyPeer(src: Usdt0Chain, dst: Usdt0Chain): Promise<void> {\n const key = `${src.eid}>${dst.eid}`;\n let p = peers.get(key);\n if (!p) {\n p = (async () => {\n const c = client(src.caip2);\n if (!c) throw new Error(`usdt0: no RPC for ${src.caip2}`);\n const peer = await c.readContract({address: getAddress(src.oft), abi: OFT_ABI, functionName: \"peers\", args: [dst.eid]});\n if (!same(peer, pad(getAddress(dst.oft), {size: 32}))) throw new Error(`usdt0: ${src.name} OFT has no peer for ${dst.name} (eid ${dst.eid}) — route not wired`);\n })();\n p.catch(() => peers.delete(key));\n peers.set(key, p);\n }\n return p;\n }\n\n function parseIntent(intentId: string): {src: Usdt0Chain; dst: Usdt0Chain} | null {\n const [tag, s, d] = intentId.split(\":\");\n if (tag !== \"usdt0\") return null;\n const src = USDT0_BY_EID[Number(s)];\n const dst = USDT0_BY_EID[Number(d)];\n return src && dst && src !== dst ? {src, dst} : null;\n }\n\n const sendParam = (dstEid: number, recipient: string, amountLD: bigint, minAmountLD: bigint) => ({\n dstEid, to: pad(getAddress(recipient), {size: 32}), amountLD, minAmountLD, extraOptions: \"0x\" as Hex, composeMsg: \"0x\" as Hex, oftCmd: \"0x\" as Hex,\n });\n\n /** The LayerZero message of a source transaction on this route, or null while Scan has not indexed it. */\n async function scanMessage(src: Usdt0Chain, dst: Usdt0Chain, sourceTxHash: string): Promise<ScanMessage | null | \"foreign\"> {\n const res = await doFetch(`${scan}/v1/messages/tx/${encodeURIComponent(sourceTxHash)}`, {headers: {accept: \"application/json\"}, signal: timeoutSignal(SCAN_TIMEOUT_MS)});\n if (res.status === 404) return null;\n if (!res.ok) throw new Error(`usdt0: LayerZero Scan → ${res.status}`);\n const body = (await res.json()) as {data?: ScanMessage[]};\n const list = Array.isArray(body?.data) ? body.data : [];\n if (list.length === 0) return null;\n const m = list.find((x) => x.pathway?.srcEid === src.eid && x.pathway?.dstEid === dst.eid && same(x.pathway?.sender?.address, src.oft));\n return m ?? \"foreign\";\n }\n\n return {\n name: \"usdt0\",\n describeActivity: describeUsdt0Activity,\n enabled: () => config.enabled ?? true,\n supportsChain: (chain: string) => usdt0Cfg.supportsChain(chain) && client(chain) !== null,\n supportsChainPair: (from: string, to: string) => usdt0Cfg.supports(from, to) && client(from) !== null,\n supportsRoute(from: Asset, to: Asset): boolean {\n const src = USDT0_CHAINS[from.chain];\n const dst = USDT0_CHAINS[to.chain];\n if (!src || !dst || src === dst || client(from.chain) === null) return false;\n return tokenMatches(src, from.token) && tokenMatches(dst, to.token);\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n const refuse = (reason: string) => { params.onRefusal?.(reason); return null; };\n if (params.flex) return refuse(\"the amount is sealed into the calldata (no flexible deposits)\");\n const src = USDT0_CHAINS[params.sourceChain];\n const dst = USDT0_CHAINS[params.destChain];\n if (!src || !dst) return refuse(\"USDT0 is not deployed on this chain\");\n if (src === dst) return refuse(\"same-chain transfers are not a bridge\");\n if (!tokenMatches(src, params.sourceToken)) return refuse(`source token ${params.sourceToken} is not USDT0 (${src.token}) on ${src.name}`);\n if (!tokenMatches(dst, params.destToken)) return refuse(`destination token ${params.destToken} is not USDT0 (${dst.token}) on ${dst.name}`);\n if (!/^\\d+$/.test(params.amountIn)) return refuse(\"amount must be a base-unit integer\");\n const amount = BigInt(params.amountIn);\n if (amount <= 0n) return refuse(\"amount must be positive\");\n const recipient = params.destAddress || EVM_PLACEHOLDER;\n if (!isAddress(recipient)) return refuse(\"destination must be an EVM address\");\n const refund = params.refundAddress || EVM_PLACEHOLDER;\n if (!isAddress(refund)) return refuse(\"refund address must be an EVM address\");\n const c = client(src.caip2);\n if (!c) return refuse(`no RPC configured for ${src.caip2}`);\n\n try {\n await Promise.all([verifyChain(src), verifyPeer(src, dst)]);\n const probe = sendParam(dst.eid, recipient, amount, 0n);\n const [limit, feeDetails, receipt] = await c.readContract({address: getAddress(src.oft), abi: OFT_ABI, functionName: \"quoteOFT\", args: [probe]});\n if (amount < limit.minAmountLD) return refuse(`amount ${amount} is below the OFT minimum ${limit.minAmountLD}`);\n if (amount > limit.maxAmountLD) return refuse(`amount ${amount} exceeds the OFT maximum ${limit.maxAmountLD}`);\n const received = receipt.amountReceivedLD;\n if (received <= 0n) return refuse(\"amount is below the OFT dust threshold — nothing would arrive\");\n if (received > amount) return refuse(\"OFT reports more received than sent — refusing\");\n if (params.minAmountOut !== undefined && received < BigInt(params.minAmountOut)) return refuse(`received ${received} is below the caller's floor ${params.minAmountOut}`);\n const sp = sendParam(dst.eid, recipient, amount, received);\n const fee = await c.readContract({address: getAddress(src.oft), abi: OFT_ABI, functionName: \"quoteSend\", args: [sp, false]});\n if (fee.lzTokenFee !== 0n) return refuse(\"OFT asks for a fee in LZ token — unsupported\");\n // Sealed with headroom: OAppSender requires msg.value == MessagingFee.nativeFee, the\n // endpoint refunds whatever the current fee does not use to `refund`.\n const nativeFee = fee.nativeFee + (fee.nativeFee * FEE_HEADROOM_BPS) / 10_000n;\n const data = encodeFunctionData({abi: OFT_ABI, functionName: \"send\", args: [sp, {nativeFee, lzTokenFee: 0n}, getAddress(refund)]});\n const protocolFees = feeDetails\n .filter((f) => f.feeAmountLD > 0n)\n .map((f) => ({type: \"protocol\" as const, amount: f.feeAmountLD.toString(), token: src.token, included: true, description: f.description || \"OFT fee\"}));\n const feeUsd = protocolFees.reduce((a, f) => a + Number(f.amount) / 1e6, 0);\n // Ethereum sources wait for 60 confirmations before the DVNs attest (~15 min live); L2 sources land in a few minutes.\n const eta = src.chainId === 1 ? 1000 : 240;\n return {\n provider: \"usdt0\",\n intentId: `usdt0:${src.eid}:${dst.eid}`,\n depositAddress: \"\",\n depositMemo: null,\n txRequest: {\n to: src.oft,\n data,\n value: nativeFee.toString(),\n chainId: src.chainId,\n gasLimit: GAS_SEND,\n ...(src.adapter ? {approvalAddress: src.oft} : {}),\n ...(nativeFee > 0n ? {nativeFee: nativeFee.toString()} : {}),\n },\n sourceAmount: amount.toString(),\n destAmount: received.toString(),\n minDestAmount: received.toString(),\n feeUsd,\n fees: protocolFees,\n etaSeconds: eta,\n reliability: 0.98,\n validUntilMs: Date.now() + quoteTtlMs,\n providerData: {\n srcEid: String(src.eid), dstEid: String(dst.eid), oft: src.oft, token: src.token, recipient: getAddress(recipient), refundAddress: getAddress(refund),\n amountLD: amount.toString(), minAmountLD: received.toString(), nativeFee: nativeFee.toString(),\n },\n };\n } catch (err) {\n return refuse(rpcSafeReason(err, src.name));\n }\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n const tx = quote.txRequest;\n const parsed = parseIntent(quote.intentId);\n if (!tx || !parsed) throw new Error(\"swap2: USDT0 quote has no transaction request\");\n return {\n chain: parsed.src.caip2,\n to: tx.to ?? \"\",\n value: tx.value ?? \"0\",\n ...(tx.data ? {data: tx.data} : {}),\n ...(tx.chainId !== undefined ? {chainId: tx.chainId} : {}),\n ...(tx.gasLimit ? {gasLimit: tx.gasLimit} : {}),\n ...(tx.approvalAddress ? {approvalAddress: tx.approvalAddress} : {}),\n };\n },\n\n /**\n * Right before signing: the target is the source OFT, the peer is still the\n * destination OFT, and the CURRENT LayerZero fee still fits the sealed\n * `msg.value` (quote + headroom) — the endpoint reverts a send that\n * underpays, so a fee past the headroom means re-quote rather than a\n * wasted broadcast.\n */\n async preflightDeposit(quote: Quote, tx: UnsignedTx): Promise<void> {\n const parsed = parseIntent(quote.intentId);\n if (!parsed) throw new Error(\"usdt0: malformed intent id\");\n const {src, dst} = parsed;\n if (!same(tx.to, src.oft)) throw new Error(`usdt0: deposit target ${tx.to} is not the ${src.name} OFT`);\n const pd = quote.providerData ?? {};\n if (!/^\\d+$/.test(pd.amountLD ?? \"\") || !/^\\d+$/.test(pd.minAmountLD ?? \"\") || !/^\\d+$/.test(pd.nativeFee ?? \"\") || !isAddress(pd.recipient ?? \"\")) {\n throw new Error(\"usdt0: quote carries no sealed send parameters\");\n }\n const c = client(src.caip2);\n if (!c) throw new Error(`usdt0: no RPC for ${src.caip2}`);\n const sp = sendParam(dst.eid, pd.recipient!, BigInt(pd.amountLD!), BigInt(pd.minAmountLD!));\n let fee: {nativeFee: bigint};\n try {\n await Promise.all([verifyChain(src), verifyPeer(src, dst)]);\n fee = await c.readContract({address: getAddress(src.oft), abi: OFT_ABI, functionName: \"quoteSend\", args: [sp, false]});\n } catch (err) {\n throw new Error(rpcSafeReason(err, src.name));\n }\n const sealed = BigInt(pd.nativeFee!);\n if (fee.nativeFee > sealed) throw new Error(`usdt0: LayerZero fee rose to ${fee.nativeFee} above the sealed ${sealed} (quote + ${FEE_HEADROOM_BPS / 100n} % headroom) — re-quote`);\n if (BigInt(tx.value) !== sealed) throw new Error(`usdt0: transaction value ${tx.value} is not the quoted fee ${sealed}`);\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n const parsed = parseIntent(ref.intentId);\n if (!parsed) return {state: \"failed\"};\n const {src, dst} = parsed;\n if (!ref.sourceTxHash) return {state: \"pending\"};\n try {\n const m = await scanMessage(src, dst, ref.sourceTxHash);\n if (m === null) return {state: \"pending\", depositReceived: false};\n if (m === \"foreign\") return {state: \"failed\"}; // the hash carries a LayerZero message, but not ours\n const name = (m.status?.name ?? \"\").toUpperCase();\n const destHash = m.destination?.tx?.txHash;\n if (name === \"DELIVERED\") return {state: \"completed\", depositReceived: true, ...(destHash ? {destTxHash: destHash} : ref.destTxHash ? {destTxHash: ref.destTxHash} : {})};\n if (name === \"PAYLOAD_STORED\") return {state: \"action-required\", depositReceived: true, claim: {chain: dst.caip2, ready: true}};\n if ([\"FAILED\", \"APPLICATION_BURNED\", \"APPLICATION_SKIPPED\", \"UNRESOLVABLE_COMMAND\", \"MALFORMED_COMMAND\"].includes(name)) return {state: \"failed\", depositReceived: true};\n // INFLIGHT, CONFIRMING, BLOCKED (an earlier nonce on the pathway is stuck — LayerZero clears it), or anything new.\n return {state: \"pending\", depositReceived: true};\n } catch {\n return {state: \"pending\"};\n }\n },\n\n /**\n * A delivery that reverted on the destination (PAYLOAD_STORED — out of\n * executor gas, paused token) is retried by anyone through the endpoint:\n * `lzReceive(origin, receiver, guid, message, extraData)` with the exact\n * packet LayerZero Scan recorded. Null while nothing is stored.\n */\n async buildClaim(ref: IntentRef): Promise<UnsignedTx | null> {\n const parsed = parseIntent(ref.intentId);\n if (!parsed || !ref.sourceTxHash) return null;\n const {src, dst} = parsed;\n const m = await scanMessage(src, dst, ref.sourceTxHash);\n if (!m || m === \"foreign\" || (m.status?.name ?? \"\").toUpperCase() !== \"PAYLOAD_STORED\") return null;\n const nonce = m.pathway?.nonce;\n const guid = m.guid;\n const message = m.source?.tx?.payload;\n if (!Number.isInteger(nonce) || !isHexData(guid) || guid.length !== 66 || !isHexData(message) || message.length <= 2) {\n throw new Error(\"usdt0: LayerZero Scan has no complete packet for the stored payload\");\n }\n if (!same(m.pathway?.receiver?.address, dst.oft)) throw new Error(\"usdt0: stored payload is addressed to another receiver\");\n const valueRaw = m.source?.tx?.options?.lzReceive?.value ?? \"0\";\n const value = /^\\d+$/.test(valueRaw) ? valueRaw : \"0\";\n return {\n chain: dst.caip2,\n to: dst.endpoint,\n value,\n data: encodeFunctionData({\n abi: ENDPOINT_ABI,\n functionName: \"lzReceive\",\n args: [{srcEid: src.eid, sender: pad(getAddress(src.oft), {size: 32}), nonce: BigInt(nonce as number)}, getAddress(dst.oft), guid, message, \"0x\"],\n }),\n chainId: dst.chainId,\n gasLimit: GAS_CLAIM,\n };\n },\n };\n}\n\n/** Exported for tests and diagnostics: the LayerZero Scan status → swap2 state mapping. */\nexport const USDT0_STATUS_MAP: Readonly<Record<string, IntentState>> = Object.freeze({\n INFLIGHT: \"pending\", CONFIRMING: \"pending\", BLOCKED: \"pending\",\n DELIVERED: \"completed\", PAYLOAD_STORED: \"action-required\",\n FAILED: \"failed\", APPLICATION_BURNED: \"failed\", APPLICATION_SKIPPED: \"failed\", UNRESOLVABLE_COMMAND: \"failed\", MALFORMED_COMMAND: \"failed\",\n});\n\nexport {ZERO_B32 as USDT0_ZERO_PEER};\n","/**\n * Activity recognition for USDT0 on every chain in `config.ts`:\n * - `send(...)` on the chain's OFT is our source leg (\"Bridged USDT0\", or\n * \"Bridged USDT\" on Ethereum where the adapter locks plain USDT);\n * - the inbound leg is the executor's delivery — the user signs nothing, so\n * it is recognized by its effect: the chain's USDT0 minted to the owner\n * (from the zero address), or USDT released by the Ethereum adapter to the\n * owner, inside a transaction that did NOT call the token itself (a plain\n * transfer is not a bridge);\n * - `lzReceive` on the LayerZero endpoint is the owner's own retry of a\n * stored payload (`claimSwap2`).\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {calledContract, chainLabel, describeSwapLike, matchesCall} from \"@anywalletkit/protocol-swap2-core/activity\";\nimport {decodeFunctionData, parseAbi, type Hex} from \"viem\";\nimport {USDT0_BY_EID, USDT0_CHAINS, type Usdt0Chain} from \"./config.js\";\n\nconst SEND_ABI = parseAbi([\n \"struct SendParam { uint32 dstEid; bytes32 to; uint256 amountLD; uint256 minAmountLD; bytes extraOptions; bytes composeMsg; bytes oftCmd; }\",\n \"struct MessagingFee { uint256 nativeFee; uint256 lzTokenFee; }\",\n \"function send(SendParam sp, MessagingFee fee, address refundAddress)\",\n]);\n\nexport const USDT0_MODULE = \"@anywalletkit/protocol-swap2-usdt0\";\n\n/** send((uint32,bytes32,uint256,uint256,bytes,bytes,bytes),(uint256,uint256),address) — IOFT */\nexport const USDT0_SEND = \"0xc7c7f5b3\";\n/** lzReceive((uint32,bytes32,uint64),address,bytes32,bytes,bytes) — EndpointV2 */\nexport const LZ_RECEIVE = \"0x0c0c389e\";\n\nconst ZERO = \"0x0000000000000000000000000000000000000000\";\n\n/** The symbol the catalog uses on each deployment: USDT where the OFT wraps Tether's USDT, USDT0 elsewhere. */\nfunction symbolFor(chain: Usdt0Chain): string {\n return chain.adapter || [42161, 10, 137].includes(chain.chainId) ? \"USDT\" : \"USDT0\";\n}\n\n/** `send(SendParam, …)` → the destination deployment (dstEid is the first word of the tuple), null when the calldata is absent or foreign. */\nfunction sendDestination(tx: ChainTx): Usdt0Chain | null {\n const data = tx.call?.data;\n if (!data || data.length < 10 + 64 * 2) return null;\n try {\n const [sp] = decodeFunctionData({abi: SEND_ABI, data: data as Hex}).args as unknown as [{dstEid: number}];\n return USDT0_BY_EID[sp.dstEid] ?? null;\n } catch {\n return null;\n }\n}\nconst lc = (a: string) => a.toLowerCase();\n\nexport function describeUsdt0Activity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n const chain = USDT0_CHAINS[tx.chain];\n if (!chain) return null;\n const subtitle = `USDT0 · ${chainLabel(tx.chain)}`;\n if (matchesCall(tx, [chain.oft], [USDT0_SEND])) {\n // The native value is the LayerZero messaging fee (plus the headroom the\n // endpoint refunds), not an asset the owner swapped away: it rides in `fee`\n // next to the gas, and the title names both ends when the calldata says\n // where the tokens go.\n const dst = sendDestination(tx);\n const item = describeSwapLike(tx, ctx, {protocol: USDT0_MODULE, subtitle, kind: \"bridge\", outVerb: \"Bridged\"});\n if (!item) return null;\n const native = item.assetsOut.filter((a) => a.token === null).reduce((sum, a) => sum + a.amount, 0n);\n item.assetsOut = item.assetsOut.filter((a) => a.token !== null);\n if (native > 0n) item.fee = (item.fee ?? 0n) + native;\n const srcSym = item.assetsOut[0]?.symbol ?? symbolFor(chain);\n if (dst) {\n item.title = `Bridged ${srcSym} → ${symbolFor(dst)}`;\n item.subtitle = `USDT0 · ${chainLabel(tx.chain)} → ${dst.name}`;\n } else item.title = `Bridged ${srcSym}`;\n return item;\n }\n if (matchesCall(tx, [chain.endpoint], [LZ_RECEIVE])) {\n return describeSwapLike(tx, ctx, {protocol: USDT0_MODULE, subtitle, kind: \"bridge\", inSuffix: \"via LayerZero\"});\n }\n // Delivery by the LayerZero executor: the token moves out of nowhere (mint)\n // or out of the adapter into the owner, and the call target is not the token.\n const called = calledContract(tx);\n if (called && called === lc(chain.token)) return null;\n const own = new Set([...ctx.own].map(lc));\n const origin = chain.adapter ? lc(chain.oft) : ZERO;\n const delivered = tx.transfers.some((t) => t.token !== null && lc(t.token) === lc(chain.token) && lc(t.from) === origin && own.has(lc(t.to)));\n if (!delivered || own.has(lc(tx.from))) return null;\n return describeSwapLike(tx, ctx, {protocol: USDT0_MODULE, subtitle, kind: \"bridge\", inSuffix: \"via LayerZero\", counterparty: chain.oft});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAkC;;;ACalC,kBAA4B;AAuB5B,IAAM,gBAAgB;AACtB,IAAM,gBAAgB;AAEtB,IAAM,IAAI,CAAC,SAAiB,KAAa,MAAc,OAAe,KAAa,UAAkB,UAAU,WAAuB;AAAA,EACpI,OAAO,UAAU,OAAO;AAAA,EAAI;AAAA,EAAS;AAAA,EAAK;AAAA,EAAM;AAAA,EAAO;AAAA,EAAK;AAAA,EAAU;AACxE;AAGO,IAAM,eAAqD,OAAO,OAAO,OAAO,YAAY;AAAA,EACjG,EAAE,GAAG,OAAO,YAAY,8CAA8C,8CAA8C,eAAe,IAAI;AAAA,EACvI,EAAE,OAAO,OAAO,YAAY,8CAA8C,8CAA8C,aAAa;AAAA,EACrI,EAAE,IAAI,OAAO,cAAc,8CAA8C,8CAA8C,aAAa;AAAA,EACpI,EAAE,KAAK,OAAO,eAAe,8CAA8C,8CAA8C,aAAa;AAAA,EACtI,EAAE,KAAK,OAAO,YAAY,8CAA8C,8CAA8C,4CAA4C;AAAA,EAClK,EAAE,OAAO,OAAO,OAAO,8CAA8C,8CAA8C,4CAA4C;AAAA,EAC/J,EAAE,OAAO,OAAO,aAAa,8CAA8C,8CAA8C,aAAa;AAAA,EACtI,EAAE,KAAK,OAAO,YAAY,8CAA8C,8CAA8C,aAAa;AAAA,EACnI,EAAE,MAAM,OAAO,OAAO,8CAA8C,8CAA8C,aAAa;AAAA,EAC/H,EAAE,MAAM,OAAO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QACL,OAAO,IAAI;AAAA,QACX,IAAI,IAAI;AAAA,QACR;AAAA,QACA,UAAM,iCAAmB;AAAA,UACvB,KAAK;AAAA,UACL,cAAc;AAAA,UACd,MAAM,CAAC,EAAC,QAAQ,IAAI,KAAK,YAAQ,sBAAI,yBAAW,IAAI,GAAG,GAAG,EAAC,MAAM,GAAE,CAAC,GAAG,OAAO,OAAO,KAAe,EAAC,OAAG,yBAAW,IAAI,GAAG,GAAG,MAAM,SAAS,IAAI;AAAA,QAClJ,CAAC;AAAA,QACD,SAAS,IAAI;AAAA,QACb,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF;AAGO,IAAM,mBAA0D,OAAO,OAAO;AAAA,EACnF,UAAU;AAAA,EAAW,YAAY;AAAA,EAAW,SAAS;AAAA,EACrD,WAAW;AAAA,EAAa,gBAAgB;AAAA,EACxC,QAAQ;AAAA,EAAU,oBAAoB;AAAA,EAAU,qBAAqB;AAAA,EAAU,sBAAsB;AAAA,EAAU,mBAAmB;AACpI,CAAC;;;AFrYM,IAAM,qBAAN,cAAiC,kCAAoB;AAAA,EACvC;AAAA,EACnB,YAAY,SAAmC,QAA0B;AACvE,UAAM,SAAS,MAAM;AACrB,SAAK,WAAW,cAAc,MAAM;AAAA,EACtC;AAAA,EACmB,eAAe,OAAwB;AACxD,WAAO,MAAS,cAAc,KAAK;AAAA,EACrC;AAAA,EACmB,cAAc,WAAmB,SAA0B;AAC5E,WAAO,MAAS,SAAS,WAAW,OAAO;AAAA,EAC7C;AACF;","names":["import_viem","import_util","c"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as _anywalletkit_protocol_swap2_core_types from '@anywalletkit/protocol-swap2-core/types';
|
|
2
|
+
import { SingleProviderSwap2 } from '@anywalletkit/protocol-swap2-core/swap2/single';
|
|
3
|
+
import { Swap2EngineConfig, Swap2Account } from '@anywalletkit/protocol-swap2-core/swap2/base';
|
|
4
|
+
import { Usdt0ProviderConfig } from './provider.cjs';
|
|
5
|
+
import 'viem';
|
|
6
|
+
|
|
7
|
+
interface Usdt0Swap2Config extends Swap2EngineConfig, Usdt0ProviderConfig {
|
|
8
|
+
}
|
|
9
|
+
/** Standalone USDT0 swap2: USDT / USDT0 between the LayerZero OFT deployments in one source transaction. */
|
|
10
|
+
declare class Usdt0Swap2Protocol extends SingleProviderSwap2 {
|
|
11
|
+
protected readonly provider: _anywalletkit_protocol_swap2_core_types.CrossChainProvider;
|
|
12
|
+
constructor(account: Swap2Account | undefined, config: Usdt0Swap2Config);
|
|
13
|
+
protected chainSupported(caip2: string): boolean;
|
|
14
|
+
protected pairSupported(fromChain: string, toChain: string): boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { type Usdt0Swap2Config, Usdt0Swap2Protocol };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as _anywalletkit_protocol_swap2_core_types from '@anywalletkit/protocol-swap2-core/types';
|
|
2
|
+
import { SingleProviderSwap2 } from '@anywalletkit/protocol-swap2-core/swap2/single';
|
|
3
|
+
import { Swap2EngineConfig, Swap2Account } from '@anywalletkit/protocol-swap2-core/swap2/base';
|
|
4
|
+
import { Usdt0ProviderConfig } from './provider.js';
|
|
5
|
+
import 'viem';
|
|
6
|
+
|
|
7
|
+
interface Usdt0Swap2Config extends Swap2EngineConfig, Usdt0ProviderConfig {
|
|
8
|
+
}
|
|
9
|
+
/** Standalone USDT0 swap2: USDT / USDT0 between the LayerZero OFT deployments in one source transaction. */
|
|
10
|
+
declare class Usdt0Swap2Protocol extends SingleProviderSwap2 {
|
|
11
|
+
protected readonly provider: _anywalletkit_protocol_swap2_core_types.CrossChainProvider;
|
|
12
|
+
constructor(account: Swap2Account | undefined, config: Usdt0Swap2Config);
|
|
13
|
+
protected chainSupported(caip2: string): boolean;
|
|
14
|
+
protected pairSupported(fromChain: string, toChain: string): boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { type Usdt0Swap2Config, Usdt0Swap2Protocol };
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|