bancorx
Version:
BancorX Utility
87 lines (86 loc) • 3.45 kB
TypeScript
import { Asset, ExtendedSymbol, SymbolCode, Name } from "eos-common";
/**
* 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
*
* ```js
* Formula:
* 1.0000 / (77814.0638 + 1.0000) * 429519.5539120331
* // => 5.519748143058556
* ```
*
* @param {Asset} balanceFrom from token balance in the relay
* @param {Asset} balanceTo to token balance in the relay
* @param {Asset} amount amount to convert
* @returns {number} computed amount
* @example
*
* const balanceFrom = split(`77814.0638 EOS`);
* const balanceTo = split(`429519.5539120331 BNT`); // BNT
* const amount = split(`1.0000 EOS`);
*
* bancorx.calculateReturn(balanceFrom, balanceTo, amount)
* // => split(`5.519748143058556 BNT`)
*/
export declare function calculateReturn(balanceFrom: Asset, balanceTo: Asset, amount: Asset): Asset;
/**
* 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
*
* ```js
* Inverse Formula:
* 77814.0638 / (1.0 - 1 / 429519.5539120331) - 77814.0638
* // => 0.18116577989712823
* ```
*
* @param {Asset} balanceFrom from token balance in the relay
* @param {Asset} balanceTo to token balance in the relay
* @param {Asset} amountDesired amount to desired
* @returns {number} computed desired amount
* @example
*
* const balanceFrom = 77814.0638 // EOS
* const balanceTo = 429519.5539120331 // BNT
* const amountDesired = 1
*
* bancorx.calculateCost(balanceFrom, balanceTo, amountDesired)
* // => 0.18116577989712823
*/
export declare function calculateCost(balanceFrom: Asset, balanceTo: Asset, amountDesired: Asset): Asset;
export declare function calculateReserveToSmart(reserveAmount: Asset, reserveBalance: Asset, smartSupply: Asset, ratio?: number): Asset;
export declare function calculateSmartToReserve(smartTokens: Asset, reserveBalance: Asset, smartSupply: Asset, ratio?: number): Asset;
/**
* Compose Memo
*
* @param {Converter[]} converters relay converters
* @param {number} minReturn minimum return
* @param {string} destAccount destination acccount
* @param {number} [version=1] bancor protocol version
* @returns {string} computed memo
* @example
*
* 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>"
*/
export declare function composeMemo(converters: {
contract: Name;
symcode: SymbolCode;
extsym?: ExtendedSymbol;
}[], minReturn: string, destAccount: string, version?: number): string;
export declare function chargeFee(asset: Asset, decimalFee: number, magnitude?: number): Asset;
export declare function liquidate(smartTokens: Asset, reserveBalance: Asset, smartSupply: Asset): Asset;
export declare function calculateLiquidateCost(reserveTokens: Asset, reserveBalance: Asset, smartSupply: Asset): Asset;
export declare function fund(smartTokens: Asset, reserveBalance: Asset, smartSupply: Asset): Asset;
export declare function calculateFundReturn(reserveTokens: Asset, reserveBalance: Asset, smartSupply: Asset): Asset;