Skip to content

Commit

Permalink
Merge pull request #543 from VenusProtocol/add-fork-deployments
Browse files Browse the repository at this point in the history
Add fork deployments
  • Loading branch information
coreyar authored Jan 2, 2025
2 parents 64d1396 + 79b9230 commit 438d7c6
Show file tree
Hide file tree
Showing 27 changed files with 1,062 additions and 1,439 deletions.
4 changes: 1 addition & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# true or false
FORK=false
FORKED_NETWORK=bscmainnet

MNEMONIC="here is where your twelve words mnemonic should be put my friend"
Expand All @@ -24,4 +22,4 @@ DEPLOYER_PRIVATE_KEY=
#ARCHIVE_NODE_basemainnet=https://open-platform.nodereal.io/<YOUR_KEY_HERE>/base

ETHERSCAN_API_KEY=
REPORT_GAS=
REPORT_GAS=
2 changes: 1 addition & 1 deletion .eslinttsconfigrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["./typechain", "./deploy", "./tests", "./script", "./scenario", "saddle.config.js", "docgen-templates", "commitlint.config.js", "./hardhat.config.zksync.ts"]
"include": ["./typechain", "./deploy", "./tests", "./script", "./scenario", "saddle.config.js", "docgen-templates", "commitlint.config.js", "./hardhat.config.zksync.ts", "type-extensions.ts"]
}
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Contract tests are defined under the [tests directory](https://github.com/VenusP
```

- To run fork tests add `FORK=true`, `FORKED_NETWORK` and one `ARCHIVE_NODE` var in the `.env` file.
- To run fork tests set the`FORKED_NETWORK` var in the `.env` file. An env variable with the name `ARCHIVE_NODE_<FORKED_NETWORK>` is also required.

## Code Coverage

Expand All @@ -107,6 +107,16 @@ npx hardhat deploy
- 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.

### Dry Run / Forked Deployments

To simulate what contracts would be deployed on a given network the deployment scripts support running on a forked network. To run the deployment scripts on a forked network the `HARDHAT_FORK_NETWORK` env variable needs to be set.

For example

```bash
HARDHAT_FORK_NETWORK=ethereum npx hardhat deploy
```

### Deployed Contracts

Contract addresses deployed before `hardhat-deploy` was adopted are available in the `networking` directory in JSON files by network name.
Expand Down
33 changes: 28 additions & 5 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "@typechain/hardhat";
import fs from "fs";
import "hardhat-dependency-compiler";
import "hardhat-deploy";
import { HardhatUserConfig, extendConfig, task } from "hardhat/config";
import { HardhatUserConfig, extendConfig, extendEnvironment, task } from "hardhat/config";
import { HardhatConfig } from "hardhat/types";
import "solidity-coverage";
import "solidity-docgen";
Expand All @@ -19,6 +19,22 @@ require("dotenv").config();

const DEPLOYER_PRIVATE_KEY = process.env.DEPLOYER_PRIVATE_KEY;

const getRpcUrl = (networkName: string): string => {
let uri;
if (networkName) {
uri = process.env[`ARCHIVE_NODE_${networkName}`];
}
if (!uri) {
throw new Error(`invalid uri or network not supported by node provider : ${uri}`);
}

return uri;
};

extendEnvironment(hre => {
hre.getNetworkName = () => process.env.FORKED_NETWORK || hre.network.name;
});

extendConfig((config: HardhatConfig) => {
if (process.env.EXPORT !== "true") {
config.external = {
Expand Down Expand Up @@ -69,6 +85,15 @@ extendConfig((config: HardhatConfig) => {
},
};
}
if (process.env.HARDHAT_FORK_NETWORK) {
config!.external!.deployments!.hardhat = [

Check warning on line 89 in hardhat.config.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion

Check warning on line 89 in hardhat.config.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion

Check warning on line 89 in hardhat.config.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion
`./deployments/${process.env.HARDHAT_FORK_NETWORK}`,
`node_modules/@venusprotocol/oracle/deployments/${process.env.HARDHAT_FORK_NETWORK}`,
`node_modules/@venusprotocol/venus-protocol/deployments/${process.env.HARDHAT_FORK_NETWORK}`,
`node_modules/@venusprotocol/protocol-reserve/deployments/${process.env.HARDHAT_FORK_NETWORK}`,
`node_modules/@venusprotocol/governance-contracts/deployments/${process.env.HARDHAT_FORK_NETWORK}`,
];
}
});

task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
Expand Down Expand Up @@ -381,14 +406,12 @@ const config: HardhatUserConfig = {
};

function isFork() {
return process.env.FORK === "true"
return process.env.FORKED_NETWORK
? {
allowUnlimitedContractSize: false,
loggingEnabled: false,
forking: {
url:
process.env[`ARCHIVE_NODE_${process.env.FORKED_NETWORK}`] ||
"https://data-seed-prebsc-1-s1.binance.org:8545",
url: getRpcUrl(process.env.FORKED_NETWORK as string) || "https://data-seed-prebsc-1-s1.binance.org:8545",
blockNumber: 21068448,
},
accounts: {
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.zksync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const config: HardhatUserConfig = {
};

function isFork() {
return process.env.FORK === "true"
return process.env.FORKED_NETWORK
? {
allowUnlimitedContractSize: false,
loggingEnabled: false,
Expand Down
2 changes: 1 addition & 1 deletion script/deploy/swapRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const main = async () => {
const deployer = await signers[0].getAddress();
const swapRouterContractFactory = await ethers.getContractFactory("SwapRouter");

const network = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet" ? Mainnet : Testnet;
const network = process.env.FORKED_NETWORK === "bscmainnet" ? Mainnet : Testnet;

const WBNB = network.Contracts.WBNB;
const FACTORY = network.Contracts.pancakeFactory;
Expand Down
2 changes: 1 addition & 1 deletion tests/hardhat/Fork/BUSDLiquidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const setupFork = async (): Promise<BUSDLiquidatorFixture> => {
await busd.connect(busdHolder).transfer(someone.address, parseUnits("10000", 18));
await busd.connect(someone).approve(busdLiquidator.address, parseUnits("10000", 18));

return { comptroller, busdLiquidator, vCollateral, vBUSD, busd, treasuryAddress };
return { comptroller, busdLiquidator, vCollateral, vBUSD, busd, treasuryAddress, collateral };
};

const test = (setup: () => Promise<BUSDLiquidatorFixture>) => () => {
Expand Down
12 changes: 6 additions & 6 deletions tests/hardhat/Fork/ForceVAIDebtFirstTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Signer } from "ethers";

import { convertToUnit } from "../../../helpers/utils";
import {
Comptroller,
Comptroller__factory,
ComptrollerHarness as Comptroller,
ComptrollerHarness__factory as Comptroller__factory,
FaucetToken__factory,
IAccessControlManagerV8__factory,
IProtocolShareReserve,
Expand All @@ -20,12 +20,12 @@ import {
VAI__factory,
VBep20Delegate__factory,
} from "../../../typechain";
import { IAccessControlManager } from "../../../typechain/contracts/Governance";
import { IAccessControlManagerV8 } from "../../../typechain";
import { initMainnetUser, setForkBlock } from "./utils";

const { ethers } = require("hardhat");

const FORK_MAINNET = process.env.FORK_MAINNET === "true";
const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";

// Address of the VAI_UNITROLLER
const VAI_CONTROLLER = "0x004065D34C6b18cE4370ced1CeBDE94865DbFAFE";
Expand All @@ -45,7 +45,7 @@ const VBNB = "0xA07c5b74C9B40447a954e1466938b865b6BBea36";
const WBNB = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";

let impersonatedTimelock: Signer;
let accessControlManager: IAccessControlManager;
let accessControlManager: IAccessControlManagerV8;
let liquidatorOld: Liquidator;
let liquidatorNew: Liquidator;
let comptroller: Comptroller;
Expand All @@ -65,7 +65,7 @@ async function deployAndConfigureLiquidator() {
const liquidatorNewImpl = await liquidatorNewFactory.deploy(UNITROLLER, VBNB, WBNB);

const proxyAdmin = ProxyAdmin__factory.connect("0x2b40B43AC5F7949905b0d2Ed9D6154a8ce06084a", impersonatedTimelock);
protocolShareReserve = await smock.fake<IProtocolShareReserve>("IProtocolShareReserve");
protocolShareReserve = await smock.fake<IProtocolShareReserve>("contracts/InterfacesV8.sol:IProtocolShareReserve");

const data = liquidatorNewImpl.interface.encodeFunctionData("initialize", [
convertToUnit(5, 16),
Expand Down
2 changes: 1 addition & 1 deletion tests/hardhat/Fork/VAIControllerUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "../../../typechain";
import { around, forking, initMainnetUser } from "./utils";

const FORK_MAINNET = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet";
const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";

const forkedNetwork = () => {
const net = process.env.FORKED_NETWORK || "";
Expand Down
4 changes: 2 additions & 2 deletions tests/hardhat/Fork/VAIVaultUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { IAccessControlManager } from "../../../typechain/contracts/Governance";
import { forking } from "./utils";

const FORK_MAINNET = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet";
const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";
const bigNumber18 = BigNumber.from("1000000000000000000"); // 1e18

// Address of the vault proxy
Expand Down Expand Up @@ -54,7 +54,7 @@ async function deployAndConfigureNewVault() {

const vaiVaultProxy = VAIVaultProxy__factory.connect(vaultProxy, admin);

const vaiVaultFactory = await ethers.getContractFactory("contracts/Vault/VAIVault.sol:VAIVault");
const vaiVaultFactory = await ethers.getContractFactory("contracts/VAIVault/VAIVault.sol:VAIVault");
const vaiVaultImpl = await vaiVaultFactory.deploy();
await vaiVaultImpl.deployed();

Expand Down
2 changes: 1 addition & 1 deletion tests/hardhat/Fork/VRTVaultUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { IAccessControlManager } from "../../../typechain/contracts/Governance";
import { forking } from "./utils";

const FORK_MAINNET = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet";
const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";
const bigNumber18 = BigNumber.from("1000000000000000000"); // 1e18

// Address of the vault proxy
Expand Down
4 changes: 2 additions & 2 deletions tests/hardhat/Fork/VTokensUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
const { expect } = chai;
chai.use(smock.matchers);

const FORK_MAINNET = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet";
const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";

const NORMAL_TIMELOCK = "0x939bD8d64c0A9583A7Dcea9933f7b21697ab6396";
const ACM = "0x4788629ABc6cFCA10F9f969efdEAa1cF70c23555";
Expand All @@ -54,7 +54,7 @@ async function configureNew(vTokenAddress: string) {
await vTokenImpl.deployed();
await vTokenProxy.connect(impersonatedTimelock)._setImplementation(vTokenImpl.address, true, "0x00");
const vToken = VBep20Delegate__factory.connect(vTokenAddress, impersonatedTimelock);
protocolShareReserve = await smock.fake<IProtocolShareReserve>("IProtocolShareReserve");
protocolShareReserve = await smock.fake<IProtocolShareReserve>("ProtocolShareReserve");
await vToken.setAccessControlManager(ACM);
await accessControlManager.giveCallPermission(
vToken.address,
Expand Down
2 changes: 1 addition & 1 deletion tests/hardhat/Fork/XVSVaultUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { IAccessControlManager } from "../../../typechain/contracts/Governance";
import { forking } from "./utils";

const FORK_MAINNET = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet";
const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";

const poolId = 0;
// Address of the vault proxy
Expand Down
2 changes: 1 addition & 1 deletion tests/hardhat/Fork/XVSVaultUpgradeTimeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ forking(36322844, () => {
let xvsVaultProxy: XVSVaultProxy;
let owner: SignerWithAddress;

if (process.env.FORK === "true" && process.env.FORKED_NETWORK === "bsctestnet") {
if (process.env.FORKED_NETWORK === "bsctestnet") {
before(async () => {
await impersonateAccount(TIMELOCK);
owner = await ethers.getSigner(TIMELOCK);
Expand Down
2 changes: 1 addition & 1 deletion tests/hardhat/Fork/comptrollerXVSAddressesUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ forking(34340887, () => {
let diamond: Diamond;
let owner: SignerWithAddress;

if (process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet") {
if (process.env.FORKED_NETWORK === "bscmainnet") {
before(async () => {
await impersonateAccount(OWNER);
owner = await ethers.getSigner(OWNER);
Expand Down
2 changes: 1 addition & 1 deletion tests/hardhat/Fork/diamondTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ forking(31873700, () => {
let ownerSigner: SignerWithAddress; //eslint-disable-line
let diamondUnitroller;

if (process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet") {
if (process.env.FORKED_NETWORK === "bscmainnet") {
before(async () => {
/*
* Forking mainnet
Expand Down
8 changes: 4 additions & 4 deletions tests/hardhat/Fork/reduceResevesTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { ethers } from "hardhat";

import { convertToUnit } from "../../../helpers/utils";
import {
Comptroller,
Comptroller__factory,
ComptrollerHarness as Comptroller,
ComptrollerHarness__factory as Comptroller__factory,
IAccessControlManagerV8,
IAccessControlManagerV8__factory,
IProtocolShareReserve,
Expand All @@ -19,7 +19,7 @@ import {
import { IBEP20__factory } from "../../../typechain/factories/contracts/Utils";
import { initMainnetUser, setForkBlock } from "./utils";

const FORK_MAINNET = process.env.FORK_MAINNET === "true";
const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";

// Address of already deployed access control manager
const ACM = "0x4788629ABc6cFCA10F9f969efdEAa1cF70c23555";
Expand Down Expand Up @@ -50,7 +50,7 @@ async function deployAndConfigureLiquidator() {

const liquidatorNewFactory = await ethers.getContractFactory("Liquidator");
const liquidatorNewImpl = await liquidatorNewFactory.deploy(UNITROLLER, VBNB, WBNB);
protocolShareReserve = await smock.fake<IProtocolShareReserve>("IProtocolShareReserve");
protocolShareReserve = await smock.fake<IProtocolShareReserve>("contracts/InterfacesV8.sol:IProtocolShareReserve");
const proxyAdmin = ProxyAdmin__factory.connect("0x2b40B43AC5F7949905b0d2Ed9D6154a8ce06084a", impersonatedTimelock);
const data = liquidatorNewImpl.interface.encodeFunctionData("initialize", [
convertToUnit(5, 16),
Expand Down
2 changes: 1 addition & 1 deletion tests/hardhat/Fork/swapTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const MIN_AMOUNT_OUT_BUSD = 250;

async function deploySimpleComptroller() {
oracle = await smock.fake<PriceOracle>("PriceOracle");
accessControl = await smock.fake<IAccessControlManager>("IAccessControlManager");
accessControl = await smock.fake<IAccessControlManager>("IAccessControlManagerV8");
accessControl.isAllowedToCall.returns(true);
const ComptrollerLensFactory = await smock.mock<ComptrollerLens__factory>("ComptrollerLens");
const ComptrollerFactory = await smock.mock<ComptrollerMock__factory>("ComptrollerMock");
Expand Down
2 changes: 1 addition & 1 deletion tests/hardhat/Fork/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const initMainnetUser = async (user: string, balance?: NumberLike) => {
return ethers.getSigner(user);
};

export const FORK_MAINNET = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet";
export const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";

export const around = (expected: BigNumberish, tolerance: BigNumberish) => {
return (actual: BigNumberish) => {
Expand Down
6 changes: 4 additions & 2 deletions tests/hardhat/Fork/vBNBAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const setupMarketFixture = async (): Promise<SetupMarketFixture> => {
const vBNB = MockVBNB__factory.connect(vBNB_ADDRESS, admin);
const WBNB = WBNB__factory.connect(WBNB_ADDRESS, admin);

const protocolShareReserve = await smock.fake<IProtocolShareReserve>("IProtocolShareReserve");
const protocolShareReserve = await smock.fake<IProtocolShareReserve>(
"contracts/InterfacesV8.sol:IProtocolShareReserve",
);

const accessControl = await smock.fake<IAccessControlManagerV8>("IAccessControlManagerV8");
accessControl.isAllowedToCall.returns(true);
Expand All @@ -67,7 +69,7 @@ const setupMarketFixture = async (): Promise<SetupMarketFixture> => {
};
};

const FORK_MAINNET = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet";
const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";

if (FORK_MAINNET) {
const blockNumber = 29244056;
Expand Down
6 changes: 4 additions & 2 deletions tests/hardhat/Fork/vTokenACMUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ async function configure() {
await vBusdProxy.connect(impersonatedTimelock)._setImplementation(vBusdImpl.address, true, "0x00");
vBusd = VBep20Delegate__factory.connect(VBUSD, impersonatedTimelock);
await vBusd.setAccessControlManager(ACM);
const protocolShareReserve = await smock.fake<IProtocolShareReserve>("IProtocolShareReserve");
const protocolShareReserve = await smock.fake<IProtocolShareReserve>(
"contracts/InterfacesV8.sol:IProtocolShareReserve",
);
await grantPermission("setReduceReservesBlockDelta(uint256)");
await expect(vBusd.connect(impersonatedTimelock).setReduceReservesBlockDelta(0)).to.be.revertedWith("Invalid Input");
await vBusd.connect(impersonatedTimelock).setReduceReservesBlockDelta(1000);
await vBusd.connect(impersonatedTimelock).setProtocolShareReserve(protocolShareReserve.address);
}

const FORK_MAINNET = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet";
const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";

if (FORK_MAINNET) {
describe("VToken ACM Upgrade", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/hardhat/Fork/vTokenRedeemUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function configureTimeLock() {
impersonatedTimeLock = await initMainnetUser(NORMAL_TIMELOCK, parseUnits("2"));
}

const FORK = process.env.FORK === "true";
const FORK = !!process.env.FORKED_NETWORK;

async function setup() {
user1 = await initMainnetUser(USER_1, parseUnits("2"));
Expand Down
2 changes: 1 addition & 1 deletion tests/hardhat/Fork/vrtStopRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { convertToUnit } from "../../../helpers/utils";
import { VRT, VRTVault, VRTVaultProxy, VRTVault__factory } from "../../../typechain";
import { forking } from "./utils";

const FORK_MAINNET = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet";
const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";

const TWO_ETHER = ethers.utils.parseEther("2");
// Address of the vault proxy
Expand Down
3 changes: 2 additions & 1 deletion tests/hardhat/XVS/XVSVaultFix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ethers } from "hardhat";
import { XVSVaultProxy__factory, XVSVault__factory, XVS__factory } from "../../../typechain";

const hre = require("hardhat");
const FORK_MAINNET = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet";
const FORK_MAINNET = process.env.FORKED_NETWORK === "bscmainnet";
let FORK_ENDPOINT;

const poolId = 0;
Expand Down Expand Up @@ -235,6 +235,7 @@ describe("XVSVault", async () => {
});

it("Verify Reward Debt for affectedUser3", async () => {
console.log("FORK_ENDPOINT", FORK_ENDPOINT);
await reset(`${FORK_ENDPOINT}`, 25458045);
await sendGasCost();
await deployAndConfigureOldVault();
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"@nomiclabs/hardhat-ethers": ["node_modules/hardhat-deploy-ethers"]
}
},
"include": ["./typechain", "./deploy"],
"include": ["./typechain", "./deploy", "./helpers", "./type-extensions.ts"],
"files": ["./hardhat.config.ts"]
}
Loading

0 comments on commit 438d7c6

Please sign in to comment.