Contract 0xf42eAe0DeC53625cbEf05FA6EddCec89eEaCcc41 1

Contract Overview

Balance:
0 Ether

Token:
Txn Hash
Method
Block
From
To
Value
0x387e345c5f57ea40f7318a90cb2604e2eae302bb9eeb85e2fe1ba10e37f7cb3dAdd Token Pair85250752021-05-04 6:47:23426 days 18 hrs ago0x35b9f43f9ec7aef35bff4f3330ef74df95ee9364 IN  0xf42eae0dec53625cbef05fa6eddcec89eeaccc410 Ether0.0022631820
0x12c452e2bf5fa250ddcf7f38d2d4642fc6add3ed30c788310923de7a8d2caad20x60a0604085247032021-05-04 5:14:23426 days 19 hrs ago0x35b9f43f9ec7aef35bff4f3330ef74df95ee9364 IN  Create: CompoundAdapterAltA0 Ether0.0593459620
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xe72a94a569ce4748192b0ec2bdc5495779b429440 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xe72a94a569ce4748192b0ec2bdc5495779b429440 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xe72a94a569ce4748192b0ec2bdc5495779b429440 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xe72a94a569ce4748192b0ec2bdc5495779b429440 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xee8502c48db57115221ba5edae181c0425cf80430 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xee8502c48db57115221ba5edae181c0425cf80430 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xee8502c48db57115221ba5edae181c0425cf80430 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xee8502c48db57115221ba5edae181c0425cf80430 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0x542f8a5e1cd31cb4ce0fe08474861e33b490e39b0 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xee8502c48db57115221ba5edae181c0425cf80430 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0x542f8a5e1cd31cb4ce0fe08474861e33b490e39b0 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xe72a94a569ce4748192b0ec2bdc5495779b429440 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xe72a94a569ce4748192b0ec2bdc5495779b429440 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xe72a94a569ce4748192b0ec2bdc5495779b429440 Ether
0xe3359da240be19c35b7dd7663aab5787a5ae409f28eca7c04f3f022c4d59453585893052021-05-15 10:34:59415 days 14 hrs ago 0xe72a94a569ce4748192b0ec2bdc5495779b42944 0xf42eae0dec53625cbef05fa6eddcec89eeaccc410 Ether
0x45c9a0d649290e870d11cedcc75acb3bc0c99301961ed76504cd834af24441e585537662021-05-09 6:24:32421 days 18 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xe72a94a569ce4748192b0ec2bdc5495779b429440 Ether
0x45c9a0d649290e870d11cedcc75acb3bc0c99301961ed76504cd834af24441e585537662021-05-09 6:24:32421 days 18 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xe72a94a569ce4748192b0ec2bdc5495779b429440 Ether
0x45c9a0d649290e870d11cedcc75acb3bc0c99301961ed76504cd834af24441e585537662021-05-09 6:24:32421 days 18 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0x542f8a5e1cd31cb4ce0fe08474861e33b490e39b0 Ether
0x45c9a0d649290e870d11cedcc75acb3bc0c99301961ed76504cd834af24441e585537662021-05-09 6:24:32421 days 18 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0x542f8a5e1cd31cb4ce0fe08474861e33b490e39b0 Ether
0x45c9a0d649290e870d11cedcc75acb3bc0c99301961ed76504cd834af24441e585537662021-05-09 6:24:32421 days 18 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0x542f8a5e1cd31cb4ce0fe08474861e33b490e39b0 Ether
0x45c9a0d649290e870d11cedcc75acb3bc0c99301961ed76504cd834af24441e585537662021-05-09 6:24:32421 days 18 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xee8502c48db57115221ba5edae181c0425cf80430 Ether
0x45c9a0d649290e870d11cedcc75acb3bc0c99301961ed76504cd834af24441e585537662021-05-09 6:24:32421 days 18 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xee8502c48db57115221ba5edae181c0425cf80430 Ether
0x45c9a0d649290e870d11cedcc75acb3bc0c99301961ed76504cd834af24441e585537662021-05-09 6:24:32421 days 18 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0x542f8a5e1cd31cb4ce0fe08474861e33b490e39b0 Ether
0x45c9a0d649290e870d11cedcc75acb3bc0c99301961ed76504cd834af24441e585537662021-05-09 6:24:32421 days 18 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xe72a94a569ce4748192b0ec2bdc5495779b429440 Ether
0x45c9a0d649290e870d11cedcc75acb3bc0c99301961ed76504cd834af24441e585537662021-05-09 6:24:32421 days 18 hrs ago 0xf42eae0dec53625cbef05fa6eddcec89eeaccc41 0xe72a94a569ce4748192b0ec2bdc5495779b429440 Ether
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CompoundAdapterAltA

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, None license
File 1 of 21 : AltContracts.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;
import "../Nutmeg.sol";

// @notice This contract is a version of Nutmeg that contains additional
// interfaces for testing

contract NutmegAltA is Nutmeg {
    //@notice output version string
    function getVersionString()
    external virtual pure returns (string memory) {
        return "nutmegalta";
   }
}

contract NutmegAltB is Nutmeg {
    //@notice output version string
    function getVersionString()
    external virtual pure returns (string memory) {
        return "nutmegaltb";
   }
}

import "../NutDistributor.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";

// @notice This contract is a version of NutDistributor that allows
// the epoch intervals to be changed for testing

contract NutDistributorAltA is NutDistributor {
    //@notice output version string
    function getVersionString()
    external virtual pure override returns (string memory) {
        return "nutdistributoralta";
   }
}

contract NutDistributorAltB is NutDistributor {
    //@notice output version string
    function getVersionString()
    external virtual pure override returns (string memory) {
        return "nutdistributoraltb";
   }
}

import "./MockERC20.sol";

contract MockERC20AltA is
MockERC20("MockERC20AltA", "MOCKERC20ALTA", 18) {
}

contract MockERC20AltB is
MockERC20("MockERC20AltB", "MOCKERC20ALTB", 18) {
}

contract MockERC20AltC is
MockERC20("MockERC20AltC", "MOCKERC20ALTC", 6) {
}

import "./MockCERC20.sol";

contract MockCERC20AltA is MockCERC20Base {
    constructor(address tokenAddr)
    MockCERC20Base(tokenAddr, "MockCERC20 AltA", "MOCKCERC20ALTA", 18) {
    }
}
contract MockCERC20AltB is MockCERC20Base {
    constructor(address tokenAddr)
    MockCERC20Base(tokenAddr, "MockCERC20 AltB", "MOCKCERC20ALTB", 18) {
    }
}
contract MockCERC20AltC is MockCERC20Base {
    constructor(address tokenAddr)
    MockCERC20Base(tokenAddr, "MockCERC20 AltC", "MOCKCERC20ALTC", 6) {
    }
}

import "../adapters/CompoundAdapter.sol";
import "../interfaces/INutmeg.sol";
contract CompoundAdapterAltA is CompoundAdapter {
    constructor(INutmeg nutmegAddr) CompoundAdapter(nutmegAddr) {
    }
}

contract CompoundAdapterAltB is CompoundAdapter {
    constructor(INutmeg nutmegAddr) CompoundAdapter(nutmegAddr) {
    }
}

File 2 of 21 : Nutmeg.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/proxy/Initializable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import './lib/Governable.sol';
import './lib/Math.sol';
import "./interfaces/IAdapter.sol";
import "./interfaces/INutmeg.sol";
import "./interfaces/INutDistributor.sol";
import "./interfaces/IPriceOracle.sol";

