SanityRates
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
You are referring to the Legacy
version of KyberSwap docs.
For the most updated information, please refer to:
is SanityRatesInterface, Withdrawable, Utils\ imports ERC20Interface, Withdrawable, Utils, SanityRatesInterface
Source: SanityRates.sol
The SanityRates contract's role is provide a safeguard for reserves whereby trades are disabled in the event exchange rates fall below the lower limit or rise above the upper limit of the sanity rates.
<AUTOGENERATED_TABLE_OF_CONTENTS>
SanityRates
Contract constructor. Note that constructor methods are called exactly once during contract instantiation and cannot be called again.
function SanityRates(address _admin) public | Parameter | Type | Description | | ----------|:-------:|:--------------------:| | _admin
| address | address of the admin |\
getSanityRate
Gets the sanity rate for a pair of tokens.
function getSanityRate(ERC20 src, ERC20 dest) public view returns (uint) | Parameter | Type | Description | | --------- |:-----:|:----------------------------------------:| | src
| ERC20 | source ERC20 token contract address | | dest
| ERC20 | destination ERC20 token contract address | Returns:\ The sanity rate for the pair of tokens
Web3 Example:
// DISCLAIMER: Code snippets in this guide are just examples and you
// should always do your own testing. If you have questions, visit our
// https://t.me/KyberDeveloper.
let sanityRate = await SanityRates.methods
.getSanityRate(
'0xdd974D5C2e2928deA5F71b9825b8b646686BD200', //ERC20 src: KNC token
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', //ERC20 dest: ETH
)
.call();
\
setReasonableDiff
Set reasonable conversion rate difference in percentage (any conversion rate outside of this range is considered unreasonable).
function setReasonableDiff(ERC20[] srcs, uint[] diff) public | Parameter | Type | Description | | --------- |:-----:|:-----------------------------------------------:| | srcs
| ERC20[] | list of source ERC20 token contract addresses | | diff
| uint[] | list of reasonableDiffs in basis points (bps)
1 bps = 0.01%
Modifiers: onlyAdmin |
Web3 Example:
// DISCLAIMER: Code snippets in this guide are just examples and you
// should always do your own testing. If you have questions, visit our
// https://t.me/KyberDeveloper.
SanityRates.methods
.setReasonableDiff(
['0xdd974D5C2e2928deA5F71b9825b8b646686BD200'], //ERC20[] srcs: [KNC token]
[1000], //uint[] diff: 10% = 1000 bps
)
.send(
{
from: adminAddress,
},
(err, res) => {
console.log(`Err: ${err}`);
console.log(`Res: ${res}`);
},
);
\
setSanityRates
Sets the sanity rate for a list of tokens.
function setSanityRates(ERC20[] srcs, uint[] rates) public | Parameter | Type | Description | | --------- |:-------:|:---------------------------------------------:| | srcs
| ERC20[] | list of source ERC20 token contract addresses | | rates
| uint[] | list of rates in ETH wei | Modifiers: onlyOperator
Web3 Example:
// DISCLAIMER: Code snippets in this guide are just examples and you
// should always do your own testing. If you have questions, visit our
// https://t.me/KyberDeveloper.
SanityRates.methods
.setSanityRates(
['0xdd974D5C2e2928deA5F71b9825b8b646686BD200'], //ERC20[] srcs: [KNC token]
[2000000000000000], //uint[] rates: 1 KNC = 0.002 ETH = 2000000000000000 wei
)
.send(
{
from: operatorAddress,
},
(err, res) => {
console.log(`Err: ${err}`);
console.log(`Res: ${res}`);
},
);