Skip to content

Commit

Permalink
Merge pull request #115 from VenusProtocol/support-hardhat-deployments
Browse files Browse the repository at this point in the history
refactor!: support project and full protocol hardhat deploy
  • Loading branch information
coreyar authored Nov 22, 2024
2 parents 128e77d + 1986c6a commit c31a0b6
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 121 deletions.
33 changes: 17 additions & 16 deletions deploy/001-psr.ts → deploy/000-psr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const func: DeployFunction = async ({
const { deployer } = await getNamedAccounts();

const vBNBAddress = (await ethers.getContractOrNull("vBNB"))?.address || ADDRESS_ONE;
const comptrollerAddress = (await ethers.getContractOrNull("Unitroller"))?.address || ADDRESS_ONE;
const comptrollerAddress = (await ethers.getContract("Unitroller"))?.address;
const WBNBAddress = (await ethers.getContractOrNull("WBNB"))?.address || ADDRESS_ONE;
const timelockAddress = (await ethers.getContractOrNull("NormalTimelock"))?.address || multisigs[name];
const acmAddress = (await ethers.getContractOrNull("AccessControlManager"))?.address || ADDRESS_ONE;
const timelockAddress = (await ethers.getContract("NormalTimelock"))?.address || multisigs[name];
const acmAddress = (await ethers.getContract("AccessControlManager"))?.address;
const loopsLimit = 20;

const defaultProxyAdmin = await hre.artifacts.readArtifact(
Expand All @@ -28,19 +28,20 @@ const func: DeployFunction = async ({
log: true,
deterministicDeployment: false,
args: [comptrollerAddress, WBNBAddress, vBNBAddress],
skipIfAlreadyDeployed: true,
proxy: {
owner: live ? timelockAddress : deployer,
proxyContract: "OptimizedTransparentUpgradeableProxy",
execute: {
methodName: "initialize",
args: [acmAddress, loopsLimit],
},
viaAdminContract: {
name: "DefaultProxyAdmin",
artifact: defaultProxyAdmin,
},
},
proxy: live
? {
owner: timelockAddress,
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
methodName: "initialize",
args: [acmAddress, loopsLimit],
},
viaAdminContract: {
name: "DefaultProxyAdmin",
artifact: defaultProxyAdmin,
},
}
: undefined,
});

const psr = await hre.ethers.getContract("ProtocolShareReserve");
Expand Down
17 changes: 11 additions & 6 deletions deploy/006-risk-fund-v2.ts → deploy/001-risk-fund-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ const func: DeployFunction = async ({
const { deployer } = await getNamedAccounts();

const proxyAdmin = await ethers.getContract("DefaultProxyAdmin");
const owner = await proxyAdmin.owner();
let owner = deployer;
if (live) {
owner = await proxyAdmin.owner();
}

await deploy("RiskFundV2", {
from: deployer,
contract: "RiskFundV2",
proxy: {
owner: owner,
proxyContract: "OpenZeppelinTransparentProxy",
upgradeIndex: 0,
},
proxy: live
? {
owner: owner,
proxyContract: "OpenZeppelinTransparentProxy",
upgradeIndex: 0,
}
: undefined,
autoMine: true,
log: true,
});
Expand Down
78 changes: 41 additions & 37 deletions deploy/002-risk-fund-converter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseUnits } from "ethers/lib/utils";
import { ethers, network } from "hardhat";
import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

Expand All @@ -15,54 +15,58 @@ const func: DeployFunction = async ({
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const acmAddress = (await ethers.getContractOrNull("AccessControlManager"))?.address || ADDRESS_ONE;
const oracleAddress = (await ethers.getContractOrNull("ResilientOracle"))?.address || ADDRESS_ONE;
const usdtAddress = (await ethers.getContractOrNull("USDT"))?.address || ADDRESS_ONE;
const corePoolAddress = (await ethers.getContractOrNull("Unitroller"))?.address || ADDRESS_ONE;
const btcbAddress = (await ethers.getContractOrNull("BTCB"))?.address || ADDRESS_ONE;
const ethAddress = (await ethers.getContractOrNull("ETH"))?.address || ADDRESS_ONE;
const acmAddress = (await ethers.getContract("AccessControlManager"))?.address;
const oracleAddress = (await ethers.getContract("ResilientOracle"))?.address;
const usdtAddress = (await ethers.getContract("USDT"))?.address;
const corePoolAddress = (await ethers.getContract("Unitroller"))?.address;
const btcbAddress = (await ethers.getContract("BTCB"))?.address;

const ethAddress = (await ethers.getContract("ETH"))?.address;
const vBNBAddress = (await ethers.getContractOrNull("vBNB"))?.address || ADDRESS_ONE;
const wBNBAddress = (await ethers.getContractOrNull("WBNB"))?.address || ADDRESS_ONE;
const riskFundAddress = (await ethers.getContractOrNull("RiskFund"))?.address || ADDRESS_ONE;
const poolRegistryAddress = (await ethers.getContractOrNull("PoolRegistry"))?.address || ADDRESS_ONE;
const poolDeFiAddress = (await ethers.getContractOrNull("Comptroller_DeFi"))?.address || ADDRESS_ONE;
const poolGameFiAddress = (await ethers.getContractOrNull("Comptroller_GameFi"))?.address || ADDRESS_ONE;
const poolTronAddress = (await ethers.getContractOrNull("Comptroller_Tron"))?.address || ADDRESS_ONE;
const timelockAddress = (await ethers.getContractOrNull("NormalTimelock"))?.address || multisigs[name];

let poolStableCoinAddress;
if (network.name === "bscmainnet") {
poolStableCoinAddress = (await ethers.getContractOrNull("Comptroller_Stablecoins"))?.address || ADDRESS_ONE;
const riskFundAddress = (await ethers.getContract("RiskFundV2"))?.address;
const poolRegistryAddress = (await ethers.getContract("PoolRegistry"))?.address;
let comptrollers;
const timelockAddress = (await ethers.getContract("NormalTimelock"))?.address || multisigs[name];
if (live) {
const poolDeFiAddress = (await ethers.getContract("Comptroller_DeFi"))?.address;
const poolGameFiAddress = (await ethers.getContract("Comptroller_GameFi"))?.address;
const poolTronAddress = (await ethers.getContract("Comptroller_Tron"))?.address;
const poolStableCoinAddress = (await ethers.getContract("Comptroller_Stablecoins"))?.address;
comptrollers = [corePoolAddress, poolStableCoinAddress, poolDeFiAddress, poolGameFiAddress, poolTronAddress];
} else {
poolStableCoinAddress = (await ethers.getContractOrNull("Comptroller_StableCoins"))?.address || ADDRESS_ONE;
const pool1Address = (await ethers.getContractOrNull("Comptroller_Pool1"))?.address || ADDRESS_ONE;
const pool2Address = (await ethers.getContractOrNull("Comptroller_Pool2"))?.address || ADDRESS_ONE;
comptrollers = [pool1Address, pool2Address];
}

const comptrollers = [corePoolAddress, poolStableCoinAddress, poolDeFiAddress, poolGameFiAddress, poolTronAddress];
const assets = [[usdtAddress, btcbAddress, ethAddress], [usdtAddress], [usdtAddress], [usdtAddress], [usdtAddress]];
const values = [[true, true, true], [true], [true], [true], [true]];

await deploy("RiskFundConverter", {
from: deployer,
contract: "RiskFundConverter",
args: [corePoolAddress, vBNBAddress, wBNBAddress],
proxy: {
owner: live ? timelockAddress : deployer,
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
methodName: "initialize",
args: [
acmAddress,
oracleAddress,
riskFundAddress,
poolRegistryAddress,
MIN_AMOUNT_TO_CONVERT,
comptrollers,
assets,
values,
],
},
upgradeIndex: 0,
},
proxy: live
? {
owner: timelockAddress,
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
methodName: "initialize",
args: [
acmAddress,
oracleAddress,
riskFundAddress,
poolRegistryAddress,
MIN_AMOUNT_TO_CONVERT,
comptrollers,
assets,
values,
],
},
upgradeIndex: 0,
}
: undefined,
autoMine: true,
log: true,
});
Expand Down
29 changes: 15 additions & 14 deletions deploy/003-xvs-vault-treasury.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import { ethers } from "hardhat";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { ADDRESS_ONE, multisigs } from "../helpers/utils";
import { multisigs } from "../helpers/utils";

const func = async ({ network: { live, name }, getNamedAccounts, deployments }: HardhatRuntimeEnvironment) => {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const xvsAddress = (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_ONE;
const proxyOwnerAddress =
(await ethers.getContractOrNull("NormalTimelock"))?.address || multisigs[name] || ADDRESS_ONE;
const acmAddress = (await ethers.getContractOrNull("AccessControlManager"))?.address || ADDRESS_ONE;
const xvsVaultAddress = (await ethers.getContractOrNull("XVSVaultProxy"))?.address || ADDRESS_ONE;
const xvsAddress = (await ethers.getContract("XVS"))?.address;
const proxyOwnerAddress = (await ethers.getContractOrNull("NormalTimelock"))?.address || multisigs[name];
const acmAddress = (await ethers.getContract("AccessControlManager"))?.address;
const xvsVaultAddress = (await ethers.getContract("XVSVaultProxy"))?.address;

await deploy("XVSVaultTreasury", {
from: deployer,
log: true,
deterministicDeployment: false,
args: [xvsAddress],
proxy: {
owner: live ? proxyOwnerAddress : deployer,
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
methodName: "initialize",
args: [acmAddress, xvsVaultAddress],
},
},
proxy: live
? {
owner: proxyOwnerAddress,
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
methodName: "initialize",
args: [acmAddress, xvsVaultAddress],
},
}
: undefined,
});

const xvsVaultTreasury = await ethers.getContract("XVSVaultTreasury");
Expand Down
83 changes: 46 additions & 37 deletions deploy/004-single-token-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,61 @@ import { DeployResult } from "hardhat-deploy/dist/types";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { ADDRESS_ONE, ADDRESS_TWO, multisigs } from "../helpers/utils";
import { multisigs } from "../helpers/utils";

type NETWORK = "hardhat" | "bsctestnet" | "bscmainnet" | "sepolia" | "ethereum";

interface BaseAssets {
[key: string]: string;
}

async function getBaseAssets(network: string): Promise<BaseAssets> {
const networkBaseAssets: { [key: string]: BaseAssets } = {
bsctestnet: {
USDTPrimeConverter: (await ethers.getContractOrNull("USDT"))?.address || ADDRESS_ONE,
USDCPrimeConverter: (await ethers.getContractOrNull("USDC"))?.address || ADDRESS_ONE,
BTCBPrimeConverter: (await ethers.getContractOrNull("BTCB"))?.address || ADDRESS_ONE,
ETHPrimeConverter: (await ethers.getContractOrNull("ETH"))?.address || ADDRESS_ONE,
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
bscmainnet: {
USDTPrimeConverter: (await ethers.getContractOrNull("USDT"))?.address || ADDRESS_ONE,
USDCPrimeConverter: (await ethers.getContractOrNull("USDC"))?.address || ADDRESS_ONE,
BTCBPrimeConverter: (await ethers.getContractOrNull("BTCB"))?.address || ADDRESS_ONE,
ETHPrimeConverter: (await ethers.getContractOrNull("ETH"))?.address || ADDRESS_ONE,
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
sepolia: {
USDTPrimeConverter: (await ethers.getContractOrNull("MockUSDT"))?.address || ADDRESS_ONE,
USDCPrimeConverter: (await ethers.getContractOrNull("MockUSDC"))?.address || ADDRESS_ONE,
WBTCPrimeConverter: (await ethers.getContractOrNull("MockWBTC"))?.address || ADDRESS_ONE,
async function getBaseAssets(network: NETWORK): Promise<BaseAssets> {
const networkBaseAssets = {
hardhat: async () => ({
USDTPrimeConverter: (await ethers.getContract("USDT"))?.address,
USDCPrimeConverter: (await ethers.getContract("USDC"))?.address,
BTCBPrimeConverter: (await ethers.getContract("BTCB"))?.address,
ETHPrimeConverter: (await ethers.getContract("ETH"))?.address,
XVSVaultConverter: (await ethers.getContract("XVS"))?.address,
}),
bsctestnet: async () => ({
USDTPrimeConverter: (await ethers.getContract("USDT"))?.address,
USDCPrimeConverter: (await ethers.getContract("USDC"))?.address,
BTCBPrimeConverter: (await ethers.getContract("BTCB"))?.address,
ETHPrimeConverter: (await ethers.getContract("ETH"))?.address,
XVSVaultConverter: (await ethers.getContract("XVS"))?.address,
}),
bscmainnet: async () => ({
USDTPrimeConverter: (await ethers.getContract("USDT"))?.address,
USDCPrimeConverter: (await ethers.getContract("USDC"))?.address,
BTCBPrimeConverter: (await ethers.getContract("BTCB"))?.address,
ETHPrimeConverter: (await ethers.getContract("ETH"))?.address,
XVSVaultConverter: (await ethers.getContract("XVS"))?.address,
}),
sepolia: async () => ({
USDTPrimeConverter: (await ethers.getContract("MockUSDT"))?.address,
USDCPrimeConverter: (await ethers.getContract("MockUSDC"))?.address,
WBTCPrimeConverter: (await ethers.getContract("MockWBTC"))?.address,
WETHPrimeConverter: "0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9", // WETH on Sepolia
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
ethereum: {
XVSVaultConverter: (await ethers.getContract("XVS"))?.address,
}),
ethereum: async () => ({
USDTPrimeConverter: "0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT on Ethereum
USDCPrimeConverter: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
WBTCPrimeConverter: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", // WBTC on Ethereum
WETHPrimeConverter: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH on Ethereum
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
arbitrumsepolia: {
XVSVaultConverter: (await ethers.getContract("XVS"))?.address,
}),
arbitrumsepolia: async () => ({
USDTPrimeConverter: "0xf3118a17863996B9F2A073c9A66Faaa664355cf8", // USDT on arbitrum sepolia
USDCPrimeConverter: "0x86f096B1D970990091319835faF3Ee011708eAe8", // USDC on arbitrum sepolia
WBTCPrimeConverter: "0xFb8d93FD3Cf18386a5564bb5619cD1FdB130dF7D", // WBTC on arbitrum sepolia
WETHPrimeConverter: "0x980B62Da83eFf3D4576C647993b0c1D7faf17c73", // WETH on arbitrum sepolia
XVSVaultConverter: "0x877Dc896e7b13096D3827872e396927BbE704407", // XVS on arbitrum sepolia
},
}),
// add more networks
};
return networkBaseAssets[network];
return await networkBaseAssets[network]();
}

const MIN_AMOUNT_TO_CONVERT = parseUnits("10", 18).toString();
Expand All @@ -59,13 +68,13 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const networkName = network.name;
const networkName = network.name as NETWORK;

const baseAssets: BaseAssets = await getBaseAssets(networkName);

const acmAddress = (await ethers.getContractOrNull("AccessControlManager"))?.address || ADDRESS_ONE;
const oracleAddress = (await ethers.getContractOrNull("ResilientOracle"))?.address || ADDRESS_ONE;
const proxyOwnerAddress =
(await ethers.getContractOrNull("NormalTimelock"))?.address || multisigs[networkName] || ADDRESS_ONE;
const acmAddress = (await ethers.getContract("AccessControlManager"))?.address;
const oracleAddress = (await ethers.getContract("ResilientOracle"))?.address;
const proxyOwnerAddress = (await ethers.getContract("NormalTimelock"))?.address || multisigs[networkName];

const singleTokenConverterImp: DeployResult = await deploy("SingleTokenConverterImp", {
contract: "SingleTokenConverter",
Expand All @@ -88,10 +97,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
for (const singleTokenConverterName in baseAssets) {
const baseAsset: string = baseAssets[singleTokenConverterName];

let destinationAddress = (await ethers.getContractOrNull("PrimeLiquidityProvider"))?.address || ADDRESS_ONE;
let destinationAddress = (await ethers.getContract("PrimeLiquidityProvider"))?.address;

if (baseAsset == ((await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO)) {
destinationAddress = (await ethers.getContractOrNull("XVSVaultTreasury"))?.address || ADDRESS_ONE;
if (baseAsset == (await ethers.getContract("XVS"))?.address) {
destinationAddress = (await ethers.getContract("XVSVaultTreasury"))?.address;
}

const args: string[] = [acmAddress, oracleAddress, destinationAddress, baseAsset, MIN_AMOUNT_TO_CONVERT];
Expand Down
22 changes: 12 additions & 10 deletions deploy/005-converter-network.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from "hardhat";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { ADDRESS_ONE, multisigs } from "../helpers/utils";
import { multisigs } from "../helpers/utils";

const MAX_LOOPS_LIMIT = 20;

Expand All @@ -10,20 +10,22 @@ const func = async ({ network: { live, name }, getNamedAccounts, deployments }:
const { deployer } = await getNamedAccounts();

const timelockAddress = (await ethers.getContractOrNull("NormalTimelock"))?.address || multisigs[name];
const acmAddress = (await ethers.getContractOrNull("AccessControlManager"))?.address || ADDRESS_ONE;
const acmAddress = (await ethers.getContract("AccessControlManager"))?.address;

await deploy("ConverterNetwork", {
from: deployer,
log: true,
deterministicDeployment: false,
proxy: {
owner: live ? timelockAddress : deployer,
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
methodName: "initialize",
args: [acmAddress, MAX_LOOPS_LIMIT],
},
},
proxy: live
? {
owner: timelockAddress,
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
methodName: "initialize",
args: [acmAddress, MAX_LOOPS_LIMIT],
},
}
: undefined,
});

const converterNetwork = await ethers.getContract("ConverterNetwork");
Expand Down
Loading

0 comments on commit c31a0b6

Please sign in to comment.