Token Quantity Conversion
You are referring to the Legacy
version of KyberSwap docs.
For the most updated information, please refer to:
Classic
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
Parameter | Description |
---|---|
| ERC20 destination token amount in its decimals |
| ERC20 source token decimals |
| ERC20 destination token decimals |
| 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
Parameter | Description |
---|---|
| ERC20 source token amount in its decimals |
| ERC20 source token decimals |
| ERC20 destination token decimals |
| 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
Parameter | Type | Description |
---|---|---|
| Number | ERC20 source token amount in its decimals |
| Number | ERC20 destination token amount in its decimals |
| Number | ERC20 source token decimals |
| Number | ERC20 destination token decimals |
Returns: Token conversion rate independent of token decimals
Javascript
Solidity
Refer to the Utils2 contract.
Last updated