Skip to content

Commit

Permalink
Merge branch 'develop' into feat/vaults
Browse files Browse the repository at this point in the history
# Conflicts:
#	.env.example
#	hardhat.config.ts
  • Loading branch information
tamtamchik committed Jan 15, 2025
2 parents eac8eb9 + 2d11786 commit 1af937a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SEPOLIA_RPC_URL=

# RPC URL for Hardhat Network forking, required for running tests on mainnet fork with tracing (Infura, Alchemy, etc.)
# https://hardhat.org/hardhat-network/docs/guides/forking-other-networks#forking-other-networks
HARDHAT_FORKING_URL=
HARDHAT_FORKING_URL=https://eth.drpc.org

# Scratch deployment via hardhat variables
DEPLOYER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ mainnet environment, allowing you to run integration tests with trace logging.
> [!NOTE]
> Ensure that `HARDHAT_FORKING_URL` is set to Ethereum Mainnet RPC and `MAINNET_*` environment variables are set in the
> `.env` file (refer to `.env.example` for guidance).
> `.env` file (refer to `.env.example` for guidance). Otherwise, the tests will run against the Scratch deployment.
```bash
# Run all integration tests
Expand Down
82 changes: 8 additions & 74 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { existsSync, readFileSync } from "node:fs";
import path from "node:path";
import * as process from "node:process";

import "@nomicfoundation/hardhat-chai-matchers";
import "@nomicfoundation/hardhat-toolbox";
Expand All @@ -13,41 +12,15 @@ import "hardhat-watcher";
import "hardhat-ignore-warnings";
import "hardhat-contract-sizer";
import "hardhat-gas-reporter";
import { globSync } from "glob";
import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names";
import { HardhatUserConfig, subtask } from "hardhat/config";
import { HardhatUserConfig } from "hardhat/config";

import { mochaRootHooks } from "test/hooks";

import "./tasks";

const RPC_URL: string = process.env.RPC_URL || "";
const ACCOUNTS_PATH = "./accounts.json";

const HARDHAT_FORKING_URL = process.env.HARDHAT_FORKING_URL || "";

const INTEGRATION_WITH_SCRATCH_DEPLOY = process.env.INTEGRATION_WITH_SCRATCH_DEPLOY || "off";

/* Determines the forking configuration for Hardhat */
function getHardhatForkingConfig() {
if (INTEGRATION_WITH_SCRATCH_DEPLOY === "on" || !HARDHAT_FORKING_URL) {
return undefined;
}
return { url: HARDHAT_FORKING_URL };
}
import { getHardhatForkingConfig, loadAccounts } from "./hardhat.helpers";

function loadAccounts(networkName: string) {
// TODO: this plaintext accounts.json private keys management is a subject
// of rework to a solution with the keys stored encrypted
if (!existsSync(ACCOUNTS_PATH)) {
return [];
}
const content = JSON.parse(readFileSync(ACCOUNTS_PATH, "utf-8"));
if (!content.eth) {
return [];
}
return content.eth[networkName] || [];
}
const RPC_URL: string = process.env.RPC_URL || "";

const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
Expand All @@ -73,18 +46,6 @@ const config: HardhatUserConfig = {
"local": {
url: process.env.LOCAL_RPC_URL || RPC_URL,
},
"holesky-vaults-devnet-0": {
url: process.env.LOCAL_RPC_URL || RPC_URL,
timeout: 20 * 60 * 1000, // 20 minutes
},
"mekong-vaults-devnet-1": {
url: process.env.LOCAL_RPC_URL || RPC_URL,
timeout: 20 * 60 * 1000, // 20 minutes
},
"mainnet-fork": {
url: process.env.MAINNET_RPC_URL || RPC_URL,
timeout: 20 * 60 * 1000, // 20 minutes
},
"holesky": {
url: process.env.HOLESKY_RPC_URL || RPC_URL,
chainId: 17000,
Expand All @@ -99,28 +60,13 @@ const config: HardhatUserConfig = {
url: process.env.SEPOLIA_RPC_URL || RPC_URL,
chainId: 11155111,
},
"mekong": {
url: process.env.MEKONG_RPC_URL || RPC_URL,
chainId: 7078815900,
accounts: loadAccounts("mekong"),
"mainnet-fork": {
url: process.env.MAINNET_RPC_URL || RPC_URL,
timeout: 20 * 60 * 1000, // 20 minutes
},
},
etherscan: {
apiKey: {
default: process.env.ETHERSCAN_API_KEY || "",
holesky: process.env.ETHERSCAN_API_KEY || "",
mekong: process.env.BLOCKSCOUT_API_KEY || "",
},
customChains: [
{
network: "mekong",
chainId: 7078815900,
urls: {
apiURL: "https://explorer.mekong.ethpandaops.io/api",
browserURL: "https://explorer.mekong.ethpandaops.io",
},
},
],
apiKey: process.env.ETHERSCAN_API_KEY || "",
},
solidity: {
compilers: [
Expand Down Expand Up @@ -231,16 +177,4 @@ const config: HardhatUserConfig = {
},
};

// a workaround for having an additional source directory for compilation
// see, https://github.com/NomicFoundation/hardhat/issues/776#issuecomment-1713584386
subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, hre, runSuper) => {
const paths = await runSuper();

const otherDirectoryGlob = path.join(hre.config.paths.root, "test", "**", "*.sol");
// Don't need to compile test, helper and script files that are not part of the contracts for Hardhat.
const otherPaths = globSync(otherDirectoryGlob).filter((x) => !/\.([ths]\.sol)$/.test(x));

return [...paths, ...otherPaths];
});

export default config;
32 changes: 32 additions & 0 deletions hardhat.helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { existsSync, readFileSync } from "node:fs";

/* Determines the forking configuration for Hardhat */
export function getHardhatForkingConfig() {
const forkingUrl = process.env.HARDHAT_FORKING_URL || "";

if (!forkingUrl) {
// Scratch deploy, need to disable CSM
process.env.INTEGRATION_ON_SCRATCH = "on";
process.env.INTEGRATION_WITH_CSM = "off";
return undefined;
}

return { url: forkingUrl };
}

// TODO: this plaintext accounts.json private keys management is a subject
// of rework to a solution with the keys stored encrypted
export function loadAccounts(networkName: string) {
const accountsPath = "./accounts.json";

if (!existsSync(accountsPath)) {
return [];
}

const content = JSON.parse(readFileSync(accountsPath, "utf-8"));
if (!content.eth) {
return [];
}

return content.eth[networkName] || [];
}
1 change: 1 addition & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./verify-contracts";
export * from "./extract-abis";
export * from "./solidity-get-source";
18 changes: 18 additions & 0 deletions tasks/solidity-get-source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import path from "node:path";

import { globSync } from "glob";
import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names";
import { subtask } from "hardhat/config";

// a workaround for having an additional source directory for compilation
// see, https://github.com/NomicFoundation/hardhat/issues/776#issuecomment-1713584386

subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, hre, runSuper) => {
const paths = await runSuper();

const otherDirectoryGlob = path.join(hre.config.paths.root, "test", "**", "*.sol");
// Don't need to compile test, helper and script files that are not part of the contracts for Hardhat.
const otherPaths = globSync(otherDirectoryGlob).filter((x) => !/\.([ths]\.sol)$/.test(x));

return [...paths, ...otherPaths];
});

0 comments on commit 1af937a

Please sign in to comment.