generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from VenusProtocol/develop
New release
- Loading branch information
Showing
18 changed files
with
1,736 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
Oops, something went wrong.