Arbitoor Aggregator
Search…
⌃K

💻 Developer Guide

Arbitoor Core is the unified SDK to trade across decentralized exchanges on NEAR. It can be used for trading bots and swap integrations in crypto wallets and third party dApps.

1. Install NPM package

npm i @arbitoor/arbitoor-core
yarn add @arbitoor/arbitoor-core

2. Initialize SDK

import { TokenInfo, TokenListProvider } from '@tonic-foundation/token-list'
import { MainnetRpc } from 'near-workspaces'
import { Arbitoor, getRoutePath, InMemoryProvider } from '@arbitoor/arbitoor-core'
​
const user = 'test.near'
​
const tokens = await new TokenListProvider().resolve()
const tokenList = tokens.filterByNearEnv('mainnet').getList()
const tokenMap = tokenList.reduce((map, item) => {
map.set(item.address, item)
return map
}, new Map<string, TokenInfo>())
​
const inMemoryProvider = new InMemoryProvider(MainnetRpc, tokenMap)
​
const arbitoor = new Arbitoor({
accountProvider: inMemoryProvider,
user
})

3. Poll for pool and token state updates

Arbitoor follows a data provider pattern to separate fetching from calculations. inMemoryProvider is used to fetch and cache pool and token data. Poll for updates every 10 seconds or so. Route generation will fail if cache is empty.
// Poll for pools and storage. If storage is set, then storage polling can be stopped.
await inMemoryProvider.ftFetchStorageBalance(outputToken, user)
await inMemoryProvider.fetchPools()

4. Generate routes

const routes = await arbitoor.computeRoutes({
inputToken,
outputToken,
inputAmount
})
Returns an array of routes across different exchanges, ranked by output amount.

5. Generate transactions

const txs = await arbitoor.generateTransactions({
routeInfo: routes[0],
slippageTolerance
})
​
// Send the TXs to the blockchain
await wallet.signAndSendTransactions({
transactions: txs,
});

6. Generate path

const path = getRoutePath(route)
This returns a RouteLeg[] object that can be used to display the route visually.
export interface RouteLeg {
tokens: [string, string] | [string, string, string];
percentage: string;
pools: (StablePool | Pool | SpinMarket)[];
dex: string;
}

Source code

Need more help?

Join the Arbitoor Discord for development related questions: https://discord.gg/yaQFbBs6Hg​