contract Nutmeg is Initializable, Governable, INutmeg {
    using SafeMath for uint;
    using SafeERC20 for IERC20;

    address public nutDistributor;
    address public nut;

    uint private constant INVALID_POSITION_ID = type(uint).max;
    uint private constant NOT_LOCKED = 0;
    uint private constant LOCKED = 1;
    uint private constant TRANCHE_BBB = uint(Tranche.BBB);
    uint private constant TRANCHE_A = uint(Tranche.A);
    uint private constant TRANCHE_AA = uint(Tranche.AA);

    uint private constant MULTIPLIER = 10**18;
    uint private constant NUM_BLOCK_PER_YEAR = 2102400;
    address private constant INVALID_ADAPTER = address(2);

    uint public constant MAX_NUM_POOL = 256;
    uint public constant LIQUIDATION_COMMISSION = 5;
    uint public constant MAX_INTEREST_RATE_PER_BLOCK = 100000; // 1000.00%
    uint public constant MIN_INTEREST_RATE_PER_BLOCK = 500; // 5.00%
    uint public constant VERSION_ID = 1;
    uint public POOL_LOCK;
    uint public EXECUTION_LOCK;
    uint public STAKE_COUNTER;
    uint public POSITION_COUNTER;
    uint public CURR_POSITION_ID;
    address public CURR_SENDER;
    address public CURR_ADAPTER;

    // treasury pool array and map
    address[] public pools; // array of treasury pools
    mapping(address => Pool) public poolMap; // baseToken => pool mapping.

    // stake
    mapping(address => mapping (address => Stake[3])) public stakeMap; // baseToken => sender => tranche.
    mapping(address => uint[]) lenderStakeMap; // all stakes of a lender. address => stakeId

    // adapter
    address[] public adapters;
    mapping(address => bool) public adapterMap;

    // position
    mapping(uint => Position) public positionMap;
    mapping(address => uint[]) borrowerPositionMap; // all positions of a borrower. address => positionId
    mapping(address => mapping(address => uint)) minNut4Borrowers; // pool => adapter => uint

    /// @dev Reentrancy lock guard.
    modifier poolLock() {
        require(POOL_LOCK == NOT_LOCKED, 'pl lck');
        POOL_LOCK = LOCKED;
        _;
        POOL_LOCK = NOT_LOCKED;
    }

    /// @dev Reentrancy lock guard for execution.
    modifier inExecution() {
        require(CURR_POSITION_ID != INVALID_POSITION_ID, 'not exc');
        require(CURR_ADAPTER == msg.sender, 'bad adpr');
        require(EXECUTION_LOCK == NOT_LOCKED, 'exc lock');
        EXECUTION_LOCK = LOCKED;
        _;
        EXECUTION_LOCK = NOT_LOCKED;
    }

    /// @dev Accrue interests in a pool
    modifier accrue(address token) {
        accrueInterest(token);
        _;
    }

    /// @dev Initialize the smart contract, using msg.sender as the first governor.
    function initialize(address _governor) external initializer {
        __Governable__init(_governor);
        POOL_LOCK = NOT_LOCKED;
        EXECUTION_LOCK = NOT_LOCKED;
        STAKE_COUNTER = 1;
        POSITION_COUNTER = 1;
        CURR_POSITION_ID = INVALID_POSITION_ID;
        CURR_ADAPTER = INVALID_ADAPTER;
    }

    function setNutDistributor(address addr) external onlyGov {
        nutDistributor = addr;
    }

    function setNut(address addr) external onlyGov {
        nut = addr;
    }

    function setMinNut4Borrowers(address poolAddr, address adapterAddr, uint val) external onlyGov {
        require(adapterMap[adapterAddr], 'setMin no adpr');
        Pool storage pool = poolMap[poolAddr];
        require(pool.isExists, 'setMin no pool');
        minNut4Borrowers[poolAddr][adapterAddr] = val;
    }

    /// @notice Get all stake IDs of a lender
    function getStakeIds(address lender) external override view returns (uint[] memory){
        return lenderStakeMap[lender];
    }

    /// @notice Get all position IDs of a borrower
    function getPositionIds(address borrower) external override view returns (uint[] memory){
        return borrowerPositionMap[borrower];
    }

    /// @notice Return current position ID
    function getCurrPositionId() external override view returns (uint) {
        return CURR_POSITION_ID;
    }

    /// @notice Return next position ID
    function getNextPositionId() external override view returns (uint) {
        return POSITION_COUNTER;
    }

    /// @notice Get position information
    function getPosition(uint id) external override view returns (Position memory) {
        return positionMap[id];
    }

    /// @dev get current sender
    function getCurrSender() external override view returns (address) {
        return CURR_SENDER;
    }


    /// @dev Get all treasury pools
    function getPools() external view returns (address[] memory) {
        return pools;
    }

    /// @dev Get a specific pool given address
    function getPool(address addr) external view returns (Pool memory) {
        return poolMap[addr];
    }

    /// @dev Add a new treasury pool.
    /// @param token The underlying base token for the pool, e.g., DAI.
    /// @param interestRate The interest rate per block of Tranche A.
    function addPool(address token, uint interestRate)
        external poolLock onlyGov {
        require(pools.length < MAX_NUM_POOL, 'addPl pl > max');
        require(_isInterestRateValid(interestRate), 'addPl bad ir');
        Pool storage pool = poolMap[token];
        require(!pool.isExists, 'addPl pool exts');
        pool.isExists = true;
        pool.baseToken = token;
        pool.interestRates = [interestRate.div(2), interestRate, interestRate.mul(2)];
        pools.push(token);
        emit addPoolEvent(token, interestRate);
        pool.lossMultiplier = [ MULTIPLIER, MULTIPLIER, MULTIPLIER ];
    }

    /// @dev Update interest rate of the pool
    /// @param token The underlying base token for the pool, e.g., DAI.
    /// @param interestRate The interest rate per block of Tranche A. Input 316 for 3.16% APY
    function updateInterestRates(address token, uint interestRate)
        external poolLock onlyGov {
        require(_isInterestRateValid(interestRate), 'upIR bad ir');
        Pool storage pool = poolMap[token];
        require(pool.isExists, 'upIR no pool');
        pool.interestRates = [interestRate.div(2), interestRate, interestRate.mul(2)];
    }

    function _isInterestRateValid(uint interestRate)
        internal pure returns(bool) {
        return (interestRate <= MAX_INTEREST_RATE_PER_BLOCK &&
            interestRate >= MIN_INTEREST_RATE_PER_BLOCK);
    }

    /// @notice Stake to a treasury pool.
    /// @param token The contract address of the base token of the pool.
    /// @param tranche The tranche of the pool, 0 - AA, 1 - A, 2 - BBB.
    /// @param principal The amount of principal
    function stake(address token, uint tranche, uint principal)
        external poolLock accrue(token) {
        require(tranche < 3, 'stk bad trnch');
        require(principal > 0, 'stk bad prpl');
        Pool storage pool = poolMap[token];
        require(pool.isExists, 'stk no pool');
        if (tranche == TRANCHE_BBB) {
            require(principal.add(pool.principals[TRANCHE_BBB]) <= pool.principals[TRANCHE_AA],
                'stk BBB full');
        }

        // 1. transfer the principal to the pool.
        IERC20(pool.baseToken).safeTransferFrom(msg.sender, address(this), principal);

        // 2. add or update a stake
        Stake storage stk = stakeMap[token][msg.sender][tranche];
        uint sumIpp = pool.sumIpp[tranche];
        uint scaledPrincipal = 0;

        if (stk.id == 0) { // new stk
            stk.id = STAKE_COUNTER++;
            stk.status = StakeStatus.Open;
            stk.owner = msg.sender;
            stk.pool = token;
            stk.tranche = tranche;
        } else { // add liquidity to an existing stk
	          scaledPrincipal = _scaleByLossMultiplier( stk, stk.principal );
            uint interest = scaledPrincipal.mul( sumIpp.sub(stk.sumIppStart)).div(MULTIPLIER);
            stk.earnedInterest = _scaleByLossMultiplier(stk, stk.earnedInterest ).add(interest);
        }
        stk.sumIppStart = sumIpp;
        stk.principal = scaledPrincipal.add(principal);
	      stk.lossZeroCounterBase = pool.lossZeroCounter[tranche];
	      stk.lossMultiplierBase = pool.lossMultiplier[tranche];
        lenderStakeMap[stk.owner].push(stk.id);

        // update pool information
        pool.principals[tranche] = pool.principals[tranche].add(principal);
        updateInterestRateAdjustment(token);
        if (INutDistributor(nutDistributor).inNutDistribution()) {
            INutDistributor(nutDistributor).updateVtb(token, stk.owner, principal, 0);
        }

        emit stakeEvent(token, msg.sender, tranche, principal, stk.id);
    }



    /// @notice Unstake from a treasury pool.
    /// @param token The address of the pool.
    /// @param tranche The tranche of the pool, 0 - AA, 1 - A, 2 - BBB.
    /// @param amount The amount of principal that owner want to withdraw
    function unstake(address token, uint tranche, uint amount)
        external poolLock accrue(token) {
        require(tranche < 3, 'unstk bad trnch');
        Pool storage pool = poolMap[token];
        Stake storage stk = stakeMap[token][msg.sender][tranche];
        require(stk.id > 0, 'unstk no dpt');
        uint activePrincipal = _scaleByLossMultiplier( stk, stk.principal );
        require(amount > 0 && amount <= activePrincipal, 'unstk bad amt');
        require(stk.status == StakeStatus.Open, 'unstk bad status');
        // get the available amount to remove
        uint withdrawAmt = _getWithdrawAmount(poolMap[stk.pool], amount);
        uint interest = activePrincipal.mul(pool.sumIpp[tranche].sub(stk.sumIppStart)).div(MULTIPLIER);
        uint totalInterest = _scaleByLossMultiplier(
            stk, stk.earnedInterest
        ).add(interest);
        if (totalInterest > pool.interests[tranche]) { // unlikely, but just in case.
            totalInterest = pool.interests[tranche];
        }

        // transfer liquidity to the lender
        uint actualWithdrawAmt = withdrawAmt.add(totalInterest);
        IERC20(pool.baseToken).safeTransfer(msg.sender, actualWithdrawAmt);

        // update stake information
        stk.principal = activePrincipal.sub(withdrawAmt);
        stk.sumIppStart = pool.sumIpp[tranche];
        stk.lossZeroCounterBase = pool.lossZeroCounter[tranche];
        stk.lossMultiplierBase = pool.lossMultiplier[tranche];
        stk.earnedInterest = 0;
        if (stk.principal == 0) {
            stk.status = StakeStatus.Closed;
        }

        // update pool principal and interest information
        pool.principals[tranche] = pool.principals[tranche].sub(withdrawAmt);
        pool.interests[tranche] = pool.interests[tranche].sub(totalInterest);
        updateInterestRateAdjustment(token);
        if (INutDistributor(nutDistributor).inNutDistribution() && withdrawAmt > 0) {
            INutDistributor(nutDistributor).updateVtb(token, stk.owner, 0, withdrawAmt);
        }

        emit unstakeEvent(token, msg.sender, tranche, withdrawAmt, stk.id);
    }

    function _scaleByLossMultiplier(Stake memory stk, uint quantity) internal view returns (uint) {
	      Pool memory pool = poolMap[stk.pool];
	      return stk.lossZeroCounterBase < pool.lossZeroCounter[stk.tranche] ? 0 :
	          quantity.mul(
	          pool.lossMultiplier[stk.tranche]
	      ).div(
	          stk.lossMultiplierBase
	      );
    }

    /// @notice Accrue interest for a given pool.
    /// @param token Address of the pool.
    function accrueInterest(address token) internal {
        Pool storage pool = poolMap[token];
        require(pool.isExists, 'accrIr no pool');

        uint totalLoan = Math.sumOf3UintArray(pool.loans);
        uint currBlock = block.number;
        if (currBlock <= pool.latestAccruedBlock) return;
        if (totalLoan > 0 ) {
            uint interestRate = pool.interestRates[TRANCHE_A];
            if (!pool.isIrAdjustPctNegative) {
                interestRate = interestRate.mul(pool.irAdjustPct.add(100)).div(100);
            } else {
                interestRate = interestRate.mul(uint(100).sub(pool.irAdjustPct)).div(100);
            }
            uint rtb = interestRate.mul(currBlock.sub(pool.latestAccruedBlock));

            // update pool sumRtb.
            pool.sumRtb = pool.sumRtb.add(rtb);

            // update tranche sumIpp.
            for (uint idx = 0; idx < pool.loans.length; idx++) {
                if (pool.principals[idx] > 0) {
                    uint interest = (pool.loans[idx].mul(rtb)).div(NUM_BLOCK_PER_YEAR.mul(10000));
                    pool.interests[idx] = pool.interests[idx].add(interest);
                    pool.sumIpp[idx]= pool.sumIpp[idx].add(interest.mul(MULTIPLIER).div(pool.principals[idx]));
                }
            }
        }
        pool.latestAccruedBlock = block.number;
    }

    /// @notice Get pool information
    /// @param token The base token
    function getPoolInfo(address token) external view override returns(uint, uint, uint) {
        Pool memory pool = poolMap[token];
        require(pool.isExists, 'getPolInf no pol');
        return (Math.sumOf3UintArray(pool.principals),
                Math.sumOf3UintArray(pool.loans),
                pool.totalCollateral);
    }

    /// @notice Get interest a position need to pay
    /// @param token Address of the pool.
    /// @param posId Position ID.
    function getPositionInterest(address token, uint posId) public override view returns(uint) {
        Pool storage pool = poolMap[token];
        require(pool.isExists, 'getPosIR no pool');
        Position storage pos = positionMap[posId];
        require(pos.baseToken == pool.baseToken, 'getPosIR bad match');
        return Math.sumOf3UintArray(pos.loans).mul(pool.sumRtb.sub(pos.sumRtbStart)).div(
            NUM_BLOCK_PER_YEAR.mul(10000)
        );
    }

    /// @dev Update the interest rate adjustment of the pool
    /// @param token Address of the pool
    function updateInterestRateAdjustment(address token) public {
        Pool storage pool = poolMap[token];
        require(pool.isExists, 'updtIRAdj no pool');

        uint totalPrincipal = Math.sumOf3UintArray(pool.principals);
        uint totalLoan = Math.sumOf3UintArray(pool.loans);

        if (totalPrincipal > 0 ) {
            uint urPct = totalLoan >= totalPrincipal ? 100 : totalLoan.mul(100).div(totalPrincipal);
            if (urPct > 90) { // 0% + 50 * (UR - 90%)
                pool.irAdjustPct = urPct.sub(90).mul(50);
                pool.isIrAdjustPctNegative = false;
            } else if (urPct < 90) { // UR - 90%
                pool.irAdjustPct = (uint(90).sub(urPct));
                pool.isIrAdjustPctNegative = true;
            }
        }
    }

    function _getWithdrawAmount(Pool memory pool, uint amount) internal pure returns (uint) {
        uint availPrincipal = Math.sumOf3UintArray(pool.principals).sub(
            Math.sumOf3UintArray(pool.loans)
        );
        return amount > availPrincipal ? availPrincipal : amount;
    }

    /// @dev Get the collateral ratio of the pool.
    /// @param baseToken Base token of the pool.
    /// @param baseAmt The collateral from the borrower.
    function _getCollateralRatioPct(address baseToken, uint baseAmt) public view returns (uint) {
        Pool storage pool = poolMap[baseToken];
        require(pool.isExists, '_getCollRatPct no pool');

        uint totalPrincipal = Math.sumOf3UintArray(pool.principals);
        uint totalLoan = Math.sumOf3UintArray(pool.loans);
        uint urPct = (totalPrincipal == 0) ? 100 : ((totalLoan.add(baseAmt)).mul(100)).div(totalPrincipal);
        if (urPct > 100) { // not likely, but just in case.
            urPct = 100;
        }

        if (urPct > 90) { // 10% + 9 * (UR - 90%)
            return (urPct.sub(90).mul(9)).add(10);
        }
        // 10% - 0.1 * (90% - UR)
        return (urPct.div(10)).add(1);
    }

    /// @notice Get the maximum available borrow amount
    /// @param baseToken Base token of the pool
    /// @param baseAmt The collateral from the borrower
    function getMaxBorrowAmount(address baseToken, uint baseAmt)
        public override view returns (uint) {
        uint crPct = _getCollateralRatioPct(baseToken, baseAmt);
        return (baseAmt.mul(100).div(crPct)).sub(baseAmt);
    }


    /// @notice Get stakes of a user in a pool
    /// @param token The address of the pool
    /// @param owner The address of the owner
    function getStake(address token, address owner) public view returns (Stake[3] memory) {
        return stakeMap[token][owner];
    }

    /// @dev Add adapter to Nutmeg
    /// @param token The address of the adapter
    function addAdapter(address token) external poolLock onlyGov {
        adapters.push(token);
        adapterMap[token] = true;
    }

    /// @dev Remove adapter from Nutmeg
    /// @param token The address of the adapter
    function removeAdapter(address token) external poolLock onlyGov {
        adapterMap[token] = false;
    }

    /// @notice Borrow tokens from the pool. Must only be called by adapter while under execution.
    /// @param baseToken The token to borrow from the pool.
    /// @param collToken The token borrowers got from the 3rd party pool.
    /// @param baseAmt The amount of collateral from borrower.
    /// @param borrowAmt The amount of tokens to borrow, x time leveraged already.
    function borrow(address baseToken, address collToken, uint baseAmt, uint borrowAmt)
        external override accrue(baseToken) inExecution {
        // check pool and position.
        Pool storage pool = poolMap[baseToken];
        require(pool.isExists, 'brw no pool');
        Position storage position = positionMap[CURR_POSITION_ID];
        require(position.baseToken == address(0), 'brw no rebrw');

        // check borrowAmt
        uint maxBorrowAmt = getMaxBorrowAmount(baseToken, baseAmt);
        require(borrowAmt <= maxBorrowAmt, "brw too bad");
        require(borrowAmt > baseAmt, "brw brw < coll");

        // check available principal per tranche.
        uint[3] memory availPrincipals;
        for (uint i = 0; i < 3; i++) {
            availPrincipals[i] = pool.principals[i].sub(pool.loans[i]);
        }
        uint totalAvailPrincipal = Math.sumOf3UintArray(availPrincipals);
        require(borrowAmt <= totalAvailPrincipal, 'brw asset low');

        // calculate loan amount from each tranche.
        uint[3] memory loans;
        for (uint i = 0; i < 3; i++) {
            loans[i] = borrowAmt.mul(availPrincipals[i]).div(totalAvailPrincipal);
        }
        loans[2] = borrowAmt.sub(loans[0].add(loans[1])); // handling rounding numbers

        // transfer base tokens from borrower to contract as the collateral.
        IERC20(pool.baseToken).safeApprove(address(this), 0);
        IERC20(pool.baseToken).safeApprove(address(this), baseAmt);
        IERC20(pool.baseToken).safeTransferFrom(position.owner, address(this), baseAmt);

        // transfer borrowed assets to the adapter
        IERC20(pool.baseToken).safeTransfer(msg.sender, borrowAmt);

        // update position information
        position.status = PositionStatus.Open;
        position.baseToken = pool.baseToken;
        position.collToken = collToken;
        position.baseAmt = baseAmt;
        position.borrowAmt = borrowAmt;
        position.loans = loans;
        position.sumRtbStart = pool.sumRtb;

        borrowerPositionMap[position.owner].push(position.id);

        // update pool information
        for (uint i = 0; i < 3; i++) {
            pool.loans[i] = pool.loans[i].add(loans[i]);
        }
        pool.totalCollateral = pool.totalCollateral.add(baseAmt);
        updateInterestRateAdjustment(baseToken);
    }

    function _getRepayAmount(uint[3] memory loans, uint totalAmt)
        public pure returns(uint[3] memory) {
        uint totalLoan = Math.sumOf3UintArray(loans);
        uint amount = totalLoan < totalAmt ? totalLoan : totalAmt;
        uint[3] memory repays = [uint(0), uint(0), uint(0)];
        for (uint i; i < 3; i++) {
            repays[i] = (loans[i].mul(amount)).div(totalLoan);
        }
        repays[2] = amount.sub(repays[0].add(repays[1]));

        return repays;
    }

    /// @notice Repay tokens to the pool and close the position. Must only be called while under execution.
    /// @param baseToken The token to borrow from the pool.
    /// @param repayAmt The amount of base token repaid from adapter.
    function repay(address baseToken, uint repayAmt)
        external override accrue(baseToken) inExecution {

        Position storage pos = positionMap[CURR_POSITION_ID];
        Pool storage pool = poolMap[pos.baseToken];
        require(pool.isExists, 'rpy no pool');
        require(adapterMap[pos.adapter] && msg.sender == pos.adapter, 'repay: no such adapter');

        uint totalLoan = Math.sumOf3UintArray(pos.loans); // owe to lenders
        uint interest = getPositionInterest(pool.baseToken, pos.id); // already paid to lenders
        uint totalRepayAmt = repayAmt.add(pos.baseAmt).sub(interest); // total amount used for repayment
        uint change = totalRepayAmt > totalLoan ? totalRepayAmt.sub(totalLoan) : 0; // profit of the borrower


        // transfer total redeemed amount from adapter to the pool
        IERC20(baseToken).safeTransferFrom(msg.sender, address(this), repayAmt);
        if (totalRepayAmt < totalLoan) {
            pos.repayDeficit = totalLoan.sub(totalRepayAmt);
        }
        uint[3] memory repays = _getRepayAmount(pos.loans, repayAmt);
        // update position information
        pos.status = PositionStatus.Closed;
        for (uint i; i < 3; i++) {
            pos.loans[i] = pos.loans[i].sub(repays[i]);
        }

        // update pool information
        pool.totalCollateral = pool.totalCollateral.sub(pos.baseAmt);
        for (uint i; i < 3; i++) {
            pool.loans[i] = pool.loans[i].sub(repays[i]);
        }

        // send profit, if any to the borrower.
        if (change > 0) {
            IERC20(baseToken).safeTransfer(pos.owner, change);
        }
    }

    /// @notice Liquidate a position when conditions are satisfied
    /// @param baseToken The base token of the pool.
    /// @param liquidateAmt The repay amount from adapter.
    function liquidate( address baseToken, uint liquidateAmt)
        external override accrue(baseToken) inExecution {
        Position storage pos = positionMap[CURR_POSITION_ID];
        Pool storage pool = poolMap[baseToken];
        require(pool.isExists, 'lqt no pool');
        require(pool.baseToken == baseToken, "lqt base no match");
        require(adapterMap[pos.adapter] && msg.sender == pos.adapter, 'lqt no adpr');
        require(liquidateAmt > 0, 'lqt bad rpy');

        // transfer liquidateAmt of base tokens from adapter to pool.
        IERC20(baseToken).safeTransferFrom(msg.sender, address(this), liquidateAmt);

        uint totalLoan = Math.sumOf3UintArray(pos.loans);
        uint interest = getPositionInterest(pool.baseToken, pos.id);
        uint totalRepayAmt = liquidateAmt.add(pos.baseAmt).sub(interest); // total base tokens from liquidated
        uint bonusAmt = LIQUIDATION_COMMISSION.mul(totalRepayAmt).div(100); // bonus for liquidator.

        uint repayAmt = totalRepayAmt.sub(bonusAmt); // amount to pay lenders and the borrower
        uint change = totalLoan < repayAmt ? repayAmt.sub(totalLoan) : 0;

        uint[3] memory repays = _getRepayAmount(pos.loans, liquidateAmt);

        // transfer bonus to the liquidator.
        IERC20(baseToken).safeTransfer(tx.origin, bonusAmt);

        // update position information
        pos.status = PositionStatus.Liquidated;
        for (uint i; i < 3; i++) {
            pos.loans[i] = pos.loans[i].sub(repays[i]);
        }

        // update pool information
        pool.totalCollateral = pool.totalCollateral.sub(pos.baseAmt);
        for (uint i; i < 3; i++) {
            pool.loans[i] = pool.loans[i].sub(repays[i]);
        }

        // send leftover to position owner
        if (change > 0) {
            IERC20(baseToken).safeTransfer(pos.owner, change);
        }
        if (totalRepayAmt < totalLoan) {
            pos.repayDeficit = totalLoan.sub(totalRepayAmt);
        }
    }

    /// @notice Settle credit event callback
    /// @param baseToken Base token of the pool.
    /// @param collateralLoss Loss to be distributed
    /// @param poolLoss Loss to be distributed
    function distributeCreditLosses( address baseToken, uint collateralLoss, uint poolLoss) external override accrue(baseToken) inExecution {
        Pool storage pool = poolMap[baseToken];
        require(pool.isExists, 'dstCrd no pool');
        require(collateralLoss <= pool.totalCollateral, 'dstCrd col high');
        if (collateralLoss >= 0) {
            pool.totalCollateral = pool.totalCollateral.sub(collateralLoss);
        }

        if (poolLoss == 0) {
            return;
        }

        uint totalPrincipal = Math.sumOf3UintArray(pool.principals);

        uint runningLoss = poolLoss;
        for (uint i = 0; i < 3; i++) {
            uint j = 3 - i - 1;
            // The running totals are based on the principal,
            // however, when I calculate the multipliers, I
            // take into account accured interest
            uint tranchePrincipal = pool.principals[j];
            uint trancheValue = pool.principals[j] + pool.interests[j];
            // Do not scale pool.sumIpp.  Since I am scaling the
            // principal, this will cause the interest rate
            // calcuations to take into account the losses when
            // a lender position is unstaked.
            if (runningLoss >= tranchePrincipal) {
                pool.principals[j] = 0;
                pool.interests[j] = 0;
                pool.lossZeroCounter[j] = block.number;
                pool.lossMultiplier[j] = MULTIPLIER;
                runningLoss = runningLoss.sub(tranchePrincipal);
            } else {
                uint valueRemaining = tranchePrincipal.sub(runningLoss);
		            pool.principals[j] = pool.principals[j].mul(valueRemaining).div(trancheValue);
		            pool.interests[j] = pool.interests[j].mul(valueRemaining).div(trancheValue);
		            pool.lossMultiplier[j] = valueRemaining.mul(MULTIPLIER).div(trancheValue);
		            break;
	          }
        }

        // subtract the pool loss from the total loans
        // this keeps principal - loans the same so that
        // we have a correct accounting of the amount of
        // liquidity available for borrows.

        uint totalLoans = pool.loans[0].add(pool.loans[1]).add(pool.loans[2]);
        totalPrincipal = (poolLoss <= totalPrincipal) ? totalPrincipal.sub(poolLoss) : 0;
        totalLoans = (poolLoss <= totalLoans) ? totalLoans.sub(poolLoss) : 0;

        for (uint i = 0; i < pool.loans.length; i++) {
            pool.loans[i] = totalPrincipal == 0 ? 0 : totalLoans.mul(pool.principals[i]).div(totalPrincipal);
        }
    }

    /// @notice Add collateral token to position. Must be called during execution.
    /// @param posId Position id
    /// @param collAmt The amount of the collateral token from 3rd party pool.
    function addCollToken(uint posId, uint collAmt)
        external override inExecution {
        Position storage pos = positionMap[CURR_POSITION_ID];
        require(pos.id == posId, "addCollTk bad pos");

        pos.collAmt = collAmt;
    }

    function getEarnedInterest( address token, address owner, Tranche tranche ) external view returns (uint256) {
        Pool storage pool = poolMap[token];
        require(pool.isExists, 'gtErndIr no pool');
        Stake memory stk = getStake(token, owner)[uint(tranche)];
        return _scaleByLossMultiplier(
            stk,
            stk.earnedInterest.add(
                stk.principal.mul(
                    pool.sumIpp[uint(tranche)].sub(stk.sumIppStart)
                ).div(MULTIPLIER))
        );
    }

    /// -------------------------------------------------------------------
    /// functions to adapter
    function beforeExecution( uint posId, IAdapter adapter ) internal {
        require(POOL_LOCK == NOT_LOCKED, 'pol lck');
        POOL_LOCK = LOCKED;
        address adapterAddr = address(adapter);
        require(adapterMap[adapterAddr], 'no adpr');

        if (posId == 0) {
            // create a new position
            posId = POSITION_COUNTER++;
            positionMap[posId].id = posId;
            positionMap[posId].owner = msg.sender;
            positionMap[posId].adapter = adapterAddr;
        } else {
            require(posId < POSITION_COUNTER, 'no pos');
            require(positionMap[posId].status == PositionStatus.Open, 'only open pos');
        }

        CURR_POSITION_ID = posId;
        CURR_ADAPTER = adapterAddr;
        CURR_SENDER = msg.sender;
    }

    function afterExecution() internal {
        CURR_POSITION_ID = INVALID_POSITION_ID;
        CURR_ADAPTER = INVALID_ADAPTER;
        POOL_LOCK = NOT_LOCKED;
        CURR_SENDER = address(0);
    }

    function openPosition( uint posId, IAdapter adapter, address baseToken, address collToken, uint baseAmt, uint borrowAmt ) external {
        uint balance = IERC20(nut).balanceOf(msg.sender);
        require(minNut4Borrowers[baseToken][address(adapter)] <= balance, 'NUT low');
        beforeExecution(posId, adapter);
        adapter.openPosition( baseToken, collToken, baseAmt, borrowAmt );
        afterExecution();
    }

    function closePosition( uint posId, IAdapter adapter ) external returns (uint) {
        beforeExecution(posId, adapter);
        uint redeemAmt = adapter.closePosition();
        afterExecution();
        return redeemAmt;
    }

    function liquidatePosition( uint posId, IAdapter adapter ) external {
        beforeExecution(posId, adapter);
        adapter.liquidate();
        afterExecution();
    }

    function settleCreditEvent( IAdapter adapter, address baseToken, uint collateralLoss, uint poolLoss ) onlyGov external {
        beforeExecution(0, adapter);
        adapter.settleCreditEvent( baseToken, collateralLoss, poolLoss );
        afterExecution();
    }

    function getMaxUnstakePrincipal(address token, address owner, uint tranche) external view returns (uint) {
        Stake memory stk = stakeMap[token][owner][tranche];
        return _getWithdrawAmount(poolMap[stk.pool], stk.principal);
    }
}

