Skip to content

Commit

Permalink
Merge branch 'feat/vaults' into feat/vaults-triggerable-exits
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
#	scripts/scratch/steps/0120-initialize-non-aragon-contracts.ts
  • Loading branch information
tamtamchik committed Feb 25, 2025
2 parents 586b0e2 + 80d2e49 commit f76c8c2
Show file tree
Hide file tree
Showing 14 changed files with 396 additions and 298 deletions.
9 changes: 5 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ LOCAL_STAKING_VAULT_BEACON_ADDRESS=

# RPC URL for a separate, non Hardhat Network node (Anvil, Infura, Alchemy, etc.)
MAINNET_RPC_URL=http://localhost:8545

# 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
FORK_RPC_URL=https://eth.drpc.org

# https://docs.lido.fi/deployed-contracts
MAINNET_LOCATOR_ADDRESS=0xC1d0b3DE6792Bf6b4b37EccdcC24e45978Cfd2Eb
MAINNET_AGENT_ADDRESS=0x3e40D73EB977Dc6a537aF587D48316feE66E9C8c
Expand Down Expand Up @@ -54,10 +59,6 @@ MAINNET_STAKING_VAULT_BEACON_ADDRESS=
HOLESKY_RPC_URL=
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=https://eth.drpc.org

# Scratch deployment via hardhat variables
DEPLOYER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
GENESIS_TIME=1639659600
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lib/abi/*.json
accounts.json
deployed-local.json
deployed-hardhat.json
deployed-local-devnet.json

# MacOS
.DS_Store
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ integration tests follows the `*.integration.ts` postfix, for example, `myScenar
Foundry's Solidity tests are specifically used for fuzzing library contracts or functions that perform complex
calculations or byte manipulation. These Solidity tests are located under `/tests` and organized into appropriate
subdirectories. The naming conventions follow
Foundry's [documentation](https://book.getfoundry.sh/tutorials/best-practices#general-test-guidance):
Foundry's [documentation](https://book.getfoundry.sh/guides/best-practices#general-test-guidance):
- For tests, use the `.t.sol` postfix (e.g., `MyContract.t.sol`).
- For scripts, use the `.s.sol` postfix (e.g., `MyScript.s.sol`).
Expand Down Expand Up @@ -327,7 +327,7 @@ This is the most common method for running integration tests. It uses an instanc
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
> Ensure that `FORK_RPC_URL` is set to Ethereum Mainnet RPC and `MAINNET_*` environment variables are set in the
> `.env` file (refer to `.env.example` for guidance). Otherwise, the tests will run against the Scratch deployment.
```bash
Expand Down
2 changes: 1 addition & 1 deletion deployed-holesky.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
"app:simple-dvt": {
"stakingRouterModuleParams": {
"moduleName": "SimpleDVT",
"moduleType": "simple-dvt-onchain-v1",
"moduleType": "curated-onchain-v1",
"targetShare": 50,
"moduleFee": 800,
"treasuryFee": 200,
Expand Down
24 changes: 16 additions & 8 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
declare namespace NodeJS {
export interface ProcessEnv {
/* iternal logging verbosity (used in scratch deploy / integration tests) */
/* internal logging verbosity (used in scratch deploy / integration tests) */
LOG_LEVEL?: "all" | "debug" | "info" | "warn" | "error" | "none"; // default: "info"

/**
* Flags for changing the behavior of the Hardhat Network
*/

/* RPC URL for Hardhat Network forking, required for running tests on mainnet fork with tracing */
HARDHAT_FORKING_URL?: string;
/* Test execution mode: 'scratch' for fresh network, 'fork' for forked network */
MODE?: "scratch" | "forking"; // default: "scratch"

/* URL of the network to fork from */
FORK_RPC_URL?: string; // default: "https://eth.drpc.org"

/**
* Flags for changing the behavior of the integration tests
*/

/* if "on" the integration tests will deploy the contracts to the empty Hardhat Network node using scratch deploy */
INTEGRATION_ON_SCRATCH?: "on" | "off"; // default: "off"

