-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ability to fetch SSV cluster information * prettier
- Loading branch information
1 parent
54927ed
commit 15aea4f
Showing
4 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
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.PROVIDER_URL : process.env.HOLESKY_PROVIDER_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.PROVIDER_URL : process.env.HOLESKY_PROVIDER_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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters