S Price: $0.881057 (+1.78%)

Contract

0x11f95aaa59F1AD89576c61E3C9Cd24DF1FdCF46f

Overview

S Balance

Sonic LogoSonic LogoSonic Logo0 S

S Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
EVault

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 20000 runs

Other Settings:
cancun EvmVersion
File 1 of 52 : EVault.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

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

/// @title EVault
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice This contract implements an EVC enabled lending vault
/// @dev The responsibility of this contract is call routing. Select functions are embedded, while most are delegated to the modules
contract EVault is Dispatch {
    constructor(Integrations memory integrations, DeployedModules memory modules) Dispatch(integrations, modules) {}


    ///////////////////////////////////////////////////////////////////////////////////////////////
    //                                     INITIALIZATION                                        //
    ///////////////////////////////////////////////////////////////////////////////////////////////

    function initialize(address proxyCreator) public virtual override use(MODULE_INITIALIZE) {}



    ///////////////////////////////////////////////////////////////////////////////////////////////
    //                                         TOKEN                                             //
    ///////////////////////////////////////////////////////////////////////////////////////////////

    function name() public view virtual override useView(MODULE_TOKEN) returns (string memory) {}

    function symbol() public view virtual override useView(MODULE_TOKEN) returns (string memory) {}

    function decimals() public view virtual override returns (uint8) { return super.decimals(); }

    function totalSupply() public view virtual override useView(MODULE_TOKEN) returns (uint256) {}

    function balanceOf(address account) public view virtual override returns (uint256) { return super.balanceOf(account); }

    function allowance(address holder, address spender) public view virtual override returns (uint256) { return super.allowance(holder, spender); }


    function transfer(address to, uint256 amount) public virtual override callThroughEVC returns (bool) { return super.transfer(to, amount); }

    function transferFrom(address from, address to, uint256 amount) public virtual override callThroughEVC returns (bool) { return super.transferFrom(from, to, amount); }

    function approve(address spender, uint256 amount) public virtual override returns (bool) { return super.approve(spender, amount); }

    function transferFromMax(address from, address to) public virtual override callThroughEVC returns (bool) { return super.transferFromMax(from, to); }



    ///////////////////////////////////////////////////////////////////////////////////////////////
    //                                         VAULT                                             //
    ///////////////////////////////////////////////////////////////////////////////////////////////

    function asset() public view virtual override returns (address) { return super.asset(); }

    function totalAssets() public view virtual override useView(MODULE_VAULT) returns (uint256) {}

    function convertToAssets(uint256 shares) public view virtual override returns (uint256) { return super.convertToAssets(shares); }

    function convertToShares(uint256 assets) public view virtual override returns (uint256) { return super.convertToShares(assets); }

    function maxDeposit(address account) public view virtual override useView(MODULE_VAULT) returns (uint256) {}

    function previewDeposit(uint256 assets) public view virtual override useView(MODULE_VAULT) returns (uint256) {}

    function maxMint(address account) public view virtual override useView(MODULE_VAULT) returns (uint256) {}

    function previewMint(uint256 shares) public view virtual override useView(MODULE_VAULT) returns (uint256) {}

    function maxWithdraw(address owner) public view virtual override useView(MODULE_VAULT) returns (uint256) {}

    function previewWithdraw(uint256 assets) public view virtual override useView(MODULE_VAULT) returns (uint256) {}

    function maxRedeem(address owner) public view virtual override useView(MODULE_VAULT) returns (uint256) {}

    function previewRedeem(uint256 shares) public view virtual override useView(MODULE_VAULT) returns (uint256) {}

    function accumulatedFees() public view virtual override returns (uint256) { return super.accumulatedFees(); }

    function accumulatedFeesAssets() public view virtual override returns (uint256) { return super.accumulatedFeesAssets(); }

    function creator() public view virtual override useView(MODULE_VAULT) returns (address) {}


    function deposit(uint256 amount, address receiver) public virtual override callThroughEVC use(MODULE_VAULT) returns (uint256) {}

    function mint(uint256 amount, address receiver) public virtual override callThroughEVC use(MODULE_VAULT) returns (uint256) {}

    function withdraw(uint256 amount, address receiver, address owner) public virtual override callThroughEVC use(MODULE_VAULT) returns (uint256) {}

    function redeem(uint256 amount, address receiver, address owner) public virtual override callThroughEVC use(MODULE_VAULT) returns (uint256) {}

    function skim(uint256 amount, address receiver) public virtual override callThroughEVC use(MODULE_VAULT) returns (uint256) {}



    ///////////////////////////////////////////////////////////////////////////////////////////////
    //                                        BORROWING                                          //
    ///////////////////////////////////////////////////////////////////////////////////////////////

    function totalBorrows() public view virtual override useView(MODULE_BORROWING) returns (uint256) {}

    function totalBorrowsExact() public view virtual override useView(MODULE_BORROWING) returns (uint256) {}

    function cash() public view virtual override useView(MODULE_BORROWING) returns (uint256) {}

    function debtOf(address account) public view virtual override returns (uint256) { return super.debtOf(account); }

    function debtOfExact(address account) public view virtual override useView(MODULE_BORROWING) returns (uint256) {}

    function interestRate() public view virtual override returns (uint256) { return super.interestRate(); }

    function interestAccumulator() public view virtual override useView(MODULE_BORROWING) returns (uint256) {}

    function dToken() public view virtual override useView(MODULE_BORROWING) returns (address) {}


    function borrow(uint256 amount, address receiver) public virtual override callThroughEVC use(MODULE_BORROWING) returns (uint256) {}

    function repay(uint256 amount, address receiver) public virtual override callThroughEVC use(MODULE_BORROWING) returns (uint256) {}

    function repayWithShares(uint256 amount, address receiver) public virtual override callThroughEVC use(MODULE_BORROWING) returns (uint256 shares, uint256 debt) {}

    function pullDebt(uint256 amount, address from) public virtual override callThroughEVC use(MODULE_BORROWING) {}

    function flashLoan(uint256 amount, bytes calldata data) public virtual override use(MODULE_BORROWING) {}

    function touch() public virtual override callThroughEVC use(MODULE_BORROWING) {}



    ///////////////////////////////////////////////////////////////////////////////////////////////
    //                                     LIQUIDATION                                           //
    ///////////////////////////////////////////////////////////////////////////////////////////////

    function checkLiquidation(address liquidator, address violator, address collateral) public view virtual override useView(MODULE_LIQUIDATION) returns (uint256 maxRepay, uint256 maxYield) {}

    function liquidate(address violator, address collateral, uint256 repayAssets, uint256 minYieldBalance) public virtual override callThroughEVC use(MODULE_LIQUIDATION) {}



    ///////////////////////////////////////////////////////////////////////////////////////////////
    //                                    RISK MANAGEMENT                                        //
    ///////////////////////////////////////////////////////////////////////////////////////////////

    function accountLiquidity(address account, bool liquidation) public view virtual override useView(MODULE_RISKMANAGER) returns (uint256 collateralValue, uint256 liabilityValue) {}

    function accountLiquidityFull(address account, bool liquidation) public view virtual override useView(MODULE_RISKMANAGER) returns (address[] memory collaterals, uint256[] memory collateralValues, uint256 liabilityValue) {}


    function disableController() public virtual override use(MODULE_RISKMANAGER) {}

    function checkAccountStatus(address account, address[] calldata collaterals) public view virtual override returns (bytes4) { return super.checkAccountStatus(account, collaterals); }

    function checkVaultStatus() public virtual override returns (bytes4) { return super.checkVaultStatus(); }



    ///////////////////////////////////////////////////////////////////////////////////////////////
    //                                   BALANCE TRACKING                                        //
    ///////////////////////////////////////////////////////////////////////////////////////////////

    function balanceTrackerAddress() public view virtual override useView(MODULE_BALANCE_FORWARDER) returns (address) {}

    function balanceForwarderEnabled(address account) public view virtual override useView(MODULE_BALANCE_FORWARDER) returns (bool) {}


    function enableBalanceForwarder() public virtual override use(MODULE_BALANCE_FORWARDER) {}

    function disableBalanceForwarder() public virtual override use(MODULE_BALANCE_FORWARDER) {}



    ///////////////////////////////////////////////////////////////////////////////////////////////
    //                                     GOVERNANCE                                            //
    ///////////////////////////////////////////////////////////////////////////////////////////////

    function governorAdmin() public view virtual override useView(MODULE_GOVERNANCE) returns (address) {}

    function feeReceiver() public view virtual override useView(MODULE_GOVERNANCE) returns (address) {}

    function interestFee() public view virtual override returns (uint16) { return super.interestFee(); }

    function interestRateModel() public view virtual override useView(MODULE_GOVERNANCE) returns (address) {}

    function protocolConfigAddress() public view virtual override useView(MODULE_GOVERNANCE) returns (address) {}

    function protocolFeeShare() public view virtual override useView(MODULE_GOVERNANCE) returns (uint256) {}

    function protocolFeeReceiver() public view virtual override useView(MODULE_GOVERNANCE) returns (address) {}

    function caps() public view virtual override useView(MODULE_GOVERNANCE) returns (uint16 supplyCap, uint16 borrowCap) {}

    function LTVBorrow(address collateral) public view virtual override useView(MODULE_GOVERNANCE) returns (uint16) {}

    function LTVLiquidation(address collateral) public view virtual override useView(MODULE_GOVERNANCE) returns (uint16) {}

    function LTVFull(address collateral) public view virtual override useView(MODULE_GOVERNANCE) returns (uint16 borrowLTV, uint16 liquidationLTV, uint16 initialLiquidationLTV, uint48 targetTimestamp, uint32 rampDuration) {}

    function LTVList() public view virtual override useView(MODULE_GOVERNANCE) returns (address[] memory) {}

    function maxLiquidationDiscount() public view virtual override useView(MODULE_GOVERNANCE) returns (uint16) {}

    function liquidationCoolOffTime() public view virtual override useView(MODULE_GOVERNANCE) returns (uint16) {}

    function hookConfig() public view virtual override useView(MODULE_GOVERNANCE) returns (address, uint32) {}

    function configFlags() public view virtual override useView(MODULE_GOVERNANCE) returns (uint32) {}

    function EVC() public view virtual override useView(MODULE_GOVERNANCE) returns (address) {}

    function unitOfAccount() public view virtual override useView(MODULE_GOVERNANCE) returns (address) {}

    function oracle() public view virtual override useView(MODULE_GOVERNANCE) returns (address) {}

    function permit2Address() public view virtual override useView(MODULE_GOVERNANCE) returns (address) {}


    function convertFees() public virtual override callThroughEVC use(MODULE_GOVERNANCE) {}

    function setGovernorAdmin(address newGovernorAdmin) public virtual override use(MODULE_GOVERNANCE) {}

    function setFeeReceiver(address newFeeReceiver) public virtual override use(MODULE_GOVERNANCE) {}

    function setHookConfig(address newHookTarget, uint32 newHookedOps) public virtual override use(MODULE_GOVERNANCE) {}

    function setLTV(address collateral, uint16 borrowLTV, uint16 liquidationLTV, uint32 rampDuration) public virtual override use(MODULE_GOVERNANCE) {}

    function setMaxLiquidationDiscount(uint16 newDiscount) public virtual override use(MODULE_GOVERNANCE) {}

    function setLiquidationCoolOffTime(uint16 newCoolOffTime) public virtual override use(MODULE_GOVERNANCE) {}

    function setInterestRateModel(address newModel) public virtual override use(MODULE_GOVERNANCE) {}

    function setConfigFlags(uint32 newConfigFlags) public virtual override use(MODULE_GOVERNANCE) {}

    function setCaps(uint16 supplyCap, uint16 borrowCap) public virtual override use(MODULE_GOVERNANCE) {}

    function setInterestFee(uint16 newFee) public virtual override use(MODULE_GOVERNANCE) {}
}

File 2 of 52 : Dispatch.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Base} from "./shared/Base.sol";

import {TokenModule} from "./modules/Token.sol";
import {VaultModule} from "./modules/Vault.sol";
import {BorrowingModule} from "./modules/Borrowing.sol";
import {LiquidationModule} from "./modules/Liquidation.sol";
import {InitializeModule} from "./modules/Initialize.sol";
import {BalanceForwarderModule} from "./modules/BalanceForwarder.sol";
import {GovernanceModule} from "./modules/Governance.sol";
import {RiskManagerModule} from "./modules/RiskManager.sol";

import {AddressUtils} from "./shared/lib/AddressUtils.sol";
import "./shared/Constants.sol";

