Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bancorx

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bancorx

BancorX Utility

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25
increased by400%
Maintainers
1
Weekly downloads
 
Created
Source

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

symbolcodeaccountprecision
EOSeosio.tokenbnt2eoscnvrt4
BNTbntbntbntbntbnt2eoscnvrt10
ZOSzosdiscountsbancorc111514
IQeveripediaiqbancorc111233
PGLprospectorsgbancorc111134
CUSDstablecarbonbancorc111442
DICEbetdicetokenbancorc111252
BLACKeosblackteambancorc111114
CETeosiochaincebancorc111144
EPRAepraofficialbancorc111244
MEETONEeosiomeetonebancorc111224
ZKSzkstokensr4ubancorc111420
OCTocttothemoonbancorc111324
KARMAtherealkarmabancorc111124
HVThirevibeshvtbancorc111314
HORUShorustokeniobancorc111214
MEVeosvegascoinbancorc111344
SENSEsensegenesisbnr5125531534
USDTtethertetherbancorc112324

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

calculateReturn

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 Asset from token balance in the relay
  • balanceTo Asset to token balance in the relay
  • amount Asset amount to convert
Examples
const balanceFrom = split(`77814.0638 EOS`)
const balanceTo = split(`429519.5539120331 BNT`)
const amount = split(`1.0000 EOS`)

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

Returns Asset computed amount

calculateCost

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 Asset from token balance in the relay
  • balanceTo Asset to token balance in the relay
  • amountDesired Asset amount to desired
Examples
const balanceFrom = split(`77814.0638 EOS`)
const balanceTo = split(`429519.5539120331 BNT`)
const amountDesired = split(`1.0000 EOS`)

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

Returns Asset 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 }

Keywords

FAQs

Package last updated on 14 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc