@anywalletkit/protocol-swap2-chainflip 0.4.6 → 0.4.8
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/dist/activity.cjs +36 -14
- package/dist/activity.cjs.map +1 -1
- package/dist/activity.js +2 -2
- package/dist/{chunk-ZH5XKSCP.js → chunk-C2OITXU4.js} +2 -2
- package/dist/{chunk-RRCQYT67.js → chunk-G5FZLGMT.js} +3 -3
- package/dist/{chunk-DGLXKJQ7.js → chunk-IQSAPDND.js} +35 -15
- package/dist/chunk-IQSAPDND.js.map +1 -0
- package/dist/{chunk-RU2NXJTL.js → chunk-XUMGQNH4.js} +66 -40
- package/dist/chunk-XUMGQNH4.js.map +1 -0
- package/dist/config.cjs +34 -14
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +2 -12
- package/dist/config.d.ts +2 -12
- package/dist/config.js +1 -1
- package/dist/index.cjs +99 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -4
- package/dist/protocol.cjs +99 -51
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.js +4 -4
- package/dist/provider.cjs +99 -51
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.js +3 -3
- package/package.json +4 -4
- package/dist/chunk-DGLXKJQ7.js.map +0 -1
- package/dist/chunk-RU2NXJTL.js.map +0 -1
- /package/dist/{chunk-ZH5XKSCP.js.map → chunk-C2OITXU4.js.map} +0 -0
- /package/dist/{chunk-RRCQYT67.js.map → chunk-G5FZLGMT.js.map} +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
describeChainflipActivity
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-C2OITXU4.js";
|
|
4
4
|
import {
|
|
5
5
|
CF_API_DEFAULT,
|
|
6
6
|
CF_CHAINS,
|
|
7
7
|
CF_VAULTS,
|
|
8
8
|
cfAsset,
|
|
9
9
|
chainflip
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-IQSAPDND.js";
|
|
11
11
|
import {
|
|
12
12
|
decodeEvmVaultCall,
|
|
13
13
|
decodeTronNote,
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
} from "./chunk-SJ6UVIVY.js";
|
|
21
21
|
|
|
22
22
|
// src/provider.ts
|
|
23
|
+
import { httpRefusal, refusal, refusalNotes } from "@anywalletkit/protocol-swap2-core/errors";
|
|
23
24
|
import { timeoutSignal } from "@anywalletkit/protocol-swap2-core/util";
|
|
24
25
|
import { decodeFunctionData, parseAbi } from "viem";
|
|
25
26
|
var QUOTE_TTL_MS = 6e4;
|
|
@@ -27,6 +28,25 @@ var RETRY_BLOCKS = 50;
|
|
|
27
28
|
var MAX_RETRY_BLOCKS = 600;
|
|
28
29
|
var ERC20 = parseAbi(["function transfer(address to, uint256 amount) returns (bool)"]);
|
|
29
30
|
var INTENT_PREFIX = "cfvault:";
|
|
31
|
+
var notes = refusalNotes();
|
|
32
|
+
function backendRefusal(status, body, retryAfter) {
|
|
33
|
+
const http = httpRefusal(status, retryAfter);
|
|
34
|
+
const byStatus = http?.reason === "key_rejected" ? { reason: "upstream_unavailable", httpStatus: status } : http;
|
|
35
|
+
if (byStatus?.reason === "rate_limited") return byStatus;
|
|
36
|
+
const m = body?.message;
|
|
37
|
+
const said = typeof m === "string" ? backendReason(m) : void 0;
|
|
38
|
+
return said && said !== byStatus?.reason ? { reason: said } : byStatus;
|
|
39
|
+
}
|
|
40
|
+
function backendReason(message) {
|
|
41
|
+
if (/liquidity/i.test(message)) return "insufficient_liquidity";
|
|
42
|
+
if (/maximum (?:swap )?amount|above (?:the )?max|too (?:large|big|high)|exceeds? (?:the )?max/i.test(message)) return "amount_too_large";
|
|
43
|
+
if (/minimum (?:swap |deposit )?amount|below (?:the )?minimum|lower than (?:the )?(?:estimated|minimum)|too (?:small|low)/i.test(message)) return "amount_too_small";
|
|
44
|
+
if (/halt|paus|maintenance|disabled|suspend|not enabled/i.test(message)) return "chain_halted";
|
|
45
|
+
if (/rate.?limit|too many requests/i.test(message)) return "rate_limited";
|
|
46
|
+
if (/not supported|unsupported|unknown asset|invalid asset/i.test(message)) return "unsupported_pair";
|
|
47
|
+
if (/no (?:route|quote)|could not find/i.test(message)) return "no_route";
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
30
50
|
function chainflipProvider(config = {}) {
|
|
31
51
|
config = Object.freeze({ ...config });
|
|
32
52
|
const base = new URL(config.apiUrl ?? CF_API_DEFAULT).toString().replace(/\/$/, "");
|
|
@@ -38,18 +58,18 @@ function chainflipProvider(config = {}) {
|
|
|
38
58
|
await new Promise((r) => setTimeout(r, 1200));
|
|
39
59
|
continue;
|
|
40
60
|
}
|
|
41
|
-
return { ok: res.ok, status: res.status, body };
|
|
61
|
+
return { ok: res.ok, status: res.status, body, retryAfter: res.headers?.get?.("retry-after") ?? null };
|
|
42
62
|
}
|
|
43
63
|
};
|
|
44
64
|
const checkParams = (p, want) => {
|
|
45
|
-
if (!sameBytes(fromHex(p.refundAddress), want.refund)) return `refund address ${p.refundAddress} is not the sender
|
|
46
|
-
if (p.minPriceX128 < want.minPriceX128) return "minimum price is below the one requested";
|
|
47
|
-
if (p.retryDurationBlocks > MAX_RETRY_BLOCKS) return `retry window ${p.retryDurationBlocks} blocks is too long
|
|
48
|
-
if (p.maxOraclePriceSlippageBps !== want.oracle) return "oracle slippage guard differs from the request";
|
|
49
|
-
if (p.dca !== null) return "unexpected DCA parameters";
|
|
50
|
-
if (p.boostFeeBps !== 0) return "unexpected boost fee";
|
|
51
|
-
if (p.broker.feeBps !== 0) return `broker takes ${p.broker.feeBps} bps
|
|
52
|
-
if (p.affiliates.length) return "unexpected affiliates";
|
|
65
|
+
if (!sameBytes(fromHex(p.refundAddress), want.refund)) return notes.note(`refund address ${p.refundAddress} is not the sender`, "recipient_mismatch");
|
|
66
|
+
if (p.minPriceX128 < want.minPriceX128) return notes.note("minimum price is below the one requested", "price_check_failed");
|
|
67
|
+
if (p.retryDurationBlocks > MAX_RETRY_BLOCKS) return notes.note(`retry window ${p.retryDurationBlocks} blocks is too long`, "policy_refused");
|
|
68
|
+
if (p.maxOraclePriceSlippageBps !== want.oracle) return notes.note("oracle slippage guard differs from the request", "price_check_failed");
|
|
69
|
+
if (p.dca !== null) return notes.note("unexpected DCA parameters", "policy_refused");
|
|
70
|
+
if (p.boostFeeBps !== 0) return notes.note("unexpected boost fee", "policy_refused");
|
|
71
|
+
if (p.broker.feeBps !== 0) return notes.note(`broker takes ${p.broker.feeBps} bps`, "policy_refused");
|
|
72
|
+
if (p.affiliates.length) return notes.note("unexpected affiliates", "policy_refused");
|
|
53
73
|
return null;
|
|
54
74
|
};
|
|
55
75
|
return {
|
|
@@ -65,16 +85,19 @@ function chainflipProvider(config = {}) {
|
|
|
65
85
|
},
|
|
66
86
|
async getQuote(params, signal) {
|
|
67
87
|
const dry = params.dry !== false;
|
|
68
|
-
const refuse = (reason) => {
|
|
69
|
-
|
|
88
|
+
const refuse = (reason, why) => {
|
|
89
|
+
const info = typeof why === "string" ? { reason: why } : why;
|
|
90
|
+
if (info) params.onRefusal?.(`chainflip: ${reason}`, info);
|
|
91
|
+
else params.onRefusal?.(`chainflip: ${reason}`);
|
|
70
92
|
return null;
|
|
71
93
|
};
|
|
72
|
-
|
|
94
|
+
const unreachable = () => signal?.aborted ? void 0 : "upstream_unavailable";
|
|
95
|
+
if (!chainflip.supports(params.sourceChain, params.destChain)) return refuse(`no vault swap ${params.sourceChain} \u2192 ${params.destChain}`, "unsupported_pair");
|
|
73
96
|
const src = cfAsset(params.sourceChain, params.sourceToken);
|
|
74
97
|
const dst = cfAsset(params.destChain, params.destToken);
|
|
75
|
-
if (!src || !dst) return refuse(`asset not listed (${params.sourceToken} on ${params.sourceChain} \u2192 ${params.destToken} on ${params.destChain})
|
|
98
|
+
if (!src || !dst) return refuse(`asset not listed (${params.sourceToken} on ${params.sourceChain} \u2192 ${params.destToken} on ${params.destChain})`, "unsupported_pair");
|
|
76
99
|
const amountIn = BigInt(params.amountIn);
|
|
77
|
-
if (amountIn < src.minDeposit) return refuse(`below the minimum deposit (${src.minDeposit} ${src.asset})
|
|
100
|
+
if (amountIn < src.minDeposit) return refuse(`below the minimum deposit (${src.minDeposit} ${src.asset})`, "amount_too_small");
|
|
78
101
|
let destBytes;
|
|
79
102
|
try {
|
|
80
103
|
destBytes = destAddressBytes(params.destChain, params.destAddress);
|
|
@@ -83,21 +106,23 @@ function chainflipProvider(config = {}) {
|
|
|
83
106
|
}
|
|
84
107
|
const qs = new URLSearchParams({ amount: params.amountIn, srcChain: src.chain, srcAsset: src.asset, destChain: dst.chain, destAsset: dst.asset, isVaultSwap: "true", isOnChain: "false", dcaV2Enabled: "false" });
|
|
85
108
|
let q;
|
|
109
|
+
let answered;
|
|
86
110
|
try {
|
|
87
111
|
const r = await call(`/v2/quote?${qs.toString()}`, {}, signal);
|
|
88
|
-
if (!r.ok) return refuse(`quote ${r.status}: ${String(r.body?.message ?? "").slice(0, 160)}
|
|
112
|
+
if (!r.ok) return refuse(`quote ${r.status}: ${String(r.body?.message ?? "").slice(0, 160)}`, backendRefusal(r.status, r.body, r.retryAfter));
|
|
113
|
+
answered = r.body;
|
|
89
114
|
q = r.body?.find((x) => x.type === "REGULAR") ?? r.body?.[0];
|
|
90
115
|
} catch (e) {
|
|
91
|
-
return refuse(`quote failed: ${e.message.slice(0, 160)}
|
|
116
|
+
return refuse(`quote failed: ${e.message.slice(0, 160)}`, unreachable());
|
|
92
117
|
}
|
|
93
|
-
if (!q?.egressAmount || !/^\d+$/.test(q.egressAmount)) return refuse("quote without an egress amount");
|
|
94
|
-
if (q.type && q.type !== "REGULAR") return refuse(`${q.type} quotes are not supported
|
|
118
|
+
if (!q?.egressAmount || !/^\d+$/.test(q.egressAmount)) return refuse("quote without an egress amount", Array.isArray(answered) && answered.length === 0 ? "no_route" : unreachable());
|
|
119
|
+
if (q.type && q.type !== "REGULAR") return refuse(`${q.type} quotes are not supported`, "unsupported_pair");
|
|
95
120
|
const expected = BigInt(q.egressAmount);
|
|
96
121
|
const slipBps = params.slippageBps ?? Math.round((q.recommendedSlippageTolerancePercent ?? 1) * 100);
|
|
97
122
|
const byTolerance = expected * BigInt(1e4 - Math.min(9999, Math.max(0, slipBps))) / 10000n;
|
|
98
123
|
const callerFloor = params.minAmountOut !== void 0 ? BigInt(params.minAmountOut) : void 0;
|
|
99
124
|
const minOut = callerFloor === void 0 ? byTolerance : params.slippageBps !== void 0 && byTolerance > callerFloor ? byTolerance : callerFloor;
|
|
100
|
-
if (minOut > expected) return refuse(`floor ${minOut} above the expected output ${expected}
|
|
125
|
+
if (minOut > expected) return refuse(`floor ${minOut} above the expected output ${expected}`, "price_check_failed");
|
|
101
126
|
const minPriceX128 = minPriceX128For(amountIn, minOut);
|
|
102
127
|
const guaranteed = minOutOf(amountIn, minPriceX128);
|
|
103
128
|
const oracle = config.maxOraclePriceSlippageBps !== void 0 ? config.maxOraclePriceSlippageBps : q.recommendedLivePriceSlippageTolerancePercent !== void 0 ? Math.round(q.recommendedLivePriceSlippageTolerancePercent * 100) : null;
|
|
@@ -115,7 +140,7 @@ function chainflipProvider(config = {}) {
|
|
|
115
140
|
validUntilMs: Date.now() + QUOTE_TTL_MS
|
|
116
141
|
};
|
|
117
142
|
if (dry) return { ...common, intentId: `dry:${crypto.randomUUID()}`, depositAddress: "", depositMemo: null };
|
|
118
|
-
if (!params.refundAddress) return refuse("live quote without a refund address");
|
|
143
|
+
if (!params.refundAddress) return refuse("live quote without a refund address", "policy_refused");
|
|
119
144
|
let refund;
|
|
120
145
|
try {
|
|
121
146
|
refund = destAddressBytes(params.sourceChain, params.refundAddress);
|
|
@@ -134,26 +159,26 @@ function chainflipProvider(config = {}) {
|
|
|
134
159
|
let enc;
|
|
135
160
|
try {
|
|
136
161
|
const r = await call("/api/encodeVaultSwapData", { method: "POST", body: JSON.stringify(body) }, signal);
|
|
137
|
-
if (!r.ok) return refuse(`encode ${r.status}: ${String(r.body?.message ?? "").slice(0, 160)}
|
|
162
|
+
if (!r.ok) return refuse(`encode ${r.status}: ${String(r.body?.message ?? "").slice(0, 160)}`, backendRefusal(r.status, r.body, r.retryAfter));
|
|
138
163
|
enc = r.body ?? {};
|
|
139
164
|
} catch (e) {
|
|
140
|
-
return refuse(`encode failed: ${e.message.slice(0, 160)}
|
|
165
|
+
return refuse(`encode failed: ${e.message.slice(0, 160)}`, unreachable());
|
|
141
166
|
}
|
|
142
167
|
const want = { refund, minPriceX128, oracle };
|
|
143
168
|
const vault = CF_VAULTS[params.sourceChain];
|
|
144
169
|
const dstChain = CF_CHAINS[params.destChain];
|
|
145
170
|
try {
|
|
146
171
|
if (params.sourceChain.startsWith("eip155:")) {
|
|
147
|
-
if (!enc.to || enc.to.toLowerCase() !== vault.toLowerCase()) return refuse(`encoder targets ${enc.to}, not the ${src.chain} Vault
|
|
172
|
+
if (!enc.to || enc.to.toLowerCase() !== vault.toLowerCase()) return refuse(`encoder targets ${enc.to}, not the ${src.chain} Vault`, !enc.to ? unreachable() : "vault_mismatch");
|
|
148
173
|
const v = decodeEvmVaultCall(enc.calldata ?? "0x");
|
|
149
|
-
if (v.dstChain !== dstChain.id || v.dstToken !== dst.id || !sameBytes(v.dstAddress, destBytes)) return refuse("encoded destination differs from the request");
|
|
174
|
+
if (v.dstChain !== dstChain.id || v.dstToken !== dst.id || !sameBytes(v.dstAddress, destBytes)) return refuse("encoded destination differs from the request", "recipient_mismatch");
|
|
150
175
|
if (src.token === null) {
|
|
151
|
-
if (!v.native || BigInt(enc.value ?? "0") !== amountIn) return refuse("native vault call with a different amount");
|
|
176
|
+
if (!v.native || BigInt(enc.value ?? "0") !== amountIn) return refuse("native vault call with a different amount", "policy_refused");
|
|
152
177
|
} else if (v.native || v.srcToken?.toLowerCase() !== src.token.toLowerCase() || v.amount !== amountIn || BigInt(enc.value ?? "0") !== 0n) {
|
|
153
|
-
return refuse("token vault call with a different token or amount");
|
|
178
|
+
return refuse("token vault call with a different token or amount", "policy_refused");
|
|
154
179
|
}
|
|
155
180
|
const bad2 = checkParams(v.params, want);
|
|
156
|
-
if (bad2) return refuse(bad2);
|
|
181
|
+
if (bad2) return refuse(bad2, notes.reasonOf(bad2));
|
|
157
182
|
return {
|
|
158
183
|
...common,
|
|
159
184
|
intentId: `${INTENT_PREFIX}${params.sourceChain}`,
|
|
@@ -163,17 +188,18 @@ function chainflipProvider(config = {}) {
|
|
|
163
188
|
providerData: { kind: "evm", srcAsset: String(src.id), dstAsset: String(dst.id) }
|
|
164
189
|
};
|
|
165
190
|
}
|
|
166
|
-
if (enc.to !== vault) return refuse(`encoder targets ${enc.to}, not the Tron Vault
|
|
167
|
-
if (!enc.note) return refuse("Tron vault swap without a note");
|
|
191
|
+
if (enc.to !== vault) return refuse(`encoder targets ${enc.to}, not the Tron Vault`, !enc.to ? unreachable() : "vault_mismatch");
|
|
192
|
+
if (!enc.note) return refuse("Tron vault swap without a note", "recipient_unverifiable");
|
|
168
193
|
if (src.token !== null) {
|
|
169
|
-
if (enc.sourceTokenAddress !== src.token) return refuse(`source token ${enc.sourceTokenAddress} is not ${src.asset}
|
|
194
|
+
if (enc.sourceTokenAddress !== src.token) return refuse(`source token ${enc.sourceTokenAddress} is not ${src.asset}`, "policy_refused");
|
|
170
195
|
const t = decodeFunctionData({ abi: ERC20, data: enc.calldata ?? "0x" });
|
|
171
|
-
|
|
196
|
+
const toVault = sameBytes(fromHex(String(t.args[0])), tronToBytes(vault));
|
|
197
|
+
if (!toVault || t.args[1] !== amountIn) return refuse("TRC-20 transfer is not the amount to the Vault", toVault ? "policy_refused" : "vault_mismatch");
|
|
172
198
|
}
|
|
173
199
|
const n = decodeTronNote(enc.note);
|
|
174
|
-
if (n.outputAsset !== dst.id || n.destTag !== dstChain.addrTag || !sameBytes(n.destAddress, destBytes)) return refuse("note names another destination");
|
|
200
|
+
if (n.outputAsset !== dst.id || n.destTag !== dstChain.addrTag || !sameBytes(n.destAddress, destBytes)) return refuse("note names another destination", "recipient_mismatch");
|
|
175
201
|
const bad = checkParams(n.params, want);
|
|
176
|
-
if (bad) return refuse(bad);
|
|
202
|
+
if (bad) return refuse(bad, notes.reasonOf(bad));
|
|
177
203
|
return {
|
|
178
204
|
...common,
|
|
179
205
|
intentId: `${INTENT_PREFIX}${params.sourceChain}`,
|
|
@@ -182,20 +208,20 @@ function chainflipProvider(config = {}) {
|
|
|
182
208
|
providerData: { kind: "tron", memoEncoding: "hex", srcAsset: String(src.id), dstAsset: String(dst.id) }
|
|
183
209
|
};
|
|
184
210
|
} catch (e) {
|
|
185
|
-
return refuse(`encoder output does not decode: ${e.message.slice(0, 160)}
|
|
211
|
+
return refuse(`encoder output does not decode: ${e.message.slice(0, 160)}`, "upstream_unavailable");
|
|
186
212
|
}
|
|
187
213
|
},
|
|
188
214
|
async buildDeposit(quote) {
|
|
189
215
|
if (quote.providerData?.kind === "evm") {
|
|
190
216
|
const tx = quote.txRequest;
|
|
191
|
-
if (!tx?.to || !tx.data) throw
|
|
217
|
+
if (!tx?.to || !tx.data) throw refusal("policy_refused", "chainflip: quote has no vault call");
|
|
192
218
|
return { chain: "", to: tx.to, value: tx.value ?? "0", data: tx.data, ...tx.chainId !== void 0 ? { chainId: tx.chainId } : {}, ...tx.approvalAddress ? { approvalAddress: tx.approvalAddress } : {} };
|
|
193
219
|
}
|
|
194
220
|
if (quote.providerData?.kind === "tron") {
|
|
195
|
-
if (!quote.depositAddress || !quote.depositMemo) throw
|
|
221
|
+
if (!quote.depositAddress || !quote.depositMemo) throw refusal("policy_refused", "chainflip: Tron quote without vault or note");
|
|
196
222
|
return { chain: "", to: quote.depositAddress, value: quote.sourceAmount, memo: quote.depositMemo, memoEncoding: "hex" };
|
|
197
223
|
}
|
|
198
|
-
throw
|
|
224
|
+
throw refusal("policy_refused", "chainflip: not a live vault-swap quote");
|
|
199
225
|
},
|
|
200
226
|
async trackIntent(ref) {
|
|
201
227
|
if (!ref.sourceTxHash) return { state: "pending" };
|
|
@@ -225,4 +251,4 @@ function chainflipProvider(config = {}) {
|
|
|
225
251
|
export {
|
|
226
252
|
chainflipProvider
|
|
227
253
|
};
|
|
228
|
-
//# sourceMappingURL=chunk-
|
|
254
|
+
//# sourceMappingURL=chunk-XUMGQNH4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider.ts"],"sourcesContent":["/**\n * Chainflip provider — VAULT SWAPS through the public backend (chainflip-swap.chainflip.io), Chainflip's own broker at\n * 0 bps, no account or key:\n * quote GET /v2/quote?isVaultSwap=true → expected output, fees, ETA, recommended slippage\n * encode POST /api/encodeVaultSwapData → EVM vault calldata / Tron TRC-20 transfer + note (live quotes only)\n * status GET /v2/swaps/{source tx hash} → RECEIVING … COMPLETED | FAILED, egress / refund tx refs\n * The encoder runs on a server we do not control, so every byte it returns is decoded here and checked against the\n * request before the quote is handed out: vault address, source token and amount, destination chain / asset / address,\n * refund address, the minimum price (it must guarantee our minimum), no boost / DCA / CCM / affiliates, broker fee 0.\n * Fill-or-kill is always on: a price below the minimum after the retry window refunds to the source address.\n */\nimport {describeChainflipActivity} from \"./activity.js\";\nimport {CF_API_DEFAULT, CF_CHAINS, CF_VAULTS, cfAsset, chainflip as cfg} from \"./config.js\";\nimport {decodeEvmVaultCall, decodeTronNote, destAddressBytes, fromHex, minOutOf, minPriceX128For, sameBytes, tronToBytes, type CfParameters} from \"./codec.js\";\nimport {httpRefusal, refusal, refusalNotes, type Swap2RefusalInfo, type Swap2RefusalReason} from \"@anywalletkit/protocol-swap2-core/errors\";\nimport {timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {decodeFunctionData, parseAbi, type Hex} from \"viem\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\nconst QUOTE_TTL_MS = 60_000;\n/** 50 state-chain blocks ≈ 5 min of retries before a fill-or-kill refund (the backend's recommendation). */\nconst RETRY_BLOCKS = 50;\nconst MAX_RETRY_BLOCKS = 600;\nconst ERC20 = parseAbi([\"function transfer(address to, uint256 amount) returns (bool)\"]);\n\nexport interface ChainflipProviderConfig {\n enabled?: boolean;\n /** Backend base URL (default the public chainflip-swap.chainflip.io). */\n apiUrl?: string;\n /** Live-price (oracle) slippage guard in bps; null turns it off. Default: the quote's recommendation. */\n maxOraclePriceSlippageBps?: number | null;\n}\n\ninterface CfQuote {\n type?: string;\n egressAmount?: string;\n depositAmount?: string;\n estimatedDurationSeconds?: number;\n recommendedSlippageTolerancePercent?: number;\n recommendedLivePriceSlippageTolerancePercent?: number;\n includedFees?: {type: string; chain: string; asset: string; amount: string}[];\n lowLiquidityWarning?: boolean;\n}\n\n/** The intent id: `cfvault:<source chain>` — vault swaps are tracked by their source transaction. */\nconst INTENT_PREFIX = \"cfvault:\";\n\n/** The reason behind each text `checkParams` returns. */\nconst notes = refusalNotes();\n\n/**\n * What a failed backend answer means: the backend's own message first (limits, liquidity, a halted pool), else the\n * status (429 with Retry-After, 408 / 425 / 5xx). The backend takes no key, so a 401 / 403 (a CDN, WAF or region block\n * in front of it) is `upstream_unavailable` with its status, never `key_rejected`. Undefined when neither says.\n */\nfunction backendRefusal(status: number, body: unknown, retryAfter: string | null): Swap2RefusalInfo | undefined {\n const http = httpRefusal(status, retryAfter);\n const byStatus: Swap2RefusalInfo | undefined = http?.reason === \"key_rejected\" ? {reason: \"upstream_unavailable\", httpStatus: status} : http;\n if (byStatus?.reason === \"rate_limited\") return byStatus;\n const m = (body as {message?: unknown} | null)?.message;\n const said = typeof m === \"string\" ? backendReason(m) : undefined;\n return said && said !== byStatus?.reason ? {reason: said} : byStatus;\n}\nfunction backendReason(message: string): Swap2RefusalReason | undefined {\n if (/liquidity/i.test(message)) return \"insufficient_liquidity\";\n if (/maximum (?:swap )?amount|above (?:the )?max|too (?:large|big|high)|exceeds? (?:the )?max/i.test(message)) return \"amount_too_large\";\n if (/minimum (?:swap |deposit )?amount|below (?:the )?minimum|lower than (?:the )?(?:estimated|minimum)|too (?:small|low)/i.test(message)) return \"amount_too_small\";\n if (/halt|paus|maintenance|disabled|suspend|not enabled/i.test(message)) return \"chain_halted\";\n if (/rate.?limit|too many requests/i.test(message)) return \"rate_limited\";\n if (/not supported|unsupported|unknown asset|invalid asset/i.test(message)) return \"unsupported_pair\";\n if (/no (?:route|quote)|could not find/i.test(message)) return \"no_route\";\n return undefined;\n}\n\nexport function chainflipProvider(config: ChainflipProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const base = new URL(config.apiUrl ?? CF_API_DEFAULT).toString().replace(/\\/$/, \"\");\n\n /** One GET/POST with a single back-off on 429 (the backend sits behind a rate-limiting CDN). */\n const call = async (path: string, init: RequestInit = {}, signal?: AbortSignal): Promise<{ok: boolean; status: number; body: unknown; retryAfter: string | null}> => {\n for (let attempt = 0; ; attempt++) {\n const res = await fetch(`${base}${path}`, {...init, headers: {accept: \"application/json\", ...(init.body ? {\"content-type\": \"application/json\"} : {}), ...(init.headers ?? {})}, signal: signal ?? timeoutSignal(12_000)});\n const body = await res.json().catch(() => null);\n if (res.status === 429 && attempt === 0 && !signal?.aborted) { await new Promise((r) => setTimeout(r, 1200)); continue; }\n return {ok: res.ok, status: res.status, body, retryAfter: res.headers?.get?.(\"retry-after\") ?? null};\n }\n };\n\n /** Everything the encoder returned must say exactly what we asked; any difference refuses the quote. */\n const checkParams = (p: CfParameters, want: {refund: Uint8Array; minPriceX128: bigint; oracle: number | null}): string | null => {\n if (!sameBytes(fromHex(p.refundAddress), want.refund)) return notes.note(`refund address ${p.refundAddress} is not the sender`, \"recipient_mismatch\");\n if (p.minPriceX128 < want.minPriceX128) return notes.note(\"minimum price is below the one requested\", \"price_check_failed\");\n if (p.retryDurationBlocks > MAX_RETRY_BLOCKS) return notes.note(`retry window ${p.retryDurationBlocks} blocks is too long`, \"policy_refused\");\n if (p.maxOraclePriceSlippageBps !== want.oracle) return notes.note(\"oracle slippage guard differs from the request\", \"price_check_failed\");\n if (p.dca !== null) return notes.note(\"unexpected DCA parameters\", \"policy_refused\");\n if (p.boostFeeBps !== 0) return notes.note(\"unexpected boost fee\", \"policy_refused\");\n if (p.broker.feeBps !== 0) return notes.note(`broker takes ${p.broker.feeBps} bps`, \"policy_refused\");\n if (p.affiliates.length) return notes.note(\"unexpected affiliates\", \"policy_refused\");\n return null;\n };\n\n return {\n name: \"chainflip\",\n describeActivity: describeChainflipActivity,\n enabled: () => config.enabled ?? true,\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (from: string, to: string) => cfg.supports(from, to),\n supportsRoute(from: Asset, to: Asset): boolean {\n if (!cfg.supports(from.chain, to.chain)) return false;\n const a = cfAsset(from.chain, from.token), b = cfAsset(to.chain, to.token);\n return !!a && !!b && a.id !== b.id;\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n const dry = params.dry !== false;\n const refuse = (reason: string, why?: Swap2RefusalReason | Swap2RefusalInfo): null => {\n const info = typeof why === \"string\" ? {reason: why} : why;\n if (info) params.onRefusal?.(`chainflip: ${reason}`, info);\n else params.onRefusal?.(`chainflip: ${reason}`);\n return null;\n };\n // A network failure or our own timeout is the backend's; the caller's abort is not.\n const unreachable = (): Swap2RefusalReason | undefined => (signal?.aborted ? undefined : \"upstream_unavailable\");\n if (!cfg.supports(params.sourceChain, params.destChain)) return refuse(`no vault swap ${params.sourceChain} → ${params.destChain}`, \"unsupported_pair\");\n const src = cfAsset(params.sourceChain, params.sourceToken);\n const dst = cfAsset(params.destChain, params.destToken);\n if (!src || !dst) return refuse(`asset not listed (${params.sourceToken} on ${params.sourceChain} → ${params.destToken} on ${params.destChain})`, \"unsupported_pair\");\n const amountIn = BigInt(params.amountIn);\n if (amountIn < src.minDeposit) return refuse(`below the minimum deposit (${src.minDeposit} ${src.asset})`, \"amount_too_small\");\n let destBytes: Uint8Array;\n try { destBytes = destAddressBytes(params.destChain, params.destAddress); } catch (e) { return refuse((e as Error).message); }\n\n const qs = new URLSearchParams({amount: params.amountIn, srcChain: src.chain, srcAsset: src.asset, destChain: dst.chain, destAsset: dst.asset, isVaultSwap: \"true\", isOnChain: \"false\", dcaV2Enabled: \"false\"});\n let q: CfQuote | undefined;\n let answered: unknown;\n try {\n const r = await call(`/v2/quote?${qs.toString()}`, {}, signal);\n if (!r.ok) return refuse(`quote ${r.status}: ${String((r.body as {message?: string} | null)?.message ?? \"\").slice(0, 160)}`, backendRefusal(r.status, r.body, r.retryAfter));\n answered = r.body;\n q = (r.body as CfQuote[] | null)?.find((x) => x.type === \"REGULAR\") ?? (r.body as CfQuote[] | null)?.[0];\n } catch (e) { return refuse(`quote failed: ${(e as Error).message.slice(0, 160)}`, unreachable()); }\n // An empty list is no quote for the pair; anything else without an amount is an answer of another shape, unless\n // the caller aborted while the body was read (it reads as null then).\n if (!q?.egressAmount || !/^\\d+$/.test(q.egressAmount)) return refuse(\"quote without an egress amount\", Array.isArray(answered) && answered.length === 0 ? \"no_route\" : unreachable());\n if (q.type && q.type !== \"REGULAR\") return refuse(`${q.type} quotes are not supported`, \"unsupported_pair\");\n const expected = BigInt(q.egressAmount);\n // Minimum: the expected output less the slippage (the caller's, else the backend's advice), or the\n // caller's floor. A caller who names both is held to both — the engine checks the quote against\n // each (execution sends a floor under the listed quote AND the slippage the list was quoted at).\n const slipBps = params.slippageBps ?? Math.round((q.recommendedSlippageTolerancePercent ?? 1) * 100);\n const byTolerance = (expected * BigInt(10_000 - Math.min(9_999, Math.max(0, slipBps)))) / 10_000n;\n const callerFloor = params.minAmountOut !== undefined ? BigInt(params.minAmountOut) : undefined;\n const minOut = callerFloor === undefined ? byTolerance\n : params.slippageBps !== undefined && byTolerance > callerFloor ? byTolerance : callerFloor;\n if (minOut > expected) return refuse(`floor ${minOut} above the expected output ${expected}`, \"price_check_failed\");\n const minPriceX128 = minPriceX128For(amountIn, minOut);\n const guaranteed = minOutOf(amountIn, minPriceX128);\n const oracle = config.maxOraclePriceSlippageBps !== undefined ? config.maxOraclePriceSlippageBps\n : q.recommendedLivePriceSlippageTolerancePercent !== undefined ? Math.round(q.recommendedLivePriceSlippageTolerancePercent * 100) : null;\n const fees = (q.includedFees ?? []).map((f) => ({type: (f.type === \"NETWORK\" ? \"protocol\" : f.type === \"BROKER\" ? \"affiliate\" : \"network\") as \"network\" | \"protocol\" | \"affiliate\", amount: f.amount, token: `${f.chain}:${f.asset}`, included: true, description: `Chainflip ${f.type.toLowerCase()} fee`}));\n const stableUsd = (f: {asset: string; amount: string}) => (f.asset === \"USDC\" || f.asset === \"USDT\" ? Number(f.amount) / 1e6 : 0);\n const common = {\n provider: \"chainflip\",\n sourceAmount: params.amountIn,\n destAmount: q.egressAmount,\n minDestAmount: guaranteed.toString(),\n feeUsd: (q.includedFees ?? []).reduce((s, f) => s + stableUsd(f), 0),\n fees,\n etaSeconds: Math.round(q.estimatedDurationSeconds ?? 180),\n reliability: q.lowLiquidityWarning ? 0.75 : 0.9,\n validUntilMs: Date.now() + QUOTE_TTL_MS,\n };\n if (dry) return {...common, intentId: `dry:${crypto.randomUUID()}`, depositAddress: \"\", depositMemo: null};\n\n if (!params.refundAddress) return refuse(\"live quote without a refund address\", \"policy_refused\");\n let refund: Uint8Array;\n try { refund = destAddressBytes(params.sourceChain, params.refundAddress); } catch (e) { return refuse(`refund address: ${(e as Error).message}`); }\n const body = {\n srcAsset: {chain: src.chain, asset: src.asset}, destAsset: {chain: dst.chain, asset: dst.asset},\n srcAddress: params.refundAddress, destAddress: params.destAddress, amount: params.amountIn,\n fillOrKillParams: {retryDurationBlocks: RETRY_BLOCKS, refundAddress: params.refundAddress, minPriceX128: minPriceX128.toString(), maxOraclePriceSlippage: oracle},\n commissionBps: 0,\n };\n let enc: {to?: string; calldata?: string; value?: string; note?: string; sourceTokenAddress?: string; chain?: string};\n try {\n const r = await call(\"/api/encodeVaultSwapData\", {method: \"POST\", body: JSON.stringify(body)}, signal);\n if (!r.ok) return refuse(`encode ${r.status}: ${String((r.body as {message?: string} | null)?.message ?? \"\").slice(0, 160)}`, backendRefusal(r.status, r.body, r.retryAfter));\n enc = (r.body ?? {}) as typeof enc;\n } catch (e) { return refuse(`encode failed: ${(e as Error).message.slice(0, 160)}`, unreachable()); }\n const want = {refund, minPriceX128, oracle};\n const vault = CF_VAULTS[params.sourceChain]!;\n const dstChain = CF_CHAINS[params.destChain]!;\n\n // An answer without a target at all is a malformed one (a body that is not JSON, `{}`, or the caller's abort while\n // it was read), not another vault.\n try {\n if (params.sourceChain.startsWith(\"eip155:\")) {\n if (!enc.to || enc.to.toLowerCase() !== vault.toLowerCase()) return refuse(`encoder targets ${enc.to}, not the ${src.chain} Vault`, !enc.to ? unreachable() : \"vault_mismatch\");\n const v = decodeEvmVaultCall(enc.calldata ?? \"0x\");\n if (v.dstChain !== dstChain.id || v.dstToken !== dst.id || !sameBytes(v.dstAddress, destBytes)) return refuse(\"encoded destination differs from the request\", \"recipient_mismatch\");\n if (src.token === null) {\n if (!v.native || BigInt(enc.value ?? \"0\") !== amountIn) return refuse(\"native vault call with a different amount\", \"policy_refused\");\n } else if (v.native || v.srcToken?.toLowerCase() !== src.token.toLowerCase() || v.amount !== amountIn || BigInt(enc.value ?? \"0\") !== 0n) {\n return refuse(\"token vault call with a different token or amount\", \"policy_refused\");\n }\n const bad = checkParams(v.params, want);\n if (bad) return refuse(bad, notes.reasonOf(bad));\n return {\n ...common,\n intentId: `${INTENT_PREFIX}${params.sourceChain}`,\n depositAddress: \"\",\n depositMemo: null,\n txRequest: {to: vault, data: enc.calldata!, value: src.token === null ? params.amountIn : \"0\", chainId: Number(params.sourceChain.slice(7)), ...(src.token ? {approvalAddress: vault} : {})},\n providerData: {kind: \"evm\", srcAsset: String(src.id), dstAsset: String(dst.id)},\n };\n }\n // Tron: the deposit IS a plain transfer to the Vault; the swap parameters ride in the transaction note.\n if (enc.to !== vault) return refuse(`encoder targets ${enc.to}, not the Tron Vault`, !enc.to ? unreachable() : \"vault_mismatch\");\n if (!enc.note) return refuse(\"Tron vault swap without a note\", \"recipient_unverifiable\");\n if (src.token !== null) {\n if (enc.sourceTokenAddress !== src.token) return refuse(`source token ${enc.sourceTokenAddress} is not ${src.asset}`, \"policy_refused\");\n const t = decodeFunctionData({abi: ERC20, data: (enc.calldata ?? \"0x\") as Hex});\n const toVault = sameBytes(fromHex(String(t.args[0])), tronToBytes(vault));\n if (!toVault || t.args[1] !== amountIn) return refuse(\"TRC-20 transfer is not the amount to the Vault\", toVault ? \"policy_refused\" : \"vault_mismatch\");\n }\n const n = decodeTronNote(enc.note);\n if (n.outputAsset !== dst.id || n.destTag !== dstChain.addrTag || !sameBytes(n.destAddress, destBytes)) return refuse(\"note names another destination\", \"recipient_mismatch\");\n const bad = checkParams(n.params, want);\n if (bad) return refuse(bad, notes.reasonOf(bad));\n return {\n ...common,\n intentId: `${INTENT_PREFIX}${params.sourceChain}`,\n depositAddress: vault,\n depositMemo: enc.note,\n providerData: {kind: \"tron\", memoEncoding: \"hex\", srcAsset: String(src.id), dstAsset: String(dst.id)},\n };\n } catch (e) {\n return refuse(`encoder output does not decode: ${(e as Error).message.slice(0, 160)}`, \"upstream_unavailable\");\n }\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n if (quote.providerData?.kind === \"evm\") {\n const tx = quote.txRequest;\n if (!tx?.to || !tx.data) throw refusal(\"policy_refused\", \"chainflip: quote has no vault call\");\n return {chain: \"\", to: tx.to, value: tx.value ?? \"0\", data: tx.data, ...(tx.chainId !== undefined ? {chainId: tx.chainId} : {}), ...(tx.approvalAddress ? {approvalAddress: tx.approvalAddress} : {})};\n }\n if (quote.providerData?.kind === \"tron\") {\n if (!quote.depositAddress || !quote.depositMemo) throw refusal(\"policy_refused\", \"chainflip: Tron quote without vault or note\");\n return {chain: \"\", to: quote.depositAddress, value: quote.sourceAmount, memo: quote.depositMemo, memoEncoding: \"hex\"};\n }\n throw refusal(\"policy_refused\", \"chainflip: not a live vault-swap quote\");\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n if (!ref.sourceTxHash) return {state: \"pending\"};\n const id = ref.intentId.startsWith(`${INTENT_PREFIX}tron:`) ? ref.sourceTxHash.replace(/^0x/, \"\") : ref.sourceTxHash;\n try {\n const r = await call(`/v2/swaps/${encodeURIComponent(id)}`);\n if (r.status === 404) return {state: \"pending\"}; // not witnessed yet\n if (!r.ok) return {state: \"pending\"};\n const s = (r.body ?? {}) as {state?: string; swapEgress?: {txRef?: string}; refundEgress?: {txRef?: string}; fallbackEgress?: {txRef?: string}; deposit?: {txRef?: string}};\n const egress = s.swapEgress?.txRef;\n const refunded = !!(s.refundEgress || s.fallbackEgress);\n if (s.state === \"COMPLETED\" || (s.state === \"SENT\" && egress)) {\n // Fill-or-kill: only a refund went out → refunded; swapped in part and refunded the rest → partial (round 3, M26).\n if (!s.swapEgress && refunded) return {state: \"refunded\", depositReceived: true};\n if (s.swapEgress && refunded) return {state: \"partial\", depositReceived: true, ...(egress ? {destTxHash: egress} : {})};\n return {state: \"completed\", depositReceived: true, ...(egress ? {destTxHash: egress} : {})};\n }\n if (s.state === \"FAILED\") return s.refundEgress || s.fallbackEgress ? {state: \"refunded\", depositReceived: true} : {state: \"failed\", depositReceived: true};\n const received = s.state === \"RECEIVING\" || s.state === \"SWAPPING\" || s.state === \"SENDING\" || s.state === \"SENT\";\n return {state: \"pending\", depositReceived: received};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAcA,SAAQ,aAAa,SAAS,oBAAmE;AACjG,SAAQ,qBAAoB;AAC5B,SAAQ,oBAAoB,gBAAyB;AAGrD,IAAM,eAAe;AAErB,IAAM,eAAe;AACrB,IAAM,mBAAmB;AACzB,IAAM,QAAQ,SAAS,CAAC,8DAA8D,CAAC;AAsBvF,IAAM,gBAAgB;AAGtB,IAAM,QAAQ,aAAa;AAO3B,SAAS,eAAe,QAAgB,MAAe,YAAyD;AAC9G,QAAM,OAAO,YAAY,QAAQ,UAAU;AAC3C,QAAM,WAAyC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AC5F;AACA,YAAI,EAAE,UAAU,SAAU,QAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAC,OAAO,YAAY,iBAAiB,KAAI,IAAI,EAAC,OAAO,UAAU,iBAAiB,KAAI;AAC1J,cAAM,WAAW,EAAE,UAAU,eAAe,EAAE,UAAU,cAAc,EAAE,UAAU,aAAa,EAAE,UAAU;AAC3G,eAAO,EAAC,OAAO,WAAW,iBAAiB,SAAQ;AAAA,MACrD,QAAQ;AACN,eAAO,EAAC,OAAO,UAAS;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACF;","names":["bad"]}
|
package/dist/config.cjs
CHANGED
|
@@ -31,6 +31,7 @@ __export(config_exports, {
|
|
|
31
31
|
chainflipVerifyQuote: () => chainflipVerifyQuote
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(config_exports);
|
|
34
|
+
var import_errors = require("@anywalletkit/protocol-swap2-core/errors");
|
|
34
35
|
|
|
35
36
|
// src/codec.ts
|
|
36
37
|
var import_base = require("@scure/base");
|
|
@@ -209,50 +210,69 @@ var chainflip = {
|
|
|
209
210
|
supportsChain: (chain) => !!CF_CHAINS[chain],
|
|
210
211
|
supports: (from, to) => CF_SOURCE_CHAINS.has(from) && !!CF_CHAINS[to] && from !== to
|
|
211
212
|
};
|
|
213
|
+
var notes = (0, import_errors.refusalNotes)();
|
|
214
|
+
var unparsed = /* @__PURE__ */ new Set();
|
|
215
|
+
function decodeFailure(text, requestParsed) {
|
|
216
|
+
unparsed.delete(text);
|
|
217
|
+
if (requestParsed) return notes.note(text, "upstream_unavailable");
|
|
218
|
+
unparsed.add(text);
|
|
219
|
+
if (unparsed.size > 64) unparsed.delete(unparsed.values().next().value);
|
|
220
|
+
return text;
|
|
221
|
+
}
|
|
222
|
+
var reasonOf = (text) => unparsed.has(text) ? void 0 : notes.reasonOf(text);
|
|
212
223
|
function chainflipVerifyQuote(params, quote) {
|
|
224
|
+
let readingRequest = false;
|
|
213
225
|
try {
|
|
214
226
|
const src = cfAsset(params.sourceChain, params.sourceToken);
|
|
215
227
|
const dst = cfAsset(params.destChain, params.destToken);
|
|
216
228
|
const dstChain = CF_CHAINS[params.destChain];
|
|
217
229
|
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";
|
|
230
|
+
if (!src || !dst || !dstChain || !vault || !CF_SOURCE_CHAINS.has(params.sourceChain)) return notes.note("not a vault swap this release signs", "unsupported_pair");
|
|
219
231
|
if (!quote.txRequest && !quote.depositAddress) return null;
|
|
220
|
-
if (!params.refundAddress) return "a live quote needs the refund address";
|
|
232
|
+
if (!params.refundAddress) return notes.note("a live quote needs the refund address", "policy_refused");
|
|
233
|
+
readingRequest = true;
|
|
221
234
|
const amountIn = BigInt(params.amountIn);
|
|
222
235
|
const dest = destAddressBytes(params.destChain, params.destAddress);
|
|
223
236
|
const refund = destAddressBytes(params.sourceChain, params.refundAddress);
|
|
237
|
+
readingRequest = false;
|
|
224
238
|
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";
|
|
239
|
+
if (!sameBytes(fromHex(p.refundAddress), refund)) return notes.note("the refund address is not the sender", "recipient_mismatch");
|
|
240
|
+
if (minOutOf(amountIn, p.minPriceX128) < BigInt(quote.minDestAmount)) return notes.note("the minimum price does not guarantee the quoted minimum", "price_check_failed");
|
|
241
|
+
if (p.dca !== null || p.boostFeeBps !== 0 || p.broker.feeBps !== 0 || p.affiliates.length) return notes.note("DCA, boost, a broker fee or affiliates", "policy_refused");
|
|
228
242
|
return null;
|
|
229
243
|
};
|
|
230
244
|
if (params.sourceChain.startsWith("eip155:")) {
|
|
231
245
|
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
|
|
246
|
+
if (quote.depositAddress || !tx?.data || tx.serializedTx !== void 0) return notes.note("an EVM vault swap is a vault call, not a deposit", "policy_refused");
|
|
247
|
+
if (!tx.to || tx.to.toLowerCase() !== vault.toLowerCase()) return notes.note(`the call targets ${tx.to}, not the Vault`, "vault_mismatch");
|
|
234
248
|
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";
|
|
249
|
+
if (v.dstChain !== dstChain.id || v.dstToken !== dst.id || !sameBytes(v.dstAddress, dest)) return notes.note("the vault call names another destination", "recipient_mismatch");
|
|
236
250
|
if (src.token === null) {
|
|
237
|
-
if (!v.native || BigInt(tx.value ?? "0") !== amountIn || tx.approvalAddress) return "the native vault call moves another amount";
|
|
251
|
+
if (!v.native || BigInt(tx.value ?? "0") !== amountIn || tx.approvalAddress) return notes.note("the native vault call moves another amount", "policy_refused");
|
|
238
252
|
} 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";
|
|
253
|
+
return notes.note("the token vault call moves another token or amount", "policy_refused");
|
|
240
254
|
}
|
|
241
255
|
return checkParams(v.params);
|
|
242
256
|
}
|
|
243
|
-
if (quote.txRequest || quote.depositAddress !== vault || !quote.depositMemo)
|
|
257
|
+
if (quote.txRequest || quote.depositAddress !== vault || !quote.depositMemo) {
|
|
258
|
+
return notes.note(
|
|
259
|
+
"a Tron vault swap is a send to the Tron Vault with its note",
|
|
260
|
+
quote.txRequest ? "policy_refused" : quote.depositAddress !== vault ? "vault_mismatch" : "recipient_unverifiable"
|
|
261
|
+
);
|
|
262
|
+
}
|
|
244
263
|
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";
|
|
264
|
+
if (n.outputAsset !== dst.id || n.destTag !== dstChain.addrTag || !sameBytes(n.destAddress, dest)) return notes.note("the note names another destination", "recipient_mismatch");
|
|
246
265
|
return checkParams(n.params);
|
|
247
266
|
} catch (e) {
|
|
248
|
-
return `the vault swap does not decode (${(e instanceof Error ? e.message : String(e)).slice(0, 120)})
|
|
267
|
+
return decodeFailure(`the vault swap does not decode (${(e instanceof Error ? e.message : String(e)).slice(0, 120)})`, !readingRequest);
|
|
249
268
|
}
|
|
250
269
|
}
|
|
251
270
|
var chainflipPins = Object.freeze({
|
|
252
271
|
callTargets: (chain) => chainflipVaultFor(chain),
|
|
253
272
|
spenders: (chain) => chainflipVaultFor(chain),
|
|
254
273
|
verifyQuote: chainflipVerifyQuote,
|
|
255
|
-
verifyBuild: (quote, tx) => quote.depositMemo && tx.memoEncoding !== "hex" ? "the Tron note is not sent as hex bytes" : null,
|
|
274
|
+
verifyBuild: (quote, tx) => quote.depositMemo && tx.memoEncoding !== "hex" ? notes.note("the Tron note is not sent as hex bytes", "policy_refused") : null,
|
|
275
|
+
reasonOf,
|
|
256
276
|
depositAddressRoutes: true
|
|
257
277
|
});
|
|
258
278
|
function chainflipVaultFor(chain) {
|
package/dist/config.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,KAAK,GAAG;AAAA,EAAI;AAAA,EAC/C,MAAM,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AI,CAAC;AAC5B;","names":["dstChain","dstAddress","dstToken","cf"]}
|
|
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 {refusalNotes} from \"@anywalletkit/protocol-swap2-core/errors\";\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/** The reason behind each text {@link chainflipVerifyQuote} and the pins' verifyBuild return (`chainflipPins.reasonOf`). */\nconst notes = refusalNotes();\n/**\n * Decode-failure texts last returned for the app's own field (destination, refund address, amount) that did not parse:\n * the caller's argument, so `reasonOf` leaves them unclassified. The same text can come from a quote that does not\n * decode, so the latest verdict wins; kept to the last 64.\n */\nconst unparsed = new Set<string>();\nfunction decodeFailure(text: string, requestParsed: boolean): string {\n unparsed.delete(text);\n if (requestParsed) return notes.note(text, \"upstream_unavailable\");\n unparsed.add(text);\n if (unparsed.size > 64) unparsed.delete(unparsed.values().next().value!);\n return text;\n}\nconst reasonOf = (text: string) => (unparsed.has(text) ? undefined : notes.reasonOf(text));\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 // True while the app's own fields are read: a throw then is the caller's argument, not the quote's.\n let readingRequest = false;\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 notes.note(\"not a vault swap this release signs\", \"unsupported_pair\");\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 notes.note(\"a live quote needs the refund address\", \"policy_refused\");\n readingRequest = true;\n const amountIn = BigInt(params.amountIn);\n const dest = destAddressBytes(params.destChain, params.destAddress);\n const refund = destAddressBytes(params.sourceChain, params.refundAddress);\n readingRequest = false;\n const checkParams = (p: CfParameters): string | null => {\n if (!sameBytes(fromHex(p.refundAddress), refund)) return notes.note(\"the refund address is not the sender\", \"recipient_mismatch\");\n if (minOutOf(amountIn, p.minPriceX128) < BigInt(quote.minDestAmount)) return notes.note(\"the minimum price does not guarantee the quoted minimum\", \"price_check_failed\");\n if (p.dca !== null || p.boostFeeBps !== 0 || p.broker.feeBps !== 0 || p.affiliates.length) return notes.note(\"DCA, boost, a broker fee or affiliates\", \"policy_refused\");\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 notes.note(\"an EVM vault swap is a vault call, not a deposit\", \"policy_refused\");\n if (!tx.to || tx.to.toLowerCase() !== vault.toLowerCase()) return notes.note(`the call targets ${tx.to}, not the Vault`, \"vault_mismatch\");\n const v = decodeEvmVaultCall(tx.data);\n if (v.dstChain !== dstChain.id || v.dstToken !== dst.id || !sameBytes(v.dstAddress, dest)) return notes.note(\"the vault call names another destination\", \"recipient_mismatch\");\n if (src.token === null) {\n if (!v.native || BigInt(tx.value ?? \"0\") !== amountIn || tx.approvalAddress) return notes.note(\"the native vault call moves another amount\", \"policy_refused\");\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 notes.note(\"the token vault call moves another token or amount\", \"policy_refused\");\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) {\n // A send elsewhere is the wrong vault; a send to the Vault without its note binds no destination.\n return notes.note(\"a Tron vault swap is a send to the Tron Vault with its note\",\n quote.txRequest ? \"policy_refused\" : quote.depositAddress !== vault ? \"vault_mismatch\" : \"recipient_unverifiable\");\n }\n const n = decodeTronNote(quote.depositMemo);\n if (n.outputAsset !== dst.id || n.destTag !== dstChain.addrTag || !sameBytes(n.destAddress, dest)) return notes.note(\"the note names another destination\", \"recipient_mismatch\");\n return checkParams(n.params);\n } catch (e) {\n return decodeFailure(`the vault swap does not decode (${(e instanceof Error ? e.message : String(e)).slice(0, 120)})`, !readingRequest);\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. `reasonOf`\n * classifies each text the verifiers return (`Swap2RefusalReason`), so a remote stub's refusal carries it.\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\" ? notes.note(\"the Tron note is not sent as hex bytes\", \"policy_refused\") : null,\n reasonOf,\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;AAUA,oBAA2B;;;ACF3B,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,KAAK,GAAG;AAAA,EAAI;AAAA,EAC/C,MAAM,GAAW;AAAE,SAAK,KAAK,CAAC;AAAG,UAAM,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AM,mBAAmB,QAAQ,mBAAmB;AAAA,MAAwB;AAAA,IACrH;AACA,UAAM,IAAI,eAAe,MAAM,WAAW;AAC1C,QAAI,EAAE,gBAAgB,IAAI,MAAM,EAAE,YAAY,SAAS,WAAW,CAAC,UAAU,EAAE,aAAa,IAAI,EAAG,QAAO,MAAM,KAAK,sCAAsC,oBAAoB;AAC/K,WAAO,YAAY,EAAE,MAAM;AAAA,EAC7B,SAAS,GAAG;AACV,WAAO,cAAc,oCAAoC,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,GAAG,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,cAAc;AAAA,EACxI;AACF;AASO,IAAM,gBAA4B,OAAO,OAAO;AAAA,EACrD,aAAa,CAAC,UAAqC,kBAAkB,KAAK;AAAA,EAC1E,UAAU,CAAC,UAAqC,kBAAkB,KAAK;AAAA,EACvE,aAAa;AAAA,EACb,aAAa,CAAC,OAAc,OAC1B,MAAM,eAAe,GAAG,iBAAiB,QAAQ,MAAM,KAAK,0CAA0C,gBAAgB,IAAI;AAAA,EAC5H;AAAA,EACA,sBAAsB;AACxB,CAAC;AACD,SAAS,kBAAkB,OAAkC;AAC3D,QAAM,QAAQ,MAAM,WAAW,SAAS,KAAK,OAAO,UAAU,eAAe,KAAK,WAAW,KAAK,IAAI,UAAU,KAAK,IAAI;AACzH,SAAO,QAAQ,CAAC,KAAK,IAAI,CAAC;AAC5B;","names":["dstChain","dstAddress","dstToken","cf"]}
|
package/dist/config.d.cts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import { RemotePins, QuoteParams, Quote } from '@anywalletkit/protocol-swap2-core/types';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Chainflip (JIT-AMM state chain) — chains, assets and contracts as the public backend and the vault encodings name them.
|
|
5
|
-
* Asset ids, chain ids and decimals are the protocol's own (`cf_environment` / networkInfo, verified 2026-10-20); the
|
|
6
|
-
* contract addresses are Chainflip's mainnet deployments (docs mainnet-addresses, confirmed by live encodings).
|
|
7
|
-
*
|
|
8
|
-
* Only VAULT SWAPS are offered: the donor signs a transaction whose every Chainflip parameter (destination, minimum price,
|
|
9
|
-
* refund address) is decoded and checked locally before signing — no off-chain deposit channel to trust, and on Tron no
|
|
10
|
-
* 3.4 USDT ingress fee. Sources: EVM (Ethereum, Arbitrum) and Tron in this release; Solana / Bitcoin vault swaps need an
|
|
11
|
-
* instruction / OP_RETURN builder and come next. Destinations: every live chain.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
3
|
type CfChain = "Ethereum" | "Bitcoin" | "Arbitrum" | "Solana" | "Tron";
|
|
15
4
|
interface CfAsset {
|
|
16
5
|
chain: CfChain;
|
|
@@ -57,7 +46,8 @@ declare function chainflipVerifyQuote(params: QuoteParams, quote: Quote): string
|
|
|
57
46
|
* The Chainflip Vault a vault swap calls and approves on an EVM chain ({@link CF_VAULTS}), and
|
|
58
47
|
* {@link chainflipVerifyQuote} — the app's pins for `remoteProvider({name: "chainflip", baseUrl, ...chainflipPins})`
|
|
59
48
|
* (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.
|
|
49
|
+
* opened to that deposit route (`depositAddressRoutes`, scan 2026-10-28 F9); its note must ride as hex bytes. `reasonOf`
|
|
50
|
+
* classifies each text the verifiers return (`Swap2RefusalReason`), so a remote stub's refusal carries it.
|
|
61
51
|
*/
|
|
62
52
|
declare const chainflipPins: RemotePins;
|
|
63
53
|
|
package/dist/config.d.ts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import { RemotePins, QuoteParams, Quote } from '@anywalletkit/protocol-swap2-core/types';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Chainflip (JIT-AMM state chain) — chains, assets and contracts as the public backend and the vault encodings name them.
|
|
5
|
-
* Asset ids, chain ids and decimals are the protocol's own (`cf_environment` / networkInfo, verified 2026-10-20); the
|
|
6
|
-
* contract addresses are Chainflip's mainnet deployments (docs mainnet-addresses, confirmed by live encodings).
|
|
7
|
-
*
|
|
8
|
-
* Only VAULT SWAPS are offered: the donor signs a transaction whose every Chainflip parameter (destination, minimum price,
|
|
9
|
-
* refund address) is decoded and checked locally before signing — no off-chain deposit channel to trust, and on Tron no
|
|
10
|
-
* 3.4 USDT ingress fee. Sources: EVM (Ethereum, Arbitrum) and Tron in this release; Solana / Bitcoin vault swaps need an
|
|
11
|
-
* instruction / OP_RETURN builder and come next. Destinations: every live chain.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
3
|
type CfChain = "Ethereum" | "Bitcoin" | "Arbitrum" | "Solana" | "Tron";
|
|
15
4
|
interface CfAsset {
|
|
16
5
|
chain: CfChain;
|
|
@@ -57,7 +46,8 @@ declare function chainflipVerifyQuote(params: QuoteParams, quote: Quote): string
|
|
|
57
46
|
* The Chainflip Vault a vault swap calls and approves on an EVM chain ({@link CF_VAULTS}), and
|
|
58
47
|
* {@link chainflipVerifyQuote} — the app's pins for `remoteProvider({name: "chainflip", baseUrl, ...chainflipPins})`
|
|
59
48
|
* (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.
|
|
49
|
+
* opened to that deposit route (`depositAddressRoutes`, scan 2026-10-28 F9); its note must ride as hex bytes. `reasonOf`
|
|
50
|
+
* classifies each text the verifiers return (`Swap2RefusalReason`), so a remote stub's refusal carries it.
|
|
61
51
|
*/
|
|
62
52
|
declare const chainflipPins: RemotePins;
|
|
63
53
|
|