Contract 0xC9985cAc4a69588Da66F74E42845B784798fe5aB

Contract Overview

Balance:
0 Ether
Txn Hash Method
Block
From
To
Value
0xfd4be500e265d6f324a7f20ab08f794d5b792caab7ca497942c5c5e8195f6da8Update Rates249197012021-05-18 20:27:2014 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0010177242
0xc2542c340207bc73e18c156cec6b6f473da85a4d619eb62b88b371e505239330Update Rates249192772021-05-18 19:57:1644 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0xb404df87111e2ae85ae21dccc2b9f487621e9af9e9760cecb71b6d0b3d07816cUpdate Rates249188552021-05-18 19:27:241 hr 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0x20bd10c9e3ed149b6cff440f38f4f84637fdf2a8f2abcc9efcf7e3ba73c73da2Update Rates249184292021-05-18 18:57:121 hr 44 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0x493096e1edf9dbccb1112d5ec1e011f546d90a85e4d582f9d89d62a03507fee5Update Rates249175852021-05-18 17:57:122 hrs 44 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0x2e4df20c303ab25735ad0813c9ab1006f9561b2d0c675aa807ab0f36c3e53caaUpdate Rates249171552021-05-18 17:27:243 hrs 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0007556842
0x4dbe8545f9915d51ea40eb843d4395834f545550030a178b60ddae84ae80f1c0Update Rates249167112021-05-18 16:57:243 hrs 44 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0x35bf129c4bd9aff61a2339a6b3a5513e066646c5c7e2ae13c95b3ddca9a20d23Update Rates249162622021-05-18 16:27:124 hrs 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0007552962
0x9c985569b08b2c57a2dcdb940636199570f0e94a098befb27339ff51ed9b0736Update Rates249158352021-05-18 15:57:164 hrs 44 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0xdb49803a42c9fc5c3fcfab0beab870a3fb4a31260b16ee3587b9401ee756de12Update Rates249154082021-05-18 15:27:085 hrs 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0xeaa000ae1a802f2b5b1b4e4f697426cbe010ae246d11acd6c8114968da41f1daUpdate Rates249149902021-05-18 14:57:205 hrs 44 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0010171922
0xbe7e2427b584637ec1a80043b807ce1e1539a7c13c823bbb30f1ffcd48bd63afUpdate Rates249145682021-05-18 14:27:246 hrs 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0xa4300bcc25e19cf817c3bcec7981ce887602ec2cfba7217d97e5fafdd9fa424fUpdate Rates249141232021-05-18 13:57:086 hrs 44 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011080882
0xb491e92bf921f4f3e5a752d9caf3dc8ec7c92bfc57857014a60b1f1fe7ca9833Update Rates249136742021-05-18 13:27:127 hrs 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011938842
0x0a220ec8590f965045300418587e2cc5a44009a5157375db998bd997c80d2181Update Rates249132262021-05-18 12:57:207 hrs 44 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0xa7c8955c3d2b05b2f7e6ac6a30bcbe18ae8cb060f8bf8b236cfaebb1243c2cbaUpdate Rates249127742021-05-18 12:27:128 hrs 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0x6b3fb3bd68754a57dcda3eabc019b5b3590866720832397281538aef9fd4e18aUpdate Rates249123262021-05-18 11:57:208 hrs 44 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011080882
0xea5cd45a30beae9e50f3101268df47574db0730c57ae26c6b2101b6530fd4281Update Rates249118782021-05-18 11:27:249 hrs 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0xf9e9c8c7f0c255e7919cbd9e4fcabafff82f2ff904cfa27f4ebc9cac148547b7Update Rates249109792021-05-18 10:27:2810 hrs 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0x31c0fe440267bfa0823c779466598a7b0545eb66d8828727550f61d1934d0a90Update Rates249105302021-05-18 9:57:3210 hrs 44 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0010176282
0x31c5962d7a0064d6240a4854ee972da8f4932d6f6808247b0adaca4d354b0967Update Rates249100802021-05-18 9:27:3211 hrs 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011938842
0x0a3c065c164fd08ad2460e77b12a841ba36a0a54e7cf3fe8f885afcef638572bUpdate Rates249096282021-05-18 8:57:2411 hrs 44 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
0x6219b2ea80f090198b55dbbff79fb6a7a2824d1271aaeea5dfea34eb2c994718Update Rates249091822021-05-18 8:27:2812 hrs 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.001193862
0x2ad65a90b927828393e188c85a1f82de55c60eeb804c43a2e58fe68e3df2bd32Update Rates249087292021-05-18 7:57:1612 hrs 44 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.001017242
0xa9ce2a2efb9bc56ef924a9d71c530d8f266b355ef79610c85feca52a62c998beUpdate Rates249082822021-05-18 7:27:2813 hrs 14 mins ago0xac1e8b385230970319906c03a1d8567e3996d1d5 IN  0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether0.0011939082
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x367a3106c89eae4d3111abb46452a59d091b1d6a1c988dbc808a27c4d7cbbbe9249191262021-05-18 19:46:4454 mins ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0x6292aa9a6650ae14fbf974e5029f36f95a1848fd0 Ether
0x367a3106c89eae4d3111abb46452a59d091b1d6a1c988dbc808a27c4d7cbbbe9249191262021-05-18 19:46:4454 mins ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0xb1751e5ede811288ce2fc4c65aaca17a955366be0 Ether
0x367a3106c89eae4d3111abb46452a59d091b1d6a1c988dbc808a27c4d7cbbbe9249191262021-05-18 19:46:4454 mins ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0xb1751e5ede811288ce2fc4c65aaca17a955366be0 Ether
0x367a3106c89eae4d3111abb46452a59d091b1d6a1c988dbc808a27c4d7cbbbe9249191262021-05-18 19:46:4454 mins ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0x31f93da9823d737b7e44bdee0df389fe62fd1acd0 Ether
0x367a3106c89eae4d3111abb46452a59d091b1d6a1c988dbc808a27c4d7cbbbe9249191262021-05-18 19:46:4454 mins ago 0xd3655a8e0b163e5ae3bad37c35354050aa7c7694 0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether
0x367a3106c89eae4d3111abb46452a59d091b1d6a1c988dbc808a27c4d7cbbbe9249191262021-05-18 19:46:4454 mins ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0x6292aa9a6650ae14fbf974e5029f36f95a1848fd0 Ether
0x367a3106c89eae4d3111abb46452a59d091b1d6a1c988dbc808a27c4d7cbbbe9249191262021-05-18 19:46:4454 mins ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0xb1751e5ede811288ce2fc4c65aaca17a955366be0 Ether
0x367a3106c89eae4d3111abb46452a59d091b1d6a1c988dbc808a27c4d7cbbbe9249191262021-05-18 19:46:4454 mins ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0xb1751e5ede811288ce2fc4c65aaca17a955366be0 Ether
0x367a3106c89eae4d3111abb46452a59d091b1d6a1c988dbc808a27c4d7cbbbe9249191262021-05-18 19:46:4454 mins ago 0x3ad8366b716deea3f46730debff537b713c76404 0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether
0x6e9b5f638708ae4ccc35b5b02aa3f5781884f9bede571f8cb924742b7c787e64249191182021-05-18 19:46:1255 mins ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0x9326bfa02add2366b30bacb125260af6410313310 Ether
0x6e9b5f638708ae4ccc35b5b02aa3f5781884f9bede571f8cb924742b7c787e64249191182021-05-18 19:46:1255 mins ago 0xf92e70301e26aadeccec5016b7d0167daf416d72 0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether
0x6e9b5f638708ae4ccc35b5b02aa3f5781884f9bede571f8cb924742b7c787e64249191182021-05-18 19:46:1255 mins ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0x9326bfa02add2366b30bacb125260af6410313310 Ether
0x6e9b5f638708ae4ccc35b5b02aa3f5781884f9bede571f8cb924742b7c787e64249191182021-05-18 19:46:1255 mins ago 0xf92e70301e26aadeccec5016b7d0167daf416d72 0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether
0x6e9b5f638708ae4ccc35b5b02aa3f5781884f9bede571f8cb924742b7c787e64249191182021-05-18 19:46:1255 mins ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0x9326bfa02add2366b30bacb125260af6410313310 Ether
0x6e9b5f638708ae4ccc35b5b02aa3f5781884f9bede571f8cb924742b7c787e64249191182021-05-18 19:46:1255 mins ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0xb1751e5ede811288ce2fc4c65aaca17a955366be0 Ether
0x6e9b5f638708ae4ccc35b5b02aa3f5781884f9bede571f8cb924742b7c787e64249191182021-05-18 19:46:1255 mins ago 0xf92e70301e26aadeccec5016b7d0167daf416d72 0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether
0xa3913923f00cd03d111c700e7a10977980675f41a4fee67046733aa9c6cb03de249190452021-05-18 19:40:561 hr ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0x6292aa9a6650ae14fbf974e5029f36f95a1848fd0 Ether
0xa3913923f00cd03d111c700e7a10977980675f41a4fee67046733aa9c6cb03de249190452021-05-18 19:40:561 hr ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0xb1751e5ede811288ce2fc4c65aaca17a955366be0 Ether
0xa3913923f00cd03d111c700e7a10977980675f41a4fee67046733aa9c6cb03de249190452021-05-18 19:40:561 hr ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0xb1751e5ede811288ce2fc4c65aaca17a955366be0 Ether
0xa3913923f00cd03d111c700e7a10977980675f41a4fee67046733aa9c6cb03de249190452021-05-18 19:40:561 hr ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0x31f93da9823d737b7e44bdee0df389fe62fd1acd0 Ether
0xa3913923f00cd03d111c700e7a10977980675f41a4fee67046733aa9c6cb03de249190452021-05-18 19:40:561 hr ago 0xd3655a8e0b163e5ae3bad37c35354050aa7c7694 0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether
0xa3913923f00cd03d111c700e7a10977980675f41a4fee67046733aa9c6cb03de249190452021-05-18 19:40:561 hr ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0x6292aa9a6650ae14fbf974e5029f36f95a1848fd0 Ether
0xa3913923f00cd03d111c700e7a10977980675f41a4fee67046733aa9c6cb03de249190452021-05-18 19:40:561 hr ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0xb1751e5ede811288ce2fc4c65aaca17a955366be0 Ether
0xa3913923f00cd03d111c700e7a10977980675f41a4fee67046733aa9c6cb03de249190452021-05-18 19:40:561 hr ago 0xc9985cac4a69588da66f74e42845b784798fe5ab 0xb1751e5ede811288ce2fc4c65aaca17a955366be0 Ether
0xa3913923f00cd03d111c700e7a10977980675f41a4fee67046733aa9c6cb03de249190452021-05-18 19:40:561 hr ago 0x3ad8366b716deea3f46730debff537b713c76404 0xc9985cac4a69588da66f74e42845b784798fe5ab0 Ether
[ Download CSV Export 
Loading

Contract Source Code Verified (Similar Match)
Note: This contract matches the deployed ByteCode of the Source Code for Contract 0x7e37f2992E14E435F865E786631E5E390Ebf7E53

Contract Name:
ExchangeRates

Compiler Version
v0.5.16+commit.9c3226ce

Optimization Enabled:
Yes with 20000 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity)

