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

[VEN-2516] Deploy weETH Oracle #175

Merged
merged 17 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"arrowParens": avoid,
"bracketSpacing": true,
"endOfLine": "auto",
"endOfLine": "lf",
"importOrder": ["module-alias/register", "<THIRD_PARTY_MODULES>", "^[./]"],
"importOrderParserPlugins": ["typescript"],
"importOrderSeparation": true,
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IAnkrBNB.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

interface IAnkrBNB {
function sharesToBonds(uint256 amount) external view returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IEtherFiLiquidityPool.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

interface IEtherFiLiquidityPool {
function amountForShare(uint256 _share) external view returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IPStakePool.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

interface IPStakePool {
struct Data {
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IPendlePtOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

interface IPendlePtOracle {
function getPtToAssetRate(address market, uint32 duration) external view returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ISFrax.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

interface ISFrax {
function convertToAssets(uint256 shares) external view returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ISfrxETH.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

interface ISfrxETH {
function convertToAssets(uint256 shares) external view returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IStaderStakeManager.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

interface IStaderStakeManager {
function convertBnbXToBnb(uint256 _amount) external view returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ISynclubStakeManager.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

interface ISynclubStakeManager {
function convertSnBnbToBnb(uint256 _amount) external view returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IWBETH.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

interface IWBETH {
function exchangeRate() external view returns (uint256);
Expand Down
4 changes: 2 additions & 2 deletions contracts/oracles/AnkrBNBOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { IAnkrBNB } from "../interfaces/IAnkrBNB.sol";
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol";
Expand All @@ -25,7 +25,7 @@ contract AnkrBNBOracle is CorrelatedTokenOracle {
* @notice Fetches the amount of BNB for 1 ankrBNB
* @return amount The amount of BNB for ankrBNB
*/
function getUnderlyingAmount() internal view override returns (uint256) {
function _getUnderlyingAmount() internal view override returns (uint256) {
return IAnkrBNB(CORRELATED_TOKEN).sharesToBonds(EXP_SCALE);
}
}
4 changes: 2 additions & 2 deletions contracts/oracles/BNBxOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { IStaderStakeManager } from "../interfaces/IStaderStakeManager.sol";
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol";
Expand Down Expand Up @@ -34,7 +34,7 @@ contract BNBxOracle is CorrelatedTokenOracle {
* @notice Fetches the amount of BNB for 1 BNBx
* @return price The amount of BNB for BNBx
*/
function getUnderlyingAmount() internal view override returns (uint256) {
function _getUnderlyingAmount() internal view override returns (uint256) {
return STAKE_MANAGER.convertBnbXToBnb(EXP_SCALE);
}
}
4 changes: 2 additions & 2 deletions contracts/oracles/OneJumpOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol";
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol";
Expand Down Expand Up @@ -31,7 +31,7 @@ contract OneJumpOracle is CorrelatedTokenOracle {
* @notice Fetches the amount of the underlying token for 1 correlated token
* @return amount The amount of the underlying token for 1 correlated token
*/
function getUnderlyingAmount() internal view override returns (uint256) {
function _getUnderlyingAmount() internal view override returns (uint256) {
return INTERMEDIATE_ORACLE.getPrice(CORRELATED_TOKEN);
}
}
4 changes: 2 additions & 2 deletions contracts/oracles/PendleOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { IPendlePtOracle } from "../interfaces/IPendlePtOracle.sol";
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol";
Expand Down Expand Up @@ -57,7 +57,7 @@ contract PendleOracle is CorrelatedTokenOracle {
* @notice Fetches the amount of underlying token for 1 pendle token
* @return amount The amount of underlying token for pendle token
*/
function getUnderlyingAmount() internal view override returns (uint256) {
function _getUnderlyingAmount() internal view override returns (uint256) {
return PT_ORACLE.getPtToAssetRate(MARKET, TWAP_DURATION);
}
}
4 changes: 2 additions & 2 deletions contracts/oracles/SFraxOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { ISFrax } from "../interfaces/ISFrax.sol";
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol";
Expand All @@ -23,7 +23,7 @@ contract SFraxOracle is CorrelatedTokenOracle {
* @notice Fetches the amount of FRAX for 1 sFrax
* @return amount The amount of FRAX for sFrax
*/
function getUnderlyingAmount() internal view override returns (uint256) {
function _getUnderlyingAmount() internal view override returns (uint256) {
return ISFrax(CORRELATED_TOKEN).convertToAssets(EXP_SCALE);
}
}
4 changes: 2 additions & 2 deletions contracts/oracles/SFrxETHOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { ISfrxETH } from "../interfaces/ISfrxETH.sol";
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol";
Expand All @@ -23,7 +23,7 @@ contract SFrxETHOracle is CorrelatedTokenOracle {
* @notice Gets the frxETH for 1 sfrxETH
* @return amount Amount of frxETH
*/
function getUnderlyingAmount() internal view override returns (uint256) {
function _getUnderlyingAmount() internal view override returns (uint256) {
return ISfrxETH(CORRELATED_TOKEN).convertToAssets(EXP_SCALE);
}
}
4 changes: 2 additions & 2 deletions contracts/oracles/SlisBNBOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { ISynclubStakeManager } from "../interfaces/ISynclubStakeManager.sol";
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol";
Expand Down Expand Up @@ -34,7 +34,7 @@ contract SlisBNBOracle is CorrelatedTokenOracle {
* @notice Fetches the amount of BNB for 1 slisBNB
* @return amount The amount of BNB for slisBNB
*/
function getUnderlyingAmount() internal view override returns (uint256) {
function _getUnderlyingAmount() internal view override returns (uint256) {
return STAKE_MANAGER.convertSnBnbToBnb(EXP_SCALE);
}
}
5 changes: 2 additions & 3 deletions contracts/oracles/StkBNBOracle.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { OracleInterface } from "../interfaces/OracleInterface.sol";
import { IPStakePool } from "../interfaces/IPStakePool.sol";
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol";
import { EXP_SCALE } from "@venusprotocol/solidity-utilities/contracts/constants.sol";
Expand Down Expand Up @@ -38,7 +37,7 @@ contract StkBNBOracle is CorrelatedTokenOracle {
* @notice Fetches the amount of BNB for 1 stkBNB
* @return price The amount of BNB for stkBNB
*/
function getUnderlyingAmount() internal view override returns (uint256) {
function _getUnderlyingAmount() internal view override returns (uint256) {
IPStakePool.Data memory exchangeRateData = STAKE_POOL.exchangeRate();

if (exchangeRateData.poolTokenSupply == 0) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/oracles/WBETHOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { IWBETH } from "../interfaces/IWBETH.sol";
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol";
Expand All @@ -22,7 +22,7 @@ contract WBETHOracle is CorrelatedTokenOracle {
* @notice Fetches the amount of ETH for 1 wBETH
* @return amount The amount of ETH for wBETH
*/
function getUnderlyingAmount() internal view override returns (uint256) {
function _getUnderlyingAmount() internal view override returns (uint256) {
return IWBETH(CORRELATED_TOKEN).exchangeRate();
}
}
4 changes: 2 additions & 2 deletions contracts/oracles/WeETHOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol";
import { IEtherFiLiquidityPool } from "../interfaces/IEtherFiLiquidityPool.sol";
Expand Down Expand Up @@ -32,7 +32,7 @@ contract WeETHOracle is CorrelatedTokenOracle {
* @notice Gets the eETH for 1 weETH
* @return amount Amount of eETH
*/
function getUnderlyingAmount() internal view override returns (uint256) {
function _getUnderlyingAmount() internal view override returns (uint256) {
return LIQUIDITY_POOL.amountForShare(EXP_SCALE);
}
}
2 changes: 1 addition & 1 deletion contracts/oracles/WstETHOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract WstETHOracle is CorrelatedTokenOracle {
* @notice Gets the stETH for 1 wstETH
* @return amount Amount of stETH
*/
function getUnderlyingAmount() internal view override returns (uint256) {
function _getUnderlyingAmount() internal view override returns (uint256) {
return IStETH(UNDERLYING_TOKEN).getPooledEthByShares(EXP_SCALE);
}
}
6 changes: 3 additions & 3 deletions contracts/oracles/common/CorrelatedTokenOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { OracleInterface } from "../../interfaces/OracleInterface.sol";
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol";
Expand Down Expand Up @@ -45,7 +45,7 @@ abstract contract CorrelatedTokenOracle is OracleInterface {
if (asset != CORRELATED_TOKEN) revert InvalidTokenAddress();

// get underlying token amount for 1 correlated token scaled by underlying token decimals
uint256 underlyingAmount = getUnderlyingAmount();
uint256 underlyingAmount = _getUnderlyingAmount();

// oracle returns (36 - asset decimal) scaled price
uint256 underlyingUSDPrice = RESILIENT_ORACLE.getPrice(UNDERLYING_TOKEN);
Expand All @@ -61,5 +61,5 @@ abstract contract CorrelatedTokenOracle is OracleInterface {
* @notice Gets the underlying amount for correlated token
* @return underlyingAmount Amount of underlying token
*/
function getUnderlyingAmount() internal view virtual returns (uint256);
function _getUnderlyingAmount() internal view virtual returns (uint256);
}
20 changes: 20 additions & 0 deletions contracts/test/MockEtherFiLiquidityPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.25;

import "../interfaces/IEtherFiLiquidityPool.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MockEtherFiLiquidityPool is IEtherFiLiquidityPool, Ownable {
/// @notice The amount of eETH per weETH scaled by 1e18
uint256 public amountPerShare;

constructor() Ownable() {}

function setAmountPerShare(uint256 _amountPerShare) external onlyOwner {
amountPerShare = _amountPerShare;
}

function amountForShare(uint256 _share) external view override returns (uint256) {
return (_share * amountPerShare) / 1e18;
}
}
47 changes: 47 additions & 0 deletions deploy/6-deploy-weETH-oracle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/dist/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { ADDRESSES, assets } from "../helpers/deploymentConfig";

const func: DeployFunction = async ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) => {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const resilientOracle = await ethers.getContract("ResilientOracle");
const proxyOwnerAddress = network.live ? ADDRESSES[network.name].timelock : deployer;

let { EtherFiLiquidityPool, weETH, eETH } = ADDRESSES[network.name];

if (!EtherFiLiquidityPool) {
// deploy mock liquidity pool
await deploy("MockEtherFiLiquidityPool", {
from: deployer,
contract: "MockEtherFiLiquidityPool",
args: [],
log: true,
autoMine: true, // speed up deployment on local network (ganache, hardhat), no effect on live networks
skipIfAlreadyDeployed: true,
});

const mockEtherFiLiquidityPool = await ethers.getContract("MockEtherFiLiquidityPool");
EtherFiLiquidityPool = mockEtherFiLiquidityPool.address;
await mockEtherFiLiquidityPool.transferOwnership(proxyOwnerAddress);
}

Copy link
Member

Choose a reason for hiding this comment

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

I would also deploy the mocks tokens for weETH and eETH if the address is not available in the ADDRESSES mapping (for example on hardhat). /cc @coreyar

Copy link
Collaborator

Choose a reason for hiding this comment

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

I highly recommend not using address mappings at all and instead fetching deployments

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can structure deployment scripts into 3 types of scripts for each deployment, (mocks, deploy, setup)
for example there could be
deploy/6-mocks-weETH-oracle.ts ( mocks wouldn't run in the right order but a name like dependencies would )
deploy/6-deploy-weETH-oracle.ts
deploy/6-setup-weETH-oracle.ts

Where setup receives an id so that it is only run once and mocks isn't deployed on live networks ( it would deploy the token contracts Jesus mentions) deploy only deploys contracts and setup doesn't deploy and only calls methods on contracts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now this deployment script is following the pattern of the other deployment scripts in this repo.

I agree with your comments but I think we should make these changes in all the deployment scripts and not just this one to keep consistency. I would suggest we create a separate ticket and PR for this changes and this it itself requires a lot of code fixes.

wdyt @coreyar @chechu ?

Copy link
Member

Choose a reason for hiding this comment

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

VEN-2547. We can leave this as it is in this PR, and review it in the new task.

await deploy("WeETHOracle", {
from: deployer,
log: true,
deterministicDeployment: false,
args: [EtherFiLiquidityPool, weETH, eETH, resilientOracle.address],
proxy: {
owner: proxyOwnerAddress,
proxyContract: "OptimizedTransparentProxy",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add skipIfAlreadyDeployed flag here? Just for consistency I guess wit will be okay. However it will not have any impact on the deployment (or any potential impl updates as we will have a separate script for impl update if needed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added skipIfAlreadyDeployed to this deployment. I think without skipIfAlreadyDeployed=true the contracts are getting re-deployed. So I think we should have a separate issue to include this flag in all the deployment scripts.

skipIfAlreadyDeployed: true,
});
};

export default func;
func.tags = ["weETH"];
func.skip = async (hre: HardhatRuntimeEnvironment) => hre.network.name !== "ethereum" && hre.network.name !== "sepolia";
Copy link
Member

Choose a reason for hiding this comment

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

Let's enable the deployment to hardhat too

Copy link
Collaborator

Choose a reason for hiding this comment

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

script 4 is also skipped on hardhat

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even this I think we should review for all the scripts and fix them if we want to enable for hardhat

Copy link
Member

Choose a reason for hiding this comment

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

VEN-2547

Loading