File 3 of 21 : Governable.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

import "@openzeppelin/contracts/proxy/Initializable.sol";
contract Governable is Initializable {
  address public governor;
  address public pendingGovernor;

  modifier onlyGov() {
    require(msg.sender == governor, 'bad gov');
    _;
  }

  function __Governable__init() internal initializer {
    governor = msg.sender;
  }

  function __Governable__init(address _governor) internal initializer {
    governor = _governor;
  }

  /// @dev Set the pending governor, which will be the governor once accepted.
  /// @param addr The address of the pending governor.
  function setPendingGovernor(address addr) external onlyGov {
    pendingGovernor = addr;
  }

  /// @dev Accept to become the new governor. Must be called by the pending governor.
  function acceptGovernor() external {
    require(msg.sender == pendingGovernor, 'no pend');
    pendingGovernor = address(0);
    governor = msg.sender;
  }
}

File 4 of 21 : Math.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

import "@openzeppelin/contracts/math/SafeMath.sol";

library Math {
    using SafeMath for uint;

    function sumOf3UintArray(uint[3] memory data) internal pure returns(uint) {
        return data[0].add(data[1]).add(data[2]);
    }
}

File 5 of 21 : IAdapter.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

interface IAdapter {
    function openPosition( address baseToken, address collToken, uint collAmount, uint borrowAmount ) external;
    function closePosition() external returns (uint);
    function liquidate() external;
    function settleCreditEvent(
        address baseToken, uint collateralLoss, uint poolLoss) external;

    event openPositionEvent(uint positionId, address caller, uint baseAmt, uint borrowAmount);
    event closePositionEvent(uint positionId, address caller, uint amount);
    event liquidateEvent(uint positionId, address caller);
    event creditEvent(address token, uint collateralLoss, uint poolLoss);
}

File 6 of 21 : INutmeg.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

interface INutmeg {
    enum Tranche {AA, A, BBB}
    enum StakeStatus {Uninitialized, Open, Closed, Settled}
    enum PositionStatus {Uninitialized, Open, Closed, Liquidated, Settled}

    struct Pool {
        bool isExists;
        address baseToken; // base token of this pool, e.g., WETH, DAI.
        uint[3] interestRates; // interest rate per block of each tranche. supposed to be updated everyday.
        uint[3] principals; // principals of each tranche, from lenders
        uint[3] loans; // loans of each tranche, from borrowers.
        uint[3] interests; // interests accrued from loans for each tranche.

        uint totalCollateral; // total collaterals in base token from borrowers.
        uint latestAccruedBlock; // the block number of the latest interest accrual action.
        uint sumRtb; // sum of interest rate per block (after adjustment) times # of blocks
        uint irAdjustPct; // interest rate adjustment in percentage, e.g., 1, 99.
        bool isIrAdjustPctNegative; // whether interestRateAdjustPct is negative
        uint[3] sumIpp; // sum of interest per principal.
        uint[3] lossMultiplier;
        uint[3] lossZeroCounter;
    }

    struct Stake {
        uint id;
        StakeStatus status;
        address owner;
        address pool;
        uint tranche; // tranche of the pool, 0 - AA, 1 - A, 2 - BBB.
        uint principal;
        uint sumIppStart;
        uint earnedInterest;
        uint lossMultiplierBase;
        uint lossZeroCounterBase;
    }

    struct Position {
        uint id; // id of the position.
        PositionStatus status; // status of the position, Open, Close, and Liquidated.
        address owner; // borrower's address
        address adapter; // adapter's address
        address baseToken; // base token that the borrower borrows from the pool
        address collToken; // collateral token that the borrower got from 3rd party pool.
        uint[3] loans; // loans of all tranches
        uint baseAmt; // amount of the base token the borrower put into pool as the collateral.
        uint collAmt; // amount of collateral token the borrower got from 3rd party pool.
        uint borrowAmt; // amount of base tokens borrowed from the pool.
        uint sumRtbStart; // rate times block when the position is created.
        uint repayDeficit; // repay pool loss
    }

    struct NutDist {
        uint endBlock;
        uint amount;
    }

    /// @dev Get all stake IDs of a lender
    function getStakeIds(address lender) external view returns (uint[] memory);

    /// @dev Get all position IDs of a borrower
    function getPositionIds(address borrower) external view returns (uint[] memory);

    /// @dev Get the maximum available borrow amount
    function getMaxBorrowAmount(address token, uint collAmount) external view returns(uint);

    /// @dev Get the current position while under execution.
    function getCurrPositionId() external view returns (uint);

    /// @dev Get the next position ID while under execution.
    function getNextPositionId() external view returns (uint);

    /// @dev Get the current sender while under execution
    function getCurrSender() external view returns (address);

    function getPosition(uint id) external view returns (Position memory);

    function getPositionInterest(address token, uint positionId) external view returns(uint);

    function getPoolInfo(address token) external view returns(uint, uint, uint);

    /// @dev Add Collateral token from the 3rd party pool to a position
    function addCollToken(uint posId, uint collAmt) external;

    /// @dev Borrow tokens from the pool.
    function borrow(address token, address collAddr, uint baseAmount, uint borrowAmount) external;

    /// @dev Repays tokens to the pool.
    function repay(address token, uint repayAmount) external;

    /// @dev Liquidate a position when conditions are satisfied
    function liquidate(address token, uint repayAmount) external;

    /// @dev Settle credit event
    function distributeCreditLosses( address baseToken, uint collateralLoss, uint poolLoss) external;
    event addPoolEvent(address bank, uint interestRateA);
    event stakeEvent(address bank, address owner, uint tranche, uint amount, uint depId);
    event unstakeEvent(address bank, address owner, uint tranche, uint amount, uint depId);
}

File 7 of 21 : INutDistributor.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

interface INutDistributor {
    function updateVtb(address token, address lender, uint incAmount, uint decAmount) external;
    function inNutDistribution() external view returns(bool);
}

File 8 of 21 : IPriceOracle.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

interface IPriceOracle {
    function getPrice(address token) external view returns (uint);
}

File 9 of 21 : NutDistributor.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "./interfaces/INutDistributor.sol";
import "./interfaces/INut.sol";
import "./interfaces/IPriceOracle.sol";
import "./lib/Governable.sol";

/*
This contract distributes nut tokens based on staking unstaking during
the staking period.  It generates an array of "value times blocks" for
each token/lender pair and "total value times block" for each token.
It then distributes the rewards across the array.

One issue is that each unstake/stake requires a calculation to
determine the fraction of the pool owned by a lender.  To avoid having
to loop across all epochs and use up gas, this algorithm relies on the
fact that all future epochs have the same value.  So the vtb and
totalVtb arrays keep an index of the last epoch in which there was a
partial stake and unstake of tokens and then the epochs beyond that
all of the same value which is stored in futureVtbMap and
futureTotalVtbMap.
*/

contract NutDistributor is Governable, INutDistributor {
    using SafeMath for uint;
    using SafeERC20 for IERC20;

    struct Echo {
        uint id;
        uint endBlock;
        uint amount;
    }

    address public nutmeg;
    address public nut;
    address public oracle;

    uint public constant MAX_NUM_POOLS = 256;
    uint public DIST_START_BLOCK; // starting block of echo 0
    uint public constant NUM_EPOCH = 15; // # of epochs
    uint public BLOCKS_PER_EPOCH; // # of blocks per epoch
    uint public constant DIST_START_AMOUNT = 250000 ether; // # of tokens distributed at epoch 0
    uint public constant DIST_MIN_AMOUNT = 18750 ether; // min # of tokens distributed at any epoch

    uint public CURRENT_EPOCH;
    mapping(address => bool) addedPoolMap;
    address[] public pools;
    mapping(uint => Echo) public echoMap;
    mapping(uint => bool) public distCompletionMap;

    // the term vtb is short for value times blocks
    mapping(address => uint[15]) public totalVtbMap; // pool => total vtb, i.e., valueTimesBlocks.
    mapping(address => uint[15]) public totalNutMap; // pool => total Nut awarded.
    mapping(address => mapping( address => uint[15] ) ) public vtbMap; // pool => lender => vtb.

    mapping(address => uint) futureTotalVtbMap;
    mapping(address => mapping( address => uint) ) futureVtbMap;
    mapping(address => uint) futureTotalVtbEpoch;
    mapping(address => mapping( address => uint) ) futureVtbEpoch;

    modifier onlyNutmeg() {
        require(msg.sender == nutmeg, 'only nutmeg can call');
        _;
    }

    /// @dev Set the Nutmeg
    function setNutmegAddress(address addr) external onlyGov {
        nutmeg = addr;
    }

    /// @dev Set the oracle
    function setPriceOracle(address addr) external onlyGov {
        oracle = addr;
    }

    function initialize(address nutAddr, address _governor) public initializer{
        nut = nutAddr;
        DIST_START_BLOCK = block.number;
        BLOCKS_PER_EPOCH = 80640;
         __Governable__init(_governor);

        // config echoMap which indicates how many tokens will be distributed at each epoch
        for (uint i = 0; i < NUM_EPOCH; i++) {
            Echo storage echo =  echoMap[i];
            echo.id = i;
            echo.endBlock = DIST_START_BLOCK.add(BLOCKS_PER_EPOCH.mul(i.add(1)));
            uint amount = DIST_START_AMOUNT.div(i.add(1));
            if (amount < DIST_MIN_AMOUNT) {
                amount = DIST_MIN_AMOUNT;
            }
            echo.amount = amount;
        }
    }


    function inNutDistribution() external override view returns(bool) {
        return (block.number >= DIST_START_BLOCK && block.number < DIST_START_BLOCK.add(BLOCKS_PER_EPOCH.mul(NUM_EPOCH)));
    }

    /// @notice Update valueTimesBlocks of pools and the lender when they stake or unstake
    /// @param token Base token of the pool.
    /// @param lender Address of the lender.
    /// @param incAmount to stake or unstake
    /// @param decAmount false=subtract/unstake true=add/stake
    function updateVtb(address token, address lender, uint incAmount, uint decAmount) external override onlyNutmeg {
        require(block.number >= DIST_START_BLOCK, 'updateVtb: invalid block number');
        require(incAmount == 0 || decAmount == 0, 'updateVtb: update amount is invalid');

        uint amount = incAmount.add(decAmount);
        require(amount > 0, 'updateVtb: update amount should be positive');

        // get current epoch
        CURRENT_EPOCH = (block.number.sub(DIST_START_BLOCK)).div(BLOCKS_PER_EPOCH);
        if (CURRENT_EPOCH >= NUM_EPOCH) return;

        _fillVtbGap(token, lender);
        _fillTotalVtbGap(token);

        uint dv = echoMap[CURRENT_EPOCH].endBlock.sub( block.number ).mul(amount);
        uint epochDv = BLOCKS_PER_EPOCH.mul(amount);

        if (incAmount > 0) {
            vtbMap[token][lender][CURRENT_EPOCH] = vtbMap[token][lender][CURRENT_EPOCH].add(dv);
            totalVtbMap[token][CURRENT_EPOCH] = totalVtbMap[token][CURRENT_EPOCH].add(dv);
            futureVtbMap[token][lender] = futureVtbMap[token][lender].add(epochDv);
            futureTotalVtbMap[token] = futureTotalVtbMap[token].add(epochDv);
        } else {
            vtbMap[token][lender][CURRENT_EPOCH] = vtbMap[token][lender][CURRENT_EPOCH].sub(dv);
            totalVtbMap[token][CURRENT_EPOCH] = totalVtbMap[token][CURRENT_EPOCH].sub(dv);
            futureVtbMap[token][lender] = futureVtbMap[token][lender].sub(epochDv);
            futureTotalVtbMap[token] = futureTotalVtbMap[token].sub(epochDv);
        }

        if (!addedPoolMap[token]) {
            pools.push(token);
            addedPoolMap[token] = true;
        }
    }
    // @dev This function fills the array between the last epoch at which things were calculated and the current epoch.
    function _fillVtbGap(address token, address lender) internal {
        if (futureVtbEpoch[token][lender] > CURRENT_EPOCH || CURRENT_EPOCH >= NUM_EPOCH ) return;
        uint futureVtb = futureVtbMap[token][lender];
        for (uint i = futureVtbEpoch[token][lender]; i <= CURRENT_EPOCH; i++) {
            vtbMap[token][lender][i] = futureVtb;
        }
        futureVtbEpoch[token][lender] = CURRENT_EPOCH.add(1);
    }

    // @dev This function fills the array between the last epoch at which things were calculated and the current epoch.
    function _fillTotalVtbGap(address token) internal {
        if (futureTotalVtbEpoch[token] > CURRENT_EPOCH || CURRENT_EPOCH >= NUM_EPOCH ) return;
        uint futureTotalVtb = futureTotalVtbMap[token];
        for (uint i = futureTotalVtbEpoch[token]; i <= CURRENT_EPOCH; i++) {
            totalVtbMap[token][i] = futureTotalVtb;
        }
        futureTotalVtbEpoch[token] = CURRENT_EPOCH.add(1);
    }

    /// @dev Distribute NUT tokens for the previous epoch
    function distribute() external onlyGov {
        require(oracle != address(0), 'distribute: no oracle available');

        // get current epoch
        uint currEpochId = (block.number.sub(DIST_START_BLOCK)).div(BLOCKS_PER_EPOCH);
        require(currEpochId > 0, 'distribute: nut token distribution not ready');
        require(currEpochId < NUM_EPOCH.add(1), 'distribute: nut token distribution is over');

        // distribute the nut tokens for the previous epoch.
        uint prevEpochId = currEpochId.sub(1);
        require(!distCompletionMap[prevEpochId], 'distribute: distribution is completed');

        // mint nut tokens
        uint amount = echoMap[prevEpochId].amount;
        INut(nut).mint(address(this), amount);

        uint numOfPools = pools.length < MAX_NUM_POOLS ? pools.length : MAX_NUM_POOLS;
        uint sumOfDv;
        uint actualSumOfNut;
        for (uint i = 0; i < numOfPools; i++) {
            uint price = IPriceOracle(oracle).getPrice(pools[i]);
            uint dv = price.mul(getTotalVtb(pools[i],prevEpochId));
            sumOfDv = sumOfDv.add(dv);
        }

        if (sumOfDv > 0) {
            for (uint i = 0; i < numOfPools; i++) {
                uint price = IPriceOracle(oracle).getPrice(pools[i]);
                uint dv = price.mul(getTotalVtb(pools[i], prevEpochId));
                uint nutAmount = dv.mul(amount).div(sumOfDv);
                actualSumOfNut = actualSumOfNut.add(nutAmount);
                totalNutMap[pools[i]][prevEpochId] = nutAmount;
            }
        }

        require(actualSumOfNut <= amount, "distribute: overflow");

        distCompletionMap[prevEpochId] = true;
    }

    /// @dev Collect Nut tokens
    function collect() external  {
        uint epochId = (block.number.sub(DIST_START_BLOCK)).div(BLOCKS_PER_EPOCH);
        require(epochId > 0, 'collect: distribution is completed');

        address lender = msg.sender;

        uint numOfPools = pools.length < MAX_NUM_POOLS ? pools.length : MAX_NUM_POOLS;
        uint totalAmount;
        for (uint i = 0; i < numOfPools; i++) {
            address pool = pools[i];
            for (uint j = 0; j < epochId && j < NUM_EPOCH; j++) {
                uint vtb = getVtb(pool, lender, j);
                if (vtb > 0 && getTotalVtb(pool, j) > 0) {
                    uint amount = vtb.mul(totalNutMap[pool][j]).div(getTotalVtb(pool, j));
                    totalAmount = totalAmount.add(amount);
                    vtbMap[pool][lender][j] = 0;
                }
            }
        }

        if (totalAmount > 0) {
            require(
                IERC20(nut).approve(address(this), 0),
                'distributor approve failed'
            );
            require(
                IERC20(nut).approve(address(this), totalAmount),
                'NutDist approve amount failed'
            );
            require(
                IERC20(nut).transferFrom(address(this), lender, totalAmount),
                'NutDist transfer failed'
            );
        }
    }

    /// @dev getCollectionAmount get the # of NUT tokens for collection
    function getCollectionAmount() external view returns(uint) {
        uint epochId = (block.number.sub(DIST_START_BLOCK)).div(BLOCKS_PER_EPOCH);
        require(epochId > 0, 'getCollectionAmount: distribution is completed');

        address lender = msg.sender;

        uint numOfPools = pools.length < MAX_NUM_POOLS ? pools.length : MAX_NUM_POOLS;
        uint totalAmount;
        for (uint i = 0; i < numOfPools; i++) {
            address pool = pools[i];
            for (uint j = 0; j < epochId && j < NUM_EPOCH; j++) {
                uint vtb = getVtb(pool, lender, j);
                if (vtb > 0 && getTotalVtb(pool, j) > 0) {
                    uint amount = vtb.mul(totalNutMap[pool][j]).div(getTotalVtb(pool, j));
                    totalAmount = totalAmount.add(amount);
                }
            }
        }

        return totalAmount;
    }

    function getVtb(address pool, address lender, uint i) public view returns(uint) {
        require(i < NUM_EPOCH, 'vtb idx err');
        return i < futureVtbEpoch[pool][lender] ?
            vtbMap[pool][lender][i] : futureVtbMap[pool][lender];
    }
    function getTotalVtb(address pool, uint i) public view returns (uint) {
        require(i < NUM_EPOCH, 'totalVtb idx err');
        return i < futureTotalVtbEpoch[pool] ?
            totalVtbMap[pool][i] : futureTotalVtbMap[pool];
    }

    //@notice output version string
    function getVersionString()
    external virtual pure returns (string memory) {
        return "1";
   }
}

