1.1.4 • Published 5 years ago
xtoken v1.1.4
xtoken-js
Install:
npm install xtoken-js
Instantiate:
const xToken = require('xtoken-js')
const provider = new ethers.providers.Web3Provider(window.ethereum)
OR
const provider = new ethers.providers.InfuraProvider('homestead')
OR
const provider = ....
const xtoken = new xToken({
provider
})
Calculate Expected Quantity on Mint
This line of code is where the the npm library will be replacing code in the front end. All the logic is here: https://github.com/xtokenmarket/xtoken-market/blob/master/src/components/AssetPage/TradeBox/utils/index.js#L60
Before minting an xToken, the end user can calculate the expected minted quantity given the input quantity of ETH or ERC20 token (e.g. KNC or SNX).
Example:
const expectedQuantity = await xtoken.calculateExpectedQuantityOnMint({
symbol: 'xKNCa',
tradeWithEth: false,
amount: 172.39
})
Props
symbol: xToken symbol. Build for 'xKNCa', 'xKNCb', 'xSNXa'
tradeWithEth: if true, amount value is in ETH. if false, amount value is in token (i.e., KNC to xKNC, SNX for xSNX)
amount: this is the input amount in 18 decimal notation. for example 172.39 KNC equals 172.39e18 in Solidity notation.