@kumbaya_xyz/smart-order-router
v4.22.42
Published
Kumbaya DEX Smart Order Router
Downloads
541
Readme

Kumbaya Smart Order Router
The Smart Order Router for Kumbaya DEX on MegaETH - the first real-time blockchain with 10ms block times.
This package finds the most efficient way to swap tokens by searching across multiple routes and considering gas costs.
Supported Networks
| Network | Chain ID | Status | |---------|----------|--------| | MegaETH Testnet | 6343 | ✅ Live | | MegaETH Mainnet | 4326 | 🔜 Coming Soon |
Installation
npm install @kumbaya_xyz/smart-order-routerQuick Start
import { AlphaRouter, ChainId } from '@kumbaya_xyz/smart-order-router';
import { ethers } from 'ethers';
const provider = new ethers.providers.JsonRpcProvider('https://carrot.megaeth.com');
const router = new AlphaRouter({
chainId: ChainId.MEGAETH_TESTNET,
provider,
});Contract Addresses (MegaETH Testnet)
| Contract | Address |
|----------|---------|
| UniswapV3Factory | 0x53447989580f541bc138d29A0FcCf72AfbBE1355 |
| SwapRouter02 | 0x8268DC930BA98759E916DEd4c9F367A844814023 |
| UniversalRouter | 0x7E6c4Ada91e432efe5F01FbCb3492Bd3eb7ccD2E |
| QuoterV2 | 0xfb230b93803F90238cB03f254452bA3a3b0Ec38d |
| NonfungiblePositionManager | 0x367f9db1F974eA241ba046b77B87C58e2947d8dF |
| Multicall | 0x0DC8eE7a1BcF659dC41B25669238688A816A051A |
| Multicall2 | 0xc638099246A98B3A110429B47B3F42CA037BC0a3 |
| WETH | 0x4200000000000000000000000000000000000006 |
Testing
Unit Tests
pnpm install
pnpm build
pnpm testIntegration Tests
Create a .env file with your RPC endpoint:
JSON_RPC_PROVIDER_MEGAETH_TESTNET = 'https://carrot.megaeth.com'Then run:
pnpm integ-testCLI Examples
MegaETH Testnet
Swap WETH to USDC:
./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0x75139A9559c9CD1aD69B7E239C216151D2c81e6f --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 6343Swap USDC to USDT:
./bin/cli quote --tokenIn 0x75139A9559c9CD1aD69B7E239C216151D2c81e6f --tokenOut 0x8E1eb0b74A0aC37abaa0f75C598A681975896900 --amount 100 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 6343Gas Configuration
MegaETH has unique gas characteristics due to its 10ms block times:
- Base swap cost: 80,000 gas
- Cost per initialized tick: 350,000 gas
- Cost per hop: 100,000 gas
- Blocks to live (cache): 360,000 blocks (~1 hour)
Measuring Gas Costs
To measure actual gas costs on MegaETH Testnet, run the gas measurement script:
npx ts-node scripts/measure-megaeth-gas.tsThis script:
- Connects to MegaETH Testnet RPC
- Scans for existing pools via PoolCreated events
- Measures gas for factory, pool, and quoter operations
- Reports gasEstimate values from QuoterV2 quotes
- Outputs recommended gas constants for the router
Related Packages
- @kumbaya_xyz/sdk-core - Core SDK with chain definitions
- @kumbaya_xyz/v3-sdk - V3 pool SDK with pool init code hash
- @kumbaya_xyz/router-sdk - Router SDK for swap encoding
- @kumbaya_xyz/universal-router-sdk - Universal Router SDK
Troubleshooting
ProviderGasLimit Errors
If you encounter gas limit errors, ensure your RPC provider has a high enough eth_call gas limit. The default configuration uses up to 150,000,000 gas per call.
For custom node configurations, you can lower the multicallChunk and gasLimitPerCall parameters when initializing the router.
License
GPL-2.0-or-later
