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

Removed drift check from Oracle Router and gas optimizations #1943

Open
wants to merge 5 commits into
base: nicka/oeth-oracle
Choose a base branch
from

Conversation

naddison36
Copy link
Collaborator

Changes

  • Removed the drift checks from the OracleRouter. Note the OETHOracleRouter does not do drift checks as its already done in the OETHVault.
  • Removed read of Oracle decimals from storage which saves close to 2k gas for stETH, rETH and frxETH. There is a slight increase in gas for WETH as it was not reading the Oracle decimals from storage.

Gas Testing

Before upgrade of OETHOracleRouter

|  Contract           ·  Method              ·  Min        ·  Max        ·  Avg        ·  # calls      ·  eur (avg)  │
······················|······················|·············|·············|·············|···············|··············
|  OETHOracleRouter   ·  price               ·      21935  ·      43431  ·      36034  ·            4  ·          -  │

WETH before

|  OETHOracleRouter   ·  price               ·          -  ·          -  ·      21935  ·            1  ·          -  │

stETH before

|  OETHOracleRouter   ·  price               ·          -  ·          -  ·      43387  ·            1  ·          -  │

After change

|  Contract           ·  Method              ·  Min        ·  Max        ·  Avg        ·  # calls      ·  eur (avg)  │
······················|······················|·············|·············|·············|···············|··············
|  OETHOracleRouter   ·  price               ·      21974  ·      41214  ·      34381  ·            4  ·          -  │

WETH after

|  OETHOracleRouter   ·  price               ·          -  ·          -  ·      21974  ·            1  ·          -  │

stETH after

|  OETHOracleRouter   ·  price               ·          -  ·          -  ·      41170  ·            1  ·          -  │

Review

If you made a contract change, make sure to complete the checklist below before merging it in master.

Refer to our documentation for more details about contract security best practices.

Contract change checklist:

  • Code reviewed by 2 reviewers.
  • Copy & paste code review security checklist below this checklist.
  • Unit tests pass
  • Slither tests pass with no warning
  • Echidna tests pass if PR includes changes to OUSD contract (not automated, run manually on local)

@naddison36 naddison36 added contracts Works related to contracts OETH OETH related things labels Nov 27, 2023
@rafaelugolini rafaelugolini temporarily deployed to preview-ousd-nicka-oeth-qrlaht November 27, 2023 10:42 Inactive
Copy link

Warnings
⚠️ 👀 This PR needs at least 2 reviewers

Generated by 🚫 dangerJS against 4bdf822

@DanielVF
Copy link
Member

Seems like a great idea.

Might be good to write some kind of test (even if a one off script) that verifies that the answers are the same before and after the upgraded.

@naddison36
Copy link
Collaborator Author

Seems like a great idea.

Might be good to write some kind of test (even if a one off script) that verifies that the answers are the same before and after the upgraded.

I added isDecimalsValid to the OracleRouter that validates the decimals returned from feedMetadata matches the decimals returned from the Oracle feed AggregatorV3Interface(_feed).decimals().
I check isDecimalsValid is true as part of the deploy script and have added checks to the fork tests.

Copy link
Member

@sparrowDom sparrowDom left a comment

Choose a reason for hiding this comment

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

I think this is a great idea, a nice gas savings, since the Oracle decimals should never change.

Left some comments inline

} else if (asset == 0xD533a949740bb3306d119CC777fa900bA034cd52) {
// https://data.chain.link/ethereum/mainnet/crypto-usd/crv-usd
// Chainlink: CRV/USD
feedAddress = 0xCd627aA160A6fA45Eb793D19Ef54f5062F20f33f;
maxStaleness = 1 days + STALENESS_BUFFER;
decimals = 18;
Copy link
Member

Choose a reason for hiding this comment

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

} else if (asset == 0xD533a949740bb3306d119CC777fa900bA034cd52) {
// https://data.chain.link/ethereum/mainnet/crypto-usd/crv-usd
// Chainlink: CRV/USD
feedAddress = 0xCd627aA160A6fA45Eb793D19Ef54f5062F20f33f;
maxStaleness = 1 days + STALENESS_BUFFER;
decimals = 18;
} else if (asset == 0x4e3FBD56CD56c3e72c1403e103b45Db9da5B9D2B) {
// Chainlink: CVX/USD
Copy link
Member

Choose a reason for hiding this comment

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

Cvx/USD is also 8 decimals:
https://etherscan.io/address/0xd962fc30a72a84ce50161031391756bf2876af5d#readContract

can you also add this link into the comment for easier verification (like in the above feeds):
https://data.chain.link/ethereum/mainnet/crypto-usd/cvx-usd

[assetAddresses.TUSD, oracleAddresses.chainlink.TUSD_USD, 8],
[assetAddresses.COMP, oracleAddresses.chainlink.COMP_USD, 8],
[assetAddresses.AAVE, oracleAddresses.chainlink.AAVE_USD, 8],
[assetAddresses.CRV, oracleAddresses.chainlink.CRV_USD, 18],
Copy link
Member

Choose a reason for hiding this comment

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

this should be 8 also

[assetAddresses.COMP, oracleAddresses.chainlink.COMP_USD, 8],
[assetAddresses.AAVE, oracleAddresses.chainlink.AAVE_USD, 8],
[assetAddresses.CRV, oracleAddresses.chainlink.CRV_USD, 18],
[assetAddresses.CVX, oracleAddresses.chainlink.CVX_USD, 18],
Copy link
Member

Choose a reason for hiding this comment

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

also 8

USDT: 8,
DAI: 8,
COMP: 8,
CVX: 18,
Copy link
Member

Choose a reason for hiding this comment

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

8 I think?

DAI: 8,
COMP: 8,
CVX: 18,
CRV: 18,
Copy link
Member

Choose a reason for hiding this comment

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

aslo 8 I think?

@sparrowDom
Copy link
Member

sparrowDom commented Nov 28, 2023

There is another issue with these changes. The currently implemented floorPrice of the VaultCore doesn't do any of its own checks of Oracle drift. The potential issue with the current implementation is that 1 underlying asset could de-peg: e.g. rEth to 0.2 worth of ETH, and an Oracle of another asset could be manipulated to return 1.8 ETH still totaling a floorPrice at 1. While in the current master a drift check at the 1.8 ETH price would fail since it exceedes the 1.3 ETH of maximum drift and prevent such situation.

We should probably utilize the _toUnitPrice by calling _toUnitPrice(asset, true) though that function might need changing since we don't want it to perform the require(price >= MINT_MINIMUM_UNIT_PRICE, "Asset price below peg"); part of the check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contracts Works related to contracts OETH OETH related things
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants