Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VEN-1829]: Deploy Oracles on Sepolia #124

Merged
merged 45 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b4505b8
refactor: refactor vBNB logic to be chain agnostic
0xlucian Sep 4, 2023
d8febab
chore: add deployment configs for sepolia
0xlucian Sep 4, 2023
525f622
chore: add sepolia network config
0xlucian Sep 4, 2023
0e339c0
chore: add oracle deployments on Sepolia. Oracles are still not confi…
0xlucian Sep 4, 2023
a7f8d11
refactor: extract deployment config in a separate file
0xlucian Sep 4, 2023
6e6aed4
refactor: prettier
0xlucian Sep 4, 2023
e3a1a87
fix: config deploy script network name fix
0xlucian Sep 4, 2023
8bc9152
refactor: format code and fix lint
0xlucian Sep 4, 2023
b25224c
refactor: remove unused imports
0xlucian Sep 4, 2023
82562dc
fix: yarn.lock checksum
0xlucian Sep 4, 2023
7d0a7df
refactor: extract getOraclesData into a helper function
0xlucian Sep 5, 2023
2386d28
chore: add deployment config and logic in script for fixed price feeds
0xlucian Sep 6, 2023
d958008
refactor: extract preconfigured adddresses and refactor deploy script…
0xlucian Sep 6, 2023
6413c8a
chore: new deployment of oracles
0xlucian Sep 6, 2023
8e294a5
refactor: add PRIVATE_KEY env var to be used for sepolia network
0xlucian Sep 6, 2023
8bdd283
chore: add vip-based generation script containing accept ownership an…
0xlucian Sep 6, 2023
e8a58dc
fix: lint
0xlucian Sep 6, 2023
b166140
chore: add vip based configuration script for oracle
0xlucian Sep 9, 2023
cd20739
fix: oracleData to handle case when not all oracles are deployed
0xlucian Sep 9, 2023
c7451f8
fix: minor bugs
0xlucian Sep 9, 2023
94d6d55
fix: minor fix
GitGuru7 Sep 21, 2023
0334e3d
chore: update deployments
GitGuru7 Sep 21, 2023
c2a702f
Revert "chore: update deployments"
GitGuru7 Sep 21, 2023
7a00b71
refactor: remove redundancy from script
GitGuru7 Sep 21, 2023
015bb68
Apply suggestions from code review
0xlucian Oct 11, 2023
86b12e7
refactor: use notNullAddress modifier instead of if statement check
0xlucian Oct 11, 2023
8ebd43c
fix: linting
0xlucian Oct 11, 2023
ceee23c
chore: add price config for XVS, CRV and crvUSD
0xlucian Nov 2, 2023
7d5dde5
fix: uncomment necessary lines
0xlucian Nov 2, 2023
e865777
fix: yarn lock file
0xlucian Nov 3, 2023
789468d
refactor: remove duplucated utils file with addresses
0xlucian Nov 3, 2023
af9f00d
refactor: fix deployer key reference in config for sepolia and add su…
0xlucian Nov 3, 2023
6e7311f
chore: add deployment for RedStone oracle in sepolia
0xlucian Nov 3, 2023
dad9b1d
fix: deployment order
0xlucian Nov 3, 2023
32c22e6
fix: lint error
0xlucian Nov 3, 2023
c5dba92
fix: adjust PRIVATE_KEY naming
0xlucian Nov 3, 2023
e71427a
fix: redstone deployment script bug
0xlucian Nov 3, 2023
40a4560
chore: add newly deployed Redstone oracle along with DefaultProxy adm…
0xlucian Nov 4, 2023
48b88e1
fix: local deployment failure
0xlucian Nov 4, 2023
b5b34fa
refactor: replace XVS address on Sepolia with the Multichain XVS that…
0xlucian Nov 20, 2023
95db9d2
chore: use the new format in the .env file - multichain
chechu Nov 21, 2023
7ed77d1
feat: updating deployment files
chechu Nov 21, 2023
2ae9c47
chore: redeploy all oracles on sepolia
0xlucian Nov 22, 2023
2e37401
feat: updating deployment files
0xlucian Nov 22, 2023
6b8b1fb
fix: yarn lock
0xlucian Nov 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
MNEMONIC=
# true or false
FORK=false
FORKED_NETWORK=bscmainnet

