Contract 0xd6B3B86209eBb3C608f3F42Bf52818169944E402

 
 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xf5a0638a95b685e8ac4a452c05c27f47d07b5bdc2f02eaaf57addb68389e76d6Settle113098692021-09-28 14:15:2712 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.002060715
0x8807e9122da3d8790ce789c8cae0cd19e209858f4561daee693363fb56db2342Settle112813792021-09-27 14:15:071 day 12 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.002060715
0xd3a12cea01f4ba67a2ff7d527893e980ccc02d2ae92b2e11a16f4cf688f26317Settle112529092021-09-26 14:15:182 days 12 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.0019385025
0x4c2bdfc08c0eec9e4c2667305bba7e1077802a3e9ad749a0b3234befbcb00167Settle112242932021-09-25 14:15:133 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.002060715
0xfb5fbdd05b58269422e4a4636e1d8fc05949c86f603f2c380b47c2d1b6a36115Settle111956442021-09-24 14:15:274 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.0019385025
0x71184049c46cc594c7c0efe38521e1bbe7b002677e86abd31607c6d86260ab57Settle111669472021-09-23 14:15:175 days 12 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.0056175525
0xc3604a9bb4ca774c376c274f6f07a819b55d045404b1341eae99199c3e4fdb32Settle111383942021-09-22 14:15:266 days 12 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.00021225
0xa4d8d4ed25c1a7ca9ba6b54f7e77d1f06f0e2cad6b0cd3c52e1ce0a3662c0ffbSettle111383932021-09-22 14:15:236 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.0019385025
0x1a1219d57930bf18573ca9dcf788a4f6e7e8a3b2ec61e21090a793b1b7dbd813Settle111098332021-09-21 14:15:097 days 12 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.00021225
0xdfea16aa78cdc28f208de1c7465eb551a42e08545c8a6a1ebc0745b872513a47Settle111098332021-09-21 14:15:097 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.002060715
0x1a12bbdff5f639ac58293dc3211a32b6092f8164ee9a32b6f6bf5d5566c542cfSettle110810942021-09-20 14:15:208 days 12 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.00021225
0x8d2485f72a95fd3677d4beea21e84d032a5c16d04040337e13f56cb8d50b4ddeSettle110810932021-09-20 14:15:178 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.0019385025
0x3131040a172e71d42fefc760de01b27bb40e3cfa73590153668c27f1baac77ccSettle110523482021-09-19 14:15:309 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.002060715
0xf022ebf4d44fce763749f08ea360d75c708affaf1ae6d58ad536a56f9b9af751Settle110238722021-09-18 14:15:1510 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.002060715
0xe47fbb215a4467d5d9a7b8fe838f5f54e48fc191aaf1fa006b403278ec82dab9Settle109951332021-09-17 14:15:2011 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.002060715
0xfc5abc390893bc9d31dc17fd2939249b2b0bfb807cfbf10bdfe48324f58e2fc8Settle109663732021-09-16 14:15:1712 days 12 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.0056175525
0x3b310a929e8fc9b49196f8021028ff1666112a1882f4af13634409b82f8fe2bdSettle109376122021-09-15 14:15:1013 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.002060715
0x84f4f958ec93bf98b668ca7662db89eb6d28bc8b3a8dadb4b6c764e31f065569Settle109089892021-09-14 14:15:2314 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.00021225
0x8986e58b5064a6ce01293788dcca686d31339b5581b4a7241cc7baa15de2e8afSettle109089872021-09-14 14:15:1714 days 12 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.002060715
0xe7da414223d67054bc9f03e9df8cef4c21c22339de7d27f4a575514febb7c579Settle108802282021-09-13 14:15:2715 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.00021225
0x6a726a0943e8f285413a0c2d844aace9df2d96e58fde7ac9a5cebdbe665df2b4Settle108802282021-09-13 14:15:2715 days 12 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.002060715
0xe6d09c2f6a612124615e44189a181510fed522322acd7055d6b490819084969aSettle108514922021-09-12 14:15:1516 days 12 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.00021225
0xb2e46ff2a66a5cdbc7f96b6a1c289cbc40445fbc65c76fd3d81f8fcde9e00958Settle108514902021-09-12 14:15:0916 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.0019385025
0x1a40b01ed8e6804289debbc9392363fc776d6b7b1898e1bfcdc3878578b0519fSettle108228282021-09-11 14:15:2017 days 12 hrs ago0x0ac8d559e8b2f6e82faff480ecf4e3d97a1928fe IN  Tranchess: BTCB Fund0 BNB0.0019385025
0xfdce36edd6818a89dcd15f4a330538472731680dad660f3325d3564ea47ef218Settle107944032021-09-10 14:15:1818 days 12 hrs ago0xbb8c8b63da6cd37e71dc40d4350cdf1886d524a1 IN  Tranchess: BTCB Fund0 BNB0.002060715
[ Download CSV Export 

OVERVIEW

Tranchess main fund tracking the price of BTCB/USDC.

Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Fund

Compiler Version
v0.6.12+commit.27d51765

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 20 : Fund.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

import "../utils/SafeDecimalMath.sol";
import "../utils/CoreUtility.sol";

import "../interfaces/IPrimaryMarket.sol";
import "../interfaces/IFund.sol";
import "../interfaces/ITwapOracle.sol";
import "../interfaces/IAprOracle.sol";
import "../interfaces/IBallot.sol";
import "../interfaces/IVotingEscrow.sol";
import "../interfaces/ITrancheIndex.sol";

import "./FundRoles.sol";

contract Fund is IFund, Ownable, ReentrancyGuard, FundRoles, CoreUtility, ITrancheIndex {
    using Math for uint256;
    using SafeMath for uint256;
    using SafeDecimalMath for uint256;
    using SafeERC20 for IERC20;

    uint256 private constant UNIT = 1e18;
    uint256 private constant MAX_INTEREST_RATE = 0.2e18; // 20% daily
    uint256 private constant MAX_DAILY_PROTOCOL_FEE_RATE = 0.05e18; // 5% daily rate

    uint256 private constant WEIGHT_A = 1;
    uint256 private constant WEIGHT_B = 1;
    uint256 private constant WEIGHT_M = WEIGHT_A + WEIGHT_B;

    /// @notice Upper bound of `NAV_B / NAV_A` to trigger a rebalance.
    uint256 public immutable upperRebalanceThreshold;

    /// @notice Lower bound of `NAV_B / NAV_A` to trigger a rebalance.
    uint256 public immutable lowerRebalanceThreshold;

    /// @notice Address of the underlying token.
    address public immutable override tokenUnderlying;

    /// @notice A multipler that normalizes an underlying balance to 18 decimal places.
    uint256 public immutable override underlyingDecimalMultiplier;

    /// @notice Daily protocol fee rate.
    uint256 public dailyProtocolFeeRate;

    /// @notice TwapOracle address for the underlying asset.
    ITwapOracle public override twapOracle;

    /// @notice AprOracle address.
    IAprOracle public aprOracle;

    /// @notice Address of the interest rate ballot.
    IBallot public ballot;

    /// @notice Fee Collector address.
    address public override feeCollector;

    /// @notice Address of Token M.
    address public override tokenM;

    /// @notice Address of Token A.
    address public override tokenA;

    /// @notice Address of Token B.
    address public override tokenB;

    /// @notice End timestamp of the current trading day.
    ///         A trading day starts at UTC time `SETTLEMENT_TIME` of a day (inclusive)
    ///         and ends at the same time of the next day (exclusive).
    uint256 public override currentDay;

    /// @notice Start timestamp of the current primary market activity window.
    uint256 public override fundActivityStartTime;

    /// @notice Start timestamp of the current exchange activity window.
    uint256 public override exchangeActivityStartTime;

    /// @dev Historical rebalances. Rebalances are often accessed in loops with bounds checking.
    ///      So we store them in a fixed-length array, in order to make compiler-generated
    ///      bounds checking on every access cheaper. The actual length of this array is stored in
    ///      `_rebalanceSize` and should be explicitly checked when necessary.
    Rebalance[65535] private _rebalances;

    /// @dev Historical rebalance count.
    uint256 private _rebalanceSize;

    /// @dev Total share supply of the three tranches. They are always rebalanced to the latest
    ///      version.
    uint256[TRANCHE_COUNT] private _totalSupplies;

    /// @dev Mapping of account => share balance of the three tranches.
    ///      Rebalance versions are stored in a separate mapping `_balanceVersions`.
    mapping(address => uint256[TRANCHE_COUNT]) private _balances;

    /// @dev Rebalance version mapping for `_balances`.
    mapping(address => uint256) private _balanceVersions;

    /// @dev Mapping of owner => spender => share allowance of the three tranches.
    ///      Rebalance versions are stored in a separate mapping `_allowanceVersions`.
    mapping(address => mapping(address => uint256[TRANCHE_COUNT])) private _allowances;

    /// @dev Rebalance version mapping for `_allowances`.
    mapping(address => mapping(address => uint256)) private _allowanceVersions;

    /// @dev Mapping of trading day => NAV tuple.
    mapping(uint256 => uint256[TRANCHE_COUNT]) private _historicalNavs;

    /// @notice Mapping of trading day => total fund shares.
    ///
    ///         Key is the end timestamp of a trading day. Value is the total fund shares after
    ///         settlement of that trading day, as if all Token A and B are merged.
    mapping(uint256 => uint256) public historicalTotalShares;

    /// @notice Mapping of trading day => underlying assets in the fund.
    ///
    ///         Key is the end timestamp of a trading day. Value is the underlying assets in
    ///         the fund after settlement of that trading day.
    mapping(uint256 => uint256) public historicalUnderlying;

    /// @notice Mapping of trading week => interest rate of Token A.
    ///
    ///         Key is the end timestamp of a trading week. Value is the interest rate captured
    ///         after settlement of the last day of the previous trading week.
    mapping(uint256 => uint256) public historicalInterestRate;

    address[] private obsoletePrimaryMarkets;
    address[] private newPrimaryMarkets;

    constructor(
        address tokenUnderlying_,
        uint256 underlyingDecimals_,
        uint256 dailyProtocolFeeRate_,
        uint256 upperRebalanceThreshold_,
        uint256 lowerRebalanceThreshold_,
        address twapOracle_,
        address aprOracle_,
        address ballot_,
        address feeCollector_
    ) public Ownable() FundRoles() {
        tokenUnderlying = tokenUnderlying_;
        require(underlyingDecimals_ <= 18, "Underlying decimals larger than 18");
        underlyingDecimalMultiplier = 10**(18 - underlyingDecimals_);
        require(
            dailyProtocolFeeRate <= MAX_DAILY_PROTOCOL_FEE_RATE,
            "Exceed max protocol fee rate"
        );
        dailyProtocolFeeRate = dailyProtocolFeeRate_;
        upperRebalanceThreshold = upperRebalanceThreshold_;
        lowerRebalanceThreshold = lowerRebalanceThreshold_;
        twapOracle = ITwapOracle(twapOracle_);
        aprOracle = IAprOracle(aprOracle_);
        ballot = IBallot(ballot_);
        feeCollector = feeCollector_;

        currentDay = endOfDay(block.timestamp);
        uint256 lastDay = currentDay - 1 days;
        uint256 currentPrice = twapOracle.getTwap(lastDay);
        require(currentPrice != 0, "Price not available");
        _historicalNavs[lastDay][TRANCHE_M] = UNIT;
        _historicalNavs[lastDay][TRANCHE_A] = UNIT;
        _historicalNavs[lastDay][TRANCHE_B] = UNIT;
        historicalInterestRate[_endOfWeek(lastDay)] = MAX_INTEREST_RATE.min(aprOracle.capture());
        fundActivityStartTime = lastDay;
        exchangeActivityStartTime = lastDay + 30 minutes;
    }

    function initialize(
        address tokenM_,
        address tokenA_,
        address tokenB_,
        address primaryMarket_
    ) external onlyOwner {
        require(tokenM == address(0) && tokenM_ != address(0), "Already initialized");
        tokenM = tokenM_;
        tokenA = tokenA_;
        tokenB = tokenB_;
        _initializeRoles(tokenM_, tokenA_, tokenB_, primaryMarket_);
    }

    /// @notice Return weights of Token A and B when splitting Token M.
    /// @return weightA Weight of Token A
    /// @return weightB Weight of Token B
    function trancheWeights() external pure override returns (uint256 weightA, uint256 weightB) {
        return (WEIGHT_A, WEIGHT_B);
    }

    /// @notice UTC time of a day when the fund settles.
    function settlementTime() external pure returns (uint256) {
        return SETTLEMENT_TIME;
    }

    /// @notice Return end timestamp of the trading day containing a given timestamp.
    ///
    ///         A trading day starts at UTC time `SETTLEMENT_TIME` of a day (inclusive)
    ///         and ends at the same time of the next day (exclusive).
    /// @param timestamp The given timestamp
    /// @return End timestamp of the trading day.
    function endOfDay(uint256 timestamp) public pure override returns (uint256) {
        return ((timestamp.add(1 days) - SETTLEMENT_TIME) / 1 days) * 1 days + SETTLEMENT_TIME;
    }

    /// @notice Return end timestamp of the trading week containing a given timestamp.
    ///
    ///         A trading week starts at UTC time `SETTLEMENT_TIME` on a Thursday (inclusive)
    ///         and ends at the same time of the next Thursday (exclusive).
    /// @param timestamp The given timestamp
    /// @return End timestamp of the trading week.
    function endOfWeek(uint256 timestamp) external pure returns (uint256) {
        return _endOfWeek(timestamp);
    }

    /// @notice Return the status of the fund contract.
    /// @param timestamp Timestamp to assess
    /// @return True if the fund contract is active
    function isFundActive(uint256 timestamp) public view override returns (bool) {
        return timestamp >= fundActivityStartTime;
    }

    /// @notice Return the status of a given primary market contract.
    /// @param primaryMarket The primary market contract address
    /// @param timestamp Timestamp to assess
    /// @return True if the primary market contract is active
    function isPrimaryMarketActive(address primaryMarket, uint256 timestamp)
        public
        view
        override
        returns (bool)
    {
        return
            isPrimaryMarket(primaryMarket) &&
            timestamp >= fundActivityStartTime &&
            timestamp < currentDay;
    }

    /// @notice Return the status of the exchange. Unlike the primary market, exchange is
    ///         anonymous to fund
    /// @param timestamp Timestamp to assess
    /// @return True if the exchange contract is active
    function isExchangeActive(uint256 timestamp) public view override returns (bool) {
        return (timestamp >= exchangeActivityStartTime && timestamp < (currentDay - 60 minutes));
    }

    /// @notice Total shares of the fund, as if all Token A and B are merged.
    function getTotalShares() public view override returns (uint256) {
        return
            _totalSupplies[TRANCHE_M].add(_totalSupplies[TRANCHE_A]).add(_totalSupplies[TRANCHE_B]);
    }

    /// @notice Return the rebalance matrix at a given index. A zero struct is returned
    ///         if `index` is out of bound.
    /// @param index Rebalance index
    /// @return A rebalance matrix
    function getRebalance(uint256 index) external view override returns (Rebalance memory) {
        return _rebalances[index];
    }

    /// @notice Return timestamp of the transaction triggering the rebalance at a given index.
    ///         Zero is returned if `index` is out of bound.
    /// @param index Rebalance index
    /// @return Timestamp of the rebalance
    function getRebalanceTimestamp(uint256 index) external view override returns (uint256) {
        return _rebalances[index].timestamp;
    }

    /// @notice Return the number of historical rebalances.
    function getRebalanceSize() external view override returns (uint256) {
        return _rebalanceSize;
    }

    /// @notice Return NAV of Token M, A and B of the given trading day.
    /// @param day End timestamp of a trading day
    /// @return NAV of Token M, A and B
    function historicalNavs(uint256 day)
        external
        view
        returns (
            uint256,
            uint256,
            uint256
        )
    {
        return (
            _historicalNavs[day][TRANCHE_M],
            _historicalNavs[day][TRANCHE_A],
            _historicalNavs[day][TRANCHE_B]
        );
    }

    /// @notice Estimate NAV of all tranches at a given timestamp, considering underlying price
    ///         change, accrued protocol fee and accrued interest since the previous settlement.
    ///
    ///         The extrapolation uses simple interest instead of daily compound interest in
    ///         calculating protocol fee and Token A's interest. There may be significant error
    ///         in the returned values when `timestamp` is far beyond the last settlement.
    /// @param timestamp Timestamp to estimate
    /// @param price Price of the underlying asset (18 decimal places)
    /// @return Estimated NAV of all tranches
    function extrapolateNav(uint256 timestamp, uint256 price)
        external
        view
        override
        returns (
            uint256,
            uint256,
            uint256
        )
    {
        // Find the last settled trading day before the given timestamp.
        uint256 previousDay = currentDay - 1 days;
        if (previousDay > timestamp) {
            previousDay = endOfDay(timestamp) - 1 days;
        }
        uint256 previousShares = historicalTotalShares[previousDay];
        uint256 navM = _extrapolateNavM(previousDay, previousShares, timestamp, price);
        uint256 navA = _extrapolateNavA(previousDay, previousShares, timestamp);
        uint256 navB = calculateNavB(navM, navA);
        return (navM, navA, navB);
    }

    function _extrapolateNavM(
        uint256 previousDay,
        uint256 previousShares,
        uint256 timestamp,
        uint256 price
    ) private view returns (uint256) {
        uint256 navM;
        if (previousShares == 0) {
            // The fund is empty. Just return the previous recorded NAV.
            navM = _historicalNavs[previousDay][TRANCHE_M];
            if (navM == 0) {
                // No NAV is recorded because the given timestamp is before the fund launches.
                return UNIT;
            } else {
                return navM;
            }
        }
        uint256 totalValue =
            price.mul(historicalUnderlying[previousDay].mul(underlyingDecimalMultiplier));
        uint256 accruedFee =
            totalValue.multiplyDecimal(dailyProtocolFeeRate).mul(timestamp - previousDay).div(
                1 days
            );
        navM = (totalValue - accruedFee).div(previousShares);
        return navM;
    }

    function _extrapolateNavA(
        uint256 previousDay,
        uint256 previousShares,
        uint256 timestamp
    ) private view returns (uint256) {
        uint256 navA = _historicalNavs[previousDay][TRANCHE_A];
        if (previousShares == 0) {
            // The fund is empty. Just return the previous recorded NAV.
            if (navA == 0) {
                // No NAV is recorded because the given timestamp is before the fund launches.
                return UNIT;
            } else {
                return navA;
            }
        }

        uint256 week = _endOfWeek(previousDay);
        uint256 newNavA =
            navA
                .multiplyDecimal(
                UNIT.sub(dailyProtocolFeeRate.mul(timestamp - previousDay).div(1 days))
            )
                .multiplyDecimal(
                UNIT.add(historicalInterestRate[week].mul(timestamp - previousDay).div(1 days))
            );
        return newNavA > navA ? newNavA : navA;
    }

    function calculateNavB(uint256 navM, uint256 navA) public pure override returns (uint256) {
        // Using unchecked multiplications because they are unlikely to overflow
        if (navM * WEIGHT_M >= navA * WEIGHT_A) {
            return (navM * WEIGHT_M - navA * WEIGHT_A) / WEIGHT_B;
        } else {
            return 0;
        }
    }

    /// @notice Transform share amounts according to the rebalance at a given index.
    ///         This function performs no bounds checking on the given index. A non-existent
    ///         rebalance transforms anything to a zero vector.
    /// @param amountM Amount of Token M before the rebalance
    /// @param amountA Amount of Token A before the rebalance
    /// @param amountB Amount of Token B before the rebalance
    /// @param index Rebalance index
    /// @return newAmountM Amount of Token M after the rebalance
    /// @return newAmountA Amount of Token A after the rebalance
    /// @return newAmountB Amount of Token B after the rebalance
    function doRebalance(
        uint256 amountM,
        uint256 amountA,
        uint256 amountB,
        uint256 index
    )
        public
        view
        override
        returns (
            uint256 newAmountM,
            uint256 newAmountA,
            uint256 newAmountB
        )
    {
        Rebalance storage rebalance = _rebalances[index];
        newAmountM = amountM
            .multiplyDecimal(rebalance.ratioM)
            .add(amountA.multiplyDecimal(rebalance.ratioA2M))
            .add(amountB.multiplyDecimal(rebalance.ratioB2M));
        uint256 ratioAB = rebalance.ratioAB; // Gas saver
        newAmountA = amountA.multiplyDecimal(ratioAB);
        newAmountB = amountB.multiplyDecimal(ratioAB);
    }

    /// @notice Transform share amounts according to rebalances in a given index range,
    ///         This function performs no bounds checking on the given indices. The original amounts
    ///         are returned if `fromIndex` is no less than `toIndex`. A zero vector is returned
    ///         if `toIndex` is greater than the number of existing rebalances.
    /// @param amountM Amount of Token M before the rebalance
    /// @param amountA Amount of Token A before the rebalance
    /// @param amountB Amount of Token B before the rebalance
    /// @param fromIndex Starting of the rebalance index range, inclusive
    /// @param toIndex End of the rebalance index range, exclusive
    /// @return newAmountM Amount of Token M after the rebalance
    /// @return newAmountA Amount of Token A after the rebalance
    /// @return newAmountB Amount of Token B after the rebalance
    function batchRebalance(
        uint256 amountM,
        uint256 amountA,
        uint256 amountB,
        uint256 fromIndex,
        uint256 toIndex
    )
        external
        view
        override
        returns (
            uint256 newAmountM,
            uint256 newAmountA,
            uint256 newAmountB
        )
    {
        for (uint256 i = fromIndex; i < toIndex; i++) {
            (amountM, amountA, amountB) = doRebalance(amountM, amountA, amountB, i);
        }
        newAmountM = amountM;
        newAmountA = amountA;
        newAmountB = amountB;
    }

    /// @notice Transform share balance to a given rebalance version, or to the latest version
    ///         if `targetVersion` is zero.
    /// @param account Account of the balance to rebalance
    /// @param targetVersion The target rebalance version, or zero for the latest version
    function refreshBalance(address account, uint256 targetVersion) external override {
        if (targetVersion > 0) {
            require(targetVersion <= _rebalanceSize, "Target version out of bound");
        }
        _refreshBalance(account, targetVersion);
    }

    /// @notice Transform allowance to a given rebalance version, or to the latest version
    ///         if `targetVersion` is zero.
    /// @param owner Owner of the allowance to rebalance
    /// @param spender Spender of the allowance to rebalance
    /// @param targetVersion The target rebalance version, or zero for the latest version
    function refreshAllowance(
        address owner,
        address spender,
        uint256 targetVersion
    ) external override {
        if (targetVersion > 0) {
            require(targetVersion <= _rebalanceSize, "Target version out of bound");
        }
        _refreshAllowance(owner, spender, targetVersion);
    }

    function shareBalanceOf(uint256 tranche, address account)
        external
        view
        override
        returns (uint256)
    {
        uint256 amountM = _balances[account][TRANCHE_M];
        uint256 amountA = _balances[account][TRANCHE_A];
        uint256 amountB = _balances[account][TRANCHE_B];

        if (tranche == TRANCHE_M) {
            if (amountM == 0 && amountA == 0 && amountB == 0) return 0;
        } else if (tranche == TRANCHE_A) {
            if (amountA == 0) return 0;
        } else {
            if (amountB == 0) return 0;
        }

        uint256 size = _rebalanceSize; // Gas saver
        for (uint256 i = _balanceVersions[account]; i < size; i++) {
            (amountM, amountA, amountB) = doRebalance(amountM, amountA, amountB, i);
        }

        if (tranche == TRANCHE_M) {
            return amountM;
        } else if (tranche == TRANCHE_A) {
            return amountA;
        } else {
            return amountB;
        }
    }

    /// @notice Return all three share balances transformed to the latest rebalance version.
    /// @param account Owner of the shares
    function allShareBalanceOf(address account)
        external
        view
        override
        returns (
            uint256,
            uint256,
            uint256
        )
    {
        uint256 amountM = _balances[account][TRANCHE_M];
        uint256 amountA = _balances[account][TRANCHE_A];
        uint256 amountB = _balances[account][TRANCHE_B];

        uint256 size = _rebalanceSize; // Gas saver
        for (uint256 i = _balanceVersions[account]; i < size; i++) {
            (amountM, amountA, amountB) = doRebalance(amountM, amountA, amountB, i);
        }

        return (amountM, amountA, amountB);
    }

    function shareBalanceVersion(address account) external view override returns (uint256) {
        return _balanceVersions[account];
    }

    function shareAllowance(
        uint256 tranche,
        address owner,
        address spender
    ) external view override returns (uint256) {
        uint256 allowanceM = _allowances[owner][spender][TRANCHE_M];
        uint256 allowanceA = _allowances[owner][spender][TRANCHE_A];
        uint256 allowanceB = _allowances[owner][spender][TRANCHE_B];

        if (tranche == TRANCHE_M) {
            if (allowanceM == 0) return 0;
        } else if (tranche == TRANCHE_A) {
            if (allowanceA == 0) return 0;
        } else {
            if (allowanceB == 0) return 0;
        }

        uint256 size = _rebalanceSize; // Gas saver
        for (uint256 i = _allowanceVersions[owner][spender]; i < size; i++) {
            (allowanceM, allowanceA, allowanceB) = _rebalanceAllowance(
                allowanceM,
                allowanceA,
                allowanceB,
                i
            );
        }

        if (tranche == TRANCHE_M) {
            return allowanceM;
        } else if (tranche == TRANCHE_A) {
            return allowanceA;
        } else {
            return allowanceB;
        }
    }

    function shareAllowanceVersion(address owner, address spender)
        external
        view
        override
        returns (uint256)
    {
        return _allowanceVersions[owner][spender];
    }

    function shareTotalSupply(uint256 tranche) external view override returns (uint256) {
        return _totalSupplies[tranche];
    }

    function mint(
        uint256 tranche,
        address account,
        uint256 amount
    ) external override onlyPrimaryMarket {
        _refreshBalance(account, _rebalanceSize);
        _mint(tranche, account, amount);
    }

    function burn(
        uint256 tranche,
        address account,
        uint256 amount
    ) external override onlyPrimaryMarket {
        _refreshBalance(account, _rebalanceSize);
        _burn(tranche, account, amount);
    }

    function transfer(
        uint256 tranche,
        address sender,
        address recipient,
        uint256 amount
    ) public override onlyShare {
        require(isFundActive(block.timestamp), "Transfer is inactive");
        _refreshBalance(sender, _rebalanceSize);
        _refreshBalance(recipient, _rebalanceSize);
        _transfer(tranche, sender, recipient, amount);
    }

    function transferFrom(
        uint256 tranche,
        address spender,
        address sender,
        address recipient,
        uint256 amount
    ) external override onlyShare returns (uint256 newAllowance) {
        transfer(tranche, sender, recipient, amount);

        _refreshAllowance(sender, spender, _rebalanceSize);
        newAllowance = _allowances[sender][spender][tranche].sub(
            amount,
            "ERC20: transfer amount exceeds allowance"
        );
        _approve(tranche, sender, spender, newAllowance);
    }

    function approve(
        uint256 tranche,
        address owner,
        address spender,
        uint256 amount
    ) external override onlyShare {
        _refreshAllowance(owner, spender, _rebalanceSize);
        _approve(tranche, owner, spender, amount);
    }

    function increaseAllowance(
        uint256 tranche,
        address sender,
        address spender,
        uint256 addedValue
    ) external override onlyShare returns (uint256 newAllowance) {
        _refreshAllowance(sender, spender, _rebalanceSize);
        newAllowance = _allowances[sender][spender][tranche].add(addedValue);
        _approve(tranche, sender, spender, newAllowance);
    }

    function decreaseAllowance(
        uint256 tranche,
        address sender,
        address spender,
        uint256 subtractedValue
    ) external override onlyShare returns (uint256 newAllowance) {
        _refreshAllowance(sender, spender, _rebalanceSize);
        newAllowance = _allowances[sender][spender][tranche].sub(subtractedValue);
        _approve(tranche, sender, spender, newAllowance);
    }

    function _transfer(
        uint256 tranche,
        address sender,
        address recipient,
        uint256 amount
    ) private {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

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

    function _mint(
        uint256 tranche,
        address account,
        uint256 amount
    ) private {
        require(account != address(0), "ERC20: mint to the zero address");

        _totalSupplies[tranche] = _totalSupplies[tranche].add(amount);
        _balances[account][tranche] = _balances[account][tranche].add(amount);
    }

    function _burn(
        uint256 tranche,
        address account,
        uint256 amount
    ) private {
        require(account != address(0), "ERC20: burn from the zero address");

        _balances[account][tranche] = _balances[account][tranche].sub(
            amount,
            "ERC20: burn amount exceeds balance"
        );
        _totalSupplies[tranche] = _totalSupplies[tranche].sub(amount);
    }

    function _approve(
        uint256 tranche,
        address owner,
        address spender,
        uint256 amount
    ) private {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender][tranche] = amount;
    }

    /// @notice Settle the current trading day. Settlement includes the following changes
    ///         to the fund.
    ///
    ///         1. Transfer protocol fee of the day to the fee collector.
    ///         2. Settle all pending creations and redemptions from all primary markets.
    ///         3. Calculate NAV of the day and trigger rebalance if necessary.
    ///         4. Capture new interest rate for Token A.
    function settle() external nonReentrant {
        uint256 day = currentDay;
        uint256 currentWeek = _endOfWeek(day - 1 days);
        require(block.timestamp >= day, "The current trading day does not end yet");
        uint256 price = twapOracle.getTwap(day);
        require(price != 0, "Underlying price for settlement is not ready yet");

        _collectFee();

        _settlePrimaryMarkets(day, price);

        // Calculate NAV
        uint256 totalShares = getTotalShares();
        uint256 underlying = IERC20(tokenUnderlying).balanceOf(address(this));
        uint256 navA = _historicalNavs[day - 1 days][TRANCHE_A];
        uint256 navM;
        if (totalShares > 0) {
            navM = price.mul(underlying.mul(underlyingDecimalMultiplier)).div(totalShares);
            if (historicalTotalShares[day - 1 days] > 0) {
                // Update NAV of Token A only when the fund is non-empty both before and after
                // this settlement
                uint256 newNavA =
                    navA.multiplyDecimal(UNIT.sub(dailyProtocolFeeRate)).multiplyDecimal(
                        historicalInterestRate[currentWeek].add(UNIT)
                    );
                if (navA < newNavA) {
                    navA = newNavA;
                }
            }
        } else {
            // If the fund is empty, use NAV of Token M in the last day
            navM = _historicalNavs[day - 1 days][TRANCHE_M];
        }
        uint256 navB = calculateNavB(navM, navA);

        if (_shouldTriggerRebalance(navA, navB)) {
            _triggerRebalance(day, navM, navA, navB);
            navM = UNIT;
            navA = UNIT;
            navB = UNIT;
            totalShares = getTotalShares();
            fundActivityStartTime = day + 12 hours;
            exchangeActivityStartTime = day + 12 hours;
        } else {
            fundActivityStartTime = day;
            exchangeActivityStartTime = day + 30 minutes;
        }

        if (currentDay == currentWeek) {
            historicalInterestRate[currentWeek + 1 weeks] = _updateInterestRate(currentWeek);
        }

        historicalTotalShares[day] = totalShares;
        historicalUnderlying[day] = underlying;
        _historicalNavs[day][TRANCHE_M] = navM;
        _historicalNavs[day][TRANCHE_A] = navA;
        _historicalNavs[day][TRANCHE_B] = navB;
        currentDay = day + 1 days;

        if (obsoletePrimaryMarkets.length > 0) {
            for (uint256 i = 0; i < obsoletePrimaryMarkets.length; i++) {
                _removePrimaryMarket(obsoletePrimaryMarkets[i]);
            }
            delete obsoletePrimaryMarkets;
        }

        if (newPrimaryMarkets.length > 0) {
            for (uint256 i = 0; i < newPrimaryMarkets.length; i++) {
                _addPrimaryMarket(newPrimaryMarkets[i]);
            }
            delete newPrimaryMarkets;
        }

        emit Settled(day, navM, navA, navB);
    }

    function addObsoletePrimaryMarket(address obsoletePrimaryMarket) external onlyOwner {
        require(isPrimaryMarket(obsoletePrimaryMarket), "The address is not a primary market");
        obsoletePrimaryMarkets.push(obsoletePrimaryMarket);
    }

    function addNewPrimaryMarket(address newPrimaryMarket) external onlyOwner {
        require(!isPrimaryMarket(newPrimaryMarket), "The address is already a primary market");
        newPrimaryMarkets.push(newPrimaryMarket);
    }

    function updateDailyProtocolFeeRate(uint256 newDailyProtocolFeeRate) external onlyOwner {
        require(
            newDailyProtocolFeeRate <= MAX_DAILY_PROTOCOL_FEE_RATE,
            "Exceed max protocol fee rate"
        );
        dailyProtocolFeeRate = newDailyProtocolFeeRate;
    }

    function updateTwapOracle(address newTwapOracle) external onlyOwner {
        twapOracle = ITwapOracle(newTwapOracle);
    }

    function updateAprOracle(address newAprOracle) external onlyOwner {
        aprOracle = IAprOracle(newAprOracle);
    }

    function updateBallot(address newBallot) external onlyOwner {
        ballot = IBallot(newBallot);
    }

    function updateFeeCollector(address newFeeCollector) external onlyOwner {
        feeCollector = newFeeCollector;
    }

    /// @dev Transfer protocol fee of the current trading day to the fee collector.
    ///      This function should be called before creation and redemption on the same day
    ///      are settled.
    function _collectFee() private {
        uint256 currentUnderlying = IERC20(tokenUnderlying).balanceOf(address(this));
        uint256 fee = currentUnderlying.multiplyDecimal(dailyProtocolFeeRate);
        if (fee > 0) {
            IERC20(tokenUnderlying).safeTransfer(address(feeCollector), fee);
        }
    }

    /// @dev Settle primary market operations in every PrimaryMarket contract.
    function _settlePrimaryMarkets(uint256 day, uint256 price) private {
        uint256 totalShares = getTotalShares();
        uint256 underlying = IERC20(tokenUnderlying).balanceOf(address(this));
        uint256 prevNavM = _historicalNavs[day - 1 days][TRANCHE_M];
        uint256 primaryMarketCount = getPrimaryMarketCount();
        for (uint256 i = 0; i < primaryMarketCount; i++) {
            uint256 price_ = price; // Fix the "stack too deep" error
            IPrimaryMarket pm = IPrimaryMarket(getPrimaryMarketMember(i));
            (
                uint256 sharesToMint,
                uint256 sharesToBurn,
                uint256 creationUnderlying,
                uint256 redemptionUnderlying,
                uint256 fee
            ) = pm.settle(day, totalShares, underlying, price_, prevNavM);
            if (sharesToMint > sharesToBurn) {
                _mint(TRANCHE_M, address(pm), sharesToMint - sharesToBurn);
            } else if (sharesToBurn > sharesToMint) {
                _burn(TRANCHE_M, address(pm), sharesToBurn - sharesToMint);
            }
            if (creationUnderlying > redemptionUnderlying) {
                IERC20(tokenUnderlying).safeTransferFrom(
                    address(pm),
                    address(this),
                    creationUnderlying - redemptionUnderlying
                );
            } else if (redemptionUnderlying > creationUnderlying) {
                IERC20(tokenUnderlying).safeTransfer(
                    address(pm),
                    redemptionUnderlying - creationUnderlying
                );
            }
            if (fee > 0) {
                IERC20(tokenUnderlying).safeTransfer(address(feeCollector), fee);
            }
        }
    }

    /// @dev Check whether a new rebalance should be triggered. Rebalance is triggered if
    ///      NAV of Token B over NAV of Token A is greater than the upper threshold or
    ///      less than the lower threshold.
    /// @param navA NAV of Token A before the rebalance
    /// @param navBOrZero NAV of Token B before the rebalance or zero if the NAV is negative
    /// @return Whether a new rebalance should be triggered
    function _shouldTriggerRebalance(uint256 navA, uint256 navBOrZero) private view returns (bool) {
        uint256 bOverA = navBOrZero.divideDecimal(navA);
        return bOverA < lowerRebalanceThreshold || bOverA > upperRebalanceThreshold;
    }

    /// @dev Create a new rebalance that resets NAV of all tranches to 1. Total supplies are
    ///      rebalanced immediately.
    /// @param day Trading day that triggers this rebalance
    /// @param navM NAV of Token M before this rebalance
    /// @param navA NAV of Token A before this rebalance
    /// @param navBOrZero NAV of Token B before this rebalance or zero if the NAV is negative
    function _triggerRebalance(
        uint256 day,
        uint256 navM,
        uint256 navA,
        uint256 navBOrZero
    ) private {
        Rebalance memory rebalance = _calculateRebalance(navM, navA, navBOrZero);
        uint256 oldSize = _rebalanceSize;
        _rebalances[oldSize] = rebalance;
        _rebalanceSize = oldSize + 1;
        emit RebalanceTriggered(
            oldSize,
            day,
            rebalance.ratioM,
            rebalance.ratioA2M,
            rebalance.ratioB2M,
            rebalance.ratioAB
        );

        (
            _totalSupplies[TRANCHE_M],
            _totalSupplies[TRANCHE_A],
            _totalSupplies[TRANCHE_B]
        ) = doRebalance(
            _totalSupplies[TRANCHE_M],
            _totalSupplies[TRANCHE_A],
            _totalSupplies[TRANCHE_B],
            oldSize
        );
        _refreshBalance(address(this), oldSize + 1);
    }

    /// @dev Create a new rebalance matrix that resets given NAVs to (1, 1, 1).
    ///
    ///      Note that NAV of Token B can be negative before the rebalance when the underlying price
    ///      drops dramatically in a single trading day, in which case zero should be passed to
    ///      this function instead of the negative NAV.
    /// @param navM NAV of Token M before the rebalance
    /// @param navA NAV of Token A before the rebalance
    /// @param navBOrZero NAV of Token B before the rebalance or zero if the NAV is negative
    /// @return The rebalance matrix
    function _calculateRebalance(
        uint256 navM,
        uint256 navA,
        uint256 navBOrZero
    ) private view returns (Rebalance memory) {
        uint256 ratioAB;
        uint256 ratioA2M;
        uint256 ratioB2M;
        if (navBOrZero <= navA) {
            // Lower rebalance
            ratioAB = navBOrZero;
            ratioA2M = ((navM - navBOrZero) * WEIGHT_M) / WEIGHT_A;
            ratioB2M = 0;
        } else {
            // Upper rebalance
            ratioAB = UNIT;
            ratioA2M = navA - UNIT;
            ratioB2M = navBOrZero - UNIT;
        }
        return
            Rebalance({
                ratioM: navM,
                ratioA2M: ratioA2M,
                ratioB2M: ratioB2M,
                ratioAB: ratioAB,
                timestamp: block.timestamp
            });
    }

    function _updateInterestRate(uint256 week) private returns (uint256) {
        uint256 baseInterestRate = MAX_INTEREST_RATE.min(aprOracle.capture());
        uint256 floatingInterestRate = ballot.count(week).div(365);
        uint256 rate = baseInterestRate.add(floatingInterestRate);

        emit InterestRateUpdated(baseInterestRate, floatingInterestRate);

        return rate;
    }

    /// @dev Transform share balance to a given rebalance version, or to the latest version
    ///      if `targetVersion` is zero. This function does no bound check on `targetVersion`.
    /// @param account Account of the balance to rebalance
    /// @param targetVersion The target rebalance version, or zero for the latest version
    function _refreshBalance(address account, uint256 targetVersion) private {
        if (targetVersion == 0) {
            targetVersion = _rebalanceSize;
        }
        uint256 oldVersion = _balanceVersions[account];
        if (oldVersion >= targetVersion) {
            return;
        }

        uint256[TRANCHE_COUNT] storage balanceTuple = _balances[account];
        uint256 balanceM = balanceTuple[TRANCHE_M];
        uint256 balanceA = balanceTuple[TRANCHE_A];
        uint256 balanceB = balanceTuple[TRANCHE_B];
        _balanceVersions[account] = targetVersion;

        if (balanceM == 0 && balanceA == 0 && balanceB == 0) {
            // Fast path for an empty account
            return;
        }

        for (uint256 i = oldVersion; i < targetVersion; i++) {
            (balanceM, balanceA, balanceB) = doRebalance(balanceM, balanceA, balanceB, i);
        }
        balanceTuple[TRANCHE_M] = balanceM;
        balanceTuple[TRANCHE_A] = balanceA;
        balanceTuple[TRANCHE_B] = balanceB;
    }

    /// @dev Transform allowance to a given rebalance version, or to the latest version
    ///      if `targetVersion` is zero. This function does no bound check on `targetVersion`.
    /// @param owner Owner of the allowance to rebalance
    /// @param spender Spender of the allowance to rebalance
    /// @param targetVersion The target rebalance version, or zero for the latest version
    function _refreshAllowance(
        address owner,
        address spender,
        uint256 targetVersion
    ) private {
        if (targetVersion == 0) {
            targetVersion = _rebalanceSize;
        }
        uint256 oldVersion = _allowanceVersions[owner][spender];
        if (oldVersion >= targetVersion) {
            return;
        }

        uint256[TRANCHE_COUNT] storage allowanceTuple = _allowances[owner][spender];
        uint256 allowanceM = allowanceTuple[TRANCHE_M];
        uint256 allowanceA = allowanceTuple[TRANCHE_A];
        uint256 allowanceB = allowanceTuple[TRANCHE_B];
        _allowanceVersions[owner][spender] = targetVersion;

        if (allowanceM == 0 && allowanceA == 0 && allowanceB == 0) {
            // Fast path for an empty allowance
            return;
        }

        for (uint256 i = oldVersion; i < targetVersion; i++) {
            (allowanceM, allowanceA, allowanceB) = _rebalanceAllowance(
                allowanceM,
                allowanceA,
                allowanceB,
                i
            );
        }
        allowanceTuple[TRANCHE_M] = allowanceM;
        allowanceTuple[TRANCHE_A] = allowanceA;
        allowanceTuple[TRANCHE_B] = allowanceB;
    }

    function _rebalanceAllowance(
        uint256 allowanceM,
        uint256 allowanceA,
        uint256 allowanceB,
        uint256 index
    )
        private
        view
        returns (
            uint256 newAllowanceM,
            uint256 newAllowanceA,
            uint256 newAllowanceB
        )
    {
        Rebalance storage rebalance = _rebalances[index];

        /// @dev using saturating arithmetic to avoid unconscious overflow revert
        newAllowanceM = allowanceM.saturatingMultiplyDecimal(rebalance.ratioM);
        newAllowanceA = allowanceA.saturatingMultiplyDecimal(rebalance.ratioAB);
        newAllowanceB = allowanceB.saturatingMultiplyDecimal(rebalance.ratioAB);
    }
}

File 2 of 20 : 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 3 of 20 : 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 4 of 20 : Math.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow, so we distribute
        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
    }
}

