Integration Guide (onchain quoting)

Two modes of integration are possible. Onchain quoting - described in this guide, and offchain state syncing and simulation. While the former is trivial to implement, the latter is better suited for Nabla's High Frequency Pricing engine and will result with greater volumes and revenues over time.

If you are new to Nabla, we recommend you start with the Developer overview section first and explore our Nabla Swap API for reference.

We will go through the steps to discover pools and get an on-chain swap quote and show you how to execute a swap via NablaPortal contract.


1. Pool Discovery

ABI

  1. Fetch available routers Portal.getRouters() → returns all supported routers.

    function getRouters() external view returns (address[] memory routers)
  2. Get pools and assets of router Portal.getRouterPools(router) → returns assets and pools supported by that router.

       function getRouterPools(address router) external view returns (address[] memory assets, address[] memory pools)

Note that currently (and in the forseeable future) we are deploying a single router only.

Ethers.js example

import { ethers } from "ethers";

const portalAddress = process.env.PORTAL_ADDRESS;

const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);

const portalAbi = [
  "function getRouters() external view returns (address[])",
  "function getRouterPools(address router) external view returns (address[])"
];

const portal = new ethers.Contract(
  portalAddress,
  portalAbi,
  provider
);

async function discoverPools() {
  const routers = await portal.getRouters();
  console.log("Routers:", routers);

  const pools = await portal.getRouterPools(routers[0]);
  const [poolAddresses, assetAddresses] = pools;
  console.log("Pools and assets for router 0:");
  poolsAddresses.forEach((pool, i) => {
    console.log("Pool:", pool, "Asset:", assetAddresses[i])
  })

  return {router: routers[0], assets: assetAddresses};
}

discoverPools();

2. Quoting

ABI

_amountIn: input token amount

_tokenPath: ordered list of token addresses (swap path).

_routerPath: ordered list of routers

Ethers.js example

3. Swapping

ABI

Ethers.js example

4. Full flow example


Done ☺️

Thanks for integrating with Nabla 🙌 If you have questions, please do not hesitate to get in contact and ask in our Discord or Telegram.

Last updated