/// @title Dispatch
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Contract which ties in the EVault modules and provides utilities for routing calls to modules and the EVC
abstract contract Dispatch is
    InitializeModule,
    TokenModule,
    VaultModule,
    BorrowingModule,
    LiquidationModule,
    RiskManagerModule,
    BalanceForwarderModule,
    GovernanceModule
{
    /// @notice Address of the Initialize module
    address public immutable MODULE_INITIALIZE;
    /// @notice Address of the Token module
    address public immutable MODULE_TOKEN;
    /// @notice Address of the Vault module
    address public immutable MODULE_VAULT;
    /// @notice Address of the Borrowing module
    address public immutable MODULE_BORROWING;
    /// @notice Address of the Liquidation module
    address public immutable MODULE_LIQUIDATION;
    /// @notice Address of the RiskManager module
    address public immutable MODULE_RISKMANAGER;
    /// @notice Address of the BalanceForwarder module
    address public immutable MODULE_BALANCE_FORWARDER;
    /// @notice Address of the Governance module
    address public immutable MODULE_GOVERNANCE;

    /// @title DeployedModules
    /// @notice This struct is used to pass in the addresses of EVault modules during deployment
    struct DeployedModules {
        address initialize;
        address token;
        address vault;
        address borrowing;
        address liquidation;
        address riskManager;
        address balanceForwarder;
        address governance;
    }

    /// @notice EVault's constructor
    /// @dev It is highly recommended to deploy fresh modules for every new EVault deployment. Particular care must
    /// also be taken to ensure the modules are deployed with the exact same values of the `Integrations` struct.
    constructor(Integrations memory integrations, DeployedModules memory modules) Base(integrations) {
        MODULE_INITIALIZE = AddressUtils.checkContract(modules.initialize);
        MODULE_TOKEN = AddressUtils.checkContract(modules.token);
        MODULE_VAULT = AddressUtils.checkContract(modules.vault);
        MODULE_BORROWING = AddressUtils.checkContract(modules.borrowing);
        MODULE_LIQUIDATION = AddressUtils.checkContract(modules.liquidation);
        MODULE_RISKMANAGER = AddressUtils.checkContract(modules.riskManager);
        MODULE_BALANCE_FORWARDER = AddressUtils.checkContract(modules.balanceForwarder);
        MODULE_GOVERNANCE = AddressUtils.checkContract(modules.governance);
    }

    // Modifier proxies the function call to a module and low-level returns the result
    modifier use(address module) {
        _; // when using the modifier, it is assumed the function body is empty.
        delegateToModule(module);
    }

    // Delegate call can't be used in a view function. To work around this limitation,
    // static call `this.viewDelegate()` function, which in turn will delegate the payload to a module.
    modifier useView(address module) {
        _; // when using the modifier, it is assumed the function body is empty.
        delegateToModuleView(module);
    }

    // Modifier ensures, that the body of the function is always executed from the EVC call.
    // It is accomplished by intercepting calls incoming directly to the vault and passing them
    // to the EVC.call function. EVC calls the vault back with original calldata. As a result, the account
    // and vault status checks are always executed in the checks deferral frame, at the end of the call,
    // outside of the vault's re-entrancy protections.
    // The modifier is applied to all functions which schedule account or vault status checks.
    modifier callThroughEVC() {
        if (msg.sender == address(evc)) {
            _;
        } else {
            callThroughEVCInternal();
        }
    }

    // External function which is only callable by the EVault itself. Its purpose is to be static called by
    // `delegateToModuleView` which allows view functions to be implemented in modules, even though delegatecall cannot
    // be directly used within view functions.
    function viewDelegate() external payable {
        if (msg.sender != address(this)) revert E_Unauthorized();

        assembly {
            let size := sub(calldatasize(), 36)
            calldatacopy(0, 36, size)
            let result := delegatecall(gas(), calldataload(4), 0, size, 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }

    function delegateToModule(address module) private {
        assembly {
            calldatacopy(0, 0, calldatasize())
            let result := delegatecall(gas(), module, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }

    function delegateToModuleView(address module) private view {
        assembly {
            // Construct optimized custom call data for `this.viewDelegate()`
            // [selector 4B][module address 32B][calldata with stripped proxy metadata][caller address 20B]
            // Proxy metadata will be appended back by the proxy on staticcall
            mstore(0, 0x1fe8b95300000000000000000000000000000000000000000000000000000000)
            let strippedCalldataSize := sub(calldatasize(), PROXY_METADATA_LENGTH)
            // we do the mstore first offset by -12 so the 20 address bytes align right behind 36 + strippedCalldataSize
            // note that it can write into the module address if the calldata is less than 12 bytes, therefore write
            // before we write module
            mstore(add(24, strippedCalldataSize), caller())
            mstore(4, module)
            calldatacopy(36, 0, strippedCalldataSize)
            // insize: stripped calldatasize + 36 (signature and module address) + 20 (caller address)
            let result := staticcall(gas(), address(), 0, add(strippedCalldataSize, 56), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }

    function callThroughEVCInternal() private {
        address _evc = address(evc);
        assembly {
            let mainCalldataLength := sub(calldatasize(), PROXY_METADATA_LENGTH)

            mstore(0, 0x1f8b521500000000000000000000000000000000000000000000000000000000) // EVC.call signature
            mstore(4, address()) // EVC.call 1st argument - address(this)
            mstore(36, caller()) // EVC.call 2nd argument - msg.sender
            mstore(68, callvalue()) // EVC.call 3rd argument - msg.value
            mstore(100, 128) // EVC.call 4th argument - msg.data, offset to the start of encoding - 128 bytes
            mstore(132, mainCalldataLength) // msg.data length without proxy metadata
            calldatacopy(164, 0, mainCalldataLength) // original calldata

            // abi encoded bytes array should be zero padded so its length is a multiple of 32
            // store zero word after msg.data bytes and round up mainCalldataLength to nearest multiple of 32
            mstore(add(164, mainCalldataLength), 0)
            let result := call(gas(), _evc, callvalue(), 0, add(164, and(add(mainCalldataLength, 31), not(31))), 0, 0)

            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 { revert(0, returndatasize()) }
            default { return(64, sub(returndatasize(), 64)) } // strip bytes encoding from call return
        }
    }
}

File 3 of 52 : Base.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {EVCClient} from "./EVCClient.sol";
import {Cache} from "./Cache.sol";
import {ProxyUtils} from "./lib/ProxyUtils.sol";
import {RevertBytes} from "./lib/RevertBytes.sol";
import {AddressUtils} from "./lib/AddressUtils.sol";

import {IProtocolConfig} from "../../ProtocolConfig/IProtocolConfig.sol";
import {IBalanceTracker} from "../../interfaces/IBalanceTracker.sol";
import {ISequenceRegistry} from "../../interfaces/ISequenceRegistry.sol";

import "./types/Types.sol";

/// @title Base
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Base contract for EVault modules with top level modifiers and utilities
abstract contract Base is EVCClient, Cache {
    IProtocolConfig internal immutable protocolConfig;
    ISequenceRegistry immutable sequenceRegistry;
    IBalanceTracker internal immutable balanceTracker;
    address internal immutable permit2;

    /// @title Integrations
    /// @notice Struct containing addresses of all of the contracts which EVault integrates with
    struct Integrations {
        // Ethereum Vault Connector's address
        address evc;
        // Address of the contract handling protocol level configurations
        address protocolConfig;
        // Address of the contract providing a unique ID used in setting the vault's name and symbol
        address sequenceRegistry;
        // Address of the contract which is called when user balances change
        address balanceTracker;
        // Address of Uniswap's Permit2 contract
        address permit2;
    }

    constructor(Integrations memory integrations) EVCClient(integrations.evc) {
        protocolConfig = IProtocolConfig(AddressUtils.checkContract(integrations.protocolConfig));
        sequenceRegistry = ISequenceRegistry(AddressUtils.checkContract(integrations.sequenceRegistry));
        balanceTracker = IBalanceTracker(integrations.balanceTracker);
        permit2 = integrations.permit2;
    }

    modifier reentrantOK() {
        _;
    } // documentation only

    modifier nonReentrant() {
        if (vaultStorage.reentrancyLocked) revert E_Reentrancy();

        vaultStorage.reentrancyLocked = true;
        _;
        vaultStorage.reentrancyLocked = false;
    }

    modifier nonReentrantView() {
        if (vaultStorage.reentrancyLocked) {
            address hookTarget = vaultStorage.hookTarget;

            // The hook target is allowed to bypass the RO-reentrancy lock. The hook target can either be a msg.sender
            // when the view function is inlined in the EVault.sol or the hook target should be taken from the trailing
            // data appended by the delegateToModuleView function used by useView modifier. In the latter case, it is
            // safe to consume the trailing data as we know we are inside useView because msg.sender == address(this)
            if (msg.sender != hookTarget && !(msg.sender == address(this) && ProxyUtils.useViewCaller() == hookTarget))
            {
                revert E_Reentrancy();
            }
        }
        _;
    }

    // Generate a vault snapshot and store it.
    // Queue vault and maybe account checks in the EVC (caller, current, onBehalfOf or none).
    // If needed, revert if this contract is not the controller of the authenticated account.
    // Returns the VaultCache and active account.
    function initOperation(uint32 operation, address accountToCheck)
        internal
        virtual
        returns (VaultCache memory vaultCache, address account)
    {
        vaultCache = updateVault();
        account = EVCAuthenticateDeferred(CONTROLLER_NEUTRAL_OPS & operation == 0);

        callHook(vaultCache.hookedOps, operation, account);
        EVCRequireStatusChecks(accountToCheck == CHECKACCOUNT_CALLER ? account : accountToCheck);

        // The snapshot is used only to verify that supply increased when checking the supply cap, and to verify that
        // the borrows increased when checking the borrowing cap. Caps are not checked when the capped variables
        // decrease (become safer). For this reason, the snapshot is disabled if both caps are disabled.
        // The snapshot is cleared during the vault status check hence the vault status check must not be forgiven.
        if (
            !vaultCache.snapshotInitialized
                && !(vaultCache.supplyCap == type(uint256).max && vaultCache.borrowCap == type(uint256).max)
        ) {
            vaultStorage.snapshotInitialized = vaultCache.snapshotInitialized = true;
            snapshot.set(vaultCache.cash, vaultCache.totalBorrows.toAssetsUp());
        }
    }

    // Checks whether the operation is disabled and returns the result of the check.
    // An operation is considered disabled if a hook has been installed for it and the
    // hook target is zero address.
    function isOperationDisabled(Flags hookedOps, uint32 operation) internal view returns (bool) {
        return hookedOps.isSet(operation) && vaultStorage.hookTarget == address(0);
    }

    // Checks whether a hook has been installed for the operation and if so, invokes the hook target.
    // If the hook target is zero address, this will revert.
    function callHook(Flags hookedOps, uint32 operation, address caller) internal virtual {
        if (hookedOps.isNotSet(operation)) return;

        invokeHookTarget(caller);
    }

    // Same as callHook, but acquires the reentrancy lock when calling the hook
    function callHookWithLock(Flags hookedOps, uint32 operation, address caller) internal virtual {
        if (hookedOps.isNotSet(operation)) return;

        invokeHookTargetWithLock(caller);
    }

    function invokeHookTarget(address caller) private {
        address hookTarget = vaultStorage.hookTarget;

        if (hookTarget == address(0)) revert E_OperationDisabled();

        (bool success, bytes memory data) = hookTarget.call(abi.encodePacked(msg.data, caller));

        if (!success) RevertBytes.revertBytes(data);
    }

    function invokeHookTargetWithLock(address caller) private nonReentrant {
        invokeHookTarget(caller);
    }

    function logVaultStatus(VaultCache memory a, uint256 interestRate) internal {
        emit VaultStatus(
            a.totalShares.toUint(),
            a.totalBorrows.toAssetsUp().toUint(),
            a.accumulatedFees.toUint(),
            a.cash.toUint(),
            a.interestAccumulator,
            interestRate,
            block.timestamp
        );
    }
}

File 4 of 52 : Token.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

import {IToken, IERC20} from "../IEVault.sol";
import {Base} from "../shared/Base.sol";
import {BalanceUtils} from "../shared/BalanceUtils.sol";
import {ProxyUtils} from "../shared/lib/ProxyUtils.sol";

import "../shared/types/Types.sol";

/// @title TokenModule
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice An EVault module handling ERC20 behaviour of vault shares
abstract contract TokenModule is IToken, BalanceUtils {
    using TypesLib for uint256;

    /// @inheritdoc IERC20
    function name() public view virtual reentrantOK returns (string memory) {
        return vaultStorage.name;
    }

    /// @inheritdoc IERC20
    function symbol() public view virtual reentrantOK returns (string memory) {
        return vaultStorage.symbol;
    }

    /// @inheritdoc IERC20
    function decimals() public view virtual reentrantOK returns (uint8) {
        (IERC20 asset,,) = ProxyUtils.metadata();
        (bool success, bytes memory data) = address(asset).staticcall(abi.encodeCall(IERC20.decimals, ()));
        return success && data.length >= 32 ? abi.decode(data, (uint8)) : 18;
    }

    /// @inheritdoc IERC20
    function totalSupply() public view virtual nonReentrantView returns (uint256) {
        return loadVault().totalShares.toUint();
    }

    /// @inheritdoc IERC20
    function balanceOf(address account) public view virtual nonReentrantView returns (uint256) {
        return vaultStorage.users[account].getBalance().toUint();
    }

    /// @inheritdoc IERC20
    function allowance(address holder, address spender) public view virtual nonReentrantView returns (uint256) {
        return vaultStorage.users[holder].eTokenAllowance[spender];
    }

    /// @inheritdoc IERC20
    function transfer(address to, uint256 amount) public virtual nonReentrant returns (bool) {
        (, address account) = initOperation(OP_TRANSFER, CHECKACCOUNT_CALLER);
        return transferFromInternal(account, account, to, amount.toShares());
    }

    /// @inheritdoc IToken
    function transferFromMax(address from, address to) public virtual nonReentrant returns (bool) {
        validateTransferFromAccount(from);

        (, address account) = initOperation(OP_TRANSFER, from);

        return transferFromInternal(account, from, to, vaultStorage.users[from].getBalance());
    }

    /// @inheritdoc IERC20
    function transferFrom(address from, address to, uint256 amount) public virtual nonReentrant returns (bool) {
        validateTransferFromAccount(from);

        (, address account) = initOperation(OP_TRANSFER, from);

        return transferFromInternal(account, from, to, amount.toShares());
    }

    /// @inheritdoc IERC20
    function approve(address spender, uint256 amount) public virtual nonReentrant returns (bool) {
        address account = EVCAuthenticate();

        setAllowance(account, spender, amount);

        return true;
    }

    function transferFromInternal(address account, address from, address to, Shares shares) private returns (bool) {
        if (from == to) revert E_SelfTransfer();

        decreaseAllowance(from, account, shares);
        transferBalance(from, to, shares);

        return true;
    }

    /// @dev Disallow users from passing special addresses used in account status checks as a `from` address.
    /// @dev Special address values modify the logic of `initOperation` so they should not be allowed.
    function validateTransferFromAccount(address from) private pure {
        if (from == CHECKACCOUNT_NONE || from == CHECKACCOUNT_CALLER) revert E_BadSharesOwner();
    }
}

/// @dev Deployable module contract
contract Token is TokenModule {
    constructor(Integrations memory integrations) Base(integrations) {}
}

File 5 of 52 : Vault.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

import {IVault, IEVault, IERC4626} from "../IEVault.sol";
import {Base} from "../shared/Base.sol";
import {BalanceUtils} from "../shared/BalanceUtils.sol";
import {AssetTransfers} from "../shared/AssetTransfers.sol";
import {SafeERC20Lib} from "../shared/lib/SafeERC20Lib.sol";
import {ProxyUtils} from "../shared/lib/ProxyUtils.sol";

import "../shared/types/Types.sol";

/// @title VaultModule
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice An EVault module handling ERC4626 standard behaviour
abstract contract VaultModule is IVault, AssetTransfers, BalanceUtils {
    using TypesLib for uint256;
    using SafeERC20Lib for IERC20;

    /// @inheritdoc IERC4626
    function asset() public view virtual reentrantOK returns (address) {
        (IERC20 _asset,,) = ProxyUtils.metadata();
        return address(_asset);
    }

    /// @inheritdoc IERC4626
    function totalAssets() public view virtual nonReentrantView returns (uint256) {
        VaultCache memory vaultCache = loadVault();
        return totalAssetsInternal(vaultCache);
    }

    /// @inheritdoc IERC4626
    function convertToAssets(uint256 shares) public view virtual nonReentrantView returns (uint256) {
        VaultCache memory vaultCache = loadVault();
        return shares.toShares().toAssetsDown(vaultCache).toUint();
    }

    /// @inheritdoc IERC4626
    function convertToShares(uint256 assets) public view virtual nonReentrantView returns (uint256) {
        VaultCache memory vaultCache = loadVault();
        return assets.toAssets().toSharesDown(vaultCache).toUint();
    }

    /// @inheritdoc IERC4626
    function maxDeposit(address account) public view virtual nonReentrantView returns (uint256) {
        VaultCache memory vaultCache = loadVault();
        if (isOperationDisabled(vaultCache.hookedOps, OP_DEPOSIT)) return 0;

        // the result may underestimate due to rounding
        Assets max = maxMintInternal(vaultCache, account).toAssetsDown(vaultCache);

        // if assets round down to zero, deposit reverts with E_ZeroShares
        return max.toSharesDown(vaultCache).toUint() == 0 ? 0 : max.toUint();
    }

    /// @inheritdoc IERC4626
    function previewDeposit(uint256 assets) public view virtual nonReentrantView returns (uint256) {
        return convertToShares(assets);
    }

    /// @inheritdoc IERC4626
    function maxMint(address account) public view virtual nonReentrantView returns (uint256) {
        VaultCache memory vaultCache = loadVault();

        return isOperationDisabled(vaultCache.hookedOps, OP_MINT) ? 0 : maxMintInternal(vaultCache, account).toUint();
    }

    /// @inheritdoc IERC4626
    function previewMint(uint256 shares) public view virtual nonReentrantView returns (uint256) {
        VaultCache memory vaultCache = loadVault();
        return shares.toShares().toAssetsUp(vaultCache).toUint();
    }

    /// @inheritdoc IERC4626
    function maxWithdraw(address owner) public view virtual nonReentrantView returns (uint256) {
        VaultCache memory vaultCache = loadVault();

        return isOperationDisabled(vaultCache.hookedOps, OP_WITHDRAW)
            ? 0
            : maxRedeemInternal(vaultCache, owner).toAssetsDown(vaultCache).toUint();
    }

    /// @inheritdoc IERC4626
    function previewWithdraw(uint256 assets) public view virtual nonReentrantView returns (uint256) {
        VaultCache memory vaultCache = loadVault();
        return assets.toAssets().toSharesUp(vaultCache).toUint();
    }

    /// @inheritdoc IERC4626
    function maxRedeem(address owner) public view virtual nonReentrantView returns (uint256) {
        VaultCache memory vaultCache = loadVault();
        if (isOperationDisabled(vaultStorage.hookedOps, OP_REDEEM)) return 0;

        Shares max = maxRedeemInternal(vaultCache, owner);
        // if shares round down to zero, redeem reverts with E_ZeroAssets
        return max.toAssetsDown(vaultCache).toUint() == 0 ? 0 : max.toUint();
    }

    /// @inheritdoc IERC4626
    function previewRedeem(uint256 shares) public view virtual nonReentrantView returns (uint256) {
        return convertToAssets(shares);
    }

    /// @inheritdoc IVault
    function accumulatedFees() public view virtual nonReentrantView returns (uint256) {
        return loadVault().accumulatedFees.toUint();
    }

    /// @inheritdoc IVault
    function accumulatedFeesAssets() public view virtual nonReentrantView returns (uint256) {
        VaultCache memory vaultCache = loadVault();

        return vaultCache.accumulatedFees.toAssetsDown(vaultCache).toUint();
    }

    /// @inheritdoc IVault
    function creator() public view virtual reentrantOK returns (address) {
        return vaultStorage.creator;
    }

    /// @inheritdoc IERC4626
    function deposit(uint256 amount, address receiver) public virtual nonReentrant returns (uint256) {
        (VaultCache memory vaultCache, address account) = initOperation(OP_DEPOSIT, CHECKACCOUNT_NONE);

        Assets assets = amount == type(uint256).max ? vaultCache.asset.balanceOf(account).toAssets() : amount.toAssets();
        if (assets.isZero()) return 0;

        Shares shares = assets.toSharesDown(vaultCache);
        if (shares.isZero()) revert E_ZeroShares();

        finalizeDeposit(vaultCache, assets, shares, account, receiver);

        return shares.toUint();
    }

    /// @inheritdoc IERC4626
    function mint(uint256 amount, address receiver) public virtual nonReentrant returns (uint256) {
        (VaultCache memory vaultCache, address account) = initOperation(OP_MINT, CHECKACCOUNT_NONE);

        Shares shares = amount.toShares();
        if (shares.isZero()) return 0;

        Assets assets = shares.toAssetsUp(vaultCache);

        finalizeDeposit(vaultCache, assets, shares, account, receiver);

        return assets.toUint();
    }

    /// @inheritdoc IERC4626
    function withdraw(uint256 amount, address receiver, address owner) public virtual nonReentrant returns (uint256) {
        (VaultCache memory vaultCache, address account) = initOperation(OP_WITHDRAW, owner);

        Assets assets = amount.toAssets();
        if (assets.isZero()) return 0;

        Shares shares = assets.toSharesUp(vaultCache);

        finalizeWithdraw(vaultCache, assets, shares, account, receiver, owner);

        return shares.toUint();
    }

    /// @inheritdoc IERC4626
    function redeem(uint256 amount, address receiver, address owner) public virtual nonReentrant returns (uint256) {
        (VaultCache memory vaultCache, address account) = initOperation(OP_REDEEM, owner);

        Shares shares = amount == type(uint256).max ? vaultStorage.users[owner].getBalance() : amount.toShares();
        if (shares.isZero()) return 0;

        Assets assets = shares.toAssetsDown(vaultCache);
        if (assets.isZero()) revert E_ZeroAssets();

        finalizeWithdraw(vaultCache, assets, shares, account, receiver, owner);

        return assets.toUint();
    }

    /// @inheritdoc IVault
    function skim(uint256 amount, address receiver) public virtual nonReentrant returns (uint256) {
        (VaultCache memory vaultCache, address account) = initOperation(OP_SKIM, CHECKACCOUNT_NONE);

        Assets balance = vaultCache.asset.balanceOf(address(this)).toAssets();
        Assets available = balance <= vaultCache.cash ? Assets.wrap(0) : balance.subUnchecked(vaultCache.cash);

        Assets assets;
        if (amount == type(uint256).max) {
            assets = available;
        } else {
            assets = amount.toAssets();
            if (assets > available) revert E_InsufficientAssets();
        }
        if (assets.isZero()) return 0;

        Shares shares = assets.toSharesDown(vaultCache);
        if (shares.isZero()) revert E_ZeroShares();

        vaultStorage.cash = vaultCache.cash = vaultCache.cash + assets;
        increaseBalance(vaultCache, receiver, account, shares, assets);

        return shares.toUint();
    }

    function finalizeDeposit(
        VaultCache memory vaultCache,
        Assets assets,
        Shares shares,
        address sender,
        address receiver
    ) private {
        pullAssets(vaultCache, sender, assets);

        increaseBalance(vaultCache, receiver, sender, shares, assets);
    }

    function finalizeWithdraw(
        VaultCache memory vaultCache,
        Assets assets,
        Shares shares,
        address sender,
        address receiver,
        address owner
    ) private {
        if (vaultCache.cash < assets) revert E_InsufficientCash();

        decreaseAllowance(owner, sender, shares);
        decreaseBalance(vaultCache, owner, sender, receiver, shares, assets);

        pushAssets(vaultCache, receiver, assets);
    }

    function maxRedeemInternal(VaultCache memory vaultCache, address owner) private view returns (Shares) {
        Shares max = vaultStorage.users[owner].getBalance();

        // If account has borrows, withdrawal might be reverted by the controller during account status checks.
        // The vault has no way to verify or enforce the behaviour of the controller, which the account owner
        // has enabled. It will therefore assume that all of the assets would be withheld by the controller and
        // under-estimate the return amount to zero.
        // Integrators who handle borrowing should implement custom logic to work with the particular controllers
        // they want to support.
        if (max.isZero() || hasAnyControllerEnabled(owner)) return Shares.wrap(0);

        Shares cash = vaultCache.cash.toSharesDown(vaultCache);
        max = max > cash ? cash : max;

        return max;
    }

    function maxMintInternal(VaultCache memory vaultCache, address) private pure returns (Shares) {
        uint256 supply = totalAssetsInternal(vaultCache);
        if (supply >= vaultCache.supplyCap) return Shares.wrap(0); // at or over the supply cap already

        unchecked {
            // limit to supply cap
            uint256 max = vaultCache.supplyCap - supply;

            // limit to cash remaining space
            uint256 limit = MAX_SANE_AMOUNT - vaultCache.cash.toUint();
            max = limit < max ? limit : max;

            // limit to total shares remaining space
            max = max.toAssets().toSharesDownUint(vaultCache);
            limit = MAX_SANE_AMOUNT - vaultCache.totalShares.toUint();

            return (limit < max ? limit : max).toShares();
        }
    }
}

/// @dev Deployable module contract
contract Vault is VaultModule {
    constructor(Integrations memory integrations) Base(integrations) {}
}

File 6 of 52 : Borrowing.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

import {IBorrowing} from "../IEVault.sol";
import {Base} from "../shared/Base.sol";
import {BalanceUtils} from "../shared/BalanceUtils.sol";
import {LiquidityUtils} from "../shared/LiquidityUtils.sol";
import {AssetTransfers} from "../shared/AssetTransfers.sol";
import {SafeERC20Lib} from "../shared/lib/SafeERC20Lib.sol";
import {ProxyUtils} from "../shared/lib/ProxyUtils.sol";
import {IFlashLoan} from "../../interfaces/IFlashLoan.sol";

import "../shared/types/Types.sol";

/// @title BorrowingModule
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice An EVault module handling borrowing and repaying of vault assets
abstract contract BorrowingModule is IBorrowing, AssetTransfers, BalanceUtils, LiquidityUtils {
    using TypesLib for uint256;
    using SafeERC20Lib for IERC20;

    /// @inheritdoc IBorrowing
    function totalBorrows() public view virtual nonReentrantView returns (uint256) {
        return loadVault().totalBorrows.toAssetsUp().toUint();
    }

    /// @inheritdoc IBorrowing
    function totalBorrowsExact() public view virtual nonReentrantView returns (uint256) {
        return loadVault().totalBorrows.toUint();
    }

    /// @inheritdoc IBorrowing
    function cash() public view virtual nonReentrantView returns (uint256) {
        return vaultStorage.cash.toUint();
    }

    /// @inheritdoc IBorrowing
    function debtOf(address account) public view virtual nonReentrantView returns (uint256) {
        return getCurrentOwed(loadVault(), account).toAssetsUp().toUint();
    }

    /// @inheritdoc IBorrowing
    function debtOfExact(address account) public view virtual nonReentrantView returns (uint256) {
        return getCurrentOwed(loadVault(), account).toUint();
    }

    /// @inheritdoc IBorrowing
    function interestRate() public view virtual nonReentrantView returns (uint256) {
        return computeInterestRateView(loadVault());
    }

    /// @inheritdoc IBorrowing
    function interestAccumulator() public view virtual nonReentrantView returns (uint256) {
        return loadVault().interestAccumulator;
    }

    /// @inheritdoc IBorrowing
    function dToken() public view virtual reentrantOK returns (address) {
        return calculateDTokenAddress();
    }

    /// @inheritdoc IBorrowing
    function borrow(uint256 amount, address receiver) public virtual nonReentrant returns (uint256) {
        (VaultCache memory vaultCache, address account) = initOperation(OP_BORROW, CHECKACCOUNT_CALLER);

        Assets assets = amount == type(uint256).max ? vaultCache.cash : amount.toAssets();
        if (assets.isZero()) return 0;

        if (assets > vaultCache.cash) revert E_InsufficientCash();

        increaseBorrow(vaultCache, account, assets);

        pushAssets(vaultCache, receiver, assets);

        return assets.toUint();
    }

    /// @inheritdoc IBorrowing
    function repay(uint256 amount, address receiver) public virtual nonReentrant returns (uint256) {
        (VaultCache memory vaultCache, address account) = initOperation(OP_REPAY, CHECKACCOUNT_NONE);

        uint256 owed = getCurrentOwed(vaultCache, receiver).toAssetsUp().toUint();

        Assets assets = (amount == type(uint256).max ? owed : amount).toAssets();
        if (assets.isZero()) return 0;

        pullAssets(vaultCache, account, assets);

        decreaseBorrow(vaultCache, receiver, assets);

        return assets.toUint();
    }

    /// @inheritdoc IBorrowing
    function repayWithShares(uint256 amount, address receiver) public virtual nonReentrant returns (uint256, uint256) {
        (VaultCache memory vaultCache, address account) = initOperation(OP_REPAY_WITH_SHARES, CHECKACCOUNT_CALLER);

        Assets owed = getCurrentOwed(vaultCache, receiver).toAssetsUp();
        if (owed.isZero()) return (0, 0);

        Assets assets;
        Shares shares;

        if (amount == type(uint256).max) {
            shares = vaultStorage.users[account].getBalance();
            assets = shares.toAssetsDown(vaultCache);
        } else {
            assets = amount.toAssets();
            shares = assets.toSharesUp(vaultCache);
        }

        if (assets.isZero()) return (0, 0);

        if (assets > owed) {
            assets = owed;
            shares = assets.toSharesUp(vaultCache);
        }

        // Burn ETokens
        decreaseBalance(vaultCache, account, account, account, shares, assets);

        // Burn DTokens
        decreaseBorrow(vaultCache, receiver, assets);

        return (shares.toUint(), assets.toUint());
    }

    /// @inheritdoc IBorrowing
    function pullDebt(uint256 amount, address from) public virtual nonReentrant {
        (VaultCache memory vaultCache, address account) = initOperation(OP_PULL_DEBT, CHECKACCOUNT_CALLER);

        if (from == account) revert E_SelfTransfer();

        Assets assets = amount == type(uint256).max ? getCurrentOwed(vaultCache, from).toAssetsUp() : amount.toAssets();

        if (assets.isZero()) return;
        transferBorrow(vaultCache, from, account, assets);

        emit PullDebt(from, account, assets.toUint());
    }

    /// @inheritdoc IBorrowing
    function flashLoan(uint256 amount, bytes calldata data) public virtual nonReentrant {
        address account = EVCAuthenticate();
        callHook(vaultStorage.hookedOps, OP_FLASHLOAN, account);

        (IERC20 asset,,) = ProxyUtils.metadata();

        uint256 origBalance = asset.balanceOf(address(this));

        asset.safeTransfer(account, amount);

        IFlashLoan(account).onFlashLoan(data);

        if (asset.balanceOf(address(this)) < origBalance) revert E_FlashLoanNotRepaid();
    }

    /// @inheritdoc IBorrowing
    function touch() public virtual nonReentrant {
        initOperation(OP_TOUCH, CHECKACCOUNT_NONE);
    }
}

/// @dev Deployable module contract
contract Borrowing is BorrowingModule {
    constructor(Integrations memory integrations) Base(integrations) {}
}

File 7 of 52 : Liquidation.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

import {ILiquidation} from "../IEVault.sol";
import {Base} from "../shared/Base.sol";
import {BalanceUtils} from "../shared/BalanceUtils.sol";
import {LiquidityUtils} from "../shared/LiquidityUtils.sol";

import "../shared/types/Types.sol";

/// @title LiquidationModule
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice An EVault module handling liquidations of unhealthy accounts
abstract contract LiquidationModule is ILiquidation, BalanceUtils, LiquidityUtils {
    using TypesLib for uint256;

    // Minimum debt value, before liquidation, which enables debt socialization.
    // With small debt positions, when vault is nearly empty, rounding in the pricing oracle
    // may have an outsized impact on vault's shares to assets exchange rate after debt socialization.
    uint256 constant MIN_SOCIALIZATION_LIABILITY_VALUE = 1e6;

    struct LiquidationCache {
        address liquidator;
        address violator;
        address collateral;
        address[] collaterals;
        Assets liability;
        Assets repay;
        uint256 yieldBalance;
        uint256 liabilityValue;
    }

    /// @inheritdoc ILiquidation
    /// @dev The function will not revert if the account is healthy and return (0, 0)
    function checkLiquidation(address liquidator, address violator, address collateral)
        public
        view
        virtual
        nonReentrantView
        returns (uint256 maxRepay, uint256 maxYield)
    {
        LiquidationCache memory liqCache =
            calculateLiquidation(loadVault(), liquidator, violator, collateral, type(uint256).max);

        maxRepay = liqCache.repay.toUint();
        maxYield = liqCache.yieldBalance;
    }

    /// @inheritdoc ILiquidation
    function liquidate(address violator, address collateral, uint256 repayAssets, uint256 minYieldBalance)
        public
        virtual
        nonReentrant
    {
        (VaultCache memory vaultCache, address liquidator) = initOperation(OP_LIQUIDATE, CHECKACCOUNT_CALLER);

        LiquidationCache memory liqCache =
            calculateLiquidation(vaultCache, liquidator, violator, collateral, repayAssets);

        executeLiquidation(vaultCache, liqCache, minYieldBalance);
    }

    function calculateLiquidation(
        VaultCache memory vaultCache,
        address liquidator,
        address violator,
        address collateral,
        uint256 desiredRepay
    ) internal view returns (LiquidationCache memory liqCache) {
        // Init cache

        liqCache.liquidator = liquidator;
        liqCache.violator = violator;
        liqCache.collateral = collateral;

        liqCache.repay = Assets.wrap(0);
        liqCache.yieldBalance = 0;
        liqCache.liability = getCurrentOwed(vaultCache, violator).toAssetsUp();
        liqCache.collaterals = getCollaterals(violator);

        // Checks

        // Same account self-liquidation is not allowed
        if (liqCache.violator == liqCache.liquidator) revert E_SelfLiquidation();
        // Only liquidate trusted collaterals to make sure yield transfer has no side effects.
        if (!isRecognizedCollateral(liqCache.collateral)) revert E_BadCollateral();
        // Verify this vault is the controller for the violator
        validateController(liqCache.violator);
        // Violator must have enabled the collateral to be transferred to the liquidator
        if (!isCollateralEnabled(liqCache.violator, liqCache.collateral)) revert E_CollateralDisabled();
        // Violator's health check must not be deferred, meaning no prior operations on violator's account
        // would possibly be forgiven after the enforced collateral transfer to the liquidator
        if (isAccountStatusCheckDeferred(violator)) revert E_ViolatorLiquidityDeferred();
        // A cool off time must elapse since successful account status check in order to mitigate self-liquidaition
        // attacks
        if (isInLiquidationCoolOff(violator)) revert E_LiquidationCoolOff();

        // Violator has no liabilities, liquidation is a no-op
        if (liqCache.liability.isZero()) return liqCache;

        // Calculate max yield and repay

        liqCache = calculateMaxLiquidation(liqCache, vaultCache);

        // Adjust for desired repay

        if (desiredRepay != type(uint256).max) {
            uint256 maxRepay = liqCache.repay.toUint();
            if (desiredRepay > maxRepay) revert E_ExcessiveRepayAmount();

            if (maxRepay > 0) {
                liqCache.yieldBalance = desiredRepay * liqCache.yieldBalance / maxRepay;
                liqCache.repay = desiredRepay.toAssets();
            }
        }
    }

    function calculateMaxLiquidation(LiquidationCache memory liqCache, VaultCache memory vaultCache)
        private
        view
        returns (LiquidationCache memory)
    {
        // Check account health

        uint256 collateralAdjustedValue;
        (collateralAdjustedValue, liqCache.liabilityValue) =
            calculateLiquidity(vaultCache, liqCache.violator, liqCache.collaterals, true);

        // no violation
        if (collateralAdjustedValue > liqCache.liabilityValue || liqCache.liabilityValue == 0) {
            return liqCache;
        }

        // Compute discount

        // discountFactor = health score = 1 - discount
        uint256 discountFactor = collateralAdjustedValue * 1e18 / liqCache.liabilityValue;
        {
            uint256 minDiscountFactor;
            unchecked {
                // discount <= config scale, so discount factor >= 0
                minDiscountFactor = 1e18 - uint256(1e18) * vaultStorage.maxLiquidationDiscount.toUint16() / CONFIG_SCALE;
            }
            if (discountFactor < minDiscountFactor) discountFactor = minDiscountFactor;
        }

        // Compute maximum yield using mid-point prices

        uint256 collateralBalance = IERC20(liqCache.collateral).balanceOf(liqCache.violator);
        uint256 collateralValue =
            vaultCache.oracle.getQuote(collateralBalance, liqCache.collateral, vaultCache.unitOfAccount);

        if (collateralValue == 0) {
            // Worthless collateral can be claimed with no repay. The collateral can be actually worthless, or the
            // amount of available collateral could be non-representable in the unit of account (rounded down to zero
            // during conversion). In this case the liquidator is able to claim the collateral without repaying any
            // debt. Note that it's not profitable as long as liquidation gas costs are larger than the value of a
            // single wei of the reference asset. Care should be taken though when selecting unit of account and
            // collateral assets.
            liqCache.yieldBalance = collateralBalance;
            return liqCache;
        }

        uint256 maxRepayValue = liqCache.liabilityValue;
        uint256 maxYieldValue = maxRepayValue * 1e18 / discountFactor;

        // Limit yield to borrower's available collateral, and reduce repay if necessary. This can happen when
        // seizing all of the collateral won't bring the violator back to solvency. It can happen simply because
        // the account health is very low, or because borrower has multiple collaterals and liquidating this one
        // is not sufficient.

        if (collateralValue < maxYieldValue) {
            maxRepayValue = collateralValue * discountFactor / 1e18;
            maxYieldValue = collateralValue;
        }

        liqCache.repay = (maxRepayValue * liqCache.liability.toUint() / liqCache.liabilityValue).toAssets();
        liqCache.yieldBalance = maxYieldValue * collateralBalance / collateralValue;

        return liqCache;
    }

    function executeLiquidation(VaultCache memory vaultCache, LiquidationCache memory liqCache, uint256 minYieldBalance)
        private
    {
        // Check minimum yield.

        if (minYieldBalance > liqCache.yieldBalance) revert E_MinYield();

        // Handle repay: liquidator takes on violator's debt:

        if (liqCache.repay.toUint() > 0) {
            transferBorrow(vaultCache, liqCache.violator, liqCache.liquidator, liqCache.repay);
        }

        // Handle yield: liquidator receives violator's collateral

        // Impersonate violator on the EVC to seize collateral. The yield transfer will trigger a health check on the
        // violator's account, which should be forgiven, because the violator's account is not guaranteed to be healthy
        // after liquidation. This operation is safe, because:
        // 1. `liquidate` function is enforcing that the violator is not in deferred checks state,
        //    therefore there were no prior batch operations that could have registered a health check,
        //    and if the check is present now, it must have been triggered by the enforced transfer.
        // 2. Only collaterals with initialized LTV settings can be liquidated and they are assumed to be audited
        //    to have safe transfer methods, which make no external calls. In other words, yield transfer will not
        //    have any side effects, which would be wrongly forgiven.
        // 3. Any additional operations on violator's account in a batch will register the health check again, and it
        //    will be executed normally at the end of the batch.

        if (liqCache.yieldBalance > 0) {
            enforceCollateralTransfer(
                liqCache.collateral, liqCache.yieldBalance, liqCache.violator, liqCache.liquidator
            );

            forgiveAccountStatusCheck(liqCache.violator);
        }

        // Handle debt socialization

        if (
            liqCache.liabilityValue >= MIN_SOCIALIZATION_LIABILITY_VALUE
                && vaultCache.configFlags.isNotSet(CFG_DONT_SOCIALIZE_DEBT) && liqCache.liability > liqCache.repay
                && checkNoCollateral(liqCache.violator, liqCache.collaterals)
        ) {
            Assets owedRemaining = liqCache.liability.subUnchecked(liqCache.repay);
            decreaseBorrow(vaultCache, liqCache.violator, owedRemaining);

            // decreaseBorrow emits Repay without any assets entering the vault. Emit Withdraw from and to zero address
            // to cover the missing amount for offchain trackers.
            emit Withdraw(liqCache.liquidator, address(0), address(0), owedRemaining.toUint(), 0);
            emit DebtSocialized(liqCache.violator, owedRemaining.toUint());
        }

        emit Liquidate(
            liqCache.liquidator, liqCache.violator, liqCache.collateral, liqCache.repay.toUint(), liqCache.yieldBalance
        );
    }

    function isInLiquidationCoolOff(address account) private view returns (bool) {
        unchecked {
            return block.timestamp < getLastAccountStatusCheckTimestamp(account) + vaultStorage.liquidationCoolOffTime;
        }
    }
}

/// @dev Deployable module contract
contract Liquidation is LiquidationModule {
    constructor(Integrations memory integrations) Base(integrations) {}
}

File 8 of 52 : Initialize.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

import {IInitialize, IERC20} from "../IEVault.sol";
import {Base} from "../shared/Base.sol";
import {BorrowUtils} from "../shared/BorrowUtils.sol";
import {DToken} from "../DToken.sol";
import {ProxyUtils} from "../shared/lib/ProxyUtils.sol";
import {RevertBytes} from "../shared/lib/RevertBytes.sol";
import {AddressUtils} from "../shared/lib/AddressUtils.sol";

import "../shared/Constants.sol";
import "../shared/types/Types.sol";

/// @title InitializeModule
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice An EVault module implementing the initialization of the new vault contract
abstract contract InitializeModule is IInitialize, BorrowUtils {
    using TypesLib for uint16;

    // Initial value of the interest accumulator: 1 ray
    uint256 internal constant INITIAL_INTEREST_ACCUMULATOR = 1e27;
    // Default fee charged on newly accrued interest in CONFIG_SCALE: 10%
    uint16 internal constant DEFAULT_INTEREST_FEE = 0.1e4;

    /// @inheritdoc IInitialize
    function initialize(address proxyCreator) public virtual reentrantOK {
        if (initialized) revert E_Initialized();
        initialized = true;

        // Validate proxy immutables

        // Calldata should include: signature and abi encoded creator address (4 + 32 bytes), followed by proxy metadata
        if (msg.data.length != 4 + 32 + PROXY_METADATA_LENGTH) revert E_ProxyMetadata();
        (IERC20 asset,,) = ProxyUtils.metadata();
        // Make sure the asset is a contract. Token transfers using a library will not revert if address has no code.
        AddressUtils.checkContract(address(asset));

        // Create sidecar DToken

        address dToken = address(new DToken());

        // Initialize storage

        vaultStorage.lastInterestAccumulatorUpdate = uint48(block.timestamp);
        vaultStorage.interestAccumulator = INITIAL_INTEREST_ACCUMULATOR;
        vaultStorage.interestFee = DEFAULT_INTEREST_FEE.toConfigAmount();
        vaultStorage.creator = vaultStorage.governorAdmin = proxyCreator;
        // all operations are initially disabled
        vaultStorage.hookedOps = Flags.wrap(OP_MAX_VALUE - 1);

        {
            string memory underlyingSymbol = getTokenSymbol(address(asset));
            uint256 seqId = sequenceRegistry.reserveSeqId(underlyingSymbol);

            vaultStorage.symbol = string(abi.encodePacked("e", underlyingSymbol, "-", uintToString(seqId)));
            vaultStorage.name = string(abi.encodePacked("EVK Vault ", vaultStorage.symbol));
        }

        snapshot.reset();

        // Emit logs

        emit EVaultCreated(proxyCreator, address(asset), dToken);
        logVaultStatus(loadVault(), 0);
    }

    // prevent initialization of the implementation contract
    constructor() {
        initialized = true;
    }

    /// @dev Calls the asset's symbol() method, taking care to handle MKR-like tokens that return bytes32 instead of
    /// string. For tokens that do not implement symbol(), "UNDEFINED" will be returned.
    function getTokenSymbol(address asset) private view returns (string memory) {
        (bool success, bytes memory data) = address(asset).staticcall(abi.encodeCall(IERC20.symbol, ()));
        if (!success) return "UNDEFINED";
        return data.length <= 32 ? string(data) : abi.decode(data, (string));
    }

    /// @dev Converts a uint256 to a decimal string representation
    function uintToString(uint256 n) private pure returns (string memory) {
        unchecked {
            if (n == 0) return "0";

            uint256 len;
            for (uint256 m = n; m != 0; m /= 10) {
                len++;
            }

            bytes memory output = new bytes(len);

            while (len > 0) {
                output[--len] = bytes1(uint8(48 + n % 10)); // 48 is ASCII '0'
                n /= 10;
            }

            return string(output);
        }
    }
}

/// @dev Deployable module contract
contract Initialize is InitializeModule {
    constructor(Integrations memory integrations) Base(integrations) {}
}

File 9 of 52 : BalanceForwarder.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

import {IBalanceForwarder} from "../IEVault.sol";
import {Base} from "../shared/Base.sol";

import "../shared/types/Types.sol";

/// @title BalanceForwarderModule
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice An EVault module handling communication with a balance tracker contract.
abstract contract BalanceForwarderModule is IBalanceForwarder, Base {
    /// @inheritdoc IBalanceForwarder
    function balanceTrackerAddress() public view virtual reentrantOK returns (address) {
        return address(balanceTracker);
    }

    /// @inheritdoc IBalanceForwarder
    function balanceForwarderEnabled(address account) public view virtual nonReentrantView returns (bool) {
        return vaultStorage.users[account].isBalanceForwarderEnabled();
    }

    /// @inheritdoc IBalanceForwarder
    function enableBalanceForwarder() public virtual nonReentrant {
        if (address(balanceTracker) == address(0)) revert E_NotSupported();

        address account = EVCAuthenticate();
        UserStorage storage user = vaultStorage.users[account];

        bool wasBalanceForwarderEnabled = user.isBalanceForwarderEnabled();

        user.setBalanceForwarder(true);
        balanceTracker.balanceTrackerHook(account, user.getBalance().toUint(), false);

        if (!wasBalanceForwarderEnabled) emit BalanceForwarderStatus(account, true);
    }

    /// @inheritdoc IBalanceForwarder
    function disableBalanceForwarder() public virtual nonReentrant {
        if (address(balanceTracker) == address(0)) revert E_NotSupported();

        address account = EVCAuthenticate();
        UserStorage storage user = vaultStorage.users[account];

        bool wasBalanceForwarderEnabled = user.isBalanceForwarderEnabled();

        user.setBalanceForwarder(false);
        balanceTracker.balanceTrackerHook(account, 0, false);

        if (wasBalanceForwarderEnabled) emit BalanceForwarderStatus(account, false);
    }
}

/// @dev Deployable module contract
contract BalanceForwarder is BalanceForwarderModule {
    constructor(Integrations memory integrations) Base(integrations) {}
}

File 10 of 52 : Governance.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

import {IGovernance} from "../IEVault.sol";
import {IPriceOracle} from "../../interfaces/IPriceOracle.sol";
import {IHookTarget} from "../../interfaces/IHookTarget.sol";
import {Base} from "../shared/Base.sol";
import {BalanceUtils} from "../shared/BalanceUtils.sol";
import {LTVUtils} from "../shared/LTVUtils.sol";
import {BorrowUtils} from "../shared/BorrowUtils.sol";
import {ProxyUtils} from "../shared/lib/ProxyUtils.sol";

import "../shared/types/Types.sol";

/// @title GovernanceModule
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice An EVault module handling governance, including configuration and fees
abstract contract GovernanceModule is IGovernance, BalanceUtils, BorrowUtils, LTVUtils {
    using TypesLib for uint16;

    // Protocol guarantees for the governor

    // Governor is guaranteed that the protocol fee share will not exceed this value
    uint16 internal constant MAX_PROTOCOL_FEE_SHARE = 0.5e4;
    // Governor is guaranteed to be able to set the interest fee to a value within a certain range.
    // Outside this range, the interest fee must be approved by ProtocolConfig.
    // Lower bound of the guaranteed range
    uint16 internal constant GUARANTEED_INTEREST_FEE_MIN = 0.1e4;
    // Higher bound of the guaranteed range
    uint16 internal constant GUARANTEED_INTEREST_FEE_MAX = 1e4;

    /// @notice Set a governor address for the EVault
    /// @param newGovernorAdmin Address of the new governor
    event GovSetGovernorAdmin(address indexed newGovernorAdmin);

    /// @notice Set a fee receiver address
    /// @param newFeeReceiver Address of the new fee receiver
    event GovSetFeeReceiver(address indexed newFeeReceiver);

    /// @notice Set new LTV configuration for a collateral
    /// @param collateral Address of the collateral
    /// @param borrowLTV The new LTV for the collateral, used to determine health of the account during regular
    /// operations, in 1e4 scale
    /// @param liquidationLTV The new LTV for the collateral, used to determine health of the account during
    /// liquidations, in 1e4 scale
    /// @param initialLiquidationLTV The previous liquidation LTV at the moment a new configuration was set
    /// @param targetTimestamp If the LTV is lowered, the timestamp when the ramped liquidation LTV will merge with the
    /// `targetLTV`
    /// @param rampDuration If the LTV is lowered, duration in seconds, during which the liquidation LTV will be merging
    /// with `targetLTV`
    event GovSetLTV(
        address indexed collateral,
        uint16 borrowLTV,
        uint16 liquidationLTV,
        uint16 initialLiquidationLTV,
        uint48 targetTimestamp,
        uint32 rampDuration
    );

    /// @notice Set an interest rate model contract address
    /// @param newInterestRateModel Address of the new IRM
    event GovSetInterestRateModel(address newInterestRateModel);

    /// @notice Set a maximum liquidation discount
    /// @param newDiscount The new maximum liquidation discount in 1e4 scale
    event GovSetMaxLiquidationDiscount(uint16 newDiscount);

    /// @notice Set a new liquidation cool off time, which must elapse after successful account status check, before
    /// account can be liquidated
    /// @param newCoolOffTime The new liquidation cool off time in seconds
    event GovSetLiquidationCoolOffTime(uint16 newCoolOffTime);

    /// @notice Set new hooks configuration
    /// @param newHookTarget Address of the new hook target contract
    /// @param newHookedOps A bitfield of operations to be hooked. See Constants.sol for a list of operations
    event GovSetHookConfig(address indexed newHookTarget, uint32 newHookedOps);

    /// @notice Set new configuration flags
    /// @param newConfigFlags New configuration flags. See Constants.sol for a list of configuration flags
    event GovSetConfigFlags(uint32 newConfigFlags);

    /// @notice Set new caps
    /// @param newSupplyCap New supply cap in AmountCap format
    /// @param newBorrowCap New borrow cap in AmountCap format
    event GovSetCaps(uint16 newSupplyCap, uint16 newBorrowCap);

    /// @notice Set new interest fee
    /// @param newFee New interest fee as percentage in 1e4 scale
    event GovSetInterestFee(uint16 newFee);

    modifier governorOnly() {
        if (vaultStorage.governorAdmin != EVCAuthenticateGovernor()) revert E_Unauthorized();
        _;
    }

    /// @inheritdoc IGovernance
    function governorAdmin() public view virtual reentrantOK returns (address) {
        return vaultStorage.governorAdmin;
    }

    /// @inheritdoc IGovernance
    function feeReceiver() public view virtual reentrantOK returns (address) {
        return vaultStorage.feeReceiver;
    }

    /// @inheritdoc IGovernance
    function interestFee() public view virtual reentrantOK returns (uint16) {
        return vaultStorage.interestFee.toUint16();
    }

    /// @inheritdoc IGovernance
    function interestRateModel() public view virtual reentrantOK returns (address) {
        return vaultStorage.interestRateModel;
    }

    /// @inheritdoc IGovernance
    function protocolConfigAddress() public view virtual reentrantOK returns (address) {
        return address(protocolConfig);
    }

    /// @inheritdoc IGovernance
    function protocolFeeShare() public view virtual reentrantOK returns (uint256) {
        if (vaultStorage.feeReceiver == address(0)) return CONFIG_SCALE;

        (, uint256 protocolShare) = protocolConfig.protocolFeeConfig(address(this));
        if (protocolShare > MAX_PROTOCOL_FEE_SHARE) return MAX_PROTOCOL_FEE_SHARE;

        return protocolShare;
    }

    /// @inheritdoc IGovernance
    function protocolFeeReceiver() public view virtual reentrantOK returns (address) {
        (address protocolReceiver,) = protocolConfig.protocolFeeConfig(address(this));
        return protocolReceiver;
    }

    /// @inheritdoc IGovernance
    function caps() public view virtual reentrantOK returns (uint16, uint16) {
        return (vaultStorage.supplyCap.toRawUint16(), vaultStorage.borrowCap.toRawUint16());
    }

    /// @inheritdoc IGovernance
    function LTVBorrow(address collateral) public view virtual reentrantOK returns (uint16) {
        return getLTV(collateral, false).toUint16();
    }

    /// @inheritdoc IGovernance
    function LTVLiquidation(address collateral) public view virtual reentrantOK returns (uint16) {
        return getLTV(collateral, true).toUint16();
    }

    /// @inheritdoc IGovernance
    function LTVFull(address collateral)
        public
        view
        virtual
        reentrantOK
        returns (uint16, uint16, uint16, uint48, uint32)
    {
        LTVConfig memory ltv = vaultStorage.ltvLookup[collateral];
        return (
            ltv.borrowLTV.toUint16(),
            ltv.liquidationLTV.toUint16(),
            ltv.initialLiquidationLTV.toUint16(),
            ltv.targetTimestamp,
            ltv.rampDuration
        );
    }

    /// @inheritdoc IGovernance
    function LTVList() public view virtual reentrantOK returns (address[] memory) {
        return vaultStorage.ltvList;
    }

    /// @inheritdoc IGovernance
    function maxLiquidationDiscount() public view virtual reentrantOK returns (uint16) {
        return vaultStorage.maxLiquidationDiscount.toUint16();
    }

    /// @inheritdoc IGovernance
    function liquidationCoolOffTime() public view virtual reentrantOK returns (uint16) {
        return vaultStorage.liquidationCoolOffTime;
    }

    /// @inheritdoc IGovernance
    function hookConfig() public view virtual reentrantOK returns (address, uint32) {
        return (vaultStorage.hookTarget, vaultStorage.hookedOps.toUint32());
    }

    /// @inheritdoc IGovernance
    function configFlags() public view virtual reentrantOK returns (uint32) {
        return vaultStorage.configFlags.toUint32();
    }

    /// @inheritdoc IGovernance
    function EVC() public view virtual reentrantOK returns (address) {
        return address(evc);
    }

    /// @inheritdoc IGovernance
    function unitOfAccount() public view virtual reentrantOK returns (address) {
        (,, address _unitOfAccount) = ProxyUtils.metadata();
        return _unitOfAccount;
    }

    /// @inheritdoc IGovernance
    function oracle() public view virtual reentrantOK returns (address) {
        (, IPriceOracle _oracle,) = ProxyUtils.metadata();
        return address(_oracle);
    }

    /// @inheritdoc IGovernance
    function permit2Address() public view virtual reentrantOK returns (address) {
        return permit2;
    }

    /// @inheritdoc IGovernance
    function convertFees() public virtual nonReentrant {
        (VaultCache memory vaultCache, address account) = initOperation(OP_CONVERT_FEES, CHECKACCOUNT_NONE);

        if (vaultCache.accumulatedFees.isZero()) return;

        (address protocolReceiver, uint16 protocolFee) = protocolConfig.protocolFeeConfig(address(this));
        address governorReceiver = vaultStorage.feeReceiver;

        if (governorReceiver == address(0)) {
            protocolFee = CONFIG_SCALE; // governor forfeits fees
        } else if (protocolFee > MAX_PROTOCOL_FEE_SHARE) {
            protocolFee = MAX_PROTOCOL_FEE_SHARE;
        }

        Shares governorShares = vaultCache.accumulatedFees.mulDiv(CONFIG_SCALE - protocolFee, CONFIG_SCALE);
        Shares protocolShares = vaultCache.accumulatedFees - governorShares;

        // Decrease totalShares because increaseBalance will increase it by that total amount
        vaultStorage.totalShares = vaultCache.totalShares = vaultCache.totalShares - vaultCache.accumulatedFees;

        vaultStorage.accumulatedFees = vaultCache.accumulatedFees = Shares.wrap(0);

        // For the Deposit events in increaseBalance the assets amount is zero - the shares are covered with the accrued
        // interest
        if (!governorShares.isZero()) {
            increaseBalance(vaultCache, governorReceiver, address(0), governorShares, Assets.wrap(0));
        }

        if (!protocolShares.isZero()) {
            increaseBalance(vaultCache, protocolReceiver, address(0), protocolShares, Assets.wrap(0));
        }

        emit ConvertFees(account, protocolReceiver, governorReceiver, protocolShares.toUint(), governorShares.toUint());
    }

    /// @inheritdoc IGovernance
    function setGovernorAdmin(address newGovernorAdmin) public virtual nonReentrant governorOnly {
        vaultStorage.governorAdmin = newGovernorAdmin;
        emit GovSetGovernorAdmin(newGovernorAdmin);
    }

    /// @inheritdoc IGovernance
    function setFeeReceiver(address newFeeReceiver) public virtual nonReentrant governorOnly {
        vaultStorage.feeReceiver = newFeeReceiver;
        emit GovSetFeeReceiver(newFeeReceiver);
    }

    /// @inheritdoc IGovernance
    /// @dev When the collateral asset is no longer deemed suitable to sustain debt, its LTV setting can be set to 0.
    /// Setting a zero liquidation LTV also enforces a zero borrowing LTV (`newBorrowLTV <= newLiquidationLTV`).
    /// In such cases, the collateral becomes immediately ineffective for new borrows. However, for liquidation
    /// purposes, the LTV can be ramped down over a period of time (`rampDuration`). This ramping helps users avoid hard
    /// liquidations with maximum discounts and gives them a chance to close their positions in an orderly fashion.
    /// The choice of `rampDuration` depends on market conditions assessed by the governor. They may decide to forgo
    /// the ramp entirely by setting the duration to zero, presumably in light of extreme market conditions, where
    /// ramping  would pose a threat to the vault's solvency. In any case, when the liquidation LTV reaches its target
    /// of 0, this asset will no longer support the debt, but it will still be possible to liquidate it at a discount
    /// and use the proceeds to repay an unhealthy loan.
    /// Setting the LTV to zero will not be sufficient if the collateral is found to be unsafe to call liquidation on,
    /// either due to a bug or a code upgrade that allows its transfer function to make arbitrary external calls.
    /// In such cases, pausing the vault and conducting an orderly wind-down is recommended.
    function setLTV(address collateral, uint16 borrowLTV, uint16 liquidationLTV, uint32 rampDuration)
        public
        virtual
        nonReentrant
        governorOnly
    {
        // self-collateralization is not allowed
        if (collateral == address(this)) revert E_InvalidLTVAsset();

        ConfigAmount newBorrowLTV = borrowLTV.toConfigAmount();
        ConfigAmount newLiquidationLTV = liquidationLTV.toConfigAmount();

        // The borrow LTV must be lower than or equal to the converged liquidation LTV
        if (newBorrowLTV > newLiquidationLTV) revert E_LTVBorrow();

        LTVConfig memory currentLTV = vaultStorage.ltvLookup[collateral];

        // If new LTV is higher or equal to current, as per ramping configuration, it should take effect immediately
        if (newLiquidationLTV >= currentLTV.getLTV(true) && rampDuration > 0) revert E_LTVLiquidation();

        LTVConfig memory newLTV = currentLTV.setLTV(newBorrowLTV, newLiquidationLTV, rampDuration);

        vaultStorage.ltvLookup[collateral] = newLTV;

        if (!currentLTV.isRecognizedCollateral()) vaultStorage.ltvList.push(collateral);

        emit GovSetLTV(
            collateral,
            newLTV.borrowLTV.toUint16(),
            newLTV.liquidationLTV.toUint16(),
            newLTV.initialLiquidationLTV.toUint16(),
            newLTV.targetTimestamp,
            newLTV.rampDuration
        );
    }

    /// @inheritdoc IGovernance
    function setMaxLiquidationDiscount(uint16 newDiscount) public virtual nonReentrant governorOnly {
        // Discount equal 1e4 would cause division by zero error during liquidation
        if (newDiscount == CONFIG_SCALE) revert E_BadMaxLiquidationDiscount();

        vaultStorage.maxLiquidationDiscount = newDiscount.toConfigAmount();
        emit GovSetMaxLiquidationDiscount(newDiscount);
    }

    /// @inheritdoc IGovernance
    function setLiquidationCoolOffTime(uint16 newCoolOffTime) public virtual nonReentrant governorOnly {
        vaultStorage.liquidationCoolOffTime = newCoolOffTime;
        emit GovSetLiquidationCoolOffTime(newCoolOffTime);
    }

    /// @inheritdoc IGovernance
    function setInterestRateModel(address newModel) public virtual nonReentrant governorOnly {
        VaultCache memory vaultCache = updateVault();

        vaultStorage.interestRateModel = newModel;
        vaultStorage.interestRate = 0;

        uint256 newInterestRate = computeInterestRate(vaultCache);

        logVaultStatus(vaultCache, newInterestRate);

        emit GovSetInterestRateModel(newModel);
    }

    /// @inheritdoc IGovernance
    function setHookConfig(address newHookTarget, uint32 newHookedOps) public virtual nonReentrant governorOnly {
        if (
            newHookTarget != address(0)
                && IHookTarget(newHookTarget).isHookTarget() != IHookTarget.isHookTarget.selector
        ) revert E_NotHookTarget();

        if (newHookedOps >= OP_MAX_VALUE) revert E_NotSupported();

        vaultStorage.hookTarget = newHookTarget;
        vaultStorage.hookedOps = Flags.wrap(newHookedOps);
        emit GovSetHookConfig(newHookTarget, newHookedOps);
    }

    /// @inheritdoc IGovernance
    function setConfigFlags(uint32 newConfigFlags) public virtual nonReentrant governorOnly {
        if (newConfigFlags >= CFG_MAX_VALUE) revert E_NotSupported();

        vaultStorage.configFlags = Flags.wrap(newConfigFlags);
        emit GovSetConfigFlags(newConfigFlags);
    }

    /// @inheritdoc IGovernance
    function setCaps(uint16 supplyCap, uint16 borrowCap) public virtual nonReentrant governorOnly {
        AmountCap _supplyCap = AmountCap.wrap(supplyCap);
        // The raw uint16 cap amount == 0 is a special value. See comments in AmountCap.sol
        // Max total assets is a sum of max pool size and max total debt, both Assets type
        if (supplyCap != 0 && _supplyCap.resolve() > 2 * MAX_SANE_AMOUNT) revert E_BadSupplyCap();

        AmountCap _borrowCap = AmountCap.wrap(borrowCap);
        if (borrowCap != 0 && _borrowCap.resolve() > MAX_SANE_AMOUNT) revert E_BadBorrowCap();

        vaultStorage.supplyCap = _supplyCap;
        vaultStorage.borrowCap = _borrowCap;

        emit GovSetCaps(supplyCap, borrowCap);
    }

    /// @inheritdoc IGovernance
    function setInterestFee(uint16 newInterestFee) public virtual nonReentrant governorOnly {
        // Update vault to apply the current interest fee to the pending interest
        VaultCache memory vaultCache = updateVault();
        logVaultStatus(vaultCache, vaultStorage.interestRate);

        // Interest fees in guaranteed range are always allowed, otherwise ask protocolConfig
        if (newInterestFee < GUARANTEED_INTEREST_FEE_MIN || newInterestFee > GUARANTEED_INTEREST_FEE_MAX) {
            if (!protocolConfig.isValidInterestFee(address(this), newInterestFee)) revert E_BadFee();
        }

        vaultStorage.interestFee = newInterestFee.toConfigAmount();

        emit GovSetInterestFee(newInterestFee);
    }
}

/// @dev Deployable module contract
contract Governance is GovernanceModule {
    constructor(Integrations memory integrations) Base(integrations) {}
}

File 11 of 52 : RiskManager.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

import {IRiskManager} from "../IEVault.sol";
import {Base} from "../shared/Base.sol";
import {LiquidityUtils} from "../shared/LiquidityUtils.sol";

import "../shared/types/Types.sol";

/// @title RiskManagerModule
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice An EVault module handling risk management, including vault and account health checks
abstract contract RiskManagerModule is IRiskManager, LiquidityUtils {
    /// @inheritdoc IRiskManager
    function accountLiquidity(address account, bool liquidation)
        public
        view
        virtual
        nonReentrantView
        returns (uint256 collateralValue, uint256 liabilityValue)
    {
        VaultCache memory vaultCache = loadVault();

        validateController(account);
        address[] memory collaterals = getCollaterals(account);

        return calculateLiquidity(vaultCache, account, collaterals, liquidation);
    }

    /// @inheritdoc IRiskManager
    function accountLiquidityFull(address account, bool liquidation)
        public
        view
        virtual
        nonReentrantView
        returns (address[] memory collaterals, uint256[] memory collateralValues, uint256 liabilityValue)
    {
        VaultCache memory vaultCache = loadVault();

        validateController(account);
        validateOracle(vaultCache);
        collaterals = getCollaterals(account);
        collateralValues = new uint256[](collaterals.length);

        for (uint256 i; i < collaterals.length; ++i) {
            collateralValues[i] = getCollateralValue(vaultCache, account, collaterals[i], liquidation);
        }

        liabilityValue = getLiabilityValue(vaultCache, account, vaultStorage.users[account].getOwed(), liquidation);
    }

    /// @inheritdoc IRiskManager
    function disableController() public virtual nonReentrant {
        address account = EVCAuthenticate();

        if (!vaultStorage.users[account].getOwed().isZero()) revert E_OutstandingDebt();

        disableControllerInternal(account);
    }

    /// @inheritdoc IRiskManager
    /// @dev The function doesn't have a reentrancy lock, because onlyEVCChecks provides equivalent behaviour. It
    /// ensures that the caller is the EVC, in 'checks in progress' state. In this state EVC will not accept any calls.
    /// Since all the functions which modify vault state use callThroughEVC modifier, they are effectively blocked while
    /// the function executes. There are non-view functions without `callThroughEVC` modifier (`flashLoan`,
    /// `disableController`), but they don't change the vault's storage.
    function checkAccountStatus(address account, address[] calldata collaterals)
        public
        view
        virtual
        reentrantOK
        onlyEVCChecks
        returns (bytes4 magicValue)
    {
        checkLiquidity(loadVault(), account, collaterals);

        magicValue = IEVCVault.checkAccountStatus.selector;
    }

    /// @inheritdoc IRiskManager
    /// @dev See comment about reentrancy for `checkAccountStatus`
    function checkVaultStatus() public virtual reentrantOK onlyEVCChecks returns (bytes4 magicValue) {
        // Use the updating variant to make sure interest is accrued in storage before the interest rate update.
        // Because of interest rate retargetting during the vault status check, the vault status check must not be
        // forgiven.
        VaultCache memory vaultCache = updateVault();
        uint256 newInterestRate = computeInterestRate(vaultCache);

        logVaultStatus(vaultCache, newInterestRate);

        // We use the snapshot to check if the borrows or supply grew, and if so then we check the borrow and supply
        // caps. If snapshot is initialized, then caps are configured. If caps are set in the middle of a batch, then
        // snapshots represent the state of the vault at that time.
        if (vaultCache.snapshotInitialized) {
            vaultStorage.snapshotInitialized = vaultCache.snapshotInitialized = false;

            Assets snapshotCash = snapshot.cash;
            Assets snapshotBorrows = snapshot.borrows;

            uint256 prevBorrows = snapshotBorrows.toUint();
            uint256 borrows = vaultCache.totalBorrows.toAssetsUp().toUint();

            if (borrows > vaultCache.borrowCap && borrows > prevBorrows) revert E_BorrowCapExceeded();

            uint256 prevSupply = snapshotCash.toUint() + prevBorrows;

            // Borrows are rounded down, because total assets could increase during repays.
            // This could happen when repaid user debt is rounded up to assets and used to increase cash,
            // while totalBorrows would be adjusted by only the exact debt, less than the increase in cash.
            // If multiple accounts need to repay while the supply cap is exceeded they should do so in
            // separate batches.
            uint256 supply = vaultCache.cash.toUint() + vaultCache.totalBorrows.toAssetsDown().toUint();

            if (supply > vaultCache.supplyCap && supply > prevSupply) revert E_SupplyCapExceeded();

            snapshot.reset();
        }

        callHookWithLock(vaultCache.hookedOps, OP_VAULT_STATUS_CHECK, address(evc));

        magicValue = IEVCVault.checkVaultStatus.selector;
    }
}

/// @dev Deployable module contract
contract RiskManager is RiskManagerModule {
    constructor(Integrations memory integrations) Base(integrations) {}
}

File 12 of 52 : AddressUtils.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import "../Errors.sol";

/// @title AddressUtils Library
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice The library provides a helper function for checking if provided address is a contract (has code)
library AddressUtils {
    function checkContract(address addr) internal view returns (address) {
        if (addr.code.length == 0) revert Errors.E_BadAddress();

        return addr;
    }
}

File 13 of 52 : Constants.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

// Implementation internals

// asset amounts are shifted left by this number of bits for increased precision of debt tracking.
uint256 constant INTERNAL_DEBT_PRECISION_SHIFT = 31;
// max amount for Assets and Shares custom types based on a uint112.
uint256 constant MAX_SANE_AMOUNT = type(uint112).max;
// max debt amount fits in uint144 (112 + 31 bits).
// Last 31 bits are zeros to ensure max debt rounded up equals max sane amount.
uint256 constant MAX_SANE_DEBT_AMOUNT = uint256(MAX_SANE_AMOUNT) << INTERNAL_DEBT_PRECISION_SHIFT;
// proxy trailing calldata length in bytes.
// Three addresses, 20 bytes each: vault underlying asset, oracle and unit of account + 4 empty bytes.
uint256 constant PROXY_METADATA_LENGTH = 64;
// gregorian calendar
uint256 constant SECONDS_PER_YEAR = 365.2425 * 86400;
// max interest rate accepted from IRM. 1,000,000% APY: floor(((1000000 / 100 + 1)**(1/(86400*365.2425)) - 1) * 1e27)
uint256 constant MAX_ALLOWED_INTEREST_RATE = 291867278914945094175;
// max valid value of the ConfigAmount custom type, signifying 100%
uint16 constant CONFIG_SCALE = 1e4;

// Account status checks special values

// no account status checks should be scheduled
address constant CHECKACCOUNT_NONE = address(0);
// account status check should be scheduled for the authenticated account
address constant CHECKACCOUNT_CALLER = address(1);

// Operations

uint32 constant OP_DEPOSIT = 1 << 0;
uint32 constant OP_MINT = 1 << 1;
uint32 constant OP_WITHDRAW = 1 << 2;
uint32 constant OP_REDEEM = 1 << 3;
uint32 constant OP_TRANSFER = 1 << 4;
uint32 constant OP_SKIM = 1 << 5;
uint32 constant OP_BORROW = 1 << 6;
uint32 constant OP_REPAY = 1 << 7;
uint32 constant OP_REPAY_WITH_SHARES = 1 << 8;
uint32 constant OP_PULL_DEBT = 1 << 9;
uint32 constant OP_CONVERT_FEES = 1 << 10;
uint32 constant OP_LIQUIDATE = 1 << 11;
uint32 constant OP_FLASHLOAN = 1 << 12;
uint32 constant OP_TOUCH = 1 << 13;
uint32 constant OP_VAULT_STATUS_CHECK = 1 << 14;
// Delimiter of possible operations
uint32 constant OP_MAX_VALUE = 1 << 15;

// Config Flags

// When flag is set, debt socialization during liquidation is disabled
uint32 constant CFG_DONT_SOCIALIZE_DEBT = 1 << 0;
// When flag is set, asset is considered to be compatible with EVC sub-accounts and protections
// against sending assets to sub-accounts are disabled
uint32 constant CFG_EVC_COMPATIBLE_ASSET = 1 << 1;
// Delimiter of possible config flags
uint32 constant CFG_MAX_VALUE = 1 << 2;

// EVC authentication

// in order to perform these operations, the account doesn't need to have the vault installed as a controller
uint32 constant CONTROLLER_NEUTRAL_OPS = OP_DEPOSIT | OP_MINT | OP_WITHDRAW | OP_REDEEM | OP_TRANSFER | OP_SKIM
    | OP_REPAY | OP_REPAY_WITH_SHARES | OP_CONVERT_FEES | OP_FLASHLOAN | OP_TOUCH | OP_VAULT_STATUS_CHECK;

File 14 of 52 : EVCClient.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Storage} from "./Storage.sol";
import {Events} from "./Events.sol";
import {Errors} from "./Errors.sol";
import {ProxyUtils} from "./lib/ProxyUtils.sol";
import {AddressUtils} from "./lib/AddressUtils.sol";

import "./Constants.sol";

import {IERC20} from "../IEVault.sol";
import {IEVC} from "ethereum-vault-connector/interfaces/IEthereumVaultConnector.sol";

/// @title EVCClient
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Utilities for interacting with the EVC (Ethereum Vault Connector)
abstract contract EVCClient is Storage, Events, Errors {
    IEVC internal immutable evc;

    modifier onlyEVCChecks() {
        if (msg.sender != address(evc) || !evc.areChecksInProgress()) {
            revert E_CheckUnauthorized();
        }

        _;
    }

    constructor(address _evc) {
        evc = IEVC(AddressUtils.checkContract(_evc));
    }

    function disableControllerInternal(address account) internal virtual {
        evc.disableController(account);
    }

    // Authenticate the account and the controller, making sure the call is made through EVC and the status checks are
    // deferred
    function EVCAuthenticateDeferred(bool checkController) internal view virtual returns (address) {
        assert(msg.sender == address(evc)); // this ensures that callThroughEVC modifier was utilized

        (address onBehalfOfAccount, bool controllerEnabled) =
            evc.getCurrentOnBehalfOfAccount(checkController ? address(this) : address(0));

        if (checkController && !controllerEnabled) revert E_ControllerDisabled();

        return onBehalfOfAccount;
    }

    // Authenticate the account
    function EVCAuthenticate() internal view virtual returns (address) {
        if (msg.sender == address(evc)) {
            (address onBehalfOfAccount,) = evc.getCurrentOnBehalfOfAccount(address(0));

            return onBehalfOfAccount;
        }
        return msg.sender;
    }

    // Authenticate the governor, making sure neither a sub-account nor operator is used. Prohibit the use of control
    // collateral
    function EVCAuthenticateGovernor() internal view virtual returns (address) {
        if (msg.sender == address(evc)) {
            (address onBehalfOfAccount,) = evc.getCurrentOnBehalfOfAccount(address(0));

            if (
                isKnownNonOwnerAccount(onBehalfOfAccount) || evc.isOperatorAuthenticated()
                    || evc.isControlCollateralInProgress()
            ) {
                revert E_Unauthorized();
            }

            return onBehalfOfAccount;
        }
        return msg.sender;
    }

    // Checks if the account is known to EVC to be a non-owner sub-account.
    // Assets that are not EVC integrated should not be sent to those accounts,
    // as there will be no way to transfer them out.
    function isKnownNonOwnerAccount(address account) internal view returns (bool) {
        address owner = evc.getAccountOwner(account);
        return owner != address(0) && owner != account;
    }

    function EVCRequireStatusChecks(address account) internal virtual {
        assert(account != CHECKACCOUNT_CALLER); // the special value should be resolved by now

        if (account == CHECKACCOUNT_NONE) {
            evc.requireVaultStatusCheck();
        } else {
            evc.requireAccountAndVaultStatusCheck(account);
        }
    }

    function enforceCollateralTransfer(address collateral, uint256 amount, address from, address receiver)
        internal
        virtual
    {
        evc.controlCollateral(collateral, from, 0, abi.encodeCall(IERC20.transfer, (receiver, amount)));
    }

    function forgiveAccountStatusCheck(address account) internal virtual {
        evc.forgiveAccountStatusCheck(account);
    }

    function hasAnyControllerEnabled(address account) internal view returns (bool) {
        return evc.getControllers(account).length > 0;
    }

    function getCollaterals(address account) internal view returns (address[] memory) {
        return evc.getCollaterals(account);
    }

    function isCollateralEnabled(address account, address collateral) internal view returns (bool) {
        return evc.isCollateralEnabled(account, collateral);
    }

    function isAccountStatusCheckDeferred(address account) internal view returns (bool) {
        return evc.isAccountStatusCheckDeferred(account);
    }

    function isVaultStatusCheckDeferred() internal view returns (bool) {
        return evc.isVaultStatusCheckDeferred(address(this));
    }

    function isControlCollateralInProgress() internal view returns (bool) {
        return evc.isControlCollateralInProgress();
    }

    function getLastAccountStatusCheckTimestamp(address account) internal view returns (uint256) {
        return evc.getLastAccountStatusCheckTimestamp(account);
    }

    function validateController(address account) internal view {
        address[] memory controllers = evc.getControllers(account);

        if (controllers.length > 1) revert E_TransientState();
        if (controllers.length == 0) revert E_NoLiability();
        if (controllers[0] != address(this)) revert E_NotController();
    }
}

File 15 of 52 : Cache.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Storage} from "./Storage.sol";
import {Errors} from "./Errors.sol";
import {RPow} from "./lib/RPow.sol";
import {SafeERC20Lib} from "./lib/SafeERC20Lib.sol";
import {ProxyUtils} from "./lib/ProxyUtils.sol";

import "./types/Types.sol";

/// @title Cache
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Utilities for loading vault storage and updating it with interest accrued
contract Cache is Storage, Errors {
    using TypesLib for uint256;

    // Returns an updated VaultCache
    // If different from VaultStorage, updates VaultStorage
    function updateVault() internal virtual returns (VaultCache memory vaultCache) {
        if (initVaultCache(vaultCache)) {
            vaultStorage.lastInterestAccumulatorUpdate = vaultCache.lastInterestAccumulatorUpdate;
            vaultStorage.accumulatedFees = vaultCache.accumulatedFees;

            vaultStorage.totalShares = vaultCache.totalShares;
            vaultStorage.totalBorrows = vaultCache.totalBorrows;

            vaultStorage.interestAccumulator = vaultCache.interestAccumulator;
        }
    }

    // Returns an updated VaultCache
    function loadVault() internal view virtual returns (VaultCache memory vaultCache) {
        initVaultCache(vaultCache);
    }

    // Takes a VaultCache struct, overwrites it with VaultStorage data and, if time has passed since VaultStorage
    // was last updated, updates VaultStorage.
    // Returns a boolean if the cache is different from storage. VaultCache param is updated to this block.
    function initVaultCache(VaultCache memory vaultCache) internal view returns (bool dirty) {
        dirty = false;

        // Proxy metadata

        (vaultCache.asset, vaultCache.oracle, vaultCache.unitOfAccount) = ProxyUtils.metadata();

        // Storage loads

        vaultCache.lastInterestAccumulatorUpdate = vaultStorage.lastInterestAccumulatorUpdate;
        vaultCache.cash = vaultStorage.cash;
        vaultCache.supplyCap = vaultStorage.supplyCap.resolve();
        vaultCache.borrowCap = vaultStorage.borrowCap.resolve();
        vaultCache.hookedOps = vaultStorage.hookedOps;
        vaultCache.snapshotInitialized = vaultStorage.snapshotInitialized;

        vaultCache.totalShares = vaultStorage.totalShares;
        vaultCache.totalBorrows = vaultStorage.totalBorrows;

        vaultCache.accumulatedFees = vaultStorage.accumulatedFees;
        vaultCache.configFlags = vaultStorage.configFlags;

        vaultCache.interestAccumulator = vaultStorage.interestAccumulator;

        // Update interest accumulator and fees balance

        uint256 deltaT = block.timestamp - vaultCache.lastInterestAccumulatorUpdate;
        if (deltaT > 0) {
            dirty = true;

            // Compute new cache values. Use full precision for intermediate results.

            ConfigAmount interestFee = vaultStorage.interestFee;
            uint256 interestRate = vaultStorage.interestRate;

            uint256 newInterestAccumulator = vaultCache.interestAccumulator;
            uint256 newTotalBorrows = vaultCache.totalBorrows.toUint();

            unchecked {
                uint256 intermediate;
                (uint256 multiplier, bool overflow) = RPow.rpow(interestRate + 1e27, deltaT, 1e27);

                // if exponentiation or accumulator update overflows, keep the old accumulator
                if (!overflow) {
                    intermediate = newInterestAccumulator * multiplier;
                    if (newInterestAccumulator == intermediate / multiplier) {
                        newInterestAccumulator = intermediate / 1e27;
                    }
                }

                intermediate = newTotalBorrows * newInterestAccumulator;
                if (newTotalBorrows == intermediate / newInterestAccumulator) {
                    newTotalBorrows = intermediate / vaultCache.interestAccumulator;
                }
            }

            uint256 newAccumulatedFees = vaultCache.accumulatedFees.toUint();
            uint256 newTotalShares = vaultCache.totalShares.toUint();
            uint256 feeAssets = (newTotalBorrows - vaultCache.totalBorrows.toUint()) * interestFee.toUint16()
                / (uint256(CONFIG_SCALE) << INTERNAL_DEBT_PRECISION_SHIFT);

            if (feeAssets != 0) {
                // Fee shares are minted at a slightly worse price than user deposits (unless the exchange rate of
                // shares to assets is < 1, which is only possible in an extreme case of large debt socialization). The
                // discrepancy arises because, firstly, the virtual deposit is not accounted for, and secondly, all new
                // interest is included in the total assets during the minting process, whereas during a regular user
                // operation, the pre-money conversion is performed. This behavior is considered safe and reduces code
                // complexity and gas costs, while its effect is positive for regular users (unless the exchange rate is
                // abnormally < 1)
                uint256 newTotalAssets = vaultCache.cash.toUint() + OwedLib.toAssetsUpUint(newTotalBorrows);
                newTotalShares = newTotalAssets * newTotalShares / (newTotalAssets - feeAssets);
                newAccumulatedFees += newTotalShares - vaultCache.totalShares.toUint();
            }

            // Store new values in vaultCache, only if no overflows will occur. Fees are not larger than total shares,
            // since they are included in them.
            if (newTotalBorrows <= MAX_SANE_DEBT_AMOUNT) {
                vaultCache.totalBorrows = newTotalBorrows.toOwed();
                vaultCache.interestAccumulator = newInterestAccumulator;
                vaultCache.lastInterestAccumulatorUpdate = uint48(block.timestamp);

                if (newTotalShares != vaultCache.totalShares.toUint() && newTotalShares <= MAX_SANE_AMOUNT) {
                    vaultCache.accumulatedFees = newAccumulatedFees.toShares();
                    vaultCache.totalShares = newTotalShares.toShares();
                }
            }
        }
    }

    function totalAssetsInternal(VaultCache memory vaultCache) internal pure virtual returns (uint256) {
        // total assets can exceed Assets max amount (MAX_SANE_AMOUNT)
        return vaultCache.cash.toUint() + vaultCache.totalBorrows.toAssetsUp().toUint();
    }
}

File 16 of 52 : ProxyUtils.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {IERC20} from "../../IEVault.sol";
import {IPriceOracle} from "../../../interfaces/IPriceOracle.sol";

import "../Constants.sol";

/// @title ProxyUtils Library
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice The library provides helper functions for working with proxy meta data
library ProxyUtils {
    function metadata() internal pure returns (IERC20 asset, IPriceOracle oracle, address unitOfAccount) {
        assembly {
            asset := shr(96, calldataload(sub(calldatasize(), 60)))
            oracle := shr(96, calldataload(sub(calldatasize(), 40)))
            unitOfAccount := shr(96, calldataload(sub(calldatasize(), 20)))
        }
    }

    // When `useView` modifier is used, the original caller's address is attached to the call data along with the
    // metadata
    function useViewCaller() internal pure returns (address viewCaller) {
        assembly {
            viewCaller := shr(96, calldataload(sub(calldatasize(), add(PROXY_METADATA_LENGTH, 20))))
        }
    }
}

File 17 of 52 : RevertBytes.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import "../Errors.sol";

/// @title RevertBytes Library
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice The library provides a helper function for bubbling up errors
library RevertBytes {
    function revertBytes(bytes memory errMsg) internal pure {
        if (errMsg.length > 0) {
            assembly {
                revert(add(32, errMsg), mload(errMsg))
            }
        }

        revert Errors.E_EmptyError();
    }
}

File 18 of 52 : IProtocolConfig.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.8.0;

/// @title IProtocolConfig
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Interface of the contract centralizing the protocol's (DAO's) configuration for all the EVault deployments
interface IProtocolConfig {
    /// @notice check if a vault's interest fee is valid
    /// @param vault address of the vault
    /// @param interestFee an interest fee value to check
    /// @dev an interest fee is considered valid only when it is greater than or equal the min interest fee and less
    /// than or equal the max interest fee
    /// @dev if a vault has a specific interest fee ranges set by admin, it will be used, otherwise the generic ones
    /// will be checked against
    /// @return bool true for valid, else false
    function isValidInterestFee(address vault, uint16 interestFee) external view returns (bool);

    /// @notice get protocol fee config for a certain vault
    /// @param vault address of the vault
    /// @dev if vault == address(0), the generic config will be returned
    /// @return address protocol fee receiver
    /// @return uint16 protocol fee share
    function protocolFeeConfig(address vault) external view returns (address, uint16);

    /// @notice get interest fee ranges for a certain vault
    /// @param vault address of the vault
    /// @dev if vault == address(0), the generic ranges will be returned
    /// @return uint16 min interest fee
    /// @return uint16 max interest fee
    function interestFeeRange(address vault) external view returns (uint16, uint16);
}

File 19 of 52 : IBalanceTracker.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.8.0;

/// @title IBalanceTracker
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Provides an interface for tracking the balance of accounts.
interface IBalanceTracker {
    /// @notice Executes the balance tracking hook for an account.
    /// @dev This function is called by the Balance Forwarder contract which was enabled for the account. This function
    /// must be called with the current balance of the account when enabling the balance forwarding for it. This
    /// function must be called with 0 balance of the account when disabling the balance forwarding for it. This
    /// function allows to be called on zero balance transfers, when the newAccountBalance is the same as the previous
    /// one. To prevent DOS attacks, forfeitRecentReward should be used appropriately.
    /// @param account The account address to execute the hook for.
    /// @param newAccountBalance The new balance of the account.
    /// @param forfeitRecentReward Whether to forfeit the most recent reward and not update the accumulator.
    function balanceTrackerHook(address account, uint256 newAccountBalance, bool forfeitRecentReward) external;
}

File 20 of 52 : ISequenceRegistry.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.8.0;

/// @title ISequenceRegistry
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Provides an interface for reserving sequence IDs.
interface ISequenceRegistry {
    /// @notice Reserve an ID for a given designator
    /// @param designator An opaque string that corresponds to the sequence counter to be used
    /// @return Sequence ID
    function reserveSeqId(string calldata designator) external returns (uint256);
}

File 21 of 52 : Types.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import "../../IEVault.sol";

import "./VaultStorage.sol";
import "./Snapshot.sol";
import "./UserStorage.sol";

import "./Shares.sol";
import "./Assets.sol";
import "./Owed.sol";
import "./ConfigAmount.sol";
import "./Flags.sol";
import "./AmountCap.sol";

/// @notice In this file, custom types are defined and linked globally with their libraries and operators

type Shares is uint112;

type Assets is uint112;

type Owed is uint144;

type AmountCap is uint16;

type ConfigAmount is uint16;

type Flags is uint32;

using SharesLib for Shares global;
using {
    addShares as +, subShares as -, eqShares as ==, neqShares as !=, gtShares as >, ltShares as <
} for Shares global;

using AssetsLib for Assets global;
using {
    addAssets as +,
    subAssets as -,
    eqAssets as ==,
    neqAssets as !=,
    gtAssets as >,
    gteAssets as >=,
    ltAssets as <,
    lteAssets as <=
} for Assets global;

using OwedLib for Owed global;
using {addOwed as +, subOwed as -, eqOwed as ==, neqOwed as !=, gtOwed as >, ltOwed as <} for Owed global;

using ConfigAmountLib for ConfigAmount global;
using {
    gtConfigAmount as >, gteConfigAmount as >=, ltConfigAmount as <, lteConfigAmount as <=
} for ConfigAmount global;

using AmountCapLib for AmountCap global;
using FlagsLib for Flags global;

/// @title TypesLib
/// @notice Library for casting basic types' amounts into custom types
library TypesLib {
    function toShares(uint256 amount) internal pure returns (Shares) {
        if (amount > MAX_SANE_AMOUNT) revert Errors.E_AmountTooLargeToEncode();
        return Shares.wrap(uint112(amount));
    }

    function toAssets(uint256 amount) internal pure returns (Assets) {
        if (amount > MAX_SANE_AMOUNT) revert Errors.E_AmountTooLargeToEncode();
        return Assets.wrap(uint112(amount));
    }

    function toOwed(uint256 amount) internal pure returns (Owed) {
        if (amount > MAX_SANE_DEBT_AMOUNT) revert Errors.E_DebtAmountTooLargeToEncode();
        return Owed.wrap(uint144(amount));
    }

    function toConfigAmount(uint16 amount) internal pure returns (ConfigAmount) {
        if (amount > CONFIG_SCALE) revert Errors.E_ConfigAmountTooLargeToEncode();
        return ConfigAmount.wrap(amount);
    }
}

File 22 of 52 : IEVault.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.8.0;

import {IVault as IEVCVault} from "ethereum-vault-connector/interfaces/IVault.sol";

// Full interface of EVault and all it's modules

/// @title IInitialize
/// @notice Interface of the initialization module of EVault
interface IInitialize {
    /// @notice Initialization of the newly deployed proxy contract
    /// @param proxyCreator Account which created the proxy or should be the initial governor
    function initialize(address proxyCreator) external;
}

/// @title IERC20
/// @notice Interface of the EVault's Initialize module
interface IERC20 {
    /// @notice Vault share token (eToken) name, ie "Euler Vault: DAI"
    /// @return The name of the eToken
    function name() external view returns (string memory);

    /// @notice Vault share token (eToken) symbol, ie "eDAI"
    /// @return The symbol of the eToken
    function symbol() external view returns (string memory);

    /// @notice Decimals, the same as the asset's or 18 if the asset doesn't implement `decimals()`
    /// @return The decimals of the eToken
    function decimals() external view returns (uint8);

    /// @notice Sum of all eToken balances
    /// @return The total supply of the eToken
    function totalSupply() external view returns (uint256);

    /// @notice Balance of a particular account, in eTokens
    /// @param account Address to query
    /// @return The balance of the account
    function balanceOf(address account) external view returns (uint256);

    /// @notice Retrieve the current allowance
    /// @param holder The account holding the eTokens
    /// @param spender Trusted address
    /// @return The allowance from holder for spender
    function allowance(address holder, address spender) external view returns (uint256);

    /// @notice Transfer eTokens to another address
    /// @param to Recipient account
    /// @param amount In shares.
    /// @return True if transfer succeeded
    function transfer(address to, uint256 amount) external returns (bool);

    /// @notice Transfer eTokens from one address to another
    /// @param from This address must've approved the to address
    /// @param to Recipient account
    /// @param amount In shares
    /// @return True if transfer succeeded
    function transferFrom(address from, address to, uint256 amount) external returns (bool);

    /// @notice Allow spender to access an amount of your eTokens
    /// @param spender Trusted address
    /// @param amount Use max uint for "infinite" allowance
    /// @return True if approval succeeded
    function approve(address spender, uint256 amount) external returns (bool);
}

/// @title IToken
/// @notice Interface of the EVault's Token module
interface IToken is IERC20 {
    /// @notice Transfer the full eToken balance of an address to another
    /// @param from This address must've approved the to address
    /// @param to Recipient account
    /// @return True if transfer succeeded
    function transferFromMax(address from, address to) external returns (bool);
}

/// @title IERC4626
/// @notice Interface of an ERC4626 vault
interface IERC4626 {
    /// @notice Vault's underlying asset
    /// @return The vault's underlying asset
    function asset() external view returns (address);

    /// @notice Total amount of managed assets, cash and borrows
    /// @return The total amount of assets
    function totalAssets() external view returns (uint256);

    /// @notice Calculate amount of assets corresponding to the requested shares amount
    /// @param shares Amount of shares to convert
    /// @return The amount of assets
    function convertToAssets(uint256 shares) external view returns (uint256);

    /// @notice Calculate amount of shares corresponding to the requested assets amount
    /// @param assets Amount of assets to convert
    /// @return The amount of shares
    function convertToShares(uint256 assets) external view returns (uint256);

    /// @notice Fetch the maximum amount of assets a user can deposit
    /// @param account Address to query
    /// @return The max amount of assets the account can deposit
    function maxDeposit(address account) external view returns (uint256);

    /// @notice Calculate an amount of shares that would be created by depositing assets
    /// @param assets Amount of assets deposited
    /// @return Amount of shares received
    function previewDeposit(uint256 assets) external view returns (uint256);

    /// @notice Fetch the maximum amount of shares a user can mint
    /// @param account Address to query
    /// @return The max amount of shares the account can mint
    function maxMint(address account) external view returns (uint256);

    /// @notice Calculate an amount of assets that would be required to mint requested amount of shares
    /// @param shares Amount of shares to be minted
    /// @return Required amount of assets
    function previewMint(uint256 shares) external view returns (uint256);

    /// @notice Fetch the maximum amount of assets a user is allowed to withdraw
    /// @param owner Account holding the shares
    /// @return The maximum amount of assets the owner is allowed to withdraw
    function maxWithdraw(address owner) external view returns (uint256);

    /// @notice Calculate the amount of shares that will be burned when withdrawing requested amount of assets
    /// @param assets Amount of assets withdrawn
    /// @return Amount of shares burned
    function previewWithdraw(uint256 assets) external view returns (uint256);

    /// @notice Fetch the maximum amount of shares a user is allowed to redeem for assets
    /// @param owner Account holding the shares
    /// @return The maximum amount of shares the owner is allowed to redeem
    function maxRedeem(address owner) external view returns (uint256);

    /// @notice Calculate the amount of assets that will be transferred when redeeming requested amount of shares
    /// @param shares Amount of shares redeemed
    /// @return Amount of assets transferred
    function previewRedeem(uint256 shares) external view returns (uint256);

    /// @notice Transfer requested amount of underlying tokens from sender to the vault pool in return for shares
    /// @param amount Amount of assets to deposit (use max uint256 for full underlying token balance)
    /// @param receiver An account to receive the shares
    /// @return Amount of shares minted
    /// @dev Deposit will round down the amount of assets that are converted to shares. To prevent losses consider using
    /// mint instead.
    function deposit(uint256 amount, address receiver) external returns (uint256);

    /// @notice Transfer underlying tokens from sender to the vault pool in return for requested amount of shares
    /// @param amount Amount of shares to be minted
    /// @param receiver An account to receive the shares
    /// @return Amount of assets deposited
    function mint(uint256 amount, address receiver) external returns (uint256);

    /// @notice Transfer requested amount of underlying tokens from the vault and decrease account's shares balance
    /// @param amount Amount of assets to withdraw
    /// @param receiver Account to receive the withdrawn assets
    /// @param owner Account holding the shares to burn
    /// @return Amount of shares burned
    function withdraw(uint256 amount, address receiver, address owner) external returns (uint256);

    /// @notice Burn requested shares and transfer corresponding underlying tokens from the vault to the receiver
    /// @param amount Amount of shares to burn (use max uint256 to burn full owner balance)
    /// @param receiver Account to receive the withdrawn assets
    /// @param owner Account holding the shares to burn.
    /// @return Amount of assets transferred
    function redeem(uint256 amount, address receiver, address owner) external returns (uint256);
}

/// @title IVault
/// @notice Interface of the EVault's Vault module
interface IVault is IERC4626 {
    /// @notice Balance of the fees accumulator, in shares
    /// @return The accumulated fees in shares
    function accumulatedFees() external view returns (uint256);

    /// @notice Balance of the fees accumulator, in underlying units
    /// @return The accumulated fees in asset units
    function accumulatedFeesAssets() external view returns (uint256);

    /// @notice Address of the original vault creator
    /// @return The address of the creator
    function creator() external view returns (address);

    /// @notice Creates shares for the receiver, from excess asset balances of the vault (not accounted for in `cash`)
    /// @param amount Amount of assets to claim (use max uint256 to claim all available assets)
    /// @param receiver An account to receive the shares
    /// @return Amount of shares minted
    /// @dev Could be used as an alternative deposit flow in certain scenarios. E.g. swap directly to the vault, call
    /// `skim` to claim deposit.
    function skim(uint256 amount, address receiver) external returns (uint256);
}

/// @title IBorrowing
/// @notice Interface of the EVault's Borrowing module
interface IBorrowing {
    /// @notice Sum of all outstanding debts, in underlying units (increases as interest is accrued)
    /// @return The total borrows in asset units
    function totalBorrows() external view returns (uint256);

    /// @notice Sum of all outstanding debts, in underlying units scaled up by shifting
    /// INTERNAL_DEBT_PRECISION_SHIFT bits
    /// @return The total borrows in internal debt precision
    function totalBorrowsExact() external view returns (uint256);

    /// @notice Balance of vault assets as tracked by deposits/withdrawals and borrows/repays
    /// @return The amount of assets the vault tracks as current direct holdings
    function cash() external view returns (uint256);

    /// @notice Debt owed by a particular account, in underlying units
    /// @param account Address to query
    /// @return The debt of the account in asset units
    function debtOf(address account) external view returns (uint256);

    /// @notice Debt owed by a particular account, in underlying units scaled up by shifting
    /// INTERNAL_DEBT_PRECISION_SHIFT bits
    /// @param account Address to query
    /// @return The debt of the account in internal precision
    function debtOfExact(address account) external view returns (uint256);

    /// @notice Retrieves the current interest rate for an asset
    /// @return The interest rate in yield-per-second, scaled by 10**27
    function interestRate() external view returns (uint256);

    /// @notice Retrieves the current interest rate accumulator for an asset
    /// @return An opaque accumulator that increases as interest is accrued
    function interestAccumulator() external view returns (uint256);

    /// @notice Returns an address of the sidecar DToken
    /// @return The address of the DToken
    function dToken() external view returns (address);

    /// @notice Transfer underlying tokens from the vault to the sender, and increase sender's debt
    /// @param amount Amount of assets to borrow (use max uint256 for all available tokens)
    /// @param receiver Account receiving the borrowed tokens
    /// @return Amount of assets borrowed
    function borrow(uint256 amount, address receiver) external returns (uint256);

    /// @notice Transfer underlying tokens from the sender to the vault, and decrease receiver's debt
    /// @param amount Amount of debt to repay in assets (use max uint256 for full debt)
    /// @param receiver Account holding the debt to be repaid
    /// @return Amount of assets repaid
    function repay(uint256 amount, address receiver) external returns (uint256);

    /// @notice Pay off liability with shares ("self-repay")
    /// @param amount In asset units (use max uint256 to repay the debt in full or up to the available deposit)
    /// @param receiver Account to remove debt from by burning sender's shares
    /// @return shares Amount of shares burned
    /// @return debt Amount of debt removed in assets
    /// @dev Equivalent to withdrawing and repaying, but no assets are needed to be present in the vault
    /// @dev Contrary to a regular `repay`, if account is unhealthy, the repay amount must bring the account back to
    /// health, or the operation will revert during account status check
    function repayWithShares(uint256 amount, address receiver) external returns (uint256 shares, uint256 debt);

    /// @notice Take over debt from another account
    /// @param amount Amount of debt in asset units (use max uint256 for all the account's debt)
    /// @param from Account to pull the debt from
    /// @dev Due to internal debt precision accounting, the liability reported on either or both accounts after
    /// calling `pullDebt` may not match the `amount` requested precisely
    function pullDebt(uint256 amount, address from) external;

    /// @notice Request a flash-loan. A onFlashLoan() callback in msg.sender will be invoked, which must repay the loan
    /// to the main Euler address prior to returning.
    /// @param amount In asset units
    /// @param data Passed through to the onFlashLoan() callback, so contracts don't need to store transient data in
    /// storage
    function flashLoan(uint256 amount, bytes calldata data) external;

    /// @notice Updates interest accumulator and totalBorrows, credits reserves, re-targets interest rate, and logs
    /// vault status
    function touch() external;
}

/// @title ILiquidation
/// @notice Interface of the EVault's Liquidation module
interface ILiquidation {
    /// @notice Checks to see if a liquidation would be profitable, without actually doing anything
    /// @param liquidator Address that will initiate the liquidation
    /// @param violator Address that may be in collateral violation
    /// @param collateral Collateral which is to be seized
    /// @return maxRepay Max amount of debt that can be repaid, in asset units
    /// @return maxYield Yield in collateral corresponding to max allowed amount of debt to be repaid, in collateral
    /// balance (shares for vaults)
    function checkLiquidation(address liquidator, address violator, address collateral)
        external
        view
        returns (uint256 maxRepay, uint256 maxYield);

    /// @notice Attempts to perform a liquidation
    /// @param violator Address that may be in collateral violation
    /// @param collateral Collateral which is to be seized
    /// @param repayAssets The amount of underlying debt to be transferred from violator to sender, in asset units (use
    /// max uint256 to repay the maximum possible amount). Meant as slippage check together with `minYieldBalance`
    /// @param minYieldBalance The minimum acceptable amount of collateral to be transferred from violator to sender, in
    /// collateral balance units (shares for vaults).  Meant as slippage check together with `repayAssets`
    /// @dev If `repayAssets` is set to max uint256 it is assumed the caller will perform their own slippage checks to
    /// make sure they are not taking on too much debt. This option is mainly meant for smart contract liquidators
    function liquidate(address violator, address collateral, uint256 repayAssets, uint256 minYieldBalance) external;
}

/// @title IRiskManager
/// @notice Interface of the EVault's RiskManager module
interface IRiskManager is IEVCVault {
    /// @notice Retrieve account's total liquidity
    /// @param account Account holding debt in this vault
    /// @param liquidation Flag to indicate if the calculation should be performed in liquidation vs account status
    /// check mode, where different LTV values might apply.
    /// @return collateralValue Total risk adjusted value of all collaterals in unit of account
    /// @return liabilityValue Value of debt in unit of account
    function accountLiquidity(address account, bool liquidation)
        external
        view
        returns (uint256 collateralValue, uint256 liabilityValue);

    /// @notice Retrieve account's liquidity per collateral
    /// @param account Account holding debt in this vault
    /// @param liquidation Flag to indicate if the calculation should be performed in liquidation vs account status
    /// check mode, where different LTV values might apply.
    /// @return collaterals Array of collaterals enabled
    /// @return collateralValues Array of risk adjusted collateral values corresponding to items in collaterals array.
    /// In unit of account
    /// @return liabilityValue Value of debt in unit of account
    function accountLiquidityFull(address account, bool liquidation)
        external
        view
        returns (address[] memory collaterals, uint256[] memory collateralValues, uint256 liabilityValue);

    /// @notice Release control of the account on EVC if no outstanding debt is present
    function disableController() external;

    /// @notice Checks the status of an account and reverts if account is not healthy
    /// @param account The address of the account to be checked
    /// @return magicValue Must return the bytes4 magic value 0xb168c58f (which is a selector of this function) when
    /// account status is valid, or revert otherwise.
    /// @dev Only callable by EVC during status checks
    function checkAccountStatus(address account, address[] calldata collaterals) external view returns (bytes4);

    /// @notice Checks the status of the vault and reverts if caps are exceeded
    /// @return magicValue Must return the bytes4 magic value 0x4b3d1223 (which is a selector of this function) when
    /// account status is valid, or revert otherwise.
    /// @dev Only callable by EVC during status checks
    function checkVaultStatus() external returns (bytes4);
}

/// @title IBalanceForwarder
/// @notice Interface of the EVault's BalanceForwarder module
interface IBalanceForwarder {
    /// @notice Retrieve the address of rewards contract, tracking changes in account's balances
    /// @return The balance tracker address
    function balanceTrackerAddress() external view returns (address);

    /// @notice Retrieves boolean indicating if the account opted in to forward balance changes to the rewards contract
    /// @param account Address to query
    /// @return True if balance forwarder is enabled
    function balanceForwarderEnabled(address account) external view returns (bool);

    /// @notice Enables balance forwarding for the authenticated account
    /// @dev Only the authenticated account can enable balance forwarding for itself
    /// @dev Should call the IBalanceTracker hook with the current account's balance
    function enableBalanceForwarder() external;

    /// @notice Disables balance forwarding for the authenticated account
    /// @dev Only the authenticated account can disable balance forwarding for itself
    /// @dev Should call the IBalanceTracker hook with the account's balance of 0
    function disableBalanceForwarder() external;
}

/// @title IGovernance
/// @notice Interface of the EVault's Governance module
interface IGovernance {
    /// @notice Retrieves the address of the governor
    /// @return The governor address
    function governorAdmin() external view returns (address);

    /// @notice Retrieves address of the governance fee receiver
    /// @return The fee receiver address
    function feeReceiver() external view returns (address);

    /// @notice Retrieves the interest fee in effect for the vault
    /// @return Amount of interest that is redirected as a fee, as a fraction scaled by 1e4
    function interestFee() external view returns (uint16);

    /// @notice Looks up an asset's currently configured interest rate model
    /// @return Address of the interest rate contract or address zero to indicate 0% interest
    function interestRateModel() external view returns (address);

    /// @notice Retrieves the ProtocolConfig address
    /// @return The protocol config address
    function protocolConfigAddress() external view returns (address);

    /// @notice Retrieves the protocol fee share
    /// @return A percentage share of fees accrued belonging to the protocol, in 1e4 scale
    function protocolFeeShare() external view returns (uint256);

    /// @notice Retrieves the address which will receive protocol's fees
    /// @notice The protocol fee receiver address
    function protocolFeeReceiver() external view returns (address);

    /// @notice Retrieves supply and borrow caps in AmountCap format
    /// @return supplyCap The supply cap in AmountCap format
    /// @return borrowCap The borrow cap in AmountCap format
    function caps() external view returns (uint16 supplyCap, uint16 borrowCap);

    /// @notice Retrieves the borrow LTV of the collateral, which is used to determine if the account is healthy during
    /// account status checks.
    /// @param collateral The address of the collateral to query
    /// @return Borrowing LTV in 1e4 scale
    function LTVBorrow(address collateral) external view returns (uint16);

    /// @notice Retrieves the current liquidation LTV, which is used to determine if the account is eligible for
    /// liquidation
    /// @param collateral The address of the collateral to query
    /// @return Liquidation LTV in 1e4 scale
    function LTVLiquidation(address collateral) external view returns (uint16);

    /// @notice Retrieves LTV configuration for the collateral
    /// @param collateral Collateral asset
    /// @return borrowLTV The current value of borrow LTV for originating positions
    /// @return liquidationLTV The value of fully converged liquidation LTV
    /// @return initialLiquidationLTV The initial value of the liquidation LTV, when the ramp began
    /// @return targetTimestamp The timestamp when the liquidation LTV is considered fully converged
    /// @return rampDuration The time it takes for the liquidation LTV to converge from the initial value to the fully
    /// converged value
    function LTVFull(address collateral)
        external
        view
        returns (
            uint16 borrowLTV,
            uint16 liquidationLTV,
            uint16 initialLiquidationLTV,
            uint48 targetTimestamp,
            uint32 rampDuration
        );

    /// @notice Retrieves a list of collaterals with configured LTVs
    /// @return List of asset collaterals
    /// @dev Returned assets could have the ltv disabled (set to zero)
    function LTVList() external view returns (address[] memory);

    /// @notice Retrieves the maximum liquidation discount
    /// @return The maximum liquidation discount in 1e4 scale
    /// @dev The default value, which is zero, is deliberately bad, as it means there would be no incentive to liquidate
    /// unhealthy users. The vault creator must take care to properly select the limit, given the underlying and
    /// collaterals used.
    function maxLiquidationDiscount() external view returns (uint16);

    /// @notice Retrieves liquidation cool-off time, which must elapse after successful account status check before
    /// account can be liquidated
    /// @return The liquidation cool off time in seconds
    function liquidationCoolOffTime() external view returns (uint16);

    /// @notice Retrieves a hook target and a bitmask indicating which operations call the hook target
    /// @return hookTarget Address of the hook target contract
    /// @return hookedOps Bitmask with operations that should call the hooks. See Constants.sol for a list of operations
    function hookConfig() external view returns (address hookTarget, uint32 hookedOps);

    /// @notice Retrieves a bitmask indicating enabled config flags
    /// @return Bitmask with config flags enabled
    function configFlags() external view returns (uint32);

    /// @notice Address of EthereumVaultConnector contract
    /// @return The EVC address
    function EVC() external view returns (address);

    /// @notice Retrieves a reference asset used for liquidity calculations
    /// @return The address of the reference asset
    function unitOfAccount() external view returns (address);

    /// @notice Retrieves the address of the oracle contract
    /// @return The address of the oracle
    function oracle() external view returns (address);

    /// @notice Retrieves the Permit2 contract address
    /// @return The address of the Permit2 contract
    function permit2Address() external view returns (address);

    /// @notice Splits accrued fees balance according to protocol fee share and transfers shares to the governor fee
    /// receiver and protocol fee receiver
    function convertFees() external;

    /// @notice Set a new governor address
    /// @param newGovernorAdmin The new governor address
    /// @dev Set to zero address to renounce privileges and make the vault non-governed
    function setGovernorAdmin(address newGovernorAdmin) external;

    /// @notice Set a new governor fee receiver address
    /// @param newFeeReceiver The new fee receiver address
    function setFeeReceiver(address newFeeReceiver) external;

    /// @notice Set a new LTV config
    /// @param collateral Address of collateral to set LTV for
    /// @param borrowLTV New borrow LTV, for assessing account's health during account status checks, in 1e4 scale
    /// @param liquidationLTV New liquidation LTV after ramp ends in 1e4 scale
    /// @param rampDuration Ramp duration in seconds
    function setLTV(address collateral, uint16 borrowLTV, uint16 liquidationLTV, uint32 rampDuration) external;

    /// @notice Set a new maximum liquidation discount
    /// @param newDiscount New maximum liquidation discount in 1e4 scale
    /// @dev If the discount is zero (the default), the liquidators will not be incentivized to liquidate unhealthy
    /// accounts
    function setMaxLiquidationDiscount(uint16 newDiscount) external;

    /// @notice Set a new liquidation cool off time, which must elapse after successful account status check before
    /// account can be liquidated
    /// @param newCoolOffTime The new liquidation cool off time in seconds
    /// @dev Setting cool off time to zero allows liquidating the account in the same block as the last successful
    /// account status check
    function setLiquidationCoolOffTime(uint16 newCoolOffTime) external;

    /// @notice Set a new interest rate model contract
    /// @param newModel The new IRM address
    /// @dev If the new model reverts, perhaps due to governor error, the vault will silently use a zero interest
    /// rate. Governor should make sure the new interest rates are computed as expected.
    function setInterestRateModel(address newModel) external;

    /// @notice Set a new hook target and a new bitmap indicating which operations should call the hook target.
    /// Operations are defined in Constants.sol.
    /// @param newHookTarget The new hook target address. Use address(0) to simply disable hooked operations
    /// @param newHookedOps Bitmask with the new hooked operations
    /// @dev All operations are initially disabled in a newly created vault. The vault creator must set their
    /// own configuration to make the vault usable
    function setHookConfig(address newHookTarget, uint32 newHookedOps) external;

    /// @notice Set new bitmap indicating which config flags should be enabled. Flags are defined in Constants.sol
    /// @param newConfigFlags Bitmask with the new config flags
    function setConfigFlags(uint32 newConfigFlags) external;

    /// @notice Set new supply and borrow caps in AmountCap format
    /// @param supplyCap The new supply cap in AmountCap fromat
    /// @param borrowCap The new borrow cap in AmountCap fromat
    function setCaps(uint16 supplyCap, uint16 borrowCap) external;

    /// @notice Set a new interest fee
    /// @param newFee The new interest fee
    function setInterestFee(uint16 newFee) external;
}

/// @title IEVault
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Interface of the EVault, an EVC enabled lending vault
interface IEVault is
    IInitialize,
    IToken,
    IVault,
    IBorrowing,
    ILiquidation,
    IRiskManager,
    IBalanceForwarder,
    IGovernance
{
    /// @notice Fetch address of the `Initialize` module
    function MODULE_INITIALIZE() external view returns (address);
    /// @notice Fetch address of the `Token` module
    function MODULE_TOKEN() external view returns (address);
    /// @notice Fetch address of the `Vault` module
    function MODULE_VAULT() external view returns (address);
    /// @notice Fetch address of the `Borrowing` module
    function MODULE_BORROWING() external view returns (address);
    /// @notice Fetch address of the `Liquidation` module
    function MODULE_LIQUIDATION() external view returns (address);
    /// @notice Fetch address of the `RiskManager` module
    function MODULE_RISKMANAGER() external view returns (address);
    /// @notice Fetch address of the `BalanceForwarder` module
    function MODULE_BALANCE_FORWARDER() external view returns (address);
    /// @notice Fetch address of the `Governance` module
    function MODULE_GOVERNANCE() external view returns (address);
}

File 23 of 52 : BalanceUtils.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

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

import "./types/Types.sol";

/// @title BalanceUtils
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Utilities for tracking share balances and allowances
abstract contract BalanceUtils is Base {
    // Balances

    function increaseBalance(
        VaultCache memory vaultCache,
        address account,
        address sender,
        Shares amount,
        Assets assets
    ) internal virtual {
        if (account == address(0)) revert E_BadSharesReceiver();
        UserStorage storage user = vaultStorage.users[account];

        (Shares origBalance, bool balanceForwarderEnabled) = user.getBalanceAndBalanceForwarder();
        Shares newBalance = origBalance + amount;

        user.setBalance(newBalance);
        vaultStorage.totalShares = vaultCache.totalShares = vaultCache.totalShares + amount;

        if (balanceForwarderEnabled) {
            balanceTracker.balanceTrackerHook(account, newBalance.toUint(), false);
        }

        emit Transfer(address(0), account, amount.toUint());
        emit Deposit(sender, account, assets.toUint(), amount.toUint());
    }

    function decreaseBalance(
        VaultCache memory vaultCache,
        address account,
        address sender,
        address receiver,
        Shares amount,
        Assets assets
    ) internal virtual {
        UserStorage storage user = vaultStorage.users[account];
        (Shares origBalance, bool balanceForwarderEnabled) = user.getBalanceAndBalanceForwarder();
        if (origBalance < amount) revert E_InsufficientBalance();

        Shares newBalance = origBalance.subUnchecked(amount);

        user.setBalance(newBalance);
        vaultStorage.totalShares = vaultCache.totalShares = vaultCache.totalShares - amount;

        if (balanceForwarderEnabled) {
            // if the balance is decreased as a part of the collateral transfer during liquidation,
            // which is indicated by the EVC with a collateral control in progress flag,
            // instruct the balance tracker to forfeit rewards due to the liquidated account, in order to
            // limit gas consumption, which could potentially be abused by violators to prevent liquidations.
            balanceTracker.balanceTrackerHook(account, newBalance.toUint(), isControlCollateralInProgress());
        }

        emit Transfer(account, address(0), amount.toUint());
        emit Withdraw(sender, receiver, account, assets.toUint(), amount.toUint());
    }

    function transferBalance(address from, address to, Shares amount) internal virtual {
        if (to == address(0)) revert E_BadSharesReceiver();

        if (!amount.isZero()) {
            // update from

            UserStorage storage user = vaultStorage.users[from];

            (Shares origFromBalance, bool fromBalanceForwarderEnabled) = user.getBalanceAndBalanceForwarder();
            if (origFromBalance < amount) revert E_InsufficientBalance();

            Shares newFromBalance = origFromBalance.subUnchecked(amount);
            user.setBalance(newFromBalance);

            if (fromBalanceForwarderEnabled) {
                balanceTracker.balanceTrackerHook(from, newFromBalance.toUint(), isControlCollateralInProgress());
            }

            // update to

            user = vaultStorage.users[to];

            (Shares origToBalance, bool toBalanceForwarderEnabled) = user.getBalanceAndBalanceForwarder();

            Shares newToBalance = origToBalance + amount;
            user.setBalance(newToBalance);

            if (toBalanceForwarderEnabled) {
                balanceTracker.balanceTrackerHook(to, newToBalance.toUint(), false);
            }
        }

        emit Transfer(from, to, amount.toUint());
    }

    // Allowance

    function setAllowance(address owner, address spender, uint256 amount) internal {
        if (spender == owner) return;

        vaultStorage.users[owner].eTokenAllowance[spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /// @dev As gas saving optimization, consuming allowance doesn't emit the Approval event.
    function decreaseAllowance(address owner, address spender, Shares amount) internal virtual {
        if (amount.isZero() || owner == spender) return;
        UserStorage storage user = vaultStorage.users[owner];

        uint256 allowance = user.eTokenAllowance[spender];
        if (allowance != type(uint256).max) {
            if (allowance < amount.toUint()) revert E_InsufficientAllowance();
            unchecked {
                allowance -= amount.toUint();
            }
            user.eTokenAllowance[spender] = allowance;
        }
    }
}

File 24 of 52 : AssetTransfers.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {SafeERC20Lib} from "./lib/SafeERC20Lib.sol";
import {Base} from "./Base.sol";

import "./types/Types.sol";

/// @title AssetTransfers
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Transfer assets into and out of the vault
abstract contract AssetTransfers is Base {
    using TypesLib for uint256;
    using SafeERC20Lib for IERC20;

    function pullAssets(VaultCache memory vaultCache, address from, Assets amount) internal virtual {
        vaultCache.asset.safeTransferFrom(from, address(this), amount.toUint(), permit2);
        vaultStorage.cash = vaultCache.cash = vaultCache.cash + amount;
    }

    /// @dev If the `CFG_EVC_COMPATIBLE_ASSET` flag is not set (default), the function will protect users from
    /// mistakenly sending funds to the EVC sub-accounts. Functions that push tokens out (`withdraw`, `redeem`,
    /// `borrow`) accept a `receiver` argument. If the user sets one of their sub-accounts (not the owner) as the
    /// receiver, funds would be lost because a regular asset doesn't support the EVC's sub-accounts. The private key to
    /// a sub-account (not the owner) is not known, so the user would not be able to move the funds out. The function
    /// will make a best effort to prevent this by checking if the receiver of the token is recognized by EVC as a
    /// non-owner sub-account. In other words, if there is an account registered in EVC as the owner for the intended
    /// receiver, the transfer will be prevented. However, there is no guarantee that EVC will have the owner
    /// registered. If the asset itself is compatible with EVC, it is safe to set the flag and send the asset to a
    /// non-owner sub-account.
    function pushAssets(VaultCache memory vaultCache, address to, Assets amount) internal virtual {
        if (
            to == address(0)
                || (vaultCache.configFlags.isNotSet(CFG_EVC_COMPATIBLE_ASSET) && isKnownNonOwnerAccount(to))
        ) {
            revert E_BadAssetReceiver();
        }

        vaultStorage.cash = vaultCache.cash = vaultCache.cash - amount;
        vaultCache.asset.safeTransfer(to, amount.toUint());
    }
}

File 25 of 52 : SafeERC20Lib.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {IERC20} from "../../IEVault.sol";
import {RevertBytes} from "./RevertBytes.sol";
import {IPermit2} from "../../../interfaces/IPermit2.sol";

/// @title SafeERC20Lib Library
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice The library provides helpers for ERC20 transfers, including Permit2 support
library SafeERC20Lib {
    error E_TransferFromFailed(bytes errorPermit2, bytes errorTransferFrom);

    // If no code exists under the token address, the function will succeed. EVault ensures this is not the case in
    // `initialize`.
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value)
        internal
        returns (bool, bytes memory)
    {
        (bool success, bytes memory data) = address(token).call(abi.encodeCall(IERC20.transferFrom, (from, to, value)));

        return isEmptyOrTrueReturn(success, data) ? (true, bytes("")) : (false, data);
    }

    function safeTransferFrom(IERC20 token, address from, address to, uint256 value, address permit2) internal {
        bool success;
        bytes memory permit2Data;
        bytes memory transferData;

        if (permit2 != address(0) && value <= type(uint160).max) {
            // it's safe to down-cast value to uint160
            (success, permit2Data) =
                permit2.call(abi.encodeCall(IPermit2.transferFrom, (from, to, uint160(value), address(token))));
        }

        if (!success) {
            (success, transferData) = trySafeTransferFrom(token, from, to, value);
        }

        if (!success) revert E_TransferFromFailed(permit2Data, transferData);
    }

    // If no code exists under the token address, the function will succeed. EVault ensures this is not the case in
    // `initialize`.
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        (bool success, bytes memory data) = address(token).call(abi.encodeCall(IERC20.transfer, (to, value)));
        if (!isEmptyOrTrueReturn(success, data)) RevertBytes.revertBytes(data);
    }

    function isEmptyOrTrueReturn(bool callSuccess, bytes memory data) private pure returns (bool) {
        return callSuccess && (data.length == 0 || (data.length >= 32 && abi.decode(data, (bool))));
    }
}

File 26 of 52 : LiquidityUtils.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {BorrowUtils} from "./BorrowUtils.sol";
import {LTVUtils} from "./LTVUtils.sol";

import "./types/Types.sol";

/// @title LiquidityUtils
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Utilities for calculating account liquidity and health status
abstract contract LiquidityUtils is BorrowUtils, LTVUtils {
    using TypesLib for uint256;

    // Calculate the value of liabilities, and the liquidation or borrowing LTV adjusted collateral value.
    function calculateLiquidity(
        VaultCache memory vaultCache,
        address account,
        address[] memory collaterals,
        bool liquidation
    ) internal view virtual returns (uint256 collateralValue, uint256 liabilityValue) {
        validateOracle(vaultCache);

        for (uint256 i; i < collaterals.length; ++i) {
            collateralValue += getCollateralValue(vaultCache, account, collaterals[i], liquidation);
        }

        liabilityValue = getLiabilityValue(vaultCache, account, vaultStorage.users[account].getOwed(), liquidation);
    }

    // Check that there is no liability, or the value of the collateral, adjusted for borrowing LTV, is greater than the
    // liability value. Since this function uses bid/ask prices, it should only be used within the account status check,
    // and not for determining whether an account can be liquidated (which uses mid-point prices).
    function checkLiquidity(VaultCache memory vaultCache, address account, address[] memory collaterals)
        internal
        view
        virtual
    {
        validateOracle(vaultCache);

        Owed owed = vaultStorage.users[account].getOwed();
        if (owed.isZero()) return;

        uint256 liabilityValue = getLiabilityValue(vaultCache, account, owed, false);

        uint256 collateralValue;
        for (uint256 i; i < collaterals.length; ++i) {
            collateralValue += getCollateralValue(vaultCache, account, collaterals[i], false);
            if (collateralValue > liabilityValue) return;
        }

        revert E_AccountLiquidity();
    }

    // Check if the account has no collateral balance left, used for debt socialization
    // If LTV is zero, the collateral can still be liquidated.
    // If the price of collateral is zero, liquidations are not executed, so the check won't be performed.
    // If there is no collateral balance at all, then debt socialization can happen.
    function checkNoCollateral(address account, address[] memory collaterals) internal view virtual returns (bool) {
        for (uint256 i; i < collaterals.length; ++i) {
            address collateral = collaterals[i];

            if (!isRecognizedCollateral(collateral)) continue;

            if (IERC20(collateral).balanceOf(account) > 0) return false;
        }

        return true;
    }

    function getLiabilityValue(VaultCache memory vaultCache, address account, Owed owed, bool liquidation)
        internal
        view
        virtual
        returns (uint256 value)
    {
        // update owed with interest accrued
        uint256 owedAssets = getCurrentOwed(vaultCache, account, owed).toAssetsUp().toUint();

        if (owedAssets == 0) return 0;

        if (address(vaultCache.asset) == vaultCache.unitOfAccount) {
            value = owedAssets;
        } else {
            if (liquidation) {
                // mid-point price
                value = vaultCache.oracle.getQuote(owedAssets, address(vaultCache.asset), vaultCache.unitOfAccount);
            } else {
                // ask price for liability
                (, value) = vaultCache.oracle.getQuotes(owedAssets, address(vaultCache.asset), vaultCache.unitOfAccount);
            }
        }
    }

    function getCollateralValue(VaultCache memory vaultCache, address account, address collateral, bool liquidation)
        internal
        view
        virtual
        returns (uint256 value)
    {
        ConfigAmount ltv = getLTV(collateral, liquidation);
        if (ltv.isZero()) return 0;

        uint256 balance = IERC20(collateral).balanceOf(account);
        if (balance == 0) return 0;

        uint256 currentCollateralValue;

        if (liquidation) {
            // mid-point price
            currentCollateralValue = vaultCache.oracle.getQuote(balance, collateral, vaultCache.unitOfAccount);
        } else {
            // bid price for collateral
            (currentCollateralValue,) = vaultCache.oracle.getQuotes(balance, collateral, vaultCache.unitOfAccount);
        }

        return currentCollateralValue * ltv.toUint16() / CONFIG_SCALE;
    }

    function validateOracle(VaultCache memory vaultCache) internal pure {
        if (address(vaultCache.oracle) == address(0)) revert E_NoPriceOracle();
    }
}

File 27 of 52 : IFlashLoan.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.8.0;

/// @title IFlashLoan
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Definition of callback method that flashLoan will invoke on your contract
interface IFlashLoan {
    /// @notice Function that will be called on the caller of `flashloan`
    /// @param data Data that was passed to the `flashloan` call
    function onFlashLoan(bytes memory data) external;
}

File 28 of 52 : BorrowUtils.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Base} from "./Base.sol";
import {DToken} from "../DToken.sol";
import {IIRM} from "../../InterestRateModels/IIRM.sol";

import "./types/Types.sol";

/// @title BorrowUtils
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Utilities for tracking debt and interest rates
abstract contract BorrowUtils is Base {
    function getCurrentOwed(VaultCache memory vaultCache, address account, Owed owed) internal view returns (Owed) {
        // Don't bother loading the user's accumulator
        if (owed.isZero()) return Owed.wrap(0);

        // Can't divide by 0 here: If owed is non-zero, we must've initialized the user's interestAccumulator
        return owed.mulDiv(vaultCache.interestAccumulator, vaultStorage.users[account].interestAccumulator);
    }

    function getCurrentOwed(VaultCache memory vaultCache, address account) internal view returns (Owed) {
        return getCurrentOwed(vaultCache, account, vaultStorage.users[account].getOwed());
    }

    function loadUserBorrow(VaultCache memory vaultCache, address account)
        private
        view
        returns (Owed newOwed, Owed prevOwed)
    {
        prevOwed = vaultStorage.users[account].getOwed();
        newOwed = getCurrentOwed(vaultCache, account, prevOwed);
    }

    function setUserBorrow(VaultCache memory vaultCache, address account, Owed newOwed) private {
        UserStorage storage user = vaultStorage.users[account];

        user.setOwed(newOwed);
        user.interestAccumulator = vaultCache.interestAccumulator;
    }

    function increaseBorrow(VaultCache memory vaultCache, address account, Assets assets) internal virtual {
        (Owed owed, Owed prevOwed) = loadUserBorrow(vaultCache, account);

        Owed amount = assets.toOwed();
        owed = owed + amount;

        setUserBorrow(vaultCache, account, owed);
        vaultStorage.totalBorrows = vaultCache.totalBorrows = vaultCache.totalBorrows + amount;

        logBorrow(account, assets, prevOwed.toAssetsUp(), owed.toAssetsUp());
    }

    /// @dev Contrary to `increaseBorrow` and `transferBorrow` this function does the accounting in Assets
    /// by first rounding up the user's debt. The rounding is an additional cost to the user and is recorded
    /// both in user's account and in `totalBorrows`
    function decreaseBorrow(VaultCache memory vaultCache, address account, Assets assets) internal virtual {
        (Owed owedExact, Owed prevOwed) = loadUserBorrow(vaultCache, account);
        Assets owed = owedExact.toAssetsUp();

        if (assets > owed) revert E_RepayTooMuch();

        Owed owedRemaining = owed.subUnchecked(assets).toOwed();

        setUserBorrow(vaultCache, account, owedRemaining);
        vaultStorage.totalBorrows = vaultCache.totalBorrows = vaultCache.totalBorrows > owedExact
            ? vaultCache.totalBorrows.subUnchecked(owedExact).addUnchecked(owedRemaining)
            : owedRemaining;

        logRepay(account, assets, prevOwed.toAssetsUp(), owedRemaining.toAssetsUp());
    }

    function transferBorrow(VaultCache memory vaultCache, address from, address to, Assets assets) internal virtual {
        Owed amount = assets.toOwed();

        (Owed fromOwed, Owed fromOwedPrev) = loadUserBorrow(vaultCache, from);

        // If amount was rounded up, or dust is left over, transfer exact amount owed
        if (
            (amount > fromOwed && amount.subUnchecked(fromOwed).isDust())
                || (amount < fromOwed && fromOwed.subUnchecked(amount).isDust())
        ) {
            amount = fromOwed;
        }

        if (amount > fromOwed) revert E_InsufficientDebt();

        fromOwed = fromOwed.subUnchecked(amount);
        setUserBorrow(vaultCache, from, fromOwed);

        (Owed toOwed, Owed toOwedPrev) = loadUserBorrow(vaultCache, to);

        toOwed = toOwed + amount;
        setUserBorrow(vaultCache, to, toOwed);

        // with small fractional debt amounts the interest calculation could be negative in `logRepay`
        Assets fromPrevAssets = fromOwedPrev.toAssetsUp();
        Assets fromAssets = fromOwed.toAssetsUp();
        Assets repayAssets = fromPrevAssets > assets + fromAssets ? fromPrevAssets.subUnchecked(fromAssets) : assets;
        logRepay(from, repayAssets, fromPrevAssets, fromAssets);

        // with small fractional debt amounts the interest calculation could be negative in `logBorrow`
        Assets toPrevAssets = toOwedPrev.toAssetsUp();
        Assets toAssets = toOwed.toAssetsUp();
        Assets borrowAssets = assets + toPrevAssets > toAssets ? toAssets.subUnchecked(toPrevAssets) : assets;
        logBorrow(to, borrowAssets, toPrevAssets, toAssets);
    }

    function computeInterestRate(VaultCache memory vaultCache) internal virtual returns (uint256) {
        // single sload
        address irm = vaultStorage.interestRateModel;
        uint256 newInterestRate = vaultStorage.interestRate;

        if (irm != address(0)) {
            (bool success, bytes memory data) = irm.call(
                abi.encodeCall(
                    IIRM.computeInterestRate,
                    (address(this), vaultCache.cash.toUint(), vaultCache.totalBorrows.toAssetsUp().toUint())
                )
            );

            if (success && data.length >= 32) {
                newInterestRate = abi.decode(data, (uint256));
                if (newInterestRate > MAX_ALLOWED_INTEREST_RATE) newInterestRate = MAX_ALLOWED_INTEREST_RATE;
                vaultStorage.interestRate = uint72(newInterestRate);
            }
        }

        return newInterestRate;
    }

    function computeInterestRateView(VaultCache memory vaultCache) internal view virtual returns (uint256) {
        // single sload
        address irm = vaultStorage.interestRateModel;
        uint256 newInterestRate = vaultStorage.interestRate;

        if (irm != address(0) && isVaultStatusCheckDeferred()) {
            (bool success, bytes memory data) = irm.staticcall(
                abi.encodeCall(
                    IIRM.computeInterestRateView,
                    (address(this), vaultCache.cash.toUint(), vaultCache.totalBorrows.toAssetsUp().toUint())
                )
            );

            if (success && data.length >= 32) {
                newInterestRate = abi.decode(data, (uint256));
                if (newInterestRate > MAX_ALLOWED_INTEREST_RATE) newInterestRate = MAX_ALLOWED_INTEREST_RATE;
            }
        }

        return newInterestRate;
    }

    function calculateDTokenAddress() internal view virtual returns (address dToken) {
        // inspired by:
        // https://github.com/Vectorized/solady/blob/229c18cfcdcd474f95c30ad31b0f7d428ee8a31a/src/utils/CREATE3.sol#L82-L90
        assembly ("memory-safe") {
            mstore(0x14, address())
            // 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ address(this) ++ 0x01).
            // 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex).
            mstore(0x00, 0xd694)
            // Nonce of the contract when DToken was deployed (1).
            mstore8(0x34, 0x01)

            dToken := keccak256(0x1e, 0x17)
        }
    }

    function logBorrow(address account, Assets amount, Assets prevOwed, Assets owed) private {
        Assets interest = owed.subUnchecked(prevOwed).subUnchecked(amount);
        if (!interest.isZero()) emit InterestAccrued(account, interest.toUint());
        if (!amount.isZero()) emit Borrow(account, amount.toUint());
        logDToken(account, prevOwed, owed);
    }

    function logRepay(address account, Assets amount, Assets prevOwed, Assets owed) private {
        Assets interest = owed.addUnchecked(amount).subUnchecked(prevOwed);
        if (!interest.isZero()) emit InterestAccrued(account, interest.toUint());
        if (!amount.isZero()) emit Repay(account, amount.toUint());
        logDToken(account, prevOwed, owed);
    }

    function logDToken(address account, Assets prevOwed, Assets owed) private {
        address dTokenAddress = calculateDTokenAddress();

        if (owed > prevOwed) {
            uint256 change = owed.subUnchecked(prevOwed).toUint();
            DToken(dTokenAddress).emitTransfer(address(0), account, change);
        } else if (prevOwed > owed) {
            uint256 change = prevOwed.subUnchecked(owed).toUint();
            DToken(dTokenAddress).emitTransfer(account, address(0), change);
        }
    }
}

File 29 of 52 : DToken.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Errors} from "./shared/Errors.sol";
import {Events} from "./shared/Events.sol";
import {IERC20, IEVault} from "./IEVault.sol";

/// @title DToken
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Contract implements read only ERC20 interface, and `Transfer` events, for EVault's debt
contract DToken is IERC20, Errors, Events {
    /// @notice The address of the EVault associated with this DToken
    address public immutable eVault;

    constructor() {
        eVault = msg.sender;
    }

    // ERC20 interface

    /// @notice The debt token (dToken) name
    /// @return The dToken name
    function name() external view returns (string memory) {
        return string.concat("Debt token of ", IEVault(eVault).name());
    }

    /// @notice The debt token (dToken) symbol
    /// @return The dToken symbol
    function symbol() external view returns (string memory) {
        return string.concat(IEVault(eVault).symbol(), "-DEBT");
    }

    /// @notice Decimals of the dToken, same as EVault's
    /// @return The dToken decimals
    function decimals() external view returns (uint8) {
        return IEVault(eVault).decimals();
    }

    /// @notice Return total supply of the DToken
    /// @return The dToken total supply
    function totalSupply() external view returns (uint256) {
        return IEVault(eVault).totalBorrows();
    }

    /// @notice Balance of a particular account, in dTokens
    /// @param owner The account to query
    /// @return The balance of the account
    function balanceOf(address owner) external view returns (uint256) {
        return IEVault(eVault).debtOf(owner);
    }

    /// @notice Retrieve the current allowance
    /// @return The allowance
    /// @dev Approvals are not supported by the dToken
    function allowance(address, address) external pure returns (uint256) {
        return 0;
    }

    /// @notice Function required by the ERC20 interface
    /// @dev Approvals are not supported by the DToken
    function approve(address, uint256) external pure returns (bool) {
        revert E_NotSupported();
    }

    /// @notice Function required by the ERC20 interface
    /// @dev Transfers are not supported by the DToken directly
    function transfer(address, uint256) external pure returns (bool) {
        revert E_NotSupported();
    }

    /// @notice Function required by the ERC20 interface
    /// @dev Transfers are not supported by the DToken directly
    function transferFrom(address, address, uint256) external pure returns (bool) {
        revert E_NotSupported();
    }

    // Events

    /// @notice Emit an ERC20 Transfer event
    /// @dev Only callable by the parent EVault
    function emitTransfer(address from, address to, uint256 value) external {
        if (msg.sender != eVault) revert E_Unauthorized();

        emit Transfer(from, to, value);
    }

    // Helpers

    /// @notice Return the address of the asset the debt is denominated in
    function asset() external view returns (address) {
        return IEVault(eVault).asset();
    }
}

File 30 of 52 : IPriceOracle.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.8.0;

/// @title IPriceOracle
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Common PriceOracle interface.
interface IPriceOracle {
    /// @notice Get the name of the oracle.
    /// @return The name of the oracle.
    function name() external view returns (string memory);

    /// @notice One-sided price: How much quote token you would get for inAmount of base token, assuming no price
    /// spread.
    /// @param inAmount The amount of `base` to convert.
    /// @param base The token that is being priced.
    /// @param quote The token that is the unit of account.
    /// @return outAmount The amount of `quote` that is equivalent to `inAmount` of `base`.
    function getQuote(uint256 inAmount, address base, address quote) external view returns (uint256 outAmount);

    /// @notice Two-sided price: How much quote token you would get/spend for selling/buying inAmount of base token.
    /// @param inAmount The amount of `base` to convert.
    /// @param base The token that is being priced.
    /// @param quote The token that is the unit of account.
    /// @return bidOutAmount The amount of `quote` you would get for selling `inAmount` of `base`.
    /// @return askOutAmount The amount of `quote` you would spend for buying `inAmount` of `base`.
    function getQuotes(uint256 inAmount, address base, address quote)
        external
        view
        returns (uint256 bidOutAmount, uint256 askOutAmount);
}

File 31 of 52 : IHookTarget.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.8.0;

/// @title IHookTarget
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @custom:security-contact [email protected]
/// @notice Provides an interface for the hook target contract
interface IHookTarget {
    /// @notice If given contract is a hook target, it is expected to return the bytes4 magic value that is the selector
    /// of this function
    /// @return The bytes4 magic value (0x87439e04) that is the selector of this function
    function isHookTarget() external view returns (bytes4);
}

File 32 of 52 : LTVUtils.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Storage} from "./Storage.sol";
import "./types/Types.sol";

