Skip to content

Commit

Permalink
feat: consensys proxyless deployement (#95)
Browse files Browse the repository at this point in the history
* feat: consensys proxyless deployement

* fix: networks values

* fix: admin address

* feat: generate artifacts

* mainnet deployment

* feat: iso deployment

* update yarn version

---------

Co-authored-by: W <[email protected]>
  • Loading branch information
gauthiermyr and 0xvv authored Feb 19, 2024
1 parent 20438fc commit 53f2d9b
Show file tree
Hide file tree
Showing 31 changed files with 7,883 additions and 494 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ This/these account(s) will be in charge of adding keys to the system. They have

These environment variables are required for the deployment command.

#### Deploying Accounts (`MNEMONIC`)
#### Deploying Accounts (`PK`)

You will need a mnemonic phrase pointing to a funded account on the deployment network. This account won't have any ownership or extra rights upon the system, losing this key will no represent a threat for the system (still, don't lose your keys)
You will need a private key pointing to a funded account on the deployment network. This account won't have any ownership or extra rights upon the system, losing this key will no represent a threat for the system (still, don't lose your keys)

#### Ethereum RPC Endpoint (`RPC_URL`)

Expand Down Expand Up @@ -93,7 +93,7 @@ These configuration variables are required to be properly set for the deployment

To start the deployment process, run this command by replacing the variables with the values gathered in the steps above and making sure that configuration file values are set properly.

`env MNEMONIC=$MNEMONIC RPC_URL=$RPC_URL yarn hh deploy --network $NETWORK`
`env PK=$PK RPC_URL=$RPC_URL yarn hh deploy --network $NETWORK`

## III. Testnet Post Deployment Steps

