From 50f44c8e45c0e0b5950a4e40e0135a992c460744 Mon Sep 17 00:00:00 2001 From: Tim Moreton Date: Tue, 13 Feb 2024 15:01:37 -0800 Subject: [PATCH 1/3] Activate from any account --- .../cli/src/commands/election/activate.ts | 25 +++++++++++++------ .../sdk/contractkit/src/wrappers/Election.ts | 11 ++++++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/commands/election/activate.ts b/packages/cli/src/commands/election/activate.ts index 8d28882f4..2d4d42304 100644 --- a/packages/cli/src/commands/election/activate.ts +++ b/packages/cli/src/commands/election/activate.ts @@ -12,34 +12,45 @@ export default class ElectionVote extends BaseCommand { static flags = { ...BaseCommand.flags, - from: CustomFlags.address({ required: true, description: "Voter's address" }), + from: CustomFlags.address({ + required: true, + description: "Address sending transaction (and voter's address if --for not specified)", + }), + for: CustomFlags.address({ + required: false, + description: 'Optional: use this to activate votes for another address', + }), wait: Flags.boolean({ description: 'Wait until all pending votes can be activated' }), } static examples = [ 'activate --from 0x4443d0349e8b3075cba511a0a87796597602a0f1', + 'activate --from 0x4443d0349e8b3075cba511a0a87796597602a0f1 --for 0x5409ed021d9299bf6814279a6a1411a7e866a631', 'activate --from 0x4443d0349e8b3075cba511a0a87796597602a0f1 --wait', ] + async run() { const kit = await this.getKit() const res = await this.parse(ElectionVote) - await newCheckBuilder(this, res.flags.from).isSignerOrAccount().runChecks() + const forAccount = res.flags.for ?? res.flags.from + await newCheckBuilder(this, forAccount).isSignerOrAccount().runChecks() - const election = await kit.contracts.getElection() const accounts = await kit.contracts.getAccounts() - const account = await accounts.voteSignerToAccount(res.flags.from) - const hasPendingVotes = await election.hasPendingVotes(account) + const signerAccount = await accounts.voteSignerToAccount(forAccount) + + const election = await kit.contracts.getElection() + const hasPendingVotes = await election.hasPendingVotes(signerAccount) if (hasPendingVotes) { if (res.flags.wait) { // Spin until pending votes become activatable. ux.action.start(`Waiting until pending votes can be activated`) - while (!(await election.hasActivatablePendingVotes(account))) { + while (!(await election.hasActivatablePendingVotes(signerAccount))) { await sleep(1000) } ux.action.stop() } - const txos = await election.activate(account) + const txos = await election.activate(signerAccount, res.flags.for != null) for (const txo of txos) { await displaySendTx('activate', txo, { from: res.flags.from }) } diff --git a/packages/sdk/contractkit/src/wrappers/Election.ts b/packages/sdk/contractkit/src/wrappers/Election.ts index ac4a3bc9d..cc7fe2a91 100644 --- a/packages/sdk/contractkit/src/wrappers/Election.ts +++ b/packages/sdk/contractkit/src/wrappers/Election.ts @@ -325,17 +325,24 @@ export class ElectionWrapper extends BaseWrapperForGoverning { private _activate = proxySend(this.connection, this.contract.methods.activate) + private _activateForAccount = proxySend(this.connection, this.contract.methods.activateForAccount) + /** * Activates any activatable pending votes. * @param account The account with pending votes to activate. */ - async activate(account: Address): Promise[]> { + async activate( + account: Address, + onBehalfOfAccount?: boolean + ): Promise>> { const groups = await this.contract.methods.getGroupsVotedForByAccount(account).call() const isActivatable = await Promise.all( groups.map((g) => this.contract.methods.hasActivatablePendingVotes(account, g).call()) ) const groupsActivatable = groups.filter((_, i) => isActivatable[i]) - return groupsActivatable.map((g) => this._activate(g)) + return groupsActivatable.map((g) => + onBehalfOfAccount ? this._activateForAccount(g, account) : this._activate(g) + ) } async revokePending( From 17c2161308087171bd8d6cd302ce10b494d964f6 Mon Sep 17 00:00:00 2001 From: Tim Moreton Date: Tue, 13 Feb 2024 15:02:14 -0800 Subject: [PATCH 2/3] Update CLI docs --- .../wrappers_Election.ElectionWrapper.md | 25 ++++++++++--------- .../contractkit/modules/wrappers_Election.md | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/docs/sdk/docs/contractkit/classes/wrappers_Election.ElectionWrapper.md b/packages/docs/sdk/docs/contractkit/classes/wrappers_Election.ElectionWrapper.md index 583dbfbc8..901f696fd 100644 --- a/packages/docs/sdk/docs/contractkit/classes/wrappers_Election.ElectionWrapper.md +++ b/packages/docs/sdk/docs/contractkit/classes/wrappers_Election.ElectionWrapper.md @@ -494,7 +494,7 @@ BaseWrapperForGoverning.address ### activate -▸ **activate**(`account`): `Promise`\<`CeloTransactionObject`\<`boolean`\>[]\> +▸ **activate**(`account`, `onBehalfOfAccount?`): `Promise`\<`CeloTransactionObject`\<`boolean`\>[]\> Activates any activatable pending votes. @@ -503,6 +503,7 @@ Activates any activatable pending votes. | Name | Type | Description | | :------ | :------ | :------ | | `account` | `string` | The account with pending votes to activate. | +| `onBehalfOfAccount?` | `boolean` | - | #### Returns @@ -510,7 +511,7 @@ Activates any activatable pending votes. #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:332](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L332) +[packages/sdk/contractkit/src/wrappers/Election.ts:334](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L334) ___ @@ -578,7 +579,7 @@ ___ #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:444](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L444) +[packages/sdk/contractkit/src/wrappers/Election.ts:451](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L451) ___ @@ -641,7 +642,7 @@ Retrieves the set of validatorsparticipating in BFT at epochNumber. #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:473](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L473) +[packages/sdk/contractkit/src/wrappers/Election.ts:480](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L480) ___ @@ -657,7 +658,7 @@ Returns the current eligible validator groups and their total votes. #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:429](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L429) +[packages/sdk/contractkit/src/wrappers/Election.ts:436](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L436) ___ @@ -680,7 +681,7 @@ Retrieves GroupVoterRewards at epochNumber. #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:485](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L485) +[packages/sdk/contractkit/src/wrappers/Election.ts:492](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L492) ___ @@ -838,7 +839,7 @@ Retrieves VoterRewards for address at epochNumber. #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:519](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L519) +[packages/sdk/contractkit/src/wrappers/Election.ts:526](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L526) ___ @@ -861,7 +862,7 @@ Retrieves a voter's share of active votes. #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:553](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L553) +[packages/sdk/contractkit/src/wrappers/Election.ts:560](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L560) ___ @@ -949,7 +950,7 @@ ___ #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:390](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L390) +[packages/sdk/contractkit/src/wrappers/Election.ts:397](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L397) ___ @@ -979,7 +980,7 @@ Must pass both `lesserAfterVote` and `greaterAfterVote` or neither. #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:365](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L365) +[packages/sdk/contractkit/src/wrappers/Election.ts:372](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L372) ___ @@ -1001,7 +1002,7 @@ ___ #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:341](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L341) +[packages/sdk/contractkit/src/wrappers/Election.ts:348](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L348) ___ @@ -1042,4 +1043,4 @@ Increments the number of total and pending votes for `group`. #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:417](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L417) +[packages/sdk/contractkit/src/wrappers/Election.ts:424](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L424) diff --git a/packages/docs/sdk/docs/contractkit/modules/wrappers_Election.md b/packages/docs/sdk/docs/contractkit/modules/wrappers_Election.md index 136110ed7..184fbd3f6 100644 --- a/packages/docs/sdk/docs/contractkit/modules/wrappers_Election.md +++ b/packages/docs/sdk/docs/contractkit/modules/wrappers_Election.md @@ -30,4 +30,4 @@ #### Defined in -[packages/sdk/contractkit/src/wrappers/Election.ts:569](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L569) +[packages/sdk/contractkit/src/wrappers/Election.ts:576](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/Election.ts#L576) From 41cccbb4b85fb3408d69eef0f8217ecff3f58c0d Mon Sep 17 00:00:00 2001 From: Tim Moreton Date: Tue, 13 Feb 2024 15:05:20 -0800 Subject: [PATCH 3/3] Add changeset --- .changeset/happy-rice-camp.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/happy-rice-camp.md diff --git a/.changeset/happy-rice-camp.md b/.changeset/happy-rice-camp.md new file mode 100644 index 000000000..e0380a9b3 --- /dev/null +++ b/.changeset/happy-rice-camp.md @@ -0,0 +1,6 @@ +--- +'@celo/contractkit': minor +'@celo/celocli': minor +--- + +Activate votes from any account, new optional parameter to specify for account in ElectionWrapper:activate