ETH Price: $1,713.94 (+1.93%)
Gas: 20 Gwei
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Sponsored

Transaction Hash
Method
Block
From
To
Value
0x6103c060174790612023-06-14 15:26:47109 days 23 hrs ago1686756407IN
 Contract Creation
0 ETH0.0927025232.39413704

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0x26Ed78...55c7e212
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
CurveV1Adapter2Assets

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 2000 runs

Other Settings:
default evmVersion
File 1 of 27 : CurveV1_2.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2023
pragma solidity ^0.8.17;

import {IAdapter, AdapterType} from "../../interfaces/IAdapter.sol";

import {N_COINS} from "../../integrations/curve/ICurvePool_2.sol";
import {ICurveV1_2AssetsAdapter} from "../../interfaces/curve/ICurveV1_2AssetsAdapter.sol";
import {CurveV1AdapterBase} from "./CurveV1_Base.sol";

/// @title Curve V1 2 assets adapter
/// @notice Implements logic allowing to interact with Curve pools with 2 assets
contract CurveV1Adapter2Assets is CurveV1AdapterBase, ICurveV1_2AssetsAdapter {
    function _gearboxAdapterType() external pure virtual override(CurveV1AdapterBase, IAdapter) returns (AdapterType) {
        return AdapterType.CURVE_V1_2ASSETS;
    }

    /// @notice Constructor
    /// @param _creditManager Credit manager address
    /// @param _curvePool Target Curve pool address
    /// @param _lp_token Pool LP token address
    /// @param _metapoolBase Base pool address (for metapools only) or zero address
    constructor(address _creditManager, address _curvePool, address _lp_token, address _metapoolBase)
        CurveV1AdapterBase(_creditManager, _curvePool, _lp_token, _metapoolBase, N_COINS)
    {}

    /// @inheritdoc ICurveV1_2AssetsAdapter
    function add_liquidity(uint256[N_COINS] calldata amounts, uint256) external creditFacadeOnly {
        _add_liquidity(amounts[0] > 1, amounts[1] > 1, false, false); // F: [ACV1_2-4, ACV1S-1]
    }

    /// @inheritdoc ICurveV1_2AssetsAdapter
    function remove_liquidity(uint256, uint256[N_COINS] calldata) external virtual creditFacadeOnly {
        _remove_liquidity(); // F: [ACV1_2-5]
    }

    /// @inheritdoc ICurveV1_2AssetsAdapter
    function remove_liquidity_imbalance(uint256[N_COINS] calldata amounts, uint256)
        external
        virtual
        override
        creditFacadeOnly
    {
        _remove_liquidity_imbalance(amounts[0] > 1, amounts[1] > 1, false, false); // F: [ACV1_2-6]
    }
}

File 2 of 27 : AbstractAdapter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

import { IACL } from "../interfaces/IACL.sol";
import { IAdapter } from "../interfaces/adapters/IAdapter.sol";
import { IAddressProvider } from "../interfaces/IAddressProvider.sol";
import { ICreditManagerV2 } from "../interfaces/ICreditManagerV2.sol";
import { IPoolService } from "../interfaces/IPoolService.sol";
import { ZeroAddressException } from "../interfaces/IErrors.sol";

/// @title Abstract adapter
/// @dev Inheriting adapters MUST use provided internal functions to perform all operations with credit accounts
abstract contract AbstractAdapter is IAdapter {
    /// @notice Credit Manager the adapter is connected to
    ICreditManagerV2 public immutable override creditManager;

    /// @notice Address provider
    IAddressProvider public immutable override addressProvider;

    /// @notice Address of the contract the adapter is interacting with
    address public immutable override targetContract;

    /// @notice ACL contract to check rights
    IACL public immutable override _acl;

    /// @notice Constructor
    /// @param _creditManager Credit Manager to connect this adapter to
    /// @param _targetContract Address of the contract this adapter should interact with
    constructor(address _creditManager, address _targetContract) {
        if (_creditManager == address(0) || _targetContract == address(0)) {
            revert ZeroAddressException(); // F: [AA-2]
        }

        creditManager = ICreditManagerV2(_creditManager); // F: [AA-1]
        addressProvider = IAddressProvider(
            IPoolService(creditManager.pool()).addressProvider()
        ); // F: [AA-1]
        targetContract = _targetContract; // F: [AA-1]

        _acl = IACL(addressProvider.getACL()); // F: [AA-1]
    }

    /// @notice Reverts if caller of the function is not configurator
    modifier configuratorOnly() {
        if (!_acl.isConfigurator(msg.sender))
            revert CallerNotConfiguratorException(); // F: [AA-16]
        _;
    }

    /// @notice Reverts if caller of the function is not the Credit Facade
    /// @dev Adapter functions are only allowed to be called from within the multicall
    ///      Since at this point Credit Account is owned by the Credit Facade, all functions
    ///      of inheriting adapters that perform actions on account MUST have this modifier
    modifier creditFacadeOnly() {
        if (msg.sender != _creditFacade()) {
            revert CreditFacadeOnlyException(); // F: [AA-5]
        }
        _;
    }

    /// @dev Returns the Credit Facade connected to the Credit Manager
    function _creditFacade() internal view returns (address) {
        return creditManager.creditFacade(); // F: [AA-3]
    }

    /// @dev Returns the Credit Account currently owned by the Credit Facade
    /// @dev Inheriting adapters MUST use this function to find the account address
    function _creditAccount() internal view returns (address) {
        return creditManager.getCreditAccountOrRevert(_creditFacade()); // F: [AA-4]
    }

    /// @dev Returns collateral token mask of given token in the Credit Manager
    /// @param token Token to get the mask for
    /// @return tokenMask Collateral token mask
    /// @dev Reverts if token is not registered as collateral token in the Credit Manager
    function _getMaskOrRevert(address token)
        internal
        view
        returns (uint256 tokenMask)
    {
        tokenMask = creditManager.tokenMasksMap(token); // F: [AA-6]
        if (tokenMask == 0) {
            revert TokenNotAllowedException(); // F: [AA-6]
        }
    }

    /// @dev Approves the target contract to spend given token from the Credit Account
    /// @param token Token to be approved
    /// @param amount Amount to be approved
    /// @dev Reverts if token is not registered as collateral token in the Credit Manager
    function _approveToken(address token, uint256 amount) internal {
        creditManager.approveCreditAccount(
            _creditFacade(),
            targetContract,
            token,
            amount
        ); // F: [AA-7, AA-8]
    }

    /// @dev Enables a token in the Credit Account
    /// @param token Address of the token to enable
    /// @dev Reverts if token is not registered as collateral token in the Credit Manager
    function _enableToken(address token) internal {
        creditManager.checkAndEnableToken(_creditAccount(), token); // F: [AA-7, AA-9]
    }

    /// @dev Disables a token in the Credit Account
    /// @param token Address of the token to disable
    function _disableToken(address token) internal {
        creditManager.disableToken(_creditAccount(), token); // F: [AA-7, AA-10]
    }

    /// @dev Changes enabled tokens in the Credit Account
    /// @param tokensToEnable Bitmask of tokens that should be enabled
    /// @param tokensToDisable Bitmask of tokens that should be disabled
    /// @dev This function might be useful for adapters that work with limited set of tokens, whose masks can be
    ///      determined in the adapter constructor, thus saving gas by avoiding querying them during execution
    ///      and combining multiple enable/disable operations into a single one
    function _changeEnabledTokens(
        uint256 tokensToEnable,
        uint256 tokensToDisable
    ) internal {
        address creditAccount = _creditAccount(); // F: [AA-7]
        unchecked {
            uint256 tokensToChange = tokensToEnable ^ tokensToDisable;
            address token;
            uint256 mask = 1;
            while (mask <= tokensToChange) {
                if (tokensToChange & mask != 0) {
                    (token, ) = creditManager.collateralTokensByMask(mask);
                    if (tokensToEnable & mask != 0) {
                        creditManager.checkAndEnableToken(creditAccount, token); // F: [AA-11]
                    } else {
                        creditManager.disableToken(creditAccount, token); // F: [AA-11]
                    }
                }
                if (mask == 1 << 255) break; // F: [AA-11A]
                mask <<= 1;
            }
        }
    }

    /// @dev Executes an arbitrary call from the Credit Account to the target contract
    /// @param callData Data to call the target contract with
    /// @return result Call output
    function _execute(bytes memory callData)
        internal
        returns (bytes memory result)
    {
        return
            creditManager.executeOrder(
                _creditFacade(),
                targetContract,
                callData
            ); // F: [AA-7, AA-12]
    }

    /// @dev Executes a swap operation on the target contract from the Credit Account
    ///      without explicit approval to spend `tokenIn`
    /// @param tokenIn The token that the call is expected to spend
    /// @param tokenOut The token that the call is expected to produce
    /// @param callData Data to call the target contract with
    /// @param disableTokenIn Whether the input token should be disabled afterwards
    ///        (for operations that spend the entire balance)
    /// @return result Call output
    /// @dev Reverts if tokenIn or tokenOut are not registered as collateral in the Credit Manager
    function _executeSwapNoApprove(
        address tokenIn,
        address tokenOut,
        bytes memory callData,
        bool disableTokenIn
    ) internal returns (bytes memory result) {
        _getMaskOrRevert(tokenIn); // F: [AA-15]
        result = _executeSwap(tokenIn, tokenOut, callData, disableTokenIn); // F: [AA-7, AA-13]
    }

    /// @dev Executes a swap operation on the target contract from the Credit Account
    ///      with maximal `tokenIn` allowance, and then sets the allowance to 1
    /// @param tokenIn The token that the call is expected to spend
    /// @param tokenOut The token that the call is expected to produce
    /// @param callData Data to call the target contract with
    /// @param disableTokenIn Whether the input token should be disabled afterwards
    ///        (for operations that spend the entire balance)
    /// @return result Call output
    /// @dev Reverts if tokenIn or tokenOut are not registered as collateral in the Credit Manager
    function _executeSwapSafeApprove(
        address tokenIn,
        address tokenOut,
        bytes memory callData,
        bool disableTokenIn
    ) internal returns (bytes memory result) {
        _approveToken(tokenIn, type(uint256).max); // F: [AA-14, AA-15]
        result = _executeSwap(tokenIn, tokenOut, callData, disableTokenIn); // F: [AA-7, AA-14]
        _approveToken(tokenIn, 1); // F: [AA-14]
    }

    /// @dev Implementation of `_executeSwap...` operations
    /// @dev Kept private as only the internal wrappers are intended to be used
    ///      by inheritors
    function _executeSwap(
        address tokenIn,
        address tokenOut,
        bytes memory callData,
        bool disableTokenIn
    ) private returns (bytes memory result) {
        result = _execute(callData); // F: [AA-13, AA-14]
        if (disableTokenIn) {
            _disableToken(tokenIn); // F: [AA-13, AA-14]
        }
        _enableToken(tokenOut); // F: [AA-13, AA-14, AA-15]
    }
}

File 3 of 27 : Claimable.sol
// SPDX-License-Identifier: BUSL-1.1
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";

/// @title Claimable
/// @dev Implements logic for a two-step ownership transfer on top of Ownable
contract Claimable is Ownable {
    /// @dev The new owner that has not claimed ownership yet
    address public pendingOwner;

    /// @dev A modifier that restricts the function to the pending owner only
    modifier onlyPendingOwner() {
        if (msg.sender != pendingOwner) {
            revert("Claimable: Sender is not pending owner");
        }
        _;
    }

    /// @dev Sets pending owner to the new owner, but does not
    /// transfer ownership yet
    /// @param newOwner The address to become the future owner
    function transferOwnership(address newOwner) public override onlyOwner {
        require(
            newOwner != address(0),
            "Claimable: new owner is the zero address"
        );
        pendingOwner = newOwner;
    }

    /// @dev Used by the pending owner to claim ownership after transferOwnership
    function claimOwnership() external onlyPendingOwner {
        _transferOwnership(pendingOwner);
        pendingOwner = address(0);
    }
}

File 4 of 27 : AddressProvider.sol
// SPDX-License-Identifier: BUSL-1.1
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

import { IAddressProvider } from "../interfaces/IAddressProvider.sol";
import { Claimable } from "./access/Claimable.sol";
import { Errors } from "../libraries/Errors.sol";

// Repositories & services
bytes32 constant CONTRACTS_REGISTER = "CONTRACTS_REGISTER";
bytes32 constant ACL = "ACL";
bytes32 constant PRICE_ORACLE = "PRICE_ORACLE";
bytes32 constant ACCOUNT_FACTORY = "ACCOUNT_FACTORY";
bytes32 constant DATA_COMPRESSOR = "DATA_COMPRESSOR";
bytes32 constant TREASURY_CONTRACT = "TREASURY_CONTRACT";
bytes32 constant GEAR_TOKEN = "GEAR_TOKEN";
bytes32 constant WETH_TOKEN = "WETH_TOKEN";
bytes32 constant WETH_GATEWAY = "WETH_GATEWAY";
bytes32 constant LEVERAGED_ACTIONS = "LEVERAGED_ACTIONS";

