ETH Price: $3,164.19 (+1.16%)
Gas: 1 Gwei

Contract

0xf9B8d8137dE64DE61cD582518Ebc5345D01D5039
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
0x6080604080538072019-06-29 16:23:401841 days ago1561825420IN
 Create: CompoundOrderFactory
0 ETH0.003686572

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
86887432019-10-06 13:27:181742 days ago1570368438
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
86883462019-10-06 11:59:161742 days ago1570363156
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
86708232019-10-03 18:23:091745 days ago1570126989
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
86648482019-10-02 19:50:101746 days ago1570045810
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
86638702019-10-02 16:20:171746 days ago1570033217
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
86634962019-10-02 14:53:001746 days ago1570027980
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
86620912019-10-02 9:36:191746 days ago1570008979
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
86617982019-10-02 8:36:301746 days ago1570005390
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
86617772019-10-02 8:31:221746 days ago1570005082
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
86617462019-10-02 8:26:191746 days ago1570004779
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
85772742019-09-19 2:51:421759 days ago1568861502
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
84933982019-09-06 0:55:371772 days ago1567731337
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
84898152019-09-05 11:33:201773 days ago1567683200
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
84845222019-09-04 15:57:491774 days ago1567612669
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
84845222019-09-04 15:57:491774 days ago1567612669
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
84451562019-08-29 12:42:341780 days ago1567082554
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
84225032019-08-25 23:52:411783 days ago1566777161
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
84224782019-08-25 23:47:361783 days ago1566776856
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
84148842019-08-24 19:42:021785 days ago1566675722
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
83837332019-08-19 23:17:481789 days ago1566256668
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
83769622019-08-18 21:54:181791 days ago1566165258
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
83729492019-08-18 7:09:211791 days ago1566112161
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
83582652019-08-16 0:26:531793 days ago1565915213
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
83540172019-08-15 8:20:571794 days ago1565857257
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
83435822019-08-13 17:45:501796 days ago1565718350
0xf9B8d813...5D01D5039
 Contract Creation0 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CompoundOrderFactory

Compiler Version
v0.5.8+commit.23d335f2

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity)

/**
 *Submitted for verification at Etherscan.io on 2019-07-01
*/

pragma solidity 0.5.8;

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be aplied to your functions to restrict their use to
 * the owner.
 */
