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(readme): explaining the oracle creation from the factory #86

Merged
merged 14 commits into from
Mar 7, 2024
94 changes: 77 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Morpho Blue Oracles


Morpho Blue Oracles are contracts that can be used as oracles for markets on [Morpho Blue](https://github.com/morpho-org/morpho-blue).
The oracles implement the `IOracle` interface defined in [`IOracle.sol`](https://github.com/morpho-org/morpho-blue/blob/main/src/interfaces/IOracle.sol#L9): they return the price of 1 asset of collateral token quoted in 1 asset of loan token.

## ChainlinkOracle
## MorphoChainlinkOracleV2

The `ChainlinkOracle` is an oracle that uses Chainlink-compliant feeds to provide price data.
The `MorphoChainlinkOracleV2` is an oracle that uses Chainlink-interface-compliant feeds to provide price data.

This oracle handles the following cases among others (let's say that our pair is A/B):

tomrpl marked this conversation as resolved.
Show resolved Hide resolved
- A/B is a feed (typically, stETH/ETH).
- B/A is a feed (typically, ETH/USDC).
- A/C and B/C are feeds (typically, stETH/ETH and USDC/ETH).
Expand All @@ -18,32 +18,92 @@ This oracle handles the following cases among others (let's say that our pair is
- A/C and C/B are feeds (typically, WBTC/BTC and BTC/ETH).
- A'/C and B/C are feeds, and there is an exchange rate between A and A'. (typically A=sDAI and A'=DAI).
Copy link
Contributor

Choose a reason for hiding this comment

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

this has to be adapted


## Getting Started
## WstETH/stETH Exchange Rate Adapter

Install dependencies: `forge install`
A specific implementation, the `WstEthStEthExchangeRateChainlinkAdapter`, provides the exchange rate between wstETH and stETH.
tomrpl marked this conversation as resolved.
Show resolved Hide resolved

In a `.env` file, set `ETH_RPC_URL` to the URL of an Ethereum provider.
Deployed on Ethereum Mainnet, this adapter can be found on Ethereum Mainnet at the address [0x905b7dAbCD3Ce6B792D874e303D336424Cdb1421](https://etherscan.io/address/0x905b7dabcd3ce6b792d874e303d336424cdb1421#code).
tomrpl marked this conversation as resolved.
Show resolved Hide resolved

Run test: `forge test`
## MorphoChainlinkOracleV2Factory
tomrpl marked this conversation as resolved.
Show resolved Hide resolved

The `MorphoChainlinkOracleV2Factory` is a factory that deploys `MorphoChainlinkOracleV2` instances.

The factory facilitates the easy creation and indexing of `MorphoChainlinkOracleV2` oracles. This factory contract streamlines the process of deploying new oracles, catering to various market pairs without the need for deploying individual contracts manually for each pair.
tomrpl marked this conversation as resolved.
Show resolved Hide resolved

### Usage

The Ethereum Mainnet address of this factory is [0x3A7bB36Ee3f3eE32A60e9f2b33c1e5f2E83ad766](https://etherscan.io/address/0x3a7bb36ee3f3ee32a60e9f2b33c1e5f2e83ad766#code).

To create a new `MorphoChainlinkOracleV2` oracle using the factory, call the `createMorphoChainlinkOracleV2` function with the following parameters:

- `baseVault`: The ERC4626 token vault for the base asset.
- `baseVaultConversionSample`: A sample size for converting base vault units.
tomrpl marked this conversation as resolved.
Show resolved Hide resolved
- `baseFeed1`, `baseFeed2`: Chainlink-interface-compliant data feeds for the base asset.
- `baseTokenDecimals`: Decimal precision of the base asset.
- `quoteVault`: The ERC4626 token vault for the quote asset.
- `quoteVaultConversionSample`: A sample size for converting quote vault units.
tomrpl marked this conversation as resolved.
Show resolved Hide resolved
- `quoteFeed1`, `quoteFeed2`: Chainlink-interface-compliant data feeds for the quote asset.
- `quoteTokenDecimals`: Decimal precision of the quote asset.
- `salt`: A unique identifier to create deterministic addresses for deployed oracles.

## Deploy an Oracle
### Deploy an Oracle

For example, to deploy a `ChainlinkOracle` on the Ethereum mainnet for the sDAI/USDC market, run:
To deploy a `MorphoChainlinkOracleV2` on the Ethereum mainnet, use the `MorphoChainlinkOracleV2Factory` to create a new oracle.

```bash
forge create src/ChainlinkOracle.sol:ChainlinkOracle --constructor-args "0x83F20F44975D03b1b09e64809B757c47f942BEeA" "0xAed0c38402a5d19df6E4c03F4E2DceD6e29c1ee9" "0x0000000000000000000000000000000000000000" "0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6" "0x0000000000000000000000000000000000000000" "1000000000000000000" "18" "6" --rpc-url https://eth-mainnet.g.alchemy.com/v2/<alchemy-key> --from <deployer-address> --ledger
``````
Below are the arguments to fill for the creation of the WETH/USDT oracle:

And for the rETH/WETH market, run:
- `baseVault`: 0x0000000000000000000000000000000000000000,
- `baseVaultConversionSample`:1,
- `baseFeed1`: 0x0000000000000000000000000000000000000000,
- `baseFeed2`: 0x0000000000000000000000000000000000000000,
- `baseTokenDecimals`:18,
- `quoteVault`:0x0000000000000000000000000000000000000000,
- `quoteVaultConversionSample`:1,
- `quoteFeed1`: 0xEe9F2375b4bdF6387aa8265dD4FB8F16512A1d46,
- `quoteFeed2`: 0x0000000000000000000000000000000000000000,
- `quoteTokenDecimals`:6,
- `salt`: <user-defined value used to make the address unique>,
tomrpl marked this conversation as resolved.
Show resolved Hide resolved

```bash
forge create src/ChainlinkOracle.sol:ChainlinkOracle --constructor-args "0x0000000000000000000000000000000000000000" "0x536218f9E9Eb48863970252233c8F271f554C2d0" "0x0000000000000000000000000000000000000000" "0x0000000000000000000000000000000000000000" "0x0000000000000000000000000000000000000000" "1" "18" "18" --rpc-url https://eth-mainnet.g.alchemy.com/v2/<alchemy-key> --from <deployer-address> --ledger
```
and for the sDAI/USDC oracle:

- `baseVault`: 0x83f20f44975d03b1b09e64809b757c47f942beea,
- `baseVaultConversionSample`: 1e18,
- `baseFeed1`: 0xAed0c38402a5d19df6E4c03F4E2DceD6e29c1ee9,
- `baseFeed2`: 0x0000000000000000000000000000000000000000,
- `baseTokenDecimals`: 18,
- `quoteVault`: 0x0000000000000000000000000000000000000000,
- `quoteVaultConversionSample`: 1,
- `quoteFeed1`: 0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6,
- `quoteFeed2`: 0x0000000000000000000000000000000000000000,
- `quoteTokenDecimals`: 6,
- `salt`: <user-defined value used to make the address unique>,

and for the wstETH/ETH oracle:

- `baseVault`:0x0000000000000000000000000000000000000000,
- `baseVaultConversionSample`:1,
- `baseFeed1`:0x905b7dAbCD3Ce6B792D874e303D336424Cdb1421,
- `baseFeed2`:0x86392dC19c0b719886221c78AB11eb8Cf5c52812,
- `baseTokenDecimals`:18,
- `quoteVault`:0x0000000000000000000000000000000000000000,
- `quoteVaultConversionSample`:1,
- `quoteFeed1`:0x0000000000000000000000000000000000000000,
- `quoteFeed2`:0x0000000000000000000000000000000000000000,
- `quoteTokenDecimals`:18,
- `salt`: <user-defined value used to make the address unique>,

## Getting Started

Install dependencies: `forge install`

In a `.env` file, set `ETH_RPC_URL` to the URL of an Ethereum provider.

Run test: `forge test`

## Audits

All audits are stored in the [audits](./audits/)' folder.

## License

Morpho Blue Oracles are licensed under `GPL-2.0-or-later`, see [`LICENSE`](./LICENSE).
Morpho Blue Oracles are licensed under `GPL-2.0-or-later`, see [`LICENSE`](./LICENSE).
Loading