Quickstart

Routing protocol integration guide

Suppose you want to swap 1 BNB for USDT and extract some arbitrage opportunities, if any. Then you should start with the api request.

import axios from "axios";

const UROBORUS_API_URL = "https://api.uroboros.co";

let routeParams = {
    // input amount, provided in hex
    amountIn: "0xde0b6b3a7640000",
    tokenIn: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
    tokenOut: "0xe9e7cea3dedca5984780bafc599bd69add087d56",
    // token that is used to count for gas usage
    // (normally it's native chain wrapped token)
    tokenGas: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
    gasPrice: "0x12a05f200",
    // cashback all tokens
    cashbackTokens: null
};
let route = await axios.post(UROBORUS_API_URL + "/route", routeParams);

Returned route may look like this:

[
    {
        tokenIn: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
        tokenOut: "0x55d398326f99059fF775485246999027B3197955",
        amountIn: "0xde0b6b3a7640000",
        // amount receibed by swappin WBNB for USDT
        amountOut: "0xf83e62b82819ce00b",
        // gas units used during a swap
        gasUsed: 58141,
        // protocol specific data, encoded and passed to protocol adaptor on UrbRouter
        swapData: {
            type: "uniswap-v2",
            address: "0xacaac9311b0096e04dfe96b6d87dec867d3883dc",
            swapFee: 20,
            // fee for selling a token
            sellFee: 0,
            // fee for buying a token
            buyFee: 0,
            zeroForOne: true
        }
    }
    // ...
]

Before using it, don't forget to approve tokens for spend on UrbRouter.

import sdk from "uroboros-sdk";
import ethers from "ethers";

let IERC20 = ethers.utils.Interface([
    "function approve(address spender, uint256 amount)"
]);
let router = sdk.getUrbRouterAddress();
let txData = IERC20.encodeFunction("approve", [
    router,
    routeParams.amountIn
]);
await signer.sendTransaction({ to: routeParams.tokenIn, data: txData });

And you can finally swap!

txData = sdk.encodeTransactionData(route);
await signer.sendTransaction({ to: router, data: txData });

In transaction logs you will be able to see resulting price, tokens that are "cash-backed" and your route id (coming soon).

Last updated