@anywalletkit/protocol-swap2-curve
@anywalletkit/protocol-swap2-curve
Section titled “@anywalletkit/protocol-swap2-curve”Curve same-chain swaps as a swap2 module, straight from the contracts: the router’s own
get_dy quotes and its exchange executes, on the Router NG deployments in src/deployments.ts, over a curated pool
allowlist the package pins. No API on the money path, no key, no fee. Standalone through CurveSwap2Protocol, or as one
provider of the router.
Chains (18): Ethereum (router v1.2), Arbitrum, Base, OP Mainnet, Polygon, Gnosis, Avalanche, BNB Chain — the [5][5]
routers; Sonic, Unichain, HyperEVM, Mantle, Monad, Plasma, Robinhood Chain (v1.1.1), Ink, X Layer, Plume — the [4][5]
routers, which drive NG pools only. A chain is offered when it has a pinned router, allowlisted pools and an RPC: today
Ethereum, Arbitrum, Base, OP Mainnet, Gnosis, Monad, Plasma and X Layer (the generated allowlist has no pool that
passes the rules on the others; module.json lists only the chains offered).
Install
Section titled “Install”npm install @anywalletkit/protocol-swap2-curve @anywalletkit/core# or: pnpm add @anywalletkit/protocol-swap2-curve @anywalletkit/core · yarn add @anywalletkit/protocol-swap2-curve @anywalletkit/coreOn npm: @anywalletkit/protocol-swap2-curve, published from the release workflow with provenance.
Configure
Section titled “Configure”import { curveProvider } from '@anywalletkit/protocol-swap2-curve'
const curve = curveProvider({ rpcUrls: { 1: ['https://eth.example/rpc'], 42161: ['https://arb.example/rpc'] },})| Option | Default | Meaning |
|---|---|---|
rpcUrls |
— | { chainId: [url…] }, tried in order. Quotes, preflight and receipts. A chain without one is not offered. A batch an endpoint answers only in part (a rate-limit element such as QuickNode’s -32007, a node fault) goes to the next one, once more after a 1 s pause when the last refusal was for the request rate, and then refuses as no RPC answered on chain N; only a revert counts as an answer. |
defaultSlippageBps |
auto | Used when the caller passes none. Default: swap2-core’s suggestSlippage for the pair and the route’s price impact (stable ↔ stable 10 bps, majors 50, others 100, plus half the impact). |
quoteTtlMs |
180000 |
The only expiry: Router NG has no deadline. Long enough for an approval to be mined on Ethereum. |
onWarning |
console.warn |
Told when a chain’s AddressProvider lists another router than the pinned one (never acted on). |
deployments, pools |
shipped tables | Overrides for tests. |
How a swap is built
Section titled “How a swap is built”- Routes come only from the allowlist (
src/pools/, generated byscripts/build-allowlist.mjsfrom Curve’s pool lists, checked on-chain — coins by address, code hash, TVL and age thresholds — and reviewed in the diff; seescripts/README-allowlist.md). One or two pools per route. A token the route hands the swap through between two pools must be listed in the swap2-assets catalog on that chain (by address), or be the native coin or the pinned wrapped native; the source and destination follow the engine’s listed / unlisted policy, and a pool’s other coins, which the route does not touch, may be anything the allowlist admitted.exchange_underlyingruns only on a metapool whose base pool is in the allowlist too (never on a lending pool). The router’s own pseudo-hops are added: swap_type 8 between the native coin and the pinned wrapped native, and on Ethereum’s v1.2 router swap_type 9 between crvUSD and scrvUSD (ERC-4626). Never type 9 on a v1.1 or[4][5]router, and[4][5]routers only drive pool types 10/20/30 (NG). Refused whatever a list says: the registered fake-USDT pool, the four pools drained in 2023 (alETH, pETH, msETH, CRV/ETH), the Iron Bank lending pool (cyDAI/cyUSDC/cyUSDT) and Polygon amWBTC/renBTC. - Quotes are the router’s
get_dyfor every candidate (at most 30, JSON-RPC batches of at most 10); the best output wins. Price impact comes from a probe at 1/1000 of the amount on the same route. - Execution is the explicit-receiver
exchange—0xc872a3c5([5][5], zero_pools) or0xfd44959c([4][5]) — paying the recipient, withmin_dyfrom the slippage (never 0; a caller’sminAmountOutfloor is refused when the minimum is below it). A native input is sent as exactly thatvalue; an ERC-20 input approves exactly the input to the pinned router (the engine resets USDT to 0 first) and sends no value. The router call carries no gas limit: the wallet estimates the exact call (with headroom) right before broadcast, after any approval — a per-step formula ran some routes out of gas and overcharged where the limit is what is paid (Monad). - Before use, once per chain, the router’s runtime code hash and
version()are checked against the pins. The chain’s AddressProvider is only compared (its id 2 may change at its admin’s will) — a difference is a warning, the pinned router is still used. - Right before broadcast (
preflightDeposit): the transaction is byte for byte the quoted call; the route passes the same rules again; every hop pool’s code and coins are re-read and must still be the pinned ones; and a freshget_dyof the exact route still pays at least the minimum. The router’s code hash and version are not re-read here: they are checked once per chain per process (above), and the router is immutable. Anything else refuses with the reason.
Router NG approves each pool it meets for the maximum from its own balance; that touches only what is in transit through the router, never the user’s allowance, which is exact and spent in the same transaction. The router also sweeps any dust it holds into the output (a few wei at most).
Ethereum and MEV. min_dy caps what a sandwich can take at the slippage; it does not stop one from taking up to
that. Keep the default (small) slippage on stable pairs and send Ethereum swaps through an MEV-protected RPC (a private
transaction relay) where the app can. Other chains in the list have sequencers or much less public-mempool exposure.
The ERC-4626 hop. For crvUSD → scrvUSD the router’s get_dy uses convertToShares, which can sit a hair above
what deposit mints (2026-11-05: 2 × 10⁻⁸ on 1 000 crvUSD); the minimum covers it.
Gas estimate (gasEstimate)
Section titled “Gas estimate (gasEstimate)”The quote still carries no gas limit (above). It does say what the exchange is expected to use, for ranking:
protocol-swap2-core’s gasEstimate with gasEstimateSource: "model" — gas used, not a limit, no approval (whoever
prices the route adds that). get_dy measures no gas, so the figure comes from a measured table (src/gas.ts,
exported as CURVE_GAS_BASE / CURVE_STEP_GAS, and curveGasEstimateOfCall for router arguments read back from a
call): a base for the call — the intrinsic 21,000, the calldata, the router, the input’s transferFrom and the payout
— plus one cost per step. Nothing in execution reads it.
| Step | Gas |
|---|---|
| base (every route) | 92,500 |
t1/2 stable, 2 coins |
94,600 |
t1/3 stable, 3 coins (3pool) |
104,700 |
t1/4 stable, 4 coins |
99,600 |
t1/4u stable metapool, exchange_underlying over 4 coins |
239,000 |
t2/2 twocrypto |
225,500 |
t3/3 tricrypto |
252,600 |
t10/2 stable-ng, 2 coins |
128,300 |
t10/3u stable-ng metapool, underlying over 3 coins |
182,000 |
t20/2 twocrypto-ng |
178,500 |
t30/3 tricrypto-ng |
143,000 |
wrap native ↔ wrapped native (swap_type 8) |
19,200 |
4626 crvUSD ↔ scrvUSD (swap_type 9) |
50,300 |
How it was measured (read-only, 2026-11-28; scripts and raw results kept outside the repo): every exchange sent
straight to the pinned router in the last 250,000 blocks on Ethereum and over several days on Arbitrum, Base, OP
Mainnet and Plasma, read from the router’s Exchange logs; of those, the 763 along routes this module builds
(checkRoute passes over the shipped allowlist), with their receipts’ gasUsed (on Arbitrum less gasUsedForL1, the L1
component); plus the module’s own quotes on 24 pairs simulated with eth_simulateV1 from a funded account
([approve(router, exactly the input), exchange]), each to a recipient holding none of the output and to one holding
some (the midpoint counted: a first receipt of a token costs ~17,100 more). The table is a least-squares fit of those,
Huber-weighted against outliers.
How far off it is: on the 763 real transactions, median 4.1% of their gasUsed, 9 in 10 within 11.1%, the worst
38.6% (bias +0.2%); per chain — Ethereum (612) median 4.1%, Arbitrum (88) 3.5%, Base (56) 1.1%, Plasma (5) 4.7%, OP
(2) 13.0%. fixtures/gas/receipts-2026-11-28.json holds 76 of them (public calldata and gasUsed, sampled by route
shape, one per sender), and tests/gas-estimate.test.ts holds the table to them: median 5.6%, 9 in 10 within 11.6%,
worst 31.4%. What moves a real swap off the table is the pool’s coins (stETH and USDT0 cost more to move than USDC,
3pool’s old code less than stable-ng’s) and the recipient’s balance.
Where it is set: Ethereum, Arbitrum, Base, OP Mainnet and Plasma (CURVE_GAS_CHAINS), on routes whose every step
has a cost above. Left out, never guessed: a route through a stable-ng pool of three coins swapped directly (t10/3:
one pool each on Ethereum and Base, no transaction to measure); Monad (another gas schedule, and its receipts report
the gas limit rather than the gas used); X Layer (two simulated quotes ran 6% and 27% above the table); Gnosis (no
transaction and no quote to measure); every other chain.
Behind remoteProvider
Section titled “Behind remoteProvider”When the provider runs on your server, spread its pins into the app’s stub:
remoteProvider({name: "curve", baseUrl, ...curvePins}). The engine then lets the EVM route call and approve only the
pinned Router NG, and curveVerifyQuote opens the router call on the device against the app’s own request: the
explicit-receiver exchange, exactly the input, the destination token, the quote’s minimum (never 0), paid to the
recipient, no zap pools, and a route through allowlisted pools only — synchronous, from the shipped tables. For the
build checked on chain as well, use remoteProvider({name: "curve", baseUrl, ...curveRemotePins({rpcUrls})}): over
the app’s RPCs it checks the router (code hash and version, once per chain), each hop pool’s code and coins, and a
fresh get_dy of the exact route ≥ the minimum. It then holds the backend’s figures to that fresh get_dy, so the
minimum is the device’s own: the quote’s output may sit at most the slippage above it, and min_dy at most the
slippage below it (or below the quoted output, if lower). The slippage is the request’s slippageBps; without one,
the defaultSlippageBps you pass (set it to the backend provider’s, if it sets one); without that, the provider’s auto
slippage re-derived on the device from a fresh 1/1000 probe, plus CURVE_AUTO_SLIPPAGE_DRIFT_BPS (5) for the impact
moving between quote and build. A backend that names min_dy = 1 or an inflated output is refused at build time. Each
quote carries its own intent id (curve:<chainId>:<nonce>), so a build is checked against the request it answered.
Quoting at one block (blockNumber)
Section titled “Quoting at one block (blockNumber)”QuoteParams.blockNumber (0.2.0; a decimal block of the source chain, read by the app once per comparison round):
every get_dy of the quote, the candidate routes and the 1/1000 impact probe, goes to that block, and the quote names
it (Quote.blockNumber; the provider declares honorsBlockNumber: true). The routes come from the pinned allowlist as
always. At “latest” whatever it says: the router’s code hash and version check, the AddressProvider read,
preflightDeposit (the sealed call, each hop pool’s code and coins and a fresh get_dy right before signing) and
curveRemotePins’ verifyBuild on the device, which hold a remote quote to the pools’ price now.
A node that does not have the block (“header not found”, “block not found”, a null result, X Layer’s and Celo’s HTTP
400 “block is out of range”) or no longer keeps its state (“missing trie node”, publicnode’s HTTP 403 for archive
state) fails its endpoint: the next one is asked, every endpoint once more after a second, then the quote is refused
as stale_node, the block named: “curve: no RPC answered on chain 1 (block 26510020 is not served by the node (header
not found))”. It is never priced at “latest” instead.
Every chain of the module takes a block number, except HyperEVM: its RPCs answer an eth_call at any block number
from their head (one 100,000 blocks ahead too, 2026-11-28). It is in CURVE_LATEST_ONLY_CHAINS ([999]): there a
request’s blockNumber is not honoured, the quote is read at “latest” and names no block. Pass blockNumber in the
comparison round only (latest, or latest − 1 on fast chains whose nodes trail), not on the execution re-quote. Without
it every request is 0.1.10’s, byte for byte (tests/block-number.test.ts against fixtures/unpinned-0.1.10.json).
Activity
Section titled “Activity”describeActivity(tx, ctx) recognizes a call into the chain’s pinned Router NG — and Ethereum’s older v1.1
(0x16C6…5353) and v1.0 (0xF0d4…8b8D) routers, for history — with one of the family’s exchange entry points
([5][5]: 0x371dc447, 0x5c9c18e2, 0xc872a3c5; [4][5]: 0xaad348a2, 0xfd44959c) as swap, “Swapped A → B”
from the owner’s net transfers. Subtitle Curve · <chain>, counterparty = the router. When the receiver (the calldata’s
_receiver, else the router’s Exchange log) is not one of the owner’s addresses, the subtitle ends in
· paid to 0x… and the receiver is the counterparty. curveKnownContracts(chainId) gives tx-preview its labels.
Fixtures (fixtures/activity/, public transactions captured with scripts/capture-fixtures.mjs, 2026-11-05): Ethereum
v1.2 CRV → crvUSD (0x5c9c18e2), Plasma [4][5] WXPL → XPL (0xaad348a2); negatives: a Uniswap SwapRouter02 swap, a
WETH9 deposit.
Live check
Section titled “Live check”node scripts/verify-live.mjs [chainId,…] (after pnpm build): per chain the router’s code hash, version, wrapped
native and ABI family against the pins, every allowlisted pool through the preflight’s own code and coins check
(curveOnChain(…).checkPools), then up to three quotes from the allowlist, each simulated with eth_call as a dummy
wallet funded by a state override (balance and router allowance); the router’s return must reach the minimum.
Then block numbers: an eth_call at head − 2 must answer that block’s own number and one at head + 100,000 must be
refused (a node that ignores the tag answers both from its head; HyperEVM, in CURVE_LATEST_ONLY_CHAINS, is reported
so), and the first quote again at head − 1 must name that block. Read-only, nothing signed.
Classes
Section titled “Classes”Interfaces
Section titled “Interfaces”- CurveChainPools
- CurveDeployment
- CurveOnChainOptions
- CurvePool
- CurveProviderConfig
- CurveRemotePinsOptions
- CurveRoute
- CurveSwap2Config
- CurveTables
- DecodedExchange
- RouterArgs
Type Aliases
Section titled “Type Aliases”Variables
Section titled “Variables”- ADDRESS_PROVIDER_ABI
- COINS_INT
- COINS_UINT
- CRVUSD_ETHEREUM
- CURVE_AUTO_SLIPPAGE_DRIFT_BPS
- CURVE_DENIED_POOLS
- CURVE_DEPLOYMENTS
- CURVE_ETH
- CURVE_GAS_BASE
- CURVE_GAS_CHAINS
- CURVE_LATEST_ONLY_CHAINS
- CURVE_LEGACY_ROUTERS
- CURVE_MODULE
- CURVE_POOLS
- CURVE_STEP_GAS
- curvePins
- curveVerifyQuote
- EXCHANGE_SELECTOR
- EXCHANGE_TOPIC
- GET_DY_SELECTOR
- MAX_QUOTE_CANDIDATES
- MAX_ROUTE_POOLS
- MAX_ROUTE_STEPS
- ROUTER_LITE4_ABI
- ROUTER_NG5_ABI
- ROUTER_SELECTORS
- SCRVUSD
- VERSION_ABI
- ZERO_ADDRESS
Functions
Section titled “Functions”- chainIdOf
- checkRoute
- curveGasEstimate
- curveGasEstimateOfCall
- curveKnownContracts
- curveOnChain
- curveProvider
- curveQuoteCheck
- curveRemotePins
- curveStepKind
- decodeExchange
- deploymentOf
- describeCurveActivity
- encodeExchange
- encodeGetDy
- findRoutes
- intermediateAllowed
- poolIndex
- poolTypeAllowed
- routeArgs
- routePools
- underlyingAllowed
References
Section titled “References”default
Section titled “default”Renames and re-exports CurveSwap2Protocol