/// @title LTVUtils
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Overridable getters for LTV configuration
abstract contract LTVUtils is Storage {
    function getLTV(address collateral, bool liquidation) internal view virtual returns (ConfigAmount) {
        return vaultStorage.ltvLookup[collateral].getLTV(liquidation);
    }

    function isRecognizedCollateral(address collateral) internal view virtual returns (bool) {
        return vaultStorage.ltvLookup[collateral].isRecognizedCollateral();
    }
}

File 33 of 52 : Errors.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

/// @title Errors
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Contract implementing EVault's custom errors
contract Errors {
    error E_Initialized();
    error E_ProxyMetadata();
    error E_SelfTransfer();
    error E_InsufficientAllowance();
    error E_InsufficientCash();
    error E_InsufficientAssets();
    error E_InsufficientBalance();
    error E_InsufficientDebt();
    error E_FlashLoanNotRepaid();
    error E_Reentrancy();
    error E_OperationDisabled();
    error E_OutstandingDebt();
    error E_AmountTooLargeToEncode();
    error E_DebtAmountTooLargeToEncode();
    error E_RepayTooMuch();
    error E_TransientState();
    error E_SelfLiquidation();
    error E_ControllerDisabled();
    error E_CollateralDisabled();
    error E_ViolatorLiquidityDeferred();
    error E_LiquidationCoolOff();
    error E_ExcessiveRepayAmount();
    error E_MinYield();
    error E_BadAddress();
    error E_ZeroAssets();
    error E_ZeroShares();
    error E_Unauthorized();
    error E_CheckUnauthorized();
    error E_NotSupported();
    error E_EmptyError();
    error E_BadBorrowCap();
    error E_BadSupplyCap();
    error E_BadCollateral();
    error E_AccountLiquidity();
    error E_NoLiability();
    error E_NotController();
    error E_BadFee();
    error E_SupplyCapExceeded();
    error E_BorrowCapExceeded();
    error E_InvalidLTVAsset();
    error E_NoPriceOracle();
    error E_ConfigAmountTooLargeToEncode();
    error E_BadAssetReceiver();
    error E_BadSharesOwner();
    error E_BadSharesReceiver();
    error E_BadMaxLiquidationDiscount();
    error E_LTVBorrow();
    error E_LTVLiquidation();
    error E_NotHookTarget();
}

