ETH Price: $3,483.91 (-1.45%)
Gas: 3 Gwei

Token

Sommelier Aave V2 Stablecoin Cellar LP Token (aave2-CLR-S)
 

Overview

Max Total Supply

6,026.650782472607418378 aave2-CLR-S

Holders

207

Market

Onchain Market Cap

$0.00

Circulating Supply Market Cap

-

Other Info

Token Contract (WITH 18 Decimals)

Filtered by Token Holder
creolyang.eth
Balance
0.000000076679074739 aave2-CLR-S

Value
$0.00
0xe6C6523Cd68E73C55958BcA91616b109B1ED061b
Loading...
Loading
Loading...
Loading
Loading...
Loading

Click here to update the token information / general information
# Exchange Pair Price  24H Volume % Volume
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.

Contract Source Code Verified (Exact Match)

Contract Name:
AaveV2StablecoinCellar

Compiler Version
v0.8.15+commit.e14f2714

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 35 : AaveV2StablecoinCellar.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC4626, ERC20, SafeTransferLib } from "./base/ERC4626.sol";
import { Multicall } from "./base/Multicall.sol";
import { Ownable } from "lib/openzeppelin-contracts/contracts/access/Ownable.sol";
import { IAaveV2StablecoinCellar } from "./interfaces/IAaveV2StablecoinCellar.sol";
import { IAaveIncentivesController } from "./interfaces/IAaveIncentivesController.sol";
import { IStakedTokenV2 } from "./interfaces/IStakedTokenV2.sol";
import { ICurveSwaps } from "./interfaces/ICurveSwaps.sol";
import { ISushiSwapRouter } from "./interfaces/ISushiSwapRouter.sol";
import { IGravity } from "./interfaces/IGravity.sol";
import { ILendingPool } from "./interfaces/ILendingPool.sol";
import { Math } from "./utils/Math.sol";

import "./Errors.sol";

/**
 * @title Sommelier Aave V2 Stablecoin Cellar
 * @notice Dynamic ERC4626 that changes positions to always get the best yield for stablecoins on Aave.
 * @author Brian Le
 */
contract AaveV2StablecoinCellar is IAaveV2StablecoinCellar, ERC4626, Multicall, Ownable {
    using SafeTransferLib for ERC20;
    using Math for uint256;

    // ======================================== POSITION STORAGE ========================================

    /**
     * @notice An interest-bearing derivative of the current asset returned by Aave for lending
     *         the current asset. Represents cellar's portion of assets earning yield in a lending
     *         position.
     */
    ERC20 public assetAToken;

    /**
     * @notice The decimals of precision used by the current position's asset.
     * @dev Since some stablecoins don't use the standard 18 decimals of precision (eg. USDC and USDT),
     *      we cache this to use for more efficient decimal conversions.
     */
    uint8 public assetDecimals;

    /**
     * @notice The total amount of assets held in the current position since the time of last accrual.
     * @dev Unlike `totalAssets`, this includes locked yield that hasn't been distributed.
     */
    uint256 public totalBalance;

    // ======================================== ACCRUAL CONFIG ========================================

    /**
     * @notice Period of time over which yield since the last accrual is linearly distributed to the cellar.
     * @dev Net gains are distributed gradually over a period to prevent frontrunning and sandwich attacks.
     *      Net losses are realized immediately otherwise users could time exits to sidestep losses.
     */
    uint32 public accrualPeriod = 7 days;

    /**
     * @notice Timestamp of when the last accrual occurred.
     */
    uint64 public lastAccrual;

    /**
     * @notice The amount of yield to be distributed to the cellar from the last accrual.
     */
    uint160 public maxLocked;

    /**
     * @notice The minimum level of total balance a strategy provider needs to achieve to receive
     *         performance fees for the next accrual.
     */
    uint256 public highWatermarkBalance;

    /**
     * @notice Set the accrual period over which yield is distributed.
     * @param newAccrualPeriod period of time in seconds of the new accrual period
     */
    function setAccrualPeriod(uint32 newAccrualPeriod) external onlyOwner {
        // Ensure that the change is not disrupting a currently ongoing distribution of accrued yield.
        if (totalLocked() > 0) revert STATE_AccrualOngoing();

        emit AccrualPeriodChanged(accrualPeriod, newAccrualPeriod);

        accrualPeriod = newAccrualPeriod;
    }

    // ========================================= FEES CONFIG =========================================

    /**
     *  @notice The percentage of yield accrued as performance fees.
     *  @dev This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%).
     */
    uint64 public constant platformFee = 0.0025e18; // 0.25%

    /**
     * @notice The percentage of total assets accrued as platform fees over a year.
     * @dev This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%).
     */
    uint64 public constant performanceFee = 0.1e18; // 10%

    /**
     * @notice Cosmos address of module that distributes fees, specified as a hex value.
     * @dev The Gravity contract expects a 32-byte value formatted in a specific way.
     */
    bytes32 public feesDistributor = hex"000000000000000000000000b813554b423266bbd4c16c32fa383394868c1f55";

    /**
     * @notice Set the address of the fee distributor on the Sommelier chain.
     * @dev IMPORTANT: Ensure that the address is formatted in the specific way that the Gravity contract
     *      expects it to be.
     * @param newFeesDistributor formatted address of the new fee distributor module
     */
    function setFeesDistributor(bytes32 newFeesDistributor) external onlyOwner {
        emit FeesDistributorChanged(feesDistributor, newFeesDistributor);

        feesDistributor = newFeesDistributor;
    }

    // ======================================== TRUST CONFIG ========================================

    /**
     * @notice Whether an asset position is trusted or not. Prevents cellar from rebalancing into an
     *         asset that has not been trusted by the users. Trusting / distrusting of an asset is done
     *         through governance.
     */
    mapping(ERC20 => bool) public isTrusted;

    /**
     * @notice Set the trust for a position.
     * @param position address of an asset position on Aave (eg. FRAX, UST, FEI).
     * @param trust whether to trust or distrust
     */
    function setTrust(ERC20 position, bool trust) external onlyOwner {
        isTrusted[position] = trust;

        // In the case that validators no longer trust the current position, pull all assets back
        // into the cellar.
        ERC20 currentPosition = asset;
        if (trust == false && position == currentPosition) _emptyPosition(currentPosition);

        emit TrustChanged(address(position), trust);
    }

    // ======================================== LIMITS CONFIG ========================================

    /**
     * @notice Maximum amount of assets that can be managed by the cellar. Denominated in the same decimals
     *         as the current asset.
     * @dev Set to `type(uint256).max` to have no limit.
     */
    uint256 public liquidityLimit;

    /**
     * @notice Maximum amount of assets per wallet. Denominated in the same decimals as the current asset.
     * @dev Set to `type(uint256).max` to have no limit.
     */
    uint256 public depositLimit;

    /**
     * @notice Set the maximum liquidity that cellar can manage. Uses the same decimals as the current asset.
     * @param newLimit amount of assets to set as the new limit
     */
    function setLiquidityLimit(uint256 newLimit) external onlyOwner {
        emit LiquidityLimitChanged(liquidityLimit, newLimit);

        liquidityLimit = newLimit;
    }

    /**
     * @notice Set the per-wallet deposit limit. Uses the same decimals as the current asset.
     * @param newLimit amount of assets to set as the new limit
     */
    function setDepositLimit(uint256 newLimit) external onlyOwner {
        emit DepositLimitChanged(depositLimit, newLimit);

        depositLimit = newLimit;
    }

    // ======================================== EMERGENCY LOGIC ========================================

    /**
     * @notice Whether or not the contract is shutdown in case of an emergency.
     */
    bool public isShutdown;

    /**
     * @notice Prevent a function from being called during a shutdown.
     */
    modifier whenNotShutdown() {
        if (isShutdown) revert STATE_ContractShutdown();

        _;
    }

    /**
     * @notice Shutdown the cellar. Used in an emergency or if the cellar has been deprecated.
     * @param emptyPosition whether to pull all assets back into the cellar from the current position
     */
    function initiateShutdown(bool emptyPosition) external whenNotShutdown onlyOwner {
        // Pull all assets from a position.
        if (emptyPosition) _emptyPosition(asset);

        isShutdown = true;

        emit ShutdownInitiated(emptyPosition);
    }

    /**
     * @notice Restart the cellar.
     */
    function liftShutdown() external onlyOwner {
        isShutdown = false;

        emit ShutdownLifted();
    }

    // ======================================== INITIALIZATION ========================================

    /**
     * @notice Curve Registry Exchange contract. Used for rebalancing positions.
     */
    ICurveSwaps public immutable curveRegistryExchange; // 0x81C46fECa27B31F3ADC2b91eE4be9717d1cd3DD7

    /**
     * @notice SushiSwap Router V2 contract. Used for reinvesting rewards back into the current position.
     */
    ISushiSwapRouter public immutable sushiswapRouter; // 0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F

    /**
     * @notice Aave Lending Pool V2 contract. Used to deposit and withdraw from the current position.
     */
    ILendingPool public immutable lendingPool; // 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9

    /**
     * @notice Aave Incentives Controller V2 contract. Used to claim and unstake rewards to reinvest.
     */
    IAaveIncentivesController public immutable incentivesController; // 0xd784927Ff2f95ba542BfC824c8a8a98F3495f6b5

    /**
     * @notice Cosmos Gravity Bridge contract. Used to transfer fees to `feeDistributor` on the Sommelier chain.
     */
    IGravity public immutable gravityBridge; // 0x69592e6f9d21989a043646fE8225da2600e5A0f7

    /**
     * @notice stkAAVE address. Used to swap rewards to the current asset to reinvest.
     */
    IStakedTokenV2 public immutable stkAAVE; // 0x4da27a545c0c5B758a6BA100e3a049001de870f5

    /**
     * @notice AAVE address. Used to swap rewards to the current asset to reinvest.
     */
    ERC20 public immutable AAVE; // 0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9

    /**
     * @notice WETH address. Used to swap rewards to the current asset to reinvest.
     */
    ERC20 public immutable WETH; // 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

    /**
     * @dev Owner will be set to the Gravity Bridge, which relays instructions from the Steward
     *      module to the cellars.
     *      https://github.com/PeggyJV/steward
     *      https://github.com/cosmos/gravity-bridge/blob/main/solidity/contracts/Gravity.sol
     * @param _asset current asset managed by the cellar
     * @param _approvedPositions list of approved positions to start with
     * @param _curveRegistryExchange Curve registry exchange
     * @param _sushiswapRouter Sushiswap V2 router address
     * @param _lendingPool Aave V2 lending pool address
     * @param _incentivesController _incentivesController
     * @param _gravityBridge Cosmos Gravity Bridge address
     * @param _stkAAVE stkAAVE address
     * @param _AAVE AAVE address
     * @param _WETH WETH address
     */
    constructor(
        ERC20 _asset,
        ERC20[] memory _approvedPositions,
        ICurveSwaps _curveRegistryExchange,
        ISushiSwapRouter _sushiswapRouter,
        ILendingPool _lendingPool,
        IAaveIncentivesController _incentivesController,
        IGravity _gravityBridge,
        IStakedTokenV2 _stkAAVE,
        ERC20 _AAVE,
        ERC20 _WETH
    ) ERC4626(_asset, "Sommelier Aave V2 Stablecoin Cellar LP Token", "aave2-CLR-S", 18) {
        // Initialize immutables.
        curveRegistryExchange = _curveRegistryExchange;
        sushiswapRouter = _sushiswapRouter;
        lendingPool = _lendingPool;
        incentivesController = _incentivesController;
        gravityBridge = _gravityBridge;
        stkAAVE = _stkAAVE;
        AAVE = _AAVE;
        WETH = _WETH;

        // Initialize asset.
        isTrusted[_asset] = true;
        uint8 _assetDecimals = _updatePosition(_asset);

        // Initialize limits.
        uint256 powOfAssetDecimals = 10**_assetDecimals;
        liquidityLimit = 5_000_000 * powOfAssetDecimals;
        depositLimit = type(uint256).max;

        // Initialize approved positions.
        for (uint256 i; i < _approvedPositions.length; i++) isTrusted[_approvedPositions[i]] = true;

        // Initialize starting timestamp for first accrual.
        lastAccrual = uint32(block.timestamp);

        // Transfer ownership to the Gravity Bridge.
        transferOwnership(address(_gravityBridge));
    }

    // ============================================ CORE LOGIC ============================================

    function deposit(uint256 assets, address receiver) public override returns (uint256 shares) {
        // Check that the deposit is not restricted by a deposit limit or liquidity limit and
        // prevent deposits during a shutdown.
        uint256 maxAssets = maxDeposit(receiver);
        if (assets > maxAssets) revert USR_DepositRestricted(assets, maxAssets);

        // Check for rounding error since we round down in previewDeposit.
        require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES");

        ERC20 cellarAsset = asset;
        uint256 assetsBeforeDeposit = cellarAsset.balanceOf(address(this));

        // Need to transfer before minting or ERC777s could reenter.
        asset.safeTransferFrom(msg.sender, address(this), assets);

        // Check that the balance transferred is what was expected.
        uint256 assetsReceived = cellarAsset.balanceOf(address(this)) - assetsBeforeDeposit;
        if (assetsReceived != assets) revert STATE_AssetUsesFeeOnTransfer(address(cellarAsset));

        _mint(receiver, shares);

        emit Deposit(msg.sender, receiver, assets, shares);
    }

    function mint(uint256 shares, address receiver) public override returns (uint256 assets) {
        assets = previewMint(shares); // No need to check for rounding error, previewMint rounds up.

        // Check that the deposit is not restricted by a deposit limit or liquidity limit and
        // prevent deposits during a shutdown.
        uint256 maxAssets = maxDeposit(receiver);
        if (assets > maxAssets) revert USR_DepositRestricted(assets, maxAssets);

        ERC20 cellarAsset = asset;
        uint256 assetsBeforeDeposit = cellarAsset.balanceOf(address(this));

        // Need to transfer before minting or ERC777s could reenter.
        asset.safeTransferFrom(msg.sender, address(this), assets);

        // Check that the balance transferred is what was expected.
        uint256 assetsReceived = cellarAsset.balanceOf(address(this)) - assetsBeforeDeposit;
        if (assetsReceived != assets) revert STATE_AssetUsesFeeOnTransfer(address(cellarAsset));

        _mint(receiver, shares);

        emit Deposit(msg.sender, receiver, assets, shares);
    }

    /**
     * @dev Check if holding position has enough funds to cover the withdraw and only pull from the
     *      current lending position if needed.
     * @param assets amount of assets to withdraw
     */
    function beforeWithdraw(
        uint256 assets,
        uint256,
        address,
        address
    ) internal override {
        ERC20 currentPosition = asset;
        uint256 holdings = totalHoldings();

        // Only withdraw if not enough assets in the holding pool.
        if (assets > holdings) {
            uint256 withdrawnAssets = _withdrawFromPosition(currentPosition, assets - holdings);

            totalBalance -= withdrawnAssets;
            highWatermarkBalance -= withdrawnAssets;
        }
    }

    // ======================================= ACCOUNTING LOGIC =======================================

    /**
     * @notice The total amount of assets in the cellar.
     * @dev Excludes locked yield that hasn't been distributed.
     */
    function totalAssets() public view override returns (uint256) {
        return totalBalance + totalHoldings() - totalLocked();
    }

    /**
     * @notice The total amount of assets in holding position.
     */
    function totalHoldings() public view returns (uint256) {
        return asset.balanceOf(address(this));
    }

    /**
     * @notice The total amount of locked yield still being distributed.
     */
    function totalLocked() public view returns (uint256) {
        // Get the last accrual and accrual period.
        uint256 previousAccrual = lastAccrual;
        uint256 accrualInterval = accrualPeriod;

        // If the accrual period has passed, there is no locked yield.
        if (block.timestamp >= previousAccrual + accrualInterval) return 0;

        // Get the maximum amount we could return.
        uint256 maxLockedYield = maxLocked;

        // Get how much yield remains locked.
        return maxLockedYield - (maxLockedYield * (block.timestamp - previousAccrual)) / accrualInterval;
    }

    /**
     * @notice The amount of assets that the cellar would exchange for the amount of shares provided.
     * @param shares amount of shares to convert
     * @return assets the shares can be exchanged for
     */
    function convertToAssets(uint256 shares) public view override returns (uint256 assets) {
        uint256 totalShares = totalSupply;

        assets = totalShares == 0
            ? shares.changeDecimals(18, assetDecimals)
            : shares.mulDivDown(totalAssets(), totalShares);
    }

    /**
     * @notice The amount of shares that the cellar would exchange for the amount of assets provided.
     * @param assets amount of assets to convert
     * @return shares the assets can be exchanged for
     */
    function convertToShares(uint256 assets) public view override returns (uint256 shares) {
        uint256 totalShares = totalSupply;

        shares = totalShares == 0
            ? assets.changeDecimals(assetDecimals, 18)
            : assets.mulDivDown(totalShares, totalAssets());
    }

    /**
     * @notice Simulate the effects of minting shares at the current block, given current on-chain conditions.
     * @param shares amount of shares to mint
     * @return assets that will be deposited
     */
    function previewMint(uint256 shares) public view override returns (uint256 assets) {
        uint256 totalShares = totalSupply;

        assets = totalShares == 0
            ? shares.changeDecimals(18, assetDecimals)
            : shares.mulDivUp(totalAssets(), totalShares);
    }

    /**
     * @notice Simulate the effects of withdrawing assets at the current block, given current on-chain conditions.
     * @param assets amount of assets to withdraw
     * @return shares that will be redeemed
     */
    function previewWithdraw(uint256 assets) public view override returns (uint256 shares) {
        uint256 totalShares = totalSupply;

        shares = totalShares == 0
            ? assets.changeDecimals(assetDecimals, 18)
            : assets.mulDivUp(totalShares, totalAssets());
    }

    // ========================================= LIMITS LOGIC =========================================

    /**
     * @notice Total amount of assets that can be deposited for a user.
     * @param receiver address of account that would receive the shares
     * @return assets maximum amount of assets that can be deposited
     */
    function maxDeposit(address receiver) public view override returns (uint256 assets) {
        if (isShutdown) return 0;

        uint256 asssetDepositLimit = depositLimit;
        uint256 asssetLiquidityLimit = liquidityLimit;
        if (asssetDepositLimit == type(uint256).max && asssetLiquidityLimit == type(uint256).max)
            return type(uint256).max;

        (uint256 leftUntilDepositLimit, uint256 leftUntilLiquidityLimit) = _getAssetsLeftUntilLimits(
            asssetDepositLimit,
            asssetLiquidityLimit,
            receiver
        );

        // Only return the more relevant of the two.
        assets = Math.min(leftUntilDepositLimit, leftUntilLiquidityLimit);
    }

    /**
     * @notice Total amount of shares that can be minted for a user.
     * @param receiver address of account that would receive the shares
     * @return shares maximum amount of shares that can be minted
     */
    function maxMint(address receiver) public view override returns (uint256 shares) {
        if (isShutdown) return 0;

        uint256 asssetDepositLimit = depositLimit;
        uint256 asssetLiquidityLimit = liquidityLimit;
        if (asssetDepositLimit == type(uint256).max && asssetLiquidityLimit == type(uint256).max)
            return type(uint256).max;

        (uint256 leftUntilDepositLimit, uint256 leftUntilLiquidityLimit) = _getAssetsLeftUntilLimits(
            asssetDepositLimit,
            asssetLiquidityLimit,
            receiver
        );

        // Only return the more relevant of the two.
        shares = convertToShares(Math.min(leftUntilDepositLimit, leftUntilLiquidityLimit));
    }

    function _getAssetsLeftUntilLimits(
        uint256 asssetDepositLimit,
        uint256 asssetLiquidityLimit,
        address receiver
    ) internal view returns (uint256 leftUntilDepositLimit, uint256 leftUntilLiquidityLimit) {
        uint256 totalAssetsIncludingUnrealizedGains = assetAToken.balanceOf(address(this)) + totalHoldings();

        // Convert receiver's shares to assets using total assets including locked yield.
        uint256 receiverShares = balanceOf[receiver];
        uint256 totalShares = totalSupply;
        uint256 maxWithdrawableByReceiver = totalShares == 0
            ? receiverShares
            : receiverShares.mulDivDown(totalAssetsIncludingUnrealizedGains, totalShares);

        // Get the maximum amount of assets that can be deposited until limits are reached.
        leftUntilDepositLimit = asssetDepositLimit.subMinZero(maxWithdrawableByReceiver);
        leftUntilLiquidityLimit = asssetLiquidityLimit.subMinZero(totalAssetsIncludingUnrealizedGains);
    }

    // ========================================== ACCRUAL LOGIC ==========================================

    /**
     * @notice Accrue yield, platform fees, and performance fees.
     * @dev Since this is the function responsible for distributing yield to shareholders and
     *      updating the cellar's balance, it is important to make sure it gets called regularly.
     */
    function accrue() public {
        uint256 totalLockedYield = totalLocked();

        // Without this check, malicious actors could do a slowdown attack on the distribution of
        // yield by continuously resetting the accrual period.
        if (msg.sender != owner() && totalLockedYield > 0) revert STATE_AccrualOngoing();

        // Compute and store current exchange rate between assets and shares for gas efficiency.
        uint256 oneAsset = 10**assetDecimals;
        uint256 exchangeRate = convertToShares(oneAsset);

        // Get balance since last accrual and updated balance for this accrual.
        uint256 balanceThisAccrual = assetAToken.balanceOf(address(this));

        // Calculate platform fees accrued.
        uint256 elapsedTime = block.timestamp - lastAccrual;
        uint256 platformFeeInAssets = (balanceThisAccrual * elapsedTime * platformFee) / 1e18 / 365 days;
        uint256 platformFees = platformFeeInAssets.mulDivDown(exchangeRate, oneAsset); // Convert to shares.

        // Calculate performance fees accrued.
        uint256 yield = balanceThisAccrual.subMinZero(highWatermarkBalance);
        uint256 performanceFeeInAssets = yield.mulWadDown(performanceFee);
        uint256 performanceFees = performanceFeeInAssets.mulDivDown(exchangeRate, oneAsset); // Convert to shares.

        // Mint accrued fees as shares.
        _mint(address(this), platformFees + performanceFees);

        // Do not count assets set aside for fees as yield. Allows fees to be immediately withdrawable.
        maxLocked = uint160(totalLockedYield + yield.subMinZero(platformFeeInAssets + performanceFeeInAssets));

        lastAccrual = uint32(block.timestamp);

        totalBalance = balanceThisAccrual;

        // Only update high watermark if balance greater than last high watermark.
        if (balanceThisAccrual > highWatermarkBalance) highWatermarkBalance = balanceThisAccrual;

        emit Accrual(platformFees, performanceFees, yield);
    }

    // ========================================= POSITION LOGIC =========================================

    /**
     * @notice Pushes assets into the current Aave lending position.
     * @param assets amount of assets to enter into the current position
     */
    function enterPosition(uint256 assets) public whenNotShutdown onlyOwner {
        ERC20 currentPosition = asset;

        totalBalance += assets;

        // Without this line, assets entered into Aave would be counted as gains during the next
        // accrual.
        highWatermarkBalance += assets;

        _depositIntoPosition(currentPosition, assets);

        emit EnterPosition(address(currentPosition), assets);
    }

    /**
     * @notice Pushes all assets in holding into the current Aave lending position.
     */
    function enterPosition() external {
        enterPosition(totalHoldings());
    }

    /**
     * @notice Pulls assets from the current Aave lending position.
     * @param assets amount of assets to exit from the current position
     */
    function exitPosition(uint256 assets) public whenNotShutdown onlyOwner {
        ERC20 currentPosition = asset;

        uint256 withdrawnAssets = _withdrawFromPosition(currentPosition, assets);

        totalBalance -= withdrawnAssets;

        // Without this line, assets exited from Aave would be counted as losses during the next
        // accrual.
        highWatermarkBalance -= withdrawnAssets;

        emit ExitPosition(address(currentPosition), assets);
    }

    /**
     * @notice Pulls all assets from the current Aave lending position.
     * @dev Strategy providers should not assume the position is empty after this call. If there is
     *      unrealized yield, that will still remain in the position. To completely empty the cellar,
     *      multicall accrue and this.
     */
    function exitPosition() external {
        exitPosition(totalBalance);
    }

    /**
     * @notice Rebalances current assets into a new position.
     * @param route array of [initial token, pool, token, pool, token, ...] that specifies the swap route on Curve.
     * @param swapParams multidimensional array of [i, j, swap type] where i and j are the correct
                         values for the n'th pool in `_route` and swap type should be 1 for a
                         stableswap `exchange`, 2 for stableswap `exchange_underlying`, 3 for a
                         cryptoswap `exchange`, 4 for a cryptoswap `exchange_underlying` and 5 for
                         Polygon factory metapools `exchange_underlying`
     * @param minAssetsOut minimum amount of assets received after swap
     */
    function rebalance(
        address[9] memory route,
        uint256[3][4] memory swapParams,
        uint256 minAssetsOut
    ) external whenNotShutdown onlyOwner {
        // Retrieve the last token in the route and store it as the new asset position.
        ERC20 newPosition;
        for (uint256 i; ; i += 2) {
            if (i == 8 || route[i + 1] == address(0)) {
                newPosition = ERC20(route[i]);
                break;
            }
        }

        // Ensure the asset position is trusted.
        if (!isTrusted[newPosition]) revert USR_UntrustedPosition(address(newPosition));

        ERC20 oldPosition = asset;

        // Doesn't make sense to rebalance into the same position.
        if (newPosition == oldPosition) revert USR_SamePosition(address(oldPosition));

        // Store this for later when updating total balance.
        uint256 totalAssetsInHolding = totalHoldings();
        uint256 totalBalanceIncludingHoldings = totalBalance + totalAssetsInHolding;

        // Pull any assets in the lending position back in to swap everything into the new position.
        uint256 assetsBeforeSwap = assetAToken.balanceOf(address(this)) > 0
            ? _withdrawFromPosition(oldPosition, type(uint256).max) + totalAssetsInHolding
            : totalAssetsInHolding;

        // Perform stablecoin swap using Curve.
        oldPosition.safeApprove(address(curveRegistryExchange), assetsBeforeSwap);
        uint256 assetsAfterSwap = curveRegistryExchange.exchange_multiple(
            route,
            swapParams,
            assetsBeforeSwap,
            minAssetsOut
        );

        uint8 oldPositionDecimals = assetDecimals;

        // Updates state for new position and check that Aave supports it.
        uint8 newPositionDecimals = _updatePosition(newPosition);

        // Deposit all newly swapped assets into Aave.
        _depositIntoPosition(newPosition, assetsAfterSwap);

        // Update maximum locked yield to scale accordingly to the decimals of the new asset.
        maxLocked = uint160(uint256(maxLocked).changeDecimals(oldPositionDecimals, newPositionDecimals));

        // Update the cellar's balance. If the unrealized gains before rebalancing exceed the losses
        // from the swap, then losses will be taken from the unrealized gains during next accrual
        // and this rebalance will not effect the exchange rate of shares to assets. Otherwise, the
        // losses from this rebalance will be realized and factored into the new balance.
        uint256 newTotalBalance = Math.min(
            totalBalanceIncludingHoldings.changeDecimals(oldPositionDecimals, newPositionDecimals),
            assetsAfterSwap
        );

        totalBalance = newTotalBalance;

        // Keep high watermark at level it should be at before rebalance because otherwise swap
        // losses from this rebalance would not be counted in the next accrual. Include holdings
        // into new high watermark balance as those have all been deposited into Aave now.
        highWatermarkBalance = (highWatermarkBalance + totalAssetsInHolding).changeDecimals(
            oldPositionDecimals,
            newPositionDecimals
        );

        emit Rebalance(address(oldPosition), address(newPosition), newTotalBalance);
    }

    // ======================================= REINVEST LOGIC =======================================

    /**
     * @notice Claim rewards from Aave and begin cooldown period to unstake them.
     * @return rewards amount of stkAAVE rewards claimed from Aave
     */
    function claimAndUnstake() external onlyOwner returns (uint256 rewards) {
        // Necessary to do as `claimRewards` accepts a dynamic array as first param.
        address[] memory aToken = new address[](1);
        aToken[0] = address(assetAToken);

        // Claim all stkAAVE rewards.
        rewards = incentivesController.claimRewards(aToken, type(uint256).max, address(this));

        // Begin the 10 day cooldown period for unstaking stkAAVE for AAVE.
        stkAAVE.cooldown();

        emit ClaimAndUnstake(rewards);
    }

    /**
     * @notice Reinvest rewards back into cellar's current position.
     * @dev Must be called within 2 day unstake period 10 days after `claimAndUnstake` was run.
     * @param minAssetsOut minimum amount of assets to receive after swapping AAVE to the current asset
     */
    function reinvest(uint256 minAssetsOut) external onlyOwner {
        // Redeems the cellar's stkAAVE rewards for AAVE.
        stkAAVE.redeem(address(this), type(uint256).max);

        // Get the amount of AAVE rewards going in to be swap for the current asset.
        uint256 rewardsIn = AAVE.balanceOf(address(this));

        ERC20 currentAsset = asset;

        // Specify the swap path from AAVE -> WETH -> current asset.
        address[] memory path = new address[](3);
        path[0] = address(AAVE);
        path[1] = address(WETH);
        path[2] = address(currentAsset);

        // Perform a multihop swap using Sushiswap.
        AAVE.safeApprove(address(sushiswapRouter), rewardsIn);
        uint256[] memory amounts = sushiswapRouter.swapExactTokensForTokens(
            rewardsIn,
            minAssetsOut,
            path,
            address(this),
            block.timestamp + 60
        );

        uint256 assetsOut = amounts[amounts.length - 1];

        // In the case of a shutdown, we just may want to redeem any leftover rewards for users to
        // claim but without entering them back into a position in case the position has been
        // exited. Also, for the purposes of performance fee calculation, we count reinvested
        // rewards as yield so do not update balance.
        if (!isShutdown) _depositIntoPosition(currentAsset, assetsOut);

        emit Reinvest(address(currentAsset), rewardsIn, assetsOut);
    }

    // ========================================= FEES LOGIC =========================================

    /**
     * @notice Transfer accrued fees to the Sommelier chain to distribute.
     * @dev Fees are accrued as shares and redeemed upon transfer.
     */
    function sendFees() external onlyOwner {
        // Redeem our fee shares for assets to send to the fee distributor module.
        uint256 totalFees = balanceOf[address(this)];
        uint256 assets = previewRedeem(totalFees);
        require(assets != 0, "ZERO_ASSETS");

        // Only withdraw assets from position if the holding position does not contain enough funds.
        // Pass in only the amount of assets withdrawn, the rest doesn't matter.
        beforeWithdraw(assets, 0, address(0), address(0));

        _burn(address(this), totalFees);

        // Transfer assets to a fee distributor on the Sommelier chain.
        ERC20 positionAsset = asset;
        positionAsset.safeApprove(address(gravityBridge), assets);
        gravityBridge.sendToCosmos(address(positionAsset), feesDistributor, assets);

        emit SendFees(totalFees, assets);
    }

    // ====================================== RECOVERY LOGIC ======================================

    /**
     * @notice Sweep tokens that are not suppose to be in the cellar.
     * @dev This may be used in case the wrong tokens are accidentally sent.
     * @param token address of token to transfer out of this cellar
     * @param to address to transfer sweeped tokens to
     */
    function sweep(ERC20 token, address to) external onlyOwner {
        // Prevent sweeping of assets managed by the cellar and shares minted to the cellar as fees.
        if (token == asset || token == assetAToken || token == this || address(token) == address(stkAAVE))
            revert USR_ProtectedAsset(address(token));

        // Transfer out tokens in this cellar that shouldn't be here.
        uint256 amount = token.balanceOf(address(this));
        token.safeTransfer(to, amount);

        emit Sweep(address(token), to, amount);
    }

    // ===================================== HELPER FUNCTIONS =====================================

    /**
     * @notice Deposits cellar holdings into an Aave lending position.
     * @param position the address of the asset position
     * @param assets the amount of assets to deposit
     */
    function _depositIntoPosition(ERC20 position, uint256 assets) internal {
        // Deposit assets into Aave position.
        position.safeApprove(address(lendingPool), assets);
        lendingPool.deposit(address(position), assets, address(this), 0);

        emit DepositIntoPosition(address(position), assets);
    }

    /**
     * @notice Withdraws assets from an Aave lending position.
     * @dev The assets withdrawn differs from the assets specified if withdrawing `type(uint256).max`.
     * @param position the address of the asset position
     * @param assets amount of assets to withdraw
     * @return withdrawnAssets amount of assets actually withdrawn
     */
    function _withdrawFromPosition(ERC20 position, uint256 assets) internal returns (uint256 withdrawnAssets) {
        // Withdraw assets from Aave position.
        withdrawnAssets = lendingPool.withdraw(address(position), assets, address(this));

        emit WithdrawFromPosition(address(position), withdrawnAssets);
    }

    /**
     * @notice Pull all assets from the current lending position on Aave back into holding.
     * @param position the address of the asset position to pull from
     */
    function _emptyPosition(ERC20 position) internal {
        uint256 totalPositionBalance = totalBalance;

        if (totalPositionBalance > 0) {
            accrue();

            _withdrawFromPosition(position, type(uint256).max);

            delete totalBalance;
            delete highWatermarkBalance;
        }
    }

    /**
     * @notice Update state variables related to the current position.
     * @dev Be aware that when updating to an asset that uses less decimals than the previous
     *      asset (eg. DAI -> USDC), `depositLimit` and `liquidityLimit` will lose some precision
     *      due to truncation.
     * @param newPosition address of the new asset being managed by the cellar
     */
    function _updatePosition(ERC20 newPosition) internal returns (uint8 newAssetDecimals) {
        // Retrieve the aToken that will represent the cellar's new position on Aave.
        (, , , , , , , address aTokenAddress, , , , ) = lendingPool.getReserveData(address(newPosition));

        // If the address is not null, it is supported by Aave.
        if (aTokenAddress == address(0)) revert USR_UnsupportedPosition(address(newPosition));

        // Update the decimals used by limits if necessary.
        uint8 oldAssetDecimals = assetDecimals;
        newAssetDecimals = newPosition.decimals();

        // Ensure the decimals of precision of the new position uses will not break the cellar.
        if (newAssetDecimals > 18) revert USR_TooManyDecimals(newAssetDecimals, 18);

        // Ignore if decimals are the same or if it is the first time initializing a position.
        if (oldAssetDecimals != 0 && oldAssetDecimals != newAssetDecimals) {
            uint256 asssetDepositLimit = depositLimit;
            uint256 asssetLiquidityLimit = liquidityLimit;
            if (asssetDepositLimit != type(uint256).max)
                depositLimit = asssetDepositLimit.changeDecimals(oldAssetDecimals, newAssetDecimals);

            if (asssetLiquidityLimit != type(uint256).max)
                liquidityLimit = asssetLiquidityLimit.changeDecimals(oldAssetDecimals, newAssetDecimals);
        }

        // Update state related to the current position.
        asset = newPosition;
        assetDecimals = newAssetDecimals;
        assetAToken = ERC20(aTokenAddress);
    }
}