File 5 of 20 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../GSN/Context.sol";
/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

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

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

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

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

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

File 6 of 20 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor () internal {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 7 of 20 : SafeDecimalMath.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;

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

library SafeDecimalMath {
    using SafeMath for uint256;

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

    /* The number representing 1.0. */
    uint256 private constant UNIT = 10**uint256(decimals);

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

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

    function multiplyDecimalPrecise(uint256 x, uint256 y) internal pure returns (uint256) {
        /* Divide by UNIT to remove the extra factor introduced by the product. */
        return x.mul(y).div(PRECISE_UNIT);
    }

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

    function divideDecimalPrecise(uint256 x, uint256 y) internal pure returns (uint256) {
        /* Reintroduce the UNIT factor that will be divided out by y. */
        return x.mul(PRECISE_UNIT).div(y);
    }

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

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

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

        return quotientTimesTen.div(10);
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, and the max value of
     * uint256 on overflow.
     */
    function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }
        uint256 c = a * b;
        return c / a != b ? type(uint256).max : c;
    }

    function saturatingMultiplyDecimal(uint256 x, uint256 y) internal pure returns (uint256) {
        /* Divide by UNIT to remove the extra factor introduced by the product. */
        return saturatingMul(x, y).div(UNIT);
    }
}

File 8 of 20 : CoreUtility.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;

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