/// @title AddressRepository
/// @notice Stores addresses of deployed contracts
contract AddressProvider is Claimable, IAddressProvider {
    // Mapping from contract keys to respective addresses
    mapping(bytes32 => address) public addresses;

    // Contract version
    uint256 public constant version = 2;

    constructor() {
        // @dev Emits first event for contract discovery
        emit AddressSet("ADDRESS_PROVIDER", address(this));
    }

    /// @return Address of ACL contract
    function getACL() external view returns (address) {
        return _getAddress(ACL); // F:[AP-3]
    }

    /// @dev Sets address of ACL contract
    /// @param _address Address of ACL contract
    function setACL(address _address)
        external
        onlyOwner // F:[AP-12]
    {
        _setAddress(ACL, _address); // F:[AP-3]
    }

    /// @return Address of ContractsRegister
    function getContractsRegister() external view returns (address) {
        return _getAddress(CONTRACTS_REGISTER); // F:[AP-4]
    }

    /// @dev Sets address of ContractsRegister
    /// @param _address Address of ContractsRegister
    function setContractsRegister(address _address)
        external
        onlyOwner // F:[AP-12]
    {
        _setAddress(CONTRACTS_REGISTER, _address); // F:[AP-4]
    }

    /// @return Address of PriceOracle
    function getPriceOracle() external view override returns (address) {
        return _getAddress(PRICE_ORACLE); // F:[AP-5]
    }

    /// @dev Sets address of PriceOracle
    /// @param _address Address of PriceOracle
    function setPriceOracle(address _address)
        external
        onlyOwner // F:[AP-12]
    {
        _setAddress(PRICE_ORACLE, _address); // F:[AP-5]
    }

    /// @return Address of AccountFactory
    function getAccountFactory() external view returns (address) {
        return _getAddress(ACCOUNT_FACTORY); // F:[AP-6]
    }

    /// @dev Sets address of AccountFactory
    /// @param _address Address of AccountFactory
    function setAccountFactory(address _address)
        external
        onlyOwner // F:[AP-12]
    {
        _setAddress(ACCOUNT_FACTORY, _address); // F:[AP-6]
    }

    /// @return Address of DataCompressor
    function getDataCompressor() external view override returns (address) {
        return _getAddress(DATA_COMPRESSOR); // F:[AP-7]
    }

    /// @dev Sets address of AccountFactory
    /// @param _address Address of AccountFactory
    function setDataCompressor(address _address)
        external
        onlyOwner // F:[AP-12]
    {
        _setAddress(DATA_COMPRESSOR, _address); // F:[AP-7]
    }

    /// @return Address of Treasury contract
    function getTreasuryContract() external view returns (address) {
        return _getAddress(TREASURY_CONTRACT); // F:[AP-8]
    }

    /// @dev Sets address of Treasury Contract
    /// @param _address Address of Treasury Contract
    function setTreasuryContract(address _address)
        external
        onlyOwner // F:[AP-12]
    {
        _setAddress(TREASURY_CONTRACT, _address); // F:[AP-8]
    }

    /// @return Address of GEAR token
    function getGearToken() external view override returns (address) {
        return _getAddress(GEAR_TOKEN); // F:[AP-9]
    }

    /// @dev Sets address of GEAR token
    /// @param _address Address of GEAR token
    function setGearToken(address _address)
        external
        onlyOwner // F:[AP-12]
    {
        _setAddress(GEAR_TOKEN, _address); // F:[AP-9]
    }

    /// @return Address of WETH token
    function getWethToken() external view override returns (address) {
        return _getAddress(WETH_TOKEN); // F:[AP-10]
    }

    /// @dev Sets address of WETH token
    /// @param _address Address of WETH token
    function setWethToken(address _address)
        external
        onlyOwner // F:[AP-12]
    {
        _setAddress(WETH_TOKEN, _address); // F:[AP-10]
    }

    /// @return Address of WETH token
    function getWETHGateway() external view override returns (address) {
        return _getAddress(WETH_GATEWAY); // F:[AP-11]
    }

    /// @dev Sets address of WETH token
    /// @param _address Address of WETH token
    function setWETHGateway(address _address)
        external
        onlyOwner // F:[AP-12]
    {
        _setAddress(WETH_GATEWAY, _address); // F:[AP-11]
    }

    /// @return Address of PathFinder
    function getLeveragedActions() external view returns (address) {
        return _getAddress(LEVERAGED_ACTIONS); // T:[AP-7]
    }

    /// @dev Sets address of  PathFinder
    /// @param _address Address of  PathFinder
    function setLeveragedActions(address _address)
        external
        onlyOwner // T:[AP-15]
    {
        _setAddress(LEVERAGED_ACTIONS, _address); // T:[AP-7]
    }

    /// @return Address of key, reverts if the key doesn't exist
    function _getAddress(bytes32 key) internal view returns (address) {
        address result = addresses[key];
        require(result != address(0), Errors.AS_ADDRESS_NOT_FOUND); // F:[AP-1]
        return result; // F:[AP-3, 4, 5, 6, 7, 8, 9, 10, 11]
    }

    /// @dev Sets address to map by its key
    /// @param key Key in string format
    /// @param value Address
    function _setAddress(bytes32 key, address value) internal {
        addresses[key] = value; // F:[AP-3, 4, 5, 6, 7, 8, 9, 10, 11]
        emit AddressSet(key, value); // F:[AP-2]
    }
}

File 5 of 27 : IAdapter.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

import { IACL } from "../IACL.sol";
import { IAddressProvider } from "../IAddressProvider.sol";
import { ICreditManagerV2 } from "../ICreditManagerV2.sol";

// NOTE: new values must always be added at the end of the enum

enum AdapterType {
    ABSTRACT,
    UNISWAP_V2_ROUTER,
    UNISWAP_V3_ROUTER,
    CURVE_V1_EXCHANGE_ONLY,
    YEARN_V2,
    CURVE_V1_2ASSETS,
    CURVE_V1_3ASSETS,
    CURVE_V1_4ASSETS,
    CURVE_V1_STECRV_POOL,
    CURVE_V1_WRAPPER,
    CONVEX_V1_BASE_REWARD_POOL,
    CONVEX_V1_BOOSTER,
    CONVEX_V1_CLAIM_ZAP,
    LIDO_V1,
    UNIVERSAL,
    LIDO_WSTETH_V1,
    BALANCER_VAULT,
    AAVE_V2_LENDING_POOL,
    AAVE_V2_WRAPPED_ATOKEN,
    COMPOUND_V2_CERC20,
    COMPOUND_V2_CETHER
}

interface IAdapterExceptions {
    /// @notice Thrown when adapter tries to use a token that's not a collateral token of the connected Credit Manager
    error TokenNotAllowedException();

    /// @notice Thrown when caller of a `creditFacadeOnly` function is not the Credit Facade
    error CreditFacadeOnlyException();

    /// @notice Thrown when caller of a `configuratorOnly` function is not configurator
    error CallerNotConfiguratorException();
}

interface IAdapter is IAdapterExceptions {
    /// @notice Credit Manager the adapter is connected to
    function creditManager() external view returns (ICreditManagerV2);

    /// @notice Address of the contract the adapter is interacting with
    function targetContract() external view returns (address);

    /// @notice Address provider
    function addressProvider() external view returns (IAddressProvider);

    /// @notice ACL contract to check rights
    function _acl() external view returns (IACL);

    /// @notice Adapter type
    function _gearboxAdapterType() external pure returns (AdapterType);

    /// @notice Adapter version
    function _gearboxAdapterVersion() external pure returns (uint16);
}

File 6 of 27 : IACL.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;
import { IVersion } from "./IVersion.sol";

interface IACLExceptions {
    /// @dev Thrown when attempting to delete an address from a set that is not a pausable admin
    error AddressNotPausableAdminException(address addr);

    /// @dev Thrown when attempting to delete an address from a set that is not a unpausable admin
    error AddressNotUnpausableAdminException(address addr);
}

interface IACLEvents {
    /// @dev Emits when a new admin is added that can pause contracts
    event PausableAdminAdded(address indexed newAdmin);

    /// @dev Emits when a Pausable admin is removed
    event PausableAdminRemoved(address indexed admin);

    /// @dev Emits when a new admin is added that can unpause contracts
    event UnpausableAdminAdded(address indexed newAdmin);

    /// @dev Emits when an Unpausable admin is removed
    event UnpausableAdminRemoved(address indexed admin);
}

/// @title ACL interface
interface IACL is IACLEvents, IACLExceptions, IVersion {
    /// @dev Returns true if the address is a pausable admin and false if not
    /// @param addr Address to check
    function isPausableAdmin(address addr) external view returns (bool);

    /// @dev Returns true if the address is unpausable admin and false if not
    /// @param addr Address to check
    function isUnpausableAdmin(address addr) external view returns (bool);

    /// @dev Returns true if an address has configurator rights
    /// @param account Address to check
    function isConfigurator(address account) external view returns (bool);

    /// @dev Returns address of configurator
    function owner() external view returns (address);
}

File 7 of 27 : IAddressProvider.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;
import { IVersion } from "./IVersion.sol";

interface IAddressProviderEvents {
    /// @dev Emits when an address is set for a contract role
    event AddressSet(bytes32 indexed service, address indexed newAddress);
}

/// @title Optimised for front-end Address Provider interface
interface IAddressProvider is IAddressProviderEvents, IVersion {
    /// @return Address of ACL contract
    function getACL() external view returns (address);

    /// @return Address of ContractsRegister
    function getContractsRegister() external view returns (address);

    /// @return Address of AccountFactory
    function getAccountFactory() external view returns (address);

    /// @return Address of DataCompressor
    function getDataCompressor() external view returns (address);

    /// @return Address of GEAR token
    function getGearToken() external view returns (address);

    /// @return Address of WETH token
    function getWethToken() external view returns (address);

    /// @return Address of WETH Gateway
    function getWETHGateway() external view returns (address);

    /// @return Address of PriceOracle
    function getPriceOracle() external view returns (address);

    /// @return Address of DAO Treasury Multisig
    function getTreasuryContract() external view returns (address);

    /// @return Address of PathFinder
    function getLeveragedActions() external view returns (address);
}

File 8 of 27 : ICreditManagerV2.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

import { IPriceOracleV2 } from "./IPriceOracle.sol";
import { IVersion } from "./IVersion.sol";

enum ClosureAction {
    CLOSE_ACCOUNT,
    LIQUIDATE_ACCOUNT,
    LIQUIDATE_EXPIRED_ACCOUNT,
    LIQUIDATE_PAUSED
}

interface ICreditManagerV2Events {
    /// @dev Emits when a call to an external contract is made through the Credit Manager
    event ExecuteOrder(address indexed borrower, address indexed target);

    /// @dev Emits when a configurator is upgraded
    event NewConfigurator(address indexed newConfigurator);
}

interface ICreditManagerV2Exceptions {
    /// @dev Thrown if an access-restricted function is called by an address that is not
    ///      the connected Credit Facade, or an allowed adapter
    error AdaptersOrCreditFacadeOnlyException();

    /// @dev Thrown if an access-restricted function is called by an address that is not
    ///      the connected Credit Facade
    error CreditFacadeOnlyException();

    /// @dev Thrown if an access-restricted function is called by an address that is not
    ///      the connected Credit Configurator
    error CreditConfiguratorOnlyException();

    /// @dev Thrown on attempting to open a Credit Account for or transfer a Credit Account
    ///      to the zero address or an address that already owns a Credit Account
    error ZeroAddressOrUserAlreadyHasAccountException();

    /// @dev Thrown on attempting to execute an order to an address that is not an allowed
    ///      target contract
    error TargetContractNotAllowedException();

    /// @dev Thrown on failing a full collateral check after an operation
    error NotEnoughCollateralException();

    /// @dev Thrown on attempting to receive a token that is not a collateral token
    ///      or was forbidden
    error TokenNotAllowedException();

    /// @dev Thrown if an attempt to approve a collateral token to a target contract failed
    error AllowanceFailedException();

    /// @dev Thrown on attempting to perform an action for an address that owns no Credit Account
    error HasNoOpenedAccountException();

    /// @dev Thrown on attempting to add a token that is already in a collateral list
    error TokenAlreadyAddedException();

    /// @dev Thrown on configurator attempting to add more than 256 collateral tokens
    error TooManyTokensException();

    /// @dev Thrown if more than the maximal number of tokens were enabled on a Credit Account,
    ///      and there are not enough unused token to disable
    error TooManyEnabledTokensException();

    /// @dev Thrown when a reentrancy into the contract is attempted
    error ReentrancyLockException();
}

