Overview
ETH Balance
ETH Value
$0.00More Info
Private Name Tags
ContractCreator
TokenTracker
Latest 24 from a total of 24 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Redeem | 16391993 | 5 days ago | IN | 0 ETH | 0.00000164 | ||||
| Approve | 16391977 | 5 days ago | IN | 0 ETH | 0.00000139 | ||||
| Deposit | 16383515 | 5 days ago | IN | 0 ETH | 0.00001018 | ||||
| Deposit | 16379645 | 5 days ago | IN | 0 ETH | 0.00000165 | ||||
| Deposit | 16368767 | 5 days ago | IN | 0 ETH | 0.00000168 | ||||
| Redeem | 16368756 | 5 days ago | IN | 0 ETH | 0.00000166 | ||||
| Deposit | 16286641 | 6 days ago | IN | 0 ETH | 0.00000165 | ||||
| Redeem | 16286522 | 6 days ago | IN | 0 ETH | 0.00000163 | ||||
| Deposit | 16286513 | 6 days ago | IN | 0 ETH | 0.00000165 | ||||
| Redeem | 16278196 | 6 days ago | IN | 0 ETH | 0.00001716 | ||||
| Withdraw | 16273245 | 6 days ago | IN | 0 ETH | 0.00000166 | ||||
| Approve | 16273235 | 6 days ago | IN | 0 ETH | 0.00000139 | ||||
| Deposit | 16272716 | 6 days ago | IN | 0 ETH | 0.00000135 | ||||
| Withdraw | 16199704 | 7 days ago | IN | 0 ETH | 0.00000626 | ||||
| Deposit | 16199677 | 7 days ago | IN | 0 ETH | 0.00000163 | ||||
| Withdraw | 16197693 | 7 days ago | IN | 0 ETH | 0.00000164 | ||||
| Deposit | 16197542 | 7 days ago | IN | 0 ETH | 0.00000163 | ||||
| Withdraw | 16170972 | 7 days ago | IN | 0 ETH | 0.00000135 | ||||
| Approve | 16170959 | 7 days ago | IN | 0 ETH | 0.00000135 | ||||
| Deposit | 16170898 | 7 days ago | IN | 0 ETH | 0.00000163 | ||||
| Update Withdraw ... | 11964791 | 56 days ago | IN | 0 ETH | 0.00000144 | ||||
| Redeem | 7228844 | 111 days ago | IN | 0 ETH | 0.00000136 | ||||
| Deposit | 7228443 | 111 days ago | IN | 0 ETH | 0.00000136 | ||||
| Redeem | 6429086 | 120 days ago | IN | 0 ETH | 0.00000042 |
Latest 25 internal transactions (View All)
| Parent Transaction Hash | Block | From | To | ||||
|---|---|---|---|---|---|---|---|
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16848823 | 3 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH | |||||
| 16841615 | 5 hrs ago | 0 ETH |
Cross-Chain Transactions
Contract Source Code Verified (Exact Match)
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.26;
import {
MarketConfig,
PendingUint192,
PendingAddress,
MarketAllocation,
IMetaMorphoV1_1Base,
IMetaMorphoV1_1StaticTyping
} from "./interfaces/IMetaMorphoV1_1.sol";
import {Id, MarketParams, Market, IMorpho} from "../lib/morpho-blue/src/interfaces/IMorpho.sol";
import {PendingUint192, PendingAddress, PendingLib} from "./libraries/PendingLib.sol";
import {ConstantsLib} from "./libraries/ConstantsLib.sol";
import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {EventsLib} from "./libraries/EventsLib.sol";
import {WAD} from "../lib/morpho-blue/src/libraries/MathLib.sol";
import {UtilsLib} from "../lib/morpho-blue/src/libraries/UtilsLib.sol";
import {SafeCast} from "../lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol";
import {SharesMathLib} from "../lib/morpho-blue/src/libraries/SharesMathLib.sol";
import {MorphoLib} from "../lib/morpho-blue/src/libraries/periphery/MorphoLib.sol";
import {MarketParamsLib} from "../lib/morpho-blue/src/libraries/MarketParamsLib.sol";
import {IERC20Metadata} from "../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {MorphoBalancesLib} from "../lib/morpho-blue/src/libraries/periphery/MorphoBalancesLib.sol";
import {Multicall} from "../lib/openzeppelin-contracts/contracts/utils/Multicall.sol";
import {Ownable2Step, Ownable} from "../lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol";
import {ERC20Permit} from "../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC20Permit.sol";
import {
IERC20,
IERC4626,
ERC20,
ERC4626,
Math,
SafeERC20
} from "../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC4626.sol";
/// @title MetaMorpho
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice ERC4626 compliant vault allowing users to deposit assets to Morpho.
contract MetaMorphoV1_1 is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorphoV1_1StaticTyping {
using Math for uint256;
using UtilsLib for uint256;
using SafeCast for uint256;
using SafeERC20 for IERC20;
using MorphoLib for IMorpho;
using SharesMathLib for uint256;
using MorphoBalancesLib for IMorpho;
using MarketParamsLib for MarketParams;
using PendingLib for MarketConfig;
using PendingLib for PendingUint192;
using PendingLib for PendingAddress;
/* IMMUTABLES */
/// @inheritdoc IMetaMorphoV1_1Base
IMorpho public immutable MORPHO;
/// @notice OpenZeppelin decimals offset used by the ERC4626 implementation.
/// @dev Calculated to be max(0, 18 - underlyingDecimals) at construction, so the initial conversion rate maximizes
/// precision between shares and assets.
uint8 public immutable DECIMALS_OFFSET;
/* STORAGE */
/// @inheritdoc IMetaMorphoV1_1Base
address public curator;
/// @inheritdoc IMetaMorphoV1_1Base
mapping(address => bool) public isAllocator;
/// @inheritdoc IMetaMorphoV1_1Base
address public guardian;
/// @inheritdoc IMetaMorphoV1_1StaticTyping
mapping(Id => MarketConfig) public config;
/// @inheritdoc IMetaMorphoV1_1Base
uint256 public timelock;
/// @inheritdoc IMetaMorphoV1_1StaticTyping
PendingAddress public pendingGuardian;
/// @inheritdoc IMetaMorphoV1_1StaticTyping
mapping(Id => PendingUint192) public pendingCap;
/// @inheritdoc IMetaMorphoV1_1StaticTyping
PendingUint192 public pendingTimelock;
/// @inheritdoc IMetaMorphoV1_1Base
uint96 public fee;
/// @inheritdoc IMetaMorphoV1_1Base
address public feeRecipient;
/// @inheritdoc IMetaMorphoV1_1Base
address public skimRecipient;
/// @inheritdoc IMetaMorphoV1_1Base
Id[] public supplyQueue;
/// @inheritdoc IMetaMorphoV1_1Base
Id[] public withdrawQueue;
/// @inheritdoc IMetaMorphoV1_1Base
uint256 public lastTotalAssets;
/// @inheritdoc IMetaMorphoV1_1Base
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 morpho The address of the Morpho contract.
/// @param initialTimelock The initial timelock.
/// @param _asset The address of the underlying asset.
/// @param __name The name of the vault.
/// @param __symbol The symbol of the 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 morpho,
uint256 initialTimelock,
address _asset,
string memory __name,
string memory __symbol
) ERC4626(IERC20(_asset)) ERC20Permit("") ERC20("", "") Ownable(owner) {
if (morpho == address(0)) revert ErrorsLib.ZeroAddress();
if (initialTimelock != 0) _checkTimelockBounds(initialTimelock);
_setTimelock(initialTimelock);
_name = __name;
emit EventsLib.SetName(__name);
_symbol = __symbol;
emit EventsLib.SetSymbol(__symbol);
MORPHO = IMorpho(morpho);
DECIMALS_OFFSET = uint8(uint256(18).zeroFloorSub(IERC20Metadata(_asset).decimals()));
IERC20(_asset).forceApprove(morpho, type(uint256).max);
}
/* MODIFIERS */
/// @dev Reverts if the caller doesn't have the curator role.
modifier onlyCuratorRole() {
address sender = _msgSender();
if (sender != curator && sender != owner()) revert ErrorsLib.NotCuratorRole();
_;
}
/// @dev Reverts if the caller doesn't have the allocator role.
modifier onlyAllocatorRole() {
address sender = _msgSender();
if (!isAllocator[sender] && sender != curator && sender != owner()) {
revert ErrorsLib.NotAllocatorRole();
}
_;
}
/// @dev Reverts if the caller doesn't have the guardian role.
modifier onlyGuardianRole() {
if (_msgSender() != owner() && _msgSender() != guardian) revert ErrorsLib.NotGuardianRole();
_;
}
/// @dev Reverts if the caller doesn't have the curator nor the guardian role.
modifier onlyCuratorOrGuardianRole() {
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 */
function setName(string memory newName) external onlyOwner {
_name = newName;
emit EventsLib.SetName(newName);
}
function setSymbol(string memory newSymbol) external onlyOwner {
_symbol = newSymbol;
emit EventsLib.SetSymbol(newSymbol);
}
/// @inheritdoc IMetaMorphoV1_1Base
function setCurator(address newCurator) external onlyOwner {
if (newCurator == curator) revert ErrorsLib.AlreadySet();
curator = newCurator;
emit EventsLib.SetCurator(newCurator);
}
/// @inheritdoc IMetaMorphoV1_1Base
function setIsAllocator(address newAllocator, bool newIsAllocator) external onlyOwner {
if (isAllocator[newAllocator] == newIsAllocator) revert ErrorsLib.AlreadySet();
isAllocator[newAllocator] = newIsAllocator;
emit EventsLib.SetIsAllocator(newAllocator, newIsAllocator);
}
/// @inheritdoc IMetaMorphoV1_1Base
function setSkimRecipient(address newSkimRecipient) external onlyOwner {
if (newSkimRecipient == skimRecipient) revert ErrorsLib.AlreadySet();
skimRecipient = newSkimRecipient;
emit EventsLib.SetSkimRecipient(newSkimRecipient);
}
/// @inheritdoc IMetaMorphoV1_1Base
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(uint184(newTimelock), timelock);
emit EventsLib.SubmitTimelock(newTimelock);
}
}
/// @inheritdoc IMetaMorphoV1_1Base
function setFee(uint256 newFee) external 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 IMetaMorphoV1_1Base
function setFeeRecipient(address newFeeRecipient) external 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 IMetaMorphoV1_1Base
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 IMetaMorphoV1_1Base
function submitCap(MarketParams memory marketParams, uint256 newSupplyCap) external onlyCuratorRole {
Id id = marketParams.id();
if (marketParams.loanToken != asset()) revert ErrorsLib.InconsistentAsset(id);
if (MORPHO.lastUpdate(id) == 0) revert ErrorsLib.MarketNotCreated();
if (pendingCap[id].validAt != 0) revert ErrorsLib.AlreadyPending();
if (config[id].removableAt != 0) revert ErrorsLib.PendingRemoval();
uint256 supplyCap = config[id].cap;
if (newSupplyCap == supplyCap) revert ErrorsLib.AlreadySet();
if (newSupplyCap < supplyCap) {
_setCap(marketParams, id, newSupplyCap.toUint184());
} else {
pendingCap[id].update(newSupplyCap.toUint184(), timelock);
emit EventsLib.SubmitCap(_msgSender(), id, newSupplyCap);
}
}
/// @inheritdoc IMetaMorphoV1_1Base
function submitMarketRemoval(MarketParams memory marketParams) external onlyCuratorRole {
Id id = marketParams.id();
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 IMetaMorphoV1_1Base
function setSupplyQueue(Id[] 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 IMetaMorphoV1_1Base
function updateWithdrawQueue(uint256[] calldata indexes) external onlyAllocatorRole {
uint256 newLength = indexes.length;
uint256 currLength = withdrawQueue.length;
bool[] memory seen = new bool[](currLength);
Id[] memory newWithdrawQueue = new Id[](newLength);
for (uint256 i; i < newLength; ++i) {
uint256 prevIndex = indexes[i];
// If prevIndex >= currLength, it will revert with native "Index out of bounds".
Id 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]) {
Id id = withdrawQueue[i];
if (config[id].cap != 0) revert ErrorsLib.InvalidMarketRemovalNonZeroCap(id);
if (pendingCap[id].validAt != 0) revert ErrorsLib.PendingCap(id);
if (MORPHO.supplyShares(id, address(this)) != 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 IMetaMorphoV1_1Base
function reallocate(MarketAllocation[] calldata allocations) external onlyAllocatorRole {
uint256 totalSupplied;
uint256 totalWithdrawn;
for (uint256 i; i < allocations.length; ++i) {
MarketAllocation memory allocation = allocations[i];
Id id = allocation.marketParams.id();
if (!config[id].enabled) revert ErrorsLib.MarketNotEnabled(id);
(uint256 supplyAssets, uint256 supplyShares,) = _accruedSupplyBalance(allocation.marketParams, id);
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) =
MORPHO.withdraw(allocation.marketParams, withdrawn, shares, address(this), address(this));
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 market's loan asset is guaranteed to be the vault's asset because it has a non-zero supply cap.
(, uint256 suppliedShares) =
MORPHO.supply(allocation.marketParams, suppliedAssets, 0, address(this), hex"");
emit EventsLib.ReallocateSupply(_msgSender(), id, suppliedAssets, suppliedShares);
totalSupplied += suppliedAssets;
}
}
if (totalWithdrawn != totalSupplied) revert ErrorsLib.InconsistentReallocation();
}
/* REVOKE FUNCTIONS */
/// @inheritdoc IMetaMorphoV1_1Base
function revokePendingTimelock() external onlyGuardianRole {
delete pendingTimelock;
emit EventsLib.RevokePendingTimelock(_msgSender());
}
/// @inheritdoc IMetaMorphoV1_1Base
function revokePendingGuardian() external onlyGuardianRole {
delete pendingGuardian;
emit EventsLib.RevokePendingGuardian(_msgSender());
}
/// @inheritdoc IMetaMorphoV1_1Base
function revokePendingCap(Id id) external onlyCuratorOrGuardianRole {
delete pendingCap[id];
emit EventsLib.RevokePendingCap(_msgSender(), id);
}
/// @inheritdoc IMetaMorphoV1_1Base
function revokePendingMarketRemoval(Id id) external onlyCuratorOrGuardianRole {
delete config[id].removableAt;
emit EventsLib.RevokePendingMarketRemoval(_msgSender(), id);
}
/* EXTERNAL */
/// @inheritdoc IMetaMorphoV1_1Base
function supplyQueueLength() external view returns (uint256) {
return supplyQueue.length;
}
/// @inheritdoc IMetaMorphoV1_1Base
function withdrawQueueLength() external view returns (uint256) {
return withdrawQueue.length;
}
/// @inheritdoc IMetaMorphoV1_1Base
function acceptTimelock() external afterTimelock(pendingTimelock.validAt) {
_setTimelock(pendingTimelock.value);
}
/// @inheritdoc IMetaMorphoV1_1Base
function acceptGuardian() external afterTimelock(pendingGuardian.validAt) {
_setGuardian(pendingGuardian.value);
}
/// @inheritdoc IMetaMorphoV1_1Base
function acceptCap(MarketParams memory marketParams)
external
afterTimelock(pendingCap[marketParams.id()].validAt)
{
Id id = marketParams.id();
// Safe "unchecked" cast because pendingCap <= type(uint184).max.
_setCap(marketParams, id, uint184(pendingCap[id].value));
}
/// @inheritdoc IMetaMorphoV1_1Base
function skim(address token) external {
if (skimRecipient == address(0)) revert ErrorsLib.ZeroAddress();
uint256 amount = IERC20(token).balanceOf(address(this));
IERC20(token).safeTransfer(skimRecipient, amount);
emit EventsLib.Skim(_msgSender(), token, amount);
}
/* ERC4626 (PUBLIC) */
/// @inheritdoc IERC20Metadata
function decimals() public view override(ERC20, ERC4626) returns (uint8) {
return ERC4626.decimals();
}
function name() public view override(IERC20Metadata, ERC20) returns (string memory) {
return _name;
}
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 markets in the supplyQueue.
function maxDeposit(address) public view override returns (uint256) {
return _maxDeposit();
}
/// @inheritdoc IERC4626
/// @dev Warning: May be higher than the actual max mint due to duplicate markets 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 returns (uint256 shares) {
_accrueInterest();
shares = _convertToSharesWithTotals(assets, totalSupply(), lastTotalAssets, Math.Rounding.Floor);
_deposit(_msgSender(), receiver, assets, shares);
}
/// @inheritdoc IERC4626
function mint(uint256 shares, address receiver) public override 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 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 returns (uint256 assets) {
_accrueInterest();
// Do not call expensive `maxRedeem` and optimistically redeem shares.
assets = _convertToAssetsWithTotals(shares, totalSupply(), lastTotalAssets, Math.Rounding.Floor);
_withdraw(_msgSender(), receiver, owner, assets, shares);
}
/// @inheritdoc IERC4626
/// @dev totalAssets is the sum of the vault's assets on the Morpho markets plus the lost assets (see corresponding
/// docs in IMetaMorphoV1_1.sol).
function totalAssets() public view override returns (uint256) {
(, uint256 newTotalAssets,) = _accruedFeeAndAssets();
return newTotalAssets;
}
/* ERC4626 (INTERNAL) */
/// @inheritdoc ERC4626
function _decimalsOffset() internal view override returns (uint8) {
return DECIMALS_OFFSET;
}
/// @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 -= _simulateWithdrawMorpho(assets);
}
/// @dev Returns the maximum amount of assets that the vault can supply on Morpho.
function _maxDeposit() internal view returns (uint256 totalSuppliable) {
for (uint256 i; i < supplyQueue.length; ++i) {
Id id = supplyQueue[i];
uint256 supplyCap = config[id].cap;
if (supplyCap == 0) continue;
uint256 supplyShares = MORPHO.supplyShares(id, address(this));
(uint256 totalSupplyAssets, uint256 totalSupplyShares,,) = MORPHO.expectedMarketBalances(_marketParams(id));
// `supplyAssets` needs to be rounded up for `totalSuppliable` to be rounded down.
uint256 supplyAssets = supplyShares.toAssetsUp(totalSupplyAssets, totalSupplyShares);
totalSuppliable += supplyCap.zeroFloorSub(supplyAssets);
}
}
/// @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 view returns (uint256) {
return assets.mulDiv(newTotalSupply + 10 ** _decimalsOffset(), newTotalAssets + 1, 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 view returns (uint256) {
return shares.mulDiv(newTotalAssets + 1, newTotalSupply + 10 ** _decimalsOffset(), rounding);
}
/// @inheritdoc ERC4626
/// @dev Used in mint or deposit to deposit the underlying asset to Morpho markets.
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal override {
super._deposit(caller, receiver, assets, shares);
_supplyMorpho(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 Morpho markets.
/// @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.
function _withdraw(address caller, address receiver, address owner, uint256 assets, uint256 shares)
internal
override
{
// `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));
_withdrawMorpho(assets);
super._withdraw(caller, receiver, owner, assets, shares);
}
/* INTERNAL */
/// @dev Returns the market params of the market defined by `id`.
function _marketParams(Id id) internal view returns (MarketParams memory) {
return MORPHO.idToMarketParams(id);
}
/// @dev Accrues interest on Morpho Blue and returns the vault's assets & corresponding shares supplied on the
/// market defined by `marketParams`, as well as the market's state.
/// @dev Assumes that the inputs `marketParams` and `id` match.
function _accruedSupplyBalance(MarketParams memory marketParams, Id id)
internal
returns (uint256 assets, uint256 shares, Market memory market)
{
MORPHO.accrueInterest(marketParams);
market = MORPHO.market(id);
shares = MORPHO.supplyShares(id, address(this));
assets = shares.toAssetsDown(market.totalSupplyAssets, market.totalSupplyShares);
}
/// @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 market defined by `id` to `supplyCap`.
/// @dev Assumes that the inputs `marketParams` and `id` match.
function _setCap(MarketParams memory marketParams, Id id, uint184 supplyCap) internal {
MarketConfig storage marketConfig = config[id];
if (supplyCap > 0) {
if (!marketConfig.enabled) {
withdrawQueue.push(id);
if (withdrawQueue.length > ConstantsLib.MAX_QUEUE_LENGTH) revert ErrorsLib.MaxQueueLengthExceeded();
marketConfig.enabled = true;
// Take into account assets of the new market without applying a fee.
_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this)));
emit EventsLib.SetWithdrawQueue(msg.sender, withdrawQueue);
}
marketConfig.removableAt = 0;
}
marketConfig.cap = supplyCap;
emit EventsLib.SetCap(_msgSender(), id, supplyCap);
delete pendingCap[id];
}
/* LIQUIDITY ALLOCATION */
/// @dev Supplies `assets` to Morpho.
function _supplyMorpho(uint256 assets) internal {
for (uint256 i; i < supplyQueue.length; ++i) {
Id id = supplyQueue[i];
uint256 supplyCap = config[id].cap;
if (supplyCap == 0) continue;
MarketParams memory marketParams = _marketParams(id);
MORPHO.accrueInterest(marketParams);
Market memory market = MORPHO.market(id);
uint256 supplyShares = MORPHO.supplyShares(id, address(this));
// `supplyAssets` needs to be rounded up for `toSupply` to be rounded down.
uint256 supplyAssets = supplyShares.toAssetsUp(market.totalSupplyAssets, market.totalSupplyShares);
uint256 toSupply = UtilsLib.min(supplyCap.zeroFloorSub(supplyAssets), assets);
if (toSupply > 0) {
// Using try/catch to skip markets that revert.
try MORPHO.supply(marketParams, toSupply, 0, address(this), hex"") {
assets -= toSupply;
} catch {}
}
if (assets == 0) return;
}
if (assets != 0) revert ErrorsLib.AllCapsReached();
}
/// @dev Withdraws `assets` from Morpho.
function _withdrawMorpho(uint256 assets) internal {
for (uint256 i; i < withdrawQueue.length; ++i) {
Id id = withdrawQueue[i];
MarketParams memory marketParams = _marketParams(id);
(uint256 supplyAssets,, Market memory market) = _accruedSupplyBalance(marketParams, id);
uint256 toWithdraw = UtilsLib.min(
_withdrawable(marketParams, market.totalSupplyAssets, market.totalBorrowAssets, supplyAssets), assets
);
if (toWithdraw > 0) {
// Using try/catch to skip markets that revert.
try MORPHO.withdraw(marketParams, toWithdraw, 0, address(this), address(this)) {
assets -= toWithdraw;
} catch {}
}
if (assets == 0) return;
}
if (assets != 0) revert ErrorsLib.NotEnoughLiquidity();
}
/// @dev Simulates a withdraw of `assets` from Morpho.
/// @return The remaining assets to be withdrawn.
function _simulateWithdrawMorpho(uint256 assets) internal view returns (uint256) {
for (uint256 i; i < withdrawQueue.length; ++i) {
Id id = withdrawQueue[i];
MarketParams memory marketParams = _marketParams(id);
uint256 supplyShares = MORPHO.supplyShares(id, address(this));
(uint256 totalSupplyAssets, uint256 totalSupplyShares, uint256 totalBorrowAssets,) =
MORPHO.expectedMarketBalances(marketParams);
// The vault withdrawing from Morpho cannot fail because:
// 1. oracle.price() is never called (the vault doesn't borrow)
// 2. the amount is capped to the liquidity available on Morpho
// 3. virtually accruing interest didn't fail
assets = assets.zeroFloorSub(
_withdrawable(
marketParams,
totalSupplyAssets,
totalBorrowAssets,
supplyShares.toAssetsDown(totalSupplyAssets, totalSupplyShares)
)
);
if (assets == 0) break;
}
return assets;
}
/// @dev Returns the withdrawable amount of assets from the market defined by `marketParams`, given the market's
/// total supply and borrow assets and the vault's assets supplied.
function _withdrawable(
MarketParams memory marketParams,
uint256 totalSupplyAssets,
uint256 totalBorrowAssets,
uint256 supplyAssets
) internal view returns (uint256) {
// Inside a flashloan callback, liquidity on Morpho Blue may be limited to the singleton's balance.
uint256 availableLiquidity = UtilsLib.min(
totalSupplyAssets - totalBorrowAssets, ERC20(marketParams.loanToken).balanceOf(address(MORPHO))
);
return UtilsLib.min(supplyAssets, availableLiquidity);
}
/* 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 vault has on Morpho.
uint256 realTotalAssets;
for (uint256 i; i < withdrawQueue.length; ++i) {
realTotalAssets += MORPHO.expectedSupplyAssets(_marketParams(withdrawQueue[i]), address(this));
}
// If the vault lost some assets (realTotalAssets decreased), lostAssets is increased.
if (realTotalAssets < lastTotalAssets - lostAssets) newLostAssets = lastTotalAssets - realTotalAssets;
// If it did not, lostAssets stays the same.
else newLostAssets = lostAssets;
newTotalAssets = realTotalAssets + newLostAssets;
uint256 totalInterest = newTotalAssets - lastTotalAssets;
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: MIT
// OpenZeppelin Contracts (last updated v5.0.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 ERC4626 "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 redeemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) external view returns (uint256 assets);
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
struct MarketConfig {
/// @notice The maximum amount of assets that can be allocated to the market.
uint184 cap;
/// @notice Whether the market is in the withdraw queue.
bool enabled;
/// @notice The timestamp at which the market can be instantly removed from the withdraw queue.
uint64 removableAt;
}
struct PendingUint192 {
/// @notice The pending value to set.
uint192 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 Morpho Labs
/// @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(PendingUint192 storage pending, uint184 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: MIT
// OpenZeppelin Contracts (last updated v5.0.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.
*
* 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.
*/
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.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import {IMorpho, Id, MarketParams} from "../../lib/morpho-blue/src/interfaces/IMorpho.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, PendingUint192, PendingAddress} from "../libraries/PendingLib.sol";
struct MarketAllocation {
/// @notice The market to allocate.
MarketParams marketParams;
/// @notice The amount of assets to allocate.
uint256 assets;
}
interface IMulticall {
function multicall(bytes[] calldata) external returns (bytes[] memory);
}
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 IMetaMorphoV1_1StaticTyping and IMetaMorphoV1_1.
/// @dev Consider using the IMetaMorphoV1_1 interface instead of this one.
interface IMetaMorphoV1_1Base {
/// @notice The address of the Morpho contract.
function MORPHO() external view returns (IMorpho);
function DECIMALS_OFFSET() external view returns (uint8);
/// @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 skim recipient.
function skimRecipient() external view returns (address);
/// @notice The current timelock.
function timelock() external view returns (uint256);
/// @dev Stores the order of markets on which liquidity is supplied upon deposit.
/// @dev Can contain any market. A market is skipped as soon as its supply cap is reached.
function supplyQueue(uint256) external view returns (Id);
/// @notice Returns the length of the supply queue.
function supplyQueueLength() external view returns (uint256);
/// @dev Stores the order of markets from which liquidity is withdrawn upon withdrawal.
/// @dev Always contain all non-zero cap markets as well as all markets on which the vault supplies liquidity,
/// without duplicate.
function withdrawQueue(uint256) external view returns (Id);
/// @notice Returns the length of the withdraw queue.
function withdrawQueueLength() 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 market 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 market defined by `marketParams`.
/// @dev Warning: Reverts if a cap is already pending. Revoke the pending cap to overwrite it.
/// @dev Warning: Reverts if a market removal is pending.
/// @dev In case the new cap is lower than the current one, the cap is set immediately.
function submitCap(MarketParams memory marketParams, uint256 newSupplyCap) external;
/// @notice Accepts the pending cap of the market defined by `marketParams`.
function acceptCap(MarketParams memory marketParams) external;
/// @notice Revokes the pending cap of the market defined by `id`.
/// @dev Does not revert if there is no pending cap.
function revokePendingCap(Id id) external;
/// @notice Submits a forced market removal from the vault, eventually losing all funds supplied to the market.
/// @notice Funds can be recovered by enabling this market again and withdrawing from it (using `reallocate`),
/// but funds will be distributed pro-rata to the shares at the time of withdrawal, not at the time of removal.
/// @notice This forced removal is expected to be used as an emergency process in case a market constantly reverts.
/// To softly remove a sane market, the curator role is expected to bundle a reallocation that empties the market
/// first (using `reallocate`), followed by the removal of the market (using `updateWithdrawQueue`).
/// @dev Warning: Removing a market with non-zero supply will instantly impact the vault's price per share.
/// @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(MarketParams memory marketParams) external;
/// @notice Revokes the pending removal of the market defined by `id`.
/// @dev Does not revert if there is no pending market removal.
function revokePendingMarketRemoval(Id id) external;
/// @notice Sets the name of the vault.
function setName(string memory newName) external;
/// @notice Sets the symbol of the vault.
function setSymbol(string memory newSymbol) external;
/// @notice Submits a `newGuardian`.
/// @notice Warning: a malicious guardian could disrupt the vault's operation, and would have the power to revoke
/// any pending guardian.
/// @dev In case there is no guardian, the gardian is set immediately.
/// @dev Warning: Submitting a gardian will overwrite the current pending gardian.
function submitGuardian(address newGuardian) external;
/// @notice Accepts the pending guardian.
function acceptGuardian() external;
/// @notice Revokes the pending guardian.
function revokePendingGuardian() external;
/// @notice Skims the vault `token` balance to `skimRecipient`.
function skim(address) 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 `skimRecipient` to `newSkimRecipient`.
function setSkimRecipient(address newSkimRecipient) external;
/// @notice Sets `supplyQueue` to `newSupplyQueue`.
/// @param newSupplyQueue is an array of enabled markets, and can contain duplicate markets, but it would only
/// increase the cost of depositing to the vault.
function setSupplyQueue(Id[] calldata newSupplyQueue) external;
/// @notice Updates the withdraw queue. Some markets can be removed, but no market can be added.
/// @notice Removing a market requires the vault to have 0 supply on it, or to have previously submitted a removal
/// for this market (with the function `submitMarketRemoval`).
/// @notice Warning: Anyone can supply on behalf of the vault so the call to `updateWithdrawQueue` that expects a
/// market 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 market with a call to `updateWithdrawQueue`.
/// @dev Warning: Removing a market 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 market 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 market.
/// @dev The behavior of the reallocation can be altered by state changes, including:
/// - Deposits on the vault that supplies to markets that are expected to be supplied to during reallocation.
/// - Withdrawals from the vault that withdraws from markets that are expected to be withdrawn from during
/// reallocation.
/// - Donations to the vault on markets that are expected to be supplied to during reallocation.
/// - Withdrawals from markets 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 MetaMorphoV1_1 so that function signatures are checked by the compiler.
/// @dev Consider using the IMetaMorphoV1_1 interface instead of this one.
interface IMetaMorphoV1_1StaticTyping is IMetaMorphoV1_1Base {
/// @notice Returns the current configuration of each market.
function config(Id) external view returns (uint184 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 market.
function pendingCap(Id) external view returns (uint192 value, uint64 validAt);
/// @notice Returns the pending timelock.
function pendingTimelock() external view returns (uint192 value, uint64 validAt);
}
/// @title IMetaMorphoV1_1
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @dev Use this interface for MetaMorphoV1_1 to have access to all the functions with the appropriate function
/// signatures.
interface IMetaMorphoV1_1 is IMetaMorphoV1_1Base, IERC4626, IERC20Permit, IOwnable, IMulticall {
/// @notice Returns the current configuration of each market.
function config(Id) external view returns (MarketConfig memory);
/// @notice Returns the pending guardian.
function pendingGuardian() external view returns (PendingAddress memory);
/// @notice Returns the pending cap for each market.
function pendingCap(Id) external view returns (PendingUint192 memory);
/// @notice Returns the pending timelock.
function pendingTimelock() external view returns (PendingUint192 memory);
}// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; /// @title ErrorsLib /// @author Morpho Labs /// @custom:contact [email protected] /// @notice Library exposing error messages. library ErrorsLib { /// @notice Thrown when the caller is not the owner. string internal constant NOT_OWNER = "not owner"; /// @notice Thrown when the LLTV to enable exceeds the maximum LLTV. string internal constant MAX_LLTV_EXCEEDED = "max LLTV exceeded"; /// @notice Thrown when the fee to set exceeds the maximum fee. string internal constant MAX_FEE_EXCEEDED = "max fee exceeded"; /// @notice Thrown when the value is already set. string internal constant ALREADY_SET = "already set"; /// @notice Thrown when the IRM is not enabled at market creation. string internal constant IRM_NOT_ENABLED = "IRM not enabled"; /// @notice Thrown when the LLTV is not enabled at market creation. string internal constant LLTV_NOT_ENABLED = "LLTV not enabled"; /// @notice Thrown when the market is already created. string internal constant MARKET_ALREADY_CREATED = "market already created"; /// @notice Thrown when a token to transfer doesn't have code. string internal constant NO_CODE = "no code"; /// @notice Thrown when the market is not created. string internal constant MARKET_NOT_CREATED = "market not created"; /// @notice Thrown when not exactly one of the input amount is zero. string internal constant INCONSISTENT_INPUT = "inconsistent input"; /// @notice Thrown when zero assets is passed as input. string internal constant ZERO_ASSETS = "zero assets"; /// @notice Thrown when a zero address is passed as input. string internal constant ZERO_ADDRESS = "zero address"; /// @notice Thrown when the caller is not authorized to conduct an action. string internal constant UNAUTHORIZED = "unauthorized"; /// @notice Thrown when the collateral is insufficient to `borrow` or `withdrawCollateral`. string internal constant INSUFFICIENT_COLLATERAL = "insufficient collateral"; /// @notice Thrown when the liquidity is insufficient to `withdraw` or `borrow`. string internal constant INSUFFICIENT_LIQUIDITY = "insufficient liquidity"; /// @notice Thrown when the position to liquidate is healthy. string internal constant HEALTHY_POSITION = "position is healthy"; /// @notice Thrown when the authorization signature is invalid. string internal constant INVALID_SIGNATURE = "invalid signature"; /// @notice Thrown when the authorization signature is expired. string internal constant SIGNATURE_EXPIRED = "signature expired"; /// @notice Thrown when the nonce is invalid. string internal constant INVALID_NONCE = "invalid nonce"; /// @notice Thrown when a token transfer reverted. string internal constant TRANSFER_REVERTED = "transfer reverted"; /// @notice Thrown when a token transfer returned false. string internal constant TRANSFER_RETURNED_FALSE = "transfer returned false"; /// @notice Thrown when a token transferFrom reverted. string internal constant TRANSFER_FROM_REVERTED = "transferFrom reverted"; /// @notice Thrown when a token transferFrom returned false string internal constant TRANSFER_FROM_RETURNED_FALSE = "transferFrom returned false"; /// @notice Thrown when the maximum uint128 is exceeded. string internal constant MAX_UINT128_EXCEEDED = "max uint128 exceeded"; }
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {ErrorsLib} from "../libraries/ErrorsLib.sol";
/// @title UtilsLib
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Library exposing helpers.
/// @dev Inspired by https://github.com/morpho-org/morpho-utils.
library UtilsLib {
/// @dev Returns true if there is exactly one zero among `x` and `y`.
function exactlyOneZero(uint256 x, uint256 y) internal pure returns (bool z) {
assembly {
z := xor(iszero(x), iszero(y))
}
}
/// @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 `x` safely cast to uint128.
function toUint128(uint256 x) internal pure returns (uint128) {
require(x <= type(uint128).max, ErrorsLib.MAX_UINT128_EXCEEDED);
return uint128(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: GPL-2.0-or-later
pragma solidity >=0.5.0;
type Id is bytes32;
struct MarketParams {
address loanToken;
address collateralToken;
address oracle;
address irm;
uint256 lltv;
}
/// @dev Warning: For `feeRecipient`, `supplyShares` does not contain the accrued shares since the last interest
/// accrual.
struct Position {
uint256 supplyShares;
uint128 borrowShares;
uint128 collateral;
}
/// @dev Warning: `totalSupplyAssets` does not contain the accrued interest since the last interest accrual.
/// @dev Warning: `totalBorrowAssets` does not contain the accrued interest since the last interest accrual.
/// @dev Warning: `totalSupplyShares` does not contain the additional shares accrued by `feeRecipient` since the last
/// interest accrual.
struct Market {
uint128 totalSupplyAssets;
uint128 totalSupplyShares;
uint128 totalBorrowAssets;
uint128 totalBorrowShares;
uint128 lastUpdate;
uint128 fee;
}
struct Authorization {
address authorizer;
address authorized;
bool isAuthorized;
uint256 nonce;
uint256 deadline;
}
struct Signature {
uint8 v;
bytes32 r;
bytes32 s;
}
/// @dev This interface is used for factorizing IMorphoStaticTyping and IMorpho.
/// @dev Consider using the IMorpho interface instead of this one.
interface IMorphoBase {
/// @notice The EIP-712 domain separator.
/// @dev Warning: Every EIP-712 signed message based on this domain separator can be reused on chains sharing the
/// same chain id and on forks because the domain separator would be the same.
function DOMAIN_SEPARATOR() external view returns (bytes32);
/// @notice The owner of the contract.
/// @dev It has the power to change the owner.
/// @dev It has the power to set fees on markets and set the fee recipient.
/// @dev It has the power to enable but not disable IRMs and LLTVs.
function owner() external view returns (address);
/// @notice The fee recipient of all markets.
/// @dev The recipient receives the fees of a given market through a supply position on that market.
function feeRecipient() external view returns (address);
/// @notice Whether the `irm` is enabled.
function isIrmEnabled(address irm) external view returns (bool);
/// @notice Whether the `lltv` is enabled.
function isLltvEnabled(uint256 lltv) external view returns (bool);
/// @notice Whether `authorized` is authorized to modify `authorizer`'s position on all markets.
/// @dev Anyone is authorized to modify their own positions, regardless of this variable.
function isAuthorized(address authorizer, address authorized) external view returns (bool);
/// @notice The `authorizer`'s current nonce. Used to prevent replay attacks with EIP-712 signatures.
function nonce(address authorizer) external view returns (uint256);
/// @notice Sets `newOwner` as `owner` of the contract.
/// @dev Warning: No two-step transfer ownership.
/// @dev Warning: The owner can be set to the zero address.
function setOwner(address newOwner) external;
/// @notice Enables `irm` as a possible IRM for market creation.
/// @dev Warning: It is not possible to disable an IRM.
function enableIrm(address irm) external;
/// @notice Enables `lltv` as a possible LLTV for market creation.
/// @dev Warning: It is not possible to disable a LLTV.
function enableLltv(uint256 lltv) external;
/// @notice Sets the `newFee` for the given market `marketParams`.
/// @param newFee The new fee, scaled by WAD.
/// @dev Warning: The recipient can be the zero address.
function setFee(MarketParams memory marketParams, uint256 newFee) external;
/// @notice Sets `newFeeRecipient` as `feeRecipient` of the fee.
/// @dev Warning: If the fee recipient is set to the zero address, fees will accrue there and will be lost.
/// @dev Modifying the fee recipient will allow the new recipient to claim any pending fees not yet accrued. To
/// ensure that the current recipient receives all due fees, accrue interest manually prior to making any changes.
function setFeeRecipient(address newFeeRecipient) external;
/// @notice Creates the market `marketParams`.
/// @dev Here is the list of assumptions on the market's dependencies (tokens, IRM and oracle) that guarantees
/// Morpho behaves as expected:
/// - The token should be ERC-20 compliant, except that it can omit return values on `transfer` and `transferFrom`.
/// - The token balance of Morpho should only decrease on `transfer` and `transferFrom`. In particular, tokens with
/// burn functions are not supported.
/// - The token should not re-enter Morpho on `transfer` nor `transferFrom`.
/// - The token balance of the sender (resp. receiver) should decrease (resp. increase) by exactly the given amount
/// on `transfer` and `transferFrom`. In particular, tokens with fees on transfer are not supported.
/// - The IRM should not re-enter Morpho.
/// - The oracle should return a price with the correct scaling.
/// @dev Here is a list of properties on the market's dependencies that could break Morpho's liveness properties
/// (funds could get stuck):
/// - The token can revert on `transfer` and `transferFrom` for a reason other than an approval or balance issue.
/// - A very high amount of assets (~1e35) supplied or borrowed can make the computation of `toSharesUp` and
/// `toSharesDown` overflow.
/// - The IRM can revert on `borrowRate`.
/// - A very high borrow rate returned by the IRM can make the computation of `interest` in `_accrueInterest`
/// overflow.
/// - The oracle can revert on `price`. Note that this can be used to prevent `borrow`, `withdrawCollateral` and
/// `liquidate` from being used under certain market conditions.
/// - A very high price returned by the oracle can make the computation of `maxBorrow` in `_isHealthy` overflow, or
/// the computation of `assetsRepaid` in `liquidate` overflow.
/// @dev The borrow share price of a market with less than 1e4 assets borrowed can be decreased by manipulations, to
/// the point where `totalBorrowShares` is very large and borrowing overflows.
function createMarket(MarketParams memory marketParams) external;
/// @notice Supplies `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's
/// `onMorphoSupply` function with the given `data`.
/// @dev Either `assets` or `shares` should be zero. Most use cases should rely on `assets` as an input so the
/// caller is guaranteed to have `assets` tokens pulled from their balance, but the possibility to mint a specific
/// amount of shares is given for full compatibility and precision.
/// @dev Supplying a large amount can revert for overflow.
/// @dev Supplying an amount of shares may lead to supply more or fewer assets than expected due to slippage.
/// Consider using the `assets` parameter to avoid this.
/// @param marketParams The market to supply assets to.
/// @param assets The amount of assets to supply.
/// @param shares The amount of shares to mint.
/// @param onBehalf The address that will own the increased supply position.
/// @param data Arbitrary data to pass to the `onMorphoSupply` callback. Pass empty data if not needed.
/// @return assetsSupplied The amount of assets supplied.
/// @return sharesSupplied The amount of shares minted.
function supply(
MarketParams memory marketParams,
uint256 assets,
uint256 shares,
address onBehalf,
bytes memory data
) external returns (uint256 assetsSupplied, uint256 sharesSupplied);
/// @notice Withdraws `assets` or `shares` on behalf of `onBehalf` and sends the assets to `receiver`.
/// @dev Either `assets` or `shares` should be zero. To withdraw max, pass the `shares`'s balance of `onBehalf`.
/// @dev `msg.sender` must be authorized to manage `onBehalf`'s positions.
/// @dev Withdrawing an amount corresponding to more shares than supplied will revert for underflow.
/// @dev It is advised to use the `shares` input when withdrawing the full position to avoid reverts due to
/// conversion roundings between shares and assets.
/// @param marketParams The market to withdraw assets from.
/// @param assets The amount of assets to withdraw.
/// @param shares The amount of shares to burn.
/// @param onBehalf The address of the owner of the supply position.
/// @param receiver The address that will receive the withdrawn assets.
/// @return assetsWithdrawn The amount of assets withdrawn.
/// @return sharesWithdrawn The amount of shares burned.
function withdraw(
MarketParams memory marketParams,
uint256 assets,
uint256 shares,
address onBehalf,
address receiver
) external returns (uint256 assetsWithdrawn, uint256 sharesWithdrawn);
/// @notice Borrows `assets` or `shares` on behalf of `onBehalf` and sends the assets to `receiver`.
/// @dev Either `assets` or `shares` should be zero. Most use cases should rely on `assets` as an input so the
/// caller is guaranteed to borrow `assets` of tokens, but the possibility to mint a specific amount of shares is
/// given for full compatibility and precision.
/// @dev `msg.sender` must be authorized to manage `onBehalf`'s positions.
/// @dev Borrowing a large amount can revert for overflow.
/// @dev Borrowing an amount of shares may lead to borrow fewer assets than expected due to slippage.
/// Consider using the `assets` parameter to avoid this.
/// @param marketParams The market to borrow assets from.
/// @param assets The amount of assets to borrow.
/// @param shares The amount of shares to mint.
/// @param onBehalf The address that will own the increased borrow position.
/// @param receiver The address that will receive the borrowed assets.
/// @return assetsBorrowed The amount of assets borrowed.
/// @return sharesBorrowed The amount of shares minted.
function borrow(
MarketParams memory marketParams,
uint256 assets,
uint256 shares,
address onBehalf,
address receiver
) external returns (uint256 assetsBorrowed, uint256 sharesBorrowed);
/// @notice Repays `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's
/// `onMorphoRepay` function with the given `data`.
/// @dev Either `assets` or `shares` should be zero. To repay max, pass the `shares`'s balance of `onBehalf`.
/// @dev Repaying an amount corresponding to more shares than borrowed will revert for underflow.
/// @dev It is advised to use the `shares` input when repaying the full position to avoid reverts due to conversion
/// roundings between shares and assets.
/// @dev An attacker can front-run a repay with a small repay making the transaction revert for underflow.
/// @param marketParams The market to repay assets to.
/// @param assets The amount of assets to repay.
/// @param shares The amount of shares to burn.
/// @param onBehalf The address of the owner of the debt position.
/// @param data Arbitrary data to pass to the `onMorphoRepay` callback. Pass empty data if not needed.
/// @return assetsRepaid The amount of assets repaid.
/// @return sharesRepaid The amount of shares burned.
function repay(
MarketParams memory marketParams,
uint256 assets,
uint256 shares,
address onBehalf,
bytes memory data
) external returns (uint256 assetsRepaid, uint256 sharesRepaid);
/// @notice Supplies `assets` of collateral on behalf of `onBehalf`, optionally calling back the caller's
/// `onMorphoSupplyCollateral` function with the given `data`.
/// @dev Interest are not accrued since it's not required and it saves gas.
/// @dev Supplying a large amount can revert for overflow.
/// @param marketParams The market to supply collateral to.
/// @param assets The amount of collateral to supply.
/// @param onBehalf The address that will own the increased collateral position.
/// @param data Arbitrary data to pass to the `onMorphoSupplyCollateral` callback. Pass empty data if not needed.
function supplyCollateral(MarketParams memory marketParams, uint256 assets, address onBehalf, bytes memory data)
external;
/// @notice Withdraws `assets` of collateral on behalf of `onBehalf` and sends the assets to `receiver`.
/// @dev `msg.sender` must be authorized to manage `onBehalf`'s positions.
/// @dev Withdrawing an amount corresponding to more collateral than supplied will revert for underflow.
/// @param marketParams The market to withdraw collateral from.
/// @param assets The amount of collateral to withdraw.
/// @param onBehalf The address of the owner of the collateral position.
/// @param receiver The address that will receive the collateral assets.
function withdrawCollateral(MarketParams memory marketParams, uint256 assets, address onBehalf, address receiver)
external;
/// @notice Liquidates the given `repaidShares` of debt asset or seize the given `seizedAssets` of collateral on the
/// given market `marketParams` of the given `borrower`'s position, optionally calling back the caller's
/// `onMorphoLiquidate` function with the given `data`.
/// @dev Either `seizedAssets` or `repaidShares` should be zero.
/// @dev Seizing more than the collateral balance will underflow and revert without any error message.
/// @dev Repaying more than the borrow balance will underflow and revert without any error message.
/// @dev An attacker can front-run a liquidation with a small repay making the transaction revert for underflow.
/// @param marketParams The market of the position.
/// @param borrower The owner of the position.
/// @param seizedAssets The amount of collateral to seize.
/// @param repaidShares The amount of shares to repay.
/// @param data Arbitrary data to pass to the `onMorphoLiquidate` callback. Pass empty data if not needed.
/// @return The amount of assets seized.
/// @return The amount of assets repaid.
function liquidate(
MarketParams memory marketParams,
address borrower,
uint256 seizedAssets,
uint256 repaidShares,
bytes memory data
) external returns (uint256, uint256);
/// @notice Executes a flash loan.
/// @dev Flash loans have access to the whole balance of the contract (the liquidity and deposited collateral of all
/// markets combined, plus donations).
/// @dev Warning: Not ERC-3156 compliant but compatibility is easily reached:
/// - `flashFee` is zero.
/// - `maxFlashLoan` is the token's balance of this contract.
/// - The receiver of `assets` is the caller.
/// @param token The token to flash loan.
/// @param assets The amount of assets to flash loan.
/// @param data Arbitrary data to pass to the `onMorphoFlashLoan` callback.
function flashLoan(address token, uint256 assets, bytes calldata data) external;
/// @notice Sets the authorization for `authorized` to manage `msg.sender`'s positions.
/// @param authorized The authorized address.
/// @param newIsAuthorized The new authorization status.
function setAuthorization(address authorized, bool newIsAuthorized) external;
/// @notice Sets the authorization for `authorization.authorized` to manage `authorization.authorizer`'s positions.
/// @dev Warning: Reverts if the signature has already been submitted.
/// @dev The signature is malleable, but it has no impact on the security here.
/// @dev The nonce is passed as argument to be able to revert with a different error message.
/// @param authorization The `Authorization` struct.
/// @param signature The signature.
function setAuthorizationWithSig(Authorization calldata authorization, Signature calldata signature) external;
/// @notice Accrues interest for the given market `marketParams`.
function accrueInterest(MarketParams memory marketParams) external;
/// @notice Returns the data stored on the different `slots`.
function extSloads(bytes32[] memory slots) external view returns (bytes32[] memory);
}
/// @dev This interface is inherited by Morpho so that function signatures are checked by the compiler.
/// @dev Consider using the IMorpho interface instead of this one.
interface IMorphoStaticTyping is IMorphoBase {
/// @notice The state of the position of `user` on the market corresponding to `id`.
/// @dev Warning: For `feeRecipient`, `supplyShares` does not contain the accrued shares since the last interest
/// accrual.
function position(Id id, address user)
external
view
returns (uint256 supplyShares, uint128 borrowShares, uint128 collateral);
/// @notice The state of the market corresponding to `id`.
/// @dev Warning: `totalSupplyAssets` does not contain the accrued interest since the last interest accrual.
/// @dev Warning: `totalBorrowAssets` does not contain the accrued interest since the last interest accrual.
/// @dev Warning: `totalSupplyShares` does not contain the accrued shares by `feeRecipient` since the last interest
/// accrual.
function market(Id id)
external
view
returns (
uint128 totalSupplyAssets,
uint128 totalSupplyShares,
uint128 totalBorrowAssets,
uint128 totalBorrowShares,
uint128 lastUpdate,
uint128 fee
);
/// @notice The market params corresponding to `id`.
/// @dev This mapping is not used in Morpho. It is there to enable reducing the cost associated to calldata on layer
/// 2s by creating a wrapper contract with functions that take `id` as input instead of `marketParams`.
function idToMarketParams(Id id)
external
view
returns (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv);
}
/// @title IMorpho
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @dev Use this interface for Morpho to have access to all the functions with the appropriate function signatures.
interface IMorpho is IMorphoBase {
/// @notice The state of the position of `user` on the market corresponding to `id`.
/// @dev Warning: For `feeRecipient`, `p.supplyShares` does not contain the accrued shares since the last interest
/// accrual.
function position(Id id, address user) external view returns (Position memory p);
/// @notice The state of the market corresponding to `id`.
/// @dev Warning: `m.totalSupplyAssets` does not contain the accrued interest since the last interest accrual.
/// @dev Warning: `m.totalBorrowAssets` does not contain the accrued interest since the last interest accrual.
/// @dev Warning: `m.totalSupplyShares` does not contain the accrued shares by `feeRecipient` since the last
/// interest accrual.
function market(Id id) external view returns (Market memory m);
/// @notice The market params corresponding to `id`.
/// @dev This mapping is not used in Morpho. It is there to enable reducing the cost associated to calldata on layer
/// 2s by creating a wrapper contract with functions that take `id` as input instead of `marketParams`.
function idToMarketParams(Id id) external view returns (MarketParams memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import {MarketParams, Market} from "./IMorpho.sol";
/// @title IIrm
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Interface that Interest Rate Models (IRMs) used by Morpho must implement.
interface IIrm {
/// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams`.
/// @dev Assumes that `market` corresponds to `marketParams`.
function borrowRate(MarketParams memory marketParams, Market memory market) external returns (uint256);
/// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams` without modifying any
/// storage.
/// @dev Assumes that `market` corresponds to `marketParams`.
function borrowRateView(MarketParams memory marketParams, Market memory market) external view returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Permit.sol)
pragma solidity ^0.8.20;
import {IERC20Permit} from "./IERC20Permit.sol";
import {ERC20} from "../ERC20.sol";
import {ECDSA} from "../../../utils/cryptography/ECDSA.sol";
import {EIP712} from "../../../utils/cryptography/EIP712.sol";
import {Nonces} from "../../../utils/Nonces.sol";
/**
* @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712, Nonces {
bytes32 private constant PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
/**
* @dev Permit deadline has expired.
*/
error ERC2612ExpiredSignature(uint256 deadline);
/**
* @dev Mismatched signature.
*/
error ERC2612InvalidSigner(address signer, address owner);
/**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
*
* It's a good idea to use the same `name` that is defined as the ERC20 token name.
*/
constructor(string memory name) EIP712(name, "1") {}
/**
* @inheritdoc IERC20Permit
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
if (block.timestamp > deadline) {
revert ERC2612ExpiredSignature(deadline);
}
bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
if (signer != owner) {
revert ERC2612InvalidSigner(signer, owner);
}
_approve(owner, spender, value);
}
/**
* @inheritdoc IERC20Permit
*/
function nonces(address owner) public view virtual override(IERC20Permit, Nonces) returns (uint256) {
return super.nonces(owner);
}
/**
* @inheritdoc IERC20Permit
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view virtual returns (bytes32) {
return _domainSeparatorV4();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.20;
import {MessageHashUtils} from "./MessageHashUtils.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {IERC5267} from "../../interfaces/IERC5267.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
* encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract
* does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to
* produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
* separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
* separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
*
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
abstract contract EIP712 is IERC5267 {
using ShortStrings for *;
bytes32 private constant TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _cachedDomainSeparator;
uint256 private immutable _cachedChainId;
address private immutable _cachedThis;
bytes32 private immutable _hashedName;
bytes32 private immutable _hashedVersion;
ShortString private immutable _name;
ShortString private immutable _version;
string private _nameFallback;
string private _versionFallback;
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
_name = name.toShortStringWithFallback(_nameFallback);
_version = version.toShortStringWithFallback(_versionFallback);
_hashedName = keccak256(bytes(name));
_hashedVersion = keccak256(bytes(version));
_cachedChainId = block.chainid;
_cachedDomainSeparator = _buildDomainSeparator();
_cachedThis = address(this);
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
return _cachedDomainSeparator;
} else {
return _buildDomainSeparator();
}
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
}
/**
* @dev See {IERC-5267}.
*/
function eip712Domain()
public
view
virtual
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)
{
return (
hex"0f", // 01111
_EIP712Name(),
_EIP712Version(),
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}
/**
* @dev The name parameter for the EIP712 domain.
*
* NOTE: By default this function reads _name which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Name() internal view returns (string memory) {
return _name.toStringWithFallback(_nameFallback);
}
/**
* @dev The version parameter for the EIP712 domain.
*
* NOTE: By default this function reads _version which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Version() internal view returns (string memory) {
return _version.toStringWithFallback(_versionFallback);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Nonces.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides tracking nonces for addresses. Nonces will only increment.
*/
abstract contract Nonces {
/**
* @dev The nonce used for an `account` is not the expected current nonce.
*/
error InvalidAccountNonce(address account, uint256 currentNonce);
mapping(address account => uint256) private _nonces;
/**
* @dev Returns the next unused nonce for an address.
*/
function nonces(address owner) public view virtual returns (uint256) {
return _nonces[owner];
}
/**
* @dev Consumes a nonce.
*
* Returns the current value and increments nonce.
*/
function _useNonce(address owner) internal virtual returns (uint256) {
// For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be
// decremented or reset. This guarantees that the nonce never overflows.
unchecked {
// It is important to do x++ and not ++x here.
return _nonces[owner]++;
}
}
/**
* @dev Same as {_useNonce} but checking that `nonce` is the next valid for `owner`.
*/
function _useCheckedNonce(address owner, uint256 nonce) internal virtual {
uint256 current = _useNonce(owner);
if (nonce != current) {
revert InvalidAccountNonce(owner, current);
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; uint256 constant WAD = 1e18; /// @title MathLib /// @author Morpho Labs /// @custom:contact [email protected] /// @notice Library to manage fixed-point arithmetic. library MathLib { /// @dev Returns (`x` * `y`) / `WAD` rounded down. function wMulDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, y, WAD); } /// @dev Returns (`x` * `WAD`) / `y` rounded down. function wDivDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, WAD, y); } /// @dev Returns (`x` * `WAD`) / `y` rounded up. function wDivUp(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivUp(x, WAD, y); } /// @dev Returns (`x` * `y`) / `d` rounded down. function mulDivDown(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) { return (x * y) / d; } /// @dev Returns (`x` * `y`) / `d` rounded up. function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) { return (x * y + (d - 1)) / d; } /// @dev Returns the sum of the first three non-zero terms of a Taylor expansion of e^(nx) - 1, to approximate a /// continuous compound interest rate. function wTaylorCompounded(uint256 x, uint256 n) internal pure returns (uint256) { uint256 firstTerm = x * n; uint256 secondTerm = mulDivDown(firstTerm, firstTerm, 2 * WAD); uint256 thirdTerm = mulDivDown(secondTerm, firstTerm, 3 * WAD); return firstTerm + secondTerm + thirdTerm; } }
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
* ```
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {Id} from "../../interfaces/IMorpho.sol";
/// @title MorphoStorageLib
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Helper library exposing getters to access Morpho storage variables' slot.
/// @dev This library is not used in Morpho itself and is intended to be used by integrators.
library MorphoStorageLib {
/* SLOTS */
uint256 internal constant OWNER_SLOT = 0;
uint256 internal constant FEE_RECIPIENT_SLOT = 1;
uint256 internal constant POSITION_SLOT = 2;
uint256 internal constant MARKET_SLOT = 3;
uint256 internal constant IS_IRM_ENABLED_SLOT = 4;
uint256 internal constant IS_LLTV_ENABLED_SLOT = 5;
uint256 internal constant IS_AUTHORIZED_SLOT = 6;
uint256 internal constant NONCE_SLOT = 7;
uint256 internal constant ID_TO_MARKET_PARAMS_SLOT = 8;
/* SLOT OFFSETS */
uint256 internal constant LOAN_TOKEN_OFFSET = 0;
uint256 internal constant COLLATERAL_TOKEN_OFFSET = 1;
uint256 internal constant ORACLE_OFFSET = 2;
uint256 internal constant IRM_OFFSET = 3;
uint256 internal constant LLTV_OFFSET = 4;
uint256 internal constant SUPPLY_SHARES_OFFSET = 0;
uint256 internal constant BORROW_SHARES_AND_COLLATERAL_OFFSET = 1;
uint256 internal constant TOTAL_SUPPLY_ASSETS_AND_SHARES_OFFSET = 0;
uint256 internal constant TOTAL_BORROW_ASSETS_AND_SHARES_OFFSET = 1;
uint256 internal constant LAST_UPDATE_AND_FEE_OFFSET = 2;
/* GETTERS */
function ownerSlot() internal pure returns (bytes32) {
return bytes32(OWNER_SLOT);
}
function feeRecipientSlot() internal pure returns (bytes32) {
return bytes32(FEE_RECIPIENT_SLOT);
}
function positionSupplySharesSlot(Id id, address user) internal pure returns (bytes32) {
return bytes32(
uint256(keccak256(abi.encode(user, keccak256(abi.encode(id, POSITION_SLOT))))) + SUPPLY_SHARES_OFFSET
);
}
function positionBorrowSharesAndCollateralSlot(Id id, address user) internal pure returns (bytes32) {
return bytes32(
uint256(keccak256(abi.encode(user, keccak256(abi.encode(id, POSITION_SLOT)))))
+ BORROW_SHARES_AND_COLLATERAL_OFFSET
);
}
function marketTotalSupplyAssetsAndSharesSlot(Id id) internal pure returns (bytes32) {
return bytes32(uint256(keccak256(abi.encode(id, MARKET_SLOT))) + TOTAL_SUPPLY_ASSETS_AND_SHARES_OFFSET);
}
function marketTotalBorrowAssetsAndSharesSlot(Id id) internal pure returns (bytes32) {
return bytes32(uint256(keccak256(abi.encode(id, MARKET_SLOT))) + TOTAL_BORROW_ASSETS_AND_SHARES_OFFSET);
}
function marketLastUpdateAndFeeSlot(Id id) internal pure returns (bytes32) {
return bytes32(uint256(keccak256(abi.encode(id, MARKET_SLOT))) + LAST_UPDATE_AND_FEE_OFFSET);
}
function isIrmEnabledSlot(address irm) internal pure returns (bytes32) {
return keccak256(abi.encode(irm, IS_IRM_ENABLED_SLOT));
}
function isLltvEnabledSlot(uint256 lltv) internal pure returns (bytes32) {
return keccak256(abi.encode(lltv, IS_LLTV_ENABLED_SLOT));
}
function isAuthorizedSlot(address authorizer, address authorizee) internal pure returns (bytes32) {
return keccak256(abi.encode(authorizee, keccak256(abi.encode(authorizer, IS_AUTHORIZED_SLOT))));
}
function nonceSlot(address authorizer) internal pure returns (bytes32) {
return keccak256(abi.encode(authorizer, NONCE_SLOT));
}
function idToLoanTokenSlot(Id id) internal pure returns (bytes32) {
return bytes32(uint256(keccak256(abi.encode(id, ID_TO_MARKET_PARAMS_SLOT))) + LOAN_TOKEN_OFFSET);
}
function idToCollateralTokenSlot(Id id) internal pure returns (bytes32) {
return bytes32(uint256(keccak256(abi.encode(id, ID_TO_MARKET_PARAMS_SLOT))) + COLLATERAL_TOKEN_OFFSET);
}
function idToOracleSlot(Id id) internal pure returns (bytes32) {
return bytes32(uint256(keccak256(abi.encode(id, ID_TO_MARKET_PARAMS_SLOT))) + ORACLE_OFFSET);
}
function idToIrmSlot(Id id) internal pure returns (bytes32) {
return bytes32(uint256(keccak256(abi.encode(id, ID_TO_MARKET_PARAMS_SLOT))) + IRM_OFFSET);
}
function idToLltvSlot(Id id) internal pure returns (bytes32) {
return bytes32(uint256(keccak256(abi.encode(id, ID_TO_MARKET_PARAMS_SLOT))) + LLTV_OFFSET);
}
}// 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.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.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 ERC4626 "Tokenized Vault Standard" as defined in
* https://eips.ethereum.org/EIPS/eip-4626[EIP-4626].
*
* This extension allows the minting and burning of "shares" (represented using the ERC20 inheritance) in exchange for
* underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
* the ERC20 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 uses virtual assets and shares to 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, as a result of the value being captured by the virtual shares (out of the attacker's
* donation) matching the attacker's expected gains. With a larger offset, the attack becomes orders of magnitude more
* expensive than it is profitable. More details about the underlying math can be found
* xref:erc4626.adoc#inflation-attack[here].
*
* The drawback of this approach is that the virtual shares do capture (a very small) part of the value being accrued
* to the vault. Also, if the vault experiences losses, the users try to exit the vault, the virtual shares and assets
* will cause the first user to exit to experience reduced losses in detriment to the last users that will experience
* bigger losses. Developers willing to revert back to the pre-v4.9 behavior just need to override the
* `_convertToShares` and `_convertToAssets` functions.
*
* To learn more, check out our xref:ROOT:erc4626.adoc[ERC-4626 guide].
* ====
*/
abstract contract 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 (ERC20 or ERC777).
*/
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, uint8) {
(bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
abi.encodeCall(IERC20Metadata.decimals, ())
);
if (success && encodedDecimals.length >= 32) {
uint256 returnedDecimals = abi.decode(encodedDecimals, (uint256));
if (returnedDecimals <= type(uint8).max) {
return (true, uint8(returnedDecimals));
}
}
return (false, 0);
}
/**
* @dev Decimals are computed by adding the decimal offset on top of the underlying asset's decimals. This
* "original" value is cached during construction of the vault contract. If this read operation fails (e.g., the
* asset has not been created yet), a default of 18 is used to represent the underlying asset's decimals.
*
* See {IERC20Metadata-decimals}.
*/
function decimals() public view virtual override(IERC20Metadata, 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 _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}.
*
* As opposed to {deposit}, minting is allowed even if the vault is in a state where the price of a share is zero.
* In this case, the shares will be minted without requiring any assets to be deposited.
*/
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 ERC777, `transferFrom` can trigger a reentrancy BEFORE the transfer happens through the
// `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
// calls the vault, which is assumed not malicious.
//
// Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
// assets are transferred and before the shares are minted, which is a valid state.
// slither-disable-next-line reentrancy-no-eth
SafeERC20.safeTransferFrom(_asset, caller, address(this), assets);
_mint(receiver, shares);
emit Deposit(caller, receiver, assets, shares);
}
/**
* @dev Withdraw/redeem common workflow.
*/
function _withdraw(
address caller,
address receiver,
address owner,
uint256 assets,
uint256 shares
) internal virtual {
if (caller != owner) {
_spendAllowance(owner, caller, shares);
}
// If _asset is ERC777, `transfer` can trigger a reentrancy AFTER the transfer happens through the
// `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
// calls the vault, which is assumed not malicious.
//
// Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
// shares are burned and after the assets are transferred, which is a valid state.
_burn(owner, shares);
SafeERC20.safeTransfer(_asset, receiver, assets);
emit Withdraw(caller, receiver, owner, assets, shares);
}
function _decimalsOffset() internal view virtual returns (uint8) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds 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.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 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 prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// ? `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// ? `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @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 + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @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 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 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 + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (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;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ShortStrings.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
// | length | 0x BB |
type ShortString is bytes32;
/**
* @dev This library provides functions to convert short memory strings
* into a `ShortString` type that can be used as an immutable variable.
*
* Strings of arbitrary length can be optimized using this library if
* they are short enough (up to 31 bytes) by packing them with their
* length (1 byte) in a single EVM word (32 bytes). Additionally, a
* fallback mechanism can be used for every other case.
*
* Usage example:
*
* ```solidity
* contract Named {
* using ShortStrings for *;
*
* ShortString private immutable _name;
* string private _nameFallback;
*
* constructor(string memory contractName) {
* _name = contractName.toShortStringWithFallback(_nameFallback);
* }
*
* function name() external view returns (string memory) {
* return _name.toStringWithFallback(_nameFallback);
* }
* }
* ```
*/
library ShortStrings {
// Used as an identifier for strings longer than 31 bytes.
bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
error StringTooLong(string str);
error InvalidShortString();
/**
* @dev Encode a string of at most 31 chars into a `ShortString`.
*
* This will trigger a `StringTooLong` error is the input string is too long.
*/
function toShortString(string memory str) internal pure returns (ShortString) {
bytes memory bstr = bytes(str);
if (bstr.length > 31) {
revert StringTooLong(str);
}
return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
}
/**
* @dev Decode a `ShortString` back to a "normal" string.
*/
function toString(ShortString sstr) internal pure returns (string memory) {
uint256 len = byteLength(sstr);
// using `new string(len)` would work locally but is not memory safe.
string memory str = new string(32);
/// @solidity memory-safe-assembly
assembly {
mstore(str, len)
mstore(add(str, 0x20), sstr)
}
return str;
}
/**
* @dev Return the length of a `ShortString`.
*/
function byteLength(ShortString sstr) internal pure returns (uint256) {
uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
if (result > 31) {
revert InvalidShortString();
}
return result;
}
/**
* @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
*/
function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
if (bytes(value).length < 32) {
return toShortString(value);
} else {
StorageSlot.getStringSlot(store).value = value;
return ShortString.wrap(FALLBACK_SENTINEL);
}
}
/**
* @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*/
function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return toString(value);
} else {
return store;
}
}
/**
* @dev Return the length of a string that was encoded to `ShortString` or written to storage using
* {setWithFallback}.
*
* WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
* actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
*/
function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return byteLength(value);
} else {
return bytes(store).length;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError, bytes32) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ? {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {Id} from "../../lib/morpho-blue/src/interfaces/IMorpho.sol";
import {PendingAddress} from "./PendingLib.sol";
/// @title EventsLib
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Library exposing events.
library EventsLib {
/// @notice Emitted when the name of the vault is set.
event SetName(string name);
/// @notice Emitted when the symbol of the 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 when `skimRecipient` is set to `newSkimRecipient`.
event SetSkimRecipient(address indexed newSkimRecipient);
/// @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 market identified by `id`.
event SubmitCap(address indexed caller, Id indexed id, uint256 cap);
/// @notice Emitted when a new `cap` is set for market identified by `id`.
event SetCap(address indexed caller, Id 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 market identified by `id` is submitted for removal.
event SubmitMarketRemoval(address indexed caller, Id 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 market identified by `id` is revoked.
event RevokePendingCap(address indexed caller, Id indexed id);
/// @notice Emitted when a `pendingGuardian` is revoked.
event RevokePendingGuardian(address indexed caller);
/// @notice Emitted when a pending market removal is revoked.
event RevokePendingMarketRemoval(address indexed caller, Id indexed id);
/// @notice Emitted when the `supplyQueue` is set to `newSupplyQueue`.
event SetSupplyQueue(address indexed caller, Id[] newSupplyQueue);
/// @notice Emitted when the `withdrawQueue` is set to `newWithdrawQueue`.
event SetWithdrawQueue(address indexed caller, Id[] newWithdrawQueue);
/// @notice Emitted when a reallocation supplies assets to the market identified by `id`.
/// @param id The id of the market.
/// @param suppliedAssets The amount of assets supplied to the market.
/// @param suppliedShares The amount of shares minted.
event ReallocateSupply(address indexed caller, Id indexed id, uint256 suppliedAssets, uint256 suppliedShares);
/// @notice Emitted when a reallocation withdraws assets from the market identified by `id`.
/// @param id The id of the market.
/// @param withdrawnAssets The amount of assets withdrawn from the market.
/// @param withdrawnShares The amount of shares burned.
event ReallocateWithdraw(address indexed caller, Id 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 an `amount` of `token` is transferred to the skim recipient by `caller`.
event Skim(address indexed caller, address indexed token, uint256 amount);
/// @notice Emitted when a new MetaMorphoV1_1 vault is created.
/// @param metaMorpho The address of the MetaMorphoV1_1 vault.
/// @param caller The caller of the function.
/// @param initialOwner The initial owner of the MetaMorphoV1_1 vault.
/// @param initialTimelock The initial timelock of the MetaMorphoV1_1 vault.
/// @param asset The address of the underlying asset.
/// @param name The name of the MetaMorphoV1_1 vault.
/// @param symbol The symbol of the MetaMorphoV1_1 vault.
/// @param salt The salt used for the MetaMorphoV1_1 vault's CREATE2 address.
event CreateMetaMorpho(
address indexed metaMorpho,
address indexed caller,
address initialOwner,
uint256 initialTimelock,
address indexed asset,
string name,
string symbol,
bytes32 salt
);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {Id, MarketParams} from "../interfaces/IMorpho.sol";
/// @title MarketParamsLib
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Library to convert a market to its id.
library MarketParamsLib {
/// @notice The length of the data used to compute the id of a market.
/// @dev The length is 5 * 32 because `MarketParams` has 5 variables of 32 bytes each.
uint256 internal constant MARKET_PARAMS_BYTES_LENGTH = 5 * 32;
/// @notice Returns the id of the market `marketParams`.
function id(MarketParams memory marketParams) internal pure returns (Id marketParamsId) {
assembly ("memory-safe") {
marketParamsId := keccak256(marketParams, MARKET_PARAMS_BYTES_LENGTH)
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {Id} from "../../lib/morpho-blue/src/interfaces/IMorpho.sol";
/// @title ErrorsLib
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Library exposing error messages.
library ErrorsLib {
/// @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 market `id` cannot be set in the supply queue.
error UnauthorizedMarket(Id id);
/// @notice Thrown when submitting a cap for a market `id` whose loan token does not correspond to the underlying.
/// asset.
error InconsistentAsset(Id id);
/// @notice Thrown when the supply cap has been exceeded on market `id` during a reallocation of funds.
error SupplyCapExceeded(Id 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 market when there is a cap already pending on that market.
error PendingCap(Id id);
/// @notice Thrown when submitting a cap for a market with a pending removal.
error PendingRemoval();
/// @notice Thrown when submitting a market removal for a market with a non zero cap.
error NonZeroCap();
/// @notice Thrown when market `id` is a duplicate in the new withdraw queue to set.
error DuplicateMarket(Id id);
/// @notice Thrown when market `id` is missing in the updated withdraw queue and the market has a non-zero cap set.
error InvalidMarketRemovalNonZeroCap(Id id);
/// @notice Thrown when market `id` is missing in the updated withdraw queue and the market has a non-zero supply.
error InvalidMarketRemovalNonZeroSupply(Id id);
/// @notice Thrown when market `id` is missing in the updated withdraw queue and the market is not yet disabled.
error InvalidMarketRemovalTimelockNotElapsed(Id id);
/// @notice Thrown when there's no pending value to set.
error NoPendingValue();
/// @notice Thrown when the requested liquidity cannot be withdrawn from Morpho.
error NotEnoughLiquidity();
/// @notice Thrown when submitting a cap for a market which does not exist.
error MarketNotCreated();
/// @notice Thrown when interacting with a non previously enabled market `id`.
error MarketNotEnabled(Id 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 markets 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();
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)
pragma solidity ^0.8.20;
interface IERC5267 {
/**
* @dev MAY be emitted to signal that the domain could have changed.
*/
event EIP712DomainChanged();
/**
* @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
* signature.
*/
function eip712Domain()
external
view
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Multicall.sol)
pragma solidity ^0.8.20;
import {Address} from "./Address.sol";
/**
* @dev Provides a function to batch together multiple calls in a single external call.
*/
abstract contract Multicall {
/**
* @dev Receives and executes a batch of function calls on this contract.
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function multicall(bytes[] calldata data) external virtual returns (bytes[] memory results) {
results = new bytes[](data.length);
for (uint256 i = 0; i < data.length; i++) {
results[i] = Address.functionDelegateCall(address(this), data[i]);
}
return results;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {Id, MarketParams, Market, IMorpho} from "../../interfaces/IMorpho.sol";
import {IIrm} from "../../interfaces/IIrm.sol";
import {MathLib} from "../MathLib.sol";
import {UtilsLib} from "../UtilsLib.sol";
import {MorphoLib} from "./MorphoLib.sol";
import {SharesMathLib} from "../SharesMathLib.sol";
import {MarketParamsLib} from "../MarketParamsLib.sol";
/// @title MorphoBalancesLib
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Helper library exposing getters with the expected value after interest accrual.
/// @dev This library is not used in Morpho itself and is intended to be used by integrators.
/// @dev The getter to retrieve the expected total borrow shares is not exposed because interest accrual does not apply
/// to it. The value can be queried directly on Morpho using `totalBorrowShares`.
library MorphoBalancesLib {
using MathLib for uint256;
using MathLib for uint128;
using UtilsLib for uint256;
using MorphoLib for IMorpho;
using SharesMathLib for uint256;
using MarketParamsLib for MarketParams;
/// @notice Returns the expected market balances of a market after having accrued interest.
/// @return The expected total supply assets.
/// @return The expected total supply shares.
/// @return The expected total borrow assets.
/// @return The expected total borrow shares.
function expectedMarketBalances(IMorpho morpho, MarketParams memory marketParams)
internal
view
returns (uint256, uint256, uint256, uint256)
{
Id id = marketParams.id();
Market memory market = morpho.market(id);
uint256 elapsed = block.timestamp - market.lastUpdate;
// Skipped if elapsed == 0 or totalBorrowAssets == 0 because interest would be null, or if irm == address(0).
if (elapsed != 0 && market.totalBorrowAssets != 0 && marketParams.irm != address(0)) {
uint256 borrowRate = IIrm(marketParams.irm).borrowRateView(marketParams, market);
uint256 interest = market.totalBorrowAssets.wMulDown(borrowRate.wTaylorCompounded(elapsed));
market.totalBorrowAssets += interest.toUint128();
market.totalSupplyAssets += interest.toUint128();
if (market.fee != 0) {
uint256 feeAmount = interest.wMulDown(market.fee);
// The fee amount is subtracted from the total supply in this calculation to compensate for the fact
// that total supply is already updated.
uint256 feeShares =
feeAmount.toSharesDown(market.totalSupplyAssets - feeAmount, market.totalSupplyShares);
market.totalSupplyShares += feeShares.toUint128();
}
}
return (market.totalSupplyAssets, market.totalSupplyShares, market.totalBorrowAssets, market.totalBorrowShares);
}
/// @notice Returns the expected total supply assets of a market after having accrued interest.
function expectedTotalSupplyAssets(IMorpho morpho, MarketParams memory marketParams)
internal
view
returns (uint256 totalSupplyAssets)
{
(totalSupplyAssets,,,) = expectedMarketBalances(morpho, marketParams);
}
/// @notice Returns the expected total borrow assets of a market after having accrued interest.
function expectedTotalBorrowAssets(IMorpho morpho, MarketParams memory marketParams)
internal
view
returns (uint256 totalBorrowAssets)
{
(,, totalBorrowAssets,) = expectedMarketBalances(morpho, marketParams);
}
/// @notice Returns the expected total supply shares of a market after having accrued interest.
function expectedTotalSupplyShares(IMorpho morpho, MarketParams memory marketParams)
internal
view
returns (uint256 totalSupplyShares)
{
(, totalSupplyShares,,) = expectedMarketBalances(morpho, marketParams);
}
/// @notice Returns the expected supply assets balance of `user` on a market after having accrued interest.
/// @dev Warning: Wrong for `feeRecipient` because their supply shares increase is not taken into account.
/// @dev Warning: Withdrawing using the expected supply assets can lead to a revert due to conversion roundings from
/// assets to shares.
function expectedSupplyAssets(IMorpho morpho, MarketParams memory marketParams, address user)
internal
view
returns (uint256)
{
Id id = marketParams.id();
uint256 supplyShares = morpho.supplyShares(id, user);
(uint256 totalSupplyAssets, uint256 totalSupplyShares,,) = expectedMarketBalances(morpho, marketParams);
return supplyShares.toAssetsDown(totalSupplyAssets, totalSupplyShares);
}
/// @notice Returns the expected borrow assets balance of `user` on a market after having accrued interest.
/// @dev Warning: The expected balance is rounded up, so it may be greater than the market's expected total borrow
/// assets.
function expectedBorrowAssets(IMorpho morpho, MarketParams memory marketParams, address user)
internal
view
returns (uint256)
{
Id id = marketParams.id();
uint256 borrowShares = morpho.borrowShares(id, user);
(,, uint256 totalBorrowAssets, uint256 totalBorrowShares) = expectedMarketBalances(morpho, marketParams);
return borrowShares.toAssetsUp(totalBorrowAssets, totalBorrowShares);
}
}// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; /// @title ConstantsLib /// @author Morpho Labs /// @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 markets 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; }
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {MathLib} from "./MathLib.sol";
/// @title SharesMathLib
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Shares management library.
/// @dev This implementation mitigates share price manipulations, using OpenZeppelin's method of virtual shares:
/// https://docs.openzeppelin.com/contracts/4.x/erc4626#inflation-attack.
library SharesMathLib {
using MathLib for uint256;
/// @dev The number of virtual shares has been chosen low enough to prevent overflows, and high enough to ensure
/// high precision computations.
/// @dev Virtual shares can never be redeemed for the assets they are entitled to, but it is assumed the share price
/// stays low enough not to inflate these assets to a significant value.
/// @dev Warning: The assets to which virtual borrow shares are entitled behave like unrealizable bad debt.
uint256 internal constant VIRTUAL_SHARES = 1e6;
/// @dev A number of virtual assets of 1 enforces a conversion rate between shares and assets when a market is
/// empty.
uint256 internal constant VIRTUAL_ASSETS = 1;
/// @dev Calculates the value of `assets` quoted in shares, rounding down.
function toSharesDown(uint256 assets, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) {
return assets.mulDivDown(totalShares + VIRTUAL_SHARES, totalAssets + VIRTUAL_ASSETS);
}
/// @dev Calculates the value of `shares` quoted in assets, rounding down.
function toAssetsDown(uint256 shares, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) {
return shares.mulDivDown(totalAssets + VIRTUAL_ASSETS, totalShares + VIRTUAL_SHARES);
}
/// @dev Calculates the value of `assets` quoted in shares, rounding up.
function toSharesUp(uint256 assets, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) {
return assets.mulDivUp(totalShares + VIRTUAL_SHARES, totalAssets + VIRTUAL_ASSETS);
}
/// @dev Calculates the value of `shares` quoted in assets, rounding up.
function toAssetsUp(uint256 shares, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) {
return shares.mulDivUp(totalAssets + VIRTUAL_ASSETS, totalShares + VIRTUAL_SHARES);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)
pragma solidity ^0.8.20;
import {Strings} from "../Strings.sol";
/**
* @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
*
* The library provides methods for generating a hash of a message that conforms to the
* https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
* specifications.
*/
library MessageHashUtils {
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing a bytes32 `messageHash` with
* `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
* keccak256, although any bytes32 value can be safely used because the final digest will
* be re-hashed.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
}
}
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing an arbitrary `message` with
* `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
return
keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
}
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x00` (data with intended validator).
*
* The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
* `validator` address. Then hashing the result.
*
* See {ECDSA-recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(hex"19_00", validator, data));
}
/**
* @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
*
* The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
* `\x19\x01` and hashing the result. It corresponds to the hash signed by the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
*
* See {ECDSA-recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, hex"19_01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
digest := keccak256(ptr, 0x42)
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {IMorpho, Id} from "../../interfaces/IMorpho.sol";
import {MorphoStorageLib} from "./MorphoStorageLib.sol";
/// @title MorphoLib
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Helper library to access Morpho storage variables.
/// @dev Warning: Supply and borrow getters may return outdated values that do not include accrued interest.
library MorphoLib {
function supplyShares(IMorpho morpho, Id id, address user) internal view returns (uint256) {
bytes32[] memory slot = _array(MorphoStorageLib.positionSupplySharesSlot(id, user));
return uint256(morpho.extSloads(slot)[0]);
}
function borrowShares(IMorpho morpho, Id id, address user) internal view returns (uint256) {
bytes32[] memory slot = _array(MorphoStorageLib.positionBorrowSharesAndCollateralSlot(id, user));
return uint128(uint256(morpho.extSloads(slot)[0]));
}
function collateral(IMorpho morpho, Id id, address user) internal view returns (uint256) {
bytes32[] memory slot = _array(MorphoStorageLib.positionBorrowSharesAndCollateralSlot(id, user));
return uint256(morpho.extSloads(slot)[0] >> 128);
}
function totalSupplyAssets(IMorpho morpho, Id id) internal view returns (uint256) {
bytes32[] memory slot = _array(MorphoStorageLib.marketTotalSupplyAssetsAndSharesSlot(id));
return uint128(uint256(morpho.extSloads(slot)[0]));
}
function totalSupplyShares(IMorpho morpho, Id id) internal view returns (uint256) {
bytes32[] memory slot = _array(MorphoStorageLib.marketTotalSupplyAssetsAndSharesSlot(id));
return uint256(morpho.extSloads(slot)[0] >> 128);
}
function totalBorrowAssets(IMorpho morpho, Id id) internal view returns (uint256) {
bytes32[] memory slot = _array(MorphoStorageLib.marketTotalBorrowAssetsAndSharesSlot(id));
return uint128(uint256(morpho.extSloads(slot)[0]));
}
function totalBorrowShares(IMorpho morpho, Id id) internal view returns (uint256) {
bytes32[] memory slot = _array(MorphoStorageLib.marketTotalBorrowAssetsAndSharesSlot(id));
return uint256(morpho.extSloads(slot)[0] >> 128);
}
function lastUpdate(IMorpho morpho, Id id) internal view returns (uint256) {
bytes32[] memory slot = _array(MorphoStorageLib.marketLastUpdateAndFeeSlot(id));
return uint128(uint256(morpho.extSloads(slot)[0]));
}
function fee(IMorpho morpho, Id id) internal view returns (uint256) {
bytes32[] memory slot = _array(MorphoStorageLib.marketLastUpdateAndFeeSlot(id));
return uint256(morpho.extSloads(slot)[0] >> 128);
}
function _array(bytes32 x) private pure returns (bytes32[] memory) {
bytes32[] memory res = new bytes32[](1);
res[0] = x;
return res;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}{
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"appendCBOR": true,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": [
"solmate/=lib/bundler3/lib/permit2/lib/solmate/",
"@openzeppelin/contracts/=lib/metamorpho-1.1/lib/openzeppelin-contracts/contracts/",
"bundler3/=lib/bundler3/",
"ds-test/=lib/metamorpho-1.1/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/metamorpho-1.1/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/bundler3/lib/permit2/lib/forge-gas-snapshot/src/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/morpho-blue/lib/halmos-cheatcodes/src/",
"metamorpho-1.1/=lib/metamorpho-1.1/",
"metamorpho/=lib/public-allocator/lib/metamorpho/",
"morpho-blue-irm/=lib/morpho-blue-irm/src/",
"morpho-blue-oracles/=lib/morpho-blue-oracles/src/",
"morpho-blue/=lib/morpho-blue/",
"murky/=lib/universal-rewards-distributor/lib/murky/src/",
"openzeppelin-contracts/=lib/metamorpho-1.1/lib/openzeppelin-contracts/",
"openzeppelin/=lib/universal-rewards-distributor/lib/openzeppelin-contracts/contracts/",
"permit2/=lib/bundler3/lib/permit2/",
"pre-liquidation/=lib/pre-liquidation/src/",
"public-allocator/=lib/public-allocator/src/",
"safe-smart-account/=lib/safe-smart-account/",
"universal-rewards-distributor/=lib/universal-rewards-distributor/"
],
"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":"morpho","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":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"AllCapsReached","type":"error"},{"inputs":[],"name":"AlreadyPending","type":"error"},{"inputs":[],"name":"AlreadySet","type":"error"},{"inputs":[],"name":"BelowMinTimelock","type":"error"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"DuplicateMarket","type":"error"},{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","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":"uint256","name":"deadline","type":"uint256"}],"name":"ERC2612ExpiredSignature","type":"error"},{"inputs":[{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"ERC2612InvalidSigner","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":"FailedInnerCall","type":"error"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"InconsistentAsset","type":"error"},{"inputs":[],"name":"InconsistentReallocation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"currentNonce","type":"uint256"}],"name":"InvalidAccountNonce","type":"error"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"InvalidMarketRemovalNonZeroCap","type":"error"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"InvalidMarketRemovalNonZeroSupply","type":"error"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"InvalidMarketRemovalTimelockNotElapsed","type":"error"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[],"name":"MarketNotCreated","type":"error"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"MarketNotEnabled","type":"error"},{"inputs":[],"name":"MathOverflowedMulDiv","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":"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":"Id","name":"id","type":"bytes32"}],"name":"PendingCap","type":"error"},{"inputs":[],"name":"PendingRemoval","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":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"SupplyCapExceeded","type":"error"},{"inputs":[],"name":"TimelockNotElapsed","type":"error"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"UnauthorizedMarket","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"inputs":[],"name":"ZeroFeeRecipient","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":[],"name":"EIP712DomainChanged","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":"Id","name":"id","type":"bytes32"},{"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":"Id","name":"id","type":"bytes32"},{"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":"Id","name":"id","type":"bytes32"}],"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":"Id","name":"id","type":"bytes32"}],"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":"Id","name":"id","type":"bytes32"},{"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":"newSkimRecipient","type":"address"}],"name":"SetSkimRecipient","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"Id[]","name":"newSupplyQueue","type":"bytes32[]"}],"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":"Id[]","name":"newWithdrawQueue","type":"bytes32[]"}],"name":"SetWithdrawQueue","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Skim","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"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":"Id","name":"id","type":"bytes32"}],"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":"DECIMALS_OFFSET","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MORPHO","outputs":[{"internalType":"contract IMorpho","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"}],"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":"Id","name":"","type":"bytes32"}],"name":"config","outputs":[{"internalType":"uint184","name":"cap","type":"uint184"},{"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":"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":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","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":"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":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"","type":"bytes32"}],"name":"pendingCap","outputs":[{"internalType":"uint192","name":"value","type":"uint192"},{"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":"uint192","name":"value","type":"uint192"},{"internalType":"uint64","name":"validAt","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"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":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"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":"Id","name":"id","type":"bytes32"}],"name":"revokePendingCap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revokePendingGuardian","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"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":"string","name":"newName","type":"string"}],"name":"setName","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newSkimRecipient","type":"address"}],"name":"setSkimRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id[]","name":"newSupplyQueue","type":"bytes32[]"}],"name":"setSupplyQueue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"newSymbol","type":"string"}],"name":"setSymbol","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"skim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"skimRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"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":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"}],"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":"Id","name":"","type":"bytes32"}],"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":"Id","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawQueueLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]Contract Creation Code
6101e0806040523461065157615c28803803809161001d8285610a31565b8339810160c0828203126106515761003482610a54565b9061004160208401610a54565b9160408401519161005460608601610a54565b60808601519095906001600160401b0381116106515782610076918301610a83565b60a08201519092906001600160401b038111610651576100969201610a83565b90602094604051966100a88789610a31565b5f885260018060a01b0316936040516100c18882610a31565b5f8152604051986100d2898b610a31565b5f8a526040998a51926100e58c85610a31565b60018452603160f81b8b8501528051906001600160401b03821161075a5760035490600182811c92168015610a27575b8d83101461073c578c82601f8594116109d5575b50508c90601f831160011461096e575f92610963575b50508160011b915f199060031b1c1916176003555b8051906001600160401b03821161075a5760045490600182811c92168015610959575b8c83101461073c5781601f84931161090a575b508b90601f83116001146108a3575f92610898575b50508160011b915f199060031b1c1916176004555b6101bd87610dc2565b9015610890575b60a052866080526101d481610af3565b610160526101e182610c5b565b6101805288815191012090816101205288815191012080610140524660e052895190898201927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f84528b83015260608201524660808201523060a082015260a0815261024e60c082610a31565b51902060c05230610100526001600160a01b031690811561087d57600980546001600160a01b03199081169091556008805491821684179055885192906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a36001600160a01b031694851561086e578061083b575b80600e5581527fd28e9b90ee9b37c5936ff84392d71f29ff18117d7e76bcee60615262a90a3f75863392a25f60115580516001600160401b03811161075a57601854600181811c91168015610831575b8782101461073c57601f81116107ed575b5085601f8211600114610779579181610377925f80516020615c08833981519152945f9161076e575b508160011b915f199060031b1c1916176018555b875191829182610ac9565b0390a180516001600160401b03811161075a57601954600181811c91168015610750575b8682101461073c57601f81116106f8575b5084601f8211600114610671579181610407927fadf3ae8bd543b3007d464f15cb8ea1db3f44e84d41d203164f40b95e27558ac6945f91610666575b508160011b915f199060031b1c1916176019555b865191829182610ac9565b0390a16101a0829052835163313ce56760e01b81528381600481855afa90811561065c575f91610620575b5060ff809116806012039060121102166101c0528351915f8085850163095ea7b360e01b81528360248701528119604487015260448652610474606487610a31565b85519082865af1610483610d93565b816105f0575b50806105e6575b156105a1575b8451614ce99081610f1f82396080518181816122bc01528181612552015281816139200152613d3b015260a05181612618015260c05181613298015260e0518161335501526101005181613262015261012051816132e70152610140518161330d015261016051816113230152610180518161134c01526101a0518181816118280152818161195e015281816121240152818161233d0152818161250e01528181612fb6015281816135530152818161362401528181613a6e01528181613e1e01528181613f11015281816145bb015281816149740152614c1701526101c051818181610e60015281816125f4015281816138330152818161387901528181613b9b0152613bde0152f35b6105dd936105d89186519163095ea7b360e01b9083015260248201525f6044820152604481526105d2606482610a31565b82610e55565b610e55565b5f808080610496565b50813b1515610490565b80518015925086908315610608575b5050505f610489565b6106189350820181019101610e3d565b5f85816105ff565b90508381813d8311610655575b6106378183610a31565b81010312610651575160ff811681036106515760ff610432565b5f80fd5b503d61062d565b85513d5f823e3d90fd5b90508201515f6103e8565b601f1982169060195f52865f20915f5b888282106106e2575050927fadf3ae8bd543b3007d464f15cb8ea1db3f44e84d41d203164f40b95e27558ac694926001928261040796106106ca575b5050811b016019556103fc565b8401515f1960f88460031b161c191690555f806106bd565b6001849582939589015181550194019201610681565b60195f52855f20601f830160051c810191878410610732575b601f0160051c01905b81811061072757506103ac565b5f815560010161071a565b9091508190610711565b634e487b7160e01b5f52602260045260245ffd5b90607f169061039b565b634e487b7160e01b5f52604160045260245ffd5b90508201515f610358565b601f1982169060185f52875f20915f5b898282106107d7575050925f80516020615c0883398151915294926001928261037796106107bf575b5050811b0160185561036c565b8401515f1960f88460031b161c191690555f806107b2565b6001849582939589015181550194019201610789565b60185f52865f20601f830160051c810191888410610827575b601f0160051c01905b81811061081c575061032f565b5f815560010161080f565b9091508190610806565b90607f169061031e565b62127500811161085f57620151808110156102ce57631a1593df60e11b5f5260045ffd5b6346fedb5760e01b5f5260045ffd5b63d92e233d60e01b5f5260045ffd5b631e4fbdf760e01b5f525f60045260245ffd5b5060126101c4565b015190505f8061019f565b60045f9081528d81209350601f198516908e5b8282106108f35750509084600195949392106108db575b505050811b016004556101b4565b01515f1960f88460031b161c191690555f80806108cd565b60018596829396860151815501950193018e6108b6565b90915060045f528b5f20601f840160051c8101918d851061094f575b90601f859493920160051c01905b818110610941575061018a565b5f8155849350600101610934565b9091508190610926565b91607f1691610177565b015190505f8061013f565b60035f9081528e81209350601f198516908f5b8282106109be5750509084600195949392106109a6575b505050811b01600355610154565b01515f1960f88460031b161c191690555f8080610998565b60018596829396860151815501950193018f610981565b9091925060035f52815f2090601f850160051c8201928510610a1d575b90601f859493920160051c01905b818110610a0f578e9150610129565b5f8155849350600101610a00565b90915081906109f2565b91607f1691610115565b601f909101601f19168101906001600160401b0382119082101761075a57604052565b51906001600160a01b038216820361065157565b6001600160401b03811161075a57601f01601f191660200190565b81601f8201121561065157805190610a9a82610a68565b92610aa86040519485610a31565b8284526020838301011161065157815f9260208093018386015e8301015290565b602060409281835280519182918282860152018484015e5f828201840152601f01601f1916010190565b908151602081105f14610b4e575090601f815111610b2d576020815191015160208210610b1e571790565b5f198260200360031b1b161790565b60405163305a27a960e01b8152908190610b4a9060048301610ac9565b0390fd5b6001600160401b03811161075a57600554600181811c91168015610c51575b602082101461073c57601f8111610c1e575b50602092601f8211600114610bbd57928192935f92610bb2575b50508160011b915f199060031b1c19161760055560ff90565b015190505f80610b99565b601f1982169360055f52805f20915f5b868110610c065750836001959610610bee575b505050811b0160055560ff90565b01515f1960f88460031b161c191690555f8080610be0565b91926020600181928685015181550194019201610bcd565b60055f52601f60205f20910160051c810190601f830160051c015b818110610c465750610b7f565b5f8155600101610c39565b90607f1690610b6d565b908151602081105f14610c86575090601f815111610b2d576020815191015160208210610b1e571790565b6001600160401b03811161075a57600654600181811c91168015610d89575b602082101461073c57601f8111610d56575b50602092601f8211600114610cf557928192935f92610cea575b50508160011b915f199060031b1c19161760065560ff90565b015190505f80610cd1565b601f1982169360065f52805f20915f5b868110610d3e5750836001959610610d26575b505050811b0160065560ff90565b01515f1960f88460031b161c191690555f8080610d18565b91926020600181928685015181550194019201610d05565b60065f52601f60205f20910160051c810190601f830160051c015b818110610d7e5750610cb7565b5f8155600101610d71565b90607f1690610ca5565b3d15610dbd573d90610da482610a68565b91610db26040519384610a31565b82523d5f602084013e565b606090565b5f8091604051602081019063313ce56760e01b825260048152610de6602482610a31565b51916001600160a01b03165afa610dfb610d93565b9080610e31575b610e0e575b505f905f90565b602081805181010312610651576020015160ff8111610e07579060ff6001921690565b50602081511015610e02565b90816020910312610651575180151581036106515790565b5f80610e7d9260018060a01b03169360208151910182865af1610e76610d93565b9083610ec0565b8051908115159182610ea5575b5050610e935750565b635274afe760e01b5f5260045260245ffd5b610eb89250602080918301019101610e3d565b155f80610e8a565b90610ee45750805115610ed557805190602001fd5b630a12f52160e11b5f5260045ffd5b81511580610f15575b610ef5575090565b639996b31560e01b5f9081526001600160a01b0391909116600452602490fd5b50803b15610eed56fe60806040526004361015610011575f80fd5b5f3560e01c806301e1d11414612aff57806306fdde0314612a6d57806307a2d13a14611ded578063095ea7b314612a475780630a28a47714612a1e578063102f7b6c1461298d57806318160ddd146129705780631ecca77c1461290757806321cb4b14146128ea57806323b872dd146128b25780632acc56f9146126bc5780632b30997b1461264f578063313ce567146125e057806333f91ebb146125c35780633644e515146125a9578063388af5b51461258157806338d52e0f1461253d5780633acb5624146124f95780633b24c2bf14612270578063402d267d1461224c57806341b6783314611ee7578063452a932014611ebf5780634690484014611e9f5780634b998de514611df25780634cdad50614611ded5780634dedf20e14611db0578063568efc0714611d9357806362518ddf14611d6a57806369fe0e2d14611cb05780636e553f6514611c6e5780636fda386814611c1257806370a0823114611bdb578063715018a614611b765780637224a51214611a8c5780637299aa3114611683578063762c31ba1461164957806379ba5097146115c35780637cc4d9a1146115925780637ecebe001461155a57806384755b5f1461140357806384b0196e1461130b5780638a2c7b39146112d65780638da5cb5b146112ae57806394bf804d1461126c57806395d89b41146111b55780639d6b4a45146110da578063a17b3130146110bd578063a31be5d614611076578063a5f31d611461101a578063a9059cbb14610fe9578063ac9650d814610e84578063aea70acc14610e47578063b192a84a14610dae578063b3d7f6b914610d7a578063b460af9414610d44578063b84c824614610ba1578063ba08765214610b6a578063bc25cf7714610a7d578063c47f0027146108c0578063c63d75b61461087d578063c6e6f59214610405578063c9649aa914610805578063cc718f76146107bc578063ce96cb7714610794578063d33219b414610777578063d505accf14610632578063d905777e146105fe578063dd62ed3e146105ae578063ddca3f4314610588578063e30c397814610560578063e66f53b714610538578063e74b981b14610486578063e90956cf1461040a578063ef8b30f714610405578063f2fde38b146103995763f7d185211461035d575f80fd5b346103955760203660031901126103955760043560145481101561039557610386602091612ce5565b90549060031b1c604051908152f35b5f80fd5b34610395576020366003190112610395576103b2612b71565b6103ba61324b565b600980546001600160a01b0319166001600160a01b039283169081179091556008549091167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e227005f80a3005b612dc6565b3461039557602036600319011261039557610423612b71565b61042b61324b565b600a546001600160a01b039182169181168214610477576001600160a01b0319168117600a557fbd0a63c12948fbc9194a5839019f99c9d71db924e5c70018265bc778b8f1a5065f80a2005b63a741a04560e01b5f5260045ffd5b346103955760203660031901126103955761049f612b71565b6104a761324b565b6012546001600160a01b0382169190606081901c83146104775782159081610525575b50610516576104d761378c565b6001600160601b036012549181199060601b169116176012557f2e979f80fe4d43055c584cf4a8467c55875ea36728fc37176c05acd784eb7a735f80a2005b6333fe7c6560e21b5f5260045ffd5b6001600160601b039150161515836104ca565b34610395575f36600319011261039557600a546040516001600160a01b039091168152602090f35b34610395575f366003190112610395576009546040516001600160a01b039091168152602090f35b34610395575f3660031901126103955760206001600160601b0360125416604051908152f35b34610395576040366003190112610395576105c7612b71565b6105cf612b87565b6001600160a01b039182165f908152600160209081526040808320949093168252928352819020549051908152f35b3461039557602036600319011261039557602061062a61062461061f612b71565b613de0565b9161386f565b604051908152f35b346103955760e03660031901126103955761064b612b71565b610653612b87565b604435906064359260843560ff8116810361039557844211610764576107276107309160018060a01b03841696875f52600760205260405f20908154916001830190556040519060208201927f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c984528a604084015260018060a01b038916606084015289608084015260a083015260c082015260c081526106f560e082612c17565b51902061070061325f565b906040519161190160f01b83526002830152602282015260c43591604260a4359220614a61565b90929192614b01565b6001600160a01b031684810361074d575061074b935061410a565b005b84906325c0072360e11b5f5260045260245260445ffd5b8463313c898160e11b5f5260045260245ffd5b34610395575f366003190112610395576020600e54604051908152f35b346103955760203660031901126103955760206107b261061f612b71565b5050604051908152f35b34610395576020366003190112610395576004355f52600d602052606060405f20546040519060018060b81b038116825260ff8160b81c161515602083015260c01c6040820152f35b34610395575f366003190112610395576008546001600160a01b031633141580610868575b610859575f601155337f921828337692c347c634c5d2aacbc7b756014674bd236f3cc2058d8e284a951b5f80a2005b637cf97e4d60e11b5f5260045ffd5b50600c546001600160a01b031633141561082a565b3461039557602036600319011261039557610896612b71565b50602061062a6108ba6108a761361c565b6108af612fad565b509290600254612f03565b9061386f565b34610395576108ce36612d88565b6108d661324b565b80516001600160401b038111610a69576108f1601854612def565b601f8111610a01575b506020601f821160011461096f57918161095f927f4df9dcd34ae35f40f2c756fd8ac83210ed0b76d065543ee73d868aec7c7fcf02945f91610964575b508160011b915f199060031b1c1916176018555b604051918291602083526020830190612b24565b0390a1005b905082015185610937565b601f1982169060185f525f80516020614c9d833981519152915f5b8181106109e95750927f4df9dcd34ae35f40f2c756fd8ac83210ed0b76d065543ee73d868aec7c7fcf0294926001928261095f96106109d1575b5050811b0160185561094b565b8401515f1960f88460031b161c1916905585806109c4565b9192602060018192868901518155019401920161098a565b60185f52601f820160051c5f80516020614c9d833981519152019060208310610a54575b601f0160051c5f80516020614c9d83398151915201905b818110610a4957506108fa565b5f8155600101610a3c565b5f80516020614c9d8339815191529150610a25565b634e487b7160e01b5f52604160045260245ffd5b3461039557602036600319011261039557610a96612b71565b6013546001600160a01b0316908115610b5b576040516370a0823160e01b81523060048201526001600160a01b039190911691602082602481865afa918215610b50575f92610b1a575b5081610aec9184613da0565b6040519081527f2ae72b44f59d038340fca5739135a1d51fc5ab720bb02d983e4c5ff4119ca7b860203392a3005b9091506020813d602011610b48575b81610b3660209383612c17565b81010312610395575190610aec610ae0565b3d9150610b29565b6040513d5f823e3d90fd5b63d92e233d60e01b5f5260045ffd5b3461039557602061062a610b7d36612cfd565b929190610b8861378c565b610b986002546016549084613bc5565b93849133613c7b565b3461039557610baf36612d88565b610bb761324b565b80516001600160401b038111610a6957610bd2601954612def565b601f8111610cdc575b506020601f8211600114610c4a57918161095f927fadf3ae8bd543b3007d464f15cb8ea1db3f44e84d41d203164f40b95e27558ac6945f91610c3f575b508160011b915f199060031b1c191617601955604051918291602083526020830190612b24565b905082015185610c18565b601f1982169060195f525f80516020614cbd833981519152915f5b818110610cc45750927fadf3ae8bd543b3007d464f15cb8ea1db3f44e84d41d203164f40b95e27558ac694926001928261095f9610610cac575b5050811b0160195561094b565b8401515f1960f88460031b161c191690558580610c9f565b91926020600181928689015181550194019201610c65565b60195f52601f820160051c5f80516020614cbd833981519152019060208310610d2f575b601f0160051c5f80516020614cbd83398151915201905b818110610d245750610bdb565b5f8155600101610d17565b5f80516020614cbd8339815191529150610d00565b3461039557602061062a610d5736612cfd565b9291610d6161378c565b610d716002546016549083613829565b93849233613c7b565b3461039557602036600319011261039557602061062a610da6610d9b612fad565b509190600254612f03565b600435613b81565b3461039557604036600319011261039557610dc7612b71565b6024359081151580920361039557610ddd61324b565b6001600160a01b03165f818152600b602052604090205490919060ff16151581146104775760207f74dc60cbc81a9472d04ad1d20e151d369c41104d655ed3f2f3091166a502cd8d91835f52600b825260405f2060ff1981541660ff8316179055604051908152a2005b34610395575f36600319011261039557602060405160ff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b34610395576020366003190112610395576004356001600160401b03811161039557610eb4903690600401612bb1565b90610ebe82612ecb565b91610ecc6040519384612c17565b808352601f19610edb82612ecb565b015f5b818110610fd8575050905f90601e1981360301915b83811015610f71578060051b82013583811215610395578201908135916001600160401b038311610395576020018236038113610395575f80610f3d610f55936001963691612d52565b602081519101305af4610f4e613c4c565b903061485d565b610f5f8288612eef565b52610f6a8187612eef565b5001610ef3565b846040518091602082016020835281518091526040830190602060408260051b8601019301915f905b828210610fa957505050500390f35b91936001919395506020610fc88192603f198a82030186528851612b24565b9601920192018594939192610f9a565b806060602080938801015201610ede565b346103955760403660031901126103955761100f611005612b71565b602435903361318e565b602060405160018152f35b34610395575f36600319011261039557600f546001600160401b038160a01c1680156110675742106110585761074b906001600160a01b0316613c02565b63333bd2cb60e11b5f5260045ffd5b63e5f408a560e01b5f5260045ffd5b34610395576020366003190112610395576004355f908152601060209081526040918290205482516001600160c01b038216815260c09190911c91810191909152f35b0390f35b34610395575f366003190112610395576020601454604051908152f35b34610395576020366003190112610395576110f3612b71565b6110fb61324b565b600c546001600160a01b03828116929116828114610477576001600160401b03600f5460a01c166111a6576111345761074b9150613c02565b50611155600e54826001600160601b0360a01b600f541617600f5542612f03565b600f805467ffffffffffffffff60a01b191660a09290921b67ffffffffffffffff60a01b169190911790557f7633313af54753bce8a149927263b1a55eba857ba4ef1d13c6aee25d384d3c4b5f80a2005b6324d9026760e11b5f5260045ffd5b34610395575f366003190112610395576040515f6019546111d581612def565b808452906001811690811561124857506001146111fd575b6110b98361094b81850382612c17565b60195f9081525f80516020614cbd833981519152939250905b80821061122e5750909150810160200161094b6111ed565b919260018160209254838588010152019101909291611216565b60ff191660208086019190915291151560051b8401909101915061094b90506111ed565b3461039557604036600319011261039557602060043561062a61128d612b87565b9161129661378c565b6112a66002546016549083613b81565b8093336138b4565b34610395575f366003190112610395576008546040516001600160a01b039091168152602090f35b34610395575f366003190112610395576011548060c01c80156110675742106110585761074b906001600160c01b0316613979565b34610395575f366003190112610395576113a76113477f00000000000000000000000000000000000000000000000000000000000000006147c6565b6113707f0000000000000000000000000000000000000000000000000000000000000000614826565b60206113b5604051926113838385612c17565b5f84525f368137604051958695600f60f81b875260e08588015260e0870190612b24565b908582036040870152612b24565b4660608501523060808501525f60a085015283810360c08501528180845192838152019301915f5b8281106113ec57505050500390f35b8351855286955093810193928101926001016113dd565b346103955760a03660031901126103955761141d36612c38565b600a546001600160a01b031633141580611545575b6115365760a09020805f52600d60205260405f205460c01c6111a6575f818152600d60205260409020546001600160b81b031661152757805f52600d60205260ff60405f205460b81c161561151557805f52601060205260405f205460c01c611504576114dd6001600160401b036114ac600e5442612f03565b5f848152600d6020526040902080546001600160c01b03169290911660c01b6001600160c01b031916919091179055565b337f3240fc70754c5a2b4dab10bf7081a00024bfc8491581ee3d355360ec0dd91f165f80a3005b62463af360e81b5f5260045260245ffd5b636113d8c760e01b5f5260045260245ffd5b63624718b960e11b5f5260045ffd5b6332a2673b60e21b5f5260045ffd5b506008546001600160a01b0316331415611432565b34610395576020366003190112610395576001600160a01b0361157b612b71565b165f526007602052602060405f2054604051908152f35b34610395575f36600319011261039557601154604080516001600160c01b038316815260c09290921c602083015290f35b34610395575f36600319011261039557600954336001600160a01b039091160361163657600980546001600160a01b0319908116909155600880543392811683179091556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3005b63118cdaa760e01b5f523360045260245ffd5b34610395575f36600319011261039557600f54604080516001600160a01b038316815260a09290921c6001600160401b0316602083015290f35b34610395576020366003190112610395576004356001600160401b03811161039557366023820112156103955780600401356001600160401b0381116103955736602460c083028401011161039557335f52600b60205260ff60405f2054161580611a77575b80611a62575b611a53575f918290815b83831015611a3c5760c083028201906023198236030160c08112610395576040519060408201908282106001600160401b03831117610a695760a091604052126103955760a060405161174b81612be1565b61175760248601612b9d565b815261176560448601612b9d565b602082015261177660648601612b9d565b604082015261178760848601612b9d565b606082015260a4850135608082015280835260c46020840195013585522092835f52600d60205260ff60405f205460b81c1615611a29576117c9848351613a3d565b5082518083118184030294929085156118e95750505f9251156118de575b5051604051635c2bea4960e01b81529290611806906004850190612f26565b60a483015260c48201523060e48201819052610104820152604081610124815f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af1918215610b50576001936118a1935f935f916118aa575b506040519084825260208201527fdd8bf5226dff861316e0fa7863fdb7dc7b87c614eb29a135f524eb79d5a1189a60403392a3612f03565b925b01916116f9565b90506118ce91935060403d81116118d7575b6118c68183612c17565b810190612f10565b9290928a611869565b503d6118bc565b5f93509150896117e7565b9293509497999350505f1981145f14611a1c575081860382871102925b8315611a0e575f858152600d60205260409020546001600160b81b03169061192f908590612f03565b116119fb5790604061195993925181518095819263a99aad8960e01b835286309160048501612f65565b03815f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af1938415610b50576001946119d5945f916119db575b506040519084825260208201527f89bf199df65bf65155e3e0a8abc4ad4a1be606220c8295840dba2ab5656c1f6d60403392a3612f03565b946118a3565b6119f3915060403d81116118d7576118c68183612c17565b90508a61199d565b83635e25afa560e01b5f5260045260245ffd5b5050959050600191506118a3565b8380820391110292611906565b83636113d8c760e01b5f5260045260245ffd5b8403611a4457005b6309e36b8960e41b5f5260045ffd5b63f7137c0f60e01b5f5260045ffd5b506008546001600160a01b03163314156116ef565b50600a546001600160a01b03163314156116e9565b3461039557602036600319011261039557600435611aa861324b565b600e548082146104775760115460c01c6111a657621275008211611b6757620151808210611b585780821115611ae2575061074b90613979565b601180546001600160c01b0319166001600160b81b0384161790557fb3aa0ade2442acf51d06713c2d1a5a3ec0373cce969d42b53f4689f97bccf38091602091611b2c9042612f03565b601180546001600160c01b031660c09290921b6001600160c01b031916919091179055604051908152a1005b631a1593df60e11b5f5260045ffd5b6346fedb5760e01b5f5260045ffd5b34610395575f36600319011261039557611b8e61324b565b600980546001600160a01b03199081169091556008805491821690555f906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b34610395576020366003190112610395576001600160a01b03611bfc612b71565b165f525f602052602060405f2054604051908152f35b346103955760a036600319011261039557611c2c36612c38565b60a081205f52601060205260405f205460c01c8015611067574210611058578060a061074b9220805f52601060205260018060b81b0360405f2054169161345e565b3461039557604036600319011261039557602060043561062a611c8f612b87565b611c9761378c565b611ca7600254601654908561386f565b928391336138b4565b3461039557602036600319011261039557600435611ccc61324b565b6012546001600160601b0381168214610477576706f05b59d3b200008211611d5b578115159081611d4f575b50610516576001600160601b0390611d0e61378c565b16806001600160601b031960125416176012556040519081527f01fe2943baee27f47add82886c2200f910c749c461c9b63c5fe83901a53bdb4960203392a2005b905060601c1582611cf8565b63f4df6ae560e01b5f5260045ffd5b346103955760203660031901126103955760043560155481101561039557610386602091612cb9565b34610395575f366003190112610395576020601654604051908152f35b34610395576020366003190112610395576001600160a01b03611dd1612b71565b165f52600b602052602060ff60405f2054166040519015158152f35b612b48565b346103955760203660031901126103955760043560018060a01b03600c541633141580611e8a575b80611e75575b611e66575f818152600d6020526040812080546001600160c01b0316905533907fcbeb8ecdaa5a3c133e62219b63bfc35bce3fda13065d2bed32e3b7dde60a59f49080a3005b63d080fa3160e01b5f5260045ffd5b506008546001600160a01b0316331415611e20565b50600a546001600160a01b0316331415611e1a565b34610395575f36600319011261039557602060125460601c604051908152f35b34610395575f36600319011261039557600c546040516001600160a01b039091168152602090f35b34610395576020366003190112610395576004356001600160401b03811161039557611f17903690600401612bb1565b90335f52600b60205260ff60405f2054161580612237575b80612222575b611a5357601554611f4581612ecb565b611f526040519182612c17565b818152601f19611f6183612ecb565b01366020830137611f7184612ecb565b92611f7f6040519485612c17565b848452611f8b85612ecb565b602085019590601f19013687375f5b8181106121c2575050505f5b8281106120c35750505080516001600160401b038111610a6957600160401b8111610a69576015548160155580821061207f575b508260155f525f5b82811061204b5750505060405190602082019060208352518091526040820192905f5b81811061203557337fe0c2db6b54586be6d7d49943139fccf0dd315ba63e55364a76c73cd8fdba724d85870386a2005b8251855260209485019490920191600101612005565b60019060208351930192817f55f448fdea98c4d29eb340757ef0a66cd03dbb9538908a6a81d96026b71ec475015501611fe2565b60155f527f55f448fdea98c4d29eb340757ef0a66cd03dbb9538908a6a81d96026b71ec4759081019082015b8181106120b85750611fda565b5f81556001016120ab565b6120cd8183612eef565b51156120dc575b600101611fa6565b6120e581612cb9565b905460039190911b1c5f818152600d60205260409020546001600160b81b03166121b057805f52601060205260405f205460c01c6115045761214830827f00000000000000000000000000000000000000000000000000000000000000006136d4565b612160575b5f908152600d60205260408120556120d4565b805f52600d60205260405f205460c01c1561219e57805f52600d60205260405f205460c01c42101561214d57632cd5119960e21b5f5260045260245ffd5b63af8ae28760e01b5f5260045260245ffd5b63401d83d960e11b5f5260045260245ffd5b6121cd818385612ea8565b356121d781612cb9565b90549060031b1c906121e98187612eef565b5161220f579060016121fd81949388612eef565b526122088289612eef565b5201611f9a565b506392a726c360e01b5f5260045260245ffd5b506008546001600160a01b0316331415611f35565b50600a546001600160a01b0316331415611f2f565b3461039557602036600319011261039557612265612b71565b50602061062a61361c565b346103955760c03660031901126103955761228a36612c38565b60a4359060018060a01b03600a5416331415806124e4575b6115365760a0812081519092906001600160a01b039081167f0000000000000000000000000000000000000000000000000000000000000000909116036124d15760405160208101908482526003604082015260408152612304606082612c17565b519020600281018091116124bd575f61231f6123399261416d565b60405180938192637784c68560e01b8352600483016133f4565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610b50576001600160801b0391612388915f9161249b575b50612ee2565b51161561248c57825f52601060205260405f205460c01c6111a657825f52600d60205260405f205460c01c61247d575f838152600d60205260409020546001600160b81b0316818114610477578110156123ef57916123e961074b9361342d565b9161345e565b9050815f52601060205261244f60405f206001600160401b036124306124148561342d565b600e549060018060b81b03168360c01b85541617845542612f03565b82546001600160c01b0316911660c01b6001600160c01b031916179055565b6040519081527fe851bb5856808a50efd748be463b8f35bcfb5ec74c5bfde776fe0a4d2a26db2760203392a3005b6325f600a360e11b5f5260045ffd5b6396e1352960e01b5f5260045ffd5b6124b791503d805f833e6124af8183612c17565b81019061337b565b86612382565b634e487b7160e01b5f52601160045260245ffd5b826333cbfd2760e21b5f5260045260245ffd5b506008546001600160a01b03163314156122a2565b34610395575f366003190112610395576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b34610395575f366003190112610395576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b34610395575f366003190112610395576013546040516001600160a01b039091168152602090f35b34610395575f36600319011261039557602061062a61325f565b34610395575f366003190112610395576020601554604051908152f35b34610395575f3660031901126103955760ff7f00000000000000000000000000000000000000000000000000000000000000001660ff7f0000000000000000000000000000000000000000000000000000000000000000160160ff81116124bd5760209060ff60405191168152f35b3461039557602036600319011261039557612668612b71565b61267061324b565b6013546001600160a01b039182169181168214610477576001600160a01b03191681176013557f2e7908865670e21b9779422cadf5f1cba271a62bb95c71eaaf615c0a1c48ebee5f80a2005b34610395576020366003190112610395576004356001600160401b038111610395576126ec903690600401612bb1565b335f52600b60205260ff60405f205416158061289d575b80612888575b611a5357601e8111612879575f5b81811061282c57506001600160401b038111610a6957600160401b8111610a6957601454816014558082106127e8575b508160145f525f5b8281106127b457505060405190806020830160208452526040820192905f5b81811061279e57337f6ce31538fc7fba95714ddc8a275a09252b4b1fb8f33d2550aa58a5f62ad934de85870386a2005b823585526020948501949092019160010161276e565b60019060208335930192817fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec01550161274f565b60145f527fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec9081019082015b8181106128215750612747565b5f8155600101612814565b612837818385612ea8565b355f908152600d60205260409020546001600160b81b03161561285c57600101612717565b9061286692612ea8565b3563067f0a2560e41b5f5260045260245ffd5b6340797bd760e11b5f5260045ffd5b506008546001600160a01b0316331415612709565b50600a546001600160a01b0316331415612703565b346103955760603660031901126103955761100f6128ce612b71565b6128d6612b87565b604435916128e58333836130c8565b61318e565b34610395575f366003190112610395576020601754604051908152f35b34610395575f366003190112610395576008546001600160a01b03163314158061295b575b610859575f600f55337fc40a085ccfa20f5fd518ade5c3a77a7ecbdfbb4c75efcdca6146a8e3c841d6635f80a2005b50600c546001600160a01b031633141561292c565b34610395575f366003190112610395576020600254604051908152f35b346103955760203660031901126103955760043560018060a01b03600c541633141580612a09575b806129f4575b611e6657805f5260106020525f6040812055337f1026ceca5ed3747eb5edec555732d4a6f901ce1a875ecf981064628cadde11205f80a3005b506008546001600160a01b03163314156129bb565b50600a546001600160a01b03163314156129b5565b3461039557602036600319011261039557602061062a612a3f610d9b612fad565b600435613829565b346103955760403660031901126103955761100f612a63612b71565b602435903361410a565b34610395575f366003190112610395576040515f601854612a8d81612def565b80845290600181169081156112485750600114612ab4576110b98361094b81850382612c17565b60185f9081525f80516020614c9d833981519152939250905b808210612ae55750909150810160200161094b6111ed565b919260018160209254838588010152019101909291612acd565b34610395575f366003190112610395576020612b19612fad565b509050604051908152f35b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b3461039557602036600319011261039557602061062a612b69610d9b612fad565b600435613bc5565b600435906001600160a01b038216820361039557565b602435906001600160a01b038216820361039557565b35906001600160a01b038216820361039557565b9181601f84011215610395578235916001600160401b038311610395576020808501948460051b01011161039557565b60a081019081106001600160401b03821117610a6957604052565b60c081019081106001600160401b03821117610a6957604052565b90601f801991011681019081106001600160401b03821117610a6957604052565b60a09060031901126103955760405190612c5182612be1565b816004356001600160a01b03811681036103955781526024356001600160a01b03811681036103955760208201526044356001600160a01b03811681036103955760408201526064356001600160a01b03811681036103955760608201526080608435910152565b601554811015612cd15760155f5260205f2001905f90565b634e487b7160e01b5f52603260045260245ffd5b601454811015612cd15760145f5260205f2001905f90565b606090600319011261039557600435906024356001600160a01b038116810361039557906044356001600160a01b03811681036103955790565b6001600160401b038111610a6957601f01601f191660200190565b929192612d5e82612d37565b91612d6c6040519384612c17565b829481845281830111610395578281602093845f960137010152565b602060031982011261039557600435906001600160401b038211610395578060238301121561039557816024612dc393600401359101612d52565b90565b3461039557602036600319011261039557602061062a612de7610d9b612fad565b60043561386f565b90600182811c92168015612e1d575b6020831014612e0957565b634e487b7160e01b5f52602260045260245ffd5b91607f1691612dfe565b5f9291815491612e3683612def565b8083529260018116908115612e8b5750600114612e5257505050565b5f9081526020812093945091925b838310612e71575060209250010190565b600181602092949394548385870101520191019190612e60565b915050602093945060ff929192191683830152151560051b010190565b9190811015612cd15760051b0190565b818102929181159184041417156124bd57565b6001600160401b038111610a695760051b60200190565b805115612cd15760200190565b8051821015612cd15760209160051b010190565b919082018092116124bd57565b9190826040910312610395576020825192015190565b80516001600160a01b03908116835260208083015182169084015260408083015182169084015260608083015190911690830152608090810151910152565b91612f74836101409593612f26565b60a08301525f60c083015260018060a01b031660e08201526101206101008201525f6101208201520190565b919082039182116124bd57565b5f905f806015547f00000000000000000000000000000000000000000000000000000000000000005b8183106130755750505060165491601754612ff18185612fa0565b83101561306757506130176130106130098486612fa0565b8094612f03565b9384612fa0565b80151580613053575b6130275750565b613050919450613043906001600160601b036012541690613fe4565b6002546106248286612fa0565b92565b506001600160601b03601254161515613020565b613010613017918094612f03565b9091926130bf6001916130b961309961308d88612cb9565b90549060031b1c613eca565b6130b16130aa3060a08420896136d4565b91876141e5565b5050916147a0565b90612f03565b93019190612fd6565b6001600160a01b039081165f81815260016020818152604080842095871684529490529290205493929184016130ff575b50505050565b82841061316b578015613158576001600160a01b03821615613145575f52600160205260405f209060018060a01b03165f5260205260405f20910390555f8080806130f9565b634a1406b160e11b5f525f60045260245ffd5b63e602df0560e01b5f525f60045260245ffd5b508290637dc7a0d960e11b5f5260018060a01b031660045260245260445260645ffd5b6001600160a01b0316908115613238576001600160a01b031691821561322557815f525f60205260405f205481811061320c57817fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92602092855f525f84520360405f2055845f525f825260405f20818154019055604051908152a3565b8263391434e360e21b5f5260045260245260445260645ffd5b63ec442f0560e01b5f525f60045260245ffd5b634b637e8f60e11b5f525f60045260245ffd5b6008546001600160a01b0316330361163657565b307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03161480613352575b156132ba577f000000000000000000000000000000000000000000000000000000000000000090565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527f000000000000000000000000000000000000000000000000000000000000000060408201527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260a0815261334c60c082612c17565b51902090565b507f00000000000000000000000000000000000000000000000000000000000000004614613291565b602081830312610395578051906001600160401b03821161039557019080601f830112156103955781516133ae81612ecb565b926133bc6040519485612c17565b81845260208085019260051b82010192831161039557602001905b8282106133e45750505090565b81518152602091820191016133d7565b60206040818301928281528451809452019201905f5b8181106134175750505090565b825184526020938401939092019160010161340a565b6001600160b81b038111613447576001600160b81b031690565b6306dfcc6560e41b5f5260b860045260245260445ffd5b5f828152600d6020526040902093926001600160b81b031690816134d0575b508192938168ffffffffffffffffff60b81b8254161790556040519081527fe86b6d3313d3098f4c5f689c935de8fde876a597c185def2cedab85efedac68660203392a35f5260106020525f6040812055565b60ff855460b81c16156134f2575b5083546001600160c01b031684558161347d565b601554600160401b811015610a69578060016135119201601555612cb9565b81549060031b9085821b915f19901b1916179055601e601554116128795761358761358c91600160b81b60ff60b81b198854161787556130b9601654916130b17f0000000000000000000000000000000000000000000000000000000000000000916135813060a08320856136d4565b926141e5565b614194565b604051936020850160208652601554809152604086019060155f527f55f448fdea98c4d29eb340757ef0a66cd03dbb9538908a6a81d96026b71ec475905f5b818110613606575050507fe0c2db6b54586be6d7d49943139fccf0dd315ba63e55364a76c73cd8fdba724d8685969733930390a293926134de565b82548452602090930192600192830192016135cb565b5f905f6014547f00000000000000000000000000000000000000000000000000000000000000005b81831061365057505050565b90919361365c85612ce5565b905460039190911b1c5f818152600d60205260409020546001600160b81b03169081156136c957916136bf916136b36001946136ab6136a561369f30848b6136d4565b92613eca565b886141e5565b5050916144cd565b80820391110290612f03565b945b019190613644565b5050936001906136c1565b61372f61374b935f936040516020810191825260026040820152604081526136fd606082612c17565b51902060405190602082019260018060a01b03168352604082015260408152613727606082612c17565b51902061416d565b906040518080958194637784c68560e01b8352600483016133f4565b03916001600160a01b03165afa8015610b505761376e915f916137725750612ee2565b5190565b61378691503d805f833e6124af8183612c17565b5f612382565b7ff66f28b40975dbb933913542c7e6a0f50a1d0f20aa74ea6e0efe65ab616323ec60407f548669ea9bcc24888e6d74a69c9865fa98d795686853b8aa3eb87814261bbb7160206137da612fad565b6137e78295939492614194565b806017558551908152a180613804575b82519182526020820152a1565b6138138160125460601c61450c565b6137f7565b60ff16604d81116124bd57600a0a90565b90613857906130b97f0000000000000000000000000000000000000000000000000000000000000000613818565b91600181018091116124bd57612dc392600192614569565b9061389d906130b97f0000000000000000000000000000000000000000000000000000000000000000613818565b91600181018091116124bd57612dc3925f92614569565b92613977937fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7604061358795946139448251946323b872dd60e01b602087015260018060a01b0316948560248201523060448201528760648201526064815261391e608482612c17565b7f00000000000000000000000000000000000000000000000000000000000000006149ed565b61394e858261450c565b815186815260208101959095526001600160a01b031693a361396f816145b9565b601654612f03565b565b80600e556040519081527fd28e9b90ee9b37c5936ff84392d71f29ff18117d7e76bcee60615262a90a3f7560203392a25f601155565b51906001600160801b038216820361039557565b908160c091031261039557613a3560a0604051926139e084612bfc565b6139e9816139af565b84526139f7602082016139af565b6020850152613a08604082016139af565b6040850152613a19606082016139af565b6060850152613a2a608082016139af565b6080850152016139af565b60a082015290565b905f915f60a0604051613a4f81612bfc565b82815282602082015282604082015282606082015282608082015201527f00000000000000000000000000000000000000000000000000000000000000009060018060a01b03821690813b1561039557604051630a8e0d6f60e11b815290613abb906004830190612f26565b5f8160a48183865af18015610b5057613b6b575b5060c060249160405192838092632e3071cd60e11b82528760048301525afa938415613b5f5793613b26575b50613b0c61305091849330916136d4565b926001600160801b036020818351169201511690846147a0565b613050919350613b50613b0c9160c03d60c011613b58575b613b488183612c17565b8101906139c3565b939150613afb565b503d613b3e565b604051903d90823e3d90fd5b613b789194505f90612c17565b5f9260c0613acf565b600183018093116124bd57612dc392613bbf6001936130b97f0000000000000000000000000000000000000000000000000000000000000000613818565b91614569565b600183018093116124bd57612dc392613bbf5f936130b97f0000000000000000000000000000000000000000000000000000000000000000613818565b600c80546001600160a01b0319166001600160a01b03929092169182179055337fcb11cc8aade2f5a556749d1b2380d108a16fac3431e6a5d5ce12ef9de0bd76e35f80a35f600f55565b3d15613c76573d90613c5d82612d37565b91613c6b6040519384612c17565b82523d5f602084013e565b606090565b9193613c8f60165485808203911102614194565b613c98846148bb565b6001600160a01b0385811695908416938290878603613d8f575b505050841561323857845f525f60205260405f2054818110613d765791816040927ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db94885f525f60205203835f205580600254036002555f877fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60208651858152a3613d5f86837f0000000000000000000000000000000000000000000000000000000000000000613da0565b825195865260208601526001600160a01b031693a4565b8563391434e360e21b5f5260045260245260445260645ffd5b613d98926130c8565b5f8181613cb2565b60405163a9059cbb60e01b60208201526001600160a01b03909216602483015260448083019390935291815261397791613ddb606483612c17565b6149ed565b613e1590613dec612fad565b50613dfb819492600254612f03565b9260018060a01b03165f525f6020528260405f2054613bc5565b6015549290805f7f00000000000000000000000000000000000000000000000000000000000000005b868210613e54575b505061305092939450612fa0565b9092613e9b613e6285612cb9565b90549060031b1c613e95613e81613e7883613eca565b923090876136d4565b613e8b83876141e5565b50939180936147a0565b92614bef565b808203911102928315613eb15760010190613e3e565b613e46565b51906001600160a01b038216820361039557565b5f6080604051613ed981612be1565b828152826020820152826040820152826060820152015260405190632c3c915760e01b8252600482015260a081602481600180851b037f0000000000000000000000000000000000000000000000000000000000000000165afa908115610b50575f91613f44575090565b905060a0813d60a011613fbe575b81613f5f60a09383612c17565b8101031261039557608060405191613f7683612be1565b613f7f81613eb6565b8352613f8d60208201613eb6565b6020840152613f9e60408201613eb6565b6040840152613faf60608201613eb6565b60608401520151608082015290565b3d9150613f52565b8115613fd0570490565b634e487b7160e01b5f52601260045260245ffd5b9190915f838202915f19858209918380841093039280840393146140635782670de0b6b3a7640000111561405457507faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106699394670de0b6b3a7640000910990828211900360ee1b910360121c170290565b63227bc15360e01b8152600490fd5b505050670de0b6b3a76400009192500490565b9091828202915f19848209938380861095039480860395146140fd57848311156140ee57829109815f0382168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b63227bc15360e01b5f5260045ffd5b505090612dc39250613fc6565b6001600160a01b0316908115613158576001600160a01b03169182156131455760207f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591835f526001825260405f20855f5282528060405f2055604051908152a3565b6040519061417c604083612c17565b600182526020368184013761419082612ee2565b5290565b60207f15c027cc4fd826d986cad358803439f7326d3aa4ed969ff90dbee4bc150f68e99180601655604051908152a1565b906001600160801b03809116911601906001600160801b0382116124bd57565b9060c060a08220602460405180958193632e3071cd60e11b8352600483015260018060a01b03165afa918215610b50575f926144ac575b50608082016142356001600160801b0382511642612fa0565b9182151580614496575b80614480575b614283575b5050506001600160801b038151166001600160801b03602083015116926001600160801b03606081604086015116940151169193929190565b6060810151604051638c00bf6b60e01b8152916001600160a01b03909116906142b0906004840190612f26565b6001600160801b0385511660a483015260208501936001600160801b0385511660c48401526001600160801b0360408701948186511660e48601528160608901511661010486015251166101248401526020836101648160a08a01956001600160801b038751166101448301525afa928315610b50575f9361444a575b506143906001600160801b039361438a614354670de0b6b3a7640000948789511693612eb8565b614385671bc16d674ec8000061436a8380612eb8565b046729a2241af62c000061437e8483612eb8565b0492612f03565b612f03565b90612eb8565b0492826143a861439f86614b7d565b828451166141c5565b169052816143c16143b885614b7d565b828851166141c5565b168552511690811561424a57670de0b6b3a7640000916143e091612eb8565b046143f5816001600160801b03855116612fa0565b6001600160801b0383511691620f424083018093116124bd57600182018092116124bd5761443a61443f926144356001600160801b039561439f94612eb8565b613fc6565b614b7d565b1690525f808061424a565b92506020833d602011614478575b8161446560209383612c17565b810103126103955791519161439061432d565b3d9150614458565b5060608101516001600160a01b03161515614245565b506001600160801b03604085015116151561423f565b6144c691925060c03d60c011613b5857613b488183612c17565b905f61421c565b90600181018091116124bd57620f42408301918284116124bd57620f423f916144f591612eb8565b9201918183116124bd57612dc39261443591612f03565b6001600160a01b0316908115613225577fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60208261454d5f94600254612f03565b60025584845283825260408420818154019055604051908152a3565b9190600180614579848487614076565b9561458381614ae3565b161492836145a4575b5050506145965790565b600181018091116124bd5790565b909180935015613fd0570915155f808061458c565b7f0000000000000000000000000000000000000000000000000000000000000000906001600160a01b0382165f5b601454811015614787576145fa81612ce5565b905460039190911b1c5f818152600d60205260409020546001600160b81b0316801561477d5761462982613eca565b91843b1561039557604051630a8e0d6f60e11b815261464b6004820185612f26565b5f8160a481838a5af18015610b505761476d575b50604051632e3071cd60e11b8152600481018290529060c082602481895afa908115610b50576146b6925f92614749575b5061469d9030908a6136d4565b906001600160801b0360208183511692015116916144cd565b808203911102908185108583180280831892036146e0575b505082156130f9576001905b016145e7565b60406147029181518093819263a99aad8960e01b835286309160048501612f65565b03815f885af1908161472c575b5061471b575b806146ce565b6147259193612fa0565b915f614715565b6147439060403d81116118d7576118c68183612c17565b5061470f565b61469d9192506147669060c03d8111613b5857613b488183612c17565b9190614690565b5f61477791612c17565b5f61465f565b50506001906146da565b5050905061479157565b63ded0652d60e01b5f5260045ffd5b60018201929183106124bd57620f424082018092116124bd57612dc39261443591612eb8565b60ff811461480c5760ff811690601f82116147fd57604051916147ea604084612c17565b6020808452838101919036833783525290565b632cd44ac360e21b5f5260045ffd5b50604051612dc38161481f816005612e27565b0382612c17565b60ff811461484a5760ff811690601f82116147fd57604051916147ea604084612c17565b50604051612dc38161481f816006612e27565b90614881575080511561487257805190602001fd5b630a12f52160e11b5f5260045ffd5b815115806148b2575b614892575090565b639996b31560e01b5f9081526001600160a01b0391909116600452602490fd5b50803b1561488a565b5f5b6015548110156149d7576148d081612cb9565b90549060031b1c6149086148ed6148e683613eca565b9283613a3d565b90506001600160801b03604081835116920151169084614bef565b9081841084831802808318920361492e575b5050811561492a576001016148bd565b5050565b604051635c2bea4960e01b81529061494a906004830190612f26565b8160a48201525f60c48201523060e482015230610104820152604081610124815f60018060a01b037f0000000000000000000000000000000000000000000000000000000000000000165af190816149ba575b506149a9575b8061491a565b6149b39192612fa0565b905f6149a3565b6149d19060403d81116118d7576118c68183612c17565b5061499d565b506149de57565b634323a55560e01b5f5260045ffd5b5f80614a159260018060a01b03169360208151910182865af1614a0e613c4c565b908361485d565b8051908115159182614a3d575b5050614a2b5750565b635274afe760e01b5f5260045260245ffd5b81925090602091810103126103955760200151801590811503610395575f80614a22565b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411614ad8579160209360809260ff5f9560405194855216868401526040830152606082015282805260015afa15610b50575f516001600160a01b03811615614ace57905f905f90565b505f906001905f90565b5050505f9160039190565b60041115614aed57565b634e487b7160e01b5f52602160045260245ffd5b614b0a81614ae3565b80614b13575050565b614b1c81614ae3565b60018103614b335763f645eedf60e01b5f5260045ffd5b614b3c81614ae3565b60028103614b57575063fce698f760e01b5f5260045260245ffd5b600390614b6381614ae3565b14614b6b5750565b6335e2f38360e21b5f5260045260245ffd5b604051614b8b604082612c17565b60148152731b585e081d5a5b9d0c4c8e08195e18d95959195960621b60208201526001600160801b038211614bc757506001600160801b031690565b60405162461bcd60e51b815260206004820152908190614beb906024830190612b24565b0390fd5b91614bfe602091602493612fa0565b92516040516370a0823160e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660048301529093849290918391165afa908115610b50575f91614c6a575b508181109082180218818110908218021890565b90506020813d602011614c94575b81614c8560209383612c17565b8101031261039557515f614c56565b3d9150614c7856feb13d2d76d1f4b7be834882e410b3e3a8afaf69f83600ae24db354391d2378d2e944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c9695a164736f6c634300081a000a4df9dcd34ae35f40f2c756fd8ac83210ed0b76d065543ee73d868aec7c7fcf02000000000000000000000000e6fc2a011153dd5a230725a9f0c89a9c81ab4887000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000203a662b0bd271a6ed5a60edfbd04bfce608fd3600000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000015537465616b686f757365205072696d65205553444300000000000000000000000000000000000000000000000000000000000000000000000000000000000009737465616b555344430000000000000000000000000000000000000000000000
Deployed Bytecode
0x60806040526004361015610011575f80fd5b5f3560e01c806301e1d11414612aff57806306fdde0314612a6d57806307a2d13a14611ded578063095ea7b314612a475780630a28a47714612a1e578063102f7b6c1461298d57806318160ddd146129705780631ecca77c1461290757806321cb4b14146128ea57806323b872dd146128b25780632acc56f9146126bc5780632b30997b1461264f578063313ce567146125e057806333f91ebb146125c35780633644e515146125a9578063388af5b51461258157806338d52e0f1461253d5780633acb5624146124f95780633b24c2bf14612270578063402d267d1461224c57806341b6783314611ee7578063452a932014611ebf5780634690484014611e9f5780634b998de514611df25780634cdad50614611ded5780634dedf20e14611db0578063568efc0714611d9357806362518ddf14611d6a57806369fe0e2d14611cb05780636e553f6514611c6e5780636fda386814611c1257806370a0823114611bdb578063715018a614611b765780637224a51214611a8c5780637299aa3114611683578063762c31ba1461164957806379ba5097146115c35780637cc4d9a1146115925780637ecebe001461155a57806384755b5f1461140357806384b0196e1461130b5780638a2c7b39146112d65780638da5cb5b146112ae57806394bf804d1461126c57806395d89b41146111b55780639d6b4a45146110da578063a17b3130146110bd578063a31be5d614611076578063a5f31d611461101a578063a9059cbb14610fe9578063ac9650d814610e84578063aea70acc14610e47578063b192a84a14610dae578063b3d7f6b914610d7a578063b460af9414610d44578063b84c824614610ba1578063ba08765214610b6a578063bc25cf7714610a7d578063c47f0027146108c0578063c63d75b61461087d578063c6e6f59214610405578063c9649aa914610805578063cc718f76146107bc578063ce96cb7714610794578063d33219b414610777578063d505accf14610632578063d905777e146105fe578063dd62ed3e146105ae578063ddca3f4314610588578063e30c397814610560578063e66f53b714610538578063e74b981b14610486578063e90956cf1461040a578063ef8b30f714610405578063f2fde38b146103995763f7d185211461035d575f80fd5b346103955760203660031901126103955760043560145481101561039557610386602091612ce5565b90549060031b1c604051908152f35b5f80fd5b34610395576020366003190112610395576103b2612b71565b6103ba61324b565b600980546001600160a01b0319166001600160a01b039283169081179091556008549091167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e227005f80a3005b612dc6565b3461039557602036600319011261039557610423612b71565b61042b61324b565b600a546001600160a01b039182169181168214610477576001600160a01b0319168117600a557fbd0a63c12948fbc9194a5839019f99c9d71db924e5c70018265bc778b8f1a5065f80a2005b63a741a04560e01b5f5260045ffd5b346103955760203660031901126103955761049f612b71565b6104a761324b565b6012546001600160a01b0382169190606081901c83146104775782159081610525575b50610516576104d761378c565b6001600160601b036012549181199060601b169116176012557f2e979f80fe4d43055c584cf4a8467c55875ea36728fc37176c05acd784eb7a735f80a2005b6333fe7c6560e21b5f5260045ffd5b6001600160601b039150161515836104ca565b34610395575f36600319011261039557600a546040516001600160a01b039091168152602090f35b34610395575f366003190112610395576009546040516001600160a01b039091168152602090f35b34610395575f3660031901126103955760206001600160601b0360125416604051908152f35b34610395576040366003190112610395576105c7612b71565b6105cf612b87565b6001600160a01b039182165f908152600160209081526040808320949093168252928352819020549051908152f35b3461039557602036600319011261039557602061062a61062461061f612b71565b613de0565b9161386f565b604051908152f35b346103955760e03660031901126103955761064b612b71565b610653612b87565b604435906064359260843560ff8116810361039557844211610764576107276107309160018060a01b03841696875f52600760205260405f20908154916001830190556040519060208201927f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c984528a604084015260018060a01b038916606084015289608084015260a083015260c082015260c081526106f560e082612c17565b51902061070061325f565b906040519161190160f01b83526002830152602282015260c43591604260a4359220614a61565b90929192614b01565b6001600160a01b031684810361074d575061074b935061410a565b005b84906325c0072360e11b5f5260045260245260445ffd5b8463313c898160e11b5f5260045260245ffd5b34610395575f366003190112610395576020600e54604051908152f35b346103955760203660031901126103955760206107b261061f612b71565b5050604051908152f35b34610395576020366003190112610395576004355f52600d602052606060405f20546040519060018060b81b038116825260ff8160b81c161515602083015260c01c6040820152f35b34610395575f366003190112610395576008546001600160a01b031633141580610868575b610859575f601155337f921828337692c347c634c5d2aacbc7b756014674bd236f3cc2058d8e284a951b5f80a2005b637cf97e4d60e11b5f5260045ffd5b50600c546001600160a01b031633141561082a565b3461039557602036600319011261039557610896612b71565b50602061062a6108ba6108a761361c565b6108af612fad565b509290600254612f03565b9061386f565b34610395576108ce36612d88565b6108d661324b565b80516001600160401b038111610a69576108f1601854612def565b601f8111610a01575b506020601f821160011461096f57918161095f927f4df9dcd34ae35f40f2c756fd8ac83210ed0b76d065543ee73d868aec7c7fcf02945f91610964575b508160011b915f199060031b1c1916176018555b604051918291602083526020830190612b24565b0390a1005b905082015185610937565b601f1982169060185f525f80516020614c9d833981519152915f5b8181106109e95750927f4df9dcd34ae35f40f2c756fd8ac83210ed0b76d065543ee73d868aec7c7fcf0294926001928261095f96106109d1575b5050811b0160185561094b565b8401515f1960f88460031b161c1916905585806109c4565b9192602060018192868901518155019401920161098a565b60185f52601f820160051c5f80516020614c9d833981519152019060208310610a54575b601f0160051c5f80516020614c9d83398151915201905b818110610a4957506108fa565b5f8155600101610a3c565b5f80516020614c9d8339815191529150610a25565b634e487b7160e01b5f52604160045260245ffd5b3461039557602036600319011261039557610a96612b71565b6013546001600160a01b0316908115610b5b576040516370a0823160e01b81523060048201526001600160a01b039190911691602082602481865afa918215610b50575f92610b1a575b5081610aec9184613da0565b6040519081527f2ae72b44f59d038340fca5739135a1d51fc5ab720bb02d983e4c5ff4119ca7b860203392a3005b9091506020813d602011610b48575b81610b3660209383612c17565b81010312610395575190610aec610ae0565b3d9150610b29565b6040513d5f823e3d90fd5b63d92e233d60e01b5f5260045ffd5b3461039557602061062a610b7d36612cfd565b929190610b8861378c565b610b986002546016549084613bc5565b93849133613c7b565b3461039557610baf36612d88565b610bb761324b565b80516001600160401b038111610a6957610bd2601954612def565b601f8111610cdc575b506020601f8211600114610c4a57918161095f927fadf3ae8bd543b3007d464f15cb8ea1db3f44e84d41d203164f40b95e27558ac6945f91610c3f575b508160011b915f199060031b1c191617601955604051918291602083526020830190612b24565b905082015185610c18565b601f1982169060195f525f80516020614cbd833981519152915f5b818110610cc45750927fadf3ae8bd543b3007d464f15cb8ea1db3f44e84d41d203164f40b95e27558ac694926001928261095f9610610cac575b5050811b0160195561094b565b8401515f1960f88460031b161c191690558580610c9f565b91926020600181928689015181550194019201610c65565b60195f52601f820160051c5f80516020614cbd833981519152019060208310610d2f575b601f0160051c5f80516020614cbd83398151915201905b818110610d245750610bdb565b5f8155600101610d17565b5f80516020614cbd8339815191529150610d00565b3461039557602061062a610d5736612cfd565b9291610d6161378c565b610d716002546016549083613829565b93849233613c7b565b3461039557602036600319011261039557602061062a610da6610d9b612fad565b509190600254612f03565b600435613b81565b3461039557604036600319011261039557610dc7612b71565b6024359081151580920361039557610ddd61324b565b6001600160a01b03165f818152600b602052604090205490919060ff16151581146104775760207f74dc60cbc81a9472d04ad1d20e151d369c41104d655ed3f2f3091166a502cd8d91835f52600b825260405f2060ff1981541660ff8316179055604051908152a2005b34610395575f36600319011261039557602060405160ff7f000000000000000000000000000000000000000000000000000000000000000c168152f35b34610395576020366003190112610395576004356001600160401b03811161039557610eb4903690600401612bb1565b90610ebe82612ecb565b91610ecc6040519384612c17565b808352601f19610edb82612ecb565b015f5b818110610fd8575050905f90601e1981360301915b83811015610f71578060051b82013583811215610395578201908135916001600160401b038311610395576020018236038113610395575f80610f3d610f55936001963691612d52565b602081519101305af4610f4e613c4c565b903061485d565b610f5f8288612eef565b52610f6a8187612eef565b5001610ef3565b846040518091602082016020835281518091526040830190602060408260051b8601019301915f905b828210610fa957505050500390f35b91936001919395506020610fc88192603f198a82030186528851612b24565b9601920192018594939192610f9a565b806060602080938801015201610ede565b346103955760403660031901126103955761100f611005612b71565b602435903361318e565b602060405160018152f35b34610395575f36600319011261039557600f546001600160401b038160a01c1680156110675742106110585761074b906001600160a01b0316613c02565b63333bd2cb60e11b5f5260045ffd5b63e5f408a560e01b5f5260045ffd5b34610395576020366003190112610395576004355f908152601060209081526040918290205482516001600160c01b038216815260c09190911c91810191909152f35b0390f35b34610395575f366003190112610395576020601454604051908152f35b34610395576020366003190112610395576110f3612b71565b6110fb61324b565b600c546001600160a01b03828116929116828114610477576001600160401b03600f5460a01c166111a6576111345761074b9150613c02565b50611155600e54826001600160601b0360a01b600f541617600f5542612f03565b600f805467ffffffffffffffff60a01b191660a09290921b67ffffffffffffffff60a01b169190911790557f7633313af54753bce8a149927263b1a55eba857ba4ef1d13c6aee25d384d3c4b5f80a2005b6324d9026760e11b5f5260045ffd5b34610395575f366003190112610395576040515f6019546111d581612def565b808452906001811690811561124857506001146111fd575b6110b98361094b81850382612c17565b60195f9081525f80516020614cbd833981519152939250905b80821061122e5750909150810160200161094b6111ed565b919260018160209254838588010152019101909291611216565b60ff191660208086019190915291151560051b8401909101915061094b90506111ed565b3461039557604036600319011261039557602060043561062a61128d612b87565b9161129661378c565b6112a66002546016549083613b81565b8093336138b4565b34610395575f366003190112610395576008546040516001600160a01b039091168152602090f35b34610395575f366003190112610395576011548060c01c80156110675742106110585761074b906001600160c01b0316613979565b34610395575f366003190112610395576113a76113477f00000000000000000000000000000000000000000000000000000000000000006147c6565b6113707f3100000000000000000000000000000000000000000000000000000000000001614826565b60206113b5604051926113838385612c17565b5f84525f368137604051958695600f60f81b875260e08588015260e0870190612b24565b908582036040870152612b24565b4660608501523060808501525f60a085015283810360c08501528180845192838152019301915f5b8281106113ec57505050500390f35b8351855286955093810193928101926001016113dd565b346103955760a03660031901126103955761141d36612c38565b600a546001600160a01b031633141580611545575b6115365760a09020805f52600d60205260405f205460c01c6111a6575f818152600d60205260409020546001600160b81b031661152757805f52600d60205260ff60405f205460b81c161561151557805f52601060205260405f205460c01c611504576114dd6001600160401b036114ac600e5442612f03565b5f848152600d6020526040902080546001600160c01b03169290911660c01b6001600160c01b031916919091179055565b337f3240fc70754c5a2b4dab10bf7081a00024bfc8491581ee3d355360ec0dd91f165f80a3005b62463af360e81b5f5260045260245ffd5b636113d8c760e01b5f5260045260245ffd5b63624718b960e11b5f5260045ffd5b6332a2673b60e21b5f5260045ffd5b506008546001600160a01b0316331415611432565b34610395576020366003190112610395576001600160a01b0361157b612b71565b165f526007602052602060405f2054604051908152f35b34610395575f36600319011261039557601154604080516001600160c01b038316815260c09290921c602083015290f35b34610395575f36600319011261039557600954336001600160a01b039091160361163657600980546001600160a01b0319908116909155600880543392811683179091556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3005b63118cdaa760e01b5f523360045260245ffd5b34610395575f36600319011261039557600f54604080516001600160a01b038316815260a09290921c6001600160401b0316602083015290f35b34610395576020366003190112610395576004356001600160401b03811161039557366023820112156103955780600401356001600160401b0381116103955736602460c083028401011161039557335f52600b60205260ff60405f2054161580611a77575b80611a62575b611a53575f918290815b83831015611a3c5760c083028201906023198236030160c08112610395576040519060408201908282106001600160401b03831117610a695760a091604052126103955760a060405161174b81612be1565b61175760248601612b9d565b815261176560448601612b9d565b602082015261177660648601612b9d565b604082015261178760848601612b9d565b606082015260a4850135608082015280835260c46020840195013585522092835f52600d60205260ff60405f205460b81c1615611a29576117c9848351613a3d565b5082518083118184030294929085156118e95750505f9251156118de575b5051604051635c2bea4960e01b81529290611806906004850190612f26565b60a483015260c48201523060e48201819052610104820152604081610124815f7f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc6001600160a01b03165af1918215610b50576001936118a1935f935f916118aa575b506040519084825260208201527fdd8bf5226dff861316e0fa7863fdb7dc7b87c614eb29a135f524eb79d5a1189a60403392a3612f03565b925b01916116f9565b90506118ce91935060403d81116118d7575b6118c68183612c17565b810190612f10565b9290928a611869565b503d6118bc565b5f93509150896117e7565b9293509497999350505f1981145f14611a1c575081860382871102925b8315611a0e575f858152600d60205260409020546001600160b81b03169061192f908590612f03565b116119fb5790604061195993925181518095819263a99aad8960e01b835286309160048501612f65565b03815f7f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc6001600160a01b03165af1938415610b50576001946119d5945f916119db575b506040519084825260208201527f89bf199df65bf65155e3e0a8abc4ad4a1be606220c8295840dba2ab5656c1f6d60403392a3612f03565b946118a3565b6119f3915060403d81116118d7576118c68183612c17565b90508a61199d565b83635e25afa560e01b5f5260045260245ffd5b5050959050600191506118a3565b8380820391110292611906565b83636113d8c760e01b5f5260045260245ffd5b8403611a4457005b6309e36b8960e41b5f5260045ffd5b63f7137c0f60e01b5f5260045ffd5b506008546001600160a01b03163314156116ef565b50600a546001600160a01b03163314156116e9565b3461039557602036600319011261039557600435611aa861324b565b600e548082146104775760115460c01c6111a657621275008211611b6757620151808210611b585780821115611ae2575061074b90613979565b601180546001600160c01b0319166001600160b81b0384161790557fb3aa0ade2442acf51d06713c2d1a5a3ec0373cce969d42b53f4689f97bccf38091602091611b2c9042612f03565b601180546001600160c01b031660c09290921b6001600160c01b031916919091179055604051908152a1005b631a1593df60e11b5f5260045ffd5b6346fedb5760e01b5f5260045ffd5b34610395575f36600319011261039557611b8e61324b565b600980546001600160a01b03199081169091556008805491821690555f906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b34610395576020366003190112610395576001600160a01b03611bfc612b71565b165f525f602052602060405f2054604051908152f35b346103955760a036600319011261039557611c2c36612c38565b60a081205f52601060205260405f205460c01c8015611067574210611058578060a061074b9220805f52601060205260018060b81b0360405f2054169161345e565b3461039557604036600319011261039557602060043561062a611c8f612b87565b611c9761378c565b611ca7600254601654908561386f565b928391336138b4565b3461039557602036600319011261039557600435611ccc61324b565b6012546001600160601b0381168214610477576706f05b59d3b200008211611d5b578115159081611d4f575b50610516576001600160601b0390611d0e61378c565b16806001600160601b031960125416176012556040519081527f01fe2943baee27f47add82886c2200f910c749c461c9b63c5fe83901a53bdb4960203392a2005b905060601c1582611cf8565b63f4df6ae560e01b5f5260045ffd5b346103955760203660031901126103955760043560155481101561039557610386602091612cb9565b34610395575f366003190112610395576020601654604051908152f35b34610395576020366003190112610395576001600160a01b03611dd1612b71565b165f52600b602052602060ff60405f2054166040519015158152f35b612b48565b346103955760203660031901126103955760043560018060a01b03600c541633141580611e8a575b80611e75575b611e66575f818152600d6020526040812080546001600160c01b0316905533907fcbeb8ecdaa5a3c133e62219b63bfc35bce3fda13065d2bed32e3b7dde60a59f49080a3005b63d080fa3160e01b5f5260045ffd5b506008546001600160a01b0316331415611e20565b50600a546001600160a01b0316331415611e1a565b34610395575f36600319011261039557602060125460601c604051908152f35b34610395575f36600319011261039557600c546040516001600160a01b039091168152602090f35b34610395576020366003190112610395576004356001600160401b03811161039557611f17903690600401612bb1565b90335f52600b60205260ff60405f2054161580612237575b80612222575b611a5357601554611f4581612ecb565b611f526040519182612c17565b818152601f19611f6183612ecb565b01366020830137611f7184612ecb565b92611f7f6040519485612c17565b848452611f8b85612ecb565b602085019590601f19013687375f5b8181106121c2575050505f5b8281106120c35750505080516001600160401b038111610a6957600160401b8111610a69576015548160155580821061207f575b508260155f525f5b82811061204b5750505060405190602082019060208352518091526040820192905f5b81811061203557337fe0c2db6b54586be6d7d49943139fccf0dd315ba63e55364a76c73cd8fdba724d85870386a2005b8251855260209485019490920191600101612005565b60019060208351930192817f55f448fdea98c4d29eb340757ef0a66cd03dbb9538908a6a81d96026b71ec475015501611fe2565b60155f527f55f448fdea98c4d29eb340757ef0a66cd03dbb9538908a6a81d96026b71ec4759081019082015b8181106120b85750611fda565b5f81556001016120ab565b6120cd8183612eef565b51156120dc575b600101611fa6565b6120e581612cb9565b905460039190911b1c5f818152600d60205260409020546001600160b81b03166121b057805f52601060205260405f205460c01c6115045761214830827f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc6136d4565b612160575b5f908152600d60205260408120556120d4565b805f52600d60205260405f205460c01c1561219e57805f52600d60205260405f205460c01c42101561214d57632cd5119960e21b5f5260045260245ffd5b63af8ae28760e01b5f5260045260245ffd5b63401d83d960e11b5f5260045260245ffd5b6121cd818385612ea8565b356121d781612cb9565b90549060031b1c906121e98187612eef565b5161220f579060016121fd81949388612eef565b526122088289612eef565b5201611f9a565b506392a726c360e01b5f5260045260245ffd5b506008546001600160a01b0316331415611f35565b50600a546001600160a01b0316331415611f2f565b3461039557602036600319011261039557612265612b71565b50602061062a61361c565b346103955760c03660031901126103955761228a36612c38565b60a4359060018060a01b03600a5416331415806124e4575b6115365760a0812081519092906001600160a01b039081167f000000000000000000000000203a662b0bd271a6ed5a60edfbd04bfce608fd36909116036124d15760405160208101908482526003604082015260408152612304606082612c17565b519020600281018091116124bd575f61231f6123399261416d565b60405180938192637784c68560e01b8352600483016133f4565b03817f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc6001600160a01b03165afa908115610b50576001600160801b0391612388915f9161249b575b50612ee2565b51161561248c57825f52601060205260405f205460c01c6111a657825f52600d60205260405f205460c01c61247d575f838152600d60205260409020546001600160b81b0316818114610477578110156123ef57916123e961074b9361342d565b9161345e565b9050815f52601060205261244f60405f206001600160401b036124306124148561342d565b600e549060018060b81b03168360c01b85541617845542612f03565b82546001600160c01b0316911660c01b6001600160c01b031916179055565b6040519081527fe851bb5856808a50efd748be463b8f35bcfb5ec74c5bfde776fe0a4d2a26db2760203392a3005b6325f600a360e11b5f5260045ffd5b6396e1352960e01b5f5260045ffd5b6124b791503d805f833e6124af8183612c17565b81019061337b565b86612382565b634e487b7160e01b5f52601160045260245ffd5b826333cbfd2760e21b5f5260045260245ffd5b506008546001600160a01b03163314156122a2565b34610395575f366003190112610395576040517f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc6001600160a01b03168152602090f35b34610395575f366003190112610395576040517f000000000000000000000000203a662b0bd271a6ed5a60edfbd04bfce608fd366001600160a01b03168152602090f35b34610395575f366003190112610395576013546040516001600160a01b039091168152602090f35b34610395575f36600319011261039557602061062a61325f565b34610395575f366003190112610395576020601554604051908152f35b34610395575f3660031901126103955760ff7f000000000000000000000000000000000000000000000000000000000000000c1660ff7f0000000000000000000000000000000000000000000000000000000000000006160160ff81116124bd5760209060ff60405191168152f35b3461039557602036600319011261039557612668612b71565b61267061324b565b6013546001600160a01b039182169181168214610477576001600160a01b03191681176013557f2e7908865670e21b9779422cadf5f1cba271a62bb95c71eaaf615c0a1c48ebee5f80a2005b34610395576020366003190112610395576004356001600160401b038111610395576126ec903690600401612bb1565b335f52600b60205260ff60405f205416158061289d575b80612888575b611a5357601e8111612879575f5b81811061282c57506001600160401b038111610a6957600160401b8111610a6957601454816014558082106127e8575b508160145f525f5b8281106127b457505060405190806020830160208452526040820192905f5b81811061279e57337f6ce31538fc7fba95714ddc8a275a09252b4b1fb8f33d2550aa58a5f62ad934de85870386a2005b823585526020948501949092019160010161276e565b60019060208335930192817fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec01550161274f565b60145f527fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec9081019082015b8181106128215750612747565b5f8155600101612814565b612837818385612ea8565b355f908152600d60205260409020546001600160b81b03161561285c57600101612717565b9061286692612ea8565b3563067f0a2560e41b5f5260045260245ffd5b6340797bd760e11b5f5260045ffd5b506008546001600160a01b0316331415612709565b50600a546001600160a01b0316331415612703565b346103955760603660031901126103955761100f6128ce612b71565b6128d6612b87565b604435916128e58333836130c8565b61318e565b34610395575f366003190112610395576020601754604051908152f35b34610395575f366003190112610395576008546001600160a01b03163314158061295b575b610859575f600f55337fc40a085ccfa20f5fd518ade5c3a77a7ecbdfbb4c75efcdca6146a8e3c841d6635f80a2005b50600c546001600160a01b031633141561292c565b34610395575f366003190112610395576020600254604051908152f35b346103955760203660031901126103955760043560018060a01b03600c541633141580612a09575b806129f4575b611e6657805f5260106020525f6040812055337f1026ceca5ed3747eb5edec555732d4a6f901ce1a875ecf981064628cadde11205f80a3005b506008546001600160a01b03163314156129bb565b50600a546001600160a01b03163314156129b5565b3461039557602036600319011261039557602061062a612a3f610d9b612fad565b600435613829565b346103955760403660031901126103955761100f612a63612b71565b602435903361410a565b34610395575f366003190112610395576040515f601854612a8d81612def565b80845290600181169081156112485750600114612ab4576110b98361094b81850382612c17565b60185f9081525f80516020614c9d833981519152939250905b808210612ae55750909150810160200161094b6111ed565b919260018160209254838588010152019101909291612acd565b34610395575f366003190112610395576020612b19612fad565b509050604051908152f35b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b3461039557602036600319011261039557602061062a612b69610d9b612fad565b600435613bc5565b600435906001600160a01b038216820361039557565b602435906001600160a01b038216820361039557565b35906001600160a01b038216820361039557565b9181601f84011215610395578235916001600160401b038311610395576020808501948460051b01011161039557565b60a081019081106001600160401b03821117610a6957604052565b60c081019081106001600160401b03821117610a6957604052565b90601f801991011681019081106001600160401b03821117610a6957604052565b60a09060031901126103955760405190612c5182612be1565b816004356001600160a01b03811681036103955781526024356001600160a01b03811681036103955760208201526044356001600160a01b03811681036103955760408201526064356001600160a01b03811681036103955760608201526080608435910152565b601554811015612cd15760155f5260205f2001905f90565b634e487b7160e01b5f52603260045260245ffd5b601454811015612cd15760145f5260205f2001905f90565b606090600319011261039557600435906024356001600160a01b038116810361039557906044356001600160a01b03811681036103955790565b6001600160401b038111610a6957601f01601f191660200190565b929192612d5e82612d37565b91612d6c6040519384612c17565b829481845281830111610395578281602093845f960137010152565b602060031982011261039557600435906001600160401b038211610395578060238301121561039557816024612dc393600401359101612d52565b90565b3461039557602036600319011261039557602061062a612de7610d9b612fad565b60043561386f565b90600182811c92168015612e1d575b6020831014612e0957565b634e487b7160e01b5f52602260045260245ffd5b91607f1691612dfe565b5f9291815491612e3683612def565b8083529260018116908115612e8b5750600114612e5257505050565b5f9081526020812093945091925b838310612e71575060209250010190565b600181602092949394548385870101520191019190612e60565b915050602093945060ff929192191683830152151560051b010190565b9190811015612cd15760051b0190565b818102929181159184041417156124bd57565b6001600160401b038111610a695760051b60200190565b805115612cd15760200190565b8051821015612cd15760209160051b010190565b919082018092116124bd57565b9190826040910312610395576020825192015190565b80516001600160a01b03908116835260208083015182169084015260408083015182169084015260608083015190911690830152608090810151910152565b91612f74836101409593612f26565b60a08301525f60c083015260018060a01b031660e08201526101206101008201525f6101208201520190565b919082039182116124bd57565b5f905f806015547f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc5b8183106130755750505060165491601754612ff18185612fa0565b83101561306757506130176130106130098486612fa0565b8094612f03565b9384612fa0565b80151580613053575b6130275750565b613050919450613043906001600160601b036012541690613fe4565b6002546106248286612fa0565b92565b506001600160601b03601254161515613020565b613010613017918094612f03565b9091926130bf6001916130b961309961308d88612cb9565b90549060031b1c613eca565b6130b16130aa3060a08420896136d4565b91876141e5565b5050916147a0565b90612f03565b93019190612fd6565b6001600160a01b039081165f81815260016020818152604080842095871684529490529290205493929184016130ff575b50505050565b82841061316b578015613158576001600160a01b03821615613145575f52600160205260405f209060018060a01b03165f5260205260405f20910390555f8080806130f9565b634a1406b160e11b5f525f60045260245ffd5b63e602df0560e01b5f525f60045260245ffd5b508290637dc7a0d960e11b5f5260018060a01b031660045260245260445260645ffd5b6001600160a01b0316908115613238576001600160a01b031691821561322557815f525f60205260405f205481811061320c57817fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92602092855f525f84520360405f2055845f525f825260405f20818154019055604051908152a3565b8263391434e360e21b5f5260045260245260445260645ffd5b63ec442f0560e01b5f525f60045260245ffd5b634b637e8f60e11b5f525f60045260245ffd5b6008546001600160a01b0316330361163657565b307f00000000000000000000000061d4f9d3797ba4da152238c53a6f93fb665c3c1d6001600160a01b03161480613352575b156132ba577f2645b98ff06356db609c2b676cf1b3a2c7abc2ae914fd83eee51ede42b9f97e990565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47060408201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260a0815261334c60c082612c17565b51902090565b507f00000000000000000000000000000000000000000000000000000000000b67d24614613291565b602081830312610395578051906001600160401b03821161039557019080601f830112156103955781516133ae81612ecb565b926133bc6040519485612c17565b81845260208085019260051b82010192831161039557602001905b8282106133e45750505090565b81518152602091820191016133d7565b60206040818301928281528451809452019201905f5b8181106134175750505090565b825184526020938401939092019160010161340a565b6001600160b81b038111613447576001600160b81b031690565b6306dfcc6560e41b5f5260b860045260245260445ffd5b5f828152600d6020526040902093926001600160b81b031690816134d0575b508192938168ffffffffffffffffff60b81b8254161790556040519081527fe86b6d3313d3098f4c5f689c935de8fde876a597c185def2cedab85efedac68660203392a35f5260106020525f6040812055565b60ff855460b81c16156134f2575b5083546001600160c01b031684558161347d565b601554600160401b811015610a69578060016135119201601555612cb9565b81549060031b9085821b915f19901b1916179055601e601554116128795761358761358c91600160b81b60ff60b81b198854161787556130b9601654916130b17f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc916135813060a08320856136d4565b926141e5565b614194565b604051936020850160208652601554809152604086019060155f527f55f448fdea98c4d29eb340757ef0a66cd03dbb9538908a6a81d96026b71ec475905f5b818110613606575050507fe0c2db6b54586be6d7d49943139fccf0dd315ba63e55364a76c73cd8fdba724d8685969733930390a293926134de565b82548452602090930192600192830192016135cb565b5f905f6014547f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc5b81831061365057505050565b90919361365c85612ce5565b905460039190911b1c5f818152600d60205260409020546001600160b81b03169081156136c957916136bf916136b36001946136ab6136a561369f30848b6136d4565b92613eca565b886141e5565b5050916144cd565b80820391110290612f03565b945b019190613644565b5050936001906136c1565b61372f61374b935f936040516020810191825260026040820152604081526136fd606082612c17565b51902060405190602082019260018060a01b03168352604082015260408152613727606082612c17565b51902061416d565b906040518080958194637784c68560e01b8352600483016133f4565b03916001600160a01b03165afa8015610b505761376e915f916137725750612ee2565b5190565b61378691503d805f833e6124af8183612c17565b5f612382565b7ff66f28b40975dbb933913542c7e6a0f50a1d0f20aa74ea6e0efe65ab616323ec60407f548669ea9bcc24888e6d74a69c9865fa98d795686853b8aa3eb87814261bbb7160206137da612fad565b6137e78295939492614194565b806017558551908152a180613804575b82519182526020820152a1565b6138138160125460601c61450c565b6137f7565b60ff16604d81116124bd57600a0a90565b90613857906130b97f000000000000000000000000000000000000000000000000000000000000000c613818565b91600181018091116124bd57612dc392600192614569565b9061389d906130b97f000000000000000000000000000000000000000000000000000000000000000c613818565b91600181018091116124bd57612dc3925f92614569565b92613977937fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7604061358795946139448251946323b872dd60e01b602087015260018060a01b0316948560248201523060448201528760648201526064815261391e608482612c17565b7f000000000000000000000000203a662b0bd271a6ed5a60edfbd04bfce608fd366149ed565b61394e858261450c565b815186815260208101959095526001600160a01b031693a361396f816145b9565b601654612f03565b565b80600e556040519081527fd28e9b90ee9b37c5936ff84392d71f29ff18117d7e76bcee60615262a90a3f7560203392a25f601155565b51906001600160801b038216820361039557565b908160c091031261039557613a3560a0604051926139e084612bfc565b6139e9816139af565b84526139f7602082016139af565b6020850152613a08604082016139af565b6040850152613a19606082016139af565b6060850152613a2a608082016139af565b6080850152016139af565b60a082015290565b905f915f60a0604051613a4f81612bfc565b82815282602082015282604082015282606082015282608082015201527f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc9060018060a01b03821690813b1561039557604051630a8e0d6f60e11b815290613abb906004830190612f26565b5f8160a48183865af18015610b5057613b6b575b5060c060249160405192838092632e3071cd60e11b82528760048301525afa938415613b5f5793613b26575b50613b0c61305091849330916136d4565b926001600160801b036020818351169201511690846147a0565b613050919350613b50613b0c9160c03d60c011613b58575b613b488183612c17565b8101906139c3565b939150613afb565b503d613b3e565b604051903d90823e3d90fd5b613b789194505f90612c17565b5f9260c0613acf565b600183018093116124bd57612dc392613bbf6001936130b97f000000000000000000000000000000000000000000000000000000000000000c613818565b91614569565b600183018093116124bd57612dc392613bbf5f936130b97f000000000000000000000000000000000000000000000000000000000000000c613818565b600c80546001600160a01b0319166001600160a01b03929092169182179055337fcb11cc8aade2f5a556749d1b2380d108a16fac3431e6a5d5ce12ef9de0bd76e35f80a35f600f55565b3d15613c76573d90613c5d82612d37565b91613c6b6040519384612c17565b82523d5f602084013e565b606090565b9193613c8f60165485808203911102614194565b613c98846148bb565b6001600160a01b0385811695908416938290878603613d8f575b505050841561323857845f525f60205260405f2054818110613d765791816040927ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db94885f525f60205203835f205580600254036002555f877fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60208651858152a3613d5f86837f000000000000000000000000203a662b0bd271a6ed5a60edfbd04bfce608fd36613da0565b825195865260208601526001600160a01b031693a4565b8563391434e360e21b5f5260045260245260445260645ffd5b613d98926130c8565b5f8181613cb2565b60405163a9059cbb60e01b60208201526001600160a01b03909216602483015260448083019390935291815261397791613ddb606483612c17565b6149ed565b613e1590613dec612fad565b50613dfb819492600254612f03565b9260018060a01b03165f525f6020528260405f2054613bc5565b6015549290805f7f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc5b868210613e54575b505061305092939450612fa0565b9092613e9b613e6285612cb9565b90549060031b1c613e95613e81613e7883613eca565b923090876136d4565b613e8b83876141e5565b50939180936147a0565b92614bef565b808203911102928315613eb15760010190613e3e565b613e46565b51906001600160a01b038216820361039557565b5f6080604051613ed981612be1565b828152826020820152826040820152826060820152015260405190632c3c915760e01b8252600482015260a081602481600180851b037f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc165afa908115610b50575f91613f44575090565b905060a0813d60a011613fbe575b81613f5f60a09383612c17565b8101031261039557608060405191613f7683612be1565b613f7f81613eb6565b8352613f8d60208201613eb6565b6020840152613f9e60408201613eb6565b6040840152613faf60608201613eb6565b60608401520151608082015290565b3d9150613f52565b8115613fd0570490565b634e487b7160e01b5f52601260045260245ffd5b9190915f838202915f19858209918380841093039280840393146140635782670de0b6b3a7640000111561405457507faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106699394670de0b6b3a7640000910990828211900360ee1b910360121c170290565b63227bc15360e01b8152600490fd5b505050670de0b6b3a76400009192500490565b9091828202915f19848209938380861095039480860395146140fd57848311156140ee57829109815f0382168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b63227bc15360e01b5f5260045ffd5b505090612dc39250613fc6565b6001600160a01b0316908115613158576001600160a01b03169182156131455760207f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591835f526001825260405f20855f5282528060405f2055604051908152a3565b6040519061417c604083612c17565b600182526020368184013761419082612ee2565b5290565b60207f15c027cc4fd826d986cad358803439f7326d3aa4ed969ff90dbee4bc150f68e99180601655604051908152a1565b906001600160801b03809116911601906001600160801b0382116124bd57565b9060c060a08220602460405180958193632e3071cd60e11b8352600483015260018060a01b03165afa918215610b50575f926144ac575b50608082016142356001600160801b0382511642612fa0565b9182151580614496575b80614480575b614283575b5050506001600160801b038151166001600160801b03602083015116926001600160801b03606081604086015116940151169193929190565b6060810151604051638c00bf6b60e01b8152916001600160a01b03909116906142b0906004840190612f26565b6001600160801b0385511660a483015260208501936001600160801b0385511660c48401526001600160801b0360408701948186511660e48601528160608901511661010486015251166101248401526020836101648160a08a01956001600160801b038751166101448301525afa928315610b50575f9361444a575b506143906001600160801b039361438a614354670de0b6b3a7640000948789511693612eb8565b614385671bc16d674ec8000061436a8380612eb8565b046729a2241af62c000061437e8483612eb8565b0492612f03565b612f03565b90612eb8565b0492826143a861439f86614b7d565b828451166141c5565b169052816143c16143b885614b7d565b828851166141c5565b168552511690811561424a57670de0b6b3a7640000916143e091612eb8565b046143f5816001600160801b03855116612fa0565b6001600160801b0383511691620f424083018093116124bd57600182018092116124bd5761443a61443f926144356001600160801b039561439f94612eb8565b613fc6565b614b7d565b1690525f808061424a565b92506020833d602011614478575b8161446560209383612c17565b810103126103955791519161439061432d565b3d9150614458565b5060608101516001600160a01b03161515614245565b506001600160801b03604085015116151561423f565b6144c691925060c03d60c011613b5857613b488183612c17565b905f61421c565b90600181018091116124bd57620f42408301918284116124bd57620f423f916144f591612eb8565b9201918183116124bd57612dc39261443591612f03565b6001600160a01b0316908115613225577fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60208261454d5f94600254612f03565b60025584845283825260408420818154019055604051908152a3565b9190600180614579848487614076565b9561458381614ae3565b161492836145a4575b5050506145965790565b600181018091116124bd5790565b909180935015613fd0570915155f808061458c565b7f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc906001600160a01b0382165f5b601454811015614787576145fa81612ce5565b905460039190911b1c5f818152600d60205260409020546001600160b81b0316801561477d5761462982613eca565b91843b1561039557604051630a8e0d6f60e11b815261464b6004820185612f26565b5f8160a481838a5af18015610b505761476d575b50604051632e3071cd60e11b8152600481018290529060c082602481895afa908115610b50576146b6925f92614749575b5061469d9030908a6136d4565b906001600160801b0360208183511692015116916144cd565b808203911102908185108583180280831892036146e0575b505082156130f9576001905b016145e7565b60406147029181518093819263a99aad8960e01b835286309160048501612f65565b03815f885af1908161472c575b5061471b575b806146ce565b6147259193612fa0565b915f614715565b6147439060403d81116118d7576118c68183612c17565b5061470f565b61469d9192506147669060c03d8111613b5857613b488183612c17565b9190614690565b5f61477791612c17565b5f61465f565b50506001906146da565b5050905061479157565b63ded0652d60e01b5f5260045ffd5b60018201929183106124bd57620f424082018092116124bd57612dc39261443591612eb8565b60ff811461480c5760ff811690601f82116147fd57604051916147ea604084612c17565b6020808452838101919036833783525290565b632cd44ac360e21b5f5260045ffd5b50604051612dc38161481f816005612e27565b0382612c17565b60ff811461484a5760ff811690601f82116147fd57604051916147ea604084612c17565b50604051612dc38161481f816006612e27565b90614881575080511561487257805190602001fd5b630a12f52160e11b5f5260045ffd5b815115806148b2575b614892575090565b639996b31560e01b5f9081526001600160a01b0391909116600452602490fd5b50803b1561488a565b5f5b6015548110156149d7576148d081612cb9565b90549060031b1c6149086148ed6148e683613eca565b9283613a3d565b90506001600160801b03604081835116920151169084614bef565b9081841084831802808318920361492e575b5050811561492a576001016148bd565b5050565b604051635c2bea4960e01b81529061494a906004830190612f26565b8160a48201525f60c48201523060e482015230610104820152604081610124815f60018060a01b037f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc165af190816149ba575b506149a9575b8061491a565b6149b39192612fa0565b905f6149a3565b6149d19060403d81116118d7576118c68183612c17565b5061499d565b506149de57565b634323a55560e01b5f5260045ffd5b5f80614a159260018060a01b03169360208151910182865af1614a0e613c4c565b908361485d565b8051908115159182614a3d575b5050614a2b5750565b635274afe760e01b5f5260045260245ffd5b81925090602091810103126103955760200151801590811503610395575f80614a22565b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411614ad8579160209360809260ff5f9560405194855216868401526040830152606082015282805260015afa15610b50575f516001600160a01b03811615614ace57905f905f90565b505f906001905f90565b5050505f9160039190565b60041115614aed57565b634e487b7160e01b5f52602160045260245ffd5b614b0a81614ae3565b80614b13575050565b614b1c81614ae3565b60018103614b335763f645eedf60e01b5f5260045ffd5b614b3c81614ae3565b60028103614b57575063fce698f760e01b5f5260045260245ffd5b600390614b6381614ae3565b14614b6b5750565b6335e2f38360e21b5f5260045260245ffd5b604051614b8b604082612c17565b60148152731b585e081d5a5b9d0c4c8e08195e18d95959195960621b60208201526001600160801b038211614bc757506001600160801b031690565b60405162461bcd60e51b815260206004820152908190614beb906024830190612b24565b0390fd5b91614bfe602091602493612fa0565b92516040516370a0823160e01b81526001600160a01b037f000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc811660048301529093849290918391165afa908115610b50575f91614c6a575b508181109082180218818110908218021890565b90506020813d602011614c94575b81614c8560209383612c17565b8101031261039557515f614c56565b3d9150614c7856feb13d2d76d1f4b7be834882e410b3e3a8afaf69f83600ae24db354391d2378d2e944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c9695a164736f6c634300081a000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000e6fc2a011153dd5a230725a9f0c89a9c81ab4887000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000203a662b0bd271a6ed5a60edfbd04bfce608fd3600000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000015537465616b686f757365205072696d65205553444300000000000000000000000000000000000000000000000000000000000000000000000000000000000009737465616b555344430000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : owner (address): 0xe6FC2a011153DD5a230725a9F0c89a9c81aB4887
Arg [1] : morpho (address): 0xD50F2DffFd62f94Ee4AEd9ca05C61d0753268aBc
Arg [2] : initialTimelock (uint256): 0
Arg [3] : _asset (address): 0x203A662b0BD271A6ed5a60EdFbd04bFce608FD36
Arg [4] : __name (string): Steakhouse Prime USDC
Arg [5] : __symbol (string): steakUSDC
-----Encoded View---------------
10 Constructor Arguments found :
Arg [0] : 000000000000000000000000e6fc2a011153dd5a230725a9f0c89a9c81ab4887
Arg [1] : 000000000000000000000000d50f2dfffd62f94ee4aed9ca05c61d0753268abc
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [3] : 000000000000000000000000203a662b0bd271a6ed5a60edfbd04bfce608fd36
Arg [4] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000100
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000015
Arg [7] : 537465616b686f757365205072696d6520555344430000000000000000000000
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000009
Arg [9] : 737465616b555344430000000000000000000000000000000000000000000000
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.