-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathssv.js
131 lines (108 loc) · 3.95 KB
/
ssv.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const {
parseUnits,
formatUnits,
solidityPack,
hexlify,
} = require("ethers/lib/utils");
const addresses = require("../utils/addresses");
const { resolveContract } = require("../utils/resolvers");
const { getSigner } = require("../utils/signers");
const { getClusterInfo } = require("../utils/ssv");
const { networkMap } = require("../utils/hardhat-helpers");
const { logTxDetails } = require("../utils/txLogger");
const { resolveNativeStakingStrategyProxy } = require("./validator");
const log = require("../utils/logger")("task:ssv");
async function removeValidators({ index, pubkeys, operatorids }) {
const signer = await getSigner();
log(`Splitting operator IDs ${operatorids}`);
const operatorIds = operatorids.split(",").map((id) => parseInt(id));
const strategy = await resolveNativeStakingStrategyProxy(index);
const { chainId } = await ethers.provider.getNetwork();
// Cluster details
const { cluster } = await getClusterInfo({
chainId,
ssvNetwork: hre.network.name.toUpperCase(),
operatorids,
ownerAddress: strategy.address,
});
log(`Splitting public keys ${pubkeys}`);
const pubKeys = pubkeys.split(",").map((pubkey) => hexlify(pubkey));
log(`About to remove validators: ${pubKeys}`);
const tx = await strategy
.connect(signer)
.removeSsvValidators(pubKeys, operatorIds, cluster);
await logTxDetails(tx, "removeSsvValidators");
}
const printClusterInfo = async (options) => {
const cluster = await getClusterInfo(options);
console.log(`block ${cluster.block}`);
console.log(`Cluster: ${JSON.stringify(cluster.cluster, null, " ")}`);
};
const depositSSV = async ({ amount, index, operatorids }) => {
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 resolveNativeStakingStrategyProxy(index);
const { chainId } = await ethers.provider.getNetwork();
const network = networkMap[chainId];
const ssvNetworkAddress = addresses[network].SSVNetwork;
const ssvNetwork = await resolveContract(ssvNetworkAddress, "ISSVNetwork");
// Cluster details
const clusterInfo = await getClusterInfo({
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");
};
const calcDepositRoot = async ({ index, pubkey, sig }, hre) => {
if (hre.network.name !== "hardhat") {
throw new Error("This task can only be run in hardhat network");
}
const factory = await ethers.getContractFactory("DepositContractUtils");
const depositContractUtils = await factory.deploy();
const proxyNumber =
index === undefined || index === 1 ? "" : index.toString();
const strategyAddress =
addresses.mainnet[`NativeStakingSSVStrategy${proxyNumber}Proxy`];
log(
`Resolved Native Staking Strategy with index ${index} to address to ${strategyAddress}`
);
const withdrawalCredentials = solidityPack(
["bytes1", "bytes11", "address"],
[
"0x01",
"0x0000000000000000000000",
addresses.mainnet[`NativeStakingSSVStrategy${proxyNumber}Proxy`],
]
);
log(`Withdrawal Credentials: ${withdrawalCredentials}`);
log(
`About to calculate deposit data root for pubkey ${pubkey} and sig ${sig}`
);
const depositDataRoot = await depositContractUtils.calculateDepositDataRoot(
pubkey,
withdrawalCredentials,
sig
);
console.log(`Deposit Root Data: ${depositDataRoot}`);
};
module.exports = {
printClusterInfo,
depositSSV,
calcDepositRoot,
removeValidators,
};