/// @notice All Credit Manager functions are access-restricted and can only be called
///         by the Credit Facade or allowed adapters. Users are not allowed to
///         interact with the Credit Manager directly
interface ICreditManagerV2 is
    ICreditManagerV2Events,
    ICreditManagerV2Exceptions,
    IVersion
{
    //
    // CREDIT ACCOUNT MANAGEMENT
    //

    ///  @dev Opens credit account and borrows funds from the pool.
    /// - Takes Credit Account from the factory;
    /// - Requests the pool to lend underlying to the Credit Account
    ///
    /// @param borrowedAmount Amount to be borrowed by the Credit Account
    /// @param onBehalfOf The owner of the newly opened Credit Account
    function openCreditAccount(uint256 borrowedAmount, address onBehalfOf)
        external
        returns (address);

    ///  @dev Closes a Credit Account - covers both normal closure and liquidation
    /// - Checks whether the contract is paused, and, if so, if the payer is an emergency liquidator.
    ///   Only emergency liquidators are able to liquidate account while the CM is paused.
    ///   Emergency liquidations do not pay a liquidator premium or liquidation fees.
    /// - Calculates payments to various recipients on closure:
    ///    + Computes amountToPool, which is the amount to be sent back to the pool.
    ///      This includes the principal, interest and fees, but can't be more than
    ///      total position value
    ///    + Computes remainingFunds during liquidations - these are leftover funds
    ///      after paying the pool and the liquidator, and are sent to the borrower
    ///    + Computes protocol profit, which includes interest and liquidation fees
    ///    + Computes loss if the totalValue is less than borrow amount + interest
    /// - Checks the underlying token balance:
    ///    + if it is larger than amountToPool, then the pool is paid fully from funds on the Credit Account
    ///    + else tries to transfer the shortfall from the payer - either the borrower during closure, or liquidator during liquidation
    /// - Send assets to the "to" address, as long as they are not included into skipTokenMask
    /// - If convertWETH is true, the function converts WETH into ETH before sending
    /// - Returns the Credit Account back to factory
    ///
    /// @param borrower Borrower address
    /// @param closureActionType Whether the account is closed, liquidated or liquidated due to expiry
    /// @param totalValue Portfolio value for liqution, 0 for ordinary closure
    /// @param payer Address which would be charged if credit account has not enough funds to cover amountToPool
    /// @param to Address to which the leftover funds will be sent
    /// @param skipTokenMask Tokenmask contains 1 for tokens which needed to be skipped for sending
    /// @param convertWETH If true converts WETH to ETH
    function closeCreditAccount(
        address borrower,
        ClosureAction closureActionType,
        uint256 totalValue,
        address payer,
        address to,
        uint256 skipTokenMask,
        bool convertWETH
    ) external returns (uint256 remainingFunds);

    /// @dev Manages debt size for borrower:
    ///
    /// - Increase debt:
    ///   + Increases debt by transferring funds from the pool to the credit account
    ///   + Updates the cumulative index to keep interest the same. Since interest
    ///     is always computed dynamically as borrowedAmount * (cumulativeIndexNew / cumulativeIndexOpen - 1),
    ///     cumulativeIndexOpen needs to be updated, as the borrow amount has changed
    ///
    /// - Decrease debt:
    ///   + Repays debt partially + all interest and fees accrued thus far
    ///   + Updates cunulativeIndex to cumulativeIndex now
    ///
    /// @param creditAccount Address of the Credit Account to change debt for
    /// @param amount Amount to increase / decrease the principal by
    /// @param increase True to increase principal, false to decrease
    /// @return newBorrowedAmount The new debt principal
    function manageDebt(
        address creditAccount,
        uint256 amount,
        bool increase
    ) external returns (uint256 newBorrowedAmount);

    /// @dev Adds collateral to borrower's credit account
    /// @param payer Address of the account which will be charged to provide additional collateral
    /// @param creditAccount Address of the Credit Account
    /// @param token Collateral token to add
    /// @param amount Amount to add
    function addCollateral(
        address payer,
        address creditAccount,
        address token,
        uint256 amount
    ) external;

    /// @dev Transfers Credit Account ownership to another address
    /// @param from Address of previous owner
    /// @param to Address of new owner
    function transferAccountOwnership(address from, address to) external;

    /// @dev Requests the Credit Account to approve a collateral token to another contract.
    /// @param borrower Borrower's address
    /// @param targetContract Spender to change allowance for
    /// @param token Collateral token to approve
    /// @param amount New allowance amount
    function approveCreditAccount(
        address borrower,
        address targetContract,
        address token,
        uint256 amount
    ) external;

    /// @dev Requests a Credit Account to make a low-level call with provided data
    /// This is the intended pathway for state-changing interactions with 3rd-party protocols
    /// @param borrower Borrower's address
    /// @param targetContract Contract to be called
    /// @param data Data to pass with the call
    function executeOrder(
        address borrower,
        address targetContract,
        bytes memory data
    ) external returns (bytes memory);

    //
    // COLLATERAL VALIDITY AND ACCOUNT HEALTH CHECKS
    //

    /// @dev Enables a token on a Credit Account, including it
    /// into account health and total value calculations
    /// @param creditAccount Address of a Credit Account to enable the token for
    /// @param token Address of the token to be enabled
    function checkAndEnableToken(address creditAccount, address token) external;

    /// @dev Optimized health check for individual swap-like operations.
    /// @notice Fast health check assumes that only two tokens (input and output)
    ///         participate in the operation and computes a % change in weighted value between
    ///         inbound and outbound collateral. The cumulative negative change across several
    ///         swaps in sequence cannot be larger than feeLiquidation (a fee that the
    ///         protocol is ready to waive if needed). Since this records a % change
    ///         between just two tokens, the corresponding % change in TWV will always be smaller,
    ///         which makes this check safe.
    ///         More details at https://dev.gearbox.fi/docs/documentation/risk/fast-collateral-check#fast-check-protection
    /// @param creditAccount Address of the Credit Account
    /// @param tokenIn Address of the token spent by the swap
    /// @param tokenOut Address of the token received from the swap
    /// @param balanceInBefore Balance of tokenIn before the operation
    /// @param balanceOutBefore Balance of tokenOut before the operation
    function fastCollateralCheck(
        address creditAccount,
        address tokenIn,
        address tokenOut,
        uint256 balanceInBefore,
        uint256 balanceOutBefore
    ) external;

    /// @dev Performs a full health check on an account, summing up
    /// value of all enabled collateral tokens
    /// @param creditAccount Address of the Credit Account to check
    function fullCollateralCheck(address creditAccount) external;

    /// @dev Checks that the number of enabled tokens on a Credit Account
    ///      does not violate the maximal enabled token limit and tries
    ///      to disable unused tokens if it does
    /// @param creditAccount Account to check enabled tokens for
    function checkAndOptimizeEnabledTokens(address creditAccount) external;

    /// @dev Disables a token on a credit account
    /// @notice Usually called by adapters to disable spent tokens during a multicall,
    ///         but can also be called separately from the Credit Facade to remove
    ///         unwanted tokens
    /// @return True if token mask was change otherwise False
    function disableToken(address creditAccount, address token)
        external
        returns (bool);

    //
    // GETTERS
    //

    /// @dev Returns the address of a borrower's Credit Account, or reverts if there is none.
    /// @param borrower Borrower's address
    function getCreditAccountOrRevert(address borrower)
        external
        view
        returns (address);

    /// @dev Computes amounts that must be sent to various addresses before closing an account
    /// @param totalValue Credit Accounts total value in underlying
    /// @param closureActionType Type of account closure
    ///        * CLOSE_ACCOUNT: The account is healthy and is closed normally
    ///        * LIQUIDATE_ACCOUNT: The account is unhealthy and is being liquidated to avoid bad debt
    ///        * LIQUIDATE_EXPIRED_ACCOUNT: The account has expired and is being liquidated (lowered liquidation premium)
    ///        * LIQUIDATE_PAUSED: The account is liquidated while the system is paused due to emergency (no liquidation premium)
    /// @param borrowedAmount Credit Account's debt principal
    /// @param borrowedAmountWithInterest Credit Account's debt principal + interest
    /// @return amountToPool Amount of underlying to be sent to the pool
    /// @return remainingFunds Amount of underlying to be sent to the borrower (only applicable to liquidations)
    /// @return profit Protocol's profit from fees (if any)
    /// @return loss Protocol's loss from bad debt (if any)
    function calcClosePayments(
        uint256 totalValue,
        ClosureAction closureActionType,
        uint256 borrowedAmount,
        uint256 borrowedAmountWithInterest
    )
        external
        view
        returns (
            uint256 amountToPool,
            uint256 remainingFunds,
            uint256 profit,
            uint256 loss
        );

    /// @dev Calculates the debt accrued by a Credit Account
    /// @param creditAccount Address of the Credit Account
    /// @return borrowedAmount The debt principal
    /// @return borrowedAmountWithInterest The debt principal + accrued interest
    /// @return borrowedAmountWithInterestAndFees The debt principal + accrued interest and protocol fees
    function calcCreditAccountAccruedInterest(address creditAccount)
        external
        view
        returns (
            uint256 borrowedAmount,
            uint256 borrowedAmountWithInterest,
            uint256 borrowedAmountWithInterestAndFees
        );

    /// @dev Maps Credit Accounts to bit masks encoding their enabled token sets
    /// Only enabled tokens are counted as collateral for the Credit Account
    /// @notice An enabled token mask encodes an enabled token by setting
    ///         the bit at the position equal to token's index to 1
    function enabledTokensMap(address creditAccount)
        external
        view
        returns (uint256);

    /// @dev Maps the Credit Account to its current percentage drop across all swaps since
    ///      the last full check, in RAY format
    function cumulativeDropAtFastCheckRAY(address creditAccount)
        external
        view
        returns (uint256);

    /// @dev Returns the collateral token at requested index and its liquidation threshold
    /// @param id The index of token to return
    function collateralTokens(uint256 id)
        external
        view
        returns (address token, uint16 liquidationThreshold);

    /// @dev Returns the collateral token with requested mask and its liquidationThreshold
    /// @param tokenMask Token mask corresponding to the token
    function collateralTokensByMask(uint256 tokenMask)
        external
        view
        returns (address token, uint16 liquidationThreshold);

    /// @dev Total number of known collateral tokens.
    function collateralTokensCount() external view returns (uint256);

    /// @dev Returns the mask for the provided token
    /// @param token Token to returns the mask for
    function tokenMasksMap(address token) external view returns (uint256);

    /// @dev Bit mask encoding a set of forbidden tokens
    function forbiddenTokenMask() external view returns (uint256);

    /// @dev Maps allowed adapters to their respective target contracts.
    function adapterToContract(address adapter) external view returns (address);

    /// @dev Maps 3rd party contracts to their respective adapters
    function contractToAdapter(address targetContract)
        external
        view
        returns (address);

    /// @dev Address of the underlying asset
    function underlying() external view returns (address);

    /// @dev Address of the connected pool
    function pool() external view returns (address);

    /// @dev Address of the connected pool
    /// @notice [DEPRECATED]: use pool() instead.
    function poolService() external view returns (address);

    /// @dev A map from borrower addresses to Credit Account addresses
    function creditAccounts(address borrower) external view returns (address);

    /// @dev Address of the connected Credit Configurator
    function creditConfigurator() external view returns (address);

    /// @dev Address of WETH
    function wethAddress() external view returns (address);

    /// @dev Returns the liquidation threshold for the provided token
    /// @param token Token to retrieve the LT for
    function liquidationThresholds(address token)
        external
        view
        returns (uint16);

    /// @dev The maximal number of enabled tokens on a single Credit Account
    function maxAllowedEnabledTokenLength() external view returns (uint8);

    /// @dev Maps addresses to their status as emergency liquidator.
    /// @notice Emergency liquidators are trusted addresses
    /// that are able to liquidate positions while the contracts are paused,
    /// e.g. when there is a risk of bad debt while an exploit is being patched.
    /// In the interest of fairness, emergency liquidators do not receive a premium
    /// And are compensated by the Gearbox DAO separately.
    function canLiquidateWhilePaused(address) external view returns (bool);

    /// @dev Returns the fee parameters of the Credit Manager
    /// @return feeInterest Percentage of interest taken by the protocol as profit
    /// @return feeLiquidation Percentage of account value taken by the protocol as profit
    ///         during unhealthy account liquidations
    /// @return liquidationDiscount Multiplier that reduces the effective totalValue during unhealthy account liquidations,
    ///         allowing the liquidator to take the unaccounted for remainder as premium. Equal to (1 - liquidationPremium)
    /// @return feeLiquidationExpired Percentage of account value taken by the protocol as profit
    ///         during expired account liquidations
    /// @return liquidationDiscountExpired Multiplier that reduces the effective totalValue during expired account liquidations,
    ///         allowing the liquidator to take the unaccounted for remainder as premium. Equal to (1 - liquidationPremiumExpired)
    function fees()
        external
        view
        returns (
            uint16 feeInterest,
            uint16 feeLiquidation,
            uint16 liquidationDiscount,
            uint16 feeLiquidationExpired,
            uint16 liquidationDiscountExpired
        );

    /// @dev Address of the connected Credit Facade
    function creditFacade() external view returns (address);

    /// @dev Address of the connected Price Oracle
    function priceOracle() external view returns (IPriceOracleV2);

    /// @dev Address of the universal adapter
    function universalAdapter() external view returns (address);

    /// @dev Contract's version
    function version() external view returns (uint256);

    /// @dev Paused() state
    function checkEmergencyPausable(address caller, bool state)
        external
        returns (bool);
}

File 9 of 27 : IErrors.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

/// @dev Common contract exceptions

/// @dev Thrown on attempting to set an important address to zero address
error ZeroAddressException();

/// @dev Thrown on attempting to call a non-implemented function
error NotImplementedException();

/// @dev Thrown on attempting to set an EOA as an important contract in the system
error AddressIsNotContractException(address);

/// @dev Thrown on attempting to use a non-ERC20 contract or an EOA as a token
error IncorrectTokenContractException();

/// @dev Thrown on attempting to set a token price feed to an address that is not a
///      correct price feed
error IncorrectPriceFeedException();

/// @dev Thrown on attempting to call an access restricted function as a non-Configurator
error CallerNotConfiguratorException();

/// @dev Thrown on attempting to call an access restricted function as a non-Configurator
error CallerNotControllerException();

/// @dev Thrown on attempting to pause a contract as a non-Pausable admin
error CallerNotPausableAdminException();

/// @dev Thrown on attempting to pause a contract as a non-Unpausable admin
error CallerNotUnPausableAdminException();

File 10 of 27 : IPoolService.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;
import "../core/AddressProvider.sol";
import { IVersion } from "./IVersion.sol";

interface IPoolServiceEvents {
    /// @dev Emits on new liquidity being added to the pool
    event AddLiquidity(
        address indexed sender,
        address indexed onBehalfOf,
        uint256 amount,
        uint256 referralCode
    );

    /// @dev Emits on liquidity being removed to the pool
    event RemoveLiquidity(
        address indexed sender,
        address indexed to,
        uint256 amount
    );

    /// @dev Emits on a Credit Manager borrowing funds for a Credit Account
    event Borrow(
        address indexed creditManager,
        address indexed creditAccount,
        uint256 amount
    );

    /// @dev Emits on repayment of a Credit Account's debt
    event Repay(
        address indexed creditManager,
        uint256 borrowedAmount,
        uint256 profit,
        uint256 loss
    );

    /// @dev Emits on updating the interest rate model
    event NewInterestRateModel(address indexed newInterestRateModel);

    /// @dev Emits on connecting a new Credit Manager
    event NewCreditManagerConnected(address indexed creditManager);

    /// @dev Emits when a Credit Manager is forbidden to borrow
    event BorrowForbidden(address indexed creditManager);

    /// @dev Emitted when loss is incurred that can't be covered by treasury funds
    event UncoveredLoss(address indexed creditManager, uint256 loss);

    /// @dev Emits when the liquidity limit is changed
    event NewExpectedLiquidityLimit(uint256 newLimit);

    /// @dev Emits when the withdrawal fee is changed
    event NewWithdrawFee(uint256 fee);
}

/// @title Pool Service Interface
/// @notice Implements business logic:
///   - Adding/removing pool liquidity
///   - Managing diesel tokens & diesel rates
///   - Taking/repaying Credit Manager debt
/// More: https://dev.gearbox.fi/developers/pool/abstractpoolservice
interface IPoolService is IPoolServiceEvents, IVersion {
    //
    // LIQUIDITY MANAGEMENT
    //

    /**
     * @dev Adds liquidity to pool
     * - transfers the underlying to the pool
     * - mints Diesel (LP) tokens to onBehalfOf
     * @param amount Amount of tokens to be deposited
     * @param onBehalfOf The address that will receive the dToken
     * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
     *   0 if the action is executed directly by the user, without a facilitator.
     */
    function addLiquidity(
        uint256 amount,
        address onBehalfOf,
        uint256 referralCode
    ) external;

    /**
     * @dev Removes liquidity from pool
     * - burns LP's Diesel (LP) tokens
     * - returns the equivalent amount of underlying to 'to'
     * @param amount Amount of Diesel tokens to burn
     * @param to Address to transfer the underlying to
     */

    function removeLiquidity(uint256 amount, address to)
        external
        returns (uint256);

    /**
     * @dev Lends pool funds to a Credit Account
     * @param borrowedAmount Credit Account's debt principal
     * @param creditAccount Credit Account's address
     */
    function lendCreditAccount(uint256 borrowedAmount, address creditAccount)
        external;

    /**
     * @dev Repays the Credit Account's debt
     * @param borrowedAmount Amount of principal ro repay
     * @param profit The treasury profit from repayment
     * @param loss Amount of underlying that the CA wan't able to repay
     * @notice Assumes that the underlying (including principal + interest + fees)
     *         was already transferred
     */
    function repayCreditAccount(
        uint256 borrowedAmount,
        uint256 profit,
        uint256 loss
    ) external;

    //
    // GETTERS
    //

    /**
     * @dev Returns the total amount of liquidity in the pool, including borrowed and available funds
     */
    function expectedLiquidity() external view returns (uint256);

    /**
     * @dev Returns the limit on total liquidity
     */
    function expectedLiquidityLimit() external view returns (uint256);

    /**
     * @dev Returns the available liquidity, which is expectedLiquidity - totalBorrowed
     */
    function availableLiquidity() external view returns (uint256);

    /**
     * @dev Calculates the current interest index, RAY format
     */
    function calcLinearCumulative_RAY() external view returns (uint256);

    /**
     * @dev Calculates the current borrow rate, RAY format
     */
    function borrowAPY_RAY() external view returns (uint256);

    /**
     * @dev Returns the total borrowed amount (includes principal only)
     */
    function totalBorrowed() external view returns (uint256);

    /**
     * ç
     **/

    function getDieselRate_RAY() external view returns (uint256);

    /**
     * @dev Returns the address of the underlying
     */
    function underlyingToken() external view returns (address);

    /**
     * @dev Returns the address of the diesel token
     */
    function dieselToken() external view returns (address);

    /**
     * @dev Returns the address of a Credit Manager by its id
     */
    function creditManagers(uint256 id) external view returns (address);

    /**
     * @dev Returns the number of known Credit Managers
     */
    function creditManagersCount() external view returns (uint256);

    /**
     * @dev Maps Credit Manager addresses to their status as a borrower.
     *      Returns false if borrowing is not allowed.
     */
    function creditManagersCanBorrow(address id) external view returns (bool);

    /// @dev Converts a quantity of the underlying to Diesel tokens
    function toDiesel(uint256 amount) external view returns (uint256);

    /// @dev Converts a quantity of Diesel tokens to the underlying
    function fromDiesel(uint256 amount) external view returns (uint256);

    /// @dev Returns the withdrawal fee
    function withdrawFee() external view returns (uint256);

    /// @dev Returns the timestamp of the pool's last update
    function _timestampLU() external view returns (uint256);