File 2 of 35 : ERC4626.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

import { ERC20 } from "lib/solmate/src/tokens/ERC20.sol";
import { SafeTransferLib } from "lib/solmate/src/utils/SafeTransferLib.sol";
import { Math } from "../utils/Math.sol";

/// @notice Minimal ERC4626 tokenized Vault implementation.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/mixins/ERC4626.sol)
abstract contract ERC4626 is ERC20 {
    using SafeTransferLib for ERC20;
    using Math for uint256;

    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares);

    event Withdraw(
        address indexed caller,
        address indexed receiver,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );

    /*//////////////////////////////////////////////////////////////
                               IMMUTABLES
    //////////////////////////////////////////////////////////////*/

    ERC20 public asset;

    constructor(
        ERC20 _asset,
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) ERC20(_name, _symbol, _decimals) {
        asset = _asset;
    }

    /*//////////////////////////////////////////////////////////////
                        DEPOSIT/WITHDRAWAL LOGIC
    //////////////////////////////////////////////////////////////*/

    function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares) {
        // Check for rounding error since we round down in previewDeposit.
        require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES");

        beforeDeposit(assets, shares, receiver);

        // Need to transfer before minting or ERC777s could reenter.
        asset.safeTransferFrom(msg.sender, address(this), assets);

        _mint(receiver, shares);

        emit Deposit(msg.sender, receiver, assets, shares);

        afterDeposit(assets, shares, receiver);
    }

    function mint(uint256 shares, address receiver) public virtual returns (uint256 assets) {
        assets = previewMint(shares); // No need to check for rounding error, previewMint rounds up.

        beforeDeposit(assets, shares, receiver);

        // Need to transfer before minting or ERC777s could reenter.
        asset.safeTransferFrom(msg.sender, address(this), assets);

        _mint(receiver, shares);

        emit Deposit(msg.sender, receiver, assets, shares);

        afterDeposit(assets, shares, receiver);
    }

    function withdraw(
        uint256 assets,
        address receiver,
        address owner
    ) public virtual returns (uint256 shares) {
        shares = previewWithdraw(assets); // No need to check for rounding error, previewWithdraw rounds up.

        if (msg.sender != owner) {
            uint256 allowed = allowance[owner][msg.sender]; // Saves gas for limited approvals.

            if (allowed != type(uint256).max) allowance[owner][msg.sender] = allowed - shares;
        }

        beforeWithdraw(assets, shares, receiver, owner);

        _burn(owner, shares);

        emit Withdraw(msg.sender, receiver, owner, assets, shares);

        asset.safeTransfer(receiver, assets);

        afterWithdraw(assets, shares, receiver, owner);
    }

    function redeem(
        uint256 shares,
        address receiver,
        address owner
    ) public virtual returns (uint256 assets) {
        if (msg.sender != owner) {
            uint256 allowed = allowance[owner][msg.sender]; // Saves gas for limited approvals.

            if (allowed != type(uint256).max) allowance[owner][msg.sender] = allowed - shares;
        }

        // Check for rounding error since we round down in previewRedeem.
        require((assets = previewRedeem(shares)) != 0, "ZERO_ASSETS");

        beforeWithdraw(assets, shares, receiver, owner);

        _burn(owner, shares);

        emit Withdraw(msg.sender, receiver, owner, assets, shares);

        asset.safeTransfer(receiver, assets);

        afterWithdraw(assets, shares, receiver, owner);
    }

    /*//////////////////////////////////////////////////////////////
                            ACCOUNTING LOGIC
    //////////////////////////////////////////////////////////////*/

    function totalAssets() public view virtual returns (uint256);

    function convertToShares(uint256 assets) public view virtual returns (uint256) {
        uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero.

        return supply == 0 ? assets : assets.mulDivDown(supply, totalAssets());
    }

    function convertToAssets(uint256 shares) public view virtual returns (uint256) {
        uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero.

        return supply == 0 ? shares : shares.mulDivDown(totalAssets(), supply);
    }

    function previewDeposit(uint256 assets) public view virtual returns (uint256) {
        return convertToShares(assets);
    }

    function previewMint(uint256 shares) public view virtual returns (uint256) {
        uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero.

        return supply == 0 ? shares : shares.mulDivUp(totalAssets(), supply);
    }

    function previewWithdraw(uint256 assets) public view virtual returns (uint256) {
        uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero.

        return supply == 0 ? assets : assets.mulDivUp(supply, totalAssets());
    }

    function previewRedeem(uint256 shares) public view virtual returns (uint256) {
        return convertToAssets(shares);
    }

    /*//////////////////////////////////////////////////////////////
                     DEPOSIT/WITHDRAWAL LIMIT LOGIC
    //////////////////////////////////////////////////////////////*/

    function maxDeposit(address) public view virtual returns (uint256) {
        return type(uint256).max;
    }

    function maxMint(address) public view virtual returns (uint256) {
        return type(uint256).max;
    }

    function maxWithdraw(address owner) public view virtual returns (uint256) {
        return convertToAssets(balanceOf[owner]);
    }

    function maxRedeem(address owner) public view virtual returns (uint256) {
        return balanceOf[owner];
    }

    /*//////////////////////////////////////////////////////////////
                          INTERNAL HOOKS LOGIC
    //////////////////////////////////////////////////////////////*/

    function beforeDeposit(
        uint256 assets,
        uint256 shares,
        address receiver
    ) internal virtual {}

    function afterDeposit(
        uint256 assets,
        uint256 shares,
        address receiver
    ) internal virtual {}

    function beforeWithdraw(
        uint256 assets,
        uint256 shares,
        address receiver,
        address owner
    ) internal virtual {}

    function afterWithdraw(
        uint256 assets,
        uint256 shares,
        address receiver,
        address owner
    ) internal virtual {}
}

File 3 of 35 : Multicall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;

import { IMulticall } from "../interfaces/IMulticall.sol";

/**
 * @title Multicall
 * @notice Enables calling multiple methods in a single call to the contract
 * From: https://github.com/Uniswap/v3-periphery/contracts/base/Multicall.sol
 */
abstract contract Multicall is IMulticall {
    /// @inheritdoc IMulticall
    function multicall(bytes[] calldata data) public payable override returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            (bool success, bytes memory result) = address(this).delegatecall(data[i]);

            if (!success) {
                // Next 5 lines from https://ethereum.stackexchange.com/a/83577
                // solhint-disable-next-line reason-string
                if (result.length < 68) revert();
                assembly {
                    result := add(result, 0x04)
                }
                revert(abi.decode(result, (string)));
            }

            results[i] = result;
        }
    }
}

File 4 of 35 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

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

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

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

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 5 of 35 : IAaveV2StablecoinCellar.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC20 } from "lib/solmate/src/tokens/ERC20.sol";
import { IAaveIncentivesController } from "../interfaces/IAaveIncentivesController.sol";
import { IStakedTokenV2 } from "../interfaces/IStakedTokenV2.sol";
import { ICurveSwaps } from "../interfaces/ICurveSwaps.sol";
import { ISushiSwapRouter } from "../interfaces/ISushiSwapRouter.sol";
import { ILendingPool } from "../interfaces/ILendingPool.sol";
import { IGravity } from "../interfaces/IGravity.sol";

/**
 * @title Interface for AaveV2StablecoinCellar
 */
interface IAaveV2StablecoinCellar {
    // ======================================== POSITION STORAGE ========================================

    function assetAToken() external view returns (ERC20);

    function assetDecimals() external view returns (uint8);

    function totalBalance() external view returns (uint256);

    // ========================================= ACCRUAL CONFIG =========================================

    /**
     * @notice Emitted when accrual period is changed.
     * @param oldPeriod time the period was changed from
     * @param newPeriod time the period was changed to
     */
    event AccrualPeriodChanged(uint32 oldPeriod, uint32 newPeriod);

    function accrualPeriod() external view returns (uint32);

    function lastAccrual() external view returns (uint64);

    function maxLocked() external view returns (uint160);

    function setAccrualPeriod(uint32 newAccrualPeriod) external;

    // =========================================== FEES CONFIG ===========================================

    /**
     * @notice Emitted when platform fees is changed.
     * @param oldPlatformFee value platform fee was changed from
     * @param newPlatformFee value platform fee was changed to
     */
    event PlatformFeeChanged(uint64 oldPlatformFee, uint64 newPlatformFee);

    /**
     * @notice Emitted when performance fees is changed.
     * @param oldPerformanceFee value performance fee was changed from
     * @param newPerformanceFee value performance fee was changed to
     */
    event PerformanceFeeChanged(uint64 oldPerformanceFee, uint64 newPerformanceFee);

    /**
     * @notice Emitted when fees distributor is changed.
     * @param oldFeesDistributor address of fee distributor was changed from
     * @param newFeesDistributor address of fee distributor was changed to
     */
    event FeesDistributorChanged(bytes32 oldFeesDistributor, bytes32 newFeesDistributor);

    function platformFee() external view returns (uint64);

    function performanceFee() external view returns (uint64);

    function feesDistributor() external view returns (bytes32);

    function setFeesDistributor(bytes32 newFeesDistributor) external;

    // ======================================== TRUST CONFIG ========================================

    /**
     * @notice Emitted when trust for a position is changed.
     * @param position address of the position that trust was changed for
     * @param trusted whether the position was trusted or untrusted
     */
    event TrustChanged(address indexed position, bool trusted);

    function isTrusted(ERC20) external view returns (bool);

    function setTrust(ERC20 position, bool trust) external;

    // ======================================== LIMITS CONFIG ========================================

    /**
     * @notice Emitted when the liquidity limit is changed.
     * @param oldLimit amount the limit was changed from
     * @param newLimit amount the limit was changed to
     */
    event LiquidityLimitChanged(uint256 oldLimit, uint256 newLimit);

    /**
     * @notice Emitted when the deposit limit is changed.
     * @param oldLimit amount the limit was changed from
     * @param newLimit amount the limit was changed to
     */
    event DepositLimitChanged(uint256 oldLimit, uint256 newLimit);

    function liquidityLimit() external view returns (uint256);

    function depositLimit() external view returns (uint256);

    function setLiquidityLimit(uint256 newLimit) external;

    function setDepositLimit(uint256 newLimit) external;

    // ======================================== EMERGENCY LOGIC ========================================

    /**
     * @notice Emitted when cellar is shutdown.
     * @param emptyPositions whether the current position(s) was exited
     */
    event ShutdownInitiated(bool emptyPositions);

    /**
     * @notice Emitted when shutdown is lifted.
     */
    event ShutdownLifted();

    function isShutdown() external view returns (bool);

    function initiateShutdown(bool emptyPosition) external;

    function liftShutdown() external;

    // ========================================== IMMUTABLES ==========================================

    function curveRegistryExchange() external view returns (ICurveSwaps);

    function sushiswapRouter() external view returns (ISushiSwapRouter);

    function lendingPool() external view returns (ILendingPool);

    function incentivesController() external view returns (IAaveIncentivesController);

    function gravityBridge() external view returns (IGravity);

    function stkAAVE() external view returns (IStakedTokenV2);

    function AAVE() external view returns (ERC20);

    function WETH() external view returns (ERC20);

    // ======================================= ACCOUNTING LOGIC =======================================

    function totalHoldings() external view returns (uint256);

    function totalLocked() external view returns (uint256);

    // ======================================== ACCRUAL LOGIC ========================================

    /**
     * @notice Emitted on accruals.
     * @param platformFees amount of shares minted as platform fees this accrual
     * @param performanceFees amount of shares minted as performance fees this accrual
     * @param yield amount of assets accrued as yield that will be distributed over this accrual period
     */
    event Accrual(uint256 platformFees, uint256 performanceFees, uint256 yield);

    /**
     * @notice Accrue yield, platform fees, and performance fees.
     * @dev Since this is the function responsible for distributing yield to shareholders and
     *      updating the cellar's balance, it is important to make sure it gets called regularly.
     */
    function accrue() external;

    // ========================================= POSITION LOGIC =========================================
    /**
     * @notice Emitted on deposit to Aave.
     * @param position the address of the position
     * @param assets the amount of assets to deposit
     */
    event DepositIntoPosition(address indexed position, uint256 assets);

    /**
     * @notice Emitted on withdraw from Aave.
     * @param position the address of the position
     * @param assets the amount of assets to withdraw
     */
    event WithdrawFromPosition(address indexed position, uint256 assets);

    /**
     * @notice Emitted upon entering assets into the current position on Aave.
     * @param position the address of the asset being pushed into the current position
     * @param assets amount of assets being pushed
     */
    event EnterPosition(address indexed position, uint256 assets);

    /**
     * @notice Emitted upon exiting assets from the current position on Aave.
     * @param position the address of the asset being pulled from the current position
     * @param assets amount of assets being pulled
     */
    event ExitPosition(address indexed position, uint256 assets);

    /**
     * @notice Emitted on rebalance of Aave poisition.
     * @param oldAsset the address of the asset for the old position
     * @param newAsset the address of the asset for the new position
     * @param assets the amount of the new assets cellar has after rebalancing
     */
    event Rebalance(address indexed oldAsset, address indexed newAsset, uint256 assets);

    function enterPosition() external;

    function enterPosition(uint256 assets) external;

    function exitPosition() external;

    function exitPosition(uint256 assets) external;

    function rebalance(
        address[9] memory route,
        uint256[3][4] memory swapParams,
        uint256 minAssetsOut
    ) external;

    // ========================================= REINVEST LOGIC =========================================

    /**
     * @notice Emitted upon claiming rewards and beginning cooldown period to unstake them.
     * @param rewards amount of rewards that were claimed
     */
    event ClaimAndUnstake(uint256 rewards);

    /**
     * @notice Emitted upon reinvesting rewards into the current position.
     * @param token the address of the asset rewards were swapped to
     * @param rewards amount of rewards swapped to be reinvested
     * @param assets amount of assets received from swapping rewards
     */
    event Reinvest(address indexed token, uint256 rewards, uint256 assets);

    function claimAndUnstake() external returns (uint256 rewards);

    function reinvest(uint256 minAssetsOut) external;

    // =========================================== FEES LOGIC ===========================================

    /**
     * @notice Emitted when platform fees are send to the Sommelier chain.
     * @param feesInSharesRedeemed amount of fees redeemed for assets to send
     * @param feesInAssetsSent amount of assets fees were redeemed for that were sent
     */
    event SendFees(uint256 feesInSharesRedeemed, uint256 feesInAssetsSent);

    function sendFees() external;

    // ========================================= RECOVERY LOGIC =========================================

    /**
     * @notice Emitted when tokens accidentally sent to cellar are recovered.
     * @param token the address of the token
     * @param to the address sweeped tokens were transferred to
     * @param amount amount transferred out
     */
    event Sweep(address indexed token, address indexed to, uint256 amount);

    function sweep(ERC20 token, address to) external;
}

File 6 of 35 : IAaveIncentivesController.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

interface IAaveIncentivesController {
    event RewardsAccrued(address indexed user, uint256 amount);

    event RewardsClaimed(address indexed user, address indexed to, address indexed claimer, uint256 amount);

    event ClaimerSet(address indexed user, address indexed claimer);

    /*
     * @dev Returns the configuration of the distribution for a certain asset
     * @param asset The address of the reference asset of the distribution
     * @return The asset index, the emission per second and the last updated timestamp
     **/
    function getAssetData(address asset)
        external
        view
        returns (
            uint256,
            uint256,
            uint256
        );

    /*
     * LEGACY **************************
     * @dev Returns the configuration of the distribution for a certain asset
     * @param asset The address of the reference asset of the distribution
     * @return The asset index, the emission per second and the last updated timestamp
     **/
    function assets(address asset)
        external
        view
        returns (
            uint128,
            uint128,
            uint256
        );

    /**
     * @dev Whitelists an address to claim the rewards on behalf of another address
     * @param user The address of the user
     * @param claimer The address of the claimer
     */
    function setClaimer(address user, address claimer) external;

    /**
     * @dev Returns the whitelisted claimer for a certain address (0x0 if not set)
     * @param user The address of the user
     * @return The claimer address
     */
    function getClaimer(address user) external view returns (address);

    /**
     * @dev Configure assets for a certain rewards emission
     * @param assets The assets to incentivize
     * @param emissionsPerSecond The emission for each asset
     */
    function configureAssets(address[] calldata assets, uint256[] calldata emissionsPerSecond) external;

    /**
     * @dev Called by the corresponding asset on any update that affects the rewards distribution
     * @param asset The address of the user
     * @param userBalance The balance of the user of the asset in the lending pool
     * @param totalSupply The total supply of the asset in the lending pool
     **/
    function handleAction(
        address asset,
        uint256 userBalance,
        uint256 totalSupply
    ) external;

    /**
     * @dev Returns the total of rewards of an user, already accrued + not yet accrued
     * @param user The address of the user
     * @return The rewards
     **/
    function getRewardsBalance(address[] calldata assets, address user) external view returns (uint256);

    /**
     * @dev Claims reward for an user, on all the assets of the lending pool, accumulating the pending rewards
     * @param amount Amount of rewards to claim
     * @param to Address that will be receiving the rewards
     * @return Rewards claimed
     **/
    function claimRewards(
        address[] calldata assets,
        uint256 amount,
        address to
    ) external returns (uint256);

    /**
     * @dev Claims reward for an user on behalf, on all the assets of the lending pool, accumulating
     * the pending rewards. The caller must
     * be whitelisted via "allowClaimOnBehalf" function by the RewardsAdmin role manager
     * @param amount Amount of rewards to claim
     * @param user Address to check and claim rewards
     * @param to Address that will be receiving the rewards
     * @return Rewards claimed
     **/
    function claimRewardsOnBehalf(
        address[] calldata assets,
        uint256 amount,
        address user,
        address to
    ) external returns (uint256);

    /**
     * @dev returns the unclaimed rewards of the user
     * @param user the address of the user
     * @return the unclaimed user rewards
     */
    function getUserUnclaimedRewards(address user) external view returns (uint256);

    /**
     * @dev returns the unclaimed rewards of the user
     * @param user the address of the user
     * @param asset The asset to incentivize
     * @return the user index for the asset
     */
    function getUserAssetData(address user, address asset) external view returns (uint256);

    /**
     * @dev for backward compatibility with previous implementation of the Incentives controller
     */
    function REWARD_TOKEN() external view returns (address);

    /**
     * @dev for backward compatibility with previous implementation of the Incentives controller
     */
    function PRECISION() external view returns (uint8);

    /**
     * @dev Gets the distribution end timestamp of the emissions
     */
    function DISTRIBUTION_END() external view returns (uint256);
}

File 7 of 35 : IStakedTokenV2.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.15;

interface IStakedTokenV2 {
    function stake(address to, uint256 amount) external;

    function redeem(address to, uint256 amount) external;

    function cooldown() external;

    function claimRewards(address to, uint256 amount) external;

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

    function stakersCooldowns(address account) external view returns (uint256);
}

File 8 of 35 : ICurveSwaps.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

/**
 * @notice Partial interface for a Curve Registry Exchanges contract
 * @dev The registry exchange contract is used to find pools and query exchange rates for token swaps.
 *      It also provides a unified exchange API that can be useful for on-chain integrators.
 **/
interface ICurveSwaps {
    /**
     * @notice Perform up to four swaps in a single transaction
     * @dev Routing and swap params must be determined off-chain. This
     *      functionality is designed for gas efficiency over ease-of-use.
     * @param _route Array of [initial token, pool, token, pool, token, ...]
     *               The array is iterated until a pool address of 0x00, then the last
     *               given token is transferred to `_receiver` (address to transfer the final output token to)
     * @param _swap_params Multidimensional array of [i, j, swap type] where i and j are the correct
     *                     values for the n'th pool in `_route`. The swap type should be 1 for
     *                     a stableswap `exchange`, 2 for stableswap `exchange_underlying`, 3
     *                     for a cryptoswap `exchange`, 4 for a cryptoswap `exchange_underlying`
     *                     and 5 for Polygon factory metapools `exchange_underlying`
     * @param _expected The minimum amount received after the final swap.
     * @return Received amount of final output token
     **/
    function exchange_multiple(
        address[9] memory _route,
        uint256[3][4] memory _swap_params,
        uint256 _amount,
        uint256 _expected
    ) external returns (uint256);
}

File 9 of 35 : ISushiSwapRouter.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

/**
 * @notice Partial interface for a SushiSwap Router contract
 **/
interface ISushiSwapRouter {
    /**
     * @notice Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the `path`
     * @dev The first element of `path` is the input token, the last is the output token,
     *      and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
     *      `msg.sender` should have already given the router an allowance of at least `amountIn` on the input token
     * @param amountIn The amount of input tokens to send
     * @param amountOutMin The minimum amount of output tokens that must be received for the transaction not to revert
     * @param path An array of token addresses. `path.length` must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity
     * @param to Recipient of the output tokens
     * @param deadline Unix timestamp after which the transaction will revert
     * @return amounts The input token amount and all subsequent output token amounts
     **/
    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
}

File 10 of 35 : IGravity.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

interface IGravity {
    function sendToCosmos(
        address _tokenContract,
        bytes32 _destination,
        uint256 _amount
    ) external;
}

File 11 of 35 : ILendingPool.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

/**
 * @dev Partial interface for a Aave LendingPool contract,
 * which is the main point of interaction with an Aave protocol's market
 **/
interface ILendingPool {
    /**
     * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.
     * - E.g. User deposits 100 USDC and gets in return 100 aUSDC
     * @param asset The address of the underlying asset to deposit
     * @param amount The amount to be deposited
     * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user
     *   wants to receive them on his own wallet, or a different address if the beneficiary of aTokens
     *   is a different wallet
     * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
     *   0 if the action is executed directly by the user, without any middle-man
     **/
    function deposit(
        address asset,
        uint256 amount,
        address onBehalfOf,
        uint16 referralCode
    ) external;

