npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bancorx-2

v0.2.96

Published

BancorX Utility

Downloads

10

Readme

BancorX utility

Collection of useful Javascript (Typescript) methods used for BancorX.

Wallet (Lynx/Scatter, etc...) transfer actions are not included.

Install

Using Yarn:

yarn add bancorx

or using NPM:

npm install --save bancorx

Import Module

CommonJS

const bancorx = require("bancorx");

Typescript (ES6)

import * as bancorx from "bancorx";

Relays

| symbol | code | account | precision | | ---------- | ------------ | ------------ | ------------- | | EOS | eosio.token | bnt2eoscnvrt | 4 | | BNT | bntbntbntbnt | bnt2eoscnvrt | 10 | | ZOS | zosdiscounts | bancorc11151 | 4 | | IQ | everipediaiq | bancorc11123 | 3 | | PGL | prospectorsg | bancorc11113 | 4 | | CUSD | stablecarbon | bancorc11144 | 2 | | DICE | betdicetoken | bancorc11125 | 2 | | BLACK | eosblackteam | bancorc11111 | 4 | | CET | eosiochaince | bancorc11114 | 4 | | EPRA | epraofficial | bancorc11124 | 4 | | MEETONE | eosiomeetone | bancorc11122 | 4 | | ZKS | zkstokensr4u | bancorc11142 | 0 | | OCT | octtothemoon | bancorc11132 | 4 | | KARMA | therealkarma | bancorc11112 | 4 | | HVT | hirevibeshvt | bancorc11131 | 4 | | HORUS | horustokenio | bancorc11121 | 4 | | MEV | eosvegascoin | bancorc11134 | 4 | | SENSE | sensegenesis | bnr512553153 | 4 | | USDT | tethertether | bancorc11232 | 4 |

Get Relay Balances

eosjs is required to use get_currency_balance method.

const {code, account, symbol} = bancorx.relays.CUSD;
const balance = await rpc.get_currency_balance(code, account, symbol);
// => [ '24874.22 CUSD' ]

API

Table of Contents

bancorFormula

Bancor Formula

  • token balance of EOS (eosio.token) in the relay: 77814.0638 EOS
  • token balance of BNT (bntbntbntbnt) in the relay: 429519.5539120331 BNT
Formula:
1.0000 / (77814.0638 + 1.0000) * 429519.5539120331
// => 5.519748143058556

Parameters

  • balanceFrom number from token balance in the relay
  • balanceTo number to token balance in the relay
  • amount number amount to convert

Examples

const balanceFrom = 77814.0638 // EOS
const balanceTo = 429519.5539120331 // BNT
const amount = 1

bancorx.bancorFormula(balanceFrom, balanceTo, amount)
// => 5.519748143058556

Returns number computed amount

bancorInverseFormula

Bancor Inverse Formula

  • token balance of EOS (eosio.token) in the relay: 77814.0638 EOS
  • token balance of BNT (bntbntbntbnt) in the relay: 429519.5539120331 BNT
Inverse Formula:
77814.0638 / (1.0 - 1 / 429519.5539120331) - 77814.0638
// => 0.18116577989712823

Parameters

  • balanceFrom number from token balance in the relay
  • balanceTo number to token balance in the relay
  • amountDesired number amount to desired

Examples

const balanceFrom = 77814.0638 // EOS
const balanceTo = 429519.5539120331 // BNT
const amountDesired = 1

bancorx.bancorInverseFormula(balanceFrom, balanceTo, amountDesired)
// => 0.18116577989712823

Returns number computed desired amount

composeMemo

Parse Memo

Parameters

  • converters Array<Converter> relay converters
  • minReturn number minimum return
  • destAccount string destination acccount
  • version number bancor protocol version (optional, default 1)

Examples

const CUSD = bancorx.relays.CUSD;
const BNT = bancorx.relays.BNT;

// Single converter (BNT => CUSD)
bancorx.composeMemo([CUSD], "3.17", "<account>")
// => "1,bancorc11144 CUSD,3.17,<account>"

// Multi converter (EOS => BNT => CUSD)
bancorx.composeMemo([BNT, CUSD], "3.17", "<account>")
// => "1,bnt2eoscnvrt BNT bancorc11144 CUSD,3.17,<account>"

Returns string computed memo

parseBalance

Parse Balance

Parameters

Examples

bancorx.parseBalance("10.0000 EOS") // => {quantity: 10.0, symbol: "EOS"}
bancorx.parseBalance(10.0) // => {quantity: 10.0}

Returns Object parsed balance

relays

Relays

Examples

bancorx.relays.BNT
// => { code: "bntbntbntbnt", account: "bnt2eoscnvrt", symbol: "BNT", precision: 10 }

bancorx.relays.CUSD
// => { code: "stablecarbon", account: "bancorc11144", symbol: "CUSD", precision: 2 }