    /// @dev Returns the interest index at the last pool update
    function _cumulativeIndex_RAY() external view returns (uint256);

    /// @dev Returns the address provider
    function addressProvider() external view returns (AddressProvider);
}

File 11 of 27 : IPriceOracle.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;
import { IVersion } from "./IVersion.sol";

interface IPriceOracleV2Events {
    /// @dev Emits when a new price feed is added
    event NewPriceFeed(address indexed token, address indexed priceFeed);
}

interface IPriceOracleV2Exceptions {
    /// @dev Thrown if a price feed returns 0
    error ZeroPriceException();

    /// @dev Thrown if the last recorded result was not updated in the last round
    error ChainPriceStaleException();

    /// @dev Thrown on attempting to get a result for a token that does not have a price feed
    error PriceOracleNotExistsException();
}

/// @title Price oracle interface
interface IPriceOracleV2 is
    IPriceOracleV2Events,
    IPriceOracleV2Exceptions,
    IVersion
{
    /// @dev Converts a quantity of an asset to USD (decimals = 8).
    /// @param amount Amount to convert
    /// @param token Address of the token to be converted
    function convertToUSD(uint256 amount, address token)
        external
        view
        returns (uint256);

    /// @dev Converts a quantity of USD (decimals = 8) to an equivalent amount of an asset
    /// @param amount Amount to convert
    /// @param token Address of the token converted to
    function convertFromUSD(uint256 amount, address token)
        external
        view
        returns (uint256);

    /// @dev Converts one asset into another
    ///
    /// @param amount Amount to convert
    /// @param tokenFrom Address of the token to convert from
    /// @param tokenTo Address of the token to convert to
    function convert(
        uint256 amount,
        address tokenFrom,
        address tokenTo
    ) external view returns (uint256);

    /// @dev Returns collateral values for two tokens, required for a fast check
    /// @param amountFrom Amount of the outbound token
    /// @param tokenFrom Address of the outbound token
    /// @param amountTo Amount of the inbound token
    /// @param tokenTo Address of the inbound token
    /// @return collateralFrom Value of the outbound token amount in USD
    /// @return collateralTo Value of the inbound token amount in USD
    function fastCheck(
        uint256 amountFrom,
        address tokenFrom,
        uint256 amountTo,
        address tokenTo
    ) external view returns (uint256 collateralFrom, uint256 collateralTo);

    /// @dev Returns token's price in USD (8 decimals)
    /// @param token The token to compute the price for
    function getPrice(address token) external view returns (uint256);

    /// @dev Returns the price feed address for the passed token
    /// @param token Token to get the price feed for
    function priceFeeds(address token)
        external
        view
        returns (address priceFeed);

    /// @dev Returns the price feed for the passed token,
    ///      with additional parameters
    /// @param token Token to get the price feed for
    function priceFeedsWithFlags(address token)
        external
        view
        returns (
            address priceFeed,
            bool skipCheck,
            uint256 decimals
        );
}

interface IPriceOracleV2Ext is IPriceOracleV2 {
    /// @dev Sets a price feed if it doesn't exist, or updates an existing one
    /// @param token Address of the token to set the price feed for
    /// @param priceFeed Address of a USD price feed adhering to Chainlink's interface
    function addPriceFeed(address token, address priceFeed) external;
}

File 12 of 27 : IVersion.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

/// @title IVersion
/// @dev Declares a version function which returns the contract's version
interface IVersion {
    /// @dev Returns contract version
    function version() external view returns (uint256);
}

File 13 of 27 : Constants.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

// Denominations

uint256 constant WAD = 1e18;
uint256 constant RAY = 1e27;

// 25% of type(uint256).max
uint256 constant ALLOWANCE_THRESHOLD = type(uint96).max >> 3;

// FEE = 50%
uint16 constant DEFAULT_FEE_INTEREST = 50_00; // 50%

// LIQUIDATION_FEE 1.5%
uint16 constant DEFAULT_FEE_LIQUIDATION = 1_50; // 1.5%

// LIQUIDATION PREMIUM 4%
uint16 constant DEFAULT_LIQUIDATION_PREMIUM = 4_00; // 4%

// LIQUIDATION_FEE_EXPIRED 2%
uint16 constant DEFAULT_FEE_LIQUIDATION_EXPIRED = 1_00; // 2%

// LIQUIDATION PREMIUM EXPIRED 2%
uint16 constant DEFAULT_LIQUIDATION_PREMIUM_EXPIRED = 2_00; // 2%

// DEFAULT PROPORTION OF MAX BORROWED PER BLOCK TO MAX BORROWED PER ACCOUNT
uint16 constant DEFAULT_LIMIT_PER_BLOCK_MULTIPLIER = 2;

// Seconds in a year
uint256 constant SECONDS_PER_YEAR = 365 days;
uint256 constant SECONDS_PER_ONE_AND_HALF_YEAR = (SECONDS_PER_YEAR * 3) / 2;

// OPERATIONS

// Leverage decimals - 100 is equal to 2x leverage (100% * collateral amount + 100% * borrowed amount)
uint8 constant LEVERAGE_DECIMALS = 100;

// Maximum withdraw fee for pool in PERCENTAGE_FACTOR format
uint8 constant MAX_WITHDRAW_FEE = 100;

uint256 constant EXACT_INPUT = 1;
uint256 constant EXACT_OUTPUT = 2;

address constant UNIVERSAL_CONTRACT = 0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC;

File 14 of 27 : Errors.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

/// @title Errors library
library Errors {
    //
    // COMMON
    //
    string public constant ZERO_ADDRESS_IS_NOT_ALLOWED = "Z0";
    string public constant NOT_IMPLEMENTED = "NI";
    string public constant INCORRECT_PATH_LENGTH = "PL";
    string public constant INCORRECT_ARRAY_LENGTH = "CR";
    string public constant REGISTERED_CREDIT_ACCOUNT_MANAGERS_ONLY = "CP";
    string public constant REGISTERED_POOLS_ONLY = "RP";
    string public constant INCORRECT_PARAMETER = "IP";

    //
    // MATH
    //
    string public constant MATH_MULTIPLICATION_OVERFLOW = "M1";
    string public constant MATH_ADDITION_OVERFLOW = "M2";
    string public constant MATH_DIVISION_BY_ZERO = "M3";

    //
    // POOL
    //
    string public constant POOL_CONNECTED_CREDIT_MANAGERS_ONLY = "PS0";
    string public constant POOL_INCOMPATIBLE_CREDIT_ACCOUNT_MANAGER = "PS1";
    string public constant POOL_MORE_THAN_EXPECTED_LIQUIDITY_LIMIT = "PS2";
    string public constant POOL_INCORRECT_WITHDRAW_FEE = "PS3";
    string public constant POOL_CANT_ADD_CREDIT_MANAGER_TWICE = "PS4";

    //
    // ACCOUNT FACTORY
    //
    string public constant AF_CANT_CLOSE_CREDIT_ACCOUNT_IN_THE_SAME_BLOCK =
        "AF1";
    string public constant AF_MINING_IS_FINISHED = "AF2";
    string public constant AF_CREDIT_ACCOUNT_NOT_IN_STOCK = "AF3";
    string public constant AF_EXTERNAL_ACCOUNTS_ARE_FORBIDDEN = "AF4";

    //
    // ADDRESS PROVIDER
    //
    string public constant AS_ADDRESS_NOT_FOUND = "AP1";

    //
    // CONTRACTS REGISTER
    //
    string public constant CR_POOL_ALREADY_ADDED = "CR1";
    string public constant CR_CREDIT_MANAGER_ALREADY_ADDED = "CR2";

    //
    // CREDIT ACCOUNT
    //
    string public constant CA_CONNECTED_CREDIT_MANAGER_ONLY = "CA1";
    string public constant CA_FACTORY_ONLY = "CA2";

    //
    // ACL
    //
    string public constant ACL_CALLER_NOT_PAUSABLE_ADMIN = "ACL1";
    string public constant ACL_CALLER_NOT_CONFIGURATOR = "ACL2";

    //
    // WETH GATEWAY
    //
    string public constant WG_DESTINATION_IS_NOT_WETH_COMPATIBLE = "WG1";
    string public constant WG_RECEIVE_IS_NOT_ALLOWED = "WG2";
    string public constant WG_NOT_ENOUGH_FUNDS = "WG3";

    //
    // TOKEN DISTRIBUTOR
    //
    string public constant TD_WALLET_IS_ALREADY_CONNECTED_TO_VC = "TD1";
    string public constant TD_INCORRECT_WEIGHTS = "TD2";
    string public constant TD_NON_ZERO_BALANCE_AFTER_DISTRIBUTION = "TD3";
    string public constant TD_CONTRIBUTOR_IS_NOT_REGISTERED = "TD4";
}

File 15 of 27 : AbstractAdapter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2023
pragma solidity ^0.8.17;

import {AbstractAdapter} from "@gearbox-protocol/core-v2/contracts/adapters/AbstractAdapter.sol";

File 16 of 27 : CurveV1_Base.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2023
pragma solidity ^0.8.17;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";

import {ZeroAddressException} from "@gearbox-protocol/core-v2/contracts/interfaces/IErrors.sol";
import {RAY} from "@gearbox-protocol/core-v2/contracts/libraries/Constants.sol";

import {AbstractAdapter} from "../AbstractAdapter.sol";
import {AdapterType} from "../../interfaces/IAdapter.sol";

import {ICurvePool} from "../../integrations/curve/ICurvePool.sol";
import {ICurvePool2Assets} from "../../integrations/curve/ICurvePool_2.sol";
import {ICurvePool3Assets} from "../../integrations/curve/ICurvePool_3.sol";
import {ICurvePool4Assets} from "../../integrations/curve/ICurvePool_4.sol";

import {ICurveV1Adapter} from "../../interfaces/curve/ICurveV1Adapter.sol";

uint256 constant ZERO = 0;