    /**
     * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned
     * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC
     * @param asset The address of the underlying asset to withdraw
     * @param amount The underlying amount to be withdrawn
     *   - Send the value type(uint256).max in order to withdraw the whole aToken balance
     * @param to Address that will receive the underlying, same as msg.sender if the user
     *   wants to receive it on his own wallet, or a different address if the beneficiary is a
     *   different wallet
     * @return The final amount withdrawn
     **/
    function withdraw(
        address asset,
        uint256 amount,
        address to
    ) external returns (uint256);

    /**
     * @dev Returns the normalized income normalized income of the reserve
     * @param asset The address of the underlying asset of the reserve
     * @return The reserve's normalized income
     */
    function getReserveNormalizedIncome(address asset) external view returns (uint256);

    /**
     * @dev Returns the normalized income normalized income of the reserve
     * @param asset The address of the underlying asset of the reserve
     **/
    function getReserveData(address asset)
        external
        view
        returns (
            //stores the reserve configuration
            //bit 0-15: LTV
            //bit 16-31: Liq. threshold
            //bit 32-47: Liq. bonus
            //bit 48-55: Decimals
            //bit 56: Reserve is active
            //bit 57: reserve is frozen
            //bit 58: borrowing is enabled
            //bit 59: stable rate borrowing enabled
            //bit 60-63: reserved
            //bit 64-79: reserve factor
            uint256 configuration,
            //the liquidity index. Expressed in ray
            uint128 liquidityIndex,
            //variable borrow index. Expressed in ray
            uint128 variableBorrowIndex,
            //the current supply rate. Expressed in ray
            uint128 currentLiquidityRate,
            //the current variable borrow rate. Expressed in ray
            uint128 currentVariableBorrowRate,
            //the current stable borrow rate. Expressed in ray
            uint128 currentStableBorrowRate,
            uint40 lastUpdateTimestamp,
            //tokens addresses
            address aTokenAddress,
            address stableDebtTokenAddress,
            address variableDebtTokenAddress,
            //address of the interest rate strategy
            address interestRateStrategyAddress,
            //the id of the reserve. Represents the position in the list of the active reserves
            uint8 id
        );
}

File 12 of 35 : Math.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

library Math {
    /**
     * @notice Substract and return 0 instead if results are negative.
     */
    function subMinZero(uint256 x, uint256 y) internal pure returns (uint256) {
        return x > y ? x - y : 0;
    }

    /**
     * @notice Used to change the decimals of precision used for an amount.
     */
    function changeDecimals(
        uint256 amount,
        uint8 fromDecimals,
        uint8 toDecimals
    ) internal pure returns (uint256) {
        if (fromDecimals == toDecimals) {
            return amount;
        } else if (fromDecimals < toDecimals) {
            return amount * 10**(toDecimals - fromDecimals);
        } else {
            return amount / 10**(fromDecimals - toDecimals);
        }
    }

    // ===================================== OPENZEPPELIN'S MATH =====================================

    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    // ================================= SOLMATE's FIXEDPOINTMATHLIB =================================

    uint256 public constant WAD = 1e18; // The scalar of ETH and most ERC20s.

    function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
        return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down.
    }

    function mulDivDown(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 z) {
        assembly {
            // Store x * y in z for now.
            z := mul(x, y)

            // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
            if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) {
                revert(0, 0)
            }

            // Divide z by the denominator.
            z := div(z, denominator)
        }
    }

    function mulDivUp(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 z) {
        assembly {
            // Store x * y in z for now.
            z := mul(x, y)

            // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
            if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) {
                revert(0, 0)
            }

            // First, divide z - 1 by the denominator and add 1.
            // We allow z - 1 to underflow if z is 0, because we multiply the
            // end result by 0 if z is zero, ensuring we return 0 if z is zero.
            z := mul(iszero(iszero(z)), add(div(sub(z, 1), denominator), 1))
        }
    }
}

File 13 of 35 : Errors.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

// ========================================== USER ERRORS ===========================================

/**
 * @dev These errors represent invalid user input to functions. Where appropriate, the invalid value
 *      is specified along with constraints. These errors can be resolved by callers updating their
 *      arguments.
 */

/**
 * @notice Attempted an action with zero assets.
 */
error USR_ZeroAssets();

/**
 * @notice Attempted an action with zero shares.
 */
error USR_ZeroShares();

/**
 * @notice Attempted deposit more than the max deposit.
 * @param assets the assets user attempted to deposit
 * @param maxDeposit the max assets that can be deposited
 */
error USR_DepositRestricted(uint256 assets, uint256 maxDeposit);

/**
 * @notice Attempted to transfer more active shares than the user has.
 * @param activeShares amount of shares user has
 * @param attemptedActiveShares amount of shares user tried to transfer
 */
error USR_NotEnoughActiveShares(uint256 activeShares, uint256 attemptedActiveShares);

/**
 * @notice Attempted swap into an asset that is not the current asset of the position.
 * @param assetOut address of the asset attempted to swap to
 * @param currentAsset address of the current asset of position
 */
error USR_InvalidSwap(address assetOut, address currentAsset);

/**
 * @notice Attempted to sweep an asset that is managed by the cellar.
 * @param token address of the token that can't be sweeped
 */
error USR_ProtectedAsset(address token);

/**
 * @notice Attempted rebalance into the same position.
 * @param position address of the position
 */
error USR_SamePosition(address position);

/**
 * @notice Attempted to update the position to one that is not supported by the platform.
 * @param unsupportedPosition address of the unsupported position
 */
error USR_UnsupportedPosition(address unsupportedPosition);

/**
 * @notice Attempted an operation on an untrusted position.
 * @param position address of the position
 */
error USR_UntrustedPosition(address position);

/**
 * @notice Attempted to update a position to an asset that uses an incompatible amount of decimals.
 * @param newDecimals decimals of precision that the new position uses
 * @param maxDecimals maximum decimals of precision for a position to be compatible with the cellar
 */
error USR_TooManyDecimals(uint8 newDecimals, uint8 maxDecimals);

/**
 * @notice User attempted to stake zero amout.
 */
error USR_ZeroDeposit();

/**
 * @notice User attempted to stake an amount smaller than the minimum deposit.
 *
 * @param amount                Amount user attmpted to stake.
 * @param minimumDeposit        The minimum deopsit amount accepted.
 */
error USR_MinimumDeposit(uint256 amount, uint256 minimumDeposit);

/**
 * @notice The specified deposit ID does not exist for the caller.
 *
 * @param depositId             The deposit ID provided for lookup.
 */
error USR_NoDeposit(uint256 depositId);

/**
 * @notice The user is attempting to cancel unbonding for a deposit which is not unbonding.
 *
 * @param depositId             The deposit ID the user attempted to cancel.
 */
error USR_NotUnbonding(uint256 depositId);

/**
 * @notice The user is attempting to unbond a deposit which has already been unbonded.
 *
 * @param depositId             The deposit ID the user attempted to unbond.
 */
error USR_AlreadyUnbonding(uint256 depositId);

/**
 * @notice The user is attempting to unstake a deposit which is still timelocked.
 *
 * @param depositId             The deposit ID the user attempted to unstake.
 */
error USR_StakeLocked(uint256 depositId);

/**
 * @notice The contract owner attempted to update rewards but the new reward rate would cause overflow.
 */
error USR_RewardTooLarge();

/**
 * @notice The reward distributor attempted to update rewards but 0 rewards per epoch.
 *         This can also happen if there is less than 1 wei of rewards per second of the
 *         epoch - due to integer division this will also lead to 0 rewards.
 */
error USR_ZeroRewardsPerEpoch();

/**
 * @notice The caller attempted to stake with a lock value that did not
 *         correspond to a valid staking time.
 *
 * @param lock                  The provided lock value.
 */
error USR_InvalidLockValue(uint256 lock);

/**
 * @notice The caller attempted an signed action with an invalid signature.
 * @param signatureLength length of the signature passed in
 * @param expectedSignatureLength expected length of the signature passed in
 */
error USR_InvalidSignature(uint256 signatureLength, uint256 expectedSignatureLength);

// ========================================== STATE ERRORS ===========================================

/**
 * @dev These errors represent actions that are being prevented due to current contract state.
 *      These errors do not relate to user input, and may or may not be resolved by other actions
 *      or the progression of time.
 */

/**
 * @notice Attempted an action when cellar is using an asset that has a fee on transfer.
 * @param assetWithFeeOnTransfer address of the asset with fee on transfer
 */
error STATE_AssetUsesFeeOnTransfer(address assetWithFeeOnTransfer);

/**
 * @notice Attempted action was prevented due to contract being shutdown.
 */
error STATE_ContractShutdown();

/**
 * @notice Attempted to shutdown the contract when it was already shutdown.
 */
error STATE_AlreadyShutdown();

/**
 * @notice The caller attempted to start a reward period, but the contract did not have enough tokens
 *         for the specified amount of rewards.
 *
 * @param rewardBalance         The amount of distributionToken held by the contract.
 * @param reward                The amount of rewards the caller attempted to distribute.
 */
error STATE_RewardsNotFunded(uint256 rewardBalance, uint256 reward);

/**
 * @notice Attempted an operation that is prohibited while yield is still being distributed from the last accrual.
 */
error STATE_AccrualOngoing();

/**
 * @notice The caller attempted to change the epoch length, but current reward epochs were active.
 */
error STATE_RewardsOngoing();

/**
 * @notice The caller attempted to change the next epoch duration, but there are rewards ready.
 */
error STATE_RewardsReady();

/**
 * @notice The caller attempted to deposit stake, but there are no remaining rewards to pay out.
 */
error STATE_NoRewardsLeft();

/**
 * @notice The caller attempted to perform an an emergency unstake, but the contract
 *         is not in emergency mode.
 */
error STATE_NoEmergencyUnstake();

/**
 * @notice The caller attempted to perform an an emergency unstake, but the contract
 *         is not in emergency mode, or the emergency mode does not allow claiming rewards.
 */
error STATE_NoEmergencyClaim();

/**
 * @notice The caller attempted to perform a state-mutating action (e.g. staking or unstaking)
 *         while the contract was paused.
 */
error STATE_ContractPaused();

/**
 * @notice The caller attempted to perform a state-mutating action (e.g. staking or unstaking)
 *         while the contract was killed (placed in emergency mode).
 * @dev    Emergency mode is irreversible.
 */
error STATE_ContractKilled();

File 14 of 35 : ERC20.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event Transfer(address indexed from, address indexed to, uint256 amount);

    event Approval(address indexed owner, address indexed spender, uint256 amount);

    /*//////////////////////////////////////////////////////////////
                            METADATA STORAGE
    //////////////////////////////////////////////////////////////*/

    string public name;

    string public symbol;

    uint8 public immutable decimals;

    /*//////////////////////////////////////////////////////////////
                              ERC20 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;

    mapping(address => mapping(address => uint256)) public allowance;

    /*//////////////////////////////////////////////////////////////
                            EIP-2612 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 internal immutable INITIAL_CHAIN_ID;

    bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;

    mapping(address => uint256) public nonces;

    /*//////////////////////////////////////////////////////////////
                               CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    constructor(
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) {
        name = _name;
        symbol = _symbol;
        decimals = _decimals;

        INITIAL_CHAIN_ID = block.chainid;
        INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
    }

    /*//////////////////////////////////////////////////////////////
                               ERC20 LOGIC
    //////////////////////////////////////////////////////////////*/

    function approve(address spender, uint256 amount) public virtual returns (bool) {
        allowance[msg.sender][spender] = amount;

        emit Approval(msg.sender, spender, amount);

        return true;
    }

    function transfer(address to, uint256 amount) public virtual returns (bool) {
        balanceOf[msg.sender] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(msg.sender, to, amount);

        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual returns (bool) {
        uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.

        if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;

        balanceOf[from] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(from, to, amount);

        return true;
    }

    /*//////////////////////////////////////////////////////////////
                             EIP-2612 LOGIC
    //////////////////////////////////////////////////////////////*/

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");

        // Unchecked because the only math done is incrementing
        // the owner's nonce which cannot realistically overflow.
        unchecked {
            address recoveredAddress = ecrecover(
                keccak256(
                    abi.encodePacked(
                        "\x19\x01",
                        DOMAIN_SEPARATOR(),
                        keccak256(
                            abi.encode(
                                keccak256(
                                    "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
                                ),
                                owner,
                                spender,
                                value,
                                nonces[owner]++,
                                deadline
                            )
                        )
                    )
                ),
                v,
                r,
                s
            );

            require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");

            allowance[recoveredAddress][spender] = value;
        }

        emit Approval(owner, spender, value);
    }

    function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
        return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
    }

    function computeDomainSeparator() internal view virtual returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
                    keccak256(bytes(name)),
                    keccak256("1"),
                    block.chainid,
                    address(this)
                )
            );
    }

    /*//////////////////////////////////////////////////////////////
                        INTERNAL MINT/BURN LOGIC
    //////////////////////////////////////////////////////////////*/

    function _mint(address to, uint256 amount) internal virtual {
        totalSupply += amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(address(0), to, amount);
    }

    function _burn(address from, uint256 amount) internal virtual {
        balanceOf[from] -= amount;

        // Cannot underflow because a user's balance
        // will never be larger than the total supply.
        unchecked {
            totalSupply -= amount;
        }

        emit Transfer(from, address(0), amount);
    }
}

File 15 of 35 : SafeTransferLib.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

import {ERC20} from "../tokens/ERC20.sol";

/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
    /*//////////////////////////////////////////////////////////////
                             ETH OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferETH(address to, uint256 amount) internal {
        bool success;

        assembly {
            // Transfer the ETH and store if it succeeded or not.
            success := call(gas(), to, amount, 0, 0, 0, 0)
        }

        require(success, "ETH_TRANSFER_FAILED");
    }

    /*//////////////////////////////////////////////////////////////
                            ERC20 OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferFrom(
        ERC20 token,
        address from,
        address to,
        uint256 amount
    ) internal {
        bool success;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), from) // Append the "from" argument.
            mstore(add(freeMemoryPointer, 36), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
            )
        }

        require(success, "TRANSFER_FROM_FAILED");
    }

    function safeTransfer(
        ERC20 token,
        address to,
        uint256 amount
    ) internal {
        bool success;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
            )
        }

        require(success, "TRANSFER_FAILED");
    }

    function safeApprove(
        ERC20 token,
        address to,
        uint256 amount
    ) internal {
        bool success;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
            )
        }

        require(success, "APPROVE_FAILED");
    }
}

File 16 of 35 : IMulticall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;

/// @title Multicall interface
/// @notice Enables calling multiple methods in a single call to the contract
// From: https://github.com/Uniswap/v3-periphery/contracts/interfaces/IMulticall.sol
interface IMulticall {
    /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
    /// @dev The `msg.value` should not be trusted for any method callable from multicall.
    /// @param data The encoded function data for each of the calls to make to this contract
    /// @return results The results from each of the calls passed in via data
    function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}

File 17 of 35 : 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 18 of 35 : CellarStaking.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC20 } from "lib/solmate/src/tokens/ERC20.sol";
import { SafeTransferLib } from "lib/solmate/src/utils/SafeTransferLib.sol";
import { Ownable } from "lib/openzeppelin-contracts/contracts/access/Ownable.sol";
import { ICellarStaking } from "./interfaces/ICellarStaking.sol";

import "./Errors.sol";

/**
 * @title Sommelier Staking
 * @author Kevin Kennis
 *
 * Staking for Sommelier Cellars.
 *
 * This contract is inspired by the Synthetix staking rewards contract, Ampleforth's
 * token geyser, and Treasure DAO's MAGIC mine. However, there are unique improvements
 * and new features, specifically unbonding, as inspired by LP bonding on Osmosis.
 * Unbonding allows the contract to guarantee deposits for a certain amount of time,
 * increasing predictability and stickiness of TVL for Cellars.
 *
 * *********************************** Funding Flow ***********************************
 *
 * 1) The contract owner calls 'notifyRewardAmount' to specify an initial schedule of rewards
 *    The contract should hold enough the distribution token to fund the
 *    specified reward schedule, where the length of the reward schedule is defined by
 *    epochDuration. This duration can also be changed by the owner, and any change will apply
 *    to future calls to 'notifyRewardAmount' (but will not affect active schedules).
 * 2) At a future time, the contract owner may call 'notifyRewardAmount' again to extend the
 *    staking program with new rewards. These new schedules may distribute more or less
 *    rewards than previous epochs. If a previous epoch is not finished, any leftover rewards
 *    get rolled into the new schedule, increasing the reward rate. Reward schedules always
 *    end exactly 'epochDuration' seconds from the most recent time 'notifyRewardAmount' has been
 *    called.
 *
 * ********************************* Staking Lifecycle ********************************
 *
 * 1) A user may deposit a certain amount of tokens to stake, and is required to lock
 *    those tokens for a specified amount of time. There are three locking options:
 *    one day, one week, or one month. Longer locking times receive larger 'boosts',
 *    that the deposit will receive a larger proportional amount of shares. A user
 *    may not unstake until they choose to unbond, and time defined by the lock has
 *    elapsed during unbonding.
 * 2) When a user wishes to withdraw, they must first "unbond" their stake, which starts
 *    a timer equivalent to the lock time. They still receive their rewards during this
 *    time, but forfeit any locktime boosts. A user may cancel the unbonding period at any
 *    time to regain their boosts, which will set the unbonding timer back to 0.
 * 2) Once the lock has elapsed, a user may unstake their deposit, either partially
 *    or in full. The user will continue to receive the same 'boosted' amount of rewards
 *    until they unstake. The user may unstake all of their deposits at once, as long
 *    as all of the lock times have elapsed. When unstaking, the user will also receive
 *    all eligible rewards for all deposited stakes, which accumulate linearly.
 * 3) At any time, a user may claim their available rewards for their deposits. Rewards
 *    accumulate linearly and can be claimed at any time, whether or not the lock has
 *    for a given deposit has expired. The user can claim rewards for a specific deposit,
 *    or may choose to collect all eligible rewards at once.
 *
 * ************************************ Accounting ************************************
 *
 * The contract uses an accounting mechanism based on the 'rewardPerToken' model,
 * originated by the Synthetix staking rewards contract. First, token deposits are accounted
 * for, with synthetic "boosted" amounts used for reward calculations. As time passes,
 * rewardPerToken continues to accumulate, whereas the value of 'rewardPerToken' will match
 * the reward due to a single token deposited before the first ever rewards were scheduled.
 *
 * At each accounting checkpoint, rewardPerToken will be recalculated, and every time an
 * existing stake is 'touched', this value is used to calculate earned rewards for that
 * stake. Each stake tracks a 'rewardPerTokenPaid' value, which represents the 'rewardPerToken'
 * value the last time the stake calculated "earned" rewards. Every recalculation pays the difference.
 * This ensures no earning is double-counted. When a new stake is deposited, its
 * initial 'rewardPerTokenPaid' is set to the current 'rewardPerToken' in the contract,
 * ensuring it will not receive any rewards emitted during the period before deposit.
 *
 * The following example applies to a given epoch of 100 seconds, with a reward rate
 * of 100 tokens per second:
 *
 * a) User 1 deposits a stake of 50 before the epoch begins
 * b) User 2 deposits a stake of 20 at second 20 of the epoch
 * c) User 3 deposits a stake of 100 at second 50 of the epoch
 *
 * In this case,
 *
 * a) At second 20, before User 2's deposit, rewardPerToken will be 40
 *     (2000 total tokens emitted over 20 seconds / 50 staked).
 * b) At second 50, before User 3's deposit, rewardPerToken will be 82.857
 *     (previous 40 + 3000 tokens emitted over 30 seconds / 70 staked == 42.857)
 * c) At second 100, when the period is over, rewardPerToken will be 112.267
 *     (previous 82.857 + 5000 tokens emitted over 50 seconds / 170 staked == 29.41)
 *
 *
 * Then, each user will receive rewards proportional to the their number of tokens. At second 100:
 * a) User 1 will receive 50 * 112.267 = 5613.35 rewards
 * b) User 2 will receive 20 * (112.267 - 40) = 1445.34
 *       (40 is deducted because it was the current rewardPerToken value on deposit)
 * c) User 3 will receive 100 * (112.267 - 82.857) = 2941
 *       (82.857 is deducted because it was the current rewardPerToken value on deposit)
 *
 * Depending on deposit times, this accumulation may take place over multiple
 * reward periods, and the total rewards earned is simply the sum of rewards earned for
 * each period. A user may also have multiple discrete deposits, which are all
 * accounted for separately due to timelocks and locking boosts. Therefore,
 * a user's total earned rewards are a function of their rewards across
 * the proportional tokens deposited, across different ranges of rewardPerToken.
 *
 * Reward accounting takes place before every operation which may change
 * accounting calculations (minting of new shares on staking, burning of
 * shares on unstaking, or claiming, which decrements eligible rewards).
 * This is gas-intensive but unavoidable, since retroactive accounting
 * based on previous proportionate shares would require a prohibitive
 * amount of storage of historical state. On every accounting run, there
 * are a number of safety checks to ensure that all reward tokens are
 * accounted for and that no accounting time periods have been missed.
 *
 */