DEPLOYER_PRIVATE_KEY=

## Archive nodes
ARCHIVE_NODE_bsctestnet=https://bsc-testnet.nodereal.io/v1/<YOUR_KEY_HERE>
ARCHIVE_NODE_bscmainnet=https://bsc-mainnet.nodereal.io/v1/<YOUR_KEY_HERE>
#ARCHIVE_NODE_bscmainnet=http://127.0.0.1:1248
ARCHIVE_NODE_sepolia=https://ethereum-sepolia.blockpi.network/v1/rpc/public
ARCHIVE_NODE_ethereum=https://eth-mainnet.nodereal.io/v1/<YOUR_KEY_HERE>
#ARCHIVE_NODE_ethereum=http://127.0.0.1:1248

ETHERSCAN_API_KEY=
REPORT_GAS=
FORK_MAINNET=
QUICK_NODE_URL=
REPORT_GAS=
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ jobs:
run: |
yarn hardhat export --network bsctestnet --export ./deployments/bsctestnet.json
yarn hardhat export --network bscmainnet --export ./deployments/bscmainnet.json
yarn hardhat export --network sepolia --export ./deployments/sepolia.json
yarn hardhat export --network ethereum --export ./deployments/ethereum.json
yarn prettier
- uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ npx hardhat test

```

- To run fork tests add FORK_MAINNET=true PRIVATE_KEY and QUICK_NODE_KEY in the .env file.
- To run fork tests add FORK=true, FORKED_NETWORK and one ARCHIVE_NODE var in the .env file.

## Releases and Versioning

Expand Down
30 changes: 17 additions & 13 deletions contracts/ResilientOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr

uint256 public constant INVALID_PRICE = 0;

/// @notice vBNB address
/// @notice Native market address
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address public immutable vBnb;
address public immutable nativeMarket;

/// @notice VAI address
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address public immutable vai;

/// @notice Set this as asset address for BNB. This is the underlying for vBNB
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
/// @notice Set this as asset address for Native token on each chain.This is the underlying for vBNB (on bsc)
/// and can serve as any underlying asset of a market that supports native tokens
address public constant NATIVE_TOKEN_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;

/// @notice Bound validator contract address
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
Expand Down Expand Up @@ -119,16 +120,19 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
}

/// @notice Constructor for the implementation contract. Sets immutable variables.
/// @param vBnbAddress The address of the vBNB
/// @param vaiAddress The address of the VAI
/// @dev nativeMarketAddress can be address(0) if on the chain we do not support native market
/// (e.g vETH on ethereum would not be supported, only vWETH)
/// @param nativeMarketAddress The address of a native market (for bsc it would be vBNB address)
/// @param vaiAddress The address of the VAI token (if there is VAI on the deployed chain).
/// Set to address(0) of VAI is not existent.
/// @param _boundValidator Address of the bound validator contract
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(
address vBnbAddress,
address nativeMarketAddress,
address vaiAddress,
BoundValidatorInterface _boundValidator
) notNullAddress(vBnbAddress) notNullAddress(vaiAddress) notNullAddress(address(_boundValidator)) {
vBnb = vBnbAddress;
) notNullAddress(address(_boundValidator)) {
nativeMarket = nativeMarketAddress;
Debugger022 marked this conversation as resolved.
Show resolved Hide resolved
vai = vaiAddress;
boundValidator = _boundValidator;

Expand Down Expand Up @@ -438,10 +442,10 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
* @param vToken vToken address
* @return asset underlying asset address
*/
function _getUnderlyingAsset(address vToken) private view returns (address asset) {
if (address(vToken) == vBnb) {
asset = BNB_ADDR;
} else if (address(vToken) == vai) {
function _getUnderlyingAsset(address vToken) private view notNullAddress(vToken) returns (address asset) {
if (vToken == nativeMarket) {
asset = NATIVE_TOKEN_ADDR;
} else if (vToken == vai) {
asset = vai;
} else {
asset = VBep20Interface(vToken).underlying();
Expand Down
10 changes: 6 additions & 4 deletions contracts/oracles/ChainlinkOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
struct TokenConfig {
/// @notice Underlying token address, which can't be a null address
/// @notice Used to check if a token is supported
/// @notice 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB for BNB
/// @notice 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB address for native tokens
/// (e.g BNB for BNB chain, ETH for Ethereum network)
address asset;
/// @notice Chainlink feed address
address feed;
/// @notice Price expiration period of this asset
uint256 maxStalePeriod;
}

/// @notice Set this as asset address for BNB. This is the underlying address for vBNB
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
/// @notice Set this as asset address for native token on each chain.
/// This is the underlying address for vBNB on BNB chain or an underlying asset for a native market on any chain.
address public constant NATIVE_TOKEN_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;

/// @notice Manually set an override price, useful under extenuating conditions such as price feed failure
mapping(address => uint256) public prices;
Expand Down Expand Up @@ -116,7 +118,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
function getPrice(address asset) public view returns (uint256) {
uint256 decimals;

if (asset == BNB_ADDR) {
if (asset == NATIVE_TOKEN_ADDR) {
decimals = 18;
} else {
IERC20Metadata token = IERC20Metadata(asset);
Expand Down
142 changes: 77 additions & 65 deletions deploy/1-deploy-oracles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import hre from "hardhat";
import { DeployFunction } from "hardhat-deploy/dist/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

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

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

const networkName = network.name === "bscmainnet" ? "bscmainnet" : "bsctestnet";
console.log(deployer);

const networkName: string = network.name === "hardhat" ? "bsctestnet" : network.name;

const { vBNBAddress } = ADDRESSES[networkName];
const { VAIAddress } = ADDRESSES[networkName];
Expand Down Expand Up @@ -76,99 +78,109 @@ const func: DeployFunction = async function ({ getNamedAccounts, deployments, ne
},
});

await deploy("TwapOracle", {
contract: network.live ? "TwapOracle" : "MockTwapOracle",
from: deployer,
log: true,
deterministicDeployment: false,
args: network.live ? [WBNBAddress] : [],
proxy: {
owner: proxyOwnerAddress,
proxyContract: "OptimizedTransparentProxy",
execute: {
methodName: "initialize",
args: network.live ? [accessControlManagerAddress] : [vBNBAddress],
// Skip deployment if chain is not BNB chain
if (networkName === "bsctetnet" || networkName === "bscmainnet") {
await deploy("TwapOracle", {
contract: network.live ? "TwapOracle" : "MockTwapOracle",
from: deployer,
log: true,
deterministicDeployment: false,
args: network.live ? [WBNBAddress] : [],
proxy: {
owner: proxyOwnerAddress,
proxyContract: "OptimizedTransparentProxy",
execute: {
methodName: "initialize",
args: network.live ? [accessControlManagerAddress] : [vBNBAddress],
},
},
},
});
});

const twapOracle = await hre.ethers.getContract("TwapOracle");
const twapOracleOwner = await twapOracle.owner();

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

const { pythOracleAddress } = ADDRESSES[networkName];

await deploy("PythOracle", {
contract: network.live ? "PythOracle" : "MockPythOracle",
from: deployer,
log: true,
deterministicDeployment: false,
args: [],
proxy: {
owner: proxyOwnerAddress,
proxyContract: "OptimizedTransparentProxy",
execute: {
methodName: "initialize",
args: network.live ? [pythOracleAddress, accessControlManagerAddress] : [pythOracleAddress],
// Skip if no pythOracle address in config
if (pythOracleAddress) {
await deploy("PythOracle", {
contract: network.live ? "PythOracle" : "MockPythOracle",
from: deployer,
log: true,
deterministicDeployment: false,
args: [],
proxy: {
owner: proxyOwnerAddress,
proxyContract: "OptimizedTransparentProxy",
execute: {
methodName: "initialize",
args: network.live ? [pythOracleAddress, accessControlManagerAddress] : [pythOracleAddress],
},
},
},
});
});

const { sidRegistryAddress } = ADDRESSES[networkName];
const pythOracle = await hre.ethers.getContract("PythOracle");
await accessControlManager?.giveCallPermission(pythOracle.address, "setTokenConfig(TokenConfig)", deployer);
const pythOracleOwner = await pythOracle.owner();

await deploy("BinanceOracle", {
contract: network.live ? "BinanceOracle" : "MockBinanceOracle",
from: deployer,
log: true,
deterministicDeployment: false,
args: [],
proxy: {
owner: proxyOwnerAddress,
proxyContract: "OptimizedTransparentProxy",
execute: {
methodName: "initialize",
args: network.live ? [sidRegistryAddress, accessControlManagerAddress] : [],
if (pythOracleOwner === deployer) {
await pythOracle.transferOwnership(ADDRESSES[networkName].timelock);
}
}

const { sidRegistryAddress } = ADDRESSES[networkName];
// Skip if no sidRegistryAddress address in config
if (sidRegistryAddress) {
await deploy("BinanceOracle", {
contract: network.live ? "BinanceOracle" : "MockBinanceOracle",
from: deployer,
log: true,
deterministicDeployment: false,
args: [],
proxy: {
owner: proxyOwnerAddress,
proxyContract: "OptimizedTransparentProxy",
execute: {
methodName: "initialize",
args: network.live ? [sidRegistryAddress, accessControlManagerAddress] : [],
},
},
},
});
});
const binanceOracle = await hre.ethers.getContract("BinanceOracle");
const binanceOracleOwner = await binanceOracle.owner();

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

const resilientOracle = await hre.ethers.getContract("ResilientOracle");
const pythOracle = await hre.ethers.getContract("PythOracle");
const chainlinkOracle = await hre.ethers.getContract("ChainlinkOracle");
const binanceOracle = await hre.ethers.getContract("BinanceOracle");
const twapOracle = await hre.ethers.getContract("TwapOracle");

await accessControlManager?.giveCallPermission(chainlinkOracle.address, "setTokenConfig(TokenConfig)", deployer);
await accessControlManager?.giveCallPermission(pythOracle.address, "setTokenConfig(TokenConfig)", deployer);
await accessControlManager?.giveCallPermission(resilientOracle.address, "setTokenConfig(TokenConfig)", deployer);

const resilientOracleOwner = await resilientOracle.owner();
const pythOracleOwner = await pythOracle.owner();
const binanceOracleOwner = await binanceOracle.owner();
const chainlinkOracleOwner = await chainlinkOracle.owner();
const twapOracleOwner = await twapOracle.owner();
const boundValidatorOwner = await boundValidator.owner();

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

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

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

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

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

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

export default func;
export const tags = ["deploy"];
func.tags = ["deploy"];
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import hre from "hardhat";
import { DeployFunction } from "hardhat-deploy/dist/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

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

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;
const proxyOwnerAddress = network.live ? ADDRESSES[network.name].timelock : deployer;

await deploy("RedStoneOracle", {
contract: network.live ? "ChainlinkOracle" : "MockChainlinkOracle",
Expand All @@ -21,16 +20,16 @@ const func: DeployFunction = async function ({ getNamedAccounts, deployments, ne
proxyContract: "OptimizedTransparentProxy",
execute: {
methodName: "initialize",
args: network.live ? [ADDRESSES[networkName].acm] : [],
args: network.live ? [ADDRESSES[network.name].acm] : [],
},
},
});

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

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

Expand Down
Loading
Loading