@anywalletkit/protocol-swap2-kyberswap 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -3
- package/dist/activity.cjs +25 -0
- package/dist/activity.cjs.map +1 -1
- package/dist/activity.js +2 -2
- package/dist/{chunk-WOVGN3FL.js → chunk-D4UIDHM2.js} +37 -1
- package/dist/chunk-D4UIDHM2.js.map +1 -0
- package/dist/{chunk-FWC6K553.js → chunk-HHZEL5IJ.js} +2 -2
- package/dist/{chunk-PIC4PYGN.js → chunk-LIEIWIYI.js} +3 -3
- package/dist/{chunk-DEWODPQQ.js → chunk-NFMHUXU6.js} +59 -12
- package/dist/chunk-NFMHUXU6.js.map +1 -0
- package/dist/index.cjs +87 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +18 -4
- package/dist/protocol.cjs +80 -8
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.js +4 -4
- package/dist/provider.cjs +83 -8
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +32 -2
- package/dist/provider.d.ts +32 -2
- package/dist/provider.js +9 -3
- package/dist/router.cjs +36 -0
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts +27 -1
- package/dist/router.d.ts +27 -1
- package/dist/router.js +9 -1
- package/package.json +3 -3
- package/dist/chunk-DEWODPQQ.js.map +0 -1
- package/dist/chunk-WOVGN3FL.js.map +0 -1
- /package/dist/{chunk-FWC6K553.js.map → chunk-HHZEL5IJ.js.map} +0 -0
- /package/dist/{chunk-PIC4PYGN.js.map → chunk-LIEIWIYI.js.map} +0 -0
package/README.md
CHANGED
|
@@ -33,7 +33,9 @@ returns is checked on the device against the pinned router and the app's own req
|
|
|
33
33
|
| `clientId` | `anywalletkit` | `x-client-id` (keyless only) and the build's `source` |
|
|
34
34
|
| `defaultSlippageBps` | 50 | KyberSwap accepts under 2000 |
|
|
35
35
|
| `quoteTtlMs` | 30 000 | how long a quote stays executable (the review fits; an approval mined meanwhile gets one re-quote) |
|
|
36
|
-
| `
|
|
36
|
+
| `rfq` | `"exclude"` | RFQ market makers (`pmm-N`, Bebop, Native, Hashflow, …); see [RFQ and limit orders](#rfq-and-limit-orders) |
|
|
37
|
+
| `limitOrders` | `"exclude"` | KyberSwap's own limit orders (`kyberswap-limit-order-v2`); see [RFQ and limit orders](#rfq-and-limit-orders) |
|
|
38
|
+
| `excludeRfqSources` | `true` | deprecated: `false` = both of the above `"include"`; each of them, when set, wins for its own sources |
|
|
37
39
|
| `excludedSources` | — | KyberSwap source ids |
|
|
38
40
|
|
|
39
41
|
## How a swap is checked
|
|
@@ -68,14 +70,162 @@ returns is checked on the device against the pinned router and the app's own req
|
|
|
68
70
|
gets the "be careful" warning even when the app has no price for the token (2026-11-25 Unichain USDC → JUP: 7 824 bps).
|
|
69
71
|
Information only, never a refusal; a token KyberSwap does not price carries none.
|
|
70
72
|
|
|
73
|
+
## RFQ and limit orders
|
|
74
|
+
|
|
75
|
+
Two kinds of KyberSwap liquidity are not pools: **RFQ market makers** (the sources KyberSwap tags "RFQ sources":
|
|
76
|
+
`pmm-N`, Bebop, Native, Hashflow, Swaap, …), whose firm quote is signed when the route is built, and KyberSwap's own
|
|
77
|
+
**limit orders** (`kyberswap-limit-order-v2`), makers' signed orders kept off-chain and co-signed by KyberSwap when the
|
|
78
|
+
route is built. Both are left out by default. KyberSwap's `excludeRFQSources=true` (0.2.0, and the default here)
|
|
79
|
+
leaves out both together; checked 2026-11-30 on Ethereum DRV → USDC: with it, no limit-order hop; with the RFQ sources
|
|
80
|
+
excluded by name instead, the limit order stays in the route.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
kyberswapProvider({rpcUrls, limitOrders: 'include'}) // limit orders, no RFQ (recommended, below)
|
|
84
|
+
kyberswapProvider({rpcUrls, rfq: 'include', limitOrders: 'include'}) // everything KyberSwap offers this client
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
| `rfq` | `limitOrders` | `GET /routes` asks |
|
|
88
|
+
|---|---|---|
|
|
89
|
+
| exclude | exclude | `excludeRFQSources=true` — the 0.2.0 request, byte for byte |
|
|
90
|
+
| exclude | include | `excludedSources=` the chain's RFQ sources (`KYBER_RFQ_SOURCES`, read from KyberSwap's source list 2026-11-30) |
|
|
91
|
+
| include | exclude | `excludedSources=kyberswap-limit-order-v2` |
|
|
92
|
+
| include | include | no source filter |
|
|
93
|
+
|
|
94
|
+
The app's own `excludedSources` are added to the list. The execution quote asks `/routes` with the same filters as
|
|
95
|
+
the dry one, so the route reviewed and the route built draw on the same liquidity.
|
|
96
|
+
|
|
97
|
+
What changes for a route that uses either kind (`kyberSourceKind` reads each hop's `poolType` — "orderbook" for an
|
|
98
|
+
RFQ maker, "limit-order" — or its source id; a new `pmm-N` KyberSwap adds after the list was read is still
|
|
99
|
+
recognised):
|
|
100
|
+
|
|
101
|
+
- `providerData.offchain` is `"rfq"`, `"limit-order"` or `"rfq,limit-order"`.
|
|
102
|
+
- `validUntilMs` is at most `KYBER_RFQ_TTL_MS` (10 s) with an RFQ hop, `KYBER_LIMIT_ORDER_TTL_MS` (30 s) with a limit
|
|
103
|
+
order, and never more than `quoteTtlMs`. The API states no expiry for either; the figures are the measurement below.
|
|
104
|
+
An approval mined after the quote ran out gets the engine's one re-quote, on the same allowance (no new approval).
|
|
105
|
+
- The execution quote's `destAmount` is the build's `amountOut` when that is lower than the route's (the maker signs,
|
|
106
|
+
or KyberSwap falls back to the pool it names after the maker — `pmm-19/uniswapv3` — only at build); a build under
|
|
107
|
+
the quote's minimum is refused (`price_check_failed`).
|
|
108
|
+
- Nothing else is relaxed: the same `swap()`, router, executor, flags, input split, receiver and minimum checks
|
|
109
|
+
(every RFQ and limit-order build measured passed `checkKyberTransaction` unchanged), the same simulation before any
|
|
110
|
+
approval and again before signing, `exactAllowanceOnly` on the generic-build routers.
|
|
111
|
+
- A swap whose maker quote or limit order no longer fills reverts in the pre-signing simulation and is refused as
|
|
112
|
+
`quote_expired` ("the limit order in this route no longer fills (expired or taken). Nothing was sent; refresh the
|
|
113
|
+
quote."); the router's minimum check stays `price_check_failed`. Recorded: `fixtures/offchain`.
|
|
114
|
+
|
|
115
|
+
What this client gets: keyless, and with an API key, a route of RFQ sources alone is refused (`40011 filtered
|
|
116
|
+
liquidity sources`) on Ethereum, Base, BNB Smart Chain and Arbitrum; RFQ makers show up only as hops inside mixed
|
|
117
|
+
routes, and not every minute (on 2026-11-30 they were in 8 of the 20 routes below at 11:38–11:44 UTC, and in none
|
|
118
|
+
of six of those pairs, asked every 9 s for two minutes, at 11:53).
|
|
119
|
+
|
|
120
|
+
### Measured (2026-11-30)
|
|
121
|
+
|
|
122
|
+
Price: 20 pairs on Ethereum, Base, Arbitrum and BNB Smart Chain, `GET /routes` in the four settings one after the
|
|
123
|
+
other (the first to the last 1–10 s apart, median 3 s: four pairs at a time shared the public API's 3 requests per
|
|
124
|
+
second), each against today's route (both excluded), in bps of `amountOut`. Differences of about 1 bps are those
|
|
125
|
+
seconds (proprietary AMMs reprice every block), not the setting.
|
|
126
|
+
|
|
127
|
+
| Chain | Swap | Size | Limit orders only | RFQ only | Both | Off-chain hops in "both" |
|
|
128
|
+
|---|---|---|---|---|---|---|
|
|
129
|
+
| Ethereum | ETH → USDC | $1,661 | +0.1 | +0.0 | +0.1 | — |
|
|
130
|
+
| Ethereum | ETH → USDC | $83,070 | −0.4 | −0.4 | +0.5 | — |
|
|
131
|
+
| Ethereum | USDC → ETH | $199,976 | −0.2 | −0.4 | −0.3 | — |
|
|
132
|
+
| Ethereum | USDT → USDC | $499,742 | +0.0 | +0.0 | +0.0 | — |
|
|
133
|
+
| Ethereum | WBTC → USDC | $178,882 | +0.0 | +0.0 | +0.0 | — |
|
|
134
|
+
| Ethereum | PEPE → ETH | $3,506 | +0.0 | +0.0 | +0.0 | — |
|
|
135
|
+
| Ethereum | DRV → USDC | $23,806 | **+15.1** | +0.0 | **+15.1** | limit order |
|
|
136
|
+
| Base | ETH → USDC | $49,819 | +0.8 | +0.6 | +0.6 | Bebop |
|
|
137
|
+
| Base | USDC → ETH | $995 | +0.7 | +0.5 | +0.5 | — |
|
|
138
|
+
| Base | USDC → cbBTC | $99,456 | +0.2 | +0.0 | +0.1 | — |
|
|
139
|
+
| Base | AERO → USDC | $19,012 | +0.1 | −0.3 | +0.1 | — |
|
|
140
|
+
| Base | USDC → VIRTUAL | $19,891 | +0.9 | −2.0 | **+7.3** | Bebop, pmm-8, pmm-19, pmm-21 |
|
|
141
|
+
| Arbitrum | ETH → USDC | $49,853 | +0.0 | +0.0 | −0.9 | Native |
|
|
142
|
+
| Arbitrum | USDC → WBTC | $99,997 | +0.7 | +0.0 | +0.0 | pmm-13 |
|
|
143
|
+
| Arbitrum | USDT0 → USDC | $199,757 | +0.0 | +0.0 | +0.0 | pmm-13 |
|
|
144
|
+
| Arbitrum | ARB → USDC | $10,898 | +0.0 | +0.0 | +0.2 | pmm-13 |
|
|
145
|
+
| BNB Smart Chain | BNB → USDT | $55,213 | +0.0 | +0.0 | −0.3 | — |
|
|
146
|
+
| BNB Smart Chain | USDT → BNB | $49,950 | −0.0 | +0.1 | +0.5 | — |
|
|
147
|
+
| BNB Smart Chain | CAKE → USDT | $30,781 | +0.1 | +0.0 | **+1.4** | pmm-19 |
|
|
148
|
+
| BNB Smart Chain | USDT → BTCB | $49,885 | −0.1 | −0.7 | −1.0 | pmm-13 |
|
|
149
|
+
|
|
150
|
+
The same DRV → USDC swap read +46 and +59 bps through a limit order earlier that day (reported first by cp0x: another
|
|
151
|
+
KyberSwap interface 0.17 % over this module on 64 000 DRV, its route through `kyberswap-limit-order-v2`); KNC → USDC
|
|
152
|
+
routes through a limit order too. Limit orders pay where makers post orders above the pools, mostly long-tail tokens; on
|
|
153
|
+
majors neither kind moved the price by more than the noise.
|
|
154
|
+
|
|
155
|
+
Execution: for every route with an off-chain hop (and today's route as a control), `POST /route/build` right after the
|
|
156
|
+
quote for a throwaway sender = recipient, and that one calldata run with `eth_simulateV1` (sender funded by a state
|
|
157
|
+
override, a token input approved exactly in the same simulated block; nothing sent) 0, 10, 30 and 60 s after the
|
|
158
|
+
quote; plus the quote's route built afresh 10, 30 and 60 s after it and run at once. Arbitrum USDC → WBTC is left out:
|
|
159
|
+
today's route reverted there too, so its reverts are not the RFQ maker's.
|
|
160
|
+
|
|
161
|
+
| Route | Calldata from the quote runs at 0 / 10 / 30 / 60 s | Built afresh at 10 / 30 / 60 s, runs |
|
|
162
|
+
|---|---|---|
|
|
163
|
+
| pools only (control) | 18/18 at 0 s, 18/18 at 60 s | — |
|
|
164
|
+
| with a limit order | 2/2, 2/2, 2/2, 2/2 | 1/1, 1/1, 1/1 |
|
|
165
|
+
| with an RFQ maker | 5/7, 5/7, **4/7**, 4/7 | 5/7, 5/7, 5/7 |
|
|
166
|
+
|
|
167
|
+
- Limit orders: one DRV → USDC calldata followed to 300 s ran up to 91 s, paying 0.17 % less at 61 s and 0.38 % less
|
|
168
|
+
at 91 s (parts of the orders gone, still above the minimum), and reverted ("Call failed") from 121 s — the recording
|
|
169
|
+
in `fixtures/offchain`.
|
|
170
|
+
- RFQ: two of the seven RFQ routes never ran (Base USDC → VIRTUAL through five makers; Arbitrum ARB → USDC through
|
|
171
|
+
`pmm-13`), not from the quote and not built afresh: the simulation right after the build refuses them before any
|
|
172
|
+
approval. One (BNB Smart Chain CAKE → USDT through `pmm-19`) ran at 11 s and reverted at 30 s: with an approval in
|
|
173
|
+
between, that swap fails after the user paid for the approval — hence the 10-second life, which sends such a swap
|
|
174
|
+
to a re-quote after the approval instead. One fresh build failed outright (`4222 quoted amount is smaller than
|
|
175
|
+
estimated`): a refusal, as for any route.
|
|
176
|
+
|
|
177
|
+
### Which setting
|
|
178
|
+
|
|
179
|
+
For an app with an approval between the quote and the signature (30–60 s): **`limitOrders: "include"`, `rfq:
|
|
180
|
+
"exclude"`.** Limit orders are where the price is (+15 to +59 bps on the long tail, nothing lost on majors), and their
|
|
181
|
+
fills lasted well past the 30 s quote life in every measurement. RFQ added at most 7 bps on 2 of 20 pairs, two of
|
|
182
|
+
seven RFQ routes did not execute at all, and one expired inside an approval's time; with RFQ included the 10-second
|
|
183
|
+
life also means a review longer than 10 s ends in "quote expired" before anything is signed.
|
|
184
|
+
|
|
185
|
+
RFQ for listing only (dry quotes with `rfq: "include"`, execution without) is not offered: the list would show a price
|
|
186
|
+
the execution quote, asking without RFQ, may not reach.
|
|
187
|
+
|
|
188
|
+
## Gas: `gasEstimate`
|
|
189
|
+
|
|
190
|
+
Every quote, dry or for execution, carries `gasEstimate` = KyberSwap's `routeSummary.gas` from `GET /routes` (asked
|
|
191
|
+
with `gasInclude=true`), `gasEstimateSource: "venue"`. It is there to compare routes (see protocol-swap2-core, "Gas:
|
|
192
|
+
`gasEstimate` vs `gasLimit`"): a dry quote has no transaction, so before this the router could only assume a gas limit
|
|
193
|
+
for it. Nothing in execution reads it: the swap still goes out with the account's own estimate of the exact call
|
|
194
|
+
(`ownGasEstimate`), and the transaction carries no gas limit. It counts the swap call only, no approval. A route that
|
|
195
|
+
states no gas (or 0) gives a quote without one.
|
|
196
|
+
|
|
197
|
+
What KyberSwap's figure is: its own model of the route's gas, not a simulation. The build answers the same number
|
|
198
|
+
(`gas` of `POST /route/build` equalled `routeSummary.gas` in all 16 recordings), and routine routes land on round model
|
|
199
|
+
values (330 498 for one Uniswap v3 or PancakeSwap v3 pool, 956 331 on two different chains). Against the gas the built
|
|
200
|
+
call used — 16 live routes recorded 2026-11-28 (`fixtures/quotes`) on Ethereum, Base, Arbitrum, Optimism, Polygon, BNB
|
|
201
|
+
Smart Chain, Linea, Sonic and Unichain for a throwaway sender = recipient, each built call run with `eth_simulateV1`
|
|
202
|
+
right after, at the chain's gas price (sender funded by a state override, a token input approved exactly in the same
|
|
203
|
+
simulated block; nothing sent):
|
|
204
|
+
|
|
205
|
+
| | Gas used ÷ `routeSummary.gas` |
|
|
206
|
+
|---|---|
|
|
207
|
+
| 16 routes | 0.58–1.85, median 0.73 |
|
|
208
|
+
| above the figure | 4 of 16: Linea Etherex CL 1.01, Polygon Ramses v3 + DODO 1.07, Sonic Metropolis LB 1.44, Base `kipseli-prop` 1.85 |
|
|
209
|
+
|
|
210
|
+
So it mostly runs high (the call used about three quarters of it at the median), and a proprietary-AMM route can run well over (how much gas such a pool
|
|
211
|
+
burns in a simulation need not be what it burns on-chain). The receiver held none of the output, so writing its first
|
|
212
|
+
balance is in these figures. On Arbitrum they are L2 execution gas without the L1 data component, which the router
|
|
213
|
+
leaves out too.
|
|
214
|
+
|
|
71
215
|
## Router owner
|
|
72
216
|
|
|
73
217
|
`KYBER_CHAINS[id].build` names the router build on each chain, read on-chain:
|
|
74
218
|
|
|
75
219
|
- `generic` (Ethereum, Base, BNB Smart Chain, Arbitrum, Optimism, Polygon, Avalanche, Linea): the router has
|
|
76
220
|
`swapGeneric` and an owner-managed whitelist, so its owner (a single key on all but Linea) could make it spend an
|
|
77
|
-
allowance left on it.
|
|
78
|
-
|
|
221
|
+
allowance left on it. None is left: the approval is exact and spent by the swap itself, and revoked if the swap
|
|
222
|
+
does not go out. The engine's two approval options (protocol-swap2-core, "Approvals") would change that —
|
|
223
|
+
`revokeUnspentApproval: false` leaves an unspent approval in place, `allowanceReuse: "sufficient"` swaps from a
|
|
224
|
+
larger allowance the account already gave the router, which then stays — so the provider declares
|
|
225
|
+
`exactAllowanceOnly` for these chains (`kyberExactAllowanceOnly`, also in `kyberPins` for a remote stub): the
|
|
226
|
+
engine holds KyberSwap routes here to the defaults whatever the app set, the allowance exact and revoked when
|
|
227
|
+
unspent. A chain this module does not list counts as `generic` (fail closed).
|
|
228
|
+
- `lite` (every other chain): no `swapGeneric`, no whitelist. The approval options apply there as on any provider.
|
|
79
229
|
|
|
80
230
|
## Limits
|
|
81
231
|
|
|
@@ -97,3 +247,7 @@ Base, 2026-11-24, one test wallet, through the engine (review → approval → p
|
|
|
97
247
|
The router's USDC allowance was 0 after the token swap. `scripts/verify-mainnet.mjs` repeats it (`--send native|token`).
|
|
98
248
|
|
|
99
249
|
`scripts/verify-live.mjs` checks the contracts on every chain and builds (unsigned) one corridor each way per chain.
|
|
250
|
+
|
|
251
|
+
## `blockNumber`
|
|
252
|
+
|
|
253
|
+
`QuoteParams.blockNumber` (one block for a comparison round) is not supported: the price comes from the KyberSwap Aggregator API, so the quote names no block (`Quote.blockNumber` absent).
|
package/dist/activity.cjs
CHANGED
|
@@ -57,6 +57,27 @@ var KYBER_CHAINS = Object.freeze({
|
|
|
57
57
|
5042: { slug: "arc", name: "Arc", build: "lite" },
|
|
58
58
|
99901: { slug: "elysium", name: "Elysium", build: "lite" }
|
|
59
59
|
});
|
|
60
|
+
var KYBER_LIMIT_ORDER_SOURCES = Object.freeze(["kyberswap-limit-order-v2"]);
|
|
61
|
+
var KYBER_RFQ_SOURCES = Object.freeze({
|
|
62
|
+
1: ["bebop", "clear-rfq", "hashflow-v3", "native-v1", "native-v2", "pmm-1", "pmm-10", "pmm-11", "pmm-12", "pmm-18", "pmm-2", "pmm-20", "pmm-3", "pmm-4", "pmm-5", "pmm-6", "pmm-7", "pmm-8", "swaap-v2"],
|
|
63
|
+
8453: ["bebop", "hashflow-v3", "native-v1", "native-v2", "pmm-1", "pmm-13", "pmm-14", "pmm-18", "pmm-19", "pmm-2", "pmm-20", "pmm-21", "pmm-4", "pmm-5", "pmm-8"],
|
|
64
|
+
56: ["bebop", "hashflow-v3", "native-v1", "native-v2", "pmm-1", "pmm-10", "pmm-13", "pmm-18", "pmm-19", "pmm-2", "pmm-20", "pmm-5", "pmm-8", "swaap-v2"],
|
|
65
|
+
42161: ["bebop", "hashflow-v3", "native-v1", "native-v2", "pmm-13", "pmm-2", "pmm-21", "pmm-5", "pmm-6", "pmm-7", "pmm-8", "swaap-v2"],
|
|
66
|
+
10: ["bebop", "pmm-13", "swaap-v2"],
|
|
67
|
+
137: ["bebop", "native-v1", "pmm-5", "pmm-8", "swaap-v2"],
|
|
68
|
+
43114: ["bebop", "dexalot", "hashflow-v3", "native-v1", "pmm-4", "swaap-v2"],
|
|
69
|
+
59144: ["native-v1", "swaap-v2"],
|
|
70
|
+
146: ["swaap-v2"],
|
|
71
|
+
80094: ["bebop"],
|
|
72
|
+
130: [],
|
|
73
|
+
999: ["bebop"],
|
|
74
|
+
9745: [],
|
|
75
|
+
143: ["native-v2", "swaap-v2"],
|
|
76
|
+
4326: [],
|
|
77
|
+
4663: ["bebop", "native-v2", "pmm-18", "pmm-19", "pmm-20", "swaap-v2"],
|
|
78
|
+
5042: ["pmm-13"],
|
|
79
|
+
99901: []
|
|
80
|
+
});
|
|
60
81
|
function kyberChain(chainId) {
|
|
61
82
|
return Object.prototype.hasOwnProperty.call(KYBER_CHAINS, chainId) ? KYBER_CHAINS[chainId] : void 0;
|
|
62
83
|
}
|
|
@@ -179,9 +200,13 @@ function kyberVerifyQuote(params, quote) {
|
|
|
179
200
|
function routerFor(chain) {
|
|
180
201
|
return kyberChain(chainIdOf(chain)) ? [KYBER_ROUTER_V2] : [];
|
|
181
202
|
}
|
|
203
|
+
function kyberExactAllowanceOnly(chain) {
|
|
204
|
+
return kyberChain(chainIdOf(chain))?.build !== "lite";
|
|
205
|
+
}
|
|
182
206
|
var kyberPins = Object.freeze({
|
|
183
207
|
callTargets: routerFor,
|
|
184
208
|
spenders: routerFor,
|
|
209
|
+
exactAllowanceOnly: kyberExactAllowanceOnly,
|
|
185
210
|
verifyQuote: kyberVerifyQuote,
|
|
186
211
|
reasonOf: (refusal) => notes.reasonOf(refusal)
|
|
187
212
|
});
|
package/dist/activity.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/activity.ts","../src/router.ts"],"sourcesContent":["/**\n * Activity recognition for KyberSwap: a `swap()` call to MetaAggregationRouterV2 on a chain the module serves →\n * `swap`, \"Swapped A → B\" from the owner's net transfers.\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {chainLabel, describeSwapLike, matchesCall} from \"@anywalletkit/protocol-swap2-core/activity\";\nimport {evmRef, isEvm} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {KYBER_ROUTER_V2, KYBER_SWAP_SELECTOR, kyberChain} from \"./router.js\";\n\nexport const KYBERSWAP_MODULE = \"@anywalletkit/protocol-swap2-kyberswap\";\n\nexport function describeKyberActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (!isEvm(tx.chain) || !kyberChain(evmRef(tx.chain))) return null;\n if (!matchesCall(tx, [KYBER_ROUTER_V2], [KYBER_SWAP_SELECTOR])) return null;\n return describeSwapLike(tx, ctx, {protocol: KYBERSWAP_MODULE, subtitle: `KyberSwap · ${chainLabel(tx.chain)}`, kind: \"swap\"});\n}\n","/**\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,sBAAwD;AACxD,IAAAA,eAA4B;;;ACM5B,kBAA4B;AAC5B,oBAA2E;AAC3E,0BAA6B;AAC7B,kBAAqF;AAG9E,IAAM,kBAAkB;AAExB,IAAM,iBAAiB;AAEvB,IAAM,kBAAkB;AAExB,IAAM,eAAe;AAC5B,IAAM,OAAO;AAeN,IAAM,eAAgG,OAAO,OAAO;AAAA,EACzH,GAAG,EAAC,MAAM,YAAY,MAAM,YAAY,OAAO,UAAS;AAAA,EACxD,MAAM,EAAC,MAAM,QAAQ,MAAM,QAAQ,OAAO,UAAS;AAAA,EACnD,IAAI,EAAC,MAAM,OAAO,MAAM,mBAAmB,OAAO,UAAS;AAAA,EAC3D,OAAO,EAAC,MAAM,YAAY,MAAM,YAAY,OAAO,UAAS;AAAA,EAC5D,IAAI,EAAC,MAAM,YAAY,MAAM,YAAY,OAAO,UAAS;AAAA,EACzD,KAAK,EAAC,MAAM,WAA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K,KAAK,CAAC,eAAW,qBAAO,GAAG,KAAK,CAAC,EAAG,QAAO;AAC9D,MAAI,KAAC,6BAAY,IAAI,CAAC,eAAe,GAAG,CAAC,mBAAmB,CAAC,EAAG,QAAO;AACvE,aAAO,kCAAiB,IAAI,KAAK,EAAC,UAAU,kBAAkB,UAAU,sBAAe,4BAAW,GAAG,KAAK,CAAC,IAAI,MAAM,OAAM,CAAC;AAC9H;","names":["import_util"]}
|
|
1
|
+
{"version":3,"sources":["../src/activity.ts","../src/router.ts"],"sourcesContent":["/**\n * Activity recognition for KyberSwap: a `swap()` call to MetaAggregationRouterV2 on a chain the module serves →\n * `swap`, \"Swapped A → B\" from the owner's net transfers.\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {chainLabel, describeSwapLike, matchesCall} from \"@anywalletkit/protocol-swap2-core/activity\";\nimport {evmRef, isEvm} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {KYBER_ROUTER_V2, KYBER_SWAP_SELECTOR, kyberChain} from \"./router.js\";\n\nexport const KYBERSWAP_MODULE = \"@anywalletkit/protocol-swap2-kyberswap\";\n\nexport function describeKyberActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (!isEvm(tx.chain) || !kyberChain(evmRef(tx.chain))) return null;\n if (!matchesCall(tx, [KYBER_ROUTER_V2], [KYBER_SWAP_SELECTOR])) return null;\n return describeSwapLike(tx, ctx, {protocol: KYBERSWAP_MODULE, subtitle: `KyberSwap · ${chainLabel(tx.chain)}`, kind: \"swap\"});\n}\n","/**\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/** KyberSwap's own limit orders: makers' signed orders kept off-chain, filled on-chain by the executor (the active source id). */\nexport const KYBER_LIMIT_ORDER_SOURCES: readonly string[] = Object.freeze([\"kyberswap-limit-order-v2\"]);\n\n/**\n * KyberSwap's RFQ sources per chain — private market makers whose firm quote is signed when the route is built: the\n * sources tagged \"RFQ sources\" in KyberSwap's own source list (`ks-setting.kyberswap.com/api/v1/dexes`, read\n * 2026-11-30). `excludeRFQSources=true` leaves out these and the limit orders together; this list is how the provider\n * asks for limit orders without RFQ (`limitOrders: \"include\"`, `rfq: \"exclude\"`). An empty list: the chain had no RFQ\n * source. A source KyberSwap adds later is still recognised in a route by `kyberSourceKind` (its `poolType`, or an\n * RFQ-like id), so the quote is marked and timed as RFQ; only the request would not leave it out.\n */\nexport const KYBER_RFQ_SOURCES: Readonly<Record<number, readonly string[]>> = Object.freeze({\n 1: [\"bebop\", \"clear-rfq\", \"hashflow-v3\", \"native-v1\", \"native-v2\", \"pmm-1\", \"pmm-10\", \"pmm-11\", \"pmm-12\", \"pmm-18\", \"pmm-2\", \"pmm-20\", \"pmm-3\", \"pmm-4\", \"pmm-5\", \"pmm-6\", \"pmm-7\", \"pmm-8\", \"swaap-v2\"],\n 8453: [\"bebop\", \"hashflow-v3\", \"native-v1\", \"native-v2\", \"pmm-1\", \"pmm-13\", \"pmm-14\", \"pmm-18\", \"pmm-19\", \"pmm-2\", \"pmm-20\", \"pmm-21\", \"pmm-4\", \"pmm-5\", \"pmm-8\"],\n 56: [\"bebop\", \"hashflow-v3\", \"native-v1\", \"native-v2\", \"pmm-1\", \"pmm-10\", \"pmm-13\", \"pmm-18\", \"pmm-19\", \"pmm-2\", \"pmm-20\", \"pmm-5\", \"pmm-8\", \"swaap-v2\"],\n 42161: [\"bebop\", \"hashflow-v3\", \"native-v1\", \"native-v2\", \"pmm-13\", \"pmm-2\", \"pmm-21\", \"pmm-5\", \"pmm-6\", \"pmm-7\", \"pmm-8\", \"swaap-v2\"],\n 10: [\"bebop\", \"pmm-13\", \"swaap-v2\"],\n 137: [\"bebop\", \"native-v1\", \"pmm-5\", \"pmm-8\", \"swaap-v2\"],\n 43114: [\"bebop\", \"dexalot\", \"hashflow-v3\", \"native-v1\", \"pmm-4\", \"swaap-v2\"],\n 59144: [\"native-v1\", \"swaap-v2\"],\n 146: [\"swaap-v2\"],\n 80094: [\"bebop\"],\n 130: [],\n 999: [\"bebop\"],\n 9745: [],\n 143: [\"native-v2\", \"swaap-v2\"],\n 4326: [],\n 4663: [\"bebop\", \"native-v2\", \"pmm-18\", \"pmm-19\", \"pmm-20\", \"swaap-v2\"],\n 5042: [\"pmm-13\"],\n 99901: [],\n});\n\n/** Source ids that look like RFQ wherever KyberSwap lists them (a source added after the list above was read). */\nconst RFQ_LIKE = /^(?:pmm-\\d+|kyber-pmm|native-v\\d+|bebop|hashflow(?:-v\\d+)?|swaap-v\\d+|clipper|dexalot|mx-trading|[a-z0-9-]*-rfq|rfq-[a-z0-9-]*)$/;\n\n/**\n * What a route hop's liquidity is: an RFQ market maker, a KyberSwap limit order, or anything else (a pool, a\n * proprietary AMM). Read from the hop as `GET /routes` returns it: `poolType` (\"orderbook\" for an RFQ maker,\n * \"limit-order\" for a limit order) or the source id — the part before \"/\" when KyberSwap names a fallback after it\n * (\"pmm-19/uniswapv3\": the maker, and the pool the route falls back to when the maker does not sign).\n */\nexport function kyberSourceKind(chainId: number, exchange: unknown, poolType?: unknown): \"rfq\" | \"limit-order\" | \"pool\" {\n const id = typeof exchange === \"string\" ? exchange.split(\"/\")[0]! : \"\";\n if (poolType === \"limit-order\" || /^kyberswap-limit-order(?:-v\\d+)?$/.test(id)) return \"limit-order\";\n const listed = Object.prototype.hasOwnProperty.call(KYBER_RFQ_SOURCES, chainId) ? KYBER_RFQ_SOURCES[chainId]! : [];\n return poolType === \"orderbook\" || listed.includes(id) || RFQ_LIKE.test(id) ? \"rfq\" : \"pool\";\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 provider's `exactAllowanceOnly` (protocol-swap2-core): true on the chains whose router is the `generic` build —\n * `swapGeneric` behind an owner-managed executor whitelist, so the router's owner (a single key on all but Linea) could\n * make it spend an allowance left on it. The engine then approves exactly the input and revokes it when the swap does\n * not spend it, whatever the app's `allowanceReuse` / `revokeUnspentApproval` say. False on the `lite` chains; true\n * for a chain this module does not know (fail closed).\n */\nexport function kyberExactAllowanceOnly(chain: string): boolean {\n return kyberChain(chainIdOf(chain))?.build !== \"lite\";\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 exactAllowanceOnly: kyberExactAllowanceOnly,\n verifyQuote: kyberVerifyQuote,\n reasonOf: (refusal: string) => notes.reasonOf(refusal),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,sBAAwD;AACxD,IAAAA,eAA4B;;;ACM5B,kBAA4B;AAC5B,oBAA2E;AAC3E,0BAA6B;AAC7B,kBAAqF;AAG9E,IAAM,kBAAkB;AAExB,IAAM,iBAAiB;AAEvB,IAAM,kBAAkB;AAExB,IAAM,eAAe;AAC5B,IAAM,OAAO;AAeN,IAAM,eAAgG,OAAO,OAAO;AAAA,EACzH,GAAG,EAAC,MAAM,YAAY,MAAM,YAAY,OAAO,UAAS;AAAA,EACxD,MAAM,EAAC,MAAM,QAAQ,MAAM,QAAQ,OAAO,UAAS;AAAA,EACnD,IAAI,EAAC,MAAM,OAAO,MAAM,mBAAmB,OAAO,UAAS;AAAA,EAC3D,OAAO,EAAC,MAAM,YAAY,MAAM,YAAY,OAAO,UAAS;AAAA,EAC5D,IAAI,EAAC,MAAM,YAAY,MAAM,YAAY,OAAO,UAAS;AAAA,EACzD,KAAK,EAAC,MAAM,WAAW,MAAM,WAAW,OAAO,UAAS;AAAA,EACxD,OAAO,EAAC,MAAM,aAAa,MAAM,aAAa,OAAO,UAAS;AAAA,EAC9D,OAAO,EAAC,MAAM,SAAS,MAAM,SAAS,OAAO,UAAS;AAAA,EACtD,KAAK,EAAC,MAAM,SAAS,MAAM,SAAS,OAAO,OAAM;AAAA,EACjD,OAAO,EAAC,MAAM,aAAa,MAAM,aAAa,OAAO,OAAM;AAAA,EAC3D,KAAK,EAAC,MAAM,YAAY,MAAM,YAAY,OAAO,OAAM;AAAA,EACvD,KAAK,EAAC,MAAM,YAAY,MAAM,YAAY,OAAO,OAAM;AAAA,EACvD,MAAM,EAAC,MAAM,UAAU,MAAM,UAAU,OAAO,OAAM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C,cAAU,wBAAW,OAAO,WAAW;AAAA,MACvC,cAAc;AAAA,IAChB,CAAC;AACD,WAAO;AAAA,EACT,SAAS,GAAG;AACV,UAAM,OAAO,aAAa,QAAQ,EAAE,QAAQ,QAAQ,gBAAgB,EAAE,IAAI,OAAO,CAAC;AAClF,UAAM,WAAO,yBAAU,CAAC;AACxB,WAAO,OAAO,MAAM,KAAK,MAAM,IAAI,IAAI;AAAA,EACzC;AACF;AAEA,SAAS,UAAU,OAAkC;AACnD,SAAO,WAAW,UAAU,KAAK,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC;AAC7D;AASO,SAAS,wBAAwB,OAAwB;AAC9D,SAAO,WAAW,UAAU,KAAK,CAAC,GAAG,UAAU;AACjD;AAOO,IAAM,YAAwB,OAAO,OAAO;AAAA,EACjD,aAAa;AAAA,EACb,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,aAAa;AAAA,EACb,UAAU,CAAC,YAAoB,MAAM,SAAS,OAAO;AACvD,CAAC;;;ADnUM,IAAM,mBAAmB;AAEzB,SAAS,sBAAsB,IAAa,KAAmD;AACpG,MAAI,KAAC,oBAAM,GAAG,KAAK,KAAK,CAAC,eAAW,qBAAO,GAAG,KAAK,CAAC,EAAG,QAAO;AAC9D,MAAI,KAAC,6BAAY,IAAI,CAAC,eAAe,GAAG,CAAC,mBAAmB,CAAC,EAAG,QAAO;AACvE,aAAO,kCAAiB,IAAI,KAAK,EAAC,UAAU,kBAAkB,UAAU,sBAAe,4BAAW,GAAG,KAAK,CAAC,IAAI,MAAM,OAAM,CAAC;AAC9H;","names":["import_util"]}
|
package/dist/activity.js
CHANGED
|
@@ -28,6 +28,34 @@ var KYBER_CHAINS = Object.freeze({
|
|
|
28
28
|
5042: { slug: "arc", name: "Arc", build: "lite" },
|
|
29
29
|
99901: { slug: "elysium", name: "Elysium", build: "lite" }
|
|
30
30
|
});
|
|
31
|
+
var KYBER_LIMIT_ORDER_SOURCES = Object.freeze(["kyberswap-limit-order-v2"]);
|
|
32
|
+
var KYBER_RFQ_SOURCES = Object.freeze({
|
|
33
|
+
1: ["bebop", "clear-rfq", "hashflow-v3", "native-v1", "native-v2", "pmm-1", "pmm-10", "pmm-11", "pmm-12", "pmm-18", "pmm-2", "pmm-20", "pmm-3", "pmm-4", "pmm-5", "pmm-6", "pmm-7", "pmm-8", "swaap-v2"],
|
|
34
|
+
8453: ["bebop", "hashflow-v3", "native-v1", "native-v2", "pmm-1", "pmm-13", "pmm-14", "pmm-18", "pmm-19", "pmm-2", "pmm-20", "pmm-21", "pmm-4", "pmm-5", "pmm-8"],
|
|
35
|
+
56: ["bebop", "hashflow-v3", "native-v1", "native-v2", "pmm-1", "pmm-10", "pmm-13", "pmm-18", "pmm-19", "pmm-2", "pmm-20", "pmm-5", "pmm-8", "swaap-v2"],
|
|
36
|
+
42161: ["bebop", "hashflow-v3", "native-v1", "native-v2", "pmm-13", "pmm-2", "pmm-21", "pmm-5", "pmm-6", "pmm-7", "pmm-8", "swaap-v2"],
|
|
37
|
+
10: ["bebop", "pmm-13", "swaap-v2"],
|
|
38
|
+
137: ["bebop", "native-v1", "pmm-5", "pmm-8", "swaap-v2"],
|
|
39
|
+
43114: ["bebop", "dexalot", "hashflow-v3", "native-v1", "pmm-4", "swaap-v2"],
|
|
40
|
+
59144: ["native-v1", "swaap-v2"],
|
|
41
|
+
146: ["swaap-v2"],
|
|
42
|
+
80094: ["bebop"],
|
|
43
|
+
130: [],
|
|
44
|
+
999: ["bebop"],
|
|
45
|
+
9745: [],
|
|
46
|
+
143: ["native-v2", "swaap-v2"],
|
|
47
|
+
4326: [],
|
|
48
|
+
4663: ["bebop", "native-v2", "pmm-18", "pmm-19", "pmm-20", "swaap-v2"],
|
|
49
|
+
5042: ["pmm-13"],
|
|
50
|
+
99901: []
|
|
51
|
+
});
|
|
52
|
+
var RFQ_LIKE = /^(?:pmm-\d+|kyber-pmm|native-v\d+|bebop|hashflow(?:-v\d+)?|swaap-v\d+|clipper|dexalot|mx-trading|[a-z0-9-]*-rfq|rfq-[a-z0-9-]*)$/;
|
|
53
|
+
function kyberSourceKind(chainId, exchange, poolType) {
|
|
54
|
+
const id = typeof exchange === "string" ? exchange.split("/")[0] : "";
|
|
55
|
+
if (poolType === "limit-order" || /^kyberswap-limit-order(?:-v\d+)?$/.test(id)) return "limit-order";
|
|
56
|
+
const listed = Object.prototype.hasOwnProperty.call(KYBER_RFQ_SOURCES, chainId) ? KYBER_RFQ_SOURCES[chainId] : [];
|
|
57
|
+
return poolType === "orderbook" || listed.includes(id) || RFQ_LIKE.test(id) ? "rfq" : "pool";
|
|
58
|
+
}
|
|
31
59
|
function kyberChain(chainId) {
|
|
32
60
|
return Object.prototype.hasOwnProperty.call(KYBER_CHAINS, chainId) ? KYBER_CHAINS[chainId] : void 0;
|
|
33
61
|
}
|
|
@@ -155,9 +183,13 @@ function kyberVerifyQuote(params, quote) {
|
|
|
155
183
|
function routerFor(chain) {
|
|
156
184
|
return kyberChain(chainIdOf(chain)) ? [KYBER_ROUTER_V2] : [];
|
|
157
185
|
}
|
|
186
|
+
function kyberExactAllowanceOnly(chain) {
|
|
187
|
+
return kyberChain(chainIdOf(chain))?.build !== "lite";
|
|
188
|
+
}
|
|
158
189
|
var kyberPins = Object.freeze({
|
|
159
190
|
callTargets: routerFor,
|
|
160
191
|
spenders: routerFor,
|
|
192
|
+
exactAllowanceOnly: kyberExactAllowanceOnly,
|
|
161
193
|
verifyQuote: kyberVerifyQuote,
|
|
162
194
|
reasonOf: (refusal) => notes.reasonOf(refusal)
|
|
163
195
|
});
|
|
@@ -168,6 +200,9 @@ export {
|
|
|
168
200
|
KYBER_ROUTER_V3,
|
|
169
201
|
KYBER_NATIVE,
|
|
170
202
|
KYBER_CHAINS,
|
|
203
|
+
KYBER_LIMIT_ORDER_SOURCES,
|
|
204
|
+
KYBER_RFQ_SOURCES,
|
|
205
|
+
kyberSourceKind,
|
|
171
206
|
kyberChain,
|
|
172
207
|
kyberNativeSwaps,
|
|
173
208
|
KYBER_ROUTER_ABI,
|
|
@@ -179,6 +214,7 @@ export {
|
|
|
179
214
|
kyberMinimum,
|
|
180
215
|
kyberApiSlippage,
|
|
181
216
|
kyberVerifyQuote,
|
|
217
|
+
kyberExactAllowanceOnly,
|
|
182
218
|
kyberPins
|
|
183
219
|
};
|
|
184
|
-
//# sourceMappingURL=chunk-
|
|
220
|
+
//# sourceMappingURL=chunk-D4UIDHM2.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/** KyberSwap's own limit orders: makers' signed orders kept off-chain, filled on-chain by the executor (the active source id). */\nexport const KYBER_LIMIT_ORDER_SOURCES: readonly string[] = Object.freeze([\"kyberswap-limit-order-v2\"]);\n\n/**\n * KyberSwap's RFQ sources per chain — private market makers whose firm quote is signed when the route is built: the\n * sources tagged \"RFQ sources\" in KyberSwap's own source list (`ks-setting.kyberswap.com/api/v1/dexes`, read\n * 2026-11-30). `excludeRFQSources=true` leaves out these and the limit orders together; this list is how the provider\n * asks for limit orders without RFQ (`limitOrders: \"include\"`, `rfq: \"exclude\"`). An empty list: the chain had no RFQ\n * source. A source KyberSwap adds later is still recognised in a route by `kyberSourceKind` (its `poolType`, or an\n * RFQ-like id), so the quote is marked and timed as RFQ; only the request would not leave it out.\n */\nexport const KYBER_RFQ_SOURCES: Readonly<Record<number, readonly string[]>> = Object.freeze({\n 1: [\"bebop\", \"clear-rfq\", \"hashflow-v3\", \"native-v1\", \"native-v2\", \"pmm-1\", \"pmm-10\", \"pmm-11\", \"pmm-12\", \"pmm-18\", \"pmm-2\", \"pmm-20\", \"pmm-3\", \"pmm-4\", \"pmm-5\", \"pmm-6\", \"pmm-7\", \"pmm-8\", \"swaap-v2\"],\n 8453: [\"bebop\", \"hashflow-v3\", \"native-v1\", \"native-v2\", \"pmm-1\", \"pmm-13\", \"pmm-14\", \"pmm-18\", \"pmm-19\", \"pmm-2\", \"pmm-20\", \"pmm-21\", \"pmm-4\", \"pmm-5\", \"pmm-8\"],\n 56: [\"bebop\", \"hashflow-v3\", \"native-v1\", \"native-v2\", \"pmm-1\", \"pmm-10\", \"pmm-13\", \"pmm-18\", \"pmm-19\", \"pmm-2\", \"pmm-20\", \"pmm-5\", \"pmm-8\", \"swaap-v2\"],\n 42161: [\"bebop\", \"hashflow-v3\", \"native-v1\", \"native-v2\", \"pmm-13\", \"pmm-2\", \"pmm-21\", \"pmm-5\", \"pmm-6\", \"pmm-7\", \"pmm-8\", \"swaap-v2\"],\n 10: [\"bebop\", \"pmm-13\", \"swaap-v2\"],\n 137: [\"bebop\", \"native-v1\", \"pmm-5\", \"pmm-8\", \"swaap-v2\"],\n 43114: [\"bebop\", \"dexalot\", \"hashflow-v3\", \"native-v1\", \"pmm-4\", \"swaap-v2\"],\n 59144: [\"native-v1\", \"swaap-v2\"],\n 146: [\"swaap-v2\"],\n 80094: [\"bebop\"],\n 130: [],\n 999: [\"bebop\"],\n 9745: [],\n 143: [\"native-v2\", \"swaap-v2\"],\n 4326: [],\n 4663: [\"bebop\", \"native-v2\", \"pmm-18\", \"pmm-19\", \"pmm-20\", \"swaap-v2\"],\n 5042: [\"pmm-13\"],\n 99901: [],\n});\n\n/** Source ids that look like RFQ wherever KyberSwap lists them (a source added after the list above was read). */\nconst RFQ_LIKE = /^(?:pmm-\\d+|kyber-pmm|native-v\\d+|bebop|hashflow(?:-v\\d+)?|swaap-v\\d+|clipper|dexalot|mx-trading|[a-z0-9-]*-rfq|rfq-[a-z0-9-]*)$/;\n\n/**\n * What a route hop's liquidity is: an RFQ market maker, a KyberSwap limit order, or anything else (a pool, a\n * proprietary AMM). Read from the hop as `GET /routes` returns it: `poolType` (\"orderbook\" for an RFQ maker,\n * \"limit-order\" for a limit order) or the source id — the part before \"/\" when KyberSwap names a fallback after it\n * (\"pmm-19/uniswapv3\": the maker, and the pool the route falls back to when the maker does not sign).\n */\nexport function kyberSourceKind(chainId: number, exchange: unknown, poolType?: unknown): \"rfq\" | \"limit-order\" | \"pool\" {\n const id = typeof exchange === \"string\" ? exchange.split(\"/\")[0]! : \"\";\n if (poolType === \"limit-order\" || /^kyberswap-limit-order(?:-v\\d+)?$/.test(id)) return \"limit-order\";\n const listed = Object.prototype.hasOwnProperty.call(KYBER_RFQ_SOURCES, chainId) ? KYBER_RFQ_SOURCES[chainId]! : [];\n return poolType === \"orderbook\" || listed.includes(id) || RFQ_LIKE.test(id) ? \"rfq\" : \"pool\";\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 provider's `exactAllowanceOnly` (protocol-swap2-core): true on the chains whose router is the `generic` build —\n * `swapGeneric` behind an owner-managed executor whitelist, so the router's owner (a single key on all but Linea) could\n * make it spend an allowance left on it. The engine then approves exactly the input and revokes it when the swap does\n * not spend it, whatever the app's `allowanceReuse` / `revokeUnspentApproval` say. False on the `lite` chains; true\n * for a chain this module does not know (fail closed).\n */\nexport function kyberExactAllowanceOnly(chain: string): boolean {\n return kyberChain(chainIdOf(chain))?.build !== \"lite\";\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 exactAllowanceOnly: kyberExactAllowanceOnly,\n verifyQuote: kyberVerifyQuote,\n reasonOf: (refusal: string) => notes.reasonOf(refusal),\n});\n"],"mappings":";AAYA,SAAQ,qBAAoB;AAC5B,SAAQ,cAAc,WAAW,kBAA0C;AAC3E,SAAQ,sBAAqB;AAC7B,SAAQ,oBAAoB,oBAAoB,YAAY,gBAAyB;AAG9E,IAAM,kBAAkB;AAExB,IAAM,iBAAiB;AAEvB,IAAM,kBAAkB;AAExB,IAAM,eAAe;AAC5B,IAAM,OAAO;AAeN,IAAM,eAAgG,OAAO,OAAO;AAAA,EACzH,GAAG,EAAC,MAAM,YAAY,MAAM,YAAY,OAAO,UAAS;AAAA,EACxD,MAAM,EAAC,MAAM,QAAQ,MAAM,QAAQ,OAAO,UAAS;AAAA,EACnD,IAAI,EAAC,MAAM,OAAO,MAAM,mBAAmB,OAAO,UAAS;AAAA,EAC3D,OAAO,EAAC,MAAM,YAAY,MAAM,YAA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AACV,UAAM,OAAO,aAAa,QAAQ,EAAE,QAAQ,QAAQ,gBAAgB,EAAE,IAAI,OAAO,CAAC;AAClF,UAAM,OAAO,UAAU,CAAC;AACxB,WAAO,OAAO,MAAM,KAAK,MAAM,IAAI,IAAI;AAAA,EACzC;AACF;AAEA,SAAS,UAAU,OAAkC;AACnD,SAAO,WAAW,UAAU,KAAK,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC;AAC7D;AASO,SAAS,wBAAwB,OAAwB;AAC9D,SAAO,WAAW,UAAU,KAAK,CAAC,GAAG,UAAU;AACjD;AAOO,IAAM,YAAwB,OAAO,OAAO;AAAA,EACjD,aAAa;AAAA,EACb,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,aAAa;AAAA,EACb,UAAU,CAAC,YAAoB,MAAM,SAAS,OAAO;AACvD,CAAC;","names":[]}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
KYBER_ROUTER_V2,
|
|
3
3
|
KYBER_SWAP_SELECTOR,
|
|
4
4
|
kyberChain
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-D4UIDHM2.js";
|
|
6
6
|
|
|
7
7
|
// src/activity.ts
|
|
8
8
|
import { chainLabel, describeSwapLike, matchesCall } from "@anywalletkit/protocol-swap2-core/activity";
|
|
@@ -18,4 +18,4 @@ export {
|
|
|
18
18
|
KYBERSWAP_MODULE,
|
|
19
19
|
describeKyberActivity
|
|
20
20
|
};
|
|
21
|
-
//# sourceMappingURL=chunk-
|
|
21
|
+
//# sourceMappingURL=chunk-HHZEL5IJ.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
kyberswapProvider
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NFMHUXU6.js";
|
|
4
4
|
import {
|
|
5
5
|
kyberChain
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-D4UIDHM2.js";
|
|
7
7
|
|
|
8
8
|
// src/protocol.ts
|
|
9
9
|
import { SingleProviderSwap2 } from "@anywalletkit/protocol-swap2-core/swap2/single";
|
|
@@ -29,4 +29,4 @@ var KyberswapSwap2Protocol = class extends SingleProviderSwap2 {
|
|
|
29
29
|
export {
|
|
30
30
|
KyberswapSwap2Protocol
|
|
31
31
|
};
|
|
32
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-LIEIWIYI.js.map
|