Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify approve and approvehotfix to support multisigs #7671

Merged
merged 4 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 38 additions & 14 deletions packages/cli/src/commands/governance/approve.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,87 @@
import { CeloTransactionObject } from '@celo/connect'
import { flags } from '@oclif/command'
import { toBuffer } from 'ethereumjs-util'
import { BaseCommand } from '../../base'
import { newCheckBuilder } from '../../utils/checks'
import { displaySendTx } from '../../utils/cli'
import { Flags } from '../../utils/command'

export default class Approve extends BaseCommand {
static description = 'Approve a dequeued governance proposal'
static description = 'Approve a dequeued governance proposal (or hotfix)'

static aliases = ['governance:approve', 'governance:approvehotfix']

// Only authorized approvers need to know about this command.
static hidden = true

static flags = {
...BaseCommand.flags,
proposalID: flags.string({ required: true, description: 'UUID of proposal to approve' }),
proposalID: flags.string({
description: 'UUID of proposal to approve',
exclusive: ['hotfix'],
}),
from: Flags.address({ required: true, description: "Approver's address" }),
useMultiSig: flags.boolean({
default: true,
description: 'True means the request will be sent through multisig.',
}),
hotfix: flags.string({
exclusive: ['proposalID'],
description: 'Hash of hotfix proposal',
}),
}

static examples = [
'approve --proposalID 99 --from 0x5409ed021d9299bf6814279a6a1411a7e866a631',
'approve --proposalID 99 --from 0x5409ed021d9299bf6814279a6a1411a7e866a631 --useMultiSig',
'approve --hotfix 0xfcfc98ec3db7c56f0866a7149e811bf7f9e30c9d40008b0def497fcc6fe90649 --from 0xCc50EaC48bA71343dC76852FAE1892c6Bd2971DA --useMultiSig',
]

async run() {
const res = this.parse(Approve)
const account = res.flags.from
const useMultiSig = res.flags.useMultiSig
const id = res.flags.proposalID
const hotfix = res.flags.hotfix
this.kit.defaultAccount = account
const governance = await this.kit.contracts.getGovernance()
const governanceApproverMultiSig = useMultiSig
? await governance.getApproverMultisig()
: undefined
const approver = useMultiSig ? governanceApproverMultiSig!.address : account

// in case target is queued
if (await governance.isQueued(id)) {
await governance.dequeueProposalsIfReady().sendAndWaitForReceipt()
}

await newCheckBuilder(this)
const checkBuilder = newCheckBuilder(this)
.isApprover(approver)
.addConditionalCheck(`${account} is multisig signatory`, useMultiSig, () =>
governanceApproverMultiSig!.isowner(account)
)
.proposalExists(id)
.addCheck(`${id} not already approved`, async () => !(await governance.isApproved(id)))
.proposalInStage(id, 'Approval')
.runChecks()

const governanceTx = await governance.approve(id)
let governanceTx: CeloTransactionObject<any>
let logEvent: string
if (id) {
checkBuilder
.proposalExists(id)
.proposalInStage(id, 'Approval')
.addCheck(`${id} not already approved`, async () => !(await governance.isApproved(id)))
governanceTx = await governance.approve(id)
logEvent = 'ProposalApproved'
} else if (hotfix) {
const hotfixBuf = toBuffer(hotfix) as Buffer
checkBuilder.hotfixNotExecuted(hotfixBuf).hotfixNotApproved(hotfixBuf)
governanceTx = governance.approveHotfix(hotfixBuf)
logEvent = 'HotfixApproved'
} else {
throw new Error('Proposal ID or hotfix must be provided')
}

await checkBuilder.runChecks()

const tx = useMultiSig
? await governanceApproverMultiSig!.submitOrConfirmTransaction(
governance.address,
governanceTx.txo
)
: governanceTx
await displaySendTx<string | void | boolean>('approveTx', tx, {}, 'ProposalApproved')
await displaySendTx<string | void | boolean>('approveTx', tx, {}, logEvent)
}
}
35 changes: 0 additions & 35 deletions packages/cli/src/commands/governance/approvehotfix.ts

This file was deleted.

6 changes: 6 additions & 0 deletions packages/cli/src/utils/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ class CheckBuilder {
this.withGovernance(async (governance) => !(await governance.getHotfixRecord(hash)).executed)
)

hotfixNotApproved = (hash: Buffer) =>
this.addCheck(
`Hotfix 0x${hash.toString('hex')} is not already approved`,
this.withGovernance(async (governance) => !(await governance.getHotfixRecord(hash)).approved)
)

canSign = (account: Address) =>
this.addCheck('Account can sign', async () => {
try {
Expand Down