/// @title Curve V1 base adapter
/// @notice Implements logic allowing to interact with all Curve pools, regardless of number of coins
contract CurveV1AdapterBase is AbstractAdapter, ICurveV1Adapter {
    using SafeCast for uint256;
    using SafeCast for int256;

    uint16 public constant override _gearboxAdapterVersion = 2;

    function _gearboxAdapterType() external pure virtual override returns (AdapterType) {
        return AdapterType.CURVE_V1_EXCHANGE_ONLY;
    }

    /// @inheritdoc ICurveV1Adapter
    address public immutable override token;

    /// @inheritdoc ICurveV1Adapter
    address public immutable override lp_token;

    /// @inheritdoc ICurveV1Adapter
    uint256 public immutable override lpTokenMask;

    /// @inheritdoc ICurveV1Adapter
    address public immutable override metapoolBase;

    /// @inheritdoc ICurveV1Adapter
    uint256 public immutable override nCoins;

    /// @inheritdoc ICurveV1Adapter
    bool public immutable override use256;

    /// @inheritdoc ICurveV1Adapter
    address public immutable token0;
    /// @inheritdoc ICurveV1Adapter
    address public immutable token1;
    /// @inheritdoc ICurveV1Adapter
    address public immutable token2;
    /// @inheritdoc ICurveV1Adapter
    address public immutable token3;

    /// @inheritdoc ICurveV1Adapter
    uint256 public immutable override token0Mask;
    /// @inheritdoc ICurveV1Adapter
    uint256 public immutable override token1Mask;
    /// @inheritdoc ICurveV1Adapter
    uint256 public immutable override token2Mask;
    /// @inheritdoc ICurveV1Adapter
    uint256 public immutable override token3Mask;

    /// @inheritdoc ICurveV1Adapter
    address public immutable override underlying0;
    /// @inheritdoc ICurveV1Adapter
    address public immutable override underlying1;
    /// @inheritdoc ICurveV1Adapter
    address public immutable override underlying2;
    /// @inheritdoc ICurveV1Adapter
    address public immutable override underlying3;

    /// @inheritdoc ICurveV1Adapter
    uint256 public immutable override underlying0Mask;
    /// @inheritdoc ICurveV1Adapter
    uint256 public immutable override underlying1Mask;
    /// @inheritdoc ICurveV1Adapter
    uint256 public immutable override underlying2Mask;
    /// @inheritdoc ICurveV1Adapter
    uint256 public immutable override underlying3Mask;

    /// @notice Constructor
    /// @param _creditManager Credit manager address
    /// @param _curvePool Target Curve pool address
    /// @param _lp_token Pool LP token address
    /// @param _metapoolBase Base pool address (for metapools only) or zero address
    /// @param _nCoins Number of coins in the pool
    constructor(address _creditManager, address _curvePool, address _lp_token, address _metapoolBase, uint256 _nCoins)
        AbstractAdapter(_creditManager, _curvePool)
    {
        if (_lp_token == address(0)) revert ZeroAddressException(); // F: [ACV1-1]

        lpTokenMask = _getMaskOrRevert(_lp_token); // F: [ACV1-2]

        token = _lp_token; // F: [ACV1-2]
        lp_token = _lp_token; // F: [ACV1-2]
        metapoolBase = _metapoolBase; // F: [ACV1-2]
        nCoins = _nCoins; // F: [ACV1-2]

        {
            bool _use256;

            /// Only Curve v2 pools have mid_fee, so it can be used to determine
            /// whether to use int128 or uint256 function signatures
            try ICurvePool(targetContract).mid_fee() returns (uint256) {
                _use256 = true;
            } catch {
                _use256 = false;
            }

            use256 = _use256;
        }

        address[4] memory tokens;
        uint256[4] memory tokenMasks;
        for (uint256 i = 0; i < nCoins;) {
            address currentCoin;
            try ICurvePool(targetContract).coins(i) returns (address tokenAddress) {
                currentCoin = tokenAddress;
            } catch {
                try ICurvePool(targetContract).coins(i.toInt256().toInt128()) returns (address tokenAddress) {
                    currentCoin = tokenAddress;
                } catch {}
            }

            if (currentCoin == address(0)) revert ZeroAddressException(); // F: [ACV1-1]
            uint256 currentMask = _getMaskOrRevert(currentCoin);

            tokens[i] = currentCoin;
            tokenMasks[i] = currentMask;

            unchecked {
                ++i;
            }
        }

        token0 = tokens[0]; // F: [ACV1-2]
        token1 = tokens[1]; // F: [ACV1-2]
        token2 = tokens[2]; // F: [ACV1-2]
        token3 = tokens[3]; // F: [ACV1-2]

        token0Mask = tokenMasks[0]; // F: [ACV1-2]
        token1Mask = tokenMasks[1]; // F: [ACV1-2]
        token2Mask = tokenMasks[2]; // F: [ACV1-2]
        token3Mask = tokenMasks[3]; // F: [ACV1-2]

        tokens = [address(0), address(0), address(0), address(0)];
        tokenMasks = [ZERO, ZERO, ZERO, ZERO];

        for (uint256 i = 0; i < 4;) {
            address currentCoin;
            uint256 currentMask;

            if (metapoolBase != address(0)) {
                if (i == 0) {
                    currentCoin = token0;
                } else {
                    try ICurvePool(metapoolBase).coins(i - 1) returns (address tokenAddress) {
                        currentCoin = tokenAddress;
                    } catch {}
                }
            } else {
                try ICurvePool(targetContract).underlying_coins(i) returns (address tokenAddress) {
                    currentCoin = tokenAddress;
                } catch {
                    try ICurvePool(targetContract).underlying_coins(i.toInt256().toInt128()) returns (
                        address tokenAddress
                    ) {
                        currentCoin = tokenAddress;
                    } catch {}
                }
            }

            if (currentCoin != address(0)) {
                currentMask = _getMaskOrRevert(currentCoin); // F: [ACV1-1]
            }

            tokens[i] = currentCoin;
            tokenMasks[i] = currentMask;

            unchecked {
                ++i;
            }
        }

        underlying0 = tokens[0]; // F: [ACV1-2]
        underlying1 = tokens[1]; // F: [ACV1-2]
        underlying2 = tokens[2]; // F: [ACV1-2]
        underlying3 = tokens[3]; // F: [ACV1-2]

        underlying0Mask = tokenMasks[0]; // F: [ACV1-2]
        underlying1Mask = tokenMasks[1]; // F: [ACV1-2]
        underlying2Mask = tokenMasks[2]; // F: [ACV1-2]
        underlying3Mask = tokenMasks[3]; // F: [ACV1-2]
    }

    /// -------- ///
    /// EXCHANGE ///
    /// -------- ///

    /// @inheritdoc ICurveV1Adapter
    function exchange(int128 i, int128 j, uint256, uint256) external override creditFacadeOnly {
        _exchange(i, j);
    }

    /// @inheritdoc ICurveV1Adapter
    function exchange(uint256 i, uint256 j, uint256, uint256) external override creditFacadeOnly {
        _exchange(i.toInt256().toInt128(), j.toInt256().toInt128());
    }

    /// @dev Internal implementation of `exchange`
    function _exchange(int128 i, int128 j) internal {
        _exchange_impl(i, j, msg.data, false, false); // F: [ACV1-4]
    }

    /// @inheritdoc ICurveV1Adapter
    function exchange_all(int128 i, int128 j, uint256 rateMinRAY) external override creditFacadeOnly {
        _exchange_all(i, j, rateMinRAY);
    }

    /// @inheritdoc ICurveV1Adapter
    function exchange_all(uint256 i, uint256 j, uint256 rateMinRAY) external override creditFacadeOnly {
        _exchange_all(i.toInt256().toInt128(), j.toInt256().toInt128(), rateMinRAY);
    }

    /// @dev Internal implementation of `exchange_all`
    function _exchange_all(int128 i, int128 j, uint256 rateMinRAY) internal {
        address creditAccount = _creditAccount(); // F: [ACV1-3]

        address tokenIn = _get_token(i, false); // F: [ACV1-5]
        uint256 dx = IERC20(tokenIn).balanceOf(creditAccount); // F: [ACV1-5]
        if (dx <= 1) return;

        unchecked {
            dx--;
        }
        uint256 min_dy = (dx * rateMinRAY) / RAY; // F: [ACV1-5]
        _exchange_impl(i, j, _getExchangeCallData(i, j, dx, min_dy, false), false, true); // F: [ACV1-5]
    }

    /// @inheritdoc ICurveV1Adapter
    function exchange_underlying(int128 i, int128 j, uint256, uint256) external override creditFacadeOnly {
        _exchange_underlying(i, j);
    }

    /// @inheritdoc ICurveV1Adapter
    function exchange_underlying(uint256 i, uint256 j, uint256, uint256) external override creditFacadeOnly {
        _exchange_underlying(i.toInt256().toInt128(), j.toInt256().toInt128());
    }

    /// @dev Internal implementation of `exchange_underlying`
    function _exchange_underlying(int128 i, int128 j) internal {
        _exchange_impl(i, j, msg.data, true, false); // F: [ACV1-6]
    }

    /// @inheritdoc ICurveV1Adapter
    function exchange_all_underlying(int128 i, int128 j, uint256 rateMinRAY) external override creditFacadeOnly {
        _exchange_all_underlying(i, j, rateMinRAY);
    }

    /// @inheritdoc ICurveV1Adapter
    function exchange_all_underlying(uint256 i, uint256 j, uint256 rateMinRAY) external override creditFacadeOnly {
        _exchange_all_underlying(i.toInt256().toInt128(), j.toInt256().toInt128(), rateMinRAY);
    }

    /// @dev Internal implementation of `exchange_all_underlying`
    function _exchange_all_underlying(int128 i, int128 j, uint256 rateMinRAY) internal {
        address creditAccount = _creditAccount(); //F: [ACV1-3]

        address tokenIn = _get_token(i, true); // F: [ACV1-7]
        uint256 dx = IERC20(tokenIn).balanceOf(creditAccount); // F: [ACV1-7]
        if (dx <= 1) return;

        unchecked {
            dx--; // F: [ACV1-7]
        }
        uint256 min_dy = (dx * rateMinRAY) / RAY; // F: [ACV1-7]
        _exchange_impl(i, j, _getExchangeCallData(i, j, dx, min_dy, true), true, true); // F: [ACV1-7]
    }

    /// @dev Internal implementation of exchange functions
    ///      - passes calldata to the target contract
    ///      - sets max approval for the input token before the call and resets it to 1 after
    ///      - enables output asset after the call
    ///      - disables input asset only when exchanging the entire balance
    function _exchange_impl(int128 i, int128 j, bytes memory callData, bool underlying, bool disableTokenIn) internal {
        _approve_token(i, underlying, type(uint256).max);
        _execute(callData);
        _approve_token(i, underlying, 1);
        _changeEnabledTokens(_get_token_mask(j, underlying), disableTokenIn ? _get_token_mask(i, underlying) : 0);
    }

    /// @dev Returns calldata for `ICurvePool.exchange` and `ICurvePool.exchange_underlying` calls
    function _getExchangeCallData(int128 i, int128 j, uint256 dx, uint256 min_dy, bool underlying)
        internal
        view
        returns (bytes memory)
    {
        if (use256) {
            return underlying
                ? abi.encodeWithSignature(
                    "exchange_underlying(uint256,uint256,uint256,uint256)",
                    uint256(int256(i)),
                    uint256(int256(j)),
                    dx,
                    min_dy
                )
                : abi.encodeWithSignature(
                    "exchange(uint256,uint256,uint256,uint256)", uint256(int256(i)), uint256(int256(j)), dx, min_dy
                );
        } else {
            return underlying
                ? abi.encodeWithSignature("exchange_underlying(int128,int128,uint256,uint256)", i, j, dx, min_dy)
                : abi.encodeWithSignature("exchange(int128,int128,uint256,uint256)", i, j, dx, min_dy);
        }
    }

    /// ------------- ///
    /// ADD LIQUIDITY ///
    /// ------------- ///

    /// @dev Internal implementation of `add_liquidity`
    ///      - passes calldata to the target contract
    ///      - sets max approvals for the specified tokens before the call and resets them to 1 after
    ///      - enables LP token
    function _add_liquidity(bool t0Approve, bool t1Approve, bool t2Approve, bool t3Approve) internal {
        _approve_tokens(t0Approve, t1Approve, t2Approve, t3Approve, type(uint256).max);
        _execute(msg.data);
        _approve_tokens(t0Approve, t1Approve, t2Approve, t3Approve, 1);
        _changeEnabledTokens(lpTokenMask, 0);
    }

    /// @inheritdoc ICurveV1Adapter
    function add_liquidity_one_coin(uint256 amount, int128 i, uint256 minAmount) external override creditFacadeOnly {
        _add_liquidity_one_coin(amount, i, minAmount);
    }

    /// @inheritdoc ICurveV1Adapter
    function add_liquidity_one_coin(uint256 amount, uint256 i, uint256 minAmount) external override creditFacadeOnly {
        _add_liquidity_one_coin(amount, i.toInt256().toInt128(), minAmount);
    }

    /// @dev Internal implementation of `add_liquidity_one_coin`
    function _add_liquidity_one_coin(uint256 amount, int128 i, uint256 minAmount) internal {
        _add_liquidity_one_coin_impl(i, _getAddLiquidityOneCoinCallData(i, amount, minAmount), false); // F: [ACV1-8]
    }

    /// @inheritdoc ICurveV1Adapter
    function add_all_liquidity_one_coin(int128 i, uint256 rateMinRAY) external override creditFacadeOnly {
        _add_all_liquidity_one_coin(i, rateMinRAY);
    }

    /// @inheritdoc ICurveV1Adapter
    function add_all_liquidity_one_coin(uint256 i, uint256 rateMinRAY) external override creditFacadeOnly {
        _add_all_liquidity_one_coin(i.toInt256().toInt128(), rateMinRAY);
    }

    /// @dev Internal implementation of `add_all_liquidity_one_coin`
    function _add_all_liquidity_one_coin(int128 i, uint256 rateMinRAY) internal {
        address creditAccount = _creditAccount();

        address tokenIn = _get_token(i, false);
        uint256 amount = IERC20(tokenIn).balanceOf(creditAccount); // F: [ACV1-9]
        if (amount <= 1) return;

        unchecked {
            amount--; // F: [ACV1-9]
        }
        uint256 minAmount = (amount * rateMinRAY) / RAY; // F: [ACV1-9]
        _add_liquidity_one_coin_impl(i, _getAddLiquidityOneCoinCallData(i, amount, minAmount), true); // F: [ACV1-9]
    }

    /// @dev Internal implementation of `add_liquidity_one_coin` and `add_all_liquidity_one_coin`
    ///      - passes calldata to the target contract
    ///      - sets max approval for the input token before the call and resets it to 1 after
    ///      - enables LP token
    ///      - disables input token only when adding the entire balance
    function _add_liquidity_one_coin_impl(int128 i, bytes memory callData, bool disableTokenIn) internal {
        _approve_token(i, false, type(uint256).max);
        _execute(callData);
        _approve_token(i, false, 1);
        _changeEnabledTokens(lpTokenMask, disableTokenIn ? _get_token_mask(i, false) : 0);
    }

    /// @dev Returns calldata for `ICurvePool.add_liquidity` with one input asset
    function _getAddLiquidityOneCoinCallData(int128 i, uint256 amount, uint256 minAmount)
        internal
        view
        returns (bytes memory)
    {
        if (nCoins == 2) {
            uint256[2] memory amounts;
            if (i > 1) revert IncorrectIndexException();
            amounts[uint256(uint128(i))] = amount;
            return abi.encodeCall(ICurvePool2Assets.add_liquidity, (amounts, minAmount)); // F: [ACV1-8, ACV1-9]
        }
        if (nCoins == 3) {
            uint256[3] memory amounts;
            if (i > 2) revert IncorrectIndexException();
            amounts[uint256(uint128(i))] = amount;
            return abi.encodeCall(ICurvePool3Assets.add_liquidity, (amounts, minAmount)); // F: [ACV1-8, ACV1-9]
        }
        if (nCoins == 4) {
            uint256[4] memory amounts;
            if (i > 3) revert IncorrectIndexException();
            amounts[uint256(uint128(i))] = amount;
            return abi.encodeCall(ICurvePool4Assets.add_liquidity, (amounts, minAmount)); // F: [ACV1-8, ACV1-9]
        }
        revert("Incorrect nCoins");
    }

    /// ---------------- ///
    /// REMOVE LIQUIDITY ///
    /// ---------------- ///

    /// @dev Internal implementation of `remove_liquidity`
    ///      - passes calldata to the target contract
    ///      - enables all pool tokens
    function _remove_liquidity() internal {
        _execute(msg.data);
        _changeEnabledTokens(token0Mask | token1Mask | token2Mask | token3Mask, 0); // F: [ACV1_2-5, ACV1_3-5, ACV1_4-5]
    }

    /// @dev Internal implementation of `remove_liquidity_imbalance`
    ///      - passes calldata to the target contract
    ///      - enables specified pool tokens
    function _remove_liquidity_imbalance(bool t0Enable, bool t1Enable, bool t2Enable, bool t3Enable) internal {
        _execute(msg.data);

        uint256 tokensMask;
        if (t0Enable) tokensMask |= _get_token_mask(0, false); // F: [ACV1_2-6, ACV1_3-6, ACV1_4-6]
        if (t1Enable) tokensMask |= _get_token_mask(1, false); // F: [ACV1_2-6, ACV1_3-6, ACV1_4-6]
        if (t2Enable) tokensMask |= _get_token_mask(2, false); // F: [ACV1_3-6, ACV1_4-6]
        if (t3Enable) tokensMask |= _get_token_mask(3, false); // F: [ACV1_4-6]
        _changeEnabledTokens(tokensMask, 0); // F: [ACV1_2-6, ACV1_3-6, ACV1_4-6]
    }

    /// @inheritdoc ICurveV1Adapter
    function remove_liquidity_one_coin(uint256, int128 i, uint256) external virtual override creditFacadeOnly {
        _remove_liquidity_one_coin(i);
    }

    /// @inheritdoc ICurveV1Adapter
    function remove_liquidity_one_coin(uint256, uint256 i, uint256) external override creditFacadeOnly {
        _remove_liquidity_one_coin(i.toInt256().toInt128());
    }

    /// @dev Internal implementation of `remove_liquidity_one_coin`
    function _remove_liquidity_one_coin(int128 i) internal {
        _remove_liquidity_one_coin_impl(i, msg.data, false); // F: [ACV1-10]
    }

    /// @inheritdoc ICurveV1Adapter
    function remove_all_liquidity_one_coin(int128 i, uint256 rateMinRAY) external virtual override creditFacadeOnly {
        _remove_all_liquidity_one_coin(i, rateMinRAY);
    }

    /// @inheritdoc ICurveV1Adapter
    function remove_all_liquidity_one_coin(uint256 i, uint256 rateMinRAY) external override creditFacadeOnly {
        _remove_all_liquidity_one_coin(i.toInt256().toInt128(), rateMinRAY);
    }

    /// @dev Internal implementation of `remove_all_liquidity_one_coin`
    function _remove_all_liquidity_one_coin(int128 i, uint256 rateMinRAY) internal {
        address creditAccount = _creditAccount();

        uint256 amount = IERC20(lp_token).balanceOf(creditAccount); // F: [ACV1-11]
        if (amount <= 1) return;

        unchecked {
            amount--; // F: [ACV1-11]
        }
        uint256 minAmount = (amount * rateMinRAY) / RAY; // F: [ACV1-11]
        _remove_liquidity_one_coin_impl(i, _getRemoveLiquidityOneCoinCallData(i, amount, minAmount), true); // F: [ACV1-11]
    }

    /// @dev Internal implementation of `remove_liquidity_one_coin` and `remove_all_liquidity_one_coin`
    ///      - passes calldata to the targe contract
    ///      - enables received asset
    ///      - disables LP token only when removing all liquidity
    function _remove_liquidity_one_coin_impl(int128 i, bytes memory callData, bool disableLP) internal {
        _execute(callData);
        _changeEnabledTokens(_get_token_mask(i, false), disableLP ? lpTokenMask : 0);
    }

    /// @dev Returns calldata for `ICurvePool.remove_liquidity_one_coin` call
    function _getRemoveLiquidityOneCoinCallData(int128 i, uint256 amount, uint256 minAmount)
        internal
        view
        returns (bytes memory)
    {
        if (use256) {
            return abi.encodeWithSignature(
                "remove_liquidity_one_coin(uint256,uint256,uint256)", amount, uint256(int256(i)), minAmount
            );
        } else {
            return abi.encodeWithSignature("remove_liquidity_one_coin(uint256,int128,uint256)", amount, i, minAmount);
        }
    }

    /// ------- ///
    /// HELPERS ///
    /// ------- ///

    /// @dev Returns token `i`'s address
    function _get_token(int128 i, bool underlying) internal view returns (address addr) {
        if (i == 0) {
            addr = underlying ? underlying0 : token0;
        } else if (i == 1) {
            addr = underlying ? underlying1 : token1;
        } else if (i == 2) {
            addr = underlying ? underlying2 : token2;
        } else if (i == 3) {
            addr = underlying ? underlying3 : token3;
        }

        if (addr == address(0)) revert IncorrectIndexException();
    }

    /// @dev Returns token `i`'s mask
    function _get_token_mask(int128 i, bool underlying) internal view returns (uint256 mask) {
        if (i == 0) {
            mask = underlying ? underlying0Mask : token0Mask;
        } else if (i == 1) {
            mask = underlying ? underlying1Mask : token1Mask;
        } else if (i == 2) {
            mask = underlying ? underlying2Mask : token2Mask;
        } else if (i == 3) {
            mask = underlying ? underlying3Mask : token3Mask;
        }

        if (mask == 0) revert IncorrectIndexException();
    }

    /// @dev Sets target contract's approval for token `i` to `amount`
    function _approve_token(int128 i, bool underlying, uint256 amount) internal {
        _approveToken(_get_token(i, underlying), amount);
    }

    /// @dev Sets target contract's approval for specified tokens to `amount`
    function _approve_tokens(bool t0Approve, bool t1Approve, bool t2Approve, bool t3Approve, uint256 amount) internal {
        if (t0Approve) _approveToken(token0, amount); // F: [ACV1_2-4, ACV1_3-4, ACV1_4-4]
        if (t1Approve) _approveToken(token1, amount); // F: [ACV1_2-4, ACV1_3-4, ACV1_4-4]
        if (t2Approve) _approveToken(token2, amount); // F: [ACV1_3-4, ACV1_4-4]
        if (t3Approve) _approveToken(token3, amount); // F: [ACV1_4-4]
    }

    /// @inheritdoc ICurveV1Adapter
    function calc_add_one_coin(uint256 amount, int128 i) public view returns (uint256) {
        if (nCoins == 2) {
            return i == 0
                ? ICurvePool2Assets(targetContract).calc_token_amount([amount, 0], true)
                : ICurvePool2Assets(targetContract).calc_token_amount([0, amount], true);
        } else if (nCoins == 3) {
            return i == 0
                ? ICurvePool3Assets(targetContract).calc_token_amount([amount, 0, 0], true)
                : i == 1
                    ? ICurvePool3Assets(targetContract).calc_token_amount([0, amount, 0], true)
                    : ICurvePool3Assets(targetContract).calc_token_amount([0, 0, amount], true);
        } else if (nCoins == 4) {
            return i == 0
                ? ICurvePool4Assets(targetContract).calc_token_amount([amount, 0, 0, 0], true)
                : i == 1
                    ? ICurvePool4Assets(targetContract).calc_token_amount([0, amount, 0, 0], true)
                    : i == 2
                        ? ICurvePool4Assets(targetContract).calc_token_amount([0, 0, amount, 0], true)
                        : ICurvePool4Assets(targetContract).calc_token_amount([0, 0, 0, amount], true);
        } else {
            revert("Incorrect nCoins");
        }
    }

    /// @inheritdoc ICurveV1Adapter
    function calc_add_one_coin(uint256 amount, uint256 i) external view returns (uint256) {
        return calc_add_one_coin(amount, i.toInt256().toInt128());
    }
}

File 17 of 27 : ICurvePool_2.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;

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

uint256 constant N_COINS = 2;

/// @title ICurvePool2Assets
/// @dev Extends original pool contract with liquidity functions
interface ICurvePool2Assets is ICurvePool {
    function add_liquidity(uint256[N_COINS] memory amounts, uint256 min_mint_amount) external;

    function remove_liquidity(uint256 _amount, uint256[N_COINS] memory min_amounts) external;

    function remove_liquidity_imbalance(uint256[N_COINS] calldata amounts, uint256 max_burn_amount) external;

    function calc_token_amount(uint256[N_COINS] calldata _amounts, bool _is_deposit) external view returns (uint256);

    function get_twap_balances(
        uint256[N_COINS] calldata _first_balances,
        uint256[N_COINS] calldata _last_balances,
        uint256 _time_elapsed
    ) external view returns (uint256[N_COINS] memory);

    function get_balances() external view returns (uint256[N_COINS] memory);

    function get_previous_balances() external view returns (uint256[N_COINS] memory);

    function get_price_cumulative_last() external view returns (uint256[N_COINS] memory);
}

File 18 of 27 : ICurvePool_3.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;

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

uint256 constant N_COINS = 3;

/// @title ICurvePool3Assets
/// @dev Extends original pool contract with liquidity functions
interface ICurvePool3Assets is ICurvePool {
    function add_liquidity(uint256[N_COINS] memory amounts, uint256 min_mint_amount) external;

    function remove_liquidity(uint256 _amount, uint256[N_COINS] memory min_amounts) external;

    function remove_liquidity_imbalance(uint256[N_COINS] memory amounts, uint256 max_burn_amount) external;

    function calc_token_amount(uint256[N_COINS] calldata _amounts, bool _is_deposit) external view returns (uint256);

    function get_twap_balances(
        uint256[N_COINS] calldata _first_balances,
        uint256[N_COINS] calldata _last_balances,
        uint256 _time_elapsed
    ) external view returns (uint256[N_COINS] memory);

    function get_balances() external view returns (uint256[N_COINS] memory);

    function get_previous_balances() external view returns (uint256[N_COINS] memory);

    function get_price_cumulative_last() external view returns (uint256[N_COINS] memory);
}

File 19 of 27 : ICurvePool_4.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;

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

uint256 constant N_COINS = 4;

/// @title ICurvePool4Assets
/// @dev Extends original pool contract with liquidity functions
interface ICurvePool4Assets is ICurvePool {
    function add_liquidity(uint256[N_COINS] memory amounts, uint256 min_mint_amount) external;

    function remove_liquidity(uint256 _amount, uint256[N_COINS] memory min_amounts) external;

    function remove_liquidity_imbalance(uint256[N_COINS] memory amounts, uint256 max_burn_amount) external;

    function calc_token_amount(uint256[N_COINS] calldata _amounts, bool _is_deposit) external view returns (uint256);

    function get_twap_balances(
        uint256[N_COINS] calldata _first_balances,
        uint256[N_COINS] calldata _last_balances,
        uint256 _time_elapsed
    ) external view returns (uint256[N_COINS] memory);

    function get_balances() external view returns (uint256[N_COINS] memory);

    function get_previous_balances() external view returns (uint256[N_COINS] memory);

    function get_price_cumulative_last() external view returns (uint256[N_COINS] memory);
}

File 20 of 27 : ICurvePool.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;

interface ICurvePool {
    function coins(uint256 i) external view returns (address);

    function underlying_coins(uint256 i) external view returns (address);

    function balances(uint256 i) external view returns (uint256);

    function coins(int128) external view returns (address);

    function underlying_coins(int128) external view returns (address);

    function balances(int128) external view returns (uint256);

    function exchange(int128 i, int128 j, uint256 dx, uint256 min_dy) external;

    function exchange(uint256 i, uint256 j, uint256 dx, uint256 min_dy) external;

    function exchange_underlying(int128 i, int128 j, uint256 dx, uint256 min_dy) external;

    function exchange_underlying(uint256 i, uint256 j, uint256 dx, uint256 min_dy) external;

    function get_dy_underlying(int128 i, int128 j, uint256 dx) external view returns (uint256);

    function get_dy_underlying(uint256 i, uint256 j, uint256 dx) external view returns (uint256);

    function get_dy(int128 i, int128 j, uint256 dx) external view returns (uint256);

    function get_dy(uint256 i, uint256 j, uint256 dx) external view returns (uint256);

    function get_virtual_price() external view returns (uint256);

    function virtual_price() external view returns (uint256);

    function token() external view returns (address);

    function remove_liquidity_one_coin(uint256 _token_amount, int128 i, uint256 min_amount) external;

    function remove_liquidity_one_coin(uint256 _token_amount, uint256 i, uint256 min_amount) external;

    function A() external view returns (uint256);

    function A_precise() external view returns (uint256);

    function calc_withdraw_one_coin(uint256 _burn_amount, int128 i) external view returns (uint256);

    function calc_withdraw_one_coin(uint256 _burn_amount, uint256 i) external view returns (uint256);

    function admin_balances(uint256 i) external view returns (uint256);

    function admin() external view returns (address);

    function fee() external view returns (uint256);

    function admin_fee() external view returns (uint256);

    function block_timestamp_last() external view returns (uint256);

    function initial_A() external view returns (uint256);

    function future_A() external view returns (uint256);

    function initial_A_time() external view returns (uint256);

    function future_A_time() external view returns (uint256);

    function mid_fee() external view returns (uint256);

    // Some pools implement ERC20

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

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

    function decimals() external view returns (uint256);

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

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

    function totalSupply() external view returns (uint256);
}

File 21 of 27 : ICurveV1_2AssetsAdapter.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2023
pragma solidity ^0.8.17;

import {N_COINS} from "../../integrations/curve/ICurvePool_2.sol";
import {ICurveV1Adapter} from "./ICurveV1Adapter.sol";

/// @title Curve V1 2 assets adapter interface
/// @notice Implements logic allowing to interact with Curve pools with 2 assets
interface ICurveV1_2AssetsAdapter is ICurveV1Adapter {
    /// @notice Add liquidity to the pool
    /// @param amounts Amounts of tokens to add
    /// @dev `min_mint_amount` parameter is ignored because calldata is passed directly to the target contract
    function add_liquidity(uint256[N_COINS] calldata amounts, uint256) external;

    /// @notice Remove liquidity from the pool
    /// @dev '_amount' and 'min_amounts' parameters are ignored because calldata is directly passed to the target contract
    function remove_liquidity(uint256, uint256[N_COINS] calldata) external;

    /// @notice Withdraw exact amounts of tokens from the pool
    /// @param amounts Amounts of tokens to withdraw
    /// @dev `max_burn_amount` parameter is ignored because calldata is directly passed to the target contract
    function remove_liquidity_imbalance(uint256[N_COINS] calldata amounts, uint256) external;
}

File 22 of 27 : ICurveV1Adapter.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2023
pragma solidity ^0.8.17;

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

interface ICurveV1AdapterExceptions {
    /// @notice Thrown when trying to pass incorrect asset index as parameter to an adapter function
    error IncorrectIndexException();
}

/// @title Curve V1 base adapter interface
/// @notice Implements logic allowing to interact with all Curve pools, regardless of number of coins
interface ICurveV1Adapter is IAdapter, ICurveV1AdapterExceptions {
    /// @notice Exchanges one pool asset to another
    /// @param i Index of the asset to spend
    /// @param j Index of the asset to receive
    /// @dev `dx` and `min_dy` parameters are ignored because calldata is passed directly to the target contract
    function exchange(int128 i, int128 j, uint256, uint256) external;

    /// @notice `exchange` wrapper to support newer pools which accept uint256 for token indices
    function exchange(uint256 i, uint256 j, uint256, uint256) external;

    /// @notice Exchanges the entire balance of one pool asset to another, disables input asset
    /// @param i Index of the asset to spend
    /// @param j Index of the asset to receive
    /// @param rateMinRAY Minimum exchange rate between assets i and j, scaled by 1e27
    function exchange_all(int128 i, int128 j, uint256 rateMinRAY) external;

    /// @notice `exchange_all` wrapper to support newer pools which accept uint256 for token indices
    function exchange_all(uint256 i, uint256 j, uint256 rateMinRAY) external;

    /// @notice Exchanges one pool's underlying asset to another
    /// @param i Index of the underlying asset to spend
    /// @param j Index of the underlying asset to receive
    /// @dev `dx` and `min_dy` parameters are ignored because calldata is passed directly to the target contract
    function exchange_underlying(int128 i, int128 j, uint256, uint256) external;

    /// @notice `exchange_underlying` wrapper to support newer pools which accept uint256 for token indices
    function exchange_underlying(uint256 i, uint256 j, uint256, uint256) external;

    /// @notice Exchanges the entire balance of one pool's underlying asset to another, disables input asset
    /// @param i Index of the underlying asset to spend
    /// @param j Index of the underlying asset to receive
    /// @param rateMinRAY Minimum exchange rate between underlying assets i and j, scaled by 1e27
    function exchange_all_underlying(int128 i, int128 j, uint256 rateMinRAY) external;

    /// @notice `exchange_all_underlying` wrapper to support newer pools which accept uint256 for token indices
    function exchange_all_underlying(uint256 i, uint256 j, uint256 rateMinRAY) external;

    /// @notice Adds given amount of asset as liquidity to the pool
    /// @param amount Amount to deposit
    /// @param i Index of the asset to deposit
    /// @param minAmount Minimum amount of LP tokens to receive
    function add_liquidity_one_coin(uint256 amount, int128 i, uint256 minAmount) external;

    /// @notice `add_liquidity_one_coin` wrapper to support newer pools which accept uint256 for token indices
    function add_liquidity_one_coin(uint256 amount, uint256 i, uint256 minAmount) external;

    /// @notice Adds the entire balance of asset as liquidity to the pool, disables this asset
    /// @param i Index of the asset to deposit
    /// @param rateMinRAY Minimum exchange rate between deposited asset and LP token, scaled by 1e27
    function add_all_liquidity_one_coin(int128 i, uint256 rateMinRAY) external;

    /// @notice `add_all_liquidity_one_coin` wrapper to support newer pools which accept uint256 for token indices
    function add_all_liquidity_one_coin(uint256 i, uint256 rateMinRAY) external;

    /// @notice Removes liquidity from the pool in a specified asset
    /// @param i Index of the asset to withdraw
    /// @dev `_token_amount` and `min_amount` parameters are ignored because calldata is passed directly to the target contract
    function remove_liquidity_one_coin(uint256, int128 i, uint256) external;

    /// @notice `remove_liquidity_one_coin` wrapper to support newer pools which accept uint256 for token indices
    function remove_liquidity_one_coin(uint256, uint256 i, uint256) external;

    /// @notice Removes all liquidity from the pool in a specified asset
    /// @param i Index of the asset to withdraw
    /// @param rateMinRAY Minimum exchange rate between LP token and received token, scaled by 1e27
    function remove_all_liquidity_one_coin(int128 i, uint256 rateMinRAY) external;

    /// @notice `remove_all_liquidity_one_coin` wrapper to support newer pools which accept uint256 for token indices
    function remove_all_liquidity_one_coin(uint256 i, uint256 rateMinRAY) external;

    /// @notice Pool LP token address (added for backward compatibility)
    function token() external view returns (address);

    /// @notice Pool LP token address
    function lp_token() external view returns (address);

