Giter Site home page Giter Site logo

morpho-blue-bundlers's Introduction

Morpho Blue Bundlers

Morpho Blue is a new lending primitive that offers better rates, high capital efficiency and extended flexibility to lenders & borrowers. morpho-blue-bundlers hosts the logic that builds alongside the core protocol like MetaMorpho and bundlers.

Structure

bundler-3

Each Bundler is a domain-specific abstract layer of contract that implements some functions that can be bundled in a single call by EOAs to a single contract. They all inherit from BaseBundler that enables bundling multiple function calls into a single multicall(bytes[] calldata data) call to the end bundler contract. Each chain-specific bundler is available under their chain-specific folder (e.g. ethereum).

Some chain-specific domains are also scoped to the chain-specific folder, because they are not expected to be used on any other chain (e.g. DAI and its specific permit function is only available on Ethereum - see EthereumPermitBundler).

User-end bundlers are provided in each chain-specific folder, instanciating all the intermediary domain-specific bundlers and associated parameters (such as chain-specific protocol addresses, e.g. EthereumBundlerV2).

Deployments

Getting Started

Install dependencies with yarn.

Run tests with yarn test:forge --chain <chainid> (chainid can be 1 or 8453).

Note that the EthereumBundlerV2 has been deployed with 80 000 optimizer runs. To compile contracts with the same configuration, run FOUNDRY_PROFILE=ethereumBundlerV2 forge b.

Audits

All audits are stored in the audits' folder.

License

Bundlers are licensed under GPL-2.0-or-later, see LICENSE.

morpho-blue-bundlers's People

Contributors

jean-grimal avatar julien-devatom avatar makcandrov avatar mathisgd avatar merlinegalite avatar pakim249cal avatar qgarchery avatar rubilmax avatar tomrpl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

morpho-blue-bundlers's Issues

`_initiator` can be set to `Morpho` with a callback

Example:

  1. Alice triggers bulker1 (sender = Alice)
  2. In a callback Morpho triggers bulker1 to call bulker2 (sender = Morpho)
  3. bulker1 delegate calls bulker2 (sender = Morpho)
  4. bulker2 sets _initiator as Morpho

Am I missing something? What are the consequences?

Remove oracles

We'll migrate oracles to periphery, but first let's merge everything into main to have all the last changes together

Should we create packages?

There will be different folders for differents use and personas

  • bundlers
  • MM
  • liquidation modules
  • borrowing modules
  • ?

What is the reason of having private functions?

/* PRIVATE */

    /// @dev Gives the max approval to the Blue contract to spend the given `asset` if not already approved.
    function _approveMaxBlue(address asset) private {
        if (ERC20(asset).allowance(address(this), address(BLUE)) == 0) {
            ERC20(asset).safeApprove(address(BLUE), type(uint256).max);
        }
    }

Missing oracle configuration

UniswapV3Oracle & Chainlink(L2)Oracle allow creating an oracle for the market C (collateral) / B (borrowable) from a feed providing the price of C in B. However, there is no contract that allows us to create one from a feed providing the price of B in C.

callBulker does not provide context to bulker on who is msg.sender

https://github.com/morpho-labs/morpho-blue-periphery/blob/c8eb91a67946410604912240f77734179a429caa/contracts/bulkers/BaseBulker.sol#L28

The bulker relies on locking an initiator to provide privileged access to certain function parameters, which doesn't seem to be passed through to other bulkers. It seems that initiator from a callBulker call would be the calling bulker itself. This potentially limits the use cases of bulkers calling other bulkers. Am I mistaken? @Rubilmax

Documentation to add

          So there are 4 features:
  1. Being able to supply all that's available before the callback
  2. Being able to supply all that's available during the callback
  3. Being able to supply a specific amount before the callback
  4. Being able to supply a specific amount during the callback

The former code handles 1,3
This change allows to handle 1,3,4, do we agree?
Do you have an alternative implementation in mind that can solve all 4 of these usecases?

Originally posted by @Rubilmax in morpho-org/morpho-blue-irm#27 (comment)

External functions from bundlers can be called by anyone

In order to protect users from unexpected behaviors of the bundlers, we may consider protecting external functions with onlySelf:

modifier onlySelf() {
  require(msg.sender == address(this));

  _;
}

However, this would not work with callbacks, because they are expected to be called by specific addresses. In all cases, we know they expected address to call callbacks (Morpho, Balancer, etc), so we can craft a similar, dedicated solution for each callback type

In any case, it doesn't threaten security because the bundler is expected to be stateless between txs

Remarks and questions on oracles

I'm going through the oracles and I have a few remarks and questions (I will add some along the way):

  1. it seems that we need to write each adapter logic twice (ChainlinkCollateralAdapter/ChainlinkBorrowableAdapter... ), and the oracles themselves (UniswapV3ChainlinkOracle/ChainlinkUniswapV3Oracle...). Did someone thought about a way to not do that ?

It seems that adapters don't need to be written twice at least. For the oracles I don't think that we have an elegant solution

Refactor oracle

Oracles have too much specific logic. We should rework a bit that to abstract each feed specificities.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.