From cdf4e52c5c12790d3f0fab88260de95ddcb75b98 Mon Sep 17 00:00:00 2001 From: web3rover Date: Wed, 30 Oct 2024 15:59:11 +0400 Subject: [PATCH] fix: added deployment scripts --- contracts/oracles/EtherfiAccountantOracle.sol | 37 +++++++++++++++ deploy/14-dependencies-eBTC-oracle.ts | 28 +++++++++++ deploy/14-deploy-eBTC-oracle.ts | 46 +++++++++++++++++++ helpers/deploymentConfig.ts | 2 + 4 files changed, 113 insertions(+) create mode 100644 contracts/oracles/EtherfiAccountantOracle.sol create mode 100644 deploy/14-dependencies-eBTC-oracle.ts create mode 100644 deploy/14-deploy-eBTC-oracle.ts diff --git a/contracts/oracles/EtherfiAccountantOracle.sol b/contracts/oracles/EtherfiAccountantOracle.sol new file mode 100644 index 00000000..f9ab4d18 --- /dev/null +++ b/contracts/oracles/EtherfiAccountantOracle.sol @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: BSD-3-Clause +pragma solidity 0.8.25; + +import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol"; +import { IAccountant } from "../interfaces/IAccountant.sol"; +import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol"; + +/** + * @title EtherfiAccountantOracle + * @author Venus + * @notice This oracle fetches the price of eBTC + */ +contract EtherfiAccountantOracle is CorrelatedTokenOracle { + /// @notice Address of Accountant + /// @custom:oz-upgrades-unsafe-allow state-variable-immutable + IAccountant public immutable ACCOUNTANT; + + /// @notice Constructor for the implementation contract. + /// @custom:oz-upgrades-unsafe-allow constructor + constructor( + address accountant, + address eBTC, + address wbtc, + address resilientOracle + ) CorrelatedTokenOracle(eBTC, wbtc, resilientOracle) { + ensureNonzeroAddress(accountant); + ACCOUNTANT = IAccountant(accountant); + } + + /** + * @notice Gets the WBTC for 1 eBTC + * @return amount Amount of WBTC + */ + function _getUnderlyingAmount() internal view override returns (uint256) { + return ACCOUNTANT.getRateSafe(); + } +} diff --git a/deploy/14-dependencies-eBTC-oracle.ts b/deploy/14-dependencies-eBTC-oracle.ts new file mode 100644 index 00000000..72e3b651 --- /dev/null +++ b/deploy/14-dependencies-eBTC-oracle.ts @@ -0,0 +1,28 @@ +import { ethers } from "hardhat"; +import { DeployFunction } from "hardhat-deploy/dist/types"; +import { HardhatRuntimeEnvironment } from "hardhat/types"; + +import { ADDRESSES } from "../helpers/deploymentConfig"; + +const func: DeployFunction = async ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) => { + const { deploy } = deployments; + const { deployer } = await getNamedAccounts(); + + const proxyOwnerAddress = network.live ? ADDRESSES[network.name].timelock : deployer; + + await deploy("MockAccountant_eBTC", { + from: deployer, + contract: "MockAccountant", + args: [], + log: true, + autoMine: true, + skipIfAlreadyDeployed: true, + }); + + const mockAccountant = await ethers.getContract("MockAccountant_eBTC"); + await mockAccountant.transferOwnership(proxyOwnerAddress); +}; + +export default func; +func.tags = ["eBTCAccountantOracle"]; +func.skip = async (hre: HardhatRuntimeEnvironment) => hre.network.name !== "sepolia"; diff --git a/deploy/14-deploy-eBTC-oracle.ts b/deploy/14-deploy-eBTC-oracle.ts new file mode 100644 index 00000000..a96892ae --- /dev/null +++ b/deploy/14-deploy-eBTC-oracle.ts @@ -0,0 +1,46 @@ +import { ethers } from "hardhat"; +import { DeployFunction } from "hardhat-deploy/dist/types"; +import { HardhatRuntimeEnvironment } from "hardhat/types"; + +import { ADDRESSES } from "../helpers/deploymentConfig"; + +const func: DeployFunction = async ({ + getNamedAccounts, + deployments, + network, + artifacts, +}: HardhatRuntimeEnvironment) => { + const { deploy } = deployments; + const { deployer } = await getNamedAccounts(); + + const resilientOracle = await ethers.getContract("ResilientOracle"); + const proxyOwnerAddress = network.live ? ADDRESSES[network.name].timelock : deployer; + const defaultProxyAdmin = await artifacts.readArtifact( + "hardhat-deploy/solc_0.8/openzeppelin/proxy/transparent/ProxyAdmin.sol:ProxyAdmin", + ); + let { eBTC_Accountant } = ADDRESSES[network.name]; + const { WBTC, eBTC } = ADDRESSES[network.name]; + + eBTC_Accountant = eBTC_Accountant || (await ethers.getContract("MockAccountant_eBTC")).address; + + await deploy("eBTCAccountantOracle", { + contract: "EtherfiAccountantOracle", + from: deployer, + log: true, + deterministicDeployment: false, + args: [eBTC_Accountant, eBTC, WBTC, resilientOracle.address], + proxy: { + owner: proxyOwnerAddress, + proxyContract: "OptimizedTransparentUpgradeableProxy", + viaAdminContract: { + name: "DefaultProxyAdmin", + artifact: defaultProxyAdmin, + }, + }, + skipIfAlreadyDeployed: true, + }); +}; + +export default func; +func.tags = ["eBTCAccountantOracle"]; +func.skip = async (hre: HardhatRuntimeEnvironment) => hre.network.name !== "ethereum" && hre.network.name !== "sepolia"; diff --git a/helpers/deploymentConfig.ts b/helpers/deploymentConfig.ts index 52c9da52..a00179d7 100644 --- a/helpers/deploymentConfig.ts +++ b/helpers/deploymentConfig.ts @@ -126,6 +126,8 @@ export const ADDRESSES: PreconfiguredAddresses = { rsETH: "0xfA0614E5C803E15070d31f7C38d2d430EBe68E47", ezETH: "0xB8eb706b85Ae7355c9FE4371a499F50f3484809c", weETHs: "0xE233527306c2fa1E159e251a2E5893334505A5E0", + eBTC: "0xd48392CCf3fe028023D0783E570DFc71996859d7", + WBTC: "0x92A2928f5634BEa89A195e7BeCF0f0FEEDAB885b", }, ethereum: { vBNBAddress: ethers.constants.AddressZero,