ETH Price: $1,959.53 (-0.94%)

Contract

0x046fFB0dFde6A21B4Fc609841f55C31b6297CfB8
Transaction Hash
Block
From
To
Withdraw4313508342026-02-12 15:04:125 days ago1770908652IN
0x046fFB0d...b6297CfB8
0 ETH0.000003290.02025
Convert Collater...4289690542026-02-05 18:19:4611 days ago1770315586IN
0x046fFB0d...b6297CfB8
0 ETH0.000004460.029572
Supply4277633092026-02-02 7:01:1815 days ago1770015678IN
0x046fFB0d...b6297CfB8
0 ETH0.000004620.020742
Repay4272999922026-01-31 22:56:5116 days ago1769900211IN
0x046fFB0d...b6297CfB8
0 ETH0.000002980.02077
Withdraw4272999252026-01-31 22:56:3416 days ago1769900194IN
0x046fFB0d...b6297CfB8
0 ETH0.000012780.020752
Supply4265137162026-01-29 16:35:1419 days ago1769704514IN
0x046fFB0d...b6297CfB8
0 ETH0.000005180.022138
Withdraw4264772902026-01-29 14:04:4119 days ago1769695481IN
0x046fFB0d...b6297CfB8
0 ETH0.000008320.02014
Withdraw4264772552026-01-29 14:04:3319 days ago1769695473IN
0x046fFB0d...b6297CfB8
0 ETH0.000008180.02014
Supply4261939302026-01-28 18:26:4019 days ago1769624800IN
0x046fFB0d...b6297CfB8
0 ETH0.000004620.020254
Convert Collater...4261576742026-01-28 15:56:0820 days ago1769615768IN
0x046fFB0d...b6297CfB8
0 ETH0.000002980.02
Supply4261576432026-01-28 15:56:0020 days ago1769615760IN
0x046fFB0d...b6297CfB8
0 ETH0.000004690.020024
Convert Collater...4261576052026-01-28 15:55:5120 days ago1769615751IN
0x046fFB0d...b6297CfB8
0 ETH0.000003450.020048
Supply4261574562026-01-28 15:55:1320 days ago1769615713IN
0x046fFB0d...b6297CfB8
0 ETH0.000004970.020456
Supply4205481942026-01-12 10:28:1836 days ago1768213698IN
0x046fFB0d...b6297CfB8
0 ETH0.000004290.020046
Supply4195643442026-01-09 14:04:0939 days ago1767967449IN
0x046fFB0d...b6297CfB8
0 ETH0.000004440.020026
Convert Collater...4195641592026-01-09 14:03:2339 days ago1767967403IN
0x046fFB0d...b6297CfB8
0 ETH0.000002960.02
Repay4195640202026-01-09 14:02:4839 days ago1767967368IN
0x046fFB0d...b6297CfB8
0 ETH0.000002660.02
Repay4195638462026-01-09 14:02:0639 days ago1767967326IN
0x046fFB0d...b6297CfB8
0 ETH0.00000290.02
Withdraw4195637702026-01-09 14:01:4739 days ago1767967307IN
0x046fFB0d...b6297CfB8
0 ETH0.000012590.02
Supply4195636292026-01-09 14:01:1239 days ago1767967272IN
0x046fFB0d...b6297CfB8
0 ETH0.000005530.020242
Withdraw4195632952026-01-09 13:59:4839 days ago1767967188IN
0x046fFB0d...b6297CfB8
0 ETH0.000012160.02
Repay4195630972026-01-09 13:58:5839 days ago1767967138IN
0x046fFB0d...b6297CfB8
0 ETH0.000002920.020012
Withdraw4195627342026-01-09 13:57:2739 days ago1767967047IN
0x046fFB0d...b6297CfB8
0 ETH0.000013290.020052
Supply4195622132026-01-09 13:55:1839 days ago1767966918IN
0x046fFB0d...b6297CfB8
0 ETH0.000004730.02
Repay4195621342026-01-09 13:54:5839 days ago1767966898IN
0x046fFB0d...b6297CfB8
0 ETH0.000002660.02
View all transactions

Latest 1 internal transaction

Parent Transaction Hash Block From To
3083535022025-02-21 10:50:39361 days ago1740135039  Contract Creation0 ETH

Cross-Chain Transactions
Loading...
Loading

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

Contract Name:
LendingPool

Compiler Version
v0.8.23+commit.f704f362

Optimization Enabled:
Yes with 10000 runs

Other Settings:
shanghai EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 30 : LendingPool.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.23;

import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import {ReentrancyGuard} from '@openzeppelin/contracts/utils/ReentrancyGuard.sol';

import {IERC20Metadata} from '@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

import {SharedData} from './lib/SharedData.sol';
import {SharesMath} from './lib/SharesMath.sol';
import {Solvency} from './lib/Solvency.sol';

import {ICollateralToken} from 'interfaces/ICollateralToken.sol';
import {IInterestRateModel} from 'interfaces/IInterestRateModel.sol';
import {ILendingPool} from 'interfaces/ILendingPool.sol';
import {ILiquidationReceiver} from 'interfaces/ILiquidationReceiver.sol';
import {IPriceProvider} from 'interfaces/IPriceProvider.sol';
import {IRepository} from 'interfaces/IRepository.sol';
import {IAllowListAuthentication} from 'interfaces/ISettlement.sol';
import {ISettlement} from 'interfaces/ISettlement.sol';
import {ISwapConnector} from 'interfaces/ISwapConnector.sol';
import {IUtilityTokensFactory} from 'interfaces/IUtilityTokensFactory.sol';

/**
 * @title LendingPool
 * @notice LendingPool implements all core lending protocol logic, such as
 * supplying assets as collateral, borrowing, repaying and withdrawing.
 * It provides liquidation mechanisms and acts as a vault for supplied assets
 */