abstract contract CoreUtility {
    using SafeMath for uint256;

    /// @dev UTC time of a day when the fund settles.
    uint256 internal constant SETTLEMENT_TIME = 14 hours;

    /// @dev Return end timestamp of the trading week containing a given timestamp.
    ///
    ///      A trading week starts at UTC time `SETTLEMENT_TIME` on a Thursday (inclusive)
    ///      and ends at the same time of the next Thursday (exclusive).
    /// @param timestamp The given timestamp
    /// @return End timestamp of the trading week.
    function _endOfWeek(uint256 timestamp) internal pure returns (uint256) {
        return ((timestamp.add(1 weeks) - SETTLEMENT_TIME) / 1 weeks) * 1 weeks + SETTLEMENT_TIME;
    }
}

File 9 of 20 : IPrimaryMarket.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;

interface IPrimaryMarket {
    function claim(address account)
        external
        returns (uint256 createdShares, uint256 redeemedUnderlying);

    function settle(
        uint256 day,
        uint256 fundTotalShares,
        uint256 fundUnderlying,
        uint256 underlyingPrice,
        uint256 previousNav
    )
        external
        returns (
            uint256 sharesToMint,
            uint256 sharesToBurn,
            uint256 creationUnderlying,
            uint256 redemptionUnderlying,
            uint256 fee
        );
}

