Arbitoor Aggregator
Searchโ€ฆ
๐Ÿ’ป 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: @arbitoor/arbitoor-core
npm
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,
});
arbitoor-ui/SwapContent.tsx at e7e0438b49e37e2ec5235b2eba036d8db9866ace ยท arbitoor/arbitoor-ui
GitHub
Transaction example

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โ€‹
Join the Arbitoor Official Discord Server!
Discord
Copy link
On this page
1. Install NPM package
2. Initialize SDK
3. Poll for pool and token state updates
4. Generate routes
5. Generate transactions
6. Generate path
Source code
Need more help?