Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: local devnet #896

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
483b442
feat: initial deploy to local devnet
eddort Dec 11, 2024
e5aa190
feat: speed up scratch deployment for local-devnet
eddort Dec 11, 2024
ee55926
refactor: add deployed-local-devnet.json to gitignore
eddort Dec 11, 2024
ce8c268
chore: add default pk for local devnet
tamtamchik Dec 12, 2024
41a7a7a
test: add Sepolia deposit contract interface
vp4242 Aug 23, 2024
b8b27cc
test: add Sepolia-specific configuration
vp4242 Aug 23, 2024
ce7d3cd
test: add workaround for sdvt module missing on Sepolia
vp4242 Aug 23, 2024
44aaa42
test: add negative rebase integration tests
vp4242 Aug 23, 2024
5c4f6ba
test: fixes according to modern changes
vp4242 Dec 17, 2024
43b2ec4
feat: remove special handling for sdvt
vp4242 Dec 17, 2024
d1b7819
test: fix initialization for scratch deploy case
vp4242 Dec 17, 2024
f5937f9
test: isolate test environment from other suite
vp4242 Dec 17, 2024
2983d01
feat: decrease voting time for devnet
eddort Dec 17, 2024
e90216a
test: move initialization in before()
vp4242 Dec 17, 2024
c633385
Merge pull request #862 from lidofinance/feat/neg-rebase-sepolia-inte…
vp4242 Dec 17, 2024
e879318
fix: consensusVersion in VEBO defaults
eddort Dec 19, 2024
ce1e448
feat: update default params for devnet
eddort Dec 19, 2024
e622b3b
feat: custom SLOTS_PER_EPOCH support
eddort Dec 22, 2024
6c8bab8
fix: change the module type on curated-onchain-v1 for SimpleDVT in th…
Amuhar Dec 24, 2024
51ae54d
feat: add script that allows pass pattern of tes files, for integrati…
BATMAH69 Dec 26, 2024
aa5c7c7
Merge pull request #909 from BATMAH69/feat/script-with-pattern-support
tamtamchik Dec 27, 2024
9cf4bb9
chore: update develop from master
tamtamchik Jan 9, 2025
49c9751
Merge pull request #916 from lidofinance/feat/develop-sync
tamtamchik Jan 13, 2025
d6caa03
fix: refactor hardhat config file
tamtamchik Jan 14, 2025
2d11786
Merge pull request #921 from lidofinance/feat/fix-integrations
tamtamchik Jan 15, 2025
2c5f189
Merge commit '2d11786ebc1f06165c501fa8e9fecef053e12ab9' into feat/loc…
mkurayan Jan 30, 2025
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
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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
HARDHAT_FORKING_URL=
HARDHAT_FORKING_URL=https://eth.drpc.org

# https://docs.lido.fi/deployed-contracts
MAINNET_LOCATOR_ADDRESS=0xC1d0b3DE6792Bf6b4b37EccdcC24e45978Cfd2Eb
Expand Down Expand Up @@ -61,3 +61,6 @@ GAS_MAX_FEE=100

# Etherscan API key for verifying contracts
ETHERSCAN_API_KEY=

# Local devnet private key
LOCAL_DEVNET_PK=0x0000000000000000000000000000000000000000000000000000000000000000
2 changes: 1 addition & 1 deletion .github/workflows/tests-integration-mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

services:
hardhat-node:
image: ghcr.io/lidofinance/hardhat-node:2.22.12
image: ghcr.io/lidofinance/hardhat-node:2.22.17
ports:
- 8545:8545
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-integration-scratch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

services:
hardhat-node:
image: ghcr.io/lidofinance/hardhat-node:2.22.12-scratch
image: ghcr.io/lidofinance/hardhat-node:2.22.17-scratch
ports:
- 8555:8545

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ lib/abi/*.json
accounts.json
deployed-local.json
deployed-hardhat.json
deployed-local-devnet.json

# MacOS
.DS_Store
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This is the core repository of the Lido on Ethereum protocol. The entire codebas
---

<div>
<img alt="Lido" src="https://img.shields.io/badge/v2-version?label=lido&labelColor=rgb(91%2C%20162%2C%20252)&color=white"/>
<img alt="Lido" src="https://img.shields.io/badge/v2.1-version?label=lido&labelColor=rgb(91%2C%20162%2C%20252)&color=white"/>
<img alt="GitHub license" src="https://img.shields.io/github/license/lidofinance/lido-dao?labelColor=orange&color=white"/>
<img alt="Solidity" src="https://img.shields.io/badge/multiver-s?style=flat&label=solidity&labelColor=rgb(86%2C%2085%2C%20212)&color=white"/>
<img alt="Aragon OS" src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Flidofinance%2Fcore%2Fmaster%2Fpackage.json&query=%24.dependencies%5B'%40aragon%2Fos'%5D&style=flat&label=aragon%2Fos&labelColor=rgb(70%2C%20100%2C%20246)&color=white"/>
Expand All @@ -14,7 +14,9 @@ This is the core repository of the Lido on Ethereum protocol. The entire codebas
<img alt="Hardhat" src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Flidofinance%2Fcore%2Fmaster%2Fpackage.json&query=%24.devDependencies.hardhat&style=flat&label=hardhat&labelColor=rgb(251%2C%20240%2C%2056)&color=white" />
<img alt="Ethers" src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Flidofinance%2Fcore%2Fmaster%2Fpackage.json&query=%24.devDependencies.ethers&style=flat&label=ethers&labelColor=rgb(51%2C%2077%2C%20121)&color=white" />
<br/>
<img alt="GitHub tests" src="https://img.shields.io/github/actions/workflow/status/lidofinance/core/tests.yml?label=tests">
<img alt="GitHub unit tests" src="https://img.shields.io/github/actions/workflow/status/lidofinance/core/tests-unit.yml?label=tests:unit">
<img alt="GitHub integration tests (scratch)" src="https://img.shields.io/github/actions/workflow/status/lidofinance/core/tests-integration-scratch.yml?label=tests:integration:scratch">
<img alt="GitHub integration tests (mainnet-fork)" src="https://img.shields.io/github/actions/workflow/status/lidofinance/core/tests-integration-mainnet.yml?label=tests:integration:mainnet-fork">
<img alt="GitHub linters" src="https://img.shields.io/github/actions/workflow/status/lidofinance/core/linters.yml?label=linters">
<img alt="GitHub code analysis" src="https://img.shields.io/github/actions/workflow/status/lidofinance/core/analyse.yml?label=code analysis">
</div>
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
3 changes: 3 additions & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,8 @@ declare namespace NodeJS {

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

/* for local devnet */
LOCAL_DEVNET_PK?: string;
}
}
69 changes: 26 additions & 43 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 @@ -12,48 +11,28 @@ import "hardhat-tracer";
import "hardhat-watcher";
import "hardhat-ignore-warnings";
import "hardhat-contract-sizer";
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 || "";
import { getHardhatForkingConfig, loadAccounts } from "./hardhat.helpers";

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 };
}
const RPC_URL: string = process.env.RPC_URL || "";

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] || [];
}
export const ZERO_PK = "0x0000000000000000000000000000000000000000000000000000000000000000";