File 10 of 20 : IFund.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;
pragma experimental ABIEncoderV2;

import "./ITwapOracle.sol";

interface IFund {
    /// @notice A linear transformation matrix that represents a rebalance.
    ///
    ///         ```
    ///             [ ratioM          0        0 ]
    ///         R = [ ratioA2M  ratioAB        0 ]
    ///             [ ratioB2M        0  ratioAB ]
    ///         ```
    ///
    ///         Amounts of the three tranches `m`, `a` and `b` can be rebalanced by multiplying the matrix:
    ///
    ///         ```
    ///         [ m', a', b' ] = [ m, a, b ] * R
    ///         ```
    struct Rebalance {
        uint256 ratioM;
        uint256 ratioA2M;
        uint256 ratioB2M;
        uint256 ratioAB;
        uint256 timestamp;
    }

    function trancheWeights() external pure returns (uint256 weightA, uint256 weightB);

    function tokenUnderlying() external view returns (address);

    function tokenM() external view returns (address);

    function tokenA() external view returns (address);

    function tokenB() external view returns (address);

    function underlyingDecimalMultiplier() external view returns (uint256);

    function twapOracle() external view returns (ITwapOracle);

    function feeCollector() external view returns (address);

    function endOfDay(uint256 timestamp) external pure returns (uint256);