/* if "on" the integration tests will assume CSM module is present in the StakingRouter, and adjust accordingly */
INTEGRATION_WITH_CSM?: "on" | "off"; // default: "off"

Expand Down Expand Up @@ -82,9 +82,17 @@ declare namespace NodeJS {

/* for contract sourcecode verification with `hardhat-verify` */
ETHERSCAN_API_KEY?: string;
BLOCKSCOUT_API_KEY?: string;

/* Scratch deploy environment variables */
/* for local devnet */
LOCAL_DEVNET_PK?: string;
LOCAL_DEVNET_CHAIN_ID?: string;
LOCAL_DEVNET_EXPLORER_API_URL?: string;
LOCAL_DEVNET_EXPLORER_URL?: string;

/* scratch deploy environment variables */
NETWORK_STATE_FILE?: string;

/* hardhat plugins options */
SKIP_CONTRACT_SIZE?: boolean;
}
}
30 changes: 25 additions & 5 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { getHardhatForkingConfig, loadAccounts } from "./hardhat.helpers";

const RPC_URL: string = process.env.RPC_URL || "";

export const ZERO_PK = "0x0000000000000000000000000000000000000000000000000000000000000000";

const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
gasReporter: {
Expand All @@ -46,6 +48,14 @@ const config: HardhatUserConfig = {
"local": {
url: process.env.LOCAL_RPC_URL || RPC_URL,
},
"local-devnet": {
url: process.env.LOCAL_RPC_URL || RPC_URL,
accounts: [process.env.LOCAL_DEVNET_PK || ZERO_PK],
},
"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 @@ -60,13 +70,23 @@ const config: HardhatUserConfig = {
url: process.env.SEPOLIA_RPC_URL || RPC_URL,
chainId: 11155111,
},
"mainnet-fork": {
url: process.env.MAINNET_RPC_URL || RPC_URL,
timeout: 20 * 60 * 1000, // 20 minutes
},
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY || "",
customChains: [
{
network: "local-devnet",
chainId: parseInt(process.env.LOCAL_DEVNET_CHAIN_ID ?? "32382", 10),
urls: {
apiURL: process.env.LOCAL_DEVNET_EXPLORER_API_URL ?? "",
browserURL: process.env.LOCAL_DEVNET_EXPLORER_URL ?? "",
},
},
],
apiKey: process.env.LOCAL_DEVNET_EXPLORER_API_URL
? {
"local-devnet": "local-devnet",
}
: process.env.ETHERSCAN_API_KEY || "",
},
solidity: {
compilers: [
Expand Down
22 changes: 14 additions & 8 deletions hardhat.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ import { existsSync, readFileSync } from "node:fs";

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

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

case "forking":
if (!process.env.FORK_RPC_URL) {
throw new Error("FORK_RPC_URL must be set when MODE=forking");
}
return { url: process.env.FORK_RPC_URL };

return { url: forkingUrl };
default:
throw new Error("MODE must be either 'scratch' or 'forking'");
}
}

// TODO: this plaintext accounts.json private keys management is a subject
Expand Down
11 changes: 6 additions & 5 deletions lib/protocol/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import hre from "hardhat";
import { deployScratchProtocol, deployUpgrade, ether, findEventsWithInterfaces, impersonate, log } from "lib";

import { discover } from "./discover";
import { isNonForkingHardhatNetwork } from "./networks";
import { provision } from "./provision";
import { ProtocolContext, ProtocolContextFlags, ProtocolSigners, Signer } from "./types";

Expand All @@ -14,8 +13,11 @@ const getSigner = async (signer: Signer, balance = ether("100"), signers: Protoc
};