const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
networks: {
"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
Expand All @@ -78,9 +57,25 @@ const config: HardhatUserConfig = {
chainId: 11155111,
accounts: loadAccounts("sepolia"),
},
"sepolia-fork": {
url: process.env.SEPOLIA_RPC_URL || RPC_URL,
chainId: 11155111,
},
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY || "",
customChains: [
{
network: "local-devnet",
chainId: 32382,
urls: {
apiURL: "http://localhost:3080/api",
browserURL: "http://localhost:3080",
},
},
],
apiKey: {
"local-devnet": "local-devnet",
},
},
solidity: {
compilers: [
Expand Down Expand Up @@ -181,16 +176,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] || [];
}
9 changes: 7 additions & 2 deletions lib/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { LidoLocator } from "typechain-types";

import { addContractHelperFields, DeployedContract, getContractPath, loadContract, LoadedContract } from "lib/contract";
import { ConvertibleToString, cy, gr, log, yl } from "lib/log";
import { getNonceManagerWithDeployer } from "lib/nonce-manager";
import { incrementGasUsed, Sk, updateObjectInState } from "lib/state-file";

const GAS_PRIORITY_FEE = process.env.GAS_PRIORITY_FEE || null;
Expand Down Expand Up @@ -33,9 +34,11 @@ export async function makeTx(
txParams: TxParams,
withStateFile = true,
): Promise<ContractTransactionReceipt> {
const contractWithNonceManager = contract.connect(await getNonceManagerWithDeployer());

log.withArguments(`Call: ${yl(contract.name)}[${cy(contract.address)}].${yl(funcName)}`, args);

const tx = await contract.getFunction(funcName)(...args, txParams);
const tx = await contractWithNonceManager.getFunction(funcName)(...args, txParams);
log(` Transaction: ${tx.hash} (nonce ${yl(tx.nonce)})...`);

const receipt = await tx.wait();
Expand Down Expand Up @@ -74,7 +77,9 @@ async function deployContractType2(
): Promise<DeployedContract> {
const txParams = await getDeployTxParams(deployer);
const factory = (await ethers.getContractFactory(artifactName, signerOrOptions)) as ContractFactory;
const contract = await factory.deploy(...constructorArgs, txParams);
const factoryWithNonceManager = factory.connect(await getNonceManagerWithDeployer());

const contract = await factoryWithNonceManager.deploy(...constructorArgs, txParams);
const tx = contract.deploymentTransaction();
if (!tx) {
throw new Error(`Failed to send the deployment transaction for ${artifactName}`);
Expand Down
16 changes: 16 additions & 0 deletions lib/nonce-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NonceManager } from "ethers";
import { ethers } from "hardhat";

let cachedNonceManager: NonceManager;

export const getNonceManagerWithDeployer = async () => {
if (cachedNonceManager) {
return cachedNonceManager;
}
const [deployer] = await ethers.getSigners();

const nonceManager = new ethers.NonceManager(deployer);
cachedNonceManager = nonceManager;

return nonceManager;
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
"test:integration:scratch:fulltrace": "INTEGRATION_WITH_CSM=off INTEGRATION_WITH_SCRATCH_DEPLOY=on 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",
"typecheck": "tsc --noEmit",
"prepare": "husky",
"abis:extract": "hardhat abis:extract",
"verify:deployed": "hardhat verify:deployed --no-compile"
"verify:deployed": "hardhat verify:deployed"
},
"lint-staged": {
"./**/*.ts": [
Expand Down Expand Up @@ -79,7 +80,7 @@
"ethers": "^6.13.4",
"glob": "^11.0.0",
"globals": "^15.9.0",
"hardhat": "^2.22.16",
"hardhat": "^2.22.17",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-gas-reporter": "^1.0.10",
"hardhat-ignore-warnings": "^0.2.12",
Expand Down
Loading
Loading