Contract 0x9712DdCC43F42402acC483e297eeFf650d18D354

Contract Overview

Balance:
0 Ether

Token:
Txn Hash Method
Block
From
To
Value
0x9f13c2f154ea718073d3350022868b826e186666b31227e5883503dfb5898f53Get Reward247516822021-05-09 12:20:449 days 7 hrs ago0x57170b6ae91d06102ec7d984d551d590ce1504e5 IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.0003711063
0x9c7e380537246ab30adf8c138889437502c9615cfe872430e256d76eb063e551Repay245713132021-04-30 20:25:2417 days 23 hrs ago0x460f0f944aa6736903cb591e89f9111ac0ca7e7b IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.05343714453
0x6b660921859008ab217ea11b15b6a0a3b80c1c0f776f4d6fcea09ff745940d35Withdraw245700642021-04-30 19:01:2418 days 39 mins ago0x460f0f944aa6736903cb591e89f9111ac0ca7e7b IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.02056345551
0x701422c916bc74fd1052d93a5def9e996e0859128c1a0c0599a5f57ccf9cf134Open245686082021-04-30 17:22:3618 days 2 hrs ago0x460f0f944aa6736903cb591e89f9111ac0ca7e7b IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.07073786871
0x9fa04c631ebb8740d44d6e6e91af158d180e427e1c987ba854d4e6a3e6f20320Open245673602021-04-30 15:58:1218 days 3 hrs ago0x460f0f944aa6736903cb591e89f9111ac0ca7e7b IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.07896587279
0xbcc7f05f4b046e3c4b2a333a0eea31f35c4472abc085cf8babdcc68f69e4b5b4Draw245255632021-04-28 16:50:2020 days 2 hrs ago0xdf0b4944f09807b6cd38afd33169cce1364acacf IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.0017434323
0x1db06b0b79ca4e888f920d3716400d84ae58ca77441ec2742cc6c669a380db65Get Reward245255582021-04-28 16:50:0020 days 2 hrs ago0xdf0b4944f09807b6cd38afd33169cce1364acacf IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.0003711063
0x0fa686f24010767b7cd6b4d00980d0ccf168d166128783b7e549fd9d36ad40ccOpen245246012021-04-28 15:44:0420 days 3 hrs ago0x460f0f944aa6736903cb591e89f9111ac0ca7e7b IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.09670832197
0x1529ca649c22c61a0a46971da3c6966b885d25b3fa3aee975cf509394cb35a2cGet Reward244820682021-04-26 15:40:1622 days 4 hrs ago0x88bcda20db72ef38f381b214779a6dc1e836fa24 IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.0002174042
0xc45bf73b5d505978362000b927cc9f2a1bc0bd5008a0950dc312ee933ea31092Open244819822021-04-26 15:34:2022 days 4 hrs ago0x88bcda20db72ef38f381b214779a6dc1e836fa24 IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.002042282
0xd747b1e3d5eebf1a6319880dd4035b30d5b76730db37747cfad60812066c24deOpen244174562021-04-23 14:26:1625 days 5 hrs ago0x460f0f944aa6736903cb591e89f9111ac0ca7e7b IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.08996105391
0x6fd7b237b383c89edf2f619000c9e9f431a1552ce08d69fff616c4d9a4d0ebedOpen244174332021-04-23 14:24:4425 days 5 hrs ago0x460f0f944aa6736903cb591e89f9111ac0ca7e7b IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.08827349389
0xd479d3f1c08435dee621044f873706979f0a32333ee8507f04202aea0120d3c4Open243937432021-04-22 11:40:2026 days 8 hrs ago0x8dd7b3223b9c2f18b0f4b4108ed2a506f824b1ce IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.104623678101
0x19edd3ffda8a259c894b63b15c95ebb82fee7e6e30bdb5b87181eb80aa10d04aGet Reward243937382021-04-22 11:40:0026 days 8 hrs ago0x8dd7b3223b9c2f18b0f4b4108ed2a506f824b1ce IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.011832453101
0x16faad5178e2cca7250219c2f25ac385ea086b7f3acb2501c627e767ebc4cc66Open243937272021-04-22 11:39:1626 days 8 hrs ago0x8dd7b3223b9c2f18b0f4b4108ed2a506f824b1ce IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.1033303100
0x1101cafeb2339dd33fe72928a16c4c7640dbb9f05875401198769ef0ffabeafcOpen243937252021-04-22 11:39:0826 days 8 hrs ago0x8dd7b3223b9c2f18b0f4b4108ed2a506f824b1ce IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.103486572103
0x3fef6f02220e80dea2afe0ad3e6e093f91975982667dae77d4209ac284876720Get Reward243937212021-04-22 11:38:5226 days 8 hrs ago0x8dd7b3223b9c2f18b0f4b4108ed2a506f824b1ce IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.014453418106
0xb242c1071c0081d4e2424064c76acd2b5b65e5a9a2cf90887eeee81facf63dcbOpen243785582021-04-21 18:34:5627 days 1 hr ago0x88bcda20db72ef38f381b214779a6dc1e836fa24 IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.0020885742
0x0bee20a445983ad6d9d4e60d4ce955a8073a1a436d9ec1c9db8f79783efdd05fAccept Ownership243386202021-04-19 21:37:0428 days 22 hrs ago0x73570075092502472e4b61a7058df1a4a1db12f2 IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.0000220661
0xac36cddfa5d4c97ebaeb71791d124d54ac0453820f1cc1acfe99d0807d9a1975Nominate New Own...243376862021-04-19 20:33:5228 days 23 hrs ago0xb64ff7a4a33acdf48d97dab0d764afd0f6176882 IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.000044861
0x6fcaf0b3c7e0f8dd8cf1a22731b0db0a057a770bab6ddfde47e617674594857cOpen243125452021-04-18 11:10:1230 days 8 hrs ago0xd7d4a7f14265b0a69ae482b85b0a8496c3f99fb9 IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.0103380210
0x8ea0a8c20e47b385d0d4dac772ea02c4cc66f87e05c6c9286ccb05212246368cOpen242483872021-04-14 9:40:2834 days 10 hrs ago0x57170b6ae91d06102ec7d984d551d590ce1504e5 IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.0009944181
0x2bb725925b6b1918ef28c4663af50ef8de702272ff2397fbd5d1fa5f3e8a626fLiquidate242424742021-04-13 17:21:3235 days 2 hrs ago0x57170b6ae91d06102ec7d984d551d590ce1504e5 IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.0000497471
0x65ec74838101c1d1bafc9390a44cb5af98b8d620db901cd32dbcc5a647f3c418Liquidate242424272021-04-13 17:15:1635 days 2 hrs ago0x57170b6ae91d06102ec7d984d551d590ce1504e5 IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.0000497471
0x5fd80c13b2adc8071404c4598b8f29a8ae266ccca7f2fa99550b22b3a01b352aLiquidate242424232021-04-13 17:14:4435 days 2 hrs ago0x57170b6ae91d06102ec7d984d551d590ce1504e5 IN  0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether0.0000497471
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x17e3969182b141fa4b6733a529bf8b744254d4fdeccb0734b248fc830c818145248081542021-05-13 4:54:085 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x17e3969182b141fa4b6733a529bf8b744254d4fdeccb0734b248fc830c818145248081542021-05-13 4:54:085 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x17e3969182b141fa4b6733a529bf8b744254d4fdeccb0734b248fc830c818145248081542021-05-13 4:54:085 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x17e3969182b141fa4b6733a529bf8b744254d4fdeccb0734b248fc830c818145248081542021-05-13 4:54:085 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x17e3969182b141fa4b6733a529bf8b744254d4fdeccb0734b248fc830c818145248081542021-05-13 4:54:085 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x17e3969182b141fa4b6733a529bf8b744254d4fdeccb0734b248fc830c818145248081542021-05-13 4:54:085 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x17e3969182b141fa4b6733a529bf8b744254d4fdeccb0734b248fc830c818145248081542021-05-13 4:54:085 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x17e3969182b141fa4b6733a529bf8b744254d4fdeccb0734b248fc830c818145248081542021-05-13 4:54:085 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x17e3969182b141fa4b6733a529bf8b744254d4fdeccb0734b248fc830c818145248081542021-05-13 4:54:085 days 14 hrs ago 0x84f87e3636aa9cc1080c07e6c61adfdcc23c0db6 0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether
0x1aab9c6e10f60e5091ed166fd27aa7398ff7bdae589e29e936cdf3ed7385e0d0248080262021-05-13 4:41:325 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x1aab9c6e10f60e5091ed166fd27aa7398ff7bdae589e29e936cdf3ed7385e0d0248080262021-05-13 4:41:325 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x1aab9c6e10f60e5091ed166fd27aa7398ff7bdae589e29e936cdf3ed7385e0d0248080262021-05-13 4:41:325 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x1aab9c6e10f60e5091ed166fd27aa7398ff7bdae589e29e936cdf3ed7385e0d0248080262021-05-13 4:41:325 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x1aab9c6e10f60e5091ed166fd27aa7398ff7bdae589e29e936cdf3ed7385e0d0248080262021-05-13 4:41:325 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x1aab9c6e10f60e5091ed166fd27aa7398ff7bdae589e29e936cdf3ed7385e0d0248080262021-05-13 4:41:325 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x1aab9c6e10f60e5091ed166fd27aa7398ff7bdae589e29e936cdf3ed7385e0d0248080262021-05-13 4:41:325 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x1aab9c6e10f60e5091ed166fd27aa7398ff7bdae589e29e936cdf3ed7385e0d0248080262021-05-13 4:41:325 days 14 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x242a3df52c375bee81b1c668741d7c63af68fdd20 Ether
0x1aab9c6e10f60e5091ed166fd27aa7398ff7bdae589e29e936cdf3ed7385e0d0248080262021-05-13 4:41:325 days 14 hrs ago 0x84f87e3636aa9cc1080c07e6c61adfdcc23c0db6 0x9712ddcc43f42402acc483e297eeff650d18d3540 Ether
0x9f13c2f154ea718073d3350022868b826e186666b31227e5883503dfb5898f53247516822021-05-09 12:20:449 days 7 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0xceecb8d9c19abe84e13a2b6de3f5ad6e2991fe6d0 Ether
0x9c7e380537246ab30adf8c138889437502c9615cfe872430e256d76eb063e551245713132021-04-30 20:25:2417 days 23 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0xd74e3a605a1a7a8a83d25df00d4057985e3cac300 Ether
0x9c7e380537246ab30adf8c138889437502c9615cfe872430e256d76eb063e551245713132021-04-30 20:25:2417 days 23 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x2fb33e35829d2bb04d8b5eb9531da129e72bced40 Ether
0x9c7e380537246ab30adf8c138889437502c9615cfe872430e256d76eb063e551245713132021-04-30 20:25:2417 days 23 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0xf1d0ee19af243bcbc140a2259290b490e4df92a90 Ether
0x9c7e380537246ab30adf8c138889437502c9615cfe872430e256d76eb063e551245713132021-04-30 20:25:2417 days 23 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x945d2dffee2d478d3d32e0f42b9649d1cbae55280 Ether
0x9c7e380537246ab30adf8c138889437502c9615cfe872430e256d76eb063e551245713132021-04-30 20:25:2417 days 23 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x53bae964339e8a742b5b47f6c10bbfa8ff138f340 Ether
0x9c7e380537246ab30adf8c138889437502c9615cfe872430e256d76eb063e551245713132021-04-30 20:25:2417 days 23 hrs ago 0x9712ddcc43f42402acc483e297eeff650d18d354 0x2fb33e35829d2bb04d8b5eb9531da129e72bced40 Ether
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CollateralShort

Compiler Version
v0.5.16+commit.9c3226ce

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity)

/**
 *Submitted for verification at Etherscan.io on 2021-01-13
*/

/*
   ____            __   __        __   _
  / __/__ __ ___  / /_ / /  ___  / /_ (_)__ __
 _\ \ / // // _ \/ __// _ \/ -_)/ __// / \ \ /
/___/ \_, //_//_/\__//_//_/\__/ \__//_/ /_\_\
     /___/

* Synthetix: CollateralShort.sol
*
* Latest source (may be newer): https://github.com/Synthetixio/synthetix/blob/master/contracts/CollateralShort.sol
* Docs: https://docs.synthetix.io/contracts/CollateralShort
*
* Contract Dependencies: 
*	- Collateral
*	- IAddressResolver
*	- ICollateralLoan
*	- MixinResolver
*	- MixinSystemSettings
*	- Owned
*	- State
* Libraries: 
*	- SafeDecimalMath
*	- SafeMath
*
* MIT License
* ===========
*
* Copyright (c) 2021 Synthetix
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/



pragma solidity ^0.5.16;


// https://docs.synthetix.io/contracts/source/contracts/owned
contract Owned {
    address public owner;
    address public nominatedOwner;

    constructor(address _owner) public {
        require(_owner != address(0), "Owner address cannot be 0");
        owner = _owner;
        emit OwnerChanged(address(0), _owner);
    }

    function nominateNewOwner(address _owner) external onlyOwner {
        nominatedOwner = _owner;
        emit OwnerNominated(_owner);
    }

    function acceptOwnership() external {
        require(msg.sender == nominatedOwner, "You must be nominated before you can accept ownership");
        emit OwnerChanged(owner, nominatedOwner);
        owner = nominatedOwner;
        nominatedOwner = address(0);
    }

    modifier onlyOwner {
        _onlyOwner();
        _;
    }

    function _onlyOwner() private view {
        require(msg.sender == owner, "Only the contract owner may perform this action");
    }

    event OwnerNominated(address newOwner);
    event OwnerChanged(address oldOwner, address newOwner);
}


// https://docs.synthetix.io/contracts/source/interfaces/iaddressresolver
interface IAddressResolver {
    function getAddress(bytes32 name) external view returns (address);

    function getSynth(bytes32 key) external view returns (address);

    function requireAndGetAddress(bytes32 name, string calldata reason) external view returns (address);
}


// https://docs.synthetix.io/contracts/source/interfaces/isynth
interface ISynth {
    // Views
    function currencyKey() external view returns (bytes32);

    function transferableSynths(address account) external view returns (uint);

    // Mutative functions
    function transferAndSettle(address to, uint value) external returns (bool);

    function transferFromAndSettle(
        address from,
        address to,
        uint value
    ) external returns (bool);

    // Restricted: used internally to Synthetix
    function burn(address account, uint amount) external;

    function issue(address account, uint amount) external;
}


// https://docs.synthetix.io/contracts/source/interfaces/iissuer
interface IIssuer {
    // Views
    function anySynthOrSNXRateIsInvalid() external view returns (bool anyRateInvalid);

    function availableCurrencyKeys() external view returns (bytes32[] memory);

    function availableSynthCount() external view returns (uint);

    function availableSynths(uint index) external view returns (ISynth);

    function canBurnSynths(address account) external view returns (bool);

    function collateral(address account) external view returns (uint);

    function collateralisationRatio(address issuer) external view returns (uint);

    function collateralisationRatioAndAnyRatesInvalid(address _issuer)
        external
        view
        returns (uint cratio, bool anyRateIsInvalid);

    function debtBalanceOf(address issuer, bytes32 currencyKey) external view returns (uint debtBalance);

    function issuanceRatio() external view returns (uint);

    function lastIssueEvent(address account) external view returns (uint);

    function maxIssuableSynths(address issuer) external view returns (uint maxIssuable);

    function minimumStakeTime() external view returns (uint);

    function remainingIssuableSynths(address issuer)
        external
        view
        returns (
            uint maxIssuable,
            uint alreadyIssued,
            uint totalSystemDebt
        );

    function synths(bytes32 currencyKey) external view returns (ISynth);

    function getSynths(bytes32[] calldata currencyKeys) external view returns (ISynth[] memory);

    function synthsByAddress(address synthAddress) external view returns (bytes32);

    function totalIssuedSynths(bytes32 currencyKey, bool excludeEtherCollateral) external view returns (uint);

    function transferableSynthetixAndAnyRateIsInvalid(address account, uint balance)
        external
        view
        returns (uint transferable, bool anyRateIsInvalid);

    // Restricted: used internally to Synthetix
    function issueSynths(address from, uint amount) external;

    function issueSynthsOnBehalf(
        address issueFor,
        address from,
        uint amount
    ) external;

    function issueMaxSynths(address from) external;

    function issueMaxSynthsOnBehalf(address issueFor, address from) external;

    function burnSynths(address from, uint amount) external;

    function burnSynthsOnBehalf(
        address burnForAddress,
        address from,
        uint amount
    ) external;

    function burnSynthsToTarget(address from) external;

    function burnSynthsToTargetOnBehalf(address burnForAddress, address from) external;

    function liquidateDelinquentAccount(
        address account,
        uint susdAmount,
        address liquidator
    ) external returns (uint totalRedeemed, uint amountToLiquidate);
}


// Inheritance


// Internal references


// https://docs.synthetix.io/contracts/source/contracts/addressresolver
contract AddressResolver is Owned, IAddressResolver {
    mapping(bytes32 => address) public repository;

    constructor(address _owner) public Owned(_owner) {}

    /* ========== RESTRICTED FUNCTIONS ========== */

    function importAddresses(bytes32[] calldata names, address[] calldata destinations) external onlyOwner {
        require(names.length == destinations.length, "Input lengths must match");

        for (uint i = 0; i < names.length; i++) {
            bytes32 name = names[i];
            address destination = destinations[i];
            repository[name] = destination;
            emit AddressImported(name, destination);
        }
    }

    /* ========= PUBLIC FUNCTIONS ========== */

    function rebuildCaches(MixinResolver[] calldata destinations) external {
        for (uint i = 0; i < destinations.length; i++) {
            destinations[i].rebuildCache();
        }
    }

    /* ========== VIEWS ========== */

    function areAddressesImported(bytes32[] calldata names, address[] calldata destinations) external view returns (bool) {
        for (uint i = 0; i < names.length; i++) {
            if (repository[names[i]] != destinations[i]) {
                return false;
            }
        }
        return true;
    }

    function getAddress(bytes32 name) external view returns (address) {
        return repository[name];
    }

    function requireAndGetAddress(bytes32 name, string calldata reason) external view returns (address) {
        address _foundAddress = repository[name];
        require(_foundAddress != address(0), reason);
        return _foundAddress;
    }

    function getSynth(bytes32 key) external view returns (address) {
        IIssuer issuer = IIssuer(repository["Issuer"]);
        require(address(issuer) != address(0), "Cannot find Issuer address");
        return address(issuer.synths(key));
    }

    /* ========== EVENTS ========== */

    event AddressImported(bytes32 name, address destination);
}