File 10 of 21 : INut.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

interface INut {
    function mint(address receipt, uint amount) external;
}

File 11 of 21 : MockERC20.sol
// SPDX-License-Identifier: MIT
// Mock ERC20 token for testing

pragma solidity 0.7.6;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MockERC20 is ERC20 {
  constructor(
    string memory name,
    string memory symbol,
    uint8 decimals
  ) ERC20(name, symbol) {
    _setupDecimals(decimals);
  }

  function mint(address to, uint amount) external {
    _mint(to, amount);
  }
}

File 12 of 21 : MockCERC20.sol
// SPDX-License-Identifier: MIT
// Mock ERC20 token for testing

pragma solidity 0.7.6;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "../interfaces/ICERC20.sol";

contract MockCERC20Base is ICERC20, ERC20 {
    address public immutable token;
    using SafeERC20 for IERC20;
    using SafeMath for uint;

    uint private constant MULTIPLIER = 10**18;
    uint public exchangeRate;
    bool public returnError;
    constructor(
        address tokenAddr,
        string memory name_, string memory symbol_, uint8 decimals_)
    ERC20(name_, symbol_) {
        token = tokenAddr;
        exchangeRate = MULTIPLIER;
        returnError = false;
        _setupDecimals(decimals_);
    }

    function mint(uint amount) external override returns (uint) {
        if (returnError) return 1;
        IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
        _mint(msg.sender, amount.mul(MULTIPLIER).div(exchangeRate));
        return 0;
    }
    function redeem(uint amount) external override returns (uint) {
        if (returnError) return 1;
        IERC20(token).safeTransfer(
            msg.sender, amount.mul(exchangeRate).div(MULTIPLIER)
        );
        _burn(msg.sender, amount);
        return 0;
    }
    function redeemUnderlying(uint amount) external override returns (uint) {
        if (returnError) return 1;
        IERC20(token).safeTransfer(msg.sender, amount);
        _burn(
            msg.sender, amount.mul(MULTIPLIER).div(exchangeRate)
        );
        return 0;
    }
    function exchangeRateCurrent() external view override returns (uint) {
        return exchangeRate;
    }
    function supplyRatePerBlock() external pure override returns (uint) {
        return 0;
    }
    function balanceOf(address account) public override(ERC20, ICERC20) view returns (uint) {
        return ERC20.balanceOf(account);
    }
    function approve(address account, uint amount) public override(ERC20, ICERC20) returns (bool) {
        return ERC20.approve(account, amount);
    }
    function transfer(address dst, uint amount) public override(ERC20, ICERC20) returns (bool) {
        return ERC20.transfer(dst, amount);
    }

    function setExchangeRate(uint e) external {
        exchangeRate = e;
    }
    function setError(bool b) external {
        returnError = b;
    }
}

contract MockCERC20 is MockCERC20Base {
    constructor(address tokenAddr) MockCERC20Base(
        tokenAddr, "MockCERC20", "MCERC20", 18
    ) {
    }
}

File 13 of 21 : ICERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;

interface ICERC20 {
    function mint(uint) external returns (uint);
    function redeem(uint) external returns (uint);
    function transfer(address dst, uint amount) external returns (bool);
    function balanceOf(address) external view returns (uint);
    function redeemUnderlying(uint) external returns (uint);
    function exchangeRateCurrent() external returns (uint);
    function supplyRatePerBlock() external returns (uint);
    function approve(address spender, uint amount) external returns (bool);
}

File 14 of 21 : CompoundAdapter.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "../interfaces/ICERC20.sol";
import "../interfaces/IAdapter.sol";
import "../interfaces/INutmeg.sol";
import "../lib/Governable.sol";
import "../lib/Math.sol";

contract CompoundAdapter is Governable, IAdapter {
    using SafeERC20 for IERC20;
    using SafeMath for uint;

    struct PosInfo {
        uint posId;
        uint collAmt;
        uint sumIpcStart;
    }

    INutmeg public immutable nutmeg;

    uint private constant MULTIPLIER = 10**18;

    address[] public baseTokens; // array of base tokens
    mapping(address => bool) public baseTokenMap; // e.g., Dai
    mapping(address => address) public tokenPairs; // Dai -> cDai or cDai -> Dai;
    mapping(address => uint) public totalMintAmt;
    mapping(address => uint) public sumIpcMap;
    mapping(uint => PosInfo) public posInfoMap;

    mapping(address => uint) public totalLoan;
    mapping(address => uint) public totalCollateral;
    mapping(address => uint) public totalLoss;

    constructor(INutmeg nutmegAddr) {
        nutmeg = nutmegAddr;
        __Governable__init();
    }

    modifier onlyNutmeg() {
        require(msg.sender == address(nutmeg), 'only nutmeg can call');
        _;
    }

    /// @dev Add baseToken collToken pairs
    function addTokenPair(address baseToken, address collToken) external onlyGov {
        baseTokenMap[baseToken] = true;
        tokenPairs[baseToken] = collToken;
        baseTokens.push(baseToken);
    }

    /// @dev Remove baseToken collToken pairs
    function removeTokenPair(address baseToken) external onlyGov {
        baseTokenMap[baseToken] = false;
        tokenPairs[baseToken] = address(0);
    }

    /// @notice Open a position.
    /// @param baseToken Base token of the position.
    /// @param collToken Collateral token of the position.
    /// @param baseAmt Amount of collateral in base token.
    /// @param borrowAmt Amount of base token to be borrowed from nutmeg.
    function openPosition(address baseToken, address collToken, uint baseAmt, uint borrowAmt)
        external onlyNutmeg override {
        require(baseAmt > 0, 'openPosition: invalid base amount');
        require(baseTokenMap[baseToken], 'openPosition: invalid baseToken address');
        require(tokenPairs[baseToken] == collToken, 'openPosition: invalid cToken address');

        uint posId = nutmeg.getCurrPositionId();
        INutmeg.Position memory pos = nutmeg.getPosition(posId);
        require(nutmeg.getCurrSender() == pos.owner, 'openPosition: only owner can initialize this call');
        require(IERC20(baseToken).balanceOf(pos.owner) >= baseAmt, 'openPosition: insufficient balance');

        // check borrowAmt
        uint maxBorrowAmt = nutmeg.getMaxBorrowAmount(baseToken, baseAmt);
        require(borrowAmt <= maxBorrowAmt, "openPosition: borrowAmt exceeds maximum");
        require(borrowAmt > baseAmt, "openPosition: borrowAmt is less than collateral");

        // borrow base tokens from nutmeg
        nutmeg.borrow(baseToken, collToken, baseAmt, borrowAmt);

        _increaseDebtAndCollateral(baseToken, posId);

        // mint collateral tokens from compound
        pos = nutmeg.getPosition(posId);
        (uint result, uint mintAmt) = _doMint(pos, borrowAmt);
        require(result == 0, 'opnPos: _doMint fail');
        if (mintAmt > 0) {
            uint currSumIpc = _calcLatestSumIpc(collToken);
            totalMintAmt[collToken] = totalMintAmt[collToken].add(mintAmt);
            PosInfo storage posInfo = posInfoMap[posId];
            posInfo.sumIpcStart = currSumIpc;
            posInfo.collAmt = mintAmt;

            // add mintAmt to the position in nutmeg.
            nutmeg.addCollToken(posId, mintAmt);
        }
        emit openPositionEvent(posId, nutmeg.getCurrSender(), baseAmt, borrowAmt);
    }

    /// @notice Close a position by the borrower
    function closePosition() external onlyNutmeg override returns (uint) {
        uint posId = nutmeg.getCurrPositionId();
        INutmeg.Position memory pos = nutmeg.getPosition(posId);
        require(pos.owner == nutmeg.getCurrSender(), 'closePosition: original caller is not the owner');

        uint collAmt = _getCollTokenAmount(pos);
        (uint result, uint redeemAmt) = _doRedeem(pos, collAmt);
        require(result == 0, 'clsPos: rdm fail');

        // allow nutmeg to receive redeemAmt from the adapter
        IERC20(pos.baseToken).safeApprove(address(nutmeg), 0);
        IERC20(pos.baseToken).safeApprove(address(nutmeg), redeemAmt);

        // repay to nutmeg
        _decreaseDebtAndCollateral(pos.baseToken, pos.id, redeemAmt);
        nutmeg.repay(pos.baseToken, redeemAmt);
        pos = nutmeg.getPosition(posId);
        totalLoss[pos.baseToken] =
            totalLoss[pos.baseToken].add(pos.repayDeficit);
        totalMintAmt[pos.collToken] = totalMintAmt[pos.collToken].sub(pos.collAmt);
        emit closePositionEvent(posId, nutmeg.getCurrSender(), redeemAmt);
        return redeemAmt;
    }

    /// @notice Liquidate a position
    function liquidate() external override onlyNutmeg  {
        uint posId = nutmeg.getCurrPositionId();
        INutmeg.Position memory pos = nutmeg.getPosition(posId);
        require(_okToLiquidate(pos), 'liquidate: position is not ready for liquidation yet.');

        uint amount = _getCollTokenAmount(pos);
        (uint result, uint redeemAmt) = _doRedeem(pos, amount);
        require(result == 0, 'lqdte: rdm fail');
        IERC20(pos.baseToken).safeApprove(address(nutmeg), 0);
        IERC20(pos.baseToken).safeApprove(address(nutmeg), redeemAmt);

        // liquidate the position in nutmeg.
        _decreaseDebtAndCollateral(pos.baseToken, posId, redeemAmt);
        nutmeg.liquidate(pos.baseToken, redeemAmt);
        pos = nutmeg.getPosition(posId);
        totalLoss[pos.baseToken] = totalLoss[pos.baseToken].add(pos.repayDeficit);
        totalMintAmt[pos.collToken] = totalMintAmt[pos.collToken].sub(pos.collAmt);
        emit liquidateEvent(posId, nutmeg.getCurrSender());
    }
    /// @notice Get value of credit tokens
    function creditTokenValue(address baseToken) public returns (uint) {
        address collToken = tokenPairs[baseToken];
        require(collToken != address(0), "settleCreditEvent: invalid collateral token" );
        uint collTokenBal = ICERC20(collToken).balanceOf(address(this));
        return collTokenBal.mul(ICERC20(collToken).exchangeRateCurrent());
    }

    /// @notice Settle credit event
    /// @param baseToken The base token address
    function settleCreditEvent( address baseToken, uint collateralLoss, uint poolLoss) external override onlyNutmeg {
        require(baseTokenMap[baseToken] , "settleCreditEvent: invalid base token" );
        require(collateralLoss <= totalCollateral[baseToken], "settleCreditEvent: invalid collateral" );
        require(poolLoss <= totalLoan[baseToken], "settleCreditEvent: invalid poolLoss" );

        nutmeg.distributeCreditLosses(baseToken, collateralLoss, poolLoss);

        emit creditEvent(baseToken, collateralLoss, poolLoss);
        totalLoss[baseToken] = 0;
        totalLoan[baseToken] = totalLoan[baseToken].sub(poolLoss);
        totalCollateral[baseToken] = totalCollateral[baseToken].sub(collateralLoss);
    }

    function _increaseDebtAndCollateral(address token, uint posId) internal {
        INutmeg.Position memory pos = nutmeg.getPosition(posId);
        for (uint i = 0; i < 3; i++) {
            totalLoan[token] = totalLoan[token].add(pos.loans[i]);
        }
        totalCollateral[token] = totalCollateral[token].add(pos.baseAmt);
    }

    /// @dev decreaseDebtAndCollateral
    function _decreaseDebtAndCollateral(address token, uint posId, uint redeemAmt) internal {
        INutmeg.Position memory pos = nutmeg.getPosition(posId);
        uint totalLoans = pos.loans[0] + pos.loans[1] + pos.loans[2];
        if (redeemAmt >= totalLoans) {
            totalLoan[token] = totalLoan[token].sub(totalLoans);
        } else {
            totalLoan[token] = totalLoan[token].sub(redeemAmt);
        }
        totalCollateral[token] = totalCollateral[token].sub(pos.baseAmt);
    }

    /// @dev Do the mint from the 3rd party pool.this
    function _doMint(INutmeg.Position memory pos, uint amount) internal returns(uint, uint) {
        uint balBefore = ICERC20(pos.collToken).balanceOf(address(this));
        require(IERC20(pos.baseToken).approve(pos.collToken, 0), '_doMint approve error');
        require(IERC20(pos.baseToken).approve(pos.collToken, amount), '_doMint approve amount error');
        uint result = ICERC20(pos.collToken).mint(amount);
        require(result == 0, '_doMint mint error');
        uint balAfter = ICERC20(pos.collToken).balanceOf(address(this));
        uint mintAmount = balAfter.sub(balBefore);
        return (result, mintAmount);
    }

    /// @dev Do the redeem from the 3rd party pool.
    function _doRedeem(INutmeg.Position memory pos, uint amount) internal returns(uint, uint) {
        uint balBefore = IERC20(pos.baseToken).balanceOf(address(this));
        uint result = ICERC20(pos.collToken).redeem(amount);
        uint balAfter = IERC20(pos.baseToken).balanceOf(address(this));
        uint redeemAmt = balAfter.sub(balBefore);
        return (result, redeemAmt);
    }

    /// @dev Get the amount of collToken a position.
    function _getCollTokenAmount(INutmeg.Position memory pos) internal returns(uint) {
        uint currSumIpc = _calcLatestSumIpc(pos.collToken);
        PosInfo storage posInfo = posInfoMap[pos.id];
        uint interest = posInfo.collAmt.mul(currSumIpc.sub(posInfo.sumIpcStart)).div(MULTIPLIER);
        return posInfo.collAmt.add(interest);
    }

    /// @dev Calculate the latest sumIpc.
    /// @param collToken The cToken.
    function _calcLatestSumIpc(address collToken) internal returns(uint) {
        uint balance = ICERC20(collToken).balanceOf(address(this));
        uint mintBalance = totalMintAmt[collToken];
        uint interest = mintBalance > balance ? mintBalance.sub(balance) : 0;
        uint currIpc = (mintBalance == 0) ? 0 : (interest.mul(MULTIPLIER)).div(mintBalance);
        if (currIpc > 0){
            sumIpcMap[collToken] = sumIpcMap[collToken].add(currIpc);
        }
        return sumIpcMap[collToken];
    }

    /// @dev Check if the position is eligible to be liquidated.
    function _okToLiquidate(INutmeg.Position memory pos) internal view returns(bool) {
        bool ok = false;
        uint interest = nutmeg.getPositionInterest(pos.baseToken, pos.id);
        if (interest.mul(2) >= pos.baseAmt) {
            ok = true;
        }
        return ok;
    }

}

