@anywalletkit/protocol-swap2-kyberswap 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +98 -2
- package/dist/activity.cjs +196 -0
- package/dist/activity.cjs.map +1 -0
- package/dist/activity.d.cts +11 -0
- package/dist/activity.d.ts +11 -0
- package/dist/activity.js +10 -0
- package/dist/activity.js.map +1 -0
- package/dist/chunk-DEWODPQQ.js +430 -0
- package/dist/chunk-DEWODPQQ.js.map +1 -0
- package/dist/chunk-FWC6K553.js +21 -0
- package/dist/chunk-FWC6K553.js.map +1 -0
- package/dist/chunk-PIC4PYGN.js +32 -0
- package/dist/chunk-PIC4PYGN.js.map +1 -0
- package/dist/chunk-WOVGN3FL.js +184 -0
- package/dist/chunk-WOVGN3FL.js.map +1 -0
- package/dist/index.cjs +657 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.cjs +635 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +17 -0
- package/dist/protocol.d.ts +17 -0
- package/dist/protocol.js +10 -0
- package/dist/protocol.js.map +1 -0
- package/dist/provider.cjs +613 -0
- package/dist/provider.cjs.map +1 -0
- package/dist/provider.d.cts +31 -0
- package/dist/provider.d.ts +31 -0
- package/dist/provider.js +11 -0
- package/dist/provider.js.map +1 -0
- package/dist/router.cjs +204 -0
- package/dist/router.cjs.map +1 -0
- package/dist/router.d.cts +180 -0
- package/dist/router.d.ts +180 -0
- package/dist/router.js +39 -0
- package/dist/router.js.map +1 -0
- package/module.json +33 -0
- package/package.json +87 -3
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// src/router.ts
|
|
2
|
+
import { sourceAssetOf } from "@anywalletkit/protocol-swap2-core/util";
|
|
3
|
+
import { refusalNotes, refusalOf, withReason } from "@anywalletkit/protocol-swap2-core/errors";
|
|
4
|
+
import { ccAssetByToken } from "@anywalletkit/swap2-assets";
|
|
5
|
+
import { decodeFunctionData, encodeFunctionData, getAddress, parseAbi } from "viem";
|
|
6
|
+
var KYBER_ROUTER_V2 = "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5";
|
|
7
|
+
var KYBER_EXECUTOR = "0x8F10B468b06c6FD214B65F87778827F7D113f996";
|
|
8
|
+
var KYBER_ROUTER_V3 = "0x6868d319c8c9a78f7d39dc3602c5c917315132d7";
|
|
9
|
+
var KYBER_NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
10
|
+
var ZERO = "0x0000000000000000000000000000000000000000";
|
|
11
|
+
var KYBER_CHAINS = Object.freeze({
|
|
12
|
+
1: { slug: "ethereum", name: "Ethereum", build: "generic" },
|
|
13
|
+
8453: { slug: "base", name: "Base", build: "generic" },
|
|
14
|
+
56: { slug: "bsc", name: "BNB Smart Chain", build: "generic" },
|
|
15
|
+
42161: { slug: "arbitrum", name: "Arbitrum", build: "generic" },
|
|
16
|
+
10: { slug: "optimism", name: "Optimism", build: "generic" },
|
|
17
|
+
137: { slug: "polygon", name: "Polygon", build: "generic" },
|
|
18
|
+
43114: { slug: "avalanche", name: "Avalanche", build: "generic" },
|
|
19
|
+
59144: { slug: "linea", name: "Linea", build: "generic" },
|
|
20
|
+
146: { slug: "sonic", name: "Sonic", build: "lite" },
|
|
21
|
+
80094: { slug: "berachain", name: "Berachain", build: "lite" },
|
|
22
|
+
130: { slug: "unichain", name: "Unichain", build: "lite" },
|
|
23
|
+
999: { slug: "hyperevm", name: "HyperEVM", build: "lite" },
|
|
24
|
+
9745: { slug: "plasma", name: "Plasma", build: "lite" },
|
|
25
|
+
143: { slug: "monad", name: "Monad", build: "lite" },
|
|
26
|
+
4326: { slug: "megaeth", name: "MegaETH", build: "lite" },
|
|
27
|
+
4663: { slug: "robinhood", name: "Robinhood Chain", build: "lite" },
|
|
28
|
+
5042: { slug: "arc", name: "Arc", build: "lite" },
|
|
29
|
+
99901: { slug: "elysium", name: "Elysium", build: "lite" }
|
|
30
|
+
});
|
|
31
|
+
function kyberChain(chainId) {
|
|
32
|
+
return Object.prototype.hasOwnProperty.call(KYBER_CHAINS, chainId) ? KYBER_CHAINS[chainId] : void 0;
|
|
33
|
+
}
|
|
34
|
+
function kyberNativeSwaps(chainId) {
|
|
35
|
+
return !!ccAssetByToken(`eip155:${chainId}`, ZERO);
|
|
36
|
+
}
|
|
37
|
+
var KYBER_ROUTER_ABI = parseAbi([
|
|
38
|
+
"struct SwapDescriptionV2 { address srcToken; address dstToken; address[] srcReceivers; uint256[] srcAmounts; address[] feeReceivers; uint256[] feeAmounts; address dstReceiver; uint256 amount; uint256 minReturnAmount; uint256 flags; bytes permit; }",
|
|
39
|
+
"struct SwapExecutionParams { address callTarget; address approveTarget; bytes targetData; SwapDescriptionV2 desc; bytes clientData; }",
|
|
40
|
+
"function swap(SwapExecutionParams execution) payable returns (uint256 returnAmount, uint256 gasUsed)"
|
|
41
|
+
]);
|
|
42
|
+
var KYBER_SWAP_SELECTOR = "0xe21fd0e9";
|
|
43
|
+
var KYBER_REFUSED_SELECTORS = Object.freeze({
|
|
44
|
+
"0x59e50fed": "swapGeneric",
|
|
45
|
+
"0x8af033fb": "swapSimpleMode"
|
|
46
|
+
});
|
|
47
|
+
var KYBER_FLAGS_ALLOWED = 0x200n;
|
|
48
|
+
var KyberTransactionError = class extends Error {
|
|
49
|
+
constructor(message) {
|
|
50
|
+
super(`kyberswap: ${message}`);
|
|
51
|
+
this.name = "KyberTransactionError";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var fail = (message, reason) => withReason(new KyberTransactionError(message), reason);
|
|
55
|
+
var notes = refusalNotes();
|
|
56
|
+
var isAddr = (a) => typeof a === "string" && /^0x[0-9a-fA-F]{40}$/.test(a);
|
|
57
|
+
var same = (a, b) => isAddr(a) && isAddr(b) && a.toLowerCase() === b.toLowerCase();
|
|
58
|
+
var routerToken = (t) => same(t, ZERO) ? KYBER_NATIVE : t;
|
|
59
|
+
var named = (a) => isAddr(a) ? a : "something that is not an address";
|
|
60
|
+
var MAX_CALLDATA_BYTES = 64 * 1024;
|
|
61
|
+
function checkKyberTransaction(tx, expected) {
|
|
62
|
+
const chain = kyberChain(expected.chainId);
|
|
63
|
+
if (!chain) throw fail(`chain ${expected.chainId} has no pinned KyberSwap router`, "unsupported_pair");
|
|
64
|
+
if (same(tx.to, KYBER_ROUTER_V3)) throw fail("Kyber router V3 not supported yet", "policy_refused");
|
|
65
|
+
if (!same(tx.to, KYBER_ROUTER_V2)) throw fail(`the transaction targets ${named(tx.to)}, not the KyberSwap router on ${chain.name}`, "vault_mismatch");
|
|
66
|
+
if (!isAddr(expected.receiver) || same(expected.receiver, ZERO) || same(expected.receiver, KYBER_ROUTER_V2) || same(expected.receiver, KYBER_EXECUTOR)) {
|
|
67
|
+
throw fail("invalid receiver", "recipient_mismatch");
|
|
68
|
+
}
|
|
69
|
+
const nativeIn = same(expected.tokenIn, ZERO), nativeOut = same(expected.tokenOut, ZERO);
|
|
70
|
+
if ((nativeIn || nativeOut) && !kyberNativeSwaps(expected.chainId)) throw fail(`the native coin on ${chain.name} is not a catalog asset here; swap its ERC-20 instead`, "unsupported_pair");
|
|
71
|
+
if (same(expected.tokenIn, expected.tokenOut)) throw fail("same token in and out", "unsupported_pair");
|
|
72
|
+
if (expected.amountIn <= 0n || expected.minAmountOut <= 0n) throw fail("invalid quote amounts", "price_check_failed");
|
|
73
|
+
if (typeof tx.data !== "string" || !/^0x(?:[0-9a-fA-F]{2}){4,}$/.test(tx.data)) throw fail("malformed calldata", "policy_refused");
|
|
74
|
+
if (tx.data.length > 2 + 2 * MAX_CALLDATA_BYTES) throw fail("calldata is larger than any routed swap", "policy_refused");
|
|
75
|
+
const selector = tx.data.slice(0, 10).toLowerCase();
|
|
76
|
+
const refused = Object.prototype.hasOwnProperty.call(KYBER_REFUSED_SELECTORS, selector) ? KYBER_REFUSED_SELECTORS[selector] : void 0;
|
|
77
|
+
if (refused) throw fail(`the transaction calls ${refused}, which this module never uses`, "policy_refused");
|
|
78
|
+
if (selector !== KYBER_SWAP_SELECTOR) throw fail("not a router swap() call", "policy_refused");
|
|
79
|
+
let x;
|
|
80
|
+
try {
|
|
81
|
+
const call = decodeFunctionData({ abi: KYBER_ROUTER_ABI, data: tx.data });
|
|
82
|
+
x = call.args[0];
|
|
83
|
+
const again = encodeFunctionData({ abi: KYBER_ROUTER_ABI, functionName: "swap", args: [x] });
|
|
84
|
+
if (again.toLowerCase() !== tx.data.toLowerCase()) throw new Error("non-canonical");
|
|
85
|
+
} catch {
|
|
86
|
+
throw fail("the calldata is not a canonical router swap() encoding", "policy_refused");
|
|
87
|
+
}
|
|
88
|
+
const d = x.desc;
|
|
89
|
+
if (!same(x.callTarget, KYBER_EXECUTOR)) throw fail(`the swap runs through ${named(x.callTarget)}, not the pinned KyberSwap executor`, "vault_mismatch");
|
|
90
|
+
if (!same(x.approveTarget, ZERO)) throw fail("the swap asks the router to approve another contract", "policy_refused");
|
|
91
|
+
if (!same(d.srcToken, routerToken(expected.tokenIn)) || !same(d.dstToken, routerToken(expected.tokenOut))) throw fail("calldata swaps other tokens than requested", "policy_refused");
|
|
92
|
+
if (d.amount !== expected.amountIn) throw fail(`calldata spends ${d.amount}, not ${expected.amountIn}`, "price_check_failed");
|
|
93
|
+
if (d.srcReceivers.length !== d.srcAmounts.length) throw fail("malformed input split", "policy_refused");
|
|
94
|
+
if (nativeIn) {
|
|
95
|
+
if (d.srcReceivers.length !== 0) throw fail("a native-coin swap must not split the input", "policy_refused");
|
|
96
|
+
if (tx.value !== expected.amountIn) throw fail("native value does not match the input", "price_check_failed");
|
|
97
|
+
} else {
|
|
98
|
+
if (tx.value !== 0n) throw fail("a token swap must not send the native coin", "price_check_failed");
|
|
99
|
+
const total = d.srcAmounts.reduce((s, a) => s + a, 0n);
|
|
100
|
+
if (total !== expected.amountIn) throw fail(`the input split adds up to ${total}, not ${expected.amountIn}`, "price_check_failed");
|
|
101
|
+
}
|
|
102
|
+
if (same(d.dstReceiver, ZERO)) throw fail("the swap names no receiver", "recipient_mismatch");
|
|
103
|
+
if (!same(d.dstReceiver, expected.receiver)) throw fail(`calldata pays ${named(d.dstReceiver)}, not ${expected.receiver}`, "recipient_mismatch");
|
|
104
|
+
if (d.minReturnAmount <= 0n) throw fail("the swap names no minimum", "price_check_failed");
|
|
105
|
+
if (d.minReturnAmount < expected.minAmountOut) throw fail(`calldata guarantees ${d.minReturnAmount}, under the quoted minimum ${expected.minAmountOut}`, "price_check_failed");
|
|
106
|
+
if (d.feeReceivers.length !== 0 || d.feeAmounts.length !== 0) throw fail("calldata pays a fee receiver \u2014 this module charges none", "policy_refused");
|
|
107
|
+
if ((d.flags & ~KYBER_FLAGS_ALLOWED) !== 0n) throw fail(`calldata sets router flags ${d.flags.toString(16).slice(0, 16)} (only 0x200 is accepted)`, "policy_refused");
|
|
108
|
+
if (d.permit !== "0x") throw fail("calldata carries a permit", "policy_refused");
|
|
109
|
+
return { srcToken: d.srcToken, dstToken: d.dstToken, dstReceiver: d.dstReceiver, amount: d.amount, minReturnAmount: d.minReturnAmount, flags: d.flags };
|
|
110
|
+
}
|
|
111
|
+
function kyberMinimum(amountOut, bps) {
|
|
112
|
+
const m = amountOut * BigInt(1e4 - bps) / 10000n - 1n;
|
|
113
|
+
return m > 0n ? m : 0n;
|
|
114
|
+
}
|
|
115
|
+
function kyberApiSlippage(amountOut, bps) {
|
|
116
|
+
const floor = amountOut * BigInt(1e4 - bps) / 10000n;
|
|
117
|
+
for (let b = bps - 1; b >= 1; b--) if (kyberMinimum(amountOut, b) >= floor && kyberMinimum(amountOut, b) > 0n) return b;
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
var chainIdOf = (caip2) => /^eip155:[0-9]+$/.test(caip2) ? Number(caip2.slice(7)) : NaN;
|
|
121
|
+
function kyberVerifyQuote(params, quote) {
|
|
122
|
+
if (params.sourceChain !== params.destChain) return notes.note("same-chain swaps only", "unsupported_pair");
|
|
123
|
+
try {
|
|
124
|
+
const chainId = chainIdOf(params.sourceChain);
|
|
125
|
+
if (!kyberChain(chainId)) return notes.note(`no pinned KyberSwap router on ${params.sourceChain}`, "unsupported_pair");
|
|
126
|
+
const src = sourceAssetOf(params);
|
|
127
|
+
if (!src) return notes.note(`unknown source token ${params.sourceToken}`, "unsupported_pair");
|
|
128
|
+
if (quote.sourceAmount !== params.amountIn) return notes.note("the quote prices another amount", "price_check_failed");
|
|
129
|
+
const min = BigInt(quote.minDestAmount), out = BigInt(quote.destAmount);
|
|
130
|
+
if (min <= 0n || min > out) return notes.note("invalid quote amounts", "price_check_failed");
|
|
131
|
+
if (params.minAmountOut !== void 0 && min < BigInt(params.minAmountOut)) return notes.note("the quote's minimum is under the floor", "price_check_failed");
|
|
132
|
+
const bps = params.slippageBps;
|
|
133
|
+
if (bps !== void 0 && Number.isInteger(bps) && bps >= 0 && bps < 1e4 && min < kyberMinimum(out, bps)) {
|
|
134
|
+
return notes.note("the quote's minimum allows more slippage than requested", "price_check_failed");
|
|
135
|
+
}
|
|
136
|
+
const tx = quote.txRequest;
|
|
137
|
+
if (!tx) return params.dry === false ? notes.note("the quote carries no router transaction", "policy_refused") : null;
|
|
138
|
+
if (!tx.to || !tx.data) return notes.note("the quote carries no router transaction", "policy_refused");
|
|
139
|
+
if (tx.approvalAddress !== void 0 && !same(tx.approvalAddress, KYBER_ROUTER_V2)) return notes.note("the quote asks to approve another spender", "vault_mismatch");
|
|
140
|
+
checkKyberTransaction({ to: tx.to, data: tx.data, value: BigInt(tx.value ?? "0") }, {
|
|
141
|
+
chainId,
|
|
142
|
+
tokenIn: src.contract ? getAddress(src.contract) : ZERO,
|
|
143
|
+
tokenOut: /^0x0+$/.test(params.destToken) ? ZERO : getAddress(params.destToken),
|
|
144
|
+
amountIn: BigInt(params.amountIn),
|
|
145
|
+
receiver: getAddress(params.destAddress),
|
|
146
|
+
minAmountOut: min
|
|
147
|
+
});
|
|
148
|
+
return null;
|
|
149
|
+
} catch (e) {
|
|
150
|
+
const text = e instanceof Error ? e.message.replace(/^kyberswap: /, "") : String(e);
|
|
151
|
+
const info = refusalOf(e);
|
|
152
|
+
return info ? notes.note(text, info) : text;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function routerFor(chain) {
|
|
156
|
+
return kyberChain(chainIdOf(chain)) ? [KYBER_ROUTER_V2] : [];
|
|
157
|
+
}
|
|
158
|
+
var kyberPins = Object.freeze({
|
|
159
|
+
callTargets: routerFor,
|
|
160
|
+
spenders: routerFor,
|
|
161
|
+
verifyQuote: kyberVerifyQuote,
|
|
162
|
+
reasonOf: (refusal) => notes.reasonOf(refusal)
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
export {
|
|
166
|
+
KYBER_ROUTER_V2,
|
|
167
|
+
KYBER_EXECUTOR,
|
|
168
|
+
KYBER_ROUTER_V3,
|
|
169
|
+
KYBER_NATIVE,
|
|
170
|
+
KYBER_CHAINS,
|
|
171
|
+
kyberChain,
|
|
172
|
+
kyberNativeSwaps,
|
|
173
|
+
KYBER_ROUTER_ABI,
|
|
174
|
+
KYBER_SWAP_SELECTOR,
|
|
175
|
+
KYBER_REFUSED_SELECTORS,
|
|
176
|
+
KYBER_FLAGS_ALLOWED,
|
|
177
|
+
KyberTransactionError,
|
|
178
|
+
checkKyberTransaction,
|
|
179
|
+
kyberMinimum,
|
|
180
|
+
kyberApiSlippage,
|
|
181
|
+
kyberVerifyQuote,
|
|
182
|
+
kyberPins
|
|
183
|
+
};
|
|
184
|
+
//# sourceMappingURL=chunk-WOVGN3FL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router.ts"],"sourcesContent":["/**\n * KyberSwap MetaAggregationRouterV2 — the only contract a KyberSwap quote may settle through. This file pins the\n * router and its executor per chain and checks the transaction KyberSwap's build endpoint encoded against the request\n * before anything is approved or sent.\n *\n * The router itself guarantees only that the input comes from the caller and that `dstReceiver` gains at least\n * `minReturnAmount` of `dstToken`; the receiver, the tokens, the minimum, the fee receivers and the flags are all\n * the calldata's (KyberSwap's build endpoint encodes whatever `routeSummary` it is sent, fee entries included).\n * So the calldata is decoded strictly, re-encoded byte for byte, and every field that can move value is compared\n * with the request. The route inside `targetData` is opaque; the router reverts below the minimum.\n */\nimport type {Quote, QuoteParams, RemotePins} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {sourceAssetOf} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {refusalNotes, refusalOf, withReason, type Swap2RefusalReason} from \"@anywalletkit/protocol-swap2-core/errors\";\nimport {ccAssetByToken} from \"@anywalletkit/swap2-assets\";\nimport {decodeFunctionData, encodeFunctionData, getAddress, parseAbi, type Hex} from \"viem\";\n\n/** MetaAggregationRouterV2 — the same address on every chain KyberSwap serves (docs.kyberswap.com, contracts). */\nexport const KYBER_ROUTER_V2 = \"0x6131B5fae19EA4f9D964eAc0408E4408b66337b5\";\n/** AggregationExecutorProxy — the `callTarget` of every swap the build endpoint encodes. */\nexport const KYBER_EXECUTOR = \"0x8F10B468b06c6FD214B65F87778827F7D113f996\";\n/** KSAggregationRouterV3: deployed on part of the chains, never returned by the API so far. Refused until decoded. */\nexport const KYBER_ROUTER_V3 = \"0x6868d319c8c9a78f7d39dc3602c5c917315132d7\";\n/** The router's native-coin sentinel; this SDK uses the zero address. */\nexport const KYBER_NATIVE = \"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE\";\nconst ZERO = \"0x0000000000000000000000000000000000000000\";\n\n/**\n * Router build on a chain. `generic`: the 2022 build (18.6 KB) with `swapGeneric` and an owner-managed whitelist — its\n * owner can make the router call any whitelisted contract, so an allowance left on it is exposed to that owner.\n * `lite`: the later build (13.7 KB) without `swapGeneric` and without the whitelist. Both share `swap()`.\n * Read on-chain 2026-11-24 (`eth_getCode`, selectors in the bytecode, `owner()`; how-to-project/kyber-data).\n */\nexport type KyberRouterBuild = \"generic\" | \"lite\";\n\n/**\n * Every chain this module quotes on: KyberSwap's `supported-chains` list (active, plus Arc \"new\" and Elysium\n * \"provisional\") intersected with the SDK's EVM catalog, each with the router and executor code checked on-chain.\n * `slug` is the API's path segment (a chain id there is a 404).\n */\nexport const KYBER_CHAINS: Readonly<Record<number, {slug: string; name: string; build: KyberRouterBuild}>> = Object.freeze({\n 1: {slug: \"ethereum\", name: \"Ethereum\", build: \"generic\"},\n 8453: {slug: \"base\", name: \"Base\", build: \"generic\"},\n 56: {slug: \"bsc\", name: \"BNB Smart Chain\", build: \"generic\"},\n 42161: {slug: \"arbitrum\", name: \"Arbitrum\", build: \"generic\"},\n 10: {slug: \"optimism\", name: \"Optimism\", build: \"generic\"},\n 137: {slug: \"polygon\", name: \"Polygon\", build: \"generic\"},\n 43114: {slug: \"avalanche\", name: \"Avalanche\", build: \"generic\"},\n 59144: {slug: \"linea\", name: \"Linea\", build: \"generic\"},\n 146: {slug: \"sonic\", name: \"Sonic\", build: \"lite\"},\n 80094: {slug: \"berachain\", name: \"Berachain\", build: \"lite\"},\n 130: {slug: \"unichain\", name: \"Unichain\", build: \"lite\"},\n 999: {slug: \"hyperevm\", name: \"HyperEVM\", build: \"lite\"},\n 9745: {slug: \"plasma\", name: \"Plasma\", build: \"lite\"},\n 143: {slug: \"monad\", name: \"Monad\", build: \"lite\"},\n 4326: {slug: \"megaeth\", name: \"MegaETH\", build: \"lite\"},\n 4663: {slug: \"robinhood\", name: \"Robinhood Chain\", build: \"lite\"},\n 5042: {slug: \"arc\", name: \"Arc\", build: \"lite\"},\n 99901: {slug: \"elysium\", name: \"Elysium\", build: \"lite\"},\n});\n\n/** The chain entry for an id, never an inherited property. */\nexport function kyberChain(chainId: number): (typeof KYBER_CHAINS)[number] | undefined {\n return Object.prototype.hasOwnProperty.call(KYBER_CHAINS, chainId) ? KYBER_CHAINS[chainId] : undefined;\n}\n\n/**\n * Whether a swap may take or pay the chain's native coin: only where the token catalog lists one. Arc's gas token is\n * USDC with 18-decimal native accounting, listed only through its 6-decimal ERC-20 interface, so a native leg there\n * would carry amounts 10^12 off the catalog's USDC; it is refused and the ERC-20 swaps instead.\n */\nexport function kyberNativeSwaps(chainId: number): boolean {\n return !!ccAssetByToken(`eip155:${chainId}`, ZERO);\n}\n\n/** `swap(SwapExecutionParams)` — the one router entry point this module accepts. */\nexport const KYBER_ROUTER_ABI = parseAbi([\n \"struct SwapDescriptionV2 { address srcToken; address dstToken; address[] srcReceivers; uint256[] srcAmounts; address[] feeReceivers; uint256[] feeAmounts; address dstReceiver; uint256 amount; uint256 minReturnAmount; uint256 flags; bytes permit; }\",\n \"struct SwapExecutionParams { address callTarget; address approveTarget; bytes targetData; SwapDescriptionV2 desc; bytes clientData; }\",\n \"function swap(SwapExecutionParams execution) payable returns (uint256 returnAmount, uint256 gasUsed)\",\n]);\nexport const KYBER_SWAP_SELECTOR = \"0xe21fd0e9\";\n/** Router entry points that are refused by name: `swapGeneric` (owner-whitelisted arbitrary call) and `swapSimpleMode` (no minimum check). */\nexport const KYBER_REFUSED_SELECTORS: Readonly<Record<string, string>> = Object.freeze({\n \"0x59e50fed\": \"swapGeneric\",\n \"0x8af033fb\": \"swapSimpleMode\",\n});\n/**\n * The only flag bit accepted: `0x200`, set on every swap the build endpoint encodes (not one of the V2 source's named\n * flags; its meaning is not documented). Partial fill (0x01), extra value (0x02), claim (0x04), burns (0x08/0x10),\n * simple mode (0x20), fee on output (0x40), fee in bps (0x80) and approve-fund (0x100) are refused, as is any other bit.\n */\nexport const KYBER_FLAGS_ALLOWED = 0x200n;\n\nexport class KyberTransactionError extends Error {\n constructor(message: string) {\n super(`kyberswap: ${message}`);\n this.name = \"KyberTransactionError\";\n }\n}\nconst fail = (message: string, reason: Swap2RefusalReason): KyberTransactionError => withReason(new KyberTransactionError(message), reason);\nconst notes = refusalNotes();\n\nexport interface ExpectedKyberSwap {\n chainId: number;\n /** ERC-20 address, or the zero address for the native coin. */\n tokenIn: string;\n tokenOut: string;\n amountIn: bigint;\n /** Who must receive the output (the request's recipient). */\n receiver: string;\n /** The least `minReturnAmount` the calldata may name: the quote's minimum (and the caller's floor). */\n minAmountOut: bigint;\n}\n\nexport interface EncodedTx {\n to: string;\n value: bigint;\n data: string;\n}\n\nexport interface DecodedKyberSwap {\n srcToken: string;\n dstToken: string;\n dstReceiver: string;\n amount: bigint;\n minReturnAmount: bigint;\n flags: bigint;\n}\n\nconst isAddr = (a: unknown): a is string => typeof a === \"string\" && /^0x[0-9a-fA-F]{40}$/.test(a);\nconst same = (a: string, b: string): boolean => isAddr(a) && isAddr(b) && a.toLowerCase() === b.toLowerCase();\nconst routerToken = (t: string): string => (same(t, ZERO) ? KYBER_NATIVE : t);\n/** The calldata may be a megabyte from an untrusted source: names in refusals are addresses only. */\nconst named = (a: unknown): string => (isAddr(a) ? a : \"something that is not an address\");\n/** At most this much calldata is decoded (a routed swap is a few KB). */\nconst MAX_CALLDATA_BYTES = 64 * 1024;\n\n/** Refuses (throws {@link KyberTransactionError}) unless `tx` is exactly the swap the wallet asked for. */\nexport function checkKyberTransaction(tx: EncodedTx, expected: ExpectedKyberSwap): DecodedKyberSwap {\n const chain = kyberChain(expected.chainId);\n if (!chain) throw fail(`chain ${expected.chainId} has no pinned KyberSwap router`, \"unsupported_pair\");\n if (same(tx.to, KYBER_ROUTER_V3)) throw fail(\"Kyber router V3 not supported yet\", \"policy_refused\");\n if (!same(tx.to, KYBER_ROUTER_V2)) throw fail(`the transaction targets ${named(tx.to)}, not the KyberSwap router on ${chain.name}`, \"vault_mismatch\");\n if (!isAddr(expected.receiver) || same(expected.receiver, ZERO) || same(expected.receiver, KYBER_ROUTER_V2) || same(expected.receiver, KYBER_EXECUTOR)) {\n throw fail(\"invalid receiver\", \"recipient_mismatch\");\n }\n const nativeIn = same(expected.tokenIn, ZERO), nativeOut = same(expected.tokenOut, ZERO);\n if ((nativeIn || nativeOut) && !kyberNativeSwaps(expected.chainId)) throw fail(`the native coin on ${chain.name} is not a catalog asset here; swap its ERC-20 instead`, \"unsupported_pair\");\n if (same(expected.tokenIn, expected.tokenOut)) throw fail(\"same token in and out\", \"unsupported_pair\");\n if (expected.amountIn <= 0n || expected.minAmountOut <= 0n) throw fail(\"invalid quote amounts\", \"price_check_failed\");\n if (typeof tx.data !== \"string\" || !/^0x(?:[0-9a-fA-F]{2}){4,}$/.test(tx.data)) throw fail(\"malformed calldata\", \"policy_refused\");\n if (tx.data.length > 2 + 2 * MAX_CALLDATA_BYTES) throw fail(\"calldata is larger than any routed swap\", \"policy_refused\");\n const selector = tx.data.slice(0, 10).toLowerCase();\n const refused = Object.prototype.hasOwnProperty.call(KYBER_REFUSED_SELECTORS, selector) ? KYBER_REFUSED_SELECTORS[selector] : undefined;\n if (refused) throw fail(`the transaction calls ${refused}, which this module never uses`, \"policy_refused\");\n if (selector !== KYBER_SWAP_SELECTOR) throw fail(\"not a router swap() call\", \"policy_refused\");\n\n let x: {callTarget: string; approveTarget: string; targetData: Hex; desc: {srcToken: string; dstToken: string; srcReceivers: readonly string[]; srcAmounts: readonly bigint[]; feeReceivers: readonly string[]; feeAmounts: readonly bigint[]; dstReceiver: string; amount: bigint; minReturnAmount: bigint; flags: bigint; permit: Hex}; clientData: Hex};\n try {\n const call = decodeFunctionData({abi: KYBER_ROUTER_ABI, data: tx.data as Hex});\n x = call.args[0] as typeof x;\n // Strict: the calldata must be exactly the canonical encoding of what was decoded (no trailing bytes, no odd offsets or padding).\n const again = encodeFunctionData({abi: KYBER_ROUTER_ABI, functionName: \"swap\", args: [x as never]});\n if (again.toLowerCase() !== tx.data.toLowerCase()) throw new Error(\"non-canonical\");\n } catch {\n throw fail(\"the calldata is not a canonical router swap() encoding\", \"policy_refused\");\n }\n const d = x.desc;\n if (!same(x.callTarget, KYBER_EXECUTOR)) throw fail(`the swap runs through ${named(x.callTarget)}, not the pinned KyberSwap executor`, \"vault_mismatch\");\n if (!same(x.approveTarget, ZERO)) throw fail(\"the swap asks the router to approve another contract\", \"policy_refused\");\n if (!same(d.srcToken, routerToken(expected.tokenIn)) || !same(d.dstToken, routerToken(expected.tokenOut))) throw fail(\"calldata swaps other tokens than requested\", \"policy_refused\");\n if (d.amount !== expected.amountIn) throw fail(`calldata spends ${d.amount}, not ${expected.amountIn}`, \"price_check_failed\");\n if (d.srcReceivers.length !== d.srcAmounts.length) throw fail(\"malformed input split\", \"policy_refused\");\n if (nativeIn) {\n if (d.srcReceivers.length !== 0) throw fail(\"a native-coin swap must not split the input\", \"policy_refused\");\n if (tx.value !== expected.amountIn) throw fail(\"native value does not match the input\", \"price_check_failed\");\n } else {\n if (tx.value !== 0n) throw fail(\"a token swap must not send the native coin\", \"price_check_failed\");\n const total = d.srcAmounts.reduce((s, a) => s + a, 0n);\n if (total !== expected.amountIn) throw fail(`the input split adds up to ${total}, not ${expected.amountIn}`, \"price_check_failed\");\n }\n if (same(d.dstReceiver, ZERO)) throw fail(\"the swap names no receiver\", \"recipient_mismatch\");\n if (!same(d.dstReceiver, expected.receiver)) throw fail(`calldata pays ${named(d.dstReceiver)}, not ${expected.receiver}`, \"recipient_mismatch\");\n if (d.minReturnAmount <= 0n) throw fail(\"the swap names no minimum\", \"price_check_failed\");\n if (d.minReturnAmount < expected.minAmountOut) throw fail(`calldata guarantees ${d.minReturnAmount}, under the quoted minimum ${expected.minAmountOut}`, \"price_check_failed\");\n if (d.feeReceivers.length !== 0 || d.feeAmounts.length !== 0) throw fail(\"calldata pays a fee receiver — this module charges none\", \"policy_refused\");\n if ((d.flags & ~KYBER_FLAGS_ALLOWED) !== 0n) throw fail(`calldata sets router flags ${d.flags.toString(16).slice(0, 16)} (only 0x200 is accepted)`, \"policy_refused\");\n if (d.permit !== \"0x\") throw fail(\"calldata carries a permit\", \"policy_refused\");\n return {srcToken: d.srcToken, dstToken: d.dstToken, dstReceiver: d.dstReceiver, amount: d.amount, minReturnAmount: d.minReturnAmount, flags: d.flags};\n}\n\n/**\n * The minimum KyberSwap's build encodes for `amountOut` at `bps` slippage: the expected output less the slippage,\n * rounded down, less one more unit — the build endpoint always lands exactly one base unit under the plain\n * `floor(amountOut × (10000 − bps) / 10000)` (18 chains, 2026-11-24). The quote shows this value, so the dry quote,\n * the build and the check agree to the unit.\n */\nexport function kyberMinimum(amountOut: bigint, bps: number): bigint {\n const m = (amountOut * BigInt(10_000 - bps)) / 10_000n - 1n;\n return m > 0n ? m : 0n;\n}\n\n/**\n * The slippage to ask KyberSwap for so that its minimum — one unit under the plain floor ({@link kyberMinimum}) — still\n * meets the engine's floor for the slippage the user chose, `floor(amountOut × (10000 − bps) / 10000)`. One basis point\n * less for most outputs; more for a tiny output (a $1 WBTC buy is a few thousand units, where 1 bps is under one unit).\n * Null when no positive slippage does (an output too small to carry a minimum).\n */\nexport function kyberApiSlippage(amountOut: bigint, bps: number): number | null {\n const floor = (amountOut * BigInt(10_000 - bps)) / 10_000n;\n for (let b = bps - 1; b >= 1; b--) if (kyberMinimum(amountOut, b) >= floor && kyberMinimum(amountOut, b) > 0n) return b;\n return null;\n}\n\nconst chainIdOf = (caip2: string): number => (/^eip155:[0-9]+$/.test(caip2) ? Number(caip2.slice(7)) : NaN);\n\n/**\n * The app's own check of a KyberSwap quote (behind `remoteProvider`, or on any quote): one chain, the exact input,\n * a minimum at or under the expected output and at or above the caller's floor; an execution quote's transaction must\n * pass {@link checkKyberTransaction} against this app's request. A dry quote carries no transaction. The reason it fails, or null.\n */\nexport function kyberVerifyQuote(params: QuoteParams, quote: Quote): string | null {\n if (params.sourceChain !== params.destChain) return notes.note(\"same-chain swaps only\", \"unsupported_pair\");\n try {\n const chainId = chainIdOf(params.sourceChain);\n if (!kyberChain(chainId)) return notes.note(`no pinned KyberSwap router on ${params.sourceChain}`, \"unsupported_pair\");\n const src = sourceAssetOf(params);\n if (!src) return notes.note(`unknown source token ${params.sourceToken}`, \"unsupported_pair\");\n if (quote.sourceAmount !== params.amountIn) return notes.note(\"the quote prices another amount\", \"price_check_failed\");\n const min = BigInt(quote.minDestAmount), out = BigInt(quote.destAmount);\n if (min <= 0n || min > out) return notes.note(\"invalid quote amounts\", \"price_check_failed\");\n if (params.minAmountOut !== undefined && min < BigInt(params.minAmountOut)) return notes.note(\"the quote's minimum is under the floor\", \"price_check_failed\");\n // The minimum is the expected output less the requested slippage, never more slippage than asked for.\n const bps = params.slippageBps;\n if (bps !== undefined && Number.isInteger(bps) && bps >= 0 && bps < 10_000 && min < kyberMinimum(out, bps)) {\n return notes.note(\"the quote's minimum allows more slippage than requested\", \"price_check_failed\");\n }\n const tx = quote.txRequest;\n if (!tx) return params.dry === false ? notes.note(\"the quote carries no router transaction\", \"policy_refused\") : null;\n if (!tx.to || !tx.data) return notes.note(\"the quote carries no router transaction\", \"policy_refused\");\n if (tx.approvalAddress !== undefined && !same(tx.approvalAddress, KYBER_ROUTER_V2)) return notes.note(\"the quote asks to approve another spender\", \"vault_mismatch\");\n checkKyberTransaction({to: tx.to, data: tx.data, value: BigInt(tx.value ?? \"0\")}, {\n chainId,\n tokenIn: src.contract ? getAddress(src.contract) : ZERO,\n tokenOut: /^0x0+$/.test(params.destToken) ? ZERO : getAddress(params.destToken),\n amountIn: BigInt(params.amountIn),\n receiver: getAddress(params.destAddress),\n minAmountOut: min,\n });\n return null;\n } catch (e) {\n const text = e instanceof Error ? e.message.replace(/^kyberswap: /, \"\") : String(e);\n const info = refusalOf(e);\n return info ? notes.note(text, info) : text;\n }\n}\n\nfunction routerFor(chain: string): readonly string[] {\n return kyberChain(chainIdOf(chain)) ? [KYBER_ROUTER_V2] : [];\n}\n\n/**\n * The router a KyberSwap swap calls and approves, and {@link kyberVerifyQuote}: the app's side of\n * `remoteProvider({name: \"kyberswap\", baseUrl, ...kyberPins})`, so a backend's quote is checked against the pinned\n * router and the app's own request, never against itself.\n */\nexport const kyberPins: RemotePins = Object.freeze({\n callTargets: routerFor,\n spenders: routerFor,\n verifyQuote: kyberVerifyQuote,\n reasonOf: (refusal: string) => notes.reasonOf(refusal),\n});\n"],"mappings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