Skip to content

Commit

Permalink
Check bonded ETH for operators
Browse files Browse the repository at this point in the history
We are getting bond creation events to obtain values of bonds created
for all the ECDSA operators.
  • Loading branch information
nkuba committed Sep 23, 2020
1 parent 9963c5e commit 65110d7
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion inspector/scripts/inspect-operators.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const truffleContract = require("@truffle/contract")
const clc = require("cli-color");

const contractHelper = require("./lib/contract-helper")

const KeepTokenJson = require("@keep-network/keep-core/artifacts/KeepToken.json")
const TokenStakingJson = require("@keep-network/keep-core/artifacts/TokenStaking.json")
const KeepBondingJson = require("@keep-network/keep-ecdsa/artifacts/KeepBonding.json")
Expand Down Expand Up @@ -39,6 +41,11 @@ module.exports = async function() {
const keepBonding = await KeepBonding.deployed()
const tbtcSystem = await TBTCSystem.deployed()

const deploymentBlock = await contractHelper.getDeploymentBlockNumber(
KeepBondingJson,
web3,
)

console.log(clc.yellow(`*** Contract Addresses ***`))
console.log(`KeepToken: ${keepToken.address}`)
console.log(`TokenStaking: ${tokenStaking.address}`)
Expand Down Expand Up @@ -85,9 +92,36 @@ module.exports = async function() {
console.log(clc.italic(`Fetching staking info for [${ecdsaOperators.length}] ECDSA operators...`))
console.log(``)

const bondCreatedEvents = await keepBonding.getPastEvents("BondCreated", {
fromBlock: deploymentBlock,
toBlock: "latest",
})

const totalOperatorBondsAmount = {}
const totalBondedAmount = web3.utils.toBN(0)

for (let i = 0; i < bondCreatedEvents.length; i++) {
const event = bondCreatedEvents[i]

const operator = event.args.operator.toLowerCase()
const bondAmount = web3.utils.toBN(event.args.amount)

totalBondedAmount.iadd(bondAmount)

if (totalOperatorBondsAmount[operator] === undefined) {
totalOperatorBondsAmount[operator] = bondAmount
} else {
totalOperatorBondsAmount[operator].iadd(bondAmount)
}
}

console.log(
`Total bonded ETH: ${web3.utils.fromWei(totalBondedAmount).toString()}`,
)

const ecdsaSummary = []
for (let i = 0; i < ecdsaOperators.length; i++) {
const operator = ecdsaOperators[i]
const operator = ecdsaOperators[i].toLowerCase()

const eligibleStake = await tokenStaking.eligibleStake(operator, keepRandomBeaconOperator.address)
const eligibleStakeKeep = eligibleStake.div(tokenDecimalMultiplier)
Expand All @@ -107,17 +141,23 @@ module.exports = async function() {
isUpToDateInTbtcPool = "N/A"
}

const bondsAmountEth = web3.utils.fromWei(
web3.utils.toBN(totalOperatorBondsAmount[operator] || 0),
)

ecdsaSummary.push({
address: operator,
eligibleStakeKeep: eligibleStakeKeep.toString(),
operatorBalanceEth: operatorBalanceEth.toString(),
unbondedValueEth: unbondedValueEth.toString(),
bondsAmountEth: bondsAmountEth.toString(),
isRegisteredInTbtcPool: isRegisteredInTbtcPool,
isUpToDateInTbtcPool: isUpToDateInTbtcPool
})
}

console.log(clc.yellow(`*** ECDSA Operators ***`))

if (process.env.OUTPUT_MODE === "text") {
ecdsaSummary.forEach((s) =>
console.log(
Expand Down

0 comments on commit 65110d7

Please sign in to comment.