File 34 of 52 : Storage.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {VaultStorage, Snapshot} from "./types/Types.sol";

/// @title Storage
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Contract that defines the EVault's data storage
abstract contract Storage {
    /// @notice Flag indicating if the vault has been initialized
    bool internal initialized;

    /// @notice Snapshot of vault's cash and borrows created at the beginning of an operation or a batch of operations
    /// @dev The snapshot is separate from VaultStorage, because it could be implemented as transient storage
    Snapshot internal snapshot;

    /// @notice A singleton VaultStorage
    VaultStorage internal vaultStorage;
}

File 35 of 52 : Events.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

/// @title Events
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Contract implementing EVault's events
abstract contract Events {
    // ERC20

    /// @notice Transfer an ERC20 token balance
    /// @param from Sender address
    /// @param to Receiver address
    /// @param value Tokens sent
    event Transfer(address indexed from, address indexed to, uint256 value);

    /// @notice Set an ERC20 approval
    /// @param owner Address granting approval to spend tokens
    /// @param spender Address receiving approval to spend tokens
    /// @param value Amount of tokens approved to spend
    event Approval(address indexed owner, address indexed spender, uint256 value);

    // ERC4626

    /// @notice Deposit assets into an ERC4626 vault
    /// @param sender Address initiating the deposit
    /// @param owner Address holding the assets
    /// @param assets Amount of assets deposited
    /// @param shares Amount of shares minted as receipt for the deposit
    event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);

    /// @notice Withdraw from an ERC4626 vault
    /// @param sender Address initiating the withdrawal
    /// @param receiver Address receiving the assets
    /// @param owner Address holding the shares
    /// @param assets Amount of assets sent to the receiver
    /// @param shares Amount of shares burned
    event Withdraw(
        address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares
    );

    // EVault

    /// @notice New EVault is initialized
    /// @param creator Address designated as the vault's creator
    /// @param asset The underlying asset of the vault
    /// @param dToken Address of the sidecar debt token
    event EVaultCreated(address indexed creator, address indexed asset, address dToken);

    /// @notice Log the current vault status
    /// @param totalShares Sum of all shares
    /// @param totalBorrows Sum of all borrows in assets
    /// @param accumulatedFees Interest fees accrued in the accumulator
    /// @param cash The amount of assets held by the vault directly
    /// @param interestAccumulator Current interest accumulator in ray
    /// @param interestRate Current interest rate, which will be applied during the next fee accrual
    /// @param timestamp Current block's timestamp
    event VaultStatus(
        uint256 totalShares,
        uint256 totalBorrows,
        uint256 accumulatedFees,
        uint256 cash,
        uint256 interestAccumulator,
        uint256 interestRate,
        uint256 timestamp
    );

    /// @notice Increase account's debt
    /// @param account Address adding liability
    /// @param assets Amount of debt added in assets
    event Borrow(address indexed account, uint256 assets);

    /// @notice Decrease account's debt
    /// @param account Address repaying the debt
    /// @param assets Amount of debt removed in assets
    event Repay(address indexed account, uint256 assets);

    /// @notice Account's debt was increased due to interest
    /// @param account Address being charged interest
    /// @param assets Amount of debt added in assets
    event InterestAccrued(address indexed account, uint256 assets);

    /// @notice Liquidate unhealthy account
    /// @param liquidator Address executing the liquidation
    /// @param violator Address holding an unhealthy borrow
    /// @param collateral Address of the asset seized
    /// @param repayAssets Amount of debt in assets transferred from violator to liquidator
    /// @param yieldBalance Amount of collateral asset's balance transferred from violator to liquidator
    event Liquidate(
        address indexed liquidator,
        address indexed violator,
        address collateral,
        uint256 repayAssets,
        uint256 yieldBalance
    );

    /// @notice Take on debt from another account
    /// @param from Account from which the debt is taken
    /// @param to Account taking on the debt
    /// @param assets Amount of debt transferred in assets
    event PullDebt(address indexed from, address indexed to, uint256 assets);

    /// @notice Socialize debt after liquidating all of the unhealthy account's collateral
    /// @param account Address holding an unhealthy borrow
    /// @param assets Amount of debt socialized among all of the share holders
    event DebtSocialized(address indexed account, uint256 assets);

    /// @notice Split the accumulated fees between the governor and the protocol
    /// @param sender Address initializing the conversion
    /// @param protocolReceiver Address receiving the protocol's share of the fees
    /// @param governorReceiver Address receiving the governor's share of the fees
    /// @param protocolShares Amount of shares transferred to the protocol receiver
    /// @param governorShares Amount of shares transferred to the governor receiver
    event ConvertFees(
        address indexed sender,
        address indexed protocolReceiver,
        address indexed governorReceiver,
        uint256 protocolShares,
        uint256 governorShares
    );

    /// @notice Enable or disable balance tracking for the account
    /// @param account Address which enabled or disabled balance tracking
    /// @param status True if balance tracking was enabled, false otherwise
    event BalanceForwarderStatus(address indexed account, bool status);
}

