From 6811ea60df7dabd62553087bd21436a5b255ba32 Mon Sep 17 00:00:00 2001 From: Aleksandr Kuperman Date: Thu, 31 Oct 2024 15:06:42 +0000 Subject: [PATCH] chore: staking verifier proposals --- ..._staking_verifier_change_limits_gnosis.js} | 2 +- ..._10_staking_verifier_set_implementation.js | 90 +++++++++++++++++++ ...ange_limits_set_implementation_polygon.js} | 23 +++-- ...e_limits_set_implementation_optimistic.js} | 22 +++-- ..._change_limits_set_implementation_celo.js} | 22 +++-- ...nge_limits_set_implementation_ethereum.js} | 13 +-- ...nge_limits_set_implementation_arbitrum.js} | 31 +++++-- 7 files changed, 171 insertions(+), 32 deletions(-) rename scripts/proposals/{proposal_10_staking_verifier_change_limits_gnosis.js => proposal_09_staking_verifier_change_limits_gnosis.js} (97%) create mode 100644 scripts/proposals/proposal_10_staking_verifier_set_implementation.js rename scripts/proposals/{proposal_11_staking_verifier_change_limits_polygon.js => proposal_11_staking_verifier_change_limits_set_implementation_polygon.js} (80%) rename scripts/proposals/{proposal_12_staking_verifier_change_limits_optimistic.js => proposal_12_staking_verifier_change_limits_set_implementation_optimistic.js} (81%) rename scripts/proposals/{proposal_13_staking_verifier_change_limits_celo.js => proposal_13_staking_verifier_change_limits_set_implementation_celo.js} (80%) rename scripts/proposals/{proposal_14_staking_verifier_change_limits_ethereum.js => proposal_14_staking_verifier_change_limits_set_implementation_ethereum.js} (74%) rename scripts/proposals/{proposal_15_staking_verifier_change_limits_arbitrum.js => proposal_15_staking_verifier_change_limits_set_implementation_arbitrum.js} (80%) diff --git a/scripts/proposals/proposal_10_staking_verifier_change_limits_gnosis.js b/scripts/proposals/proposal_09_staking_verifier_change_limits_gnosis.js similarity index 97% rename from scripts/proposals/proposal_10_staking_verifier_change_limits_gnosis.js rename to scripts/proposals/proposal_09_staking_verifier_change_limits_gnosis.js index 2ce62b2d..db0bf2a3 100644 --- a/scripts/proposals/proposal_10_staking_verifier_change_limits_gnosis.js +++ b/scripts/proposals/proposal_09_staking_verifier_change_limits_gnosis.js @@ -60,7 +60,7 @@ async function main() { ); // Proposal preparation - console.log("Proposal 10. Change staking limits for gnosis StakingVerifier\n"); + console.log("Proposal 9. Change staking limits for gnosis StakingVerifier\n"); const mediatorPayload = await homeMediator.interface.encodeFunctionData("processMessageFromForeign", [data]); // AMBContractProxyHomeAddress on gnosis mainnet: 0x75Df5AF045d91108662D8080fD1FEFAd6aA0bb59 diff --git a/scripts/proposals/proposal_10_staking_verifier_set_implementation.js b/scripts/proposals/proposal_10_staking_verifier_set_implementation.js new file mode 100644 index 00000000..0b3066a4 --- /dev/null +++ b/scripts/proposals/proposal_10_staking_verifier_set_implementation.js @@ -0,0 +1,90 @@ +/*global process*/ + +const { ethers } = require("ethers"); + +async function main() { + const fs = require("fs"); + // Mainnet globals file + const globalsFile = "globals.json"; + const dataFromJSON = fs.readFileSync(globalsFile, "utf8"); + const parsedData = JSON.parse(dataFromJSON); + + const ALCHEMY_API_KEY_MAINNET = process.env.ALCHEMY_API_KEY_MAINNET; + const mainnetURL = "https://eth-mainnet.g.alchemy.com/v2/" + ALCHEMY_API_KEY_MAINNET; + const mainnetProvider = new ethers.providers.JsonRpcProvider(mainnetURL); + await mainnetProvider.getBlockNumber().then((result) => { + console.log("Current block number mainnet: " + result); + }); + + const gnosisURL = "https://rpc.gnosischain.com"; + const gnosisProvider = new ethers.providers.JsonRpcProvider(gnosisURL); + await gnosisProvider.getBlockNumber().then((result) => { + console.log("Current block number gnosis: " + result); + }); + + + // AMBProxy address on mainnet + const AMBProxyAddress = parsedData.AMBContractProxyForeignAddress; + const AMBProxyJSON = "abis/bridges/gnosis/EternalStorageProxy.json"; + let contractFromJSON = fs.readFileSync(AMBProxyJSON, "utf8"); + const AMBProxyABI = JSON.parse(contractFromJSON); + const AMBProxy = new ethers.Contract(AMBProxyAddress, AMBProxyABI, mainnetProvider); + + // Test deployed HomeMediator address on chiado + const homeMediatorAddress = parsedData.bridgeMediatorAddress; + const homeMediatorJSON = "abis/bridges/gnosis/HomeMediator.json"; + contractFromJSON = fs.readFileSync(homeMediatorJSON, "utf8"); + let parsedFile = JSON.parse(contractFromJSON); + const homeMediatorABI = parsedFile["abi"]; + const homeMediator = new ethers.Contract(homeMediatorAddress, homeMediatorABI, gnosisProvider); + + // StakingVerifier address on gnosis + const stakingVerifierAddress = parsedData.stakingVerifierAddress; + const stakingVerifierJSON = "artifacts/contracts/staking/StakingVerifier.sol/StakingVerifier.json"; + contractFromJSON = fs.readFileSync(stakingVerifierJSON, "utf8"); + parsedFile = JSON.parse(contractFromJSON); + const stakingVerifierABI = parsedFile["abi"]; + const stakingVerifier = new ethers.Contract(stakingVerifierAddress, stakingVerifierABI, gnosisProvider); + + // Timelock contract across the bridge must change staking limits + const rawPayload = stakingVerifier.interface.encodeFunctionData("setImplementationsStatuses", + [[parsedData.stakingTokenAddress], [true], true]); + // Pack the second part of data + const target = stakingVerifierAddress; + const value = 0; + const payload = ethers.utils.arrayify(rawPayload); + const data = ethers.utils.solidityPack( + ["address", "uint96", "uint32", "bytes"], + [target, value, payload.length, payload] + ); + + // Proposal preparation + console.log("Proposal 10. Whitelist StakingTokenImplementation in StakingFactory on gnosis\n"); + const mediatorPayload = await homeMediator.interface.encodeFunctionData("processMessageFromForeign", [data]); + + // AMBContractProxyHomeAddress on gnosis mainnet: 0x75Df5AF045d91108662D8080fD1FEFAd6aA0bb59 + // Function to call by homeMediator: processMessageFromForeign + console.log("AMBContractProxyHomeAddress to call homeMediator's processMessageFromForeign function with the data:", data); + + const requestGasLimit = "2000000"; + const timelockPayload = await AMBProxy.interface.encodeFunctionData("requireToPassMessage", [homeMediatorAddress, + mediatorPayload, requestGasLimit]); + + const targets = [AMBProxyAddress]; + const values = [0]; + const callDatas = [timelockPayload]; + const description = "Whitelist StakingTokenImplementation in StakingFactory on gnosis"; + + // Proposal details + console.log("targets:", targets); + console.log("values:", values); + console.log("call datas:", callDatas); + console.log("description:", description); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/scripts/proposals/proposal_11_staking_verifier_change_limits_polygon.js b/scripts/proposals/proposal_11_staking_verifier_change_limits_set_implementation_polygon.js similarity index 80% rename from scripts/proposals/proposal_11_staking_verifier_change_limits_polygon.js rename to scripts/proposals/proposal_11_staking_verifier_change_limits_set_implementation_polygon.js index bc30c1ce..4dd505b4 100644 --- a/scripts/proposals/proposal_11_staking_verifier_change_limits_polygon.js +++ b/scripts/proposals/proposal_11_staking_verifier_change_limits_set_implementation_polygon.js @@ -43,19 +43,28 @@ async function main() { const fxGovernorTunnelAddress = parsedData.bridgeMediatorAddress; // Proposal preparation - console.log("Proposal 11. Change staking limits for polygon StakingVerifier\n"); - const rawPayload = stakingVerifier.interface.encodeFunctionData("changeStakingLimits", + console.log("Proposal 11. Change staking limits on polygon in StakingVerifier and whitelist StakingTokenImplementation in StakingFactory\n"); + const value = 0; + const target = stakingVerifierAddress; + let rawPayload = stakingVerifier.interface.encodeFunctionData("changeStakingLimits", [parsedData.minStakingDepositLimit, parsedData.timeForEmissionsLimit, parsedData.numServicesLimit, parsedData.apyLimit]); // Pack the second part of data - const target = stakingVerifierAddress; - const value = 0; - const payload = ethers.utils.arrayify(rawPayload); - const data = ethers.utils.solidityPack( + let payload = ethers.utils.arrayify(rawPayload); + let data = ethers.utils.solidityPack( ["address", "uint96", "uint32", "bytes"], [target, value, payload.length, payload] ); + rawPayload = stakingVerifier.interface.encodeFunctionData("setImplementationsStatuses", + [[parsedData.stakingTokenAddress], [true], true]); + payload = ethers.utils.arrayify(rawPayload); + data += ethers.utils.solidityPack( + ["address", "uint96", "uint32", "bytes"], + [target, value, payload.length, payload] + ).slice(2); + + // fxChild address polygon mainnet: 0x8397259c983751DAf40400790063935a11afa28a // Function to call by fxGovernorTunnelAddress: processMessageFromRoot // state Id: any; rootMessageSender = timelockAddress @@ -67,7 +76,7 @@ async function main() { const targets = [fxRootAddress]; const values = [0]; const callDatas = [timelockPayload]; - const description = "Change Drainer in ServiceRegistryL2 on polygon"; + const description = "Change staking limits on polygon in StakingVerifier and whitelist StakingTokenImplementation in StakingFactory"; // Proposal details console.log("targets:", targets); diff --git a/scripts/proposals/proposal_12_staking_verifier_change_limits_optimistic.js b/scripts/proposals/proposal_12_staking_verifier_change_limits_set_implementation_optimistic.js similarity index 81% rename from scripts/proposals/proposal_12_staking_verifier_change_limits_optimistic.js rename to scripts/proposals/proposal_12_staking_verifier_change_limits_set_implementation_optimistic.js index 3576bfc4..20672f84 100644 --- a/scripts/proposals/proposal_12_staking_verifier_change_limits_optimistic.js +++ b/scripts/proposals/proposal_12_staking_verifier_change_limits_set_implementation_optimistic.js @@ -46,20 +46,28 @@ async function main() { const stakingVerifier = new ethers.Contract(stakingVerifierAddress, stakingVerifierABI, optimisticProvider); // Timelock contract across the bridge must change staking limits - const rawPayload = stakingVerifier.interface.encodeFunctionData("changeStakingLimits", + const value = 0; + const target = stakingVerifierAddress; + let rawPayload = stakingVerifier.interface.encodeFunctionData("changeStakingLimits", [parsedData.minStakingDepositLimit, parsedData.timeForEmissionsLimit, parsedData.numServicesLimit, parsedData.apyLimit]); // Pack the second part of data - const target = stakingVerifierAddress; - const value = 0; - const payload = ethers.utils.arrayify(rawPayload); - const data = ethers.utils.solidityPack( + let payload = ethers.utils.arrayify(rawPayload); + let data = ethers.utils.solidityPack( ["address", "uint96", "uint32", "bytes"], [target, value, payload.length, payload] ); + rawPayload = stakingVerifier.interface.encodeFunctionData("setImplementationsStatuses", + [[parsedData.stakingTokenAddress], [true], true]); + payload = ethers.utils.arrayify(rawPayload); + data += ethers.utils.solidityPack( + ["address", "uint96", "uint32", "bytes"], + [target, value, payload.length, payload] + ).slice(2); + // Proposal preparation - console.log("Proposal 12. Change staking limits for optimism StakingVerifier\n"); + console.log("Proposal 12. Change staking limits on optimism in StakingVerifier and whitelist StakingTokenImplementation in StakingFactory\n"); // Build the bridge payload const messengerPayload = await optimismMessenger.interface.encodeFunctionData("processMessageFromSource", [data]); const minGasLimit = "2000000"; @@ -70,7 +78,7 @@ async function main() { const targets = [CDMProxyAddress]; const values = [0]; const callDatas = [timelockPayload]; - const description = "Change Manager in StakingVerifier on optimism"; + const description = "Change staking limits on optimism in StakingVerifier and whitelist StakingTokenImplementation in StakingFactory"; // Proposal details console.log("targets:", targets); diff --git a/scripts/proposals/proposal_13_staking_verifier_change_limits_celo.js b/scripts/proposals/proposal_13_staking_verifier_change_limits_set_implementation_celo.js similarity index 80% rename from scripts/proposals/proposal_13_staking_verifier_change_limits_celo.js rename to scripts/proposals/proposal_13_staking_verifier_change_limits_set_implementation_celo.js index 597a60f9..78fabec9 100644 --- a/scripts/proposals/proposal_13_staking_verifier_change_limits_celo.js +++ b/scripts/proposals/proposal_13_staking_verifier_change_limits_set_implementation_celo.js @@ -40,24 +40,32 @@ async function main() { const stakingVerifier = new ethers.Contract(stakingVerifierAddress, stakingVerifierABI, celoProvider); // Timelock contract across the bridge must change staking limits - const rawPayload = stakingVerifier.interface.encodeFunctionData("changeStakingLimits", + const target = stakingVerifierAddress; + const value = 0; + let rawPayload = stakingVerifier.interface.encodeFunctionData("changeStakingLimits", [parsedData.minStakingDepositLimit, parsedData.timeForEmissionsLimit, parsedData.numServicesLimit, parsedData.apyLimit]); // Pack the second part of data - const target = stakingVerifierAddress; - const value = 0; - const payload = ethers.utils.arrayify(rawPayload); - const data = ethers.utils.solidityPack( + let payload = ethers.utils.arrayify(rawPayload); + let data = ethers.utils.solidityPack( ["address", "uint96", "uint32", "bytes"], [target, value, payload.length, payload] ); + rawPayload = stakingVerifier.interface.encodeFunctionData("setImplementationsStatuses", + [[parsedData.stakingTokenAddress], [true], true]); + payload = ethers.utils.arrayify(rawPayload); + data += ethers.utils.solidityPack( + ["address", "uint96", "uint32", "bytes"], + [target, value, payload.length, payload] + ).slice(2); + const targetChain = 14; // celo const minGasLimit = "2000000"; const transferCost = await wormholeRelayer["quoteEVMDeliveryPrice(uint16,uint256,uint256)"](targetChain, 0, minGasLimit); // Proposal preparation - console.log("Proposal 13. Change staking limits for celo StakingVerifier\n"); + console.log("Proposal 13. Change staking limits on celo in StakingVerifier and whitelist StakingTokenImplementation in StakingFactory\n"); // Build the final payload for the Timelock const sendPayloadSelector = "0x4b5ca6f4"; const timelockPayload = await wormholeRelayer.interface.encodeFunctionData(sendPayloadSelector, [targetChain, @@ -66,7 +74,7 @@ async function main() { const targets = [wormholeRelayerAddress]; const values = [transferCost.nativePriceQuote.toString()]; const callDatas = [timelockPayload]; - const description = "Change Manager in StakingVerifier on celo"; + const description = "Change staking limits on celo in StakingVerifier and whitelist StakingTokenImplementation in StakingFactory"; // Proposal details console.log("targets:", targets); diff --git a/scripts/proposals/proposal_14_staking_verifier_change_limits_ethereum.js b/scripts/proposals/proposal_14_staking_verifier_change_limits_set_implementation_ethereum.js similarity index 74% rename from scripts/proposals/proposal_14_staking_verifier_change_limits_ethereum.js rename to scripts/proposals/proposal_14_staking_verifier_change_limits_set_implementation_ethereum.js index 4dfcf5c7..7c8061eb 100644 --- a/scripts/proposals/proposal_14_staking_verifier_change_limits_ethereum.js +++ b/scripts/proposals/proposal_14_staking_verifier_change_limits_set_implementation_ethereum.js @@ -25,16 +25,19 @@ async function main() { const stakingVerifier = new ethers.Contract(stakingVerifierAddress, stakingVerifierABI, mainnetProvider); // Proposal preparation - console.log("Proposal 14. Change staking limits for ethereum StakingVerifier\n"); + console.log("Proposal 14. Change staking limits on mainnet in StakingVerifier and whitelist StakingTokenImplementation in StakingFactory\n"); // Timelock to change staking limits const timelockPayload = stakingVerifier.interface.encodeFunctionData("changeStakingLimits", [parsedData.minStakingDepositLimit, parsedData.timeForEmissionsLimit, parsedData.numServicesLimit, parsedData.apyLimit]); - const targets = [stakingVerifierAddress]; - const values = [0]; - const callDatas = [timelockPayload]; - const description = "Change Manager in StakingVerifier on mainnet"; + const timelockPayload2 = stakingVerifier.interface.encodeFunctionData("setImplementationsStatuses", + [[parsedData.stakingTokenAddress], [true], true]); + + const targets = [stakingVerifierAddress, stakingVerifierAddress]; + const values = [0, 0]; + const callDatas = [timelockPayload, timelockPayload2]; + const description = "Change staking limits on mainnet in StakingVerifier and whitelist StakingTokenImplementation in StakingFactory"; // Proposal details console.log("targets:", targets); diff --git a/scripts/proposals/proposal_15_staking_verifier_change_limits_arbitrum.js b/scripts/proposals/proposal_15_staking_verifier_change_limits_set_implementation_arbitrum.js similarity index 80% rename from scripts/proposals/proposal_15_staking_verifier_change_limits_arbitrum.js rename to scripts/proposals/proposal_15_staking_verifier_change_limits_set_implementation_arbitrum.js index c7e90971..9f301535 100644 --- a/scripts/proposals/proposal_15_staking_verifier_change_limits_arbitrum.js +++ b/scripts/proposals/proposal_15_staking_verifier_change_limits_set_implementation_arbitrum.js @@ -49,7 +49,7 @@ async function main() { //console.log(l1ToL2MessageGasEstimate); // Proposal preparation - console.log("Proposal 15. Change staking limits for arbitrum StakingVerifier\n"); + console.log("Proposal 15. Change staking limits on arbitrum in StakingVerifier and whitelist StakingTokenImplementation in StakingFactory\n"); // To be able to estimate the gas related params to our L1-L2 message, we need to know how many bytes of calldata out // retryable ticket will require const calldata = stakingVerifier.interface.encodeFunctionData("changeStakingLimits", @@ -106,10 +106,31 @@ async function main() { L1ToL2MessageGasParams.maxSubmissionCost, arbitrumTimelockAddress, AddressZero, L1ToL2MessageGasParams.gasLimit, gasPriceBid, calldata]); - const targets = [inboxAddress]; - const values = [L1ToL2MessageGasParams.deposit]; - const callDatas = [timelockCalldata]; - const description = "Change Manager in StakingVerifier on arbitrum"; + const calldata2 = stakingVerifier.interface.encodeFunctionData("setImplementationsStatuses", + [[parsedData.stakingTokenAddress], [true], true]); + + const L1ToL2MessageGasParams2 = await l1ToL2MessageGasEstimate.estimateAll( + { + from: timelockAddress, + to: stakingVerifierAddress, + l2CallValue, + excessFeeRefundAddress: arbitrumTimelockAddress, + callValueRefundAddress: AddressZero, + data: calldata2, + }, + await getBaseFee(mainnetProvider), + mainnetProvider, + RetryablesGasOverrides + ); + + const timelockCalldata2 = iface.encodeFunctionData("createRetryableTicket", [stakingVerifierAddress, l2CallValue, + L1ToL2MessageGasParams.maxSubmissionCost, arbitrumTimelockAddress, AddressZero, + L1ToL2MessageGasParams.gasLimit, gasPriceBid, calldata2]); + + const targets = [inboxAddress, inboxAddress]; + const values = [L1ToL2MessageGasParams.deposit, L1ToL2MessageGasParams2.deposit]; + const callDatas = [timelockCalldata, timelockCalldata2]; + const description = "Change staking limits on arbitrum in StakingVerifier and whitelist StakingTokenImplementation in StakingFactory"; // Proposal details console.log("targets:", targets);