Skip to content

Commit

Permalink
Merge pull request #132 from VenusProtocol/chore/ven-1725
Browse files Browse the repository at this point in the history
[VEN-1725] Deployment of Redstone Oracle
  • Loading branch information
0xlucian authored Nov 3, 2023
2 parents 97e0644 + a3de347 commit 3ad57ef
Show file tree
Hide file tree
Showing 19 changed files with 4,377 additions and 7,231 deletions.
26 changes: 13 additions & 13 deletions contracts/oracles/BinanceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
_disableInitializers();
}

/**
* @notice Sets the contracts required to fetch prices
* @param _sidRegistryAddress Address of SID registry
* @param _accessControlManager Address of the access control manager contract
*/
function initialize(
address _sidRegistryAddress,
address _accessControlManager
) external initializer notNullAddress(_sidRegistryAddress) {
sidRegistryAddress = _sidRegistryAddress;
__AccessControlled_init(_accessControlManager);
}

/**
* @notice Used to set the max stale period of an asset
* @param symbol The symbol of the asset
Expand Down Expand Up @@ -72,19 +85,6 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
emit SymbolOverridden(symbol, overrideSymbol);
}

/**
* @notice Sets the contracts required to fetch prices
* @param _sidRegistryAddress Address of SID registry
* @param _accessControlManager Address of the access control manager contract
*/
function initialize(
address _sidRegistryAddress,
address _accessControlManager
) external initializer notNullAddress(_sidRegistryAddress) {
sidRegistryAddress = _sidRegistryAddress;
__AccessControlled_init(_accessControlManager);
}

/**
* @notice Uses Space ID to fetch the feed registry address
* @return feedRegistryAddress Address of binance oracle feed registry.
Expand Down
16 changes: 8 additions & 8 deletions contracts/oracles/BoundValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
_disableInitializers();
}

/**
* @notice Initializes the owner of the contract
* @param accessControlManager_ Address of the access control manager contract
*/
function initialize(address accessControlManager_) external initializer {
__AccessControlled_init(accessControlManager_);
}

/**
* @notice Add multiple validation configs at the same time
* @param configs Array of validation configs
Expand All @@ -54,14 +62,6 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
}
}

/**
* @notice Initializes the owner of the contract
* @param accessControlManager_ Address of the access control manager contract
*/
function initialize(address accessControlManager_) external initializer {
__AccessControlled_init(accessControlManager_);
}

/**
* @notice Add a single validation config
* @param config Validation config struct
Expand Down
16 changes: 8 additions & 8 deletions contracts/oracles/ChainlinkOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
_disableInitializers();
}

/**
* @notice Initializes the owner of the contract
* @param accessControlManager_ Address of the access control manager contract
*/
function initialize(address accessControlManager_) external initializer {
__AccessControlled_init(accessControlManager_);
}

/**
* @notice Manually set the price of a given asset
* @param asset Asset address
Expand Down Expand Up @@ -81,14 +89,6 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
}
}

/**
* @notice Initializes the owner of the contract
* @param accessControlManager_ Address of the access control manager contract
*/
function initialize(address accessControlManager_) external initializer {
__AccessControlled_init(accessControlManager_);
}

/**
* @notice Add single token config. asset & feed cannot be null addresses and maxStalePeriod must be positive
* @param tokenConfig Token config struct
Expand Down
30 changes: 15 additions & 15 deletions contracts/oracles/PythOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ contract PythOracle is AccessControlledV8, OracleInterface {
_disableInitializers();
}

/**
* @notice Initializes the owner of the contract and sets required contracts
* @param underlyingPythOracle_ Address of the Pyth oracle
* @param accessControlManager_ Address of the access control manager contract
*/
function initialize(
address underlyingPythOracle_,
address accessControlManager_
) external initializer notNullAddress(underlyingPythOracle_) {
__AccessControlled_init(accessControlManager_);

underlyingPythOracle = IPyth(underlyingPythOracle_);
emit PythOracleSet(address(0), underlyingPythOracle_);
}

/**
* @notice Batch set token configs
* @param tokenConfigs_ Token config array
Expand Down Expand Up @@ -89,21 +104,6 @@ contract PythOracle is AccessControlledV8, OracleInterface {
emit PythOracleSet(address(oldUnderlyingPythOracle), address(underlyingPythOracle_));
}

/**
* @notice Initializes the owner of the contract and sets required contracts
* @param underlyingPythOracle_ Address of the Pyth oracle
* @param accessControlManager_ Address of the access control manager contract
*/
function initialize(
address underlyingPythOracle_,
address accessControlManager_
) external initializer notNullAddress(underlyingPythOracle_) {
__AccessControlled_init(accessControlManager_);

underlyingPythOracle = IPyth(underlyingPythOracle_);
emit PythOracleSet(address(0), underlyingPythOracle_);
}

/**
* @notice Set single token config. `maxStalePeriod` cannot be 0 and `asset` cannot be a null address
* @param tokenConfig Token config struct
Expand Down
16 changes: 8 additions & 8 deletions contracts/oracles/TwapOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
_disableInitializers();
}

/**
* @notice Initializes the owner of the contract
* @param accessControlManager_ Address of the access control manager contract
*/
function initialize(address accessControlManager_) external initializer {
__AccessControlled_init(accessControlManager_);
}

/**
* @notice Adds multiple token configs at the same time
* @param configs Config array
Expand All @@ -103,14 +111,6 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
}
}

/**
* @notice Initializes the owner of the contract
* @param accessControlManager_ Address of the access control manager contract
*/
function initialize(address accessControlManager_) external initializer {
__AccessControlled_init(accessControlManager_);
}