File 36 of 52 : IEthereumVaultConnector.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.8.0;

/// @title IEVC
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice This interface defines the methods for the Ethereum Vault Connector.
interface IEVC {
    /// @notice A struct representing a batch item.
    /// @dev Each batch item represents a single operation to be performed within a checks deferred context.
    struct BatchItem {
        /// @notice The target contract to be called.
        address targetContract;
        /// @notice The account on behalf of which the operation is to be performed. msg.sender must be authorized to
        /// act on behalf of this account. Must be address(0) if the target contract is the EVC itself.
        address onBehalfOfAccount;
        /// @notice The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole
        /// balance of the EVC contract will be forwarded. Must be 0 if the target contract is the EVC itself.
        uint256 value;
        /// @notice The encoded data which is called on the target contract.
        bytes data;
    }

    /// @notice A struct representing the result of a batch item operation.
    /// @dev Used only for simulation purposes.
    struct BatchItemResult {
        /// @notice A boolean indicating whether the operation was successful.
        bool success;
        /// @notice The result of the operation.
        bytes result;
    }

    /// @notice A struct representing the result of the account or vault status check.
    /// @dev Used only for simulation purposes.
    struct StatusCheckResult {
        /// @notice The address of the account or vault for which the check was performed.
        address checkedAddress;
        /// @notice A boolean indicating whether the status of the account or vault is valid.
        bool isValid;
        /// @notice The result of the check.
        bytes result;
    }

    /// @notice Returns current raw execution context.
    /// @dev When checks in progress, on behalf of account is always address(0).
    /// @return context Current raw execution context.
    function getRawExecutionContext() external view returns (uint256 context);

    /// @notice Returns an account on behalf of which the operation is being executed at the moment and whether the
    /// controllerToCheck is an enabled controller for that account.
    /// @dev This function should only be used by external smart contracts if msg.sender is the EVC. Otherwise, the
    /// account address returned must not be trusted.
    /// @dev When checks in progress, on behalf of account is always address(0). When address is zero, the function
    /// reverts to protect the consumer from ever relying on the on behalf of account address which is in its default
    /// state.
    /// @param controllerToCheck The address of the controller for which it is checked whether it is an enabled
    /// controller for the account on behalf of which the operation is being executed at the moment.
    /// @return onBehalfOfAccount An account that has been authenticated and on behalf of which the operation is being
    /// executed at the moment.
    /// @return controllerEnabled A boolean value that indicates whether controllerToCheck is an enabled controller for
    /// the account on behalf of which the operation is being executed at the moment. Always false if controllerToCheck
    /// is address(0).
    function getCurrentOnBehalfOfAccount(address controllerToCheck)
        external
        view
        returns (address onBehalfOfAccount, bool controllerEnabled);

    /// @notice Checks if checks are deferred.
    /// @return A boolean indicating whether checks are deferred.
    function areChecksDeferred() external view returns (bool);

    /// @notice Checks if checks are in progress.
    /// @return A boolean indicating whether checks are in progress.
    function areChecksInProgress() external view returns (bool);

    /// @notice Checks if control collateral is in progress.
    /// @return A boolean indicating whether control collateral is in progress.
    function isControlCollateralInProgress() external view returns (bool);

    /// @notice Checks if an operator is authenticated.
    /// @return A boolean indicating whether an operator is authenticated.
    function isOperatorAuthenticated() external view returns (bool);

    /// @notice Checks if a simulation is in progress.
    /// @return A boolean indicating whether a simulation is in progress.
    function isSimulationInProgress() external view returns (bool);

    /// @notice Checks whether the specified account and the other account have the same owner.
    /// @dev The function is used to check whether one account is authorized to perform operations on behalf of the
    /// other. Accounts are considered to have a common owner if they share the first 19 bytes of their address.
    /// @param account The address of the account that is being checked.
    /// @param otherAccount The address of the other account that is being checked.
    /// @return A boolean flag that indicates whether the accounts have the same owner.
    function haveCommonOwner(address account, address otherAccount) external pure returns (bool);

    /// @notice Returns the address prefix of the specified account.
    /// @dev The address prefix is the first 19 bytes of the account address.
    /// @param account The address of the account whose address prefix is being retrieved.
    /// @return A bytes19 value that represents the address prefix of the account.
    function getAddressPrefix(address account) external pure returns (bytes19);

    /// @notice Returns the owner for the specified account.
    /// @dev The function returns address(0) if the owner is not registered. Registration of the owner happens on the
    /// initial
    /// interaction with the EVC that requires authentication of an owner.
    /// @param account The address of the account whose owner is being retrieved.
    /// @return owner The address of the account owner. An account owner is an EOA/smart contract which address matches
    /// the first 19 bytes of the account address.
    function getAccountOwner(address account) external view returns (address);

    /// @notice Checks if lockdown mode is enabled for a given address prefix.
    /// @param addressPrefix The address prefix to check for lockdown mode status.
    /// @return A boolean indicating whether lockdown mode is enabled.
    function isLockdownMode(bytes19 addressPrefix) external view returns (bool);

    /// @notice Checks if permit functionality is disabled for a given address prefix.
    /// @param addressPrefix The address prefix to check for permit functionality status.
    /// @return A boolean indicating whether permit functionality is disabled.
    function isPermitDisabledMode(bytes19 addressPrefix) external view returns (bool);

    /// @notice Returns the current nonce for a given address prefix and nonce namespace.
    /// @dev Each nonce namespace provides 256 bit nonce that has to be used sequentially. There's no requirement to use
    /// all the nonces for a given nonce namespace before moving to the next one which allows to use permit messages in
    /// a non-sequential manner.
    /// @param addressPrefix The address prefix for which the nonce is being retrieved.
    /// @param nonceNamespace The nonce namespace for which the nonce is being retrieved.
    /// @return nonce The current nonce for the given address prefix and nonce namespace.
    function getNonce(bytes19 addressPrefix, uint256 nonceNamespace) external view returns (uint256 nonce);

    /// @notice Returns the bit field for a given address prefix and operator.
    /// @dev The bit field is used to store information about authorized operators for a given address prefix. Each bit
    /// in the bit field corresponds to one account belonging to the same owner. If the bit is set, the operator is
    /// authorized for the account.
    /// @param addressPrefix The address prefix for which the bit field is being retrieved.
    /// @param operator The address of the operator for which the bit field is being retrieved.
    /// @return operatorBitField The bit field for the given address prefix and operator. The bit field defines which
    /// accounts the operator is authorized for. It is a 256-position binary array like 0...010...0, marking the account
    /// positionally in a uint256. The position in the bit field corresponds to the account ID (0-255), where 0 is the
    /// owner account's ID.
    function getOperator(bytes19 addressPrefix, address operator) external view returns (uint256 operatorBitField);

    /// @notice Returns whether a given operator has been authorized for a given account.
    /// @param account The address of the account whose operator is being checked.
    /// @param operator The address of the operator that is being checked.
    /// @return authorized A boolean value that indicates whether the operator is authorized for the account.
    function isAccountOperatorAuthorized(address account, address operator) external view returns (bool authorized);

    /// @notice Enables or disables lockdown mode for a given address prefix.
    /// @dev This function can only be called by the owner of the address prefix. To disable this mode, the EVC
    /// must be called directly. It is not possible to disable this mode by using checks-deferrable call or
    /// permit message.
    /// @param addressPrefix The address prefix for which the lockdown mode is being set.
    /// @param enabled A boolean indicating whether to enable or disable lockdown mode.
    function setLockdownMode(bytes19 addressPrefix, bool enabled) external payable;

    /// @notice Enables or disables permit functionality for a given address prefix.
    /// @dev This function can only be called by the owner of the address prefix. To disable this mode, the EVC
    /// must be called directly. It is not possible to disable this mode by using checks-deferrable call or (by
    /// definition) permit message. To support permit functionality by default, note that the logic was inverted here. To
    /// disable  the permit functionality, one must pass true as the second argument. To enable the permit
    /// functionality, one must pass false as the second argument.
    /// @param addressPrefix The address prefix for which the permit functionality is being set.
    /// @param enabled A boolean indicating whether to enable or disable the disable-permit mode.
    function setPermitDisabledMode(bytes19 addressPrefix, bool enabled) external payable;

    /// @notice Sets the nonce for a given address prefix and nonce namespace.
    /// @dev This function can only be called by the owner of the address prefix. Each nonce namespace provides a 256
    /// bit nonce that has to be used sequentially. There's no requirement to use all the nonces for a given nonce
    /// namespace before moving to the next one which allows the use of permit messages in a non-sequential manner. To
    /// invalidate signed permit messages, set the nonce for a given nonce namespace accordingly. To invalidate all the
    /// permit messages for a given nonce namespace, set the nonce to type(uint).max.
    /// @param addressPrefix The address prefix for which the nonce is being set.
    /// @param nonceNamespace The nonce namespace for which the nonce is being set.
    /// @param nonce The new nonce for the given address prefix and nonce namespace.
    function setNonce(bytes19 addressPrefix, uint256 nonceNamespace, uint256 nonce) external payable;

    /// @notice Sets the bit field for a given address prefix and operator.
    /// @dev This function can only be called by the owner of the address prefix. Each bit in the bit field corresponds
    /// to one account belonging to the same owner. If the bit is set, the operator is authorized for the account.
    /// @param addressPrefix The address prefix for which the bit field is being set.
    /// @param operator The address of the operator for which the bit field is being set. Can neither be the EVC address
    /// nor an address belonging to the same address prefix.
    /// @param operatorBitField The new bit field for the given address prefix and operator. Reverts if the provided
    /// value is equal to the currently stored value.
    function setOperator(bytes19 addressPrefix, address operator, uint256 operatorBitField) external payable;

    /// @notice Authorizes or deauthorizes an operator for the account.
    /// @dev Only the owner or authorized operator of the account can call this function. An operator is an address that
    /// can perform actions for an account on behalf of the owner. If it's an operator calling this function, it can
    /// only deauthorize itself.
    /// @param account The address of the account whose operator is being set or unset.
    /// @param operator The address of the operator that is being installed or uninstalled. Can neither be the EVC
    /// address nor an address belonging to the same owner as the account.
    /// @param authorized A boolean value that indicates whether the operator is being authorized or deauthorized.
    /// Reverts if the provided value is equal to the currently stored value.
    function setAccountOperator(address account, address operator, bool authorized) external payable;

    /// @notice Returns an array of collaterals enabled for an account.
    /// @dev A collateral is a vault for which an account's balances are under the control of the currently enabled
    /// controller vault.
    /// @param account The address of the account whose collaterals are being queried.
    /// @return An array of addresses that are enabled collaterals for the account.
    function getCollaterals(address account) external view returns (address[] memory);

    /// @notice Returns whether a collateral is enabled for an account.
    /// @dev A collateral is a vault for which account's balances are under the control of the currently enabled
    /// controller vault.
    /// @param account The address of the account that is being checked.
    /// @param vault The address of the collateral that is being checked.
    /// @return A boolean value that indicates whether the vault is an enabled collateral for the account or not.
    function isCollateralEnabled(address account, address vault) external view returns (bool);

    /// @notice Enables a collateral for an account.
    /// @dev A collaterals is a vault for which account's balances are under the control of the currently enabled
    /// controller vault. Only the owner or an operator of the account can call this function. Unless it's a duplicate,
    /// the collateral is added to the end of the array. There can be at most 10 unique collaterals enabled at a time.
    /// Account status checks are performed.
    /// @param account The account address for which the collateral is being enabled.
    /// @param vault The address being enabled as a collateral.
    function enableCollateral(address account, address vault) external payable;

    /// @notice Disables a collateral for an account.
    /// @dev This function does not preserve the order of collaterals in the array obtained using the getCollaterals
    /// function; the order may change. A collateral is a vault for which account’s balances are under the control of
    /// the currently enabled controller vault. Only the owner or an operator of the account can call this function.
    /// Disabling a collateral might change the order of collaterals in the array obtained using getCollaterals
    /// function. Account status checks are performed.
    /// @param account The account address for which the collateral is being disabled.
    /// @param vault The address of a collateral being disabled.
    function disableCollateral(address account, address vault) external payable;

    /// @notice Swaps the position of two collaterals so that they appear switched in the array of collaterals for a
    /// given account obtained by calling getCollaterals function.
    /// @dev A collateral is a vault for which account’s balances are under the control of the currently enabled
    /// controller vault. Only the owner or an operator of the account can call this function. The order of collaterals
    /// can be changed by specifying the indices of the two collaterals to be swapped. Indices are zero-based and must
    /// be in the range of 0 to the number of collaterals minus 1. index1 must be lower than index2. Account status
    /// checks are performed.
    /// @param account The address of the account for which the collaterals are being reordered.
    /// @param index1 The index of the first collateral to be swapped.
    /// @param index2 The index of the second collateral to be swapped.
    function reorderCollaterals(address account, uint8 index1, uint8 index2) external payable;

    /// @notice Returns an array of enabled controllers for an account.
    /// @dev A controller is a vault that has been chosen for an account to have special control over the account's
    /// balances in enabled collaterals vaults. A user can have multiple controllers during a call execution, but at
    /// most one can be selected when the account status check is performed.
    /// @param account The address of the account whose controllers are being queried.
    /// @return An array of addresses that are the enabled controllers for the account.
    function getControllers(address account) external view returns (address[] memory);

    /// @notice Returns whether a controller is enabled for an account.
    /// @dev A controller is a vault that has been chosen for an account to have special control over account’s
    /// balances in the enabled collaterals vaults.
    /// @param account The address of the account that is being checked.
    /// @param vault The address of the controller that is being checked.
    /// @return A boolean value that indicates whether the vault is enabled controller for the account or not.
    function isControllerEnabled(address account, address vault) external view returns (bool);

    /// @notice Enables a controller for an account.
    /// @dev A controller is a vault that has been chosen for an account to have special control over account’s
    /// balances in the enabled collaterals vaults. Only the owner or an operator of the account can call this function.
    /// Unless it's a duplicate, the controller is added to the end of the array. Transiently, there can be at most 10
    /// unique controllers enabled at a time, but at most one can be enabled after the outermost checks-deferrable
    /// call concludes. Account status checks are performed.
    /// @param account The address for which the controller is being enabled.
    /// @param vault The address of the controller being enabled.
    function enableController(address account, address vault) external payable;

    /// @notice Disables a controller for an account.
    /// @dev A controller is a vault that has been chosen for an account to have special control over account’s
    /// balances in the enabled collaterals vaults. Only the vault itself can call this function. Disabling a controller
    /// might change the order of controllers in the array obtained using getControllers function. Account status checks
    /// are performed.
    /// @param account The address for which the calling controller is being disabled.
    function disableController(address account) external payable;

    /// @notice Executes signed arbitrary data by self-calling into the EVC.
    /// @dev Low-level call function is used to execute the arbitrary data signed by the owner or the operator on the
    /// EVC contract. During that call, EVC becomes msg.sender.
    /// @param signer The address signing the permit message (ECDSA) or verifying the permit message signature
    /// (ERC-1271). It's also the owner or the operator of all the accounts for which authentication will be needed
    /// during the execution of the arbitrary data call.
    /// @param sender The address of the msg.sender which is expected to execute the data signed by the signer. If
    /// address(0) is passed, the msg.sender is ignored.
    /// @param nonceNamespace The nonce namespace for which the nonce is being used.
    /// @param nonce The nonce for the given account and nonce namespace. A valid nonce value is considered to be the
    /// value currently stored and can take any value between 0 and type(uint256).max - 1.
    /// @param deadline The timestamp after which the permit is considered expired.
    /// @param value The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole
    /// balance of the EVC contract will be forwarded.
    /// @param data The encoded data which is self-called on the EVC contract.
    /// @param signature The signature of the data signed by the signer.
    function permit(
        address signer,
        address sender,
        uint256 nonceNamespace,
        uint256 nonce,
        uint256 deadline,
        uint256 value,
        bytes calldata data,
        bytes calldata signature
    ) external payable;

    /// @notice Calls into a target contract as per data encoded.
    /// @dev This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost
    /// call ends, the account and vault status checks are performed.
    /// @dev This function can be used to interact with any contract while checks are deferred. If the target contract
    /// is msg.sender, msg.sender is called back with the calldata provided and the context set up according to the
    /// account provided. If the target contract is not msg.sender, only the owner or the operator of the account
    /// provided can call this function.
    /// @dev This function can be used to recover the remaining value from the EVC contract.
    /// @param targetContract The address of the contract to be called.
    /// @param onBehalfOfAccount  If the target contract is msg.sender, the address of the account which will be set
    /// in the context. It assumes msg.sender has authenticated the account themselves. If the target contract is
    /// not msg.sender, the address of the account for which it is checked whether msg.sender is authorized to act
    /// on behalf of.
    /// @param value The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole
    /// balance of the EVC contract will be forwarded.
    /// @param data The encoded data which is called on the target contract.
    /// @return result The result of the call.
    function call(
        address targetContract,
        address onBehalfOfAccount,
        uint256 value,
        bytes calldata data
    ) external payable returns (bytes memory result);

    /// @notice For a given account, calls into one of the enabled collateral vaults from the currently enabled
    /// controller vault as per data encoded.
    /// @dev This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost
    /// call ends, the account and vault status checks are performed.
    /// @dev This function can be used to interact with any contract while checks are deferred as long as the contract
    /// is enabled as a collateral of the account and the msg.sender is the only enabled controller of the account.
    /// @param targetCollateral The collateral address to be called.
    /// @param onBehalfOfAccount The address of the account for which it is checked whether msg.sender is authorized to
    /// act on behalf.
    /// @param value The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole
    /// balance of the EVC contract will be forwarded.
    /// @param data The encoded data which is called on the target collateral.
    /// @return result The result of the call.
    function controlCollateral(
        address targetCollateral,
        address onBehalfOfAccount,
        uint256 value,
        bytes calldata data
    ) external payable returns (bytes memory result);

    /// @notice Executes multiple calls into the target contracts while checks deferred as per batch items provided.
    /// @dev This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost
    /// call ends, the account and vault status checks are performed.
    /// @dev The authentication rules for each batch item are the same as for the call function.
    /// @param items An array of batch items to be executed.
    function batch(BatchItem[] calldata items) external payable;

    /// @notice Executes multiple calls into the target contracts while checks deferred as per batch items provided.
    /// @dev This function always reverts as it's only used for simulation purposes. This function cannot be called
    /// within a checks-deferrable call.
    /// @param items An array of batch items to be executed.
    function batchRevert(BatchItem[] calldata items) external payable;

    /// @notice Executes multiple calls into the target contracts while checks deferred as per batch items provided.
    /// @dev This function does not modify state and should only be used for simulation purposes. This function cannot
    /// be called within a checks-deferrable call.
    /// @param items An array of batch items to be executed.
    /// @return batchItemsResult An array of batch item results for each item.
    /// @return accountsStatusCheckResult An array of account status check results for each account.
    /// @return vaultsStatusCheckResult An array of vault status check results for each vault.
    function batchSimulation(BatchItem[] calldata items)
        external
        payable
        returns (
            BatchItemResult[] memory batchItemsResult,
            StatusCheckResult[] memory accountsStatusCheckResult,
            StatusCheckResult[] memory vaultsStatusCheckResult
        );

    /// @notice Retrieves the timestamp of the last successful account status check performed for a specific account.
    /// @dev This function reverts if the checks are in progress.
    /// @dev The account status check is considered to be successful if it calls into the selected controller vault and
    /// obtains expected magic value. This timestamp does not change if the account status is considered valid when no
    /// controller enabled. When consuming, one might need to ensure that the account status check is not deferred at
    /// the moment.
    /// @param account The address of the account for which the last status check timestamp is being queried.
    /// @return The timestamp of the last status check as a uint256.
    function getLastAccountStatusCheckTimestamp(address account) external view returns (uint256);

    /// @notice Checks whether the status check is deferred for a given account.
    /// @dev This function reverts if the checks are in progress.
    /// @param account The address of the account for which it is checked whether the status check is deferred.
    /// @return A boolean flag that indicates whether the status check is deferred or not.
    function isAccountStatusCheckDeferred(address account) external view returns (bool);

    /// @notice Checks the status of an account and reverts if it is not valid.
    /// @dev If checks deferred, the account is added to the set of accounts to be checked at the end of the outermost
    /// checks-deferrable call. There can be at most 10 unique accounts added to the set at a time. Account status
    /// check is performed by calling into the selected controller vault and passing the array of currently enabled
    /// collaterals. If controller is not selected, the account is always considered valid.
    /// @param account The address of the account to be checked.
    function requireAccountStatusCheck(address account) external payable;

    /// @notice Forgives previously deferred account status check.
    /// @dev Account address is removed from the set of addresses for which status checks are deferred. This function
    /// can only be called by the currently enabled controller of a given account. Depending on the vault
    /// implementation, may be needed in the liquidation flow.
    /// @param account The address of the account for which the status check is forgiven.
    function forgiveAccountStatusCheck(address account) external payable;

    /// @notice Checks whether the status check is deferred for a given vault.
    /// @dev This function reverts if the checks are in progress.
    /// @param vault The address of the vault for which it is checked whether the status check is deferred.
    /// @return A boolean flag that indicates whether the status check is deferred or not.
    function isVaultStatusCheckDeferred(address vault) external view returns (bool);

    /// @notice Checks the status of a vault and reverts if it is not valid.
    /// @dev If checks deferred, the vault is added to the set of vaults to be checked at the end of the outermost
    /// checks-deferrable call. There can be at most 10 unique vaults added to the set at a time. This function can
    /// only be called by the vault itself.
    function requireVaultStatusCheck() external payable;

    /// @notice Forgives previously deferred vault status check.
    /// @dev Vault address is removed from the set of addresses for which status checks are deferred. This function can
    /// only be called by the vault itself.
    function forgiveVaultStatusCheck() external payable;

    /// @notice Checks the status of an account and a vault and reverts if it is not valid.
    /// @dev If checks deferred, the account and the vault are added to the respective sets of accounts and vaults to be
    /// checked at the end of the outermost checks-deferrable call. Account status check is performed by calling into
    /// selected controller vault and passing the array of currently enabled collaterals. If controller is not selected,
    /// the account is always considered valid. This function can only be called by the vault itself.
    /// @param account The address of the account to be checked.
    function requireAccountAndVaultStatusCheck(address account) external payable;
}

File 37 of 52 : RPow.sol
// SPDX-License-Identifier: AGPL-3.0-or-later

pragma solidity ^0.8.0;

/// @notice Arithmetic library with operations for fixed-point numbers.
/// @custom:security-contact [email protected]
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
/// @author Modified by Euler Labs (https://www.eulerlabs.com/) to return an `overflow` bool instead of reverting
library RPow {
    /// @dev If overflow is true, an overflow occurred and the value of z is undefined
    function rpow(uint256 x, uint256 n, uint256 scalar) internal pure returns (uint256 z, bool overflow) {
        /// @solidity memory-safe-assembly
        assembly {
            switch x
            case 0 {
                switch n
                case 0 {
                    // 0 ** 0 = 1
                    z := scalar
                }
                default {
                    // 0 ** n = 0
                    z := 0
                }
            }
            default {
                switch mod(n, 2)
                case 0 {
                    // If n is even, store scalar in z for now.
                    z := scalar
                }
                default {
                    // If n is odd, store x in z for now.
                    z := x
                }

                // Shifting right by 1 is like dividing by 2.
                let half := shr(1, scalar)

                for {
                    // Shift n right by 1 before looping to halve it.
                    n := shr(1, n)
                } n {
                    // Shift n right by 1 each iteration to halve it.
                    n := shr(1, n)
                } {
                    // Bail if x ** 2 would overflow.
                    // Equivalent to iszero(eq(div(xx, x), x)) here.
                    if shr(128, x) {
                        overflow := 1
                        break
                    }

                    // Store x squared.
                    let xx := mul(x, x)

                    // Round to the nearest number.
                    let xxRound := add(xx, half)

                    // Bail if xx + half overflowed.
                    if lt(xxRound, xx) {
                        overflow := 1
                        break
                    }

                    // Set x to scaled xxRound.
                    x := div(xxRound, scalar)

                    // If n is even:
                    if mod(n, 2) {
                        // Compute z * x.
                        let zx := mul(z, x)

                        // If z * x overflowed:
                        if iszero(eq(div(zx, x), z)) {
                            // Bail if x is non-zero.
                            if iszero(iszero(x)) {
                                overflow := 1
                                break
                            }
                        }

                        // Round to the nearest number.
                        let zxRound := add(zx, half)

                        // Bail if zx + half overflowed.
                        if lt(zxRound, zx) {
                            overflow := 1
                            break
                        }

                        // Return properly scaled zxRound.
                        z := div(zxRound, scalar)
                    }
                }
            }
        }
    }
}

File 38 of 52 : VaultStorage.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Assets, Shares, Owed, AmountCap, ConfigAmount, Flags} from "./Types.sol";
import {LTVConfig} from "./LTVConfig.sol";
import {UserStorage} from "./UserStorage.sol";

/// @title VaultStorage
/// @notice This struct is used to hold all of the vault's permanent storage
/// @dev Note that snapshots are not a part of this struct, as they might be reimplemented as transient storage
struct VaultStorage {
    // Packed slot 6 + 14 + 2 + 2 + 4 + 1 + 1 = 30
    // A timestamp of the last interest accumulator update
    uint48 lastInterestAccumulatorUpdate;
    // The amount of assets held directly by the vault
    Assets cash;
    // Current supply cap in asset units
    AmountCap supplyCap;
    // Current borrow cap in asset units
    AmountCap borrowCap;
    // A bitfield of operations which trigger a hook call
    Flags hookedOps;
    // A vault global reentrancy protection flag
    bool reentrancyLocked;
    // A flag indicating if the vault snapshot has already been initialized for the currently executing batch
    bool snapshotInitialized;

    // Packed slot 14 + 18 = 32
    // Sum of all user shares
    Shares totalShares;
    // Sum of all user debts
    Owed totalBorrows;

    // Packed slot 14 + 2 + 2 + 4 = 22
    // Interest fees accrued since the last fee conversion
    Shares accumulatedFees;
    // Maximum liquidation discount
    ConfigAmount maxLiquidationDiscount;
    // Amount of time in seconds that must pass after a successful account status check before liquidation is possible
    uint16 liquidationCoolOffTime;
    // A bitfield of vault configuration options
    Flags configFlags;

    // Current interest accumulator
    uint256 interestAccumulator;

    // Packed slot 20 + 2 + 9 = 31
    // Address of the interest rate model contract. If not set, 0% interest is applied
    address interestRateModel;
    // Percentage of accrued interest that is directed to fees
    ConfigAmount interestFee;
    // Current interest rate applied to outstanding borrows
    uint72 interestRate;

    // Name of the shares token (eToken)
    string name;
    // Symbol of the shares token (eToken)
    string symbol;

    // Address of the vault's creator
    address creator;

    // Address of the vault's governor
    address governorAdmin;
    // Address which receives governor fees
    address feeReceiver;
    // Address which will be called for enabled hooks
    address hookTarget;

    // User accounts
    mapping(address account => UserStorage) users;

    // LTV configuration for collaterals
    mapping(address collateral => LTVConfig) ltvLookup;
    // List of addresses which were at any point configured as collateral
    address[] ltvList;
}

File 39 of 52 : Snapshot.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Assets} from "./Types.sol";

/// @title Snapshot
/// @notice This struct is used to store a snapshot of the vault's cash and total borrows at the beginning of an
/// operation (or a batch thereof)
struct Snapshot {
    // Packed slot: 14 + 14 + 4 = 32
    // vault's cash holdings
    Assets cash;
    // vault's total borrows in assets, in regular precision
    Assets borrows;
    // stamp occupies the rest of the storage slot and makes sure the slot is non-zero for gas savings
    uint32 stamp;
}

/// @title SnapshotLib
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Library for working with the `Snapshot` struct
library SnapshotLib {
    uint32 private constant STAMP = 1; // non zero initial value of the snapshot slot to save gas on SSTORE

    function set(Snapshot storage self, Assets cash, Assets borrows) internal {
        self.cash = cash;
        self.borrows = borrows;
        self.stamp = STAMP;
    }

    function reset(Snapshot storage self) internal {
        self.set(Assets.wrap(0), Assets.wrap(0));
    }
}

using SnapshotLib for Snapshot global;

File 40 of 52 : UserStorage.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Shares, Owed} from "./Types.sol";

/// @dev Custom type for holding shares and debt balances of an account, packed with balance forwarder opt-in flag
type PackedUserSlot is uint256;

/// @title UserStorage
/// @notice This struct is used to store user account data
struct UserStorage {
    // Shares and debt balances, balance forwarder opt-in
    PackedUserSlot data;
    // Snapshot of the interest accumulator from the last change to account's liability
    uint256 interestAccumulator;
    // A mapping with allowances for the vault shares token (eToken)
    mapping(address spender => uint256 allowance) eTokenAllowance;
}

/// @title UserStorageLib
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Library for working with the UserStorage struct
library UserStorageLib {
    uint256 private constant BALANCE_FORWARDER_MASK = 0x8000000000000000000000000000000000000000000000000000000000000000;
    uint256 private constant OWED_MASK = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000000000000000;
    uint256 private constant SHARES_MASK = 0x000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF;
    uint256 private constant OWED_OFFSET = 112;

    function isBalanceForwarderEnabled(UserStorage storage self) internal view returns (bool) {
        return unpackBalanceForwarder(self.data);
    }

    function getOwed(UserStorage storage self) internal view returns (Owed) {
        return Owed.wrap(uint144((PackedUserSlot.unwrap(self.data) & OWED_MASK) >> OWED_OFFSET));
    }

    function getBalance(UserStorage storage self) internal view returns (Shares) {
        return unpackBalance(self.data);
    }

    function getBalanceAndBalanceForwarder(UserStorage storage self) internal view returns (Shares, bool) {
        PackedUserSlot data = self.data; // single SLOAD
        return (unpackBalance(data), unpackBalanceForwarder(data));
    }

    function setBalanceForwarder(UserStorage storage self, bool newValue) internal {
        uint256 data = PackedUserSlot.unwrap(self.data);

        uint256 newFlag = newValue ? BALANCE_FORWARDER_MASK : 0;
        self.data = PackedUserSlot.wrap(newFlag | (data & ~BALANCE_FORWARDER_MASK));
    }

    function setOwed(UserStorage storage self, Owed owed) internal {
        uint256 data = PackedUserSlot.unwrap(self.data);

        self.data = PackedUserSlot.wrap((owed.toUint() << OWED_OFFSET) | (data & ~OWED_MASK));
    }

    function setBalance(UserStorage storage self, Shares balance) internal {
        uint256 data = PackedUserSlot.unwrap(self.data);

        self.data = PackedUserSlot.wrap(balance.toUint() | (data & ~SHARES_MASK));
    }

    function unpackBalance(PackedUserSlot data) private pure returns (Shares) {
        return Shares.wrap(uint112(PackedUserSlot.unwrap(data) & SHARES_MASK));
    }

    function unpackBalanceForwarder(PackedUserSlot data) private pure returns (bool) {
        return (PackedUserSlot.unwrap(data) & BALANCE_FORWARDER_MASK) > 0;
    }
}

using UserStorageLib for UserStorage global;

File 41 of 52 : Shares.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Shares, Assets, TypesLib} from "./Types.sol";
import {VaultCache} from "./VaultCache.sol";
import {ConversionHelpers} from "../lib/ConversionHelpers.sol";

/// @title SharesLib
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Library for `Shares` custom type, which is used to store vault's shares balances
library SharesLib {
    function toUint(Shares self) internal pure returns (uint256) {
        return Shares.unwrap(self);
    }

    function isZero(Shares self) internal pure returns (bool) {
        return Shares.unwrap(self) == 0;
    }

    function toAssetsDown(Shares amount, VaultCache memory vaultCache) internal pure returns (Assets) {
        (uint256 totalAssets, uint256 totalShares) = ConversionHelpers.conversionTotals(vaultCache);
        unchecked {
            return TypesLib.toAssets(amount.toUint() * totalAssets / totalShares);
        }
    }

    function toAssetsUp(Shares amount, VaultCache memory vaultCache) internal pure returns (Assets) {
        (uint256 totalAssets, uint256 totalShares) = ConversionHelpers.conversionTotals(vaultCache);
        unchecked {
            // totalShares >= VIRTUAL_DEPOSIT_AMOUNT > 1
            return TypesLib.toAssets((amount.toUint() * totalAssets + (totalShares - 1)) / totalShares);
        }
    }

    function mulDiv(Shares self, uint256 multiplier, uint256 divisor) internal pure returns (Shares) {
        return TypesLib.toShares(uint256(Shares.unwrap(self)) * multiplier / divisor);
    }

    function subUnchecked(Shares self, Shares b) internal pure returns (Shares) {
        unchecked {
            return Shares.wrap(uint112(self.toUint() - b.toUint()));
        }
    }
}

