Overview
S Balance
0 S
S Value
-More Info
Private Name Tags
ContractCreator
Latest 1 internal transaction
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
331755 | 8 days ago | Contract Creation | 0 S |
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
LiquidityBorrowingManager
Compiler Version
v0.8.23+commit.f704f362
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: SAL-1.0 pragma solidity 0.8.23; /** * WAGMI Leverage Protocol v2.3 * wagmi.com * / | _ / | / \ / \ / \ / |/ | $$ | / \ $$ |/$$$$$$ |/$$$$$$ |$$ \ /$$ |$$$$$$/ $$ |/$ \$$ |$$ |__$$ |$$ | _$$/ $$$ \ /$$$ | $$ | $$ /$$$ $$ |$$ $$ |$$ |/ |$$$$ /$$$$ | $$ | $$ $$/$$ $$ |$$$$$$$$ |$$ |$$$$ |$$ $$ $$/$$ | $$ | $$$$/ $$$$ |$$ | $$ |$$ \__$$ |$$ |$$$/ $$ | _$$ |_ $$$/ $$$ |$$ | $$ |$$ $$/ $$ | $/ $$ |/ $$ | $$/ $$/ $$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ */ import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "./abstract/OwnerSettings.sol"; import "./abstract/DailyRateAndCollateral.sol"; import "./libraries/ErrLib.sol"; import "./interfaces/ILiquidityBorrowingManager.sol"; import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; contract LiquidityBorrowingManager is ILiquidityBorrowingManager, OwnerSettings, DailyRateAndCollateral, ReentrancyGuard { using { ErrLib.revertError } for bool; using EnumerableSet for EnumerableSet.Bytes32Set; /// borrowingKey=>LoanInfo mapping(bytes32 => LoanInfo[]) private loansInfo; /// borrowingKey=>BorrowingInfo mapping(bytes32 => BorrowingInfo) public borrowingsInfo; /// NonfungiblePositionManager tokenId => EnumerableSet.Bytes32Set mapping(uint256 => EnumerableSet.Bytes32Set) private tokenIdToBorrowingKeys; /// borrower => EnumerableSet.Bytes32Set mapping(address => EnumerableSet.Bytes32Set) private userBorrowingKeys; /// @dev Modifier to check if the current block timestamp is before or equal to the deadline. modifier checkDeadline(uint256 deadline) { (_blockTimestamp() > deadline).revertError(ErrLib.ErrorCode.TOO_OLD_TRANSACTION); _; } modifier onlyOperator() { (msg.sender != operator).revertError(ErrLib.ErrorCode.INVALID_CALLER); _; } function _blockTimestamp() internal view returns (uint256) { return block.timestamp; } constructor( address _underlyingPositionManagerAddress, address _flashLoanAggregator, address _lightQuoterV3, address _underlyingV3Factory, bytes32 _underlyingV3PoolInitCodeHash ) LiquidityManager( _underlyingPositionManagerAddress, _flashLoanAggregator, _lightQuoterV3, _underlyingV3Factory, _underlyingV3PoolInitCodeHash ) {} /** * @dev Adds or removes a swap call params to the whitelist. * @param swapTarget The address of the target contract for the swap call. * @param isAllowed A boolean indicating whether the swap call is allowed or not. */ function setSwapCallToWhitelist(address swapTarget, bool isAllowed) external onlyOwner { (swapTarget == VAULT_ADDRESS || swapTarget == address(this) || swapTarget == address(underlyingPositionManager)).revertError( ErrLib.ErrorCode.FORBIDDEN ); whitelistedCall[swapTarget] = isAllowed; emit ToWhitelist(swapTarget, isAllowed); } /** * @notice This function allows the owner to collect protocol fees for multiple tokens * and transfer them to a specified recipient. * @dev Only the contract owner can call this function. * @param recipient The address of the recipient who will receive the collected fees. * @param tokens An array of addresses representing the tokens for which fees will be collected. */ function collectProtocol(address recipient, address[] calldata tokens) external onlyOwner { uint256[] memory amounts = _collect(platformsFeesInfo, recipient, tokens); emit CollectProtocol(recipient, tokens, amounts); } /** * @notice This function allows the caller to collect their own loan fees for multiple tokens * and transfer them to themselves. * @param tokens An array of addresses representing the tokens for which fees will be collected. */ function collectLoansFees(address[] calldata tokens) external { mapping(address => uint256) storage collection = loansFeesInfo[msg.sender]; uint256[] memory amounts = _collect(collection, msg.sender, tokens); emit CollectLoansFees(msg.sender, tokens, amounts); } /** * @notice This function is used to update the daily rate for holding token for specific pair. * @dev Only the daily rate operator can call this function. * @param saleToken The address of the sale token. * @param holdToken The address of the hold token. * @param value The new value of the daily rate for the hold token will be calculated based * on the volatility of the pair and the popularity of loans in it * @dev The value must be within the range of MIN_DAILY_RATE and MAX_DAILY_RATE. */ function updateHoldTokenDailyRate( address saleToken, address holdToken, uint256 value ) external onlyOperator { if (value > Constants.MAX_DAILY_RATE || value < Constants.MIN_DAILY_RATE) { revert InvalidSettingsValue(value); } // If the value is within the acceptable range, the function updates the currentDailyRate property // of the holdTokenRateInfo structure associated with the token pair. (, TokenInfo storage holdTokenRateInfo) = _updateHoldTokenRateInfo(saleToken, holdToken); holdTokenRateInfo.currentDailyRate = value; emit UpdateHoldTokenDailyRate(saleToken, holdToken, value); } function updateHoldTokenEntranceFee( address saleToken, address holdToken, uint256 value ) external onlyOperator { if (value > Constants.MAX_ENTRANCE_FEE_BPS + 1) { revert InvalidSettingsValue(value); } // If the value is within the acceptable range, the function updates the currentDailyRate property // of the holdTokenRateInfo structure associated with the token pair. (, TokenInfo storage holdTokenEntranceFeeInfo) = _updateHoldTokenRateInfo( saleToken, holdToken ); holdTokenEntranceFeeInfo.entranceFeeBP = value; emit UpdateHoldTokeEntranceFee(saleToken, holdToken, value); } /** * @notice This function is used to check the daily rate collateral for a specific borrowing. * @param borrowingKey The key of the borrowing. * @return balance The balance of the daily rate collateral. * @return estimatedLifeTime The estimated lifetime of the collateral in seconds. */ function checkDailyRateCollateral( bytes32 borrowingKey ) external view returns (int256 balance, uint256 estimatedLifeTime) { (, balance, estimatedLifeTime) = _getDebtInfo(borrowingKey); balance /= int256(Constants.COLLATERAL_BALANCE_PRECISION); } /** * @notice Get information about loans associated with a borrowing key * @dev This function retrieves an array of loan information for a given borrowing key. * The loans are stored in the loansInfo mapping, which is a mapping of borrowing keys to LoanInfo arrays. * @param borrowingKey The unique key associated with the borrowing * @return loans An array containing LoanInfo structs representing the loans associated with the borrowing key */ function getLoansInfo(bytes32 borrowingKey) external view returns (LoanInfo[] memory loans) { loans = loansInfo[borrowingKey]; } /** * @notice Retrieves the borrowing information for a specific NonfungiblePositionManager tokenId. * @param tokenId The unique identifier of the PositionManager token. * @return extinfo An array of BorrowingInfoExt structs representing the borrowing information. */ function getLenderCreditsInfo( uint256 tokenId ) external view returns (BorrowingInfoExt[] memory extinfo) { bytes32[] memory borrowingKeys = getBorrowingKeysForTokenId(tokenId); extinfo = _getDebtsInfo(borrowingKeys); } /** * @dev Retrieves the borrowing keys associated with a token ID. * @param tokenId The identifier of the token. * @return borrowingKeys An array of borrowing keys. */ function getBorrowingKeysForTokenId( uint256 tokenId ) public view returns (bytes32[] memory borrowingKeys) { borrowingKeys = tokenIdToBorrowingKeys[tokenId].values(); } /** * @dev Retrieves the borrowing keys for a specific borrower. * @param borrower The address of the borrower. * @return borrowingKeys An array of borrowing keys. */ function getBorrowingKeysForBorrower( address borrower ) public view returns (bytes32[] memory borrowingKeys) { borrowingKeys = userBorrowingKeys[borrower].values(); } /** * @notice Retrieves the debts information for a specific borrower. * @param borrower The address of the borrower. * @return extinfo An array of BorrowingInfoExt structs representing the borrowing information. */ function getBorrowerDebtsInfo( address borrower ) external view returns (BorrowingInfoExt[] memory extinfo) { bytes32[] memory borrowingKeys = userBorrowingKeys[borrower].values(); extinfo = _getDebtsInfo(borrowingKeys); } /** * @dev Returns the current daily rate for holding token. * @param saleToken The address of the token being sold. * @param holdToken The address of the token being held. * @return holdTokenRateInfo The structured data containing detailed information for the hold token. */ function getHoldTokenInfo( address saleToken, address holdToken ) external view returns (TokenInfo memory holdTokenRateInfo) { holdTokenRateInfo = _getHoldTokenInfo(saleToken, holdToken); } /** * @dev Returns the fees information for multiple tokens in an array. * @param feesOwner The address of the owner of the fees. * @param tokens An array of token addresses for which the fees are to be retrieved. * @return fees An array containing the fees for each token. */ function getFeesInfo( address feesOwner, address[] calldata tokens ) external view returns (uint256[] memory fees) { mapping(address => uint256) storage collection = loansFeesInfo[feesOwner]; fees = _getFees(collection, tokens); } /** * @dev Get the platform fees information for a list of tokens. * * This function returns an array of fees corresponding to the list of input tokens provided. * Each fee is retrieved from the `platformsFeesInfo` mapping which stores the fee for each token address. * * @param tokens An array of token addresses for which to retrieve the fees information. * @return fees Returns an array of fees, one per each token given as input in the same order. */ function getPlatformFeesInfo( address[] calldata tokens ) external view returns (uint256[] memory fees) { mapping(address => uint256) storage collection = platformsFeesInfo; fees = _getFees(collection, tokens); } /** * @dev Calculates the liquidation bonus for a given token, borrowed amount, and times factor. * @param token The address of the token. * @param borrowedAmount The amount of tokens borrowed. * @return liquidationBonus The calculated liquidation bonus. */ function getLiquidationBonus( address token, uint256 borrowedAmount ) public view returns (uint256 liquidationBonus) { // Retrieve liquidation bonus for the given token Liquidation memory liq = liquidationBonusForToken[token]; unchecked { if (liq.bonusBP == 0) { // If there is no specific bonus for the token // Use default bonus liq.minBonusAmount = Constants.MINIMUM_AMOUNT; liq.bonusBP = dafaultLiquidationBonusBP; } liquidationBonus = (borrowedAmount * liq.bonusBP) / Constants.BP; if (liquidationBonus < liq.minBonusAmount) { liquidationBonus = liq.minBonusAmount; } } } /** * @dev Calculates the collateral amount required for a lifetime in seconds. * * @param borrowingKey The unique identifier of the borrowing. * @param lifetimeInSeconds The duration of the borrowing in seconds. * @return collateralAmt The calculated collateral amount that is needed. */ function calculateCollateralAmtForLifetime( bytes32 borrowingKey, uint256 lifetimeInSeconds ) external view returns (uint256 collateralAmt) { // Retrieve the BorrowingInfo struct associated with the borrowing key BorrowingInfo memory borrowing = borrowingsInfo[borrowingKey]; // Check if the borrowed position is existing if (borrowing.borrowedAmount > 0) { // Get the current daily rate for the hold token uint256 currentDailyRate = _getHoldTokenInfo(borrowing.saleToken, borrowing.holdToken) .currentDailyRate; // Calculate the collateral amount per second uint256 everySecond = _everySecond(borrowing.borrowedAmount, currentDailyRate); // Calculate the total collateral amount for the borrowing lifetime collateralAmt = FullMath.mulDivRoundingUp( everySecond, lifetimeInSeconds, Constants.COLLATERAL_BALANCE_PRECISION ); // Ensure that the collateral amount is at least 1 if (collateralAmt == 0) collateralAmt = 1; } } /** * @notice This function is used to increase the daily rate collateral for a specific borrowing. * @param borrowingKey The unique identifier of the borrowing. * @param collateralAmt The amount of collateral to be added. * @param deadline The deadline timestamp after which the transaction is considered invalid. */ function increaseCollateralBalance( bytes32 borrowingKey, uint256 collateralAmt, uint256 deadline ) external nonReentrant checkDeadline(deadline) { BorrowingInfo storage borrowing = borrowingsInfo[borrowingKey]; // Ensure that the borrowed position exists and the borrower is the message sender (borrowing.borrowedAmount == 0 || borrowing.borrower != address(msg.sender)).revertError( ErrLib.ErrorCode.INVALID_BORROWING_KEY ); // Increase the daily rate collateral balance by the specified collateral amount borrowing.dailyRateCollateralBalance += collateralAmt * Constants.COLLATERAL_BALANCE_PRECISION; _pay(borrowing.holdToken, msg.sender, VAULT_ADDRESS, collateralAmt); emit IncreaseCollateralBalance(msg.sender, borrowingKey, collateralAmt); } /** * @notice Borrow function allows a user to borrow tokens by providing collateral and taking out loans. * The trader opens a long position by borrowing the liquidity of Uniswap V3 and extracting it into a pair of tokens, * one of which will be swapped into a desired(holdToken).The tokens will be kept in storage until the position is closed. * The margin is calculated on the basis that liquidity must be restored with any price movement. * The time the position is held is paid by the trader. * @dev Emits a Borrow event upon successful borrowing. * @param params The BorrowParams struct containing the necessary parameters for borrowing. * @param deadline The deadline timestamp after which the transaction is considered invalid. * * @return borrowedAmount The total amount of `params.holdToken` borrowed. * @return marginDeposit The required collateral deposit amount for initiating the loan. * @return liquidationBonus An additional amount added to the debt as a bonus in case of liquidation. * @return dailyRateCollateral The collateral deposit to hold the transaction for a day. */ function borrow( BorrowParams calldata params, uint256 deadline ) external nonReentrant checkDeadline(deadline) returns (uint256, uint256, uint256, uint256, uint256) { BorrowCache memory cache; BorrowingInfo storage borrowing; { // Update the token rate information and retrieve the dailyRate and TokenInfo for the holdTokenRateInfo TokenInfo storage holdTokenRateInfo; (cache.dailyRateCollateral, holdTokenRateInfo) = _updateHoldTokenRateInfo( params.saleToken, params.holdToken ); uint256 entranceFee = _checkEntranceFee(holdTokenRateInfo.entranceFeeBP); // Precalculating borrowing details and storing them in cache _precalculateBorrowing(cache, params, entranceFee); // Initializing borrowing variables and obtaining borrowing key borrowing = borrowingsInfo[cache.borrowingKey]; _initOrUpdateBorrowing( params.saleToken, params.holdToken, params.maxDailyRate, cache, borrowing, holdTokenRateInfo ); } uint256 marginDeposit; // positive slippage if (cache.holdTokenBalance > cache.borrowedAmount) { // Thus, we stimulate the platform to look for the best conditions for swapping on external aggregators. platformsFeesInfo[params.holdToken] += (cache.holdTokenBalance - cache.borrowedAmount) * Constants.COLLATERAL_BALANCE_PRECISION; } else { unchecked { marginDeposit = cache.borrowedAmount - cache.holdTokenBalance; } (marginDeposit > params.maxMarginDeposit).revertError( ErrLib.ErrorCode.TOO_BIG_MARGIN_DEPOSIT ); } // Adding borrowing key and loans information to storage _addKeysAndLoansInfo(cache.borrowingKey, params.loans); // Calculating liquidation bonus based on hold token, borrowed amount, and number of used loans uint256 liquidationBonus = getLiquidationBonus(params.holdToken, cache.borrowedAmount); uint256 amountToPay; unchecked { // Updating borrowing details borrowing.borrowedAmount += cache.borrowedAmount; borrowing.liquidationBonus += liquidationBonus; // Transfer the required tokens to the VAULT_ADDRESS for collateral and holdTokenBalance borrowing.dailyRateCollateralBalance += cache.dailyRateCollateral * Constants.COLLATERAL_BALANCE_PRECISION; amountToPay = marginDeposit + liquidationBonus + cache.dailyRateCollateral + cache.holdTokenEntranceFee; } _pay(params.holdToken, msg.sender, VAULT_ADDRESS, amountToPay); // Transferring holdTokenBalance to VAULT_ADDRESS _pay(params.holdToken, address(this), VAULT_ADDRESS, cache.holdTokenBalance); // Emit the Borrow event with the borrower, borrowing key, and borrowed amount emit Borrow( msg.sender, cache.borrowingKey, cache.borrowedAmount, marginDeposit, liquidationBonus, cache.dailyRateCollateral, cache.holdTokenEntranceFee ); return ( cache.borrowedAmount, marginDeposit, liquidationBonus, cache.dailyRateCollateral, cache.holdTokenEntranceFee ); } /** * @notice Allows lenders to harvest the fees accumulated from their loans. * @dev Retrieves and updates fee amounts for all loans associated with a borrowing position. * The function iterates through each loan, calculating and updating the amount of fees due. * * Requirements: * - The borrowingKey must correspond to an active and valid borrowing position. * - The collateral balance must be above zero or the current fees must be above the minimum required amount. * * @param borrowingKey The unique identifier for the specific borrowing position. * * @return harvestedAmt The total amount of fees harvested by the borrower. */ function harvest(bytes32 borrowingKey) external nonReentrant returns (uint256 harvestedAmt) { BorrowingInfo storage borrowing = borrowingsInfo[borrowingKey]; // Check if the borrowing key is valid _existenceCheck(borrowing.borrowedAmount); // Update token rate information and get holdTokenRateInfo storage reference (, TokenInfo storage holdTokenRateInfo) = _updateHoldTokenRateInfo( borrowing.saleToken, borrowing.holdToken ); return _harvest(borrowingKey, borrowing, holdTokenRateInfo); } /** * @notice Used for repaying loans, optionally with liquidation or emergency liquidity withdrawal. * The position is closed either by the trader or by the liquidator if the trader has not paid for holding the position * and the moment of liquidation has arrived.The positions borrowed from liquidation providers are restored from the held * token and the remainder is sent to the caller.In the event of liquidation, the liquidity provider * whose liquidity is present in the trader’s position can use the emergency mode and withdraw their liquidity.In this case, * he will receive hold tokens and liquidity will not be restored in the uniswap pool. * @param params The repayment parameters including * activation of the emergency liquidity restoration mode (available only to the lender) * internal swap pool fee, * external swap parameters, * borrowing key, * swap slippage allowance. * @param deadline The deadline by which the repayment must be made. * * @return saleTokenOut The amount of saleToken returned back to the user after repayment. * @return holdTokenOut The amount of holdToken returned back to the user after repayment or emergency withdrawal. */ function repay( RepayParams calldata params, uint256 deadline ) external nonReentrant checkDeadline(deadline) returns (uint256 saleTokenOut, uint256 holdTokenOut) { BorrowingInfo memory borrowing = borrowingsInfo[params.borrowingKey]; // Check if the borrowing key is valid _existenceCheck(borrowing.borrowedAmount); bool zeroForSaleToken = borrowing.saleToken < borrowing.holdToken; uint256 liquidationBonus = borrowing.liquidationBonus; int256 collateralBalance; uint256 currentFees; // Update token rate information and get holdTokenRateInfo storage reference (, TokenInfo storage holdTokenRateInfo) = _updateHoldTokenRateInfo( borrowing.saleToken, borrowing.holdToken ); bool underLiquidation; { // Calculate collateral balance and validate caller uint256 accLoanRatePerSeconds = holdTokenRateInfo.accLoanRatePerSeconds; (collateralBalance, currentFees) = _calculateCollateralBalance( borrowing.borrowedAmount, borrowing.accLoanRatePerSeconds, borrowing.dailyRateCollateralBalance, accLoanRatePerSeconds ); underLiquidation = collateralBalance < 0; (msg.sender != borrowing.borrower && !underLiquidation).revertError( ErrLib.ErrorCode.INVALID_CALLER ); // Calculate liquidation bonus and adjust fees owed if (collateralBalance > 0) { unchecked { liquidationBonus += uint256(collateralBalance) / Constants.COLLATERAL_BALANCE_PRECISION; } } else { currentFees = borrowing.dailyRateCollateralBalance; } } // Check if it's an emergency repayment if (params.isEmergency) { (!underLiquidation).revertError(ErrLib.ErrorCode.FORBIDDEN); ( uint256 removedAmt, uint256 feesAmt, bool completeRepayment ) = _calculateEmergencyLoanClosure( zeroForSaleToken, params.borrowingKey, currentFees, borrowing.borrowedAmount ); (removedAmt == 0).revertError(ErrLib.ErrorCode.LIQUIDITY_IS_ZERO); // Subtract the removed amount and fees from borrowedAmount and feesOwed borrowing.borrowedAmount -= removedAmt; borrowing.dailyRateCollateralBalance -= feesAmt; feesAmt = _pickUpPlatformFees(borrowing.holdToken, feesAmt) / Constants.COLLATERAL_BALANCE_PRECISION; // Deduct the removed amount from totalBorrowed unchecked { holdTokenRateInfo.totalBorrowed -= removedAmt; } // If loansInfoLength is 0, remove the borrowing key from storage and get the liquidation bonus if (completeRepayment) { LoanInfo[] memory empty; _removeKeysAndClearStorage(borrowing.borrower, params.borrowingKey, empty); feesAmt += liquidationBonus; } else { // make changes to the storage BorrowingInfo storage borrowingStorage = borrowingsInfo[params.borrowingKey]; borrowingStorage.dailyRateCollateralBalance = borrowing.dailyRateCollateralBalance; borrowingStorage.borrowedAmount = borrowing.borrowedAmount; } unchecked { holdTokenOut = removedAmt + feesAmt; } // Transfer removedAmt + feesAmt to msg.sender and emit EmergencyLoanClosure event Vault(VAULT_ADDRESS).transferToken(borrowing.holdToken, msg.sender, holdTokenOut); emit EmergencyLoanClosure(borrowing.borrower, msg.sender, params.borrowingKey); } else { // Calculate platform fees and adjust fees owed currentFees = _pickUpPlatformFees(borrowing.holdToken, currentFees); // Deduct borrowedAmount from totalBorrowed unchecked { holdTokenRateInfo.totalBorrowed -= borrowing.borrowedAmount; } // Transfer the borrowed amount and liquidation bonus from the VAULT to this contract Vault(VAULT_ADDRESS).transferToken( borrowing.holdToken, address(this), borrowing.borrowedAmount + liquidationBonus ); if (params.externalSwap.length != 0) { _callExternalSwap(borrowing.holdToken, params.externalSwap); } // Restore liquidity using the borrowed amount and pay a daily rate fee LoanInfo[] memory loans = loansInfo[params.borrowingKey]; _maxApproveIfNecessary(borrowing.holdToken, address(underlyingPositionManager)); _maxApproveIfNecessary(borrowing.saleToken, address(underlyingPositionManager)); _restoreLiquidity( RestoreLiquidityParams({ zeroForSaleToken: zeroForSaleToken, totalfeesOwed: currentFees, totalBorrowedAmount: borrowing.borrowedAmount, routes: params.routes, loans: loans }) ); // Remove borrowing key from related data structures _removeKeysAndClearStorage(borrowing.borrower, params.borrowingKey, loans); // Get the remaining balance of saleToken and holdToken (saleTokenOut, holdTokenOut) = _getPairBalance( borrowing.saleToken, borrowing.holdToken ); (holdTokenOut < params.minHoldTokenOut || saleTokenOut < params.minSaleTokenOut) .revertError(ErrLib.ErrorCode.PRICE_SLIPPAGE_CHECK); // Pay a profit to a msg.sender _pay(borrowing.holdToken, address(this), msg.sender, holdTokenOut); _pay(borrowing.saleToken, address(this), msg.sender, saleTokenOut); emit Repay(borrowing.borrower, msg.sender, params.borrowingKey); } } /// @notice Calculates the collateral balance, picks up platform fees, updates rates, and distributes the fees to creditors. /// @custom:throw "FORBIDDEN" When the calculated collateral balance is less than or equal to zero, indicating the caller is not allowed to initiate harvest. function _harvest( bytes32 borrowingKey, BorrowingInfo storage borrowing, TokenInfo storage holdTokenRateInfo ) private returns (uint256 harvestedAmt) { // Calculate collateral balance and validate caller (int256 collateralBalance, uint256 currentFees) = _calculateCollateralBalance( borrowing.borrowedAmount, borrowing.accLoanRatePerSeconds, borrowing.dailyRateCollateralBalance, holdTokenRateInfo.accLoanRatePerSeconds ); (collateralBalance <= 0).revertError(ErrLib.ErrorCode.FORBIDDEN); // Calculate platform fees and adjust fees owed unchecked { borrowing.dailyRateCollateralBalance -= currentFees; } uint256 feesOwed = _pickUpPlatformFees(borrowing.holdToken, currentFees); // Set the accumulated loan rate per second for the borrowing position borrowing.accLoanRatePerSeconds = holdTokenRateInfo.accLoanRatePerSeconds; uint256 borrowedAmount = borrowing.borrowedAmount; bool zeroForSaleToken = borrowing.saleToken < borrowing.holdToken; // Create a memory struct to store liquidity cache information. NftPositionCache memory cache; // Get the array of LoanInfo structs associated with the given borrowing key. LoanInfo[] memory loans = loansInfo[borrowingKey]; // Iterate through each loan in the loans array. for (uint256 i; i < loans.length; ) { LoanInfo memory loan = loans[i]; // Get the owner address of the loan's token ID using the underlyingPositionManager contract. address creditor = _getOwnerOf(loan.tokenId); // if the Pos-NFT has not been burned. if (creditor != address(0)) { // Update the liquidity cache based on the loan information. _upNftPositionCache(zeroForSaleToken, loan, cache); uint256 feesAmt = FullMath.mulDiv(feesOwed, cache.holdTokenDebt, borrowedAmount); // Calculate the fees amount based on the total fees owed and holdTokenDebt. unchecked { loansFeesInfo[creditor][cache.holdToken] += feesAmt; harvestedAmt += feesAmt; } } unchecked { ++i; } } emit Harvest(borrowingKey, harvestedAmt); } /** * @notice Calculates the amount to be repaid in an emergency situation. * @dev This function removes loans associated with a borrowing key owned by the `msg.sender`. * @param zeroForSaleToken A boolean value indicating whether the token for sale is the 0th token or not. * @param borrowingKey The identifier for the borrowing key. * @param totalfeesOwed The total fees owed. * @param totalBorrowedAmount The total borrowed amount. * @return removedAmt The amount of debt removed from the loan. * @return feesAmt The calculated fees amount. * @return completeRepayment indicates the complete closure of the debtor's position */ function _calculateEmergencyLoanClosure( bool zeroForSaleToken, bytes32 borrowingKey, uint256 totalfeesOwed, uint256 totalBorrowedAmount ) private returns (uint256 removedAmt, uint256 feesAmt, bool completeRepayment) { // Create a memory struct to store liquidity cache information. NftPositionCache memory cache; // Get the array of LoanInfo structs associated with the given borrowing key. LoanInfo[] storage loans = loansInfo[borrowingKey]; // Iterate through each loan in the loans array. for (uint256 i; i < loans.length; ) { LoanInfo memory loan = loans[i]; // Get the owner address of the loan's token ID using the underlyingPositionManager contract. address creditor = _getOwnerOf(loan.tokenId); // if the Pos-NFT has not been burned. if (creditor == msg.sender) { // If the owner matches the `msg.sender`, replace the current loan with the last loan in the loans array // and remove the last element. loans[i] = loans[loans.length - 1]; loans.pop(); // Remove the borrowing key from the tokenIdToBorrowingKeys mapping. tokenIdToBorrowingKeys[loan.tokenId].remove(borrowingKey); // Update the liquidity cache based on the loan information. _upNftPositionCache(zeroForSaleToken, loan, cache); // Add the holdTokenDebt value to the removedAmt. unchecked { removedAmt += cache.holdTokenDebt; // Calculate the fees amount based on the total fees owed and holdTokenDebt. feesAmt += FullMath.mulDiv( totalfeesOwed, cache.holdTokenDebt, totalBorrowedAmount ); } } else { // If the owner of the loan's token ID is not equal to the `msg.sender`, // the function increments the loop counter and moves on to the next loan. unchecked { ++i; } } } // Check if all loans have been removed, indicating complete repayment. completeRepayment = loans.length == 0; } /** * @dev This internal function is used to remove borrowing keys and clear related storage for a specific * borrower and borrowing key. * @param borrower The address of the borrower. * @param borrowingKey The borrowing key to be removed. * @param loans An array of LoanInfo structs representing the loans associated with the borrowing key. */ function _removeKeysAndClearStorage( address borrower, bytes32 borrowingKey, LoanInfo[] memory loans ) private { // Remove the borrowing key from the tokenIdToBorrowingKeys mapping for each loan in the loans array. for (uint256 i; i < loans.length; ) { tokenIdToBorrowingKeys[loans[i].tokenId].remove(borrowingKey); unchecked { ++i; } } // Remove the borrowing key from the userBorrowingKeys mapping for the borrower. userBorrowingKeys[borrower].remove(borrowingKey); // Delete the borrowing information and loans associated with the borrowing key from the borrowingsInfo // and loansInfo mappings. delete borrowingsInfo[borrowingKey]; delete loansInfo[borrowingKey]; } /** * @dev This internal function is used to add borrowing keys and loan information for a specific borrowing key. * @param borrowingKey The borrowing key to be added or updated. * @param sourceLoans An array of LoanInfo structs representing the loans to be associated with the borrowing key. */ function _addKeysAndLoansInfo(bytes32 borrowingKey, LoanInfo[] memory sourceLoans) private { // Get the storage reference to the loans array for the borrowing key LoanInfo[] storage loans = loansInfo[borrowingKey]; // Iterate through the sourceLoans array for (uint256 i; i < sourceLoans.length; ) { // Get the current loan from the sourceLoans array LoanInfo memory loan = sourceLoans[i]; // Get the storage reference to the tokenIdLoansKeys array for the loan's token ID if (tokenIdToBorrowingKeys[loan.tokenId].add(borrowingKey)) { // Push the current loan to the loans array loans.push(loan); } else { // If already exists, find the loan and update its liquidity for (uint256 j; j < loans.length; ) { if (loans[j].tokenId == loan.tokenId) { unchecked { loans[j].liquidity += loan.liquidity; } break; } unchecked { ++j; } } } unchecked { ++i; } } // Ensure that the number of loans does not exceed the maximum limit (loans.length > Constants.MAX_NUM_LOANS_PER_POSITION).revertError( ErrLib.ErrorCode.TOO_MANY_LOANS_PER_POSITION ); // Add the borrowing key to the userBorrowingKeys mapping for the borrower if it does not exist userBorrowingKeys[msg.sender].add(borrowingKey); } /** * @dev This internal function is used to precalculate borrowing parameters and update the cache. * @param cache The current state of the BorrowCache struct that needs to be updated. * @param params The BorrowParams struct containing the essential borrowing parameters. * @param entranceFee The fee amount which is applied when borrowing. */ function _precalculateBorrowing( BorrowCache memory cache, BorrowParams calldata params, uint256 entranceFee ) private { // Compute the borrowingKey using the msg.sender, saleToken, and holdToken cache.borrowingKey = Keys.computeBorrowingKey( msg.sender, params.saleToken, params.holdToken ); { bool zeroForSaleToken = params.saleToken < params.holdToken; // Create a storage reference for the hold token rate information // Extract liquidity and store the borrowed amount in the cache uint256 holdTokenPlatformFee; ( cache.borrowedAmount, cache.holdTokenEntranceFee, holdTokenPlatformFee ) = _extractLiquidity( zeroForSaleToken, params.saleToken, params.holdToken, entranceFee, platformFeesBP, params.loans ); // the empty loans[] disallowed (cache.borrowedAmount == 0).revertError(ErrLib.ErrorCode.LOANS_IS_EMPTY); // Increment the total borrowed amount for the hold token information unchecked { platformsFeesInfo[params.holdToken] += holdTokenPlatformFee; } } if (params.externalSwap.length != 0) { // Call the external swap function _callExternalSwap(params.saleToken, params.externalSwap); } uint256 saleTokenBalance; // Get the balance of the sale token and hold token in the pair (saleTokenBalance, cache.holdTokenBalance) = _getPairBalance( params.saleToken, params.holdToken ); // Check if the sale token balance is greater than 0 if (saleTokenBalance > 0) { // Call the internal v3SwapExactInput function and update the hold token balance in the cache cache.holdTokenBalance += _v3SwapExact( v3SwapExactParams({ isExactInput: true, fee: params.internalSwapPoolfee, tokenIn: params.saleToken, tokenOut: params.holdToken, amount: saleTokenBalance }) ); (_getBalance(params.saleToken) > 0).revertError(ErrLib.ErrorCode.TOO_LOW_LIQUIDITY); } // Ensure that the received holdToken balance meets the minimum required if (cache.holdTokenBalance < params.minHoldTokenOut) { revert TooLittleReceivedError(params.minHoldTokenOut, cache.holdTokenBalance); } } /** * @dev This internal function is used to initialize or update the borrowing process for a given saleToken and holdToken combination. * It computes the borrowingKey, retrieves the BorrowingInfo from borrowingsInfo mapping, * and updates the BorrowingInfo based on the current state of the borrowing. * @param saleToken The address of the token being sold. * @param holdToken The address of the token used as collateral. * @param maxDailyRate The maximum allowed daily rate for the borrowing. * @param cache A memory-struct holding temporary data to minimize the number of storage reads. * @param borrowing A reference to the updated BorrowingInfo struct from the `borrowingsInfo` * mapping, corresponding to the computed borrowing key. * @param holdTokenRateInfo A storage reference to the TokenInfo struct containing * interest rate information about the holdToken being used. */ function _initOrUpdateBorrowing( address saleToken, address holdToken, uint256 maxDailyRate, BorrowCache memory cache, BorrowingInfo storage borrowing, TokenInfo storage holdTokenRateInfo ) private { (cache.dailyRateCollateral > maxDailyRate).revertError(ErrLib.ErrorCode.TOO_BIG_DAILY_RATE); // Calculate the prepayment per day fees based on the borrowed amount and daily rate collateral cache.dailyRateCollateral = FullMath.mulDivRoundingUp( cache.borrowedAmount, cache.dailyRateCollateral, Constants.BP ); // update if (borrowing.borrowedAmount > 0) { // Ensure that the borrower of the existing borrowing position matches the msg.sender (borrowing.borrower != address(msg.sender)).revertError( ErrLib.ErrorCode.INVALID_BORROWING_KEY ); _harvest(cache.borrowingKey, borrowing, holdTokenRateInfo); } else { // Initialize the BorrowingInfo for the new position borrowing.borrower = msg.sender; borrowing.saleToken = saleToken; borrowing.holdToken = holdToken; // Set the accumulated loan rate per second for the borrowing position borrowing.accLoanRatePerSeconds = holdTokenRateInfo.accLoanRatePerSeconds; } holdTokenRateInfo.totalBorrowed += cache.borrowedAmount; (holdTokenRateInfo.totalBorrowed > type(uint160).max).revertError( ErrLib.ErrorCode.TOO_MUCH_TOTAL_BORROW ); } /** * @dev This internal function is used to pick up platform fees from the given fees amount. * It calculates the platform fees based on the fees and platformFeesBP (basis points) variables, * updates the platformsFeesInfo mapping with the platform fees for the holdToken, * and returns the remaining fees after deducting the platform fees. * @param holdToken The address of the hold token. * @param fees The total fees amount. * @return currentFees The remaining fees after deducting the platform fees. */ function _pickUpPlatformFees( address holdToken, uint256 fees ) private returns (uint256 currentFees) { uint256 platformFees = (fees * platformFeesBP) / Constants.BP; unchecked { platformsFeesInfo[holdToken] += platformFees; currentFees = fees - platformFees; } } /** * @dev This internal function is used to get information about a specific debt. * It retrieves the borrowing information from the borrowingsInfo mapping based on the borrowingKey, * calculates the current daily rate and hold token rate info using the _getHoldTokenInfo function, * calculates the collateral balance using the _calculateCollateralBalance function, * and calculates the estimated lifetime of the debt if the collateral balance is greater than zero. * @param borrowingKey The unique key associated with the debt. * @return borrowing The struct containing information about the debt. * @return collateralBalance The calculated collateral balance for the debt. * @return estimatedLifeTime The estimated number of seconds the debt will last based on the collateral balance. */ function _getDebtInfo( bytes32 borrowingKey ) private view returns ( BorrowingInfo memory borrowing, int256 collateralBalance, uint256 estimatedLifeTime ) { // Retrieve the borrowing information from the borrowingsInfo mapping based on the borrowingKey borrowing = borrowingsInfo[borrowingKey]; // Calculate the current daily rate and hold token rate info using the _getHoldTokenInfo function TokenInfo memory holdTokenRateInfo = _getHoldTokenInfo( borrowing.saleToken, borrowing.holdToken ); (collateralBalance, ) = _calculateCollateralBalance( borrowing.borrowedAmount, borrowing.accLoanRatePerSeconds, borrowing.dailyRateCollateralBalance, holdTokenRateInfo.accLoanRatePerSeconds ); // Calculate the estimated lifetime of the debt if the collateral balance is greater than zero if (collateralBalance > 0) { uint256 everySecond = _everySecond( borrowing.borrowedAmount, holdTokenRateInfo.currentDailyRate ); estimatedLifeTime = uint256(collateralBalance) / everySecond; if (estimatedLifeTime == 0) estimatedLifeTime = 1; } } function _everySecond( uint256 borrowedAmount, uint256 currentDailyRate ) private pure returns (uint256 everySecond) { unchecked { everySecond = FullMath.mulDivRoundingUp( borrowedAmount, currentDailyRate * Constants.COLLATERAL_BALANCE_PRECISION, 1 days * Constants.BP ); } } function _getFees( mapping(address => uint256) storage collection, address[] calldata tokens ) internal view returns (uint256[] memory fees) { fees = new uint256[](tokens.length); for (uint256 i; i < tokens.length; ) { address token = tokens[i]; uint256 amount = collection[token]; fees[i] = amount; unchecked { ++i; } } } /// @notice Retrieves the debt information for the specified borrowing keys. /// @param borrowingKeys The array of borrowing keys to retrieve the debt information for. /// @return extinfo An array of BorrowingInfoExt structs representing the borrowing information. function _getDebtsInfo( bytes32[] memory borrowingKeys ) private view returns (BorrowingInfoExt[] memory extinfo) { extinfo = new BorrowingInfoExt[](borrowingKeys.length); for (uint256 i; i < borrowingKeys.length; ) { bytes32 key = borrowingKeys[i]; extinfo[i].key = key; extinfo[i].loans = loansInfo[key]; ( extinfo[i].info, extinfo[i].collateralBalance, extinfo[i].estimatedLifeTime ) = _getDebtInfo(key); unchecked { ++i; } } } function _existenceCheck(uint256 borrowedAmount) private pure { (borrowedAmount == 0).revertError(ErrLib.ErrorCode.INVALID_BORROWING_KEY); } function _collect( mapping(address => uint256) storage collection, address recipient, address[] calldata tokens ) private returns (uint256[] memory amounts) { amounts = new uint256[](tokens.length); for (uint256 i; i < tokens.length; ) { address token = tokens[i]; uint256 amount; unchecked { amount = collection[token] / Constants.COLLATERAL_BALANCE_PRECISION; } if (amount > 0) { collection[token] = 0; amounts[i] = amount; Vault(VAULT_ADDRESS).transferToken(token, recipient, amount); } unchecked { ++i; } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby disabling any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @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 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; 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 require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // 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 v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 amount) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ```solidity * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
// SPDX-License-Identifier: SAL-1.0 pragma solidity 0.8.23; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { TransferHelper } from "../libraries/TransferHelper.sol"; import { IUniswapV3Pool } from "../interfaces/IUniswapV3Pool.sol"; import { IApproveSwapAndPay } from "../interfaces/abstract/IApproveSwapAndPay.sol"; import { SafeCast } from "../vendor0.8/uniswap/SafeCast.sol"; import "../libraries/ExternalCall.sol"; import "../libraries/ErrLib.sol"; abstract contract ApproveSwapAndPay is IApproveSwapAndPay { using SafeCast for uint256; using TransferHelper for address; using { ExternalCall._externalCall } for address; using { ErrLib.revertError } for bool; uint160 internal constant MIN_SQRT_RATIO_ADD_ONE = 4295128740; uint160 internal constant MAX_SQRT_RATIO_SUB_ONE = 1461446703485210103287273052203988822378723970341; address public immutable UNDERLYING_V3_FACTORY_ADDRESS; bytes32 public immutable UNDERLYING_V3_POOL_INIT_CODE_HASH; /// swapTarget => is allowed mapping(address => bool) internal whitelistedCall; error SwapSlippageCheckError(uint256 expectedOut, uint256 receivedOut); constructor( address _UNDERLYING_V3_FACTORY_ADDRESS, bytes32 _UNDERLYING_V3_POOL_INIT_CODE_HASH ) { UNDERLYING_V3_FACTORY_ADDRESS = _UNDERLYING_V3_FACTORY_ADDRESS; UNDERLYING_V3_POOL_INIT_CODE_HASH = _UNDERLYING_V3_POOL_INIT_CODE_HASH; } /** * @notice Checks if a swap call is whitelisted. * @dev Determines if a given `swapTarget` address and function `selector` are whitelisted for swaps. * @param swapTarget The address to check if it is a whitelisted destination for a swap call. * @return IsWhitelisted Returns `true` if the `swapTarget` address and `selector` combination is whitelisted, otherwise `false`. */ function swapIsWhitelisted(address swapTarget) external view returns (bool IsWhitelisted) { IsWhitelisted = whitelistedCall[swapTarget]; } /** * @dev This internal function attempts to approve a specific amount of tokens for a spender. * It performs a call to the `approve` function on the token contract using the provided parameters, * and returns a boolean indicating whether the approval was successful or not. * @param token The address of the token contract. * @param spender The address of the spender. * @param amount The amount of tokens to be approved. * @return A boolean indicating whether the approval was successful or not. */ function _tryApprove(address token, address spender, uint256 amount) private returns (bool) { (bool success, bytes memory data) = token.call( abi.encodeWithSelector(IERC20.approve.selector, spender, amount) ); return success && (data.length == 0 || abi.decode(data, (bool))); } /** * @dev This internal function ensures that the allowance for a spender is at least the specified amount. * If the current allowance is less than the specified amount, it attempts to approve the maximum possible value, * and if that fails, it retries with the maximum possible value minus one. If both attempts fail, * it reverts with an error indicating that the approval did not succeed. * @param token The address of the token contract. * @param spender The address of the spender. */ function _maxApproveIfNecessary(address token, address spender) internal { if (IERC20(token).allowance(address(this), spender) < type(uint128).max) { if (!_tryApprove(token, spender, type(uint256).max)) { if (!_tryApprove(token, spender, type(uint256).max - 1)) { require(_tryApprove(token, spender, 0)); if (!_tryApprove(token, spender, type(uint256).max)) { if (!_tryApprove(token, spender, type(uint256).max - 1)) { true.revertError(ErrLib.ErrorCode.ERC20_APPROVE_DID_NOT_SUCCEED); } } } } } } /** * @dev This internal view function retrieves the balance of the contract for a specific token. * It performs a staticcall to the `balanceOf` function on the token contract using the provided parameter, * and returns the balance as a uint256 value. * @param token The address of the token contract. * @return balance The balance of the contract for the specified token. */ function _getBalance(address token) internal view returns (uint256 balance) { balance = token.getBalance(); } /** * @dev Retrieves the balance of two tokens in the contract. * @param tokenA The address of the first token. * @param tokenB The address of the second token. * @return balanceA The balance of the first token in the contract. * @return balanceB The balance of the second token in the contract. */ function _getPairBalance( address tokenA, address tokenB ) internal view returns (uint256 balanceA, uint256 balanceB) { balanceA = tokenA.getBalance(); balanceB = tokenB.getBalance(); } /** * @dev Performs a series of external swap calls as defined by the `externalSwap` parameter. * It iterates through an array of `SwapParams`, executing each corresponding swap. * * Emits a revert with specific error code if: * - The swap target is not whitelisted for the specified function selector. * - The external swap call is unsuccessful. * * @param tokenIn The address of the input token that will be swapped. * @param externalSwap An array of `SwapParams` containing the targets, gas limits, * and data for each external swap call. */ function _callExternalSwap(address tokenIn, SwapParams[] calldata externalSwap) internal { for (uint256 i = 0; i < externalSwap.length; ) { (address swapTarget, uint256 maxGasForCall, bytes calldata swapData) = ( externalSwap[i].swapTarget, externalSwap[i].maxGasForCall, externalSwap[i].swapData ); (swapTarget == address(0)).revertError(ErrLib.ErrorCode.SWAP_TARGET_ADDRESS_IS_ZERO); // Verifying if the swap target is whitelisted for the specified function selector (!whitelistedCall[swapTarget]).revertError(ErrLib.ErrorCode.SWAP_TARGET_NOT_APPROVED); // Maximizing approval if necessary _maxApproveIfNecessary(tokenIn, swapTarget); // calling the external swap bool success = swapTarget._externalCall(swapData, maxGasForCall); (!success).revertError(ErrLib.ErrorCode.EXTERNAL_SWAP_ERROR); unchecked { ++i; } } } /** * @dev Transfers a specified amount of tokens from the `payer` to the `recipient`. * @param token The address of the token to be transferred. * @param payer The address from which the tokens will be transferred. * @param recipient The address that will receive the tokens. * @param value The amount of tokens to be transferred. * @notice If the specified `value` is greater than zero, this function will transfer the tokens either by calling `safeTransfer` * if the `payer` is equal to `address(this)`, or by calling `safeTransferFrom` otherwise. */ function _pay(address token, address payer, address recipient, uint256 value) internal { if (value > 0) { if (payer == address(this)) { token.safeTransfer(recipient, value); } else { token.safeTransferFrom(payer, recipient, value); } } } /** * @notice Performs a token swap on Uniswap V3 using either exact input or output amount. * @dev This internal function allows swapping tokens on Uniswap V3 with precise control over inputs or outputs. It asserts non-zero pool fees and validates the resultant amounts against minimum expectations. * @param params A `v3SwapExactParams` struct containing: * - tokenIn: Address of the token being swapped from. * - tokenOut: Address of the token being swapped to. * - amount: Exact amount of tokenIn or maximum expected amount of tokenOut. * - fee: Pool fee used for the swap. * - isExactInput: Set to true if `amount` is the amount of tokenIn, false if it's the maximum amount of tokenOut. * @return amount The actual amount of tokens received from the swap. Depending on `isExactInput`, this is either the amount of tokenOut or tokenIn. */ function _v3SwapExact(v3SwapExactParams memory params) internal returns (uint256 amount) { // fee must be non-zero (params.fee == 0).revertError(ErrLib.ErrorCode.INTERNAL_SWAP_POOL_FEE_CANNOT_BE_ZERO); // Determine if tokenIn has a 0th token bool zeroForTokenIn = params.tokenIn < params.tokenOut; // Compute the address of the Uniswap V3 pool based on tokenIn, tokenOut, and fee // Call the swap function on the Uniswap V3 pool contract (int256 amount0Delta, int256 amount1Delta) = IUniswapV3Pool( computePoolAddress(params.tokenIn, params.tokenOut, params.fee) ).swap( address(this), //recipient zeroForTokenIn, params.isExactInput ? params.amount.toInt256() : -params.amount.toInt256(), zeroForTokenIn ? MIN_SQRT_RATIO_ADD_ONE : MAX_SQRT_RATIO_SUB_ONE, abi.encode(params.fee, params.tokenIn, params.tokenOut) ); if (params.isExactInput) { // Calculate the actual amount of output tokens received unchecked { amount = uint256(-(zeroForTokenIn ? amount1Delta : amount0Delta)); } } else { uint256 amountOutReceived; (amount, amountOutReceived) = zeroForTokenIn ? (uint256(amount0Delta), uint256(-amount1Delta)) : (uint256(amount1Delta), uint256(-amount0Delta)); (amountOutReceived < params.amount).revertError( ErrLib.ErrorCode.INTERNAL_SWAP_TOO_SMALL_AMOUNT_OUT ); } } /** * @dev Callback function invoked by Uniswap V3 swap. * * This function is called when a swap is executed on a Uniswap V3 pool. It performs the necessary validations * and payment processing. * * Requirements: * - The swap must not entirely fall within 0-liquidity regions, as it is not supported. * - The caller must be the expected Uniswap V3 pool contract. * * @param amount0Delta The change in token0 balance resulting from the swap. * @param amount1Delta The change in token1 balance resulting from the swap. * @param data Additional data required for processing the swap, encoded as `(uint24, address, address)`. */ function uniswapV3SwapCallback( int256 amount0Delta, int256 amount1Delta, bytes calldata data ) external { // swaps entirely within 0-liquidity regions are not supported (amount0Delta <= 0 && amount1Delta <= 0).revertError(ErrLib.ErrorCode.INTERNAL_SWAP_ERROR); (uint24 fee, address tokenIn, address tokenOut) = abi.decode( data, (uint24, address, address) ); (computePoolAddress(tokenIn, tokenOut, fee) != msg.sender).revertError( ErrLib.ErrorCode.INVALID_CALLER ); uint256 amountToPay = amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta); _pay(tokenIn, address(this), msg.sender, amountToPay); } /** * @dev Computes the address of a Uniswap V3 pool based on the provided parameters. * * This function calculates the address of a Uniswap V3 pool contract using the token addresses and fee. * It follows the same logic as Uniswap's pool initialization process. * * @param tokenA The address of one of the tokens in the pair. * @param tokenB The address of the other token in the pair. * @param fee The fee level of the pool. * @return pool The computed address of the Uniswap V3 pool. */ function computePoolAddress( address tokenA, address tokenB, uint24 fee ) public view returns (address pool) { if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); pool = address( uint160( uint256( keccak256( abi.encodePacked( hex"ff", UNDERLYING_V3_FACTORY_ADDRESS, keccak256(abi.encode(tokenA, tokenB, fee)), UNDERLYING_V3_POOL_INIT_CODE_HASH ) ) ) ) ); } }
// SPDX-License-Identifier: SAL-1.0 pragma solidity 0.8.23; import "../vendor0.8/uniswap/FullMath.sol"; import "../libraries/Keys.sol"; import { Constants } from "../libraries/Constants.sol"; import "../interfaces/abstract/IDailyRateAndCollateral.sol"; abstract contract DailyRateAndCollateral is IDailyRateAndCollateral { /// pairKey => TokenInfo mapping(bytes32 => TokenInfo) internal holdTokenInfo; /** * @notice Adjusts the entrance fee basis points according to predefined rules. * @dev This function normalizes the entrance fee basis points (BP). If the entrance fee is zero, it defaults to * `Constants.DEFAULT_ENTRANCE_FEE_BPS`. To disable entrance fees completely, the entrance fee BP should be set * to `Constants.MAX_ENTRANCE_FEE_BPS + 1`, which will reset the fee to zero. This function should only be used internally. * @param entranceFeeBP The initial entrance fee in basis points proposed for a financial operation. * @return The normalized entrance fee in basis points after applying the adjustment rules. */ function _checkEntranceFee(uint256 entranceFeeBP) internal pure returns (uint256) { if (entranceFeeBP == 0) { entranceFeeBP = Constants.DEFAULT_ENTRANCE_FEE_BPS; } else if (entranceFeeBP == Constants.MAX_ENTRANCE_FEE_BPS + 1) { // To disable entry fees, set it to MAX_ENTRANCE_FEE_BPS + 1 entranceFeeBP = 0; } return entranceFeeBP; } /** * @notice This internal view function retrieves the current daily rate for the hold token specified by `holdToken` * in relation to the sale token specified by `saleToken`. It also returns detailed information about the hold token rate stored * in the `holdTokenInfo` mapping. If the rate is not set, it defaults to `Constants.DEFAULT_DAILY_RATE`. If there are any existing * borrowings for the hold token, the accumulated loan rate per second is updated based on the time difference since the last update and the * current daily rate. The latest update timestamp is also recorded for future calculations. * @param saleToken The address of the sale token in the pair. * @param holdToken The address of the hold token in the pair. * @return holdTokenRateInfo The struct containing information about the hold token rate. */ function _getHoldTokenInfo( address saleToken, address holdToken ) internal view returns (TokenInfo memory) { (, TokenInfo memory holdTokenRateInfo) = _getHTInfo(saleToken, holdToken); holdTokenRateInfo.entranceFeeBP = _checkEntranceFee(holdTokenRateInfo.entranceFeeBP); return holdTokenRateInfo; } /** * @notice Updates the hold token rate information for a given pair of sale and hold tokens * @dev This internal function updates the `accLoanRatePerSeconds` and `latestUpTimestamp` in the `holdTokenInfo` mapping. * It also returns the latest `currentDailyRate` and the updated `holdTokenRateInfo` storage reference. * @param saleToken The address of the sale token in the pair * @param holdToken The address of the hold token in the pair * @return currentDailyRate The current daily rate for the hold token after the update * @return holdTokenRateInfo A storage reference to the hold token's rate info in the `holdTokenInfo` mapping */ function _updateHoldTokenRateInfo( address saleToken, address holdToken ) internal returns (uint256, TokenInfo storage) { (bytes32 key, TokenInfo memory info) = _getHTInfo(saleToken, holdToken); TokenInfo storage holdTokenRateInfo = holdTokenInfo[key]; holdTokenRateInfo.accLoanRatePerSeconds = info.accLoanRatePerSeconds; holdTokenRateInfo.latestUpTimestamp = info.latestUpTimestamp; return (info.currentDailyRate, holdTokenRateInfo); } /** * @notice Calculates the collateral balance and current fees for a borrowing operation. * @dev If there is a borrowed amount, this function computes the accrued fees since the time of borrowing. It uses full precision math * for fee calculations, rounding up the result. The collateral balance is then updated by subtracting the fees from the initial * daily rate collateral value. * @param borrowedAmount The principal amount that was borrowed. * @param borrowingAccLoanRatePerShare The accumulated loan rate per share at the time when the amount was borrowed. * @param borrowingDailyRateCollateral The total collateral balance associated with the daily rate at the time of borrowing. * @param accLoanRatePerSeconds The latest available accumulated loan rate per second. * @return collateralBalance The updated collateral balance after accounting for the accrued fees. * @return currentFees The total fees accrued since the time of borrowing. */ function _calculateCollateralBalance( uint256 borrowedAmount, uint256 borrowingAccLoanRatePerShare, uint256 borrowingDailyRateCollateral, uint256 accLoanRatePerSeconds ) internal pure returns (int256 collateralBalance, uint256 currentFees) { if (borrowedAmount > 0) { currentFees = FullMath.mulDivRoundingUp( borrowedAmount, accLoanRatePerSeconds - borrowingAccLoanRatePerShare, Constants.BP ); collateralBalance = int256(borrowingDailyRateCollateral) - int256(currentFees); } } /** * @notice Retrieves the hash key and TokenInfo information for a holder token associated with a sale token. * @dev This function computes the unique pair key using `Keys.computePairKey` for the provided `saleToken` * and `holdToken` and fetches the corresponding `TokenInfo`. If the current daily rate for the hold token * is zero, it defaults to `Constants.DEFAULT_DAILY_RATE`. It then calculates and updates the time weighted rate * if there has been any borrowing against the hold token. Lastly, it updates the `latestUpTimestamp` to the current * block timestamp. * @param saleToken The address of the sale token that is being used in association with a hold token. * @param holdToken The address of the hold token whose information is being retrieved. * @return key A bytes32 type representing the unique pair key for the sale token and hold token. * @return holdTokenRateInfo A `TokenInfo` struct containing rate information for the hold token. */ function _getHTInfo( address saleToken, address holdToken ) private view returns (bytes32 key, TokenInfo memory holdTokenRateInfo) { key = Keys.computePairKey(saleToken, holdToken); holdTokenRateInfo = holdTokenInfo[key]; if (holdTokenRateInfo.currentDailyRate == 0) { holdTokenRateInfo.currentDailyRate = Constants.DEFAULT_DAILY_RATE; } if (holdTokenRateInfo.totalBorrowed > 0) { unchecked { uint256 timeWeightedRate = (uint32(block.timestamp) - holdTokenRateInfo.latestUpTimestamp) * holdTokenRateInfo.currentDailyRate; holdTokenRateInfo.accLoanRatePerSeconds += (timeWeightedRate * Constants.COLLATERAL_BALANCE_PRECISION) / 1 days; } } holdTokenRateInfo.latestUpTimestamp = uint32(block.timestamp); } }
// SPDX-License-Identifier: SAL-1.0 pragma solidity 0.8.23; import "../vendor0.8/uniswap/LiquidityAmounts.sol"; import "../vendor0.8/uniswap/TickMath.sol"; import "./ApproveSwapAndPay.sol"; import "../Vault.sol"; import { Constants } from "../libraries/Constants.sol"; import { ErrLib } from "../libraries/ErrLib.sol"; import { AmountsLiquidity } from "../libraries/AmountsLiquidity.sol"; import "../interfaces/abstract/ILiquidityManager.sol"; import "../interfaces/IWagmiLeverageFlashCallback.sol"; import "../interfaces/IFlashLoanAggregator.sol"; abstract contract LiquidityManager is ApproveSwapAndPay, ILiquidityManager, IWagmiLeverageFlashCallback { using { ErrLib.revertError } for bool; /** * @notice The address of the vault contract. */ address public immutable VAULT_ADDRESS; address public flashLoanAggregatorAddress; /** * @notice The Nonfungible Position Manager contract. */ INonfungiblePositionManager public immutable underlyingPositionManager; /** * @notice The Quoter contract. */ address public lightQuoterV3Address; /// msg.sender => token => FeesAmt mapping(address => mapping(address => uint256)) internal loansFeesInfo; /// token => FeesAmt mapping(address => uint256) internal platformsFeesInfo; /** * @dev Contract constructor. * @param _underlyingPositionManagerAddress Address of the underlying position manager contract. * @param _lightQuoterV3 Address of the LightQuoterV3 contract. * @param _underlyingV3Factory Address of the underlying V3 factory contract. * @param _underlyingV3PoolInitCodeHash The init code hash of the underlying V3 pool. */ constructor( address _underlyingPositionManagerAddress, address _flashLoanAggregator, address _lightQuoterV3, address _underlyingV3Factory, bytes32 _underlyingV3PoolInitCodeHash ) ApproveSwapAndPay(_underlyingV3Factory, _underlyingV3PoolInitCodeHash) { // Assign the underlying position manager contract address underlyingPositionManager = INonfungiblePositionManager(_underlyingPositionManagerAddress); // Assign the quoter contract address lightQuoterV3Address = _lightQuoterV3; flashLoanAggregatorAddress = _flashLoanAggregator; // Generate a unique salt for the new Vault contract bytes32 salt = keccak256(abi.encode(block.timestamp, address(this))); // Deploy a new Vault contract using the generated salt and assign its address to VAULT_ADDRESS VAULT_ADDRESS = address(new Vault{ salt: salt }(Constants.FLASH_LOAN_DEFAULT_VAULT_FEE)); } modifier onlyTrustedCallers() { (msg.sender != flashLoanAggregatorAddress && msg.sender != VAULT_ADDRESS).revertError( ErrLib.ErrorCode.INVALID_CALLER ); _; } error InvalidLiquidityAmount(uint256 tokenId, uint128 max, uint128 min, uint128 liquidity); error InvalidTokens(uint256 tokenId); error NotApproved(uint256 tokenId); error InvalidRestoredLiquidity( uint256 tokenId, uint128 borrowedLiquidity, uint128 restoredLiquidity ); function _chargePlatformFees(address holdToken, uint256 feesAmt) internal { unchecked { platformsFeesInfo[holdToken] += feesAmt * Constants.COLLATERAL_BALANCE_PRECISION; } } /** * @dev Calculates the borrowed amount from a pool's single side position, rounding up if necessary. * @param zeroForSaleToken A boolean value indicating whether the token for sale is the 0th token or not. * @param tickLower The lower tick value of the position range. * @param tickUpper The upper tick value of the position range. * @param liquidity The liquidity of the position. * @return borrowedAmount The calculated borrowed amount. */ function _getSingleSideRoundUpBorrowedAmount( bool zeroForSaleToken, uint24 feeTiers, int24 tickLower, int24 tickUpper, uint128 liquidity ) private pure returns (uint256 borrowedAmount) { borrowedAmount = ( zeroForSaleToken ? AmountsLiquidity.getAmount1RoundingUpForLiquidity( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ) : AmountsLiquidity.getAmount0RoundingUpForLiquidity( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity ) ); // Apply the fee tier to the borrowed amount feeTiers += Constants.FLASH_LOAN_FEE_COMPENSATION; borrowedAmount += FullMath.mulDivRoundingUp(borrowedAmount, feeTiers, 1e6 - feeTiers); } /** * @dev Calculates the minimum liquidity amount for a given tick range. * @param tickLower The lower tick of the range. * @param tickUpper The upper tick of the range. * @return minLiquidity The minimum liquidity amount. */ function _getMinLiquidityAmt( int24 tickLower, int24 tickUpper ) internal pure returns (uint128 minLiquidity) { uint128 liquidity0 = LiquidityAmounts.getLiquidityForAmount0( TickMath.getSqrtRatioAtTick(tickUpper - 1), TickMath.getSqrtRatioAtTick(tickUpper), Constants.MINIMUM_EXTRACTED_AMOUNT ); uint128 liquidity1 = LiquidityAmounts.getLiquidityForAmount1( TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickLower + 1), Constants.MINIMUM_EXTRACTED_AMOUNT ); minLiquidity = liquidity0 > liquidity1 ? liquidity0 : liquidity1; } /** * @notice This function extracts liquidity from provided loans and calculates the total borrowed amount. * @dev Iterates through an array of LoanInfo structs, validates loan parameters, and accumulates borrowed amounts. * @param zeroForSaleToken A boolean indicating whether the token for sale is the 0th token in the pair. * @param saleToken The address of the token being sold in the trading pair. * @param holdToken The address of the token being held in the trading pair. * @param loans An array of LoanInfo struct instances, each representing a loan from which to extract liquidity. * @return borrowedAmount The total amount of the holdToken that has been borrowed across all provided loans. */ function _extractLiquidity( bool zeroForSaleToken, address saleToken, address holdToken, uint256 entranceFeeBps, uint256 platformFeesBPs, LoanInfo[] memory loans ) internal returns ( uint256 borrowedAmount, uint256 holdTokenEntranceFee, uint256 holdTokenPlatformFees ) { NftPositionCache memory cache; for (uint256 i; i < loans.length; ) { LoanInfo memory loan = loans[i]; // Extract position-related details _upNftPositionCache(zeroForSaleToken, loan, cache); // Check operator approval if (cache.operator != address(this)) { revert NotApproved(loan.tokenId); } address creditor = _getOwnerOf(loan.tokenId); // Check token validity if ( cache.saleToken != saleToken || cache.holdToken != holdToken || creditor == address(0) ) { revert InvalidTokens(loan.tokenId); } // Check borrowed liquidity validity uint128 minLiquidityAmt = _getMinLiquidityAmt(cache.tickLower, cache.tickUpper); if (loan.liquidity > cache.liquidity || loan.liquidity < minLiquidityAmt) { revert InvalidLiquidityAmount( loan.tokenId, cache.liquidity, minLiquidityAmt, loan.liquidity ); } if (entranceFeeBps > 0) { uint256 entranceFeeAmt = FullMath.mulDivRoundingUp( cache.holdTokenDebt, entranceFeeBps, Constants.BP ); unchecked { holdTokenEntranceFee += entranceFeeAmt; entranceFeeAmt *= Constants.COLLATERAL_BALANCE_PRECISION; uint256 platformFeesAmt = (entranceFeeAmt * platformFeesBPs) / Constants.BP; holdTokenPlatformFees += platformFeesAmt; loansFeesInfo[creditor][cache.holdToken] += (entranceFeeAmt - platformFeesAmt); } } // Calculate borrowed amount unchecked { borrowedAmount += cache.holdTokenDebt; } // Decrease liquidity and move to the next loan _decreaseLiquidity(loan.tokenId, loan.liquidity); unchecked { ++i; } } } /** * @notice Calculates the amounts to be swapped using a quoter contract. * @dev This function utilizes a static call to the quoter contract to determine the swap amounts without affecting the blockchain state. * @param zeroForIn A boolean to indicate if we're swapping the token at index 0 in the pool. * @param pool The address of the Uniswap V3 pool involved in the swap. * @param liquidity The amount of liquidity to provide to the pool. * @param tickLower The lower tick range for the position. * @param tickUpper The upper tick range for the position. * @param saleTokenBalance The balance of the token intended to sell. * @param holdTokenBalance The balance of the token not being sold (held). * @param amounts A struct to receive the calculated amounts of tokens involved in the swap. * @return amountIn The computed amount of input tokens that needs to be swapped. */ function _calculateAmountsToSwap( bool zeroForIn, address pool, uint128 liquidity, int24 tickLower, int24 tickUpper, uint256 saleTokenBalance, uint256 holdTokenBalance, Amounts memory amounts ) private view returns (uint256 amountIn) { (, bytes memory data) = lightQuoterV3Address.staticcall( abi.encodeWithSelector( ILightQuoterV3.calculateExactZapIn.selector, ILightQuoterV3.CalculateExactZapInParams({ swapPool: pool, zeroForIn: zeroForIn, tickLower: tickLower, tickUpper: tickUpper, liquidityExactAmount: liquidity, tokenInBalance: holdTokenBalance, tokenOutBalance: saleTokenBalance }) ) ); (amountIn, amounts.amount0, amounts.amount1) = abi.decode( data, (uint256, uint256, uint256) ); } /** * @notice Internal function to restore liquidity using parameters and loans provided. * @dev Iteratively processes each loan from the list given in params, restores liquidity as per defined logic, * and handles token swaps if necessary. Also updates fees information for loan creditors. * @param params Struct of type `RestoreLiquidityParams` containing all parameters required for the restoration. */ function _restoreLiquidity(RestoreLiquidityParams memory params) internal { NftPositionCache memory cache; Amounts memory amounts; for (uint256 i; i < params.loans.length; ) { // Update the cache for the current loan LoanInfo memory loan = params.loans[i]; // Get the owner of the Nonfungible Position Manager token by its tokenId address creditor = _getOwnerOf(loan.tokenId); // Check that the token is not burned if (creditor != address(0)) { _upNftPositionCache(params.zeroForSaleToken, loan, cache); (uint256 saleTokenBalance, uint256 holdTokenBalance) = _getPairBalance( cache.saleToken, cache.holdToken ); { uint256 liquidityOwnerReward = FullMath.mulDiv( params.totalfeesOwed, cache.holdTokenDebt, params.totalBorrowedAmount ); unchecked { loansFeesInfo[creditor][cache.holdToken] += liquidityOwnerReward; } // Calculate the square root price using `_getCurrentSqrtPriceX96` function uint160 sqrtPriceX96 = _getCurrentSqrtPriceX96( cache.saleToken, cache.holdToken, cache.fee ); (amounts.amount0, amounts.amount1) = AmountsLiquidity .getAmountsRoundingUpForLiquidity( sqrtPriceX96, TickMath.getSqrtRatioAtTick(cache.tickLower), TickMath.getSqrtRatioAtTick(cache.tickUpper), loan.liquidity ); } uint256 saleTokenAmt = params.zeroForSaleToken ? amounts.amount0 : amounts.amount1; // If balance is low, perform a flash loan to meet the liquidity requirements if (saleTokenBalance < saleTokenAmt) { unchecked { saleTokenAmt -= saleTokenBalance; } Vault(VAULT_ADDRESS).vaultFlash( cache.saleToken, saleTokenAmt, abi.encode( CallbackData({ zeroForSaleToken: params.zeroForSaleToken, fee: cache.fee, tickLower: cache.tickLower, tickUpper: cache.tickUpper, saleToken: cache.saleToken, holdToken: cache.holdToken, holdTokenDebt: cache.holdTokenDebt > holdTokenBalance ? holdTokenBalance : cache.holdTokenDebt, vaultBodyDebt: uint256(0), vaultFeeDebt: uint256(0), amounts: amounts, loan: loan, routes: params.routes }) ) ); } else { // Increase liquidity directly without using a flash loan _increaseLiquidity(loan, amounts.amount0, amounts.amount1); } } unchecked { ++i; } } } /** * @dev Executes a flash loan callback function for the Wagmi Leverage protocol. * It performs various operations based on the received flash loan data. * If the sale token balance is insufficient, it initiates a flash loan to borrow the required amount. * Otherwise, it increases liquidity and performs token swaps. * Finally, it charges platform fees and makes payments to the vault and flash loan aggregator contracts. * @param bodyAmt The amount of the flash loan body token. * @param feeAmt The amount of the flash loan fee token. * @param data The encoded flash loan callback data. */ function wagmiLeverageFlashCallback( uint256 bodyAmt, uint256 feeAmt, bytes calldata data ) external onlyTrustedCallers { // Decoding the callback data to extract loan details and swap information CallbackData memory decodedData = abi.decode(data, (CallbackData)); // Retrieve the current balance of the sale token uint256 saleTokenBalance = _getBalance(decodedData.saleToken); // Calculate the sale token amount needed based on the encoded data uint256 saleTokenAmt = decodedData.zeroForSaleToken ? decodedData.amounts.amount0 : decodedData.amounts.amount1; // If the token balance is less than required, try to get more tokens through a flash loan or swap if (saleTokenBalance < saleTokenAmt) { // When there are no more routes left or the sender is the flash loan aggregator if ( decodedData.routes.flashLoanParams.length == 0 || msg.sender == flashLoanAggregatorAddress ) { // Compute the pool address using provided tokens and fee address pool = computePoolAddress( decodedData.holdToken, decodedData.saleToken, decodedData.fee ); // Calculate the amount needed for swapping hold tokens to sale tokens uint256 holdTokenAmountIn = _calculateAmountsToSwap( !decodedData.zeroForSaleToken, pool, decodedData.loan.liquidity, decodedData.tickLower, decodedData.tickUpper, saleTokenBalance, decodedData.holdTokenDebt, decodedData.amounts ); // Perform the actual Uniswap V3 swap saleTokenBalance += _v3SwapExact( v3SwapExactParams({ isExactInput: true, fee: decodedData.fee, tokenIn: decodedData.holdToken, tokenOut: decodedData.saleToken, amount: holdTokenAmountIn }) ); } else { unchecked { saleTokenAmt -= saleTokenBalance; } // Initiate another flash loan if additional funds are required IFlashLoanAggregator(flashLoanAggregatorAddress).flashLoan( saleTokenAmt, abi.encode( CallbackData({ zeroForSaleToken: decodedData.zeroForSaleToken, fee: decodedData.fee, tickLower: decodedData.tickLower, tickUpper: decodedData.tickUpper, saleToken: decodedData.saleToken, holdToken: decodedData.holdToken, holdTokenDebt: decodedData.holdTokenDebt, vaultBodyDebt: bodyAmt, vaultFeeDebt: feeAmt, amounts: decodedData.amounts, loan: decodedData.loan, routes: decodedData.routes }) ) ); return; // Exit the function to wait for the new flash loan callback } } // Add liquidity to the Uniswap position after obtaining the required tokens _increaseLiquidity( decodedData.loan, decodedData.amounts.amount0, decodedData.amounts.amount1 ); // Calculate the total amount to pay back for the flash loan(s) uint256 amountToPay = bodyAmt + feeAmt + decodedData.vaultBodyDebt + decodedData.vaultFeeDebt; if (amountToPay > 0) { // Swap tokens to repay the flash loan uint256 holdTokenAmtIn = _v3SwapExact( v3SwapExactParams({ isExactInput: false, fee: decodedData.fee, tokenIn: decodedData.holdToken, tokenOut: decodedData.saleToken, amount: amountToPay }) ); decodedData.holdTokenDebt -= decodedData.zeroForSaleToken ? decodedData.amounts.amount1 : decodedData.amounts.amount0; // Check for strict route adherence, revert the transaction if conditions are not met (decodedData.routes.strict && holdTokenAmtIn > decodedData.holdTokenDebt).revertError( ErrLib.ErrorCode.SWAP_AFTER_FLASH_LOAN_FAILED ); // Deduct platform fees and transfer owed amounts to the vault and/or the flash loan aggregator if (msg.sender == flashLoanAggregatorAddress) { _chargePlatformFees(decodedData.saleToken, decodedData.vaultFeeDebt); _pay( decodedData.saleToken, address(this), VAULT_ADDRESS, decodedData.vaultBodyDebt + decodedData.vaultFeeDebt ); _pay( decodedData.saleToken, address(this), flashLoanAggregatorAddress, bodyAmt + feeAmt ); } else { // Charge only the standard flash loan fee and pay the vault _chargePlatformFees(decodedData.saleToken, feeAmt); _pay(decodedData.saleToken, address(this), VAULT_ADDRESS, bodyAmt + feeAmt); } } } /** * @dev Retrieves the owner of a token without causing a revert if token not exist. * @param tokenId The identifier of the token. * @return tokenOwner The address of the token owner. */ function _getOwnerOf(uint256 tokenId) internal view returns (address tokenOwner) { bytes memory callData = abi.encodeWithSelector( underlyingPositionManager.ownerOf.selector, tokenId ); (bool success, bytes memory data) = address(underlyingPositionManager).staticcall(callData); if (success && data.length >= 32) { tokenOwner = abi.decode(data, (address)); } } /** * @dev Retrieves the current square root price in X96 representation. * @param tokenA The address of token A. * @param tokenB The address of token B. * @param fee The fee associated with the Uniswap V3 pool. * @return sqrtPriceX96 The current square root price in X96 representation. */ function _getCurrentSqrtPriceX96( address tokenA, address tokenB, uint24 fee ) private view returns (uint160 sqrtPriceX96) { address poolAddress = computePoolAddress(tokenA, tokenB, fee); (sqrtPriceX96, , , , , , ) = IUniswapV3Pool(poolAddress).slot0(); } /** * @dev Decreases the liquidity of a position by removing tokens. * @param tokenId The ID of the position token. * @param liquidity The amount of liquidity to be removed. */ function _decreaseLiquidity(uint256 tokenId, uint128 liquidity) private { // Call the decreaseLiquidity function of underlyingPositionManager contract // with DecreaseLiquidityParams struct as argument (uint256 amount0, uint256 amount1) = underlyingPositionManager.decreaseLiquidity( INonfungiblePositionManager.DecreaseLiquidityParams({ tokenId: tokenId, liquidity: liquidity, amount0Min: 0, amount1Min: 0, deadline: block.timestamp }) ); // Call the collect function of underlyingPositionManager contract // with CollectParams struct as argument (amount0, amount1) = underlyingPositionManager.collect( INonfungiblePositionManager.CollectParams({ tokenId: tokenId, recipient: address(this), amount0Max: uint128(amount0), amount1Max: uint128(amount1) }) ); } /** * @dev Increases the liquidity of a position by providing additional tokens. * @param loan An instance of LoanInfo memory struct containing loan details. * @param amount0 The amount of token0 to be added to the liquidity. * @param amount1 The amount of token1 to be added to the liquidity. */ function _increaseLiquidity(LoanInfo memory loan, uint256 amount0, uint256 amount1) private { // Call the increaseLiquidity function of underlyingPositionManager contract // with IncreaseLiquidityParams struct as argument (uint128 restoredLiquidity, , ) = underlyingPositionManager.increaseLiquidity( INonfungiblePositionManager.IncreaseLiquidityParams({ tokenId: loan.tokenId, amount0Desired: amount0, amount1Desired: amount1, amount0Min: 0, amount1Min: 0, deadline: block.timestamp }) ); // Check if the restored liquidity is less than the loan liquidity amount // If true, revert with InvalidRestoredLiquidity exception if (restoredLiquidity < loan.liquidity) { revert InvalidRestoredLiquidity(loan.tokenId, loan.liquidity, restoredLiquidity); } } /** * @dev Updates the NftPositionCache struct with data from the underlyingPositionManager contract. * @param zeroForSaleToken A boolean value indicating whether the token for sale is the 0th token or not. * @param loan The LoanInfo struct containing loan details. * @param cache The NftPositionCache struct to be updated. */ function _upNftPositionCache( bool zeroForSaleToken, LoanInfo memory loan, NftPositionCache memory cache ) internal view { // Get the positions data from `PositionManager` and store it in the cache variables ( , cache.operator, cache.saleToken, cache.holdToken, cache.fee, cache.tickLower, cache.tickUpper, cache.liquidity, , , , ) = underlyingPositionManager.positions(loan.tokenId); // Swap saleToken and holdToken if zeroForSaleToken is false if (!zeroForSaleToken) { (cache.saleToken, cache.holdToken) = (cache.holdToken, cache.saleToken); } // Calculate the holdTokenDebt using cache.holdTokenDebt = _getSingleSideRoundUpBorrowedAmount( zeroForSaleToken, cache.fee, cache.tickLower, cache.tickUpper, loan.liquidity ); } }
// SPDX-License-Identifier: SAL-1.0 pragma solidity 0.8.23; import "@openzeppelin/contracts/access/Ownable.sol"; import { Constants } from "../libraries/Constants.sol"; import "../interfaces/abstract/IOwnerSettings.sol"; import "./LiquidityManager.sol"; abstract contract OwnerSettings is Ownable, LiquidityManager, IOwnerSettings { /** * @dev Address of the daily rate operator. */ address public operator; /** * @dev Platform fees in basis points. * 2000 BP represents a 20% fee on the daily rate. */ uint256 public platformFeesBP = 2000; /** * @dev Default liquidation bonus in basis points. * 69 BP represents a 1.5% bonus per extracted liquidity. */ uint256 public dafaultLiquidationBonusBP = 150; /** * @dev Mapping to store liquidation bonuses for each token address. * The keys are token addresses and values are instances of the `Liquidation` struct. */ mapping(address => Liquidation) public liquidationBonusForToken; event UpdateSettingsByOwner(ITEM _item, uint256[] values); error InvalidSettingsValue(uint256 value); constructor() { operator = msg.sender; } /** * @notice This external function is used to update the settings for a particular item. The function requires two parameters: `_item`, * which is the item to be updated, and `values`, which is an array of values containing the new settings. * Only the owner of the contract has the permission to call this function. * @dev Can only be called by the owner of the contract. * @param _item The item to update the settings for. * @param values An array of values containing the new settings. */ function updateSettings(ITEM _item, uint256[] calldata values) external onlyOwner { if (_item == ITEM.LIQUIDATION_BONUS_FOR_TOKEN) { require(values.length == 3); if (values[1] > Constants.MAX_LIQUIDATION_BONUS) { revert InvalidSettingsValue(values[1]); } if (values[2] == 0) { revert InvalidSettingsValue(0); } liquidationBonusForToken[address(uint160(values[0]))] = Liquidation( values[1], values[2] ); } else if (_item == ITEM.VAULT_FLASH_FEES) { require(values.length == 2); Vault(VAULT_ADDRESS).setFlashFee(address(uint160(values[0])), uint24(values[1])); } else { require(values.length == 1); if (_item == ITEM.PLATFORM_FEES_BP) { if (values[0] > Constants.MAX_PLATFORM_FEE) { revert InvalidSettingsValue(values[0]); } platformFeesBP = values[0]; } else if (_item == ITEM.DEFAULT_LIQUIDATION_BONUS) { if (values[0] > Constants.MAX_LIQUIDATION_BONUS) { revert InvalidSettingsValue(values[0]); } dafaultLiquidationBonusBP = values[0]; } else if (_item == ITEM.OPERATOR) { operator = address(uint160(values[0])); } else if (_item == ITEM.FLASH_LOAN_AGGREGATOR) { flashLoanAggregatorAddress = address(uint160(values[0])); } else if (_item == ITEM.LIGHT_QUOTER) { lightQuoterV3Address = address(uint160(values[0])); } } emit UpdateSettingsByOwner(_item, values); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.23; interface IApproveSwapAndPay { /// @notice Struct representing the parameters for a Uniswap V3 exact input swap. struct v3SwapExactParams { bool isExactInput; /// @dev The fee tier to be used for the swap. uint24 fee; /// @dev The address of the token to be swapped from. address tokenIn; /// @dev The address of the token to be swapped to. address tokenOut; /// @dev The amount of `tokenIn/tokenOut` to be swapped. uint256 amount; } /// @notice Struct to hold parameters for swapping tokens struct SwapParams { /// @notice Address of the aggregator's router address swapTarget; /// @notice The maximum gas limit for the swap call uint256 maxGasForCall; /// @notice The aggregator's data that stores paths and amounts for swapping through bytes swapData; } function computePoolAddress( address tokenA, address tokenB, uint24 fee ) external view returns (address); function swapIsWhitelisted(address swapTarget) external view returns (bool IsWhitelisted); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.23; interface IDailyRateAndCollateral { /** * @dev Struct representing information about a token. * @param latestUpTimestamp The timestamp of the latest update for the token information. * @param accLoanRatePerSeconds The accumulated loan rate per second for the token. * @param currentDailyRate The current daily loan rate for the token. * @param totalBorrowed The total amount borrowed for the token. * @param entranceFeeBP The entrance fee in basis points for the token. */ struct TokenInfo { uint32 latestUpTimestamp; uint256 accLoanRatePerSeconds; uint256 currentDailyRate; uint256 totalBorrowed; uint256 entranceFeeBP; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.23; import "../INonfungiblePositionManager.sol"; import "../ILightQuoterV3.sol"; interface ILiquidityManager { /** * @notice Represents information about a loan. * @dev This struct is used to store liquidity and tokenId for a loan. * @param liquidity The amount of liquidity for the loan represented by a uint128 value. * @param tokenId The token ID associated with the loan represented by a uint256 value. */ struct LoanInfo { uint128 liquidity; uint256 tokenId; } struct Amounts { uint256 amount0; uint256 amount1; } struct SqrtPriceLimitation { uint24 feeTier; uint160 sqrtPriceLimitX96; } /// @dev Struct containing parameters necessary for conducting a flash loan. /// @param protocol The identifier of the flash loan protocol (if 0, the flash loan is not used). /// @param data Arbitrary data that can be used by the flash loan protocol. struct FlashLoanParams { uint8 protocol; bytes data; } /// @dev Struct containing parameters for defining restoration routes, /// including the use of external swaps, fee tiers for internal swaps, and potential flash loan arrangements. /// @param strict If the flag strict is false, part of the profit or liquidation bonus can be used to close the position. /// @param tokenId The ID of the NFT-POS token that needs to be restored, if applicable. /// @param flashLoanParams An array of FlashLoanParams structs, detailing each flash loan involved in the route. struct FlashLoanRoutes { bool strict; FlashLoanParams[] flashLoanParams; } /** * @notice Contains parameters for restoring liquidity. * @dev This struct is used to store various parameters required for restoring liquidity. * @param zeroForSaleToken A boolean value indicating whether the token for sale is the 0th token or not. * @param totalfeesOwed The total fees owed represented by a uint256 value. * @param totalBorrowedAmount The total borrowed amount represented by a uint256 value. * @param routes An array of FlashLoanRoutes structs representing the restoration routes. * @param loans An array of LoanInfo structs representing the loans. */ struct RestoreLiquidityParams { bool zeroForSaleToken; uint256 totalfeesOwed; uint256 totalBorrowedAmount; FlashLoanRoutes routes; LoanInfo[] loans; } struct CallbackData { bool zeroForSaleToken; uint24 fee; int24 tickLower; int24 tickUpper; address saleToken; address holdToken; uint256 holdTokenDebt; uint256 vaultBodyDebt; uint256 vaultFeeDebt; Amounts amounts; LoanInfo loan; FlashLoanRoutes routes; } /** * @title NFT Position Cache Data Structure * @notice This struct holds the cache data necessary for restoring liquidity to an NFT position. * @dev Stores essential parameters for an NFT representing a position in a Uniswap-like pool. * @param tickLower The lower bound of the liquidity position's price range, represented as an int24. * @param tickUpper The upper bound of the liquidity position's price range, represented as an int24. * @param fee The fee tier of the Uniswap pool in which this liquidity will be restored, represented as a uint24. * @param liquidity The amount of NFT Position liquidity. * @param saleToken The ERC-20 sale token. * @param holdToken The ERC-20 hold token. * @param operator The address of the operator who is permitted to restore liquidity and manage this position. * @param holdTokenDebt The outstanding debt of the hold token that needs to be repaid when liquidity is restored, represented as a uint256. */ struct NftPositionCache { int24 tickLower; int24 tickUpper; uint24 fee; uint128 liquidity; address saleToken; address holdToken; address operator; uint256 holdTokenDebt; } function VAULT_ADDRESS() external view returns (address); function underlyingPositionManager() external view returns (INonfungiblePositionManager); function lightQuoterV3Address() external view returns (address); function flashLoanAggregatorAddress() external view returns (address); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.23; interface IOwnerSettings { /** * @dev Enum representing various items. * * @param PLATFORM_FEES_BP The percentage of platform fees in basis points. * @param DEFAULT_LIQUIDATION_BONUS The default liquidation bonus. * @param OPERATOR The operator for operating the daily rate and entrance fee. * @param LIQUIDATION_BONUS_FOR_TOKEN The liquidation bonus for a specific token. */ enum ITEM { PLATFORM_FEES_BP, DEFAULT_LIQUIDATION_BONUS, OPERATOR, LIQUIDATION_BONUS_FOR_TOKEN, FLASH_LOAN_AGGREGATOR, LIGHT_QUOTER, VAULT_FLASH_FEES } /** * @dev Struct representing liquidation parameters. * * @param bonusBP The bonus in basis points that will be applied during a liquidation. * @param minBonusAmount The minimum amount of bonus that can be applied during a liquidation. */ struct Liquidation { uint256 bonusBP; uint256 minBonusAmount; } function updateSettings(ITEM _item, uint256[] calldata values) external; function liquidationBonusForToken( address ) external view returns (uint256 bonusBP, uint256 minBonusAmount); function platformFeesBP() external view returns (uint256); function dafaultLiquidationBonusBP() external view returns (uint256); function operator() external view returns (address); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IFlashLoanAggregator { function flashLoan(uint256 amount, bytes calldata data) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title Light Quoter Interface interface ILightQuoterV3 { /// @title Struct for "Zap In" Calculation Parameters /// @notice This struct encapsulates the various parameters required for calculating the exact amount of tokens to zap in. struct CalculateExactZapInParams { /// @notice The address of the swap pool where liquidity will be added. address swapPool; /// @notice A boolean determining which token will be used to add liquidity (true for token0 or false for token1). bool zeroForIn; /// @notice The lower bound of the tick range for the position within the pool. int24 tickLower; /// @notice The upper bound of the tick range for the position within the pool. int24 tickUpper; /// @notice The exact amount of liquidity to add to the pool. uint128 liquidityExactAmount; /// @notice The balance of the token that will be used to add liquidity. uint256 tokenInBalance; /// @notice The balance of the other token in the pool, not typically used for adding liquidity directly but necessary for calculations. uint256 tokenOutBalance; } /// @notice Calculates parameters related to "zapping in" to a position with an exact amount of liquidity. /// @dev Interacts with an on-chain liquidity pool to precisely estimate the amounts in/out to add liquidity. /// This calculation is performed using iterative methods to ensure the exactness of the resulting values. /// It uses the `getSqrtRatioAtTick` method within the loop to determine price bounds. /// This process is designed to avoid failure due to constraints such as limited input or other conditions. /// The number of iterations to reach an accurate result is bounded by a maximum value. /// @param params A `CalculateExactZapInParams` struct containing all necessary parameters to perform the calculations. /// This may include details about the liquidity pool, desired position, slippage tolerance, etc. /// @return swapAmountIn The exact total amount of input tokens required to complete the zap in operation. /// @return amount0 The exact amount of the token0 will be used for "zapping in" to a position. /// @return amount1 The exact amount of the token1 will be used for "zapping in" to a position. function calculateExactZapIn( CalculateExactZapInParams memory params ) external view returns (uint256 swapAmountIn, uint256 amount0, uint256 amount1); /** * @notice Quotes the output amount for a given input amount in a single token swap operation on Uniswap V3. * @dev This function simulates the swap and returns the estimated output amount. It does not execute the trade itself. * @param zeroForIn A boolean indicating the direction of the swap: * true for swapping the 0th token (token0) to the 1st token (token1), false for token1 to token0. * @param swapPool The address of the Uniswap V3 pool contract through which the swap will be simulated. * @param amountIn The amount of input tokens that one would like to swap. * @return sqrtPriceX96After The square root of the price after the swap, scaled by 2^96. This is the price between the two tokens in the pool post-simulation. * @return amountOut The amount of output tokens that can be expected to receive in the swap based on the current state of the pool. */ function quoteExactInputSingle( bool zeroForIn, address swapPool, uint256 amountIn ) external view returns (uint160 sqrtPriceX96After, uint256 amountOut); /** * @notice Quotes the amount of input tokens required to arrive at a specified output token amount for a single pool swap. * @dev This function performs a read-only operation to compute the necessary input amount and does not execute an actual swap. * It is useful for obtaining quotes prior to performing transactions. * @param zeroForIn A boolean that indicates the direction of the trade, true if swapping zero for in-token, false otherwise. * @param swapPool The address of the swap pool contract where the trade will take place. * @param amountOut The desired amount of output tokens. * @return sqrtPriceX96After The square root price (encoded as a 96-bit fixed point number) after the swap would occur. * @return amountIn The amount of input tokens required for the swap to achieve the desired `amountOut`. */ function quoteExactOutputSingle( bool zeroForIn, address swapPool, uint256 amountOut ) external view returns (uint160 sqrtPriceX96After, uint256 amountIn); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.23; import "./abstract/IApproveSwapAndPay.sol"; import "./abstract/ILiquidityManager.sol"; import "./abstract/IDailyRateAndCollateral.sol"; import "./abstract/IOwnerSettings.sol"; interface ILiquidityBorrowingManager is IApproveSwapAndPay, ILiquidityManager, IDailyRateAndCollateral, IOwnerSettings { /// @title BorrowParams /// @notice This struct represents the parameters required for borrowing. struct BorrowParams { /// @notice The pool fee level for the internal swap uint24 internalSwapPoolfee; /// @notice The address of the token that will be sold to obtain the loan currency address saleToken; /// @notice The address of the token that will be held address holdToken; /// @notice The minimum amount of holdToken that must be obtained uint256 minHoldTokenOut; /// @notice The maximum amount of margin deposit that can be provided uint256 maxMarginDeposit; /// @notice The maximum allowable daily rate uint256 maxDailyRate; /// @notice The SwapParams struct representing the external swap parameters SwapParams[] externalSwap; /// @notice An array of LoanInfo structs representing multiple loans LoanInfo[] loans; } /// @title BorrowingInfo /// @notice This struct represents the borrowing information for a borrower. struct BorrowingInfo { address borrower; address saleToken; address holdToken; /// @notice The amount borrowed by the borrower uint256 borrowedAmount; /// @notice The amount of liquidation bonus uint256 liquidationBonus; /// @notice The accumulated loan rate per share uint256 accLoanRatePerSeconds; /// @notice The daily rate collateral balance multiplied by COLLATERAL_BALANCE_PRECISION uint256 dailyRateCollateralBalance; } /// @notice This struct used for caching variables inside a function 'borrow' struct BorrowCache { bytes32 borrowingKey; uint256 holdTokenEntranceFee; uint256 dailyRateCollateral; uint256 borrowedAmount; uint256 holdTokenBalance; } /// @notice Struct representing the extended borrowing information. struct BorrowingInfoExt { /// @notice The main borrowing information. BorrowingInfo info; /// @notice An array of LoanInfo structs representing multiple loans LoanInfo[] loans; /// @notice The balance of the collateral. int256 collateralBalance; /// @notice The estimated lifetime of the loan. uint256 estimatedLifeTime; /// borrowing Key bytes32 key; } /// @title Repayment Parameters Structure Definition /// @notice This struct represents the parameters required for repaying a loan, including emergency mode flag, restoration routes, external swaps, and minimum expected token outputs. /// @dev Struct storing the details necessary to facilitate the repayment of a loan. /// This includes whether emergency liquidity restoration is activated, detailed restoration routes, /// parameters for any external swaps during repayment, the unique loan identifier, and minimum output amounts expected for both hold and sale tokens. struct RepayParams { /// @notice The activation of the emergency liquidity restoration, accessible only by the lender. bool isEmergency; /// @notice FlashLoanRoutes structs, detailing each route used in the repayment process. FlashLoanRoutes routes; /// @notice The external swap parameters for the repayment transaction SwapParams[] externalSwap; /// @notice The unique identifier (borrowing key) associated with the specific loan being repaid. bytes32 borrowingKey; /// @notice The minimum amount of hold token that must be received when the loan is repaid. uint256 minHoldTokenOut; /// @notice The minimum amount of sale token that must be received when the loan is repaid. uint256 minSaleTokenOut; } /// Indicates that a borrower has made a new loan event Borrow( address borrower, bytes32 borrowingKey, uint256 borrowedAmount, uint256 borrowingCollateral, uint256 liquidationBonus, uint256 dailyRatePrepayment, uint256 holdTokenEntranceFee ); /// Indicates that a borrower has repaid their loan, optionally with the help of a liquidator event Repay(address borrower, address liquidator, bytes32 borrowingKey); /// Indicates that a loan has been closed due to an emergency situation event EmergencyLoanClosure(address borrower, address lender, bytes32 borrowingKey); /// Indicates that the protocol has collected fee tokens event CollectProtocol(address recipient, address[] tokens, uint256[] amounts); /// Indicates that the lender has collected fee tokens event CollectLoansFees(address recipient, address[] tokens, uint256[] amounts); /// Indicates that the daily interest rate for holding token(for specific pair) has been updated event UpdateHoldTokenDailyRate(address saleToken, address holdToken, uint256 value); /// Indicates that the entrance fee for holding token(for specific pair) has been updated event UpdateHoldTokeEntranceFee(address saleToken, address holdToken, uint256 value); /// Indicates that a borrower has increased their collateral balance for a loan event IncreaseCollateralBalance(address borrower, bytes32 borrowingKey, uint256 collateralAmt); event ToWhitelist(address swapTarget, bool isAllowed); event Harvest(bytes32 borrowingKey, uint256 harvestedAmt); error TooLittleReceivedError(uint256 minOut, uint256 out); function getLoansInfo(bytes32 borrowingKey) external view returns (LoanInfo[] memory loans); function borrowingsInfo( bytes32 borrowingKey ) external view returns ( address borrower, address saleToken, address holdToken, uint256 borrowedAmount, uint256 liquidationBonus, uint256 accLoanRatePerSeconds, uint256 dailyRateCollateralBalance ); function collectProtocol(address recipient, address[] calldata tokens) external; function collectLoansFees(address[] calldata tokens) external; function setSwapCallToWhitelist(address swapTarget, bool isAllowed) external; function updateHoldTokenDailyRate(address saleToken, address holdToken, uint256 value) external; function updateHoldTokenEntranceFee( address saleToken, address holdToken, uint256 value ) external; function checkDailyRateCollateral( bytes32 borrowingKey ) external view returns (int256 balance, uint256 estimatedLifeTime); function getLenderCreditsInfo( uint256 tokenId ) external view returns (BorrowingInfoExt[] memory extinfo); function getBorrowingKeysForTokenId( uint256 tokenId ) external view returns (bytes32[] memory borrowingKeys); function getBorrowingKeysForBorrower( address borrower ) external view returns (bytes32[] memory borrowingKeys); function getBorrowerDebtsInfo( address borrower ) external view returns (BorrowingInfoExt[] memory extinfo); function getLiquidationBonus( address token, uint256 borrowedAmount ) external view returns (uint256 liquidationBonus); function getHoldTokenInfo( address saleToken, address holdToken ) external view returns (TokenInfo memory holdTokenRateInfo); function getFeesInfo( address feesOwner, address[] calldata tokens ) external view returns (uint256[] memory fees); function getPlatformFeesInfo( address[] calldata tokens ) external view returns (uint256[] memory fees); function calculateCollateralAmtForLifetime( bytes32 borrowingKey, uint256 lifetimeInSeconds ) external view returns (uint256 collateralAmt); function increaseCollateralBalance( bytes32 borrowingKey, uint256 collateralAmt, uint256 deadline ) external; function harvest(bytes32 borrowingKey) external returns (uint256 harvestedAmt); function borrow( BorrowParams calldata params, uint256 deadline ) external returns ( uint256 borrowedAmount, uint256 marginDeposit, uint256 liquidationBonus, uint256 dailyRateCollateral, uint256 holdTokenEntranceFee ); function repay( RepayParams calldata params, uint256 deadline ) external returns (uint256 saleTokenOut, uint256 holdTokenOut); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.23; interface INonfungiblePositionManager { /// @notice Returns the position information associated with a given token ID. /// @dev Throws if the token ID is not valid. /// @param tokenId The ID of the token that represents the position /// @return nonce The nonce for permits /// @return operator The address that is approved for spending /// @return token0 The address of the token0 for a specific pool /// @return token1 The address of the token1 for a specific pool /// @return fee The fee associated with the pool /// @return tickLower The lower end of the tick range for the position /// @return tickUpper The higher end of the tick range for the position /// @return liquidity The liquidity of the position /// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position /// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position /// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation /// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation function positions( uint256 tokenId ) external view returns ( uint96 nonce, address operator, address token0, address token1, uint24 fee, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); struct MintParams { address token0; address token1; uint24 fee; int24 tickLower; int24 tickUpper; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; address recipient; uint256 deadline; } /// @notice Creates a new position wrapped in a NFT /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized /// a method does not exist, i.e. the pool is assumed to be initialized. /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata /// @return tokenId The ID of the token that represents the minted position /// @return liquidity The amount of liquidity for this position /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function mint( MintParams calldata params ) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); struct IncreaseLiquidityParams { uint256 tokenId; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; uint256 deadline; } /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender` /// @param params tokenId The ID of the token for which liquidity is being increased, /// amount0Desired The desired amount of token0 to be spent, /// amount1Desired The desired amount of token1 to be spent, /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check, /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check, /// deadline The time by which the transaction must be included to effect the change /// @return liquidity The new liquidity amount as a result of the increase /// @return amount0 The amount of token0 to acheive resulting liquidity /// @return amount1 The amount of token1 to acheive resulting liquidity function increaseLiquidity( IncreaseLiquidityParams calldata params ) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1); struct DecreaseLiquidityParams { uint256 tokenId; uint128 liquidity; uint256 amount0Min; uint256 amount1Min; uint256 deadline; } /// @notice Decreases the amount of liquidity in a position and accounts it to the position /// @param params tokenId The ID of the token for which liquidity is being decreased, /// amount The amount by which liquidity will be decreased, /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity, /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity, /// deadline The time by which the transaction must be included to effect the change /// @return amount0 The amount of token0 accounted to the position's tokens owed /// @return amount1 The amount of token1 accounted to the position's tokens owed function decreaseLiquidity( DecreaseLiquidityParams calldata params ) external payable returns (uint256 amount0, uint256 amount1); struct CollectParams { uint256 tokenId; address recipient; uint128 amount0Max; uint128 amount1Max; } /// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient /// @param params tokenId The ID of the NFT for which tokens are being collected, /// recipient The account that should receive the tokens, /// amount0Max The maximum amount of token0 to collect, /// amount1Max The maximum amount of token1 to collect /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect( CollectParams calldata params ) external payable returns (uint256 amount0, uint256 amount1); /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens /// must be collected first. /// @param tokenId The ID of the token that is being burned function burn(uint256 tokenId) external payable; /** * @notice from IERC721 * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); function approve(address to, uint256 tokenId) external; function getApproved(uint256 tokenId) external view returns (address); event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import {IUniswapV3PoolImmutables} from './pool/IUniswapV3PoolImmutables.sol'; import {IUniswapV3PoolState} from './pool/IUniswapV3PoolState.sol'; import {IUniswapV3PoolDerivedState} from './pool/IUniswapV3PoolDerivedState.sol'; import {IUniswapV3PoolActions} from './pool/IUniswapV3PoolActions.sol'; import {IUniswapV3PoolOwnerActions} from './pool/IUniswapV3PoolOwnerActions.sol'; import {IUniswapV3PoolErrors} from './pool/IUniswapV3PoolErrors.sol'; import {IUniswapV3PoolEvents} from './pool/IUniswapV3PoolEvents.sol'; /// @title The interface for a Uniswap V3 Pool /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform /// to the ERC20 specification /// @dev The pool interface is broken up into many smaller pieces interface IUniswapV3Pool is IUniswapV3PoolImmutables, IUniswapV3PoolState, IUniswapV3PoolDerivedState, IUniswapV3PoolActions, IUniswapV3PoolOwnerActions, IUniswapV3PoolErrors, IUniswapV3PoolEvents { }
// SPDX-License-Identifier: MIT pragma solidity 0.8.23; // Interface for the Vault contract interface IVault { event VaultFlash(address token, uint256 amount, uint256 fee); // Function to transfer tokens from the vault to a specified address function transferToken(address _token, address _to, uint256 _amount) external; function vaultFlash(address token, uint256 amount, bytes calldata data) external; function setFlashFee(address token, uint24 flashFee) external; // Function to get the balances of multiple tokens function getBalances( address[] calldata tokens ) external view returns (uint256[] memory balances); function flashFeeForToken(address token) external view returns (uint24); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; interface IWagmiLeverageFlashCallback { function wagmiLeverageFlashCallback( uint256 bodyAmt, uint256 feeAmt, bytes calldata data ) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissionless pool actions /// @notice Contains pool methods that can be called by anyone interface IUniswapV3PoolActions { /// @notice Sets the initial price for the pool /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96 function initialize(uint160 sqrtPriceX96) external; /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends /// on tickLower, tickUpper, the amount of liquidity, and the current price. /// @param recipient The address for which the liquidity will be created /// @param tickLower The lower tick of the position in which to add liquidity /// @param tickUpper The upper tick of the position in which to add liquidity /// @param amount The amount of liquidity to mint /// @param data Any data that should be passed through to the callback /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback function mint( address recipient, int24 tickLower, int24 tickUpper, uint128 amount, bytes calldata data ) external returns (uint256 amount0, uint256 amount1); /// @notice Collects tokens owed to a position /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity. /// @param recipient The address which should receive the fees collected /// @param tickLower The lower tick of the position for which to collect fees /// @param tickUpper The upper tick of the position for which to collect fees /// @param amount0Requested How much token0 should be withdrawn from the fees owed /// @param amount1Requested How much token1 should be withdrawn from the fees owed /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0 /// @dev Fees must be collected separately via a call to #collect /// @param tickLower The lower tick of the position for which to burn liquidity /// @param tickUpper The upper tick of the position for which to burn liquidity /// @param amount How much liquidity to burn /// @return amount0 The amount of token0 sent to the recipient /// @return amount1 The amount of token1 sent to the recipient function burn( int24 tickLower, int24 tickUpper, uint128 amount ) external returns (uint256 amount0, uint256 amount1); /// @notice Swap token0 for token1, or token1 for token0 /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback /// @param recipient The address to receive the output of the swap /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0 /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this /// value after the swap. If one for zero, the price cannot be greater than this value after the swap /// @param data Any data to be passed through to the callback /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data ) external returns (int256 amount0, int256 amount1); /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling /// with 0 amount{0,1} and sending the donation amount(s) from the callback /// @param recipient The address which will receive the token0 and token1 amounts /// @param amount0 The amount of token0 to send /// @param amount1 The amount of token1 to send /// @param data Any data to be passed through to the callback function flash( address recipient, uint256 amount0, uint256 amount1, bytes calldata data ) external; /// @notice Increase the maximum number of price and liquidity observations that this pool will store /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to /// the input observationCardinalityNext. /// @param observationCardinalityNext The desired minimum number of observations for the pool to store function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that is not stored /// @notice Contains view functions to provide information about the pool that is computed rather than stored on the /// blockchain. The functions here may have variable gas costs. interface IUniswapV3PoolDerivedState { /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, /// you must call it with secondsAgos = [3600, 0]. /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio. /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block /// timestamp function observe(uint32[] calldata secondsAgos) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s); /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed. /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first /// snapshot is taken and the second snapshot is taken. /// @param tickLower The lower tick of the range /// @param tickUpper The upper tick of the range /// @return tickCumulativeInside The snapshot of the tick accumulator for the range /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range /// @return secondsInside The snapshot of seconds per liquidity for the range function snapshotCumulativesInside(int24 tickLower, int24 tickUpper) external view returns ( int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Errors emitted by a pool /// @notice Contains all events emitted by the pool interface IUniswapV3PoolErrors { error LOK(); error TLU(); error TLM(); error TUM(); error AI(); error M0(); error M1(); error AS(); error IIA(); error L(); error F0(); error F1(); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Events emitted by a pool /// @notice Contains all events emitted by the pool interface IUniswapV3PoolEvents { /// @notice Emitted exactly once by a pool when #initialize is first called on the pool /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96 /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool event Initialize(uint160 sqrtPriceX96, int24 tick); /// @notice Emitted when liquidity is minted for a given position /// @param sender The address that minted the liquidity /// @param owner The owner of the position and recipient of any minted liquidity /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity minted to the position range /// @param amount0 How much token0 was required for the minted liquidity /// @param amount1 How much token1 was required for the minted liquidity event Mint( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted when fees are collected by the owner of a position /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees /// @param owner The owner of the position for which fees are collected /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount0 The amount of token0 fees collected /// @param amount1 The amount of token1 fees collected event Collect( address indexed owner, address recipient, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount0, uint128 amount1 ); /// @notice Emitted when a position's liquidity is removed /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect /// @param owner The owner of the position for which liquidity is removed /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity to remove /// @param amount0 The amount of token0 withdrawn /// @param amount1 The amount of token1 withdrawn event Burn( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted by the pool for any swaps between token0 and token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the output of the swap /// @param amount0 The delta of the token0 balance of the pool /// @param amount1 The delta of the token1 balance of the pool /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96 /// @param liquidity The liquidity of the pool after the swap /// @param tick The log base 1.0001 of price of the pool after the swap event Swap( address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick ); /// @notice Emitted by the pool for any flashes of token0/token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the tokens from flash /// @param amount0 The amount of token0 that was flashed /// @param amount1 The amount of token1 that was flashed /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee event Flash( address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint256 paid0, uint256 paid1 ); /// @notice Emitted by the pool for increases to the number of observations that can be stored /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index /// just before a mint/swap/burn. /// @param observationCardinalityNextOld The previous value of the next observation cardinality /// @param observationCardinalityNextNew The updated value of the next observation cardinality event IncreaseObservationCardinalityNext( uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew ); /// @notice Emitted when the protocol fee is changed by the pool /// @param feeProtocol0Old The previous value of the token0 protocol fee /// @param feeProtocol1Old The previous value of the token1 protocol fee /// @param feeProtocol0New The updated value of the token0 protocol fee /// @param feeProtocol1New The updated value of the token1 protocol fee event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New); /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner /// @param sender The address that collects the protocol fees /// @param recipient The address that receives the collected protocol fees /// @param amount0 The amount of token0 protocol fees that is withdrawn /// @param amount0 The amount of token1 protocol fees that is withdrawn event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that never changes /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values interface IUniswapV3PoolImmutables { /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface /// @return The contract address function factory() external view returns (address); /// @notice The first of the two tokens of the pool, sorted by address /// @return The token contract address function token0() external view returns (address); /// @notice The second of the two tokens of the pool, sorted by address /// @return The token contract address function token1() external view returns (address); /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 /// @return The fee function fee() external view returns (uint24); /// @notice The pool tick spacing /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... /// This value is an int24 to avoid casting even though it is always positive. /// @return The tick spacing function tickSpacing() external view returns (int24); /// @notice The maximum amount of position liquidity that can use any tick in the range /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool /// @return The max amount of liquidity per tick function maxLiquidityPerTick() external view returns (uint128); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissioned pool actions /// @notice Contains pool methods that may only be called by the factory owner interface IUniswapV3PoolOwnerActions { /// @notice Set the denominator of the protocol's % share of the fees /// @param feeProtocol0 new protocol fee for token0 of the pool /// @param feeProtocol1 new protocol fee for token1 of the pool function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; /// @notice Collect the protocol fee accrued to the pool /// @param recipient The address to which collected protocol fees should be sent /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 /// @return amount0 The protocol fee collected in token0 /// @return amount1 The protocol fee collected in token1 function collectProtocol( address recipient, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that can change /// @notice These methods compose the pool's state, and can change with any frequency including multiple times /// per transaction interface IUniswapV3PoolState { /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas /// when accessed externally. /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value /// @return tick The current tick of the pool, i.e. according to the last tick transition that was run. /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick /// boundary. /// @return observationIndex The index of the last oracle observation that was written, /// @return observationCardinality The current maximum number of observations stored in the pool, /// @return observationCardinalityNext The next maximum number of observations, to be updated when the observation. /// @return feeProtocol The protocol fee for both tokens of the pool. /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0 /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee. /// unlocked Whether the pool is currently locked to reentrancy function slot0() external view returns ( uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked ); /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal0X128() external view returns (uint256); /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal1X128() external view returns (uint256); /// @notice The amounts of token0 and token1 that are owed to the protocol /// @dev Protocol fees will never exceed uint128 max in either token function protocolFees() external view returns (uint128 token0, uint128 token1); /// @notice The currently in range liquidity available to the pool /// @dev This value has no relationship to the total liquidity across all ticks /// @return The liquidity at the current price of the pool function liquidity() external view returns (uint128); /// @notice Look up information about a specific tick in the pool /// @param tick The tick to look up /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or /// tick upper /// @return liquidityNet how much liquidity changes when the pool price crosses the tick, /// @return feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0, /// @return feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1, /// @return tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick /// @return secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick, /// @return secondsOutside the seconds spent on the other side of the tick from the current tick, /// @return initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false. /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0. /// In addition, these values are only relative and must be used only in comparison to previous snapshots for /// a specific position. function ticks(int24 tick) external view returns ( uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128, int56 tickCumulativeOutside, uint160 secondsPerLiquidityOutsideX128, uint32 secondsOutside, bool initialized ); /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information function tickBitmap(int16 wordPosition) external view returns (uint256); /// @notice Returns the information about a position by the position's key /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper /// @return liquidity The amount of liquidity in the position, /// @return feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke, /// @return feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke, /// @return tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke, /// @return tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke function positions(bytes32 key) external view returns ( uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); /// @notice Returns data about a specific observation index /// @param index The element of the observations array to fetch /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time /// ago, rather than at a specific index in the array. /// @return blockTimestamp The timestamp of the observation, /// @return tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp, /// @return secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp, /// @return initialized whether the observation has been initialized and the values are safe to use function observations(uint256 index) external view returns ( uint32 blockTimestamp, int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128, bool initialized ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import { FullMath } from "../vendor0.8/uniswap/FullMath.sol"; import { FixedPoint96 } from "../vendor0.8/uniswap/FixedPoint96.sol"; library AmountsLiquidity { /// @notice Computes the amount of token0 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 function getAmount0RoundingUpForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0) { unchecked { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96); return FullMath.mulDivRoundingUp(liquidity, sqrtRatioBX96 - sqrtRatioAX96, intermediate); } } /// @notice Computes the amount of token1 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount1 The amount of token1 function getAmount1RoundingUpForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); unchecked { return FullMath.mulDivRoundingUp( liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96 ); } } /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function getAmountsRoundingUpForLiquidity( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0, uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { amount0 = getAmount0RoundingUpForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } else if (sqrtRatioX96 < sqrtRatioBX96) { amount0 = getAmount0RoundingUpForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity); amount1 = getAmount1RoundingUpForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity); } else { amount1 = getAmount1RoundingUpForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } } }
// SPDX-License-Identifier: SAL-1.0 pragma solidity 0.8.23; /// @title Constant state library Constants { uint256 internal constant BP = 10000; uint256 internal constant BPS = 1000; uint24 internal constant FLASH_LOAN_DEFAULT_VAULT_FEE = 6900; // 0.69 % uint24 internal constant FLASH_LOAN_FEE_COMPENSATION = 10100; // 1.01% uint256 internal constant DEFAULT_DAILY_RATE = 30; // 0.3% uint256 internal constant MAX_PLATFORM_FEE = 2000; // 20% uint256 internal constant MAX_LIQUIDATION_BONUS = 1000; // 10% uint256 internal constant MAX_DAILY_RATE = 10000; // 100% uint256 internal constant MIN_DAILY_RATE = 5; // 0.05 % uint256 internal constant MAX_ENTRANCE_FEE_BPS = 1000; // 10% uint256 internal constant DEFAULT_ENTRANCE_FEE_BPS = 10; // 0.1% uint256 internal constant MAX_NUM_LOANS_PER_POSITION = 7; uint256 internal constant COLLATERAL_BALANCE_PRECISION = 1e18; uint256 internal constant MINIMUM_AMOUNT = 1000; uint256 internal constant MINIMUM_EXTRACTED_AMOUNT = 10; }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.23; library ErrLib { enum ErrorCode { INVALID_BORROWING_KEY, // 0 LIQUIDITY_IS_ZERO, // 1 TOO_BIG_MARGIN_DEPOSIT, // 2 TOO_OLD_TRANSACTION, // 3 FORBIDDEN, // 4 COLLATERAL_AMOUNT_IS_NOT_ENOUGH, // 5 TOO_MANY_LOANS_PER_POSITION, // 6 LOANS_IS_EMPTY, // 7 PRICE_SLIPPAGE_CHECK, // 8 ERC20_APPROVE_DID_NOT_SUCCEED, // 9 SWAP_TARGET_NOT_APPROVED, // 10 INTERNAL_SWAP_ERROR, //11 INVALID_CALLER, //12 TOO_LOW_LIQUIDITY, //13 TOO_BIG_DAILY_RATE, //14 UNACCEPTABLE_SQRT_PRICE, //15 SWAP_TARGET_ADDRESS_IS_ZERO, //16 INTERNAL_SWAP_POOL_FEE_CANNOT_BE_ZERO, //17, SWAP_PRICE_IS_TOO_BAD, //18 INVALID_EXTERNAL_SWAP, //19 EXTERNAL_SWAP_ERROR, //20 INTERNAL_SWAP_TOO_SMALL_AMOUNT_OUT, //21 INVALID_ROUTE_TOKENID, //22 SWAP_AFTER_FLASH_LOAN_FAILED, //23 TOO_MUCH_TOTAL_BORROW //24 } error RevertErrorCode(ErrorCode code); /** * @dev Reverts with a custom error message based on the provided condition and error code. * @param condition The condition to check for reverting. * @param code The ErrorCode representing the specific error. */ function revertError(bool condition, ErrorCode code) internal pure { if (condition) { revert RevertErrorCode(code); } } }
// SPDX-License-Identifier: SAL-1.0 pragma solidity 0.8.23; library ExternalCall { /** * @dev Executes a call to the `target` address with the given `data`, gas limit `maxGas`. * @param target The address of the contract or external function to call. * @param data The calldata to include in the call. * @param maxGas The maximum amount of gas to be used for the call. If set to 0, it uses the remaining gas. * @return success A boolean indicating whether the call was successful. */ function _externalCall( address target, bytes calldata data, uint256 maxGas ) internal returns (bool success) { if (maxGas == 0) { maxGas = gasleft(); } assembly ("memory-safe") { let ptr := mload(0x40) calldatacopy(ptr, data.offset, data.length) success := call( maxGas, target, 0, //value ptr, //Inputs are stored at location ptr data.length, 0, 0 ) if and(not(success), and(gt(returndatasize(), 0), lt(returndatasize(), 256))) { returndatacopy(ptr, 0, returndatasize()) revert(ptr, returndatasize()) } mstore(0x40, add(ptr, data.length)) // Set storage pointer to empty space } } }
// SPDX-License-Identifier: SAL-1.0 pragma solidity 0.8.23; library Keys { /** * @dev Computes the borrowing key based on the borrower's address, sale token address, and hold token address. * @param borrower The address of the borrower. * @param saleToken The address of the sale token. * @param holdToken The address of the hold token. * @return The computed borrowing key as a bytes32 value. */ function computeBorrowingKey( address borrower, address saleToken, address holdToken ) internal pure returns (bytes32) { return keccak256(abi.encodePacked(borrower, saleToken, holdToken)); } /** * @dev Computes the pair key based on the sale token address and hold token address. * @param saleToken The address of the sale token. * @param holdToken The address of the hold token. * @return The computed pair key as a bytes32 value. */ function computePairKey(address saleToken, address holdToken) internal pure returns (bytes32) { return keccak256(abi.encodePacked(saleToken, holdToken)); } }
// SPDX-License-Identifier: GPL-2.0-or-later // https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/TransferHelper.sol pragma solidity 0.8.23; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; library TransferHelper { /// @notice Transfers tokens from the targeted address to the given destination /// @notice Errors with 'STF' if transfer fails /// @param token The contract address of the token to be transferred /// @param from The originating address from which the tokens will be transferred /// @param to The destination address of the transfer /// @param value The amount to be transferred function safeTransferFrom(address token, address from, address to, uint256 value) internal { (bool success, bytes memory data) = token.call( abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value) ); require(success && (data.length == 0 || abi.decode(data, (bool))), "W-STF"); } /// @notice Transfers tokens from msg.sender to a recipient /// @dev Errors with ST if transfer fails /// @param token The contract address of the token which will be transferred /// @param to The recipient of the transfer /// @param value The value of the transfer function safeTransfer(address token, address to, uint256 value) internal { (bool success, bytes memory data) = token.call( abi.encodeWithSelector(IERC20.transfer.selector, to, value) ); require(success && (data.length == 0 || abi.decode(data, (bool))), "W-ST"); } function getBalance(address token) internal view returns (uint256 balance) { bytes memory callData = abi.encodeWithSelector(IERC20.balanceOf.selector, address(this)); (bool success, bytes memory data) = token.staticcall(callData); require(success && data.length >= 32); balance = abi.decode(data, (uint256)); } function getBalanceOf(address token, address target) internal view returns (uint256 balance) { bytes memory callData = abi.encodeWithSelector(IERC20.balanceOf.selector, target); (bool success, bytes memory data) = token.staticcall(callData); require(success && data.length >= 32); balance = abi.decode(data, (uint256)); } }
// SPDX-License-Identifier: SAL-1.0 /** * WAGMI Leverage Protocol Vault v2.0 * wagmi.com */ pragma solidity 0.8.23; import "@openzeppelin/contracts/access/Ownable.sol"; import "./interfaces/IVault.sol"; import "./interfaces/IWagmiLeverageFlashCallback.sol"; import "./vendor0.8/uniswap/FullMath.sol"; import { TransferHelper } from "./libraries/TransferHelper.sol"; contract Vault is Ownable, IVault { using TransferHelper for address; uint24 internal constant MAX_FLASH_FEE = 10000; // 1.00% uint24 private immutable defaultFlashFee; mapping(address => uint24) public flashFeeForToken; constructor(uint24 _defaultFlashFee) { defaultFlashFee = _defaultFlashFee; } function setFlashFee(address token, uint24 flashFee) external onlyOwner { require(flashFee <= MAX_FLASH_FEE, "V-FE"); flashFeeForToken[token] = flashFee; } function vaultFlash(address token, uint256 amount, bytes calldata data) external onlyOwner { uint256 balanceBefore = token.getBalance(); if (balanceBefore < amount) amount = balanceBefore; uint256 feeAmt; if (amount > 0) { uint24 flashFee = flashFeeForToken[token]; if (flashFee == 0) { flashFee = defaultFlashFee; } feeAmt = FullMath.mulDivRoundingUp(amount, flashFee, 1e6); token.safeTransfer(msg.sender, amount); balanceBefore += feeAmt; } IWagmiLeverageFlashCallback(msg.sender).wagmiLeverageFlashCallback(amount, feeAmt, data); uint256 balanceAfter = token.getBalance(); require(balanceBefore <= balanceAfter, "V-FL"); if (amount > 0) emit VaultFlash(token, amount, feeAmt); } /** * @notice Transfers tokens to a specified address * @param _token The address of the token to be transferred * @param _to The address to which the tokens will be transferred * @param _amount The amount of tokens to be transferred */ function transferToken(address _token, address _to, uint256 _amount) external onlyOwner { if (_amount > 0) { _token.safeTransfer(_to, _amount); } } /** * @dev Retrieves the balances of multiple tokens for this contract. * @param tokens The array of token addresses for which to retrieve the balances. * @return balances An array of uint256 values representing the balances of the corresponding tokens in the `tokens` array. */ function getBalances( address[] calldata tokens ) external view returns (uint256[] memory balances) { uint256 length = tokens.length; balances = new uint256[](length); for (uint256 i; i < length; ) { balances[i] = tokens[i].getBalance(); unchecked { ++i; } } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.4.0; /// @title FixedPoint96 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) /// @dev Used in SqrtPriceMath.sol library FixedPoint96 { uint8 internal constant RESOLUTION = 96; uint256 internal constant Q96 = 0x1000000000000000000000000; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; /// @title Contains 512-bit math functions /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits library FullMath { /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv function mulDiv( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = a * b // Compute the product mod 2**256 and mod 2**256 - 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**256 + prod0 uint256 prod0 = a * b; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(a, b, not(0)) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Make sure the result is less than 2**256. // Also prevents denominator == 0 require(denominator > prod1); // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { assembly { result := div(prod0, denominator) } return result; } /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0] // Compute remainder using mulmod uint256 remainder; assembly { remainder := mulmod(a, b, denominator) } // Subtract 256 bit number from 512 bit number assembly { prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator // Compute largest power of two divisor of denominator. // Always >= 1. uint256 twos = (0 - denominator) & denominator; // Divide denominator by power of two assembly { denominator := div(denominator, twos) } // Divide [prod1 prod0] by the factors of two assembly { prod0 := div(prod0, twos) } // Shift in bits from prod1 into prod0. For this we need // to flip `twos` such that it is 2**256 / twos. // If twos is zero, then it becomes one assembly { twos := add(div(sub(0, twos), twos), 1) } prod0 |= prod1 * twos; // Invert denominator mod 2**256 // Now that denominator is an odd number, it has an inverse // modulo 2**256 such that denominator * inv = 1 mod 2**256. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, denominator * inv = 1 mod 2**4 uint256 inv = (3 * denominator) ^ 2; // Now use 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. inv *= 2 - denominator * inv; // inverse mod 2**8 inv *= 2 - denominator * inv; // inverse mod 2**16 inv *= 2 - denominator * inv; // inverse mod 2**32 inv *= 2 - denominator * inv; // inverse mod 2**64 inv *= 2 - denominator * inv; // inverse mod 2**128 inv *= 2 - denominator * inv; // inverse mod 2**256 // Because the division is now exact we can divide by multiplying // with the modular inverse of denominator. This will give us the // correct result modulo 2**256. Since the preconditions guarantee // that the outcome is less than 2**256, this is the final result. // We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inv; return result; } } /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result function mulDivRoundingUp( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { unchecked { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) > 0) { require(result < type(uint256).max); result++; } } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import { FullMath } from "./FullMath.sol"; import { FixedPoint96 } from "./FixedPoint96.sol"; import { SafeCast } from "./SafeCast.sol"; /// @title Liquidity amount functions /// @notice Provides functions for computing liquidity amounts from token amounts and prices library LiquidityAmounts { /// @notice Computes the amount of liquidity received for a given amount of token0 and price range /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower)) /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount0 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount0( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96); unchecked { return SafeCast.toUint128( FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96) ); } } /// @notice Computes the amount of liquidity received for a given amount of token1 and price range /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)). /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount1 The amount1 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount1( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); unchecked { return SafeCast.toUint128( FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96) ); } } /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount of token0 being sent in /// @param amount1 The amount of token1 being sent in /// @return liquidity The maximum amount of liquidity received function getLiquidityForAmounts( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0); } else if (sqrtRatioX96 < sqrtRatioBX96) { uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0); uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1); liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1; } else { liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1); } } /// @notice Computes the amount of token0 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 function getAmount0ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0) { unchecked { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return FullMath.mulDiv( uint256(liquidity) << FixedPoint96.RESOLUTION, sqrtRatioBX96 - sqrtRatioAX96, sqrtRatioBX96 ) / sqrtRatioAX96; } } /// @notice Computes the amount of token1 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount1 The amount of token1 function getAmount1ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); unchecked { return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96); } } /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function getAmountsForLiquidity( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0, uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } else if (sqrtRatioX96 < sqrtRatioBX96) { amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity); amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity); } else { amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Safe casting methods /// @notice Contains methods for safely casting between types library SafeCast { /// @notice Cast a uint256 to a uint160, revert on overflow /// @param y The uint256 to be downcasted /// @return z The downcasted integer, now type uint160 function toUint160(uint256 y) internal pure returns (uint160 z) { require((z = uint160(y)) == y); } /// @notice Cast a int256 to a int128, revert on overflow or underflow /// @param y The int256 to be downcasted /// @return z The downcasted integer, now type int128 function toInt128(int256 y) internal pure returns (int128 z) { require((z = int128(y)) == y); } /// @notice Cast a uint256 to a int256, revert on overflow /// @param y The uint256 to be casted /// @return z The casted integer, now type int256 function toInt256(uint256 y) internal pure returns (int256 z) { require(y < 2 ** 255); z = int256(y); } /// @notice Downcasts uint256 to uint128 /// @param x The uint258 to be downcasted /// @return y The passed value, downcasted to uint128 function toUint128(uint256 x) internal pure returns (uint128 y) { require((y = uint128(x)) == x); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.20; /// @title Math library for computing sqrt prices from ticks and vice versa /// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports /// prices between 2**-128 and 2**128 library TickMath { /// @notice Thrown when the tick passed to #getSqrtRatioAtTick is not between MIN_TICK and MAX_TICK error InvalidTick(); /// @notice Thrown when the ratio passed to #getTickAtSqrtRatio does not correspond to a price between MIN_TICK and MAX_TICK error InvalidSqrtRatio(); /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128 int24 internal constant MIN_TICK = -887272; /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 int24 internal constant MAX_TICK = -MIN_TICK; /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) uint160 internal constant MIN_SQRT_RATIO = 4295128739; /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342; /// @notice Given a tickSpacing, compute the maximum usable tick function maxUsableTick(int24 tickSpacing) internal pure returns (int24) { unchecked { return (MAX_TICK / tickSpacing) * tickSpacing; } } /// @notice Given a tickSpacing, compute the minimum usable tick function minUsableTick(int24 tickSpacing) internal pure returns (int24) { unchecked { return (MIN_TICK / tickSpacing) * tickSpacing; } } /// @notice Calculates sqrt(1.0001^tick) * 2^96 /// @dev Throws if |tick| > max tick /// @param tick The input tick for the above formula /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (currency1/currency0) /// at the given tick function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) { unchecked { uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); if (absTick > uint256(int256(MAX_TICK))) revert InvalidTick(); uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000; if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128; if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128; if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128; if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128; if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128; if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128; if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128; if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128; if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128; if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128; if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128; if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128; if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128; if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128; if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128; if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128; if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128; if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128; if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128; if (tick > 0) ratio = type(uint256).max / ratio; // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96. // we then downcast because we know the result always fits within 160 bits due to our tick input constraint // we round up in the division so getTickAtSqrtRatio of the output price is always consistent sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1)); } } /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may /// ever return. /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96 /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) { unchecked { // second inequality must be < because the price can never reach the price at the max tick if (sqrtPriceX96 < MIN_SQRT_RATIO || sqrtPriceX96 >= MAX_SQRT_RATIO) revert InvalidSqrtRatio(); uint256 ratio = uint256(sqrtPriceX96) << 32; uint256 r = ratio; uint256 msb = 0; assembly { let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(5, gt(r, 0xFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(4, gt(r, 0xFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(3, gt(r, 0xFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(2, gt(r, 0xF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(1, gt(r, 0x3)) msb := or(msb, f) r := shr(f, r) } assembly { let f := gt(r, 0x1) msb := or(msb, f) } if (msb >= 128) r = ratio >> (msb - 127); else r = ratio << (127 - msb); int256 log_2 = (int256(msb) - 128) << 64; assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(63, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(62, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(61, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(60, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(59, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(58, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(57, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(56, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(55, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(54, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(53, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(52, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(51, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(50, f)) } int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128); int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128); tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow; } } }
{ "viaIR": true, "evmVersion": "paris", "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_underlyingPositionManagerAddress","type":"address"},{"internalType":"address","name":"_flashLoanAggregator","type":"address"},{"internalType":"address","name":"_lightQuoterV3","type":"address"},{"internalType":"address","name":"_underlyingV3Factory","type":"address"},{"internalType":"bytes32","name":"_underlyingV3PoolInitCodeHash","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint128","name":"max","type":"uint128"},{"internalType":"uint128","name":"min","type":"uint128"},{"internalType":"uint128","name":"liquidity","type":"uint128"}],"name":"InvalidLiquidityAmount","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint128","name":"borrowedLiquidity","type":"uint128"},{"internalType":"uint128","name":"restoredLiquidity","type":"uint128"}],"name":"InvalidRestoredLiquidity","type":"error"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"InvalidSettingsValue","type":"error"},{"inputs":[],"name":"InvalidTick","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"InvalidTokens","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"NotApproved","type":"error"},{"inputs":[{"internalType":"enum ErrLib.ErrorCode","name":"code","type":"uint8"}],"name":"RevertErrorCode","type":"error"},{"inputs":[{"internalType":"uint256","name":"expectedOut","type":"uint256"},{"internalType":"uint256","name":"receivedOut","type":"uint256"}],"name":"SwapSlippageCheckError","type":"error"},{"inputs":[{"internalType":"uint256","name":"minOut","type":"uint256"},{"internalType":"uint256","name":"out","type":"uint256"}],"name":"TooLittleReceivedError","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"bytes32","name":"borrowingKey","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"borrowedAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"borrowingCollateral","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"liquidationBonus","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dailyRatePrepayment","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"holdTokenEntranceFee","type":"uint256"}],"name":"Borrow","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"address[]","name":"tokens","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"CollectLoansFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"address[]","name":"tokens","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"CollectProtocol","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"address","name":"lender","type":"address"},{"indexed":false,"internalType":"bytes32","name":"borrowingKey","type":"bytes32"}],"name":"EmergencyLoanClosure","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"borrowingKey","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"harvestedAmt","type":"uint256"}],"name":"Harvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"bytes32","name":"borrowingKey","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"collateralAmt","type":"uint256"}],"name":"IncreaseCollateralBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"bytes32","name":"borrowingKey","type":"bytes32"}],"name":"Repay","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"swapTarget","type":"address"},{"indexed":false,"internalType":"bool","name":"isAllowed","type":"bool"}],"name":"ToWhitelist","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"saleToken","type":"address"},{"indexed":false,"internalType":"address","name":"holdToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"UpdateHoldTokeEntranceFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"saleToken","type":"address"},{"indexed":false,"internalType":"address","name":"holdToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"UpdateHoldTokenDailyRate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum IOwnerSettings.ITEM","name":"_item","type":"uint8"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"UpdateSettingsByOwner","type":"event"},{"inputs":[],"name":"UNDERLYING_V3_FACTORY_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNDERLYING_V3_POOL_INIT_CODE_HASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VAULT_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint24","name":"internalSwapPoolfee","type":"uint24"},{"internalType":"address","name":"saleToken","type":"address"},{"internalType":"address","name":"holdToken","type":"address"},{"internalType":"uint256","name":"minHoldTokenOut","type":"uint256"},{"internalType":"uint256","name":"maxMarginDeposit","type":"uint256"},{"internalType":"uint256","name":"maxDailyRate","type":"uint256"},{"components":[{"internalType":"address","name":"swapTarget","type":"address"},{"internalType":"uint256","name":"maxGasForCall","type":"uint256"},{"internalType":"bytes","name":"swapData","type":"bytes"}],"internalType":"struct IApproveSwapAndPay.SwapParams[]","name":"externalSwap","type":"tuple[]"},{"components":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"internalType":"struct ILiquidityManager.LoanInfo[]","name":"loans","type":"tuple[]"}],"internalType":"struct ILiquidityBorrowingManager.BorrowParams","name":"params","type":"tuple"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"borrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"borrowingsInfo","outputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"saleToken","type":"address"},{"internalType":"address","name":"holdToken","type":"address"},{"internalType":"uint256","name":"borrowedAmount","type":"uint256"},{"internalType":"uint256","name":"liquidationBonus","type":"uint256"},{"internalType":"uint256","name":"accLoanRatePerSeconds","type":"uint256"},{"internalType":"uint256","name":"dailyRateCollateralBalance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"borrowingKey","type":"bytes32"},{"internalType":"uint256","name":"lifetimeInSeconds","type":"uint256"}],"name":"calculateCollateralAmtForLifetime","outputs":[{"internalType":"uint256","name":"collateralAmt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"borrowingKey","type":"bytes32"}],"name":"checkDailyRateCollateral","outputs":[{"internalType":"int256","name":"balance","type":"int256"},{"internalType":"uint256","name":"estimatedLifeTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"collectLoansFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"collectProtocol","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"}],"name":"computePoolAddress","outputs":[{"internalType":"address","name":"pool","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dafaultLiquidationBonusBP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"flashLoanAggregatorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"}],"name":"getBorrowerDebtsInfo","outputs":[{"components":[{"components":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"saleToken","type":"address"},{"internalType":"address","name":"holdToken","type":"address"},{"internalType":"uint256","name":"borrowedAmount","type":"uint256"},{"internalType":"uint256","name":"liquidationBonus","type":"uint256"},{"internalType":"uint256","name":"accLoanRatePerSeconds","type":"uint256"},{"internalType":"uint256","name":"dailyRateCollateralBalance","type":"uint256"}],"internalType":"struct ILiquidityBorrowingManager.BorrowingInfo","name":"info","type":"tuple"},{"components":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"internalType":"struct ILiquidityManager.LoanInfo[]","name":"loans","type":"tuple[]"},{"internalType":"int256","name":"collateralBalance","type":"int256"},{"internalType":"uint256","name":"estimatedLifeTime","type":"uint256"},{"internalType":"bytes32","name":"key","type":"bytes32"}],"internalType":"struct ILiquidityBorrowingManager.BorrowingInfoExt[]","name":"extinfo","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"}],"name":"getBorrowingKeysForBorrower","outputs":[{"internalType":"bytes32[]","name":"borrowingKeys","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getBorrowingKeysForTokenId","outputs":[{"internalType":"bytes32[]","name":"borrowingKeys","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"feesOwner","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"getFeesInfo","outputs":[{"internalType":"uint256[]","name":"fees","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"saleToken","type":"address"},{"internalType":"address","name":"holdToken","type":"address"}],"name":"getHoldTokenInfo","outputs":[{"components":[{"internalType":"uint32","name":"latestUpTimestamp","type":"uint32"},{"internalType":"uint256","name":"accLoanRatePerSeconds","type":"uint256"},{"internalType":"uint256","name":"currentDailyRate","type":"uint256"},{"internalType":"uint256","name":"totalBorrowed","type":"uint256"},{"internalType":"uint256","name":"entranceFeeBP","type":"uint256"}],"internalType":"struct IDailyRateAndCollateral.TokenInfo","name":"holdTokenRateInfo","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getLenderCreditsInfo","outputs":[{"components":[{"components":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"saleToken","type":"address"},{"internalType":"address","name":"holdToken","type":"address"},{"internalType":"uint256","name":"borrowedAmount","type":"uint256"},{"internalType":"uint256","name":"liquidationBonus","type":"uint256"},{"internalType":"uint256","name":"accLoanRatePerSeconds","type":"uint256"},{"internalType":"uint256","name":"dailyRateCollateralBalance","type":"uint256"}],"internalType":"struct ILiquidityBorrowingManager.BorrowingInfo","name":"info","type":"tuple"},{"components":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"internalType":"struct ILiquidityManager.LoanInfo[]","name":"loans","type":"tuple[]"},{"internalType":"int256","name":"collateralBalance","type":"int256"},{"internalType":"uint256","name":"estimatedLifeTime","type":"uint256"},{"internalType":"bytes32","name":"key","type":"bytes32"}],"internalType":"struct ILiquidityBorrowingManager.BorrowingInfoExt[]","name":"extinfo","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"borrowedAmount","type":"uint256"}],"name":"getLiquidationBonus","outputs":[{"internalType":"uint256","name":"liquidationBonus","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"borrowingKey","type":"bytes32"}],"name":"getLoansInfo","outputs":[{"components":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"internalType":"struct ILiquidityManager.LoanInfo[]","name":"loans","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"getPlatformFeesInfo","outputs":[{"internalType":"uint256[]","name":"fees","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"borrowingKey","type":"bytes32"}],"name":"harvest","outputs":[{"internalType":"uint256","name":"harvestedAmt","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"borrowingKey","type":"bytes32"},{"internalType":"uint256","name":"collateralAmt","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"increaseCollateralBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lightQuoterV3Address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"liquidationBonusForToken","outputs":[{"internalType":"uint256","name":"bonusBP","type":"uint256"},{"internalType":"uint256","name":"minBonusAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"platformFeesBP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"isEmergency","type":"bool"},{"components":[{"internalType":"bool","name":"strict","type":"bool"},{"components":[{"internalType":"uint8","name":"protocol","type":"uint8"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct ILiquidityManager.FlashLoanParams[]","name":"flashLoanParams","type":"tuple[]"}],"internalType":"struct ILiquidityManager.FlashLoanRoutes","name":"routes","type":"tuple"},{"components":[{"internalType":"address","name":"swapTarget","type":"address"},{"internalType":"uint256","name":"maxGasForCall","type":"uint256"},{"internalType":"bytes","name":"swapData","type":"bytes"}],"internalType":"struct IApproveSwapAndPay.SwapParams[]","name":"externalSwap","type":"tuple[]"},{"internalType":"bytes32","name":"borrowingKey","type":"bytes32"},{"internalType":"uint256","name":"minHoldTokenOut","type":"uint256"},{"internalType":"uint256","name":"minSaleTokenOut","type":"uint256"}],"internalType":"struct ILiquidityBorrowingManager.RepayParams","name":"params","type":"tuple"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"repay","outputs":[{"internalType":"uint256","name":"saleTokenOut","type":"uint256"},{"internalType":"uint256","name":"holdTokenOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"swapTarget","type":"address"},{"internalType":"bool","name":"isAllowed","type":"bool"}],"name":"setSwapCallToWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"swapTarget","type":"address"}],"name":"swapIsWhitelisted","outputs":[{"internalType":"bool","name":"IsWhitelisted","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"underlyingPositionManager","outputs":[{"internalType":"contract INonfungiblePositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"saleToken","type":"address"},{"internalType":"address","name":"holdToken","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"updateHoldTokenDailyRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"saleToken","type":"address"},{"internalType":"address","name":"holdToken","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"updateHoldTokenEntranceFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum IOwnerSettings.ITEM","name":"_item","type":"uint8"},{"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"updateSettings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"bodyAmt","type":"uint256"},{"internalType":"uint256","name":"feeAmt","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"wagmiLeverageFlashCallback","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
610100346200026d57601f62006c3138819003918201601f1916830192916001600160401b03918285118486101762000272578160a092859260409788528339810103126200026d57620000538262000288565b90620000626020840162000288565b906200007085850162000288565b926080620000816060870162000288565b9501519060009384549260018060a01b0396878094819360018060a01b03199b338d8a16178b558d5198843391167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08d80a360805260a0521660e05216876003541617600355168560025416176002556020810190428252308782015286815260608101918183108484111762000259578288528151902092610a268083019160608301919082118583101762000245576020939291611af4916200620b87395203019083f59081156200023a57501660c0526107d06007556096600855339060065416176006556001600b5551615f6d90816200029e8239608051818181610e9001526139d8015260a051818181610d150152613a07015260c0518181816104a5015281816106a30152818161082f01528181610b0b01528181610ca201528181610df301528181611c4d0152818161274f015281816129170152818161298201528181612d3001528181612d9f015281816131db0152613f46015260e0518181816105940152818161070c015281816115930152818161165501528181612a0101528181615147015281816153ee01526154b00152f35b8451903d90823e3d90fd5b634e487b7160e01b87526041600452602487fd5b634e487b7160e01b85526041600452602485fd5b600080fd5b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b03821682036200026d5756fe610100604052600436101561001357600080fd5b600060a05260a0513560e01c806301777e961461312e57806309e3d369146123175780630d4aa914146122955780631291f2d6146122505780632bfcb42a146121cb5780632d6913631461215a5780632de3b8d7146121305780632f59e85a146120c457806339afeff414611fc45780634555b94714611f835780634960b29d14611f105780634b7dd768146111ca57806352ee2671146111a057806353b744201461117157806355ecf5a814611122578063570ca735146110f85780635d689b6f146110635780636c8edaca1461102c578063715018a614610fce5780637775422e14610f4557806382a9440214610ebf57806383719c6514610e79578063873c7ef514610d385780638c804b2814610cfc5780638da5cb5b14610cd15780639092c31c14610c8b578063a0b014a814610940578063a4841bcf146108c0578063ade9712a14610743578063ae6e34661461063e578063b58b18d7146105c3578063bb9e8ef01461057d578063c24c9b8f146104ce578063d623439314610443578063e81a893914610424578063f2fde38b1461035c578063f4c5ef6d146102da578063fa461e33146101f55763fe9507ec146101d057600080fd5b346101ef5760a0513660031901126101ef576020600754604051908152f35b60a05180fd5b346101ef5760603660031901126101ef576004356024356044356001600160401b0381116101ef5761022b9036906004016134e3565b92909160a0518213938415806102ce575b6102b55783606091810103126101ef576102a79361029661025c856133e3565b9461028d610278604061027160208501613268565b9301613268565b6001600160a01b039283169790831688613977565b163314156143c9565b156102ad5750905b33903090614406565b60a05180f35b90509061029e565b60405163b88beff960e01b8152600b6004820152602490fd5b5060a05182131561023c565b346101ef576020806003193601126101ef5760043560a05152600e602052604060a051209060405190816020845491828152019360a05152602060a051209160a051905b8282106103455761034185610335818903826135d3565b6040519182918261349a565b0390f35b83548652948501946001938401939091019061031e565b346101ef5760203660031901126101ef5761037561323c565b61037d614e16565b6001600160a01b039081169081156103d057600054826001600160601b0360a01b821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a360a05180f35b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b346101ef5760a0513660031901126101ef576020600854604051908152f35b346101ef5760603660031901126101ef576044356001600160401b0381116101ef576104766102a79136906004016134e3565b9061049660018060a01b03806002541633141590816104a1575b506143c9565b602435600435613c79565b90507f00000000000000000000000000000000000000000000000000000000000000001633141585610490565b346101ef576104dc366133ae565b916104f360018060a01b03600654163314156143c9565b6103e983116105645761055b837f3e5945033f29e2143d79669b9b4968fbf6d998878c579e907f1cbef4fd8fb11794600461052e868661459e565b905001556040519384938460409194939294606082019560018060a01b0380921683521660208201520152565b0390a160a05180f35b604051636bd62feb60e11b815260048101849052602490fd5b346101ef5760a0513660031901126101ef576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b346101ef5760203660031901126101ef5760043560a05152600d60205260e0604060a0512060018060a01b038082541691816001820154169160028201541660038201546004830154916006600585015494015494604051968752602087015260408601526060850152608084015260a083015260c0820152f35b346101ef5760403660031901126101ef5761065761323c565b60243580151580910361073e577f2ba7a606df56ff43c0a75a37d64019d91adf54eda72f67c6a457189a4a7d943891604091610691614e16565b6001600160a01b03918216916106db907f000000000000000000000000000000000000000000000000000000000000000081168414908115610734575b8115610708575b506143e8565b8160a0515260016020528260a0512060ff1981541660ff831617905582519182526020820152a160a05180f35b90507f0000000000000000000000000000000000000000000000000000000000000000168314866106d5565b30851491506106ce565b600080fd5b346101ef576020806003193601126101ef576004356001600160401b0381116101ef576107749036906004016133f3565b903360a051526004602052604060a051209261078f83614cff565b9360005b8481106107cf5750505061055b7f54217ca99866ba075643d5ee9eccf9ed28c2f0099ebe01b821d121b5ec3c8e9f936040519384933385613a47565b6107e26107dd828787613ab6565b613836565b6001600160a01b038082166000908152848652604090208054670de0b6b3a76400009004939291908461081d575b5050506001915001610793565b600090558361082c848b614975565b527f00000000000000000000000000000000000000000000000000000000000000001692833b1561073e57604051637aa9bf6f60e11b81526001600160a01b039290921660048301523360248301526044820152916000908390606490829084905af19182156108b4576001926108a5575b8080610810565b6108ae90613538565b8761089e565b6040513d6000823e3d90fd5b346101ef576020806003193601126101ef576001600160a01b036108e261323c565b1660a05152600f602052604060a051209060405190816020845491828152019360a05152602060a051209160a051905b8282106109295761034185610335818903826135d3565b835486529485019460019384019390910190610912565b346101ef5760403660031901126101ef5760043560078110156101ef57602480356001600160401b0381116101ef5761097d9036906004016133f3565b92610986614e16565b60009260038203610af157600385036101ef578460011015610adb5760208301356103e88111610ac6578560021015610aaf5760408401358015610a9657604051916109d183613566565b8252602082019081528615610a7f5760a080516001600160a01b0387351690526009602052516040902091518255516001909101555b60405193610a695750825260406020830181905282018390526001600160fb1b0383116101ef57816060917f95d8e1d07c148ab8a26430cf05958b3aeecebe03ec33919e180e1bba835bfccc9460051b8091848401378101030190a160a05180f35b60a08051634e487b7160e01b9052602160045251fd5b82634e487b7160e01b60a05152603260045260a051fd5b604051636bd62feb60e11b815260a05160048201528390fd5b5060a08051634e487b7160e01b9052603260045251fd5b60405190636bd62feb60e11b82526004820152fd5b60a08051634e487b7160e01b9052603260045251fd5b60068203610ba957600285036101ef576001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081168615610a7f578660011015610a7f57803b156101ef5760405191630bfa1a8960e41b8352853516600483015262ffffff602086013516838301528160448160a0519360a051905af18015610b9c57610b86575b505b610a07565b610b8f90613538565b60a0516101ef5785610b7f565b6040513d60a051823e3d90fd5b9250600184036101ef5760009281610bd4578415610adb5782356107d08111610ac657600755610a07565b60018203610bf5578415610adb5782356103e88111610ac657600855610a07565b6000935060028203610c28578415610adb57600680546001600160a01b03191684356001600160a01b0316179055610a07565b60048203610c57578415610adb57600280546001600160a01b03191684356001600160a01b0316179055610a07565b600093506004198201610b81578415610adb57600380546001600160a01b03191684356001600160a01b0316179055610a07565b346101ef5760a0513660031901126101ef576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b346101ef5760a0513660031901126101ef5760a051546040516001600160a01b039091168152602090f35b346101ef5760a0513660031901126101ef5760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b346101ef57610d4636613457565b610d4e614e16565b610d5781614cff565b9060005b818110610d9657507fcace23d1ed8c8a9e74d77b41c1418438aa1e682092d5019be401b54ae82c11ad939161055b9160405194859485613a47565b610da46107dd828487613ab6565b6001600160a01b0380821660009081526005602052604090208054670de0b6b3a764000090049392919084610de1575b5050506001915001610d5b565b6000905583610df08488614975565b527f00000000000000000000000000000000000000000000000000000000000000001692833b1561073e57604051637aa9bf6f60e11b81526001600160a01b03928316600482015291881660248301526044820152916000908390606490829084905af19182156108b457600192610e6a575b8080610dd4565b610e7390613538565b86610e63565b346101ef5760a0513660031901126101ef576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b346101ef57610ecd36613457565b919060018060a01b0380921660a0515260206004602052604060a0512090610ef485614cff565b9360005b868110610f15576040516020808252819061034190820189613423565b8082610f276107dd6001948b8a613ab6565b16600052848452604060002054610f3e8289614975565b5201610ef8565b346101ef576020806003193601126101ef5760043560a05152600c8152610f70604060a05120613667565b604051908282018383528151809152836040840192019360a0515b828110610f985784840385f35b90919282604082610fbf6001948a51602080916001600160801b0381511684520151910152565b01960191019492919094610f8b565b346101ef5760a0513660031901126101ef57610fe8614e16565b600080546001600160a01b0319811682556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a360a05180f35b346101ef5760203660031901126101ef57604061104a600435614d31565b909150670de0b6b3a76400008351920582526020820152f35b346101ef576020806003193601126101ef576004356001600160401b0381116101ef576110949036906004016133f3565b909161109f82614cff565b9260005b8381106110c0576040516020808252819061034190820188613423565b6001906001600160a01b036110d96107dd838887613ab6565b16600052600584526040600020546110f18288614975565b52016110a3565b346101ef5760a0513660031901126101ef576006546040516001600160a01b039091168152602090f35b346101ef5760603660031901126101ef5761113b61323c565b611143613252565b9060443562ffffff8116810361073e5760209261115f92613977565b6040516001600160a01b039091168152f35b346101ef5760403660031901126101ef57602061119861118f61323c565b60243590613915565b604051908152f35b346101ef5760a0513660031901126101ef576003546040516001600160a01b039091168152602090f35b346101ef576003196040368201126101ef576001600160401b03600435116101ef5761010090600435360301126101ef57611203614335565b611210602435421161438b565b61121861380b565b60805261124061122c602460043501613836565b61123a604460043501613836565b9061459e565b90604060805101526112556004820154614ce2565b60c052611266602460043501613836565b611274604460043501613836565b906040519060208201923360601b84526001600160601b0319809260601b16603484015260601b166048820152603c81526112ae8161359d565b519020608051526112c3602460043501613836565b6001600160a01b036112d9600435604401613836565b166001600160a01b0390911610906112f5600435602401613836565b611303604460043501613836565b60075461132461131d60e46004350160043560040161384a565b36916138b8565b60a0519586949193859291611337614926565b60a051979096905b8151891015611853576113528983614975565b5160e0526113638860e0518561547f565b60c0880151306001600160a01b039091160361183557611388602060e05101516153b4565b60808901516001600160a01b0387811691161480159061181b575b801561180a575b6117ec57885160029060208b0151820b906000198201627fffff1992627fffff8213848312176117c9576113e96113e361142a93615929565b91615929565b80826001600160a01b03808316908216116117e1575b5061141890506001600160a01b038281169084166156ab565b9190036001600160a01b0316906156f2565b92836001600160801b0381160361073e5761144682820b615929565b92627fffff83830b6001019081139113176117c957611469916001910b01615929565b9081816001600160a01b03808316908216116117be575b505090036001600160a01b0316801561073e57600560611b04906001600160801b03821691820361073e576001600160801b0381168210156117b8576001600160801b039150165b6001600160801b0360e05151166001600160801b0360608c0151169182821180156117a6575b61176c5750505060c0516116f3575b5060e08801510197602060e0510151906001600160801b0360e0515116604051906115278261354b565b838252602082019081526040820160a0518152606083019060a05182526001600160801b03608085019342855260405195630624e65f60e11b87525160048701525116602485015251604484015251606483015251608482015260408160a48160a05160018060a01b037f0000000000000000000000000000000000000000000000000000000000000000165af18015610b9c5760a0519182916116d2575b50604051938460808101106001600160401b036080870111176116bc5760808501604090815290855230602086019081526001600160801b0393841682870190815292841660608701908152825163fc6f786560e01b81529651600488015290516001600160a01b03908116602488015292518416604487015251909216606485015260a051849160849183917f0000000000000000000000000000000000000000000000000000000000000000165af1918215610b9c5760019261168e575b50019761133f565b6116af9060403d6040116116b5575b6116a781836135d3565b810190615eb3565b50611686565b503d61169d565b634e487b7160e01b600052604160045260246000fd5b90506116ed915060403d6040116116b5576116a781836135d3565b8e6115c6565b9a9561170560c05160e08b0151614b38565b80910196612710670de0b6b3a76400008a84020204019b60018060a01b031660a051526004602052604060a0512060018060a01b0360a08b015116600052602052604060002090670de0b6b3a7640000612710818b8402020491020381540190558b6114fd565b608493506001600160801b0390602060e0510151936040519463198c2b6f60e21b8652600486015260248501521660448301526064820152fd5b506001600160801b03811682106114ee565b506114c8565b925090508f80611480565b634e487b7160e01b60a051526011600452602460a051fd5b9150915038806113ff565b6024602060e051015160405190633c129e7d60e21b82526004820152fd5b506001600160a01b038116156113aa565b5060a08901516001600160a01b03868116911614156113a3565b6024602060e0510151604051906319db8bf560e21b82526004820152fd5b8a8a918760206080510152806060608051015215611ef7576001600160a01b03611881600435604401613836565b1660a051526005602052604060a0512090815401905560c4600435016118ac816004356004016135f4565b9050611eca575b506118c2602460043501613836565b6118e26118dc6118d6604460043501613836565b92615c9a565b91615c9a565b60808051015280611e0c575b506080805101516064600435013590818110611dee57826080515160a05152600d602052604060a0512090611927602460043501613836565b611935604460043501613836565b9060a460043501356040608051015111611dd557611960606060805101516040608051015190614b38565b60805160400152600384015415611d8b575050815461198a906001600160a01b03163314156143aa565b611998818360805151614b7a565b505b6119b06003606060805101519201918254613510565b908190556001600160a01b0310611d725760a051608080519081015160609091015180821115611d485750506119f260808051015160606080510151906137fe565b670de0b6b3a764000081818102048114821517156117c957611a3d906001600160a01b03611a24600435604401613836565b1660a051526005602052604060a0512092028254613510565b90555b6080515191611a5c61131d60e46004350160043560040161384a565b60a08051859052600c602052516040812092905b8251811015611bad57611a838184614975565b5190602082015160a05152600e602052611aa287604060a05120615ec9565b15611b29578454600160401b811015611b1157611ac6600191828101885587614989565b919091611af8576020846001600160801b0360019651166001600160801b031985541617845501519101555b01611a70565b634e487b7160e01b60a0515260a051600452602460a051fd5b634e487b7160e01b60a051526041600452602460a051fd5b93949095919260a0515060a0515b8654811015611b9e576001611b4c8289614989565b500154602089015114611b6157600101611b37565b96600192969591949397611b816001600160801b03809351169188614989565b50918254918183160116906001600160801b031916179055611af2565b50929195509392600190611af2565b8582866007875411611d2f57611bd260a09333855152600f6020526040855120615ec9565b50611c92611bf4611be7604460043501613836565b6060608051015190613915565b92606060805101516003820154016003820155600481018481540190556006604060805101519101670de0b6b3a76400008202815401905560206080510151908484010101611c75611c4a604460043501613836565b917f000000000000000000000000000000000000000000000000000000000000000080933390614406565b611c83604460043501613836565b90608080510151913090614406565b7fb3f3f47c10633b93eb42b0a7467190b3f64baf0e6364f9b6821bab84d506dc1460e0608051516060608051015160406080510151602060805101519160405193338552602085015260408401528560608401528660808401528783015260c0820152a16060608051015191604060805101519060206080510151926001600b556040519485526020850152604084015260608301526080820152f35b60405163b88beff960e01b815260066004820152602490fd5b03905060043560840135811115611a405760405163b88beff960e01b815260026004820152602490fd5b60405163b88beff960e01b815260186004820152602490fd5b83546001600160a01b0319908116331785556001808601805483166001600160a01b039485161790556002860180549092169390921692909217909155810154600583015561199a565b60405163b88beff960e01b8152600e6004820152602490fd5b6044925060405191631cc0106b60e21b835260048301526024820152fd5b600435600401359062ffffff821682036101ef57611e8b91611e8091611e36602460043501613836565b611e44604460043501613836565b9062ffffff60405194611e568661354b565b600186521660208501526001600160a01b0390811660408501521660608301526080820152614eaf565b608080510151613510565b608080510152611ea7611ea2602460043501613836565b615c9a565b611eb157816118ee565b60405163b88beff960e01b8152600d6004820152602490fd5b611ef190611eeb611edf602460043501613836565b916004356004016135f4565b91614687565b816118b3565b60405163b88beff960e01b815260076004820152602490fd5b346101ef5760203660031901126101ef576020611f76600435611f31614335565b8060a05152600d8352604060a05120611f4e6003820154156143aa565b60018101546002820154611f6e916001600160a01b03918216911661459e565b929050614b7a565b6001600b55604051908152f35b346101ef5760203660031901126101ef576001600160a01b03611fa461323c565b1660a051526001602052602060ff604060a0512054166040519015158152f35b346101ef5760403660031901126101ef5760243560a0515060a05160043560a05152600d602052604060a05120604051611ffd8161351d565b60018060a01b0380835416825280600184015416908160208401526002840154169182604082015260038401549060c06006606083019684885260048101546080850152600581015460a08501520154910152612060575b602084604051908152f35b61208892935060409161207291614ae5565b01519151670de0b6b3a764000080930290614b0d565b916120938184615772565b92096120b2575b80156120aa575b80828080612055565b5060016120a1565b60001981101561073e5760010161209a565b346101ef5760403660031901126101ef5760a06120f96120e261323c565b6120ea613252565b906120f361380b565b50614ae5565b60806040519163ffffffff815116835260208101516020840152604081015160408401526060810151606084015201516080820152f35b346101ef5760a0513660031901126101ef576002546040516001600160a01b039091168152602090f35b346101ef57612168366133ae565b9161217f60018060a01b03600654163314156143c9565b612710831180156121c1575b6105645761055b837fe25bc35d32d39a14e740b4d2ffafc3a63704f9cdc1d79b8691c41eb1cc7dc5b894600261052e868661459e565b506005831061218b565b346101ef576020806003193601126101ef5760043560a05152600e602052604060a0512060405191826020835491828152019260a05152602060a051209160a051905b8282106122395761034161222d87612228818903826135d3565b6149dd565b6040519182918261327c565b83548552938401936001938401939091019061220e565b346101ef5760203660031901126101ef576001600160a01b0361227161323c565b1660a05152600960205260408060a051206001815491015482519182526020820152f35b346101ef576020806003193601126101ef576001600160a01b036122b761323c565b1660a05152600f602052604060a0512060405191826020835491828152019260a05152602060a051209160a051905b8282106123005761034161222d87612228818903826135d3565b8354855293840193600193840193909101906122e6565b346101ef576003196040368201126101ef576001600160401b03600435116101ef5760c090600435360301126101ef5761234f614335565b61235c602435421161438b565b60a08051600435606401358152600d60205290516040908190209051906123dd906123868361351d565b80546001600160a01b039081168452600182015481166020850152600282015416604084015260038101546060840181905260048201546080850152600582015460a085015260069091015460c0840152156143aa565b6020810151604082015160808301516001600160a01b03928316939290911690612407828561459e565b90506124266001820154606086015160a087015160c0880151916145dd565b9490949260a05186129560018060a01b0383511633141580613126575b61244c906143c9565b60a05181131561311757670de0b6b3a7640000900401945b6004356004013580151581036101ef57156128d15761248390156143e8565b606081015160a0519095909485612498614926565b936064600435013560a05152600c602052604060a051209560a0515060a051925b875480851015612603576124d66124d0868b614989565b50613640565b903360018060a01b036124ec60208501516153b4565b16036125f65760001981019081116117c957612508908a614989565b50612513868b614989565b919091611af8578082036125cc575b5050885480156125b45761253a60001982018b614989565b92909261259e57878f8b9360006001878261258299550155600019018d55602083015160a05152600e60205261257b60646004350135604060a05120615dac565b501061547f565b6125958b60e0890151809c019b8b61589c565b019b5b9b6124b9565b634e487b7160e01b600052600060045260246000fd5b634e487b7160e01b60a051526031600452602460a051fd5b6001816001600160801b03829354166001600160801b031985541617845501549101558e80612522565b50509b9260010192612598565b5096955099509997505050925054159083156128b857670de0b6b3a76400006126616003926126368760608c01516137fe565b60608b01526126498160c08c01516137fe565b60c08b015260408a01516001600160a01b031661462c565b0495018381540390556000146128855784516001600160a01b03169360005b6060518110156126bc57806020608060019360051b01510151600052600e6020526126b5606460043501356040600020615dac565b5001612680565b5090919293600052600f6020526126dd606460043501356040600020615dac565b5060646004350135600052600d60205260006006604082208281558260018201558260028201558260038201558260048201558260058201550155600c60205260406000208054906000815581612835575b50509061273b91613510565b905b60408401519101906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081169116813b156101ef57604051637aa9bf6f60e11b815260a080516001600160a01b039390931660048301523360248301526044820185905251909283916064918391905af18015610b9c5761281f575b509151604080516001600160a01b039092168252336020830152600435606401358282015292907f7d5a4c3aa8690b61be4809a3878d586d548b08150b40170ba9488271c708208090606090a15b6001600b5582519182526020820152f35b61282890613538565b60a0516101ef57836127c0565b6001600160ff1b038216820361286f5760005260206000209060011b8101905b8181101561272f5760008082556001820155600201612855565b634e487b7160e01b600052601160045260246000fd5b506064600493929335013560a05152600d602052604060a0512060c085015160068201556003606086015191015561273d565b60405163b88beff960e01b815260016004820152602490fd5b509550906128f16129149160018060a09897981b0360408901511661462c565b9460036060880151930183815403905560018060a01b0360408801511692613510565b907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163b156101ef57604051637aa9bf6f60e11b815260a080516001600160a01b03938416600484015230602484015260448301949094525190929183916064918391907f0000000000000000000000000000000000000000000000000000000000000000165af18015610b9c57613108575b506044600435016129c5816004356004016135f4565b90506130e2575b506064600435013560a05152600c6020526129eb604060a05120613667565b6040850151909390612a42906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811691612a2f918391166147b8565b60208701516001600160a01b03166147b8565b6060850151916042196004353603016024600435013512156101ef5760405193612a6b8561354b565b10835260208301526040820152612a8c3660048035602481013501016136d8565b6060820152816080820152612a9f614926565b9260405190612aad82613566565b60a08051835280516020840152515b60808401518051821015612ef25781612ad491614975565b519060018060a01b03612aea60208401516153b4565b169182612afd575b506001915001612abc565b600492612b0e89838951151561547f565b608089015160a08a01516001600160a01b039081169291612b33916118d69116615c9a565b90612b4c60208a015160e08d015160408c01519161589c565b9060a0515285602052604060a0512060018060a01b0360a08d015116600052602052604060002090815401905560e08a612bb060018060a01b0360808301511660018060a01b0360a08401511662ffffff604060018060a01b039501511691613977565b1660405196878092633850c7bd851b82525afa908115610b9c578a9560a05192612e5c575b50612be3865160020b615929565b91612bf4602088015160020b615929565b855160a051946001600160801b03909116928583836001600160a01b0380831690821611612e51575b50506001600160a01b038281169084168111612e135750505090612c419291615d52565b915b60208901819052828952895115612e0c57825b83851015612df5575050612d20939495612d2e9160018060a01b03608083015116968b805115159362ffffff60408201511693815160020b6060602084015160020b9260e060018060a01b0360a08701511695015160a05150818111600014612ded5750945b01519560405197612ccc89613581565b885260208801526040870152606086015289608086015260a085015260c084015260a05160e084015260a0516101008401528a61012084015261014083015261016082015260405194859160208301613b2a565b03601f1981018552846135d3565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163b156101ef5760405193630af2d39160e31b85526004850152036024830152606060448301528180612d9160a051936064830190613aea565b038160a05160018060a01b037f0000000000000000000000000000000000000000000000000000000000000000165af18015610b9c57612dd7575b506001905b87612af2565b612de090613538565b60a0516101ef5786612dcc565b905094612cbc565b925092505060019450612e07926150bb565b612dd1565b8092612c56565b9296509092916001600160a01b0383161115612e45575090612e3a83612e40949383615d52565b94615d00565b612c43565b94612e40939250615d00565b945092503880612c1d565b9550905060e0853d60e011612eea575b81612e7960e093836135d3565b810103126101ef5784516001600160a01b03811681036101ef57612e9f60208701615471565b50612eac6040870161591a565b50612eb96060870161591a565b50612ec66080870161591a565b5060a086015160ff8116036101ef57612ee260c08c970161520a565b50908b612bd5565b3d9150612e6c565b5050929350505060018060a01b038151169060005b8351811015612f4557806020612f1f60019387614975565b510151600052600e602052612f3e606460043501356040600020615dac565b5001612f07565b509150600052600f602052612f64606460043501356040600020615dac565b5060646004350135600052600d60205260006006604082208281558260018201558260028201558260038201558260048201558260058201550155600c602052604060002080549060008155816130a8575b5050602081015160408201516001600160a01b039081169291612fdd916118d69116615c9a565b82916084600435013582108015613099575b613080576130787f9d807a078de01997b96cd2f26db189efd5999c0926b7da12fbe7b50fe57f4b8b9161304c60409661303586333060018060a01b038c88015116614406565b6020830151339030906001600160a01b0316614406565b5185516001600160a01b0390911681523360208201526064600435013560408201529081906060820190565b0390a161280e565b60405163b88beff960e01b815260086004820152602490fd5b5060a460043501358410612fef565b6001600160ff1b038216820361286f5760005260206000209060011b8101905b81811015612fb657600080825560018201556002016130c8565b61310290611eeb60018060a01b03604088015116916004356004016135f4565b846129cc565b61311190613538565b846129af565b5094925060c081015192612464565b508615612443565b346101ef5760603660031901126101ef5760043560243561314d614335565b61315a604435421161438b565b8160a05152600d602052604060a05120916003830154158015613228575b613181906143aa565b670de0b6b3a7640000918281029281840414811517156117c95761320b81856060956131d360067f32adb282cc270b34d31ba66933cfadafe5bf671d46a694da62f520987046b0119901918254613510565b9055600201547f00000000000000000000000000000000000000000000000000000000000000009033906001600160a01b0316614406565b6040519133835260208301526040820152a16001600b5560a05180f35b5082546001600160a01b0316331415613178565b600435906001600160a01b038216820361073e57565b602435906001600160a01b038216820361073e57565b35906001600160a01b038216820361073e57565b602080820190808352835180925260409283810182858560051b8401019601946000906000935b8685106132b557505050505050505090565b9091929394959697603f1982820301855286895191610160928382019080519160018060a01b03808451168552808685015116868601528884015116888501526060908184015182860152608093848101518587015260a0808201519087015260c08091015190860152858301519660e086015286518091528561018086019701908a905b8a818310613374578501516101008801525050508101516101208401520151610140909101529098810197969560010194019291906132a3565b8961339d859b6001959798999a9b949651602080916001600160801b0381511684520151910152565b01980192018d96959493929161333a565b606090600319011261073e576001600160a01b0390600435828116810361073e5791602435908116810361073e579060443590565b359062ffffff8216820361073e57565b9181601f8401121561073e578235916001600160401b03831161073e576020808501948460051b01011161073e57565b90815180825260208080930193019160005b828110613443575050505090565b835185529381019392810192600101613435565b90604060031983011261073e576004356001600160a01b038116810361073e5791602435906001600160401b03821161073e57613496916004016133f3565b9091565b602090602060408183019282815285518094520193019160005b8281106134c2575050505090565b8351855293810193928101926001016134b4565b3590811515820361073e57565b9181601f8401121561073e578235916001600160401b03831161073e576020838186019501011161073e57565b9190820180921161286f57565b60e081019081106001600160401b038211176116bc57604052565b6001600160401b0381116116bc57604052565b60a081019081106001600160401b038211176116bc57604052565b604081019081106001600160401b038211176116bc57604052565b61018081019081106001600160401b038211176116bc57604052565b606081019081106001600160401b038211176116bc57604052565b608081019081106001600160401b038211176116bc57604052565b90601f801991011681019081106001600160401b038211176116bc57604052565b903590601e198136030182121561073e57018035906001600160401b03821161073e57602001918160051b3603831361073e57565b6001600160401b0381116116bc5760051b60200190565b9060405161364d81613566565b6020600182946001600160801b0381541684520154910152565b90815461367381613629565b9261368160405194856135d3565b818452600090815260208082208186015b8484106136a0575050505050565b6002836001926136af85613640565b815201920193019290613692565b6001600160401b0381116116bc57601f01601f191660200190565b91906040808483031261073e5780516136f081613566565b80946136fb816134d6565b8252602092838201356001600160401b039283821161073e57019185601f8401121561073e5782359061372d82613629565b9661373a845198896135d3565b828852868089019360051b8601019481861161073e57878101935b86851061376757505050505050500152565b843584811161073e5782019086601f19838603011261073e5786519161378c83613566565b8a81013560ff8116810361073e578352878101359086821161073e57019084603f8301121561073e578a820135926137c3846136bd565b6137cf8a5191826135d3565b848152868a868601011161073e5760008d8681978d839801838601378301015283820152815201940193613755565b9190820391821161286f57565b604051906138188261354b565b60006080838281528260208201528260408201528260608201520152565b356001600160a01b038116810361073e5790565b903590601e198136030182121561073e57018035906001600160401b03821161073e57602001918160061b3603831361073e57565b919082604091031261073e5760405161389781613566565b809280356001600160801b038116810361073e578252602090810135910152565b9291926138c482613629565b6040926138d460405192836135d3565b819581835260208093019160061b84019381851161073e57915b8483106138fd57505050505050565b83869161390a848661387f565b8152019201916138ee565b91909160018060a01b0316600052600960205261271060406000209260405161393d81613566565b60018554958683520154946020820195865215613968575b51020491518083106139645750565b9150565b6103e885526008548152613955565b6001600160a01b039290919083821684841611613a3f575b62ffffff908460405193816020860196168652166040840152166060820152606081526139bb816135b8565b519020604051602081019160ff60f81b83526001600160601b03197f000000000000000000000000000000000000000000000000000000000000000060601b16602183015260358201527f0000000000000000000000000000000000000000000000000000000000000000605582015260558152613a38816135b8565b5190201690565b90919061398f565b6001600160a01b0391821681526060602080830182905290820185905291959460808201949093919260005b828110613a945750505050613a919394506040818403910152613423565b90565b9091929582806001928b613aa78b613268565b16815201970193929101613a73565b9190811015613ac65760051b0190565b634e487b7160e01b600052603260045260246000fd5b35908160020b820361073e57565b919082519283825260005b848110613b16575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201613af5565b9060208083528151151581840152808201519162ffffff604093166040850152604081015160020b6060850152606081015160020b6080850152608081015160018060a01b0380911660a086015260a08201511660c085015260c081015160e085015260e08101516101009081860152810151610120908186015281015190613be383610140938051858901520151926101609384880152820151610180870190602080916001600160801b0381511684520151910152565b0151906101c08085015280610220850192805115156101e08701520151936040610200820152845180935261024082818301918560051b8401019601946000925b858410613c35575050505050505090565b909192939495968580613c6860019361023f1986820301885286838d5160ff815116845201519181858201520190613aea565b990194019401929594939190613c24565b909192602084828101031261073e578335936001600160401b03851161073e576101c0858201838301031261073e5760405194613cb586613581565b613cc08183016134d6565b8652613cd06020828401016133e3565b6020870152613ce3604082840101613adc565b6040870152613cf6606082840101613adc565b6060870152613d09608082840101613268565b6080870152613d1c60a082840101613268565b60a087015281810160c0818101359088015260e08082013590880152610100808201359088015260408484019190910361011f19011261073e57604051613d6281613566565b6101208284010135815261014082840101356020820152610120870152613d918383016101608385010161387f565b6101408701526101a08183010135906001600160401b03821161073e57613dbc9383019201016136d8565b6101608401526080830151613dd9906001600160a01b0316615c9a565b8351158015906143255761012085015151905b818310614019575b505050613e1361014084015161012085015160208151910151916150bb565b613e3a613e2e613e238484613510565b60e086015190613510565b61010085015190613510565b80613e46575b50505050565b602084015160a08501516080860151604051613e9994909390926001600160a01b0392831692169062ffffff16613e7c8561354b565b600085526020850152604084015260608301526080820152614eaf565b83511561400a57613eb8602061012086015101515b60c08601516137fe565b8060c08601526101608501515115159182614000575b5050613fe757600254336001600160a01b0390911603613f9957608083018051610100850180516001600160a01b0392831660009081526005602052604090208054670de0b6b3a76400009092029091019055915160e08601519251613f9096613f88949093613f6d931691613f4391613510565b907f0000000000000000000000000000000000000000000000000000000000000000903090614406565b608001516002546001600160a01b0391821694911692613510565b913090614406565b38808080613e40565b60808301516001600160a01b031660009081526005602052604090208054670de0b6b3a76400008402019055613fe2929091613f4391608001516001600160a01b031692613510565b613f90565b60405163b88beff960e01b815260176004820152602490fd5b1190503880613ece565b613eb861012085015151613eae565b610160860151602081015151158015614311575b156141f45750505060a0840151608085015160208601516140629262ffffff909116916001600160a01b039081169116613977565b908451156001600160801b036101408701515116926040870151606088015160020b9060c08901516001600160801b036101208b01519760018060a01b036003541694604051966140b28861351d565b60018060a01b0316875260208701978852604087019460020b8552606087019081526080870191825260a0870193845260c08701948986526040519860208a01986320dcf3cd60e01b8a5260018060a01b0390511660248b015251151560448a01525160020b60648901525160020b6084880152511660a48601525160c48501525160e484015260e483526101208301918383106001600160401b038411176116bc57600093849360405251915afa5061416a614e6e565b60608180518101031261073e576141eb928160206141e5930151916060604083015192015160208201525262ffffff6020880151169060018060a01b0360a08901511660018060a01b0360808a01511690604051936141c88561354b565b600185526020850152604084015260608301526080820152614eaf565b90613510565b50388080613df4565b6142ad946142bb9396949760018060a01b03600254169562ffffff60208301511692604083015160020b606084015160020b60018060a01b0360808601511660018060a01b0360a0870151169160c087015193610140610120890151980151986040519b6142618d613581565b8c5260208c015260408b015260608a0152608089015260a088015260c087015260e086015261010085015261012084015261014083015261016082015260405193849160208301613b2a565b03601f1981018452836135d3565b803b1561073e576142f5936000809460405196879586948593635296a43160e01b8552036004840152604060248401526044830190613aea565b03925af180156108b4576143065750565b61430f90613538565b565b506002546001600160a01b0316331461402d565b6020610120860151015190613dec565b6002600b5414614346576002600b55565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b61439157565b60405163b88beff960e01b815260036004820152602490fd5b6143b057565b60405163b88beff960e01b815260006004820152602490fd5b6143cf57565b60405163b88beff960e01b8152600c6004820152602490fd5b6143ee57565b60405163b88beff960e01b8152600480820152602490fd5b90929192826144155750505050565b60009384936001600160a01b039083821630036144de578592935060405191602083019463a9059cbb60e01b865216602483015260448201526044815261445b816135b8565b51925af1614467614e6e565b816144a7575b501561447c5738808080613e40565b606460405162461bcd60e51b815260206004820152600460248201526315cb54d560e21b6044820152fd5b80518015925082156144bc575b50503861446d565b819250906020918101031261073e5760206144d7910161520a565b38806144b4565b6040516323b872dd60e01b602082019081526001600160a01b0395861660248301529390941660448501526064808501919091528352509083906145236084826135d3565b51925af161452f614e6e565b81614567575b50613f905760405162461bcd60e51b81526020600482015260056024820152642b96a9aa2360d91b6044820152606490fd5b805180159250821561457c575b505038614535565b819250906020918101031261073e576020614597910161520a565b3880614574565b906145a891615217565b9190600052600a602052604080600020926020810151600185015563ffffffff81511663ffffffff1985541617845501519190565b93919093600094600094826145f25750505050565b61460a949650614604929395506137fe565b90614b38565b908181039060008312801582841316918312161761286f579138808080613e40565b9060075480820290828204148215171561286f5761271090049160018060a01b0316600052600560205260406000208281540190550390565b9190811015613ac65760051b81013590605e198136030182121561073e570190565b60005b8381106146975750505050565b6146a56107dd828686614665565b90602091826146b5838888614665565b0135906146c3838888614665565b916040928381013590601e198136030182121561073e5701918235926001600160401b03841161073e57860191833603831361073e576001600160a01b03821680156147a057600052600180975260ff856000205416156147885783809360008481959461473283968e6147b8565b8015614781575b89519889948537f1916101003d103d15151683191661477857018092521561476257500161468a565b63b88beff960e01b815260146004820152602490fd5b3d6000823e3d90fd5b505a614739565b845163b88beff960e01b8152600a6004820152602490fd5b855163b88beff960e01b815260106004820152602490fd5b9060018060a01b0360405190636eb1769f60e11b82523060048301528181841691826024830152816044602095869389165afa80156108b4576000906148f2575b6001600160801b0391501061480e5750505050565b61481883856152f1565b613e40576148268385615373565b613e4057600080916040518481019163095ea7b360e01b8352602482015282604482015260448152614857816135b8565b519082875af190614866614e6e565b826148b8575b50501561073e5761487d81836152f1565b1561488a575b8080613e40565b61489391615373565b1561489f573880614883565b60405163b88beff960e01b815260096004820152602490fd5b80919250519182159283156148d2575b505050388061486c565b8293509181928101031261073e576148ea910161520a565b3880806148c8565b508281813d831161491f575b61490881836135d3565b8101031261073e576001600160801b0390516147f9565b503d6148fe565b6040519061010082018281106001600160401b038211176116bc576040528160e06000918281528260208201528260408201528260608201528260808201528260a08201528260c08201520152565b8051821015613ac65760209160051b010190565b8054821015613ac65760005260206000209060011b0190600090565b604051906149b28261351d565b8160c06000918281528260208201528260408201528260608201528260808201528260a08201520152565b9081516149e981613629565b906040906149fa60405193846135d3565b808352614a09601f1991613629565b0160005b818110614aa85750508160005b8551811015614aa15780614a6f614a3360019389614975565b51806080614a41858a614975565b510152806000526020600c8152614a688760002091614a60868b614975565b510191613667565b9052614d31565b90614a7a8489614975565b519187614a87868b614975565b5101906060614a96878c614975565b510152525201614a1a565b5093505050565b6020908351614ab68161354b565b614abe6149a5565b81526060600084918083850152818885015283015260006080830152828701015201614a0d565b90614af891614af261380b565b50615217565b905060808101614b088151614ce2565b905290565b919063337f980090614b1f81856157de565b9309614b2757565b9060001981101561073e5760010190565b919061271090614b1f818561583e565b929190614b5682828661589c565b938215614b645709614b2757565b634e487b7160e01b600052601260045260246000fd5b929092600092600094600381019081549660058201928184549460068501805460019c60018e9a0198828a5491614bb0936145dd565b948592911315614bbf906143e8565b0390556002850180546001600160a01b0394919385938493929091614be591851661462c565b985490555495600101541691541611614bfc614926565b91878452602091600c60205260409560408620614c1890613667565b869d5b614c60575b505050505050505050507fd3ab9a69ac1632a6447fe8ed278bf0868cb4e8b70c9f0630769bb07b5abe513c919293506040908151908152846020820152a1565b8d81511115614cdd57614c738e82614975565b5184614c81878301516153b4565b169081614c95575b50509c89019c89614c1b565b908b9c9d9e614ca6898e948861547f565b614cb6858d60e08c01519061589c565b918a52600488528a8a208760a08b0151168b5288528a8a20828154019055019d9c9b614c89565b614c20565b80614ced5750600a90565b6103e98114614cf95790565b50600090565b90614d0982613629565b614d1660405191826135d3565b8281528092614d27601f1991613629565b0190602036910137565b614d396149a5565b50600090600052600d60205260406000209060405192614d588461351d565b60018060a01b0393848454168152614dd0856001860154169586602084015260028601541694856040840152614dbd6003820154966060850197885260048301546080860152600660058401549360a0870194855201549460c0810195865298614ae5565b92865191519051906020850151926145dd565b5090819460008313614de157505050565b614dff929394506040670de0b6b3a764000091519201510290614b0d565b908115614b645704908115614e1057565b60019150565b6000546001600160a01b03163303614e2a57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b3d15614e99573d90614e7f826136bd565b91614e8d60405193846135d3565b82523d6000602084013e565b606090565b600160ff1b811461286f5760000390565b6020810162ffffff808251161561508e576040928381019260018060a01b038085511693606084019282614eef8186511697888110988585511691613977565b8651911692901561506757608086015190600160ff1b82101561073e5789958580600094935b8b861461504c576401000276a4965b51169b51169151169087519a60208c0152878b015260608a015260608952614f4b896135b8565b614f898651998a9687958694630251596160e31b86523060048701528c6024870152604486015216606484015260a0608484015260a4830190613aea565b03925af1938415615042576000938495615008575b50815115614fbc57505015614fb557505b60000390565b9050614faf565b90949390929115614ff657614fd2608091614e9e565b915b94015111614fdf5750565b5163b88beff960e01b815260156004820152602490fd5b90615002608091614e9e565b91614fd4565b939080955084813d831161503b575b61502181836135d3565b810103126150385750602083519301519338614f9e565b80fd5b503d615017565b513d6000823e3d90fd5b73fffd8963efd1fc6a506488495d951d5263988d2596614f24565b608086015190600160ff1b82101561073e5789958580615088600095614e9e565b93614f15565b60405163b88beff960e01b815260116004820152602490fd5b51906001600160801b038216820361073e57565b90916020820191825160409485519160c083018381106001600160401b038211176116bc57875282526020820190815281860193845260006060808401828152608085018381524260a087019081528a5163219f5d1760e01b815296516004880152945160248701529651604486015251606485015294516084840152905160a4830152928160c481867f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af19283156151ff5780936151c0575b50506001600160801b038091511691169181831061519d5750505050565b606494505192519263a0f2e85960e01b8452600484015260248301526044820152fd5b909192506060823d6060116151f7575b816151dd606093836135d3565b8101031261503857506151ef906150a7565b90388061517f565b3d91506151d0565b8551903d90823e3d90fd5b5190811515820361073e57565b61521f61380b565b506040519060208201926001600160601b0319809260601b16845260601b166034820152602881526152508161359d565b5190209081600052600a60205260406000209060405161526f8161354b565b63ffffffff80845416936001810154826020850192828452600281015497604087019189835260046003820154918260608b0152015460808901528799156152e8575b6152c2575b505050505042169052565b6201518092670de0b6b3a7640000925191814216031602020401905238808281806152b7565b601e83526152b2565b60405163095ea7b360e01b602082019081526001600160a01b03909316602482015260001960448083019190915281526000928392918390615332816135b8565b51925af161533e614e6e565b81615347575090565b805180159250821561535857505090565b819250906020918101031261073e576020613a91910161520a565b60405163095ea7b360e01b602082019081526001600160a01b03909316602482015260011960448083019190915281526000928392918390615332816135b8565b90600091600080806040519360208501906331a9108f60e11b82526024860152602485526153e18561359d565b93516001600160a01b03947f000000000000000000000000000000000000000000000000000000000000000086165afa615419614e6e565b9080615451575b61542957505050565b909192935060208180518101031261544d5760200151918216809203615038575090565b5080fd5b50602081511015615420565b51906001600160a01b038216820361073e57565b51908160020b820361073e57565b602082015160405163133f757160e31b815260048101919091529392916001600160a01b03916101809182876024817f000000000000000000000000000000000000000000000000000000000000000088165afa9081156108b457600097889089968a978b928c988d976155cc575b505091899a9b82808c999896948a989660808a019560a08b019d6001600160801b03809b1660608d015260020b6020819c015260020b809c5262ffffff809e169e8f90604001521694858c5216918284521660c08d0152861598612774996155c1575b505050505116916000146155a65761556e6113e361557494615929565b90615d00565b925b0181811161286f5781169182620f42400382811161286f5760e0936155a1936141e592169083614b48565b910152565b6155b56113e36155bb94615929565b90615d52565b92615576565b525238808080615551565b959950975050999350505083813d83116156a4575b6155eb81836135d3565b810103126150385782516001600160601b03811603615038576156106020840161545d565b9361561d6040850161545d565b6156296060860161545d565b9860808601519362ffffff8516850361503857509187989986899695938580899761565660a08601615471565b9c61568a61016061567560e061566e60c08b01615471565b99016150a7565b9e61568361014082016150a7565b50016150a7565b509395979c949b999a5050939592949650819d9c506154ee565b503d6155e1565b8181029190600019828209918380841093039183830393600160601b938585111561073e57146156e8570990828211900360a01b910360601c1790565b5050505060601c90565b9081600a029060001983600a099282808510940393808503948584111561073e571461576b578190600a0981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b5091500490565b9080820290600019818409908280831092039082820392670de0b6b3a7640000928484111561073e57146157d6577faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac10669940990828211900360ee1b910360121c170290565b509250500490565b908082029060001981840990828083109203908282039263337f9800928484111561073e57146157d6577fc5df62d97a91e61f2cac50459aa56a00fdd543b3a40ecf0789397887f0eac13b940990828211900360f51b9103600b1c170290565b9080820290600019818409908280831092039082820392612710928484111561073e57146157d6577fbc01a36e2eb1c432ca57a786c226809d495182a9930be0ded288ce703afb7e91940990828211900360fc1b910360041c170290565b91818302916000198185099383808610950394808603958685111561073e5714615912579082910981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b505091500490565b519061ffff8216820361073e57565b60020b6000811215615c945780600003905b620d89e88211615c82576001821615615c70576001600160881b036ffffcb933bd6fad37aa2d162d1a5940015b169160028116615c54575b60048116615c38575b60088116615c1c575b60108116615c00575b60208116615be4575b60408116615bc8575b608090818116615bad575b6101008116615b92575b6102008116615b77575b6104008116615b5c575b6108008116615b41575b6110008116615b26575b6120008116615b0b575b6140008116615af0575b6180008116615ad5575b620100008116615aba575b620200008116615aa0575b620400008116615a86575b6208000016615a6b575b50600012615a5c575b63ffffffff8116615a54576000905b60201c60ff91909116016001600160a01b031690565b600190615a3e565b8015614b645760001904615a2f565b6b048a170391f7dc42444e8fa26000929302901c9190615a26565b6d2216e584f5fa1ea926041bedfe98909302811c92615a1c565b926e5d6af8dedb81196699c329225ee60402811c92615a11565b926f09aa508b5b7a84e1c677de54f3e99bc902811c92615a06565b926f31be135f97d08fd981231505542fcfa602811c926159fb565b926f70d869a156d2a1b890bb3df62baf32f702811c926159f1565b926fa9f746462d870fdf8a65dc1f90e061e502811c926159e7565b926fd097f3bdfd2022b8845ad8f792aa582502811c926159dd565b926fe7159475a2c29b7443b29c7fa6e889d902811c926159d3565b926ff3392b0822b70005940c7a398e4b70f302811c926159c9565b926ff987a7253ac413176f2b074cf7815e5402811c926159bf565b926ffcbe86c7900a88aedcffc83b479aa3a402811c926159b5565b926ffe5dee046a99a2a811c461f1969c305302811c926159ab565b916fff2ea16466c96a3843ec78b326b528610260801c916159a0565b916fff973b41fa98c081472e6896dfb254c00260801c91615997565b916fffcb9843d60f6159c9db58835c9266440260801c9161598e565b916fffe5caca7e10e4e61c3624eaa0941cd00260801c91615985565b916ffff2e50f5f656932ef12357cf3c7fdcc0260801c9161597c565b916ffff97272373d413259a46990580e213a0260801c91615973565b6001600160881b03600160801b615968565b6040516333a3bdff60e21b8152600490fd5b8061593b565b60405160208101906370a0823160e01b825230602482015260248152615cbf8161359d565b6000928392839251915afa90615cd3614e6e565b9180615cf4575b156150385760208280518101031261503857506020015190565b50602082511015615cda565b6001600160801b03916001600160a01b03919082811683831611615d4c575b03169116615d2d82826156ab565b91600160601b9109615d3c5790565b60001981101561073e5760010190565b90615d1f565b613a9192906001600160a01b039083821682821611615d8e575b906001600160801b0391615d848286168383166156ab565b9403169116614b48565b92615d6c565b8054821015613ac65760005260206000200190600090565b90600182019060009281845282602052604084205490811515600014615eac5760001991808301818111615e9857825490848201918211615e8457808203615e38575b50505080548015615e2457820191615e078383615d94565b909182549160031b1b191690555582526020526040812055600190565b634e487b7160e01b86526031600452602486fd5b615e6f615e48615e589386615d94565b90549060031b1c92839286615d94565b819391549060031b91821b91600019901b19161790565b90558652846020526040862055388080615def565b634e487b7160e01b88526011600452602488fd5b634e487b7160e01b87526011600452602487fd5b5050505090565b919082604091031261073e576020825192015190565b91906001830160009082825280602052604082205415600014615f3157845494600160401b861015615f1d5783615f0d615e58886001604098999a01855584615d94565b9055549382526020522055600190565b634e487b7160e01b83526041600452602483fd5b5092505056fea264697066735822122001ba995590e15d2d41df360631a1c847555e2253f1590c8991d82589114820bc64736f6c6343000817003360a0346100ac57601f610a2638819003918201601f19168301916001600160401b038311848410176100b1578084926020946040528339810103126100ac575162ffffff811681036100ac5760008054336001600160a01b0319821681178355604051939290916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09080a360805261095e90816100c88239608051816104d30152f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe60406080815260048036101561001457600080fd5b600091823560e01c9182632d2ae1c1146105465782634b8e29731461050857826357969c88146102b8578263715018a61461025e5782638da5cb5b14610232578263bfa1a890146101a6578263f2fde38b146100d457505063f5537ede1461007b57600080fd5b346100d15760603660031901126100d157610094610672565b6024356001600160a01b03811681036100cc57604435906100b361078f565b816100bc578380f35b6100c5926107e7565b3880808380f35b600080fd5b80fd5b909150346101a25760203660031901126101a2576100f0610672565b906100f961078f565b6001600160a01b03918216928315610150575050600054826bffffffffffffffffffffffff60a01b821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a380f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b8280fd5b9150346101a257806003193601126101a2576101c0610672565b6024359262ffffff841680940361022e576101d961078f565b612710841161020557506001600160a01b0316835260016020528220805462ffffff1916909117905580f35b60649083519062461bcd60e51b8252602081830152602482015263562d464560e01b6044820152fd5b8480fd5b83823461025a578160031936011261025a57905490516001600160a01b039091168152602090f35b5080fd5b83346100d157806003193601126100d15761027761078f565b600080546001600160a01b0319811682556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b909150346101a25760603660031901126101a2576102d4610672565b60249182356044359367ffffffffffffffff92838611610504573660238701121561050457858101359284841161050057368385890101116105005761031861078f565b809661032387610718565b9182106104f7575b89958a8915159687610449575b333b1561025a5760848b828b938f8b9051988996879563d623439360e01b87528d870152828601526060604486015282606486015201848401378181018301859052601f01601f1916810103018183335af1801561043f5761041a575b50506103a086610718565b106103f25750506103af578480f35b836060937fd484ef0f7d7628a59a68ac61d0f72688997f1e503c87fe122563d259dbba68e795519360018060a01b031684526020840152820152a1388080808480f35b865162461bcd60e51b81526020828201529182015263158b519360e21b604482015260649150fd5b819a929a1161042d578852973880610395565b50634e487b7160e01b81526041909152fd5b8a513d8d823e3d90fd5b6001600160a01b038a168d5260016020528b8d20549498509362ffffff9150811680156104d0575b1696620f4240610481898c6108c1565b988b096104b8575b876104958b338c6107e7565b81018091116104a6578b9093610338565b634e487b7160e01b8c5260118552858cfd5b966000198110156104cc5760010196610489565b8b80fd5b507f0000000000000000000000000000000000000000000000000000000000000000610471565b9650809661032b565b8880fd5b8780fd5b83823461025a57602036600319011261025a5760209162ffffff9082906001600160a01b03610535610672565b168152600185522054169051908152f35b83346100d15760208060031936011261025a5782359167ffffffffffffffff80841161025a573660238501121561025a578385013590811161025a576024906005953660248360051b8801011161066e576105a6829897969495986106c0565b936105b388519586610688565b8285526105bf836106c0565b858a019790601f1901368937865b8481106106155750505050505083519485948186019282875251809352850193925b8281106105fe57505050500390f35b8351855286955093810193928101926001016105ef565b989997989597969580821b8381018701356001600160a01b03811681036105005761063f90610718565b908a5183101561065c578a018901529699989795966001016105cd565b634e487b7160e01b8952603286528789fd5b8380fd5b600435906001600160a01b03821682036100cc57565b90601f8019910116810190811067ffffffffffffffff8211176106aa57604052565b634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff81116106aa5760051b60200190565b3d15610713573d9067ffffffffffffffff82116106aa5760405191610707601f8201601f191660200184610688565b82523d6000602084013e565b606090565b60405160208101906370a0823160e01b8252306024820152602481526060810181811067ffffffffffffffff8211176106aa576040526000928392839251915afa906107626106d8565b9180610783575b156100d1576020828051810103126100d157506020015190565b50602082511015610769565b6000546001600160a01b031633036107a357565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b60405163a9059cbb60e01b602082019081526001600160a01b039093166024820152604480820194909452928352916080810167ffffffffffffffff8111828210176106aa57604052600092839283809351925af1906108456106d8565b9082610880575b50501561085557565b606460405162461bcd60e51b815260206004820152600460248201526315cb54d560e21b6044820152fd5b908092505191821592831561089a575b505050388061084c565b81929350906020918101031261025a57602001519081151582036100d15750388080610890565b9080820290600019818409908280831092039082820392620f424092848411156100cc5714610920577fde8f6cefed634549b62c77574f722e1ac57e23f24d8fd5cb790fb65668c26139940990828211900360fa1b910360061c170290565b50925050049056fea2646970667358221220358c986140634f9ebc7a8ddd405fc318fb12b6581496ea718f8ac8798111436164736f6c6343000817003300000000000000000000000077dcc9b09c6ae94cdc726540735682a38e18d690000000000000000000000000259308e7d8557e4ba192de1ab8cf7e0e21896442000000000000000000000000c49c177736107fd8351ed6564136b9adbe5b1ec300000000000000000000000056cfc796bc88c9c7e1b38c2b0af9b7120b079aef30146866f3a846fe3c636beb2756dbd24cf321bc52c9113c837c21f47470dfeb
Deployed Bytecode
0x610100604052600436101561001357600080fd5b600060a05260a0513560e01c806301777e961461312e57806309e3d369146123175780630d4aa914146122955780631291f2d6146122505780632bfcb42a146121cb5780632d6913631461215a5780632de3b8d7146121305780632f59e85a146120c457806339afeff414611fc45780634555b94714611f835780634960b29d14611f105780634b7dd768146111ca57806352ee2671146111a057806353b744201461117157806355ecf5a814611122578063570ca735146110f85780635d689b6f146110635780636c8edaca1461102c578063715018a614610fce5780637775422e14610f4557806382a9440214610ebf57806383719c6514610e79578063873c7ef514610d385780638c804b2814610cfc5780638da5cb5b14610cd15780639092c31c14610c8b578063a0b014a814610940578063a4841bcf146108c0578063ade9712a14610743578063ae6e34661461063e578063b58b18d7146105c3578063bb9e8ef01461057d578063c24c9b8f146104ce578063d623439314610443578063e81a893914610424578063f2fde38b1461035c578063f4c5ef6d146102da578063fa461e33146101f55763fe9507ec146101d057600080fd5b346101ef5760a0513660031901126101ef576020600754604051908152f35b60a05180fd5b346101ef5760603660031901126101ef576004356024356044356001600160401b0381116101ef5761022b9036906004016134e3565b92909160a0518213938415806102ce575b6102b55783606091810103126101ef576102a79361029661025c856133e3565b9461028d610278604061027160208501613268565b9301613268565b6001600160a01b039283169790831688613977565b163314156143c9565b156102ad5750905b33903090614406565b60a05180f35b90509061029e565b60405163b88beff960e01b8152600b6004820152602490fd5b5060a05182131561023c565b346101ef576020806003193601126101ef5760043560a05152600e602052604060a051209060405190816020845491828152019360a05152602060a051209160a051905b8282106103455761034185610335818903826135d3565b6040519182918261349a565b0390f35b83548652948501946001938401939091019061031e565b346101ef5760203660031901126101ef5761037561323c565b61037d614e16565b6001600160a01b039081169081156103d057600054826001600160601b0360a01b821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a360a05180f35b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b346101ef5760a0513660031901126101ef576020600854604051908152f35b346101ef5760603660031901126101ef576044356001600160401b0381116101ef576104766102a79136906004016134e3565b9061049660018060a01b03806002541633141590816104a1575b506143c9565b602435600435613c79565b90507f000000000000000000000000fb3efa944e81260d316bcb2f589f12f2727641321633141585610490565b346101ef576104dc366133ae565b916104f360018060a01b03600654163314156143c9565b6103e983116105645761055b837f3e5945033f29e2143d79669b9b4968fbf6d998878c579e907f1cbef4fd8fb11794600461052e868661459e565b905001556040519384938460409194939294606082019560018060a01b0380921683521660208201520152565b0390a160a05180f35b604051636bd62feb60e11b815260048101849052602490fd5b346101ef5760a0513660031901126101ef576040517f00000000000000000000000077dcc9b09c6ae94cdc726540735682a38e18d6906001600160a01b03168152602090f35b346101ef5760203660031901126101ef5760043560a05152600d60205260e0604060a0512060018060a01b038082541691816001820154169160028201541660038201546004830154916006600585015494015494604051968752602087015260408601526060850152608084015260a083015260c0820152f35b346101ef5760403660031901126101ef5761065761323c565b60243580151580910361073e577f2ba7a606df56ff43c0a75a37d64019d91adf54eda72f67c6a457189a4a7d943891604091610691614e16565b6001600160a01b03918216916106db907f000000000000000000000000fb3efa944e81260d316bcb2f589f12f27276413281168414908115610734575b8115610708575b506143e8565b8160a0515260016020528260a0512060ff1981541660ff831617905582519182526020820152a160a05180f35b90507f00000000000000000000000077dcc9b09c6ae94cdc726540735682a38e18d690168314866106d5565b30851491506106ce565b600080fd5b346101ef576020806003193601126101ef576004356001600160401b0381116101ef576107749036906004016133f3565b903360a051526004602052604060a051209261078f83614cff565b9360005b8481106107cf5750505061055b7f54217ca99866ba075643d5ee9eccf9ed28c2f0099ebe01b821d121b5ec3c8e9f936040519384933385613a47565b6107e26107dd828787613ab6565b613836565b6001600160a01b038082166000908152848652604090208054670de0b6b3a76400009004939291908461081d575b5050506001915001610793565b600090558361082c848b614975565b527f000000000000000000000000fb3efa944e81260d316bcb2f589f12f2727641321692833b1561073e57604051637aa9bf6f60e11b81526001600160a01b039290921660048301523360248301526044820152916000908390606490829084905af19182156108b4576001926108a5575b8080610810565b6108ae90613538565b8761089e565b6040513d6000823e3d90fd5b346101ef576020806003193601126101ef576001600160a01b036108e261323c565b1660a05152600f602052604060a051209060405190816020845491828152019360a05152602060a051209160a051905b8282106109295761034185610335818903826135d3565b835486529485019460019384019390910190610912565b346101ef5760403660031901126101ef5760043560078110156101ef57602480356001600160401b0381116101ef5761097d9036906004016133f3565b92610986614e16565b60009260038203610af157600385036101ef578460011015610adb5760208301356103e88111610ac6578560021015610aaf5760408401358015610a9657604051916109d183613566565b8252602082019081528615610a7f5760a080516001600160a01b0387351690526009602052516040902091518255516001909101555b60405193610a695750825260406020830181905282018390526001600160fb1b0383116101ef57816060917f95d8e1d07c148ab8a26430cf05958b3aeecebe03ec33919e180e1bba835bfccc9460051b8091848401378101030190a160a05180f35b60a08051634e487b7160e01b9052602160045251fd5b82634e487b7160e01b60a05152603260045260a051fd5b604051636bd62feb60e11b815260a05160048201528390fd5b5060a08051634e487b7160e01b9052603260045251fd5b60405190636bd62feb60e11b82526004820152fd5b60a08051634e487b7160e01b9052603260045251fd5b60068203610ba957600285036101ef576001600160a01b037f000000000000000000000000fb3efa944e81260d316bcb2f589f12f27276413281168615610a7f578660011015610a7f57803b156101ef5760405191630bfa1a8960e41b8352853516600483015262ffffff602086013516838301528160448160a0519360a051905af18015610b9c57610b86575b505b610a07565b610b8f90613538565b60a0516101ef5785610b7f565b6040513d60a051823e3d90fd5b9250600184036101ef5760009281610bd4578415610adb5782356107d08111610ac657600755610a07565b60018203610bf5578415610adb5782356103e88111610ac657600855610a07565b6000935060028203610c28578415610adb57600680546001600160a01b03191684356001600160a01b0316179055610a07565b60048203610c57578415610adb57600280546001600160a01b03191684356001600160a01b0316179055610a07565b600093506004198201610b81578415610adb57600380546001600160a01b03191684356001600160a01b0316179055610a07565b346101ef5760a0513660031901126101ef576040517f000000000000000000000000fb3efa944e81260d316bcb2f589f12f2727641326001600160a01b03168152602090f35b346101ef5760a0513660031901126101ef5760a051546040516001600160a01b039091168152602090f35b346101ef5760a0513660031901126101ef5760206040517f30146866f3a846fe3c636beb2756dbd24cf321bc52c9113c837c21f47470dfeb8152f35b346101ef57610d4636613457565b610d4e614e16565b610d5781614cff565b9060005b818110610d9657507fcace23d1ed8c8a9e74d77b41c1418438aa1e682092d5019be401b54ae82c11ad939161055b9160405194859485613a47565b610da46107dd828487613ab6565b6001600160a01b0380821660009081526005602052604090208054670de0b6b3a764000090049392919084610de1575b5050506001915001610d5b565b6000905583610df08488614975565b527f000000000000000000000000fb3efa944e81260d316bcb2f589f12f2727641321692833b1561073e57604051637aa9bf6f60e11b81526001600160a01b03928316600482015291881660248301526044820152916000908390606490829084905af19182156108b457600192610e6a575b8080610dd4565b610e7390613538565b86610e63565b346101ef5760a0513660031901126101ef576040517f00000000000000000000000056cfc796bc88c9c7e1b38c2b0af9b7120b079aef6001600160a01b03168152602090f35b346101ef57610ecd36613457565b919060018060a01b0380921660a0515260206004602052604060a0512090610ef485614cff565b9360005b868110610f15576040516020808252819061034190820189613423565b8082610f276107dd6001948b8a613ab6565b16600052848452604060002054610f3e8289614975565b5201610ef8565b346101ef576020806003193601126101ef5760043560a05152600c8152610f70604060a05120613667565b604051908282018383528151809152836040840192019360a0515b828110610f985784840385f35b90919282604082610fbf6001948a51602080916001600160801b0381511684520151910152565b01960191019492919094610f8b565b346101ef5760a0513660031901126101ef57610fe8614e16565b600080546001600160a01b0319811682556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a360a05180f35b346101ef5760203660031901126101ef57604061104a600435614d31565b909150670de0b6b3a76400008351920582526020820152f35b346101ef576020806003193601126101ef576004356001600160401b0381116101ef576110949036906004016133f3565b909161109f82614cff565b9260005b8381106110c0576040516020808252819061034190820188613423565b6001906001600160a01b036110d96107dd838887613ab6565b16600052600584526040600020546110f18288614975565b52016110a3565b346101ef5760a0513660031901126101ef576006546040516001600160a01b039091168152602090f35b346101ef5760603660031901126101ef5761113b61323c565b611143613252565b9060443562ffffff8116810361073e5760209261115f92613977565b6040516001600160a01b039091168152f35b346101ef5760403660031901126101ef57602061119861118f61323c565b60243590613915565b604051908152f35b346101ef5760a0513660031901126101ef576003546040516001600160a01b039091168152602090f35b346101ef576003196040368201126101ef576001600160401b03600435116101ef5761010090600435360301126101ef57611203614335565b611210602435421161438b565b61121861380b565b60805261124061122c602460043501613836565b61123a604460043501613836565b9061459e565b90604060805101526112556004820154614ce2565b60c052611266602460043501613836565b611274604460043501613836565b906040519060208201923360601b84526001600160601b0319809260601b16603484015260601b166048820152603c81526112ae8161359d565b519020608051526112c3602460043501613836565b6001600160a01b036112d9600435604401613836565b166001600160a01b0390911610906112f5600435602401613836565b611303604460043501613836565b60075461132461131d60e46004350160043560040161384a565b36916138b8565b60a0519586949193859291611337614926565b60a051979096905b8151891015611853576113528983614975565b5160e0526113638860e0518561547f565b60c0880151306001600160a01b039091160361183557611388602060e05101516153b4565b60808901516001600160a01b0387811691161480159061181b575b801561180a575b6117ec57885160029060208b0151820b906000198201627fffff1992627fffff8213848312176117c9576113e96113e361142a93615929565b91615929565b80826001600160a01b03808316908216116117e1575b5061141890506001600160a01b038281169084166156ab565b9190036001600160a01b0316906156f2565b92836001600160801b0381160361073e5761144682820b615929565b92627fffff83830b6001019081139113176117c957611469916001910b01615929565b9081816001600160a01b03808316908216116117be575b505090036001600160a01b0316801561073e57600560611b04906001600160801b03821691820361073e576001600160801b0381168210156117b8576001600160801b039150165b6001600160801b0360e05151166001600160801b0360608c0151169182821180156117a6575b61176c5750505060c0516116f3575b5060e08801510197602060e0510151906001600160801b0360e0515116604051906115278261354b565b838252602082019081526040820160a0518152606083019060a05182526001600160801b03608085019342855260405195630624e65f60e11b87525160048701525116602485015251604484015251606483015251608482015260408160a48160a05160018060a01b037f00000000000000000000000077dcc9b09c6ae94cdc726540735682a38e18d690165af18015610b9c5760a0519182916116d2575b50604051938460808101106001600160401b036080870111176116bc5760808501604090815290855230602086019081526001600160801b0393841682870190815292841660608701908152825163fc6f786560e01b81529651600488015290516001600160a01b03908116602488015292518416604487015251909216606485015260a051849160849183917f00000000000000000000000077dcc9b09c6ae94cdc726540735682a38e18d690165af1918215610b9c5760019261168e575b50019761133f565b6116af9060403d6040116116b5575b6116a781836135d3565b810190615eb3565b50611686565b503d61169d565b634e487b7160e01b600052604160045260246000fd5b90506116ed915060403d6040116116b5576116a781836135d3565b8e6115c6565b9a9561170560c05160e08b0151614b38565b80910196612710670de0b6b3a76400008a84020204019b60018060a01b031660a051526004602052604060a0512060018060a01b0360a08b015116600052602052604060002090670de0b6b3a7640000612710818b8402020491020381540190558b6114fd565b608493506001600160801b0390602060e0510151936040519463198c2b6f60e21b8652600486015260248501521660448301526064820152fd5b506001600160801b03811682106114ee565b506114c8565b925090508f80611480565b634e487b7160e01b60a051526011600452602460a051fd5b9150915038806113ff565b6024602060e051015160405190633c129e7d60e21b82526004820152fd5b506001600160a01b038116156113aa565b5060a08901516001600160a01b03868116911614156113a3565b6024602060e0510151604051906319db8bf560e21b82526004820152fd5b8a8a918760206080510152806060608051015215611ef7576001600160a01b03611881600435604401613836565b1660a051526005602052604060a0512090815401905560c4600435016118ac816004356004016135f4565b9050611eca575b506118c2602460043501613836565b6118e26118dc6118d6604460043501613836565b92615c9a565b91615c9a565b60808051015280611e0c575b506080805101516064600435013590818110611dee57826080515160a05152600d602052604060a0512090611927602460043501613836565b611935604460043501613836565b9060a460043501356040608051015111611dd557611960606060805101516040608051015190614b38565b60805160400152600384015415611d8b575050815461198a906001600160a01b03163314156143aa565b611998818360805151614b7a565b505b6119b06003606060805101519201918254613510565b908190556001600160a01b0310611d725760a051608080519081015160609091015180821115611d485750506119f260808051015160606080510151906137fe565b670de0b6b3a764000081818102048114821517156117c957611a3d906001600160a01b03611a24600435604401613836565b1660a051526005602052604060a0512092028254613510565b90555b6080515191611a5c61131d60e46004350160043560040161384a565b60a08051859052600c602052516040812092905b8251811015611bad57611a838184614975565b5190602082015160a05152600e602052611aa287604060a05120615ec9565b15611b29578454600160401b811015611b1157611ac6600191828101885587614989565b919091611af8576020846001600160801b0360019651166001600160801b031985541617845501519101555b01611a70565b634e487b7160e01b60a0515260a051600452602460a051fd5b634e487b7160e01b60a051526041600452602460a051fd5b93949095919260a0515060a0515b8654811015611b9e576001611b4c8289614989565b500154602089015114611b6157600101611b37565b96600192969591949397611b816001600160801b03809351169188614989565b50918254918183160116906001600160801b031916179055611af2565b50929195509392600190611af2565b8582866007875411611d2f57611bd260a09333855152600f6020526040855120615ec9565b50611c92611bf4611be7604460043501613836565b6060608051015190613915565b92606060805101516003820154016003820155600481018481540190556006604060805101519101670de0b6b3a76400008202815401905560206080510151908484010101611c75611c4a604460043501613836565b917f000000000000000000000000fb3efa944e81260d316bcb2f589f12f27276413280933390614406565b611c83604460043501613836565b90608080510151913090614406565b7fb3f3f47c10633b93eb42b0a7467190b3f64baf0e6364f9b6821bab84d506dc1460e0608051516060608051015160406080510151602060805101519160405193338552602085015260408401528560608401528660808401528783015260c0820152a16060608051015191604060805101519060206080510151926001600b556040519485526020850152604084015260608301526080820152f35b60405163b88beff960e01b815260066004820152602490fd5b03905060043560840135811115611a405760405163b88beff960e01b815260026004820152602490fd5b60405163b88beff960e01b815260186004820152602490fd5b83546001600160a01b0319908116331785556001808601805483166001600160a01b039485161790556002860180549092169390921692909217909155810154600583015561199a565b60405163b88beff960e01b8152600e6004820152602490fd5b6044925060405191631cc0106b60e21b835260048301526024820152fd5b600435600401359062ffffff821682036101ef57611e8b91611e8091611e36602460043501613836565b611e44604460043501613836565b9062ffffff60405194611e568661354b565b600186521660208501526001600160a01b0390811660408501521660608301526080820152614eaf565b608080510151613510565b608080510152611ea7611ea2602460043501613836565b615c9a565b611eb157816118ee565b60405163b88beff960e01b8152600d6004820152602490fd5b611ef190611eeb611edf602460043501613836565b916004356004016135f4565b91614687565b816118b3565b60405163b88beff960e01b815260076004820152602490fd5b346101ef5760203660031901126101ef576020611f76600435611f31614335565b8060a05152600d8352604060a05120611f4e6003820154156143aa565b60018101546002820154611f6e916001600160a01b03918216911661459e565b929050614b7a565b6001600b55604051908152f35b346101ef5760203660031901126101ef576001600160a01b03611fa461323c565b1660a051526001602052602060ff604060a0512054166040519015158152f35b346101ef5760403660031901126101ef5760243560a0515060a05160043560a05152600d602052604060a05120604051611ffd8161351d565b60018060a01b0380835416825280600184015416908160208401526002840154169182604082015260038401549060c06006606083019684885260048101546080850152600581015460a08501520154910152612060575b602084604051908152f35b61208892935060409161207291614ae5565b01519151670de0b6b3a764000080930290614b0d565b916120938184615772565b92096120b2575b80156120aa575b80828080612055565b5060016120a1565b60001981101561073e5760010161209a565b346101ef5760403660031901126101ef5760a06120f96120e261323c565b6120ea613252565b906120f361380b565b50614ae5565b60806040519163ffffffff815116835260208101516020840152604081015160408401526060810151606084015201516080820152f35b346101ef5760a0513660031901126101ef576002546040516001600160a01b039091168152602090f35b346101ef57612168366133ae565b9161217f60018060a01b03600654163314156143c9565b612710831180156121c1575b6105645761055b837fe25bc35d32d39a14e740b4d2ffafc3a63704f9cdc1d79b8691c41eb1cc7dc5b894600261052e868661459e565b506005831061218b565b346101ef576020806003193601126101ef5760043560a05152600e602052604060a0512060405191826020835491828152019260a05152602060a051209160a051905b8282106122395761034161222d87612228818903826135d3565b6149dd565b6040519182918261327c565b83548552938401936001938401939091019061220e565b346101ef5760203660031901126101ef576001600160a01b0361227161323c565b1660a05152600960205260408060a051206001815491015482519182526020820152f35b346101ef576020806003193601126101ef576001600160a01b036122b761323c565b1660a05152600f602052604060a0512060405191826020835491828152019260a05152602060a051209160a051905b8282106123005761034161222d87612228818903826135d3565b8354855293840193600193840193909101906122e6565b346101ef576003196040368201126101ef576001600160401b03600435116101ef5760c090600435360301126101ef5761234f614335565b61235c602435421161438b565b60a08051600435606401358152600d60205290516040908190209051906123dd906123868361351d565b80546001600160a01b039081168452600182015481166020850152600282015416604084015260038101546060840181905260048201546080850152600582015460a085015260069091015460c0840152156143aa565b6020810151604082015160808301516001600160a01b03928316939290911690612407828561459e565b90506124266001820154606086015160a087015160c0880151916145dd565b9490949260a05186129560018060a01b0383511633141580613126575b61244c906143c9565b60a05181131561311757670de0b6b3a7640000900401945b6004356004013580151581036101ef57156128d15761248390156143e8565b606081015160a0519095909485612498614926565b936064600435013560a05152600c602052604060a051209560a0515060a051925b875480851015612603576124d66124d0868b614989565b50613640565b903360018060a01b036124ec60208501516153b4565b16036125f65760001981019081116117c957612508908a614989565b50612513868b614989565b919091611af8578082036125cc575b5050885480156125b45761253a60001982018b614989565b92909261259e57878f8b9360006001878261258299550155600019018d55602083015160a05152600e60205261257b60646004350135604060a05120615dac565b501061547f565b6125958b60e0890151809c019b8b61589c565b019b5b9b6124b9565b634e487b7160e01b600052600060045260246000fd5b634e487b7160e01b60a051526031600452602460a051fd5b6001816001600160801b03829354166001600160801b031985541617845501549101558e80612522565b50509b9260010192612598565b5096955099509997505050925054159083156128b857670de0b6b3a76400006126616003926126368760608c01516137fe565b60608b01526126498160c08c01516137fe565b60c08b015260408a01516001600160a01b031661462c565b0495018381540390556000146128855784516001600160a01b03169360005b6060518110156126bc57806020608060019360051b01510151600052600e6020526126b5606460043501356040600020615dac565b5001612680565b5090919293600052600f6020526126dd606460043501356040600020615dac565b5060646004350135600052600d60205260006006604082208281558260018201558260028201558260038201558260048201558260058201550155600c60205260406000208054906000815581612835575b50509061273b91613510565b905b60408401519101906001600160a01b037f000000000000000000000000fb3efa944e81260d316bcb2f589f12f27276413281169116813b156101ef57604051637aa9bf6f60e11b815260a080516001600160a01b039390931660048301523360248301526044820185905251909283916064918391905af18015610b9c5761281f575b509151604080516001600160a01b039092168252336020830152600435606401358282015292907f7d5a4c3aa8690b61be4809a3878d586d548b08150b40170ba9488271c708208090606090a15b6001600b5582519182526020820152f35b61282890613538565b60a0516101ef57836127c0565b6001600160ff1b038216820361286f5760005260206000209060011b8101905b8181101561272f5760008082556001820155600201612855565b634e487b7160e01b600052601160045260246000fd5b506064600493929335013560a05152600d602052604060a0512060c085015160068201556003606086015191015561273d565b60405163b88beff960e01b815260016004820152602490fd5b509550906128f16129149160018060a09897981b0360408901511661462c565b9460036060880151930183815403905560018060a01b0360408801511692613510565b907f000000000000000000000000fb3efa944e81260d316bcb2f589f12f2727641326001600160a01b03163b156101ef57604051637aa9bf6f60e11b815260a080516001600160a01b03938416600484015230602484015260448301949094525190929183916064918391907f000000000000000000000000fb3efa944e81260d316bcb2f589f12f272764132165af18015610b9c57613108575b506044600435016129c5816004356004016135f4565b90506130e2575b506064600435013560a05152600c6020526129eb604060a05120613667565b6040850151909390612a42906001600160a01b037f00000000000000000000000077dcc9b09c6ae94cdc726540735682a38e18d690811691612a2f918391166147b8565b60208701516001600160a01b03166147b8565b6060850151916042196004353603016024600435013512156101ef5760405193612a6b8561354b565b10835260208301526040820152612a8c3660048035602481013501016136d8565b6060820152816080820152612a9f614926565b9260405190612aad82613566565b60a08051835280516020840152515b60808401518051821015612ef25781612ad491614975565b519060018060a01b03612aea60208401516153b4565b169182612afd575b506001915001612abc565b600492612b0e89838951151561547f565b608089015160a08a01516001600160a01b039081169291612b33916118d69116615c9a565b90612b4c60208a015160e08d015160408c01519161589c565b9060a0515285602052604060a0512060018060a01b0360a08d015116600052602052604060002090815401905560e08a612bb060018060a01b0360808301511660018060a01b0360a08401511662ffffff604060018060a01b039501511691613977565b1660405196878092633850c7bd851b82525afa908115610b9c578a9560a05192612e5c575b50612be3865160020b615929565b91612bf4602088015160020b615929565b855160a051946001600160801b03909116928583836001600160a01b0380831690821611612e51575b50506001600160a01b038281169084168111612e135750505090612c419291615d52565b915b60208901819052828952895115612e0c57825b83851015612df5575050612d20939495612d2e9160018060a01b03608083015116968b805115159362ffffff60408201511693815160020b6060602084015160020b9260e060018060a01b0360a08701511695015160a05150818111600014612ded5750945b01519560405197612ccc89613581565b885260208801526040870152606086015289608086015260a085015260c084015260a05160e084015260a0516101008401528a61012084015261014083015261016082015260405194859160208301613b2a565b03601f1981018552846135d3565b7f000000000000000000000000fb3efa944e81260d316bcb2f589f12f2727641326001600160a01b03163b156101ef5760405193630af2d39160e31b85526004850152036024830152606060448301528180612d9160a051936064830190613aea565b038160a05160018060a01b037f000000000000000000000000fb3efa944e81260d316bcb2f589f12f272764132165af18015610b9c57612dd7575b506001905b87612af2565b612de090613538565b60a0516101ef5786612dcc565b905094612cbc565b925092505060019450612e07926150bb565b612dd1565b8092612c56565b9296509092916001600160a01b0383161115612e45575090612e3a83612e40949383615d52565b94615d00565b612c43565b94612e40939250615d00565b945092503880612c1d565b9550905060e0853d60e011612eea575b81612e7960e093836135d3565b810103126101ef5784516001600160a01b03811681036101ef57612e9f60208701615471565b50612eac6040870161591a565b50612eb96060870161591a565b50612ec66080870161591a565b5060a086015160ff8116036101ef57612ee260c08c970161520a565b50908b612bd5565b3d9150612e6c565b5050929350505060018060a01b038151169060005b8351811015612f4557806020612f1f60019387614975565b510151600052600e602052612f3e606460043501356040600020615dac565b5001612f07565b509150600052600f602052612f64606460043501356040600020615dac565b5060646004350135600052600d60205260006006604082208281558260018201558260028201558260038201558260048201558260058201550155600c602052604060002080549060008155816130a8575b5050602081015160408201516001600160a01b039081169291612fdd916118d69116615c9a565b82916084600435013582108015613099575b613080576130787f9d807a078de01997b96cd2f26db189efd5999c0926b7da12fbe7b50fe57f4b8b9161304c60409661303586333060018060a01b038c88015116614406565b6020830151339030906001600160a01b0316614406565b5185516001600160a01b0390911681523360208201526064600435013560408201529081906060820190565b0390a161280e565b60405163b88beff960e01b815260086004820152602490fd5b5060a460043501358410612fef565b6001600160ff1b038216820361286f5760005260206000209060011b8101905b81811015612fb657600080825560018201556002016130c8565b61310290611eeb60018060a01b03604088015116916004356004016135f4565b846129cc565b61311190613538565b846129af565b5094925060c081015192612464565b508615612443565b346101ef5760603660031901126101ef5760043560243561314d614335565b61315a604435421161438b565b8160a05152600d602052604060a05120916003830154158015613228575b613181906143aa565b670de0b6b3a7640000918281029281840414811517156117c95761320b81856060956131d360067f32adb282cc270b34d31ba66933cfadafe5bf671d46a694da62f520987046b0119901918254613510565b9055600201547f000000000000000000000000fb3efa944e81260d316bcb2f589f12f2727641329033906001600160a01b0316614406565b6040519133835260208301526040820152a16001600b5560a05180f35b5082546001600160a01b0316331415613178565b600435906001600160a01b038216820361073e57565b602435906001600160a01b038216820361073e57565b35906001600160a01b038216820361073e57565b602080820190808352835180925260409283810182858560051b8401019601946000906000935b8685106132b557505050505050505090565b9091929394959697603f1982820301855286895191610160928382019080519160018060a01b03808451168552808685015116868601528884015116888501526060908184015182860152608093848101518587015260a0808201519087015260c08091015190860152858301519660e086015286518091528561018086019701908a905b8a818310613374578501516101008801525050508101516101208401520151610140909101529098810197969560010194019291906132a3565b8961339d859b6001959798999a9b949651602080916001600160801b0381511684520151910152565b01980192018d96959493929161333a565b606090600319011261073e576001600160a01b0390600435828116810361073e5791602435908116810361073e579060443590565b359062ffffff8216820361073e57565b9181601f8401121561073e578235916001600160401b03831161073e576020808501948460051b01011161073e57565b90815180825260208080930193019160005b828110613443575050505090565b835185529381019392810192600101613435565b90604060031983011261073e576004356001600160a01b038116810361073e5791602435906001600160401b03821161073e57613496916004016133f3565b9091565b602090602060408183019282815285518094520193019160005b8281106134c2575050505090565b8351855293810193928101926001016134b4565b3590811515820361073e57565b9181601f8401121561073e578235916001600160401b03831161073e576020838186019501011161073e57565b9190820180921161286f57565b60e081019081106001600160401b038211176116bc57604052565b6001600160401b0381116116bc57604052565b60a081019081106001600160401b038211176116bc57604052565b604081019081106001600160401b038211176116bc57604052565b61018081019081106001600160401b038211176116bc57604052565b606081019081106001600160401b038211176116bc57604052565b608081019081106001600160401b038211176116bc57604052565b90601f801991011681019081106001600160401b038211176116bc57604052565b903590601e198136030182121561073e57018035906001600160401b03821161073e57602001918160051b3603831361073e57565b6001600160401b0381116116bc5760051b60200190565b9060405161364d81613566565b6020600182946001600160801b0381541684520154910152565b90815461367381613629565b9261368160405194856135d3565b818452600090815260208082208186015b8484106136a0575050505050565b6002836001926136af85613640565b815201920193019290613692565b6001600160401b0381116116bc57601f01601f191660200190565b91906040808483031261073e5780516136f081613566565b80946136fb816134d6565b8252602092838201356001600160401b039283821161073e57019185601f8401121561073e5782359061372d82613629565b9661373a845198896135d3565b828852868089019360051b8601019481861161073e57878101935b86851061376757505050505050500152565b843584811161073e5782019086601f19838603011261073e5786519161378c83613566565b8a81013560ff8116810361073e578352878101359086821161073e57019084603f8301121561073e578a820135926137c3846136bd565b6137cf8a5191826135d3565b848152868a868601011161073e5760008d8681978d839801838601378301015283820152815201940193613755565b9190820391821161286f57565b604051906138188261354b565b60006080838281528260208201528260408201528260608201520152565b356001600160a01b038116810361073e5790565b903590601e198136030182121561073e57018035906001600160401b03821161073e57602001918160061b3603831361073e57565b919082604091031261073e5760405161389781613566565b809280356001600160801b038116810361073e578252602090810135910152565b9291926138c482613629565b6040926138d460405192836135d3565b819581835260208093019160061b84019381851161073e57915b8483106138fd57505050505050565b83869161390a848661387f565b8152019201916138ee565b91909160018060a01b0316600052600960205261271060406000209260405161393d81613566565b60018554958683520154946020820195865215613968575b51020491518083106139645750565b9150565b6103e885526008548152613955565b6001600160a01b039290919083821684841611613a3f575b62ffffff908460405193816020860196168652166040840152166060820152606081526139bb816135b8565b519020604051602081019160ff60f81b83526001600160601b03197f00000000000000000000000056cfc796bc88c9c7e1b38c2b0af9b7120b079aef60601b16602183015260358201527f30146866f3a846fe3c636beb2756dbd24cf321bc52c9113c837c21f47470dfeb605582015260558152613a38816135b8565b5190201690565b90919061398f565b6001600160a01b0391821681526060602080830182905290820185905291959460808201949093919260005b828110613a945750505050613a919394506040818403910152613423565b90565b9091929582806001928b613aa78b613268565b16815201970193929101613a73565b9190811015613ac65760051b0190565b634e487b7160e01b600052603260045260246000fd5b35908160020b820361073e57565b919082519283825260005b848110613b16575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201613af5565b9060208083528151151581840152808201519162ffffff604093166040850152604081015160020b6060850152606081015160020b6080850152608081015160018060a01b0380911660a086015260a08201511660c085015260c081015160e085015260e08101516101009081860152810151610120908186015281015190613be383610140938051858901520151926101609384880152820151610180870190602080916001600160801b0381511684520151910152565b0151906101c08085015280610220850192805115156101e08701520151936040610200820152845180935261024082818301918560051b8401019601946000925b858410613c35575050505050505090565b909192939495968580613c6860019361023f1986820301885286838d5160ff815116845201519181858201520190613aea565b990194019401929594939190613c24565b909192602084828101031261073e578335936001600160401b03851161073e576101c0858201838301031261073e5760405194613cb586613581565b613cc08183016134d6565b8652613cd06020828401016133e3565b6020870152613ce3604082840101613adc565b6040870152613cf6606082840101613adc565b6060870152613d09608082840101613268565b6080870152613d1c60a082840101613268565b60a087015281810160c0818101359088015260e08082013590880152610100808201359088015260408484019190910361011f19011261073e57604051613d6281613566565b6101208284010135815261014082840101356020820152610120870152613d918383016101608385010161387f565b6101408701526101a08183010135906001600160401b03821161073e57613dbc9383019201016136d8565b6101608401526080830151613dd9906001600160a01b0316615c9a565b8351158015906143255761012085015151905b818310614019575b505050613e1361014084015161012085015160208151910151916150bb565b613e3a613e2e613e238484613510565b60e086015190613510565b61010085015190613510565b80613e46575b50505050565b602084015160a08501516080860151604051613e9994909390926001600160a01b0392831692169062ffffff16613e7c8561354b565b600085526020850152604084015260608301526080820152614eaf565b83511561400a57613eb8602061012086015101515b60c08601516137fe565b8060c08601526101608501515115159182614000575b5050613fe757600254336001600160a01b0390911603613f9957608083018051610100850180516001600160a01b0392831660009081526005602052604090208054670de0b6b3a76400009092029091019055915160e08601519251613f9096613f88949093613f6d931691613f4391613510565b907f000000000000000000000000fb3efa944e81260d316bcb2f589f12f272764132903090614406565b608001516002546001600160a01b0391821694911692613510565b913090614406565b38808080613e40565b60808301516001600160a01b031660009081526005602052604090208054670de0b6b3a76400008402019055613fe2929091613f4391608001516001600160a01b031692613510565b613f90565b60405163b88beff960e01b815260176004820152602490fd5b1190503880613ece565b613eb861012085015151613eae565b610160860151602081015151158015614311575b156141f45750505060a0840151608085015160208601516140629262ffffff909116916001600160a01b039081169116613977565b908451156001600160801b036101408701515116926040870151606088015160020b9060c08901516001600160801b036101208b01519760018060a01b036003541694604051966140b28861351d565b60018060a01b0316875260208701978852604087019460020b8552606087019081526080870191825260a0870193845260c08701948986526040519860208a01986320dcf3cd60e01b8a5260018060a01b0390511660248b015251151560448a01525160020b60648901525160020b6084880152511660a48601525160c48501525160e484015260e483526101208301918383106001600160401b038411176116bc57600093849360405251915afa5061416a614e6e565b60608180518101031261073e576141eb928160206141e5930151916060604083015192015160208201525262ffffff6020880151169060018060a01b0360a08901511660018060a01b0360808a01511690604051936141c88561354b565b600185526020850152604084015260608301526080820152614eaf565b90613510565b50388080613df4565b6142ad946142bb9396949760018060a01b03600254169562ffffff60208301511692604083015160020b606084015160020b60018060a01b0360808601511660018060a01b0360a0870151169160c087015193610140610120890151980151986040519b6142618d613581565b8c5260208c015260408b015260608a0152608089015260a088015260c087015260e086015261010085015261012084015261014083015261016082015260405193849160208301613b2a565b03601f1981018452836135d3565b803b1561073e576142f5936000809460405196879586948593635296a43160e01b8552036004840152604060248401526044830190613aea565b03925af180156108b4576143065750565b61430f90613538565b565b506002546001600160a01b0316331461402d565b6020610120860151015190613dec565b6002600b5414614346576002600b55565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b61439157565b60405163b88beff960e01b815260036004820152602490fd5b6143b057565b60405163b88beff960e01b815260006004820152602490fd5b6143cf57565b60405163b88beff960e01b8152600c6004820152602490fd5b6143ee57565b60405163b88beff960e01b8152600480820152602490fd5b90929192826144155750505050565b60009384936001600160a01b039083821630036144de578592935060405191602083019463a9059cbb60e01b865216602483015260448201526044815261445b816135b8565b51925af1614467614e6e565b816144a7575b501561447c5738808080613e40565b606460405162461bcd60e51b815260206004820152600460248201526315cb54d560e21b6044820152fd5b80518015925082156144bc575b50503861446d565b819250906020918101031261073e5760206144d7910161520a565b38806144b4565b6040516323b872dd60e01b602082019081526001600160a01b0395861660248301529390941660448501526064808501919091528352509083906145236084826135d3565b51925af161452f614e6e565b81614567575b50613f905760405162461bcd60e51b81526020600482015260056024820152642b96a9aa2360d91b6044820152606490fd5b805180159250821561457c575b505038614535565b819250906020918101031261073e576020614597910161520a565b3880614574565b906145a891615217565b9190600052600a602052604080600020926020810151600185015563ffffffff81511663ffffffff1985541617845501519190565b93919093600094600094826145f25750505050565b61460a949650614604929395506137fe565b90614b38565b908181039060008312801582841316918312161761286f579138808080613e40565b9060075480820290828204148215171561286f5761271090049160018060a01b0316600052600560205260406000208281540190550390565b9190811015613ac65760051b81013590605e198136030182121561073e570190565b60005b8381106146975750505050565b6146a56107dd828686614665565b90602091826146b5838888614665565b0135906146c3838888614665565b916040928381013590601e198136030182121561073e5701918235926001600160401b03841161073e57860191833603831361073e576001600160a01b03821680156147a057600052600180975260ff856000205416156147885783809360008481959461473283968e6147b8565b8015614781575b89519889948537f1916101003d103d15151683191661477857018092521561476257500161468a565b63b88beff960e01b815260146004820152602490fd5b3d6000823e3d90fd5b505a614739565b845163b88beff960e01b8152600a6004820152602490fd5b855163b88beff960e01b815260106004820152602490fd5b9060018060a01b0360405190636eb1769f60e11b82523060048301528181841691826024830152816044602095869389165afa80156108b4576000906148f2575b6001600160801b0391501061480e5750505050565b61481883856152f1565b613e40576148268385615373565b613e4057600080916040518481019163095ea7b360e01b8352602482015282604482015260448152614857816135b8565b519082875af190614866614e6e565b826148b8575b50501561073e5761487d81836152f1565b1561488a575b8080613e40565b61489391615373565b1561489f573880614883565b60405163b88beff960e01b815260096004820152602490fd5b80919250519182159283156148d2575b505050388061486c565b8293509181928101031261073e576148ea910161520a565b3880806148c8565b508281813d831161491f575b61490881836135d3565b8101031261073e576001600160801b0390516147f9565b503d6148fe565b6040519061010082018281106001600160401b038211176116bc576040528160e06000918281528260208201528260408201528260608201528260808201528260a08201528260c08201520152565b8051821015613ac65760209160051b010190565b8054821015613ac65760005260206000209060011b0190600090565b604051906149b28261351d565b8160c06000918281528260208201528260408201528260608201528260808201528260a08201520152565b9081516149e981613629565b906040906149fa60405193846135d3565b808352614a09601f1991613629565b0160005b818110614aa85750508160005b8551811015614aa15780614a6f614a3360019389614975565b51806080614a41858a614975565b510152806000526020600c8152614a688760002091614a60868b614975565b510191613667565b9052614d31565b90614a7a8489614975565b519187614a87868b614975565b5101906060614a96878c614975565b510152525201614a1a565b5093505050565b6020908351614ab68161354b565b614abe6149a5565b81526060600084918083850152818885015283015260006080830152828701015201614a0d565b90614af891614af261380b565b50615217565b905060808101614b088151614ce2565b905290565b919063337f980090614b1f81856157de565b9309614b2757565b9060001981101561073e5760010190565b919061271090614b1f818561583e565b929190614b5682828661589c565b938215614b645709614b2757565b634e487b7160e01b600052601260045260246000fd5b929092600092600094600381019081549660058201928184549460068501805460019c60018e9a0198828a5491614bb0936145dd565b948592911315614bbf906143e8565b0390556002850180546001600160a01b0394919385938493929091614be591851661462c565b985490555495600101541691541611614bfc614926565b91878452602091600c60205260409560408620614c1890613667565b869d5b614c60575b505050505050505050507fd3ab9a69ac1632a6447fe8ed278bf0868cb4e8b70c9f0630769bb07b5abe513c919293506040908151908152846020820152a1565b8d81511115614cdd57614c738e82614975565b5184614c81878301516153b4565b169081614c95575b50509c89019c89614c1b565b908b9c9d9e614ca6898e948861547f565b614cb6858d60e08c01519061589c565b918a52600488528a8a208760a08b0151168b5288528a8a20828154019055019d9c9b614c89565b614c20565b80614ced5750600a90565b6103e98114614cf95790565b50600090565b90614d0982613629565b614d1660405191826135d3565b8281528092614d27601f1991613629565b0190602036910137565b614d396149a5565b50600090600052600d60205260406000209060405192614d588461351d565b60018060a01b0393848454168152614dd0856001860154169586602084015260028601541694856040840152614dbd6003820154966060850197885260048301546080860152600660058401549360a0870194855201549460c0810195865298614ae5565b92865191519051906020850151926145dd565b5090819460008313614de157505050565b614dff929394506040670de0b6b3a764000091519201510290614b0d565b908115614b645704908115614e1057565b60019150565b6000546001600160a01b03163303614e2a57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b3d15614e99573d90614e7f826136bd565b91614e8d60405193846135d3565b82523d6000602084013e565b606090565b600160ff1b811461286f5760000390565b6020810162ffffff808251161561508e576040928381019260018060a01b038085511693606084019282614eef8186511697888110988585511691613977565b8651911692901561506757608086015190600160ff1b82101561073e5789958580600094935b8b861461504c576401000276a4965b51169b51169151169087519a60208c0152878b015260608a015260608952614f4b896135b8565b614f898651998a9687958694630251596160e31b86523060048701528c6024870152604486015216606484015260a0608484015260a4830190613aea565b03925af1938415615042576000938495615008575b50815115614fbc57505015614fb557505b60000390565b9050614faf565b90949390929115614ff657614fd2608091614e9e565b915b94015111614fdf5750565b5163b88beff960e01b815260156004820152602490fd5b90615002608091614e9e565b91614fd4565b939080955084813d831161503b575b61502181836135d3565b810103126150385750602083519301519338614f9e565b80fd5b503d615017565b513d6000823e3d90fd5b73fffd8963efd1fc6a506488495d951d5263988d2596614f24565b608086015190600160ff1b82101561073e5789958580615088600095614e9e565b93614f15565b60405163b88beff960e01b815260116004820152602490fd5b51906001600160801b038216820361073e57565b90916020820191825160409485519160c083018381106001600160401b038211176116bc57875282526020820190815281860193845260006060808401828152608085018381524260a087019081528a5163219f5d1760e01b815296516004880152945160248701529651604486015251606485015294516084840152905160a4830152928160c481867f00000000000000000000000077dcc9b09c6ae94cdc726540735682a38e18d6906001600160a01b03165af19283156151ff5780936151c0575b50506001600160801b038091511691169181831061519d5750505050565b606494505192519263a0f2e85960e01b8452600484015260248301526044820152fd5b909192506060823d6060116151f7575b816151dd606093836135d3565b8101031261503857506151ef906150a7565b90388061517f565b3d91506151d0565b8551903d90823e3d90fd5b5190811515820361073e57565b61521f61380b565b506040519060208201926001600160601b0319809260601b16845260601b166034820152602881526152508161359d565b5190209081600052600a60205260406000209060405161526f8161354b565b63ffffffff80845416936001810154826020850192828452600281015497604087019189835260046003820154918260608b0152015460808901528799156152e8575b6152c2575b505050505042169052565b6201518092670de0b6b3a7640000925191814216031602020401905238808281806152b7565b601e83526152b2565b60405163095ea7b360e01b602082019081526001600160a01b03909316602482015260001960448083019190915281526000928392918390615332816135b8565b51925af161533e614e6e565b81615347575090565b805180159250821561535857505090565b819250906020918101031261073e576020613a91910161520a565b60405163095ea7b360e01b602082019081526001600160a01b03909316602482015260011960448083019190915281526000928392918390615332816135b8565b90600091600080806040519360208501906331a9108f60e11b82526024860152602485526153e18561359d565b93516001600160a01b03947f00000000000000000000000077dcc9b09c6ae94cdc726540735682a38e18d69086165afa615419614e6e565b9080615451575b61542957505050565b909192935060208180518101031261544d5760200151918216809203615038575090565b5080fd5b50602081511015615420565b51906001600160a01b038216820361073e57565b51908160020b820361073e57565b602082015160405163133f757160e31b815260048101919091529392916001600160a01b03916101809182876024817f00000000000000000000000077dcc9b09c6ae94cdc726540735682a38e18d69088165afa9081156108b457600097889089968a978b928c988d976155cc575b505091899a9b82808c999896948a989660808a019560a08b019d6001600160801b03809b1660608d015260020b6020819c015260020b809c5262ffffff809e169e8f90604001521694858c5216918284521660c08d0152861598612774996155c1575b505050505116916000146155a65761556e6113e361557494615929565b90615d00565b925b0181811161286f5781169182620f42400382811161286f5760e0936155a1936141e592169083614b48565b910152565b6155b56113e36155bb94615929565b90615d52565b92615576565b525238808080615551565b959950975050999350505083813d83116156a4575b6155eb81836135d3565b810103126150385782516001600160601b03811603615038576156106020840161545d565b9361561d6040850161545d565b6156296060860161545d565b9860808601519362ffffff8516850361503857509187989986899695938580899761565660a08601615471565b9c61568a61016061567560e061566e60c08b01615471565b99016150a7565b9e61568361014082016150a7565b50016150a7565b509395979c949b999a5050939592949650819d9c506154ee565b503d6155e1565b8181029190600019828209918380841093039183830393600160601b938585111561073e57146156e8570990828211900360a01b910360601c1790565b5050505060601c90565b9081600a029060001983600a099282808510940393808503948584111561073e571461576b578190600a0981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b5091500490565b9080820290600019818409908280831092039082820392670de0b6b3a7640000928484111561073e57146157d6577faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac10669940990828211900360ee1b910360121c170290565b509250500490565b908082029060001981840990828083109203908282039263337f9800928484111561073e57146157d6577fc5df62d97a91e61f2cac50459aa56a00fdd543b3a40ecf0789397887f0eac13b940990828211900360f51b9103600b1c170290565b9080820290600019818409908280831092039082820392612710928484111561073e57146157d6577fbc01a36e2eb1c432ca57a786c226809d495182a9930be0ded288ce703afb7e91940990828211900360fc1b910360041c170290565b91818302916000198185099383808610950394808603958685111561073e5714615912579082910981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b505091500490565b519061ffff8216820361073e57565b60020b6000811215615c945780600003905b620d89e88211615c82576001821615615c70576001600160881b036ffffcb933bd6fad37aa2d162d1a5940015b169160028116615c54575b60048116615c38575b60088116615c1c575b60108116615c00575b60208116615be4575b60408116615bc8575b608090818116615bad575b6101008116615b92575b6102008116615b77575b6104008116615b5c575b6108008116615b41575b6110008116615b26575b6120008116615b0b575b6140008116615af0575b6180008116615ad5575b620100008116615aba575b620200008116615aa0575b620400008116615a86575b6208000016615a6b575b50600012615a5c575b63ffffffff8116615a54576000905b60201c60ff91909116016001600160a01b031690565b600190615a3e565b8015614b645760001904615a2f565b6b048a170391f7dc42444e8fa26000929302901c9190615a26565b6d2216e584f5fa1ea926041bedfe98909302811c92615a1c565b926e5d6af8dedb81196699c329225ee60402811c92615a11565b926f09aa508b5b7a84e1c677de54f3e99bc902811c92615a06565b926f31be135f97d08fd981231505542fcfa602811c926159fb565b926f70d869a156d2a1b890bb3df62baf32f702811c926159f1565b926fa9f746462d870fdf8a65dc1f90e061e502811c926159e7565b926fd097f3bdfd2022b8845ad8f792aa582502811c926159dd565b926fe7159475a2c29b7443b29c7fa6e889d902811c926159d3565b926ff3392b0822b70005940c7a398e4b70f302811c926159c9565b926ff987a7253ac413176f2b074cf7815e5402811c926159bf565b926ffcbe86c7900a88aedcffc83b479aa3a402811c926159b5565b926ffe5dee046a99a2a811c461f1969c305302811c926159ab565b916fff2ea16466c96a3843ec78b326b528610260801c916159a0565b916fff973b41fa98c081472e6896dfb254c00260801c91615997565b916fffcb9843d60f6159c9db58835c9266440260801c9161598e565b916fffe5caca7e10e4e61c3624eaa0941cd00260801c91615985565b916ffff2e50f5f656932ef12357cf3c7fdcc0260801c9161597c565b916ffff97272373d413259a46990580e213a0260801c91615973565b6001600160881b03600160801b615968565b6040516333a3bdff60e21b8152600490fd5b8061593b565b60405160208101906370a0823160e01b825230602482015260248152615cbf8161359d565b6000928392839251915afa90615cd3614e6e565b9180615cf4575b156150385760208280518101031261503857506020015190565b50602082511015615cda565b6001600160801b03916001600160a01b03919082811683831611615d4c575b03169116615d2d82826156ab565b91600160601b9109615d3c5790565b60001981101561073e5760010190565b90615d1f565b613a9192906001600160a01b039083821682821611615d8e575b906001600160801b0391615d848286168383166156ab565b9403169116614b48565b92615d6c565b8054821015613ac65760005260206000200190600090565b90600182019060009281845282602052604084205490811515600014615eac5760001991808301818111615e9857825490848201918211615e8457808203615e38575b50505080548015615e2457820191615e078383615d94565b909182549160031b1b191690555582526020526040812055600190565b634e487b7160e01b86526031600452602486fd5b615e6f615e48615e589386615d94565b90549060031b1c92839286615d94565b819391549060031b91821b91600019901b19161790565b90558652846020526040862055388080615def565b634e487b7160e01b88526011600452602488fd5b634e487b7160e01b87526011600452602487fd5b5050505090565b919082604091031261073e576020825192015190565b91906001830160009082825280602052604082205415600014615f3157845494600160401b861015615f1d5783615f0d615e58886001604098999a01855584615d94565b9055549382526020522055600190565b634e487b7160e01b83526041600452602483fd5b5092505056fea264697066735822122001ba995590e15d2d41df360631a1c847555e2253f1590c8991d82589114820bc64736f6c63430008170033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000077dcc9b09c6ae94cdc726540735682a38e18d690000000000000000000000000259308e7d8557e4ba192de1ab8cf7e0e21896442000000000000000000000000c49c177736107fd8351ed6564136b9adbe5b1ec300000000000000000000000056cfc796bc88c9c7e1b38c2b0af9b7120b079aef30146866f3a846fe3c636beb2756dbd24cf321bc52c9113c837c21f47470dfeb
-----Decoded View---------------
Arg [0] : _underlyingPositionManagerAddress (address): 0x77DcC9b09C6Ae94CDC726540735682A38e18d690
Arg [1] : _flashLoanAggregator (address): 0x259308E7d8557e4Ba192De1aB8Cf7e0E21896442
Arg [2] : _lightQuoterV3 (address): 0xC49c177736107fD8351ed6564136B9ADbE5B1eC3
Arg [3] : _underlyingV3Factory (address): 0x56CFC796bC88C9c7e1b38C2b0aF9B7120B079aef
Arg [4] : _underlyingV3PoolInitCodeHash (bytes32): 0x30146866f3a846fe3c636beb2756dbd24cf321bc52c9113c837c21f47470dfeb
-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 00000000000000000000000077dcc9b09c6ae94cdc726540735682a38e18d690
Arg [1] : 000000000000000000000000259308e7d8557e4ba192de1ab8cf7e0e21896442
Arg [2] : 000000000000000000000000c49c177736107fd8351ed6564136b9adbe5b1ec3
Arg [3] : 00000000000000000000000056cfc796bc88c9c7e1b38c2b0af9b7120b079aef
Arg [4] : 30146866f3a846fe3c636beb2756dbd24cf321bc52c9113c837c21f47470dfeb
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ 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.