Address Contract Partially Verified
Address
0x2859581da59BD4e16a866Dd06b461b76d8E489a4
Balance
0 ETH
Nonce
1
Code Size
5601 bytes
Creator
0x93A7C464...5d3A at tx 0x8bde86ce...d78220
Indexed Transactions
0 (1 on-chain, 1.0% indexed)
Contract Bytecode
5601 bytes
0x60806040526004361061003f5760003560e01c80633bba21dc146100445780637df49300146100c4578063a683beb81461011b578063b27f823614610173575b600080fd5b34801561005057600080fd5b506100a76004803603606081101561006757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001909291905050506101e2565b604051808381526020018281526020019250505060405180910390f35b3480156100d057600080fd5b506100d96106e2565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61015d6004803603602081101561013157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061070a565b6040518082815260200191505060405180910390f35b34801561017f57600080fd5b506101cc6004803603604081101561019657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506109ab565b6040518082815260200191505060405180910390f35b6000806000841161025b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4b79626572436f6e7665727465723a205f737263416d6f756e74206572726f7281525060200191505060405180910390fd5b60008573ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156102da57600080fd5b505afa1580156102ee573d6000803e3d6000fd5b505050506040513d602081101561030457600080fd5b810190808051906020019092919050505090506103443330878973ffffffffffffffffffffffffffffffffffffffff16610b3e909392919063ffffffff16565b61038f7f0000000000000000000000009aab3f75489902f3a48495025729a0af77d4b11e868873ffffffffffffffffffffffffffffffffffffffff16610c2b9092919063ffffffff16565b7f0000000000000000000000009aab3f75489902f3a48495025729a0af77d4b11e73ffffffffffffffffffffffffffffffffffffffff1663cb3c28c7878773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee33896000806040518863ffffffff1660e01b8152600401808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018781526020018673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018381526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001975050505050505050602060405180830381600087803b1580156104f757600080fd5b505af115801561050b573d6000803e3d6000fd5b505050506040513d602081101561052157600080fd5b810190808051906020019092919050505092506105807f0000000000000000000000009aab3f75489902f3a48495025729a0af77d4b11e60008873ffffffffffffffffffffffffffffffffffffffff16610c2b9092919063ffffffff16565b8383146105d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806115076024913960400191505060405180910390fd5b6106a2818773ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561065957600080fd5b505afa15801561066d573d6000803e3d6000fd5b505050506040513d602081101561068357600080fd5b8101908080519060200190929190505050610e3290919063ffffffff16565b915060008211156106d9576106d833838873ffffffffffffffffffffffffffffffffffffffff16610e7c9092919063ffffffff16565b5b50935093915050565b60007f0000000000000000000000009aab3f75489902f3a48495025729a0af77d4b11e905090565b6000803411610781576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f4b79626572436f6e7665727465723a206d73672e76616c7565206572726f720081525060200191505060405180910390fd5b60007f0000000000000000000000009aab3f75489902f3a48495025729a0af77d4b11e73ffffffffffffffffffffffffffffffffffffffff1663cb3c28c73473eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee3487337fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000806040518963ffffffff1660e01b8152600401808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018781526020018673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018381526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019750505050505050506020604051808303818588803b15801561090b57600080fd5b505af115801561091f573d6000803e3d6000fd5b50505050506040513d602081101561093657600080fd5b81019080805190602001909291905050509050600081116109a2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806114e36024913960400191505060405180910390fd5b80915050919050565b6000807f0000000000000000000000009aab3f75489902f3a48495025729a0af77d4b11e73ffffffffffffffffffffffffffffffffffffffff1663809a9e5573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee86866040518463ffffffff1660e01b8152600401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050604080518083038186803b158015610a9a57600080fd5b505afa158015610aae573d6000803e3d6000fd5b505050506040513d6040811015610ac457600080fd5b810190808051906020019092919080519060200190929190505050509050610b356064610b276069610b19670de0b6b3a7640000610b0b878a610f3490919063ffffffff16565b610fba90919063ffffffff16565b610f3490919063ffffffff16565b610fba90919063ffffffff16565b91505092915050565b610c25846323b872dd60e01b858585604051602401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611004565b50505050565b6000811480610d25575060008373ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e30856040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019250505060206040518083038186803b158015610ce857600080fd5b505afa158015610cfc573d6000803e3d6000fd5b505050506040513d6020811015610d1257600080fd5b8101908080519060200190929190505050145b610d7a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260368152602001806115766036913960400191505060405180910390fd5b610e2d8363095ea7b360e01b8484604051602401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611004565b505050565b6000610e7483836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506110f3565b905092915050565b610f2f8363a9059cbb60e01b8484604051602401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611004565b505050565b600080831415610f475760009050610fb4565b6000828402905082848281610f5857fe5b0414610faf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602181526020018061152b6021913960400191505060405180910390fd5b809150505b92915050565b6000610ffc83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506111b3565b905092915050565b6060611066826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff166112799092919063ffffffff16565b90506000815111156110ee5780806020019051602081101561108757600080fd5b81019080805190602001909291905050506110ed576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a81526020018061154c602a913960400191505060405180910390fd5b5b505050565b60008383111582906111a0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561116557808201518184015260208101905061114a565b50505050905090810190601f1680156111925780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b6000808311829061125f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611224578082015181840152602081019050611209565b50505050905090810190601f1680156112515780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161126b57fe5b049050809150509392505050565b60606112888484600085611291565b90509392505050565b606061129c85611497565b61130e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000081525060200191505060405180910390fd5b600060608673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b6020831061135e578051825260208201915060208101905060208303925061133b565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146113c0576040519150601f19603f3d011682016040523d82523d6000602084013e6113c5565b606091505b509150915081156113da57809250505061148f565b6000815111156113ed5780518082602001fd5b836040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611454578082015181840152602081019050611439565b50505050905090810190601f1680156114815780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b949350505050565b60008060007fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47060001b9050833f91508082141580156114d957506000801b8214155b9250505091905056fe4b79626572436f6e7665727465723a204574686572203c3e20546f6b656e206572726f724b79626572436f6e7665727465723a20546f6b656e203c3e204574686572206572726f72536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a2646970667358221220888cfea6511d53871bee55557a74be35b87c1aa33e140a4727f5a04ab1354b2864736f6c63430006080033
Verified Source Code Partial Match
Compiler: v0.6.8+commit.0bbfe453
EVM: istanbul
Optimization: No
KyberConverter.sol 622 lines
/**
*Submitted for verification at Etherscan.io on 2020-07-06
*/
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: contracts/dex/IConverter.sol
pragma solidity ^0.6.8;
interface IConverter {
function getTrader() external view returns (address);
function calcNeededTokensForEther(IERC20 _dstToken, uint256 _etherAmount) external view returns (uint256);
function swapEtherToToken(IERC20 _dstToken) external payable returns (uint256);
function swapTokenToEther(IERC20 _srcToken, uint256 _srcAmount, uint256 _maxDstAmount)
external returns (uint256 dstAmount, uint256 srcRemainder);
}
// File: contracts/dex/IKyberNetworkProxy.sol
pragma solidity ^0.6.8;
interface IKyberNetworkProxy {
function getExpectedRate(
IERC20 src,
IERC20 dest,
uint256 srcQty
)
external view returns (uint256 expectedRate, uint256 slippageRate);
function trade(
IERC20 src,
uint256 srcAmount,
IERC20 dest,
address destAddress,
uint256 maxDestAmount,
uint256 minConversionRate,
address walletId
)
external payable returns (uint256);
}
// File: @openzeppelin/contracts/math/SafeMath.sol
pragma solidity ^0.6.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
// File: @openzeppelin/contracts/utils/Address.sol
pragma solidity ^0.6.2;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol
pragma solidity ^0.6.0;
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// File: contracts/dex/KyberConverter.sol
pragma solidity ^0.6.8;
contract KyberConverter is IConverter {
using SafeMath for uint256;
using SafeERC20 for IERC20;
IKyberNetworkProxy private immutable kyberProxy;
uint256 constant MAX_UINT_VALUE = 2**256 - 1;
uint256 constant GROSSING_UP_PERCENTAGE = 105;
/**
* @param _kyberProxy KyberProxy address.
*/
constructor(address _kyberProxy) public {
kyberProxy = IKyberNetworkProxy(_kyberProxy);
}
function getTrader() public view override returns (address) {
return address(kyberProxy);
}
function calcNeededTokensForEther(
IERC20 _dstToken,
uint256 _etherAmount
)
public view override returns (uint256)
{
// check expected rate for this token -> eth pair
(uint256 exchangeRate, ) = kyberProxy.getExpectedRate(
IERC20(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee),
IERC20(_dstToken),
_etherAmount
);
// https://github.com/KyberNetwork/smart-contracts/blob/master/contracts/Utils.sol#L34-L45
// simplified calcDestQty from with source / destination tokens both having 1e18 precision
return _etherAmount.mul(exchangeRate)
.div(1e18)
.mul(GROSSING_UP_PERCENTAGE)
.div(100);
}
function swapTokenToEther(
IERC20 _srcToken,
uint256 _srcAmount,
uint256 _maxDstAmount
)
public override returns (uint256 dstAmount, uint256 srcRemainder)
{
require(_srcAmount > 0, "KyberConverter: _srcAmount error");
// save pre balance
uint256 prevSrcBalance = _srcToken.balanceOf(address(this));
// Get Tokens from caller and aprove exchange
_srcToken.safeTransferFrom(msg.sender, address(this), _srcAmount);
_srcToken.safeApprove(address(kyberProxy), _srcAmount);
dstAmount = kyberProxy.trade(
_srcToken, // srcToken
_srcAmount, // srcAmount
IERC20(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee), // dstToken
msg.sender, // dstAddress
_maxDstAmount, // maxDstAmount
0, // minConversion Rate
address(0) // walletId for fees sharing
);
// clear approval
_srcToken.safeApprove(address(kyberProxy), 0);
// Check if the amount traded is equal to the expected one
require(dstAmount == _maxDstAmount, "KyberConverter: Token <> Ether error");
srcRemainder = _srcToken.balanceOf(address(this)).sub(prevSrcBalance);
// If theres a remainder, transfer remainder tokens back to caller
if (srcRemainder > 0) {
_srcToken.safeTransfer(msg.sender, srcRemainder);
}
}
function swapEtherToToken(
IERC20 _dstToken
)
payable public override returns (uint256)
{
require(msg.value > 0, "KyberConverter: msg.value error");
uint256 dstTokenAmount = kyberProxy.trade{
value: msg.value
}(
IERC20(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee), // srcToken
msg.value, // srcAmount
_dstToken, // dstToken
msg.sender, // dstAddress
MAX_UINT_VALUE, // maxDestAmount
0, // minConversion Rate
address(0) // walletId for fees sharing
);
require(dstTokenAmount > 0, "KyberConverter: Ether <> Token error");
return dstTokenAmount;
}
}
Read Contract
calcNeededTokensForEther 0xb27f8236 → uint256
getTrader 0x7df49300 → address
Write Contract 2 functions
These functions modify contract state and require a wallet transaction to execute.
swapEtherToToken 0xa683beb8
address _dstToken
returns: uint256
swapTokenToEther 0x3bba21dc
address _srcToken
uint256 _srcAmount
uint256 _maxDstAmount
returns: uint256, uint256
Recent Transactions
This address has 1 on-chain transactions, but only 1.0% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →