npm
npm i @alcorexchange/alcor-swap-sdk
yarn
yarn add @alcorexchange/alcor-swap-sdk
ES6
import SwapSDK from '@alcorexchange/alcor-swap-sdk'
CommonJS
const SwapSDK = require('@alcorexchange/alcor-swap-sdk')
import fetch from 'node-fetch'
import { Token, Pool } from '@alcorexchange/alcor-swap-sdk'
import { asset } from 'eos-common'
import { JsonRpc } from 'eosjs'
export function parseToken(token) {
return new Token(
token.contract,
asset(token.quantity).symbol.precision(),
asset(token.quantity).symbol.code().to_string()
)
}
const rpc = new JsonRpc('https://waxnode02.alcor.exchange', { fetch });
async function main() {
const { rows } = await rpc.get_table_rows({
scope: 'swap.alcor',
table: 'pools',
code: 'swap.alcor',
})
const { tokenA, tokenB, currSlot: { sqrtPriceX64, tick } } = rows[0]
const pool = new Pool({
...rows[0],
tokenA: parseToken(tokenA),
tokenB: parseToken(tokenB),
sqrtPriceX64,
tickCurrent: tick
})
// Do you thing with pool here
}
The examples can be found in examples/ directory.