Skip to content

Commit

Permalink
small test change
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrowDom committed Apr 29, 2024
1 parent 6d22648 commit 51c4d4e
Show file tree
Hide file tree
Showing 5 changed files with 1,617 additions and 28 deletions.
1 change: 0 additions & 1 deletion contracts/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ if (process.env.HARDHAT_CACHE_DIR) {
}
const { provider, chainId } = getHardhatNetworkProperties();

console.log("PATHS", paths);
module.exports = {
solidity: {
version: "0.8.7",
Expand Down
1 change: 1 addition & 0 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"solhint": "^3.4.1",
"solidifier": "^2.2.3",
"solidity-coverage": "^0.8.2",
"ssv-scanner": "github:bloxapp/ssv-scanner",
"sync-fetch": "^0.5.2",
"web3-utils": "^1.5.2"
},
Expand Down
71 changes: 71 additions & 0 deletions contracts/tasks/ssv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const { ClusterScanner, NonceScanner } = require("ssv-scanner");
const log = require("../utils/logger")("task:ssv");

const getClusterInfo = async ({ ownerAddress, operatorids, chainId, ssvNetwork }) => {
const operatorIds = operatorids.split(".").map((id) => parseInt(id));

const ssvNetworkName = chainId === 1 ? "MAINNET" : "PRATER";
const providerUrl = chainId === 1 ? process.env.MAINNET_RPC_URL : process.env.GOERLI_RPC_URL;

const params = {
nodeUrl: providerUrl, // this can be an Infura, or Alchemy node, necessary to query the blockchain
contractAddress: ssvNetwork, // this is the address of SSV smart contract
ownerAddress, // this is the wallet address of the cluster owner
/* Based on the network they fetch contract ABIs. See code: https://github.com/bloxapp/ssv-scanner/blob/v1.0.3/src/lib/contract.provider.ts#L16-L22
* and the ABIs are fetched from here: https://github.com/bloxapp/ssv-scanner/tree/v1.0.3/src/shared/abi
*
* Prater seems to work for Goerli at the moment
*/
network: ssvNetworkName,
operatorIds: operatorIds, // this is a list of operator IDs chosen by the owner for their cluster
};

// ClusterScanner is initialized with the given parameters
const clusterScanner = new ClusterScanner(params);
// and when run, it returns the Cluster Snapshot
const result = await clusterScanner.run(params.operatorIds);
const cluster = {
block: result.payload.Block,
snapshot: result.cluster,
cluster: Object.values(result.cluster),
};
log(`Cluster info ${JSON.stringify(cluster)}`);
return cluster;
};

const getClusterNonce = async ({ ownerAddress, operatorids, chainId, ssvNetwork }) => {
const operatorIds = operatorids.split(".").map((id) => parseInt(id));

const ssvNetworkName = chainId === 1 ? "MAINNET" : "PRATER";
const providerUrl = chainId === 1 ? process.env.MAINNET_RPC_URL : process.env.GOERLI_RPC_URL;

const params = {
nodeUrl: providerUrl, // this can be an Infura, or Alchemy node, necessary to query the blockchain
contractAddress: ssvNetwork, // this is the address of SSV smart contract
ownerAddress, // this is the wallet address of the cluster owner
/* Based on the network they fetch contract ABIs. See code: https://github.com/bloxapp/ssv-scanner/blob/v1.0.3/src/lib/contract.provider.ts#L16-L22
* and the ABIs are fetched from here: https://github.com/bloxapp/ssv-scanner/tree/v1.0.3/src/shared/abi
*
* Prater seems to work for Goerli at the moment
*/
network: ssvNetworkName,
operatorIds: operatorIds, // this is a list of operator IDs chosen by the owner for their cluster
};

const nonceScanner = new NonceScanner(params);
const nextNonce = await nonceScanner.run();
return nextNonce;
};

const printClusterInfo = async (options) => {
const cluster = await getClusterInfo(options);
const nextNonce = await getClusterNonce(options);
console.log(`block ${cluster.block}`);
console.log(`Cluster: ${JSON.stringify(cluster.snapshot, null, " ")}`);
console.log("Next Nonce:", nextNonce);
};

module.exports = {
printClusterInfo,
getClusterInfo,
};
27 changes: 26 additions & 1 deletion contracts/tasks/tasks.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { subtask, task, types } = require("hardhat/config");

const ethers = require("ethers");
const { fund } = require("./account");
const { debug } = require("./debug");
const { env } = require("./env");
const { execute, executeOnFork, proposal, governors } = require("./governance");
const { smokeTest, smokeTestCheck } = require("./smokeTest");
const addresses = require("../utils/addresses");
const {
storeStorageLayoutForAllContracts,
assertStorageLayoutChangeSafe,
Expand Down Expand Up @@ -46,6 +47,9 @@ const {
curveSwapTask,
curvePoolTask,
} = require("./curve");
const {
printClusterInfo
} = require("./ssv");
const {
amoStrategyTask,
mintAndAddOTokensTask,
Expand Down Expand Up @@ -739,3 +743,24 @@ task("proxyUpgrades", "Lists all proxy implementation changes")
types.int
)
.setAction(proxyUpgrades);

subtask("getClusterInfo", "Print out information regarding SSV cluster")
.addParam(
"operatorids",
"4 operator ids separated with a dot: same as IP format. E.g. 60.79.220.349",
"",
types.string,
)
.addParam("owner", "Address of the cluster owner. Default to NodeDelegator", undefined, types.string)
.setAction(async (taskArgs) => {
const network = await ethers.provider.getNetwork();
const ssvNetwork = addresses[network.name].SSVNetwork;

log(
`Fetching cluster info for cluster owner ${taskArgs.owner} with operator ids: ${taskArgs.operatorids} from the ${network.name} network using ssvNetworkContract ${ssvNetwork}`,
);
await printClusterInfo({ ...taskArgs, ownerAddress: taskArgs.owner, chainId: network.chainId, ssvNetwork });
});
task("getClusterInfo").setAction(async (_, __, runSuper) => {
return runSuper();
});
Loading

0 comments on commit 51c4d4e

Please sign in to comment.