export const getProtocolContext = async (): Promise<ProtocolContext> => {
if (isNonForkingHardhatNetwork()) {
await deployScratchProtocol(hre.network.name);
if (hre.network.name === "hardhat") {
const networkConfig = hre.config.networks[hre.network.name];
if (!networkConfig.forking?.enabled) {
await deployScratchProtocol(hre.network.name);
}
} else {
await deployUpgrade(hre.network.name);
}
Expand All @@ -25,12 +27,11 @@ export const getProtocolContext = async (): Promise<ProtocolContext> => {

// By default, all flags are "on"
const flags = {
onScratch: process.env.INTEGRATION_ON_SCRATCH === "on",
withCSM: process.env.INTEGRATION_WITH_CSM !== "off",
} as ProtocolContextFlags;

log.debug("Protocol context flags", {
"On scratch": flags.onScratch,
"With CSM": flags.withCSM,
});

const context = {
Expand Down
1 change: 0 additions & 1 deletion lib/protocol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export type ProtocolSigners = {
export type Signer = keyof ProtocolSigners;

export type ProtocolContextFlags = {
onScratch: boolean;
withCSM: boolean;
};

Expand Down
38 changes: 18 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@
"test:trace": "hardhat test test/**/*.test.ts --trace --disabletracer",
"test:fulltrace": "hardhat test test/**/*.test.ts --fulltrace --disabletracer",
"test:watch": "SKIP_GAS_REPORT=true SKIP_CONTRACT_SIZE=true hardhat watch test",
"test:watch:trace": "SKIP_GAS_REPORT=true SKIP_CONTRACT_SIZE=true hardhat watch test --trace --disabletracer",
"test:integration": "hardhat test test/integration/**/*.ts",
"test:integration:trace": "hardhat test test/integration/**/*.ts --trace --disabletracer",
"test:integration:fulltrace": "hardhat test test/integration/**/*.ts --fulltrace --disabletracer",
"test:integration:scratch": "HARDHAT_FORKING_URL= INTEGRATION_WITH_CSM=off hardhat test test/integration/**/*.ts",
"test:integration:scratch:trace": "HARDHAT_FORKING_URL= INTEGRATION_WITH_CSM=off hardhat test test/integration/**/*.ts --trace --disabletracer",
"test:integration:scratch:fulltrace": "HARDHAT_FORKING_URL= INTEGRATION_WITH_CSM=off hardhat test test/integration/**/*.ts --fulltrace --disabletracer",
"test:integration:fork:local": "hardhat test test/integration/**/*.ts --network local",
"test:integration:fork:mainnet": "hardhat test test/integration/**/*.ts --network mainnet-fork",
"test:integration:fork:mainnet:custom": "hardhat test --network mainnet-fork",
"test:integration": "MODE=forking hardhat test test/integration/**/*.ts",
"test:integration:trace": "MODE=forking hardhat test test/integration/**/*.ts --trace --disabletracer",
"test:integration:fulltrace": "MODE=forking hardhat test test/integration/**/*.ts --fulltrace --disabletracer",
"test:integration:scratch": "MODE=scratch hardhat test test/integration/**/*.ts",
"test:integration:scratch:trace": "MODE=scratch hardhat test test/integration/**/*.ts --trace --disabletracer",
"test:integration:scratch:fulltrace": "MODE=scratch hardhat test test/integration/**/*.ts --fulltrace --disabletracer",
"test:integration:fork:local": "MODE=scratch hardhat test test/integration/**/*.ts --network local",
"test:integration:fork:mainnet": "MODE=forking hardhat test test/integration/**/*.ts --network mainnet-fork",
"test:integration:fork:mainnet:custom": "MODE=forking hardhat test --network mainnet-fork",
"typecheck": "tsc --noEmit",
"prepare": "husky",
"abis:extract": "hardhat abis:extract",
Expand All @@ -51,10 +50,10 @@
]
},
"devDependencies": {
"@commitlint/cli": "19.6.1",
"@commitlint/config-conventional": "19.6.0",
"@eslint/compat": "1.2.5",
"@eslint/js": "9.19.0",
"@commitlint/cli": "19.7.1",
"@commitlint/config-conventional": "19.7.1",
"@eslint/compat": "1.2.7",
"@eslint/js": "9.21.0",
"@nomicfoundation/hardhat-chai-matchers": "2.0.8",
"@nomicfoundation/hardhat-ethers": "3.0.8",
"@nomicfoundation/hardhat-ignition": "0.15.9",
Expand All @@ -67,22 +66,21 @@
"@typechain/hardhat": "9.1.0",
"@types/chai": "4.3.20",
"@types/eslint": "9.6.1",
"@types/eslint__js": "8.42.3",
"@types/mocha": "10.0.10",
"@types/node": "22.10.10",
"@types/node": "22.13.5",
"bigint-conversion": "2.4.3",
"chai": "4.5.0",
"chalk": "4.1.2",
"dotenv": "16.4.7",
"eslint": "9.19.0",
"eslint": "9.21.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-no-only-tests": "3.3.0",
"eslint-plugin-prettier": "5.2.3",
"eslint-plugin-simple-import-sort": "12.1.1",
"ethereumjs-util": "7.1.5",
"ethers": "6.13.5",
"glob": "11.0.1",
"globals": "15.14.0",
"globals": "15.15.0",
"hardhat": "2.22.18",
"hardhat-contract-sizer": "2.10.0",
"hardhat-gas-reporter": "1.0.10",
Expand All @@ -91,7 +89,7 @@
"hardhat-watcher": "2.5.0",
"husky": "9.1.7",
"lint-staged": "15.4.3",
"prettier": "3.4.2",
"prettier": "3.5.2",
"prettier-plugin-solidity": "1.4.2",
"solhint": "5.0.5",
"solhint-plugin-lido": "0.0.4",
Expand All @@ -100,7 +98,7 @@
"tsconfig-paths": "4.2.0",
"typechain": "8.3.2",
"typescript": "5.7.3",
"typescript-eslint": "8.21.0"
"typescript-eslint": "8.25.0"
},
"dependencies": {
"@aragon/apps-agent": "2.1.0",
Expand Down
4 changes: 2 additions & 2 deletions scripts/defaults/testnet-defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
},
"validatorsExitBusOracle": {
"deployParameters": {
"consensusVersion": 1
"consensusVersion": 2
}
},
"depositSecurityModule": {
Expand Down Expand Up @@ -144,7 +144,7 @@
},
"simpleDvt": {
"deployParameters": {
"stakingModuleTypeId": "simple-dvt-onchain-v1",
"stakingModuleTypeId": "curated-onchain-v1",
"stuckPenaltyDelay": 432000
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export async function main() {
const deployer = ethers.getAddress(getEnvVariable("DEPLOYER"));
const gateSealFactoryAddress = getEnvVariable("GATE_SEAL_FACTORY", "");
const genesisTime = parseInt(getEnvVariable("GENESIS_TIME"));
const slotsPerEpoch = parseInt(getEnvVariable("SLOTS_PER_EPOCH", "32"), 10);
const depositContractAddress = getEnvVariable("DEPOSIT_CONTRACT", "");
const withdrawalQueueBaseUri = getEnvVariable("WITHDRAWAL_QUEUE_BASE_URI", "");
const dsmPredefinedAddress = getEnvVariable("DSM_PREDEFINED_ADDRESS", "");
Expand All @@ -29,7 +30,7 @@ export async function main() {
state.deployer = deployer;

// Update state with new values from environment variables
state.chainSpec = { ...state.chainSpec, genesisTime };
state.chainSpec = { ...state.chainSpec, genesisTime, slotsPerEpoch };

if (depositContractAddress) {
state.chainSpec.depositContract = ethers.getAddress(depositContractAddress);
Expand Down
5 changes: 5 additions & 0 deletions tasks/verify-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ task("verify:deployed", "Verifies deployed contracts based on state file")
});

async function verifyContract(contract: DeployedContract, hre: HardhatRuntimeEnvironment) {
if (!contract.contract) {
// TODO: In the case of state processing on the local devnet there are skips, we need to find the cause
return;
}

log.splitter();

const contractName = contract.contractName ?? contract.contract.split("/").pop()?.split(".")[0];
Expand Down
Loading

0 comments on commit f76c8c2

Please sign in to comment.