Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion solidity/random-beacon/tasks/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
stake,
authorize,
register,
addBetaOperator,
} from "./utils"

// Main task executing all child tasks.
Expand All @@ -19,10 +20,12 @@ export const TASK_STAKE = "stake"
// Name prefix that should be used in tasks implementation for specific application.
export const TASK_AUTHORIZE = "authorize"
export const TASK_REGISTER = "register"
export const TASK_ADD_BETA_OPERATOR = "add_beta_operator"
// Subtask for the Random Beacon application.
const TASK_INITIALIZE_BEACON = `${TASK_INITIALIZE}:beacon`
const TASK_AUTHORIZE_BEACON = `${TASK_AUTHORIZE}:beacon`
const TASK_REGISTER_BEACON = `${TASK_REGISTER}:beacon`
const TASK_ADD_BETA_OPERATOR_BEACON = `${TASK_ADD_BETA_OPERATOR}:beacon`

task(
TASK_INITIALIZE,
Expand All @@ -45,6 +48,8 @@ task(
await hre.run(TASK_INITIALIZE_STAKING, args)
// Initialize Beacon
await hre.run(TASK_INITIALIZE_BEACON, args)
// Set the operator as a beta operator
await hre.run(TASK_ADD_BETA_OPERATOR_BEACON, args)
})

task(TASK_INITIALIZE_STAKING, "Initializes staking for a service provider")
Expand Down Expand Up @@ -124,7 +129,16 @@ task(
"Registers an operator for a staking provider in Beacon"
)
.addParam("provider", "Staking Provider", undefined, types.string)
.addParam("operator", "Staking Operator", undefined, types.string)
.addParam("operator", "Operator Address", undefined, types.string)
.setAction(async (args, hre) => {
await register(hre, "RandomBeacon", args.provider, args.operator)
})

task(
TASK_ADD_BETA_OPERATOR_BEACON,
"Adds an operator to the set of beta operators in Beacon"
)
.addParam("operator", "Operator Address", undefined, types.string)
.setAction(async (args, hre) => {
await addBetaOperator(hre, "BeaconSortitionPool", args.operator)
})
22 changes: 22 additions & 0 deletions solidity/random-beacon/tasks/utils/add_beta_operator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable no-console */
import type { HardhatRuntimeEnvironment } from "hardhat/types"

// eslint-disable-next-line import/prefer-default-export
export async function addBetaOperator(
hre: HardhatRuntimeEnvironment,
sortitionPoolDeploymentName: string,
operator: string
): Promise<void> {
const { ethers, helpers } = hre
const sortitionPool = await helpers.contracts.getContract(
sortitionPoolDeploymentName
)
const chaosnetOwner = await sortitionPool.chaosnetOwner()

console.log(`Adding ${operator} to the set of beta operators...`)
await (
await sortitionPool
.connect(await ethers.getSigner(chaosnetOwner))
.addBetaOperators([operator])
).wait()
}
1 change: 1 addition & 0 deletions solidity/random-beacon/tasks/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./ether"
export * from "./mint"
export * from "./register"
export * from "./stake"
export * from "./add_beta_operator"