Contract 0xa17bda2B0a0bE2B4eC9D3873CC54Dda852FDc990 2

Txn Hash Method
Block
From
To
Value [Txn Fee]
0xe4d6b1d35c4e4d1a0802567f4d066d1bd3c4110920bba5dff5caa7ae165e9df2Set Oracle201856322022-09-23 18:08:245 days 17 hrs ago0xe6edf5d683d74a2f5623284d4722bcdbf1fd7d43 IN  0xa17bda2b0a0be2b4ec9d3873cc54dda852fdc9900 AVAX0.00116797525
0xbb0617f3a8bebb3f82ace86aa296ab5a31adbddfd4366c46affb632ed8f1ad7dSet Oracle201856302022-09-23 18:08:195 days 17 hrs ago0xe6edf5d683d74a2f5623284d4722bcdbf1fd7d43 IN  0xa17bda2b0a0be2b4ec9d3873cc54dda852fdc9900 AVAX0.00116797525
0x5e445e20c18d28b40eae5b2c8467cc14014392e9d47e052950347f2829ae0e19Set Oracle201856272022-09-23 18:08:135 days 17 hrs ago0xe6edf5d683d74a2f5623284d4722bcdbf1fd7d43 IN  0xa17bda2b0a0be2b4ec9d3873cc54dda852fdc9900 AVAX0.00116797525
0x89c59b61a3ff271c00326e33930261828529bc455e97601c05bdfeea52209c7e0x60806040201853842022-09-23 17:59:405 days 17 hrs ago0xe878d69526e611d0e547bcfd64f5a28d15ae20fd IN  Create: StrategyAlphaHomora0 AVAX0.124387625
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
StrategyAlphaHomora

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 28 : AHStrategy.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "IERC20Upgradeable.sol";
import "ERC20Upgradeable.sol";
import "AddressUpgradeable.sol";
import "SafeERC20Upgradeable.sol";
import "SafeERC20.sol";
import "IController.sol";
import "IBank.sol";
import "IUniswapRouterV2.sol";
import "IUniswapV2Pair.sol";
import "IUniswapV2Factory.sol";
import "AggregatorV3Interface.sol";
import "IBaseOracle.sol";
import {BaseStrategy} from "BaseStrategy.sol";


contract StrategyAlphaHomora is BaseStrategy {
    using SafeERC20Upgradeable for IERC20Upgradeable;
    using AddressUpgradeable for address;

    event TreeDistribution(
        address indexed token,
        uint256 amount,
        uint256 indexed blockNumber,
        uint256 timestamp
    );

    event RebalanceDone(
        uint256 gradient,
        uint256 indexed blockNumber,
        uint256 timestamp
    );

    event Harvest(uint256 stableAmount);

    struct Amounts {
        uint256 aUser; // Supplied tokenA amount
        uint256 bUser; // Supplied tokenB amount
        uint256 lpUser; // Supplied LP token amount
        uint256 aBorrow; // Borrow tokenA amount
        uint256 bBorrow; // Borrow tokenB amount
        uint256 lpBorrow; // Borrow LP token amount
        uint256 aMin; // Desired tokenA amount (slippage control)
        uint256 bMin; // Desired tokenB amount (slippage control)
    }

    struct RepayAmounts {
        uint256 lpTake; // Take out LP token amount (from Homora)
        uint256 lpWithdraw; // Withdraw LP token amount (back to caller)
        uint256 aRepay; // Repay tokenA amount
        uint256 bRepay; // Repay tokenB amount
        uint256 lpRepay; // Repay LP token amount
        uint256 aMin; // Desired tokenA amount
        uint256 bMin; // Desired tokenB amount
    }

    address public lpComponent;
    bool public activeDistribution;

    address public blueSwanTree;

    uint256 public slippage;

    address public spell;
    address public homoraBank;
    address public volatileToken;
    address public lpToken;
    address public router;
    address[] public rewards;
    uint256 public pid;
    uint256 public positionId;
    uint256 public leverage;
    uint256 public priceAnchor;
    uint256 public stableSupplied;
    uint256 public numRebalances;
    uint256 ammCheckThreshold;
    uint256 debtRatioThreshold;
    uint256 volatilityThreshold;
    mapping(address=>address) oracles;    
    address homoraOracle;

    uint256 PRECISION;
    uint256 MAX_INT;

    string constant spellOpen =
        "addLiquidityWMasterChef(address,address,(uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256),uint256)";
    string constant spellClose =
        "removeLiquidityWMasterChef(address,address,(uint256,uint256,uint256,uint256,uint256,uint256,uint256))";
    string constant spellHarvest = "harvestWMasterChef()";
    string nameOfStrategy;

    constructor(
        address _governance,
        address _strategist,
        address _controller,
        address _keeper,
        address _guardian,
        uint256 _pid,
        uint256 _leverage,        
        address[] memory config,
        address[] memory _rewards,
        uint256[3] memory _feeConfig,
        address _vault
    ){
        __BaseStrategy_init(
            _governance,
            _strategist,
            _controller,
            _keeper,
            _guardian
        );

        PRECISION = 1e12;
        MAX_INT = 2**256 - 1;

        leverage = _leverage;
        ammCheckThreshold = PRECISION / 100;
        debtRatioThreshold = 99 * PRECISION / 100;
        volatilityThreshold = PRECISION; // Don't perform any rebalance or harvest, if volatility is at 100%        
        spell = config[0];
        homoraBank = config[1];
        lpToken = config[2];
        router = config[3];
        homoraOracle=config[4];
        stableToken = IUniswapV2Pair(lpToken).token0();
        depositToken = stableToken;
        volatileToken = IUniswapV2Pair(lpToken).token1();
        pid = _pid;
        for (uint256 j = 0; j < _rewards.length; j++) {
            rewards.push(_rewards[j]);
        }

        performanceFeeGovernance = _feeConfig[0];
        performanceFeeStrategist = _feeConfig[1];
        withdrawalFee = _feeConfig[2];

        address[] memory path = new address[](2);
        path[0] = volatileToken;
        path[1] = stableToken;
        priceAnchor = _routerQuote(
            uint256(10)**ERC20Upgradeable(volatileToken).decimals(),
            path
        );

        vault = _vault;
        slippage = PRECISION / 50; // 2% slippage allowance

        // Approvals
        IERC20(stableToken).approve(homoraBank, MAX_INT);
        IERC20(volatileToken).approve(homoraBank, MAX_INT);
        IERC20(lpToken).approve(homoraBank, MAX_INT);
        IERC20(stableToken).approve(router, MAX_INT);
        IERC20(volatileToken).approve(router, MAX_INT);
        IERC20(lpToken).approve(router, MAX_INT);
        for (uint256 i = 0; i < rewards.length; i++) {
            IERC20(rewards[i]).approve(router, MAX_INT);
        }
    }

    /// ===== View Functions =====

    // @dev Specify the name of the strategy
    function getName() external virtual pure override returns (string memory) {
        return "LYF-AH-STRATEGY";
    }

    // @dev Specify the version of the Strategy, for upgrades
    function version() external pure returns (string memory) {
        return "1.0";
    }

    /// @dev Balance of want-USDC currently held in strategy positions in POOL
    /// This returns the expected closing equity from unwinding the position after
    /// debt repayment
    function balanceOfPool() public view override returns (uint256) {
        uint256 collateral = getCollateralSize();
        (uint256 debt0, uint256 debt1) = getDebts();
        (uint256 r0, uint256 r1, ) = IUniswapV2Pair(lpToken).getReserves();
        uint256 totalSupply = IUniswapV2Pair(lpToken).totalSupply();
        uint256 supply0 = (r0 * collateral) / totalSupply;
        uint256 supply1 = (r1 * collateral) / totalSupply;
        uint256 equity0 = supply0 - debt0;
        address[] memory path = new address[](2);
        path[0] = volatileToken;
        path[1] = stableToken;
        uint256 expectedEquity;
        if (supply1 > debt1) {
            expectedEquity = equity0 + _routerQuote(supply1 - debt1, path);
        } else {
            expectedEquity = equity0;
        }
        return expectedEquity;
    }

    /// @notice Change reward getter
    /// @notice Can only be changed by governance
    function setBlueSwanTree(address _blueSwanAddress) external {
        _onlyAuthorizedActors();
        blueSwanTree = _blueSwanAddress;
    }

    /// @notice Change distribution strategy to active-passive
    /// @notice Can only be changed by governance
    function setActiveDistrution(bool _active) external {
        _onlyAuthorizedActors();
        activeDistribution = _active;
    }

    function setOracle(address token, address oracle) external {
        _onlyAuthorizedActors();
        oracles[token] = oracle;
    }

    function setLeverage(uint256 _leverage) external {
        _onlyAuthorizedActors();
        leverage = _leverage;
    }

    /// ===== Internal Core Implementations =====

    function _oraclePrice(address token) internal view returns (uint) {
        uint tokenDecimals = ERC20Upgradeable(token).decimals();
        uint stableDecimals = ERC20Upgradeable(stableToken).decimals();
        uint tokenPrice = IBaseOracle(homoraOracle).getETHPx(token)*uint(10)**tokenDecimals;
        uint stablePrice = IBaseOracle(homoraOracle).getETHPx(stableToken)*uint(10)**stableDecimals;
        uint tokenPriceUsdc = (tokenPrice*uint(10)**stableDecimals)/stablePrice;
        return tokenPriceUsdc;
    }

    /// @dev Check if router price matches oracle price        
    function _ammCheck() internal view returns (bool) {
        uint256 oraclePrice = _oraclePrice(volatileToken);
        uint256 poolPrice = _pairQuote(volatileToken);
        uint256 ratio = (poolPrice * PRECISION) / oraclePrice;
        if (ratio < PRECISION) {
            return PRECISION - ratio < ammCheckThreshold;
        } else {
            return ratio - PRECISION < ammCheckThreshold;
        }
    }

    /// @dev Checks that position's debt ratio isn't too high and the token isn't experiencing very high volatility
    /// @dev If volatility check is too high, revert
    /// @dev If debt ratio is too high, withdraw all funds from homora
    function _checkPositionHealth() internal returns (bool healthy) {
        uint currentPrice = _pairQuote(volatileToken);
        uint priceChange;
        if (currentPrice>priceAnchor) {
            priceChange = (currentPrice-priceAnchor)*PRECISION/priceAnchor;
        } else {
            priceChange = (priceAnchor-currentPrice)*PRECISION/priceAnchor;
        }
        if (priceChange>volatilityThreshold) {
            revert("Failed volaitlity check");
        }
        (, uint debtRatio,,,,) = heartBeat();
        if (debtRatio>debtRatioThreshold) {
            _decreasePosition(PRECISION);
            return false;
        }
        return true;
    }

   function requireAmmCheckPass() internal view {
        bool ammCheck = _ammCheck();
        require(ammCheck == true, "reason: Oracle Price difference");
    }

    /// @dev Perform amm check and check if strategy needs rebalancing, returns equity, price change and amount to rebalance by
    /// @return ammCheck Wether router price and oracle price are close to each other
    /// @return debtRatio ratio of collateral and borrow
    /// @return equity equity
    /// @return priceChange price difference between current price and price anchor
    /// @return currentPrice current price of risky asset
    /// @return gradient If greater than 0 strategy needs to be rebalanced by withdrawing this percentage
    function heartBeat()
        public
        view
        returns (
            bool ammCheck,
            uint256 debtRatio,
            uint256 equity,
            uint256 priceChange,
            uint256 currentPrice,
            uint256 gradient
        )
    {
        equity = balanceOfPool();
        // AMM check
        ammCheck = _ammCheck();
        // Calculate debt ratio
        uint256 borrowValue = IBank(homoraBank).getBorrowETHValue(positionId);
        uint256 collateralValue =
            IBank(homoraBank).getCollateralETHValue(positionId);
        debtRatio = (borrowValue * PRECISION) / collateralValue;

        // Calculate gradient
        currentPrice = _pairQuote(volatileToken);
        if (currentPrice >= priceAnchor) {
            priceChange =
                ((currentPrice - priceAnchor) * PRECISION) /
                priceAnchor;
        } else {
            priceChange =
                ((priceAnchor - currentPrice) * PRECISION) /
                priceAnchor;
        }
        if (priceChange < (25 * PRECISION) / 1000) {
            gradient = 0;
        } else if (priceChange < (50 * PRECISION) / 1000) {
            gradient = (2 * PRECISION) / 10;
        } else if (priceChange < (75 * PRECISION) / 1000) {
            gradient = (4 * PRECISION) / 10;
        } else {
            gradient = (75 * PRECISION) / 100;
        }
    }

    function _withdrawAll() internal override {
        if (positionId==0) return;
        _harvest();
        _swapRewards();
        _decreasePosition(PRECISION);
    }

    /// @dev Get router price for token
    function _routerQuote(uint256 _amount, address[] memory path)
        internal
        view
        returns (uint256)
    {
        uint256[] memory amounts =
            IUniswapRouterV2(router).getAmountsOut(_amount, path);
        return amounts[amounts.length - 1];
    }

    /// @dev Get price of token from liquidity pool in terms of USDC
    function _pairQuote(address token) internal view returns (uint price) {
        IUniswapV2Factory factory = IUniswapV2Factory(IUniswapRouterV2(router).factory());
        IUniswapV2Pair pool = IUniswapV2Pair(factory.getPair(stableToken, token));
        (uint r0, uint r1,) = pool.getReserves();
        uint volatileDecimals = ERC20Upgradeable(token).decimals();
        if (pool.token0()==stableToken) {
            price = r0/(r1/uint256(10)**volatileDecimals);
        } else {
            price = r1/(r0/uint256(10)**volatileDecimals);
        }
    }

    /// @dev invest the amount of want
    /// @notice When this function is called, the controller has already sent want to this
    /// @notice Just get the current balance and then invest accordingly
    function _deposit() internal override {
        requireAmmCheckPass();
        uint256 supplied = IERC20(stableToken).balanceOf(address(this));
        stableSupplied+=supplied;
        uint256 multiplier = leverage - 1;
        uint256 frac_stable = PRECISION / (leverage / (leverage - 2) + 1);
        uint256 frac_volatile = PRECISION - frac_stable;
        uint256 borrow_stable =
            (supplied * frac_stable * multiplier) / PRECISION;
        uint256 borrow_volatile_in_stable =
            ((supplied * frac_volatile * multiplier) / PRECISION);
        address[] memory path = new address[](2);
        path[0] = stableToken;
        path[1] = volatileToken;
        uint256 borrow_volatile = _routerQuote(borrow_volatile_in_stable, path);
        require(borrow_stable*2==supplied || borrow_stable*2==supplied-1);
        uint minStable = (borrow_stable + supplied)*(PRECISION-slippage)/PRECISION;
        uint minVolatile = borrow_volatile*(PRECISION-slippage)/PRECISION;
        Amounts memory amt = Amounts(supplied, 0, 0, borrow_stable, borrow_volatile, 0, minStable, minVolatile);
        positionId = IBank(homoraBank).execute(
            positionId,
            spell,
            abi.encodeWithSignature(
                spellOpen,
                stableToken,
                volatileToken,
                amt,
                pid
            )
        );
    }


    function _decreasePosition(uint256 gradient) internal returns (uint256) {
        requireAmmCheckPass();
        uint256 lpTokens = getCollateralSize();        
        require(lpTokens==getCollateralSize(), "Lost lp tokens");
        uint256 stableBalance0 = IERC20(stableToken).balanceOf(address(this));
        (uint256 debtStable, uint256 debtVolatile) = getDebts();
        uint256 tokensToWithdraw = (lpTokens * gradient) / PRECISION;
        uint256 repayStable = (debtStable * gradient) / PRECISION;
        uint256 repayVolatile = (debtVolatile * gradient) / PRECISION;
        if (gradient==PRECISION) {
            repayStable = MAX_INT;
            repayVolatile = MAX_INT;
        }
        uint balance = balanceOfPool();
        uint withdrawn = balance*gradient/PRECISION;
        uint minWithdrawn = withdrawn*(PRECISION-slippage)/PRECISION;
        RepayAmounts memory amt =
            RepayAmounts(
                tokensToWithdraw,
                0,
                repayStable,
                repayVolatile,
                0,
                minWithdrawn,
                0
            );
        IBank(homoraBank).execute(
            positionId,
            spell,
            abi.encodeWithSignature(spellClose, stableToken, volatileToken, amt)
        );
        uint256 stableBalance1 = IERC20(stableToken).balanceOf(address(this));
        stableSupplied-=stableBalance1 - stableBalance0;
        return stableBalance1 - stableBalance0;
    }
    
    receive() external payable {
        uint256 oraclePrice = _oraclePrice(volatileToken);
        address[] memory path = new address[](2);
        path[0] = volatileToken;
        path[1] = stableToken;
        uint expectedOut = msg.value*oraclePrice/uint256(10)**ERC20Upgradeable(volatileToken).decimals();
        uint minOut = expectedOut*(PRECISION-slippage)/PRECISION;
        IUniswapRouterV2(router).swapExactETHForTokens{value: msg.value}(
            minOut,
            path,
            address(this),
            block.timestamp
        );
    }
    
    function _withdrawSome(uint256 amount)
        internal
        override
        returns (uint256 withdrawn)
    {
        if (positionId==0) return (0);
        uint256 equity = balanceOfPool();
        uint256 gradient = (amount * PRECISION) / equity;
        if (gradient>PRECISION) {
            gradient = PRECISION;
        }
        withdrawn = _decreasePosition(gradient);
    }

    function harvest() external {
        _onlyAuthorizedActorsOrController();
        uint balanceBefore = IERC20(stableToken).balanceOf(address(this));
        _harvest();
        _swapRewards();
        uint harvested = IERC20(stableToken).balanceOf(address(this)) - balanceBefore;
        _deposit();
        // Don't want to count harvested usdc towards supplied usdc
        stableSupplied-=harvested;
        emit Harvest(harvested);
    }

    function rebalance(uint256 gradient) external {
        _onlyAuthorizedActorsOrController();
        requireAmmCheckPass();
        bool healthy = _checkPositionHealth();
        if (!healthy) return;
        _decreasePosition(gradient);
        _deposit();
        numRebalances += 1;
        uint currentPrice = _pairQuote(volatileToken);
        priceAnchor = priceAnchor*(PRECISION-gradient)/PRECISION + currentPrice*gradient/PRECISION;
        emit RebalanceDone(
                gradient,
                block.number,
                block.timestamp
        );
    }

    function _harvest() internal {
        requireAmmCheckPass();
        bool healthy = _checkPositionHealth();
        if (!healthy) return;
        IBank(homoraBank).execute(
            positionId,
            spell,
            abi.encodeWithSignature(spellHarvest)
        );
    }
    
    function _swapRewards() internal {
        for (uint256 i = 0; i < rewards.length; i++) {
            uint256 balance = IERC20(rewards[i]).balanceOf(address(this));
            require(balance > 0, "didnt get rewards");

            // Slippage control
            uint price;
            if (oracles[rewards[i]]!=address(0)) {
                (, int256 stablePrice, , , ) = AggregatorV3Interface(oracles[stableToken]).latestRoundData();
                (, int256 volatilePrice, , , ) = AggregatorV3Interface(oracles[rewards[i]]).latestRoundData();
                price = uint256((volatilePrice * int256(10)**ERC20Upgradeable(stableToken).decimals()) /stablePrice);
            } else {
                price = _pairQuote(rewards[i]);
            }
            uint expectedOut = balance*price/uint256(10)**ERC20Upgradeable(rewards[i]).decimals();
            uint minOut = expectedOut*(PRECISION-slippage)/PRECISION;
            require(minOut>0, "Badd slippage control");

            address[] memory path = new address[](2);
            path[0] = rewards[i];
            path[1] = stableToken;
            IUniswapRouterV2(router).swapExactTokensForTokens(
                balance,
                minOut,
                path,
                address(this),
                block.timestamp
            );
        }
    }

    /// @notice sets slippage tolerance for liquidity provision in terms of BPS ie.
    /// @notice minSlippage = 0
    /// @notice maxSlippage = 10_000
    function setSlippageTolerance(uint256 _s) external whenNotPaused {
        _onlyAuthorizedActors();
        require(_s <= PRECISION, "slippage out of bounds");
        slippage = _s;
    }

    function getDebts() public view returns (uint256, uint256) {
        (address[] memory tokens, uint256[] memory debts) =
            IBank(homoraBank).getPositionDebts(positionId);
        if (tokens.length == 2) {
            if (tokens[0] == stableToken) {
                return (debts[0], debts[1]);
            } else {
                return (debts[1], debts[0]);
            }
        } else if (tokens.length == 1) {
            if (tokens[0] == stableToken) {
                return (debts[0], 0);
            } else {
                return (0, debts[0]);
            }
        } else {
            return (0, 0);
        }
    }

    function getCollateralSize() public view returns (uint256 collateral) {
        (, , , collateral) = IBank(homoraBank).getPositionInfo(positionId);
    }

    function getCollateralBorrowValue() public view returns (uint collateralValue, uint borrowValue) {
        borrowValue = IBank(homoraBank).getBorrowETHValue(positionId);
        collateralValue = IBank(homoraBank).getCollateralETHValue(positionId);
    }
}