// solhint-disable payable-fallback

// https://docs.synthetix.io/contracts/source/contracts/readproxy
contract ReadProxy is Owned {
    address public target;

    constructor(address _owner) public Owned(_owner) {}

    function setTarget(address _target) external onlyOwner {
        target = _target;
        emit TargetUpdated(target);
    }

    function() external {
        // The basics of a proxy read call
        // Note that msg.sender in the underlying will always be the address of this contract.
        assembly {
            calldatacopy(0, 0, calldatasize)

            // Use of staticcall - this will revert if the underlying function mutates state
            let result := staticcall(gas, sload(target_slot), 0, calldatasize, 0, 0)
            returndatacopy(0, 0, returndatasize)

            if iszero(result) {
                revert(0, returndatasize)
            }
            return(0, returndatasize)
        }
    }

    event TargetUpdated(address newTarget);
}


// Inheritance


// Internal references


// https://docs.synthetix.io/contracts/source/contracts/mixinresolver
contract MixinResolver {
    AddressResolver public resolver;

    mapping(bytes32 => address) private addressCache;

    constructor(address _resolver) internal {
        resolver = AddressResolver(_resolver);
    }

    /* ========== INTERNAL FUNCTIONS ========== */

    function combineArrays(bytes32[] memory first, bytes32[] memory second)
        internal
        pure
        returns (bytes32[] memory combination)
    {
        combination = new bytes32[](first.length + second.length);

        for (uint i = 0; i < first.length; i++) {
            combination[i] = first[i];
        }

        for (uint j = 0; j < second.length; j++) {
            combination[first.length + j] = second[j];
        }
    }

    /* ========== PUBLIC FUNCTIONS ========== */

    // Note: this function is public not external in order for it to be overridden and invoked via super in subclasses
    function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {}

    function rebuildCache() public {
        bytes32[] memory requiredAddresses = resolverAddressesRequired();
        // The resolver must call this function whenver it updates its state
        for (uint i = 0; i < requiredAddresses.length; i++) {
            bytes32 name = requiredAddresses[i];
            // Note: can only be invoked once the resolver has all the targets needed added
            address destination = resolver.requireAndGetAddress(
                name,
                string(abi.encodePacked("Resolver missing target: ", name))
            );
            addressCache[name] = destination;
            emit CacheUpdated(name, destination);
        }
    }

    /* ========== VIEWS ========== */

    function isResolverCached() external view returns (bool) {
        bytes32[] memory requiredAddresses = resolverAddressesRequired();
        for (uint i = 0; i < requiredAddresses.length; i++) {
            bytes32 name = requiredAddresses[i];
            // false if our cache is invalid or if the resolver doesn't have the required address
            if (resolver.getAddress(name) != addressCache[name] || addressCache[name] == address(0)) {
                return false;
            }
        }

        return true;
    }

    /* ========== INTERNAL FUNCTIONS ========== */

    function requireAndGetAddress(bytes32 name) internal view returns (address) {
        address _foundAddress = addressCache[name];
        require(_foundAddress != address(0), string(abi.encodePacked("Missing address: ", name)));
        return _foundAddress;
    }

    /* ========== EVENTS ========== */

    event CacheUpdated(bytes32 name, address destination);
}


// https://docs.synthetix.io/contracts/source/interfaces/iflexiblestorage
interface IFlexibleStorage {
    // Views
    function getUIntValue(bytes32 contractName, bytes32 record) external view returns (uint);

    function getUIntValues(bytes32 contractName, bytes32[] calldata records) external view returns (uint[] memory);

    function getIntValue(bytes32 contractName, bytes32 record) external view returns (int);

    function getIntValues(bytes32 contractName, bytes32[] calldata records) external view returns (int[] memory);

    function getAddressValue(bytes32 contractName, bytes32 record) external view returns (address);

    function getAddressValues(bytes32 contractName, bytes32[] calldata records) external view returns (address[] memory);

    function getBoolValue(bytes32 contractName, bytes32 record) external view returns (bool);

    function getBoolValues(bytes32 contractName, bytes32[] calldata records) external view returns (bool[] memory);

    function getBytes32Value(bytes32 contractName, bytes32 record) external view returns (bytes32);

    function getBytes32Values(bytes32 contractName, bytes32[] calldata records) external view returns (bytes32[] memory);

    // Mutative functions
    function deleteUIntValue(bytes32 contractName, bytes32 record) external;

    function deleteIntValue(bytes32 contractName, bytes32 record) external;

    function deleteAddressValue(bytes32 contractName, bytes32 record) external;

    function deleteBoolValue(bytes32 contractName, bytes32 record) external;

    function deleteBytes32Value(bytes32 contractName, bytes32 record) external;

    function setUIntValue(
        bytes32 contractName,
        bytes32 record,
        uint value
    ) external;

    function setUIntValues(
        bytes32 contractName,
        bytes32[] calldata records,
        uint[] calldata values
    ) external;

    function setIntValue(
        bytes32 contractName,
        bytes32 record,
        int value
    ) external;

    function setIntValues(
        bytes32 contractName,
        bytes32[] calldata records,
        int[] calldata values
    ) external;

    function setAddressValue(
        bytes32 contractName,
        bytes32 record,
        address value
    ) external;

    function setAddressValues(
        bytes32 contractName,
        bytes32[] calldata records,
        address[] calldata values
    ) external;

    function setBoolValue(
        bytes32 contractName,
        bytes32 record,
        bool value
    ) external;

    function setBoolValues(
        bytes32 contractName,
        bytes32[] calldata records,
        bool[] calldata values
    ) external;

    function setBytes32Value(
        bytes32 contractName,
        bytes32 record,
        bytes32 value
    ) external;

    function setBytes32Values(
        bytes32 contractName,
        bytes32[] calldata records,
        bytes32[] calldata values
    ) external;
}


// Internal references


// https://docs.synthetix.io/contracts/source/contracts/mixinsystemsettings
contract MixinSystemSettings is MixinResolver {
    bytes32 internal constant SETTING_CONTRACT_NAME = "SystemSettings";

    bytes32 internal constant SETTING_WAITING_PERIOD_SECS = "waitingPeriodSecs";
    bytes32 internal constant SETTING_PRICE_DEVIATION_THRESHOLD_FACTOR = "priceDeviationThresholdFactor";
    bytes32 internal constant SETTING_ISSUANCE_RATIO = "issuanceRatio";
    bytes32 internal constant SETTING_FEE_PERIOD_DURATION = "feePeriodDuration";
    bytes32 internal constant SETTING_TARGET_THRESHOLD = "targetThreshold";
    bytes32 internal constant SETTING_LIQUIDATION_DELAY = "liquidationDelay";
    bytes32 internal constant SETTING_LIQUIDATION_RATIO = "liquidationRatio";
    bytes32 internal constant SETTING_LIQUIDATION_PENALTY = "liquidationPenalty";
    bytes32 internal constant SETTING_RATE_STALE_PERIOD = "rateStalePeriod";
    bytes32 internal constant SETTING_EXCHANGE_FEE_RATE = "exchangeFeeRate";
    bytes32 internal constant SETTING_MINIMUM_STAKE_TIME = "minimumStakeTime";
    bytes32 internal constant SETTING_AGGREGATOR_WARNING_FLAGS = "aggregatorWarningFlags";
    bytes32 internal constant SETTING_TRADING_REWARDS_ENABLED = "tradingRewardsEnabled";
    bytes32 internal constant SETTING_DEBT_SNAPSHOT_STALE_TIME = "debtSnapshotStaleTime";
    bytes32 internal constant SETTING_CROSS_DOMAIN_DEPOSIT_GAS_LIMIT = "crossDomainDepositGasLimit";
    bytes32 internal constant SETTING_CROSS_DOMAIN_ESCROW_GAS_LIMIT = "crossDomainEscrowGasLimit";
    bytes32 internal constant SETTING_CROSS_DOMAIN_REWARD_GAS_LIMIT = "crossDomainRewardGasLimit";
    bytes32 internal constant SETTING_CROSS_DOMAIN_WITHDRAWAL_GAS_LIMIT = "crossDomainWithdrawalGasLimit";

    bytes32 internal constant CONTRACT_FLEXIBLESTORAGE = "FlexibleStorage";

    enum CrossDomainMessageGasLimits {Deposit, Escrow, Reward, Withdrawal}

    constructor(address _resolver) internal MixinResolver(_resolver) {}

    function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
        addresses = new bytes32[](1);
        addresses[0] = CONTRACT_FLEXIBLESTORAGE;
    }

    function flexibleStorage() internal view returns (IFlexibleStorage) {
        return IFlexibleStorage(requireAndGetAddress(CONTRACT_FLEXIBLESTORAGE));
    }

    function _getGasLimitSetting(CrossDomainMessageGasLimits gasLimitType) internal pure returns (bytes32) {
        if (gasLimitType == CrossDomainMessageGasLimits.Deposit) {
            return SETTING_CROSS_DOMAIN_DEPOSIT_GAS_LIMIT;
        } else if (gasLimitType == CrossDomainMessageGasLimits.Escrow) {
            return SETTING_CROSS_DOMAIN_ESCROW_GAS_LIMIT;
        } else if (gasLimitType == CrossDomainMessageGasLimits.Reward) {
            return SETTING_CROSS_DOMAIN_REWARD_GAS_LIMIT;
        } else if (gasLimitType == CrossDomainMessageGasLimits.Withdrawal) {
            return SETTING_CROSS_DOMAIN_WITHDRAWAL_GAS_LIMIT;
        } else {
            revert("Unknown gas limit type");
        }
    }

    function getCrossDomainMessageGasLimit(CrossDomainMessageGasLimits gasLimitType) internal view returns (uint) {
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, _getGasLimitSetting(gasLimitType));
    }

    function getTradingRewardsEnabled() internal view returns (bool) {
        return flexibleStorage().getBoolValue(SETTING_CONTRACT_NAME, SETTING_TRADING_REWARDS_ENABLED);
    }

    function getWaitingPeriodSecs() internal view returns (uint) {
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_WAITING_PERIOD_SECS);
    }

    function getPriceDeviationThresholdFactor() internal view returns (uint) {
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_PRICE_DEVIATION_THRESHOLD_FACTOR);
    }

    function getIssuanceRatio() internal view returns (uint) {
        // lookup on flexible storage directly for gas savings (rather than via SystemSettings)
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_ISSUANCE_RATIO);
    }

    function getFeePeriodDuration() internal view returns (uint) {
        // lookup on flexible storage directly for gas savings (rather than via SystemSettings)
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_FEE_PERIOD_DURATION);
    }

    function getTargetThreshold() internal view returns (uint) {
        // lookup on flexible storage directly for gas savings (rather than via SystemSettings)
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_TARGET_THRESHOLD);
    }

    function getLiquidationDelay() internal view returns (uint) {
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_LIQUIDATION_DELAY);
    }

    function getLiquidationRatio() internal view returns (uint) {
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_LIQUIDATION_RATIO);
    }

    function getLiquidationPenalty() internal view returns (uint) {
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_LIQUIDATION_PENALTY);
    }

    function getRateStalePeriod() internal view returns (uint) {
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_RATE_STALE_PERIOD);
    }

    function getExchangeFeeRate(bytes32 currencyKey) internal view returns (uint) {
        return
            flexibleStorage().getUIntValue(
                SETTING_CONTRACT_NAME,
                keccak256(abi.encodePacked(SETTING_EXCHANGE_FEE_RATE, currencyKey))
            );
    }

    function getMinimumStakeTime() internal view returns (uint) {
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_MINIMUM_STAKE_TIME);
    }

    function getAggregatorWarningFlags() internal view returns (address) {
        return flexibleStorage().getAddressValue(SETTING_CONTRACT_NAME, SETTING_AGGREGATOR_WARNING_FLAGS);
    }

    function getDebtSnapshotStaleTime() internal view returns (uint) {
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_DEBT_SNAPSHOT_STALE_TIME);
    }
}


pragma experimental ABIEncoderV2;


interface ICollateralLoan {
    struct Loan {
        // ID for the loan
        uint id;
        //  Acccount that created the loan
        address payable account;
        //  Amount of collateral deposited
        uint collateral;
        // The synth that was borowed
        bytes32 currency;
        //  Amount of synths borrowed
        uint amount;
        // Indicates if the position was short sold
        bool short;
        // interest amounts accrued
        uint accruedInterest;
        // last interest index
        uint interestIndex;
        // time of last interaction.
        uint lastInteraction;
    }
}


/**
 * @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;
    }
}


// Libraries


// https://docs.synthetix.io/contracts/source/libraries/safedecimalmath
library SafeDecimalMath {
    using SafeMath for uint;

    /* Number of decimal places in the representations. */
    uint8 public constant decimals = 18;
    uint8 public constant highPrecisionDecimals = 27;

    /* The number representing 1.0. */
    uint public constant UNIT = 10**uint(decimals);

    /* The number representing 1.0 for higher fidelity numbers. */
    uint public constant PRECISE_UNIT = 10**uint(highPrecisionDecimals);
    uint private constant UNIT_TO_HIGH_PRECISION_CONVERSION_FACTOR = 10**uint(highPrecisionDecimals - decimals);

    /**
     * @return Provides an interface to UNIT.
     */
    function unit() external pure returns (uint) {
        return UNIT;
    }

    /**
     * @return Provides an interface to PRECISE_UNIT.
     */
    function preciseUnit() external pure returns (uint) {
        return PRECISE_UNIT;
    }

    /**
     * @return The result of multiplying x and y, interpreting the operands as fixed-point
     * decimals.
     *
     * @dev A unit factor is divided out after the product of x and y is evaluated,
     * so that product must be less than 2**256. As this is an integer division,
     * the internal division always rounds down. This helps save on gas. Rounding
     * is more expensive on gas.
     */
    function multiplyDecimal(uint x, uint y) internal pure returns (uint) {
        /* Divide by UNIT to remove the extra factor introduced by the product. */
        return x.mul(y) / UNIT;
    }

    /**
     * @return The result of safely multiplying x and y, interpreting the operands
     * as fixed-point decimals of the specified precision unit.
     *
     * @dev The operands should be in the form of a the specified unit factor which will be
     * divided out after the product of x and y is evaluated, so that product must be
     * less than 2**256.
     *
     * Unlike multiplyDecimal, this function rounds the result to the nearest increment.
     * Rounding is useful when you need to retain fidelity for small decimal numbers
     * (eg. small fractions or percentages).
     */
    function _multiplyDecimalRound(
        uint x,
        uint y,
        uint precisionUnit
    ) private pure returns (uint) {
        /* Divide by UNIT to remove the extra factor introduced by the product. */
        uint quotientTimesTen = x.mul(y) / (precisionUnit / 10);

        if (quotientTimesTen % 10 >= 5) {
            quotientTimesTen += 10;
        }

        return quotientTimesTen / 10;
    }

    /**
     * @return The result of safely multiplying x and y, interpreting the operands
     * as fixed-point decimals of a precise unit.
     *
     * @dev The operands should be in the precise unit factor which will be
     * divided out after the product of x and y is evaluated, so that product must be
     * less than 2**256.
     *
     * Unlike multiplyDecimal, this function rounds the result to the nearest increment.
     * Rounding is useful when you need to retain fidelity for small decimal numbers
     * (eg. small fractions or percentages).
     */
    function multiplyDecimalRoundPrecise(uint x, uint y) internal pure returns (uint) {
        return _multiplyDecimalRound(x, y, PRECISE_UNIT);
    }

    /**
     * @return The result of safely multiplying x and y, interpreting the operands
     * as fixed-point decimals of a standard unit.
     *
     * @dev The operands should be in the standard unit factor which will be
     * divided out after the product of x and y is evaluated, so that product must be
     * less than 2**256.
     *
     * Unlike multiplyDecimal, this function rounds the result to the nearest increment.
     * Rounding is useful when you need to retain fidelity for small decimal numbers
     * (eg. small fractions or percentages).
     */
    function multiplyDecimalRound(uint x, uint y) internal pure returns (uint) {
        return _multiplyDecimalRound(x, y, UNIT);
    }

    /**
     * @return The result of safely dividing x and y. The return value is a high
     * precision decimal.
     *
     * @dev y is divided after the product of x and the standard precision unit
     * is evaluated, so the product of x and UNIT must be less than 2**256. As
     * this is an integer division, the result is always rounded down.
     * This helps save on gas. Rounding is more expensive on gas.
     */
    function divideDecimal(uint x, uint y) internal pure returns (uint) {
        /* Reintroduce the UNIT factor that will be divided out by y. */
        return x.mul(UNIT).div(y);
    }

    /**
     * @return The result of safely dividing x and y. The return value is as a rounded
     * decimal in the precision unit specified in the parameter.
     *
     * @dev y is divided after the product of x and the specified precision unit
     * is evaluated, so the product of x and the specified precision unit must
     * be less than 2**256. The result is rounded to the nearest increment.
     */
    function _divideDecimalRound(
        uint x,
        uint y,
        uint precisionUnit
    ) private pure returns (uint) {
        uint resultTimesTen = x.mul(precisionUnit * 10).div(y);

        if (resultTimesTen % 10 >= 5) {
            resultTimesTen += 10;
        }

        return resultTimesTen / 10;
    }

    /**
     * @return The result of safely dividing x and y. The return value is as a rounded
     * standard precision decimal.
     *
     * @dev y is divided after the product of x and the standard precision unit
     * is evaluated, so the product of x and the standard precision unit must
     * be less than 2**256. The result is rounded to the nearest increment.
     */
    function divideDecimalRound(uint x, uint y) internal pure returns (uint) {
        return _divideDecimalRound(x, y, UNIT);
    }

    /**
     * @return The result of safely dividing x and y. The return value is as a rounded
     * high precision decimal.
     *
     * @dev y is divided after the product of x and the high precision unit
     * is evaluated, so the product of x and the high precision unit must
     * be less than 2**256. The result is rounded to the nearest increment.
     */
    function divideDecimalRoundPrecise(uint x, uint y) internal pure returns (uint) {
        return _divideDecimalRound(x, y, PRECISE_UNIT);
    }

    /**
     * @dev Convert a standard decimal representation to a high precision one.
     */
    function decimalToPreciseDecimal(uint i) internal pure returns (uint) {
        return i.mul(UNIT_TO_HIGH_PRECISION_CONVERSION_FACTOR);
    }

    /**
     * @dev Convert a high precision decimal to a standard decimal representation.
     */
    function preciseDecimalToDecimal(uint i) internal pure returns (uint) {
        uint quotientTimesTen = i / (UNIT_TO_HIGH_PRECISION_CONVERSION_FACTOR / 10);

        if (quotientTimesTen % 10 >= 5) {
            quotientTimesTen += 10;
        }

        return quotientTimesTen / 10;
    }
}


