Skip to content

Commit 0c44328

Browse files
committed
Add operator != msg.sender. Add setOperator to cli
1 parent d3576ce commit 0c44328

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

cli/commands/contracts/staking.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ export const setDelegationParameters = async (
124124
...[indexingRewardCut, queryFeeCut, cooldownBlocks],
125125
)
126126
}
127+
export const setOperator = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
128+
const operator = cliArgs.operator
129+
const allowed = cliArgs.allowed
130+
const staking = cli.contracts.Staking
131+
logger.log(`Setting operator ${operator} to ${allowed} for account ${cli.walletAddress}`)
132+
await sendTransaction(cli.wallet, staking, 'setOperator', ...[operator, allowed])
133+
}
127134

128135
export const stakingCommand = {
129136
command: 'staking',
@@ -359,12 +366,32 @@ export const stakingCommand = {
359366
.option('cooldownBlocks', {
360367
description: 'Period that need to pass to update delegation parameters',
361368
type: 'number',
369+
})
370+
},
371+
handler: async (argv: CLIArgs): Promise<void> => {
372+
return setDelegationParameters(await loadEnv(argv), argv)
373+
},
374+
})
375+
.command({
376+
command: 'setOperator',
377+
describe: 'Set the operator for a graph account',
378+
builder: (yargs: Argv) => {
379+
return yargs
380+
.option('operator', {
381+
description: 'Address of the operator',
382+
type: 'string',
383+
requiresArg: true,
384+
demandOption: true,
385+
})
386+
.option('allowed', {
387+
description: 'Set to true to be an operator, false to revoke',
388+
type: 'boolean',
362389
requiresArg: true,
363390
demandOption: true,
364391
})
365392
},
366393
handler: async (argv: CLIArgs): Promise<void> => {
367-
return setDelegationParameters(await loadEnv(argv), argv)
394+
return setOperator(await loadEnv(argv), argv)
368395
},
369396
})
370397
},

contracts/staking/Staking.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
493493
* @param _allowed Whether authorized or not
494494
*/
495495
function setOperator(address _operator, bool _allowed) external override {
496+
require(_operator != msg.sender, "operator != sender");
496497
operatorAuth[msg.sender][_operator] = _allowed;
497498
emit SetOperator(msg.sender, _operator, _allowed);
498499
}

0 commit comments

Comments
 (0)