Skip to content

Commit

Permalink
Added depositSSV HH task
Browse files Browse the repository at this point in the history
  • Loading branch information
naddison36 committed May 3, 2024
1 parent 1498267 commit 0ece8b9
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 45 deletions.
56 changes: 50 additions & 6 deletions contracts/tasks/ssv.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
const { parseUnits, formatUnits } = require("ethers/lib/utils");
const { ClusterScanner, NonceScanner } = require("ssv-scanner");

const addresses = require("../utils/addresses");
const { resolveContract } = require("../utils/resolvers");
const { getSigner } = require("../utils/signers");
const { logTxDetails } = require("../utils/txLogger");

const log = require("../utils/logger")("task:ssv");

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);
};

const getClusterInfo = async ({
ownerAddress,
operatorids,
Expand Down Expand Up @@ -69,15 +84,44 @@ const getClusterNonce = async ({
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);
const depositSSV = async ({ amount, operatorids }, hre) => {
const amountBN = parseUnits(amount.toString(), 18);
log(`Splitting operator IDs ${operatorids}`);
const operatorIds = operatorids.split(".").map((id) => parseInt(id));

const signer = await getSigner();

const strategy = await resolveContract(
"NativeStakingSSVStrategyProxy",
"NativeStakingSSVStrategy"
);
const ssvNetworkAddress = addresses[hre.network.name].SSVNetwork;
const ssvNetwork = await resolveContract(ssvNetworkAddress, "ISSVNetwork");

// Cluster details
const clusterInfo = await getClusterInfo({
chainId: hre.network.config.chainId,
ssvNetwork: ssvNetwork.address,
operatorIds,
ownerAddress: strategy.address,
});

log(
`About to deposit ${formatUnits(
amountBN
)} SSV tokens to the SSV Network for native staking strategy ${
strategy.address
} with operator IDs ${operatorIds}`
);
log(`Cluster: ${JSON.stringify(clusterInfo.snapshot)}`);
const tx = await strategy
.connect(signer)
.depositSSV(operatorIds, amountBN, clusterInfo.cluster);
await logTxDetails(tx, "depositSSV");
};

module.exports = {
printClusterInfo,
getClusterInfo,
depositSSV,
};
19 changes: 18 additions & 1 deletion contracts/tasks/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const {
curveSwapTask,
curvePoolTask,
} = require("./curve");
const { printClusterInfo } = require("./ssv");
const { depositSSV, printClusterInfo } = require("./ssv");
const {
amoStrategyTask,
mintAndAddOTokensTask,
Expand All @@ -61,6 +61,7 @@ const {
transferGovernance,
claimGovernance,
} = require("./governable");

const log = require("../utils/logger")("tasks");

// Environment tasks.
Expand Down Expand Up @@ -816,3 +817,19 @@ subtask("getClusterInfo", "Print out information regarding SSV cluster")
task("getClusterInfo").setAction(async (_, __, runSuper) => {
return runSuper();
});

subtask(
"depositSSV",
"Deposit SSV tokens from the native staking strategy into an SSV Cluster"
)
.addParam("amount", "Amount of SSV tokens to deposit", undefined, types.float)
.addParam(
"operatorids",
"4 operator ids separated with a dot: same as IP format. E.g. 60.79.220.349",
undefined,
types.string
)
.setAction(depositSSV);
task("depositSSV").setAction(async (_, __, runSuper) => {
return runSuper();
});
29 changes: 21 additions & 8 deletions contracts/utils/resolvers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const addresses = require("./addresses");
const { ethereumAddress } = require("./regex");

const log = require("./logger")("task:assets");

Expand Down Expand Up @@ -34,28 +35,40 @@ const resolveAsset = async (symbol) => {

/**
* Returns a contract instance.
* @param {string} proxyName Name of the proxy contract or contract name if no proxy. eg OETHVaultProxy or OETHZapper
* @param {string} abiName ABI name. eg VaultAdmin, VaultCore, Governable or IERC20Metadata
* @param {string} proxy Address or name of the proxy contract or contract name if no proxy. eg OETHVaultProxy or OETHZapper
* @param {string} [abiName=proxy] ABI name. Will default to proxy is not used. eg VaultAdmin, VaultCore, Governable or IERC20Metadata
* @returns
*/
const resolveContract = async (proxyName, abiName) => {
const resolveContract = async (proxy, abiName) => {
// dynamically load in function so this function can be used by tasks
// if put outside this function, the following error occurs:
// "Hardhat can't be initialized while its config is being defined"
const hre = require("hardhat");

const proxy = await ethers.getContract(proxyName);
if (!proxy) {
// If proxy is an address
if (proxy.match(ethereumAddress)) {
if (!abiName) {
throw Error(`Must pass an ABI name if the proxy is an address`);
}
const contract = await ethers.getContractAt(abiName, proxy);
if (!contract) {
throw Error(`Failed find ABI for "${abiName}"`);
}
return contract;
}

const proxyContract = await ethers.getContract(proxy);
if (!proxyContract) {
throw Error(
`Failed find proxy "${proxyName}" on the ${hre.network.name} network`
`Failed find proxy "${proxy}" on the ${hre.network.name} network`
);
}
log(
`Resolved proxy ${proxyName} on the ${hre.network.name} network to ${proxy.address}`
`Resolved proxy ${proxy} on the ${hre.network.name} network to ${proxyContract.address}`
);

if (abiName) {
const contract = await ethers.getContractAt(abiName, proxy.address);
const contract = await ethers.getContractAt(abiName, proxyContract.address);
if (!contract) {
throw Error(`Failed find ABI for "${abiName}"`);
}
Expand Down
30 changes: 0 additions & 30 deletions contracts/utils/ssv.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,12 @@
const { parseUnits, formatUnits } = require("ethers/lib/utils");
const { ClusterScanner, NonceScanner } = require("ssv-scanner");
const { SSVKeys, KeyShares, KeySharesItem } = require("ssv-keys");
const path = require("path");
const fsp = require("fs").promises;

const { isForkWithLocalNode } = require("../test/helpers");
const { logTxDetails } = require("../utils/txLogger");

const log = require("../utils/logger")("utils:ssv");

const depositSSV = async (options) => {
const { signer, chainId, nodeDelegator, ssvNetwork, amount, operatorIds } =
options;
const amountBN = parseUnits(amount.toString(), 18);

// Cluster details
const clusterInfo = await getClusterInfo({
chainId,
ssvNetwork,
operatorIds,
ownerAddress: nodeDelegator.address,
});

log(
`About to deposit ${formatUnits(
amountBN
)} SSV tokens to the SSV Network for NodeDelegator ${
nodeDelegator.address
} with operator IDs ${operatorIds}`
);
log(`Cluster: ${JSON.stringify(clusterInfo.snapshot)}`);
const tx = await nodeDelegator
.connect(signer)
.depositSSV(operatorIds, amountBN, clusterInfo.cluster);
await logTxDetails(tx, "depositSSV");
};

const splitValidatorKey = async ({
keystorelocation,
keystorepass,
Expand Down Expand Up @@ -195,7 +166,6 @@ const printClusterInfo = async (options) => {
};

module.exports = {
depositSSV,
printClusterInfo,
getClusterInfo,
splitValidatorKey,
Expand Down

0 comments on commit 0ece8b9

Please sign in to comment.