File 2 of 28 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

    /**
     * @dev 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 `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, 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 `from` to `to` 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 from,
        address to,
        uint256 amount
    ) external returns (bool);
}

File 3 of 28 : ERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "IERC20Upgradeable.sol";
import "IERC20MetadataUpgradeable.sol";
import "ContextUpgradeable.sol";
import "Initializable.sol";

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

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
        __ERC20_init_unchained(name_, symbol_);
    }

    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

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

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

        return true;
    }

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

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

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

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

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

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

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

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

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

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

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[45] private __gap;
}

File 4 of 28 : IERC20MetadataUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "IERC20Upgradeable.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 5 of 28 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "Initializable.sol";

/**
 * @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 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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 6 of 28 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

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

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
     * initialization step. This is essential to configure modules that are added through upgrades and that require
     * initialization.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }
}

File 7 of 28 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @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
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 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");

        (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");

        (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");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal 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
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 8 of 28 : SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "IERC20Upgradeable.sol";
import "draft-IERC20PermitUpgradeable.sol";
import "AddressUpgradeable.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 SafeERC20Upgradeable {
    using AddressUpgradeable for address;

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

    function safeTransferFrom(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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'
        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(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    function safePermit(
        IERC20PermitUpgradeable token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @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(IERC20Upgradeable 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
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 9 of 28 : draft-IERC20PermitUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20PermitUpgradeable {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 10 of 28 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "IERC20.sol";
import "draft-IERC20Permit.sol";
import "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 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'
        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) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

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

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @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
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 11 of 28 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

    /**
     * @dev 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 `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, 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 `from` to `to` 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 from,
        address to,
        uint256 amount
    ) external returns (bool);
}

File 12 of 28 : draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 13 of 28 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @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
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 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");

        (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");

        (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");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

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

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal 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
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 14 of 28 : IController.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

interface IController {
    function withdraw(address, uint256) external;

    function withdrawAll(address) external;
    
    function withdrawAllFromRebalance(address) external;

    function strategies(address) external view returns (address);

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

    function earn(address, uint256, address) external;

    function want(address) external view returns (address);

    function rewards() external view returns (address);

    function vaults(address) external view returns (address);
}

File 15 of 28 : IBank.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.17;

interface IBank {
    /// The governor adds a new bank gets added to the system.
    event AddBank(address token, address cToken);
    /// The governor sets the address of the oracle smart contract.
    event SetOracle(address oracle);
    /// The governor sets the basis point fee of the bank.
    event SetFeeBps(uint256 feeBps);
    /// The governor withdraw tokens from the reserve of a bank.
    event WithdrawReserve(address user, address token, uint256 amount);
    /// Someone borrows tokens from a bank via a spell caller.
    event Borrow(
        uint256 positionId,
        address caller,
        address token,
        uint256 amount,
        uint256 share
    );
    /// Someone repays tokens to a bank via a spell caller.
    event Repay(
        uint256 positionId,
        address caller,
        address token,
        uint256 amount,
        uint256 share
    );
    /// Someone puts tokens as collateral via a spell caller.
    event PutCollateral(
        uint256 positionId,
        address caller,
        address token,
        uint256 id,
        uint256 amount
    );
    /// Someone takes tokens from collateral via a spell caller.
    event TakeCollateral(
        uint256 positionId,
        address caller,
        address token,
        uint256 id,
        uint256 amount
    );
    /// Someone calls liquidatation on a position, paying debt and taking collateral tokens.
    event Liquidate(
        uint256 positionId,
        address liquidator,
        address debtToken,
        uint256 amount,
        uint256 share,
        uint256 bounty
    );


    /// @dev Return the current position while under execution.
    function POSITION_ID() external view returns (uint256);

    /// @dev Return the current target while under execution.
    function SPELL() external view returns (address);

    /// @dev Return the current executor (the owner of the current position).
    function EXECUTOR() external view returns (address);

    /// @dev Return bank information for the given token.
    function getBankInfo(address token)
        external
        view
        returns (
            bool isListed,
            address cToken,
            uint256 reserve,
            uint256 totalDebt,
            uint256 totalShare
        );

    /// @dev Return position information for the given position id.
    function getPositionInfo(uint256 positionId)
        external
        view
        returns (
            address owner,
            address collToken,
            uint256 collId,
            uint256 collateralSize
        );

    function getPositionDebts(uint256 positionId)
        external
        view
        returns (address[] memory tokens, uint256[] memory debts);

    function execute(
        uint256 positionId,
        address spell,
        bytes memory data
    ) external payable returns (uint256);

    /// @dev Return the borrow balance for given positon and token without trigger interest accrual.
    function borrowBalanceStored(uint256 positionId, address token)
        external
        view
        returns (uint256);

    /// @dev Trigger interest accrual and return the current borrow balance.
    function borrowBalanceCurrent(uint256 positionId, address token)
        external
        returns (uint256);

    /// @dev Borrow tokens from the bank.
    function borrow(address token, uint256 amount) external;

    /// @dev Repays tokens to the bank.
    function repay(address token, uint256 amountCall) external;

    /// @dev Transmit user assets to the spell.
    function transmit(address token, uint256 amount) external;

    /// @dev Put more collateral for users.
    function putCollateral(
        address collToken,
        uint256 collId,
        uint256 amountCall
    ) external;

    /// @dev Take some collateral back.
    function takeCollateral(
        address collToken,
        uint256 collId,
        uint256 amount
    ) external;

    /// @dev Liquidate a position.
    function liquidate(
        uint256 positionId,
        address debtToken,
        uint256 amountCall
    ) external;

    function getBorrowETHValue(uint256 positionId)
        external
        view
        returns (uint256);

    function getCollateralETHValue(uint256 positionId)
        external
        view
        returns (uint256);

    function accrue(address token) external;

    function nextPositionId() external view returns (uint256);

    /// @dev Return current position information.
    function getCurrentPositionInfo()
        external
        view
        returns (
            address owner,
            address collToken,
            uint256 collId,
            uint256 collateralSize
        );

    function support(address token) external view returns (bool);

    function setAllowContractCalls(bool ok) external;

    function setWhitelistUsers(
        address[] calldata users,
        bool[] calldata statuses
    ) external;

    function allowContractCalls() external view returns (bool);

    function governor() external view returns (address);

    function oracle() external view returns (address);

    struct CreditLimit{
        address user;
        address token;
        uint limit;
        address origin;
    }
    function setCreditLimits(CreditLimit[] memory _creditLimits) external;
}

File 16 of 28 : IUniswapRouterV2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

interface IUniswapRouterV2 {
    function factory() external view returns (address);
    function addLiquidity(
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    )
        external
        returns (
            uint256 amountA,
            uint256 amountB,
            uint256 liquidity
        );

    function addLiquidityETH(
        address token,
        uint256 amountTokenDesired,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    )
        external
        payable
        returns (
            uint256 amountToken,
            uint256 amountETH,
            uint256 liquidity
        );

    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB);

    function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts);

    function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts);

    function swapETHForExactTokens(
        uint256 amountOut,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function swapExactETHForTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function swapExactTokensForETH(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapTokensForExactETH(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapTokensForExactTokens(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
}

File 17 of 28 : IUniswapV2Pair.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

interface IUniswapV2Pair {
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
    event Transfer(address indexed from, address indexed to, uint256 value);

    function name() external pure returns (string memory);

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

    function decimals() external pure returns (uint8);

    function totalSupply() external view returns (uint256);

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

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

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

    function transfer(address to, uint256 value) external returns (bool);

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

    function DOMAIN_SEPARATOR() external view returns (bytes32);

    function PERMIT_TYPEHASH() external pure returns (bytes32);

    function nonces(address owner) external view returns (uint256);

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    event Mint(address indexed sender, uint256 amount0, uint256 amount1);
    event Burn(
        address indexed sender,
        uint256 amount0,
        uint256 amount1,
        address indexed to
    );
    event Swap(
        address indexed sender,
        uint256 amount0In,
        uint256 amount1In,
        uint256 amount0Out,
        uint256 amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint256);

    function factory() external view returns (address);

    function token0() external view returns (address);

    function token1() external view returns (address);

    function getReserves()
        external
        view
        returns (
            uint112 reserve0,
            uint112 reserve1,
            uint32 blockTimestampLast
        );

    function price0CumulativeLast() external view returns (uint256);

    function price1CumulativeLast() external view returns (uint256);

    function kLast() external view returns (uint256);

    function mint(address to) external returns (uint256 liquidity);

    function burn(address to)
        external
        returns (uint256 amount0, uint256 amount1);

    function swap(
        uint256 amount0Out,
        uint256 amount1Out,
        address to,
        bytes calldata data
    ) external;

    function skim(address to) external;

    function sync() external;
}

File 18 of 28 : IUniswapV2Factory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

interface IUniswapV2Factory {
    event PairCreated(
        address indexed token0,
        address indexed token1,
        address pair,
        uint256
    );

    function getPair(address tokenA, address tokenB)
        external
        view
        returns (address pair);

    function allPairs(uint256) external view returns (address pair);

    function allPairsLength() external view returns (uint256);

    function feeTo() external view returns (address);

    function feeToSetter() external view returns (address);

    function createPair(address tokenA, address tokenB)
        external
        returns (address pair);
}

File 19 of 28 : AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

interface AggregatorV3Interface {
    function decimals() external view returns (uint8);

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

    function version() external view returns (uint256);

    function getRoundData(uint80 _roundId)
        external
        view
        returns (
            uint80 roundId,
            int256 answer,
            uint256 startedAt,
            uint256 updatedAt,
            uint80 answeredInRound
        );

    function latestRoundData()
        external
        view
        returns (
            uint80 roundId,
            int256 answer,
            uint256 startedAt,
            uint256 updatedAt,
            uint80 answeredInRound
        );
}

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

pragma solidity ^0.8.17;

interface IBaseOracle {
    /// @dev Return the value of the given input as ETH per unit, multiplied by 2**112.
    /// @param token The ERC-20 token to check the value.
    function getETHPx(address token) external view returns (uint256);
}

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

pragma solidity ^0.8.17;

import "IERC20Upgradeable.sol";
import "SafeMathUpgradeable.sol";
import "MathUpgradeable.sol";
import "AddressUpgradeable.sol";
import "PausableUpgradeable.sol";
import "Pausable.sol";
import "SafeERC20Upgradeable.sol";
import "Initializable.sol";
import "IUniswapRouterV2.sol";
import "IController.sol";
import "IStrategy.sol";

import "SettAccessControl.sol";

/*
    ===== Badger Base Strategy =====
    Common base class for all Sett strategies

    Changelog
    V1.1
    - Verify amount unrolled from strategy positions on withdraw() is within a threshold relative to the requested amount as a sanity check
    - Add version number which is displayed with baseStrategyVersion(). If a strategy does not implement this function, it can be assumed to be 1.0

    V1.2
    - Remove idle want handling from base withdraw() function. This should be handled as the strategy sees fit in _withdrawSome()
*/
abstract contract BaseStrategy is Pausable, SettAccessControl {
    using SafeERC20Upgradeable for IERC20Upgradeable;
    using AddressUpgradeable for address;
    using SafeMathUpgradeable for uint256;

    event Withdraw(uint256 amount);
    event WithdrawAll(uint256 balance);
    event WithdrawOther(address token, uint256 amount);
    event SetStrategist(address strategist);
    event SetGovernance(address governance);
    event SetController(address controller);
    event SetWithdrawalFee(uint256 withdrawalFee);
    event SetPerformanceFeeStrategist(uint256 performanceFeeStrategist);
    event SetPerformanceFeeGovernance(uint256 performanceFeeGovernance);
    event Harvest(uint256 harvested, uint256 indexed blockNumber);
    event Tend(uint256 tended);

    address public want; // 
    address public depositToken;
    address public vault;
    
    uint256 public performanceFeeGovernance;
    uint256 public performanceFeeStrategist;
    uint256 public withdrawalFee;

    uint256 public constant MAX_FEE = 10000;    

    address public controller;
    address public guardian;

    uint256 public withdrawalMaxDeviationThreshold;    
    address public stableToken;

    function __BaseStrategy_init(
        address _governance,
        address _strategist,
        address _controller,
        address _keeper,
        address _guardian
    ) public initializer whenNotPaused {
        governance = _governance;
        strategist = _strategist;
        keeper = _keeper;
        controller = _controller;
        guardian = _guardian;
        withdrawalMaxDeviationThreshold = 50;
    }

    // ===== Modifiers =====

    function _onlyController() internal view {
        require(msg.sender == controller, "onlyController");
    }

    function _onlyAuthorizedActorsOrController() internal view {
        require(msg.sender == keeper || msg.sender == governance || msg.sender == controller, "onlyAuthorizedActorsOrController");
    }

    function _onlyControllerOrGovernor() internal view {
        require(msg.sender == governance || msg.sender == controller, "onlyControllerOrGovernor");
    }

    function _onlyAuthorizedPausers() internal view {
        require(msg.sender == guardian || msg.sender == governance, "onlyPausers");
    }

    /// ===== View Functions =====
    function baseStrategyVersion() public pure returns (string memory) {
        return "1.2";
    }

    /// @notice Get the balance of want held idle in the Strategy
    function balanceOfWant() public view returns (uint256) {
        return IERC20Upgradeable(want).balanceOf(address(this));
    }

    /// @notice Get the total balance of want realized in the strategy, whether idle or active in Strategy positions.
    function balanceOf() public virtual view returns (uint256) {
        return balanceOfPool();
    }

    function isTendable() public virtual pure returns (bool) {
        return false;
    }

    /// ===== Permissioned Actions: Governance =====

    function setGuardian(address _guardian) external {
        _onlyGovernance();
        guardian = _guardian;
    }

    function setWithdrawalFee(uint256 _withdrawalFee) external {
        _onlyGovernance();
        require(_withdrawalFee <= MAX_FEE, "base-strategy/excessive-withdrawal-fee");
        withdrawalFee = _withdrawalFee;
    }

    function setPerformanceFeeStrategist(uint256 _performanceFeeStrategist) external {
        _onlyGovernance();
        require(_performanceFeeStrategist <= MAX_FEE, "base-strategy/excessive-strategist-performance-fee");
        performanceFeeStrategist = _performanceFeeStrategist;
    }

    function setPerformanceFeeGovernance(uint256 _performanceFeeGovernance) external {
        _onlyGovernance();
        require(_performanceFeeGovernance <= MAX_FEE, "base-strategy/excessive-governance-performance-fee");
        performanceFeeGovernance = _performanceFeeGovernance;
    }

    function setController(address _controller) external {
        _onlyGovernance();
        controller = _controller;
    }

    function setWithdrawalMaxDeviationThreshold(uint256 _threshold) external {
        _onlyGovernance();
        require(_threshold <= MAX_FEE, "base-strategy/excessive-max-deviation-threshold");
        withdrawalMaxDeviationThreshold = _threshold;
    }

    function deposit() public virtual whenNotPaused {
        _onlyControllerOrGovernor();
        uint256 _usdcToken = IERC20Upgradeable(stableToken).balanceOf(address(this));
        if (_usdcToken > 0) {
            _deposit();
        }
        _postDeposit();
    }

    // ===== Permissioned Actions: Controller =====

    /// @notice Controller-only function to Withdraw partial funds, normally used with a vault withdrawal
    function withdrawAll() external virtual whenNotPaused {
        _onlyController();

        _withdrawAll();
        uint256 _toWithdraw = IERC20Upgradeable(depositToken).balanceOf(address(this));
        _transferToVault(_toWithdraw);    
    }

     /// @notice Controller-only function to Withdraw partial funds, normally used with a vault withdrawal
    function withdrawAllForRebalance() external virtual whenNotPaused {
        _onlyController();

        _withdrawAll();
        uint256 _toWithdraw = IERC20Upgradeable(depositToken).balanceOf(address(this));
        _transferToVault(_toWithdraw);    
    }



    /// @notice Withdraw partial funds from the strategy, unrolling from strategy positions as necessary
    /// @notice Processes withdrawal fee if present
    /// @dev If it fails to recover sufficient funds (defined by withdrawalMaxDeviationThreshold), the withdrawal should fail so that this unexpected behavior can be investigated
    function withdraw(uint256 _amount) external virtual whenNotPaused {
        _onlyController();

        // Withdraw from strategy positions, typically taking from any idle want first.
        _withdrawSome(_amount);
        uint256 _postWithdraw = IERC20Upgradeable(stableToken).balanceOf(address(this));

        // Sanity check: Ensure we were able to retrieve sufficent want from strategy positions
        // If we end up with less than the amount requested, make sure it does not deviate beyond a maximum threshold
        if (_postWithdraw < _amount) {
            uint256 diff = _diff(_amount, _postWithdraw);

            // Require that difference between expected and actual values is less than the deviation threshold percentage
            require(diff <= _amount.mul(withdrawalMaxDeviationThreshold).div(MAX_FEE), "base-strategy/withdraw-exceed-max-deviation-threshold");
        }

        // Return the amount actually withdrawn if less than amount requested
        uint256 _toWithdraw = MathUpgradeable.min(_postWithdraw, _amount);

        // Process withdrawal fee - No withdrawal fee now
        // uint256 _fee = _processWithdrawalFee(_toWithdraw);
        uint256 _fee = 0;

        // Transfer remaining to Vault to handle withdrawal
        _transferToVault(_toWithdraw.sub(_fee));
    }

    // NOTE: must exclude any tokens used in the yield
    // Controller role - withdraw should return to Controller
    function withdrawOther(address _asset) external virtual whenNotPaused returns (uint256 balance) {
        _onlyController();

        balance = IERC20Upgradeable(_asset).balanceOf(address(this));
        IERC20Upgradeable(_asset).safeTransfer(controller, balance);
    }

    /// ===== Permissioned Actions: Authoized Contract Pausers =====

    function pause() external {
        _onlyAuthorizedPausers();
        _pause();
    }

    function unpause() external {
        _onlyGovernance();
        _unpause();
    }

    /// ===== Internal Helper Functions =====

    /// @notice If withdrawal fee is active, take the appropriate amount from the given value and transfer to rewards recipient
    /// @return The withdrawal fee that was taken
    function _processWithdrawalFee(uint256 _amount) internal returns (uint256) {
        if (withdrawalFee == 0) {
            return 0;
        }

        uint256 fee = _amount.mul(withdrawalFee).div(MAX_FEE);
        IERC20Upgradeable(want).safeTransfer(IController(controller).rewards(), fee);
        return fee;
    }

    /// @dev Helper function to process an arbitrary fee
    /// @dev If the fee is active, transfers a given portion in basis points of the specified value to the recipient
    /// @return The fee that was taken
    function _processFee(
        address token,
        uint256 amount,
        uint256 feeBps,
        address recipient
    ) internal returns (uint256) {
        if (feeBps == 0) {
            return 0;
        }
        uint256 fee = amount.mul(feeBps).div(MAX_FEE);
        IERC20Upgradeable(token).safeTransfer(recipient, fee);
        return fee;
    }

    function _transferToVault(uint256 _amount) internal {
        address _vault = vault;
        require(_vault != address(0), "!vault"); // additional protection so we don't burn the funds
        IERC20Upgradeable(stableToken).safeTransfer(_vault, _amount);
    }

    /// @notice Utility function to diff two numbers, expects higher value in first position
    function _diff(uint256 a, uint256 b) internal pure returns (uint256) {
        require(a >= b, "diff/expected-higher-number-in-first-position");
        return a.sub(b);
    }

    // ===== Abstract Functions: To be implemented by specific Strategies =====

    /// @dev Internal deposit logic to be implemented by Stratgies
    function _deposit() internal virtual;

    function _postDeposit() internal virtual {
        //no-op by default
    }


    /// @dev Internal logic for strategy migration. Should exit positions as efficiently as possible
    function _withdrawAll() internal virtual;

    /// @dev Internal logic for partial withdrawals. Should exit positions as efficiently as possible.
    /// @dev The withdraw() function shell automatically uses idle want in the strategy before attempting to withdraw more using this
    function _withdrawSome(uint256 _amount) internal virtual returns (uint256);

    /// @dev Realize returns from positions
    /// @dev Returns can be reinvested into positions, or distributed in another fashion
    /// @dev Performance fees should also be implemented in this function
    /// @dev Override function stub is removed as each strategy can have it's own return signature for STATICCALL
    // function harvest() external virtual;

    /// @dev User-friendly name for this strategy for purposes of convenient reading
    function getName() external virtual pure returns (string memory);

    /// @dev Balance of want currently held in strategy positions
    function balanceOfPool() public virtual view returns (uint256);

    uint256[49] private __gap;
}