    /// @notice Collateral token mask of pool LP token in the credit manager
    function lpTokenMask() external view returns (uint256);

    /// @notice Base pool address (for metapools only)
    function metapoolBase() external view returns (address);

    /// @notice Number of coins in the pool
    function nCoins() external view returns (uint256);

    /// @notice Whether to use uint256 for token indexes in write functions
    function use256() external view returns (bool);

    /// @notice Token in the pool under index 0
    function token0() external view returns (address);

    /// @notice Token in the pool under index 1
    function token1() external view returns (address);

    /// @notice Token in the pool under index 2
    function token2() external view returns (address);

    /// @notice Token in the pool under index 3
    function token3() external view returns (address);

    /// @notice Collateral token mask of token0 in the credit manager
    function token0Mask() external view returns (uint256);

    /// @notice Collateral token mask of token1 in the credit manager
    function token1Mask() external view returns (uint256);

    /// @notice Collateral token mask of token2 in the credit manager
    function token2Mask() external view returns (uint256);

    /// @notice Collateral token mask of token3 in the credit manager
    function token3Mask() external view returns (uint256);

    /// @notice Underlying in the pool under index 0
    function underlying0() external view returns (address);

    /// @notice Underlying in the pool under index 1
    function underlying1() external view returns (address);

    /// @notice Underlying in the pool under index 2
    function underlying2() external view returns (address);

    /// @notice Underlying in the pool under index 3
    function underlying3() external view returns (address);

    /// @notice Collateral token mask of underlying0 in the credit manager
    function underlying0Mask() external view returns (uint256);

    /// @notice Collateral token mask of underlying1 in the credit manager
    function underlying1Mask() external view returns (uint256);

    /// @notice Collateral token mask of underlying2 in the credit manager
    function underlying2Mask() external view returns (uint256);

    /// @notice Collateral token mask of underlying3 in the credit manager
    function underlying3Mask() external view returns (uint256);

    /// @notice Returns the amount of LP token received for adding a single asset to the pool
    /// @param amount Amount to deposit
    /// @param i Index of the asset to deposit
    function calc_add_one_coin(uint256 amount, int128 i) external view returns (uint256);

    /// @notice `calc_add_one_coin` wrapper to support newer pools which accept uint256 for token indices
    function calc_add_one_coin(uint256 amount, uint256 i) external view returns (uint256);
}

File 23 of 27 : IAdapter.sol
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2023
pragma solidity ^0.8.17;

import {IAdapter, AdapterType} from "@gearbox-protocol/core-v2/contracts/interfaces/adapters/IAdapter.sol";

File 24 of 27 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

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

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

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

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

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

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

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

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

pragma solidity ^0.8.0;

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

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

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

