zrouter-sdk
v0.0.28
Published
sdk for integrating zrouter contracts
Downloads
134
Readme
zRouter SDK (TypeScript + viem)
A minimal scaffold for your multi-AMM router.
Installation
Install via npm:
npm install zrouter-sdkHighlights
- Approvals inference. Planner checks ERC-20 allowance and ERC-6909 operator status for
owner → routerand returns actions to perform. - Transient balance friendly. For multihop, intermediate legs use
to = router, final leg usesto = finalTo.
Quick start
import {
createDefaultPublicClient,
buildRoutePlan,
executeRoute,
mainnetConfig
} from 'zrouter-sdk';
import { parseUnits } from 'viem';
const publicClient = createDefaultPublicClient(process.env.RPC!, 1);
const owner = '0xYourEOA' as const;
const finalTo = owner;
const steps = [{
kind: 'V2',
tokenIn: { address: '0x0000000000000000000000000000000000000000' }, // ETH
tokenOut: { address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' }, // USDC
side: 'EXACT_IN',
amount: parseUnits('0.1', 18),
limit: 0n,
deadline: BigInt(Math.floor(Date.now()/1000) + 600)
} as const];
const plan = await buildRoutePlan({
publicClient,
owner,
router: mainnetConfig.router,
steps,
finalTo
});
// Prompt user to approve any plan.approvals (approve/setOperator), then:
const { request } = await executeRoute({
publicClient,
router: mainnetConfig.router,
account: owner,
calls: plan.calls,
value: plan.value
});Implemented
| From ↓ / To → | ETH | ERC20 | ERC6909 | | ------------- | ----------------------- | ----------------------------------- | ----------------------------------- | | ETH | — | ✅ ExactIn✅ ExactOut | ✅ ExactIn✅ ExactOut | | ERC20 | ✅ ExactIn✅ ExactOut | ✅ ExactIn✅ ExactOut | ✅ ExactIn✅ ExactOut | | ERC6909 | ✅ ExactIn✅ ExactOut | ✅ ExactOut✅ ExactIn¹ | ✅ ExactOut✅ ExactIn² |