contract CellarStaking is ICellarStaking, Ownable {
    using SafeTransferLib for ERC20;

    // ============================================ STATE ==============================================

    // ============== Constants ==============

    uint256 public constant ONE = 1e18;
    uint256 public constant ONE_DAY = 60 * 60 * 24;
    uint256 public constant ONE_WEEK = ONE_DAY * 7;
    uint256 public constant TWO_WEEKS = ONE_WEEK * 2;

    uint256 public immutable SHORT_BOOST;
    uint256 public immutable MEDIUM_BOOST;
    uint256 public immutable LONG_BOOST;

    uint256 public immutable SHORT_BOOST_TIME;
    uint256 public immutable MEDIUM_BOOST_TIME;
    uint256 public immutable LONG_BOOST_TIME;

    // ============ Global State =============

    ERC20 public immutable override stakingToken;
    ERC20 public immutable override distributionToken;
    uint256 public override currentEpochDuration;
    uint256 public override nextEpochDuration;
    uint256 public override rewardsReady;

    uint256 public override minimumDeposit;
    uint256 public override endTimestamp;
    uint256 public override totalDeposits;
    uint256 public override totalDepositsWithBoost;
    uint256 public override rewardRate;
    uint256 public override rewardPerTokenStored;

    uint256 private lastAccountingTimestamp = block.timestamp;

    /// @notice Emergency states in case of contract malfunction.
    bool public override paused;
    bool public override ended;
    bool public override claimable;

    // ============= User State ==============

    /// @notice user => all user's staking positions
    mapping(address => UserStake[]) public stakes;

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

    /**
     * @param _owner                The owner of the staking contract - will immediately receive ownership.
     * @param _stakingToken         The token users will deposit in order to stake.
     * @param _distributionToken    The token the staking contract will distribute as rewards.
     * @param _epochDuration        The length of a reward schedule.
     * @param shortBoost            The boost multiplier for the short unbonding time.
     * @param mediumBoost           The boost multiplier for the medium unbonding time.
     * @param longBoost             The boost multiplier for the long unbonding time.
     * @param shortBoostTime        The short unbonding time.
     * @param mediumBoostTime       The medium unbonding time.
     * @param longBoostTime         The long unbonding time.
     */
    constructor(
        address _owner,
        ERC20 _stakingToken,
        ERC20 _distributionToken,
        uint256 _epochDuration,
        uint256 shortBoost,
        uint256 mediumBoost,
        uint256 longBoost,
        uint256 shortBoostTime,
        uint256 mediumBoostTime,
        uint256 longBoostTime
    ) {
        stakingToken = _stakingToken;
        distributionToken = _distributionToken;
        nextEpochDuration = _epochDuration;

        SHORT_BOOST = shortBoost;
        MEDIUM_BOOST = mediumBoost;
        LONG_BOOST = longBoost;

        SHORT_BOOST_TIME = shortBoostTime;
        MEDIUM_BOOST_TIME = mediumBoostTime;
        LONG_BOOST_TIME = longBoostTime;

        transferOwnership(_owner);
    }

    // ======================================= STAKING OPERATIONS =======================================

    /**
     * @notice  Make a new deposit into the staking contract. Longer locks receive reward boosts.
     * @dev     Specified amount of stakingToken must be approved for withdrawal by the caller.
     * @dev     Valid lock values are 0 (one day), 1 (one week), and 2 (two weeks).
     *
     * @param amount                The amount of the stakingToken to stake.
     * @param lock                  The amount of time to lock stake for.
     */
    function stake(uint256 amount, Lock lock) external override whenNotPaused updateRewards {
        if (amount == 0) revert USR_ZeroDeposit();
        if (amount < minimumDeposit) revert USR_MinimumDeposit(amount, minimumDeposit);

        if (totalDeposits == 0 && rewardsReady > 0) {
            _startProgram(rewardsReady);
            rewardsReady = 0;

            // Need to run updateRewards again
            _updateRewards();
        } else if (block.timestamp > endTimestamp) {
            revert STATE_NoRewardsLeft();
        }

        // Do share accounting and populate user stake information
        (uint256 boost, ) = _getBoost(lock);
        uint256 amountWithBoost = amount + ((amount * boost) / ONE);

        stakes[msg.sender].push(
            UserStake({
                amount: uint112(amount),
                amountWithBoost: uint112(amountWithBoost),
                unbondTimestamp: 0,
                rewardPerTokenPaid: uint112(rewardPerTokenStored),
                rewards: 0,
                lock: lock
            })
        );

        // Update global state
        totalDeposits += amount;
        totalDepositsWithBoost += amountWithBoost;

        stakingToken.safeTransferFrom(msg.sender, address(this), amount);

        emit Stake(msg.sender, stakes[msg.sender].length - 1, amount);
    }

    /**
     * @notice  Unbond a specified amount from a certain deposited stake.
     * @dev     After the unbond time elapses, the deposit can be unstaked.
     *
     * @param depositId             The specified deposit to unstake from.
     *
     */
    function unbond(uint256 depositId) external override whenNotPaused updateRewards {
        _unbond(depositId);
    }

    /**
     * @notice  Unbond all user deposits.
     * @dev     Different deposits may have different timelocks.
     *
     */
    function unbondAll() external override whenNotPaused updateRewards {
        // Individually unbond each deposit
        UserStake[] storage userStakes = stakes[msg.sender];
        for (uint256 i = 0; i < userStakes.length; i++) {
            UserStake storage s = userStakes[i];

            if (s.amount != 0 && s.unbondTimestamp == 0) {
                _unbond(i);
            }
        }
    }

    /**
     * @dev     Contains all logic for processing an unbond operation.
     *          For the given deposit, sets an unlock time, and
     *          reverts boosts to 0.
     *
     * @param depositId             The specified deposit to unbond from.
     */
    function _unbond(uint256 depositId) internal {
        // Fetch stake and make sure it is withdrawable
        UserStake storage s = stakes[msg.sender][depositId];

        uint256 depositAmount = s.amount;
        if (depositAmount == 0) revert USR_NoDeposit(depositId);
        if (s.unbondTimestamp > 0) revert USR_AlreadyUnbonding(depositId);

        _updateRewardForStake(msg.sender, depositId);

        // Remove any lock boosts
        uint256 depositAmountReduced = s.amountWithBoost - depositAmount;
        (, uint256 lockDuration) = _getBoost(s.lock);

        s.amountWithBoost = uint112(depositAmount);
        s.unbondTimestamp = uint32(block.timestamp + lockDuration);

        totalDepositsWithBoost -= uint112(depositAmountReduced);

        emit Unbond(msg.sender, depositId, depositAmount);
    }

    /**
     * @notice  Cancel an unbonding period for a stake that is currently unbonding.
     * @dev     Resets the unbonding timer and reinstates any lock boosts.
     *
     * @param depositId             The specified deposit to unstake from.
     *
     */
    function cancelUnbonding(uint256 depositId) external override whenNotPaused updateRewards {
        _cancelUnbonding(depositId);
    }

    /**
     * @notice  Cancel an unbonding period for all stakes.
     * @dev     Only cancels stakes that are unbonding.
     *
     */
    function cancelUnbondingAll() external override whenNotPaused updateRewards {
        // Individually unbond each deposit
        UserStake[] storage userStakes = stakes[msg.sender];
        for (uint256 i = 0; i < userStakes.length; i++) {
            UserStake storage s = userStakes[i];

            if (s.amount != 0 && s.unbondTimestamp != 0) {
                _cancelUnbonding(i);
            }
        }
    }

    /**
     * @dev     Contains all logic for cancelling an unbond operation.
     *          For the given deposit, resets the unbonding timer, and
     *          reverts boosts to amount determined by lock.
     *
     * @param depositId             The specified deposit to unbond from.
     */
    function _cancelUnbonding(uint256 depositId) internal {
        // Fetch stake and make sure it is withdrawable
        UserStake storage s = stakes[msg.sender][depositId];

        uint256 depositAmount = s.amount;
        if (depositAmount == 0) revert USR_NoDeposit(depositId);
        if (s.unbondTimestamp == 0) revert USR_NotUnbonding(depositId);

        _updateRewardForStake(msg.sender, depositId);

        // Reinstate
        (uint256 boost, ) = _getBoost(s.lock);
        uint256 depositAmountIncreased = (s.amount * boost) / ONE;
        uint256 amountWithBoost = s.amount + depositAmountIncreased;

        s.amountWithBoost = uint112(amountWithBoost);
        s.unbondTimestamp = 0;

        totalDepositsWithBoost += depositAmountIncreased;

        emit CancelUnbond(msg.sender, depositId);
    }

    /**
     * @notice  Unstake a specific deposited stake.
     * @dev     The unbonding time for the specified deposit must have elapsed.
     * @dev     Unstaking automatically claims available rewards for the deposit.
     *
     * @param depositId             The specified deposit to unstake from.
     *
     * @return reward               The amount of accumulated rewards since the last reward claim.
     */
    function unstake(uint256 depositId) external override whenNotPaused updateRewards returns (uint256 reward) {
        return _unstake(depositId);
    }

    /**
     * @notice  Unstake all user deposits.
     * @dev     Only unstakes rewards that are unbonded.
     * @dev     Unstaking automatically claims all available rewards.
     *
     * @return rewards              The amount of accumulated rewards since the last reward claim.
     */
    function unstakeAll() external override whenNotPaused updateRewards returns (uint256[] memory) {
        // Individually unstake each deposit
        UserStake[] storage userStakes = stakes[msg.sender];
        uint256[] memory rewards = new uint256[](userStakes.length);

        for (uint256 i = 0; i < userStakes.length; i++) {
            UserStake storage s = userStakes[i];

            if (s.amount != 0 && s.unbondTimestamp != 0 && block.timestamp >= s.unbondTimestamp) {
                rewards[i] = _unstake(i);
            }
        }

        return rewards;
    }

    /**
     * @dev     Contains all logic for processing an unstake operation.
     *          For the given deposit, does share accounting and burns
     *          shares, returns staking tokens to the original owner,
     *          updates global deposit and share trackers, and claims
     *          rewards for the given deposit.
     *
     * @param depositId             The specified deposit to unstake from.
     */
    function _unstake(uint256 depositId) internal returns (uint256 reward) {
        // Fetch stake and make sure it is withdrawable
        UserStake storage s = stakes[msg.sender][depositId];

        uint256 depositAmount = s.amount;

        if (depositAmount == 0) revert USR_NoDeposit(depositId);
        if (s.unbondTimestamp == 0 || block.timestamp < s.unbondTimestamp) revert USR_StakeLocked(depositId);

        _updateRewardForStake(msg.sender, depositId);

        // Start unstaking
        reward = s.rewards;

        s.amount = 0;
        s.amountWithBoost = 0;
        s.rewards = 0;

        // Update global state
        // Boosted amount same as deposit amount, since we have unbonded
        totalDeposits -= depositAmount;
        totalDepositsWithBoost -= depositAmount;

        // Distribute stake
        stakingToken.safeTransfer(msg.sender, depositAmount);

        // Distribute reward
        distributionToken.safeTransfer(msg.sender, reward);

        emit Unstake(msg.sender, depositId, depositAmount, reward);
    }

    /**
     * @notice  Claim rewards for a given deposit.
     * @dev     Rewards accumulate linearly since deposit.
     *
     * @param depositId             The specified deposit for which to claim rewards.
     *
     * @return reward               The amount of accumulated rewards since the last reward claim.
     */
    function claim(uint256 depositId) external override whenNotPaused updateRewards returns (uint256 reward) {
        return _claim(depositId);
    }

    /**
     * @notice  Claim all available rewards.
     * @dev     Rewards accumulate linearly.
     *
     *
     * @return rewards               The amount of accumulated rewards since the last reward claim.
     *                               Each element of the array specified rewards for the corresponding
     *                               indexed deposit.
     */
    function claimAll() external override whenNotPaused updateRewards returns (uint256[] memory rewards) {
        // Individually claim for each stake
        UserStake[] storage userStakes = stakes[msg.sender];
        rewards = new uint256[](userStakes.length);

        for (uint256 i = 0; i < userStakes.length; i++) {
            rewards[i] = _claim(i);
        }
    }

    /**
     * @dev Contains all logic for processing a claim operation.
     *      Relies on previous reward accounting done before
     *      processing external functions. Updates the amount
     *      of rewards claimed so rewards cannot be claimed twice.
     *
     *
     * @param depositId             The specified deposit to claim rewards for.
     *
     * @return reward               The amount of accumulated rewards since the last reward claim.
     */
    function _claim(uint256 depositId) internal returns (uint256 reward) {
        // Fetch stake and make sure it is valid
        UserStake storage s = stakes[msg.sender][depositId];

        _updateRewardForStake(msg.sender, depositId);

        reward = s.rewards;

        // Distribute reward
        if (reward > 0) {
            s.rewards = 0;

            distributionToken.safeTransfer(msg.sender, reward);

            emit Claim(msg.sender, depositId, reward);
        }
    }

    /**
     * @notice  Unstake and return all staked tokens to the caller.
     * @dev     In emergency mode, staking time locks do not apply.
     */
    function emergencyUnstake() external override {
        if (!ended) revert STATE_NoEmergencyUnstake();

        UserStake[] storage userStakes = stakes[msg.sender];
        for (uint256 i = 0; i < userStakes.length; i++) {
            if (claimable) _updateRewardForStake(msg.sender, i);

            UserStake storage s = userStakes[i];
            uint256 amount = s.amount;

            if (amount > 0) {
                // Update global state
                totalDeposits -= amount;
                totalDepositsWithBoost -= s.amountWithBoost;

                s.amount = 0;
                s.amountWithBoost = 0;

                stakingToken.transfer(msg.sender, amount);

                emit EmergencyUnstake(msg.sender, i, amount);
            }
        }
    }

    /**
     * @notice  Claim any accumulated rewards in emergency mode.
     * @dev     In emergency node, no additional reward accounting is done.
     *          Rewards do not accumulate after emergency mode begins,
     *          so any earned amount is only retroactive to when the contract
     *          was active.
     */
    function emergencyClaim() external override {
        if (!ended) revert STATE_NoEmergencyUnstake();
        if (!claimable) revert STATE_NoEmergencyClaim();

        uint256 reward;

        UserStake[] storage userStakes = stakes[msg.sender];
        for (uint256 i = 0; i < userStakes.length; i++) {
            _updateRewardForStake(msg.sender, i);

            UserStake storage s = userStakes[i];

            reward += s.rewards;
            s.rewards = 0;
        }

        if (reward > 0) {
            distributionToken.safeTransfer(msg.sender, reward);

            // No need for per-stake events like emergencyUnstake:
            // don't need to make sure positions were unwound
            emit EmergencyClaim(msg.sender, reward);
        }
    }

    // ======================================== ADMIN OPERATIONS ========================================

    /**
     * @notice Specify a new schedule for staking rewards. Contract must already hold enough tokens.
     * @dev    Can only be called by reward distributor. Owner must approve distributionToken for withdrawal.
     * @dev    epochDuration must divide reward evenly, otherwise any remainder will be lost.
     *
     * @param reward                The amount of rewards to distribute per second.
     */
    function notifyRewardAmount(uint256 reward) external override onlyOwner updateRewards {
        if (block.timestamp < endTimestamp) {
            uint256 remaining = endTimestamp - block.timestamp;
            uint256 leftover = remaining * rewardRate;
            reward += leftover;
        }

        if (reward < nextEpochDuration) revert USR_ZeroRewardsPerEpoch();

        uint256 rewardBalance = distributionToken.balanceOf(address(this));
        uint256 pendingRewards = reward + rewardsReady;
        if (rewardBalance < pendingRewards) revert STATE_RewardsNotFunded(rewardBalance, pendingRewards);

        // prevent overflow when computing rewardPerToken
        uint256 proposedRewardRate = reward / nextEpochDuration;
        if (proposedRewardRate >= ((type(uint256).max / ONE) / nextEpochDuration)) {
            revert USR_RewardTooLarge();
        }

        if (totalDeposits == 0) {
            // No deposits yet, so keep rewards pending until first deposit
            // Incrementing in case it is called twice
            rewardsReady += reward;
        } else {
            // Ready to start
            _startProgram(reward);
        }

        lastAccountingTimestamp = block.timestamp;
    }

    /**
     * @notice Change the length of a reward epoch for future reward schedules.
     *
     * @param _epochDuration        The new duration for reward schedules.
     */
    function setRewardsDuration(uint256 _epochDuration) external override onlyOwner {
        if (rewardsReady > 0) revert STATE_RewardsReady();

        nextEpochDuration = _epochDuration;
        emit EpochDurationChange(nextEpochDuration);
    }

    /**
     * @notice Specify a minimum deposit for staking.
     * @dev    Can only be called by owner.
     *
     * @param _minimum              The minimum deposit for each new stake.
     */
    function setMinimumDeposit(uint256 _minimum) external override onlyOwner {
        minimumDeposit = _minimum;
    }

    /**
     * @notice Pause the contract. Pausing prevents staking, unstaking, claiming
     *         rewards, and scheduling new rewards. Should only be used
     *         in an emergency.
     *
     * @param _paused               Whether the contract should be paused.
     */
    function setPaused(bool _paused) external override onlyOwner {
        paused = _paused;
    }

    /**
     * @notice Stops the contract - this is irreversible. Should only be used
     *         in an emergency, for example an irreversible accounting bug
     *         or an exploit. Enables all depositors to withdraw their stake
     *         instantly. Also stops new rewards accounting.
     *
     * @param makeRewardsClaimable  Whether any previously accumulated rewards should be claimable.
     */
    function emergencyStop(bool makeRewardsClaimable) external override onlyOwner {
        if (ended) revert STATE_AlreadyShutdown();

        // Update state and put in irreversible emergency mode
        ended = true;
        claimable = makeRewardsClaimable;
        uint256 amountToReturn = distributionToken.balanceOf(address(this));

        if (makeRewardsClaimable) {
            // Update rewards one more time
            _updateRewards();

            // Return any remaining, since new calculation is stopped
            uint256 remaining = endTimestamp > block.timestamp ? (endTimestamp - block.timestamp) * rewardRate : 0;

            // Make sure any rewards except for remaining are kept for claims
            uint256 amountToKeep = rewardRate * currentEpochDuration - remaining;

            amountToReturn -= amountToKeep;
        }

        // Send distribution token back to owner
        distributionToken.transfer(msg.sender, amountToReturn);

        emit EmergencyStop(msg.sender, makeRewardsClaimable);
    }

    // ======================================= STATE INFORMATION =======================================

    /**
     * @notice Returns the latest time to account for in the reward program.
     *
     * @return timestamp           The latest time to calculate.
     */
    function latestRewardsTimestamp() public view override returns (uint256) {
        return block.timestamp < endTimestamp ? block.timestamp : endTimestamp;
    }

    /**
     * @notice Returns the amount of reward to distribute per currently-depostied token.
     *         Will update on changes to total deposit balance or reward rate.
     * @dev    Sets rewardPerTokenStored.
     *
     *
     * @return newRewardPerTokenStored  The new rewards to distribute per token.
     * @return latestTimestamp          The latest time to calculate.
     */
    function rewardPerToken() public view override returns (uint256 newRewardPerTokenStored, uint256 latestTimestamp) {
        latestTimestamp = latestRewardsTimestamp();

        if (totalDeposits == 0) return (rewardPerTokenStored, latestTimestamp);

        uint256 timeElapsed = latestTimestamp - lastAccountingTimestamp;
        uint256 rewardsForTime = timeElapsed * rewardRate;
        uint256 newRewardsPerToken = (rewardsForTime * ONE) / totalDepositsWithBoost;

        newRewardPerTokenStored = rewardPerTokenStored + newRewardsPerToken;
    }

    /**
     * @notice Gets all of a user's stakes.
     * @dev This is provided because Solidity converts public arrays into index getters,
     *      but we need a way to allow external contracts and users to access the whole array.

     * @param user                      The user whose stakes to get.
     *
     * @return stakes                   Array of all user's stakes
     */
    function getUserStakes(address user) public view override returns (UserStake[] memory) {
        return stakes[user];
    }

    // ============================================ HELPERS ============================================

    /**
     * @dev Modifier to apply reward updates before functions that change accounts.
     */
    modifier updateRewards() {
        _updateRewards();
        _;
    }

    /**
     * @dev Blocks calls if contract is paused or killed.
     */
    modifier whenNotPaused() {
        if (paused) revert STATE_ContractPaused();
        if (ended) revert STATE_ContractKilled();
        _;
    }

    /**
     * @dev Update reward accounting for the global state totals.
     */
    function _updateRewards() internal {
        (rewardPerTokenStored, lastAccountingTimestamp) = rewardPerToken();
    }

    /**
     * @dev On initial deposit, start the rewards program.
     *
     * @param reward                    The pending rewards to start distributing.
     */
    function _startProgram(uint256 reward) internal {
        // Assumptions
        // Total deposits are now (mod current tx), no ongoing program
        // Rewards are already funded (since checked in notifyRewardAmount)

        rewardRate = reward / nextEpochDuration;
        endTimestamp = block.timestamp + nextEpochDuration;
        currentEpochDuration = nextEpochDuration;

        emit Funding(reward, endTimestamp);
    }

    /**
     * @dev Update reward for a specific user stake.
     */
    function _updateRewardForStake(address user, uint256 depositId) internal {
        UserStake storage s = stakes[user][depositId];
        if (s.amount == 0) return;

        uint256 earned = _earned(s);
        s.rewards += uint112(earned);

        s.rewardPerTokenPaid = uint112(rewardPerTokenStored);
    }

    /**
     * @dev Return how many rewards a stake has earned and has claimable.
     */
    function _earned(UserStake memory s) internal view returns (uint256) {
        uint256 rewardPerTokenAcc = rewardPerTokenStored - s.rewardPerTokenPaid;
        uint256 newRewards = (s.amountWithBoost * rewardPerTokenAcc) / ONE;

        return newRewards;
    }

    /**
     * @dev Maps Lock enum values to corresponding lengths of time and reward boosts.
     */
    function _getBoost(Lock _lock) internal view returns (uint256 boost, uint256 timelock) {
        if (_lock == Lock.short) {
            return (SHORT_BOOST, SHORT_BOOST_TIME);
        } else if (_lock == Lock.medium) {
            return (MEDIUM_BOOST, MEDIUM_BOOST_TIME);
        } else if (_lock == Lock.long) {
            return (LONG_BOOST, LONG_BOOST_TIME);
        } else {
            revert USR_InvalidLockValue(uint256(_lock));
        }
    }
}

File 19 of 35 : ICellarStaking.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC20 } from "lib/solmate/src/tokens/ERC20.sol";

/**
 * @title Sommelier Staking Interface
 * @author Kevin Kennis
 *
 * @notice Full documentation in implementation contract.
 */
interface ICellarStaking {
    // ===================== Events =======================

    event Funding(uint256 rewardAmount, uint256 rewardEnd);
    event Stake(address indexed user, uint256 depositId, uint256 amount);
    event Unbond(address indexed user, uint256 depositId, uint256 amount);
    event CancelUnbond(address indexed user, uint256 depositId);
    event Unstake(address indexed user, uint256 depositId, uint256 amount, uint256 reward);
    event Claim(address indexed user, uint256 depositId, uint256 amount);
    event EmergencyStop(address owner, bool claimable);
    event EmergencyUnstake(address indexed user, uint256 depositId, uint256 amount);
    event EmergencyClaim(address indexed user, uint256 amount);
    event EpochDurationChange(uint256 duration);

    // ===================== Structs ======================

    enum Lock {
        short,
        medium,
        long
    }

    struct UserStake {
        uint112 amount;
        uint112 amountWithBoost;
        uint32 unbondTimestamp;
        uint112 rewardPerTokenPaid;
        uint112 rewards;
        Lock lock;
    }

    // ============== Public State Variables ==============

    function stakingToken() external returns (ERC20);

    function distributionToken() external returns (ERC20);

    function currentEpochDuration() external returns (uint256);

    function nextEpochDuration() external returns (uint256);

    function rewardsReady() external returns (uint256);

    function minimumDeposit() external returns (uint256);

    function endTimestamp() external returns (uint256);

    function totalDeposits() external returns (uint256);

    function totalDepositsWithBoost() external returns (uint256);

    function rewardRate() external returns (uint256);

    function rewardPerTokenStored() external returns (uint256);

    function paused() external returns (bool);

    function ended() external returns (bool);

    function claimable() external returns (bool);

    // ================ User Functions ================

    function stake(uint256 amount, Lock lock) external;

    function unbond(uint256 depositId) external;

    function unbondAll() external;

    function cancelUnbonding(uint256 depositId) external;

    function cancelUnbondingAll() external;

    function unstake(uint256 depositId) external returns (uint256 reward);

    function unstakeAll() external returns (uint256[] memory rewards);

    function claim(uint256 depositId) external returns (uint256 reward);

    function claimAll() external returns (uint256[] memory rewards);

    function emergencyUnstake() external;

    function emergencyClaim() external;

    // ================ Admin Functions ================

    function notifyRewardAmount(uint256 reward) external;

    function setRewardsDuration(uint256 _epochDuration) external;

    function setMinimumDeposit(uint256 _minimum) external;

    function setPaused(bool _paused) external;

    function emergencyStop(bool makeRewardsClaimable) external;

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

    function latestRewardsTimestamp() external view returns (uint256);

    function rewardPerToken() external view returns (uint256, uint256);

    function getUserStakes(address user) external view returns (UserStake[] memory);
}

File 20 of 35 : MockSwapRouter.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC20 } from "lib/solmate/src/tokens/ERC20.sol";
import { Math } from "src/utils/Math.sol";

library BytesLib {
    function slice(
        bytes memory _bytes,
        uint256 _start,
        uint256 _length
    ) internal pure returns (bytes memory) {
        require(_length + 31 >= _length, "slice_overflow");
        require(_start + _length >= _start, "slice_overflow");
        require(_bytes.length >= _start + _length, "slice_outOfBounds");

        bytes memory tempBytes;

        assembly {
            switch iszero(_length)
            case 0 {
                // Get a location of some free memory and store it in tempBytes as
                // Solidity does for memory variables.
                tempBytes := mload(0x40)

                // The first word of the slice result is potentially a partial
                // word read from the original array. To read it, we calculate
                // the length of that partial word and start copying that many
                // bytes into the array. The first word we copy will start with
                // data we don't care about, but the last `lengthmod` bytes will
                // land at the beginning of the contents of the new array. When
                // we're done copying, we overwrite the full first word with
                // the actual length of the slice.
                let lengthmod := and(_length, 31)

                // The multiplication in the next line is necessary
                // because when slicing multiples of 32 bytes (lengthmod == 0)
                // the following copy loop was copying the origin's length
                // and then ending prematurely not copying everything it should.
                let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
                let end := add(mc, _length)

                for {
                    // The multiplication in the next line has the same exact purpose
                    // as the one above.
                    let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
                } lt(mc, end) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    mstore(mc, mload(cc))
                }

                mstore(tempBytes, _length)

                //update free-memory pointer
                //allocating the array padded to 32 bytes like the compiler does now
                mstore(0x40, and(add(mc, 31), not(31)))
            }
            //if we want a zero-length slice let's just return a zero-length array
            default {
                tempBytes := mload(0x40)
                //zero out the 32 bytes slice we are about to return
                //we need to do it because Solidity does not garbage collect
                mstore(tempBytes, 0)

                mstore(0x40, add(tempBytes, 0x20))
            }
        }

        return tempBytes;
    }

    function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
        require(_start + 20 >= _start, "toAddress_overflow");
        require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
        address tempAddress;

        assembly {
            tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
        }

        return tempAddress;
    }

    function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) {
        require(_start + 3 >= _start, "toUint24_overflow");
        require(_bytes.length >= _start + 3, "toUint24_outOfBounds");
        uint24 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x3), _start))
        }

        return tempUint;
    }
}

/// @title Functions for manipulating path data for multihop swaps
library Path {
    using BytesLib for bytes;

    /// @dev The length of the bytes encoded address
    uint256 private constant ADDR_SIZE = 20;
    /// @dev The length of the bytes encoded fee
    uint256 private constant FEE_SIZE = 3;

    /// @dev The offset of a single token address and pool fee
    uint256 private constant NEXT_OFFSET = ADDR_SIZE + FEE_SIZE;
    /// @dev The offset of an encoded pool key
    uint256 private constant POP_OFFSET = NEXT_OFFSET + ADDR_SIZE;
    /// @dev The minimum length of an encoding that contains 2 or more pools
    uint256 private constant MULTIPLE_POOLS_MIN_LENGTH = POP_OFFSET + NEXT_OFFSET;

    /// @notice Returns true iff the path contains two or more pools
    /// @param path The encoded swap path
    /// @return True if path contains two or more pools, otherwise false
    function hasMultiplePools(bytes memory path) internal pure returns (bool) {
        return path.length >= MULTIPLE_POOLS_MIN_LENGTH;
    }

    /// @notice Decodes the first pool in path
    /// @param path The bytes encoded swap path
    /// @return tokenA The first token of the given pool
    /// @return tokenB The second token of the given pool
    /// @return fee The fee level of the pool
    function decodeFirstPool(bytes memory path)
        internal
        pure
        returns (
            address tokenA,
            address tokenB,
            uint24 fee
        )
    {
        tokenA = path.toAddress(0);
        fee = path.toUint24(ADDR_SIZE);
        tokenB = path.toAddress(NEXT_OFFSET);
    }

    /// @notice Gets the segment corresponding to the first pool in the path
    /// @param path The bytes encoded swap path
    /// @return The segment containing all data necessary to target the first pool in the path
    function getFirstPool(bytes memory path) internal pure returns (bytes memory) {
        return path.slice(0, POP_OFFSET);
    }

    /// @notice Skips a token + fee element from the buffer and returns the remainder
    /// @param path The swap path
    /// @return The remaining token + fee elements in the path
    function skipToken(bytes memory path) internal pure returns (bytes memory) {
        return path.slice(NEXT_OFFSET, path.length - NEXT_OFFSET);
    }
}

contract MockSwapRouter {
    using Path for bytes;
    using Math for uint256;

    uint256 public constant EXCHANGE_RATE = 0.95e18;

    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256) {
        ERC20(params.tokenIn).transferFrom(msg.sender, address(this), params.amountIn);

        uint256 amountOut = params.amountIn.mulWadDown(EXCHANGE_RATE);

        uint8 fromDecimals = ERC20(params.tokenIn).decimals();
        uint8 toDecimals = ERC20(params.tokenOut).decimals();
        amountOut = amountOut.changeDecimals(fromDecimals, toDecimals);

        require(amountOut >= params.amountOutMinimum, "amountOutMin invariant failed");

        ERC20(params.tokenOut).transfer(params.recipient, amountOut);
        return amountOut;
    }

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    function exactInput(ExactInputParams memory params) external payable returns (uint256) {
        (address tokenIn, address tokenOut, ) = params.path.decodeFirstPool();

        while (params.path.hasMultiplePools()) {
            params.path = params.path.skipToken();
            (, tokenOut, ) = params.path.decodeFirstPool();
        }

        ERC20(tokenIn).transferFrom(msg.sender, address(this), params.amountIn);

        uint256 amountOut = params.amountIn.mulWadDown(EXCHANGE_RATE);

        uint8 fromDecimals = ERC20(tokenIn).decimals();
        uint8 toDecimals = ERC20(tokenOut).decimals();
        amountOut = amountOut.changeDecimals(fromDecimals, toDecimals);

        require(amountOut >= params.amountOutMinimum, "amountOutMin invariant failed");

        ERC20(tokenOut).transfer(params.recipient, amountOut);
        return amountOut;
    }

    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256
    ) external returns (uint256[] memory) {
        address tokenIn = path[0];
        address tokenOut = path[path.length - 1];

        ERC20(tokenIn).transferFrom(msg.sender, address(this), amountIn);

        uint256 amountOut = amountIn.mulWadDown(EXCHANGE_RATE);

        uint8 fromDecimals = ERC20(tokenIn).decimals();
        uint8 toDecimals = ERC20(tokenOut).decimals();
        amountOut = amountOut.changeDecimals(fromDecimals, toDecimals);

        require(amountOut >= amountOutMin, "amountOutMin invariant failed");

        ERC20(tokenOut).transfer(to, amountOut);

        uint256[] memory amounts = new uint256[](1);
        amounts[0] = amountOut;

        return amounts;
    }

    function exchange_multiple(
        address[9] memory _route,
        uint256[3][4] memory,
        uint256 _amount,
        uint256 _expected
    ) external returns (uint256) {
        address tokenIn = _route[0];

        address tokenOut;
        for (uint256 i; ; i += 2) {
            if (i == 8 || _route[i + 1] == address(0)) {
                tokenOut = _route[i];
                break;
            }
        }

        ERC20(tokenIn).transferFrom(msg.sender, address(this), _amount);

        uint256 amountOut = _amount.mulWadDown(EXCHANGE_RATE);

        uint8 fromDecimals = ERC20(tokenIn).decimals();
        uint8 toDecimals = ERC20(tokenOut).decimals();
        amountOut = amountOut.changeDecimals(fromDecimals, toDecimals);

        require(amountOut >= _expected, "received less than expected");

        ERC20(tokenOut).transfer(msg.sender, amountOut);

        return amountOut;
    }

    function quote(uint256 amountIn, address[] calldata path) external view returns (uint256) {
        address tokenIn = path[0];
        address tokenOut = path[path.length - 1];

        uint256 amountOut = amountIn.mulWadDown(EXCHANGE_RATE);

        uint8 fromDecimals = ERC20(tokenIn).decimals();
        uint8 toDecimals = ERC20(tokenOut).decimals();
        return amountOut.changeDecimals(fromDecimals, toDecimals);
    }

    receive() external payable {}
}

File 21 of 35 : MockERC20WithTransferFee.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { MockERC20 } from "./MockERC20.sol";
import { Math } from "src/utils/Math.sol";

contract MockERC20WithTransferFee is MockERC20 {
    using Math for uint256;

    uint256 public constant transferFee = 0.01e18;

    constructor(string memory _symbol, uint8 _decimals) MockERC20(_symbol, _decimals) {}

    function transfer(address to, uint256 amount) public override returns (bool) {
        balanceOf[msg.sender] -= amount;

        amount -= amount.mulWadDown(transferFee);

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(msg.sender, to, amount);

        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public override returns (bool) {
        uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.

        if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;

        balanceOf[from] -= amount;

        amount -= amount.mulWadDown(transferFee);

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(from, to, amount);

        return true;
    }
}

File 22 of 35 : MockERC20.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC20 } from "lib/solmate/src/tokens/ERC20.sol";

contract MockERC20 is ERC20 {
    constructor(string memory _symbol, uint8 _decimals) ERC20(_symbol, _symbol, _decimals) {}

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

    function burn(address to, uint256 amount) external {
        _burn(to, amount);
    }
}

File 23 of 35 : MockStkAAVE.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { MockERC20 } from "./MockERC20.sol";

