Skip to content

Commit

Permalink
Merge pull request #357 from morpho-org/post-cantina
Browse files Browse the repository at this point in the history
Post cantina
  • Loading branch information
MerlinEgalite authored Jan 2, 2024
2 parents 0b63c34 + 0e036c6 commit f5faa9c
Show file tree
Hide file tree
Showing 21 changed files with 324 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- uses: ./.github/actions/install-cache

- name: Run tests in ${{ matrix.type }} mode
run: yarn test:forge
run: yarn test:forge -vvv
env:
FOUNDRY_FUZZ_RUNS: ${{ matrix.fuzz-runs }}
FOUNDRY_FUZZ_MAX_TEST_REJECTS: ${{ matrix.max-test-rejects }}
Expand Down
1 change: 0 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
[submodule "lib/morpho-blue"]
path = lib/morpho-blue
url = https://github.com/morpho-org/morpho-blue
branch = chore/remove-remapping-context
[submodule "lib/universal-rewards-distributor"]
path = lib/universal-rewards-distributor
url = https://github.com/morpho-org/universal-rewards-distributor
Expand Down
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Those rewards can be transferred to the `skimRecipient`.
The vault's owner has the choice to distribute back these rewards to vault depositors however they want.
For more information about this use case, see the [Rewards](#rewards) section.

All actions that may be against users' interests (e.g. enabling a market with a high exposure, increasing the fee) are subject to a timelock of minimum 12 hours.
If set, the `guardian` can revoke the action during the timelock except for the fee increase.
All actions that may be against users' interests (e.g. enabling a market with a high exposure) are subject to a timelock of minimum 24 hours.
The `owner`, or the `guardian` if set, can revoke the action during the timelock.
After the timelock, the action can be executed by anyone.

### Roles
Expand All @@ -48,8 +48,8 @@ It can:
- Set the rewards recipient.
- Increase the timelock.
- [Timelocked] Decrease the timelock.
- [Timelocked with no possible veto] Set the performance fee (capped to 50%).
- [Timelocked] Set the guardian.
- Set the performance fee (capped at 50%).
- Set the fee recipient.

#### Curator
Expand All @@ -67,6 +67,7 @@ It can:
- After the timelock has elapsed, the allocator role is free to remove the market from the withdraw queue. The funds supplied to this market will be lost.
- If the market ever functions again, the allocator role can withdraw the funds that were previously lost.
- Revoke the pending cap of any market.
- Revoke the pending removal of any market.

#### Allocator

Expand All @@ -76,7 +77,7 @@ It can:

- Set the `supplyQueue` and `withdrawQueue`, i.e. decide on the order of the markets to supply/withdraw from.
- Upon a deposit, the vault will supply up to the cap of each Morpho Blue market in the `supplyQueue` in the order set.
- Upon a withdrawal, the vault will first withdraw from the idle supply and then withdraw up to the liquidity of each Morpho Blue market in the `withdrawalQueue` in the order set.
- Upon a withdrawal, the vault will withdraw up to the liquidity of each Morpho Blue market in the `withdrawQueue` in the order set.
- The `supplyQueue` only contains markets which cap has previously been non-zero.
- The `withdrawQueue` contains all markets that have a non-zero cap or a non-zero vault allocation.
- Instantaneously reallocate funds by supplying on markets of the `withdrawQueue` and withdrawing from markets that have the same loan asset as the vault's asset.
Expand All @@ -93,20 +94,22 @@ It can:
- Revoke the pending timelock.
- Revoke the pending guardian (which means it can revoke any attempt to change the guardian).
- Revoke the pending cap of any market.
- Revoke the pending removal of any market.

### Idle Supply

In some cases, the vault's curator or allocators may want to keep some funds "idle", to guarantee lenders that some liquidity can be withdrawn from the vault (beyond the liquidity of each of the vault's markets).

To achieve this, it is advised to allocate "idle" funds to any market on Morpho Blue having:
To achieve this, they can deposit in markets with `address(0)` as the oracle or the collateral, ensuring that these funds can't be borrowed.
They are thus guaranteed to be liquid; though they won't generate interest.
It is advised to use these canonical configurations for "idle" markets:

- The vault's asset as loan token.
- No collateral token (`address(0)`).
- An arbitrary IRM.
- An arbitrary oracle (`address(0)`).
- An arbitrary LLTV.
- `loanToken`: The vault's asset to be able to supply/withdraw funds.
- `collateralToken`: `address(0)` (not necessary since no funds will be borrowed on this market)
- `irm`: `address(0)` (Morpho Blue will skip the call to the IRM in this case, thus reducing the gas cost)
- `oracle`: `address(0)` (not necessary since no funds will be borrowed on this market)
- `lltv`: `0` (not necessary since no funds will be borrowed on this market)

Thus, these funds cannot be borrowed on Morpho Blue and are guaranteed to be liquid; though it won't generate interest.

