Skip to content

Commit 856fb59

Browse files
committed
Hardhat task to add an operator to beta operators set for the random beacon
After adding chaosnet feature to the sortition pool, we need to add an operator to the beta operators set during the operator initialization. It is done here: hardhat task doing it is provided and it is attached to the initialize task.
1 parent 723bc65 commit 856fb59

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

solidity/random-beacon/tasks/initialize.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
stake,
77
authorize,
88
register,
9+
addBetaOperator,
910
} from "./utils"
1011

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

2730
task(
2831
TASK_INITIALIZE,
@@ -45,6 +48,8 @@ task(
4548
await hre.run(TASK_INITIALIZE_STAKING, args)
4649
// Initialize Beacon
4750
await hre.run(TASK_INITIALIZE_BEACON, args)
51+
// Set the operator as a beta operator
52+
await hre.run(TASK_ADD_BETA_OPERATOR_BEACON, args)
4853
})
4954

5055
task(TASK_INITIALIZE_STAKING, "Initializes staking for a service provider")
@@ -124,7 +129,16 @@ task(
124129
"Registers an operator for a staking provider in Beacon"
125130
)
126131
.addParam("provider", "Staking Provider", undefined, types.string)
127-
.addParam("operator", "Staking Operator", undefined, types.string)
132+
.addParam("operator", "Operator Address", undefined, types.string)
128133
.setAction(async (args, hre) => {
129134
await register(hre, "RandomBeacon", args.provider, args.operator)
130135
})
136+
137+
task(
138+
TASK_ADD_BETA_OPERATOR_BEACON,
139+
"Adds an operator to the set of beta operators in Beacon"
140+
)
141+
.addParam("operator", "Operator Address", undefined, types.string)
142+
.setAction(async (args, hre) => {
143+
await addBetaOperator(hre, "BeaconSortitionPool", args.operator)
144+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable no-console */
2+
import type { HardhatRuntimeEnvironment } from "hardhat/types"
3+
4+
// eslint-disable-next-line import/prefer-default-export
5+
export async function addBetaOperator(
6+
hre: HardhatRuntimeEnvironment,
7+
sortitionPoolDeploymentName: string,
8+
operator: string
9+
): Promise<void> {
10+
const { ethers, helpers } = hre
11+
const sortitionPool = await helpers.contracts.getContract(
12+
sortitionPoolDeploymentName
13+
)
14+
const chaosnetOwner = await sortitionPool.chaosnetOwner()
15+
16+
console.log(`Adding ${operator} to the set of beta operators...`)
17+
await (
18+
await sortitionPool
19+
.connect(await ethers.getSigner(chaosnetOwner))
20+
.addBetaOperators([operator])
21+
).wait()
22+
}

solidity/random-beacon/tasks/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from "./ether"
33
export * from "./mint"
44
export * from "./register"
55
export * from "./stake"
6+
export * from "./add_beta_operator"

0 commit comments

Comments
 (0)