Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ npx hardhat deploy
- This command will execute all the deployment scripts in `./deploy` directory - It will skip only deployment scripts which implement a `skip` condition - Here is example of a skip condition: - Skipping deployment script on `bsctestnet` network `func.skip = async (hre: HardhatRuntimeEnvironment) => hre.network.name !== "bsctestnet";`
- The default network will be `hardhat`
- Deployment to another network: - Make sure the desired network is configured in `hardhat.config.ts` - Add `MNEMONIC` variable in `.env` file - Execute deploy command by adding `--network <network_name>` in the deploy command above - E.g. `npx hardhat deploy --network bsctestnet`
- Local Hardhat node: start `npx hardhat node` in one terminal, then run `npx hardhat deploy --network localhost` in another
- Execution of single or custom set of scripts is possible, if:
- In the deployment scripts you have added `tags` for example: - `func.tags = ["MockTokens"];`
- Once this is done, adding `--tags "<tag_name>,<tag_name>..."` to the deployment command will execute only the scripts containing the tags.
Expand Down
1 change: 1 addition & 0 deletions deploy/005-deploy-VTreasuryV8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
bscmainnet: await getTimelock(),
bsctestnet: await getTimelock(),
hardhat: deployer,
localhost: deployer,,
};

const deployerSigner = await hre.ethers.getSigner(deployer);
Expand Down
10 changes: 5 additions & 5 deletions deploy/006-deploy-psm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { skipRemoteNetworks } from "../helpers/deploymentConfig";
import { isLocalNetwork, skipRemoteNetworks } from "../helpers/deploymentConfig";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, network, getNamedAccounts, getChainId } = hre;
Expand All @@ -16,11 +16,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const usdtAddress = (await deployments.get("USDT")).address;
const acmAddress = (await deployments.get("AccessControlManager")).address;
const treasuryAddress = (await deployments.get(hre.network.name == "hardhat" ? "VTreasuryV8" : "VTreasury")).address;
const treasuryAddress = (await deployments.get(isLocalNetwork(network.name) ? "VTreasuryV8" : "VTreasury")).address;
const oracleAddress = (await deployments.get("ResilientOracle")).address;

