|
| 1 | +import { getContractAddress } from "ethers/lib/utils"; |
| 2 | +import { DeployFunction } from "hardhat-deploy/types"; |
| 3 | +import { HardhatRuntimeEnvironment } from "hardhat/types"; |
| 4 | +import { isDeployed } from "../ts_utils/index"; |
| 5 | + |
| 6 | +const getMaxFeeBps = (network: string): number => { |
| 7 | + switch (network) { |
| 8 | + case "holesky_dev_safe": |
| 9 | + return 1000; |
| 10 | + case "mainnet_safe": |
| 11 | + return 1000; //10% max user fee |
| 12 | + |
| 13 | + default: |
| 14 | + return 1000; |
| 15 | + } |
| 16 | +}; |
| 17 | + |
| 18 | +const getMaxOperatorFeeBps = (network: string): number => { |
| 19 | + switch (network) { |
| 20 | + case "holesky_dev_safe": |
| 21 | + return 10000; |
| 22 | + case "mainnet_safe": |
| 23 | + return 10000; // Leave the possibility of doing the split onchain in the future |
| 24 | + |
| 25 | + default: |
| 26 | + return 0; |
| 27 | + } |
| 28 | +}; |
| 29 | + |
| 30 | +const getFeeBps = (network: string): number => { |
| 31 | + switch (network) { |
| 32 | + case "holesky_dev_safe": |
| 33 | + return 600; |
| 34 | + case "mainnet_safe": |
| 35 | + return 600; //6% end-user fee |
| 36 | + |
| 37 | + default: |
| 38 | + return 600; |
| 39 | + } |
| 40 | +}; |
| 41 | + |
| 42 | +const getOperatorFeeBps = (network: string): number => { |
| 43 | + switch (network) { |
| 44 | + case "holesky_dev_safe": |
| 45 | + return 0; |
| 46 | + case "mainnet_safe": |
| 47 | + return 0; // at the start all the fees go to the treasury |
| 48 | + |
| 49 | + default: |
| 50 | + return 0; |
| 51 | + } |
| 52 | +}; |
| 53 | + |
| 54 | +const func: DeployFunction = async function ({ |
| 55 | + deployments, |
| 56 | + getNamedAccounts, |
| 57 | + ethers, |
| 58 | + network, |
| 59 | +}: HardhatRuntimeEnvironment) { |
| 60 | + const { deployer, admin, depositContract, treasury } = await getNamedAccounts(); |
| 61 | + |
| 62 | + //1. Deploy Minimal Recipient |
| 63 | + const feeRecipientDeployment = await deployments.deploy("FeeRecipient", { |
| 64 | + from: deployer, |
| 65 | + log: true |
| 66 | + }); |
| 67 | + |
| 68 | + //2. Compute future staking contract address |
| 69 | + const signer = await ethers.getSigner(deployer); |
| 70 | + const txCount = await signer.getTransactionCount(); |
| 71 | + const futureStakingContractAddress = getContractAddress({ |
| 72 | + from: deployer, |
| 73 | + nonce: txCount + 4, // staking contract proxy is in 5 txs |
| 74 | + }); |
| 75 | + |
| 76 | + //3. Deploy ConsensusLayerFeeDispatcher without proxy |
| 77 | + const clfdDeployment = (await deployments.deploy("ConsensusLayerFeeDispatcher", { |
| 78 | + from: deployer, |
| 79 | + log: true, |
| 80 | + args: [0], |
| 81 | + })); |
| 82 | + |
| 83 | + |
| 84 | + const clf = await ethers.getContractAt("ConsensusLayerFeeDispatcher", clfdDeployment.address); |
| 85 | + await (await clf.initCLD(futureStakingContractAddress)).wait(); |
| 86 | + |
| 87 | + //4. Deploy ExecutionLayerFeeDispatcher without proxy |
| 88 | + const elfdDeployment = await deployments.deploy("ExecutionLayerFeeDispatcher", { |
| 89 | + from: deployer, |
| 90 | + log: true, |
| 91 | + args: [0], |
| 92 | + }); |
| 93 | + |
| 94 | + const elf = await ethers.getContractAt("ExecutionLayerFeeDispatcher", elfdDeployment.address); |
| 95 | + await (await elf.initELD(futureStakingContractAddress)).wait(); |
| 96 | + |
| 97 | + |
| 98 | + //5. Deploy StakingContract without proxy |
| 99 | + const stakingContractDeployment = await deployments.deploy("StakingContract", { |
| 100 | + from: deployer, |
| 101 | + log: true, |
| 102 | + }); |
| 103 | + |
| 104 | + const stakingContract = await ethers.getContractAt("StakingContract", stakingContractDeployment.address); |
| 105 | + |
| 106 | + const initStaking_1 = await stakingContract.initialize_1( |
| 107 | + admin, |
| 108 | + treasury, |
| 109 | + depositContract, |
| 110 | + elfdDeployment.address, |
| 111 | + clfdDeployment.address, |
| 112 | + feeRecipientDeployment.address, |
| 113 | + getFeeBps(network.name), |
| 114 | + getOperatorFeeBps(network.name), |
| 115 | + getMaxFeeBps(network.name), |
| 116 | + getMaxOperatorFeeBps(network.name), |
| 117 | + ); |
| 118 | + await initStaking_1.wait(); |
| 119 | + |
| 120 | + if (stakingContractDeployment.address.toLowerCase() !== futureStakingContractAddress.toLowerCase()) { |
| 121 | + throw new Error("Invalid future deployment address for staking contract"); |
| 122 | + } |
| 123 | +}; |
| 124 | + |
| 125 | +func.skip = async function ({ deployments, network }: HardhatRuntimeEnvironment): Promise<boolean> { |
| 126 | + const shouldSkip = network.name !== "holesky_dev_safe" && network.name !== "mainnet_safe"; |
| 127 | + if (shouldSkip) { |
| 128 | + console.log("Skipped"); |
| 129 | + } |
| 130 | + return shouldSkip; |
| 131 | +}; |
| 132 | + |
| 133 | +export default func; |
0 commit comments