ERC-20
Source Code
Overview
Max Total Supply
30,705.957119 Re7mUSD
Holders
925
Market
Price
$0.00 @ 0.000000 ETH
Onchain Market Cap
-
Circulating Supply Market Cap
-
Other Info
Token Contract (WITH 6 Decimals)
Balance
0.995525 Re7mUSDValue
$0.00Loading...
Loading
Loading...
Loading
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xe9De3063...0dCd60597 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
EulerEarn
Compiler Version
v0.8.26+commit.8a97fa7a
Optimization Enabled:
Yes with 200 runs
Other Settings:
london EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.26;
import {
MarketConfig,
PendingUint136,
PendingAddress,
MarketAllocation,
IEulerEarnBase,
IEulerEarnStaticTyping
} from "./interfaces/IEulerEarn.sol";
import {IEulerEarnFactory} from "./interfaces/IEulerEarnFactory.sol";
import {PendingLib} from "./libraries/PendingLib.sol";
import {ConstantsLib} from "./libraries/ConstantsLib.sol";
import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {EventsLib} from "./libraries/EventsLib.sol";
import {SafeERC20Permit2Lib} from "./libraries/SafeERC20Permit2Lib.sol";
import {UtilsLib, WAD} from "./libraries/UtilsLib.sol";
import {SafeCast} from "../lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol";
import {IERC20Metadata} from "../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {Context} from "../lib/openzeppelin-contracts/contracts/utils/Context.sol";
import {ReentrancyGuard} from "../lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol";
import {Ownable2Step, Ownable} from "../lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol";
import {
IERC20,
IERC4626,
ERC20,
ERC4626,
Math,
SafeERC20
} from "../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC4626.sol";
import {EVCUtil} from "../lib/ethereum-vault-connector/src/utils/EVCUtil.sol";
/// @title EulerEarn
/// @author Forked with gratitude from Morpho Labs. Inspired by Silo Labs.
/// @custom:contact [email protected]
/// @custom:contact [email protected]
/// @notice ERC4626 compliant vault allowing users to deposit assets to any ERC4626 strategy vault allowed by the factory.
contract EulerEarn is ReentrancyGuard, ERC4626, Ownable2Step, EVCUtil, IEulerEarnStaticTyping {
using Math for uint256;
using UtilsLib for uint256;
using SafeCast for uint256;
using SafeERC20 for IERC20;
using SafeERC20Permit2Lib for IERC20;
using PendingLib for MarketConfig;
using PendingLib for PendingUint136;
using PendingLib for PendingAddress;
/* IMMUTABLES */
/// @inheritdoc IEulerEarnBase
address public immutable permit2Address;
/// @inheritdoc IEulerEarnBase
address public immutable creator;
/* STORAGE */
/// @inheritdoc IEulerEarnBase
address public curator;
/// @inheritdoc IEulerEarnBase
mapping(address => bool) public isAllocator;
/// @inheritdoc IEulerEarnBase
address public guardian;
/// @inheritdoc IEulerEarnStaticTyping
mapping(IERC4626 => MarketConfig) public config;
/// @inheritdoc IEulerEarnBase
uint256 public timelock;
/// @inheritdoc IEulerEarnStaticTyping
PendingAddress public pendingGuardian;
/// @inheritdoc IEulerEarnStaticTyping
mapping(IERC4626 => PendingUint136) public pendingCap;
/// @inheritdoc IEulerEarnStaticTyping
PendingUint136 public pendingTimelock;
/// @inheritdoc IEulerEarnBase
uint96 public fee;
/// @inheritdoc IEulerEarnBase
address public feeRecipient;
/// @inheritdoc IEulerEarnBase
IERC4626[] public supplyQueue;
/// @inheritdoc IEulerEarnBase
IERC4626[] public withdrawQueue;
/// @inheritdoc IEulerEarnBase
uint256 public lastTotalAssets;
/// @inheritdoc IEulerEarnBase
uint256 public lostAssets;
/// @dev "Overrides" the ERC20's storage variable to be able to modify it.
string private _name;
/// @dev "Overrides" the ERC20's storage variable to be able to modify it.
string private _symbol;
/* CONSTRUCTOR */
/// @dev Initializes the contract.
/// @param owner The owner of the contract.
/// @param evc The EVC address.
/// @param permit2 The address of the Permit2 contract.
/// @param initialTimelock The initial timelock.
/// @param _asset The address of the underlying asset.
/// @param __name The name of the Earn vault.
/// @param __symbol The symbol of the Earn vault.
/// @dev We pass "" as name and symbol to the ERC20 because these are overriden in this contract.
/// This means that the contract deviates slightly from the ERC2612 standard.
constructor(
address owner,
address evc,
address permit2,
uint256 initialTimelock,
address _asset,
string memory __name,
string memory __symbol
) ERC4626(IERC20(_asset)) ERC20("", "") Ownable(owner) EVCUtil(evc) {
if (initialTimelock != 0) _checkTimelockBounds(initialTimelock);
_setTimelock(initialTimelock);
_name = __name;
emit EventsLib.SetName(__name);
_symbol = __symbol;
emit EventsLib.SetSymbol(__symbol);
permit2Address = permit2;
creator = msg.sender;
}
/* MODIFIERS */
/// @dev Reverts if the caller doesn't have the curator role.
modifier onlyCuratorRole() {
address msgSender = _msgSenderOnlyEVCAccountOwner();
if (msgSender != curator && msgSender != owner()) revert ErrorsLib.NotCuratorRole();
_;
}
/// @dev Reverts if the caller doesn't have the allocator role.
modifier onlyAllocatorRole() {
address msgSender = _msgSenderOnlyEVCAccountOwner();
if (!isAllocator[msgSender] && msgSender != curator && msgSender != owner()) {
revert ErrorsLib.NotAllocatorRole();
}
_;
}
/// @dev Reverts if the caller doesn't have the guardian role.
modifier onlyGuardianRole() {
address msgSender = _msgSenderOnlyEVCAccountOwner();
if (msgSender != owner() && msgSender != guardian) revert ErrorsLib.NotGuardianRole();
_;
}
/// @dev Reverts if the caller doesn't have the curator nor the guardian role.
modifier onlyCuratorOrGuardianRole() {
address msgSender = _msgSenderOnlyEVCAccountOwner();
if (msgSender != guardian && msgSender != curator && msgSender != owner()) {
revert ErrorsLib.NotCuratorNorGuardianRole();
}
_;
}
/// @dev Makes sure conditions are met to accept a pending value.
/// @dev Reverts if:
/// - there's no pending value;
/// - the timelock has not elapsed since the pending value has been submitted.
modifier afterTimelock(uint256 validAt) {
if (validAt == 0) revert ErrorsLib.NoPendingValue();
if (block.timestamp < validAt) revert ErrorsLib.TimelockNotElapsed();
_;
}
/* ONLY OWNER FUNCTIONS */
/*
/// @inheritdoc IEulerEarnBase
function setName(string memory newName) external onlyOwner {
_name = newName;
emit EventsLib.SetName(newName);
}
/// @inheritdoc IEulerEarnBase
function setSymbol(string memory newSymbol) external onlyOwner {
_symbol = newSymbol;
emit EventsLib.SetSymbol(newSymbol);
}
*/
/// @inheritdoc IEulerEarnBase
function setCurator(address newCurator) external onlyOwner {
if (newCurator == curator) revert ErrorsLib.AlreadySet();
curator = newCurator;
emit EventsLib.SetCurator(newCurator);
}
/// @inheritdoc IEulerEarnBase
function setIsAllocator(address newAllocator, bool newIsAllocator) external onlyOwner {
if (isAllocator[newAllocator] == newIsAllocator) revert ErrorsLib.AlreadySet();
isAllocator[newAllocator] = newIsAllocator;
emit EventsLib.SetIsAllocator(newAllocator, newIsAllocator);
}
/// @inheritdoc IEulerEarnBase
function submitTimelock(uint256 newTimelock) external onlyOwner {
if (newTimelock == timelock) revert ErrorsLib.AlreadySet();
if (pendingTimelock.validAt != 0) revert ErrorsLib.AlreadyPending();
_checkTimelockBounds(newTimelock);
if (newTimelock > timelock) {
_setTimelock(newTimelock);
} else {
// Safe "unchecked" cast because newTimelock <= MAX_TIMELOCK.
pendingTimelock.update(uint136(newTimelock), timelock);
emit EventsLib.SubmitTimelock(newTimelock);
}
}
/// @inheritdoc IEulerEarnBase
function setFee(uint256 newFee) external nonReentrant onlyOwner {
if (newFee == fee) revert ErrorsLib.AlreadySet();
if (newFee > ConstantsLib.MAX_FEE) revert ErrorsLib.MaxFeeExceeded();
if (newFee != 0 && feeRecipient == address(0)) revert ErrorsLib.ZeroFeeRecipient();
// Accrue interest and fee using the previous fee set before changing it.
_accrueInterest();
// Safe "unchecked" cast because newFee <= MAX_FEE.
fee = uint96(newFee);
emit EventsLib.SetFee(_msgSender(), fee);
}
/// @inheritdoc IEulerEarnBase
function setFeeRecipient(address newFeeRecipient) external nonReentrant onlyOwner {
if (newFeeRecipient == feeRecipient) revert ErrorsLib.AlreadySet();
if (newFeeRecipient == address(0) && fee != 0) revert ErrorsLib.ZeroFeeRecipient();
// Accrue interest and fee to the previous fee recipient set before changing it.
_accrueInterest();
feeRecipient = newFeeRecipient;
emit EventsLib.SetFeeRecipient(newFeeRecipient);
}
/// @inheritdoc IEulerEarnBase
function submitGuardian(address newGuardian) external onlyOwner {
if (newGuardian == guardian) revert ErrorsLib.AlreadySet();
if (pendingGuardian.validAt != 0) revert ErrorsLib.AlreadyPending();
if (guardian == address(0)) {
_setGuardian(newGuardian);
} else {
pendingGuardian.update(newGuardian, timelock);
emit EventsLib.SubmitGuardian(newGuardian);
}
}
/* ONLY CURATOR FUNCTIONS */
/// @inheritdoc IEulerEarnBase
function submitCap(IERC4626 id, uint256 newSupplyCap) external nonReentrant onlyCuratorRole {
if (id.asset() != asset()) revert ErrorsLib.InconsistentAsset(id);
if (pendingCap[id].validAt != 0) revert ErrorsLib.AlreadyPending();
if (config[id].removableAt != 0) revert ErrorsLib.PendingRemoval();
// For the sake of backwards compatibility, the max allowed cap can either be set to type(uint184).max or type(uint136).max.
newSupplyCap = newSupplyCap == type(uint184).max ? type(uint136).max : newSupplyCap;
uint256 supplyCap = config[id].cap;
if (newSupplyCap == supplyCap) revert ErrorsLib.AlreadySet();
if (newSupplyCap < supplyCap) {
_setCap(id, newSupplyCap.toUint136());
} else {
if (!IEulerEarnFactory(creator).isStrategyAllowed(address(id))) revert ErrorsLib.UnauthorizedMarket(id);
pendingCap[id].update(newSupplyCap.toUint136(), timelock);
emit EventsLib.SubmitCap(_msgSender(), id, newSupplyCap);
}
}
/// @inheritdoc IEulerEarnBase
function submitMarketRemoval(IERC4626 id) external onlyCuratorRole {
if (config[id].removableAt != 0) revert ErrorsLib.AlreadyPending();
if (config[id].cap != 0) revert ErrorsLib.NonZeroCap();
if (!config[id].enabled) revert ErrorsLib.MarketNotEnabled(id);
if (pendingCap[id].validAt != 0) revert ErrorsLib.PendingCap(id);
// Safe "unchecked" cast because timelock <= MAX_TIMELOCK.
config[id].removableAt = uint64(block.timestamp + timelock);
emit EventsLib.SubmitMarketRemoval(_msgSender(), id);
}
/* ONLY ALLOCATOR FUNCTIONS */
/// @inheritdoc IEulerEarnBase
function setSupplyQueue(IERC4626[] calldata newSupplyQueue) external onlyAllocatorRole {
uint256 length = newSupplyQueue.length;
if (length > ConstantsLib.MAX_QUEUE_LENGTH) revert ErrorsLib.MaxQueueLengthExceeded();
for (uint256 i; i < length; ++i) {
if (config[newSupplyQueue[i]].cap == 0) revert ErrorsLib.UnauthorizedMarket(newSupplyQueue[i]);
}
supplyQueue = newSupplyQueue;
emit EventsLib.SetSupplyQueue(_msgSender(), newSupplyQueue);
}
/// @inheritdoc IEulerEarnBase
function updateWithdrawQueue(uint256[] calldata indexes) external onlyAllocatorRole {
uint256 newLength = indexes.length;
uint256 currLength = withdrawQueue.length;
bool[] memory seen = new bool[](currLength);
IERC4626[] memory newWithdrawQueue = new IERC4626[](newLength);
for (uint256 i; i < newLength; ++i) {
uint256 prevIndex = indexes[i];
// If prevIndex >= currLength, it will revert with native "Index out of bounds".
IERC4626 id = withdrawQueue[prevIndex];
if (seen[prevIndex]) revert ErrorsLib.DuplicateMarket(id);
seen[prevIndex] = true;
newWithdrawQueue[i] = id;
}
for (uint256 i; i < currLength; ++i) {
if (!seen[i]) {
IERC4626 id = withdrawQueue[i];
if (config[id].cap != 0) revert ErrorsLib.InvalidMarketRemovalNonZeroCap(id);
if (pendingCap[id].validAt != 0) revert ErrorsLib.PendingCap(id);
if (expectedSupplyAssets(id) != 0) {
if (config[id].removableAt == 0) revert ErrorsLib.InvalidMarketRemovalNonZeroSupply(id);
if (block.timestamp < config[id].removableAt) {
revert ErrorsLib.InvalidMarketRemovalTimelockNotElapsed(id);
}
}
delete config[id];
}
}
withdrawQueue = newWithdrawQueue;
emit EventsLib.SetWithdrawQueue(_msgSender(), newWithdrawQueue);
}
/// @inheritdoc IEulerEarnBase
function reallocate(MarketAllocation[] calldata allocations) external nonReentrant onlyAllocatorRole {
address msgSender = _msgSender();
uint256 totalSupplied;
uint256 totalWithdrawn;
for (uint256 i; i < allocations.length; ++i) {
MarketAllocation memory allocation = allocations[i];
IERC4626 id = allocation.id;
if (!config[id].enabled) revert ErrorsLib.MarketNotEnabled(id);
uint256 supplyShares = config[id].balance;
uint256 supplyAssets = id.previewRedeem(supplyShares);
uint256 withdrawn = supplyAssets.zeroFloorSub(allocation.assets);
if (withdrawn > 0) {
// Guarantees that unknown frontrunning donations can be withdrawn, in order to disable a market.
uint256 shares;
if (allocation.assets == 0) {
shares = supplyShares;
withdrawn = 0;
}
uint256 withdrawnAssets;
uint256 withdrawnShares;
if (shares == 0) {
withdrawnAssets = withdrawn;
withdrawnShares = id.withdraw(withdrawn, address(this), address(this));
} else {
withdrawnAssets = id.redeem(shares, address(this), address(this));
withdrawnShares = shares;
}
config[id].balance = uint112(supplyShares - withdrawnShares);
emit EventsLib.ReallocateWithdraw(msgSender, id, withdrawnAssets, withdrawnShares);
totalWithdrawn += withdrawnAssets;
} else {
uint256 suppliedAssets = allocation.assets == type(uint256).max
? totalWithdrawn.zeroFloorSub(totalSupplied)
: allocation.assets.zeroFloorSub(supplyAssets);
if (suppliedAssets == 0) continue;
uint256 supplyCap = config[id].cap;
if (supplyAssets + suppliedAssets > supplyCap) revert ErrorsLib.SupplyCapExceeded(id);
// The vaults's underlying asset is guaranteed to be the vault's asset because it has a non-zero supply cap.
uint256 suppliedShares = id.deposit(suppliedAssets, address(this));
config[id].balance = (supplyShares + suppliedShares).toUint112();
emit EventsLib.ReallocateSupply(msgSender, id, suppliedAssets, suppliedShares);
totalSupplied += suppliedAssets;
}
}
if (totalWithdrawn != totalSupplied) revert ErrorsLib.InconsistentReallocation();
}
/* REVOKE FUNCTIONS */
/// @inheritdoc IEulerEarnBase
function revokePendingTimelock() external onlyGuardianRole {
delete pendingTimelock;
emit EventsLib.RevokePendingTimelock(_msgSender());
}
/// @inheritdoc IEulerEarnBase
function revokePendingGuardian() external onlyGuardianRole {
delete pendingGuardian;
emit EventsLib.RevokePendingGuardian(_msgSender());
}
/// @inheritdoc IEulerEarnBase
function revokePendingCap(IERC4626 id) external onlyCuratorOrGuardianRole {
delete pendingCap[id];
emit EventsLib.RevokePendingCap(_msgSender(), id);
}
/// @inheritdoc IEulerEarnBase
function revokePendingMarketRemoval(IERC4626 id) external onlyCuratorOrGuardianRole {
delete config[id].removableAt;
emit EventsLib.RevokePendingMarketRemoval(_msgSender(), id);
}
/* EXTERNAL */
/// @inheritdoc IEulerEarnBase
function supplyQueueLength() external view returns (uint256) {
return supplyQueue.length;
}
/// @inheritdoc IEulerEarnBase
function withdrawQueueLength() external view returns (uint256) {
return withdrawQueue.length;
}
/// @inheritdoc IEulerEarnBase
function maxWithdrawFromStrategy(IERC4626 id) public view returns (uint256) {
return UtilsLib.min(id.maxWithdraw(address(this)), expectedSupplyAssets(id));
}
/// @inheritdoc IEulerEarnBase
function expectedSupplyAssets(IERC4626 id) public view returns (uint256) {
return id.previewRedeem(config[id].balance);
}
/// @inheritdoc IEulerEarnBase
function acceptTimelock() external afterTimelock(pendingTimelock.validAt) {
_setTimelock(pendingTimelock.value);
}
/// @inheritdoc IEulerEarnBase
function acceptGuardian() external afterTimelock(pendingGuardian.validAt) {
_setGuardian(pendingGuardian.value);
}
/// @inheritdoc IEulerEarnBase
function acceptCap(IERC4626 id) external afterTimelock(pendingCap[id].validAt) {
if (!IEulerEarnFactory(creator).isStrategyAllowed(address(id))) revert ErrorsLib.UnauthorizedMarket(id);
// Safe "unchecked" cast because pendingCap <= type(uint136).max.
_setCap(id, uint136(pendingCap[id].value));
}
/* ERC4626 (PUBLIC) */
/// @inheritdoc IERC20Metadata
function name() public view override(IERC20Metadata, ERC20) returns (string memory) {
return _name;
}
/// @inheritdoc IERC20Metadata
function symbol() public view override(IERC20Metadata, ERC20) returns (string memory) {
return _symbol;
}
/// @inheritdoc IERC4626
/// @dev Warning: May be higher than the actual max deposit due to duplicate vaults in the supplyQueue.
/// @dev If deposit would throw ZeroShares error, function returns 0.
function maxDeposit(address) public view override returns (uint256) {
uint256 suppliable = _maxDeposit();
return _convertToShares(suppliable, Math.Rounding.Floor) == 0 ? 0 : suppliable;
}
/// @inheritdoc IERC4626
/// @dev Warning: May be higher than the actual max mint due to duplicate vaults in the supplyQueue.
function maxMint(address) public view override returns (uint256) {
uint256 suppliable = _maxDeposit();
return _convertToShares(suppliable, Math.Rounding.Floor);
}
/// @inheritdoc IERC4626
/// @dev Warning: May be lower than the actual amount of assets that can be withdrawn by `owner` due to conversion
/// roundings between shares and assets.
function maxWithdraw(address owner) public view override returns (uint256 assets) {
(assets,,) = _maxWithdraw(owner);
}
/// @inheritdoc IERC4626
/// @dev Warning: May be lower than the actual amount of shares that can be redeemed by `owner` due to conversion
/// roundings between shares and assets.
function maxRedeem(address owner) public view override returns (uint256) {
(uint256 assets, uint256 newTotalSupply, uint256 newTotalAssets) = _maxWithdraw(owner);
return _convertToSharesWithTotals(assets, newTotalSupply, newTotalAssets, Math.Rounding.Floor);
}
/// @inheritdoc IERC4626
function deposit(uint256 assets, address receiver) public override nonReentrant returns (uint256 shares) {
_accrueInterest();
shares = _convertToSharesWithTotals(assets, totalSupply(), lastTotalAssets, Math.Rounding.Floor);
if (shares == 0) revert ErrorsLib.ZeroShares();
_deposit(_msgSender(), receiver, assets, shares);
}
/// @inheritdoc IERC4626
function mint(uint256 shares, address receiver) public override nonReentrant returns (uint256 assets) {
_accrueInterest();
assets = _convertToAssetsWithTotals(shares, totalSupply(), lastTotalAssets, Math.Rounding.Ceil);
_deposit(_msgSender(), receiver, assets, shares);
}
/// @inheritdoc IERC4626
function withdraw(uint256 assets, address receiver, address owner)
public
override
nonReentrant
returns (uint256 shares)
{
_accrueInterest();
// Do not call expensive `maxWithdraw` and optimistically withdraw assets.
shares = _convertToSharesWithTotals(assets, totalSupply(), lastTotalAssets, Math.Rounding.Ceil);
_withdraw(_msgSender(), receiver, owner, assets, shares);
}
/// @inheritdoc IERC4626
function redeem(uint256 shares, address receiver, address owner)
public
override
nonReentrant
returns (uint256 assets)
{
_accrueInterest();
// Do not call expensive `maxRedeem` and optimistically redeem shares.
assets = _convertToAssetsWithTotals(shares, totalSupply(), lastTotalAssets, Math.Rounding.Floor);
// Since losses are not realized, exchange rate is never < 1 and zero assets check is not needed.
_withdraw(_msgSender(), receiver, owner, assets, shares);
}
/// @inheritdoc IERC4626
/// @dev totalAssets is the sum of the vault's assets on the strategy vaults plus the lost assets (see corresponding
/// docs in IEulerEarn.sol).
function totalAssets() public view override returns (uint256) {
(, uint256 newTotalAssets,) = _accruedFeeAndAssets();
return newTotalAssets;
}
/* ERC4626 (INTERNAL) */
/// @dev Returns the maximum amount of asset (`assets`) that the `owner` can withdraw from the vault, as well as the
/// new vault's total supply (`newTotalSupply`) and total assets (`newTotalAssets`).
function _maxWithdraw(address owner)
internal
view
returns (uint256 assets, uint256 newTotalSupply, uint256 newTotalAssets)
{
uint256 feeShares;
(feeShares, newTotalAssets,) = _accruedFeeAndAssets();
newTotalSupply = totalSupply() + feeShares;
assets = _convertToAssetsWithTotals(balanceOf(owner), newTotalSupply, newTotalAssets, Math.Rounding.Floor);
assets -= _simulateWithdrawStrategy(assets);
}
/// @dev Returns the maximum amount of assets that the Earn vault can supply to the strategy vaults.
function _maxDeposit() internal view returns (uint256 totalSuppliable) {
for (uint256 i; i < supplyQueue.length; ++i) {
IERC4626 id = supplyQueue[i];
uint256 supplyCap = config[id].cap;
if (supplyCap == 0) continue;
uint256 supplyAssets = expectedSupplyAssets(id);
totalSuppliable += UtilsLib.min(supplyCap.zeroFloorSub(supplyAssets), id.maxDeposit(address(this)));
}
}
/// @inheritdoc ERC4626
/// @dev The accrual of performance fees is taken into account in the conversion.
function _convertToShares(uint256 assets, Math.Rounding rounding) internal view override returns (uint256) {
(uint256 feeShares, uint256 newTotalAssets,) = _accruedFeeAndAssets();
return _convertToSharesWithTotals(assets, totalSupply() + feeShares, newTotalAssets, rounding);
}
/// @inheritdoc ERC4626
/// @dev The accrual of performance fees is taken into account in the conversion.
function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view override returns (uint256) {
(uint256 feeShares, uint256 newTotalAssets,) = _accruedFeeAndAssets();
return _convertToAssetsWithTotals(shares, totalSupply() + feeShares, newTotalAssets, rounding);
}
/// @dev Returns the amount of shares that the vault would exchange for the amount of `assets` provided.
/// @dev It assumes that the arguments `newTotalSupply` and `newTotalAssets` are up to date.
function _convertToSharesWithTotals(
uint256 assets,
uint256 newTotalSupply,
uint256 newTotalAssets,
Math.Rounding rounding
) internal pure returns (uint256) {
return assets.mulDiv(
newTotalSupply + ConstantsLib.VIRTUAL_AMOUNT, newTotalAssets + ConstantsLib.VIRTUAL_AMOUNT, rounding
);
}
/// @dev Returns the amount of assets that the vault would exchange for the amount of `shares` provided.
/// @dev It assumes that the arguments `newTotalSupply` and `newTotalAssets` are up to date.
function _convertToAssetsWithTotals(
uint256 shares,
uint256 newTotalSupply,
uint256 newTotalAssets,
Math.Rounding rounding
) internal pure returns (uint256) {
return shares.mulDiv(
newTotalAssets + ConstantsLib.VIRTUAL_AMOUNT, newTotalSupply + ConstantsLib.VIRTUAL_AMOUNT, rounding
);
}
/// @inheritdoc ERC4626
/// @dev Used in mint or deposit to deposit the underlying asset to strategy vaults.
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal override {
IERC20(asset()).safeTransferFromWithPermit2(caller, address(this), assets, permit2Address);
_mint(receiver, shares);
emit Deposit(caller, receiver, assets, shares);
_supplyStrategy(assets);
// `lastTotalAssets + assets` may be a little above `totalAssets()`.
// This can lead to a small accrual of `lostAssets` at the next interaction.
_updateLastTotalAssets(lastTotalAssets + assets);
}
/// @inheritdoc ERC4626
/// @dev Used in redeem or withdraw to withdraw the underlying asset from the strategy vaults.
/// @dev Depending on 3 cases, reverts when withdrawing "too much" with:
/// 1. NotEnoughLiquidity when withdrawing more than available liquidity.
/// 2. ERC20InsufficientAllowance when withdrawing more than `caller`'s allowance.
/// 3. ERC20InsufficientBalance when withdrawing more than `owner`'s balance.
/// @dev The function prevents sending assets to addresses which are known to be EVC sub-accounts
function _withdraw(address caller, address receiver, address owner, uint256 assets, uint256 shares)
internal
override
{
// assets sent to EVC sub-accounts would be lost, as the private key for a sub-account is not known
address evcOwner = evc.getAccountOwner(receiver);
if (evcOwner != address(0) && evcOwner != receiver) {
revert ErrorsLib.BadAssetReceiver();
}
// `lastTotalAssets - assets` may be a little above `totalAssets()`.
// This can lead to a small accrual of `lostAssets` at the next interaction.
// clamp at 0 so the error raised is the more informative NotEnoughLiquidity.
_updateLastTotalAssets(lastTotalAssets.zeroFloorSub(assets));
_withdrawStrategy(assets);
super._withdraw(caller, receiver, owner, assets, shares);
}
/* INTERNAL */
/// @notice Retrieves the message sender in the context of the EVC.
/// @dev This function returns the account on behalf of which the current operation is being performed, which is
/// either msg.sender or the account authenticated by the EVC.
/// @return The address of the message sender.
function _msgSender() internal view virtual override(EVCUtil, Context) returns (address) {
return EVCUtil._msgSender();
}
/// @dev Reverts if `newTimelock` is not within the bounds.
function _checkTimelockBounds(uint256 newTimelock) internal pure {
if (newTimelock > ConstantsLib.MAX_TIMELOCK) revert ErrorsLib.AboveMaxTimelock();
if (newTimelock < ConstantsLib.POST_INITIALIZATION_MIN_TIMELOCK) revert ErrorsLib.BelowMinTimelock();
}
/// @dev Sets `timelock` to `newTimelock`.
function _setTimelock(uint256 newTimelock) internal {
timelock = newTimelock;
emit EventsLib.SetTimelock(_msgSender(), newTimelock);
delete pendingTimelock;
}
/// @dev Sets `guardian` to `newGuardian`.
function _setGuardian(address newGuardian) internal {
guardian = newGuardian;
emit EventsLib.SetGuardian(_msgSender(), newGuardian);
delete pendingGuardian;
}
/// @dev Sets the cap of the vault to `supplyCap`.
function _setCap(IERC4626 id, uint136 supplyCap) internal {
address msgSender = _msgSender();
MarketConfig storage marketConfig = config[id];
(bool success, bytes memory result) = address(id).staticcall(abi.encodeCall(this.permit2Address, ()));
address permit2 = success && result.length >= 32 ? abi.decode(result, (address)) : address(0);
if (supplyCap > 0) {
IERC20(asset()).forceApproveMaxWithPermit2(address(id), permit2);
if (!marketConfig.enabled) {
withdrawQueue.push(id);
if (withdrawQueue.length > ConstantsLib.MAX_QUEUE_LENGTH) revert ErrorsLib.MaxQueueLengthExceeded();
marketConfig.enabled = true;
marketConfig.balance = id.balanceOf(address(this)).toUint112();
// Take into account assets of the new vault without applying a fee.
_updateLastTotalAssets(lastTotalAssets + expectedSupplyAssets(id));
emit EventsLib.SetWithdrawQueue(msgSender, withdrawQueue);
}
marketConfig.removableAt = 0;
} else {
IERC20(asset()).revokeApprovalWithPermit2(address(id), permit2);
}
marketConfig.cap = supplyCap;
emit EventsLib.SetCap(msgSender, id, supplyCap);
delete pendingCap[id];
}
/* LIQUIDITY ALLOCATION */
/// @dev Supplies `assets` to the strategy vaults.
function _supplyStrategy(uint256 assets) internal {
for (uint256 i; i < supplyQueue.length; ++i) {
IERC4626 id = supplyQueue[i];
uint256 supplyCap = config[id].cap;
if (supplyCap == 0) continue;
uint256 supplyAssets = expectedSupplyAssets(id);
uint256 toSupply =
UtilsLib.min(UtilsLib.min(supplyCap.zeroFloorSub(supplyAssets), id.maxDeposit(address(this))), assets);
if (toSupply > 0) {
// Using try/catch to skip vaults that revert.
try id.deposit(toSupply, address(this)) returns (uint256 suppliedShares) {
config[id].balance = (config[id].balance + suppliedShares).toUint112();
assets -= toSupply;
} catch {}
}
if (assets == 0) return;
}
if (assets != 0) revert ErrorsLib.AllCapsReached();
}
/// @dev Withdraws `assets` from the strategy vaults.
function _withdrawStrategy(uint256 assets) internal {
for (uint256 i; i < withdrawQueue.length; ++i) {
IERC4626 id = withdrawQueue[i];
uint256 toWithdraw = UtilsLib.min(maxWithdrawFromStrategy(id), assets);
if (toWithdraw > 0) {
// Using try/catch to skip vaults that revert.
try id.withdraw(toWithdraw, address(this), address(this)) returns (uint256 withdrawnShares) {
config[id].balance = uint112(config[id].balance - withdrawnShares);
assets -= toWithdraw;
} catch {}
}
if (assets == 0) return;
}
if (assets != 0) revert ErrorsLib.NotEnoughLiquidity();
}
/// @dev Simulates a withdraw of `assets` from the strategy vaults.
/// @return The remaining assets to be withdrawn.
function _simulateWithdrawStrategy(uint256 assets) internal view returns (uint256) {
for (uint256 i; i < withdrawQueue.length; ++i) {
IERC4626 id = withdrawQueue[i];
assets = assets.zeroFloorSub(maxWithdrawFromStrategy(id));
if (assets == 0) break;
}
return assets;
}
/* FEE MANAGEMENT */
/// @dev Updates `lastTotalAssets` to `updatedTotalAssets`.
function _updateLastTotalAssets(uint256 updatedTotalAssets) internal {
lastTotalAssets = updatedTotalAssets;
emit EventsLib.UpdateLastTotalAssets(updatedTotalAssets);
}
/// @dev Accrues `lastTotalAssets`, `lostAssets` and mints the fee shares to the fee recipient.
function _accrueInterest() internal {
(uint256 feeShares, uint256 newTotalAssets, uint256 newLostAssets) = _accruedFeeAndAssets();
_updateLastTotalAssets(newTotalAssets);
lostAssets = newLostAssets;
emit EventsLib.UpdateLostAssets(newLostAssets);
if (feeShares != 0) _mint(feeRecipient, feeShares);
emit EventsLib.AccrueInterest(newTotalAssets, feeShares);
}
/// @dev Computes and returns the `feeShares` to mint, the new `totalAssets` and the new `lostAssets`.
/// @return feeShares the shares to mint to `feeRecipient`.
/// @return newTotalAssets the new `totalAssets`.
/// @return newLostAssets the new lostAssets.
function _accruedFeeAndAssets()
internal
view
returns (uint256 feeShares, uint256 newTotalAssets, uint256 newLostAssets)
{
// The assets that the Earn vault has on the strategy vaults.
uint256 realTotalAssets;
for (uint256 i; i < withdrawQueue.length; ++i) {
IERC4626 id = withdrawQueue[i];
realTotalAssets += expectedSupplyAssets(id);
}
uint256 lastTotalAssetsCached = lastTotalAssets;
if (realTotalAssets < lastTotalAssetsCached - lostAssets) {
// If the vault lost some assets (realTotalAssets decreased), lostAssets is increased.
newLostAssets = lastTotalAssetsCached - realTotalAssets;
} else {
// If it did not, lostAssets stays the same.
newLostAssets = lostAssets;
}
newTotalAssets = realTotalAssets + newLostAssets;
uint256 totalInterest = newTotalAssets - lastTotalAssetsCached;
if (totalInterest != 0 && fee != 0) {
// It is acknowledged that `feeAssets` may be rounded down to 0 if `totalInterest * fee < WAD`.
uint256 feeAssets = totalInterest.mulDiv(fee, WAD);
// The fee assets is subtracted from the total assets in this calculation to compensate for the fact
// that total assets is already increased by the total interest (including the fee assets).
feeShares =
_convertToSharesWithTotals(feeAssets, totalSupply(), newTotalAssets - feeAssets, Math.Rounding.Floor);
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import {IEulerEarnFactory} from "./IEulerEarnFactory.sol";
import {IERC4626} from "../../lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol";
import {IERC20Permit} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {MarketConfig, PendingUint136, PendingAddress} from "../libraries/PendingLib.sol";
struct MarketAllocation {
/// @notice The vault to allocate.
IERC4626 id;
/// @notice The amount of assets to allocate.
uint256 assets;
}
interface IOwnable {
function owner() external view returns (address);
function transferOwnership(address) external;
function renounceOwnership() external;
function acceptOwnership() external;
function pendingOwner() external view returns (address);
}
/// @dev This interface is used for factorizing IEulerEarnStaticTyping and IEulerEarn.
/// @dev Consider using the IEulerEarn interface instead of this one.
interface IEulerEarnBase {
/// @notice The address of the Permit2 contract.
function permit2Address() external view returns (address);
/// @notice The address of the creator.
function creator() external view returns (address);
/// @notice The address of the curator.
function curator() external view returns (address);
/// @notice Stores whether an address is an allocator or not.
function isAllocator(address target) external view returns (bool);
/// @notice The current guardian. Can be set even without the timelock set.
function guardian() external view returns (address);
/// @notice The current fee.
function fee() external view returns (uint96);
/// @notice The fee recipient.
function feeRecipient() external view returns (address);
/// @notice The current timelock.
function timelock() external view returns (uint256);
/// @dev Stores the order of vaults in which liquidity is supplied upon deposit.
/// @dev Can contain any vault. A vault is skipped as soon as its supply cap is reached.
function supplyQueue(uint256) external view returns (IERC4626);
/// @notice Returns the length of the supply queue.
function supplyQueueLength() external view returns (uint256);
/// @dev Stores the order of vault from which liquidity is withdrawn upon withdrawal.
/// @dev Always contain all non-zero cap vault as well as all vault on which the Earn vault supplies liquidity,
/// without duplicate.
function withdrawQueue(uint256) external view returns (IERC4626);
/// @notice Returns the length of the withdraw queue.
function withdrawQueueLength() external view returns (uint256);
/// @notice Returns the amount of assets that can be withdrawn from given strategy vault.
/// @dev Accounts for internally tracked balance, ignoring direct shares transfer and for assets available in the strategy.
function maxWithdrawFromStrategy(IERC4626 id) external view returns (uint256);
/// @notice Returns the amount of assets expected to be supplied to the strategy vault.
/// @dev Accounts for internally tracked balance, ignoring direct shares transfer.
function expectedSupplyAssets(IERC4626 id) external view returns (uint256);
/// @notice Stores the total assets managed by this vault when the fee was last accrued.
function lastTotalAssets() external view returns (uint256);
/// @notice Stores the missing assets due to realized bad debt or forced vault removal.
/// @dev In order to cover those lost assets, it is advised to supply on behalf of address(1) on the vault
/// (canonical method).
function lostAssets() external view returns (uint256);
/// @notice Submits a `newTimelock`.
/// @dev Warning: Reverts if a timelock is already pending. Revoke the pending timelock to overwrite it.
/// @dev In case the new timelock is higher than the current one, the timelock is set immediately.
function submitTimelock(uint256 newTimelock) external;
/// @notice Accepts the pending timelock.
function acceptTimelock() external;
/// @notice Revokes the pending timelock.
/// @dev Does not revert if there is no pending timelock.
function revokePendingTimelock() external;
/// @notice Submits a `newSupplyCap` for the vault.
/// @dev Warning: Reverts if a cap is already pending. Revoke the pending cap to overwrite it.
/// @dev Warning: Reverts if a vault removal is pending.
/// @dev In case the new cap is lower than the current one, the cap is set immediately.
/// @dev For the sake of backwards compatibility, the max allowed cap can either be set to type(uint184).max or type(uint136).max.
function submitCap(IERC4626 id, uint256 newSupplyCap) external;
/// @notice Accepts the pending cap of the vault.
function acceptCap(IERC4626 id) external;
/// @notice Revokes the pending cap of the vault.
/// @dev Does not revert if there is no pending cap.
function revokePendingCap(IERC4626 id) external;
/// @notice Submits a forced vault removal from the Earn vault, eventually losing all funds supplied to the vault.
/// @notice This forced removal is expected to be used as an emergency process in case a vault constantly reverts.
/// To softly remove a sane vault, the curator role is expected to bundle a reallocation that empties the vault
/// first (using `reallocate`), followed by the removal of the vault (using `updateWithdrawQueue`).
/// @dev Warning: Reverts for non-zero cap or if there is a pending cap. Successfully submitting a zero cap will
/// prevent such reverts.
function submitMarketRemoval(IERC4626 id) external;
/// @notice Revokes the pending removal of the vault.
/// @dev Does not revert if there is no pending vault removal.
function revokePendingMarketRemoval(IERC4626 id) external;
/// @notice Sets the name of the Earn vault.
//function setName(string memory newName) external;
/// @notice Sets the symbol of the Earn vault.
//function setSymbol(string memory newSymbol) external;
/// @notice Submits a `newGuardian`.
/// @notice Warning: a malicious guardian could disrupt the Earn vault's operation, and would have the power to revoke
/// any pending guardian.
/// @dev In case there is no guardian, the guardian is set immediately.
/// @dev Warning: Submitting a guardian will overwrite the current pending guardian.
function submitGuardian(address newGuardian) external;
/// @notice Accepts the pending guardian.
function acceptGuardian() external;
/// @notice Revokes the pending guardian.
function revokePendingGuardian() external;
/// @notice Sets `newAllocator` as an allocator or not (`newIsAllocator`).
function setIsAllocator(address newAllocator, bool newIsAllocator) external;
/// @notice Sets `curator` to `newCurator`.
function setCurator(address newCurator) external;
/// @notice Sets the `fee` to `newFee`.
function setFee(uint256 newFee) external;
/// @notice Sets `feeRecipient` to `newFeeRecipient`.
function setFeeRecipient(address newFeeRecipient) external;
/// @notice Sets `supplyQueue` to `newSupplyQueue`.
/// @param newSupplyQueue is an array of enabled vaults, and can contain duplicate vaults, but it would only
/// increase the cost of depositing to the vault.
function setSupplyQueue(IERC4626[] calldata newSupplyQueue) external;
/// @notice Updates the withdraw queue. Some vaults can be removed, but no vault can be added.
/// @notice Removing a vault requires the vault to have 0 supply on it, or to have previously submitted a removal
/// for this vault (with the function `submitMarketRemoval`).
/// @notice Warning: Anyone can supply on behalf of the vault so the call to `updateWithdrawQueue` that expects a
/// vault to be empty can be griefed by a front-run. To circumvent this, the allocator can simply bundle a
/// reallocation that withdraws max from this vault with a call to `updateWithdrawQueue`.
/// @dev Warning: Removing a vault with supply will decrease the fee accrued until one of the functions updating
/// `lastTotalAssets` is triggered (deposit/mint/withdraw/redeem/setFee/setFeeRecipient).
/// @dev Warning: `updateWithdrawQueue` is not idempotent. Submitting twice the same tx will change the queue twice.
/// @param indexes The indexes of each vault in the previous withdraw queue, in the new withdraw queue's order.
function updateWithdrawQueue(uint256[] calldata indexes) external;
/// @notice Reallocates the vault's liquidity so as to reach a given allocation of assets on each given vault.
/// @dev The behavior of the reallocation can be altered by state changes, including:
/// - Deposits on the Earn vault that supplies to vaults that are expected to be supplied to during reallocation.
/// - Withdrawals from the Earn vault that withdraws from vaults that are expected to be withdrawn from during
/// reallocation.
/// - Donations to the vault on vaults that are expected to be supplied to during reallocation.
/// - Withdrawals from vaults that are expected to be withdrawn from during reallocation.
/// @dev Sender is expected to pass `assets = type(uint256).max` with the last MarketAllocation of `allocations` to
/// supply all the remaining withdrawn liquidity, which would ensure that `totalWithdrawn` = `totalSupplied`.
/// @dev A supply in a reallocation step will make the reallocation revert if the amount is greater than the net
/// amount from previous steps (i.e. total withdrawn minus total supplied).
function reallocate(MarketAllocation[] calldata allocations) external;
}
/// @dev This interface is inherited by IEulerEarn so that function signatures are checked by the compiler.
/// @dev Consider using the IEulerEarn interface instead of this one.
interface IEulerEarnStaticTyping is IEulerEarnBase {
/// @notice Returns the current configuration of each vault.
function config(IERC4626) external view returns (uint112 balance, uint136 cap, bool enabled, uint64 removableAt);
/// @notice Returns the pending guardian.
function pendingGuardian() external view returns (address guardian, uint64 validAt);
/// @notice Returns the pending cap for each vault.
function pendingCap(IERC4626) external view returns (uint136 value, uint64 validAt);
/// @notice Returns the pending timelock.
function pendingTimelock() external view returns (uint136 value, uint64 validAt);
}
/// @title IEulerEarn
/// @author Forked with gratitude from Morpho Labs. Inspired by Silo Labs.
/// @custom:contact [email protected]
/// @custom:contact [email protected]
/// @dev Use this interface for IEulerEarn to have access to all the functions with the appropriate function
/// signatures.
interface IEulerEarn is IEulerEarnBase, IERC4626, IERC20Permit, IOwnable {
/// @notice Returns the address of the Ethereum Vault Connector (EVC) used by this contract.
function EVC() external view returns (address);
/// @notice Returns the current configuration of each vault.
function config(IERC4626) external view returns (MarketConfig memory);
/// @notice Returns the pending guardian.
function pendingGuardian() external view returns (PendingAddress memory);
/// @notice Returns the pending cap for each vault.
function pendingCap(IERC4626) external view returns (PendingUint136 memory);
/// @notice Returns the pending timelock.
function pendingTimelock() external view returns (PendingUint136 memory);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import {IEulerEarn} from "./IEulerEarn.sol";
/// @title IEulerEarnFactory
/// @author Forked with gratitude from Morpho Labs. Inspired by Silo Labs.
/// @custom:contact [email protected]
/// @custom:contact [email protected]
/// @notice Interface of EulerEarn's factory.
interface IEulerEarnFactory {
/// @notice The address of the Permit2 contract.
function permit2Address() external view returns (address);
/// @notice The address of the supported perspective contract.
function supportedPerspective() external view returns (address);
/// @notice Whether a vault was created with the factory.
function isVault(address target) external view returns (bool);
/// @notice Fetch the length of the deployed proxies list
/// @return The length of the proxy list array
function getVaultListLength() external view returns (uint256);
/// @notice Get a slice of the deployed proxies array
/// @param start Start index of the slice
/// @param end End index of the slice
/// @return list An array containing the slice of the proxy list
function getVaultListSlice(uint256 start, uint256 end) external view returns (address[] memory list);
/// @notice Sets the perspective contract.
/// @param _perspective The address of the new perspective contract.
function setPerspective(address _perspective) external;
/// @notice Whether a strategy is allowed to be used by the Earn vault.
/// @dev Warning: Only allow trusted, correctly implemented ERC4626 strategies to be used by the Earn vault.
/// @dev Warning: Allowed strategies must not be prone to the first-depositor attack.
/// @dev Warning: To prevent exchange rate manipulation, it is recommended that the allowed strategies are not empty or have sufficient protection.
function isStrategyAllowed(address id) external view returns (bool);
/// @notice Creates a new EulerEarn vault.
/// @param initialOwner The owner of the vault.
/// @param initialTimelock The initial timelock of the vault.
/// @param asset The address of the underlying asset.
/// @param name The name of the vault.
/// @param symbol The symbol of the vault.
/// @param salt The salt to use for the EulerEarn vault's CREATE2 address.
function createEulerEarn(
address initialOwner,
uint256 initialTimelock,
address asset,
string memory name,
string memory symbol,
bytes32 salt
) external returns (IEulerEarn eulerEarn);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
struct MarketConfig {
/// @notice The current balance of vault shares.
uint112 balance;
/// @notice The maximum amount of assets that can be allocated to the vault.
uint136 cap;
/// @notice Whether the vault is in the withdraw queue.
bool enabled;
/// @notice The timestamp at which the vault can be instantly removed from the withdraw queue.
uint64 removableAt;
}
struct PendingUint136 {
/// @notice The pending value to set.
uint136 value;
/// @notice The timestamp at which the pending value becomes valid.
uint64 validAt;
}
struct PendingAddress {
/// @notice The pending value to set.
address value;
/// @notice The timestamp at which the pending value becomes valid.
uint64 validAt;
}
/// @title PendingLib
/// @author Forked with gratitude from Morpho Labs. Inspired by Silo Labs.
/// @custom:contact [email protected]
/// @custom:contact [email protected]
/// @notice Library to manage pending values and their validity timestamp.
library PendingLib {
/// @dev Updates `pending`'s value to `newValue` and its corresponding `validAt` timestamp.
/// @dev Assumes `timelock` <= `MAX_TIMELOCK`.
function update(PendingUint136 storage pending, uint136 newValue, uint256 timelock) internal {
pending.value = newValue;
// Safe "unchecked" cast because timelock <= MAX_TIMELOCK.
pending.validAt = uint64(block.timestamp + timelock);
}
/// @dev Updates `pending`'s value to `newValue` and its corresponding `validAt` timestamp.
/// @dev Assumes `timelock` <= `MAX_TIMELOCK`.
function update(PendingAddress storage pending, address newValue, uint256 timelock) internal {
pending.value = newValue;
// Safe "unchecked" cast because timelock <= MAX_TIMELOCK.
pending.validAt = uint64(block.timestamp + timelock);
}
}// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; /// @title ConstantsLib /// @author Forked with gratitude from Morpho Labs. Inspired by Silo Labs. /// @custom:contact [email protected] /// @custom:contact [email protected] /// @notice Library exposing constants. library ConstantsLib { /// @dev The maximum delay of a timelock. uint256 internal constant MAX_TIMELOCK = 2 weeks; /// @dev The minimum delay of a timelock post initialization. uint256 internal constant POST_INITIALIZATION_MIN_TIMELOCK = 1 days; /// @dev The maximum number of vaults in the supply/withdraw queue. uint256 internal constant MAX_QUEUE_LENGTH = 30; /// @dev The maximum fee the vault can have (50%). uint256 internal constant MAX_FEE = 0.5e18; /// @dev The virtual amount added to total shares and total assets. uint256 internal constant VIRTUAL_AMOUNT = 1e6; }
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {IERC4626} from "../../lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol";
/// @title ErrorsLib
/// @author Forked with gratitude from Morpho Labs. Inspired by Silo Labs.
/// @custom:contact [email protected]
/// @custom:contact [email protected]
/// @notice Library exposing error messages.
library ErrorsLib {
/// @notice Thrown when the query is invalid.
error BadQuery();
/// @notice Thrown when the address passed is the zero address.
error ZeroAddress();
/// @notice Thrown when the caller doesn't have the curator role.
error NotCuratorRole();
/// @notice Thrown when the caller doesn't have the allocator role.
error NotAllocatorRole();
/// @notice Thrown when the caller doesn't have the guardian role.
error NotGuardianRole();
/// @notice Thrown when the caller doesn't have the curator nor the guardian role.
error NotCuratorNorGuardianRole();
/// @notice Thrown when the vault cannot be set in the supply queue.
error UnauthorizedMarket(IERC4626 id);
/// @notice Thrown when submitting a cap for a vault whose underlying asset does not correspond to the underlying
/// asset of the Earn vault.
error InconsistentAsset(IERC4626 id);
/// @notice Thrown when the supply cap has been exceeded on vault during a reallocation of funds.
error SupplyCapExceeded(IERC4626 id);
/// @notice Thrown when the fee to set exceeds the maximum fee.
error MaxFeeExceeded();
/// @notice Thrown when the value is already set.
error AlreadySet();
/// @notice Thrown when a value is already pending.
error AlreadyPending();
/// @notice Thrown when submitting the removal of a vault when there is a cap already pending on that vault.
error PendingCap(IERC4626 id);
/// @notice Thrown when submitting a cap for a vault with a pending removal.
error PendingRemoval();
/// @notice Thrown when submitting a vault removal for a vault with a non zero cap.
error NonZeroCap();
/// @notice Thrown when vault is a duplicate in the new withdraw queue to set.
error DuplicateMarket(IERC4626 id);
/// @notice Thrown when vault is missing in the updated withdraw queue and the vault has a non-zero cap set.
error InvalidMarketRemovalNonZeroCap(IERC4626 id);
/// @notice Thrown when vault is missing in the updated withdraw queue and the vault has a non-zero supply.
error InvalidMarketRemovalNonZeroSupply(IERC4626 id);
/// @notice Thrown when vault is missing in the updated withdraw queue and the vault is not yet disabled.
error InvalidMarketRemovalTimelockNotElapsed(IERC4626 id);
/// @notice Thrown when there's no pending value to set.
error NoPendingValue();
/// @notice Thrown when the requested liquidity cannot be withdrawn from EulerEarn.
error NotEnoughLiquidity();
/// @notice Thrown when interacting with a non previously enabled vault.
error MarketNotEnabled(IERC4626 id);
/// @notice Thrown when the submitted timelock is above the max timelock.
error AboveMaxTimelock();
/// @notice Thrown when the submitted timelock is below the min timelock.
error BelowMinTimelock();
/// @notice Thrown when the timelock is not elapsed.
error TimelockNotElapsed();
/// @notice Thrown when too many vaults are in the withdraw queue.
error MaxQueueLengthExceeded();
/// @notice Thrown when setting the fee to a non zero value while the fee recipient is the zero address.
error ZeroFeeRecipient();
/// @notice Thrown when the amount withdrawn is not exactly the amount supplied.
error InconsistentReallocation();
/// @notice Thrown when all caps have been reached.
error AllCapsReached();
/// @notice Thrown when the `msg.sender` is not the admin nor the owner of the vault.
error NotAdminNorVaultOwner();
/// @notice Thrown when the reallocation fee given is wrong.
error IncorrectFee();
/// @notice Thrown when `withdrawals` is empty.
error EmptyWithdrawals();
/// @notice Thrown when `withdrawals` contains a duplicate or is not sorted.
error InconsistentWithdrawals();
/// @notice Thrown when the deposit vault is in `withdrawals`.
error DepositMarketInWithdrawals();
/// @notice Thrown when attempting to deposit amount of assets corresponding to zero shares.
error ZeroShares();
/// @notice Thrown when attempting to withdraw zero from a vault.
error WithdrawZero(IERC4626 id);
/// @notice Thrown when attempting to set max inflow/outflow above the MAX_SETTABLE_FLOW_CAP.
error MaxSettableFlowCapExceeded();
/// @notice Thrown when the fee transfer fails.
error FeeTransferFailed(address feeRecipient);
/// @notice Thrown when attempting to withdraw more than the available supply of a vault.
error NotEnoughSupply(IERC4626 id);
/// @notice Thrown when attempting to withdraw more than the max outflow of a vault.
error MaxOutflowExceeded(IERC4626 id);
/// @notice Thrown when attempting to supply more than the max inflow of a vault.
error MaxInflowExceeded(IERC4626 id);
/// @notice Thrown when the maximum uint128 is exceeded.
error MaxUint128Exceeded();
/// @notice Thrown when withdrawal is attempted to an address known to be an EVC sub-account
error BadAssetReceiver();
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {FlowCapsConfig} from "../interfaces/IPublicAllocator.sol";
import {IERC4626} from "../../lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol";
import {PendingAddress} from "./PendingLib.sol";
/// @title EventsLib
/// @author Forked with gratitude from Morpho Labs. Inspired by Silo Labs.
/// @custom:contact [email protected]
/// @custom:contact [email protected]
/// @notice Library exposing events.
library EventsLib {
/// @notice Emitted when the perspective is set.
event SetPerspective(address);
/// @notice Emitted when the name of the Earn vault is set.
event SetName(string name);
/// @notice Emitted when the symbol of the Earn vault is set.
event SetSymbol(string symbol);
/// @notice Emitted when a pending `newTimelock` is submitted.
event SubmitTimelock(uint256 newTimelock);
/// @notice Emitted when `timelock` is set to `newTimelock`.
event SetTimelock(address indexed caller, uint256 newTimelock);
/// @notice Emitted `fee` is set to `newFee`.
event SetFee(address indexed caller, uint256 newFee);
/// @notice Emitted when a new `newFeeRecipient` is set.
event SetFeeRecipient(address indexed newFeeRecipient);
/// @notice Emitted when a pending `newGuardian` is submitted.
event SubmitGuardian(address indexed newGuardian);
/// @notice Emitted when `guardian` is set to `newGuardian`.
event SetGuardian(address indexed caller, address indexed guardian);
/// @notice Emitted when a pending `cap` is submitted for a vault.
event SubmitCap(address indexed caller, IERC4626 indexed id, uint256 cap);
/// @notice Emitted when a new `cap` is set for a vault.
event SetCap(address indexed caller, IERC4626 indexed id, uint256 cap);
/// @notice Emitted when the vault's last total assets is updated to `updatedTotalAssets`.
event UpdateLastTotalAssets(uint256 updatedTotalAssets);
/// @notice Emitted when the vault's lostAssets is updated to `newLostAssets`.
event UpdateLostAssets(uint256 newLostAssets);
/// @notice Emitted when the vault is submitted for removal.
event SubmitMarketRemoval(address indexed caller, IERC4626 indexed id);
/// @notice Emitted when `curator` is set to `newCurator`.
event SetCurator(address indexed newCurator);
/// @notice Emitted when an `allocator` is set to `isAllocator`.
event SetIsAllocator(address indexed allocator, bool isAllocator);
/// @notice Emitted when a `pendingTimelock` is revoked.
event RevokePendingTimelock(address indexed caller);
/// @notice Emitted when a `pendingCap` for the vault is revoked.
event RevokePendingCap(address indexed caller, IERC4626 indexed id);
/// @notice Emitted when a `pendingGuardian` is revoked.
event RevokePendingGuardian(address indexed caller);
/// @notice Emitted when a pending vault removal is revoked.
event RevokePendingMarketRemoval(address indexed caller, IERC4626 indexed id);
/// @notice Emitted when the `supplyQueue` is set to `newSupplyQueue`.
event SetSupplyQueue(address indexed caller, IERC4626[] newSupplyQueue);
/// @notice Emitted when the `withdrawQueue` is set to `newWithdrawQueue`.
event SetWithdrawQueue(address indexed caller, IERC4626[] newWithdrawQueue);
/// @notice Emitted when a reallocation supplies assets to the vault.
/// @param id The address of the vault.
/// @param suppliedAssets The amount of assets supplied to the vault.
/// @param suppliedShares The amount of shares minted.
event ReallocateSupply(address indexed caller, IERC4626 indexed id, uint256 suppliedAssets, uint256 suppliedShares);
/// @notice Emitted when a reallocation withdraws assets from the vault.
/// @param id The address of the vault.
/// @param withdrawnAssets The amount of assets withdrawn from the vault.
/// @param withdrawnShares The amount of shares burned.
event ReallocateWithdraw(
address indexed caller, IERC4626 indexed id, uint256 withdrawnAssets, uint256 withdrawnShares
);
/// @notice Emitted when interest are accrued.
/// @param newTotalAssets The assets of the vault after accruing the interest but before the interaction.
/// @param feeShares The shares minted to the fee recipient.
event AccrueInterest(uint256 newTotalAssets, uint256 feeShares);
/// @notice Emitted when a new EulerEarn vault is created.
/// @param eulerEarn The address of the EulerEarn vault.
/// @param caller The caller of the function.
/// @param initialOwner The initial owner of the EulerEarn vault.
/// @param initialTimelock The initial timelock of the EulerEarn vault.
/// @param asset The address of the underlying asset.
/// @param name The name of the EulerEarn vault.
/// @param symbol The symbol of the EulerEarn vault.
/// @param salt The salt used for the EulerEarn vault's CREATE2 address.
event CreateEulerEarn(
address indexed eulerEarn,
address indexed caller,
address initialOwner,
uint256 initialTimelock,
address indexed asset,
string name,
string symbol,
bytes32 salt
);
/// @notice Emitted during a public reallocation for each withdrawn-from vault.
event PublicWithdrawal(address indexed sender, address indexed vault, IERC4626 indexed id, uint256 withdrawnAssets);
/// @notice Emitted at the end of a public reallocation.
event PublicReallocateTo(
address indexed sender, address indexed vault, IERC4626 indexed supplyId, uint256 suppliedAssets
);
/// @notice Emitted when the admin is set for a vault.
event SetAdmin(address indexed sender, address indexed vault, address admin);
/// @notice Emitted when the fee is set for a vault.
event SetAllocationFee(address indexed sender, address indexed vault, uint256 fee);
/// @notice Emitted when the fee is transfered for a vault.
event TransferAllocationFee(
address indexed sender, address indexed vault, uint256 amount, address indexed feeRecipient
);
/// @notice Emitted when the flow caps are set for a vault.
event SetFlowCaps(address indexed sender, address indexed vault, FlowCapsConfig[] config);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {IAllowanceTransfer} from "../interfaces/IAllowanceTransfer.sol";
import {IERC20} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import {SafeERC20} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
/// @title SafeERC20Permit2Lib Library
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice The library provides a helper for ERC20 approvals and transfers with use of Permit2
library SafeERC20Permit2Lib {
function forceApproveMaxWithPermit2(IERC20 token, address spender, address permit2) internal {
if (permit2 == address(0)) {
SafeERC20.forceApprove(token, spender, type(uint256).max);
} else {
if (token.allowance(address(this), permit2) == 0) {
SafeERC20.forceApprove(token, permit2, type(uint256).max);
}
IAllowanceTransfer(permit2).approve(address(token), spender, type(uint160).max, type(uint48).max);
}
}
function revokeApprovalWithPermit2(IERC20 token, address spender, address permit2) internal {
if (permit2 == address(0)) {
if (!trySafeApprove(token, spender, 0)) {
trySafeApprove(token, spender, 1);
}
} else {
IAllowanceTransfer(permit2).approve(address(token), spender, 0, 0);
}
}
function safeTransferFromWithPermit2(IERC20 token, address from, address to, uint256 value, address permit2)
internal
{
uint160 permit2Amount;
uint48 permit2Expiration;
if (permit2 != address(0)) {
(permit2Amount, permit2Expiration,) =
IAllowanceTransfer(permit2).allowance(from, address(token), address(this));
}
if (permit2Amount >= value && permit2Expiration >= block.timestamp) {
// it's safe to down-cast value to uint160
IAllowanceTransfer(permit2).transferFrom(from, to, uint160(value), address(token));
} else {
SafeERC20.safeTransferFrom(token, from, to, value);
}
}
function trySafeApprove(IERC20 token, address to, uint256 value) internal returns (bool) {
(bool success, bytes memory data) = address(token).call(abi.encodeCall(IERC20.approve, (to, value)));
return success && (data.length == 0 || abi.decode(data, (bool)));
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {ErrorsLib} from "./ErrorsLib.sol";
uint256 constant WAD = 1e18;
/// @title UtilsLib
/// @author Forked with gratitude from Morpho Labs. Inspired by Silo Labs.
/// @custom:contact [email protected]
/// @custom:contact [email protected]
/// @notice Library exposing helpers.
/// @dev Inspired by https://github.com/morpho-org/morpho-utils.
library UtilsLib {
/// @dev Returns the min of `x` and `y`.
function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly {
z := xor(x, mul(xor(x, y), lt(y, x)))
}
}
/// @dev Returns max(0, x - y).
function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly {
z := mul(gt(x, y), sub(x, y))
}
}
}// 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) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.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 Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
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 {
_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 {
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.3.0) (token/ERC20/extensions/ERC4626.sol)
pragma solidity ^0.8.20;
import {IERC20, IERC20Metadata, ERC20} from "../ERC20.sol";
import {SafeERC20} from "../utils/SafeERC20.sol";
import {IERC4626} from "../../../interfaces/IERC4626.sol";
import {Math} from "../../../utils/math/Math.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 ERC4626 is ERC20, IERC4626 {
using Math for uint256;
IERC20 private immutable _asset;
uint8 private immutable _underlyingDecimals;
/**
* @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).
*/
constructor(IERC20 asset_) {
(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, ERC20) returns (uint8) {
return _underlyingDecimals + _decimalsOffset();
}
/** @dev See {IERC4626-asset}. */
function asset() public view virtual returns (address) {
return address(_asset);
}
/** @dev See {IERC4626-totalAssets}. */
function totalAssets() public view virtual returns (uint256) {
return IERC20(asset()).balanceOf(address(this));
}
/** @dev See {IERC4626-convertToShares}. */
function convertToShares(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Floor);
}
/** @dev See {IERC4626-convertToAssets}. */
function convertToAssets(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Floor);
}
/** @dev See {IERC4626-maxDeposit}. */
function maxDeposit(address) public view virtual returns (uint256) {
return type(uint256).max;
}
/** @dev See {IERC4626-maxMint}. */
function maxMint(address) public view virtual returns (uint256) {
return type(uint256).max;
}
/** @dev See {IERC4626-maxWithdraw}. */
function maxWithdraw(address owner) public view virtual returns (uint256) {
return _convertToAssets(balanceOf(owner), Math.Rounding.Floor);
}
/** @dev See {IERC4626-maxRedeem}. */
function maxRedeem(address owner) public view virtual returns (uint256) {
return balanceOf(owner);
}
/** @dev See {IERC4626-previewDeposit}. */
function previewDeposit(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Floor);
}
/** @dev See {IERC4626-previewMint}. */
function previewMint(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Ceil);
}
/** @dev See {IERC4626-previewWithdraw}. */
function previewWithdraw(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Ceil);
}
/** @dev See {IERC4626-previewRedeem}. */
function previewRedeem(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Floor);
}
/** @dev See {IERC4626-deposit}. */
function deposit(uint256 assets, address receiver) public virtual returns (uint256) {
uint256 maxAssets = maxDeposit(receiver);
if (assets > maxAssets) {
revert ERC4626ExceededMaxDeposit(receiver, assets, maxAssets);
}
uint256 shares = previewDeposit(assets);
_deposit(_msgSender(), receiver, assets, shares);
return shares;
}
/** @dev See {IERC4626-mint}. */
function mint(uint256 shares, address receiver) public virtual returns (uint256) {
uint256 maxShares = maxMint(receiver);
if (shares > maxShares) {
revert ERC4626ExceededMaxMint(receiver, shares, maxShares);
}
uint256 assets = previewMint(shares);
_deposit(_msgSender(), receiver, assets, shares);
return assets;
}
/** @dev See {IERC4626-withdraw}. */
function withdraw(uint256 assets, address receiver, address owner) public virtual returns (uint256) {
uint256 maxAssets = maxWithdraw(owner);
if (assets > maxAssets) {
revert ERC4626ExceededMaxWithdraw(owner, assets, maxAssets);
}
uint256 shares = previewWithdraw(assets);
_withdraw(_msgSender(), receiver, owner, assets, shares);
return shares;
}
/** @dev See {IERC4626-redeem}. */
function redeem(uint256 shares, address receiver, address owner) public virtual returns (uint256) {
uint256 maxShares = maxRedeem(owner);
if (shares > maxShares) {
revert ERC4626ExceededMaxRedeem(owner, shares, maxShares);
}
uint256 assets = previewRedeem(shares);
_withdraw(_msgSender(), receiver, owner, assets, shares);
return assets;
}
/**
* @dev Internal conversion function (from assets to shares) with support for rounding direction.
*/
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
pragma solidity ^0.8.0;
import {IEVC} from "../interfaces/IEthereumVaultConnector.sol";
import {ExecutionContext, EC} from "../ExecutionContext.sol";
/// @title EVCUtil
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice This contract is an abstract base contract for interacting with the Ethereum Vault Connector (EVC).
/// It provides utility functions for authenticating the callers in the context of the EVC, a pattern for enforcing the
/// contracts to be called through the EVC.
abstract contract EVCUtil {
using ExecutionContext for EC;
uint160 internal constant ACCOUNT_ID_OFFSET = 8;
IEVC internal immutable evc;
error EVC_InvalidAddress();
error NotAuthorized();
error ControllerDisabled();
constructor(address _evc) {
if (_evc == address(0)) revert EVC_InvalidAddress();
evc = IEVC(_evc);
}
/// @notice Returns the address of the Ethereum Vault Connector (EVC) used by this contract.
/// @return The address of the EVC contract.
function EVC() external view virtual returns (address) {
return address(evc);
}
/// @notice Ensures that the msg.sender is the EVC by using the EVC callback functionality if necessary.
/// @dev Optional to use for functions requiring account and vault status checks to enforce predictable behavior.
/// @dev If this modifier used in conjuction with any other modifier, it must appear as the first (outermost)
/// modifier of the function.
modifier callThroughEVC() virtual {
_callThroughEVC();
_;
}
/// @notice Ensures that the caller is the EVC in the appropriate context.
/// @dev Should be used for checkAccountStatus and checkVaultStatus functions.
modifier onlyEVCWithChecksInProgress() virtual {
_onlyEVCWithChecksInProgress();
_;
}
/// @notice Ensures a standard authentication path on the EVC allowing the account owner or any of its EVC accounts.
/// @dev This modifier checks if the caller is the EVC and if so, verifies the execution context.
/// It reverts if the operator is authenticated, control collateral is in progress, or checks are in progress.
/// @dev This modifier must not be used on functions utilized by liquidation flows, i.e. transfer or withdraw.
/// @dev This modifier must not be used on checkAccountStatus and checkVaultStatus functions.
/// @dev This modifier can be used on access controlled functions to prevent non-standard authentication paths on
/// the EVC.
modifier onlyEVCAccount() virtual {
_authenticateCallerWithStandardContextState(false);
_;
}
/// @notice Ensures a standard authentication path on the EVC.
/// @dev This modifier checks if the caller is the EVC and if so, verifies the execution context.
/// It reverts if the operator is authenticated, control collateral is in progress, or checks are in progress.
/// It reverts if the authenticated account owner is known and it is not the account owner.
/// @dev It assumes that if the caller is not the EVC, the caller is the account owner.
/// @dev This modifier must not be used on functions utilized by liquidation flows, i.e. transfer or withdraw.
/// @dev This modifier must not be used on checkAccountStatus and checkVaultStatus functions.
/// @dev This modifier can be used on access controlled functions to prevent non-standard authentication paths on
/// the EVC.
modifier onlyEVCAccountOwner() virtual {
_authenticateCallerWithStandardContextState(true);
_;
}
/// @notice Checks whether the specified account and the other account have the same owner.
/// @dev The function is used to check whether one account is authorized to perform operations on behalf of the
/// other. Accounts are considered to have a common owner if they share the first 19 bytes of their address.
/// @param account The address of the account that is being checked.
/// @param otherAccount The address of the other account that is being checked.
/// @return A boolean flag that indicates whether the accounts have the same owner.
function _haveCommonOwner(address account, address otherAccount) internal pure returns (bool) {
bool result;
assembly {
result := lt(xor(account, otherAccount), 0x100)
}
return result;
}
/// @notice Returns the address prefix of the specified account.
/// @dev The address prefix is the first 19 bytes of the account address.
/// @param account The address of the account whose address prefix is being retrieved.
/// @return A bytes19 value that represents the address prefix of the account.
function _getAddressPrefix(address account) internal pure returns (bytes19) {
return bytes19(uint152(uint160(account) >> ACCOUNT_ID_OFFSET));
}
/// @notice Retrieves the message sender in the context of the EVC.
/// @dev This function returns the account on behalf of which the current operation is being performed, which is
/// either msg.sender or the account authenticated by the EVC.
/// @return The address of the message sender.
function _msgSender() internal view virtual returns (address) {
address sender = msg.sender;
if (sender == address(evc)) {
(sender,) = evc.getCurrentOnBehalfOfAccount(address(0));
}
return sender;
}
/// @notice Retrieves the message sender in the context of the EVC for a borrow operation.
/// @dev This function returns the account on behalf of which the current operation is being performed, which is
/// either msg.sender or the account authenticated by the EVC. This function reverts if this contract is not enabled
/// as a controller for the account on behalf of which the operation is being executed.
/// @return The address of the message sender.
function _msgSenderForBorrow() internal view virtual returns (address) {
address sender = msg.sender;
bool controllerEnabled;
if (sender == address(evc)) {
(sender, controllerEnabled) = evc.getCurrentOnBehalfOfAccount(address(this));
} else {
controllerEnabled = evc.isControllerEnabled(sender, address(this));
}
if (!controllerEnabled) {
revert ControllerDisabled();
}
return sender;
}
/// @notice Retrieves the message sender, ensuring it's any EVC account meaning that the execution context is in a
/// standard state (not operator authenticated, not control collateral in progress, not checks in progress).
/// @dev This function must not be used on functions utilized by liquidation flows, i.e. transfer or withdraw.
/// @dev This function must not be used on checkAccountStatus and checkVaultStatus functions.
/// @dev This function can be used on access controlled functions to prevent non-standard authentication paths on
/// the EVC.
/// @return The address of the message sender.
function _msgSenderOnlyEVCAccount() internal view returns (address) {
return _authenticateCallerWithStandardContextState(false);
}
/// @notice Retrieves the message sender, ensuring it's the EVC account owner and that the execution context is in a
/// standard state (not operator authenticated, not control collateral in progress, not checks in progress).
/// @dev It assumes that if the caller is not the EVC, the caller is the account owner.
/// @dev This function must not be used on functions utilized by liquidation flows, i.e. transfer or withdraw.
/// @dev This function must not be used on checkAccountStatus and checkVaultStatus functions.
/// @dev This function can be used on access controlled functions to prevent non-standard authentication paths on
/// the EVC.
/// @return The address of the message sender.
function _msgSenderOnlyEVCAccountOwner() internal view returns (address) {
return _authenticateCallerWithStandardContextState(true);
}
/// @notice Calls the current external function through the EVC.
/// @dev This function is used to route the current call through the EVC if it's not already coming from the EVC. It
/// makes the EVC set the execution context and call back this contract with unchanged calldata. msg.sender is used
/// as the onBehalfOfAccount.
/// @dev This function shall only be used by the callThroughEVC modifier.
function _callThroughEVC() internal {
address _evc = address(evc);
if (msg.sender == _evc) return;
assembly {
mstore(0, 0x1f8b521500000000000000000000000000000000000000000000000000000000) // EVC.call selector
mstore(4, address()) // EVC.call 1st argument - address(this)
mstore(36, caller()) // EVC.call 2nd argument - msg.sender
mstore(68, callvalue()) // EVC.call 3rd argument - msg.value
mstore(100, 128) // EVC.call 4th argument - msg.data, offset to the start of encoding - 128 bytes
mstore(132, calldatasize()) // msg.data length
calldatacopy(164, 0, calldatasize()) // original calldata
// abi encoded bytes array should be zero padded so its length is a multiple of 32
// store zero word after msg.data bytes and round up calldatasize to nearest multiple of 32
mstore(add(164, calldatasize()), 0)
let result := call(gas(), _evc, callvalue(), 0, add(164, and(add(calldatasize(), 31), not(31))), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 { revert(0, returndatasize()) }
default { return(64, sub(returndatasize(), 64)) } // strip bytes encoding from call return
}
}
/// @notice Ensures that the function is called only by the EVC during the checks phase
/// @dev Reverts if the caller is not the EVC or if checks are not in progress.
function _onlyEVCWithChecksInProgress() internal view {
if (msg.sender != address(evc) || !evc.areChecksInProgress()) {
revert NotAuthorized();
}
}
/// @notice Ensures that the function is called only by the EVC account owner or any of its EVC accounts
/// @dev This function checks if the caller is the EVC and if so, verifies that the execution context is not in a
/// special state (operator authenticated, collateral control in progress, or checks in progress). If
/// onlyAccountOwner is true and the owner was already registered on the EVC, it verifies that the onBehalfOfAccount
/// is the owner. If onlyAccountOwner is false, it allows any EVC account of the owner to call the function.
/// @param onlyAccountOwner If true, only allows the account owner; if false, allows any EVC account of the owner
/// @return The address of the message sender.
function _authenticateCallerWithStandardContextState(bool onlyAccountOwner) internal view returns (address) {
if (msg.sender == address(evc)) {
EC ec = EC.wrap(evc.getRawExecutionContext());
if (ec.isOperatorAuthenticated() || ec.isControlCollateralInProgress() || ec.areChecksInProgress()) {
revert NotAuthorized();
}
address onBehalfOfAccount = ec.getOnBehalfOfAccount();
if (onlyAccountOwner) {
address owner = evc.getAccountOwner(onBehalfOfAccount);
if (owner != address(0) && owner != onBehalfOfAccount) {
revert NotAuthorized();
}
}
return onBehalfOfAccount;
}
return msg.sender;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (interfaces/IERC4626.sol)
pragma solidity ^0.8.20;
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.1.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC-20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import {MarketAllocation} from "./IEulerEarn.sol";
import {IERC4626} from "../../lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol";
/// @dev Max settable flow cap, such that caps can always be stored on 128 bits.
/// @dev The actual max possible flow cap is type(uint128).max-1.
/// @dev Equals to 170141183460469231731687303715884105727;
uint128 constant MAX_SETTABLE_FLOW_CAP = type(uint128).max / 2;
struct FlowCaps {
/// @notice The maximum allowed inflow in a vault.
uint128 maxIn;
/// @notice The maximum allowed outflow in a vault.
uint128 maxOut;
}
struct FlowCapsConfig {
/// @notice Vault for which to change flow caps.
IERC4626 id;
/// @notice New flow caps for this vault.
FlowCaps caps;
}
struct Withdrawal {
/// @notice The vault from which to withdraw.
IERC4626 id;
/// @notice The amount to withdraw.
uint128 amount;
}
/// @dev This interface is used for factorizing IPublicAllocatorStaticTyping and IPublicAllocator.
/// @dev Consider using the IPublicAllocator interface instead of this one.
interface IPublicAllocatorBase {
/// @notice The admin for a given vault.
function admin(address vault) external view returns (address);
/// @notice The current ETH fee for a given vault.
function fee(address vault) external view returns (uint256);
/// @notice The accrued ETH fee for a given vault.
function accruedFee(address vault) external view returns (uint256);
/// @notice Reallocates from a list of vaults to one vault.
/// @param vault The EulerEarn vault to reallocate.
/// @param withdrawals The vaults to withdraw from, and the amounts to withdraw.
/// @param supplyId The vault receiving total withdrawn to.
/// @dev Will call EulerEarn's `reallocate`.
/// @dev Checks that the flow caps are respected.
/// @dev Will revert when `withdrawals` contains a duplicate or is not sorted.
/// @dev Will revert if `withdrawals` contains the supply vault.
/// @dev Will revert if a withdrawal amount is larger than available liquidity.
function reallocateTo(address vault, Withdrawal[] calldata withdrawals, IERC4626 supplyId) external payable;
/// @notice Sets the admin for a given vault.
function setAdmin(address vault, address newAdmin) external;
/// @notice Sets the fee for a given vault.
function setFee(address vault, uint256 newFee) external;
/// @notice Transfers the current balance to `feeRecipient` for a given vault.
function transferFee(address vault, address payable feeRecipient) external;
/// @notice Sets the maximum inflow and outflow through public allocation for some vaults for a given Earn vault.
/// @dev Max allowed inflow/outflow is MAX_SETTABLE_FLOW_CAP.
/// @dev Doesn't revert if it doesn't change the storage at all.
function setFlowCaps(address vault, FlowCapsConfig[] calldata config) external;
}
/// @dev This interface is inherited by PublicAllocator so that function signatures are checked by the compiler.
/// @dev Consider using the IPublicAllocator interface instead of this one.
interface IPublicAllocatorStaticTyping is IPublicAllocatorBase {
/// @notice Returns (maximum inflow, maximum outflow) through public allocation of a given vault for a given Earn vault.
function flowCaps(address vault, IERC4626) external view returns (uint128, uint128);
}
/// @title IPublicAllocator
/// @author Forked with gratitude from Morpho Labs. Inspired by Silo Labs.
/// @custom:contact [email protected]
/// @custom:contact [email protected]
/// @dev Use this interface for PublicAllocator to have access to all the functions with the appropriate function
/// signatures.
interface IPublicAllocator is IPublicAllocatorBase {
/// @notice Returns the maximum inflow and maximum outflow through public allocation of a given vault for a given
/// Earn vault.
function flowCaps(address vault, IERC4626) external view returns (FlowCaps memory);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title AllowanceTransfer
/// @notice Handles ERC20 token permissions through signature based allowance setting and ERC20 token transfers by checking allowed amounts
/// @dev Requires user's token approval on the Permit2 contract
interface IAllowanceTransfer {
/// @notice A mapping from owner address to token address to spender address to PackedAllowance struct, which contains details and conditions of the approval.
/// @notice The mapping is indexed in the above order see: allowance[ownerAddress][tokenAddress][spenderAddress]
/// @dev The packed slot holds the allowed amount, expiration at which the allowed amount is no longer valid, and current nonce thats updated on any signature based approvals.
function allowance(address user, address token, address spender)
external
view
returns (uint160 amount, uint48 expiration, uint48 nonce);
/// @notice Approves the spender to use up to amount of the specified token up until the expiration
/// @param token The token to approve
/// @param spender The spender address to approve
/// @param amount The approved amount of the token
/// @param expiration The timestamp at which the approval is no longer valid
/// @dev The packed allowance also holds a nonce, which will stay unchanged in approve
/// @dev Setting amount to type(uint160).max sets an unlimited approval
function approve(address token, address spender, uint160 amount, uint48 expiration) external;
/// @notice Transfer approved tokens from one address to another
/// @param from The address to transfer from
/// @param to The address of the recipient
/// @param amount The amount of the token to transfer
/// @param token The token address to transfer
/// @dev Requires the from address to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(address from, address to, uint160 amount, address token) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* Both values are immutable: they can only be set once during construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner`'s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance < type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.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.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* 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 Ownable is Context {
address private _owner;
/**
* @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.
*/
constructor(address initialOwner) {
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) {
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 {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// 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: GPL-2.0-or-later pragma solidity >=0.8.0; /// @title IEVC /// @custom:security-contact [email protected] /// @author Euler Labs (https://www.eulerlabs.com/) /// @notice This interface defines the methods for the Ethereum Vault Connector. interface IEVC { /// @notice A struct representing a batch item. /// @dev Each batch item represents a single operation to be performed within a checks deferred context. struct BatchItem { /// @notice The target contract to be called. address targetContract; /// @notice The account on behalf of which the operation is to be performed. msg.sender must be authorized to /// act on behalf of this account. Must be address(0) if the target contract is the EVC itself. address onBehalfOfAccount; /// @notice The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole /// balance of the EVC contract will be forwarded. Must be 0 if the target contract is the EVC itself. uint256 value; /// @notice The encoded data which is called on the target contract. bytes data; } /// @notice A struct representing the result of a batch item operation. /// @dev Used only for simulation purposes. struct BatchItemResult { /// @notice A boolean indicating whether the operation was successful. bool success; /// @notice The result of the operation. bytes result; } /// @notice A struct representing the result of the account or vault status check. /// @dev Used only for simulation purposes. struct StatusCheckResult { /// @notice The address of the account or vault for which the check was performed. address checkedAddress; /// @notice A boolean indicating whether the status of the account or vault is valid. bool isValid; /// @notice The result of the check. bytes result; } /// @notice Returns current raw execution context. /// @dev When checks in progress, on behalf of account is always address(0). /// @return context Current raw execution context. function getRawExecutionContext() external view returns (uint256 context); /// @notice Returns an account on behalf of which the operation is being executed at the moment and whether the /// controllerToCheck is an enabled controller for that account. /// @dev This function should only be used by external smart contracts if msg.sender is the EVC. Otherwise, the /// account address returned must not be trusted. /// @dev When checks in progress, on behalf of account is always address(0). When address is zero, the function /// reverts to protect the consumer from ever relying on the on behalf of account address which is in its default /// state. /// @param controllerToCheck The address of the controller for which it is checked whether it is an enabled /// controller for the account on behalf of which the operation is being executed at the moment. /// @return onBehalfOfAccount An account that has been authenticated and on behalf of which the operation is being /// executed at the moment. /// @return controllerEnabled A boolean value that indicates whether controllerToCheck is an enabled controller for /// the account on behalf of which the operation is being executed at the moment. Always false if controllerToCheck /// is address(0). function getCurrentOnBehalfOfAccount(address controllerToCheck) external view returns (address onBehalfOfAccount, bool controllerEnabled); /// @notice Checks if checks are deferred. /// @return A boolean indicating whether checks are deferred. function areChecksDeferred() external view returns (bool); /// @notice Checks if checks are in progress. /// @return A boolean indicating whether checks are in progress. function areChecksInProgress() external view returns (bool); /// @notice Checks if control collateral is in progress. /// @return A boolean indicating whether control collateral is in progress. function isControlCollateralInProgress() external view returns (bool); /// @notice Checks if an operator is authenticated. /// @return A boolean indicating whether an operator is authenticated. function isOperatorAuthenticated() external view returns (bool); /// @notice Checks if a simulation is in progress. /// @return A boolean indicating whether a simulation is in progress. function isSimulationInProgress() external view returns (bool); /// @notice Checks whether the specified account and the other account have the same owner. /// @dev The function is used to check whether one account is authorized to perform operations on behalf of the /// other. Accounts are considered to have a common owner if they share the first 19 bytes of their address. /// @param account The address of the account that is being checked. /// @param otherAccount The address of the other account that is being checked. /// @return A boolean flag that indicates whether the accounts have the same owner. function haveCommonOwner(address account, address otherAccount) external pure returns (bool); /// @notice Returns the address prefix of the specified account. /// @dev The address prefix is the first 19 bytes of the account address. /// @param account The address of the account whose address prefix is being retrieved. /// @return A bytes19 value that represents the address prefix of the account. function getAddressPrefix(address account) external pure returns (bytes19); /// @notice Returns the owner for the specified account. /// @dev The function returns address(0) if the owner is not registered. Registration of the owner happens on the /// initial /// interaction with the EVC that requires authentication of an owner. /// @param account The address of the account whose owner is being retrieved. /// @return owner The address of the account owner. An account owner is an EOA/smart contract which address matches /// the first 19 bytes of the account address. function getAccountOwner(address account) external view returns (address); /// @notice Checks if lockdown mode is enabled for a given address prefix. /// @param addressPrefix The address prefix to check for lockdown mode status. /// @return A boolean indicating whether lockdown mode is enabled. function isLockdownMode(bytes19 addressPrefix) external view returns (bool); /// @notice Checks if permit functionality is disabled for a given address prefix. /// @param addressPrefix The address prefix to check for permit functionality status. /// @return A boolean indicating whether permit functionality is disabled. function isPermitDisabledMode(bytes19 addressPrefix) external view returns (bool); /// @notice Returns the current nonce for a given address prefix and nonce namespace. /// @dev Each nonce namespace provides 256 bit nonce that has to be used sequentially. There's no requirement to use /// all the nonces for a given nonce namespace before moving to the next one which allows to use permit messages in /// a non-sequential manner. /// @param addressPrefix The address prefix for which the nonce is being retrieved. /// @param nonceNamespace The nonce namespace for which the nonce is being retrieved. /// @return nonce The current nonce for the given address prefix and nonce namespace. function getNonce(bytes19 addressPrefix, uint256 nonceNamespace) external view returns (uint256 nonce); /// @notice Returns the bit field for a given address prefix and operator. /// @dev The bit field is used to store information about authorized operators for a given address prefix. Each bit /// in the bit field corresponds to one account belonging to the same owner. If the bit is set, the operator is /// authorized for the account. /// @param addressPrefix The address prefix for which the bit field is being retrieved. /// @param operator The address of the operator for which the bit field is being retrieved. /// @return operatorBitField The bit field for the given address prefix and operator. The bit field defines which /// accounts the operator is authorized for. It is a 256-position binary array like 0...010...0, marking the account /// positionally in a uint256. The position in the bit field corresponds to the account ID (0-255), where 0 is the /// owner account's ID. function getOperator(bytes19 addressPrefix, address operator) external view returns (uint256 operatorBitField); /// @notice Returns whether a given operator has been authorized for a given account. /// @param account The address of the account whose operator is being checked. /// @param operator The address of the operator that is being checked. /// @return authorized A boolean value that indicates whether the operator is authorized for the account. function isAccountOperatorAuthorized(address account, address operator) external view returns (bool authorized); /// @notice Enables or disables lockdown mode for a given address prefix. /// @dev This function can only be called by the owner of the address prefix. To disable this mode, the EVC /// must be called directly. It is not possible to disable this mode by using checks-deferrable call or /// permit message. /// @param addressPrefix The address prefix for which the lockdown mode is being set. /// @param enabled A boolean indicating whether to enable or disable lockdown mode. function setLockdownMode(bytes19 addressPrefix, bool enabled) external payable; /// @notice Enables or disables permit functionality for a given address prefix. /// @dev This function can only be called by the owner of the address prefix. To disable this mode, the EVC /// must be called directly. It is not possible to disable this mode by using checks-deferrable call or (by /// definition) permit message. To support permit functionality by default, note that the logic was inverted here. To /// disable the permit functionality, one must pass true as the second argument. To enable the permit /// functionality, one must pass false as the second argument. /// @param addressPrefix The address prefix for which the permit functionality is being set. /// @param enabled A boolean indicating whether to enable or disable the disable-permit mode. function setPermitDisabledMode(bytes19 addressPrefix, bool enabled) external payable; /// @notice Sets the nonce for a given address prefix and nonce namespace. /// @dev This function can only be called by the owner of the address prefix. Each nonce namespace provides a 256 /// bit nonce that has to be used sequentially. There's no requirement to use all the nonces for a given nonce /// namespace before moving to the next one which allows the use of permit messages in a non-sequential manner. To /// invalidate signed permit messages, set the nonce for a given nonce namespace accordingly. To invalidate all the /// permit messages for a given nonce namespace, set the nonce to type(uint).max. /// @param addressPrefix The address prefix for which the nonce is being set. /// @param nonceNamespace The nonce namespace for which the nonce is being set. /// @param nonce The new nonce for the given address prefix and nonce namespace. function setNonce(bytes19 addressPrefix, uint256 nonceNamespace, uint256 nonce) external payable; /// @notice Sets the bit field for a given address prefix and operator. /// @dev This function can only be called by the owner of the address prefix. Each bit in the bit field corresponds /// to one account belonging to the same owner. If the bit is set, the operator is authorized for the account. /// @param addressPrefix The address prefix for which the bit field is being set. /// @param operator The address of the operator for which the bit field is being set. Can neither be the EVC address /// nor an address belonging to the same address prefix. /// @param operatorBitField The new bit field for the given address prefix and operator. Reverts if the provided /// value is equal to the currently stored value. function setOperator(bytes19 addressPrefix, address operator, uint256 operatorBitField) external payable; /// @notice Authorizes or deauthorizes an operator for the account. /// @dev Only the owner or authorized operator of the account can call this function. An operator is an address that /// can perform actions for an account on behalf of the owner. If it's an operator calling this function, it can /// only deauthorize itself. /// @param account The address of the account whose operator is being set or unset. /// @param operator The address of the operator that is being installed or uninstalled. Can neither be the EVC /// address nor an address belonging to the same owner as the account. /// @param authorized A boolean value that indicates whether the operator is being authorized or deauthorized. /// Reverts if the provided value is equal to the currently stored value. function setAccountOperator(address account, address operator, bool authorized) external payable; /// @notice Returns an array of collaterals enabled for an account. /// @dev A collateral is a vault for which an account's balances are under the control of the currently enabled /// controller vault. /// @param account The address of the account whose collaterals are being queried. /// @return An array of addresses that are enabled collaterals for the account. function getCollaterals(address account) external view returns (address[] memory); /// @notice Returns whether a collateral is enabled for an account. /// @dev A collateral is a vault for which account's balances are under the control of the currently enabled /// controller vault. /// @param account The address of the account that is being checked. /// @param vault The address of the collateral that is being checked. /// @return A boolean value that indicates whether the vault is an enabled collateral for the account or not. function isCollateralEnabled(address account, address vault) external view returns (bool); /// @notice Enables a collateral for an account. /// @dev A collaterals is a vault for which account's balances are under the control of the currently enabled /// controller vault. Only the owner or an operator of the account can call this function. Unless it's a duplicate, /// the collateral is added to the end of the array. There can be at most 10 unique collaterals enabled at a time. /// Account status checks are performed. /// @param account The account address for which the collateral is being enabled. /// @param vault The address being enabled as a collateral. function enableCollateral(address account, address vault) external payable; /// @notice Disables a collateral for an account. /// @dev This function does not preserve the order of collaterals in the array obtained using the getCollaterals /// function; the order may change. A collateral is a vault for which account’s balances are under the control of /// the currently enabled controller vault. Only the owner or an operator of the account can call this function. /// Disabling a collateral might change the order of collaterals in the array obtained using getCollaterals /// function. Account status checks are performed. /// @param account The account address for which the collateral is being disabled. /// @param vault The address of a collateral being disabled. function disableCollateral(address account, address vault) external payable; /// @notice Swaps the position of two collaterals so that they appear switched in the array of collaterals for a /// given account obtained by calling getCollaterals function. /// @dev A collateral is a vault for which account’s balances are under the control of the currently enabled /// controller vault. Only the owner or an operator of the account can call this function. The order of collaterals /// can be changed by specifying the indices of the two collaterals to be swapped. Indices are zero-based and must /// be in the range of 0 to the number of collaterals minus 1. index1 must be lower than index2. Account status /// checks are performed. /// @param account The address of the account for which the collaterals are being reordered. /// @param index1 The index of the first collateral to be swapped. /// @param index2 The index of the second collateral to be swapped. function reorderCollaterals(address account, uint8 index1, uint8 index2) external payable; /// @notice Returns an array of enabled controllers for an account. /// @dev A controller is a vault that has been chosen for an account to have special control over the account's /// balances in enabled collaterals vaults. A user can have multiple controllers during a call execution, but at /// most one can be selected when the account status check is performed. /// @param account The address of the account whose controllers are being queried. /// @return An array of addresses that are the enabled controllers for the account. function getControllers(address account) external view returns (address[] memory); /// @notice Returns whether a controller is enabled for an account. /// @dev A controller is a vault that has been chosen for an account to have special control over account’s /// balances in the enabled collaterals vaults. /// @param account The address of the account that is being checked. /// @param vault The address of the controller that is being checked. /// @return A boolean value that indicates whether the vault is enabled controller for the account or not. function isControllerEnabled(address account, address vault) external view returns (bool); /// @notice Enables a controller for an account. /// @dev A controller is a vault that has been chosen for an account to have special control over account’s /// balances in the enabled collaterals vaults. Only the owner or an operator of the account can call this function. /// Unless it's a duplicate, the controller is added to the end of the array. Transiently, there can be at most 10 /// unique controllers enabled at a time, but at most one can be enabled after the outermost checks-deferrable /// call concludes. Account status checks are performed. /// @param account The address for which the controller is being enabled. /// @param vault The address of the controller being enabled. function enableController(address account, address vault) external payable; /// @notice Disables a controller for an account. /// @dev A controller is a vault that has been chosen for an account to have special control over account’s /// balances in the enabled collaterals vaults. Only the vault itself can call this function. Disabling a controller /// might change the order of controllers in the array obtained using getControllers function. Account status checks /// are performed. /// @param account The address for which the calling controller is being disabled. function disableController(address account) external payable; /// @notice Executes signed arbitrary data by self-calling into the EVC. /// @dev Low-level call function is used to execute the arbitrary data signed by the owner or the operator on the /// EVC contract. During that call, EVC becomes msg.sender. /// @param signer The address signing the permit message (ECDSA) or verifying the permit message signature /// (ERC-1271). It's also the owner or the operator of all the accounts for which authentication will be needed /// during the execution of the arbitrary data call. /// @param sender The address of the msg.sender which is expected to execute the data signed by the signer. If /// address(0) is passed, the msg.sender is ignored. /// @param nonceNamespace The nonce namespace for which the nonce is being used. /// @param nonce The nonce for the given account and nonce namespace. A valid nonce value is considered to be the /// value currently stored and can take any value between 0 and type(uint256).max - 1. /// @param deadline The timestamp after which the permit is considered expired. /// @param value The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole /// balance of the EVC contract will be forwarded. /// @param data The encoded data which is self-called on the EVC contract. /// @param signature The signature of the data signed by the signer. function permit( address signer, address sender, uint256 nonceNamespace, uint256 nonce, uint256 deadline, uint256 value, bytes calldata data, bytes calldata signature ) external payable; /// @notice Calls into a target contract as per data encoded. /// @dev This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost /// call ends, the account and vault status checks are performed. /// @dev This function can be used to interact with any contract while checks are deferred. If the target contract /// is msg.sender, msg.sender is called back with the calldata provided and the context set up according to the /// account provided. If the target contract is not msg.sender, only the owner or the operator of the account /// provided can call this function. /// @dev This function can be used to recover the remaining value from the EVC contract. /// @param targetContract The address of the contract to be called. /// @param onBehalfOfAccount If the target contract is msg.sender, the address of the account which will be set /// in the context. It assumes msg.sender has authenticated the account themselves. If the target contract is /// not msg.sender, the address of the account for which it is checked whether msg.sender is authorized to act /// on behalf of. /// @param value The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole /// balance of the EVC contract will be forwarded. /// @param data The encoded data which is called on the target contract. /// @return result The result of the call. function call( address targetContract, address onBehalfOfAccount, uint256 value, bytes calldata data ) external payable returns (bytes memory result); /// @notice For a given account, calls into one of the enabled collateral vaults from the currently enabled /// controller vault as per data encoded. /// @dev This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost /// call ends, the account and vault status checks are performed. /// @dev This function can be used to interact with any contract while checks are deferred as long as the contract /// is enabled as a collateral of the account and the msg.sender is the only enabled controller of the account. /// @param targetCollateral The collateral address to be called. /// @param onBehalfOfAccount The address of the account for which it is checked whether msg.sender is authorized to /// act on behalf. /// @param value The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole /// balance of the EVC contract will be forwarded. /// @param data The encoded data which is called on the target collateral. /// @return result The result of the call. function controlCollateral( address targetCollateral, address onBehalfOfAccount, uint256 value, bytes calldata data ) external payable returns (bytes memory result); /// @notice Executes multiple calls into the target contracts while checks deferred as per batch items provided. /// @dev This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost /// call ends, the account and vault status checks are performed. /// @dev The authentication rules for each batch item are the same as for the call function. /// @param items An array of batch items to be executed. function batch(BatchItem[] calldata items) external payable; /// @notice Executes multiple calls into the target contracts while checks deferred as per batch items provided. /// @dev This function always reverts as it's only used for simulation purposes. This function cannot be called /// within a checks-deferrable call. /// @param items An array of batch items to be executed. function batchRevert(BatchItem[] calldata items) external payable; /// @notice Executes multiple calls into the target contracts while checks deferred as per batch items provided. /// @dev This function does not modify state and should only be used for simulation purposes. This function cannot /// be called within a checks-deferrable call. /// @param items An array of batch items to be executed. /// @return batchItemsResult An array of batch item results for each item. /// @return accountsStatusCheckResult An array of account status check results for each account. /// @return vaultsStatusCheckResult An array of vault status check results for each vault. function batchSimulation(BatchItem[] calldata items) external payable returns ( BatchItemResult[] memory batchItemsResult, StatusCheckResult[] memory accountsStatusCheckResult, StatusCheckResult[] memory vaultsStatusCheckResult ); /// @notice Retrieves the timestamp of the last successful account status check performed for a specific account. /// @dev This function reverts if the checks are in progress. /// @dev The account status check is considered to be successful if it calls into the selected controller vault and /// obtains expected magic value. This timestamp does not change if the account status is considered valid when no /// controller enabled. When consuming, one might need to ensure that the account status check is not deferred at /// the moment. /// @param account The address of the account for which the last status check timestamp is being queried. /// @return The timestamp of the last status check as a uint256. function getLastAccountStatusCheckTimestamp(address account) external view returns (uint256); /// @notice Checks whether the status check is deferred for a given account. /// @dev This function reverts if the checks are in progress. /// @param account The address of the account for which it is checked whether the status check is deferred. /// @return A boolean flag that indicates whether the status check is deferred or not. function isAccountStatusCheckDeferred(address account) external view returns (bool); /// @notice Checks the status of an account and reverts if it is not valid. /// @dev If checks deferred, the account is added to the set of accounts to be checked at the end of the outermost /// checks-deferrable call. There can be at most 10 unique accounts added to the set at a time. Account status /// check is performed by calling into the selected controller vault and passing the array of currently enabled /// collaterals. If controller is not selected, the account is always considered valid. /// @param account The address of the account to be checked. function requireAccountStatusCheck(address account) external payable; /// @notice Forgives previously deferred account status check. /// @dev Account address is removed from the set of addresses for which status checks are deferred. This function /// can only be called by the currently enabled controller of a given account. Depending on the vault /// implementation, may be needed in the liquidation flow. /// @param account The address of the account for which the status check is forgiven. function forgiveAccountStatusCheck(address account) external payable; /// @notice Checks whether the status check is deferred for a given vault. /// @dev This function reverts if the checks are in progress. /// @param vault The address of the vault for which it is checked whether the status check is deferred. /// @return A boolean flag that indicates whether the status check is deferred or not. function isVaultStatusCheckDeferred(address vault) external view returns (bool); /// @notice Checks the status of a vault and reverts if it is not valid. /// @dev If checks deferred, the vault is added to the set of vaults to be checked at the end of the outermost /// checks-deferrable call. There can be at most 10 unique vaults added to the set at a time. This function can /// only be called by the vault itself. function requireVaultStatusCheck() external payable; /// @notice Forgives previously deferred vault status check. /// @dev Vault address is removed from the set of addresses for which status checks are deferred. This function can /// only be called by the vault itself. function forgiveVaultStatusCheck() external payable; /// @notice Checks the status of an account and a vault and reverts if it is not valid. /// @dev If checks deferred, the account and the vault are added to the respective sets of accounts and vaults to be /// checked at the end of the outermost checks-deferrable call. Account status check is performed by calling into /// selected controller vault and passing the array of currently enabled collaterals. If controller is not selected, /// the account is always considered valid. This function can only be called by the vault itself. /// @param account The address of the account to be checked. function requireAccountAndVaultStatusCheck(address account) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; type EC is uint256; /// @title ExecutionContext /// @custom:security-contact [email protected] /// @author Euler Labs (https://www.eulerlabs.com/) /// @notice This library provides functions for managing the execution context in the Ethereum Vault Connector. /// @dev The execution context is a bit field that stores the following information: /// @dev - on behalf of account - an account on behalf of which the currently executed operation is being performed /// @dev - checks deferred flag - used to indicate whether checks are deferred /// @dev - checks in progress flag - used to indicate that the account/vault status checks are in progress. This flag is /// used to prevent re-entrancy. /// @dev - control collateral in progress flag - used to indicate that the control collateral is in progress. This flag /// is used to prevent re-entrancy. /// @dev - operator authenticated flag - used to indicate that the currently executed operation is being performed by /// the account operator /// @dev - simulation flag - used to indicate that the currently executed batch call is a simulation /// @dev - stamp - dummy value for optimization purposes library ExecutionContext { uint256 internal constant ON_BEHALF_OF_ACCOUNT_MASK = 0x000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; uint256 internal constant CHECKS_DEFERRED_MASK = 0x0000000000000000000000FF0000000000000000000000000000000000000000; uint256 internal constant CHECKS_IN_PROGRESS_MASK = 0x00000000000000000000FF000000000000000000000000000000000000000000; uint256 internal constant CONTROL_COLLATERAL_IN_PROGRESS_LOCK_MASK = 0x000000000000000000FF00000000000000000000000000000000000000000000; uint256 internal constant OPERATOR_AUTHENTICATED_MASK = 0x0000000000000000FF0000000000000000000000000000000000000000000000; uint256 internal constant SIMULATION_MASK = 0x00000000000000FF000000000000000000000000000000000000000000000000; uint256 internal constant STAMP_OFFSET = 200; // None of the functions below modifies the state. All the functions operate on the copy // of the execution context and return its modified value as a result. In order to update // one should use the result of the function call as a new execution context value. function getOnBehalfOfAccount(EC self) internal pure returns (address result) { result = address(uint160(EC.unwrap(self) & ON_BEHALF_OF_ACCOUNT_MASK)); } function setOnBehalfOfAccount(EC self, address account) internal pure returns (EC result) { result = EC.wrap((EC.unwrap(self) & ~ON_BEHALF_OF_ACCOUNT_MASK) | uint160(account)); } function areChecksDeferred(EC self) internal pure returns (bool result) { result = EC.unwrap(self) & CHECKS_DEFERRED_MASK != 0; } function setChecksDeferred(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) | CHECKS_DEFERRED_MASK); } function areChecksInProgress(EC self) internal pure returns (bool result) { result = EC.unwrap(self) & CHECKS_IN_PROGRESS_MASK != 0; } function setChecksInProgress(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) | CHECKS_IN_PROGRESS_MASK); } function isControlCollateralInProgress(EC self) internal pure returns (bool result) { result = EC.unwrap(self) & CONTROL_COLLATERAL_IN_PROGRESS_LOCK_MASK != 0; } function setControlCollateralInProgress(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) | CONTROL_COLLATERAL_IN_PROGRESS_LOCK_MASK); } function isOperatorAuthenticated(EC self) internal pure returns (bool result) { result = EC.unwrap(self) & OPERATOR_AUTHENTICATED_MASK != 0; } function setOperatorAuthenticated(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) | OPERATOR_AUTHENTICATED_MASK); } function clearOperatorAuthenticated(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) & ~OPERATOR_AUTHENTICATED_MASK); } function isSimulationInProgress(EC self) internal pure returns (bool result) { result = EC.unwrap(self) & SIMULATION_MASK != 0; } function setSimulationInProgress(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) | SIMULATION_MASK); } }
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/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: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}{
"remappings": [
"ethereum-vault-connector/=lib/ethereum-vault-connector/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"ds-test/=lib/ethereum-vault-connector/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/erc4626-tests/",
"euler-vault-kit/=lib/euler-vault-kit/",
"forge-gas-snapshot/=lib/euler-vault-kit/lib/permit2/lib/forge-gas-snapshot/src/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin/=lib/ethereum-vault-connector/lib/openzeppelin-contracts/contracts/",
"permit2/=lib/euler-vault-kit/lib/permit2/",
"solmate/=lib/euler-vault-kit/lib/permit2/lib/solmate/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "london",
"viaIR": true
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"evc","type":"address"},{"internalType":"address","name":"permit2","type":"address"},{"internalType":"uint256","name":"initialTimelock","type":"uint256"},{"internalType":"address","name":"_asset","type":"address"},{"internalType":"string","name":"__name","type":"string"},{"internalType":"string","name":"__symbol","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AboveMaxTimelock","type":"error"},{"inputs":[],"name":"AllCapsReached","type":"error"},{"inputs":[],"name":"AlreadyPending","type":"error"},{"inputs":[],"name":"AlreadySet","type":"error"},{"inputs":[],"name":"BadAssetReceiver","type":"error"},{"inputs":[],"name":"BelowMinTimelock","type":"error"},{"inputs":[],"name":"ControllerDisabled","type":"error"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"DuplicateMarket","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":"EVC_InvalidAddress","type":"error"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"InconsistentAsset","type":"error"},{"inputs":[],"name":"InconsistentReallocation","type":"error"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"InvalidMarketRemovalNonZeroCap","type":"error"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"InvalidMarketRemovalNonZeroSupply","type":"error"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"InvalidMarketRemovalTimelockNotElapsed","type":"error"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"MarketNotEnabled","type":"error"},{"inputs":[],"name":"MaxFeeExceeded","type":"error"},{"inputs":[],"name":"MaxQueueLengthExceeded","type":"error"},{"inputs":[],"name":"NoPendingValue","type":"error"},{"inputs":[],"name":"NonZeroCap","type":"error"},{"inputs":[],"name":"NotAllocatorRole","type":"error"},{"inputs":[],"name":"NotAuthorized","type":"error"},{"inputs":[],"name":"NotCuratorNorGuardianRole","type":"error"},{"inputs":[],"name":"NotCuratorRole","type":"error"},{"inputs":[],"name":"NotEnoughLiquidity","type":"error"},{"inputs":[],"name":"NotGuardianRole","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":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"PendingCap","type":"error"},{"inputs":[],"name":"PendingRemoval","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"SupplyCapExceeded","type":"error"},{"inputs":[],"name":"TimelockNotElapsed","type":"error"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"UnauthorizedMarket","type":"error"},{"inputs":[],"name":"ZeroFeeRecipient","type":"error"},{"inputs":[],"name":"ZeroShares","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newTotalAssets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeShares","type":"uint256"}],"name":"AccrueInterest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"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":"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":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"contract IERC4626","name":"id","type":"address"},{"indexed":false,"internalType":"uint256","name":"suppliedAssets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"suppliedShares","type":"uint256"}],"name":"ReallocateSupply","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"contract IERC4626","name":"id","type":"address"},{"indexed":false,"internalType":"uint256","name":"withdrawnAssets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"withdrawnShares","type":"uint256"}],"name":"ReallocateWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"RevokePendingCap","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"RevokePendingGuardian","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"RevokePendingMarketRemoval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"RevokePendingTimelock","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"contract IERC4626","name":"id","type":"address"},{"indexed":false,"internalType":"uint256","name":"cap","type":"uint256"}],"name":"SetCap","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newCurator","type":"address"}],"name":"SetCurator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"SetFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newFeeRecipient","type":"address"}],"name":"SetFeeRecipient","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"guardian","type":"address"}],"name":"SetGuardian","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"allocator","type":"address"},{"indexed":false,"internalType":"bool","name":"isAllocator","type":"bool"}],"name":"SetIsAllocator","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"name","type":"string"}],"name":"SetName","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"contract IERC4626[]","name":"newSupplyQueue","type":"address[]"}],"name":"SetSupplyQueue","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"symbol","type":"string"}],"name":"SetSymbol","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"newTimelock","type":"uint256"}],"name":"SetTimelock","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"contract IERC4626[]","name":"newWithdrawQueue","type":"address[]"}],"name":"SetWithdrawQueue","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"contract IERC4626","name":"id","type":"address"},{"indexed":false,"internalType":"uint256","name":"cap","type":"uint256"}],"name":"SubmitCap","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newGuardian","type":"address"}],"name":"SubmitGuardian","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"SubmitMarketRemoval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newTimelock","type":"uint256"}],"name":"SubmitTimelock","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":"uint256","name":"updatedTotalAssets","type":"uint256"}],"name":"UpdateLastTotalAssets","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newLostAssets","type":"uint256"}],"name":"UpdateLostAssets","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":"EVC","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"acceptCap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"acceptGuardian","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"acceptTimelock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC4626","name":"","type":"address"}],"name":"config","outputs":[{"internalType":"uint112","name":"balance","type":"uint112"},{"internalType":"uint136","name":"cap","type":"uint136"},{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"uint64","name":"removableAt","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"creator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"curator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"expectedSupplyAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fee","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"guardian","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isAllocator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastTotalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lostAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"maxWithdrawFromStrategy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC4626","name":"","type":"address"}],"name":"pendingCap","outputs":[{"internalType":"uint136","name":"value","type":"uint136"},{"internalType":"uint64","name":"validAt","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingGuardian","outputs":[{"internalType":"address","name":"value","type":"address"},{"internalType":"uint64","name":"validAt","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingTimelock","outputs":[{"internalType":"uint136","name":"value","type":"uint136"},{"internalType":"uint64","name":"validAt","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"permit2Address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC4626","name":"id","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"}],"internalType":"struct MarketAllocation[]","name":"allocations","type":"tuple[]"}],"name":"reallocate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"revokePendingCap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revokePendingGuardian","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"revokePendingMarketRemoval","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revokePendingTimelock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newCurator","type":"address"}],"name":"setCurator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newFeeRecipient","type":"address"}],"name":"setFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAllocator","type":"address"},{"internalType":"bool","name":"newIsAllocator","type":"bool"}],"name":"setIsAllocator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC4626[]","name":"newSupplyQueue","type":"address[]"}],"name":"setSupplyQueue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"},{"internalType":"uint256","name":"newSupplyCap","type":"uint256"}],"name":"submitCap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newGuardian","type":"address"}],"name":"submitGuardian","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC4626","name":"id","type":"address"}],"name":"submitMarketRemoval","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newTimelock","type":"uint256"}],"name":"submitTimelock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"supplyQueue","outputs":[{"internalType":"contract IERC4626","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"supplyQueueLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"timelock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","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":[{"internalType":"uint256[]","name":"indexes","type":"uint256[]"}],"name":"updateWithdrawQueue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"withdrawQueue","outputs":[{"internalType":"contract IERC4626","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawQueueLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]Contract Creation Code
0x61012080604052346108b657615217803803809161001d82856108bb565b8339810160e0828203126108b657610034826108de565b91610041602082016108de565b9161004e604083016108de565b92606083015190610061608085016108de565b60a08501519094906001600160401b0381116108b65784610083918301610930565b60c08201519094906001600160401b0381116108b6576100a39201610930565b60405160209791956001600160a01b0316906100bf89826108bb565b60008152604051906100d18a836108bb565b6000808352600190558051906001600160401b0382116105125760045490600182811c921680156108ac575b8c8310146104f25781601f84931161085a575b508b90601f83116001146107f0576000926107e5575b50508160011b916000199060031b1c1916176004555b8051906001600160401b0382116105125760055490600182811c921680156107db575b8b8310146104f25781601f849311610789575b508a90601f831160011461072157600092610716575b50508160011b916000199060031b1c1916176005555b6101a7816109a1565b901561070e575b60a0526080526001600160a01b03169081156106f857600780546001600160a01b0319908116909155600680549182168417905560405192906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a36001600160a01b03169081156106e75786908260c052836106a8575b83600c5533928033146105fd575b50506040519283526001600160a01b03909116916000805160206151f78339815191529190a26000600f5580516001600160401b03811161051257601554600181811c911680156105f3575b868210146104f257601f81116105ac575b5084601f82116001146105335791816102e8926000805160206151d783398151915294600091610528575b508160011b916000199060031b1c1916176015555b60405191829182610975565b0390a18051926001600160401b03841161051257601654600181811c91168015610508575b828210146104f257601f81116104ab575b5080601f851160011461041d575090837fadf3ae8bd543b3007d464f15cb8ea1db3f44e84d41d203164f40b95e27558ac6939461037d93600091610412575b508160011b916000199060031b1c19161760165560405191829182610975565b0390a160e052336101005260405161478e9081610a4982396080518181816104530152818161250201528181613128015281816134b5015281816138700152613c53015260a05181612564015260c05181818161129301528181613b1101528181613f5c0152614008015260e051818181610a870152613104015261010051818181610535015281816116af01526128e10152f35b90508201513861035d565b90601f198516601660005282600020926000905b8282106104935750509461037d9392600192827fadf3ae8bd543b3007d464f15cb8ea1db3f44e84d41d203164f40b95e27558ac697981061047a575b5050811b016016556102dc565b84015160001960f88460031b161c19169055388061046d565b80600185968294968901518155019501930190610431565b601660005281600020601f860160051c8101918387106104e8575b601f0160051c01905b8181106104dc575061031e565b600081556001016104cf565b90915081906104c6565b634e487b7160e01b600052602260045260246000fd5b90607f169061030d565b634e487b7160e01b600052604160045260246000fd5b9050820151386102c7565b601f198216906015600052866000209160005b88828210610596575050926000805160206151d78339815191529492600192826102e8961061057d575b5050811b016015556102dc565b84015160001960f88460031b161c191690553880610570565b6001849582939589015181550194019201610546565b601560005285600020601f830160051c8101918784106105e9575b601f0160051c01905b8181106105dd575061029c565b600081556001016105d0565b90915081906105c7565b90607f169061028b565b8180945060409350602491630c281d0f60e11b8252600060048301525afa801561069c578690600090610642575b91506000805160206151f78339815191523861023f565b90506040823d604011610694575b8161065d604093836108bb565b81010312610691578661066f836108de565b920151801515036106915750856000805160206151f78339815191529161062b565b80fd5b3d9150610650565b6040513d6000823e3d90fd5b90506212750083116106d6576201518083106106c5578690610231565b631a1593df60e11b60005260046000fd5b6346fedb5760e01b60005260046000fd5b638133abd160e01b60005260046000fd5b631e4fbdf760e01b600052600060045260246000fd5b5060126101ae565b015190503880610188565b600560009081528c81209350601f198516905b8d82821061077357505090846001959493921061075a575b505050811b0160055561019e565b015160001960f88460031b161c1916905538808061074c565b6001859682939686015181550195019301610734565b90915060056000528a600020601f840160051c8101918c85106107d1575b90601f859493920160051c01905b8181106107c25750610172565b600081558493506001016107b5565b90915081906107a7565b91607f169161015f565b015190503880610126565b600460009081528d81209350601f198516908e5b828210610842575050908460019594939210610829575b505050811b0160045561013c565b015160001960f88460031b161c1916905538808061081b565b80600186978294978701518155019601940190610804565b90915060046000528b600020601f840160051c8101918d85106108a2575b90601f859493920160051c01905b8181106108935750610110565b60008155849350600101610886565b9091508190610878565b91607f16916100fd565b600080fd5b601f909101601f19168101906001600160401b0382119082101761051257604052565b51906001600160a01b03821682036108b657565b6001600160401b03811161051257601f01601f191660200190565b60005b8381106109205750506000910152565b8181015183820152602001610910565b81601f820112156108b6578051610946816108f2565b9261095460405194856108bb565b818452602082840101116108b657610972916020808501910161090d565b90565b60409160208252610995815180928160208601526020868601910161090d565b601f01601f1916010190565b60008091604051602081019063313ce56760e01b8252600481526109c66024826108bb565b51916001600160a01b03165afa3d15610a40573d906109e4826108f2565b916109f260405193846108bb565b82523d6000602084013e5b80610a34575b610a11575b50600090600090565b6020818051810103126108b6576020015160ff8111610a08579060ff6001921690565b50602081511015610a03565b6060906109fd56fe6080604052600436101561001257600080fd5b60003560e01c806301e1d1141461291057806302d05d3f146128cb57806306fdde031461280c57806307a2d13a14611fc2578063095ea7b31461274b5780630a28a477146127225780630e68ec95146126ae57806318160ddd146126905780631ecca77c1461260557806321cb4b14146125e757806323b872dd146125ad578063313ce5671461254f57806333f91ebb1461253157806338d52e0f146124ec5780633a72efdf1461242f578063402d267d146123e057806341b6783314612011578063452a932014611fe85780634690484014611fc75780634cdad50614611fc25780634dedf20e14611f835780634e083eb314611d0a578063568efc0714611cec5780635897a06d14611b7357806362518ddf14611b4a5780636623b57514611b2757806369fe0e2d14611a4f5780636e553f65146119ea57806370a08231146119b0578063715018a6146119495780637224a51214611851578063762c31ba1461181657806379ba5097146117845780637cc4d9a11461174957806381bc23a6146116465780638a2c7b39146116075780638da5cb5b146115de57806394bf804d1461158d57806395d89b4114611489578063987ee783146114105780639d6b4a4514611343578063a17b313014611325578063a5f31d61146112c2578063a70354a11461127d578063a9059cbb14611245578063ac88990c14611166578063b192a84a146110ca578063b3d7f6b914611096578063b460af9414611056578063b65dbf5614611033578063ba08765214610fe0578063be9c580014610ab6578063c522498314610a71578063c63d75b614610a2e578063c6e6f592146103c7578063c9649aa914610992578063ce96cb771461096a578063d33219b41461094c578063d905777e14610918578063dd62ed3e146108c7578063ddca3f43146108a0578063e30c397814610877578063e66f53b71461084e578063e74b981b1461078c578063e90956cf1461071e578063ee7a4b33146103cc578063ef8b30f7146103c7578063f2fde38b1461035a5763f7d185211461031357600080fd5b34610355576020366003190112610355576004356011548110156103555761033c602091612a49565b905460405160039290921b1c6001600160a01b03168152f35b600080fd5b34610355576020366003190112610355576103736129a8565b61037b612fce565b600780546001600160a01b0319166001600160a01b039283169081179091556006549091167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e22700600080a3005b612a9e565b34610355576040366003190112610355576103e56129a8565b6024356103f0612fac565b6103f8614006565b6008546001600160a01b0391821691168114159081610708575b506106f7576040516338d52e0f60e01b81526001600160a01b0383169190602081600481865afa908115610663576000916106bd575b506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081169116036106a85781600052600e6020526001600160401b0360406000205460881c166106975781600052600b6020526001600160401b0360016040600020015416610686576001600160b81b03810361068057506001600160881b03905b80600052600b6020526001600160881b0360406000205460701c1680831461066f5782101561051657509061050961050f92613dd5565b90613415565b6001600055005b6040516367c1def960e01b8152600481018290529092506020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa90811561066357600091610629575b50156106145781600052600e602052604060002061058b82613dd5565b6001600160881b03600c549116825491816001600160881b031984161784556105bf6001600160401b0360881b9142612b37565b60881b169166ffffffffffffff60c81b16171790557f7bfc48861a5d71fc7afd7b9c92b4feeef1628ab1d5145dede52590c46dd155e9602060018060a01b03610606613f59565b1692604051908152a361050f565b5063320b1e2560e21b60005260045260246000fd5b90506020813d60201161065b575b8161064460209383612ac7565b810103126103555761065590612bc1565b8361056e565b3d9150610637565b6040513d6000823e3d90fd5b63a741a04560e01b60005260046000fd5b906104d2565b6325f600a360e11b60005260046000fd5b6324d9026760e11b60005260046000fd5b50634854a41360e11b60005260045260246000fd5b90506020813d6020116106ef575b816106d860209383612ac7565b81010312610355576106e990612c5b565b84610448565b3d91506106cb565b6332a2673b60e21b60005260046000fd5b6006546001600160a01b03161415905083610412565b34610355576020366003190112610355576107376129a8565b61073f612fce565b6008546001600160a01b03918216918116821461066f576001600160a01b03191681176008557fbd0a63c12948fbc9194a5839019f99c9d71db924e5c70018265bc778b8f1a506600080a2005b34610355576020366003190112610355576107a56129a8565b6107ad612fac565b6107b5612fce565b6010546001600160a01b0382169190606081901c831461066f578215908161083b575b5061082a576107e5613016565b6001600160601b036010549181199060601b169116176010557f2e979f80fe4d43055c584cf4a8467c55875ea36728fc37176c05acd784eb7a73600080a26001600055005b6333fe7c6560e21b60005260046000fd5b6001600160601b039150161515836107d8565b34610355576000366003190112610355576008546040516001600160a01b039091168152602090f35b34610355576000366003190112610355576007546040516001600160a01b039091168152602090f35b346103555760003660031901126103555760206001600160601b0360105416604051908152f35b34610355576040366003190112610355576108e06129a8565b6108e86129be565b6001600160a01b039182166000908152600260209081526040808320949093168252928352819020549051908152f35b3461035557602036600319011261035557602061094461093e6109396129a8565b613d41565b916130cd565b604051908152f35b34610355576000366003190112610355576020600c54604051908152f35b346103555760203660031901126103555760206109886109396129a8565b5050604051908152f35b34610355576000366003190112610355576109ab614006565b6006546001600160a01b0391821691168114159081610a18575b50610a07576000600f556001600160a01b036109df613f59565b167f921828337692c347c634c5d2aacbc7b756014674bd236f3cc2058d8e284a951b600080a2005b637cf97e4d60e11b60005260046000fd5b600a546001600160a01b031614159050816109c5565b3461035557602036600319011261035557610a476129a8565b506020610944610a6b610a58612ebf565b610a60612c6f565b509290600354612b37565b906130cd565b34610355576000366003190112610355576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b34610355576020366003190112610355576004356001600160401b03811161035557366023820112156103555780600401356001600160401b038111610355573660248260061b8401011161035557610b0d612fac565b6001600160a01b03610b1d614006565b1680600052600960205260ff60406000205416159081610fca575b81610fb4575b50610fa357610b4b613f59565b6000908190815b84831015610f85576000908360061b87019160406023198436030112610f8257604051604081018181106001600160401b03821117610f6e5760405260446020610b9e602487016129d4565b9283815201940135845260018060a01b031690818152600b602052604081205460f81c15610f5c57818152600b6020526001600160701b03604082205416906040519463266d6a8360e11b8652826004870152602086602481875afa958615610d1e578296610f29575b5080518087118188030296908715610dc357505081905115610db9575b80610d295750604051632d182be560e21b8152600481018690523060248201819052604482015260208160648185885af1908115610d1e578291610ce8575b509160019593916001600160701b03604081610c85610cdf99978096612c4e565b1692858152600b6020522091166001600160701b03198254161790556040519084825260208201527f416d9fcbb15941508bf9f557a950fb085de673ae90db45a32efdc9b35f29b0f16040878060a01b03891692a3612b37565b925b0191610b52565b90506020813d8211610d16575b81610d0260209383612ac7565b81010312610d1257516001610c64565b5080fd5b3d9150610cf5565b6040513d84823e3d90fd5b604051635d043b2960e11b8152600481018290523060248201819052604482015290955060208160648185885af1908115610d1e578291610d87575b509160019593916001600160701b03604081610c85610cdf9997988096612c4e565b90506020813d8211610db1575b81610da160209383612ac7565b81010312610d1257516001610d65565b3d9150610d94565b5093508381610c25565b9899959890965090506000198103610f1c575083870384881102945b8515610f0e57838252600b602052610e08866001600160881b03604085205460701c1692612b37565b11610efa57604051636e553f6560e01b8152600481018690523060248201529160208360448185885af1928315610d1e578293610ec6575b509160019593916001600160701b036040610e67610e6285610ec09a98612b37565b613d0e565b92858152600b6020522091166001600160701b03198254161790556040519084825260208201527f73e8a9d66522fa5c6fcec2e89aad8e52f6f66eadeb7fc7c172cfcbacb52838516040878060a01b03891692a3612b37565b93610ce1565b9092506020813d8211610ef2575b81610ee160209383612ac7565b81010312610d125751916001610e40565b3d9150610ed4565b63034506ef60e21b81526004839052602490fd5b505050509360019150610ce1565b8580820391110294610ddf565b9095506020813d8211610f54575b81610f4460209383612ac7565b81010312610d125751948b610c08565b3d9150610f37565b602491632215cda760e01b8252600452fd5b634e487b7160e01b83526041600452602483fd5b80fd5b8303610f92576001600055005b6309e36b8960e41b60005260046000fd5b63f7137c0f60e01b60005260046000fd5b6006546001600160a01b03161415905083610b3e565b6008546001600160a01b03168114159150610b38565b34610355576020611026610ff336612a64565b929190610ffe612fac565b611006613016565b6110166003546013549084613a62565b938491611021613f59565b613ade565b6001600055604051908152f35b346103555760203660031901126103555760206109446110516129a8565b612bce565b3461035557602061102661106936612a64565b9291611073612fac565b61107b613016565b61108b60035460135490836130a2565b938492611021613f59565b346103555760203660031901126103555760206109446110c26110b7612c6f565b509190600354612b37565b600435613a3b565b34610355576040366003190112610355576110e36129a8565b60243590811515809203610355576110f9612fce565b6001600160a01b031660008181526009602052604090205490919060ff161515811461066f5760207f74dc60cbc81a9472d04ad1d20e151d369c41104d655ed3f2f3091166a502cd8d918360005260098252604060002060ff1981541660ff8316179055604051908152a2005b346103555760203660031901126103555761117f6129a8565b611187614006565b600a546001600160a01b039182169116811415908161122f575b81611219575b50611208576001600160a01b039081166000818152600b60205260409020600101805467ffffffffffffffff19169055906111e0613f59565b167f8387c3346650400a72032f8bd1aa3f5f44038cf2bf32945e8eeb8a498decea77600080a3005b63d080fa3160e01b60005260046000fd5b6006546001600160a01b031614159050826111a7565b6008546001600160a01b031681141591506111a1565b34610355576040366003190112610355576112726112616129a8565b6024359061126d613f59565b612df7565b602060405160018152f35b34610355576000366003190112610355576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b3461035557600036600319011261035557600d546001600160401b038160a01c16801561131457421061130357611301906001600160a01b0316613a89565b005b63333bd2cb60e11b60005260046000fd5b63e5f408a560e01b60005260046000fd5b34610355576000366003190112610355576020601154604051908152f35b346103555760203660031901126103555761135c6129a8565b611364612fce565b600a546001600160a01b0382811692911682811461066f576001600160401b03600d5460a01c166106975761139d576113019150613a89565b506113be600c54826001600160601b0360a01b600d541617600d5542612b37565b600d805467ffffffffffffffff60a01b191660a09290921b67ffffffffffffffff60a01b169190911790557f7633313af54753bce8a149927263b1a55eba857ba4ef1d13c6aee25d384d3c4b600080a2005b34610355576020366003190112610355576001600160a01b036114316129a8565b16600052600e60205261148560406000205460405191816001600160881b036001600160401b03859460881c169116839092916001600160401b036020916001600160881b03604085019616845216910152565b0390f35b346103555760003660031901126103555760405160006016548060011c90600181168015611583575b60208310811461156f5782855290811561154b57506001146114eb575b611485836114df81850382612ac7565b60405191829182612936565b91905060166000527fd833147d7dc355ba459fc788f669e58cfaf9dc25ddcd0702e87d69c7b5124289916000905b808210611531575090915081016020016114df6114cf565b919260018160209254838588010152019101909291611519565b60ff191660208086019190915291151560051b840190910191506114df90506114cf565b634e487b7160e01b84526022600452602484fd5b91607f16916114b2565b346103555760403660031901126103555760206004356110266115ae6129be565b916115b7612fac565b6115bf613016565b6115cf6003546013549083613a3b565b80936115d9613f59565b6130f5565b34610355576000366003190112610355576006546040516001600160a01b039091168152602090f35b3461035557600036600319011261035557600f546001600160401b038160881c168015611314574210611303576001600160881b03611301911661338e565b346103555760203660031901126103555761165f6129a8565b6001600160a01b0381166000818152600e602052604090205490919060881c6001600160401b03168015611314574210611303576040516367c1def960e01b8152600481018390526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9081156106635760009161170f575b50156106145761130191600052600e6020526001600160881b036040600020541690613415565b90506020813d602011611741575b8161172a60209383612ac7565b810103126103555761173b90612bc1565b836116e8565b3d915061171d565b3461035557600036600319011261035557600f54604080516001600160881b038316815260889290921c6001600160401b0316602083015290f35b346103555760003660031901126103555761179d613f59565b6007546001600160a01b03918216911681900361180257600780546001600160a01b031990811690915560068054918216831790556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3005b63118cdaa760e01b60005260045260246000fd5b3461035557600036600319011261035557600d54604080516001600160a01b038316815260a09290921c6001600160401b0316602083015290f35b346103555760203660031901126103555760043561186d612fce565b600c5480821461066f576001600160401b03600f5460881c16610697576212750082116119385762015180821061192757808211156118b057506113019061338e565b816020916001600160881b037fb3aa0ade2442acf51d06713c2d1a5a3ec0373cce969d42b53f4689f97bccf3809416600f5491816001600160881b0319841617600f556119086001600160401b0360881b9142612b37565b60881b169166ffffffffffffff60c81b161717600f55604051908152a1005b631a1593df60e11b60005260046000fd5b6346fedb5760e01b60005260046000fd5b3461035557600036600319011261035557611962612fce565b600780546001600160a01b03199081169091556006805491821690556000906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b34610355576020366003190112610355576001600160a01b036119d16129a8565b1660005260016020526020604060002054604051908152f35b3461035557604036600319011261035557600435611a066129be565b90611a0f612fac565b611a17613016565b611a2760035460135490836130cd565b908115611a3e5781611026916020946115d9613f59565b639811e0c760e01b60005260046000fd5b3461035557602036600319011261035557600435611a6b612fac565b611a73612fce565b6010546001600160601b038116821461066f576706f05b59d3b200008211611b16578115159081611b0a575b5061082a576001600160601b0390611ab5613016565b16806001600160601b031960105416176010557f01fe2943baee27f47add82886c2200f910c749c461c9b63c5fe83901a53bdb49602060018060a01b03611afa613f59565b1692604051908152a26001600055005b905060601c1582611a9f565b63f4df6ae560e01b60005260046000fd5b34610355576020366003190112610355576020610944611b456129a8565b612b44565b34610355576020366003190112610355576004356012548110156103555761033c602091612a18565b3461035557602036600319011261035557611b8c6129a8565b611b94614006565b6008546001600160a01b0391821691168114159081611cd6575b506106f7576001600160a01b03166000818152600b60205260409020600101546001600160401b03166106975780600052600b6020526001600160881b0360406000205460701c16611cc55780600052600b60205260406000205460f81c15611cb15780600052600e6020526001600160401b0360406000205460881c16611c9d576001600160401b03611c44600c5442612b37565b1681600052600b6020526001604060002001906001600160401b031982541617905560018060a01b03611c75613f59565b167f354f25f4208ab6528fb2d016019c0e2a66f51376cbb2cc8571064779735d3485600080a3005b634fc6b6fd60e01b60005260045260246000fd5b632215cda760e01b60005260045260246000fd5b63624718b960e11b60005260046000fd5b6006546001600160a01b03161415905082611bae565b34610355576000366003190112610355576020601354604051908152f35b34610355576020366003190112610355576004356001600160401b03811161035557611d3a9036906004016129e8565b6001600160a01b03611d4a614006565b1680600052600960205260ff60406000205416159081611f6d575b81611f57575b50610fa357601e8111611f465760005b818110611ed557506001600160401b038111611ebf57600160401b8111611ebf5760115481601155808210611e79575b5081601160005260005b828110611e3e57506001600160a01b039050611dcf613f59565b1691604051918060208401602085525260408301919060005b818110611e1857857fb07686dd0abe7422b9801e8f38bafd24669a65591071f11120c2f6a7c175813e86860387a2005b909192602080600192838060a01b03611e30886129d4565b168152019401929101611de8565b6001906020611e4c84612b23565b930192817f31ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c68015501611db5565b60116000527f31ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c689081019082015b818110611eb35750611dab565b60008155600101611ea6565b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03611ef0611eeb838587612aff565b612b23565b16600052600b6020526001600160881b0360406000205460701c1615611f1857600101611d7b565b611eeb91611f2593612aff565b63320b1e2560e21b60009081526001600160a01b0391909116600452602490fd5b6340797bd760e11b60005260046000fd5b6006546001600160a01b03161415905083611d6b565b6008546001600160a01b03168114159150611d65565b34610355576020366003190112610355576001600160a01b03611fa46129a8565b166000526009602052602060ff604060002054166040519015158152f35b61297f565b3461035557600036600319011261035557602060105460601c604051908152f35b3461035557600036600319011261035557600a546040516001600160a01b039091168152602090f35b34610355576020366003190112610355576004356001600160401b038111610355576120419036906004016129e8565b906001600160a01b03612052614006565b1680600052600960205260ff604060002054161590816123ca575b816123b4575b50610fa35760125461208481612ae8565b6120916040519182612ac7565b818152601f196120a083612ae8565b013660208301376120b084612ae8565b926120be6040519485612ac7565b8484526120ca85612ae8565b602085019590601f190136873760005b8181106123475750505060005b82811061222f5750505080516001600160401b038111611ebf57600160401b8111611ebf57601254816012558082106121e9575b5082601260005260005b8281106121ac57506001600160a01b0391506121419050613f59565b1691604051916020830190602084525180915260408301919060005b81811061218d57857f834ae37621cd31f2636b1cb6f1bded844d79ecf755af866b5d896da642d7b56786860387a2005b82516001600160a01b031684526020938401939092019160010161215d565b81516001600160a01b03167fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec3444820155602090910190600101612125565b60126000527fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec34449081019082015b818110612223575061211b565b60008155600101612216565b6122398183612b0f565b5115612248575b6001016120e7565b61225181612a18565b905460039190911b1c6001600160a01b03166000818152600b602052604090205460701c6001600160881b03166123335780600052600e6020526001600160401b0360406000205460881c16611c9d576122aa81612b44565b6122c9575b6000908152600b6020526040812081815560010155612240565b80600052600b6020526001600160401b03600160406000200154161561231f5780600052600b6020526001600160401b03600160406000200154164210156122af57634b74115160e01b60005260045260246000fd5b6325dce25160e21b60005260045260246000fd5b6301554f3760e71b60005260045260246000fd5b612352818385612aff565b3561235c81612a18565b905460039190911b1c6001600160a01b0316906123798187612b0f565b5161239f5790600161238d81949388612b0f565b526123988289612b0f565b52016120da565b50633d85a77d60e11b60005260045260246000fd5b6006546001600160a01b03161415905083612073565b6008546001600160a01b0316811415915061206d565b34610355576020366003190112610355576123f96129a8565b50612402612ebf565b6124166124106110b7612c6f565b836130cd565b612427575060206000604051908152f35b602090610944565b34610355576020366003190112610355576124486129a8565b612450614006565b600a546001600160a01b03918216911681141590816124d6575b816124c0575b50611208576001600160a01b039081166000818152600e602052604081205590612498613f59565b167f23edd264f2dcc193d13a29cdab4ac169d60d9b4a0e74f0303c753036d8eb1c13600080a3005b6006546001600160a01b03161415905082612470565b6008546001600160a01b0316811415915061246a565b34610355576000366003190112610355576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b34610355576000366003190112610355576020601254604051908152f35b346103555760003660031901126103555760ff7f00000000000000000000000000000000000000000000000000000000000000001660ff811161259757602090604051908152f35b634e487b7160e01b600052601160045260246000fd5b34610355576060366003190112610355576112726125c96129a8565b6125d16129be565b6044359161126d836125e1613f59565b83612d4c565b34610355576000366003190112610355576020601454604051908152f35b346103555760003660031901126103555761261e614006565b6006546001600160a01b039182169116811415908161267a575b50610a07576000600d556001600160a01b03612652613f59565b167fc40a085ccfa20f5fd518ade5c3a77a7ecbdfbb4c75efcdca6146a8e3c841d663600080a2005b600a546001600160a01b03161415905081612638565b34610355576000366003190112610355576020600354604051908152f35b34610355576020366003190112610355576001600160a01b036126cf6129a8565b16600052600b602052608060406000206001600160401b036001825492015416604051916001600160701b03811683526001600160881b038160701c16602084015260f81c151560408301526060820152f35b346103555760203660031901126103555760206109446127436110b7612c6f565b6004356130a2565b34610355576040366003190112610355576127646129a8565b602435906001600160a01b03612778613f59565b169081156127f6576001600160a01b03169182156127e05760207f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925918360005260028252604060002085600052825280604060002055604051908152a3602060405160018152f35b634a1406b160e11b600052600060045260246000fd5b63e602df0560e01b600052600060045260246000fd5b346103555760003660031901126103555760405160006015548060011c906001811680156128c1575b60208310811461156f5782855290811561154b575060011461286157611485836114df81850382612ac7565b91905060156000527f55f448fdea98c4d29eb340757ef0a66cd03dbb9538908a6a81d96026b71ec475916000905b8082106128a7575090915081016020016114df6114cf565b91926001816020925483858801015201910190929161288f565b91607f1691612835565b34610355576000366003190112610355576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b3461035557600036600319011261035557602061292b612c6f565b509050604051908152f35b91909160208152825180602083015260005b818110612969575060409293506000838284010152601f8019910116010190565b8060208092870101516040828601015201612948565b346103555760203660031901126103555760206109446129a06110b7612c6f565b600435613a62565b600435906001600160a01b038216820361035557565b602435906001600160a01b038216820361035557565b35906001600160a01b038216820361035557565b9181601f84011215610355578235916001600160401b038311610355576020808501948460051b01011161035557565b601254811015612a3357601260005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b601154811015612a3357601160005260206000200190600090565b606090600319011261035557600435906024356001600160a01b038116810361035557906044356001600160a01b03811681036103555790565b34610355576020366003190112610355576020610944612abf6110b7612c6f565b6004356130cd565b90601f801991011681019081106001600160401b03821117611ebf57604052565b6001600160401b038111611ebf5760051b60200190565b9190811015612a335760051b0190565b8051821015612a335760209160051b010190565b356001600160a01b03811681036103555790565b9190820180921161259757565b60018060a01b031680600052600b60205260206001600160701b036040600020541660246040518094819363266d6a8360e11b835260048301525afa90811561066357600091612b92575090565b90506020813d602011612bb9575b81612bad60209383612ac7565b81010312610355575190565b3d9150612ba0565b5190811515820361035557565b60405163ce96cb7760e01b8152306004820152906020826024816001600160a01b0385165afa91821561066357600092612c18575b50612c0d90612b44565b818110908218021890565b90916020823d602011612c46575b81612c3360209383612ac7565b81010312610f8257505190612c0d612c03565b3d9150612c26565b9190820391821161259757565b51906001600160a01b038216820361035557565b6000906000806012545b808210612d1757505060135491601454612c938185612c4e565b831015612d095750612cb9612cb2612cab8486612c4e565b8094612b37565b9384612c4e565b80151580612cf5575b612cc95750565b612cf2919450612ce5906001600160601b036010541690613e08565b60035461093e8286612c4e565b92565b506001600160601b03601054161515612cc2565b612cb2612cb9918094612b37565b9091612d44600191612d3e612d2b86612a18565b858060a01b0391549060031b1c16612b44565b90612b37565b920190612c79565b6001600160a01b039081166000818152600260209081526040808320948616835293905291909120549291906000198410612d88575b50505050565b828410612dd25780156127f6576001600160a01b038216156127e057600052600260205260406000209060018060a01b031660005260205260406000209103905538808080612d82565b508290637dc7a0d960e11b60005260018060a01b031660045260245260445260646000fd5b6001600160a01b0316908115612ea9576001600160a01b0316918215612e9357600082815260016020526040812054828110612e795791604082827fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9587602096526001865203828220558681526001845220818154019055604051908152a3565b916064928463391434e360e21b8452600452602452604452fd5b63ec442f0560e01b600052600060045260246000fd5b634b637e8f60e11b600052600060045260246000fd5b60009060006011545b808210612ed3575050565b9092612ede84612a49565b905460039190911b1c6001600160a01b03166000818152600b602052604090205460701c6001600160881b03168015612fa1576020602491612f1f84612b44565b808203911102926040519283809263402d267d60e01b82523060048301525afa90811561066357600091612f6e575b50918183612f659360019510908218021890612b37565b935b0190612ec8565b906020823d8211612f99575b81612f8760209383612ac7565b81010312610f82575051612f65612f4e565b3d9150612f7a565b505092600190612f67565b600260005414612fbd576002600055565b633ee5aeb560e01b60005260046000fd5b6006546001600160a01b0390811690612fe5613f59565b1603612fed57565b612ff5613f59565b63118cdaa760e01b60009081526001600160a01b0391909116600452602490fd5b7ff66f28b40975dbb933913542c7e6a0f50a1d0f20aa74ea6e0efe65ab616323ec60407f548669ea9bcc24888e6d74a69c9865fa98d795686853b8aa3eb87814261bbb716020613064612c6f565b613071829593949261417d565b806014558551908152a18061308e575b82519182526020820152a1565b61309d8160105460601c6141ae565b613081565b9091620f4240830180931161259757620f42408101809111612597576130ca9260019261420d565b90565b9091620f4240830180931161259757620f42408101809111612597576130ca9260009261420d565b91929060006001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116907f000000000000000000000000000000000000000000000000000000000000000016828781846132cc575b6001600160a01b0316101590816132b8575b501561324057813b1561323c57604051631b63c28b60e11b81526001600160a01b0387811660048301523060248301528816604482015260648101919091529082908290608490829084905af18015610d1e57613225959361322a9795937fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d79360409361322c575b50505b6131f884826141ae565b815186815260208101949094526001600160a01b03908116941692a361321d81614280565b601354612b37565b61417d565b565b8161323691612ac7565b386131eb565b8280fd5b61322a969492507fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7915061322595936132b36040928351906323b872dd60e01b602083015260018060a01b0388166024830152306044830152886064830152606482526132ae608483612ac7565b6146dd565b6131ee565b905065ffffffffffff429116101538613163565b505060405163927da10560e01b81526001600160a01b0388166004820152602481018390523060448201529050606081606481865afa80156133835788908592869161331a575b5091613151565b925050506060813d60601161337b575b8161333760609383612ac7565b810103126133775780516001600160a01b038116810361337357889061336b60406133646020860161426d565b940161426d565b509138613313565b8480fd5b8380fd5b3d915061332a565b6040513d86823e3d90fd5b600c8190557fd28e9b90ee9b37c5936ff84392d71f29ff18117d7e76bcee60615262a90a3f7560206001600160a01b036133c6613f59565b1692604051908152a26000600f55565b3d15613410573d906001600160401b038211611ebf5760405191613404601f8201601f191660200184612ac7565b82523d6000602084013e565b606090565b919091613420613f59565b60009160018060a01b03811691828452600b602052604084208480604051602081019063c522498360e01b82526004815261345c602482612ac7565b5190875afa6134696133d6565b9080613a2f575b15613a275760208180518101031261380357602001516001600160a01b0381169081900361380357965b6001600160881b038116938415613863576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116908a16806137555750868098999a506134ee9161461c565b825460f81c15613578575b509181600080516020614739833981519152936001602094016001600160401b031981541690555b815470ffffffffffffffffffffffffffffffffff60701b191660709190911b70ffffffffffffffffffffffffffffffffff60701b161790556040519384526001600160a01b031692a38152600e6020526040812055565b909192939450601254600160401b8110156137415780600161359d9201601255612a18565b81546001600160a01b0360039290921b91821b19169088901b179055601254601e106137325782546001600160f81b0316600160f81b1783556040516370a0823160e01b81523060048201526020816024818a5afa9081156137275788916136f3575b506132258796959493926001600160701b0361361e61363a94613d0e565b166001600160701b0319865416178555612d3e60135491612b44565b604051602081019060208152601254809252604081019160128a527fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec3444908a5b8181106136d15750505091602093917f834ae37621cd31f2636b1cb6f1bded844d79ecf755af866b5d896da642d7b56784600080516020614739833981519152979560018060a01b038716930390a2919350916134f9565b82546001600160a01b031685528a995060209094019360019283019201613679565b90506020813d60201161371f575b8161370e60209383612ac7565b81010312610355575161363a613600565b3d9150613701565b6040513d8a823e3d90fd5b6340797bd760e11b8752600487fd5b634e487b7160e01b88526041600452602488fd5b9199604051636eb1769f60e11b8152306004820152836024820152602081604481865afa908115613858578a91613826575b5015613816575b50813b15613812576040516387517c4560e01b81526004810191909152602481018790526001600160a01b03604482015265ffffffffffff60648201529087908290608490829084905af18015613807576137ee575b50849596976134ee565b6137f9878092612ac7565b61380357386137e4565b8580fd5b6040513d89823e3d90fd5b8780fd5b613820908261461c565b3861378e565b90506020813d602011613850575b8161384160209383612ac7565b81010312610355575138613787565b3d9150613834565b6040513d8c823e3d90fd5b5095966001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811691168061398f575060405163095ea7b360e01b602082019081526024820187905260448083018990528252969795968796929187918a918291906138d6606482612ac7565b519082865af16138e46133d6565b81613922575b509160008051602061473983398151915295939183602096945015613911575b5050613521565b61391a91614590565b50388761390a565b915050805190811591821561394b575b50879190506000805160206147398339815191526138ea565b8180949596979899506020935001031261381257926020928796959287613982866000805160206147398339815191529801612bc1565b9294965081939550613932565b90813b15613a235786916084839260405194859384926387517c4560e01b845260048401528a60248401528160448401528160648401525af18015613a18576139ef575b5060008051602061473983398151915291602091859697613521565b9160209186613a0e879860008051602061473983398151915296612ac7565b96509150916139d3565b6040513d88823e3d90fd5b8680fd5b50849661349a565b50602081511015613470565b90620f4240830180931161259757620f42408101809111612597576130ca9260019261420d565b90620f4240830180931161259757620f42408101809111612597576130ca9260009261420d565b600a80546001600160a01b0319166001600160a01b0392831690811790915590613ab1613f59565b167fcb11cc8aade2f5a556749d1b2380d108a16fac3431e6a5d5ce12ef9de0bd76e3600080a36000600d55565b60405163110ac5cb60e21b81526001600160a01b03928316600482018190529395939491939192602090829060249082907f0000000000000000000000000000000000000000000000000000000000000000165afa90811561066357600091613cd4575b506001600160a01b031680151590859082613cc9575b5050613cb857613b706013548380820391110261417d565b613b7982614453565b6001600160a01b0385811695908416938290878603613ca7575b5050508415612ea957600085815260016020526040812054828110613c8d5791613c8082826040958a7ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db98965260016020520385822055826003540360035580897fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60208851878152a3613c518551809263a9059cbb60e01b6020830152602482019050866020898301928d8152015203601f198101835282612ac7565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166146dd565b82519182526020820152a4565b916064928763391434e360e21b8452600452602452604452fd5b613cb092612d4c565b388181613b93565b6399253a5160e01b60005260046000fd5b141590508438613b58565b90506020813d602011613d06575b81613cef60209383612ac7565b8101031261035557613d0090612c5b565b38613b42565b3d9150613ce2565b6001600160701b038111613d28576001600160701b031690565b6306dfcc6560e41b600052607060045260245260446000fd5b613d7990613d4d612c6f565b50613d5c819492600354612b37565b9260018060a01b0316600052600160205282604060002054613a62565b60125492908060005b858110613d97575b50612cf292939450612c4e565b91613dbb613da484612a18565b905460039190911b1c6001600160a01b0316612bce565b808203911102918215613dd057600101613d82565b613d8a565b6001600160881b038111613def576001600160881b031690565b6306dfcc6560e41b600052608860045260245260446000fd5b9091906000906000198482099084810292838084109303928084039314613e8d5782670de0b6b3a76400001115613e7b57507faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106699394670de0b6b3a7640000910990828211900360ee1b910360121c170290565b634e487b71905260116020526024601cfd5b505050670de0b6b3a76400009192500490565b90916000198383099280830292838086109503948086039514613f355784831115613f1c5790829109816000038216809204600281600302188082026002030280820260020302808202600203028082026002030280820260020302809102600203029360018380600003040190848311900302920304170290565b82634e487b71600052156003026011186020526024601cfd5b505080925015613f43570490565b634e487b7160e01b600052601260045260246000fd5b337f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316808214613f8f575090565b60408051630c281d0f60e11b815260006004820152925090829060249082905afa90811561066357600091613fc2575090565b90506040813d604011613ffe575b81613fdd60409383612ac7565b8101031261035557613ffa6020613ff383612c5b565b9201612bc1565b5090565b3d9150613fd0565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633811461403c57503390565b604051633a1a3a1d60e01b8152602081600481855afa9081156106635760009161414b575b5060ff60b81b81161580159061413c575b801561412d575b6140d75760405163110ac5cb60e21b81526001600160a01b039091166004820181905291602090829060249082905afa908115610663576000916140f3575b506001600160a01b0316801515908290826140e8575b50506140d75790565b63ea8e4eb560e01b60005260046000fd5b1415905081386140ce565b90506020813d602011614125575b8161410e60209383612ac7565b810103126103555761411f90612c5b565b386140b8565b3d9150614101565b5060ff60a81b81161515614079565b5060ff60b01b81161515614072565b906020823d602011614175575b8161416560209383612ac7565b81010312610f8257505138614061565b3d9150614158565b60207f15c027cc4fd826d986cad358803439f7326d3aa4ed969ff90dbee4bc150f68e99180601355604051908152a1565b6001600160a01b0316908115612e93577fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6020826141f0600094600354612b37565b6003558484526001825260408420818154019055604051908152a3565b929161421a818386613ea0565b926004811015614257576001809116149182614240575b50506130ca9250151590612b37565b9080925015613f43576130ca930915153880614231565b634e487b7160e01b600052602160045260246000fd5b519065ffffffffffff8216820361035557565b60005b60115481101561443b5761429681612a49565b905460039190911b1c6001600160a01b03166000818152600b602052604090205460701c6001600160881b03168015614431576142d282612b44565b80820391110260405163402d267d60e01b8152306004820152602081602481865afa90811561066357600091614400575b50818110908218021890818410848318028083189203614334575b50508115614330576001905b01614283565b5050565b604051636e553f6560e01b8152600481018390523060248201526020816044816000865af1600091816143cd575b5061436e575b5061431e565b90614398610e626143c495969383600052600b6020526001600160701b0360406000205416612b37565b90600052600b6020526001600160701b03604060002091166001600160701b0319825416179055612c4e565b90388080614368565b90916020823d82116143f8575b816143e760209383612ac7565b81010312610f825750519038614362565b3d91506143da565b906020823d8211614429575b8161441960209383612ac7565b81010312610f8257505138614303565b3d915061440c565b505060019061432a565b5061444257565b63ded0652d60e01b60005260046000fd5b60005b6012548110156145785761446981612a18565b905460039190911b1c6001600160a01b031661448481612bce565b908184108483180280831892036144a6575b5050811561433057600101614456565b604051632d182be560e21b815260048101839052306024820181905260448201526020816064816000865af160009181614545575b506144e7575b50614496565b906001600160701b0361450f61453c95969383600052600b6020528260406000205416612c4e565b1690600052600b6020526001600160701b03604060002091166001600160701b0319825416179055612c4e565b903880806144e1565b90916020823d8211614570575b8161455f60209383612ac7565b81010312610f8257505190386144db565b3d9150614552565b5061457f57565b634323a55560e01b60005260046000fd5b60405163095ea7b360e01b602082019081526001600160a01b0390931660248201526001604480830191909152815260009283929183906145d2606482612ac7565b51926001600160a01b03165af16145e76133d6565b816145f0575090565b805180159250821561460157505090565b81925090602091810103126103555760206130ca9101612bc1565b60405163095ea7b360e01b60208083019182526001600160a01b039094166024830181905260001960448085019190915283529391929190600090614662606486612ac7565b84519082855af16000513d826146b8575b50501561467f57505050565b6132ae61322a936040519063095ea7b360e01b6020830152602482015260006044820152604481526146b2606482612ac7565b826146dd565b9091506146d557506001600160a01b0381163b15155b3880614673565b6001146146ce565b906000602091828151910182855af115610663576000513d61472f57506001600160a01b0381163b155b61470e5750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b6001141561470756fe10dbbfa98a21bc7a80d86cb89391600c590e0e2ce25698013741bcad42956569a264697066735822122092a933310e1697f21f46b6e5cd3f554addde5044b2e713fb09f2f9fd34d8700764736f6c634300081a00334df9dcd34ae35f40f2c756fd8ac83210ed0b76d065543ee73d868aec7c7fcf02d28e9b90ee9b37c5936ff84392d71f29ff18117d7e76bcee60615262a90a3f75000000000000000000000000e5eae3770750dc9e9ea5fb1b1d81a0f9c6c3369c000000000000000000000000d8cecee9a04ea3d941a959f68fb4486f23271d09000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000aca92e438df0b2401ff60da7e4337b687a2435da00000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000008526537206d55534400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000075265376d55534400000000000000000000000000000000000000000000000000
Deployed Bytecode
0x6080604052600436101561001257600080fd5b60003560e01c806301e1d1141461291057806302d05d3f146128cb57806306fdde031461280c57806307a2d13a14611fc2578063095ea7b31461274b5780630a28a477146127225780630e68ec95146126ae57806318160ddd146126905780631ecca77c1461260557806321cb4b14146125e757806323b872dd146125ad578063313ce5671461254f57806333f91ebb1461253157806338d52e0f146124ec5780633a72efdf1461242f578063402d267d146123e057806341b6783314612011578063452a932014611fe85780634690484014611fc75780634cdad50614611fc25780634dedf20e14611f835780634e083eb314611d0a578063568efc0714611cec5780635897a06d14611b7357806362518ddf14611b4a5780636623b57514611b2757806369fe0e2d14611a4f5780636e553f65146119ea57806370a08231146119b0578063715018a6146119495780637224a51214611851578063762c31ba1461181657806379ba5097146117845780637cc4d9a11461174957806381bc23a6146116465780638a2c7b39146116075780638da5cb5b146115de57806394bf804d1461158d57806395d89b4114611489578063987ee783146114105780639d6b4a4514611343578063a17b313014611325578063a5f31d61146112c2578063a70354a11461127d578063a9059cbb14611245578063ac88990c14611166578063b192a84a146110ca578063b3d7f6b914611096578063b460af9414611056578063b65dbf5614611033578063ba08765214610fe0578063be9c580014610ab6578063c522498314610a71578063c63d75b614610a2e578063c6e6f592146103c7578063c9649aa914610992578063ce96cb771461096a578063d33219b41461094c578063d905777e14610918578063dd62ed3e146108c7578063ddca3f43146108a0578063e30c397814610877578063e66f53b71461084e578063e74b981b1461078c578063e90956cf1461071e578063ee7a4b33146103cc578063ef8b30f7146103c7578063f2fde38b1461035a5763f7d185211461031357600080fd5b34610355576020366003190112610355576004356011548110156103555761033c602091612a49565b905460405160039290921b1c6001600160a01b03168152f35b600080fd5b34610355576020366003190112610355576103736129a8565b61037b612fce565b600780546001600160a01b0319166001600160a01b039283169081179091556006549091167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e22700600080a3005b612a9e565b34610355576040366003190112610355576103e56129a8565b6024356103f0612fac565b6103f8614006565b6008546001600160a01b0391821691168114159081610708575b506106f7576040516338d52e0f60e01b81526001600160a01b0383169190602081600481865afa908115610663576000916106bd575b506001600160a01b037f000000000000000000000000aca92e438df0b2401ff60da7e4337b687a2435da81169116036106a85781600052600e6020526001600160401b0360406000205460881c166106975781600052600b6020526001600160401b0360016040600020015416610686576001600160b81b03810361068057506001600160881b03905b80600052600b6020526001600160881b0360406000205460701c1680831461066f5782101561051657509061050961050f92613dd5565b90613415565b6001600055005b6040516367c1def960e01b8152600481018290529092506020816024817f000000000000000000000000377879a039343fec7564e54616e519328951da6d6001600160a01b03165afa90811561066357600091610629575b50156106145781600052600e602052604060002061058b82613dd5565b6001600160881b03600c549116825491816001600160881b031984161784556105bf6001600160401b0360881b9142612b37565b60881b169166ffffffffffffff60c81b16171790557f7bfc48861a5d71fc7afd7b9c92b4feeef1628ab1d5145dede52590c46dd155e9602060018060a01b03610606613f59565b1692604051908152a361050f565b5063320b1e2560e21b60005260045260246000fd5b90506020813d60201161065b575b8161064460209383612ac7565b810103126103555761065590612bc1565b8361056e565b3d9150610637565b6040513d6000823e3d90fd5b63a741a04560e01b60005260046000fd5b906104d2565b6325f600a360e11b60005260046000fd5b6324d9026760e11b60005260046000fd5b50634854a41360e11b60005260045260246000fd5b90506020813d6020116106ef575b816106d860209383612ac7565b81010312610355576106e990612c5b565b84610448565b3d91506106cb565b6332a2673b60e21b60005260046000fd5b6006546001600160a01b03161415905083610412565b34610355576020366003190112610355576107376129a8565b61073f612fce565b6008546001600160a01b03918216918116821461066f576001600160a01b03191681176008557fbd0a63c12948fbc9194a5839019f99c9d71db924e5c70018265bc778b8f1a506600080a2005b34610355576020366003190112610355576107a56129a8565b6107ad612fac565b6107b5612fce565b6010546001600160a01b0382169190606081901c831461066f578215908161083b575b5061082a576107e5613016565b6001600160601b036010549181199060601b169116176010557f2e979f80fe4d43055c584cf4a8467c55875ea36728fc37176c05acd784eb7a73600080a26001600055005b6333fe7c6560e21b60005260046000fd5b6001600160601b039150161515836107d8565b34610355576000366003190112610355576008546040516001600160a01b039091168152602090f35b34610355576000366003190112610355576007546040516001600160a01b039091168152602090f35b346103555760003660031901126103555760206001600160601b0360105416604051908152f35b34610355576040366003190112610355576108e06129a8565b6108e86129be565b6001600160a01b039182166000908152600260209081526040808320949093168252928352819020549051908152f35b3461035557602036600319011261035557602061094461093e6109396129a8565b613d41565b916130cd565b604051908152f35b34610355576000366003190112610355576020600c54604051908152f35b346103555760203660031901126103555760206109886109396129a8565b5050604051908152f35b34610355576000366003190112610355576109ab614006565b6006546001600160a01b0391821691168114159081610a18575b50610a07576000600f556001600160a01b036109df613f59565b167f921828337692c347c634c5d2aacbc7b756014674bd236f3cc2058d8e284a951b600080a2005b637cf97e4d60e11b60005260046000fd5b600a546001600160a01b031614159050816109c5565b3461035557602036600319011261035557610a476129a8565b506020610944610a6b610a58612ebf565b610a60612c6f565b509290600354612b37565b906130cd565b34610355576000366003190112610355576040517f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba36001600160a01b03168152602090f35b34610355576020366003190112610355576004356001600160401b03811161035557366023820112156103555780600401356001600160401b038111610355573660248260061b8401011161035557610b0d612fac565b6001600160a01b03610b1d614006565b1680600052600960205260ff60406000205416159081610fca575b81610fb4575b50610fa357610b4b613f59565b6000908190815b84831015610f85576000908360061b87019160406023198436030112610f8257604051604081018181106001600160401b03821117610f6e5760405260446020610b9e602487016129d4565b9283815201940135845260018060a01b031690818152600b602052604081205460f81c15610f5c57818152600b6020526001600160701b03604082205416906040519463266d6a8360e11b8652826004870152602086602481875afa958615610d1e578296610f29575b5080518087118188030296908715610dc357505081905115610db9575b80610d295750604051632d182be560e21b8152600481018690523060248201819052604482015260208160648185885af1908115610d1e578291610ce8575b509160019593916001600160701b03604081610c85610cdf99978096612c4e565b1692858152600b6020522091166001600160701b03198254161790556040519084825260208201527f416d9fcbb15941508bf9f557a950fb085de673ae90db45a32efdc9b35f29b0f16040878060a01b03891692a3612b37565b925b0191610b52565b90506020813d8211610d16575b81610d0260209383612ac7565b81010312610d1257516001610c64565b5080fd5b3d9150610cf5565b6040513d84823e3d90fd5b604051635d043b2960e11b8152600481018290523060248201819052604482015290955060208160648185885af1908115610d1e578291610d87575b509160019593916001600160701b03604081610c85610cdf9997988096612c4e565b90506020813d8211610db1575b81610da160209383612ac7565b81010312610d1257516001610d65565b3d9150610d94565b5093508381610c25565b9899959890965090506000198103610f1c575083870384881102945b8515610f0e57838252600b602052610e08866001600160881b03604085205460701c1692612b37565b11610efa57604051636e553f6560e01b8152600481018690523060248201529160208360448185885af1928315610d1e578293610ec6575b509160019593916001600160701b036040610e67610e6285610ec09a98612b37565b613d0e565b92858152600b6020522091166001600160701b03198254161790556040519084825260208201527f73e8a9d66522fa5c6fcec2e89aad8e52f6f66eadeb7fc7c172cfcbacb52838516040878060a01b03891692a3612b37565b93610ce1565b9092506020813d8211610ef2575b81610ee160209383612ac7565b81010312610d125751916001610e40565b3d9150610ed4565b63034506ef60e21b81526004839052602490fd5b505050509360019150610ce1565b8580820391110294610ddf565b9095506020813d8211610f54575b81610f4460209383612ac7565b81010312610d125751948b610c08565b3d9150610f37565b602491632215cda760e01b8252600452fd5b634e487b7160e01b83526041600452602483fd5b80fd5b8303610f92576001600055005b6309e36b8960e41b60005260046000fd5b63f7137c0f60e01b60005260046000fd5b6006546001600160a01b03161415905083610b3e565b6008546001600160a01b03168114159150610b38565b34610355576020611026610ff336612a64565b929190610ffe612fac565b611006613016565b6110166003546013549084613a62565b938491611021613f59565b613ade565b6001600055604051908152f35b346103555760203660031901126103555760206109446110516129a8565b612bce565b3461035557602061102661106936612a64565b9291611073612fac565b61107b613016565b61108b60035460135490836130a2565b938492611021613f59565b346103555760203660031901126103555760206109446110c26110b7612c6f565b509190600354612b37565b600435613a3b565b34610355576040366003190112610355576110e36129a8565b60243590811515809203610355576110f9612fce565b6001600160a01b031660008181526009602052604090205490919060ff161515811461066f5760207f74dc60cbc81a9472d04ad1d20e151d369c41104d655ed3f2f3091166a502cd8d918360005260098252604060002060ff1981541660ff8316179055604051908152a2005b346103555760203660031901126103555761117f6129a8565b611187614006565b600a546001600160a01b039182169116811415908161122f575b81611219575b50611208576001600160a01b039081166000818152600b60205260409020600101805467ffffffffffffffff19169055906111e0613f59565b167f8387c3346650400a72032f8bd1aa3f5f44038cf2bf32945e8eeb8a498decea77600080a3005b63d080fa3160e01b60005260046000fd5b6006546001600160a01b031614159050826111a7565b6008546001600160a01b031681141591506111a1565b34610355576040366003190112610355576112726112616129a8565b6024359061126d613f59565b612df7565b602060405160018152f35b34610355576000366003190112610355576040517f000000000000000000000000d8cecee9a04ea3d941a959f68fb4486f23271d096001600160a01b03168152602090f35b3461035557600036600319011261035557600d546001600160401b038160a01c16801561131457421061130357611301906001600160a01b0316613a89565b005b63333bd2cb60e11b60005260046000fd5b63e5f408a560e01b60005260046000fd5b34610355576000366003190112610355576020601154604051908152f35b346103555760203660031901126103555761135c6129a8565b611364612fce565b600a546001600160a01b0382811692911682811461066f576001600160401b03600d5460a01c166106975761139d576113019150613a89565b506113be600c54826001600160601b0360a01b600d541617600d5542612b37565b600d805467ffffffffffffffff60a01b191660a09290921b67ffffffffffffffff60a01b169190911790557f7633313af54753bce8a149927263b1a55eba857ba4ef1d13c6aee25d384d3c4b600080a2005b34610355576020366003190112610355576001600160a01b036114316129a8565b16600052600e60205261148560406000205460405191816001600160881b036001600160401b03859460881c169116839092916001600160401b036020916001600160881b03604085019616845216910152565b0390f35b346103555760003660031901126103555760405160006016548060011c90600181168015611583575b60208310811461156f5782855290811561154b57506001146114eb575b611485836114df81850382612ac7565b60405191829182612936565b91905060166000527fd833147d7dc355ba459fc788f669e58cfaf9dc25ddcd0702e87d69c7b5124289916000905b808210611531575090915081016020016114df6114cf565b919260018160209254838588010152019101909291611519565b60ff191660208086019190915291151560051b840190910191506114df90506114cf565b634e487b7160e01b84526022600452602484fd5b91607f16916114b2565b346103555760403660031901126103555760206004356110266115ae6129be565b916115b7612fac565b6115bf613016565b6115cf6003546013549083613a3b565b80936115d9613f59565b6130f5565b34610355576000366003190112610355576006546040516001600160a01b039091168152602090f35b3461035557600036600319011261035557600f546001600160401b038160881c168015611314574210611303576001600160881b03611301911661338e565b346103555760203660031901126103555761165f6129a8565b6001600160a01b0381166000818152600e602052604090205490919060881c6001600160401b03168015611314574210611303576040516367c1def960e01b8152600481018390526020816024817f000000000000000000000000377879a039343fec7564e54616e519328951da6d6001600160a01b03165afa9081156106635760009161170f575b50156106145761130191600052600e6020526001600160881b036040600020541690613415565b90506020813d602011611741575b8161172a60209383612ac7565b810103126103555761173b90612bc1565b836116e8565b3d915061171d565b3461035557600036600319011261035557600f54604080516001600160881b038316815260889290921c6001600160401b0316602083015290f35b346103555760003660031901126103555761179d613f59565b6007546001600160a01b03918216911681900361180257600780546001600160a01b031990811690915560068054918216831790556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3005b63118cdaa760e01b60005260045260246000fd5b3461035557600036600319011261035557600d54604080516001600160a01b038316815260a09290921c6001600160401b0316602083015290f35b346103555760203660031901126103555760043561186d612fce565b600c5480821461066f576001600160401b03600f5460881c16610697576212750082116119385762015180821061192757808211156118b057506113019061338e565b816020916001600160881b037fb3aa0ade2442acf51d06713c2d1a5a3ec0373cce969d42b53f4689f97bccf3809416600f5491816001600160881b0319841617600f556119086001600160401b0360881b9142612b37565b60881b169166ffffffffffffff60c81b161717600f55604051908152a1005b631a1593df60e11b60005260046000fd5b6346fedb5760e01b60005260046000fd5b3461035557600036600319011261035557611962612fce565b600780546001600160a01b03199081169091556006805491821690556000906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b34610355576020366003190112610355576001600160a01b036119d16129a8565b1660005260016020526020604060002054604051908152f35b3461035557604036600319011261035557600435611a066129be565b90611a0f612fac565b611a17613016565b611a2760035460135490836130cd565b908115611a3e5781611026916020946115d9613f59565b639811e0c760e01b60005260046000fd5b3461035557602036600319011261035557600435611a6b612fac565b611a73612fce565b6010546001600160601b038116821461066f576706f05b59d3b200008211611b16578115159081611b0a575b5061082a576001600160601b0390611ab5613016565b16806001600160601b031960105416176010557f01fe2943baee27f47add82886c2200f910c749c461c9b63c5fe83901a53bdb49602060018060a01b03611afa613f59565b1692604051908152a26001600055005b905060601c1582611a9f565b63f4df6ae560e01b60005260046000fd5b34610355576020366003190112610355576020610944611b456129a8565b612b44565b34610355576020366003190112610355576004356012548110156103555761033c602091612a18565b3461035557602036600319011261035557611b8c6129a8565b611b94614006565b6008546001600160a01b0391821691168114159081611cd6575b506106f7576001600160a01b03166000818152600b60205260409020600101546001600160401b03166106975780600052600b6020526001600160881b0360406000205460701c16611cc55780600052600b60205260406000205460f81c15611cb15780600052600e6020526001600160401b0360406000205460881c16611c9d576001600160401b03611c44600c5442612b37565b1681600052600b6020526001604060002001906001600160401b031982541617905560018060a01b03611c75613f59565b167f354f25f4208ab6528fb2d016019c0e2a66f51376cbb2cc8571064779735d3485600080a3005b634fc6b6fd60e01b60005260045260246000fd5b632215cda760e01b60005260045260246000fd5b63624718b960e11b60005260046000fd5b6006546001600160a01b03161415905082611bae565b34610355576000366003190112610355576020601354604051908152f35b34610355576020366003190112610355576004356001600160401b03811161035557611d3a9036906004016129e8565b6001600160a01b03611d4a614006565b1680600052600960205260ff60406000205416159081611f6d575b81611f57575b50610fa357601e8111611f465760005b818110611ed557506001600160401b038111611ebf57600160401b8111611ebf5760115481601155808210611e79575b5081601160005260005b828110611e3e57506001600160a01b039050611dcf613f59565b1691604051918060208401602085525260408301919060005b818110611e1857857fb07686dd0abe7422b9801e8f38bafd24669a65591071f11120c2f6a7c175813e86860387a2005b909192602080600192838060a01b03611e30886129d4565b168152019401929101611de8565b6001906020611e4c84612b23565b930192817f31ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c68015501611db5565b60116000527f31ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c689081019082015b818110611eb35750611dab565b60008155600101611ea6565b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03611ef0611eeb838587612aff565b612b23565b16600052600b6020526001600160881b0360406000205460701c1615611f1857600101611d7b565b611eeb91611f2593612aff565b63320b1e2560e21b60009081526001600160a01b0391909116600452602490fd5b6340797bd760e11b60005260046000fd5b6006546001600160a01b03161415905083611d6b565b6008546001600160a01b03168114159150611d65565b34610355576020366003190112610355576001600160a01b03611fa46129a8565b166000526009602052602060ff604060002054166040519015158152f35b61297f565b3461035557600036600319011261035557602060105460601c604051908152f35b3461035557600036600319011261035557600a546040516001600160a01b039091168152602090f35b34610355576020366003190112610355576004356001600160401b038111610355576120419036906004016129e8565b906001600160a01b03612052614006565b1680600052600960205260ff604060002054161590816123ca575b816123b4575b50610fa35760125461208481612ae8565b6120916040519182612ac7565b818152601f196120a083612ae8565b013660208301376120b084612ae8565b926120be6040519485612ac7565b8484526120ca85612ae8565b602085019590601f190136873760005b8181106123475750505060005b82811061222f5750505080516001600160401b038111611ebf57600160401b8111611ebf57601254816012558082106121e9575b5082601260005260005b8281106121ac57506001600160a01b0391506121419050613f59565b1691604051916020830190602084525180915260408301919060005b81811061218d57857f834ae37621cd31f2636b1cb6f1bded844d79ecf755af866b5d896da642d7b56786860387a2005b82516001600160a01b031684526020938401939092019160010161215d565b81516001600160a01b03167fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec3444820155602090910190600101612125565b60126000527fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec34449081019082015b818110612223575061211b565b60008155600101612216565b6122398183612b0f565b5115612248575b6001016120e7565b61225181612a18565b905460039190911b1c6001600160a01b03166000818152600b602052604090205460701c6001600160881b03166123335780600052600e6020526001600160401b0360406000205460881c16611c9d576122aa81612b44565b6122c9575b6000908152600b6020526040812081815560010155612240565b80600052600b6020526001600160401b03600160406000200154161561231f5780600052600b6020526001600160401b03600160406000200154164210156122af57634b74115160e01b60005260045260246000fd5b6325dce25160e21b60005260045260246000fd5b6301554f3760e71b60005260045260246000fd5b612352818385612aff565b3561235c81612a18565b905460039190911b1c6001600160a01b0316906123798187612b0f565b5161239f5790600161238d81949388612b0f565b526123988289612b0f565b52016120da565b50633d85a77d60e11b60005260045260246000fd5b6006546001600160a01b03161415905083612073565b6008546001600160a01b0316811415915061206d565b34610355576020366003190112610355576123f96129a8565b50612402612ebf565b6124166124106110b7612c6f565b836130cd565b612427575060206000604051908152f35b602090610944565b34610355576020366003190112610355576124486129a8565b612450614006565b600a546001600160a01b03918216911681141590816124d6575b816124c0575b50611208576001600160a01b039081166000818152600e602052604081205590612498613f59565b167f23edd264f2dcc193d13a29cdab4ac169d60d9b4a0e74f0303c753036d8eb1c13600080a3005b6006546001600160a01b03161415905082612470565b6008546001600160a01b0316811415915061246a565b34610355576000366003190112610355576040517f000000000000000000000000aca92e438df0b2401ff60da7e4337b687a2435da6001600160a01b03168152602090f35b34610355576000366003190112610355576020601254604051908152f35b346103555760003660031901126103555760ff7f00000000000000000000000000000000000000000000000000000000000000061660ff811161259757602090604051908152f35b634e487b7160e01b600052601160045260246000fd5b34610355576060366003190112610355576112726125c96129a8565b6125d16129be565b6044359161126d836125e1613f59565b83612d4c565b34610355576000366003190112610355576020601454604051908152f35b346103555760003660031901126103555761261e614006565b6006546001600160a01b039182169116811415908161267a575b50610a07576000600d556001600160a01b03612652613f59565b167fc40a085ccfa20f5fd518ade5c3a77a7ecbdfbb4c75efcdca6146a8e3c841d663600080a2005b600a546001600160a01b03161415905081612638565b34610355576000366003190112610355576020600354604051908152f35b34610355576020366003190112610355576001600160a01b036126cf6129a8565b16600052600b602052608060406000206001600160401b036001825492015416604051916001600160701b03811683526001600160881b038160701c16602084015260f81c151560408301526060820152f35b346103555760203660031901126103555760206109446127436110b7612c6f565b6004356130a2565b34610355576040366003190112610355576127646129a8565b602435906001600160a01b03612778613f59565b169081156127f6576001600160a01b03169182156127e05760207f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925918360005260028252604060002085600052825280604060002055604051908152a3602060405160018152f35b634a1406b160e11b600052600060045260246000fd5b63e602df0560e01b600052600060045260246000fd5b346103555760003660031901126103555760405160006015548060011c906001811680156128c1575b60208310811461156f5782855290811561154b575060011461286157611485836114df81850382612ac7565b91905060156000527f55f448fdea98c4d29eb340757ef0a66cd03dbb9538908a6a81d96026b71ec475916000905b8082106128a7575090915081016020016114df6114cf565b91926001816020925483858801015201910190929161288f565b91607f1691612835565b34610355576000366003190112610355576040517f000000000000000000000000377879a039343fec7564e54616e519328951da6d6001600160a01b03168152602090f35b3461035557600036600319011261035557602061292b612c6f565b509050604051908152f35b91909160208152825180602083015260005b818110612969575060409293506000838284010152601f8019910116010190565b8060208092870101516040828601015201612948565b346103555760203660031901126103555760206109446129a06110b7612c6f565b600435613a62565b600435906001600160a01b038216820361035557565b602435906001600160a01b038216820361035557565b35906001600160a01b038216820361035557565b9181601f84011215610355578235916001600160401b038311610355576020808501948460051b01011161035557565b601254811015612a3357601260005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b601154811015612a3357601160005260206000200190600090565b606090600319011261035557600435906024356001600160a01b038116810361035557906044356001600160a01b03811681036103555790565b34610355576020366003190112610355576020610944612abf6110b7612c6f565b6004356130cd565b90601f801991011681019081106001600160401b03821117611ebf57604052565b6001600160401b038111611ebf5760051b60200190565b9190811015612a335760051b0190565b8051821015612a335760209160051b010190565b356001600160a01b03811681036103555790565b9190820180921161259757565b60018060a01b031680600052600b60205260206001600160701b036040600020541660246040518094819363266d6a8360e11b835260048301525afa90811561066357600091612b92575090565b90506020813d602011612bb9575b81612bad60209383612ac7565b81010312610355575190565b3d9150612ba0565b5190811515820361035557565b60405163ce96cb7760e01b8152306004820152906020826024816001600160a01b0385165afa91821561066357600092612c18575b50612c0d90612b44565b818110908218021890565b90916020823d602011612c46575b81612c3360209383612ac7565b81010312610f8257505190612c0d612c03565b3d9150612c26565b9190820391821161259757565b51906001600160a01b038216820361035557565b6000906000806012545b808210612d1757505060135491601454612c938185612c4e565b831015612d095750612cb9612cb2612cab8486612c4e565b8094612b37565b9384612c4e565b80151580612cf5575b612cc95750565b612cf2919450612ce5906001600160601b036010541690613e08565b60035461093e8286612c4e565b92565b506001600160601b03601054161515612cc2565b612cb2612cb9918094612b37565b9091612d44600191612d3e612d2b86612a18565b858060a01b0391549060031b1c16612b44565b90612b37565b920190612c79565b6001600160a01b039081166000818152600260209081526040808320948616835293905291909120549291906000198410612d88575b50505050565b828410612dd25780156127f6576001600160a01b038216156127e057600052600260205260406000209060018060a01b031660005260205260406000209103905538808080612d82565b508290637dc7a0d960e11b60005260018060a01b031660045260245260445260646000fd5b6001600160a01b0316908115612ea9576001600160a01b0316918215612e9357600082815260016020526040812054828110612e795791604082827fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9587602096526001865203828220558681526001845220818154019055604051908152a3565b916064928463391434e360e21b8452600452602452604452fd5b63ec442f0560e01b600052600060045260246000fd5b634b637e8f60e11b600052600060045260246000fd5b60009060006011545b808210612ed3575050565b9092612ede84612a49565b905460039190911b1c6001600160a01b03166000818152600b602052604090205460701c6001600160881b03168015612fa1576020602491612f1f84612b44565b808203911102926040519283809263402d267d60e01b82523060048301525afa90811561066357600091612f6e575b50918183612f659360019510908218021890612b37565b935b0190612ec8565b906020823d8211612f99575b81612f8760209383612ac7565b81010312610f82575051612f65612f4e565b3d9150612f7a565b505092600190612f67565b600260005414612fbd576002600055565b633ee5aeb560e01b60005260046000fd5b6006546001600160a01b0390811690612fe5613f59565b1603612fed57565b612ff5613f59565b63118cdaa760e01b60009081526001600160a01b0391909116600452602490fd5b7ff66f28b40975dbb933913542c7e6a0f50a1d0f20aa74ea6e0efe65ab616323ec60407f548669ea9bcc24888e6d74a69c9865fa98d795686853b8aa3eb87814261bbb716020613064612c6f565b613071829593949261417d565b806014558551908152a18061308e575b82519182526020820152a1565b61309d8160105460601c6141ae565b613081565b9091620f4240830180931161259757620f42408101809111612597576130ca9260019261420d565b90565b9091620f4240830180931161259757620f42408101809111612597576130ca9260009261420d565b91929060006001600160a01b037f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba38116907f000000000000000000000000aca92e438df0b2401ff60da7e4337b687a2435da16828781846132cc575b6001600160a01b0316101590816132b8575b501561324057813b1561323c57604051631b63c28b60e11b81526001600160a01b0387811660048301523060248301528816604482015260648101919091529082908290608490829084905af18015610d1e57613225959361322a9795937fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d79360409361322c575b50505b6131f884826141ae565b815186815260208101949094526001600160a01b03908116941692a361321d81614280565b601354612b37565b61417d565b565b8161323691612ac7565b386131eb565b8280fd5b61322a969492507fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7915061322595936132b36040928351906323b872dd60e01b602083015260018060a01b0388166024830152306044830152886064830152606482526132ae608483612ac7565b6146dd565b6131ee565b905065ffffffffffff429116101538613163565b505060405163927da10560e01b81526001600160a01b0388166004820152602481018390523060448201529050606081606481865afa80156133835788908592869161331a575b5091613151565b925050506060813d60601161337b575b8161333760609383612ac7565b810103126133775780516001600160a01b038116810361337357889061336b60406133646020860161426d565b940161426d565b509138613313565b8480fd5b8380fd5b3d915061332a565b6040513d86823e3d90fd5b600c8190557fd28e9b90ee9b37c5936ff84392d71f29ff18117d7e76bcee60615262a90a3f7560206001600160a01b036133c6613f59565b1692604051908152a26000600f55565b3d15613410573d906001600160401b038211611ebf5760405191613404601f8201601f191660200184612ac7565b82523d6000602084013e565b606090565b919091613420613f59565b60009160018060a01b03811691828452600b602052604084208480604051602081019063c522498360e01b82526004815261345c602482612ac7565b5190875afa6134696133d6565b9080613a2f575b15613a275760208180518101031261380357602001516001600160a01b0381169081900361380357965b6001600160881b038116938415613863576001600160a01b037f000000000000000000000000aca92e438df0b2401ff60da7e4337b687a2435da8116908a16806137555750868098999a506134ee9161461c565b825460f81c15613578575b509181600080516020614739833981519152936001602094016001600160401b031981541690555b815470ffffffffffffffffffffffffffffffffff60701b191660709190911b70ffffffffffffffffffffffffffffffffff60701b161790556040519384526001600160a01b031692a38152600e6020526040812055565b909192939450601254600160401b8110156137415780600161359d9201601255612a18565b81546001600160a01b0360039290921b91821b19169088901b179055601254601e106137325782546001600160f81b0316600160f81b1783556040516370a0823160e01b81523060048201526020816024818a5afa9081156137275788916136f3575b506132258796959493926001600160701b0361361e61363a94613d0e565b166001600160701b0319865416178555612d3e60135491612b44565b604051602081019060208152601254809252604081019160128a527fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec3444908a5b8181106136d15750505091602093917f834ae37621cd31f2636b1cb6f1bded844d79ecf755af866b5d896da642d7b56784600080516020614739833981519152979560018060a01b038716930390a2919350916134f9565b82546001600160a01b031685528a995060209094019360019283019201613679565b90506020813d60201161371f575b8161370e60209383612ac7565b81010312610355575161363a613600565b3d9150613701565b6040513d8a823e3d90fd5b6340797bd760e11b8752600487fd5b634e487b7160e01b88526041600452602488fd5b9199604051636eb1769f60e11b8152306004820152836024820152602081604481865afa908115613858578a91613826575b5015613816575b50813b15613812576040516387517c4560e01b81526004810191909152602481018790526001600160a01b03604482015265ffffffffffff60648201529087908290608490829084905af18015613807576137ee575b50849596976134ee565b6137f9878092612ac7565b61380357386137e4565b8580fd5b6040513d89823e3d90fd5b8780fd5b613820908261461c565b3861378e565b90506020813d602011613850575b8161384160209383612ac7565b81010312610355575138613787565b3d9150613834565b6040513d8c823e3d90fd5b5095966001600160a01b037f000000000000000000000000aca92e438df0b2401ff60da7e4337b687a2435da811691168061398f575060405163095ea7b360e01b602082019081526024820187905260448083018990528252969795968796929187918a918291906138d6606482612ac7565b519082865af16138e46133d6565b81613922575b509160008051602061473983398151915295939183602096945015613911575b5050613521565b61391a91614590565b50388761390a565b915050805190811591821561394b575b50879190506000805160206147398339815191526138ea565b8180949596979899506020935001031261381257926020928796959287613982866000805160206147398339815191529801612bc1565b9294965081939550613932565b90813b15613a235786916084839260405194859384926387517c4560e01b845260048401528a60248401528160448401528160648401525af18015613a18576139ef575b5060008051602061473983398151915291602091859697613521565b9160209186613a0e879860008051602061473983398151915296612ac7565b96509150916139d3565b6040513d88823e3d90fd5b8680fd5b50849661349a565b50602081511015613470565b90620f4240830180931161259757620f42408101809111612597576130ca9260019261420d565b90620f4240830180931161259757620f42408101809111612597576130ca9260009261420d565b600a80546001600160a01b0319166001600160a01b0392831690811790915590613ab1613f59565b167fcb11cc8aade2f5a556749d1b2380d108a16fac3431e6a5d5ce12ef9de0bd76e3600080a36000600d55565b60405163110ac5cb60e21b81526001600160a01b03928316600482018190529395939491939192602090829060249082907f000000000000000000000000d8cecee9a04ea3d941a959f68fb4486f23271d09165afa90811561066357600091613cd4575b506001600160a01b031680151590859082613cc9575b5050613cb857613b706013548380820391110261417d565b613b7982614453565b6001600160a01b0385811695908416938290878603613ca7575b5050508415612ea957600085815260016020526040812054828110613c8d5791613c8082826040958a7ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db98965260016020520385822055826003540360035580897fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60208851878152a3613c518551809263a9059cbb60e01b6020830152602482019050866020898301928d8152015203601f198101835282612ac7565b7f000000000000000000000000aca92e438df0b2401ff60da7e4337b687a2435da6001600160a01b03166146dd565b82519182526020820152a4565b916064928763391434e360e21b8452600452602452604452fd5b613cb092612d4c565b388181613b93565b6399253a5160e01b60005260046000fd5b141590508438613b58565b90506020813d602011613d06575b81613cef60209383612ac7565b8101031261035557613d0090612c5b565b38613b42565b3d9150613ce2565b6001600160701b038111613d28576001600160701b031690565b6306dfcc6560e41b600052607060045260245260446000fd5b613d7990613d4d612c6f565b50613d5c819492600354612b37565b9260018060a01b0316600052600160205282604060002054613a62565b60125492908060005b858110613d97575b50612cf292939450612c4e565b91613dbb613da484612a18565b905460039190911b1c6001600160a01b0316612bce565b808203911102918215613dd057600101613d82565b613d8a565b6001600160881b038111613def576001600160881b031690565b6306dfcc6560e41b600052608860045260245260446000fd5b9091906000906000198482099084810292838084109303928084039314613e8d5782670de0b6b3a76400001115613e7b57507faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106699394670de0b6b3a7640000910990828211900360ee1b910360121c170290565b634e487b71905260116020526024601cfd5b505050670de0b6b3a76400009192500490565b90916000198383099280830292838086109503948086039514613f355784831115613f1c5790829109816000038216809204600281600302188082026002030280820260020302808202600203028082026002030280820260020302809102600203029360018380600003040190848311900302920304170290565b82634e487b71600052156003026011186020526024601cfd5b505080925015613f43570490565b634e487b7160e01b600052601260045260246000fd5b337f000000000000000000000000d8cecee9a04ea3d941a959f68fb4486f23271d096001600160a01b0316808214613f8f575090565b60408051630c281d0f60e11b815260006004820152925090829060249082905afa90811561066357600091613fc2575090565b90506040813d604011613ffe575b81613fdd60409383612ac7565b8101031261035557613ffa6020613ff383612c5b565b9201612bc1565b5090565b3d9150613fd0565b7f000000000000000000000000d8cecee9a04ea3d941a959f68fb4486f23271d096001600160a01b031633811461403c57503390565b604051633a1a3a1d60e01b8152602081600481855afa9081156106635760009161414b575b5060ff60b81b81161580159061413c575b801561412d575b6140d75760405163110ac5cb60e21b81526001600160a01b039091166004820181905291602090829060249082905afa908115610663576000916140f3575b506001600160a01b0316801515908290826140e8575b50506140d75790565b63ea8e4eb560e01b60005260046000fd5b1415905081386140ce565b90506020813d602011614125575b8161410e60209383612ac7565b810103126103555761411f90612c5b565b386140b8565b3d9150614101565b5060ff60a81b81161515614079565b5060ff60b01b81161515614072565b906020823d602011614175575b8161416560209383612ac7565b81010312610f8257505138614061565b3d9150614158565b60207f15c027cc4fd826d986cad358803439f7326d3aa4ed969ff90dbee4bc150f68e99180601355604051908152a1565b6001600160a01b0316908115612e93577fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6020826141f0600094600354612b37565b6003558484526001825260408420818154019055604051908152a3565b929161421a818386613ea0565b926004811015614257576001809116149182614240575b50506130ca9250151590612b37565b9080925015613f43576130ca930915153880614231565b634e487b7160e01b600052602160045260246000fd5b519065ffffffffffff8216820361035557565b60005b60115481101561443b5761429681612a49565b905460039190911b1c6001600160a01b03166000818152600b602052604090205460701c6001600160881b03168015614431576142d282612b44565b80820391110260405163402d267d60e01b8152306004820152602081602481865afa90811561066357600091614400575b50818110908218021890818410848318028083189203614334575b50508115614330576001905b01614283565b5050565b604051636e553f6560e01b8152600481018390523060248201526020816044816000865af1600091816143cd575b5061436e575b5061431e565b90614398610e626143c495969383600052600b6020526001600160701b0360406000205416612b37565b90600052600b6020526001600160701b03604060002091166001600160701b0319825416179055612c4e565b90388080614368565b90916020823d82116143f8575b816143e760209383612ac7565b81010312610f825750519038614362565b3d91506143da565b906020823d8211614429575b8161441960209383612ac7565b81010312610f8257505138614303565b3d915061440c565b505060019061432a565b5061444257565b63ded0652d60e01b60005260046000fd5b60005b6012548110156145785761446981612a18565b905460039190911b1c6001600160a01b031661448481612bce565b908184108483180280831892036144a6575b5050811561433057600101614456565b604051632d182be560e21b815260048101839052306024820181905260448201526020816064816000865af160009181614545575b506144e7575b50614496565b906001600160701b0361450f61453c95969383600052600b6020528260406000205416612c4e565b1690600052600b6020526001600160701b03604060002091166001600160701b0319825416179055612c4e565b903880806144e1565b90916020823d8211614570575b8161455f60209383612ac7565b81010312610f8257505190386144db565b3d9150614552565b5061457f57565b634323a55560e01b60005260046000fd5b60405163095ea7b360e01b602082019081526001600160a01b0390931660248201526001604480830191909152815260009283929183906145d2606482612ac7565b51926001600160a01b03165af16145e76133d6565b816145f0575090565b805180159250821561460157505090565b81925090602091810103126103555760206130ca9101612bc1565b60405163095ea7b360e01b60208083019182526001600160a01b039094166024830181905260001960448085019190915283529391929190600090614662606486612ac7565b84519082855af16000513d826146b8575b50501561467f57505050565b6132ae61322a936040519063095ea7b360e01b6020830152602482015260006044820152604481526146b2606482612ac7565b826146dd565b9091506146d557506001600160a01b0381163b15155b3880614673565b6001146146ce565b906000602091828151910182855af115610663576000513d61472f57506001600160a01b0381163b155b61470e5750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b6001141561470756fe10dbbfa98a21bc7a80d86cb89391600c590e0e2ce25698013741bcad42956569a264697066735822122092a933310e1697f21f46b6e5cd3f554addde5044b2e713fb09f2f9fd34d8700764736f6c634300081a0033
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.
Add Token to MetaMask (Web3)