File 22 of 28 : SafeMathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMathUpgradeable {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

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

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

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

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

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

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

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

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

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

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * 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) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

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

File 23 of 28 : MathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library MathUpgradeable {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @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.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator,
        Rounding rounding
    ) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. It the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`.
        // We also know that `k`, the position of the most significant bit, is such that `msb(a) = 2**k`.
        // This gives `2**k < a <= 2**(k+1)` → `2**(k/2) <= sqrt(a) < 2 ** (k/2+1)`.
        // Using an algorithm similar to the msb conmputation, we are able to compute `result = 2**(k/2)` which is a
        // good first aproximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1;
        uint256 x = a;
        if (x >> 128 > 0) {
            x >>= 128;
            result <<= 64;
        }
        if (x >> 64 > 0) {
            x >>= 64;
            result <<= 32;
        }
        if (x >> 32 > 0) {
            x >>= 32;
            result <<= 16;
        }
        if (x >> 16 > 0) {
            x >>= 16;
            result <<= 8;
        }
        if (x >> 8 > 0) {
            x >>= 8;
            result <<= 4;
        }
        if (x >> 4 > 0) {
            x >>= 4;
            result <<= 2;
        }
        if (x >> 2 > 0) {
            result <<= 1;
        }

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        uint256 result = sqrt(a);
        if (rounding == Rounding.Up && result * result < a) {
            result += 1;
        }
        return result;
    }
}

File 24 of 28 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "ContextUpgradeable.sol";
import "Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 25 of 28 : Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

File 26 of 28 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^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 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) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 27 of 28 : IStrategy.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

interface IStrategy {
    function want() external view returns (address);

    function deposit() external;

    // NOTE: must exclude any tokens used in the yield
    // Controller role - withdraw should return to Controller
    function withdrawOther(address) external;

    // Controller | Vault role - withdraw should always return to Vault
    function withdraw(uint256) external;

    // Controller | Vault role - withdraw should always return to Vault
    function withdrawAll() external;

    function withdrawAllForRebalance() external;

    function balanceOf() external view returns (uint256);

    function getName() external pure returns (string memory);

    function setStrategist(address _strategist) external;

    function setWithdrawalFee(uint256 _withdrawalFee) external;

    function setPerformanceFeeStrategist(uint256 _performanceFeeStrategist) external;

    function setPerformanceFeeGovernance(uint256 _performanceFeeGovernance) external;

    function setGovernance(address _governance) external;

    function setController(address _controller) external;

    function tend() external;

    function harvest() external;
}

File 28 of 28 : SettAccessControl.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "Initializable.sol";

/*
    Common base for permissioned roles throughout Sett ecosystem
*/
contract SettAccessControl is Initializable {
    address public governance;
    address public strategist;
    address public keeper;

    // ===== MODIFIERS =====
    function _onlyGovernance() internal view {
        require(msg.sender == governance, "onlyGovernance");
    }

    function _onlyGovernanceOrStrategist() internal view {
        require(msg.sender == strategist || msg.sender == governance, "onlyGovernanceOrStrategist");
    }

    function _onlyAuthorizedActors() internal view {
        require(msg.sender == governance, "onlyAuthorizedActors");
    }

    // ===== PERMISSIONED ACTIONS =====

    /// @notice Change strategist address
    /// @notice Can only be changed by governance itself
    function setStrategist(address _strategist) external {
        _onlyGovernance();
        strategist = _strategist;
    }

    /// @notice Change keeper address
    /// @notice Can only be changed by governance itself
    function setKeeper(address _keeper) external {
        _onlyGovernance();
        keeper = _keeper;
    }

    /// @notice Change governance address
    /// @notice Can only be changed by governance itself
    function setGovernance(address _governance) public {
        _onlyGovernance();
        governance = _governance;
    }

    uint256[50] private __gap;
}

Settings
{
  "evmVersion": "istanbul",
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "libraries": {
    "AHStrategy.sol": {}
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"_governance","type":"address"},{"internalType":"address","name":"_strategist","type":"address"},{"internalType":"address","name":"_controller","type":"address"},{"internalType":"address","name":"_keeper","type":"address"},{"internalType":"address","name":"_guardian","type":"address"},{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"uint256","name":"_leverage","type":"uint256"},{"internalType":"address[]","name":"config","type":"address[]"},{"internalType":"address[]","name":"_rewards","type":"address[]"},{"internalType":"uint256[3]","name":"_feeConfig","type":"uint256[3]"},{"internalType":"address","name":"_vault","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"stableAmount","type":"uint256"}],"name":"Harvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"harvested","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"Harvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"gradient","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"blockNumber","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"RebalanceDone","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"controller","type":"address"}],"name":"SetController","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"governance","type":"address"}],"name":"SetGovernance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"performanceFeeGovernance","type":"uint256"}],"name":"SetPerformanceFeeGovernance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"performanceFeeStrategist","type":"uint256"}],"name":"SetPerformanceFeeStrategist","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"strategist","type":"address"}],"name":"SetStrategist","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"withdrawalFee","type":"uint256"}],"name":"SetWithdrawalFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tended","type":"uint256"}],"name":"Tend","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"blockNumber","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"TreeDistribution","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"balance","type":"uint256"}],"name":"WithdrawAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawOther","type":"event"},{"inputs":[],"name":"MAX_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_governance","type":"address"},{"internalType":"address","name":"_strategist","type":"address"},{"internalType":"address","name":"_controller","type":"address"},{"internalType":"address","name":"_keeper","type":"address"},{"internalType":"address","name":"_guardian","type":"address"}],"name":"__BaseStrategy_init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"activeDistribution","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balanceOfPool","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balanceOfWant","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"baseStrategyVersion","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"blueSwanTree","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"controller","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCollateralBorrowValue","outputs":[{"internalType":"uint256","name":"collateralValue","type":"uint256"},{"internalType":"uint256","name":"borrowValue","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCollateralSize","outputs":[{"internalType":"uint256","name":"collateral","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDebts","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getName","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"governance","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"guardian","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"heartBeat","outputs":[{"internalType":"bool","name":"ammCheck","type":"bool"},{"internalType":"uint256","name":"debtRatio","type":"uint256"},{"internalType":"uint256","name":"equity","type":"uint256"},{"internalType":"uint256","name":"priceChange","type":"uint256"},{"internalType":"uint256","name":"currentPrice","type":"uint256"},{"internalType":"uint256","name":"gradient","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"homoraBank","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isTendable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"keeper","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"leverage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpComponent","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"numRebalances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"performanceFeeGovernance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"performanceFeeStrategist","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"priceAnchor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"gradient","type":"uint256"}],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewards","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"router","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_active","type":"bool"}],"name":"setActiveDistrution","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_blueSwanAddress","type":"address"}],"name":"setBlueSwanTree","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_controller","type":"address"}],"name":"setController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_governance","type":"address"}],"name":"setGovernance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_guardian","type":"address"}],"name":"setGuardian","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_keeper","type":"address"}],"name":"setKeeper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_leverage","type":"uint256"}],"name":"setLeverage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"oracle","type":"address"}],"name":"setOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_performanceFeeGovernance","type":"uint256"}],"name":"setPerformanceFeeGovernance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_performanceFeeStrategist","type":"uint256"}],"name":"setPerformanceFeeStrategist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_s","type":"uint256"}],"name":"setSlippageTolerance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_strategist","type":"address"}],"name":"setStrategist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_withdrawalFee","type":"uint256"}],"name":"setWithdrawalFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_threshold","type":"uint256"}],"name":"setWithdrawalMaxDeviationThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"slippage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"spell","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stableSupplied","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stableToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"strategist","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"volatileToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"want","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawAllForRebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"withdrawOther","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawalFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawalMaxDeviationThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

60806040523480156200001157600080fd5b506040516200596738038062005967833981016040819052620000349162000cf8565b6000805460ff191690556200004d8b8b8b8b8b620008b3565b64e8d4a510006084819055600019608555607b869055620000719060649062000e1a565b607f556084546064906200008790606362000e3d565b62000093919062000e1a565b60805560845460815583518490600090620000b257620000b262000e57565b6020026020010151607360006101000a8154816001600160a01b0302191690836001600160a01b0316021790555083600181518110620000f657620000f662000e57565b6020026020010151607460006101000a8154816001600160a01b0302191690836001600160a01b03160217905550836002815181106200013a576200013a62000e57565b6020026020010151607660006101000a8154816001600160a01b0302191690836001600160a01b03160217905550836003815181106200017e576200017e62000e57565b6020026020010151607760006101000a8154816001600160a01b0302191690836001600160a01b0316021790555083600481518110620001c257620001c262000e57565b602090810291909101810151608380546001600160a01b0319166001600160a01b0392831617905560765460408051630dfe168160e01b815290519190921692630dfe168192600480820193918290030181865afa15801562000229573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200024f919062000e6d565b603e80546001600160a01b039283166001600160a01b031991821681179092556036805490911690911790556076546040805163d21220a760e01b81529051919092169163d21220a79160048083019260209291908290030181865afa158015620002be573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002e4919062000e6d565b607580546001600160a01b0319166001600160a01b0392909216919091179055607986905560005b83518110156200037d5760788482815181106200032d576200032d62000e57565b60209081029190910181015182546001810184556000938452919092200180546001600160a01b0319166001600160a01b0390921691909117905580620003748162000e92565b9150506200030c565b5081516038556020820151603955604080830151603a558051600280825260608201909252600091816020016020820280368337505060755482519293506001600160a01b031691839150600090620003da57620003da62000e57565b6001600160a01b039283166020918202929092010152603e548251911690829060019081106200040e576200040e62000e57565b6001600160a01b039283166020918202929092018101919091526075546040805163313ce56760e01b81529051620004a594929092169263313ce567926004808401938290030181865afa1580156200046b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000491919062000eae565b6200049e90600a62000fd0565b8262000a6a565b607c55603780546001600160a01b0319166001600160a01b038416179055608454620004d49060329062000e1a565b607255603e5460745460855460405163095ea7b360e01b81526001600160a01b039283166004820152602481019190915291169063095ea7b3906044016020604051808303816000875af115801562000531573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000557919062000fe1565b5060755460745460855460405163095ea7b360e01b81526001600160a01b039283166004820152602481019190915291169063095ea7b3906044016020604051808303816000875af1158015620005b2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620005d8919062000fe1565b5060765460745460855460405163095ea7b360e01b81526001600160a01b039283166004820152602481019190915291169063095ea7b3906044016020604051808303816000875af115801562000633573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000659919062000fe1565b50603e5460775460855460405163095ea7b360e01b81526001600160a01b039283166004820152602481019190915291169063095ea7b3906044016020604051808303816000875af1158015620006b4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620006da919062000fe1565b5060755460775460855460405163095ea7b360e01b81526001600160a01b039283166004820152602481019190915291169063095ea7b3906044016020604051808303816000875af115801562000735573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200075b919062000fe1565b5060765460775460855460405163095ea7b360e01b81526001600160a01b039283166004820152602481019190915291169063095ea7b3906044016020604051808303816000875af1158015620007b6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620007dc919062000fe1565b5060005b607854811015620008a0576078818154811062000801576200080162000e57565b60009182526020909120015460775460855460405163095ea7b360e01b81526001600160a01b039283166004820152602481019190915291169063095ea7b3906044016020604051808303816000875af115801562000864573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200088a919062000fe1565b5080620008978162000e92565b915050620007e0565b505050505050505050505050506200110d565b60005462010000900460ff1615808015620008d95750600054600161010090910460ff16105b806200090f5750620008f63062000b2360201b620022f21760201c565b1580156200090f575060005460ff610100909104166001145b620009785760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805461ff0019166101001790558015620009a0576000805462ff00001916620100001790555b620009aa62000b32565b600080546301000000600160b81b03191663010000006001600160a01b038981169190910291909117909155600180546001600160a01b031990811688841617909155600280548216868416179055603b80548216878416179055603c80549091169184169190911790556032603d55801562000a62576000805462ff000019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b60775460405163d06ca61f60e01b815260009182916001600160a01b039091169063d06ca61f9062000aa3908790879060040162001005565b600060405180830381865afa15801562000ac1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405262000aeb91908101906200105e565b9050806001825162000afe9190620010f7565b8151811062000b115762000b1162000e57565b60200260200101519150505b92915050565b6001600160a01b03163b151590565b60005460ff161562000b7a5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016200096f565b565b80516001600160a01b038116811462000b9457600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171562000bda5762000bda62000b99565b604052919050565b60006001600160401b0382111562000bfe5762000bfe62000b99565b5060051b60200190565b600082601f83011262000c1a57600080fd5b8151602062000c3362000c2d8362000be2565b62000baf565b82815260059290921b8401810191818101908684111562000c5357600080fd5b8286015b8481101562000c795762000c6b8162000b7c565b835291830191830162000c57565b509695505050505050565b600082601f83011262000c9657600080fd5b604051606081016001600160401b038111828210171562000cbb5762000cbb62000b99565b60405280606084018581111562000cd157600080fd5b845b8181101562000ced57805183526020928301920162000cd3565b509195945050505050565b60008060008060008060008060008060006101a08c8e03121562000d1b57600080fd5b62000d268c62000b7c565b9a5062000d3660208d0162000b7c565b995062000d4660408d0162000b7c565b985062000d5660608d0162000b7c565b975062000d6660808d0162000b7c565b60a08d015160c08e015160e08f015192995090975095506001600160401b0381111562000d9257600080fd5b62000da08e828f0162000c08565b6101008e015190955090506001600160401b0381111562000dc057600080fd5b62000dce8e828f0162000c08565b93505062000de18d6101208e0162000c84565b915062000df26101808d0162000b7c565b90509295989b509295989b9093969950565b634e487b7160e01b600052601160045260246000fd5b60008262000e3857634e487b7160e01b600052601260045260246000fd5b500490565b808202811582820484141762000b1d5762000b1d62000e04565b634e487b7160e01b600052603260045260246000fd5b60006020828403121562000e8057600080fd5b62000e8b8262000b7c565b9392505050565b60006001820162000ea75762000ea762000e04565b5060010190565b60006020828403121562000ec157600080fd5b815160ff8116811462000e8b57600080fd5b600181815b8085111562000f1457816000190482111562000ef85762000ef862000e04565b8085161562000f0657918102915b93841c939080029062000ed8565b509250929050565b60008262000f2d5750600162000b1d565b8162000f3c5750600062000b1d565b816001811462000f55576002811462000f605762000f80565b600191505062000b1d565b60ff84111562000f745762000f7462000e04565b50506001821b62000b1d565b5060208310610133831016604e8410600b841016171562000fa5575081810a62000b1d565b62000fb1838362000ed3565b806000190482111562000fc85762000fc862000e04565b029392505050565b600062000e8b60ff84168362000f1c565b60006020828403121562000ff457600080fd5b8151801515811462000e8b57600080fd5b6000604082018483526020604081850152818551808452606086019150828701935060005b81811015620010515784516001600160a01b0316835293830193918301916001016200102a565b5090979650505050505050565b600060208083850312156200107257600080fd5b82516001600160401b038111156200108957600080fd5b8301601f810185136200109b57600080fd5b8051620010ac62000c2d8262000be2565b81815260059190911b82018301908381019087831115620010cc57600080fd5b928401925b82841015620010ec57835182529284019290840190620010d1565b979650505050505050565b8181038181111562000b1d5762000b1d62000e04565b61484a806200111d6000396000f3fe6080604052600436106103dd5760003560e01c80638457213a116101fd578063c89039c511610118578063f1068454116100ab578063f6c016041161007a578063f6c0160414610d01578063f77c479114610d16578063f887ea4014610d36578063fb883d0c14610d56578063fbfa77cf14610d6c57600080fd5b8063f106845414610c8b578063f301af4214610ca1578063f499301814610cc1578063f55462f414610ce157600080fd5b8063da6eeedc116100e7578063da6eeedc14610c09578063e066ca1314610c1f578063e3b0a9df14610c4b578063ea762b7914610c6b57600080fd5b8063c89039c514610b94578063d0e30db014610bb4578063d51f3fe114610bc9578063d704ba9b14610be957600080fd5b8063ab033ea911610190578063bc063e1a1161015f578063bc063e1a14610b34578063c1a3d44c14610b4a578063c7b9d53014610b5f578063c836ef2e14610b7f57600080fd5b8063ab033ea914610a90578063ac1e502514610ab0578063aced166114610ad0578063b56a9f2c14610af057600080fd5b806391ed960a116101cc57806391ed960a14610a1957806392d663f114610a3a57806392eefe9b14610a50578063a9d75b2b14610a7057600080fd5b80638457213a146109c3578063853828b6146109995780638a0dac4a146109e35780638bc7e8c414610a0357600080fd5b80633f4ba83a116102f85780635fcbd2851161028b578063748747e61161025a578063748747e61461094557806379575b23146109655780637e744eea14610985578063837283c0146109995780638456cb59146109ae57600080fd5b80635fcbd285146108da5780636e840647146108fa57806371640de31461091a578063722713f71461093057600080fd5b806354fd4d50116102c757806354fd4d50146108435780635aa6e6751461086f5780635c38eb3a146108965780635c975abb146108b657600080fd5b80633f4ba83a146107e3578063452a9320146107f85780634641257d14610818578063504a16471461082d57600080fd5b80631f1fcd51116103705780632e1a7d4d1161033f5780632e1a7d4d1461076d578063342c330f1461078d5780633951f3df146107ad5780633e032a3b146107cd57600080fd5b80631f1fcd51146106f75780631fe4a6861461071757806320152f8f146107375780632c86d98e1461075757600080fd5b806315b18ddd116103ac57806315b18ddd1461066a5780631663cd9e1461068057806317d7de7c146106965780631bd43be3146106d757600080fd5b806305801aac146105c05780630df278f0146105fd5780631158808614610627578063117da1ee1461064a57600080fd5b366105bb576075546000906103fa906001600160a01b0316610d8c565b6040805160028082526060820183529293506000929091602083019080368337505060755482519293506001600160a01b03169183915060009061044057610440613e1e565b6001600160a01b039283166020918202929092010152603e5482519116908290600190811061047157610471613e1e565b6001600160a01b039283166020918202929092018101919091526075546040805163313ce56760e01b81529051600094929092169263313ce567926004808401938290030181865afa1580156104cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104ef9190613e34565b6104fa90600a613f9e565b6105048434613fad565b61050e9190613fda565b905060006084546072546084546105259190613fee565b61052f9084613fad565b6105399190613fda565b607754604051637ff36ab560e01b81529192506001600160a01b031690637ff36ab5903490610572908590889030904290600401614045565b60006040518083038185885af1158015610590573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f191682016040526105b9919081019061413a565b005b600080fd5b3480156105cc57600080fd5b506075546105e0906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561060957600080fd5b50610612610fb1565b604080519283526020830191909152016105f4565b34801561063357600080fd5b5061063c6110a4565b6040519081526020016105f4565b34801561065657600080fd5b506105b961066536600461416f565b6112e1565b34801561067657600080fd5b5061063c60385481565b34801561068c57600080fd5b5061063c607c5481565b3480156106a257600080fd5b5060408051808201909152600f81526e4c59462d41482d535452415445475960881b60208201525b6040516105f491906141d8565b3480156106e357600080fd5b5061063c6106f2366004614200565b611346565b34801561070357600080fd5b506035546105e0906001600160a01b031681565b34801561072357600080fd5b506001546105e0906001600160a01b031681565b34801561074357600080fd5b506105b961075236600461422b565b6113e2565b34801561076357600080fd5b5061063c607b5481565b34801561077957600080fd5b506105b961078836600461416f565b611408565b34801561079957600080fd5b506071546105e0906001600160a01b031681565b3480156107b957600080fd5b506105b96107c8366004614248565b61155f565b3480156107d957600080fd5b5061063c60725481565b3480156107ef57600080fd5b506105b96116f5565b34801561080457600080fd5b50603c546105e0906001600160a01b031681565b34801561082457600080fd5b506105b9611707565b34801561083957600080fd5b5061063c60395481565b34801561084f57600080fd5b506040805180820190915260038152620312e360ec1b60208201526106ca565b34801561087b57600080fd5b506000546105e090630100000090046001600160a01b031681565b3480156108a257600080fd5b506105b96108b13660046142b9565b611861565b3480156108c257600080fd5b5060005460ff165b60405190151581526020016105f4565b3480156108e657600080fd5b506076546105e0906001600160a01b031681565b34801561090657600080fd5b506105b9610915366004614200565b611897565b34801561092657600080fd5b5061063c607a5481565b34801561093c57600080fd5b5061063c6118c1565b34801561095157600080fd5b506105b9610960366004614200565b6118d0565b34801561097157600080fd5b506105b961098036600461416f565b6118fa565b34801561099157600080fd5b5060006108ca565b3480156109a557600080fd5b506105b9611907565b3480156109ba57600080fd5b506105b961199a565b3480156109cf57600080fd5b506105b96109de36600461416f565b6119aa565b3480156109ef57600080fd5b506105b96109fe366004614200565b611a24565b348015610a0f57600080fd5b5061063c603a5481565b348015610a2557600080fd5b506070546108ca90600160a01b900460ff1681565b348015610a4657600080fd5b5061063c607d5481565b348015610a5c57600080fd5b506105b9610a6b366004614200565b611a4e565b348015610a7c57600080fd5b50603e546105e0906001600160a01b031681565b348015610a9c57600080fd5b506105b9610aab366004614200565b611a78565b348015610abc57600080fd5b506105b9610acb36600461416f565b611aac565b348015610adc57600080fd5b506002546105e0906001600160a01b031681565b348015610afc57600080fd5b50610b05611b1a565b6040805196151587526020870195909552938501929092526060840152608083015260a082015260c0016105f4565b348015610b4057600080fd5b5061063c61271081565b348015610b5657600080fd5b5061063c611d8a565b348015610b6b57600080fd5b506105b9610b7a366004614200565b611df7565b348015610b8b57600080fd5b50610612611e21565b348015610ba057600080fd5b506036546105e0906001600160a01b031681565b348015610bc057600080fd5b506105b9611fdf565b348015610bd557600080fd5b506074546105e0906001600160a01b031681565b348015610bf557600080fd5b506105b9610c0436600461416f565b61206c565b348015610c1557600080fd5b5061063c607e5481565b348015610c2b57600080fd5b5060408051808201909152600381526218971960e91b60208201526106ca565b348015610c5757600080fd5b506070546105e0906001600160a01b031681565b348015610c7757600080fd5b506073546105e0906001600160a01b031681565b348015610c9757600080fd5b5061063c60795481565b348015610cad57600080fd5b506105e0610cbc36600461416f565b6120e3565b348015610ccd57600080fd5b506105b9610cdc36600461416f565b61210d565b348015610ced57600080fd5b506105b9610cfc36600461416f565b6121fe565b348015610d0d57600080fd5b5061063c612278565b348015610d2257600080fd5b50603b546105e0906001600160a01b031681565b348015610d4257600080fd5b506077546105e0906001600160a01b031681565b348015610d6257600080fd5b5061063c603d5481565b348015610d7857600080fd5b506037546105e0906001600160a01b031681565b600080826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610dcd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610df19190613e34565b60ff1690506000603e60009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e4b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6f9190613e34565b60ff1690506000610e8183600a6142f2565b6083546040516355cd56ff60e11b81526001600160a01b0388811660048301529091169063ab9aadfe90602401602060405180830381865afa158015610ecb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eef91906142fe565b610ef99190613fad565b90506000610f0883600a6142f2565b608354603e546040516355cd56ff60e11b81526001600160a01b03918216600482015291169063ab9aadfe90602401602060405180830381865afa158015610f54573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f7891906142fe565b610f829190613fad565b9050600081610f9285600a6142f2565b610f9c9085613fad565b610fa69190613fda565b979650505050505050565b607454607a54604051635787d29160e01b815260009283926001600160a01b0390911691635787d29191610feb9160040190815260200190565b602060405180830381865afa158015611008573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061102c91906142fe565b607454607a54604051635b06d70960e11b815260048101919091529192506001600160a01b03169063b60dae1290602401602060405180830381865afa15801561107a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109e91906142fe565b91509091565b6000806110af612278565b90506000806110bc611e21565b91509150600080607660009054906101000a90046001600160a01b03166001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015611116573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061113a919061432e565b506001600160701b031691506001600160701b031691506000607660009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ca91906142fe565b90506000816111d98886613fad565b6111e39190613fda565b90506000826111f28986613fad565b6111fc9190613fda565b9050600061120a8884613fee565b6040805160028082526060820183529293506000929091602083019080368337505060755482519293506001600160a01b03169183915060009061125057611250613e1e565b6001600160a01b039283166020918202929092010152603e5482519116908290600190811061128157611281613e1e565b60200260200101906001600160a01b031690816001600160a01b0316815250506000888411156112cf576112be6112b88a86613fee565b83612301565b6112c8908461437e565b90506112d2565b50815b9b9a5050505050505050505050565b6112e96123b0565b6112f16123f6565b6084548111156113415760405162461bcd60e51b8152602060048201526016602482015275736c697070616765206f7574206f6620626f756e647360501b60448201526064015b60405180910390fd5b607255565b60006113506123b0565b61135861244e565b6040516370a0823160e01b81523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa15801561139c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113c091906142fe565b603b549091506113dd906001600160a01b03848116911683612499565b919050565b6113ea6123f6565b60708054911515600160a01b0260ff60a01b19909216919091179055565b6114106123b0565b61141861244e565b611421816124f0565b50603e546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa15801561146b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061148f91906142fe565b9050818110156115375760006114a58383612545565b90506114c86127106114c2603d54866125be90919063ffffffff16565b906125ca565b8111156115355760405162461bcd60e51b815260206004820152603560248201527f626173652d73747261746567792f77697468647261772d6578636565642d6d616044820152741e0b59195d9a585d1a5bdb8b5d1a1c995cda1bdb19605a1b6064820152608401611338565b505b600061154382846125d6565b9050600061155961155483836125ec565b6125f8565b50505050565b60005462010000900460ff16158080156115845750600054600161010090910460ff16105b806115a45750303b1580156115a4575060005460ff610100909104166001145b6116075760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401611338565b6000805461ff001916610100179055801561162e576000805462ff00001916620100001790555b6116366123b0565b600080546301000000600160b81b03191663010000006001600160a01b038981169190910291909117909155600180546001600160a01b031990811688841617909155600280548216868416179055603b80548216878416179055603c80549091169184169190911790556032603d5580156116ed576000805462ff000019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b6116fd612655565b6117056126a7565b565b61170f6126f9565b603e546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015611758573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061177c91906142fe565b9050611786612784565b61178e612888565b603e546040516370a0823160e01b815230600482015260009183916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156117db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117ff91906142fe565b6118099190613fee565b9050611813612e05565b80607d60008282546118259190613fee565b90915550506040518181527f80f97f878e16410266694f134ddf012f2be424f54f8b5cafa107eccc51d00d589060200160405180910390a15050565b6118696123f6565b6001600160a01b03918216600090815260826020526040902080546001600160a01b03191691909216179055565b61189f6123f6565b607180546001600160a01b0319166001600160a01b0392909216919091179055565b60006118cb6110a4565b905090565b6118d8612655565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b6119026123f6565b607b55565b61190f6123b0565b61191761244e565b61191f613240565b6036546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015611968573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061198c91906142fe565b9050611997816125f8565b50565b6119a2613267565b6117056132cb565b6119b2612655565b612710811115611a1f5760405162461bcd60e51b815260206004820152603260248201527f626173652d73747261746567792f6578636573736976652d676f7665726e616e60448201527163652d706572666f726d616e63652d66656560701b6064820152608401611338565b603855565b611a2c612655565b603c80546001600160a01b0319166001600160a01b0392909216919091179055565b611a56612655565b603b80546001600160a01b0319166001600160a01b0392909216919091179055565b611a80612655565b600080546001600160a01b039092166301000000026301000000600160b81b0319909216919091179055565b611ab4612655565b612710811115611b155760405162461bcd60e51b815260206004820152602660248201527f626173652d73747261746567792f6578636573736976652d7769746864726177604482015265616c2d66656560d01b6064820152608401611338565b603a55565b600080600080600080611b2b6110a4565b9350611b35613308565b607454607a54604051635787d29160e01b81529298506000926001600160a01b0390921691635787d29191611b709160040190815260200190565b602060405180830381865afa158015611b8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bb191906142fe565b607454607a54604051635b06d70960e11b81529293506000926001600160a01b039092169163b60dae1291611bec9160040190815260200190565b602060405180830381865afa158015611c09573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c2d91906142fe565b90508060845483611c3e9190613fad565b611c489190613fda565b607554909750611c60906001600160a01b0316613390565b9350607c548410611c9657607c54608454611c7b8287613fee565b611c859190613fad565b611c8f9190613fda565b9450611cbd565b607c54608454611ca68683613fee565b611cb09190613fad565b611cba9190613fda565b94505b6103e86084546019611ccf9190613fad565b611cd99190613fda565b851015611ce95760009250611d80565b6103e86084546032611cfb9190613fad565b611d059190613fda565b851015611d2e57600a6084546002611d1d9190613fad565b611d279190613fda565b9250611d80565b6103e8608454604b611d409190613fad565b611d4a9190613fda565b851015611d6257600a6084546004611d1d9190613fad565b6064608454604b611d739190613fad565b611d7d9190613fda565b92505b5050909192939495565b6035546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015611dd3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118cb91906142fe565b611dff612655565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b607454607a54604051631b5abccd60e21b81526000928392839283926001600160a01b031691636d6af33491611e5e919060040190815260200190565b600060405180830381865afa158015611e7b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611ea39190810190614391565b915091508151600203611f5657603e5482516001600160a01b03909116908390600090611ed257611ed2613e1e565b60200260200101516001600160a01b031603611f285780600081518110611efb57611efb613e1e565b602002602001015181600181518110611f1657611f16613e1e565b60200260200101519350935050509091565b80600181518110611f3b57611f3b613e1e565b602002602001015181600081518110611f1657611f16613e1e565b8151600103611fd357603e5482516001600160a01b03909116908390600090611f8157611f81613e1e565b60200260200101516001600160a01b031603611fbe5780600081518110611faa57611faa613e1e565b602002602001015160009350935050509091565b600081600081518110611f1657611f16613e1e565b50600093849350915050565b611fe76123b0565b611fef61364e565b603e546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015612038573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061205c91906142fe565b9050801561199757611997612e05565b612074612655565b6127108111156120de5760405162461bcd60e51b815260206004820152602f60248201527f626173652d73747261746567792f6578636573736976652d6d61782d6465766960448201526e185d1a5bdb8b5d1a1c995cda1bdb19608a1b6064820152608401611338565b603d55565b607881815481106120f357600080fd5b6000918252602090912001546001600160a01b0316905081565b6121156126f9565b61211d6136c4565b6000612127613722565b905080612132575050565b61213b82613829565b50612144612e05565b6001607e6000828254612157919061437e565b9091555050607554600090612174906001600160a01b0316613390565b6084549091506121848483613fad565b61218e9190613fda565b60845461219b8582613fee565b607c546121a89190613fad565b6121b29190613fda565b6121bc919061437e565b607c556040805184815242602082015243917fa945421a11628be89b1371dfc849819b1569bd18c14c130fc14f882c418eba8d910160405180910390a2505050565b612206612655565b6127108111156122735760405162461bcd60e51b815260206004820152603260248201527f626173652d73747261746567792f6578636573736976652d737472617465676960448201527173742d706572666f726d616e63652d66656560701b6064820152608401611338565b603955565b607454607a5460405163519f509960e01b815260048101919091526000916001600160a01b03169063519f509990602401608060405180830381865afa1580156122c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122ea9190614456565b949350505050565b6001600160a01b03163b151590565b60775460405163d06ca61f60e01b815260009182916001600160a01b039091169063d06ca61f90612338908790879060040161449e565b600060405180830381865afa158015612355573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261237d919081019061413a565b9050806001825161238e9190613fee565b8151811061239e5761239e613e1e565b60200260200101519150505b92915050565b60005460ff16156117055760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401611338565b600054630100000090046001600160a01b031633146117055760405162461bcd60e51b81526020600482015260146024820152736f6e6c79417574686f72697a65644163746f727360601b6044820152606401611338565b603b546001600160a01b031633146117055760405162461bcd60e51b815260206004820152600e60248201526d37b7363ca1b7b73a3937b63632b960911b6044820152606401611338565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526124eb908490613be9565b505050565b6000607a5460000361250457506000919050565b600061250e6110a4565b9050600081608454856125219190613fad565b61252b9190613fda565b905060845481111561253c57506084545b6122ea81613829565b6000818310156125ad5760405162461bcd60e51b815260206004820152602d60248201527f646966662f65787065637465642d6869676865722d6e756d6265722d696e2d6660448201526c34b939ba16b837b9b4ba34b7b760991b6064820152608401611338565b6125b783836125ec565b9392505050565b60006125b78284613fad565b60006125b78284613fda565b60008183106125e557816125b7565b5090919050565b60006125b78284613fee565b6037546001600160a01b03168061263a5760405162461bcd60e51b8152602060048201526006602482015265085d985d5b1d60d21b6044820152606401611338565b603e54612651906001600160a01b03168284612499565b5050565b600054630100000090046001600160a01b031633146117055760405162461bcd60e51b815260206004820152600e60248201526d6f6e6c79476f7665726e616e636560901b6044820152606401611338565b6126af613cbb565b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6002546001600160a01b03163314806127235750600054630100000090046001600160a01b031633145b806127385750603b546001600160a01b031633145b6117055760405162461bcd60e51b815260206004820181905260248201527f6f6e6c79417574686f72697a65644163746f72734f72436f6e74726f6c6c65726044820152606401611338565b61278c6136c4565b6000612796613722565b9050806127a05750565b607454607a54607354604080518082018252601481527368617276657374574d617374657243686566282960601b602082015281516004815260248101928390526001600160a01b039586169563710a9f68959416929091612801916144b7565b60408051918290039091206020830180516001600160e01b03166001600160e01b0319928316179052905160e086901b9091168152612845939291906004016144d3565b6020604051808303816000875af1158015612864573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061265191906142fe565b60005b607854811015611997576000607882815481106128aa576128aa613e1e565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa1580156128fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061291f91906142fe565b9050600081116129655760405162461bcd60e51b81526020600482015260116024820152706469646e7420676574207265776172647360781b6044820152606401611338565b6000806001600160a01b0316608260006078868154811061298857612988613e1e565b60009182526020808320909101546001600160a01b0390811684529083019390935260409091019020541614612b8657603e546001600160a01b03908116600090815260826020526040808220548151633fabe5a360e21b815291519293169163feaf968c9160048082019260a0929091908290030181865afa158015612a13573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a379190614520565b50505091505060006082600060788781548110612a5657612a56613e1e565b60009182526020808320909101546001600160a01b0390811684529083019390935260409182019020548151633fabe5a360e21b8152915192169163feaf968c9160048082019260a0929091908290030181865afa158015612abc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ae09190614520565b50505091505081603e60009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b3a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b5e9190613e34565b612b6990600a614641565b612b739083614650565b612b7d9190614680565b92505050612bb9565b612bb660788481548110612b9c57612b9c613e1e565b6000918252602090912001546001600160a01b0316613390565b90505b600060788481548110612bce57612bce613e1e565b600091825260209182902001546040805163313ce56760e01b815290516001600160a01b039092169263313ce567926004808401938290030181865afa158015612c1c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c409190613e34565b612c4b90600a613f9e565b612c558385613fad565b612c5f9190613fda565b90506000608454607254608454612c769190613fee565b612c809084613fad565b612c8a9190613fda565b905060008111612cd45760405162461bcd60e51b815260206004820152601560248201527410985919081cdb1a5c1c1859d94818dbdb9d1c9bdb605a1b6044820152606401611338565b60408051600280825260608201835260009260208301908036833701905050905060788681548110612d0857612d08613e1e565b600091825260208220015482516001600160a01b03909116918391612d2f57612d2f613e1e565b6001600160a01b039283166020918202929092010152603e54825191169082906001908110612d6057612d60613e1e565b6001600160a01b0392831660209182029290920101526077546040516338ed173960e01b81529116906338ed173990612da590889086908690309042906004016146ae565b6000604051808303816000875af1158015612dc4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612dec919081019061413a565b5050505050508080612dfd906146ea565b91505061288b565b612e0d6136c4565b603e546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015612e56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e7a91906142fe565b905080607d6000828254612e8e919061437e565b9091555050607b54600090612ea590600190613fee565b905060006002607b54612eb89190613fee565b607b54612ec59190613fda565b612ed090600161437e565b608454612edd9190613fda565b9050600081608454612eef9190613fee565b90506000608454848487612f039190613fad565b612f0d9190613fad565b612f179190613fda565b90506000608454858488612f2b9190613fad565b612f359190613fad565b612f3f9190613fda565b60408051600280825260608201835292935060009290916020830190803683375050603e5482519293506001600160a01b031691839150600090612f8557612f85613e1e565b6001600160a01b039283166020918202929092010152607554825191169082906001908110612fb657612fb6613e1e565b60200260200101906001600160a01b031690816001600160a01b0316815250506000612fe28383612301565b905087612ff0856002613fad565b148061300f5750613002600189613fee565b61300d856002613fad565b145b61301857600080fd5b600060845460725460845461302d9190613fee565b6130378b8861437e565b6130419190613fad565b61304b9190613fda565b905060006084546072546084546130629190613fee565b61306c9085613fad565b6130769190613fda565b905060006040518061010001604052808c8152602001600081526020016000815260200188815260200185815260200160008152602001848152602001838152509050607460009054906101000a90046001600160a01b03166001600160a01b031663710a9f68607a54607360009054906101000a90046001600160a01b03166040518060a00160405280607281526020016147a360729139603e54607554607954604080516001600160a01b03948516602482015293909216604484015288516064840152602089015160848401529088015160a4830152606088015160c4830152608088015160e483015260a088015161010483015260c088015161012483015260e08801516101448301526101648201526101840160408051601f1981840301815290829052916131a9916144b7565b60408051918290039091206020830180516001600160e01b03166001600160e01b0319928316179052905160e086901b90911681526131ed939291906004016144d3565b6020604051808303816000875af115801561320c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061323091906142fe565b607a555050505050505050505050565b607a5460000361324c57565b613254612784565b61325c612888565b611997608454613829565b603c546001600160a01b03163314806132915750600054630100000090046001600160a01b031633145b6117055760405162461bcd60e51b815260206004820152600b60248201526a6f6e6c795061757365727360a81b6044820152606401611338565b6132d36123b0565b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586126dc3390565b6075546000908190613322906001600160a01b0316610d8c565b60755490915060009061333d906001600160a01b0316613390565b9050600082608454836133509190613fad565b61335a9190613fda565b905060845481101561338057607f54816084546133779190613fee565b10935050505090565b607f546084546133779083613fee565b600080607760009054906101000a90046001600160a01b03166001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156133e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061340a9190614703565b603e5460405163e6a4390560e01b81526001600160a01b03918216600482015285821660248201529192506000919083169063e6a4390590604401602060405180830381865afa158015613462573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134869190614703565b9050600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa1580156134c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134ed919061432e565b506001600160701b031691506001600160701b031691506000866001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613544573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135689190613e34565b60ff169050603e60009054906101000a90046001600160a01b03166001600160a01b0316846001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156135ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135ee9190614703565b6001600160a01b0316036136225761360781600a6142f2565b6136119083613fda565b61361b9084613fda565b9550613644565b61362d81600a6142f2565b6136379084613fda565b6136419083613fda565b95505b5050505050919050565b600054630100000090046001600160a01b03163314806136785750603b546001600160a01b031633145b6117055760405162461bcd60e51b815260206004820152601860248201527f6f6e6c79436f6e74726f6c6c65724f72476f7665726e6f7200000000000000006044820152606401611338565b60006136ce613308565b90506001811515146119975760405162461bcd60e51b815260206004820152601f60248201527f726561736f6e3a204f7261636c6520507269636520646966666572656e6365006044820152606401611338565b607554600090819061373c906001600160a01b0316613390565b90506000607c5482111561377557607c5460845461375a8285613fee565b6137649190613fad565b61376e9190613fda565b905061379c565b607c546084546137858483613fee565b61378f9190613fad565b6137999190613fda565b90505b6081548111156137ee5760405162461bcd60e51b815260206004820152601760248201527f4661696c656420766f6c6169746c69747920636865636b0000000000000000006044820152606401611338565b60006137f8611b1a565b5050505091505060805481111561381f57613814608454613829565b506000935050505090565b6001935050505090565b60006138336136c4565b600061383d612278565b9050613847612278565b81146138865760405162461bcd60e51b815260206004820152600e60248201526d4c6f7374206c7020746f6b656e7360901b6044820152606401611338565b603e546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa1580156138cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138f391906142fe565b9050600080613900611e21565b91509150600060845487866139159190613fad565b61391f9190613fda565b9050600060845488856139329190613fad565b61393c9190613fda565b90506000608454898561394f9190613fad565b6139599190613fda565b9050608454890361396b575050608554805b60006139756110a4565b905060006084548b836139889190613fad565b6139929190613fda565b905060006084546072546084546139a99190613fee565b6139b39084613fad565b6139bd9190613fda565b6040805160e081018252888152600060208083018290528284018a9052606083018990526080830182905260a080840186905260c0840192909252607454607a546073548651948501909652606580855296975093956001600160a01b039182169563710a9f68959492169261473e90830139603e54607554604080516001600160a01b039384166024820152929091166044830152875160648301526020880151608483015287015160a4820152606087015160c4820152608087015160e482015260a087015161010482015260c08701516101248201526101440160408051601f198184030181529082905291613ab5916144b7565b60408051918290039091206020830180516001600160e01b03166001600160e01b0319928316179052905160e086901b9091168152613af9939291906004016144d3565b6020604051808303816000875af1158015613b18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b3c91906142fe565b50603e546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015613b86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613baa91906142fe565b9050613bb68b82613fee565b607d6000828254613bc79190613fee565b90915550613bd790508b82613fee565b9e9d5050505050505050505050505050565b6000613c3e826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316613d049092919063ffffffff16565b8051909150156124eb5780806020019051810190613c5c9190614720565b6124eb5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401611338565b60005460ff166117055760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401611338565b60606122ea8484600085856001600160a01b0385163b613d665760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401611338565b600080866001600160a01b03168587604051613d8291906144b7565b60006040518083038185875af1925050503d8060008114613dbf576040519150601f19603f3d011682016040523d82523d6000602084013e613dc4565b606091505b5091509150610fa682828660608315613dde5750816125b7565b825115613dee5782518084602001fd5b8160405162461bcd60e51b815260040161133891906141d8565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600060208284031215613e4657600080fd5b815160ff811681146125b757600080fd5b634e487b7160e01b600052601160045260246000fd5b600181815b80851115613ea8578160001904821115613e8e57613e8e613e57565b80851615613e9b57918102915b93841c9390800290613e72565b509250929050565b80825b6001808611613ec25750613ef5565b6001600160ff1b03829004821115613edc57613edc613e57565b80861615613ee957918102915b9490941c938002613eb3565b935093915050565b600082613f0c575060016123aa565b81613f19575060006123aa565b8160018114613f2f5760028114613f3957613f55565b60019150506123aa565b60ff841115613f4a57613f4a613e57565b50506001821b6123aa565b5060208310610133831016604e8410600b8410161715613f78575081810a6123aa565b613f828383613e6d565b8060001904821115613f9657613f96613e57565b029392505050565b60006125b760ff841683613efd565b80820281158282048414176123aa576123aa613e57565b634e487b7160e01b600052601260045260246000fd5b600082613fe957613fe9613fc4565b500490565b818103818111156123aa576123aa613e57565b600081518084526020808501945080840160005b8381101561403a5781516001600160a01b031687529582019590820190600101614015565b509495945050505050565b84815260806020820152600061405e6080830186614001565b6001600160a01b03949094166040830152506060015292915050565b604051601f8201601f1916810167ffffffffffffffff811182821017156140a3576140a3613e08565b604052919050565b600067ffffffffffffffff8211156140c5576140c5613e08565b5060051b60200190565b600082601f8301126140e057600080fd5b815160206140f56140f0836140ab565b61407a565b82815260059290921b8401810191818101908684111561411457600080fd5b8286015b8481101561412f5780518352918301918301614118565b509695505050505050565b60006020828403121561414c57600080fd5b815167ffffffffffffffff81111561416357600080fd5b6122ea848285016140cf565b60006020828403121561418157600080fd5b5035919050565b60005b838110156141a357818101518382015260200161418b565b50506000910152565b600081518084526141c4816020860160208601614188565b601f01601f19169290920160200192915050565b6020815260006125b760208301846141ac565b6001600160a01b038116811461199757600080fd5b60006020828403121561421257600080fd5b81356125b7816141eb565b801515811461199757600080fd5b60006020828403121561423d57600080fd5b81356125b78161421d565b600080600080600060a0868803121561426057600080fd5b853561426b816141eb565b9450602086013561427b816141eb565b9350604086013561428b816141eb565b9250606086013561429b816141eb565b915060808601356142ab816141eb565b809150509295509295909350565b600080604083850312156142cc57600080fd5b82356142d7816141eb565b915060208301356142e7816141eb565b809150509250929050565b60006125b78383613efd565b60006020828403121561431057600080fd5b5051919050565b80516001600160701b03811681146113dd57600080fd5b60008060006060848603121561434357600080fd5b61434c84614317565b925061435a60208501614317565b9150604084015163ffffffff8116811461437357600080fd5b809150509250925092565b808201808211156123aa576123aa613e57565b600080604083850312156143a457600080fd5b825167ffffffffffffffff808211156143bc57600080fd5b818501915085601f8301126143d057600080fd5b815160206143e06140f0836140ab565b82815260059290921b840181019181810190898411156143ff57600080fd5b948201945b83861015614426578551614417816141eb565b82529482019490820190614404565b9188015191965090935050508082111561443f57600080fd5b5061444c858286016140cf565b9150509250929050565b6000806000806080858703121561446c57600080fd5b8451614477816141eb565b6020860151909450614488816141eb565b6040860151606090960151949790965092505050565b8281526040602082015260006122ea6040830184614001565b600082516144c9818460208701614188565b9190910192915050565b8381526001600160a01b03831660208201526060604082018190526000906144fd908301846141ac565b95945050505050565b805169ffffffffffffffffffff811681146113dd57600080fd5b600080600080600060a0868803121561453857600080fd5b61454186614506565b945060208601519350604086015192506060860151915061456460808701614506565b90509295509295909350565b6000828015613f2f576001810361458a57829150506123aa565b5081614598575060006123aa565b506001600082138082146145b15780156145d0576145ea565b6001600160ff1b038390048311156145cb576145cb613e57565b6145ea565b6001600160ff1b038390058312156145ea576145ea613e57565b50808316156145f65750805b6146068360011c83840283613eb0565b600082136001600160ff1b038290048311161561462557614625613e57565b60008212600160ff1b82900583121615613f9657613f96613e57565b60006125b760ff841683614570565b80820260008212600160ff1b8414161561466c5761466c613e57565b81810583148215176123aa576123aa613e57565b60008261468f5761468f613fc4565b600160ff1b8214600019841416156146a9576146a9613e57565b500590565b85815284602082015260a0604082015260006146cd60a0830186614001565b6001600160a01b0394909416606083015250608001529392505050565b6000600182016146fc576146fc613e57565b5060010190565b60006020828403121561471557600080fd5b81516125b7816141eb565b60006020828403121561473257600080fd5b81516125b78161421d56fe72656d6f76654c6971756964697479574d61737465724368656628616464726573732c616464726573732c2875696e743235362c75696e743235362c75696e743235362c75696e743235362c75696e743235362c75696e743235362c75696e7432353629296164644c6971756964697479574d61737465724368656628616464726573732c616464726573732c2875696e743235362c75696e743235362c75696e743235362c75696e743235362c75696e743235362c75696e743235362c75696e743235362c75696e74323536292c75696e7432353629a26469706673582212200b50ec91dc61e3a062285a4a5911b7555ecbc6ef09f681ea45c5ab8a80a8787764736f6c63430008110033000000000000000000000000e6edf5d683d74a2f5623284d4722bcdbf1fd7d43000000000000000000000000e878d69526e611d0e547bcfd64f5a28d15ae20fd0000000000000000000000009251bf28564c6085bd27cddea1a5bcd999066ec8000000000000000000000000e878d69526e611d0e547bcfd64f5a28d15ae20fd000000000000000000000000e878d69526e611d0e547bcfd64f5a28d15ae20fd000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000032000000000000000000000000172c106130c363b25760eb3db234c94e37ee7ae4000000000000000000000000000000000000000000000000000000000000000500000000000000000000000005edd168030a821d6afdbd6b1134348870e08520000000000000000000000000376d16c7de138b01455a51da79ad65806e9cd694000000000000000000000000ed8cbd9f0ce3c6986b22002f03c6475ceb7a625600000000000000000000000060ae616a2155ee3d9a68541ba4544862310933d4000000000000000000000000c842cc25fe89f0a60fe9c1fd6483b6971020eb3a00000000000000000000000000000000000000000000000000000000000000010000000000000000000000006e84a6216ea6dacc71ee8e6b0a5b7322eebc0fdd

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

000000000000000000000000e6edf5d683d74a2f5623284d4722bcdbf1fd7d43000000000000000000000000e878d69526e611d0e547bcfd64f5a28d15ae20fd0000000000000000000000009251bf28564c6085bd27cddea1a5bcd999066ec8000000000000000000000000e878d69526e611d0e547bcfd64f5a28d15ae20fd000000000000000000000000e878d69526e611d0e547bcfd64f5a28d15ae20fd000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000032000000000000000000000000172c106130c363b25760eb3db234c94e37ee7ae4000000000000000000000000000000000000000000000000000000000000000500000000000000000000000005edd168030a821d6afdbd6b1134348870e08520000000000000000000000000376d16c7de138b01455a51da79ad65806e9cd694000000000000000000000000ed8cbd9f0ce3c6986b22002f03c6475ceb7a625600000000000000000000000060ae616a2155ee3d9a68541ba4544862310933d4000000000000000000000000c842cc25fe89f0a60fe9c1fd6483b6971020eb3a00000000000000000000000000000000000000000000000000000000000000010000000000000000000000006e84a6216ea6dacc71ee8e6b0a5b7322eebc0fdd

-----Decoded View---------------
Arg [0] : _governance (address): 0xe6edf5d683d74a2f5623284d4722bcdbf1fd7d43
Arg [1] : _strategist (address): 0xe878d69526e611d0e547bcfd64f5a28d15ae20fd
Arg [2] : _controller (address): 0x9251bf28564c6085bd27cddea1a5bcd999066ec8
Arg [3] : _keeper (address): 0xe878d69526e611d0e547bcfd64f5a28d15ae20fd
Arg [4] : _guardian (address): 0xe878d69526e611d0e547bcfd64f5a28d15ae20fd
Arg [5] : _pid (uint256): 28
Arg [6] : _leverage (uint256): 3
Arg [7] : config (address[]): 0x05edd168030a821d6afdbd6b1134348870e08520,0x376d16c7de138b01455a51da79ad65806e9cd694,0xed8cbd9f0ce3c6986b22002f03c6475ceb7a6256,0x60ae616a2155ee3d9a68541ba4544862310933d4,0xc842cc25fe89f0a60fe9c1fd6483b6971020eb3a
Arg [8] : _rewards (address[]): 0x6e84a6216ea6dacc71ee8e6b0a5b7322eebc0fdd
Arg [9] : _feeConfig (uint256[3]): 1000,1000,50
Arg [10] : _vault (address): 0x172c106130c363b25760eb3db234c94e37ee7ae4

-----Encoded View---------------
21 Constructor Arguments found :
Arg [0] : 000000000000000000000000e6edf5d683d74a2f5623284d4722bcdbf1fd7d43
Arg [1] : 000000000000000000000000e878d69526e611d0e547bcfd64f5a28d15ae20fd
Arg [2] : 0000000000000000000000009251bf28564c6085bd27cddea1a5bcd999066ec8
Arg [3] : 000000000000000000000000e878d69526e611d0e547bcfd64f5a28d15ae20fd
Arg [4] : 000000000000000000000000e878d69526e611d0e547bcfd64f5a28d15ae20fd
Arg [5] : 000000000000000000000000000000000000000000000000000000000000001c
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000003
Arg [7] : 00000000000000000000000000000000000000000000000000000000000001a0
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000260
Arg [9] : 00000000000000000000000000000000000000000000000000000000000003e8
Arg [10] : 00000000000000000000000000000000000000000000000000000000000003e8
Arg [11] : 0000000000000000000000000000000000000000000000000000000000000032
Arg [12] : 000000000000000000000000172c106130c363b25760eb3db234c94e37ee7ae4
Arg [13] : 0000000000000000000000000000000000000000000000000000000000000005
Arg [14] : 00000000000000000000000005edd168030a821d6afdbd6b1134348870e08520
Arg [15] : 000000000000000000000000376d16c7de138b01455a51da79ad65806e9cd694
Arg [16] : 000000000000000000000000ed8cbd9f0ce3c6986b22002f03c6475ceb7a6256
Arg [17] : 00000000000000000000000060ae616a2155ee3d9a68541ba4544862310933d4
Arg [18] : 000000000000000000000000c842cc25fe89f0a60fe9c1fd6483b6971020eb3a
Arg [19] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [20] : 0000000000000000000000006e84a6216ea6dacc71ee8e6b0a5b7322eebc0fdd


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