@alcorexchange/alcor-swap-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.25 • Public • Published

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.

Package Sidebar

Install

npm i @alcorexchange/alcor-swap-sdk

Weekly Downloads

63

Version

1.0.25

License

ISC

Unpacked Size

436 kB

Total Files

153

Last publish

Collaborators

  • alcorexchange