contract Ownable {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor () internal {
        _owner = msg.sender;
        emit OwnershipTransferred(address(0), _owner);
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(isOwner(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Returns true if the caller is the current owner.
     */
    function isOwner() public view returns (bool) {
        return msg.sender == _owner;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * > Note: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public onlyOwner {
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     */
    function _transferOwnership(address newOwner) internal {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

// Compound finance comptroller
interface Comptroller {
    function enterMarkets(address[] calldata cTokens) external returns (uint[] memory);
    function markets(address cToken) external view returns (bool isListed, uint256 collateralFactorMantissa);
}

// Compound finance's price oracle
interface PriceOracle {
  function getPrice(address asset) external view returns (uint);
}

// Compound finance ERC20 market interface
interface CERC20 {
  function mint(uint mintAmount) external returns (uint);
  function redeemUnderlying(uint redeemAmount) external returns (uint);
  function borrow(uint borrowAmount) external returns (uint);
  function repayBorrow(uint repayAmount) external returns (uint);
  function borrowBalanceCurrent(address account) external returns (uint);
  function exchangeRateCurrent() external returns (uint);

  function balanceOf(address account) external view returns (uint);
  function decimals() external view returns (uint);
  function underlying() external view returns (address);
}

contract CompoundOrderStorage is Ownable {
  // Constants
  uint256 internal constant NEGLIGIBLE_DEBT = 10 ** 14; // we don't care about debts below 10^-4 DAI (0.1 cent)
  uint256 internal constant MAX_REPAY_STEPS = 3; // Max number of times we attempt to repay remaining debt

  // Contract instances
  Comptroller public COMPTROLLER; // The Compound comptroller
  PriceOracle public ORACLE; // The Compound price oracle
  CERC20 public CDAI; // The Compound DAI market token
  address public CETH_ADDR;

  // Instance variables
  uint256 public stake;
  uint256 public collateralAmountInDAI;
  uint256 public loanAmountInDAI;
  uint256 public cycleNumber;
  uint256 public buyTime; // Timestamp for order execution
  uint256 public outputAmount; // Records the total output DAI after order is sold
  address public compoundTokenAddr;
  bool public isSold;
  bool public orderType; // True for shorting, false for longing

  // The contract containing the code to be executed
  address public logicContract;
}

/**
 * @dev Interface of the ERC20 standard as defined in the EIP. Does not include
 * the optional functions; to access them see `ERC20Detailed`.
 */
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.
     *
     * > 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);
}

/**
 * @dev Optional functions from the ERC20 standard.
 */
contract ERC20Detailed is IERC20 {
    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for `name`, `symbol`, and `decimals`. All three of
     * these values are immutable: they can only be set once during
     * construction.
     */
    constructor (string memory name, string memory symbol, uint8 decimals) public {
        _name = name;
        _symbol = symbol;
        _decimals = decimals;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei.
     *
     * > Note that this information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * `IERC20.balanceOf` and `IERC20.transfer`.
     */
    function decimals() public view returns (uint8) {
        return _decimals;
    }
}

/**
 * @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) {
        require(b <= a, "SafeMath: subtraction overflow");
        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-solidity/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) {
        // Solidity only automatically asserts when dividing by 0
        require(b > 0, "SafeMath: division by zero");
        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) {
        require(b != 0, "SafeMath: modulo by zero");
        return a % b;
    }
}

/**
 * @dev Collection of functions related to the address type,
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * This test is non-exhaustive, and there may be false-negatives: during the
     * execution of a contract's constructor, its address will be reported as
     * not containing a contract.
     *
     * > It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies in extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 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 ERC20;` 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));
    }

    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);
        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.

        // A Solidity high level call has three parts:
        //  1. The target address is checked to verify it contains contract code
        //  2. The call itself is made, and success asserted
        //  3. The return value is decoded, which in turn checks the size of the returned data.
        // solhint-disable-next-line max-line-length
        require(address(token).isContract(), "SafeERC20: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = address(token).call(data);
        require(success, "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");
        }
    }
}

/**
 * @title The interface for the Kyber Network smart contract
 * @author Zefram Lou (Zebang Liu)
 */
interface KyberNetwork {
  function getExpectedRate(ERC20Detailed src, ERC20Detailed dest, uint srcQty) external view
      returns (uint expectedRate, uint slippageRate);

  function tradeWithHint(
    ERC20Detailed src, uint srcAmount, ERC20Detailed dest, address payable destAddress, uint maxDestAmount,
    uint minConversionRate, address walletId, bytes calldata hint) external payable returns(uint);
}

/**
 * @title The smart contract for useful utility functions and constants.
 * @author Zefram Lou (Zebang Liu)
 */
contract Utils {
  using SafeMath for uint256;
  using SafeERC20 for ERC20Detailed;

  /**
   * @notice Checks if `_token` is a valid token.
   * @param _token the token's address
   */
  modifier isValidToken(address _token) {
    require(_token != address(0));
    if (_token != address(ETH_TOKEN_ADDRESS)) {
      require(isContract(_token));
    }
    _;
  }

  address public DAI_ADDR;
  address payable public KYBER_ADDR;
  
  bytes public constant PERM_HINT = "PERM";

  ERC20Detailed internal constant ETH_TOKEN_ADDRESS = ERC20Detailed(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee);
  ERC20Detailed internal dai;
  KyberNetwork internal kyber;

  uint constant internal PRECISION = (10**18);
  uint constant internal MAX_QTY   = (10**28); // 10B tokens
  uint constant internal ETH_DECIMALS = 18;
  uint constant internal MAX_DECIMALS = 18;

  constructor(
    address _daiAddr,
    address payable _kyberAddr
  ) public {
    DAI_ADDR = _daiAddr;
    KYBER_ADDR = _kyberAddr;

    dai = ERC20Detailed(_daiAddr);
    kyber = KyberNetwork(_kyberAddr);
  }

  /**
   * @notice Get the number of decimals of a token
   * @param _token the token to be queried
   * @return number of decimals
   */
  function getDecimals(ERC20Detailed _token) internal view returns(uint256) {
    if (address(_token) == address(ETH_TOKEN_ADDRESS)) {
      return uint256(ETH_DECIMALS);
    }
    return uint256(_token.decimals());
  }

  /**
   * @notice Get the token balance of an account
   * @param _token the token to be queried
   * @param _addr the account whose balance will be returned
   * @return token balance of the account
   */
  function getBalance(ERC20Detailed _token, address _addr) internal view returns(uint256) {
    if (address(_token) == address(ETH_TOKEN_ADDRESS)) {
      return uint256(_addr.balance);
    }
    return uint256(_token.balanceOf(_addr));
  }

  /**
   * @notice Calculates the rate of a trade. The rate is the price of the source token in the dest token, in 18 decimals.
   *         Note: the rate is on the token level, not the wei level, so for example if 1 Atoken = 10 Btoken, then the rate
   *         from A to B is 10 * 10**18, regardless of how many decimals each token uses.
   * @param srcAmount amount of source token
   * @param destAmount amount of dest token
   * @param srcDecimals decimals used by source token
   * @param dstDecimals decimals used by dest token
   */
  function calcRateFromQty(uint srcAmount, uint destAmount, uint srcDecimals, uint dstDecimals)
        internal pure returns(uint)
  {
    require(srcAmount <= MAX_QTY);
    require(destAmount <= MAX_QTY);

    if (dstDecimals >= srcDecimals) {
      require((dstDecimals - srcDecimals) <= MAX_DECIMALS);
      return (destAmount * PRECISION / ((10 ** (dstDecimals - srcDecimals)) * srcAmount));
    } else {
      require((srcDecimals - dstDecimals) <= MAX_DECIMALS);
      return (destAmount * PRECISION * (10 ** (srcDecimals - dstDecimals)) / srcAmount);
    }
  }

  /**
   * @notice Wrapper function for doing token conversion on Kyber Network
   * @param _srcToken the token to convert from
   * @param _srcAmount the amount of tokens to be converted
   * @param _destToken the destination token
   * @return _destPriceInSrc the price of the dest token, in terms of source tokens
   *         _srcPriceInDest the price of the source token, in terms of dest tokens
   *         _actualDestAmount actual amount of dest token traded
   *         _actualSrcAmount actual amount of src token traded
   */
  function __kyberTrade(ERC20Detailed _srcToken, uint256 _srcAmount, ERC20Detailed _destToken)
    internal
    returns(
      uint256 _destPriceInSrc,
      uint256 _srcPriceInDest,
      uint256 _actualDestAmount,
      uint256 _actualSrcAmount
    )
  {
    require(_srcToken != _destToken);

    // Get current rate & ensure token is listed on Kyber
    (, uint256 rate) = kyber.getExpectedRate(_srcToken, _destToken, _srcAmount);
    require(rate > 0);

    uint256 beforeSrcBalance = getBalance(_srcToken, address(this));
    uint256 msgValue;
    if (_srcToken != ETH_TOKEN_ADDRESS) {
      msgValue = 0;
      _srcToken.safeApprove(KYBER_ADDR, 0);
      _srcToken.safeApprove(KYBER_ADDR, _srcAmount);
    } else {
      msgValue = _srcAmount;
    }
    _actualDestAmount = kyber.tradeWithHint.value(msgValue)(
      _srcToken,
      _srcAmount,
      _destToken,
      toPayableAddr(address(this)),
      MAX_QTY,
      rate,
      0x332D87209f7c8296389C307eAe170c2440830A47,
      PERM_HINT
    );
    require(_actualDestAmount > 0);
    if (_srcToken != ETH_TOKEN_ADDRESS) {
      _srcToken.safeApprove(KYBER_ADDR, 0);
    }

    _actualSrcAmount = beforeSrcBalance.sub(getBalance(_srcToken, address(this)));
    _destPriceInSrc = calcRateFromQty(_actualDestAmount, _actualSrcAmount, getDecimals(_destToken), getDecimals(_srcToken));
    _srcPriceInDest = calcRateFromQty(_actualSrcAmount, _actualDestAmount, getDecimals(_srcToken), getDecimals(_destToken));
  }

  /**
   * @notice Checks if an Ethereum account is a smart contract
   * @param _addr the account to be checked
   * @return True if the account is a smart contract, false otherwise
   */
  function isContract(address _addr) view internal returns(bool) {
    uint size;
    if (_addr == address(0)) return false;
    assembly {
        size := extcodesize(_addr)
    }
    return size>0;
  }

  function toPayableAddr(address _addr) pure internal returns (address payable) {
    return address(uint160(_addr));
  }
}

contract CompoundOrder is CompoundOrderStorage, Utils {
  constructor(
    address _compoundTokenAddr,
    uint256 _cycleNumber,
    uint256 _stake,
    uint256 _collateralAmountInDAI,
    uint256 _loanAmountInDAI,
    bool _orderType,
    address _logicContract,
    address _daiAddr,
    address payable _kyberAddr,
    address _comptrollerAddr,
    address _priceOracleAddr,
    address _cDAIAddr,
    address _cETHAddr
  ) public Utils(_daiAddr, _kyberAddr)  {
    // Initialize details of short order
    require(_compoundTokenAddr != _cDAIAddr);
    require(_stake > 0 && _collateralAmountInDAI > 0 && _loanAmountInDAI > 0); // Validate inputs
    stake = _stake;
    collateralAmountInDAI = _collateralAmountInDAI;
    loanAmountInDAI = _loanAmountInDAI;
    cycleNumber = _cycleNumber;
    compoundTokenAddr = _compoundTokenAddr;
    orderType = _orderType;
    logicContract = _logicContract;

    COMPTROLLER = Comptroller(_comptrollerAddr);
    ORACLE = PriceOracle(_priceOracleAddr);
    CDAI = CERC20(_cDAIAddr);
    CETH_ADDR = _cETHAddr;
  }
  
  /**
   * @notice Executes the Compound order
   * @param _minPrice the minimum token price
   * @param _maxPrice the maximum token price
   */
  function executeOrder(uint256 _minPrice, uint256 _maxPrice) public {
    (bool success,) = logicContract.delegatecall(abi.encodeWithSelector(this.executeOrder.selector, _minPrice, _maxPrice));
    if (!success) { revert(); }
  }

  /**
   * @notice Sells the Compound order and returns assets to BetokenFund
   * @param _minPrice the minimum token price
   * @param _maxPrice the maximum token price
   */
  function sellOrder(uint256 _minPrice, uint256 _maxPrice) public returns (uint256 _inputAmount, uint256 _outputAmount) {
    (bool success, bytes memory result) = logicContract.delegatecall(abi.encodeWithSelector(this.sellOrder.selector, _minPrice, _maxPrice));
    if (!success) { revert(); }
    return abi.decode(result, (uint256, uint256));
  }

  /**
   * @notice Repays the loans taken out to prevent the collateral ratio from dropping below threshold
   * @param _repayAmountInDAI the amount to repay, in DAI
   */
  function repayLoan(uint256 _repayAmountInDAI) public {
    (bool success,) = logicContract.delegatecall(abi.encodeWithSelector(this.repayLoan.selector, _repayAmountInDAI));
    if (!success) { revert(); }
  }

  /**
   * @notice Calculates the current liquidity (supply - collateral) on the Compound platform
   * @return the liquidity
   */
  function getCurrentLiquidityInDAI() public returns (bool _isNegative, uint256 _amount) {
    (bool success, bytes memory result) = logicContract.delegatecall(abi.encodeWithSelector(this.getCurrentLiquidityInDAI.selector));
    if (!success) { revert(); }
    return abi.decode(result, (bool, uint256));
  }

  /**
   * @notice Calculates the current collateral ratio on Compound, using 18 decimals
   * @return the collateral ratio
   */
  function getCurrentCollateralRatioInDAI() public returns (uint256 _amount) {
    (bool success, bytes memory result) = logicContract.delegatecall(abi.encodeWithSelector(this.getCurrentCollateralRatioInDAI.selector));
    if (!success) { revert(); }
    return abi.decode(result, (uint256));
  }

  /**
   * @notice Calculates the current profit in DAI
   * @return the profit amount
   */
  function getCurrentProfitInDAI() public returns (bool _isNegative, uint256 _amount) {
    (bool success, bytes memory result) = logicContract.delegatecall(abi.encodeWithSelector(this.getCurrentProfitInDAI.selector));
    if (!success) { revert(); }
    return abi.decode(result, (bool, uint256));
  }

  function getMarketCollateralFactor() public returns (uint256) {
    (bool success, bytes memory result) = logicContract.delegatecall(abi.encodeWithSelector(this.getMarketCollateralFactor.selector));
    if (!success) { revert(); }
    return abi.decode(result, (uint256));
  }

  function getCurrentCollateralInDAI() public returns (uint256 _amount) {
    (bool success, bytes memory result) = logicContract.delegatecall(abi.encodeWithSelector(this.getCurrentCollateralInDAI.selector));
    if (!success) { revert(); }
    return abi.decode(result, (uint256));
  }

  function getCurrentBorrowInDAI() public returns (uint256 _amount) {
    (bool success, bytes memory result) = logicContract.delegatecall(abi.encodeWithSelector(this.getCurrentBorrowInDAI.selector));
    if (!success) { revert(); }
    return abi.decode(result, (uint256));
  }

  function getCurrentCashInDAI() public returns (uint256 _amount) {
    (bool success, bytes memory result) = logicContract.delegatecall(abi.encodeWithSelector(this.getCurrentCashInDAI.selector));
    if (!success) { revert(); }
    return abi.decode(result, (uint256));
  }

  function() external payable {}
}

contract CompoundOrderFactory {
  address public SHORT_CERC20_LOGIC_CONTRACT;
  address public SHORT_CEther_LOGIC_CONTRACT;
  address public LONG_CERC20_LOGIC_CONTRACT;
  address public LONG_CEther_LOGIC_CONTRACT;

  address public DAI_ADDR;
  address payable public KYBER_ADDR;
  address public COMPTROLLER_ADDR;
  address public ORACLE_ADDR;
  address public CDAI_ADDR;
  address public CETH_ADDR;

  constructor(
    address _shortCERC20LogicContract,
    address _shortCEtherLogicContract,
    address _longCERC20LogicContract,
    address _longCEtherLogicContract,
    address _daiAddr,
    address payable _kyberAddr,
    address _comptrollerAddr,
    address _priceOracleAddr,
    address _cDAIAddr,
    address _cETHAddr
  ) public {
    SHORT_CERC20_LOGIC_CONTRACT = _shortCERC20LogicContract;
    SHORT_CEther_LOGIC_CONTRACT = _shortCEtherLogicContract;
    LONG_CERC20_LOGIC_CONTRACT = _longCERC20LogicContract;
    LONG_CEther_LOGIC_CONTRACT = _longCEtherLogicContract;

    DAI_ADDR = _daiAddr;
    KYBER_ADDR = _kyberAddr;
    COMPTROLLER_ADDR = _comptrollerAddr;
    ORACLE_ADDR = _priceOracleAddr;
    CDAI_ADDR = _cDAIAddr;
    CETH_ADDR = _cETHAddr;
  }

  function createOrder(
    address _compoundTokenAddr,
    uint256 _cycleNumber,
    uint256 _stake,
    uint256 _collateralAmountInDAI,
    uint256 _loanAmountInDAI,
    bool _orderType
  ) public returns (CompoundOrder) {
    require(_compoundTokenAddr != address(0));

    CompoundOrder order;
    address logicContract;

    if (_compoundTokenAddr != CETH_ADDR) {
      logicContract = _orderType ? SHORT_CERC20_LOGIC_CONTRACT : LONG_CERC20_LOGIC_CONTRACT;
    } else {
      logicContract = _orderType ? SHORT_CEther_LOGIC_CONTRACT : LONG_CEther_LOGIC_CONTRACT;
    }
    order = new CompoundOrder(_compoundTokenAddr, _cycleNumber, _stake, _collateralAmountInDAI, _loanAmountInDAI, _orderType, logicContract, DAI_ADDR, KYBER_ADDR, COMPTROLLER_ADDR, ORACLE_ADDR, CDAI_ADDR, CETH_ADDR);
    order.transferOwnership(msg.sender);
    return order;
  }

  function getMarketCollateralFactor(address _compoundTokenAddr) public view returns (uint256) {
    Comptroller troll = Comptroller(COMPTROLLER_ADDR);
    (, uint256 factor) = troll.markets(_compoundTokenAddr);
    return factor;
  }
}

Contract Security Audit

Contract ABI

[{"constant":true,"inputs":[],"name":"SHORT_CERC20_LOGIC_CONTRACT","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"LONG_CEther_LOGIC_CONTRACT","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"COMPTROLLER_ADDR","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CETH_ADDR","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"SHORT_CEther_LOGIC_CONTRACT","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_compoundTokenAddr","type":"address"},{"name":"_cycleNumber","type":"uint256"},{"name":"_stake","type":"uint256"},{"name":"_collateralAmountInDAI","type":"uint256"},{"name":"_loanAmountInDAI","type":"uint256"},{"name":"_orderType","type":"bool"}],"name":"createOrder","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_compoundTokenAddr","type":"address"}],"name":"getMarketCollateralFactor","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"LONG_CERC20_LOGIC_CONTRACT","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"KYBER_ADDR","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"DAI_ADDR","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CDAI_ADDR","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ORACLE_ADDR","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_shortCERC20LogicContract","type":"address"},{"name":"_shortCEtherLogicContract","type":"address"},{"name":"_longCERC20LogicContract","type":"address"},{"name":"_longCEtherLogicContract","type":"address"},{"name":"_daiAddr","type":"address"},{"name":"_kyberAddr","type":"address"},{"name":"_comptrollerAddr","type":"address"},{"name":"_priceOracleAddr","type":"address"},{"name":"_cDAIAddr","type":"address"},{"name":"_cETHAddr","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]

608060405234801561001057600080fd5b50604051610140806117ed833981018060405261014081101561003257600080fd5b508051602082015160408301516060840151608085015160a086015160c087015160e088015161010089015161012090990151600080546001600160a01b03199081166001600160a01b039b8c161782556001805482169a8c169a909a17909955600280548a16988b1698909817909755600380548916968a169690961790955560048054881694891694909417909355600580548716928816929092179091556006805486169187169190911790556007805485169186169190911790556008805484169585169590951790945560098054909216929093169190911790556116cb90819061012290396000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c8063aca9de6611610071578063aca9de6614610143578063c5818d611461017b578063cb0ef21d14610183578063d95393eb1461018b578063da52d3d214610193578063e236abb41461019b576100b4565b80633eb7cd4d146100b95780634076c143146100dd57806346d6773b146100e557806350fbd642146100ed57806364a00918146100f5578063680db379146100fd575b600080fd5b6100c16101a3565b604080516001600160a01b039092168252519081900360200190f35b6100c16101b2565b6100c16101c1565b6100c16101d0565b6100c16101df565b6100c1600480360360c081101561011357600080fd5b506001600160a01b038135169060208101359060408101359060608101359060808101359060a0013515156101ee565b6101696004803603602081101561015957600080fd5b50356001600160a01b03166103bc565b60408051918252519081900360200190f35b6100c1610448565b6100c1610457565b6100c1610466565b6100c1610475565b6100c1610484565b6000546001600160a01b031681565b6003546001600160a01b031681565b6006546001600160a01b031681565b6009546001600160a01b031681565b6001546001600160a01b031681565b60006001600160a01b03871661020357600080fd5b60095460009081906001600160a01b038a81169116146102475783610233576002546001600160a01b0316610240565b6000546001600160a01b03165b905061026d565b8361025d576003546001600160a01b031661026a565b6001546001600160a01b03165b90505b6004546005546006546007546008546009546040518f968f968f968f968f968f968d966001600160a01b039687169695861695948516949384169392831692909116906102b990610493565b6001600160a01b039d8e168152602081019c909c526040808d019b909b5260608c019990995260808b019790975294151560a08a015292891660c089015290881660e088015287166101008701528616610120860152851661014085015284166101608401529092166101808201529051908190036101a001906000f080158015610348573d6000803e3d6000fd5b5060408051600160e01b63f2fde38b02815233600482015290519193506001600160a01b0384169163f2fde38b9160248082019260009290919082900301818387803b15801561039757600080fd5b505af11580156103ab573d6000803e3d6000fd5b50939b9a5050505050505050505050565b60065460408051600160e01b638e8f294b0281526001600160a01b0384811660048301528251600094919091169284928492638e8f294b92602480840193919291829003018186803b15801561041157600080fd5b505afa158015610425573d6000803e3d6000fd5b505050506040513d604081101561043b57600080fd5b5060200151949350505050565b6002546001600160a01b031681565b6005546001600160a01b031681565b6004546001600160a01b031681565b6008546001600160a01b031681565b6007546001600160a01b031681565b6111ff806104a18339019056fe608060405234801561001057600080fd5b506040516101a0806111ff83398101806040526101a081101561003257600080fd5b50805160208201516040808401516060850151608086015160a087015160c088015160e08901516101008a01516101208b01516101408c01516101608d0151610180909d0151600080546001600160a01b03191633178082559b519d9e9c9d9a9c999b989a9799969895979496939592949192889288926001600160a01b039290921691907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3600d80546001600160a01b039384166001600160a01b03199182168117909255600e805493851693821684179055600f805482169092179091556010805490911690911790558d8116908316141561013357600080fd5b60008b118015610143575060008a115b801561014f5750600089115b61015857600080fd5b60059a909a556006989098556007969096556008989098555050600b8054921515750100000000000000000000000000000000000000000002600160a81b60ff02196001600160a01b03998a166001600160a01b03199586161716179055600c80549188169183169190911790556001805495871695821695909517909455600280549186169185169190911790556003805491851691841691909117905560048054919093169116179055610fec806102136000396000f3fe6080604052600436106101d85760003560e01c80637461df1111610102578063cb0ef21d11610095578063e852e74111610064578063e852e7411461052c578063ef46e0ca14610541578063f2fde38b14610571578063f7fa7202146105a4576101d8565b8063cb0ef21d146104a4578063cc0e97c9146104b9578063cd61a95a146104ce578063d95393eb14610517576101d8565b80638da5cb5b116100d15780638da5cb5b1461043b5780638f32d59b1461045057806394d5567a14610465578063ab7b1c891461047a576101d8565b80637461df111461037257806376017b6414610387578063878f76031461039c5780638b98a2c5146103b1576101d8565b806350fbd6421161017a57806362141fcc1161014957806362141fcc1461030a5780636db153de1461031f5780636f17591f14610334578063715018a61461035d576101d8565b806350fbd642146102b657806359690e70146102cb5780635f2d554b146102e05780635f82c67e146102f5576101d8565b80632fe7d446116101b65780632fe7d4461461022b57806338013f02146102405780633a4b66f1146102715780633bc3c23b14610286576101d8565b806303eeb4ca146101da5780632e27f486146102015780632f88471014610216575b005b3480156101e657600080fd5b506101ef6105b9565b60408051918252519081900360200190f35b34801561020d57600080fd5b506101ef6105bf565b34801561022257600080fd5b506101ef6106bf565b34801561023757600080fd5b506101ef6106c5565b34801561024c57600080fd5b506102556106cb565b604080516001600160a01b039092168252519081900360200190f35b34801561027d57600080fd5b506101ef6106da565b34801561029257600080fd5b5061029b6106e0565b60408051921515835260208301919091528051918290030190f35b3480156102c257600080fd5b506102556107ed565b3480156102d757600080fd5b5061029b6107fc565b3480156102ec57600080fd5b506101ef61086b565b34801561030157600080fd5b506102556108d8565b34801561031657600080fd5b506101ef6108e7565b34801561032b57600080fd5b506101ef6108ed565b34801561034057600080fd5b5061034961095a565b604080519115158252519081900360200190f35b34801561036957600080fd5b506101d861096a565b34801561037e57600080fd5b506101ef610a10565b34801561039357600080fd5b50610255610a7d565b3480156103a857600080fd5b50610255610a8c565b3480156103bd57600080fd5b506103c6610a9b565b6040805160208082528351818301528351919283929083019185019080838360005b838110156104005781810151838201526020016103e8565b50505050905090810190601f16801561042d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561044757600080fd5b50610255610abe565b34801561045c57600080fd5b50610349610acd565b34801561047157600080fd5b506101ef610ade565b34801561048657600080fd5b506101d86004803603602081101561049d57600080fd5b5035610ae4565b3480156104b057600080fd5b50610255610bce565b3480156104c557600080fd5b50610255610bdd565b3480156104da57600080fd5b506104fe600480360360408110156104f157600080fd5b5080359060200135610bec565b6040805192835260208301919091528051918290030190f35b34801561052357600080fd5b50610255610d11565b34801561053857600080fd5b50610349610d20565b34801561054d57600080fd5b506101d86004803603604081101561056457600080fd5b5080359060200135610d30565b34801561057d57600080fd5b506101d86004803603602081101561059457600080fd5b50356001600160a01b0316610e22565b3480156105b057600080fd5b506101ef610e8a565b60095481565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e11b631713fa43021781529151815160009485946060946001600160a01b039092169391928291908083835b6020831061062d5780518252601f19909201916020918201910161060e565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d806000811461068d576040519150601f19603f3d011682016040523d82523d6000602084013e610692565b606091505b5091509150816106a157600080fd5b8080602001905160208110156106b657600080fd5b50519250505090565b60085481565b60065481565b6002546001600160a01b031681565b60055481565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e01b633bc3c23b0217815291518151600094859485946060946001600160a01b039093169390929182918083835b602083106107505780518252601f199092019160209182019101610731565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d80600081146107b0576040519150601f19603f3d011682016040523d82523d6000602084013e6107b5565b606091505b5091509150816107c457600080fd5b8080602001905160408110156107d957600080fd5b508051602090910151909450925050509091565b6004546001600160a01b031681565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e41b63059690e70217815291518151600094859485946060946001600160a01b03909316939092918291808383602083106107505780518252601f199092019160209182019101610731565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e01b635f2d554b021781529151815160009485946060946001600160a01b039092169391928291908083836020831061062d5780518252601f19909201916020918201910161060e565b6001546001600160a01b031681565b60075481565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e11b6336d8a9ef021781529151815160009485946060946001600160a01b039092169391928291908083836020831061062d5780518252601f19909201916020918201910161060e565b600b54600160a81b900460ff1681565b610972610acd565b6109c65760408051600160e51b62461bcd02815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e01b637461df11021781529151815160009485946060946001600160a01b039092169391928291908083836020831061062d5780518252601f19909201916020918201910161060e565b600b546001600160a01b031681565b6003546001600160a01b031681565b604051806040016040528060048152602001600160e01b635045524d0281525081565b6000546001600160a01b031690565b6000546001600160a01b0316331490565b600a5481565b600c5460408051602480820185905282518083039091018152604490910182526020810180516001600160e01b0316600160e01b63ab7b1c8902178152915181516000946001600160a01b03169382918083835b60208310610b575780518252601f199092019160209182019101610b38565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d8060008114610bb7576040519150601f19603f3d011682016040523d82523d6000602084013e610bbc565b606091505b5050905080610bca57600080fd5b5050565b600e546001600160a01b031681565b600c546001600160a01b031681565b600c546040805160248101859052604480820185905282518083039091018152606490910182526020810180516001600160e01b0316600160e11b6366b0d4ad0217815291518151600094859485946060946001600160a01b039093169390929182918083835b60208310610c725780518252601f199092019160209182019101610c53565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d8060008114610cd2576040519150601f19603f3d011682016040523d82523d6000602084013e610cd7565b606091505b509150915081610ce657600080fd5b808060200190516040811015610cfb57600080fd5b5080516020909101519097909650945050505050565b600d546001600160a01b031681565b600b54600160a01b900460ff1681565b600c546040805160248101859052604480820185905282518083039091018152606490910182526020810180516001600160e01b0316600160e11b6377a3706502178152915181516000946001600160a01b03169382918083835b60208310610daa5780518252601f199092019160209182019101610d8b565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d8060008114610e0a576040519150601f19603f3d011682016040523d82523d6000602084013e610e0f565b606091505b5050905080610e1d57600080fd5b505050565b610e2a610acd565b610e7e5760408051600160e51b62461bcd02815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b610e8781610ef7565b50565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e11b637bfd3901021781529151815160009485946060946001600160a01b039092169391928291908083836020831061062d5780518252601f19909201916020918201910161060e565b6001600160a01b038116610f3f57604051600160e51b62461bcd028152600401808060200182810382526026815260200180610f9b6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b039290921691909117905556fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373a165627a7a72305820f2c91c2f74d5d7f43012ab2bd1c4eefeee9ab4e1af2bcf2b3849a6e113950f6f0029a165627a7a7230582022f62c38d60a858af5740acd71f8075c1e02a64d05c7cf572b1674589110e6370029000000000000000000000000215827fe862ea5a449677c20672022a8d01566de000000000000000000000000efd9a8d7bd9753a732c2c01b1c3261625890061f00000000000000000000000012860ccd1e84d5dcc008901d8ae38fa7114e56b3000000000000000000000000629118bd40556d3cb3fb9ce48e64709a821578c800000000000000000000000089d24a6b4ccb1b6faa2625fe562bdd9a23260359000000000000000000000000818e6fecd516ecc3849daf6845e3ec868087b7550000000000000000000000003d9819210a31b4961b30ef54be2aed79b9c9cd3b00000000000000000000000002557a5e05defeffd4cae6d83ea3d173b272c904000000000000000000000000f5dce57282a584d2746faf1593d3121fcac444dc0000000000000000000000004ddc2d193948926d02f9b1fe9e1daa0718270ed5

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100b45760003560e01c8063aca9de6611610071578063aca9de6614610143578063c5818d611461017b578063cb0ef21d14610183578063d95393eb1461018b578063da52d3d214610193578063e236abb41461019b576100b4565b80633eb7cd4d146100b95780634076c143146100dd57806346d6773b146100e557806350fbd642146100ed57806364a00918146100f5578063680db379146100fd575b600080fd5b6100c16101a3565b604080516001600160a01b039092168252519081900360200190f35b6100c16101b2565b6100c16101c1565b6100c16101d0565b6100c16101df565b6100c1600480360360c081101561011357600080fd5b506001600160a01b038135169060208101359060408101359060608101359060808101359060a0013515156101ee565b6101696004803603602081101561015957600080fd5b50356001600160a01b03166103bc565b60408051918252519081900360200190f35b6100c1610448565b6100c1610457565b6100c1610466565b6100c1610475565b6100c1610484565b6000546001600160a01b031681565b6003546001600160a01b031681565b6006546001600160a01b031681565b6009546001600160a01b031681565b6001546001600160a01b031681565b60006001600160a01b03871661020357600080fd5b60095460009081906001600160a01b038a81169116146102475783610233576002546001600160a01b0316610240565b6000546001600160a01b03165b905061026d565b8361025d576003546001600160a01b031661026a565b6001546001600160a01b03165b90505b6004546005546006546007546008546009546040518f968f968f968f968f968f968d966001600160a01b039687169695861695948516949384169392831692909116906102b990610493565b6001600160a01b039d8e168152602081019c909c526040808d019b909b5260608c019990995260808b019790975294151560a08a015292891660c089015290881660e088015287166101008701528616610120860152851661014085015284166101608401529092166101808201529051908190036101a001906000f080158015610348573d6000803e3d6000fd5b5060408051600160e01b63f2fde38b02815233600482015290519193506001600160a01b0384169163f2fde38b9160248082019260009290919082900301818387803b15801561039757600080fd5b505af11580156103ab573d6000803e3d6000fd5b50939b9a5050505050505050505050565b60065460408051600160e01b638e8f294b0281526001600160a01b0384811660048301528251600094919091169284928492638e8f294b92602480840193919291829003018186803b15801561041157600080fd5b505afa158015610425573d6000803e3d6000fd5b505050506040513d604081101561043b57600080fd5b5060200151949350505050565b6002546001600160a01b031681565b6005546001600160a01b031681565b6004546001600160a01b031681565b6008546001600160a01b031681565b6007546001600160a01b031681565b6111ff806104a18339019056fe608060405234801561001057600080fd5b506040516101a0806111ff83398101806040526101a081101561003257600080fd5b50805160208201516040808401516060850151608086015160a087015160c088015160e08901516101008a01516101208b01516101408c01516101608d0151610180909d0151600080546001600160a01b03191633178082559b519d9e9c9d9a9c999b989a9799969895979496939592949192889288926001600160a01b039290921691907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3600d80546001600160a01b039384166001600160a01b03199182168117909255600e805493851693821684179055600f805482169092179091556010805490911690911790558d8116908316141561013357600080fd5b60008b118015610143575060008a115b801561014f5750600089115b61015857600080fd5b60059a909a556006989098556007969096556008989098555050600b8054921515750100000000000000000000000000000000000000000002600160a81b60ff02196001600160a01b03998a166001600160a01b03199586161716179055600c80549188169183169190911790556001805495871695821695909517909455600280549186169185169190911790556003805491851691841691909117905560048054919093169116179055610fec806102136000396000f3fe6080604052600436106101d85760003560e01c80637461df1111610102578063cb0ef21d11610095578063e852e74111610064578063e852e7411461052c578063ef46e0ca14610541578063f2fde38b14610571578063f7fa7202146105a4576101d8565b8063cb0ef21d146104a4578063cc0e97c9146104b9578063cd61a95a146104ce578063d95393eb14610517576101d8565b80638da5cb5b116100d15780638da5cb5b1461043b5780638f32d59b1461045057806394d5567a14610465578063ab7b1c891461047a576101d8565b80637461df111461037257806376017b6414610387578063878f76031461039c5780638b98a2c5146103b1576101d8565b806350fbd6421161017a57806362141fcc1161014957806362141fcc1461030a5780636db153de1461031f5780636f17591f14610334578063715018a61461035d576101d8565b806350fbd642146102b657806359690e70146102cb5780635f2d554b146102e05780635f82c67e146102f5576101d8565b80632fe7d446116101b65780632fe7d4461461022b57806338013f02146102405780633a4b66f1146102715780633bc3c23b14610286576101d8565b806303eeb4ca146101da5780632e27f486146102015780632f88471014610216575b005b3480156101e657600080fd5b506101ef6105b9565b60408051918252519081900360200190f35b34801561020d57600080fd5b506101ef6105bf565b34801561022257600080fd5b506101ef6106bf565b34801561023757600080fd5b506101ef6106c5565b34801561024c57600080fd5b506102556106cb565b604080516001600160a01b039092168252519081900360200190f35b34801561027d57600080fd5b506101ef6106da565b34801561029257600080fd5b5061029b6106e0565b60408051921515835260208301919091528051918290030190f35b3480156102c257600080fd5b506102556107ed565b3480156102d757600080fd5b5061029b6107fc565b3480156102ec57600080fd5b506101ef61086b565b34801561030157600080fd5b506102556108d8565b34801561031657600080fd5b506101ef6108e7565b34801561032b57600080fd5b506101ef6108ed565b34801561034057600080fd5b5061034961095a565b604080519115158252519081900360200190f35b34801561036957600080fd5b506101d861096a565b34801561037e57600080fd5b506101ef610a10565b34801561039357600080fd5b50610255610a7d565b3480156103a857600080fd5b50610255610a8c565b3480156103bd57600080fd5b506103c6610a9b565b6040805160208082528351818301528351919283929083019185019080838360005b838110156104005781810151838201526020016103e8565b50505050905090810190601f16801561042d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561044757600080fd5b50610255610abe565b34801561045c57600080fd5b50610349610acd565b34801561047157600080fd5b506101ef610ade565b34801561048657600080fd5b506101d86004803603602081101561049d57600080fd5b5035610ae4565b3480156104b057600080fd5b50610255610bce565b3480156104c557600080fd5b50610255610bdd565b3480156104da57600080fd5b506104fe600480360360408110156104f157600080fd5b5080359060200135610bec565b6040805192835260208301919091528051918290030190f35b34801561052357600080fd5b50610255610d11565b34801561053857600080fd5b50610349610d20565b34801561054d57600080fd5b506101d86004803603604081101561056457600080fd5b5080359060200135610d30565b34801561057d57600080fd5b506101d86004803603602081101561059457600080fd5b50356001600160a01b0316610e22565b3480156105b057600080fd5b506101ef610e8a565b60095481565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e11b631713fa43021781529151815160009485946060946001600160a01b039092169391928291908083835b6020831061062d5780518252601f19909201916020918201910161060e565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d806000811461068d576040519150601f19603f3d011682016040523d82523d6000602084013e610692565b606091505b5091509150816106a157600080fd5b8080602001905160208110156106b657600080fd5b50519250505090565b60085481565b60065481565b6002546001600160a01b031681565b60055481565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e01b633bc3c23b0217815291518151600094859485946060946001600160a01b039093169390929182918083835b602083106107505780518252601f199092019160209182019101610731565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d80600081146107b0576040519150601f19603f3d011682016040523d82523d6000602084013e6107b5565b606091505b5091509150816107c457600080fd5b8080602001905160408110156107d957600080fd5b508051602090910151909450925050509091565b6004546001600160a01b031681565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e41b63059690e70217815291518151600094859485946060946001600160a01b03909316939092918291808383602083106107505780518252601f199092019160209182019101610731565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e01b635f2d554b021781529151815160009485946060946001600160a01b039092169391928291908083836020831061062d5780518252601f19909201916020918201910161060e565b6001546001600160a01b031681565b60075481565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e11b6336d8a9ef021781529151815160009485946060946001600160a01b039092169391928291908083836020831061062d5780518252601f19909201916020918201910161060e565b600b54600160a81b900460ff1681565b610972610acd565b6109c65760408051600160e51b62461bcd02815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e01b637461df11021781529151815160009485946060946001600160a01b039092169391928291908083836020831061062d5780518252601f19909201916020918201910161060e565b600b546001600160a01b031681565b6003546001600160a01b031681565b604051806040016040528060048152602001600160e01b635045524d0281525081565b6000546001600160a01b031690565b6000546001600160a01b0316331490565b600a5481565b600c5460408051602480820185905282518083039091018152604490910182526020810180516001600160e01b0316600160e01b63ab7b1c8902178152915181516000946001600160a01b03169382918083835b60208310610b575780518252601f199092019160209182019101610b38565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d8060008114610bb7576040519150601f19603f3d011682016040523d82523d6000602084013e610bbc565b606091505b5050905080610bca57600080fd5b5050565b600e546001600160a01b031681565b600c546001600160a01b031681565b600c546040805160248101859052604480820185905282518083039091018152606490910182526020810180516001600160e01b0316600160e11b6366b0d4ad0217815291518151600094859485946060946001600160a01b039093169390929182918083835b60208310610c725780518252601f199092019160209182019101610c53565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d8060008114610cd2576040519150601f19603f3d011682016040523d82523d6000602084013e610cd7565b606091505b509150915081610ce657600080fd5b808060200190516040811015610cfb57600080fd5b5080516020909101519097909650945050505050565b600d546001600160a01b031681565b600b54600160a01b900460ff1681565b600c546040805160248101859052604480820185905282518083039091018152606490910182526020810180516001600160e01b0316600160e11b6377a3706502178152915181516000946001600160a01b03169382918083835b60208310610daa5780518252601f199092019160209182019101610d8b565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d8060008114610e0a576040519150601f19603f3d011682016040523d82523d6000602084013e610e0f565b606091505b5050905080610e1d57600080fd5b505050565b610e2a610acd565b610e7e5760408051600160e51b62461bcd02815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b610e8781610ef7565b50565b600c5460408051600481526024810182526020810180516001600160e01b0316600160e11b637bfd3901021781529151815160009485946060946001600160a01b039092169391928291908083836020831061062d5780518252601f19909201916020918201910161060e565b6001600160a01b038116610f3f57604051600160e51b62461bcd028152600401808060200182810382526026815260200180610f9b6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b039290921691909117905556fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373a165627a7a72305820f2c91c2f74d5d7f43012ab2bd1c4eefeee9ab4e1af2bcf2b3849a6e113950f6f0029a165627a7a7230582022f62c38d60a858af5740acd71f8075c1e02a64d05c7cf572b1674589110e6370029

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000215827fe862ea5a449677c20672022a8d01566de000000000000000000000000efd9a8d7bd9753a732c2c01b1c3261625890061f00000000000000000000000012860ccd1e84d5dcc008901d8ae38fa7114e56b3000000000000000000000000629118bd40556d3cb3fb9ce48e64709a821578c800000000000000000000000089d24a6b4ccb1b6faa2625fe562bdd9a23260359000000000000000000000000818e6fecd516ecc3849daf6845e3ec868087b7550000000000000000000000003d9819210a31b4961b30ef54be2aed79b9c9cd3b00000000000000000000000002557a5e05defeffd4cae6d83ea3d173b272c904000000000000000000000000f5dce57282a584d2746faf1593d3121fcac444dc0000000000000000000000004ddc2d193948926d02f9b1fe9e1daa0718270ed5

-----Decoded View---------------
Arg [0] : _shortCERC20LogicContract (address): 0x215827FE862EA5A449677c20672022a8D01566De
Arg [1] : _shortCEtherLogicContract (address): 0xEFD9A8d7BD9753a732C2c01B1c3261625890061f
Arg [2] : _longCERC20LogicContract (address): 0x12860CCd1E84D5dcC008901d8aE38fa7114e56B3
Arg [3] : _longCEtherLogicContract (address): 0x629118bD40556D3CB3Fb9ce48E64709A821578C8
Arg [4] : _daiAddr (address): 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359
Arg [5] : _kyberAddr (address): 0x818E6FECD516Ecc3849DAf6845e3EC868087B755
Arg [6] : _comptrollerAddr (address): 0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B
Arg [7] : _priceOracleAddr (address): 0x02557a5E05DeFeFFD4cAe6D83eA3d173B272c904
Arg [8] : _cDAIAddr (address): 0xF5DCe57282A584D2746FaF1593d3121Fcac444dC
Arg [9] : _cETHAddr (address): 0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5

-----Encoded View---------------
10 Constructor Arguments found :
Arg [0] : 000000000000000000000000215827fe862ea5a449677c20672022a8d01566de
Arg [1] : 000000000000000000000000efd9a8d7bd9753a732c2c01b1c3261625890061f
Arg [2] : 00000000000000000000000012860ccd1e84d5dcc008901d8ae38fa7114e56b3
Arg [3] : 000000000000000000000000629118bd40556d3cb3fb9ce48e64709a821578c8
Arg [4] : 00000000000000000000000089d24a6b4ccb1b6faa2625fe562bdd9a23260359
Arg [5] : 000000000000000000000000818e6fecd516ecc3849daf6845e3ec868087b755
Arg [6] : 0000000000000000000000003d9819210a31b4961b30ef54be2aed79b9c9cd3b
Arg [7] : 00000000000000000000000002557a5e05defeffd4cae6d83ea3d173b272c904
Arg [8] : 000000000000000000000000f5dce57282a584d2746faf1593d3121fcac444dc
Arg [9] : 0000000000000000000000004ddc2d193948926d02f9b1fe9e1daa0718270ed5


Swarm Source

bzzr://22f62c38d60a858af5740acd71f8075c1e02a64d05c7cf572b1674589110e637

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.