sfi-router-sdk
v0.1.12
Published
ABIs and chain deployments for the SFI modular router framework
Maintainers
Readme
sfi-router-sdk
ABIs and verified chain deployments for the SFI modular router framework. The package has no runtime dependencies and supports both ESM and CommonJS.
Install
npm install sfi-router-sdkImport an ABI
import { DynaRouterRegistryABI, MetaDynaRouterABI } from "sfi-router-sdk";Every production router and zapper ABI is available as <ContractName>ABI. They can also be selected dynamically:
import { contractAbis, getContractABI } from "sfi-router-sdk/abis";
const registryABI = getContractABI("DynaRouterRegistry");
const zapperABI = contractAbis.ERC4626DynaZapper;The generated DynaRoutePreviewerABI includes getBestPreviewFor(requester, tokenIn, amountIn, tokenOut), and router/zapper ABIs include isSwapAllowed(requester, tokenIn, tokenOut). This lets clients discard quotes that the requester cannot execute while keeping preview calls caller-independent.
Zap a native gas token into a vault
The Ethereum, Base, BNB Chain, and Arbitrum One VaultDynaZapper deployments support one-transaction native gas-token zaps. Request a quote with the native-token sentinel, then pass the previewer's returned router and swap data directly to swapNative:
import { Contract, utils } from "ethers";
import {
DynaRoutePreviewerABI,
VaultDynaZapperABI,
requireRoutePreviewerAddress,
} from "sfi-router-sdk";
const NATIVE_BNB = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
const amountIn = utils.parseEther("0.01");
const previewer = new Contract(
requireRoutePreviewerAddress(56),
DynaRoutePreviewerABI,
signer,
);
const quote = await previewer.getBestPreviewFor(
userAddress,
NATIVE_BNB,
amountIn,
dynBnbUSDCAddress,
);
const zapper = new Contract(quote.router, VaultDynaZapperABI, signer);
await zapper.swapNative(
NATIVE_BNB,
amountIn,
dynBnbUSDCAddress,
quote.amountOut.mul(99).div(100),
userAddress,
quote.swapData,
{ value: amountIn },
);Resolve a deployment
import {
ChainId,
erc4626ZapperAddresses,
getERC4626ZapperAddress,
getRoutePreviewerAddress,
getRouterRegistryAddress,
getVaultZapperAddress,
requireRoutePreviewerAddress,
requireERC4626ZapperAddress,
requireRouterRegistryAddress,
requireVaultZapperAddress,
routePreviewerAddresses,
routerRegistryAddresses,
vaultZapperAddresses,
} from "sfi-router-sdk/chains";
const baseRegistry = routerRegistryAddresses[ChainId.BASE];
const optimismRegistry = routerRegistryAddresses[ChainId.OPTIMISM];
const arbitrumRegistry = routerRegistryAddresses[ChainId.ARBITRUM];
const bnbRegistry = routerRegistryAddresses[ChainId.BNB];
const polygonRegistry = routerRegistryAddresses[ChainId.POLYGON];
const ethereumRegistry = routerRegistryAddresses[ChainId.ETHEREUM];
const basePreviewer = routePreviewerAddresses[ChainId.BASE];
const optimismPreviewer = routePreviewerAddresses[ChainId.OPTIMISM];
const arbitrumPreviewer = routePreviewerAddresses[ChainId.ARBITRUM];
const bnbPreviewer = routePreviewerAddresses[ChainId.BNB];
const polygonPreviewer = routePreviewerAddresses[ChainId.POLYGON];
const ethereumPreviewer = routePreviewerAddresses[ChainId.ETHEREUM];
const ethereumVaultZapper = vaultZapperAddresses[ChainId.ETHEREUM];
const baseVaultZapper = vaultZapperAddresses[ChainId.BASE];
const bnbVaultZapper = vaultZapperAddresses[ChainId.BNB];
const arbitrumVaultZapper = vaultZapperAddresses[ChainId.ARBITRUM];
const ethereumERC4626Zapper = erc4626ZapperAddresses[ChainId.ETHEREUM];
const bnbERC4626Zapper = erc4626ZapperAddresses[ChainId.BNB];
const polygonERC4626Zapper = erc4626ZapperAddresses[ChainId.POLYGON];
const baseERC4626Zapper = erc4626ZapperAddresses[ChainId.BASE];
const optimismERC4626Zapper = erc4626ZapperAddresses[ChainId.OPTIMISM];
const arbitrumERC4626Zapper = erc4626ZapperAddresses[ChainId.ARBITRUM];
// Returns undefined when the chain is not supported.
const optionalRegistry = getRouterRegistryAddress(chainId);
const optionalPreviewer = getRoutePreviewerAddress(chainId);
const optionalVaultZapper = getVaultZapperAddress(chainId);
const optionalERC4626Zapper = getERC4626ZapperAddress(chainId);
// Throws when the chain is not supported.
const registry = requireRouterRegistryAddress(chainId);
const previewer = requireRoutePreviewerAddress(chainId);
const vaultZapper = requireVaultZapperAddress(chainId);
const erc4626Zapper = requireERC4626ZapperAddress(chainId);Use the ABI and address with ethers:
import { Contract } from "ethers";
import {
DynaRouterRegistryABI,
requireRouterRegistryAddress,
} from "sfi-router-sdk";
const registry = new Contract(
requireRouterRegistryAddress(chainId),
DynaRouterRegistryABI,
provider,
);Or with viem:
import { getContract } from "viem";
import {
DynaRouterRegistryABI,
requireRouterRegistryAddress,
} from "sfi-router-sdk";
const registry = getContract({
address: requireRouterRegistryAddress(client.chain.id),
abi: DynaRouterRegistryABI,
client,
});Supported deployments
| Chain | Chain ID | DynaRouterRegistry | DynaRoutePreviewer | VaultDynaZapper | ERC4626DynaZapper |
| ------------ | -------: | -------------------------------------------- | -------------------------------------------- | -------------------------------------------- | -------------------------------------------- |
| Ethereum | 1 | 0xC6d8Ea820806A64ae098d3B236eeB8c220fe86bF | 0x514977eEa9265609fE31a5fD93A0195d4C57751B | 0x8A03B826244e8d344A9E1c0F194b77743a754D66 | 0x3479193a0Ac604413aaFBc1560109005cDC9e485 |
| Optimism | 10 | 0xB034c1C2796318aD0CF55127C63995D4449c58dC | 0x944c7EBA44C610E5C1Ff402EEe96D00d0aeE31e6 | — | 0x32eFfE073941a49f40d2E6b7272b943D27FcF60E |
| BNB Chain | 56 | 0x44856908217e0071E204d2C674E2B96476f7B49b | 0xC1a42fA3eE6280205e935445f5ed3a9a27EAC285 | 0x2Ffa552D0C41050D494d4A5b9cEf1763Ad4D4334 | 0x2bfb08260a46910e78CE62Be8F94f9f3f0049745 |
| Polygon PoS | 137 | 0x5C08A94707c3133e3a02221f3C3385323A8Bf689 | 0x1eD0ee7F20eB8dF53976A042fBae5e31bc249E54 | — | 0x585B4D33a3943c81582C97ef8904C4214be91AB6 |
| Base | 8453 | 0x82BccFF6E13a5B6e4D56E33a2079b009255D40f9 | 0xB3b08DD95c3c45f035d67c2502CD3Eb48A7f88C2 | 0xcd2E423F997DD44608B8663EAEa3b6e6De66dD36 | 0x8A1217655655e7D991Ab44403159BB070771be10 |
| Arbitrum One | 42161 | 0xaEC3200F5Ce5598e868BA6a769DbB11F45a65e69 | 0x2bB1608772f8e3c6b62032bE3db0938842941979 | 0x01A942023AB8eadC7C89Dd581ee9984742B5f60A | 0xcD45C864df59731100f2Dde7B04aB0403ab22da1 |
Only deployments verified against the compiled contract bytecode and expected registry configuration are included. Unsupported chains return undefined from non-throwing lookup functions.
Exported ABIs
AerodromeDynaRouterABIAerodromeV3CLDynaRouterABIBalancerV2RouterABIBaseDynaRouterABIConnectorDynaRouterABICurveDynaRouterABIDynaRoutePreviewerABIDynaRouterRegistryABIMetaDynaRouterABINativeDynaRouterABITokenWhitelistRegistryABIUniswapV2DynaRouterABIUniswapV3DynaRouterABIAerodromeDynaZapperABIBalancerV2DynaZapperABIBalancerV2MultiTokenDynaZapperABIERC4626DynaZapperABIVaultDynaZapperABI