File 15 of 21 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using SafeMath for uint256;
    using Address for address;

    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        // solhint-disable-next-line max-line-length
        require((value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).add(value);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) { // Return data is optional
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 16 of 21 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

File 17 of 21 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b > a) return (false, 0);
        return (true, a - b);
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) return (true, 0);
        uint256 c = a * b;
        if (c / a != b) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a / b);
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a % b);
    }

    /**
     * @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");
        return a - b;
    }

    /**
     * @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) {
        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, reverting 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) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: modulo by zero");
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        return a - b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a % b;
    }
}

File 18 of 21 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain`call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
      return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: value }(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 19 of 21 : Initializable.sol
// SPDX-License-Identifier: MIT

// solhint-disable-next-line compiler-version
pragma solidity >=0.4.24 <0.8.0;

import "../utils/Address.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 */
abstract contract Initializable {

    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /// @dev Returns true if and only if the function is running in the constructor
    function _isConstructor() private view returns (bool) {
        return !Address.isContract(address(this));
    }
}

File 20 of 21 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../utils/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin guidelines: functions revert instead
 * of returning `false` on failure. This behavior is nonetheless conventional
 * and does not conflict with the expectations of ERC20 applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20 {
    using SafeMath for uint256;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    constructor (string memory name_, string memory symbol_) public {
        _name = name_;
        _symbol = symbol_;
        _decimals = 18;
    }

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

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

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

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    /**
     * @dev Moves tokens `amount` from `sender` to `recipient`.
     *
     * This is internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Sets {decimals} to a value other than the default one of 18.
     *
     * WARNING: This function should only be called from the constructor. Most
     * applications that interact with token contracts will not expect
     * {decimals} to ever change, and may work incorrectly if it does.
     */
    function _setupDecimals(uint8 decimals_) internal virtual {
        _decimals = decimals_;
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be to transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}

File 21 of 21 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

Settings
{
  "metadata": {
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  }
}

Contract ABI

[{"inputs":[{"internalType":"contract INutmeg","name":"nutmegAddr","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"closePositionEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralLoss","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"poolLoss","type":"uint256"}],"name":"creditEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"}],"name":"liquidateEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"baseAmt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"borrowAmount","type":"uint256"}],"name":"openPositionEvent","type":"event"},{"inputs":[],"name":"acceptGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"baseToken","type":"address"},{"internalType":"address","name":"collToken","type":"address"}],"name":"addTokenPair","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"baseTokenMap","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"baseTokens","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"closePosition","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"baseToken","type":"address"}],"name":"creditTokenValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"governor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nutmeg","outputs":[{"internalType":"contract INutmeg","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"baseToken","type":"address"},{"internalType":"address","name":"collToken","type":"address"},{"internalType":"uint256","name":"baseAmt","type":"uint256"},{"internalType":"uint256","name":"borrowAmt","type":"uint256"}],"name":"openPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pendingGovernor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"posInfoMap","outputs":[{"internalType":"uint256","name":"posId","type":"uint256"},{"internalType":"uint256","name":"collAmt","type":"uint256"},{"internalType":"uint256","name":"sumIpcStart","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"baseToken","type":"address"}],"name":"removeTokenPair","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setPendingGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"baseToken","type":"address"},{"internalType":"uint256","name":"collateralLoss","type":"uint256"},{"internalType":"uint256","name":"poolLoss","type":"uint256"}],"name":"settleCreditEvent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"sumIpcMap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"tokenPairs","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"totalCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"totalLoan","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"totalLoss","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"totalMintAmt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

60a06040523480156200001157600080fd5b50604051620036ae380380620036ae833981016040819052620000349162000140565b6001600160601b0319606082901b16608052806200005162000059565b505062000170565b600054610100900460ff1680620000755750620000756200011c565b8062000084575060005460ff16155b620000c15760405162461bcd60e51b815260040180806020018281038252602e81526020018062003680602e913960400191505060405180910390fd5b600054610100900460ff16158015620000ed576000805460ff1961ff0019909116610100171660011790555b6000805462010000600160b01b031916336201000002179055801562000119576000805461ff00191690555b50565b600062000134306200013a60201b62001bb01760201c565b15905090565b3b151590565b60006020828403121562000152578081fd5b81516001600160a01b038116811462000169578182fd5b9392505050565b60805160601c613457620002296000398061030b528061035552806103ea52806104fe5280610538528061058852806106055280610755528061086c5280610899528061096e5280610a035280610ab05280610c1e5280610cfd5280610d8b5280610ec15280610f5352806112e652806113e25280611527528061156852806115fd528061169c52806117b152806117eb528061183f52806118bc5280611a0c5280611bdb5280611fd2528061221852506134576000f3fe608060405234801561001057600080fd5b50600436106101375760003560e01c80637e059b22116100b8578063ad431d121161007c578063ad431d1214610279578063b4aaae791461028c578063c393d0e31461029f578063e3056a34146102a7578063e58bb639146102af578063f235757f146102b757610137565b80637e059b221461020d57806392bf17e5146102205780639c162d03146102335780639df6a37914610253578063a7c87ec21461026657610137565b80633770e79d116100ff5780633770e79d146101b957806347bbbdf5146101cc578063656d565e146101df5780636ef1a28f146101e757806376340a67146101fa57610137565b80630c340a241461013c57806315eeb6b51461015a57806328a070251461017c578063320fe91314610186578063328123a2146101a6575b600080fd5b6101446102ca565b6040516101519190612d43565b60405180910390f35b61016d610168366004612d13565b6102df565b60405161015193929190613328565b610184610300565b005b610199610194366004612b3e565b610801565b60405161015191906132b7565b6101446101b4366004612d13565b610813565b6101996101c7366004612b3e565b61083d565b6101446101da366004612b3e565b61084f565b61014461086a565b6101846101f5366004612bae565b61088e565b610199610208366004612b3e565b611007565b61019961021b366004612b3e565b611019565b61019961022e366004612b3e565b61102b565b610246610241366004612b3e565b61116d565b6040516101519190612dba565b610184610261366004612b3e565b611182565b610184610274366004612b76565b61120a565b610184610287366004612bf3565b6112db565b61019961029a366004612b3e565b611508565b61019961151a565b610144611abc565b610184611acb565b6101846102c5366004612b3e565b611b3f565b6000546201000090046001600160a01b031681565b60076020526000908152604090208054600182015460029092015490919083565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146103515760405162461bcd60e51b815260040161034890612e9b565b60405180910390fd5b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637e7768ae6040518163ffffffff1660e01b815260040160206040518083038186803b1580156103ac57600080fd5b505afa1580156103c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103e49190612d2b565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663eb02c301836040518263ffffffff1660e01b815260040161043491906132b7565b6101c06040518083038186803b15801561044d57600080fd5b505afa158015610461573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104859190612c47565b905061049081611bb6565b6104ac5760405162461bcd60e51b815260040161034890613207565b60006104b782611c82565b90506000806104c68484611cf4565b91509150816000146104ea5760405162461bcd60e51b815260040161034890613169565b6080840151610524906001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006000611ea0565b608084015161055d906001600160a01b03167f000000000000000000000000000000000000000000000000000000000000000083611ea0565b61056c84608001518683611fb8565b608084015160405163bcbaf48760e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163bcbaf487916105be91908590600401612d80565b600060405180830381600087803b1580156105d857600080fd5b505af11580156105ec573d6000803e3d6000fd5b505060405163eb02c30160e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016925063eb02c301915061063c9088906004016132b7565b6101c06040518083038186803b15801561065557600080fd5b505afa158015610669573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061068d9190612c47565b61016081015160808201516001600160a01b03166000908152600a60205260409020549195506106bd919061213e565b60808501516001600160a01b039081166000908152600a602090815260408083209490945561010088015160a08901519093168252600590529190912054610704916121a1565b600560008660a001516001600160a01b03166001600160a01b03168152602001908152602001600020819055507fb1d3b1d444607bfe3a3e5b87e71d41301e1f7031b7e3f0b87a100079d6be26e6857f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a17fff756040518163ffffffff1660e01b815260040160206040518083038186803b1580156107ac57600080fd5b505afa1580156107c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107e49190612b5a565b6040516107f29291906132c0565b60405180910390a15050505050565b600a6020526000908152604090205481565b6002818154811061082357600080fd5b6000918252602090912001546001600160a01b0316905081565b60066020526000908152604090205481565b6004602052600090815260409020546001600160a01b031681565b7f000000000000000000000000000000000000000000000000000000000000000081565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146108d65760405162461bcd60e51b815260040161034890612e9b565b600082116108f65760405162461bcd60e51b8152600401610348906130d9565b6001600160a01b03841660009081526003602052604090205460ff1661092e5760405162461bcd60e51b815260040161034890613092565b6001600160a01b0384811660009081526004602052604090205481169084161461096a5760405162461bcd60e51b815260040161034890612ec9565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637e7768ae6040518163ffffffff1660e01b815260040160206040518083038186803b1580156109c557600080fd5b505afa1580156109d9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109fd9190612d2b565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663eb02c301836040518263ffffffff1660e01b8152600401610a4d91906132b7565b6101c06040518083038186803b158015610a6657600080fd5b505afa158015610a7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a9e9190612c47565b905080604001516001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a17fff756040518163ffffffff1660e01b815260040160206040518083038186803b158015610b0757600080fd5b505afa158015610b1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3f9190612b5a565b6001600160a01b031614610b655760405162461bcd60e51b81526004016103489061300a565b60408082015190516370a0823160e01b815285916001600160a01b038916916370a0823191610b9691600401612d43565b60206040518083038186803b158015610bae57600080fd5b505afa158015610bc2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610be69190612d2b565b1015610c045760405162461bcd60e51b815260040161034890612e14565b60405163405c451760e11b81526000906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906380b88a2e90610c55908a908990600401612d80565b60206040518083038186803b158015610c6d57600080fd5b505afa158015610c81573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca59190612d2b565b905080841115610cc75760405162461bcd60e51b815260040161034890613192565b848411610ce65760405162461bcd60e51b81526004016103489061311a565b60405163fbf3773960e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063fbf3773990610d38908a908a908a908a90600401612d57565b600060405180830381600087803b158015610d5257600080fd5b505af1158015610d66573d6000803e3d6000fd5b50505050610d7487846121fe565b60405163eb02c30160e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063eb02c30190610dc09086906004016132b7565b6101c06040518083038186803b158015610dd957600080fd5b505afa158015610ded573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e119190612c47565b9150600080610e208487612341565b9150915081600014610e445760405162461bcd60e51b8152600401610348906131d9565b8015610f2f576000610e55896125ea565b6001600160a01b038a16600090815260056020526040902054909150610e7b908361213e565b6001600160a01b03808b166000908152600560209081526040808320949094558982526007905282902060028101849055600181018590559151632aa0145d60e11b81527f00000000000000000000000000000000000000000000000000000000000000009091169063554028ba90610efa908a90879060040161331a565b600060405180830381600087803b158015610f1457600080fd5b505af1158015610f28573d6000803e3d6000fd5b5050505050505b7f4f8d474cdd22aabe2e96f65f6dee87cd74d538fa1b8bd3d2352b980235a6dff6857f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a17fff756040518163ffffffff1660e01b815260040160206040518083038186803b158015610faa57600080fd5b505afa158015610fbe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fe29190612b5a565b8989604051610ff494939291906132f6565b60405180910390a1505050505050505050565b60056020526000908152604090205481565b60096020526000908152604090205481565b6001600160a01b03808216600090815260046020526040812054909116806110655760405162461bcd60e51b815260040161034890612f7a565b6040516370a0823160e01b81526000906001600160a01b038316906370a0823190611094903090600401612d43565b60206040518083038186803b1580156110ac57600080fd5b505afa1580156110c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110e49190612d2b565b9050611163826001600160a01b031663bd6d894d6040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561112457600080fd5b505af1158015611138573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061115c9190612d2b565b829061272e565b925050505b919050565b60036020526000908152604090205460ff1681565b6000546201000090046001600160a01b031633146111d1576040805162461bcd60e51b81526020600482015260076024820152663130b21033b7bb60c91b604482015290519081900360640190fd5b6001600160a01b03166000908152600360209081526040808320805460ff191690556004909152902080546001600160a01b0319169055565b6000546201000090046001600160a01b03163314611259576040805162461bcd60e51b81526020600482015260076024820152663130b21033b7bb60c91b604482015290519081900360640190fd5b6001600160a01b039182166000818152600360209081526040808320805460ff19166001908117909155600490925282208054949095166001600160a01b03199485161790945560028054948501815590527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace90920180549091169091179055565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146113235760405162461bcd60e51b815260040161034890612e9b565b6001600160a01b03831660009081526003602052604090205460ff1661135b5760405162461bcd60e51b815260040161034890612fc5565b6001600160a01b0383166000908152600960205260409020548211156113935760405162461bcd60e51b815260040161034890612e56565b6001600160a01b0383166000908152600860205260409020548111156113cb5760405162461bcd60e51b815260040161034890612f37565b604051632b692db960e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632b692db99061141b90869086908690600401612d99565b600060405180830381600087803b15801561143557600080fd5b505af1158015611449573d6000803e3d6000fd5b505050507ff43c9b3430b5ffd997ba4b5d58204bdcb4761cfb86b2897c8f641276b26fcc2383838360405161148093929190612d99565b60405180910390a16001600160a01b0383166000908152600a6020908152604080832083905560089091529020546114b890826121a1565b6001600160a01b0384166000908152600860209081526040808320939093556009905220546114e790836121a1565b6001600160a01b039093166000908152600960205260409020929092555050565b60086020526000908152604090205481565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146115645760405162461bcd60e51b815260040161034890612e9b565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637e7768ae6040518163ffffffff1660e01b815260040160206040518083038186803b1580156115bf57600080fd5b505afa1580156115d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115f79190612d2b565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663eb02c301836040518263ffffffff1660e01b815260040161164791906132b7565b6101c06040518083038186803b15801561166057600080fd5b505afa158015611674573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116989190612c47565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a17fff756040518163ffffffff1660e01b815260040160206040518083038186803b1580156116f357600080fd5b505afa158015611707573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061172b9190612b5a565b6001600160a01b031681604001516001600160a01b03161461175f5760405162461bcd60e51b815260040161034890612dc5565b600061176a82611c82565b90506000806117798484611cf4565b915091508160001461179d5760405162461bcd60e51b815260040161034890612f0d565b60808401516117d7906001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006000611ea0565b6080840151611810906001600160a01b03167f000000000000000000000000000000000000000000000000000000000000000083611ea0565b6118238460800151856000015183611fb8565b6080840151604051630450cfaf60e31b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916322867d789161187591908590600401612d80565b600060405180830381600087803b15801561188f57600080fd5b505af11580156118a3573d6000803e3d6000fd5b505060405163eb02c30160e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016925063eb02c30191506118f39088906004016132b7565b6101c06040518083038186803b15801561190c57600080fd5b505afa158015611920573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119449190612c47565b61016081015160808201516001600160a01b03166000908152600a6020526040902054919550611974919061213e565b60808501516001600160a01b039081166000908152600a602090815260408083209490945561010088015160a089015190931682526005905291909120546119bb916121a1565b600560008660a001516001600160a01b03166001600160a01b03168152602001908152602001600020819055507fd245dd480b54d4fb2c6abff0ab361ff89a8073a603e5ef738a86ecbaa1ae7cc7857f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a17fff756040518163ffffffff1660e01b815260040160206040518083038186803b158015611a6357600080fd5b505afa158015611a77573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a9b9190612b5a565b83604051611aab939291906132d7565b60405180910390a194505050505090565b6001546001600160a01b031681565b6001546001600160a01b03163314611b14576040805162461bcd60e51b81526020600482015260076024820152661b9bc81c195b9960ca1b604482015290519081900360640190fd5b600180546001600160a01b03191690556000805462010000600160b01b031916336201000002179055565b6000546201000090046001600160a01b03163314611b8e576040805162461bcd60e51b81526020600482015260076024820152663130b21033b7bb60c91b604482015290519081900360640190fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b3b151590565b6080810151815160405163238672f960e11b8152600092839283926001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169263470ce5f292611c0e92600401612d80565b60206040518083038186803b158015611c2657600080fd5b505afa158015611c3a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c5e9190612d2b565b60e0850151909150611c7182600261272e565b10611c7b57600191505b5092915050565b600080611c928360a001516125ea565b83516000908152600760205260408120600281015492935091611cd990670de0b6b3a764000090611cd390611cc89087906121a1565b60018601549061272e565b90612787565b6001830154909150611ceb908261213e565b95945050505050565b600080600084608001516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401611d299190612d43565b60206040518083038186803b158015611d4157600080fd5b505afa158015611d55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d799190612d2b565b905060008560a001516001600160a01b031663db006a75866040518263ffffffff1660e01b8152600401611dad91906132b7565b602060405180830381600087803b158015611dc757600080fd5b505af1158015611ddb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dff9190612d2b565b9050600086608001516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401611e339190612d43565b60206040518083038186803b158015611e4b57600080fd5b505afa158015611e5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e839190612d2b565b90506000611e9182856121a1565b92989297509195505050505050565b801580611f26575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b158015611ef857600080fd5b505afa158015611f0c573d6000803e3d6000fd5b505050506040513d6020811015611f2257600080fd5b5051155b611f615760405162461bcd60e51b81526004018080602001828103825260368152602001806133ec6036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b179052611fb39084906127ee565b505050565b60405163eb02c30160e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063eb02c301906120079086906004016132b7565b6101c06040518083038186803b15801561202057600080fd5b505afa158015612034573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120589190612c47565b60c08101516040810151602082015191519293509101018083106120b7576001600160a01b03851660009081526008602052604090205461209990826121a1565b6001600160a01b0386166000908152600860205260409020556120f4565b6001600160a01b0385166000908152600860205260409020546120da90846121a1565b6001600160a01b0386166000908152600860205260409020555b60e08201516001600160a01b03861660009081526009602052604090205461211b916121a1565b6001600160a01b0390951660009081526009602052604090209490945550505050565b600082820183811015612198576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b90505b92915050565b6000828211156121f8576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60405163eb02c30160e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063eb02c3019061224d9085906004016132b7565b6101c06040518083038186803b15801561226657600080fd5b505afa15801561227a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061229e9190612c47565b905060005b6003811015612319576122f88260c0015182600381106122bf57fe5b602002015160086000876001600160a01b03166001600160a01b031681526020019081526020016000205461213e90919063ffffffff16565b6001600160a01b0385166000908152600860205260409020556001016122a3565b5060e08101516001600160a01b0384166000908152600960205260409020546114e79161213e565b60008060008460a001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016123769190612d43565b60206040518083038186803b15801561238e57600080fd5b505afa1580156123a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123c69190612d2b565b905084608001516001600160a01b031663095ea7b38660a0015160006040518363ffffffff1660e01b81526004016123ff929190612d80565b602060405180830381600087803b15801561241957600080fd5b505af115801561242d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124519190612c27565b61246d5760405162461bcd60e51b81526004016103489061325c565b608085015160a086015160405163095ea7b360e01b81526001600160a01b039092169163095ea7b3916124a4918890600401612d80565b602060405180830381600087803b1580156124be57600080fd5b505af11580156124d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124f69190612c27565b6125125760405162461bcd60e51b81526004016103489061305b565b60a085015160405163140e25ad60e31b81526000916001600160a01b03169063a0712d68906125459088906004016132b7565b602060405180830381600087803b15801561255f57600080fd5b505af1158015612573573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125979190612d2b565b905080156125b75760405162461bcd60e51b81526004016103489061328b565b60a08601516040516370a0823160e01b81526000916001600160a01b0316906370a0823190611e33903090600401612d43565b600080826001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016126199190612d43565b60206040518083038186803b15801561263157600080fd5b505afa158015612645573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126699190612d2b565b6001600160a01b03841660009081526005602052604081205491925082821161269357600061269d565b61269d82846121a1565b9050600082156126c2576126bd83611cd384670de0b6b3a764000061272e565b6126c5565b60005b9050801561270a576001600160a01b0386166000908152600660205260409020546126f0908261213e565b6001600160a01b0387166000908152600660205260409020555b5050506001600160a01b038316600090815260066020526040902054915050919050565b60008261273d5750600061219b565b8282028284828161274a57fe5b04146121985760405162461bcd60e51b81526004018080602001828103825260218152602001806133a16021913960400191505060405180910390fd5b60008082116127dd576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b8183816127e657fe5b049392505050565b6000612843826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661289f9092919063ffffffff16565b805190915015611fb35780806020019051602081101561286257600080fd5b5051611fb35760405162461bcd60e51b815260040180806020018281038252602a8152602001806133c2602a913960400191505060405180910390fd5b60606128ae84846000856128b8565b90505b9392505050565b6060824710156128f95760405162461bcd60e51b815260040180806020018281038252602681526020018061337b6026913960400191505060405180910390fd5b61290285611bb0565b612953576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600080866001600160a01b031685876040518082805190602001908083835b602083106129915780518252601f199092019160209182019101612972565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146129f3576040519150601f19603f3d011682016040523d82523d6000602084013e6129f8565b606091505b5091509150612a08828286612a13565b979650505050505050565b60608315612a225750816128b1565b825115612a325782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015612a7c578181015183820152602001612a64565b50505050905090810190601f168015612aa95780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b805161116881613362565b600082601f830112612ad2578081fd5b6040516060810181811067ffffffffffffffff82111715612aef57fe5b604052808360608101861015612b03578384fd5b835b6003811015612b24578151835260209283019290910190600101612b05565b509195945050505050565b80516005811061116857600080fd5b600060208284031215612b4f578081fd5b813561219881613362565b600060208284031215612b6b578081fd5b815161219881613362565b60008060408385031215612b88578081fd5b8235612b9381613362565b91506020830135612ba381613362565b809150509250929050565b60008060008060808587031215612bc3578182fd5b8435612bce81613362565b93506020850135612bde81613362565b93969395505050506040820135916060013590565b600080600060608486031215612c07578283fd5b8335612c1281613362565b95602085013595506040909401359392505050565b600060208284031215612c38578081fd5b81518015158114612198578182fd5b60006101c08284031215612c59578081fd5b610180612c658161333e565b83518152612c7560208501612b2f565b6020820152612c8660408501612ab7565b6040820152612c9760608501612ab7565b6060820152612ca860808501612ab7565b6080820152612cb960a08501612ab7565b60a0820152612ccb8560c08601612ac2565b60c08201526101208481015160e083015261014080860151610100840152610160808701519284019290925292850151928201929092526101a0909301519083015250919050565b600060208284031215612d24578081fd5b5035919050565b600060208284031215612d3c578081fd5b5051919050565b6001600160a01b0391909116815260200190565b6001600160a01b0394851681529290931660208301526040820152606081019190915260800190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039390931683526020830191909152604082015260600190565b901515815260200190565b6020808252602f908201527f636c6f7365506f736974696f6e3a206f726967696e616c2063616c6c6572206960408201526e39903737ba103a34329037bbb732b960891b606082015260800190565b60208082526022908201527f6f70656e506f736974696f6e3a20696e73756666696369656e742062616c616e604082015261636560f01b606082015260800190565b60208082526025908201527f736574746c654372656469744576656e743a20696e76616c696420636f6c6c616040820152641d195c985b60da1b606082015260800190565b6020808252601490820152731bdb9b1e481b9d5d1b5959c818d85b8818d85b1b60621b604082015260600190565b60208082526024908201527f6f70656e506f736974696f6e3a20696e76616c69642063546f6b656e206164646040820152637265737360e01b606082015260800190565b60208082526010908201526f18db1cd41bdcce881c991b4819985a5b60821b604082015260600190565b60208082526023908201527f736574746c654372656469744576656e743a20696e76616c696420706f6f6c4c6040820152626f737360e81b606082015260800190565b6020808252602b908201527f736574746c654372656469744576656e743a20696e76616c696420636f6c6c6160408201526a3a32b930b6103a37b5b2b760a91b606082015260800190565b60208082526025908201527f736574746c654372656469744576656e743a20696e76616c69642062617365206040820152643a37b5b2b760d91b606082015260800190565b60208082526031908201527f6f70656e506f736974696f6e3a206f6e6c79206f776e65722063616e20696e696040820152701d1a585b1a5e99481d1a1a5cc818d85b1b607a1b606082015260800190565b6020808252601c908201527f5f646f4d696e7420617070726f766520616d6f756e74206572726f7200000000604082015260600190565b60208082526027908201527f6f70656e506f736974696f6e3a20696e76616c69642062617365546f6b656e206040820152666164647265737360c81b606082015260800190565b60208082526021908201527f6f70656e506f736974696f6e3a20696e76616c6964206261736520616d6f756e6040820152601d60fa1b606082015260800190565b6020808252602f908201527f6f70656e506f736974696f6e3a20626f72726f77416d74206973206c6573732060408201526e1d1a185b8818dbdb1b185d195c985b608a1b606082015260800190565b6020808252600f908201526e1b1c591d194e881c991b4819985a5b608a1b604082015260600190565b60208082526027908201527f6f70656e506f736974696f6e3a20626f72726f77416d742065786365656473206040820152666d6178696d756d60c81b606082015260800190565b6020808252601490820152731bdc1b941bdcce8817d91bd35a5b9d0819985a5b60621b604082015260600190565b60208082526035908201527f6c69717569646174653a20706f736974696f6e206973206e6f74207265616479604082015274103337b9103634b8bab4b230ba34b7b7103cb2ba1760591b606082015260800190565b6020808252601590820152742fb237a6b4b73a1030b8383937bb329032b93937b960591b604082015260600190565b6020808252601290820152712fb237a6b4b73a1036b4b73a1032b93937b960711b604082015260600190565b90815260200190565b9182526001600160a01b0316602082015260400190565b9283526001600160a01b03919091166020830152604082015260600190565b9384526001600160a01b039290921660208401526040830152606082015260800190565b918252602082015260400190565b9283526020830191909152604082015260600190565b60405181810167ffffffffffffffff8111828210171561335a57fe5b604052919050565b6001600160a01b038116811461337757600080fd5b5056fe416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a2646970667358221220b90b253c3bfc6dafc134899ead87ff23e2f1cd0b0cd0d663721958d40db2ff5f64736f6c63430007060033496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a6564000000000000000000000000e72a94a569ce4748192b0ec2bdc5495779b42944

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

000000000000000000000000e72a94a569ce4748192b0ec2bdc5495779b42944

-----Decoded View---------------
Arg [0] : nutmegAddr (address): 0xe72a94a569ce4748192b0ec2bdc5495779b42944

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000e72a94a569ce4748192b0ec2bdc5495779b42944


Deployed ByteCode Sourcemap

2097:123:11:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;156:23:9;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;1026:42:2;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;:::i;5260:998::-;;;:::i;:::-;;1175:41;;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;727:27::-;;;;;;:::i;:::-;;:::i;979:41::-;;;;;;:::i;:::-;;:::i;847:45::-;;;;;;:::i;:::-;;:::i;641:31::-;;;:::i;2180:1858::-;;;;;;:::i;:::-;;:::i;929:44::-;;;;;;:::i;:::-;;:::i;1122:47::-;;;;;;:::i;:::-;;:::i;6306:363::-;;;;;;:::i;:::-;;:::i;784:44::-;;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;1743:153::-;;;;;;:::i;:::-;;:::i;1488:203::-;;;;;;:::i;:::-;;:::i;6759:727::-;;;;;;:::i;:::-;;:::i;1075:41::-;;;;;;:::i;:::-;;:::i;4093:1124::-;;;:::i;183:30:9:-;;;:::i;807:156::-;;;:::i;625:92::-;;;;;;:::i;:::-;;:::i;156:23::-;;;;;;-1:-1:-1;;;;;156:23:9;;:::o;1026:42:2:-;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;5260:998::-;1367:10;-1:-1:-1;;;;;1389:6:2;1367:29;;1359:62;;;;-1:-1:-1;;;1359:62:2;;;;;;;:::i;:::-;;;;;;;;;5321:10:::1;5334:6;-1:-1:-1::0;;;;;5334:24:2::1;;:26;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;5321:39;;5370:27;5400:6;-1:-1:-1::0;;;;;5400:18:2::1;;5419:5;5400:25;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;5370:55;;5443:19;5458:3;5443:14;:19::i;:::-;5435:85;;;;-1:-1:-1::0;;;5435:85:2::1;;;;;;;:::i;:::-;5531:11;5545:24;5565:3;5545:19;:24::i;:::-;5531:38;;5580:11;5593:14:::0;5611:22:::1;5621:3;5626:6;5611:9;:22::i;:::-;5579:54;;;;5651:6;5661:1;5651:11;5643:39;;;;-1:-1:-1::0;;;5643:39:2::1;;;;;;;:::i;:::-;5699:13;::::0;::::1;::::0;5692:53:::1;::::0;-1:-1:-1;;;;;5692:33:2::1;5734:6;5743:1;5692:33;:53::i;:::-;5762:13;::::0;::::1;::::0;5755:61:::1;::::0;-1:-1:-1;;;;;5755:33:2::1;5797:6;5806:9:::0;5755:33:::1;:61::i;:::-;5872:59;5899:3;:13;;;5914:5;5921:9;5872:26;:59::i;:::-;5958:13;::::0;::::1;::::0;5941:42:::1;::::0;-1:-1:-1;;;5941:42:2;;-1:-1:-1;;;;;5941:6:2::1;:16;::::0;::::1;::::0;:42:::1;::::0;5958:13;5973:9;;5941:42:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;-1:-1:-1::0;;5999:25:2::1;::::0;-1:-1:-1;;;5999:25:2;;-1:-1:-1;;;;;5999:6:2::1;:18;::::0;-1:-1:-1;5999:18:2::1;::::0;-1:-1:-1;5999:25:2::1;::::0;6018:5;;5999:25:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;6090:16;::::0;::::1;::::0;6071:13:::1;::::0;::::1;::::0;-1:-1:-1;;;;;6061:24:2::1;;::::0;;;:9:::1;:24;::::0;;;;;5993:31;;-1:-1:-1;6061:46:2::1;::::0;:24;:28:::1;:46::i;:::-;6044:13;::::0;::::1;::::0;-1:-1:-1;;;;;6034:24:2;;::::1;;::::0;;;:9:::1;:24;::::0;;;;;;;:73;;;;6179:11:::1;::::0;::::1;::::0;6160:13:::1;::::0;::::1;::::0;6147:27;;::::1;::::0;;:12:::1;:27:::0;;;;;;;:44:::1;::::0;:31:::1;:44::i;:::-;6117:12;:27;6130:3;:13;;;-1:-1:-1::0;;;;;6117:27:2::1;-1:-1:-1::0;;;;;6117:27:2::1;;;;;;;;;;;;:74;;;;6206:45;6221:5;6228:6;-1:-1:-1::0;;;;;6228:20:2::1;;:22;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;6206:45;;;;;;;:::i;:::-;;;;;;;;1431:1;;;;;5260:998::o:0;1175:41::-;;;;;;;;;;;;;:::o;727:27::-;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;727:27:2;;-1:-1:-1;727:27:2;:::o;979:41::-;;;;;;;;;;;;;:::o;847:45::-;;;;;;;;;;;;-1:-1:-1;;;;;847:45:2;;:::o;641:31::-;;;:::o;2180:1858::-;1367:10;-1:-1:-1;;;;;1389:6:2;1367:29;;1359:62;;;;-1:-1:-1;;;1359:62:2;;;;;;;:::i;:::-;2335:1:::1;2325:7;:11;2317:57;;;;-1:-1:-1::0;;;2317:57:2::1;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;2392:23:2;::::1;;::::0;;;:12:::1;:23;::::0;;;;;::::1;;2384:75;;;;-1:-1:-1::0;;;2384:75:2::1;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;2477:21:2;;::::1;;::::0;;;:10:::1;:21;::::0;;;;;;::::1;:34:::0;;::::1;;2469:83;;;;-1:-1:-1::0;;;2469:83:2::1;;;;;;;:::i;:::-;2563:10;2576:6;-1:-1:-1::0;;;;;2576:24:2::1;;:26;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2563:39;;2612:27;2642:6;-1:-1:-1::0;;;;;2642:18:2::1;;2661:5;2642:25;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2612:55;;2711:3;:9;;;-1:-1:-1::0;;;;;2685:35:2::1;:6;-1:-1:-1::0;;;;;2685:20:2::1;;:22;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;2685:35:2::1;;2677:97;;;;-1:-1:-1::0;;;2677:97:2::1;;;;;;;:::i;:::-;2820:9;::::0;;::::1;::::0;2792:38;;-1:-1:-1;;;2792:38:2;;2834:7;;-1:-1:-1;;;;;2792:27:2;::::1;::::0;::::1;::::0;:38:::1;::::0;::::1;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:49;;2784:96;;;;-1:-1:-1::0;;;2784:96:2::1;;;;;;;:::i;:::-;2938:45;::::0;-1:-1:-1;;;2938:45:2;;2918:17:::1;::::0;-1:-1:-1;;;;;2938:6:2::1;:25;::::0;::::1;::::0;:45:::1;::::0;2964:9;;2975:7;;2938:45:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2918:65;;3014:12;3001:9;:25;;2993:77;;;;-1:-1:-1::0;;;2993:77:2::1;;;;;;;:::i;:::-;3100:7;3088:9;:19;3080:79;;;;-1:-1:-1::0;;;3080:79:2::1;;;;;;;:::i;:::-;3212:55;::::0;-1:-1:-1;;;3212:55:2;;-1:-1:-1;;;;;3212:6:2::1;:13;::::0;::::1;::::0;:55:::1;::::0;3226:9;;3237;;3248:7;;3257:9;;3212:55:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;3278:44;3305:9;3316:5;3278:26;:44::i;:::-;3387:25;::::0;-1:-1:-1;;;3387:25:2;;-1:-1:-1;;;;;3387:6:2::1;:18;::::0;::::1;::::0;:25:::1;::::0;3406:5;;3387:25:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;3381:31;;3423:11;3436:12:::0;3452:23:::1;3460:3;3465:9;3452:7;:23::i;:::-;3422:53;;;;3493:6;3503:1;3493:11;3485:44;;;;-1:-1:-1::0;;;3485:44:2::1;;;;;;;:::i;:::-;3543:11:::0;;3539:410:::1;;3570:15;3588:28;3606:9;3588:17;:28::i;:::-;-1:-1:-1::0;;;;;3656:23:2;::::1;;::::0;;;:12:::1;:23;::::0;;;;;3570:46;;-1:-1:-1;3656:36:2::1;::::0;3684:7;3656:27:::1;:36::i;:::-;-1:-1:-1::0;;;;;3630:23:2;;::::1;;::::0;;;:12:::1;:23;::::0;;;;;;;:62;;;;3732:17;;;:10:::1;:17:::0;;;;;3763:19:::1;::::0;::::1;:32:::0;;;3809:15:::1;::::0;::::1;:25:::0;;;3903:35;;-1:-1:-1;;;3903:35:2;;:6:::1;:19:::0;;::::1;::::0;::::1;::::0;:35:::1;::::0;3743:5;;3827:7;;3903:35:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;3539:410;;;3963:68;3981:5;3988:6;-1:-1:-1::0;;;;;3988:20:2::1;;:22;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;4012:7;4021:9;3963:68;;;;;;;;;:::i;:::-;;;;;;;;1431:1;;;;;2180:1858:::0;;;;:::o;929:44::-;;;;;;;;;;;;;:::o;1122:47::-;;;;;;;;;;;;;:::o;6306:363::-;-1:-1:-1;;;;;6403:21:2;;;6367:4;6403:21;;;:10;:21;;;;;;6367:4;;6403:21;6442:23;6434:80;;;;-1:-1:-1;;;6434:80:2;;;;;;;:::i;:::-;6544:43;;-1:-1:-1;;;6544:43:2;;6524:17;;-1:-1:-1;;;;;6544:28:2;;;;;:43;;6581:4;;6544:43;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;6524:63;;6604:58;6629:9;-1:-1:-1;;;;;6621:38:2;;:40;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;6604:12;;:16;:58::i;:::-;6597:65;;;;6306:363;;;;:::o;784:44::-;;;;;;;;;;;;;;;:::o;1743:153::-;265:8:9;;;;;-1:-1:-1;;;;;265:8:9;251:10;:22;243:42;;;;;-1:-1:-1;;;243:42:9;;;;;;;;;;;;-1:-1:-1;;;243:42:9;;;;;;;;;;;;;;;-1:-1:-1;;;;;1814:23:2::1;1840:5;1814:23:::0;;;:12:::1;:23;::::0;;;;;;;:31;;-1:-1:-1;;1814:31:2::1;::::0;;1855:10:::1;:21:::0;;;;;:34;;-1:-1:-1;;;;;;1855:34:2::1;::::0;;1743:153::o;1488:203::-;265:8:9;;;;;-1:-1:-1;;;;;265:8:9;251:10;:22;243:42;;;;;-1:-1:-1;;;243:42:9;;;;;;;;;;;;-1:-1:-1;;;243:42:9;;;;;;;;;;;;;;;-1:-1:-1;;;;;1575:23:2;;::::1;;::::0;;;:12:::1;:23;::::0;;;;;;;:30;;-1:-1:-1;;1575:30:2::1;1601:4;1575:30:::0;;::::1;::::0;;;1615:10:::1;:21:::0;;;;;:33;;;;;::::1;-1:-1:-1::0;;;;;;1615:33:2;;::::1;;::::0;;;1658:10:::1;:26:::0;;;;::::1;::::0;;;;;;;::::1;::::0;;;;::::1;::::0;;::::1;::::0;;1488:203::o;6759:727::-;1367:10;-1:-1:-1;;;;;1389:6:2;1367:29;;1359:62;;;;-1:-1:-1;;;1359:62:2;;;;;;;:::i;:::-;-1:-1:-1;;;;;6889:23:2;::::1;;::::0;;;:12:::1;:23;::::0;;;;;::::1;;6881:75;;;;-1:-1:-1::0;;;6881:75:2::1;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;6992:26:2;::::1;;::::0;;;:15:::1;:26;::::0;;;;;6974:44;::::1;;6966:95;;;;-1:-1:-1::0;;;6966:95:2::1;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;7091:20:2;::::1;;::::0;;;:9:::1;:20;::::0;;;;;7079:32;::::1;;7071:81;;;;-1:-1:-1::0;;;7071:81:2::1;;;;;;;:::i;:::-;7163:66;::::0;-1:-1:-1;;;7163:66:2;;-1:-1:-1;;;;;7163:6:2::1;:29;::::0;::::1;::::0;:66:::1;::::0;7193:9;;7204:14;;7220:8;;7163:66:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;7245:48;7257:9;7268:14;7284:8;7245:48;;;;;;;;:::i;:::-;;;;;;;;-1:-1:-1::0;;;;;7303:20:2;::::1;7326:1;7303:20:::0;;;:9:::1;:20;::::0;;;;;;;:24;;;7360:9:::1;:20:::0;;;;;;:34:::1;::::0;7385:8;7360:24:::1;:34::i;:::-;-1:-1:-1::0;;;;;7337:20:2;::::1;;::::0;;;:9:::1;:20;::::0;;;;;;;:57;;;;7433:15:::1;:26:::0;;;;:46:::1;::::0;7464:14;7433:30:::1;:46::i;:::-;-1:-1:-1::0;;;;;7404:26:2;;::::1;;::::0;;;:15:::1;:26;::::0;;;;:75;;;;-1:-1:-1;;6759:727:2:o;1075:41::-;;;;;;;;;;;;;:::o;4093:1124::-;4156:4;1367:10;-1:-1:-1;;;;;1389:6:2;1367:29;;1359:62;;;;-1:-1:-1;;;1359:62:2;;;;;;;:::i;:::-;4172:10:::1;4185:6;-1:-1:-1::0;;;;;4185:24:2::1;;:26;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;4172:39;;4221:27;4251:6;-1:-1:-1::0;;;;;4251:18:2::1;;4270:5;4251:25;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;4221:55;;4307:6;-1:-1:-1::0;;;;;4307:20:2::1;;:22;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;4294:35:2::1;:3;:9;;;-1:-1:-1::0;;;;;4294:35:2::1;;4286:95;;;;-1:-1:-1::0;;;4286:95:2::1;;;;;;;:::i;:::-;4392:12;4407:24;4427:3;4407:19;:24::i;:::-;4392:39;;4442:11;4455:14:::0;4473:23:::1;4483:3;4488:7;4473:9;:23::i;:::-;4441:55;;;;4514:6;4524:1;4514:11;4506:40;;;;-1:-1:-1::0;;;4506:40:2::1;;;;;;;:::i;:::-;4626:13;::::0;::::1;::::0;4619:53:::1;::::0;-1:-1:-1;;;;;4619:33:2::1;4661:6;4670:1;4619:33;:53::i;:::-;4689:13;::::0;::::1;::::0;4682:61:::1;::::0;-1:-1:-1;;;;;4682:33:2::1;4724:6;4733:9:::0;4682:33:::1;:61::i;:::-;4781:60;4808:3;:13;;;4823:3;:6;;;4831:9;4781:26;:60::i;:::-;4864:13;::::0;::::1;::::0;4851:38:::1;::::0;-1:-1:-1;;;4851:38:2;;-1:-1:-1;;;;;4851:6:2::1;:12;::::0;::::1;::::0;:38:::1;::::0;4864:13;4879:9;;4851:38:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;-1:-1:-1::0;;4905:25:2::1;::::0;-1:-1:-1;;;4905:25:2;;-1:-1:-1;;;;;4905:6:2::1;:18;::::0;-1:-1:-1;4905:18:2::1;::::0;-1:-1:-1;4905:25:2::1;::::0;4924:5;;4905:25:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;5008:16;::::0;::::1;::::0;4989:13:::1;::::0;::::1;::::0;-1:-1:-1;;;;;4979:24:2::1;;::::0;;;:9:::1;:24;::::0;;;;;4899:31;;-1:-1:-1;4979:46:2::1;::::0;:24;:28:::1;:46::i;:::-;4950:13;::::0;::::1;::::0;-1:-1:-1;;;;;4940:24:2;;::::1;;::::0;;;:9:::1;:24;::::0;;;;;;;:85;;;;5097:11:::1;::::0;::::1;::::0;5078:13:::1;::::0;::::1;::::0;5065:27;;::::1;::::0;;:12:::1;:27:::0;;;;;;;:44:::1;::::0;:31:::1;:44::i;:::-;5035:12;:27;5048:3;:13;;;-1:-1:-1::0;;;;;5035:27:2::1;-1:-1:-1::0;;;;;5035:27:2::1;;;;;;;;;;;;:74;;;;5124:60;5143:5;5150:6;-1:-1:-1::0;;;;;5150:20:2::1;;:22;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;5174:9;5124:60;;;;;;;;:::i;:::-;;;;;;;;5201:9:::0;-1:-1:-1;;;;;4093:1124:2;:::o;183:30:9:-;;;-1:-1:-1;;;;;183:30:9;;:::o;807:156::-;870:15;;-1:-1:-1;;;;;870:15:9;856:10;:29;848:49;;;;;-1:-1:-1;;;848:49:9;;;;;;;;;;;;-1:-1:-1;;;848:49:9;;;;;;;;;;;;;;;903:15;:28;;-1:-1:-1;;;;;;903:28:9;;;-1:-1:-1;937:21:9;;-1:-1:-1;;;;;;937:21:9;948:10;937:21;;;;;807:156::o;625:92::-;265:8;;;;;-1:-1:-1;;;;;265:8:9;251:10;:22;243:42;;;;;-1:-1:-1;;;243:42:9;;;;;;;;;;;;-1:-1:-1;;;243:42:9;;;;;;;;;;;;;;;690:15:::1;:22:::0;;-1:-1:-1;;;;;;690:22:9::1;-1:-1:-1::0;;;;;690:22:9;;;::::1;::::0;;;::::1;::::0;;625:92::o;726:413:19:-;1086:20;1124:8;;;726:413::o;10583:286:2:-;10742:13;;;;10757:6;;10715:49;;-1:-1:-1;;;10715:49:2;;10658:4;;;;;;-1:-1:-1;;;;;10715:6:2;:26;;;;:49;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;10797:11;;;;10699:65;;-1:-1:-1;10778:15:2;10699:65;10791:1;10778:12;:15::i;:::-;:30;10774:70;;10829:4;10824:9;;10774:70;-1:-1:-1;10860:2:2;10583:286;-1:-1:-1;;10583:286:2:o;9571:346::-;9646:4;9662:15;9680:32;9698:3;:13;;;9680:17;:32::i;:::-;9759:6;;9722:23;9748:18;;;:10;:18;;;;;9827:19;;;;9662:50;;-1:-1:-1;9748:18:2;9792:72;;714:6;;9792:56;;9812:35;;9662:50;;9812:14;:35::i;:::-;9792:15;;;;;:19;:56::i;:::-;:60;;:72::i;:::-;9881:15;;;;9776:88;;-1:-1:-1;9881:29:2;;9776:88;9881:19;:29::i;:::-;9874:36;9571:346;-1:-1:-1;;;;;9571:346:2:o;9123:389::-;9201:4;9207;9223:14;9247:3;:13;;;-1:-1:-1;;;;;9240:31:2;;9280:4;9240:46;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;9223:63;;9296:11;9318:3;:13;;;-1:-1:-1;;;;;9310:29:2;;9340:6;9310:37;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;9296:51;;9357:13;9380:3;:13;;;-1:-1:-1;;;;;9373:31:2;;9413:4;9373:46;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;9357:62;-1:-1:-1;9429:14:2;9446:23;9357:62;9459:9;9446:12;:23::i;:::-;9487:6;;;;-1:-1:-1;9123:389:2;;-1:-1:-1;;;;;;9123:389:2:o;1348:613:18:-;1713:10;;;1712:62;;-1:-1:-1;1729:39:18;;;-1:-1:-1;;;1729:39:18;;1753:4;1729:39;;;;-1:-1:-1;;;;;1729:39:18;;;;;;;;;:15;;;;;;:39;;;;;;;;;;;;;;;:15;:39;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1729:39:18;:44;1712:62;1704:150;;;;-1:-1:-1;;;1704:150:18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1891:62;;;-1:-1:-1;;;;;1891:62:18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;1891:62:18;-1:-1:-1;;;1891:62:18;;;1864:90;;1884:5;;1864:19;:90::i;:::-;1348:613;;;:::o;7871:499:2:-;7999:25;;-1:-1:-1;;;7999:25:2;;7969:27;;-1:-1:-1;;;;;7999:6:2;:18;;;;:25;;8018:5;;7999:25;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;8082:9;;;;:12;;;;;8067;;;8052;;8082:9;;-1:-1:-1;8052:27:2;;:42;8108:23;;;8104:186;;-1:-1:-1;;;;;8166:16:2;;;;;;:9;:16;;;;;;:32;;8187:10;8166:20;:32::i;:::-;-1:-1:-1;;;;;8147:16:2;;;;;;:9;:16;;;;;:51;8104:186;;;-1:-1:-1;;;;;8248:16:2;;;;;;:9;:16;;;;;;:31;;8269:9;8248:20;:31::i;:::-;-1:-1:-1;;;;;8229:16:2;;;;;;:9;:16;;;;;:50;8104:186;8351:11;;;;-1:-1:-1;;;;;8324:22:2;;;;;;:15;:22;;;;;;:39;;:26;:39::i;:::-;-1:-1:-1;;;;;8299:22:2;;;;;;;:15;:22;;;;;:64;;;;-1:-1:-1;;;;7871:499:2:o;2690:175:14:-;2748:7;2779:5;;;2802:6;;;;2794:46;;;;;-1:-1:-1;;;2794:46:14;;;;;;;;;;;;;;;;;;;;;;;;;;;;2857:1;-1:-1:-1;2690:175:14;;;;;:::o;3136:155::-;3194:7;3226:1;3221;:6;;3213:49;;;;;-1:-1:-1;;;3213:49:14;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;3279:5:14;;;3136:155::o;7492:334:2:-;7604:25;;-1:-1:-1;;;7604:25:2;;7574:27;;-1:-1:-1;;;;;7604:6:2;:18;;;;:25;;7623:5;;7604:25;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;7574:55;;7644:6;7639:107;7660:1;7656;:5;7639:107;;;7701:34;7722:3;:9;;;7732:1;7722:12;;;;;;;;;;;7701:9;:16;7711:5;-1:-1:-1;;;;;7701:16:2;-1:-1:-1;;;;;7701:16:2;;;;;;;;;;;;;:20;;:34;;;;:::i;:::-;-1:-1:-1;;;;;7682:16:2;;;;;;:9;:16;;;;;:53;7663:3;;7639:107;;;-1:-1:-1;7807:11:2;;;;-1:-1:-1;;;;;7780:22:2;;;;;;:15;:22;;;;;;:39;;:26;:39::i;8430:635::-;8506:4;8512;8528:14;8553:3;:13;;;-1:-1:-1;;;;;8545:32:2;;8586:4;8545:47;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;8528:64;;8617:3;:13;;;-1:-1:-1;;;;;8610:29:2;;8640:3;:13;;;8655:1;8610:47;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;8602:81;;;;-1:-1:-1;;;8602:81:2;;;;;;;:::i;:::-;8708:13;;;;8731;;;;8701:52;;-1:-1:-1;;;8701:52:2;;-1:-1:-1;;;;;8701:29:2;;;;;;:52;;8746:6;;8701:52;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;8693:93;;;;-1:-1:-1;;;8693:93:2;;;;;;;:::i;:::-;8818:13;;;;8810:35;;-1:-1:-1;;;8810:35:2;;8796:11;;-1:-1:-1;;;;;8810:27:2;;;;:35;;8838:6;;8810:35;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;8796:49;-1:-1:-1;8863:11:2;;8855:42;;;;-1:-1:-1;;;8855:42:2;;;;;;;:::i;:::-;8931:13;;;;8923:47;;-1:-1:-1;;;8923:47:2;;8907:13;;-1:-1:-1;;;;;8923:32:2;;;;:47;;8964:4;;8923:47;;;:::i;10002:510::-;10065:4;10081:12;10104:9;-1:-1:-1;;;;;10096:28:2;;10133:4;10096:43;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;;;;10168:23:2;;10149:16;10168:23;;;:12;:23;;;;;;10081:58;;-1:-1:-1;10217:21:2;;;:52;;10268:1;10217:52;;;10241:24;:11;10257:7;10241:15;:24::i;:::-;10201:68;-1:-1:-1;10279:12:2;10295:16;;10294:68;;10319:43;10350:11;10320:24;:8;714:6;10320:12;:24::i;10319:43::-;10294:68;;;10315:1;10294:68;10279:83;-1:-1:-1;10376:11:2;;10372:97;;-1:-1:-1;;;;;10425:20:2;;;;;;:9;:20;;;;;;:33;;10450:7;10425:24;:33::i;:::-;-1:-1:-1;;;;;10402:20:2;;;;;;:9;:20;;;;;:56;10372:97;-1:-1:-1;;;;;;;;10485:20:2;;;;;;:9;:20;;;;;;;-1:-1:-1;;10002:510:2;;;:::o;3538:215:14:-;3596:7;3619:6;3615:20;;-1:-1:-1;3634:1:14;3627:8;;3615:20;3657:5;;;3661:1;3657;:5;:1;3680:5;;;;;:10;3672:56;;;;-1:-1:-1;;;3672:56:14;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4217:150;4275:7;4306:1;4302;:5;4294:44;;;;;-1:-1:-1;;;4294:44:14;;;;;;;;;;;;;;;;;;;;;;;;;;;;4359:1;4355;:5;;;;;;;4217:150;-1:-1:-1;;;4217:150:14:o;2967:751:18:-;3386:23;3412:69;3440:4;3412:69;;;;;;;;;;;;;;;;;3420:5;-1:-1:-1;;;;;3412:27:18;;;:69;;;;;:::i;:::-;3495:17;;3386:95;;-1:-1:-1;3495:21:18;3491:221;;3635:10;3624:30;;;;;;;;;;;;;;;-1:-1:-1;3624:30:18;3616:85;;;;-1:-1:-1;;;3616:85:18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3581:193:19;3684:12;3715:52;3737:6;3745:4;3751:1;3754:12;3715:21;:52::i;:::-;3708:59;;3581:193;;;;;;:::o;4608:523::-;4735:12;4792:5;4767:21;:30;;4759:81;;;;-1:-1:-1;;;4759:81:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4858:18;4869:6;4858:10;:18::i;:::-;4850:60;;;;;-1:-1:-1;;;4850:60:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;4981:12;4995:23;5022:6;-1:-1:-1;;;;;5022:11:19;5042:5;5050:4;5022:33;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;5022:33:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4980:75;;;;5072:52;5090:7;5099:10;5111:12;5072:17;:52::i;:::-;5065:59;4608:523;-1:-1:-1;;;;;;;4608:523:19:o;7091:725::-;7206:12;7234:7;7230:580;;;-1:-1:-1;7264:10:19;7257:17;;7230:580;7375:17;;:21;7371:429;;7633:10;7627:17;7693:15;7680:10;7676:2;7672:19;7665:44;7582:145;7772:12;7765:20;;-1:-1:-1;;;7765:20:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;14:142:21;95:13;;117:33;95:13;117:33;:::i;161:702::-;;280:3;273:4;265:6;261:17;257:27;247:2;;302:5;295;288:20;247:2;339;333:9;381:2;373:6;369:15;450:6;438:10;435:22;414:18;402:10;399:34;396:62;393:2;;;461:9;393:2;488;481:22;523:6;549;582:2;570:15;;567:24;-1:-1:-1;564:2:21;;;608:5;601;594:20;564:2;634:5;648:185;662:4;659:1;656:11;648:185;;;721:10;;709:23;;755:4;779:12;;;;811;;;;682:1;675:9;648:185;;;-1:-1:-1;851:6:21;;237:626;-1:-1:-1;;;;;237:626:21:o;868:162::-;962:13;;1004:1;994:12;;984:2;;1020:1;1017;1010:12;1035:259;;1147:2;1135:9;1126:7;1122:23;1118:32;1115:2;;;1168:6;1160;1153:22;1115:2;1212:9;1199:23;1231:33;1258:5;1231:33;:::i;1299:263::-;;1422:2;1410:9;1401:7;1397:23;1393:32;1390:2;;;1443:6;1435;1428:22;1390:2;1480:9;1474:16;1499:33;1526:5;1499:33;:::i;1567:402::-;;;1696:2;1684:9;1675:7;1671:23;1667:32;1664:2;;;1717:6;1709;1702:22;1664:2;1761:9;1748:23;1780:33;1807:5;1780:33;:::i;:::-;1832:5;-1:-1:-1;1889:2:21;1874:18;;1861:32;1902:35;1861:32;1902:35;:::i;:::-;1956:7;1946:17;;;1654:315;;;;;:::o;1974:539::-;;;;;2137:3;2125:9;2116:7;2112:23;2108:33;2105:2;;;2159:6;2151;2144:22;2105:2;2203:9;2190:23;2222:33;2249:5;2222:33;:::i;:::-;2274:5;-1:-1:-1;2331:2:21;2316:18;;2303:32;2344:35;2303:32;2344:35;:::i;:::-;2095:418;;2398:7;;-1:-1:-1;;;;2452:2:21;2437:18;;2424:32;;2503:2;2488:18;2475:32;;2095:418::o;2518:395::-;;;;2664:2;2652:9;2643:7;2639:23;2635:32;2632:2;;;2685:6;2677;2670:22;2632:2;2729:9;2716:23;2748:33;2775:5;2748:33;:::i;:::-;2800:5;2852:2;2837:18;;2824:32;;-1:-1:-1;2903:2:21;2888:18;;;2875:32;;2622:291;-1:-1:-1;;;2622:291:21:o;2918:297::-;;3038:2;3026:9;3017:7;3013:23;3009:32;3006:2;;;3059:6;3051;3044:22;3006:2;3096:9;3090:16;3149:5;3142:13;3135:21;3128:5;3125:32;3115:2;;3176:6;3168;3161:22;3220:1219;;3369:3;3357:9;3348:7;3344:23;3340:33;3337:2;;;3391:6;3383;3376:22;3337:2;3419:6;3447:18;3462:2;3447:18;:::i;:::-;3494:9;3488:16;3481:5;3474:31;3537:64;3597:2;3586:9;3582:18;3537:64;:::i;:::-;3532:2;3525:5;3521:14;3514:88;3634:51;3681:2;3670:9;3666:18;3634:51;:::i;:::-;3629:2;3622:5;3618:14;3611:75;3718:51;3765:2;3754:9;3750:18;3718:51;:::i;:::-;3713:2;3706:5;3702:14;3695:75;3803:52;3850:3;3839:9;3835:19;3803:52;:::i;:::-;3797:3;3790:5;3786:15;3779:77;3889:52;3936:3;3925:9;3921:19;3889:52;:::i;:::-;3883:3;3876:5;3872:15;3865:77;3975:70;4037:7;4031:3;4020:9;4016:19;3975:70;:::i;:::-;3969:3;3958:15;;3951:95;4065:3;4108:18;;;4102:25;4095:4;4084:16;;4077:51;4147:3;4192:18;;;4186:25;4177:6;4166:18;;4159:53;4231:3;4272:18;;;4266:25;4250:14;;;4243:49;;;;4330:18;;;4324:25;4308:14;;;4301:49;;;;4403:3;4388:19;;;4382:26;4366:14;;;4359:50;-1:-1:-1;3962:5:21;3327:1112;-1:-1:-1;3327:1112:21:o;4444:190::-;;4556:2;4544:9;4535:7;4531:23;4527:32;4524:2;;;4577:6;4569;4562:22;4524:2;-1:-1:-1;4605:23:21;;4514:120;-1:-1:-1;4514:120:21:o;4639:194::-;;4762:2;4750:9;4741:7;4737:23;4733:32;4730:2;;;4783:6;4775;4768:22;4730:2;-1:-1:-1;4811:16:21;;4720:113;-1:-1:-1;4720:113:21:o;4838:203::-;-1:-1:-1;;;;;5002:32:21;;;;4984:51;;4972:2;4957:18;;4939:102::o;5046:447::-;-1:-1:-1;;;;;5333:15:21;;;5315:34;;5385:15;;;;5380:2;5365:18;;5358:43;5432:2;5417:18;;5410:34;5475:2;5460:18;;5453:34;;;;5264:3;5249:19;;5231:262::o;5498:282::-;-1:-1:-1;;;;;5698:32:21;;;;5680:51;;5762:2;5747:18;;5740:34;5668:2;5653:18;;5635:145::o;6064:345::-;-1:-1:-1;;;;;6284:32:21;;;;6266:51;;6348:2;6333:18;;6326:34;;;;6391:2;6376:18;;6369:34;6254:2;6239:18;;6221:188::o;6414:187::-;6579:14;;6572:22;6554:41;;6542:2;6527:18;;6509:92::o;6830:411::-;7032:2;7014:21;;;7071:2;7051:18;;;7044:30;7110:34;7105:2;7090:18;;7083:62;-1:-1:-1;;;7176:2:21;7161:18;;7154:45;7231:3;7216:19;;7004:237::o;7246:398::-;7448:2;7430:21;;;7487:2;7467:18;;;7460:30;7526:34;7521:2;7506:18;;7499:62;-1:-1:-1;;;7592:2:21;7577:18;;7570:32;7634:3;7619:19;;7420:224::o;7649:401::-;7851:2;7833:21;;;7890:2;7870:18;;;7863:30;7929:34;7924:2;7909:18;;7902:62;-1:-1:-1;;;7995:2:21;7980:18;;7973:35;8040:3;8025:19;;7823:227::o;8055:344::-;8257:2;8239:21;;;8296:2;8276:18;;;8269:30;-1:-1:-1;;;8330:2:21;8315:18;;8308:50;8390:2;8375:18;;8229:170::o;8404:400::-;8606:2;8588:21;;;8645:2;8625:18;;;8618:30;8684:34;8679:2;8664:18;;8657:62;-1:-1:-1;;;8750:2:21;8735:18;;8728:34;8794:3;8779:19;;8578:226::o;8809:340::-;9011:2;8993:21;;;9050:2;9030:18;;;9023:30;-1:-1:-1;;;9084:2:21;9069:18;;9062:46;9140:2;9125:18;;8983:166::o;9154:399::-;9356:2;9338:21;;;9395:2;9375:18;;;9368:30;9434:34;9429:2;9414:18;;9407:62;-1:-1:-1;;;9500:2:21;9485:18;;9478:33;9543:3;9528:19;;9328:225::o;9558:407::-;9760:2;9742:21;;;9799:2;9779:18;;;9772:30;9838:34;9833:2;9818:18;;9811:62;-1:-1:-1;;;9904:2:21;9889:18;;9882:41;9955:3;9940:19;;9732:233::o;9970:401::-;10172:2;10154:21;;;10211:2;10191:18;;;10184:30;10250:34;10245:2;10230:18;;10223:62;-1:-1:-1;;;10316:2:21;10301:18;;10294:35;10361:3;10346:19;;10144:227::o;10376:413::-;10578:2;10560:21;;;10617:2;10597:18;;;10590:30;10656:34;10651:2;10636:18;;10629:62;-1:-1:-1;;;10722:2:21;10707:18;;10700:47;10779:3;10764:19;;10550:239::o;10794:352::-;10996:2;10978:21;;;11035:2;11015:18;;;11008:30;11074;11069:2;11054:18;;11047:58;11137:2;11122:18;;10968:178::o;11151:403::-;11353:2;11335:21;;;11392:2;11372:18;;;11365:30;11431:34;11426:2;11411:18;;11404:62;-1:-1:-1;;;11497:2:21;11482:18;;11475:37;11544:3;11529:19;;11325:229::o;11559:397::-;11761:2;11743:21;;;11800:2;11780:18;;;11773:30;11839:34;11834:2;11819:18;;11812:62;-1:-1:-1;;;11905:2:21;11890:18;;11883:31;11946:3;11931:19;;11733:223::o;11961:411::-;12163:2;12145:21;;;12202:2;12182:18;;;12175:30;12241:34;12236:2;12221:18;;12214:62;-1:-1:-1;;;12307:2:21;12292:18;;12285:45;12362:3;12347:19;;12135:237::o;12377:339::-;12579:2;12561:21;;;12618:2;12598:18;;;12591:30;-1:-1:-1;;;12652:2:21;12637:18;;12630:45;12707:2;12692:18;;12551:165::o;12721:403::-;12923:2;12905:21;;;12962:2;12942:18;;;12935:30;13001:34;12996:2;12981:18;;12974:62;-1:-1:-1;;;13067:2:21;13052:18;;13045:37;13114:3;13099:19;;12895:229::o;13129:344::-;13331:2;13313:21;;;13370:2;13350:18;;;13343:30;-1:-1:-1;;;13404:2:21;13389:18;;13382:50;13464:2;13449:18;;13303:170::o;13478:417::-;13680:2;13662:21;;;13719:2;13699:18;;;13692:30;13758:34;13753:2;13738:18;;13731:62;-1:-1:-1;;;13824:2:21;13809:18;;13802:51;13885:3;13870:19;;13652:243::o;13900:345::-;14102:2;14084:21;;;14141:2;14121:18;;;14114:30;-1:-1:-1;;;14175:2:21;14160:18;;14153:51;14236:2;14221:18;;14074:171::o;14250:342::-;14452:2;14434:21;;;14491:2;14471:18;;;14464:30;-1:-1:-1;;;14525:2:21;14510:18;;14503:48;14583:2;14568:18;;14424:168::o;14597:177::-;14743:25;;;14731:2;14716:18;;14698:76::o;14779:274::-;14953:25;;;-1:-1:-1;;;;;15014:32:21;15009:2;14994:18;;14987:60;14941:2;14926:18;;14908:145::o;15058:345::-;15260:25;;;-1:-1:-1;;;;;15321:32:21;;;;15316:2;15301:18;;15294:60;15385:2;15370:18;;15363:34;15248:2;15233:18;;15215:188::o;15408:417::-;15639:25;;;-1:-1:-1;;;;;15700:32:21;;;;15695:2;15680:18;;15673:60;15764:2;15749:18;;15742:34;15807:2;15792:18;;15785:34;15626:3;15611:19;;15593:232::o;15830:248::-;16004:25;;;16060:2;16045:18;;16038:34;15992:2;15977:18;;15959:119::o;16083:319::-;16285:25;;;16341:2;16326:18;;16319:34;;;;16384:2;16369:18;;16362:34;16273:2;16258:18;;16240:162::o;16407:242::-;16477:2;16471:9;16507:17;;;16554:18;16539:34;;16575:22;;;16536:62;16533:2;;;16601:9;16533:2;16628;16621:22;16451:198;;-1:-1:-1;16451:198:21:o;16654:133::-;-1:-1:-1;;;;;16731:31:21;;16721:42;;16711:2;;16777:1;16774;16767:12;16711:2;16701:86;:::o

Swarm Source

ipfs://b90b253c3bfc6dafc134899ead87ff23e2f1cd0b0cd0d663721958d40db2ff5f
Block Transaction Difficulty Gas Used Reward
Block Uncle Number Difficulty Gas Used Reward
Loading

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