/**
 *Submitted for verification at Etherscan.io on 2020-12-21
*/

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

* Synthetix: ExchangeRates.sol
*
* Latest source (may be newer): https://github.com/Synthetixio/synthetix/blob/master/contracts/ExchangeRates.sol
* Docs: https://docs.synthetix.io/contracts/ExchangeRates
*
* Contract Dependencies: 
*	- IAddressResolver
*	- IExchangeRates
*	- MixinResolver
*	- MixinSystemSettings
*	- Owned
* Libraries: 
*	- SafeDecimalMath
*	- SafeMath
*
* MIT License
* ===========
*
* Copyright (c) 2020 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() external {
        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_MESSAGE_GAS_LIMIT = "crossDomainMessageGasLimit";

    bytes32 internal constant CONTRACT_FLEXIBLESTORAGE = "FlexibleStorage";

    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 getCrossDomainMessageGasLimit() internal view returns (uint) {
        return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_CROSS_DOMAIN_MESSAGE_GAS_LIMIT);
    }

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


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


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


interface AggregatorInterface {
  function latestAnswer() external view returns (int256);
  function latestTimestamp() external view returns (uint256);
  function latestRound() external view returns (uint256);
  function getAnswer(uint256 roundId) external view returns (int256);
  function getTimestamp(uint256 roundId) external view returns (uint256);

  event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 timestamp);
  event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt);
}


interface AggregatorV3Interface {

  function decimals() external view returns (uint8);
  function description() external view returns (string memory);
  function version() external view returns (uint256);

  // getRoundData and latestRoundData should both raise "No data present"
  // if they do not have data to report, instead of returning unset values
  // which could be misinterpreted as actual reported values.
  function getRoundData(uint80 _roundId)
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );
  function latestRoundData()
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

}


/**
 * @title The V2 & V3 Aggregator Interface
 * @notice Solidity V0.5 does not allow interfaces to inherit from other
 * interfaces so this contract is a combination of v0.5 AggregatorInterface.sol
 * and v0.5 AggregatorV3Interface.sol.
 */
interface AggregatorV2V3Interface {
  //
  // V2 Interface:
  //
  function latestAnswer() external view returns (int256);
  function latestTimestamp() external view returns (uint256);
  function latestRound() external view returns (uint256);
  function getAnswer(uint256 roundId) external view returns (int256);
  function getTimestamp(uint256 roundId) external view returns (uint256);

  event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 timestamp);
  event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt);

  //
  // V3 Interface:
  //
  function decimals() external view returns (uint8);
  function description() external view returns (string memory);
  function version() external view returns (uint256);

  // getRoundData and latestRoundData should both raise "No data present"
  // if they do not have data to report, instead of returning unset values
  // which could be misinterpreted as actual reported values.
  function getRoundData(uint80 _roundId)
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );
  function latestRoundData()
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

}


interface FlagsInterface {
  function getFlag(address) external view returns (bool);
  function getFlags(address[] calldata) external view returns (bool[] memory);
  function raiseFlag(address) external;
  function raiseFlags(address[] calldata) external;
  function lowerFlags(address[] calldata) external;
  function setRaisingAccessController(address) 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;
}


// Inheritance


// Libraries


// Internal references
// AggregatorInterface from Chainlink represents a decentralized pricing network for a single currency key

// FlagsInterface from Chainlink addresses SIP-76


