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

Feat/queue revamp #71

merged 21 commits into from
Sep 19, 2023

Conversation

Rubilmax
Copy link
Contributor

@Rubilmax Rubilmax commented Sep 18, 2023

This PR implements the latest specs on supply/withdraw queues. It relies on some definitions and invariants to verify execution is correct:

Definitions

  • a market is enabled as long as it has a non-zero cap OR the vault supplies liquidity on it
  • a market is hence disabled when it has a zero cap AND the vault doesn't supply any liquidity on it

Invariants

  1. supplyQueue stores any queue of markets: if the market has a zero cap, it is skipped ; if it doesn't, it is enabled and thus supplied to
  2. withdrawQueue only stores enabled markets and always stores them all

Invariant 2 is verified thanks to the way markets are enabled and the way the withdraw queue is managed:

  • when a market is enabled, it is necessarily pushed to the withdraw queue
  • changing the order of the withdraw queue is only performed via a permutation of enabled markets. By recursivity, withdrawQueue always contains all enabled markets

I let the reviewer prove that "changing the order of the withdraw queue is only performed via a permutation of enabled markets"!

Gas diff

  • Enabling a market
    • Before: required 2 txs (submitMarket + enableMarket = 350k)
    • After: requires a single tx (submitCap + acceptCap if timelock = 122k)
  • Disabling a market
    • Before: disableMarket (not tested)
    • After: submitCap(0) (122k)

@Rubilmax Rubilmax changed the base branch from main to perf/role-check September 18, 2023 20:28
@Rubilmax Rubilmax changed the base branch from perf/role-check to main September 18, 2023 20:28
@Rubilmax Rubilmax linked an issue Sep 18, 2023 that may be closed by this pull request
@Rubilmax Rubilmax marked this pull request as ready for review September 18, 2023 21:48
src/MetaMorpho.sol Outdated Show resolved Hide resolved
@Rubilmax Rubilmax marked this pull request as draft September 19, 2023 09:21
Copy link
Contributor

@MerlinEgalite MerlinEgalite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review but nice job!

src/interfaces/IMetaMorpho.sol Outdated Show resolved Hide resolved
src/MetaMorpho.sol Outdated Show resolved Hide resolved
src/MetaMorpho.sol Show resolved Hide resolved
src/MetaMorpho.sol Show resolved Hide resolved
src/MetaMorpho.sol Show resolved Hide resolved
src/MetaMorpho.sol Outdated Show resolved Hide resolved
src/MetaMorpho.sol Show resolved Hide resolved
src/MetaMorpho.sol Show resolved Hide resolved
src/MetaMorpho.sol Show resolved Hide resolved
@Rubilmax Rubilmax marked this pull request as ready for review September 19, 2023 11:12
src/MetaMorpho.sol Outdated Show resolved Hide resolved
src/MetaMorpho.sol Show resolved Hide resolved
src/MetaMorpho.sol Show resolved Hide resolved
src/MetaMorpho.sol Show resolved Hide resolved
src/MetaMorpho.sol Show resolved Hide resolved
src/MetaMorpho.sol Outdated Show resolved Hide resolved
@Rubilmax Rubilmax linked an issue Sep 19, 2023 that may be closed by this pull request
@Rubilmax Rubilmax merged commit 6720b65 into main Sep 19, 2023
6 checks passed
@Rubilmax Rubilmax deleted the feat/queue-revamp branch September 19, 2023 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment