Skip to content

Commit

Permalink
Merge pull request #158 from VenusProtocol/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
chechu authored Jan 23, 2024
2 parents 1e9210e + ad4482e commit ee5907b
Show file tree
Hide file tree
Showing 18 changed files with 1,736 additions and 7 deletions.
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
## [1.9.0-dev.3](https://github.com/VenusProtocol/oracle/compare/v1.9.0-dev.2...v1.9.0-dev.3) (2024-01-23)


### Features

* update deps to the stable versions ([cc79591](https://github.com/VenusProtocol/oracle/commit/cc7959157cc57345099de169a3779632b072e1a1))

## [1.9.0-dev.2](https://github.com/VenusProtocol/oracle/compare/v1.9.0-dev.1...v1.9.0-dev.2) (2024-01-23)


### Features

* updating deployment files ([e9cedb9](https://github.com/VenusProtocol/oracle/commit/e9cedb91e152ffc0ffba7bd26cc587e9c3d77c98))

## [1.9.0-dev.1](https://github.com/VenusProtocol/oracle/compare/v1.8.0...v1.9.0-dev.1) (2024-01-22)


### Features

* add implementation of new wstETH oracle ([ee78b61](https://github.com/VenusProtocol/oracle/commit/ee78b61504f09f3f6e732c9b54862a17f15d6b13))
* add unit tests for wstETH oracle ([8ee95dc](https://github.com/VenusProtocol/oracle/commit/8ee95dcb43a478ef29e9d58114bcd07b43747506))
* fork test for wstETH oracle ([373d192](https://github.com/VenusProtocol/oracle/commit/373d1920251ec5abe58c711cb56161361e0e83b1))


### Bug Fixes

* CI test failing ([68e8bfe](https://github.com/VenusProtocol/oracle/commit/68e8bfe47dd0a74bb8172f95a6ab01a53b695714))
* lint ([e1b730d](https://github.com/VenusProtocol/oracle/commit/e1b730d67997cfe186e209e601c6236ee0ece846))
* remove hardcoded gas price for sepolia ([5a83647](https://github.com/VenusProtocol/oracle/commit/5a836478266b5799fe3e2335f25f864c94c3a3f9))
* try fix sol parsing in github ([c909088](https://github.com/VenusProtocol/oracle/commit/c909088eedb7816b82282fa46ca4a55526b254e0))
* typo ([25921ac](https://github.com/VenusProtocol/oracle/commit/25921ac407151d1ed658540eb35385eec609d3b1))
* wrong denominator value ([a1c037e](https://github.com/VenusProtocol/oracle/commit/a1c037e1fad829b291c09eb3a635fbe6cce74491))


### Reverts

* Revert "fix: comment format of constructor" ([889fb21](https://github.com/VenusProtocol/oracle/commit/889fb21c20b539678cdd83d0077fe5928feb6522))

## [1.8.0](https://github.com/VenusProtocol/oracle/compare/v1.7.3...v1.8.0) (2023-12-28)


Expand Down
6 changes: 6 additions & 0 deletions contracts/interfaces/IStETH.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;

interface IStETH {
function getPooledEthByShares(uint256 _sharesAmount) external view returns (uint256);
}
61 changes: 61 additions & 0 deletions contracts/oracles/WstETHOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;

import { OracleInterface } from "../interfaces/OracleInterface.sol";
import { IStETH } from "../interfaces/IStETH.sol";
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol";
import { EXP_SCALE } from "@venusprotocol/solidity-utilities/contracts/constants.sol";

/**
* @title WstETHOracle
* @author Venus
* @notice This oracle fetches the price of wstETH asset
*/
contract WstETHOracle is OracleInterface {
/// @notice Address of stETH
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
IStETH public immutable STETH;

/// @notice Address of wstETH
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address public immutable WSTETH_ADDRESS;

/// @notice Address of WETH
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address public immutable WETH_ADDRESS;

/// @notice Address of Resilient Oracle
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
OracleInterface public immutable RESILIENT_ORACLE;

/// @notice Constructor for the implementation contract.
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address wstETHAddress, address wETHAddress, address stETHAddress, address resilientOracleAddress) {
ensureNonzeroAddress(wstETHAddress);
ensureNonzeroAddress(wETHAddress);
ensureNonzeroAddress(stETHAddress);
ensureNonzeroAddress(resilientOracleAddress);
WSTETH_ADDRESS = wstETHAddress;
WETH_ADDRESS = wETHAddress;
STETH = IStETH(stETHAddress);
RESILIENT_ORACLE = OracleInterface(resilientOracleAddress);
}

/**
* @notice Gets the price of wstETH asset
* @param asset Address of wstETH
* @return wstETH Price in USD scaled by 1e18
*/
function getPrice(address asset) public view returns (uint256) {
if (asset != WSTETH_ADDRESS) revert("wrong wstETH address");

// get stETH amount for 1 wstETH scaled by 1e18
uint256 stETHAmount = STETH.getPooledEthByShares(1 ether);

// price is scaled 1e18 (oracle returns 36 - asset decimal scale)
uint256 wethUSDPrice = RESILIENT_ORACLE.getPrice(WETH_ADDRESS);

// stETHAmount (for 1 wstETH) * wethUSDPrice (assuming 1stETH = 1 WETH) / 1e18
return (stETHAmount * wethUSDPrice) / EXP_SCALE;
}
}
36 changes: 36 additions & 0 deletions deploy/4-deploy-wstETH-oracle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/dist/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

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

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

console.log(`Deployer ${deployer}`);
const networkName: string = network.name === "hardhat" ? "bsctestnet" : network.name;

const proxyOwnerAddress = network.live ? ADDRESSES[networkName].timelock : deployer;

const { stETHAddress, wstETHAddress } = ADDRESSES[networkName];
const WETHAsset = assets[networkName].find(asset => asset.token === "WETH");
const WETHAddress = WETHAsset?.address ?? addr0000;

const oracle = await ethers.getContract("ResilientOracle");

await deploy("WstETHOracle", {
from: deployer,
log: true,
deterministicDeployment: false,
args: [wstETHAddress, WETHAddress, stETHAddress, oracle.address],
proxy: {
owner: proxyOwnerAddress,
proxyContract: "OptimizedTransparentProxy",
},
});
};

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

0 comments on commit ee5907b

Please sign in to comment.