function addShares(Shares a, Shares b) pure returns (Shares) {
    return TypesLib.toShares(uint256(Shares.unwrap(a)) + uint256(Shares.unwrap(b)));
}

function subShares(Shares a, Shares b) pure returns (Shares) {
    return Shares.wrap((Shares.unwrap(a) - Shares.unwrap(b)));
}

function eqShares(Shares a, Shares b) pure returns (bool) {
    return Shares.unwrap(a) == Shares.unwrap(b);
}

function neqShares(Shares a, Shares b) pure returns (bool) {
    return Shares.unwrap(a) != Shares.unwrap(b);
}

function gtShares(Shares a, Shares b) pure returns (bool) {
    return Shares.unwrap(a) > Shares.unwrap(b);
}

function ltShares(Shares a, Shares b) pure returns (bool) {
    return Shares.unwrap(a) < Shares.unwrap(b);
}

File 42 of 52 : Assets.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Assets, Shares, Owed, TypesLib} from "./Types.sol";
import {VaultCache} from "./VaultCache.sol";
import {ConversionHelpers} from "../lib/ConversionHelpers.sol";
import "../Constants.sol";

/// @title AssetsLib
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Custom type `Assets` represents amounts of the vault's underlying asset
library AssetsLib {
    function toUint(Assets self) internal pure returns (uint256) {
        return Assets.unwrap(self);
    }

    function isZero(Assets self) internal pure returns (bool) {
        return Assets.unwrap(self) == 0;
    }

    function toSharesDown(Assets amount, VaultCache memory vaultCache) internal pure returns (Shares) {
        return TypesLib.toShares(toSharesDownUint(amount, vaultCache));
    }

    function toSharesDownUint(Assets amount, VaultCache memory vaultCache) internal pure returns (uint256) {
        (uint256 totalAssets, uint256 totalShares) = ConversionHelpers.conversionTotals(vaultCache);
        unchecked {
            return amount.toUint() * totalShares / totalAssets;
        }
    }

    function toSharesUp(Assets amount, VaultCache memory vaultCache) internal pure returns (Shares) {
        (uint256 totalAssets, uint256 totalShares) = ConversionHelpers.conversionTotals(vaultCache);
        unchecked {
            // totalAssets >= VIRTUAL_DEPOSIT_AMOUNT > 1
            return TypesLib.toShares((amount.toUint() * totalShares + (totalAssets - 1)) / totalAssets);
        }
    }

    function toOwed(Assets self) internal pure returns (Owed) {
        unchecked {
            return TypesLib.toOwed(self.toUint() << INTERNAL_DEBT_PRECISION_SHIFT);
        }
    }

    function addUnchecked(Assets self, Assets b) internal pure returns (Assets) {
        unchecked {
            return Assets.wrap(uint112(self.toUint() + b.toUint()));
        }
    }

    function subUnchecked(Assets self, Assets b) internal pure returns (Assets) {
        unchecked {
            return Assets.wrap(uint112(self.toUint() - b.toUint()));
        }
    }
}

function addAssets(Assets a, Assets b) pure returns (Assets) {
    return TypesLib.toAssets(a.toUint() + b.toUint());
}

function subAssets(Assets a, Assets b) pure returns (Assets) {
    return Assets.wrap((Assets.unwrap(a) - Assets.unwrap(b)));
}

function eqAssets(Assets a, Assets b) pure returns (bool) {
    return Assets.unwrap(a) == Assets.unwrap(b);
}

function neqAssets(Assets a, Assets b) pure returns (bool) {
    return Assets.unwrap(a) != Assets.unwrap(b);
}

function gtAssets(Assets a, Assets b) pure returns (bool) {
    return Assets.unwrap(a) > Assets.unwrap(b);
}

function gteAssets(Assets a, Assets b) pure returns (bool) {
    return Assets.unwrap(a) >= Assets.unwrap(b);
}

function ltAssets(Assets a, Assets b) pure returns (bool) {
    return Assets.unwrap(a) < Assets.unwrap(b);
}

function lteAssets(Assets a, Assets b) pure returns (bool) {
    return Assets.unwrap(a) <= Assets.unwrap(b);
}

File 43 of 52 : Owed.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Owed, Assets, TypesLib} from "./Types.sol";
import "../Constants.sol";

/// @title OwedLib
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Library for `Owed` custom type
/// @dev The owed type tracks borrowed funds in asset units scaled up by shifting left INTERNAL_DEBT_PRECISION_SHIFT
/// bits. Increased precision allows for accurate interest accounting.
library OwedLib {
    function toUint(Owed self) internal pure returns (uint256) {
        return Owed.unwrap(self);
    }

    function toAssetsUp(Owed amount) internal pure returns (Assets) {
        if (Owed.unwrap(amount) == 0) return Assets.wrap(0);

        return TypesLib.toAssets(toAssetsUpUint(Owed.unwrap(amount)));
    }

    function toAssetsDown(Owed amount) internal pure returns (Assets) {
        if (Owed.unwrap(amount) == 0) return Assets.wrap(0);

        return TypesLib.toAssets(Owed.unwrap(amount) >> INTERNAL_DEBT_PRECISION_SHIFT);
    }

    function isDust(Owed self) internal pure returns (bool) {
        // less than a minimum representable internal debt amount
        return Owed.unwrap(self) < (1 << INTERNAL_DEBT_PRECISION_SHIFT);
    }

    function isZero(Owed self) internal pure returns (bool) {
        return Owed.unwrap(self) == 0;
    }

    function mulDiv(Owed self, uint256 multiplier, uint256 divisor) internal pure returns (Owed) {
        return TypesLib.toOwed(uint256(Owed.unwrap(self)) * multiplier / divisor);
    }

    function addUnchecked(Owed self, Owed b) internal pure returns (Owed) {
        unchecked {
            return Owed.wrap(uint144(self.toUint() + b.toUint()));
        }
    }

    function subUnchecked(Owed self, Owed b) internal pure returns (Owed) {
        unchecked {
            return Owed.wrap(uint144(self.toUint() - b.toUint()));
        }
    }

    function toAssetsUpUint(uint256 owedExact) internal pure returns (uint256) {
        return (owedExact + (1 << INTERNAL_DEBT_PRECISION_SHIFT) - 1) >> INTERNAL_DEBT_PRECISION_SHIFT;
    }
}

function addOwed(Owed a, Owed b) pure returns (Owed) {
    return TypesLib.toOwed(uint256(Owed.unwrap(a)) + uint256(Owed.unwrap(b)));
}

function subOwed(Owed a, Owed b) pure returns (Owed) {
    return Owed.wrap((Owed.unwrap(a) - Owed.unwrap(b)));
}

function eqOwed(Owed a, Owed b) pure returns (bool) {
    return Owed.unwrap(a) == Owed.unwrap(b);
}

function neqOwed(Owed a, Owed b) pure returns (bool) {
    return Owed.unwrap(a) != Owed.unwrap(b);
}

function gtOwed(Owed a, Owed b) pure returns (bool) {
    return Owed.unwrap(a) > Owed.unwrap(b);
}

function ltOwed(Owed a, Owed b) pure returns (bool) {
    return Owed.unwrap(a) < Owed.unwrap(b);
}

File 44 of 52 : ConfigAmount.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {ConfigAmount} from "./Types.sol";
import {Errors} from "../Errors.sol";
import "../Constants.sol";

/// @title ConfigAmountLib
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Library for `ConfigAmount` custom type
/// @dev ConfigAmounts are fixed point values encoded in 16 bits with a 1e4 precision.
/// @dev The type is used to store protocol configuration values.
library ConfigAmountLib {
    function isZero(ConfigAmount self) internal pure returns (bool) {
        return self.toUint16() == 0;
    }

    function toUint16(ConfigAmount self) internal pure returns (uint16) {
        return ConfigAmount.unwrap(self);
    }
}

function gtConfigAmount(ConfigAmount a, ConfigAmount b) pure returns (bool) {
    return a.toUint16() > b.toUint16();
}

function gteConfigAmount(ConfigAmount a, ConfigAmount b) pure returns (bool) {
    return a.toUint16() >= b.toUint16();
}

function ltConfigAmount(ConfigAmount a, ConfigAmount b) pure returns (bool) {
    return a.toUint16() < b.toUint16();
}

function lteConfigAmount(ConfigAmount a, ConfigAmount b) pure returns (bool) {
    return a.toUint16() <= b.toUint16();
}

File 45 of 52 : Flags.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {Flags} from "./Types.sol";

/// @title FlagsLib
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Library for `Flags` custom type
library FlagsLib {
    /// @dev Are *all* of the flags in bitMask set?
    function isSet(Flags self, uint32 bitMask) internal pure returns (bool) {
        return (Flags.unwrap(self) & bitMask) == bitMask;
    }

    /// @dev Are *none* of the flags in bitMask set?
    function isNotSet(Flags self, uint32 bitMask) internal pure returns (bool) {
        return (Flags.unwrap(self) & bitMask) == 0;
    }

    function toUint32(Flags self) internal pure returns (uint32) {
        return Flags.unwrap(self);
    }
}

File 46 of 52 : AmountCap.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {AmountCap} from "./Types.sol";

/// @title AmountCapLib
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Library for `AmountCap` custom type
/// @dev AmountCaps are 16-bit decimal floating point values:
/// * The least significant 6 bits are the exponent
/// * The most significant 10 bits are the mantissa, scaled by 100
/// * The special value of 0 means limit is not set
///   * This is so that uninitialized storage implies no limit
///   * For an actual cap value of 0, use a zero mantissa and non-zero exponent
library AmountCapLib {
    function resolve(AmountCap self) internal pure returns (uint256) {
        uint256 amountCap = AmountCap.unwrap(self);

        if (amountCap == 0) return type(uint256).max;

        unchecked {
            // Cannot overflow because this is less than 2**256:
            //   10**(2**6 - 1) * (2**10 - 1) = 1.023e+66
            return 10 ** (amountCap & 63) * (amountCap >> 6) / 100;
        }
    }

    function toRawUint16(AmountCap self) internal pure returns (uint16) {
        return AmountCap.unwrap(self);
    }
}

File 47 of 52 : IVault.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.8.0;

/// @title IVault
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice This interface defines the methods for the Vault for the purpose of integration with the Ethereum Vault
/// Connector.
interface IVault {
    /// @notice Disables a controller (this vault) for the authenticated account.
    /// @dev A controller is a vault that has been chosen for an account to have special control over account’s
    /// balances in the enabled collaterals vaults. User calls this function in order for the vault to disable itself
    /// for the account if the conditions are met (i.e. user has repaid debt in full). If the conditions are not met,
    /// the function reverts.
    function disableController() external;

    /// @notice Checks the status of an account.
    /// @dev This function must only deliberately revert if the account status is invalid. If this function reverts due
    /// to any other reason, it may render the account unusable with possibly no way to recover funds.
    /// @param account The address of the account to be checked.
    /// @param collaterals The array of enabled collateral addresses to be considered for the account status check.
    /// @return magicValue Must return the bytes4 magic value 0xb168c58f (which is a selector of this function) when
    /// account status is valid, or revert otherwise.
    function checkAccountStatus(
        address account,
        address[] calldata collaterals
    ) external view returns (bytes4 magicValue);

    /// @notice Checks the status of the vault.
    /// @dev This function must only deliberately revert if the vault status is invalid. If this function reverts due to
    /// any other reason, it may render some accounts unusable with possibly no way to recover funds.
    /// @return magicValue Must return the bytes4 magic value 0x4b3d1223 (which is a selector of this function) when
    /// account status is valid, or revert otherwise.
    function checkVaultStatus() external returns (bytes4 magicValue);
}

File 48 of 52 : IPermit2.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.8.0;

/// @title IPermit2
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice A minimal interface of the Uniswap's Permit2 contract
interface IPermit2 {
    /// @notice Transfer tokens between two accounts
    /// @param from The account to send the tokens from
    /// @param to The account to send the tokens to
    /// @param amount Amount of tokens to send
    /// @param token Address of the token contract
    function transferFrom(address from, address to, uint160 amount, address token) external;
}

File 49 of 52 : IIRM.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.8.0;

/// @title IIRM
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Interface of the interest rate model contracts used by EVault
interface IIRM {
    error E_IRMUpdateUnauthorized();

    /// @notice Perform potentially state mutating computation of the new interest rate
    /// @param vault Address of the vault to compute the new interest rate for
    /// @param cash Amount of assets held directly by the vault
    /// @param borrows Amount of assets lent out to borrowers by the vault
    /// @return Then new interest rate in second percent yield (SPY), scaled by 1e27
    function computeInterestRate(address vault, uint256 cash, uint256 borrows) external returns (uint256);

    /// @notice Perform computation of the new interest rate without mutating state
    /// @param vault Address of the vault to compute the new interest rate for
    /// @param cash Amount of assets held directly by the vault
    /// @param borrows Amount of assets lent out to borrowers by the vault
    /// @return Then new interest rate in second percent yield (SPY), scaled by 1e27
    function computeInterestRateView(address vault, uint256 cash, uint256 borrows) external view returns (uint256);
}

File 50 of 52 : LTVConfig.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {ConfigAmount} from "./Types.sol";

/// @title LTVConfig
/// @notice This packed struct is used to store LTV configuration of a collateral
struct LTVConfig {
    // Packed slot: 2 + 2 + 2 + 6 + 4 = 16
    // The value of borrow LTV for originating positions
    ConfigAmount borrowLTV;
    // The value of fully converged liquidation LTV
    ConfigAmount liquidationLTV;
    // The initial value of liquidation LTV, when the ramp began
    ConfigAmount initialLiquidationLTV;
    // The timestamp when the liquidation LTV is considered fully converged
    uint48 targetTimestamp;
    // The time it takes for the liquidation LTV to converge from the initial value to the fully converged value
    uint32 rampDuration;
}

/// @title LTVConfigLib
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Library for getting and setting the LTV configurations
library LTVConfigLib {
    // Is the collateral considered safe to liquidate
    function isRecognizedCollateral(LTVConfig memory self) internal pure returns (bool) {
        return self.targetTimestamp != 0;
    }

    // Get current LTV of the collateral. When liquidation LTV is lowered, it is ramped down to the target value over a
    // period of time.
    function getLTV(LTVConfig memory self, bool liquidation) internal view returns (ConfigAmount) {
        if (!liquidation) {
            return self.borrowLTV;
        }

        if (block.timestamp >= self.targetTimestamp || self.liquidationLTV >= self.initialLiquidationLTV) {
            return self.liquidationLTV;
        }

        uint256 currentLiquidationLTV = self.initialLiquidationLTV.toUint16();

        unchecked {
            uint256 targetLiquidationLTV = self.liquidationLTV.toUint16();
            uint256 timeRemaining = self.targetTimestamp - block.timestamp;

            // targetLiquidationLTV < initialLiquidationLTV and timeRemaining <= rampDuration
            currentLiquidationLTV = targetLiquidationLTV
                + (currentLiquidationLTV - targetLiquidationLTV) * timeRemaining / self.rampDuration;
        }

        // because ramping happens only when liquidation LTV decreases, it's safe to down-cast the new value
        return ConfigAmount.wrap(uint16(currentLiquidationLTV));
    }

    function setLTV(LTVConfig memory self, ConfigAmount borrowLTV, ConfigAmount liquidationLTV, uint32 rampDuration)
        internal
        view
        returns (LTVConfig memory newLTV)
    {
        newLTV.borrowLTV = borrowLTV;
        newLTV.liquidationLTV = liquidationLTV;
        newLTV.initialLiquidationLTV = self.getLTV(true);
        newLTV.targetTimestamp = uint48(block.timestamp + rampDuration);
        newLTV.rampDuration = rampDuration;
    }
}

using LTVConfigLib for LTVConfig global;

File 51 of 52 : VaultCache.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {IERC20} from "../../IEVault.sol";
import {IPriceOracle} from "../../../interfaces/IPriceOracle.sol";

import {Assets, Owed, Shares, Flags} from "./Types.sol";

/// @title VaultCache
/// @notice This struct is used to hold all the most often used vault data in memory
struct VaultCache {
    // Proxy immutables

    // Vault's asset
    IERC20 asset;
    // Vault's pricing oracle
    IPriceOracle oracle;
    // Unit of account is the asset in which collateral and liability values are expressed
    address unitOfAccount;

    // Vault data

    // A timestamp of the last interest accumulator update
    uint48 lastInterestAccumulatorUpdate;
    // The amount of assets held directly by the vault
    Assets cash;
    // Sum of all user debts
    Owed totalBorrows;
    // Sum of all user shares
    Shares totalShares;
    // Interest fees accrued since the last fee conversion
    Shares accumulatedFees;
    // Current interest accumulator
    uint256 interestAccumulator;

    // Vault config

    // Current supply cap in asset units
    uint256 supplyCap;
    // Current borrow cap in asset units
    uint256 borrowCap;
    // A bitfield of operations which trigger a hook call
    Flags hookedOps;
    // A bitfield of vault configuration options
    Flags configFlags;

    // Runtime

    // A flag indicating if the vault snapshot has already been initialized for the currently executing batch
    bool snapshotInitialized;
}

File 52 of 52 : ConversionHelpers.sol
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {VaultCache} from "../types/VaultCache.sol";

/// @title ConversionHelpers Library
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice The library provides a helper function for conversions between shares and assets
library ConversionHelpers {
    // virtual deposit used in conversions between shares and assets, serving as exchange rate manipulation mitigation
    uint256 internal constant VIRTUAL_DEPOSIT_AMOUNT = 1e6;

    function conversionTotals(VaultCache memory vaultCache)
        internal
        pure
        returns (uint256 totalAssets, uint256 totalShares)
    {
        unchecked {
            totalAssets =
                vaultCache.cash.toUint() + vaultCache.totalBorrows.toAssetsUp().toUint() + VIRTUAL_DEPOSIT_AMOUNT;
            totalShares = vaultCache.totalShares.toUint() + VIRTUAL_DEPOSIT_AMOUNT;
        }
    }
}

Settings
{
  "remappings": [
    "lib/euler-price-oracle:@openzeppelin/contracts/=lib/euler-price-oracle/lib/openzeppelin-contracts/contracts/",
    "lib/native-token-transfers/evm:openzeppelin-contracts/contracts/=lib/native-token-transfers/evm/lib/openzeppelin-contracts/contracts/",
    "lib/euler-earn:@openzeppelin/=lib/euler-earn/lib/openzeppelin-contracts/",
    "lib/euler-earn:@openzeppelin-upgradeable/=lib/euler-earn/lib/openzeppelin-contracts-upgradeable/contracts/",
    "lib/euler-earn:ethereum-vault-connector/=lib/euler-earn/lib/ethereum-vault-connector/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "ethereum-vault-connector/=lib/ethereum-vault-connector/src/",
    "evc/=lib/ethereum-vault-connector/src/",
    "evk/=lib/euler-vault-kit/src/",
    "evk-test/=lib/euler-vault-kit/test/",
    "euler-price-oracle/=lib/euler-price-oracle/src/",
    "euler-price-oracle-test/=lib/euler-price-oracle/test/",
    "fee-flow/=lib/fee-flow/src/",
    "reward-streams/=lib/reward-streams/src/",
    "@openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "euler-earn/=lib/euler-earn/src/",
    "native-token-transfers/=lib/native-token-transfers/evm/src/",
    "@openzeppelin-upgradeable/=lib/euler-earn/lib/openzeppelin-contracts-upgradeable/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@pendle/core-v2/=lib/euler-price-oracle/lib/pendle-core-v2-public/contracts/",
    "@pyth/=lib/euler-price-oracle/lib/pyth-sdk-solidity/",
    "@redstone/evm-connector/=lib/euler-price-oracle/lib/redstone-oracles-monorepo/packages/evm-connector/contracts/",
    "@solady/=lib/euler-price-oracle/lib/solady/src/",
    "@uniswap/v3-core/=lib/euler-price-oracle/lib/v3-core/",
    "@uniswap/v3-periphery/=lib/euler-price-oracle/lib/v3-periphery/",
    "ERC4626/=lib/euler-earn/lib/properties/lib/ERC4626/contracts/",
    "crytic-properties/=lib/euler-earn/lib/properties/contracts/",
    "ds-test/=lib/ethereum-vault-connector/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "euler-vault-kit/=lib/euler-vault-kit/",
    "forge-gas-snapshot/=lib/euler-vault-kit/lib/permit2/lib/forge-gas-snapshot/src/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
    "layerzero-devtools/=lib/layerzero-devtools/packages/toolbox-foundry/src/",
    "layerzero-v2/=lib/layerzero-v2/",
    "openzeppelin/=lib/ethereum-vault-connector/lib/openzeppelin-contracts/contracts/",
    "pendle-core-v2-public/=lib/euler-price-oracle/lib/pendle-core-v2-public/contracts/",
    "permit2/=lib/euler-vault-kit/lib/permit2/",
    "properties/=lib/euler-earn/lib/properties/contracts/",
    "pyth-sdk-solidity/=lib/euler-price-oracle/lib/pyth-sdk-solidity/",
    "redstone-oracles-monorepo/=lib/euler-price-oracle/lib/",
    "solady/=lib/euler-price-oracle/lib/solady/src/",
    "solidity-bytes-utils/=lib/native-token-transfers/evm/lib/solidity-bytes-utils/contracts/",
    "solmate/=lib/fee-flow/lib/solmate/src/",
    "v3-core/=lib/euler-price-oracle/lib/v3-core/contracts/",
    "v3-periphery/=lib/euler-price-oracle/lib/v3-periphery/contracts/",
    "wormhole-solidity-sdk/=lib/native-token-transfers/evm/lib/wormhole-solidity-sdk/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 20000
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false,
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"components":[{"internalType":"address","name":"evc","type":"address"},{"internalType":"address","name":"protocolConfig","type":"address"},{"internalType":"address","name":"sequenceRegistry","type":"address"},{"internalType":"address","name":"balanceTracker","type":"address"},{"internalType":"address","name":"permit2","type":"address"}],"internalType":"struct Base.Integrations","name":"integrations","type":"tuple"},{"components":[{"internalType":"address","name":"initialize","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"borrowing","type":"address"},{"internalType":"address","name":"liquidation","type":"address"},{"internalType":"address","name":"riskManager","type":"address"},{"internalType":"address","name":"balanceForwarder","type":"address"},{"internalType":"address","name":"governance","type":"address"}],"internalType":"struct Dispatch.DeployedModules","name":"modules","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"E_AccountLiquidity","type":"error"},{"inputs":[],"name":"E_AmountTooLargeToEncode","type":"error"},{"inputs":[],"name":"E_BadAddress","type":"error"},{"inputs":[],"name":"E_BadAssetReceiver","type":"error"},{"inputs":[],"name":"E_BadBorrowCap","type":"error"},{"inputs":[],"name":"E_BadCollateral","type":"error"},{"inputs":[],"name":"E_BadFee","type":"error"},{"inputs":[],"name":"E_BadMaxLiquidationDiscount","type":"error"},{"inputs":[],"name":"E_BadSharesOwner","type":"error"},{"inputs":[],"name":"E_BadSharesReceiver","type":"error"},{"inputs":[],"name":"E_BadSupplyCap","type":"error"},{"inputs":[],"name":"E_BorrowCapExceeded","type":"error"},{"inputs":[],"name":"E_CheckUnauthorized","type":"error"},{"inputs":[],"name":"E_CollateralDisabled","type":"error"},{"inputs":[],"name":"E_ConfigAmountTooLargeToEncode","type":"error"},{"inputs":[],"name":"E_ControllerDisabled","type":"error"},{"inputs":[],"name":"E_DebtAmountTooLargeToEncode","type":"error"},{"inputs":[],"name":"E_EmptyError","type":"error"},{"inputs":[],"name":"E_ExcessiveRepayAmount","type":"error"},{"inputs":[],"name":"E_FlashLoanNotRepaid","type":"error"},{"inputs":[],"name":"E_Initialized","type":"error"},{"inputs":[],"name":"E_InsufficientAllowance","type":"error"},{"inputs":[],"name":"E_InsufficientAssets","type":"error"},{"inputs":[],"name":"E_InsufficientBalance","type":"error"},{"inputs":[],"name":"E_InsufficientCash","type":"error"},{"inputs":[],"name":"E_InsufficientDebt","type":"error"},{"inputs":[],"name":"E_InvalidLTVAsset","type":"error"},{"inputs":[],"name":"E_LTVBorrow","type":"error"},{"inputs":[],"name":"E_LTVLiquidation","type":"error"},{"inputs":[],"name":"E_LiquidationCoolOff","type":"error"},{"inputs":[],"name":"E_MinYield","type":"error"},{"inputs":[],"name":"E_NoLiability","type":"error"},{"inputs":[],"name":"E_NoPriceOracle","type":"error"},{"inputs":[],"name":"E_NotController","type":"error"},{"inputs":[],"name":"E_NotHookTarget","type":"error"},{"inputs":[],"name":"E_NotSupported","type":"error"},{"inputs":[],"name":"E_OperationDisabled","type":"error"},{"inputs":[],"name":"E_OutstandingDebt","type":"error"},{"inputs":[],"name":"E_ProxyMetadata","type":"error"},{"inputs":[],"name":"E_Reentrancy","type":"error"},{"inputs":[],"name":"E_RepayTooMuch","type":"error"},{"inputs":[],"name":"E_SelfLiquidation","type":"error"},{"inputs":[],"name":"E_SelfTransfer","type":"error"},{"inputs":[],"name":"E_SupplyCapExceeded","type":"error"},{"inputs":[],"name":"E_TransientState","type":"error"},{"inputs":[],"name":"E_Unauthorized","type":"error"},{"inputs":[],"name":"E_ViolatorLiquidityDeferred","type":"error"},{"inputs":[],"name":"E_ZeroAssets","type":"error"},{"inputs":[],"name":"E_ZeroShares","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"BalanceForwarderStatus","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"Borrow","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"protocolReceiver","type":"address"},{"indexed":true,"internalType":"address","name":"governorReceiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"protocolShares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"governorShares","type":"uint256"}],"name":"ConvertFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"DebtSocialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","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":"creator","type":"address"},{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"address","name":"dToken","type":"address"}],"name":"EVaultCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"newSupplyCap","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"newBorrowCap","type":"uint16"}],"name":"GovSetCaps","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"newConfigFlags","type":"uint32"}],"name":"GovSetConfigFlags","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newFeeReceiver","type":"address"}],"name":"GovSetFeeReceiver","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newGovernorAdmin","type":"address"}],"name":"GovSetGovernorAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newHookTarget","type":"address"},{"indexed":false,"internalType":"uint32","name":"newHookedOps","type":"uint32"}],"name":"GovSetHookConfig","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"newFee","type":"uint16"}],"name":"GovSetInterestFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newInterestRateModel","type":"address"}],"name":"GovSetInterestRateModel","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"collateral","type":"address"},{"indexed":false,"internalType":"uint16","name":"borrowLTV","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"liquidationLTV","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"initialLiquidationLTV","type":"uint16"},{"indexed":false,"internalType":"uint48","name":"targetTimestamp","type":"uint48"},{"indexed":false,"internalType":"uint32","name":"rampDuration","type":"uint32"}],"name":"GovSetLTV","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"newCoolOffTime","type":"uint16"}],"name":"GovSetLiquidationCoolOffTime","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"newDiscount","type":"uint16"}],"name":"GovSetMaxLiquidationDiscount","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"InterestAccrued","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"liquidator","type":"address"},{"indexed":true,"internalType":"address","name":"violator","type":"address"},{"indexed":false,"internalType":"address","name":"collateral","type":"address"},{"indexed":false,"internalType":"uint256","name":"repayAssets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"yieldBalance","type":"uint256"}],"name":"Liquidate","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":"assets","type":"uint256"}],"name":"PullDebt","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"Repay","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":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"totalShares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalBorrows","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"accumulatedFees","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"cash","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"interestAccumulator","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"interestRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"VaultStatus","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","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"},{"inputs":[],"name":"EVC","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"LTVBorrow","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"LTVFull","outputs":[{"internalType":"uint16","name":"borrowLTV","type":"uint16"},{"internalType":"uint16","name":"liquidationLTV","type":"uint16"},{"internalType":"uint16","name":"initialLiquidationLTV","type":"uint16"},{"internalType":"uint48","name":"targetTimestamp","type":"uint48"},{"internalType":"uint32","name":"rampDuration","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"LTVLiquidation","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LTVList","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MODULE_BALANCE_FORWARDER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MODULE_BORROWING","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MODULE_GOVERNANCE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MODULE_INITIALIZE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MODULE_LIQUIDATION","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MODULE_RISKMANAGER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MODULE_TOKEN","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MODULE_VAULT","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bool","name":"liquidation","type":"bool"}],"name":"accountLiquidity","outputs":[{"internalType":"uint256","name":"collateralValue","type":"uint256"},{"internalType":"uint256","name":"liabilityValue","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bool","name":"liquidation","type":"bool"}],"name":"accountLiquidityFull","outputs":[{"internalType":"address[]","name":"collaterals","type":"address[]"},{"internalType":"uint256[]","name":"collateralValues","type":"uint256[]"},{"internalType":"uint256","name":"liabilityValue","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accumulatedFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accumulatedFeesAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"},{"internalType":"address","name":"spender","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":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceForwarderEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balanceTrackerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"borrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"caps","outputs":[{"internalType":"uint16","name":"supplyCap","type":"uint16"},{"internalType":"uint16","name":"borrowCap","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cash","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address[]","name":"collaterals","type":"address[]"}],"name":"checkAccountStatus","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"liquidator","type":"address"},{"internalType":"address","name":"violator","type":"address"},{"internalType":"address","name":"collateral","type":"address"}],"name":"checkLiquidation","outputs":[{"internalType":"uint256","name":"maxRepay","type":"uint256"},{"internalType":"uint256","name":"maxYield","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"checkVaultStatus","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"configFlags","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"convertFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"creator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"debtOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"debtOfExact","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"disableBalanceForwarder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"disableController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"enableBalanceForwarder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"flashLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"governorAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hookConfig","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"proxyCreator","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"interestAccumulator","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"interestFee","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"interestRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"interestRateModel","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"violator","type":"address"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"repayAssets","type":"uint256"},{"internalType":"uint256","name":"minYieldBalance","type":"uint256"}],"name":"liquidate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"liquidationCoolOffTime","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxLiquidationDiscount","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","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":"amount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracle","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"permit2Address","outputs":[{"internalType":"address","name":"","type":"address"}],"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":"","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":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolConfigAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFeeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFeeShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"from","type":"address"}],"name":"pullDebt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"repay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"repayWithShares","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"debt","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"supplyCap","type":"uint16"},{"internalType":"uint16","name":"borrowCap","type":"uint16"}],"name":"setCaps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"newConfigFlags","type":"uint32"}],"name":"setConfigFlags","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newFeeReceiver","type":"address"}],"name":"setFeeReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newGovernorAdmin","type":"address"}],"name":"setGovernorAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newHookTarget","type":"address"},{"internalType":"uint32","name":"newHookedOps","type":"uint32"}],"name":"setHookConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"newFee","type":"uint16"}],"name":"setInterestFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newModel","type":"address"}],"name":"setInterestRateModel","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint16","name":"borrowLTV","type":"uint16"},{"internalType":"uint16","name":"liquidationLTV","type":"uint16"},{"internalType":"uint32","name":"rampDuration","type":"uint32"}],"name":"setLTV","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"newCoolOffTime","type":"uint16"}],"name":"setLiquidationCoolOffTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"newDiscount","type":"uint16"}],"name":"setMaxLiquidationDiscount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"skim","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":"totalBorrows","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBorrowsExact","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"touch","outputs":[],"stateMutability":"nonpayable","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":"from","type":"address"},{"internalType":"address","name":"to","type":"address"}],"name":"transferFromMax","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unitOfAccount","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"viewDelegate","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]

