1.0.25 • Published 3 months ago

@alcorexchange/alcor-swap-sdk v1.0.25

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

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.

1.0.25

3 months ago

1.0.24

3 months ago

1.0.22

3 months ago

1.0.21

3 months ago

1.0.23

3 months ago

1.0.19

3 months ago

1.0.20

3 months ago

1.0.18

7 months ago

1.0.17

7 months ago

1.0.16

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.15

7 months ago

1.0.14

7 months ago

1.0.13

7 months ago

1.0.12

7 months ago

1.0.2

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.1

1 year ago

1.0.0

1 year ago