contract MockStkAAVE is MockERC20 {
    MockERC20 public immutable AAVE; // AAVE
    uint256 public constant COOLDOWN_SECONDS = 864000; // 10 days
    uint256 public constant UNSTAKE_WINDOW = 172800; // 2 days
    mapping(address => uint256) public stakersCooldowns;

    constructor(MockERC20 _AAVE) MockERC20("stkAAVE", 18) {
        AAVE = _AAVE;
    }

    function cooldown() external {
        require(balanceOf[msg.sender] != 0, "INVALID_BALANCE_ON_COOLDOWN");
        stakersCooldowns[msg.sender] = block.timestamp;
    }

    function redeem(address to, uint256 amount) external {
        require(amount != 0, "INVALID_ZERO_AMOUNT");
        uint256 cooldownStartTimestamp = stakersCooldowns[msg.sender];
        require(block.timestamp > cooldownStartTimestamp + COOLDOWN_SECONDS, "INSUFFICIENT_COOLDOWN");
        require(
            block.timestamp - (cooldownStartTimestamp + COOLDOWN_SECONDS) <= UNSTAKE_WINDOW,
            "UNSTAKE_WINDOW_FINISHED"
        );

        uint256 balanceOfMessageSender = balanceOf[msg.sender];

        uint256 amountToRedeem = amount > balanceOfMessageSender ? balanceOfMessageSender : amount;

        // _updateCurrentUnclaimedRewards(msg.sender, balanceOfMessageSender, true);

        _burn(msg.sender, amountToRedeem);

        if (balanceOfMessageSender - amountToRedeem == 0) stakersCooldowns[msg.sender] = 0;

        AAVE.mint(to, amountToRedeem);
    }
}

File 24 of 35 : MockIncentivesController.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { MockStkAAVE } from "./MockStkAAVE.sol";

contract MockIncentivesController {
    MockStkAAVE public stkAAVE;
    mapping(address => uint256) public usersUnclaimedRewards;

    constructor(MockStkAAVE _stkAAVE) {
        stkAAVE = _stkAAVE;
    }

    /// @dev For testing purposes
    function addRewards(address account, uint256 amount) external {
        usersUnclaimedRewards[account] += amount;
    }

    function claimRewards(
        address[] calldata,
        uint256 amount,
        address to
    ) external returns (uint256) {
        uint256 claimable = usersUnclaimedRewards[to];

        if (amount > claimable) {
            amount = claimable;
        }

        usersUnclaimedRewards[to] -= amount;

        stkAAVE.mint(to, amount);

        return amount;
    }
}

File 25 of 35 : MockERC4626.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC4626 } from "src/base/ERC4626.sol";
import { ERC20 } from "lib/solmate/src/tokens/ERC20.sol";
import { MockERC20 } from "./MockERC20.sol";

contract MockERC4626 is ERC4626 {
    constructor(
        ERC20 _asset,
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) ERC4626(_asset, _name, _symbol, _decimals) {}

    function mint(address to, uint256 value) external {
        _mint(to, value);
    }

    function burn(address from, uint256 value) external {
        _burn(from, value);
    }

    function simulateGain(uint256 assets, address receiver) external returns (uint256 shares) {
        require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES");

        MockERC20(address(asset)).mint(address(this), assets);

        _mint(receiver, shares);
    }

    function simulateLoss(uint256 assets) external {
        MockERC20(address(asset)).burn(address(this), assets);
    }

    function totalAssets() public view override returns (uint256) {
        return asset.balanceOf(address(this));
    }
}

File 26 of 35 : ICellarRouter.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC20 } from "lib/solmate/src/tokens/ERC20.sol";
import { ERC4626 } from "src/base/ERC4626.sol";

interface ICellarRouter {
    // ======================================= ROUTER OPERATIONS =======================================

    function depositIntoCellarWithPermit(
        ERC4626 cellar,
        uint256 assets,
        address receiver,
        uint256 deadline,
        bytes memory signature
    ) external returns (uint256 shares);

    function depositAndSwapIntoCellar(
        ERC4626 cellar,
        address[] calldata path,
        uint24[] calldata poolFees,
        uint256 assets,
        uint256 assetsOutMin,
        address receiver
    ) external returns (uint256 shares);

    function depositAndSwapIntoCellarWithPermit(
        ERC4626 cellar,
        address[] calldata path,
        uint24[] calldata poolFees,
        uint256 assets,
        uint256 assetsOutMin,
        address receiver,
        uint256 deadline,
        bytes memory signature
    ) external returns (uint256 shares);

    function withdrawAndSwapFromCellar(
        ERC4626 cellar,
        address[] calldata path,
        uint24[] calldata poolFees,
        uint256 assets,
        uint256 assetsOutMin,
        address receiver
    ) external returns (uint256 shares);

    function withdrawAndSwapFromCellarWithPermit(
        ERC4626 cellar,
        address[] calldata path,
        uint24[] calldata poolFees,
        uint256 assets,
        uint256 assetsOutMin,
        address receiver,
        uint256 deadline,
        bytes memory signature
    ) external returns (uint256 shares);
}

File 27 of 35 : CellarRouter.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC20 } from "lib/solmate/src/tokens/ERC20.sol";
import { SafeTransferLib } from "lib/solmate/src/utils/SafeTransferLib.sol";
import { ERC4626 } from "./base/ERC4626.sol";
import { Ownable } from "lib/openzeppelin-contracts/contracts/access/Ownable.sol";
import { ISwapRouter as IUniswapV3Router } from "./interfaces/ISwapRouter.sol";
import { IUniswapV2Router02 as IUniswapV2Router } from "./interfaces/IUniswapV2Router02.sol";
import { ICellarRouter } from "./interfaces/ICellarRouter.sol";
import { IGravity } from "./interfaces/IGravity.sol";

import "./Errors.sol";

contract CellarRouter is ICellarRouter, Ownable {
    using SafeTransferLib for ERC20;

    // ========================================== CONSTRUCTOR ==========================================
    /**
     * @notice Uniswap V3 swap router contract. Used for swapping if pool fees are specified.
     */
    IUniswapV3Router public immutable uniswapV3Router; // 0xE592427A0AEce92De3Edee1F18E0157C05861564

    /**
     * @notice Uniswap V2 swap router contract. Used for swapping if pool fees are not specified.
     */
    IUniswapV2Router public immutable uniswapV2Router; // 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D

    /**
     * @param _uniswapV3Router Uniswap V3 swap router address
     * @param _uniswapV2Router Uniswap V2 swap router address
     */
    constructor(
        IUniswapV3Router _uniswapV3Router,
        IUniswapV2Router _uniswapV2Router,
        address owner
    ) {
        uniswapV3Router = _uniswapV3Router;
        uniswapV2Router = _uniswapV2Router;

        // Transfer ownership to the Sommelier multisig.
        transferOwnership(address(owner));
    }

    // ======================================= DEPOSIT OPERATIONS =======================================

    /**
     * @notice Deposit assets into a cellar using permit.
     * @param cellar address of the cellar to deposit into
     * @param assets amount of assets to deposit
     * @param receiver address receiving the shares
     * @param deadline timestamp after which permit is invalid
     * @param signature a valid secp256k1 signature
     * @return shares amount of shares minted
     */
    function depositIntoCellarWithPermit(
        ERC4626 cellar,
        uint256 assets,
        address receiver,
        uint256 deadline,
        bytes memory signature
    ) external returns (uint256 shares) {
        // Retrieve the cellar's current asset.
        ERC20 asset = cellar.asset();

        // Approve the assets from the user to the router via permit.
        (uint8 v, bytes32 r, bytes32 s) = _splitSignature(signature);
        asset.permit(msg.sender, address(this), assets, deadline, v, r, s);

        // Transfer assets from the user to the router.
        asset.safeTransferFrom(msg.sender, address(this), assets);

        // Approve the cellar to spend assets.
        asset.safeApprove(address(cellar), assets);

        // Deposit assets into the cellar.
        shares = cellar.deposit(assets, receiver);
    }

    /**
     * @notice Deposit into a cellar by first performing a swap to the cellar's current asset if necessary.
     * @dev If using Uniswap V3 for swap, must specify the pool fee tier to use for each swap. For
     *      example, if there are "n" addresses in path, there should be "n-1" values specifying the
     *      fee tiers of each pool used for each swap. The current possible pool fee tiers for
     *      Uniswap V3 are 0.01% (100), 0.05% (500), 0.3% (3000), and 1% (10000). If using Uniswap
     *      V2, leave pool fees empty to use Uniswap V2 for swap.
     * @param cellar address of the cellar to deposit into
     * @param path array of [token1, token2, token3] that specifies the swap path on Sushiswap
     * @param poolFees amount out of 1e4 (eg. 10000 == 1%) that represents the fee tier to use for each swap
     * @param assets amount of assets to deposit
     * @param assetsOutMin minimum amount of assets received from swap
     * @param receiver address receiving the shares
     * @return shares amount of shares minted
     */
    function depositAndSwapIntoCellar(
        ERC4626 cellar,
        address[] calldata path,
        uint24[] calldata poolFees,
        uint256 assets,
        uint256 assetsOutMin,
        address receiver
    ) public returns (uint256 shares) {
        // Retrieve the asset being swapped and asset of cellar.
        ERC20 asset = cellar.asset();
        ERC20 assetIn = ERC20(path[0]);

        // Transfer assets from the user to the router.
        assetIn.safeTransferFrom(msg.sender, address(this), assets);

        // Check whether a swap is necessary. If not, skip swap and deposit into cellar directly.
        if (assetIn != asset) assets = _swap(path, poolFees, assets, assetsOutMin);

        // Approve the cellar to spend assets.
        asset.safeApprove(address(cellar), assets);

        // Deposit assets into the cellar.
        shares = cellar.deposit(assets, receiver);
    }

    /**
     * @notice Deposit into a cellar by first performing a swap to the cellar's current asset if necessary.
     * @dev If using Uniswap V3 for swap, must specify the pool fee tier to use for each swap. For
     *      example, if there are "n" addresses in path, there should be "n-1" values specifying the
     *      fee tiers of each pool used for each swap. The current possible pool fee tiers for
     *      Uniswap V3 are 0.01% (100), 0.05% (500), 0.3% (3000), and 1% (10000). If using Uniswap
     *      V2, leave pool fees empty to use Uniswap V2 for swap.
     * @param cellar address of the cellar to deposit into
     * @param path array of [token1, token2, token3] that specifies the swap path on Sushiswap
     * @param poolFees amount out of 1e4 (eg. 10000 == 1%) that represents the fee tier to use for each swap
     * @param assets amount of assets to deposit
     * @param assetsOutMin minimum amount of assets received from swap
     * @param receiver address receiving the shares
     * @param deadline timestamp after which permit is invalid
     * @param signature a valid secp256k1 signature
     * @return shares amount of shares minted
     */
    function depositAndSwapIntoCellarWithPermit(
        ERC4626 cellar,
        address[] calldata path,
        uint24[] calldata poolFees,
        uint256 assets,
        uint256 assetsOutMin,
        address receiver,
        uint256 deadline,
        bytes memory signature
    ) external returns (uint256 shares) {
        // Retrieve the asset being swapped.
        ERC20 assetIn = ERC20(path[0]);

        // Approve for router to burn user shares via permit.
        (uint8 v, bytes32 r, bytes32 s) = _splitSignature(signature);
        assetIn.permit(msg.sender, address(this), assets, deadline, v, r, s);

        // Deposit assets into the cellar using a swap if necessary.
        shares = depositAndSwapIntoCellar(cellar, path, poolFees, assets, assetsOutMin, receiver);
    }

    // ======================================= WITHDRAW OPERATIONS =======================================

    /**
     * @notice Withdraws from a cellar and then performs a swap to another desired asset, if the
     *         withdrawn asset is not already.
     * @dev Permission is required from caller for router to burn shares. Please make sure that
     *      caller has approved the router to spend their shares.
     * @dev If using Uniswap V3 for swap, must specify the pool fee tier to use for each swap. For
     *      example, if there are "n" addresses in path, there should be "n-1" values specifying the
     *      fee tiers of each pool used for each swap. The current possible pool fee tiers for
     *      Uniswap V3 are 0.01% (100), 0.05% (500), 0.3% (3000), and 1% (10000). If using Uniswap
     *      V2, leave pool fees empty to use Uniswap V2 for swap.
     * @param cellar address of the cellar
     * @param path array of [token1, token2, token3] that specifies the swap path on swap
     * @param poolFees amount out of 1e4 (eg. 10000 == 1%) that represents the fee tier to use for each swap
     * @param assets amount of assets to withdraw
     * @param assetsOutMin minimum amount of assets received from swap
     * @param receiver address receiving the assets
     * @return shares amount of shares burned
     */
    function withdrawAndSwapFromCellar(
        ERC4626 cellar,
        address[] calldata path,
        uint24[] calldata poolFees,
        uint256 assets,
        uint256 assetsOutMin,
        address receiver
    ) public returns (uint256 shares) {
        ERC20 asset = cellar.asset();
        ERC20 assetOut = ERC20(path[path.length - 1]);

        // Withdraw assets from the cellar.
        shares = cellar.withdraw(assets, address(this), msg.sender);

        // Check whether a swap is necessary. If not, skip swap and transfer withdrawn assets to receiver.
        if (assetOut != asset) assets = _swap(path, poolFees, assets, assetsOutMin);

        // Transfer assets from the router to the receiver.
        assetOut.safeTransfer(receiver, assets);
    }

    /**
     * @notice Withdraws from a cellar and then performs a swap to another desired asset, if the
     *         withdrawn asset is not already, using permit.
     * @dev If using Uniswap V3 for swap, must specify the pool fee tier to use for each swap. For
     *      example, if there are "n" addresses in path, there should be "n-1" values specifying the
     *      fee tiers of each pool used for each swap. The current possible pool fee tiers for
     *      Uniswap V3 are 0.01% (100), 0.05% (500), 0.3% (3000), and 1% (10000). If using Uniswap
     *      V2, leave pool fees empty to use Uniswap V2 for swap.
     * @param cellar address of the cellar
     * @param path array of [token1, token2, token3] that specifies the swap path on swap
     * @param poolFees amount out of 1e4 (eg. 10000 == 1%) that represents the fee tier to use for each swap
     * @param assets amount of assets to withdraw
     * @param assetsOutMin minimum amount of assets received from swap
     * @param receiver address receiving the assets
     * @param deadline timestamp after which permit is invalid
     * @param signature a valid secp256k1 signature
     * @return shares amount of shares burned
     */
    function withdrawAndSwapFromCellarWithPermit(
        ERC4626 cellar,
        address[] calldata path,
        uint24[] calldata poolFees,
        uint256 assets,
        uint256 assetsOutMin,
        address receiver,
        uint256 deadline,
        bytes memory signature
    ) external returns (uint256 shares) {
        // Approve for router to burn user shares via permit.
        (uint8 v, bytes32 r, bytes32 s) = _splitSignature(signature);
        cellar.permit(msg.sender, address(this), assets, deadline, v, r, s);

        // Withdraw assets from the cellar and swap to another asset if necessary.
        shares = withdrawAndSwapFromCellar(cellar, path, poolFees, assets, assetsOutMin, receiver);
    }

    // ========================================== RECOVERY LOGIC ==========================================

    /**
     * @notice Emitted when tokens accidentally sent to cellar router are recovered.
     * @param token the address of the token
     * @param to the address sweeped tokens were transferred to
     * @param amount amount transferred out
     */
    event Sweep(address indexed token, address indexed to, uint256 amount);

    function sweep(
        ERC20 token,
        address to,
        uint256 amount
    ) external onlyOwner {
        // Transfer out tokens from this cellar router contract that shouldn't be here.
        token.safeTransfer(to, amount);

        emit Sweep(address(token), to, amount);
    }

    // ========================================= HELPER FUNCTIONS =========================================

    /**
     * @notice Split a signature into its components.
     * @param signature a valid secp256k1 signature
     * @return v a component of the secp256k1 signature
     * @return r a component of the secp256k1 signature
     * @return s a component of the secp256k1 signature
     */
    function _splitSignature(bytes memory signature)
        internal
        pure
        returns (
            uint8 v,
            bytes32 r,
            bytes32 s
        )
    {
        if (signature.length != 65) revert USR_InvalidSignature(signature.length, 65);

        // Read each parameter directly from the signature's memory region.
        assembly {
            // Place first word on the stack at r.
            r := mload(add(signature, 32))

            // Place second word on the stack at s.
            s := mload(add(signature, 64))

            // Place final byte on the stack at v.
            v := byte(0, mload(add(signature, 96)))
        }
    }

    /**
     * @notice Perform a swap using Uniswap.
     * @dev If using Uniswap V3 for swap, must specify the pool fee tier to use for each swap. For
     *      example, if there are "n" addresses in path, there should be "n-1" values specifying the
     *      fee tiers of each pool used for each swap. The current possible pool fee tiers for
     *      Uniswap V3 are 0.01% (100), 0.05% (500), 0.3% (3000), and 1% (10000). If using Uniswap
     *      V2, leave pool fees empty to use Uniswap V2 for swap.
     * @param path array of [token1, token2, token3] that specifies the swap path on swap
     * @param poolFees amount out of 1e4 (eg. 10000 == 1%) that represents the fee tier to use for each swap
     * @param assets amount of assets to withdraw
     * @param assetsOutMin minimum amount of assets received from swap
     * @return assetsOut amount of assets received after swap
     */
    function _swap(
        address[] calldata path,
        uint24[] calldata poolFees,
        uint256 assets,
        uint256 assetsOutMin
    ) internal returns (uint256 assetsOut) {
        // Retrieve the asset being swapped.
        ERC20 assetIn = ERC20(path[0]);

        // Check whether to use Uniswap V2 or Uniswap V3 for swap.
        if (poolFees.length == 0) {
            // If no pool fees are specified, use Uniswap V2 for swap.

            // Approve assets to be swapped through the router.
            assetIn.safeApprove(address(uniswapV2Router), assets);

            // Execute the swap.
            uint256[] memory amountsOut = uniswapV2Router.swapExactTokensForTokens(
                assets,
                assetsOutMin,
                path,
                address(this),
                block.timestamp + 60
            );

            assetsOut = amountsOut[amountsOut.length - 1];
        } else {
            // If pool fees are specified, use Uniswap V3 for swap.

            // Approve assets to be swapped through the router.
            assetIn.safeApprove(address(uniswapV3Router), assets);

            // Encode swap parameters.
            bytes memory encodePackedPath = abi.encodePacked(address(assetIn));
            for (uint256 i = 1; i < path.length; i++)
                encodePackedPath = abi.encodePacked(encodePackedPath, poolFees[i - 1], path[i]);

            // Execute the swap.
            assetsOut = uniswapV3Router.exactInput(
                IUniswapV3Router.ExactInputParams({
                    path: encodePackedPath,
                    recipient: address(this),
                    deadline: block.timestamp + 60,
                    amountIn: assets,
                    amountOutMinimum: assetsOutMin
                })
            );
        }
    }
}

File 28 of 35 : ISwapRouter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;
}

/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}

File 29 of 35 : IUniswapV2Router02.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.0;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);

    function WETH() external pure 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 removeLiquidityETH(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountToken, uint256 amountETH);

    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETHWithPermit(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountToken, uint256 amountETH);

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

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

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

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

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

    function quote(
        uint256 amountA,
        uint256 reserveA,
        uint256 reserveB
    ) external pure returns (uint256 amountB);

    function getAmountOut(
        uint256 amountIn,
        uint256 reserveIn,
        uint256 reserveOut
    ) external pure returns (uint256 amountOut);

    function getAmountIn(
        uint256 amountOut,
        uint256 reserveIn,
        uint256 reserveOut
    ) external pure returns (uint256 amountIn);

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

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountETH);

    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;

    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable;

    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;
}

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

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.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 ERC20 is Context, IERC20, IERC20Metadata {
    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.
     */
    constructor(string memory name_, string memory symbol_) {
        _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 {}
}

File 31 of 35 : 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 32 of 35 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @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 33 of 35 : MockAToken.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC20 } from "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import { MockLendingPool } from "./MockLendingPool.sol";
import { Math } from "src/utils/Math.sol";

library WadRayMath {
    uint256 public constant RAY = 1e27;
    uint256 public constant HALF_RAY = RAY / 2;

    /**
     * @dev Divides two ray, rounding half up to the nearest ray
     * @param a Ray
     * @param b Ray
     * @return The result of a/b, in ray
     **/
    function rayDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b != 0, "cannot divide by zero");
        uint256 halfB = b / 2;

        require(a <= (type(uint256).max - halfB) / RAY, "math multiplication overflow");

        return (a * RAY + halfB) / b;
    }

    /**
     * @dev Multiplies two ray, rounding down to the nearest ray
     * @param a Ray
     * @param b Ray
     * @return The result of a*b, in ray
     **/
    function rayMul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0 || b == 0) return 0;

        require(a <= (type(uint256).max - HALF_RAY) / b, "math multiplication overflow");

        return (a * b + HALF_RAY) / RAY;
    }
}

contract MockAToken is ERC20 {
    address public underlyingAsset;
    MockLendingPool public lendingPool;

    constructor(
        address _lendingPool,
        address _underlyingAsset,
        string memory _symbol
    ) ERC20(_symbol, _symbol) {
        lendingPool = MockLendingPool(_lendingPool);
        underlyingAsset = _underlyingAsset;
    }

    function decimals() public view override returns (uint8) {
        return ERC20(underlyingAsset).decimals();
    }

    function mint(address user, uint256 amount) external {
        uint256 amountScaled = WadRayMath.rayDiv(amount, lendingPool.index());
        require(amountScaled != 0, "CT_INVALID_MINT_AMOUNT");
        _mint(user, amountScaled);
    }

    function burn(address user, uint256 amount) external {
        uint256 amountScaled = WadRayMath.rayDiv(amount, lendingPool.index());
        require(amountScaled != 0, "CT_INVALID_BURN_AMOUNT");
        _burn(user, amountScaled);
    }

    /**
     * @dev Mints aTokens to `user`
     * - Only callable by the LendingPool, as extra state updates there need to be managed
     * @param user The address receiving the minted tokens
     * @param amount The amount of tokens getting minted
     * @param index The new liquidity index of the reserve
     * @return `true` if the the previous balance of the user was 0
     */
    function mint(
        address user,
        uint256 amount,
        uint256 index
    ) external returns (bool) {
        uint256 previousBalance = super.balanceOf(user);

        uint256 amountScaled = WadRayMath.rayDiv(amount, index);
        require(amountScaled != 0, "CT_INVALID_MINT_AMOUNT");
        _mint(user, amountScaled);

        return previousBalance == 0;
    }

    /**
     * @dev Burns aTokens from `user` and sends the equivalent amount of underlying to `receiverOfUnderlying`
     * - Only callable by the LendingPool, as extra state updates there need to be managed
     * @param user The owner of the aTokens, getting them burned
     * @param receiverOfUnderlying The address that will receive the underlying
     * @param amount The amount being burned
     * @param index The new liquidity index of the reserve
     */
    function burn(
        address user,
        address receiverOfUnderlying,
        uint256 amount,
        uint256 index
    ) external {
        uint256 amountScaled = WadRayMath.rayDiv(amount, index);
        require(amountScaled != 0, "CT_INVALID_BURN_AMOUNT");
        _burn(user, amountScaled);

        ERC20(underlyingAsset).transfer(receiverOfUnderlying, amount);
    }

    /**
     * @dev Calculates the balance of the user: principal balance + interest generated by the principal
     * @param user The user whose balance is calculated
     * @return The balance of the user
     **/
    function balanceOf(address user) public view override returns (uint256) {
        return WadRayMath.rayMul(super.balanceOf(user), lendingPool.index());
    }

    /**
     * @dev Returns the scaled balance of the user. The scaled balance is the sum of all the
     * updated stored balance divided by the reserve's liquidity index at the moment of the update
     * @param user The user whose balance is calculated
     * @return The scaled balance of the user
     **/
    function scaledBalanceOf(address user) external view returns (uint256) {
        return super.balanceOf(user);
    }
}

File 34 of 35 : MockLendingPool.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC20 } from "lib/solmate/src/tokens/ERC20.sol";
import { MockAToken } from "./MockAToken.sol";

contract MockLendingPool {
    mapping(address => address) public aTokens;
    uint256 public index = 1000000000000000000000000000;

    constructor() {}

    // for testing purposes; not in actual contract
    function setLiquidityIndex(uint256 _index) external {
        index = _index;
    }

    function deposit(
        address asset,
        uint256 amount,
        address onBehalfOf,
        uint16
    ) external {
        ERC20(asset).transferFrom(onBehalfOf, aTokens[asset], amount);
        MockAToken(aTokens[asset]).mint(onBehalfOf, amount, index);
    }

    function withdraw(
        address asset,
        uint256 amount,
        address to
    ) external returns (uint256) {
        if (amount == type(uint256).max) amount = MockAToken(aTokens[asset]).balanceOf(msg.sender);

        MockAToken(aTokens[asset]).burn(msg.sender, to, amount, index);

        return amount;
    }

    function getReserveData(address asset)
        external
        view
        returns (
            uint256 configuration,
            uint128 liquidityIndex,
            uint128 variableBorrowIndex,
            uint128 currentLiquidityRate,
            uint128 currentVariableBorrowRate,
            uint128 currentStableBorrowRate,
            uint40 lastUpdateTimestamp,
            address aTokenAddress,
            address stableDebtTokenAddress,
            address variableDebtTokenAddress,
            address interestRateStrategyAddress,
            uint8 id
        )
    {
        asset;
        configuration;
        liquidityIndex = uint128(index);
        variableBorrowIndex;
        currentLiquidityRate;
        currentVariableBorrowRate;
        currentStableBorrowRate;
        lastUpdateTimestamp;
        aTokenAddress = aTokens[asset];
        stableDebtTokenAddress;
        variableDebtTokenAddress;
        interestRateStrategyAddress;
        id;
    }

    function getReserveNormalizedIncome(address) external view returns (uint256) {
        return index;
    }

    function initReserve(address asset, address aTokenAddress) external {
        aTokens[asset] = aTokenAddress;
    }
}

File 35 of 35 : MockGravity.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.15;

import { ERC20 } from "lib/solmate/src/tokens/ERC20.sol";
import { SafeTransferLib } from "lib/solmate/src/utils/SafeTransferLib.sol";

contract MockGravity {
    using SafeTransferLib for ERC20;
    error InvalidSendToCosmos();

    function sendToCosmos(
        address _tokenContract,
        bytes32,
        uint256 _amount
    ) external {
        // we snapshot our current balance of this token
        uint256 ourStartingBalance = ERC20(_tokenContract).balanceOf(address(this));

        // attempt to transfer the user specified amount
        ERC20(_tokenContract).safeTransferFrom(msg.sender, address(this), _amount);

        // check what this particular ERC20 implementation actually gave us, since it doesn't
        // have to be at all related to the _amount
        uint256 ourEndingBalance = ERC20(_tokenContract).balanceOf(address(this));

        // a very strange ERC20 may trigger this condition, if we didn't have this we would
        // underflow, so it's mostly just an error message printer
        if (ourEndingBalance <= ourStartingBalance) {
            revert InvalidSendToCosmos();
        }
    }

    receive() external payable {}
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200,
    "details": {
      "yul": true,
      "yulDetails": {
        "stackAllocation": true
      }
    }
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract ERC20","name":"_asset","type":"address"},{"internalType":"contract ERC20[]","name":"_approvedPositions","type":"address[]"},{"internalType":"contract ICurveSwaps","name":"_curveRegistryExchange","type":"address"},{"internalType":"contract ISushiSwapRouter","name":"_sushiswapRouter","type":"address"},{"internalType":"contract ILendingPool","name":"_lendingPool","type":"address"},{"internalType":"contract IAaveIncentivesController","name":"_incentivesController","type":"address"},{"internalType":"contract IGravity","name":"_gravityBridge","type":"address"},{"internalType":"contract IStakedTokenV2","name":"_stkAAVE","type":"address"},{"internalType":"contract ERC20","name":"_AAVE","type":"address"},{"internalType":"contract ERC20","name":"_WETH","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"STATE_AccrualOngoing","type":"error"},{"inputs":[{"internalType":"address","name":"assetWithFeeOnTransfer","type":"address"}],"name":"STATE_AssetUsesFeeOnTransfer","type":"error"},{"inputs":[],"name":"STATE_ContractShutdown","type":"error"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"maxDeposit","type":"uint256"}],"name":"USR_DepositRestricted","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"USR_ProtectedAsset","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"USR_SamePosition","type":"error"},{"inputs":[{"internalType":"uint8","name":"newDecimals","type":"uint8"},{"internalType":"uint8","name":"maxDecimals","type":"uint8"}],"name":"USR_TooManyDecimals","type":"error"},{"inputs":[{"internalType":"address","name":"unsupportedPosition","type":"address"}],"name":"USR_UnsupportedPosition","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"USR_UntrustedPosition","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"platformFees","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"performanceFees","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"yield","type":"uint256"}],"name":"Accrual","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"oldPeriod","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"newPeriod","type":"uint32"}],"name":"AccrualPeriodChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rewards","type":"uint256"}],"name":"ClaimAndUnstake","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"DepositIntoPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldLimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"DepositLimitChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"EnterPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"ExitPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"oldFeesDistributor","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"newFeesDistributor","type":"bytes32"}],"name":"FeesDistributorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldLimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"LiquidityLimitChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPerformanceFee","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPerformanceFee","type":"uint64"}],"name":"PerformanceFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPlatformFee","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPlatformFee","type":"uint64"}],"name":"PlatformFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldAsset","type":"address"},{"indexed":true,"internalType":"address","name":"newAsset","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"Rebalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"rewards","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"Reinvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feesInSharesRedeemed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feesInAssetsSent","type":"uint256"}],"name":"SendFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"emptyPositions","type":"bool"}],"name":"ShutdownInitiated","type":"event"},{"anonymous":false,"inputs":[],"name":"ShutdownLifted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Sweep","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"bool","name":"trusted","type":"bool"}],"name":"TrustChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"WithdrawFromPosition","type":"event"},{"inputs":[],"name":"AAVE","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accrualPeriod","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accrue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"assetAToken","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"assetDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimAndUnstake","outputs":[{"internalType":"uint256","name":"rewards","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"curveRegistryExchange","outputs":[{"internalType":"contract ICurveSwaps","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enterPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"enterPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"exitPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"exitPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feesDistributor","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gravityBridge","outputs":[{"internalType":"contract IGravity","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"highWatermarkBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"incentivesController","outputs":[{"internalType":"contract IAaveIncentivesController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"emptyPosition","type":"bool"}],"name":"initiateShutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isShutdown","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"name":"isTrusted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastAccrual","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lendingPool","outputs":[{"internalType":"contract ILendingPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liftShutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"liquidityLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxLocked","outputs":[{"internalType":"uint160","name":"","type":"uint160"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"performanceFee","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"platformFee","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[9]","name":"route","type":"address[9]"},{"internalType":"uint256[3][4]","name":"swapParams","type":"uint256[3][4]"},{"internalType":"uint256","name":"minAssetsOut","type":"uint256"}],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minAssetsOut","type":"uint256"}],"name":"reinvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sendFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"newAccrualPeriod","type":"uint32"}],"name":"setAccrualPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"setDepositLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"newFeesDistributor","type":"bytes32"}],"name":"setFeesDistributor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"setLiquidityLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"position","type":"address"},{"internalType":"bool","name":"trust","type":"bool"}],"name":"setTrust","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stkAAVE","outputs":[{"internalType":"contract IStakedTokenV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sushiswapRouter","outputs":[{"internalType":"contract ISushiSwapRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"}],"name":"sweep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalHoldings","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalLocked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]