61022060405234801562000011575f80fd5b506040516200601338038062006013833981016040819052620000349162000250565b815182908290829062000047816200019f565b6001600160a01b031660805250602081015162000064906200019f565b6001600160a01b031660a052604081015162000080906200019f565b6001600160a01b0390811660c0526060820151811660e05260809091015116610100525f805460ff191660011790558051620000bc906200019f565b6001600160a01b0316610120526020810151620000d9906200019f565b6001600160a01b0316610140526040810151620000f6906200019f565b6001600160a01b031661016052606081015162000113906200019f565b6001600160a01b031661018052608081015162000130906200019f565b6001600160a01b03166101a05260a08101516200014d906200019f565b6001600160a01b03166101c05260c08101516200016a906200019f565b6001600160a01b03166101e05260e081015162000187906200019f565b6001600160a01b031661020052506200039b92505050565b5f816001600160a01b03163b5f03620001cb576040516306e1f36760e31b815260040160405180910390fd5b5090565b60405160a081016001600160401b0381118282101715620001fe57634e487b7160e01b5f52604160045260245ffd5b60405290565b60405161010081016001600160401b0381118282101715620001fe57634e487b7160e01b5f52604160045260245ffd5b80516001600160a01b03811681146200024b575f80fd5b919050565b5f808284036101a081121562000264575f80fd5b60a081121562000272575f80fd5b6200027c620001cf565b620002878562000234565b8152620002976020860162000234565b6020820152620002aa6040860162000234565b6040820152620002bd6060860162000234565b6060820152620002d06080860162000234565b60808201529250610100609f198201811315620002eb575f80fd5b620002f562000204565b91506200030560a0860162000234565b82526200031560c0860162000234565b60208301526200032860e0860162000234565b60408301526200033a81860162000234565b6060830152506200034f610120850162000234565b608082015262000363610140850162000234565b60a082015262000377610160850162000234565b60c08201526200038b610180850162000234565b60e0820152809150509250929050565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c0516101e05161020051615a6b620005a85f395f8181610d300152818161104e01528181611159015281816111c00152818161120a015281816112e7015281816113510152818161137d01528181611689015261185c01525f8181610b2c0152818161123e0152818161189c01526118c701525f8181610acb01528181611422015281816114ea01526117e201525f81816108f60152818161144e015261177201525f818161071a01528181610fb4015281816112af01528181611318015281816114be015281816115aa015281816115ea015261165101525f8181610efc01528181610f4901528181610ff1015281816113e5015261170501525f8181610a0601528181610f79015261102201525f8181610c6701526117aa01525f50505f81816144ce015261465901525f50505f50505f81816111160152818161119801528181611287015281816113bd01528181611496015281816115320152818161158201528181611629015281816116dd0152818161174a0152818161182a01528181611c6001528181611e2c01528181611e56015281816120f9015281816125380152818161256201528181612cd701528181612d2e01528181613f3b01528181613f6c0152818161410c015281816141c6015281816148b001526150ba0152615a6b5ff3fe608060405260043610610603575f3560e01c806394bf804d11610311578063bf58094d1161019c578063d87f780f116100e7578063e388be7b11610092578063efdcd9741161006d578063efdcd97414610aed578063f3fdb15a146108a3578063f6e50f5814610f32575f80fd5b8063e388be7b146106a7578063ece6a7fa14610f1e578063ef8b30f7146106ea575f80fd5b8063dd62ed3e116100c2578063dd62ed3e14610ead578063e15c82ec14610ecc578063e2f206e514610eeb575f80fd5b8063d87f780f14610e7f578063d905777e146108b7578063d9d7858a14610e99575f80fd5b8063c7b0e3a311610147578063cf349b7d11610122578063cf349b7d14610dfc578063d1a3a30814610e41578063d283e75f14610e60575f80fd5b8063c7b0e3a314610daf578063cbfdd7e114610ddd578063ce96cb77146108b7575f80fd5b8063c522498311610177578063c5224983146108a3578063c63d75b6146108b7578063c6e6f59214610d90575f80fd5b8063bf58094d14610cc2578063c134257414610d52578063c4d66de814610d71575f80fd5b8063ad80ad0b1161025c578063b3d7f6b911610207578063b460af94116101e2578063b460af9414610d00578063b4cd541b14610d1f578063ba08765214610d00575f80fd5b8063b3d7f6b9146106ea578063b3f00674146108a3578063b4113ba714610a28575f80fd5b8063af06d3cf11610237578063af06d3cf14610a28578063af5aaeeb14610cc2578063b168c58f14610ce1575f80fd5b8063ad80ad0b14610c56578063ada3d56f14610c89578063aebde56b14610ca3575f80fd5b8063a75df498116102bc578063a9c8eb7e11610297578063a9c8eb7e14610c18578063ab49b7f114610c37578063acb7081514610984575f80fd5b8063a75df49814610baa578063a824bf6714610bda578063a9059cbb14610bf9575f80fd5b8063961be391116102ec578063961be391146106a7578063a55526db14610b96578063a70354a1146108a3575f80fd5b806394bf804d14610a6857806395d89b4114610667578063960b26a214610b82575f80fd5b80634b3d1223116104915780636ce98c29116103dc57806382ebd6741161038757806388aa6f121161036257806388aa6f1214610b4e5780638bcd401614610aed5780638d56c63914610a68575f80fd5b806382ebd67414610aed578063869e50c714610b07578063883e387514610b1b575f80fd5b80637c3a00fd116103b75780637c3a00fd14610aa65780637d5f2e4e14610aba5780637dc0d1d0146108a3575f80fd5b80636ce98c29146108a35780636e553f6514610a6857806370a0823114610a87575f80fd5b8063539bd5bf1161043c57806360cb90ef1161041757806360cb90ef14610a2857806364b1cdd6146108d15780636a16ef8414610a47575f80fd5b8063539bd5bf146108a3578063587f5ed7146109e15780635fa23055146109f5575f80fd5b80634cdad5061161046c5780634cdad506146106ea5780634f7e43df146109185780635296a431146109c2575f80fd5b80634b3d12231461093f5780634b3fd148146109845780634bca3d5b146109a3575f80fd5b80632b38a367116105515780633e833364116104fc57806342895567116104d757806342895567146108e557806347bd3718146106a75780634abdb95914610918575f80fd5b80633e833364146108a3578063402d267d146108b757806341233a98146108d1575f80fd5b806333708d0c1161052c57806333708d0c1461080b57806338d52e0f1461086b57806339a51be5146108a3575f80fd5b80632b38a367146107a85780632b5335c3146107d1578063313ce567146107e5575f80fd5b80630a28a477116105b157806318e22d981161058c57806318e22d98146107505780631fe8b9531461077f57806323b872dd14610789575f80fd5b80630a28a477146106ea57806314c054bc1461070957806318160ddd1461073c575f80fd5b806307a2d13a116105e157806307a2d13a14610688578063087a6007146106a7578063095ea7b3146106bb575f80fd5b806301e1d1141461060757806302d05d3f1461062e57806306fdde0314610667575b5f80fd5b348015610612575f80fd5b5061061b610f46565b6040519081526020015b60405180910390f35b348015610639575f80fd5b50610642610f46565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610625565b348015610672575f80fd5b5061067b610f75565b6040516106259190615323565b348015610693575f80fd5b5061061b6106a2366004615373565b610fa1565b3480156106b2575f80fd5b5061061b610fb1565b3480156106c6575f80fd5b506106da6106d53660046153ab565b610fdc565b6040519015158152602001610625565b3480156106f5575f80fd5b5061061b610704366004615373565b610fee565b348015610714575f80fd5b506106427f000000000000000000000000000000000000000000000000000000000000000081565b348015610747575f80fd5b5061061b61101f565b34801561075b575f80fd5b5061076461104a565b6040805161ffff938416815292909116602083015201610625565b61078761107b565b005b348015610794575f80fd5b506106da6107a33660046153d5565b6110fe565b3480156107b3575f80fd5b506107bc611156565b60405163ffffffff9091168152602001610625565b3480156107dc575f80fd5b50610787611181565b3480156107f0575f80fd5b506107f96111f5565b60405160ff9091168152602001610625565b348015610816575f80fd5b5061082a610825366004615413565b611203565b6040805161ffff96871681529486166020860152929094169183019190915265ffffffffffff16606082015263ffffffff909116608082015260a001610625565b348015610876575f80fd5b50367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc4013560601c610642565b3480156108ae575f80fd5b50610642611156565b3480156108c2575f80fd5b5061061b610704366004615413565b3480156108dc575f80fd5b5061078761123c565b3480156108f0575f80fd5b506106427f000000000000000000000000000000000000000000000000000000000000000081565b348015610923575f80fd5b5061092c611156565b60405161ffff9091168152602001610625565b34801561094a575f80fd5b50610953611266565b6040517fffffffff000000000000000000000000000000000000000000000000000000009091168152602001610625565b34801561098f575f80fd5b5061061b61099e36600461542e565b61126f565b3480156109ae575f80fd5b506107876109bd366004615480565b6112e5565b3480156109cd575f80fd5b506107876109dc3660046154d3565b611316565b3480156109ec575f80fd5b5061061b611346565b348015610a00575f80fd5b506106427f000000000000000000000000000000000000000000000000000000000000000081565b348015610a33575f80fd5b50610787610a42366004615548565b61134f565b348015610a52575f80fd5b50610a5b611379565b60405161062591906155b1565b348015610a73575f80fd5b5061061b610a8236600461542e565b6113a5565b348015610a92575f80fd5b5061061b610aa1366004615413565b61140d565b348015610ab1575f80fd5b5061061b611417565b348015610ac5575f80fd5b506106427f000000000000000000000000000000000000000000000000000000000000000081565b348015610af8575f80fd5b50610787610a42366004615413565b348015610b12575f80fd5b50610787611420565b348015610b26575f80fd5b506106427f000000000000000000000000000000000000000000000000000000000000000081565b348015610b59575f80fd5b50610b6d610b683660046155c3565b61144a565b60408051928352602083019190915201610625565b348015610b8d575f80fd5b5061061b611156565b348015610ba1575f80fd5b5061078761147f565b348015610bb5575f80fd5b5060065474010000000000000000000000000000000000000000900461ffff1661092c565b348015610be5575f80fd5b50610b6d610bf4366004615618565b6114e6565b348015610c04575f80fd5b506106da610c133660046153ab565b61151a565b348015610c23575f80fd5b50610b6d610c3236600461542e565b611569565b348015610c42575f80fd5b5061061b610c51366004615413565b6115e7565b348015610c61575f80fd5b506106427f000000000000000000000000000000000000000000000000000000000000000081565b348015610c94575f80fd5b50610787610a42366004615644565b348015610cae575f80fd5b50610787610cbd36600461542e565b611612565b348015610ccd575f80fd5b5061092c610cdc366004615413565b611686565b348015610cec575f80fd5b50610953610cfb36600461565d565b6116b1565b348015610d0b575f80fd5b5061061b610d1a3660046156cb565b6116c5565b348015610d2a575f80fd5b506106427f000000000000000000000000000000000000000000000000000000000000000081565b348015610d5d575f80fd5b50610787610d6c3660046156ef565b611733565b348015610d7c575f80fd5b50610787610d8b366004615413565b6117a8565b348015610d9b575f80fd5b5061061b610daa366004615373565b6117d2565b348015610dba575f80fd5b50610dce610dc9366004615618565b6117dc565b60405161062593929190615732565b348015610de8575f80fd5b506106da610df7366004615790565b611812565b348015610e07575f80fd5b50610e1061104a565b6040805173ffffffffffffffffffffffffffffffffffffffff909316835263ffffffff909116602083015201610625565b348015610e4c575f80fd5b50610787610e5b3660046157bc565b61185a565b348015610e6b575f80fd5b5061061b610e7a366004615413565b611884565b348015610e8a575f80fd5b50610787610e5b3660046157ef565b348015610ea4575f80fd5b50610642610fb1565b348015610eb8575f80fd5b5061061b610ec7366004615790565b61188e565b348015610ed7575f80fd5b506106da610ee6366004615413565b611899565b348015610ef6575f80fd5b506106427f000000000000000000000000000000000000000000000000000000000000000081565b348015610f29575f80fd5b506106426118c4565b348015610f3d575f80fd5b5061061b6118ef565b5f7f0000000000000000000000000000000000000000000000000000000000000000610f71816118f8565b5090565b60607f0000000000000000000000000000000000000000000000000000000000000000610f71816118f8565b5f610fab82611949565b92915050565b5f7f0000000000000000000000000000000000000000000000000000000000000000610f71816118f8565b5f610fe78383611a6c565b9392505050565b5f7f0000000000000000000000000000000000000000000000000000000000000000611019816118f8565b50919050565b5f7f0000000000000000000000000000000000000000000000000000000000000000610f71816118f8565b5f807f0000000000000000000000000000000000000000000000000000000000000000611076816118f8565b509091565b3330146110b4576040517f08e2ce1700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc36018060245f375f80825f6004355af490503d5f803e8080156110f6573d5ff35b3d5ffd5b5050565b5f73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016330361114e57611147848484611b5a565b9050610fe7565b610fe7611c5d565b5f7f0000000000000000000000000000000000000000000000000000000000000000610f71816118f8565b73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001633036111eb577f00000000000000000000000000000000000000000000000000000000000000006111e881611cef565b50565b6111f3611c5d565b565b5f6111fe611d09565b905090565b5f805f805f7f0000000000000000000000000000000000000000000000000000000000000000611232816118f8565b5091939590929450565b7f00000000000000000000000000000000000000000000000000000000000000006111e881611cef565b5f6111fe611e13565b5f73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001633036112dd577f00000000000000000000000000000000000000000000000000000000000000006112d781611cef565b50610fab565b610fab611c5d565b7f000000000000000000000000000000000000000000000000000000000000000061130f81611cef565b5050505050565b7f000000000000000000000000000000000000000000000000000000000000000061134081611cef565b50505050565b5f6111fe612145565b7f00000000000000000000000000000000000000000000000000000000000000006110fa81611cef565b60607f0000000000000000000000000000000000000000000000000000000000000000610f71816118f8565b5f73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001633036112dd577f00000000000000000000000000000000000000000000000000000000000000006112d781611cef565b5f610fab8261223d565b5f6111fe612344565b7f00000000000000000000000000000000000000000000000000000000000000006111e881611cef565b5f807f0000000000000000000000000000000000000000000000000000000000000000611476816118f8565b50935093915050565b73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001633036111eb577f00000000000000000000000000000000000000000000000000000000000000006111e881611cef565b5f807f0000000000000000000000000000000000000000000000000000000000000000611512816118f8565b509250929050565b5f73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001633036112dd57611562838361242a565b9050610fab565b5f8073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001633036115d8577f00000000000000000000000000000000000000000000000000000000000000006115d281611cef565b506115e0565b6115e0611c5d565b9250929050565b5f7f0000000000000000000000000000000000000000000000000000000000000000611019816118f8565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016330361167e577f000000000000000000000000000000000000000000000000000000000000000061167981611cef565b505050565b6110fa611c5d565b5f7f0000000000000000000000000000000000000000000000000000000000000000611019816118f8565b5f6116bd84848461251f565b949350505050565b5f73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016330361114e577f000000000000000000000000000000000000000000000000000000000000000061172d81611cef565b50610fe7565b73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001633036117a0577f000000000000000000000000000000000000000000000000000000000000000061179a81611cef565b50611340565b611340611c5d565b7f00000000000000000000000000000000000000000000000000000000000000006110fa81611cef565b5f610fab82612693565b6060805f7f000000000000000000000000000000000000000000000000000000000000000061180a816118f8565b509250925092565b5f73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001633036112dd57611562838361279a565b7f000000000000000000000000000000000000000000000000000000000000000061167981611cef565b5f610fab82612890565b5f610fe78383612996565b5f7f0000000000000000000000000000000000000000000000000000000000000000611019816118f8565b5f7f0000000000000000000000000000000000000000000000000000000000000000610f71816118f8565b5f6111fe612aa8565b7f1fe8b953000000000000000000000000000000000000000000000000000000005f526040360333816018015281600452805f6024375f80603883015f305afa90503d5f803e8080156110f6573d5ff35b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615611a1f57600c5473ffffffffffffffffffffffffffffffffffffffff163381148015906119e6575033301480156119e457507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15611a1d576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b5f611a28612bb9565b9050611a63611a5082611a3a86612c32565b6dffffffffffffffffffffffffffff1690612c7b565b6dffffffffffffffffffffffffffff1690565b9150505b919050565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615611acb576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c01000000000000000000000000000000000000000000000000000000001790555f611b1b612cbf565b9050611b28818585612db7565b5050600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff169055506001919050565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615611bb9576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c0100000000000000000000000000000000000000000000000000000000179055611c0984612e61565b5f611c15601086612ed1565b915050611c2c818686611c2787612c32565b613118565b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff16905595945050505050565b5f7f00000000000000000000000000000000000000000000000000000000000000009050604036037f1f8b5215000000000000000000000000000000000000000000000000000000005f52306004523360245234604452608060645280608452805f60a4375f8160a401525f80601f19601f84011660a4015f34865af190503d5f803e8080156110f65760403d036040f35b365f80375f80365f845af43d5f803e8080156110f6573d5ff35b60408051600481526024810182526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f313ce5670000000000000000000000000000000000000000000000000000000017905290515f91367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc4013560601c91839182918491611d9a91615817565b5f60405180830381855afa9150503d805f8114611dd2576040519150601f19603f3d011682016040523d82523d5f602084013e611dd7565b606091505b5091509150818015611deb57506020815110155b611df6576012611e0a565b80806020019051810190611e0a9190615832565b93505050505b90565b5f3373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016141580611ee357507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663e21e537c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ebd573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ee19190615852565b155b15611f1a576040517ff0991feb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611f2361319f565b90505f611f2f826132dd565b9050611f3b8282613522565b816101a00151156120eb575f6101a08301819052600280547fffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1690556001546dffffffffffffffffffffffffffff808216926e01000000000000000000000000000090920416908190505f611fca611a508760a0015171ffffffffffffffffffffffffffffffffffff166135e9565b905085610140015181118015611fdf57508181115b15612016576040517f6ef90ef100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f612031836dffffffffffffffffffffffffffff871661589a565b90505f612058611a508960a0015171ffffffffffffffffffffffffffffffffffff16613631565b60808901516dffffffffffffffffffffffffffff16612077919061589a565b90508761012001518111801561208c57508181115b156120c3576040517f426073f200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7c01000000000000000000000000000000000000000000000000000000006001555050505050505b61211d8261016001516140007f0000000000000000000000000000000000000000000000000000000000000000613672565b507f4b3d12230000000000000000000000000000000000000000000000000000000092915050565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff161561221b57600c5473ffffffffffffffffffffffffffffffffffffffff163381148015906121e2575033301480156121e057507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612219576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b6111fe612226612bb9565b60e001516dffffffffffffffffffffffffffff1690565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff161561231357600c5473ffffffffffffffffffffffffffffffffffffffff163381148015906122da575033301480156122d857507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612311576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b73ffffffffffffffffffffffffffffffffffffffff82165f908152600d60205260409020610fab90611a5090613699565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff161561241a57600c5473ffffffffffffffffffffffffffffffffffffffff163381148015906123e1575033301480156123df57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612418576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b6111fe612425612bb9565b6136b2565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615612489576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c01000000000000000000000000000000000000000000000000000000001790555f6124dd60106001612ed1565b9150506124ef818286611c2787612c32565b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff169055949350505050565b5f3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000161415806125ef57507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663e21e537c6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156125c9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125ed9190615852565b155b15612626576040517ff0991feb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61266a612631612bb9565b858585808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152506138b692505050565b507fb168c58f000000000000000000000000000000000000000000000000000000009392505050565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff161561276957600c5473ffffffffffffffffffffffffffffffffffffffff163381148015906127305750333014801561272e57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612767576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b5f612772612bb9565b9050611a63611a508261278486612c32565b6dffffffffffffffffffffffffffff169061399e565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff16156127f9576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000017905561284983612e61565b5f612855601085612ed1565b73ffffffffffffffffffffffffffffffffffffffff86165f908152600d602052604090209092506124ef9150829086908690611c2790613699565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff161561296657600c5473ffffffffffffffffffffffffffffffffffffffff1633811480159061292d5750333014801561292b57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612964576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b610fab611a5061297d612977612bb9565b856139ac565b71ffffffffffffffffffffffffffffffffffff166135e9565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615612a6c57600c5473ffffffffffffffffffffffffffffffffffffffff16338114801590612a3357503330148015612a3157507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612a6a576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b5073ffffffffffffffffffffffffffffffffffffffff9182165f908152600d602090815260408083209390941682526002909201909152205490565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615612b7e57600c5473ffffffffffffffffffffffffffffffffffffffff16338114801590612b4557503330148015612b4357507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612b7c576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b5f612b87612bb9565b9050612bb3611a50828360e001516dffffffffffffffffffffffffffff16612c7b90919063ffffffff16565b91505090565b604080516101c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a0810191909152610f71816139f5565b5f6dffffffffffffffffffffffffffff821115610f71576040517f64e0647900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f805f612c8784613ea8565b9092509050612cb681836dffffffffffffffffffffffffffff88160281612cb057612cb06158ad565b04612c32565b95945050505050565b5f73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000163303612db2576040517f18503a1e0000000000000000000000000000000000000000000000000000000081525f60048201819052907f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16906318503a1e906024016040805180830381865afa158015612d87573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612dab91906158da565b5092915050565b503390565b8273ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603612def57505050565b73ffffffffffffffffffffffffffffffffffffffff8381165f818152600d60209081526040808320948716808452600290950182529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b73ffffffffffffffffffffffffffffffffffffffff81161580612e9a575073ffffffffffffffffffffffffffffffffffffffff81166001145b156111e8576040517f9b44163600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604080516101c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a0810182905290612f4961319f565b9150612f596175bf851615613f22565b9050612f6b8261016001518583614083565b612f9873ffffffffffffffffffffffffffffffffffffffff8416600114612f9257836140aa565b816140aa565b816101a0015115801561300057507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826101200151148015612ffe57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826101400151145b155b156115e05760016101a0830152600280547fffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167d010000000000000000000000000000000000000000000000000000000000179055608082015160a08301516115e091906130819071ffffffffffffffffffffffffffffffffffff166135e9565b6001919082547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff6dffffffffffffffffffffffffffff9283166e010000000000000000000000000000027fffffffff00000000000000000000000000000000000000000000000000000000909216929093169190911717167c0100000000000000000000000000000000000000000000000000000000179055565b5f8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff160361317e576040517ff2fbfb2d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613189848684614207565b613194848484614345565b506001949350505050565b604080516101c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a0810191909152613218816139f5565b15611e105760608101516002805465ffffffffffff9092167fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000090921691909117905560e0810151600480546dffffffffffffffffffffffffffff9283167fffffffffffffffffffffffffffffffffffff000000000000000000000000000090911617905560c082015160a083015171ffffffffffffffffffffffffffffffffffff166e0100000000000000000000000000000291161760035561010081015160055590565b6006545f9073ffffffffffffffffffffffffffffffffffffffff811690760100000000000000000000000000000000000000000000900468ffffffffffffffffff168115610fe7575f808373ffffffffffffffffffffffffffffffffffffffff163061336a88608001516dffffffffffffffffffffffffffff166dffffffffffffffffffffffffffff1690565b61338e611a508a60a0015171ffffffffffffffffffffffffffffffffffff166135e9565b60405173ffffffffffffffffffffffffffffffffffffffff909316602484015260448301919091526064820152608401604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fbca02c13000000000000000000000000000000000000000000000000000000001790525161343f9190615817565b5f604051808303815f865af19150503d805f8114613478576040519150601f19603f3d011682016040523d82523d5f602084013e61347d565b606091505b509150915081801561349157506020815110155b1561351957808060200190518101906134aa9190615907565b9250680fd278dfcb4529121f8311156134ca57680fd278dfcb4529121f92505b600680547fff000000000000000000ffffffffffffffffffffffffffffffffffffffffffff1676010000000000000000000000000000000000000000000068ffffffffffffffffff8616021790555b50509392505050565b60c08201517f80b61abbfc5f73cfe5cf93cec97a69ed20643dc6c6f1833b05a1560aa164e24c906dffffffffffffffffffffffffffff1661357d611a508560a0015171ffffffffffffffffffffffffffffffffffff166135e9565b60e08501516dffffffffffffffffffffffffffff1660808601516dffffffffffffffffffffffffffff16610100870151604080519586526020860194909452928401919091526060830152608082015260a081018390524260c082015260e00160405180910390a15050565b5f8171ffffffffffffffffffffffffffffffffffff165f0361360c57505f919050565b610fab61362c8371ffffffffffffffffffffffffffffffffffff16614778565b612c32565b5f8171ffffffffffffffffffffffffffffffffffff165f0361365457505f919050565b610fab6e01ffffffffffffffffffffffffffff601f84901c16612c32565b61368663ffffffff80851690849061479d16565b1561369057505050565b611679816147a8565b80545f906dffffffffffffffffffffffffffff16610fab565b6006545f9073ffffffffffffffffffffffffffffffffffffffff811690760100000000000000000000000000000000000000000000900468ffffffffffffffffff1681158015906137065750613706614880565b15610fe7575f808373ffffffffffffffffffffffffffffffffffffffff163061375088608001516dffffffffffffffffffffffffffff166dffffffffffffffffffffffffffff1690565b613774611a508a60a0015171ffffffffffffffffffffffffffffffffffff166135e9565b60405173ffffffffffffffffffffffffffffffffffffffff909316602484015260448301919091526064820152608401604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f2e34c87200000000000000000000000000000000000000000000000000000000179052516138259190615817565b5f60405180830381855afa9150503d805f811461385d576040519150601f19603f3d011682016040523d82523d5f602084013e613862565b606091505b509150915081801561387657506020815110155b15613519578080602001905181019061388f9190615907565b9250680fd278dfcb4529121f8311156135195750680fd278dfcb4529121f95945050505050565b6138bf8361492e565b73ffffffffffffffffffffffffffffffffffffffff82165f908152600d602052604090205460701c717fffffffffffffffffffffffffffffffffff16806139065750505050565b5f6139138585845f61497f565b90505f805b845181101561396b5761394687878784815181106139385761393861591e565b60200260200101515f614b51565b613950908361589a565b9150828211156139635750505050505050565b600101613918565b506040517f34373fbc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610fe761362c8484614d9b565b73ffffffffffffffffffffffffffffffffffffffff81165f908152600d6020526040812054610fe7908490849060701c717fffffffffffffffffffffffffffffffffff16614dd7565b367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec810135606090811c60408401527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd8820135811c60208401527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc490910135811c825260025465ffffffffffff811691830191909152660100000000000081046dffffffffffffffffffffffffffff1660808301525f90613ad19074010000000000000000000000000000000000000000900461ffff16614e45565b610120830152600254613b0190760100000000000000000000000000000000000000000000900461ffff16614e45565b6101408301526002547801000000000000000000000000000000000000000000000000810463ffffffff9081166101608501527d01000000000000000000000000000000000000000000000000000000000090910460ff1615156101a08401526003546dffffffffffffffffffffffffffff80821660c08601526e01000000000000000000000000000090910471ffffffffffffffffffffffffffffffffffff1660a085015260045490811660e0850152720100000000000000000000000000000000000090041661018083015260055461010083015260608201515f90613bf19065ffffffffffff164261594b565b905080156110195760065461010084015160a08501516001945074010000000000000000000000000000000000000000830461ffff1692760100000000000000000000000000000000000000000000900468ffffffffffffffffff16919071ffffffffffffffffffffffffffffffffffff165f8080613c816b033b2e3c9fd0803ce8000000808801908a90614e91565b9150915080613cb7578185029250818381613c9e57613c9e6158ad565b048503613cb7576b033b2e3c9fd0803ce8000000830494505b8484029250848381613ccb57613ccb6158ad565b048403613cea578961010001518381613ce657613ce66158ad565b0493505b50505060e087015160c088015160a08901516dffffffffffffffffffffffffffff92831692909116905f90651388000000009061ffff89169071ffffffffffffffffffffffffffffffffffff16613d41908761594b565b613d4b919061595e565b613d559190615975565b90508015613dd6575f613d6785614778565b60808c01516dffffffffffffffffffffffffffff16613d86919061589a565b9050613d92828261594b565b613d9c848361595e565b613da69190615975565b60c08c01519093506dffffffffffffffffffffffffffff16613dc8908461594b565b613dd2908561589a565b9350505b717fffffffffffffffffffffffffff800000008411613e9b57613df884614f63565b71ffffffffffffffffffffffffffffffffffff1660a08b01526101008a018590524265ffffffffffff1660608b015260c08a01516dffffffffffffffffffffffffffff168214158015613e5957506dffffffffffffffffffffffffffff8211155b15613e9b57613e6783612c32565b6dffffffffffffffffffffffffffff1660e08b0152613e8582612c32565b6dffffffffffffffffffffffffffff1660c08b01525b5050505050505050919050565b5f80620f4240613ed2611a508560a0015171ffffffffffffffffffffffffffffffffffff166135e9565b60808501516dffffffffffffffffffffffffffff1601019150620f4240613f1a8460c001516dffffffffffffffffffffffffffff166dffffffffffffffffffffffffffff1690565b019050915091565b5f3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614613f6857613f686159ad565b5f807f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166318503a1e85613fb1575f613fb3565b305b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff90911660048201526024016040805180830381865afa158015614019573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061403d91906158da565b9150915083801561404c575080155b15612dab576040517f13790bf000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61409763ffffffff80851690849061479d16565b156140a157505050565b61167981614fb0565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff73ffffffffffffffffffffffffffffffffffffffff8216016140ef576140ef6159ad565b73ffffffffffffffffffffffffffffffffffffffff8116614181577f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663a37d54af6040518163ffffffff1660e01b81526004015f604051808303815f87803b15801561416f575f80fd5b505af115801561130f573d5f803e3d5ffd5b6040517f30f3166700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff82811660048301527f000000000000000000000000000000000000000000000000000000000000000016906330f31667906024015f604051808303815f87803b15801561416f575f80fd5b6dffffffffffffffffffffffffffff8116158061424f57508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b1561425957505050565b73ffffffffffffffffffffffffffffffffffffffff8084165f908152600d602090815260408083209386168352600284019091529020547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811461130f576dffffffffffffffffffffffffffff8316811015614301576040517f9f428ac400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6dffffffffffffffffffffffffffff831673ffffffffffffffffffffffffffffffffffffffff85165f90815260028401602052604090209103908190555050505050565b73ffffffffffffffffffffffffffffffffffffffff8216614392576040517fa8af73b400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6dffffffffffffffffffffffffffff81161561471d5773ffffffffffffffffffffffffffffffffffffffff83165f908152600d60205260408120908061440e83546dffffffffffffffffffffffffffff8116917f8000000000000000000000000000000000000000000000000000000000000000909116151590565b90925090506dffffffffffffffffffffffffffff8085169083161015614460576040517f7374809300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6dffffffffffffffffffffffffffff8581169084160384547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff8216178555905081156145965773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016636fc4fdc1886dffffffffffffffffffffffffffff841661450d6150b7565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b16815273ffffffffffffffffffffffffffffffffffffffff90931660048401526024830191909152151560448201526064015f604051808303815f87803b15801561457f575f80fd5b505af1158015614591573d5f803e3d5ffd5b505050505b73ffffffffffffffffffffffffffffffffffffffff86165f908152600d6020526040812080549095506dffffffffffffffffffffffffffff8116917f80000000000000000000000000000000000000000000000000000000000000009091161515906146028389615121565b87547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff8216178855905081156147155773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016636fc4fdc18a6dffffffffffffffffffffffffffff84166040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff909216600483015260248201525f60448201526064015f604051808303815f87803b1580156146fe575f80fd5b505af1158015614710573d5f803e3d5ffd5b505050505b505050505050505b73ffffffffffffffffffffffffffffffffffffffff8083169084167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6dffffffffffffffffffffffffffff8416604051908152602001612e54565b5f601f600161478b63800000008561589a565b614795919061594b565b901c92915050565b1663ffffffff161590565b6002547c0100000000000000000000000000000000000000000000000000000000900460ff1615614805576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000017905561485581614fb0565b50600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff169055565b6040517fcdd8ea780000000000000000000000000000000000000000000000000000000081523060048201525f907f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff169063cdd8ea7890602401602060405180830381865afa15801561490a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111fe9190615852565b602081015173ffffffffffffffffffffffffffffffffffffffff166111e8576040517f5b92337100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80614992611a5061297d888888614dd7565b9050805f036149a4575f9150506116bd565b856040015173ffffffffffffffffffffffffffffffffffffffff16865f015173ffffffffffffffffffffffffffffffffffffffff16036149e657809150614b48565b8215614a9c576020860151865160408089015190517fae68676c0000000000000000000000000000000000000000000000000000000081526004810185905273ffffffffffffffffffffffffffffffffffffffff9283166024820152908216604482015291169063ae68676c90606401602060405180830381865afa158015614a71573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614a959190615907565b9150614b48565b6020860151865160408089015190517f0579e61f0000000000000000000000000000000000000000000000000000000081526004810185905273ffffffffffffffffffffffffffffffffffffffff92831660248201529082166044820152911690630579e61f906064016040805180830381865afa158015614b20573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614b4491906159da565b9250505b50949350505050565b5f80614b5d8484615142565b905061ffff8116614b71575f9150506116bd565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86811660048301525f91908616906370a0823190602401602060405180830381865afa158015614bde573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614c029190615907565b9050805f03614c15575f925050506116bd565b5f8415614cca5760208801516040808a015190517fae68676c0000000000000000000000000000000000000000000000000000000081526004810185905273ffffffffffffffffffffffffffffffffffffffff8981166024830152918216604482015291169063ae68676c90606401602060405180830381865afa158015614c9f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614cc39190615907565b9050614d74565b60208801516040808a015190517f0579e61f0000000000000000000000000000000000000000000000000000000081526004810185905273ffffffffffffffffffffffffffffffffffffffff89811660248301529182166044820152911690630579e61f906064016040805180830381865afa158015614d4c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614d7091906159da565b5090505b612710614d8561ffff85168361595e565b614d8f9190615975565b98975050505050505050565b5f805f614da784613ea8565b909250905081816dffffffffffffffffffffffffffff87160281614dcd57614dcd6158ad565b0495945050505050565b5f71ffffffffffffffffffffffffffffffffffff8216614df857505f610fe7565b61010084015173ffffffffffffffffffffffffffffffffffffffff84165f908152600d60205260409020600101546116bd9171ffffffffffffffffffffffffffffffffffff8516916151dc565b5f61ffff8216808203614e7a57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff92915050565b6064603f8216600a0a600683901c02049392505050565b5f80848015614f4657600185168015614eac57869350614eb0565b8493505b508360011c8560011c95505b8515614f40578660801c15614ed45760019250614f40565b86870281810181811015614eed57600194505050614f40565b8690049750506001861615614f35578684028488820414614f18578715614f18576001935050614f40565b81810181811015614f2e57600194505050614f40565b8690049450505b8560011c9550614ebc565b50611476565b848015614f55575f9350614f59565b8493505b5050935093915050565b5f717fffffffffffffffffffffffffff80000000821115610f71576040517f9388c33400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600c5473ffffffffffffffffffffffffffffffffffffffff1680615000576040517f750f881700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f808273ffffffffffffffffffffffffffffffffffffffff165f368660405160200161502e939291906159fc565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529082905261506691615817565b5f604051808303815f865af19150503d805f811461509f576040519150601f19603f3d011682016040523d82523d5f602084013e6150a4565b606091505b509150915081611340576113408161520e565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663863789d76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561490a573d5f803e3d5ffd5b5f610fe761362c6dffffffffffffffffffffffffffff80851690861661589a565b73ffffffffffffffffffffffffffffffffffffffff82165f908152600e60209081526040808320815160a081018352905461ffff808216835262010000820481169483019490945264010000000081049093169181019190915265ffffffffffff6601000000000000830416606082015263ffffffff6c0100000000000000000000000090920482166080820152610fe791849061524f16565b5f6116bd826151ff8571ffffffffffffffffffffffffffffffffffff881661595e565b6152099190615975565b614f63565b80511561521d57805181602001fd5b6040517f2082e20000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8161525d57508151610fab565b826060015165ffffffffffff164210158061528857506020830151604084015161ffff908116911610155b1561529857506020820151610fab565b5f6152a8846040015161ffff1690565b61ffff1690505f6152be856020015161ffff1690565b61ffff1690505f42866060015165ffffffffffff16039050856080015163ffffffff168183850302816152f3576152f36158ad565b049190910195945050505050565b5f5b8381101561531b578181015183820152602001615303565b50505f910152565b602081525f8251806020840152615341816040850160208701615301565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b5f60208284031215615383575f80fd5b5035919050565b73ffffffffffffffffffffffffffffffffffffffff811681146111e8575f80fd5b5f80604083850312156153bc575f80fd5b82356153c78161538a565b946020939093013593505050565b5f805f606084860312156153e7575f80fd5b83356153f28161538a565b925060208401356154028161538a565b929592945050506040919091013590565b5f60208284031215615423575f80fd5b8135610fe78161538a565b5f806040838503121561543f575f80fd5b8235915060208301356154518161538a565b809150509250929050565b803561ffff81168114611a67575f80fd5b803563ffffffff81168114611a67575f80fd5b5f805f8060808587031215615493575f80fd5b843561549e8161538a565b93506154ac6020860161545c565b92506154ba6040860161545c565b91506154c86060860161546d565b905092959194509250565b5f805f604084860312156154e5575f80fd5b83359250602084013567ffffffffffffffff80821115615503575f80fd5b818601915086601f830112615516575f80fd5b813581811115615524575f80fd5b876020828501011115615535575f80fd5b6020830194508093505050509250925092565b5f60208284031215615558575f80fd5b610fe78261545c565b5f815180845260208085019450602084015f5b838110156155a657815173ffffffffffffffffffffffffffffffffffffffff1687529582019590820190600101615574565b509495945050505050565b602081525f610fe76020830184615561565b5f805f606084860312156155d5575f80fd5b83356155e08161538a565b925060208401356155f08161538a565b915060408401356156008161538a565b809150509250925092565b80151581146111e8575f80fd5b5f8060408385031215615629575f80fd5b82356156348161538a565b915060208301356154518161560b565b5f60208284031215615654575f80fd5b610fe78261546d565b5f805f6040848603121561566f575f80fd5b833561567a8161538a565b9250602084013567ffffffffffffffff80821115615696575f80fd5b818601915086601f8301126156a9575f80fd5b8135818111156156b7575f80fd5b8760208260051b8501011115615535575f80fd5b5f805f606084860312156156dd575f80fd5b8335925060208401356155f08161538a565b5f805f8060808587031215615702575f80fd5b843561570d8161538a565b9350602085013561571d8161538a565b93969395505050506040820135916060013590565b606081525f6157446060830186615561565b8281036020848101919091528551808352868201928201905f5b8181101561577a5784518352938301939183019160010161575e565b5050809350505050826040830152949350505050565b5f80604083850312156157a1575f80fd5b82356157ac8161538a565b915060208301356154518161538a565b5f80604083850312156157cd575f80fd5b82356157d88161538a565b91506157e66020840161546d565b90509250929050565b5f8060408385031215615800575f80fd5b6158098361545c565b91506157e66020840161545c565b5f8251615828818460208701615301565b9190910192915050565b5f60208284031215615842575f80fd5b815160ff81168114610fe7575f80fd5b5f60208284031215615862575f80fd5b8151610fe78161560b565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b80820180821115610fab57610fab61586d565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f80604083850312156158eb575f80fd5b82516158f68161538a565b60208401519092506154518161560b565b5f60208284031215615917575f80fd5b5051919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b81810381811115610fab57610fab61586d565b8082028115828204841417610fab57610fab61586d565b5f826159a8577f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b500490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b5f80604083850312156159eb575f80fd5b505080516020909101519092909150565b8284823760609190911b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016910190815260140191905056fea26469706673582212209451d74da1a78e85e970abf3b4a14ea86d4dc8ee9fa68422ebcf58adc0cf92ba64736f6c634300081800330000000000000000000000004860c903f6ad709c3eda46d3d502943f184d4315000000000000000000000000c2f9fe90bd17e017898b6efdaa73c34fddde299e0000000000000000000000006f417aaec1d41db692307269acda019ce5f10b0e000000000000000000000000e6e4687c35429942391afe42cddecba857531492000000000000000000000000b952578f3520ee8ea45b7914994dcf4702cee578000000000000000000000000c11085f6f3ba3c685502c8a99669240e8e450a200000000000000000000000006b0d4efa46bc7f8f17e9b1aa30132d426907ebe10000000000000000000000008d089d7b8af57be845ff79cf51288f716ff9c945000000000000000000000000f6fc02bfef0e901b50657dc64ff1506d1f331fdd000000000000000000000000cec866898d475f32cbe74ab9cb76448a6b557bc30000000000000000000000003d6ffa08a81d6c6f506733a6cb8c264c1585d13400000000000000000000000065f7d2208e7ac3c19af7e48643fee1cc0533588f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd19625

Deployed Bytecode

