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 = ;
Typescript (ES6)
;
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 = bancorxrelaysCUSD;const balance = await rpc;// => [ '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:10000 / 778140638 + 10000 * 4295195539120331// => 5.519748143058556
Parameters
balanceFrom
Asset from token balance in the relaybalanceTo
Asset to token balance in the relayamount
Asset amount to convert
Examples
const balanceFrom = const balanceTo = const amount = bancorx// => 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:778140638 / 10 - 1 / 4295195539120331 - 778140638// => 0.18116577989712823
Parameters
balanceFrom
Asset from token balance in the relaybalanceTo
Asset to token balance in the relayamountDesired
Asset amount to desired
Examples
const balanceFrom = const balanceTo = const amountDesired = bancorx// => 0.18116577989712823
Returns Asset computed desired amount
composeMemo
Parse Memo
Parameters
converters
Array<Converter> relay convertersminReturn
number minimum returndestAccount
string destination acccountversion
number bancor protocol version (optional, default1
)
Examples
const CUSD = bancorxrelaysCUSD;const BNT = bancorxrelaysBNT; // Single converter (BNT => CUSD)bancorx// => "1,bancorc11144 CUSD,3.17,<account>" // Multi converter (EOS => BNT => CUSD)bancorx// => "1,bnt2eoscnvrt BNT bancorc11144 CUSD,3.17,<account>"
Returns string computed memo
parseBalance
Parse Balance
Parameters
Examples
bancorx // => {quantity: 10.0, symbol: "EOS"}bancorx // => {quantity: 10.0}
Returns Object parsed balance
relays
Relays
Examples
bancorxrelaysBNT// => { code: "bntbntbntbnt", account: "bnt2eoscnvrt", symbol: "BNT", precision: 10 } bancorxrelaysCUSD// => { code: "stablecarbon", account: "bancorc11144", symbol: "CUSD", precision: 2 }