Token Quantity Conversion
You are referring to the Legacy
version of KyberSwap docs.
For the most updated information, please refer to:
Token Amount Conversion
Since getExpectedRate
returns a rate, not the amount, the following code snippets show how to convert to both source and destination token amounts, taking their decimals into account.
calcSrcQty
calcSrcQty
dstQty
ERC20 destination token amount in its decimals
srcDecimals
ERC20 source token decimals
dstDecimals
ERC20 destination token decimals
rate
src -> dst conversion rate, independent of token decimals
Returns: ERC20 source token amount in its decimals.
Javascript
Solidity
Refer to the Utils contract.
calcDstQty
calcDstQty
srcQty
ERC20 source token amount in its decimals
srcDecimals
ERC20 source token decimals
dstDecimals
ERC20 destination token decimals
rate
src -> dst conversion rate, independent of token decimals
Returns: ERC20 destination token amount in its decimals.
Javascript
Solidity
Refer to the Utils contract.
calcRateFromQty
calcRateFromQty
srcAmount
Number
ERC20 source token amount in its decimals
destAmount
Number
ERC20 source token decimals
srcDecimals
Number
ERC20 destination token decimals
dstDecimals
Number
src -> dst conversion rate, independent of token decimals
Returns: Token conversion rate independent of token decimals
Javascript
Solidity
Refer to the Utils2 contract.
Last updated