6101e0604052600a805463ffffffff191662093a8017905573b813554b423266bbd4c16c32fa383394868c1f55600c553480156200003c57600080fd5b5060405162005786380380620057868339810160408190526200005f9162000701565b896040518060600160405280602c81526020016200575a602c913960408051808201909152600b81526a61617665322d434c522d5360a81b602082015260128282826000620000af848262000918565b506001620000be838262000918565b5060ff81166080524660a052620000d462000251565b60c0525050600680546001600160a01b0319166001600160a01b039690961695909517909455506200011292503391506200010c9050565b620002ed565b6001600160a01b0380891660e05287811661010052868116610120528581166101405284811661016052838116610180528281166101a0528181166101c0528a166000908152600d60205260408120805460ff19166001179055620001778b6200033f565b905060006200018882600a62000af9565b90506200019981624c4b4062000b0a565b600e55600019600f5560005b8b5181101562000211576001600d60008e8481518110620001ca57620001ca62000b2c565b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff191691151591909117905580620002088162000b42565b915050620001a5565b50600a8054600160201b600160601b0319164263ffffffff16640100000000021790556200023f8662000572565b50505050505050505050505062000d64565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f600060405162000285919062000b5e565b6040805191829003822060208301939093528101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b600780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b610120516040516335ea6a7560e01b81526001600160a01b03838116600483015260009283929116906335ea6a759060240161018060405180830381865afa15801562000390573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003b6919062000c06565b50929a50506001600160a01b038a169850620003fe97505050505050505057604051630a5c5e7d60e11b81526001600160a01b03841660048201526024015b60405180910390fd5b6000600860149054906101000a900460ff169050836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000451573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000477919062000cfd565b925060128360ff161115620004ac57604051630651982f60e11b815260ff8416600482015260126024820152604401620003f5565b60ff811615801590620004c557508260ff168160ff1614155b156200052857600f54600e546000198214620004fb57620004f78386846200064360201b6200328c179092919060201c565b600f555b60001981146200052557620005218386836200064360201b6200328c179092919060201c565b600e555b50505b50600680546001600160a01b03199081166001600160a01b0395861617909155600880546001600160a81b031916600160a01b60ff86160290921691909117919093161790915590565b6007546001600160a01b03163314620005ce5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401620003f5565b6001600160a01b038116620006355760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401620003f5565b6200064081620002ed565b50565b60008160ff168360ff16036200065b575082620006bc565b8160ff168360ff161015620006975762000676838362000d1b565b6200068390600a62000af9565b6200068f908562000b0a565b9050620006bc565b620006a3828462000d1b565b620006b090600a62000af9565b6200068f908562000d41565b9392505050565b6001600160a01b03811681146200064057600080fd5b8051620006e681620006c3565b919050565b634e487b7160e01b600052604160045260246000fd5b6000806000806000806000806000806101408b8d0312156200072257600080fd5b8a516200072f81620006c3565b60208c0151909a506001600160401b03808211156200074d57600080fd5b818d0191508d601f8301126200076257600080fd5b815181811115620007775762000777620006eb565b604051601f19603f8360051b0116810181811084821117156200079e576200079e620006eb565b6040528181526020808201935060059290921b8401909101908f821115620007c557600080fd5b6020840193505b81841015620007f257620007e084620006d9565b835260209384019390920191620007cc565b9b50620008069250505060408c01620006d9565b97506200081660608c01620006d9565b96506200082660808c01620006d9565b95506200083660a08c01620006d9565b94506200084660c08c01620006d9565b93506200085660e08c01620006d9565b9250620008676101008c01620006d9565b9150620008786101208c01620006d9565b90509295989b9194979a5092959850565b600181811c908216806200089e57607f821691505b602082108103620008bf57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200091357600081815260208120601f850160051c81016020861015620008ee5750805b601f850160051c820191505b818110156200090f57828155600101620008fa565b5050505b505050565b81516001600160401b03811115620009345762000934620006eb565b6200094c8162000945845462000889565b84620008c5565b602080601f8311600181146200098457600084156200096b5750858301515b600019600386901b1c1916600185901b1785556200090f565b600085815260208120601f198616915b82811015620009b55788860151825594840194600190910190840162000994565b5085821015620009d45787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b600181815b8085111562000a3b57816000190482111562000a1f5762000a1f620009e4565b8085161562000a2d57918102915b93841c9390800290620009ff565b509250929050565b60008262000a545750600162000af3565b8162000a635750600062000af3565b816001811462000a7c576002811462000a875762000aa7565b600191505062000af3565b60ff84111562000a9b5762000a9b620009e4565b50506001821b62000af3565b5060208310610133831016604e8410600b841016171562000acc575081810a62000af3565b62000ad88383620009fa565b806000190482111562000aef5762000aef620009e4565b0290505b92915050565b6000620006bc60ff84168362000a43565b600081600019048311821515161562000b275762000b27620009e4565b500290565b634e487b7160e01b600052603260045260246000fd5b60006001820162000b575762000b57620009e4565b5060010190565b600080835462000b6e8162000889565b6001828116801562000b89576001811462000b9f5762000bd0565b60ff198416875282151583028701945062000bd0565b8760005260208060002060005b8581101562000bc75781548a82015290840190820162000bac565b50505082870194505b50929695505050505050565b80516001600160801b0381168114620006e657600080fd5b805160ff81168114620006e657600080fd5b6000806000806000806000806000806000806101808d8f03121562000c2a57600080fd5b8c519b5062000c3c60208e0162000bdc565b9a5062000c4c60408e0162000bdc565b995062000c5c60608e0162000bdc565b985062000c6c60808e0162000bdc565b975062000c7c60a08e0162000bdc565b965060c08d015164ffffffffff8116811462000c9757600080fd5b955062000ca760e08e01620006d9565b945062000cb86101008e01620006d9565b935062000cc96101208e01620006d9565b925062000cda6101408e01620006d9565b915062000ceb6101608e0162000bf4565b90509295989b509295989b509295989b565b60006020828403121562000d1057600080fd5b620006bc8262000bf4565b600060ff821660ff84168082101562000d385762000d38620009e4565b90039392505050565b60008262000d5f57634e487b7160e01b600052601260045260246000fd5b500490565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c0516148f162000e6960003960008181610a2b0152611c3601526000818161067e01528181611b3701528181611be20152611cb801526000818161052f01528181611abc015281816122e6015261251401526000818161093a01528181612c9c0152612cf2015260008181610a75015261226201526000818161096e01528181613371015281816134cc015281816136d2015261372a015260008181610cfd01528181611cda0152611d0b0152600081816109c2015281816111c401526112030152600061149301526000611463015260006105ce01526148f16000f3fe6080604052600436106104265760003560e01c80639972921611610229578063c2d416011161012e578063dff90b5b116100b6578063ef7ac8831161007a578063ef7ac88314610d6a578063ef8b30f714610d8a578063f2fde38b14610daa578063f666415514610dca578063f8ba4cff14610dfc57600080fd5b8063dff90b5b14610cd6578063e9240c2d14610ceb578063e9ec2e9914610d1f578063ecf7085814610d34578063ef465d9214610d4a57600080fd5b8063ce96cb77116100fd578063ce96cb7714610c08578063d505accf14610c28578063d905777e14610c48578063dd62ed3e14610c7e578063df05a52a14610cb657600080fd5b8063c2d4160114610b87578063c63d75b614610ba8578063c6e6f59214610bc8578063cab5923814610be857600080fd5b8063af1df255116101b1578063ba08765211610180578063ba08765214610af7578063bdc8144b14610b17578063bf86d69014610b37578063c17f674014610b51578063c28c0abe14610b7157600080fd5b8063af1df25514610a63578063b3d7f6b914610a97578063b460af9414610ab7578063b8dc491b14610ad757600080fd5b8063ac353510116101f8578063ac353510146109b0578063ac9650d8146109e4578063ad004e2014610a04578063ad5c464814610a19578063ad7a672f14610a4d57600080fd5b80639972921614610913578063a4da2d0214610928578063a59a99731461095c578063a9059cbb1461099057600080fd5b80635e2c576e1161032f5780637ecebe00116102b75780638e0bae7f116102865780638e0bae7f146108715780638fdc9dfa1461088757806394bf804d146108ae57806395d89b41146108ce57806396d64879146108e357600080fd5b80637ecebe00146107ea57806383b4918b1461081757806387788782146108375780638da5cb5b1461085357600080fd5b806370a08231116102fe57806370a082311461074a578063715018a614610777578063721637151461078c57806378dc9059146107a25780637b3baab4146107c257600080fd5b80635e2c576e146106d55780636e08406b146106ea5780636e553f651461070a5780636e85f1831461072a57600080fd5b806326232a2e116103b25780633dc6eabf116103815780633dc6eabf14610637578063402d267d1461064c57806348ccda3c1461066c5780634cdad506146106a057806356891412146106c057600080fd5b806326232a2e14610589578063313ce567146105bc5780633644e5151461060257806338d52e0f1461061757600080fd5b80630a28a477116103f95780630a28a477146104c557806315f4c611146104e557806318160ddd146105075780631fc29c011461051d57806323b872dd1461056957600080fd5b806301e1d1141461042b57806306fdde031461045357806307a2d13a14610475578063095ea7b314610495575b600080fd5b34801561043757600080fd5b50610440610e11565b6040519081526020015b60405180910390f35b34801561045f57600080fd5b50610468610e3f565b60405161044a9190613c88565b34801561048157600080fd5b50610440610490366004613c9b565b610ecd565b3480156104a157600080fd5b506104b56104b0366004613cc9565b610f13565b604051901515815260200161044a565b3480156104d157600080fd5b506104406104e0366004613c9b565b610f80565b3480156104f157600080fd5b50610505610500366004613da8565b610fba565b005b34801561051357600080fd5b5061044060025481565b34801561052957600080fd5b506105517f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161044a565b34801561057557600080fd5b506104b5610584366004613eb2565b61137f565b34801561059557600080fd5b506105a46608e1bc9bf0400081565b6040516001600160401b03909116815260200161044a565b3480156105c857600080fd5b506105f07f000000000000000000000000000000000000000000000000000000000000000081565b60405160ff909116815260200161044a565b34801561060e57600080fd5b5061044061145f565b34801561062357600080fd5b50600654610551906001600160a01b031681565b34801561064357600080fd5b506105056114b5565b34801561065857600080fd5b50610440610667366004613ef3565b6114c2565b34801561067857600080fd5b506105517f000000000000000000000000000000000000000000000000000000000000000081565b3480156106ac57600080fd5b506104406106bb366004613c9b565b611526565b3480156106cc57600080fd5b50610440611531565b3480156106e157600080fd5b506105056115ac565b3480156106f657600080fd5b50610505610705366004613c9b565b61160b565b34801561071657600080fd5b50610440610725366004613f10565b6116ed565b34801561073657600080fd5b50610505610745366004613c9b565b6118fa565b34801561075657600080fd5b50610440610765366004613ef3565b60036020526000908152604090205481565b34801561078357600080fd5b50610505611965565b34801561079857600080fd5b50610440600e5481565b3480156107ae57600080fd5b506105056107bd366004613c9b565b611999565b3480156107ce57600080fd5b50600a546105a49064010000000090046001600160401b031681565b3480156107f657600080fd5b50610440610805366004613ef3565b60056020526000908152604090205481565b34801561082357600080fd5b50610505610832366004613c9b565b611a75565b34801561084357600080fd5b506105a467016345785d8a000081565b34801561085f57600080fd5b506007546001600160a01b0316610551565b34801561087d57600080fd5b50610440600c5481565b34801561089357600080fd5b50600a5461055190600160601b90046001600160a01b031681565b3480156108ba57600080fd5b506104406108c9366004613f10565b611e37565b3480156108da57600080fd5b50610468611ff9565b3480156108ef57600080fd5b506104b56108fe366004613ef3565b600d6020526000908152604090205460ff1681565b34801561091f57600080fd5b50610505612006565b34801561093457600080fd5b506105517f000000000000000000000000000000000000000000000000000000000000000081565b34801561096857600080fd5b506105517f000000000000000000000000000000000000000000000000000000000000000081565b34801561099c57600080fd5b506104b56109ab366004613cc9565b612011565b3480156109bc57600080fd5b506105517f000000000000000000000000000000000000000000000000000000000000000081565b6109f76109f2366004613f40565b612077565b60405161044a9190613fb4565b348015610a1057600080fd5b506104406121ce565b348015610a2557600080fd5b506105517f000000000000000000000000000000000000000000000000000000000000000081565b348015610a5957600080fd5b5061044060095481565b348015610a6f57600080fd5b506105517f000000000000000000000000000000000000000000000000000000000000000081565b348015610aa357600080fd5b50610440610ab2366004613c9b565b612394565b348015610ac357600080fd5b50610440610ad2366004614016565b6123b3565b348015610ae357600080fd5b50610505610af2366004614058565b6124a6565b348015610b0357600080fd5b50610440610b12366004614016565b612644565b348015610b2357600080fd5b50610505610b32366004613c9b565b612775565b348015610b4357600080fd5b506010546104b59060ff1681565b348015610b5d57600080fd5b50600854610551906001600160a01b031681565b348015610b7d57600080fd5b50610440600b5481565b348015610b9357600080fd5b506008546105f090600160a01b900460ff1681565b348015610bb457600080fd5b50610440610bc3366004613ef3565b6127e0565b348015610bd457600080fd5b50610440610be3366004613c9b565b61283d565b348015610bf457600080fd5b50610505610c0336600461409b565b61285d565b348015610c1457600080fd5b50610440610c23366004613ef3565b61291d565b348015610c3457600080fd5b50610505610c433660046140df565b61293f565b348015610c5457600080fd5b50610440610c63366004613ef3565b6001600160a01b031660009081526003602052604090205490565b348015610c8a57600080fd5b50610440610c99366004614058565b600460209081526000928352604080842090915290825290205481565b348015610cc257600080fd5b50610505610cd1366004613c9b565b612b83565b348015610ce257600080fd5b50610505612bee565b348015610cf757600080fd5b506105517f000000000000000000000000000000000000000000000000000000000000000081565b348015610d2b57600080fd5b50610440612d8f565b348015610d4057600080fd5b50610440600f5481565b348015610d5657600080fd5b50610505610d65366004614150565b612dfc565b348015610d7657600080fd5b50610505610d8536600461416b565b612eb1565b348015610d9657600080fd5b50610440610da5366004613c9b565b612f64565b348015610db657600080fd5b50610505610dc5366004613ef3565b612f6f565b348015610dd657600080fd5b50600a54610de79063ffffffff1681565b60405163ffffffff909116815260200161044a565b348015610e0857600080fd5b5061050561300a565b6000610e1b611531565b610e23612d8f565b600954610e3091906141a7565b610e3a91906141bf565b905090565b60008054610e4c906141d6565b80601f0160208091040260200160405190810160405280929190818152602001828054610e78906141d6565b8015610ec55780601f10610e9a57610100808354040283529160200191610ec5565b820191906000526020600020905b815481529060010190602001808311610ea857829003601f168201915b505050505081565b6002546000908015610ef157610eec610ee4610e11565b8490836132f5565b610f0c565b600854610f0c908490601290600160a01b900460ff1661328c565b9392505050565b3360008181526004602090815260408083206001600160a01b038716808552925280832085905551919290917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590610f6e9086815260200190565b60405180910390a35060015b92915050565b6002546000908015610fa057610eec81610f98610e11565b859190613314565b600854610f0c908490600160a01b900460ff16601261328c565b60105460ff1615610fde57604051632f22819760e11b815260040160405180910390fd5b6007546001600160a01b031633146110115760405162461bcd60e51b815260040161100890614210565b60405180910390fd5b6000805b806008148061104d575060008561102d8360016141a7565b6009811061103d5761103d614245565b60200201516001600160a01b0316145b156110705784816009811061106457611064614245565b60200201519150611082565b61107b6002826141a7565b9050611015565b506001600160a01b0381166000908152600d602052604090205460ff166110c7576040516386433f2b60e01b81526001600160a01b0382166004820152602401611008565b6006546001600160a01b0390811690821681900361110357604051630613aecf60e11b81526001600160a01b0382166004820152602401611008565b600061110d612d8f565b905060008160095461111f91906141a7565b6008546040516370a0823160e01b815230600482015291925060009182916001600160a01b0316906370a0823190602401602060405180830381865afa15801561116d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611191919061425b565b1161119c57826111b3565b826111a985600019613342565b6111b391906141a7565b90506111e96001600160a01b0385167f00000000000000000000000000000000000000000000000000000000000000008361342b565b604051630d4f290960e21b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063353ca4249061123e908c908c9087908d90600401614274565b6020604051808303816000875af115801561125d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611281919061425b565b600854909150600160a01b900460ff16600061129c886134a8565b90506112a888846136c3565b600a546112c690600160601b90046001600160a01b0316838361328c565b600a80546001600160a01b0392909216600160601b026bffffffffffffffffffffffff909216919091179055600061130861130287858561328c565b856137c1565b90508060098190555061132b838389600b5461132491906141a7565b919061328c565b600b556040518181526001600160a01b03808b1691908a16907fb0850b8e0f9e8315dde3c9f9f31138283e6bbe16cd29e8552eb1dcdf9fac9e3b9060200160405180910390a3505050505050505050505050565b6001600160a01b038316600090815260046020908152604080832033845290915281205460001981146113db576113b683826141bf565b6001600160a01b03861660009081526004602090815260408083203384529091529020555b6001600160a01b038516600090815260036020526040812080548592906114039084906141bf565b90915550506001600160a01b038085166000818152600360205260409081902080548701905551909187169060008051602061489c8339815191529061144c9087815260200190565b60405180910390a3506001949350505050565b60007f0000000000000000000000000000000000000000000000000000000000000000461461149057610e3a6137d7565b507f000000000000000000000000000000000000000000000000000000000000000090565b6114c0610705612d8f565b565b60105460009060ff16156114d857506000919050565b600f54600e54600019821480156114f0575060001981145b1561150057506000199392505050565b60008061150e848488613871565b9150915061151c82826137c1565b9695505050505050565b6000610f7a82610ecd565b600a546000906001600160401b036401000000008204169063ffffffff1661155981836141a7565b42106115685760009250505090565b600a54600160601b90046001600160a01b03168161158684426141bf565b6115909083614310565b61159a919061432f565b6115a490826141bf565b935050505090565b6007546001600160a01b031633146115d65760405162461bcd60e51b815260040161100890614210565b6010805460ff191690556040517f09bec6199b5712abe9cbb71997b06f6149a453eca5abec15d528e14e65e1605e90600090a1565b60105460ff161561162f57604051632f22819760e11b815260040160405180910390fd5b6007546001600160a01b031633146116595760405162461bcd60e51b815260040161100890614210565b600654600980546001600160a01b039092169183919060009061167d9084906141a7565b9250508190555081600b600082825461169691906141a7565b909155506116a6905081836136c3565b806001600160a01b03167fb6f4b9255ee989b1844a8e6b7da8906b81200c38f7b3f4f1ac31e9a241c75750836040516116e191815260200190565b60405180910390a25050565b6000806116f9836114c2565b905080841115611726576040516323dc290560e21b81526004810185905260248101829052604401611008565b61172f84612f64565b91508160000361176f5760405162461bcd60e51b815260206004820152600b60248201526a5a45524f5f53484152455360a81b6044820152606401611008565b6006546040516370a0823160e01b81523060048201526001600160a01b039091169060009082906370a0823190602401602060405180830381865afa1580156117bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117e0919061425b565b6006549091506117fb906001600160a01b0316333089613953565b6040516370a0823160e01b815230600482015260009082906001600160a01b038516906370a0823190602401602060405180830381865afa158015611844573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611868919061425b565b61187291906141bf565b905086811461189f57604051632901b09360e11b81526001600160a01b0384166004820152602401611008565b6118a986866139dd565b60408051888152602081018790526001600160a01b0388169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d791015b60405180910390a35050505092915050565b6007546001600160a01b031633146119245760405162461bcd60e51b815260040161100890614210565b600c5460408051918252602082018390527f513ac19cbbaaad4e450c732ed37635178b7d83bf8e84a940ffe7e052c9c7caa2910160405180910390a1600c55565b6007546001600160a01b0316331461198f5760405162461bcd60e51b815260040161100890614210565b6114c06000613a37565b60105460ff16156119bd57604051632f22819760e11b815260040160405180910390fd5b6007546001600160a01b031633146119e75760405162461bcd60e51b815260040161100890614210565b6006546001600160a01b031660006119ff8284613342565b90508060096000828254611a1391906141bf565b9250508190555080600b6000828254611a2c91906141bf565b90915550506040518381526001600160a01b038316907fde4cc1d2dd41970a827a8df55efd18c527c17c26485847d680cc2b4c71e7a87c906020015b60405180910390a2505050565b6007546001600160a01b03163314611a9f5760405162461bcd60e51b815260040161100890614210565b6040516301e9a69560e41b815230600482015260001960248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690631e9a695090604401600060405180830381600087803b158015611b0857600080fd5b505af1158015611b1c573d6000803e3d6000fd5b50506040516370a0823160e01b8152306004820152600092507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031691506370a0823190602401602060405180830381865afa158015611b87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bab919061425b565b600654604080516003808252608082019092529293506001600160a01b0390911691600091602082016060803683370190505090507f000000000000000000000000000000000000000000000000000000000000000081600081518110611c1457611c14614245565b60200260200101906001600160a01b031690816001600160a01b0316815250507f000000000000000000000000000000000000000000000000000000000000000081600181518110611c6857611c68614245565b60200260200101906001600160a01b031690816001600160a01b0316815250508181600281518110611c9c57611c9c614245565b6001600160a01b039283166020918202929092010152611cff907f0000000000000000000000000000000000000000000000000000000000000000167f00000000000000000000000000000000000000000000000000000000000000008561342b565b60006001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000166338ed173985878530611d3f42603c6141a7565b6040518663ffffffff1660e01b8152600401611d5f959493929190614395565b6000604051808303816000875af1158015611d7e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611da691908101906143d1565b905060008160018351611db991906141bf565b81518110611dc957611dc9614245565b602090810291909101015160105490915060ff16611deb57611deb84826136c3565b60408051868152602081018390526001600160a01b038616917fc003f45bc224d116b6d079100d4ab57a5b9633244c47a5a92a176c5b79a85f28910160405180910390a2505050505050565b6000611e4283612394565b90506000611e4f836114c2565b905080821115611e7c576040516323dc290560e21b81526004810183905260248101829052604401611008565b6006546040516370a0823160e01b81523060048201526001600160a01b039091169060009082906370a0823190602401602060405180830381865afa158015611ec9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eed919061425b565b600654909150611f08906001600160a01b0316333087613953565b6040516370a0823160e01b815230600482015260009082906001600160a01b038516906370a0823190602401602060405180830381865afa158015611f51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f75919061425b565b611f7f91906141bf565b9050848114611fac57604051632901b09360e11b81526001600160a01b0384166004820152602401611008565b611fb686886139dd565b60408051868152602081018990526001600160a01b0388169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d791016118e8565b60018054610e4c906141d6565b6114c0600954611999565b336000908152600360205260408120805483919083906120329084906141bf565b90915550506001600160a01b0383166000818152600360205260409081902080548501905551339060008051602061489c83398151915290610f6e9086815260200190565b6060816001600160401b0381111561209157612091613cf5565b6040519080825280602002602001820160405280156120c457816020015b60608152602001906001900390816120af5790505b50905060005b828110156121c757600080308686858181106120e8576120e8614245565b90506020028101906120fa9190614476565b6040516121089291906144c3565b600060405180830381855af49150503d8060008114612143576040519150601f19603f3d011682016040523d82523d6000602084013e612148565b606091505b5091509150816121945760448151101561216157600080fd5b6004810190508080602001905181019061217b91906144d3565b60405162461bcd60e51b81526004016110089190613c88565b808484815181106121a7576121a7614245565b6020026020010181905250505080806121bf90614566565b9150506120ca565b5092915050565b6007546000906001600160a01b031633146121fb5760405162461bcd60e51b815260040161100890614210565b60408051600180825281830190925260009160208083019080368337505060085482519293506001600160a01b03169183915060009061223d5761223d614245565b6001600160a01b039283166020918202929092010152604051633111e7b360e01b81527f000000000000000000000000000000000000000000000000000000000000000090911690633111e7b39061229f90849060001990309060040161457f565b6020604051808303816000875af11580156122be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122e2919061425b565b91507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663787a08a66040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561233f57600080fd5b505af1158015612353573d6000803e3d6000fd5b505050507f8ca0188d9770b383d1a7a2ddfe5e0c1f029084481a53697d6c51525c47a8d88e8260405161238891815260200190565b60405180910390a15090565b6002546000908015610ef157610eec6123ab610e11565b849083613314565b60006123be84610f80565b9050336001600160a01b0383161461242e576001600160a01b0382166000908152600460209081526040808320338452909152902054600019811461242c5761240782826141bf565b6001600160a01b03841660009081526004602090815260408083203384529091529020555b505b61243a84828585613a89565b6124448282613afa565b60408051858152602081018390526001600160a01b03808516929086169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a4600654610eec906001600160a01b03168486613b5c565b6007546001600160a01b031633146124d05760405162461bcd60e51b815260040161100890614210565b6006546001600160a01b03838116911614806124f957506008546001600160a01b038381169116145b8061250c57506001600160a01b03821630145b8061254857507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316145b15612571576040516339b8549160e01b81526001600160a01b0383166004820152602401611008565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa1580156125b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125dc919061425b565b90506125f26001600160a01b0384168383613b5c565b816001600160a01b0316836001600160a01b03167fed679328aebf74ede77ae09efcf36e90244f83643dadac1c2d9f0b21a46f6ab78360405161263791815260200190565b60405180910390a3505050565b6000336001600160a01b038316146126b4576001600160a01b038216600090815260046020908152604080832033845290915290205460001981146126b25761268d85826141bf565b6001600160a01b03841660009081526004602090815260408083203384529091529020555b505b6126bd84611526565b9050806000036126fd5760405162461bcd60e51b815260206004820152600b60248201526a5a45524f5f41535345545360a81b6044820152606401611008565b61270981858585613a89565b6127138285613afa565b60408051828152602081018690526001600160a01b03808516929086169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a4600654610eec906001600160a01b03168483613b5c565b6007546001600160a01b0316331461279f5760405162461bcd60e51b815260040161100890614210565b600f5460408051918252602082018390527fcfb5a454b8aa7dc04ecb5bc1410b2a57969ca1d67f66d565196f60c6f9975404910160405180910390a1600f55565b60105460009060ff16156127f657506000919050565b600f54600e546000198214801561280e575060001981145b1561281e57506000199392505050565b60008061282c848488613871565b9150915061151c610be383836137c1565b6002546000908015610fa057610eec81612855610e11565b8591906132f5565b6007546001600160a01b031633146128875760405162461bcd60e51b815260040161100890614210565b6001600160a01b038281166000908152600d60205260409020805460ff191683158015918217909255600654909216916128d25750806001600160a01b0316836001600160a01b0316145b156128e0576128e081613bd4565b826001600160a01b03167fd600b9348603c6deff34b4e0b28b60e1c8036c806741b9e6d90032e7f37dd27f83604051611a68911515815260200190565b6001600160a01b038116600090815260036020526040812054610f7a90610ecd565b4284101561298f5760405162461bcd60e51b815260206004820152601760248201527f5045524d49545f444541444c494e455f455850495245440000000000000000006044820152606401611008565b6000600161299b61145f565b6001600160a01b038a811660008181526005602090815260409182902080546001810190915582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98184015280840194909452938d166060840152608083018c905260a083019390935260c08083018b90528151808403909101815260e08301909152805192019190912061190160f01b6101008301526101028201929092526101228101919091526101420160408051601f198184030181528282528051602091820120600084529083018083525260ff871690820152606081018590526080810184905260a0016020604051602081039080840390855afa158015612aa7573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811615801590612add5750876001600160a01b0316816001600160a01b0316145b612b1a5760405162461bcd60e51b815260206004820152600e60248201526d24a72b20a624a22fa9a4a3a722a960911b6044820152606401611008565b6001600160a01b0390811660009081526004602090815260408083208a8516808552908352928190208990555188815291928a16917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a350505050505050565b6007546001600160a01b03163314612bad5760405162461bcd60e51b815260040161100890614210565b600e5460408051918252602082018390527f1f21432dd7b8ead64d2e7c06a74baf13783b2d2f7153f099e2c4cabc3c5dbec6910160405180910390a1600e55565b6007546001600160a01b03163314612c185760405162461bcd60e51b815260040161100890614210565b3060009081526003602052604081205490612c3282611526565b905080600003612c725760405162461bcd60e51b815260206004820152600b60248201526a5a45524f5f41535345545360a81b6044820152606401611008565b612c80816000806000613a89565b612c8a3083613afa565b6006546001600160a01b0316612cc1817f00000000000000000000000000000000000000000000000000000000000000008461342b565b600c54604051631ffbe7f960e01b81526001600160a01b0383811660048301526024820192909252604481018490527f000000000000000000000000000000000000000000000000000000000000000090911690631ffbe7f990606401600060405180830381600087803b158015612d3857600080fd5b505af1158015612d4c573d6000803e3d6000fd5b505060408051868152602081018690527f15e3e2a76a6839c244c1ed0a821c233ce8af552dffcb856089eae6cbbbb71ea6935001905060405180910390a1505050565b6006546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015612dd8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e3a919061425b565b60105460ff1615612e2057604051632f22819760e11b815260040160405180910390fd5b6007546001600160a01b03163314612e4a5760405162461bcd60e51b815260040161100890614210565b8015612e6557600654612e65906001600160a01b0316613bd4565b6010805460ff191660011790556040517f6e7cab6accf9b093a6b800ed920df610db4dbfd8807417f5f2c48dd66c03babb90612ea690831515815260200190565b60405180910390a150565b6007546001600160a01b03163314612edb5760405162461bcd60e51b815260040161100890614210565b6000612ee5611531565b1115612f0457604051636b86639360e11b815260040160405180910390fd5b600a546040805163ffffffff928316815291831660208301527f3c392b44ad99b1fb7c87ae7b914cbd1de1aeed3e9369a20d3070cc771669898f910160405180910390a1600a805463ffffffff191663ffffffff92909216919091179055565b6000610f7a8261283d565b6007546001600160a01b03163314612f995760405162461bcd60e51b815260040161100890614210565b6001600160a01b038116612ffe5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401611008565b61300781613a37565b50565b6000613014611531565b90506130286007546001600160a01b031690565b6001600160a01b0316336001600160a01b0316141580156130495750600081115b1561306757604051636b86639360e11b815260040160405180910390fd5b60085460009061308290600160a01b900460ff16600a614696565b9050600061308f8261283d565b6008546040516370a0823160e01b81523060048201529192506000916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156130dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613101919061425b565b600a549091506000906131259064010000000090046001600160401b0316426141bf565b905060006301e13380670de0b6b3a76400006608e1bc9bf040006131498587614310565b6131539190614310565b61315d919061432f565b613167919061432f565b905060006131768286886132f5565b9050600061318f600b5486613c0190919063ffffffff16565b905060006131a58267016345785d8a0000613c1b565b905060006131b482898b6132f5565b90506131c9306131c483876141a7565b6139dd565b6131dd6131d683876141a7565b8490613c01565b6131e7908b6141a7565b600a805464010000000063ffffffff428116919091026bffffffffffffffff00000000196001600160a01b0395909516600160601b02949094169116179190911790556009879055600b5487111561323f57600b8790555b60408051858152602081018390529081018490527ffd23cefb4992bc1b95df1f544efdb9908d901288354421270f7a8f8a0dfec20a9060600160405180910390a150505050505050505050565b60008160ff168360ff16036132a2575082610f0c565b8160ff168360ff1610156132d6576132ba83836146a5565b6132c590600a614696565b6132cf9085614310565b9050610f0c565b6132e082846146a5565b6132eb90600a614696565b6132cf908561432f565b82820281151584158583048514171661330d57600080fd5b0492915050565b82820281151584158583048514171661332c57600080fd5b6001826001830304018115150290509392505050565b604051631a4ca37b60e21b81526001600160a01b038381166004830152602482018390523060448301526000917f0000000000000000000000000000000000000000000000000000000000000000909116906369328dec906064016020604051808303816000875af11580156133bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133e0919061425b565b9050826001600160a01b03167f84343cc97621dbc51bce198a258218a2063c160e4d473ff51007c7a60eec5fa18260405161341d91815260200190565b60405180910390a292915050565b600060405163095ea7b360e01b8152836004820152826024820152602060006044836000895af13d15601f3d11600160005114161716915050806134a25760405162461bcd60e51b815260206004820152600e60248201526d1054141493d59157d1905253115160921b6044820152606401611008565b50505050565b6040516335ea6a7560e01b81526001600160a01b03828116600483015260009182917f000000000000000000000000000000000000000000000000000000000000000016906335ea6a759060240161018060405180830381865afa158015613514573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061353891906146fe565b50929a50506001600160a01b038a16985061357a97505050505050505057604051630a5c5e7d60e11b81526001600160a01b0384166004820152602401611008565b6000600860149054906101000a900460ff169050836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156135cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135f091906147df565b925060128360ff16111561362357604051630651982f60e11b815260ff8416600482015260126024820152604401611008565b60ff81161580159061363b57508260ff168160ff1614155b1561367957600f54600e54600019821461365e5761365a82848761328c565b600f555b60001981146136765761367281848761328c565b600e555b50505b50600680546001600160a01b03199081166001600160a01b0395861617909155600880546001600160a81b031916600160a01b60ff86160290921691909117919093161790915590565b6136f76001600160a01b0383167f00000000000000000000000000000000000000000000000000000000000000008361342b565b60405163e8eda9df60e01b81526001600160a01b03838116600483015260248201839052306044830152600060648301527f0000000000000000000000000000000000000000000000000000000000000000169063e8eda9df90608401600060405180830381600087803b15801561376e57600080fd5b505af1158015613782573d6000803e3d6000fd5b50505050816001600160a01b03167ff099efd56d0c64f9a1aa1379a470d871392b67ea7678ed5659ad4bfe7dd76575826040516116e191815260200190565b60008183106137d05781610f0c565b5090919050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f600060405161380991906147fc565b6040805191829003822060208301939093528101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b600080600061387e612d8f565b6008546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa1580156138c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138ea919061425b565b6138f491906141a7565b6001600160a01b0385166000908152600360205260408120546002549293509190811561392b576139268385846132f5565b61392d565b825b90506139398982613c01565b95506139458885613c01565b945050505050935093915050565b60006040516323b872dd60e01b81528460048201528360248201528260448201526020600060648360008a5af13d15601f3d11600160005114161716915050806139d65760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606401611008565b5050505050565b80600260008282546139ef91906141a7565b90915550506001600160a01b03821660008181526003602090815260408083208054860190555184815260008051602061489c83398151915291015b60405180910390a35050565b600780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6006546001600160a01b03166000613a9f612d8f565b905080861115613af2576000613abe83613ab9848a6141bf565b613342565b90508060096000828254613ad291906141bf565b9250508190555080600b6000828254613aeb91906141bf565b9091555050505b505050505050565b6001600160a01b03821660009081526003602052604081208054839290613b229084906141bf565b90915550506002805482900390556040518181526000906001600160a01b0384169060008051602061489c83398151915290602001613a2b565b600060405163a9059cbb60e01b8152836004820152826024820152602060006044836000895af13d15601f3d11600160005114161716915050806134a25760405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b6044820152606401611008565b6009548015613bfd57613be561300a565b613bf182600019613342565b5060006009819055600b555b5050565b6000818311613c11576000610f0c565b610f0c82846141bf565b6000610f0c8383670de0b6b3a76400006132f5565b60005b83811015613c4b578181015183820152602001613c33565b838111156134a25750506000910152565b60008151808452613c74816020860160208601613c30565b601f01601f19169290920160200192915050565b602081526000610f0c6020830184613c5c565b600060208284031215613cad57600080fd5b5035919050565b6001600160a01b038116811461300757600080fd5b60008060408385031215613cdc57600080fd5b8235613ce781613cb4565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b60405161012081016001600160401b0381118282101715613d2e57613d2e613cf5565b60405290565b604051608081016001600160401b0381118282101715613d2e57613d2e613cf5565b604051606081016001600160401b0381118282101715613d2e57613d2e613cf5565b604051601f8201601f191681016001600160401b0381118282101715613da057613da0613cf5565b604052919050565b60008060006102c08486031215613dbe57600080fd5b601f8581860112613dce57600080fd5b613dd6613d0b565b80610120870188811115613de957600080fd5b875b81811015613e0c578035613dfe81613cb4565b845260209384019301613deb565b508196508861013f890112613e2057600080fd5b613e28613d34565b92508291506102a0880189811115613e3f57600080fd5b80821015613ea2578985830112613e565760008081fd5b613e5e613d56565b80606084018c811115613e715760008081fd5b845b81811015613e8b578035845260209384019301613e73565b505085525060209093019260609190910190613e3f565b9699919850509435955050505050565b600080600060608486031215613ec757600080fd5b8335613ed281613cb4565b92506020840135613ee281613cb4565b929592945050506040919091013590565b600060208284031215613f0557600080fd5b8135610f0c81613cb4565b60008060408385031215613f2357600080fd5b823591506020830135613f3581613cb4565b809150509250929050565b60008060208385031215613f5357600080fd5b82356001600160401b0380821115613f6a57600080fd5b818501915085601f830112613f7e57600080fd5b813581811115613f8d57600080fd5b8660208260051b8501011115613fa257600080fd5b60209290920196919550909350505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561400957603f19888603018452613ff7858351613c5c565b94509285019290850190600101613fdb565b5092979650505050505050565b60008060006060848603121561402b57600080fd5b83359250602084013561403d81613cb4565b9150604084013561404d81613cb4565b809150509250925092565b6000806040838503121561406b57600080fd5b823561407681613cb4565b91506020830135613f3581613cb4565b8035801515811461409657600080fd5b919050565b600080604083850312156140ae57600080fd5b82356140b981613cb4565b91506140c760208401614086565b90509250929050565b60ff8116811461300757600080fd5b600080600080600080600060e0888a0312156140fa57600080fd5b873561410581613cb4565b9650602088013561411581613cb4565b955060408801359450606088013593506080880135614133816140d0565b9699959850939692959460a0840135945060c09093013592915050565b60006020828403121561416257600080fd5b610f0c82614086565b60006020828403121561417d57600080fd5b813563ffffffff81168114610f0c57600080fd5b634e487b7160e01b600052601160045260246000fd5b600082198211156141ba576141ba614191565b500190565b6000828210156141d1576141d1614191565b500390565b600181811c908216806141ea57607f821691505b60208210810361420a57634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561426d57600080fd5b5051919050565b6102e08101818660005b60098110156142a65781516001600160a01b031683526020928301929091019060010161427e565b50505061012082018560005b60048110156142f95781518360005b60038110156142e05782518252602092830192909101906001016142c1565b50505060609290920191602091909101906001016142b2565b5050506102a08201939093526102c0015292915050565b600081600019048311821515161561432a5761432a614191565b500290565b60008261434c57634e487b7160e01b600052601260045260246000fd5b500490565b600081518084526020808501945080840160005b8381101561438a5781516001600160a01b031687529582019590820190600101614365565b509495945050505050565b85815284602082015260a0604082015260006143b460a0830186614351565b6001600160a01b0394909416606083015250608001529392505050565b600060208083850312156143e457600080fd5b82516001600160401b03808211156143fb57600080fd5b818501915085601f83011261440f57600080fd5b81518181111561442157614421613cf5565b8060051b9150614432848301613d78565b818152918301840191848101908884111561444c57600080fd5b938501935b8385101561446a57845182529385019390850190614451565b98975050505050505050565b6000808335601e1984360301811261448d57600080fd5b8301803591506001600160401b038211156144a757600080fd5b6020019150368190038213156144bc57600080fd5b9250929050565b8183823760009101908152919050565b6000602082840312156144e557600080fd5b81516001600160401b03808211156144fc57600080fd5b818401915084601f83011261451057600080fd5b81518181111561452257614522613cf5565b614535601f8201601f1916602001613d78565b915080825285602082850101111561454c57600080fd5b61455d816020840160208601613c30565b50949350505050565b60006001820161457857614578614191565b5060010190565b6060815260006145926060830186614351565b6020830194909452506001600160a01b0391909116604090910152919050565b600181815b808511156145ed5781600019048211156145d3576145d3614191565b808516156145e057918102915b93841c93908002906145b7565b509250929050565b60008261460457506001610f7a565b8161461157506000610f7a565b816001811461462757600281146146315761464d565b6001915050610f7a565b60ff84111561464257614642614191565b50506001821b610f7a565b5060208310610133831016604e8410600b8410161715614670575081810a610f7a565b61467a83836145b2565b806000190482111561468e5761468e614191565b029392505050565b6000610f0c60ff8416836145f5565b600060ff821660ff8416808210156146bf576146bf614191565b90039392505050565b80516fffffffffffffffffffffffffffffffff8116811461409657600080fd5b805161409681613cb4565b8051614096816140d0565b6000806000806000806000806000806000806101808d8f03121561472157600080fd5b8c519b5061473160208e016146c8565b9a5061473f60408e016146c8565b995061474d60608e016146c8565b985061475b60808e016146c8565b975061476960a08e016146c8565b965060c08d015164ffffffffff8116811461478357600080fd5b955061479160e08e016146e8565b94506147a06101008e016146e8565b93506147af6101208e016146e8565b92506147be6101408e016146e8565b91506147cd6101608e016146f3565b90509295989b509295989b509295989b565b6000602082840312156147f157600080fd5b8151610f0c816140d0565b600080835481600182811c91508083168061481857607f831692505b6020808410820361483757634e487b7160e01b86526022600452602486fd5b81801561484b57600181146148605761488d565b60ff198616895284151585028901965061488d565b60008a81526020902060005b868110156148855781548b82015290850190830161486c565b505084890196505b50949897505050505050505056feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220bc3ca6867b9d04038523b6f26f10f12ab9cd2bdf7af0ea5702822bf20301306264736f6c634300080f0033536f6d6d656c696572204161766520563220537461626c65636f696e2043656c6c6172204c5020546f6b656e000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000014000000000000000000000000081c46feca27b31f3adc2b91ee4be9717d1cd3dd7000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a9000000000000000000000000d784927ff2f95ba542bfc824c8a8a98f3495f6b500000000000000000000000069592e6f9d21989a043646fe8225da2600e5a0f70000000000000000000000004da27a545c0c5b758a6ba100e3a049001de870f50000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000008000000000000000000000000056fd409e1d7a124bd7017459dfea2f387b6d5cd0000000000000000000000004fabb145d64652a948d72533023f6e7a623c7c53000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000956f47f50a910163d8bf957cf5846d573e7f87ca000000000000000000000000853d955acef822db058eb8505911ed77f175b99e00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f510000000000000000000000008e870d67f660d95d5be530380d0ec0bd388289e1

