Skip to content

Commit

Permalink
chore: adding to staking instance deployment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kupermind committed Jul 26, 2024
1 parent 87cc60f commit d195ee3
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/autonolas-registries
Submodule autonolas-registries updated 41 files
+109 −0 .gitleaksignore
+4 −0 README.md
+28 −2 abis/0.8.25/StakingFactory.json
+71 −8 abis/0.8.25/StakingNativeToken.json
+71 −8 abis/0.8.25/StakingToken.json
+84 −25 abis/0.8.25/StakingVerifier.json
+3 −0 audits/README.md
+212 −0 audits/internal6/README.md
+130 −91 contracts/staking/StakingBase.sol
+60 −29 contracts/staking/StakingFactory.sol
+2 −0 contracts/staking/StakingNativeToken.sol
+124 −30 contracts/staking/StakingVerifier.sol
+25 −3 contracts/test/MockStaking.sol
+1 −3 contracts/test/ReentrancyStakingAttacker.sol
+ docs/Vulnerabilities_list_registries.pdf
+105 −0 docs/configuration.json
+1 −1 package.json
+12 −1 scripts/deployment/l2/deploy_16_service_staking_token.js
+12 −1 scripts/deployment/l2/deploy_17_service_staking_native_token.js
+12 −1 scripts/deployment/l2/deploy_18_service_staking_activity_checker.js
+18 −4 scripts/deployment/l2/deploy_19_service_staking_verifier.js
+12 −1 scripts/deployment/l2/deploy_20_service_staking_factory.js
+7 −3 scripts/deployment/l2/deploy_21_service_staking_token_instance.js
+6 −3 scripts/deployment/l2/deploy_22_service_staking_native_token_instance.js
+1 −1 scripts/deployment/l2/globals_arbitrum_one.json
+1 −1 scripts/deployment/l2/globals_arbitrum_sepolia.json
+1 −1 scripts/deployment/l2/globals_base_mainnet.json
+1 −1 scripts/deployment/l2/globals_celo_mainnet.json
+40 −0 scripts/deployment/l2/globals_ethereum_mainnet.json
+1 −1 scripts/deployment/l2/globals_gnosis_chiado.json
+9 −8 scripts/deployment/l2/globals_gnosis_mainnet.json
+1 −1 scripts/deployment/l2/globals_optimistic_mainnet.json
+1 −1 scripts/deployment/l2/globals_optimistic_sepolia.json
+1 −1 scripts/deployment/l2/globals_polygon_amoy.json
+1 −1 scripts/deployment/l2/globals_polygon_mainnet.json
+9 −3 scripts/deployment/l2/verify_19_service_staking_verifier.js
+2 −2 test/ServiceRegistry.js
+244 −29 test/ServiceStaking.js
+7 −4 test/ServiceStaking.t.sol
+129 −49 test/ServiceStakingFactory.js
+65 −99 yarn.lock
2 changes: 1 addition & 1 deletion lib/forge-std
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*global process*/

const { ethers } = require("hardhat");
const { LedgerSigner } = require("@anders-t/ethers-ledger");

