Skip to content

Commit

Permalink
feat: add fork deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Dec 30, 2024
1 parent 7494c2f commit d37a53a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 70 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"]
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 27 additions & 2 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 @@ -387,7 +412,7 @@ function isFork() {
loggingEnabled: false,
forking: {
url:
process.env[`ARCHIVE_NODE_${process.env.FORKED_NETWORK}`] ||
getRpcUrl(process.env.FORKED_NETWORK as string) ||
"https://data-seed-prebsc-1-s1.binance.org:8545",
blockNumber: 21068448,
},
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"]
}
7 changes: 7 additions & 0 deletions type-extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import "hardhat/types/runtime";

declare module "hardhat/types/runtime" {
export interface HardhatRuntimeEnvironment {
getNetworkName: () => string;
}
}
64 changes: 1 addition & 63 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3551,17 +3551,6 @@ __metadata:
languageName: node
linkType: hard

"@venusprotocol/governance-contracts@npm:^2.4.0":
version: 2.4.0
resolution: "@venusprotocol/governance-contracts@npm:2.4.0"
dependencies:
"@venusprotocol/solidity-utilities": 2.0.0
hardhat-deploy-ethers: ^0.3.0-beta.13
module-alias: ^2.2.2
checksum: 2a754a05a655bc7b24c33685f86c9bd616a6e7cba4b048315b11eca67a8c1e37c033f04e1b4394e7326251b6af49ab257275cef72727c8976ae16c7f2c2ff0e7
languageName: node
linkType: hard

"@venusprotocol/governance-contracts@npm:^2.6.0":
version: 2.6.0
resolution: "@venusprotocol/governance-contracts@npm:2.6.0"
Expand Down Expand Up @@ -3594,24 +3583,6 @@ __metadata:
languageName: node
linkType: hard

"@venusprotocol/protocol-reserve@npm:^2.4.0":
version: 2.4.0
resolution: "@venusprotocol/protocol-reserve@npm:2.4.0"
dependencies:
"@nomiclabs/hardhat-ethers": ^2.2.3
"@openzeppelin/contracts": ^4.8.3
"@openzeppelin/contracts-upgradeable": ^4.8.3
"@openzeppelin/hardhat-upgrades": ^1.21.0
"@solidity-parser/parser": ^0.13.2
"@venusprotocol/solidity-utilities": ^2.0.3
"@venusprotocol/venus-protocol": ^9.1.0
ethers: ^5.7.0
hardhat-deploy: ^0.11.14
module-alias: ^2.2.2
checksum: 6e5ffa1c458cff073f9b920ab6385d9db0c86ac11d0950fe421a853e709ee12ec0013c6d3e9cb4e50e94f749dcd33e7a515d57828c5aa6f925dee8324e896ee5
languageName: node
linkType: hard

"@venusprotocol/protocol-reserve@npm:^3.0.0":
version: 3.0.0
resolution: "@venusprotocol/protocol-reserve@npm:3.0.0"
Expand Down Expand Up @@ -3644,21 +3615,6 @@ __metadata:
languageName: node
linkType: hard

"@venusprotocol/token-bridge@npm:^2.3.0":
version: 2.3.0
resolution: "@venusprotocol/token-bridge@npm:2.3.0"
dependencies:
"@layerzerolabs/solidity-examples": ^1.0.0
"@openzeppelin/contracts": ^4.8.3
"@openzeppelin/contracts-upgradeable": ^4.8.3
"@openzeppelin/hardhat-upgrades": ^1.21.0
"@solidity-parser/parser": ^0.13.2
ethers: ^5.7.0
module-alias: ^2.2.2
checksum: c9f3dcf9eb014592404de14998f817c230e51ec640074ad0811c4ab21e141478b91daefe949b51fc80d6437f3b1f1bb9f606f2c50c2720b01a2e673008208917
languageName: node
linkType: hard

"@venusprotocol/token-bridge@npm:^2.4.0":
version: 2.4.0
resolution: "@venusprotocol/token-bridge@npm:2.4.0"
Expand All @@ -3674,25 +3630,7 @@ __metadata:
languageName: node
linkType: hard

"@venusprotocol/venus-protocol@npm:^9.1.0":
version: 9.3.0
resolution: "@venusprotocol/venus-protocol@npm:9.3.0"
dependencies:
"@nomicfoundation/hardhat-ethers": ^3.0.0
"@openzeppelin/contracts": 4.9.3
"@openzeppelin/contracts-upgradeable": ^4.8.0
"@venusprotocol/governance-contracts": ^2.4.0
"@venusprotocol/protocol-reserve": ^2.4.0
"@venusprotocol/solidity-utilities": ^2.0.3
"@venusprotocol/token-bridge": ^2.3.0
bignumber.js: ^9.1.2
dotenv: ^16.0.1
module-alias: ^2.2.2
checksum: e9869d63a5c6a4f00ad091357cf76ee6b27a2c61459e69e6818fb36fedb677ae4717c047c5241c6993b86ce29d8657e69abbd88ce4f3344d636a0069ca1559d2
languageName: node
linkType: hard

"@venusprotocol/venus-protocol@workspace:.":
"@venusprotocol/venus-protocol@^9.1.0, @venusprotocol/venus-protocol@workspace:.":
version: 0.0.0-use.local
resolution: "@venusprotocol/venus-protocol@workspace:."
dependencies:
Expand Down

0 comments on commit d37a53a

Please sign in to comment.