Overview
S Balance
S Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 10 from a total of 10 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
_become | 5921079 | 39 days ago | IN | 0 S | 0.00293221 | ||||
_become | 5914045 | 39 days ago | IN | 0 S | 0.00293221 | ||||
_become | 5476985 | 43 days ago | IN | 0 S | 0.00293221 | ||||
_become | 5476553 | 43 days ago | IN | 0 S | 0.00293221 | ||||
_become | 4019371 | 54 days ago | IN | 0 S | 0.00175932 | ||||
_become | 3908717 | 55 days ago | IN | 0 S | 0.00175932 | ||||
_become | 2020925 | 70 days ago | IN | 0 S | 0.00005864 | ||||
_become | 2020353 | 70 days ago | IN | 0 S | 0.00005864 | ||||
_become | 1023165 | 79 days ago | IN | 0 S | 0.00005864 | ||||
_become | 930743 | 80 days ago | IN | 0 S | 0.00005864 |
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
LexPoolV1
Compiler Version
v0.8.24+commit.e11b9ed9
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/utils/math/SafeCast.sol"; import "../../interfaces/ILexPoolV1.sol"; import "../../interfaces/IPoolAccountantV1.sol"; import "../../interfaces/IRegistryV1.sol"; import "../LexCommon.sol"; import "./LexPoolStorage.sol"; import "./LexPoolProxy.sol"; import "../../interfaces/IAffiliationV1.sol"; /** * @title LexPoolV1 * @dev The main contract for the Lex Pool, holds the liquidity and the logic for depositing and redeeming * and for the epoch system. */ contract LexPoolV1 is LexPoolStorage, ILexPoolFunctionality, IAffiliationV1 { using SafeERC20 for IERC20; using SafeCast for uint256; using SafeCast for int256; // ***** Constants ***** uint public constant SELF_UNIT_SCALE = 1e18; // ***** Modifiers ***** modifier onlyLiquidityIntentsVerifier() { require( msg.sender == IRegistryV1(registry).liquidityIntentsVerifier(), "!LiquidityIntentsVerifier" ); _; } // ***** Views ***** /** * Calculates the beginning timestamp of the next epoch by rounding down to a round "duration" unit multiplication. * @return The timestamp in which the next epoch can start (seconds) */ function calcNextEpochStartMin() public view returns (uint256) { uint256 duration = epochDuration; uint256 virtualEpochIndex = block.timestamp / duration; return (virtualEpochIndex + 1) * duration; } /** * @return The current underlying balance of this contract (underlying scale) */ function currentBalanceInternal() public view returns (uint256) { return underlying.balanceOf(address(this)); } /** * @return The current underlying balance of this contract to be used for exchange rate purposes (underlying scale) */ function underlyingBalanceForExchangeRate() public view returns (uint256) { uint256 balance = currentBalanceInternal(); uint256 pendingAmount = pendingDepositAmount; require(balance > pendingAmount, "Fatal error"); return balance - pendingAmount; } /** * Calculates the amount that is available to be borrowed by reducing the GIVEN amounts and pending * amounts from the current ERC20 balance * @return The amount of underlying (in underlying scale) that is available to be borrowed */ function virtualBalanceForUtilization( uint256 extraAmount, // sum of the amounts that are held by the contract but are not part of the available balance for utilization (such as interestShare and ) int256 unrealizedFunding ) public view returns (uint256) { uint256 balance = currentBalanceInternal(); uint subtractionFromUnrealizedFunding = unrealizedFunding < 0 ? (-unrealizedFunding).toUint256() : 0; uint256 pendingAmount = pendingDepositAmount + pendingWithdrawalAmount; if ( balance < pendingAmount + extraAmount + subtractionFromUnrealizedFunding ) return 0; return balance - pendingAmount - extraAmount - subtractionFromUnrealizedFunding; } /** * Calculates the amount that is available to be borrowed by reducing the CURRENT amounts and pending * amounts from the current ERC20 balance * @return The amount of underlying (in underlying scale) that is available to be borrowed */ function virtualBalanceForUtilization() public view returns (uint256) { return virtualBalanceForUtilization( poolAccountant.totalReservesView(), poolAccountant.unrealizedFunding() ); } /** * Calculates the utilization as a percentage of virtual borrows out the of the total available balance * by the GIVEN values. * @return The 'virtual' utilization, scaled by PRECISION */ function currentVirtualUtilization( uint256 totalBorrows, uint256 interestShare, int256 unrealizedFunding ) public view returns (uint256) { if (totalBorrows == 0) { return 0; } uint256 virtualBalance = virtualBalanceForUtilization( interestShare, unrealizedFunding ); if (virtualBalance == 0) return type(uint256).max; return (totalBorrows * PRECISION) / virtualBalance; } /** * Calculates the utilization as a percentage of virtual borrows out the of the total available balance * by the CURRENT values. * @return The 'virtual' utilization, scaled by PRECISION */ function currentVirtualUtilization() public view returns (uint256) { (uint256 borrows, uint256 interestShare) = poolAccountant .borrowsAndInterestShare(); int256 unrealizedFunding = poolAccountant.unrealizedFunding(); return currentVirtualUtilization(borrows, interestShare, unrealizedFunding); } /** * @return true if the current utilization is less than a hundred */ function isUtilizationForLPsValid() public view returns (bool) { uint256 utilization = currentVirtualUtilization(); uint256 hundredPercent = 1 * PRECISION; return utilization <= hundredPercent; } /** * Utility function to underlying amount to its matching amount in Lex tokens by the current exchange rate */ function underlyingAmountToOwnAmount( uint256 underlyingAmount ) public view returns (uint256 ownAmount) { ownAmount = underlyingAmountToOwnAmountInternal( currentExchangeRate, underlyingAmount ); } /** * Utility function to retrieve the amount of depositors of a given epoch or a subsection of */ function getDepositorsCount(uint256 epoch) external view returns (uint256) { return pendingDepositorsArr[epoch].length; } /** * Utility function to retrieve the amount of redeemers of a given epoch or a subsection of */ function getRedeemersCount(uint256 epoch) external view returns (uint256) { return pendingRedeemersArr[epoch].length; } /** * Utility function to retrieve the array of depositors of a given epoch or a subsection of */ function getDepositors( uint256 epoch, uint256 indexFrom, uint256 count ) external view returns (address[] memory depositors) { return getArrItems(pendingDepositorsArr[epoch], indexFrom, count); } /** * Utility function to retrieve the array of redeemers of a given epoch or a subsection of */ function getRedeemers( uint256 epoch, uint256 indexFrom, uint256 count ) external view returns (address[] memory redeemers) { return getArrItems(pendingRedeemersArr[epoch], indexFrom, count); } // ***** Initialization functions ***** /** * @notice Part of the Proxy mechanism */ function _become(LexPoolProxy proxy) public { require(msg.sender == proxy.admin(), "!proxy.admin"); require(proxy._acceptImplementation() == 0, "fail"); } /** * @notice Used to initialize this contract, can only be called once * @dev This is needed because of the Proxy-Upgrade paradigm. */ function initialize( ERC20 _underlying, ITradingFloorV1 _tradingFloor, uint _epochDuration ) external { initializeLexPoolStorage(_tradingFloor, _underlying, _epochDuration); currentExchangeRate = 10 ** underlyingDecimals; epochsDelayDeposit = 2; epochsDelayRedeem = 2; nextEpochStartMin = calcNextEpochStartMin(); } // ***** Admin functions ***** function setPoolAccountant( IPoolAccountantFunctionality _poolAccountant ) external onlyAdmin { require(address(_poolAccountant) != address(0), "InvalidAddress"); poolAccountant = _poolAccountant; emit AddressUpdated( LexPoolAddressesEnum.poolAccountant, address(_poolAccountant) ); } function setPnlRole(address pnl) external onlyAdmin { require(address(pnl) != address(0), "InvalidAddress"); pnlRole = pnl; emit AddressUpdated(LexPoolAddressesEnum.pnlRole, address(pnl)); } function setMaxExtraWithdrawalAmountF(uint256 maxExtra) external onlyAdmin { maxExtraWithdrawalAmountF = maxExtra; emit NumberUpdated(LexPoolNumbersEnum.maxExtraWithdrawalAmountF, maxExtra); } function setEpochsDelayDeposit(uint256 delay) external onlyAdmin { epochsDelayDeposit = delay; emit NumberUpdated(LexPoolNumbersEnum.epochsDelayDeposit, delay); } function setEpochsDelayRedeem(uint256 delay) external onlyAdmin { epochsDelayRedeem = delay; emit NumberUpdated(LexPoolNumbersEnum.epochsDelayRedeem, delay); } function setEpochDuration(uint256 duration) external onlyAdmin { epochDuration = duration; emit NumberUpdated(LexPoolNumbersEnum.epochDuration, duration); } function setMinDepositAmount(uint256 amount) external onlyAdmin { minDepositAmount = amount; emit NumberUpdated(LexPoolNumbersEnum.minDepositAmount, amount); } /** * Toggle the immediate deposit functionality - this way, no trigger is needed after requesting deposit */ function toggleImmediateDepositAllowed() external onlyAdmin { immediateDepositAllowed = !immediateDepositAllowed; emit ImmediateDepositAllowedToggled(immediateDepositAllowed); } /** * Withdraw the reserves from the system * We accrue interest to maximize the amount of reserves that can be withdrawn */ function reduceReserves( address _to ) external returns (uint256 interestShare, uint256 totalFundingShare) { require( msg.sender == IRegistryV1(registry).feesManagers(address(underlying)), "!feesManager" ); poolAccountant.accrueInterest(virtualBalanceForUtilization()); // Read interest and funding reserves and send them. (interestShare, totalFundingShare) = poolAccountant.readAndZeroReserves(); uint reservesToSend = interestShare + totalFundingShare; if (reservesToSend > 0) { underlying.safeTransfer(_to, reservesToSend); } // Emit event to notify how much was withdrawn // from accumulated interest and funding reserves. emit ReservesWithdrawn(_to, interestShare, totalFundingShare); } // ***** User interaction functions ***** /** * User interaction to deposit to the pool in a single tx using the current exchange rate. * The 'immediateDepositAllowed' must be 'true' to allow this function to pass * We accrue interest before the deposit because the virtualBalanceForUtilization changes (the underlying balance changes) */ function immediateDeposit( uint256 depositAmount, bytes32 domain, bytes32 referralCode ) external nonReentrant { require(immediateDepositAllowed, "!Allowed"); if (depositAmount < minDepositAmount) revert CapError(CapType.MIN_DEPOSIT_AMOUNT, depositAmount); poolAccountant.accrueInterest(virtualBalanceForUtilization()); address user = msg.sender; takeUnderlying(user, depositAmount); uint256 amountToMint = underlyingAmountToOwnAmount(depositAmount); _mint(user, amountToMint); emit ImmediateDeposit(user, depositAmount, amountToMint); emit LiquidityProvided( domain, referralCode, user, depositAmount, currentEpoch ); } /** * Direct EOA interaction for requesting deposit */ function requestDeposit( uint256 amount, uint256 minAmountOut, bytes32 domain, bytes32 referralCode ) external nonReentrant { require(!immediateDepositAllowed, "!Allowed"); address user = msg.sender; requestDepositInternal(user, amount, minAmountOut, domain, referralCode); } /** * Intent based interaction for requesting deposit */ function requestDepositViaIntent( address user, uint256 amount, uint256 minAmountOut, bytes32 domain, bytes32 referralCode ) external nonReentrant onlyLiquidityIntentsVerifier { require(!immediateDepositAllowed, "!Allowed"); requestDepositInternal(user, amount, minAmountOut, domain, referralCode); } /** * User interaction to request to deposit to the pool in a two phases. * The request can be triggered after 'epochsDelayDeposit' epochs have passed * We don't accrue interest here becuase the virtualBalanceForUtilization doesn't change * as the underlying balance and the pendingDepositAmount changes cancel each other out. */ function requestDepositInternal( address user, uint256 amount, uint256 minAmountOut, bytes32 domain, bytes32 referralCode ) internal { if (amount < minDepositAmount) revert CapError(CapType.MIN_DEPOSIT_AMOUNT, amount); uint256 epoch = currentEpoch + epochsDelayDeposit; require(pendingRedeems[epoch][user].amount == 0, "Redeem exists"); takeUnderlying(user, amount); pendingDepositAmount += amount; PendingDeposit storage pendingDeposit = pendingDeposits[epoch][user]; if (pendingDeposit.amount == 0) { // The first time for this user on this epoch // So this user is not yet in the array pendingDepositorsArr[epoch].push(user); } pendingDeposit.amount = pendingDeposit.amount + amount; pendingDeposit.minAmountOut = pendingDeposit.minAmountOut + minAmountOut; emit DepositRequest(user, amount, minAmountOut, epoch); emit LiquidityProvided(domain, referralCode, user, amount, epoch); } /** * Direct EOA interaction for requesting redeeming */ function requestRedeem( uint256 amount, uint256 minAmountOut ) external nonReentrant { address user = msg.sender; requestRedeemInternal(user, amount, minAmountOut); } /** * Intent based interaction for requesting redeeming */ function requestRedeemViaIntent( address user, uint256 amount, uint256 minAmountOut ) external nonReentrant onlyLiquidityIntentsVerifier { requestRedeemInternal(user, amount, minAmountOut); } /** * User interaction to request to redeem from the pool in a two phases. * The request can be triggered after 'epochsDelayRedeem' epochs have passed * Not like requestDeposit, here we have to accrue interest before the request because we do change the state: * the pendingWithdrawalAmount increases by the max amount that can be withdrawn (even though most of the time * the actual withdrawal will be less than the max amount that can be withdrawn). */ function requestRedeemInternal( address user, uint256 amount, uint256 minAmountOut ) internal { uint256 epoch = currentEpoch + epochsDelayRedeem; require(pendingDeposits[epoch][user].amount == 0, "Exists deposit"); poolAccountant.accrueInterest(virtualBalanceForUtilization()); _transfer(user, address(this), amount); uint256 rate = currentExchangeRate; uint256 currentUnderlyingAmountOut = ownAmountToUnderlyingAmountInternal( rate, amount ); require( minAmountOut <= currentUnderlyingAmountOut, "MinAmountOut too high" ); uint256 maxUnderlyingAmountOut = (currentUnderlyingAmountOut * (FRACTION_SCALE + maxExtraWithdrawalAmountF)) / FRACTION_SCALE; pendingWithdrawalAmount += maxUnderlyingAmountOut; verifyUtilizationForLPs(); PendingRedeem storage pendingRedeem = pendingRedeems[epoch][user]; if (pendingRedeem.amount == 0) { // The first time for this user on this epoch // So this user is not yet in the array pendingRedeemersArr[epoch].push(user); } pendingRedeem.amount = pendingRedeem.amount + amount; pendingRedeem.minAmountOut = pendingRedeem.minAmountOut + minAmountOut; pendingRedeem.maxAmountOut = pendingRedeem.maxAmountOut + maxUnderlyingAmountOut; emit RedeemRequest(user, amount, minAmountOut, epoch); } /** * Allows "processing" of pending deposit requests that are due for the current epoch. * Each user's request can be accepted, in which case the user receives the proper amount of Lex tokens, * or cancelled, in which case the user gets their underlying back. * @dev This function is opened to be called by any EOA or contract. * We accrue interest before processing as the pendingDepositAmount changes (causes the virtualBalanceForUtilization to change) */ function processDeposit( address[] calldata users ) external nonReentrant returns ( uint256 amountDeposited, uint256 amountCanceled, uint256 counterDeposited, uint256 counterCanceled ) { poolAccountant.accrueInterest(virtualBalanceForUtilization()); uint256 epochToProcess = currentEpoch; uint256 rate = currentExchangeRate; for (uint8 index = 0; index < users.length; index++) { (bool existed, bool deposited, uint256 amount) = processDepositSingle( epochToProcess, users[index], rate ); if (!existed) { continue; } if (deposited) { amountDeposited += amount; counterDeposited += 1; } else { amountCanceled += amount; counterCanceled += 1; } } pendingDepositAmount -= amountDeposited + amountCanceled; } /** * Handles the logic for a single deposit request */ function processDepositSingle( uint256 epoch, address user, uint256 exchangeRate ) internal returns (bool existed, bool deposited, uint256 amount) { PendingDeposit memory pendingDeposit = pendingDeposits[epoch][user]; if (0 == pendingDeposit.amount) { return (false, false, 0); } existed = true; delete pendingDeposits[epoch][user]; uint256 actualAmountOut = underlyingAmountToOwnAmountInternal( exchangeRate, pendingDeposit.amount ); if (actualAmountOut >= pendingDeposit.minAmountOut) { _mint(user, actualAmountOut); deposited = true; } else { // Cancelling underlying.safeTransfer(user, pendingDeposit.amount); deposited = false; } amount = pendingDeposit.amount; emit ProcessedDeposit(user, deposited, amount); } /** * Allows the cancellation of deposit requests whose matching epoch has passed. * @dev This function is opened to be called by any EOA or contract. * We don't accrue interest here becuase the virtualBalanceForUtilization doesn't change * as the underlying balance and the pendingDepositAmount changes cancel each other out. */ function cancelDeposits( address[] calldata users, uint256[] calldata epochs ) external nonReentrant { require(users.length == epochs.length, "!ArrayLengths"); uint256 maxEpochToCancel = currentEpoch - 1; for (uint8 index = 0; index < users.length; index++) { address user = users[index]; uint256 epoch = epochs[index]; require(epoch <= maxEpochToCancel, "Epoch too soon"); PendingDeposit memory pendingDeposit = pendingDeposits[epoch][user]; delete pendingDeposits[epoch][user]; pendingDepositAmount -= pendingDeposit.amount; underlying.safeTransfer(user, pendingDeposit.amount); emit CanceledDeposit(user, epoch, pendingDeposit.amount); } } /** * Allows "processing" of pending redeem requests that are due for the current epoch. * @dev This function is opened to be called by any EOA or contract. * Accrues interest before processing is required because: * 1. We might have cancelled redeems which changes the pendingWithdrawalAmount but not the underlying balance * 2. The amountRedeemed and the underlyingAllocated for a specific redeem request might not be the same. Which means * that we change the underlying balance and the pendigWithdrawalAmount by different amounts - they don't cancel each other. */ function processRedeems( address[] calldata users ) external nonReentrant returns ( uint256 amountRedeemed, uint256 amountCanceled, uint256 counterRedeemed, uint256 counterCanceled ) { poolAccountant.accrueInterest(virtualBalanceForUtilization()); uint256 epochToProcess = currentEpoch; uint256 rate = currentExchangeRate; uint256 underlyingFreeAllocatedAmount = 0; for (uint8 index = 0; index < users.length; index++) { ( bool existed, bool redeemed, uint256 amount, uint256 underlyingAllocated ) = processRedeemSingle(epochToProcess, users[index], rate); if (!existed) { continue; } if (redeemed) { amountRedeemed += amount; counterRedeemed += 1; } else { amountCanceled += amount; counterCanceled += 1; } underlyingFreeAllocatedAmount += underlyingAllocated; } pendingWithdrawalAmount -= underlyingFreeAllocatedAmount; } /** * Handles the logic for a single redeem request */ function processRedeemSingle( uint256 epoch, address user, uint256 exchangeRate ) internal returns ( bool existed, bool redeemed, uint256 amount, uint256 underlyingAllocated ) { PendingRedeem memory pendingRedeem = pendingRedeems[epoch][user]; if (0 == pendingRedeem.amount) { return (false, false, 0, 0); } existed = true; delete pendingRedeems[epoch][user]; uint256 currentUnderlyingAmountOut = ownAmountToUnderlyingAmountInternal( exchangeRate, pendingRedeem.amount ); uint256 finalUnderlyingAmountOut = (pendingRedeem.maxAmountOut < currentUnderlyingAmountOut) ? pendingRedeem.maxAmountOut : currentUnderlyingAmountOut; if (finalUnderlyingAmountOut >= pendingRedeem.minAmountOut) { _burn(address(this), pendingRedeem.amount); underlying.safeTransfer(user, finalUnderlyingAmountOut); redeemed = true; } else { _transfer(address(this), user, pendingRedeem.amount); redeemed = false; } amount = pendingRedeem.amount; underlyingAllocated = pendingRedeem.maxAmountOut; emit ProcessedRedeem(user, redeemed, amount); } /** * Allows the cancellation of redeem requests whose matching epoch has passed. * @dev This function is opened to be called by any EOA or contract. * We need to accure interest as we change the pendingWithdrawalAmount. */ function cancelRedeems( address[] calldata users, uint256[] calldata epochs ) external nonReentrant { require(users.length == epochs.length, "!ArrayLengths"); poolAccountant.accrueInterest(virtualBalanceForUtilization()); uint256 maxEpochToCancel = currentEpoch - 1; for (uint8 index = 0; index < users.length; index++) { address user = users[index]; uint256 epoch = epochs[index]; require(epoch <= maxEpochToCancel, "Epoch too soon"); PendingRedeem memory pendingRedeem = pendingRedeems[epoch][user]; delete pendingRedeems[epoch][user]; pendingWithdrawalAmount -= pendingRedeem.maxAmountOut; _transfer(address(this), user, pendingRedeem.amount); emit CanceledRedeem(user, epoch, pendingRedeem.amount); } } // ***** PnL Role interaction functions ***** /** * Advances the Pool's epoch while taking into account the unrealized PnL of the opened positions * @dev Can be called only by the "PnlRole" */ function nextEpoch( int256 totalUnrealizedPricePnL // Underlying scale ) external nonReentrant returns (uint256 newExchangeRate) { require(msg.sender == pnlRole, "!Auth"); require(block.timestamp >= nextEpochStartMin, "!Time pass new epoch"); (uint256 totalInterest, uint256 interestShare, ) = poolAccountant .accrueInterest(virtualBalanceForUtilization()); int256 unrealizedFunding = poolAccountant.unrealizedFunding(); uint256 newEpochId = currentEpoch + 1; uint256 supply = totalSupply; uint256 virtualUnderlyingBalance = 0; if (0 == supply) { // newExchangeRate = 1e18; newExchangeRate = (10 ** underlyingDecimals); // 1.00 } else { // Note : Subtracting all values that does not belong to the LPs // and adding values that do virtualUnderlyingBalance = (underlyingBalanceForExchangeRate() .toInt256() + unrealizedFunding + totalInterest.toInt256() - interestShare.toInt256() + totalUnrealizedPricePnL).toUint256(); newExchangeRate = (virtualUnderlyingBalance * (SELF_UNIT_SCALE)) / supply; } currentEpoch = newEpochId; currentExchangeRate = newExchangeRate; nextEpochStartMin = calcNextEpochStartMin(); emit NewEpoch( newEpochId, totalUnrealizedPricePnL, newExchangeRate, virtualUnderlyingBalance, supply ); } // ***** TradingFloor interaction functions ***** /** * Sends assets to a winning trader. */ function sendAssetToTrader( address to, uint256 amount ) external onlyTradingFloor { underlying.safeTransfer(to, amount); } // ***** Internal Views ***** /** * Sanity function to ensure that the utilization is valid */ function verifyUtilizationForLPs() internal view { require(isUtilizationForLPsValid(), "LP utilization"); } /** * Utility function to get a sub array from a given array */ function getArrItems( address[] storage arr, uint256 indexFrom, uint256 count ) internal view returns (address[] memory subArr) { uint256 itemsLeft = arr.length - indexFrom; count = count < itemsLeft ? count : itemsLeft; subArr = new address[](count); for (uint256 index = 0; index < count; index++) { subArr[index] = arr[indexFrom + index]; } } /** * Converts the underlying amount to the amount of self tokens by the current exchange rate */ function underlyingAmountToOwnAmountInternal( uint256 exchangeRate, uint256 underlyingAmount ) internal pure returns (uint256 ownAmount) { ownAmount = (underlyingAmount * SELF_UNIT_SCALE) / exchangeRate; } /** * Converts the (self) LP amount to the equal underlying amount by the current exchange rate */ function ownAmountToUnderlyingAmountInternal( uint256 exchangeRate, uint256 ownAmount ) internal pure returns (uint256 underlyingAmount) { underlyingAmount = (ownAmount * exchangeRate) / SELF_UNIT_SCALE; } // ***** Underlying utils ***** /** * Utility function to safely take underlying tokens (ERC20) from a pre-approved account * @dev Will revert if the contract will not get the exact 'amount' value */ function takeUnderlying(address from, uint amount) internal { uint balanceBefore = underlying.balanceOf(address(this)); underlying.safeTransferFrom(from, address(this), amount); uint balanceAfter = underlying.balanceOf(address(this)); require(balanceAfter - balanceBefore == amount, "DID_NOT_RECEIVE_EXACT"); } // ***** Reentrancy Guard ***** /** * @dev Prevents a contract from calling itself, directly or indirectly. */ modifier nonReentrant() { _beforeNonReentrant(); _; _afterNonReentrant(); } /** * @dev Tries to get the system lock */ function _beforeNonReentrant() private { IRegistryV1(registry).lock(); } /** * @dev Releases the system lock */ function _afterNonReentrant() private { IRegistryV1(registry).freeLock(); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol) pragma solidity ^0.8.20; /** * @dev Standard ERC20 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens. */ interface IERC20Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC20InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC20InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers. * @param spender Address that may be allowed to operate on tokens without being their owner. * @param allowance Amount of tokens a `spender` is allowed to operate with. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC20InvalidApprover(address approver); /** * @dev Indicates a failure with the `spender` to be approved. Used in approvals. * @param spender Address that may be allowed to operate on tokens without being their owner. */ error ERC20InvalidSpender(address spender); } /** * @dev Standard ERC721 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens. */ interface IERC721Errors { /** * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20. * Used in balance queries. * @param owner Address of the current owner of a token. */ error ERC721InvalidOwner(address owner); /** * @dev Indicates a `tokenId` whose `owner` is the zero address. * @param tokenId Identifier number of a token. */ error ERC721NonexistentToken(uint256 tokenId); /** * @dev Indicates an error related to the ownership over a particular token. Used in transfers. * @param sender Address whose tokens are being transferred. * @param tokenId Identifier number of a token. * @param owner Address of the current owner of a token. */ error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC721InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC721InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param tokenId Identifier number of a token. */ error ERC721InsufficientApproval(address operator, uint256 tokenId); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC721InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC721InvalidOperator(address operator); } /** * @dev Standard ERC1155 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens. */ interface IERC1155Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. * @param tokenId Identifier number of a token. */ error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC1155InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC1155InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param owner Address of the current owner of a token. */ error ERC1155MissingApprovalForAll(address operator, address owner); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC1155InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC1155InvalidOperator(address operator); /** * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation. * Used in batch transfers. * @param idsLength Length of the array of token identifiers * @param valuesLength Length of the array of token amounts */ error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "./IERC20.sol"; import {IERC20Metadata} from "./extensions/IERC20Metadata.sol"; import {Context} from "../../utils/Context.sol"; import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * * TIP: For a detailed writeup see our guide * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * The default value of {decimals} is 18. To change this, you should override * this function so it returns a different value. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. */ abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors { mapping(address account => uint256) private _balances; mapping(address account => mapping(address spender => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the default value returned by this function, unless * it's overridden. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `value`. */ function transfer(address to, uint256 value) public virtual returns (bool) { address owner = _msgSender(); _transfer(owner, to, value); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 value) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, value); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `value`. * - the caller must have allowance for ``from``'s tokens of at least * `value`. */ function transferFrom(address from, address to, uint256 value) public virtual returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, value); _transfer(from, to, value); return true; } /** * @dev Moves a `value` amount of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * NOTE: This function is not virtual, {_update} should be overridden instead. */ function _transfer(address from, address to, uint256 value) internal { if (from == address(0)) { revert ERC20InvalidSender(address(0)); } if (to == address(0)) { revert ERC20InvalidReceiver(address(0)); } _update(from, to, value); } /** * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from` * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding * this function. * * Emits a {Transfer} event. */ function _update(address from, address to, uint256 value) internal virtual { if (from == address(0)) { // Overflow check required: The rest of the code assumes that totalSupply never overflows _totalSupply += value; } else { uint256 fromBalance = _balances[from]; if (fromBalance < value) { revert ERC20InsufficientBalance(from, fromBalance, value); } unchecked { // Overflow not possible: value <= fromBalance <= totalSupply. _balances[from] = fromBalance - value; } } if (to == address(0)) { unchecked { // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply. _totalSupply -= value; } } else { unchecked { // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256. _balances[to] += value; } } emit Transfer(from, to, value); } /** * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0). * Relies on the `_update` mechanism * * Emits a {Transfer} event with `from` set to the zero address. * * NOTE: This function is not virtual, {_update} should be overridden instead. */ function _mint(address account, uint256 value) internal { if (account == address(0)) { revert ERC20InvalidReceiver(address(0)); } _update(address(0), account, value); } /** * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply. * Relies on the `_update` mechanism. * * Emits a {Transfer} event with `to` set to the zero address. * * NOTE: This function is not virtual, {_update} should be overridden instead */ function _burn(address account, uint256 value) internal { if (account == address(0)) { revert ERC20InvalidSender(address(0)); } _update(account, address(0), value); } /** * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. * * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument. */ function _approve(address owner, address spender, uint256 value) internal { _approve(owner, spender, value, true); } /** * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event. * * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any * `Approval` event during `transferFrom` operations. * * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to * true using the following override: * ``` * function _approve(address owner, address spender, uint256 value, bool) internal virtual override { * super._approve(owner, spender, value, true); * } * ``` * * Requirements are the same as {_approve}. */ function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual { if (owner == address(0)) { revert ERC20InvalidApprover(address(0)); } if (spender == address(0)) { revert ERC20InvalidSpender(address(0)); } _allowances[owner][spender] = value; if (emitEvent) { emit Approval(owner, spender, value); } } /** * @dev Updates `owner` s allowance for `spender` based on spent `value`. * * Does not update the allowance value in case of infinite allowance. * Revert if not enough allowance is available. * * Does not emit an {Approval} event. */ function _spendAllowance(address owner, address spender, uint256 value) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { if (currentAllowance < value) { revert ERC20InsufficientAllowance(spender, currentAllowance, value); } unchecked { _approve(owner, spender, currentAllowance - value, false); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. * * ==== Security Considerations * * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be * considered as an intention to spend the allowance in any specific way. The second is that because permits have * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be * generally recommended is: * * ```solidity * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public { * try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {} * doThing(..., value); * } * * function doThing(..., uint256 value) public { * token.safeTransferFrom(msg.sender, address(this), value); * ... * } * ``` * * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also * {SafeERC20-safeTransferFrom}). * * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so * contracts should have entry points that don't rely on permit. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. * * CAUTION: See Security Considerations above. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.20; /** * @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 value of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the value of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves a `value` amount of tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 value) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the * allowance mechanism. `value` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 value) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; import {IERC20Permit} from "../extensions/IERC20Permit.sol"; import {Address} from "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @dev An operation with an ERC20 token failed. */ error SafeERC20FailedOperation(address token); /** * @dev Indicates a failed `decreaseAllowance` request. */ error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease); /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value))); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value))); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); forceApprove(token, spender, oldAllowance + value); } /** * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no * value, non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal { unchecked { uint256 currentAllowance = token.allowance(address(this), spender); if (currentAllowance < requestedDecrease) { revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease); } forceApprove(token, spender, currentAllowance - requestedDecrease); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value)); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0))); _callOptionalReturn(token, approvalCall); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data); if (returndata.length != 0 && !abi.decode(returndata, (bool))) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol) pragma solidity ^0.8.20; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev The ETH balance of the account is not enough to perform the operation. */ error AddressInsufficientBalance(address account); /** * @dev There's no code at `target` (it is not a contract). */ error AddressEmptyCode(address target); /** * @dev A call to an address target failed. The target may have reverted. */ error FailedInnerCall(); /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { if (address(this).balance < amount) { revert AddressInsufficientBalance(address(this)); } (bool success, ) = recipient.call{value: amount}(""); if (!success) { revert FailedInnerCall(); } } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason or custom error, it is bubbled * up by this function (like regular Solidity function calls). However, if * the call reverted with no returned reason, this function reverts with a * {FailedInnerCall} error. * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { if (address(this).balance < value) { revert AddressInsufficientBalance(address(this)); } (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an * unsuccessful call. */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata ) internal view returns (bytes memory) { if (!success) { _revert(returndata); } else { // only check if target is a contract if the call was successful and the return data is empty // otherwise we already know that it was a contract if (returndata.length == 0 && target.code.length == 0) { revert AddressEmptyCode(target); } return returndata; } } /** * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the * revert reason or with a default {FailedInnerCall} error. */ function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) { if (!success) { _revert(returndata); } else { return returndata; } } /** * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}. */ function _revert(bytes memory returndata) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert FailedInnerCall(); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. pragma solidity ^0.8.20; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeCast { /** * @dev Value doesn't fit in an uint of `bits` size. */ error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value); /** * @dev An int value doesn't fit in an uint of `bits` size. */ error SafeCastOverflowedIntToUint(int256 value); /** * @dev Value doesn't fit in an int of `bits` size. */ error SafeCastOverflowedIntDowncast(uint8 bits, int256 value); /** * @dev An uint value doesn't fit in an int of `bits` size. */ error SafeCastOverflowedUintToInt(uint256 value); /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits */ function toUint248(uint256 value) internal pure returns (uint248) { if (value > type(uint248).max) { revert SafeCastOverflowedUintDowncast(248, value); } return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits */ function toUint240(uint256 value) internal pure returns (uint240) { if (value > type(uint240).max) { revert SafeCastOverflowedUintDowncast(240, value); } return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits */ function toUint232(uint256 value) internal pure returns (uint232) { if (value > type(uint232).max) { revert SafeCastOverflowedUintDowncast(232, value); } return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits */ function toUint224(uint256 value) internal pure returns (uint224) { if (value > type(uint224).max) { revert SafeCastOverflowedUintDowncast(224, value); } return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits */ function toUint216(uint256 value) internal pure returns (uint216) { if (value > type(uint216).max) { revert SafeCastOverflowedUintDowncast(216, value); } return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits */ function toUint208(uint256 value) internal pure returns (uint208) { if (value > type(uint208).max) { revert SafeCastOverflowedUintDowncast(208, value); } return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits */ function toUint200(uint256 value) internal pure returns (uint200) { if (value > type(uint200).max) { revert SafeCastOverflowedUintDowncast(200, value); } return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits */ function toUint192(uint256 value) internal pure returns (uint192) { if (value > type(uint192).max) { revert SafeCastOverflowedUintDowncast(192, value); } return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits */ function toUint184(uint256 value) internal pure returns (uint184) { if (value > type(uint184).max) { revert SafeCastOverflowedUintDowncast(184, value); } return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits */ function toUint176(uint256 value) internal pure returns (uint176) { if (value > type(uint176).max) { revert SafeCastOverflowedUintDowncast(176, value); } return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits */ function toUint168(uint256 value) internal pure returns (uint168) { if (value > type(uint168).max) { revert SafeCastOverflowedUintDowncast(168, value); } return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits */ function toUint160(uint256 value) internal pure returns (uint160) { if (value > type(uint160).max) { revert SafeCastOverflowedUintDowncast(160, value); } return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits */ function toUint152(uint256 value) internal pure returns (uint152) { if (value > type(uint152).max) { revert SafeCastOverflowedUintDowncast(152, value); } return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits */ function toUint144(uint256 value) internal pure returns (uint144) { if (value > type(uint144).max) { revert SafeCastOverflowedUintDowncast(144, value); } return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits */ function toUint136(uint256 value) internal pure returns (uint136) { if (value > type(uint136).max) { revert SafeCastOverflowedUintDowncast(136, value); } return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits */ function toUint128(uint256 value) internal pure returns (uint128) { if (value > type(uint128).max) { revert SafeCastOverflowedUintDowncast(128, value); } return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits */ function toUint120(uint256 value) internal pure returns (uint120) { if (value > type(uint120).max) { revert SafeCastOverflowedUintDowncast(120, value); } return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits */ function toUint112(uint256 value) internal pure returns (uint112) { if (value > type(uint112).max) { revert SafeCastOverflowedUintDowncast(112, value); } return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits */ function toUint104(uint256 value) internal pure returns (uint104) { if (value > type(uint104).max) { revert SafeCastOverflowedUintDowncast(104, value); } return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits */ function toUint96(uint256 value) internal pure returns (uint96) { if (value > type(uint96).max) { revert SafeCastOverflowedUintDowncast(96, value); } return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits */ function toUint88(uint256 value) internal pure returns (uint88) { if (value > type(uint88).max) { revert SafeCastOverflowedUintDowncast(88, value); } return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits */ function toUint80(uint256 value) internal pure returns (uint80) { if (value > type(uint80).max) { revert SafeCastOverflowedUintDowncast(80, value); } return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits */ function toUint72(uint256 value) internal pure returns (uint72) { if (value > type(uint72).max) { revert SafeCastOverflowedUintDowncast(72, value); } return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits */ function toUint64(uint256 value) internal pure returns (uint64) { if (value > type(uint64).max) { revert SafeCastOverflowedUintDowncast(64, value); } return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits */ function toUint56(uint256 value) internal pure returns (uint56) { if (value > type(uint56).max) { revert SafeCastOverflowedUintDowncast(56, value); } return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits */ function toUint48(uint256 value) internal pure returns (uint48) { if (value > type(uint48).max) { revert SafeCastOverflowedUintDowncast(48, value); } return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits */ function toUint40(uint256 value) internal pure returns (uint40) { if (value > type(uint40).max) { revert SafeCastOverflowedUintDowncast(40, value); } return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits */ function toUint32(uint256 value) internal pure returns (uint32) { if (value > type(uint32).max) { revert SafeCastOverflowedUintDowncast(32, value); } return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits */ function toUint24(uint256 value) internal pure returns (uint24) { if (value > type(uint24).max) { revert SafeCastOverflowedUintDowncast(24, value); } return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits */ function toUint16(uint256 value) internal pure returns (uint16) { if (value > type(uint16).max) { revert SafeCastOverflowedUintDowncast(16, value); } return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits */ function toUint8(uint256 value) internal pure returns (uint8) { if (value > type(uint8).max) { revert SafeCastOverflowedUintDowncast(8, value); } return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. */ function toUint256(int256 value) internal pure returns (uint256) { if (value < 0) { revert SafeCastOverflowedIntToUint(value); } return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits */ function toInt248(int256 value) internal pure returns (int248 downcasted) { downcasted = int248(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(248, value); } } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits */ function toInt240(int256 value) internal pure returns (int240 downcasted) { downcasted = int240(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(240, value); } } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits */ function toInt232(int256 value) internal pure returns (int232 downcasted) { downcasted = int232(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(232, value); } } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits */ function toInt224(int256 value) internal pure returns (int224 downcasted) { downcasted = int224(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(224, value); } } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits */ function toInt216(int256 value) internal pure returns (int216 downcasted) { downcasted = int216(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(216, value); } } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits */ function toInt208(int256 value) internal pure returns (int208 downcasted) { downcasted = int208(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(208, value); } } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits */ function toInt200(int256 value) internal pure returns (int200 downcasted) { downcasted = int200(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(200, value); } } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits */ function toInt192(int256 value) internal pure returns (int192 downcasted) { downcasted = int192(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(192, value); } } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits */ function toInt184(int256 value) internal pure returns (int184 downcasted) { downcasted = int184(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(184, value); } } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits */ function toInt176(int256 value) internal pure returns (int176 downcasted) { downcasted = int176(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(176, value); } } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits */ function toInt168(int256 value) internal pure returns (int168 downcasted) { downcasted = int168(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(168, value); } } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits */ function toInt160(int256 value) internal pure returns (int160 downcasted) { downcasted = int160(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(160, value); } } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits */ function toInt152(int256 value) internal pure returns (int152 downcasted) { downcasted = int152(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(152, value); } } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits */ function toInt144(int256 value) internal pure returns (int144 downcasted) { downcasted = int144(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(144, value); } } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits */ function toInt136(int256 value) internal pure returns (int136 downcasted) { downcasted = int136(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(136, value); } } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits */ function toInt128(int256 value) internal pure returns (int128 downcasted) { downcasted = int128(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(128, value); } } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits */ function toInt120(int256 value) internal pure returns (int120 downcasted) { downcasted = int120(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(120, value); } } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits */ function toInt112(int256 value) internal pure returns (int112 downcasted) { downcasted = int112(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(112, value); } } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits */ function toInt104(int256 value) internal pure returns (int104 downcasted) { downcasted = int104(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(104, value); } } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits */ function toInt96(int256 value) internal pure returns (int96 downcasted) { downcasted = int96(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(96, value); } } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits */ function toInt88(int256 value) internal pure returns (int88 downcasted) { downcasted = int88(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(88, value); } } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits */ function toInt80(int256 value) internal pure returns (int80 downcasted) { downcasted = int80(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(80, value); } } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits */ function toInt72(int256 value) internal pure returns (int72 downcasted) { downcasted = int72(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(72, value); } } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits */ function toInt64(int256 value) internal pure returns (int64 downcasted) { downcasted = int64(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(64, value); } } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits */ function toInt56(int256 value) internal pure returns (int56 downcasted) { downcasted = int56(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(56, value); } } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits */ function toInt48(int256 value) internal pure returns (int48 downcasted) { downcasted = int48(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(48, value); } } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits */ function toInt40(int256 value) internal pure returns (int40 downcasted) { downcasted = int40(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(40, value); } } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits */ function toInt32(int256 value) internal pure returns (int32 downcasted) { downcasted = int32(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(32, value); } } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits */ function toInt24(int256 value) internal pure returns (int24 downcasted) { downcasted = int24(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(24, value); } } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits */ function toInt16(int256 value) internal pure returns (int16 downcasted) { downcasted = int16(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(16, value); } } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits */ function toInt8(int256 value) internal pure returns (int8 downcasted) { downcasted = int8(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(8, value); } } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive if (value > uint256(type(int256).max)) { revert SafeCastOverflowedUintToInt(value); } return int256(value); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "./AcceptableImplementationClaimableAdminStorage.sol"; /** * @title SafeUpgradeableClaimableAdmin * @dev based on Compound's Unitroller * https://github.com/compound-finance/compound-protocol/blob/a3214f67b73310d547e00fc578e8355911c9d376/contracts/Unitroller.sol */ contract AcceptableImplementationClaimableAdmin is AcceptableImplementationClaimableAdminStorage { /** * @notice Emitted when pendingImplementation is changed */ event NewPendingImplementation( address oldPendingImplementation, address newPendingImplementation ); /** * @notice Emitted when pendingImplementation is accepted, which means delegation implementation is updated */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); /*** Admin Functions ***/ function _setPendingImplementation(address newPendingImplementation) public { require(msg.sender == admin, "not admin"); require( approvePendingImplementationInternal(newPendingImplementation), "INVALID_IMPLEMENTATION" ); address oldPendingImplementation = pendingImplementation; pendingImplementation = newPendingImplementation; emit NewPendingImplementation( oldPendingImplementation, pendingImplementation ); } /** * @notice Accepts new implementation. msg.sender must be pendingImplementation * @dev Admin function for new implementation to accept it's role as implementation */ function _acceptImplementation() public returns (uint) { // Check caller is pendingImplementation and pendingImplementation ≠ address(0) require( msg.sender == pendingImplementation && pendingImplementation != address(0), "Not the EXISTING pending implementation" ); // Save current values for inclusion in log address oldImplementation = implementation; address oldPendingImplementation = pendingImplementation; implementation = pendingImplementation; pendingImplementation = address(0); emit NewImplementation(oldImplementation, implementation); emit NewPendingImplementation( oldPendingImplementation, pendingImplementation ); return 0; } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. */ function _setPendingAdmin(address newPendingAdmin) public { // Check caller = admin require(msg.sender == admin, "Not Admin"); // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin */ function _acceptAdmin() public { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) require( msg.sender == pendingAdmin && pendingAdmin != address(0), "Not the EXISTING pending admin" ); // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); } constructor(address _initialAdmin) { admin = _initialAdmin; emit NewAdmin(address(0), _initialAdmin); } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ fallback() external payable { // delegate all other functions to current implementation (bool success, ) = implementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize()) switch success case 0 { revert(free_mem_ptr, returndatasize()) } default { return(free_mem_ptr, returndatasize()) } } } receive() external payable {} function approvePendingImplementationInternal( address // _implementation ) internal virtual returns (bool) { return true; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; contract ClaimableAdminStorage { /** * @notice Administrator for this contract */ address public admin; /** * @notice Pending administrator for this contract */ address public pendingAdmin; /*** Modifiers ***/ modifier onlyAdmin() { require(msg.sender == admin, "ONLY_ADMIN"); _; } /*** Constructor ***/ constructor() { // Set admin to caller admin = msg.sender; } } contract AcceptableImplementationClaimableAdminStorage is ClaimableAdminStorage { /** * @notice Active logic */ address public implementation; /** * @notice Pending logic */ address public pendingImplementation; } contract AcceptableRegistryImplementationClaimableAdminStorage is AcceptableImplementationClaimableAdminStorage { /** * @notice System Registry */ address public registry; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "./AcceptableImplementationClaimableAdmin.sol"; import "./IContractRegistryBase.sol"; /** * @title AcceptableRegistryImplementationClaimableAdmin */ contract AcceptableRegistryImplementationClaimableAdmin is AcceptableImplementationClaimableAdmin, AcceptableRegistryImplementationClaimableAdminStorage { bytes32 public immutable CONTRACT_NAME_HASH; constructor( address _registry, string memory proxyName, address _initialAdmin ) AcceptableImplementationClaimableAdmin(_initialAdmin) { registry = _registry; CONTRACT_NAME_HASH = keccak256(abi.encodePacked(proxyName)); } function approvePendingImplementationInternal( address _implementation ) internal view override returns (bool) { return IContractRegistryBase(registry).isImplementationValidForProxy( CONTRACT_NAME_HASH, _implementation ); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface IContractRegistryBase { function isImplementationValidForProxy( bytes32 proxyNameHash, address _implementation ) external view returns (bool); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.24; /** * @dev only use immutables and constants in this contract */ contract CommonScales { uint256 public constant PRECISION = 1e18; // 18 decimals uint256 public constant LEVERAGE_SCALE = 100; // 2 decimal points uint256 public constant FRACTION_SCALE = 100000; // 5 decimal points uint256 public constant ACCURACY_IMPROVEMENT_SCALE = 1e9; function calculateLeveragedPosition( uint256 collateral, uint256 leverage ) internal pure returns (uint256) { return (collateral * leverage) / LEVERAGE_SCALE; } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.24; interface IAffiliationV1 { event PositionRequested( bytes32 indexed domain, bytes32 indexed referralCode, bytes32 indexed positionId ); event LiquidityProvided( bytes32 indexed domain, bytes32 indexed referralCode, address indexed user, uint amountUnderlying, uint processingEpoch ); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface IFundingRateModel { // return value is the "funding paid by heavier side" in PRECISION per OI (heavier side) per second // e.g : (0.01 * PRECISION) = Paying (heavier) side (as a whole) pays 1% of funding per second for each OI unit function getFundingRate( uint256 pairId, uint256 openInterestLong, uint256 openInterestShort, uint256 pairMaxOpenInterest ) external view returns (uint256); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface IGlobalLock { function lock() external; function freeLock() external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface IInterestRateModel { // Returns asset/second of interest per borrowed unit // e.g : (0.01 * PRECISION) = 1% of interest per second function getBorrowRate(uint256 utilization) external view returns (uint256); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "./LexErrors.sol"; import "./LexPoolAdminEnums.sol"; import "./IPoolAccountantV1.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface LexPoolStructs { struct PendingDeposit { uint256 amount; uint256 minAmountOut; } struct PendingRedeem { uint256 amount; uint256 minAmountOut; uint256 maxAmountOut; } } interface LexPoolEvents is LexPoolAdminEnums { event NewEpoch( uint256 epochId, int256 reportedUnrealizedPricePnL, uint256 exchangeRate, uint256 virtualUnderlyingBalance, uint256 totalSupply ); event AddressUpdated(LexPoolAddressesEnum indexed enumCode, address a); event NumberUpdated(LexPoolNumbersEnum indexed enumCode, uint value); event DepositRequest( address indexed user, uint256 amount, uint256 minAmountOut, uint256 processingEpoch ); event RedeemRequest( address indexed user, uint256 amount, uint256 minAmountOut, uint256 processingEpoch ); event ProcessedDeposit( address indexed user, bool deposited, uint256 depositedAmount ); event ProcessedRedeem( address indexed user, bool redeemed, uint256 withdrawnAmount // Underlying amount ); event CanceledDeposit( address indexed user, uint256 epoch, uint256 cancelledAmount ); event CanceledRedeem( address indexed user, uint256 epoch, uint256 cancelledAmount ); event ImmediateDepositAllowedToggled(bool indexed value); event ImmediateDeposit( address indexed depositor, uint256 depositAmount, uint256 mintAmount ); event ReservesWithdrawn( address _to, uint256 interestShare, uint256 totalFundingShare ); } interface ILexPoolFunctionality is IERC20, LexPoolStructs, LexPoolEvents, LexErrors { function setPoolAccountant( IPoolAccountantFunctionality _poolAccountant ) external; function setPnlRole(address pnl) external; function setMaxExtraWithdrawalAmountF(uint256 maxExtra) external; function setEpochsDelayDeposit(uint256 delay) external; function setEpochsDelayRedeem(uint256 delay) external; function setEpochDuration(uint256 duration) external; function setMinDepositAmount(uint256 amount) external; function toggleImmediateDepositAllowed() external; function reduceReserves( address _to ) external returns (uint256 interestShare, uint256 totalFundingShare); function requestDeposit( uint256 amount, uint256 minAmountOut, bytes32 domain, bytes32 referralCode ) external; function requestDepositViaIntent( address user, uint256 amount, uint256 minAmountOut, bytes32 domain, bytes32 referralCode ) external; function requestRedeem(uint256 amount, uint256 minAmountOut) external; function requestRedeemViaIntent( address user, uint256 amount, uint256 minAmountOut ) external; function processDeposit( address[] memory users ) external returns ( uint256 amountDeposited, uint256 amountCancelled, uint256 counterDeposited, uint256 counterCancelled ); function cancelDeposits( address[] memory users, uint256[] memory epochs ) external; function processRedeems( address[] memory users ) external returns ( uint256 amountRedeemed, uint256 amountCancelled, uint256 counterDeposited, uint256 counterCancelled ); function cancelRedeems( address[] memory users, uint256[] memory epochs ) external; function nextEpoch( int256 totalUnrealizedPricePnL ) external returns (uint256 newExchangeRate); function currentVirtualUtilization() external view returns (uint256); function currentVirtualUtilization( uint256 totalBorrows, uint256 totalReserves, int256 unrealizedFunding ) external view returns (uint256); function virtualBalanceForUtilization() external view returns (uint256); function virtualBalanceForUtilization( uint256 extraAmount, int256 unrealizedFunding ) external view returns (uint256); function underlyingBalanceForExchangeRate() external view returns (uint256); function sendAssetToTrader(address to, uint256 amount) external; function isUtilizationForLPsValid() external view returns (bool); } interface ILexPoolV1 is ILexPoolFunctionality { function name() external view returns (string memory); function symbol() external view returns (string memory); function SELF_UNIT_SCALE() external view returns (uint); function underlyingDecimals() external view returns (uint256); function poolAccountant() external view returns (address); function underlying() external view returns (IERC20); function tradingFloor() external view returns (address); function currentEpoch() external view returns (uint256); function currentExchangeRate() external view returns (uint256); function nextEpochStartMin() external view returns (uint256); function epochDuration() external view returns (uint256); function minDepositAmount() external view returns (uint256); function epochsDelayDeposit() external view returns (uint256); function epochsDelayRedeem() external view returns (uint256); function immediateDepositAllowed() external view returns (bool); function pendingDeposits( uint epoch, address account ) external view returns (PendingDeposit memory); function pendingRedeems( uint epoch, address account ) external view returns (PendingRedeem memory); function pendingDepositAmount() external view returns (uint256); function pendingWithdrawalAmount() external view returns (uint256); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "./LexErrors.sol"; import "./ILexPoolV1.sol"; import "./IInterestRateModel.sol"; import "./IFundingRateModel.sol"; import "./TradingEnumsV1.sol"; interface PoolAccountantStructs { // @note To be used for passing information in function calls struct PositionRegistrationParams { uint256 collateral; uint32 leverage; bool long; uint64 openPrice; uint64 tp; } struct PairFunding { // Slot 0 int256 accPerOiLong; // 32 bytes -- Underlying Decimals // Slot 1 int256 accPerOiShort; // 32 bytes -- Underlying Decimals // Slot 2 uint256 lastUpdateTimestamp; // 32 bytes } struct TradeInitialAccFees { // Slot 0 uint256 borrowIndex; // 32 bytes // Slot 1 int256 funding; // 32 bytes -- underlying units -- Underlying Decimals } struct PairOpenInterest { // Slot 0 uint256 long; // 32 bytes -- underlying units -- Dynamic open interest for long positions // Slot 1 uint256 short; // 32 bytes -- underlying units -- Dynamic open interest for short positions } // This struct is not kept in storage struct PairFromTo { string from; string to; } struct Pair { // Slot 0 uint16 id; // 02 bytes uint16 groupId; // 02 bytes uint16 feeId; // 02 bytes uint32 minLeverage; // 04 bytes uint32 maxLeverage; // 04 bytes uint32 maxBorrowF; // 04 bytes -- FRACTION_SCALE (5) // Slot 1 uint256 maxPositionSize; // 32 bytes -- underlying units // Slot 2 uint256 maxGain; // 32 bytes -- underlying units // Slot 3 uint256 maxOpenInterest; // 32 bytes -- Underlying units // Slot 4 uint256 maxSkew; // 32 bytes -- underlying units // Slot 5 uint256 minOpenFee; // 32 bytes -- underlying units. MAX_UINT means use the default group level value // Slot 6 uint256 minPerformanceFee; // 32 bytes -- underlying units } struct Group { // Slot 0 uint16 id; // 02 bytes uint32 minLeverage; // 04 bytes uint32 maxLeverage; // 04 bytes uint32 maxBorrowF; // 04 bytes -- FRACTION_SCALE (5) // Slot 1 uint256 maxPositionSize; // 32 bytes (Underlying units) // Slot 2 uint256 minOpenFee; // 32 bytes (Underlying uints). MAX_UINT means use the default global level value } struct Fee { // Slot 0 uint16 id; // 02 bytes uint32 openFeeF; // 04 bytes -- FRACTION_SCALE (5) (Fraction of leveraged pos) uint32 closeFeeF; // 04 bytes -- FRACTION_SCALE (5) (Fraction of leveraged pos) uint32 performanceFeeF; // 04 bytes -- FRACTION_SCALE (5) (Fraction of performance) } } interface PoolAccountantEvents is PoolAccountantStructs { event PairAdded( uint256 indexed id, string indexed from, string indexed to, Pair pair ); event PairUpdated(uint256 indexed id, Pair pair); event GroupAdded(uint256 indexed id, string indexed groupName, Group group); event GroupUpdated(uint256 indexed id, Group group); event FeeAdded(uint256 indexed id, string indexed name, Fee fee); event FeeUpdated(uint256 indexed id, Fee fee); event TradeInitialAccFeesStored( bytes32 indexed positionId, uint256 borrowIndex, // uint256 rollover, int256 funding ); event AccrueFunding( uint256 indexed pairId, int256 valueLong, int256 valueShort ); event ProtocolFundingShareAccrued( uint16 indexed pairId, uint256 protocolFundingShare ); // event AccRolloverFeesStored(uint256 pairIndex, uint256 value); event FeesCharged( bytes32 indexed positionId, address indexed trader, uint16 indexed pairId, PositionRegistrationParams positionRegistrationParams, // bool long, // uint256 collateral, // Underlying Decimals // uint256 leverage, int256 profitPrecision, // PRECISION uint256 interest, int256 funding, // Underlying Decimals uint256 closingFee, uint256 tradeValue ); event PerformanceFeeCharging( bytes32 indexed positionId, uint256 performanceFee ); event MaxOpenInterestUpdated(uint256 pairIndex, uint256 maxOpenInterest); event AccrueInterest( uint256 cash, uint256 totalInterestNew, uint256 borrowIndexNew, uint256 interestShareNew ); event Borrow( uint256 indexed pairId, uint256 borrowAmount, uint256 newTotalBorrows ); event Repay( uint256 indexed pairId, uint256 repayAmount, uint256 newTotalBorrows ); } interface IPoolAccountantFunctionality is PoolAccountantStructs, PoolAccountantEvents, LexErrors, TradingEnumsV1 { function setTradeIncentivizer(address _tradeIncentivizer) external; function setMaxGainF(uint256 _maxGainF) external; function setFrm(IFundingRateModel _frm) external; function setMinOpenFee(uint256 min) external; function setLexPartF(uint256 partF) external; function setFundingRateMax(uint256 maxValue) external; function setLiquidationThresholdF(uint256 threshold) external; function setLiquidationFeeF(uint256 fee) external; function setIrm(IInterestRateModel _irm) external; function setIrmHard(IInterestRateModel _irm) external; function setInterestShareFactor(uint256 factor) external; function setFundingShareFactor(uint256 factor) external; function setBorrowRateMax(uint256 rate) external; function setMaxTotalBorrows(uint256 maxBorrows) external; function setMaxVirtualUtilization(uint256 _maxVirtualUtilization) external; function resetTradersPairGains(uint256 pairId) external; function addGroup(Group calldata _group) external; function updateGroup(Group calldata _group) external; function addFee(Fee calldata _fee) external; function updateFee(Fee calldata _fee) external; function addPair(Pair calldata _pair) external; function addPairs(Pair[] calldata _pairs) external; function updatePair(Pair calldata _pair) external; function readAndZeroReserves() external returns (uint256 accumulatedInterestShare, uint256 accFundingShare); function registerOpenTrade( bytes32 positionId, address trader, uint16 pairId, uint256 collateral, uint32 leverage, bool long, uint256 tp, uint256 openPrice ) external returns (uint256 fee, uint256 lexPartFee); function registerCloseTrade( bytes32 positionId, address trader, uint16 pairId, PositionRegistrationParams calldata positionRegistrationParams, uint256 closePrice, PositionCloseType positionCloseType ) external returns ( uint256 closingFee, uint256 tradeValue, int256 profitPrecision, uint finalClosePrice ); function registerUpdateTp( bytes32 positionId, address trader, uint16 pairId, uint256 collateral, uint32 leverage, bool long, uint256 openPrice, uint256 oldTriggerPrice, uint256 triggerPrice ) external; // function registerUpdateSl( // address trader, // uint256 pairIndex, // uint256 index, // uint256 collateral, // uint256 leverage, // bool long, // uint256 openPrice, // uint256 triggerPrice // ) external returns (uint256 fee); function accrueInterest() external returns ( uint256 totalInterestNew, uint256 interestShareNew, uint256 borrowIndexNew ); // Limited only for the LexPool function accrueInterest( uint256 availableCash ) external returns ( uint256 totalInterestNew, uint256 interestShareNew, uint256 borrowIndexNew ); function getTradeClosingValues( bytes32 positionId, uint16 pairId, PositionRegistrationParams calldata positionRegistrationParams, uint256 closePrice, bool isLiquidation ) external returns ( uint256 tradeValue, // Underlying Decimals uint256 safeClosingFee, int256 profitPrecision, uint256 interest, int256 funding ); function getTradeLiquidationPrice( bytes32 positionId, uint16 pairId, uint256 openPrice, // PRICE_SCALE (8) uint256 tp, bool long, uint256 collateral, // Underlying Decimals uint32 leverage ) external returns ( uint256 // PRICE_SCALE (8) ); function calcTradeDynamicFees( bytes32 positionId, uint16 pairId, bool long, uint256 collateral, uint32 leverage, uint256 openPrice, uint256 tp ) external returns (uint256 interest, int256 funding); function unrealizedFunding() external view returns (int256); function totalBorrows() external view returns (uint256); function interestShare() external view returns (uint256); function fundingShare() external view returns (uint256); function totalReservesView() external view returns (uint256); function borrowsAndInterestShare() external view returns (uint256 totalBorrows, uint256 totalInterestShare); function pairTotalOpenInterest( uint256 pairIndex ) external view returns (int256); function pricePnL( uint256 pairId, uint256 price ) external view returns (int256); function getAllSupportedPairIds() external view returns (uint16[] memory); function getAllSupportedGroupsIds() external view returns (uint16[] memory); function getAllSupportedFeeIds() external view returns (uint16[] memory); } interface IPoolAccountantV1 is IPoolAccountantFunctionality { function totalBorrows() external view returns (uint256); function maxTotalBorrows() external view returns (uint256); function pairBorrows(uint256 pairId) external view returns (uint256); function groupBorrows(uint256 groupId) external view returns (uint256); function pairMaxBorrow(uint16 pairId) external view returns (uint256); function groupMaxBorrow(uint16 groupId) external view returns (uint256); function lexPool() external view returns (ILexPoolV1); function maxGainF() external view returns (uint256); function interestShareFactor() external view returns (uint256); function fundingShareFactor() external view returns (uint256); function frm() external view returns (IFundingRateModel); function irm() external view returns (IInterestRateModel); function pairs(uint16 pairId) external view returns (Pair memory); function groups(uint16 groupId) external view returns (Group memory); function fees(uint16 feeId) external view returns (Fee memory); function openInterestInPair( uint pairId ) external view returns (PairOpenInterest memory); function minOpenFee() external view returns (uint256); function liquidationThresholdF() external view returns (uint256); function liquidationFeeF() external view returns (uint256); function lexPartF() external view returns (uint256); function tradersPairGains(uint256 pairId) external view returns (int256); function calcBorrowAmount( uint256 collateral, uint256 leverage, bool long, uint256 openPrice, uint256 tp ) external pure returns (uint256); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "../../AdministrationContracts/IContractRegistryBase.sol"; import "./IGlobalLock.sol"; interface IRegistryV1Functionality is IContractRegistryBase, IGlobalLock { // **** Locking mechanism **** function isTradersPortalAndLocker( address _address ) external view returns (bool); function isTriggersAndLocker(address _address) external view returns (bool); function isTradersPortalOrTriggersAndLocker( address _address ) external view returns (bool); } interface IRegistryV1 is IRegistryV1Functionality { // **** Public Storage params **** function feesManagers(address asset) external view returns (address); function orderBook() external view returns (address); function tradersPortal() external view returns (address); function triggers() external view returns (address); function tradeIntentsVerifier() external view returns (address); function liquidityIntentsVerifier() external view returns (address); function chipsIntentsVerifier() external view returns (address); function lexProxiesFactory() external view returns (address); function chipsFactory() external view returns (address); /** * @return An array of all supported trading floors */ function getAllSupportedTradingFloors() external view returns (address[] memory); /** * @return An array of all supported settlement assets */ function getSettlementAssetsForTradingFloor( address _tradingFloor ) external view returns (address[] memory); /** * @return The spender role address that is set for this chip */ function getValidSpenderTargetForChipByRole( address chip, string calldata role ) external view returns (address); /** * @return the address of the valid 'burnHandler' for the chip */ function validBurnHandlerForChip( address chip ) external view returns (address); /** * @return The address matching for the given role */ function getDynamicRoleAddress( string calldata _role ) external view returns (address); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "./TradingFloorStructsV1.sol"; import "./IPoolAccountantV1.sol"; import "./ILexPoolV1.sol"; interface ITradingFloorV1Functionality is TradingFloorStructsV1 { function supportNewSettlementAsset( address _asset, address _lexPool, address _poolAccountant ) external; function getPositionTriggerInfo( bytes32 _positionId ) external view returns ( PositionPhase positionPhase, uint64 timestamp, uint16 pairId, bool long, uint32 spreadReductionF ); function getPositionPortalInfo( bytes32 _positionId ) external view returns ( PositionPhase positionPhase, uint64 inPhaseSince, address positionTrader ); function storePendingPosition( OpenOrderType _orderType, PositionRequestIdentifiers memory _requestIdentifiers, PositionRequestParams memory _requestParams, uint32 _spreadReductionF ) external returns (bytes32 positionId); function setOpenedPositionToMarketClose( bytes32 _positionId, uint64 _minPrice, uint64 _maxPrice ) external; function cancelPendingPosition( bytes32 _positionId, OpenOrderType _orderType, uint feeFraction ) external; function cancelMarketCloseForPosition( bytes32 _positionId, CloseOrderType _orderType, uint feeFraction ) external; function updatePendingPosition_openLimit( bytes32 _positionId, uint64 _minPrice, uint64 _maxPrice, uint64 _tp, uint64 _sl ) external; function openNewPosition_market( bytes32 _positionId, uint64 assetEffectivePrice, uint256 feeForCancellation ) external; function openNewPosition_limit( bytes32 _positionId, uint64 assetEffectivePrice, uint256 feeForCancellation ) external; function closeExistingPosition_Market( bytes32 _positionId, uint64 assetPrice, uint64 effectivePrice ) external; function closeExistingPosition_Limit( bytes32 _positionId, LimitTrigger limitTrigger, uint64 assetPrice, uint64 effectivePrice ) external; // Manage open trade function updateOpenedPosition( bytes32 _positionId, PositionField updateField, uint64 fieldValue, uint64 effectivePrice ) external; // Fees function collectFee(address _asset, FeeType _feeType, address _to) external; } interface ITradingFloorV1 is ITradingFloorV1Functionality { function PRECISION() external pure returns (uint); // *** Views *** function pairTradersArray( address _asset, uint _pairIndex ) external view returns (address[] memory); function generatePositionHashId( address settlementAsset, address trader, uint16 pairId, uint32 index ) external pure returns (bytes32 hashId); // *** Public Storage addresses *** function lexPoolForAsset(address asset) external view returns (ILexPoolV1); function poolAccountantForAsset( address asset ) external view returns (IPoolAccountantV1); function registry() external view returns (address); // *** Public Storage params *** function positionsById(bytes32 id) external view returns (Position memory); function positionIdentifiersById( bytes32 id ) external view returns (PositionIdentifiers memory); function positionLimitsInfoById( bytes32 id ) external view returns (PositionLimitsInfo memory); function triggerPricesById( bytes32 id ) external view returns (PositionTriggerPrices memory); function pairTradersInfo( address settlementAsset, address trader, uint pairId ) external view returns (PairTraderInfo memory); function spreadReductionsP(uint) external view returns (uint); function maxSlF() external view returns (uint); function maxTradesPerPair() external view returns (uint); function maxSanityProfitF() external view returns (uint); function feesMap( address settlementAsset, FeeType feeType ) external view returns (uint256); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface LexErrors { enum CapType { NONE, // 0 MIN_OPEN_FEE, // 1 MAX_POS_SIZE_PAIR, // 2 MAX_POS_SIZE_GROUP, // 3 MAX_LEVERAGE, // 4 MIN_LEVERAGE, // 5 MAX_VIRTUAL_UTILIZATION, // 6 MAX_OPEN_INTEREST, // 7 MAX_ABS_SKEW, // 8 MAX_BORROW_PAIR, // 9 MAX_BORROW_GROUP, // 10 MIN_DEPOSIT_AMOUNT, // 11 MAX_ACCUMULATED_GAINS, // 12 BORROW_RATE_MAX, // 13 FUNDING_RATE_MAX, // 14 MAX_POTENTIAL_GAIN, // 15 MAX_TOTAL_BORROW, // 16 MIN_PERFORMANCE_FEE // 17 //... } error CapError(CapType, uint256 value); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.24; interface LexPoolAdminEnums { enum LexPoolAddressesEnum { none, poolAccountant, pnlRole } enum LexPoolNumbersEnum { none, maxExtraWithdrawalAmountF, epochsDelayDeposit, epochsDelayRedeem, epochDuration, minDepositAmount } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface TradingEnumsV1 { enum PositionPhase { NONE, OPEN_MARKET, OPEN_LIMIT, OPENED, CLOSE_MARKET, CLOSED } enum OpenOrderType { NONE, MARKET, LIMIT } enum CloseOrderType { NONE, MARKET } enum FeeType { NONE, OPEN_FEE, CLOSE_FEE, TRIGGER_FEE } enum LimitTrigger { NONE, TP, SL, LIQ } enum PositionField { NONE, TP, SL } enum PositionCloseType { NONE, TP, SL, LIQ, MARKET } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "./TradingEnumsV1.sol"; interface TradingFloorStructsV1 is TradingEnumsV1 { enum AdminNumericParam { NONE, MAX_TRADES_PER_PAIR, MAX_SL_F, MAX_SANITY_PROFIT_F } /** * @dev Memory struct for identifiers */ struct PositionRequestIdentifiers { address trader; uint16 pairId; address settlementAsset; uint32 positionIndex; } struct PositionRequestParams { bool long; uint256 collateral; // Settlement Asset Decimals uint32 leverage; uint64 minPrice; // PRICE_SCALE uint64 maxPrice; // PRICE_SCALE uint64 tp; // PRICE_SCALE uint64 sl; // PRICE_SCALE uint64 tpByFraction; // FRACTION_SCALE uint64 slByFraction; // FRACTION_SCALE } /** * @dev Storage struct for identifiers */ struct PositionIdentifiers { // Slot 0 address settlementAsset; // 20 bytes uint16 pairId; // 02 bytes uint32 index; // 04 bytes // Slot 1 address trader; // 20 bytes } struct Position { // Slot 0 uint collateral; // 32 bytes -- Settlement Asset Decimals // Slot 1 PositionPhase phase; // 01 bytes uint64 inPhaseSince; // 08 bytes uint32 leverage; // 04 bytes bool long; // 01 bytes uint64 openPrice; // 08 bytes -- PRICE_SCALE (8) uint32 spreadReductionF; // 04 bytes -- FRACTION_SCALE (5) } /** * Holds the non liquidation limits for the position */ struct PositionLimitsInfo { uint64 tpLastUpdated; // 08 bytes -- timestamp uint64 slLastUpdated; // 08 bytes -- timestamp uint64 tp; // 08 bytes -- PRICE_SCALE (8) uint64 sl; // 08 bytes -- PRICE_SCALE (8) } /** * Holds the prices for opening (and market closing) of a position */ struct PositionTriggerPrices { uint64 minPrice; // 08 bytes -- PRICE_SCALE uint64 maxPrice; // 08 bytes -- PRICE_SCALE uint64 tpByFraction; // 04 bytes -- FRACTION_SCALE uint64 slByFraction; // 04 bytes -- FRACTION_SCALE } /** * @dev administration struct, used to keep tracks on the 'PairTraders' list and * to limit the amount of positions a trader can have */ struct PairTraderInfo { uint32 positionsCounter; // 04 bytes uint32 positionInArray; // 04 bytes (the index + 1) // Note : Can add more fields here } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "../../AdministrationContracts/AcceptableImplementationClaimableAdminStorage.sol"; import "../interfaces/ITradingFloorV1.sol"; import "../Common/CommonScales.sol"; /** * @title LexCommon * @dev For Lex contracts to inherit from, holding common variables and modifiers */ contract LexCommon is CommonScales, AcceptableRegistryImplementationClaimableAdminStorage { IERC20 public underlying; ITradingFloorV1 public tradingFloor; function initializeLexCommon( ITradingFloorV1 _tradingFloor, IERC20 _underlying ) public { require( address(tradingFloor) == address(0) && address(underlying) == address(0), "Initialized" ); tradingFloor = _tradingFloor; underlying = _underlying; } modifier onlyTradingFloor() { require(msg.sender == address(tradingFloor), "TRADING_FLOOR_ONLY"); _; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @title LexERC20 * @dev simple erc20 contract. * @notice This is the token that is issued against the deposited funds. * The value of the token is represented by the exchange rate of the pool. */ contract LexERC20 is IERC20 { mapping(address => uint256) internal _balances; mapping(address => mapping(address => uint256)) internal _allowances; uint256 public totalSupply; string public name; string public symbol; function initializeLexERC20( string memory _name, string memory _symbol ) public { require( bytes(name).length == 0 && bytes(symbol).length == 0, "Initialized" ); name = _name; symbol = _symbol; } function decimals() public pure returns (uint8) { return 18; } function balanceOf(address account) public view returns (uint256) { return _balances[account]; } function transfer(address recipient, uint256 amount) public returns (bool) { _transfer(msg.sender, recipient, amount); return true; } function allowance( address owner, address spender ) public view returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public returns (bool) { _approve(msg.sender, spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) public returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][msg.sender]; require( currentAllowance >= amount, "ERC20: transfer amount exceeds allowance" ); unchecked { _approve(sender, msg.sender, currentAllowance - amount); } return true; } function _transfer( address sender, address recipient, uint256 amount ) internal { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[sender] = senderBalance - amount; } _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } function _mint(address account, uint256 amount) internal { require(account != address(0), "ERC20: mint to the zero address"); totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } function _burn(address account, uint256 amount) internal { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } totalSupply -= amount; emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "../../../AdministrationContracts/AcceptableRegistryImplementationClaimableAdmin.sol"; /** * @title LexPoolProxy * @dev Used as the upgradable lex pool of the Lynx platform */ contract LexPoolProxy is AcceptableRegistryImplementationClaimableAdmin { constructor( address _registry, address _initialAdmin ) AcceptableRegistryImplementationClaimableAdmin( _registry, "LexPool", _initialAdmin ) {} }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "../LexCommon.sol"; import "./LexERC20.sol"; /** * @title LexPoolStorage * @dev Storage contract for LexPool */ abstract contract LexPoolStorage is LexCommon, LexERC20, LexPoolStructs { uint256 public underlyingDecimals; // ***** Roles ***** IPoolAccountantFunctionality public poolAccountant; address public pnlRole; // ***** Depositing and Withdrawing ***** // epoch => user => PendingDeposit mapping(uint256 => mapping(address => PendingDeposit)) public pendingDeposits; // epoch => user => PendingRedeem mapping(uint256 => mapping(address => PendingRedeem)) public pendingRedeems; // epoch => users who deposits on this epoch mapping(uint256 => address[]) public pendingDepositorsArr; // epoch => users who redeems on this epoch mapping(uint256 => address[]) public pendingRedeemersArr; uint256 public pendingDepositAmount; uint256 public pendingWithdrawalAmount; // Extra fraction allowed to be withdrawn when redeem processes uint256 public maxExtraWithdrawalAmountF; uint256 public minDepositAmount; // ***** Epochs ***** uint256 public currentEpoch; uint256 public nextEpochStartMin; // Minimum timestamp that calling nextEpoch will be possible uint256 public currentExchangeRate; uint256 public epochsDelayDeposit; uint256 public epochsDelayRedeem; uint256 public epochDuration; // ***** Flags ***** bool public immediateDepositAllowed; function initializeLexPoolStorage( ITradingFloorV1 _tradingFloor, ERC20 _underlying, uint _epochDuration ) internal { initializeLexERC20( string.concat("Lynx LP ", _underlying.symbol()), string.concat("lx", _underlying.symbol()) ); initializeLexCommon(_tradingFloor, IERC20(_underlying)); underlyingDecimals = _underlying.decimals(); epochDuration = _epochDuration; } }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "metadata": { "useLiteralContent": true }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[{"internalType":"enum LexErrors.CapType","name":"","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"CapError","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[{"internalType":"int256","name":"value","type":"int256"}],"name":"SafeCastOverflowedIntToUint","type":"error"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintToInt","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"enum LexPoolAdminEnums.LexPoolAddressesEnum","name":"enumCode","type":"uint8"},{"indexed":false,"internalType":"address","name":"a","type":"address"}],"name":"AddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"cancelledAmount","type":"uint256"}],"name":"CanceledDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"cancelledAmount","type":"uint256"}],"name":"CanceledRedeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"processingEpoch","type":"uint256"}],"name":"DepositRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"depositAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mintAmount","type":"uint256"}],"name":"ImmediateDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"value","type":"bool"}],"name":"ImmediateDepositAllowedToggled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"domain","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"referralCode","type":"bytes32"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountUnderlying","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"processingEpoch","type":"uint256"}],"name":"LiquidityProvided","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"epochId","type":"uint256"},{"indexed":false,"internalType":"int256","name":"reportedUnrealizedPricePnL","type":"int256"},{"indexed":false,"internalType":"uint256","name":"exchangeRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"virtualUnderlyingBalance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalSupply","type":"uint256"}],"name":"NewEpoch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"enum LexPoolAdminEnums.LexPoolNumbersEnum","name":"enumCode","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"NumberUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"domain","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"referralCode","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"positionId","type":"bytes32"}],"name":"PositionRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"bool","name":"deposited","type":"bool"},{"indexed":false,"internalType":"uint256","name":"depositedAmount","type":"uint256"}],"name":"ProcessedDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"bool","name":"redeemed","type":"bool"},{"indexed":false,"internalType":"uint256","name":"withdrawnAmount","type":"uint256"}],"name":"ProcessedRedeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"processingEpoch","type":"uint256"}],"name":"RedeemRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"interestShare","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalFundingShare","type":"uint256"}],"name":"ReservesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"ACCURACY_IMPROVEMENT_SCALE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FRACTION_SCALE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LEVERAGE_SCALE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRECISION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SELF_UNIT_SCALE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract LexPoolProxy","name":"proxy","type":"address"}],"name":"_become","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"calcNextEpochStartMin","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"users","type":"address[]"},{"internalType":"uint256[]","name":"epochs","type":"uint256[]"}],"name":"cancelDeposits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"users","type":"address[]"},{"internalType":"uint256[]","name":"epochs","type":"uint256[]"}],"name":"cancelRedeems","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentBalanceInternal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentExchangeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentVirtualUtilization","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"totalBorrows","type":"uint256"},{"internalType":"uint256","name":"interestShare","type":"uint256"},{"internalType":"int256","name":"unrealizedFunding","type":"int256"}],"name":"currentVirtualUtilization","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"epochDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epochsDelayDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epochsDelayRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"uint256","name":"indexFrom","type":"uint256"},{"internalType":"uint256","name":"count","type":"uint256"}],"name":"getDepositors","outputs":[{"internalType":"address[]","name":"depositors","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epoch","type":"uint256"}],"name":"getDepositorsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"uint256","name":"indexFrom","type":"uint256"},{"internalType":"uint256","name":"count","type":"uint256"}],"name":"getRedeemers","outputs":[{"internalType":"address[]","name":"redeemers","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epoch","type":"uint256"}],"name":"getRedeemersCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"depositAmount","type":"uint256"},{"internalType":"bytes32","name":"domain","type":"bytes32"},{"internalType":"bytes32","name":"referralCode","type":"bytes32"}],"name":"immediateDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"immediateDepositAllowed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"_underlying","type":"address"},{"internalType":"contract ITradingFloorV1","name":"_tradingFloor","type":"address"},{"internalType":"uint256","name":"_epochDuration","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ITradingFloorV1","name":"_tradingFloor","type":"address"},{"internalType":"contract IERC20","name":"_underlying","type":"address"}],"name":"initializeLexCommon","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"name":"initializeLexERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isUtilizationForLPsValid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxExtraWithdrawalAmountF","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minDepositAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int256","name":"totalUnrealizedPricePnL","type":"int256"}],"name":"nextEpoch","outputs":[{"internalType":"uint256","name":"newExchangeRate","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nextEpochStartMin","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingDepositAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"pendingDepositorsArr","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"pendingDeposits","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingImplementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"pendingRedeemersArr","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"pendingRedeems","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"uint256","name":"maxAmountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingWithdrawalAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pnlRole","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolAccountant","outputs":[{"internalType":"contract IPoolAccountantFunctionality","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"users","type":"address[]"}],"name":"processDeposit","outputs":[{"internalType":"uint256","name":"amountDeposited","type":"uint256"},{"internalType":"uint256","name":"amountCanceled","type":"uint256"},{"internalType":"uint256","name":"counterDeposited","type":"uint256"},{"internalType":"uint256","name":"counterCanceled","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"users","type":"address[]"}],"name":"processRedeems","outputs":[{"internalType":"uint256","name":"amountRedeemed","type":"uint256"},{"internalType":"uint256","name":"amountCanceled","type":"uint256"},{"internalType":"uint256","name":"counterRedeemed","type":"uint256"},{"internalType":"uint256","name":"counterCanceled","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"}],"name":"reduceReserves","outputs":[{"internalType":"uint256","name":"interestShare","type":"uint256"},{"internalType":"uint256","name":"totalFundingShare","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"bytes32","name":"domain","type":"bytes32"},{"internalType":"bytes32","name":"referralCode","type":"bytes32"}],"name":"requestDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"bytes32","name":"domain","type":"bytes32"},{"internalType":"bytes32","name":"referralCode","type":"bytes32"}],"name":"requestDepositViaIntent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"name":"requestRedeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"name":"requestRedeemViaIntent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"sendAssetToTrader","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"duration","type":"uint256"}],"name":"setEpochDuration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"delay","type":"uint256"}],"name":"setEpochsDelayDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"delay","type":"uint256"}],"name":"setEpochsDelayRedeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"maxExtra","type":"uint256"}],"name":"setMaxExtraWithdrawalAmountF","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"setMinDepositAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pnl","type":"address"}],"name":"setPnlRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IPoolAccountantFunctionality","name":"_poolAccountant","type":"address"}],"name":"setPoolAccountant","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"toggleImmediateDepositAllowed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tradingFloor","outputs":[{"internalType":"contract ITradingFloorV1","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"underlying","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"underlyingAmount","type":"uint256"}],"name":"underlyingAmountToOwnAmount","outputs":[{"internalType":"uint256","name":"ownAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlyingBalanceForExchangeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlyingDecimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"extraAmount","type":"uint256"},{"internalType":"int256","name":"unrealizedFunding","type":"int256"}],"name":"virtualBalanceForUtilization","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"virtualBalanceForUtilization","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b50600080546001600160a01b03191633179055614417806100326000396000f3fe608060405234801561001057600080fd5b50600436106104545760003560e01c806380193b2611610241578063c12d636b1161013b578063e1618fe8116100c3578063ef693fe411610087578063ef693fe4146109c6578063f2fc6e66146109cf578063f851a440146109e2578063f87fc31c146109f5578063ff9d4ff314610a0857600080fd5b8063e1618fe81461097c578063e5abb5a51461098f578063eb449c2f146109a2578063eb6ced71146109b5578063eda6d6be146109bd57600080fd5b8063cb5460fd1161010a578063cb5460fd146108c0578063d03bfffd146108d3578063d3c5b5f8146108db578063d3fd3cf514610930578063dd62ed3e1461094357600080fd5b8063c12d636b1461087e578063c6775bad14610891578063c6b27f24146108a4578063c87d7e8d146108ad57600080fd5b8063a9059cbb116101c9578063b225018d1161018d578063b225018d14610838578063b407153c1461084b578063b71f3cfe14610858578063baf7fdd614610863578063bd3658e61461086b57600080fd5b8063a9059cbb14610801578063aaf5eb681461073c578063ad1f2b5614610814578063af8a89ce1461081c578063b16e49b31461082f57600080fd5b80639980a5f3116102105780639980a5f3146107b65780639b27168b146107c95780639bb7d707146107d2578063a3684977146107e5578063a7227981146107ee57600080fd5b806380193b261461077e57806392c51a7e1461078857806394870a541461079b57806395d89b41146107ae57600080fd5b8063313ce567116103525780635c60da1b116102da57806370a082311161029e57806370a082311461070a578063766718081461073357806379c80dc21461073c5780637b1039991461074b5780637bd1bf0c1461075e57600080fd5b80635c60da1b146106c057806360f3da41146106d357806361428953146106db578063645006ca146106ee5780636f307dc3146106f757600080fd5b80633ce9a294116103215780633ce9a2941461062a578063414a831f1461063d578063470aad06146106505780634ff0876a1461067057806356ef801b1461067957600080fd5b8063313ce567146105ed5780633233c5e3146105fc578063396f7b231461060f5780633a8f09f31461062257600080fd5b80631d504dc6116103e057806326782247116103a457806326782247146105985780632a80cda3146105ab5780632c5b1066146105be5780632d4138c1146105c757806330024dfe146105da57600080fd5b80631d504dc61461054357806321d491131461055657806323b872dd1461056957806323c874201461057c57806325a760c21461058f57600080fd5b80630d3b0b76116104275780630d3b0b76146104df57806312a45f651461050a578063149673191461051f5780631794bb3c1461052757806318160ddd1461053a57600080fd5b8063022dced21461045957806306fdde0314610474578063095ea7b314610489578063098ee6f2146104ac575b600080fd5b610461610a28565b6040519081526020015b60405180910390f35b61047c610a8c565b60405161046b91906139bd565b61049c610497366004613a05565b610b1a565b604051901515815260200161046b565b6104bf6104ba366004613a7d565b610b31565b60408051948552602085019390935291830152606082015260800161046b565b6006546104f2906001600160a01b031681565b6040516001600160a01b03909116815260200161046b565b61051d610518366004613abf565b610cb2565b005b61049c610d3c565b61051d610535366004613af8565b610d68565b61046160095481565b61051d610551366004613b39565b610d9e565b61051d610564366004613a05565b610eec565b61049c610577366004613af8565b610f56565b600e546104f2906001600160a01b031681565b610461600c5481565b6001546104f2906001600160a01b031681565b61051d6105b9366004613b56565b611002565b61046160145481565b6104f26105d5366004613b6f565b61106b565b61051d6105e8366004613b56565b6110a3565b6040516012815260200161046b565b61051d61060a366004613c56565b6110d9565b6003546104f2906001600160a01b031681565b61051d611159565b610461610638366004613b6f565b6111c8565b61051d61064b366004613cba565b61125e565b61066361065e366004613d26565b611448565b60405161046b9190613d52565b610461601c5481565b6106ab610687366004613d9f565b600f6020908152600092835260408084209091529082529020805460019091015482565b6040805192835260208301919091520161046b565b6002546104f2906001600160a01b031681565b61046161146c565b6104616106e9366004613b56565b611579565b61046160165481565b6005546104f2906001600160a01b031681565b610461610718366004613b39565b6001600160a01b031660009081526007602052604090205490565b61046160175481565b610461670de0b6b3a764000081565b6004546104f2906001600160a01b031681565b61046161076c366004613b56565b60009081526011602052604090205490565b610461620186a081565b61051d610796366004613cba565b61182a565b61051d6107a9366004613b39565b611a82565b61047c611b4a565b61051d6107c4366004613dc4565b611b57565b61046160155481565b6104616107e0366004613d26565b611c39565b61046160195481565b6106636107fc366004613d26565b611c92565b61049c61080f366004613a05565b611cae565b610461606481565b61051d61082a366004613df9565b611cbb565b610461601b5481565b61051d610846366004613b39565b611cfd565b601d5461049c9060ff1681565b610461633b9aca0081565b610461611d90565b610461610879366004613b56565b611db9565b600d546104f2906001600160a01b031681565b61051d61089f366004613b56565b611dc7565b61046160185481565b61051d6108bb366004613b6f565b611dfd565b61051d6108ce366004613b56565b611e1a565b610461611e50565b6109156108e9366004613d9f565b601060209081526000928352604080842090915290825290208054600182015460029092015490919083565b6040805193845260208401929092529082015260600161046b565b6104bf61093e366004613a7d565b611f48565b610461610951366004613abf565b6001600160a01b03918216600090815260086020908152604080832093909416825291909152205490565b6104f261098a366004613b6f565b6120b6565b61051d61099d366004613b56565b6120d2565b6106ab6109b0366004613b39565b612108565b610461612339565b61046160135481565b610461601a5481565b61051d6109dd366004613e2b565b6123a6565b6000546104f2906001600160a01b031681565b61051d610a03366004613d26565b6124b4565b610461610a16366004613b56565b60009081526012602052604090205490565b600080610a33612339565b601354909150808211610a7b5760405162461bcd60e51b815260206004820152600b60248201526a2330ba30b61032b93937b960a91b60448201526064015b60405180910390fd5b610a858183613e85565b9250505090565b600a8054610a9990613e98565b80601f0160208091040260200160405190810160405280929190818152602001828054610ac590613e98565b8015610b125780601f10610ae757610100808354040283529160200191610b12565b820191906000526020600020905b815481529060010190602001808311610af557829003601f168201915b505050505081565b6000610b27338484612645565b5060015b92915050565b600080600080610b3f61276a565b600d546001600160a01b031663e0dc1750610b58611e50565b6040518263ffffffff1660e01b8152600401610b7691815260200190565b6060604051808303816000875af1158015610b95573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bb99190613ed2565b50506017546019549091506000805b60ff8116891115610c8457600080600080610c0d888f8f8860ff16818110610bf257610bf2613f00565b9050602002016020810190610c079190613b39565b896127c1565b935093509350935083610c235750505050610c72565b8215610c4757610c33828d613f16565b9b50610c4060018b613f16565b9950610c61565b610c51828c613f16565b9a50610c5e60018a613f16565b98505b610c6b8187613f16565b9550505050505b80610c7c81613f29565b915050610bc8565b508060146000828254610c979190613e85565b92505081905550505050610ca9612936565b92959194509250565b6006546001600160a01b0316158015610cd457506005546001600160a01b0316155b610d0e5760405162461bcd60e51b815260206004820152600b60248201526a125b9a5d1a585b1a5e995960aa1b6044820152606401610a72565b600680546001600160a01b039384166001600160a01b03199182161790915560058054929093169116179055565b600080610d4761146c565b90506000610d5e670de0b6b3a76400006001613f48565b9091111592915050565b610d73828483612979565b600c54610d8190600a614043565b6019556002601a819055601b55610d96611d90565b601855505050565b806001600160a01b031663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ddc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e00919061404f565b6001600160a01b0316336001600160a01b031614610e4f5760405162461bcd60e51b815260206004820152600c60248201526b10b83937bc3c9730b236b4b760a11b6044820152606401610a72565b806001600160a01b031663c1e803346040518163ffffffff1660e01b81526004016020604051808303816000875af1158015610e8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb3919061406c565b15610ee95760405162461bcd60e51b8152600401610a729060208082526004908201526319985a5b60e21b604082015260600190565b50565b6006546001600160a01b03163314610f3b5760405162461bcd60e51b815260206004820152601260248201527154524144494e475f464c4f4f525f4f4e4c5960701b6044820152606401610a72565b600554610f52906001600160a01b03168383612b04565b5050565b6000610f63848484612b63565b6001600160a01b038416600090815260086020908152604080832033845290915290205482811015610fe85760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610a72565b610ff58533858403612645565b60019150505b9392505050565b6000546001600160a01b0316331461102c5760405162461bcd60e51b8152600401610a7290614085565b601681905560055b6040518281527fcb48ce14f4edda961e8a606e8fd9c6562f93440fb820dca0908689c65412abd1906020015b60405180910390a250565b6012602052816000526040600020818154811061108757600080fd5b6000918252602090912001546001600160a01b03169150829050565b6000546001600160a01b031633146110cd5760405162461bcd60e51b8152600401610a7290614085565b601c8190556004611034565b600a80546110e690613e98565b15905080156111015750600b80546110fd90613e98565b1590505b61113b5760405162461bcd60e51b815260206004820152600b60248201526a125b9a5d1a585b1a5e995960aa1b6044820152606401610a72565b600a61114783826140f9565b50600b61115482826140f9565b505050565b6000546001600160a01b031633146111835760405162461bcd60e51b8152600401610a7290614085565b601d805460ff19811660ff9182161590811790925560405191161515907fc9f43b0876da39c7355d8836120531728db6aaced21ca1337740891901ba3dc190600090a2565b6000806111d3612339565b905060008084126111e55760006111f6565b6111f66111f1856141b9565b612d32565b9050600060145460135461120a9190613f16565b9050816112178783613f16565b6112219190613f16565b8310156112345760009350505050610b2b565b81866112408386613e85565b61124a9190613e85565b6112549190613e85565b9695505050505050565b61126661276a565b8281146112a55760405162461bcd60e51b815260206004820152600d60248201526c2141727261794c656e6774687360981b6044820152606401610a72565b600060016017546112b69190613e85565b905060005b60ff811685111561143857600086868360ff168181106112dd576112dd613f00565b90506020020160208101906112f29190613b39565b9050600085858460ff1681811061130b5761130b613f00565b905060200201359050838111156113555760405162461bcd60e51b815260206004820152600e60248201526d22b837b1b4103a37b79039b7b7b760911b6044820152606401610a72565b6000818152600f602090815260408083206001600160a01b038616808552818452828520835180850190945280548452600181018054858701529186529190935283905590829055805160138054929391929091906113b5908490613e85565b909155505080516005546113d6916001600160a01b03909116908590612b04565b80516040516001600160a01b038516917f72d926b894af0cddcbb7e70b67142b7ba4a03a369f678e37baad34e288f435ff9161141a91868252602082015260400190565b60405180910390a2505050808061143090613f29565b9150506112bb565b5050611442612936565b50505050565b6000838152601260205260409020606090611464908484612d5c565b949350505050565b6000806000600d60009054906101000a90046001600160a01b03166001600160a01b031663d370f1d46040518163ffffffff1660e01b81526004016040805180830381865afa1580156114c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114e791906141d5565b915091506000600d60009054906101000a90046001600160a01b03166001600160a01b031663d9cf36ba6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611540573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611564919061406c565b9050611571838383611c39565b935050505090565b600061158361276a565b600e546001600160a01b031633146115c55760405162461bcd60e51b815260206004820152600560248201526404282eae8d60db1b6044820152606401610a72565b60185442101561160e5760405162461bcd60e51b8152602060048201526014602482015273042a8d2daca40e0c2e6e640dccaee40cae0dec6d60631b6044820152606401610a72565b600d5460009081906001600160a01b031663e0dc175061162c611e50565b6040518263ffffffff1660e01b815260040161164a91815260200190565b6060604051808303816000875af1158015611669573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061168d9190613ed2565b50915091506000600d60009054906101000a90046001600160a01b03166001600160a01b031663d9cf36ba6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061170b919061406c565b90506000601754600161171e9190613f16565b600954909150600081810361174257600c5461173b90600a614043565b96506117b3565b6117918861174f87612e46565b61175889612e46565b87611769611764610a28565b612e46565b61177391906141f9565b61177d91906141f9565b6117879190614221565b6111f191906141f9565b9050816117a6670de0b6b3a764000083613f48565b6117b09190614248565b96505b601783905560198790556117c5611d90565b60185560408051848152602081018a905290810188905260608101829052608081018390527f7b504be1b0f48aaf364e873952fa4daf419806a7f85486cdb25d4a61f57f26f49060a00160405180910390a1505050505050611825612936565b919050565b61183261276a565b8281146118715760405162461bcd60e51b815260206004820152600d60248201526c2141727261794c656e6774687360981b6044820152606401610a72565b600d546001600160a01b031663e0dc175061188a611e50565b6040518263ffffffff1660e01b81526004016118a891815260200190565b6060604051808303816000875af11580156118c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118eb9190613ed2565b505050600060016017546118ff9190613e85565b905060005b60ff811685111561143857600086868360ff1681811061192657611926613f00565b905060200201602081019061193b9190613b39565b9050600085858460ff1681811061195457611954613f00565b9050602002013590508381111561199e5760405162461bcd60e51b815260206004820152600e60248201526d22b837b1b4103a37b79039b7b7b760911b6044820152606401610a72565b60008181526010602090815260408083206001600160a01b038616808552818452828520835160608101855281548152600182018054828801526002830180549683019687529388529390955285905590849055839055516014805492939192909190611a0c908490613e85565b90915550508051611a209030908590612b63565b80516040516001600160a01b038516917fd2733907f0171f7e5ccf8333680e9b6f29023e611aa0d8bfb6d295ac3cf44ccd91611a6491868252602082015260400190565b60405180910390a25050508080611a7a90613f29565b915050611904565b6000546001600160a01b03163314611aac5760405162461bcd60e51b8152600401610a7290614085565b6001600160a01b038116611af35760405162461bcd60e51b815260206004820152600e60248201526d496e76616c69644164647265737360901b6044820152606401610a72565b600d80546001600160a01b0319166001600160a01b03831617905560015b6040516001600160a01b03831681527fdab6a10a2b64bf52b6d4f3921f6244f7e050c6a0bc35a77f81b42d0095248ee690602001611060565b600b8054610a9990613e98565b611b5f61276a565b6004805460408051635cecd5ff60e01b815290516001600160a01b0390921692635cecd5ff9282820192602092908290030181865afa158015611ba6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bca919061404f565b6001600160a01b0316336001600160a01b031614611c265760405162461bcd60e51b815260206004820152601960248201527810a634b8bab4b234ba3ca4b73a32b73a39ab32b934b334b2b960391b6044820152606401610a72565b611c31838383612e73565b611154612936565b600083600003611c4b57506000610ffb565b6000611c5784846111c8565b905080600003611c6c57600019915050610ffb565b80611c7f670de0b6b3a764000087613f48565b611c899190614248565b95945050505050565b6000838152601160205260409020606090611464908484612d5c565b6000610b27338484612b63565b611cc361276a565b601d5460ff1615611ce65760405162461bcd60e51b8152600401610a729061426a565b33611cf48186868686613109565b50611442612936565b6000546001600160a01b03163314611d275760405162461bcd60e51b8152600401610a7290614085565b6001600160a01b038116611d6e5760405162461bcd60e51b815260206004820152600e60248201526d496e76616c69644164647265737360901b6044820152606401610a72565b600e80546001600160a01b0319166001600160a01b0383161790556002611b11565b601c5460009081611da18242614248565b905081611daf826001613f16565b610a859190613f48565b6000610b2b601954836132f1565b6000546001600160a01b03163314611df15760405162461bcd60e51b8152600401610a7290614085565b601b8190556003611034565b611e0561276a565b33611e11818484612e73565b50610f52612936565b6000546001600160a01b03163314611e445760405162461bcd60e51b8152600401610a7290614085565b601a8190556002611034565b6000611f43600d60009054906101000a90046001600160a01b03166001600160a01b0316635dc70c776040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ea8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ecc919061406c565b600d60009054906101000a90046001600160a01b03166001600160a01b031663d9cf36ba6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610638919061406c565b905090565b600080600080611f5661276a565b600d546001600160a01b031663e0dc1750611f6f611e50565b6040518263ffffffff1660e01b8152600401611f8d91815260200190565b6060604051808303816000875af1158015611fac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fd09190613ed2565b505060175460195490915060005b60ff8116881115612089576000806000612022868d8d8760ff1681811061200757612007613f00565b905060200201602081019061201c9190613b39565b87613310565b9250925092508261203557505050612077565b811561205957612045818b613f16565b9950612052600189613f16565b9750612073565b612063818a613f16565b9850612070600188613f16565b96505b5050505b8061208181613f29565b915050611fde565b506120948587613f16565b601360008282546120a59190613e85565b925050819055505050610ca9612936565b6011602052816000526040600020818154811061108757600080fd5b6000546001600160a01b031633146120fc5760405162461bcd60e51b8152600401610a7290614085565b60158190556001611034565b6004805460055460405163a8e36e5b60e01b81526001600160a01b03918216938101939093526000928392919091169063a8e36e5b90602401602060405180830381865afa15801561215e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612182919061404f565b6001600160a01b0316336001600160a01b0316146121d15760405162461bcd60e51b815260206004820152600c60248201526b10b332b2b9a6b0b730b3b2b960a11b6044820152606401610a72565b600d546001600160a01b031663e0dc17506121ea611e50565b6040518263ffffffff1660e01b815260040161220891815260200190565b6060604051808303816000875af1158015612227573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061224b9190613ed2565b5050600d546040805163083aeef360e11b815281516001600160a01b039093169350631075dde6926004808301939282900301816000875af1158015612295573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122b991906141d5565b909250905060006122ca8284613f16565b905080156122e9576005546122e9906001600160a01b03168583612b04565b604080516001600160a01b0386168152602081018590529081018390527fcc6cda91f93e55c24ee945dedb481174398b780a07be27f9f420b5411a2590e49060600160405180910390a150915091565b6005546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015612382573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f43919061406c565b6123ae61276a565b6004805460408051635cecd5ff60e01b815290516001600160a01b0390921692635cecd5ff9282820192602092908290030181865afa1580156123f5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612419919061404f565b6001600160a01b0316336001600160a01b0316146124755760405162461bcd60e51b815260206004820152601960248201527810a634b8bab4b234ba3ca4b73a32b73a39ab32b934b334b2b960391b6044820152606401610a72565b601d5460ff16156124985760405162461bcd60e51b8152600401610a729061426a565b6124a58585858585613109565b6124ad612936565b5050505050565b6124bc61276a565b601d5460ff166124de5760405162461bcd60e51b8152600401610a729061426a565b60165483101561250657600b83604051632eb752bf60e21b8152600401610a7292919061428c565b600d546001600160a01b031663e0dc175061251f611e50565b6040518263ffffffff1660e01b815260040161253d91815260200190565b6060604051808303816000875af115801561255c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125809190613ed2565b503391506125909050818561343d565b600061259b85611db9565b90506125a78282613584565b60408051868152602081018390526001600160a01b038416917f44b0aec0c46855b77340001dff75f91304dea1799518c36af2d9bec5dae2738c910160405180910390a2816001600160a01b031683857f7ba502a6e8d9c35b8430a91efccdff6928f2e0aca8193f08d0e34c02ff51cbd688601754604051612633929190918252602082015260400190565b60405180910390a45050611154612936565b6001600160a01b0383166126a75760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610a72565b6001600160a01b0382166127085760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610a72565b6001600160a01b0383811660008181526008602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6004805460408051637c1e845d60e11b815290516001600160a01b039092169263f83d08ba92828201926000929082900301818387803b1580156127ad57600080fd5b505af1158015611442573d6000803e3d6000fd5b60008381526010602090815260408083206001600160a01b03861684528252808320815160608101835281548082526001830154948201949094526002909101549181019190915282918291829182036128295760008060008094509450945094505061292d565b60008881526010602090815260408083206001600160a01b038b168452909152812081815560018181018390556002909101829055825190965061286e908890613663565b90506000818360400151106128835781612889565b82604001515b9050826020015181106128c4576128a4308460000151613678565b6005546128bb906001600160a01b03168a83612b04565b600195506128d8565b6128d3308a8560000151612b63565b600095505b8251604080850151815189151581526020810184905292975095506001600160a01b038b16917ff88a20f7519d20766db2ee9136f3dff5afe20494c2d786e0475f1d94af09c5ad910160405180910390a25050505b93509350935093565b60048054604080516340da020f60e01b815290516001600160a01b03909216926340da020f92828201926000929082900301818387803b1580156127ad57600080fd5b612a8b826001600160a01b03166395d89b416040518163ffffffff1660e01b8152600401600060405180830381865afa1580156129ba573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526129e291908101906142b8565b6040516020016129f29190614326565b604051602081830303815290604052836001600160a01b03166395d89b416040518163ffffffff1660e01b8152600401600060405180830381865afa158015612a3f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6791908101906142b8565b604051602001612a779190614356565b6040516020818303038152906040526110d9565b612a958383610cb2565b816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ad3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612af79190614380565b60ff16600c55601c555050565b6040516001600160a01b0383811660248301526044820183905261115491859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506137be565b6001600160a01b038316612bc75760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610a72565b6001600160a01b038216612c295760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610a72565b6001600160a01b03831660009081526007602052604090205481811015612ca15760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610a72565b6001600160a01b03808516600090815260076020526040808220858503905591851681529081208054849290612cd8908490613f16565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051612d2491815260200190565b60405180910390a350505050565b600080821215612d5857604051635467221960e11b815260048101839052602401610a72565b5090565b8254606090600090612d6f908590613e85565b9050808310612d7e5780612d80565b825b92508267ffffffffffffffff811115612d9b57612d9b613b91565b604051908082528060200260200182016040528015612dc4578160200160208202803683370190505b50915060005b83811015612e3d5785612ddd8287613f16565b81548110612ded57612ded613f00565b9060005260206000200160009054906101000a90046001600160a01b0316838281518110612e1d57612e1d613f00565b6001600160a01b0390921660209283029190910190910152600101612dca565b50509392505050565b60006001600160ff1b03821115612d585760405163123baf0360e11b815260048101839052602401610a72565b6000601b54601754612e859190613f16565b6000818152600f602090815260408083206001600160a01b038916845290915290205490915015612ee95760405162461bcd60e51b815260206004820152600e60248201526d115e1a5cdd1cc819195c1bdcda5d60921b6044820152606401610a72565b600d546001600160a01b031663e0dc1750612f02611e50565b6040518263ffffffff1660e01b8152600401612f2091815260200190565b6060604051808303816000875af1158015612f3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f639190613ed2565b505050612f71843085612b63565b6019546000612f808286613663565b905080841115612fca5760405162461bcd60e51b815260206004820152601560248201527409ad2dc82dadeeadce89eeae840e8dede40d0d2ced605b1b6044820152606401610a72565b6000620186a0601554620186a0612fe19190613f16565b612feb9084613f48565b612ff59190614248565b905080601460008282546130099190613f16565b909155506130179050613821565b60008481526010602090815260408083206001600160a01b038b1684529091528120805490910361307a5760008581526012602090815260408220805460018101825590835291200180546001600160a01b0319166001600160a01b038a161790555b8054613087908890613f16565b81556001810154613099908790613f16565b600182015560028101546130ae908390613f16565b600282015560408051888152602081018890529081018690526001600160a01b038916907f69827d824993c5fce39851a711a15efc9b98133015a018c84f13340521e7adce9060600160405180910390a25050505050505050565b60165484101561313157600b84604051632eb752bf60e21b8152600401610a7292919061428c565b6000601a546017546131439190613f16565b60008181526010602090815260408083206001600160a01b038b168452909152902054909150156131a65760405162461bcd60e51b815260206004820152600d60248201526c52656465656d2065786973747360981b6044820152606401610a72565b6131b0868661343d565b84601360008282546131c29190613f16565b90915550506000818152600f602090815260408083206001600160a01b038a1684529091528120805490910361322a5760008281526011602090815260408220805460018101825590835291200180546001600160a01b0319166001600160a01b0389161790555b8054613237908790613f16565b81556001810154613249908690613f16565b600182015560408051878152602081018790529081018390526001600160a01b038816907f05204c412c9232d14ad1bb18ac9118f4a7e10c8a2d8eca85693d9388a6aac96b9060600160405180910390a2866001600160a01b031683857f7ba502a6e8d9c35b8430a91efccdff6928f2e0aca8193f08d0e34c02ff51cbd689866040516132e0929190918252602082015260400190565b60405180910390a450505050505050565b600082613306670de0b6b3a764000084613f48565b610ffb9190614248565b6000838152600f602090815260408083206001600160a01b0386168452825280832081518083019092528054808352600190910154928201929092528291829190820361336857600080600093509350935050613434565b6000878152600f602090815260408083206001600160a01b038a1684529091528120818155600190810182905582519095506133a59087906132f1565b9050816020015181106133c5576133bc8782613584565b600193506133e6565b81516005546133e1916001600160a01b03909116908990612b04565b600093505b8151604080518615158152602081018390529194506001600160a01b038916917fe0658942d1f815976a88ef2c4f1b8d5d0ff7f83c1cde078f60e39b08069bd55c910160405180910390a250505b93509350939050565b6005546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015613486573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134aa919061406c565b6005549091506134c5906001600160a01b0316843085613868565b6005546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa15801561350e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613532919061406c565b90508261353f8383613e85565b146114425760405162461bcd60e51b815260206004820152601560248201527411125117d393d517d49150d152559157d1561050d5605a1b6044820152606401610a72565b6001600160a01b0382166135da5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610a72565b80600960008282546135ec9190613f16565b90915550506001600160a01b03821660009081526007602052604081208054839290613619908490613f16565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6000670de0b6b3a76400006133068484613f48565b6001600160a01b0382166136d85760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610a72565b6001600160a01b0382166000908152600760205260409020548181101561374c5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610a72565b6001600160a01b038316600090815260076020526040812083830390556009805484929061377b908490613e85565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200161275d565b60006137d36001600160a01b038416836138a1565b905080516000141580156137f85750808060200190518101906137f691906143a3565b155b1561115457604051635274afe760e01b81526001600160a01b0384166004820152602401610a72565b613829610d3c565b6138665760405162461bcd60e51b815260206004820152600e60248201526d2628103aba34b634bd30ba34b7b760911b6044820152606401610a72565b565b6040516001600160a01b0384811660248301528381166044830152606482018390526114429186918216906323b872dd90608401612b31565b6060610ffb8383600084600080856001600160a01b031684866040516138c791906143c5565b60006040518083038185875af1925050503d8060008114613904576040519150601f19603f3d011682016040523d82523d6000602084013e613909565b606091505b50915091506112548683836060826139295761392482613970565b610ffb565b815115801561394057506001600160a01b0384163b155b1561396957604051639996b31560e01b81526001600160a01b0385166004820152602401610a72565b5080610ffb565b8051156139805780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b60005b838110156139b457818101518382015260200161399c565b50506000910152565b60208152600082518060208401526139dc816040850160208701613999565b601f01601f19169190910160400192915050565b6001600160a01b0381168114610ee957600080fd5b60008060408385031215613a1857600080fd5b8235613a23816139f0565b946020939093013593505050565b60008083601f840112613a4357600080fd5b50813567ffffffffffffffff811115613a5b57600080fd5b6020830191508360208260051b8501011115613a7657600080fd5b9250929050565b60008060208385031215613a9057600080fd5b823567ffffffffffffffff811115613aa757600080fd5b613ab385828601613a31565b90969095509350505050565b60008060408385031215613ad257600080fd5b8235613add816139f0565b91506020830135613aed816139f0565b809150509250929050565b600080600060608486031215613b0d57600080fd5b8335613b18816139f0565b92506020840135613b28816139f0565b929592945050506040919091013590565b600060208284031215613b4b57600080fd5b8135610ffb816139f0565b600060208284031215613b6857600080fd5b5035919050565b60008060408385031215613b8257600080fd5b50508035926020909101359150565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715613bd057613bd0613b91565b604052919050565b600067ffffffffffffffff821115613bf257613bf2613b91565b50601f01601f191660200190565b600082601f830112613c1157600080fd5b8135613c24613c1f82613bd8565b613ba7565b818152846020838601011115613c3957600080fd5b816020850160208301376000918101602001919091529392505050565b60008060408385031215613c6957600080fd5b823567ffffffffffffffff80821115613c8157600080fd5b613c8d86838701613c00565b93506020850135915080821115613ca357600080fd5b50613cb085828601613c00565b9150509250929050565b60008060008060408587031215613cd057600080fd5b843567ffffffffffffffff80821115613ce857600080fd5b613cf488838901613a31565b90965094506020870135915080821115613d0d57600080fd5b50613d1a87828801613a31565b95989497509550505050565b600080600060608486031215613d3b57600080fd5b505081359360208301359350604090920135919050565b6020808252825182820181905260009190848201906040850190845b81811015613d935783516001600160a01b031683529284019291840191600101613d6e565b50909695505050505050565b60008060408385031215613db257600080fd5b823591506020830135613aed816139f0565b600080600060608486031215613dd957600080fd5b8335613de4816139f0565b95602085013595506040909401359392505050565b60008060008060808587031215613e0f57600080fd5b5050823594602084013594506040840135936060013592509050565b600080600080600060a08688031215613e4357600080fd5b8535613e4e816139f0565b97602087013597506040870135966060810135965060800135945092505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610b2b57610b2b613e6f565b600181811c90821680613eac57607f821691505b602082108103613ecc57634e487b7160e01b600052602260045260246000fd5b50919050565b600080600060608486031215613ee757600080fd5b8351925060208401519150604084015190509250925092565b634e487b7160e01b600052603260045260246000fd5b80820180821115610b2b57610b2b613e6f565b600060ff821660ff8103613f3f57613f3f613e6f565b60010192915050565b8082028115828204841417610b2b57610b2b613e6f565b600181815b80851115613f9a578160001904821115613f8057613f80613e6f565b80851615613f8d57918102915b93841c9390800290613f64565b509250929050565b600082613fb157506001610b2b565b81613fbe57506000610b2b565b8160018114613fd45760028114613fde57613ffa565b6001915050610b2b565b60ff841115613fef57613fef613e6f565b50506001821b610b2b565b5060208310610133831016604e8410600b841016171561401d575081810a610b2b565b6140278383613f5f565b806000190482111561403b5761403b613e6f565b029392505050565b6000610ffb8383613fa2565b60006020828403121561406157600080fd5b8151610ffb816139f0565b60006020828403121561407e57600080fd5b5051919050565b6020808252600a908201526927a7262cafa0a226a4a760b11b604082015260600190565b601f821115611154576000816000526020600020601f850160051c810160208610156140d25750805b601f850160051c820191505b818110156140f1578281556001016140de565b505050505050565b815167ffffffffffffffff81111561411357614113613b91565b614127816141218454613e98565b846140a9565b602080601f83116001811461415c57600084156141445750858301515b600019600386901b1c1916600185901b1785556140f1565b600085815260208120601f198616915b8281101561418b5788860151825594840194600190910190840161416c565b50858210156141a95787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6000600160ff1b82016141ce576141ce613e6f565b5060000390565b600080604083850312156141e857600080fd5b505080516020909101519092909150565b808201828112600083128015821682158216171561421957614219613e6f565b505092915050565b818103600083128015838313168383128216171561424157614241613e6f565b5092915050565b60008261426557634e487b7160e01b600052601260045260246000fd5b500490565b60208082526008908201526708505b1b1bddd95960c21b604082015260600190565b60408101601284106142ae57634e487b7160e01b600052602160045260246000fd5b9281526020015290565b6000602082840312156142ca57600080fd5b815167ffffffffffffffff8111156142e157600080fd5b8201601f810184136142f257600080fd5b8051614300613c1f82613bd8565b81815285602083850101111561431557600080fd5b611c89826020830160208601613999565b670263cb73c102628160c51b815260008251614349816008850160208701613999565b9190910160080192915050565b610d8f60f31b815260008251614373816002850160208701613999565b9190910160020192915050565b60006020828403121561439257600080fd5b815160ff81168114610ffb57600080fd5b6000602082840312156143b557600080fd5b81518015158114610ffb57600080fd5b600082516143d7818460208701613999565b919091019291505056fea264697066735822122060616af47ed6cb1468e4a8400509af9cbe7ed04b4b4d3cb6821cecb82e8e725b64736f6c63430008180033
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106104545760003560e01c806380193b2611610241578063c12d636b1161013b578063e1618fe8116100c3578063ef693fe411610087578063ef693fe4146109c6578063f2fc6e66146109cf578063f851a440146109e2578063f87fc31c146109f5578063ff9d4ff314610a0857600080fd5b8063e1618fe81461097c578063e5abb5a51461098f578063eb449c2f146109a2578063eb6ced71146109b5578063eda6d6be146109bd57600080fd5b8063cb5460fd1161010a578063cb5460fd146108c0578063d03bfffd146108d3578063d3c5b5f8146108db578063d3fd3cf514610930578063dd62ed3e1461094357600080fd5b8063c12d636b1461087e578063c6775bad14610891578063c6b27f24146108a4578063c87d7e8d146108ad57600080fd5b8063a9059cbb116101c9578063b225018d1161018d578063b225018d14610838578063b407153c1461084b578063b71f3cfe14610858578063baf7fdd614610863578063bd3658e61461086b57600080fd5b8063a9059cbb14610801578063aaf5eb681461073c578063ad1f2b5614610814578063af8a89ce1461081c578063b16e49b31461082f57600080fd5b80639980a5f3116102105780639980a5f3146107b65780639b27168b146107c95780639bb7d707146107d2578063a3684977146107e5578063a7227981146107ee57600080fd5b806380193b261461077e57806392c51a7e1461078857806394870a541461079b57806395d89b41146107ae57600080fd5b8063313ce567116103525780635c60da1b116102da57806370a082311161029e57806370a082311461070a578063766718081461073357806379c80dc21461073c5780637b1039991461074b5780637bd1bf0c1461075e57600080fd5b80635c60da1b146106c057806360f3da41146106d357806361428953146106db578063645006ca146106ee5780636f307dc3146106f757600080fd5b80633ce9a294116103215780633ce9a2941461062a578063414a831f1461063d578063470aad06146106505780634ff0876a1461067057806356ef801b1461067957600080fd5b8063313ce567146105ed5780633233c5e3146105fc578063396f7b231461060f5780633a8f09f31461062257600080fd5b80631d504dc6116103e057806326782247116103a457806326782247146105985780632a80cda3146105ab5780632c5b1066146105be5780632d4138c1146105c757806330024dfe146105da57600080fd5b80631d504dc61461054357806321d491131461055657806323b872dd1461056957806323c874201461057c57806325a760c21461058f57600080fd5b80630d3b0b76116104275780630d3b0b76146104df57806312a45f651461050a578063149673191461051f5780631794bb3c1461052757806318160ddd1461053a57600080fd5b8063022dced21461045957806306fdde0314610474578063095ea7b314610489578063098ee6f2146104ac575b600080fd5b610461610a28565b6040519081526020015b60405180910390f35b61047c610a8c565b60405161046b91906139bd565b61049c610497366004613a05565b610b1a565b604051901515815260200161046b565b6104bf6104ba366004613a7d565b610b31565b60408051948552602085019390935291830152606082015260800161046b565b6006546104f2906001600160a01b031681565b6040516001600160a01b03909116815260200161046b565b61051d610518366004613abf565b610cb2565b005b61049c610d3c565b61051d610535366004613af8565b610d68565b61046160095481565b61051d610551366004613b39565b610d9e565b61051d610564366004613a05565b610eec565b61049c610577366004613af8565b610f56565b600e546104f2906001600160a01b031681565b610461600c5481565b6001546104f2906001600160a01b031681565b61051d6105b9366004613b56565b611002565b61046160145481565b6104f26105d5366004613b6f565b61106b565b61051d6105e8366004613b56565b6110a3565b6040516012815260200161046b565b61051d61060a366004613c56565b6110d9565b6003546104f2906001600160a01b031681565b61051d611159565b610461610638366004613b6f565b6111c8565b61051d61064b366004613cba565b61125e565b61066361065e366004613d26565b611448565b60405161046b9190613d52565b610461601c5481565b6106ab610687366004613d9f565b600f6020908152600092835260408084209091529082529020805460019091015482565b6040805192835260208301919091520161046b565b6002546104f2906001600160a01b031681565b61046161146c565b6104616106e9366004613b56565b611579565b61046160165481565b6005546104f2906001600160a01b031681565b610461610718366004613b39565b6001600160a01b031660009081526007602052604090205490565b61046160175481565b610461670de0b6b3a764000081565b6004546104f2906001600160a01b031681565b61046161076c366004613b56565b60009081526011602052604090205490565b610461620186a081565b61051d610796366004613cba565b61182a565b61051d6107a9366004613b39565b611a82565b61047c611b4a565b61051d6107c4366004613dc4565b611b57565b61046160155481565b6104616107e0366004613d26565b611c39565b61046160195481565b6106636107fc366004613d26565b611c92565b61049c61080f366004613a05565b611cae565b610461606481565b61051d61082a366004613df9565b611cbb565b610461601b5481565b61051d610846366004613b39565b611cfd565b601d5461049c9060ff1681565b610461633b9aca0081565b610461611d90565b610461610879366004613b56565b611db9565b600d546104f2906001600160a01b031681565b61051d61089f366004613b56565b611dc7565b61046160185481565b61051d6108bb366004613b6f565b611dfd565b61051d6108ce366004613b56565b611e1a565b610461611e50565b6109156108e9366004613d9f565b601060209081526000928352604080842090915290825290208054600182015460029092015490919083565b6040805193845260208401929092529082015260600161046b565b6104bf61093e366004613a7d565b611f48565b610461610951366004613abf565b6001600160a01b03918216600090815260086020908152604080832093909416825291909152205490565b6104f261098a366004613b6f565b6120b6565b61051d61099d366004613b56565b6120d2565b6106ab6109b0366004613b39565b612108565b610461612339565b61046160135481565b610461601a5481565b61051d6109dd366004613e2b565b6123a6565b6000546104f2906001600160a01b031681565b61051d610a03366004613d26565b6124b4565b610461610a16366004613b56565b60009081526012602052604090205490565b600080610a33612339565b601354909150808211610a7b5760405162461bcd60e51b815260206004820152600b60248201526a2330ba30b61032b93937b960a91b60448201526064015b60405180910390fd5b610a858183613e85565b9250505090565b600a8054610a9990613e98565b80601f0160208091040260200160405190810160405280929190818152602001828054610ac590613e98565b8015610b125780601f10610ae757610100808354040283529160200191610b12565b820191906000526020600020905b815481529060010190602001808311610af557829003601f168201915b505050505081565b6000610b27338484612645565b5060015b92915050565b600080600080610b3f61276a565b600d546001600160a01b031663e0dc1750610b58611e50565b6040518263ffffffff1660e01b8152600401610b7691815260200190565b6060604051808303816000875af1158015610b95573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bb99190613ed2565b50506017546019549091506000805b60ff8116891115610c8457600080600080610c0d888f8f8860ff16818110610bf257610bf2613f00565b9050602002016020810190610c079190613b39565b896127c1565b935093509350935083610c235750505050610c72565b8215610c4757610c33828d613f16565b9b50610c4060018b613f16565b9950610c61565b610c51828c613f16565b9a50610c5e60018a613f16565b98505b610c6b8187613f16565b9550505050505b80610c7c81613f29565b915050610bc8565b508060146000828254610c979190613e85565b92505081905550505050610ca9612936565b92959194509250565b6006546001600160a01b0316158015610cd457506005546001600160a01b0316155b610d0e5760405162461bcd60e51b815260206004820152600b60248201526a125b9a5d1a585b1a5e995960aa1b6044820152606401610a72565b600680546001600160a01b039384166001600160a01b03199182161790915560058054929093169116179055565b600080610d4761146c565b90506000610d5e670de0b6b3a76400006001613f48565b9091111592915050565b610d73828483612979565b600c54610d8190600a614043565b6019556002601a819055601b55610d96611d90565b601855505050565b806001600160a01b031663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ddc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e00919061404f565b6001600160a01b0316336001600160a01b031614610e4f5760405162461bcd60e51b815260206004820152600c60248201526b10b83937bc3c9730b236b4b760a11b6044820152606401610a72565b806001600160a01b031663c1e803346040518163ffffffff1660e01b81526004016020604051808303816000875af1158015610e8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb3919061406c565b15610ee95760405162461bcd60e51b8152600401610a729060208082526004908201526319985a5b60e21b604082015260600190565b50565b6006546001600160a01b03163314610f3b5760405162461bcd60e51b815260206004820152601260248201527154524144494e475f464c4f4f525f4f4e4c5960701b6044820152606401610a72565b600554610f52906001600160a01b03168383612b04565b5050565b6000610f63848484612b63565b6001600160a01b038416600090815260086020908152604080832033845290915290205482811015610fe85760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610a72565b610ff58533858403612645565b60019150505b9392505050565b6000546001600160a01b0316331461102c5760405162461bcd60e51b8152600401610a7290614085565b601681905560055b6040518281527fcb48ce14f4edda961e8a606e8fd9c6562f93440fb820dca0908689c65412abd1906020015b60405180910390a250565b6012602052816000526040600020818154811061108757600080fd5b6000918252602090912001546001600160a01b03169150829050565b6000546001600160a01b031633146110cd5760405162461bcd60e51b8152600401610a7290614085565b601c8190556004611034565b600a80546110e690613e98565b15905080156111015750600b80546110fd90613e98565b1590505b61113b5760405162461bcd60e51b815260206004820152600b60248201526a125b9a5d1a585b1a5e995960aa1b6044820152606401610a72565b600a61114783826140f9565b50600b61115482826140f9565b505050565b6000546001600160a01b031633146111835760405162461bcd60e51b8152600401610a7290614085565b601d805460ff19811660ff9182161590811790925560405191161515907fc9f43b0876da39c7355d8836120531728db6aaced21ca1337740891901ba3dc190600090a2565b6000806111d3612339565b905060008084126111e55760006111f6565b6111f66111f1856141b9565b612d32565b9050600060145460135461120a9190613f16565b9050816112178783613f16565b6112219190613f16565b8310156112345760009350505050610b2b565b81866112408386613e85565b61124a9190613e85565b6112549190613e85565b9695505050505050565b61126661276a565b8281146112a55760405162461bcd60e51b815260206004820152600d60248201526c2141727261794c656e6774687360981b6044820152606401610a72565b600060016017546112b69190613e85565b905060005b60ff811685111561143857600086868360ff168181106112dd576112dd613f00565b90506020020160208101906112f29190613b39565b9050600085858460ff1681811061130b5761130b613f00565b905060200201359050838111156113555760405162461bcd60e51b815260206004820152600e60248201526d22b837b1b4103a37b79039b7b7b760911b6044820152606401610a72565b6000818152600f602090815260408083206001600160a01b038616808552818452828520835180850190945280548452600181018054858701529186529190935283905590829055805160138054929391929091906113b5908490613e85565b909155505080516005546113d6916001600160a01b03909116908590612b04565b80516040516001600160a01b038516917f72d926b894af0cddcbb7e70b67142b7ba4a03a369f678e37baad34e288f435ff9161141a91868252602082015260400190565b60405180910390a2505050808061143090613f29565b9150506112bb565b5050611442612936565b50505050565b6000838152601260205260409020606090611464908484612d5c565b949350505050565b6000806000600d60009054906101000a90046001600160a01b03166001600160a01b031663d370f1d46040518163ffffffff1660e01b81526004016040805180830381865afa1580156114c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114e791906141d5565b915091506000600d60009054906101000a90046001600160a01b03166001600160a01b031663d9cf36ba6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611540573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611564919061406c565b9050611571838383611c39565b935050505090565b600061158361276a565b600e546001600160a01b031633146115c55760405162461bcd60e51b815260206004820152600560248201526404282eae8d60db1b6044820152606401610a72565b60185442101561160e5760405162461bcd60e51b8152602060048201526014602482015273042a8d2daca40e0c2e6e640dccaee40cae0dec6d60631b6044820152606401610a72565b600d5460009081906001600160a01b031663e0dc175061162c611e50565b6040518263ffffffff1660e01b815260040161164a91815260200190565b6060604051808303816000875af1158015611669573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061168d9190613ed2565b50915091506000600d60009054906101000a90046001600160a01b03166001600160a01b031663d9cf36ba6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061170b919061406c565b90506000601754600161171e9190613f16565b600954909150600081810361174257600c5461173b90600a614043565b96506117b3565b6117918861174f87612e46565b61175889612e46565b87611769611764610a28565b612e46565b61177391906141f9565b61177d91906141f9565b6117879190614221565b6111f191906141f9565b9050816117a6670de0b6b3a764000083613f48565b6117b09190614248565b96505b601783905560198790556117c5611d90565b60185560408051848152602081018a905290810188905260608101829052608081018390527f7b504be1b0f48aaf364e873952fa4daf419806a7f85486cdb25d4a61f57f26f49060a00160405180910390a1505050505050611825612936565b919050565b61183261276a565b8281146118715760405162461bcd60e51b815260206004820152600d60248201526c2141727261794c656e6774687360981b6044820152606401610a72565b600d546001600160a01b031663e0dc175061188a611e50565b6040518263ffffffff1660e01b81526004016118a891815260200190565b6060604051808303816000875af11580156118c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118eb9190613ed2565b505050600060016017546118ff9190613e85565b905060005b60ff811685111561143857600086868360ff1681811061192657611926613f00565b905060200201602081019061193b9190613b39565b9050600085858460ff1681811061195457611954613f00565b9050602002013590508381111561199e5760405162461bcd60e51b815260206004820152600e60248201526d22b837b1b4103a37b79039b7b7b760911b6044820152606401610a72565b60008181526010602090815260408083206001600160a01b038616808552818452828520835160608101855281548152600182018054828801526002830180549683019687529388529390955285905590849055839055516014805492939192909190611a0c908490613e85565b90915550508051611a209030908590612b63565b80516040516001600160a01b038516917fd2733907f0171f7e5ccf8333680e9b6f29023e611aa0d8bfb6d295ac3cf44ccd91611a6491868252602082015260400190565b60405180910390a25050508080611a7a90613f29565b915050611904565b6000546001600160a01b03163314611aac5760405162461bcd60e51b8152600401610a7290614085565b6001600160a01b038116611af35760405162461bcd60e51b815260206004820152600e60248201526d496e76616c69644164647265737360901b6044820152606401610a72565b600d80546001600160a01b0319166001600160a01b03831617905560015b6040516001600160a01b03831681527fdab6a10a2b64bf52b6d4f3921f6244f7e050c6a0bc35a77f81b42d0095248ee690602001611060565b600b8054610a9990613e98565b611b5f61276a565b6004805460408051635cecd5ff60e01b815290516001600160a01b0390921692635cecd5ff9282820192602092908290030181865afa158015611ba6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bca919061404f565b6001600160a01b0316336001600160a01b031614611c265760405162461bcd60e51b815260206004820152601960248201527810a634b8bab4b234ba3ca4b73a32b73a39ab32b934b334b2b960391b6044820152606401610a72565b611c31838383612e73565b611154612936565b600083600003611c4b57506000610ffb565b6000611c5784846111c8565b905080600003611c6c57600019915050610ffb565b80611c7f670de0b6b3a764000087613f48565b611c899190614248565b95945050505050565b6000838152601160205260409020606090611464908484612d5c565b6000610b27338484612b63565b611cc361276a565b601d5460ff1615611ce65760405162461bcd60e51b8152600401610a729061426a565b33611cf48186868686613109565b50611442612936565b6000546001600160a01b03163314611d275760405162461bcd60e51b8152600401610a7290614085565b6001600160a01b038116611d6e5760405162461bcd60e51b815260206004820152600e60248201526d496e76616c69644164647265737360901b6044820152606401610a72565b600e80546001600160a01b0319166001600160a01b0383161790556002611b11565b601c5460009081611da18242614248565b905081611daf826001613f16565b610a859190613f48565b6000610b2b601954836132f1565b6000546001600160a01b03163314611df15760405162461bcd60e51b8152600401610a7290614085565b601b8190556003611034565b611e0561276a565b33611e11818484612e73565b50610f52612936565b6000546001600160a01b03163314611e445760405162461bcd60e51b8152600401610a7290614085565b601a8190556002611034565b6000611f43600d60009054906101000a90046001600160a01b03166001600160a01b0316635dc70c776040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ea8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ecc919061406c565b600d60009054906101000a90046001600160a01b03166001600160a01b031663d9cf36ba6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610638919061406c565b905090565b600080600080611f5661276a565b600d546001600160a01b031663e0dc1750611f6f611e50565b6040518263ffffffff1660e01b8152600401611f8d91815260200190565b6060604051808303816000875af1158015611fac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fd09190613ed2565b505060175460195490915060005b60ff8116881115612089576000806000612022868d8d8760ff1681811061200757612007613f00565b905060200201602081019061201c9190613b39565b87613310565b9250925092508261203557505050612077565b811561205957612045818b613f16565b9950612052600189613f16565b9750612073565b612063818a613f16565b9850612070600188613f16565b96505b5050505b8061208181613f29565b915050611fde565b506120948587613f16565b601360008282546120a59190613e85565b925050819055505050610ca9612936565b6011602052816000526040600020818154811061108757600080fd5b6000546001600160a01b031633146120fc5760405162461bcd60e51b8152600401610a7290614085565b60158190556001611034565b6004805460055460405163a8e36e5b60e01b81526001600160a01b03918216938101939093526000928392919091169063a8e36e5b90602401602060405180830381865afa15801561215e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612182919061404f565b6001600160a01b0316336001600160a01b0316146121d15760405162461bcd60e51b815260206004820152600c60248201526b10b332b2b9a6b0b730b3b2b960a11b6044820152606401610a72565b600d546001600160a01b031663e0dc17506121ea611e50565b6040518263ffffffff1660e01b815260040161220891815260200190565b6060604051808303816000875af1158015612227573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061224b9190613ed2565b5050600d546040805163083aeef360e11b815281516001600160a01b039093169350631075dde6926004808301939282900301816000875af1158015612295573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122b991906141d5565b909250905060006122ca8284613f16565b905080156122e9576005546122e9906001600160a01b03168583612b04565b604080516001600160a01b0386168152602081018590529081018390527fcc6cda91f93e55c24ee945dedb481174398b780a07be27f9f420b5411a2590e49060600160405180910390a150915091565b6005546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015612382573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f43919061406c565b6123ae61276a565b6004805460408051635cecd5ff60e01b815290516001600160a01b0390921692635cecd5ff9282820192602092908290030181865afa1580156123f5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612419919061404f565b6001600160a01b0316336001600160a01b0316146124755760405162461bcd60e51b815260206004820152601960248201527810a634b8bab4b234ba3ca4b73a32b73a39ab32b934b334b2b960391b6044820152606401610a72565b601d5460ff16156124985760405162461bcd60e51b8152600401610a729061426a565b6124a58585858585613109565b6124ad612936565b5050505050565b6124bc61276a565b601d5460ff166124de5760405162461bcd60e51b8152600401610a729061426a565b60165483101561250657600b83604051632eb752bf60e21b8152600401610a7292919061428c565b600d546001600160a01b031663e0dc175061251f611e50565b6040518263ffffffff1660e01b815260040161253d91815260200190565b6060604051808303816000875af115801561255c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125809190613ed2565b503391506125909050818561343d565b600061259b85611db9565b90506125a78282613584565b60408051868152602081018390526001600160a01b038416917f44b0aec0c46855b77340001dff75f91304dea1799518c36af2d9bec5dae2738c910160405180910390a2816001600160a01b031683857f7ba502a6e8d9c35b8430a91efccdff6928f2e0aca8193f08d0e34c02ff51cbd688601754604051612633929190918252602082015260400190565b60405180910390a45050611154612936565b6001600160a01b0383166126a75760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610a72565b6001600160a01b0382166127085760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610a72565b6001600160a01b0383811660008181526008602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6004805460408051637c1e845d60e11b815290516001600160a01b039092169263f83d08ba92828201926000929082900301818387803b1580156127ad57600080fd5b505af1158015611442573d6000803e3d6000fd5b60008381526010602090815260408083206001600160a01b03861684528252808320815160608101835281548082526001830154948201949094526002909101549181019190915282918291829182036128295760008060008094509450945094505061292d565b60008881526010602090815260408083206001600160a01b038b168452909152812081815560018181018390556002909101829055825190965061286e908890613663565b90506000818360400151106128835781612889565b82604001515b9050826020015181106128c4576128a4308460000151613678565b6005546128bb906001600160a01b03168a83612b04565b600195506128d8565b6128d3308a8560000151612b63565b600095505b8251604080850151815189151581526020810184905292975095506001600160a01b038b16917ff88a20f7519d20766db2ee9136f3dff5afe20494c2d786e0475f1d94af09c5ad910160405180910390a25050505b93509350935093565b60048054604080516340da020f60e01b815290516001600160a01b03909216926340da020f92828201926000929082900301818387803b1580156127ad57600080fd5b612a8b826001600160a01b03166395d89b416040518163ffffffff1660e01b8152600401600060405180830381865afa1580156129ba573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526129e291908101906142b8565b6040516020016129f29190614326565b604051602081830303815290604052836001600160a01b03166395d89b416040518163ffffffff1660e01b8152600401600060405180830381865afa158015612a3f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6791908101906142b8565b604051602001612a779190614356565b6040516020818303038152906040526110d9565b612a958383610cb2565b816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ad3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612af79190614380565b60ff16600c55601c555050565b6040516001600160a01b0383811660248301526044820183905261115491859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506137be565b6001600160a01b038316612bc75760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610a72565b6001600160a01b038216612c295760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610a72565b6001600160a01b03831660009081526007602052604090205481811015612ca15760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610a72565b6001600160a01b03808516600090815260076020526040808220858503905591851681529081208054849290612cd8908490613f16565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051612d2491815260200190565b60405180910390a350505050565b600080821215612d5857604051635467221960e11b815260048101839052602401610a72565b5090565b8254606090600090612d6f908590613e85565b9050808310612d7e5780612d80565b825b92508267ffffffffffffffff811115612d9b57612d9b613b91565b604051908082528060200260200182016040528015612dc4578160200160208202803683370190505b50915060005b83811015612e3d5785612ddd8287613f16565b81548110612ded57612ded613f00565b9060005260206000200160009054906101000a90046001600160a01b0316838281518110612e1d57612e1d613f00565b6001600160a01b0390921660209283029190910190910152600101612dca565b50509392505050565b60006001600160ff1b03821115612d585760405163123baf0360e11b815260048101839052602401610a72565b6000601b54601754612e859190613f16565b6000818152600f602090815260408083206001600160a01b038916845290915290205490915015612ee95760405162461bcd60e51b815260206004820152600e60248201526d115e1a5cdd1cc819195c1bdcda5d60921b6044820152606401610a72565b600d546001600160a01b031663e0dc1750612f02611e50565b6040518263ffffffff1660e01b8152600401612f2091815260200190565b6060604051808303816000875af1158015612f3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f639190613ed2565b505050612f71843085612b63565b6019546000612f808286613663565b905080841115612fca5760405162461bcd60e51b815260206004820152601560248201527409ad2dc82dadeeadce89eeae840e8dede40d0d2ced605b1b6044820152606401610a72565b6000620186a0601554620186a0612fe19190613f16565b612feb9084613f48565b612ff59190614248565b905080601460008282546130099190613f16565b909155506130179050613821565b60008481526010602090815260408083206001600160a01b038b1684529091528120805490910361307a5760008581526012602090815260408220805460018101825590835291200180546001600160a01b0319166001600160a01b038a161790555b8054613087908890613f16565b81556001810154613099908790613f16565b600182015560028101546130ae908390613f16565b600282015560408051888152602081018890529081018690526001600160a01b038916907f69827d824993c5fce39851a711a15efc9b98133015a018c84f13340521e7adce9060600160405180910390a25050505050505050565b60165484101561313157600b84604051632eb752bf60e21b8152600401610a7292919061428c565b6000601a546017546131439190613f16565b60008181526010602090815260408083206001600160a01b038b168452909152902054909150156131a65760405162461bcd60e51b815260206004820152600d60248201526c52656465656d2065786973747360981b6044820152606401610a72565b6131b0868661343d565b84601360008282546131c29190613f16565b90915550506000818152600f602090815260408083206001600160a01b038a1684529091528120805490910361322a5760008281526011602090815260408220805460018101825590835291200180546001600160a01b0319166001600160a01b0389161790555b8054613237908790613f16565b81556001810154613249908690613f16565b600182015560408051878152602081018790529081018390526001600160a01b038816907f05204c412c9232d14ad1bb18ac9118f4a7e10c8a2d8eca85693d9388a6aac96b9060600160405180910390a2866001600160a01b031683857f7ba502a6e8d9c35b8430a91efccdff6928f2e0aca8193f08d0e34c02ff51cbd689866040516132e0929190918252602082015260400190565b60405180910390a450505050505050565b600082613306670de0b6b3a764000084613f48565b610ffb9190614248565b6000838152600f602090815260408083206001600160a01b0386168452825280832081518083019092528054808352600190910154928201929092528291829190820361336857600080600093509350935050613434565b6000878152600f602090815260408083206001600160a01b038a1684529091528120818155600190810182905582519095506133a59087906132f1565b9050816020015181106133c5576133bc8782613584565b600193506133e6565b81516005546133e1916001600160a01b03909116908990612b04565b600093505b8151604080518615158152602081018390529194506001600160a01b038916917fe0658942d1f815976a88ef2c4f1b8d5d0ff7f83c1cde078f60e39b08069bd55c910160405180910390a250505b93509350939050565b6005546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015613486573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134aa919061406c565b6005549091506134c5906001600160a01b0316843085613868565b6005546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa15801561350e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613532919061406c565b90508261353f8383613e85565b146114425760405162461bcd60e51b815260206004820152601560248201527411125117d393d517d49150d152559157d1561050d5605a1b6044820152606401610a72565b6001600160a01b0382166135da5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610a72565b80600960008282546135ec9190613f16565b90915550506001600160a01b03821660009081526007602052604081208054839290613619908490613f16565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6000670de0b6b3a76400006133068484613f48565b6001600160a01b0382166136d85760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610a72565b6001600160a01b0382166000908152600760205260409020548181101561374c5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610a72565b6001600160a01b038316600090815260076020526040812083830390556009805484929061377b908490613e85565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200161275d565b60006137d36001600160a01b038416836138a1565b905080516000141580156137f85750808060200190518101906137f691906143a3565b155b1561115457604051635274afe760e01b81526001600160a01b0384166004820152602401610a72565b613829610d3c565b6138665760405162461bcd60e51b815260206004820152600e60248201526d2628103aba34b634bd30ba34b7b760911b6044820152606401610a72565b565b6040516001600160a01b0384811660248301528381166044830152606482018390526114429186918216906323b872dd90608401612b31565b6060610ffb8383600084600080856001600160a01b031684866040516138c791906143c5565b60006040518083038185875af1925050503d8060008114613904576040519150601f19603f3d011682016040523d82523d6000602084013e613909565b606091505b50915091506112548683836060826139295761392482613970565b610ffb565b815115801561394057506001600160a01b0384163b155b1561396957604051639996b31560e01b81526001600160a01b0385166004820152602401610a72565b5080610ffb565b8051156139805780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b60005b838110156139b457818101518382015260200161399c565b50506000910152565b60208152600082518060208401526139dc816040850160208701613999565b601f01601f19169190910160400192915050565b6001600160a01b0381168114610ee957600080fd5b60008060408385031215613a1857600080fd5b8235613a23816139f0565b946020939093013593505050565b60008083601f840112613a4357600080fd5b50813567ffffffffffffffff811115613a5b57600080fd5b6020830191508360208260051b8501011115613a7657600080fd5b9250929050565b60008060208385031215613a9057600080fd5b823567ffffffffffffffff811115613aa757600080fd5b613ab385828601613a31565b90969095509350505050565b60008060408385031215613ad257600080fd5b8235613add816139f0565b91506020830135613aed816139f0565b809150509250929050565b600080600060608486031215613b0d57600080fd5b8335613b18816139f0565b92506020840135613b28816139f0565b929592945050506040919091013590565b600060208284031215613b4b57600080fd5b8135610ffb816139f0565b600060208284031215613b6857600080fd5b5035919050565b60008060408385031215613b8257600080fd5b50508035926020909101359150565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715613bd057613bd0613b91565b604052919050565b600067ffffffffffffffff821115613bf257613bf2613b91565b50601f01601f191660200190565b600082601f830112613c1157600080fd5b8135613c24613c1f82613bd8565b613ba7565b818152846020838601011115613c3957600080fd5b816020850160208301376000918101602001919091529392505050565b60008060408385031215613c6957600080fd5b823567ffffffffffffffff80821115613c8157600080fd5b613c8d86838701613c00565b93506020850135915080821115613ca357600080fd5b50613cb085828601613c00565b9150509250929050565b60008060008060408587031215613cd057600080fd5b843567ffffffffffffffff80821115613ce857600080fd5b613cf488838901613a31565b90965094506020870135915080821115613d0d57600080fd5b50613d1a87828801613a31565b95989497509550505050565b600080600060608486031215613d3b57600080fd5b505081359360208301359350604090920135919050565b6020808252825182820181905260009190848201906040850190845b81811015613d935783516001600160a01b031683529284019291840191600101613d6e565b50909695505050505050565b60008060408385031215613db257600080fd5b823591506020830135613aed816139f0565b600080600060608486031215613dd957600080fd5b8335613de4816139f0565b95602085013595506040909401359392505050565b60008060008060808587031215613e0f57600080fd5b5050823594602084013594506040840135936060013592509050565b600080600080600060a08688031215613e4357600080fd5b8535613e4e816139f0565b97602087013597506040870135966060810135965060800135945092505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610b2b57610b2b613e6f565b600181811c90821680613eac57607f821691505b602082108103613ecc57634e487b7160e01b600052602260045260246000fd5b50919050565b600080600060608486031215613ee757600080fd5b8351925060208401519150604084015190509250925092565b634e487b7160e01b600052603260045260246000fd5b80820180821115610b2b57610b2b613e6f565b600060ff821660ff8103613f3f57613f3f613e6f565b60010192915050565b8082028115828204841417610b2b57610b2b613e6f565b600181815b80851115613f9a578160001904821115613f8057613f80613e6f565b80851615613f8d57918102915b93841c9390800290613f64565b509250929050565b600082613fb157506001610b2b565b81613fbe57506000610b2b565b8160018114613fd45760028114613fde57613ffa565b6001915050610b2b565b60ff841115613fef57613fef613e6f565b50506001821b610b2b565b5060208310610133831016604e8410600b841016171561401d575081810a610b2b565b6140278383613f5f565b806000190482111561403b5761403b613e6f565b029392505050565b6000610ffb8383613fa2565b60006020828403121561406157600080fd5b8151610ffb816139f0565b60006020828403121561407e57600080fd5b5051919050565b6020808252600a908201526927a7262cafa0a226a4a760b11b604082015260600190565b601f821115611154576000816000526020600020601f850160051c810160208610156140d25750805b601f850160051c820191505b818110156140f1578281556001016140de565b505050505050565b815167ffffffffffffffff81111561411357614113613b91565b614127816141218454613e98565b846140a9565b602080601f83116001811461415c57600084156141445750858301515b600019600386901b1c1916600185901b1785556140f1565b600085815260208120601f198616915b8281101561418b5788860151825594840194600190910190840161416c565b50858210156141a95787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6000600160ff1b82016141ce576141ce613e6f565b5060000390565b600080604083850312156141e857600080fd5b505080516020909101519092909150565b808201828112600083128015821682158216171561421957614219613e6f565b505092915050565b818103600083128015838313168383128216171561424157614241613e6f565b5092915050565b60008261426557634e487b7160e01b600052601260045260246000fd5b500490565b60208082526008908201526708505b1b1bddd95960c21b604082015260600190565b60408101601284106142ae57634e487b7160e01b600052602160045260246000fd5b9281526020015290565b6000602082840312156142ca57600080fd5b815167ffffffffffffffff8111156142e157600080fd5b8201601f810184136142f257600080fd5b8051614300613c1f82613bd8565b81815285602083850101111561431557600080fd5b611c89826020830160208601613999565b670263cb73c102628160c51b815260008251614349816008850160208701613999565b9190910160080192915050565b610d8f60f31b815260008251614373816002850160208701613999565b9190910160020192915050565b60006020828403121561439257600080fd5b815160ff81168114610ffb57600080fd5b6000602082840312156143b557600080fd5b81518015158114610ffb57600080fd5b600082516143d7818460208701613999565b919091019291505056fea264697066735822122060616af47ed6cb1468e4a8400509af9cbe7ed04b4b4d3cb6821cecb82e8e725b64736f6c63430008180033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 35 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ 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.