@anywalletkit/protocol-swap2-chainflip 0.2.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/activity.cjs +201 -0
- package/dist/activity.cjs.map +1 -1
- package/dist/activity.js +3 -2
- package/dist/chunk-DGLXKJQ7.js +115 -0
- package/dist/chunk-DGLXKJQ7.js.map +1 -0
- package/dist/{chunk-R4KDUQMK.js → chunk-RRCQYT67.js} +3 -3
- package/dist/{chunk-MFAELZLP.js → chunk-RU2NXJTL.js} +11 -11
- package/dist/{chunk-H6GJVVWS.js → chunk-ZH5XKSCP.js} +2 -2
- package/dist/config.cjs +189 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +19 -1
- package/dist/config.d.ts +19 -1
- package/dist/config.js +8 -3
- package/dist/index.cjs +109 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +19 -15
- package/dist/protocol.cjs +107 -57
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.js +4 -4
- package/dist/provider.cjs +106 -56
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.js +3 -3
- package/package.json +6 -6
- package/dist/chunk-GXHOO3CT.js +0 -54
- package/dist/chunk-GXHOO3CT.js.map +0 -1
- /package/dist/{chunk-R4KDUQMK.js.map → chunk-RRCQYT67.js.map} +0 -0
- /package/dist/{chunk-MFAELZLP.js.map → chunk-RU2NXJTL.js.map} +0 -0
- /package/dist/{chunk-H6GJVVWS.js.map → chunk-ZH5XKSCP.js.map} +0 -0
package/dist/config.cjs
CHANGED
|
@@ -26,9 +26,147 @@ __export(config_exports, {
|
|
|
26
26
|
CF_SOURCE_CHAINS: () => CF_SOURCE_CHAINS,
|
|
27
27
|
CF_VAULTS: () => CF_VAULTS,
|
|
28
28
|
cfAsset: () => cfAsset,
|
|
29
|
-
chainflip: () => chainflip
|
|
29
|
+
chainflip: () => chainflip,
|
|
30
|
+
chainflipPins: () => chainflipPins,
|
|
31
|
+
chainflipVerifyQuote: () => chainflipVerifyQuote
|
|
30
32
|
});
|
|
31
33
|
module.exports = __toCommonJS(config_exports);
|
|
34
|
+
|
|
35
|
+
// src/codec.ts
|
|
36
|
+
var import_base = require("@scure/base");
|
|
37
|
+
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
38
|
+
var import_viem = require("viem");
|
|
39
|
+
var Reader = class {
|
|
40
|
+
constructor(b) {
|
|
41
|
+
this.b = b;
|
|
42
|
+
}
|
|
43
|
+
b;
|
|
44
|
+
i = 0;
|
|
45
|
+
need(n) {
|
|
46
|
+
if (this.i + n > this.b.length) throw new Error(`chainflip codec: truncated at ${this.i} (+${n} of ${this.b.length})`);
|
|
47
|
+
}
|
|
48
|
+
u8() {
|
|
49
|
+
this.need(1);
|
|
50
|
+
return this.b[this.i++];
|
|
51
|
+
}
|
|
52
|
+
bytes(n) {
|
|
53
|
+
this.need(n);
|
|
54
|
+
const out = this.b.slice(this.i, this.i + n);
|
|
55
|
+
this.i += n;
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
uLE(n) {
|
|
59
|
+
const x = this.bytes(n);
|
|
60
|
+
let v = 0n;
|
|
61
|
+
for (let k = n - 1; k >= 0; k--) v = v << 8n | BigInt(x[k]);
|
|
62
|
+
return v;
|
|
63
|
+
}
|
|
64
|
+
/** Little-endian unsigned of up to 6 bytes as a number (exact: below 2^48). */
|
|
65
|
+
uNum(n) {
|
|
66
|
+
if (n > 6) throw new Error("chainflip codec: uNum takes at most 6 bytes");
|
|
67
|
+
const x = this.bytes(n);
|
|
68
|
+
let v = 0;
|
|
69
|
+
for (let k = n - 1; k >= 0; k--) v = v * 256 + x[k];
|
|
70
|
+
return v;
|
|
71
|
+
}
|
|
72
|
+
/** SCALE compact integer */
|
|
73
|
+
compact() {
|
|
74
|
+
const first = this.u8();
|
|
75
|
+
const mode = first & 3;
|
|
76
|
+
if (mode === 0) return first >> 2;
|
|
77
|
+
if (mode === 1) return (this.u8() << 8 | first) >> 2;
|
|
78
|
+
if (mode === 2) {
|
|
79
|
+
const rest = this.uNum(3);
|
|
80
|
+
return (rest << 8 | first) >>> 2;
|
|
81
|
+
}
|
|
82
|
+
throw new Error("chainflip codec: big compact integers are not used here");
|
|
83
|
+
}
|
|
84
|
+
done() {
|
|
85
|
+
if (this.i !== this.b.length) throw new Error(`chainflip codec: ${this.b.length - this.i} trailing bytes`);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var toHex = (b) => `0x${[...b].map((x) => x.toString(16).padStart(2, "0")).join("")}`;
|
|
89
|
+
function fromHex(h) {
|
|
90
|
+
const s = h.startsWith("0x") ? h.slice(2) : h;
|
|
91
|
+
if (s.length % 2 || /[^0-9a-f]/i.test(s)) throw new Error("chainflip codec: not hex");
|
|
92
|
+
return Uint8Array.from(s.match(/../g) ?? [], (x) => Number.parseInt(x, 16));
|
|
93
|
+
}
|
|
94
|
+
function decodeCfParameters(bytes, refundLen) {
|
|
95
|
+
const r = new Reader(bytes);
|
|
96
|
+
const p = readCfParameters(r, refundLen);
|
|
97
|
+
r.done();
|
|
98
|
+
return p;
|
|
99
|
+
}
|
|
100
|
+
function readCfParameters(r, refundLen) {
|
|
101
|
+
const version = r.u8();
|
|
102
|
+
if (version !== 1) throw new Error(`chainflip codec: cf parameters version ${version}`);
|
|
103
|
+
const retryDurationBlocks = r.uNum(4);
|
|
104
|
+
const refundAddress = toHex(r.bytes(refundLen));
|
|
105
|
+
const minPriceX128 = r.uLE(32);
|
|
106
|
+
const refundCcm = r.u8() !== 0;
|
|
107
|
+
if (refundCcm) throw new Error("chainflip codec: refund CCM metadata is not expected");
|
|
108
|
+
const maxOraclePriceSlippageBps = r.u8() ? r.uNum(2) : null;
|
|
109
|
+
const dca = r.u8() ? { chunks: r.uNum(4), intervalBlocks: r.uNum(4) } : null;
|
|
110
|
+
const boostFeeBps = r.u8();
|
|
111
|
+
const broker = { account: toHex(r.bytes(32)), feeBps: r.uNum(2) };
|
|
112
|
+
const n = r.compact();
|
|
113
|
+
const affiliates = Array.from({ length: n }, () => ({ account: r.u8(), feeBps: r.uNum(2) }));
|
|
114
|
+
return { version, retryDurationBlocks, refundAddress, minPriceX128, refundCcm, maxOraclePriceSlippageBps, dca, boostFeeBps, broker, affiliates };
|
|
115
|
+
}
|
|
116
|
+
var TAG_LEN = { 0: 20, 1: 32, 2: "vec", 3: 20, 4: 32, 5: 32, 6: 20 };
|
|
117
|
+
function decodeTronNote(note) {
|
|
118
|
+
const r = new Reader(fromHex(note));
|
|
119
|
+
const outputAsset = r.u8();
|
|
120
|
+
const destTag = r.u8();
|
|
121
|
+
const len = TAG_LEN[destTag];
|
|
122
|
+
if (len === void 0) throw new Error(`chainflip codec: unknown address tag ${destTag}`);
|
|
123
|
+
const destAddress = len === "vec" ? r.bytes(r.compact()) : r.bytes(len);
|
|
124
|
+
const ccm = r.u8() !== 0;
|
|
125
|
+
if (ccm) throw new Error("chainflip codec: CCM swaps are not expected");
|
|
126
|
+
const paramsLen = r.compact();
|
|
127
|
+
const start = r.i;
|
|
128
|
+
const params = readCfParameters(r, 20);
|
|
129
|
+
if (r.i - start !== paramsLen) throw new Error(`chainflip codec: cf parameters length ${r.i - start} \u2260 declared ${paramsLen}`);
|
|
130
|
+
r.done();
|
|
131
|
+
return { outputAsset, destTag, destAddress, ccm, params };
|
|
132
|
+
}
|
|
133
|
+
var VAULT_ABI = (0, import_viem.parseAbi)([
|
|
134
|
+
"function xSwapNative(uint32 dstChain, bytes dstAddress, uint32 dstToken, bytes cfParameters) payable",
|
|
135
|
+
"function xSwapToken(uint32 dstChain, bytes dstAddress, uint32 dstToken, address srcToken, uint256 amount, bytes cfParameters)"
|
|
136
|
+
]);
|
|
137
|
+
function decodeEvmVaultCall(data) {
|
|
138
|
+
const d = (0, import_viem.decodeFunctionData)({ abi: VAULT_ABI, data });
|
|
139
|
+
if (d.functionName === "xSwapNative") {
|
|
140
|
+
const [dstChain2, dstAddress2, dstToken2, cf2] = d.args;
|
|
141
|
+
return { native: true, dstChain: dstChain2, dstAddress: fromHex(dstAddress2), dstToken: dstToken2, srcToken: null, amount: null, params: decodeCfParameters(fromHex(cf2), 20) };
|
|
142
|
+
}
|
|
143
|
+
const [dstChain, dstAddress, dstToken, srcToken, amount, cf] = d.args;
|
|
144
|
+
return { native: false, dstChain, dstAddress: fromHex(dstAddress), dstToken, srcToken, amount, params: decodeCfParameters(fromHex(cf), 20) };
|
|
145
|
+
}
|
|
146
|
+
function tronToBytes(address) {
|
|
147
|
+
const b = import_base.base58.decode(address);
|
|
148
|
+
if (b.length !== 25 || b[0] !== 65) throw new Error(`not a Tron address: ${address}`);
|
|
149
|
+
const check = (0, import_sha2.sha256)((0, import_sha2.sha256)(b.subarray(0, 21))).subarray(0, 4);
|
|
150
|
+
if (toHex(check) !== toHex(b.subarray(21))) throw new Error(`bad Tron checksum: ${address}`);
|
|
151
|
+
return b.subarray(1, 21);
|
|
152
|
+
}
|
|
153
|
+
function destAddressBytes(chain, address) {
|
|
154
|
+
if (chain.startsWith("eip155:")) return fromHex(address);
|
|
155
|
+
if (chain.startsWith("tron:")) return tronToBytes(address);
|
|
156
|
+
if (chain.startsWith("solana:")) {
|
|
157
|
+
const b = import_base.base58.decode(address);
|
|
158
|
+
if (b.length !== 32) throw new Error(`not a Solana address: ${address}`);
|
|
159
|
+
return b;
|
|
160
|
+
}
|
|
161
|
+
if (chain.startsWith("bitcoin:")) return new TextEncoder().encode(address);
|
|
162
|
+
throw new Error(`chainflip: no address encoding for ${chain}`);
|
|
163
|
+
}
|
|
164
|
+
var sameBytes = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
|
|
165
|
+
function minOutOf(amountIn, minPriceX128) {
|
|
166
|
+
return amountIn * minPriceX128 / 2n ** 128n;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/config.ts
|
|
32
170
|
var CF_CHAINS = {
|
|
33
171
|
"eip155:1": { name: "Ethereum", id: 1, addrTag: 0 },
|
|
34
172
|
"bitcoin:mainnet": { name: "Bitcoin", id: 3, addrTag: 2 },
|
|
@@ -71,4 +209,54 @@ var chainflip = {
|
|
|
71
209
|
supportsChain: (chain) => !!CF_CHAINS[chain],
|
|
72
210
|
supports: (from, to) => CF_SOURCE_CHAINS.has(from) && !!CF_CHAINS[to] && from !== to
|
|
73
211
|
};
|
|
212
|
+
function chainflipVerifyQuote(params, quote) {
|
|
213
|
+
try {
|
|
214
|
+
const src = cfAsset(params.sourceChain, params.sourceToken);
|
|
215
|
+
const dst = cfAsset(params.destChain, params.destToken);
|
|
216
|
+
const dstChain = CF_CHAINS[params.destChain];
|
|
217
|
+
const vault = Object.prototype.hasOwnProperty.call(CF_VAULTS, params.sourceChain) ? CF_VAULTS[params.sourceChain] : void 0;
|
|
218
|
+
if (!src || !dst || !dstChain || !vault || !CF_SOURCE_CHAINS.has(params.sourceChain)) return "not a vault swap this release signs";
|
|
219
|
+
if (!quote.txRequest && !quote.depositAddress) return null;
|
|
220
|
+
if (!params.refundAddress) return "a live quote needs the refund address";
|
|
221
|
+
const amountIn = BigInt(params.amountIn);
|
|
222
|
+
const dest = destAddressBytes(params.destChain, params.destAddress);
|
|
223
|
+
const refund = destAddressBytes(params.sourceChain, params.refundAddress);
|
|
224
|
+
const checkParams = (p) => {
|
|
225
|
+
if (!sameBytes(fromHex(p.refundAddress), refund)) return "the refund address is not the sender";
|
|
226
|
+
if (minOutOf(amountIn, p.minPriceX128) < BigInt(quote.minDestAmount)) return "the minimum price does not guarantee the quoted minimum";
|
|
227
|
+
if (p.dca !== null || p.boostFeeBps !== 0 || p.broker.feeBps !== 0 || p.affiliates.length) return "DCA, boost, a broker fee or affiliates";
|
|
228
|
+
return null;
|
|
229
|
+
};
|
|
230
|
+
if (params.sourceChain.startsWith("eip155:")) {
|
|
231
|
+
const tx = quote.txRequest;
|
|
232
|
+
if (quote.depositAddress || !tx?.data || tx.serializedTx !== void 0) return "an EVM vault swap is a vault call, not a deposit";
|
|
233
|
+
if (!tx.to || tx.to.toLowerCase() !== vault.toLowerCase()) return `the call targets ${tx.to}, not the Vault`;
|
|
234
|
+
const v = decodeEvmVaultCall(tx.data);
|
|
235
|
+
if (v.dstChain !== dstChain.id || v.dstToken !== dst.id || !sameBytes(v.dstAddress, dest)) return "the vault call names another destination";
|
|
236
|
+
if (src.token === null) {
|
|
237
|
+
if (!v.native || BigInt(tx.value ?? "0") !== amountIn || tx.approvalAddress) return "the native vault call moves another amount";
|
|
238
|
+
} else if (v.native || v.srcToken?.toLowerCase() !== src.token.toLowerCase() || v.amount !== amountIn || BigInt(tx.value ?? "0") !== 0n || tx.approvalAddress?.toLowerCase() !== vault.toLowerCase()) {
|
|
239
|
+
return "the token vault call moves another token or amount";
|
|
240
|
+
}
|
|
241
|
+
return checkParams(v.params);
|
|
242
|
+
}
|
|
243
|
+
if (quote.txRequest || quote.depositAddress !== vault || !quote.depositMemo) return "a Tron vault swap is a send to the Tron Vault with its note";
|
|
244
|
+
const n = decodeTronNote(quote.depositMemo);
|
|
245
|
+
if (n.outputAsset !== dst.id || n.destTag !== dstChain.addrTag || !sameBytes(n.destAddress, dest)) return "the note names another destination";
|
|
246
|
+
return checkParams(n.params);
|
|
247
|
+
} catch (e) {
|
|
248
|
+
return `the vault swap does not decode (${(e instanceof Error ? e.message : String(e)).slice(0, 120)})`;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
var chainflipPins = Object.freeze({
|
|
252
|
+
callTargets: (chain) => chainflipVaultFor(chain),
|
|
253
|
+
spenders: (chain) => chainflipVaultFor(chain),
|
|
254
|
+
verifyQuote: chainflipVerifyQuote,
|
|
255
|
+
verifyBuild: (quote, tx) => quote.depositMemo && tx.memoEncoding !== "hex" ? "the Tron note is not sent as hex bytes" : null,
|
|
256
|
+
depositAddressRoutes: true
|
|
257
|
+
});
|
|
258
|
+
function chainflipVaultFor(chain) {
|
|
259
|
+
const vault = chain.startsWith("eip155:") && Object.prototype.hasOwnProperty.call(CF_VAULTS, chain) ? CF_VAULTS[chain] : void 0;
|
|
260
|
+
return vault ? [vault] : [];
|
|
261
|
+
}
|
|
74
262
|
//# sourceMappingURL=config.cjs.map
|
package/dist/config.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts"],"sourcesContent":["/**\n * Chainflip (JIT-AMM state chain) — chains, assets and contracts as the public backend and the vault encodings name them.\n * Asset ids, chain ids and decimals are the protocol's own (`cf_environment` / networkInfo, verified 2026-10-20); the\n * contract addresses are Chainflip's mainnet deployments (docs mainnet-addresses, confirmed by live encodings).\n *\n * Only VAULT SWAPS are offered: the donor signs a transaction whose every Chainflip parameter (destination, minimum price,\n * refund address) is decoded and checked locally before signing — no off-chain deposit channel to trust, and on Tron no\n * 3.4 USDT ingress fee. Sources: EVM (Ethereum, Arbitrum) and Tron in this release; Solana / Bitcoin vault swaps need an\n * instruction / OP_RETURN builder and come next. Destinations: every live chain.\n */\nexport type CfChain = \"Ethereum\" | \"Bitcoin\" | \"Arbitrum\" | \"Solana\" | \"Tron\";\n\nexport interface CfAsset {\n chain: CfChain;\n /** the API's asset symbol */\n asset: string;\n /** the u32 asset id inside vault encodings */\n id: number;\n decimals: number;\n /** token contract / mint on its chain, null for the native coin */\n token: string | null;\n /** smallest deposit the state chain accepts (base units) */\n minDeposit: bigint;\n}\n\n/**\n * CAIP-2 → Chainflip chain: `id` = the ForeignChain number an EVM vault call names (`dstChain`), `addrTag` = the\n * EncodedAddress variant a Tron note names (Eth 0, Dot 1, Btc 2, Arb 3, Sol 4, Hub 5, Tron 6) — two different enums.\n */\nexport const CF_CHAINS: Readonly<Record<string, {name: CfChain; id: number; addrTag: number}>> = {\n \"eip155:1\": {name: \"Ethereum\", id: 1, addrTag: 0},\n \"bitcoin:mainnet\": {name: \"Bitcoin\", id: 3, addrTag: 2},\n \"eip155:42161\": {name: \"Arbitrum\", id: 4, addrTag: 3},\n \"solana:mainnet\": {name: \"Solana\", id: 5, addrTag: 4},\n \"tron:728126428\": {name: \"Tron\", id: 7, addrTag: 6},\n};\n\nexport const CF_ASSETS: readonly CfAsset[] = [\n {chain: \"Ethereum\", asset: \"ETH\", id: 1, decimals: 18, token: null, minDeposit: 10n ** 16n},\n {chain: \"Ethereum\", asset: \"USDC\", id: 3, decimals: 6, token: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\", minDeposit: 20_000_000n},\n {chain: \"Ethereum\", asset: \"USDT\", id: 8, decimals: 6, token: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\", minDeposit: 20_000_000n},\n {chain: \"Ethereum\", asset: \"WBTC\", id: 14, decimals: 8, token: \"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599\", minDeposit: 40_000n},\n {chain: \"Bitcoin\", asset: \"BTC\", id: 5, decimals: 8, token: null, minDeposit: 40_000n},\n {chain: \"Arbitrum\", asset: \"ETH\", id: 6, decimals: 18, token: null, minDeposit: 3_900_000_000_000_000n},\n {chain: \"Arbitrum\", asset: \"USDC\", id: 7, decimals: 6, token: \"0xaf88d065e77c8cC2239327C5EDb3A432268e5831\", minDeposit: 10_000_000n},\n {chain: \"Arbitrum\", asset: \"USDT\", id: 15, decimals: 6, token: \"0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9\", minDeposit: 10_000_000n},\n {chain: \"Solana\", asset: \"SOL\", id: 9, decimals: 9, token: null, minDeposit: 68_000_000n},\n {chain: \"Solana\", asset: \"USDC\", id: 10, decimals: 6, token: \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\", minDeposit: 10_000_000n},\n {chain: \"Solana\", asset: \"USDT\", id: 16, decimals: 6, token: \"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB\", minDeposit: 10_000_000n},\n {chain: \"Tron\", asset: \"TRX\", id: 17, decimals: 6, token: null, minDeposit: 30_000_000n},\n {chain: \"Tron\", asset: \"USDT\", id: 18, decimals: 6, token: \"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t\", minDeposit: 10_000_000n},\n];\n\n/** Vault contracts that receive vault swaps (the deposit transaction's target). */\nexport const CF_VAULTS: Readonly<Record<string, string>> = {\n \"eip155:1\": \"0xF5e10380213880111522dd0efD3dbb45b9f62Bcc\",\n \"eip155:42161\": \"0x79001a5e762f3bEFC8e5871b42F6734e00498920\",\n \"tron:728126428\": \"TEcDijvKSXcfWT7S6rd44H5vNgufm7Y4XC\",\n};\n\n/** Sources this release signs (vault swaps the engine can execute and the verifier can decode). */\nexport const CF_SOURCE_CHAINS = new Set([\"eip155:1\", \"eip155:42161\", \"tron:728126428\"]);\n\nexport const CF_API_DEFAULT = \"https://chainflip-swap.chainflip.io\";\n\nconst sameToken = (chain: string, a: string, b: string) => (chain.startsWith(\"eip155:\") ? a.toLowerCase() === b.toLowerCase() : a === b);\nconst NATIVE = new Set([\"\", \"native\", \"0x0000000000000000000000000000000000000000\"]);\n\n/** The Chainflip asset for a CAIP-2 chain + token (contract / mint, a native marker, or the asset symbol). */\nexport function cfAsset(chain: string, token: string): CfAsset | undefined {\n const c = CF_CHAINS[chain];\n if (!c) return undefined;\n const on = CF_ASSETS.filter((a) => a.chain === c.name);\n if (NATIVE.has(token.toLowerCase())) return on.find((a) => a.token === null);\n return on.find((a) => (a.token !== null && sameToken(chain, a.token, token)) || a.asset === token.toUpperCase());\n}\n\nexport const chainflip = {\n supportsChain: (chain: string) => !!CF_CHAINS[chain],\n supports: (from: string, to: string) => CF_SOURCE_CHAINS.has(from) && !!CF_CHAINS[to] && from !== to,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6BO,IAAM,YAAoF;AAAA,EAC/F,YAAY,EAAC,MAAM,YAAY,IAAI,GAAG,SAAS,EAAC;AAAA,EAChD,mBAAmB,EAAC,MAAM,WAAW,IAAI,GAAG,S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,gDAAgD,YAAY,UAAW;AAAA,EACpI,EAAC,OAAO,QAAQ,OAAO,OAAO,IAAI,IAAI,UAAU,GAAG,OAAO,MAAM,YAAY,UAAW;AAAA,EACvF,EAAC,OAAO,QAAQ,OAAO,QAAQ,IAAI,IAAI,UAAU,GAAG,OAAO,sCAAsC,YAAY,UAAW;AAC1H;AAGO,IAAM,YAA8C;AAAA,EACzD,YAAY;AAAA,EACZ,gBAAgB;AAAA,EAChB,kBAAkB;AACpB;AAGO,IAAM,mBAAmB,oBAAI,IAAI,CAAC,YAAY,gBAAgB,gBAAgB,CAAC;AAE/E,IAAM,iBAAiB;AAE9B,IAAM,YAAY,CAAC,OAAe,GAAW,MAAe,MAAM,WAAW,SAAS,IAAI,EAAE,YAAY,MAAM,EAAE,YAAY,IAAI,MAAM;AACtI,IAAM,SAAS,oBAAI,IAAI,CAAC,IAAI,UAAU,4CAA4C,CAAC;AAG5E,SAAS,QAAQ,OAAe,OAAoC;AACzE,QAAM,IAAI,UAAU,KAAK;AACzB,MAAI,CAAC,EAAG,QAAO;AACf,QAAM,KAAK,UAAU,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI;AACrD,MAAI,OAAO,IAAI,MAAM,YAAY,CAAC,EAAG,QAAO,GAAG,KAAK,CAAC,MAAM,EAAE,UAAU,IAAI;AAC3E,SAAO,GAAG,KAAK,CAAC,MAAO,EAAE,UAAU,QAAQ,UAAU,OAAO,EAAE,OAAO,KAAK,KAAM,EAAE,UAAU,MAAM,YAAY,CAAC;AACjH;AAEO,IAAM,YAAY;AAAA,EACvB,eAAe,CAAC,UAAkB,CAAC,CAAC,UAAU,KAAK;AAAA,EACnD,UAAU,CAAC,MAAc,OAAe,iBAAiB,IAAI,IAAI,KAAK,CAAC,CAAC,UAAU,EAAE,KAAK,SAAS;AACpG;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/codec.ts"],"sourcesContent":["/**\n * Chainflip (JIT-AMM state chain) — chains, assets and contracts as the public backend and the vault encodings name them.\n * Asset ids, chain ids and decimals are the protocol's own (`cf_environment` / networkInfo, verified 2026-10-20); the\n * contract addresses are Chainflip's mainnet deployments (docs mainnet-addresses, confirmed by live encodings).\n *\n * Only VAULT SWAPS are offered: the donor signs a transaction whose every Chainflip parameter (destination, minimum price,\n * refund address) is decoded and checked locally before signing — no off-chain deposit channel to trust, and on Tron no\n * 3.4 USDT ingress fee. Sources: EVM (Ethereum, Arbitrum) and Tron in this release; Solana / Bitcoin vault swaps need an\n * instruction / OP_RETURN builder and come next. Destinations: every live chain.\n */\nimport type {Quote, QuoteParams, RemotePins, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {decodeEvmVaultCall, decodeTronNote, destAddressBytes, fromHex, minOutOf, sameBytes, type CfParameters} from \"./codec.js\";\n\nexport type CfChain = \"Ethereum\" | \"Bitcoin\" | \"Arbitrum\" | \"Solana\" | \"Tron\";\n\nexport interface CfAsset {\n chain: CfChain;\n /** the API's asset symbol */\n asset: string;\n /** the u32 asset id inside vault encodings */\n id: number;\n decimals: number;\n /** token contract / mint on its chain, null for the native coin */\n token: string | null;\n /** smallest deposit the state chain accepts (base units) */\n minDeposit: bigint;\n}\n\n/**\n * CAIP-2 → Chainflip chain: `id` = the ForeignChain number an EVM vault call names (`dstChain`), `addrTag` = the\n * EncodedAddress variant a Tron note names (Eth 0, Dot 1, Btc 2, Arb 3, Sol 4, Hub 5, Tron 6) — two different enums.\n */\nexport const CF_CHAINS: Readonly<Record<string, {name: CfChain; id: number; addrTag: number}>> = {\n \"eip155:1\": {name: \"Ethereum\", id: 1, addrTag: 0},\n \"bitcoin:mainnet\": {name: \"Bitcoin\", id: 3, addrTag: 2},\n \"eip155:42161\": {name: \"Arbitrum\", id: 4, addrTag: 3},\n \"solana:mainnet\": {name: \"Solana\", id: 5, addrTag: 4},\n \"tron:728126428\": {name: \"Tron\", id: 7, addrTag: 6},\n};\n\nexport const CF_ASSETS: readonly CfAsset[] = [\n {chain: \"Ethereum\", asset: \"ETH\", id: 1, decimals: 18, token: null, minDeposit: 10n ** 16n},\n {chain: \"Ethereum\", asset: \"USDC\", id: 3, decimals: 6, token: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\", minDeposit: 20_000_000n},\n {chain: \"Ethereum\", asset: \"USDT\", id: 8, decimals: 6, token: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\", minDeposit: 20_000_000n},\n {chain: \"Ethereum\", asset: \"WBTC\", id: 14, decimals: 8, token: \"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599\", minDeposit: 40_000n},\n {chain: \"Bitcoin\", asset: \"BTC\", id: 5, decimals: 8, token: null, minDeposit: 40_000n},\n {chain: \"Arbitrum\", asset: \"ETH\", id: 6, decimals: 18, token: null, minDeposit: 3_900_000_000_000_000n},\n {chain: \"Arbitrum\", asset: \"USDC\", id: 7, decimals: 6, token: \"0xaf88d065e77c8cC2239327C5EDb3A432268e5831\", minDeposit: 10_000_000n},\n {chain: \"Arbitrum\", asset: \"USDT\", id: 15, decimals: 6, token: \"0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9\", minDeposit: 10_000_000n},\n {chain: \"Solana\", asset: \"SOL\", id: 9, decimals: 9, token: null, minDeposit: 68_000_000n},\n {chain: \"Solana\", asset: \"USDC\", id: 10, decimals: 6, token: \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\", minDeposit: 10_000_000n},\n {chain: \"Solana\", asset: \"USDT\", id: 16, decimals: 6, token: \"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB\", minDeposit: 10_000_000n},\n {chain: \"Tron\", asset: \"TRX\", id: 17, decimals: 6, token: null, minDeposit: 30_000_000n},\n {chain: \"Tron\", asset: \"USDT\", id: 18, decimals: 6, token: \"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t\", minDeposit: 10_000_000n},\n];\n\n/** Vault contracts that receive vault swaps (the deposit transaction's target). */\nexport const CF_VAULTS: Readonly<Record<string, string>> = {\n \"eip155:1\": \"0xF5e10380213880111522dd0efD3dbb45b9f62Bcc\",\n \"eip155:42161\": \"0x79001a5e762f3bEFC8e5871b42F6734e00498920\",\n \"tron:728126428\": \"TEcDijvKSXcfWT7S6rd44H5vNgufm7Y4XC\",\n};\n\n/** Sources this release signs (vault swaps the engine can execute and the verifier can decode). */\nexport const CF_SOURCE_CHAINS = new Set([\"eip155:1\", \"eip155:42161\", \"tron:728126428\"]);\n\nexport const CF_API_DEFAULT = \"https://chainflip-swap.chainflip.io\";\n\nconst sameToken = (chain: string, a: string, b: string) => (chain.startsWith(\"eip155:\") ? a.toLowerCase() === b.toLowerCase() : a === b);\nconst NATIVE = new Set([\"\", \"native\", \"0x0000000000000000000000000000000000000000\"]);\n\n/** The Chainflip asset for a CAIP-2 chain + token (contract / mint, a native marker, or the asset symbol). */\nexport function cfAsset(chain: string, token: string): CfAsset | undefined {\n const c = CF_CHAINS[chain];\n if (!c) return undefined;\n const on = CF_ASSETS.filter((a) => a.chain === c.name);\n if (NATIVE.has(token.toLowerCase())) return on.find((a) => a.token === null);\n return on.find((a) => (a.token !== null && sameToken(chain, a.token, token)) || a.asset === token.toUpperCase());\n}\n\nexport const chainflip = {\n supportsChain: (chain: string) => !!CF_CHAINS[chain],\n supports: (from: string, to: string) => CF_SOURCE_CHAINS.has(from) && !!CF_CHAINS[to] && from !== to,\n};\n\n/**\n * The provider's own decode of a vault swap, run on the client against the app's request (scan 2026-10-28, F9): an\n * EVM source is a vault call (`xSwapNative` / `xSwapToken`) on the pinned Vault, a Tron source a send to the pinned\n * Tron Vault whose note carries the swap; either way the destination chain, asset and address, the source token and\n * amount, the refund address and a minimum price that guarantees the quoted minimum must be the app's, with no DCA,\n * boost, broker fee or affiliates. The reason it fails, or null.\n */\nexport function chainflipVerifyQuote(params: QuoteParams, quote: Quote): string | null {\n try {\n const src = cfAsset(params.sourceChain, params.sourceToken);\n const dst = cfAsset(params.destChain, params.destToken);\n const dstChain = CF_CHAINS[params.destChain];\n const vault = Object.prototype.hasOwnProperty.call(CF_VAULTS, params.sourceChain) ? CF_VAULTS[params.sourceChain] : undefined;\n if (!src || !dst || !dstChain || !vault || !CF_SOURCE_CHAINS.has(params.sourceChain)) return \"not a vault swap this release signs\";\n // A dry quote lists a route and pays nobody; execution re-quotes live.\n if (!quote.txRequest && !quote.depositAddress) return null;\n if (!params.refundAddress) return \"a live quote needs the refund address\";\n const amountIn = BigInt(params.amountIn);\n const dest = destAddressBytes(params.destChain, params.destAddress);\n const refund = destAddressBytes(params.sourceChain, params.refundAddress);\n const checkParams = (p: CfParameters): string | null => {\n if (!sameBytes(fromHex(p.refundAddress), refund)) return \"the refund address is not the sender\";\n if (minOutOf(amountIn, p.minPriceX128) < BigInt(quote.minDestAmount)) return \"the minimum price does not guarantee the quoted minimum\";\n if (p.dca !== null || p.boostFeeBps !== 0 || p.broker.feeBps !== 0 || p.affiliates.length) return \"DCA, boost, a broker fee or affiliates\";\n return null;\n };\n if (params.sourceChain.startsWith(\"eip155:\")) {\n const tx = quote.txRequest;\n if (quote.depositAddress || !tx?.data || tx.serializedTx !== undefined) return \"an EVM vault swap is a vault call, not a deposit\";\n if (!tx.to || tx.to.toLowerCase() !== vault.toLowerCase()) return `the call targets ${tx.to}, not the Vault`;\n const v = decodeEvmVaultCall(tx.data);\n if (v.dstChain !== dstChain.id || v.dstToken !== dst.id || !sameBytes(v.dstAddress, dest)) return \"the vault call names another destination\";\n if (src.token === null) {\n if (!v.native || BigInt(tx.value ?? \"0\") !== amountIn || tx.approvalAddress) return \"the native vault call moves another amount\";\n } else if (v.native || v.srcToken?.toLowerCase() !== src.token.toLowerCase() || v.amount !== amountIn || BigInt(tx.value ?? \"0\") !== 0n ||\n tx.approvalAddress?.toLowerCase() !== vault.toLowerCase()) {\n return \"the token vault call moves another token or amount\";\n }\n return checkParams(v.params);\n }\n // Tron: the deposit is a send of the input to the Vault, the swap riding in the note.\n if (quote.txRequest || quote.depositAddress !== vault || !quote.depositMemo) return \"a Tron vault swap is a send to the Tron Vault with its note\";\n const n = decodeTronNote(quote.depositMemo);\n if (n.outputAsset !== dst.id || n.destTag !== dstChain.addrTag || !sameBytes(n.destAddress, dest)) return \"the note names another destination\";\n return checkParams(n.params);\n } catch (e) {\n return `the vault swap does not decode (${(e instanceof Error ? e.message : String(e)).slice(0, 120)})`;\n }\n}\n\n/**\n * The Chainflip Vault a vault swap calls and approves on an EVM chain ({@link CF_VAULTS}), and\n * {@link chainflipVerifyQuote} — the app's pins for `remoteProvider({name: \"chainflip\", baseUrl, ...chainflipPins})`\n * (scan 2026-10-27 modules, F8/F16). A Tron vault swap is a send to the Tron Vault the verifier pins, so the stub is\n * opened to that deposit route (`depositAddressRoutes`, scan 2026-10-28 F9); its note must ride as hex bytes.\n */\nexport const chainflipPins: RemotePins = Object.freeze({\n callTargets: (chain: string): readonly string[] => chainflipVaultFor(chain),\n spenders: (chain: string): readonly string[] => chainflipVaultFor(chain),\n verifyQuote: chainflipVerifyQuote,\n verifyBuild: (quote: Quote, tx: UnsignedTx): string | null =>\n quote.depositMemo && tx.memoEncoding !== \"hex\" ? \"the Tron note is not sent as hex bytes\" : null,\n depositAddressRoutes: true,\n});\nfunction chainflipVaultFor(chain: string): readonly string[] {\n const vault = chain.startsWith(\"eip155:\") && Object.prototype.hasOwnProperty.call(CF_VAULTS, chain) ? CF_VAULTS[chain] : undefined;\n return vault ? [vault] : [];\n}\n","/**\n * Decoders for what Chainflip's encoder returns, so a vault swap is checked byte by byte before anyone signs it:\n * - VersionedCfParameters (SCALE): retry window, refund address, minimum price (X128), oracle slippage, DCA, boost,\n * broker + its fee, affiliates — the EVM vault call's `cfParameters` and the tail of the Tron note;\n * - the Tron note: output asset id, encoded destination address, CCM option, then the length-prefixed parameters;\n * - the EVM vault calls xSwapNative / xSwapToken.\n * Layouts were decoded from live encoder outputs (2026-10-20) and match the state chain's types.\n */\nimport {base58} from \"@scure/base\";\nimport {sha256} from \"@noble/hashes/sha2.js\";\nimport {decodeFunctionData, parseAbi, type Hex} from \"viem\";\n\nexport interface CfParameters {\n version: number;\n retryDurationBlocks: number;\n /** raw refund address bytes (20 for EVM / Tron, 32 for Solana) as 0x-hex */\n refundAddress: Hex;\n /** minimum output price × 2^128, scaled by 10^(destDecimals − srcDecimals) */\n minPriceX128: bigint;\n refundCcm: boolean;\n maxOraclePriceSlippageBps: number | null;\n dca: {chunks: number; intervalBlocks: number} | null;\n boostFeeBps: number;\n broker: {account: Hex; feeBps: number};\n affiliates: {account: number; feeBps: number}[];\n}\n\nclass Reader {\n i = 0;\n constructor(readonly b: Uint8Array) {}\n need(n: number) { if (this.i + n > this.b.length) throw new Error(`chainflip codec: truncated at ${this.i} (+${n} of ${this.b.length})`); }\n u8() { this.need(1); return this.b[this.i++]!; }\n bytes(n: number) { this.need(n); const out = this.b.slice(this.i, this.i + n); this.i += n; return out; }\n uLE(n: number): bigint { const x = this.bytes(n); let v = 0n; for (let k = n - 1; k >= 0; k--) v = (v << 8n) | BigInt(x[k]!); return v; }\n /** Little-endian unsigned of up to 6 bytes as a number (exact: below 2^48). */\n uNum(n: number): number { if (n > 6) throw new Error(\"chainflip codec: uNum takes at most 6 bytes\"); const x = this.bytes(n); let v = 0; for (let k = n - 1; k >= 0; k--) v = v * 256 + x[k]!; return v; }\n /** SCALE compact integer */\n compact(): number {\n const first = this.u8();\n const mode = first & 3;\n if (mode === 0) return first >> 2;\n if (mode === 1) return ((this.u8() << 8) | first) >> 2;\n if (mode === 2) { const rest = this.uNum(3); return ((rest << 8) | first) >>> 2; }\n throw new Error(\"chainflip codec: big compact integers are not used here\");\n }\n done() { if (this.i !== this.b.length) throw new Error(`chainflip codec: ${this.b.length - this.i} trailing bytes`); }\n}\n\nexport const toHex = (b: Uint8Array): Hex => `0x${[...b].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\")}` as Hex;\nexport function fromHex(h: string): Uint8Array {\n const s = h.startsWith(\"0x\") ? h.slice(2) : h;\n if (s.length % 2 || /[^0-9a-f]/i.test(s)) throw new Error(\"chainflip codec: not hex\");\n return Uint8Array.from(s.match(/../g) ?? [], (x) => Number.parseInt(x, 16));\n}\n\n/** VersionedCfParameters V1. `refundLen` = 20 for EVM / Tron sources, 32 for Solana. */\nexport function decodeCfParameters(bytes: Uint8Array, refundLen: 20 | 32): CfParameters {\n const r = new Reader(bytes);\n const p = readCfParameters(r, refundLen);\n r.done();\n return p;\n}\n\nfunction readCfParameters(r: Reader, refundLen: number): CfParameters {\n const version = r.u8();\n if (version !== 1) throw new Error(`chainflip codec: cf parameters version ${version}`);\n // ccm_additional_data is `()` for non-CCM swaps: zero bytes\n const retryDurationBlocks = r.uNum(4);\n const refundAddress = toHex(r.bytes(refundLen));\n const minPriceX128 = r.uLE(32);\n const refundCcm = r.u8() !== 0;\n if (refundCcm) throw new Error(\"chainflip codec: refund CCM metadata is not expected\");\n const maxOraclePriceSlippageBps = r.u8() ? r.uNum(2) : null;\n const dca = r.u8() ? {chunks: r.uNum(4), intervalBlocks: r.uNum(4)} : null;\n const boostFeeBps = r.u8();\n const broker = {account: toHex(r.bytes(32)), feeBps: r.uNum(2)};\n const n = r.compact();\n const affiliates = Array.from({length: n}, () => ({account: r.u8(), feeBps: r.uNum(2)}));\n return {version, retryDurationBlocks, refundAddress, minPriceX128, refundCcm, maxOraclePriceSlippageBps, dca, boostFeeBps, broker, affiliates};\n}\n\nexport interface TronNote {\n outputAsset: number;\n /** EncodedAddress variant of the destination (Eth 0, Dot 1, Btc 2, Arb 3, Sol 4, Hub 5, Tron 6) and its raw bytes */\n destTag: number;\n destAddress: Uint8Array;\n ccm: boolean;\n params: CfParameters;\n}\n\n/** Address byte length per encoded-address tag (EncodedAddress enum: Eth, Dot, Btc, Arb, Sol, Hub, Tron …). */\nconst TAG_LEN: Record<number, number | \"vec\"> = {0: 20, 1: 32, 2: \"vec\", 3: 20, 4: 32, 5: 32, 6: 20};\n\n/** The note a Tron vault swap carries in raw_data.data. */\nexport function decodeTronNote(note: string): TronNote {\n const r = new Reader(fromHex(note));\n const outputAsset = r.u8();\n const destTag = r.u8();\n const len = TAG_LEN[destTag];\n if (len === undefined) throw new Error(`chainflip codec: unknown address tag ${destTag}`);\n const destAddress = len === \"vec\" ? r.bytes(r.compact()) : r.bytes(len);\n const ccm = r.u8() !== 0;\n if (ccm) throw new Error(\"chainflip codec: CCM swaps are not expected\");\n const paramsLen = r.compact();\n const start = r.i;\n const params = readCfParameters(r, 20);\n if (r.i - start !== paramsLen) throw new Error(`chainflip codec: cf parameters length ${r.i - start} ≠ declared ${paramsLen}`);\n r.done();\n return {outputAsset, destTag, destAddress, ccm, params};\n}\n\nconst VAULT_ABI = parseAbi([\n \"function xSwapNative(uint32 dstChain, bytes dstAddress, uint32 dstToken, bytes cfParameters) payable\",\n \"function xSwapToken(uint32 dstChain, bytes dstAddress, uint32 dstToken, address srcToken, uint256 amount, bytes cfParameters)\",\n]);\n\nexport interface EvmVaultCall {\n native: boolean;\n dstChain: number;\n dstAddress: Uint8Array;\n dstToken: number;\n srcToken: string | null;\n amount: bigint | null;\n params: CfParameters;\n}\n\nexport function decodeEvmVaultCall(data: string): EvmVaultCall {\n const d = decodeFunctionData({abi: VAULT_ABI, data: data as Hex});\n if (d.functionName === \"xSwapNative\") {\n const [dstChain, dstAddress, dstToken, cf] = d.args;\n return {native: true, dstChain, dstAddress: fromHex(dstAddress), dstToken, srcToken: null, amount: null, params: decodeCfParameters(fromHex(cf), 20)};\n }\n const [dstChain, dstAddress, dstToken, srcToken, amount, cf] = d.args;\n return {native: false, dstChain, dstAddress: fromHex(dstAddress), dstToken, srcToken, amount, params: decodeCfParameters(fromHex(cf), 20)};\n}\n\n/** Tron base58check `T…` ↔ the 20 raw bytes Chainflip encodes (0x41 prefix dropped). */\nexport function tronToBytes(address: string): Uint8Array {\n const b = base58.decode(address);\n if (b.length !== 25 || b[0] !== 0x41) throw new Error(`not a Tron address: ${address}`);\n const check = sha256(sha256(b.subarray(0, 21))).subarray(0, 4);\n if (toHex(check) !== toHex(b.subarray(21))) throw new Error(`bad Tron checksum: ${address}`);\n return b.subarray(1, 21);\n}\n\n/** The raw bytes a destination address is encoded with, per destination chain (EVM / Tron 20, Solana 32, BTC ASCII). */\nexport function destAddressBytes(chain: string, address: string): Uint8Array {\n if (chain.startsWith(\"eip155:\")) return fromHex(address);\n if (chain.startsWith(\"tron:\")) return tronToBytes(address);\n if (chain.startsWith(\"solana:\")) { const b = base58.decode(address); if (b.length !== 32) throw new Error(`not a Solana address: ${address}`); return b; }\n if (chain.startsWith(\"bitcoin:\")) return new TextEncoder().encode(address);\n throw new Error(`chainflip: no address encoding for ${chain}`);\n}\n\nexport const sameBytes = (a: Uint8Array, b: Uint8Array) => a.length === b.length && a.every((x, i) => x === b[i]);\n\n/** minPriceX128 for a guaranteed output: ceil(minOut × 2^128 / amountIn) (base units on both sides carry the decimals). */\nexport function minPriceX128For(amountIn: bigint, minOut: bigint): bigint {\n return (minOut * 2n ** 128n + amountIn - 1n) / amountIn;\n}\n/** The output a min price guarantees for `amountIn` (floor). */\nexport function minOutOf(amountIn: bigint, minPriceX128: bigint): bigint {\n return (amountIn * minPriceX128) / 2n ** 128n;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQA,kBAAqB;AACrB,kBAAqB;AACrB,kBAAqD;AAiBrD,IAAM,SAAN,MAAa;AAAA,EAEX,YAAqB,GAAe;AAAf;AAAA,EAAgB;AAAA,EAAhB;AAAA,EADrB,IAAI;AAAA,EAEJ,KAAK,GAAW;AAAE,QAAI,KAAK,IAAI,IAAI,KAAK,EAAE,OAAQ,OAAM,IAAI,MAAM,iCAAiC,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,EAAE,MAAM,GAAG;AAAA,EAAG;AAAA,EAC1I,KAAK;AAAE,SAAK,KAAK,CAAC;AAAG,WAAO,KAAK,EAAE,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AK,IAAI;AACzH,SAAO,QAAQ,CAAC,KAAK,IAAI,CAAC;AAC5B;","names":["dstChain","dstAddress","dstToken","cf"]}
|
package/dist/config.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RemotePins, QuoteParams, Quote } from '@anywalletkit/protocol-swap2-core/types';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Chainflip (JIT-AMM state chain) — chains, assets and contracts as the public backend and the vault encodings name them.
|
|
3
5
|
* Asset ids, chain ids and decimals are the protocol's own (`cf_environment` / networkInfo, verified 2026-10-20); the
|
|
@@ -8,6 +10,7 @@
|
|
|
8
10
|
* 3.4 USDT ingress fee. Sources: EVM (Ethereum, Arbitrum) and Tron in this release; Solana / Bitcoin vault swaps need an
|
|
9
11
|
* instruction / OP_RETURN builder and come next. Destinations: every live chain.
|
|
10
12
|
*/
|
|
13
|
+
|
|
11
14
|
type CfChain = "Ethereum" | "Bitcoin" | "Arbitrum" | "Solana" | "Tron";
|
|
12
15
|
interface CfAsset {
|
|
13
16
|
chain: CfChain;
|
|
@@ -42,5 +45,20 @@ declare const chainflip: {
|
|
|
42
45
|
supportsChain: (chain: string) => boolean;
|
|
43
46
|
supports: (from: string, to: string) => boolean;
|
|
44
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* The provider's own decode of a vault swap, run on the client against the app's request (scan 2026-10-28, F9): an
|
|
50
|
+
* EVM source is a vault call (`xSwapNative` / `xSwapToken`) on the pinned Vault, a Tron source a send to the pinned
|
|
51
|
+
* Tron Vault whose note carries the swap; either way the destination chain, asset and address, the source token and
|
|
52
|
+
* amount, the refund address and a minimum price that guarantees the quoted minimum must be the app's, with no DCA,
|
|
53
|
+
* boost, broker fee or affiliates. The reason it fails, or null.
|
|
54
|
+
*/
|
|
55
|
+
declare function chainflipVerifyQuote(params: QuoteParams, quote: Quote): string | null;
|
|
56
|
+
/**
|
|
57
|
+
* The Chainflip Vault a vault swap calls and approves on an EVM chain ({@link CF_VAULTS}), and
|
|
58
|
+
* {@link chainflipVerifyQuote} — the app's pins for `remoteProvider({name: "chainflip", baseUrl, ...chainflipPins})`
|
|
59
|
+
* (scan 2026-10-27 modules, F8/F16). A Tron vault swap is a send to the Tron Vault the verifier pins, so the stub is
|
|
60
|
+
* opened to that deposit route (`depositAddressRoutes`, scan 2026-10-28 F9); its note must ride as hex bytes.
|
|
61
|
+
*/
|
|
62
|
+
declare const chainflipPins: RemotePins;
|
|
45
63
|
|
|
46
|
-
export { CF_API_DEFAULT, CF_ASSETS, CF_CHAINS, CF_SOURCE_CHAINS, CF_VAULTS, type CfAsset, type CfChain, cfAsset, chainflip };
|
|
64
|
+
export { CF_API_DEFAULT, CF_ASSETS, CF_CHAINS, CF_SOURCE_CHAINS, CF_VAULTS, type CfAsset, type CfChain, cfAsset, chainflip, chainflipPins, chainflipVerifyQuote };
|
package/dist/config.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RemotePins, QuoteParams, Quote } from '@anywalletkit/protocol-swap2-core/types';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Chainflip (JIT-AMM state chain) — chains, assets and contracts as the public backend and the vault encodings name them.
|
|
3
5
|
* Asset ids, chain ids and decimals are the protocol's own (`cf_environment` / networkInfo, verified 2026-10-20); the
|
|
@@ -8,6 +10,7 @@
|
|
|
8
10
|
* 3.4 USDT ingress fee. Sources: EVM (Ethereum, Arbitrum) and Tron in this release; Solana / Bitcoin vault swaps need an
|
|
9
11
|
* instruction / OP_RETURN builder and come next. Destinations: every live chain.
|
|
10
12
|
*/
|
|
13
|
+
|
|
11
14
|
type CfChain = "Ethereum" | "Bitcoin" | "Arbitrum" | "Solana" | "Tron";
|
|
12
15
|
interface CfAsset {
|
|
13
16
|
chain: CfChain;
|
|
@@ -42,5 +45,20 @@ declare const chainflip: {
|
|
|
42
45
|
supportsChain: (chain: string) => boolean;
|
|
43
46
|
supports: (from: string, to: string) => boolean;
|
|
44
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* The provider's own decode of a vault swap, run on the client against the app's request (scan 2026-10-28, F9): an
|
|
50
|
+
* EVM source is a vault call (`xSwapNative` / `xSwapToken`) on the pinned Vault, a Tron source a send to the pinned
|
|
51
|
+
* Tron Vault whose note carries the swap; either way the destination chain, asset and address, the source token and
|
|
52
|
+
* amount, the refund address and a minimum price that guarantees the quoted minimum must be the app's, with no DCA,
|
|
53
|
+
* boost, broker fee or affiliates. The reason it fails, or null.
|
|
54
|
+
*/
|
|
55
|
+
declare function chainflipVerifyQuote(params: QuoteParams, quote: Quote): string | null;
|
|
56
|
+
/**
|
|
57
|
+
* The Chainflip Vault a vault swap calls and approves on an EVM chain ({@link CF_VAULTS}), and
|
|
58
|
+
* {@link chainflipVerifyQuote} — the app's pins for `remoteProvider({name: "chainflip", baseUrl, ...chainflipPins})`
|
|
59
|
+
* (scan 2026-10-27 modules, F8/F16). A Tron vault swap is a send to the Tron Vault the verifier pins, so the stub is
|
|
60
|
+
* opened to that deposit route (`depositAddressRoutes`, scan 2026-10-28 F9); its note must ride as hex bytes.
|
|
61
|
+
*/
|
|
62
|
+
declare const chainflipPins: RemotePins;
|
|
45
63
|
|
|
46
|
-
export { CF_API_DEFAULT, CF_ASSETS, CF_CHAINS, CF_SOURCE_CHAINS, CF_VAULTS, type CfAsset, type CfChain, cfAsset, chainflip };
|
|
64
|
+
export { CF_API_DEFAULT, CF_ASSETS, CF_CHAINS, CF_SOURCE_CHAINS, CF_VAULTS, type CfAsset, type CfChain, cfAsset, chainflip, chainflipPins, chainflipVerifyQuote };
|
package/dist/config.js
CHANGED
|
@@ -5,8 +5,11 @@ import {
|
|
|
5
5
|
CF_SOURCE_CHAINS,
|
|
6
6
|
CF_VAULTS,
|
|
7
7
|
cfAsset,
|
|
8
|
-
chainflip
|
|
9
|
-
|
|
8
|
+
chainflip,
|
|
9
|
+
chainflipPins,
|
|
10
|
+
chainflipVerifyQuote
|
|
11
|
+
} from "./chunk-DGLXKJQ7.js";
|
|
12
|
+
import "./chunk-SJ6UVIVY.js";
|
|
10
13
|
export {
|
|
11
14
|
CF_API_DEFAULT,
|
|
12
15
|
CF_ASSETS,
|
|
@@ -14,6 +17,8 @@ export {
|
|
|
14
17
|
CF_SOURCE_CHAINS,
|
|
15
18
|
CF_VAULTS,
|
|
16
19
|
cfAsset,
|
|
17
|
-
chainflip
|
|
20
|
+
chainflip,
|
|
21
|
+
chainflipPins,
|
|
22
|
+
chainflipVerifyQuote
|
|
18
23
|
};
|
|
19
24
|
//# sourceMappingURL=config.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -29,7 +29,9 @@ __export(src_exports, {
|
|
|
29
29
|
ChainflipSwap2Protocol: () => ChainflipSwap2Protocol,
|
|
30
30
|
cfAsset: () => cfAsset,
|
|
31
31
|
chainflip: () => chainflip,
|
|
32
|
+
chainflipPins: () => chainflipPins,
|
|
32
33
|
chainflipProvider: () => chainflipProvider,
|
|
34
|
+
chainflipVerifyQuote: () => chainflipVerifyQuote,
|
|
33
35
|
decodeCfParameters: () => decodeCfParameters,
|
|
34
36
|
decodeEvmVaultCall: () => decodeEvmVaultCall,
|
|
35
37
|
decodeTronNote: () => decodeTronNote,
|
|
@@ -45,63 +47,6 @@ __export(src_exports, {
|
|
|
45
47
|
});
|
|
46
48
|
module.exports = __toCommonJS(src_exports);
|
|
47
49
|
|
|
48
|
-
// src/config.ts
|
|
49
|
-
var CF_CHAINS = {
|
|
50
|
-
"eip155:1": { name: "Ethereum", id: 1, addrTag: 0 },
|
|
51
|
-
"bitcoin:mainnet": { name: "Bitcoin", id: 3, addrTag: 2 },
|
|
52
|
-
"eip155:42161": { name: "Arbitrum", id: 4, addrTag: 3 },
|
|
53
|
-
"solana:mainnet": { name: "Solana", id: 5, addrTag: 4 },
|
|
54
|
-
"tron:728126428": { name: "Tron", id: 7, addrTag: 6 }
|
|
55
|
-
};
|
|
56
|
-
var CF_ASSETS = [
|
|
57
|
-
{ chain: "Ethereum", asset: "ETH", id: 1, decimals: 18, token: null, minDeposit: 10n ** 16n },
|
|
58
|
-
{ chain: "Ethereum", asset: "USDC", id: 3, decimals: 6, token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", minDeposit: 20000000n },
|
|
59
|
-
{ chain: "Ethereum", asset: "USDT", id: 8, decimals: 6, token: "0xdAC17F958D2ee523a2206206994597C13D831ec7", minDeposit: 20000000n },
|
|
60
|
-
{ chain: "Ethereum", asset: "WBTC", id: 14, decimals: 8, token: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", minDeposit: 40000n },
|
|
61
|
-
{ chain: "Bitcoin", asset: "BTC", id: 5, decimals: 8, token: null, minDeposit: 40000n },
|
|
62
|
-
{ chain: "Arbitrum", asset: "ETH", id: 6, decimals: 18, token: null, minDeposit: 3900000000000000n },
|
|
63
|
-
{ chain: "Arbitrum", asset: "USDC", id: 7, decimals: 6, token: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", minDeposit: 10000000n },
|
|
64
|
-
{ chain: "Arbitrum", asset: "USDT", id: 15, decimals: 6, token: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", minDeposit: 10000000n },
|
|
65
|
-
{ chain: "Solana", asset: "SOL", id: 9, decimals: 9, token: null, minDeposit: 68000000n },
|
|
66
|
-
{ chain: "Solana", asset: "USDC", id: 10, decimals: 6, token: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", minDeposit: 10000000n },
|
|
67
|
-
{ chain: "Solana", asset: "USDT", id: 16, decimals: 6, token: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB", minDeposit: 10000000n },
|
|
68
|
-
{ chain: "Tron", asset: "TRX", id: 17, decimals: 6, token: null, minDeposit: 30000000n },
|
|
69
|
-
{ chain: "Tron", asset: "USDT", id: 18, decimals: 6, token: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", minDeposit: 10000000n }
|
|
70
|
-
];
|
|
71
|
-
var CF_VAULTS = {
|
|
72
|
-
"eip155:1": "0xF5e10380213880111522dd0efD3dbb45b9f62Bcc",
|
|
73
|
-
"eip155:42161": "0x79001a5e762f3bEFC8e5871b42F6734e00498920",
|
|
74
|
-
"tron:728126428": "TEcDijvKSXcfWT7S6rd44H5vNgufm7Y4XC"
|
|
75
|
-
};
|
|
76
|
-
var CF_SOURCE_CHAINS = /* @__PURE__ */ new Set(["eip155:1", "eip155:42161", "tron:728126428"]);
|
|
77
|
-
var CF_API_DEFAULT = "https://chainflip-swap.chainflip.io";
|
|
78
|
-
var sameToken = (chain, a, b) => chain.startsWith("eip155:") ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
79
|
-
var NATIVE = /* @__PURE__ */ new Set(["", "native", "0x0000000000000000000000000000000000000000"]);
|
|
80
|
-
function cfAsset(chain, token) {
|
|
81
|
-
const c = CF_CHAINS[chain];
|
|
82
|
-
if (!c) return void 0;
|
|
83
|
-
const on = CF_ASSETS.filter((a) => a.chain === c.name);
|
|
84
|
-
if (NATIVE.has(token.toLowerCase())) return on.find((a) => a.token === null);
|
|
85
|
-
return on.find((a) => a.token !== null && sameToken(chain, a.token, token) || a.asset === token.toUpperCase());
|
|
86
|
-
}
|
|
87
|
-
var chainflip = {
|
|
88
|
-
supportsChain: (chain) => !!CF_CHAINS[chain],
|
|
89
|
-
supports: (from, to) => CF_SOURCE_CHAINS.has(from) && !!CF_CHAINS[to] && from !== to
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// src/activity.ts
|
|
93
|
-
var import_activity = require("@anywalletkit/protocol-swap2-core/activity");
|
|
94
|
-
var CHAINFLIP_MODULE = "@anywalletkit/protocol-swap2-chainflip";
|
|
95
|
-
var same = (chain, a, b) => !!a && (chain.startsWith("eip155:") ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
96
|
-
var CHAIN_ALIAS = { "tron:0x2b6653dc": "tron:728126428" };
|
|
97
|
-
function describeChainflipActivity(tx, ctx) {
|
|
98
|
-
const vault = CF_VAULTS[CHAIN_ALIAS[tx.chain] ?? tx.chain];
|
|
99
|
-
if (!vault) return null;
|
|
100
|
-
const toVault = same(tx.chain, tx.to, vault) || tx.transfers.some((t) => same(tx.chain, t.to, vault) && ctx.own.has(t.from));
|
|
101
|
-
if (!toVault) return null;
|
|
102
|
-
return (0, import_activity.describeSwapLike)(tx, ctx, { protocol: CHAINFLIP_MODULE, subtitle: "Chainflip", kind: "bridge", counterparty: vault, inSuffix: "via Chainflip" });
|
|
103
|
-
}
|
|
104
|
-
|
|
105
50
|
// src/codec.ts
|
|
106
51
|
var import_base = require("@scure/base");
|
|
107
52
|
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
@@ -239,6 +184,113 @@ function minOutOf(amountIn, minPriceX128) {
|
|
|
239
184
|
return amountIn * minPriceX128 / 2n ** 128n;
|
|
240
185
|
}
|
|
241
186
|
|
|
187
|
+
// src/config.ts
|
|
188
|
+
var CF_CHAINS = {
|
|
189
|
+
"eip155:1": { name: "Ethereum", id: 1, addrTag: 0 },
|
|
190
|
+
"bitcoin:mainnet": { name: "Bitcoin", id: 3, addrTag: 2 },
|
|
191
|
+
"eip155:42161": { name: "Arbitrum", id: 4, addrTag: 3 },
|
|
192
|
+
"solana:mainnet": { name: "Solana", id: 5, addrTag: 4 },
|
|
193
|
+
"tron:728126428": { name: "Tron", id: 7, addrTag: 6 }
|
|
194
|
+
};
|
|
195
|
+
var CF_ASSETS = [
|
|
196
|
+
{ chain: "Ethereum", asset: "ETH", id: 1, decimals: 18, token: null, minDeposit: 10n ** 16n },
|
|
197
|
+
{ chain: "Ethereum", asset: "USDC", id: 3, decimals: 6, token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", minDeposit: 20000000n },
|
|
198
|
+
{ chain: "Ethereum", asset: "USDT", id: 8, decimals: 6, token: "0xdAC17F958D2ee523a2206206994597C13D831ec7", minDeposit: 20000000n },
|
|
199
|
+
{ chain: "Ethereum", asset: "WBTC", id: 14, decimals: 8, token: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", minDeposit: 40000n },
|
|
200
|
+
{ chain: "Bitcoin", asset: "BTC", id: 5, decimals: 8, token: null, minDeposit: 40000n },
|
|
201
|
+
{ chain: "Arbitrum", asset: "ETH", id: 6, decimals: 18, token: null, minDeposit: 3900000000000000n },
|
|
202
|
+
{ chain: "Arbitrum", asset: "USDC", id: 7, decimals: 6, token: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", minDeposit: 10000000n },
|
|
203
|
+
{ chain: "Arbitrum", asset: "USDT", id: 15, decimals: 6, token: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", minDeposit: 10000000n },
|
|
204
|
+
{ chain: "Solana", asset: "SOL", id: 9, decimals: 9, token: null, minDeposit: 68000000n },
|
|
205
|
+
{ chain: "Solana", asset: "USDC", id: 10, decimals: 6, token: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", minDeposit: 10000000n },
|
|
206
|
+
{ chain: "Solana", asset: "USDT", id: 16, decimals: 6, token: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB", minDeposit: 10000000n },
|
|
207
|
+
{ chain: "Tron", asset: "TRX", id: 17, decimals: 6, token: null, minDeposit: 30000000n },
|
|
208
|
+
{ chain: "Tron", asset: "USDT", id: 18, decimals: 6, token: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", minDeposit: 10000000n }
|
|
209
|
+
];
|
|
210
|
+
var CF_VAULTS = {
|
|
211
|
+
"eip155:1": "0xF5e10380213880111522dd0efD3dbb45b9f62Bcc",
|
|
212
|
+
"eip155:42161": "0x79001a5e762f3bEFC8e5871b42F6734e00498920",
|
|
213
|
+
"tron:728126428": "TEcDijvKSXcfWT7S6rd44H5vNgufm7Y4XC"
|
|
214
|
+
};
|
|
215
|
+
var CF_SOURCE_CHAINS = /* @__PURE__ */ new Set(["eip155:1", "eip155:42161", "tron:728126428"]);
|
|
216
|
+
var CF_API_DEFAULT = "https://chainflip-swap.chainflip.io";
|
|
217
|
+
var sameToken = (chain, a, b) => chain.startsWith("eip155:") ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
218
|
+
var NATIVE = /* @__PURE__ */ new Set(["", "native", "0x0000000000000000000000000000000000000000"]);
|
|
219
|
+
function cfAsset(chain, token) {
|
|
220
|
+
const c = CF_CHAINS[chain];
|
|
221
|
+
if (!c) return void 0;
|
|
222
|
+
const on = CF_ASSETS.filter((a) => a.chain === c.name);
|
|
223
|
+
if (NATIVE.has(token.toLowerCase())) return on.find((a) => a.token === null);
|
|
224
|
+
return on.find((a) => a.token !== null && sameToken(chain, a.token, token) || a.asset === token.toUpperCase());
|
|
225
|
+
}
|
|
226
|
+
var chainflip = {
|
|
227
|
+
supportsChain: (chain) => !!CF_CHAINS[chain],
|
|
228
|
+
supports: (from, to) => CF_SOURCE_CHAINS.has(from) && !!CF_CHAINS[to] && from !== to
|
|
229
|
+
};
|
|
230
|
+
function chainflipVerifyQuote(params, quote) {
|
|
231
|
+
try {
|
|
232
|
+
const src = cfAsset(params.sourceChain, params.sourceToken);
|
|
233
|
+
const dst = cfAsset(params.destChain, params.destToken);
|
|
234
|
+
const dstChain = CF_CHAINS[params.destChain];
|
|
235
|
+
const vault = Object.prototype.hasOwnProperty.call(CF_VAULTS, params.sourceChain) ? CF_VAULTS[params.sourceChain] : void 0;
|
|
236
|
+
if (!src || !dst || !dstChain || !vault || !CF_SOURCE_CHAINS.has(params.sourceChain)) return "not a vault swap this release signs";
|
|
237
|
+
if (!quote.txRequest && !quote.depositAddress) return null;
|
|
238
|
+
if (!params.refundAddress) return "a live quote needs the refund address";
|
|
239
|
+
const amountIn = BigInt(params.amountIn);
|
|
240
|
+
const dest = destAddressBytes(params.destChain, params.destAddress);
|
|
241
|
+
const refund = destAddressBytes(params.sourceChain, params.refundAddress);
|
|
242
|
+
const checkParams = (p) => {
|
|
243
|
+
if (!sameBytes(fromHex(p.refundAddress), refund)) return "the refund address is not the sender";
|
|
244
|
+
if (minOutOf(amountIn, p.minPriceX128) < BigInt(quote.minDestAmount)) return "the minimum price does not guarantee the quoted minimum";
|
|
245
|
+
if (p.dca !== null || p.boostFeeBps !== 0 || p.broker.feeBps !== 0 || p.affiliates.length) return "DCA, boost, a broker fee or affiliates";
|
|
246
|
+
return null;
|
|
247
|
+
};
|
|
248
|
+
if (params.sourceChain.startsWith("eip155:")) {
|
|
249
|
+
const tx = quote.txRequest;
|
|
250
|
+
if (quote.depositAddress || !tx?.data || tx.serializedTx !== void 0) return "an EVM vault swap is a vault call, not a deposit";
|
|
251
|
+
if (!tx.to || tx.to.toLowerCase() !== vault.toLowerCase()) return `the call targets ${tx.to}, not the Vault`;
|
|
252
|
+
const v = decodeEvmVaultCall(tx.data);
|
|
253
|
+
if (v.dstChain !== dstChain.id || v.dstToken !== dst.id || !sameBytes(v.dstAddress, dest)) return "the vault call names another destination";
|
|
254
|
+
if (src.token === null) {
|
|
255
|
+
if (!v.native || BigInt(tx.value ?? "0") !== amountIn || tx.approvalAddress) return "the native vault call moves another amount";
|
|
256
|
+
} else if (v.native || v.srcToken?.toLowerCase() !== src.token.toLowerCase() || v.amount !== amountIn || BigInt(tx.value ?? "0") !== 0n || tx.approvalAddress?.toLowerCase() !== vault.toLowerCase()) {
|
|
257
|
+
return "the token vault call moves another token or amount";
|
|
258
|
+
}
|
|
259
|
+
return checkParams(v.params);
|
|
260
|
+
}
|
|
261
|
+
if (quote.txRequest || quote.depositAddress !== vault || !quote.depositMemo) return "a Tron vault swap is a send to the Tron Vault with its note";
|
|
262
|
+
const n = decodeTronNote(quote.depositMemo);
|
|
263
|
+
if (n.outputAsset !== dst.id || n.destTag !== dstChain.addrTag || !sameBytes(n.destAddress, dest)) return "the note names another destination";
|
|
264
|
+
return checkParams(n.params);
|
|
265
|
+
} catch (e) {
|
|
266
|
+
return `the vault swap does not decode (${(e instanceof Error ? e.message : String(e)).slice(0, 120)})`;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
var chainflipPins = Object.freeze({
|
|
270
|
+
callTargets: (chain) => chainflipVaultFor(chain),
|
|
271
|
+
spenders: (chain) => chainflipVaultFor(chain),
|
|
272
|
+
verifyQuote: chainflipVerifyQuote,
|
|
273
|
+
verifyBuild: (quote, tx) => quote.depositMemo && tx.memoEncoding !== "hex" ? "the Tron note is not sent as hex bytes" : null,
|
|
274
|
+
depositAddressRoutes: true
|
|
275
|
+
});
|
|
276
|
+
function chainflipVaultFor(chain) {
|
|
277
|
+
const vault = chain.startsWith("eip155:") && Object.prototype.hasOwnProperty.call(CF_VAULTS, chain) ? CF_VAULTS[chain] : void 0;
|
|
278
|
+
return vault ? [vault] : [];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/activity.ts
|
|
282
|
+
var import_activity = require("@anywalletkit/protocol-swap2-core/activity");
|
|
283
|
+
var CHAINFLIP_MODULE = "@anywalletkit/protocol-swap2-chainflip";
|
|
284
|
+
var same = (chain, a, b) => !!a && (chain.startsWith("eip155:") ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
285
|
+
var CHAIN_ALIAS = { "tron:0x2b6653dc": "tron:728126428" };
|
|
286
|
+
function describeChainflipActivity(tx, ctx) {
|
|
287
|
+
const vault = CF_VAULTS[CHAIN_ALIAS[tx.chain] ?? tx.chain];
|
|
288
|
+
if (!vault) return null;
|
|
289
|
+
const toVault = same(tx.chain, tx.to, vault) || tx.transfers.some((t) => same(tx.chain, t.to, vault) && ctx.own.has(t.from));
|
|
290
|
+
if (!toVault) return null;
|
|
291
|
+
return (0, import_activity.describeSwapLike)(tx, ctx, { protocol: CHAINFLIP_MODULE, subtitle: "Chainflip", kind: "bridge", counterparty: vault, inSuffix: "via Chainflip" });
|
|
292
|
+
}
|
|
293
|
+
|
|
242
294
|
// src/provider.ts
|
|
243
295
|
var import_util = require("@anywalletkit/protocol-swap2-core/util");
|
|
244
296
|
var import_viem2 = require("viem");
|