@anywalletkit/protocol-swap2-kyberswap 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,136 @@
1
- # Temporary Holding Version
1
+ # @anywalletkit/protocol-swap2-kyberswap
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ KyberSwap Aggregator as a same-chain swap2 provider: exact-input swaps routed by KyberSwap and settled through
4
+ MetaAggregationRouterV2 on 18 EVM chains — Ethereum, Base, BNB Smart Chain, Arbitrum, Optimism, Polygon, Avalanche,
5
+ Linea, Sonic, Berachain, Unichain, HyperEVM, Plasma, Monad, MegaETH, Robinhood Chain, Arc and Elysium.
6
+
7
+ Keyless (KyberSwap's public API) or with an API-gateway key. No integrator fee is charged.
8
+
9
+ ## Use
10
+
11
+ ```ts
12
+ import {kyberswapProvider} from '@anywalletkit/protocol-swap2-kyberswap'
13
+
14
+ const kyber = kyberswapProvider({
15
+ rpcUrls: {8453: ['https://…'], 999: ['https://…']}, // required to execute (simulation before signing) and for receipts
16
+ enabledChains: [8453, 999], // default: every chain in KYBER_CHAINS
17
+ clientId: 'my-wallet', // x-client-id and the build's `source` (written on-chain)
18
+ })
19
+ // in the router: new RouterSwap2Protocol(account, {fromChain, providers: [kyber, …]})
20
+ ```
21
+
22
+ Standalone: `new KyberswapSwap2Protocol(account, {fromChain: 'eip155:8453', rpcUrls})`.
23
+
24
+ Behind a backend: `remoteProvider({name: 'kyberswap', baseUrl, ...kyberPins})` in the app, so every quote the backend
25
+ returns is checked on the device against the pinned router and the app's own request.
26
+
27
+ | Option | Default | |
28
+ |---|---|---|
29
+ | `rpcUrls` | — | per chain id; without one, execution quotes on that chain are refused |
30
+ | `enabledChains` | all of `KYBER_CHAINS` | |
31
+ | `apiKey` | — | KyberSwap API-gateway key (`X-Api-Key`, `https://api.kyberswap.com/swap`); keep it on a server. With a key, `x-client-id` is not sent |
32
+ | `baseUrl` | public API | override the API base |
33
+ | `clientId` | `anywalletkit` | `x-client-id` (keyless only) and the build's `source` |
34
+ | `defaultSlippageBps` | 50 | KyberSwap accepts under 2000 |
35
+ | `quoteTtlMs` | 30 000 | how long a quote stays executable (the review fits; an approval mined meanwhile gets one re-quote) |
36
+ | `excludeRfqSources` | `true` | RFQ / private market makers quote for seconds only |
37
+ | `excludedSources` | — | KyberSwap source ids |
38
+
39
+ ## How a swap is checked
40
+
41
+ - A dry quote is `GET /routes`; an execution quote also calls `POST /route/build`. The route summary is sent back
42
+ untouched, with sender, recipient, slippage, a 20-minute deadline and `source` — never fee fields, `permit`,
43
+ `ignoreCappedSlippage` or `origin`.
44
+ - KyberSwap's build endpoint encodes whatever route summary it receives, fee entries and output amount included, so
45
+ nothing in its answer is trusted. `checkKyberTransaction` decodes the calldata strictly (re-encoded byte for byte)
46
+ and refuses unless:
47
+ - the target is MetaAggregationRouterV2 and the call is `swap()` (`swapGeneric`, `swapSimpleMode` and router V3 are
48
+ refused by name);
49
+ - the executor is the pinned AggregationExecutorProxy and the router approves nothing itself;
50
+ - input token and amount are the request's: a native input carries no split and `value` equal to the amount, a token
51
+ input's split adds up to the amount and sends no value;
52
+ - output token and receiver are the request's (never the zero address);
53
+ - the minimum is positive and at least the quote's minimum and the caller's floor;
54
+ - there are no fee receivers, no permit, and no flag but `0x200`.
55
+ - The quote's minimum is KyberSwap's own: `floor(amountOut × (1 − slippage)) − 1` (the build lands one unit under the
56
+ plain floor on every chain). `destAmount` is KyberSwap's `amountOut`, the route's ceiling: executed outputs come a few
57
+ basis points under it, and KyberSwap keeps any output above the quote.
58
+ - Every execution quote is simulated before the user pays for anything: a native input with a balance override; a
59
+ token input with its approval and the swap as one simulated block (`eth_simulateV1`), or as the plain call when the
60
+ allowance is already there — so a route that reverts never asks for an approval. A wallet without the input, or an
61
+ RPC without `eth_simulateV1` (Monad, Avalanche, HyperEVM on 2026-11-25), skips that early check
62
+ (`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. Gas is
64
+ the account's own estimate of the exact call (`ownGasEstimate`).
65
+ - Token inputs approve exactly the amount to the router (the engine default), spent in the same transaction.
66
+ - KyberSwap's own USD values of the input and the output (`amountInUsd` / `amountOutUsd`) reach the router's
67
+ `quoteValues` as `providerData.priceImpactBps` — the value lost to pool impact and pool fees — so a near-total loss
68
+ 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
+ Information only, never a refusal; a token KyberSwap does not price carries none.
70
+
71
+ ## Gas: `gasEstimate`
72
+
73
+ Every quote, dry or for execution, carries `gasEstimate` = KyberSwap's `routeSummary.gas` from `GET /routes` (asked
74
+ with `gasInclude=true`), `gasEstimateSource: "venue"`. It is there to compare routes (see protocol-swap2-core, "Gas:
75
+ `gasEstimate` vs `gasLimit`"): a dry quote has no transaction, so before this the router could only assume a gas limit
76
+ for it. Nothing in execution reads it: the swap still goes out with the account's own estimate of the exact call
77
+ (`ownGasEstimate`), and the transaction carries no gas limit. It counts the swap call only, no approval. A route that
78
+ states no gas (or 0) gives a quote without one.
79
+
80
+ What KyberSwap's figure is: its own model of the route's gas, not a simulation. The build answers the same number
81
+ (`gas` of `POST /route/build` equalled `routeSummary.gas` in all 16 recordings), and routine routes land on round model
82
+ values (330 498 for one Uniswap v3 or PancakeSwap v3 pool, 956 331 on two different chains). Against the gas the built
83
+ call used — 16 live routes recorded 2026-11-28 (`fixtures/quotes`) on Ethereum, Base, Arbitrum, Optimism, Polygon, BNB
84
+ Smart Chain, Linea, Sonic and Unichain for a throwaway sender = recipient, each built call run with `eth_simulateV1`
85
+ right after, at the chain's gas price (sender funded by a state override, a token input approved exactly in the same
86
+ simulated block; nothing sent):
87
+
88
+ | | Gas used ÷ `routeSummary.gas` |
89
+ |---|---|
90
+ | 16 routes | 0.58–1.85, median 0.73 |
91
+ | above the figure | 4 of 16: Linea Etherex CL 1.01, Polygon Ramses v3 + DODO 1.07, Sonic Metropolis LB 1.44, Base `kipseli-prop` 1.85 |
92
+
93
+ So it mostly runs high (the call used about three quarters of it at the median), and a proprietary-AMM route can run well over (how much gas such a pool
94
+ burns in a simulation need not be what it burns on-chain). The receiver held none of the output, so writing its first
95
+ balance is in these figures. On Arbitrum they are L2 execution gas without the L1 data component, which the router
96
+ leaves out too.
97
+
98
+ ## Router owner
99
+
100
+ `KYBER_CHAINS[id].build` names the router build on each chain, read on-chain:
101
+
102
+ - `generic` (Ethereum, Base, BNB Smart Chain, Arbitrum, Optimism, Polygon, Avalanche, Linea): the router has
103
+ `swapGeneric` and an owner-managed whitelist, so its owner (a single key on all but Linea) could make it spend an
104
+ allowance left on it. None is left: the approval is exact and spent by the swap itself, and revoked if the swap
105
+ does not go out. The engine's two approval options (protocol-swap2-core, "Approvals") would change that —
106
+ `revokeUnspentApproval: false` leaves an unspent approval in place, `allowanceReuse: "sufficient"` swaps from a
107
+ larger allowance the account already gave the router, which then stays — so the provider declares
108
+ `exactAllowanceOnly` for these chains (`kyberExactAllowanceOnly`, also in `kyberPins` for a remote stub): the
109
+ engine holds KyberSwap routes here to the defaults whatever the app set, the allowance exact and revoked when
110
+ unspent. A chain this module does not list counts as `generic` (fail closed).
111
+ - `lite` (every other chain): no `swapGeneric`, no whitelist. The approval options apply there as on any provider.
112
+
113
+ ## Limits
114
+
115
+ - Exact input only; same chain only; native ↔ wrapped is the Wrap provider's (not routed here).
116
+ - On Arc the native coin is refused (USDC with 18-decimal native accounting); swap its ERC-20.
117
+ - The public API allows 3 requests per second per IP, shared by everything behind that IP; dry routes for the same
118
+ request are reused for 5 seconds. A 429 is a `rate_limited` refusal and the router carries on without KyberSwap.
119
+ - Smart-account / EIP-7702 senders, fee-on-transfer and rebasing tokens are not supported.
120
+
121
+ ## Checked on mainnet
122
+
123
+ Base, 2026-11-24, one test wallet, through the engine (review → approval → preflight → send):
124
+
125
+ | Swap | Quoted | Received | Gas | Transaction |
126
+ |---|---|---|---|---|
127
+ | 0.000079 ETH → USDC (native value, no approval) | 0.133161 USDC (min 0.132494) | 0.133160 USDC | 239,155 | `0x989779e9…148fe7` |
128
+ | 1 USDC → ETH (exact approval, spent in the swap) | 0.000595564 ETH (min 0.000592587) | 0.000595540 ETH (−0.4 bps) | 305,229 + approval | `0xda5f2326…ba6dac` |
129
+
130
+ The router's USDC allowance was 0 after the token swap. `scripts/verify-mainnet.mjs` repeats it (`--send native|token`).
131
+
132
+ `scripts/verify-live.mjs` checks the contracts on every chain and builds (unsigned) one corridor each way per chain.
133
+
134
+ ## `blockNumber`
135
+
136
+ `QuoteParams.blockNumber` (one block for a comparison round) is not supported: the price comes from the KyberSwap Aggregator API, so the quote names no block (`Quote.blockNumber` absent).
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/activity.ts
21
+ var activity_exports = {};
22
+ __export(activity_exports, {
23
+ KYBERSWAP_MODULE: () => KYBERSWAP_MODULE,
24
+ describeKyberActivity: () => describeKyberActivity
25
+ });
26
+ module.exports = __toCommonJS(activity_exports);
27
+ var import_activity = require("@anywalletkit/protocol-swap2-core/activity");
28
+ var import_util2 = require("@anywalletkit/protocol-swap2-core/util");
29
+
30
+ // src/router.ts
31
+ var import_util = require("@anywalletkit/protocol-swap2-core/util");
32
+ var import_errors = require("@anywalletkit/protocol-swap2-core/errors");
33
+ var import_swap2_assets = require("@anywalletkit/swap2-assets");
34
+ var import_viem = require("viem");
35
+ var KYBER_ROUTER_V2 = "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5";
36
+ var KYBER_EXECUTOR = "0x8F10B468b06c6FD214B65F87778827F7D113f996";
37
+ var KYBER_ROUTER_V3 = "0x6868d319c8c9a78f7d39dc3602c5c917315132d7";
38
+ var KYBER_NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
39
+ var ZERO = "0x0000000000000000000000000000000000000000";
40
+ var KYBER_CHAINS = Object.freeze({
41
+ 1: { slug: "ethereum", name: "Ethereum", build: "generic" },
42
+ 8453: { slug: "base", name: "Base", build: "generic" },
43
+ 56: { slug: "bsc", name: "BNB Smart Chain", build: "generic" },
44
+ 42161: { slug: "arbitrum", name: "Arbitrum", build: "generic" },
45
+ 10: { slug: "optimism", name: "Optimism", build: "generic" },
46
+ 137: { slug: "polygon", name: "Polygon", build: "generic" },
47
+ 43114: { slug: "avalanche", name: "Avalanche", build: "generic" },
48
+ 59144: { slug: "linea", name: "Linea", build: "generic" },
49
+ 146: { slug: "sonic", name: "Sonic", build: "lite" },
50
+ 80094: { slug: "berachain", name: "Berachain", build: "lite" },
51
+ 130: { slug: "unichain", name: "Unichain", build: "lite" },
52
+ 999: { slug: "hyperevm", name: "HyperEVM", build: "lite" },
53
+ 9745: { slug: "plasma", name: "Plasma", build: "lite" },
54
+ 143: { slug: "monad", name: "Monad", build: "lite" },
55
+ 4326: { slug: "megaeth", name: "MegaETH", build: "lite" },
56
+ 4663: { slug: "robinhood", name: "Robinhood Chain", build: "lite" },
57
+ 5042: { slug: "arc", name: "Arc", build: "lite" },
58
+ 99901: { slug: "elysium", name: "Elysium", build: "lite" }
59
+ });
60
+ function kyberChain(chainId) {
61
+ return Object.prototype.hasOwnProperty.call(KYBER_CHAINS, chainId) ? KYBER_CHAINS[chainId] : void 0;
62
+ }
63
+ function kyberNativeSwaps(chainId) {
64
+ return !!(0, import_swap2_assets.ccAssetByToken)(`eip155:${chainId}`, ZERO);
65
+ }
66
+ var KYBER_ROUTER_ABI = (0, import_viem.parseAbi)([
67
+ "struct SwapDescriptionV2 { address srcToken; address dstToken; address[] srcReceivers; uint256[] srcAmounts; address[] feeReceivers; uint256[] feeAmounts; address dstReceiver; uint256 amount; uint256 minReturnAmount; uint256 flags; bytes permit; }",
68
+ "struct SwapExecutionParams { address callTarget; address approveTarget; bytes targetData; SwapDescriptionV2 desc; bytes clientData; }",
69
+ "function swap(SwapExecutionParams execution) payable returns (uint256 returnAmount, uint256 gasUsed)"
70
+ ]);
71
+ var KYBER_SWAP_SELECTOR = "0xe21fd0e9";
72
+ var KYBER_REFUSED_SELECTORS = Object.freeze({
73
+ "0x59e50fed": "swapGeneric",
74
+ "0x8af033fb": "swapSimpleMode"
75
+ });
76
+ var KYBER_FLAGS_ALLOWED = 0x200n;
77
+ var KyberTransactionError = class extends Error {
78
+ constructor(message) {
79
+ super(`kyberswap: ${message}`);
80
+ this.name = "KyberTransactionError";
81
+ }
82
+ };
83
+ var fail = (message, reason) => (0, import_errors.withReason)(new KyberTransactionError(message), reason);
84
+ var notes = (0, import_errors.refusalNotes)();
85
+ var isAddr = (a) => typeof a === "string" && /^0x[0-9a-fA-F]{40}$/.test(a);
86
+ var same = (a, b) => isAddr(a) && isAddr(b) && a.toLowerCase() === b.toLowerCase();
87
+ var routerToken = (t) => same(t, ZERO) ? KYBER_NATIVE : t;
88
+ var named = (a) => isAddr(a) ? a : "something that is not an address";
89
+ var MAX_CALLDATA_BYTES = 64 * 1024;
90
+ function checkKyberTransaction(tx, expected) {
91
+ const chain = kyberChain(expected.chainId);
92
+ if (!chain) throw fail(`chain ${expected.chainId} has no pinned KyberSwap router`, "unsupported_pair");
93
+ if (same(tx.to, KYBER_ROUTER_V3)) throw fail("Kyber router V3 not supported yet", "policy_refused");
94
+ if (!same(tx.to, KYBER_ROUTER_V2)) throw fail(`the transaction targets ${named(tx.to)}, not the KyberSwap router on ${chain.name}`, "vault_mismatch");
95
+ if (!isAddr(expected.receiver) || same(expected.receiver, ZERO) || same(expected.receiver, KYBER_ROUTER_V2) || same(expected.receiver, KYBER_EXECUTOR)) {
96
+ throw fail("invalid receiver", "recipient_mismatch");
97
+ }
98
+ const nativeIn = same(expected.tokenIn, ZERO), nativeOut = same(expected.tokenOut, ZERO);
99
+ 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");
100
+ if (same(expected.tokenIn, expected.tokenOut)) throw fail("same token in and out", "unsupported_pair");
101
+ if (expected.amountIn <= 0n || expected.minAmountOut <= 0n) throw fail("invalid quote amounts", "price_check_failed");
102
+ if (typeof tx.data !== "string" || !/^0x(?:[0-9a-fA-F]{2}){4,}$/.test(tx.data)) throw fail("malformed calldata", "policy_refused");
103
+ if (tx.data.length > 2 + 2 * MAX_CALLDATA_BYTES) throw fail("calldata is larger than any routed swap", "policy_refused");
104
+ const selector = tx.data.slice(0, 10).toLowerCase();
105
+ const refused = Object.prototype.hasOwnProperty.call(KYBER_REFUSED_SELECTORS, selector) ? KYBER_REFUSED_SELECTORS[selector] : void 0;
106
+ if (refused) throw fail(`the transaction calls ${refused}, which this module never uses`, "policy_refused");
107
+ if (selector !== KYBER_SWAP_SELECTOR) throw fail("not a router swap() call", "policy_refused");
108
+ let x;
109
+ try {
110
+ const call = (0, import_viem.decodeFunctionData)({ abi: KYBER_ROUTER_ABI, data: tx.data });
111
+ x = call.args[0];
112
+ const again = (0, import_viem.encodeFunctionData)({ abi: KYBER_ROUTER_ABI, functionName: "swap", args: [x] });
113
+ if (again.toLowerCase() !== tx.data.toLowerCase()) throw new Error("non-canonical");
114
+ } catch {
115
+ throw fail("the calldata is not a canonical router swap() encoding", "policy_refused");
116
+ }
117
+ const d = x.desc;
118
+ if (!same(x.callTarget, KYBER_EXECUTOR)) throw fail(`the swap runs through ${named(x.callTarget)}, not the pinned KyberSwap executor`, "vault_mismatch");
119
+ if (!same(x.approveTarget, ZERO)) throw fail("the swap asks the router to approve another contract", "policy_refused");
120
+ if (!same(d.srcToken, routerToken(expected.tokenIn)) || !same(d.dstToken, routerToken(expected.tokenOut))) throw fail("calldata swaps other tokens than requested", "policy_refused");
121
+ if (d.amount !== expected.amountIn) throw fail(`calldata spends ${d.amount}, not ${expected.amountIn}`, "price_check_failed");
122
+ if (d.srcReceivers.length !== d.srcAmounts.length) throw fail("malformed input split", "policy_refused");
123
+ if (nativeIn) {
124
+ if (d.srcReceivers.length !== 0) throw fail("a native-coin swap must not split the input", "policy_refused");
125
+ if (tx.value !== expected.amountIn) throw fail("native value does not match the input", "price_check_failed");
126
+ } else {
127
+ if (tx.value !== 0n) throw fail("a token swap must not send the native coin", "price_check_failed");
128
+ const total = d.srcAmounts.reduce((s, a) => s + a, 0n);
129
+ if (total !== expected.amountIn) throw fail(`the input split adds up to ${total}, not ${expected.amountIn}`, "price_check_failed");
130
+ }
131
+ if (same(d.dstReceiver, ZERO)) throw fail("the swap names no receiver", "recipient_mismatch");
132
+ if (!same(d.dstReceiver, expected.receiver)) throw fail(`calldata pays ${named(d.dstReceiver)}, not ${expected.receiver}`, "recipient_mismatch");
133
+ if (d.minReturnAmount <= 0n) throw fail("the swap names no minimum", "price_check_failed");
134
+ if (d.minReturnAmount < expected.minAmountOut) throw fail(`calldata guarantees ${d.minReturnAmount}, under the quoted minimum ${expected.minAmountOut}`, "price_check_failed");
135
+ if (d.feeReceivers.length !== 0 || d.feeAmounts.length !== 0) throw fail("calldata pays a fee receiver \u2014 this module charges none", "policy_refused");
136
+ 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");
137
+ if (d.permit !== "0x") throw fail("calldata carries a permit", "policy_refused");
138
+ return { srcToken: d.srcToken, dstToken: d.dstToken, dstReceiver: d.dstReceiver, amount: d.amount, minReturnAmount: d.minReturnAmount, flags: d.flags };
139
+ }
140
+ function kyberMinimum(amountOut, bps) {
141
+ const m = amountOut * BigInt(1e4 - bps) / 10000n - 1n;
142
+ return m > 0n ? m : 0n;
143
+ }
144
+ var chainIdOf = (caip2) => /^eip155:[0-9]+$/.test(caip2) ? Number(caip2.slice(7)) : NaN;
145
+ function kyberVerifyQuote(params, quote) {
146
+ if (params.sourceChain !== params.destChain) return notes.note("same-chain swaps only", "unsupported_pair");
147
+ try {
148
+ const chainId = chainIdOf(params.sourceChain);
149
+ if (!kyberChain(chainId)) return notes.note(`no pinned KyberSwap router on ${params.sourceChain}`, "unsupported_pair");
150
+ const src = (0, import_util.sourceAssetOf)(params);
151
+ if (!src) return notes.note(`unknown source token ${params.sourceToken}`, "unsupported_pair");
152
+ if (quote.sourceAmount !== params.amountIn) return notes.note("the quote prices another amount", "price_check_failed");
153
+ const min = BigInt(quote.minDestAmount), out = BigInt(quote.destAmount);
154
+ if (min <= 0n || min > out) return notes.note("invalid quote amounts", "price_check_failed");
155
+ 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 (bps !== void 0 && Number.isInteger(bps) && bps >= 0 && bps < 1e4 && min < kyberMinimum(out, bps)) {
158
+ return notes.note("the quote's minimum allows more slippage than requested", "price_check_failed");
159
+ }
160
+ const tx = quote.txRequest;
161
+ if (!tx) return params.dry === false ? notes.note("the quote carries no router transaction", "policy_refused") : null;
162
+ if (!tx.to || !tx.data) return notes.note("the quote carries no router transaction", "policy_refused");
163
+ if (tx.approvalAddress !== void 0 && !same(tx.approvalAddress, KYBER_ROUTER_V2)) return notes.note("the quote asks to approve another spender", "vault_mismatch");
164
+ checkKyberTransaction({ to: tx.to, data: tx.data, value: BigInt(tx.value ?? "0") }, {
165
+ chainId,
166
+ tokenIn: src.contract ? (0, import_viem.getAddress)(src.contract) : ZERO,
167
+ tokenOut: /^0x0+$/.test(params.destToken) ? ZERO : (0, import_viem.getAddress)(params.destToken),
168
+ amountIn: BigInt(params.amountIn),
169
+ receiver: (0, import_viem.getAddress)(params.destAddress),
170
+ minAmountOut: min
171
+ });
172
+ return null;
173
+ } catch (e) {
174
+ const text = e instanceof Error ? e.message.replace(/^kyberswap: /, "") : String(e);
175
+ const info = (0, import_errors.refusalOf)(e);
176
+ return info ? notes.note(text, info) : text;
177
+ }
178
+ }
179
+ function routerFor(chain) {
180
+ return kyberChain(chainIdOf(chain)) ? [KYBER_ROUTER_V2] : [];
181
+ }
182
+ function kyberExactAllowanceOnly(chain) {
183
+ return kyberChain(chainIdOf(chain))?.build !== "lite";
184
+ }
185
+ var kyberPins = Object.freeze({
186
+ callTargets: routerFor,
187
+ spenders: routerFor,
188
+ exactAllowanceOnly: kyberExactAllowanceOnly,
189
+ verifyQuote: kyberVerifyQuote,
190
+ reasonOf: (refusal) => notes.reasonOf(refusal)
191
+ });
192
+
193
+ // src/activity.ts
194
+ var KYBERSWAP_MODULE = "@anywalletkit/protocol-swap2-kyberswap";
195
+ function describeKyberActivity(tx, ctx) {
196
+ if (!(0, import_util2.isEvm)(tx.chain) || !kyberChain((0, import_util2.evmRef)(tx.chain))) return null;
197
+ if (!(0, import_activity.matchesCall)(tx, [KYBER_ROUTER_V2], [KYBER_SWAP_SELECTOR])) return null;
198
+ return (0, import_activity.describeSwapLike)(tx, ctx, { protocol: KYBERSWAP_MODULE, subtitle: `KyberSwap \xB7 ${(0, import_activity.chainLabel)(tx.chain)}`, kind: "swap" });
199
+ }
200
+ //# sourceMappingURL=activity.cjs.map
@@ -0,0 +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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IAChB,CAAC;AACD,WAAO;AAAA,EACT,SAAS,GAAG;AACV,UAAM,OAAO,aAAa,QAAQ,EAAE,QAAQ,QAAQ,gBAAgB,EAAE,IAAI,OAAO,CAAC;AAClF,UAAM,WAAO,yBAAU,CAAC;AACxB,WAAO,OAAO,MAAM,KAAK,MAAM,IAAI,IAAI;AAAA,EACzC;AACF;AAEA,SAAS,UAAU,OAAkC;AACnD,SAAO,WAAW,UAAU,KAAK,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC;AAC7D;AASO,SAAS,wBAAwB,OAAwB;AAC9D,SAAO,WAAW,UAAU,KAAK,CAAC,GAAG,UAAU;AACjD;AAOO,IAAM,YAAwB,OAAO,OAAO;AAAA,EACjD,aAAa;AAAA,EACb,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,aAAa;AAAA,EACb,UAAU,CAAC,YAAoB,MAAM,SAAS,OAAO;AACvD,CAAC;;;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"]}
@@ -0,0 +1,11 @@
1
+ import { ChainTx, DescribeActivityContext, ActivityItem } from '@anywalletkit/core';
2
+
3
+ /**
4
+ * Activity recognition for KyberSwap: a `swap()` call to MetaAggregationRouterV2 on a chain the module serves →
5
+ * `swap`, "Swapped A → B" from the owner's net transfers.
6
+ */
7
+
8
+ declare const KYBERSWAP_MODULE = "@anywalletkit/protocol-swap2-kyberswap";
9
+ declare function describeKyberActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null;
10
+
11
+ export { KYBERSWAP_MODULE, describeKyberActivity };
@@ -0,0 +1,11 @@
1
+ import { ChainTx, DescribeActivityContext, ActivityItem } from '@anywalletkit/core';
2
+
3
+ /**
4
+ * Activity recognition for KyberSwap: a `swap()` call to MetaAggregationRouterV2 on a chain the module serves →
5
+ * `swap`, "Swapped A → B" from the owner's net transfers.
6
+ */
7
+
8
+ declare const KYBERSWAP_MODULE = "@anywalletkit/protocol-swap2-kyberswap";
9
+ declare function describeKyberActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null;
10
+
11
+ export { KYBERSWAP_MODULE, describeKyberActivity };