async function main() {
const fs = require("fs");
const globalsFile = "globals.json";
const dataFromJSON = fs.readFileSync(globalsFile, "utf8");
let parsedData = JSON.parse(dataFromJSON);
const useLedger = parsedData.useLedger;
const derivationPath = parsedData.derivationPath;
const providerName = parsedData.providerName;
const gasPriceInGwei = parsedData.gasPriceInGwei;
const livenessRatio = parsedData.livenessRatio;

let networkURL = parsedData.networkURL;
if (providerName === "mainnet") {
if (!process.env.ALCHEMY_API_KEY_MAINNET) {
console.log("set ALCHEMY_API_KEY_MAINNET env variable");
}
networkURL += process.env.ALCHEMY_API_KEY_MAINNET;
} else if (providerName === "sepolia") {
if (!process.env.ALCHEMY_API_KEY_SEPOLIA) {
console.log("set ALCHEMY_API_KEY_SEPOLIA env variable");
return;
}
networkURL += process.env.ALCHEMY_API_KEY_SEPOLIA;
} else if (providerName === "polygon") {
if (!process.env.ALCHEMY_API_KEY_MATIC) {
console.log("set ALCHEMY_API_KEY_MATIC env variable");
}
networkURL += process.env.ALCHEMY_API_KEY_MATIC;
} else if (providerName === "polygonAmoy") {
if (!process.env.ALCHEMY_API_KEY_AMOY) {
console.log("set ALCHEMY_API_KEY_AMOY env variable");
return;
}
networkURL += process.env.ALCHEMY_API_KEY_AMOY;
}

const provider = new ethers.providers.JsonRpcProvider(networkURL);
const signers = await ethers.getSigners();

let EOA;
if (useLedger) {
EOA = new LedgerSigner(provider, derivationPath);
} else {
EOA = signers[0];
}
// EOA address
const deployer = await EOA.getAddress();
console.log("EOA is:", deployer);

// Transaction signing and execution
console.log("18. EOA to deploy StakingActivityChecker");
const gasPrice = ethers.utils.parseUnits(gasPriceInGwei, "gwei");
const StakingActivityChecker = await ethers.getContractFactory("StakingActivityChecker");
console.log("You are signing the following transaction: StakingActivityChecker.connect(EOA).deploy()");
const stakingActivityChecker = await StakingActivityChecker.connect(EOA).deploy(livenessRatio,
{ gasPrice });
const result = await stakingActivityChecker.deployed();

// Transaction details
console.log("Contract deployment: StakingActivityChecker");
console.log("Contract address:", stakingActivityChecker.address);
console.log("Transaction:", result.deployTransaction.hash);
// Wait half a minute for the transaction completion
await new Promise(r => setTimeout(r, 30000));

// Writing updated parameters back to the JSON file
parsedData.stakingActivityCheckerAddress = stakingActivityChecker.address;
fs.writeFileSync(globalsFile, JSON.stringify(parsedData));

// Contract verification
if (parsedData.contractVerification) {
const execSync = require("child_process").execSync;
execSync("npx hardhat verify --constructor-args scripts/deployment/l2/verify_18_service_staking_activity_checker.js --network " + providerName + " " + stakingActivityChecker.address, { encoding: "utf-8" });
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
10 changes: 7 additions & 3 deletions scripts/deployment/deploy_02_staking_token_instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async function main() {
const derivationPath = parsedData.derivationPath;
const providerName = parsedData.providerName;
const stakingParams = parsedData.stakingParams;
const gasPriceInGwei = parsedData.gasPriceInGwei;
const serviceRegistryTokenUtilityAddress = parsedData.serviceRegistryTokenUtilityAddress;
const olasAddress = parsedData.olasAddress;
const stakingTokenAddress = parsedData.stakingTokenAddress;
Expand Down Expand Up @@ -52,11 +53,14 @@ async function main() {
// Transaction signing and execution
console.log("21. EOA to deploy StakingTokenInstance via the StakingFactory");
console.log("You are signing the following transaction: StakingFactory.connect(EOA).createStakingInstance()");
const gasPrice = ethers.utils.parseUnits(gasPriceInGwei, "gwei");
const initPayload = stakingToken.interface.encodeFunctionData("initialize", [stakingParams,
serviceRegistryTokenUtilityAddress, olasAddress]);
const stakingTokenInstanceAddress = await stakingFactory.callStatic.createStakingInstance(stakingTokenAddress,
initPayload);
const result = await stakingFactory.createStakingInstance(stakingTokenAddress, initPayload);
const result = await stakingFactory.createStakingInstance(stakingTokenAddress, initPayload, { gasPrice });
let res = await result.wait();
// Get staking contract instance address from the event
const stakingTokenInstanceAddress = "0x" + res.logs[0].topics[2].slice(26);


// Transaction details
console.log("Contract deployment: StakingProxy");
Expand Down
9 changes: 6 additions & 3 deletions scripts/deployment/deploy_03_staking_native_token_instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ async function main() {
const useLedger = parsedData.useLedger;
const derivationPath = parsedData.derivationPath;
const providerName = parsedData.providerName;
const gasPriceInGwei = parsedData.gasPriceInGwei;
const stakingParams = parsedData.stakingParams;
const stakingNativeTokenAddress = parsedData.stakingNativeTokenAddress;
const stakingFactoryAddress = parsedData.stakingFactoryAddress;
Expand Down Expand Up @@ -50,10 +51,12 @@ async function main() {
// Transaction signing and execution
console.log("22. EOA to deploy StakingNativeTokenInstance via the StakingFactory");
console.log("You are signing the following transaction: StakingFactory.connect(EOA).createStakingInstance()");
const gasPrice = ethers.utils.parseUnits(gasPriceInGwei, "gwei");
const initPayload = stakingNativeToken.interface.encodeFunctionData("initialize", [stakingParams]);
const stakingNativeTokenInstanceAddress = await stakingFactory.callStatic.createStakingInstance(
stakingNativeTokenAddress, initPayload);
const result = await stakingFactory.createStakingInstance(stakingNativeTokenAddress, initPayload);
const result = await stakingFactory.createStakingInstance(stakingNativeTokenAddress, initPayload, { gasPrice });
let res = await result.wait();
// Get staking contract instance address from the event
const stakingNativeTokenInstanceAddress = "0x" + res.logs[0].topics[2].slice(26);

// Transaction details
console.log("Contract deployment: StakingProxy");
Expand Down
2 changes: 1 addition & 1 deletion scripts/deployment/globals_gnosis_chiado.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"contractVerification":true,"useLedger":false,"derivationPath":"m/44'/60'/2'/0/0","providerName":"chiado","networkURL":"https://rpc.chiadochain.net","gasPriceInGwei":"5","gnosisSafeAddress":"0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552","gnosisSafeProxyFactoryAddress":"0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2","serviceRegistryAddress":"0x31D3202d8744B16A120117A053459DDFAE93c855","serviceRegistryTokenUtilityAddress":"0xc2c7E40674f1C7Bb99eFe5680Efd79842502bED4","olasAddress":"0xE40AE73aa0Ed3Ec35fdAF56e01FCd0D1Ff1d9AB6","multisigProxyHash130":"0xb89c1b3bdf2cf8827818646bce9a8f6e372885f8c55e5c07acbd307cb133b000","stakingNativeTokenAddress":"0xAed729d4f4b895d8ca84ba022675bB0C44d2cD52","stakingTokenAddress":"0xf438a9a11902ffecfc2dA2f2224193C6AaBc6346","agentMechAddress":"0x0A3cFc6BEe9658Eda040e6BB366FE963DdCe82C9","livenessRatio":"700000000000000","mechActivityCheckerAddress":"0x7781202B9b09B92F512A0E343F24d349d09bc3A6","stakingVerifierAddress":"0x00000000000000000000000000000000000000000","stakingFactoryAddress":"0xbF6Dd5e87535b8766f4848DE1c13f8d4EDfA86C5","stakingParams":{"metadataHash":"0x0000000000000000000000000000000000000000000000000000000000000001","maxNumServices":"100","rewardsPerSecond":"1000000000000000","minStakingDeposit":"50000000000000000000","minNumStakingPeriods":"3","maxNumInactivityPeriods":"3","livenessPeriod":"86400","timeForEmissions":"86400","numAgentInstances":"1","agentIds":["12"],"threshold":"0","configHash":"0x0000000000000000000000000000000000000000000000000000000000000000","proxyHash":"0xb89c1b3bdf2cf8827818646bce9a8f6e372885f8c55e5c07acbd307cb133b000","serviceRegistry":"0x31D3202d8744B16A120117A053459DDFAE93c855","activityChecker":"0x7781202B9b09B92F512A0E343F24d349d09bc3A6"},"stakingTokenInstanceAddress":"0x3cbf58bcC16d9195c35E01aFE1A57caf257e113a","stakingNativeTokenInstanceAddress":"0x6F67efF5cb5C35a40CdE2eD570f0885fe7De7D6b"}
{"contractVerification":true,"useLedger":false,"derivationPath":"m/44'/60'/2'/0/0","providerName":"chiado","networkURL":"https://rpc.chiadochain.net","gasPriceInGwei":"5","gnosisSafeAddress":"0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552","gnosisSafeProxyFactoryAddress":"0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2","serviceRegistryAddress":"0x31D3202d8744B16A120117A053459DDFAE93c855","serviceRegistryTokenUtilityAddress":"0xc2c7E40674f1C7Bb99eFe5680Efd79842502bED4","olasAddress":"0xE40AE73aa0Ed3Ec35fdAF56e01FCd0D1Ff1d9AB6","multisigProxyHash130":"0xb89c1b3bdf2cf8827818646bce9a8f6e372885f8c55e5c07acbd307cb133b000","stakingNativeTokenAddress":"","stakingTokenAddress":"0x00c3B912FF54B2a7E37D495a496f025D51fb8058","agentMechAddress":"0x0A3cFc6BEe9658Eda040e6BB366FE963DdCe82C9","livenessRatio":"700000000000000","mechActivityCheckerAddress":"0x7781202B9b09B92F512A0E343F24d349d09bc3A6","stakingFactoryAddress":"0xbF6Dd5e87535b8766f4848DE1c13f8d4EDfA86C5","stakingParams":{"metadataHash":"0x0000000000000000000000000000000000000000000000000000000000000001","maxNumServices":"100","rewardsPerSecond":"1000000000000000","minStakingDeposit":"50000000000000000000","minNumStakingPeriods":"3","maxNumInactivityPeriods":"2","livenessPeriod":"86400","timeForEmissions":"86400","numAgentInstances":"1","agentIds":["25"],"threshold":"0","configHash":"0x0000000000000000000000000000000000000000000000000000000000000000","proxyHash":"0xb89c1b3bdf2cf8827818646bce9a8f6e372885f8c55e5c07acbd307cb133b000","serviceRegistry":"0x31D3202d8744B16A120117A053459DDFAE93c855","activityChecker":"0x7781202B9b09B92F512A0E343F24d349d09bc3A6"},"stakingTokenInstanceAddress":"","stakingNativeTokenInstanceAddress":""}
2 changes: 1 addition & 1 deletion scripts/deployment/globals_gnosis_mainnet.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"contractVerification":true,"useLedger":false,"derivationPath":"m/44'/60'/2'/0/0","providerName":"gnosis","networkURL":"https://rpc.gnosischain.com","gasPriceInGwei":"15","gnosisSafeAddress":"0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552","gnosisSafeProxyFactoryAddress":"0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2","serviceRegistryAddress":"0x9338b5153AE39BB89f50468E608eD9d764B755fD","serviceRegistryTokenUtilityAddress":"0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8","olasAddress":"0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f","multisigProxyHash130":"0xb89c1b3bdf2cf8827818646bce9a8f6e372885f8c55e5c07acbd307cb133b000","stakingNativeTokenAddress":"","stakingTokenAddress":"0x9Ec97Be9FF55ff11606ce7c589956f7Bf3D0b241","agentMechAddress":"0x77af31De935740567Cf4fF1986D04B2c964A786a","livenessRatio":"46296296296296","mechActivityCheckerAddress":"0x155547857680A6D51bebC5603397488988DEb1c8","stakingVerifierAddress":"0x00000000000000000000000000000000000000000","stakingFactoryAddress":"0xC720f1Ada2a882a4B375dCCd0aAc3F3B3e58bc84","stakingParams":{"metadataHash":"0x888914090dd6dd2bc98e113d7558854e6be7ad06d1af180cac83aac61479059e","maxNumServices":"200","rewardsPerSecond":"549768518519","minStakingDeposit":"10000000000000000000","minNumStakingPeriods":"3","maxNumInactivityPeriods":"2","livenessPeriod":"86400","timeForEmissions":"2592000","numAgentInstances":"1","agentIds":["14"],"threshold":"0","configHash":"0x0000000000000000000000000000000000000000000000000000000000000000","proxyHash":"0xb89c1b3bdf2cf8827818646bce9a8f6e372885f8c55e5c07acbd307cb133b000","serviceRegistry":"0x9338b5153AE39BB89f50468E608eD9d764B755fD","activityChecker":"0x155547857680A6D51bebC5603397488988DEb1c8"},"stakingTokenInstanceAddress":"0xEE9F19b5DF06c7E8Bfc7B28745dcf944C504198A"}
{"contractVerification":true,"useLedger":false,"derivationPath":"m/44'/60'/2'/0/0","providerName":"gnosis","networkURL":"https://rpc.gnosischain.com","gasPriceInGwei":"15","gnosisSafeAddress":"0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552","gnosisSafeProxyFactoryAddress":"0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2","serviceRegistryAddress":"0x9338b5153AE39BB89f50468E608eD9d764B755fD","serviceRegistryTokenUtilityAddress":"0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8","olasAddress":"0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f","multisigProxyHash130":"0xb89c1b3bdf2cf8827818646bce9a8f6e372885f8c55e5c07acbd307cb133b000","stakingNativeTokenAddress":"","stakingTokenAddress":"0xEa00be6690a871827fAfD705440D20dd75e67AB1","agentMechAddress":"0x77af31De935740567Cf4fF1986D04B2c964A786a","livenessRatio":"46296296296296","mechActivityCheckerAddress":"0x155547857680A6D51bebC5603397488988DEb1c8","stakingFactoryAddress":"0xb0228CA253A88Bc8eb4ca70BCAC8f87b381f4700","stakingParams":{"metadataHash":"0x888914090dd6dd2bc98e113d7558854e6be7ad06d1af180cac83aac61479059e","maxNumServices":"100","rewardsPerSecond":"1649305555557","minStakingDeposit":"20000000000000000000","minNumStakingPeriods":"3","maxNumInactivityPeriods":"2","livenessPeriod":"86400","timeForEmissions":"2592000","numAgentInstances":"1","agentIds":["25"],"threshold":"0","configHash":"0x0000000000000000000000000000000000000000000000000000000000000000","proxyHash":"0xb89c1b3bdf2cf8827818646bce9a8f6e372885f8c55e5c07acbd307cb133b000","serviceRegistry":"0x9338b5153AE39BB89f50468E608eD9d764B755fD","activityChecker":"0x155547857680A6D51bebC5603397488988DEb1c8"},"stakingTokenInstanceAddress":""}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require("fs");
const globalsFile = "globals.json";
const dataFromJSON = fs.readFileSync(globalsFile, "utf8");
const parsedData = JSON.parse(dataFromJSON);
const livenessRatio = parsedData.livenessRatio;

module.exports = [
livenessRatio
];

0 comments on commit d195ee3

Please sign in to comment.