diff --git a/deploy/001-psr.ts b/deploy/000-psr.ts similarity index 65% rename from deploy/001-psr.ts rename to deploy/000-psr.ts index 49a6fbfe..15830bea 100644 --- a/deploy/001-psr.ts +++ b/deploy/000-psr.ts @@ -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( @@ -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"); diff --git a/deploy/006-risk-fund-v2.ts b/deploy/001-risk-fund-v2.ts similarity index 82% rename from deploy/006-risk-fund-v2.ts rename to deploy/001-risk-fund-v2.ts index f607d5f8..46e2cf76 100644 --- a/deploy/006-risk-fund-v2.ts +++ b/deploy/001-risk-fund-v2.ts @@ -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, }); diff --git a/deploy/002-risk-fund-converter.ts b/deploy/002-risk-fund-converter.ts index d2d7dd13..a5869529 100644 --- a/deploy/002-risk-fund-converter.ts +++ b/deploy/002-risk-fund-converter.ts @@ -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"; @@ -15,29 +15,31 @@ 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]]; @@ -45,24 +47,26 @@ const func: DeployFunction = async ({ 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, }); diff --git a/deploy/003-xvs-vault-treasury.ts b/deploy/003-xvs-vault-treasury.ts index 10d47c09..66373bb9 100644 --- a/deploy/003-xvs-vault-treasury.ts +++ b/deploy/003-xvs-vault-treasury.ts @@ -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"); diff --git a/deploy/004-single-token-converter.ts b/deploy/004-single-token-converter.ts index 6af25f85..b1e6c8d5 100644 --- a/deploy/004-single-token-converter.ts +++ b/deploy/004-single-token-converter.ts @@ -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 { - 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 { + 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(); @@ -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", @@ -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]; diff --git a/deploy/005-converter-network.ts b/deploy/005-converter-network.ts index 799e5085..ee6ebaf1 100644 --- a/deploy/005-converter-network.ts +++ b/deploy/005-converter-network.ts @@ -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; @@ -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"); diff --git a/hardhat.config.ts b/hardhat.config.ts index 65197e9a..0017374c 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -24,6 +24,12 @@ const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY; // if we define the Oracle deployments at last then DefaultProxyAdmin of current repository will be overwritten by DefaultProxyAdmin of Oracle // when the export deployment command executes independently for each network. const externalDeployments = { + hardhat: [ + "node_modules/@venusprotocol/isolated-pools/deployments/bscmainnet", + "node_modules/@venusprotocol/venus-protocol/deployments/bscmainnet", + "node_modules/@venusprotocol/governance-contracts/deployments/bscmainnet", + "node_modules/@venusprotocol/oracle/deployments/bscmainnet", + ], bsctestnet: [ "node_modules/@venusprotocol/governance-contracts/deployments/bsctestnet", "node_modules/@venusprotocol/oracle/deployments/bsctestnet", diff --git a/helpers/utils.ts b/helpers/utils.ts index 40f07c80..31b3f288 100644 --- a/helpers/utils.ts +++ b/helpers/utils.ts @@ -18,7 +18,6 @@ export const convertToUnit = (amount: string | number, decimals: number) => { }; export const ADDRESS_ONE = "0x0000000000000000000000000000000000000001"; -export const ADDRESS_TWO = "0x0000000000000000000000000000000000000002"; interface ChainAddressesConfig { [key: string]: string;