Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/queue revamp #71

Merged
merged 21 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at 1d9650
2 changes: 1 addition & 1 deletion lib/morpho-blue
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
src/=src/
test/=test/

@forge-std/=lib/forge-std/src/
@morpho-blue/=lib/morpho-blue/src/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
412 changes: 229 additions & 183 deletions src/MetaMorpho.sol

Large diffs are not rendered by default.

57 changes: 51 additions & 6 deletions src/interfaces/IMetaMorpho.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,61 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.2;

import {MarketParams} from "@morpho-blue/interfaces/IMorpho.sol";
import {IMorpho, Id, MarketParams} from "@morpho-blue/interfaces/IMorpho.sol";
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";

struct Pending {
uint192 value;
uint64 submittedAt;
}

struct MarketConfig {
uint192 cap;
uint64 withdrawRank;
}

struct MarketAllocation {
MarketParams marketParams;
uint256 assets;
}

struct Pending {
uint128 value;
uint128 timestamp;
}
interface IMetaMorpho is IERC4626 {
function MORPHO() external view returns (IMorpho);

function isAllocator(address target) external view returns (bool);
function isRiskManager(address target) external view returns (bool);

interface IMetaMorpho {}
function fee() external view returns (uint96);
function feeRecipient() external view returns (address);
function timelock() external view returns (uint256);
function supplyQueue(uint256) external view returns (Id);
function withdrawQueue(uint256) external view returns (Id);
function config(Id) external view returns (uint192 cap, uint64 withdrawRank);

function idle() external view returns (uint256);
function lastTotalAssets() external view returns (uint256);

function submitTimelock(uint256 newTimelock) external;
function acceptTimelock() external;
function pendingTimelock() external view returns (uint192 value, uint64 submittedAt);

function submitCap(MarketParams memory marketParams, uint256 marketCap) external;
function acceptCap(Id id) external;
function pendingCap(Id) external view returns (uint192 value, uint64 submittedAt);

function submitFee(uint256 newFee) external;
function acceptFee() external;
function pendingFee() external view returns (uint192 value, uint64 submittedAt);

function setIsAllocator(address newAllocator, bool newIsAllocator) external;
function setIsRiskManager(address newRiskManager, bool newIsRiskManager) external;
function setFeeRecipient(address newFeeRecipient) external;

function setSupplyQueue(Id[] calldata newSupplyQueue) external;

/// @notice Changes the order of the withdraw queue, given a permutation.
/// @param indexes The permutation, mapping an Id's previous index in the withdraw queue to its new position in
/// `indexes`.
function sortWithdrawQueue(uint256[] calldata indexes) external;
function reallocate(MarketAllocation[] calldata withdrawn, MarketAllocation[] calldata supplied) external;
}
2 changes: 1 addition & 1 deletion src/interfaces/IMorphoMarketParams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pragma solidity >=0.6.2;
import {MarketParams, Id} from "@morpho-blue/interfaces/IMorpho.sol";

interface IMorphoMarketParams {
function idToMarketParams(Id id) external returns (MarketParams memory marketParams);
function idToMarketParams(Id id) external view returns (MarketParams memory marketParams);
}
16 changes: 0 additions & 16 deletions src/interfaces/ISupplyVault.sol

This file was deleted.

120 changes: 0 additions & 120 deletions src/libraries/ConfigSetLib.sol

This file was deleted.

8 changes: 6 additions & 2 deletions src/libraries/ConstantsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ pragma solidity ^0.8.0;

/// @dev The delay after a timelock ends after which the owner must submit a parameter again.
/// It guarantees users that the owner only accepts parameters submitted recently.
uint256 constant TIMELOCK_EXPIRATION = 2 days;
uint256 constant TIMELOCK_EXPIRATION = 3 days;

/// @dev The maximum delay of a timelock.
uint256 constant MAX_TIMELOCK = 2 weeks;

/// @dev OpenZeppelin's decimals offset used in MetaMorpho's ERC4626 implementation.
uint256 constant DECIMALS_OFFSET = 6;
uint8 constant DECIMALS_OFFSET = 6;

/// @dev The role assigned to risk managers. Must be greater than the allocator role.
uint256 constant RISK_MANAGER_ROLE = 2;

/// @dev The role assigned to allocators.
uint256 constant ALLOCATOR_ROLE = 1;

/// @dev The maximum supply/withdraw queue size ensuring the cost of depositing/withdrawing from the vault fits in a
/// block.
uint256 constant MAX_QUEUE_SIZE = 64;
12 changes: 5 additions & 7 deletions src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ library ErrorsLib {
/// @notice Thrown when the value is already set.
string internal constant ALREADY_SET = "already set";

string internal constant ENABLE_MARKET_FAILED = "enable market failed";
string internal constant DUPLICATE_MARKET = "duplicate market";

string internal constant DISABLE_MARKET_FAILED = "disable market failed";
string internal constant MISSING_MARKET = "missing market";

string internal constant INVALID_LENGTH = "invalid length";

string internal constant MARKET_NOT_ENABLED = "market not enabled";

string internal constant WITHDRAW_ORDER_FAILED = "withdraw order failed";
string internal constant WITHDRAW_FAILED_MORPHO = "withdraw failed on Morpho";

string internal constant MARKET_NOT_CREATED = "market not created";

Expand All @@ -35,4 +31,6 @@ library ErrorsLib {
string internal constant TIMELOCK_NOT_ELAPSED = "timelock not elapsed";

string internal constant TIMELOCK_EXPIRATION_EXCEEDED = "timelock expiration exceeded";

string internal constant MAX_QUEUE_SIZE_EXCEEDED = "max queue size exceeded";
}
18 changes: 7 additions & 11 deletions src/libraries/EventsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,23 @@ import {Id} from "@morpho-blue/interfaces/IMorpho.sol";
library EventsLib {
event SubmitTimelock(uint256 timelock);

event AcceptTimelock(uint256 timelock);
event SetTimelock(uint256 timelock);

event SetRole(address indexed target, uint256 role);

event SubmitFee(uint256 fee);

/// @notice Emitted when setting a new fee.
/// @param newFee The new fee.
event AcceptFee(uint256 newFee);
/// @param fee The new fee.
event SetFee(uint256 fee);

/// @notice Emitted when setting a new fee recipient.
/// @param newFeeRecipient The new fee recipient.
event SetFeeRecipient(address indexed newFeeRecipient);
/// @param feeRecipient The new fee recipient.
event SetFeeRecipient(address indexed feeRecipient);

event SubmitMarket(Id id);
event SubmitCap(Id id, uint256 cap);
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved

event EnableMarket(Id id, uint128 cap);

event SetCap(uint128 cap);

event DisableMarket(Id id);
event SetCap(Id id, uint256 cap);

/// @notice Emitted when the vault's last total assets is updated.
/// @param totalAssets The total amount of assets this vault manages.
Expand Down
2 changes: 1 addition & 1 deletion test/forge/ERC4626Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract ERC4626Test is BaseTest {
function setUp() public override {
super.setUp();

_submitAndEnableMarket(allMarkets[0], CAP);
_setCap(allMarkets[0], CAP);
}

function testMint(uint256 assets) public {
Expand Down
Loading
Loading