💻 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.
npm i @arbitoor/arbitoor-core
yarn add @arbitoor/arbitoor-core
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
})
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()
const routes = await arbitoor.computeRoutes({
inputToken,
outputToken,
inputAmount
})
Returns an array of routes across different exchanges, ranked by output amount.
const txs = await arbitoor.generateTransactions({
routeInfo: routes[0],
slippageTolerance
})
// Send the TXs to the blockchain
await wallet.signAndSendTransactions({
transactions: txs,
});
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;
}
- 1.
- 2.
Last modified 10mo ago