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

Sepolia deployment and deposit contract adapter #820

Merged
merged 17 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
27 changes: 27 additions & 0 deletions contracts/0.8.9/SepoliaDepositAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: 2024 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0

/* See contracts/COMPILERS.md */
pragma solidity 0.8.9;


contract SepoliaDepositAdapter {

uint public constant TEST_VALUE = 16;
address public depositContract;

function deposit(
bytes calldata pubkey,
bytes calldata withdrawal_credentials,
bytes calldata signature,
bytes32 deposit_data_root
) external payable {
}

constructor(address _deposit_contract) {
depositContract = _deposit_contract;
}



}
3 changes: 2 additions & 1 deletion deployed-testnet-defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"deployParameters": {
"maxDepositsPerBlock": 150,
"minDepositBlockDistance": 5,
"pauseIntentValidityPeriodBlocks": 6646
"pauseIntentValidityPeriodBlocks": 6646,
"usePredefinedAddressInstead": null
}
},
"oracleReportSanityChecker": {
Expand Down
9 changes: 5 additions & 4 deletions docs/scratch-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
## General info

The repo contains bash scripts for deployment of the DAO under multiple environments:
- local node (ganache, anvil, hardhat network) `dao-local-deploy.sh`
- holesky testnet - `dao-holesky-deploy.sh`
- local node (ganache, anvil, hardhat network) `scripts/scratch/dao-local-deploy.sh`
- holesky testnet - `scripts/scratch/dao-holesky-deploy.sh`

The protocol has a bunch of parameters to configure for the scratch deployment. The default configuration is stored in files `deployed-<deploy env>-defaults.json`, where `<deploy env>` is the target environment. Currently, there is a single default configuration, `deployed-testnet-defaults.json`, suitable for testnet deployments. Compared to the mainnet configuration, it has lower vote durations, more frequent oracle report cycles, etc. Part of the parameters require further specification -- they are marked with `null` values.
During the deployment, the "default" configuration is copied to `deployed-<network name>.json`, where `<network name>` is the name of a network configuration defined in `hardhat.config.js`. The file `deployed-<network name>.json` gets populated with the contract addresses and transaction hashes during the deployment process.
Expand Down Expand Up @@ -91,8 +91,9 @@ To do Holešky deployment, the following parameters must be set up via env varia
- `RPC_URL`. Address of of the Ethereum RPC node to use. E.g. for Infura it is `https://holesky.infura.io/v3/<yourProjectId>`
- `GAS_PRIORITY_FEE`. Gas priority fee. By default set to `2`
- `GAS_MAX_FEE`. Gas max fee. By default set to `100`
- `GATE_SEAL_FACTORY`. Address of the [GateSeal Factory](https://github.com/lidofinance/gate-seals) contract. Must be deployed in advance. Can be set to any `0x0000000000000000000000000000000000000000` to debug deployment.
- `WITHDRAWAL_QUEUE_BASE_URI`. BaseURI for WithdrawalQueueERC712. By default not set (left an empty string).
- `GATE_SEAL_FACTORY`. Address of the [GateSeal Factory](https://github.com/lidofinance/gate-seals) contract. Must be deployed in advance. Can be set to any `0x0000000000000000000000000000000000000000` to debug deployment
- `WITHDRAWAL_QUEUE_BASE_URI`. BaseURI for WithdrawalQueueERC712. By default not set (left an empty string)
- `DSM_PREDEFINED_ADDRESS`. Address to use instead of deploying `DepositSecurityModule` or `null` otherwise. If used, the deposits can be made by calling `Lido.deposit` from the address.

Also you need to specify `DEPLOYER` private key in `accounts.json` under `/eth/holesky` like `"holesky": ["<key>"]`. See `accounts.sample.json` for an example.

Expand Down
6 changes: 6 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ const getNetConfig = (networkName, ethAccountName) => {
chainId: 17000,
timeout: 60000 * 15,
},
sepolia: {
...base,
url: RPC_URL,
chainId: 11155111,
timeout: 60000 * 15,
},
mainnet: {
...base,
url: RPC_URL,
Expand Down
33 changes: 33 additions & 0 deletions scripts/deploy-sepolia-deposit-contract-adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const runOrWrapScript = require('./helpers/run-or-wrap-script')

const DEPLOYER = process.env.DEPLOYER || ''

async function deployNewContracts({ web3, artifacts }) {
// const netId = await web3.eth.net.getId()
// logWideSplitter()
// log(`Network ID:`, yl(netId))
// let state = readNetworkState(network.name, netId)
// assertRequiredNetworkState(state, REQUIRED_NET_STATE)

if (!DEPLOYER) {
throw new Error('Deployer is not specified')
}

const sepoliaDepositContract = "0x7f02C3E3c98b133055B8B348B2Ac625669Ed295D"
// const constructorArgs = [sepoliaDepositContract]
const constructorArgs = []
const Contract = await ethers.getContractFactory("SepoliaDepositAdapter")
const txParams = {
type: 2,
maxPriorityFeePerGas: ethers.utils.parseUnits(String(2), "gwei"),
maxFeePerGas: ethers.utils.parseUnits(String(200), "gwei"),
// from: DEPLOYER,
}
const contract = await Contract.deploy(...constructorArgs, txParams)
await contract.deployed()

console.log(contract.address)

}

module.exports = runOrWrapScript(deployNewContracts, module)
10 changes: 9 additions & 1 deletion scripts/scratch/00-populate-deploy-artifact-from-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ const GATE_SEAL_FACTORY = process.env.GATE_SEAL_FACTORY
const GENESIS_TIME = parseInt(process.env.GENESIS_TIME)
const DEPOSIT_CONTRACT = process.env.DEPOSIT_CONTRACT
const WITHDRAWAL_QUEUE_BASE_URI = process.env.WITHDRAWAL_QUEUE_BASE_URI
const DSM_PREDEFINED_ADDRESS = process.env.DSM_PREDEFINED_ADDRESS

async function saveDeployParameters({ web3, artifacts }) {
async function saveDeployParameters({ web3 }) {
const netId = await web3.eth.net.getId()

console.log('Using env values:')
Expand Down Expand Up @@ -45,6 +46,13 @@ async function saveDeployParameters({ web3, artifacts }) {
baseUri: WITHDRAWAL_QUEUE_BASE_URI,
}
}
if (DSM_PREDEFINED_ADDRESS !== undefined) {
state.depositSecurityModule.deployParameters = {
...state.depositSecurityModule.deployParameters,
usePredefinedAddressInstead: DSM_PREDEFINED_ADDRESS,
}
state.depositSecurityModule.address = DSM_PREDEFINED_ADDRESS
}
persistNetworkState(network.name, netId, state)
}

Expand Down
27 changes: 16 additions & 11 deletions scripts/scratch/13-deploy-non-aragon-contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,22 @@ async function deployNewContracts({ web3, artifacts }) {
//
// === DepositSecurityModule ===
//
const {maxDepositsPerBlock, minDepositBlockDistance, pauseIntentValidityPeriodBlocks} = depositSecurityModuleParams
const depositSecurityModuleArgs = [
lidoAddress,
depositContract,
stakingRouterAddress,
maxDepositsPerBlock,
minDepositBlockDistance,
pauseIntentValidityPeriodBlocks,
]
const depositSecurityModuleAddress = await deployWithoutProxy(
"depositSecurityModule", "DepositSecurityModule", deployer, depositSecurityModuleArgs)
let depositSecurityModuleAddress = depositSecurityModuleParams.usePredefinedAddressInstead
if (depositSecurityModuleAddress === null) {
const {maxDepositsPerBlock, minDepositBlockDistance, pauseIntentValidityPeriodBlocks} = depositSecurityModuleParams
const depositSecurityModuleArgs = [
lidoAddress,
depositContract,
stakingRouterAddress,
maxDepositsPerBlock,
minDepositBlockDistance,
pauseIntentValidityPeriodBlocks,
]
depositSecurityModuleAddress = await deployWithoutProxy(
"depositSecurityModule", "DepositSecurityModule", deployer, depositSecurityModuleArgs)
} else {
console.log(`NB: skipping deployment of DepositSecurityModule - using the predefined address ${depositSecurityModuleAddress} instead`)
}
logWideSplitter()

//
Expand Down
4 changes: 3 additions & 1 deletion scripts/scratch/19-transfer-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ async function deployNewContracts({ web3, artifacts }) {
await changeOssifiableProxyAdmin(state.validatorsExitBusOracle.proxy.address, deployer, agent)
await changeOssifiableProxyAdmin(state.withdrawalQueueERC721.proxy.address, deployer, agent)

await changeDepositSecurityModuleAdmin(state.depositSecurityModule.address, deployer, agent)
if (state.depositSecurityModule.deployParameters.usePredefinedAddressInstead === null) {
await changeDepositSecurityModuleAdmin(state.depositSecurityModule.address, deployer, agent)
}

await TotalGasCounter.incrementTotalGasUsedInStateFile()
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/scratch/20-check-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ async function checkDAO({ web3, artifacts }) {
log.splitter()

const permissionsConfig = JSON.parse(fs.readFileSync('./scripts/scratch/checks/scratch-deploy-permissions.json'))
if (state.depositSecurityModule.deployParameters.usePredefinedAddressInstead !== null) {
delete permissionsConfig['depositSecurityModule']
}
await assertNonAragonPermissions(state, permissionsConfig)

log.splitter()
Expand Down
10 changes: 5 additions & 5 deletions scripts/scratch/checks/scratch-acceptance-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function loadDeployedProtocol(state) {
voting: await artifacts.require('Voting').at(state['app:aragon-voting'].proxy.address),
agent: await artifacts.require('Agent').at(state['app:aragon-agent'].proxy.address),
nodeOperatorsRegistry: await artifacts.require('NodeOperatorsRegistry').at(state['app:node-operators-registry'].proxy.address),
depositSecurityModule: await artifacts.require('DepositSecurityModule').at(state.depositSecurityModule.address),
depositSecurityModuleAddress: state.depositSecurityModule.address, // Deploying DepositSecurityModule might be omitted and e.g. EOA is used
accountingOracle: await artifacts.require('AccountingOracle').at(state.accountingOracle.proxy.address),
hashConsensusForAO: await artifacts.require('HashConsensus').at(state.hashConsensusForAccountingOracle.address),
elRewardsVault: await artifacts.require('LidoExecutionLayerRewardsVault').at(state.executionLayerRewardsVault.address),
Expand All @@ -68,13 +68,13 @@ async function prepareProtocolForSubmitDepositReportWithdrawalFlow(protocol, sta
voting,
agent,
nodeOperatorsRegistry,
depositSecurityModule,
depositSecurityModuleAddress,
hashConsensusForAO,
withdrawalQueue,
} = protocol

await ethers.provider.send('hardhat_impersonateAccount', [voting.address])
await ethers.provider.send('hardhat_impersonateAccount', [depositSecurityModule.address])
await ethers.provider.send('hardhat_impersonateAccount', [depositSecurityModuleAddress])
await ethers.provider.send('hardhat_impersonateAccount', [agent.address])

await lido.resume({ from: voting.address })
Expand Down Expand Up @@ -111,7 +111,7 @@ async function checkSubmitDepositReportWithdrawal(protocol, state, user1, user2)
const {
lido,
agent,
depositSecurityModule,
depositSecurityModuleAddress,
accountingOracle,
hashConsensusForAO,
elRewardsVault,
Expand All @@ -130,7 +130,7 @@ async function checkSubmitDepositReportWithdrawal(protocol, state, user1, user2)
assert.equals(await lido.getTotalPooledEther(), initialLidoBalance + BigInt(ETH(34)))
assert.equals(await lido.getBufferedEther(), initialLidoBalance + BigInt(ETH(34)))

await lido.deposit(MAX_DEPOSITS, CURATED_MODULE_ID, CALLDATA, { from: depositSecurityModule.address })
await lido.deposit(MAX_DEPOSITS, CURATED_MODULE_ID, CALLDATA, { from: depositSecurityModuleAddress })
log.success('Ether deposited')


Expand Down
1 change: 1 addition & 0 deletions scripts/scratch/dao-local-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export RPC_URL=${RPC_URL:="http://127.0.0.1:8555"} # if defined use the value s
export GATE_SEAL_FACTORY=0x0000000000000000000000000000000000000000
export GENESIS_TIME=1639659600 # just some time
# export WITHDRAWAL_QUEUE_BASE_URI="<< SET IF REQUIED >>"
# export DSM_PREDEFINED_ADDRESS="<< SET IF REQUIED >>"
#
export DEPLOYER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
export GAS_PRIORITY_FEE=1
Expand Down
39 changes: 39 additions & 0 deletions scripts/scratch/dao-sepolia-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -e +u
set -o pipefail

if [[ -z "$DEPLOYER" ]]; then
echo "Must set DEPLOYER env variable" 1>&2
exit 1
fi
if [[ -z "$RPC_URL" ]]; then
echo "Must set RPC_URL env variable" 1>&2
exit 1
fi
if [[ -z "$GATE_SEAL_FACTORY" ]]; then
echo "Must set GATE_SEAL_FACTORY env variable" 1>&2
exit 1
fi

export NETWORK=sepolia
export NETWORK_STATE_FILE="deployed-${NETWORK}.json"
export NETWORK_STATE_DEFAULTS_FILE="deployed-testnet-defaults.json"

# Holesky params: https://github.com/eth-clients/holesky/blob/main/README.md
export GENESIS_TIME=1695902400

# TODO: set a dedicated EOA address (arwer is up to it). Let it be a stub for now
export DSM_PREDEFINED_ADDRESS="0x000000000000000000000000000000000000dead"


# export WITHDRAWAL_QUEUE_BASE_URI="<< SET IF REQUIED >>"

export GAS_PRIORITY_FEE="${GAS_PRIORITY_FEE:=1}"
export GAS_MAX_FEE="${GAS_MAX_FEE:=100}"

# WTF??
export DEPOSIT_CONTRACT=0x7f02C3E3c98b133055B8B348B2Ac625669Ed295D
ADAPTER_ADDRESS=$(yarn hardhat run --no-compile ./scripts/deploy-sepolia-deposit-contract-adapter.js --network $NETWORK)

export DEPOSIT_CONTRACT=ADAPTER_ADDRESS
bash scripts/scratch/dao-deploy.sh
27 changes: 27 additions & 0 deletions test/0.8.9/sepolia-deployment.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { artifacts, contract, ethers } = require('hardhat')

const { EvmSnapshot } = require('../helpers/blockchain')

const SepoliaDepositAdapter = artifacts.require('SepoliaDepositAdapter')

contract('SepoliaDepositAdapter', ([deployer]) => {
let depositAdapter
let snapshot

before('deploy lido with dao', async () => {
depositAdapter = await SepoliaDepositAdapter.new(deployer, { from: deployer })
const dna = await depositAdapter.TEST_VALUE()
console.log(dna)

snapshot = new EvmSnapshot(ethers.provider)
await snapshot.make()
})

afterEach(async () => {
await snapshot.rollback()
})

describe('SepoliaDepositAdapter Logic', () => {
it(`state after deployment`, async () => {})
})
})
Loading