Programmatic access to flat-fee routing on Base. Free, no key required.
Endpoints are served from https://guave.trade and proxy KyberSwap aggregation (chains 8453, 42161, 1, 10). To execute through Guave and pay the flat fee instead of calling the KyberSwap router directly, the returned calldata is passed to the GuaveRouter contract - see the full example below.
Returns the expected output amount for a swap.
Parameters: src source token address (e.g. 0x833589... for USDC) dst destination token address amount amount in the token's smallest unit (wei; 6 decimals for USDC) Response: dstAmount expected output in destination token's smallest unit
curl "https://guave.trade/api/quote?src=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&dst=0x4200000000000000000000000000000000000006&amount=1000000"
Returns the optimal route and the KyberSwap calldata for it. All parameters are query strings.
Parameters: src, dst, amount same as /api/quote from address that will hold the tokens when the router executes - use the GuaveRouter address (0x94583743e729377367ccF6B7cC5a973A62be9e99) slippage e.g. 1 (percent) disableEstimate true (required when from is a contract) Response: dstAmount expected output amount tx.data KyberSwap calldata - pass this to GuaveRouter.swap() tx.to / tx.gas KyberSwap router (0x6131B5fae19EA4f9D964eAc0408E4408b66337b5) + gas
curl "https://guave.trade/api/swap?src=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&dst=0x4200000000000000000000000000000000000006&amount=1000000&from=0x94583743e729377367ccF6B7cC5a973A62be9e99&slippage=1&disableEstimate=true"
The calldata from /api/swap is executed by calling swap() on GuaveRouter v7 (0x94583743e729377367ccF6B7cC5a973A62be9e99, Base):
function swap( address router, // KyberSwap MetaRouter: 0x6131B5fae19EA4f9D964eAc0408E4408b66337b5 address srcToken, uint256 srcAmount, address dstToken, uint8 tier, // fee tier 0-8 by trade USD value bytes swapCalldata // tx.data from /api/swap ) payable
The fee tier must match the trade's USD value and is paid as msg.value in ETH:
| Tier | Trade size (USD) | Fee |
|---|---|---|
| 0 | under $1,000 | $0.01 |
| 1 | $1,000 - $10,000 | $0.99 |
| 2 | $10,000 - $100,000 | $2.99 |
| 3 | $100,000 - $1,000,000 | $9.99 |
| 4 | $1,000,000 - $5,000,000 | $29.99 |
| 5 | $5,000,000 - $10,000,000 | $99.99 |
| 6 | $10,000,000 - $50,000,000 | $199.99 |
| 7 | $50,000,000 - $100,000,000 | $499.99 |
| 8 | over $100,000,000 | $999.99 |
import { ethers } from "ethers";
const wallet = new ethers.Wallet(process.env.KEY, new ethers.JsonRpcProvider("https://mainnet.base.org"));
const USDC = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
const WETH = "0x4200000000000000000000000000000000000006";
const GUAVE = "0x94583743e729377367ccF6B7cC5a973A62be9e99";
const ONEINCH = "0x111111125421cA6dc452d289314280a0f8842A65";
const amount = ethers.parseUnits("100", 6); // 100 USDC, tier 0
// approve GuaveRouter once
const usdc = new ethers.Contract(USDC, ["function approve(address,uint256)"], wallet);
await (await usdc.approve(GUAVE, amount)).wait();
// get KyberSwap calldata routed to the Guave contract
const { tx } = await fetch(
`https://guave.trade/api/swap?src=${USDC}&dst=${WETH}&amount=${amount}&from=${GUAVE}&slippage=1&disableEstimate=true`
).then((r) => r.json());
// execute: tier 0 fee is $0.01 ~ 6e12 wei at $1700 ETH (whitelisted wallets send 0)
const guave = new ethers.Contract(GUAVE,
["function swap(address,address,uint256,address,uint8,bytes) payable returns (uint256)"], wallet);
const sent = await guave.swap(ONEINCH, USDC, amount, WETH, 0, tx.data, { value: 6_000_000_000_000n });
await sent.wait();
console.log("swapped:", sent.hash);