Skip to content

Commit

Permalink
Merge pull request #233 from VenusProtocol/feat/ven-2923
Browse files Browse the repository at this point in the history
[VEN-2923] Add EtherfiAccountantOracle
  • Loading branch information
web3rover authored Nov 8, 2024
2 parents 265c0a4 + b2b592e commit d123b13
Show file tree
Hide file tree
Showing 17 changed files with 2,923 additions and 0 deletions.
38 changes: 38 additions & 0 deletions contracts/oracles/EtherfiAccountantOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 any Ether.fi asset that uses
* Accountant contracts to derive the underlying price
*/
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 correlatedToken,
address underlyingToken,
address resilientOracle
) CorrelatedTokenOracle(correlatedToken, underlyingToken, resilientOracle) {
ensureNonzeroAddress(accountant);
ACCOUNTANT = IAccountant(accountant);
}

/**
* @notice Fetches the conversion rate from the ACCOUNTANT contract
* @return amount Amount of WBTC
*/
function _getUnderlyingAmount() internal view override returns (uint256) {
return ACCOUNTANT.getRateSafe();
}
}
28 changes: 28 additions & 0 deletions deploy/14-dependencies-eBTC-oracle.ts
Original file line number Diff line number Diff line change
@@ -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";
46 changes: 46 additions & 0 deletions deploy/14-deploy-eBTC-oracle.ts
Original file line number Diff line number Diff line change
@@ -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";
Loading

0 comments on commit d123b13

Please sign in to comment.