contract LendingPool is ReentrancyGuard, ILendingPool {
  using SharesMath for uint256;
  using SafeERC20 for ERC20;

  IRepository public override repository;

  address[] private _allAssets;
  /// @dev address of an asset => asset state
  mapping(address => AssetState) private _assetState;
  /// @dev address of an asset => interest data
  mapping(address => AssetInterestData) private _interestData;

  /**
   * @notice Emitted when a new asset is added to the pool
   * @param asset address of new underlying asset
   * @param collateralToken address created collateralToken
   * @param lockedCollateralToken address of created lockedCollateralToken
   * @param debtToken address of created debtToken
   */
  event AssetAdded(address indexed asset, address collateralToken, address lockedCollateralToken, address debtToken);

  /**
   * @notice Emitted when a user borrows an asset from the pool
   * @param asset address of borrowed asset
   * @param borrower address of borrower
   * @param receiver address receiving borrowed amount
   * @param amount amount of asset borrowed
   * @param debtShare amount of debt share tokens minted
   */
  event Borrow(address indexed asset, address indexed borrower, address receiver, uint256 amount, uint256 debtShare);

  /**
   * @notice Emitted when protocol fees on an asset are harvested
   * @param asset address of the underlying harvested asset
   * @param receiver address receiving harvested fees
   * @param harvestedFees amount of harvested fees
   */
  event HarvestProtocolFees(address indexed asset, address receiver, uint256 harvestedFees);

  /**
   * @notice Emitted when successful liquidation occurs
   * @param user address of a liquidated user
   * @param liquidator address of a liquidator
   */
  event Liquidation(address indexed user, address indexed liquidator);

  /**
   * @notice Emitted when a debt is repaid to the pool
   * @param asset address of repaid asset
   * @param borrower address of user whose debt is being repaid
   * @param repayer address of user repaying the debt
   * @param repayAmount amount of asset repaid to the pool
   * @param repayShare amount of debt share tokens burned
   */
  event Repay(
    address indexed asset, address indexed borrower, address repayer, uint256 repayAmount, uint256 repayShare
  );

  /**
   * @dev Emitted when collateral is supplied to the lending pool
   * @param asset address of the asset being supplied as collateral
   * @param depositor address of the account supplying the collateral
   * @param receiver address of the account receiving the minted collateral shares
   * @param amount amount of the asset being supplied as collateral
   * @param mintedShares amount of shares minted for the supplied collateral
   * @param lockedCollateral collateral type flag
   */
  event SupplyCollateral(
    address indexed asset,
    address depositor,
    address indexed receiver,
    uint256 amount,
    uint256 mintedShares,
    bool indexed lockedCollateral
  );

  /**
   * @notice Emitted when a user withdraws collateral tokens from the pool
   * @param asset address of withdrawn asset
   * @param depositor address of user withdrawing collateral
   * @param withdrawnAmount amount of asset withdrawn
   * @param collateralShare amount of collateral share tokens burned
   * @param lockedCollateral collateral type flag
   */
  event WithdrawCollateral(
    address indexed asset,
    address indexed depositor,
    uint256 withdrawnAmount,
    uint256 collateralShare,
    bool indexed lockedCollateral
  );

  error ActionPaused();
  error BorrowerNotMaker();
  error DuplicateAsset();
  error LiquidationNotSuccessful();
  error MaximumLTVReached();
  error MaxSupplyLimitExceeded();
  error NotEnoughLiquidity();
  error NotEnoughDeposits();
  error NotSolvent();
  error OnlyRepository();
  error OnlySettlement();
  error ZeroRepay();
  error ZeroWithdraw();

  modifier onlyRepository() {
    if (msg.sender != address(repository)) revert OnlyRepository();

    _;
  }

  modifier onlySettlement() {
    if (msg.sender != repository.settlement()) revert OnlySettlement();

    _;
  }

  /**
   * @param _repository address of the repository
   */
  constructor(
    address _repository
  ) {
    repository = IRepository(_repository);
  }

  /// @inheritdoc ILendingPool
  function addAssets(IUtilityTokensFactory tokensFactory, address[] memory newAssets) external override onlyRepository {
    for (uint256 i = 0; i < newAssets.length; i++) {
      address asset = newAssets[i];
      AssetState storage assetState = _assetState[asset];

      if (address(assetState.collateralToken) != address(0)) {
        revert DuplicateAsset();
      }

      _allAssets.push(asset);

      UtilityTokensMetadata memory metadata = _generateMetadata(asset);

      assetState.collateralToken = tokensFactory.createCollateralToken(
        metadata.collateralName, metadata.collateralSymbol, address(this), asset, false
      );

      assetState.lockedCollateralToken = tokensFactory.createCollateralToken(
        metadata.lockedCollateralName, metadata.lockedCollateralSymbol, address(this), asset, true
      );

      // solhint-disable-next-line max-line-length
      assetState.debtToken = tokensFactory.createDebtToken(metadata.debtName, metadata.debtSymbol, address(this), asset);

      emit AssetAdded(
        asset,
        address(assetState.collateralToken),
        address(assetState.lockedCollateralToken),
        address(assetState.debtToken)
      );
    }
  }

  /// @inheritdoc ILendingPool
  function convertCollateral(address asset, uint256 amount, bool fromLockedCollateral) external override nonReentrant {
    _convertCollateral(asset, msg.sender, amount, fromLockedCollateral);
  }

  /// @inheritdoc ILendingPool
  function supply(address asset, uint256 amount, bool lockedCollateral) external override {
    _supply(asset, msg.sender, msg.sender, amount, lockedCollateral);
  }

  /// @inheritdoc ILendingPool
  function supplyFor(address asset, address receiver, uint256 amount, bool lockedCollateral) external override {
    _supply(asset, msg.sender, receiver, amount, lockedCollateral);
  }

  /// @inheritdoc ILendingPool
  function withdraw(address asset, uint256 amount, bool lockedCollateral) external override nonReentrant {
    _withdraw(asset, msg.sender, msg.sender, amount, lockedCollateral);
  }

  /// @inheritdoc ILendingPool
  function withdrawFor(
    address asset,
    address depositor,
    address receiver,
    uint256 amount,
    bool lockedCollateral
  ) external override nonReentrant onlySettlement {
    _withdraw(asset, depositor, receiver, amount, lockedCollateral);
  }

  /// @inheritdoc ILendingPool
  function borrow(address asset, uint256 amount) external override nonReentrant {
    _validateIsMaker(msg.sender);
    _borrow(asset, msg.sender, msg.sender, amount);
  }

  /// @inheritdoc ILendingPool
  function borrowFor(
    address asset,
    address borrower,
    address receiver,
    uint256 amount
  ) external override nonReentrant onlySettlement {
    _borrow(asset, borrower, receiver, amount);
  }

  /// @inheritdoc ILendingPool
  function borrowFor(
    address asset,
    address borrower,
    address source,
    address recipient,
    uint256 amount,
    address tradeAsset,
    uint256 tradeAmount
  ) external override nonReentrant onlySettlement {
    _borrow(asset, borrower, source, recipient, amount, tradeAsset, tradeAmount);
  }

  /// @inheritdoc ILendingPool
  function repay(address asset, uint256 amount) external override {
    return _repay(asset, msg.sender, msg.sender, amount);
  }

  /// @inheritdoc ILendingPool
  function repayFor(address asset, address borrower, uint256 amount) external override {
    return _repay(asset, borrower, msg.sender, amount);
  }

  /// @inheritdoc ILendingPool
  function harvestProtocolFees() external override nonReentrant returns (uint256[] memory harvestedAmounts) {
    address[] memory assets = _allAssets;
    harvestedAmounts = new uint256[](assets.length);

    address repositoryOwner = repository.aclAdmin();

    for (uint256 i; i < assets.length;) {
      unchecked {
        harvestedAmounts[i] = _harvestProtocolFees(assets[i], repositoryOwner);
        i++;
      }
    }
  }

  /// @inheritdoc ILendingPool
  function liquidate(
    address _user,
    LiquidateParams[] memory _withdrawalParams,
    LiquidateParams[] memory _repayParams,
    bytes memory _receiverData
  )
    external
    override
    nonReentrant
    returns (LiquidateParams[] memory receivedCollaterals, LiquidateParams[] memory shareAmountsToRepay)
  {
    (receivedCollaterals, shareAmountsToRepay) =
      _liquidate(_user, _withdrawalParams, _repayParams, ILiquidationReceiver(msg.sender), _receiverData);

    emit Liquidation(_user, msg.sender);
  }

  /// @inheritdoc ILendingPool
  function rebalance(
    address _fromAsset,
    address _toAsset,
    uint256 _amount,
    uint256 _minReceiveQuantity,
    bool _lockedCollateral,
    bool _isExactOutput
  ) external override {
    _checkWithdrawPaused(_fromAsset);
    _checkSupplyPaused(_toAsset);
    _accrueInterest(_fromAsset);

    address swapConnector = repository.swapConnector();

    (, uint256 amountToTransfer,) = _withdrawAsset(_fromAsset, _amount, msg.sender, _lockedCollateral, 0);
    ERC20(_fromAsset).safeTransfer(swapConnector, amountToTransfer);

    uint256 amountReceived = ISwapConnector(swapConnector).trade(
      msg.sender, _fromAsset, _toAsset, amountToTransfer, _minReceiveQuantity, _isExactOutput
    );

    _supply(_toAsset, msg.sender, msg.sender, amountReceived, _lockedCollateral);

    if (_lockedCollateral && !isSolvent(msg.sender)) revert NotSolvent();
    _validateMaxSupplyLimitAfter(_toAsset);
  }

  /// @inheritdoc ILendingPool
  function assetUtilizationData(
    address _asset
  ) external view override returns (AssetUtilizationData memory data) {
    AssetState storage _state = _assetState[_asset];

    // solhint-disable-next-line max-line-length
    return AssetUtilizationData(_state.totalDeposits, _state.totalBorrowAmount, _interestData[_asset].interestTimestamp);
  }

  /// @inheritdoc ILendingPool
  function getAssetState(
    address _asset
  ) external view override returns (AssetState memory) {
    return _assetState[_asset];
  }

  /// @inheritdoc ILendingPool
  function interestData(
    address _asset
  ) external view override returns (AssetInterestData memory) {
    return _interestData[_asset];
  }

  /// @inheritdoc ILendingPool
  function isSolvent(
    address _user
  ) public view override returns (bool) {
    (address[] memory assets, AssetState[] memory assetsStates) = getAssetsWithState();

    (uint256 userLTV, uint256 maximumAllowedLTV) = Solvency.calculateLTVs(
      Solvency.SolvencyParams(repository, ILendingPool(address(this)), assets, assetsStates, _user),
      Solvency.TypeofLTV.MaximumLTV
    );

    return userLTV <= maximumAllowedLTV;
  }

  /**
   * @notice Get loan-to-value for a given user with liquidation threshold
   * @param _user address of a user
   * @return userLTV loan-to-value for a given user
   * @return liquidationThreshold liquidation threshold
   */
  function getUserLTV(
    address _user
  ) public view returns (uint256 userLTV, uint256 liquidationThreshold) {
    (address[] memory assets, AssetState[] memory assetsStates) = getAssetsWithState();

    (userLTV, liquidationThreshold) = Solvency.calculateLTVs(
      Solvency.SolvencyParams(repository, ILendingPool(address(this)), assets, assetsStates, _user),
      Solvency.TypeofLTV.LiquidationThreshold
    );
  }

  /// @inheritdoc ILendingPool
  // solhint-disable-next-line max-line-length
  function getAssetsWithState() public view override returns (address[] memory assets, AssetState[] memory assetsState) {
    assets = _allAssets;
    assetsState = new AssetState[](assets.length);

    for (uint256 i = 0; i < assets.length; i++) {
      assetsState[i] = _assetState[assets[i]];
    }
  }

  /**
   * @notice Get liquidity of a given asset
   * @param _asset address of an asset
   * @return uint256 liquidity of given asset
   */
  function liquidity(
    address _asset
  ) public view returns (uint256) {
    return ERC20(_asset).balanceOf(address(this)) - _assetState[_asset].totalLockedDeposits;
  }

  /**
   * @notice Accrues interest for a given asset
   * @param _asset address of an asset
   * @return accruedInterest amount of accrued interest
   */
  function accrueInterest(
    address _asset
  ) external returns (uint256 accruedInterest) {
    return _accrueInterest(_asset);
  }

  /**
   * @notice Converts collateral type from standard to locked and vice versa
   * @param _asset address of an asset
   * @param _depositor address of a depositor
   * @param _amount amount for asset
   * @param _fromLockedCollateral converion type flag
   */
  // solhint-disable-next-line max-line-length
  function _convertCollateral(address _asset, address _depositor, uint256 _amount, bool _fromLockedCollateral) internal {
    _accrueInterest(_asset);

    AssetState storage _state = _assetState[_asset];
    uint256 totalDepositsCached;
    uint256 collateralShare;
    uint256 withdrawnAmount;

    (withdrawnAmount,,) = _withdrawAsset(_asset, _amount, _depositor, _fromLockedCollateral, 0);

    if (_fromLockedCollateral) {
      totalDepositsCached = _state.totalDeposits;
      collateralShare = withdrawnAmount.toShare(totalDepositsCached, _state.collateralToken.totalSupply());
      _state.totalDeposits = totalDepositsCached + withdrawnAmount;
      _state.collateralToken.mint(_depositor, collateralShare);
      if (!isSolvent(_depositor)) revert NotSolvent();
    } else {
      totalDepositsCached = _state.totalLockedDeposits;
      collateralShare = withdrawnAmount.toShare(totalDepositsCached, _state.lockedCollateralToken.totalSupply());
      _state.totalLockedDeposits = totalDepositsCached + withdrawnAmount;
      _state.lockedCollateralToken.mint(_depositor, collateralShare);
    }

    emit SupplyCollateral(_asset, _depositor, _depositor, withdrawnAmount, collateralShare, !_fromLockedCollateral);
  }

  /**
   * @notice Supplies asset as collateral with a given type
   * @param _asset address of an asset
   * @param _depositor address of a depositor
   * @param _receiver address of collateral tokens receiver
   * @param _amount amount for asset
   * @param _lockedCollateral collateral type flag
   */
  function _supply(
    address _asset,
    address _depositor,
    address _receiver,
    uint256 _amount,
    bool _lockedCollateral
  ) internal {
    _checkSupplyPaused(_asset);
    _accrueInterest(_asset);

    AssetState storage _state = _assetState[_asset];

    uint256 collateralShare;
    uint256 totalDeposits = _lockedCollateral ? _state.totalLockedDeposits : _state.totalDeposits;

    if (_lockedCollateral) {
      collateralShare = _amount.toShare(totalDeposits, _state.lockedCollateralToken.totalSupply());
      _state.totalLockedDeposits = totalDeposits + _amount;
      _state.lockedCollateralToken.mint(_receiver, collateralShare);
    } else {
      collateralShare = _amount.toShare(totalDeposits, _state.collateralToken.totalSupply());
      _state.totalDeposits = totalDeposits + _amount;
      _state.collateralToken.mint(_receiver, collateralShare);
    }

    ERC20(_asset).safeTransferFrom(_depositor, address(this), _amount);

    _validateMaxSupplyLimitAfter(_asset);

    emit SupplyCollateral(_asset, _depositor, _receiver, _amount, collateralShare, _lockedCollateral);
  }

  /**
   * @notice Withdraws asset from collateral with a given type
   * @param _asset address of an asset
   * @param _depositor address of a depositor
   * @param _receiver address of asset tokens receiver
   * @param _amount amount for asset
   * @param _lockedCollateral collateral type flag
   */
  function _withdraw(
    address _asset,
    address _depositor,
    address _receiver,
    uint256 _amount,
    bool _lockedCollateral
  ) internal returns (uint256 withdrawnAmount, uint256 withdrawnShare) {
    _accrueInterest(_asset);
    uint256 amountToTransfer;

    (withdrawnAmount, amountToTransfer, withdrawnShare) = _withdrawAsset(
      _asset,
      _amount,
      _depositor,
      _lockedCollateral,
      0 // do not apply any fees on regular withdraw
    );

    if (withdrawnAmount == 0) revert ZeroWithdraw();

    ERC20(_asset).safeTransfer(_receiver, amountToTransfer);

    if (_lockedCollateral && !isSolvent(_depositor)) revert NotSolvent();
  }

  /**
   * @notice Calculates amount of asset to withdraw, updates state, burns collateral tokens
   * @param _asset address of an asset
   * @param _assetAmount amount for asset
   * @param _depositor address of a depositor
   * @param _lockedCollateral collateral type flag
   * @param _protocolLiquidationFee protocol liquidation fee
   * @return withdrawnAmount amount of withdrawn collateral tokens
   * @return amountToTransfer amount of underlying tokens to transfer
   * @return collateralShare amount of burns collateral tokens
   */
  function _withdrawAsset(
    address _asset,
    uint256 _assetAmount,
    address _depositor,
    bool _lockedCollateral,
    uint256 _protocolLiquidationFee
  ) internal returns (uint256 withdrawnAmount, uint256 amountToTransfer, uint256 collateralShare) {
    _checkWithdrawPaused(_asset);

    (uint256 assetTotalDeposits, ICollateralToken collateralToken, uint256 availableLiquidity) =
      getWithdrawAssetData(_asset, _lockedCollateral);

    if (_assetAmount == type(uint256).max) {
      collateralShare = collateralToken.balanceOf(_depositor);
      withdrawnAmount = collateralShare.toAmount(assetTotalDeposits, collateralToken.totalSupply());
    } else {
      collateralShare = _assetAmount.toShareRoundUp(assetTotalDeposits, collateralToken.totalSupply());
      withdrawnAmount = _assetAmount;
    }

    if (withdrawnAmount == 0) {
      // we can not revert here, because liquidation will fail when one of collaterals will be empty
      return (0, 0, 0);
    }

    if (assetTotalDeposits < withdrawnAmount) revert NotEnoughDeposits();

    unchecked {
      assetTotalDeposits -= withdrawnAmount;
    }

    amountToTransfer = _applyLiquidationFee(_asset, withdrawnAmount, _protocolLiquidationFee);

    if (availableLiquidity < amountToTransfer) revert NotEnoughLiquidity();

    AssetState storage _state = _assetState[_asset];

    if (_lockedCollateral) {
      _state.totalLockedDeposits = assetTotalDeposits;
    } else {
      _state.totalDeposits = assetTotalDeposits;
    }

    collateralToken.burn(_depositor, collateralShare);

    emit WithdrawCollateral(_asset, _depositor, amountToTransfer, collateralShare, _lockedCollateral);
  }

  /**
   * @notice Calculates liquidation fee
   * @param _asset address of an asset
   * @param _amount amount on which fee is applied
   * @param _protocolLiquidationFee protocol liquidation fee
   * @return change amount left after substracting fee
   */
  function _applyLiquidationFee(
    address _asset,
    uint256 _amount,
    uint256 _protocolLiquidationFee
  ) internal returns (uint256 change) {
    if (_protocolLiquidationFee == 0) {
      return _amount;
    }

    uint256 liquidationFeeAmount;

    (liquidationFeeAmount, _interestData[_asset].protocolFees) =
      Solvency.calculateLiquidationFee(_interestData[_asset].protocolFees, _amount, _protocolLiquidationFee);

    unchecked {
      // if fees will not be higher than 100% this will not underflow, this is responsibility of Repository
      // in case we do underflow, we can expect liquidator reject tx because of too little change
      change = _amount - liquidationFeeAmount;
    }
  }

  /**
   * @notice Function for standard overcollateralized borrowing action
   * @param _asset address of an asset
   * @param _borrower address that will receive debt tokens
   * @param _receiver address that will receive borrowed tokens
   * @param _amount amount of asset to borrow
   */
  function _borrow(address _asset, address _borrower, address _receiver, uint256 _amount) internal {
    _checkWithdrawPaused(_asset);
    _accrueInterest(_asset);

    if (liquidity(_asset) < _amount) revert NotEnoughLiquidity();

    AssetState storage _state = _assetState[_asset];

    uint256 totalBorrowAmount = _state.totalBorrowAmount;
    uint256 entryFee = repository.entryFee();
    uint256 fee = entryFee == 0 ? 0 : _amount * entryFee / SharedData._FEE_PRECISION_DECIMALS;
    uint256 debtShare = (_amount + fee).toShareRoundUp(totalBorrowAmount, _state.debtToken.totalSupply());

    _state.totalBorrowAmount = totalBorrowAmount + _amount + fee;
    _interestData[_asset].protocolFees += fee;

    _state.debtToken.mint(_borrower, debtShare);

    ERC20(_asset).safeTransfer(_receiver, _amount);

    _validateBorrowAfter(_borrower);

    emit Borrow(_asset, _borrower, _receiver, _amount, debtShare);
  }

  /**
   * @notice Function that allows to borrow for a trade inside settlement
   * @param _asset address of an asset
   * @param _borrower address that will receive debt tokens
   * @param _source address from which trade asset will be received
   * @param _recipient address that will receive borrowed tokens
   * @param _amount amount of asset to borrow
   * @param _tradeAsset address of a trade asset
   * @param _tradeAmount amount of a trade asset
   */
  function _borrow(
    address _asset,
    address _borrower,
    address _source,
    address _recipient,
    uint256 _amount,
    address _tradeAsset,
    uint256 _tradeAmount
  ) internal {
    _checkPaused(_asset);
    _accrueInterest(_asset);
    _accrueInterest(_tradeAsset);

    if (liquidity(_asset) < _amount) revert NotEnoughLiquidity();

    AssetState storage _state = _assetState[_asset];

    uint256 totalBorrowAmount = _state.totalBorrowAmount;
    uint256 entryFee = repository.entryFee();
    uint256 fee = entryFee == 0 ? 0 : _amount * entryFee / SharedData._FEE_PRECISION_DECIMALS;
    uint256 debtShare = (_amount + fee).toShareRoundUp(totalBorrowAmount, _state.debtToken.totalSupply());

    _state.totalBorrowAmount = totalBorrowAmount + _amount + fee;
    _interestData[_asset].protocolFees += fee;

    _state.debtToken.mint(_borrower, debtShare);

    ERC20(_asset).safeTransfer(_recipient, _amount);

    _state = _assetState[_tradeAsset];

    uint256 totalDepositsCached = _state.totalLockedDeposits;

    uint256 collateralShare = _tradeAmount.toShare(totalDepositsCached, _state.lockedCollateralToken.totalSupply());
    _state.totalLockedDeposits = totalDepositsCached + _tradeAmount;
    _state.lockedCollateralToken.mint(_borrower, collateralShare);

    ERC20(_tradeAsset).safeTransferFrom(_source, address(this), _tradeAmount);

    _validateBorrowAfter(_borrower);
    _validateMaxSupplyLimitAfter(_tradeAsset);

    emit SupplyCollateral(_tradeAsset, _source, _borrower, _tradeAmount, collateralShare, true);
    emit Borrow(_asset, _borrower, _recipient, _amount, debtShare);
  }

  /**
   * @notice Harvest protocol fees generated from an asset
   * @param _asset address of an asset to harvest fees from
   * @param _receiver address that will receive fees
   */
  function _harvestProtocolFees(address _asset, address _receiver) internal returns (uint256 harvestedFees) {
    _checkWithdrawPaused(_asset);
    _accrueInterest(_asset);

    AssetInterestData storage data = _interestData[_asset];

    harvestedFees = data.protocolFees - data.harvestedProtocolFees;

    uint256 currentLiquidity = liquidity(_asset);

    if (harvestedFees > currentLiquidity) {
      harvestedFees = currentLiquidity;
    }

    if (harvestedFees == 0) {
      return 0;
    }

    unchecked {
      // This can't overflow because this addition is less than or equal to data.protocolFees
      data.harvestedProtocolFees += harvestedFees;
    }

    ERC20(_asset).safeTransfer(_receiver, harvestedFees);

    emit HarvestProtocolFees(_asset, _receiver, harvestedFees);
  }

  /**
   * @notice Allows to liquidate user's positon
   * @param _user address of a user to liquidate
   * @param _withdrawal array of liquidate params for withdrawal
   * @param _repays array of liquidate params for repay
   * @param _flashReceiver address for liquidation callback
   * @param _flashReceiverData calldata for liquidation callback
   * @return receivedCollaterals array of received collaterals
   * @return shareAmountsToRepay array of required amount of debt to be repaid
   */
  function _liquidate(
    address _user,
    LiquidateParams[] memory _withdrawal,
    LiquidateParams[] memory _repays,
    ILiquidationReceiver _flashReceiver,
    bytes memory _flashReceiverData
  ) internal returns (LiquidateParams[] memory receivedCollaterals, LiquidateParams[] memory shareAmountsToRepay) {
    (uint256 cachedUserLTV, uint256 cachedLiquidationThreshold) = getUserLTV(_user);

    if (cachedUserLTV <= cachedLiquidationThreshold) {
      LiquidateParams[] memory emptyW = new LiquidateParams[](_withdrawal.length);
      LiquidateParams[] memory emptyR = new LiquidateParams[](_repays.length);
      return (emptyW, emptyR);
    }

    (receivedCollaterals, shareAmountsToRepay) = _liquidation(_withdrawal, _repays, _user, address(_flashReceiver));

    _flashReceiver.liquidationCallback(_user, receivedCollaterals, shareAmountsToRepay, _flashReceiverData);

    (uint256 userLTV, uint256 liquidationThreshold) = getUserLTV(_user);

    if (userLTV > liquidationThreshold) {
      if (
        (userLTV >= cachedUserLTV) || ((userLTV * cachedLiquidationThreshold) >= (cachedUserLTV * liquidationThreshold))
      ) {
        revert LiquidationNotSuccessful();
      }
    }
  }

  /**
   * @notice Allows to liquidate user's positon by the liquidator
   * @param _withdrawal array of liquidate params for withdrawal
   * @param _repays array of liquidate params for repay
   * @param _borrower address of a user to liquidate
   * @param _liquidator address of a liquidator
   * @return receivedCollaterals array of received collaterals
   * @return amountsToRepay array of required amount of debt to be repaid
   */
  function _liquidation(
    LiquidateParams[] memory _withdrawal,
    LiquidateParams[] memory _repays,
    address _borrower,
    address _liquidator
  ) internal returns (LiquidateParams[] memory receivedCollaterals, LiquidateParams[] memory amountsToRepay) {
    uint256 withdrawalLength = _withdrawal.length;
    receivedCollaterals = new LiquidateParams[](withdrawalLength);

    uint256 protocolLiquidationFee = repository.protocolLiquidationFee();

    for (uint256 i = 0; i < withdrawalLength; i++) {
      _accrueInterest(_withdrawal[i].asset);

      (uint256 withdrawnAmount, uint256 amountToTransfer,) =
        _withdrawAsset(_withdrawal[i].asset, _withdrawal[i].amount, _borrower, true, protocolLiquidationFee);

      ERC20(_withdrawal[i].asset).safeTransfer(_liquidator, amountToTransfer);

      receivedCollaterals[i].amount = withdrawnAmount;
      receivedCollaterals[i].asset = _withdrawal[i].asset;
    }

    uint256 repayLength = _repays.length;

    amountsToRepay = new LiquidateParams[](repayLength);

    for (uint256 i = 0; i < repayLength; i++) {
      AssetState storage _state = _assetState[_repays[i].asset];
      (uint256 amountToRepay,) = _calculateDebtAmountAndShare(_state, _borrower, _repays[i].amount);

      amountsToRepay[i].asset = _repays[i].asset;
      amountsToRepay[i].amount = amountToRepay;
    }
  }

  /**
   * @notice Function that allows to repay debt
   * @param _asset address of an asset
   * @param _borrower address that for which to repay
   * @param _repayer address from which asset will be received as repay
   * @param _amount amount of asset to borrow
   */
  function _repay(address _asset, address _borrower, address _repayer, uint256 _amount) internal {
    _checkSupplyPaused(_asset);
    _accrueInterest(_asset);

    AssetState storage _state = _assetState[_asset];

    (uint256 repayAmount, uint256 repayShare) = _calculateDebtAmountAndShare(_state, _borrower, _amount);

    if (repayShare == 0) revert ZeroRepay();

    ERC20(_asset).safeTransferFrom(_repayer, address(this), repayAmount);

    _state.debtToken.burn(_borrower, repayShare);
    _state.totalBorrowAmount -= repayAmount;

    emit Repay(_asset, _borrower, _repayer, repayAmount, repayShare);
  }

  /**
   * @notice Accrue interest for asset using interest rate model
   * @param _asset address of an asset
   * @return accruedInterest total accrued interest
   */
  function _accrueInterest(
    address _asset
  ) internal returns (uint256 accruedInterest) {
    AssetState storage _state = _assetState[_asset];
    AssetInterestData storage _assetInterestData = _interestData[_asset];

    if (_assetInterestData.interestTimestamp == block.timestamp) {
      return 0;
    }

    uint256 rcur = _getModel(_asset).getInterestRateAndUpdate(_asset);
    uint256 protocolShareFee = repository.protocolShareFee();

    uint256 totalBorrowAmountCached = _state.totalBorrowAmount;
    uint256 protocolFeesCached = _assetInterestData.protocolFees;
    uint256 newProtocolFees;
    uint256 protocolShare;
    uint256 depositorsShare;

    accruedInterest = totalBorrowAmountCached * rcur / SharedData._PRECISION_DECIMALS;

    unchecked {
      protocolShare = accruedInterest * protocolShareFee / SharedData._FEE_PRECISION_DECIMALS;
      newProtocolFees = protocolFeesCached + protocolShare;
      depositorsShare = accruedInterest - protocolShare;
    }

    // update state
    _state.totalBorrowAmount = totalBorrowAmountCached + accruedInterest;
    _state.totalDeposits = _state.totalDeposits + depositorsShare;
    _assetInterestData.protocolFees = newProtocolFees;
    _assetInterestData.interestTimestamp = block.timestamp;
  }

  /**
   * @notice Calculates amount for asset to repay
   * @param _state asset state
   * @param _borrower address of a borrower
   * @param _amount proposed amount to repay
   * @return amount amount of asset to repay
   * @return repayShare amount of debt tokens
   */
  function _calculateDebtAmountAndShare(
    AssetState storage _state,
    address _borrower,
    uint256 _amount
  ) internal view returns (uint256 amount, uint256 repayShare) {
    uint256 borrowerDebtBalance = _state.debtToken.balanceOf(_borrower);
    uint256 debtTokenTotalSupply = _state.debtToken.totalSupply();
    uint256 totalBorrowed = _state.totalBorrowAmount;
    uint256 maxAmount = borrowerDebtBalance.toAmountRoundUp(totalBorrowed, debtTokenTotalSupply);

    if (_amount >= maxAmount) {
      amount = maxAmount;
      repayShare = borrowerDebtBalance;
    } else {
      amount = _amount;
      repayShare = _amount.toShare(totalBorrowed, debtTokenTotalSupply);
    }
  }

  /**
   * @notice Get interest rate model for a given asset
   * @param _asset address of an asset
   * @return IInterestRateModel address of an interest rate model
   */
  function _getModel(
    address _asset
  ) internal view returns (IInterestRateModel) {
    return IInterestRateModel(repository.getInterestRateModel(address(this), _asset));
  }

  /**
   * @notice Generates metadata for utility tokens
   * @param _asset address of an asset
   * @return metadata metadata for utility tokens
   */
  function _generateMetadata(
    address _asset
  ) internal view returns (UtilityTokensMetadata memory metadata) {
    string memory assetSymbol = IERC20Metadata(_asset).symbol();

    metadata = UtilityTokensMetadata({
      collateralName: string.concat('Liquorice LP ', assetSymbol),
      collateralSymbol: string.concat('LLP', assetSymbol),
      lockedCollateralName: string.concat('Liquorice Locked Collateral ', assetSymbol),
      lockedCollateralSymbol: string.concat('LLC', assetSymbol),
      debtName: string.concat('Liquorice Debt ', assetSymbol),
      debtSymbol: string.concat('LD', assetSymbol)
    });
  }

  /**
   * @notice Get state for a matching collateral type
   * @param _asset address of an asset
   * @param _lockedCollateral type of collateral flag
   * @return assetTotalDeposits asset total deposits
   * @return collateralToken address of a collateral token
   * @return availableLiquidity available liquidity
   */
  function getWithdrawAssetData(
    address _asset,
    bool _lockedCollateral
  ) public view returns (uint256 assetTotalDeposits, ICollateralToken collateralToken, uint256 availableLiquidity) {
    AssetState storage _state = _assetState[_asset];

    if (_lockedCollateral) {
      assetTotalDeposits = _state.totalLockedDeposits;
      collateralToken = _state.lockedCollateralToken;
      availableLiquidity = assetTotalDeposits;
    } else {
      assetTotalDeposits = _state.totalDeposits;
      collateralToken = _state.collateralToken;
      availableLiquidity = liquidity(_asset);
    }
  }

  /**
   * @notice Verifies if user exceeded appropriate loan-to-value after borrowing action
   * @param _user address of a user
   */
  function _validateBorrowAfter(
    address _user
  ) private view {
    (address[] memory assets, AssetState[] memory assetsStates) = getAssetsWithState();

    (uint256 userLTV, uint256 maximumAllowedLTV) = Solvency.calculateLTVs(
      Solvency.SolvencyParams(repository, ILendingPool(address(this)), assets, assetsStates, _user),
      Solvency.TypeofLTV.MaximumLTV
    );

    if (userLTV > maximumAllowedLTV) revert MaximumLTVReached();
  }

  /**
   * @notice Verifies if maximum supply limit for an asset was exceeded
   * @param _asset address of an asset
   */
  function _validateMaxSupplyLimitAfter(
    address _asset
  ) private view {
    IPriceProvider priceProvider = repository.priceProvider();

    AssetState storage assetState = _assetState[_asset];
    uint256 allDeposits = assetState.totalDeposits + assetState.totalLockedDeposits;

    if (
      priceProvider.getPrice(_asset) * allDeposits / (10 ** IERC20Metadata(_asset).decimals())
        > repository.getMaxSupplyLimit(address(this), _asset)
    ) {
      revert MaxSupplyLimitExceeded();
    }
  }

  /**
   * @notice Verifies if user is allowlisted maker
   * @param _user address of a user
   */
  function _validateIsMaker(
    address _user
  ) private view {
    if (!IAllowListAuthentication(ISettlement(repository.settlement()).AUTHENTICATOR()).isMaker(_user)) {
      revert BorrowerNotMaker();
    }
  }

  /**
   * @notice Verifies if supply, withdraw or all action are paused
   * @param _asset address of an asset
   */
  function _checkPaused(
    address _asset
  ) private view {
    IRepository.PauseType pause = repository.getPauseStatus(address(this), _asset);
    if (
      pause == IRepository.PauseType.PAUSED || pause == IRepository.PauseType.SUPPLY_PAUSED
        || pause == IRepository.PauseType.WITHDRAW_PAUSED
    ) {
      revert ActionPaused();
    }
  }

  /**
   * @notice Verifies if supply action or all action are paused
   * @param _asset address of an asset
   */
  function _checkSupplyPaused(
    address _asset
  ) private view {
    IRepository.PauseType pause = repository.getPauseStatus(address(this), _asset);
    if (pause == IRepository.PauseType.PAUSED || pause == IRepository.PauseType.SUPPLY_PAUSED) {
      revert ActionPaused();
    }
  }

  /**
   * @notice Verifies if withdraw action or all action are paused
   * @param _asset address of an asset
   */
  function _checkWithdrawPaused(
    address _asset
  ) private view {
    IRepository.PauseType pause = repository.getPauseStatus(address(this), _asset);
    if (pause == IRepository.PauseType.PAUSED || pause == IRepository.PauseType.WITHDRAW_PAUSED) {
      revert ActionPaused();
    }
  }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC-20
 * applications.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

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

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

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     *
     * ```solidity
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance < type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(spender, currentAllowance, value);
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

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

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

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

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

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

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Interface for the optional metadata functions from the ERC-20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    /**
     * @dev An operation with an ERC-20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}

File 6 of 30 : SharedData.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.23;

/**
 * @title SharedData
 * @dev Library for storing shared constants used across contracts
 */
library SharedData {
  /// @notice Precision decimals used for calculations
  uint256 internal constant _PRECISION_DECIMALS = 1e18;

  /// @notice Precision decimals used for fees
  uint256 internal constant _FEE_PRECISION_DECIMALS = 100_000; // 100%
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.23;

import {Math} from '@openzeppelin/contracts/utils/math/Math.sol';

/**
 * @title SharesMath
 * @dev Library for performing calculations related to shares and amounts
 */
library SharesMath {
  using Math for uint256;

  uint256 internal constant _DECIMALS_OFFSET = 3;

  /// @dev This is a constant version of openzeppelin/contracts/token/ERC20/extensions/ERC4626._decimalsOffset
  uint256 internal constant _DECIMALS_OFFSET_POW = 10 ** _DECIMALS_OFFSET;

  error ZeroAssets();
  error ZeroShares();

  /**
   * @notice Converts an amount to shares
   * @param amount Amount to convert
   * @param totalAmount Total amount of assets
   * @param totalShares Total number of shares
   * @return result Equivalent number of shares
   */
  function toShare(uint256 amount, uint256 totalAmount, uint256 totalShares) internal pure returns (uint256 result) {
    result = amount.mulDiv(totalShares + _DECIMALS_OFFSET_POW, totalAmount + 1, Math.Rounding.Floor);
  }

  /**
   * @notice Converts an amount to shares, rounding up
   * @param amount Amount to convert
   * @param totalAmount Total amount of assets
   * @param totalShares Total number of shares
   * @return result Equivalent number of shares, rounded up
   */
  function toShareRoundUp(
    uint256 amount,
    uint256 totalAmount,
    uint256 totalShares
  ) internal pure returns (uint256 result) {
    result = amount.mulDiv(totalShares + _DECIMALS_OFFSET_POW, totalAmount + 1, Math.Rounding.Ceil);
  }

  /**
   * @notice Converts shares to an amount
   * @param share Number of shares to convert
   * @param totalAmount Total amount of assets
   * @param totalShares Total number of shares
   * @return result Equivalent amount of assets
   */
  function toAmount(uint256 share, uint256 totalAmount, uint256 totalShares) internal pure returns (uint256 result) {
    result = share.mulDiv(totalAmount + 1, totalShares + _DECIMALS_OFFSET_POW, Math.Rounding.Floor);
  }

  /**
   * @notice Converts shares to an amount, rounding up
   * @param share Number of shares to convert
   * @param totalAmount Total amount of assets
   * @param totalShares Total number of shares
   * @return result Equivalent amount of assets, rounded up
   */
  function toAmountRoundUp(
    uint256 share,
    uint256 totalAmount,
    uint256 totalShares
  ) internal pure returns (uint256 result) {
    result = share.mulDiv(totalAmount + 1, totalShares + _DECIMALS_OFFSET_POW, Math.Rounding.Ceil);
  }

  /**
   * @notice Converts an asset amount to its value based on price and decimals
   * @param _assetAmount Amount of the asset
   * @param _assetPrice Price of the asset
   * @param _assetDecimals Number of decimals the asset uses
   * @return value Value of the asset amount
   */
  function toValue(
    uint256 _assetAmount,
    uint256 _assetPrice,
    uint256 _assetDecimals
  ) internal pure returns (uint256 value) {
    value = _assetAmount * _assetPrice;
    // Power of 10 can not be 0, so we can uncheck
    unchecked {
      value /= 10 ** _assetDecimals;
    }
  }

  /**
   * @notice Converts a value to an asset amount based on price and decimals
   * @param value Value to convert
   * @param price Price of the asset
   * @param decimals Number of decimals the asset uses
   * @return amount Equivalent amount of the asset
   */
  function fromValueToAmount(uint256 value, uint256 price, uint8 decimals) internal pure returns (uint256 amount) {
    amount = Math.mulDiv(value, 10 ** uint256(decimals), price, Math.Rounding.Floor);
  }

  /**
   * @notice Sums an array of numbers
   * @param _numbers Array of numbers to sum
   * @return s Sum of the numbers
   */
  function sum(
    uint256[] memory _numbers
  ) internal pure returns (uint256 s) {
    for (uint256 i; i < _numbers.length;) {
      s += _numbers[i];
      unchecked {
        i++;
      }
    }
  }

  /**
   * @notice Calculates the utilization of an asset
   * @param _dp Decimal precision
   * @param _totalDeposits Total deposits of the asset
   * @param _totalBorrowAmount Total borrowed amount of the asset
   * @return Utilization rate of the asset
   */
  function calculateUtilization(
    uint256 _dp,
    uint256 _totalDeposits,
    uint256 _totalBorrowAmount
  ) internal pure returns (uint256) {
    if (_totalDeposits == 0 || _totalBorrowAmount == 0) return 0;

    return _totalBorrowAmount * _dp / _totalDeposits;
  }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.23;

import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol';

import {SharedData} from './SharedData.sol';
import {SharesMath} from './SharesMath.sol';
import {IInterestRateModel} from 'interfaces/IInterestRateModel.sol';
import {ILendingPool} from 'interfaces/ILendingPool.sol';
import {IPriceProvider} from 'interfaces/IPriceProvider.sol';
import {IRepository} from 'interfaces/IRepository.sol';

library Solvency {
  using SharesMath for uint256;

  enum TypeofLTV {
    MaximumLTV,
    LiquidationThreshold
  }

  struct SolvencyParams {
    IRepository repository;
    ILendingPool lendingPool;
    address[] assets;
    ILendingPool.AssetState[] assetStates;
    address user;
  }

  uint256 internal constant _INFINITY = type(uint256).max;

  error DifferentArrayLength();
  error UnsupportedLTVType();

  /**
   * @notice Calculates the current user's Loan-to-Value (LTV) and a secondary LTV based on the specified type
   * @param _params Struct containing repository, lending pool, assets, asset states, and user address
   * @param _secondLtvType Type of LTV to calculate (MaximumLTV or LiquidationThreshold)
   * @return currentUserLTV Current LTV of the user
   * @return secondLTV Secondary LTV based on the specified type
   */
  function calculateLTVs(
    SolvencyParams memory _params,
    TypeofLTV _secondLtvType
  ) internal view returns (uint256 currentUserLTV, uint256 secondLTV) {
    uint256[] memory totalBorrowAmounts = getBorrowAmounts(_params);

    // this return avoids eg. additional checks on withdraw, when user did not borrow any asset
    if (SharesMath.sum(totalBorrowAmounts) == 0) return (0, 0);

    IPriceProvider priceProviderRepository = _params.repository.priceProvider();

    uint256[] memory borrowValues = convertAmountsToValues(priceProviderRepository, _params.assets, totalBorrowAmounts);

    // value of user's total debt
    uint256 borrowTotalValue = SharesMath.sum(borrowValues);

    if (borrowTotalValue == 0) return (0, 0);

    uint256[] memory collateralValues = getUserCollateralValues(priceProviderRepository, _params);

    // value of user's collateral
    uint256 collateralTotalValue = SharesMath.sum(collateralValues);

    if (collateralTotalValue == 0) return (_INFINITY, 0);

    // value of theoretical debt user can have depending on TypeofLTV
    uint256 borrowAvailableTotalValue = _getTotalAvailableToBorrowValue(
      _params.repository, address(_params.lendingPool), _params.assets, _secondLtvType, collateralValues
    );

    currentUserLTV = borrowTotalValue * SharedData._PRECISION_DECIMALS / collateralTotalValue;

    // one of Solvency.TypeofLTV
    secondLTV = borrowAvailableTotalValue * SharedData._PRECISION_DECIMALS / collateralTotalValue;
  }

  /**
   * @notice Retrieves the collateral values for a user
   * @param _priceProvidersRepository Price provider repository
   * @param _params Struct containing repository, lending pool, assets, asset states, and user address
   * @return collateralValues Array of collateral values for each asset
   */
  function getUserCollateralValues(
    IPriceProvider _priceProvidersRepository,
    SolvencyParams memory _params
  ) internal view returns (uint256[] memory collateralValues) {
    uint256[] memory collateralAmounts = getCollateralAmounts(_params);
    collateralValues = convertAmountsToValues(_priceProvidersRepository, _params.assets, collateralAmounts);
  }

  /**
   * @notice Converts asset amounts to their respective values using current prices
   * @param _priceProviderRepo Price provider repository
   * @param _assets Array of asset addresses
   * @param _amounts Array of asset amounts
   * @return values Array of asset values
   */
  function convertAmountsToValues(
    IPriceProvider _priceProviderRepo,
    address[] memory _assets,
    uint256[] memory _amounts
  ) internal view returns (uint256[] memory values) {
    if (_assets.length != _amounts.length) revert DifferentArrayLength();

    values = new uint256[](_assets.length);

    for (uint256 i = 0; i < _assets.length; i++) {
      if (_amounts[i] == 0) continue;

      uint256 assetPrice = _priceProviderRepo.getPrice(_assets[i]);
      uint8 assetDecimals = ERC20(_assets[i]).decimals();

      values[i] = _amounts[i].toValue(assetPrice, assetDecimals);
    }
  }

  /**
   * @notice Calculates the available borrow amount for a specific asset
   * @param _params Struct containing repository, lending pool, assets, asset states, and user address
   * @param _asset Asset address
   * @return availableBorrowAmount Available borrow amount for the asset
   */
  function getAvailableBorrowAmount(
    SolvencyParams memory _params,
    address _asset
  ) internal view returns (uint256 availableBorrowAmount) {
    uint256[] memory totalBorrowAmounts = getBorrowAmounts(_params);
    IPriceProvider priceProviderRepository = _params.repository.priceProvider();

    uint256[] memory borrowValues = convertAmountsToValues(priceProviderRepository, _params.assets, totalBorrowAmounts);
    uint256 borrowTotalValue = SharesMath.sum(borrowValues);

    uint256[] memory collateralValues = getUserCollateralValues(priceProviderRepository, _params);
    uint256 collateralTotalValue = SharesMath.sum(collateralValues);

    if (collateralTotalValue == 0) return 0;

    uint256 totalAvailableToBorrowValue = _getTotalAvailableToBorrowValue(
      _params.repository, address(_params.lendingPool), _params.assets, TypeofLTV.MaximumLTV, collateralValues
    );

    if (borrowTotalValue >= totalAvailableToBorrowValue) return 0;

    uint256 borrowableValue = totalAvailableToBorrowValue - borrowTotalValue;

    uint256 tokenPrice = priceProviderRepository.getPrice(_asset);
    uint8 tokenDecimals = ERC20(_asset).decimals();

    availableBorrowAmount = borrowableValue.fromValueToAmount(tokenPrice, tokenDecimals);
  }

  /**
   * @notice Calculates the available withdraw amount for a specific asset
   * @param _params Struct containing repository, lending pool, assets, asset states, and user address
   * @param _asset Asset address
   * @param _maxWithdrawAmount Maximum amount that can be withdrawn from asset
   * @return availableWithdrawAmount Available withdraw amount for the asset
   */
  function getAvailableWithdrawAmount(
    SolvencyParams memory _params,
    address _asset,
    uint256 _maxWithdrawAmount
  ) internal view returns (uint256 availableWithdrawAmount) {
    uint256[] memory totalBorrowAmounts = getBorrowAmounts(_params);
    IPriceProvider priceProviderRepository = _params.repository.priceProvider();

    uint256[] memory borrowValues = convertAmountsToValues(priceProviderRepository, _params.assets, totalBorrowAmounts);
    uint256 borrowTotalValue = SharesMath.sum(borrowValues);

    if (borrowTotalValue == 0) return _maxWithdrawAmount;

    uint256[] memory collateralValues = getUserCollateralValues(priceProviderRepository, _params);
    uint256 collateralTotalValue = SharesMath.sum(collateralValues);

    if (collateralTotalValue == 0) return 0;

    uint256 totalAvailableToBorrowValue = _getTotalAvailableToBorrowValue(
      _params.repository, address(_params.lendingPool), _params.assets, TypeofLTV.MaximumLTV, collateralValues
    );

    if (borrowTotalValue >= totalAvailableToBorrowValue) return 0;

    uint256 borrowableValue = totalAvailableToBorrowValue - borrowTotalValue;

    uint256 tokenPrice = priceProviderRepository.getPrice(_asset);
    uint8 tokenDecimals = ERC20(_asset).decimals();

    availableWithdrawAmount = borrowableValue.fromValueToAmount(tokenPrice, tokenDecimals);
  }

  /**
   * @notice Retrieves the collateral amounts for a user
   * @param _params Struct containing repository, lending pool, assets, asset states, and user address
   * @return collateralAmounts Array of collateral amounts for each asset
   */
  function getCollateralAmounts(
    SolvencyParams memory _params
  ) internal view returns (uint256[] memory collateralAmounts) {
    if (_params.assets.length != _params.assetStates.length) {
      revert DifferentArrayLength();
    }

    collateralAmounts = new uint256[](_params.assets.length);

    for (uint256 i = 0; i < _params.assets.length; i++) {
      uint256 userLockedCollateralTokenBalance = _params.assetStates[i].lockedCollateralToken.balanceOf(_params.user);

      if (userLockedCollateralTokenBalance == 0) continue;

      collateralAmounts[i] = getUserCollateralAmount(_params.assetStates[i], userLockedCollateralTokenBalance);
    }
  }

  /**
   * @notice Retrieves the total borrow amounts for a user
   * @param _params Struct containing repository, lending pool, assets, asset states, and user address
   * @return totalBorrowAmounts Array of total borrow amounts for each asset
   */
  function getBorrowAmounts(
    SolvencyParams memory _params
  ) internal view returns (uint256[] memory totalBorrowAmounts) {
    if (_params.assets.length != _params.assetStates.length) {
      revert DifferentArrayLength();
    }

    totalBorrowAmounts = new uint256[](_params.assets.length);

    for (uint256 i = 0; i < _params.assets.length; i++) {
      uint256 rcur = getRcur(_params.lendingPool, _params.repository, _params.assets[i]);
      totalBorrowAmounts[i] = getUserBorrowAmount(_params.assetStates[i], _params.user, rcur);
    }
  }

  /**
   * @notice Calculates the user's collateral amount for a specific asset
   * @param _assetStates Asset state information
   * @param _userLockedCollateralTokenBalance User's locked collateral token balance
   * @return assetLockedCollateralAmount User's total collateral amount for the asset
   */
  function getUserCollateralAmount(
    ILendingPool.AssetState memory _assetStates,
    uint256 _userLockedCollateralTokenBalance
  ) internal view returns (uint256 assetLockedCollateralAmount) {
    assetLockedCollateralAmount = _userLockedCollateralTokenBalance == 0
      ? 0
      : _userLockedCollateralTokenBalance.toAmount(
        _assetStates.totalLockedDeposits, _assetStates.lockedCollateralToken.totalSupply()
      );
  }

  /**
   * @notice Calculates the user's borrow amount for a specific asset
   * @param _assetStates Asset state information
   * @param _user User address
   * @param _rcur Current interest rate
   * @return User's total borrow amount for the asset
   */
  function getUserBorrowAmount(
    ILendingPool.AssetState memory _assetStates,
    address _user,
    uint256 _rcur
  ) internal view returns (uint256) {
    uint256 balance = _assetStates.debtToken.balanceOf(_user);
    if (balance == 0) return 0;

    uint256 totalBorrowAmountCached = totalBorrowAmountWithInterest(_assetStates.totalBorrowAmount, _rcur);
    return balance.toAmountRoundUp(totalBorrowAmountCached, _assetStates.debtToken.totalSupply());
  }

  /**
   * @notice Retrieves the current interest rate for a specific asset in a lending pool
   * @param _pool Lending pool interface
   * @param _repository Repository interface
   * @param _asset Asset address
   * @return rcur Current interest rate
   */
  function getRcur(ILendingPool _pool, IRepository _repository, address _asset) internal view returns (uint256 rcur) {
    IInterestRateModel model = _repository.getInterestRateModel(address(_pool), _asset);
    rcur = model.getCurrentInterestRate(address(_pool), _asset);
  }

  /**
   * @notice Calculates the liquidation fee and updates protocol earned fees
   * @param _protocolEarnedFees Current protocol earned fees
   * @param _amount Amount to calculate the fee on
   * @param _liquidationFee Liquidation fee percentage
   * @return liquidationFeeAmount Calculated liquidation fee amount
   * @return newProtocolEarnedFees Updated protocol earned fees
   */
  function calculateLiquidationFee(
    uint256 _protocolEarnedFees,
    uint256 _amount,
    uint256 _liquidationFee
  ) internal pure returns (uint256 liquidationFeeAmount, uint256 newProtocolEarnedFees) {
    unchecked {
      // If we overflow on multiplication it should not revert tx, we will get lower fees
      liquidationFeeAmount = _amount * _liquidationFee / SharedData._FEE_PRECISION_DECIMALS;

      if (_protocolEarnedFees > type(uint256).max - liquidationFeeAmount) {
        newProtocolEarnedFees = type(uint256).max;
        liquidationFeeAmount = type(uint256).max - _protocolEarnedFees;
      } else {
        newProtocolEarnedFees = _protocolEarnedFees + liquidationFeeAmount;
      }
    }
  }

  /**
   * @notice Calculates the total borrow amount with interest for an asset
   * @param _totalBorrowAmount Total borrow amount for the asset
   * @param _rcur Current interest rate
   * @return totalBorrowAmountWithInterests Total borrow amount with interest
   */
  function totalBorrowAmountWithInterest(
    uint256 _totalBorrowAmount,
    uint256 _rcur
  ) internal pure returns (uint256 totalBorrowAmountWithInterests) {
    totalBorrowAmountWithInterests = _totalBorrowAmount + _totalBorrowAmount * _rcur / SharedData._PRECISION_DECIMALS;
  }

  /**
   * @notice Calculates the available value to borrow for a specific asset
   * @param _repository Repository interface
   * @param _lendingPool Lending pool address
   * @param _asset Asset address
   * @param _type Type of LTV (MaximumLTV or LiquidationThreshold)
   * @param _collateralValue Collateral value for the asset
   * @return availableToBorrow Available value to borrow
   */
  function _getAvailableToBorrowValue(
    IRepository _repository,
    address _lendingPool,
    address _asset,
    TypeofLTV _type,
    uint256 _collateralValue
  ) private view returns (uint256 availableToBorrow) {
    uint256 assetLTV;

    if (_type == TypeofLTV.MaximumLTV) {
      assetLTV = _repository.getMaximumLTV(_lendingPool, _asset);
    } else if (_type == TypeofLTV.LiquidationThreshold) {
      assetLTV = _repository.getLiquidationThreshold(_lendingPool, _asset);
    } else {
      revert UnsupportedLTVType();
    }

    availableToBorrow = _collateralValue * assetLTV / SharedData._PRECISION_DECIMALS;
  }

  /**
   * @notice Calculates the total available value to borrow for all assets
   * @param _repository Repository interface
   * @param _lendingPool Lending pool address
   * @param _assets Array of asset addresses
   * @param _ltvType Type of LTV (MaximumLTV or LiquidationThreshold)
   * @param _collateralValues Array of collateral values for each asset
   * @return totalAvailableToBorrowValue Total available value to borrow
   * @dev Reverts if the lengths of _assets and _collateralValues do not match
   */
  function _getTotalAvailableToBorrowValue(
    IRepository _repository,
    address _lendingPool,
    address[] memory _assets,
    TypeofLTV _ltvType,
    uint256[] memory _collateralValues
  ) private view returns (uint256 totalAvailableToBorrowValue) {
    if (_assets.length != _collateralValues.length) revert DifferentArrayLength();

    for (uint256 i = 0; i < _assets.length; i++) {
      totalAvailableToBorrowValue +=
        _getAvailableToBorrowValue(_repository, _lendingPool, _assets[i], _ltvType, _collateralValues[i]);
    }
  }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {IERC20Metadata} from '@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol';

/**
 * @title ICollateralToken
 * @notice Interface for collateral tokens that represent locked collateral in lending pools
 */
interface ICollateralToken is IERC20Metadata {
  /**
   * @notice Mints collateral tokens to an account
   * @param _account Address to mint tokens to
   * @param _amount Amount of tokens to mint
   */
  function mint(address _account, uint256 _amount) external;

  /**
   * @notice Burns collateral tokens from an account
   * @param _account Address to burn tokens from
   * @param _amount Amount of tokens to burn
   */
  function burn(address _account, uint256 _amount) external;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

/**
 * @title IInterestRateModel
 * @notice Interface for interest rate calculation and configuration
 */
interface IInterestRateModel {
  struct Config {
    int256 r0;
    int256 r1;
    int256 r2;
    uint256 ri;
    int256 uopt;
    uint256 rMax;
    uint256 rMin;
  }

  /**
   * @dev Set the current asset config.
   * @param _pool Address of the pool for which the config is set
   * @param _asset Address of the asset for which the config is set
   * @param _config Current config for this token
   */
  function setConfig(address _pool, address _asset, Config calldata _config) external;

  /**
   * @notice Gets and updates the current interest rate for an asset
   * @param _asset Address of the asset
   * @return rcur Current interest rate
   */
  function getInterestRateAndUpdate(
    address _asset
  ) external returns (uint256 rcur);

  /**
   * @notice Returns the current asset config. If no config is found, returns the default one.
   * @param _pool Address of the pool where the config is searched for
   * @param _asset Address of the asset
   * @return Current configuration parameters
   */
  function getConfig(address _pool, address _asset) external returns (Config memory);

  /**
   * @notice Gets the current interest rate for a pool's asset without updating state
   * @param _pool Address of the lending pool
   * @param _asset Address of the asset
   * @return rcur Current interest rate
   */
  function getCurrentInterestRate(address _pool, address _asset) external view returns (uint256 rcur);

  /**
   * @notice Returns the current APR for pool and asset
   * @param _pool Address of the lending pool
   * @param _asset Address of the asset
   * @return apr Current APR
   */
  function getCurrentAPR(address _pool, address _asset) external view returns (uint256 apr);

  /**
   * @dev Returns the current rate.
   * @param _c Current config for this token
   * @param _totalDeposits Total amount deposited for this asset
   * @param _totalBorrowAmount Total amount borrowed for this asset
   * @return Current interest rate
   */
  function calculateCurrentInterestRate(
    Config memory _c,
    uint256 _totalDeposits,
    uint256 _totalBorrowAmount
  ) external pure returns (uint256);

  /// @dev DP is 18 decimal points used for integer calculations
  // solhint-disable-next-line func-name-mixedcase
  function DP() external pure returns (uint256);

  /// @dev Number of seconds in a year
  // solhint-disable-next-line func-name-mixedcase
  function SECONDS_PER_YEAR() external pure returns (uint256);
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {ICollateralToken} from 'interfaces/ICollateralToken.sol';
import {IDebtToken} from 'interfaces/IDebtToken.sol';

import {IRepository} from 'interfaces/IRepository.sol';
import {IUtilityTokensFactory} from 'interfaces/IUtilityTokensFactory.sol';

import {IInterestRateModel} from 'interfaces/IInterestRateModel.sol';

interface ILendingPool {
  struct AssetState {
    ICollateralToken collateralToken;
    ICollateralToken lockedCollateralToken;
    IDebtToken debtToken;
    uint256 totalDeposits;
    uint256 totalLockedDeposits;
    uint256 totalBorrowAmount;
  }

  struct UtilityTokensMetadata {
    string collateralName;
    string collateralSymbol;
    string lockedCollateralName;
    string lockedCollateralSymbol;
    string debtName;
    string debtSymbol;
  }

  struct AssetInterestData {
    uint256 protocolFees;
    uint256 harvestedProtocolFees;
    uint256 interestTimestamp;
  }

  struct AssetUtilizationData {
    uint256 totalDeposits;
    uint256 totalBorrowAmount;
    uint256 interestTimestamp;
  }

  struct LiquidateParams {
    uint256 amount;
    address asset;
  }

  function addAssets(IUtilityTokensFactory tokensFactory, address[] memory newAssets) external;

  /**
   * @notice Supplies asset as collateral with a given type
   * @param asset address of an asset
   * @param amount amount for asset
   * @param lockedCollateral collateral type flag
   */
  function supply(address asset, uint256 amount, bool lockedCollateral) external;

  /**
   * @notice Supplies asset as collateral with a given type on behalf of depositor
   * @param asset address of an asset
   * @param receiver address of collateral tokens receiver
   * @param amount amount for asset
   * @param lockedCollateral collateral type flag
   */
  function supplyFor(address asset, address receiver, uint256 amount, bool lockedCollateral) external;

  /**
   * @notice Withdraws asset from collateral with a given type
   * @param asset address of an asset
   * @param amount amount for asset
   * @param lockedCollateral collateral type flag
   */
  function withdraw(address asset, uint256 amount, bool lockedCollateral) external;

  /**
   * @notice Withdraws asset from collateral with a given type on behalf of depositor
   * @param asset address of an asset
   * @param depositor address of a depositor
   * @param receiver address of asset tokens receiver
   * @param amount amount for asset
   * @param lockedCollateral collateral type flag
   */
  function withdrawFor(
    address asset,
    address depositor,
    address receiver,
    uint256 amount,
    bool lockedCollateral
  ) external;

  /**
   * @notice Function for standard overcollateralized borrowing action
   * @param asset address of an asset
   * @param amount amount of asset to borrow
   */
  function borrow(address asset, uint256 amount) external;

  /**
   * @notice Function for standard overcollateralized borrowing action on behalf of borrower
   * @param asset address of an asset
   * @param borrower address that will receive debt tokens
   * @param receiver address that will receive borrowed tokens
   * @param amount amount of asset to borrow
   */
  function borrowFor(address asset, address borrower, address receiver, uint256 amount) external;

  /**
   * @notice Function that allows to borrow for a trade inside settlement
   * @param asset address of an asset
   * @param borrower address that will receive debt tokens
   * @param source address from which trade asset will be received
   * @param recipient address that will receive borrowed tokens
   * @param amount amount of asset to borrow
   * @param tradeAsset address of a trade asset
   * @param tradeAmount amount of a trade asset
   */
  function borrowFor(
    address asset,
    address borrower,
    address source,
    address recipient,
    uint256 amount,
    address tradeAsset,
    uint256 tradeAmount
  ) external;

  /**
   * @notice Converts collateral type from standard to locked and vice versa
   * @param asset address of an asset
   * @param amount amount for asset
   * @param fromLockedCollateral conversion collateral type flag
   */
  function convertCollateral(address asset, uint256 amount, bool fromLockedCollateral) external;

  /**
   * @notice Function that allows to repay debt
   * @param asset address of an asset
   * @param amount amount of asset to borrow
   */
  function repay(address asset, uint256 amount) external;

  /**
   * @notice Function that allows to repay debt on behalf of borrower
   * @param asset address of an asset
   * @param borrower address that for which to repay
   * @param amount amount of asset to borrow
   */
  function repayFor(address asset, address borrower, uint256 amount) external;

  /**
   * @notice Harvest protocol fees accross all assets
   * @return harvestedAmounts array of harvested amounts
   */
  function harvestProtocolFees() external returns (uint256[] memory harvestedAmounts);

  /**
   * @notice Allows to liquidate user's positon
   * @param _user address of a user to liquidate
   * @param _withdrawal array of liquidate params for withdrawal
   * @param _repay array of liquidate params for repay
   * @return receivedCollaterals array of received collaterals
   * @return shareAmountsToRepay array of required amount of debt to be repaid
   */
  function liquidate(
    address _user,
    LiquidateParams[] memory _withdrawal,
    LiquidateParams[] memory _repay,
    bytes memory _receiverData
  ) external returns (LiquidateParams[] memory receivedCollaterals, LiquidateParams[] memory shareAmountsToRepay);

  /**
   * @notice Rebalances depositor's collateral between assets using external swap connector
   * @param _fromAsset address of an asset to withdraw
   * @param _toAsset address of an asset to supply
   * @param _amount amount of asset to rebalance
   * @param _minReceiveQuantity minimum amount of asset to receive
   * @param _lockedCollateral collateral type flag
   * @param _isExactOutput is exact output flag
   */
  function rebalance(
    address _fromAsset,
    address _toAsset,
    uint256 _amount,
    uint256 _minReceiveQuantity,
    bool _lockedCollateral,
    bool _isExactOutput
  ) external;

  /**
   * @notice Accrues interest for a given asset
   * @param _asset address of an asset
   * @return accruedInterest amount of accrued interest
   */
  function accrueInterest(
    address _asset
  ) external returns (uint256 accruedInterest);

  /**
   * @notice Get utilization data of an asset
   * @param _asset address of an asset
   * @return data asset utilization data
   */
  function assetUtilizationData(
    address _asset
  ) external view returns (AssetUtilizationData memory data);

  /**
   * @notice Get repository
   * @return IRepository address of the repository
   */
  function repository() external view returns (IRepository);

  /**
   * @notice Get state of an asset
   * @param asset address of an asset
   * @return AssetState struct state of an asset
   */
  function getAssetState(
    address asset
  ) external view returns (AssetState memory);

  /**
   * @notice Get all assets with their state
   * @return assets array of assets addresses
   * @return assetsState array of state structs of assets
   */
  function getAssetsWithState() external view returns (address[] memory assets, AssetState[] memory assetsState);

  /**
   * @notice Calculates solvency of a user address
   * @param _user address of a user
   * @return true if solvent, false otherwise
   */
  function isSolvent(
    address _user
  ) external view returns (bool);

  /**
   * @notice Get interest data of an asset
   * @param _asset address of an asset
   * @return AssetInterestData struct of interest data
   */
  function interestData(
    address _asset
  ) external view returns (AssetInterestData memory);

  function getWithdrawAssetData(
    address _asset,
    bool _lockedCollateral
  ) external view returns (uint256 assetTotalDeposits, ICollateralToken collateralToken, uint256 availableLiquidity);
}

File 12 of 30 : ILiquidationReceiver.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {ILendingPool} from './ILendingPool.sol';

interface ILiquidationReceiver {
  function liquidationCallback(
    address _user,
    ILendingPool.LiquidateParams[] calldata _receivedCollaterals,
    ILendingPool.LiquidateParams[] calldata _shareAmountsToRepaid,
    bytes memory _flashReceiverData
  ) external;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

interface IPriceProvider {
  function getPrice(
    address _asset
  ) external view returns (uint256 price);

  function assetSupported(
    address _asset
  ) external view returns (bool);

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

// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {IACLManager} from './IACLManager.sol';

import {IPriceProvider} from './IPriceProvider.sol';
import {IInterestRateModel} from 'interfaces/IInterestRateModel.sol';

interface IRepository is IACLManager {
  enum PauseType {
    /// @dev not paused status
    NOT_PAUSED,
    /// @dev all actions are paused
    PAUSED,
    /// @dev only action with supply of an asset are paused
    SUPPLY_PAUSED,
    /// @dev only action with withdrawal of an asset are paused
    WITHDRAW_PAUSED
  }

  struct Fees {
    uint64 entryFee;
    uint64 protocolShareFee;
    uint64 protocolLiquidationFee;
  }

  struct AssetConfig {
    IInterestRateModel interestRateModel;
    uint256 maxSupplyLimit;
    uint64 maxLoanToValue;
    uint64 liquidationThreshold;
  }

  /**
   * @notice Deploys new lending pool and adds assets to it
   * @param assets array of assets to add
   * @param configs array of configs for assets
   * @return createdPool deployed lending pool address
   */
  function newLendingPool(
    address[] calldata assets,
    IInterestRateModel.Config[] calldata configs
  ) external returns (address createdPool);

  /**
   * @notice Adds new assets to a lending pool
   * @param _lendingPool address of a lending pool
   * @param _assets array of assets to add
   * @param _configs array of configs for assets
   */
  function newAssets(
    address _lendingPool,
    address[] calldata _assets,
    IInterestRateModel.Config[] calldata _configs
  ) external;

  /**
   * @notice Set factory contract for deploying new lending pools
   * @param _newLendingPoolsFactory address of a new lending pools factory
   */
  function setLendingPoolsFactory(
    address _newLendingPoolsFactory
  ) external;

  /**
   * @notice Set factory contract for deploying new collateral, locked collateral and debt tokens
   * @param _newTokensFactory address of a new tokens factory
   */
  function setTokensFactory(
    address _newTokensFactory
  ) external;

  /**
   * @notice Set default interest rate model
   * @param _defaultInterestRateModel address of a new default interest rate model
   */
  function setDefaultInterestRateModel(
    IInterestRateModel _defaultInterestRateModel
  ) external;

  /**
   * @notice Set default maximum loan-to-value
   * @param _defaultMaxLoanToValue new default loan-to-value
   */
  function setDefaultMaxLoanToValue(
    uint64 _defaultMaxLoanToValue
  ) external;

  /**
   * @notice Set default liquidation threshold
   * @param _defaultLiquidationThreshold new default liquidation threshold
   */
  function setDefaultLiquidationThreshold(
    uint64 _defaultLiquidationThreshold
  ) external;

  /**
   * @notice Set default maximum supply limit in quote token
   * @param _defaulMaxSupplyLimit new default maximum supply limit
   */
  function setDefaultMaxSupplyLimit(
    uint256 _defaulMaxSupplyLimit
  ) external;

  /**
   * @notice Set default interest rate model for an asset in a lending pool
   * @param _lendingPool address of a lending pool
   * @param _asset address of an asset
   * @param _interestRateModel address of a new interest rate model
   */
  function setInterestRateModel(address _lendingPool, address _asset, IInterestRateModel _interestRateModel) external;

  /**
   * @notice Set maximum loan-to-value for an asset in a lending pool
   * @param _lendingPool address of a lending pool
   * @param _asset address of an asset
   * @param _maxLoanToValue new loan-to-value
   */
  function setMaxLoanToValue(address _lendingPool, address _asset, uint64 _maxLoanToValue) external;

  /**
   * @notice Set liquidation threshold for an asset in a lending pool
   * @param _lendingPool address of a lending pool
   * @param _asset address of an asset
   * @param _liquidationThreshold new liquidation threshold
   */
  function setLiquidationThreshold(address _lendingPool, address _asset, uint64 _liquidationThreshold) external;

  /**
   * @notice Set maximum supply limit in quote token for an asset in a lending pool
   * @param _lendingPool address of a lending pool
   * @param _asset address of an asset
   * @param _maxSupplyLimit new maximum supply limit in quote token
   */
  function setMaxSupplyLimit(address _lendingPool, address _asset, uint256 _maxSupplyLimit) external;

  /**
   * @notice Set protocol fees
   * @param _fees new protocol fees
   */
  function setFees(
    Fees calldata _fees
  ) external;

  /**
   * @notice Set swap connector
   * @param _newSwapConnector new swap connector
   */
  function setSwapConnector(
    address _newSwapConnector
  ) external;

  /**
   * @notice Set liquorice settlement contract
   * @param _settlement new liquorice settlement contract
   */
  function setSettlement(
    address _settlement
  ) external;

  /**
   * @notice Set price provider
   * @param _priceProvider new price provider
   */
  function setPriceProvider(
    IPriceProvider _priceProvider
  ) external;

  /**
   * @notice Set global limit of maximum supplied assets in quote token
   * @param _globalLimit new global limit value
   */
  function setGlobalSupplyLimit(
    bool _globalLimit
  ) external;

  /**
   * @notice Set global pause for lending pools interactions
   * @param _globalPause new global pause value
   */
  function setGlobalPause(
    bool _globalPause
  ) external;

  /**
   * @notice Set pause for specific lending pool's asset interactions
   * @param _lendingPool address of a lending pool
   * @param _asset address of an asset
   * @param _pauseType type of pause
   */
  function setPause(address _lendingPool, address _asset, PauseType _pauseType) external;

  /**
   * @notice Get address of the Liquorice Settlement contract
   * @return address of LiquoriceSettlement contract
   */
  function settlement() external view returns (address);

  /**
   * @notice Get address of default role admin
   * @return address of default role admin
   */
  function aclAdmin() external view returns (address);

  /**
   * @notice Get global supply limit flag value
   * @return bool global supply limit flag value
   */
  function globalSupplyLimit() external view returns (bool);

  /**
   * @notice Get global pause flag value
   * @return bool global pause flag value
   */
  function globalPause() external view returns (bool);

  /**
   * @notice Get interest rate model for specific lending pool and asset
   * @param _lendingPool address of a lending pool
   * @param _asset address of an asset
   * @return model address of interest rate model
   */
  function getInterestRateModel(address _lendingPool, address _asset) external view returns (IInterestRateModel model);

  /**
   * @notice Get maximum loan-to-value for specific lending pool and asset
   * @param _lendingPool address of a lending pool
   * @param _asset address of an asset
   * @return uint256 maximum loan-to-value
   */
  function getMaximumLTV(address _lendingPool, address _asset) external view returns (uint256);

  /**
   * @notice Get liquidation threshold for specific lending pool and asset
   * @param _lendingPool address of a lending pool
   * @param _asset address of an asset
   * @return uint256 liquidation threshold
   */
  function getLiquidationThreshold(address _lendingPool, address _asset) external view returns (uint256);

  /**
   * @notice Get maximum supply limit in quote token for specific lending pool and asset
   * @param _lendingPool address of a lending pool
   * @param _asset address of an asset
   * @return uint256 maximum supply limit in quote token
   */
  function getMaxSupplyLimit(address _lendingPool, address _asset) external view returns (uint256);

  /**
   * @notice Get pause status for specific lending pool and asset
   * @param _lendingPool address of a lending pool
   * @param _asset address of an asset
   * @return PauseType type of pause set
   */
  function getPauseStatus(address _lendingPool, address _asset) external view returns (PauseType);

  /**
   * @notice Get fee for entering the lending pool
   * @return uint256 entry fee
   */
  function entryFee() external view returns (uint256);

  /**
   * @notice Check if contract address is existing lending pool
   * @return true if address is lending pool, otherwise faulse
   */
  function isLendingPool(
    address _lendingPool
  ) external view returns (bool);

  /**
   * @notice Get PriceProvider contract
   * @return IPriceProvider address
   */
  function priceProvider() external view returns (IPriceProvider);

  /**
   * @notice Get protocol share fee value
   * @return uint256 protocol share fee
   */
  function protocolShareFee() external view returns (uint256);

  /**
   * @notice Get protocol liquidation fee value
   * @return uint256 protocol liquidation fee
   */
  function protocolLiquidationFee() external view returns (uint256);

  /**
   * @notice Get swap connector contract address
   * @return address of swap connector contract
   */
  function swapConnector() external view returns (address);
}

File 15 of 30 : ISettlement.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {IAllowListAuthentication} from './IAllowListAuthentication.sol';

interface ISettlement {
  function AUTHENTICATOR() external view returns (IAllowListAuthentication);
}

File 16 of 30 : ISwapConnector.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

interface ISwapConnector {
  function trade(
    address _receiver,
    address _fromToken,
    address _toToken,
    uint256 _amount,
    uint256 _minReceiveQuantity,
    bool _isExactOutput
  ) external returns (uint256);
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {ICollateralToken} from './ICollateralToken.sol';
import {IDebtToken} from './IDebtToken.sol';

/**
 * @title IUtilityTokensFactory
 * @notice Interface for factory contract that creates collateral and debt tokens
 */
interface IUtilityTokensFactory {
  /**
   * @notice Emitted when a new collateral token is created
   * @param token Address of the newly created collateral token
   */
  event NewCollateralTokenCreated(address indexed token);

  /**
   * @notice Emitted when a new debt token is created
   * @param token Address of the newly created debt token
   */
  event NewDebtTokenCreated(address indexed token);

  /**
   * @notice Creates new collateral token for a lending pool
   * @param _name Name of collateral token
   * @param _symbol Symbol of collateral token
   * @param _lendingPool Address of lending pool contract
   * @param _asset Address of underlying asset
   * @param _lockedCollateral Collateral type flag
   * @return token Address of created collateral token
   */
  function createCollateralToken(
    string memory _name,
    string memory _symbol,
    address _lendingPool,
    address _asset,
    bool _lockedCollateral
  ) external returns (ICollateralToken);

  /**
   * @notice Creates new debt token for a lending pool
   * @param _name Name of debt token
   * @param _symbol Symbol of debt token
   * @param _lendingPool Address of lending pool contract
   * @param _asset Address of underlying asset
   * @return token Address of created debt token
   */
  function createDebtToken(
    string memory _name,
    string memory _symbol,
    address _lendingPool,
    address _asset
  ) external returns (IDebtToken);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC-20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC-721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC-1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

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

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

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

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

    /**
     * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
     *
     * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
     * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
     * one branch when needed, making this function more expensive.
     */
    function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
        unchecked {
            // branchless ternary works because:
            // b ^ (a ^ b) == a
            // b ^ 0 == b
            return b ^ ((a ^ b) * SafeCast.toUint(condition));
        }
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return ternary(a > b, a, b);
    }

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

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

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }

        // The following calculation ensures accurate ceiling division without overflow.
        // Since a is non-zero, (a - 1) / b will not overflow.
        // The largest possible result occurs when (a - 1) / b is type(uint256).max,
        // but the largest value we can obtain is type(uint256).max - 1, which happens
        // when a = type(uint256).max and b = 1.
        unchecked {
            return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
        }
    }

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

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
            if (denominator <= prod1) {
                Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
            }

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

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

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

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

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

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

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

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

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

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
            // works in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
            inverse *= 2 - denominator * inverse; // inverse mod 2³²
            inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
            inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶

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

    /**
     * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
    }

    /**
     * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
     *
     * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
     * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
     *
     * If the input value is not inversible, 0 is returned.
     *
     * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
     * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
     */
    function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
        unchecked {
            if (n == 0) return 0;

            // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
            // Used to compute integers x and y such that: ax + ny = gcd(a, n).
            // When the gcd is 1, then the inverse of a modulo n exists and it's x.
            // ax + ny = 1
            // ax = 1 + (-y)n
            // ax ≡ 1 (mod n) # x is the inverse of a modulo n

            // If the remainder is 0 the gcd is n right away.
            uint256 remainder = a % n;
            uint256 gcd = n;

            // Therefore the initial coefficients are:
            // ax + ny = gcd(a, n) = n
            // 0a + 1n = n
            int256 x = 0;
            int256 y = 1;

            while (remainder != 0) {
                uint256 quotient = gcd / remainder;

                (gcd, remainder) = (
                    // The old remainder is the next gcd to try.
                    remainder,
                    // Compute the next remainder.
                    // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
                    // where gcd is at most n (capped to type(uint256).max)
                    gcd - remainder * quotient
                );

                (x, y) = (
                    // Increment the coefficient of a.
                    y,
                    // Decrement the coefficient of n.
                    // Can overflow, but the result is casted to uint256 so that the
                    // next value of y is "wrapped around" to a value between 0 and n - 1.
                    x - y * int256(quotient)
                );
            }

            if (gcd != 1) return 0; // No inverse exists.
            return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
        }
    }

    /**
     * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
     *
     * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
     * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
     * `a**(p-2)` is the modular multiplicative inverse of a in Fp.
     *
     * NOTE: this function does NOT check that `p` is a prime greater than `2`.
     */
    function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
        unchecked {
            return Math.modExp(a, p - 2, p);
        }
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
     *
     * Requirements:
     * - modulus can't be zero
     * - underlying staticcall to precompile must succeed
     *
     * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
     * sure the chain you're using it on supports the precompiled contract for modular exponentiation
     * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
     * the underlying function will succeed given the lack of a revert, but the result may be incorrectly
     * interpreted as 0.
     */
    function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
        (bool success, uint256 result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
     * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
     * to operate modulo 0 or if the underlying precompile reverted.
     *
     * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
     * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
     * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
     * of a revert, but the result may be incorrectly interpreted as 0.
     */
    function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
        if (m == 0) return (false, 0);
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            // | Offset    | Content    | Content (Hex)                                                      |
            // |-----------|------------|--------------------------------------------------------------------|
            // | 0x00:0x1f | size of b  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x20:0x3f | size of e  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x40:0x5f | size of m  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x60:0x7f | value of b | 0x<.............................................................b> |
            // | 0x80:0x9f | value of e | 0x<.............................................................e> |
            // | 0xa0:0xbf | value of m | 0x<.............................................................m> |
            mstore(ptr, 0x20)
            mstore(add(ptr, 0x20), 0x20)
            mstore(add(ptr, 0x40), 0x20)
            mstore(add(ptr, 0x60), b)
            mstore(add(ptr, 0x80), e)
            mstore(add(ptr, 0xa0), m)

            // Given the result < m, it's guaranteed to fit in 32 bytes,
            // so we can use the memory scratch space located at offset 0.
            success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
            result := mload(0x00)
        }
    }

    /**
     * @dev Variant of {modExp} that supports inputs of arbitrary length.
     */
    function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
        (bool success, bytes memory result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Variant of {tryModExp} that supports inputs of arbitrary length.
     */
    function tryModExp(
        bytes memory b,
        bytes memory e,
        bytes memory m
    ) internal view returns (bool success, bytes memory result) {
        if (_zeroBytes(m)) return (false, new bytes(0));

        uint256 mLen = m.length;

        // Encode call args in result and move the free memory pointer
        result = abi.encodePacked(b.length, e.length, mLen, b, e, m);

        assembly ("memory-safe") {
            let dataPtr := add(result, 0x20)
            // Write result on top of args to avoid allocating extra memory.
            success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
            // Overwrite the length.
            // result.length > returndatasize() is guaranteed because returndatasize() == m.length
            mstore(result, mLen)
            // Set the memory pointer after the returned data.
            mstore(0x40, add(dataPtr, mLen))
        }
    }

    /**
     * @dev Returns whether the provided byte array is zero.
     */
    function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
        for (uint256 i = 0; i < byteArray.length; ++i) {
            if (byteArray[i] != 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * This method is based on Newton's method for computing square roots; the algorithm is restricted to only
     * using integer operations.
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        unchecked {
            // Take care of easy edge cases when a == 0 or a == 1
            if (a <= 1) {
                return a;
            }

            // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
            // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
            // the current value as `ε_n = | x_n - sqrt(a) |`.
            //
            // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
            // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
            // bigger than any uint256.
            //
            // By noticing that
            // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
            // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
            // to the msb function.
            uint256 aa = a;
            uint256 xn = 1;

            if (aa >= (1 << 128)) {
                aa >>= 128;
                xn <<= 64;
            }
            if (aa >= (1 << 64)) {
                aa >>= 64;
                xn <<= 32;
            }
            if (aa >= (1 << 32)) {
                aa >>= 32;
                xn <<= 16;
            }
            if (aa >= (1 << 16)) {
                aa >>= 16;
                xn <<= 8;
            }
            if (aa >= (1 << 8)) {
                aa >>= 8;
                xn <<= 4;
            }
            if (aa >= (1 << 4)) {
                aa >>= 4;
                xn <<= 2;
            }
            if (aa >= (1 << 2)) {
                xn <<= 1;
            }

            // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
            //
            // We can refine our estimation by noticing that the middle of that interval minimizes the error.
            // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
            // This is going to be our x_0 (and ε_0)
            xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)

            // From here, Newton's method give us:
            // x_{n+1} = (x_n + a / x_n) / 2
            //
            // One should note that:
            // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
            //              = ((x_n² + a) / (2 * x_n))² - a
            //              = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
            //              = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
            //              = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
            //              = (x_n² - a)² / (2 * x_n)²
            //              = ((x_n² - a) / (2 * x_n))²
            //              ≥ 0
            // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
            //
            // This gives us the proof of quadratic convergence of the sequence:
            // ε_{n+1} = | x_{n+1} - sqrt(a) |
            //         = | (x_n + a / x_n) / 2 - sqrt(a) |
            //         = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
            //         = | (x_n - sqrt(a))² / (2 * x_n) |
            //         = | ε_n² / (2 * x_n) |
            //         = ε_n² / | (2 * x_n) |
            //
            // For the first iteration, we have a special case where x_0 is known:
            // ε_1 = ε_0² / | (2 * x_0) |
            //     ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
            //     ≤ 2**(2*e-4) / (3 * 2**(e-1))
            //     ≤ 2**(e-3) / 3
            //     ≤ 2**(e-3-log2(3))
            //     ≤ 2**(e-4.5)
            //
            // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
            // ε_{n+1} = ε_n² / | (2 * x_n) |
            //         ≤ (2**(e-k))² / (2 * 2**(e-1))
            //         ≤ 2**(2*e-2*k) / 2**e
            //         ≤ 2**(e-2*k)
            xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5)  -- special case, see above
            xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9)    -- general case with k = 4.5
            xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18)   -- general case with k = 9
            xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36)   -- general case with k = 18
            xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72)   -- general case with k = 36
            xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144)  -- general case with k = 72

            // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
            // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
            // sqrt(a) or sqrt(a) + 1.
            return xn - SafeCast.toUint(xn > a / xn);
        }
    }

    /**
     * @dev Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 x) internal pure returns (uint256 r) {
        // If value has upper 128 bits set, log2 result is at least 128
        r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
        // If upper 64 bits of 128-bit half set, add 64 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
        // If upper 32 bits of 64-bit half set, add 32 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
        // If upper 16 bits of 32-bit half set, add 16 to result
        r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
        // If upper 8 bits of 16-bit half set, add 8 to result
        r |= SafeCast.toUint((x >> r) > 0xff) << 3;
        // If upper 4 bits of 8-bit half set, add 4 to result
        r |= SafeCast.toUint((x >> r) > 0xf) << 2;

        // Shifts value right by the current result and use it as an index into this lookup table:
        //
        // | x (4 bits) |  index  | table[index] = MSB position |
        // |------------|---------|-----------------------------|
        // |    0000    |    0    |        table[0] = 0         |
        // |    0001    |    1    |        table[1] = 0         |
        // |    0010    |    2    |        table[2] = 1         |
        // |    0011    |    3    |        table[3] = 1         |
        // |    0100    |    4    |        table[4] = 2         |
        // |    0101    |    5    |        table[5] = 2         |
        // |    0110    |    6    |        table[6] = 2         |
        // |    0111    |    7    |        table[7] = 2         |
        // |    1000    |    8    |        table[8] = 3         |
        // |    1001    |    9    |        table[9] = 3         |
        // |    1010    |   10    |        table[10] = 3        |
        // |    1011    |   11    |        table[11] = 3        |
        // |    1100    |   12    |        table[12] = 3        |
        // |    1101    |   13    |        table[13] = 3        |
        // |    1110    |   14    |        table[14] = 3        |
        // |    1111    |   15    |        table[15] = 3        |
        //
        // The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
        assembly ("memory-safe") {
            r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
        }
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 x) internal pure returns (uint256 r) {
        // If value has upper 128 bits set, log2 result is at least 128
        r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
        // If upper 64 bits of 128-bit half set, add 64 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
        // If upper 32 bits of 64-bit half set, add 32 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
        // If upper 16 bits of 32-bit half set, add 16 to result
        r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
        // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
        return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {IERC20Metadata} from '@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol';

import {ILendingPool} from 'interfaces/ILendingPool.sol';

/**
 * @title IDebtToken
 * @notice Interface for debt tokens that represent borrowed assets in lending pools
 */
interface IDebtToken is IERC20Metadata {
  /**
   * @notice Mints debt tokens to an account
   * @param _account Address to mint tokens to
   * @param _amount Amount of tokens to mint
   */
  function mint(address _account, uint256 _amount) external;

  /**
   * @notice Burns debt tokens from an account
   * @param _account Address to burn tokens from
   * @param _amount Amount of tokens to burn
   */
  function burn(address _account, uint256 _amount) external;

  /**
   * @notice Increases allowance for a spender
   * @param spender Address allowed to spend tokens
   * @param addedValue Amount to increase allowance by
   * @return bool True if operation succeeded
   */
  function increaseAllowance(address spender, uint256 addedValue) external returns (bool);

  /**
   * @notice Decreases allowance for a spender
   * @param spender Address allowed to spend tokens
   * @param subtractedValue Amount to decrease allowance by
   * @return bool True if operation succeeded
   */
  function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);

  /**
   * @notice Returns the lending pool contract address
   * @return ILendingPool The lending pool contract interface
   */
  function LENDING_POOL() external view returns (ILendingPool);

  /**
   * @notice Returns the underlying asset token address
   * @return address The underlying token address
   */
  function UNDERLYING() external view returns (address);
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

interface IACLManager {
  function setRoleAdmin(bytes32 _role, bytes32 _adminRole) external;

  function addEmergency(
    address admin
  ) external;

  function addManager(
    address admin
  ) external;

  function addConsumer(
    address admin
  ) external;

  function removeConsumer(
    address admin
  ) external;

  function removeManager(
    address admin
  ) external;

  function removeEmergency(
    address admin
  ) external;

  function isEmergencyRole(
    address admin
  ) external view returns (bool);

  function isManagerRole(
    address admin
  ) external view returns (bool);

  function isConsumerRole(
    address admin
  ) external view returns (bool);
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

interface IAllowListAuthentication {
  function setManager(
    address manager_
  ) external;

  function addSolver(
    address _solver
  ) external;

  function removeSolver(
    address _solver
  ) external;

  function addMaker(
    address _maker
  ) external;

  function removeMaker(
    address _maker
  ) external;

  function isSolver(
    address _addr
  ) external view returns (bool);

  function isMaker(
    address _addr
  ) external view returns (bool);

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

File 26 of 30 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../token/ERC20/IERC20.sol";

File 27 of 30 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../utils/introspection/IERC165.sol";

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)

pragma solidity ^0.8.20;

/**
 * @dev Helper library for emitting standardized panic codes.
 *
 * ```solidity
 * contract Example {
 *      using Panic for uint256;
 *
 *      // Use any of the declared internal constants
 *      function foo() { Panic.GENERIC.panic(); }
 *
 *      // Alternatively
 *      function foo() { Panic.panic(Panic.GENERIC); }
 * }
 * ```
 *
 * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
 *
 * _Available since v5.1._
 */
// slither-disable-next-line unused-state
library Panic {
    /// @dev generic / unspecified error
    uint256 internal constant GENERIC = 0x00;
    /// @dev used by the assert() builtin
    uint256 internal constant ASSERT = 0x01;
    /// @dev arithmetic underflow or overflow
    uint256 internal constant UNDER_OVERFLOW = 0x11;
    /// @dev division or modulo by zero
    uint256 internal constant DIVISION_BY_ZERO = 0x12;
    /// @dev enum conversion error
    uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
    /// @dev invalid encoding in storage
    uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
    /// @dev empty array pop
    uint256 internal constant EMPTY_ARRAY_POP = 0x31;
    /// @dev array out of bounds access
    uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
    /// @dev resource error (too large allocation or too large array)
    uint256 internal constant RESOURCE_ERROR = 0x41;
    /// @dev calling invalid internal function
    uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;

    /// @dev Reverts with a panic code. Recommended to use with
    /// the internal constants with predefined codes.
    function panic(uint256 code) internal pure {
        assembly ("memory-safe") {
            mstore(0x00, 0x4e487b71)
            mstore(0x20, code)
            revert(0x1c, 0x24)
        }
    }
}

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

pragma solidity ^0.8.20;

/**
 * @dev Wrappers over Solidity's uintXX/intXX/bool 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.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

    /**
     * @dev An int value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedIntToUint(int256 value);

    /**
     * @dev Value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);

    /**
     * @dev An uint value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedUintToInt(uint256 value);

    /**
     * @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
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        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
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        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
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        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
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        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
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        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
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        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
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        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
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        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
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        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
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        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
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        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
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        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
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        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
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        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
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        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
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        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
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        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
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        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
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        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
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        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
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        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
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        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
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        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
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        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
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        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
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        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
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        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
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        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
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        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
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        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
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        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
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(248, value);
        }
    }

    /**
     * @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
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(240, value);
        }
    }

    /**
     * @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
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(232, value);
        }
    }

    /**
     * @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
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(224, value);
        }
    }

    /**
     * @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
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(216, value);
        }
    }

    /**
     * @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
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(208, value);
        }
    }

    /**
     * @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
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(200, value);
        }
    }

    /**
     * @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
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(192, value);
        }
    }

    /**
     * @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
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(184, value);
        }
    }

    /**
     * @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
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(176, value);
        }
    }

    /**
     * @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
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(168, value);
        }
    }

    /**
     * @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
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(160, value);
        }
    }

    /**
     * @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
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(152, value);
        }
    }

    /**
     * @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
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(144, value);
        }
    }

    /**
     * @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
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(136, value);
        }
    }

    /**
     * @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
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(128, value);
        }
    }

    /**
     * @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
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(120, value);
        }
    }

    /**
     * @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
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(112, value);
        }
    }

    /**
     * @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
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(104, value);
        }
    }

    /**
     * @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
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(96, value);
        }
    }

    /**
     * @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
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(88, value);
        }
    }

    /**
     * @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
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(80, value);
        }
    }

    /**
     * @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
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(72, value);
        }
    }

    /**
     * @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
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(64, value);
        }
    }

    /**
     * @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
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(56, value);
        }
    }

    /**
     * @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
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(48, value);
        }
    }

    /**
     * @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
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(40, value);
        }
    }

    /**
     * @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
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(32, value);
        }
    }

    /**
     * @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
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(24, value);
        }
    }

    /**
     * @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
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(16, value);
        }
    }

    /**
     * @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
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(8, value);
        }
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        if (value > uint256(type(int256).max)) {
            revert SafeCastOverflowedUintToInt(value);
        }
        return int256(value);
    }

    /**
     * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
     */
    function toUint(bool b) internal pure returns (uint256 u) {
        assembly ("memory-safe") {
            u := iszero(iszero(b))
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

Settings
{
  "remappings": [
    "ds-test/=node_modules/ds-test/src/",
    "forge-std/=lib/forge-std/src/",
    "@chainlink/=lib/chainlink/contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "contracts/=src/contracts/",
    "interfaces/=src/interfaces/",
    "chainlink/=lib/chainlink/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin-upgrades/=lib/openzeppelin-upgrades/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 10000
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "shanghai",
  "viaIR": false,
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_repository","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ActionPaused","type":"error"},{"inputs":[],"name":"BorrowerNotMaker","type":"error"},{"inputs":[],"name":"DifferentArrayLength","type":"error"},{"inputs":[],"name":"DuplicateAsset","type":"error"},{"inputs":[],"name":"LiquidationNotSuccessful","type":"error"},{"inputs":[],"name":"MaxSupplyLimitExceeded","type":"error"},{"inputs":[],"name":"MaximumLTVReached","type":"error"},{"inputs":[],"name":"NotEnoughDeposits","type":"error"},{"inputs":[],"name":"NotEnoughLiquidity","type":"error"},{"inputs":[],"name":"NotSolvent","type":"error"},{"inputs":[],"name":"OnlyRepository","type":"error"},{"inputs":[],"name":"OnlySettlement","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"UnsupportedLTVType","type":"error"},{"inputs":[],"name":"ZeroRepay","type":"error"},{"inputs":[],"name":"ZeroWithdraw","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"address","name":"collateralToken","type":"address"},{"indexed":false,"internalType":"address","name":"lockedCollateralToken","type":"address"},{"indexed":false,"internalType":"address","name":"debtToken","type":"address"}],"name":"AssetAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"debtShare","type":"uint256"}],"name":"Borrow","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"harvestedFees","type":"uint256"}],"name":"HarvestProtocolFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"liquidator","type":"address"}],"name":"Liquidation","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"address","name":"repayer","type":"address"},{"indexed":false,"internalType":"uint256","name":"repayAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"repayShare","type":"uint256"}],"name":"Repay","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"address","name":"depositor","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mintedShares","type":"uint256"},{"indexed":true,"internalType":"bool","name":"lockedCollateral","type":"bool"}],"name":"SupplyCollateral","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"withdrawnAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralShare","type":"uint256"},{"indexed":true,"internalType":"bool","name":"lockedCollateral","type":"bool"}],"name":"WithdrawCollateral","type":"event"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"accrueInterest","outputs":[{"internalType":"uint256","name":"accruedInterest","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IUtilityTokensFactory","name":"tokensFactory","type":"address"},{"internalType":"address[]","name":"newAssets","type":"address[]"}],"name":"addAssets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"assetUtilizationData","outputs":[{"components":[{"internalType":"uint256","name":"totalDeposits","type":"uint256"},{"internalType":"uint256","name":"totalBorrowAmount","type":"uint256"},{"internalType":"uint256","name":"interestTimestamp","type":"uint256"}],"internalType":"struct ILendingPool.AssetUtilizationData","name":"data","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"borrow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"source","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"tradeAsset","type":"address"},{"internalType":"uint256","name":"tradeAmount","type":"uint256"}],"name":"borrowFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"borrowFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"fromLockedCollateral","type":"bool"}],"name":"convertCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"getAssetState","outputs":[{"components":[{"internalType":"contract ICollateralToken","name":"collateralToken","type":"address"},{"internalType":"contract ICollateralToken","name":"lockedCollateralToken","type":"address"},{"internalType":"contract IDebtToken","name":"debtToken","type":"address"},{"internalType":"uint256","name":"totalDeposits","type":"uint256"},{"internalType":"uint256","name":"totalLockedDeposits","type":"uint256"},{"internalType":"uint256","name":"totalBorrowAmount","type":"uint256"}],"internalType":"struct ILendingPool.AssetState","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAssetsWithState","outputs":[{"internalType":"address[]","name":"assets","type":"address[]"},{"components":[{"internalType":"contract ICollateralToken","name":"collateralToken","type":"address"},{"internalType":"contract ICollateralToken","name":"lockedCollateralToken","type":"address"},{"internalType":"contract IDebtToken","name":"debtToken","type":"address"},{"internalType":"uint256","name":"totalDeposits","type":"uint256"},{"internalType":"uint256","name":"totalLockedDeposits","type":"uint256"},{"internalType":"uint256","name":"totalBorrowAmount","type":"uint256"}],"internalType":"struct ILendingPool.AssetState[]","name":"assetsState","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"getUserLTV","outputs":[{"internalType":"uint256","name":"userLTV","type":"uint256"},{"internalType":"uint256","name":"liquidationThreshold","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"bool","name":"_lockedCollateral","type":"bool"}],"name":"getWithdrawAssetData","outputs":[{"internalType":"uint256","name":"assetTotalDeposits","type":"uint256"},{"internalType":"contract ICollateralToken","name":"collateralToken","type":"address"},{"internalType":"uint256","name":"availableLiquidity","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"harvestProtocolFees","outputs":[{"internalType":"uint256[]","name":"harvestedAmounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"interestData","outputs":[{"components":[{"internalType":"uint256","name":"protocolFees","type":"uint256"},{"internalType":"uint256","name":"harvestedProtocolFees","type":"uint256"},{"internalType":"uint256","name":"interestTimestamp","type":"uint256"}],"internalType":"struct ILendingPool.AssetInterestData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"isSolvent","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"asset","type":"address"}],"internalType":"struct ILendingPool.LiquidateParams[]","name":"_withdrawalParams","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"asset","type":"address"}],"internalType":"struct ILendingPool.LiquidateParams[]","name":"_repayParams","type":"tuple[]"},{"internalType":"bytes","name":"_receiverData","type":"bytes"}],"name":"liquidate","outputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"asset","type":"address"}],"internalType":"struct ILendingPool.LiquidateParams[]","name":"receivedCollaterals","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"asset","type":"address"}],"internalType":"struct ILendingPool.LiquidateParams[]","name":"shareAmountsToRepay","type":"tuple[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"liquidity","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_fromAsset","type":"address"},{"internalType":"address","name":"_toAsset","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_minReceiveQuantity","type":"uint256"},{"internalType":"bool","name":"_lockedCollateral","type":"bool"},{"internalType":"bool","name":"_isExactOutput","type":"bool"}],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"repay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"repayFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"repository","outputs":[{"internalType":"contract IRepository","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"lockedCollateral","type":"bool"}],"name":"supply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"lockedCollateral","type":"bool"}],"name":"supplyFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"lockedCollateral","type":"bool"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"depositor","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"lockedCollateral","type":"bool"}],"name":"withdrawFor","outputs":[],"stateMutability":"nonpayable","type":"function"}]

0x608060405234801562000010575f80fd5b50604051620057a1380380620057a183398101604081905262000033916200005d565b60015f81905580546001600160a01b0319166001600160a01b03929092169190911790556200008c565b5f602082840312156200006e575f80fd5b81516001600160a01b038116811462000085575f80fd5b9392505050565b615707806200009a5f395ff3fe608060405234801561000f575f80fd5b506004361061018e575f3560e01c80637cf51195116100dd578063b8c876b111610088578063ead5d35911610063578063ead5d3591461045b578063f364181c1461046e578063fb25570314610481575f80fd5b8063b8c876b11461040a578063dbc5b4811461041d578063e9176c6014610430575f80fd5b80638b7c30ab116100b85780638b7c30ab146103b65780639198e515146103d6578063976ce495146103f7575f80fd5b80637cf511951461036f5780637f2870e714610382578063823b0ba8146103a3575f80fd5b806338b51ce11161013d578063525fef2711610118578063525fef271461031057806364654cf51461032357806367f97cc814610339575f80fd5b806338b51ce1146102c75780633fc56217146102ea5780634b8a3529146102fd575f80fd5b8063151541f01161016d578063151541f01461027757806316fa77ab1461028c57806322867d78146102b4575f80fd5b8062bb2691146101925780630abf8bf2146101a75780630c60118b14610264575b5f80fd5b6101a56101a03660046148f3565b610494565b005b61024e6101b536600461495f565b6040805160c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810191909152506001600160a01b039081165f90815260036020818152604092839020835160c081018552815486168152600182015486169281019290925260028101549094169281019290925282015460608201526004820154608082015260059091015460a082015290565b60405161025b919061497a565b60405180910390f35b6101a5610272366004614a94565b610673565b61027f610a51565b60405161025b9190614b43565b61029f61029a36600461495f565b610bd6565b6040805192835260208301919091520161025b565b6101a56102c2366004614b86565b610c34565b6102da6102d536600461495f565b610c44565b604051901515815260200161025b565b6101a56102f8366004614bb0565b610ca3565b6101a561030b366004614b86565b610cb6565b6101a561031e366004614c00565b610cdc565b61032b610cf9565b60405161025b929190614c3f565b61034c610347366004614d0f565b610e8f565b604080519384526001600160a01b0390921660208401529082015260600161025b565b6101a561037d366004614c00565b610ef9565b610395610390366004614e19565b610f06565b60405161025b929190614f37565b6101a56103b1366004614f5b565b610f6a565b6103c96103c436600461495f565b611051565b60405161025b9190614fda565b6103e96103e436600461495f565b6110bb565b60405190815260200161025b565b6101a5610405366004614ffb565b6110cb565b6103e961041836600461495f565b6110d7565b6101a561042b366004615039565b611178565b600154610443906001600160a01b031681565b6040516001600160a01b03909116815260200161025b565b6101a5610469366004614c00565b611253565b6101a561047c366004615087565b611273565b6103c961048f36600461495f565b611358565b61049d866113ba565b6104a6856114b1565b6104af86611560565b50600154604080517f18f51fea00000000000000000000000000000000000000000000000000000000815290515f926001600160a01b0316916318f51fea9160048083019260209291908290030181865afa158015610510573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061053491906150eb565b90505f610544888733875f61171a565b50915061055d90506001600160a01b0389168383611a57565b6040517fb4f8b2b90000000000000000000000000000000000000000000000000000000081523360048201526001600160a01b0389811660248301528881166044830152606482018390526084820187905284151560a48301525f919084169063b4f8b2b99060c4016020604051808303815f875af11580156105e2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106069190615106565b90506106158833338489611acb565b848015610628575061062633610c44565b155b1561065f576040517fe081c8f300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61066888611d8d565b505050505050505050565b6001546001600160a01b031633146106b7576040517f97691a2f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f5b8151811015610a4c575f8282815181106106d5576106d561511d565b6020908102919091018101516001600160a01b038082165f908152600390935260409092208054919350911615610738576040517f587daa3000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280546001810182555f9182527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0385161790556107a283612009565b805160208201516040517f1c600ae10000000000000000000000000000000000000000000000000000000081529293506001600160a01b03891692631c600ae1926107f7929091309089905f906004016151b5565b6020604051808303815f875af1158015610813573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061083791906150eb565b82547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03918216178355604082810151606084015191517f1c600ae100000000000000000000000000000000000000000000000000000000815292891692631c600ae1926108b79291309089906001906004016151b5565b6020604051808303815f875af11580156108d3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108f791906150eb565b6001830180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03928316179055608082015160a08301516040517ff6933f220000000000000000000000000000000000000000000000000000000081529289169263f6933f229261097992909130908990600401615203565b6020604051808303815f875af1158015610995573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109b991906150eb565b6002830180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03928316908117909155835460018501546040805192851683529084166020830152810191909152908416907fd8b220be2e60c36e6b45a9c94291f9e9b082065c9f8ed360725449c66326d7829060600160405180910390a25050506001016106b9565b505050565b6060610a5b6121d1565b5f6002805480602002602001604051908101604052809291908181526020018280548015610ab057602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311610a92575b50505050509050805167ffffffffffffffff811115610ad157610ad16149cc565b604051908082528060200260200182016040528015610afa578160200160208202803683370190505b5091505f60015f9054906101000a90046001600160a01b03166001600160a01b031663d08fc1006040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b4e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b7291906150eb565b90505f5b8251811015610bc757610ba2838281518110610b9457610b9461511d565b602002602001015183612212565b848281518110610bb457610bb461511d565b6020908102919091010152600101610b76565b505050610bd360015f55565b90565b5f805f80610be2610cf9565b6040805160a081018252600180546001600160a01b039081168352306020840152928201859052606082018490529189166080820152929450909250610c2891906122e5565b90969095509350505050565b610c4082333384612442565b5050565b5f805f610c4f610cf9565b6040805160a0810182526001546001600160a01b03908116825230602083015291810184905260608101839052908716608082015291935091505f908190610c9790826122e5565b10159695505050505050565b610cb08433858585611acb565b50505050565b610cbe6121d1565b610cc7336125ba565b610cd382333384612749565b610c4060015f55565b610ce46121d1565b610cf083338484612a2d565b610a4c60015f55565b6060806002805480602002602001604051908101604052809291908181526020018280548015610d5057602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311610d32575b50505050509150815167ffffffffffffffff811115610d7157610d716149cc565b604051908082528060200260200182016040528015610dcf57816020015b6040805160c0810182525f8082526020808301829052928201819052606082018190526080820181905260a082015282525f19909201910181610d8f5790505b5090505f5b8251811015610e8a5760035f848381518110610df257610df261511d565b6020908102919091018101516001600160a01b0390811683528282019390935260409182015f20825160c0810184528154851681526001820154851692810192909252600281015490931691810191909152600382015460608201526004820154608082015260059091015460a08201528251839083908110610e7757610e7761511d565b6020908102919091010152600101610dd4565b509091565b6001600160a01b0382165f908152600360205260408120819081908415610ed057600481015460018201549094506001600160a01b03169250839150610ef1565b600381015481549094506001600160a01b03169250610eee866110d7565b91505b509250925092565b610a4c8333338585611acb565b606080610f116121d1565b610f1e8686863387612d0f565b604051919350915033906001600160a01b038816907fce054da468b0607d4d65949d7572acd17087e593b3e5be27ba665ba1a60ad75b905f90a3610f6160015f55565b94509492505050565b610f726121d1565b60015f9054906101000a90046001600160a01b03166001600160a01b031663511606306040518163ffffffff1660e01b8152600401602060405180830381865afa158015610fc2573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fe691906150eb565b6001600160a01b0316336001600160a01b031614611030576040517f15b3197600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61103f87878787878787612f00565b61104860015f55565b50505050505050565b61107260405180606001604052805f81526020015f81526020015f81525090565b506001600160a01b03165f818152600360208181526040808420815160608101835293810154845260050154838301529383526004905290829020600201549181019190915290565b5f6110c582611560565b92915050565b610a4c83833384612442565b6001600160a01b0381165f8181526003602052604080822060049081015491517f70a082310000000000000000000000000000000000000000000000000000000081523091810191909152919290916370a0823190602401602060405180830381865afa15801561114a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061116e9190615106565b6110c59190615279565b6111806121d1565b60015f9054906101000a90046001600160a01b03166001600160a01b031663511606306040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111d0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111f491906150eb565b6001600160a01b0316336001600160a01b03161461123e576040517f15b3197600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61124a84848484612749565b610cb060015f55565b61125b6121d1565b61126883333385856133d6565b5050610a4c60015f55565b61127b6121d1565b60015f9054906101000a90046001600160a01b03166001600160a01b031663511606306040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112cb573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112ef91906150eb565b6001600160a01b0316336001600160a01b031614611339576040517f15b3197600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61134685858585856133d6565b505061135160015f55565b5050505050565b61137960405180606001604052805f81526020015f81526020015f81525090565b506001600160a01b03165f90815260046020908152604091829020825160608101845281548152600182015492810192909252600201549181019190915290565b6001546040517f5cfe84080000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0383811660248301525f921690635cfe840890604401602060405180830381865afa158015611421573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611445919061528c565b905060015b81600381111561145c5761145c6152aa565b148061147a575060035b816003811115611478576114786152aa565b145b15610c40576040517fc6052bd800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001546040517f5cfe84080000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0383811660248301525f921690635cfe840890604401602060405180830381865afa158015611518573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061153c919061528c565b90506001816003811115611552576115526152aa565b148061147a57506002611466565b6001600160a01b0381165f90815260036020908152604080832060049092528220600281015442900361159657505f9392505050565b5f6115a08561349b565b6040517f1b9286010000000000000000000000000000000000000000000000000000000081526001600160a01b0387811660048301529190911690631b928601906024016020604051808303815f875af1158015611600573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116249190615106565b90505f60015f9054906101000a90046001600160a01b03166001600160a01b03166325ed3d446040518163ffffffff1660e01b8152600401602060405180830381865afa158015611677573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061169b9190615106565b60058501548454919250905f8080670de0b6b3a76400006116bc88876152d7565b6116c6919061531b565b9950505050620186a083880204818101908089036116e48a8661532e565b60058a015560038901546116f990829061532e565b60039099019890985550855550504260029093019290925550919392505050565b5f805f611726886113ba565b5f805f6117338b89610e8f565b9250925092505f198a03611837576040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b038a811660048301528316906370a0823190602401602060405180830381865afa15801561179e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117c29190615106565b935061183083836001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611804573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118289190615106565b869190613526565b95506118a9565b6118a383836001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611877573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061189b9190615106565b8c919061355c565b93508995505b855f036118c1575f805f955095509550505050611a4c565b858310156118fb576040517fb2454c7800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b858303925061190b8b878961358b565b945084811015611947576040517f4323a55500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038b165f90815260036020526040902088156119705760048101849055611978565b600381018490555b6040517f9dc29fac0000000000000000000000000000000000000000000000000000000081526001600160a01b038b8116600483015260248201879052841690639dc29fac906044015f604051808303815f87803b1580156119d8575f80fd5b505af11580156119ea573d5f803e3d5ffd5b505050508815158a6001600160a01b03168d6001600160a01b03167f8c915e101d80f0ed9c723dea5a8c7b20f04d7c2d94c6ea6a382f22a8fd2bfe5b8989604051611a3f929190918252602082015260400190565b60405180910390a4505050505b955095509592505050565b6040516001600160a01b03838116602483015260448201839052610a4c91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506135e2565b611ad4856114b1565b611add85611560565b506001600160a01b0385165f908152600360205260408120908083611b06578260030154611b0c565b82600401545b90508315611c2d57611b9681846001015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b6a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b8e9190615106565b87919061366b565b9150611ba2858261532e565b60048481019190915560018401546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b0389811693820193909352602481018590529116906340c10f19906044015f604051808303815f87803b158015611c12575f80fd5b505af1158015611c24573d5f803e3d5ffd5b50505050611d0d565b611c8281845f015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b6a573d5f803e3d5ffd5b9150611c8e858261532e565b600384015582546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b03888116600483015260248201859052909116906340c10f19906044015f604051808303815f87803b158015611cf6575f80fd5b505af1158015611d08573d5f803e3d5ffd5b505050505b611d226001600160a01b038916883088613690565b611d2b88611d8d565b604080516001600160a01b038981168252602082018890529181018490528515159180891691908b16907f62a793ab5de9d8b6f21940de9c7e83ec9ab7ae16c9db46977a2fa2c01b89a85b906060015b60405180910390a45050505050505050565b600154604080517fb888879e00000000000000000000000000000000000000000000000000000000815290515f926001600160a01b03169163b888879e9160048083019260209291908290030181865afa158015611ded573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e1191906150eb565b6001600160a01b0383165f908152600360208190526040822060048101549181015493945092611e41919061532e565b6001546040517f437e3edc0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b03878116602483015292935091169063437e3edc90604401602060405180830381865afa158015611eaa573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ece9190615106565b846001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f0a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f2e9190615341565b611f3990600a615441565b6040517f41976e090000000000000000000000000000000000000000000000000000000081526001600160a01b0387811660048301528491908716906341976e0990602401602060405180830381865afa158015611f99573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fbd9190615106565b611fc791906152d7565b611fd1919061531b565b1115610cb0576040517f6d85e6e300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6120426040518060c001604052806060815260200160608152602001606081526020016060815260200160608152602001606081525090565b5f826001600160a01b03166395d89b416040518163ffffffff1660e01b81526004015f60405180830381865afa15801561207e573d5f803e3d5ffd5b505050506040513d5f823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526120c3919081019061544f565b90506040518060c00160405280826040516020016120e191906154b8565b60405160208183030381529060405281526020018260405160200161210691906154fc565b60405160208183030381529060405281526020018260405160200161212b9190615540565b6040516020818303038152906040528152602001826040516020016121509190615584565b60405160208183030381529060405281526020018260405160200161217591906155bb565b60405160208183030381529060405281526020018260405160200161219a91906155ff565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905290529392505050565b60025f540361220c576040517f3ee5aeb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60025f55565b5f61221c836113ba565b61222583611560565b506001600160a01b0383165f9081526004602052604090206001810154815461224e9190615279565b91505f61225a856110d7565b905080831115612268578092505b825f03612279575f925050506110c5565b600182018054840190556122976001600160a01b0386168585611a57565b604080516001600160a01b038681168252602082018690528716917fe59943d5ba8f431f481a3df311cc18e2ff305525e251144b0042be1b59dbc097910160405180910390a2505092915050565b5f805f6122f1856136c9565b90506122fc816137f1565b5f0361230e575f80925092505061243b565b5f855f01516001600160a01b031663b888879e6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561234e573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061237291906150eb565b90505f6123848288604001518561382c565b90505f612390826137f1565b9050805f036123a8575f80955095505050505061243b565b5f6123b3848a613a4f565b90505f6123bf826137f1565b9050805f036123da575f195f9750975050505050505061243b565b5f6123f38b5f01518c602001518d604001518d87613a6c565b905081612408670de0b6b3a7640000866152d7565b612412919061531b565b985081612427670de0b6b3a7640000836152d7565b612431919061531b565b9750505050505050505b9250929050565b61244b846114b1565b61245484611560565b506001600160a01b0384165f9081526003602052604081209080612479838786613b10565b91509150805f036124b6576040517f685e923500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6124cb6001600160a01b038816863085613690565b60028301546040517f9dc29fac0000000000000000000000000000000000000000000000000000000081526001600160a01b0388811660048301526024820184905290911690639dc29fac906044015f604051808303815f87803b158015612531575f80fd5b505af1158015612543573d5f803e3d5ffd5b5050505081836005015f82825461255a9190615279565b9091555050604080516001600160a01b03878116825260208201859052918101839052818816918916907f81cfb79463601de705d4cf6b8d69112983d76a685120e5e4d3581f30871b87fc9060600160405180910390a350505050505050565b60015f9054906101000a90046001600160a01b03166001600160a01b031663511606306040518163ffffffff1660e01b8152600401602060405180830381865afa15801561260a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061262e91906150eb565b6001600160a01b031663c61861816040518163ffffffff1660e01b8152600401602060405180830381865afa158015612669573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061268d91906150eb565b6040517fe75600c30000000000000000000000000000000000000000000000000000000081526001600160a01b038381166004830152919091169063e75600c390602401602060405180830381865afa1580156126ec573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127109190615643565b612746576040517ff19f8c9e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50565b612752846113ba565b61275b84611560565b5080612766856110d7565b101561279e576040517f4323a55500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038085165f908152600360209081526040808320600581015460015483517f072ea61c0000000000000000000000000000000000000000000000000000000081529351929691959491169263072ea61c92600480830193928290030181865afa158015612814573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128389190615106565b90505f811561285e57620186a061284f83876152d7565b612859919061531b565b612860565b5f5b90505f6128ee84866002015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128b9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128dd9190615106565b6128e7858a61532e565b919061355c565b9050816128fb878661532e565b612905919061532e565b60058601556001600160a01b0389165f908152600460205260408120805484929061293190849061532e565b909155505060028501546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b038a8116600483015260248201849052909116906340c10f19906044015f604051808303815f87803b15801561299c575f80fd5b505af11580156129ae573d5f803e3d5ffd5b506129c7925050506001600160a01b038a168888611a57565b6129d088613c5b565b604080516001600160a01b03898116825260208201899052918101839052818a16918b16907f96558a334f4759f0e7c423d68c84721860bd8fbf94ddc4e55158ecb125ad04b59060600160405180910390a3505050505050505050565b612a3684611560565b506001600160a01b0384165f908152600360205260408120908080612a5e888789888561171a565b50909150508415612bce5760038401548454604080517f18160ddd0000000000000000000000000000000000000000000000000000000081529051929550612b009286926001600160a01b0316916318160ddd9160048083019260209291908290030181865afa158015612ad4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612af89190615106565b83919061366b565b9150612b0c818461532e565b600385015583546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b03898116600483015260248201859052909116906340c10f19906044015f604051808303815f87803b158015612b74575f80fd5b505af1158015612b86573d5f803e3d5ffd5b50505050612b9387610c44565b612bc9576040517fe081c8f300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612cbe565b83600401549250612c2b83856001015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ad4573d5f803e3d5ffd5b9150612c37818461532e565b60048581019190915560018501546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b038a811693820193909352602481018590529116906340c10f19906044015f604051808303815f87803b158015612ca7575f80fd5b505af1158015612cb9573d5f803e3d5ffd5b505050505b604080516001600160a01b03808a168083526020830185905292820185905287159291908b16907f62a793ab5de9d8b6f21940de9c7e83ec9ab7ae16c9db46977a2fa2c01b89a85b90606001611d7b565b6060805f80612d1d89610bd6565b91509150808211612df9575f885167ffffffffffffffff811115612d4357612d436149cc565b604051908082528060200260200182016040528015612d8757816020015b604080518082019091525f8082526020820152815260200190600190039081612d615790505b5090505f885167ffffffffffffffff811115612da557612da56149cc565b604051908082528060200260200182016040528015612de957816020015b604080518082019091525f8082526020820152815260200190600190039081612dc35790505b50919550909350612ef692505050565b612e0588888b89613ceb565b6040517f72ea3feb00000000000000000000000000000000000000000000000000000000815291955093506001600160a01b038716906372ea3feb90612e55908c90889088908b9060040161565e565b5f604051808303815f87803b158015612e6c575f80fd5b505af1158015612e7e573d5f803e3d5ffd5b505050505f80612e8d8b610bd6565b9150915080821115612ef1578382101580612eba5750612ead81856152d7565b612eb784846152d7565b10155b15612ef1576040517f62a8087e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505b9550959350505050565b612f098761405e565b612f1287611560565b50612f1c82611560565b5082612f27886110d7565b1015612f5f576040517f4323a55500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038088165f908152600360209081526040808320600581015460015483517f072ea61c0000000000000000000000000000000000000000000000000000000081529351929691959491169263072ea61c92600480830193928290030181865afa158015612fd5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ff99190615106565b90505f811561301f57620186a061301083896152d7565b61301a919061531b565b613021565b5f5b90505f6130a884866002015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561307a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061309e9190615106565b6128e7858c61532e565b9050816130b5898661532e565b6130bf919061532e565b60058601556001600160a01b038c165f90815260046020526040812080548492906130eb90849061532e565b909155505060028501546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b038d8116600483015260248201849052909116906340c10f19906044015f604051808303815f87803b158015613156575f80fd5b505af1158015613168573d5f803e3d5ffd5b50613181925050506001600160a01b038d168a8a611a57565b6001600160a01b038088165f908152600360209081526040808320600480820154600183015484517f18160ddd0000000000000000000000000000000000000000000000000000000081529451939c50909661322b95889592909116936318160ddd93838101938290030181865afa1580156131ff573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906132239190615106565b8a919061366b565b9050613237888361532e565b8760040181905550866001015f9054906101000a90046001600160a01b03166001600160a01b03166340c10f198e836040518363ffffffff1660e01b81526004016132979291906001600160a01b03929092168252602082015260400190565b5f604051808303815f87803b1580156132ae575f80fd5b505af11580156132c0573d5f803e3d5ffd5b506132da925050506001600160a01b038a168d308b613690565b6132e38d613c5b565b6132ec89611d8d565b600115158d6001600160a01b03168a6001600160a01b03167f62a793ab5de9d8b6f21940de9c7e83ec9ab7ae16c9db46977a2fa2c01b89a85b8f8c86604051613353939291906001600160a01b039390931683526020830191909152604082015260600190565b60405180910390a48c6001600160a01b03168e6001600160a01b03167f96558a334f4759f0e7c423d68c84721860bd8fbf94ddc4e55158ecb125ad04b58d8d876040516133be939291906001600160a01b039390931683526020830191909152604082015260600190565b60405180910390a35050505050505050505050505050565b5f806133e187611560565b505f6133f0888689875f61171a565b91945090925090505f839003613432576040517fb8cb621900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6134466001600160a01b0389168783611a57565b838015613459575061345787610c44565b155b15613490576040517fe081c8f300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b509550959350505050565b6001546040517f48b3eabc0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0383811660248301525f9216906348b3eabc90604401602060405180830381865afa158015613502573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110c591906150eb565b5f61355461353584600161532e565b6135416003600a6156a5565b61354b908561532e565b8691905f61411a565b949350505050565b5f61355461356c6003600a6156a5565b613576908461532e565b61358185600161532e565b869190600161411a565b5f815f0361359a5750816135db565b6001600160a01b0384165f908152600460205260408120546135bd908585614165565b6001600160a01b0387165f9081526004602052604090205584039150505b9392505050565b5f8060205f8451602086015f885af180613601576040513d5f823e3d81fd5b50505f513d91508115613618578060011415613625565b6001600160a01b0384163b155b15610cb0576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b038516600482015260240160405180910390fd5b5f61355461367b6003600a6156a5565b613685908461532e565b61354b85600161532e565b6040516001600160a01b038481166024830152838116604483015260648201839052610cb09186918216906323b872dd90608401611a84565b60608160600151518260400151511461370e576040517fdba17af500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81604001515167ffffffffffffffff81111561372c5761372c6149cc565b604051908082528060200260200182016040528015613755578160200160208202803683370190505b5090505f5b8260400151518110156137eb575f6137978460200151855f01518660400151858151811061378a5761378a61511d565b602002602001015161418f565b90506137c5846060015183815181106137b2576137b261511d565b60200260200101518560800151836142a7565b8383815181106137d7576137d761511d565b60209081029190910101525060010161375a565b50919050565b5f805b82518110156137eb5782818151811061380f5761380f61511d565b602002602001015182613822919061532e565b91506001016137f4565b60608151835114613869576040517fdba17af500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b825167ffffffffffffffff811115613883576138836149cc565b6040519080825280602002602001820160405280156138ac578160200160208202803683370190505b5090505f5b8351811015613a47578281815181106138cc576138cc61511d565b60200260200101515f0315613a3f575f856001600160a01b03166341976e098684815181106138fd576138fd61511d565b60200260200101516040518263ffffffff1660e01b815260040161393091906001600160a01b0391909116815260200190565b602060405180830381865afa15801561394b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061396f9190615106565b90505f8583815181106139845761398461511d565b60200260200101516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156139c7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906139eb9190615341565b9050613a1e828260ff16878681518110613a0757613a0761511d565b60200260200101516143ce9092919063ffffffff16565b848481518110613a3057613a3061511d565b60200260200101818152505050505b6001016138b1565b509392505050565b60605f613a5b836143f6565b90506135548484604001518361382c565b5f8151845114613aa8576040517fdba17af500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f5b8451811015613b0657613af28787878481518110613aca57613aca61511d565b602002602001015187878681518110613ae557613ae561511d565b602002602001015161459d565b613afc908361532e565b9150600101613aaa565b5095945050505050565b60028301546040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301525f9283928392909116906370a0823190602401602060405180830381865afa158015613b79573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613b9d9190615106565b90505f866002015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613bf2573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613c169190615106565b60058801549091505f613c2a84838561470a565b9050808710613c3e57809550839450613c4f565b869550613c4c86838561366b565b94505b50505050935093915050565b5f80613c65610cf9565b6040805160a0810182526001546001600160a01b03908116825230602083015291810184905260608101839052908616608082015291935091505f908190613cad90826122e5565b9150915080821115611351576040517f32ad975800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b835160609081908067ffffffffffffffff811115613d0b57613d0b6149cc565b604051908082528060200260200182016040528015613d4f57816020015b604080518082019091525f8082526020820152815260200190600190039081613d295790505b5092505f60015f9054906101000a90046001600160a01b03166001600160a01b031663eafecffa6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613da3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613dc79190615106565b90505f5b82811015613ef957613df9898281518110613de857613de861511d565b602002602001015160200151611560565b505f80613e438b8481518110613e1157613e1161511d565b6020026020010151602001518c8581518110613e2f57613e2f61511d565b60200260200101515f01518b60018861171a565b5091509150613e8388828d8681518110613e5f57613e5f61511d565b6020026020010151602001516001600160a01b0316611a579092919063ffffffff16565b81878481518110613e9657613e9661511d565b60200260200101515f0181815250508a8381518110613eb757613eb761511d565b602002602001015160200151878481518110613ed557613ed561511d565b6020908102919091018101516001600160a01b039092169101525050600101613dcb565b5086518067ffffffffffffffff811115613f1557613f156149cc565b604051908082528060200260200182016040528015613f5957816020015b604080518082019091525f8082526020820152815260200190600190039081613f335790505b5093505f5b81811015614051575f60035f8b8481518110613f7c57613f7c61511d565b6020026020010151602001516001600160a01b03166001600160a01b031681526020019081526020015f2090505f613fd1828b8d8681518110613fc157613fc161511d565b60200260200101515f0151613b10565b5090508a8381518110613fe657613fe661511d565b6020026020010151602001518784815181106140045761400461511d565b6020026020010151602001906001600160a01b031690816001600160a01b0316815250508087848151811061403b5761403b61511d565b6020908102919091010151525050600101613f5e565b5050505094509492505050565b6001546040517f5cfe84080000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0383811660248301525f921690635cfe840890604401602060405180830381865afa1580156140c5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906140e9919061528c565b905060018160038111156140ff576140ff6152aa565b148061410d5750600261144a565b8061147a57506003611466565b5f6141476141278361472f565b801561414257505f848061413d5761413d6152ee565b868809115b151590565b61415286868661475b565b61415c919061532e565b95945050505050565b620186a0818302045f811985111561418257505082195f19614187565b508381015b935093915050565b6040517f48b3eabc0000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015282811660248301525f9182918516906348b3eabc90604401602060405180830381865afa1580156141f8573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061421c91906150eb565b6040517e4479d30000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152858116602483015291925090821690624479d390604401602060405180830381865afa158015614283573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061415c9190615106565b60408084015190517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301525f9283929116906370a0823190602401602060405180830381865afa15801561430d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906143319190615106565b9050805f03614343575f9150506135db565b5f6143528660a0015185614811565b90506143c48187604001516001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614398573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906143bc9190615106565b84919061470a565b9695505050505050565b5f6143d983856152d7565b905081600a0a81816143ed576143ed6152ee565b04949350505050565b60608160600151518260400151511461443b576040517fdba17af500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81604001515167ffffffffffffffff811115614459576144596149cc565b604051908082528060200260200182016040528015614482578160200160208202803683370190505b5090505f5b8260400151518110156137eb575f836060015182815181106144ab576144ab61511d565b602090810291909101810151015160808501516040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b0391821660048201529116906370a0823190602401602060405180830381865afa15801561451b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061453f9190615106565b9050805f0361454e5750614595565b614575846060015183815181106145675761456761511d565b602002602001015182614839565b8383815181106145875761458761511d565b602002602001018181525050505b600101614487565b5f80808460018111156145b2576145b26152aa565b03614648576040517fc2fa74940000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152868116602483015288169063c2fa7494906044015b602060405180830381865afa15801561461d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906146419190615106565b90506146e2565b600184600181111561465c5761465c6152aa565b036146b0576040517f32936c440000000000000000000000000000000000000000000000000000000081526001600160a01b03878116600483015286811660248301528816906332936c4490604401614602565b6040517f53c3731500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b670de0b6b3a76400006146f582856152d7565b6146ff919061531b565b979650505050505050565b5f61355461471984600161532e565b6147256003600a6156a5565b613581908561532e565b5f6002826003811115614744576147446152aa565b61474e91906156b0565b60ff166001149050919050565b5f838302815f1985870982811083820303915050805f0361478f57838281614785576147856152ee565b04925050506135db565b8084116147a6576147a660038515026011186148c1565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b5f670de0b6b3a764000061482583856152d7565b61482f919061531b565b6135db908461532e565b5f81156148b9576148b4836080015184602001516001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614888573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906148ac9190615106565b849190613526565b6135db565b5f9392505050565b634e487b715f52806020526024601cfd5b6001600160a01b0381168114612746575f80fd5b8015158114612746575f80fd5b5f805f805f8060c08789031215614908575f80fd5b8635614913816148d2565b95506020870135614923816148d2565b945060408701359350606087013592506080870135614941816148e6565b915060a0870135614951816148e6565b809150509295509295509295565b5f6020828403121561496f575f80fd5b81356135db816148d2565b60c081016110c582846001600160a01b0380825116835280602083015116602084015280604083015116604084015250606081015160608301526080810151608083015260a081015160a08301525050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040805190810167ffffffffffffffff81118282101715614a1c57614a1c6149cc565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715614a6957614a696149cc565b604052919050565b5f67ffffffffffffffff821115614a8a57614a8a6149cc565b5060051b60200190565b5f8060408385031215614aa5575f80fd5b8235614ab0816148d2565b915060208381013567ffffffffffffffff811115614acc575f80fd5b8401601f81018613614adc575f80fd5b8035614aef614aea82614a71565b614a22565b81815260059190911b82018301908381019088831115614b0d575f80fd5b928401925b82841015614b34578335614b25816148d2565b82529284019290840190614b12565b80955050505050509250929050565b602080825282518282018190525f9190848201906040850190845b81811015614b7a57835183529284019291840191600101614b5e565b50909695505050505050565b5f8060408385031215614b97575f80fd5b8235614ba2816148d2565b946020939093013593505050565b5f805f8060808587031215614bc3575f80fd5b8435614bce816148d2565b93506020850135614bde816148d2565b9250604085013591506060850135614bf5816148e6565b939692955090935050565b5f805f60608486031215614c12575f80fd5b8335614c1d816148d2565b9250602084013591506040840135614c34816148e6565b809150509250925092565b604080825283519082018190525f906020906060840190828701845b82811015614c805781516001600160a01b031684529284019290840190600101614c5b565b505050838103828501528451808252858301918301905f5b81811015614d0257614cef8385516001600160a01b0380825116835280602083015116602084015280604083015116604084015250606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c09290920191600101614c98565b5090979650505050505050565b5f8060408385031215614d20575f80fd5b8235614d2b816148d2565b91506020830135614d3b816148e6565b809150509250929050565b5f82601f830112614d55575f80fd5b81356020614d65614aea83614a71565b82815260069290921b84018101918181019086841115614d83575f80fd5b8286015b84811015614dc95760408189031215614d9e575f80fd5b614da66149f9565b8135815284820135614db7816148d2565b81860152835291830191604001614d87565b509695505050505050565b5f67ffffffffffffffff821115614ded57614ded6149cc565b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b5f805f8060808587031215614e2c575f80fd5b8435614e37816148d2565b9350602085013567ffffffffffffffff80821115614e53575f80fd5b614e5f88838901614d46565b94506040870135915080821115614e74575f80fd5b614e8088838901614d46565b93506060870135915080821115614e95575f80fd5b508501601f81018713614ea6575f80fd5b8035614eb4614aea82614dd4565b818152886020838501011115614ec8575f80fd5b816020840160208301375f6020838301015280935050505092959194509250565b5f815180845260208085019450602084015f5b83811015614f2c578151805188528301516001600160a01b03168388015260409096019590820190600101614efc565b509495945050505050565b604081525f614f496040830185614ee9565b828103602084015261415c8185614ee9565b5f805f805f805f60e0888a031215614f71575f80fd5b8735614f7c816148d2565b96506020880135614f8c816148d2565b95506040880135614f9c816148d2565b94506060880135614fac816148d2565b93506080880135925060a0880135614fc3816148d2565b8092505060c0880135905092959891949750929550565b815181526020808301519082015260408083015190820152606081016110c5565b5f805f6060848603121561500d575f80fd5b8335615018816148d2565b92506020840135615028816148d2565b929592945050506040919091013590565b5f805f806080858703121561504c575f80fd5b8435615057816148d2565b93506020850135615067816148d2565b92506040850135615077816148d2565b9396929550929360600135925050565b5f805f805f60a0868803121561509b575f80fd5b85356150a6816148d2565b945060208601356150b6816148d2565b935060408601356150c6816148d2565b92506060860135915060808601356150dd816148e6565b809150509295509295909350565b5f602082840312156150fb575f80fd5b81516135db816148d2565b5f60208284031215615116575f80fd5b5051919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f5b8381101561516457818101518382015260200161514c565b50505f910152565b5f815180845261518381602086016020860161514a565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b60a081525f6151c760a083018861516c565b82810360208401526151d9818861516c565b6001600160a01b039687166040850152949095166060830152509015156080909101529392505050565b608081525f615215608083018761516c565b8281036020840152615227818761516c565b9150506001600160a01b03808516604084015280841660608401525095945050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b818103818111156110c5576110c561524c565b5f6020828403121561529c575f80fd5b8151600481106135db575f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b80820281158282048414176110c5576110c561524c565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f82615329576153296152ee565b500490565b808201808211156110c5576110c561524c565b5f60208284031215615351575f80fd5b815160ff811681146135db575f80fd5b600181815b8085111561539b57815f19048211156153815761538161524c565b8085161561538e57918102915b93841c9390800290615366565b509250929050565b5f826153b1575060016110c5565b816153bd57505f6110c5565b81600181146153d357600281146153dd576153f9565b60019150506110c5565b60ff8411156153ee576153ee61524c565b50506001821b6110c5565b5060208310610133831016604e8410600b841016171561541c575081810a6110c5565b6154268383615361565b805f19048211156154395761543961524c565b029392505050565b5f6135db60ff8416836153a3565b5f6020828403121561545f575f80fd5b815167ffffffffffffffff811115615475575f80fd5b8201601f81018413615485575f80fd5b8051615493614aea82614dd4565b8181528560208385010111156154a7575f80fd5b61415c82602083016020860161514a565b7f4c6971756f72696365204c50200000000000000000000000000000000000000081525f82516154ef81600d85016020870161514a565b91909101600d0192915050565b7f4c4c50000000000000000000000000000000000000000000000000000000000081525f825161553381600385016020870161514a565b9190910160030192915050565b7f4c6971756f72696365204c6f636b656420436f6c6c61746572616c200000000081525f825161557781601c85016020870161514a565b91909101601c0192915050565b7f4c4c43000000000000000000000000000000000000000000000000000000000081525f825161553381600385016020870161514a565b7f4c6971756f72696365204465627420000000000000000000000000000000000081525f82516155f281600f85016020870161514a565b91909101600f0192915050565b7f4c4400000000000000000000000000000000000000000000000000000000000081525f825161563681600285016020870161514a565b9190910160020192915050565b5f60208284031215615653575f80fd5b81516135db816148e6565b6001600160a01b0385168152608060208201525f61567f6080830186614ee9565b82810360408401526156918186614ee9565b905082810360608401526146ff818561516c565b5f6135db83836153a3565b5f60ff8316806156c2576156c26152ee565b8060ff8416069150509291505056fea2646970667358221220003353f0b6ece01317ea69ca5e4d7b180f7ceaecd91dedb13459006ccddd490564736f6c634300081700330000000000000000000000008c9dc23cbd4fdee6688c5fb6ddfa543f7a5b75f8

Deployed Bytecode

0x608060405234801561000f575f80fd5b506004361061018e575f3560e01c80637cf51195116100dd578063b8c876b111610088578063ead5d35911610063578063ead5d3591461045b578063f364181c1461046e578063fb25570314610481575f80fd5b8063b8c876b11461040a578063dbc5b4811461041d578063e9176c6014610430575f80fd5b80638b7c30ab116100b85780638b7c30ab146103b65780639198e515146103d6578063976ce495146103f7575f80fd5b80637cf511951461036f5780637f2870e714610382578063823b0ba8146103a3575f80fd5b806338b51ce11161013d578063525fef2711610118578063525fef271461031057806364654cf51461032357806367f97cc814610339575f80fd5b806338b51ce1146102c75780633fc56217146102ea5780634b8a3529146102fd575f80fd5b8063151541f01161016d578063151541f01461027757806316fa77ab1461028c57806322867d78146102b4575f80fd5b8062bb2691146101925780630abf8bf2146101a75780630c60118b14610264575b5f80fd5b6101a56101a03660046148f3565b610494565b005b61024e6101b536600461495f565b6040805160c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810191909152506001600160a01b039081165f90815260036020818152604092839020835160c081018552815486168152600182015486169281019290925260028101549094169281019290925282015460608201526004820154608082015260059091015460a082015290565b60405161025b919061497a565b60405180910390f35b6101a5610272366004614a94565b610673565b61027f610a51565b60405161025b9190614b43565b61029f61029a36600461495f565b610bd6565b6040805192835260208301919091520161025b565b6101a56102c2366004614b86565b610c34565b6102da6102d536600461495f565b610c44565b604051901515815260200161025b565b6101a56102f8366004614bb0565b610ca3565b6101a561030b366004614b86565b610cb6565b6101a561031e366004614c00565b610cdc565b61032b610cf9565b60405161025b929190614c3f565b61034c610347366004614d0f565b610e8f565b604080519384526001600160a01b0390921660208401529082015260600161025b565b6101a561037d366004614c00565b610ef9565b610395610390366004614e19565b610f06565b60405161025b929190614f37565b6101a56103b1366004614f5b565b610f6a565b6103c96103c436600461495f565b611051565b60405161025b9190614fda565b6103e96103e436600461495f565b6110bb565b60405190815260200161025b565b6101a5610405366004614ffb565b6110cb565b6103e961041836600461495f565b6110d7565b6101a561042b366004615039565b611178565b600154610443906001600160a01b031681565b6040516001600160a01b03909116815260200161025b565b6101a5610469366004614c00565b611253565b6101a561047c366004615087565b611273565b6103c961048f36600461495f565b611358565b61049d866113ba565b6104a6856114b1565b6104af86611560565b50600154604080517f18f51fea00000000000000000000000000000000000000000000000000000000815290515f926001600160a01b0316916318f51fea9160048083019260209291908290030181865afa158015610510573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061053491906150eb565b90505f610544888733875f61171a565b50915061055d90506001600160a01b0389168383611a57565b6040517fb4f8b2b90000000000000000000000000000000000000000000000000000000081523360048201526001600160a01b0389811660248301528881166044830152606482018390526084820187905284151560a48301525f919084169063b4f8b2b99060c4016020604051808303815f875af11580156105e2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106069190615106565b90506106158833338489611acb565b848015610628575061062633610c44565b155b1561065f576040517fe081c8f300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61066888611d8d565b505050505050505050565b6001546001600160a01b031633146106b7576040517f97691a2f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f5b8151811015610a4c575f8282815181106106d5576106d561511d565b6020908102919091018101516001600160a01b038082165f908152600390935260409092208054919350911615610738576040517f587daa3000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280546001810182555f9182527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0385161790556107a283612009565b805160208201516040517f1c600ae10000000000000000000000000000000000000000000000000000000081529293506001600160a01b03891692631c600ae1926107f7929091309089905f906004016151b5565b6020604051808303815f875af1158015610813573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061083791906150eb565b82547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03918216178355604082810151606084015191517f1c600ae100000000000000000000000000000000000000000000000000000000815292891692631c600ae1926108b79291309089906001906004016151b5565b6020604051808303815f875af11580156108d3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108f791906150eb565b6001830180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03928316179055608082015160a08301516040517ff6933f220000000000000000000000000000000000000000000000000000000081529289169263f6933f229261097992909130908990600401615203565b6020604051808303815f875af1158015610995573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109b991906150eb565b6002830180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03928316908117909155835460018501546040805192851683529084166020830152810191909152908416907fd8b220be2e60c36e6b45a9c94291f9e9b082065c9f8ed360725449c66326d7829060600160405180910390a25050506001016106b9565b505050565b6060610a5b6121d1565b5f6002805480602002602001604051908101604052809291908181526020018280548015610ab057602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311610a92575b50505050509050805167ffffffffffffffff811115610ad157610ad16149cc565b604051908082528060200260200182016040528015610afa578160200160208202803683370190505b5091505f60015f9054906101000a90046001600160a01b03166001600160a01b031663d08fc1006040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b4e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b7291906150eb565b90505f5b8251811015610bc757610ba2838281518110610b9457610b9461511d565b602002602001015183612212565b848281518110610bb457610bb461511d565b6020908102919091010152600101610b76565b505050610bd360015f55565b90565b5f805f80610be2610cf9565b6040805160a081018252600180546001600160a01b039081168352306020840152928201859052606082018490529189166080820152929450909250610c2891906122e5565b90969095509350505050565b610c4082333384612442565b5050565b5f805f610c4f610cf9565b6040805160a0810182526001546001600160a01b03908116825230602083015291810184905260608101839052908716608082015291935091505f908190610c9790826122e5565b10159695505050505050565b610cb08433858585611acb565b50505050565b610cbe6121d1565b610cc7336125ba565b610cd382333384612749565b610c4060015f55565b610ce46121d1565b610cf083338484612a2d565b610a4c60015f55565b6060806002805480602002602001604051908101604052809291908181526020018280548015610d5057602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311610d32575b50505050509150815167ffffffffffffffff811115610d7157610d716149cc565b604051908082528060200260200182016040528015610dcf57816020015b6040805160c0810182525f8082526020808301829052928201819052606082018190526080820181905260a082015282525f19909201910181610d8f5790505b5090505f5b8251811015610e8a5760035f848381518110610df257610df261511d565b6020908102919091018101516001600160a01b0390811683528282019390935260409182015f20825160c0810184528154851681526001820154851692810192909252600281015490931691810191909152600382015460608201526004820154608082015260059091015460a08201528251839083908110610e7757610e7761511d565b6020908102919091010152600101610dd4565b509091565b6001600160a01b0382165f908152600360205260408120819081908415610ed057600481015460018201549094506001600160a01b03169250839150610ef1565b600381015481549094506001600160a01b03169250610eee866110d7565b91505b509250925092565b610a4c8333338585611acb565b606080610f116121d1565b610f1e8686863387612d0f565b604051919350915033906001600160a01b038816907fce054da468b0607d4d65949d7572acd17087e593b3e5be27ba665ba1a60ad75b905f90a3610f6160015f55565b94509492505050565b610f726121d1565b60015f9054906101000a90046001600160a01b03166001600160a01b031663511606306040518163ffffffff1660e01b8152600401602060405180830381865afa158015610fc2573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fe691906150eb565b6001600160a01b0316336001600160a01b031614611030576040517f15b3197600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61103f87878787878787612f00565b61104860015f55565b50505050505050565b61107260405180606001604052805f81526020015f81526020015f81525090565b506001600160a01b03165f818152600360208181526040808420815160608101835293810154845260050154838301529383526004905290829020600201549181019190915290565b5f6110c582611560565b92915050565b610a4c83833384612442565b6001600160a01b0381165f8181526003602052604080822060049081015491517f70a082310000000000000000000000000000000000000000000000000000000081523091810191909152919290916370a0823190602401602060405180830381865afa15801561114a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061116e9190615106565b6110c59190615279565b6111806121d1565b60015f9054906101000a90046001600160a01b03166001600160a01b031663511606306040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111d0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111f491906150eb565b6001600160a01b0316336001600160a01b03161461123e576040517f15b3197600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61124a84848484612749565b610cb060015f55565b61125b6121d1565b61126883333385856133d6565b5050610a4c60015f55565b61127b6121d1565b60015f9054906101000a90046001600160a01b03166001600160a01b031663511606306040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112cb573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112ef91906150eb565b6001600160a01b0316336001600160a01b031614611339576040517f15b3197600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61134685858585856133d6565b505061135160015f55565b5050505050565b61137960405180606001604052805f81526020015f81526020015f81525090565b506001600160a01b03165f90815260046020908152604091829020825160608101845281548152600182015492810192909252600201549181019190915290565b6001546040517f5cfe84080000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0383811660248301525f921690635cfe840890604401602060405180830381865afa158015611421573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611445919061528c565b905060015b81600381111561145c5761145c6152aa565b148061147a575060035b816003811115611478576114786152aa565b145b15610c40576040517fc6052bd800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001546040517f5cfe84080000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0383811660248301525f921690635cfe840890604401602060405180830381865afa158015611518573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061153c919061528c565b90506001816003811115611552576115526152aa565b148061147a57506002611466565b6001600160a01b0381165f90815260036020908152604080832060049092528220600281015442900361159657505f9392505050565b5f6115a08561349b565b6040517f1b9286010000000000000000000000000000000000000000000000000000000081526001600160a01b0387811660048301529190911690631b928601906024016020604051808303815f875af1158015611600573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116249190615106565b90505f60015f9054906101000a90046001600160a01b03166001600160a01b03166325ed3d446040518163ffffffff1660e01b8152600401602060405180830381865afa158015611677573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061169b9190615106565b60058501548454919250905f8080670de0b6b3a76400006116bc88876152d7565b6116c6919061531b565b9950505050620186a083880204818101908089036116e48a8661532e565b60058a015560038901546116f990829061532e565b60039099019890985550855550504260029093019290925550919392505050565b5f805f611726886113ba565b5f805f6117338b89610e8f565b9250925092505f198a03611837576040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b038a811660048301528316906370a0823190602401602060405180830381865afa15801561179e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117c29190615106565b935061183083836001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611804573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118289190615106565b869190613526565b95506118a9565b6118a383836001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611877573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061189b9190615106565b8c919061355c565b93508995505b855f036118c1575f805f955095509550505050611a4c565b858310156118fb576040517fb2454c7800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b858303925061190b8b878961358b565b945084811015611947576040517f4323a55500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038b165f90815260036020526040902088156119705760048101849055611978565b600381018490555b6040517f9dc29fac0000000000000000000000000000000000000000000000000000000081526001600160a01b038b8116600483015260248201879052841690639dc29fac906044015f604051808303815f87803b1580156119d8575f80fd5b505af11580156119ea573d5f803e3d5ffd5b505050508815158a6001600160a01b03168d6001600160a01b03167f8c915e101d80f0ed9c723dea5a8c7b20f04d7c2d94c6ea6a382f22a8fd2bfe5b8989604051611a3f929190918252602082015260400190565b60405180910390a4505050505b955095509592505050565b6040516001600160a01b03838116602483015260448201839052610a4c91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506135e2565b611ad4856114b1565b611add85611560565b506001600160a01b0385165f908152600360205260408120908083611b06578260030154611b0c565b82600401545b90508315611c2d57611b9681846001015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b6a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b8e9190615106565b87919061366b565b9150611ba2858261532e565b60048481019190915560018401546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b0389811693820193909352602481018590529116906340c10f19906044015f604051808303815f87803b158015611c12575f80fd5b505af1158015611c24573d5f803e3d5ffd5b50505050611d0d565b611c8281845f015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b6a573d5f803e3d5ffd5b9150611c8e858261532e565b600384015582546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b03888116600483015260248201859052909116906340c10f19906044015f604051808303815f87803b158015611cf6575f80fd5b505af1158015611d08573d5f803e3d5ffd5b505050505b611d226001600160a01b038916883088613690565b611d2b88611d8d565b604080516001600160a01b038981168252602082018890529181018490528515159180891691908b16907f62a793ab5de9d8b6f21940de9c7e83ec9ab7ae16c9db46977a2fa2c01b89a85b906060015b60405180910390a45050505050505050565b600154604080517fb888879e00000000000000000000000000000000000000000000000000000000815290515f926001600160a01b03169163b888879e9160048083019260209291908290030181865afa158015611ded573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e1191906150eb565b6001600160a01b0383165f908152600360208190526040822060048101549181015493945092611e41919061532e565b6001546040517f437e3edc0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b03878116602483015292935091169063437e3edc90604401602060405180830381865afa158015611eaa573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ece9190615106565b846001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f0a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f2e9190615341565b611f3990600a615441565b6040517f41976e090000000000000000000000000000000000000000000000000000000081526001600160a01b0387811660048301528491908716906341976e0990602401602060405180830381865afa158015611f99573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fbd9190615106565b611fc791906152d7565b611fd1919061531b565b1115610cb0576040517f6d85e6e300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6120426040518060c001604052806060815260200160608152602001606081526020016060815260200160608152602001606081525090565b5f826001600160a01b03166395d89b416040518163ffffffff1660e01b81526004015f60405180830381865afa15801561207e573d5f803e3d5ffd5b505050506040513d5f823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526120c3919081019061544f565b90506040518060c00160405280826040516020016120e191906154b8565b60405160208183030381529060405281526020018260405160200161210691906154fc565b60405160208183030381529060405281526020018260405160200161212b9190615540565b6040516020818303038152906040528152602001826040516020016121509190615584565b60405160208183030381529060405281526020018260405160200161217591906155bb565b60405160208183030381529060405281526020018260405160200161219a91906155ff565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905290529392505050565b60025f540361220c576040517f3ee5aeb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60025f55565b5f61221c836113ba565b61222583611560565b506001600160a01b0383165f9081526004602052604090206001810154815461224e9190615279565b91505f61225a856110d7565b905080831115612268578092505b825f03612279575f925050506110c5565b600182018054840190556122976001600160a01b0386168585611a57565b604080516001600160a01b038681168252602082018690528716917fe59943d5ba8f431f481a3df311cc18e2ff305525e251144b0042be1b59dbc097910160405180910390a2505092915050565b5f805f6122f1856136c9565b90506122fc816137f1565b5f0361230e575f80925092505061243b565b5f855f01516001600160a01b031663b888879e6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561234e573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061237291906150eb565b90505f6123848288604001518561382c565b90505f612390826137f1565b9050805f036123a8575f80955095505050505061243b565b5f6123b3848a613a4f565b90505f6123bf826137f1565b9050805f036123da575f195f9750975050505050505061243b565b5f6123f38b5f01518c602001518d604001518d87613a6c565b905081612408670de0b6b3a7640000866152d7565b612412919061531b565b985081612427670de0b6b3a7640000836152d7565b612431919061531b565b9750505050505050505b9250929050565b61244b846114b1565b61245484611560565b506001600160a01b0384165f9081526003602052604081209080612479838786613b10565b91509150805f036124b6576040517f685e923500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6124cb6001600160a01b038816863085613690565b60028301546040517f9dc29fac0000000000000000000000000000000000000000000000000000000081526001600160a01b0388811660048301526024820184905290911690639dc29fac906044015f604051808303815f87803b158015612531575f80fd5b505af1158015612543573d5f803e3d5ffd5b5050505081836005015f82825461255a9190615279565b9091555050604080516001600160a01b03878116825260208201859052918101839052818816918916907f81cfb79463601de705d4cf6b8d69112983d76a685120e5e4d3581f30871b87fc9060600160405180910390a350505050505050565b60015f9054906101000a90046001600160a01b03166001600160a01b031663511606306040518163ffffffff1660e01b8152600401602060405180830381865afa15801561260a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061262e91906150eb565b6001600160a01b031663c61861816040518163ffffffff1660e01b8152600401602060405180830381865afa158015612669573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061268d91906150eb565b6040517fe75600c30000000000000000000000000000000000000000000000000000000081526001600160a01b038381166004830152919091169063e75600c390602401602060405180830381865afa1580156126ec573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127109190615643565b612746576040517ff19f8c9e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50565b612752846113ba565b61275b84611560565b5080612766856110d7565b101561279e576040517f4323a55500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038085165f908152600360209081526040808320600581015460015483517f072ea61c0000000000000000000000000000000000000000000000000000000081529351929691959491169263072ea61c92600480830193928290030181865afa158015612814573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128389190615106565b90505f811561285e57620186a061284f83876152d7565b612859919061531b565b612860565b5f5b90505f6128ee84866002015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128b9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128dd9190615106565b6128e7858a61532e565b919061355c565b9050816128fb878661532e565b612905919061532e565b60058601556001600160a01b0389165f908152600460205260408120805484929061293190849061532e565b909155505060028501546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b038a8116600483015260248201849052909116906340c10f19906044015f604051808303815f87803b15801561299c575f80fd5b505af11580156129ae573d5f803e3d5ffd5b506129c7925050506001600160a01b038a168888611a57565b6129d088613c5b565b604080516001600160a01b03898116825260208201899052918101839052818a16918b16907f96558a334f4759f0e7c423d68c84721860bd8fbf94ddc4e55158ecb125ad04b59060600160405180910390a3505050505050505050565b612a3684611560565b506001600160a01b0384165f908152600360205260408120908080612a5e888789888561171a565b50909150508415612bce5760038401548454604080517f18160ddd0000000000000000000000000000000000000000000000000000000081529051929550612b009286926001600160a01b0316916318160ddd9160048083019260209291908290030181865afa158015612ad4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612af89190615106565b83919061366b565b9150612b0c818461532e565b600385015583546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b03898116600483015260248201859052909116906340c10f19906044015f604051808303815f87803b158015612b74575f80fd5b505af1158015612b86573d5f803e3d5ffd5b50505050612b9387610c44565b612bc9576040517fe081c8f300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612cbe565b83600401549250612c2b83856001015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ad4573d5f803e3d5ffd5b9150612c37818461532e565b60048581019190915560018501546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b038a811693820193909352602481018590529116906340c10f19906044015f604051808303815f87803b158015612ca7575f80fd5b505af1158015612cb9573d5f803e3d5ffd5b505050505b604080516001600160a01b03808a168083526020830185905292820185905287159291908b16907f62a793ab5de9d8b6f21940de9c7e83ec9ab7ae16c9db46977a2fa2c01b89a85b90606001611d7b565b6060805f80612d1d89610bd6565b91509150808211612df9575f885167ffffffffffffffff811115612d4357612d436149cc565b604051908082528060200260200182016040528015612d8757816020015b604080518082019091525f8082526020820152815260200190600190039081612d615790505b5090505f885167ffffffffffffffff811115612da557612da56149cc565b604051908082528060200260200182016040528015612de957816020015b604080518082019091525f8082526020820152815260200190600190039081612dc35790505b50919550909350612ef692505050565b612e0588888b89613ceb565b6040517f72ea3feb00000000000000000000000000000000000000000000000000000000815291955093506001600160a01b038716906372ea3feb90612e55908c90889088908b9060040161565e565b5f604051808303815f87803b158015612e6c575f80fd5b505af1158015612e7e573d5f803e3d5ffd5b505050505f80612e8d8b610bd6565b9150915080821115612ef1578382101580612eba5750612ead81856152d7565b612eb784846152d7565b10155b15612ef1576040517f62a8087e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505b9550959350505050565b612f098761405e565b612f1287611560565b50612f1c82611560565b5082612f27886110d7565b1015612f5f576040517f4323a55500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038088165f908152600360209081526040808320600581015460015483517f072ea61c0000000000000000000000000000000000000000000000000000000081529351929691959491169263072ea61c92600480830193928290030181865afa158015612fd5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ff99190615106565b90505f811561301f57620186a061301083896152d7565b61301a919061531b565b613021565b5f5b90505f6130a884866002015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561307a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061309e9190615106565b6128e7858c61532e565b9050816130b5898661532e565b6130bf919061532e565b60058601556001600160a01b038c165f90815260046020526040812080548492906130eb90849061532e565b909155505060028501546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b038d8116600483015260248201849052909116906340c10f19906044015f604051808303815f87803b158015613156575f80fd5b505af1158015613168573d5f803e3d5ffd5b50613181925050506001600160a01b038d168a8a611a57565b6001600160a01b038088165f908152600360209081526040808320600480820154600183015484517f18160ddd0000000000000000000000000000000000000000000000000000000081529451939c50909661322b95889592909116936318160ddd93838101938290030181865afa1580156131ff573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906132239190615106565b8a919061366b565b9050613237888361532e565b8760040181905550866001015f9054906101000a90046001600160a01b03166001600160a01b03166340c10f198e836040518363ffffffff1660e01b81526004016132979291906001600160a01b03929092168252602082015260400190565b5f604051808303815f87803b1580156132ae575f80fd5b505af11580156132c0573d5f803e3d5ffd5b506132da925050506001600160a01b038a168d308b613690565b6132e38d613c5b565b6132ec89611d8d565b600115158d6001600160a01b03168a6001600160a01b03167f62a793ab5de9d8b6f21940de9c7e83ec9ab7ae16c9db46977a2fa2c01b89a85b8f8c86604051613353939291906001600160a01b039390931683526020830191909152604082015260600190565b60405180910390a48c6001600160a01b03168e6001600160a01b03167f96558a334f4759f0e7c423d68c84721860bd8fbf94ddc4e55158ecb125ad04b58d8d876040516133be939291906001600160a01b039390931683526020830191909152604082015260600190565b60405180910390a35050505050505050505050505050565b5f806133e187611560565b505f6133f0888689875f61171a565b91945090925090505f839003613432576040517fb8cb621900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6134466001600160a01b0389168783611a57565b838015613459575061345787610c44565b155b15613490576040517fe081c8f300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b509550959350505050565b6001546040517f48b3eabc0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0383811660248301525f9216906348b3eabc90604401602060405180830381865afa158015613502573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110c591906150eb565b5f61355461353584600161532e565b6135416003600a6156a5565b61354b908561532e565b8691905f61411a565b949350505050565b5f61355461356c6003600a6156a5565b613576908461532e565b61358185600161532e565b869190600161411a565b5f815f0361359a5750816135db565b6001600160a01b0384165f908152600460205260408120546135bd908585614165565b6001600160a01b0387165f9081526004602052604090205584039150505b9392505050565b5f8060205f8451602086015f885af180613601576040513d5f823e3d81fd5b50505f513d91508115613618578060011415613625565b6001600160a01b0384163b155b15610cb0576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b038516600482015260240160405180910390fd5b5f61355461367b6003600a6156a5565b613685908461532e565b61354b85600161532e565b6040516001600160a01b038481166024830152838116604483015260648201839052610cb09186918216906323b872dd90608401611a84565b60608160600151518260400151511461370e576040517fdba17af500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81604001515167ffffffffffffffff81111561372c5761372c6149cc565b604051908082528060200260200182016040528015613755578160200160208202803683370190505b5090505f5b8260400151518110156137eb575f6137978460200151855f01518660400151858151811061378a5761378a61511d565b602002602001015161418f565b90506137c5846060015183815181106137b2576137b261511d565b60200260200101518560800151836142a7565b8383815181106137d7576137d761511d565b60209081029190910101525060010161375a565b50919050565b5f805b82518110156137eb5782818151811061380f5761380f61511d565b602002602001015182613822919061532e565b91506001016137f4565b60608151835114613869576040517fdba17af500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b825167ffffffffffffffff811115613883576138836149cc565b6040519080825280602002602001820160405280156138ac578160200160208202803683370190505b5090505f5b8351811015613a47578281815181106138cc576138cc61511d565b60200260200101515f0315613a3f575f856001600160a01b03166341976e098684815181106138fd576138fd61511d565b60200260200101516040518263ffffffff1660e01b815260040161393091906001600160a01b0391909116815260200190565b602060405180830381865afa15801561394b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061396f9190615106565b90505f8583815181106139845761398461511d565b60200260200101516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156139c7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906139eb9190615341565b9050613a1e828260ff16878681518110613a0757613a0761511d565b60200260200101516143ce9092919063ffffffff16565b848481518110613a3057613a3061511d565b60200260200101818152505050505b6001016138b1565b509392505050565b60605f613a5b836143f6565b90506135548484604001518361382c565b5f8151845114613aa8576040517fdba17af500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f5b8451811015613b0657613af28787878481518110613aca57613aca61511d565b602002602001015187878681518110613ae557613ae561511d565b602002602001015161459d565b613afc908361532e565b9150600101613aaa565b5095945050505050565b60028301546040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301525f9283928392909116906370a0823190602401602060405180830381865afa158015613b79573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613b9d9190615106565b90505f866002015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613bf2573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613c169190615106565b60058801549091505f613c2a84838561470a565b9050808710613c3e57809550839450613c4f565b869550613c4c86838561366b565b94505b50505050935093915050565b5f80613c65610cf9565b6040805160a0810182526001546001600160a01b03908116825230602083015291810184905260608101839052908616608082015291935091505f908190613cad90826122e5565b9150915080821115611351576040517f32ad975800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b835160609081908067ffffffffffffffff811115613d0b57613d0b6149cc565b604051908082528060200260200182016040528015613d4f57816020015b604080518082019091525f8082526020820152815260200190600190039081613d295790505b5092505f60015f9054906101000a90046001600160a01b03166001600160a01b031663eafecffa6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613da3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613dc79190615106565b90505f5b82811015613ef957613df9898281518110613de857613de861511d565b602002602001015160200151611560565b505f80613e438b8481518110613e1157613e1161511d565b6020026020010151602001518c8581518110613e2f57613e2f61511d565b60200260200101515f01518b60018861171a565b5091509150613e8388828d8681518110613e5f57613e5f61511d565b6020026020010151602001516001600160a01b0316611a579092919063ffffffff16565b81878481518110613e9657613e9661511d565b60200260200101515f0181815250508a8381518110613eb757613eb761511d565b602002602001015160200151878481518110613ed557613ed561511d565b6020908102919091018101516001600160a01b039092169101525050600101613dcb565b5086518067ffffffffffffffff811115613f1557613f156149cc565b604051908082528060200260200182016040528015613f5957816020015b604080518082019091525f8082526020820152815260200190600190039081613f335790505b5093505f5b81811015614051575f60035f8b8481518110613f7c57613f7c61511d565b6020026020010151602001516001600160a01b03166001600160a01b031681526020019081526020015f2090505f613fd1828b8d8681518110613fc157613fc161511d565b60200260200101515f0151613b10565b5090508a8381518110613fe657613fe661511d565b6020026020010151602001518784815181106140045761400461511d565b6020026020010151602001906001600160a01b031690816001600160a01b0316815250508087848151811061403b5761403b61511d565b6020908102919091010151525050600101613f5e565b5050505094509492505050565b6001546040517f5cfe84080000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0383811660248301525f921690635cfe840890604401602060405180830381865afa1580156140c5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906140e9919061528c565b905060018160038111156140ff576140ff6152aa565b148061410d5750600261144a565b8061147a57506003611466565b5f6141476141278361472f565b801561414257505f848061413d5761413d6152ee565b868809115b151590565b61415286868661475b565b61415c919061532e565b95945050505050565b620186a0818302045f811985111561418257505082195f19614187565b508381015b935093915050565b6040517f48b3eabc0000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015282811660248301525f9182918516906348b3eabc90604401602060405180830381865afa1580156141f8573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061421c91906150eb565b6040517e4479d30000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152858116602483015291925090821690624479d390604401602060405180830381865afa158015614283573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061415c9190615106565b60408084015190517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301525f9283929116906370a0823190602401602060405180830381865afa15801561430d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906143319190615106565b9050805f03614343575f9150506135db565b5f6143528660a0015185614811565b90506143c48187604001516001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614398573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906143bc9190615106565b84919061470a565b9695505050505050565b5f6143d983856152d7565b905081600a0a81816143ed576143ed6152ee565b04949350505050565b60608160600151518260400151511461443b576040517fdba17af500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81604001515167ffffffffffffffff811115614459576144596149cc565b604051908082528060200260200182016040528015614482578160200160208202803683370190505b5090505f5b8260400151518110156137eb575f836060015182815181106144ab576144ab61511d565b602090810291909101810151015160808501516040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b0391821660048201529116906370a0823190602401602060405180830381865afa15801561451b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061453f9190615106565b9050805f0361454e5750614595565b614575846060015183815181106145675761456761511d565b602002602001015182614839565b8383815181106145875761458761511d565b602002602001018181525050505b600101614487565b5f80808460018111156145b2576145b26152aa565b03614648576040517fc2fa74940000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152868116602483015288169063c2fa7494906044015b602060405180830381865afa15801561461d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906146419190615106565b90506146e2565b600184600181111561465c5761465c6152aa565b036146b0576040517f32936c440000000000000000000000000000000000000000000000000000000081526001600160a01b03878116600483015286811660248301528816906332936c4490604401614602565b6040517f53c3731500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b670de0b6b3a76400006146f582856152d7565b6146ff919061531b565b979650505050505050565b5f61355461471984600161532e565b6147256003600a6156a5565b613581908561532e565b5f6002826003811115614744576147446152aa565b61474e91906156b0565b60ff166001149050919050565b5f838302815f1985870982811083820303915050805f0361478f57838281614785576147856152ee565b04925050506135db565b8084116147a6576147a660038515026011186148c1565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b5f670de0b6b3a764000061482583856152d7565b61482f919061531b565b6135db908461532e565b5f81156148b9576148b4836080015184602001516001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614888573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906148ac9190615106565b849190613526565b6135db565b5f9392505050565b634e487b715f52806020526024601cfd5b6001600160a01b0381168114612746575f80fd5b8015158114612746575f80fd5b5f805f805f8060c08789031215614908575f80fd5b8635614913816148d2565b95506020870135614923816148d2565b945060408701359350606087013592506080870135614941816148e6565b915060a0870135614951816148e6565b809150509295509295509295565b5f6020828403121561496f575f80fd5b81356135db816148d2565b60c081016110c582846001600160a01b0380825116835280602083015116602084015280604083015116604084015250606081015160608301526080810151608083015260a081015160a08301525050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040805190810167ffffffffffffffff81118282101715614a1c57614a1c6149cc565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715614a6957614a696149cc565b604052919050565b5f67ffffffffffffffff821115614a8a57614a8a6149cc565b5060051b60200190565b5f8060408385031215614aa5575f80fd5b8235614ab0816148d2565b915060208381013567ffffffffffffffff811115614acc575f80fd5b8401601f81018613614adc575f80fd5b8035614aef614aea82614a71565b614a22565b81815260059190911b82018301908381019088831115614b0d575f80fd5b928401925b82841015614b34578335614b25816148d2565b82529284019290840190614b12565b80955050505050509250929050565b602080825282518282018190525f9190848201906040850190845b81811015614b7a57835183529284019291840191600101614b5e565b50909695505050505050565b5f8060408385031215614b97575f80fd5b8235614ba2816148d2565b946020939093013593505050565b5f805f8060808587031215614bc3575f80fd5b8435614bce816148d2565b93506020850135614bde816148d2565b9250604085013591506060850135614bf5816148e6565b939692955090935050565b5f805f60608486031215614c12575f80fd5b8335614c1d816148d2565b9250602084013591506040840135614c34816148e6565b809150509250925092565b604080825283519082018190525f906020906060840190828701845b82811015614c805781516001600160a01b031684529284019290840190600101614c5b565b505050838103828501528451808252858301918301905f5b81811015614d0257614cef8385516001600160a01b0380825116835280602083015116602084015280604083015116604084015250606081015160608301526080810151608083015260a081015160a08301525050565b9284019260c09290920191600101614c98565b5090979650505050505050565b5f8060408385031215614d20575f80fd5b8235614d2b816148d2565b91506020830135614d3b816148e6565b809150509250929050565b5f82601f830112614d55575f80fd5b81356020614d65614aea83614a71565b82815260069290921b84018101918181019086841115614d83575f80fd5b8286015b84811015614dc95760408189031215614d9e575f80fd5b614da66149f9565b8135815284820135614db7816148d2565b81860152835291830191604001614d87565b509695505050505050565b5f67ffffffffffffffff821115614ded57614ded6149cc565b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b5f805f8060808587031215614e2c575f80fd5b8435614e37816148d2565b9350602085013567ffffffffffffffff80821115614e53575f80fd5b614e5f88838901614d46565b94506040870135915080821115614e74575f80fd5b614e8088838901614d46565b93506060870135915080821115614e95575f80fd5b508501601f81018713614ea6575f80fd5b8035614eb4614aea82614dd4565b818152886020838501011115614ec8575f80fd5b816020840160208301375f6020838301015280935050505092959194509250565b5f815180845260208085019450602084015f5b83811015614f2c578151805188528301516001600160a01b03168388015260409096019590820190600101614efc565b509495945050505050565b604081525f614f496040830185614ee9565b828103602084015261415c8185614ee9565b5f805f805f805f60e0888a031215614f71575f80fd5b8735614f7c816148d2565b96506020880135614f8c816148d2565b95506040880135614f9c816148d2565b94506060880135614fac816148d2565b93506080880135925060a0880135614fc3816148d2565b8092505060c0880135905092959891949750929550565b815181526020808301519082015260408083015190820152606081016110c5565b5f805f6060848603121561500d575f80fd5b8335615018816148d2565b92506020840135615028816148d2565b929592945050506040919091013590565b5f805f806080858703121561504c575f80fd5b8435615057816148d2565b93506020850135615067816148d2565b92506040850135615077816148d2565b9396929550929360600135925050565b5f805f805f60a0868803121561509b575f80fd5b85356150a6816148d2565b945060208601356150b6816148d2565b935060408601356150c6816148d2565b92506060860135915060808601356150dd816148e6565b809150509295509295909350565b5f602082840312156150fb575f80fd5b81516135db816148d2565b5f60208284031215615116575f80fd5b5051919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f5b8381101561516457818101518382015260200161514c565b50505f910152565b5f815180845261518381602086016020860161514a565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b60a081525f6151c760a083018861516c565b82810360208401526151d9818861516c565b6001600160a01b039687166040850152949095166060830152509015156080909101529392505050565b608081525f615215608083018761516c565b8281036020840152615227818761516c565b9150506001600160a01b03808516604084015280841660608401525095945050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b818103818111156110c5576110c561524c565b5f6020828403121561529c575f80fd5b8151600481106135db575f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b80820281158282048414176110c5576110c561524c565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f82615329576153296152ee565b500490565b808201808211156110c5576110c561524c565b5f60208284031215615351575f80fd5b815160ff811681146135db575f80fd5b600181815b8085111561539b57815f19048211156153815761538161524c565b8085161561538e57918102915b93841c9390800290615366565b509250929050565b5f826153b1575060016110c5565b816153bd57505f6110c5565b81600181146153d357600281146153dd576153f9565b60019150506110c5565b60ff8411156153ee576153ee61524c565b50506001821b6110c5565b5060208310610133831016604e8410600b841016171561541c575081810a6110c5565b6154268383615361565b805f19048211156154395761543961524c565b029392505050565b5f6135db60ff8416836153a3565b5f6020828403121561545f575f80fd5b815167ffffffffffffffff811115615475575f80fd5b8201601f81018413615485575f80fd5b8051615493614aea82614dd4565b8181528560208385010111156154a7575f80fd5b61415c82602083016020860161514a565b7f4c6971756f72696365204c50200000000000000000000000000000000000000081525f82516154ef81600d85016020870161514a565b91909101600d0192915050565b7f4c4c50000000000000000000000000000000000000000000000000000000000081525f825161553381600385016020870161514a565b9190910160030192915050565b7f4c6971756f72696365204c6f636b656420436f6c6c61746572616c200000000081525f825161557781601c85016020870161514a565b91909101601c0192915050565b7f4c4c43000000000000000000000000000000000000000000000000000000000081525f825161553381600385016020870161514a565b7f4c6971756f72696365204465627420000000000000000000000000000000000081525f82516155f281600f85016020870161514a565b91909101600f0192915050565b7f4c4400000000000000000000000000000000000000000000000000000000000081525f825161563681600285016020870161514a565b9190910160020192915050565b5f60208284031215615653575f80fd5b81516135db816148e6565b6001600160a01b0385168152608060208201525f61567f6080830186614ee9565b82810360408401526156918186614ee9565b905082810360608401526146ff818561516c565b5f6135db83836153a3565b5f60ff8316806156c2576156c26152ee565b8060ff8416069150509291505056fea2646970667358221220003353f0b6ece01317ea69ca5e4d7b180f7ceaecd91dedb13459006ccddd490564736f6c63430008170033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
0x046fFB0dFde6A21B4Fc609841f55C31b6297CfB8
Loading...
Loading
[ Download: CSV Export  ]
[ 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.