// https://docs.synthetix.io/contracts/source/contracts/exchangerates
contract ExchangeRates is Owned, MixinSystemSettings, IExchangeRates {
    using SafeMath for uint;
    using SafeDecimalMath for uint;

    // Exchange rates and update times stored by currency code, e.g. 'SNX', or 'sUSD'
    mapping(bytes32 => mapping(uint => RateAndUpdatedTime)) private _rates;

    // The address of the oracle which pushes rate updates to this contract
    address public oracle;

    // Decentralized oracle networks that feed into pricing aggregators
    mapping(bytes32 => AggregatorV2V3Interface) public aggregators;

    mapping(bytes32 => uint8) public currencyKeyDecimals;

    // List of aggregator keys for convenient iteration
    bytes32[] public aggregatorKeys;

    // Do not allow the oracle to submit times any further forward into the future than this constant.
    uint private constant ORACLE_FUTURE_LIMIT = 10 minutes;

    mapping(bytes32 => InversePricing) public inversePricing;

    bytes32[] public invertedKeys;

    mapping(bytes32 => uint) public currentRoundForRate;

    mapping(bytes32 => uint) public roundFrozen;

    /* ========== ADDRESS RESOLVER CONFIGURATION ========== */
    bytes32 private constant CONTRACT_EXCHANGER = "Exchanger";

    //
    // ========== CONSTRUCTOR ==========

    constructor(
        address _owner,
        address _oracle,
        address _resolver,
        bytes32[] memory _currencyKeys,
        uint[] memory _newRates
    ) public Owned(_owner) MixinSystemSettings(_resolver) {
        require(_currencyKeys.length == _newRates.length, "Currency key length and rate length must match.");

        oracle = _oracle;

        // The sUSD rate is always 1 and is never stale.
        _setRate("sUSD", SafeDecimalMath.unit(), now);

        internalUpdateRates(_currencyKeys, _newRates, now);
    }

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

    function setOracle(address _oracle) external onlyOwner {
        oracle = _oracle;
        emit OracleUpdated(oracle);
    }

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

    function updateRates(
        bytes32[] calldata currencyKeys,
        uint[] calldata newRates,
        uint timeSent
    ) external onlyOracle returns (bool) {
        return internalUpdateRates(currencyKeys, newRates, timeSent);
    }

    function deleteRate(bytes32 currencyKey) external onlyOracle {
        require(_getRate(currencyKey) > 0, "Rate is zero");

        delete _rates[currencyKey][currentRoundForRate[currencyKey]];

        currentRoundForRate[currencyKey]--;

        emit RateDeleted(currencyKey);
    }

    function setInversePricing(
        bytes32 currencyKey,
        uint entryPoint,
        uint upperLimit,
        uint lowerLimit,
        bool freezeAtUpperLimit,
        bool freezeAtLowerLimit
    ) external onlyOwner {
        // 0 < lowerLimit < entryPoint => 0 < entryPoint
        require(lowerLimit > 0, "lowerLimit must be above 0");
        require(upperLimit > entryPoint, "upperLimit must be above the entryPoint");
        require(upperLimit < entryPoint.mul(2), "upperLimit must be less than double entryPoint");
        require(lowerLimit < entryPoint, "lowerLimit must be below the entryPoint");

        require(!(freezeAtUpperLimit && freezeAtLowerLimit), "Cannot freeze at both limits");

        InversePricing storage inverse = inversePricing[currencyKey];
        if (inverse.entryPoint == 0) {
            // then we are adding a new inverse pricing, so add this
            invertedKeys.push(currencyKey);
        }
        inverse.entryPoint = entryPoint;
        inverse.upperLimit = upperLimit;
        inverse.lowerLimit = lowerLimit;

        if (freezeAtUpperLimit || freezeAtLowerLimit) {
            // When indicating to freeze, we need to know the rate to freeze it at - either upper or lower
            // this is useful in situations where ExchangeRates is updated and there are existing inverted
            // rates already frozen in the current contract that need persisting across the upgrade

            inverse.frozenAtUpperLimit = freezeAtUpperLimit;
            inverse.frozenAtLowerLimit = freezeAtLowerLimit;
            uint roundId = _getCurrentRoundId(currencyKey);
            roundFrozen[currencyKey] = roundId;
            emit InversePriceFrozen(currencyKey, freezeAtUpperLimit ? upperLimit : lowerLimit, roundId, msg.sender);
        } else {
            // unfreeze if need be
            inverse.frozenAtUpperLimit = false;
            inverse.frozenAtLowerLimit = false;
            // remove any tracking
            roundFrozen[currencyKey] = 0;
        }

        // SIP-78
        uint rate = _getRate(currencyKey);
        if (rate > 0) {
            exchanger().setLastExchangeRateForSynth(currencyKey, rate);
        }

        emit InversePriceConfigured(currencyKey, entryPoint, upperLimit, lowerLimit);
    }

    function removeInversePricing(bytes32 currencyKey) external onlyOwner {
        require(inversePricing[currencyKey].entryPoint > 0, "No inverted price exists");

        delete inversePricing[currencyKey];

        // now remove inverted key from array
        bool wasRemoved = removeFromArray(currencyKey, invertedKeys);

        if (wasRemoved) {
            emit InversePriceConfigured(currencyKey, 0, 0, 0);
        }
    }

    function addAggregator(bytes32 currencyKey, address aggregatorAddress) external onlyOwner {
        AggregatorV2V3Interface aggregator = AggregatorV2V3Interface(aggregatorAddress);
        // This check tries to make sure that a valid aggregator is being added.
        // It checks if the aggregator is an existing smart contract that has implemented `latestTimestamp` function.

        require(aggregator.latestRound() >= 0, "Given Aggregator is invalid");
        uint8 decimals = aggregator.decimals();
        require(decimals <= 18, "Aggregator decimals should be lower or equal to 18");
        if (address(aggregators[currencyKey]) == address(0)) {
            aggregatorKeys.push(currencyKey);
        }
        aggregators[currencyKey] = aggregator;
        currencyKeyDecimals[currencyKey] = decimals;
        emit AggregatorAdded(currencyKey, address(aggregator));
    }

    function removeAggregator(bytes32 currencyKey) external onlyOwner {
        address aggregator = address(aggregators[currencyKey]);
        require(aggregator != address(0), "No aggregator exists for key");
        delete aggregators[currencyKey];
        delete currencyKeyDecimals[currencyKey];

        bool wasRemoved = removeFromArray(currencyKey, aggregatorKeys);

        if (wasRemoved) {
            emit AggregatorRemoved(currencyKey, aggregator);
        }
    }

    // SIP-75 Public keeper function to freeze a synth that is out of bounds
    function freezeRate(bytes32 currencyKey) external {
        InversePricing storage inverse = inversePricing[currencyKey];
        require(inverse.entryPoint > 0, "Cannot freeze non-inverse rate");
        require(!inverse.frozenAtUpperLimit && !inverse.frozenAtLowerLimit, "The rate is already frozen");

        uint rate = _getRate(currencyKey);

        if (rate > 0 && (rate >= inverse.upperLimit || rate <= inverse.lowerLimit)) {
            inverse.frozenAtUpperLimit = (rate == inverse.upperLimit);
            inverse.frozenAtLowerLimit = (rate == inverse.lowerLimit);
            uint currentRoundId = _getCurrentRoundId(currencyKey);
            roundFrozen[currencyKey] = currentRoundId;
            emit InversePriceFrozen(currencyKey, rate, currentRoundId, msg.sender);
        } else {
            revert("Rate within bounds");
        }
    }

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

    function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
        bytes32[] memory existingAddresses = MixinSystemSettings.resolverAddressesRequired();
        bytes32[] memory newAddresses = new bytes32[](1);
        newAddresses[0] = CONTRACT_EXCHANGER;
        addresses = combineArrays(existingAddresses, newAddresses);
    }

    // SIP-75 View to determine if freezeRate can be called safely
    function canFreezeRate(bytes32 currencyKey) external view returns (bool) {
        InversePricing memory inverse = inversePricing[currencyKey];
        if (inverse.entryPoint == 0 || inverse.frozenAtUpperLimit || inverse.frozenAtLowerLimit) {
            return false;
        } else {
            uint rate = _getRate(currencyKey);
            return (rate > 0 && (rate >= inverse.upperLimit || rate <= inverse.lowerLimit));
        }
    }

    function currenciesUsingAggregator(address aggregator) external view returns (bytes32[] memory currencies) {
        uint count = 0;
        currencies = new bytes32[](aggregatorKeys.length);
        for (uint i = 0; i < aggregatorKeys.length; i++) {
            bytes32 currencyKey = aggregatorKeys[i];
            if (address(aggregators[currencyKey]) == aggregator) {
                currencies[count++] = currencyKey;
            }
        }
    }

    function rateStalePeriod() external view returns (uint) {
        return getRateStalePeriod();
    }

    function aggregatorWarningFlags() external view returns (address) {
        return getAggregatorWarningFlags();
    }

    function rateAndUpdatedTime(bytes32 currencyKey) external view returns (uint rate, uint time) {
        RateAndUpdatedTime memory rateAndTime = _getRateAndUpdatedTime(currencyKey);
        return (rateAndTime.rate, rateAndTime.time);
    }

    function getLastRoundIdBeforeElapsedSecs(
        bytes32 currencyKey,
        uint startingRoundId,
        uint startingTimestamp,
        uint timediff
    ) external view returns (uint) {
        uint roundId = startingRoundId;
        uint nextTimestamp = 0;
        while (true) {
            (, nextTimestamp) = _getRateAndTimestampAtRound(currencyKey, roundId + 1);
            // if there's no new round, then the previous roundId was the latest
            if (nextTimestamp == 0 || nextTimestamp > startingTimestamp + timediff) {
                return roundId;
            }
            roundId++;
        }
        return roundId;
    }

    function getCurrentRoundId(bytes32 currencyKey) external view returns (uint) {
        return _getCurrentRoundId(currencyKey);
    }

    function effectiveValueAtRound(
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey,
        uint roundIdForSrc,
        uint roundIdForDest
    ) external view returns (uint value) {
        // If there's no change in the currency, then just return the amount they gave us
        if (sourceCurrencyKey == destinationCurrencyKey) return sourceAmount;

        (uint srcRate, ) = _getRateAndTimestampAtRound(sourceCurrencyKey, roundIdForSrc);
        (uint destRate, ) = _getRateAndTimestampAtRound(destinationCurrencyKey, roundIdForDest);
        if (destRate == 0) {
            // prevent divide-by 0 error (this can happen when roundIDs jump epochs due
            // to aggregator upgrades)
            return 0;
        }
        // Calculate the effective value by going from source -> USD -> destination
        value = sourceAmount.multiplyDecimalRound(srcRate).divideDecimalRound(destRate);
    }

    function rateAndTimestampAtRound(bytes32 currencyKey, uint roundId) external view returns (uint rate, uint time) {
        return _getRateAndTimestampAtRound(currencyKey, roundId);
    }

    function lastRateUpdateTimes(bytes32 currencyKey) external view returns (uint256) {
        return _getUpdatedTime(currencyKey);
    }

    function lastRateUpdateTimesForCurrencies(bytes32[] calldata currencyKeys) external view returns (uint[] memory) {
        uint[] memory lastUpdateTimes = new uint[](currencyKeys.length);

        for (uint i = 0; i < currencyKeys.length; i++) {
            lastUpdateTimes[i] = _getUpdatedTime(currencyKeys[i]);
        }

        return lastUpdateTimes;
    }

    function effectiveValue(
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey
    ) external view returns (uint value) {
        (value, , ) = _effectiveValueAndRates(sourceCurrencyKey, sourceAmount, destinationCurrencyKey);
    }

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

    function rateForCurrency(bytes32 currencyKey) external view returns (uint) {
        return _getRateAndUpdatedTime(currencyKey).rate;
    }

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

        uint roundId = _getCurrentRoundId(currencyKey);
        for (uint i = 0; i < numRounds; i++) {
            // fetch the rate and treat is as current, so inverse limits if frozen will always be applied
            // regardless of current rate
            (rates[i], times[i]) = _getRateAndTimestampAtRound(currencyKey, roundId);

            if (roundId == 0) {
                // if we hit the last round, then return what we have
                return (rates, times);
            } else {
                roundId--;
            }
        }
    }

    function ratesForCurrencies(bytes32[] calldata currencyKeys) external view returns (uint[] memory) {
        uint[] memory _localRates = new uint[](currencyKeys.length);

        for (uint i = 0; i < currencyKeys.length; i++) {
            _localRates[i] = _getRate(currencyKeys[i]);
        }

        return _localRates;
    }

    function rateAndInvalid(bytes32 currencyKey) external view returns (uint rate, bool isInvalid) {
        RateAndUpdatedTime memory rateAndTime = _getRateAndUpdatedTime(currencyKey);

        if (currencyKey == "sUSD") {
            return (rateAndTime.rate, false);
        }
        return (
            rateAndTime.rate,
            _rateIsStaleWithTime(getRateStalePeriod(), rateAndTime.time) ||
                _rateIsFlagged(currencyKey, FlagsInterface(getAggregatorWarningFlags()))
        );
    }

    function ratesAndInvalidForCurrencies(bytes32[] calldata currencyKeys)
        external
        view
        returns (uint[] memory rates, bool anyRateInvalid)
    {
        rates = new uint[](currencyKeys.length);

        uint256 _rateStalePeriod = getRateStalePeriod();

        // fetch all flags at once
        bool[] memory flagList = getFlagsForRates(currencyKeys);

        for (uint i = 0; i < currencyKeys.length; i++) {
            // do one lookup of the rate & time to minimize gas
            RateAndUpdatedTime memory rateEntry = _getRateAndUpdatedTime(currencyKeys[i]);
            rates[i] = rateEntry.rate;
            if (!anyRateInvalid && currencyKeys[i] != "sUSD") {
                anyRateInvalid = flagList[i] || _rateIsStaleWithTime(_rateStalePeriod, rateEntry.time);
            }
        }
    }

    function rateIsStale(bytes32 currencyKey) external view returns (bool) {
        return _rateIsStale(currencyKey, getRateStalePeriod());
    }

    function rateIsFrozen(bytes32 currencyKey) external view returns (bool) {
        return _rateIsFrozen(currencyKey);
    }

    function rateIsInvalid(bytes32 currencyKey) external view returns (bool) {
        return
            _rateIsStale(currencyKey, getRateStalePeriod()) ||
            _rateIsFlagged(currencyKey, FlagsInterface(getAggregatorWarningFlags()));
    }

    function rateIsFlagged(bytes32 currencyKey) external view returns (bool) {
        return _rateIsFlagged(currencyKey, FlagsInterface(getAggregatorWarningFlags()));
    }

    function anyRateIsInvalid(bytes32[] calldata currencyKeys) external view returns (bool) {
        // Loop through each key and check whether the data point is stale.

        uint256 _rateStalePeriod = getRateStalePeriod();
        bool[] memory flagList = getFlagsForRates(currencyKeys);

        for (uint i = 0; i < currencyKeys.length; i++) {
            if (flagList[i] || _rateIsStale(currencyKeys[i], _rateStalePeriod)) {
                return true;
            }
        }

        return false;
    }

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

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

    function getFlagsForRates(bytes32[] memory currencyKeys) internal view returns (bool[] memory flagList) {
        FlagsInterface _flags = FlagsInterface(getAggregatorWarningFlags());

        // fetch all flags at once
        if (_flags != FlagsInterface(0)) {
            address[] memory _aggregators = new address[](currencyKeys.length);

            for (uint i = 0; i < currencyKeys.length; i++) {
                _aggregators[i] = address(aggregators[currencyKeys[i]]);
            }

            flagList = _flags.getFlags(_aggregators);
        } else {
            flagList = new bool[](currencyKeys.length);
        }
    }

    function _setRate(
        bytes32 currencyKey,
        uint256 rate,
        uint256 time
    ) internal {
        // Note: this will effectively start the rounds at 1, which matches Chainlink's Agggregators
        currentRoundForRate[currencyKey]++;

        _rates[currencyKey][currentRoundForRate[currencyKey]] = RateAndUpdatedTime({
            rate: uint216(rate),
            time: uint40(time)
        });
    }

    function internalUpdateRates(
        bytes32[] memory currencyKeys,
        uint[] memory newRates,
        uint timeSent
    ) internal returns (bool) {
        require(currencyKeys.length == newRates.length, "Currency key array length must match rates array length.");
        require(timeSent < (now + ORACLE_FUTURE_LIMIT), "Time is too far into the future");

        // Loop through each key and perform update.
        for (uint i = 0; i < currencyKeys.length; i++) {
            bytes32 currencyKey = currencyKeys[i];

            // Should not set any rate to zero ever, as no asset will ever be
            // truely worthless and still valid. In this scenario, we should
            // delete the rate and remove it from the system.
            require(newRates[i] != 0, "Zero is not a valid rate, please call deleteRate instead.");
            require(currencyKey != "sUSD", "Rate of sUSD cannot be updated, it's always UNIT.");

            // We should only update the rate if it's at least the same age as the last rate we've got.
            if (timeSent < _getUpdatedTime(currencyKey)) {
                continue;
            }

            // Ok, go ahead with the update.
            _setRate(currencyKey, newRates[i], timeSent);
        }

        emit RatesUpdated(currencyKeys, newRates);

        return true;
    }

    function removeFromArray(bytes32 entry, bytes32[] storage array) internal returns (bool) {
        for (uint i = 0; i < array.length; i++) {
            if (array[i] == entry) {
                delete array[i];

                // Copy the last key into the place of the one we just deleted
                // If there's only one key, this is array[0] = array[0].
                // If we're deleting the last one, it's also a NOOP in the same way.
                array[i] = array[array.length - 1];

                // Decrease the size of the array by one.
                array.length--;

                return true;
            }
        }
        return false;
    }

    function _rateOrInverted(
        bytes32 currencyKey,
        uint rate,
        uint roundId
    ) internal view returns (uint newRate) {
        // if an inverse mapping exists, adjust the price accordingly
        InversePricing memory inverse = inversePricing[currencyKey];
        if (inverse.entryPoint == 0 || rate == 0) {
            // when no inverse is set or when given a 0 rate, return the rate, regardless of the inverse status
            // (the latter is so when a new inverse is set but the underlying has no rate, it will return 0 as
            // the rate, not the lowerLimit)
            return rate;
        }

        newRate = rate;

        // Determine when round was frozen (if any)
        uint roundWhenRateFrozen = roundFrozen[currencyKey];
        // And if we're looking at a rate after frozen, and it's currently frozen, then apply the bounds limit even
        // if the current price is back within bounds
        if (roundId >= roundWhenRateFrozen && inverse.frozenAtUpperLimit) {
            newRate = inverse.upperLimit;
        } else if (roundId >= roundWhenRateFrozen && inverse.frozenAtLowerLimit) {
            newRate = inverse.lowerLimit;
        } else {
            // this ensures any rate outside the limit will never be returned
            uint doubleEntryPoint = inverse.entryPoint.mul(2);
            if (doubleEntryPoint <= rate) {
                // avoid negative numbers for unsigned ints, so set this to 0
                // which by the requirement that lowerLimit be > 0 will
                // cause this to freeze the price to the lowerLimit
                newRate = 0;
            } else {
                newRate = doubleEntryPoint.sub(rate);
            }

            // now ensure the rate is between the bounds
            if (newRate >= inverse.upperLimit) {
                newRate = inverse.upperLimit;
            } else if (newRate <= inverse.lowerLimit) {
                newRate = inverse.lowerLimit;
            }
        }
    }

    function _formatAggregatorAnswer(bytes32 currencyKey, int256 rate) internal view returns (uint) {
        require(rate >= 0, "Negative rate not supported");
        if (currencyKeyDecimals[currencyKey] > 0) {
            uint multiplier = 10**uint(SafeMath.sub(18, currencyKeyDecimals[currencyKey]));
            return uint(uint(rate).mul(multiplier));
        }
        return uint(rate);
    }

    function _getRateAndUpdatedTime(bytes32 currencyKey) internal view returns (RateAndUpdatedTime memory) {
        AggregatorV2V3Interface aggregator = aggregators[currencyKey];

        if (aggregator != AggregatorV2V3Interface(0)) {
            // this view from the aggregator is the most gas efficient but it can throw when there's no data,
            // so let's call it low-level to suppress any reverts
            bytes memory payload = abi.encodeWithSignature("latestRoundData()");
            // solhint-disable avoid-low-level-calls
            (bool success, bytes memory returnData) = address(aggregator).staticcall(payload);

            if (success) {
                (uint80 roundId, int256 answer, , uint256 updatedAt, ) = abi.decode(
                    returnData,
                    (uint80, int256, uint256, uint256, uint80)
                );
                return
                    RateAndUpdatedTime({
                        rate: uint216(_rateOrInverted(currencyKey, _formatAggregatorAnswer(currencyKey, answer), roundId)),
                        time: uint40(updatedAt)
                    });
            }
        } else {
            uint roundId = currentRoundForRate[currencyKey];
            RateAndUpdatedTime memory entry = _rates[currencyKey][roundId];

            return RateAndUpdatedTime({rate: uint216(_rateOrInverted(currencyKey, entry.rate, roundId)), time: entry.time});
        }
    }

    function _getCurrentRoundId(bytes32 currencyKey) internal view returns (uint) {
        AggregatorV2V3Interface aggregator = aggregators[currencyKey];

        if (aggregator != AggregatorV2V3Interface(0)) {
            return aggregator.latestRound();
        } else {
            return currentRoundForRate[currencyKey];
        }
    }

    function _getRateAndTimestampAtRound(bytes32 currencyKey, uint roundId) internal view returns (uint rate, uint time) {
        AggregatorV2V3Interface aggregator = aggregators[currencyKey];

        if (aggregator != AggregatorV2V3Interface(0)) {
            // this view from the aggregator is the most gas efficient but it can throw when there's no data,
            // so let's call it low-level to suppress any reverts
            bytes memory payload = abi.encodeWithSignature("getRoundData(uint80)", roundId);
            // solhint-disable avoid-low-level-calls
            (bool success, bytes memory returnData) = address(aggregator).staticcall(payload);

            if (success) {
                (, int256 answer, , uint256 updatedAt, ) = abi.decode(
                    returnData,
                    (uint80, int256, uint256, uint256, uint80)
                );
                return (_rateOrInverted(currencyKey, _formatAggregatorAnswer(currencyKey, answer), roundId), updatedAt);
            }
        } else {
            RateAndUpdatedTime memory update = _rates[currencyKey][roundId];
            return (_rateOrInverted(currencyKey, update.rate, roundId), update.time);
        }
    }

    function _getRate(bytes32 currencyKey) internal view returns (uint256) {
        return _getRateAndUpdatedTime(currencyKey).rate;
    }

    function _getUpdatedTime(bytes32 currencyKey) internal view returns (uint256) {
        return _getRateAndUpdatedTime(currencyKey).time;
    }

    function _effectiveValueAndRates(
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey
    )
        internal
        view
        returns (
            uint value,
            uint sourceRate,
            uint destinationRate
        )
    {
        sourceRate = _getRate(sourceCurrencyKey);
        // If there's no change in the currency, then just return the amount they gave us
        if (sourceCurrencyKey == destinationCurrencyKey) {
            destinationRate = sourceRate;
            value = sourceAmount;
        } else {
            // Calculate the effective value by going from source -> USD -> destination
            destinationRate = _getRate(destinationCurrencyKey);
            // prevent divide-by 0 error (this happens if the dest is not a valid rate)
            if (destinationRate > 0) {
                value = sourceAmount.multiplyDecimalRound(sourceRate).divideDecimalRound(destinationRate);
            }
        }
    }

    function _rateIsStale(bytes32 currencyKey, uint _rateStalePeriod) internal view returns (bool) {
        // sUSD is a special case and is never stale (check before an SLOAD of getRateAndUpdatedTime)
        if (currencyKey == "sUSD") return false;

        return _rateIsStaleWithTime(_rateStalePeriod, _getUpdatedTime(currencyKey));
    }

    function _rateIsStaleWithTime(uint _rateStalePeriod, uint _time) internal view returns (bool) {
        return _time.add(_rateStalePeriod) < now;
    }

    function _rateIsFrozen(bytes32 currencyKey) internal view returns (bool) {
        InversePricing memory inverse = inversePricing[currencyKey];
        return inverse.frozenAtUpperLimit || inverse.frozenAtLowerLimit;
    }

    function _rateIsFlagged(bytes32 currencyKey, FlagsInterface flags) internal view returns (bool) {
        // sUSD is a special case and is never invalid
        if (currencyKey == "sUSD") return false;
        address aggregator = address(aggregators[currencyKey]);
        // when no aggregator or when the flags haven't been setup
        if (aggregator == address(0) || flags == FlagsInterface(0)) {
            return false;
        }
        return flags.getFlag(aggregator);
    }

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

    modifier onlyOracle {
        _onlyOracle();
        _;
    }

    function _onlyOracle() internal {
        require(msg.sender == oracle, "Only the oracle can perform this action");
    }

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

    event OracleUpdated(address newOracle);
    event RatesUpdated(bytes32[] currencyKeys, uint[] newRates);
    event RateDeleted(bytes32 currencyKey);
    event InversePriceConfigured(bytes32 currencyKey, uint entryPoint, uint upperLimit, uint lowerLimit);
    event InversePriceFrozen(bytes32 currencyKey, uint rate, uint roundId, address initiator);
    event AggregatorAdded(bytes32 currencyKey, address aggregator);
    event AggregatorRemoved(bytes32 currencyKey, address aggregator);
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_oracle","type":"address"},{"internalType":"address","name":"_resolver","type":"address"},{"internalType":"bytes32[]","name":"_currencyKeys","type":"bytes32[]"},{"internalType":"uint256[]","name":"_newRates","type":"uint256[]"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"currencyKey","type":"bytes32"},{"indexed":false,"internalType":"address","name":"aggregator","type":"address"}],"name":"AggregatorAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"currencyKey","type":"bytes32"},{"indexed":false,"internalType":"address","name":"aggregator","type":"address"}],"name":"AggregatorRemoved","type":"event"},{"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":"bytes32","name":"currencyKey","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"entryPoint","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"upperLimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lowerLimit","type":"uint256"}],"name":"InversePriceConfigured","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"currencyKey","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"rate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"address","name":"initiator","type":"address"}],"name":"InversePriceFrozen","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOracle","type":"address"}],"name":"OracleUpdated","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"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"RateDeleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32[]","name":"currencyKeys","type":"bytes32[]"},{"indexed":false,"internalType":"uint256[]","name":"newRates","type":"uint256[]"}],"name":"RatesUpdated","type":"event"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"},{"internalType":"address","name":"aggregatorAddress","type":"address"}],"name":"addAggregator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"aggregatorKeys","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"aggregatorWarningFlags","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"aggregators","outputs":[{"internalType":"contract AggregatorV2V3Interface","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32[]","name":"currencyKeys","type":"bytes32[]"}],"name":"anyRateIsInvalid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"canFreezeRate","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"aggregator","type":"address"}],"name":"currenciesUsingAggregator","outputs":[{"internalType":"bytes32[]","name":"currencies","type":"bytes32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"currencyKeyDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"currentRoundForRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"deleteRate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"sourceCurrencyKey","type":"bytes32"},{"internalType":"uint256","name":"sourceAmount","type":"uint256"},{"internalType":"bytes32","name":"destinationCurrencyKey","type":"bytes32"}],"name":"effectiveValue","outputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"sourceCurrencyKey","type":"bytes32"},{"internalType":"uint256","name":"sourceAmount","type":"uint256"},{"internalType":"bytes32","name":"destinationCurrencyKey","type":"bytes32"}],"name":"effectiveValueAndRates","outputs":[{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"sourceRate","type":"uint256"},{"internalType":"uint256","name":"destinationRate","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"sourceCurrencyKey","type":"bytes32"},{"internalType":"uint256","name":"sourceAmount","type":"uint256"},{"internalType":"bytes32","name":"destinationCurrencyKey","type":"bytes32"},{"internalType":"uint256","name":"roundIdForSrc","type":"uint256"},{"internalType":"uint256","name":"roundIdForDest","type":"uint256"}],"name":"effectiveValueAtRound","outputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"freezeRate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"getCurrentRoundId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"},{"internalType":"uint256","name":"startingRoundId","type":"uint256"},{"internalType":"uint256","name":"startingTimestamp","type":"uint256"},{"internalType":"uint256","name":"timediff","type":"uint256"}],"name":"getLastRoundIdBeforeElapsedSecs","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"inversePricing","outputs":[{"internalType":"uint256","name":"entryPoint","type":"uint256"},{"internalType":"uint256","name":"upperLimit","type":"uint256"},{"internalType":"uint256","name":"lowerLimit","type":"uint256"},{"internalType":"bool","name":"frozenAtUpperLimit","type":"bool"},{"internalType":"bool","name":"frozenAtLowerLimit","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"invertedKeys","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"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":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"lastRateUpdateTimes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32[]","name":"currencyKeys","type":"bytes32[]"}],"name":"lastRateUpdateTimesForCurrencies","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":true,"inputs":[],"name":"oracle","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"rateAndInvalid","outputs":[{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"bool","name":"isInvalid","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"},{"internalType":"uint256","name":"roundId","type":"uint256"}],"name":"rateAndTimestampAtRound","outputs":[{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"uint256","name":"time","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"rateAndUpdatedTime","outputs":[{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"uint256","name":"time","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"rateForCurrency","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"rateIsFlagged","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"rateIsFrozen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"rateIsInvalid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"rateIsStale","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"rateStalePeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32[]","name":"currencyKeys","type":"bytes32[]"}],"name":"ratesAndInvalidForCurrencies","outputs":[{"internalType":"uint256[]","name":"rates","type":"uint256[]"},{"internalType":"bool","name":"anyRateInvalid","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"},{"internalType":"uint256","name":"numRounds","type":"uint256"}],"name":"ratesAndUpdatedTimeForCurrencyLastNRounds","outputs":[{"internalType":"uint256[]","name":"rates","type":"uint256[]"},{"internalType":"uint256[]","name":"times","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32[]","name":"currencyKeys","type":"bytes32[]"}],"name":"ratesForCurrencies","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"rebuildCache","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"removeAggregator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"}],"name":"removeInversePricing","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":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"roundFrozen","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"currencyKey","type":"bytes32"},{"internalType":"uint256","name":"entryPoint","type":"uint256"},{"internalType":"uint256","name":"upperLimit","type":"uint256"},{"internalType":"uint256","name":"lowerLimit","type":"uint256"},{"internalType":"bool","name":"freezeAtUpperLimit","type":"bool"},{"internalType":"bool","name":"freezeAtLowerLimit","type":"bool"}],"name":"setInversePricing","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_oracle","type":"address"}],"name":"setOracle","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32[]","name":"currencyKeys","type":"bytes32[]"},{"internalType":"uint256[]","name":"newRates","type":"uint256[]"},{"internalType":"uint256","name":"timeSent","type":"uint256"}],"name":"updateRates","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]

