More Info
Private Name Tags
ContractCreator
TokenTracker
Latest 24 from a total of 24 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Request Deposit | 38955280 | 54 days ago | IN | 0 ETH | 0.00000042 | ||||
| Claim Shares And... | 38954587 | 54 days ago | IN | 0 ETH | 0.00000043 | ||||
| Claim Shares And... | 38954578 | 54 days ago | IN | 0 ETH | 0.00000062 | ||||
| Request Deposit | 38954432 | 54 days ago | IN | 0 ETH | 0.00000042 | ||||
| Request Deposit | 38954170 | 54 days ago | IN | 0 ETH | 0.00000078 | ||||
| Request Deposit | 38954163 | 54 days ago | IN | 0 ETH | 0.00000078 | ||||
| Claim Shares And... | 38954011 | 54 days ago | IN | 0 ETH | 0.00000048 | ||||
| Request Deposit | 38953885 | 54 days ago | IN | 0 ETH | 0.00000076 | ||||
| Request Deposit | 38953819 | 54 days ago | IN | 0 ETH | 0.00000129 | ||||
| Claim Shares And... | 38902314 | 55 days ago | IN | 0 ETH | 0.00000108 | ||||
| Redeem | 38901801 | 55 days ago | IN | 0 ETH | 0.00000039 | ||||
| Request Deposit | 38816835 | 57 days ago | IN | 0 ETH | 0.00000015 | ||||
| Claim Shares And... | 38784854 | 58 days ago | IN | 0 ETH | 0.00000014 | ||||
| Request Deposit | 38782375 | 58 days ago | IN | 0 ETH | 0.00000049 | ||||
| Claim Shares And... | 38782223 | 58 days ago | IN | 0 ETH | 0.00000033 | ||||
| Claim Shares And... | 38782164 | 58 days ago | IN | 0 ETH | 0.00000031 | ||||
| Request Deposit | 38782092 | 58 days ago | IN | 0 ETH | 0.00000042 | ||||
| Request Deposit | 38781970 | 58 days ago | IN | 0 ETH | 0.00000053 | ||||
| Request Deposit | 38781914 | 58 days ago | IN | 0 ETH | 0.00000112 | ||||
| Claim Shares And... | 38781842 | 58 days ago | IN | 0 ETH | 0.00000042 | ||||
| Request Deposit | 38781677 | 58 days ago | IN | 0 ETH | 0.00000039 | ||||
| Claim Shares And... | 38781562 | 58 days ago | IN | 0 ETH | 0.0000007 | ||||
| Request Deposit | 38781293 | 58 days ago | IN | 0 ETH | 0.00000071 | ||||
| Initialize | 38781114 | 58 days ago | IN | 0 ETH | 0.00000075 |
Latest 1 internal transaction
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 38781114 | 58 days ago | Contract Creation | 0 ETH |
Cross-Chain Transactions
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x6E9aBD15...604704404 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {ERC7540} from "./ERC7540.sol";
import {FeeManager} from "./FeeManager.sol";
import {Roles} from "./Roles.sol";
import {Whitelistable} from "./Whitelistable.sol";
import {State} from "./primitives/Enums.sol";
import {
CantDepositNativeToken,
Closed,
ERC7540InvalidOperator,
NotClosing,
NotOpen,
NotWhitelisted,
OnlyAsyncDepositAllowed,
OnlySyncDepositAllowed,
ValuationUpdateNotAllowed
} from "./primitives/Errors.sol";
import {DepositSync, Referral, StateUpdated} from "./primitives/Events.sol";
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {ERC4626Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {FeeRegistry} from "../protocol/FeeRegistry.sol";
using SafeERC20 for IERC20;
/// @custom:storage-definition erc7201:hopper.storage.vault
/// @param underlying The address of the underlying asset.
/// @param name The name of the vault and by extension the ERC20 token.
/// @param symbol The symbol of the vault and by extension the ERC20 token.
/// @param safe The address of the safe smart contract.
/// @param whitelistManager The address of the whitelist manager.
/// @param valuationManager The address of the valuation manager.
/// @param admin The address of the owner of the vault.
/// @param feeReceiver The address of the fee receiver.
/// @param feeRegistry The address of the fee registry.
/// @param wrappedNativeToken The address of the wrapped native token.
/// @param managementRate The management fee rate.
/// @param performanceRate The performance fee rate.
/// @param rateUpdateCooldown The cooldown period for updating the fee rates.
/// @param enableWhitelist A boolean indicating whether the whitelist is enabled.
struct InitStruct {
IERC20 underlying;
string name;
string symbol;
address safe;
address whitelistManager;
address valuationManager;
address admin;
address feeReceiver;
uint16 managementRate;
uint16 performanceRate;
bool enableWhitelist;
uint256 rateUpdateCooldown;
}
/// @custom:oz-upgrades-from src/v0.4.0/Vault.sol:Vault
contract Vault is ERC7540, Whitelistable, FeeManager {
/// @custom:storage-location erc7201:hopper.storage.vault
/// @param newTotalAssets The new total assets of the vault. It is used to update the totalAssets variable.
/// @param state The state of the vault. It can be Open, Closing, or Closed.
struct VaultStorage {
State state;
}
// keccak256(abi.encode(uint256(keccak256("hopper.storage.vault")) - 1)) & ~bytes32(uint256(0xff))
/// @custom:slot erc7201:hopper.storage.vault
// solhint-disable-next-line const-name-snakecase
bytes32 private constant vaultStorage = 0x0e6b3200a60a991c539f47dddaca04a18eb4bcf2b53906fb44751d827f001400;
/// @notice Returns the storage struct of the vault.
/// @return _vaultStorage The storage struct of the vault.
function _getVaultStorage() internal pure returns (VaultStorage storage _vaultStorage) {
// solhint-disable-next-line no-inline-assembly
assembly {
_vaultStorage.slot := vaultStorage
}
}
/// @custom:oz-upgrades-unsafe-allow constructor
// solhint-disable-next-line ignoreConstructors
constructor(
bool disable
) {
if (disable) _disableInitializers();
}
/// @notice Initializes the vault.
/// @param data The encoded initialization parameters of the vault.
function initialize(
bytes memory data,
address feeRegistry,
address wrappedNativeToken
) public virtual initializer {
InitStruct memory init = abi.decode(data, (InitStruct));
__Ownable_init(init.admin); // initial vault owner
__Roles_init(
Roles.RolesStorage({
whitelistManager: init.whitelistManager,
feeReceiver: init.feeReceiver,
safe: init.safe,
feeRegistry: FeeRegistry(feeRegistry),
valuationManager: init.valuationManager
})
);
__ERC20_init(init.name, init.symbol);
__ERC20Pausable_init();
__ERC4626_init(init.underlying);
__ERC7540_init(init.underlying, wrappedNativeToken);
__Whitelistable_init(init.enableWhitelist);
__FeeManager_init(
feeRegistry,
init.managementRate,
init.performanceRate,
IERC20Metadata(address(init.underlying)).decimals(),
init.rateUpdateCooldown
);
emit StateUpdated(State.Open);
}
/////////////////////
// ## MODIFIERS ## //
/////////////////////
/// @notice Reverts if the vault is not open.
modifier onlyOpen() {
State _state = _getVaultStorage().state;
if (_state != State.Open) revert NotOpen(_state);
_;
}
/// @notice Reverts if the vault is not closing.
modifier onlyClosing() {
State _state = _getVaultStorage().state;
if (_state != State.Closing) revert NotClosing(_state);
_;
}
// @notice Reverts if totalAssets is expired.
modifier onlySyncDeposit() {
// if total assets is not valid we can only do asynchronous deposit
if (!isTotalAssetsValid()) {
revert OnlyAsyncDepositAllowed();
}
_;
}
// @notice Reverts if totalAssets is valid.
modifier onlyAsyncDeposit() {
// if total assets is valid we can only do synchronous deposit
if (isTotalAssetsValid()) {
revert OnlySyncDepositAllowed();
}
_;
}
/////////////////////////////////////////////
// ## DEPOSIT AND REDEEM FLOW FUNCTIONS ## //
/////////////////////////////////////////////
/// @param assets The amount of assets to deposit.
/// @param controller The address of the controller involved in the deposit request.
/// @param owner The address of the owner for whom the deposit is requested.
function requestDeposit(
uint256 assets,
address controller,
address owner
) public payable override onlyOperator(owner) whenNotPaused onlyAsyncDeposit returns (uint256 requestId) {
if (!isWhitelisted(owner)) revert NotWhitelisted();
return _requestDeposit(assets, controller, owner);
}
/// @notice Requests a deposit of assets, subject to whitelist validation.
/// @param assets The amount of assets to deposit.
/// @param controller The address of the controller involved in the deposit request.
/// @param owner The address of the owner for whom the deposit is requested.
/// @param referral The address who referred the deposit.
function requestDeposit(
uint256 assets,
address controller,
address owner,
address referral
) public payable onlyOperator(owner) whenNotPaused onlyAsyncDeposit returns (uint256 requestId) {
if (!isWhitelisted(owner)) revert NotWhitelisted();
requestId = _requestDeposit(assets, controller, owner);
emit Referral(referral, owner, requestId, assets);
}
/// @notice Deposit in a sychronous fashion into the vault.
/// @param assets The assets to deposit.
/// @param receiver The receiver of the shares.
/// @return shares The resulting shares.
function syncDeposit(
uint256 assets,
address receiver,
address referral
) public payable onlySyncDeposit onlyOpen returns (uint256 shares) {
ERC7540Storage storage $ = _getERC7540Storage();
if (!isWhitelisted(msg.sender)) revert NotWhitelisted();
if (msg.value != 0) {
// if user sends eth and the underlying is wETH we will wrap it for him
if (asset() == address($.wrappedNativeToken)) {
assets = msg.value;
// we do not send directly eth in case the safe is not payable
$.pendingSilo.depositEth{value: assets}();
IERC20(asset()).safeTransferFrom(address($.pendingSilo), safe(), assets);
} else {
revert CantDepositNativeToken();
}
} else {
IERC20(asset()).safeTransferFrom(msg.sender, safe(), assets);
}
shares = _convertToShares(assets, Math.Rounding.Floor);
$.totalAssets += assets;
_mint(receiver, shares);
emit DepositSync(msg.sender, receiver, assets, shares);
emit Referral(referral, msg.sender, 0, assets);
}
/// @notice Requests the redemption of tokens, subject to whitelist validation.
/// @param shares The number of tokens to redeem.
/// @param controller The address of the controller involved in the redemption request.
/// @param owner The address of the token owner requesting redemption.
/// @return requestId The id of the redeem request.
function requestRedeem(
uint256 shares,
address controller,
address owner
) public onlyOpen whenNotPaused returns (uint256 requestId) {
if (!isWhitelisted(owner)) revert NotWhitelisted();
return _requestRedeem(shares, controller, owner);
}
/// @notice Function to bundle a claim of shares and a request redeem. It can be convenient for UX.
/// @dev if claimable == 0, it has the same behavior as requestRedeem function.
/// @dev if claimable > 0, user shares follow this path: vault --> user ; user --> pendingSilo
function claimSharesAndRequestRedeem(
uint256 sharesToRedeem
) public onlyOpen whenNotPaused returns (uint40 requestId) {
if (!isWhitelisted(msg.sender)) revert NotWhitelisted();
uint256 claimable = claimableDepositRequest(0, msg.sender);
if (claimable > 0) _deposit(claimable, msg.sender, msg.sender);
uint256 redeemId = _requestRedeem(sharesToRedeem, msg.sender, msg.sender);
return uint40(redeemId);
}
/// @dev Unusable when paused.
/// @dev First _withdraw path: whenNotPaused via ERC20Pausable._update.
/// @dev Second _withdraw path: whenNotPaused in ERC7540.
function withdraw(
uint256 assets,
address receiver,
address controller
) public override(ERC4626Upgradeable, IERC4626) whenNotPaused returns (uint256 shares) {
VaultStorage storage $ = _getVaultStorage();
if ($.state == State.Closed && claimableRedeemRequest(0, controller) == 0) {
shares = _convertToShares(assets, Math.Rounding.Ceil);
_withdraw(msg.sender, receiver, controller, assets, shares); // sync
} else {
if (controller != msg.sender && !isOperator(controller, msg.sender)) {
revert ERC7540InvalidOperator();
}
return _withdraw(assets, receiver, controller); // async
}
}
/// @dev Unusable when paused.
/// @dev First _withdraw path: whenNotPaused via ERC20Pausable._update.
/// @dev Second _withdraw path: whenNotPaused in ERC7540.
/// @notice Claim assets from the vault. After a request is made and settled.
/// @param shares The amount shares to convert into assets.
/// @param receiver The receiver of the assets.
/// @param controller The controller, who owns the redeem request.
/// @return assets The corresponding assets.
function redeem(
uint256 shares,
address receiver,
address controller
) public override(ERC4626Upgradeable, IERC4626) whenNotPaused returns (uint256 assets) {
VaultStorage storage $ = _getVaultStorage();
if ($.state == State.Closed && claimableRedeemRequest(0, controller) == 0) {
assets = _convertToAssets(shares, Math.Rounding.Floor);
_withdraw(msg.sender, receiver, controller, assets, shares);
} else {
if (controller != msg.sender && !isOperator(controller, msg.sender)) {
revert ERC7540InvalidOperator();
}
return _redeem(shares, receiver, controller);
}
}
/// @dev override ERC4626 synchronous withdraw; called only when vault is closed
/// @param caller The address of the caller.
/// @param receiver The address of the receiver of the assets.
/// @param owner The address of the owner of the shares.
/// @param assets The amount of assets to withdraw.
/// @param shares The amount of shares to burn.
function _withdraw(
address caller,
address receiver,
address owner,
uint256 assets,
uint256 shares
) internal virtual override {
if (caller != owner && !isOperator(owner, caller)) {
_spendAllowance(owner, caller, shares);
}
_getERC7540Storage().totalAssets -= assets;
_burn(owner, shares);
IERC20(asset()).safeTransfer(receiver, assets);
emit Withdraw(caller, receiver, owner, assets, shares);
}
/// @notice Claims all available shares for a list of controller addresses.
/// @dev Iterates over each controller address, checks for claimable deposits, and deposits them on their behalf.
/// @param controllers The list of controller addresses for which to claim shares.
function claimSharesOnBehalf(
address[] memory controllers
) external onlySafe {
for (uint256 i = 0; i < controllers.length; i++) {
uint256 claimable = claimableDepositRequest(0, controllers[i]);
if (claimable > 0) {
_deposit(claimable, controllers[i], controllers[i]);
}
}
}
/// @notice Sends assets to users who already have a claimable redemption,
/// so they don't need to call redeem() themselves. Processes in batch.
/// @dev Only the Safe can call this; it respects the vault's paused state.
/// @param controllers The list of controller addresses for which to redeem.
function redeemOnBehalf(
address[] memory controllers
) external onlySafe whenNotPaused {
for (uint256 i = 0; i < controllers.length; i++) {
uint256 claimable = claimableRedeemRequest(0, controllers[i]);
if (claimable > 0) {
// receiver = controller by default
_redeem(claimable, controllers[i], controllers[i]);
}
}
}
///////////////////////////////////////////////////////
// ## VALUATION UPDATING AND SETTLEMENT FUNCTIONS ## //
///////////////////////////////////////////////////////
function updateTotalAssetsLifespan(
uint128 lifespan
) external onlySafe {
_updateTotalAssetsLifespan(lifespan);
}
/// @notice Function to propose a new valuation for the vault.
/// @notice It can only be called by the ValueManager.
/// @param _newTotalAssets The new total assets of the vault.
function updateNewTotalAssets(
uint256 _newTotalAssets
) public onlyValuationManager {
if (_getVaultStorage().state == State.Closed) revert Closed();
// if totalAssets is not expired yet it means syncDeposit are allowed
// in this case we do not allow onlyValuationManager to propose a new nav
// he must call unvalidateTotalAssets first.
if (isTotalAssetsValid()) {
revert ValuationUpdateNotAllowed();
}
_updateNewTotalAssets(_newTotalAssets);
}
/// @notice Settles deposit requests, integrates user funds into the vault strategy, and enables share claims.
/// If possible, it also settles redeem requests.
/// @dev Unusable when paused, protected by whenNotPaused in _updateTotalAssets.
function settleDeposit(
uint256 _newTotalAssets
) public override onlySafe onlyOpen {
_updateTotalAssetsAndTakeFees(_newTotalAssets);
_settleDeposit(msg.sender);
_settleRedeem(msg.sender); // if it is possible to settleRedeem, we should do so
}
/// @notice Settles redeem requests, only callable by the safe.
/// @dev Unusable when paused, protected by whenNotPaused in _updateTotalAssets.
/// @dev After updating totalAssets, it takes fees, updates highWaterMark and finally settles redeem requests.
/// @inheritdoc ERC7540
function settleRedeem(
uint256 _newTotalAssets
) public override onlySafe onlyOpen {
_updateTotalAssetsAndTakeFees(_newTotalAssets);
_settleRedeem(msg.sender);
}
/// @notice Settles deposit requests, integrates user funds into the vault strategy, and enables share claims.
/// If possible, it also settles redeem requests.
/// @dev Unusable when paused, protected by whenNotPaused in _updateTotalAssets.
function _updateTotalAssetsAndTakeFees(
uint256 _newTotalAssets
) internal {
RolesStorage storage $roles = _getRolesStorage();
_updateTotalAssets(_newTotalAssets);
_takeFees($roles.feeReceiver, $roles.feeRegistry.protocolFeeReceiver());
}
/////////////////////////////
// ## CLOSING FUNCTIONS ## //
/////////////////////////////
/// @notice Initiates the closing of the vault. Can only be called by the owner.
/// @dev we make sure that initiate closing will make an epoch changement if the variable newTotalAssets is
/// "defined"
/// @dev (!= type(uint256).max). This guarantee that no userShares will be locked in a pending state.
function initiateClosing() external onlyOwner onlyOpen {
ERC7540Storage storage $ = _getERC7540Storage();
if ($.newTotalAssets != type(uint256).max) {
_updateNewTotalAssets($.newTotalAssets);
}
_getVaultStorage().state = State.Closing;
emit StateUpdated(State.Closing);
}
/// @notice Closes the vault, only redemption and withdrawal are allowed after this. Can only be called by the safe.
/// @dev Users can still requestDeposit but it can't be settled.
function close(
uint256 _newTotalAssets
) external onlySafe onlyClosing {
RolesStorage storage $roles = _getRolesStorage();
_updateTotalAssets(_newTotalAssets);
_takeFees($roles.feeReceiver, $roles.feeRegistry.protocolFeeReceiver());
_settleDeposit(msg.sender);
_settleRedeem(msg.sender);
_getVaultStorage().state = State.Closed;
// Transfer will fail if there are not enough assets inside the safe, making sure that redeem requests are
// fulfilled
IERC20(asset()).safeTransferFrom(msg.sender, address(this), _getERC7540Storage().totalAssets);
emit StateUpdated(State.Closed);
}
/////////////////////////////////
// ## PAUSABILITY FUNCTIONS ## //
/////////////////////////////////
/// @notice Halts core operations of the vault. Can only be called by the owner.
/// @notice Core operations include deposit, redeem, withdraw, any type of request, settles deposit and redeem and
/// newTotalAssets update.
function pause() public onlyOwner {
_pause();
}
/// @notice Resumes core operations of the vault. Can only be called by the owner.
function unpause() public onlyOwner {
_unpause();
}
function expireTotalAssets() public onlySafe {
_getERC7540Storage().totalAssetsExpiration = 0;
}
// MAX FUNCTIONS OVERRIDE //
/// @notice Returns the maximum redeemable shares for a controller.
/// @param controller The controller.
/// @return shares The maximum redeemable shares.
/// @dev When the vault is closed, users may claim there assets (erc7540.redeem style) or redeem there assets in a
/// sync manner.
/// this is why when they have nothing to claim and the vault is closed, we return their shares balance
function maxRedeem(
address controller
) public view override(IERC4626, ERC4626Upgradeable) returns (uint256) {
if (paused()) return 0;
uint256 shares = claimableRedeemRequest(0, controller);
if (shares == 0 && _getVaultStorage().state == State.Closed) {
// controller has no redeem claimable, we will use the synchronous flow
return balanceOf(controller);
}
return shares;
}
/// @notice Returns the amount of assets a controller will get if he redeem.
/// @param controller The controller.
/// @return The maximum amount of assets to get.
/// @dev This is the same philosophy as maxRedeem, except that we take care to convertToAssets the value before
/// returning it
function maxWithdraw(
address controller
) public view override(IERC4626, ERC4626Upgradeable) returns (uint256) {
if (paused()) return 0;
uint256 shares = claimableRedeemRequest(0, controller);
if (shares == 0 && _getVaultStorage().state == State.Closed) {
// controller has no redeem claimable, we will use the synchronous flow
return convertToAssets(balanceOf(controller));
}
uint256 lastRedeemId = _getERC7540Storage().lastRedeemRequestId[controller];
return convertToAssets(shares, lastRedeemId);
}
/// @notice Returns the amount of assets a controller will get if he redeem.
/// @param controller address to check
/// @dev If the contract is paused no deposit/claims are possible.
function maxDeposit(
address controller
) public view override(IERC4626, ERC4626Upgradeable) returns (uint256) {
if (paused()) return 0;
return claimableDepositRequest(0, controller);
}
/// @notice Returns the amount of sharres a controller will get if he calls Deposit.
/// @param controller The controller.
/// @dev If the contract is paused no deposit/claims are possible.
/// @dev We read the claimableDepositRequest of the controller then convert it to shares using the
/// convertToShares
/// of the related epochId
/// @return The maximum amount of shares to get.
function maxMint(
address controller
) public view override(IERC4626, ERC4626Upgradeable) returns (uint256) {
if (paused()) return 0;
uint256 lastDepositId = _getERC7540Storage().lastDepositRequestId[controller];
uint256 claimable = claimableDepositRequest(lastDepositId, controller);
return convertToShares(claimable, lastDepositId);
}
function isTotalAssetsValid() public view returns (bool) {
return block.timestamp < _getERC7540Storage().totalAssetsExpiration;
}
function safe() public view override returns (address) {
return _getRolesStorage().safe;
}
function version() public pure returns (string memory) {
return "v0.5.0";
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {OwnableUpgradeable} from "./OwnableUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This extension of the {Ownable} contract includes a two-step mechanism to transfer
* ownership, where the new owner must call {acceptOwnership} in order to replace the
* old one. This can help prevent common mistakes, such as transfers of ownership to
* incorrect accounts, or to contracts that are unable to interact with the
* permission system.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable2Step
struct Ownable2StepStorage {
address _pendingOwner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable2Step")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant Ownable2StepStorageLocation = 0x237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c00;
function _getOwnable2StepStorage() private pure returns (Ownable2StepStorage storage $) {
assembly {
$.slot := Ownable2StepStorageLocation
}
}
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
function __Ownable2Step_init() internal onlyInitializing {
}
function __Ownable2Step_init_unchained() internal onlyInitializing {
}
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
Ownable2StepStorage storage $ = _getOwnable2StepStorage();
return $._pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
Ownable2StepStorage storage $ = _getOwnable2StepStorage();
$._pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
Ownable2StepStorage storage $ = _getOwnable2StepStorage();
delete $._pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable
struct OwnableStorage {
address _owner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
assembly {
$.slot := OwnableStorageLocation
}
}
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
function __Ownable_init(address initialOwner) internal onlyInitializing {
__Ownable_init_unchained(initialOwner);
}
function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
OwnableStorage storage $ = _getOwnableStorage();
return $._owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
OwnableStorage storage $ = _getOwnableStorage();
address oldOwner = $._owner;
$._owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.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 reinitialization) 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 Pointer to storage slot. Allows integrators to override it with a custom storage location.
*
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
*/
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
return INITIALIZABLE_STORAGE;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
bytes32 slot = _initializableStorageSlot();
assembly {
$.slot := slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.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}.
*
* Both 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;
}
/// @inheritdoc IERC20
function totalSupply() public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._totalSupply;
}
/// @inheritdoc IERC20
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;
}
/// @inheritdoc IERC20
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 v5.1.0) (token/ERC20/extensions/ERC20Pausable.sol)
pragma solidity ^0.8.20;
import {ERC20Upgradeable} from "../ERC20Upgradeable.sol";
import {PausableUpgradeable} from "../../../utils/PausableUpgradeable.sol";
import {Initializable} from "../../../proxy/utils/Initializable.sol";
/**
* @dev ERC-20 token with pausable token transfers, minting and burning.
*
* Useful for scenarios such as preventing trades until the end of an evaluation
* period, or having an emergency switch for freezing all token transfers in the
* event of a large bug.
*
* IMPORTANT: This contract does not include public pause and unpause functions. In
* addition to inheriting this contract, you must define both functions, invoking the
* {Pausable-_pause} and {Pausable-_unpause} internal functions, with appropriate
* access control, e.g. using {AccessControl} or {Ownable}. Not doing so will
* make the contract pause mechanism of the contract unreachable, and thus unusable.
*/
abstract contract ERC20PausableUpgradeable is Initializable, ERC20Upgradeable, PausableUpgradeable {
function __ERC20Pausable_init() internal onlyInitializing {
}
function __ERC20Pausable_init_unchained() internal onlyInitializing {
}
/**
* @dev See {ERC20-_update}.
*
* Requirements:
*
* - the contract must not be paused.
*/
function _update(address from, address to, uint256 value) internal virtual override whenNotPaused {
super._update(from, to, value);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.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:ROOT: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 ok, uint8 assetDecimals) {
(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();
}
/// @inheritdoc IERC4626
function asset() public view virtual returns (address) {
ERC4626Storage storage $ = _getERC4626Storage();
return address($._asset);
}
/// @inheritdoc IERC4626
function totalAssets() public view virtual returns (uint256) {
return IERC20(asset()).balanceOf(address(this));
}
/// @inheritdoc IERC4626
function convertToShares(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Floor);
}
/// @inheritdoc IERC4626
function convertToAssets(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Floor);
}
/// @inheritdoc IERC4626
function maxDeposit(address) public view virtual returns (uint256) {
return type(uint256).max;
}
/// @inheritdoc IERC4626
function maxMint(address) public view virtual returns (uint256) {
return type(uint256).max;
}
/// @inheritdoc IERC4626
function maxWithdraw(address owner) public view virtual returns (uint256) {
return _convertToAssets(balanceOf(owner), Math.Rounding.Floor);
}
/// @inheritdoc IERC4626
function maxRedeem(address owner) public view virtual returns (uint256) {
return balanceOf(owner);
}
/// @inheritdoc IERC4626
function previewDeposit(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Floor);
}
/// @inheritdoc IERC4626
function previewMint(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Ceil);
}
/// @inheritdoc IERC4626
function previewWithdraw(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Ceil);
}
/// @inheritdoc IERC4626
function previewRedeem(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Floor);
}
/// @inheritdoc IERC4626
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;
}
/// @inheritdoc IERC4626
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;
}
/// @inheritdoc IERC4626
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;
}
/// @inheritdoc IERC4626
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.
*/
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 {
// 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(IERC20(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 {
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(IERC20(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 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.3.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Pausable
struct PausableStorage {
bool _paused;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300;
function _getPausableStorage() private pure returns (PausableStorage storage $) {
assembly {
$.slot := PausableStorageLocation
}
}
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
function __Pausable_init() internal onlyInitializing {
}
function __Pausable_init_unchained() internal onlyInitializing {
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
PausableStorage storage $ = _getPausableStorage();
return $._paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
PausableStorage storage $ = _getPausableStorage();
$._paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
PausableStorage storage $ = _getPausableStorage();
$._paused = false;
emit Unpaused(_msgSender());
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/draft-IERC6093.sol)
pragma solidity >=0.8.4;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC4626.sol)
pragma solidity >=0.6.2;
import {IERC20} from "../token/ERC20/IERC20.sol";
import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";
/**
* @dev Interface of the ERC-4626 "Tokenized Vault Standard", as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*/
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 redemption 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 v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity >=0.6.2;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Return the 512-bit addition of two uint256.
*
* The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.
*/
function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
assembly ("memory-safe") {
low := add(a, b)
high := lt(low, a)
}
}
/**
* @dev Return the 512-bit multiplication of two uint256.
*
* The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.
*/
function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
// 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = high * 2²⁵⁶ + low.
assembly ("memory-safe") {
let mm := mulmod(a, b, not(0))
low := mul(a, b)
high := sub(sub(mm, low), lt(mm, low))
}
}
/**
* @dev Returns the addition of two unsigned integers, with a success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
success = c >= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a - b;
success = c <= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a * b;
assembly ("memory-safe") {
// Only true when the multiplication doesn't overflow
// (c / a == b) || (a == 0)
success := or(eq(div(c, a), b), iszero(a))
}
// equivalent to: success ? c : 0
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `DIV` opcode returns zero when the denominator is 0.
result := div(a, b)
}
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `MOD` opcode returns zero when the denominator is 0.
result := mod(a, b)
}
}
}
/**
* @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryAdd(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.
*/
function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {
(, uint256 result) = trySub(a, b);
return result;
}
/**
* @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryMul(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
// Handle non-overflow cases, 256 by 256 division.
if (high == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return low / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= high) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [high low].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
high := sub(high, gt(remainder, low))
low := sub(low, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly ("memory-safe") {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [high low] by twos.
low := div(low, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from high into low.
low |= high * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high
// is no longer required.
result = low * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.
*/
function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
if (high >= 1 << n) {
Panic.panic(Panic.UNDER_OVERFLOW);
}
return (high << (256 - n)) | (low >> n);
}
}
/**
* @dev Calculates x * y >> n with full precision, following the selected rounding direction.
*/
function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {
return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// If upper 8 bits of 16-bit half set, add 8 to result
r |= SafeCast.toUint((x >> r) > 0xff) << 3;
// If upper 4 bits of 8-bit half set, add 4 to result
r |= SafeCast.toUint((x >> r) > 0xf) << 2;
// Shifts value right by the current result and use it as an index into this lookup table:
//
// | x (4 bits) | index | table[index] = MSB position |
// |------------|---------|-----------------------------|
// | 0000 | 0 | table[0] = 0 |
// | 0001 | 1 | table[1] = 0 |
// | 0010 | 2 | table[2] = 1 |
// | 0011 | 3 | table[3] = 1 |
// | 0100 | 4 | table[4] = 2 |
// | 0101 | 5 | table[5] = 2 |
// | 0110 | 6 | table[6] = 2 |
// | 0111 | 7 | table[7] = 2 |
// | 1000 | 8 | table[8] = 3 |
// | 1001 | 9 | table[9] = 3 |
// | 1010 | 10 | table[10] = 3 |
// | 1011 | 11 | table[11] = 3 |
// | 1100 | 12 | table[12] = 3 |
// | 1101 | 13 | table[13] = 3 |
// | 1110 | 14 | table[14] = 3 |
// | 1111 | 15 | table[15] = 3 |
//
// The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
assembly ("memory-safe") {
r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
}
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.26; /// @notice Emitted when the protocol fee receiver is updated. /// @param oldReceiver The old protocol fee receiver address. /// @param newReceiver The new protocol fee receiver address. event ProtocolFeeReceiverUpdated(address oldReceiver, address newReceiver); /// @notice Emitted when the default protocol fee rate is updated. /// @param oldRate The old default protocol fee rate. /// @param newRate The new default protocol fee rate. event DefaultRateUpdated(uint256 oldRate, uint256 newRate); /// @notice Emitted when a custom fee rate is updated for a specific vault. /// @param vault The address of the vault. /// @param rate The new custom fee rate for the vault. /// @param isActivated A boolean indicating whether the custom rate is activated. event CustomRateUpdated(address vault, uint16 rate, bool isActivated);
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {CustomRateUpdated, DefaultRateUpdated, ProtocolFeeReceiverUpdated} from "./Events.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
/// @title FeeRegistry
/// @notice The FeeRegistry contract manages protocol fee rates for various vaults.
/// It allows the contract owner (the protocol) to set a default protocol fee rate, define custom fee rates
/// for specific vaults, and manage the address that receives these protocol fees.
/// Protocol fees represents a fraction (which is the rate) of the fees taken by the asset manager of the vault
contract FeeRegistry is Ownable2StepUpgradeable {
struct CustomRate {
bool isActivated;
uint16 rate;
}
/// @custom:storage-location erc7201:hopper.storage.FeeRegistry
struct FeeRegistryStorage {
uint16 defaultRate;
address protocolFeeReceiver;
mapping(address => CustomRate) customRate;
}
// keccak256(abi.encode(uint256(keccak256("hopper.storage.FeeRegistry")) - 1)) & ~bytes32(uint256(0xff));
// solhint-disable-next-line const-name-snakecase
bytes32 private constant feeRegistryStorage = 0xfae567c932a2d69f96a50330b7967af6689561bf72e1f4ad815fc97800b3f300;
/// @custom:oz-upgrades-unsafe-allow constructor
// solhint-disable-next-line ignoreConstructors
constructor(
bool disable
) {
if (disable) _disableInitializers();
}
/// @notice Initializes the owner and protocol fee receiver.
/// @param initialOwner The contract protocol address.
/// @param _protocolFeeReceiver The protocol fee receiver.
function initialize(address initialOwner, address _protocolFeeReceiver) public initializer {
__Ownable_init(initialOwner);
FeeRegistryStorage storage $ = _getFeeRegistryStorage();
$.protocolFeeReceiver = _protocolFeeReceiver;
}
function _getFeeRegistryStorage() internal pure returns (FeeRegistryStorage storage $) {
// solhint-disable-next-line no-inline-assembly
assembly {
$.slot := feeRegistryStorage
}
}
/// @notice Updates the address of the protocol fee receiver.
/// @param _protocolFeeReceiver The new protocol fee receiver address.
function updateProtocolFeeReceiver(
address _protocolFeeReceiver
) external onlyOwner {
emit ProtocolFeeReceiverUpdated(_getFeeRegistryStorage().protocolFeeReceiver, _protocolFeeReceiver);
_getFeeRegistryStorage().protocolFeeReceiver = _protocolFeeReceiver;
}
/// @notice Sets the default protocol fee rate.
/// @param rate The new default protocol fee rate.
function updateDefaultRate(
uint16 rate
) external onlyOwner {
FeeRegistryStorage storage $ = _getFeeRegistryStorage();
emit DefaultRateUpdated($.defaultRate, rate);
$.defaultRate = rate;
}
/// @notice Sets a custom fee rate for a specific vault.
/// @param vault The address of the vault.
/// @param rate The custom fee rate for the vault.
/// @param isActivated A boolean indicating whether the custom rate is activated.
function updateCustomRate(address vault, uint16 rate, bool isActivated) external onlyOwner {
_getFeeRegistryStorage().customRate[vault] = CustomRate({isActivated: isActivated, rate: rate});
emit CustomRateUpdated(vault, rate, isActivated);
}
/// @notice Checks if a custom fee rate is activated for a specific vault.
/// @param vault The address of the vault.
/// @return True if the vault has a custom fee rate, false otherwise.
function isCustomRate(
address vault
) external view returns (bool) {
return _getFeeRegistryStorage().customRate[vault].isActivated;
}
/// @notice Returns the address of the protocol fee receiver.
/// @return The protocol fee receiver address.
function protocolFeeReceiver() external view returns (address) {
return _getFeeRegistryStorage().protocolFeeReceiver;
}
/// @notice Returns the protocol fee rate for a specific vault,
/// representing the percentage of the fees taken by the asset manager.
/// @param vault The address of the vault.
/// @return rate The protocol fee rate for the vault.
function protocolRate(
address vault
) external view returns (uint256 rate) {
return _protocolRate(vault);
}
/// @return rate The protocol fee rate for the caller,
/// representing the percentage of the fees taken by the asset manager.
function protocolRate() external view returns (uint256 rate) {
return _protocolRate(msg.sender);
}
/// @notice Returns the protocol fee rate for a specific vault.
/// @param vault The address of the vault.
/// @return rate The protocol fee rate for the vault, considering custom rates.
function _protocolRate(
address vault
) internal view returns (uint256 rate) {
FeeRegistryStorage storage $ = _getFeeRegistryStorage();
if ($.customRate[vault].isActivated) {
return $.customRate[vault].rate;
}
return $.defaultRate;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {Silo} from "./Silo.sol";
import {IERC7540Deposit} from "./interfaces/IERC7540Deposit.sol";
import {IERC7540Redeem} from "./interfaces/IERC7540Redeem.sol";
import {IWETH9} from "./interfaces/IWETH9.sol";
import {
CantDepositNativeToken,
ERC7540InvalidOperator,
ERC7540PreviewDepositDisabled,
ERC7540PreviewMintDisabled,
ERC7540PreviewRedeemDisabled,
ERC7540PreviewWithdrawDisabled,
NewTotalAssetsMissing,
OnlyOneRequestAllowed,
RequestIdNotClaimable,
RequestNotCancelable,
WrongNewTotalAssets
} from "./primitives/Errors.sol";
import {
DepositRequestCanceled,
NewTotalAssetsUpdated,
SettleRedeem,
SettleDeposit,
TotalAssetsLifespanUpdated,
TotalAssetsUpdated
} from "./primitives/Events.sol";
import {EpochData, SettleData} from "./primitives/Struct.sol";
import {
ERC20Upgradeable,
IERC20,
IERC20Metadata
} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {ERC20PausableUpgradeable} from
"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import {ERC4626Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
using SafeERC20 for IERC20;
using Math for uint256;
/// @title ERC7540Upgradeable
/// @dev An implementation of the ERC7540 standard. It defines the core data structures and functions necessary
/// to do requests and process them.
abstract contract ERC7540 is IERC7540Redeem, IERC7540Deposit, ERC20PausableUpgradeable, ERC4626Upgradeable {
/// @custom:storage-location erc7201:hopper.storage.ERC7540
/// @param totalAssets The total assets.
/// @param depositEpochId The current deposit epoch ID.
/// @param depositSettleId The current deposit settle ID.
/// @param lastDepositEpochIdSettled The last deposit epoch ID settled.
/// @param redeemEpochId The current redeem epoch ID.
/// @param redeemSettleId The current redeem settle ID.
/// @param lastRedeemEpochIdSettled The last redeem epoch ID settled.
/// @param epochs A mapping of epochs data.
/// @param settles A mapping of settle data.
/// @param lastDepositRequestId A mapping of the last deposit request ID for each user.
/// @param lastRedeemRequestId A mapping of the last redeem request ID for each user.
/// @param isOperator A mapping of operators for each user.
/// @param pendingSilo The pending silo.
/// @param wrappedNativeToken The wrapped native token. WETH9 for ethereum.
struct ERC7540Storage {
uint256 totalAssets;
uint256 newTotalAssets;
uint40 depositEpochId;
uint40 depositSettleId;
uint40 lastDepositEpochIdSettled;
uint40 redeemEpochId;
uint40 redeemSettleId;
uint40 lastRedeemEpochIdSettled;
mapping(uint40 epochId => EpochData) epochs;
mapping(uint40 settleId => SettleData) settles;
mapping(address user => uint40 epochId) lastDepositRequestId;
mapping(address user => uint40 epochId) lastRedeemRequestId;
mapping(address controller => mapping(address operator => bool)) isOperator;
Silo pendingSilo;
IWETH9 wrappedNativeToken;
uint8 decimals;
uint8 decimalsOffset;
// New variables introduce with v0.5.0
uint128 totalAssetsExpiration;
uint128 totalAssetsLifespan;
}
// keccak256(abi.encode(uint256(keccak256("hopper.storage.ERC7540")) - 1)) & ~bytes32(uint256(0xff));
/// @custom:slot erc7201:hopper.storage.ERC7540
// solhint-disable-next-line const-name-snakecase
bytes32 private constant erc7540Storage = 0x5c74d456014b1c0eb4368d944667a568313858a3029a650ff0cb7b56f8b57a00;
/// @notice Returns the ERC7540 storage struct.
/// @return _erc7540Storage The ERC7540 storage struct.
function _getERC7540Storage() internal pure returns (ERC7540Storage storage _erc7540Storage) {
// solhint-disable-next-line no-inline-assembly
assembly {
_erc7540Storage.slot := erc7540Storage
}
}
/// @notice Initializes the ERC7540 contract.
/// @param underlying The underlying token.
/// @param wrappedNativeToken The wrapped native token.
// solhint-disable-next-line func-name-mixedcase
function __ERC7540_init(IERC20 underlying, address wrappedNativeToken) internal onlyInitializing {
ERC7540Storage storage $ = _getERC7540Storage();
$.depositEpochId = 1;
$.redeemEpochId = 2;
$.depositSettleId = 1;
$.redeemSettleId = 2;
$.pendingSilo = new Silo(underlying, wrappedNativeToken);
$.wrappedNativeToken = IWETH9(wrappedNativeToken);
$.newTotalAssets = type(uint256).max;
uint8 underlyingDecimals = ERC20Upgradeable(asset()).decimals();
if (underlyingDecimals >= 18) {
$.decimals = underlyingDecimals;
} else {
$.decimals = 18;
unchecked {
$.decimalsOffset = 18 - underlyingDecimals;
}
}
}
///////////////
// MODIFIERS //
///////////////
/// @notice Make sure the caller is an operator or the controller.
/// @param controller The controller.
modifier onlyOperator(
address controller
) {
if (controller != msg.sender && !isOperator(controller, msg.sender)) {
revert ERC7540InvalidOperator();
}
_;
}
/////////////////////
// ## Overrides ## //
/////////////////////
/// @notice Returns the total assets.
/// @return The total assets.
function totalAssets() public view override(IERC4626, ERC4626Upgradeable) returns (uint256) {
ERC7540Storage storage $ = _getERC7540Storage();
return $.totalAssets;
}
function decimals()
public
view
virtual
override(ERC4626Upgradeable, ERC20Upgradeable, IERC20Metadata)
returns (uint8)
{
return _getERC7540Storage().decimals;
}
function _decimalsOffset() internal view virtual override returns (uint8) {
return _getERC7540Storage().decimalsOffset;
}
function _update(
address from,
address to,
uint256 value
) internal virtual override(ERC20PausableUpgradeable, ERC20Upgradeable) {
return ERC20PausableUpgradeable._update(from, to, value);
}
///////////////////
// ## EIP7540 ## //
///////////////////
function isOperator(address controller, address operator) public view returns (bool) {
return _getERC7540Storage().isOperator[controller][operator];
}
/// @dev should not be usable when contract is paused
function setOperator(address operator, bool approved) external whenNotPaused returns (bool success) {
_getERC7540Storage().isOperator[msg.sender][operator] = approved;
emit OperatorSet(msg.sender, operator, approved);
return true;
}
function previewDeposit(
uint256
) public pure override(ERC4626Upgradeable, IERC4626) returns (uint256) {
revert ERC7540PreviewDepositDisabled();
}
function previewMint(
uint256
) public pure override(ERC4626Upgradeable, IERC4626) returns (uint256) {
revert ERC7540PreviewMintDisabled();
}
function previewRedeem(
uint256
) public pure override(ERC4626Upgradeable, IERC4626) returns (uint256) {
revert ERC7540PreviewRedeemDisabled();
}
function previewWithdraw(
uint256
) public pure override(ERC4626Upgradeable, IERC4626) returns (uint256) {
revert ERC7540PreviewWithdrawDisabled();
}
////////////////////////////////
// ## EIP7540 Deposit Flow ## //
////////////////////////////////
/// @dev Unusable when paused. Modifier not needed as it's overridden.
/// @notice Request deposit of assets into the vault.
/// @param assets The amount of assets to deposit.
/// @param controller The controller is the address that will manage the request.
/// @param owner The owner of the assets.
function _requestDeposit(uint256 assets, address controller, address owner) internal returns (uint256) {
uint256 claimable = claimableDepositRequest(0, controller);
if (claimable > 0) _deposit(claimable, controller, controller);
ERC7540Storage storage $ = _getERC7540Storage();
uint40 _depositId = $.depositEpochId;
if ($.lastDepositRequestId[controller] != _depositId) {
if (pendingDepositRequest(0, controller) > 0) {
revert OnlyOneRequestAllowed();
}
$.lastDepositRequestId[controller] = _depositId;
}
if (msg.value != 0) {
// if user sends eth and the underlying is wETH we will wrap it for him
if (asset() == address($.wrappedNativeToken)) {
$.pendingSilo.depositEth{value: msg.value}();
assets = msg.value;
} else {
revert CantDepositNativeToken();
}
} else {
IERC20(asset()).safeTransferFrom(owner, address($.pendingSilo), assets);
}
$.epochs[_depositId].depositRequest[controller] += assets;
emit DepositRequest(controller, owner, _depositId, msg.sender, assets);
return _depositId;
}
/// @dev Unusable when paused. Protected by ERC20PausableUpgradeable's _transfer function.
/// @notice Claim the assets from the vault after a request has been settled.
/// @param assets The amount of assets requested to deposit.
/// @param receiver The receiver of the shares.
/// @return shares The corresponding shares.
function deposit(
uint256 assets,
address receiver
) public virtual override(ERC4626Upgradeable, IERC4626) returns (uint256) {
return _deposit(assets, receiver, msg.sender);
}
/// @dev Unusable when paused. Protected by ERC20PausableUpgradeable's _transfer function.
/// @notice Claim the assets from the vault after a request has been settled.
/// @param assets The assets to deposit.
/// @param receiver The receiver of the shares.
/// @param controller The controller, who owns the deposit request.
/// @return shares The corresponding shares.
function deposit(
uint256 assets,
address receiver,
address controller
) external virtual onlyOperator(controller) returns (uint256) {
return _deposit(assets, receiver, controller);
}
/// @notice Claim the assets from the vault after a request has been settled.
/// @param assets The assets to deposit.
/// @param receiver The receiver of the shares.
/// @param controller The controller, who owns the deposit request.
/// @return shares The corresponding shares.
function _deposit(uint256 assets, address receiver, address controller) internal virtual returns (uint256 shares) {
ERC7540Storage storage $ = _getERC7540Storage();
uint40 requestId = $.lastDepositRequestId[controller];
if (requestId > $.lastDepositEpochIdSettled) {
revert RequestIdNotClaimable();
}
$.epochs[requestId].depositRequest[controller] -= assets;
shares = convertToShares(assets, requestId);
_transfer(address(this), receiver, shares);
emit Deposit(controller, receiver, assets, shares);
}
/// @dev Unusable when paused. Protected by ERC20PausableUpgradeable's _transfer function.
function mint(
uint256 shares,
address receiver
) public virtual override(ERC4626Upgradeable, IERC4626) returns (uint256) {
return _mint(shares, receiver, msg.sender);
}
/// @dev Unusable when paused. Protected by ERC20PausableUpgradeable's _transfer function.
/// @notice Claim shares from the vault after a request deposit.
function mint(
uint256 shares,
address receiver,
address controller
) external virtual onlyOperator(controller) returns (uint256) {
return _mint(shares, receiver, controller);
}
/// @notice Mint shares from the vault.
/// @param shares The shares to mint.
/// @param receiver The receiver of the shares.
/// @param controller The controller, who owns the mint request.
/// @return assets The corresponding assets.
function _mint(uint256 shares, address receiver, address controller) internal virtual returns (uint256 assets) {
ERC7540Storage storage $ = _getERC7540Storage();
uint40 requestId = $.lastDepositRequestId[controller];
if (requestId > $.lastDepositEpochIdSettled) {
revert RequestIdNotClaimable();
}
assets = _convertToAssets(shares, requestId, Math.Rounding.Ceil);
$.epochs[requestId].depositRequest[controller] -= assets;
_transfer(address(this), receiver, shares);
emit Deposit(controller, receiver, assets, shares);
}
/// @dev Unusable when paused. Protected by whenNotPaused.
/// @notice Cancel a deposit request.
/// @dev It can only be called in the same epoch.
function cancelRequestDeposit() external whenNotPaused {
ERC7540Storage storage $ = _getERC7540Storage();
uint40 requestId = $.lastDepositRequestId[msg.sender];
if (requestId != $.depositEpochId) {
revert RequestNotCancelable(requestId);
}
uint256 requestedAmount = $.epochs[requestId].depositRequest[msg.sender];
$.epochs[requestId].depositRequest[msg.sender] = 0;
IERC20(asset()).safeTransferFrom(address($.pendingSilo), msg.sender, requestedAmount);
emit DepositRequestCanceled(requestId, msg.sender);
}
///////////////////////////////
// ## EIP7540 REDEEM FLOW ## //
///////////////////////////////
/// @dev Unusable when paused. Protected by ERC20PausableUpgradeable's _update function.
/// @notice Request redemption of shares from the vault.
/// @param shares The amount of shares to redeem.
/// @param controller The controller is the address that will manage the request.
/// @param owner The owner of the shares.
/// @return The request ID. It is the current redeem epoch ID.
function _requestRedeem(uint256 shares, address controller, address owner) internal returns (uint256) {
if (msg.sender != owner && !isOperator(owner, msg.sender)) {
_spendAllowance(owner, msg.sender, shares);
}
ERC7540Storage storage $ = _getERC7540Storage();
uint256 claimable = claimableRedeemRequest(0, controller);
if (claimable > 0) _redeem(claimable, controller, controller);
uint40 _redeemId = $.redeemEpochId;
if ($.lastRedeemRequestId[controller] != _redeemId) {
if (pendingRedeemRequest(0, controller) > 0) {
revert OnlyOneRequestAllowed();
}
$.lastRedeemRequestId[controller] = _redeemId;
}
$.epochs[_redeemId].redeemRequest[controller] += shares;
_update(owner, address($.pendingSilo), shares);
emit RedeemRequest(controller, owner, _redeemId, msg.sender, shares);
return _redeemId;
}
/// @notice Redeem shares from the vault.
/// @param shares The shares to redeem.
/// @param receiver The receiver of the assets.
/// @param controller The controller, who owns the redeem request.
/// @return assets The corresponding assets.
function _redeem(uint256 shares, address receiver, address controller) internal returns (uint256 assets) {
ERC7540Storage storage $ = _getERC7540Storage();
uint40 requestId = $.lastRedeemRequestId[controller];
if (requestId > $.lastRedeemEpochIdSettled) {
revert RequestIdNotClaimable();
}
$.epochs[requestId].redeemRequest[controller] -= shares;
assets = _convertToAssets(shares, requestId, Math.Rounding.Floor);
IERC20(asset()).safeTransfer(receiver, assets);
emit Withdraw(msg.sender, receiver, controller, assets, shares);
}
/// @notice Withdraw assets from the vault.
/// @param assets The assets to withdraw.
/// @param receiver The receiver of the assets.
/// @param controller The controller, who owns the request.
/// @return shares The corresponding shares.
function _withdraw(uint256 assets, address receiver, address controller) internal returns (uint256 shares) {
ERC7540Storage storage $ = _getERC7540Storage();
uint40 requestId = $.lastRedeemRequestId[controller];
if (requestId > $.lastRedeemEpochIdSettled) {
revert RequestIdNotClaimable();
}
shares = _convertToShares(assets, requestId, Math.Rounding.Ceil);
$.epochs[requestId].redeemRequest[controller] -= shares;
IERC20(asset()).safeTransfer(receiver, assets);
emit Withdraw(msg.sender, receiver, controller, assets, shares);
}
////////////////////////////////
// ## SETTLEMENT FUNCTIONS ## //
////////////////////////////////
/// @dev This function will deposit the pending assets of the pendingSilo.
/// and save the deposit parameters in the settleData.
/// @param assetsCustodian The address that will hold the assets.
function _settleDeposit(
address assetsCustodian
) internal {
ERC7540Storage storage $erc7540 = _getERC7540Storage();
uint40 depositSettleId = $erc7540.depositSettleId;
uint256 _pendingAssets = $erc7540.settles[depositSettleId].pendingAssets;
if (_pendingAssets == 0) return;
uint256 shares = _convertToShares(_pendingAssets, Math.Rounding.Floor);
// cache
uint256 _totalAssets = totalAssets();
uint256 _totalSupply = totalSupply();
uint40 lastDepositEpochIdSettled = $erc7540.depositEpochId - 2;
SettleData storage settleData = $erc7540.settles[depositSettleId];
settleData.totalAssets = _totalAssets;
settleData.totalSupply = _totalSupply;
_mint(address(this), shares);
_totalAssets += _pendingAssets;
_totalSupply += shares;
$erc7540.totalAssets = _totalAssets;
$erc7540.depositSettleId = depositSettleId + 2;
$erc7540.lastDepositEpochIdSettled = lastDepositEpochIdSettled;
IERC20(asset()).safeTransferFrom(address($erc7540.pendingSilo), assetsCustodian, _pendingAssets);
emit SettleDeposit(
lastDepositEpochIdSettled, depositSettleId, _totalAssets, _totalSupply, _pendingAssets, shares
);
}
/// @dev This function will redeem the pending shares of the pendingSilo.
/// and save the redeem parameters in the settleData.
/// @param assetsCustodian The address that holds the assets.
function _settleRedeem(
address assetsCustodian
) internal {
ERC7540Storage storage $erc7540 = _getERC7540Storage();
uint40 redeemSettleId = $erc7540.redeemSettleId;
address _asset = asset();
uint256 pendingShares = $erc7540.settles[redeemSettleId].pendingShares;
uint256 assetsToWithdraw = _convertToAssets(pendingShares, Math.Rounding.Floor);
uint256 assetsInTheSafe = IERC20(_asset).balanceOf(assetsCustodian);
if (assetsToWithdraw == 0 || assetsToWithdraw > assetsInTheSafe) return;
// cache
uint256 _totalAssets = totalAssets();
uint256 _totalSupply = totalSupply();
uint40 lastRedeemEpochIdSettled = $erc7540.redeemEpochId - 2;
SettleData storage settleData = $erc7540.settles[redeemSettleId];
settleData.totalAssets = _totalAssets;
settleData.totalSupply = _totalSupply;
_burn(address($erc7540.pendingSilo), pendingShares);
_totalAssets -= assetsToWithdraw;
_totalSupply -= pendingShares;
$erc7540.totalAssets = _totalAssets;
$erc7540.redeemSettleId = redeemSettleId + 2;
$erc7540.lastRedeemEpochIdSettled = lastRedeemEpochIdSettled;
IERC20(_asset).safeTransferFrom(assetsCustodian, address(this), assetsToWithdraw);
emit SettleRedeem(
lastRedeemEpochIdSettled, redeemSettleId, _totalAssets, _totalSupply, assetsToWithdraw, pendingShares
);
}
////////////////////////////////////////
// ## TOTALASSETS UPDATE FUNCTIONS ## //
////////////////////////////////////////
/// @notice Update newTotalAssets variable in order to update totalAssets.
/// @param _newTotalAssets The new total assets of the vault.
function _updateNewTotalAssets(
uint256 _newTotalAssets
) internal whenNotPaused {
ERC7540Storage storage $ = _getERC7540Storage();
$.epochs[$.depositEpochId].settleId = $.depositSettleId;
$.epochs[$.redeemEpochId].settleId = $.redeemSettleId;
address _pendingSilo = address($.pendingSilo);
uint256 pendingAssets = IERC20(asset()).balanceOf(_pendingSilo);
uint256 pendingShares = balanceOf(_pendingSilo);
if (pendingAssets != 0) {
$.depositEpochId += 2;
$.settles[$.depositSettleId].pendingAssets = pendingAssets;
}
if (pendingShares != 0) {
$.redeemEpochId += 2;
$.settles[$.redeemSettleId].pendingShares = pendingShares;
}
$.newTotalAssets = _newTotalAssets;
emit NewTotalAssetsUpdated(_newTotalAssets);
}
/// @dev Updates the totalAssets variable with the newTotalAssets variable.
function _updateTotalAssets(
uint256 _newTotalAssets
) internal whenNotPaused {
ERC7540Storage storage $ = _getERC7540Storage();
uint256 newTotalAssets = $.newTotalAssets;
if (
newTotalAssets == type(uint256).max // it means newTotalAssets has not been updated
) revert NewTotalAssetsMissing();
if (_newTotalAssets != newTotalAssets) {
revert WrongNewTotalAssets();
}
$.totalAssets = newTotalAssets;
$.newTotalAssets = type(uint256).max; // by setting it to max, we ensure that it is not called again
$.totalAssetsExpiration = uint128(block.timestamp) + $.totalAssetsLifespan;
emit TotalAssetsUpdated(newTotalAssets);
}
function _updateTotalAssetsLifespan(
uint128 lifespan
) internal {
ERC7540Storage storage $ = _getERC7540Storage();
uint128 oldLifespan = $.totalAssetsLifespan;
$.totalAssetsLifespan = lifespan;
emit TotalAssetsLifespanUpdated(oldLifespan, lifespan);
}
//////////////////////////
// ## VIEW FUNCTIONS ## //
//////////////////////////
/// @notice Converts assets to shares for a specific epoch.
/// @param assets The assets to convert.
/// @param requestId The request ID, which is equivalent to the epoch ID.
/// @return The corresponding shares.
function convertToShares(uint256 assets, uint256 requestId) public view returns (uint256) {
return _convertToShares(assets, uint40(requestId), Math.Rounding.Floor);
}
/// @dev Converts assets to shares for a specific epoch.
/// @param assets The assets to convert.
/// @param requestId The request ID.
/// @param rounding The rounding method.
/// @return The corresponding shares.
function _convertToShares(
uint256 assets,
uint40 requestId,
Math.Rounding rounding
) internal view returns (uint256) {
ERC7540Storage storage $ = _getERC7540Storage();
// cache
uint40 settleId = $.epochs[requestId].settleId;
uint256 _totalAssets = $.settles[settleId].totalAssets + 1;
uint256 _totalSupply = $.settles[settleId].totalSupply + 10 ** _decimalsOffset();
return assets.mulDiv(_totalSupply, _totalAssets, rounding);
}
/// @dev Converts shares to assets for a specific epoch.
/// @param shares The shares to convert.
/// @param requestId The request ID.
function convertToAssets(uint256 shares, uint256 requestId) public view returns (uint256) {
return _convertToAssets(shares, uint40(requestId), Math.Rounding.Floor);
}
/// @notice Convert shares to assets for a specific epoch/request.
/// @param shares The shares to convert.
/// @param requestId The request ID at which the conversion should be done.
/// @param rounding The rounding method.
/// @return The corresponding assets.
function _convertToAssets(
uint256 shares,
uint40 requestId,
Math.Rounding rounding
) internal view returns (uint256) {
ERC7540Storage storage $ = _getERC7540Storage();
// cache
uint40 settleId = $.epochs[requestId].settleId;
uint256 _totalAssets = $.settles[settleId].totalAssets + 1;
uint256 _totalSupply = $.settles[settleId].totalSupply + 10 ** _decimalsOffset();
return shares.mulDiv(_totalAssets, _totalSupply, rounding);
}
/// @notice Returns the pending redeem request for a controller.
/// @param requestId The request ID.
/// @param controller The controller.
/// @return shares The shares that are waiting to be settled.
function pendingRedeemRequest(uint256 requestId, address controller) public view returns (uint256 shares) {
ERC7540Storage storage $ = _getERC7540Storage();
if (requestId == 0) {
requestId = $.lastRedeemRequestId[controller];
}
if (requestId > $.lastRedeemEpochIdSettled) {
return $.epochs[uint40(requestId)].redeemRequest[controller];
}
}
/// @notice Returns the claimable redeem request for a controller for a specific request ID.
/// @param requestId The request ID.
/// @param controller The controller.
/// @return shares The shares that can be redeemed.
function claimableRedeemRequest(uint256 requestId, address controller) public view returns (uint256 shares) {
ERC7540Storage storage $ = _getERC7540Storage();
if (requestId == 0) requestId = $.lastRedeemRequestId[controller];
if (requestId <= $.lastRedeemEpochIdSettled) {
return $.epochs[uint40(requestId)].redeemRequest[controller];
}
}
/// @notice Returns the amount of assets that are pending to be deposited for a controller. For a specific request
/// ID.
/// @param requestId The request ID.
/// @param controller The controller.
/// @return assets The assets that are waiting to be settled.
function pendingDepositRequest(uint256 requestId, address controller) public view returns (uint256 assets) {
ERC7540Storage storage $ = _getERC7540Storage();
if (requestId == 0) requestId = $.lastDepositRequestId[controller];
if (requestId > $.lastDepositEpochIdSettled) {
return $.epochs[uint40(requestId)].depositRequest[controller];
}
}
/// @notice Returns the claimable deposit request for a controller for a specific request ID.
/// @param requestId The request ID.
/// @param controller The controller.
/// @return assets The assets that can be claimed.
function claimableDepositRequest(uint256 requestId, address controller) public view returns (uint256 assets) {
ERC7540Storage storage $ = _getERC7540Storage();
if (requestId == 0) requestId = $.lastDepositRequestId[controller];
if (requestId <= $.lastDepositEpochIdSettled) {
return $.epochs[uint40(requestId)].depositRequest[controller];
}
}
///////////////////
// ## EIP7575 ## //
///////////////////
function share() external view returns (address) {
return (address(this));
}
///////////////////
// ## EIP165 ## //
//////////////////
function supportsInterface(
bytes4 interfaceId
) public view virtual returns (bool) {
return interfaceId == 0x2f0a18c5 // IERC7575
|| interfaceId == 0xf815c03d // IERC7575 shares
|| interfaceId == 0xce3bbe50 // IERC7540Deposit
|| interfaceId == 0x620ee8e4 // IERC7540Redeem
|| interfaceId == 0xe3bc4e65 // IERC7540
|| interfaceId == type(IERC165).interfaceId;
}
//////////////////////////////////
// ## FUNCTIONS TO IMPLEMENT ## //
//////////////////////////////////
/// @dev Settles deposit requests by transferring assets from the pendingSilo to the safe
/// and minting the corresponding shares to vault.
/// The function is not implemented here and must be implemented.
function settleDeposit(
uint256 _newTotalAssets
) public virtual;
/// @dev Settles redeem requests by transferring assets from the safe to the vault
/// and burning the corresponding shares from the pending silo.
/// The function is not implemented here and must be implemented.
function settleRedeem(
uint256 _newTotalAssets
) public virtual;
function safe() public view virtual returns (address);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {ERC7540} from "./ERC7540.sol";
import {AboveMaxRate} from "./primitives/Errors.sol";
import {HighWaterMarkUpdated, RatesUpdated} from "./primitives/Events.sol";
import {Rates} from "./primitives/Struct.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {FeeRegistry} from "../protocol/FeeRegistry.sol";
uint256 constant ONE_YEAR = 365 days;
uint256 constant BPS_DIVIDER = 10_000; // 100 %
abstract contract FeeManager is Ownable2StepUpgradeable, ERC7540 {
using Math for uint256;
uint16 public constant MAX_MANAGEMENT_RATE = 1000; // 10 %
uint16 public constant MAX_PERFORMANCE_RATE = 5000; // 50 %
uint16 public constant MAX_PROTOCOL_RATE = 3000; // 30 %
/// @custom:storage-definition erc7201:hopper.storage.FeeManager
/// @param newRatesTimestamp the timestamp at which the new rates will be applied
/// @param lastFeeTime the timestamp of the last fee calculation, it is used to compute management fees
/// @param highWaterMark the highest price per share ever reached, performance fees are taken when the price per
/// share is above this value
/// @param cooldown the time to wait before applying new rates
/// @param rates the current fee rates
/// @param oldRates the previous fee rates, they are used during the cooldown period when new rates are set
/// @param feeRegistry the fee registry contract, it is used to read the protocol rate
struct FeeManagerStorage {
FeeRegistry feeRegistry;
uint256 newRatesTimestamp;
uint256 lastFeeTime;
uint256 highWaterMark;
uint256 cooldown;
Rates rates;
Rates oldRates;
}
// keccak256(abi.encode(uint256(keccak256("hopper.storage.FeeManager")) - 1)) & ~bytes32(uint256(0xff));
/// @custom:storage-location erc7201:hopper.storage.FeeManager
// solhint-disable-next-line const-name-snakecase
bytes32 private constant feeManagerStorage = 0xa5292f7ccd85acc1b3080c01f5da9af7799f2c26826bd4d79081d6511780bd00;
/// @notice Get the storage slot for the FeeManagerStorage struct
/// @return _feeManagerStorage the storage slot
function _getFeeManagerStorage() internal pure returns (FeeManagerStorage storage _feeManagerStorage) {
// solhint-disable-next-line no-inline-assembly
assembly {
_feeManagerStorage.slot := feeManagerStorage
}
}
/// @notice Initialize the FeeManager contract
/// @param _registry the address of the fee registry contract
/// @param _managementRate the management rate, expressed in BPS
/// @param _performanceRate the performance rate, expressed in BPS
/// @param _decimals the number of decimals of the shares
/// @param _cooldown the time to wait before applying new rates
// solhint-disable-next-line func-name-mixedcase
function __FeeManager_init(
address _registry,
uint16 _managementRate,
uint16 _performanceRate,
uint256 _decimals,
uint256 _cooldown
) internal onlyInitializing {
if (_managementRate > MAX_MANAGEMENT_RATE) {
revert AboveMaxRate(MAX_MANAGEMENT_RATE);
}
if (_performanceRate > MAX_PERFORMANCE_RATE) {
revert AboveMaxRate(MAX_PERFORMANCE_RATE);
}
FeeManagerStorage storage $ = _getFeeManagerStorage();
$.newRatesTimestamp = block.timestamp;
$.cooldown = _cooldown;
$.feeRegistry = FeeRegistry(_registry);
$.highWaterMark = 10 ** _decimals;
$.rates.managementRate = _managementRate;
$.rates.performanceRate = _performanceRate;
}
/// @notice Take the fees by minting the manager and protocol shares
/// @param feeReceiver the address that will receive the manager shares
/// @param protocolFeeReceiver the address that will receive the protocol shares
function _takeFees(address feeReceiver, address protocolFeeReceiver) internal {
FeeManagerStorage storage $ = _getFeeManagerStorage();
(uint256 managerShares, uint256 protocolShares) = _calculateFees();
if (managerShares > 0) {
_mint(feeReceiver, managerShares);
if (
protocolShares > 0 // they can't be protocolShares without managerShares
) _mint(protocolFeeReceiver, protocolShares);
}
uint256 pricePerShare = _convertToAssets(10 ** decimals(), Math.Rounding.Floor);
_setHighWaterMark(pricePerShare);
$.lastFeeTime = block.timestamp;
}
/// @notice update the fee rates, the new rates will be applied after the cooldown period
/// @param newRates the new fee rates
function updateRates(
Rates memory newRates
) external onlyOwner {
FeeManagerStorage storage $ = _getFeeManagerStorage();
if (newRates.managementRate > MAX_MANAGEMENT_RATE) {
revert AboveMaxRate(MAX_MANAGEMENT_RATE);
}
if (newRates.performanceRate > MAX_PERFORMANCE_RATE) {
revert AboveMaxRate(MAX_PERFORMANCE_RATE);
}
uint256 newRatesTimestamp = block.timestamp + $.cooldown;
Rates memory currentRates = $.rates;
$.newRatesTimestamp = newRatesTimestamp;
$.oldRates = currentRates;
$.rates = newRates;
emit RatesUpdated(currentRates, newRates, newRatesTimestamp);
}
/// @dev Since we have a cooldown period and to avoid a double call
/// to update the feeRates, this function returns a different rate
/// following the timestamp
/// @notice the current fee rates
function feeRates() public view returns (Rates memory) {
FeeManagerStorage storage $ = _getFeeManagerStorage();
if ($.newRatesTimestamp <= block.timestamp) return $.rates;
return $.oldRates;
}
/// @dev Update the high water mark only if the new value is greater than the current one
/// @dev The high water mark is the highest price per share ever reached
/// @param _newHighWaterMark the new high water mark
function _setHighWaterMark(
uint256 _newHighWaterMark
) internal {
FeeManagerStorage storage $ = _getFeeManagerStorage();
uint256 _highWaterMark = $.highWaterMark;
if (_newHighWaterMark > _highWaterMark) {
emit HighWaterMarkUpdated(_highWaterMark, _newHighWaterMark);
$.highWaterMark = _newHighWaterMark;
}
}
/// @dev Read the protocol rate from the fee registry
/// @dev if the value is above the MAX_PROTOCOL_RATE, return the MAX_PROTOCOL_RATE
/// @return protocolRate the protocol rate
function _protocolRate() internal view returns (uint256 protocolRate) {
FeeManagerStorage storage $ = _getFeeManagerStorage();
protocolRate = $.feeRegistry.protocolRate();
if (protocolRate > MAX_PROTOCOL_RATE) return MAX_PROTOCOL_RATE;
return protocolRate;
}
/// @dev Calculate and return the manager and protocol shares to be minted as fees
/// @dev total fees are the sum of the management and performance fees
/// @dev manager shares are the fees that go to the manager, it is the difference between the total fees and the
/// protocol fees
/// @dev protocol shares are the fees that go to the protocol
/// @return managerShares the manager shares to be minted as fees
/// @return protocolShares the protocol shares to be minted as fees
function _calculateFees() internal view returns (uint256 managerShares, uint256 protocolShares) {
FeeManagerStorage storage $ = _getFeeManagerStorage();
uint256 _decimals = decimals();
Rates memory _rates = feeRates();
/// Management fee computation ///
uint256 timeElapsed = block.timestamp - $.lastFeeTime;
uint256 _totalAssets = totalAssets();
uint256 managementFees = _calculateManagementFee(_totalAssets, _rates.managementRate, timeElapsed);
// by taking management fees the price per share decreases
uint256 pricePerShare = (10 ** _decimals).mulDiv(
_totalAssets + 1 - managementFees, totalSupply() + 10 ** _decimalsOffset(), Math.Rounding.Ceil
);
/// Performance fee computation ///
uint256 _totalSupply = totalSupply();
uint256 performanceFees =
_calculatePerformanceFee(_rates.performanceRate, _totalSupply, pricePerShare, $.highWaterMark, _decimals);
/// Protocol fee computation & convertion to shares ///
uint256 totalFees = managementFees + performanceFees;
// since we are minting shares without actually increasing the totalAssets, we need to compensate the future
// dilution of price per share by virtually decreasing totalAssets in our computation
uint256 totalShares =
totalFees.mulDiv(_totalSupply + 10 ** _decimalsOffset(), (_totalAssets - totalFees) + 1, Math.Rounding.Ceil);
protocolShares = totalShares.mulDiv(_protocolRate(), BPS_DIVIDER, Math.Rounding.Ceil);
managerShares = totalShares - protocolShares;
}
/// @dev Calculate the management fee
/// @param assets the total assets under management
/// @param annualRate the management rate, expressed in BPS and corresponding to the annual
/// @param timeElapsed the time elapsed since the last fee calculation in seconds
/// @return managementFee the management fee express in assets
function _calculateManagementFee(
uint256 assets,
uint256 annualRate,
uint256 timeElapsed
) internal pure returns (uint256 managementFee) {
uint256 annualFee = assets.mulDiv(annualRate, BPS_DIVIDER, Math.Rounding.Ceil);
managementFee = annualFee.mulDiv(timeElapsed, ONE_YEAR, Math.Rounding.Ceil);
}
/// @dev Calculate the performance fee
/// @dev The performance is calculated as the difference between the current price per share and the high water mark
/// @dev The performance fee is calculated as the product of the performance and the performance rate
/// @param _rate the performance rate, expressed in BPS
/// @param _totalSupply the total supply of shares
/// @param _pricePerShare the current price per share
/// @param _highWaterMark the highest price per share ever reached
/// @param _decimals the number of decimals of the shares
/// @return performanceFee the performance fee express in assets
function _calculatePerformanceFee(
uint256 _rate,
uint256 _totalSupply,
uint256 _pricePerShare,
uint256 _highWaterMark,
uint256 _decimals
) internal pure returns (uint256 performanceFee) {
if (_pricePerShare > _highWaterMark) {
uint256 profitPerShare;
unchecked {
profitPerShare = _pricePerShare - _highWaterMark;
}
uint256 profit = profitPerShare.mulDiv(_totalSupply, 10 ** _decimals, Math.Rounding.Ceil);
performanceFee = profit.mulDiv(_rate, BPS_DIVIDER, Math.Rounding.Ceil);
}
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {IERC7575} from "./IERC7575.sol";
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
interface IERC7540 is IERC7575, IERC165 {
event OperatorSet(address indexed controller, address indexed operator, bool approved);
// EIP7575 https://eips.ethereum.org/EIPS/eip-7575
function share() external view returns (address);
function isOperator(address controller, address operator) external returns (bool);
function setOperator(address operator, bool approved) external returns (bool success);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {IERC7540} from "./IERC7540.sol";
interface IERC7540Deposit is IERC7540 {
/**
* owner has locked assets in the Vault to Request a deposit with request ID requestId.
* controller controls this Request.
* sender is the caller of the requestDeposit
* which may not be equal to the owner
*
*/
event DepositRequest(
address indexed controller, address indexed owner, uint256 indexed requestId, address sender, uint256 assets
);
function requestDeposit(
uint256 assets,
address controller,
address owner
) external payable returns (uint256 requestId);
function deposit(uint256 assets, address receiver, address controller) external returns (uint256 shares);
function mint(uint256 shares, address receiver, address controller) external returns (uint256 assets);
function pendingDepositRequest(uint256 requestId, address controller) external view returns (uint256 assets);
function claimableDepositRequest(uint256 requestId, address controller) external view returns (uint256 assets);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {IERC7540} from "./IERC7540.sol";
interface IERC7540Redeem is IERC7540 {
event RedeemRequest(
address indexed controller, address indexed owner, uint256 indexed requestId, address sender, uint256 shares
);
function requestRedeem(uint256 shares, address operator, address owner) external returns (uint256 requestId);
function pendingRedeemRequest(uint256 requestId, address controller) external view returns (uint256 shares);
function claimableRedeemRequest(uint256 requestId, address controller) external view returns (uint256 shares);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
// EIP7575 https://eips.ethereum.org/EIPS/eip-7575
interface IERC7575 is IERC4626 {
function share() external view returns (address);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title Interface for WETH9
interface IWETH9 is IERC20 {
/// @notice Deposit ether to get wrapped ether
function deposit() external payable;
/// @notice Withdraw wrapped ether to get ether
function withdraw(
uint256
) external;
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
// ********************* VAULT ********************* //
enum State {
Open, // The vault is open for deposits and withdrawals.
Closing, // The vault is in the process of closing; no NEW deposit (settlement) are accepted into the vault
Closed // The vault is closed; settlement are locked; withdrawals are guaranteed at fixed price per share
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {State} from "./Enums.sol";
// ********************* VAULT ********************* //
/// @notice Indicates that the vault is not Open. It's either Closing or Close.
/// @param currentState The current state of the vault.
error NotOpen(State currentState);
/// @notice Indicates that the vault is not in the process of closing. It's either Open or Close.
/// @param currentState The current state of the vault.
error NotClosing(State currentState);
/// @notice Indicates that the vault is Closed.
error Closed();
/// @notice No new valuation proposition is allowed
error ValuationUpdateNotAllowed();
// ********************* ERC7540 ********************* //
/// @notice Indicates that preview deposit is disabled.
error ERC7540PreviewDepositDisabled();
/// @notice Indicates that preview mint is disabled.
error ERC7540PreviewMintDisabled();
/// @notice Indicates that preview redeem is disabled.
error ERC7540PreviewRedeemDisabled();
/// @notice Indicates that preview withdraw is disabled.
error ERC7540PreviewWithdrawDisabled();
/// @notice Indicates that only one request is allowed per settlement period.
error OnlyOneRequestAllowed();
/// @notice Indicates that the specified request is not cancelable.
/// @param requestId The ID of the request that cannot be canceled.
error RequestNotCancelable(uint256 requestId);
/// @notice Indicates an invalid operator for ERC7540 operations.
error ERC7540InvalidOperator();
/// @notice Indicates that the specified request ID is not claimable.
error RequestIdNotClaimable();
/// @notice Indicates that depositing a native token is not allowed.
error CantDepositNativeToken();
/// @notice Indicates that a new total assets value was not provided by the valuation manager.
error NewTotalAssetsMissing();
/// @notice Indicates that the new total assets value is not the one expected.
error WrongNewTotalAssets();
/// @notice Indicates that totalAssets value is outdated and that synchronous deposits are not allowed.
error OnlyAsyncDepositAllowed();
/// @notice Indicates that deposit can only happen via the synchronous path.
error OnlySyncDepositAllowed();
// ********************* FEE MANAGER ********************* //
/// @notice Indicates that the provided rate exceeds the maximum allowed rate.
/// @param maxRate The maximum allowable rate.
error AboveMaxRate(uint256 maxRate);
// ********************* ROLES ********************* //
/// @notice Indicates that the caller is not a safe address.
/// @param safe The address of the safe.
error OnlySafe(address safe);
/// @notice Indicates that the caller is not the whitelist manager.
/// @param whitelistManager The address of the whitelist manager.
error OnlyWhitelistManager(address whitelistManager);
/// @notice Indicates that the caller is not the valuation manager.
/// @param valuationManager The address of the valuation manager.
error OnlyValuationManager(address valuationManager);
// ********************* WHITELISTABLE ********************* //
/// @notice Indicates that the caller is not whitelisted.
error NotWhitelisted();// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {State} from "./Enums.sol";
import {Rates} from "./Struct.sol";
// ********************* VAULT ********************* //
/// @notice Emitted when a referral is made.
/// @param referral The address of the referral.
/// @param owner The address of the owner making the referral.
/// @param requestId The ID of the associated request.
/// @param assets The amount of assets involved in the referral.
event Referral(address indexed referral, address indexed owner, uint256 indexed requestId, uint256 assets);
/// @notice Emitted when the state of the vault is updated.
/// @param state The new state of the vault. Either Open, Closing or Close.
event StateUpdated(State state);
event SettleDeposit(
uint40 indexed epochId,
uint40 indexed settledId,
uint256 totalAssets,
uint256 totalSupply,
uint256 assetsDeposited,
uint256 sharesMinted
);
event SettleRedeem(
uint40 indexed epochId,
uint40 indexed settledId,
uint256 totalAssets,
uint256 totalSupply,
uint256 assetsWithdrawed,
uint256 sharesBurned
);
// ********************* WHITELISTABLE ********************* //
/// @notice Emitted when the Merkle tree root is updated.
/// @param root The new Merkle tree root.
event RootUpdated(bytes32 indexed root);
/// @notice Emitted when a whitelist entry is updated.
/// @param account The address of the account being updated.
/// @param authorized Indicates whether the account is authorized (true) or not (false).
event WhitelistUpdated(address indexed account, bool authorized);
/// @notice Emitted when the whitelist is disabled.
event WhitelistDisabled();
// ********************* ROLES ********************* //
/// @notice Emitted when the whitelist manager role is updated.
/// @param oldManager The address of the old whitelist manager.
/// @param newManager The address of the new whitelist manager.
event WhitelistManagerUpdated(address oldManager, address newManager);
/// @notice Emitted when the fee receiver role is updated.
/// @param oldReceiver The address of the old fee receiver.
/// @param newReceiver The address of the new fee receiver.
event FeeReceiverUpdated(address oldReceiver, address newReceiver);
/// @notice Emitted when the Valuation manager role is updated.
/// @param oldManager The address of the old Valuation manager.
/// @param newManager The address of the new Valuation manager.
event ValuationManagerUpdated(address oldManager, address newManager);
// ********************* FEE_MANAGER ********************* //
/// @notice Emitted when the rates are updated.
/// @param oldRates The new rates.
/// @param newRate The new rates.
/// @param timestamp The timestamp at which the update will take effect.
event RatesUpdated(Rates oldRates, Rates newRate, uint256 timestamp);
/// @notice Emitted when the highWaterMark is updated.
/// @param oldHighWaterMark The old highWaterMark.
/// @param newHighWaterMark The new highWaterMark.
event HighWaterMarkUpdated(uint256 oldHighWaterMark, uint256 newHighWaterMark);
// ********************* ERC7540 ********************* //
/// @notice Emitted when the totalAssets variable is updated.
/// @param totalAssets The new total assets value.
event TotalAssetsUpdated(uint256 totalAssets);
/// @notice Emitted when the newTotalAssets variable is updated.
/// @param totalAssets The new newTotalAssets value.
event NewTotalAssetsUpdated(uint256 totalAssets);
/// @notice Emitted when a deposit request is canceled.
/// @param requestId The ID of the canceled request.
/// @param controller The address of the controller of the canceled request.
event DepositRequestCanceled(uint256 indexed requestId, address indexed controller);
/// @notice Emitted when the lifespan is updated.
/// @param oldLifespan The old lifespan.
/// @param newLifespan The new lifespan.
event TotalAssetsLifespanUpdated(uint128 oldLifespan, uint128 newLifespan);
/// @notice Same as a 4626 Deposit event
/// @param sender The address who gave its assets
/// @param owner The receiver of the shares
/// @param assets Amount of assets deposit
/// @param shares Amount of shares minted to owner
event DepositSync(address indexed sender, address indexed owner, uint256 assets, uint256 shares);// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
// ********************* ERC7540 ********************* //
/// @dev Holds management and performance rates for the vault.
/// @param managementRate Management fee rate in basis points.
/// @param performanceRate Performance fee rate in basis points.
struct Rates {
uint16 managementRate;
uint16 performanceRate;
}
/// @dev Holds data for a specific epoch.
/// @param settleId Unique identifier for the related settlement data.
/// @param depositRequest Records deposit requests by address.
/// @param redeemRequest Records redeem requests by address.
struct EpochData {
uint40 settleId;
mapping(address => uint256) depositRequest;
mapping(address => uint256) redeemRequest;
}
/// @dev Holds settlement data for the vault.
/// @param totalSupply Total number of shares for this settlement.
/// @param totalAssets Total value of assets managed by the vault for this settlement.
struct SettleData {
uint256 totalSupply;
uint256 totalAssets;
uint256 pendingAssets;
uint256 pendingShares;
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {FeeRegistry} from "../protocol/FeeRegistry.sol";
import {OnlySafe, OnlyValuationManager, OnlyWhitelistManager} from "./primitives/Errors.sol";
import {FeeReceiverUpdated, ValuationManagerUpdated, WhitelistManagerUpdated} from "./primitives/Events.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
/// @title RolesUpgradeable
/// @dev This contract is used to define the various roles needed for a vault to operate.
/// @dev It also defines the modifiers used to check functions' caller.
abstract contract Roles is Ownable2StepUpgradeable {
/// @notice Stores the various roles responsible of managing the vault.
/// @param whitelistManager The address responsible of managing the whitelist.
/// @param feeReceiver The address that will receive the fees generated.
/// @param safe Every lagoon vault is associated with a Safe smart contract. This address will receive the assets of
/// the vault and can settle deposits and redeems.
/// @param feeRegistry The address of the FeeRegistry contract.
/// @param valuationManager. This address is responsible of updating the newTotalAssets value of the vault.
/// @param owner The address of the owner of the contract. It considered as the admin. It is not visible in the
/// struct. It can change the others roles and itself. Initiate the fund closing. Disable the whitelist.
struct RolesStorage {
address whitelistManager;
address feeReceiver;
address safe;
FeeRegistry feeRegistry;
address valuationManager;
}
/// @dev Initializes the roles of the vault.
/// @param roles The roles to be initialized.
// solhint-disable-next-line func-name-mixedcase
function __Roles_init(
RolesStorage memory roles
) internal onlyInitializing {
RolesStorage storage $ = _getRolesStorage();
$.whitelistManager = roles.whitelistManager;
$.feeReceiver = roles.feeReceiver;
$.safe = roles.safe;
$.feeRegistry = FeeRegistry(roles.feeRegistry);
$.valuationManager = roles.valuationManager;
}
// keccak256(abi.encode(uint256(keccak256("hopper.storage.Roles")) - 1)) & ~bytes32(uint256(0xff))
/// @custom:storage-location erc7201:hopper.storage.Roles
// solhint-disable-next-line const-name-snakecase
bytes32 private constant rolesStorage = 0x7c302ed2c673c3d6b4551cf74a01ee649f887e14fd20d13dbca1b6099534d900;
/// @dev Returns the storage struct of the roles.
/// @return _rolesStorage The storage struct of the roles.
function _getRolesStorage() internal pure returns (RolesStorage storage _rolesStorage) {
// solhint-disable-next-line no-inline-assembly
assembly {
_rolesStorage.slot := rolesStorage
}
}
/// @dev Returns the storage struct of the roles.
/// @return _rolesStorage The storage struct of the roles.
function getRolesStorage() public pure returns (RolesStorage memory _rolesStorage) {
_rolesStorage = _getRolesStorage();
}
/// @dev Modifier to check if the caller is the safe.
modifier onlySafe() {
address _safe = _getRolesStorage().safe;
if (_safe != msg.sender) revert OnlySafe(_safe);
_;
}
/// @dev Modifier to check if the caller is the whitelist manager.
modifier onlyWhitelistManager() {
address _whitelistManager = _getRolesStorage().whitelistManager;
if (_whitelistManager != msg.sender) {
revert OnlyWhitelistManager(_whitelistManager);
}
_;
}
/// @dev Modifier to check if the caller is the valuation manager.
modifier onlyValuationManager() {
address _valuationManager = _getRolesStorage().valuationManager;
if (_valuationManager != msg.sender) {
revert OnlyValuationManager(_valuationManager);
}
_;
}
/// @notice Updates the address of the whitelist manager.
/// @param _whitelistManager The new address of the whitelist manager.
/// @dev Only the owner can call this function.
function updateWhitelistManager(
address _whitelistManager
) external onlyOwner {
emit WhitelistManagerUpdated(_getRolesStorage().whitelistManager, _whitelistManager);
_getRolesStorage().whitelistManager = _whitelistManager;
}
/// @notice Updates the address of the valuation manager.
/// @param _valuationManager The new address of the valuation manager.
/// @dev Only the owner can call this function.
function updateValuationManager(
address _valuationManager
) external onlyOwner {
emit ValuationManagerUpdated(_getRolesStorage().valuationManager, _valuationManager);
_getRolesStorage().valuationManager = _valuationManager;
}
/// @notice Updates the address of the fee receiver.
/// @param _feeReceiver The new address of the fee receiver.
/// @dev Only the owner can call this function.
function updateFeeReceiver(
address _feeReceiver
) external onlyOwner {
emit FeeReceiverUpdated(_getRolesStorage().feeReceiver, _feeReceiver);
_getRolesStorage().feeReceiver = _feeReceiver;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {IWETH9} from "./interfaces/IWETH9.sol";
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
using SafeERC20 for IERC20;
/// @title Silo
/// @dev This contract is used to hold the assets/shares of the users that
/// requested a deposit/redeem. It is used to simplify the logic of the vault.
contract Silo {
IWETH9 public wrappedNativeToken;
constructor(IERC20 underlying, address _wrappedNativeToken) {
underlying.forceApprove(msg.sender, type(uint256).max);
wrappedNativeToken = IWETH9(_wrappedNativeToken);
}
function depositEth() external payable {
IWETH9(wrappedNativeToken).deposit{value: msg.value}();
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.26;
import {Roles} from "./Roles.sol";
import {WhitelistDisabled, WhitelistUpdated} from "./primitives/Events.sol";
abstract contract Whitelistable is Roles {
// keccak256(abi.encode(uint256(keccak256("hopper.storage.Whitelistable")) - 1)) & ~bytes32(uint256(0xff))
/// @custom:storage-location erc7201:hopper.storage.Whitelistable
// solhint-disable-next-line const-name-snakecase
bytes32 private constant whitelistableStorage = 0x083cc98ab296d1a1f01854b5f7a2f47df4425a56ba7b35f7faa3a336067e4800;
/// @custom:storage-definition erc7201:hopper.storage.Whitelistable
/// @param isWhitelisted The mapping of whitelisted addresses.
/// @param isActivated The flag to check if the whitelist is activated.
struct WhitelistableStorage {
mapping(address => bool) isWhitelisted;
bool isActivated;
}
/// @dev Returns the storage struct of the whitelist.
/// @return _whitelistableStorage The storage struct of the whitelist.
function _getWhitelistableStorage() internal pure returns (WhitelistableStorage storage _whitelistableStorage) {
// solhint-disable-next-line no-inline-assembly
assembly {
_whitelistableStorage.slot := whitelistableStorage
}
}
/// @dev Initializes the whitelist.
/// @param activate if the whitelist should be activated.
// solhint-disable-next-line func-name-mixedcase
function __Whitelistable_init(
bool activate
) internal onlyInitializing {
if (activate) {
WhitelistableStorage storage $ = _getWhitelistableStorage();
$.isActivated = true;
}
}
/// @notice Deactivates the whitelist
function disableWhitelist() public onlyOwner {
_getWhitelistableStorage().isActivated = false;
emit WhitelistDisabled();
}
/// @notice Checks if an account is whitelisted
/// @param account The address of the account to check
/// @return True if the account is whitelisted, false otherwise
function isWhitelisted(
address account
) public view returns (bool) {
WhitelistableStorage storage $ = _getWhitelistableStorage();
if (_getRolesStorage().feeRegistry.protocolFeeReceiver() == account) {
return true;
}
return $.isActivated ? $.isWhitelisted[account] : true;
}
/// @notice Adds multiple accounts to the whitelist
function addToWhitelist(
address[] memory accounts
) external onlyWhitelistManager {
WhitelistableStorage storage $ = _getWhitelistableStorage();
for (uint256 i = 0; i < accounts.length; i++) {
$.isWhitelisted[accounts[i]] = true;
emit WhitelistUpdated(accounts[i], true);
}
}
/// @notice Removes multiple accounts from the whitelist
/// @param accounts The addresses of the accounts to remove
function revokeFromWhitelist(
address[] memory accounts
) external onlyWhitelistManager {
WhitelistableStorage storage $ = _getWhitelistableStorage();
uint256 i = 0;
for (; i < accounts.length;) {
$.isWhitelisted[accounts[i]] = false;
emit WhitelistUpdated(accounts[i], false);
// solhint-disable-next-line no-inline-assembly
unchecked {
++i;
}
}
}
}{
"optimizer": {
"enabled": true,
"runs": 1
},
"metadata": {
"bytecodeHash": "none"
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"bool","name":"disable","type":"bool"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"maxRate","type":"uint256"}],"name":"AboveMaxRate","type":"error"},{"inputs":[],"name":"CantDepositNativeToken","type":"error"},{"inputs":[],"name":"Closed","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":"ERC7540InvalidOperator","type":"error"},{"inputs":[],"name":"ERC7540PreviewDepositDisabled","type":"error"},{"inputs":[],"name":"ERC7540PreviewMintDisabled","type":"error"},{"inputs":[],"name":"ERC7540PreviewRedeemDisabled","type":"error"},{"inputs":[],"name":"ERC7540PreviewWithdrawDisabled","type":"error"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NewTotalAssetsMissing","type":"error"},{"inputs":[{"internalType":"enum State","name":"currentState","type":"uint8"}],"name":"NotClosing","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[{"internalType":"enum State","name":"currentState","type":"uint8"}],"name":"NotOpen","type":"error"},{"inputs":[],"name":"NotWhitelisted","type":"error"},{"inputs":[],"name":"OnlyAsyncDepositAllowed","type":"error"},{"inputs":[],"name":"OnlyOneRequestAllowed","type":"error"},{"inputs":[{"internalType":"address","name":"safe","type":"address"}],"name":"OnlySafe","type":"error"},{"inputs":[],"name":"OnlySyncDepositAllowed","type":"error"},{"inputs":[{"internalType":"address","name":"valuationManager","type":"address"}],"name":"OnlyValuationManager","type":"error"},{"inputs":[{"internalType":"address","name":"whitelistManager","type":"address"}],"name":"OnlyWhitelistManager","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"RequestIdNotClaimable","type":"error"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"}],"name":"RequestNotCancelable","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"ValuationUpdateNotAllowed","type":"error"},{"inputs":[],"name":"WrongNewTotalAssets","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":"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":"controller","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"DepositRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":true,"internalType":"address","name":"controller","type":"address"}],"name":"DepositRequestCanceled","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":"DepositSync","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldReceiver","type":"address"},{"indexed":false,"internalType":"address","name":"newReceiver","type":"address"}],"name":"FeeReceiverUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldHighWaterMark","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newHighWaterMark","type":"uint256"}],"name":"HighWaterMarkUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"totalAssets","type":"uint256"}],"name":"NewTotalAssetsUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"controller","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"OperatorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint16","name":"managementRate","type":"uint16"},{"internalType":"uint16","name":"performanceRate","type":"uint16"}],"indexed":false,"internalType":"struct Rates","name":"oldRates","type":"tuple"},{"components":[{"internalType":"uint16","name":"managementRate","type":"uint16"},{"internalType":"uint16","name":"performanceRate","type":"uint16"}],"indexed":false,"internalType":"struct Rates","name":"newRate","type":"tuple"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"RatesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"controller","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"RedeemRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"referral","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"Referral","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint40","name":"epochId","type":"uint40"},{"indexed":true,"internalType":"uint40","name":"settledId","type":"uint40"},{"indexed":false,"internalType":"uint256","name":"totalAssets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalSupply","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assetsDeposited","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesMinted","type":"uint256"}],"name":"SettleDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint40","name":"epochId","type":"uint40"},{"indexed":true,"internalType":"uint40","name":"settledId","type":"uint40"},{"indexed":false,"internalType":"uint256","name":"totalAssets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalSupply","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assetsWithdrawed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesBurned","type":"uint256"}],"name":"SettleRedeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum State","name":"state","type":"uint8"}],"name":"StateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"oldLifespan","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"newLifespan","type":"uint128"}],"name":"TotalAssetsLifespanUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"totalAssets","type":"uint256"}],"name":"TotalAssetsUpdated","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":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldManager","type":"address"},{"indexed":false,"internalType":"address","name":"newManager","type":"address"}],"name":"ValuationManagerUpdated","type":"event"},{"anonymous":false,"inputs":[],"name":"WhitelistDisabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldManager","type":"address"},{"indexed":false,"internalType":"address","name":"newManager","type":"address"}],"name":"WhitelistManagerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"authorized","type":"bool"}],"name":"WhitelistUpdated","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":"MAX_MANAGEMENT_RATE","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_PERFORMANCE_RATE","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_PROTOCOL_RATE","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"}],"name":"addToWhitelist","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":[],"name":"cancelRequestDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"sharesToRedeem","type":"uint256"}],"name":"claimSharesAndRequestRedeem","outputs":[{"internalType":"uint40","name":"requestId","type":"uint40"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"controllers","type":"address[]"}],"name":"claimSharesOnBehalf","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"address","name":"controller","type":"address"}],"name":"claimableDepositRequest","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"address","name":"controller","type":"address"}],"name":"claimableRedeemRequest","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newTotalAssets","type":"uint256"}],"name":"close","outputs":[],"stateMutability":"nonpayable","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":"shares","type":"uint256"},{"internalType":"uint256","name":"requestId","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":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"requestId","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"},{"internalType":"address","name":"controller","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"disableWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"expireTotalAssets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeRates","outputs":[{"components":[{"internalType":"uint16","name":"managementRate","type":"uint16"},{"internalType":"uint16","name":"performanceRate","type":"uint16"}],"internalType":"struct Rates","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRolesStorage","outputs":[{"components":[{"internalType":"address","name":"whitelistManager","type":"address"},{"internalType":"address","name":"feeReceiver","type":"address"},{"internalType":"address","name":"safe","type":"address"},{"internalType":"contract FeeRegistry","name":"feeRegistry","type":"address"},{"internalType":"address","name":"valuationManager","type":"address"}],"internalType":"struct Roles.RolesStorage","name":"_rolesStorage","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"address","name":"feeRegistry","type":"address"},{"internalType":"address","name":"wrappedNativeToken","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initiateClosing","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"controller","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isTotalAssetsValid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isWhitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"controller","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"controller","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"controller","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"controller","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":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"controller","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"address","name":"controller","type":"address"}],"name":"pendingDepositRequest","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"address","name":"controller","type":"address"}],"name":"pendingRedeemRequest","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"controller","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"controllers","type":"address[]"}],"name":"redeemOnBehalf","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"controller","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"requestDeposit","outputs":[{"internalType":"uint256","name":"requestId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"controller","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"referral","type":"address"}],"name":"requestDeposit","outputs":[{"internalType":"uint256","name":"requestId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"controller","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"requestRedeem","outputs":[{"internalType":"uint256","name":"requestId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"}],"name":"revokeFromWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"safe","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setOperator","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newTotalAssets","type":"uint256"}],"name":"settleDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newTotalAssets","type":"uint256"}],"name":"settleRedeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"share","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"referral","type":"address"}],"name":"syncDeposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","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":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeReceiver","type":"address"}],"name":"updateFeeReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newTotalAssets","type":"uint256"}],"name":"updateNewTotalAssets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint16","name":"managementRate","type":"uint16"},{"internalType":"uint16","name":"performanceRate","type":"uint16"}],"internalType":"struct Rates","name":"newRates","type":"tuple"}],"name":"updateRates","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"lifespan","type":"uint128"}],"name":"updateTotalAssetsLifespan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_valuationManager","type":"address"}],"name":"updateValuationManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_whitelistManager","type":"address"}],"name":"updateWhitelistManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"controller","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
0x608060405234801561001057600080fd5b5060405161610338038061610383398101604081905261002f916100f5565b801561003d5761003d610043565b5061011e565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff16156100935760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b03908116146100f25780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b60006020828403121561010757600080fd5b8151801515811461011757600080fd5b9392505050565b615fd68061012d6000396000f3fe6080604052600436106103625760003560e01c806301e1d1141461036757806301ffc9a71461038f57806306fdde03146103bf57806307a2d13a146103e1578063095ea7b3146104015780630a28a477146104215780630aebeb4e146104415780630c2b5b911461046357806318160ddd14610478578063181e7b3b1461048d578063186f0354146104ad57806323b872dd146104cf5780632542d4a6146104ef57806326c6f96c146105125780632e2d298414610532578063313ce5671461055257806338d52e0f146105795780633af32abf1461058e5780633e0a3c25146105ae5780633f4ba83a146105ce578063402d267d146105e35780634cdad5061461060357806354fd4d5014610623578063558a7297146106525780635c975abb146106725780635cfe2fe41461068757806365ccfcef146106bd578063660b88ee146106dd5780636e553f65146106fd57806370a082311461071d578063715018a61461073d5780637688c5841461075257806379ba5097146107745780637d41c86e146107895780637f649783146107a95780638456cb59146107c957806385b77f45146107de57806386af6e68146107f15780638da5cb5b14610811578063927b15df14610826578063937147e31461083b57806394bf804d1461089f57806395d89b41146108bf578063995ea21a146108d45780639c428921146108f4578063a1e5944214610909578063a43939151461091f578063a5948c8914610934578063a627df6614610947578063a8d5fd6514610967578063a9059cbb1461097a578063ae16ea8c1461099a578063b3d7f6b9146109ba578063b460af94146109da578063b6363cf2146109fa578063ba08765214610a1a578063bcd1bf3414610a3a578063c63d75b614610a5a578063c69bebe414610a7a578063c6e6f59214610a9a578063ce96cb7714610aba578063d01d073a14610ada578063d24ca58a14610aed578063d6b0f48414610b0d578063d905777e14610b22578063da39b3e714610b42578063db2088f414610b62578063dd62ed3e14610b82578063e30c397814610ba2578063eaed1d0714610bb7578063ee1f142714610bd7578063ef8b30f714610bf7578063f15be6f914610c17578063f1a76fcc14610c37578063f2fde38b14610c57578063f5a23d8d14610c77578063f886d4bd14610c97575b600080fd5b34801561037357600080fd5b5061037c610cad565b6040519081526020015b60405180910390f35b34801561039b57600080fd5b506103af6103aa366004615057565b610cbf565b6040519015158152602001610386565b3480156103cb57600080fd5b506103d4610d62565b60405161038691906150a5565b3480156103ed57600080fd5b5061037c6103fc3660046150d8565b610e03565b34801561040d57600080fd5b506103af61041c366004615106565b610e10565b34801561042d57600080fd5b5061037c61043c3660046150d8565b610e28565b34801561044d57600080fd5b5061046161045c3660046150d8565b610e43565b005b34801561046f57600080fd5b506103af610fed565b34801561048457600080fd5b5061037c61100b565b34801561049957600080fd5b5061037c6104a8366004615132565b611020565b3480156104b957600080fd5b506104c2611035565b6040516103869190615154565b3480156104db57600080fd5b506103af6104ea366004615168565b611051565b3480156104fb57600080fd5b50610505610bb881565b60405161038691906151a9565b34801561051e57600080fd5b5061037c61052d3660046151b8565b611075565b34801561053e57600080fd5b5061037c61054d3660046151e8565b611108565b34801561055e57600080fd5b5061056761115f565b60405160ff9091168152602001610386565b34801561058557600080fd5b506104c261117c565b34801561059a57600080fd5b506103af6105a936600461522a565b611197565b3480156105ba57600080fd5b506104616105c93660046152c6565b61127b565b3480156105da57600080fd5b5061046161139d565b3480156105ef57600080fd5b5061037c6105fe36600461522a565b6113af565b34801561060f57600080fd5b5061037c61061e3660046150d8565b6113d1565b34801561062f57600080fd5b50604080518082019091526006815265076302e352e360d41b60208201526103d4565b34801561065e57600080fd5b506103af61066d366004615334565b6113ec565b34801561067e57600080fd5b506103af61147e565b34801561069357600080fd5b506106a76106a23660046150d8565b611493565b60405164ffffffffff9091168152602001610386565b3480156106c957600080fd5b506104616106d836600461522a565b611540565b3480156106e957600080fd5b506104616106f8366004615389565b6115c2565b34801561070957600080fd5b5061037c6107183660046151b8565b61182f565b34801561072957600080fd5b5061037c61073836600461522a565b61183c565b34801561074957600080fd5b50610461611867565b34801561075e57600080fd5b50610767611879565b604051610386919061542a565b34801561078057600080fd5b506104616118f8565b34801561079557600080fd5b5061037c6107a43660046151e8565b611937565b3480156107b557600080fd5b506104616107c4366004615438565b6119b5565b3480156107d557600080fd5b50610461611ab9565b61037c6107ec3660046151e8565b611ac9565b3480156107fd57600080fd5b5061046161080c366004615438565b611b69565b34801561081d57600080fd5b506104c2611c67565b34801561083257600080fd5b50610461611c72565b34801561084757600080fd5b50610850611cdb565b604051610386919081516001600160a01b039081168252602080840151821690830152604080840151821690830152606080840151821690830152608092830151169181019190915260a00190565b3480156108ab57600080fd5b5061037c6108ba3660046151b8565b611d5e565b3480156108cb57600080fd5b506103d4611d6b565b3480156108e057600080fd5b5061037c6108ef3660046151b8565b611d88565b34801561090057600080fd5b50610461611e13565b34801561091557600080fd5b5061050561138881565b34801561092b57600080fd5b50610461611ef7565b61037c6109423660046154ef565b611fbc565b34801561095357600080fd5b506104616109623660046150d8565b6120a3565b34801561097357600080fd5b50306104c2565b34801561098657600080fd5b506103af610995366004615106565b612139565b3480156109a657600080fd5b506104616109b5366004615542565b612147565b3480156109c657600080fd5b5061037c6109d53660046150d8565b61218f565b3480156109e657600080fd5b5061037c6109f53660046151e8565b6121aa565b348015610a0657600080fd5b506103af610a1536600461556b565b612262565b348015610a2657600080fd5b5061037c610a353660046151e8565b61229f565b348015610a4657600080fd5b50610461610a553660046150d8565b61234a565b348015610a6657600080fd5b5061037c610a7536600461522a565b6123f1565b348015610a8657600080fd5b50610461610a9536600461522a565b612456565b348015610aa657600080fd5b5061037c610ab53660046150d8565b6124d8565b348015610ac657600080fd5b5061037c610ad536600461522a565b6124e5565b61037c610ae83660046151e8565b612580565b348015610af957600080fd5b50610461610b083660046150d8565b6127c6565b348015610b1957600080fd5b50610461612857565b348015610b2e57600080fd5b5061037c610b3d36600461522a565b6128a6565b348015610b4e57600080fd5b5061037c610b5d3660046151e8565b612904565b348015610b6e57600080fd5b5061037c610b7d366004615132565b612950565b348015610b8e57600080fd5b5061037c610b9d36600461556b565b61295e565b348015610bae57600080fd5b506104c261299a565b348015610bc357600080fd5b5061037c610bd23660046151b8565b6129a5565b348015610be357600080fd5b50610461610bf2366004615438565b612a30565b348015610c0357600080fd5b5061037c610c123660046150d8565b612af5565b348015610c2357600080fd5b50610461610c32366004615438565b612b10565b348015610c4357600080fd5b50610461610c5236600461522a565b612bcd565b348015610c6357600080fd5b50610461610c7236600461522a565b612c49565b348015610c8357600080fd5b5061037c610c923660046151b8565b612cba565b348015610ca357600080fd5b506105056103e881565b600080610cb8612d46565b5492915050565b6000632f0a18c560e01b6001600160e01b031983161480610cf0575063f815c03d60e01b6001600160e01b03198316145b80610d0b5750630ce3bbe560e41b6001600160e01b03198316145b80610d265750631883ba3960e21b6001600160e01b03198316145b80610d41575063e3bc4e6560e01b6001600160e01b03198316145b80610d5c57506001600160e01b031982166301ffc9a760e01b145b92915050565b60606000610d6e612d6a565b9050806003018054610d7f90615599565b80601f0160208091040260200160405190810160405280929190818152602001828054610dab90615599565b8015610df85780601f10610dcd57610100808354040283529160200191610df8565b820191906000526020600020905b815481529060010190602001808311610ddb57829003601f168201915b505050505091505090565b6000610d5c826000612d8e565b600033610e1e818585612dd4565b5060019392505050565b600060405163954bf3b160e01b815260040160405180910390fd5b6000610e4d612de1565b600201546001600160a01b03169050338114610e87578060405163fde82f1f60e01b8152600401610e7e9190615154565b60405180910390fd5b6000610e91612e05565b5460ff1690506001816002811115610eab57610eab6155cd565b14610ecb57806040516373cc9d4d60e01b8152600401610e7e91906155e3565b6000610ed5612de1565b9050610ee084612e29565b60018101546003820154604080516339a51be560e01b81529051610f5f936001600160a01b039081169316916339a51be59160048083019260209291908290030181865afa158015610f36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f5a919061561b565b612f08565b610f6833612f7f565b610f713361310e565b6002610f7b612e05565b805460ff19166001836002811115610f9557610f956155cd565b0217905550610fc13330610fa7612d46565b54610fb061117c565b6001600160a01b031692919061333b565b600080516020615f6a8339815191526002604051610fdf91906155e3565b60405180910390a150505050565b6000610ff7612d46565b600a01546001600160801b03164210919050565b600080611016612d6a565b6002015492915050565b600061102e838360006133a2565b9392505050565b600061103f612de1565b600201546001600160a01b0316919050565b60003361105f858285613445565b61106a858585613493565b506001949350505050565b600080611080612d46565b9050836000036110af576001600160a01b038316600090815260058201602052604090205464ffffffffff1693505b6002810154600160501b900464ffffffffff168411156111015764ffffffffff841660009081526003909101602090815260408083206001600160a01b03861684526001019091529020549050610d5c565b5092915050565b6000816001600160a01b038116331480159061112b57506111298133612262565b155b15611149576040516331d00f8160e11b815260040160405180910390fd5b6111548585856134f2565b91505b509392505050565b6000611169612d46565b60090154600160a01b900460ff16919050565b6000806111876135f9565b546001600160a01b031692915050565b6000806111a261361d565b9050826001600160a01b03166111b6612de1565b60030160009054906101000a90046001600160a01b03166001600160a01b03166339a51be56040518163ffffffff1660e01b8152600401602060405180830381865afa15801561120a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061122e919061561b565b6001600160a01b0316036112455750600192915050565b600181015460ff1661125857600161102e565b6001600160a01b03831660009081526020829052604090205460ff169392505050565b611283613641565b600061128d613673565b90506103e861ffff16826000015161ffff1611156112c2576103e8604051630343096960e31b8152600401610e7e91906151a9565b61138861ffff16826020015161ffff1611156112f557611388604051630343096960e31b8152600401610e7e91906151a9565b6000816004015442611307919061564e565b60408051808201825260058501805461ffff808216808552620100008084048316602080880182905260018c018a905560068c01805492840263ffffffff19938416909517949094179093558b51928c0151841690910293169116171790559051919250907f9eb7e8ec6516c29bbbd60a1c51902c46787a4ce63ef22701759b0b4e9dd34fe090610fdf90839087908690615661565b6113a5613641565b6113ad613697565b565b60006113b961147e565b156113c657506000919050565b610d5c600083611d88565b6000604051630aaf8c3d60e31b815260040160405180910390fd5b60006113f66136ee565b816113ff612d46565b336000818152600792909201602090815260408084206001600160a01b038916808652925292839020805494151560ff199095169490941790935590517fceb576d9f15e4e200fdb5096d64d5dfd667e16def20c1eefd14256d8e3faa2679061146d90861515815260200190565b60405180910390a350600192915050565b600080611489613714565b5460ff1692915050565b60008061149e612e05565b5460ff16905060008160028111156114b8576114b86155cd565b146114d85780604051634b0145f360e01b8152600401610e7e91906155e3565b6114e06136ee565b6114e933611197565b61150657604051630b094f2760e31b815260040160405180910390fd5b6000611513600033611d88565b90508015611528576115268133336134f2565b505b6000611535853333613738565b935050505b50919050565b611548613641565b7f27e018912099274c84ffbb1a48209e91c5b25727666d86b88a9d27c5abf4aa67611571612de1565b6004015460405161158d916001600160a01b031690849061568a565b60405180910390a18061159e612de1565b60040180546001600160a01b0319166001600160a01b039290921691909117905550565b60006115cc6138f0565b805490915060ff600160401b82041615906001600160401b03166000811580156115f35750825b90506000826001600160401b0316600114801561160f5750303b155b90508115801561161d575080155b1561163b5760405163f92ee8a960e01b815260040160405180910390fd5b84546001600160401b0319166001178555831561166457845460ff60401b1916600160401b1785555b60008880602001905181019061167a91906156ff565b90506116898160c00151613919565b6116f56040518060a0016040528083608001516001600160a01b031681526020018360e001516001600160a01b0316815260200183606001516001600160a01b031681526020018a6001600160a01b031681526020018360a001516001600160a01b031681525061392a565b611707816020015182604001516139b5565b61170f6139c7565b805161171a906139cf565b805161172690886139e0565b611734816101400151613b5b565b6117b88882610100015183610120015184600001516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611786573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117aa9190615846565b60ff16856101600151613b87565b600080516020615f6a83398151915260006040516117d691906155e3565b60405180910390a150831561182557845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b5050505050505050565b600061102e8383336134f2565b600080611847612d6a565b6001600160a01b0390931660009081526020939093525050604090205490565b61186f613641565b6113ad6000613c54565b60408051808201909152600080825260208201526000611897613673565b9050428160010154116118ce576040805180820190915260059091015461ffff808216835262010000909104166020820152919050565b6040805180820190915260069091015461ffff808216835262010000909104166020820152919050565b338061190261299a565b6001600160a01b03161461192b578060405163118cdaa760e01b8152600401610e7e9190615154565b61193481613c54565b50565b600080611942612e05565b5460ff169050600081600281111561195c5761195c6155cd565b1461197c5780604051634b0145f360e01b8152600401610e7e91906155e3565b6119846136ee565b61198d83611197565b6119aa57604051630b094f2760e31b815260040160405180910390fd5b611154858585613738565b60006119bf612de1565b546001600160a01b031690503381146119ed5780604051632c1d27eb60e11b8152600401610e7e9190615154565b60006119f761361d565b905060005b8351811015611ab3576001826000016000868481518110611a1f57611a1f615869565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff021916908315150217905550838181518110611a7057611a70615869565b60200260200101516001600160a01b0316600080516020615faa8339815191526001604051611aa3911515815260200190565b60405180910390a26001016119fc565b50505050565b611ac1613641565b6113ad613c77565b6000816001600160a01b0381163314801590611aec5750611aea8133612262565b155b15611b0a576040516331d00f8160e11b815260040160405180910390fd5b611b126136ee565b611b1a610fed565b15611b385760405163b097d84160e01b815260040160405180910390fd5b611b4183611197565b611b5e57604051630b094f2760e31b815260040160405180910390fd5b611154858585613cbe565b6000611b73612de1565b546001600160a01b03169050338114611ba15780604051632c1d27eb60e11b8152600401610e7e9190615154565b6000611bab61361d565b905060005b8351811015611ab3576000826000016000868481518110611bd357611bd3615869565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff021916908315150217905550838181518110611c2457611c24615869565b60200260200101516001600160a01b0316600080516020615faa8339815191526000604051611c57911515815260200190565b60405180910390a2600101611bb0565b600080611187613ec8565b6000611c7c612de1565b600201546001600160a01b03169050338114611cad578060405163fde82f1f60e01b8152600401610e7e9190615154565b6000611cb7612d46565b600a0180546001600160801b0319166001600160801b039290921691909117905550565b6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152611d0e612de1565b6040805160a08101825282546001600160a01b0390811682526001840154811660208301526002840154811692820192909252600383015482166060820152600490920154166080820152919050565b600061102e838333613eec565b60606000611d77612d6a565b9050806004018054610d7f90615599565b600080611d93612d46565b905083600003611dc2576001600160a01b038316600090815260058201602052604090205464ffffffffff1693505b6002810154600160501b900464ffffffffff1684116111015764ffffffffff841660009081526003909101602090815260408083206001600160a01b03861684526001019091529020549050610d5c565b611e1b6136ee565b6000611e25612d46565b336000908152600582016020526040902054600282015491925064ffffffffff90811691168114611e7257604051630378803f60e51b815264ffffffffff82166004820152602401610e7e565b64ffffffffff811660009081526003830160209081526040808320338085526001909101909252822080549290556008840154611ebe916001600160a01b039091169083610fb061117c565b604051339064ffffffffff8416907ff3df774413906479e4aa6d20ad2ad938e10990d517dc9d29909f6eaa4981ad4390600090a3505050565b611eff613641565b6000611f09612e05565b5460ff1690506000816002811115611f2357611f236155cd565b14611f435780604051634b0145f360e01b8152600401610e7e91906155e3565b6000611f4d612d46565b9050600019816001015414611f6957611f698160010154613fe0565b6001611f73612e05565b805460ff19166001836002811115611f8d57611f8d6155cd565b0217905550600080516020615f6a8339815191526001604051611fb091906155e3565b60405180910390a15050565b6000826001600160a01b0381163314801590611fdf5750611fdd8133612262565b155b15611ffd576040516331d00f8160e11b815260040160405180910390fd5b6120056136ee565b61200d610fed565b1561202b5760405163b097d84160e01b815260040160405180910390fd5b61203484611197565b61205157604051630b094f2760e31b815260040160405180910390fd5b61205c868686613cbe565b915081846001600160a01b0316846001600160a01b0316600080516020615f2a8339815191528960405161209291815260200190565b60405180910390a450949350505050565b60006120ad612de1565b600201546001600160a01b031690503381146120de578060405163fde82f1f60e01b8152600401610e7e9190615154565b60006120e8612e05565b5460ff1690506000816002811115612102576121026155cd565b146121225780604051634b0145f360e01b8152600401610e7e91906155e3565b61212b836141fd565b6121343361310e565b505050565b600033610e1e818585613493565b6000612151612de1565b600201546001600160a01b03169050338114612182578060405163fde82f1f60e01b8152600401610e7e9190615154565b61218b82614268565b5050565b60006040516366345fa160e01b815260040160405180910390fd5b60006121b46136ee565b60006121be612e05565b90506002815460ff1660028111156121d8576121d86155cd565b1480156121ed57506121eb6000846129a5565b155b15612211576121fd8560016142d3565b915061220c3385858886614310565b611157565b6001600160a01b0383163314801590612231575061222f8333612262565b155b1561224f576040516331d00f8160e11b815260040160405180910390fd5b61225a8585856143db565b91505061102e565b600061226c612d46565b6001600160a01b039384166000908152600791909101602090815260408083209490951682529290925250205460ff1690565b60006122a96136ee565b60006122b3612e05565b90506002815460ff1660028111156122cd576122cd6155cd565b1480156122e257506122e06000846129a5565b155b15612301576122f2856000612d8e565b915061220c3385858589614310565b6001600160a01b0383163314801590612321575061231f8333612262565b155b1561233f576040516331d00f8160e11b815260040160405180910390fd5b61225a8585856144db565b6000612354612de1565b600401546001600160a01b0316905033811461238557806040516314c9222d60e01b8152600401610e7e9190615154565b600261238f612e05565b5460ff1660028111156123a4576123a46155cd565b036123c257604051631cdde67b60e01b815260040160405180910390fd5b6123ca610fed565b156123e85760405163ebe435fd60e01b815260040160405180910390fd5b61218b82613fe0565b60006123fb61147e565b1561240857506000919050565b6000612412612d46565b6001600160a01b0384166000908152600591909101602052604081205464ffffffffff1691506124428285611d88565b905061244e8183612950565b949350505050565b61245e613641565b7fa92ff4390fe6943f0b30e8fe715dde86f85ab79b2b2c640a10fc094cc4036cc8612487612de1565b600101546040516124a3916001600160a01b031690849061568a565b60405180910390a1806124b4612de1565b60010180546001600160a01b0319166001600160a01b039290921691909117905550565b6000610d5c8260006142d3565b60006124ef61147e565b156124fc57506000919050565b60006125096000846129a5565b9050801580156125355750600261251e612e05565b5460ff166002811115612533576125336155cd565b145b156125465761102e6103fc8461183c565b6000612550612d46565b6001600160a01b0385166000908152600691909101602052604090205464ffffffffff16905061244e8282611020565b600061258a610fed565b6125a7576040516341e86ac160e11b815260040160405180910390fd5b60006125b1612e05565b5460ff16905060008160028111156125cb576125cb6155cd565b146125eb5780604051634b0145f360e01b8152600401610e7e91906155e3565b60006125f5612d46565b905061260033611197565b61261d57604051630b094f2760e31b815260040160405180910390fd5b34156126f65760098101546001600160a01b031661263961117c565b6001600160a01b0316036126dd573495508060080160009054906101000a90046001600160a01b03166001600160a01b031663439370b1876040518263ffffffff1660e01b81526004016000604051808303818588803b15801561269c57600080fd5b505af11580156126b0573d6000803e3d6000fd5b5050505060088201546126d891506001600160a01b03166126cf611035565b88610fb061117c565b612702565b604051636546370360e01b815260040160405180910390fd5b612702336126cf611035565b61270d8660006142d3565b925085816000016000828254612723919061564e565b90915550612733905085846145d8565b846001600160a01b0316336001600160a01b03167fc7fa05bbaa7a6c46527c364d2da9fbafe81091552e9cfa35b7fd69c27878afbc888660405161277892919061587f565b60405180910390a36000336001600160a01b0316856001600160a01b0316600080516020615f2a833981519152896040516127b591815260200190565b60405180910390a450509392505050565b60006127d0612de1565b600201546001600160a01b03169050338114612801578060405163fde82f1f60e01b8152600401610e7e9190615154565b600061280b612e05565b5460ff1690506000816002811115612825576128256155cd565b146128455780604051634b0145f360e01b8152600401610e7e91906155e3565b61284e836141fd565b61212b33612f7f565b61285f613641565b600061286961361d565b600101805460ff19169115159190911790556040517f212c6e1d3045c9581ef0adf2504dbb1d137f52f38162ccf77a16c69d14eba5c390600090a1565b60006128b061147e565b156128bd57506000919050565b60006128ca6000846129a5565b9050801580156128f6575060026128df612e05565b5460ff1660028111156128f4576128f46155cd565b145b15610d5c5761102e8361183c565b6000816001600160a01b038116331480159061292757506129258133612262565b155b15612945576040516331d00f8160e11b815260040160405180910390fd5b611154858585613eec565b600061102e8383600061460e565b600080612969612d6a565b6001600160a01b03948516600090815260019190910160209081526040808320959096168252939093525050205490565b6000806111876146a5565b6000806129b0612d46565b9050836000036129df576001600160a01b038316600090815260068201602052604090205464ffffffffff1693505b6002810154600160c81b900464ffffffffff1684116111015764ffffffffff841660009081526003909101602090815260408083206001600160a01b03861684526002019091529020549050610d5c565b6000612a3a612de1565b600201546001600160a01b03169050338114612a6b578060405163fde82f1f60e01b8152600401610e7e9190615154565b612a736136ee565b60005b8251811015612134576000612aa56000858481518110612a9857612a98615869565b60200260200101516129a5565b90508015612aec57612aea81858481518110612ac357612ac3615869565b6020026020010151868581518110612add57612add615869565b60200260200101516144db565b505b50600101612a76565b6000604051633e26cc2f60e11b815260040160405180910390fd5b6000612b1a612de1565b600201546001600160a01b03169050338114612b4b578060405163fde82f1f60e01b8152600401610e7e9190615154565b60005b8251811015612134576000612b7d6000858481518110612b7057612b70615869565b6020026020010151611d88565b90508015612bc457612bc281858481518110612b9b57612b9b615869565b6020026020010151868581518110612bb557612bb5615869565b60200260200101516134f2565b505b50600101612b4e565b612bd5613641565b7f1eee17fbeb6d1c008ca140cc7d787451b233547ba63af138cea3470a1faf33a5612bfe612de1565b54604051612c17916001600160a01b031690849061568a565b60405180910390a180612c28612de1565b80546001600160a01b0319166001600160a01b039290921691909117905550565b612c51613641565b6000612c5b6146a5565b80546001600160a01b0319166001600160a01b0384169081178255909150612c81611c67565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a35050565b600080612cc5612d46565b905083600003612cf4576001600160a01b038316600090815260068201602052604090205464ffffffffff1693505b6002810154600160c81b900464ffffffffff168411156111015764ffffffffff841660009081526003909101602090815260408083206001600160a01b03861684526002019091529020549050610d5c565b7f5c74d456014b1c0eb4368d944667a568313858a3029a650ff0cb7b56f8b57a0090565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0090565b600061102e612d9b610cad565b612da690600161564e565b612dae6146c9565b612db990600a615974565b612dc161100b565b612dcb919061564e565b859190856146e6565b6121348383836001614733565b7f7c302ed2c673c3d6b4551cf74a01ee649f887e14fd20d13dbca1b6099534d90090565b7f0e6b3200a60a991c539f47dddaca04a18eb4bcf2b53906fb44751d827f00140090565b612e316136ee565b6000612e3b612d46565b6001808201549192508101612e63576040516343ec4aed60e11b815260040160405180910390fd5b808314612e835760405163389db72f60e01b815260040160405180910390fd5b8082556000196001830155600a820154612ead90600160801b90046001600160801b031642615983565b600a830180546001600160801b0319166001600160801b03929092169190911790556040518181527ff306601d1bd9ff6895ca817f568f68463b269e4b0cf4710e5f1003592ad29f5c906020015b60405180910390a1505050565b6000612f12613673565b9050600080612f1f614818565b90925090508115612f4457612f3485836145d8565b8015612f4457612f4484826145d8565b6000612f63612f5161115f565b612f5c90600a615974565b6000612d8e565b9050612f6e8161497e565b428460020181905550505050505050565b6000612f89612d46565b600281810154600160281b900464ffffffffff1660008181526004840160205260408120909201549293509190819003612fc35750505050565b6000612fd08260006142d3565b90506000612fdc610cad565b90506000612fe861100b565b600287810154919250600091613005919064ffffffffff166159a2565b64ffffffffff8716600090815260048901602052604090206001810185905583815590915061303430866145d8565b61303e868561564e565b935061304a858461564e565b848955925061305a8760026159bf565b600289018054600160281b600160781b031916600160281b64ffffffffff9384160264ffffffffff60501b191617600160501b9285169290920291909117905560088801546130b6906001600160a01b03168a88610fb061117c565b8664ffffffffff168264ffffffffff167f26be8b1af887e484fec2868840869fd162e136268c24803bede886ab91aa29bc86868a8a6040516130fb94939291906159dc565b60405180910390a3505050505050505050565b6000613118612d46565b6002810154909150600160a01b900464ffffffffff16600061313861117c565b64ffffffffff831660009081526004850160205260408120600301549192506131618282612d8e565b90506000836001600160a01b03166370a08231886040518263ffffffff1660e01b81526004016131919190615154565b602060405180830381865afa1580156131ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131d291906159f7565b90508115806131e057508082115b156131ee5750505050505050565b60006131f8610cad565b9050600061320461100b565b6002898101549192506000916132289190600160781b900464ffffffffff166159a2565b64ffffffffff8916600090815260048b01602052604090206001810185905583815560088b015491925090613266906001600160a01b0316886149d8565b6132708685615a10565b935061327c8784615a10565b848b55925061328c8960026159bf565b60028b018054600160a01b600160f01b031916600160a01b64ffffffffff9384160264ffffffffff60c81b191617600160c81b928516929092029190911790556132e16001600160a01b0389168c308961333b565b8864ffffffffff168264ffffffffff167fa8fe241e26fead168e608ab85aa4e059a34552bad0fc6d98961122cb5a0abefd86868a8c60405161332694939291906159dc565b60405180910390a35050505050505050505050565b6040516001600160a01b038481166024830152838116604483015260648201839052611ab39186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050614a0e565b6000806133ad612d46565b64ffffffffff808616600090815260038301602090815260408083205490931680835260048501909152918120600190810154939450919290916133f1919061564e565b905060006133fd6146c9565b61340890600a615974565b64ffffffffff8416600090815260048601602052604090205461342b919061564e565b9050613439888383896146e6565b98975050505050505050565b6000613451848461295e565b9050600019811015611ab3578181101561348457828183604051637dc7a0d960e11b8152600401610e7e93929190615a23565b611ab384848484036000614733565b6001600160a01b0383166134bd576000604051634b637e8f60e11b8152600401610e7e9190615154565b6001600160a01b0382166134e757600060405163ec442f0560e01b8152600401610e7e9190615154565b612134838383614a76565b6000806134fd612d46565b6001600160a01b0384166000908152600582016020526040902054600282015491925064ffffffffff90811691600160501b9004168111156135525760405163912d1a7360e01b815260040160405180910390fd5b64ffffffffff8116600090815260038301602090815260408083206001600160a01b038816845260010190915281208054889290613591908490615a10565b909155506135a890508664ffffffffff8316612950565b92506135b5308685613493565b846001600160a01b0316846001600160a01b0316600080516020615f8a83398151915288866040516135e892919061587f565b60405180910390a350509392505050565b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e0090565b7f083cc98ab296d1a1f01854b5f7a2f47df4425a56ba7b35f7faa3a336067e480090565b3361364a611c67565b6001600160a01b0316146113ad573360405163118cdaa760e01b8152600401610e7e9190615154565b7fa5292f7ccd85acc1b3080c01f5da9af7799f2c26826bd4d79081d6511780bd0090565b61369f614a81565b60006136a9613714565b805460ff1916815590507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516136e39190615154565b60405180910390a150565b6136f661147e565b156113ad5760405163d93c066560e01b815260040160405180910390fd5b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f0330090565b6000336001600160a01b0383161480159061375a57506137588233612262565b155b1561376a5761376a823386613445565b6000613774612d46565b905060006137836000866129a5565b90508015613798576137968186876144db565b505b60028201546001600160a01b038616600090815260068401602052604090205464ffffffffff600160781b90920482169116811461382c5760006137dd600088612cba565b11156137fc5760405163cadcefcf60e01b815260040160405180910390fd5b6001600160a01b03861660009081526006840160205260409020805464ffffffffff191664ffffffffff83161790555b64ffffffffff8116600090815260038401602090815260408083206001600160a01b038a1684526002019091528120805489929061386b90849061564e565b9091555050600883015461388a9086906001600160a01b031689614a76565b8064ffffffffff16856001600160a01b0316876001600160a01b03167f1fdc681a13d8c5da54e301c7ce6542dcde4581e4725043fdab2db12ddc574506338b6040516138d7929190615a44565b60405180910390a464ffffffffff169695505050505050565b6000807ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00610d5c565b613921614aa6565b61193481614acb565b613932614aa6565b600061393c612de1565b825181546001600160a01b03199081166001600160a01b039283161783556020850151600184018054831691841691909117905560408501516002840180548316918416919091179055606085015160038401805483169184169190911790556080909401516004909201805490941691161790915550565b6139bd614aa6565b61218b8282614afd565b6113ad614aa6565b6139d7614aa6565b61193481614b2e565b6139e8614aa6565b60006139f2612d46565b600281018054600164ffffffffff60501b01600160c81b031916650100000000016501000000000160791b0117905560405190915083908390613a349061504a565b613a3f92919061568a565b604051809103906000f080158015613a5b573d6000803e3d6000fd5b506008820180546001600160a01b03199081166001600160a01b039384161790915560098301805490911691841691909117905560001960018201556000613aa161117c565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ade573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b029190615846565b905060128160ff1610613b2e5760098201805460ff60a01b1916600160a01b60ff841602179055611ab3565b600982018054601283900360ff16600160a81b0261ffff60a01b1990911617600960a11b17905550505050565b613b63614aa6565b8015611934576000613b7361361d565b6001908101805460ff191690911790555050565b613b8f614aa6565b6103e861ffff85161115613bba576103e8604051630343096960e31b8152600401610e7e91906151a9565b61138861ffff84161115613be557611388604051630343096960e31b8152600401610e7e91906151a9565b6000613bef613673565b4260018201556004810183905580546001600160a01b0319166001600160a01b0388161781559050613c2283600a615a5d565b6003820155600501805461ffff948516620100000263ffffffff19909116949095169390931793909317909155505050565b6000613c5e6146a5565b80546001600160a01b0319168155905061218b82614b9d565b613c7f6136ee565b6000613c89613714565b805460ff1916600117815590507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586136d63390565b600080613ccc600085611d88565b90508015613ce157613cdf8185866134f2565b505b6000613ceb612d46565b60028101546001600160a01b038716600090815260058301602052604090205491925064ffffffffff90811691168114613d7b576000613d2c600088611075565b1115613d4b5760405163cadcefcf60e01b815260040160405180910390fd5b6001600160a01b03861660009081526005830160205260409020805464ffffffffff191664ffffffffff83161790555b3415613e185760098201546001600160a01b0316613d9761117c565b6001600160a01b0316036126dd578160080160009054906101000a90046001600160a01b03166001600160a01b031663439370b1346040518263ffffffff1660e01b81526004016000604051808303818588803b158015613df757600080fd5b505af1158015613e0b573d6000803e3d6000fd5b5050505050349650613e35565b6008820154613e359086906001600160a01b031689610fb061117c565b64ffffffffff8116600090815260038301602090815260408083206001600160a01b038a16845260010190915281208054899290613e7490849061564e565b925050819055508064ffffffffff16856001600160a01b0316876001600160a01b03167fbb58420bb8ce44e11b84e214cc0de10ce5e7c24d0355b2815c3d758b514cae72338b6040516138d7929190615a44565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930090565b600080613ef7612d46565b6001600160a01b0384166000908152600582016020526040902054600282015491925064ffffffffff90811691600160501b900416811115613f4c5760405163912d1a7360e01b815260040160405180910390fd5b613f58868260016133a2565b64ffffffffff8216600090815260038401602090815260408083206001600160a01b0389168452600101909152812080549295508592909190613f9c908490615a10565b90915550613fad9050308688613493565b846001600160a01b0316846001600160a01b0316600080516020615f8a83398151915285896040516135e892919061587f565b613fe86136ee565b6000613ff2612d46565b60028101805464ffffffffff80821660009081526003850160205260408082208054600160281b909504841664ffffffffff199586161790559354600160781b8104831682529381208054600160a01b909504909216939092169290921790915560088201549192506001600160a01b039091169061406f61117c565b6001600160a01b03166370a08231836040518263ffffffff1660e01b815260040161409a9190615154565b602060405180830381865afa1580156140b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140db91906159f7565b905060006140e88361183c565b90508115614150576002848101805460009061410c90849064ffffffffff166159bf565b82546101009290920a64ffffffffff818102199093169183160217909155600286810154600160281b90049091166000908152600487016020526040902001839055505b80156141bc5760028481018054600f90614179908490600160781b900464ffffffffff166159bf565b82546101009290920a64ffffffffff8181021990931691831602179091556002860154600160a01b90041660009081526004860160205260409020600301829055505b600184018590556040518581527f3809c8827d04fcf6537fe5af7a5e42a8ec939c3556096ca7107842a2d44efca59060200160405180910390a15050505050565b6000614207612de1565b905061421282612e29565b60018101546003820154604080516339a51be560e01b8152905161218b936001600160a01b039081169316916339a51be59160048083019260209291908290030181865afa158015610f36573d6000803e3d6000fd5b6000614272612d46565b600a810180546001600160801b03858116600160801b81810283851617909455604080519490930490911680845260208401919091529293507f2bc73e9b849f667d30dc57236e1deed6d5368da53fe4367a550d7309ae219d779101612efb565b600061102e6142e06146c9565b6142eb90600a615974565b6142f361100b565b6142fd919061564e565b614305610cad565b612dcb90600161564e565b826001600160a01b0316856001600160a01b03161415801561433957506143378386612262565b155b1561434957614349838683613445565b81614352612d46565b8054600090614362908490615a10565b90915550614372905083826149d8565b61438f848361437f61117c565b6001600160a01b03169190614bf9565b826001600160a01b0316846001600160a01b0316866001600160a01b0316600080516020615f4a83398151915285856040516143cc92919061587f565b60405180910390a45050505050565b6000806143e6612d46565b6001600160a01b0384166000908152600682016020526040902054600282015491925064ffffffffff90811691600160c81b90041681111561443b5760405163912d1a7360e01b815260040160405180910390fd5b6144478682600161460e565b64ffffffffff8216600090815260038401602090815260408083206001600160a01b038916845260020190915281208054929550859290919061448b908490615a10565b9091555061449e9050858761437f61117c565b836001600160a01b0316856001600160a01b0316336001600160a01b0316600080516020615f4a83398151915289876040516127b592919061587f565b6000806144e6612d46565b6001600160a01b0384166000908152600682016020526040902054600282015491925064ffffffffff90811691600160c81b90041681111561453b5760405163912d1a7360e01b815260040160405180910390fd5b64ffffffffff8116600090815260038301602090815260408083206001600160a01b03881684526002019091528120805488929061457a908490615a10565b9091555061458c9050868260006133a2565b925061459b858461437f61117c565b836001600160a01b0316856001600160a01b0316336001600160a01b0316600080516020615f4a833981519152868a6040516127b592919061587f565b6001600160a01b03821661460257600060405163ec442f0560e01b8152600401610e7e9190615154565b61218b60008383614a76565b600080614619612d46565b64ffffffffff8086166000908152600383016020908152604080832054909316808352600485019091529181206001908101549394509192909161465d919061564e565b905060006146696146c9565b61467490600a615974565b64ffffffffff84166000908152600486016020526040902054614697919061564e565b9050613439888284896146e6565b7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0090565b60006146d3612d46565b60090154600160a81b900460ff16919050565b60006147156146f483614c1f565b801561471057506000848061470b5761470b615a69565b868809115b151590565b614720868686614c4c565b61472a919061564e565b95945050505050565b600061473d612d6a565b90506001600160a01b03851661476957600060405163e602df0560e01b8152600401610e7e9190615154565b6001600160a01b038416614793576000604051634a1406b160e11b8152600401610e7e9190615154565b6001600160a01b0380861660009081526001830160209081526040808320938816835292905220839055811561481157836001600160a01b0316856001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258560405161480891815260200190565b60405180910390a35b5050505050565b6000806000614825613673565b9050600061483161115f565b60ff1690506000614840611879565b905060008360020154426148549190615a10565b90506000614860610cad565b9050600061487782856000015161ffff1685614d01565b905060006148ce8261488a85600161564e565b6148949190615a10565b61489c6146c9565b6148a790600a615974565b6148af61100b565b6148b9919061564e565b60016148c68a600a615a5d565b9291906146e6565b905060006148da61100b565b905060006148f7876020015161ffff1683858c600301548c614d26565b90506000614905828661564e565b905060006149486149146146c9565b61491f90600a615974565b614929908661564e565b614933848a615a10565b61493e90600161564e565b84919060016146e6565b9050614961614955614d55565b829061271060016146e6565b9b5061496d8c82615a10565b9c5050505050505050505050509091565b6000614988613673565b600381015490915080831115612134577f03f8f938dbe4475565f0cf1c3dcf09728208c2c6065e1f717102058c51e94d0681846040516149c992919061587f565b60405180910390a15060030155565b6001600160a01b038216614a02576000604051634b637e8f60e11b8152600401610e7e9190615154565b61218b82600083614a76565b600080602060008451602086016000885af180614a31576040513d6000823e3d81fd5b50506000513d91508115614a49578060011415614a56565b6001600160a01b0384163b155b15611ab35783604051635274afe760e01b8152600401610e7e9190615154565b612134838383614de9565b614a8961147e565b6113ad57604051638dfc202b60e01b815260040160405180910390fd5b614aae614dfc565b6113ad57604051631afcd79f60e31b815260040160405180910390fd5b614ad3614aa6565b6001600160a01b03811661192b576000604051631e4fbdf760e01b8152600401610e7e9190615154565b614b05614aa6565b6000614b0f612d6a565b905060038101614b1f8482615ac6565b5060048101611ab38382615ac6565b614b36614aa6565b6000614b406135f9565b9050600080614b4e84614e16565b9150915081614b5e576012614b60565b805b83546001600160a81b031916600160a01b60ff92909216919091026001600160a01b031916176001600160a01b0394909416939093179091555050565b6000614ba7613ec8565b80546001600160a01b038481166001600160a01b031983168117845560405193945091169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3505050565b61213483846001600160a01b031663a9059cbb8585604051602401613370929190615a44565b60006002826003811115614c3557614c356155cd565b614c3f9190615b84565b60ff166001149050919050565b6000806000614c5b8686614ef2565b9150915081600003614c8057838181614c7657614c76615a69565b049250505061102e565b818411614c9757614c976003851502601118614f10565b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010185841190960395909502919093039390930492909217029150509392505050565b600080614d13858561271060016146e6565b905061115481846301e1338060016146e6565b60008284111561472a578284036000614d448761493e86600a615a5d565b9050613439818961271060016146e6565b600080614d60613673565b805460408051634cee8ab360e11b815290519293506001600160a01b03909116916399dd1566916004808201926020929091908290030181865afa158015614dac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614dd091906159f7565b9150610bb8821115614de55750610bb8919050565b5090565b614df16136ee565b612134838383614f22565b6000614e066138f0565b54600160401b900460ff16919050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290516000918291829182916001600160a01b03871691614e5d91615bb4565b600060405180830381855afa9150503d8060008114614e98576040519150601f19603f3d011682016040523d82523d6000602084013e614e9d565b606091505b5091509150818015614eb157506020815110155b15614ee557600081806020019051810190614ecc91906159f7565b905060ff8111614ee3576001969095509350505050565b505b5060009485945092505050565b60008060001983850993909202808410938190039390930393915050565b634e487b71600052806020526024601cfd5b6000614f2c612d6a565b90506001600160a01b038416614f5b5781816002016000828254614f50919061564e565b90915550614fba9050565b6001600160a01b03841660009081526020829052604090205482811015614f9b5784818460405163391434e360e21b8152600401610e7e93929190615a23565b6001600160a01b03851660009081526020839052604090209083900390555b6001600160a01b038316614fd8576002810180548390039055614ff7565b6001600160a01b03831660009081526020829052604090208054830190555b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161503c91815260200190565b60405180910390a350505050565b61035980615bd183390190565b60006020828403121561506957600080fd5b81356001600160e01b03198116811461102e57600080fd5b60005b8381101561509c578181015183820152602001615084565b50506000910152565b60208152600082518060208401526150c4816040850160208701615081565b601f01601f19169190910160400192915050565b6000602082840312156150ea57600080fd5b5035919050565b6001600160a01b038116811461193457600080fd5b6000806040838503121561511957600080fd5b8235615124816150f1565b946020939093013593505050565b6000806040838503121561514557600080fd5b50508035926020909101359150565b6001600160a01b0391909116815260200190565b60008060006060848603121561517d57600080fd5b8335615188816150f1565b92506020840135615198816150f1565b929592945050506040919091013590565b61ffff91909116815260200190565b600080604083850312156151cb57600080fd5b8235915060208301356151dd816150f1565b809150509250929050565b6000806000606084860312156151fd57600080fd5b83359250602084013561520f816150f1565b9150604084013561521f816150f1565b809150509250925092565b60006020828403121561523c57600080fd5b813561102e816150f1565b634e487b7160e01b600052604160045260246000fd5b60405161018081016001600160401b038111828210171561528057615280615247565b60405290565b604051601f8201601f191681016001600160401b03811182821017156152ae576152ae615247565b604052919050565b61ffff8116811461193457600080fd5b600060408284031280156152d957600080fd5b50604080519081016001600160401b03811182821017156152fc576152fc615247565b604052823561530a816152b6565b8152602083013561531a816152b6565b60208201529392505050565b801515811461193457600080fd5b6000806040838503121561534757600080fd5b8235615352816150f1565b915060208301356151dd81615326565b60006001600160401b0382111561537b5761537b615247565b50601f01601f191660200190565b60008060006060848603121561539e57600080fd5b83356001600160401b038111156153b457600080fd5b8401601f810186136153c557600080fd5b80356153d86153d382615362565b615286565b8181528760208385010111156153ed57600080fd5b81602084016020830137600060208383010152809550505050602084013561520f816150f1565b805161ffff908116835260209182015116910152565b60408101610d5c8284615414565b60006020828403121561544a57600080fd5b81356001600160401b0381111561546057600080fd5b8201601f8101841361547157600080fd5b80356001600160401b0381111561548a5761548a615247565b8060051b61549a60208201615286565b918252602081840181019290810190878411156154b657600080fd5b6020850194505b838510156154e457843592506154d2836150f1565b828252602094850194909101906154bd565b979650505050505050565b6000806000806080858703121561550557600080fd5b843593506020850135615517816150f1565b92506040850135615527816150f1565b91506060850135615537816150f1565b939692955090935050565b60006020828403121561555457600080fd5b81356001600160801b038116811461102e57600080fd5b6000806040838503121561557e57600080fd5b8235615589816150f1565b915060208301356151dd816150f1565b600181811c908216806155ad57607f821691505b60208210810361153a57634e487b7160e01b600052602260045260246000fd5b634e487b7160e01b600052602160045260246000fd5b602081016003831061560557634e487b7160e01b600052602160045260246000fd5b91905290565b8051615616816150f1565b919050565b60006020828403121561562d57600080fd5b815161102e816150f1565b634e487b7160e01b600052601160045260246000fd5b80820180821115610d5c57610d5c615638565b60a0810161566f8286615414565b61567c6040830185615414565b826080830152949350505050565b6001600160a01b0392831681529116602082015260400190565b600082601f8301126156b557600080fd5b81516156c36153d382615362565b8181528460208386010111156156d857600080fd5b61244e826020830160208701615081565b8051615616816152b6565b805161561681615326565b60006020828403121561571157600080fd5b81516001600160401b0381111561572757600080fd5b8201610180818503121561573a57600080fd5b61574261525d565b61574b8261560b565b815260208201516001600160401b0381111561576657600080fd5b615772868285016156a4565b60208301525060408201516001600160401b0381111561579157600080fd5b61579d868285016156a4565b6040830152506157af6060830161560b565b60608201526157c06080830161560b565b60808201526157d160a0830161560b565b60a08201526157e260c0830161560b565b60c08201526157f360e0830161560b565b60e082015261580561010083016156e9565b61010082015261581861012083016156e9565b61012082015261582b61014083016156f4565b61014082015261016091820151918101919091529392505050565b60006020828403121561585857600080fd5b815160ff8116811461102e57600080fd5b634e487b7160e01b600052603260045260246000fd5b918252602082015260400190565b6001815b60018411156158c8578085048111156158ac576158ac615638565b60018416156158ba57908102905b60019390931c928002615891565b935093915050565b6000826158df57506001610d5c565b816158ec57506000610d5c565b8160018114615902576002811461590c57615928565b6001915050610d5c565b60ff84111561591d5761591d615638565b50506001821b610d5c565b5060208310610133831016604e8410600b841016171561594b575081810a610d5c565b615958600019848461588d565b806000190482111561596c5761596c615638565b029392505050565b600061102e60ff8416836158d0565b6001600160801b038181168382160190811115610d5c57610d5c615638565b64ffffffffff8281168282160390811115610d5c57610d5c615638565b64ffffffffff8181168382160190811115610d5c57610d5c615638565b93845260208401929092526040830152606082015260800190565b600060208284031215615a0957600080fd5b5051919050565b81810381811115610d5c57610d5c615638565b6001600160a01b039390931683526020830191909152604082015260600190565b6001600160a01b03929092168252602082015260400190565b600061102e83836158d0565b634e487b7160e01b600052601260045260246000fd5b601f82111561213457806000526020600020601f840160051c81016020851015615aa65750805b601f840160051c820191505b818110156148115760008155600101615ab2565b81516001600160401b03811115615adf57615adf615247565b615af381615aed8454615599565b84615a7f565b6020601f821160018114615b275760008315615b0f5750848201515b600019600385901b1c1916600184901b178455614811565b600084815260208120601f198516915b82811015615b575787850151825560209485019460019092019101615b37565b5084821015615b755786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b600060ff831680615ba557634e487b7160e01b600052601260045260246000fd5b8060ff84160691505092915050565b60008251615bc6818460208701615081565b919091019291505056fe608060405234801561001057600080fd5b5060405161035938038061035983398101604081905261002f91610217565b6100456001600160a01b0383163360001961006b565b600080546001600160a01b0319166001600160a01b03929092169190911790555061026a565b6000836001600160a01b031663095ea7b3848460405160240161008f929190610251565b604051602081830303815290604052915060e01b6020820180516001600160e01b03838183161783525050505090506100ce848261013b60201b60201c565b6101355761012b84856001600160a01b031663095ea7b38660006040516024016100f9929190610251565b60408051808303601f1901815291905260208101805160e09390931b6001600160e01b03938416179052915061018a16565b610135848261018a565b50505050565b6000806000806020600086516020880160008a5af192503d91506000519050828015610180575081156101715780600114610180565b6000866001600160a01b03163b115b9695505050505050565b600080602060008451602086016000885af1806101ad576040513d6000823e3d81fd5b50506000513d915081156101c55780600114156101d2565b6001600160a01b0384163b155b1561013557604051635274afe760e01b81526001600160a01b038516600482015260240160405180910390fd5b6001600160a01b038116811461021457600080fd5b50565b6000806040838503121561022a57600080fd5b8251610235816101ff565b6020840151909250610246816101ff565b809150509250929050565b6001600160a01b03929092168252602082015260400190565b60e1806102786000396000f3fe60806040526004361060265760003560e01c806317fcb39b14602b578063439370b1146065575b600080fd5b348015603657600080fd5b506000546049906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b606b606d565b005b60008054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801560ba57600080fd5b505af115801560cd573d6000803e3d6000fd5b505050505056fea164736f6c634300081a000a90f46099733ed637df811df4fcc5cae4961192ca04f36da9ab64b4dd8dc9b7f5fbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db23ad33ab6a13a00aa7d06cd167b2abd03dec86af3cf3cc91759dcd3ae8411887dcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7f93f9a76c1bf3444d22400a00cb9fe990e6abe9dbb333fda48859cfee864543da164736f6c634300081a000a0000000000000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x6080604052600436106103625760003560e01c806301e1d1141461036757806301ffc9a71461038f57806306fdde03146103bf57806307a2d13a146103e1578063095ea7b3146104015780630a28a477146104215780630aebeb4e146104415780630c2b5b911461046357806318160ddd14610478578063181e7b3b1461048d578063186f0354146104ad57806323b872dd146104cf5780632542d4a6146104ef57806326c6f96c146105125780632e2d298414610532578063313ce5671461055257806338d52e0f146105795780633af32abf1461058e5780633e0a3c25146105ae5780633f4ba83a146105ce578063402d267d146105e35780634cdad5061461060357806354fd4d5014610623578063558a7297146106525780635c975abb146106725780635cfe2fe41461068757806365ccfcef146106bd578063660b88ee146106dd5780636e553f65146106fd57806370a082311461071d578063715018a61461073d5780637688c5841461075257806379ba5097146107745780637d41c86e146107895780637f649783146107a95780638456cb59146107c957806385b77f45146107de57806386af6e68146107f15780638da5cb5b14610811578063927b15df14610826578063937147e31461083b57806394bf804d1461089f57806395d89b41146108bf578063995ea21a146108d45780639c428921146108f4578063a1e5944214610909578063a43939151461091f578063a5948c8914610934578063a627df6614610947578063a8d5fd6514610967578063a9059cbb1461097a578063ae16ea8c1461099a578063b3d7f6b9146109ba578063b460af94146109da578063b6363cf2146109fa578063ba08765214610a1a578063bcd1bf3414610a3a578063c63d75b614610a5a578063c69bebe414610a7a578063c6e6f59214610a9a578063ce96cb7714610aba578063d01d073a14610ada578063d24ca58a14610aed578063d6b0f48414610b0d578063d905777e14610b22578063da39b3e714610b42578063db2088f414610b62578063dd62ed3e14610b82578063e30c397814610ba2578063eaed1d0714610bb7578063ee1f142714610bd7578063ef8b30f714610bf7578063f15be6f914610c17578063f1a76fcc14610c37578063f2fde38b14610c57578063f5a23d8d14610c77578063f886d4bd14610c97575b600080fd5b34801561037357600080fd5b5061037c610cad565b6040519081526020015b60405180910390f35b34801561039b57600080fd5b506103af6103aa366004615057565b610cbf565b6040519015158152602001610386565b3480156103cb57600080fd5b506103d4610d62565b60405161038691906150a5565b3480156103ed57600080fd5b5061037c6103fc3660046150d8565b610e03565b34801561040d57600080fd5b506103af61041c366004615106565b610e10565b34801561042d57600080fd5b5061037c61043c3660046150d8565b610e28565b34801561044d57600080fd5b5061046161045c3660046150d8565b610e43565b005b34801561046f57600080fd5b506103af610fed565b34801561048457600080fd5b5061037c61100b565b34801561049957600080fd5b5061037c6104a8366004615132565b611020565b3480156104b957600080fd5b506104c2611035565b6040516103869190615154565b3480156104db57600080fd5b506103af6104ea366004615168565b611051565b3480156104fb57600080fd5b50610505610bb881565b60405161038691906151a9565b34801561051e57600080fd5b5061037c61052d3660046151b8565b611075565b34801561053e57600080fd5b5061037c61054d3660046151e8565b611108565b34801561055e57600080fd5b5061056761115f565b60405160ff9091168152602001610386565b34801561058557600080fd5b506104c261117c565b34801561059a57600080fd5b506103af6105a936600461522a565b611197565b3480156105ba57600080fd5b506104616105c93660046152c6565b61127b565b3480156105da57600080fd5b5061046161139d565b3480156105ef57600080fd5b5061037c6105fe36600461522a565b6113af565b34801561060f57600080fd5b5061037c61061e3660046150d8565b6113d1565b34801561062f57600080fd5b50604080518082019091526006815265076302e352e360d41b60208201526103d4565b34801561065e57600080fd5b506103af61066d366004615334565b6113ec565b34801561067e57600080fd5b506103af61147e565b34801561069357600080fd5b506106a76106a23660046150d8565b611493565b60405164ffffffffff9091168152602001610386565b3480156106c957600080fd5b506104616106d836600461522a565b611540565b3480156106e957600080fd5b506104616106f8366004615389565b6115c2565b34801561070957600080fd5b5061037c6107183660046151b8565b61182f565b34801561072957600080fd5b5061037c61073836600461522a565b61183c565b34801561074957600080fd5b50610461611867565b34801561075e57600080fd5b50610767611879565b604051610386919061542a565b34801561078057600080fd5b506104616118f8565b34801561079557600080fd5b5061037c6107a43660046151e8565b611937565b3480156107b557600080fd5b506104616107c4366004615438565b6119b5565b3480156107d557600080fd5b50610461611ab9565b61037c6107ec3660046151e8565b611ac9565b3480156107fd57600080fd5b5061046161080c366004615438565b611b69565b34801561081d57600080fd5b506104c2611c67565b34801561083257600080fd5b50610461611c72565b34801561084757600080fd5b50610850611cdb565b604051610386919081516001600160a01b039081168252602080840151821690830152604080840151821690830152606080840151821690830152608092830151169181019190915260a00190565b3480156108ab57600080fd5b5061037c6108ba3660046151b8565b611d5e565b3480156108cb57600080fd5b506103d4611d6b565b3480156108e057600080fd5b5061037c6108ef3660046151b8565b611d88565b34801561090057600080fd5b50610461611e13565b34801561091557600080fd5b5061050561138881565b34801561092b57600080fd5b50610461611ef7565b61037c6109423660046154ef565b611fbc565b34801561095357600080fd5b506104616109623660046150d8565b6120a3565b34801561097357600080fd5b50306104c2565b34801561098657600080fd5b506103af610995366004615106565b612139565b3480156109a657600080fd5b506104616109b5366004615542565b612147565b3480156109c657600080fd5b5061037c6109d53660046150d8565b61218f565b3480156109e657600080fd5b5061037c6109f53660046151e8565b6121aa565b348015610a0657600080fd5b506103af610a1536600461556b565b612262565b348015610a2657600080fd5b5061037c610a353660046151e8565b61229f565b348015610a4657600080fd5b50610461610a553660046150d8565b61234a565b348015610a6657600080fd5b5061037c610a7536600461522a565b6123f1565b348015610a8657600080fd5b50610461610a9536600461522a565b612456565b348015610aa657600080fd5b5061037c610ab53660046150d8565b6124d8565b348015610ac657600080fd5b5061037c610ad536600461522a565b6124e5565b61037c610ae83660046151e8565b612580565b348015610af957600080fd5b50610461610b083660046150d8565b6127c6565b348015610b1957600080fd5b50610461612857565b348015610b2e57600080fd5b5061037c610b3d36600461522a565b6128a6565b348015610b4e57600080fd5b5061037c610b5d3660046151e8565b612904565b348015610b6e57600080fd5b5061037c610b7d366004615132565b612950565b348015610b8e57600080fd5b5061037c610b9d36600461556b565b61295e565b348015610bae57600080fd5b506104c261299a565b348015610bc357600080fd5b5061037c610bd23660046151b8565b6129a5565b348015610be357600080fd5b50610461610bf2366004615438565b612a30565b348015610c0357600080fd5b5061037c610c123660046150d8565b612af5565b348015610c2357600080fd5b50610461610c32366004615438565b612b10565b348015610c4357600080fd5b50610461610c5236600461522a565b612bcd565b348015610c6357600080fd5b50610461610c7236600461522a565b612c49565b348015610c8357600080fd5b5061037c610c923660046151b8565b612cba565b348015610ca357600080fd5b506105056103e881565b600080610cb8612d46565b5492915050565b6000632f0a18c560e01b6001600160e01b031983161480610cf0575063f815c03d60e01b6001600160e01b03198316145b80610d0b5750630ce3bbe560e41b6001600160e01b03198316145b80610d265750631883ba3960e21b6001600160e01b03198316145b80610d41575063e3bc4e6560e01b6001600160e01b03198316145b80610d5c57506001600160e01b031982166301ffc9a760e01b145b92915050565b60606000610d6e612d6a565b9050806003018054610d7f90615599565b80601f0160208091040260200160405190810160405280929190818152602001828054610dab90615599565b8015610df85780601f10610dcd57610100808354040283529160200191610df8565b820191906000526020600020905b815481529060010190602001808311610ddb57829003601f168201915b505050505091505090565b6000610d5c826000612d8e565b600033610e1e818585612dd4565b5060019392505050565b600060405163954bf3b160e01b815260040160405180910390fd5b6000610e4d612de1565b600201546001600160a01b03169050338114610e87578060405163fde82f1f60e01b8152600401610e7e9190615154565b60405180910390fd5b6000610e91612e05565b5460ff1690506001816002811115610eab57610eab6155cd565b14610ecb57806040516373cc9d4d60e01b8152600401610e7e91906155e3565b6000610ed5612de1565b9050610ee084612e29565b60018101546003820154604080516339a51be560e01b81529051610f5f936001600160a01b039081169316916339a51be59160048083019260209291908290030181865afa158015610f36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f5a919061561b565b612f08565b610f6833612f7f565b610f713361310e565b6002610f7b612e05565b805460ff19166001836002811115610f9557610f956155cd565b0217905550610fc13330610fa7612d46565b54610fb061117c565b6001600160a01b031692919061333b565b600080516020615f6a8339815191526002604051610fdf91906155e3565b60405180910390a150505050565b6000610ff7612d46565b600a01546001600160801b03164210919050565b600080611016612d6a565b6002015492915050565b600061102e838360006133a2565b9392505050565b600061103f612de1565b600201546001600160a01b0316919050565b60003361105f858285613445565b61106a858585613493565b506001949350505050565b600080611080612d46565b9050836000036110af576001600160a01b038316600090815260058201602052604090205464ffffffffff1693505b6002810154600160501b900464ffffffffff168411156111015764ffffffffff841660009081526003909101602090815260408083206001600160a01b03861684526001019091529020549050610d5c565b5092915050565b6000816001600160a01b038116331480159061112b57506111298133612262565b155b15611149576040516331d00f8160e11b815260040160405180910390fd5b6111548585856134f2565b91505b509392505050565b6000611169612d46565b60090154600160a01b900460ff16919050565b6000806111876135f9565b546001600160a01b031692915050565b6000806111a261361d565b9050826001600160a01b03166111b6612de1565b60030160009054906101000a90046001600160a01b03166001600160a01b03166339a51be56040518163ffffffff1660e01b8152600401602060405180830381865afa15801561120a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061122e919061561b565b6001600160a01b0316036112455750600192915050565b600181015460ff1661125857600161102e565b6001600160a01b03831660009081526020829052604090205460ff169392505050565b611283613641565b600061128d613673565b90506103e861ffff16826000015161ffff1611156112c2576103e8604051630343096960e31b8152600401610e7e91906151a9565b61138861ffff16826020015161ffff1611156112f557611388604051630343096960e31b8152600401610e7e91906151a9565b6000816004015442611307919061564e565b60408051808201825260058501805461ffff808216808552620100008084048316602080880182905260018c018a905560068c01805492840263ffffffff19938416909517949094179093558b51928c0151841690910293169116171790559051919250907f9eb7e8ec6516c29bbbd60a1c51902c46787a4ce63ef22701759b0b4e9dd34fe090610fdf90839087908690615661565b6113a5613641565b6113ad613697565b565b60006113b961147e565b156113c657506000919050565b610d5c600083611d88565b6000604051630aaf8c3d60e31b815260040160405180910390fd5b60006113f66136ee565b816113ff612d46565b336000818152600792909201602090815260408084206001600160a01b038916808652925292839020805494151560ff199095169490941790935590517fceb576d9f15e4e200fdb5096d64d5dfd667e16def20c1eefd14256d8e3faa2679061146d90861515815260200190565b60405180910390a350600192915050565b600080611489613714565b5460ff1692915050565b60008061149e612e05565b5460ff16905060008160028111156114b8576114b86155cd565b146114d85780604051634b0145f360e01b8152600401610e7e91906155e3565b6114e06136ee565b6114e933611197565b61150657604051630b094f2760e31b815260040160405180910390fd5b6000611513600033611d88565b90508015611528576115268133336134f2565b505b6000611535853333613738565b935050505b50919050565b611548613641565b7f27e018912099274c84ffbb1a48209e91c5b25727666d86b88a9d27c5abf4aa67611571612de1565b6004015460405161158d916001600160a01b031690849061568a565b60405180910390a18061159e612de1565b60040180546001600160a01b0319166001600160a01b039290921691909117905550565b60006115cc6138f0565b805490915060ff600160401b82041615906001600160401b03166000811580156115f35750825b90506000826001600160401b0316600114801561160f5750303b155b90508115801561161d575080155b1561163b5760405163f92ee8a960e01b815260040160405180910390fd5b84546001600160401b0319166001178555831561166457845460ff60401b1916600160401b1785555b60008880602001905181019061167a91906156ff565b90506116898160c00151613919565b6116f56040518060a0016040528083608001516001600160a01b031681526020018360e001516001600160a01b0316815260200183606001516001600160a01b031681526020018a6001600160a01b031681526020018360a001516001600160a01b031681525061392a565b611707816020015182604001516139b5565b61170f6139c7565b805161171a906139cf565b805161172690886139e0565b611734816101400151613b5b565b6117b88882610100015183610120015184600001516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611786573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117aa9190615846565b60ff16856101600151613b87565b600080516020615f6a83398151915260006040516117d691906155e3565b60405180910390a150831561182557845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b5050505050505050565b600061102e8383336134f2565b600080611847612d6a565b6001600160a01b0390931660009081526020939093525050604090205490565b61186f613641565b6113ad6000613c54565b60408051808201909152600080825260208201526000611897613673565b9050428160010154116118ce576040805180820190915260059091015461ffff808216835262010000909104166020820152919050565b6040805180820190915260069091015461ffff808216835262010000909104166020820152919050565b338061190261299a565b6001600160a01b03161461192b578060405163118cdaa760e01b8152600401610e7e9190615154565b61193481613c54565b50565b600080611942612e05565b5460ff169050600081600281111561195c5761195c6155cd565b1461197c5780604051634b0145f360e01b8152600401610e7e91906155e3565b6119846136ee565b61198d83611197565b6119aa57604051630b094f2760e31b815260040160405180910390fd5b611154858585613738565b60006119bf612de1565b546001600160a01b031690503381146119ed5780604051632c1d27eb60e11b8152600401610e7e9190615154565b60006119f761361d565b905060005b8351811015611ab3576001826000016000868481518110611a1f57611a1f615869565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff021916908315150217905550838181518110611a7057611a70615869565b60200260200101516001600160a01b0316600080516020615faa8339815191526001604051611aa3911515815260200190565b60405180910390a26001016119fc565b50505050565b611ac1613641565b6113ad613c77565b6000816001600160a01b0381163314801590611aec5750611aea8133612262565b155b15611b0a576040516331d00f8160e11b815260040160405180910390fd5b611b126136ee565b611b1a610fed565b15611b385760405163b097d84160e01b815260040160405180910390fd5b611b4183611197565b611b5e57604051630b094f2760e31b815260040160405180910390fd5b611154858585613cbe565b6000611b73612de1565b546001600160a01b03169050338114611ba15780604051632c1d27eb60e11b8152600401610e7e9190615154565b6000611bab61361d565b905060005b8351811015611ab3576000826000016000868481518110611bd357611bd3615869565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff021916908315150217905550838181518110611c2457611c24615869565b60200260200101516001600160a01b0316600080516020615faa8339815191526000604051611c57911515815260200190565b60405180910390a2600101611bb0565b600080611187613ec8565b6000611c7c612de1565b600201546001600160a01b03169050338114611cad578060405163fde82f1f60e01b8152600401610e7e9190615154565b6000611cb7612d46565b600a0180546001600160801b0319166001600160801b039290921691909117905550565b6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152611d0e612de1565b6040805160a08101825282546001600160a01b0390811682526001840154811660208301526002840154811692820192909252600383015482166060820152600490920154166080820152919050565b600061102e838333613eec565b60606000611d77612d6a565b9050806004018054610d7f90615599565b600080611d93612d46565b905083600003611dc2576001600160a01b038316600090815260058201602052604090205464ffffffffff1693505b6002810154600160501b900464ffffffffff1684116111015764ffffffffff841660009081526003909101602090815260408083206001600160a01b03861684526001019091529020549050610d5c565b611e1b6136ee565b6000611e25612d46565b336000908152600582016020526040902054600282015491925064ffffffffff90811691168114611e7257604051630378803f60e51b815264ffffffffff82166004820152602401610e7e565b64ffffffffff811660009081526003830160209081526040808320338085526001909101909252822080549290556008840154611ebe916001600160a01b039091169083610fb061117c565b604051339064ffffffffff8416907ff3df774413906479e4aa6d20ad2ad938e10990d517dc9d29909f6eaa4981ad4390600090a3505050565b611eff613641565b6000611f09612e05565b5460ff1690506000816002811115611f2357611f236155cd565b14611f435780604051634b0145f360e01b8152600401610e7e91906155e3565b6000611f4d612d46565b9050600019816001015414611f6957611f698160010154613fe0565b6001611f73612e05565b805460ff19166001836002811115611f8d57611f8d6155cd565b0217905550600080516020615f6a8339815191526001604051611fb091906155e3565b60405180910390a15050565b6000826001600160a01b0381163314801590611fdf5750611fdd8133612262565b155b15611ffd576040516331d00f8160e11b815260040160405180910390fd5b6120056136ee565b61200d610fed565b1561202b5760405163b097d84160e01b815260040160405180910390fd5b61203484611197565b61205157604051630b094f2760e31b815260040160405180910390fd5b61205c868686613cbe565b915081846001600160a01b0316846001600160a01b0316600080516020615f2a8339815191528960405161209291815260200190565b60405180910390a450949350505050565b60006120ad612de1565b600201546001600160a01b031690503381146120de578060405163fde82f1f60e01b8152600401610e7e9190615154565b60006120e8612e05565b5460ff1690506000816002811115612102576121026155cd565b146121225780604051634b0145f360e01b8152600401610e7e91906155e3565b61212b836141fd565b6121343361310e565b505050565b600033610e1e818585613493565b6000612151612de1565b600201546001600160a01b03169050338114612182578060405163fde82f1f60e01b8152600401610e7e9190615154565b61218b82614268565b5050565b60006040516366345fa160e01b815260040160405180910390fd5b60006121b46136ee565b60006121be612e05565b90506002815460ff1660028111156121d8576121d86155cd565b1480156121ed57506121eb6000846129a5565b155b15612211576121fd8560016142d3565b915061220c3385858886614310565b611157565b6001600160a01b0383163314801590612231575061222f8333612262565b155b1561224f576040516331d00f8160e11b815260040160405180910390fd5b61225a8585856143db565b91505061102e565b600061226c612d46565b6001600160a01b039384166000908152600791909101602090815260408083209490951682529290925250205460ff1690565b60006122a96136ee565b60006122b3612e05565b90506002815460ff1660028111156122cd576122cd6155cd565b1480156122e257506122e06000846129a5565b155b15612301576122f2856000612d8e565b915061220c3385858589614310565b6001600160a01b0383163314801590612321575061231f8333612262565b155b1561233f576040516331d00f8160e11b815260040160405180910390fd5b61225a8585856144db565b6000612354612de1565b600401546001600160a01b0316905033811461238557806040516314c9222d60e01b8152600401610e7e9190615154565b600261238f612e05565b5460ff1660028111156123a4576123a46155cd565b036123c257604051631cdde67b60e01b815260040160405180910390fd5b6123ca610fed565b156123e85760405163ebe435fd60e01b815260040160405180910390fd5b61218b82613fe0565b60006123fb61147e565b1561240857506000919050565b6000612412612d46565b6001600160a01b0384166000908152600591909101602052604081205464ffffffffff1691506124428285611d88565b905061244e8183612950565b949350505050565b61245e613641565b7fa92ff4390fe6943f0b30e8fe715dde86f85ab79b2b2c640a10fc094cc4036cc8612487612de1565b600101546040516124a3916001600160a01b031690849061568a565b60405180910390a1806124b4612de1565b60010180546001600160a01b0319166001600160a01b039290921691909117905550565b6000610d5c8260006142d3565b60006124ef61147e565b156124fc57506000919050565b60006125096000846129a5565b9050801580156125355750600261251e612e05565b5460ff166002811115612533576125336155cd565b145b156125465761102e6103fc8461183c565b6000612550612d46565b6001600160a01b0385166000908152600691909101602052604090205464ffffffffff16905061244e8282611020565b600061258a610fed565b6125a7576040516341e86ac160e11b815260040160405180910390fd5b60006125b1612e05565b5460ff16905060008160028111156125cb576125cb6155cd565b146125eb5780604051634b0145f360e01b8152600401610e7e91906155e3565b60006125f5612d46565b905061260033611197565b61261d57604051630b094f2760e31b815260040160405180910390fd5b34156126f65760098101546001600160a01b031661263961117c565b6001600160a01b0316036126dd573495508060080160009054906101000a90046001600160a01b03166001600160a01b031663439370b1876040518263ffffffff1660e01b81526004016000604051808303818588803b15801561269c57600080fd5b505af11580156126b0573d6000803e3d6000fd5b5050505060088201546126d891506001600160a01b03166126cf611035565b88610fb061117c565b612702565b604051636546370360e01b815260040160405180910390fd5b612702336126cf611035565b61270d8660006142d3565b925085816000016000828254612723919061564e565b90915550612733905085846145d8565b846001600160a01b0316336001600160a01b03167fc7fa05bbaa7a6c46527c364d2da9fbafe81091552e9cfa35b7fd69c27878afbc888660405161277892919061587f565b60405180910390a36000336001600160a01b0316856001600160a01b0316600080516020615f2a833981519152896040516127b591815260200190565b60405180910390a450509392505050565b60006127d0612de1565b600201546001600160a01b03169050338114612801578060405163fde82f1f60e01b8152600401610e7e9190615154565b600061280b612e05565b5460ff1690506000816002811115612825576128256155cd565b146128455780604051634b0145f360e01b8152600401610e7e91906155e3565b61284e836141fd565b61212b33612f7f565b61285f613641565b600061286961361d565b600101805460ff19169115159190911790556040517f212c6e1d3045c9581ef0adf2504dbb1d137f52f38162ccf77a16c69d14eba5c390600090a1565b60006128b061147e565b156128bd57506000919050565b60006128ca6000846129a5565b9050801580156128f6575060026128df612e05565b5460ff1660028111156128f4576128f46155cd565b145b15610d5c5761102e8361183c565b6000816001600160a01b038116331480159061292757506129258133612262565b155b15612945576040516331d00f8160e11b815260040160405180910390fd5b611154858585613eec565b600061102e8383600061460e565b600080612969612d6a565b6001600160a01b03948516600090815260019190910160209081526040808320959096168252939093525050205490565b6000806111876146a5565b6000806129b0612d46565b9050836000036129df576001600160a01b038316600090815260068201602052604090205464ffffffffff1693505b6002810154600160c81b900464ffffffffff1684116111015764ffffffffff841660009081526003909101602090815260408083206001600160a01b03861684526002019091529020549050610d5c565b6000612a3a612de1565b600201546001600160a01b03169050338114612a6b578060405163fde82f1f60e01b8152600401610e7e9190615154565b612a736136ee565b60005b8251811015612134576000612aa56000858481518110612a9857612a98615869565b60200260200101516129a5565b90508015612aec57612aea81858481518110612ac357612ac3615869565b6020026020010151868581518110612add57612add615869565b60200260200101516144db565b505b50600101612a76565b6000604051633e26cc2f60e11b815260040160405180910390fd5b6000612b1a612de1565b600201546001600160a01b03169050338114612b4b578060405163fde82f1f60e01b8152600401610e7e9190615154565b60005b8251811015612134576000612b7d6000858481518110612b7057612b70615869565b6020026020010151611d88565b90508015612bc457612bc281858481518110612b9b57612b9b615869565b6020026020010151868581518110612bb557612bb5615869565b60200260200101516134f2565b505b50600101612b4e565b612bd5613641565b7f1eee17fbeb6d1c008ca140cc7d787451b233547ba63af138cea3470a1faf33a5612bfe612de1565b54604051612c17916001600160a01b031690849061568a565b60405180910390a180612c28612de1565b80546001600160a01b0319166001600160a01b039290921691909117905550565b612c51613641565b6000612c5b6146a5565b80546001600160a01b0319166001600160a01b0384169081178255909150612c81611c67565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a35050565b600080612cc5612d46565b905083600003612cf4576001600160a01b038316600090815260068201602052604090205464ffffffffff1693505b6002810154600160c81b900464ffffffffff168411156111015764ffffffffff841660009081526003909101602090815260408083206001600160a01b03861684526002019091529020549050610d5c565b7f5c74d456014b1c0eb4368d944667a568313858a3029a650ff0cb7b56f8b57a0090565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0090565b600061102e612d9b610cad565b612da690600161564e565b612dae6146c9565b612db990600a615974565b612dc161100b565b612dcb919061564e565b859190856146e6565b6121348383836001614733565b7f7c302ed2c673c3d6b4551cf74a01ee649f887e14fd20d13dbca1b6099534d90090565b7f0e6b3200a60a991c539f47dddaca04a18eb4bcf2b53906fb44751d827f00140090565b612e316136ee565b6000612e3b612d46565b6001808201549192508101612e63576040516343ec4aed60e11b815260040160405180910390fd5b808314612e835760405163389db72f60e01b815260040160405180910390fd5b8082556000196001830155600a820154612ead90600160801b90046001600160801b031642615983565b600a830180546001600160801b0319166001600160801b03929092169190911790556040518181527ff306601d1bd9ff6895ca817f568f68463b269e4b0cf4710e5f1003592ad29f5c906020015b60405180910390a1505050565b6000612f12613673565b9050600080612f1f614818565b90925090508115612f4457612f3485836145d8565b8015612f4457612f4484826145d8565b6000612f63612f5161115f565b612f5c90600a615974565b6000612d8e565b9050612f6e8161497e565b428460020181905550505050505050565b6000612f89612d46565b600281810154600160281b900464ffffffffff1660008181526004840160205260408120909201549293509190819003612fc35750505050565b6000612fd08260006142d3565b90506000612fdc610cad565b90506000612fe861100b565b600287810154919250600091613005919064ffffffffff166159a2565b64ffffffffff8716600090815260048901602052604090206001810185905583815590915061303430866145d8565b61303e868561564e565b935061304a858461564e565b848955925061305a8760026159bf565b600289018054600160281b600160781b031916600160281b64ffffffffff9384160264ffffffffff60501b191617600160501b9285169290920291909117905560088801546130b6906001600160a01b03168a88610fb061117c565b8664ffffffffff168264ffffffffff167f26be8b1af887e484fec2868840869fd162e136268c24803bede886ab91aa29bc86868a8a6040516130fb94939291906159dc565b60405180910390a3505050505050505050565b6000613118612d46565b6002810154909150600160a01b900464ffffffffff16600061313861117c565b64ffffffffff831660009081526004850160205260408120600301549192506131618282612d8e565b90506000836001600160a01b03166370a08231886040518263ffffffff1660e01b81526004016131919190615154565b602060405180830381865afa1580156131ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131d291906159f7565b90508115806131e057508082115b156131ee5750505050505050565b60006131f8610cad565b9050600061320461100b565b6002898101549192506000916132289190600160781b900464ffffffffff166159a2565b64ffffffffff8916600090815260048b01602052604090206001810185905583815560088b015491925090613266906001600160a01b0316886149d8565b6132708685615a10565b935061327c8784615a10565b848b55925061328c8960026159bf565b60028b018054600160a01b600160f01b031916600160a01b64ffffffffff9384160264ffffffffff60c81b191617600160c81b928516929092029190911790556132e16001600160a01b0389168c308961333b565b8864ffffffffff168264ffffffffff167fa8fe241e26fead168e608ab85aa4e059a34552bad0fc6d98961122cb5a0abefd86868a8c60405161332694939291906159dc565b60405180910390a35050505050505050505050565b6040516001600160a01b038481166024830152838116604483015260648201839052611ab39186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050614a0e565b6000806133ad612d46565b64ffffffffff808616600090815260038301602090815260408083205490931680835260048501909152918120600190810154939450919290916133f1919061564e565b905060006133fd6146c9565b61340890600a615974565b64ffffffffff8416600090815260048601602052604090205461342b919061564e565b9050613439888383896146e6565b98975050505050505050565b6000613451848461295e565b9050600019811015611ab3578181101561348457828183604051637dc7a0d960e11b8152600401610e7e93929190615a23565b611ab384848484036000614733565b6001600160a01b0383166134bd576000604051634b637e8f60e11b8152600401610e7e9190615154565b6001600160a01b0382166134e757600060405163ec442f0560e01b8152600401610e7e9190615154565b612134838383614a76565b6000806134fd612d46565b6001600160a01b0384166000908152600582016020526040902054600282015491925064ffffffffff90811691600160501b9004168111156135525760405163912d1a7360e01b815260040160405180910390fd5b64ffffffffff8116600090815260038301602090815260408083206001600160a01b038816845260010190915281208054889290613591908490615a10565b909155506135a890508664ffffffffff8316612950565b92506135b5308685613493565b846001600160a01b0316846001600160a01b0316600080516020615f8a83398151915288866040516135e892919061587f565b60405180910390a350509392505050565b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e0090565b7f083cc98ab296d1a1f01854b5f7a2f47df4425a56ba7b35f7faa3a336067e480090565b3361364a611c67565b6001600160a01b0316146113ad573360405163118cdaa760e01b8152600401610e7e9190615154565b7fa5292f7ccd85acc1b3080c01f5da9af7799f2c26826bd4d79081d6511780bd0090565b61369f614a81565b60006136a9613714565b805460ff1916815590507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516136e39190615154565b60405180910390a150565b6136f661147e565b156113ad5760405163d93c066560e01b815260040160405180910390fd5b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f0330090565b6000336001600160a01b0383161480159061375a57506137588233612262565b155b1561376a5761376a823386613445565b6000613774612d46565b905060006137836000866129a5565b90508015613798576137968186876144db565b505b60028201546001600160a01b038616600090815260068401602052604090205464ffffffffff600160781b90920482169116811461382c5760006137dd600088612cba565b11156137fc5760405163cadcefcf60e01b815260040160405180910390fd5b6001600160a01b03861660009081526006840160205260409020805464ffffffffff191664ffffffffff83161790555b64ffffffffff8116600090815260038401602090815260408083206001600160a01b038a1684526002019091528120805489929061386b90849061564e565b9091555050600883015461388a9086906001600160a01b031689614a76565b8064ffffffffff16856001600160a01b0316876001600160a01b03167f1fdc681a13d8c5da54e301c7ce6542dcde4581e4725043fdab2db12ddc574506338b6040516138d7929190615a44565b60405180910390a464ffffffffff169695505050505050565b6000807ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00610d5c565b613921614aa6565b61193481614acb565b613932614aa6565b600061393c612de1565b825181546001600160a01b03199081166001600160a01b039283161783556020850151600184018054831691841691909117905560408501516002840180548316918416919091179055606085015160038401805483169184169190911790556080909401516004909201805490941691161790915550565b6139bd614aa6565b61218b8282614afd565b6113ad614aa6565b6139d7614aa6565b61193481614b2e565b6139e8614aa6565b60006139f2612d46565b600281018054600164ffffffffff60501b01600160c81b031916650100000000016501000000000160791b0117905560405190915083908390613a349061504a565b613a3f92919061568a565b604051809103906000f080158015613a5b573d6000803e3d6000fd5b506008820180546001600160a01b03199081166001600160a01b039384161790915560098301805490911691841691909117905560001960018201556000613aa161117c565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ade573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b029190615846565b905060128160ff1610613b2e5760098201805460ff60a01b1916600160a01b60ff841602179055611ab3565b600982018054601283900360ff16600160a81b0261ffff60a01b1990911617600960a11b17905550505050565b613b63614aa6565b8015611934576000613b7361361d565b6001908101805460ff191690911790555050565b613b8f614aa6565b6103e861ffff85161115613bba576103e8604051630343096960e31b8152600401610e7e91906151a9565b61138861ffff84161115613be557611388604051630343096960e31b8152600401610e7e91906151a9565b6000613bef613673565b4260018201556004810183905580546001600160a01b0319166001600160a01b0388161781559050613c2283600a615a5d565b6003820155600501805461ffff948516620100000263ffffffff19909116949095169390931793909317909155505050565b6000613c5e6146a5565b80546001600160a01b0319168155905061218b82614b9d565b613c7f6136ee565b6000613c89613714565b805460ff1916600117815590507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586136d63390565b600080613ccc600085611d88565b90508015613ce157613cdf8185866134f2565b505b6000613ceb612d46565b60028101546001600160a01b038716600090815260058301602052604090205491925064ffffffffff90811691168114613d7b576000613d2c600088611075565b1115613d4b5760405163cadcefcf60e01b815260040160405180910390fd5b6001600160a01b03861660009081526005830160205260409020805464ffffffffff191664ffffffffff83161790555b3415613e185760098201546001600160a01b0316613d9761117c565b6001600160a01b0316036126dd578160080160009054906101000a90046001600160a01b03166001600160a01b031663439370b1346040518263ffffffff1660e01b81526004016000604051808303818588803b158015613df757600080fd5b505af1158015613e0b573d6000803e3d6000fd5b5050505050349650613e35565b6008820154613e359086906001600160a01b031689610fb061117c565b64ffffffffff8116600090815260038301602090815260408083206001600160a01b038a16845260010190915281208054899290613e7490849061564e565b925050819055508064ffffffffff16856001600160a01b0316876001600160a01b03167fbb58420bb8ce44e11b84e214cc0de10ce5e7c24d0355b2815c3d758b514cae72338b6040516138d7929190615a44565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930090565b600080613ef7612d46565b6001600160a01b0384166000908152600582016020526040902054600282015491925064ffffffffff90811691600160501b900416811115613f4c5760405163912d1a7360e01b815260040160405180910390fd5b613f58868260016133a2565b64ffffffffff8216600090815260038401602090815260408083206001600160a01b0389168452600101909152812080549295508592909190613f9c908490615a10565b90915550613fad9050308688613493565b846001600160a01b0316846001600160a01b0316600080516020615f8a83398151915285896040516135e892919061587f565b613fe86136ee565b6000613ff2612d46565b60028101805464ffffffffff80821660009081526003850160205260408082208054600160281b909504841664ffffffffff199586161790559354600160781b8104831682529381208054600160a01b909504909216939092169290921790915560088201549192506001600160a01b039091169061406f61117c565b6001600160a01b03166370a08231836040518263ffffffff1660e01b815260040161409a9190615154565b602060405180830381865afa1580156140b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140db91906159f7565b905060006140e88361183c565b90508115614150576002848101805460009061410c90849064ffffffffff166159bf565b82546101009290920a64ffffffffff818102199093169183160217909155600286810154600160281b90049091166000908152600487016020526040902001839055505b80156141bc5760028481018054600f90614179908490600160781b900464ffffffffff166159bf565b82546101009290920a64ffffffffff8181021990931691831602179091556002860154600160a01b90041660009081526004860160205260409020600301829055505b600184018590556040518581527f3809c8827d04fcf6537fe5af7a5e42a8ec939c3556096ca7107842a2d44efca59060200160405180910390a15050505050565b6000614207612de1565b905061421282612e29565b60018101546003820154604080516339a51be560e01b8152905161218b936001600160a01b039081169316916339a51be59160048083019260209291908290030181865afa158015610f36573d6000803e3d6000fd5b6000614272612d46565b600a810180546001600160801b03858116600160801b81810283851617909455604080519490930490911680845260208401919091529293507f2bc73e9b849f667d30dc57236e1deed6d5368da53fe4367a550d7309ae219d779101612efb565b600061102e6142e06146c9565b6142eb90600a615974565b6142f361100b565b6142fd919061564e565b614305610cad565b612dcb90600161564e565b826001600160a01b0316856001600160a01b03161415801561433957506143378386612262565b155b1561434957614349838683613445565b81614352612d46565b8054600090614362908490615a10565b90915550614372905083826149d8565b61438f848361437f61117c565b6001600160a01b03169190614bf9565b826001600160a01b0316846001600160a01b0316866001600160a01b0316600080516020615f4a83398151915285856040516143cc92919061587f565b60405180910390a45050505050565b6000806143e6612d46565b6001600160a01b0384166000908152600682016020526040902054600282015491925064ffffffffff90811691600160c81b90041681111561443b5760405163912d1a7360e01b815260040160405180910390fd5b6144478682600161460e565b64ffffffffff8216600090815260038401602090815260408083206001600160a01b038916845260020190915281208054929550859290919061448b908490615a10565b9091555061449e9050858761437f61117c565b836001600160a01b0316856001600160a01b0316336001600160a01b0316600080516020615f4a83398151915289876040516127b592919061587f565b6000806144e6612d46565b6001600160a01b0384166000908152600682016020526040902054600282015491925064ffffffffff90811691600160c81b90041681111561453b5760405163912d1a7360e01b815260040160405180910390fd5b64ffffffffff8116600090815260038301602090815260408083206001600160a01b03881684526002019091528120805488929061457a908490615a10565b9091555061458c9050868260006133a2565b925061459b858461437f61117c565b836001600160a01b0316856001600160a01b0316336001600160a01b0316600080516020615f4a833981519152868a6040516127b592919061587f565b6001600160a01b03821661460257600060405163ec442f0560e01b8152600401610e7e9190615154565b61218b60008383614a76565b600080614619612d46565b64ffffffffff8086166000908152600383016020908152604080832054909316808352600485019091529181206001908101549394509192909161465d919061564e565b905060006146696146c9565b61467490600a615974565b64ffffffffff84166000908152600486016020526040902054614697919061564e565b9050613439888284896146e6565b7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0090565b60006146d3612d46565b60090154600160a81b900460ff16919050565b60006147156146f483614c1f565b801561471057506000848061470b5761470b615a69565b868809115b151590565b614720868686614c4c565b61472a919061564e565b95945050505050565b600061473d612d6a565b90506001600160a01b03851661476957600060405163e602df0560e01b8152600401610e7e9190615154565b6001600160a01b038416614793576000604051634a1406b160e11b8152600401610e7e9190615154565b6001600160a01b0380861660009081526001830160209081526040808320938816835292905220839055811561481157836001600160a01b0316856001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258560405161480891815260200190565b60405180910390a35b5050505050565b6000806000614825613673565b9050600061483161115f565b60ff1690506000614840611879565b905060008360020154426148549190615a10565b90506000614860610cad565b9050600061487782856000015161ffff1685614d01565b905060006148ce8261488a85600161564e565b6148949190615a10565b61489c6146c9565b6148a790600a615974565b6148af61100b565b6148b9919061564e565b60016148c68a600a615a5d565b9291906146e6565b905060006148da61100b565b905060006148f7876020015161ffff1683858c600301548c614d26565b90506000614905828661564e565b905060006149486149146146c9565b61491f90600a615974565b614929908661564e565b614933848a615a10565b61493e90600161564e565b84919060016146e6565b9050614961614955614d55565b829061271060016146e6565b9b5061496d8c82615a10565b9c5050505050505050505050509091565b6000614988613673565b600381015490915080831115612134577f03f8f938dbe4475565f0cf1c3dcf09728208c2c6065e1f717102058c51e94d0681846040516149c992919061587f565b60405180910390a15060030155565b6001600160a01b038216614a02576000604051634b637e8f60e11b8152600401610e7e9190615154565b61218b82600083614a76565b600080602060008451602086016000885af180614a31576040513d6000823e3d81fd5b50506000513d91508115614a49578060011415614a56565b6001600160a01b0384163b155b15611ab35783604051635274afe760e01b8152600401610e7e9190615154565b612134838383614de9565b614a8961147e565b6113ad57604051638dfc202b60e01b815260040160405180910390fd5b614aae614dfc565b6113ad57604051631afcd79f60e31b815260040160405180910390fd5b614ad3614aa6565b6001600160a01b03811661192b576000604051631e4fbdf760e01b8152600401610e7e9190615154565b614b05614aa6565b6000614b0f612d6a565b905060038101614b1f8482615ac6565b5060048101611ab38382615ac6565b614b36614aa6565b6000614b406135f9565b9050600080614b4e84614e16565b9150915081614b5e576012614b60565b805b83546001600160a81b031916600160a01b60ff92909216919091026001600160a01b031916176001600160a01b0394909416939093179091555050565b6000614ba7613ec8565b80546001600160a01b038481166001600160a01b031983168117845560405193945091169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3505050565b61213483846001600160a01b031663a9059cbb8585604051602401613370929190615a44565b60006002826003811115614c3557614c356155cd565b614c3f9190615b84565b60ff166001149050919050565b6000806000614c5b8686614ef2565b9150915081600003614c8057838181614c7657614c76615a69565b049250505061102e565b818411614c9757614c976003851502601118614f10565b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010185841190960395909502919093039390930492909217029150509392505050565b600080614d13858561271060016146e6565b905061115481846301e1338060016146e6565b60008284111561472a578284036000614d448761493e86600a615a5d565b9050613439818961271060016146e6565b600080614d60613673565b805460408051634cee8ab360e11b815290519293506001600160a01b03909116916399dd1566916004808201926020929091908290030181865afa158015614dac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614dd091906159f7565b9150610bb8821115614de55750610bb8919050565b5090565b614df16136ee565b612134838383614f22565b6000614e066138f0565b54600160401b900460ff16919050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290516000918291829182916001600160a01b03871691614e5d91615bb4565b600060405180830381855afa9150503d8060008114614e98576040519150601f19603f3d011682016040523d82523d6000602084013e614e9d565b606091505b5091509150818015614eb157506020815110155b15614ee557600081806020019051810190614ecc91906159f7565b905060ff8111614ee3576001969095509350505050565b505b5060009485945092505050565b60008060001983850993909202808410938190039390930393915050565b634e487b71600052806020526024601cfd5b6000614f2c612d6a565b90506001600160a01b038416614f5b5781816002016000828254614f50919061564e565b90915550614fba9050565b6001600160a01b03841660009081526020829052604090205482811015614f9b5784818460405163391434e360e21b8152600401610e7e93929190615a23565b6001600160a01b03851660009081526020839052604090209083900390555b6001600160a01b038316614fd8576002810180548390039055614ff7565b6001600160a01b03831660009081526020829052604090208054830190555b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161503c91815260200190565b60405180910390a350505050565b61035980615bd183390190565b60006020828403121561506957600080fd5b81356001600160e01b03198116811461102e57600080fd5b60005b8381101561509c578181015183820152602001615084565b50506000910152565b60208152600082518060208401526150c4816040850160208701615081565b601f01601f19169190910160400192915050565b6000602082840312156150ea57600080fd5b5035919050565b6001600160a01b038116811461193457600080fd5b6000806040838503121561511957600080fd5b8235615124816150f1565b946020939093013593505050565b6000806040838503121561514557600080fd5b50508035926020909101359150565b6001600160a01b0391909116815260200190565b60008060006060848603121561517d57600080fd5b8335615188816150f1565b92506020840135615198816150f1565b929592945050506040919091013590565b61ffff91909116815260200190565b600080604083850312156151cb57600080fd5b8235915060208301356151dd816150f1565b809150509250929050565b6000806000606084860312156151fd57600080fd5b83359250602084013561520f816150f1565b9150604084013561521f816150f1565b809150509250925092565b60006020828403121561523c57600080fd5b813561102e816150f1565b634e487b7160e01b600052604160045260246000fd5b60405161018081016001600160401b038111828210171561528057615280615247565b60405290565b604051601f8201601f191681016001600160401b03811182821017156152ae576152ae615247565b604052919050565b61ffff8116811461193457600080fd5b600060408284031280156152d957600080fd5b50604080519081016001600160401b03811182821017156152fc576152fc615247565b604052823561530a816152b6565b8152602083013561531a816152b6565b60208201529392505050565b801515811461193457600080fd5b6000806040838503121561534757600080fd5b8235615352816150f1565b915060208301356151dd81615326565b60006001600160401b0382111561537b5761537b615247565b50601f01601f191660200190565b60008060006060848603121561539e57600080fd5b83356001600160401b038111156153b457600080fd5b8401601f810186136153c557600080fd5b80356153d86153d382615362565b615286565b8181528760208385010111156153ed57600080fd5b81602084016020830137600060208383010152809550505050602084013561520f816150f1565b805161ffff908116835260209182015116910152565b60408101610d5c8284615414565b60006020828403121561544a57600080fd5b81356001600160401b0381111561546057600080fd5b8201601f8101841361547157600080fd5b80356001600160401b0381111561548a5761548a615247565b8060051b61549a60208201615286565b918252602081840181019290810190878411156154b657600080fd5b6020850194505b838510156154e457843592506154d2836150f1565b828252602094850194909101906154bd565b979650505050505050565b6000806000806080858703121561550557600080fd5b843593506020850135615517816150f1565b92506040850135615527816150f1565b91506060850135615537816150f1565b939692955090935050565b60006020828403121561555457600080fd5b81356001600160801b038116811461102e57600080fd5b6000806040838503121561557e57600080fd5b8235615589816150f1565b915060208301356151dd816150f1565b600181811c908216806155ad57607f821691505b60208210810361153a57634e487b7160e01b600052602260045260246000fd5b634e487b7160e01b600052602160045260246000fd5b602081016003831061560557634e487b7160e01b600052602160045260246000fd5b91905290565b8051615616816150f1565b919050565b60006020828403121561562d57600080fd5b815161102e816150f1565b634e487b7160e01b600052601160045260246000fd5b80820180821115610d5c57610d5c615638565b60a0810161566f8286615414565b61567c6040830185615414565b826080830152949350505050565b6001600160a01b0392831681529116602082015260400190565b600082601f8301126156b557600080fd5b81516156c36153d382615362565b8181528460208386010111156156d857600080fd5b61244e826020830160208701615081565b8051615616816152b6565b805161561681615326565b60006020828403121561571157600080fd5b81516001600160401b0381111561572757600080fd5b8201610180818503121561573a57600080fd5b61574261525d565b61574b8261560b565b815260208201516001600160401b0381111561576657600080fd5b615772868285016156a4565b60208301525060408201516001600160401b0381111561579157600080fd5b61579d868285016156a4565b6040830152506157af6060830161560b565b60608201526157c06080830161560b565b60808201526157d160a0830161560b565b60a08201526157e260c0830161560b565b60c08201526157f360e0830161560b565b60e082015261580561010083016156e9565b61010082015261581861012083016156e9565b61012082015261582b61014083016156f4565b61014082015261016091820151918101919091529392505050565b60006020828403121561585857600080fd5b815160ff8116811461102e57600080fd5b634e487b7160e01b600052603260045260246000fd5b918252602082015260400190565b6001815b60018411156158c8578085048111156158ac576158ac615638565b60018416156158ba57908102905b60019390931c928002615891565b935093915050565b6000826158df57506001610d5c565b816158ec57506000610d5c565b8160018114615902576002811461590c57615928565b6001915050610d5c565b60ff84111561591d5761591d615638565b50506001821b610d5c565b5060208310610133831016604e8410600b841016171561594b575081810a610d5c565b615958600019848461588d565b806000190482111561596c5761596c615638565b029392505050565b600061102e60ff8416836158d0565b6001600160801b038181168382160190811115610d5c57610d5c615638565b64ffffffffff8281168282160390811115610d5c57610d5c615638565b64ffffffffff8181168382160190811115610d5c57610d5c615638565b93845260208401929092526040830152606082015260800190565b600060208284031215615a0957600080fd5b5051919050565b81810381811115610d5c57610d5c615638565b6001600160a01b039390931683526020830191909152604082015260600190565b6001600160a01b03929092168252602082015260400190565b600061102e83836158d0565b634e487b7160e01b600052601260045260246000fd5b601f82111561213457806000526020600020601f840160051c81016020851015615aa65750805b601f840160051c820191505b818110156148115760008155600101615ab2565b81516001600160401b03811115615adf57615adf615247565b615af381615aed8454615599565b84615a7f565b6020601f821160018114615b275760008315615b0f5750848201515b600019600385901b1c1916600184901b178455614811565b600084815260208120601f198516915b82811015615b575787850151825560209485019460019092019101615b37565b5084821015615b755786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b600060ff831680615ba557634e487b7160e01b600052601260045260246000fd5b8060ff84160691505092915050565b60008251615bc6818460208701615081565b919091019291505056fe608060405234801561001057600080fd5b5060405161035938038061035983398101604081905261002f91610217565b6100456001600160a01b0383163360001961006b565b600080546001600160a01b0319166001600160a01b03929092169190911790555061026a565b6000836001600160a01b031663095ea7b3848460405160240161008f929190610251565b604051602081830303815290604052915060e01b6020820180516001600160e01b03838183161783525050505090506100ce848261013b60201b60201c565b6101355761012b84856001600160a01b031663095ea7b38660006040516024016100f9929190610251565b60408051808303601f1901815291905260208101805160e09390931b6001600160e01b03938416179052915061018a16565b610135848261018a565b50505050565b6000806000806020600086516020880160008a5af192503d91506000519050828015610180575081156101715780600114610180565b6000866001600160a01b03163b115b9695505050505050565b600080602060008451602086016000885af1806101ad576040513d6000823e3d81fd5b50506000513d915081156101c55780600114156101d2565b6001600160a01b0384163b155b1561013557604051635274afe760e01b81526001600160a01b038516600482015260240160405180910390fd5b6001600160a01b038116811461021457600080fd5b50565b6000806040838503121561022a57600080fd5b8251610235816101ff565b6020840151909250610246816101ff565b809150509250929050565b6001600160a01b03929092168252602082015260400190565b60e1806102786000396000f3fe60806040526004361060265760003560e01c806317fcb39b14602b578063439370b1146065575b600080fd5b348015603657600080fd5b506000546049906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b606b606d565b005b60008054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801560ba57600080fd5b505af115801560cd573d6000803e3d6000fd5b505050505056fea164736f6c634300081a000a90f46099733ed637df811df4fcc5cae4961192ca04f36da9ab64b4dd8dc9b7f5fbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db23ad33ab6a13a00aa7d06cd167b2abd03dec86af3cf3cc91759dcd3ae8411887dcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7f93f9a76c1bf3444d22400a00cb9fe990e6abe9dbb333fda48859cfee864543da164736f6c634300081a000a
Net Worth in USD
Net Worth in ETH
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
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.