// Inheritance


// https://docs.synthetix.io/contracts/source/contracts/state
contract State is Owned {
    // the address of the contract that can modify variables
    // this can only be changed by the owner of this contract
    address public associatedContract;

    constructor(address _associatedContract) internal {
        // This contract is abstract, and thus cannot be instantiated directly
        require(owner != address(0), "Owner must be set");

        associatedContract = _associatedContract;
        emit AssociatedContractUpdated(_associatedContract);
    }

    /* ========== SETTERS ========== */

    // Change the associated contract to a new address
    function setAssociatedContract(address _associatedContract) external onlyOwner {
        associatedContract = _associatedContract;
        emit AssociatedContractUpdated(_associatedContract);
    }

    /* ========== MODIFIERS ========== */

    modifier onlyAssociatedContract {
        require(msg.sender == associatedContract, "Only the associated contract can perform this action");
        _;
    }

    /* ========== EVENTS ========== */

    event AssociatedContractUpdated(address associatedContract);
}


// Inheritance


// Libraries


contract CollateralState is Owned, State, ICollateralLoan {
    using SafeMath for uint;
    using SafeDecimalMath for uint;

    mapping(address => Loan[]) public loans;

    constructor(address _owner, address _associatedContract) public Owned(_owner) State(_associatedContract) {}

    /* ========== VIEWS ========== */
    // If we do not find the loan, this returns a struct with 0'd values.
    function getLoan(address account, uint256 loanID) external view returns (Loan memory) {
        Loan[] memory accountLoans = loans[account];
        for (uint i = 0; i < accountLoans.length; i++) {
            if (accountLoans[i].id == loanID) {
                return (accountLoans[i]);
            }
        }
    }

    function getNumLoans(address account) external view returns (uint numLoans) {
        return loans[account].length;
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    function createLoan(Loan memory loan) public onlyAssociatedContract {
        loans[loan.account].push(loan);
    }

    function updateLoan(Loan memory loan) public onlyAssociatedContract {
        Loan[] storage accountLoans = loans[loan.account];
        for (uint i = 0; i < accountLoans.length; i++) {
            if (accountLoans[i].id == loan.id) {
                loans[loan.account][i] = loan;
            }
        }
    }
}


interface ICollateralManager {
    // Manager information
    function hasCollateral(address collateral) external view returns (bool);

    function isSynthManaged(bytes32 currencyKey) external view returns (bool);

    // State information
    function long(bytes32 synth) external view returns (uint amount);

    function short(bytes32 synth) external view returns (uint amount);

    function totalLong() external view returns (uint susdValue, bool anyRateIsInvalid);

    function totalShort() external view returns (uint susdValue, bool anyRateIsInvalid);

    function getBorrowRate() external view returns (uint borrowRate, bool anyRateIsInvalid);

    function getShortRate(bytes32 synth) external view returns (uint shortRate, bool rateIsInvalid);

    function getRatesAndTime(uint index)
        external
        view
        returns (
            uint entryRate,
            uint lastRate,
            uint lastUpdated,
            uint newIndex
        );

    function getShortRatesAndTime(bytes32 currency, uint index)
        external
        view
        returns (
            uint entryRate,
            uint lastRate,
            uint lastUpdated,
            uint newIndex
        );

    function exceedsDebtLimit(uint amount, bytes32 currency) external view returns (bool canIssue, bool anyRateIsInvalid);

    function areSynthsAndCurrenciesSet(bytes32[] calldata requiredSynthNamesInResolver, bytes32[] calldata synthKeys)
        external
        view
        returns (bool);

    function areShortableSynthsSet(bytes32[] calldata requiredSynthNamesInResolver, bytes32[] calldata synthKeys)
        external
        view
        returns (bool);

    // Loans
    function getNewLoanId() external returns (uint id);

    // Manager mutative
    function addCollaterals(address[] calldata collaterals) external;

    function removeCollaterals(address[] calldata collaterals) external;

    function addSynths(bytes32[] calldata synthNamesInResolver, bytes32[] calldata synthKeys) external;

    function removeSynths(bytes32[] calldata synths, bytes32[] calldata synthKeys) external;

    function addShortableSynths(bytes32[2][] calldata requiredSynthAndInverseNamesInResolver, bytes32[] calldata synthKeys)
        external;

    function removeShortableSynths(bytes32[] calldata synths) external;

    // State mutative
    function updateBorrowRates(uint rate) external;

    function updateShortRates(bytes32 currency, uint rate) external;

    function incrementLongs(bytes32 synth, uint amount) external;

    function decrementLongs(bytes32 synth, uint amount) external;

    function incrementShorts(bytes32 synth, uint amount) external;

    function decrementShorts(bytes32 synth, uint amount) external;
}


// https://docs.synthetix.io/contracts/source/interfaces/isystemstatus
interface ISystemStatus {
    struct Status {
        bool canSuspend;
        bool canResume;
    }

    struct Suspension {
        bool suspended;
        // reason is an integer code,
        // 0 => no reason, 1 => upgrading, 2+ => defined by system usage
        uint248 reason;
    }

    // Views
    function accessControl(bytes32 section, address account) external view returns (bool canSuspend, bool canResume);

    function requireSystemActive() external view;

    function requireIssuanceActive() external view;

    function requireExchangeActive() external view;

    function requireSynthActive(bytes32 currencyKey) external view;

    function requireSynthsActive(bytes32 sourceCurrencyKey, bytes32 destinationCurrencyKey) external view;

    function synthSuspension(bytes32 currencyKey) external view returns (bool suspended, uint248 reason);

    // Restricted functions
    function suspendSynth(bytes32 currencyKey, uint256 reason) external;

    function updateAccessControl(
        bytes32 section,
        address account,
        bool canSuspend,
        bool canResume
    ) external;
}


// https://docs.synthetix.io/contracts/source/interfaces/ifeepool
interface IFeePool {
    // Views

    // solhint-disable-next-line func-name-mixedcase
    function FEE_ADDRESS() external view returns (address);

    function feesAvailable(address account) external view returns (uint, uint);

    function feePeriodDuration() external view returns (uint);

    function isFeesClaimable(address account) external view returns (bool);

    function targetThreshold() external view returns (uint);

    function totalFeesAvailable() external view returns (uint);

    function totalRewardsAvailable() external view returns (uint);

    // Mutative Functions
    function claimFees() external returns (bool);

    function claimOnBehalf(address claimingForAddress) external returns (bool);

    function closeCurrentFeePeriod() external;

    // Restricted: used internally to Synthetix
    function appendAccountIssuanceRecord(
        address account,
        uint lockedAmount,
        uint debtEntryIndex
    ) external;

    function recordFeePaid(uint sUSDAmount) external;

    function setRewardsToDistribute(uint amount) external;
}


// https://docs.synthetix.io/contracts/source/interfaces/ierc20
interface IERC20 {
    // ERC20 Optional Views
    function name() external view returns (string memory);

    function symbol() external view returns (string memory);

    function decimals() external view returns (uint8);

    // Views
    function totalSupply() external view returns (uint);

    function balanceOf(address owner) external view returns (uint);

    function allowance(address owner, address spender) external view returns (uint);

    // Mutative functions
    function transfer(address to, uint value) external returns (bool);

    function approve(address spender, uint value) external returns (bool);

    function transferFrom(
        address from,
        address to,
        uint value
    ) external returns (bool);

    // Events
    event Transfer(address indexed from, address indexed to, uint value);

    event Approval(address indexed owner, address indexed spender, uint value);
}


// https://docs.synthetix.io/contracts/source/interfaces/iexchangerates
interface IExchangeRates {
    // Structs
    struct RateAndUpdatedTime {
        uint216 rate;
        uint40 time;
    }

    struct InversePricing {
        uint entryPoint;
        uint upperLimit;
        uint lowerLimit;
        bool frozenAtUpperLimit;
        bool frozenAtLowerLimit;
    }

    // Views
    function aggregators(bytes32 currencyKey) external view returns (address);

    function aggregatorWarningFlags() external view returns (address);

    function anyRateIsInvalid(bytes32[] calldata currencyKeys) external view returns (bool);

    function canFreezeRate(bytes32 currencyKey) external view returns (bool);

    function currentRoundForRate(bytes32 currencyKey) external view returns (uint);

    function currenciesUsingAggregator(address aggregator) external view returns (bytes32[] memory);

    function effectiveValue(
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey
    ) external view returns (uint value);

    function effectiveValueAndRates(
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey
    )
        external
        view
        returns (
            uint value,
            uint sourceRate,
            uint destinationRate
        );

    function effectiveValueAtRound(
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey,
        uint roundIdForSrc,
        uint roundIdForDest
    ) external view returns (uint value);

    function getCurrentRoundId(bytes32 currencyKey) external view returns (uint);

    function getLastRoundIdBeforeElapsedSecs(
        bytes32 currencyKey,
        uint startingRoundId,
        uint startingTimestamp,
        uint timediff
    ) external view returns (uint);

    function inversePricing(bytes32 currencyKey)
        external
        view
        returns (
            uint entryPoint,
            uint upperLimit,
            uint lowerLimit,
            bool frozenAtUpperLimit,
            bool frozenAtLowerLimit
        );

    function lastRateUpdateTimes(bytes32 currencyKey) external view returns (uint256);

    function oracle() external view returns (address);

    function rateAndTimestampAtRound(bytes32 currencyKey, uint roundId) external view returns (uint rate, uint time);

    function rateAndUpdatedTime(bytes32 currencyKey) external view returns (uint rate, uint time);

    function rateAndInvalid(bytes32 currencyKey) external view returns (uint rate, bool isInvalid);

    function rateForCurrency(bytes32 currencyKey) external view returns (uint);

    function rateIsFlagged(bytes32 currencyKey) external view returns (bool);

    function rateIsFrozen(bytes32 currencyKey) external view returns (bool);

    function rateIsInvalid(bytes32 currencyKey) external view returns (bool);

    function rateIsStale(bytes32 currencyKey) external view returns (bool);

    function rateStalePeriod() external view returns (uint);

    function ratesAndUpdatedTimeForCurrencyLastNRounds(bytes32 currencyKey, uint numRounds)
        external
        view
        returns (uint[] memory rates, uint[] memory times);

    function ratesAndInvalidForCurrencies(bytes32[] calldata currencyKeys)
        external
        view
        returns (uint[] memory rates, bool anyRateInvalid);

    function ratesForCurrencies(bytes32[] calldata currencyKeys) external view returns (uint[] memory);

    // Mutative functions
    function freezeRate(bytes32 currencyKey) external;
}


interface IVirtualSynth {
    // Views
    function balanceOfUnderlying(address account) external view returns (uint);

    function rate() external view returns (uint);

    function readyToSettle() external view returns (bool);

    function secsLeftInWaitingPeriod() external view returns (uint);

    function settled() external view returns (bool);

    function synth() external view returns (ISynth);

    // Mutative functions
    function settle(address account) external;
}


// https://docs.synthetix.io/contracts/source/interfaces/iexchanger
interface IExchanger {
    // Views
    function calculateAmountAfterSettlement(
        address from,
        bytes32 currencyKey,
        uint amount,
        uint refunded
    ) external view returns (uint amountAfterSettlement);

    function isSynthRateInvalid(bytes32 currencyKey) external view returns (bool);

    function maxSecsLeftInWaitingPeriod(address account, bytes32 currencyKey) external view returns (uint);

    function settlementOwing(address account, bytes32 currencyKey)
        external
        view
        returns (
            uint reclaimAmount,
            uint rebateAmount,
            uint numEntries
        );

    function hasWaitingPeriodOrSettlementOwing(address account, bytes32 currencyKey) external view returns (bool);

    function feeRateForExchange(bytes32 sourceCurrencyKey, bytes32 destinationCurrencyKey)
        external
        view
        returns (uint exchangeFeeRate);

    function getAmountsForExchange(
        uint sourceAmount,
        bytes32 sourceCurrencyKey,
        bytes32 destinationCurrencyKey
    )
        external
        view
        returns (
            uint amountReceived,
            uint fee,
            uint exchangeFeeRate
        );

    function priceDeviationThresholdFactor() external view returns (uint);

    function waitingPeriodSecs() external view returns (uint);

    // Mutative functions
    function exchange(
        address from,
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey,
        address destinationAddress
    ) external returns (uint amountReceived);

    function exchangeOnBehalf(
        address exchangeForAddress,
        address from,
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey
    ) external returns (uint amountReceived);

    function exchangeWithTracking(
        address from,
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey,
        address destinationAddress,
        address originator,
        bytes32 trackingCode
    ) external returns (uint amountReceived);

    function exchangeOnBehalfWithTracking(
        address exchangeForAddress,
        address from,
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey,
        address originator,
        bytes32 trackingCode
    ) external returns (uint amountReceived);

    function exchangeWithVirtual(
        address from,
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey,
        address destinationAddress,
        bytes32 trackingCode
    ) external returns (uint amountReceived, IVirtualSynth vSynth);

    function settle(address from, bytes32 currencyKey)
        external
        returns (
            uint reclaimed,
            uint refunded,
            uint numEntries
        );

    function setLastExchangeRateForSynth(bytes32 currencyKey, uint rate) external;

    function suspendSynthWithInvalidRate(bytes32 currencyKey) external;
}


// https://docs.synthetix.io/contracts/source/interfaces/istakingrewards
interface IShortingRewards {
    // Views
    function lastTimeRewardApplicable() external view returns (uint256);

    function rewardPerToken() external view returns (uint256);

    function earned(address account) external view returns (uint256);

    function getRewardForDuration() external view returns (uint256);

    function totalSupply() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    // Mutative

    function enrol(address account, uint256 amount) external;

    function withdraw(address account, uint256 amount) external;

    function getReward(address account) external;

    function exit(address account) external;
}


// Inheritance


// Libraries


// Internal references


contract Collateral is ICollateralLoan, Owned, MixinSystemSettings {
    /* ========== LIBRARIES ========== */
    using SafeMath for uint;
    using SafeDecimalMath for uint;

    /* ========== CONSTANTS ========== */

    bytes32 private constant sUSD = "sUSD";

    // ========== STATE VARIABLES ==========

    // The synth corresponding to the collateral.
    bytes32 public collateralKey;

    // Stores loans
    CollateralState public state;

    address public manager;

    // The synths that this contract can issue.
    bytes32[] public synths;

    // Map from currency key to synth contract name.
    mapping(bytes32 => bytes32) public synthsByKey;

    // Map from currency key to the shorting rewards contract
    mapping(bytes32 => address) public shortingRewards;

    // ========== SETTER STATE VARIABLES ==========

    // The minimum collateral ratio required to avoid liquidation.
    uint public minCratio;

    // The minimum amount of collateral to create a loan.
    uint public minCollateral;

    // The fee charged for issuing a loan.
    uint public issueFeeRate;

    // The maximum number of loans that an account can create with this collateral.
    uint public maxLoansPerAccount = 50;

    // Time in seconds that a user must wait between interacting with a loan.
    // Provides front running and flash loan protection.
    uint public interactionDelay = 300;

    bool public canOpenLoans = true;

    /* ========== ADDRESS RESOLVER CONFIGURATION ========== */

    bytes32 private constant CONTRACT_SYSTEMSTATUS = "SystemStatus";
    bytes32 private constant CONTRACT_EXRATES = "ExchangeRates";
    bytes32 private constant CONTRACT_EXCHANGER = "Exchanger";
    bytes32 private constant CONTRACT_FEEPOOL = "FeePool";
    bytes32 private constant CONTRACT_SYNTHSUSD = "SynthsUSD";

    /* ========== CONSTRUCTOR ========== */

    constructor(
        CollateralState _state,
        address _owner,
        address _manager,
        address _resolver,
        bytes32 _collateralKey,
        uint _minCratio,
        uint _minCollateral
    ) public Owned(_owner) MixinSystemSettings(_resolver) {
        manager = _manager;
        state = _state;
        collateralKey = _collateralKey;
        minCratio = _minCratio;
        minCollateral = _minCollateral;
    }

    /* ========== VIEWS ========== */

    function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
        bytes32[] memory existingAddresses = MixinSystemSettings.resolverAddressesRequired();
        bytes32[] memory newAddresses = new bytes32[](5);
        newAddresses[0] = CONTRACT_FEEPOOL;
        newAddresses[1] = CONTRACT_EXRATES;
        newAddresses[2] = CONTRACT_EXCHANGER;
        newAddresses[3] = CONTRACT_SYSTEMSTATUS;
        newAddresses[4] = CONTRACT_SYNTHSUSD;

        bytes32[] memory combined = combineArrays(existingAddresses, newAddresses);

        addresses = combineArrays(combined, synths);
    }

    /* ---------- Related Contracts ---------- */

    function _systemStatus() internal view returns (ISystemStatus) {
        return ISystemStatus(requireAndGetAddress(CONTRACT_SYSTEMSTATUS));
    }

    function _synth(bytes32 synthName) internal view returns (ISynth) {
        return ISynth(requireAndGetAddress(synthName));
    }

    function _synthsUSD() internal view returns (ISynth) {
        return ISynth(requireAndGetAddress(CONTRACT_SYNTHSUSD));
    }

    function _exchangeRates() internal view returns (IExchangeRates) {
        return IExchangeRates(requireAndGetAddress(CONTRACT_EXRATES));
    }

    function _exchanger() internal view returns (IExchanger) {
        return IExchanger(requireAndGetAddress(CONTRACT_EXCHANGER));
    }

    function _feePool() internal view returns (IFeePool) {
        return IFeePool(requireAndGetAddress(CONTRACT_FEEPOOL));
    }

    function _manager() internal view returns (ICollateralManager) {
        return ICollateralManager(manager);
    }

    /* ---------- Public Views ---------- */

    function collateralRatio(Loan memory loan) public view returns (uint cratio) {
        uint cvalue = _exchangeRates().effectiveValue(collateralKey, loan.collateral, sUSD);
        uint dvalue = _exchangeRates().effectiveValue(loan.currency, loan.amount.add(loan.accruedInterest), sUSD);
        cratio = cvalue.divideDecimal(dvalue);
    }

    // The maximum number of synths issuable for this amount of collateral
    function maxLoan(uint amount, bytes32 currency) public view returns (uint max) {
        max = issuanceRatio().multiplyDecimal(_exchangeRates().effectiveValue(collateralKey, amount, currency));
    }

    /**
     * r = target issuance ratio
     * D = debt value in sUSD
     * V = collateral value in sUSD
     * P = liquidation penalty
     * Calculates amount of synths = (D - V * r) / (1 - (1 + P) * r)
     * Note: if you pass a loan in here that is not eligible for liquidation it will revert.
     * We check the ratio first in liquidateInternal and only pass eligible loans in.
     */
    function liquidationAmount(Loan memory loan) public view returns (uint amount) {
        uint liquidationPenalty = getLiquidationPenalty();
        uint debtValue = _exchangeRates().effectiveValue(loan.currency, loan.amount.add(loan.accruedInterest), sUSD);
        uint collateralValue = _exchangeRates().effectiveValue(collateralKey, loan.collateral, sUSD);
        uint unit = SafeDecimalMath.unit();

        uint dividend = debtValue.sub(collateralValue.divideDecimal(minCratio));
        uint divisor = unit.sub(unit.add(liquidationPenalty).divideDecimal(minCratio));

        uint sUSDamount = dividend.divideDecimal(divisor);

        return _exchangeRates().effectiveValue(sUSD, sUSDamount, loan.currency);
    }

    // amount is the amount of synths we are liquidating
    function collateralRedeemed(bytes32 currency, uint amount) public view returns (uint collateral) {
        uint liquidationPenalty = getLiquidationPenalty();
        collateral = _exchangeRates().effectiveValue(currency, amount, collateralKey);

        collateral = collateral.multiplyDecimal(SafeDecimalMath.unit().add(liquidationPenalty));
    }

    function areSynthsAndCurrenciesSet(bytes32[] calldata _synthNamesInResolver, bytes32[] calldata _synthKeys)
        external
        view
        returns (bool)
    {
        if (synths.length != _synthNamesInResolver.length) {
            return false;
        }

        for (uint i = 0; i < _synthNamesInResolver.length; i++) {
            bytes32 synthName = _synthNamesInResolver[i];
            if (synths[i] != synthName) {
                return false;
            }
            if (synthsByKey[_synthKeys[i]] != synths[i]) {
                return false;
            }
        }

        return true;
    }

    /* ---------- UTILITIES ---------- */

    // Check the account has enough of the synth to make the payment
    function _checkSynthBalance(
        address payer,
        bytes32 key,
        uint amount
    ) internal view {
        require(IERC20(address(_synth(synthsByKey[key]))).balanceOf(payer) >= amount, "Not enough synth balance");
    }

    // We set the interest index to 0 to indicate the loan has been closed.
    function _checkLoanAvailable(Loan memory _loan) internal view {
        require(_loan.interestIndex > 0, "Loan does not exist");
        require(_loan.lastInteraction.add(interactionDelay) <= block.timestamp, "Loan recently interacted with");
    }

    function issuanceRatio() internal view returns (uint ratio) {
        ratio = SafeDecimalMath.unit().divideDecimalRound(minCratio);
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    /* ---------- Synths ---------- */

    function addSynths(bytes32[] calldata _synthNamesInResolver, bytes32[] calldata _synthKeys) external onlyOwner {
        require(_synthNamesInResolver.length == _synthKeys.length, "Input array length mismatch");

        for (uint i = 0; i < _synthNamesInResolver.length; i++) {
            bytes32 synthName = _synthNamesInResolver[i];
            synths.push(synthName);
            synthsByKey[_synthKeys[i]] = synthName;
        }

        // ensure cache has the latest
        rebuildCache();
    }

    /* ---------- Rewards Contracts ---------- */

    function addRewardsContracts(address rewardsContract, bytes32 synth) external onlyOwner {
        shortingRewards[synth] = rewardsContract;
    }

    /* ---------- SETTERS ---------- */

    function setMinCratio(uint _minCratio) external onlyOwner {
        require(_minCratio > SafeDecimalMath.unit(), "Must be greater than 1");
        minCratio = _minCratio;
        emit MinCratioRatioUpdated(minCratio);
    }

    function setIssueFeeRate(uint _issueFeeRate) external onlyOwner {
        issueFeeRate = _issueFeeRate;
        emit IssueFeeRateUpdated(issueFeeRate);
    }

    function setInteractionDelay(uint _interactionDelay) external onlyOwner {
        require(_interactionDelay <= SafeDecimalMath.unit() * 3600, "Max 1 hour");
        interactionDelay = _interactionDelay;
        emit InteractionDelayUpdated(interactionDelay);
    }

    function setManager(address _newManager) external onlyOwner {
        manager = _newManager;
        emit ManagerUpdated(manager);
    }

    function setCanOpenLoans(bool _canOpenLoans) external onlyOwner {
        canOpenLoans = _canOpenLoans;
        emit CanOpenLoansUpdated(canOpenLoans);
    }

    /* ---------- LOAN INTERACTIONS ---------- */

    function openInternal(
        uint collateral,
        uint amount,
        bytes32 currency,
        bool short
    ) internal returns (uint id) {
        // 0. Check the system is active.
        _systemStatus().requireIssuanceActive();

        require(canOpenLoans, "Opening is disabled");

        // 1. Make sure the collateral rate is valid.
        require(!_exchangeRates().rateIsInvalid(collateralKey), "Collateral rate is invalid");

        // 2. We can only issue certain synths.
        require(synthsByKey[currency] > 0, "Not allowed to issue this synth");

        // 3. Make sure the synth rate is not invalid.
        require(!_exchangeRates().rateIsInvalid(currency), "Currency rate is invalid");

        // 4. Collateral >= minimum collateral size.
        require(collateral >= minCollateral, "Not enough collateral to open");

        // 5. Cap the number of loans so that the array doesn't get too big.
        require(state.getNumLoans(msg.sender) < maxLoansPerAccount, "Max loans exceeded");

        // 6. Check we haven't hit the debt cap for non snx collateral.
        (bool canIssue, bool anyRateIsInvalid) = _manager().exceedsDebtLimit(amount, currency);

        require(canIssue && !anyRateIsInvalid, "Debt limit or invalid rate");

        // 7. Require requested loan < max loan
        require(amount <= maxLoan(collateral, currency), "Exceeds max borrowing power");

        // 8. This fee is denominated in the currency of the loan
        uint issueFee = amount.multiplyDecimalRound(issueFeeRate);

        // 9. Calculate the minting fee and subtract it from the loan amount
        uint loanAmountMinusFee = amount.sub(issueFee);

        // 10. Get a Loan ID
        id = _manager().getNewLoanId();

        // 11. Create the loan struct.
        Loan memory loan = Loan({
            id: id,
            account: msg.sender,
            collateral: collateral,
            currency: currency,
            amount: amount,
            short: short,
            accruedInterest: 0,
            interestIndex: 0,
            lastInteraction: block.timestamp
        });

        // 12. Accrue interest on the loan.
        loan = accrueInterest(loan);

        // 13. Save the loan to storage
        state.createLoan(loan);

        // 14. Pay the minting fees to the fee pool
        _payFees(issueFee, currency);

        // 15. If its short, convert back to sUSD, otherwise issue the loan.
        if (short) {
            _synthsUSD().issue(msg.sender, _exchangeRates().effectiveValue(currency, loanAmountMinusFee, sUSD));
            _manager().incrementShorts(currency, amount);

            if (shortingRewards[currency] != address(0)) {
                IShortingRewards(shortingRewards[currency]).enrol(msg.sender, amount);
            }
        } else {
            _synth(synthsByKey[currency]).issue(msg.sender, loanAmountMinusFee);
            _manager().incrementLongs(currency, amount);
        }

        // 16. Emit event
        emit LoanCreated(msg.sender, id, amount, collateral, currency, issueFee);
    }

    function closeInternal(address borrower, uint id) internal returns (uint collateral) {
        // 0. Check the system is active.
        _systemStatus().requireIssuanceActive();

        // 1. Make sure the collateral rate is valid
        require(!_exchangeRates().rateIsInvalid(collateralKey), "Collateral rate is invalid");

        // 2. Get the loan.
        Loan memory loan = state.getLoan(borrower, id);

        // 3. Check loan is open and the last interaction time.
        _checkLoanAvailable(loan);

        // 4. Accrue interest on the loan.
        loan = accrueInterest(loan);

        // 5. Work out the total amount owing on the loan.
        uint total = loan.amount.add(loan.accruedInterest);

        // 6. Check they have enough balance to close the loan.
        _checkSynthBalance(loan.account, loan.currency, total);

        // 7. Burn the synths
        require(
            !_exchanger().hasWaitingPeriodOrSettlementOwing(borrower, loan.currency),
            "Waiting secs or settlement owing"
        );
        _synth(synthsByKey[loan.currency]).burn(borrower, total);

        // 8. Tell the manager.
        if (loan.short) {
            _manager().decrementShorts(loan.currency, loan.amount);

            if (shortingRewards[loan.currency] != address(0)) {
                IShortingRewards(shortingRewards[loan.currency]).withdraw(borrower, loan.amount);
            }
        } else {
            _manager().decrementLongs(loan.currency, loan.amount);
        }

        // 9. Assign the collateral to be returned.
        collateral = loan.collateral;

        // 10. Pay fees
        _payFees(loan.accruedInterest, loan.currency);

        // 11. Record loan as closed
        loan.amount = 0;
        loan.collateral = 0;
        loan.accruedInterest = 0;
        loan.interestIndex = 0;
        loan.lastInteraction = block.timestamp;
        state.updateLoan(loan);

        // 12. Emit the event
        emit LoanClosed(borrower, id);
    }

    function closeByLiquidationInternal(
        address borrower,
        address liquidator,
        Loan memory loan
    ) internal returns (uint collateral) {
        // 1. Work out the total amount owing on the loan.
        uint total = loan.amount.add(loan.accruedInterest);

        // 2. Store this for the event.
        uint amount = loan.amount;

        // 3. Return collateral to the child class so it knows how much to transfer.
        collateral = loan.collateral;

        // 4. Burn the synths
        require(!_exchanger().hasWaitingPeriodOrSettlementOwing(liquidator, loan.currency), "Waiting or settlement owing");
        _synth(synthsByKey[loan.currency]).burn(liquidator, total);

        // 5. Tell the manager.
        if (loan.short) {
            _manager().decrementShorts(loan.currency, loan.amount);

            if (shortingRewards[loan.currency] != address(0)) {
                IShortingRewards(shortingRewards[loan.currency]).withdraw(borrower, loan.amount);
            }
        } else {
            _manager().decrementLongs(loan.currency, loan.amount);
        }

        // 6. Pay fees
        _payFees(loan.accruedInterest, loan.currency);

        // 7. Record loan as closed
        loan.amount = 0;
        loan.collateral = 0;
        loan.accruedInterest = 0;
        loan.interestIndex = 0;
        loan.lastInteraction = block.timestamp;
        state.updateLoan(loan);

        // 8. Emit the event.
        emit LoanClosedByLiquidation(borrower, loan.id, liquidator, amount, collateral);
    }

    function depositInternal(
        address account,
        uint id,
        uint amount
    ) internal {
        // 0. Check the system is active.
        _systemStatus().requireIssuanceActive();

        // 1. Make sure the collateral rate is valid.
        require(!_exchangeRates().rateIsInvalid(collateralKey), "Collateral rate is invalid");

        // 2. They sent some value > 0
        require(amount > 0, "Deposit must be greater than 0");

        // 3. Get the loan
        Loan memory loan = state.getLoan(account, id);

        // 4. Check loan is open and last interaction time.
        _checkLoanAvailable(loan);

        // 5. Accrue interest
        loan = accrueInterest(loan);

        // 6. Add the collateral
        loan.collateral = loan.collateral.add(amount);

        // 7. Update the last interaction time.
        loan.lastInteraction = block.timestamp;

        // 8. Store the loan
        state.updateLoan(loan);

        // 9. Emit the event
        emit CollateralDeposited(account, id, amount, loan.collateral);
    }

    function withdrawInternal(uint id, uint amount) internal returns (uint withdraw) {
        // 0. Check the system is active.
        _systemStatus().requireIssuanceActive();

        // 1. Make sure the collateral rate is valid.
        require(!_exchangeRates().rateIsInvalid(collateralKey), "Collateral rate is invalid");

        // 2. Get the loan.
        Loan memory loan = state.getLoan(msg.sender, id);

        // 3. Check loan is open and last interaction time.
        _checkLoanAvailable(loan);

        // 4. Accrue interest.
        loan = accrueInterest(loan);

        // 5. Subtract the collateral.
        loan.collateral = loan.collateral.sub(amount);

        // 6. Update the last interaction time.
        loan.lastInteraction = block.timestamp;

        // 7. Check that the new amount does not put them under the minimum c ratio.
        require(collateralRatio(loan) > minCratio, "Cratio too low");

        // 8. Store the loan.
        state.updateLoan(loan);

        // 9. Assign the return variable.
        withdraw = amount;

        // 10. Emit the event.
        emit CollateralWithdrawn(msg.sender, id, amount, loan.collateral);
    }

    function liquidateInternal(
        address borrower,
        uint id,
        uint payment
    ) internal returns (uint collateralLiquidated) {
        // 0. Check the system is active.
        _systemStatus().requireIssuanceActive();

        // 1. Make sure the collateral rate is valid.
        require(!_exchangeRates().rateIsInvalid(collateralKey), "Collateral rate is invalid");

        // 2. Check the payment amount.
        require(payment > 0, "Payment must be greater than 0");

        // 3. Get the loan.
        Loan memory loan = state.getLoan(borrower, id);

        // 4. Check loan is open and last interaction time.
        _checkLoanAvailable(loan);

        // 5. Accrue interest.
        loan = accrueInterest(loan);

        // 6. Check they have enough balance to make the payment.
        _checkSynthBalance(msg.sender, loan.currency, payment);

        // 7. Check they are eligible for liquidation.
        require(collateralRatio(loan) < minCratio, "Cratio above liquidation ratio");

        // 8. Determine how much needs to be liquidated to fix their c ratio.
        uint liqAmount = liquidationAmount(loan);

        // 9. Only allow them to liquidate enough to fix the c ratio.
        uint amountToLiquidate = liqAmount < payment ? liqAmount : payment;

        // 10. Work out the total amount owing on the loan.
        uint amountOwing = loan.amount.add(loan.accruedInterest);

        // 11. If its greater than the amount owing, we need to close the loan.
        if (amountToLiquidate >= amountOwing) {
            return closeByLiquidationInternal(borrower, msg.sender, loan);
        }

        // 12. Process the payment to workout interest/principal split.
        loan = _processPayment(loan, amountToLiquidate);

        // 13. Work out how much collateral to redeem.
        collateralLiquidated = collateralRedeemed(loan.currency, amountToLiquidate);
        loan.collateral = loan.collateral.sub(collateralLiquidated);

        // 14. Update the last interaction time.
        loan.lastInteraction = block.timestamp;

        // 15. Burn the synths from the liquidator.
        require(!_exchanger().hasWaitingPeriodOrSettlementOwing(msg.sender, loan.currency), "Waiting or settlement owing");
        _synth(synthsByKey[loan.currency]).burn(msg.sender, amountToLiquidate);

        // 16. Store the loan.
        state.updateLoan(loan);

        // 17. Emit the event
        emit LoanPartiallyLiquidated(borrower, id, msg.sender, amountToLiquidate, collateralLiquidated);
    }

    function repayInternal(
        address borrower,
        address repayer,
        uint id,
        uint payment
    ) internal {
        // 0. Check the system is active.
        _systemStatus().requireIssuanceActive();

        // 1. Make sure the collateral rate is valid.
        require(!_exchangeRates().rateIsInvalid(collateralKey), "Collateral rate is invalid");

        // 2. Check the payment amount.
        require(payment > 0, "Payment must be greater than 0");

        // 3. Get loan
        Loan memory loan = state.getLoan(borrower, id);

        // 4. Check loan is open and last interaction time.
        _checkLoanAvailable(loan);

        // 5. Accrue interest.
        loan = accrueInterest(loan);

        // 6. Check the spender has enough synths to make the repayment
        _checkSynthBalance(repayer, loan.currency, payment);

        // 7. Process the payment.
        loan = _processPayment(loan, payment);

        // 8. Update the last interaction time.
        loan.lastInteraction = block.timestamp;

        // 9. Burn synths from the payer
        require(!_exchanger().hasWaitingPeriodOrSettlementOwing(repayer, loan.currency), "Waiting or settlement owing");
        _synth(synthsByKey[loan.currency]).burn(repayer, payment);

        // 10. Store the loan
        state.updateLoan(loan);

        // 11. Emit the event.
        emit LoanRepaymentMade(borrower, repayer, id, payment, loan.amount);
    }

    function drawInternal(uint id, uint amount) internal {
        // 0. Check the system is active.
        _systemStatus().requireIssuanceActive();

        // 1. Make sure the collateral rate is valid.
        require(!_exchangeRates().rateIsInvalid(collateralKey), "Collateral rate is invalid");

        // 2. Get loan.
        Loan memory loan = state.getLoan(msg.sender, id);

        // 3. Check loan is open and last interaction time.
        _checkLoanAvailable(loan);

        // 4. Accrue interest.
        loan = accrueInterest(loan);

        // 5. Add the requested amount.
        loan.amount = loan.amount.add(amount);

        // 6. If it is below the minimum, don't allow this draw.
        require(collateralRatio(loan) > minCratio, "Cannot draw this much");

        // 7. This fee is denominated in the currency of the loan
        uint issueFee = amount.multiplyDecimalRound(issueFeeRate);

        // 8. Calculate the minting fee and subtract it from the draw amount
        uint amountMinusFee = amount.sub(issueFee);

        // 9. If its short, let the child handle it, otherwise issue the synths.
        if (loan.short) {
            _manager().incrementShorts(loan.currency, amount);
            _synthsUSD().issue(msg.sender, _exchangeRates().effectiveValue(loan.currency, amountMinusFee, sUSD));

            if (shortingRewards[loan.currency] != address(0)) {
                IShortingRewards(shortingRewards[loan.currency]).enrol(msg.sender, amount);
            }
        } else {
            _manager().incrementLongs(loan.currency, amount);
            _synth(synthsByKey[loan.currency]).issue(msg.sender, amountMinusFee);
        }

        // 10. Pay the minting fees to the fee pool
        _payFees(issueFee, loan.currency);

        // 11. Update the last interaction time.
        loan.lastInteraction = block.timestamp;

        // 12. Store the loan
        state.updateLoan(loan);

        // 13. Emit the event.
        emit LoanDrawnDown(msg.sender, id, amount);
    }

    // Update the cumulative interest rate for the currency that was interacted with.
    function accrueInterest(Loan memory loan) internal returns (Loan memory loanAfter) {
        loanAfter = loan;

        // 1. Get the rates we need.
        (uint entryRate, uint lastRate, uint lastUpdated, uint newIndex) = loan.short
            ? _manager().getShortRatesAndTime(loan.currency, loan.interestIndex)
            : _manager().getRatesAndTime(loan.interestIndex);

        // 2. Get the instantaneous rate.
        (uint rate, bool invalid) = loan.short
            ? _manager().getShortRate(synthsByKey[loan.currency])
            : _manager().getBorrowRate();

        require(!invalid, "Rates are invalid");

        // 3. Get the time since we last updated the rate.
        uint timeDelta = block.timestamp.sub(lastUpdated).mul(SafeDecimalMath.unit());

        // 4. Get the latest cumulative rate. F_n+1 = F_n + F_last
        uint latestCumulative = lastRate.add(rate.multiplyDecimal(timeDelta));

        // 5. If the loan was just opened, don't record any interest. Otherwise multiple by the amount outstanding.
        uint interest = loan.interestIndex == 0 ? 0 : loan.amount.multiplyDecimal(latestCumulative.sub(entryRate));

        // 7. Update rates with the lastest cumulative rate. This also updates the time.
        loan.short
            ? _manager().updateShortRates(loan.currency, latestCumulative)
            : _manager().updateBorrowRates(latestCumulative);

        // 8. Update loan
        loanAfter.accruedInterest = loan.accruedInterest.add(interest);
        loanAfter.interestIndex = newIndex;
        state.updateLoan(loanAfter);
    }

    // Works out the amount of interest and principal after a repayment is made.
    function _processPayment(Loan memory loanBefore, uint payment) internal returns (Loan memory loanAfter) {
        loanAfter = loanBefore;

        if (payment > 0 && loanBefore.accruedInterest > 0) {
            uint interestPaid = payment > loanBefore.accruedInterest ? loanBefore.accruedInterest : payment;
            loanAfter.accruedInterest = loanBefore.accruedInterest.sub(interestPaid);
            payment = payment.sub(interestPaid);

            _payFees(interestPaid, loanBefore.currency);
        }

        // If there is more payment left after the interest, pay down the principal.
        if (payment > 0) {
            loanAfter.amount = loanBefore.amount.sub(payment);

            // And get the manager to reduce the total long/short balance.
            if (loanAfter.short) {
                _manager().decrementShorts(loanAfter.currency, payment);

                if (shortingRewards[loanAfter.currency] != address(0)) {
                    IShortingRewards(shortingRewards[loanAfter.currency]).withdraw(loanAfter.account, payment);
                }
            } else {
                _manager().decrementLongs(loanAfter.currency, payment);
            }
        }
    }

    // Take an amount of fees in a certain synth and convert it to sUSD before paying the fee pool.
    function _payFees(uint amount, bytes32 synth) internal {
        if (amount > 0) {
            if (synth != sUSD) {
                amount = _exchangeRates().effectiveValue(synth, amount, sUSD);
            }
            _synthsUSD().issue(_feePool().FEE_ADDRESS(), amount);
            _feePool().recordFeePaid(amount);
        }
    }

    // ========== EVENTS ==========
    // Setters
    event MinCratioRatioUpdated(uint minCratio);
    event MinCollateralUpdated(uint minCollateral);
    event IssueFeeRateUpdated(uint issueFeeRate);
    event MaxLoansPerAccountUpdated(uint maxLoansPerAccount);
    event InteractionDelayUpdated(uint interactionDelay);
    event ManagerUpdated(address manager);
    event CanOpenLoansUpdated(bool canOpenLoans);

    // Loans
    event LoanCreated(address indexed account, uint id, uint amount, uint collateral, bytes32 currency, uint issuanceFee);
    event LoanClosed(address indexed account, uint id);
    event CollateralDeposited(address indexed account, uint id, uint amountDeposited, uint collateralAfter);
    event CollateralWithdrawn(address indexed account, uint id, uint amountWithdrawn, uint collateralAfter);
    event LoanRepaymentMade(address indexed account, address indexed repayer, uint id, uint amountRepaid, uint amountAfter);
    event LoanDrawnDown(address indexed account, uint id, uint amount);
    event LoanPartiallyLiquidated(
        address indexed account,
        uint id,
        address liquidator,
        uint amountLiquidated,
        uint collateralLiquidated
    );
    event LoanClosedByLiquidation(
        address indexed account,
        uint id,
        address indexed liquidator,
        uint amountLiquidated,
        uint collateralLiquidated
    );
}


// Inheritance


// Internal references


contract CollateralShort is Collateral {
    constructor(
        CollateralState _state,
        address _owner,
        address _manager,
        address _resolver,
        bytes32 _collateralKey,
        uint _minCratio,
        uint _minCollateral
    ) public Collateral(_state, _owner, _manager, _resolver, _collateralKey, _minCratio, _minCollateral) {}

    function open(
        uint collateral,
        uint amount,
        bytes32 currency
    ) external {
        require(
            collateral <= IERC20(address(_synthsUSD())).allowance(msg.sender, address(this)),
            "Allowance not high enough"
        );

        openInternal(collateral, amount, currency, true);

        IERC20(address(_synthsUSD())).transferFrom(msg.sender, address(this), collateral);
    }

    function close(uint id) external {
        uint collateral = closeInternal(msg.sender, id);

        IERC20(address(_synthsUSD())).transfer(msg.sender, collateral);
    }

    function deposit(
        address borrower,
        uint id,
        uint amount
    ) external {
        require(amount <= IERC20(address(_synthsUSD())).allowance(msg.sender, address(this)), "Allowance not high enough");

        IERC20(address(_synthsUSD())).transferFrom(msg.sender, address(this), amount);

        depositInternal(borrower, id, amount);
    }

    function withdraw(uint id, uint amount) external {
        uint withdrawnAmount = withdrawInternal(id, amount);

        IERC20(address(_synthsUSD())).transfer(msg.sender, withdrawnAmount);
    }

    function repay(
        address borrower,
        uint id,
        uint amount
    ) external {
        repayInternal(borrower, msg.sender, id, amount);
    }

    function draw(uint id, uint amount) external {
        drawInternal(id, amount);
    }

    function liquidate(
        address borrower,
        uint id,
        uint amount
    ) external {
        uint collateralLiquidated = liquidateInternal(borrower, id, amount);

        IERC20(address(_synthsUSD())).transfer(msg.sender, collateralLiquidated);
    }

    function getReward(bytes32 currency, address account) external {
        if (shortingRewards[currency] != address(0)) {
            IShortingRewards(shortingRewards[currency]).getReward(account);
        }
    }
}

Contract ABI

[{"inputs":[{"internalType":"contract CollateralState","name":"_state","type":"address"},{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_manager","type":"address"},{"internalType":"address","name":"_resolver","type":"address"},{"internalType":"bytes32","name":"_collateralKey","type":"bytes32"},{"internalType":"uint256","name":"_minCratio","type":"uint256"},{"internalType":"uint256","name":"_minCollateral","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"name","type":"bytes32"},{"indexed":false,"internalType":"address","name":"destination","type":"address"}],"name":"CacheUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"canOpenLoans","type":"bool"}],"name":"CanOpenLoansUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountDeposited","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralAfter","type":"uint256"}],"name":"CollateralDeposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountWithdrawn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralAfter","type":"uint256"}],"name":"CollateralWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"interactionDelay","type":"uint256"}],"name":"InteractionDelayUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"issueFeeRate","type":"uint256"}],"name":"IssueFeeRateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"}],"name":"LoanClosed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountLiquidated","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralLiquidated","type":"uint256"}],"name":"LoanClosedByLiquidation","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateral","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"currency","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"issuanceFee","type":"uint256"}],"name":"LoanCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"LoanDrawnDown","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountLiquidated","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralLiquidated","type":"uint256"}],"name":"LoanPartiallyLiquidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"repayer","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountRepaid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountAfter","type":"uint256"}],"name":"LoanRepaymentMade","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"manager","type":"address"}],"name":"ManagerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxLoansPerAccount","type":"uint256"}],"name":"MaxLoansPerAccountUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"minCollateral","type":"uint256"}],"name":"MinCollateralUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"minCratio","type":"uint256"}],"name":"MinCratioRatioUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerNominated","type":"event"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"rewardsContract","type":"address"},{"internalType":"bytes32","name":"synth","type":"bytes32"}],"name":"addRewardsContracts","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32[]","name":"_synthNamesInResolver","type":"bytes32[]"},{"internalType":"bytes32[]","name":"_synthKeys","type":"bytes32[]"}],"name":"addSynths","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32[]","name":"_synthNamesInResolver","type":"bytes32[]"},{"internalType":"bytes32[]","name":"_synthKeys","type":"bytes32[]"}],"name":"areSynthsAndCurrenciesSet","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"canOpenLoans","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"close","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"collateralKey","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address payable","name":"account","type":"address"},{"internalType":"uint256","name":"collateral","type":"uint256"},{"internalType":"bytes32","name":"currency","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"short","type":"bool"},{"internalType":"uint256","name":"accruedInterest","type":"uint256"},{"internalType":"uint256","name":"interestIndex","type":"uint256"},{"internalType":"uint256","name":"lastInteraction","type":"uint256"}],"internalType":"struct ICollateralLoan.Loan","name":"loan","type":"tuple"}],"name":"collateralRatio","outputs":[{"internalType":"uint256","name":"cratio","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currency","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"collateralRedeemed","outputs":[{"internalType":"uint256","name":"collateral","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"draw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"currency","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"getReward","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"interactionDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isResolverCached","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"issueFeeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"liquidate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address payable","name":"account","type":"address"},{"internalType":"uint256","name":"collateral","type":"uint256"},{"internalType":"bytes32","name":"currency","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"short","type":"bool"},{"internalType":"uint256","name":"accruedInterest","type":"uint256"},{"internalType":"uint256","name":"interestIndex","type":"uint256"},{"internalType":"uint256","name":"lastInteraction","type":"uint256"}],"internalType":"struct ICollateralLoan.Loan","name":"loan","type":"tuple"}],"name":"liquidationAmount","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32","name":"currency","type":"bytes32"}],"name":"maxLoan","outputs":[{"internalType":"uint256","name":"max","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"maxLoansPerAccount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"minCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"minCratio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"nominateNewOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"nominatedOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"collateral","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32","name":"currency","type":"bytes32"}],"name":"open","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"rebuildCache","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"repay","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"resolver","outputs":[{"internalType":"contract AddressResolver","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"resolverAddressesRequired","outputs":[{"internalType":"bytes32[]","name":"addresses","type":"bytes32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bool","name":"_canOpenLoans","type":"bool"}],"name":"setCanOpenLoans","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_interactionDelay","type":"uint256"}],"name":"setInteractionDelay","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_issueFeeRate","type":"uint256"}],"name":"setIssueFeeRate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_newManager","type":"address"}],"name":"setManager","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_minCratio","type":"uint256"}],"name":"setMinCratio","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"shortingRewards","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"state","outputs":[{"internalType":"contract CollateralState","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"synths","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"synthsByKey","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]

60806040526032600d5561012c600e55600f805460ff191660011790553480156200002957600080fd5b50604051620062ce380380620062ce8339810160408190526200004c9162000167565b868686868686868380876001600160a01b038116620000885760405162461bcd60e51b81526004016200007f906200028f565b60405180910390fd5b600080546001600160a01b0319166001600160a01b0383161781556040517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c91620000d591849062000269565b60405180910390a150600280546001600160a01b03199081166001600160a01b03938416179091556006805482169883169890981790975560058054909716981697909717909455600491909155600a5550600b555062000310975050505050505050565b80516200014781620002e0565b92915050565b80516200014781620002fa565b8051620001478162000305565b600080600080600080600060e0888a0312156200018357600080fd5b6000620001918a8a6200015a565b9750506020620001a48a828b016200013a565b9650506040620001b78a828b016200013a565b9550506060620001ca8a828b016200013a565b9450506080620001dd8a828b016200014d565b93505060a0620001f08a828b016200014d565b92505060c0620002038a828b016200014d565b91505092959891949750929550565b6200021d81620002d3565b82525050565b6200021d81620002aa565b60006200023d601983620002a1565b7f4f776e657220616464726573732063616e6e6f74206265203000000000000000815260200192915050565b6040810162000279828562000212565b62000288602083018462000223565b9392505050565b6020808252810162000147816200022e565b90815260200190565b60006200014782620002c7565b90565b60006200014782620002aa565b6001600160a01b031690565b60006200014782620002ba565b620002eb81620002aa565b8114620002f757600080fd5b50565b620002eb81620002b7565b620002eb81620002ba565b615fae80620003206000396000f3fe608060405234801561001057600080fd5b50600436106102485760003560e01c806372e18b6a1161013b578063b562a1ab116100b8578063dac8cf681161007c578063dac8cf681461048d578063de81eda9146104a0578063e74337c6146104b3578063eb8e3b65146104c6578063f93451ed146104ce57610248565b8063b562a1ab1461044f578063ba2de9bc14610457578063c19d93fb1461045f578063d0ebdbe714610467578063d2b8035a1461047a57610248565b80638cd2e0c7116100ff5780638cd2e0c7146104065780638da5cb5b1461041957806390abb4d914610421578063925ead1114610434578063a76cdfa51461043c57610248565b806372e18b6a146103bb57806374185360146103ce57806379ba5097146103d65780637e132355146103de578063899ffef4146103f157610248565b806330edd961116101c9578063481c6a751161018d578063481c6a75146103655780634c17ace41461037a57806353a47bb71461038d57806356dc04a1146103955780635eb2ad01146103a857610248565b806330edd9611461031c578063361e20861461032f57806338245377146103375780634065b81b1461034a578063441a3e701461035257610248565b80630efe6a8b116102105780630efe6a8b146102c657806315aaf4dd146102d95780631627540c146102e157806323d60e2e146102f45780632af64bd31461030757610248565b806304f3bcec1461024d5780630710285c1461026b5780630a153c97146102805780630aebeb4e146102a05780630cdd1c65146102b3575b600080fd5b6102556104e1565b6040516102629190615c1a565b60405180910390f35b61027e610279366004614fee565b6104f0565b005b61029361028e366004615165565b61058d565b6040516102629190615bb5565b61027e6102ae366004615117565b6106c9565b61027e6102c1366004615117565b610763565b61027e6102d4366004614fee565b61084e565b610293610987565b61027e6102ef366004614f78565b61098d565b61027e61030236600461503b565b6109e0565b61030f610aa6565b6040516102629190615ba7565b61029361032a366004615117565b610bbe565b610293610bdc565b610293610345366004615117565b610be2565b61030f610bf4565b61027e610360366004615165565b610bfd565b61036d610c92565b6040516102629190615b00565b61027e610388366004615117565b610ca1565b61036d610d7d565b61027e6103a3366004615135565b610d8c565b61027e6103b6366004614fb4565b610e1d565b61030f6103c936600461503b565b610e53565b61027e610f15565b61027e611067565b6102936103ec366004615165565b611103565b6103f96111ac565b6040516102629190615b96565b61027e610414366004614fee565b611311565b61036d61131d565b61027e61042f3660046150ab565b61132c565b610293611378565b61027e61044a366004615117565b61137e565b6102936113bb565b6102936113c1565b6102556113c7565b61027e610475366004614f78565b6113d6565b61027e610488366004615165565b61142f565b61029361049b366004615184565b611439565b61036d6104ae366004615117565b611592565b6102936104c1366004615184565b6115ad565b610293611897565b61027e6104dc3660046151ff565b61189d565b6002546001600160a01b031681565b60006104fd848484611986565b9050610507611deb565b6001600160a01b031663a9059cbb33836040518363ffffffff1660e01b8152600401610534929190615b5f565b602060405180830381600087803b15801561054e57600080fd5b505af1158015610562573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061058691908101906150c9565b5050505050565b600080610598611e07565b90506105a2611eb4565b6001600160a01b031663654a60ac85856004546040518463ffffffff1660e01b81526004016105d393929190615bff565b60206040518083038186803b1580156105eb57600080fd5b505afa1580156105ff573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061062391908101906151c2565b91506106c16106b482731a60e2e2a8be0bc2b6381dd31fd3fd5f9a28de4c63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b15801561067057600080fd5b505af4158015610684573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506106a891908101906151c2565b9063ffffffff611ecf16565b839063ffffffff611efd16565b949350505050565b60006106d53383611f27565b90506106df611deb565b6001600160a01b031663a9059cbb33836040518363ffffffff1660e01b815260040161070c929190615b5f565b602060405180830381600087803b15801561072657600080fd5b505af115801561073a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061075e91908101906150c9565b505050565b61076b61248c565b731a60e2e2a8be0bc2b6381dd31fd3fd5f9a28de4c63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b1580156107af57600080fd5b505af41580156107c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506107e791908101906151c2565b811161080e5760405162461bcd60e51b815260040161080590615c49565b60405180910390fd5b600a8190556040517f813a44586e8ecb9390b2568dbe810e193087f80e415c8845340ef06d4cbb42a590610843908390615bb5565b60405180910390a150565b610856611deb565b6001600160a01b031663dd62ed3e33306040518363ffffffff1660e01b8152600401610883929190615b1c565b60206040518083038186803b15801561089b57600080fd5b505afa1580156108af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506108d391908101906151c2565b8111156108f25760405162461bcd60e51b815260040161080590615c89565b6108fa611deb565b6001600160a01b03166323b872dd3330846040518463ffffffff1660e01b815260040161092993929190615b37565b602060405180830381600087803b15801561094357600080fd5b505af1158015610957573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061097b91908101906150c9565b5061075e8383836124b8565b600e5481565b61099561248c565b600180546001600160a01b0319166001600160a01b0383161790556040517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce2290610843908390615b00565b6109e861248c565b828114610a075760405162461bcd60e51b815260040161080590615c39565b60005b83811015610a97576000858583818110610a2057fe5b600780546001810182556000918252602090920293909301357fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c6889091018190559250829160089150868686818110610a7457fe5b602090810292909201358352508101919091526040016000205550600101610a0a565b50610aa0610f15565b50505050565b60006060610ab26111ac565b905060005b8151811015610bb4576000828281518110610ace57fe5b602090810291909101810151600081815260039092526040918290205460025492516321f8a72160e01b81529193506001600160a01b039081169216906321f8a72190610b1f908590600401615bb5565b60206040518083038186803b158015610b3757600080fd5b505afa158015610b4b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610b6f9190810190614f96565b6001600160a01b0316141580610b9a57506000818152600360205260409020546001600160a01b0316155b15610bab5760009350505050610bbb565b50600101610ab7565b5060019150505b90565b60078181548110610bcb57fe5b600091825260209091200154905081565b600c5481565b60086020526000908152604090205481565b600f5460ff1681565b6000610c098383612749565b9050610c13611deb565b6001600160a01b031663a9059cbb33836040518363ffffffff1660e01b8152600401610c40929190615b5f565b602060405180830381600087803b158015610c5a57600080fd5b505af1158015610c6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610aa091908101906150c9565b6006546001600160a01b031681565b610ca961248c565b731a60e2e2a8be0bc2b6381dd31fd3fd5f9a28de4c63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b158015610ced57600080fd5b505af4158015610d01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610d2591908101906151c2565b610e1002811115610d485760405162461bcd60e51b815260040161080590615d59565b600e8190556040517f4d71c92b0a9dc236066597b95637bb04d58cd135e9165aee13eb68e3199c236190610843908390615bb5565b6001546001600160a01b031681565b6000828152600960205260409020546001600160a01b031615610e195760008281526009602052604090819020549051630c00007b60e41b81526001600160a01b039091169063c00007b090610de6908490600401615b00565b600060405180830381600087803b158015610e0057600080fd5b505af1158015610e14573d6000803e3d6000fd5b505050505b5050565b610e2561248c565b600090815260096020526040902080546001600160a01b0319166001600160a01b0392909216919091179055565b6007546000908414610e67575060006106c1565b60005b84811015610f09576000868683818110610e8057fe5b9050602002013590508060078381548110610e9757fe5b906000526020600020015414610eb2576000925050506106c1565b60078281548110610ebf57fe5b906000526020600020015460086000878786818110610eda57fe5b9050602002013581526020019081526020016000205414610f00576000925050506106c1565b50600101610e6a565b50600195945050505050565b6060610f1f6111ac565b905060005b8151811015610e19576000828281518110610f3b57fe5b602002602001015190506000600260009054906101000a90046001600160a01b03166001600160a01b031663dacb2d018384604051602001610f7d9190615af5565b6040516020818303038152906040526040518363ffffffff1660e01b8152600401610fa9929190615bdf565b60206040518083038186803b158015610fc157600080fd5b505afa158015610fd5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610ff99190810190614f96565b6000838152600360205260409081902080546001600160a01b0319166001600160a01b038416179055519091507f88a93678a3692f6789d9546fc621bf7234b101ddb7d4fe479455112831b8aa68906110559084908490615bc3565b60405180910390a15050600101610f24565b6001546001600160a01b031633146110915760405162461bcd60e51b815260040161080590615c79565b6000546001546040517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c926110d4926001600160a01b0391821692911690615b7a565b60405180910390a160018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b60006111a5611110611eb4565b6001600160a01b031663654a60ac60045486866040518463ffffffff1660e01b815260040161114193929190615bff565b60206040518083038186803b15801561115957600080fd5b505afa15801561116d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061119191908101906151c2565b6111996129e6565b9063ffffffff611efd16565b9392505050565b6060806111b7612a76565b60408051600580825260c08201909252919250606091906020820160a08038833901905050905066119959541bdbdb60ca1b816000815181106111f657fe5b6020026020010181815250506c45786368616e6765526174657360981b8160018151811061122057fe5b6020026020010181815250506822bc31b430b733b2b960b91b8160028151811061124657fe5b6020026020010181815250506b53797374656d53746174757360a01b8160038151811061126f57fe5b6020026020010181815250506814de5b9d1a1cd554d160ba1b8160048151811061129557fe5b60200260200101818152505060606112ad8383612ac7565b90506113098160078054806020026020016040519081016040528092919081815260200182805480156112ff57602002820191906000526020600020905b8154815260200190600101908083116112eb575b5050505050612ac7565b935050505090565b61075e83338484612b83565b6000546001600160a01b031681565b61133461248c565b600f805460ff191682151517908190556040517f261991749e1b2436706a31bde8bf184bb37fe21e303709b78d3b881afacadaa2916108439160ff90911690615ba7565b600a5481565b61138661248c565b600c8190556040517fe7bd72551c54d568cd97b00dc52d2787b5c5d4f0070d3582c1e8ba25141f799c90610843908390615bb5565b60045481565b600b5481565b6005546001600160a01b031681565b6113de61248c565b600680546001600160a01b0319166001600160a01b0383811691909117918290556040517f2c1c11af44aa5608f1dca38c00275c30ea091e02417d36e70e9a1538689c433d92610843921690615b00565b610e198282612f3e565b600080611444611eb4565b6001600160a01b031663654a60ac6004548560400151631cd554d160e21b6040518463ffffffff1660e01b815260040161148093929190615bff565b60206040518083038186803b15801561149857600080fd5b505afa1580156114ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506114d091908101906151c2565b905060006114dc611eb4565b6001600160a01b031663654a60ac856060015161150a8760c001518860800151611ecf90919063ffffffff16565b631cd554d160e21b6040518463ffffffff1660e01b815260040161153093929190615bff565b60206040518083038186803b15801561154857600080fd5b505afa15801561155c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061158091908101906151c2565b90506106c1828263ffffffff6134fe16565b6009602052600090815260409020546001600160a01b031681565b6000806115b8611e07565b905060006115c4611eb4565b6001600160a01b031663654a60ac85606001516115f28760c001518860800151611ecf90919063ffffffff16565b631cd554d160e21b6040518463ffffffff1660e01b815260040161161893929190615bff565b60206040518083038186803b15801561163057600080fd5b505afa158015611644573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061166891908101906151c2565b90506000611674611eb4565b6001600160a01b031663654a60ac6004548760400151631cd554d160e21b6040518463ffffffff1660e01b81526004016116b093929190615bff565b60206040518083038186803b1580156116c857600080fd5b505afa1580156116dc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061170091908101906151c2565b90506000731a60e2e2a8be0bc2b6381dd31fd3fd5f9a28de4c63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b15801561174857600080fd5b505af415801561175c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061178091908101906151c2565b905060006117a961179c600a54856134fe90919063ffffffff16565b859063ffffffff61352816565b905060006117e26117d5600a546117c98987611ecf90919063ffffffff16565b9063ffffffff6134fe16565b849063ffffffff61352816565b905060006117f6838363ffffffff6134fe16565b9050611800611eb4565b6001600160a01b031663654a60ac631cd554d160e21b838c606001516040518463ffffffff1660e01b815260040161183a93929190615bff565b60206040518083038186803b15801561185257600080fd5b505afa158015611866573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061188a91908101906151c2565b9998505050505050505050565b600d5481565b6118a5611deb565b6001600160a01b031663dd62ed3e33306040518363ffffffff1660e01b81526004016118d2929190615b1c565b60206040518083038186803b1580156118ea57600080fd5b505afa1580156118fe573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061192291908101906151c2565b8311156119415760405162461bcd60e51b815260040161080590615c89565b61194e8383836001613550565b50611957611deb565b6001600160a01b03166323b872dd3330866040518463ffffffff1660e01b8152600401610c4093929190615b37565b6000611990613d79565b6001600160a01b0316637c3125416040518163ffffffff1660e01b815260040160006040518083038186803b1580156119c857600080fd5b505afa1580156119dc573d6000803e3d6000fd5b505050506119e8611eb4565b6001600160a01b0316632528f0fe6004546040518263ffffffff1660e01b8152600401611a159190615bb5565b60206040518083038186803b158015611a2d57600080fd5b505afa158015611a41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611a6591908101906150c9565b15611a825760405162461bcd60e51b815260040161080590615d69565b60008211611aa25760405162461bcd60e51b815260040161080590615ca9565b611aaa614cf2565b6005546040516350e28ac360e11b81526001600160a01b039091169063a1c5158690611adc9088908890600401615b88565b6101206040518083038186803b158015611af557600080fd5b505afa158015611b09573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611b2d91908101906151a3565b9050611b3881613d93565b611b4181613df3565b9050611b52338260600151856142df565b600a54611b5e82611439565b10611b7b5760405162461bcd60e51b815260040161080590615cd9565b6000611b86826115ad565b90506000848210611b975784611b99565b815b90506000611bb88460c001518560800151611ecf90919063ffffffff16565b9050808210611bd757611bcc883386614392565b9450505050506111a5565b611be18483614761565b9350611bf184606001518361058d565b6040850151909550611c09908663ffffffff61352816565b604085015242610100850152611c1d614984565b6001600160a01b031663d6f32e063386606001516040518363ffffffff1660e01b8152600401611c4e929190615b5f565b60206040518083038186803b158015611c6657600080fd5b505afa158015611c7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611c9e91908101906150c9565b15611cbb5760405162461bcd60e51b815260040161080590615df9565b6060840151600090815260086020526040902054611cd89061499b565b6001600160a01b0316639dc29fac33846040518363ffffffff1660e01b8152600401611d05929190615b5f565b600060405180830381600087803b158015611d1f57600080fd5b505af1158015611d33573d6000803e3d6000fd5b5050600554604051631137390760e21b81526001600160a01b0390911692506344dce41c9150611d67908790600401615e09565b600060405180830381600087803b158015611d8157600080fd5b505af1158015611d95573d6000803e3d6000fd5b50505050876001600160a01b03167fb6e43890aeea54fbe6c0ed628e78172a0ff30bbcb1d70d8b130b12c366bac4c588338589604051611dd89493929190615e18565b60405180910390a2505050509392505050565b6000611e026814de5b9d1a1cd554d160ba1b6149a2565b905090565b6000611e116149ff565b6001600160a01b03166323257c2b6d53797374656d53657474696e677360901b716c69717569646174696f6e50656e616c747960701b6040518363ffffffff1660e01b8152600401611e64929190615bd1565b60206040518083038186803b158015611e7c57600080fd5b505afa158015611e90573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611e0291908101906151c2565b6000611e026c45786368616e6765526174657360981b6149a2565b600082820183811015611ef45760405162461bcd60e51b815260040161080590615cb9565b90505b92915050565b6000670de0b6b3a7640000611f18848463ffffffff614a1c16565b81611f1f57fe5b049392505050565b6000611f31613d79565b6001600160a01b0316637c3125416040518163ffffffff1660e01b815260040160006040518083038186803b158015611f6957600080fd5b505afa158015611f7d573d6000803e3d6000fd5b50505050611f89611eb4565b6001600160a01b0316632528f0fe6004546040518263ffffffff1660e01b8152600401611fb69190615bb5565b60206040518083038186803b158015611fce57600080fd5b505afa158015611fe2573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061200691908101906150c9565b156120235760405162461bcd60e51b815260040161080590615d69565b61202b614cf2565b6005546040516350e28ac360e11b81526001600160a01b039091169063a1c515869061205d9087908790600401615b88565b6101206040518083038186803b15801561207657600080fd5b505afa15801561208a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506120ae91908101906151a3565b90506120b981613d93565b6120c281613df3565b905060006120e18260c001518360800151611ecf90919063ffffffff16565b90506120f682602001518360600151836142df565b6120fe614984565b6001600160a01b031663d6f32e068684606001516040518363ffffffff1660e01b815260040161212f929190615b88565b60206040518083038186803b15801561214757600080fd5b505afa15801561215b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061217f91908101906150c9565b1561219c5760405162461bcd60e51b815260040161080590615d09565b60608201516000908152600860205260409020546121b99061499b565b6001600160a01b0316639dc29fac86836040518363ffffffff1660e01b81526004016121e6929190615b88565b600060405180830381600087803b15801561220057600080fd5b505af1158015612214573d6000803e3d6000fd5b505050508160a00151156123325761222a614a56565b6001600160a01b0316635246f2b9836060015184608001516040518363ffffffff1660e01b815260040161225f929190615bd1565b600060405180830381600087803b15801561227957600080fd5b505af115801561228d573d6000803e3d6000fd5b5050505060608201516000908152600960205260409020546001600160a01b03161561232d57606082015160009081526009602052604090819020546080840151915163f3fef3a360e01b81526001600160a01b039091169163f3fef3a3916122fa918991600401615b88565b600060405180830381600087803b15801561231457600080fd5b505af1158015612328573d6000803e3d6000fd5b505050505b6123a2565b61233a614a56565b6001600160a01b031663e50a31b3836060015184608001516040518363ffffffff1660e01b815260040161236f929190615bd1565b600060405180830381600087803b15801561238957600080fd5b505af115801561239d573d6000803e3d6000fd5b505050505b816040015192506123bb8260c001518360600151614a65565b600060808301819052604080840182905260c0840182905260e0840191909152426101008401526005549051631137390760e21b81526001600160a01b03909116906344dce41c90612411908590600401615e09565b600060405180830381600087803b15801561242b57600080fd5b505af115801561243f573d6000803e3d6000fd5b50505050846001600160a01b03167fcab22a4e95d29d40da2ace3f6ec72b49954a9bc7b2584f8fd47bf7f357a3ed6f8560405161247c9190615bb5565b60405180910390a2505092915050565b6000546001600160a01b031633146124b65760405162461bcd60e51b815260040161080590615d89565b565b6124c0613d79565b6001600160a01b0316637c3125416040518163ffffffff1660e01b815260040160006040518083038186803b1580156124f857600080fd5b505afa15801561250c573d6000803e3d6000fd5b50505050612518611eb4565b6001600160a01b0316632528f0fe6004546040518263ffffffff1660e01b81526004016125459190615bb5565b60206040518083038186803b15801561255d57600080fd5b505afa158015612571573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061259591908101906150c9565b156125b25760405162461bcd60e51b815260040161080590615d69565b600081116125d25760405162461bcd60e51b815260040161080590615dc9565b6125da614cf2565b6005546040516350e28ac360e11b81526001600160a01b039091169063a1c515869061260c9087908790600401615b88565b6101206040518083038186803b15801561262557600080fd5b505afa158015612639573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061265d91908101906151a3565b905061266881613d93565b61267181613df3565b6040810151909150612689908363ffffffff611ecf16565b604080830191909152426101008301526005549051631137390760e21b81526001600160a01b03909116906344dce41c906126c8908490600401615e09565b600060405180830381600087803b1580156126e257600080fd5b505af11580156126f6573d6000803e3d6000fd5b50505050836001600160a01b03167f0b1992dffc262be88559dcaf96464e9d661d8bfca7e82f2bb73e31932a82187c8484846040015160405161273b93929190615bff565b60405180910390a250505050565b6000612753613d79565b6001600160a01b0316637c3125416040518163ffffffff1660e01b815260040160006040518083038186803b15801561278b57600080fd5b505afa15801561279f573d6000803e3d6000fd5b505050506127ab611eb4565b6001600160a01b0316632528f0fe6004546040518263ffffffff1660e01b81526004016127d89190615bb5565b60206040518083038186803b1580156127f057600080fd5b505afa158015612804573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061282891908101906150c9565b156128455760405162461bcd60e51b815260040161080590615d69565b61284d614cf2565b6005546040516350e28ac360e11b81526001600160a01b039091169063a1c515869061287f9033908890600401615b5f565b6101206040518083038186803b15801561289857600080fd5b505afa1580156128ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506128d091908101906151a3565b90506128db81613d93565b6128e481613df3565b60408101519091506128fc908463ffffffff61352816565b604082015242610100820152600a5461291482611439565b116129315760405162461bcd60e51b815260040161080590615c59565b600554604051631137390760e21b81526001600160a01b03909116906344dce41c90612961908490600401615e09565b600060405180830381600087803b15801561297b57600080fd5b505af115801561298f573d6000803e3d6000fd5b50505050829150336001600160a01b03167ffae26280bca25d80f1501a9e363c73d3845e651c9aaae54f1fc09a9dcd5f3303858584604001516040516129d793929190615bff565b60405180910390a25092915050565b6000611e02600a54731a60e2e2a8be0bc2b6381dd31fd3fd5f9a28de4c63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b158015612a3257600080fd5b505af4158015612a46573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250612a6a91908101906151c2565b9063ffffffff614c1b16565b604080516001808252818301909252606091602080830190803883390190505090506e466c657869626c6553746f7261676560881b81600081518110612ab857fe5b60200260200101818152505090565b60608151835101604051908082528060200260200182016040528015612af7578160200160208202803883390190505b50905060005b8351811015612b3957838181518110612b1257fe5b6020026020010151828281518110612b2657fe5b6020908102919091010152600101612afd565b5060005b8251811015612b7c57828181518110612b5257fe5b6020026020010151828286510181518110612b6957fe5b6020908102919091010152600101612b3d565b5092915050565b612b8b613d79565b6001600160a01b0316637c3125416040518163ffffffff1660e01b815260040160006040518083038186803b158015612bc357600080fd5b505afa158015612bd7573d6000803e3d6000fd5b50505050612be3611eb4565b6001600160a01b0316632528f0fe6004546040518263ffffffff1660e01b8152600401612c109190615bb5565b60206040518083038186803b158015612c2857600080fd5b505afa158015612c3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250612c6091908101906150c9565b15612c7d5760405162461bcd60e51b815260040161080590615d69565b60008111612c9d5760405162461bcd60e51b815260040161080590615ca9565b612ca5614cf2565b6005546040516350e28ac360e11b81526001600160a01b039091169063a1c5158690612cd79088908790600401615b88565b6101206040518083038186803b158015612cf057600080fd5b505afa158015612d04573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250612d2891908101906151a3565b9050612d3381613d93565b612d3c81613df3565b9050612d4d848260600151846142df565b612d578183614761565b426101008201529050612d68614984565b6001600160a01b031663d6f32e068583606001516040518363ffffffff1660e01b8152600401612d99929190615b88565b60206040518083038186803b158015612db157600080fd5b505afa158015612dc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250612de991908101906150c9565b15612e065760405162461bcd60e51b815260040161080590615df9565b6060810151600090815260086020526040902054612e239061499b565b6001600160a01b0316639dc29fac85846040518363ffffffff1660e01b8152600401612e50929190615b88565b600060405180830381600087803b158015612e6a57600080fd5b505af1158015612e7e573d6000803e3d6000fd5b5050600554604051631137390760e21b81526001600160a01b0390911692506344dce41c9150612eb2908490600401615e09565b600060405180830381600087803b158015612ecc57600080fd5b505af1158015612ee0573d6000803e3d6000fd5b50505050836001600160a01b0316856001600160a01b03167fdf10512219e869922340b1b24b21d7d79bf71f411a6391cc7c3ef5dd2fe89e7f85858560800151604051612f2f93929190615bff565b60405180910390a35050505050565b612f46613d79565b6001600160a01b0316637c3125416040518163ffffffff1660e01b815260040160006040518083038186803b158015612f7e57600080fd5b505afa158015612f92573d6000803e3d6000fd5b50505050612f9e611eb4565b6001600160a01b0316632528f0fe6004546040518263ffffffff1660e01b8152600401612fcb9190615bb5565b60206040518083038186803b158015612fe357600080fd5b505afa158015612ff7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061301b91908101906150c9565b156130385760405162461bcd60e51b815260040161080590615d69565b613040614cf2565b6005546040516350e28ac360e11b81526001600160a01b039091169063a1c51586906130729033908790600401615b5f565b6101206040518083038186803b15801561308b57600080fd5b505afa15801561309f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506130c391908101906151a3565b90506130ce81613d93565b6130d781613df3565b60808101519091506130ef908363ffffffff611ecf16565b6080820152600a5461310082611439565b1161311d5760405162461bcd60e51b815260040161080590615c69565b6000613134600c5484614c3090919063ffffffff16565b90506000613148848363ffffffff61352816565b90508260a00151156133555761315c614a56565b6001600160a01b031663e31f27c18460600151866040518363ffffffff1660e01b815260040161318d929190615bd1565b600060405180830381600087803b1580156131a757600080fd5b505af11580156131bb573d6000803e3d6000fd5b505050506131c7611deb565b6001600160a01b031663867904b4336131de611eb4565b6001600160a01b031663654a60ac876060015186631cd554d160e21b6040518463ffffffff1660e01b815260040161321893929190615bff565b60206040518083038186803b15801561323057600080fd5b505afa158015613244573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061326891908101906151c2565b6040518363ffffffff1660e01b8152600401613285929190615b5f565b600060405180830381600087803b15801561329f57600080fd5b505af11580156132b3573d6000803e3d6000fd5b5050505060608301516000908152600960205260409020546001600160a01b0316156133505760608301516000908152600960205260409081902054905163db454a5160e01b81526001600160a01b039091169063db454a519061331d9033908890600401615b5f565b600060405180830381600087803b15801561333757600080fd5b505af115801561334b573d6000803e3d6000fd5b505050505b61343d565b61335d614a56565b6001600160a01b031663eb94bbde8460600151866040518363ffffffff1660e01b815260040161338e929190615bd1565b600060405180830381600087803b1580156133a857600080fd5b505af11580156133bc573d6000803e3d6000fd5b50505060608401516000908152600860205260409020546133dd915061499b565b6001600160a01b031663867904b433836040518363ffffffff1660e01b815260040161340a929190615b5f565b600060405180830381600087803b15801561342457600080fd5b505af1158015613438573d6000803e3d6000fd5b505050505b61344b828460600151614a65565b42610100840152600554604051631137390760e21b81526001600160a01b03909116906344dce41c90613482908690600401615e09565b600060405180830381600087803b15801561349c57600080fd5b505af11580156134b0573d6000803e3d6000fd5b50505050336001600160a01b03167f5754fe57f36ac0f121901d7555aba517e6608590429d86a81c662cf35831065486866040516134ef929190615bd1565b60405180910390a25050505050565b60006111a58261351c85670de0b6b3a764000063ffffffff614a1c16565b9063ffffffff614c4516565b60008282111561354a5760405162461bcd60e51b815260040161080590615d19565b50900390565b600061355a613d79565b6001600160a01b0316637c3125416040518163ffffffff1660e01b815260040160006040518083038186803b15801561359257600080fd5b505afa1580156135a6573d6000803e3d6000fd5b5050600f5460ff1691506135ce90505760405162461bcd60e51b815260040161080590615d49565b6135d6611eb4565b6001600160a01b0316632528f0fe6004546040518263ffffffff1660e01b81526004016136039190615bb5565b60206040518083038186803b15801561361b57600080fd5b505afa15801561362f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061365391908101906150c9565b156136705760405162461bcd60e51b815260040161080590615d69565b60008381526008602052604090205461369b5760405162461bcd60e51b815260040161080590615d99565b6136a3611eb4565b6001600160a01b0316632528f0fe846040518263ffffffff1660e01b81526004016136ce9190615bb5565b60206040518083038186803b1580156136e657600080fd5b505afa1580156136fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061371e91908101906150c9565b1561373b5760405162461bcd60e51b815260040161080590615cf9565b600b5485101561375d5760405162461bcd60e51b815260040161080590615ce9565b600d5460055460405163382dab6f60e21b81526001600160a01b039091169063e0b6adbc90613790903390600401615b0e565b60206040518083038186803b1580156137a857600080fd5b505afa1580156137bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506137e091908101906151c2565b106137fd5760405162461bcd60e51b815260040161080590615cc9565b600080613808614a56565b6001600160a01b031663b4d6cb4087876040518363ffffffff1660e01b8152600401613835929190615bd1565b604080518083038186803b15801561384c57600080fd5b505afa158015613860573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061388491908101906150e7565b91509150818015613893575080155b6138af5760405162461bcd60e51b815260040161080590615dd9565b6138b98786611103565b8611156138d85760405162461bcd60e51b815260040161080590615d79565b60006138ef600c5488614c3090919063ffffffff16565b90506000613903888363ffffffff61352816565b905061390d614a56565b6001600160a01b031663b3b467326040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561394757600080fd5b505af115801561395b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061397f91908101906151c2565b9450613989614cf2565b604051806101200160405280878152602001336001600160a01b031681526020018b81526020018981526020018a8152602001881515815260200160008152602001600081526020014281525090506139e181613df3565b60055460405163170cc48160e21b81529192506001600160a01b031690635c33120490613a12908490600401615e09565b600060405180830381600087803b158015613a2c57600080fd5b505af1158015613a40573d6000803e3d6000fd5b50505050613a4e8389614a65565b8615613c4457613a5c611deb565b6001600160a01b031663867904b433613a73611eb4565b6001600160a01b031663654a60ac8c87631cd554d160e21b6040518463ffffffff1660e01b8152600401613aa993929190615bff565b60206040518083038186803b158015613ac157600080fd5b505afa158015613ad5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250613af991908101906151c2565b6040518363ffffffff1660e01b8152600401613b16929190615b5f565b600060405180830381600087803b158015613b3057600080fd5b505af1158015613b44573d6000803e3d6000fd5b50505050613b50614a56565b6001600160a01b031663e31f27c1898b6040518363ffffffff1660e01b8152600401613b7d929190615bd1565b600060405180830381600087803b158015613b9757600080fd5b505af1158015613bab573d6000803e3d6000fd5b5050506000898152600960205260409020546001600160a01b0316159050613c3f576000888152600960205260409081902054905163db454a5160e01b81526001600160a01b039091169063db454a5190613c0c9033908d90600401615b5f565b600060405180830381600087803b158015613c2657600080fd5b505af1158015613c3a573d6000803e3d6000fd5b505050505b613d23565b600088815260086020526040902054613c5c9061499b565b6001600160a01b031663867904b433846040518363ffffffff1660e01b8152600401613c89929190615b5f565b600060405180830381600087803b158015613ca357600080fd5b505af1158015613cb7573d6000803e3d6000fd5b50505050613cc3614a56565b6001600160a01b031663eb94bbde898b6040518363ffffffff1660e01b8152600401613cf0929190615bd1565b600060405180830381600087803b158015613d0a57600080fd5b505af1158015613d1e573d6000803e3d6000fd5b505050505b336001600160a01b03167f604952b18be5fed608cbdd28101dc57bd667055c9678ec6d44fb1d8e4c7c172a878b8d8c88604051613d64959493929190615e56565b60405180910390a25050505050949350505050565b6000611e026b53797374656d53746174757360a01b6149a2565b60008160e0015111613db75760405162461bcd60e51b815260040161080590615de9565b42613dd2600e54836101000151611ecf90919063ffffffff16565b1115613df05760405162461bcd60e51b815260040161080590615c99565b50565b613dfb614cf2565b8190506000806000808560a00151613e9957613e15614a56565b6001600160a01b03166303f048b08760e001516040518263ffffffff1660e01b8152600401613e449190615bb5565b60806040518083038186803b158015613e5c57600080fd5b505afa158015613e70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250613e949190810190615220565b613f26565b613ea1614a56565b6001600160a01b031663af07aa9d87606001518860e001516040518363ffffffff1660e01b8152600401613ed6929190615bd1565b60806040518083038186803b158015613eee57600080fd5b505afa158015613f02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250613f269190810190615220565b93509350935093506000808760a00151613fb657613f42614a56565b6001600160a01b031663ba1c5e806040518163ffffffff1660e01b8152600401604080518083038186803b158015613f7957600080fd5b505afa158015613f8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250613fb191908101906151e0565b61404e565b613fbe614a56565b606089015160009081526008602052604090819020549051630ee81f7960e41b81526001600160a01b03929092169163ee81f79091613fff91600401615bb5565b604080518083038186803b15801561401657600080fd5b505afa15801561402a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061404e91908101906151e0565b9150915080156140705760405162461bcd60e51b815260040161080590615d39565b600061410d731a60e2e2a8be0bc2b6381dd31fd3fd5f9a28de4c63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b1580156140b957600080fd5b505af41580156140cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506140f191908101906151c2565b614101428863ffffffff61352816565b9063ffffffff614a1c16565b90506000614131614124858463ffffffff611efd16565b889063ffffffff611ecf16565b905060008a60e0015160001461416a57614165614154838b63ffffffff61352816565b60808d01519063ffffffff611efd16565b61416d565b60005b90508a60a001516141e257614180614a56565b6001600160a01b031663f53037b6836040518263ffffffff1660e01b81526004016141ab9190615bb5565b600060405180830381600087803b1580156141c557600080fd5b505af11580156141d9573d6000803e3d6000fd5b5050505061424e565b6141ea614a56565b6001600160a01b031663246206398c60600151846040518363ffffffff1660e01b815260040161421b929190615bd1565b600060405180830381600087803b15801561423557600080fd5b505af1158015614249573d6000803e3d6000fd5b505050505b60c08b0151614263908263ffffffff611ecf16565b60c08b015260e08a01869052600554604051631137390760e21b81526001600160a01b03909116906344dce41c9061429f908d90600401615e09565b600060405180830381600087803b1580156142b957600080fd5b505af11580156142cd573d6000803e3d6000fd5b50505050505050505050505050919050565b60008281526008602052604090205481906142f99061499b565b6001600160a01b03166370a08231856040518263ffffffff1660e01b81526004016143249190615b00565b60206040518083038186803b15801561433c57600080fd5b505afa158015614350573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061437491908101906151c2565b101561075e5760405162461bcd60e51b815260040161080590615db9565b6000806143b08360c001518460800151611ecf90919063ffffffff16565b6080840151604085015193509091506143c7614984565b6001600160a01b031663d6f32e068686606001516040518363ffffffff1660e01b81526004016143f8929190615b88565b60206040518083038186803b15801561441057600080fd5b505afa158015614424573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061444891908101906150c9565b156144655760405162461bcd60e51b815260040161080590615df9565b60608401516000908152600860205260409020546144829061499b565b6001600160a01b0316639dc29fac86846040518363ffffffff1660e01b81526004016144af929190615b88565b600060405180830381600087803b1580156144c957600080fd5b505af11580156144dd573d6000803e3d6000fd5b505050508360a00151156145fb576144f3614a56565b6001600160a01b0316635246f2b9856060015186608001516040518363ffffffff1660e01b8152600401614528929190615bd1565b600060405180830381600087803b15801561454257600080fd5b505af1158015614556573d6000803e3d6000fd5b5050505060608401516000908152600960205260409020546001600160a01b0316156145f657606084015160009081526009602052604090819020546080860151915163f3fef3a360e01b81526001600160a01b039091169163f3fef3a3916145c3918a91600401615b88565b600060405180830381600087803b1580156145dd57600080fd5b505af11580156145f1573d6000803e3d6000fd5b505050505b61466b565b614603614a56565b6001600160a01b031663e50a31b3856060015186608001516040518363ffffffff1660e01b8152600401614638929190615bd1565b600060405180830381600087803b15801561465257600080fd5b505af1158015614666573d6000803e3d6000fd5b505050505b61467d8460c001518560600151614a65565b600060808501819052604080860182905260c0860182905260e0860191909152426101008601526005549051631137390760e21b81526001600160a01b03909116906344dce41c906146d3908790600401615e09565b600060405180830381600087803b1580156146ed57600080fd5b505af1158015614701573d6000803e3d6000fd5b50505050846001600160a01b0316866001600160a01b03167f697721ed1b9d4866cb1aaa0692f62bb3abc1b01c2dafeaad053ffd4532aa7dbb8660000151848760405161475093929190615bff565b60405180910390a350509392505050565b614769614cf2565b5081811580159061477e575060008360c00151115b156147db5760008360c001518311614796578261479c565b8360c001515b60c08501519091506147b4908263ffffffff61352816565b60c08301526147c9838263ffffffff61352816565b92506147d9818560600151614a65565b505b8115611ef75760808301516147f6908363ffffffff61352816565b608082015260a0810151156149135761480d614a56565b6001600160a01b0316635246f2b98260600151846040518363ffffffff1660e01b815260040161483e929190615bd1565b600060405180830381600087803b15801561485857600080fd5b505af115801561486c573d6000803e3d6000fd5b5050505060608101516000908152600960205260409020546001600160a01b03161561490e5760608101516000908152600960209081526040918290205490830151915163f3fef3a360e01b81526001600160a01b039091169163f3fef3a3916148db91908690600401615b5f565b600060405180830381600087803b1580156148f557600080fd5b505af1158015614909573d6000803e3d6000fd5b505050505b611ef7565b61491b614a56565b6001600160a01b031663e50a31b38260600151846040518363ffffffff1660e01b815260040161494c929190615bd1565b600060405180830381600087803b15801561496657600080fd5b505af115801561497a573d6000803e3d6000fd5b5050505092915050565b6000611e026822bc31b430b733b2b960b91b6149a2565b6000611ef7825b60008181526003602090815260408083205490516001600160a01b0390911691821515916149d291869101615ad5565b60405160208183030381529060405290612b7c5760405162461bcd60e51b81526004016108059190615c28565b6000611e026e466c657869626c6553746f7261676560881b6149a2565b600082614a2b57506000611ef7565b82820282848281614a3857fe5b0414611ef45760405162461bcd60e51b815260040161080590615da9565b6006546001600160a01b031690565b8115610e1957631cd554d160e21b8114614b0a57614a81611eb4565b6001600160a01b031663654a60ac8284631cd554d160e21b6040518463ffffffff1660e01b8152600401614ab793929190615bff565b60206040518083038186803b158015614acf57600080fd5b505afa158015614ae3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250614b0791908101906151c2565b91505b614b12611deb565b6001600160a01b031663867904b4614b28614c7a565b6001600160a01b031663eb1edd616040518163ffffffff1660e01b815260040160206040518083038186803b158015614b6057600080fd5b505afa158015614b74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250614b989190810190614f96565b846040518363ffffffff1660e01b8152600401614bb6929190615b88565b600060405180830381600087803b158015614bd057600080fd5b505af1158015614be4573d6000803e3d6000fd5b50505050614bf0614c7a565b6001600160a01b03166322bf55ef836040518263ffffffff1660e01b8152600401610de69190615bb5565b60006111a58383670de0b6b3a7640000614c8f565b60006111a58383670de0b6b3a7640000614cc7565b6000808211614c665760405162461bcd60e51b815260040161080590615d29565b6000828481614c7157fe5b04949350505050565b6000611e0266119959541bdbdb60ca1b6149a2565b600080614ca98461351c87600a870263ffffffff614a1c16565b90506005600a825b0610614cbb57600a015b600a9004949350505050565b600080600a8304614cde868663ffffffff614a1c16565b81614ce557fe5b0490506005600a82614cb1565b6040518061012001604052806000815260200160006001600160a01b031681526020016000815260200160008019168152602001600081526020016000151581526020016000815260200160008152602001600081525090565b8035611ef781615f45565b8051611ef781615f45565b60008083601f840112614d7457600080fd5b50813567ffffffffffffffff811115614d8c57600080fd5b602083019150836020820283011115614da457600080fd5b9250929050565b8035611ef781615f59565b8051611ef781615f59565b8035611ef781615f62565b8051611ef781615f62565b60006101208284031215614dea57600080fd5b614df5610120615ea2565b90506000614e038484614dc1565b8252506020614e1484848301614d4c565b6020830152506040614e2884828501614dc1565b6040830152506060614e3c84828501614dc1565b6060830152506080614e5084828501614dc1565b60808301525060a0614e6484828501614dab565b60a08301525060c0614e7884828501614dc1565b60c08301525060e0614e8c84828501614dc1565b60e083015250610100614ea184828501614dc1565b6101008301525092915050565b60006101208284031215614ec157600080fd5b614ecc610120615ea2565b90506000614eda8484614dcc565b8252506020614eeb84848301614d57565b6020830152506040614eff84828501614dcc565b6040830152506060614f1384828501614dcc565b6060830152506080614f2784828501614dcc565b60808301525060a0614f3b84828501614db6565b60a08301525060c0614f4f84828501614dcc565b60c08301525060e0614f6384828501614dcc565b60e083015250610100614ea184828501614dcc565b600060208284031215614f8a57600080fd5b60006106c18484614d4c565b600060208284031215614fa857600080fd5b60006106c18484614d57565b60008060408385031215614fc757600080fd5b6000614fd38585614d4c565b9250506020614fe485828601614dc1565b9150509250929050565b60008060006060848603121561500357600080fd5b600061500f8686614d4c565b935050602061502086828701614dc1565b925050604061503186828701614dc1565b9150509250925092565b6000806000806040858703121561505157600080fd5b843567ffffffffffffffff81111561506857600080fd5b61507487828801614d62565b9450945050602085013567ffffffffffffffff81111561509357600080fd5b61509f87828801614d62565b95989497509550505050565b6000602082840312156150bd57600080fd5b60006106c18484614dab565b6000602082840312156150db57600080fd5b60006106c18484614db6565b600080604083850312156150fa57600080fd5b60006151068585614db6565b9250506020614fe485828601614db6565b60006020828403121561512957600080fd5b60006106c18484614dc1565b6000806040838503121561514857600080fd5b60006151548585614dc1565b9250506020614fe485828601614d4c565b6000806040838503121561517857600080fd5b6000614fd38585614dc1565b6000610120828403121561519757600080fd5b60006106c18484614dd7565b600061012082840312156151b657600080fd5b60006106c18484614eae565b6000602082840312156151d457600080fd5b60006106c18484614dcc565b600080604083850312156151f357600080fd5b60006151068585614dcc565b60008060006060848603121561521457600080fd5b600061500f8686614dc1565b6000806000806080858703121561523657600080fd5b60006152428787614dcc565b945050602061525387828801614dcc565b935050604061526487828801614dcc565b925050606061527587828801614dcc565b91505092959194509250565b600061528d838361530f565b505060200190565b61529e81615efd565b82525050565b61529e81615ee1565b60006152b882615ecf565b6152c28185615ed3565b93506152cd83615ec9565b8060005b838110156152fb5781516152e58882615281565b97506152f083615ec9565b9250506001016152d1565b509495945050505050565b61529e81615eec565b61529e81610bbb565b61529e61532482610bbb565b610bbb565b61529e81615f04565b600061533d82615ecf565b6153478185615ed3565b9350615357818560208601615f0f565b61536081615f3b565b9093019392505050565b6000615377601b83615ed3565b7f496e707574206172726179206c656e677468206d69736d617463680000000000815260200192915050565b60006153b0601683615ed3565b754d7573742062652067726561746572207468616e203160501b815260200192915050565b60006153e2600e83615ed3565b6d43726174696f20746f6f206c6f7760901b815260200192915050565b600061540c601583615ed3565b74086c2dcdcdee840c8e4c2ee40e8d0d2e640daeac6d605b1b815260200192915050565b600061543d603583615ed3565b7f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7581527402063616e20616363657074206f776e65727368697605c1b602082015260400192915050565b6000615494601983615ed3565b7f416c6c6f77616e6365206e6f74206869676820656e6f75676800000000000000815260200192915050565b60006154cd601d83615ed3565b7f4c6f616e20726563656e746c7920696e74657261637465642077697468000000815260200192915050565b6000615506601e83615ed3565b7f5061796d656e74206d7573742062652067726561746572207468616e20300000815260200192915050565b600061553f601b83615ed3565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000815260200192915050565b6000615578601283615ed3565b7113585e081b1bd85b9cc8195e18d95959195960721b815260200192915050565b60006155a6601e83615ed3565b7f43726174696f2061626f7665206c69717569646174696f6e20726174696f0000815260200192915050565b60006155df601d83615ed3565b7f4e6f7420656e6f75676820636f6c6c61746572616c20746f206f70656e000000815260200192915050565b6000615618601883615ed3565b7f43757272656e6379207261746520697320696e76616c69640000000000000000815260200192915050565b6000615651602083615ed3565b7f57616974696e672073656373206f7220736574746c656d656e74206f77696e67815260200192915050565b600061568a601e83615ed3565b7f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815260200192915050565b60006156c3601a83615ed3565b7f536166654d6174683a206469766973696f6e206279207a65726f000000000000815260200192915050565b60006156fc601183615edc565b70026b4b9b9b4b7339030b2323932b9b99d1607d1b815260110192915050565b6000615729601183615ed3565b7014985d195cc8185c99481a5b9d985b1a59607a1b815260200192915050565b6000615756601383615ed3565b7213dc195b9a5b99c81a5cc8191a5cd8589b1959606a1b815260200192915050565b6000615785600a83615ed3565b6926b0bc1018903437bab960b11b815260200192915050565b60006157ab601a83615ed3565b7f436f6c6c61746572616c207261746520697320696e76616c6964000000000000815260200192915050565b60006157e4601b83615ed3565b7f45786365656473206d617820626f72726f77696e6720706f7765720000000000815260200192915050565b600061581d602f83615ed3565b7f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726681526e37b936903a3434b99030b1ba34b7b760891b602082015260400192915050565b600061586e601f83615ed3565b7f4e6f7420616c6c6f77656420746f20697373756520746869732073796e746800815260200192915050565b60006158a7602183615ed3565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f8152607760f81b602082015260400192915050565b60006158ea601883615ed3565b7f4e6f7420656e6f7567682073796e74682062616c616e63650000000000000000815260200192915050565b6000615923601e83615ed3565b7f4465706f736974206d7573742062652067726561746572207468616e20300000815260200192915050565b600061595c601a83615ed3565b7f44656274206c696d6974206f7220696e76616c69642072617465000000000000815260200192915050565b6000615995601983615edc565b7f5265736f6c766572206d697373696e67207461726765743a2000000000000000815260190192915050565b60006159ce601383615ed3565b72131bd85b88191bd95cc81b9bdd08195e1a5cdd606a1b815260200192915050565b60006159fd601b83615ed3565b7f57616974696e67206f7220736574746c656d656e74206f77696e670000000000815260200192915050565b8051610120830190615a3b848261530f565b506020820151615a4e60208501826152a4565b506040820151615a61604085018261530f565b506060820151615a74606085018261530f565b506080820151615a87608085018261530f565b5060a0820151615a9a60a0850182615306565b5060c0820151615aad60c085018261530f565b5060e0820151615ac060e085018261530f565b50610100820151610aa061010085018261530f565b6000615ae0826156ef565b9150615aec8284615318565b50602001919050565b6000615ae082615988565b60208101611ef782846152a4565b60208101611ef78284615295565b60408101615b2a8285615295565b6111a560208301846152a4565b60608101615b458286615295565b615b5260208301856152a4565b6106c1604083018461530f565b60408101615b6d8285615295565b6111a5602083018461530f565b60408101615b2a82856152a4565b60408101615b6d82856152a4565b602080825281016111a581846152ad565b60208101611ef78284615306565b60208101611ef7828461530f565b60408101615b2a828561530f565b60408101615b6d828561530f565b60408101615bed828561530f565b81810360208301526106c18184615332565b60608101615c0d828661530f565b615b52602083018561530f565b60208101611ef78284615329565b602080825281016111a58184615332565b60208082528101611ef78161536a565b60208082528101611ef7816153a3565b60208082528101611ef7816153d5565b60208082528101611ef7816153ff565b60208082528101611ef781615430565b60208082528101611ef781615487565b60208082528101611ef7816154c0565b60208082528101611ef7816154f9565b60208082528101611ef781615532565b60208082528101611ef78161556b565b60208082528101611ef781615599565b60208082528101611ef7816155d2565b60208082528101611ef78161560b565b60208082528101611ef781615644565b60208082528101611ef78161567d565b60208082528101611ef7816156b6565b60208082528101611ef78161571c565b60208082528101611ef781615749565b60208082528101611ef781615778565b60208082528101611ef78161579e565b60208082528101611ef7816157d7565b60208082528101611ef781615810565b60208082528101611ef781615861565b60208082528101611ef78161589a565b60208082528101611ef7816158dd565b60208082528101611ef781615916565b60208082528101611ef78161594f565b60208082528101611ef7816159c1565b60208082528101611ef7816159f0565b6101208101611ef78284615a29565b60808101615e26828761530f565b615e336020830186615295565b615e40604083018561530f565b615e4d606083018461530f565b95945050505050565b60a08101615e64828861530f565b615e71602083018761530f565b615e7e604083018661530f565b615e8b606083018561530f565b615e98608083018461530f565b9695505050505050565b60405181810167ffffffffffffffff81118282101715615ec157600080fd5b604052919050565b60200190565b5190565b90815260200190565b919050565b6000611ef782615ef1565b151590565b6001600160a01b031690565b6000611ef7825b6000611ef782615ee1565b60005b83811015615f2a578181015183820152602001615f12565b83811115610aa05750506000910152565b601f01601f191690565b615f4e81615ee1565b8114613df057600080fd5b615f4e81615eec565b615f4e81610bbb56fea365627a7a723158207eea408e568f2b63599acab5435027c647d16c8da004a96930363835dfbc8f026c6578706572696d656e74616cf564736f6c63430005100040000000000000000000000000d74e3a605a1a7a8a83d25df00d4057985e3cac30000000000000000000000000b64ff7a4a33acdf48d97dab0d764afd0f617688200000000000000000000000053bae964339e8a742b5b47f6c10bbfa8ff138f34000000000000000000000000242a3df52c375bee81b1c668741d7c63af68fdd2735553440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010a741a46278000000000000000000000000000000000000000000000000003635c9adc5dea00000

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

000000000000000000000000d74e3a605a1a7a8a83d25df00d4057985e3cac30000000000000000000000000b64ff7a4a33acdf48d97dab0d764afd0f617688200000000000000000000000053bae964339e8a742b5b47f6c10bbfa8ff138f34000000000000000000000000242a3df52c375bee81b1c668741d7c63af68fdd2735553440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010a741a46278000000000000000000000000000000000000000000000000003635c9adc5dea00000

-----Decoded View---------------
Arg [0] : _state (address): 0xd74e3a605a1a7a8a83d25df00d4057985e3cac30
Arg [1] : _owner (address): 0xb64ff7a4a33acdf48d97dab0d764afd0f6176882
Arg [2] : _manager (address): 0x53bae964339e8a742b5b47f6c10bbfa8ff138f34
Arg [3] : _resolver (address): 0x242a3df52c375bee81b1c668741d7c63af68fdd2
Arg [4] : _collateralKey (bytes32): 0x7355534400000000000000000000000000000000000000000000000000000000
Arg [5] : _minCratio (uint256): 1200000000000000000
Arg [6] : _minCollateral (uint256): 1000000000000000000000

-----Encoded View---------------
7 Constructor Arguments found :
Arg [0] : 000000000000000000000000d74e3a605a1a7a8a83d25df00d4057985e3cac30
Arg [1] : 000000000000000000000000b64ff7a4a33acdf48d97dab0d764afd0f6176882
Arg [2] : 00000000000000000000000053bae964339e8a742b5b47f6c10bbfa8ff138f34
Arg [3] : 000000000000000000000000242a3df52c375bee81b1c668741d7c63af68fdd2
Arg [4] : 7355534400000000000000000000000000000000000000000000000000000000
Arg [5] : 00000000000000000000000000000000000000000000000010a741a462780000
Arg [6] : 00000000000000000000000000000000000000000000003635c9adc5dea00000


Library Used

SafeDecimalMath : 0x1a60e2e2a8be0bc2b6381dd31fd3fd5f9a28de4c

Block Transaction Difficulty Gas Used Reward
Block Uncle Number Difficulty Gas Used Reward
Loading