Skip to content

Commit 3ad57ef

Browse files
authored
Merge pull request #132 from VenusProtocol/chore/ven-1725
[VEN-1725] Deployment of Redstone Oracle
2 parents 97e0644 + a3de347 commit 3ad57ef

19 files changed

+4377
-7231
lines changed

contracts/oracles/BinanceOracle.sol

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
4545
_disableInitializers();
4646
}
4747

48+
/**
49+
* @notice Sets the contracts required to fetch prices
50+
* @param _sidRegistryAddress Address of SID registry
51+
* @param _accessControlManager Address of the access control manager contract
52+
*/
53+
function initialize(
54+
address _sidRegistryAddress,
55+
address _accessControlManager
56+
) external initializer notNullAddress(_sidRegistryAddress) {
57+
sidRegistryAddress = _sidRegistryAddress;
58+
__AccessControlled_init(_accessControlManager);
59+
}
60+
4861
/**
4962
* @notice Used to set the max stale period of an asset
5063
* @param symbol The symbol of the asset
@@ -72,19 +85,6 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
7285
emit SymbolOverridden(symbol, overrideSymbol);
7386
}
7487

75-
/**
76-
* @notice Sets the contracts required to fetch prices
77-
* @param _sidRegistryAddress Address of SID registry
78-
* @param _accessControlManager Address of the access control manager contract
79-
*/
80-
function initialize(
81-
address _sidRegistryAddress,
82-
address _accessControlManager
83-
) external initializer notNullAddress(_sidRegistryAddress) {
84-
sidRegistryAddress = _sidRegistryAddress;
85-
__AccessControlled_init(_accessControlManager);
86-
}
87-
8888
/**
8989
* @notice Uses Space ID to fetch the feed registry address
9090
* @return feedRegistryAddress Address of binance oracle feed registry.

contracts/oracles/BoundValidator.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
3636
_disableInitializers();
3737
}
3838

39+
/**
40+
* @notice Initializes the owner of the contract
41+
* @param accessControlManager_ Address of the access control manager contract
42+
*/
43+
function initialize(address accessControlManager_) external initializer {
44+
__AccessControlled_init(accessControlManager_);
45+
}
46+
3947
/**
4048
* @notice Add multiple validation configs at the same time
4149
* @param configs Array of validation configs
@@ -54,14 +62,6 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
5462
}
5563
}
5664

57-
/**
58-
* @notice Initializes the owner of the contract
59-
* @param accessControlManager_ Address of the access control manager contract
60-
*/
61-
function initialize(address accessControlManager_) external initializer {
62-
__AccessControlled_init(accessControlManager_);
63-
}
64-
6565
/**
6666
* @notice Add a single validation config
6767
* @param config Validation config struct

contracts/oracles/ChainlinkOracle.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
4949
_disableInitializers();
5050
}
5151

52+
/**
53+
* @notice Initializes the owner of the contract
54+
* @param accessControlManager_ Address of the access control manager contract
55+
*/
56+
function initialize(address accessControlManager_) external initializer {
57+
__AccessControlled_init(accessControlManager_);
58+
}
59+
5260
/**
5361
* @notice Manually set the price of a given asset
5462
* @param asset Asset address
@@ -81,14 +89,6 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
8189
}
8290
}
8391

84-
/**
85-
* @notice Initializes the owner of the contract
86-
* @param accessControlManager_ Address of the access control manager contract
87-
*/
88-
function initialize(address accessControlManager_) external initializer {
89-
__AccessControlled_init(accessControlManager_);
90-
}
91-
9292
/**
9393
* @notice Add single token config. asset & feed cannot be null addresses and maxStalePeriod must be positive
9494
* @param tokenConfig Token config struct

contracts/oracles/PythOracle.sol

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ contract PythOracle is AccessControlledV8, OracleInterface {
5656
_disableInitializers();
5757
}
5858

59+
/**
60+
* @notice Initializes the owner of the contract and sets required contracts
61+
* @param underlyingPythOracle_ Address of the Pyth oracle
62+
* @param accessControlManager_ Address of the access control manager contract
63+
*/
64+
function initialize(
65+
address underlyingPythOracle_,
66+
address accessControlManager_
67+
) external initializer notNullAddress(underlyingPythOracle_) {
68+
__AccessControlled_init(accessControlManager_);
69+
70+
underlyingPythOracle = IPyth(underlyingPythOracle_);
71+
emit PythOracleSet(address(0), underlyingPythOracle_);
72+
}
73+
5974
/**
6075
* @notice Batch set token configs
6176
* @param tokenConfigs_ Token config array
@@ -89,21 +104,6 @@ contract PythOracle is AccessControlledV8, OracleInterface {
89104
emit PythOracleSet(address(oldUnderlyingPythOracle), address(underlyingPythOracle_));
90105
}
91106

92-
/**
93-
* @notice Initializes the owner of the contract and sets required contracts
94-
* @param underlyingPythOracle_ Address of the Pyth oracle
95-
* @param accessControlManager_ Address of the access control manager contract
96-
*/
97-
function initialize(
98-
address underlyingPythOracle_,
99-
address accessControlManager_
100-
) external initializer notNullAddress(underlyingPythOracle_) {
101-
__AccessControlled_init(accessControlManager_);
102-
103-
underlyingPythOracle = IPyth(underlyingPythOracle_);
104-
emit PythOracleSet(address(0), underlyingPythOracle_);
105-
}
106-
107107
/**
108108
* @notice Set single token config. `maxStalePeriod` cannot be 0 and `asset` cannot be a null address
109109
* @param tokenConfig Token config struct

contracts/oracles/TwapOracle.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
8787
_disableInitializers();
8888
}
8989

90+
/**
91+
* @notice Initializes the owner of the contract
92+
* @param accessControlManager_ Address of the access control manager contract
93+
*/
94+
function initialize(address accessControlManager_) external initializer {
95+
__AccessControlled_init(accessControlManager_);
96+
}
97+
9098
/**
9199
* @notice Adds multiple token configs at the same time
92100
* @param configs Config array
@@ -103,14 +111,6 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
103111
}
104112
}
105113

106-
/**
107-
* @notice Initializes the owner of the contract
108-
* @param accessControlManager_ Address of the access control manager contract
109-
*/
110-
function initialize(address accessControlManager_) external initializer {
111-
__AccessControlled_init(accessControlManager_);
112-
}
113-
114114
/**
115115
* @notice Get the TWAP price for the given asset
116116
* @param asset asset address

contracts/oracles/mocks/MockBinanceOracle.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ contract MockBinanceOracle is OwnableUpgradeable, OracleInterface {
99

1010
constructor() {}
1111

12+
function initialize() public initializer {}
13+
1214
function setPrice(address asset, uint256 price) external {
1315
assetPrices[asset] = price;
1416
}
1517

16-
function initialize() public initializer {}
17-
1818
function getPrice(address token) public view returns (uint256) {
1919
return assetPrices[token];
2020
}

contracts/oracles/mocks/MockChainlinkOracle.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ contract MockChainlinkOracle is OwnableUpgradeable, OracleInterface {
1010
//set price in 6 decimal precision
1111
constructor() {}
1212

13-
function setPrice(address asset, uint256 price) external {
14-
assetPrices[asset] = price;
15-
}
16-
1713
function initialize() public initializer {
1814
__Ownable_init();
1915
}
2016

17+
function setPrice(address asset, uint256 price) external {
18+
assetPrices[asset] = price;
19+
}
20+
2121
//https://compound.finance/docs/prices
2222
function getPrice(address token) public view returns (uint256) {
2323
return assetPrices[token];

contracts/oracles/mocks/MockPythOracle.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ contract MockPythOracle is OwnableUpgradeable {
1414
//set price in 6 decimal precision
1515
constructor() {}
1616

17-
function setPrice(address asset, uint256 price) external {
18-
assetPrices[asset] = price;
19-
}
20-
2117
function initialize(address underlyingPythOracle_) public initializer {
2218
__Ownable_init();
2319
if (underlyingPythOracle_ == address(0)) revert("pyth oracle cannot be zero address");
2420
underlyingPythOracle = IPyth(underlyingPythOracle_);
2521
}
2622

23+
function setPrice(address asset, uint256 price) external {
24+
assetPrices[asset] = price;
25+
}
26+
2727
//https://compound.finance/docs/prices
2828
function getPrice(address token) public view returns (uint256) {
2929
return assetPrices[token];

contracts/oracles/mocks/MockTwapOracle.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ contract MockTwapOracle is OwnableUpgradeable {
1313
//set price in 6 decimal precision
1414
constructor() {}
1515

16-
function setPrice(address asset, uint256 price) external {
17-
assetPrices[asset] = price;
18-
}
19-
2016
function initialize(address vBNB_) public initializer {
2117
__Ownable_init();
2218
if (vBNB_ == address(0)) revert("vBNB can't be zero address");
2319
vBNB = vBNB_;
2420
}
2521

22+
function setPrice(address asset, uint256 price) external {
23+
assetPrices[asset] = price;
24+
}
25+
2626
//https://compound.finance/docs/prices
2727
function getPrice(address token) public view returns (uint256) {
2828
return assetPrices[token];

deploy/1-deploy-oracles.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
1-
import mainnetDeployments from "@venusprotocol/venus-protocol/networks/mainnet.json";
2-
import testnetDeployments from "@venusprotocol/venus-protocol/networks/testnet.json";
31
import hre from "hardhat";
42
import { DeployFunction } from "hardhat-deploy/dist/types";
53
import { HardhatRuntimeEnvironment } from "hardhat/types";
64

7-
const ADDRESSES = {
8-
bsctestnet: {
9-
vBNBAddress: testnetDeployments.Contracts.vBNB,
10-
WBNBAddress: "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",
11-
VAIAddress: testnetDeployments.Contracts.VAI,
12-
pythOracleAddress: "0xd7308b14BF4008e7C7196eC35610B1427C5702EA",
13-
sidRegistryAddress: "0xfFB52185b56603e0fd71De9de4F6f902f05EEA23",
14-
acm: "0x45f8a08F534f34A97187626E05d4b6648Eeaa9AA",
15-
timelock: testnetDeployments.Contracts.Timelock,
16-
},
17-
bscmainnet: {
18-
vBNBAddress: mainnetDeployments.Contracts.vBNB,
19-
WBNBAddress: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
20-
VAIAddress: mainnetDeployments.Contracts.VAI,
21-
pythOracleAddress: "0x4D7E825f80bDf85e913E0DD2A2D54927e9dE1594",
22-
sidRegistryAddress: "0x08CEd32a7f3eeC915Ba84415e9C07a7286977956",
23-
acm: "0x4788629ABc6cFCA10F9f969efdEAa1cF70c23555",
24-
timelock: mainnetDeployments.Contracts.Timelock,
25-
},
26-
};
5+
import { ADDRESSES } from "../utils/deploymentUtils";
276

287
const func: DeployFunction = async function ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) {
298
const { deploy } = deployments;

deploy/3-deploy-redstone-oracle.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import hre from "hardhat";
2+
import { DeployFunction } from "hardhat-deploy/dist/types";
3+
import { HardhatRuntimeEnvironment } from "hardhat/types";
4+
5+
import { ADDRESSES } from "../utils/deploymentUtils";
6+
7+
const func: DeployFunction = async function ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) {
8+
const { deploy } = deployments;
9+
const { deployer } = await getNamedAccounts();
10+
const networkName = network.name === "bscmainnet" ? "bscmainnet" : "bsctestnet";
11+
const proxyOwnerAddress = network.live ? ADDRESSES[networkName].timelock : deployer;
12+
13+
await deploy("RedStoneOracle", {
14+
contract: network.live ? "ChainlinkOracle" : "MockChainlinkOracle",
15+
from: deployer,
16+
log: true,
17+
deterministicDeployment: false,
18+
args: [],
19+
proxy: {
20+
owner: proxyOwnerAddress,
21+
proxyContract: "OptimizedTransparentProxy",
22+
execute: {
23+
methodName: "initialize",
24+
args: network.live ? [ADDRESSES[networkName].acm] : [],
25+
},
26+
},
27+
});
28+
29+
const redStoneOracle = await hre.ethers.getContract("RedStoneOracle");
30+
const redStoneOracleOwner = await redStoneOracle.owner();
31+
32+
if (redStoneOracleOwner === deployer) {
33+
await redStoneOracle.transferOwnership(ADDRESSES[networkName].timelock);
34+
}
35+
};
36+
37+
func.tags = ["deploy-redstone"];
38+
export default func;

0 commit comments

Comments
 (0)