let normalVipTimelockAddress;
if (hre.network.name === "hardhat") {
if (isLocalNetwork(network.name)) {
normalVipTimelockAddress = (
await deploy("NormalTimelock", {
contract: "TestTimelockV8",
Expand Down Expand Up @@ -55,7 +55,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
autoMine: true,
proxy: {
owner: network.name === "hardhat" ? deployer : normalVipTimelockAddress,
owner: isLocalNetwork(network.name) ? deployer : normalVipTimelockAddress,
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
methodName: "initialize",
Expand All @@ -66,7 +66,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const psm = await ethers.getContract("PegStability_USDT");

if (network.name !== "hardhat") {
if (!isLocalNetwork(network.name)) {
const timelockAddress = normalVipTimelockAddress;
await psm.transferOwnership(timelockAddress);
console.log(`PSM Contract (${psm.address}) owner changed from ${deployer} to ${timelockAddress}`);
Expand Down
4 changes: 2 additions & 2 deletions deploy/006-update-liquidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseUnits } from "ethers/lib/utils";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { skipRemoteNetworks } from "../helpers/deploymentConfig";
import { isLocalNetwork, skipRemoteNetworks } from "../helpers/deploymentConfig";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, network, getNamedAccounts } = hre;
Expand All @@ -27,7 +27,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
autoMine: true,
proxy: {
owner: network.name === "hardhat" ? deployer : timelockAddress,
owner: isLocalNetwork(network.name) ? deployer : timelockAddress,
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
methodName: "initialize",
Expand Down
6 changes: 3 additions & 3 deletions deploy/007-deploy-VBNBAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { skipRemoteNetworks } from "../helpers/deploymentConfig";
import { isLocalNetwork, skipRemoteNetworks } from "../helpers/deploymentConfig";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, network, getNamedAccounts } = hre;
Expand All @@ -26,7 +26,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
autoMine: true,
proxy: {
owner: network.name === "hardhat" ? deployer : normalVipTimelockAddress,
owner: isLocalNetwork(network.name) ? deployer : normalVipTimelockAddress,
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
methodName: "initialize",
Expand All @@ -37,7 +37,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const vBNBAdmin = await ethers.getContract("VBNBAdmin");

if (network.name !== "hardhat") {
if (!isLocalNetwork(network.name)) {
await vBNBAdmin.transferOwnership(normalVipTimelockAddress);
console.log(
`VBNBAdmin Contract (${vBNBAdmin.address}) owner changed from ${deployer} to ${normalVipTimelockAddress}`,
Expand Down
1 change: 1 addition & 0 deletions deploy/009-configure-vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
unichainsepolia: unichainsepoliaGovernanceDeployments.contracts.NormalTimelock.address,
unichainmainnet: unichainmainnetGovernanceDeployments.contracts.NormalTimelock.address,
hardhat: deployer,
localhost: deployer,,
};

const accessControlManager = await ethers.getContract("AccessControlManager");
Expand Down
9 changes: 6 additions & 3 deletions deploy/012-deploy-prime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { getContractAddressOrNullAddress } from "../helpers/deploymentConfig";
import { isLocalNetwork, getContractAddressOrNullAddress } from "../helpers/deploymentConfig";

interface AdminAccounts {
[key: string]: string;
Expand All @@ -25,6 +25,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}
const stakingPeriod: Config = {
hardhat: TEN_MINUTES,
localhost: TEN_MINUTES,,
bsctestnet: TEN_MINUTES,
sepolia: TEN_MINUTES,
arbitrumsepolia: TEN_MINUTES,
Expand Down Expand Up @@ -54,6 +55,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
opmainnet: 0,
unichainsepolia: 0,
hardhat: 0,
localhost: 0,,
basesepolia: 0,
basemainnet: 0,
unichainmainnet: 0,
Expand All @@ -75,6 +77,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
bscmainnet: 70_080_000,
ethereum: 2_628_000,
hardhat: 100,
localhost: 100,,
};

const networkName: string = network.name;
Expand Down Expand Up @@ -125,7 +128,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
deterministicDeployment: false,
args: [isTimeBased, blocksPerYear[networkName]],
proxy: {
owner: network.name === "hardhat" ? deployer : adminAccount[networkName],
owner: isLocalNetwork(network.name) ? deployer : adminAccount[networkName],
proxyContract: "OptimizedTransparentUpgradeableProxy",
execute: {
methodName: "initialize",
Expand Down Expand Up @@ -154,7 +157,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
isTimeBased,
],
proxy: {
owner: network.name === "hardhat" ? deployer : adminAccount[networkName],
owner: isLocalNetwork(network.name) ? deployer : adminAccount[networkName],
proxyContract: "OptimizedTransparentUpgradeableProxy",
execute: {
methodName: "initialize",
Expand Down
4 changes: 2 additions & 2 deletions deploy/013-configure-prime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { getContractAddressOrNullAddress } from "../helpers/deploymentConfig";
import { isLocalNetwork, getContractAddressOrNullAddress } from "../helpers/deploymentConfig";

interface AdminAccounts {
[key: string]: string;
Expand Down Expand Up @@ -33,7 +33,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const prime = await ethers.getContract("Prime");
const plp = await ethers.getContract("PrimeLiquidityProvider");

if (network.name !== "hardhat") {
if (!isLocalNetwork(network.name)) {
console.log("Transferring Prime ownership to Timelock");
await prime.transferOwnership(adminAccount[network.name]);

Expand Down
9 changes: 5 additions & 4 deletions deploy/014-deploy-prime-leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { getContractAddressOrNullAddress } from "../helpers/deploymentConfig";
import { isLocalNetwork, getContractAddressOrNullAddress } from "../helpers/deploymentConfig";

interface AdminAccounts {
[key: string]: string;
Expand Down Expand Up @@ -30,6 +30,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
opmainnet: 0,
unichainsepolia: 0,
hardhat: 0,
localhost: 0,,
basesepolia: 0,
basemainnet: 0,
unichainmainnet: 0,
Expand Down Expand Up @@ -72,7 +73,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
deterministicDeployment: false,
args: constructorArgs,
proxy: {
owner: network.name === "hardhat" ? deployer : adminAccount[networkName],
owner: isLocalNetwork(network.name) ? deployer : adminAccount[networkName],
proxyContract: "OptimizedTransparentUpgradeableProxy",
execute: {
methodName: "initialize",
Expand All @@ -89,7 +90,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`PrimeLeaderboard deployed: ${primeLeaderboard.address}`);

// ============ Verify implementation ============
if (network.name !== "hardhat" && primeLeaderboardDeployment.implementation) {
if (!isLocalNetwork(network.name) && primeLeaderboardDeployment.implementation) {
try {
await hre.run("verify:verify", {
address: primeLeaderboardDeployment.implementation,
Expand All @@ -101,7 +102,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}

// ============ Transfer ownership to Timelock ============
if (network.name !== "hardhat") {
if (!isLocalNetwork(network.name)) {
console.log("Transferring PrimeLeaderboard ownership to Timelock...");
await primeLeaderboard.transferOwnership(adminAccount[networkName]);
console.log(`PrimeLeaderboard ownership transfer initiated to ${adminAccount[networkName]} (pending acceptance)`);
Expand Down
12 changes: 7 additions & 5 deletions deploy/014-deploy-prime-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { getContractAddressOrNullAddress } from "../helpers/deploymentConfig";
import { isLocalNetwork, getContractAddressOrNullAddress } from "../helpers/deploymentConfig";

interface AdminAccounts {
[key: string]: string;
Expand Down Expand Up @@ -35,6 +35,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
bscmainnet: 70_080_000,
ethereum: 2_628_000,
hardhat: 100,
localhost: 100,,
};

const xVSVaultPoolId: Config = {
Expand All @@ -50,6 +51,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
opmainnet: 0,
unichainsepolia: 0,
hardhat: 0,
localhost: 0,,
basesepolia: 0,
basemainnet: 0,
unichainmainnet: 0,
Expand Down Expand Up @@ -112,7 +114,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
deterministicDeployment: false,
args: constructorArgs,
proxy: {
owner: network.name === "hardhat" ? deployer : adminAccount[networkName],
owner: isLocalNetwork(network.name) ? deployer : adminAccount[networkName],
proxyContract: "OptimizedTransparentUpgradeableProxy",
execute: {
methodName: "initialize",
Expand All @@ -136,7 +138,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const primeV2 = await ethers.getContract("PrimeV2");

// ============ Verify implementation ============
if (network.name !== "hardhat" && primeV2Deployment.implementation) {
if (!isLocalNetwork(network.name) && primeV2Deployment.implementation) {
try {
await hre.run("verify:verify", {
address: primeV2Deployment.implementation,
Expand All @@ -151,7 +153,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// On live networks the setPrimeV2 / setPrimeLeaderboard wiring is performed via a VIP
// (both setters are ACM-gated and called by governance). On hardhat we grant the deployer
// permission and wire inline so local/integration runs have a usable, fully-wired pair.
if (network.name === "hardhat") {
if (isLocalNetwork(network.name)) {
const accessControlManager = await ethers.getContract("AccessControlManager");
await accessControlManager.giveCallPermission(primeLeaderboard.address, "setPrimeV2(address)", deployer);
await accessControlManager.giveCallPermission(primeV2.address, "setPrimeLeaderboard(address)", deployer);
Expand All @@ -165,7 +167,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}

// ============ Transfer ownership to Timelock ============
if (network.name !== "hardhat") {
if (!isLocalNetwork(network.name)) {
console.log("Transferring PrimeV2 ownership to Timelock...");
await primeV2.transferOwnership(adminAccount[networkName]);
console.log(`PrimeV2 ownership transfer initiated to ${adminAccount[networkName]} (pending acceptance)`);
Expand Down
6 changes: 4 additions & 2 deletions deploy/015-deploy-prime-v2-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { getContractAddressOrNullAddress } from "../helpers/deploymentConfig";
import { isLocalNetwork, getContractAddressOrNullAddress } from "../helpers/deploymentConfig";

/**
* Deploys ONLY a new PrimeV2 implementation contract — no proxy, no wiring.
Expand Down Expand Up @@ -37,6 +37,7 @@ const blocksPerYear: Config = {
bscmainnet: 70_080_000,
ethereum: 2_628_000,
hardhat: 100,
localhost: 100,,
};

const xVSVaultPoolId: Config = {
Expand All @@ -52,6 +53,7 @@ const xVSVaultPoolId: Config = {
opmainnet: 0,
unichainsepolia: 0,
hardhat: 0,
localhost: 0,,
basesepolia: 0,
basemainnet: 0,
unichainmainnet: 0,
Expand Down Expand Up @@ -95,7 +97,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`PrimeV2 implementation: ${implDeployment.address}`);

// ============ Verify implementation ============
if (network.name !== "hardhat") {
if (!isLocalNetwork(network.name)) {
try {
await hre.run("verify:verify", {
address: implDeployment.address,
Expand Down
3 changes: 2 additions & 1 deletion deploy/015-deploy-token-redeemer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isLocalNetwork } from "../helpers/deploymentConfig";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

Expand All @@ -19,6 +20,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
};

func.tags = ["TokenRedeemer"];
func.skip = async hre => hre.network.name !== "hardhat" && hre.network.name !== "bscmainnet";
func.skip = async hre => !isLocalNetwork(hre.network.name) && hre.network.name !== "bscmainnet";

export default func;
3 changes: 2 additions & 1 deletion deploy/016-deploy-prime-lens.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isLocalNetwork } from "../helpers/deploymentConfig";
import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
Expand Down Expand Up @@ -32,7 +33,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`PrimeLens: ${lensDeployment.address}`);
console.log(` reads from PrimeV2: ${primeV2.address}`);

if (network.name !== "hardhat") {
if (!isLocalNetwork(network.name)) {
try {
await hre.run("verify:verify", {
address: lensDeployment.address,
Expand Down
5 changes: 3 additions & 2 deletions deploy/019-deploy-bstock-liquidator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isLocalNetwork } from "../helpers/deploymentConfig";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

Expand All @@ -24,8 +25,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// - Ownable owner (OPERATIONAL admin) -> the bStock owner Safe, set directly in `initialize`.
// On hardhat both collapse to the deployer so tests can drive them.
const timelockAddress = (await deployments.get("NormalTimelock")).address;
const proxyAdmin = network.name === "hardhat" ? deployer : timelockAddress;
const contractOwner = network.name === "hardhat" ? deployer : BSTOCK_LIQUIDATOR_OWNER;
const proxyAdmin = isLocalNetwork(network.name) ? deployer : timelockAddress;
const contractOwner = isLocalNetwork(network.name) ? deployer : BSTOCK_LIQUIDATOR_OWNER;

await catchUnknownSigner(
deploy("BStockLiquidator", {
Expand Down
5 changes: 5 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ const config: HardhatUserConfig = {
live: true,
accounts: DEPLOYER_PRIVATE_KEY ? [`0x${DEPLOYER_PRIVATE_KEY}`] : [],
},
localhost: {
url: process.env.ARCHIVE_NODE_localhost || "http://127.0.0.1:8545",
chainId: 31337,
},
},
sourcify: {
enabled: false,
Expand Down Expand Up @@ -348,6 +352,7 @@ const config: HardhatUserConfig = {
paths: [
"hardhat-deploy/solc_0.8/proxy/OptimizedTransparentUpgradeableProxy.sol",
"hardhat-deploy/solc_0.8/openzeppelin/proxy/transparent/ProxyAdmin.sol",
"contracts/test/MockToken.sol",
],
},
};
Expand Down
2 changes: 2 additions & 0 deletions helpers/chains.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const knownChains = [
"hardhat",
"localhost",
"bsctestnet",
"bscmainnet",
"sepolia",
Expand All @@ -24,6 +25,7 @@ export type BlocksPerYear = number | "time-based";

export const blocksPerYear = {
hardhat: 100,
localhost: 100,
bsctestnet: 70_080_000, // 0.45 sec per block
bscmainnet: 70_080_000,
sepolia: 2_628_000, // 12 sec per block
Expand Down
Loading