60806040523480156200001157600080fd5b5060405162004ffd38038062004ffd833981810160405260a08110156200003757600080fd5b8151602083015160408085015160608601805192519496939591949391820192846401000000008211156200006b57600080fd5b9083019060208201858111156200008157600080fd5b82518660208202830111640100000000821117156200009f57600080fd5b82525081516020918201928201910280838360005b83811015620000ce578181015183820152602001620000b4565b5050505090500160405260200180516040519392919084640100000000821115620000f857600080fd5b9083019060208201858111156200010e57600080fd5b82518660208202830111640100000000821117156200012c57600080fd5b82525081516020918201928201910280838360005b838110156200015b57818101518382015260200162000141565b5050505090500160405250505082808660006001600160a01b0316816001600160a01b03161415620001d4576040805162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f74206265203000000000000000604482015290519081900360640190fd5b600080546001600160a01b0319166001600160a01b038316908117825560408051928352602083019190915280517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9281900390910190a150600280546001600160a01b0319166001600160a01b0392909216919091179055508051825114620002905760405162461bcd60e51b815260040180806020018281038252602f81526020018062004f0b602f913960400191505060405180910390fd5b83600560006101000a8154816001600160a01b0302191690836001600160a01b0316021790555062000346631cd554d160e21b731a60e2e2a8be0bc2b6381dd31fd3fd5f9a28de4c63907af6c06040518163ffffffff1660e01b815260040160206040518083038186803b1580156200030857600080fd5b505af41580156200031d573d6000803e3d6000fd5b505050506040513d60208110156200033457600080fd5b5051426001600160e01b036200036816565b6200035c8282426001600160e01b03620003e116565b50505050505062000c13565b6000838152600b60209081526040808320805460010190819055815180830183526001600160d81b03968716815264ffffffffff958616818501908152978552600484528285209185529252909120905181549451909216600160d81b029183166001600160d81b031990941693909317909116179055565b60008251845114620004255760405162461bcd60e51b815260040180806020018281038252603881526020018062004f8c6038913960400191505060405180910390fd5b610258420182106200047e576040805162461bcd60e51b815260206004820152601f60248201527f54696d6520697320746f6f2066617220696e746f207468652066757475726500604482015290519081900360640190fd5b60005b8451811015620005975760008582815181106200049a57fe5b60200260200101519050848281518110620004b157fe5b602002602001015160001415620004fa5760405162461bcd60e51b815260040180806020018281038252603981526020018062004fc46039913960400191505060405180910390fd5b80631cd554d160e21b1415620005425760405162461bcd60e51b815260040180806020018281038252603181526020018062004f3a6031913960400191505060405180910390fd5b62000556816001600160e01b036200066216565b8410156200056557506200058e565b6200058c818684815181106200057757fe5b6020026020010151866200036860201b60201c565b505b60010162000481565b507f1bc0fc8997efa076f59b5ef02c315bc5390f7a6d24d661ce12128c01a3b0ba578484604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b8381101562000601578181015183820152602001620005e7565b50505050905001838103825284818151815260200191508051906020019060200280838360005b838110156200064257818101518382015260200162000628565b5050505090500194505050505060405180910390a15060015b9392505050565b600062000678826001600160e01b036200068b16565b6020015164ffffffffff1690505b919050565b6200069562000bc9565b6000828152600660205260409020546001600160a01b03168015620008315760408051600481526024810182526020810180516001600160e01b0316633fabe5a360e21b1781529151815191926000926060926001600160a01b0387169286928291908083835b602083106200071d5780518252601f199092019160209182019101620006fc565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d80600081146200077f576040519150601f19603f3d011682016040523d82523d6000602084013e62000784565b606091505b50915091508115620008285760008060008380602001905160a0811015620007ab57600080fd5b50805160208201516060909201516040805180820190915291955091935090915080620008008b620007e781876001600160e01b03620008dd16565b6001600160501b0388166001600160e01b03620009aa16565b6001600160d81b031681526020018264ffffffffff1681525097505050505050505062000686565b505050620008d7565b6000838152600b60205260409020546200084a62000bc9565b5060008481526004602090815260408083208484528252918290208251808401845290546001600160d81b038082168352600160d81b90910464ffffffffff1692820192909252825180840190935280519092918291620008af9189911686620009aa565b6001600160d81b03168152602001826020015164ffffffffff16815250935050505062000686565b50919050565b60008082121562000935576040805162461bcd60e51b815260206004820152601b60248201527f4e656761746976652072617465206e6f7420737570706f727465640000000000604482015290519081900360640190fd5b60008381526007602052604090205460ff1615620009a1576000838152600760209081526040822054620009799160129160ff169062003f6962000b0d821b17901c565b600a0a905062000998818462000b6b60201b620037e31790919060201c565b915050620009a4565b50805b92915050565b6000620009b662000be0565b50600084815260096020908152604091829020825160a08101845281548082526001830154938201939093526002820154938101939093526003015460ff808216151560608501526101009091041615156080830152158062000a17575083155b1562000a2757839150506200065b565b6000858152600c602052604090205484925080841080159062000a4b575081606001515b1562000a5e578160200151925062000b04565b80841015801562000a70575081608001515b1562000a83578160400151925062000b04565b600062000aa46002846000015162000b6b60201b620037e31790919060201c565b905085811162000ab8576000935062000ad5565b62000ad2868262000b0d60201b62003f691790919060201c565b93505b8260200151841062000aee578260200151935062000b02565b8260400151841162000b0257826040015193505b505b50509392505050565b60008282111562000b65576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008262000b7c57506000620009a4565b8282028284828162000b8a57fe5b04146200065b5760405162461bcd60e51b815260040180806020018281038252602181526020018062004f6b6021913960400191505060405180910390fd5b604080518082019091526000808252602082015290565b6040518060a001604052806000815260200160008152602001600081526020016000151581526020016000151581525090565b6142e88062000c236000396000f3fe608060405234801561001057600080fd5b50600436106103145760003560e01c8063654a60ac116101a7578063935f4abd116100ee578063c2c8a67611610097578063ce8480ea11610071578063ce8480ea14610c2a578063de02795e14610c47578063fdadbc7e14610c6457610314565b8063c2c8a67614610ace578063c8e5bbd514610b3e578063c8e6f39514610c0d57610314565b8063b199c764116100c8578063b199c7641461099a578063b295ad34146109d9578063bfa005ce14610a0c57610314565b8063935f4abd14610943578063ac82f60814610960578063af3aea861461097d57610314565b80637adbf973116101505780638295016a1161012a5780638295016a146108ec578063899ffef4146109335780638da5cb5b1461093b57610314565b80637adbf973146108945780637dc0d1d0146108c75780637f6e9d15146108cf57610314565b80637418536011610181578063741853601461086757806379ba50971461086f5780637a018a1e1461087757610314565b8063654a60ac146107d55780637103353e146107fe578063728dec291461081b57610314565b80632af64bd31161026b5780633f0e084f116102145780634c36b837116101ee5780634c36b837146107a85780634f72def6146107b057806353a47bb7146107cd57610314565b80633f0e084f1461071c5780634308a94f14610755578063459388491461078b57610314565b80632ea913d4116102455780632ea913d4146106c55780633375fcd1146106e257806338aa1b99146106ff57610314565b80632af64bd3146105e45780632bed9e0c146105ec5780632d7371e11461060957610314565b80630ee4951b116102cd5780632528f0fe116102a75780632528f0fe1461055f578063266da16b1461057c5780632678df96146105b157610314565b80630ee4951b146104e1578063109e46a2146104fb5780631627540c1461052a57610314565b806305a046e5116102fe57806305a046e51461037b5780630a7d36d11461043b5780630c71cd23146104ab57610314565b80629919c01461031957806304f3bcec1461034a575b600080fd5b6103366004803603602081101561032f57600080fd5b5035610c87565b604080519115158252519081900360200190f35b610352610ca2565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6103eb6004803603602081101561039157600080fd5b8101906020810181356401000000008111156103ac57600080fd5b8201836020820111156103be57600080fd5b803590602001918460208302840111640100000000831117156103e057600080fd5b509092509050610cbe565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561042757818101518382015260200161040f565b505050509050019250505060405180910390f35b6103366004803603602081101561045157600080fd5b81019060208101813564010000000081111561046c57600080fd5b82018360208201111561047e57600080fd5b803590602001918460208302840111640100000000831117156104a057600080fd5b509092509050610d40565b6104c8600480360360208110156104c157600080fd5b5035610df3565b6040805192835290151560208301528051918290030190f35b6104e9610eb9565b60408051918252519081900360200190f35b6104e96004803603608081101561051157600080fd5b5080359060208101359060408101359060600135610ec9565b61055d6004803603602081101561054057600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610f0c565b005b6103366004803603602081101561057557600080fd5b5035610f8d565b6104e9600480360360a081101561059257600080fd5b5080359060208101359060408101359060608101359060800135610fad565b6103eb600480360360208110156105c757600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661101a565b6103366110db565b61055d6004803603602081101561060257600080fd5b5035611225565b61062c6004803603604081101561061f57600080fd5b5080359060200135611371565b604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b83811015610670578181015183820152602001610658565b50505050905001838103825284818151815260200191508051906020019060200280838360005b838110156106af578181015183820152602001610697565b5050505090500194505050505060405180910390f35b6104e9600480360360208110156106db57600080fd5b5035611462565b610336600480360360208110156106f857600080fd5b5035611480565b6103366004803603602081101561071557600080fd5b5035611546565b61055d6004803603604081101561073257600080fd5b508035906020013573ffffffffffffffffffffffffffffffffffffffff16611554565b6107726004803603602081101561076b57600080fd5b5035611804565b6040805192835260208301919091528051918290030190f35b61055d600480360360208110156107a157600080fd5b5035611850565b61035261193d565b6104e9600480360360208110156107c657600080fd5b5035611947565b610352611954565b6104e9600480360360608110156107eb57600080fd5b5080359060208101359060400135611970565b6103526004803603602081101561081457600080fd5b5035611988565b6108386004803603602081101561083157600080fd5b50356119b0565b604080519586526020860194909452848401929092521515606084015215156080830152519081900360a00190f35b61055d6119e3565b61055d611bf6565b6104e96004803603602081101561088d57600080fd5b5035611cf1565b61055d600480360360208110156108aa57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611cfc565b610352611d83565b6104e9600480360360208110156108e557600080fd5b5035611d9f565b6109156004803603606081101561090257600080fd5b5080359060208101359060400135611db1565b60408051938452602084019290925282820152519081900360600190f35b6103eb611dd1565b610352611e4d565b6104e96004803603602081101561095957600080fd5b5035611e69565b6104e96004803603602081101561097657600080fd5b5035611e7b565b6103366004803603602081101561099357600080fd5b5035611eaa565b61055d600480360360c08110156109b057600080fd5b50803590602081013590604081013590606081013590608081013515159060a001351515611eb5565b6109f6600480360360208110156109ef57600080fd5b503561228a565b6040805160ff9092168252519081900360200190f35b61033660048036036060811015610a2257600080fd5b810190602081018135640100000000811115610a3d57600080fd5b820183602082011115610a4f57600080fd5b80359060200191846020830284011164010000000083111715610a7157600080fd5b919390929091602081019035640100000000811115610a8f57600080fd5b820183602082011115610aa157600080fd5b80359060200191846020830284011164010000000083111715610ac357600080fd5b91935091503561229f565b6103eb60048036036020811015610ae457600080fd5b810190602081018135640100000000811115610aff57600080fd5b820183602082011115610b1157600080fd5b80359060200191846020830284011164010000000083111715610b3357600080fd5b509092509050612322565b610bae60048036036020811015610b5457600080fd5b810190602081018135640100000000811115610b6f57600080fd5b820183602082011115610b8157600080fd5b80359060200191846020830284011164010000000083111715610ba357600080fd5b50909250905061239a565b604051808060200183151515158152602001828103825284818151815260200191508051906020019060200280838360005b83811015610bf8578181015183820152602001610be0565b50505050905001935050505060405180910390f35b61055d60048036036020811015610c2357600080fd5b503561250e565b6104e960048036036020811015610c4057600080fd5b503561261c565b61055d60048036036020811015610c5d57600080fd5b5035612627565b61077260048036036040811015610c7a57600080fd5b508035906020013561284f565b6000610c9a82610c95612867565b61293a565b90505b919050565b60025473ffffffffffffffffffffffffffffffffffffffff1681565b60608083839050604051908082528060200260200182016040528015610cee578160200160208202803883390190505b50905060005b83811015610d3657610d17858583818110610d0b57fe5b90506020020135612985565b828281518110610d2357fe5b6020908102919091010152600101610cf4565b5090505b92915050565b600080610d4b612867565b90506060610d8b8585808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506129a192505050565b905060005b84811015610de757818181518110610da457fe5b602002602001015180610dce5750610dce868683818110610dc157fe5b905060200201358461293a565b15610ddf5760019350505050610d3a565b600101610d90565b50600095945050505050565b600080610dfe614030565b610e0784612c4f565b9050837f73555344000000000000000000000000000000000000000000000000000000001415610e5a57517affffffffffffffffffffffffffffffffffffffffffffffffffffff16915060009050610eb4565b8051610e78610e67612867565b836020015164ffffffffff16612f32565b80610e8f5750610e8f85610e8a612f4d565b612fef565b7affffffffffffffffffffffffffffffffffffffffffffffffffffff90911693509150505b915091565b6000610ec3612867565b90505b90565b600083815b610edb8783600101613127565b915050801580610eec575083850181115b15610ef957509050610f04565b600190910190610ece565b949350505050565b610f1461338f565b6001805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff0000000000000000000000000000000000000000909116811790915560408051918252517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce229181900360200190a150565b6000610f9b82610c95612867565b80610c9a5750610c9a82610e8a612f4d565b600083861415610fbe575083611011565b6000610fca8785613127565b5090506000610fd98685613127565b50905080610fec57600092505050611011565b61100c81611000898563ffffffff6133e716565b9063ffffffff6133fc16565b925050505b95945050505050565b60085460408051828152602080840282010190915260609160009190801561104c578160200160208202803883390190505b50915060005b6008548110156110d45760006008828154811061106b57fe5b6000918252602080832090910154808352600690915260409091205490915073ffffffffffffffffffffffffffffffffffffffff90811690861614156110cb57808484806001019550815181106110be57fe5b6020026020010181815250505b50600101611052565b5050919050565b600060606110e7611dd1565b905060005b815181101561121c57600082828151811061110357fe5b6020908102919091018101516000818152600383526040908190205460025482517f21f8a72100000000000000000000000000000000000000000000000000000000815260048101859052925193955073ffffffffffffffffffffffffffffffffffffffff918216949116926321f8a721926024808201939291829003018186803b15801561119157600080fd5b505afa1580156111a5573d6000803e3d6000fd5b505050506040513d60208110156111bb57600080fd5b505173ffffffffffffffffffffffffffffffffffffffff16141580611202575060008181526003602052604090205473ffffffffffffffffffffffffffffffffffffffff16155b156112135760009350505050610ec6565b506001016110ec565b50600191505090565b61122d61338f565b60008181526006602052604090205473ffffffffffffffffffffffffffffffffffffffff16806112a4576040805162461bcd60e51b815260206004820152601c60248201527f4e6f2061676772656761746f722065786973747320666f72206b657900000000604482015290519081900360640190fd5b600082815260066020908152604080832080547fffffffffffffffffffffffff00000000000000000000000000000000000000001690556007909152812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055611313836008613411565b9050801561136c576040805184815273ffffffffffffffffffffffffffffffffffffffff8416602082015281517fec70e890fc7db7de4059b114c9093a1f41283d18ffcfbcac45566feea4d4f777929181900390910190a15b505050565b6060808260405190808252806020026020018201604052801561139e578160200160208202803883390190505b509150826040519080825280602002602001820160405280156113cb578160200160208202803883390190505b50905060006113d9856134f1565b905060005b84811015611458576113f08683613127565b8583815181106113fc57fe5b6020026020010185848151811061140f57fe5b6020908102919091010191909152528161142b575061145b9050565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff909101906001016113de565b50505b9250929050565b600a818154811061146f57fe5b600091825260209091200154905081565b600061148a614047565b50600082815260096020908152604091829020825160a08101845281548082526001830154938201939093526002820154938101939093526003015460ff80821615156060850152610100909104161515608083015215806114ed575080606001515b806114f9575080608001515b15611508576000915050610c9d565b600061151384611e7b565b90506000811180156115375750816020015181101580611537575081604001518111155b92505050610c9d565b50919050565b6000610c9a82610e8a612f4d565b61155c61338f565b600081905060008173ffffffffffffffffffffffffffffffffffffffff1663668a0f026040518163ffffffff1660e01b815260040160206040518083038186803b1580156115a957600080fd5b505afa1580156115bd573d6000803e3d6000fd5b505050506040513d60208110156115d357600080fd5b50511015611628576040805162461bcd60e51b815260206004820152601b60248201527f476976656e2041676772656761746f7220697320696e76616c69640000000000604482015290519081900360640190fd5b60008173ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561167057600080fd5b505afa158015611684573d6000803e3d6000fd5b505050506040513d602081101561169a57600080fd5b50519050601260ff821611156116e15760405162461bcd60e51b81526004018080602001828103825260328152602001806142226032913960400191505060405180910390fd5b60008481526006602052604090205473ffffffffffffffffffffffffffffffffffffffff1661174057600880546001810182556000919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee3018490555b600084815260066020908152604080832080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8716908117909155600783529281902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660ff861617905580518781529182019290925281517f0bcae573430f69c5361e5d76534d3f61d2d803958778680cd74be9dc6299bc63929181900390910190a150505050565b60008061180f614030565b61181884612c4f565b80516020909101517affffffffffffffffffffffffffffffffffffffffffffffffffffff909116935064ffffffffff16915050915091565b6118586135ad565b600061186382611e7b565b116118b5576040805162461bcd60e51b815260206004820152600c60248201527f52617465206973207a65726f0000000000000000000000000000000000000000604482015290519081900360640190fd5b6000818152600460209081526040808320600b808452828520805486529184528285208590559385905292825282547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01909255815183815291517fe69d655565c7ff1353d8eaeea62fb7904fa9696987431ec351be288c865f1ae19281900390910190a150565b6000610ec3612f4d565b6008818154811061146f57fe5b60015473ffffffffffffffffffffffffffffffffffffffff1681565b600061197d848484613603565b509095945050505050565b60066020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b60096020526000908152604090208054600182015460028301546003909301549192909160ff8082169161010090041685565b60606119ed611dd1565b905060005b8151811015611bf2576000828281518110611a0957fe5b602090810291909101810151600254604080517f5265736f6c766572206d697373696e67207461726765743a200000000000000081860152603980820185905282518083039091018152605982018084527fdacb2d01000000000000000000000000000000000000000000000000000000009052605d8201858152607d83019384528151609d840152815195975060009673ffffffffffffffffffffffffffffffffffffffff9095169563dacb2d01958995939492939260bd0191908501908083838c5b83811015611ae5578181015183820152602001611acd565b50505050905090810190601f168015611b125780820380516001836020036101000a031916815260200191505b50935050505060206040518083038186803b158015611b3057600080fd5b505afa158015611b44573d6000803e3d6000fd5b505050506040513d6020811015611b5a57600080fd5b505160008381526003602090815260409182902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff851690811790915582518681529182015281519293507f88a93678a3692f6789d9546fc621bf7234b101ddb7d4fe479455112831b8aa68929081900390910190a150506001016119f2565b5050565b60015473ffffffffffffffffffffffffffffffffffffffff163314611c4c5760405162461bcd60e51b81526004018080602001828103825260358152602001806140b86035913960400191505060405180910390fd5b6000546001546040805173ffffffffffffffffffffffffffffffffffffffff938416815292909116602083015280517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9281900390910190a160018054600080547fffffffffffffffffffffffff000000000000000000000000000000000000000090811673ffffffffffffffffffffffffffffffffffffffff841617909155169055565b6000610c9a826134f1565b611d0461338f565b600580547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff838116919091179182905560408051929091168252517f3df77beb5db05fcdd70a30fc8adf3f83f9501b68579455adbd100b8180940394916020908290030190a150565b60055473ffffffffffffffffffffffffffffffffffffffff1681565b600c6020526000908152604090205481565b6000806000611dc1868686613603565b9250925092505b93509350939050565b606080611ddc613655565b60408051600180825281830190925291925060609190602080830190803883390190505090507f45786368616e676572000000000000000000000000000000000000000000000081600081518110611e3057fe5b602002602001018181525050611e4682826136b4565b9250505090565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b600b6020526000908152604090205481565b6000611e8682612c4f565b517affffffffffffffffffffffffffffffffffffffffffffffffffffff1692915050565b6000610c9a82613770565b611ebd61338f565b60008311611f12576040805162461bcd60e51b815260206004820152601a60248201527f6c6f7765724c696d6974206d7573742062652061626f76652030000000000000604482015290519081900360640190fd5b848411611f505760405162461bcd60e51b815260040180806020018281038252602781526020018061428d6027913960400191505060405180910390fd5b611f6185600263ffffffff6137e316565b8410611f9e5760405162461bcd60e51b815260040180806020018281038252602e8152602001806141f4602e913960400191505060405180910390fd5b848310611fdc5760405162461bcd60e51b81526004018080602001828103825260278152602001806141cd6027913960400191505060405180910390fd5b818015611fe65750805b15612038576040805162461bcd60e51b815260206004820152601c60248201527f43616e6e6f7420667265657a6520617420626f7468206c696d69747300000000604482015290519081900360640190fd5b6000868152600960205260409020805461208257600a80546001810182556000919091527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a8018790555b8581556001810185905560028101849055828061209c5750815b15612171576003810180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016841515177fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16610100841515021790556000612104886134f1565b6000898152600c6020526040902081905590507ff72828471e37526c68fd812a1fa6eeff993c3f81bd96c0242dc5b3e144145df088856121445786612146565b875b604080519283526020830191909152818101849052336060830152519081900360800190a1506121ab565b6003810180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00001690556000878152600c60205260408120555b60006121b688611e7b565b90508015612239576121c661383c565b73ffffffffffffffffffffffffffffffffffffffff1663ce09694089836040518363ffffffff1660e01b81526004018083815260200182815260200192505050600060405180830381600087803b15801561222057600080fd5b505af1158015612234573d6000803e3d6000fd5b505050505b60408051898152602081018990528082018890526060810187905290517f37efb38e92b0f94698f6df0c9070e2f00946862a042ac09e34ae8c547684240a9181900360800190a15050505050505050565b60076020526000908152604090205460ff1681565b60006122a96135ad565b61231886868080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808a02828101820190935289825290935089925088918291850190849080828437600092019190915250879250613867915050565b9695505050505050565b60608083839050604051908082528060200260200182016040528015612352578160200160208202803883390190505b50905060005b83811015610d365761237b85858381811061236f57fe5b90506020020135611e7b565b82828151811061238757fe5b6020908102919091010152600101612358565b60606000838390506040519080825280602002602001820160405280156123cb578160200160208202803883390190505b50915060006123d8612867565b905060606124188686808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506129a192505050565b905060005b858110156125045761242d614030565b61244888888481811061243c57fe5b90506020020135612c4f565b905080600001517affffffffffffffffffffffffffffffffffffffffffffffffffffff1686838151811061247857fe5b602002602001018181525050841580156124c4575087878381811061249957fe5b905060200201357f735553440000000000000000000000000000000000000000000000000000000014155b156124fb578282815181106124d557fe5b6020026020010151806124f857506124f884826020015164ffffffffff16612f32565b94505b5060010161241d565b5050509250929050565b61251661338f565b600081815260096020526040902054612576576040805162461bcd60e51b815260206004820152601860248201527f4e6f20696e766572746564207072696365206578697374730000000000000000604482015290519081900360640190fd5b6000818152600960205260408120818155600181018290556002810182905560030180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00001690556125c982600a613411565b90508015611bf25760408051838152600060208201819052818301819052606082015290517f37efb38e92b0f94698f6df0c9070e2f00946862a042ac09e34ae8c547684240a9181900360800190a15050565b6000610c9a82612985565b60008181526009602052604090208054612688576040805162461bcd60e51b815260206004820152601e60248201527f43616e6e6f7420667265657a65206e6f6e2d696e766572736520726174650000604482015290519081900360640190fd5b600381015460ff161580156126a757506003810154610100900460ff16155b6126f8576040805162461bcd60e51b815260206004820152601a60248201527f546865207261746520697320616c72656164792066726f7a656e000000000000604482015290519081900360640190fd5b600061270383611e7b565b90506000811180156127275750816001015481101580612727575081600201548111155b1561280257600182015460038301805460028501548414610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00909216938514939093171691909117905560006127a0846134f1565b6000858152600c6020908152604091829020839055815187815290810185905280820183905233606082015290519192507ff72828471e37526c68fd812a1fa6eeff993c3f81bd96c0242dc5b3e144145df0919081900360800190a15061136c565b6040805162461bcd60e51b815260206004820152601260248201527f526174652077697468696e20626f756e64730000000000000000000000000000604482015290519081900360640190fd5b60008061285c8484613127565b915091509250929050565b6000612871613adb565b73ffffffffffffffffffffffffffffffffffffffff166323257c2b7f53797374656d53657474696e67730000000000000000000000000000000000007f726174655374616c65506572696f6400000000000000000000000000000000006040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561290957600080fd5b505afa15801561291d573d6000803e3d6000fd5b505050506040513d602081101561293357600080fd5b5051905090565b6000827f7355534400000000000000000000000000000000000000000000000000000000141561296c57506000610d3a565b61297e8261297985612985565b612f32565b9392505050565b600061299082612c4f565b6020015164ffffffffff1692915050565b606060006129ad612f4d565b905073ffffffffffffffffffffffffffffffffffffffff811615612c1c57606083516040519080825280602002602001820160405280156129f8578160200160208202803883390190505b50905060005b8451811015612a875760066000868381518110612a1757fe5b6020026020010151815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16828281518110612a5a57fe5b73ffffffffffffffffffffffffffffffffffffffff909216602092830291909101909101526001016129fe565b506040517f7d723cac00000000000000000000000000000000000000000000000000000000815260206004820181815283516024840152835173ffffffffffffffffffffffffffffffffffffffff861693637d723cac93869392839260440191808601910280838360005b83811015612b0a578181015183820152602001612af2565b505050509050019250505060006040518083038186803b158015612b2d57600080fd5b505afa158015612b41573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526020811015612b8857600080fd5b8101908080516040519392919084640100000000821115612ba857600080fd5b908301906020820185811115612bbd57600080fd5b8251866020820283011164010000000082111715612bda57600080fd5b82525081516020918201928201910280838360005b83811015612c07578181015183820152602001612bef565b50505050905001604052505050925050611540565b8251604051908082528060200260200182016040528015612c47578160200160208202803883390190505b509392505050565b612c57614030565b60008281526006602052604090205473ffffffffffffffffffffffffffffffffffffffff168015612e515760408051600481526024810182526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167ffeaf968c0000000000000000000000000000000000000000000000000000000017815291518151919260009260609273ffffffffffffffffffffffffffffffffffffffff87169286928291908083835b60208310612d4257805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101612d05565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d8060008114612da2576040519150601f19603f3d011682016040523d82523d6000602084013e612da7565b606091505b50915091508115612e495760008060008380602001905160a0811015612dcc57600080fd5b50805160208201516060909201516040805180820190915291955091935090915080612e0e8b612dfc8187613b06565b8769ffffffffffffffffffff16613baf565b7affffffffffffffffffffffffffffffffffffffffffffffffffffff1681526020018264ffffffffff16815250975050505050505050610c9d565b505050611540565b6000838152600b6020526040902054612e68614030565b5060008481526004602090815260408083208484528252918290208251808401845290547affffffffffffffffffffffffffffffffffffffffffffffffffffff80821683527b0100000000000000000000000000000000000000000000000000000090910464ffffffffff1692820192909252825180840190935280519092918291612ef79189911686613baf565b7affffffffffffffffffffffffffffffffffffffffffffffffffffff168152602001826020015164ffffffffff168152509350505050610c9d565b600042612f45838563ffffffff613ced16565b109392505050565b6000612f57613adb565b73ffffffffffffffffffffffffffffffffffffffff16639ee5955a7f53797374656d53657474696e67730000000000000000000000000000000000007f61676772656761746f725761726e696e67466c616773000000000000000000006040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561290957600080fd5b6000827f7355534400000000000000000000000000000000000000000000000000000000141561302157506000610d3a565b60008381526006602052604090205473ffffffffffffffffffffffffffffffffffffffff16801580613067575073ffffffffffffffffffffffffffffffffffffffff8316155b15613076576000915050610d3a565b8273ffffffffffffffffffffffffffffffffffffffff1663357e47fe826040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156130f357600080fd5b505afa158015613107573d6000803e3d6000fd5b505050506040513d602081101561311d57600080fd5b5051949350505050565b600082815260066020526040812054819073ffffffffffffffffffffffffffffffffffffffff1680156132e75760408051602480820187905282518083039091018152604490910182526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f9a6fc8f50000000000000000000000000000000000000000000000000000000017815291518151919260009260609273ffffffffffffffffffffffffffffffffffffffff87169286928291908083835b6020831061322357805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016131e6565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d8060008114613283576040519150601f19603f3d011682016040523d82523d6000602084013e613288565b606091505b509150915081156132df576000808280602001905160a08110156132ab57600080fd5b50602081015160609091015190925090506132d08a6132ca8185613b06565b8b613baf565b9750955061145b945050505050565b505050613387565b6132ef614030565b5060008581526004602090815260408083208784528252918290208251808401909352547affffffffffffffffffffffffffffffffffffffffffffffffffffff81168084527b0100000000000000000000000000000000000000000000000000000090910464ffffffffff169183019190915261336e90879087613baf565b60209091015190935064ffffffffff16915061145b9050565b509250929050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146133e55760405162461bcd60e51b815260040180806020018281038252602f815260200180614145602f913960400191505060405180910390fd5b565b600061297e8383670de0b6b3a7640000613d47565b600061297e8383670de0b6b3a7640000613d84565b6000805b82548110156134e7578383828154811061342b57fe5b906000526020600020015414156134df5782818154811061344857fe5b6000918252602082200155825483907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810190811061348357fe5b906000526020600020015483828154811061349a57fe5b60009182526020909120015582546134d4847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff830161407a565b506001915050610d3a565b600101613415565b5060009392505050565b60008181526006602052604081205473ffffffffffffffffffffffffffffffffffffffff168015613597578073ffffffffffffffffffffffffffffffffffffffff1663668a0f026040518163ffffffff1660e01b815260040160206040518083038186803b15801561356257600080fd5b505afa158015613576573d6000803e3d6000fd5b505050506040513d602081101561358c57600080fd5b50519150610c9d9050565b50506000818152600b6020526040902054610c9d565b60055473ffffffffffffffffffffffffffffffffffffffff1633146133e55760405162461bcd60e51b815260040180806020018281038252602781526020018061411e6027913960400191505060405180910390fd5b600080600061361186611e7b565b915083861415613625575083915080611dc8565b61362e84611e7b565b90508015611dc85761364a81611000878563ffffffff6133e716565b925093509350939050565b604080516001808252818301909252606091602080830190803883390190505090507f466c657869626c6553746f726167650000000000000000000000000000000000816000815181106136a557fe5b60200260200101818152505090565b606081518351016040519080825280602002602001820160405280156136e4578160200160208202803883390190505b50905060005b8351811015613726578381815181106136ff57fe5b602002602001015182828151811061371357fe5b60209081029190910101526001016136ea565b5060005b82518110156137695782818151811061373f57fe5b602002602001015182828651018151811061375657fe5b602090810291909101015260010161372a565b5092915050565b600061377a614047565b50600082815260096020908152604091829020825160a0810184528154815260018201549281019290925260028101549282019290925260039091015460ff80821615156060840181905261010090920416151560808301528061297e57506080015192915050565b6000826137f257506000610d3a565b828202828482816137ff57fe5b041461297e5760405162461bcd60e51b81526004018080602001828103825260218152602001806141746021913960400191505060405180910390fd5b6000610ec37f45786368616e6765720000000000000000000000000000000000000000000000613db6565b600082518451146138a95760405162461bcd60e51b81526004018080602001828103825260388152602001806141956038913960400191505060405180910390fd5b61025842018210613901576040805162461bcd60e51b815260206004820152601f60248201527f54696d6520697320746f6f2066617220696e746f207468652066757475726500604482015290519081900360640190fd5b60005b8451811015613a1557600085828151811061391b57fe5b6020026020010151905084828151811061393157fe5b6020026020010151600014156139785760405162461bcd60e51b81526004018080602001828103825260398152602001806142546039913960400191505060405180910390fd5b807f735553440000000000000000000000000000000000000000000000000000000014156139d75760405162461bcd60e51b81526004018080602001828103825260318152602001806140ed6031913960400191505060405180910390fd5b6139e081612985565b8410156139ed5750613a0d565b613a0b818684815181106139fd57fe5b602002602001015186613eac565b505b600101613904565b507f1bc0fc8997efa076f59b5ef02c315bc5390f7a6d24d661ce12128c01a3b0ba578484604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b83811015613a7d578181015183820152602001613a65565b50505050905001838103825284818151815260200191508051906020019060200280838360005b83811015613abc578181015183820152602001613aa4565b5050505090500194505050505060405180910390a15060019392505050565b6000610ec37f466c657869626c6553746f726167650000000000000000000000000000000000613db6565b600080821215613b5d576040805162461bcd60e51b815260206004820152601b60248201527f4e656761746976652072617465206e6f7420737570706f727465640000000000604482015290519081900360640190fd5b60008381526007602052604090205460ff161561154057600083815260076020526040812054613b929060129060ff16613f69565b600a0a9050613ba7838263ffffffff6137e316565b915050610d3a565b6000613bb9614047565b50600084815260096020908152604091829020825160a08101845281548082526001830154938201939093526002820154938101939093526003015460ff8082161515606085015261010090910416151560808301521580613c19575083155b15613c27578391505061297e565b6000858152600c6020526040902054849250808410801590613c4a575081606001515b15613c5b5781602001519250613ce4565b808410158015613c6c575081608001515b15613c7d5781604001519250613ce4565b8151600090613c9390600263ffffffff6137e316565b9050858111613ca55760009350613cb8565b613cb5818763ffffffff613f6916565b93505b82602001518410613ccf5782602001519350613ce2565b82604001518411613ce257826040015193505b505b50509392505050565b60008282018381101561297e576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b600080600a8304613d5e868663ffffffff6137e316565b81613d6557fe5b0490506005600a825b0610613d7857600a015b600a9004949350505050565b600080613daa84613d9e87600a870263ffffffff6137e316565b9063ffffffff613fc616565b90506005600a82613d6e565b60008181526003602090815260408083205481517f4d697373696e6720616464726573733a2000000000000000000000000000000093810193909352603180840186905282518085039091018152605190930190915273ffffffffffffffffffffffffffffffffffffffff1690816137695760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613e71578181015183820152602001613e59565b50505050905090810190601f168015613e9e5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b6000838152600b60209081526040808320805460010190819055815180830183527affffffffffffffffffffffffffffffffffffffffffffffffffffff968716815264ffffffffff9586168185019081529785526004845282852091855292529091209051815494519092167b01000000000000000000000000000000000000000000000000000000029183167fffffffffff00000000000000000000000000000000000000000000000000000090941693909317909116179055565b600082821115613fc0576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b600080821161401c576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b600082848161402757fe5b04949350505050565b604080518082019091526000808252602082015290565b6040518060a001604052806000815260200160008152602001600081526020016000151581526020016000151581525090565b81548183558181111561136c5760008381526020902061136c918101908301610ec691905b808211156140b3576000815560010161409f565b509056fe596f75206d757374206265206e6f6d696e61746564206265666f726520796f752063616e20616363657074206f776e65727368697052617465206f6620735553442063616e6e6f7420626520757064617465642c206974277320616c7761797320554e49542e4f6e6c7920746865206f7261636c652063616e20706572666f726d207468697320616374696f6e4f6e6c792074686520636f6e7472616374206f776e6572206d617920706572666f726d207468697320616374696f6e536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7743757272656e6379206b6579206172726179206c656e677468206d757374206d61746368207261746573206172726179206c656e6774682e6c6f7765724c696d6974206d7573742062652062656c6f772074686520656e747279506f696e7475707065724c696d6974206d757374206265206c657373207468616e20646f75626c6520656e747279506f696e7441676772656761746f7220646563696d616c732073686f756c64206265206c6f776572206f7220657175616c20746f2031385a65726f206973206e6f7420612076616c696420726174652c20706c656173652063616c6c2064656c6574655261746520696e73746561642e75707065724c696d6974206d7573742062652061626f76652074686520656e747279506f696e74a265627a7a7231582007867f64bfca816832be8b1e5b111cb78f9c62335028c392907d0a5cfca55c8364736f6c6343000510003243757272656e6379206b6579206c656e67746820616e642072617465206c656e677468206d757374206d617463682e52617465206f6620735553442063616e6e6f7420626520757064617465642c206974277320616c7761797320554e49542e536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7743757272656e6379206b6579206172726179206c656e677468206d757374206d61746368207261746573206172726179206c656e6774682e5a65726f206973206e6f7420612076616c696420726174652c20706c656173652063616c6c2064656c6574655261746520696e73746561642e000000000000000000000000b64ff7a4a33acdf48d97dab0d764afd0f6176882000000000000000000000000ac1e8b385230970319906c03a1d8567e3996d1d5000000000000000000000000242a3df52c375bee81b1c668741d7c63af68fdd200000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Library Used

SafeDecimalMath : 0x1a60e2e2a8be0bc2b6381dd31fd3fd5f9a28de4c

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