Skip to content

Commit

Permalink
chore: staking verifier proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
kupermind committed Oct 31, 2024
1 parent a63bf83 commit 6811ea6
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6811ea6

Please sign in to comment.