Skip to content

alcorexchange/alcor-v2-sdk

Repository files navigation

alcor-v2-sdk

Installation

​​ npm

npm i @alcorexchange/alcor-swap-sdk

yarn

yarn add @alcorexchange/alcor-swap-sdk

Usage

Import:

ES6

import SwapSDK from '@alcorexchange/alcor-swap-sdk'

CommonJS

const SwapSDK = require('@alcorexchange/alcor-swap-sdk')

Initialization:

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
}

Examples

The examples can be found in examples/ directory.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published