Deployed Bytecode

0x6080604052600436106104265760003560e01c80639972921611610229578063c2d416011161012e578063dff90b5b116100b6578063ef7ac8831161007a578063ef7ac88314610d6a578063ef8b30f714610d8a578063f2fde38b14610daa578063f666415514610dca578063f8ba4cff14610dfc57600080fd5b8063dff90b5b14610cd6578063e9240c2d14610ceb578063e9ec2e9914610d1f578063ecf7085814610d34578063ef465d9214610d4a57600080fd5b8063ce96cb77116100fd578063ce96cb7714610c08578063d505accf14610c28578063d905777e14610c48578063dd62ed3e14610c7e578063df05a52a14610cb657600080fd5b8063c2d4160114610b87578063c63d75b614610ba8578063c6e6f59214610bc8578063cab5923814610be857600080fd5b8063af1df255116101b1578063ba08765211610180578063ba08765214610af7578063bdc8144b14610b17578063bf86d69014610b37578063c17f674014610b51578063c28c0abe14610b7157600080fd5b8063af1df25514610a63578063b3d7f6b914610a97578063b460af9414610ab7578063b8dc491b14610ad757600080fd5b8063ac353510116101f8578063ac353510146109b0578063ac9650d8146109e4578063ad004e2014610a04578063ad5c464814610a19578063ad7a672f14610a4d57600080fd5b80639972921614610913578063a4da2d0214610928578063a59a99731461095c578063a9059cbb1461099057600080fd5b80635e2c576e1161032f5780637ecebe00116102b75780638e0bae7f116102865780638e0bae7f146108715780638fdc9dfa1461088757806394bf804d146108ae57806395d89b41146108ce57806396d64879146108e357600080fd5b80637ecebe00146107ea57806383b4918b1461081757806387788782146108375780638da5cb5b1461085357600080fd5b806370a08231116102fe57806370a082311461074a578063715018a614610777578063721637151461078c57806378dc9059146107a25780637b3baab4146107c257600080fd5b80635e2c576e146106d55780636e08406b146106ea5780636e553f651461070a5780636e85f1831461072a57600080fd5b806326232a2e116103b25780633dc6eabf116103815780633dc6eabf14610637578063402d267d1461064c57806348ccda3c1461066c5780634cdad506146106a057806356891412146106c057600080fd5b806326232a2e14610589578063313ce567146105bc5780633644e5151461060257806338d52e0f1461061757600080fd5b80630a28a477116103f95780630a28a477146104c557806315f4c611146104e557806318160ddd146105075780631fc29c011461051d57806323b872dd1461056957600080fd5b806301e1d1141461042b57806306fdde031461045357806307a2d13a14610475578063095ea7b314610495575b600080fd5b34801561043757600080fd5b50610440610e11565b6040519081526020015b60405180910390f35b34801561045f57600080fd5b50610468610e3f565b60405161044a9190613c88565b34801561048157600080fd5b50610440610490366004613c9b565b610ecd565b3480156104a157600080fd5b506104b56104b0366004613cc9565b610f13565b604051901515815260200161044a565b3480156104d157600080fd5b506104406104e0366004613c9b565b610f80565b3480156104f157600080fd5b50610505610500366004613da8565b610fba565b005b34801561051357600080fd5b5061044060025481565b34801561052957600080fd5b506105517f0000000000000000000000004da27a545c0c5b758a6ba100e3a049001de870f581565b6040516001600160a01b03909116815260200161044a565b34801561057557600080fd5b506104b5610584366004613eb2565b61137f565b34801561059557600080fd5b506105a46608e1bc9bf0400081565b6040516001600160401b03909116815260200161044a565b3480156105c857600080fd5b506105f07f000000000000000000000000000000000000000000000000000000000000001281565b60405160ff909116815260200161044a565b34801561060e57600080fd5b5061044061145f565b34801561062357600080fd5b50600654610551906001600160a01b031681565b34801561064357600080fd5b506105056114b5565b34801561065857600080fd5b50610440610667366004613ef3565b6114c2565b34801561067857600080fd5b506105517f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae981565b3480156106ac57600080fd5b506104406106bb366004613c9b565b611526565b3480156106cc57600080fd5b50610440611531565b3480156106e157600080fd5b506105056115ac565b3480156106f657600080fd5b50610505610705366004613c9b565b61160b565b34801561071657600080fd5b50610440610725366004613f10565b6116ed565b34801561073657600080fd5b50610505610745366004613c9b565b6118fa565b34801561075657600080fd5b50610440610765366004613ef3565b60036020526000908152604090205481565b34801561078357600080fd5b50610505611965565b34801561079857600080fd5b50610440600e5481565b3480156107ae57600080fd5b506105056107bd366004613c9b565b611999565b3480156107ce57600080fd5b50600a546105a49064010000000090046001600160401b031681565b3480156107f657600080fd5b50610440610805366004613ef3565b60056020526000908152604090205481565b34801561082357600080fd5b50610505610832366004613c9b565b611a75565b34801561084357600080fd5b506105a467016345785d8a000081565b34801561085f57600080fd5b506007546001600160a01b0316610551565b34801561087d57600080fd5b50610440600c5481565b34801561089357600080fd5b50600a5461055190600160601b90046001600160a01b031681565b3480156108ba57600080fd5b506104406108c9366004613f10565b611e37565b3480156108da57600080fd5b50610468611ff9565b3480156108ef57600080fd5b506104b56108fe366004613ef3565b600d6020526000908152604090205460ff1681565b34801561091f57600080fd5b50610505612006565b34801561093457600080fd5b506105517f00000000000000000000000069592e6f9d21989a043646fe8225da2600e5a0f781565b34801561096857600080fd5b506105517f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a981565b34801561099c57600080fd5b506104b56109ab366004613cc9565b612011565b3480156109bc57600080fd5b506105517f00000000000000000000000081c46feca27b31f3adc2b91ee4be9717d1cd3dd781565b6109f76109f2366004613f40565b612077565b60405161044a9190613fb4565b348015610a1057600080fd5b506104406121ce565b348015610a2557600080fd5b506105517f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b348015610a5957600080fd5b5061044060095481565b348015610a6f57600080fd5b506105517f000000000000000000000000d784927ff2f95ba542bfc824c8a8a98f3495f6b581565b348015610aa357600080fd5b50610440610ab2366004613c9b565b612394565b348015610ac357600080fd5b50610440610ad2366004614016565b6123b3565b348015610ae357600080fd5b50610505610af2366004614058565b6124a6565b348015610b0357600080fd5b50610440610b12366004614016565b612644565b348015610b2357600080fd5b50610505610b32366004613c9b565b612775565b348015610b4357600080fd5b506010546104b59060ff1681565b348015610b5d57600080fd5b50600854610551906001600160a01b031681565b348015610b7d57600080fd5b50610440600b5481565b348015610b9357600080fd5b506008546105f090600160a01b900460ff1681565b348015610bb457600080fd5b50610440610bc3366004613ef3565b6127e0565b348015610bd457600080fd5b50610440610be3366004613c9b565b61283d565b348015610bf457600080fd5b50610505610c0336600461409b565b61285d565b348015610c1457600080fd5b50610440610c23366004613ef3565b61291d565b348015610c3457600080fd5b50610505610c433660046140df565b61293f565b348015610c5457600080fd5b50610440610c63366004613ef3565b6001600160a01b031660009081526003602052604090205490565b348015610c8a57600080fd5b50610440610c99366004614058565b600460209081526000928352604080842090915290825290205481565b348015610cc257600080fd5b50610505610cd1366004613c9b565b612b83565b348015610ce257600080fd5b50610505612bee565b348015610cf757600080fd5b506105517f000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f81565b348015610d2b57600080fd5b50610440612d8f565b348015610d4057600080fd5b50610440600f5481565b348015610d5657600080fd5b50610505610d65366004614150565b612dfc565b348015610d7657600080fd5b50610505610d8536600461416b565b612eb1565b348015610d9657600080fd5b50610440610da5366004613c9b565b612f64565b348015610db657600080fd5b50610505610dc5366004613ef3565b612f6f565b348015610dd657600080fd5b50600a54610de79063ffffffff1681565b60405163ffffffff909116815260200161044a565b348015610e0857600080fd5b5061050561300a565b6000610e1b611531565b610e23612d8f565b600954610e3091906141a7565b610e3a91906141bf565b905090565b60008054610e4c906141d6565b80601f0160208091040260200160405190810160405280929190818152602001828054610e78906141d6565b8015610ec55780601f10610e9a57610100808354040283529160200191610ec5565b820191906000526020600020905b815481529060010190602001808311610ea857829003601f168201915b505050505081565b6002546000908015610ef157610eec610ee4610e11565b8490836132f5565b610f0c565b600854610f0c908490601290600160a01b900460ff1661328c565b9392505050565b3360008181526004602090815260408083206001600160a01b038716808552925280832085905551919290917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590610f6e9086815260200190565b60405180910390a35060015b92915050565b6002546000908015610fa057610eec81610f98610e11565b859190613314565b600854610f0c908490600160a01b900460ff16601261328c565b60105460ff1615610fde57604051632f22819760e11b815260040160405180910390fd5b6007546001600160a01b031633146110115760405162461bcd60e51b815260040161100890614210565b60405180910390fd5b6000805b806008148061104d575060008561102d8360016141a7565b6009811061103d5761103d614245565b60200201516001600160a01b0316145b156110705784816009811061106457611064614245565b60200201519150611082565b61107b6002826141a7565b9050611015565b506001600160a01b0381166000908152600d602052604090205460ff166110c7576040516386433f2b60e01b81526001600160a01b0382166004820152602401611008565b6006546001600160a01b0390811690821681900361110357604051630613aecf60e11b81526001600160a01b0382166004820152602401611008565b600061110d612d8f565b905060008160095461111f91906141a7565b6008546040516370a0823160e01b815230600482015291925060009182916001600160a01b0316906370a0823190602401602060405180830381865afa15801561116d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611191919061425b565b1161119c57826111b3565b826111a985600019613342565b6111b391906141a7565b90506111e96001600160a01b0385167f00000000000000000000000081c46feca27b31f3adc2b91ee4be9717d1cd3dd78361342b565b604051630d4f290960e21b81526000906001600160a01b037f00000000000000000000000081c46feca27b31f3adc2b91ee4be9717d1cd3dd7169063353ca4249061123e908c908c9087908d90600401614274565b6020604051808303816000875af115801561125d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611281919061425b565b600854909150600160a01b900460ff16600061129c886134a8565b90506112a888846136c3565b600a546112c690600160601b90046001600160a01b0316838361328c565b600a80546001600160a01b0392909216600160601b026bffffffffffffffffffffffff909216919091179055600061130861130287858561328c565b856137c1565b90508060098190555061132b838389600b5461132491906141a7565b919061328c565b600b556040518181526001600160a01b03808b1691908a16907fb0850b8e0f9e8315dde3c9f9f31138283e6bbe16cd29e8552eb1dcdf9fac9e3b9060200160405180910390a3505050505050505050505050565b6001600160a01b038316600090815260046020908152604080832033845290915281205460001981146113db576113b683826141bf565b6001600160a01b03861660009081526004602090815260408083203384529091529020555b6001600160a01b038516600090815260036020526040812080548592906114039084906141bf565b90915550506001600160a01b038085166000818152600360205260409081902080548701905551909187169060008051602061489c8339815191529061144c9087815260200190565b60405180910390a3506001949350505050565b60007f0000000000000000000000000000000000000000000000000000000000000001461461149057610e3a6137d7565b507ff610a354a8e45bf8248dbaf7e909eb211e64aa694c433bdffc2be3b0ecd5041b90565b6114c0610705612d8f565b565b60105460009060ff16156114d857506000919050565b600f54600e54600019821480156114f0575060001981145b1561150057506000199392505050565b60008061150e848488613871565b9150915061151c82826137c1565b9695505050505050565b6000610f7a82610ecd565b600a546000906001600160401b036401000000008204169063ffffffff1661155981836141a7565b42106115685760009250505090565b600a54600160601b90046001600160a01b03168161158684426141bf565b6115909083614310565b61159a919061432f565b6115a490826141bf565b935050505090565b6007546001600160a01b031633146115d65760405162461bcd60e51b815260040161100890614210565b6010805460ff191690556040517f09bec6199b5712abe9cbb71997b06f6149a453eca5abec15d528e14e65e1605e90600090a1565b60105460ff161561162f57604051632f22819760e11b815260040160405180910390fd5b6007546001600160a01b031633146116595760405162461bcd60e51b815260040161100890614210565b600654600980546001600160a01b039092169183919060009061167d9084906141a7565b9250508190555081600b600082825461169691906141a7565b909155506116a6905081836136c3565b806001600160a01b03167fb6f4b9255ee989b1844a8e6b7da8906b81200c38f7b3f4f1ac31e9a241c75750836040516116e191815260200190565b60405180910390a25050565b6000806116f9836114c2565b905080841115611726576040516323dc290560e21b81526004810185905260248101829052604401611008565b61172f84612f64565b91508160000361176f5760405162461bcd60e51b815260206004820152600b60248201526a5a45524f5f53484152455360a81b6044820152606401611008565b6006546040516370a0823160e01b81523060048201526001600160a01b039091169060009082906370a0823190602401602060405180830381865afa1580156117bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117e0919061425b565b6006549091506117fb906001600160a01b0316333089613953565b6040516370a0823160e01b815230600482015260009082906001600160a01b038516906370a0823190602401602060405180830381865afa158015611844573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611868919061425b565b61187291906141bf565b905086811461189f57604051632901b09360e11b81526001600160a01b0384166004820152602401611008565b6118a986866139dd565b60408051888152602081018790526001600160a01b0388169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d791015b60405180910390a35050505092915050565b6007546001600160a01b031633146119245760405162461bcd60e51b815260040161100890614210565b600c5460408051918252602082018390527f513ac19cbbaaad4e450c732ed37635178b7d83bf8e84a940ffe7e052c9c7caa2910160405180910390a1600c55565b6007546001600160a01b0316331461198f5760405162461bcd60e51b815260040161100890614210565b6114c06000613a37565b60105460ff16156119bd57604051632f22819760e11b815260040160405180910390fd5b6007546001600160a01b031633146119e75760405162461bcd60e51b815260040161100890614210565b6006546001600160a01b031660006119ff8284613342565b90508060096000828254611a1391906141bf565b9250508190555080600b6000828254611a2c91906141bf565b90915550506040518381526001600160a01b038316907fde4cc1d2dd41970a827a8df55efd18c527c17c26485847d680cc2b4c71e7a87c906020015b60405180910390a2505050565b6007546001600160a01b03163314611a9f5760405162461bcd60e51b815260040161100890614210565b6040516301e9a69560e41b815230600482015260001960248201527f0000000000000000000000004da27a545c0c5b758a6ba100e3a049001de870f56001600160a01b031690631e9a695090604401600060405180830381600087803b158015611b0857600080fd5b505af1158015611b1c573d6000803e3d6000fd5b50506040516370a0823160e01b8152306004820152600092507f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae96001600160a01b031691506370a0823190602401602060405180830381865afa158015611b87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bab919061425b565b600654604080516003808252608082019092529293506001600160a01b0390911691600091602082016060803683370190505090507f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae981600081518110611c1457611c14614245565b60200260200101906001600160a01b031690816001600160a01b0316815250507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600181518110611c6857611c68614245565b60200260200101906001600160a01b031690816001600160a01b0316815250508181600281518110611c9c57611c9c614245565b6001600160a01b039283166020918202929092010152611cff907f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9167f000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f8561342b565b60006001600160a01b037f000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f166338ed173985878530611d3f42603c6141a7565b6040518663ffffffff1660e01b8152600401611d5f959493929190614395565b6000604051808303816000875af1158015611d7e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611da691908101906143d1565b905060008160018351611db991906141bf565b81518110611dc957611dc9614245565b602090810291909101015160105490915060ff16611deb57611deb84826136c3565b60408051868152602081018390526001600160a01b038616917fc003f45bc224d116b6d079100d4ab57a5b9633244c47a5a92a176c5b79a85f28910160405180910390a2505050505050565b6000611e4283612394565b90506000611e4f836114c2565b905080821115611e7c576040516323dc290560e21b81526004810183905260248101829052604401611008565b6006546040516370a0823160e01b81523060048201526001600160a01b039091169060009082906370a0823190602401602060405180830381865afa158015611ec9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eed919061425b565b600654909150611f08906001600160a01b0316333087613953565b6040516370a0823160e01b815230600482015260009082906001600160a01b038516906370a0823190602401602060405180830381865afa158015611f51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f75919061425b565b611f7f91906141bf565b9050848114611fac57604051632901b09360e11b81526001600160a01b0384166004820152602401611008565b611fb686886139dd565b60408051868152602081018990526001600160a01b0388169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d791016118e8565b60018054610e4c906141d6565b6114c0600954611999565b336000908152600360205260408120805483919083906120329084906141bf565b90915550506001600160a01b0383166000818152600360205260409081902080548501905551339060008051602061489c83398151915290610f6e9086815260200190565b6060816001600160401b0381111561209157612091613cf5565b6040519080825280602002602001820160405280156120c457816020015b60608152602001906001900390816120af5790505b50905060005b828110156121c757600080308686858181106120e8576120e8614245565b90506020028101906120fa9190614476565b6040516121089291906144c3565b600060405180830381855af49150503d8060008114612143576040519150601f19603f3d011682016040523d82523d6000602084013e612148565b606091505b5091509150816121945760448151101561216157600080fd5b6004810190508080602001905181019061217b91906144d3565b60405162461bcd60e51b81526004016110089190613c88565b808484815181106121a7576121a7614245565b6020026020010181905250505080806121bf90614566565b9150506120ca565b5092915050565b6007546000906001600160a01b031633146121fb5760405162461bcd60e51b815260040161100890614210565b60408051600180825281830190925260009160208083019080368337505060085482519293506001600160a01b03169183915060009061223d5761223d614245565b6001600160a01b039283166020918202929092010152604051633111e7b360e01b81527f000000000000000000000000d784927ff2f95ba542bfc824c8a8a98f3495f6b590911690633111e7b39061229f90849060001990309060040161457f565b6020604051808303816000875af11580156122be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122e2919061425b565b91507f0000000000000000000000004da27a545c0c5b758a6ba100e3a049001de870f56001600160a01b031663787a08a66040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561233f57600080fd5b505af1158015612353573d6000803e3d6000fd5b505050507f8ca0188d9770b383d1a7a2ddfe5e0c1f029084481a53697d6c51525c47a8d88e8260405161238891815260200190565b60405180910390a15090565b6002546000908015610ef157610eec6123ab610e11565b849083613314565b60006123be84610f80565b9050336001600160a01b0383161461242e576001600160a01b0382166000908152600460209081526040808320338452909152902054600019811461242c5761240782826141bf565b6001600160a01b03841660009081526004602090815260408083203384529091529020555b505b61243a84828585613a89565b6124448282613afa565b60408051858152602081018390526001600160a01b03808516929086169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a4600654610eec906001600160a01b03168486613b5c565b6007546001600160a01b031633146124d05760405162461bcd60e51b815260040161100890614210565b6006546001600160a01b03838116911614806124f957506008546001600160a01b038381169116145b8061250c57506001600160a01b03821630145b8061254857507f0000000000000000000000004da27a545c0c5b758a6ba100e3a049001de870f56001600160a01b0316826001600160a01b0316145b15612571576040516339b8549160e01b81526001600160a01b0383166004820152602401611008565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa1580156125b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125dc919061425b565b90506125f26001600160a01b0384168383613b5c565b816001600160a01b0316836001600160a01b03167fed679328aebf74ede77ae09efcf36e90244f83643dadac1c2d9f0b21a46f6ab78360405161263791815260200190565b60405180910390a3505050565b6000336001600160a01b038316146126b4576001600160a01b038216600090815260046020908152604080832033845290915290205460001981146126b25761268d85826141bf565b6001600160a01b03841660009081526004602090815260408083203384529091529020555b505b6126bd84611526565b9050806000036126fd5760405162461bcd60e51b815260206004820152600b60248201526a5a45524f5f41535345545360a81b6044820152606401611008565b61270981858585613a89565b6127138285613afa565b60408051828152602081018690526001600160a01b03808516929086169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a4600654610eec906001600160a01b03168483613b5c565b6007546001600160a01b0316331461279f5760405162461bcd60e51b815260040161100890614210565b600f5460408051918252602082018390527fcfb5a454b8aa7dc04ecb5bc1410b2a57969ca1d67f66d565196f60c6f9975404910160405180910390a1600f55565b60105460009060ff16156127f657506000919050565b600f54600e546000198214801561280e575060001981145b1561281e57506000199392505050565b60008061282c848488613871565b9150915061151c610be383836137c1565b6002546000908015610fa057610eec81612855610e11565b8591906132f5565b6007546001600160a01b031633146128875760405162461bcd60e51b815260040161100890614210565b6001600160a01b038281166000908152600d60205260409020805460ff191683158015918217909255600654909216916128d25750806001600160a01b0316836001600160a01b0316145b156128e0576128e081613bd4565b826001600160a01b03167fd600b9348603c6deff34b4e0b28b60e1c8036c806741b9e6d90032e7f37dd27f83604051611a68911515815260200190565b6001600160a01b038116600090815260036020526040812054610f7a90610ecd565b4284101561298f5760405162461bcd60e51b815260206004820152601760248201527f5045524d49545f444541444c494e455f455850495245440000000000000000006044820152606401611008565b6000600161299b61145f565b6001600160a01b038a811660008181526005602090815260409182902080546001810190915582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98184015280840194909452938d166060840152608083018c905260a083019390935260c08083018b90528151808403909101815260e08301909152805192019190912061190160f01b6101008301526101028201929092526101228101919091526101420160408051601f198184030181528282528051602091820120600084529083018083525260ff871690820152606081018590526080810184905260a0016020604051602081039080840390855afa158015612aa7573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811615801590612add5750876001600160a01b0316816001600160a01b0316145b612b1a5760405162461bcd60e51b815260206004820152600e60248201526d24a72b20a624a22fa9a4a3a722a960911b6044820152606401611008565b6001600160a01b0390811660009081526004602090815260408083208a8516808552908352928190208990555188815291928a16917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a350505050505050565b6007546001600160a01b03163314612bad5760405162461bcd60e51b815260040161100890614210565b600e5460408051918252602082018390527f1f21432dd7b8ead64d2e7c06a74baf13783b2d2f7153f099e2c4cabc3c5dbec6910160405180910390a1600e55565b6007546001600160a01b03163314612c185760405162461bcd60e51b815260040161100890614210565b3060009081526003602052604081205490612c3282611526565b905080600003612c725760405162461bcd60e51b815260206004820152600b60248201526a5a45524f5f41535345545360a81b6044820152606401611008565b612c80816000806000613a89565b612c8a3083613afa565b6006546001600160a01b0316612cc1817f00000000000000000000000069592e6f9d21989a043646fe8225da2600e5a0f78461342b565b600c54604051631ffbe7f960e01b81526001600160a01b0383811660048301526024820192909252604481018490527f00000000000000000000000069592e6f9d21989a043646fe8225da2600e5a0f790911690631ffbe7f990606401600060405180830381600087803b158015612d3857600080fd5b505af1158015612d4c573d6000803e3d6000fd5b505060408051868152602081018690527f15e3e2a76a6839c244c1ed0a821c233ce8af552dffcb856089eae6cbbbb71ea6935001905060405180910390a1505050565b6006546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015612dd8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e3a919061425b565b60105460ff1615612e2057604051632f22819760e11b815260040160405180910390fd5b6007546001600160a01b03163314612e4a5760405162461bcd60e51b815260040161100890614210565b8015612e6557600654612e65906001600160a01b0316613bd4565b6010805460ff191660011790556040517f6e7cab6accf9b093a6b800ed920df610db4dbfd8807417f5f2c48dd66c03babb90612ea690831515815260200190565b60405180910390a150565b6007546001600160a01b03163314612edb5760405162461bcd60e51b815260040161100890614210565b6000612ee5611531565b1115612f0457604051636b86639360e11b815260040160405180910390fd5b600a546040805163ffffffff928316815291831660208301527f3c392b44ad99b1fb7c87ae7b914cbd1de1aeed3e9369a20d3070cc771669898f910160405180910390a1600a805463ffffffff191663ffffffff92909216919091179055565b6000610f7a8261283d565b6007546001600160a01b03163314612f995760405162461bcd60e51b815260040161100890614210565b6001600160a01b038116612ffe5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401611008565b61300781613a37565b50565b6000613014611531565b90506130286007546001600160a01b031690565b6001600160a01b0316336001600160a01b0316141580156130495750600081115b1561306757604051636b86639360e11b815260040160405180910390fd5b60085460009061308290600160a01b900460ff16600a614696565b9050600061308f8261283d565b6008546040516370a0823160e01b81523060048201529192506000916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156130dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613101919061425b565b600a549091506000906131259064010000000090046001600160401b0316426141bf565b905060006301e13380670de0b6b3a76400006608e1bc9bf040006131498587614310565b6131539190614310565b61315d919061432f565b613167919061432f565b905060006131768286886132f5565b9050600061318f600b5486613c0190919063ffffffff16565b905060006131a58267016345785d8a0000613c1b565b905060006131b482898b6132f5565b90506131c9306131c483876141a7565b6139dd565b6131dd6131d683876141a7565b8490613c01565b6131e7908b6141a7565b600a805464010000000063ffffffff428116919091026bffffffffffffffff00000000196001600160a01b0395909516600160601b02949094169116179190911790556009879055600b5487111561323f57600b8790555b60408051858152602081018390529081018490527ffd23cefb4992bc1b95df1f544efdb9908d901288354421270f7a8f8a0dfec20a9060600160405180910390a150505050505050505050565b60008160ff168360ff16036132a2575082610f0c565b8160ff168360ff1610156132d6576132ba83836146a5565b6132c590600a614696565b6132cf9085614310565b9050610f0c565b6132e082846146a5565b6132eb90600a614696565b6132cf908561432f565b82820281151584158583048514171661330d57600080fd5b0492915050565b82820281151584158583048514171661332c57600080fd5b6001826001830304018115150290509392505050565b604051631a4ca37b60e21b81526001600160a01b038381166004830152602482018390523060448301526000917f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a9909116906369328dec906064016020604051808303816000875af11580156133bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133e0919061425b565b9050826001600160a01b03167f84343cc97621dbc51bce198a258218a2063c160e4d473ff51007c7a60eec5fa18260405161341d91815260200190565b60405180910390a292915050565b600060405163095ea7b360e01b8152836004820152826024820152602060006044836000895af13d15601f3d11600160005114161716915050806134a25760405162461bcd60e51b815260206004820152600e60248201526d1054141493d59157d1905253115160921b6044820152606401611008565b50505050565b6040516335ea6a7560e01b81526001600160a01b03828116600483015260009182917f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a916906335ea6a759060240161018060405180830381865afa158015613514573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061353891906146fe565b50929a50506001600160a01b038a16985061357a97505050505050505057604051630a5c5e7d60e11b81526001600160a01b0384166004820152602401611008565b6000600860149054906101000a900460ff169050836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156135cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135f091906147df565b925060128360ff16111561362357604051630651982f60e11b815260ff8416600482015260126024820152604401611008565b60ff81161580159061363b57508260ff168160ff1614155b1561367957600f54600e54600019821461365e5761365a82848761328c565b600f555b60001981146136765761367281848761328c565b600e555b50505b50600680546001600160a01b03199081166001600160a01b0395861617909155600880546001600160a81b031916600160a01b60ff86160290921691909117919093161790915590565b6136f76001600160a01b0383167f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a98361342b565b60405163e8eda9df60e01b81526001600160a01b03838116600483015260248201839052306044830152600060648301527f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a9169063e8eda9df90608401600060405180830381600087803b15801561376e57600080fd5b505af1158015613782573d6000803e3d6000fd5b50505050816001600160a01b03167ff099efd56d0c64f9a1aa1379a470d871392b67ea7678ed5659ad4bfe7dd76575826040516116e191815260200190565b60008183106137d05781610f0c565b5090919050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f600060405161380991906147fc565b6040805191829003822060208301939093528101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b600080600061387e612d8f565b6008546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa1580156138c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138ea919061425b565b6138f491906141a7565b6001600160a01b0385166000908152600360205260408120546002549293509190811561392b576139268385846132f5565b61392d565b825b90506139398982613c01565b95506139458885613c01565b945050505050935093915050565b60006040516323b872dd60e01b81528460048201528360248201528260448201526020600060648360008a5af13d15601f3d11600160005114161716915050806139d65760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606401611008565b5050505050565b80600260008282546139ef91906141a7565b90915550506001600160a01b03821660008181526003602090815260408083208054860190555184815260008051602061489c83398151915291015b60405180910390a35050565b600780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6006546001600160a01b03166000613a9f612d8f565b905080861115613af2576000613abe83613ab9848a6141bf565b613342565b90508060096000828254613ad291906141bf565b9250508190555080600b6000828254613aeb91906141bf565b9091555050505b505050505050565b6001600160a01b03821660009081526003602052604081208054839290613b229084906141bf565b90915550506002805482900390556040518181526000906001600160a01b0384169060008051602061489c83398151915290602001613a2b565b600060405163a9059cbb60e01b8152836004820152826024820152602060006044836000895af13d15601f3d11600160005114161716915050806134a25760405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b6044820152606401611008565b6009548015613bfd57613be561300a565b613bf182600019613342565b5060006009819055600b555b5050565b6000818311613c11576000610f0c565b610f0c82846141bf565b6000610f0c8383670de0b6b3a76400006132f5565b60005b83811015613c4b578181015183820152602001613c33565b838111156134a25750506000910152565b60008151808452613c74816020860160208601613c30565b601f01601f19169290920160200192915050565b602081526000610f0c6020830184613c5c565b600060208284031215613cad57600080fd5b5035919050565b6001600160a01b038116811461300757600080fd5b60008060408385031215613cdc57600080fd5b8235613ce781613cb4565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b60405161012081016001600160401b0381118282101715613d2e57613d2e613cf5565b60405290565b604051608081016001600160401b0381118282101715613d2e57613d2e613cf5565b604051606081016001600160401b0381118282101715613d2e57613d2e613cf5565b604051601f8201601f191681016001600160401b0381118282101715613da057613da0613cf5565b604052919050565b60008060006102c08486031215613dbe57600080fd5b601f8581860112613dce57600080fd5b613dd6613d0b565b80610120870188811115613de957600080fd5b875b81811015613e0c578035613dfe81613cb4565b845260209384019301613deb565b508196508861013f890112613e2057600080fd5b613e28613d34565b92508291506102a0880189811115613e3f57600080fd5b80821015613ea2578985830112613e565760008081fd5b613e5e613d56565b80606084018c811115613e715760008081fd5b845b81811015613e8b578035845260209384019301613e73565b505085525060209093019260609190910190613e3f565b9699919850509435955050505050565b600080600060608486031215613ec757600080fd5b8335613ed281613cb4565b92506020840135613ee281613cb4565b929592945050506040919091013590565b600060208284031215613f0557600080fd5b8135610f0c81613cb4565b60008060408385031215613f2357600080fd5b823591506020830135613f3581613cb4565b809150509250929050565b60008060208385031215613f5357600080fd5b82356001600160401b0380821115613f6a57600080fd5b818501915085601f830112613f7e57600080fd5b813581811115613f8d57600080fd5b8660208260051b8501011115613fa257600080fd5b60209290920196919550909350505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561400957603f19888603018452613ff7858351613c5c565b94509285019290850190600101613fdb565b5092979650505050505050565b60008060006060848603121561402b57600080fd5b83359250602084013561403d81613cb4565b9150604084013561404d81613cb4565b809150509250925092565b6000806040838503121561406b57600080fd5b823561407681613cb4565b91506020830135613f3581613cb4565b8035801515811461409657600080fd5b919050565b600080604083850312156140ae57600080fd5b82356140b981613cb4565b91506140c760208401614086565b90509250929050565b60ff8116811461300757600080fd5b600080600080600080600060e0888a0312156140fa57600080fd5b873561410581613cb4565b9650602088013561411581613cb4565b955060408801359450606088013593506080880135614133816140d0565b9699959850939692959460a0840135945060c09093013592915050565b60006020828403121561416257600080fd5b610f0c82614086565b60006020828403121561417d57600080fd5b813563ffffffff81168114610f0c57600080fd5b634e487b7160e01b600052601160045260246000fd5b600082198211156141ba576141ba614191565b500190565b6000828210156141d1576141d1614191565b500390565b600181811c908216806141ea57607f821691505b60208210810361420a57634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561426d57600080fd5b5051919050565b6102e08101818660005b60098110156142a65781516001600160a01b031683526020928301929091019060010161427e565b50505061012082018560005b60048110156142f95781518360005b60038110156142e05782518252602092830192909101906001016142c1565b50505060609290920191602091909101906001016142b2565b5050506102a08201939093526102c0015292915050565b600081600019048311821515161561432a5761432a614191565b500290565b60008261434c57634e487b7160e01b600052601260045260246000fd5b500490565b600081518084526020808501945080840160005b8381101561438a5781516001600160a01b031687529582019590820190600101614365565b509495945050505050565b85815284602082015260a0604082015260006143b460a0830186614351565b6001600160a01b0394909416606083015250608001529392505050565b600060208083850312156143e457600080fd5b82516001600160401b03808211156143fb57600080fd5b818501915085601f83011261440f57600080fd5b81518181111561442157614421613cf5565b8060051b9150614432848301613d78565b818152918301840191848101908884111561444c57600080fd5b938501935b8385101561446a57845182529385019390850190614451565b98975050505050505050565b6000808335601e1984360301811261448d57600080fd5b8301803591506001600160401b038211156144a757600080fd5b6020019150368190038213156144bc57600080fd5b9250929050565b8183823760009101908152919050565b6000602082840312156144e557600080fd5b81516001600160401b03808211156144fc57600080fd5b818401915084601f83011261451057600080fd5b81518181111561452257614522613cf5565b614535601f8201601f1916602001613d78565b915080825285602082850101111561454c57600080fd5b61455d816020840160208601613c30565b50949350505050565b60006001820161457857614578614191565b5060010190565b6060815260006145926060830186614351565b6020830194909452506001600160a01b0391909116604090910152919050565b600181815b808511156145ed5781600019048211156145d3576145d3614191565b808516156145e057918102915b93841c93908002906145b7565b509250929050565b60008261460457506001610f7a565b8161461157506000610f7a565b816001811461462757600281146146315761464d565b6001915050610f7a565b60ff84111561464257614642614191565b50506001821b610f7a565b5060208310610133831016604e8410600b8410161715614670575081810a610f7a565b61467a83836145b2565b806000190482111561468e5761468e614191565b029392505050565b6000610f0c60ff8416836145f5565b600060ff821660ff8416808210156146bf576146bf614191565b90039392505050565b80516fffffffffffffffffffffffffffffffff8116811461409657600080fd5b805161409681613cb4565b8051614096816140d0565b6000806000806000806000806000806000806101808d8f03121561472157600080fd5b8c519b5061473160208e016146c8565b9a5061473f60408e016146c8565b995061474d60608e016146c8565b985061475b60808e016146c8565b975061476960a08e016146c8565b965060c08d015164ffffffffff8116811461478357600080fd5b955061479160e08e016146e8565b94506147a06101008e016146e8565b93506147af6101208e016146e8565b92506147be6101408e016146e8565b91506147cd6101608e016146f3565b90509295989b509295989b509295989b565b6000602082840312156147f157600080fd5b8151610f0c816140d0565b600080835481600182811c91508083168061481857607f831692505b6020808410820361483757634e487b7160e01b86526022600452602486fd5b81801561484b57600181146148605761488d565b60ff198616895284151585028901965061488d565b60008a81526020902060005b868110156148855781548b82015290850190830161486c565b505084890196505b50949897505050505050505056feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220bc3ca6867b9d04038523b6f26f10f12ab9cd2bdf7af0ea5702822bf20301306264736f6c634300080f0033

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

