Overview
BERA Balance
BERA Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 6 from a total of 6 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Redeem | 3025684 | 24 days ago | IN | 0 BERA | 0.00000005 | ||||
Redeem | 3025671 | 24 days ago | IN | 0 BERA | 0.00000005 | ||||
Redeem | 3025568 | 24 days ago | IN | 0 BERA | 0.00000004 | ||||
Redeem | 3024994 | 24 days ago | IN | 0 BERA | 0.00000003 | ||||
Redeem | 3024883 | 24 days ago | IN | 0 BERA | 0.00000004 | ||||
Redeem | 3024873 | 24 days ago | IN | 0 BERA | 0.00000003 |
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Source Code Verified (Exact Match)
Contract Name:
LiquidStabilityPool
Compiler Version
v0.8.26+commit.8a97fa7a
Optimization Enabled:
Yes with 200 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {ERC4626Upgradeable, ERC20Upgradeable, IERC20, Math, SafeERC20} from "@openzeppelin-upgradeable/contracts/token/ERC20/extensions/ERC4626Upgradeable.sol"; import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import {UUPSUpgradeable} from "@openzeppelin-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol"; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {PriceLib} from "../libraries/PriceLib.sol"; import {TokenValidationLib} from "../libraries/TokenValidationLib.sol"; import {EmissionsLib} from "../libraries/EmissionsLib.sol"; import {FeeLib} from "../libraries/FeeLib.sol"; import {BeraborrowMath} from "../dependencies/BeraborrowMath.sol"; import {ILiquidStabilityPool} from "../interfaces/core/ILiquidStabilityPool.sol"; import {IPriceFeed} from "../interfaces/core/IPriceFeed.sol"; import {IDebtToken} from "../interfaces/core/IDebtToken.sol"; import {IBeraborrowCore} from "../interfaces/core/IBeraborrowCore.sol"; import {IRebalancer} from "../interfaces/utils/integrations/IRebalancer.sol"; import {IAsset} from "../interfaces/utils/tokens/IAsset.sol"; /** @title Beraborrow Stability Pool @notice Based on Liquity's `StabilityPool` https://github.com/liquity/dev/blob/main/packages/contracts/contracts/StabilityPool.sol Beraborrow's implementation is modified to support multiple collaterals. Deposits into the liquid stability pool may be used to liquidate any supported collateral type. */ contract LiquidStabilityPool is ERC4626Upgradeable, UUPSUpgradeable { using Math for uint; using SafeERC20 for IERC20; using EnumerableSet for EnumerableSet.AddressSet; using PriceLib for uint; using TokenValidationLib for address; using TokenValidationLib for address[]; using EmissionsLib for EmissionsLib.BalanceData; using EmissionsLib for EmissionsLib.EmissionSchedule; using SafeCast for uint; using FeeLib for uint; uint128 public constant SUNSET_DURATION = 7 days; uint constant WAD = 1e18; uint constant BP = 1e4; // keccak256(abi.encode(uint(keccak256("openzeppelin.storage.LiquidStabilityPool")) - 1)) & ~bytes32(uint(0xff)) bytes32 private constant LiquidStabilityPoolStorageLocation = 0x3c2bbd5b01c023780ac7877400fd851b17fd98c152afdb1efc02015acd68a300; function _getLSPStorage() internal pure returns (ILiquidStabilityPool.LSPStorage storage store) { assembly { store.slot := LiquidStabilityPoolStorageLocation } } event CollateralOverwritten(address oldCollateral, address newCollateral); event AssetsWithdraw( address indexed receiver, uint shares, address[] tokens, uint[] amounts ); event ExtraAssetAdded(address token); event ExtraAssetRemoved(address token); event ProtocolRegistered( address indexed factory, address indexed liquidationManager ); event ProtocolBlacklisted(address indexed factoryRemoved, address indexed LMremoved); event Offset(address collateral, uint debtToOffset, uint collToAdd, uint collSurplusAmount); event Rebalance(address indexed sentCurrency, address indexed receivedCurrency, uint sentAmount, uint receivedAmount, uint sentValue, uint receivedValue); error AddressZero(); error NoPriceFeed(); error OnlyOwner(); error TokenCannotBeNect(); error TokenCannotBeExtraAsset(); error CallerNotFactory(); error CollateralIsSunsetting(); error ExistingCollateral(); error CollateralMustBeSunset(); error BalanceRemaining(); error Paused(); error BootstrapPeriod(); error InvalidArrayLength(); error LastTokenMustBeNect(); error CallerNotLM(); error SameTokens(); error BelowThreshold(); error ZeroTotalSupply(); error TokenMustBeExtraAsset(); error TokenIsVesting(); error InvalidThreshold(); error FactoryAlreadyRegistered(); error LMAlreadyRegistered(); error FactoryNotRegistered(); error LMNotRegistered(); error WithdrawingLockedEmissions(); constructor() { _disableInitializers(); } function initialize(ILiquidStabilityPool.InitParams calldata params) initializer external { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if (address(params._metaBeraborrowCore) == address(0) || params._liquidationManager == address(0) || params._factory == address(0)) { revert AddressZero(); } $.metaBeraborrowCore = params._metaBeraborrowCore; $.feeReceiver = params._feeReceiver; _registerProtocol( $, address(params._liquidationManager), address(params._factory) ); IPriceFeed priceFeed = IPriceFeed(params._metaBeraborrowCore.priceFeed()); if (priceFeed.fetchPrice(address(params._asset)) == 0) revert NoPriceFeed(); __ERC20_init(params._sharesName, params._sharesSymbol); __ERC4626_init(params._asset); } modifier onlyOwner { _onlyOwner(); _; } modifier whenNotBootstrapPeriod() { _whenNotBootstrapPeriod(); _; } function _onlyOwner() private view { // Owner is beacon variable MetaBeraborrowCore::owner() if (msg.sender != _getLSPStorage().metaBeraborrowCore.owner()) revert OnlyOwner(); } function _whenNotBootstrapPeriod() internal view { // BoycoVaults should be able to unwind in the case ICR closes MCR ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if ( block.timestamp < $.metaBeraborrowCore.lspBootstrapPeriod() && !$.boycoVault[msg.sender] ) revert BootstrapPeriod(); } function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} function enableCollateral(address _collateral, uint64 _unlockRatePerSecond, bool forceThroughBalanceCheck) external { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if (_collateral == asset()) revert TokenCannotBeNect(); if (!$.factoryProtocol[msg.sender]) revert CallerNotFactory(); if ($.extraAssets.contains(_collateral)) revert TokenCannotBeExtraAsset(); uint length = $.collateralTokens.length; bool collateralEnabled; $.balanceData.setUnlockRatePerSecond(_collateral, _unlockRatePerSecond); for (uint i; i < length; i++) { if ($.collateralTokens[i] == _collateral) { collateralEnabled = true; break; } } if (!collateralEnabled) { ILiquidStabilityPool.Queue memory queueCached = $.queue; if ( queueCached.nextSunsetIndexKey > queueCached.firstSunsetIndexKey ) { ILiquidStabilityPool.SunsetIndex memory sIdx = $._sunsetIndexes[ queueCached.firstSunsetIndexKey ]; if (sIdx.expiry < block.timestamp) { delete $._sunsetIndexes[$.queue.firstSunsetIndexKey++]; _overwriteCollateral(_collateral, sIdx.idx, forceThroughBalanceCheck); return; } } $.collateralTokens.push(_collateral); $.indexByCollateral[_collateral] = $.collateralTokens.length; } else { bool isSunsetting = $.indexByCollateral[_collateral] == 0; if (isSunsetting) { revert CollateralIsSunsetting(); } else { revert ExistingCollateral(); } } } /// @dev When a collateral is overwritten it will stop being tracked on totalAssets and withdraws, a total rebalance is needed function _overwriteCollateral(address _newCollateral, uint idx, bool forceThroughBalanceCheck) internal { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if($.indexByCollateral[_newCollateral] != 0) revert CollateralMustBeSunset(); address oldCollateral = $.collateralTokens[idx]; if ($.balanceData.balance[oldCollateral] != 0 && !forceThroughBalanceCheck) revert BalanceRemaining(); $.indexByCollateral[_newCollateral] = idx + 1; $.collateralTokens[idx] = _newCollateral; emit CollateralOverwritten(oldCollateral, _newCollateral); } /** * @notice Starts sunsetting a collateral * During sunsetting liquidated collateral handoff to the SP will revert @dev IMPORTANT: When sunsetting a collateral, `DenManager.startSunset` should be called on all DM linked to that collateral @param collateral Collateral to sunset */ function startCollateralSunset(address collateral) external onlyOwner { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if ($.indexByCollateral[collateral] == 0) revert CollateralIsSunsetting(); $._sunsetIndexes[$.queue.nextSunsetIndexKey++] = ILiquidStabilityPool.SunsetIndex( uint128($.indexByCollateral[collateral] - 1), uint128(block.timestamp + SUNSET_DURATION) ); delete $.indexByCollateral[collateral]; } /** @dev See {IERC4626-totalAssets}. */ /// @dev AmountInNect is scaled to 18 decimals, since its NECT decimals /// @dev Substracts balances locked emissions function totalAssets() public view override returns (uint amountInNect) { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); uint amountInUsd; address[] memory collaterals = getCollateralTokens(); uint nectPrice = getPrice(asset()); uint collateralsLength = collaterals.length; uint extraAssetsLength = $.extraAssets.length(); // we directly use `$.balanceData.balance[]` instead of `$.balanceOf` because NECT can't be an extra asset, neither a collateral, which are the only ones that can be locked through `addEmissions()` // this comment applies to all instances of `$.balanceData.balance[asset()]` // assumes NECT is 18 decimals uint nectBalance = $.balanceData.balance[asset()]; for (uint i; i < collateralsLength; i++) { address collateral = collaterals[i]; uint balance = $.balanceData.balanceOf(collateral); if (balance > 0) { amountInUsd += balance.convertToValue(getPrice(collateral), IAsset(collateral).decimals()); } } for (uint i; i < extraAssetsLength; i++) { address token = $.extraAssets.at(i); uint balance = $.balanceData.balanceOf(token); if (balance > 0) { amountInUsd += balance.convertToValue(getPrice(token), IAsset(token).decimals()); } } amountInNect = amountInUsd * WAD / nectPrice + nectBalance; } function getPrice( address token ) public view returns (uint scaledPriceInUsdWad) { IPriceFeed priceFeed = IPriceFeed(_getLSPStorage().metaBeraborrowCore.priceFeed()); return priceFeed.fetchPrice(token); } function deposit( uint assets, address receiver ) public override returns (uint shares) { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if ($.metaBeraborrowCore.paused()) revert Paused(); (uint rawShares, uint feeShares) = _previewDeposit(assets); shares = rawShares - feeShares; _depositAndMint($, shares, assets, receiver, feeShares); } function mint( uint shares, address receiver ) public override returns (uint assets) { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if ($.metaBeraborrowCore.paused()) revert Paused(); assets = previewMint(shares); uint fee = shares.mulDiv(BP, BP - _entryFeeBP(), Math.Rounding.Up) - shares; _depositAndMint($, shares, assets, receiver, fee); } function _depositAndMint(ILiquidStabilityPool.LSPStorage storage $, uint shares, uint assets, address receiver, uint fee) private { // Here we pass 'assets' since it is the amount of Nect we want to transfer to the LSP _provideFromAccount(msg.sender, assets); if (fee != 0) { _mint($.feeReceiver, fee); } _mint(receiver, shares); emit Deposit(msg.sender, receiver, assets, shares); } function withdraw( uint assets, address receiver, address _owner ) public whenNotBootstrapPeriod override returns (uint shares) { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); uint _totalSupply = totalSupply(); uint maxAssets = maxWithdraw(_owner); if (assets > maxAssets) revert ERC4626ExceededMaxWithdraw(_owner, assets, maxAssets); shares = previewWithdraw(assets); (uint nectAmount, uint fee) = _burn($, shares, _totalSupply, _owner); _withdraw(nectAmount, receiver, shares - fee, _totalSupply, _owner, assets, shares); } function redeem( uint shares, address receiver, address _owner ) public whenNotBootstrapPeriod override returns (uint assets) { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); uint _totalSupply = totalSupply(); uint maxShares = maxRedeem(_owner); if (shares > maxShares) revert ERC4626ExceededMaxRedeem(_owner, shares, maxShares); assets = previewRedeem(shares); (uint nectAmount, uint fee) = _burn($, shares, _totalSupply, _owner); _withdraw(nectAmount, receiver, shares - fee, _totalSupply, _owner, assets, shares); } function _withdraw(uint nectAmount, address receiver, uint cachedShares, uint _totalSupply, address _owner, uint assets, uint shares) private { _withdrawFromAccount(nectAmount, receiver); _withdrawCollAndExtraAssets(receiver, cachedShares, _totalSupply); emit Withdraw(msg.sender, receiver, _owner, assets, shares); } function withdraw( uint assets, address[] calldata preferredUnderlyingTokens, address receiver, address _owner ) public whenNotBootstrapPeriod returns (uint shares) { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); uint maxAssets = maxWithdraw(_owner); if (assets > maxAssets) revert ERC4626ExceededMaxWithdraw(_owner, assets, maxAssets); /// @dev should we have a check for assets == 0? its redundant but gas will be low shares = previewWithdraw(assets); // Pass totalSupply as 0 since we don't need to calculate `nectAmount` _burn($, shares, 0, _owner); _withdrawPreferredUnderlying($, assets, preferredUnderlyingTokens, receiver); emit Withdraw(msg.sender, receiver, _owner, assets, shares); } function redeem( uint shares, address[] calldata preferredUnderlyingTokens, address receiver, address _owner ) public whenNotBootstrapPeriod returns (uint assets) { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); uint maxShares = maxRedeem(_owner); if (shares > maxShares) revert ERC4626ExceededMaxRedeem(_owner, shares, maxShares); assets = previewRedeem(shares); // Pass totalSupply as 0 since we don't need to calculate `nectAmount` _burn($, shares, 0, _owner); _withdrawPreferredUnderlying($, assets, preferredUnderlyingTokens, receiver); emit Withdraw(msg.sender, receiver, _owner, assets, shares); } function _burn(ILiquidStabilityPool.LSPStorage storage $, uint shares, uint _totalSupply, address _owner) private returns (uint nectAmount, uint fee) { fee = shares.feeOnRaw(_exitFeeBP()); if (msg.sender != _owner) { _spendAllowance(_owner, msg.sender, shares); } /// @dev Always round in favor of the vault if (_totalSupply != 0) { nectAmount = (shares - fee).mulDiv($.balanceData.balance[asset()], _totalSupply, Math.Rounding.Down); } // We could remove fee > 0 if we deploy with fees and the minimum fee is not 0 if (fee != 0) { _mint($.feeReceiver, fee); } _burn(_owner, shares); } /// @dev No token validation is needed, if token is not collateral or extraAsset, it will underflow in `$balance[token]` /// @dev Reentrancy attack vector should not be possible since user has their shares burned before the calls to tokens /// @dev No duplicated token check needed function _withdrawPreferredUnderlying( ILiquidStabilityPool.LSPStorage storage $, uint assets, address[] memory preferredUnderlyingTokens, address receiver ) internal { // Avoid stack too deep error ILiquidStabilityPool.Arrays memory arr = _initArrays(preferredUnderlyingTokens); if (arr.length != $.extraAssets.length() + arr.collateralsLength + 1) revert InvalidArrayLength(); if (preferredUnderlyingTokens[arr.length - 1] != asset()) revert LastTokenMustBeNect(); preferredUnderlyingTokens.checkForDuplicates(arr.length); uint remainingAssets = assets; uint nectPrice = getPrice(asset()); for (uint i; i < arr.length && remainingAssets != 0; i++) { address token = preferredUnderlyingTokens[i]; token.checkValidToken(arr.collaterals, arr.collateralsLength, asset(), $.extraAssets.contains(token)); uint unlockedBalance = $.balanceData.balanceOf(token); if (unlockedBalance == 0) continue; uint tokenPrice = getPrice(token); // Price could be 0 if CollVault collateral or extraAsset is just added without atomical initial deposit // Would result in less assets withdrawn than expected if (tokenPrice == 0) continue; uint8 tokenDecimals = IAsset(token).decimals(); uint amount = remainingAssets.convertAssetsToCollAmount( tokenPrice, nectPrice, decimals(), // NECT decimals tokenDecimals, Math.Rounding.Down ); if (unlockedBalance >= amount) { remainingAssets = 0; $.balanceData.balance[token] -= amount; } else { uint remainingColl = amount - unlockedBalance; remainingAssets = remainingColl.convertCollAmountToAssets( tokenPrice, nectPrice, decimals(), // NECT decimals tokenDecimals ); amount = unlockedBalance; $.balanceData.balance[token] -= amount; } arr.amounts[i] = amount; } for (uint i; i < arr.length; i++) { if(arr.amounts[i] > 0) { IERC20(preferredUnderlyingTokens[i]).safeTransfer(receiver, arr.amounts[i]); } } emit AssetsWithdraw(receiver, assets, preferredUnderlyingTokens, arr.amounts); } function _provideFromAccount( address account, uint _amount ) internal { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); IDebtToken(asset()).sendToSP(account, _amount); $.balanceData.balance[asset()] += _amount; } function _withdrawFromAccount( uint _amount, address receiver ) internal { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); IDebtToken(asset()).returnFromPool(address(this), receiver, _amount); $.balanceData.balance[asset()] -= _amount; } /* * Cancels out the specified debt against the Debt contained in the Stability Pool (as far as possible) */ function offset( address collateral, uint _debtToOffset, uint _collToAdd ) external virtual { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if (!$.liquidationManagerProtocol[msg.sender]) revert CallerNotLM(); uint collPrice = getPrice(collateral); uint nectPrice = getPrice(asset()); uint debtInCollateralAmount = _debtToOffset.convertAssetsToCollAmount( collPrice, nectPrice, decimals(), IAsset(collateral).decimals(), Math.Rounding.Up ); // Unlikely case in which LM offsets more debt value than collateral uint collSurplusAmount; if (_collToAdd > debtInCollateralAmount) { collSurplusAmount = _collToAdd - debtInCollateralAmount; } if (collSurplusAmount > 0) { $.balanceData.addEmissions(address(collateral), collSurplusAmount.toUint128()); } $.balanceData.balance[collateral] += _collToAdd - collSurplusAmount; // Cancel the liquidated Debt debt with the Debt in the stability pool $.balanceData.balance[asset()] -= _debtToOffset; emit Offset(collateral, _debtToOffset, _collToAdd, collSurplusAmount); } /** * @notice Withdraws as much collaterals awaiting conversion as shares being used for NECT withdrawal * @param receiver Address to receive the collaterals * @param shares Amount of shares being used for NECT withdrawal * @param _totalSupply Has shares added to total supply since they have just been burned */ function _withdrawCollAndExtraAssets( address receiver, uint shares, uint _totalSupply ) internal { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); address[] memory collaterals = getCollateralTokens(); uint collLength = collaterals.length; uint extraAssetsLength = $.extraAssets.length(); uint[] memory amounts = new uint[](collLength + extraAssetsLength); address[] memory tokens = new address[](collLength + extraAssetsLength); for (uint i; i < collLength; i++) { uint balanceWithUnlockedEmissions = $.balanceData.balanceOf(collaterals[i]); amounts[i] = shares.mulDiv(balanceWithUnlockedEmissions, _totalSupply, Math.Rounding.Down); tokens[i] = collaterals[i]; $.balanceData.balance[collaterals[i]] -= amounts[i]; } for (uint i; i < extraAssetsLength; i++) { uint idx = i + collLength; address token = $.extraAssets.at(i); uint balanceWithUnlockedEmissions = $.balanceData.balanceOf(token); amounts[idx] = shares.mulDiv(balanceWithUnlockedEmissions, _totalSupply, Math.Rounding.Down); tokens[idx] = token; $.balanceData.balance[token] -= amounts[idx]; } for (uint i; i < tokens.length; i++) { if (amounts[i] != 0) { IERC20(tokens[i]).safeTransfer(receiver, amounts[i]); } } emit AssetsWithdraw(receiver, shares, tokens, amounts); } function rebalance(ILiquidStabilityPool.RebalanceParams calldata p) external onlyOwner { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if (p.sentCurrency == p.receivedCurrency) revert SameTokens(); uint sentPrice = getPrice(p.sentCurrency); uint receivedPrice = getPrice(p.receivedCurrency); uint8 sentDecimals = IAsset(p.sentCurrency).decimals(); uint8 receivedDecimals = IAsset(p.receivedCurrency).decimals(); uint sentCurrencyBalance = IAsset(p.sentCurrency).balanceOf(address(this)); uint receivedCurrencyBalance = IAsset(p.receivedCurrency).balanceOf(address(this)); // Perform the swap using the swapper contract IERC20(p.sentCurrency).safeTransfer(p.swapper, p.sentAmount); IRebalancer(p.swapper).swap( p.sentCurrency, p.sentAmount, p.receivedCurrency, p.payload ); uint received = IAsset(p.receivedCurrency).balanceOf(address(this)) - receivedCurrencyBalance; uint sent = sentCurrencyBalance - IAsset(p.sentCurrency).balanceOf(address(this)); // if we were to rebalance locked emissions, a possible revert on subsequent `$.balanceOf` calls would occur if (sent > $.balanceData.balance[p.sentCurrency] - getLockedEmissions(p.sentCurrency)) revert WithdrawingLockedEmissions(); uint receivedValue = received.convertToValue(receivedPrice, receivedDecimals); uint sentValue = sent.convertToValue(sentPrice, sentDecimals); bytes32 hash = keccak256(abi.encodePacked(p.sentCurrency, p.receivedCurrency)); // if threshold isn't set, it will be 0, not tolerating any slippage if (receivedValue < sentValue * (BP - $.threshold[hash]) / BP) revert BelowThreshold(); $.balanceData.balance[p.sentCurrency] -= sent; $.balanceData.balance[p.receivedCurrency] += received; emit Rebalance(p.sentCurrency, p.receivedCurrency, sent, received, sentValue, receivedValue); } /** * @dev Limited to tokens that are not collaterals or NECT * @param token Token to add to the extraAssets * @param _unlockRatePerSecond Unlock rate per second once the token is pulled to the LSP */ function addNewExtraAsset( address token, uint64 _unlockRatePerSecond ) external onlyOwner { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); address[] memory collaterals = getCollateralTokens(); if (token == asset()) revert TokenCannotBeNect(); uint enableCollateralLength = collaterals.length; for (uint i; i < enableCollateralLength; i++) { if (collaterals[i] == token) revert ExistingCollateral(); } if (!$.extraAssets.add(token)) revert TokenCannotBeExtraAsset(); IPriceFeed priceFeed = IPriceFeed($.metaBeraborrowCore.priceFeed()); if (priceFeed.fetchPrice(token) == 0) revert NoPriceFeed(); $.balanceData.setUnlockRatePerSecond(token, _unlockRatePerSecond); emit ExtraAssetAdded(token); } /* * @notice Params overwrites the current vesting for the token * @dev Adjust the unlockRatePerSecond if we want to keep the fullUnlockTimestamp */ function linearVestingExtraAssets(address token, int amount, address recipient) external onlyOwner { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if (totalSupply() == 0) revert ZeroTotalSupply(); // convertToShares will return 0 for 'assets < totalAssets' if (!$.extraAssets.contains(token)) revert TokenMustBeExtraAsset(); if (amount > 0) { uint _amount = uint(amount); IERC20(token).safeTransferFrom(msg.sender, address(this), _amount); $.balanceData.addEmissions(token, _amount.toUint128()); } else { uint _amount = uint(-amount); // Note, revert with underflow if amount > `lockedEmissions` $.balanceData.subEmissions(token, _amount.toUint128()); IERC20(token).safeTransfer(recipient, _amount); } } function removeExtraAsset(address token) external onlyOwner { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if ($.balanceData.balance[token] != 0) revert BalanceRemaining(); if ($.balanceData.emissionSchedule[token].unlockTimestamp() >= block.timestamp) revert TokenIsVesting(); if (!$.extraAssets.remove(token)) revert TokenMustBeExtraAsset(); emit ExtraAssetRemoved(token); } function setPairThreshold(address tokenIn, address tokenOut, uint thresholdInBP) external onlyOwner { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if (thresholdInBP > BP) revert InvalidThreshold(); bytes32 hash = keccak256(abi.encodePacked(tokenIn, tokenOut)); $.threshold[hash] = thresholdInBP; } function setUnlockRatePerSecond(address token, uint64 _unlockRatePerSecond) external onlyOwner { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); $.balanceData.setUnlockRatePerSecond(token, _unlockRatePerSecond); } function setBoycoVaults(address[] calldata _boycoVaults, bool[] calldata enable) external onlyOwner { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if (_boycoVaults.length != enable.length) revert InvalidArrayLength(); for (uint i; i < _boycoVaults.length; i++) { address boycoVault = _boycoVaults[i]; if (boycoVault == address(0)) revert AddressZero(); $.boycoVault[boycoVault] = enable[i]; } } // Preview ERC4626 functions applying entry/exit fees function previewDeposit(uint assets) public view override returns (uint) { (uint rawShares, uint feeShares) = _previewDeposit(assets); return rawShares - feeShares; } function _previewDeposit(uint assets) internal view returns (uint rawShares, uint feeShares) { rawShares = super.previewDeposit(assets); feeShares = rawShares.feeOnRaw(_entryFeeBP()); } function previewMint(uint netShares) public view override returns (uint) { uint totalShares = netShares.mulDiv(BP, BP - _entryFeeBP(), Math.Rounding.Up); return super.previewMint(totalShares); } function previewWithdraw(uint assets) public view override returns (uint) { uint netShares = super.previewWithdraw(assets); uint totalShares = netShares.mulDiv(BP, BP - _exitFeeBP(), Math.Rounding.Up); return totalShares; } function previewRedeem(uint shares) public view override returns (uint) { uint fee = shares.feeOnRaw(_exitFeeBP()); return super.previewRedeem(shares - fee); } /** @dev See {IERC4626-maxWithdraw}. */ function maxWithdraw(address _owner) public view override returns (uint) { return previewRedeem(balanceOf(_owner)); } // === Fee configuration === /// @dev Rebalancer fee discounts will look to a forwarding contract similar to LSPRouter, but with access control function _entryFeeBP() internal view virtual returns (uint) { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); return $.metaBeraborrowCore.getLspEntryFee(msg.sender); } function _exitFeeBP() internal view virtual returns (uint) { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); return $.metaBeraborrowCore.getLspExitFee(msg.sender); } function _initArrays(address[] memory preferredUnderlyingTokens) private view returns (ILiquidStabilityPool.Arrays memory arr) { address[] memory collaterals = getCollateralTokens(); uint length = preferredUnderlyingTokens.length; arr = ILiquidStabilityPool.Arrays({ length: length, collaterals: collaterals, collateralsLength: collaterals.length, amounts: new uint[](length) }); } /// @notice Either registeres or blacklists a protocol from using the LSP by setting/removing its factory and liquidation manager permissions /// @param _factory The factory contract address to update /// @param _liquidationManager The liquidation manager contract address to update function updateProtocol( address _liquidationManager, address _factory, bool _register ) external onlyOwner { ILiquidStabilityPool.LSPStorage storage $ = _getLSPStorage(); if ( _liquidationManager == address(0) || _factory == address(0) ) revert AddressZero(); if (_register) { _registerProtocol($, _liquidationManager, _factory); } else { if (!$.factoryProtocol[_factory]) revert FactoryNotRegistered(); if (!$.liquidationManagerProtocol[_liquidationManager]) revert LMNotRegistered(); delete $.factoryProtocol[_factory]; delete $.liquidationManagerProtocol[_liquidationManager]; emit ProtocolBlacklisted(_factory, _liquidationManager); } } function _registerProtocol( ILiquidStabilityPool.LSPStorage storage $, address _liquidationManager, address _factory ) internal { if ($.factoryProtocol[_factory]) revert FactoryAlreadyRegistered(); if ($.liquidationManagerProtocol[_liquidationManager]) revert LMAlreadyRegistered(); $.factoryProtocol[_factory] = true; $.liquidationManagerProtocol[_liquidationManager] = true; emit ProtocolRegistered(_factory, _liquidationManager); } /* STORAGE VIEW */ function extSloads(bytes32[] calldata slots) external view returns (bytes32[] memory res) { uint nSlots = slots.length; res = new bytes32[](nSlots); for (uint i; i < nSlots;) { bytes32 slot = slots[i++]; assembly ("memory-safe") { mstore(add(res, mul(i, 32)), sload(slot)) } } } /// @dev Returns the locked emissions function getLockedEmissions(address token) public view returns (uint) { EmissionsLib.EmissionSchedule memory schedule = _getLSPStorage().balanceData.emissionSchedule[token]; uint fullUnlockTimestamp = schedule.unlockTimestamp(); return schedule.lockedEmissions(fullUnlockTimestamp); } /** * @notice NECT is not locked */ function getTotalDebtTokenDeposits() external view returns (uint) { return _getLSPStorage().balanceData.balance[asset()]; } /** * @dev Tracks Stability's Pool `collateralTokens` * `collateralTokens` is pushed when a new collateral is added, but its index are overwritten if coll didn't exist * When a sunset is expired, its epoch is set to 0, and a new coll is added at that index * `queue.first` is increased for every sunsetted expired coll that is overwritten * `queue.next` is increased for every coll sunset, and it stores the index of the coll being sunset of the `collateralTokens` array * because the sunsetted expired collateral is only removed from the `collateralTokens` array when a new coll is added, the pulling of the coll has to check the sunset isn't expired * TLDR; the function doesn't need changes but the pulling of the coll has to check the sunset isn't expired */ /// The comments below is to handle the case when a sunset collateral expires and is not yet overwritten on the LSP::collateralTokens array /// @dev My stance on this matter is that it is possible that certain balance liquidated collateral can happen to stoy at LV after its sunset expires /// On that case we could whitelist it to overwrite it and remove it from the LSP::collateralTokens array /// Doing that we could add it as extraAsset token (it no longer is in coll array) /// But whitelisting would require a new token, which we may not have the need to add as collateral type /// I'm a fan of dynamically excluding it below once the sunset expires and manually adding it as extraAsset token if it makes sense economically function getCollateralTokens() public view returns (address[] memory) { return _getLSPStorage().collateralTokens; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC4626.sol) pragma solidity ^0.8.20; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {ERC20Upgradeable} from "../ERC20Upgradeable.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol"; import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; import {Initializable} from "../../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the ERC-4626 "Tokenized Vault Standard" as defined in * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626]. * * This extension allows the minting and burning of "shares" (represented using the ERC-20 inheritance) in exchange for * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends * the ERC-20 standard. Any additional extensions included along it would affect the "shares" token represented by this * contract and not the "assets" token which is an independent contract. * * [CAUTION] * ==== * In empty (or nearly empty) ERC-4626 vaults, deposits are at high risk of being stolen through frontrunning * with a "donation" to the vault that inflates the price of a share. This is variously known as a donation or inflation * attack and is essentially a problem of slippage. Vault deployers can protect against this attack by making an initial * deposit of a non-trivial amount of the asset, such that price manipulation becomes infeasible. Withdrawals may * similarly be affected by slippage. Users can protect against this attack as well as unexpected slippage in general by * verifying the amount received is as expected, using a wrapper that performs these checks such as * https://github.com/fei-protocol/ERC4626#erc4626router-and-base[ERC4626Router]. * * Since v4.9, this implementation introduces configurable virtual assets and shares to help developers mitigate that risk. * The `_decimalsOffset()` corresponds to an offset in the decimal representation between the underlying asset's decimals * and the vault decimals. This offset also determines the rate of virtual shares to virtual assets in the vault, which * itself determines the initial exchange rate. While not fully preventing the attack, analysis shows that the default * offset (0) makes it non-profitable even if an attacker is able to capture value from multiple user deposits, as a result * of the value being captured by the virtual shares (out of the attacker's donation) matching the attacker's expected gains. * With a larger offset, the attack becomes orders of magnitude more expensive than it is profitable. More details about the * underlying math can be found xref:erc4626.adoc#inflation-attack[here]. * * The drawback of this approach is that the virtual shares do capture (a very small) part of the value being accrued * to the vault. Also, if the vault experiences losses, the users try to exit the vault, the virtual shares and assets * will cause the first user to exit to experience reduced losses in detriment to the last users that will experience * bigger losses. Developers willing to revert back to the pre-v4.9 behavior just need to override the * `_convertToShares` and `_convertToAssets` functions. * * To learn more, check out our xref:ROOT:erc4626.adoc[ERC-4626 guide]. * ==== */ abstract contract ERC4626Upgradeable is Initializable, ERC20Upgradeable, IERC4626 { using Math for uint256; /// @custom:storage-location erc7201:openzeppelin.storage.ERC4626 struct ERC4626Storage { IERC20 _asset; uint8 _underlyingDecimals; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC4626")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant ERC4626StorageLocation = 0x0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00; function _getERC4626Storage() private pure returns (ERC4626Storage storage $) { assembly { $.slot := ERC4626StorageLocation } } /** * @dev Attempted to deposit more assets than the max amount for `receiver`. */ error ERC4626ExceededMaxDeposit(address receiver, uint256 assets, uint256 max); /** * @dev Attempted to mint more shares than the max amount for `receiver`. */ error ERC4626ExceededMaxMint(address receiver, uint256 shares, uint256 max); /** * @dev Attempted to withdraw more assets than the max amount for `receiver`. */ error ERC4626ExceededMaxWithdraw(address owner, uint256 assets, uint256 max); /** * @dev Attempted to redeem more shares than the max amount for `receiver`. */ error ERC4626ExceededMaxRedeem(address owner, uint256 shares, uint256 max); /** * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC-20 or ERC-777). */ function __ERC4626_init(IERC20 asset_) internal onlyInitializing { __ERC4626_init_unchained(asset_); } function __ERC4626_init_unchained(IERC20 asset_) internal onlyInitializing { ERC4626Storage storage $ = _getERC4626Storage(); (bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_); $._underlyingDecimals = success ? assetDecimals : 18; $._asset = asset_; } /** * @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way. */ function _tryGetAssetDecimals(IERC20 asset_) private view returns (bool, uint8) { (bool success, bytes memory encodedDecimals) = address(asset_).staticcall( abi.encodeCall(IERC20Metadata.decimals, ()) ); if (success && encodedDecimals.length >= 32) { uint256 returnedDecimals = abi.decode(encodedDecimals, (uint256)); if (returnedDecimals <= type(uint8).max) { return (true, uint8(returnedDecimals)); } } return (false, 0); } /** * @dev Decimals are computed by adding the decimal offset on top of the underlying asset's decimals. This * "original" value is cached during construction of the vault contract. If this read operation fails (e.g., the * asset has not been created yet), a default of 18 is used to represent the underlying asset's decimals. * * See {IERC20Metadata-decimals}. */ function decimals() public view virtual override(IERC20Metadata, ERC20Upgradeable) returns (uint8) { ERC4626Storage storage $ = _getERC4626Storage(); return $._underlyingDecimals + _decimalsOffset(); } /** @dev See {IERC4626-asset}. */ function asset() public view virtual returns (address) { ERC4626Storage storage $ = _getERC4626Storage(); return address($._asset); } /** @dev See {IERC4626-totalAssets}. */ function totalAssets() public view virtual returns (uint256) { ERC4626Storage storage $ = _getERC4626Storage(); return $._asset.balanceOf(address(this)); } /** @dev See {IERC4626-convertToShares}. */ function convertToShares(uint256 assets) public view virtual returns (uint256) { return _convertToShares(assets, Math.Rounding.Down); } /** @dev See {IERC4626-convertToAssets}. */ function convertToAssets(uint256 shares) public view virtual returns (uint256) { return _convertToAssets(shares, Math.Rounding.Down); } /** @dev See {IERC4626-maxDeposit}. */ function maxDeposit(address) public view virtual returns (uint256) { return type(uint256).max; } /** @dev See {IERC4626-maxMint}. */ function maxMint(address) public view virtual returns (uint256) { return type(uint256).max; } /** @dev See {IERC4626-maxWithdraw}. */ function maxWithdraw(address owner) public view virtual returns (uint256) { return _convertToAssets(balanceOf(owner), Math.Rounding.Down); } /** @dev See {IERC4626-maxRedeem}. */ function maxRedeem(address owner) public view virtual returns (uint256) { return balanceOf(owner); } /** @dev See {IERC4626-previewDeposit}. */ function previewDeposit(uint256 assets) public view virtual returns (uint256) { return _convertToShares(assets, Math.Rounding.Down); } /** @dev See {IERC4626-previewMint}. */ function previewMint(uint256 shares) public view virtual returns (uint256) { return _convertToAssets(shares, Math.Rounding.Up); } /** @dev See {IERC4626-previewWithdraw}. */ function previewWithdraw(uint256 assets) public view virtual returns (uint256) { return _convertToShares(assets, Math.Rounding.Up); } /** @dev See {IERC4626-previewRedeem}. */ function previewRedeem(uint256 shares) public view virtual returns (uint256) { return _convertToAssets(shares, Math.Rounding.Down); } /** @dev See {IERC4626-deposit}. */ function deposit(uint256 assets, address receiver) public virtual returns (uint256) { uint256 maxAssets = maxDeposit(receiver); if (assets > maxAssets) { revert ERC4626ExceededMaxDeposit(receiver, assets, maxAssets); } uint256 shares = previewDeposit(assets); _deposit(_msgSender(), receiver, assets, shares); return shares; } /** @dev See {IERC4626-mint}. */ function mint(uint256 shares, address receiver) public virtual returns (uint256) { uint256 maxShares = maxMint(receiver); if (shares > maxShares) { revert ERC4626ExceededMaxMint(receiver, shares, maxShares); } uint256 assets = previewMint(shares); _deposit(_msgSender(), receiver, assets, shares); return assets; } /** @dev See {IERC4626-withdraw}. */ function withdraw(uint256 assets, address receiver, address owner) public virtual returns (uint256) { uint256 maxAssets = maxWithdraw(owner); if (assets > maxAssets) { revert ERC4626ExceededMaxWithdraw(owner, assets, maxAssets); } uint256 shares = previewWithdraw(assets); _withdraw(_msgSender(), receiver, owner, assets, shares); return shares; } /** @dev See {IERC4626-redeem}. */ function redeem(uint256 shares, address receiver, address owner) public virtual returns (uint256) { uint256 maxShares = maxRedeem(owner); if (shares > maxShares) { revert ERC4626ExceededMaxRedeem(owner, shares, maxShares); } uint256 assets = previewRedeem(shares); _withdraw(_msgSender(), receiver, owner, assets, shares); return assets; } /** * @dev Internal conversion function (from assets to shares) with support for rounding direction. */ // Deposit 1 USDC // 1e6 * 1e12 / 1 -> 1e18 shares minted // Deposit 1 USDC after first mint // 1e6 * 1e18 / 1e18 -> 1e6 shares minted // After first mint, BaseCollVault correctly does: // 1e6 * 1e18 / 1e6 -> 1e18 shares minted // Problem is usdValue in `totalAssets will have to be multiplied in 10 ** decimal precision, instead of WAD: // Currently: `amountInAsset = usdValue.mulDiv(WAD, assetPrice) + assetBalanceWad;` // Fix: `amountInAsset = usdValue.mulDiv(assetDecimals(), assetPrice) + assetBalance;` // Which reduces precision in totalAsset. // We could fix it by overriding deposit/mint/withdraw/redeem to scale internally assets to WAD, but leads to higher complexity // 8 decimals // 1e8 * 1e10 / 1 = 1e18 minted shares // 1e8 * 1e18 / 1e8 = 1e18 minted shares function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256) { return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding); } /** * @dev Internal conversion function (from shares to assets) with support for rounding direction. */ function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view virtual returns (uint256) { return shares.mulDiv(totalAssets() + 1, totalSupply() + 10 ** _decimalsOffset(), rounding); } /** * @dev Deposit/mint common workflow. */ function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual { ERC4626Storage storage $ = _getERC4626Storage(); // If _asset is ERC-777, `transferFrom` can trigger a reentrancy BEFORE the transfer happens through the // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer, // calls the vault, which is assumed not malicious. // // Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the // assets are transferred and before the shares are minted, which is a valid state. // slither-disable-next-line reentrancy-no-eth SafeERC20.safeTransferFrom($._asset, caller, address(this), assets); _mint(receiver, shares); emit Deposit(caller, receiver, assets, shares); } /** * @dev Withdraw/redeem common workflow. */ function _withdraw( address caller, address receiver, address owner, uint256 assets, uint256 shares ) internal virtual { ERC4626Storage storage $ = _getERC4626Storage(); if (caller != owner) { _spendAllowance(owner, caller, shares); } // If _asset is ERC-777, `transfer` can trigger a reentrancy AFTER the transfer happens through the // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer, // calls the vault, which is assumed not malicious. // // Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the // shares are burned and after the assets are transferred, which is a valid state. _burn(owner, shares); SafeERC20.safeTransfer($._asset, receiver, assets); emit Withdraw(caller, receiver, owner, assets, shares); } function _decimalsOffset() internal view virtual returns (uint8) { return 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.20; import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol"; import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; import {Initializable} from "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. */ abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable { /// @custom:oz-upgrades-unsafe-allow state-variable-immutable address private immutable __self = address(this); /** * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)` * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called, * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string. * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function * during an upgrade. */ string public constant UPGRADE_INTERFACE_VERSION = "5.0.0"; /** * @dev The call is from an unauthorized context. */ error UUPSUnauthorizedCallContext(); /** * @dev The storage `slot` is unsupported as a UUID. */ error UUPSUnsupportedProxiableUUID(bytes32 slot); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { _checkProxy(); _; } /** * @dev Check that the execution is not being performed through a delegate call. This allows a function to be * callable on the implementing contract but not through proxies. */ modifier notDelegated() { _checkNotDelegated(); _; } function __UUPSUpgradeable_init() internal onlyInitializing { } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /** * @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the * implementation. It is used to validate the implementation's compatibility when performing an upgrade. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier. */ function proxiableUUID() external view virtual notDelegated returns (bytes32) { return ERC1967Utils.IMPLEMENTATION_SLOT; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. * * @custom:oz-upgrades-unsafe-allow-reachable delegatecall */ function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallUUPS(newImplementation, data); } /** * @dev Reverts if the execution is not performed via delegatecall or the execution * context is not of a proxy with an ERC-1967 compliant implementation pointing to self. * See {_onlyProxy}. */ function _checkProxy() internal view virtual { if ( address(this) == __self || // Must be called through delegatecall ERC1967Utils.getImplementation() != __self // Must be called through an active proxy ) { revert UUPSUnauthorizedCallContext(); } } /** * @dev Reverts if the execution is performed via delegatecall. * See {notDelegated}. */ function _checkNotDelegated() internal view virtual { if (address(this) != __self) { // Must not be called through delegatecall revert UUPSUnauthorizedCallContext(); } } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; /** * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call. * * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value * is expected to be the implementation slot in ERC-1967. * * Emits an {IERC1967-Upgraded} event. */ function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private { try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) { if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) { revert UUPSUnsupportedProxiableUUID(slot); } ERC1967Utils.upgradeToAndCall(newImplementation, data); } catch { // The implementation is not UUPS revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toUint248(uint256 value) internal pure returns (uint248) { require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits"); return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toUint240(uint256 value) internal pure returns (uint240) { require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits"); return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toUint232(uint256 value) internal pure returns (uint232) { require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits"); return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.2._ */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toUint216(uint256 value) internal pure returns (uint216) { require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits"); return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toUint208(uint256 value) internal pure returns (uint208) { require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits"); return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toUint200(uint256 value) internal pure returns (uint200) { require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits"); return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toUint192(uint256 value) internal pure returns (uint192) { require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits"); return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toUint184(uint256 value) internal pure returns (uint184) { require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits"); return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toUint176(uint256 value) internal pure returns (uint176) { require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits"); return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toUint168(uint256 value) internal pure returns (uint168) { require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits"); return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toUint160(uint256 value) internal pure returns (uint160) { require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits"); return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toUint152(uint256 value) internal pure returns (uint152) { require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits"); return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toUint144(uint256 value) internal pure returns (uint144) { require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits"); return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toUint136(uint256 value) internal pure returns (uint136) { require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits"); return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v2.5._ */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toUint120(uint256 value) internal pure returns (uint120) { require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits"); return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toUint112(uint256 value) internal pure returns (uint112) { require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits"); return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toUint104(uint256 value) internal pure returns (uint104) { require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits"); return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.2._ */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toUint88(uint256 value) internal pure returns (uint88) { require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits"); return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toUint80(uint256 value) internal pure returns (uint80) { require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits"); return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toUint72(uint256 value) internal pure returns (uint72) { require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits"); return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v2.5._ */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toUint56(uint256 value) internal pure returns (uint56) { require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits"); return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toUint48(uint256 value) internal pure returns (uint48) { require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits"); return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toUint40(uint256 value) internal pure returns (uint40) { require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits"); return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v2.5._ */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toUint24(uint256 value) internal pure returns (uint24) { require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits"); return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v2.5._ */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v2.5._ */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. * * _Available since v3.0._ */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toInt248(int256 value) internal pure returns (int248 downcasted) { downcasted = int248(value); require(downcasted == value, "SafeCast: value doesn't fit in 248 bits"); } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toInt240(int256 value) internal pure returns (int240 downcasted) { downcasted = int240(value); require(downcasted == value, "SafeCast: value doesn't fit in 240 bits"); } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toInt232(int256 value) internal pure returns (int232 downcasted) { downcasted = int232(value); require(downcasted == value, "SafeCast: value doesn't fit in 232 bits"); } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.7._ */ function toInt224(int256 value) internal pure returns (int224 downcasted) { downcasted = int224(value); require(downcasted == value, "SafeCast: value doesn't fit in 224 bits"); } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toInt216(int256 value) internal pure returns (int216 downcasted) { downcasted = int216(value); require(downcasted == value, "SafeCast: value doesn't fit in 216 bits"); } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toInt208(int256 value) internal pure returns (int208 downcasted) { downcasted = int208(value); require(downcasted == value, "SafeCast: value doesn't fit in 208 bits"); } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toInt200(int256 value) internal pure returns (int200 downcasted) { downcasted = int200(value); require(downcasted == value, "SafeCast: value doesn't fit in 200 bits"); } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toInt192(int256 value) internal pure returns (int192 downcasted) { downcasted = int192(value); require(downcasted == value, "SafeCast: value doesn't fit in 192 bits"); } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toInt184(int256 value) internal pure returns (int184 downcasted) { downcasted = int184(value); require(downcasted == value, "SafeCast: value doesn't fit in 184 bits"); } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toInt176(int256 value) internal pure returns (int176 downcasted) { downcasted = int176(value); require(downcasted == value, "SafeCast: value doesn't fit in 176 bits"); } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toInt168(int256 value) internal pure returns (int168 downcasted) { downcasted = int168(value); require(downcasted == value, "SafeCast: value doesn't fit in 168 bits"); } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toInt160(int256 value) internal pure returns (int160 downcasted) { downcasted = int160(value); require(downcasted == value, "SafeCast: value doesn't fit in 160 bits"); } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toInt152(int256 value) internal pure returns (int152 downcasted) { downcasted = int152(value); require(downcasted == value, "SafeCast: value doesn't fit in 152 bits"); } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toInt144(int256 value) internal pure returns (int144 downcasted) { downcasted = int144(value); require(downcasted == value, "SafeCast: value doesn't fit in 144 bits"); } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toInt136(int256 value) internal pure returns (int136 downcasted) { downcasted = int136(value); require(downcasted == value, "SafeCast: value doesn't fit in 136 bits"); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128 downcasted) { downcasted = int128(value); require(downcasted == value, "SafeCast: value doesn't fit in 128 bits"); } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toInt120(int256 value) internal pure returns (int120 downcasted) { downcasted = int120(value); require(downcasted == value, "SafeCast: value doesn't fit in 120 bits"); } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toInt112(int256 value) internal pure returns (int112 downcasted) { downcasted = int112(value); require(downcasted == value, "SafeCast: value doesn't fit in 112 bits"); } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toInt104(int256 value) internal pure returns (int104 downcasted) { downcasted = int104(value); require(downcasted == value, "SafeCast: value doesn't fit in 104 bits"); } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.7._ */ function toInt96(int256 value) internal pure returns (int96 downcasted) { downcasted = int96(value); require(downcasted == value, "SafeCast: value doesn't fit in 96 bits"); } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toInt88(int256 value) internal pure returns (int88 downcasted) { downcasted = int88(value); require(downcasted == value, "SafeCast: value doesn't fit in 88 bits"); } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toInt80(int256 value) internal pure returns (int80 downcasted) { downcasted = int80(value); require(downcasted == value, "SafeCast: value doesn't fit in 80 bits"); } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toInt72(int256 value) internal pure returns (int72 downcasted) { downcasted = int72(value); require(downcasted == value, "SafeCast: value doesn't fit in 72 bits"); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64 downcasted) { downcasted = int64(value); require(downcasted == value, "SafeCast: value doesn't fit in 64 bits"); } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toInt56(int256 value) internal pure returns (int56 downcasted) { downcasted = int56(value); require(downcasted == value, "SafeCast: value doesn't fit in 56 bits"); } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toInt48(int256 value) internal pure returns (int48 downcasted) { downcasted = int48(value); require(downcasted == value, "SafeCast: value doesn't fit in 48 bits"); } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toInt40(int256 value) internal pure returns (int40 downcasted) { downcasted = int40(value); require(downcasted == value, "SafeCast: value doesn't fit in 40 bits"); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32 downcasted) { downcasted = int32(value); require(downcasted == value, "SafeCast: value doesn't fit in 32 bits"); } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toInt24(int256 value) internal pure returns (int24 downcasted) { downcasted = int24(value); require(downcasted == value, "SafeCast: value doesn't fit in 24 bits"); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16 downcasted) { downcasted = int16(value); require(downcasted == value, "SafeCast: value doesn't fit in 16 bits"); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8 downcasted) { downcasted = int8(value); require(downcasted == value, "SafeCast: value doesn't fit in 8 bits"); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. * * _Available since v3.0._ */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; library PriceLib { using Math for uint; // WAD adjusted result function convertToValue(uint amount, uint price, uint8 decimals) internal pure returns (uint) { return amount * price / 10 ** decimals; } // Coll decimal adjust amount result function convertAssetsToCollAmount(uint assets, uint collPrice, uint nectPrice, uint8 vaultDecimals, uint8 collDecimals, Math.Rounding rounding) internal pure returns (uint) { uint assetsUsdValue = assets.mulDiv(nectPrice, 10 ** vaultDecimals, rounding); if (collPrice != 0) { return assetsUsdValue.mulDiv(10 ** collDecimals, collPrice, rounding); } else { return 0; } } function convertCollAmountToAssets(uint collAmount, uint collPrice, uint nectPrice, uint8 vaultDecimals, uint8 collDecimals) internal pure returns (uint) { uint collUsdValue = collAmount * collPrice / 10 ** collDecimals; if (nectPrice != 0) { return collUsdValue * 10 ** vaultDecimals / nectPrice; } else { return 0; } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol"; import {DynamicArrayLib} from "solady/utils/DynamicArrayLib.sol"; import {IInfraredCollateralVault} from "src/interfaces/core/vaults/IInfraredCollateralVault.sol"; library TokenValidationLib { using DynamicArrayLib for DynamicArrayLib.DynamicArray; using DynamicArrayLib for address[]; using DynamicArrayLib for uint[]; error DuplicateToken(); error InvalidToken(); function checkForDuplicates(address[] memory tokens, uint length) internal pure { for (uint i; i < length; i++) { for (uint j = i + 1; j < length; j++) { if (tokens[i] == tokens[j]) revert DuplicateToken(); } } } function checkValidToken(address token, address[] memory collaterals, uint collateralsLength, address nect, bool isExtraAsset) internal pure { if (isExtraAsset || token == nect) { return; } bool isCollateral; for (uint j; j < collateralsLength; j++) { if (collaterals[j] == token) { isCollateral = true; break; } } if (!isCollateral) revert InvalidToken(); } function aggregateIfNotExistent( address token, uint amount, DynamicArrayLib.DynamicArray memory tokens, DynamicArrayLib.DynamicArray memory amounts ) internal pure { uint index = tokens.indexOf(token); if (index != DynamicArrayLib.NOT_FOUND) { uint existingAmount = amounts.getUint256(index); amounts.set(index, existingAmount + amount); } else { tokens.p(token); amounts.p(amount); } } function contains(address[] memory tokenArray, address targetToken) internal pure returns (uint256) { uint256 length = tokenArray.length; for (uint256 i; i < length; ++i) { if (tokenArray[i] == targetToken) { return i + 1; } } return 0; } /// @dev If the ibgtVault is included in the rewardTokens list, it returns a new reward array that includes the rewardToken list from the ibgtVault. function tryGetRewardedTokensIncludingIbgtVault( address[] memory rewardTokens, address collVaultAsset, IInfraredCollateralVault ibgtVault ) internal view returns (address[] memory, uint256) { // Gets a new rewardToken array that includes collVaultAsset. (address[] memory newRewardTokens, uint256 length) = underlyingCollVaultAssets(rewardTokens, collVaultAsset); uint256 ibgtVaultIdx = contains(newRewardTokens, address(ibgtVault)); // returns when ibgtVault is not included in rewardTokens array if(ibgtVaultIdx == 0) { return (newRewardTokens, length); } // replace ibgtVault with ibgt newRewardTokens[ibgtVaultIdx - 1] = ibgtVault.asset(); address[] memory ibgtVaultRewardTokens = tryGetRewardedTokens(ibgtVault); if(ibgtVaultRewardTokens.length == 0) { return (newRewardTokens, length); } // finalRewardTokens length shouldn't be bigger than (length + ibgtVaultLength) uint256 ibgtVaultLength = ibgtVaultRewardTokens.length; address[] memory finalRewardTokens = new address[](length + ibgtVaultLength); uint256 finalLength; // Merge two arrays using the union set method for(uint256 i; i < length; ++i) { if(contains(ibgtVaultRewardTokens, newRewardTokens[i]) == 0) { finalRewardTokens[finalLength] = newRewardTokens[i]; ++finalLength; } } for(uint256 i; i < ibgtVaultLength; ++i) { finalRewardTokens[finalLength] = ibgtVaultRewardTokens[i]; ++finalLength; } assembly { mstore(finalRewardTokens, finalLength) } return (finalRewardTokens, finalLength); } /// @dev Checks if asset is included in reward tokens array (e.g. BBiBGT) /// @dev CollVault main asset goes at index (len - 1), if it is not included in reward tokens /// @dev The ordering is inlined with the `CollVaultRouter::previewRedeemUnderlying()` function function underlyingCollVaultAssets(address[] memory rewardTokens, address collVaultAsset) internal pure returns (address[] memory, uint256) { uint256 originalLength = rewardTokens.length; if(contains(rewardTokens, collVaultAsset) > 0) { return (rewardTokens, originalLength); } address[] memory _rewardTokens = new address[](originalLength + 1); for (uint i; i < originalLength; ++i) { _rewardTokens[i] = rewardTokens[i]; } _rewardTokens[originalLength] = collVaultAsset; return (_rewardTokens, originalLength + 1); } /// @dev Vaults in LSP could still not have been upgrade to InfraredCollateralVault if there is no InfraredVault to earn PoL deployed yet function tryGetRewardedTokens(IInfraredCollateralVault collVault) internal view returns (address[] memory) { address[] memory rewardedTokens; try collVault.rewardedTokens() returns (address[] memory _rewardedTokens) { rewardedTokens = _rewardedTokens; } catch {} return rewardedTokens; } function underlyingAmounts(address[] calldata tokens, address account) internal view returns (uint[] memory amounts) { amounts = new uint[](tokens.length); for (uint i; i < tokens.length; i++) { amounts[i] = IERC20(tokens[i]).balanceOf(account); } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {ILiquidStabilityPool} from "../interfaces/core/ILiquidStabilityPool.sol"; library EmissionsLib { using SafeCast for uint256; uint64 constant internal DEFAULT_UNLOCK_RATE = 1e11; // 10% per second uint64 constant internal MAX_UNLOCK_RATE = 1e12; // 100% struct BalanceData { mapping(address token => uint) balance; mapping(address token => EmissionSchedule) emissionSchedule; } struct EmissionSchedule { uint128 emissions; uint64 lockTimestamp; uint64 _unlockRatePerSecond; // rate points } error AmountCannotBeZero(); error EmissionRateExceedsMax(); // error UnsupportedEmissionConfig(); event EmissionsAdded(address indexed token, uint128 amount); event EmissionsSub(address indexed token, uint128 amount); event NewUnlockRatePerSecond(address indexed token, uint64 unlockRatePerSecond); /// @dev zero _unlockRatePerSecond parameter resets rate back to DEFAULT_UNLOCK_RATE function setUnlockRatePerSecond(BalanceData storage $, address token, uint64 _unlockRatePerSecond) internal { if (_unlockRatePerSecond > MAX_UNLOCK_RATE) revert EmissionRateExceedsMax(); _addEmissions($, token, 0); // update lockTimestamp and emissions $.emissionSchedule[token]._unlockRatePerSecond = _unlockRatePerSecond; emit NewUnlockRatePerSecond(token, _unlockRatePerSecond); } function addEmissions(BalanceData storage $, address token, uint128 amount) internal { if (amount == 0) revert AmountCannotBeZero(); _addEmissions($, token, amount); emit EmissionsAdded(token, amount); } function _addEmissions(BalanceData storage $, address token, uint128 amount) private { EmissionSchedule memory schedule = $.emissionSchedule[token]; uint256 _unlockTimestamp = unlockTimestamp(schedule); uint128 nextEmissions = (lockedEmissions(schedule, _unlockTimestamp) + amount).toUint128(); schedule.emissions = nextEmissions; schedule.lockTimestamp = block.timestamp.toUint64(); $.balance[token] += amount; $.emissionSchedule[token] = schedule; } function subEmissions(BalanceData storage $, address token, uint128 amount) internal { if (amount == 0) revert AmountCannotBeZero(); _subEmissions($, token, amount); emit EmissionsSub(token, amount); } function _subEmissions(BalanceData storage $, address token, uint128 amount) private { EmissionSchedule memory schedule = $.emissionSchedule[token]; uint256 _unlockTimestamp = unlockTimestamp(schedule); uint128 nextEmissions = (lockedEmissions(schedule, _unlockTimestamp) - amount).toUint128(); schedule.emissions = nextEmissions; schedule.lockTimestamp = block.timestamp.toUint64(); $.balance[token] -= amount; $.emissionSchedule[token] = schedule; } /// @dev Doesn't include locked emissions function unlockedEmissions(EmissionSchedule memory schedule) internal view returns (uint256) { return schedule.emissions - lockedEmissions(schedule, unlockTimestamp(schedule)); } function balanceOfWithFutureEmissions(BalanceData storage $, address token) internal view returns (uint256) { return $.balance[token]; } /** * @notice Returns the unlocked token emissions */ function balanceOf(BalanceData storage $, address token) internal view returns (uint256) { EmissionSchedule memory schedule = $.emissionSchedule[token]; return $.balance[token] - lockedEmissions(schedule, unlockTimestamp(schedule)); } /** * @notice Returns locked emissions */ function lockedEmissions(EmissionSchedule memory schedule, uint256 _unlockTimestamp) internal view returns (uint256) { if (block.timestamp >= _unlockTimestamp) { // all emissions were unlocked return 0; } else { // emissions are still unlocking, calculate the amount of already unlocked emissions uint256 secondsSinceLockup = block.timestamp - schedule.lockTimestamp; // design decision - use dimensionless 'unlock rate units' to unlock emissions over a fixed time window uint256 ratePointsUnlocked = unlockRatePerSecond(schedule) * secondsSinceLockup; // emissions remainder is designed to be added to balance in unlockTimestamp return schedule.emissions - ratePointsUnlocked * schedule.emissions / MAX_UNLOCK_RATE; } } // timestamp at which all emissions are fully unlocked function unlockTimestamp(EmissionSchedule memory schedule) internal pure returns (uint256) { // ceil to account for remainder seconds left after integer division return divRoundUp(MAX_UNLOCK_RATE, unlockRatePerSecond(schedule)) + schedule.lockTimestamp; } function unlockRatePerSecond(EmissionSchedule memory schedule) internal pure returns (uint256) { return schedule._unlockRatePerSecond == 0 ? DEFAULT_UNLOCK_RATE : schedule._unlockRatePerSecond; } function divRoundUp(uint256 dividend, uint256 divisor) internal pure returns (uint256) { return (dividend + divisor - 1) / divisor; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; library FeeLib { using Math for uint; uint private constant BP = 1e4; /// @dev Calculates the fees that should be added to an amount `shares` that does already include fees. /// Used in {IERC4626-deposit}, {IERC4626-mint}, {IERC4626-withdraw} and {IERC4626-previewRedeem} operations. function feeOnRaw( uint shares, uint feeBP ) internal pure returns (uint) { return shares.mulDiv(feeBP, BP, Math.Rounding.Up); } /// @dev Calculates the fee part of an amount `shares` that deoes not includes fees. /// Used in {IERC4626-previewDeposit} and {IERC4626-previewRedeem} operations. function feeOnTotal( uint shares, uint feeBP ) internal pure returns (uint) { return shares.mulDiv(feeBP, feeBP + BP, Math.Rounding.Up); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; library BeraborrowMath { uint256 internal constant DECIMAL_PRECISION = 1e18; /* Precision for Nominal ICR (independent of price). Rationale for the value: * * - Making it “too high” could lead to overflows. * - Making it “too low” could lead to an ICR equal to zero, due to truncation from Solidity floor division. * * This value of 1e20 is chosen for safety: the NICR will only overflow for numerator > ~1e39, * and will only truncate to 0 if the denominator is at least 1e20 times greater than the numerator. * */ uint256 internal constant NICR_PRECISION = 1e20; function _min(uint256 _a, uint256 _b) internal pure returns (uint256) { return (_a < _b) ? _a : _b; } function _max(uint256 _a, uint256 _b) internal pure returns (uint256) { return (_a >= _b) ? _a : _b; } /* * Multiply two decimal numbers and use normal rounding rules: * -round product up if 19'th mantissa digit >= 5 * -round product down if 19'th mantissa digit < 5 * * Used only inside the exponentiation, _decPow(). */ function decMul(uint256 x, uint256 y) internal pure returns (uint256 decProd) { uint256 prod_xy = x * y; decProd = (prod_xy + (DECIMAL_PRECISION / 2)) / DECIMAL_PRECISION; } /* * _decPow: Exponentiation function for 18-digit decimal base, and integer exponent n. * * Uses the efficient "exponentiation by squaring" algorithm. O(log(n)) complexity. * * Called by two functions that represent time in units of minutes: * 1) DenManager._calcDecayedBaseRate * 2) CommunityIssuance._getCumulativeIssuanceFraction * * The exponent is capped to avoid reverting due to overflow. The cap 525600000 equals * "minutes in 1000 years": 60 * 24 * 365 * 1000 * * If a period of > 1000 years is ever used as an exponent in either of the above functions, the result will be * negligibly different from just passing the cap, since: * * In function 1), the decayed base rate will be 0 for 1000 years or > 1000 years * In function 2), the difference in tokens issued at 1000 years and any time > 1000 years, will be negligible */ function _decPow(uint256 _base, uint256 _minutes) internal pure returns (uint256) { if (_minutes > 525600000) { _minutes = 525600000; } // cap to avoid overflow if (_minutes == 0) { return DECIMAL_PRECISION; } uint256 y = DECIMAL_PRECISION; uint256 x = _base; uint256 n = _minutes; // Exponentiation-by-squaring while (n > 1) { if (n % 2 == 0) { x = decMul(x, x); n = n / 2; } else { // if (n % 2 != 0) y = decMul(x, y); x = decMul(x, x); n = (n - 1) / 2; } } return decMul(x, y); } function _getAbsoluteDifference(uint256 _a, uint256 _b) internal pure returns (uint256) { return (_a >= _b) ? _a - _b : _b - _a; } function _computeNominalCR(uint256 _coll, uint256 _debt) internal pure returns (uint256) { if (_debt > 0) { return (_coll * NICR_PRECISION) / _debt; } // Return the maximal value for uint256 if the Den has a debt of 0. Represents "infinite" CR. else { // if (_debt == 0) return 2 ** 256 - 1; } } function _computeCR(uint256 _coll, uint256 _debt, uint256 _price) internal pure returns (uint256) { if (_debt > 0) { uint256 newCollRatio = (_coll * _price) / _debt; return newCollRatio; } // Return the maximal value for uint256 if the Den has a debt of 0. Represents "infinite" CR. else { // if (_debt == 0) return 2 ** 256 - 1; } } function _computeCR(uint256 _coll, uint256 _debt) internal pure returns (uint256) { if (_debt > 0) { uint256 newCollRatio = (_coll) / _debt; return newCollRatio; } // Return the maximal value for uint256 if the Den has a debt of 0. Represents "infinite" CR. else { // if (_debt == 0) return 2 ** 256 - 1; } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol"; import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol"; import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol"; import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import {IMetaBeraborrowCore} from "./IMetaBeraborrowCore.sol"; import {IDebtToken} from "./IDebtToken.sol"; import {IDebtToken} from "./IDebtToken.sol"; import {EmissionsLib} from "src/libraries/EmissionsLib.sol"; interface ILiquidStabilityPool is IERC4626, IERC1822Proxiable { struct LSPStorage { IMetaBeraborrowCore metaBeraborrowCore; address feeReceiver; /// @notice Array of tokens that have been emitted to the LiquidStabilityPool /// @notice Used to track which tokens can be withdrawn to LSP share holders /// @dev Doesn't include tokens that are already BeraBorrow's collaterals EnumerableSet.AddressSet extraAssets; Queue queue; address[] collateralTokens; mapping(uint16 => SunsetIndex) _sunsetIndexes; mapping(address collateral => uint256 index) indexByCollateral; mapping(bytes32 => uint) threshold; EmissionsLib.BalanceData balanceData; mapping(address => bool) factoryProtocol; mapping(address => bool) liquidationManagerProtocol; // Allowed to withdraw their positions during bootstrap period mapping(address => bool) boycoVault; } struct InitParams { IERC20 _asset; string _sharesName; string _sharesSymbol; IMetaBeraborrowCore _metaBeraborrowCore; address _liquidationManager; address _factory; address _feeReceiver; } struct RebalanceParams { address sentCurrency; uint sentAmount; address receivedCurrency; address swapper; bytes payload; } struct SunsetIndex { uint128 idx; uint128 expiry; } struct Queue { uint16 firstSunsetIndexKey; uint16 nextSunsetIndexKey; } event CollAndEmissionsWithdraw( address indexed receiver, uint shares, uint[] amounts ); struct Arrays { uint length; address[] collaterals; uint collateralsLength; uint[] amounts; } event EmissionTokenAdded(address token); event EmissionTokenRemoved(address token); event StabilityPoolDebtBalanceUpdated(uint256 newBalance); event UserDepositChanged(address indexed depositor, uint256 newDeposit); event CollateralOverwritten(address oldCollateral, address newCollateral); // PROXY function upgradeToAndCall(address newImplementation, bytes calldata data) external; function getCurrentImplementation() external view returns (address); function SUNSET_DURATION() external view returns (uint128); function totalDebtTokenDeposits() external view returns (uint256); function enableCollateral(address _collateral, uint64 _unlockRatePerSecond, bool forceThroughBalanceCheck) external; function startCollateralSunset(address collateral) external; function getTotalDebtTokenDeposits() external view returns (uint256); function getCollateralTokens() external view returns (address[] memory); function offset(address collateral, uint256 _debtToOffset, uint256 _collToAdd) external; function initialize(InitParams calldata params) external; function rebalance(RebalanceParams calldata p) external; function linearVestingExtraAssets(address token, int amount, address recipient) external; function withdraw( uint assets, address[] calldata preferredUnderlyingTokens, address receiver, address _owner ) external returns (uint shares); function redeem( uint shares, address[] calldata preferredUnderlyingTokens, address receiver, address _owner ) external returns (uint assets); function updateProtocol( address _liquidationManager, address _factory, bool _register ) external; function addNewExtraAsset(address token, uint64 _unlockRatePerSecond) external; function removeEmitedTokens(address token) external; function setPairThreshold(address tokenIn, address tokenOut, uint thresholdInBP) external; function setUnlockRatePerSecond(address token, uint64 _unlockRatePerSecond) external; function getPrice(address token) external view returns (uint); function getLockedEmissions(address token) external view returns (uint); function extSloads(bytes32[] calldata slots) external view returns (bytes32[] memory res); function unlockRatePerSecond(address token) external view returns (uint); function removeExtraAsset(address token) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IPriceFeed { struct FeedType { address spotOracle; bool isCollVault; } event NewOracleRegistered(address token, address chainlinkAggregator, address underlyingDerivative); event PriceFeedStatusUpdated(address token, address oracle, bool isWorking); event PriceRecordUpdated(address indexed token, uint256 _price); event NewCollVaultRegistered(address collVault, bool enable); event NewSpotOracleRegistered(address token, address spotOracle); function fetchPrice(address _token) external view returns (uint256); function getMultiplePrices(address[] memory _tokens) external view returns (uint256[] memory prices); function setOracle( address _token, address _chainlinkOracle, uint32 _heartbeat, uint16 _staleThreshold, address underlyingDerivative ) external; function whitelistCollateralVault(address _collateralVaultShareToken, bool enable) external; function setSpotOracle(address _token, address _spotOracle) external; function MAX_PRICE_DEVIATION_FROM_PREVIOUS_ROUND() external view returns (uint256); function BERABORROW_CORE() external view returns (address); function RESPONSE_TIMEOUT() external view returns (uint256); function TARGET_DIGITS() external view returns (uint256); function guardian() external view returns (address); function oracleRecords( address ) external view returns ( address chainLinkOracle, uint8 decimals, uint32 heartbeat, uint16 staleThreshold, address underlyingDerivative ); function isCollVault(address _collateralVaultShareToken) external view returns (bool); function isStableBPT(address _oracle) external view returns (bool); function isWeightedBPT(address _oracle) external view returns (bool); function getSpotOracle(address _token) external view returns (address); function feedType(address _token) external view returns (FeedType memory); function owner() external view returns (address); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { IERC3156FlashBorrower } from "@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol"; import "./IBeraborrowCore.sol"; interface IDebtToken is IERC20 { // --- Events --- event FlashLoanFeeUpdated(uint256 newFee); // --- Public constants --- function version() external view returns (string memory); function permitTypeHash() external view returns (bytes32); // --- Public immutables --- function gasPool() external view returns (address); function DEBT_GAS_COMPENSATION() external view returns (uint256); function PSMBond() external view returns (address); // --- Public mappings --- function liquidStabilityPools(address) external view returns (bool); function borrowerOperations(address) external view returns (bool); function factories(address) external view returns (bool); function peripheries(address) external view returns (bool); function denManagers(address) external view returns (bool); // --- External functions --- function enableDenManager(address _denManager) external; function mintWithGasCompensation(address _account, uint256 _amount) external returns (bool); function burnWithGasCompensation(address _account, uint256 _amount) external returns (bool); function mint(address _account, uint256 _amount) external; function burn(address _account, uint256 _amount) external; function decimals() external view returns (uint8); function sendToPeriphery(address _sender, uint256 _amount) external; function sendToSP(address _sender, uint256 _amount) external; function returnFromPool(address _poolAddress, address _receiver, uint256 _amount) external; function transfer(address recipient, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); function maxFlashLoan(address token) external view returns (uint256); function flashFee(address token, uint256 amount) external view returns (uint256); function flashLoan( IERC3156FlashBorrower receiver, address token, uint256 amount, bytes calldata data ) external returns (bool); function whitelistLiquidStabilityPoolAddress(address _liquidStabilityPool, bool active) external; function whitelistBorrowerOperationsAddress(address _borrowerOperations, bool active) external; function whitelistFactoryAddress(address _factory, bool active) external; function whitelistPeripheryAddress(address _periphery, bool active) external; function setDebtGasCompensation(uint256 _gasCompensation, bool _isFinalValue) external; function setFlashLoanFee(uint256 _fee) external; function DOMAIN_SEPARATOR() external view returns (bytes32); function permit( address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; function nonces(address owner) external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {IMetaBeraborrowCore} from "src/interfaces/core/IMetaBeraborrowCore.sol"; interface IBeraborrowCore { // --- Public variables --- function metaBeraborrowCore() external view returns (IMetaBeraborrowCore); function startTime() external view returns (uint256); function CCR() external view returns (uint256); function dmBootstrapPeriod() external view returns (uint64); function isPeriphery(address peripheryContract) external view returns (bool); // --- External functions --- function setPeripheryEnabled(address _periphery, bool _enabled) external; function setDMBootstrapPeriod(address dm, uint64 _bootstrapPeriod) external; function setNewCCR(uint256 _CCR) external; function priceFeed() external view returns (address); function owner() external view returns (address); function pendingOwner() external view returns (address); function guardian() external view returns (address); function manager() external view returns (address); function feeReceiver() external view returns (address); function paused() external view returns (bool); function lspBootstrapPeriod() external view returns (uint64); function getLspEntryFee(address rebalancer) external view returns (uint16); function getLspExitFee(address rebalancer) external view returns (uint16); function getPeripheryFlashLoanFee(address peripheryContract) external view returns (uint16); // --- Events --- event CCRSet(uint256 initialCCR); event DMBootstrapPeriodSet(address dm, uint64 bootstrapPeriod); event PeripheryEnabled(address indexed periphery, bool enabled); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; interface IRebalancer { function swap( address sentCurrency, uint sentAmount, address receivedCurrency, bytes calldata payload ) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol"; interface IAsset is IERC20 { function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ 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/ERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {ContextUpgradeable} from "../../utils/ContextUpgradeable.sol"; import {IERC20Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol"; import {Initializable} from "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * * TIP: For a detailed writeup see our guide * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * The default value of {decimals} is 18. To change this, you should override * this function so it returns a different value. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC-20 * applications. */ abstract contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20, IERC20Metadata, IERC20Errors { /// @custom:storage-location erc7201:openzeppelin.storage.ERC20 struct ERC20Storage { mapping(address account => uint256) _balances; mapping(address account => mapping(address spender => uint256)) _allowances; uint256 _totalSupply; string _name; string _symbol; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC20")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant ERC20StorageLocation = 0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00; function _getERC20Storage() private pure returns (ERC20Storage storage $) { assembly { $.slot := ERC20StorageLocation } } /** * @dev Sets the values for {name} and {symbol}. * * All two of these values are immutable: they can only be set once during * construction. */ function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing { __ERC20_init_unchained(name_, symbol_); } function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing { ERC20Storage storage $ = _getERC20Storage(); $._name = name_; $._symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual returns (string memory) { ERC20Storage storage $ = _getERC20Storage(); return $._name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual returns (string memory) { ERC20Storage storage $ = _getERC20Storage(); 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) { ERC20Storage storage $ = _getERC20Storage(); return $._totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual returns (uint256) { ERC20Storage storage $ = _getERC20Storage(); 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) { ERC20Storage storage $ = _getERC20Storage(); return $._allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 value) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, value); return true; } /** * @dev See {IERC20-transferFrom}. * * Skips emitting an {Approval} event indicating an allowance update. This is not * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve]. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `value`. * - the caller must have allowance for ``from``'s tokens of at least * `value`. */ function transferFrom(address from, address to, uint256 value) public virtual returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, value); _transfer(from, to, value); return true; } /** * @dev Moves a `value` amount of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * NOTE: This function is not virtual, {_update} should be overridden instead. */ function _transfer(address from, address to, uint256 value) internal { if (from == address(0)) { revert ERC20InvalidSender(address(0)); } if (to == address(0)) { revert ERC20InvalidReceiver(address(0)); } _update(from, to, value); } /** * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from` * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding * this function. * * Emits a {Transfer} event. */ function _update(address from, address to, uint256 value) internal virtual { ERC20Storage storage $ = _getERC20Storage(); if (from == address(0)) { // Overflow check required: The rest of the code assumes that totalSupply never overflows $._totalSupply += value; } else { uint256 fromBalance = $._balances[from]; if (fromBalance < value) { revert ERC20InsufficientBalance(from, fromBalance, value); } unchecked { // Overflow not possible: value <= fromBalance <= totalSupply. $._balances[from] = fromBalance - value; } } if (to == address(0)) { unchecked { // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply. $._totalSupply -= value; } } else { unchecked { // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256. $._balances[to] += value; } } emit Transfer(from, to, value); } /** * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0). * Relies on the `_update` mechanism * * Emits a {Transfer} event with `from` set to the zero address. * * NOTE: This function is not virtual, {_update} should be overridden instead. */ function _mint(address account, uint256 value) internal { if (account == address(0)) { revert ERC20InvalidReceiver(address(0)); } _update(address(0), account, value); } /** * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply. * Relies on the `_update` mechanism. * * Emits a {Transfer} event with `to` set to the zero address. * * NOTE: This function is not virtual, {_update} should be overridden instead */ function _burn(address account, uint256 value) internal { if (account == address(0)) { revert ERC20InvalidSender(address(0)); } _update(account, address(0), value); } /** * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. * * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument. */ function _approve(address owner, address spender, uint256 value) internal { _approve(owner, spender, value, true); } /** * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event. * * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any * `Approval` event during `transferFrom` operations. * * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to * true using the following override: * * ```solidity * function _approve(address owner, address spender, uint256 value, bool) internal virtual override { * super._approve(owner, spender, value, true); * } * ``` * * Requirements are the same as {_approve}. */ function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual { ERC20Storage storage $ = _getERC20Storage(); 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 v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-IERC20Permit.sol"; import "../../../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; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @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, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (interfaces/IERC4626.sol) pragma solidity ^0.8.0; import "../token/ERC20/IERC20.sol"; import "../token/ERC20/extensions/IERC20Metadata.sol"; /** * @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626]. * * _Available since v4.7._ */ interface IERC4626 is IERC20, IERC20Metadata { event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares); event Withdraw( address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares ); /** * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing. * * - MUST be an ERC-20 token contract. * - MUST NOT revert. */ function asset() external view returns (address assetTokenAddress); /** * @dev Returns the total amount of the underlying asset that is “managed” by Vault. * * - SHOULD include any compounding that occurs from yield. * - MUST be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT revert. */ function totalAssets() external view returns (uint256 totalManagedAssets); /** * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal * scenario where all the conditions are met. * * - MUST NOT be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT show any variations depending on the caller. * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange. * - MUST NOT revert. * * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and * from. */ function convertToShares(uint256 assets) external view returns (uint256 shares); /** * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal * scenario where all the conditions are met. * * - MUST NOT be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT show any variations depending on the caller. * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange. * - MUST NOT revert. * * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and * from. */ function convertToAssets(uint256 shares) external view returns (uint256 assets); /** * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver, * through a deposit call. * * - MUST return a limited value if receiver is subject to some deposit limit. * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited. * - MUST NOT revert. */ function maxDeposit(address receiver) external view returns (uint256 maxAssets); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given * current on-chain conditions. * * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit * call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called * in the same transaction. * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the * deposit would be accepted, regardless if the user has enough tokens approved, etc. * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by depositing. */ function previewDeposit(uint256 assets) external view returns (uint256 shares); /** * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens. * * - MUST emit the Deposit event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * deposit execution, and are accounted for during deposit. * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not * approving enough underlying tokens to the Vault contract, etc). * * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token. */ function deposit(uint256 assets, address receiver) external returns (uint256 shares); /** * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call. * - MUST return a limited value if receiver is subject to some mint limit. * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted. * - MUST NOT revert. */ function maxMint(address receiver) external view returns (uint256 maxShares); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given * current on-chain conditions. * * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call * in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the * same transaction. * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint * would be accepted, regardless if the user has enough tokens approved, etc. * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by minting. */ function previewMint(uint256 shares) external view returns (uint256 assets); /** * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens. * * - MUST emit the Deposit event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint * execution, and are accounted for during mint. * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not * approving enough underlying tokens to the Vault contract, etc). * * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token. */ function mint(uint256 shares, address receiver) external returns (uint256 assets); /** * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the * Vault, through a withdraw call. * * - MUST return a limited value if owner is subject to some withdrawal limit or timelock. * - MUST NOT revert. */ function maxWithdraw(address owner) external view returns (uint256 maxAssets); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block, * given current on-chain conditions. * * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw * call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if * called * in the same transaction. * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though * the withdrawal would be accepted, regardless if the user has enough shares, etc. * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by depositing. */ function previewWithdraw(uint256 assets) external view returns (uint256 shares); /** * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver. * * - MUST emit the Withdraw event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * withdraw execution, and are accounted for during withdraw. * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner * not having enough shares, etc). * * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed. * Those methods should be performed separately. */ function withdraw( uint256 assets, address receiver, address owner ) external returns (uint256 shares); /** * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault, * through a redeem call. * * - MUST return a limited value if owner is subject to some withdrawal limit or timelock. * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock. * - MUST NOT revert. */ function maxRedeem(address owner) external view returns (uint256 maxShares); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block, * given current on-chain conditions. * * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call * in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the * same transaction. * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the * redemption would be accepted, regardless if the user has enough shares, etc. * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by redeeming. */ function previewRedeem(uint256 shares) external view returns (uint256 assets); /** * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver. * * - MUST emit the Withdraw event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * redeem execution, and are accounted for during redeem. * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner * not having enough shares, etc). * * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed. * Those methods should be performed separately. */ function redeem( uint256 shares, address receiver, address owner ) external returns (uint256 assets); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10**64) { value /= 10**64; result += 64; } if (value >= 10**32) { value /= 10**32; result += 32; } if (value >= 10**16) { value /= 10**16; result += 16; } if (value >= 10**8) { value /= 10**8; result += 8; } if (value >= 10**4) { value /= 10**4; result += 4; } if (value >= 10**2) { value /= 10**2; result += 2; } if (value >= 10**1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.20; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Storage of the initializable contract. * * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions * when using with upgradeable contracts. * * @custom:storage-location erc7201:openzeppelin.storage.Initializable */ struct InitializableStorage { /** * @dev Indicates that the contract has been initialized. */ uint64 _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool _initializing; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00; /** * @dev The contract is already initialized. */ error InvalidInitialization(); /** * @dev The contract is not initializing. */ error NotInitializing(); /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint64 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in * production. * * Emits an {Initialized} event. */ modifier initializer() { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); // Cache values to avoid duplicated sloads bool isTopLevelCall = !$._initializing; uint64 initialized = $._initialized; // Allowed calls: // - initialSetup: the contract is not in the initializing state and no previous version was // initialized // - construction: the contract is initialized at version 1 (no reininitialization) and the // current contract is just being deployed bool initialSetup = initialized == 0 && isTopLevelCall; bool construction = initialized == 1 && address(this).code.length == 0; if (!initialSetup && !construction) { revert InvalidInitialization(); } $._initialized = 1; if (isTopLevelCall) { $._initializing = true; } _; if (isTopLevelCall) { $._initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint64 version) { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing || $._initialized >= version) { revert InvalidInitialization(); } $._initialized = version; $._initializing = true; _; $._initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { _checkInitializing(); _; } /** * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}. */ function _checkInitializing() internal view virtual { if (!_isInitializing()) { revert NotInitializing(); } } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing) { revert InvalidInitialization(); } if ($._initialized != type(uint64).max) { $._initialized = type(uint64).max; emit Initialized(type(uint64).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint64) { return _getInitializableStorage()._initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _getInitializableStorage()._initializing; } /** * @dev Returns a pointer to the storage namespace. */ // solhint-disable-next-line var-name-mixedcase function _getInitializableStorage() private pure returns (InitializableStorage storage $) { assembly { $.slot := INITIALIZABLE_STORAGE } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol) pragma solidity ^0.8.0; /** * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified * proxy whose upgrades are fully controlled by the current implementation. */ interface IERC1822Proxiable { /** * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation * address. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. */ function proxiableUUID() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol) pragma solidity ^0.8.21; import {IBeacon} from "../beacon/IBeacon.sol"; import {IERC1967} from "../../interfaces/IERC1967.sol"; import {Address} from "../../utils/Address.sol"; import {StorageSlot} from "../../utils/StorageSlot.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots. */ library ERC1967Utils { /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1. */ // solhint-disable-next-line private-vars-leading-underscore bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev The `implementation` of the proxy is invalid. */ error ERC1967InvalidImplementation(address implementation); /** * @dev The `admin` of the proxy is invalid. */ error ERC1967InvalidAdmin(address admin); /** * @dev The `beacon` of the proxy is invalid. */ error ERC1967InvalidBeacon(address beacon); /** * @dev An upgrade function sees `msg.value > 0` that may be lost. */ error ERC1967NonPayable(); /** * @dev Returns the current implementation address. */ function getImplementation() internal view returns (address) { return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the ERC-1967 implementation slot. */ function _setImplementation(address newImplementation) private { if (newImplementation.code.length == 0) { revert ERC1967InvalidImplementation(newImplementation); } StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Performs implementation upgrade with additional setup call if data is nonempty. * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected * to avoid stuck value in the contract. * * Emits an {IERC1967-Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) internal { _setImplementation(newImplementation); emit IERC1967.Upgraded(newImplementation); if (data.length > 0) { Address.functionDelegateCall(newImplementation, data); } else { _checkNonPayable(); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1. */ // solhint-disable-next-line private-vars-leading-underscore bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Returns the current admin. * * TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103` */ function getAdmin() internal view returns (address) { return StorageSlot.getAddressSlot(ADMIN_SLOT).value; } /** * @dev Stores a new address in the ERC-1967 admin slot. */ function _setAdmin(address newAdmin) private { if (newAdmin == address(0)) { revert ERC1967InvalidAdmin(address(0)); } StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {IERC1967-AdminChanged} event. */ function changeAdmin(address newAdmin) internal { emit IERC1967.AdminChanged(getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1. */ // solhint-disable-next-line private-vars-leading-underscore bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Returns the current beacon. */ function getBeacon() internal view returns (address) { return StorageSlot.getAddressSlot(BEACON_SLOT).value; } /** * @dev Stores a new beacon in the ERC-1967 beacon slot. */ function _setBeacon(address newBeacon) private { if (newBeacon.code.length == 0) { revert ERC1967InvalidBeacon(newBeacon); } StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon; address beaconImplementation = IBeacon(newBeacon).implementation(); if (beaconImplementation.code.length == 0) { revert ERC1967InvalidImplementation(beaconImplementation); } } /** * @dev Change the beacon and trigger a setup call if data is nonempty. * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected * to avoid stuck value in the contract. * * Emits an {IERC1967-BeaconUpgraded} event. * * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for * efficiency. */ function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal { _setBeacon(newBeacon); emit IERC1967.BeaconUpgraded(newBeacon); if (data.length > 0) { Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data); } else { _checkNonPayable(); } } /** * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract * if an upgrade doesn't perform an initialization call. */ function _checkNonPayable() private { if (msg.value > 0) { revert ERC1967NonPayable(); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol) pragma solidity ^0.8.0; import "../token/ERC20/IERC20.sol";
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Library for memory arrays with automatic capacity resizing. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/DynamicArrayLib.sol) library DynamicArrayLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STRUCTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Type to represent a dynamic array in memory. /// You can directly assign to `data`, and the `p` function will /// take care of the memory allocation. struct DynamicArray { uint256[] data; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The constant returned when the element is not found in the array. uint256 internal constant NOT_FOUND = type(uint256).max; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* UINT256 ARRAY OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // Low level minimalist uint256 array operations. // If you don't need syntax sugar, it's recommended to use these. // Some of these functions returns the same array for function chaining. // e.g. `array.set(0, 1).set(1, 2)`. /// @dev Returns a uint256 array with `n` elements. The elements are not zeroized. function malloc(uint256 n) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { result := or(sub(0, shr(32, n)), mload(0x40)) mstore(result, n) mstore(0x40, add(add(result, 0x20), shl(5, n))) } } /// @dev Zeroizes all the elements of `a`. function zeroize(uint256[] memory a) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { result := a codecopy(add(result, 0x20), codesize(), shl(5, mload(result))) } } /// @dev Returns the element at `a[i]`, without bounds checking. function get(uint256[] memory a, uint256 i) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := mload(add(add(a, 0x20), shl(5, i))) } } /// @dev Returns the element at `a[i]`, without bounds checking. function getUint256(uint256[] memory a, uint256 i) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := mload(add(add(a, 0x20), shl(5, i))) } } /// @dev Returns the element at `a[i]`, without bounds checking. function getAddress(uint256[] memory a, uint256 i) internal pure returns (address result) { /// @solidity memory-safe-assembly assembly { result := mload(add(add(a, 0x20), shl(5, i))) } } /// @dev Returns the element at `a[i]`, without bounds checking. function getBool(uint256[] memory a, uint256 i) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { result := mload(add(add(a, 0x20), shl(5, i))) } } /// @dev Returns the element at `a[i]`, without bounds checking. function getBytes32(uint256[] memory a, uint256 i) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { result := mload(add(add(a, 0x20), shl(5, i))) } } /// @dev Sets `a.data[i]` to `data`, without bounds checking. function set(uint256[] memory a, uint256 i, uint256 data) internal pure returns (uint256[] memory result) { result = a; /// @solidity memory-safe-assembly assembly { mstore(add(add(result, 0x20), shl(5, i)), data) } } /// @dev Sets `a.data[i]` to `data`, without bounds checking. function set(uint256[] memory a, uint256 i, address data) internal pure returns (uint256[] memory result) { result = a; /// @solidity memory-safe-assembly assembly { mstore(add(add(result, 0x20), shl(5, i)), shr(96, shl(96, data))) } } /// @dev Sets `a.data[i]` to `data`, without bounds checking. function set(uint256[] memory a, uint256 i, bool data) internal pure returns (uint256[] memory result) { result = a; /// @solidity memory-safe-assembly assembly { mstore(add(add(result, 0x20), shl(5, i)), iszero(iszero(data))) } } /// @dev Sets `a.data[i]` to `data`, without bounds checking. function set(uint256[] memory a, uint256 i, bytes32 data) internal pure returns (uint256[] memory result) { result = a; /// @solidity memory-safe-assembly assembly { mstore(add(add(result, 0x20), shl(5, i)), data) } } /// @dev Casts `a` to `address[]`. function asAddressArray(uint256[] memory a) internal pure returns (address[] memory result) { /// @solidity memory-safe-assembly assembly { result := a } } /// @dev Casts `a` to `bool[]`. function asBoolArray(uint256[] memory a) internal pure returns (bool[] memory result) { /// @solidity memory-safe-assembly assembly { result := a } } /// @dev Casts `a` to `bytes32[]`. function asBytes32Array(uint256[] memory a) internal pure returns (bytes32[] memory result) { /// @solidity memory-safe-assembly assembly { result := a } } /// @dev Casts `a` to `uint256[]`. function toUint256Array(address[] memory a) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { result := a } } /// @dev Casts `a` to `uint256[]`. function toUint256Array(bool[] memory a) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { result := a } } /// @dev Casts `a` to `uint256[]`. function toUint256Array(bytes32[] memory a) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { result := a } } /// @dev Reduces the size of `a` to `n`. /// If `n` is greater than the size of `a`, this will be a no-op. function truncate(uint256[] memory a, uint256 n) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { result := a mstore(mul(lt(n, mload(result)), result), n) } } /// @dev Clears the array and attempts to free the memory if possible. function free(uint256[] memory a) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { result := a let n := mload(result) mstore(shl(6, lt(iszero(n), eq(add(shl(5, add(1, n)), result), mload(0x40)))), result) mstore(result, 0) } } /// @dev Equivalent to `keccak256(abi.encodePacked(a))`. function hash(uint256[] memory a) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { result := keccak256(add(a, 0x20), shl(5, mload(a))) } } /// @dev Returns a copy of `a` sliced from `start` to `end` (exclusive). function slice(uint256[] memory a, uint256 start, uint256 end) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { let arrayLen := mload(a) if iszero(gt(arrayLen, end)) { end := arrayLen } if iszero(gt(arrayLen, start)) { start := arrayLen } if lt(start, end) { result := mload(0x40) let resultLen := sub(end, start) mstore(result, resultLen) a := add(a, shl(5, start)) // Copy the `a` one word at a time, backwards. let o := shl(5, resultLen) mstore(0x40, add(add(result, o), 0x20)) // Allocate memory. for {} 1 {} { mstore(add(result, o), mload(add(a, o))) o := sub(o, 0x20) if iszero(o) { break } } } } } /// @dev Returns if `needle` is in `a`. function contains(uint256[] memory a, uint256 needle) internal pure returns (bool) { return ~indexOf(a, needle, 0) != 0; } /// @dev Returns the first index of `needle`, scanning forward from `from`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function indexOf(uint256[] memory a, uint256 needle, uint256 from) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := not(0) if lt(from, mload(a)) { let o := add(a, shl(5, from)) let end := add(shl(5, add(1, mload(a))), a) let c := mload(end) // Cache the word after the array. for { mstore(end, needle) } 1 {} { o := add(o, 0x20) if eq(mload(o), needle) { break } } mstore(end, c) // Restore the word after the array. if iszero(eq(o, end)) { result := shr(5, sub(o, add(0x20, a))) } } } } /// @dev Returns the first index of `needle`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function indexOf(uint256[] memory a, uint256 needle) internal pure returns (uint256 result) { result = indexOf(a, needle, 0); } /// @dev Returns the last index of `needle`, scanning backwards from `from`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function lastIndexOf(uint256[] memory a, uint256 needle, uint256 from) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := not(0) let n := mload(a) if n { if iszero(lt(from, n)) { from := sub(n, 1) } let o := add(shl(5, add(2, from)), a) for { mstore(a, needle) } 1 {} { o := sub(o, 0x20) if eq(mload(o), needle) { break } } mstore(a, n) // Restore the length. if iszero(eq(o, a)) { result := shr(5, sub(o, add(0x20, a))) } } } } /// @dev Returns the first index of `needle`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function lastIndexOf(uint256[] memory a, uint256 needle) internal pure returns (uint256 result) { result = lastIndexOf(a, needle, NOT_FOUND); } /// @dev Directly returns `a` without copying. function directReturn(uint256[] memory a) internal pure { assembly { let retStart := sub(a, 0x20) mstore(retStart, 0x20) return(retStart, add(0x40, shl(5, mload(a)))) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* DYNAMIC ARRAY OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // Some of these functions returns the same array for function chaining. // e.g. `a.p("1").p("2")`. /// @dev Shorthand for `a.data.length`. function length(DynamicArray memory a) internal pure returns (uint256) { return a.data.length; } /// @dev Wraps `a` in a dynamic array struct. function wrap(uint256[] memory a) internal pure returns (DynamicArray memory result) { result.data = a; } /// @dev Wraps `a` in a dynamic array struct. function wrap(address[] memory a) internal pure returns (DynamicArray memory result) { /// @solidity memory-safe-assembly assembly { mstore(result, a) } } /// @dev Wraps `a` in a dynamic array struct. function wrap(bool[] memory a) internal pure returns (DynamicArray memory result) { /// @solidity memory-safe-assembly assembly { mstore(result, a) } } /// @dev Wraps `a` in a dynamic array struct. function wrap(bytes32[] memory a) internal pure returns (DynamicArray memory result) { /// @solidity memory-safe-assembly assembly { mstore(result, a) } } /// @dev Clears the array without deallocating the memory. function clear(DynamicArray memory a) internal pure returns (DynamicArray memory result) { _deallocate(result); result = a; /// @solidity memory-safe-assembly assembly { mstore(mload(result), 0) } } /// @dev Clears the array and attempts to free the memory if possible. function free(DynamicArray memory a) internal pure returns (DynamicArray memory result) { _deallocate(result); result = a; /// @solidity memory-safe-assembly assembly { let arrData := mload(result) if iszero(eq(arrData, 0x60)) { let prime := 8188386068317523 let cap := mload(sub(arrData, 0x20)) // Extract `cap`, initializing it to zero if it is not a multiple of `prime`. cap := mul(div(cap, prime), iszero(mod(cap, prime))) // If `cap` is non-zero and the memory is contiguous, we can free it. if lt(iszero(cap), eq(mload(0x40), add(arrData, add(0x20, cap)))) { mstore(0x40, sub(arrData, 0x20)) } mstore(result, 0x60) } } } /// @dev Resizes the array to contain `n` elements. New elements will be zeroized. function resize(DynamicArray memory a, uint256 n) internal pure returns (DynamicArray memory result) { _deallocate(result); result = a; reserve(result, n); /// @solidity memory-safe-assembly assembly { let arrData := mload(result) let arrLen := mload(arrData) if iszero(lt(n, arrLen)) { codecopy(add(arrData, shl(5, add(1, arrLen))), codesize(), shl(5, sub(n, arrLen))) } mstore(arrData, n) } } /// @dev Increases the size of `a` to `n`. /// If `n` is less than the size of `a`, this will be a no-op. /// This method does not zeroize any newly created elements. function expand(DynamicArray memory a, uint256 n) internal pure returns (DynamicArray memory result) { _deallocate(result); result = a; if (n >= a.data.length) { reserve(result, n); /// @solidity memory-safe-assembly assembly { mstore(mload(result), n) } } } /// @dev Reduces the size of `a` to `n`. /// If `n` is greater than the size of `a`, this will be a no-op. function truncate(DynamicArray memory a, uint256 n) internal pure returns (DynamicArray memory result) { _deallocate(result); result = a; /// @solidity memory-safe-assembly assembly { mstore(mul(lt(n, mload(mload(result))), mload(result)), n) } } /// @dev Reserves at least `minimum` amount of contiguous memory. function reserve(DynamicArray memory a, uint256 minimum) internal pure returns (DynamicArray memory result) { _deallocate(result); result = a; /// @solidity memory-safe-assembly assembly { if iszero(lt(minimum, 0xffffffff)) { invalid() } // For extra safety. for { let arrData := mload(a) } 1 {} { // Some random prime number to multiply `cap`, so that // we know that the `cap` is for a dynamic array. // Selected to be larger than any memory pointer realistically. let prime := 8188386068317523 // Special case for `arrData` pointing to zero pointer. if eq(arrData, 0x60) { let newCap := shl(5, add(1, minimum)) let capSlot := mload(0x40) mstore(capSlot, mul(prime, newCap)) // Store the capacity. let newArrData := add(0x20, capSlot) mstore(newArrData, 0) // Store the length. mstore(0x40, add(newArrData, add(0x20, newCap))) // Allocate memory. mstore(a, newArrData) break } let w := not(0x1f) let cap := mload(add(arrData, w)) // `mload(sub(arrData, w))`. // Extract `cap`, initializing it to zero if it is not a multiple of `prime`. cap := mul(div(cap, prime), iszero(mod(cap, prime))) let newCap := shl(5, minimum) // If we don't need to grow the memory. if iszero(and(gt(minimum, mload(arrData)), gt(newCap, cap))) { break } // If the memory is contiguous, we can simply expand it. if eq(mload(0x40), add(arrData, add(0x20, cap))) { mstore(add(arrData, w), mul(prime, newCap)) // Store the capacity. mstore(0x40, add(arrData, add(0x20, newCap))) // Expand the memory allocation. break } let capSlot := mload(0x40) let newArrData := add(capSlot, 0x20) mstore(0x40, add(newArrData, add(0x20, newCap))) // Reallocate the memory. mstore(a, newArrData) // Store the `newArrData`. // Copy `arrData` one word at a time, backwards. for { let o := add(0x20, shl(5, mload(arrData))) } 1 {} { mstore(add(newArrData, o), mload(add(arrData, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } mstore(capSlot, mul(prime, newCap)) // Store the capacity. mstore(newArrData, mload(arrData)) // Store the length. break } } } /// @dev Appends `data` to `a`. function p(DynamicArray memory a, uint256 data) internal pure returns (DynamicArray memory result) { _deallocate(result); result = a; /// @solidity memory-safe-assembly assembly { let arrData := mload(a) let newArrLen := add(mload(arrData), 1) let newArrBytesLen := shl(5, newArrLen) // Some random prime number to multiply `cap`, so that // we know that the `cap` is for a dynamic array. // Selected to be larger than any memory pointer realistically. let prime := 8188386068317523 let cap := mload(sub(arrData, 0x20)) // Extract `cap`, initializing it to zero if it is not a multiple of `prime`. cap := mul(div(cap, prime), iszero(mod(cap, prime))) // Expand / Reallocate memory if required. // Note that we need to allocate an extra word for the length. for {} iszero(lt(newArrBytesLen, cap)) {} { // Approximately more than double the capacity to ensure more than enough space. let newCap := add(cap, or(cap, newArrBytesLen)) // If the memory is contiguous, we can simply expand it. if iszero(or(xor(mload(0x40), add(arrData, add(0x20, cap))), eq(arrData, 0x60))) { mstore(sub(arrData, 0x20), mul(prime, newCap)) // Store the capacity. mstore(0x40, add(arrData, add(0x20, newCap))) // Expand the memory allocation. break } // Set the `newArrData` to point to the word after `cap`. let newArrData := add(mload(0x40), 0x20) mstore(0x40, add(newArrData, add(0x20, newCap))) // Reallocate the memory. mstore(a, newArrData) // Store the `newArrData`. let w := not(0x1f) // Copy `arrData` one word at a time, backwards. for { let o := newArrBytesLen } 1 {} { mstore(add(newArrData, o), mload(add(arrData, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } mstore(add(newArrData, w), mul(prime, newCap)) // Store the memory. arrData := newArrData // Assign `newArrData` to `arrData`. break } mstore(add(arrData, newArrBytesLen), data) // Append `data`. mstore(arrData, newArrLen) // Store the length. } } /// @dev Appends `data` to `a`. function p(DynamicArray memory a, address data) internal pure returns (DynamicArray memory result) { _deallocate(result); result = p(a, uint256(uint160(data))); } /// @dev Appends `data` to `a`. function p(DynamicArray memory a, bool data) internal pure returns (DynamicArray memory result) { _deallocate(result); result = p(a, _toUint(data)); } /// @dev Appends `data` to `a`. function p(DynamicArray memory a, bytes32 data) internal pure returns (DynamicArray memory result) { _deallocate(result); result = p(a, uint256(data)); } /// @dev Shorthand for returning an empty array. function p() internal pure returns (DynamicArray memory result) {} /// @dev Shorthand for `p(p(), data)`. function p(uint256 data) internal pure returns (DynamicArray memory result) { p(result, uint256(data)); } /// @dev Shorthand for `p(p(), data)`. function p(address data) internal pure returns (DynamicArray memory result) { p(result, uint256(uint160(data))); } /// @dev Shorthand for `p(p(), data)`. function p(bool data) internal pure returns (DynamicArray memory result) { p(result, _toUint(data)); } /// @dev Shorthand for `p(p(), data)`. function p(bytes32 data) internal pure returns (DynamicArray memory result) { p(result, uint256(data)); } /// @dev Removes and returns the last element of `a`. /// Returns 0 and does not pop anything if the array is empty. function pop(DynamicArray memory a) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { let o := mload(a) let n := mload(o) result := mload(add(o, shl(5, n))) mstore(o, sub(n, iszero(iszero(n)))) } } /// @dev Removes and returns the last element of `a`. /// Returns 0 and does not pop anything if the array is empty. function popUint256(DynamicArray memory a) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { let o := mload(a) let n := mload(o) result := mload(add(o, shl(5, n))) mstore(o, sub(n, iszero(iszero(n)))) } } /// @dev Removes and returns the last element of `a`. /// Returns 0 and does not pop anything if the array is empty. function popAddress(DynamicArray memory a) internal pure returns (address result) { /// @solidity memory-safe-assembly assembly { let o := mload(a) let n := mload(o) result := mload(add(o, shl(5, n))) mstore(o, sub(n, iszero(iszero(n)))) } } /// @dev Removes and returns the last element of `a`. /// Returns 0 and does not pop anything if the array is empty. function popBool(DynamicArray memory a) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let o := mload(a) let n := mload(o) result := mload(add(o, shl(5, n))) mstore(o, sub(n, iszero(iszero(n)))) } } /// @dev Removes and returns the last element of `a`. /// Returns 0 and does not pop anything if the array is empty. function popBytes32(DynamicArray memory a) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { let o := mload(a) let n := mload(o) result := mload(add(o, shl(5, n))) mstore(o, sub(n, iszero(iszero(n)))) } } /// @dev Returns the element at `a.data[i]`, without bounds checking. function get(DynamicArray memory a, uint256 i) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := mload(add(add(mload(a), 0x20), shl(5, i))) } } /// @dev Returns the element at `a.data[i]`, without bounds checking. function getUint256(DynamicArray memory a, uint256 i) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := mload(add(add(mload(a), 0x20), shl(5, i))) } } /// @dev Returns the element at `a.data[i]`, without bounds checking. function getAddress(DynamicArray memory a, uint256 i) internal pure returns (address result) { /// @solidity memory-safe-assembly assembly { result := mload(add(add(mload(a), 0x20), shl(5, i))) } } /// @dev Returns the element at `a.data[i]`, without bounds checking. function getBool(DynamicArray memory a, uint256 i) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { result := mload(add(add(mload(a), 0x20), shl(5, i))) } } /// @dev Returns the element at `a.data[i]`, without bounds checking. function getBytes32(DynamicArray memory a, uint256 i) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { result := mload(add(add(mload(a), 0x20), shl(5, i))) } } /// @dev Sets `a.data[i]` to `data`, without bounds checking. function set(DynamicArray memory a, uint256 i, uint256 data) internal pure returns (DynamicArray memory result) { _deallocate(result); result = a; /// @solidity memory-safe-assembly assembly { mstore(add(add(mload(result), 0x20), shl(5, i)), data) } } /// @dev Sets `a.data[i]` to `data`, without bounds checking. function set(DynamicArray memory a, uint256 i, address data) internal pure returns (DynamicArray memory result) { _deallocate(result); result = a; /// @solidity memory-safe-assembly assembly { mstore(add(add(mload(result), 0x20), shl(5, i)), shr(96, shl(96, data))) } } /// @dev Sets `a.data[i]` to `data`, without bounds checking. function set(DynamicArray memory a, uint256 i, bool data) internal pure returns (DynamicArray memory result) { _deallocate(result); result = a; /// @solidity memory-safe-assembly assembly { mstore(add(add(mload(result), 0x20), shl(5, i)), iszero(iszero(data))) } } /// @dev Sets `a.data[i]` to `data`, without bounds checking. function set(DynamicArray memory a, uint256 i, bytes32 data) internal pure returns (DynamicArray memory result) { _deallocate(result); result = a; /// @solidity memory-safe-assembly assembly { mstore(add(add(mload(result), 0x20), shl(5, i)), data) } } /// @dev Returns the underlying array as a `uint256[]`. function asUint256Array(DynamicArray memory a) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { result := mload(a) } } /// @dev Returns the underlying array as a `address[]`. function asAddressArray(DynamicArray memory a) internal pure returns (address[] memory result) { /// @solidity memory-safe-assembly assembly { result := mload(a) } } /// @dev Returns the underlying array as a `bool[]`. function asBoolArray(DynamicArray memory a) internal pure returns (bool[] memory result) { /// @solidity memory-safe-assembly assembly { result := mload(a) } } /// @dev Returns the underlying array as a `bytes32[]`. function asBytes32Array(DynamicArray memory a) internal pure returns (bytes32[] memory result) { /// @solidity memory-safe-assembly assembly { result := mload(a) } } /// @dev Returns a copy of `a` sliced from `start` to `end` (exclusive). function slice(DynamicArray memory a, uint256 start, uint256 end) internal pure returns (DynamicArray memory result) { result.data = slice(a.data, start, end); } /// @dev Returns a copy of `a` sliced from `start` to the end of the array. function slice(DynamicArray memory a, uint256 start) internal pure returns (DynamicArray memory result) { result.data = slice(a.data, start, type(uint256).max); } /// @dev Returns if `needle` is in `a`. function contains(DynamicArray memory a, uint256 needle) internal pure returns (bool) { return ~indexOf(a.data, needle, 0) != 0; } /// @dev Returns if `needle` is in `a`. function contains(DynamicArray memory a, address needle) internal pure returns (bool) { return ~indexOf(a.data, uint160(needle), 0) != 0; } /// @dev Returns if `needle` is in `a`. function contains(DynamicArray memory a, bytes32 needle) internal pure returns (bool) { return ~indexOf(a.data, uint256(needle), 0) != 0; } /// @dev Returns the first index of `needle`, scanning forward from `from`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function indexOf(DynamicArray memory a, uint256 needle, uint256 from) internal pure returns (uint256) { return indexOf(a.data, needle, from); } /// @dev Returns the first index of `needle`, scanning forward from `from`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function indexOf(DynamicArray memory a, address needle, uint256 from) internal pure returns (uint256) { return indexOf(a.data, uint160(needle), from); } /// @dev Returns the first index of `needle`, scanning forward from `from`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function indexOf(DynamicArray memory a, bytes32 needle, uint256 from) internal pure returns (uint256) { return indexOf(a.data, uint256(needle), from); } /// @dev Returns the first index of `needle`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function indexOf(DynamicArray memory a, uint256 needle) internal pure returns (uint256) { return indexOf(a.data, needle, 0); } /// @dev Returns the first index of `needle`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function indexOf(DynamicArray memory a, address needle) internal pure returns (uint256) { return indexOf(a.data, uint160(needle), 0); } /// @dev Returns the first index of `needle`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function indexOf(DynamicArray memory a, bytes32 needle) internal pure returns (uint256) { return indexOf(a.data, uint256(needle), 0); } /// @dev Returns the last index of `needle`, scanning backwards from `from`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function lastIndexOf(DynamicArray memory a, uint256 needle, uint256 from) internal pure returns (uint256) { return lastIndexOf(a.data, needle, from); } /// @dev Returns the last index of `needle`, scanning backwards from `from`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function lastIndexOf(DynamicArray memory a, address needle, uint256 from) internal pure returns (uint256) { return lastIndexOf(a.data, uint160(needle), from); } /// @dev Returns the last index of `needle`, scanning backwards from `from`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function lastIndexOf(DynamicArray memory a, bytes32 needle, uint256 from) internal pure returns (uint256) { return lastIndexOf(a.data, uint256(needle), from); } /// @dev Returns the last index of `needle`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function lastIndexOf(DynamicArray memory a, uint256 needle) internal pure returns (uint256) { return lastIndexOf(a.data, needle, NOT_FOUND); } /// @dev Returns the last index of `needle`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function lastIndexOf(DynamicArray memory a, address needle) internal pure returns (uint256) { return lastIndexOf(a.data, uint160(needle), NOT_FOUND); } /// @dev Returns the last index of `needle`. /// If `needle` is not in `a`, returns `NOT_FOUND`. function lastIndexOf(DynamicArray memory a, bytes32 needle) internal pure returns (uint256) { return lastIndexOf(a.data, uint256(needle), NOT_FOUND); } /// @dev Equivalent to `keccak256(abi.encodePacked(a.data))`. function hash(DynamicArray memory a) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { result := keccak256(add(mload(a), 0x20), shl(5, mload(mload(a)))) } } /// @dev Directly returns `a` without copying. function directReturn(DynamicArray memory a) internal pure { assembly { let arrData := mload(a) let retStart := sub(arrData, 0x20) mstore(retStart, 0x20) return(retStart, add(0x40, shl(5, mload(arrData)))) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PRIVATE HELPERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Helper for deallocating a automatically allocated array pointer. function _deallocate(DynamicArray memory result) private pure { /// @solidity memory-safe-assembly assembly { mstore(0x40, result) // Deallocate, as we have already allocated. } } /// @dev Casts the bool into a uint256. function _toUint(bool b) private pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := iszero(iszero(b)) } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol"; import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import {IBaseCollateralVault} from "./IBaseCollateralVault.sol"; import {IInfraredWrapper} from "./IInfraredWrapper.sol"; import {IDenManager} from "../IDenManager.sol"; import {IBeraborrowCore} from "../IBeraborrowCore.sol"; import {IInfraredVault} from "../../utils/integrations/IInfraredVault.sol"; import {EmissionsLib} from "src/libraries/EmissionsLib.sol"; interface IInfraredCollateralVault is IBaseCollateralVault { struct InfraredCollVaultStorage { uint16 minPerformanceFee; uint16 maxPerformanceFee; uint16 performanceFee; // over yield, in basis points address iRedToken; /// @dev We currently don't know the infraredVault implementation, but if it were to be possible for them to remove tokens from the rewardTokens /// There would be no need to remove it from here since the amounts should continue being accounted for in the virtual balance EnumerableSet.AddressSet rewardedTokens; IInfraredVault _infraredVault; address ibgtVault; address ibgt; IInfraredWrapper infraredWrapper; uint96 lastUpdate; mapping(address tokenIn => uint) threshold; } struct InfraredInitParams { BaseInitParams _baseParams; uint16 _minPerformanceFee; uint16 _maxPerformanceFee; uint16 _performanceFee; // over yield, in basis points address _iRedToken; IInfraredVault _infraredVault; address _ibgtVault; address _infraredWrapper; } struct RebalanceParams { address sentCurrency; uint sentAmount; address swapper; bytes payload; } function rebalance(RebalanceParams calldata p) external; function setUnlockRatePerSecond(address token, uint64 _unlockRatePerSecond) external; function internalizeDonations(address[] memory tokens, uint128[] memory amounts) external; function setPairThreshold(address tokenIn, uint thresholdInBP) external; function setPerformanceFee(uint16 _performanceFee) external; function setWithdrawFee(uint16 _withdrawFee) external; function getBalance(address token) external view returns (uint); function getBalanceOfWithFutureEmissions(address token) external view returns (uint); function getFullProfitUnlockTimestamp(address token) external view returns (uint); function unlockRatePerSecond(address token) external view returns (uint); function getLockedEmissions(address token) external view returns (uint); function getPerformanceFee() external view returns (uint16); function rewardedTokens() external view returns (address[] memory); function iRedToken() external view returns (address); function infraredVault() external view returns (IInfraredVault); function ibgt() external view returns (address); function ibgtVault() external view returns (address); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; interface IMetaBeraborrowCore { // --------------------------------- // Structures // --------------------------------- struct FeeInfo { bool existsForNect; uint16 nectFee; } struct RebalancerFeeInfo { bool exists; uint16 entryFee; uint16 exitFee; } // --------------------------------- // Public constants // --------------------------------- function OWNERSHIP_TRANSFER_DELAY() external view returns (uint256); function DEFAULT_FLASH_LOAN_FEE() external view returns (uint16); // --------------------------------- // Public state variables // --------------------------------- function nect() external view returns (address); function lspEntryFee() external view returns (uint16); function lspExitFee() external view returns (uint16); function feeReceiver() external view returns (address); function priceFeed() external view returns (address); function owner() external view returns (address); function pendingOwner() external view returns (address); function ownershipTransferDeadline() external view returns (uint256); function manager() external view returns (address); function guardian() external view returns (address); function paused() external view returns (bool); function lspBootstrapPeriod() external view returns (uint64); // --------------------------------- // External functions // --------------------------------- function setFeeReceiver(address _feeReceiver) external; function setPriceFeed(address _priceFeed) external; function setGuardian(address _guardian) external; function setManager(address _manager) external; /** * @notice Global pause/unpause * Pausing halts new deposits/borrowing across the protocol */ function setPaused(bool _paused) external; /** * @notice Extend or change the LSP bootstrap period, * after which certain protocol mechanics change */ function setLspBootstrapPeriod(uint64 _bootstrapPeriod) external; /** * @notice Set a custom flash-loan fee for a given periphery contract * @param _periphery Target contract that will get this custom fee * @param _nectFee Fee in basis points (bp) * @param _existsForNect Whether this custom fee is used when the caller = `nect` */ function setPeripheryFlashLoanFee(address _periphery, uint16 _nectFee, bool _existsForNect) external; /** * @notice Begin the ownership transfer process * @param newOwner The address proposed to be the new owner */ function commitTransferOwnership(address newOwner) external; /** * @notice Finish the ownership transfer, after the mandatory delay */ function acceptTransferOwnership() external; /** * @notice Revoke a pending ownership transfer */ function revokeTransferOwnership() external; /** * @notice Look up a custom flash-loan fee for a specific periphery contract * @param peripheryContract The contract that might have a custom fee * @return The flash-loan fee in basis points */ function getPeripheryFlashLoanFee(address peripheryContract) external view returns (uint16); /** * @notice Set / override entry & exit fees for a special rebalancer contract */ function setRebalancerFee(address _rebalancer, uint16 _entryFee, uint16 _exitFee) external; /** * @notice Set the LSP entry fee globally * @param _fee Fee in basis points */ function setEntryFee(uint16 _fee) external; /** * @notice Set the LSP exit fee globally * @param _fee Fee in basis points */ function setExitFee(uint16 _fee) external; /** * @notice Look up the LSP entry fee for a rebalancer * @param rebalancer Possibly has a special fee * @return The entry fee in basis points */ function getLspEntryFee(address rebalancer) external view returns (uint16); /** * @notice Look up the LSP exit fee for a rebalancer * @param rebalancer Possibly has a special fee * @return The exit fee in basis points */ function getLspExitFee(address rebalancer) external view returns (uint16); // --------------------------------- // Events // --------------------------------- event NewOwnerCommitted(address indexed owner, address indexed pendingOwner, uint256 deadline); event NewOwnerAccepted(address indexed oldOwner, address indexed newOwner); event NewOwnerRevoked(address indexed owner, address indexed revokedOwner); event FeeReceiverSet(address indexed feeReceiver); event PriceFeedSet(address indexed priceFeed); event GuardianSet(address indexed guardian); event ManagerSet(address indexed manager); event PeripheryFlashLoanFee(address indexed periphery, uint16 nectFee); event LSPBootstrapPeriodSet(uint64 bootstrapPeriod); event RebalancerFees(address indexed rebalancer, uint16 entryFee, uint16 exitFee); event EntryFeeSet(uint16 fee); event ExitFeeSet(uint16 fee); event Paused(); event Unpaused(); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (interfaces/IERC3156FlashBorrower.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC3156 FlashBorrower, as defined in * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156]. * * _Available since v4.1._ */ interface IERC3156FlashBorrower { /** * @dev Receive a flash loan. * @param initiator The initiator of the loan. * @param token The loan currency. * @param amount The amount of tokens lent. * @param fee The additional amount of tokens to repay. * @param data Arbitrary data structure, intended to contain user-defined parameters. * @return The keccak256 hash of "IERC3156FlashBorrower.onFlashLoan" */ function onFlashLoan( address initiator, address token, uint256 amount, uint256 fee, bytes calldata data ) external returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } 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) (interfaces/draft-IERC6093.sol) pragma solidity ^0.8.20; /** * @dev Standard ERC-20 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens. */ interface IERC20Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC20InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC20InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers. * @param spender Address that may be allowed to operate on tokens without being their owner. * @param allowance Amount of tokens a `spender` is allowed to operate with. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC20InvalidApprover(address approver); /** * @dev Indicates a failure with the `spender` to be approved. Used in approvals. * @param spender Address that may be allowed to operate on tokens without being their owner. */ error ERC20InvalidSpender(address spender); } /** * @dev Standard ERC-721 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens. */ interface IERC721Errors { /** * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20. * Used in balance queries. * @param owner Address of the current owner of a token. */ error ERC721InvalidOwner(address owner); /** * @dev Indicates a `tokenId` whose `owner` is the zero address. * @param tokenId Identifier number of a token. */ error ERC721NonexistentToken(uint256 tokenId); /** * @dev Indicates an error related to the ownership over a particular token. Used in transfers. * @param sender Address whose tokens are being transferred. * @param tokenId Identifier number of a token. * @param owner Address of the current owner of a token. */ error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC721InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC721InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param tokenId Identifier number of a token. */ error ERC721InsufficientApproval(address operator, uint256 tokenId); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC721InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC721InvalidOperator(address operator); } /** * @dev Standard ERC-1155 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens. */ interface IERC1155Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. * @param tokenId Identifier number of a token. */ error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC1155InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC1155InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param owner Address of the current owner of a token. */ error ERC1155MissingApprovalForAll(address operator, address owner); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC1155InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC1155InvalidOperator(address operator); /** * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation. * Used in batch transfers. * @param idsLength Length of the array of token identifiers * @param valuesLength Length of the array of token amounts */ error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @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. */ 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]. */ 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 v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @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, it is bubbled up by this * function (like regular Solidity function calls). * * 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. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @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`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeacon { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1967.sol) pragma solidity ^0.8.20; /** * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC. */ interface IERC1967 { /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Emitted when the beacon is changed. */ event BeaconUpgraded(address indexed beacon); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {IERC4626, IERC20} from "@openzeppelin/contracts/interfaces/IERC4626.sol"; import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol"; import {IDenManager} from "../IDenManager.sol"; import {IMetaBeraborrowCore} from "../IMetaBeraborrowCore.sol"; import {IPriceFeed} from "../IPriceFeed.sol"; import {EmissionsLib} from "src/libraries/EmissionsLib.sol"; interface IBaseCollateralVault is IERC4626, IERC1822Proxiable { struct BaseInitParams { uint16 _minWithdrawFee; uint16 _maxWithdrawFee; uint16 _withdrawFee; IMetaBeraborrowCore _metaBeraborrowCore; // ERC4626 IERC20 _asset; // ERC20 string _sharesName; string _sharesSymbol; } struct BaseCollVaultStorage { uint16 minWithdrawFee; uint16 maxWithdrawFee; uint16 withdrawFee; // over rewarded tokens, in basis points uint8 assetDecimals; IMetaBeraborrowCore _metaBeraborrowCore; // Second mapping of this struct is usless, but it's for retrocompatibility with InfraredCollateralVault EmissionsLib.BalanceData balanceData; } function totalAssets() external view returns (uint); function fetchPrice() external view returns (uint); function getPrice(address token) external view returns (uint); function receiveDonations(address[] memory tokens, uint[] memory amounts, address receiver) external; function setWithdrawFee(uint16 _withdrawFee) external; function getBalance(address token) external view returns (uint); function getWithdrawFee() external view returns (uint16); function getMetaBeraborrowCore() external view returns (IMetaBeraborrowCore); function getPriceFeed() external view returns (IPriceFeed); function assetDecimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol"; interface IInfraredWrapper is IERC20 { function metaBeraborrowCore() external view returns (address); function infraredCollVault() external view returns (address); function decimals() external view returns (uint8); function depositFor(address account, uint256 amount) external returns (bool); function withdrawTo(address account, uint256 amount) external returns (bool); function recover(address account) external returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {IERC3156FlashBorrower} from "@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IFactory} from "./IFactory.sol"; interface IDenManager { event BaseRateUpdated(uint256 _baseRate); event CollateralSent(address _to, uint256 _amount); event LTermsUpdated(uint256 _L_collateral, uint256 _L_debt); event LastFeeOpTimeUpdated(uint256 _lastFeeOpTime); event Redemption( address indexed _redeemer, uint256 _attemptedDebtAmount, uint256 _actualDebtAmount, uint256 _collateralSent, uint256 _collateralFee ); event SystemSnapshotsUpdated(uint256 _totalStakesSnapshot, uint256 _totalCollateralSnapshot); event TotalStakesUpdated(uint256 _newTotalStakes); event DenIndexUpdated(address _borrower, uint256 _newIndex); event DenSnapshotsUpdated(uint256 _L_collateral, uint256 _L_debt); event DenUpdated(address indexed _borrower, uint256 _debt, uint256 _coll, uint256 _stake, uint8 _operation); function addCollateralSurplus(address borrower, uint256 collSurplus) external; function applyPendingRewards(address _borrower) external returns (uint256 coll, uint256 debt); function claimCollateral(address borrower, address _receiver) external; function closeDen(address _borrower, address _receiver, uint256 collAmount, uint256 debtAmount) external; function closeDenByLiquidation(address _borrower) external; function setCollVaultRouter(address _collVaultRouter) external; function collectInterests() external; function decayBaseRateAndGetBorrowingFee(uint256 _debt) external returns (uint256); function decreaseDebtAndSendCollateral(address account, uint256 debt, uint256 coll) external; function fetchPrice() external view returns (uint256); function finalizeLiquidation( address _liquidator, uint256 _debt, uint256 _coll, uint256 _collSurplus, uint256 _debtGasComp, uint256 _collGasComp ) external; function getEntireSystemBalances() external view returns (uint256, uint256, uint256); function movePendingDenRewardsToActiveBalances(uint256 _debt, uint256 _collateral) external; function openDen( address _borrower, uint256 _collateralAmount, uint256 _compositeDebt, uint256 NICR, address _upperHint, address _lowerHint ) external returns (uint256 stake, uint256 arrayIndex); function redeemCollateral( uint256 _debtAmount, address _firstRedemptionHint, address _upperPartialRedemptionHint, address _lowerPartialRedemptionHint, uint256 _partialRedemptionHintNICR, uint256 _maxIterations, uint256 _maxFeePercentage ) external; function setAddresses(address _priceFeedAddress, address _sortedDensAddress, address _collateralToken) external; function setParameters( IFactory.DeploymentParams calldata _params ) external; function setPaused(bool _paused) external; function setPriceFeed(address _priceFeedAddress) external; function startSunset() external; function updateBalances() external; function updateDenFromAdjustment( bool _isDebtIncrease, uint256 _debtChange, uint256 _netDebtChange, bool _isCollIncrease, uint256 _collChange, address _upperHint, address _lowerHint, address _borrower, address _receiver ) external returns (uint256, uint256, uint256); function DEBT_GAS_COMPENSATION() external view returns (uint256); function DECIMAL_PRECISION() external view returns (uint256); function L_collateral() external view returns (uint256); function L_debt() external view returns (uint256); function MCR() external view returns (uint256); function PERCENT_DIVISOR() external view returns (uint256); function BERABORROW_CORE() external view returns (address); function SUNSETTING_INTEREST_RATE() external view returns (uint256); function Dens( address ) external view returns ( uint256 debt, uint256 coll, uint256 stake, uint8 status, uint128 arrayIndex, uint256 activeInterestIndex ); function activeInterestIndex() external view returns (uint256); function baseRate() external view returns (uint256); function borrowerOperations() external view returns (address); function borrowingFeeFloor() external view returns (uint256); function collateralToken() external view returns (address); function debtToken() external view returns (address); function defaultedCollateral() external view returns (uint256); function defaultedDebt() external view returns (uint256); function getBorrowingFee(uint256 _debt) external view returns (uint256); function getBorrowingFeeWithDecay(uint256 _debt) external view returns (uint256); function getBorrowingRate() external view returns (uint256); function getBorrowingRateWithDecay() external view returns (uint256); function getCurrentICR(address _borrower, uint256 _price) external view returns (uint256); function getEntireDebtAndColl( address _borrower ) external view returns (uint256 debt, uint256 coll, uint256 pendingDebtReward, uint256 pendingCollateralReward); function getEntireSystemColl() external view returns (uint256); function getEntireSystemDebt() external view returns (uint256); function getNominalICR(address _borrower) external view returns (uint256); function getPendingCollAndDebtRewards(address _borrower) external view returns (uint256, uint256); function getRedemptionFeeWithDecay(uint256 _collateralDrawn) external view returns (uint256); function getRedemptionRate() external view returns (uint256); function getRedemptionRateWithDecay() external view returns (uint256); function getTotalActiveCollateral() external view returns (uint256); function getTotalActiveDebt() external view returns (uint256); function getDenCollAndDebt(address _borrower) external view returns (uint256 coll, uint256 debt); function getDenFromDenOwnersArray(uint256 _index) external view returns (address); function getDenOwnersCount() external view returns (uint256); function getDenStake(address _borrower) external view returns (uint256); function getDenStatus(address _borrower) external view returns (uint256); function guardian() external view returns (address); function hasPendingRewards(address _borrower) external view returns (bool); function interestPayable() external view returns (uint256); function interestRate() external view returns (uint256); function lastActiveIndexUpdate() external view returns (uint256); function lastCollateralError_Redistribution() external view returns (uint256); function lastDebtError_Redistribution() external view returns (uint256); function lastFeeOperationTime() external view returns (uint256); function liquidationManager() external view returns (address); function maxBorrowingFee() external view returns (uint256); function maxRedemptionFee() external view returns (uint256); function maxSystemDebt() external view returns (uint256); function minuteDecayFactor() external view returns (uint256); function owner() external view returns (address); function paused() external view returns (bool); function priceFeed() external view returns (address); function redemptionFeeFloor() external view returns (uint256); function rewardSnapshots(address) external view returns (uint256 collateral, uint256 debt); function sortedDens() external view returns (address); function sunsetting() external view returns (bool); function surplusBalances(address) external view returns (uint256); function systemDeploymentTime() external view returns (uint256); function totalCollateralSnapshot() external view returns (uint256); function totalStakes() external view returns (uint256); function totalStakesSnapshot() external view returns (uint256); function brimeDen() external view returns (address); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; interface IInfraredVault { function stakingToken() external view returns (address); function stake(uint256 amount) external; function withdraw(uint256 amount) external; function getReward() external; function getRewardForUser(address account) external; function rewardTokens(uint) external view returns (address); function getAllRewardTokens() external view returns (address[] memory); function earned(address account, address _rewardsToken) external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.26; interface IFactory { // commented values are suggested default parameters struct DeploymentParams { uint256 minuteDecayFactor; // 999037758833783000 (half life of 12 hours) uint256 redemptionFeeFloor; // 1e18 / 1000 * 5 (0.5%) uint256 maxRedemptionFee; // 1e18 (100%) uint256 borrowingFeeFloor; // 1e18 / 1000 * 5 (0.5%) uint256 maxBorrowingFee; // 1e18 / 100 * 5 (5%) uint256 interestRateInBps; // 100 (1%) uint256 maxDebt; uint256 MCR; // 12 * 1e17 (120%) address collVaultRouter; // set to address(0) if DenManager coll is not CollateralVault } event NewDeployment(address collateral, address priceFeed, address denManager, address sortedDens); function deployNewInstance( address collateral, address priceFeed, address customDenManagerImpl, address customSortedDensImpl, DeploymentParams calldata params, uint64 unlockRatePerSecond, bool forceThroughLspBalanceCheck ) external; function setImplementations(address _denManagerImpl, address _sortedDensImpl) external; function BERABORROW_CORE() external view returns (address); function borrowerOperations() external view returns (address); function debtToken() external view returns (address); function guardian() external view returns (address); function liquidationManager() external view returns (address); function owner() external view returns (address); function sortedDensImpl() external view returns (address); function liquidStabilityPool() external view returns (address); function denManagerCount() external view returns (uint256); function denManagerImpl() external view returns (address); function denManagers(uint256) external view returns (address); }
{ "remappings": [ "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "@openzeppelin-upgradeable/contracts/=lib/openzeppelin-contracts-upgradeable/contracts/", "solady/=lib/solady/src/", "@chimera/=lib/chimera/src/", "forge-std/=lib/forge-std/src/", "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/", "chimera/=lib/chimera/src/", "ds-test/=lib/chimera/lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/", "halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/", "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/", "openzeppelin-contracts/=lib/openzeppelin-contracts/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "cancun", "viaIR": false, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AddressZero","type":"error"},{"inputs":[],"name":"AmountCannotBeZero","type":"error"},{"inputs":[],"name":"BalanceRemaining","type":"error"},{"inputs":[],"name":"BelowThreshold","type":"error"},{"inputs":[],"name":"BootstrapPeriod","type":"error"},{"inputs":[],"name":"CallerNotFactory","type":"error"},{"inputs":[],"name":"CallerNotLM","type":"error"},{"inputs":[],"name":"CollateralIsSunsetting","type":"error"},{"inputs":[],"name":"CollateralMustBeSunset","type":"error"},{"inputs":[],"name":"DuplicateToken","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxDeposit","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxMint","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxRedeem","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxWithdraw","type":"error"},{"inputs":[],"name":"EmissionRateExceedsMax","type":"error"},{"inputs":[],"name":"ExistingCollateral","type":"error"},{"inputs":[],"name":"FactoryAlreadyRegistered","type":"error"},{"inputs":[],"name":"FactoryNotRegistered","type":"error"},{"inputs":[],"name":"InvalidArrayLength","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"InvalidThreshold","type":"error"},{"inputs":[],"name":"InvalidToken","type":"error"},{"inputs":[],"name":"LMAlreadyRegistered","type":"error"},{"inputs":[],"name":"LMNotRegistered","type":"error"},{"inputs":[],"name":"LastTokenMustBeNect","type":"error"},{"inputs":[],"name":"NoPriceFeed","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"OnlyOwner","type":"error"},{"inputs":[],"name":"Paused","type":"error"},{"inputs":[],"name":"SameTokens","type":"error"},{"inputs":[],"name":"TokenCannotBeExtraAsset","type":"error"},{"inputs":[],"name":"TokenCannotBeNect","type":"error"},{"inputs":[],"name":"TokenIsVesting","type":"error"},{"inputs":[],"name":"TokenMustBeExtraAsset","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"inputs":[],"name":"WithdrawingLockedEmissions","type":"error"},{"inputs":[],"name":"ZeroTotalSupply","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"address[]","name":"tokens","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"AssetsWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldCollateral","type":"address"},{"indexed":false,"internalType":"address","name":"newCollateral","type":"address"}],"name":"CollateralOverwritten","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"}],"name":"EmissionsAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"}],"name":"EmissionsSub","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"}],"name":"ExtraAssetAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"}],"name":"ExtraAssetRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint64","name":"unlockRatePerSecond","type":"uint64"}],"name":"NewUnlockRatePerSecond","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"collateral","type":"address"},{"indexed":false,"internalType":"uint256","name":"debtToOffset","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collToAdd","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collSurplusAmount","type":"uint256"}],"name":"Offset","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"factoryRemoved","type":"address"},{"indexed":true,"internalType":"address","name":"LMremoved","type":"address"}],"name":"ProtocolBlacklisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"factory","type":"address"},{"indexed":true,"internalType":"address","name":"liquidationManager","type":"address"}],"name":"ProtocolRegistered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sentCurrency","type":"address"},{"indexed":true,"internalType":"address","name":"receivedCurrency","type":"address"},{"indexed":false,"internalType":"uint256","name":"sentAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"receivedAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sentValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"receivedValue","type":"uint256"}],"name":"Rebalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"SUNSET_DURATION","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint64","name":"_unlockRatePerSecond","type":"uint64"}],"name":"addNewExtraAsset","outputs":[],"stateMutability":"nonpayable","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":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_collateral","type":"address"},{"internalType":"uint64","name":"_unlockRatePerSecond","type":"uint64"},{"internalType":"bool","name":"forceThroughBalanceCheck","type":"bool"}],"name":"enableCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"slots","type":"bytes32[]"}],"name":"extSloads","outputs":[{"internalType":"bytes32[]","name":"res","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCollateralTokens","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getLockedEmissions","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getPrice","outputs":[{"internalType":"uint256","name":"scaledPriceInUsdWad","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalDebtTokenDeposits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20","name":"_asset","type":"address"},{"internalType":"string","name":"_sharesName","type":"string"},{"internalType":"string","name":"_sharesSymbol","type":"string"},{"internalType":"contract IMetaBeraborrowCore","name":"_metaBeraborrowCore","type":"address"},{"internalType":"address","name":"_liquidationManager","type":"address"},{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_feeReceiver","type":"address"}],"internalType":"struct ILiquidStabilityPool.InitParams","name":"params","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"int256","name":"amount","type":"int256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"linearVestingExtraAssets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"_debtToOffset","type":"uint256"},{"internalType":"uint256","name":"_collToAdd","type":"uint256"}],"name":"offset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"netShares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"sentCurrency","type":"address"},{"internalType":"uint256","name":"sentAmount","type":"uint256"},{"internalType":"address","name":"receivedCurrency","type":"address"},{"internalType":"address","name":"swapper","type":"address"},{"internalType":"bytes","name":"payload","type":"bytes"}],"internalType":"struct ILiquidStabilityPool.RebalanceParams","name":"p","type":"tuple"}],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address[]","name":"preferredUnderlyingTokens","type":"address[]"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"removeExtraAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_boycoVaults","type":"address[]"},{"internalType":"bool[]","name":"enable","type":"bool[]"}],"name":"setBoycoVaults","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"thresholdInBP","type":"uint256"}],"name":"setPairThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint64","name":"_unlockRatePerSecond","type":"uint64"}],"name":"setUnlockRatePerSecond","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"collateral","type":"address"}],"name":"startCollateralSunset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"amountInNect","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_liquidationManager","type":"address"},{"internalType":"address","name":"_factory","type":"address"},{"internalType":"bool","name":"_register","type":"bool"}],"name":"updateProtocol","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address[]","name":"preferredUnderlyingTokens","type":"address[]"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60a060405230608052348015610013575f80fd5b5061001c610021565b6100d3565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff16156100715760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b03908116146100d05780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b608051615e136100f95f395f81816135f701528181613620015261375f0152615e135ff3fe60806040526004361061028b575f3560e01c80637b8b8b7411610155578063badd8b2d116100be578063dd62ed3e11610078578063dd62ed3e146107ba578063ddda679b146107d9578063e6666733146107f8578063ef8b30f714610817578063fcb9990514610836578063fd69414414610855575f80fd5b8063badd8b2d1461071f578063c5e6a7671461073e578063c63d75b614610448578063c6e6f5921461075d578063ce96cb771461077c578063d905777e1461079b575f80fd5b8063a9059cbb1161010f578063a9059cbb14610652578063ad3cb1cc14610671578063b3d7f6b9146106a1578063b460af94146106c0578063b58eb63f146106df578063ba08765214610700575f80fd5b80637b8b8b74146105945780637d4601c0146105b35780637facd79b146105d257806394bf804d146105f157806395d89b4114610610578063a7528a0314610624575f80fd5b806338d52e0f116101f757806352d1902d116101b157806352d1902d146104d8578063602ecae5146104ec5780636cd611be1461050b5780636e553f651461052a57806370a08231146105495780637784c68514610568575f80fd5b806338d52e0f1461041c578063402d267d14610448578063403dd3bc1461046857806341976e09146104875780634cdad506146104a65780634f1ef286146104c5575f80fd5b80630d9a6b35116102485780630d9a6b351461036557806318160ddd1461037957806319f27b3b1461039957806323b872dd146103b8578063313ce567146103d757806331e95162146103fd575f80fd5b806301e1d1141461028f57806306fdde03146102b657806307a2d13a146102d7578063095ea7b3146102f65780630a28a477146103255780630b983a7414610344575b5f80fd5b34801561029a575f80fd5b506102a3610874565b6040519081526020015b60405180910390f35b3480156102c1575f80fd5b506102ca610a36565b6040516102ad919061524d565b3480156102e2575f80fd5b506102a36102f1366004615282565b610af6565b348015610301575f80fd5b506103156103103660046152ad565b610b07565b60405190151581526020016102ad565b348015610330575f80fd5b506102a361033f366004615282565b610b1e565b34801561034f575f80fd5b5061036361035e3660046152eb565b610b58565b005b348015610370575f80fd5b506102a3610b7e565b348015610384575f80fd5b505f80516020615d77833981519152546102a3565b3480156103a4575f80fd5b506103636103b3366004615322565b610bb8565b3480156103c3575f80fd5b506103156103d236600461533d565b610cec565b3480156103e2575f80fd5b506103eb610d11565b60405160ff90911681526020016102ad565b348015610408575f80fd5b506102a36104173660046153c2565b610d53565b348015610427575f80fd5b50610430610e52565b6040516001600160a01b0390911681526020016102ad565b348015610453575f80fd5b506102a3610462366004615322565b505f1990565b348015610473575f80fd5b506102a3610482366004615322565b610e80565b348015610492575f80fd5b506102a36104a1366004615322565b610efa565b3480156104b1575f80fd5b506102a36104c0366004615282565b610fda565b6103636104d3366004615444565b610ffd565b3480156104e3575f80fd5b506102a361101c565b3480156104f7575f80fd5b50610363610506366004615514565b611037565b348015610516575f80fd5b50610363610525366004615322565b6112c9565b348015610535575f80fd5b506102a361054436600461555c565b611404565b348015610554575f80fd5b506102a3610563366004615322565b6114cc565b348015610573575f80fd5b5061058761058236600461557f565b6114f2565b6040516102ad91906155bd565b34801561059f575f80fd5b506103636105ae3660046155ff565b611581565b3480156105be575f80fd5b506103636105cd36600461562c565b6116c6565b3480156105dd575f80fd5b506103636105ec366004615696565b6117ad565b3480156105fc575f80fd5b506102a361060b36600461555c565b611e4b565b34801561061b575f80fd5b506102ca611f2b565b34801561062f575f80fd5b5061063a62093a8081565b6040516001600160801b0390911681526020016102ad565b34801561065d575f80fd5b5061031561066c3660046152ad565b611f69565b34801561067c575f80fd5b506102ca604051806040016040528060058152602001640352e302e360dc1b81525081565b3480156106ac575f80fd5b506102a36106bb366004615282565b611f76565b3480156106cb575f80fd5b506102a36106da3660046156cc565b611fa7565b3480156106ea575f80fd5b506106f3612048565b6040516102ad9190615743565b34801561070b575f80fd5b506102a361071a3660046156cc565b6120b1565b34801561072a575f80fd5b5061036361073936600461533d565b612146565b348015610749575f80fd5b50610363610758366004615755565b6121d7565b348015610768575f80fd5b506102a3610777366004615282565b6122c3565b348015610787575f80fd5b506102a3610796366004615322565b6122ce565b3480156107a6575f80fd5b506102a36107b5366004615322565b6122db565b3480156107c5575f80fd5b506102a36107d4366004615789565b6122e5565b3480156107e4575f80fd5b506102a36107f33660046153c2565b61232e565b348015610803575f80fd5b506103636108123660046157b5565b612415565b348015610822575f80fd5b506102a3610831366004615282565b6125f0565b348015610841575f80fd5b506103636108503660046152eb565b61260b565b348015610860575f80fd5b5061036361086f3660046157e7565b612834565b5f8061087e612bed565b90505f8061088a612048565b90505f6108986104a1610e52565b82519091505f6108aa60028701612c11565b90505f60098701816108ba610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f205490505f5b838110156109ad575f8682815181106108f9576108f961581d565b602002602001015190505f61091a828b600901612c1a90919063ffffffff16565b905080156109a35761099661092e83610efa565b836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561096a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061098e9190615831565b839190612ca6565b6109a0908a615865565b98505b50506001016108de565b505f5b82811015610a01575f6109c660028a0183612cc6565b90505f6109d660098b0183612c1a565b905080156109f7576109ea61092e83610efa565b6109f4908a615865565b98505b50506001016109b0565b508084610a16670de0b6b3a764000089615878565b610a2091906158a3565b610a2a9190615865565b97505050505050505090565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0380546060915f80516020615d5783398151915291610a74906158c2565b80601f0160208091040260200160405190810160405280929190818152602001828054610aa0906158c2565b8015610aeb5780601f10610ac257610100808354040283529160200191610aeb565b820191905f5260205f20905b815481529060010190602001808311610ace57829003601f168201915b505050505091505090565b5f610b01825f612cd1565b92915050565b5f33610b14818585612d15565b5060019392505050565b5f80610b2983612d22565b90505f610b50612710610b3a612d2e565b610b46906127106158fa565b8491906001612dad565b949350505050565b610b60612e08565b5f610b69612bed565b9050610b79600982018484612ead565b505050565b5f610b87612bed565b6009015f610b93610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f2054905090565b610bc0612e08565b5f610bc9612bed565b6001600160a01b0383165f90815260078201602052604081205491925003610c0457604051630b3cfa8f60e01b815260040160405180910390fd5b6040805180820182526001600160a01b0384165f9081526007840160205291909120548190610c35906001906158fa565b6001600160801b03168152602001610c5062093a8042615865565b6001600160801b0316905260048201805460068401915f9162010000900461ffff16906002610c7e8361590d565b825461ffff9182166101009390930a92830292820219169190911790915516815260208082019290925260409081015f9081208451948401516001600160801b03908116600160801b029516949094179093556001600160a01b039094168252600790920190915290812055565b5f33610cf9858285612f5e565b610d04858585612fa8565b60019150505b9392505050565b5f807f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e0090505f8154610d4d9190600160a01b900460ff1661592d565b91505090565b5f610d5c613005565b5f610d65612bed565b90505f610d71846122db565b905080881115610da357838882604051632e52afbb60e21b8152600401610d9a93929190615946565b60405180910390fd5b610dac88610fda565b9250610dba82895f876130c5565b5050610dfb82848989808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152508b9250613176915050565b60408051848152602081018a90526001600160a01b03808716929088169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db91015b60405180910390a4505095945050505050565b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00546001600160a01b031690565b5f80610e8a612bed565b6001600160a01b0384165f908152600a90910160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b9004909216908201529150610eee82613524565b9050610b508282613555565b5f80610f04612bed565b5460408051633a0df78d60e11b815290516001600160a01b039092169163741bef1a916004808201926020929091908290030181865afa158015610f4a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f6e9190615967565b604051635670bcc760e11b81526001600160a01b0385811660048301529192509082169063ace1798e90602401602060405180830381865afa158015610fb6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d0a9190615982565b5f80610fee610fe7612d2e565b84906135dc565b9050610d0a6102f182856158fa565b6110056135ec565b61100e82613690565b6110188282613698565b5050565b5f611025613754565b505f80516020615d9783398151915290565b5f611040612bed565b905061104a610e52565b6001600160a01b0316846001600160a01b03160361107b5760405163338665cd60e01b815260040160405180910390fd5b335f908152600b8201602052604090205460ff166110ac5760405163a84178ab60e01b815260040160405180910390fd5b6110b9600282018561379d565b156110d757604051631cf57a9f60e11b815260040160405180910390fd5b60058101545f6110eb600984018787612ead565b5f5b8281101561113e57866001600160a01b03168460050182815481106111145761111461581d565b5f918252602090912001546001600160a01b031603611136576001915061113e565b6001016110ed565b508061126e5760408051808201909152600484015461ffff808216808452620100009092041660208301819052111561122357805161ffff165f9081526006850160209081526040918290208251808401909352546001600160801b038082168452600160801b909104169082018190524211156112215760048501805460068701915f9161ffff1690826111d28361590d565b82546101009290920a61ffff81810219909316918316021790915516815260208101919091526040015f9081205580516112179089906001600160801b0316886137be565b5050505050505050565b505b506005830180546001810182555f828152602080822090920180546001600160a01b0319166001600160a01b038b1690811790915592549281526007860190915260409020556112c1565b6001600160a01b0386165f9081526007840160205260409020541580156112a857604051630b3cfa8f60e01b815260040160405180910390fd5b6040516360f7af0b60e11b815260040160405180910390fd5b505050505050565b6112d1612e08565b5f6112da612bed565b6001600160a01b0383165f90815260098201602052604090205490915015611315576040516305ec751560e51b815260040160405180910390fd5b6001600160a01b0382165f908152600a82016020908152604091829020825160608101845290546001600160801b03811682526001600160401b03600160801b8204811693830193909352600160c01b900490911691810191909152429061137c90613524565b1061139a5760405163fda6d69360e01b815260040160405180910390fd5b6113a76002820183613913565b6113c45760405163081fcdbf60e21b815260040160405180910390fd5b6040516001600160a01b03831681527ffc9138846a97b86614d19b78419b88e555c50bbd80b03feffd6264cd430643809060200160405180910390a15050565b5f8061140e612bed565b805460408051635c975abb60e01b815290519293506001600160a01b0390911691635c975abb916004808201926020929091908290030181865afa158015611458573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061147c9190615999565b1561149a576040516313d0ff5960e31b815260040160405180910390fd5b5f806114a586613927565b90925090506114b481836158fa565b93506114c3838588888561394d565b50505092915050565b6001600160a01b03165f9081525f80516020615d57833981519152602052604090205490565b606081806001600160401b0381111561150d5761150d615430565b604051908082528060200260200182016040528015611536578160200160208202803683370190505b5091505f5b81811015611579575f858583611550816159b4565b94508181106115615761156161581d565b9050602002013590508054602083028501525061153b565b505092915050565b611589612e08565b5f611592612bed565b90506001600160a01b03841615806115b157506001600160a01b038316155b156115cf57604051639fabe1c160e01b815260040160405180910390fd5b81156115e5576115e08185856139cd565b6116c0565b6001600160a01b0383165f908152600b8201602052604090205460ff1661161f576040516335f85eb560e11b815260040160405180910390fd5b6001600160a01b0384165f908152600c8201602052604090205460ff1661165957604051635819892360e11b815260040160405180910390fd5b6001600160a01b038084165f818152600b840160209081526040808320805460ff19908116909155948916808452600c8701909252808320805490951690945592517f88ecee496061ddc38d88503f7cf6a1f4f6ade60ee216c946c5a0e8de6049595c9190a35b50505050565b6116ce612e08565b5f6116d7612bed565b90508382146116f957604051634ec4810560e11b815260040160405180910390fd5b5f5b848110156112c1575f8686838181106117165761171661581d565b905060200201602081019061172b9190615322565b90506001600160a01b03811661175457604051639fabe1c160e01b815260040160405180910390fd5b8484838181106117665761176661581d565b905060200201602081019061177b91906159cc565b6001600160a01b03919091165f908152600d840160205260409020805460ff19169115159190911790556001016116fb565b6117b5612e08565b5f6117be612bed565b90506117d06060830160408401615322565b6001600160a01b03166117e66020840184615322565b6001600160a01b03160361180d57604051630d11785f60e21b815260040160405180910390fd5b5f61181e6104a16020850185615322565b90505f6118346104a16060860160408701615322565b90505f6118446020860186615322565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561187f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118a39190615831565b90505f6118b66060870160408801615322565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156118f1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119159190615831565b90505f6119256020880188615322565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611969573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061198d9190615982565b90505f6119a06060890160408a01615322565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa1580156119e4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a089190615982565b9050611a3e611a1d60808a0160608b01615322565b60208a01803590611a2e908c615322565b6001600160a01b03169190613ab3565b611a4e6080890160608a01615322565b6001600160a01b0316637f0f41d7611a6960208b018b615322565b60208b0135611a7e60608d0160408e01615322565b611a8b60808e018e6159e7565b6040518663ffffffff1660e01b8152600401611aab959493929190615a29565b5f604051808303815f87803b158015611ac2575f80fd5b505af1158015611ad4573d5f803e3d5ffd5b505050505f81896040016020810190611aed9190615322565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611b31573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b559190615982565b611b5f91906158fa565b90505f611b6f60208b018b615322565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611bb3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611bd79190615982565b611be190856158fa565b9050611bf361048260208c018c615322565b60098a015f611c0560208e018e615322565b6001600160a01b03166001600160a01b031681526020019081526020015f2054611c2f91906158fa565b811115611c4f57604051630301465d60e11b815260040160405180910390fd5b5f611c5b838988612ca6565b90505f611c69838b8a612ca6565b90505f611c7960208e018e615322565b8d6040016020810190611c8c9190615322565b6040516bffffffffffffffffffffffff19606093841b811660208301529190921b1660348201526048016040516020818303038152906040528051906020012090506127108c6008015f8381526020019081526020015f2054612710611cf291906158fa565b611cfc9084615878565b611d0691906158a3565b831015611d2557604051625713a160e91b815260040160405180910390fd5b838c6009015f015f8f5f016020810190611d3f9190615322565b6001600160a01b03166001600160a01b031681526020019081526020015f205f828254611d6c91906158fa565b92505081905550848c6009015f015f8f6040016020810190611d8e9190615322565b6001600160a01b03166001600160a01b031681526020019081526020015f205f828254611dbb9190615865565b90915550611dd1905060608e0160408f01615322565b6001600160a01b0316611de760208f018f615322565b6040805187815260208101899052908101859052606081018690526001600160a01b0391909116907fb8c3fd52c06cd7e35d81a3fc31542187d197c9deef253587a27e0214677d0f6b9060800160405180910390a350505050505050505050505050565b5f80611e55612bed565b805460408051635c975abb60e01b815290519293506001600160a01b0390911691635c975abb916004808201926020929091908290030181865afa158015611e9f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ec39190615999565b15611ee1576040516313d0ff5960e31b815260040160405180910390fd5b611eea84611f76565b91505f84611f12612710611efc613b16565b611f08906127106158fa565b8891906001612dad565b611f1c91906158fa565b9050611579828685878561394d565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0480546060915f80516020615d5783398151915291610a74906158c2565b5f33610b14818585612fa8565b5f80611f9c612710611f86613b16565b611f92906127106158fa565b8591906001612dad565b9050610d0a81613b50565b5f611fb0613005565b5f611fb9612bed565b90505f611fd15f80516020615d778339815191525490565b90505f611fdd856122ce565b90508087111561200657848782604051633fa733bb60e21b8152600401610d9a93929190615946565b61200f87610b1e565b93505f8061201f8587868a6130c5565b909250905061203c8289612033848a6158fa565b878b8e8c613b5c565b50505050509392505050565b6060612052612bed565b6005018054806020026020016040519081016040528092919081815260200182805480156120a757602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311612089575b5050505050905090565b5f6120ba613005565b5f6120c3612bed565b90505f6120db5f80516020615d778339815191525490565b90505f6120e7856122db565b90508087111561211057848782604051632e52afbb60e21b8152600401610d9a93929190615946565b61211987610fda565b93505f80612129858a868a6130c5565b909250905061203c828961213d848d6158fa565b878b8b8f613b5c565b61214e612e08565b5f612157612bed565b905061271082111561217c5760405163aabd5a0960e01b815260040160405180910390fd5b6040516bffffffffffffffffffffffff19606086811b8216602084015285901b1660348201525f9060480160408051601f1981840301815291815281516020928301205f908152600890940190915290912091909155505050565b6121df612e08565b5f6121e8612bed565b90506121ff5f80516020615d778339815191525490565b5f0361221e576040516348b5002360e01b815260040160405180910390fd5b61222b600282018561379d565b6122485760405163081fcdbf60e21b815260040160405180910390fd5b5f83131561228457826122666001600160a01b038616333084613bc5565b61227e8561227383613bfd565b600985019190613c69565b506116c0565b5f61228e84615a79565b90506122a88561229d83613bfd565b600985019190613ce1565b6122bc6001600160a01b0386168483613ab3565b5050505050565b5f610b01825f613d59565b5f610b016104c0836114cc565b5f610b01826114cc565b6001600160a01b039182165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace016020908152604080832093909416825291909152205490565b5f612337613005565b5f612340612bed565b90505f61234c846122ce565b90508088111561237557838882604051633fa733bb60e21b8152600401610d9a93929190615946565b61237e88610b1e565b925061238c82845f876130c5565b50506123cd82898989808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152508b9250613176915050565b60408051898152602081018590526001600160a01b03808716929088169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db9101610e3f565b5f61241e612bed565b335f908152600c8201602052604090205490915060ff16612452576040516358164d9160e11b815260040160405180910390fd5b5f61245c85610efa565b90505f61246a6104a1610e52565b90505f6124e6838361247a610d11565b8a6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156124b6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906124da9190615831565b8a939291906001613d94565b90505f818611156124fe576124fb82876158fa565b90505b801561251c5761251c8861251183613bfd565b600988019190613c69565b61252681876158fa565b6001600160a01b0389165f9081526009870160205260408120805490919061254f908490615865565b90915550879050600986015f612563610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f205f82825461259091906158fa565b9091555050604080516001600160a01b038a16815260208101899052908101879052606081018290527fc659bef2facfde65b659c8c5160cf21ac8232b38f8331aac0cea195e1d9296659060800160405180910390a15050505050505050565b5f805f6125fc84613927565b9092509050610b5081836158fa565b612613612e08565b5f61261c612bed565b90505f612627612048565b9050612631610e52565b6001600160a01b0316846001600160a01b0316036126625760405163338665cd60e01b815260040160405180910390fd5b80515f5b818110156126c157856001600160a01b031683828151811061268a5761268a61581d565b60200260200101516001600160a01b0316036126b9576040516360f7af0b60e11b815260040160405180910390fd5b600101612666565b506126cf6002840186613de4565b6126ec57604051631cf57a9f60e11b815260040160405180910390fd5b825460408051633a0df78d60e11b815290515f926001600160a01b03169163741bef1a9160048083019260209291908290030181865afa158015612732573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127569190615967565b604051635670bcc760e11b81526001600160a01b0388811660048301529192509082169063ace1798e90602401602060405180830381865afa15801561279e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127c29190615982565b5f036127e15760405163fb94c4ed60e01b815260040160405180910390fd5b6127ef600985018787612ead565b6040516001600160a01b03871681527f252fb22f1e5dcdba04908f13259852204aead54fea1342d028eb2f49510bee97906020015b60405180910390a1505050505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03165f811580156128785750825b90505f826001600160401b031660011480156128935750303b155b9050811580156128a1575080155b156128bf5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff1916600117855583156128e957845460ff60401b1916600160401b1785555b5f6128f2612bed565b90505f6129056080890160608a01615322565b6001600160a01b0316148061293157505f61292660a0890160808a01615322565b6001600160a01b0316145b8061295357505f61294860c0890160a08a01615322565b6001600160a01b0316145b1561297157604051639fabe1c160e01b815260040160405180910390fd5b6129816080880160608901615322565b81546001600160a01b0319166001600160a01b03919091161781556129ac60e0880160c08901615322565b6001820180546001600160a01b0319166001600160a01b03929092169190911790556129f7816129e260a08a0160808b01615322565b6129f260c08b0160a08c01615322565b6139cd565b5f612a086080890160608a01615322565b6001600160a01b031663741bef1a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a43573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612a679190615967565b90506001600160a01b03811663ace1798e612a8560208b018b615322565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015612ac7573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612aeb9190615982565b5f03612b0a5760405163fb94c4ed60e01b815260040160405180910390fd5b612b94612b1a60208a018a6159e7565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250612b5b9250505060408b018b6159e7565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250613df892505050565b612ba9612ba460208a018a615322565b613e0a565b505083156112c157845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602001612824565b7f3c2bbd5b01c023780ac7877400fd851b17fd98c152afdb1efc02015acd68a30090565b5f610b01825490565b6001600160a01b0381165f9081526001830160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b900490921690820152612c8481612c7f81613524565b613555565b6001600160a01b0384165f90815260208690526040902054610b5091906158fa565b5f612cb282600a615b76565b612cbc8486615878565b610b5091906158a3565b5f610d0a8383613e1b565b5f610d0a612cdd610874565b612ce8906001615865565b612cf35f600a615b76565b5f80516020615d7783398151915254612d0c9190615865565b85919085612dad565b610b798383836001613e41565b5f610b01826001613d59565b5f80612d38612bed565b80546040516301646b0560e61b81523360048201529192506001600160a01b03169063591ac140906024015b602060405180830381865afa158015612d7f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612da39190615b84565b61ffff1691505090565b5f80612dba868686613f15565b90506001836002811115612dd057612dd0615ba5565b148015612dec57505f8480612de757612de761588f565b868809115b15612dff57612dfc600182615865565b90505b95945050505050565b612e10612bed565b5460408051638da5cb5b60e01b815290516001600160a01b0390921691638da5cb5b916004808201926020929091908290030181865afa158015612e56573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612e7a9190615967565b6001600160a01b0316336001600160a01b031614612eab57604051635fc483c560e01b815260040160405180910390fd5b565b64e8d4a510006001600160401b0382161115612edc576040516304bba2fb60e51b815260040160405180910390fd5b612ee783835f613fbe565b6001600160a01b0382165f81815260018501602090815260409182902080546001600160c01b0316600160c01b6001600160401b0387169081029190911790915591519182527f5577d4c8f6e5397effa5c71df8fe221e1162e18aaa0aabe87026cfb0c676215091015b60405180910390a2505050565b5f612f6984846122e5565b90505f1981146116c05781811015612f9a57828183604051637dc7a0d960e11b8152600401610d9a93929190615946565b6116c084848484035f613e41565b6001600160a01b038316612fd157604051634b637e8f60e11b81525f6004820152602401610d9a565b6001600160a01b038216612ffa5760405163ec442f0560e01b81525f6004820152602401610d9a565b610b79838383614122565b5f61300e612bed565b8054604080516341ba27eb60e01b815290519293506001600160a01b03909116916341ba27eb916004808201926020929091908290030181865afa158015613058573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061307c9190615bb9565b6001600160401b0316421080156130a45750335f908152600d8201602052604090205460ff16155b156130c25760405163abdc9be160e01b815260040160405180910390fd5b50565b5f806130d96130d2612d2e565b86906135dc565b9050336001600160a01b038416146130f6576130f6833387612f5e565b831561314557613142600987015f61310c610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f2054855f848961313a91906158fa565b929190612dad565b91505b8015613163576001860154613163906001600160a01b031682614248565b61316d838661427c565b94509492505050565b5f613180836142b0565b9050806040015161319386600201612c11565b61319d9190615865565b6131a8906001615865565b8151146131c857604051634ec4810560e11b815260040160405180910390fd5b6131d0610e52565b6001600160a01b0316836001835f01516131ea91906158fa565b815181106131fa576131fa61581d565b60200260200101516001600160a01b03161461322957604051636f89c5bf60e11b815260040160405180910390fd5b8051613236908490614353565b835f6132436104a1610e52565b90505f5b83518110801561325657508215155b15613444575f86828151811061326e5761326e61581d565b602002602001015190506132ad8560200151866040015161328d610e52565b61329a60028e018661379d565b6001600160a01b038616939291906143e9565b5f6132bb60098b0183612c1a565b9050805f036132cb575050613432565b5f6132d583610efa565b9050805f036132e657505050613432565b5f836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613323573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906133479190615831565b90505f6133628388613357610d11565b8b929190865f613d94565b90508084106133a3576001600160a01b0385165f90815260098e0160205260408120805491995082918a906133989084906158fa565b909155506134099050565b5f6133ae85836158fa565b90506133c784896133bd610d11565b8492919087614477565b9850849150818e6009015f015f886001600160a01b03166001600160a01b031681526020019081526020015f205f82825461340291906158fa565b9091555050505b80896060015187815181106134205761342061581d565b60200260200101818152505050505050505b8061343c816159b4565b915050613247565b505f5b83518110156134d1575f846060015182815181106134675761346761581d565b602002602001015111156134c9576134c9858560600151838151811061348f5761348f61581d565b60200260200101518884815181106134a9576134a961581d565b60200260200101516001600160a01b0316613ab39092919063ffffffff16565b600101613447565b50836001600160a01b03167f86bcb277da75a9fbb738b8bb82beb731d82a0a89516b848730df92849f966bf08787866060015160405161351393929190615bd4565b60405180910390a250505050505050565b60208101515f906001600160401b031661354b64e8d4a51000613546856144d4565b614509565b610b019190615865565b5f81421061356457505f610b01565b5f83602001516001600160401b03164261357e91906158fa565b90505f8161358b866144d4565b6135959190615878565b855190915064e8d4a51000906135b4906001600160801b031683615878565b6135be91906158a3565b85516135d391906001600160801b03166158fa565b92505050610b01565b5f610d0a83836127106001612dad565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148061367257507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166136665f80516020615d97833981519152546001600160a01b031690565b6001600160a01b031614155b15612eab5760405163703e46dd60e11b815260040160405180910390fd5b6130c2612e08565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156136f2575060408051601f3d908101601f191682019092526136ef91810190615982565b60015b61371a57604051634c9c8ce360e01b81526001600160a01b0383166004820152602401610d9a565b5f80516020615d97833981519152811461374a57604051632a87526960e21b815260048101829052602401610d9a565b610b79838361452b565b306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614612eab5760405163703e46dd60e11b815260040160405180910390fd5b6001600160a01b0381165f9081526001830160205260408120541515610d0a565b5f6137c7612bed565b6001600160a01b0385165f908152600782016020526040902054909150156138025760405163caf865c160e01b815260040160405180910390fd5b5f8160050184815481106138185761381861581d565b5f9182526020808320909101546001600160a01b0316808352600985019091526040909120549091501580159061384d575082155b1561386b576040516305ec751560e51b815260040160405180910390fd5b613876846001615865565b6001600160a01b0386165f908152600784016020526040902055600582018054869190869081106138a9576138a961581d565b5f9182526020918290200180546001600160a01b0319166001600160a01b03938416179055604080518484168152928816918301919091527f9e147d339c63698deb55c3d0d44ed3eba29bac2a068a88c4bc5bde17d6331e19910160405180910390a15050505050565b5f610d0a836001600160a01b038416614580565b5f80613932836122c3565b915061394661393f613b16565b83906135dc565b9050915091565b6139573384614663565b8015613975576001850154613975906001600160a01b031682614248565b61397f8285614248565b60408051848152602081018690526001600160a01b0384169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d791015b60405180910390a35050505050565b6001600160a01b0381165f908152600b8401602052604090205460ff1615613a0857604051631f160d3160e11b815260040160405180910390fd5b6001600160a01b0382165f908152600c8401602052604090205460ff1615613a4357604051632748f32960e21b815260040160405180910390fd5b6001600160a01b038181165f818152600b8601602090815260408083208054600160ff199182168117909255958816808552600c8a0190935281842080549096161790945592517fd6c91941062a66dc4c4344f6b10af4b565b256816a2f9080ba7f83e1d6a2bdc69190a3505050565b6040516001600160a01b038316602482015260448101829052610b7990849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261471c565b5f80613b20612bed565b8054604051636034d9f560e01b81523360048201529192506001600160a01b031690636034d9f590602401612d64565b5f610b01826001612cd1565b613b6687876147ed565b613b718686866148a2565b60408051838152602081018390526001600160a01b03808616929089169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a450505050505050565b6040516001600160a01b03808516602483015283166044820152606481018290526116c09085906323b872dd60e01b90608401613adf565b5f6001600160801b03821115613c655760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608401610d9a565b5090565b806001600160801b03165f03613c925760405163d11b25af60e01b815260040160405180910390fd5b613c9d838383613fbe565b6040516001600160801b03821681526001600160a01b038316907f693ffe037fd29f4846b006bd3ada57d4fd4c3622277227342f0e4fed9011dc2090602001612f51565b806001600160801b03165f03613d0a5760405163d11b25af60e01b815260040160405180910390fd5b613d15838383614c3b565b6040516001600160801b03821681526001600160a01b038316907f5f4e7177e0f8e013ddb6d29e468fa7a45f8df4e00e7895b7f20c5979cab21c6c90602001612f51565b5f610d0a613d6882600a615b76565b5f80516020615d7783398151915254613d819190615865565b613d89610874565b612d0c906001615865565b5f80613dae86613da587600a615b76565b8a919086612dad565b90508615613dd557613dcd613dc485600a615b76565b82908986612dad565b915050613dda565b5f9150505b9695505050505050565b5f610d0a836001600160a01b038416614d19565b613e00614d65565b6110188282614dae565b613e12614d65565b6130c281614dfe565b5f825f018281548110613e3057613e3061581d565b905f5260205f200154905092915050565b5f80516020615d578339815191526001600160a01b038516613e785760405163e602df0560e01b81525f6004820152602401610d9a565b6001600160a01b038416613ea157604051634a1406b160e11b81525f6004820152602401610d9a565b6001600160a01b038086165f908152600183016020908152604080832093881683529290522083905581156122bc57836001600160a01b0316856001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040516139be91815260200190565b5f80805f19858709858702925082811083820303915050805f03613f4c57838281613f4257613f4261588f565b0492505050610d0a565b808411613f57575f80fd5b5f8486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091025f889003889004909101858311909403939093029303949094049190911702949350505050565b6001600160a01b0382165f9081526001840160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b9004909216908201529061402082613524565b90505f614049846001600160801b031661403a8585613555565b6140449190615865565b613bfd565b6001600160801b0381168452905061406042614e81565b6001600160401b03166020808501919091526001600160a01b0386165f908152908790526040812080546001600160801b03871692906140a1908490615865565b909155505050506001600160a01b03929092165f9081526001939093016020908152604093849020835181549285015194909501516001600160801b039095166001600160c01b031990921691909117600160801b6001600160401b0394851602176001600160c01b0316600160c01b939094169290920292909217905550565b5f80516020615d578339815191526001600160a01b03841661415c5781816002015f8282546141519190615865565b909155506141b99050565b6001600160a01b0384165f908152602082905260409020548281101561419b5784818460405163391434e360e21b8152600401610d9a93929190615946565b6001600160a01b0385165f9081526020839052604090209083900390555b6001600160a01b0383166141d75760028101805483900390556141f5565b6001600160a01b0383165f9081526020829052604090208054830190555b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161423a91815260200190565b60405180910390a350505050565b6001600160a01b0382166142715760405163ec442f0560e01b81525f6004820152602401610d9a565b6110185f8383614122565b6001600160a01b0382166142a557604051634b637e8f60e11b81525f6004820152602401610d9a565b611018825f83614122565b6142d960405180608001604052805f8152602001606081526020015f8152602001606081525090565b5f6142e2612048565b90505f83519050604051806080016040528082815260200183815260200183518152602001826001600160401b0381111561431f5761431f615430565b604051908082528060200260200182016040528015614348578160200160208202803683370190505b509052949350505050565b5f5b81811015610b79575f614369826001615865565b90505b828110156143e0578381815181106143865761438661581d565b60200260200101516001600160a01b03168483815181106143a9576143a961581d565b60200260200101516001600160a01b0316036143d8576040516323271fb560e11b815260040160405180910390fd5b60010161436c565b50600101614355565b80806144065750816001600160a01b0316856001600160a01b0316145b6122bc575f805b8481101561445857866001600160a01b03168682815181106144315761443161581d565b60200260200101516001600160a01b0316036144505760019150614458565b60010161440d565b50806112c15760405163c1ab6dc160e01b815260040160405180910390fd5b5f8061448483600a615b76565b61448e8789615878565b61449891906158a3565b905084156144c857846144ac85600a615b76565b6144b69083615878565b6144c091906158a3565b915050612dff565b505f9695505050505050565b5f81604001516001600160401b03165f146144f35781604001516144fa565b64174876e8005b6001600160401b031692915050565b5f8160016145178286615865565b61452191906158fa565b610d0a91906158a3565b61453482614ee8565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a280511561457857610b798282614f4b565b611018614f70565b5f818152600183016020526040812054801561465a575f6145a26001836158fa565b85549091505f906145b5906001906158fa565b9050818114614614575f865f0182815481106145d3576145d361581d565b905f5260205f200154905080875f0184815481106145f3576145f361581d565b5f918252602080832090910192909255918252600188019052604090208390555b855486908061462557614625615c2e565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f905560019350505050610b01565b5f915050610b01565b5f61466c612bed565b9050614676610e52565b60405163e75b3ae760e01b81526001600160a01b03858116600483015260248201859052919091169063e75b3ae7906044015f604051808303815f87803b1580156146bf575f80fd5b505af11580156146d1573d5f803e3d5ffd5b5050505081816009015f015f6146e5610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f205f8282546147129190615865565b9091555050505050565b5f614770826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614f8f9092919063ffffffff16565b805190915015610b79578080602001905181019061478e9190615999565b610b795760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610d9a565b5f6147f6612bed565b9050614800610e52565b604051631062c15f60e11b81523060048201526001600160a01b0384811660248301526044820186905291909116906320c582be906064015f604051808303815f87803b15801561484f575f80fd5b505af1158015614861573d5f803e3d5ffd5b5050505082816009015f015f614875610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f205f82825461471291906158fa565b5f6148ab612bed565b90505f6148b6612048565b80519091505f6148c860028501612c11565b90505f6148d58284615865565b6001600160401b038111156148ec576148ec615430565b604051908082528060200260200182016040528015614915578160200160208202803683370190505b5090505f6149238385615865565b6001600160401b0381111561493a5761493a615430565b604051908082528060200260200182016040528015614963578160200160208202803683370190505b5090505f5b84811015614a8e575f6149a08783815181106149865761498661581d565b602002602001015189600901612c1a90919063ffffffff16565b90506149ae8a828b5f612dad565b8483815181106149c0576149c061581d565b6020026020010181815250508682815181106149de576149de61581d565b60200260200101518383815181106149f8576149f861581d565b60200260200101906001600160a01b031690816001600160a01b031681525050838281518110614a2a57614a2a61581d565b6020026020010151886009015f015f898581518110614a4b57614a4b61581d565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f205f828254614a8091906158fa565b909155505050600101614968565b505f5b83811015614b86575f614aa48683615865565b90505f614ab460028a0184612cc6565b90505f614ac460098b0183612c1a565b9050614ad28c828d5f612dad565b868481518110614ae457614ae461581d565b60200260200101818152505081858481518110614b0357614b0361581d565b60200260200101906001600160a01b031690816001600160a01b031681525050858381518110614b3557614b3561581d565b60200260200101518a6009015f015f846001600160a01b03166001600160a01b031681526020019081526020015f205f828254614b7291906158fa565b909155505060019093019250614a91915050565b505f5b8151811015614bea57828181518110614ba457614ba461581d565b60200260200101515f14614be257614be28a848381518110614bc857614bc861581d565b60200260200101518484815181106134a9576134a961581d565b600101614b89565b50886001600160a01b03167f86bcb277da75a9fbb738b8bb82beb731d82a0a89516b848730df92849f966bf0898385604051614c2893929190615bd4565b60405180910390a2505050505050505050565b6001600160a01b0382165f9081526001840160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b90049092169082015290614c9d82613524565b90505f614cc1846001600160801b0316614cb78585613555565b61404491906158fa565b6001600160801b03811684529050614cd842614e81565b6001600160401b03166020808501919091526001600160a01b0386165f908152908790526040812080546001600160801b03871692906140a19084906158fa565b5f818152600183016020526040812054614d5e57508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610b01565b505f610b01565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff16612eab57604051631afcd79f60e31b815260040160405180910390fd5b614db6614d65565b5f80516020615d578339815191527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace03614def8482615c86565b50600481016116c08382615c86565b614e06614d65565b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e005f80614e3284614f9d565b9150915081614e42576012614e44565b805b83546001600160a81b031916600160a01b60ff92909216919091026001600160a01b031916176001600160a01b0394909416939093179091555050565b5f6001600160401b03821115613c655760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203660448201526534206269747360d01b6064820152608401610d9a565b806001600160a01b03163b5f03614f1d57604051634c9c8ce360e01b81526001600160a01b0382166004820152602401610d9a565b5f80516020615d9783398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6060610d0a8383604051806060016040528060278152602001615db760279139615073565b3415612eab5760405163b398979f60e01b815260040160405180910390fd5b6060610b5084845f856150dd565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290515f918291829182916001600160a01b03871691614fe391615d40565b5f60405180830381855afa9150503d805f811461501b576040519150601f19603f3d011682016040523d82523d5f602084013e615020565b606091505b509150915081801561503457506020815110155b15615067575f8180602001905181019061504e9190615982565b905060ff8111615065576001969095509350505050565b505b505f9485945092505050565b60605f80856001600160a01b03168560405161508f9190615d40565b5f60405180830381855af49150503d805f81146150c7576040519150601f19603f3d011682016040523d82523d5f602084013e6150cc565b606091505b5091509150613dda868383876151b4565b60608247101561513e5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610d9a565b5f80866001600160a01b031685876040516151599190615d40565b5f6040518083038185875af1925050503d805f8114615193576040519150601f19603f3d011682016040523d82523d5f602084013e615198565b606091505b50915091506151a9878383876151b4565b979650505050505050565b606083156152225782515f0361521b576001600160a01b0385163b61521b5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610d9a565b5081610b50565b610b5083838151156152375781518083602001fd5b8060405162461bcd60e51b8152600401610d9a91905b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f60208284031215615292575f80fd5b5035919050565b6001600160a01b03811681146130c2575f80fd5b5f80604083850312156152be575f80fd5b82356152c981615299565b946020939093013593505050565b6001600160401b03811681146130c2575f80fd5b5f80604083850312156152fc575f80fd5b823561530781615299565b91506020830135615317816152d7565b809150509250929050565b5f60208284031215615332575f80fd5b8135610d0a81615299565b5f805f6060848603121561534f575f80fd5b833561535a81615299565b9250602084013561536a81615299565b929592945050506040919091013590565b5f8083601f84011261538b575f80fd5b5081356001600160401b038111156153a1575f80fd5b6020830191508360208260051b85010111156153bb575f80fd5b9250929050565b5f805f805f608086880312156153d6575f80fd5b8535945060208601356001600160401b038111156153f2575f80fd5b6153fe8882890161537b565b909550935050604086013561541281615299565b9150606086013561542281615299565b809150509295509295909350565b634e487b7160e01b5f52604160045260245ffd5b5f8060408385031215615455575f80fd5b823561546081615299565b915060208301356001600160401b0381111561547a575f80fd5b8301601f8101851361548a575f80fd5b80356001600160401b038111156154a3576154a3615430565b604051601f8201601f19908116603f011681016001600160401b03811182821017156154d1576154d1615430565b6040528181528282016020018710156154e8575f80fd5b816020840160208301375f602083830101528093505050509250929050565b80151581146130c2575f80fd5b5f805f60608486031215615526575f80fd5b833561553181615299565b92506020840135615541816152d7565b9150604084013561555181615507565b809150509250925092565b5f806040838503121561556d575f80fd5b82359150602083013561531781615299565b5f8060208385031215615590575f80fd5b82356001600160401b038111156155a5575f80fd5b6155b18582860161537b565b90969095509350505050565b602080825282518282018190525f918401906040840190835b818110156155f45783518352602093840193909201916001016155d6565b509095945050505050565b5f805f60608486031215615611575f80fd5b833561561c81615299565b9250602084013561554181615299565b5f805f806040858703121561563f575f80fd5b84356001600160401b03811115615654575f80fd5b6156608782880161537b565b90955093505060208501356001600160401b0381111561567e575f80fd5b61568a8782880161537b565b95989497509550505050565b5f602082840312156156a6575f80fd5b81356001600160401b038111156156bb575f80fd5b820160a08185031215610d0a575f80fd5b5f805f606084860312156156de575f80fd5b8335925060208401356156f081615299565b9150604084013561555181615299565b5f8151808452602084019350602083015f5b828110156157395781516001600160a01b0316865260209586019590910190600101615712565b5093949350505050565b602081525f610d0a6020830184615700565b5f805f60608486031215615767575f80fd5b833561577281615299565b925060208401359150604084013561555181615299565b5f806040838503121561579a575f80fd5b82356157a581615299565b9150602083013561531781615299565b5f805f606084860312156157c7575f80fd5b83356157d281615299565b95602085013595506040909401359392505050565b5f602082840312156157f7575f80fd5b81356001600160401b0381111561580c575f80fd5b820160e08185031215610d0a575f80fd5b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215615841575f80fd5b815160ff81168114610d0a575f80fd5b634e487b7160e01b5f52601160045260245ffd5b80820180821115610b0157610b01615851565b8082028115828204841417610b0157610b01615851565b634e487b7160e01b5f52601260045260245ffd5b5f826158bd57634e487b7160e01b5f52601260045260245ffd5b500490565b600181811c908216806158d657607f821691505b6020821081036158f457634e487b7160e01b5f52602260045260245ffd5b50919050565b81810381811115610b0157610b01615851565b5f61ffff821661ffff810361592457615924615851565b60010192915050565b60ff8181168382160190811115610b0157610b01615851565b6001600160a01b039390931683526020830191909152604082015260600190565b5f60208284031215615977575f80fd5b8151610d0a81615299565b5f60208284031215615992575f80fd5b5051919050565b5f602082840312156159a9575f80fd5b8151610d0a81615507565b5f600182016159c5576159c5615851565b5060010190565b5f602082840312156159dc575f80fd5b8135610d0a81615507565b5f808335601e198436030181126159fc575f80fd5b8301803591506001600160401b03821115615a15575f80fd5b6020019150368190038213156153bb575f80fd5b6001600160a01b03868116825260208201869052841660408201526080606082018190528101829052818360a08301375f81830160a090810191909152601f909201601f19160101949350505050565b5f600160ff1b8201615a8d57615a8d615851565b505f0390565b6001815b6001841115615ace57808504811115615ab257615ab2615851565b6001841615615ac057908102905b60019390931c928002615a97565b935093915050565b5f82615ae457506001610b01565b81615af057505f610b01565b8160018114615b065760028114615b1057615b2c565b6001915050610b01565b60ff841115615b2157615b21615851565b50506001821b610b01565b5060208310610133831016604e8410600b8410161715615b4f575081810a610b01565b615b5b5f198484615a93565b805f1904821115615b6e57615b6e615851565b029392505050565b5f610d0a60ff841683615ad6565b5f60208284031215615b94575f80fd5b815161ffff81168114610d0a575f80fd5b634e487b7160e01b5f52602160045260245ffd5b5f60208284031215615bc9575f80fd5b8151610d0a816152d7565b838152606060208201525f615bec6060830185615700565b8281036040840152835180825260208086019201905f5b81811015615c21578351835260209384019390920191600101615c03565b5090979650505050505050565b634e487b7160e01b5f52603160045260245ffd5b601f821115610b7957805f5260205f20601f840160051c81016020851015615c675750805b601f840160051c820191505b818110156122bc575f8155600101615c73565b81516001600160401b03811115615c9f57615c9f615430565b615cb381615cad84546158c2565b84615c42565b6020601f821160018114615ce5575f8315615cce5750848201515b5f19600385901b1c1916600184901b1784556122bc565b5f84815260208120601f198516915b82811015615d145787850151825560209485019460019092019101615cf4565b5084821015615d3157868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b5f82518060208501845e5f92019182525091905056fe52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace02360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220c0e2a3c0a969483070b6abd693c642c5c25a42fc7bbaf88c41046f1fbe1b77cb64736f6c634300081a0033
Deployed Bytecode
0x60806040526004361061028b575f3560e01c80637b8b8b7411610155578063badd8b2d116100be578063dd62ed3e11610078578063dd62ed3e146107ba578063ddda679b146107d9578063e6666733146107f8578063ef8b30f714610817578063fcb9990514610836578063fd69414414610855575f80fd5b8063badd8b2d1461071f578063c5e6a7671461073e578063c63d75b614610448578063c6e6f5921461075d578063ce96cb771461077c578063d905777e1461079b575f80fd5b8063a9059cbb1161010f578063a9059cbb14610652578063ad3cb1cc14610671578063b3d7f6b9146106a1578063b460af94146106c0578063b58eb63f146106df578063ba08765214610700575f80fd5b80637b8b8b74146105945780637d4601c0146105b35780637facd79b146105d257806394bf804d146105f157806395d89b4114610610578063a7528a0314610624575f80fd5b806338d52e0f116101f757806352d1902d116101b157806352d1902d146104d8578063602ecae5146104ec5780636cd611be1461050b5780636e553f651461052a57806370a08231146105495780637784c68514610568575f80fd5b806338d52e0f1461041c578063402d267d14610448578063403dd3bc1461046857806341976e09146104875780634cdad506146104a65780634f1ef286146104c5575f80fd5b80630d9a6b35116102485780630d9a6b351461036557806318160ddd1461037957806319f27b3b1461039957806323b872dd146103b8578063313ce567146103d757806331e95162146103fd575f80fd5b806301e1d1141461028f57806306fdde03146102b657806307a2d13a146102d7578063095ea7b3146102f65780630a28a477146103255780630b983a7414610344575b5f80fd5b34801561029a575f80fd5b506102a3610874565b6040519081526020015b60405180910390f35b3480156102c1575f80fd5b506102ca610a36565b6040516102ad919061524d565b3480156102e2575f80fd5b506102a36102f1366004615282565b610af6565b348015610301575f80fd5b506103156103103660046152ad565b610b07565b60405190151581526020016102ad565b348015610330575f80fd5b506102a361033f366004615282565b610b1e565b34801561034f575f80fd5b5061036361035e3660046152eb565b610b58565b005b348015610370575f80fd5b506102a3610b7e565b348015610384575f80fd5b505f80516020615d77833981519152546102a3565b3480156103a4575f80fd5b506103636103b3366004615322565b610bb8565b3480156103c3575f80fd5b506103156103d236600461533d565b610cec565b3480156103e2575f80fd5b506103eb610d11565b60405160ff90911681526020016102ad565b348015610408575f80fd5b506102a36104173660046153c2565b610d53565b348015610427575f80fd5b50610430610e52565b6040516001600160a01b0390911681526020016102ad565b348015610453575f80fd5b506102a3610462366004615322565b505f1990565b348015610473575f80fd5b506102a3610482366004615322565b610e80565b348015610492575f80fd5b506102a36104a1366004615322565b610efa565b3480156104b1575f80fd5b506102a36104c0366004615282565b610fda565b6103636104d3366004615444565b610ffd565b3480156104e3575f80fd5b506102a361101c565b3480156104f7575f80fd5b50610363610506366004615514565b611037565b348015610516575f80fd5b50610363610525366004615322565b6112c9565b348015610535575f80fd5b506102a361054436600461555c565b611404565b348015610554575f80fd5b506102a3610563366004615322565b6114cc565b348015610573575f80fd5b5061058761058236600461557f565b6114f2565b6040516102ad91906155bd565b34801561059f575f80fd5b506103636105ae3660046155ff565b611581565b3480156105be575f80fd5b506103636105cd36600461562c565b6116c6565b3480156105dd575f80fd5b506103636105ec366004615696565b6117ad565b3480156105fc575f80fd5b506102a361060b36600461555c565b611e4b565b34801561061b575f80fd5b506102ca611f2b565b34801561062f575f80fd5b5061063a62093a8081565b6040516001600160801b0390911681526020016102ad565b34801561065d575f80fd5b5061031561066c3660046152ad565b611f69565b34801561067c575f80fd5b506102ca604051806040016040528060058152602001640352e302e360dc1b81525081565b3480156106ac575f80fd5b506102a36106bb366004615282565b611f76565b3480156106cb575f80fd5b506102a36106da3660046156cc565b611fa7565b3480156106ea575f80fd5b506106f3612048565b6040516102ad9190615743565b34801561070b575f80fd5b506102a361071a3660046156cc565b6120b1565b34801561072a575f80fd5b5061036361073936600461533d565b612146565b348015610749575f80fd5b50610363610758366004615755565b6121d7565b348015610768575f80fd5b506102a3610777366004615282565b6122c3565b348015610787575f80fd5b506102a3610796366004615322565b6122ce565b3480156107a6575f80fd5b506102a36107b5366004615322565b6122db565b3480156107c5575f80fd5b506102a36107d4366004615789565b6122e5565b3480156107e4575f80fd5b506102a36107f33660046153c2565b61232e565b348015610803575f80fd5b506103636108123660046157b5565b612415565b348015610822575f80fd5b506102a3610831366004615282565b6125f0565b348015610841575f80fd5b506103636108503660046152eb565b61260b565b348015610860575f80fd5b5061036361086f3660046157e7565b612834565b5f8061087e612bed565b90505f8061088a612048565b90505f6108986104a1610e52565b82519091505f6108aa60028701612c11565b90505f60098701816108ba610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f205490505f5b838110156109ad575f8682815181106108f9576108f961581d565b602002602001015190505f61091a828b600901612c1a90919063ffffffff16565b905080156109a35761099661092e83610efa565b836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561096a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061098e9190615831565b839190612ca6565b6109a0908a615865565b98505b50506001016108de565b505f5b82811015610a01575f6109c660028a0183612cc6565b90505f6109d660098b0183612c1a565b905080156109f7576109ea61092e83610efa565b6109f4908a615865565b98505b50506001016109b0565b508084610a16670de0b6b3a764000089615878565b610a2091906158a3565b610a2a9190615865565b97505050505050505090565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0380546060915f80516020615d5783398151915291610a74906158c2565b80601f0160208091040260200160405190810160405280929190818152602001828054610aa0906158c2565b8015610aeb5780601f10610ac257610100808354040283529160200191610aeb565b820191905f5260205f20905b815481529060010190602001808311610ace57829003601f168201915b505050505091505090565b5f610b01825f612cd1565b92915050565b5f33610b14818585612d15565b5060019392505050565b5f80610b2983612d22565b90505f610b50612710610b3a612d2e565b610b46906127106158fa565b8491906001612dad565b949350505050565b610b60612e08565b5f610b69612bed565b9050610b79600982018484612ead565b505050565b5f610b87612bed565b6009015f610b93610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f2054905090565b610bc0612e08565b5f610bc9612bed565b6001600160a01b0383165f90815260078201602052604081205491925003610c0457604051630b3cfa8f60e01b815260040160405180910390fd5b6040805180820182526001600160a01b0384165f9081526007840160205291909120548190610c35906001906158fa565b6001600160801b03168152602001610c5062093a8042615865565b6001600160801b0316905260048201805460068401915f9162010000900461ffff16906002610c7e8361590d565b825461ffff9182166101009390930a92830292820219169190911790915516815260208082019290925260409081015f9081208451948401516001600160801b03908116600160801b029516949094179093556001600160a01b039094168252600790920190915290812055565b5f33610cf9858285612f5e565b610d04858585612fa8565b60019150505b9392505050565b5f807f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e0090505f8154610d4d9190600160a01b900460ff1661592d565b91505090565b5f610d5c613005565b5f610d65612bed565b90505f610d71846122db565b905080881115610da357838882604051632e52afbb60e21b8152600401610d9a93929190615946565b60405180910390fd5b610dac88610fda565b9250610dba82895f876130c5565b5050610dfb82848989808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152508b9250613176915050565b60408051848152602081018a90526001600160a01b03808716929088169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db91015b60405180910390a4505095945050505050565b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00546001600160a01b031690565b5f80610e8a612bed565b6001600160a01b0384165f908152600a90910160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b9004909216908201529150610eee82613524565b9050610b508282613555565b5f80610f04612bed565b5460408051633a0df78d60e11b815290516001600160a01b039092169163741bef1a916004808201926020929091908290030181865afa158015610f4a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f6e9190615967565b604051635670bcc760e11b81526001600160a01b0385811660048301529192509082169063ace1798e90602401602060405180830381865afa158015610fb6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d0a9190615982565b5f80610fee610fe7612d2e565b84906135dc565b9050610d0a6102f182856158fa565b6110056135ec565b61100e82613690565b6110188282613698565b5050565b5f611025613754565b505f80516020615d9783398151915290565b5f611040612bed565b905061104a610e52565b6001600160a01b0316846001600160a01b03160361107b5760405163338665cd60e01b815260040160405180910390fd5b335f908152600b8201602052604090205460ff166110ac5760405163a84178ab60e01b815260040160405180910390fd5b6110b9600282018561379d565b156110d757604051631cf57a9f60e11b815260040160405180910390fd5b60058101545f6110eb600984018787612ead565b5f5b8281101561113e57866001600160a01b03168460050182815481106111145761111461581d565b5f918252602090912001546001600160a01b031603611136576001915061113e565b6001016110ed565b508061126e5760408051808201909152600484015461ffff808216808452620100009092041660208301819052111561122357805161ffff165f9081526006850160209081526040918290208251808401909352546001600160801b038082168452600160801b909104169082018190524211156112215760048501805460068701915f9161ffff1690826111d28361590d565b82546101009290920a61ffff81810219909316918316021790915516815260208101919091526040015f9081205580516112179089906001600160801b0316886137be565b5050505050505050565b505b506005830180546001810182555f828152602080822090920180546001600160a01b0319166001600160a01b038b1690811790915592549281526007860190915260409020556112c1565b6001600160a01b0386165f9081526007840160205260409020541580156112a857604051630b3cfa8f60e01b815260040160405180910390fd5b6040516360f7af0b60e11b815260040160405180910390fd5b505050505050565b6112d1612e08565b5f6112da612bed565b6001600160a01b0383165f90815260098201602052604090205490915015611315576040516305ec751560e51b815260040160405180910390fd5b6001600160a01b0382165f908152600a82016020908152604091829020825160608101845290546001600160801b03811682526001600160401b03600160801b8204811693830193909352600160c01b900490911691810191909152429061137c90613524565b1061139a5760405163fda6d69360e01b815260040160405180910390fd5b6113a76002820183613913565b6113c45760405163081fcdbf60e21b815260040160405180910390fd5b6040516001600160a01b03831681527ffc9138846a97b86614d19b78419b88e555c50bbd80b03feffd6264cd430643809060200160405180910390a15050565b5f8061140e612bed565b805460408051635c975abb60e01b815290519293506001600160a01b0390911691635c975abb916004808201926020929091908290030181865afa158015611458573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061147c9190615999565b1561149a576040516313d0ff5960e31b815260040160405180910390fd5b5f806114a586613927565b90925090506114b481836158fa565b93506114c3838588888561394d565b50505092915050565b6001600160a01b03165f9081525f80516020615d57833981519152602052604090205490565b606081806001600160401b0381111561150d5761150d615430565b604051908082528060200260200182016040528015611536578160200160208202803683370190505b5091505f5b81811015611579575f858583611550816159b4565b94508181106115615761156161581d565b9050602002013590508054602083028501525061153b565b505092915050565b611589612e08565b5f611592612bed565b90506001600160a01b03841615806115b157506001600160a01b038316155b156115cf57604051639fabe1c160e01b815260040160405180910390fd5b81156115e5576115e08185856139cd565b6116c0565b6001600160a01b0383165f908152600b8201602052604090205460ff1661161f576040516335f85eb560e11b815260040160405180910390fd5b6001600160a01b0384165f908152600c8201602052604090205460ff1661165957604051635819892360e11b815260040160405180910390fd5b6001600160a01b038084165f818152600b840160209081526040808320805460ff19908116909155948916808452600c8701909252808320805490951690945592517f88ecee496061ddc38d88503f7cf6a1f4f6ade60ee216c946c5a0e8de6049595c9190a35b50505050565b6116ce612e08565b5f6116d7612bed565b90508382146116f957604051634ec4810560e11b815260040160405180910390fd5b5f5b848110156112c1575f8686838181106117165761171661581d565b905060200201602081019061172b9190615322565b90506001600160a01b03811661175457604051639fabe1c160e01b815260040160405180910390fd5b8484838181106117665761176661581d565b905060200201602081019061177b91906159cc565b6001600160a01b03919091165f908152600d840160205260409020805460ff19169115159190911790556001016116fb565b6117b5612e08565b5f6117be612bed565b90506117d06060830160408401615322565b6001600160a01b03166117e66020840184615322565b6001600160a01b03160361180d57604051630d11785f60e21b815260040160405180910390fd5b5f61181e6104a16020850185615322565b90505f6118346104a16060860160408701615322565b90505f6118446020860186615322565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561187f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118a39190615831565b90505f6118b66060870160408801615322565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156118f1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119159190615831565b90505f6119256020880188615322565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611969573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061198d9190615982565b90505f6119a06060890160408a01615322565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa1580156119e4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a089190615982565b9050611a3e611a1d60808a0160608b01615322565b60208a01803590611a2e908c615322565b6001600160a01b03169190613ab3565b611a4e6080890160608a01615322565b6001600160a01b0316637f0f41d7611a6960208b018b615322565b60208b0135611a7e60608d0160408e01615322565b611a8b60808e018e6159e7565b6040518663ffffffff1660e01b8152600401611aab959493929190615a29565b5f604051808303815f87803b158015611ac2575f80fd5b505af1158015611ad4573d5f803e3d5ffd5b505050505f81896040016020810190611aed9190615322565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611b31573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b559190615982565b611b5f91906158fa565b90505f611b6f60208b018b615322565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611bb3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611bd79190615982565b611be190856158fa565b9050611bf361048260208c018c615322565b60098a015f611c0560208e018e615322565b6001600160a01b03166001600160a01b031681526020019081526020015f2054611c2f91906158fa565b811115611c4f57604051630301465d60e11b815260040160405180910390fd5b5f611c5b838988612ca6565b90505f611c69838b8a612ca6565b90505f611c7960208e018e615322565b8d6040016020810190611c8c9190615322565b6040516bffffffffffffffffffffffff19606093841b811660208301529190921b1660348201526048016040516020818303038152906040528051906020012090506127108c6008015f8381526020019081526020015f2054612710611cf291906158fa565b611cfc9084615878565b611d0691906158a3565b831015611d2557604051625713a160e91b815260040160405180910390fd5b838c6009015f015f8f5f016020810190611d3f9190615322565b6001600160a01b03166001600160a01b031681526020019081526020015f205f828254611d6c91906158fa565b92505081905550848c6009015f015f8f6040016020810190611d8e9190615322565b6001600160a01b03166001600160a01b031681526020019081526020015f205f828254611dbb9190615865565b90915550611dd1905060608e0160408f01615322565b6001600160a01b0316611de760208f018f615322565b6040805187815260208101899052908101859052606081018690526001600160a01b0391909116907fb8c3fd52c06cd7e35d81a3fc31542187d197c9deef253587a27e0214677d0f6b9060800160405180910390a350505050505050505050505050565b5f80611e55612bed565b805460408051635c975abb60e01b815290519293506001600160a01b0390911691635c975abb916004808201926020929091908290030181865afa158015611e9f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ec39190615999565b15611ee1576040516313d0ff5960e31b815260040160405180910390fd5b611eea84611f76565b91505f84611f12612710611efc613b16565b611f08906127106158fa565b8891906001612dad565b611f1c91906158fa565b9050611579828685878561394d565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0480546060915f80516020615d5783398151915291610a74906158c2565b5f33610b14818585612fa8565b5f80611f9c612710611f86613b16565b611f92906127106158fa565b8591906001612dad565b9050610d0a81613b50565b5f611fb0613005565b5f611fb9612bed565b90505f611fd15f80516020615d778339815191525490565b90505f611fdd856122ce565b90508087111561200657848782604051633fa733bb60e21b8152600401610d9a93929190615946565b61200f87610b1e565b93505f8061201f8587868a6130c5565b909250905061203c8289612033848a6158fa565b878b8e8c613b5c565b50505050509392505050565b6060612052612bed565b6005018054806020026020016040519081016040528092919081815260200182805480156120a757602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311612089575b5050505050905090565b5f6120ba613005565b5f6120c3612bed565b90505f6120db5f80516020615d778339815191525490565b90505f6120e7856122db565b90508087111561211057848782604051632e52afbb60e21b8152600401610d9a93929190615946565b61211987610fda565b93505f80612129858a868a6130c5565b909250905061203c828961213d848d6158fa565b878b8b8f613b5c565b61214e612e08565b5f612157612bed565b905061271082111561217c5760405163aabd5a0960e01b815260040160405180910390fd5b6040516bffffffffffffffffffffffff19606086811b8216602084015285901b1660348201525f9060480160408051601f1981840301815291815281516020928301205f908152600890940190915290912091909155505050565b6121df612e08565b5f6121e8612bed565b90506121ff5f80516020615d778339815191525490565b5f0361221e576040516348b5002360e01b815260040160405180910390fd5b61222b600282018561379d565b6122485760405163081fcdbf60e21b815260040160405180910390fd5b5f83131561228457826122666001600160a01b038616333084613bc5565b61227e8561227383613bfd565b600985019190613c69565b506116c0565b5f61228e84615a79565b90506122a88561229d83613bfd565b600985019190613ce1565b6122bc6001600160a01b0386168483613ab3565b5050505050565b5f610b01825f613d59565b5f610b016104c0836114cc565b5f610b01826114cc565b6001600160a01b039182165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace016020908152604080832093909416825291909152205490565b5f612337613005565b5f612340612bed565b90505f61234c846122ce565b90508088111561237557838882604051633fa733bb60e21b8152600401610d9a93929190615946565b61237e88610b1e565b925061238c82845f876130c5565b50506123cd82898989808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152508b9250613176915050565b60408051898152602081018590526001600160a01b03808716929088169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db9101610e3f565b5f61241e612bed565b335f908152600c8201602052604090205490915060ff16612452576040516358164d9160e11b815260040160405180910390fd5b5f61245c85610efa565b90505f61246a6104a1610e52565b90505f6124e6838361247a610d11565b8a6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156124b6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906124da9190615831565b8a939291906001613d94565b90505f818611156124fe576124fb82876158fa565b90505b801561251c5761251c8861251183613bfd565b600988019190613c69565b61252681876158fa565b6001600160a01b0389165f9081526009870160205260408120805490919061254f908490615865565b90915550879050600986015f612563610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f205f82825461259091906158fa565b9091555050604080516001600160a01b038a16815260208101899052908101879052606081018290527fc659bef2facfde65b659c8c5160cf21ac8232b38f8331aac0cea195e1d9296659060800160405180910390a15050505050505050565b5f805f6125fc84613927565b9092509050610b5081836158fa565b612613612e08565b5f61261c612bed565b90505f612627612048565b9050612631610e52565b6001600160a01b0316846001600160a01b0316036126625760405163338665cd60e01b815260040160405180910390fd5b80515f5b818110156126c157856001600160a01b031683828151811061268a5761268a61581d565b60200260200101516001600160a01b0316036126b9576040516360f7af0b60e11b815260040160405180910390fd5b600101612666565b506126cf6002840186613de4565b6126ec57604051631cf57a9f60e11b815260040160405180910390fd5b825460408051633a0df78d60e11b815290515f926001600160a01b03169163741bef1a9160048083019260209291908290030181865afa158015612732573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127569190615967565b604051635670bcc760e11b81526001600160a01b0388811660048301529192509082169063ace1798e90602401602060405180830381865afa15801561279e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127c29190615982565b5f036127e15760405163fb94c4ed60e01b815260040160405180910390fd5b6127ef600985018787612ead565b6040516001600160a01b03871681527f252fb22f1e5dcdba04908f13259852204aead54fea1342d028eb2f49510bee97906020015b60405180910390a1505050505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03165f811580156128785750825b90505f826001600160401b031660011480156128935750303b155b9050811580156128a1575080155b156128bf5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff1916600117855583156128e957845460ff60401b1916600160401b1785555b5f6128f2612bed565b90505f6129056080890160608a01615322565b6001600160a01b0316148061293157505f61292660a0890160808a01615322565b6001600160a01b0316145b8061295357505f61294860c0890160a08a01615322565b6001600160a01b0316145b1561297157604051639fabe1c160e01b815260040160405180910390fd5b6129816080880160608901615322565b81546001600160a01b0319166001600160a01b03919091161781556129ac60e0880160c08901615322565b6001820180546001600160a01b0319166001600160a01b03929092169190911790556129f7816129e260a08a0160808b01615322565b6129f260c08b0160a08c01615322565b6139cd565b5f612a086080890160608a01615322565b6001600160a01b031663741bef1a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a43573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612a679190615967565b90506001600160a01b03811663ace1798e612a8560208b018b615322565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015612ac7573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612aeb9190615982565b5f03612b0a5760405163fb94c4ed60e01b815260040160405180910390fd5b612b94612b1a60208a018a6159e7565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250612b5b9250505060408b018b6159e7565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250613df892505050565b612ba9612ba460208a018a615322565b613e0a565b505083156112c157845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602001612824565b7f3c2bbd5b01c023780ac7877400fd851b17fd98c152afdb1efc02015acd68a30090565b5f610b01825490565b6001600160a01b0381165f9081526001830160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b900490921690820152612c8481612c7f81613524565b613555565b6001600160a01b0384165f90815260208690526040902054610b5091906158fa565b5f612cb282600a615b76565b612cbc8486615878565b610b5091906158a3565b5f610d0a8383613e1b565b5f610d0a612cdd610874565b612ce8906001615865565b612cf35f600a615b76565b5f80516020615d7783398151915254612d0c9190615865565b85919085612dad565b610b798383836001613e41565b5f610b01826001613d59565b5f80612d38612bed565b80546040516301646b0560e61b81523360048201529192506001600160a01b03169063591ac140906024015b602060405180830381865afa158015612d7f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612da39190615b84565b61ffff1691505090565b5f80612dba868686613f15565b90506001836002811115612dd057612dd0615ba5565b148015612dec57505f8480612de757612de761588f565b868809115b15612dff57612dfc600182615865565b90505b95945050505050565b612e10612bed565b5460408051638da5cb5b60e01b815290516001600160a01b0390921691638da5cb5b916004808201926020929091908290030181865afa158015612e56573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612e7a9190615967565b6001600160a01b0316336001600160a01b031614612eab57604051635fc483c560e01b815260040160405180910390fd5b565b64e8d4a510006001600160401b0382161115612edc576040516304bba2fb60e51b815260040160405180910390fd5b612ee783835f613fbe565b6001600160a01b0382165f81815260018501602090815260409182902080546001600160c01b0316600160c01b6001600160401b0387169081029190911790915591519182527f5577d4c8f6e5397effa5c71df8fe221e1162e18aaa0aabe87026cfb0c676215091015b60405180910390a2505050565b5f612f6984846122e5565b90505f1981146116c05781811015612f9a57828183604051637dc7a0d960e11b8152600401610d9a93929190615946565b6116c084848484035f613e41565b6001600160a01b038316612fd157604051634b637e8f60e11b81525f6004820152602401610d9a565b6001600160a01b038216612ffa5760405163ec442f0560e01b81525f6004820152602401610d9a565b610b79838383614122565b5f61300e612bed565b8054604080516341ba27eb60e01b815290519293506001600160a01b03909116916341ba27eb916004808201926020929091908290030181865afa158015613058573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061307c9190615bb9565b6001600160401b0316421080156130a45750335f908152600d8201602052604090205460ff16155b156130c25760405163abdc9be160e01b815260040160405180910390fd5b50565b5f806130d96130d2612d2e565b86906135dc565b9050336001600160a01b038416146130f6576130f6833387612f5e565b831561314557613142600987015f61310c610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f2054855f848961313a91906158fa565b929190612dad565b91505b8015613163576001860154613163906001600160a01b031682614248565b61316d838661427c565b94509492505050565b5f613180836142b0565b9050806040015161319386600201612c11565b61319d9190615865565b6131a8906001615865565b8151146131c857604051634ec4810560e11b815260040160405180910390fd5b6131d0610e52565b6001600160a01b0316836001835f01516131ea91906158fa565b815181106131fa576131fa61581d565b60200260200101516001600160a01b03161461322957604051636f89c5bf60e11b815260040160405180910390fd5b8051613236908490614353565b835f6132436104a1610e52565b90505f5b83518110801561325657508215155b15613444575f86828151811061326e5761326e61581d565b602002602001015190506132ad8560200151866040015161328d610e52565b61329a60028e018661379d565b6001600160a01b038616939291906143e9565b5f6132bb60098b0183612c1a565b9050805f036132cb575050613432565b5f6132d583610efa565b9050805f036132e657505050613432565b5f836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613323573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906133479190615831565b90505f6133628388613357610d11565b8b929190865f613d94565b90508084106133a3576001600160a01b0385165f90815260098e0160205260408120805491995082918a906133989084906158fa565b909155506134099050565b5f6133ae85836158fa565b90506133c784896133bd610d11565b8492919087614477565b9850849150818e6009015f015f886001600160a01b03166001600160a01b031681526020019081526020015f205f82825461340291906158fa565b9091555050505b80896060015187815181106134205761342061581d565b60200260200101818152505050505050505b8061343c816159b4565b915050613247565b505f5b83518110156134d1575f846060015182815181106134675761346761581d565b602002602001015111156134c9576134c9858560600151838151811061348f5761348f61581d565b60200260200101518884815181106134a9576134a961581d565b60200260200101516001600160a01b0316613ab39092919063ffffffff16565b600101613447565b50836001600160a01b03167f86bcb277da75a9fbb738b8bb82beb731d82a0a89516b848730df92849f966bf08787866060015160405161351393929190615bd4565b60405180910390a250505050505050565b60208101515f906001600160401b031661354b64e8d4a51000613546856144d4565b614509565b610b019190615865565b5f81421061356457505f610b01565b5f83602001516001600160401b03164261357e91906158fa565b90505f8161358b866144d4565b6135959190615878565b855190915064e8d4a51000906135b4906001600160801b031683615878565b6135be91906158a3565b85516135d391906001600160801b03166158fa565b92505050610b01565b5f610d0a83836127106001612dad565b306001600160a01b037f0000000000000000000000008343a45d793688410a60d67ea17e8ce0ab3c2c2416148061367257507f0000000000000000000000008343a45d793688410a60d67ea17e8ce0ab3c2c246001600160a01b03166136665f80516020615d97833981519152546001600160a01b031690565b6001600160a01b031614155b15612eab5760405163703e46dd60e11b815260040160405180910390fd5b6130c2612e08565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156136f2575060408051601f3d908101601f191682019092526136ef91810190615982565b60015b61371a57604051634c9c8ce360e01b81526001600160a01b0383166004820152602401610d9a565b5f80516020615d97833981519152811461374a57604051632a87526960e21b815260048101829052602401610d9a565b610b79838361452b565b306001600160a01b037f0000000000000000000000008343a45d793688410a60d67ea17e8ce0ab3c2c241614612eab5760405163703e46dd60e11b815260040160405180910390fd5b6001600160a01b0381165f9081526001830160205260408120541515610d0a565b5f6137c7612bed565b6001600160a01b0385165f908152600782016020526040902054909150156138025760405163caf865c160e01b815260040160405180910390fd5b5f8160050184815481106138185761381861581d565b5f9182526020808320909101546001600160a01b0316808352600985019091526040909120549091501580159061384d575082155b1561386b576040516305ec751560e51b815260040160405180910390fd5b613876846001615865565b6001600160a01b0386165f908152600784016020526040902055600582018054869190869081106138a9576138a961581d565b5f9182526020918290200180546001600160a01b0319166001600160a01b03938416179055604080518484168152928816918301919091527f9e147d339c63698deb55c3d0d44ed3eba29bac2a068a88c4bc5bde17d6331e19910160405180910390a15050505050565b5f610d0a836001600160a01b038416614580565b5f80613932836122c3565b915061394661393f613b16565b83906135dc565b9050915091565b6139573384614663565b8015613975576001850154613975906001600160a01b031682614248565b61397f8285614248565b60408051848152602081018690526001600160a01b0384169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d791015b60405180910390a35050505050565b6001600160a01b0381165f908152600b8401602052604090205460ff1615613a0857604051631f160d3160e11b815260040160405180910390fd5b6001600160a01b0382165f908152600c8401602052604090205460ff1615613a4357604051632748f32960e21b815260040160405180910390fd5b6001600160a01b038181165f818152600b8601602090815260408083208054600160ff199182168117909255958816808552600c8a0190935281842080549096161790945592517fd6c91941062a66dc4c4344f6b10af4b565b256816a2f9080ba7f83e1d6a2bdc69190a3505050565b6040516001600160a01b038316602482015260448101829052610b7990849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261471c565b5f80613b20612bed565b8054604051636034d9f560e01b81523360048201529192506001600160a01b031690636034d9f590602401612d64565b5f610b01826001612cd1565b613b6687876147ed565b613b718686866148a2565b60408051838152602081018390526001600160a01b03808616929089169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a450505050505050565b6040516001600160a01b03808516602483015283166044820152606481018290526116c09085906323b872dd60e01b90608401613adf565b5f6001600160801b03821115613c655760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608401610d9a565b5090565b806001600160801b03165f03613c925760405163d11b25af60e01b815260040160405180910390fd5b613c9d838383613fbe565b6040516001600160801b03821681526001600160a01b038316907f693ffe037fd29f4846b006bd3ada57d4fd4c3622277227342f0e4fed9011dc2090602001612f51565b806001600160801b03165f03613d0a5760405163d11b25af60e01b815260040160405180910390fd5b613d15838383614c3b565b6040516001600160801b03821681526001600160a01b038316907f5f4e7177e0f8e013ddb6d29e468fa7a45f8df4e00e7895b7f20c5979cab21c6c90602001612f51565b5f610d0a613d6882600a615b76565b5f80516020615d7783398151915254613d819190615865565b613d89610874565b612d0c906001615865565b5f80613dae86613da587600a615b76565b8a919086612dad565b90508615613dd557613dcd613dc485600a615b76565b82908986612dad565b915050613dda565b5f9150505b9695505050505050565b5f610d0a836001600160a01b038416614d19565b613e00614d65565b6110188282614dae565b613e12614d65565b6130c281614dfe565b5f825f018281548110613e3057613e3061581d565b905f5260205f200154905092915050565b5f80516020615d578339815191526001600160a01b038516613e785760405163e602df0560e01b81525f6004820152602401610d9a565b6001600160a01b038416613ea157604051634a1406b160e11b81525f6004820152602401610d9a565b6001600160a01b038086165f908152600183016020908152604080832093881683529290522083905581156122bc57836001600160a01b0316856001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040516139be91815260200190565b5f80805f19858709858702925082811083820303915050805f03613f4c57838281613f4257613f4261588f565b0492505050610d0a565b808411613f57575f80fd5b5f8486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091025f889003889004909101858311909403939093029303949094049190911702949350505050565b6001600160a01b0382165f9081526001840160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b9004909216908201529061402082613524565b90505f614049846001600160801b031661403a8585613555565b6140449190615865565b613bfd565b6001600160801b0381168452905061406042614e81565b6001600160401b03166020808501919091526001600160a01b0386165f908152908790526040812080546001600160801b03871692906140a1908490615865565b909155505050506001600160a01b03929092165f9081526001939093016020908152604093849020835181549285015194909501516001600160801b039095166001600160c01b031990921691909117600160801b6001600160401b0394851602176001600160c01b0316600160c01b939094169290920292909217905550565b5f80516020615d578339815191526001600160a01b03841661415c5781816002015f8282546141519190615865565b909155506141b99050565b6001600160a01b0384165f908152602082905260409020548281101561419b5784818460405163391434e360e21b8152600401610d9a93929190615946565b6001600160a01b0385165f9081526020839052604090209083900390555b6001600160a01b0383166141d75760028101805483900390556141f5565b6001600160a01b0383165f9081526020829052604090208054830190555b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161423a91815260200190565b60405180910390a350505050565b6001600160a01b0382166142715760405163ec442f0560e01b81525f6004820152602401610d9a565b6110185f8383614122565b6001600160a01b0382166142a557604051634b637e8f60e11b81525f6004820152602401610d9a565b611018825f83614122565b6142d960405180608001604052805f8152602001606081526020015f8152602001606081525090565b5f6142e2612048565b90505f83519050604051806080016040528082815260200183815260200183518152602001826001600160401b0381111561431f5761431f615430565b604051908082528060200260200182016040528015614348578160200160208202803683370190505b509052949350505050565b5f5b81811015610b79575f614369826001615865565b90505b828110156143e0578381815181106143865761438661581d565b60200260200101516001600160a01b03168483815181106143a9576143a961581d565b60200260200101516001600160a01b0316036143d8576040516323271fb560e11b815260040160405180910390fd5b60010161436c565b50600101614355565b80806144065750816001600160a01b0316856001600160a01b0316145b6122bc575f805b8481101561445857866001600160a01b03168682815181106144315761443161581d565b60200260200101516001600160a01b0316036144505760019150614458565b60010161440d565b50806112c15760405163c1ab6dc160e01b815260040160405180910390fd5b5f8061448483600a615b76565b61448e8789615878565b61449891906158a3565b905084156144c857846144ac85600a615b76565b6144b69083615878565b6144c091906158a3565b915050612dff565b505f9695505050505050565b5f81604001516001600160401b03165f146144f35781604001516144fa565b64174876e8005b6001600160401b031692915050565b5f8160016145178286615865565b61452191906158fa565b610d0a91906158a3565b61453482614ee8565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a280511561457857610b798282614f4b565b611018614f70565b5f818152600183016020526040812054801561465a575f6145a26001836158fa565b85549091505f906145b5906001906158fa565b9050818114614614575f865f0182815481106145d3576145d361581d565b905f5260205f200154905080875f0184815481106145f3576145f361581d565b5f918252602080832090910192909255918252600188019052604090208390555b855486908061462557614625615c2e565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f905560019350505050610b01565b5f915050610b01565b5f61466c612bed565b9050614676610e52565b60405163e75b3ae760e01b81526001600160a01b03858116600483015260248201859052919091169063e75b3ae7906044015f604051808303815f87803b1580156146bf575f80fd5b505af11580156146d1573d5f803e3d5ffd5b5050505081816009015f015f6146e5610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f205f8282546147129190615865565b9091555050505050565b5f614770826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614f8f9092919063ffffffff16565b805190915015610b79578080602001905181019061478e9190615999565b610b795760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610d9a565b5f6147f6612bed565b9050614800610e52565b604051631062c15f60e11b81523060048201526001600160a01b0384811660248301526044820186905291909116906320c582be906064015f604051808303815f87803b15801561484f575f80fd5b505af1158015614861573d5f803e3d5ffd5b5050505082816009015f015f614875610e52565b6001600160a01b03166001600160a01b031681526020019081526020015f205f82825461471291906158fa565b5f6148ab612bed565b90505f6148b6612048565b80519091505f6148c860028501612c11565b90505f6148d58284615865565b6001600160401b038111156148ec576148ec615430565b604051908082528060200260200182016040528015614915578160200160208202803683370190505b5090505f6149238385615865565b6001600160401b0381111561493a5761493a615430565b604051908082528060200260200182016040528015614963578160200160208202803683370190505b5090505f5b84811015614a8e575f6149a08783815181106149865761498661581d565b602002602001015189600901612c1a90919063ffffffff16565b90506149ae8a828b5f612dad565b8483815181106149c0576149c061581d565b6020026020010181815250508682815181106149de576149de61581d565b60200260200101518383815181106149f8576149f861581d565b60200260200101906001600160a01b031690816001600160a01b031681525050838281518110614a2a57614a2a61581d565b6020026020010151886009015f015f898581518110614a4b57614a4b61581d565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f205f828254614a8091906158fa565b909155505050600101614968565b505f5b83811015614b86575f614aa48683615865565b90505f614ab460028a0184612cc6565b90505f614ac460098b0183612c1a565b9050614ad28c828d5f612dad565b868481518110614ae457614ae461581d565b60200260200101818152505081858481518110614b0357614b0361581d565b60200260200101906001600160a01b031690816001600160a01b031681525050858381518110614b3557614b3561581d565b60200260200101518a6009015f015f846001600160a01b03166001600160a01b031681526020019081526020015f205f828254614b7291906158fa565b909155505060019093019250614a91915050565b505f5b8151811015614bea57828181518110614ba457614ba461581d565b60200260200101515f14614be257614be28a848381518110614bc857614bc861581d565b60200260200101518484815181106134a9576134a961581d565b600101614b89565b50886001600160a01b03167f86bcb277da75a9fbb738b8bb82beb731d82a0a89516b848730df92849f966bf0898385604051614c2893929190615bd4565b60405180910390a2505050505050505050565b6001600160a01b0382165f9081526001840160209081526040808320815160608101835290546001600160801b03811682526001600160401b03600160801b8204811694830194909452600160c01b90049092169082015290614c9d82613524565b90505f614cc1846001600160801b0316614cb78585613555565b61404491906158fa565b6001600160801b03811684529050614cd842614e81565b6001600160401b03166020808501919091526001600160a01b0386165f908152908790526040812080546001600160801b03871692906140a19084906158fa565b5f818152600183016020526040812054614d5e57508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610b01565b505f610b01565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff16612eab57604051631afcd79f60e31b815260040160405180910390fd5b614db6614d65565b5f80516020615d578339815191527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace03614def8482615c86565b50600481016116c08382615c86565b614e06614d65565b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e005f80614e3284614f9d565b9150915081614e42576012614e44565b805b83546001600160a81b031916600160a01b60ff92909216919091026001600160a01b031916176001600160a01b0394909416939093179091555050565b5f6001600160401b03821115613c655760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203660448201526534206269747360d01b6064820152608401610d9a565b806001600160a01b03163b5f03614f1d57604051634c9c8ce360e01b81526001600160a01b0382166004820152602401610d9a565b5f80516020615d9783398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6060610d0a8383604051806060016040528060278152602001615db760279139615073565b3415612eab5760405163b398979f60e01b815260040160405180910390fd5b6060610b5084845f856150dd565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290515f918291829182916001600160a01b03871691614fe391615d40565b5f60405180830381855afa9150503d805f811461501b576040519150601f19603f3d011682016040523d82523d5f602084013e615020565b606091505b509150915081801561503457506020815110155b15615067575f8180602001905181019061504e9190615982565b905060ff8111615065576001969095509350505050565b505b505f9485945092505050565b60605f80856001600160a01b03168560405161508f9190615d40565b5f60405180830381855af49150503d805f81146150c7576040519150601f19603f3d011682016040523d82523d5f602084013e6150cc565b606091505b5091509150613dda868383876151b4565b60608247101561513e5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610d9a565b5f80866001600160a01b031685876040516151599190615d40565b5f6040518083038185875af1925050503d805f8114615193576040519150601f19603f3d011682016040523d82523d5f602084013e615198565b606091505b50915091506151a9878383876151b4565b979650505050505050565b606083156152225782515f0361521b576001600160a01b0385163b61521b5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610d9a565b5081610b50565b610b5083838151156152375781518083602001fd5b8060405162461bcd60e51b8152600401610d9a91905b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f60208284031215615292575f80fd5b5035919050565b6001600160a01b03811681146130c2575f80fd5b5f80604083850312156152be575f80fd5b82356152c981615299565b946020939093013593505050565b6001600160401b03811681146130c2575f80fd5b5f80604083850312156152fc575f80fd5b823561530781615299565b91506020830135615317816152d7565b809150509250929050565b5f60208284031215615332575f80fd5b8135610d0a81615299565b5f805f6060848603121561534f575f80fd5b833561535a81615299565b9250602084013561536a81615299565b929592945050506040919091013590565b5f8083601f84011261538b575f80fd5b5081356001600160401b038111156153a1575f80fd5b6020830191508360208260051b85010111156153bb575f80fd5b9250929050565b5f805f805f608086880312156153d6575f80fd5b8535945060208601356001600160401b038111156153f2575f80fd5b6153fe8882890161537b565b909550935050604086013561541281615299565b9150606086013561542281615299565b809150509295509295909350565b634e487b7160e01b5f52604160045260245ffd5b5f8060408385031215615455575f80fd5b823561546081615299565b915060208301356001600160401b0381111561547a575f80fd5b8301601f8101851361548a575f80fd5b80356001600160401b038111156154a3576154a3615430565b604051601f8201601f19908116603f011681016001600160401b03811182821017156154d1576154d1615430565b6040528181528282016020018710156154e8575f80fd5b816020840160208301375f602083830101528093505050509250929050565b80151581146130c2575f80fd5b5f805f60608486031215615526575f80fd5b833561553181615299565b92506020840135615541816152d7565b9150604084013561555181615507565b809150509250925092565b5f806040838503121561556d575f80fd5b82359150602083013561531781615299565b5f8060208385031215615590575f80fd5b82356001600160401b038111156155a5575f80fd5b6155b18582860161537b565b90969095509350505050565b602080825282518282018190525f918401906040840190835b818110156155f45783518352602093840193909201916001016155d6565b509095945050505050565b5f805f60608486031215615611575f80fd5b833561561c81615299565b9250602084013561554181615299565b5f805f806040858703121561563f575f80fd5b84356001600160401b03811115615654575f80fd5b6156608782880161537b565b90955093505060208501356001600160401b0381111561567e575f80fd5b61568a8782880161537b565b95989497509550505050565b5f602082840312156156a6575f80fd5b81356001600160401b038111156156bb575f80fd5b820160a08185031215610d0a575f80fd5b5f805f606084860312156156de575f80fd5b8335925060208401356156f081615299565b9150604084013561555181615299565b5f8151808452602084019350602083015f5b828110156157395781516001600160a01b0316865260209586019590910190600101615712565b5093949350505050565b602081525f610d0a6020830184615700565b5f805f60608486031215615767575f80fd5b833561577281615299565b925060208401359150604084013561555181615299565b5f806040838503121561579a575f80fd5b82356157a581615299565b9150602083013561531781615299565b5f805f606084860312156157c7575f80fd5b83356157d281615299565b95602085013595506040909401359392505050565b5f602082840312156157f7575f80fd5b81356001600160401b0381111561580c575f80fd5b820160e08185031215610d0a575f80fd5b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215615841575f80fd5b815160ff81168114610d0a575f80fd5b634e487b7160e01b5f52601160045260245ffd5b80820180821115610b0157610b01615851565b8082028115828204841417610b0157610b01615851565b634e487b7160e01b5f52601260045260245ffd5b5f826158bd57634e487b7160e01b5f52601260045260245ffd5b500490565b600181811c908216806158d657607f821691505b6020821081036158f457634e487b7160e01b5f52602260045260245ffd5b50919050565b81810381811115610b0157610b01615851565b5f61ffff821661ffff810361592457615924615851565b60010192915050565b60ff8181168382160190811115610b0157610b01615851565b6001600160a01b039390931683526020830191909152604082015260600190565b5f60208284031215615977575f80fd5b8151610d0a81615299565b5f60208284031215615992575f80fd5b5051919050565b5f602082840312156159a9575f80fd5b8151610d0a81615507565b5f600182016159c5576159c5615851565b5060010190565b5f602082840312156159dc575f80fd5b8135610d0a81615507565b5f808335601e198436030181126159fc575f80fd5b8301803591506001600160401b03821115615a15575f80fd5b6020019150368190038213156153bb575f80fd5b6001600160a01b03868116825260208201869052841660408201526080606082018190528101829052818360a08301375f81830160a090810191909152601f909201601f19160101949350505050565b5f600160ff1b8201615a8d57615a8d615851565b505f0390565b6001815b6001841115615ace57808504811115615ab257615ab2615851565b6001841615615ac057908102905b60019390931c928002615a97565b935093915050565b5f82615ae457506001610b01565b81615af057505f610b01565b8160018114615b065760028114615b1057615b2c565b6001915050610b01565b60ff841115615b2157615b21615851565b50506001821b610b01565b5060208310610133831016604e8410600b8410161715615b4f575081810a610b01565b615b5b5f198484615a93565b805f1904821115615b6e57615b6e615851565b029392505050565b5f610d0a60ff841683615ad6565b5f60208284031215615b94575f80fd5b815161ffff81168114610d0a575f80fd5b634e487b7160e01b5f52602160045260245ffd5b5f60208284031215615bc9575f80fd5b8151610d0a816152d7565b838152606060208201525f615bec6060830185615700565b8281036040840152835180825260208086019201905f5b81811015615c21578351835260209384019390920191600101615c03565b5090979650505050505050565b634e487b7160e01b5f52603160045260245ffd5b601f821115610b7957805f5260205f20601f840160051c81016020851015615c675750805b601f840160051c820191505b818110156122bc575f8155600101615c73565b81516001600160401b03811115615c9f57615c9f615430565b615cb381615cad84546158c2565b84615c42565b6020601f821160018114615ce5575f8315615cce5750848201515b5f19600385901b1c1916600184901b1784556122bc565b5f84815260208120601f198516915b82811015615d145787850151825560209485019460019092019101615cf4565b5084821015615d3157868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b5f82518060208501845e5f92019182525091905056fe52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace02360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220c0e2a3c0a969483070b6abd693c642c5c25a42fc7bbaf88c41046f1fbe1b77cb64736f6c634300081a0033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
Loading...
Loading
[ 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.