Expand Down
4 changes: 2 additions & 2 deletions deploy/1_deploy_fee_recipient_implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const func: DeployFunction = async function ({

};

func.skip = async function ({ deployments }: HardhatRuntimeEnvironment): Promise<boolean> {
const shouldSkip = await isDeployed("FeeRecipient", deployments);
func.skip = async function ({ deployments, network }: HardhatRuntimeEnvironment): Promise<boolean> {
const shouldSkip = (await isDeployed("FeeRecipient", deployments)) || network.name.endsWith("_consensys");
if (shouldSkip) {
console.log("Skipped");
}
Expand Down
6 changes: 3 additions & 3 deletions deploy/2_deploy_staking_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ const func: DeployFunction = async function ({
}
};

func.skip = async function ({ deployments }: HardhatRuntimeEnvironment): Promise<boolean> {
func.skip = async function ({ deployments, network }: HardhatRuntimeEnvironment): Promise<boolean> {
const shouldSkip =
(await isDeployed("ConsensusLayerFeeDispatcher_Proxy", deployments)) &&
((await isDeployed("ConsensusLayerFeeDispatcher_Proxy", deployments)) &&
(await isDeployed("ExecutionLayerFeeDispatcher_Proxy", deployments)) &&
(await isDeployed("StakingContract_Proxy", deployments));
(await isDeployed("StakingContract_Proxy", deployments))) || network.name.endsWith("_consensys");
if (shouldSkip) {
console.log("Skipped");
}
Expand Down
2 changes: 1 addition & 1 deletion deploy/3_deploy_mainnet_vault_staking_contract_fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const func: DeployFunction = async function ({
};

func.skip = async function ({ deployments, network }: HardhatRuntimeEnvironment): Promise<boolean> {
const shouldSkip = await isDeployed("StakingContract_1.1_Implementation", deployments) || network.name !== "mainnet_vault"
const shouldSkip = await isDeployed("StakingContract_1.1_Implementation", deployments) || network.name !== "mainnet_vault" || network.name.endsWith("_consensys")
if (shouldSkip) {
console.log("Skipped");
}
Expand Down
3 changes: 1 addition & 2 deletions deploy/4_deploy_exit_and_withdrawals_contract_fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const func: DeployFunction = async function ({
};

func.skip = async function ({ deployments, network }: HardhatRuntimeEnvironment): Promise<boolean> {
const shouldSkip = await isDeployed("StakingContract_1.2_Implementation", deployments) && await isDeployed("ConsensusLayerFeeDispatcher_1.2_Implementation", deployments)
|| !["goerli_vault", "goerli_live", "mainnet_vault", "mainnet_live", "mainnet_enzyme", "mainnet_komainu"].includes(network.name);
const shouldSkip = (await isDeployed("StakingContract_1.2_Implementation", deployments) && await isDeployed("ConsensusLayerFeeDispatcher_1.2_Implementation", deployments)) || network.name.endsWith("_consensys");
if (shouldSkip) {
console.log("Skipped");
}
Expand Down
141 changes: 141 additions & 0 deletions deploy/5_deploy_consensys_staking_contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { getContractAddress } from "ethers/lib/utils";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { isDeployed } from "../ts_utils/index";

const getMaxFeeBps = (network: string): number => {
switch (network) {
case "goerli_uat_consensys":
return 5000;
case "goerli_dev_consensys":
return 5000;
case "mainnet_consensys":
return 1500; //15% max fee

default:
return 5000;
}
};

const getMaxOperatorFeeBps = (network: string): number => {
switch (network) {
case "goerli_uat_consensys":
return 5000;
case "goerli_dev_consensys":
return 5000;
case "mainnet_consensys":
return 10000; //100% of 15% = 15%

default:
return 5000;
}
};

const getFeeBps = (network: string): number => {
switch (network) {
case "goerli_uat_consensys":
return 500;
case "goerli_dev_consensys":
return 500;
case "mainnet_consensys":
return 1000; //10% end-user fee

default:
return 500;
}
};

const getOperatorFeeBps = (network: string): number => {
switch (network) {
case "goerli_uat_consensys":
return 500;
case "goerli_dev_consensys":
return 500;
case "mainnet_consensys":
return 9000; //90% of 10% = 9% for consensys, 1% for kiln

default:
return 500;
}
};

const func: DeployFunction = async function ({
deployments,
getNamedAccounts,
ethers,
network,
}: HardhatRuntimeEnvironment) {
const { deployer, admin, depositContract, treasury } = await getNamedAccounts();

//1. Deploy Minimal Recipient
const feeRecipientDeployment = await deployments.deploy("FeeRecipient", {
from: deployer,
log: true
});

//2. Compute future staking contract address
const signer = await ethers.getSigner(deployer);
const txCount = await signer.getTransactionCount();
const futureStakingContractAddress = getContractAddress({
from: deployer,
nonce: txCount + 4, // staking contract proxy is in 5 txs
});

//3. Deploy ConsensusLayerFeeDispatcher without proxy
const clfdDeployment = (await deployments.deploy("ConsensusLayerFeeDispatcher", {
from: deployer,
log: true,
args: [0],
}));


const clf = await ethers.getContractAt("ConsensusLayerFeeDispatcher", clfdDeployment.address);
await (await clf.initCLD(futureStakingContractAddress)).wait();

//4. Deploy ExecutionLayerFeeDispatcher without proxy
const elfdDeployment = await deployments.deploy("ExecutionLayerFeeDispatcher", {
from: deployer,
log: true,
args: [0],
});

const elf = await ethers.getContractAt("ExecutionLayerFeeDispatcher", elfdDeployment.address);
await (await elf.initELD(futureStakingContractAddress)).wait();


//5. Deploy StakingContract without proxy
const stakingContractDeployment = await deployments.deploy("StakingContract", {
from: deployer,
log: true,
});

const stakingContract = await ethers.getContractAt("StakingContract", stakingContractDeployment.address);

const initStaking_1 = await stakingContract.initialize_1(
admin,
treasury,
depositContract,
elfdDeployment.address,
clfdDeployment.address,
feeRecipientDeployment.address,
getFeeBps(network.name),
getOperatorFeeBps(network.name),
getMaxFeeBps(network.name),
getMaxOperatorFeeBps(network.name),
);
await initStaking_1.wait();

if (stakingContractDeployment.address.toLowerCase() !== futureStakingContractAddress.toLowerCase()) {
throw new Error("Invalid future deployment address for staking contract");
}
};

func.skip = async function ({ deployments, network }: HardhatRuntimeEnvironment): Promise<boolean> {
const shouldSkip = network.name !== "goerli_uat_consensys" && network.name !== "goerli_dev_consensys" && network.name !== "mainnet_consensys";
if (shouldSkip) {
console.log("Skipped");
}
return shouldSkip;
};

export default func;
16 changes: 16 additions & 0 deletions deployment.goerli_dev_consensys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "goerli_dev_consensys",
"chainId": "5",
"contracts": {
"ConsensusLayerFeeDispatcher": "0xD8875BAab3c5a1244d10fbBbC03b756f7649f320",
"ExecutionLayerFeeDispatcher": "0x3fb3bf7D78150865eE891d5Ea344D0CC9c1E1E84",
"FeeRecipient": "0x8Fa87245c0D88e2D0cfE05679cED0C367950514b",
"StakingContract": "0x97230E85e6443371B5b7bB5d47FA868E2eE48301"
},
"namedAccounts": {
"deployer": "0xBcc3816221d083D8E72F2CB14959F24d89406810",
"admin": "0xFb0961bea75145bC62fB6A53bE9Be70A0A7D206E",
"depositContract": "0xff50ed3d0ec03aC01D4C79aAd74928BFF48a7b2b",
"treasury": "0xAb07A64D407c25f02f1a2dc0aF97076630a03F17"
}
}
16 changes: 16 additions & 0 deletions deployment.goerli_uat_consensys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "goerli_uat_consensys",
"chainId": "5",
"contracts": {
"ConsensusLayerFeeDispatcher": "0xb4C5d4B5e4ed044e68f235a0BFE7346D2a2E634d",
"ExecutionLayerFeeDispatcher": "0x6F4579e7C3B3aeb030dC325f2e2476E3c4f3AA60",
"FeeRecipient": "0xe24F071021205Ba706fAfd4f8F1a74F24c303745",
"StakingContract": "0xD36142289a230423Bb1341e2F9CbE9c549C5c93d"
},
"namedAccounts": {
"deployer": "0xBcc3816221d083D8E72F2CB14959F24d89406810",
"admin": "0xFb0961bea75145bC62fB6A53bE9Be70A0A7D206E",
"depositContract": "0xff50ed3d0ec03aC01D4C79aAd74928BFF48a7b2b",
"treasury": "0xAb07A64D407c25f02f1a2dc0aF97076630a03F17"
}
}
16 changes: 16 additions & 0 deletions deployment.mainnet_consensys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "mainnet_consensys",
"chainId": "1",
"contracts": {
"ConsensusLayerFeeDispatcher": "0xC24162aa69C3267Ed5a4900a2976487BDDFC69d2",
"ExecutionLayerFeeDispatcher": "0xeD216054cb9bA38d22E3E72B8245147F890329e4",
"FeeRecipient": "0xFE1b6a789e2BD96a69C49a14353E51116b48107F",
"StakingContract": "0xDc71aFFC862fceB6aD32BE58E098423A7727bEbd"
},
"namedAccounts": {
"deployer": "0x6C74FDa18Ea90E1C61e800Dd9B4508Ac782e0Dc8",
"admin": "0x5Bc5ec5130f66f13d5C21ac6811A7e624ED3C7c6",
"depositContract": "0x00000000219ab540356cBB839Cbe05303d7705Fa",
"treasury": "0xb631dB8b5D95947025b77bFB44De32eFA8bc15Da"
}
}
1 change: 1 addition & 0 deletions deployments/goerli_dev_consensys/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
Loading

0 comments on commit 53f2d9b

Please sign in to comment.