000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000014000000000000000000000000081c46feca27b31f3adc2b91ee4be9717d1cd3dd7000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a9000000000000000000000000d784927ff2f95ba542bfc824c8a8a98f3495f6b500000000000000000000000069592e6f9d21989a043646fe8225da2600e5a0f70000000000000000000000004da27a545c0c5b758a6ba100e3a049001de870f50000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000008000000000000000000000000056fd409e1d7a124bd7017459dfea2f387b6d5cd0000000000000000000000004fabb145d64652a948d72533023f6e7a623c7c53000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000956f47f50a910163d8bf957cf5846d573e7f87ca000000000000000000000000853d955acef822db058eb8505911ed77f175b99e00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f510000000000000000000000008e870d67f660d95d5be530380d0ec0bd388289e1

-----Decoded View---------------
Arg [0] : _asset (address): 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
Arg [1] : _approvedPositions (address[]): 0x056Fd409E1d7A124BD7017459dFEa2F387b6d5Cd,0x4Fabb145d64652a948d72533023f6E7A623C7C53,0xdAC17F958D2ee523a2206206994597C13D831ec7,0x6B175474E89094C44Da98b954EedeAC495271d0F,0x956F47F50A910163D8BF957Cf5846D573E7f87CA,0x853d955aCEf822Db058eb8505911ED77F175b99e,0x57Ab1ec28D129707052df4dF418D58a2D46d5f51,0x8E870D67F660D95d5be530380D0eC0bd388289E1
Arg [2] : _curveRegistryExchange (address): 0x81C46fECa27B31F3ADC2b91eE4be9717d1cd3DD7
Arg [3] : _sushiswapRouter (address): 0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F
Arg [4] : _lendingPool (address): 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9
Arg [5] : _incentivesController (address): 0xd784927Ff2f95ba542BfC824c8a8a98F3495f6b5
Arg [6] : _gravityBridge (address): 0x69592e6f9d21989a043646fE8225da2600e5A0f7
Arg [7] : _stkAAVE (address): 0x4da27a545c0c5B758a6BA100e3a049001de870f5
Arg [8] : _AAVE (address): 0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9
Arg [9] : _WETH (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

-----Encoded View---------------
19 Constructor Arguments found :
Arg [0] : 000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000140
Arg [2] : 00000000000000000000000081c46feca27b31f3adc2b91ee4be9717d1cd3dd7
Arg [3] : 000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f
Arg [4] : 0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a9
Arg [5] : 000000000000000000000000d784927ff2f95ba542bfc824c8a8a98f3495f6b5
Arg [6] : 00000000000000000000000069592e6f9d21989a043646fe8225da2600e5a0f7
Arg [7] : 0000000000000000000000004da27a545c0c5b758a6ba100e3a049001de870f5
Arg [8] : 0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9
Arg [9] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [10] : 0000000000000000000000000000000000000000000000000000000000000008
Arg [11] : 000000000000000000000000056fd409e1d7a124bd7017459dfea2f387b6d5cd
Arg [12] : 0000000000000000000000004fabb145d64652a948d72533023f6e7a623c7c53
Arg [13] : 000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7
Arg [14] : 0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f
Arg [15] : 000000000000000000000000956f47f50a910163d8bf957cf5846d573e7f87ca
Arg [16] : 000000000000000000000000853d955acef822db058eb8505911ed77f175b99e
Arg [17] : 00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f51
Arg [18] : 0000000000000000000000008e870d67f660d95d5be530380d0ec0bd388289e1


Loading...
Loading
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.