@anywalletkit/protocol-swap2-kyberswap 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -6
- package/dist/activity.cjs +28 -2
- package/dist/activity.cjs.map +1 -1
- package/dist/activity.js +2 -2
- package/dist/{chunk-LO4G4NX7.js → chunk-BGMHF5MC.js} +3 -3
- package/dist/{chunk-OHBN7OQI.js → chunk-CFL4E4AW.js} +40 -3
- package/dist/chunk-CFL4E4AW.js.map +1 -0
- package/dist/{chunk-5ZMVXS7P.js → chunk-DP4WDX4C.js} +2 -2
- package/dist/{chunk-RZ2CCM34.js → chunk-INSCVUFN.js} +62 -15
- package/dist/chunk-INSCVUFN.js.map +1 -0
- package/dist/index.cjs +93 -13
- 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 +16 -4
- package/dist/protocol.cjs +87 -13
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.js +4 -4
- package/dist/provider.cjs +89 -13
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +25 -2
- package/dist/provider.d.ts +25 -2
- package/dist/provider.js +7 -3
- package/dist/router.cjs +39 -2
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts +23 -2
- package/dist/router.d.ts +23 -2
- package/dist/router.js +9 -1
- package/package.json +7 -7
- package/dist/chunk-OHBN7OQI.js.map +0 -1
- package/dist/chunk-RZ2CCM34.js.map +0 -1
- /package/dist/{chunk-LO4G4NX7.js.map → chunk-BGMHF5MC.js.map} +0 -0
- /package/dist/{chunk-5ZMVXS7P.js.map → chunk-DP4WDX4C.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
|
|
@@ -60,22 +62,164 @@ returns is checked on the device against the pinned router and the app's own req
|
|
|
60
62
|
allowance is already there — so a route that reverts never asks for an approval. A wallet without the input, or an
|
|
61
63
|
RPC without `eth_simulateV1` (Monad, Avalanche, HyperEVM on 2026-11-25), skips that early check
|
|
62
64
|
(`providerData.simulated: "none"`). Every swap is simulated again from the account at the latest block right before
|
|
63
|
-
signing (`preflightDeposit`). A revert, or no RPC answering, refuses the swap — nothing is sent unsimulated.
|
|
64
|
-
the account's own estimate of the exact call (`ownGasEstimate`)
|
|
65
|
+
signing (`preflightDeposit`). A revert, or no RPC answering, refuses the swap — nothing is sent unsimulated. The
|
|
66
|
+
gas limit is built on the account's own estimate of the exact call (`ownGasEstimate`): `max(estimate, build gas) ×
|
|
67
|
+
1.3 + 100 000`, see "Gas" below.
|
|
65
68
|
- Token inputs approve exactly the amount to the router (the engine default), spent in the same transaction.
|
|
66
69
|
- KyberSwap's own USD values of the input and the output (`amountInUsd` / `amountOutUsd`) reach the router's
|
|
67
70
|
`quoteValues` as `providerData.priceImpactBps` — the value lost to pool impact and pool fees — so a near-total loss
|
|
68
71
|
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
72
|
Information only, never a refusal; a token KyberSwap does not price carries none.
|
|
70
73
|
|
|
74
|
+
## RFQ and limit orders
|
|
75
|
+
|
|
76
|
+
Two kinds of KyberSwap liquidity are not pools: **RFQ market makers** (the sources KyberSwap tags "RFQ sources":
|
|
77
|
+
`pmm-N`, Bebop, Native, Hashflow, Swaap, …), whose firm quote is signed when the route is built, and KyberSwap's own
|
|
78
|
+
**limit orders** (`kyberswap-limit-order-v2`), makers' signed orders kept off-chain and co-signed by KyberSwap when the
|
|
79
|
+
route is built. Both are left out by default. KyberSwap's `excludeRFQSources=true` (0.2.0, and the default here)
|
|
80
|
+
leaves out both together; checked 2026-11-30 on Ethereum DRV → USDC: with it, no limit-order hop; with the RFQ sources
|
|
81
|
+
excluded by name instead, the limit order stays in the route.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
kyberswapProvider({rpcUrls, limitOrders: 'include'}) // limit orders, no RFQ (recommended, below)
|
|
85
|
+
kyberswapProvider({rpcUrls, rfq: 'include', limitOrders: 'include'}) // everything KyberSwap offers this client
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
| `rfq` | `limitOrders` | `GET /routes` asks |
|
|
89
|
+
|---|---|---|
|
|
90
|
+
| exclude | exclude | `excludeRFQSources=true` — the 0.2.0 request, byte for byte |
|
|
91
|
+
| exclude | include | `excludedSources=` the chain's RFQ sources (`KYBER_RFQ_SOURCES`, read from KyberSwap's source list 2026-11-30) |
|
|
92
|
+
| include | exclude | `excludedSources=kyberswap-limit-order-v2` |
|
|
93
|
+
| include | include | no source filter |
|
|
94
|
+
|
|
95
|
+
The app's own `excludedSources` are added to the list. The execution quote asks `/routes` with the same filters as
|
|
96
|
+
the dry one, so the route reviewed and the route built draw on the same liquidity.
|
|
97
|
+
|
|
98
|
+
What changes for a route that uses either kind (`kyberSourceKind` reads each hop's `poolType` — "orderbook" for an
|
|
99
|
+
RFQ maker, "limit-order" — or its source id; a new `pmm-N` KyberSwap adds after the list was read is still
|
|
100
|
+
recognised):
|
|
101
|
+
|
|
102
|
+
- `providerData.offchain` is `"rfq"`, `"limit-order"` or `"rfq,limit-order"`.
|
|
103
|
+
- `validUntilMs` is at most `KYBER_RFQ_TTL_MS` (10 s) with an RFQ hop, `KYBER_LIMIT_ORDER_TTL_MS` (30 s) with a limit
|
|
104
|
+
order, and never more than `quoteTtlMs`. The API states no expiry for either; the figures are the measurement below.
|
|
105
|
+
An approval mined after the quote ran out gets the engine's one re-quote, on the same allowance (no new approval).
|
|
106
|
+
- The execution quote's `destAmount` is the build's `amountOut` when that is lower than the route's (the maker signs,
|
|
107
|
+
or KyberSwap falls back to the pool it names after the maker — `pmm-19/uniswapv3` — only at build); a build under
|
|
108
|
+
the quote's minimum is refused (`price_check_failed`).
|
|
109
|
+
- Nothing else is relaxed: the same `swap()`, router, executor, flags, input split, receiver and minimum checks
|
|
110
|
+
(every RFQ and limit-order build measured passed `checkKyberTransaction` unchanged), the same simulation before any
|
|
111
|
+
approval and again before signing, `exactAllowanceOnly` on the generic-build routers.
|
|
112
|
+
- A swap whose maker quote or limit order no longer fills reverts in the pre-signing simulation and is refused as
|
|
113
|
+
`quote_expired` ("the limit order in this route no longer fills (expired or taken). Nothing was sent; refresh the
|
|
114
|
+
quote."); the router's minimum check stays `price_check_failed`. Recorded: `fixtures/offchain`.
|
|
115
|
+
|
|
116
|
+
What this client gets: keyless, and with an API key, a route of RFQ sources alone is refused (`40011 filtered
|
|
117
|
+
liquidity sources`) on Ethereum, Base, BNB Smart Chain and Arbitrum; RFQ makers show up only as hops inside mixed
|
|
118
|
+
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
|
|
119
|
+
of six of those pairs, asked every 9 s for two minutes, at 11:53).
|
|
120
|
+
|
|
121
|
+
### Measured (2026-11-30)
|
|
122
|
+
|
|
123
|
+
Price: 20 pairs on Ethereum, Base, Arbitrum and BNB Smart Chain, `GET /routes` in the four settings one after the
|
|
124
|
+
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
|
|
125
|
+
second), each against today's route (both excluded), in bps of `amountOut`. Differences of about 1 bps are those
|
|
126
|
+
seconds (proprietary AMMs reprice every block), not the setting.
|
|
127
|
+
|
|
128
|
+
| Chain | Swap | Size | Limit orders only | RFQ only | Both | Off-chain hops in "both" |
|
|
129
|
+
|---|---|---|---|---|---|---|
|
|
130
|
+
| Ethereum | ETH → USDC | $1,661 | +0.1 | +0.0 | +0.1 | — |
|
|
131
|
+
| Ethereum | ETH → USDC | $83,070 | −0.4 | −0.4 | +0.5 | — |
|
|
132
|
+
| Ethereum | USDC → ETH | $199,976 | −0.2 | −0.4 | −0.3 | — |
|
|
133
|
+
| Ethereum | USDT → USDC | $499,742 | +0.0 | +0.0 | +0.0 | — |
|
|
134
|
+
| Ethereum | WBTC → USDC | $178,882 | +0.0 | +0.0 | +0.0 | — |
|
|
135
|
+
| Ethereum | PEPE → ETH | $3,506 | +0.0 | +0.0 | +0.0 | — |
|
|
136
|
+
| Ethereum | DRV → USDC | $23,806 | **+15.1** | +0.0 | **+15.1** | limit order |
|
|
137
|
+
| Base | ETH → USDC | $49,819 | +0.8 | +0.6 | +0.6 | Bebop |
|
|
138
|
+
| Base | USDC → ETH | $995 | +0.7 | +0.5 | +0.5 | — |
|
|
139
|
+
| Base | USDC → cbBTC | $99,456 | +0.2 | +0.0 | +0.1 | — |
|
|
140
|
+
| Base | AERO → USDC | $19,012 | +0.1 | −0.3 | +0.1 | — |
|
|
141
|
+
| Base | USDC → VIRTUAL | $19,891 | +0.9 | −2.0 | **+7.3** | Bebop, pmm-8, pmm-19, pmm-21 |
|
|
142
|
+
| Arbitrum | ETH → USDC | $49,853 | +0.0 | +0.0 | −0.9 | Native |
|
|
143
|
+
| Arbitrum | USDC → WBTC | $99,997 | +0.7 | +0.0 | +0.0 | pmm-13 |
|
|
144
|
+
| Arbitrum | USDT0 → USDC | $199,757 | +0.0 | +0.0 | +0.0 | pmm-13 |
|
|
145
|
+
| Arbitrum | ARB → USDC | $10,898 | +0.0 | +0.0 | +0.2 | pmm-13 |
|
|
146
|
+
| BNB Smart Chain | BNB → USDT | $55,213 | +0.0 | +0.0 | −0.3 | — |
|
|
147
|
+
| BNB Smart Chain | USDT → BNB | $49,950 | −0.0 | +0.1 | +0.5 | — |
|
|
148
|
+
| BNB Smart Chain | CAKE → USDT | $30,781 | +0.1 | +0.0 | **+1.4** | pmm-19 |
|
|
149
|
+
| BNB Smart Chain | USDT → BTCB | $49,885 | −0.1 | −0.7 | −1.0 | pmm-13 |
|
|
150
|
+
|
|
151
|
+
The same DRV → USDC swap read +46 and +59 bps through a limit order earlier that day (reported first by cp0x: another
|
|
152
|
+
KyberSwap interface 0.17 % over this module on 64 000 DRV, its route through `kyberswap-limit-order-v2`); KNC → USDC
|
|
153
|
+
routes through a limit order too. Limit orders pay where makers post orders above the pools, mostly long-tail tokens; on
|
|
154
|
+
majors neither kind moved the price by more than the noise.
|
|
155
|
+
|
|
156
|
+
Execution: for every route with an off-chain hop (and today's route as a control), `POST /route/build` right after the
|
|
157
|
+
quote for a throwaway sender = recipient, and that one calldata run with `eth_simulateV1` (sender funded by a state
|
|
158
|
+
override, a token input approved exactly in the same simulated block; nothing sent) 0, 10, 30 and 60 s after the
|
|
159
|
+
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:
|
|
160
|
+
today's route reverted there too, so its reverts are not the RFQ maker's.
|
|
161
|
+
|
|
162
|
+
| Route | Calldata from the quote runs at 0 / 10 / 30 / 60 s | Built afresh at 10 / 30 / 60 s, runs |
|
|
163
|
+
|---|---|---|
|
|
164
|
+
| pools only (control) | 18/18 at 0 s, 18/18 at 60 s | — |
|
|
165
|
+
| with a limit order | 2/2, 2/2, 2/2, 2/2 | 1/1, 1/1, 1/1 |
|
|
166
|
+
| with an RFQ maker | 5/7, 5/7, **4/7**, 4/7 | 5/7, 5/7, 5/7 |
|
|
167
|
+
|
|
168
|
+
- 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
|
|
169
|
+
at 91 s (parts of the orders gone, still above the minimum), and reverted ("Call failed") from 121 s — the recording
|
|
170
|
+
in `fixtures/offchain`.
|
|
171
|
+
- RFQ: two of the seven RFQ routes never ran (Base USDC → VIRTUAL through five makers; Arbitrum ARB → USDC through
|
|
172
|
+
`pmm-13`), not from the quote and not built afresh: the simulation right after the build refuses them before any
|
|
173
|
+
approval. One (BNB Smart Chain CAKE → USDT through `pmm-19`) ran at 11 s and reverted at 30 s: with an approval in
|
|
174
|
+
between, that swap fails after the user paid for the approval — hence the 10-second life, which sends such a swap
|
|
175
|
+
to a re-quote after the approval instead. One fresh build failed outright (`4222 quoted amount is smaller than
|
|
176
|
+
estimated`): a refusal, as for any route.
|
|
177
|
+
|
|
178
|
+
### Which setting
|
|
179
|
+
|
|
180
|
+
For an app with an approval between the quote and the signature (30–60 s): **`limitOrders: "include"`, `rfq:
|
|
181
|
+
"exclude"`.** Limit orders are where the price is (+15 to +59 bps on the long tail, nothing lost on majors), and their
|
|
182
|
+
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
|
|
183
|
+
seven RFQ routes did not execute at all, and one expired inside an approval's time; with RFQ included the 10-second
|
|
184
|
+
life also means a review longer than 10 s ends in "quote expired" before anything is signed.
|
|
185
|
+
|
|
186
|
+
RFQ for listing only (dry quotes with `rfq: "include"`, execution without) is not offered: the list would show a price
|
|
187
|
+
the execution quote, asking without RFQ, may not reach.
|
|
188
|
+
|
|
71
189
|
## Gas: `gasEstimate`
|
|
72
190
|
|
|
73
191
|
Every quote, dry or for execution, carries `gasEstimate` = KyberSwap's `routeSummary.gas` from `GET /routes` (asked
|
|
74
192
|
with `gasInclude=true`), `gasEstimateSource: "venue"`. It is there to compare routes (see protocol-swap2-core, "Gas:
|
|
75
193
|
`gasEstimate` vs `gasLimit`"): a dry quote has no transaction, so before this the router could only assume a gas limit
|
|
76
|
-
for it.
|
|
77
|
-
|
|
78
|
-
|
|
194
|
+
for it. It counts the swap call only, no approval. A route that states no gas (or 0) gives a dry quote without one;
|
|
195
|
+
an execution quote then takes the build's `gas` instead, when that is a valid figure.
|
|
196
|
+
|
|
197
|
+
## Gas: the limit the swap is sent with
|
|
198
|
+
|
|
199
|
+
The execution quote carries the build's `gas` as `txRequest.venueGas` (a decimal string from 21 000 to
|
|
200
|
+
10 000 000; anything else is left out, never refused), and the transaction carries no `gasLimit`. Right before the
|
|
201
|
+
broadcast the engine dry-runs the exact call from the account (`ownGasEstimate`) and sends it with
|
|
202
|
+
`max(the account's estimate, venueGas) × 1.3 + 100 000`, at most 10 000 000 (30 000 000 on Monad; above it the swap is refused,
|
|
203
|
+
`policy_refused`); the native-gas check prices that limit. KyberSwap's figure is a floor, never a ceiling: it can
|
|
204
|
+
raise the limit, never lower it below the account's estimate. An account that does not report its estimate
|
|
205
|
+
(`quoteSendTransaction` without `gas`) sends with its own estimate, as before. A remote stub with `kyberPins` declares
|
|
206
|
+
`ownGasEstimate` too, and a swap2 server carries `venueGas` in the sealed quote.
|
|
207
|
+
|
|
208
|
+
Why (2026-12-04, Ethereum, 19 WETH → USDC through MetaAggregationRouterV2, three execution quotes in a row): the
|
|
209
|
+
routes went through many oracle-priced PMM pools, whose gas moves between the estimate and inclusion, and the router's
|
|
210
|
+
catch turns an out-of-gas inside the executor into a plain "Call failed".
|
|
211
|
+
|
|
212
|
+
| Transaction | Sent with (the wallet's estimate × 1.2) | Gas used | Result | The new rule from that estimate alone |
|
|
213
|
+
|---|---|---|---|---|
|
|
214
|
+
| 0x4da3fd71… | 1 187 136 (989 280) | 1 152 501 | out of gas | 1 386 064 |
|
|
215
|
+
| 0x05151ebb… | 2 882 809 (2 402 341) | 2 762 524 | out of gas | 3 223 044 |
|
|
216
|
+
| 0x6fc9f8ac… | 4 316 655 (3 597 212) | 2 864 620 | success | 4 776 376 |
|
|
217
|
+
|
|
218
|
+
For the first one the build's `gas` decides: the new limit reaches the 2 864 620 the successful route used when that
|
|
219
|
+
figure is at least 2 126 631. A fresh build of the same swap (19 WETH → USDC, 2026-12-04, a public WETH holder as
|
|
220
|
+
sender) stated 1 949 706 (RFQ excluded, as the module asks; limit 2 634 618) and 2 241 582 (all sources; limit
|
|
221
|
+
3 014 057). The first route's own figure is not recoverable and its calldata was about half the size of the
|
|
222
|
+
successful one (7.5 kB against 15.8 kB), so what it needed is not known.
|
|
79
223
|
|
|
80
224
|
What KyberSwap's figure is: its own model of the route's gas, not a simulation. The build answers the same number
|
|
81
225
|
(`gas` of `POST /route/build` equalled `routeSummary.gas` in all 16 recordings), and routine routes land on round model
|
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
|
}
|
|
@@ -141,6 +162,7 @@ function kyberMinimum(amountOut, bps) {
|
|
|
141
162
|
const m = amountOut * BigInt(1e4 - bps) / 10000n - 1n;
|
|
142
163
|
return m > 0n ? m : 0n;
|
|
143
164
|
}
|
|
165
|
+
var KYBER_DEFAULT_SLIPPAGE_BPS = 50;
|
|
144
166
|
var chainIdOf = (caip2) => /^eip155:[0-9]+$/.test(caip2) ? Number(caip2.slice(7)) : NaN;
|
|
145
167
|
function kyberVerifyQuote(params, quote) {
|
|
146
168
|
if (params.sourceChain !== params.destChain) return notes.note("same-chain swaps only", "unsupported_pair");
|
|
@@ -153,8 +175,9 @@ function kyberVerifyQuote(params, quote) {
|
|
|
153
175
|
const min = BigInt(quote.minDestAmount), out = BigInt(quote.destAmount);
|
|
154
176
|
if (min <= 0n || min > out) return notes.note("invalid quote amounts", "price_check_failed");
|
|
155
177
|
if (params.minAmountOut !== void 0 && min < BigInt(params.minAmountOut)) return notes.note("the quote's minimum is under the floor", "price_check_failed");
|
|
156
|
-
const bps = params.slippageBps;
|
|
157
|
-
if (
|
|
178
|
+
const bps = params.slippageBps ?? KYBER_DEFAULT_SLIPPAGE_BPS;
|
|
179
|
+
if (!Number.isInteger(bps) || bps < 0 || bps >= 1e4) return notes.note("invalid slippage", "policy_refused");
|
|
180
|
+
if (min < kyberMinimum(out, bps)) {
|
|
158
181
|
return notes.note("the quote's minimum allows more slippage than requested", "price_check_failed");
|
|
159
182
|
}
|
|
160
183
|
const tx = quote.txRequest;
|
|
@@ -186,6 +209,9 @@ var kyberPins = Object.freeze({
|
|
|
186
209
|
callTargets: routerFor,
|
|
187
210
|
spenders: routerFor,
|
|
188
211
|
exactAllowanceOnly: kyberExactAllowanceOnly,
|
|
212
|
+
// As the provider: the engine dry-runs the call from the account and sends it with a limit built on that estimate
|
|
213
|
+
// (the build's gas, `venueGas`, as a floor), never a gas limit the backend quoted.
|
|
214
|
+
ownGasEstimate: true,
|
|
189
215
|
verifyQuote: kyberVerifyQuote,
|
|
190
216
|
reasonOf: (refusal) => notes.reasonOf(refusal)
|
|
191
217
|
});
|
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 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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,EACpB,aAAa;AAAA,EACb,UAAU,CAAC,YAAoB,MAAM,SAAS,OAAO;AACvD,CAAC;;;ADnRM,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"]}
|
|
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\n/** The slippage a KyberSwap quote is held to when the request names none, in bps: 0.5 %, the provider's own default. */\nexport const KYBER_DEFAULT_SLIPPAGE_BPS = 50;\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, within the slippage (default {@link KYBER_DEFAULT_SLIPPAGE_BPS}) and at or\n * 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 — the provider's default when the request names\n // none — never more slippage than that: without a default, a backend's minimum of one unit would pass.\n const bps = params.slippageBps ?? KYBER_DEFAULT_SLIPPAGE_BPS;\n if (!Number.isInteger(bps) || bps < 0 || bps >= 10_000) return notes.note(\"invalid slippage\", \"policy_refused\");\n if (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 // As the provider: the engine dry-runs the call from the account and sends it with a limit built on that estimate\n // (the build's gas, `venueGas`, as a floor), never a gas limit the backend quoted.\n ownGasEstimate: true,\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,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AD5UM,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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
kyberswapProvider
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-INSCVUFN.js";
|
|
4
4
|
import {
|
|
5
5
|
kyberChain
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-CFL4E4AW.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-BGMHF5MC.js.map
|
|
@@ -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
|
}
|
|
@@ -117,6 +145,7 @@ function kyberApiSlippage(amountOut, bps) {
|
|
|
117
145
|
for (let b = bps - 1; b >= 1; b--) if (kyberMinimum(amountOut, b) >= floor && kyberMinimum(amountOut, b) > 0n) return b;
|
|
118
146
|
return null;
|
|
119
147
|
}
|
|
148
|
+
var KYBER_DEFAULT_SLIPPAGE_BPS = 50;
|
|
120
149
|
var chainIdOf = (caip2) => /^eip155:[0-9]+$/.test(caip2) ? Number(caip2.slice(7)) : NaN;
|
|
121
150
|
function kyberVerifyQuote(params, quote) {
|
|
122
151
|
if (params.sourceChain !== params.destChain) return notes.note("same-chain swaps only", "unsupported_pair");
|
|
@@ -129,8 +158,9 @@ function kyberVerifyQuote(params, quote) {
|
|
|
129
158
|
const min = BigInt(quote.minDestAmount), out = BigInt(quote.destAmount);
|
|
130
159
|
if (min <= 0n || min > out) return notes.note("invalid quote amounts", "price_check_failed");
|
|
131
160
|
if (params.minAmountOut !== void 0 && min < BigInt(params.minAmountOut)) return notes.note("the quote's minimum is under the floor", "price_check_failed");
|
|
132
|
-
const bps = params.slippageBps;
|
|
133
|
-
if (
|
|
161
|
+
const bps = params.slippageBps ?? KYBER_DEFAULT_SLIPPAGE_BPS;
|
|
162
|
+
if (!Number.isInteger(bps) || bps < 0 || bps >= 1e4) return notes.note("invalid slippage", "policy_refused");
|
|
163
|
+
if (min < kyberMinimum(out, bps)) {
|
|
134
164
|
return notes.note("the quote's minimum allows more slippage than requested", "price_check_failed");
|
|
135
165
|
}
|
|
136
166
|
const tx = quote.txRequest;
|
|
@@ -162,6 +192,9 @@ var kyberPins = Object.freeze({
|
|
|
162
192
|
callTargets: routerFor,
|
|
163
193
|
spenders: routerFor,
|
|
164
194
|
exactAllowanceOnly: kyberExactAllowanceOnly,
|
|
195
|
+
// As the provider: the engine dry-runs the call from the account and sends it with a limit built on that estimate
|
|
196
|
+
// (the build's gas, `venueGas`, as a floor), never a gas limit the backend quoted.
|
|
197
|
+
ownGasEstimate: true,
|
|
165
198
|
verifyQuote: kyberVerifyQuote,
|
|
166
199
|
reasonOf: (refusal) => notes.reasonOf(refusal)
|
|
167
200
|
});
|
|
@@ -172,6 +205,9 @@ export {
|
|
|
172
205
|
KYBER_ROUTER_V3,
|
|
173
206
|
KYBER_NATIVE,
|
|
174
207
|
KYBER_CHAINS,
|
|
208
|
+
KYBER_LIMIT_ORDER_SOURCES,
|
|
209
|
+
KYBER_RFQ_SOURCES,
|
|
210
|
+
kyberSourceKind,
|
|
175
211
|
kyberChain,
|
|
176
212
|
kyberNativeSwaps,
|
|
177
213
|
KYBER_ROUTER_ABI,
|
|
@@ -182,8 +218,9 @@ export {
|
|
|
182
218
|
checkKyberTransaction,
|
|
183
219
|
kyberMinimum,
|
|
184
220
|
kyberApiSlippage,
|
|
221
|
+
KYBER_DEFAULT_SLIPPAGE_BPS,
|
|
185
222
|
kyberVerifyQuote,
|
|
186
223
|
kyberExactAllowanceOnly,
|
|
187
224
|
kyberPins
|
|
188
225
|
};
|
|
189
|
-
//# sourceMappingURL=chunk-
|
|
226
|
+
//# sourceMappingURL=chunk-CFL4E4AW.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\n/** The slippage a KyberSwap quote is held to when the request names none, in bps: 0.5 %, the provider's own default. */\nexport const KYBER_DEFAULT_SLIPPAGE_BPS = 50;\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, within the slippage (default {@link KYBER_DEFAULT_SLIPPAGE_BPS}) and at or\n * 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 — the provider's default when the request names\n // none — never more slippage than that: without a default, a backend's minimum of one unit would pass.\n const bps = params.slippageBps ?? KYBER_DEFAULT_SLIPPAGE_BPS;\n if (!Number.isInteger(bps) || bps < 0 || bps >= 10_000) return notes.note(\"invalid slippage\", \"policy_refused\");\n if (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 // As the provider: the engine dry-runs the call from the account and sends it with a limit built on that estimate\n // (the build's gas, `venueGas`, as a floor), never a gas limit the backend quoted.\n ownGasEstimate: true,\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,YAAY,OAAO,UAAS;AAAA,EAC5D,IAAI,EAAC,MAAM,YAAY,MAAM,YAAY,OAAO,UAAS;AA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,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;AAAA;AAAA,EAGpB,gBAAgB;AAAA,EAChB,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-CFL4E4AW.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-DP4WDX4C.js.map
|