    function shareTotalSupply(uint256 tranche) external view returns (uint256);

    function shareBalanceOf(uint256 tranche, address account) external view returns (uint256);

    function allShareBalanceOf(address account)
        external
        view
        returns (
            uint256,
            uint256,
            uint256
        );

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

    function shareAllowance(
        uint256 tranche,
        address owner,
        address spender
    ) external view returns (uint256);

    function shareAllowanceVersion(address owner, address spender) external view returns (uint256);

    function getRebalanceSize() external view returns (uint256);

    function getRebalance(uint256 index) external view returns (Rebalance memory);

    function getRebalanceTimestamp(uint256 index) external view returns (uint256);

    function currentDay() external view returns (uint256);

    function fundActivityStartTime() external view returns (uint256);

    function exchangeActivityStartTime() external view returns (uint256);

    function isFundActive(uint256 timestamp) external view returns (bool);

    function isPrimaryMarketActive(address primaryMarket, uint256 timestamp)
        external
        view
        returns (bool);

    function isExchangeActive(uint256 timestamp) external view returns (bool);

    function getTotalShares() external view returns (uint256);

    function extrapolateNav(uint256 timestamp, uint256 price)
        external
        view
        returns (
            uint256,
            uint256,
            uint256
        );

    function calculateNavB(uint256 navM, uint256 navA) external pure returns (uint256);

    function doRebalance(
        uint256 amountM,
        uint256 amountA,
        uint256 amountB,
        uint256 index
    )
        external
        view
        returns (
            uint256 newAmountM,
            uint256 newAmountA,
            uint256 newAmountB
        );

    function batchRebalance(
        uint256 amountM,
        uint256 amountA,
        uint256 amountB,
        uint256 fromIndex,
        uint256 toIndex
    )
        external
        view
        returns (
            uint256 newAmountM,
            uint256 newAmountA,
            uint256 newAmountB
        );

    function refreshBalance(address account, uint256 targetVersion) external;

    function refreshAllowance(
        address owner,
        address spender,
        uint256 targetVersion
    ) external;

    function mint(
        uint256 tranche,
        address account,
        uint256 amount
    ) external;

    function burn(
        uint256 tranche,
        address account,
        uint256 amount
    ) external;

    function transfer(
        uint256 tranche,
        address sender,
        address recipient,
        uint256 amount
    ) external;

    function transferFrom(
        uint256 tranche,
        address spender,
        address sender,
        address recipient,
        uint256 amount
    ) external returns (uint256 newAllowance);

    function increaseAllowance(
        uint256 tranche,
        address sender,
        address spender,
        uint256 addedValue
    ) external returns (uint256 newAllowance);

    function decreaseAllowance(
        uint256 tranche,
        address sender,
        address spender,
        uint256 subtractedValue
    ) external returns (uint256 newAllowance);

    function approve(
        uint256 tranche,
        address owner,
        address spender,
        uint256 amount
    ) external;

    event RebalanceTriggered(
        uint256 indexed index,
        uint256 indexed day,
        uint256 ratioM,
        uint256 ratioA2M,
        uint256 ratioB2M,
        uint256 ratioAB
    );
    event Settled(uint256 indexed day, uint256 navM, uint256 navA, uint256 navB);
    event InterestRateUpdated(uint256 baseInterestRate, uint256 floatingInterestRate);
}

File 11 of 20 : ITwapOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;

interface ITwapOracle {
    function getTwap(uint256 timestamp) external view returns (uint256);
}

File 12 of 20 : IAprOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;

interface IAprOracle {
    function capture() external returns (uint256 dailyRate);
}

File 13 of 20 : IBallot.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;

interface IBallot {
    struct Voter {
        uint256 amount;
        uint256 unlockTime;
        uint256 weight;
    }

    function count(uint256 timestamp) external view returns (uint256);

    // An event emitted when a new proposal is created
    event Voted(
        address indexed account,
        uint256 oldAmount,
        uint256 oldUnlockTime,
        uint256 oldWeight,
        uint256 amount,
        uint256 indexed unlockTime,
        uint256 indexed weight
    );
}

File 14 of 20 : IVotingEscrow.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;
pragma experimental ABIEncoderV2;

interface IVotingEscrow {
    struct LockedBalance {
        uint256 amount;
        uint256 unlockTime;
    }

    function token() external view returns (address);

    function maxTime() external view returns (uint256);

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

    function totalSupply() external view returns (uint256);

    function balanceOfAtTimestamp(address account, uint256 timestamp)
        external
        view
        returns (uint256);

    function getTimestampDropBelow(address account, uint256 threshold)
        external
        view
        returns (uint256);

    function getLockedBalance(address account) external view returns (LockedBalance memory);
}

File 15 of 20 : ITrancheIndex.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;

/// @notice Amounts of Token M, A and B are sometimes stored in a `uint256[3]` array. This contract
///         defines index of each tranche in this array.
///
///         Solidity does not allow constants to be defined in interfaces. So this contract follows
///         the naming convention of interfaces but is implemented as an `abstract contract`.
abstract contract ITrancheIndex {
    uint256 internal constant TRANCHE_M = 0;
    uint256 internal constant TRANCHE_A = 1;
    uint256 internal constant TRANCHE_B = 2;

    uint256 internal constant TRANCHE_COUNT = 3;
}

File 16 of 20 : FundRoles.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;

import "@openzeppelin/contracts/utils/EnumerableSet.sol";

abstract contract FundRoles {
    using EnumerableSet for EnumerableSet.AddressSet;

    EnumerableSet.AddressSet private _primaryMarketMembers;
    mapping(address => bool) private _shareMembers;

    event PrimaryMarketAdded(address indexed primaryMarket);
    event PrimaryMarketRemoved(address indexed primaryMarket);

    function _initializeRoles(
        address tokenM_,
        address tokenA_,
        address tokenB_,
        address primaryMarket_
    ) internal {
        _shareMembers[tokenM_] = true;
        _shareMembers[tokenA_] = true;
        _shareMembers[tokenB_] = true;

        _addPrimaryMarket(primaryMarket_);
    }

    modifier onlyPrimaryMarket() {
        require(isPrimaryMarket(msg.sender), "FundRoles: only primary market");
        _;
    }

    function isPrimaryMarket(address account) public view returns (bool) {
        return _primaryMarketMembers.contains(account);
    }

    function getPrimaryMarketMember(uint256 index) public view returns (address) {
        return _primaryMarketMembers.at(index);
    }

    function getPrimaryMarketCount() public view returns (uint256) {
        return _primaryMarketMembers.length();
    }

    function _addPrimaryMarket(address primaryMarket) internal {
        if (_primaryMarketMembers.add(primaryMarket)) {
            emit PrimaryMarketAdded(primaryMarket);
        }
    }

    function _removePrimaryMarket(address primaryMarket) internal {
        if (_primaryMarketMembers.remove(primaryMarket)) {
            emit PrimaryMarketRemoved(primaryMarket);
        }
    }

    modifier onlyShare() {
        require(isShare(msg.sender), "FundRoles: only share");
        _;
    }

    function isShare(address account) public view returns (bool) {
        return _shareMembers[account];
    }
}

File 17 of 20 : 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, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return sub(a, b, "SafeMath: subtraction overflow");
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;

        return c;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return div(a, b, "SafeMath: division by zero");
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

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

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

File 18 of 20 : 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);
    }

    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 20 : 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;
    }
}

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

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;

        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping (bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) { // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            bytes32 lastvalue = set._values[lastIndex];

            // Move the last value to the index where the value to delete is
            set._values[toDeleteIndex] = lastvalue;
            // Update the index for the moved value
            set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        require(set._values.length > index, "EnumerableSet: index out of bounds");
        return set._values[index];
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(value)));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(value)));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(value)));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint256(_at(set._inner, index)));
    }


    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"tokenUnderlying_","type":"address"},{"internalType":"uint256","name":"underlyingDecimals_","type":"uint256"},{"internalType":"uint256","name":"dailyProtocolFeeRate_","type":"uint256"},{"internalType":"uint256","name":"upperRebalanceThreshold_","type":"uint256"},{"internalType":"uint256","name":"lowerRebalanceThreshold_","type":"uint256"},{"internalType":"address","name":"twapOracle_","type":"address"},{"internalType":"address","name":"aprOracle_","type":"address"},{"internalType":"address","name":"ballot_","type":"address"},{"internalType":"address","name":"feeCollector_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"baseInterestRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"floatingInterestRate","type":"uint256"}],"name":"InterestRateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"primaryMarket","type":"address"}],"name":"PrimaryMarketAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"primaryMarket","type":"address"}],"name":"PrimaryMarketRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"index","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"day","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ratioM","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ratioA2M","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ratioB2M","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ratioAB","type":"uint256"}],"name":"RebalanceTriggered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"day","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"navM","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"navA","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"navB","type":"uint256"}],"name":"Settled","type":"event"},{"inputs":[{"internalType":"address","name":"newPrimaryMarket","type":"address"}],"name":"addNewPrimaryMarket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"obsoletePrimaryMarket","type":"address"}],"name":"addObsoletePrimaryMarket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"allShareBalanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tranche","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"aprOracle","outputs":[{"internalType":"contract IAprOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ballot","outputs":[{"internalType":"contract IBallot","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountM","type":"uint256"},{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"},{"internalType":"uint256","name":"fromIndex","type":"uint256"},{"internalType":"uint256","name":"toIndex","type":"uint256"}],"name":"batchRebalance","outputs":[{"internalType":"uint256","name":"newAmountM","type":"uint256"},{"internalType":"uint256","name":"newAmountA","type":"uint256"},{"internalType":"uint256","name":"newAmountB","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tranche","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"navM","type":"uint256"},{"internalType":"uint256","name":"navA","type":"uint256"}],"name":"calculateNavB","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"currentDay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dailyProtocolFeeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tranche","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"uint256","name":"newAllowance","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountM","type":"uint256"},{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"doRebalance","outputs":[{"internalType":"uint256","name":"newAmountM","type":"uint256"},{"internalType":"uint256","name":"newAmountA","type":"uint256"},{"internalType":"uint256","name":"newAmountB","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"endOfDay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"endOfWeek","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"exchangeActivityStartTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"}],"name":"extrapolateNav","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeCollector","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fundActivityStartTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPrimaryMarketCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getPrimaryMarketMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRebalance","outputs":[{"components":[{"internalType":"uint256","name":"ratioM","type":"uint256"},{"internalType":"uint256","name":"ratioA2M","type":"uint256"},{"internalType":"uint256","name":"ratioB2M","type":"uint256"},{"internalType":"uint256","name":"ratioAB","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"internalType":"struct IFund.Rebalance","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRebalanceSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRebalanceTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"historicalInterestRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"day","type":"uint256"}],"name":"historicalNavs","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"historicalTotalShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"historicalUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tranche","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"uint256","name":"newAllowance","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenM_","type":"address"},{"internalType":"address","name":"tokenA_","type":"address"},{"internalType":"address","name":"tokenB_","type":"address"},{"internalType":"address","name":"primaryMarket_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"isExchangeActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"isFundActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isPrimaryMarket","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"primaryMarket","type":"address"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"isPrimaryMarketActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isShare","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lowerRebalanceThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tranche","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"targetVersion","type":"uint256"}],"name":"refreshAllowance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"targetVersion","type":"uint256"}],"name":"refreshBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"settle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"settlementTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"tranche","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"shareAllowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"shareAllowanceVersion","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tranche","type":"uint256"},{"internalType":"address","name":"account","type":"address"}],"name":"shareBalanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"shareBalanceVersion","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tranche","type":"uint256"}],"name":"shareTotalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenA","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenB","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenM","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenUnderlying","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"trancheWeights","outputs":[{"internalType":"uint256","name":"weightA","type":"uint256"},{"internalType":"uint256","name":"weightB","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"tranche","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tranche","type":"uint256"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"uint256","name":"newAllowance","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"twapOracle","outputs":[{"internalType":"contract ITwapOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlyingDecimalMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newAprOracle","type":"address"}],"name":"updateAprOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newBallot","type":"address"}],"name":"updateBallot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newDailyProtocolFeeRate","type":"uint256"}],"name":"updateDailyProtocolFeeRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newFeeCollector","type":"address"}],"name":"updateFeeCollector","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newTwapOracle","type":"address"}],"name":"updateTwapOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"upperRebalanceThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