File 27 of 27 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.2._
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v2.5._
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.2._
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v2.5._
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v2.5._
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v2.5._
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v2.5._
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_creditManager","type":"address"},{"internalType":"address","name":"_curvePool","type":"address"},{"internalType":"address","name":"_lp_token","type":"address"},{"internalType":"address","name":"_metapoolBase","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"CallerNotConfiguratorException","type":"error"},{"inputs":[],"name":"CreditFacadeOnlyException","type":"error"},{"inputs":[],"name":"IncorrectIndexException","type":"error"},{"inputs":[],"name":"TokenNotAllowedException","type":"error"},{"inputs":[],"name":"ZeroAddressException","type":"error"},{"inputs":[],"name":"_acl","outputs":[{"internalType":"contract IACL","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_gearboxAdapterType","outputs":[{"internalType":"enum AdapterType","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"_gearboxAdapterVersion","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"},{"internalType":"uint256","name":"rateMinRAY","type":"uint256"}],"name":"add_all_liquidity_one_coin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int128","name":"i","type":"int128"},{"internalType":"uint256","name":"rateMinRAY","type":"uint256"}],"name":"add_all_liquidity_one_coin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[2]","name":"amounts","type":"uint256[2]"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"add_liquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"i","type":"uint256"},{"internalType":"uint256","name":"minAmount","type":"uint256"}],"name":"add_liquidity_one_coin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"int128","name":"i","type":"int128"},{"internalType":"uint256","name":"minAmount","type":"uint256"}],"name":"add_liquidity_one_coin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressProvider","outputs":[{"internalType":"contract IAddressProvider","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"int128","name":"i","type":"int128"}],"name":"calc_add_one_coin","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"i","type":"uint256"}],"name":"calc_add_one_coin","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"creditManager","outputs":[{"internalType":"contract ICreditManagerV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int128","name":"i","type":"int128"},{"internalType":"int128","name":"j","type":"int128"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"exchange","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"},{"internalType":"uint256","name":"j","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"exchange","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"},{"internalType":"uint256","name":"j","type":"uint256"},{"internalType":"uint256","name":"rateMinRAY","type":"uint256"}],"name":"exchange_all","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int128","name":"i","type":"int128"},{"internalType":"int128","name":"j","type":"int128"},{"internalType":"uint256","name":"rateMinRAY","type":"uint256"}],"name":"exchange_all","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int128","name":"i","type":"int128"},{"internalType":"int128","name":"j","type":"int128"},{"internalType":"uint256","name":"rateMinRAY","type":"uint256"}],"name":"exchange_all_underlying","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"},{"internalType":"uint256","name":"j","type":"uint256"},{"internalType":"uint256","name":"rateMinRAY","type":"uint256"}],"name":"exchange_all_underlying","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"},{"internalType":"uint256","name":"j","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"exchange_underlying","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int128","name":"i","type":"int128"},{"internalType":"int128","name":"j","type":"int128"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"exchange_underlying","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lpTokenMask","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lp_token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"metapoolBase","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nCoins","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int128","name":"i","type":"int128"},{"internalType":"uint256","name":"rateMinRAY","type":"uint256"}],"name":"remove_all_liquidity_one_coin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"},{"internalType":"uint256","name":"rateMinRAY","type":"uint256"}],"name":"remove_all_liquidity_one_coin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256[2]","name":"","type":"uint256[2]"}],"name":"remove_liquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[2]","name":"amounts","type":"uint256[2]"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"remove_liquidity_imbalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"int128","name":"i","type":"int128"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"remove_liquidity_one_coin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"i","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"remove_liquidity_one_coin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"targetContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token0","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token0Mask","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1Mask","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token2Mask","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token3","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token3Mask","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlying0","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlying0Mask","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlying1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlying1Mask","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlying2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlying2Mask","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlying3","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlying3Mask","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"use256","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061032b5760003560e01c806379bea664116101b2578063c21ee162116100f9578063e3103273116100a2578063ef14101e1161007c578063ef14101e14610894578063f1dc3cc9146108bb578063f8f15639146108ce578063fc0c546a146108f557600080fd5b8063e31032731461085b578063e90d1dbc1461086e578063ec026ca71461088157600080fd5b8063ce30bbdb116100d3578063ce30bbdb14610812578063cf023dd014610821578063d21220a71461083457600080fd5b8063c21ee1621461079d578063c7c4fe1e146107c4578063caed3787146107eb57600080fd5b8063a50cf2c81161015b578063ae206e2411610135578063ae206e241461073c578063bd90df701461074f578063c12c21c01461077657600080fd5b8063a50cf2c8146106ef578063a6417ed614610716578063ab6548fa1461072957600080fd5b80638ba51dfc1161018c5780638ba51dfc1461067a57806393a58153146106a15780639e9c1e88146106c857600080fd5b806379bea6641461061957806382c630661461062c57806387427f461461065357600080fd5b806341c84b3611610276578063623d85851161021f57806365b2489b116101f957806365b2489b146105c45780636e1d8271146105d757806378aa73a4146105fe57600080fd5b8063623d85851461055357806363e73cbb1461058a57806364a89bca1461059d57600080fd5b80635b36389c116102505780635b36389c146105065780635b41b908146105195780635e8d3f551461052c57600080fd5b806341c84b36146104b95780634be97fb0146104cc57806357d78875146104df57600080fd5b806325be124e116102d857806333d2ebf2116102b257806333d2ebf21461046c5780633df021241461047f578063403d4e4a1461049257600080fd5b806325be124e1461040b5780632954018c146104325780632c5788d21461045957600080fd5b80630dfe1681116103095780630dfe1681146103be5780631a4d01d2146103e55780631af4de83146103f857600080fd5b806301b44c8414610330578063068711631461036a5780630b4c7e4d146103a9575b600080fd5b6103577f000000000000000000000000000000000000000000000000000000000000010081565b6040519081526020015b60405180910390f35b6103917f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b6040516001600160a01b039091168152602001610361565b6103bc6103b7366004612be2565b61091c565b005b6103917f000000000000000000000000056fd409e1d7a124bd7017459dfea2f387b6d5cd81565b6103bc6103f3366004612c1f565b610971565b6103bc610406366004612c54565b6109b8565b6103917f000000000000000000000000000000000000000000000000000000000000000081565b6103917f000000000000000000000000cf64698aff7e5f27a11dff868af228653ba53be081565b610357610467366004612c80565b6109fc565b6103bc61047a366004612cac565b610f79565b6103bc61048d366004612cd6565b610fbc565b6103577f000000000000000000000000000000000000000000000000000000000000001081565b6103bc6104c7366004612d18565b611005565b6103bc6104da366004612d18565b611064565b6103917f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec781565b6103bc610514366004612d44565b6110b3565b6103bc610527366004612d68565b6110f4565b6103577f000000000000000000000000000000000000000000000000000000000000000181565b61057a7f000000000000000000000000000000000000000000000000000000000000000081565b6040519015158152602001610361565b6103bc610598366004612d9a565b61114d565b6103917f000000000000000000000000bebc44782c7db0a1a60cb6fe97d0b483032ff1c781565b6103bc6105d2366004612d68565b61119b565b6103917f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f81565b610606600281565b60405161ffff9091168152602001610361565b6103bc610627366004612c54565b6111f4565b6103917f000000000000000000000000d2967f45c4f384deea880f807be904762a3dea0781565b6103577f000000000000000000000000000000000000000000000000000000000000010081565b6103917f000000000000000000000000056fd409e1d7a124bd7017459dfea2f387b6d5cd81565b6103577f000000000000000000000000000000000000000000000000000000000000002081565b6103577f000000000000000000000000000000000000000000000000000000000000000081565b6103917f000000000000000000000000523da3a8961e4dd4f6206dbf7e6c749f51796bb381565b6103bc610724366004612cd6565b611238565b6103bc610737366004612d18565b61127b565b61035761074a366004612d9a565b6112d5565b6103917f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf4116795681565b6103917f00000000000000000000000095357303f995e184a7998da6c6ea35cc728a190081565b6103577f000000000000000000000000000000000000000000000000000000000000000281565b6103577f000000000000000000000000000000000000000000000000000000000010000081565b6103577f000000000000000000000000000000000000000000000000000000000000000081565b60056040516103619190612dbc565b6103bc61082f366004612c1f565b6112ee565b6103917f0000000000000000000000006c3f90f043a72fa612cbac8115ee7e52bde6e49081565b6103bc610869366004612be2565b611332565b6103bc61087c366004612d9a565b611383565b6103bc61088f366004612cac565b6113d1565b6103917f000000000000000000000000000000000000000000000000000000000000000081565b6103bc6108c9366004612d18565b611414565b6103577f000000000000000000000000000000000000000000000000000000000000100081565b6103917f000000000000000000000000d2967f45c4f384deea880f807be904762a3dea0781565b61092461157c565b6001600160a01b0316336001600160a01b03161461095557604051636c01359160e11b815260040160405180910390fd5b61096d60018335811090602085013511600080611605565b5050565b61097961157c565b6001600160a01b0316336001600160a01b0316146109aa57604051636c01359160e11b815260040160405180910390fd5b6109b38261168e565b505050565b6109c061157c565b6001600160a01b0316336001600160a01b0316146109f157604051636c01359160e11b815260040160405180910390fd5b6109b38383836116d2565b60007f0000000000000000000000000000000000000000000000000000000000000002600203610bb25781600f0b600014610af157604080518082018252600081526020810185905290517fed8e84f30000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf41167956169163ed8e84f391610aab9190600190600401612e1d565b602060405180830381865afa158015610ac8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aec9190612e3a565b610bab565b6040805180820182528481526000602082015290517fed8e84f30000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf41167956169163ed8e84f391610b6a9190600190600401612e1d565b602060405180830381865afa158015610b87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bab9190612e3a565b9050610f73565b7f0000000000000000000000000000000000000000000000000000000000000002600303610d255781600f0b600014610cbe5781600f0b600114610c575760408051606081018252600080825260208201528082018590529051633883e11960e01b81526001600160a01b037f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf411679561691633883e11991610aab9190600190600401612e76565b60408051606081018252600080825260208201869052818301529051633883e11960e01b81526001600160a01b037f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf411679561691633883e11991610aab9190600190600401612e76565b60408051606081018252848152600060208201819052818301529051633883e11960e01b81526001600160a01b037f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf411679561691633883e11991610b6a9190600190600401612e76565b7f0000000000000000000000000000000000000000000000000000000000000002600403610f265781600f0b600014610eb85781600f0b600114610e4a5781600f0b600214610ddc57604080516080810182526000808252602082018190528183015260608101859052905163cf701ff760e01b81526001600160a01b037f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf41167956169163cf701ff791610aab9190600190600401612eb6565b604080516080810182526000808252602082018190528183018690526060820152905163cf701ff760e01b81526001600160a01b037f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf41167956169163cf701ff791610aab9190600190600401612eb6565b604080516080810182526000808252602082018690528183018190526060820152905163cf701ff760e01b81526001600160a01b037f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf41167956169163cf701ff791610aab9190600190600401612eb6565b604080516080810182528481526000602082018190528183018190526060820152905163cf701ff760e01b81526001600160a01b037f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf41167956169163cf701ff791610b6a9190600190600401612eb6565b60405162461bcd60e51b815260206004820152601060248201527f496e636f7272656374206e436f696e730000000000000000000000000000000060448201526064015b60405180910390fd5b92915050565b610f8161157c565b6001600160a01b0316336001600160a01b031614610fb257604051636c01359160e11b815260040160405180910390fd5b61096d82826117ba565b610fc461157c565b6001600160a01b0316336001600160a01b031614610ff557604051636c01359160e11b815260040160405180910390fd5b610fff84846118aa565b50505050565b61100d61157c565b6001600160a01b0316336001600160a01b03161461103e57604051636c01359160e11b815260040160405180910390fd5b6109b361105261104d85611461565b6114fd565b61105e61104d85611461565b836118ee565b61106c61157c565b6001600160a01b0316336001600160a01b03161461109d57604051636c01359160e11b815260040160405180910390fd5b6109b3836110ad61104d85611461565b836119ce565b6110bb61157c565b6001600160a01b0316336001600160a01b0316146110ec57604051636c01359160e11b815260040160405180910390fd5b61096d6119e4565b6110fc61157c565b6001600160a01b0316336001600160a01b03161461112d57604051636c01359160e11b815260040160405180910390fd5b610fff61113c61104d86611461565b61114861104d86611461565b6118aa565b61115561157c565b6001600160a01b0316336001600160a01b03161461118657604051636c01359160e11b815260040160405180910390fd5b61096d61119561104d84611461565b82611ab8565b6111a361157c565b6001600160a01b0316336001600160a01b0316146111d457604051636c01359160e11b815260040160405180910390fd5b610fff6111e361104d86611461565b6111ef61104d86611461565b611b99565b6111fc61157c565b6001600160a01b0316336001600160a01b03161461122d57604051636c01359160e11b815260040160405180910390fd5b6109b38383836118ee565b61124061157c565b6001600160a01b0316336001600160a01b03161461127157604051636c01359160e11b815260040160405180910390fd5b610fff8484611b99565b61128361157c565b6001600160a01b0316336001600160a01b0316146112b457604051636c01359160e11b815260040160405180910390fd5b6109b36112c361104d85611461565b6112cf61104d85611461565b836116d2565b60006112e78361046761104d85611461565b9392505050565b6112f661157c565b6001600160a01b0316336001600160a01b03161461132757604051636c01359160e11b815260040160405180910390fd5b6109b38383836119ce565b61133a61157c565b6001600160a01b0316336001600160a01b03161461136b57604051636c01359160e11b815260040160405180910390fd5b61096d60018335811090602085013511600080611bde565b61138b61157c565b6001600160a01b0316336001600160a01b0316146113bc57604051636c01359160e11b815260040160405180910390fd5b61096d6113cb61104d84611461565b826117ba565b6113d961157c565b6001600160a01b0316336001600160a01b03161461140a57604051636c01359160e11b815260040160405180910390fd5b61096d8282611ab8565b61141c61157c565b6001600160a01b0316336001600160a01b03161461144d57604051636c01359160e11b815260040160405180910390fd5b6109b361145c61104d84611461565b61168e565b60007f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8211156114f95760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e206160448201527f6e20696e743235360000000000000000000000000000000000000000000000006064820152608401610f6a565b5090565b80600f81900b81146115775760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201527f32382062697473000000000000000000000000000000000000000000000000006064820152608401610f6a565b919050565b60007f00000000000000000000000095357303f995e184a7998da6c6ea35cc728a19006001600160a01b0316632f7a18816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156115dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116009190612eea565b905090565b61161484848484600019611c7b565b6116546000368080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611d3b92505050565b50611663848484846001611c7b565b610fff7f00000000000000000000000000000000000000000000000000000000001000006000611dfb565b6116cf816000368080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509250612049915050565b50565b60006116dc612094565b905060006116eb856001612129565b6040516370a0823160e01b81526001600160a01b0384811660048301529192506000918316906370a0823190602401602060405180830381865afa158015611737573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061175b9190612e3a565b90506001811161176d57505050505050565b6000190160006b033b2e3c9fd0803ce800000061178a8684612f05565b6117949190612f2a565b90506117b187876117a98a8a878760016122c6565b6001806124ba565b50505050505050565b60006117c4612094565b6040516370a0823160e01b81526001600160a01b0380831660048301529192506000917f000000000000000000000000d2967f45c4f384deea880f807be904762a3dea0716906370a0823190602401602060405180830381865afa158015611830573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118549190612e3a565b9050600181116118645750505050565b6000190160006b033b2e3c9fd0803ce80000006118818584612f05565b61188b9190612f2a565b90506118a38561189c878585612500565b6001612049565b5050505050565b61096d82826000368080601f016020809104026020016040519081016040528093929190818152602001838380828437600092018290525092508291506124ba9050565b60006118f8612094565b90506000611907856000612129565b6040516370a0823160e01b81526001600160a01b0384811660048301529192506000918316906370a0823190602401602060405180830381865afa158015611953573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119779190612e3a565b90506001811161198957505050505050565b6000190160006b033b2e3c9fd0803ce80000006119a68684612f05565b6119b09190612f2a565b90506117b187876119c58a8a878760006122c6565b600060016124ba565b6109b3826119dd8486856125fa565b6000612896565b611a246000368080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611d3b92505050565b50611ab67f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000010007f00000000000000000000000000000000000000000000000000000000000001001717176000611dfb565b565b6000611ac2612094565b90506000611ad1846000612129565b6040516370a0823160e01b81526001600160a01b0384811660048301529192506000918316906370a0823190602401602060405180830381865afa158015611b1d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b419190612e3a565b905060018111611b52575050505050565b6000190160006b033b2e3c9fd0803ce8000000611b6f8684612f05565b611b799190612f2a565b9050611b9186611b8a8885856125fa565b6001612896565b505050505050565b61096d82826000368080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052506001935091506124ba9050565b611c1e6000368080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611d3b92505050565b5060008415611c3457611c326000806128f2565b175b8315611c4857611c46600160006128f2565b175b8215611c5c57611c5a600260006128f2565b175b8115611c7057611c6e600360006128f2565b175b6118a3816000611dfb565b8415611cab57611cab7f000000000000000000000000056fd409e1d7a124bd7017459dfea2f387b6d5cd82612a89565b8315611cdb57611cdb7f0000000000000000000000006c3f90f043a72fa612cbac8115ee7e52bde6e49082612a89565b8215611d0b57611d0b7f000000000000000000000000000000000000000000000000000000000000000082612a89565b81156118a3576118a37f000000000000000000000000000000000000000000000000000000000000000082612a89565b60607f00000000000000000000000095357303f995e184a7998da6c6ea35cc728a19006001600160a01b0316636ce4074a611d7461157c565b7f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf41167956856040518463ffffffff1660e01b8152600401611db493929190612f70565b6000604051808303816000875af1158015611dd3573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610f739190810190612fd4565b6000611e05612094565b9050828218600060015b828111611b91578281161561201a576040517fe75538c7000000000000000000000000000000000000000000000000000000008152600481018290527f00000000000000000000000095357303f995e184a7998da6c6ea35cc728a19006001600160a01b03169063e75538c7906024016040805180830381865afa158015611e9b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ebf9190613081565b50915085811615611f6b576040517f51e3f1600000000000000000000000000000000000000000000000000000000081526001600160a01b03858116600483015283811660248301527f00000000000000000000000095357303f995e184a7998da6c6ea35cc728a190016906351e3f16090604401600060405180830381600087803b158015611f4e57600080fd5b505af1158015611f62573d6000803e3d6000fd5b5050505061201a565b6040517f0d8f9cee0000000000000000000000000000000000000000000000000000000081526001600160a01b03858116600483015283811660248301527f00000000000000000000000095357303f995e184a7998da6c6ea35cc728a19001690630d8f9cee906044016020604051808303816000875af1158015611ff4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061201891906130bf565b505b7f80000000000000000000000000000000000000000000000000000000000000008114611b915760011b611e0f565b61205282611d3b565b506109b36120618460006128f2565b8261206d576000611dfb565b7f00000000000000000000000000000000000000000000000000000000001000005b611dfb565b60007f00000000000000000000000095357303f995e184a7998da6c6ea35cc728a19006001600160a01b031663e958b7046120cd61157c565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa1580156115dc573d6000803e3d6000fd5b600082600f0b60000361218a5781612161577f000000000000000000000000056fd409e1d7a124bd7017459dfea2f387b6d5cd612183565b7f000000000000000000000000056fd409e1d7a124bd7017459dfea2f387b6d5cd5b905061229f565b82600f0b6001036121e757816121c0577f0000000000000000000000006c3f90f043a72fa612cbac8115ee7e52bde6e490612183565b507f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f61229f565b82600f0b600203612244578161221d577f0000000000000000000000000000000000000000000000000000000000000000612183565b507f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4861229f565b82600f0b60030361229f578161227a577f000000000000000000000000000000000000000000000000000000000000000061229c565b7f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec75b90505b6001600160a01b038116610f73576040516334769e6f60e21b815260040160405180910390fd5b60607f0000000000000000000000000000000000000000000000000000000000000000156123d2578161236157604051600f87810b602483015286900b6044820152606481018590526084810184905260a40160408051601f198184030181529190526020810180516001600160e01b03167f5b41b908000000000000000000000000000000000000000000000000000000001790526123cb565b604051600f87810b602483015286900b6044820152606481018590526084810184905260a40160408051601f198184030181529190526020810180516001600160e01b03167f65b2489b000000000000000000000000000000000000000000000000000000001790525b90506124b1565b8161244557604051600f87810b602483015286900b6044820152606481018590526084810184905260a40160408051601f198184030181529190526020810180516001600160e01b03167f3df02124000000000000000000000000000000000000000000000000000000001790526123cb565b604051600f87810b602483015286900b6044820152606481018590526084810184905260a40160408051601f198184030181529190526020810180516001600160e01b03167fa6417ed60000000000000000000000000000000000000000000000000000000017905290505b95945050505050565b6124c78583600019612b64565b6124d083611d3b565b506124dd85836001612b64565b6118a36124ea85846128f2565b826124f6576000611dfb565b61208f87856128f2565b60607f0000000000000000000000000000000000000000000000000000000000000000156125905760405160248101849052600f85900b60448201526064810183905260840160408051601f198184030181529190526020810180516001600160e01b03167ff1dc3cc90000000000000000000000000000000000000000000000000000000017905290506112e7565b60405160248101849052600f85900b60448201526064810183905260840160408051601f198184030181529190526020810180516001600160e01b03167f1a4d01d20000000000000000000000000000000000000000000000000000000017905290509392505050565b60607f00000000000000000000000000000000000000000000000000000000000000026002036126da5761262c612b77565b600185600f0b1315612651576040516334769e6f60e21b815260040160405180910390fd5b8381866fffffffffffffffffffffffffffffffff166002811061267657612676612de4565b602002015260405161268e90829085906024016130e1565b60408051601f198184030181529190526020810180516001600160e01b03167f0b4c7e4d0000000000000000000000000000000000000000000000000000000017905291506112e79050565b7f00000000000000000000000000000000000000000000000000000000000000026003036127b85761270a612b95565b600285600f0b131561272f576040516334769e6f60e21b815260040160405180910390fd5b8381866fffffffffffffffffffffffffffffffff166003811061275457612754612de4565b602002015260405161276c90829085906024016130fc565b60408051601f198184030181529190526020810180516001600160e01b03167f4515cef30000000000000000000000000000000000000000000000000000000017905291506112e79050565b7f0000000000000000000000000000000000000000000000000000000000000002600403610f26576127e8612bb3565b600385600f0b131561280d576040516334769e6f60e21b815260040160405180910390fd5b8381866fffffffffffffffffffffffffffffffff166004811061283257612832612de4565b602002015260405161284a9082908590602401613117565b60408051601f198184030181529190526020810180516001600160e01b03167f029b2f340000000000000000000000000000000000000000000000000000000017905291506112e79050565b6128a4836000600019612b64565b6128ad82611d3b565b506128bb8360006001612b64565b6109b37f0000000000000000000000000000000000000000000000000000000000100000826128eb576000611dfb565b61208f8560005b600082600f0b600003612953578161292a577f000000000000000000000000000000000000000000000000000000000000010061294c565b7f00000000000000000000000000000000000000000000000000000000000001005b9050612a68565b82600f0b6001036129b05781612989577f000000000000000000000000000000000000000000000000000000000000100061294c565b507f0000000000000000000000000000000000000000000000000000000000000010612a68565b82600f0b600203612a0d57816129e6577f000000000000000000000000000000000000000000000000000000000000000061294c565b507f0000000000000000000000000000000000000000000000000000000000000001612a68565b82600f0b600303612a685781612a43577f0000000000000000000000000000000000000000000000000000000000000000612a65565b7f00000000000000000000000000000000000000000000000000000000000000205b90505b80600003610f73576040516334769e6f60e21b815260040160405180910390fd5b7f00000000000000000000000095357303f995e184a7998da6c6ea35cc728a19006001600160a01b03166346fb371d612ac061157c565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b0391821660048201527f0000000000000000000000004f062658eaaf2c1ccf8c8e36d6824cdf4116795682166024820152908516604482015260648101849052608401600060405180830381600087803b158015612b5057600080fd5b505af1158015611b91573d6000803e3d6000fd5b6109b3612b718484612129565b82612a89565b60405180604001604052806002906020820280368337509192915050565b60405180606001604052806003906020820280368337509192915050565b60405180608001604052806004906020820280368337509192915050565b8060408101831015610f7357600080fd5b60008060608385031215612bf557600080fd5b612bff8484612bd1565b946040939093013593505050565b8035600f81900b811461157757600080fd5b600080600060608486031215612c3457600080fd5b83359250612c4460208501612c0d565b9150604084013590509250925092565b600080600060608486031215612c6957600080fd5b612c7284612c0d565b9250612c4460208501612c0d565b60008060408385031215612c9357600080fd5b82359150612ca360208401612c0d565b90509250929050565b60008060408385031215612cbf57600080fd5b612cc883612c0d565b946020939093013593505050565b60008060008060808587031215612cec57600080fd5b612cf585612c0d565b9350612d0360208601612c0d565b93969395505050506040820135916060013590565b600080600060608486031215612d2d57600080fd5b505081359360208301359350604090920135919050565b60008060608385031215612d5757600080fd5b82359150612ca38460208501612bd1565b60008060008060808587031215612d7e57600080fd5b5050823594602084013594506040840135936060013592509050565b60008060408385031215612dad57600080fd5b50508035926020909101359150565b6020810160158310612dde57634e487b7160e01b600052602160045260246000fd5b91905290565b634e487b7160e01b600052603260045260246000fd5b8060005b6002811015610fff578151845260209384019390910190600101612dfe565b60608101612e2b8285612dfa565b82151560408301529392505050565b600060208284031215612e4c57600080fd5b5051919050565b8060005b6003811015610fff578151845260209384019390910190600101612e57565b60808101612e848285612e53565b82151560608301529392505050565b8060005b6004811015610fff578151845260209384019390910190600101612e97565b60a08101612ec48285612e93565b82151560808301529392505050565b80516001600160a01b038116811461157757600080fd5b600060208284031215612efc57600080fd5b6112e782612ed3565b8082028115828204841417610f7357634e487b7160e01b600052601160045260246000fd5b600082612f4757634e487b7160e01b600052601260045260246000fd5b500490565b60005b83811015612f67578181015183820152602001612f4f565b50506000910152565b60006001600160a01b038086168352808516602084015250606060408301528251806060840152612fa8816080850160208701612f4c565b601f01601f191691909101608001949350505050565b634e487b7160e01b600052604160045260246000fd5b600060208284031215612fe657600080fd5b815167ffffffffffffffff80821115612ffe57600080fd5b818401915084601f83011261301257600080fd5b81518181111561302457613024612fbe565b604051601f8201601f19908116603f0116810190838211818310171561304c5761304c612fbe565b8160405282815287602084870101111561306557600080fd5b613076836020830160208801612f4c565b979650505050505050565b6000806040838503121561309457600080fd5b61309d83612ed3565b9150602083015161ffff811681146130b457600080fd5b809150509250929050565b6000602082840312156130d157600080fd5b815180151581146112e757600080fd5b606081016130ef8285612dfa565b8260408301529392505050565b6080810161310a8285612e53565b8260608301529392505050565b60a081016131258285612e93565b826080830152939250505056fea26469706673582212209174bb8d1023f2374ea0089a3c2db5957aed06dbbdbf9e03a8ec1251b534b08064736f6c63430008110033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.

Validator Index Block Amount
View All Withdrawals

Txn Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

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.