0x608060405260043610610603575f3560e01c806394bf804d11610311578063bf58094d1161019c578063d87f780f116100e7578063e388be7b11610092578063efdcd9741161006d578063efdcd97414610aed578063f3fdb15a146108a3578063f6e50f5814610f32575f80fd5b8063e388be7b146106a7578063ece6a7fa14610f1e578063ef8b30f7146106ea575f80fd5b8063dd62ed3e116100c2578063dd62ed3e14610ead578063e15c82ec14610ecc578063e2f206e514610eeb575f80fd5b8063d87f780f14610e7f578063d905777e146108b7578063d9d7858a14610e99575f80fd5b8063c7b0e3a311610147578063cf349b7d11610122578063cf349b7d14610dfc578063d1a3a30814610e41578063d283e75f14610e60575f80fd5b8063c7b0e3a314610daf578063cbfdd7e114610ddd578063ce96cb77146108b7575f80fd5b8063c522498311610177578063c5224983146108a3578063c63d75b6146108b7578063c6e6f59214610d90575f80fd5b8063bf58094d14610cc2578063c134257414610d52578063c4d66de814610d71575f80fd5b8063ad80ad0b1161025c578063b3d7f6b911610207578063b460af94116101e2578063b460af9414610d00578063b4cd541b14610d1f578063ba08765214610d00575f80fd5b8063b3d7f6b9146106ea578063b3f00674146108a3578063b4113ba714610a28575f80fd5b8063af06d3cf11610237578063af06d3cf14610a28578063af5aaeeb14610cc2578063b168c58f14610ce1575f80fd5b8063ad80ad0b14610c56578063ada3d56f14610c89578063aebde56b14610ca3575f80fd5b8063a75df498116102bc578063a9c8eb7e11610297578063a9c8eb7e14610c18578063ab49b7f114610c37578063acb7081514610984575f80fd5b8063a75df49814610baa578063a824bf6714610bda578063a9059cbb14610bf9575f80fd5b8063961be391116102ec578063961be391146106a7578063a55526db14610b96578063a70354a1146108a3575f80fd5b806394bf804d14610a6857806395d89b4114610667578063960b26a214610b82575f80fd5b80634b3d1223116104915780636ce98c29116103dc57806382ebd6741161038757806388aa6f121161036257806388aa6f1214610b4e5780638bcd401614610aed5780638d56c63914610a68575f80fd5b806382ebd67414610aed578063869e50c714610b07578063883e387514610b1b575f80fd5b80637c3a00fd116103b75780637c3a00fd14610aa65780637d5f2e4e14610aba5780637dc0d1d0146108a3575f80fd5b80636ce98c29146108a35780636e553f6514610a6857806370a0823114610a87575f80fd5b8063539bd5bf1161043c57806360cb90ef1161041757806360cb90ef14610a2857806364b1cdd6146108d15780636a16ef8414610a47575f80fd5b8063539bd5bf146108a3578063587f5ed7146109e15780635fa23055146109f5575f80fd5b80634cdad5061161046c5780634cdad506146106ea5780634f7e43df146109185780635296a431146109c2575f80fd5b80634b3d12231461093f5780634b3fd148146109845780634bca3d5b146109a3575f80fd5b80632b38a367116105515780633e833364116104fc57806342895567116104d757806342895567146108e557806347bd3718146106a75780634abdb95914610918575f80fd5b80633e833364146108a3578063402d267d146108b757806341233a98146108d1575f80fd5b806333708d0c1161052c57806333708d0c1461080b57806338d52e0f1461086b57806339a51be5146108a3575f80fd5b80632b38a367146107a85780632b5335c3146107d1578063313ce567146107e5575f80fd5b80630a28a477116105b157806318e22d981161058c57806318e22d98146107505780631fe8b9531461077f57806323b872dd14610789575f80fd5b80630a28a477146106ea57806314c054bc1461070957806318160ddd1461073c575f80fd5b806307a2d13a116105e157806307a2d13a14610688578063087a6007146106a7578063095ea7b3146106bb575f80fd5b806301e1d1141461060757806302d05d3f1461062e57806306fdde0314610667575b5f80fd5b348015610612575f80fd5b5061061b610f46565b6040519081526020015b60405180910390f35b348015610639575f80fd5b50610642610f46565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610625565b348015610672575f80fd5b5061067b610f75565b6040516106259190615323565b348015610693575f80fd5b5061061b6106a2366004615373565b610fa1565b3480156106b2575f80fd5b5061061b610fb1565b3480156106c6575f80fd5b506106da6106d53660046153ab565b610fdc565b6040519015158152602001610625565b3480156106f5575f80fd5b5061061b610704366004615373565b610fee565b348015610714575f80fd5b506106427f000000000000000000000000f6fc02bfef0e901b50657dc64ff1506d1f331fdd81565b348015610747575f80fd5b5061061b61101f565b34801561075b575f80fd5b5061076461104a565b6040805161ffff938416815292909116602083015201610625565b61078761107b565b005b348015610794575f80fd5b506106da6107a33660046153d5565b6110fe565b3480156107b3575f80fd5b506107bc611156565b60405163ffffffff9091168152602001610625565b3480156107dc575f80fd5b50610787611181565b3480156107f0575f80fd5b506107f96111f5565b60405160ff9091168152602001610625565b348015610816575f80fd5b5061082a610825366004615413565b611203565b6040805161ffff96871681529486166020860152929094169183019190915265ffffffffffff16606082015263ffffffff909116608082015260a001610625565b348015610876575f80fd5b50367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc4013560601c610642565b3480156108ae575f80fd5b50610642611156565b3480156108c2575f80fd5b5061061b610704366004615413565b3480156108dc575f80fd5b5061078761123c565b3480156108f0575f80fd5b506106427f000000000000000000000000cec866898d475f32cbe74ab9cb76448a6b557bc381565b348015610923575f80fd5b5061092c611156565b60405161ffff9091168152602001610625565b34801561094a575f80fd5b50610953611266565b6040517fffffffff000000000000000000000000000000000000000000000000000000009091168152602001610625565b34801561098f575f80fd5b5061061b61099e36600461542e565b61126f565b3480156109ae575f80fd5b506107876109bd366004615480565b6112e5565b3480156109cd575f80fd5b506107876109dc3660046154d3565b611316565b3480156109ec575f80fd5b5061061b611346565b348015610a00575f80fd5b506106427f0000000000000000000000006b0d4efa46bc7f8f17e9b1aa30132d426907ebe181565b348015610a33575f80fd5b50610787610a42366004615548565b61134f565b348015610a52575f80fd5b50610a5b611379565b60405161062591906155b1565b348015610a73575f80fd5b5061061b610a8236600461542e565b6113a5565b348015610a92575f80fd5b5061061b610aa1366004615413565b61140d565b348015610ab1575f80fd5b5061061b611417565b348015610ac5575f80fd5b506106427f0000000000000000000000003d6ffa08a81d6c6f506733a6cb8c264c1585d13481565b348015610af8575f80fd5b50610787610a42366004615413565b348015610b12575f80fd5b50610787611420565b348015610b26575f80fd5b506106427f00000000000000000000000065f7d2208e7ac3c19af7e48643fee1cc0533588f81565b348015610b59575f80fd5b50610b6d610b683660046155c3565b61144a565b60408051928352602083019190915201610625565b348015610b8d575f80fd5b5061061b611156565b348015610ba1575f80fd5b5061078761147f565b348015610bb5575f80fd5b5060065474010000000000000000000000000000000000000000900461ffff1661092c565b348015610be5575f80fd5b50610b6d610bf4366004615618565b6114e6565b348015610c04575f80fd5b506106da610c133660046153ab565b61151a565b348015610c23575f80fd5b50610b6d610c3236600461542e565b611569565b348015610c42575f80fd5b5061061b610c51366004615413565b6115e7565b348015610c61575f80fd5b506106427f000000000000000000000000c11085f6f3ba3c685502c8a99669240e8e450a2081565b348015610c94575f80fd5b50610787610a42366004615644565b348015610cae575f80fd5b50610787610cbd36600461542e565b611612565b348015610ccd575f80fd5b5061092c610cdc366004615413565b611686565b348015610cec575f80fd5b50610953610cfb36600461565d565b6116b1565b348015610d0b575f80fd5b5061061b610d1a3660046156cb565b6116c5565b348015610d2a575f80fd5b506106427f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd1962581565b348015610d5d575f80fd5b50610787610d6c3660046156ef565b611733565b348015610d7c575f80fd5b50610787610d8b366004615413565b6117a8565b348015610d9b575f80fd5b5061061b610daa366004615373565b6117d2565b348015610dba575f80fd5b50610dce610dc9366004615618565b6117dc565b60405161062593929190615732565b348015610de8575f80fd5b506106da610df7366004615790565b611812565b348015610e07575f80fd5b50610e1061104a565b6040805173ffffffffffffffffffffffffffffffffffffffff909316835263ffffffff909116602083015201610625565b348015610e4c575f80fd5b50610787610e5b3660046157bc565b61185a565b348015610e6b575f80fd5b5061061b610e7a366004615413565b611884565b348015610e8a575f80fd5b50610787610e5b3660046157ef565b348015610ea4575f80fd5b50610642610fb1565b348015610eb8575f80fd5b5061061b610ec7366004615790565b61188e565b348015610ed7575f80fd5b506106da610ee6366004615413565b611899565b348015610ef6575f80fd5b506106427f0000000000000000000000008d089d7b8af57be845ff79cf51288f716ff9c94581565b348015610f29575f80fd5b506106426118c4565b348015610f3d575f80fd5b5061061b6118ef565b5f7f0000000000000000000000008d089d7b8af57be845ff79cf51288f716ff9c945610f71816118f8565b5090565b60607f0000000000000000000000006b0d4efa46bc7f8f17e9b1aa30132d426907ebe1610f71816118f8565b5f610fab82611949565b92915050565b5f7f000000000000000000000000f6fc02bfef0e901b50657dc64ff1506d1f331fdd610f71816118f8565b5f610fe78383611a6c565b9392505050565b5f7f0000000000000000000000008d089d7b8af57be845ff79cf51288f716ff9c945611019816118f8565b50919050565b5f7f0000000000000000000000006b0d4efa46bc7f8f17e9b1aa30132d426907ebe1610f71816118f8565b5f807f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd19625611076816118f8565b509091565b3330146110b4576040517f08e2ce1700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc36018060245f375f80825f6004355af490503d5f803e8080156110f6573d5ff35b3d5ffd5b5050565b5f73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431516330361114e57611147848484611b5a565b9050610fe7565b610fe7611c5d565b5f7f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd19625610f71816118f8565b73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d43151633036111eb577f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd196256111e881611cef565b50565b6111f3611c5d565b565b5f6111fe611d09565b905090565b5f805f805f7f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd19625611232816118f8565b5091939590929450565b7f00000000000000000000000065f7d2208e7ac3c19af7e48643fee1cc0533588f6111e881611cef565b5f6111fe611e13565b5f73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d43151633036112dd577f000000000000000000000000f6fc02bfef0e901b50657dc64ff1506d1f331fdd6112d781611cef565b50610fab565b610fab611c5d565b7f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd1962561130f81611cef565b5050505050565b7f000000000000000000000000f6fc02bfef0e901b50657dc64ff1506d1f331fdd61134081611cef565b50505050565b5f6111fe612145565b7f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd196256110fa81611cef565b60607f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd19625610f71816118f8565b5f73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d43151633036112dd577f0000000000000000000000008d089d7b8af57be845ff79cf51288f716ff9c9456112d781611cef565b5f610fab8261223d565b5f6111fe612344565b7f0000000000000000000000003d6ffa08a81d6c6f506733a6cb8c264c1585d1346111e881611cef565b5f807f000000000000000000000000cec866898d475f32cbe74ab9cb76448a6b557bc3611476816118f8565b50935093915050565b73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d43151633036111eb577f000000000000000000000000f6fc02bfef0e901b50657dc64ff1506d1f331fdd6111e881611cef565b5f807f0000000000000000000000003d6ffa08a81d6c6f506733a6cb8c264c1585d134611512816118f8565b509250929050565b5f73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d43151633036112dd57611562838361242a565b9050610fab565b5f8073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d43151633036115d8577f000000000000000000000000f6fc02bfef0e901b50657dc64ff1506d1f331fdd6115d281611cef565b506115e0565b6115e0611c5d565b9250929050565b5f7f000000000000000000000000f6fc02bfef0e901b50657dc64ff1506d1f331fdd611019816118f8565b73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431516330361167e577f000000000000000000000000f6fc02bfef0e901b50657dc64ff1506d1f331fdd61167981611cef565b505050565b6110fa611c5d565b5f7f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd19625611019816118f8565b5f6116bd84848461251f565b949350505050565b5f73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431516330361114e577f0000000000000000000000008d089d7b8af57be845ff79cf51288f716ff9c94561172d81611cef565b50610fe7565b73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d43151633036117a0577f000000000000000000000000cec866898d475f32cbe74ab9cb76448a6b557bc361179a81611cef565b50611340565b611340611c5d565b7f000000000000000000000000c11085f6f3ba3c685502c8a99669240e8e450a206110fa81611cef565b5f610fab82612693565b6060805f7f0000000000000000000000003d6ffa08a81d6c6f506733a6cb8c264c1585d13461180a816118f8565b509250925092565b5f73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d43151633036112dd57611562838361279a565b7f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd1962561167981611cef565b5f610fab82612890565b5f610fe78383612996565b5f7f00000000000000000000000065f7d2208e7ac3c19af7e48643fee1cc0533588f611019816118f8565b5f7f00000000000000000000000065f7d2208e7ac3c19af7e48643fee1cc0533588f610f71816118f8565b5f6111fe612aa8565b7f1fe8b953000000000000000000000000000000000000000000000000000000005f526040360333816018015281600452805f6024375f80603883015f305afa90503d5f803e8080156110f6573d5ff35b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615611a1f57600c5473ffffffffffffffffffffffffffffffffffffffff163381148015906119e6575033301480156119e457507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15611a1d576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b5f611a28612bb9565b9050611a63611a5082611a3a86612c32565b6dffffffffffffffffffffffffffff1690612c7b565b6dffffffffffffffffffffffffffff1690565b9150505b919050565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615611acb576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c01000000000000000000000000000000000000000000000000000000001790555f611b1b612cbf565b9050611b28818585612db7565b5050600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff169055506001919050565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615611bb9576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c0100000000000000000000000000000000000000000000000000000000179055611c0984612e61565b5f611c15601086612ed1565b915050611c2c818686611c2787612c32565b613118565b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff16905595945050505050565b5f7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d43159050604036037f1f8b5215000000000000000000000000000000000000000000000000000000005f52306004523360245234604452608060645280608452805f60a4375f8160a401525f80601f19601f84011660a4015f34865af190503d5f803e8080156110f65760403d036040f35b365f80375f80365f845af43d5f803e8080156110f6573d5ff35b60408051600481526024810182526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f313ce5670000000000000000000000000000000000000000000000000000000017905290515f91367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc4013560601c91839182918491611d9a91615817565b5f60405180830381855afa9150503d805f8114611dd2576040519150601f19603f3d011682016040523d82523d5f602084013e611dd7565b606091505b5091509150818015611deb57506020815110155b611df6576012611e0a565b80806020019051810190611e0a9190615832565b93505050505b90565b5f3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431516141580611ee357507f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431573ffffffffffffffffffffffffffffffffffffffff1663e21e537c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ebd573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ee19190615852565b155b15611f1a576040517ff0991feb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611f2361319f565b90505f611f2f826132dd565b9050611f3b8282613522565b816101a00151156120eb575f6101a08301819052600280547fffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1690556001546dffffffffffffffffffffffffffff808216926e01000000000000000000000000000090920416908190505f611fca611a508760a0015171ffffffffffffffffffffffffffffffffffff166135e9565b905085610140015181118015611fdf57508181115b15612016576040517f6ef90ef100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f612031836dffffffffffffffffffffffffffff871661589a565b90505f612058611a508960a0015171ffffffffffffffffffffffffffffffffffff16613631565b60808901516dffffffffffffffffffffffffffff16612077919061589a565b90508761012001518111801561208c57508181115b156120c3576040517f426073f200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7c01000000000000000000000000000000000000000000000000000000006001555050505050505b61211d8261016001516140007f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d4315613672565b507f4b3d12230000000000000000000000000000000000000000000000000000000092915050565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff161561221b57600c5473ffffffffffffffffffffffffffffffffffffffff163381148015906121e2575033301480156121e057507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612219576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b6111fe612226612bb9565b60e001516dffffffffffffffffffffffffffff1690565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff161561231357600c5473ffffffffffffffffffffffffffffffffffffffff163381148015906122da575033301480156122d857507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612311576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b73ffffffffffffffffffffffffffffffffffffffff82165f908152600d60205260409020610fab90611a5090613699565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff161561241a57600c5473ffffffffffffffffffffffffffffffffffffffff163381148015906123e1575033301480156123df57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612418576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b6111fe612425612bb9565b6136b2565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615612489576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c01000000000000000000000000000000000000000000000000000000001790555f6124dd60106001612ed1565b9150506124ef818286611c2787612c32565b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff169055949350505050565b5f3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d4315161415806125ef57507f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431573ffffffffffffffffffffffffffffffffffffffff1663e21e537c6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156125c9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125ed9190615852565b155b15612626576040517ff0991feb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61266a612631612bb9565b858585808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152506138b692505050565b507fb168c58f000000000000000000000000000000000000000000000000000000009392505050565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff161561276957600c5473ffffffffffffffffffffffffffffffffffffffff163381148015906127305750333014801561272e57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612767576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b5f612772612bb9565b9050611a63611a508261278486612c32565b6dffffffffffffffffffffffffffff169061399e565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff16156127f9576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000017905561284983612e61565b5f612855601085612ed1565b73ffffffffffffffffffffffffffffffffffffffff86165f908152600d602052604090209092506124ef9150829086908690611c2790613699565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff161561296657600c5473ffffffffffffffffffffffffffffffffffffffff1633811480159061292d5750333014801561292b57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612964576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b610fab611a5061297d612977612bb9565b856139ac565b71ffffffffffffffffffffffffffffffffffff166135e9565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615612a6c57600c5473ffffffffffffffffffffffffffffffffffffffff16338114801590612a3357503330148015612a3157507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612a6a576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b5073ffffffffffffffffffffffffffffffffffffffff9182165f908152600d602090815260408083209390941682526002909201909152205490565b6002545f907c0100000000000000000000000000000000000000000000000000000000900460ff1615612b7e57600c5473ffffffffffffffffffffffffffffffffffffffff16338114801590612b4557503330148015612b4357507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffac36013560601c73ffffffffffffffffffffffffffffffffffffffff8216145b155b15612b7c576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b5f612b87612bb9565b9050612bb3611a50828360e001516dffffffffffffffffffffffffffff16612c7b90919063ffffffff16565b91505090565b604080516101c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a0810191909152610f71816139f5565b5f6dffffffffffffffffffffffffffff821115610f71576040517f64e0647900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f805f612c8784613ea8565b9092509050612cb681836dffffffffffffffffffffffffffff88160281612cb057612cb06158ad565b04612c32565b95945050505050565b5f73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d4315163303612db2576040517f18503a1e0000000000000000000000000000000000000000000000000000000081525f60048201819052907f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431573ffffffffffffffffffffffffffffffffffffffff16906318503a1e906024016040805180830381865afa158015612d87573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612dab91906158da565b5092915050565b503390565b8273ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603612def57505050565b73ffffffffffffffffffffffffffffffffffffffff8381165f818152600d60209081526040808320948716808452600290950182529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b73ffffffffffffffffffffffffffffffffffffffff81161580612e9a575073ffffffffffffffffffffffffffffffffffffffff81166001145b156111e8576040517f9b44163600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604080516101c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a0810182905290612f4961319f565b9150612f596175bf851615613f22565b9050612f6b8261016001518583614083565b612f9873ffffffffffffffffffffffffffffffffffffffff8416600114612f9257836140aa565b816140aa565b816101a0015115801561300057507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826101200151148015612ffe57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826101400151145b155b156115e05760016101a0830152600280547fffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167d010000000000000000000000000000000000000000000000000000000000179055608082015160a08301516115e091906130819071ffffffffffffffffffffffffffffffffffff166135e9565b6001919082547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff6dffffffffffffffffffffffffffff9283166e010000000000000000000000000000027fffffffff00000000000000000000000000000000000000000000000000000000909216929093169190911717167c0100000000000000000000000000000000000000000000000000000000179055565b5f8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff160361317e576040517ff2fbfb2d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613189848684614207565b613194848484614345565b506001949350505050565b604080516101c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a0810191909152613218816139f5565b15611e105760608101516002805465ffffffffffff9092167fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000090921691909117905560e0810151600480546dffffffffffffffffffffffffffff9283167fffffffffffffffffffffffffffffffffffff000000000000000000000000000090911617905560c082015160a083015171ffffffffffffffffffffffffffffffffffff166e0100000000000000000000000000000291161760035561010081015160055590565b6006545f9073ffffffffffffffffffffffffffffffffffffffff811690760100000000000000000000000000000000000000000000900468ffffffffffffffffff168115610fe7575f808373ffffffffffffffffffffffffffffffffffffffff163061336a88608001516dffffffffffffffffffffffffffff166dffffffffffffffffffffffffffff1690565b61338e611a508a60a0015171ffffffffffffffffffffffffffffffffffff166135e9565b60405173ffffffffffffffffffffffffffffffffffffffff909316602484015260448301919091526064820152608401604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fbca02c13000000000000000000000000000000000000000000000000000000001790525161343f9190615817565b5f604051808303815f865af19150503d805f8114613478576040519150601f19603f3d011682016040523d82523d5f602084013e61347d565b606091505b509150915081801561349157506020815110155b1561351957808060200190518101906134aa9190615907565b9250680fd278dfcb4529121f8311156134ca57680fd278dfcb4529121f92505b600680547fff000000000000000000ffffffffffffffffffffffffffffffffffffffffffff1676010000000000000000000000000000000000000000000068ffffffffffffffffff8616021790555b50509392505050565b60c08201517f80b61abbfc5f73cfe5cf93cec97a69ed20643dc6c6f1833b05a1560aa164e24c906dffffffffffffffffffffffffffff1661357d611a508560a0015171ffffffffffffffffffffffffffffffffffff166135e9565b60e08501516dffffffffffffffffffffffffffff1660808601516dffffffffffffffffffffffffffff16610100870151604080519586526020860194909452928401919091526060830152608082015260a081018390524260c082015260e00160405180910390a15050565b5f8171ffffffffffffffffffffffffffffffffffff165f0361360c57505f919050565b610fab61362c8371ffffffffffffffffffffffffffffffffffff16614778565b612c32565b5f8171ffffffffffffffffffffffffffffffffffff165f0361365457505f919050565b610fab6e01ffffffffffffffffffffffffffff601f84901c16612c32565b61368663ffffffff80851690849061479d16565b1561369057505050565b611679816147a8565b80545f906dffffffffffffffffffffffffffff16610fab565b6006545f9073ffffffffffffffffffffffffffffffffffffffff811690760100000000000000000000000000000000000000000000900468ffffffffffffffffff1681158015906137065750613706614880565b15610fe7575f808373ffffffffffffffffffffffffffffffffffffffff163061375088608001516dffffffffffffffffffffffffffff166dffffffffffffffffffffffffffff1690565b613774611a508a60a0015171ffffffffffffffffffffffffffffffffffff166135e9565b60405173ffffffffffffffffffffffffffffffffffffffff909316602484015260448301919091526064820152608401604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f2e34c87200000000000000000000000000000000000000000000000000000000179052516138259190615817565b5f60405180830381855afa9150503d805f811461385d576040519150601f19603f3d011682016040523d82523d5f602084013e613862565b606091505b509150915081801561387657506020815110155b15613519578080602001905181019061388f9190615907565b9250680fd278dfcb4529121f8311156135195750680fd278dfcb4529121f95945050505050565b6138bf8361492e565b73ffffffffffffffffffffffffffffffffffffffff82165f908152600d602052604090205460701c717fffffffffffffffffffffffffffffffffff16806139065750505050565b5f6139138585845f61497f565b90505f805b845181101561396b5761394687878784815181106139385761393861591e565b60200260200101515f614b51565b613950908361589a565b9150828211156139635750505050505050565b600101613918565b506040517f34373fbc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610fe761362c8484614d9b565b73ffffffffffffffffffffffffffffffffffffffff81165f908152600d6020526040812054610fe7908490849060701c717fffffffffffffffffffffffffffffffffff16614dd7565b367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec810135606090811c60408401527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd8820135811c60208401527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc490910135811c825260025465ffffffffffff811691830191909152660100000000000081046dffffffffffffffffffffffffffff1660808301525f90613ad19074010000000000000000000000000000000000000000900461ffff16614e45565b610120830152600254613b0190760100000000000000000000000000000000000000000000900461ffff16614e45565b6101408301526002547801000000000000000000000000000000000000000000000000810463ffffffff9081166101608501527d01000000000000000000000000000000000000000000000000000000000090910460ff1615156101a08401526003546dffffffffffffffffffffffffffff80821660c08601526e01000000000000000000000000000090910471ffffffffffffffffffffffffffffffffffff1660a085015260045490811660e0850152720100000000000000000000000000000000000090041661018083015260055461010083015260608201515f90613bf19065ffffffffffff164261594b565b905080156110195760065461010084015160a08501516001945074010000000000000000000000000000000000000000830461ffff1692760100000000000000000000000000000000000000000000900468ffffffffffffffffff16919071ffffffffffffffffffffffffffffffffffff165f8080613c816b033b2e3c9fd0803ce8000000808801908a90614e91565b9150915080613cb7578185029250818381613c9e57613c9e6158ad565b048503613cb7576b033b2e3c9fd0803ce8000000830494505b8484029250848381613ccb57613ccb6158ad565b048403613cea578961010001518381613ce657613ce66158ad565b0493505b50505060e087015160c088015160a08901516dffffffffffffffffffffffffffff92831692909116905f90651388000000009061ffff89169071ffffffffffffffffffffffffffffffffffff16613d41908761594b565b613d4b919061595e565b613d559190615975565b90508015613dd6575f613d6785614778565b60808c01516dffffffffffffffffffffffffffff16613d86919061589a565b9050613d92828261594b565b613d9c848361595e565b613da69190615975565b60c08c01519093506dffffffffffffffffffffffffffff16613dc8908461594b565b613dd2908561589a565b9350505b717fffffffffffffffffffffffffff800000008411613e9b57613df884614f63565b71ffffffffffffffffffffffffffffffffffff1660a08b01526101008a018590524265ffffffffffff1660608b015260c08a01516dffffffffffffffffffffffffffff168214158015613e5957506dffffffffffffffffffffffffffff8211155b15613e9b57613e6783612c32565b6dffffffffffffffffffffffffffff1660e08b0152613e8582612c32565b6dffffffffffffffffffffffffffff1660c08b01525b5050505050505050919050565b5f80620f4240613ed2611a508560a0015171ffffffffffffffffffffffffffffffffffff166135e9565b60808501516dffffffffffffffffffffffffffff1601019150620f4240613f1a8460c001516dffffffffffffffffffffffffffff166dffffffffffffffffffffffffffff1690565b019050915091565b5f3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d43151614613f6857613f686159ad565b5f807f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431573ffffffffffffffffffffffffffffffffffffffff166318503a1e85613fb1575f613fb3565b305b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff90911660048201526024016040805180830381865afa158015614019573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061403d91906158da565b9150915083801561404c575080155b15612dab576040517f13790bf000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61409763ffffffff80851690849061479d16565b156140a157505050565b61167981614fb0565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff73ffffffffffffffffffffffffffffffffffffffff8216016140ef576140ef6159ad565b73ffffffffffffffffffffffffffffffffffffffff8116614181577f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431573ffffffffffffffffffffffffffffffffffffffff1663a37d54af6040518163ffffffff1660e01b81526004015f604051808303815f87803b15801561416f575f80fd5b505af115801561130f573d5f803e3d5ffd5b6040517f30f3166700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff82811660048301527f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431516906330f31667906024015f604051808303815f87803b15801561416f575f80fd5b6dffffffffffffffffffffffffffff8116158061424f57508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b1561425957505050565b73ffffffffffffffffffffffffffffffffffffffff8084165f908152600d602090815260408083209386168352600284019091529020547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811461130f576dffffffffffffffffffffffffffff8316811015614301576040517f9f428ac400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6dffffffffffffffffffffffffffff831673ffffffffffffffffffffffffffffffffffffffff85165f90815260028401602052604090209103908190555050505050565b73ffffffffffffffffffffffffffffffffffffffff8216614392576040517fa8af73b400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6dffffffffffffffffffffffffffff81161561471d5773ffffffffffffffffffffffffffffffffffffffff83165f908152600d60205260408120908061440e83546dffffffffffffffffffffffffffff8116917f8000000000000000000000000000000000000000000000000000000000000000909116151590565b90925090506dffffffffffffffffffffffffffff8085169083161015614460576040517f7374809300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6dffffffffffffffffffffffffffff8581169084160384547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff8216178555905081156145965773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e6e4687c35429942391afe42cddecba85753149216636fc4fdc1886dffffffffffffffffffffffffffff841661450d6150b7565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b16815273ffffffffffffffffffffffffffffffffffffffff90931660048401526024830191909152151560448201526064015f604051808303815f87803b15801561457f575f80fd5b505af1158015614591573d5f803e3d5ffd5b505050505b73ffffffffffffffffffffffffffffffffffffffff86165f908152600d6020526040812080549095506dffffffffffffffffffffffffffff8116917f80000000000000000000000000000000000000000000000000000000000000009091161515906146028389615121565b87547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff8216178855905081156147155773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e6e4687c35429942391afe42cddecba85753149216636fc4fdc18a6dffffffffffffffffffffffffffff84166040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff909216600483015260248201525f60448201526064015f604051808303815f87803b1580156146fe575f80fd5b505af1158015614710573d5f803e3d5ffd5b505050505b505050505050505b73ffffffffffffffffffffffffffffffffffffffff8083169084167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6dffffffffffffffffffffffffffff8416604051908152602001612e54565b5f601f600161478b63800000008561589a565b614795919061594b565b901c92915050565b1663ffffffff161590565b6002547c0100000000000000000000000000000000000000000000000000000000900460ff1615614805576040517f74f3606300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000017905561485581614fb0565b50600280547fffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffff169055565b6040517fcdd8ea780000000000000000000000000000000000000000000000000000000081523060048201525f907f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431573ffffffffffffffffffffffffffffffffffffffff169063cdd8ea7890602401602060405180830381865afa15801561490a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111fe9190615852565b602081015173ffffffffffffffffffffffffffffffffffffffff166111e8576040517f5b92337100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80614992611a5061297d888888614dd7565b9050805f036149a4575f9150506116bd565b856040015173ffffffffffffffffffffffffffffffffffffffff16865f015173ffffffffffffffffffffffffffffffffffffffff16036149e657809150614b48565b8215614a9c576020860151865160408089015190517fae68676c0000000000000000000000000000000000000000000000000000000081526004810185905273ffffffffffffffffffffffffffffffffffffffff9283166024820152908216604482015291169063ae68676c90606401602060405180830381865afa158015614a71573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614a959190615907565b9150614b48565b6020860151865160408089015190517f0579e61f0000000000000000000000000000000000000000000000000000000081526004810185905273ffffffffffffffffffffffffffffffffffffffff92831660248201529082166044820152911690630579e61f906064016040805180830381865afa158015614b20573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614b4491906159da565b9250505b50949350505050565b5f80614b5d8484615142565b905061ffff8116614b71575f9150506116bd565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86811660048301525f91908616906370a0823190602401602060405180830381865afa158015614bde573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614c029190615907565b9050805f03614c15575f925050506116bd565b5f8415614cca5760208801516040808a015190517fae68676c0000000000000000000000000000000000000000000000000000000081526004810185905273ffffffffffffffffffffffffffffffffffffffff8981166024830152918216604482015291169063ae68676c90606401602060405180830381865afa158015614c9f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614cc39190615907565b9050614d74565b60208801516040808a015190517f0579e61f0000000000000000000000000000000000000000000000000000000081526004810185905273ffffffffffffffffffffffffffffffffffffffff89811660248301529182166044820152911690630579e61f906064016040805180830381865afa158015614d4c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614d7091906159da565b5090505b612710614d8561ffff85168361595e565b614d8f9190615975565b98975050505050505050565b5f805f614da784613ea8565b909250905081816dffffffffffffffffffffffffffff87160281614dcd57614dcd6158ad565b0495945050505050565b5f71ffffffffffffffffffffffffffffffffffff8216614df857505f610fe7565b61010084015173ffffffffffffffffffffffffffffffffffffffff84165f908152600d60205260409020600101546116bd9171ffffffffffffffffffffffffffffffffffff8516916151dc565b5f61ffff8216808203614e7a57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff92915050565b6064603f8216600a0a600683901c02049392505050565b5f80848015614f4657600185168015614eac57869350614eb0565b8493505b508360011c8560011c95505b8515614f40578660801c15614ed45760019250614f40565b86870281810181811015614eed57600194505050614f40565b8690049750506001861615614f35578684028488820414614f18578715614f18576001935050614f40565b81810181811015614f2e57600194505050614f40565b8690049450505b8560011c9550614ebc565b50611476565b848015614f55575f9350614f59565b8493505b5050935093915050565b5f717fffffffffffffffffffffffffff80000000821115610f71576040517f9388c33400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600c5473ffffffffffffffffffffffffffffffffffffffff1680615000576040517f750f881700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f808273ffffffffffffffffffffffffffffffffffffffff165f368660405160200161502e939291906159fc565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529082905261506691615817565b5f604051808303815f865af19150503d805f811461509f576040519150601f19603f3d011682016040523d82523d5f602084013e6150a4565b606091505b509150915081611340576113408161520e565b5f7f0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d431573ffffffffffffffffffffffffffffffffffffffff1663863789d76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561490a573d5f803e3d5ffd5b5f610fe761362c6dffffffffffffffffffffffffffff80851690861661589a565b73ffffffffffffffffffffffffffffffffffffffff82165f908152600e60209081526040808320815160a081018352905461ffff808216835262010000820481169483019490945264010000000081049093169181019190915265ffffffffffff6601000000000000830416606082015263ffffffff6c0100000000000000000000000090920482166080820152610fe791849061524f16565b5f6116bd826151ff8571ffffffffffffffffffffffffffffffffffff881661595e565b6152099190615975565b614f63565b80511561521d57805181602001fd5b6040517f2082e20000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8161525d57508151610fab565b826060015165ffffffffffff164210158061528857506020830151604084015161ffff908116911610155b1561529857506020820151610fab565b5f6152a8846040015161ffff1690565b61ffff1690505f6152be856020015161ffff1690565b61ffff1690505f42866060015165ffffffffffff16039050856080015163ffffffff168183850302816152f3576152f36158ad565b049190910195945050505050565b5f5b8381101561531b578181015183820152602001615303565b50505f910152565b602081525f8251806020840152615341816040850160208701615301565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b5f60208284031215615383575f80fd5b5035919050565b73ffffffffffffffffffffffffffffffffffffffff811681146111e8575f80fd5b5f80604083850312156153bc575f80fd5b82356153c78161538a565b946020939093013593505050565b5f805f606084860312156153e7575f80fd5b83356153f28161538a565b925060208401356154028161538a565b929592945050506040919091013590565b5f60208284031215615423575f80fd5b8135610fe78161538a565b5f806040838503121561543f575f80fd5b8235915060208301356154518161538a565b809150509250929050565b803561ffff81168114611a67575f80fd5b803563ffffffff81168114611a67575f80fd5b5f805f8060808587031215615493575f80fd5b843561549e8161538a565b93506154ac6020860161545c565b92506154ba6040860161545c565b91506154c86060860161546d565b905092959194509250565b5f805f604084860312156154e5575f80fd5b83359250602084013567ffffffffffffffff80821115615503575f80fd5b818601915086601f830112615516575f80fd5b813581811115615524575f80fd5b876020828501011115615535575f80fd5b6020830194508093505050509250925092565b5f60208284031215615558575f80fd5b610fe78261545c565b5f815180845260208085019450602084015f5b838110156155a657815173ffffffffffffffffffffffffffffffffffffffff1687529582019590820190600101615574565b509495945050505050565b602081525f610fe76020830184615561565b5f805f606084860312156155d5575f80fd5b83356155e08161538a565b925060208401356155f08161538a565b915060408401356156008161538a565b809150509250925092565b80151581146111e8575f80fd5b5f8060408385031215615629575f80fd5b82356156348161538a565b915060208301356154518161560b565b5f60208284031215615654575f80fd5b610fe78261546d565b5f805f6040848603121561566f575f80fd5b833561567a8161538a565b9250602084013567ffffffffffffffff80821115615696575f80fd5b818601915086601f8301126156a9575f80fd5b8135818111156156b7575f80fd5b8760208260051b8501011115615535575f80fd5b5f805f606084860312156156dd575f80fd5b8335925060208401356155f08161538a565b5f805f8060808587031215615702575f80fd5b843561570d8161538a565b9350602085013561571d8161538a565b93969395505050506040820135916060013590565b606081525f6157446060830186615561565b8281036020848101919091528551808352868201928201905f5b8181101561577a5784518352938301939183019160010161575e565b5050809350505050826040830152949350505050565b5f80604083850312156157a1575f80fd5b82356157ac8161538a565b915060208301356154518161538a565b5f80604083850312156157cd575f80fd5b82356157d88161538a565b91506157e66020840161546d565b90509250929050565b5f8060408385031215615800575f80fd5b6158098361545c565b91506157e66020840161545c565b5f8251615828818460208701615301565b9190910192915050565b5f60208284031215615842575f80fd5b815160ff81168114610fe7575f80fd5b5f60208284031215615862575f80fd5b8151610fe78161560b565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b80820180821115610fab57610fab61586d565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f80604083850312156158eb575f80fd5b82516158f68161538a565b60208401519092506154518161560b565b5f60208284031215615917575f80fd5b5051919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b81810381811115610fab57610fab61586d565b8082028115828204841417610fab57610fab61586d565b5f826159a8577f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b500490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b5f80604083850312156159eb575f80fd5b505080516020909101519092909150565b8284823760609190911b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016910190815260140191905056fea26469706673582212209451d74da1a78e85e970abf3b4a14ea86d4dc8ee9fa68422ebcf58adc0cf92ba64736f6c63430008180033

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

0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d4315000000000000000000000000c2f9fe90bd17e017898b6efdaa73c34fddde299e0000000000000000000000006f417aaec1d41db692307269acda019ce5f10b0e000000000000000000000000e6e4687c35429942391afe42cddecba857531492000000000000000000000000b952578f3520ee8ea45b7914994dcf4702cee578000000000000000000000000c11085f6f3ba3c685502c8a99669240e8e450a200000000000000000000000006b0d4efa46bc7f8f17e9b1aa30132d426907ebe10000000000000000000000008d089d7b8af57be845ff79cf51288f716ff9c945000000000000000000000000f6fc02bfef0e901b50657dc64ff1506d1f331fdd000000000000000000000000cec866898d475f32cbe74ab9cb76448a6b557bc30000000000000000000000003d6ffa08a81d6c6f506733a6cb8c264c1585d13400000000000000000000000065f7d2208e7ac3c19af7e48643fee1cc0533588f0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd19625

-----Decoded View---------------
Arg [0] : integrations (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [1] : modules (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]

-----Encoded View---------------
13 Constructor Arguments found :
Arg [0] : 0000000000000000000000004860c903f6ad709c3eda46d3d502943f184d4315
Arg [1] : 000000000000000000000000c2f9fe90bd17e017898b6efdaa73c34fddde299e
Arg [2] : 0000000000000000000000006f417aaec1d41db692307269acda019ce5f10b0e
Arg [3] : 000000000000000000000000e6e4687c35429942391afe42cddecba857531492
Arg [4] : 000000000000000000000000b952578f3520ee8ea45b7914994dcf4702cee578
Arg [5] : 000000000000000000000000c11085f6f3ba3c685502c8a99669240e8e450a20
Arg [6] : 0000000000000000000000006b0d4efa46bc7f8f17e9b1aa30132d426907ebe1
Arg [7] : 0000000000000000000000008d089d7b8af57be845ff79cf51288f716ff9c945
Arg [8] : 000000000000000000000000f6fc02bfef0e901b50657dc64ff1506d1f331fdd
Arg [9] : 000000000000000000000000cec866898d475f32cbe74ab9cb76448a6b557bc3
Arg [10] : 0000000000000000000000003d6ffa08a81d6c6f506733a6cb8c264c1585d134
Arg [11] : 00000000000000000000000065f7d2208e7ac3c19af7e48643fee1cc0533588f
Arg [12] : 0000000000000000000000003e9c05d9e384b18cd964e52b1fe232bcfdd19625


Block Transaction Gas Used Reward
view all blocks produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits

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