6101006040523480156200001257600080fd5b506040516200422a3803806200422a83398101604081905262000035916200040c565b6000620000416200032c565b600080546001600160a01b0319166001600160a01b0383169081178255604051929350917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a350600180556001600160601b031960608a901b1660c0526012881115620000ce5760405162461bcd60e51b8152600401620000c590620004c0565b60405180910390fd5b6012889003600a0a60e05260055466b1a2bc2ec500001015620001055760405162461bcd60e51b8152600401620000c59062000539565b6005879055608086905260a0859052600680546001600160a01b038087166001600160a01b03199283161790925560078054868416908316179055600880548584169083161790556009805492841692909116919091179055620001694262000330565b600d819055600654604051639f05715160e01b81526201517f19909201916000916001600160a01b031690639f05715190620001aa908590600401620005a7565b60206040518083038186803b158015620001c357600080fd5b505afa158015620001d8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001fe9190620004a7565b905080620002205760405162461bcd60e51b8152600401620000c59062000570565b60008281526205001360209081526040808320670de0b6b3a764000080825560018201819055600290910155600754815163d4a3e9d760e01b81529151620002ed946001600160a01b039092169363d4a3e9d793600480820194929392918390030190829087803b1580156200029557600080fd5b505af1158015620002aa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002d09190620004a7565b6702c68af0bb1400006200037060201b62001c411790919060201c565b620500166000620002fe856200038c565b815260208101919091526040016000205550600e81905561070801600f5550620005b0975050505050505050565b3390565b600061c4e06201518061c4e0620003596201518086620003cc60201b62001c571790919060201c565b03816200036257fe5b046201518002019050919050565b600081831062000381578162000383565b825b90505b92915050565b600061c4e062093a8061c4e0620003b562093a8086620003cc60201b62001c571790919060201c565b0381620003be57fe5b0462093a8002019050919050565b600082820183811015620003835760405162461bcd60e51b8152600401620000c59062000502565b80516001600160a01b03811681146200038657600080fd5b60008060008060008060008060006101208a8c0312156200042b578485fd5b620004378b8b620003f4565b985060208a0151975060408a0151965060608a0151955060808a01519450620004648b60a08c01620003f4565b9350620004758b60c08c01620003f4565b9250620004868b60e08c01620003f4565b9150620004988b6101008c01620003f4565b90509295985092959850929598565b600060208284031215620004b9578081fd5b5051919050565b60208082526022908201527f556e6465726c79696e6720646563696d616c73206c6172676572207468616e20604082015261062760f31b606082015260800190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b6020808252601c908201527f457863656564206d61782070726f746f636f6c20666565207261746500000000604082015260600190565b60208082526013908201527f5072696365206e6f7420617661696c61626c6500000000000000000000000000604082015260600190565b90815260200190565b60805160a05160c05160601c60e051613c0a62000620600039806109235280610bf95280612a70525080610b2e52806117495280611ecd5280611f845280611fbd528061217352806121b752806121f75250806110b85280612323525080611725528061234c5250613c0a6000f3fe608060405234801561001057600080fd5b50600436106103db5760003560e01c80638da5cb5b1161020a578063d2c35ce811610125578063ed056e21116100b8578063f2ad414e11610087578063f2ad414e146107b3578063f2fde38b146107c6578063f8c8765e146107d9578063fb954b20146107ec578063fd4fc82f146107ff576103db565b8063ed056e2114610767578063eeb80ee91461077a578063eed9a1791461078d578063f20f76ba146107a0576103db565b8063d90ed209116100f4578063d90ed20914610731578063db77e2b214610739578063e780bf6c14610741578063e89900bc14610754576103db565b8063d2c35ce8146106f0578063d5002f2e14610703578063d52011c21461070b578063d5feac711461071e576103db565b8063a2f901831161019d578063bbae20ea1161016c578063bbae20ea146106af578063c415b95c146106c2578063c82c464f146106ca578063cb15d6ec146106dd576103db565b8063a2f901831461066e578063ac3910a214610681578063ad65048f14610689578063b8a5374d1461069c576103db565b8063999db3d4116101d9578063999db3d4146106225780639c6ff4f3146106355780639d657d6e146106485780639eea5f661461065b576103db565b80638da5cb5b146106025780639043292a1461060a57806393af74e11461061257806394990bd81461061a576103db565b80633a56c61c116102fa5780635c9302c91161028d578063715018a61161025c578063715018a6146105c15780637d76b991146105c9578063836a1040146105dc5780638da5c0bf146105ef576103db565b80635c9302c91461057c5780635f64b55b146105845780636809de6b1461058c5780636961b4ee146105ae576103db565b8063491f7deb116102c9578063491f7deb1461055157806350fca1bf146105645780635118a1821461056c5780635264e68114610574576103db565b80633a56c61c1461050d5780633d760bdb146105205780633fa4f59014610528578063443beba01461053e576103db565b80631d25d8ef1161037257806332050d8b1161034157806332050d8b146104cc57806336cd52a6146104d45780633806b4e6146104e757806339359a8a146104fa576103db565b80631d25d8ef1461047e57806323c794cb146104915780632629a2f3146104a4578063287ad849146104ac576103db565b80630fc63d10116103ae5780630fc63d101461042c57806311da60b4146104415780631673e9141461044b578063170d35231461046b576103db565b806301af6a8c146103e05780630553d60414610409578063094fc921146104115780630a23b9b114610419575b600080fd5b6103f36103ee366004613232565b610812565b6040516104009190613ab8565b60405180910390f35b6103f361091b565b6103f3610921565b6103f3610427366004613273565b610945565b6104346109ff565b604051610400919061342b565b610449610a0e565b005b61045e610459366004613195565b610ea1565b604051610400919061347c565b6103f36104793660046131df565b610ed0565b6103f361048c3660046131df565b610edb565b61045e61049f3660046131df565b610eef565b6103f3610ef7565b6104bf6104ba3660046131df565b610efd565b6040516104009190613a7e565b6103f3610f5b565b6104496104e23660046132ca565b610f6c565b6104496104f53660046130af565b610fe4565b61045e6105083660046131df565b61103b565b61043461051b3660046131df565b611057565b6103f3611064565b61053061106a565b604051610400929190613ac1565b6103f361054c3660046130ca565b611070565b6103f361055f3660046131df565b61109d565b6103f36110b6565b6103f36110da565b6103f36110e0565b6103f36110e8565b6104346110ee565b61059f61059a366004613365565b6110fd565b60405161040093929190613acf565b6103f36105bc366004613344565b61118a565b6104496111ab565b6103f36105d73660046132ca565b61122a565b6104496105ea36600461330f565b6112b6565b6104496105fd3660046130af565b6112f9565b610434611350565b61043461135f565b61043461136e565b61043461137d565b61045e6106303660046130af565b61138c565b610449610643366004613155565b611399565b6103f36106563660046131df565b6113ce565b61044961066936600461330f565b6113f8565b6103f361067c3660046131df565b611436565b61043461144a565b6104496106973660046130af565b611459565b6104496106aa3660046130af565b6114b0565b61059f6106bd3660046130af565b61155e565b6104346115d2565b61045e6106d83660046130af565b6115e1565b6103f36106eb3660046131df565b6115ff565b6104496106fe3660046130af565b61161e565b6103f3611675565b6103f36107193660046130af565b611698565b6103f361072c3660046132ca565b6116b5565b6103f3611723565b610434611747565b6103f361074f36600461320f565b61176b565b6103f36107623660046131df565b611867565b61059f610775366004613396565b61187b565b6104496107883660046130af565b6118b3565b61059f61079b3660046131df565b611961565b6104496107ae3660046132ca565b611982565b6104496107c13660046131df565b6119c2565b6104496107d43660046130af565b611a23565b6104496107e73660046130fe565b611ad9565b61059f6107fa366004613344565b611b94565b61044961080d366004613195565b611c09565b6001600160a01b03828116600090815262050011602090815260408083209385168352929052908120805460018201546002909201549091908661086657826108615760009350505050610914565b610891565b600187141561088057816108615760009350505050610914565b806108915760009350505050610914565b6205000b546001600160a01b0380881660009081526205001260209081526040808320938a16835292905220545b818110156108e2576108d385858584611c7c565b919650945092506001016108bf565b50876108f45783945050505050610914565b60018814156109095782945050505050610914565b509250610914915050565b9392505050565b61c4e090565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000610950336115e1565b6109755760405162461bcd60e51b815260040161096c906139b3565b60405180910390fd5b61098186858585610f6c565b61099084866205000b54611ce3565b6109e882604051806060016040528060288152602001613bad602891396001600160a01b0380881660009081526205001160209081526040808320938c1683529290522089600381106109df57fe5b01549190611dd5565b90506109f686858784611e01565b95945050505050565b600b546001600160a01b031681565b60026001541415610a315760405162461bcd60e51b815260040161096c90613a10565b6002600155600d546000610a4a6201517f198301611e89565b905081421015610a6c5760405162461bcd60e51b815260040161096c906136ff565b600654604051639f05715160e01b81526000916001600160a01b031690639f05715190610a9d908690600401613ab8565b60206040518083038186803b158015610ab557600080fd5b505afa158015610ac9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aed91906131f7565b905080610b0c5760405162461bcd60e51b815260040161096c90613582565b610b14611eb3565b610b1e8382611fad565b6000610b28611675565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401610b78919061342b565b60206040518083038186803b158015610b9057600080fd5b505afa158015610ba4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc891906131f7565b6201517f19860160009081526205001360205260408120600101549192508315610cb357610c2a84610c24610c1d867f000000000000000000000000000000000000000000000000000000000000000061223c565b889061223c565b90612276565b6201517f198801600090815262050014602052604090205490915015610cae576000868152620500166020526040812054610c9e90610c7190670de0b6b3a7640000611c57565b610c98610c91600554670de0b6b3a76400006122b890919063ffffffff16565b86906122fa565b906122fa565b905080831015610cac578092505b505b610ccd565b506201517f19860160009081526205001360205260409020545b6000610cd9828461118a565b9050610ce58382612312565b15610d2257610cf688838584612373565b50670de0b6b3a7640000915081905080610d0e611675565b61a8c08901600e819055600f559450610d30565b600e8890556107088801600f555b86600d541415610d5b57610d4387612470565b62093a80880160009081526205001660205260409020555b6000888152620500146020908152604080832088905562050015825280832087905562050013909152902082815560018101849055600201819055620151808801600d55620500175415610dfb5760005b6205001754811015610dec57610de4620500178281548110610dca57fe5b6000918252602090912001546001600160a01b03166125ec565b600101610dac565b50610dfb620500176000613032565b620500185415610e575760005b6205001854811015610e4857610e40620500188281548110610e2657fe5b6000918252602090912001546001600160a01b0316612634565b600101610e08565b50610e57620500186000613032565b877f0b88c5bd74fc625a4f651904bf835063c6a449220be319924685261fb7709dd5838584604051610e8b93929190613acf565b60405180910390a2505060018055505050505050565b6000610eac8361138c565b8015610eba5750600e548210155b8015610ec75750600d5482105b90505b92915050565b6000610eca82611e89565b620500146020526000908152604090205481565b600e54111590565b600f5481565b610f05613050565b60108261ffff8110610f1357fe5b600502016040518060a0016040529081600082015481526020016001820154815260200160028201548152602001600382015481526020016004820154815250509050919050565b6000610f67600261267b565b905090565b610f75336115e1565b610f915760405162461bcd60e51b815260040161096c906139b3565b610f9a42610eef565b610fb65760405162461bcd60e51b815260040161096c906139e2565b610fc4836205000b54612686565b610fd2826205000b54612686565b610fde84848484612751565b50505050565b610fec612856565b6000546001600160a01b039081169116146110195760405162461bcd60e51b815260040161096c906137bf565b600880546001600160a01b0319166001600160a01b0392909216919091179055565b6000600f548210158015610eca575050600d54610e0f19011190565b6000610eca60028361285a565b600e5481565b60018091565b6001600160a01b039182166000908152620500126020908152604080832093909416825291909152205490565b60006205000c82600381106110ae57fe5b015492915050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60055481565b6205000b5490565b600d5481565b600c546001600160a01b031681565b60008060008060108561ffff811061111157fe5b60050201905061115e6111318260020154886122fa90919063ffffffff16565b61115861114b84600101548b6122fa90919063ffffffff16565b8454611158908d906122fa565b90611c57565b600382015490945061117088826122fa565b935061117c87826122fa565b925050509450945094915050565b60006002830282116111a3575060028202819003610eca565b506000610eca565b6111b3612856565b6000546001600160a01b039081169116146111e05760405162461bcd60e51b815260040161096c906137bf565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000611235336115e1565b6112515760405162461bcd60e51b815260040161096c906139b3565b61126084846205000b54611ce3565b6001600160a01b03808516600090815262050011602090815260408083209387168352929052206112a0908390876003811061129857fe5b0154906122b8565b90506112ae85858584611e01565b949350505050565b6112bf3361138c565b6112db5760405162461bcd60e51b815260040161096c90613691565b6112e9826205000b54612686565b6112f4838383612866565b505050565b611301612856565b6000546001600160a01b0390811691161461132e5760405162461bcd60e51b815260040161096c906137bf565b600680546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031690565b6006546001600160a01b031681565b600a546001600160a01b031681565b6007546001600160a01b031681565b6000610eca600283612907565b80156113c3576205000b548111156113c35760405162461bcd60e51b815260040161096c90613747565b6112f4838383611ce3565b600061c4e062015180816113e28583611c57565b03816113ea57fe5b046201518002019050919050565b6114013361138c565b61141d5760405162461bcd60e51b815260040161096c90613691565b61142b826205000b54612686565b6112f483838361291c565b620500156020526000908152604090205481565b6008546001600160a01b031681565b611461612856565b6000546001600160a01b0390811691161461148e5760405162461bcd60e51b815260040161096c906137bf565b600780546001600160a01b0319166001600160a01b0392909216919091179055565b6114b8612856565b6000546001600160a01b039081169116146114e55760405162461bcd60e51b815260040161096c906137bf565b6114ee8161138c565b61150a5760405162461bcd60e51b815260040161096c9061353f565b6205001780546001810182556000919091527fdc74df4d1bc467265435b4b4806cad304a5e2ba6107cd8428a78b09a9935dc420180546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03811660009081526205000f60209081526040808320805460018201546002909201546205000b54620500109095529285205485948594929392915b818110156115c4576115b5858585846110fd565b919650945092506001016115a1565b509297919650945092505050565b6009546001600160a01b031681565b6001600160a01b031660009081526004602052604090205460ff1690565b600060108261ffff811061160f57fe5b60050201600401549050919050565b611626612856565b6000546001600160a01b039081169116146116535760405162461bcd60e51b815260040161096c906137bf565b600980546001600160a01b0319166001600160a01b0392909216919091179055565b6205000e546205000d54600091610f6791611158906205000c855b015490611c57565b6001600160a01b0316600090815262050010602052604090205490565b60006116c0336115e1565b6116dc5760405162461bcd60e51b815260040161096c906139b3565b6116eb84846205000b54611ce3565b6001600160a01b03808516600090815262050011602090815260408083209387168352929052206112a0908390876003811061169057fe5b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b6001600160a01b03811660009081526205000f6020526040812080546001820154600290920154909190856117c657821580156117a6575081155b80156117b0575080155b156117c15760009350505050610eca565b6117f1565b60018614156117e057816117c15760009350505050610eca565b806117f15760009350505050610eca565b6205000b546001600160a01b03861660009081526205001060205260409020545b8181101561183557611826858585846110fd565b91965094509250600101611812565b50866118475783945050505050610eca565b600187141561185c5782945050505050610eca565b509250610eca915050565b620500166020526000908152604090205481565b60008080845b848110156118a457611895898989846110fd565b919a5098509650600101611881565b50969795965093949350505050565b6118bb612856565b6000546001600160a01b039081169116146118e85760405162461bcd60e51b815260040161096c906137bf565b6118f18161138c565b1561190e5760405162461bcd60e51b815260040161096c906137f4565b6205001880546001810182556000919091527e9340f16b65397f216be6c1432cec66d2ee87dc6950e7794214e8e4d8716d2c0180546001600160a01b0319166001600160a01b0392909216919091179055565b60009081526205001360205260409020805460018201546002909201549092565b61198b336115e1565b6119a75760405162461bcd60e51b815260040161096c906139b3565b6119b683836205000b54611ce3565b610fde84848484611e01565b6119ca612856565b6000546001600160a01b039081169116146119f75760405162461bcd60e51b815260040161096c906137bf565b66b1a2bc2ec50000811115611a1e5760405162461bcd60e51b815260040161096c906136c8565b600555565b611a2b612856565b6000546001600160a01b03908116911614611a585760405162461bcd60e51b815260040161096c906137bf565b6001600160a01b038116611a7e5760405162461bcd60e51b815260040161096c906135d2565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b611ae1612856565b6000546001600160a01b03908116911614611b0e5760405162461bcd60e51b815260040161096c906137bf565b600a546001600160a01b0316158015611b2f57506001600160a01b03841615155b611b4b5760405162461bcd60e51b815260040161096c9061393c565b600a80546001600160a01b038087166001600160a01b031992831617909255600b8054868416908316179055600c805492851692909116919091179055610fde848484846129cd565b60008060008062015180600d5403905085811115611bbd5762015180611bb9876113ce565b0390505b600081815262050014602052604081205490611bdb83838a8a612a1e565b90506000611bea84848b612ae1565b90506000611bf8838361118a565b929a91995091975095505050505050565b8015611c33576205000b54811115611c335760405162461bcd60e51b815260040161096c90613747565b611c3d8282612686565b5050565b6000818310611c505781610ec7565b5090919050565b600082820183811015610ec75760405162461bcd60e51b815260040161096c9061365a565b60008060008060108561ffff8110611c9057fe5b600502018054909150611ca4908990612bb2565b9350611cbd816003015488612bb290919063ffffffff16565b9250611cd6816003015487612bb290919063ffffffff16565b9150509450945094915050565b80611cef57506205000b545b6001600160a01b038084166000908152620500126020908152604080832093861683529290522054818110611d2457506112f4565b6001600160a01b03848116600081815262050011602090815260408083209488168084529482528083208054600182015460028301549686526205001285528386209786529690935292208690559092909182158015611d82575081155b8015611d8c575080155b15611d9b5750505050506112f4565b845b86811015611dc057611db184848484611c7c565b91955093509150600101611d9d565b50918355600183015560029091015550505050565b60008184841115611df95760405162461bcd60e51b815260040161096c9190613487565b505050900390565b6001600160a01b038316611e275760405162461bcd60e51b815260040161096c906138c1565b6001600160a01b038216611e4d5760405162461bcd60e51b815260040161096c90613618565b6001600160a01b038084166000908152620500116020908152604080832093861683529290522081908560038110611e8157fe5b015550505050565b600061c4e062093a8081611e9d8583611c57565b0381611ea557fe5b0462093a8002019050919050565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823190611f0290309060040161342b565b60206040518083038186803b158015611f1a57600080fd5b505afa158015611f2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f5291906131f7565b90506000611f6b600554836122fa90919063ffffffff16565b90508015611c3d57600954611c3d906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116911683612bca565b6000611fb7611675565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401612007919061342b565b60206040518083038186803b15801561201f57600080fd5b505afa158015612033573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061205791906131f7565b6201517f198501600090815262050013602052604081205491925061207a610f5b565b905060005b818110156122335785600061209383611057565b90506000806000806000856001600160a01b0316635235bf908f8e8e8b8f6040518663ffffffff1660e01b81526004016120d1959493929190613b00565b60a060405180830381600087803b1580156120eb57600080fd5b505af11580156120ff573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061212391906133d0565b945094509450945094508385111561214857612143600087868803612866565b61215e565b8484111561215e5761215e60008787870361291c565b818311156121a25761219d6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168730858703612c20565b6121e0565b828211156121e0576121e06001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001687858503612bca565b801561222057600954612220906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116911683612bca565b50506001909501945061207f9350505050565b50505050505050565b60008261224b57506000610eca565b8282028284828161225857fe5b0414610ec75760405162461bcd60e51b815260040161096c9061377e565b6000610ec783836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612c41565b6000610ec783836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611dd5565b6000610ec7670de0b6b3a7640000610c24858561223c565b60008061231f8385612c78565b90507f00000000000000000000000000000000000000000000000000000000000000008110806112ae57507f0000000000000000000000000000000000000000000000000000000000000000109392505050565b61237b613050565b612386848484612c90565b6205000b549091508160108261ffff811061239d57fe5b600502016000820151816000015560208201518160010155604082015181600201556060820151816003015560808201518160040155905050806001016205000b8190555085817f2646fce1ab948f0064ff11ff23fe1fb2b482174464b400d834c25fe6d564d62e84600001518560200151866040015187606001516040516124299493929190613ae5565b60405180910390a36205000c546205000d546205000e5461244c929190846110fd565b6205000e556205000d556205000c556124683060018301612686565b505050505050565b60008061250d600760009054906101000a90046001600160a01b03166001600160a01b031663d4a3e9d76040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156124c657600080fd5b505af11580156124da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124fe91906131f7565b6702c68af0bb14000090611c41565b600854604051630766a8d960e31b815291925060009161259b9161016d916001600160a01b0390911690633b3546c89061254b908990600401613ab8565b60206040518083038186803b15801561256357600080fd5b505afa158015612577573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2491906131f7565b905060006125a98383611c57565b90507f41e376fd99913dea7fda140f5c0bd997515b1a181acc58737320322548ec6e7283836040516125dc929190613ac1565b60405180910390a1949350505050565b6125f7600282612cfe565b15612631576040516001600160a01b038216907f9a3d6285c0c0ecadb50aeb8ce65db861aa9107eff2d78ba69610fe6c7d854b5290600090a25b50565b61263f600282612d13565b15612631576040516001600160a01b038216907f07dcfbc227b93d1631b8861a3f6b9c2b79b5d2ca159fe4f90ced4cc46c97d58e90600090a250565b6000610eca82612d28565b8061269257506205000b545b6001600160a01b03821660009081526205001060205260409020548181106126ba5750611c3d565b6001600160a01b03831660009081526205000f6020908152604080832080546001820154600283015462050010909552929094208690559291821580156126ff575081155b8015612709575080155b15612718575050505050611c3d565b845b8681101561273d5761272e848484846110fd565b9195509350915060010161271a565b509183556001830155600290910155505050565b6001600160a01b0383166127775760405162461bcd60e51b815260040161096c9061387c565b6001600160a01b03821661279d5760405162461bcd60e51b815260040161096c906134fc565b6127df81604051806060016040528060268152602001613b87602691396001600160a01b03861660009081526205000f6020526040902087600381106109df57fe5b6001600160a01b03841660009081526205000f60205260409020856003811061280457fe5b01556001600160a01b03821660009081526205000f60205260409020612831908290866003811061169057fe5b6001600160a01b03831660009081526205000f602052604090208560038110611e8157fe5b3390565b6000610ec78383612d2c565b6001600160a01b03821661288c5760405162461bcd60e51b815260040161096c90613a47565b61289f816205000c856003811061169057fe5b6205000c84600381106128ae57fe5b01556001600160a01b03821660009081526205000f602052604090206128db908290856003811061169057fe5b6001600160a01b03831660009081526205000f60205260409020846003811061290057fe5b0155505050565b6000610ec7836001600160a01b038416612d71565b6001600160a01b0382166129425760405162461bcd60e51b815260040161096c9061383b565b61298481604051806060016040528060228152602001613b65602291396001600160a01b03851660009081526205000f6020526040902086600381106109df57fe5b6001600160a01b03831660009081526205000f6020526040902084600381106129a957fe5b01556129be816205000c856003811061129857fe5b6205000c846003811061290057fe5b6001600160a01b038481166000908152600460205260408082208054600160ff19918216811790925587851684528284208054821683179055938616835291208054909216179055610fde81612634565b60008084612a555750600085815262050013602052604090205480612a4e57670de0b6b3a76400009150506112ae565b90506112ae565b6000868152620500156020526040812054612a9b90612a94907f000000000000000000000000000000000000000000000000000000000000000061223c565b859061223c565b90506000612ac762015180610c248a8903612ac1600554876122fa90919063ffffffff16565b9061223c565b9050612ad581830388612276565b98975050505050505050565b600083815262050013602052604081206001015483612b175780612b1057670de0b6b3a7640000915050610914565b9050610914565b6000612b2286611e89565b600081815262050016602052604081205491925090612b9690612b6390612b54906201518090610c24908c8b0361223c565b670de0b6b3a764000090611c57565b610c98610c91612b8762015180610c248d8c0360055461223c90919063ffffffff16565b670de0b6b3a7640000906122b8565b9050828111612ba55782612ba7565b805b979650505050505050565b6000610ec7670de0b6b3a7640000610c248585612d89565b6112f48363a9059cbb60e01b8484604051602401612be9929190613463565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612dbd565b610fde846323b872dd60e01b858585604051602401612be99392919061343f565b60008183612c625760405162461bcd60e51b815260040161096c9190613487565b506000838581612c6e57fe5b0495945050505050565b6000610ec782610c2485670de0b6b3a764000061223c565b612c98613050565b6000806000858511612cb65750839150506002818603026000612cd4565b50670de0b6b3a7640000915050670de0b6b3a763ffff198085019084015b6040805160a081018252978852602088019290925290860152606085015250504260808301525090565b6000610ec7836001600160a01b038416612e4c565b6000610ec7836001600160a01b038416612f12565b5490565b81546000908210612d4f5760405162461bcd60e51b815260040161096c906134ba565b826000018281548110612d5e57fe5b9060005260206000200154905092915050565b60009081526001919091016020526040902054151590565b600082612d9857506000610eca565b82820282848281612da557fe5b041415612db257806112ae565b506000199392505050565b6060612e12826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612f549092919063ffffffff16565b8051909150156112f45780806020019051810190612e3091906131bf565b6112f45760405162461bcd60e51b815260040161096c90613969565b60008181526001830160205260408120548015612f085783546000198083019190810190600090879083908110612e7f57fe5b9060005260206000200154905080876000018481548110612e9c57fe5b600091825260208083209091019290925582815260018981019092526040902090840190558654879080612ecc57fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610eca565b6000915050610eca565b6000612f1e8383612d71565b6111a357508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610eca565b60606112ae848460008585612f6885612ff3565b612f845760405162461bcd60e51b815260040161096c90613905565b60006060866001600160a01b03168587604051612fa1919061340f565b60006040518083038185875af1925050503d8060008114612fde576040519150601f19603f3d011682016040523d82523d6000602084013e612fe3565b606091505b5091509150612ba7828286612ff9565b3b151590565b60608315613008575081610914565b8251156130185782518084602001fd5b8160405162461bcd60e51b815260040161096c9190613487565b5080546000825590600052602060002090810190612631919061307f565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b5b808211156130945760008155600101613080565b5090565b80356001600160a01b0381168114610eca57600080fd5b6000602082840312156130c0578081fd5b610ec78383613098565b600080604083850312156130dc578081fd5b6130e68484613098565b91506130f58460208501613098565b90509250929050565b60008060008060808587031215613113578182fd5b61311d8686613098565b935061312c8660208701613098565b925061313b8660408701613098565b915061314a8660608701613098565b905092959194509250565b600080600060608486031215613169578283fd5b833561317481613b4f565b9250602084013561318481613b4f565b929592945050506040919091013590565b600080604083850312156131a7578182fd5b6131b18484613098565b946020939093013593505050565b6000602082840312156131d0578081fd5b81518015158114610ec7578182fd5b6000602082840312156131f0578081fd5b5035919050565b600060208284031215613208578081fd5b5051919050565b60008060408385031215613221578182fd5b823591506130f58460208501613098565b600080600060608486031215613246578283fd5b83359250602084013561325881613b4f565b9150604084013561326881613b4f565b809150509250925092565b600080600080600060a0868803121561328a578081fd5b8535945061329b8760208801613098565b93506132aa8760408801613098565b92506132b98760608801613098565b949793965091946080013592915050565b600080600080608085870312156132df578384fd5b843593506132f08660208701613098565b92506132ff8660408701613098565b9396929550929360600135925050565b600080600060608486031215613323578283fd5b833592506133348560208601613098565b9150604084013590509250925092565b60008060408385031215613356578182fd5b50508035926020909101359150565b6000806000806080858703121561337a578182fd5b5050823594602084013594506040840135936060013592509050565b600080600080600060a086880312156133ad578283fd5b505083359560208501359550604085013594606081013594506080013592509050565b600080600080600060a086880312156133e7578283fd5b5050835160208501516040860151606087015160809097015192989197509594509092509050565b60008251613421818460208701613b23565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b60006020825282518060208401526134a6816040850160208701613b23565b601f01601f19169190910160400192915050565b60208082526022908201527f456e756d657261626c655365743a20696e646578206f7574206f6620626f756e604082015261647360f01b606082015260800190565b60208082526023908201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260408201526265737360e81b606082015260800190565b60208082526023908201527f5468652061646472657373206973206e6f742061207072696d617279206d61726040820152621ad95d60ea1b606082015260800190565b60208082526030908201527f556e6465726c79696e6720707269636520666f7220736574746c656d656e742060408201526f1a5cc81b9bdd081c9958591e481e595d60821b606082015260800190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b60208082526022908201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604082015261737360f01b606082015260800190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b6020808252601e908201527f46756e64526f6c65733a206f6e6c79207072696d617279206d61726b65740000604082015260600190565b6020808252601c908201527f457863656564206d61782070726f746f636f6c20666565207261746500000000604082015260600190565b60208082526028908201527f5468652063757272656e742074726164696e672064617920646f6573206e6f7460408201526708195b99081e595d60c21b606082015260800190565b6020808252601b908201527f5461726765742076657273696f6e206f7574206f6620626f756e640000000000604082015260600190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526027908201527f546865206164647265737320697320616c72656164792061207072696d617279604082015266081b585c9ad95d60ca1b606082015260800190565b60208082526021908201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736040820152607360f81b606082015260800190565b60208082526025908201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604082015264647265737360d81b606082015260800190565b60208082526024908201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646040820152637265737360e01b606082015260800190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b602080825260139082015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b604082015260600190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b60208082526015908201527446756e64526f6c65733a206f6e6c7920736861726560581b604082015260600190565b6020808252601490820152735472616e7366657220697320696e61637469766560601b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6020808252601f908201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604082015260600190565b600060a082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015292915050565b90815260200190565b918252602082015260400190565b9283526020830191909152604082015260600190565b93845260208401929092526040830152606082015260800190565b948552602085019390935260408401919091526060830152608082015260a00190565b60005b83811015613b3e578181015183820152602001613b26565b83811115610fde5750506000910152565b6001600160a01b038116811461263157600080fdfe45524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a26469706673582212207f877c75e69ae3bc33805c85bb603c19ea2d693ca1280e91c6b7762021a6c0e264736f6c634300060c00330000000000000000000000007130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000190af13c5e390000000000000000000000000000000000000000000000001bc16d674ec8000000000000000000000000000000000000000000000000000006f05b59d3b20000000000000000000000000000d924955c92a67d32e0c10e686a6003b22ecfba280000000000000000000000008424d933fbb73665e5a8880de63c7b1366a56eed000000000000000000000000e8061a74412e78dda7a762b8f6361518bb9783d30000000000000000000000000a599ea28beb703f04f45d566e91c94f2761bb26

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