/**
* @notice Get the TWAP price for the given asset
* @param asset asset address
Expand Down
4 changes: 2 additions & 2 deletions contracts/oracles/mocks/MockBinanceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ contract MockBinanceOracle is OwnableUpgradeable, OracleInterface {

constructor() {}

function initialize() public initializer {}

function setPrice(address asset, uint256 price) external {
assetPrices[asset] = price;
}

function initialize() public initializer {}

function getPrice(address token) public view returns (uint256) {
return assetPrices[token];
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/oracles/mocks/MockChainlinkOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ contract MockChainlinkOracle is OwnableUpgradeable, OracleInterface {
//set price in 6 decimal precision
constructor() {}

function setPrice(address asset, uint256 price) external {
assetPrices[asset] = price;
}

function initialize() public initializer {
__Ownable_init();
}

function setPrice(address asset, uint256 price) external {
assetPrices[asset] = price;
}

//https://compound.finance/docs/prices
function getPrice(address token) public view returns (uint256) {
return assetPrices[token];
Expand Down
8 changes: 4 additions & 4 deletions contracts/oracles/mocks/MockPythOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ contract MockPythOracle is OwnableUpgradeable {
//set price in 6 decimal precision
constructor() {}

function setPrice(address asset, uint256 price) external {
assetPrices[asset] = price;
}

function initialize(address underlyingPythOracle_) public initializer {
__Ownable_init();
if (underlyingPythOracle_ == address(0)) revert("pyth oracle cannot be zero address");
underlyingPythOracle = IPyth(underlyingPythOracle_);
}

function setPrice(address asset, uint256 price) external {
assetPrices[asset] = price;
}

//https://compound.finance/docs/prices
function getPrice(address token) public view returns (uint256) {
return assetPrices[token];
Expand Down
8 changes: 4 additions & 4 deletions contracts/oracles/mocks/MockTwapOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ contract MockTwapOracle is OwnableUpgradeable {
//set price in 6 decimal precision
constructor() {}

function setPrice(address asset, uint256 price) external {
assetPrices[asset] = price;
}

function initialize(address vBNB_) public initializer {
__Ownable_init();
if (vBNB_ == address(0)) revert("vBNB can't be zero address");
vBNB = vBNB_;
}

function setPrice(address asset, uint256 price) external {
assetPrices[asset] = price;
}

//https://compound.finance/docs/prices
function getPrice(address token) public view returns (uint256) {
return assetPrices[token];
Expand Down
23 changes: 1 addition & 22 deletions deploy/1-deploy-oracles.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
import mainnetDeployments from "@venusprotocol/venus-protocol/networks/mainnet.json";
import testnetDeployments from "@venusprotocol/venus-protocol/networks/testnet.json";
import hre from "hardhat";
import { DeployFunction } from "hardhat-deploy/dist/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const ADDRESSES = {
bsctestnet: {
vBNBAddress: testnetDeployments.Contracts.vBNB,
WBNBAddress: "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",
VAIAddress: testnetDeployments.Contracts.VAI,
pythOracleAddress: "0xd7308b14BF4008e7C7196eC35610B1427C5702EA",
sidRegistryAddress: "0xfFB52185b56603e0fd71De9de4F6f902f05EEA23",
acm: "0x45f8a08F534f34A97187626E05d4b6648Eeaa9AA",
timelock: testnetDeployments.Contracts.Timelock,
},
bscmainnet: {
vBNBAddress: mainnetDeployments.Contracts.vBNB,
WBNBAddress: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
VAIAddress: mainnetDeployments.Contracts.VAI,
pythOracleAddress: "0x4D7E825f80bDf85e913E0DD2A2D54927e9dE1594",
sidRegistryAddress: "0x08CEd32a7f3eeC915Ba84415e9C07a7286977956",
acm: "0x4788629ABc6cFCA10F9f969efdEAa1cF70c23555",
timelock: mainnetDeployments.Contracts.Timelock,
},
};
import { ADDRESSES } from "../utils/deploymentUtils";

const func: DeployFunction = async function ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) {
const { deploy } = deployments;
Expand Down
38 changes: 38 additions & 0 deletions deploy/3-deploy-redstone-oracle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import hre from "hardhat";
import { DeployFunction } from "hardhat-deploy/dist/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { ADDRESSES } from "../utils/deploymentUtils";

const func: DeployFunction = async function ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();
const networkName = network.name === "bscmainnet" ? "bscmainnet" : "bsctestnet";
const proxyOwnerAddress = network.live ? ADDRESSES[networkName].timelock : deployer;

await deploy("RedStoneOracle", {
contract: network.live ? "ChainlinkOracle" : "MockChainlinkOracle",
from: deployer,
log: true,
deterministicDeployment: false,
args: [],
proxy: {
owner: proxyOwnerAddress,
proxyContract: "OptimizedTransparentProxy",
execute: {
methodName: "initialize",
args: network.live ? [ADDRESSES[networkName].acm] : [],
},
},
});

const redStoneOracle = await hre.ethers.getContract("RedStoneOracle");
const redStoneOracleOwner = await redStoneOracle.owner();

if (redStoneOracleOwner === deployer) {
await redStoneOracle.transferOwnership(ADDRESSES[networkName].timelock);
}
};

func.tags = ["deploy-redstone"];
export default func;
Loading

0 comments on commit 3ad57ef

Please sign in to comment.