Note that to allocate funds to this idle market, it is first required to enable its cap on MetaMorpho.
Enabling an infinite cap (`type(uint184).max`) will always allow users to deposit on the vault.
Expand Down
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fs_permissions = [
{ access = "read", path = "./config/"},
{ access = "read", path = "./lib/morpho-blue/out/"}
]
optimization_runs = 999999 # Etherscan does not support verifying contracts with more optimization runs.

[profile.default.rpc_endpoints]
mainnet = "https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}"
Expand Down
2 changes: 1 addition & 1 deletion lib/morpho-blue
Submodule morpho-blue updated 63 files
+51 −0 .github/workflows/certora.yml
+1 −1 .github/workflows/foundry.yml
+4 −0 .gitignore
+1 −1 README.md
+389 −0 certora/LICENSE
+287 −0 certora/README.md
+14 −0 certora/confs/AccrueInterest.conf
+9 −0 certora/confs/AssetsAccounting.conf
+9 −0 certora/confs/ConsistentState.conf
+13 −0 certora/confs/ExactMath.conf
+13 −0 certora/confs/Health.conf
+9 −0 certora/confs/LibSummary.conf
+9 −0 certora/confs/Liveness.conf
+14 −0 certora/confs/RatioMath.conf
+12 −0 certora/confs/Reentrancy.conf
+9 −0 certora/confs/Reverts.conf
+12 −0 certora/confs/Transfer.conf
+48 −0 certora/dispatch/ERC20NoRevert.sol
+42 −0 certora/dispatch/ERC20Standard.sol
+45 −0 certora/dispatch/ERC20USDT.sol
+6 −0 certora/gambit.conf
+92 −0 certora/harness/MorphoHarness.sol
+17 −0 certora/harness/MorphoInternalAccess.sol
+35 −0 certora/harness/TransferHarness.sol
+138 −0 certora/specs/AccrueInterest.spec
+126 −0 certora/specs/AssetsAccounting.spec
+294 −0 certora/specs/ConsistentState.spec
+123 −0 certora/specs/ExactMath.spec
+108 −0 certora/specs/Health.spec
+26 −0 certora/specs/LibSummary.spec
+386 −0 certora/specs/Liveness.spec
+184 −0 certora/specs/RatioMath.spec
+61 −0 certora/specs/Reentrancy.spec
+179 −0 certora/specs/Reverts.spec
+82 −0 certora/specs/Transfer.spec
+1 −1 foundry.toml
+1 −1 lib/forge-std
+48 −34 src/Morpho.sol
+3 −2 src/interfaces/IIrm.sol
+17 −14 src/interfaces/IMorpho.sol
+3 −0 src/libraries/ErrorsLib.sol
+10 −7 src/libraries/EventsLib.sol
+4 −3 src/libraries/SafeTransferLib.sol
+3 −0 src/libraries/SharesMathLib.sol
+1 −1 src/libraries/UtilsLib.sol
+6 −7 src/libraries/periphery/MorphoBalancesLib.sol
+9 −7 test/forge/BaseTest.sol
+1 −1 test/forge/helpers/SigUtils.sol
+12 −0 test/forge/integration/AccrueInterestIntegrationTest.sol
+17 −1 test/forge/integration/AuthorizationIntegrationTest.sol
+3 −3 test/forge/integration/BorrowIntegrationTest.sol
+5 −0 test/forge/integration/CallbacksIntegrationTest.sol
+22 −20 test/forge/integration/CreateMarketIntegrationTest.sol
+66 −4 test/forge/integration/LiquidateIntegrationTest.sol
+3 −2 test/forge/integration/OnlyOwnerIntegrationTest.sol
+12 −0 test/forge/integration/SupplyCollateralIntegrationTest.sol
+12 −0 test/forge/integration/SupplyIntegrationTest.sol
+1 −1 test/forge/integration/WithdrawCollateralIntegrationTest.sol
+5 −3 test/forge/invariant/MorphoInvariantTest.sol
+14 −0 test/forge/libraries/SafeTransferLibTest.sol
+31 −1 test/hardhat/Morpho.spec.ts
+0 −288 test/morpho_tests.tree
+1 −1 tsconfig.json
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "morpho-stack",
"description": "Morpho Stack Contracts",
"name": "metamorpho",
"description": "MetaMorpho",
"license": "GPL-2.0-or-later",
"version": "1.0.0",
"main": "lib/index.js",
Expand All @@ -27,17 +27,17 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/morpho-labs/morpho-stack.git"
"url": "git+https://github.com/morpho-org/metamorpho.git"
},
"author": {
"name": "Morpho Labs",
"email": "[email protected]",
"url": "https://github.com/morpho-labs"
},
"bugs": {
"url": "https://github.com/morpho-labs/morpho-stack/issues"
"url": "https://github.com/morpho-org/metamorpho/issues"
},
"homepage": "https://github.com/morpho-labs/morpho-stack#readme",
"homepage": "https://github.com/morpho-org/metamorpho#readme",
"dependencies": {
"ethers": "^6.7.1",
"ethers-maths": "^5.0.0",
Expand Down
Loading

0 comments on commit f5faa9c

Please sign in to comment.