0000000000000000000000007130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000190af13c5e390000000000000000000000000000000000000000000000001bc16d674ec8000000000000000000000000000000000000000000000000000006f05b59d3b20000000000000000000000000000d924955c92a67d32e0c10e686a6003b22ecfba280000000000000000000000008424d933fbb73665e5a8880de63c7b1366a56eed000000000000000000000000e8061a74412e78dda7a762b8f6361518bb9783d30000000000000000000000000a599ea28beb703f04f45d566e91c94f2761bb26

-----Decoded View---------------
Arg [0] : tokenUnderlying_ (address): 0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c
Arg [1] : underlyingDecimals_ (uint256): 18
Arg [2] : dailyProtocolFeeRate_ (uint256): 27534787632697
Arg [3] : upperRebalanceThreshold_ (uint256): 2000000000000000000
Arg [4] : lowerRebalanceThreshold_ (uint256): 500000000000000000
Arg [5] : twapOracle_ (address): 0xd924955c92a67d32e0c10e686a6003b22ecfba28
Arg [6] : aprOracle_ (address): 0x8424d933fbb73665e5a8880de63c7b1366a56eed
Arg [7] : ballot_ (address): 0xe8061a74412e78dda7a762b8f6361518bb9783d3
Arg [8] : feeCollector_ (address): 0x0a599ea28beb703f04f45d566e91c94f2761bb26

-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 0000000000000000000000007130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000012
Arg [2] : 0000000000000000000000000000000000000000000000000000190af13c5e39
Arg [3] : 0000000000000000000000000000000000000000000000001bc16d674ec80000
Arg [4] : 00000000000000000000000000000000000000000000000006f05b59d3b20000
Arg [5] : 000000000000000000000000d924955c92a67d32e0c10e686a6003b22ecfba28
Arg [6] : 0000000000000000000000008424d933fbb73665e5a8880de63c7b1366a56eed
Arg [7] : 000000000000000000000000e8061a74412e78dda7a762b8f6361518bb9783d3
Arg [8] : 0000000000000000000000000a599ea28beb703f04f45d566e91c94f2761bb26


Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.