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

refactor: signalling proposal subgraph change #503

Merged
merged 13 commits into from
Nov 23, 2023
10 changes: 9 additions & 1 deletion packages/subgraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UPCOMING]

### Added

- Added `isSignaling` attribute to `TokenVotingProposal`, `AddresslistVotingProposal`, and `MultisigProposal` that is set to true for proposals having an empty action array.

### Changed

- Renamed `potentiallyExecutable` attribute to `approvalReached` and stopped setting it to `true` during multisig proposal creation if `minApprovals = 1` when zero approvals were given yet.

## 1.3.1

### Added
Expand Down Expand Up @@ -82,7 +90,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changed `IPluginInstallation` to `IPlugin`.
- Changed `release: Int!` to `release: PluginRelease!` in `PluginVersion`
- Changed `versions` to `releases` in `PluginRepo`.
- Changes `Permission` entity to be muteable.
- Changes `Permission` entity to be mutable.

### Removed

Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aragon/osx-subgraph",
"version": "1.3.1",
"version": "1.4.0",
"description": "The Aragon OSx Subgraph",
"homepage": "https://github.com/aragon/osx",
"license": "AGPL-3.0-or-later",
Expand Down
9 changes: 6 additions & 3 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ type TokenVotingProposal implements IProposal @entity {
startDate: BigInt!
endDate: BigInt!
creationBlockNumber: BigInt!
potentiallyExecutable: Boolean!
approvalReached: Boolean!
isSignaling: Boolean!
earlyExecutable: Boolean
executionDate: BigInt
executionBlockNumber: BigInt
Expand Down Expand Up @@ -536,7 +537,8 @@ type AddresslistVotingProposal implements IProposal @entity {
startDate: BigInt!
endDate: BigInt!
creationBlockNumber: BigInt!
potentiallyExecutable: Boolean!
approvalReached: Boolean!
isSignaling: Boolean!
earlyExecutable: Boolean
executionDate: BigInt
executionBlockNumber: BigInt
Expand Down Expand Up @@ -640,7 +642,8 @@ type MultisigProposal implements IProposal @entity {
snapshotBlock: BigInt!
minApprovals: Int!
approvals: Int
potentiallyExecutable: Boolean!
approvalReached: Boolean!
isSignaling: Boolean!
executed: Boolean!
executionDate: BigInt
executionBlockNumber: BigInt
Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/scripts/deploy-subgraph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ else
graph deploy $FULLNAME \
--version-label $SUBGRAPH_VERSION \
--ipfs https://ipfs.satsuma.xyz \
--node https://app.satsuma.xyz/api/subgraphs/deploy \
--node https://subgraphs.alchemy.com/api/subgraphs/deploy \
--deploy-key $GRAPH_KEY > deploy-output.txt

SUBGRAPH_ID=$(grep "Build completed:" deploy-output.txt | grep -oE "Qm[a-zA-Z0-9]{44}")
Expand Down
18 changes: 9 additions & 9 deletions packages/subgraph/src/packages/addresslist/addresslist-voting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import {
Action,
AddresslistVotingPlugin,
AddresslistVotingProposal,
AddresslistVotingVoter,
AddresslistVotingVote,
AddresslistVotingVoter,
} from '../../../generated/schema';
import {
VoteCast,
AddresslistVoting,
MembersAdded,
MembersRemoved,
ProposalCreated,
ProposalExecuted,
VoteCast,
VotingSettingsUpdated,
MembersAdded,
MembersRemoved,
AddresslistVoting,
} from '../../../generated/templates/AddresslistVoting/AddresslistVoting';
import {RATIO_BASE, VOTER_OPTIONS, VOTING_MODES} from '../../utils/constants';
import {getProposalId} from '../../utils/proposals';
Expand Down Expand Up @@ -44,7 +44,7 @@ export function _handleProposalCreated(
proposalEntity.createdAt = event.block.timestamp;
proposalEntity.creationBlockNumber = event.block.number;
proposalEntity.allowFailureMap = event.params.allowFailureMap;
proposalEntity.potentiallyExecutable = false;
proposalEntity.approvalReached = false;

let contract = AddresslistVoting.bind(pluginAddress);
let proposal = contract.try_getProposal(pluginProposalId);
Expand Down Expand Up @@ -88,7 +88,7 @@ export function _handleProposalCreated(
actionEntity.proposal = proposalId;
actionEntity.save();
}

proposalEntity.isSignaling = actions.length == 0;
// totalVotingPower
proposalEntity.totalVotingPower = contract.try_totalVotingPower(
parameters.snapshotBlock
Expand Down Expand Up @@ -185,7 +185,7 @@ export function handleVoteCast(event: VoteCast): void {
let minParticipationReached = castedVotingPower.ge(minVotingPower);

// Used when proposal has ended.
proposalEntity.potentiallyExecutable =
proposalEntity.approvalReached =
supportThresholdReached && minParticipationReached;

// Used when proposal has not ended.
Expand All @@ -206,7 +206,7 @@ export function handleProposalExecuted(event: ProposalExecuted): void {
let proposalEntity = AddresslistVotingProposal.load(proposalId);
if (proposalEntity) {
proposalEntity.executed = true;
proposalEntity.potentiallyExecutable = false;
proposalEntity.approvalReached = true;
proposalEntity.executionDate = event.block.timestamp;
proposalEntity.executionBlockNumber = event.block.number;
proposalEntity.executionTxHash = event.transaction.hash;
Expand Down
27 changes: 11 additions & 16 deletions packages/subgraph/src/packages/multisig/multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,20 @@ export function _handleProposalCreated(
proposalEntity.allowFailureMap = event.params.allowFailureMap;

let contract = Multisig.bind(event.address);
let vote = contract.try_getProposal(pluginProposalId);
let proposal = contract.try_getProposal(pluginProposalId);

if (!vote.reverted) {
proposalEntity.executed = vote.value.value0;
proposalEntity.approvals = vote.value.value1;
if (!proposal.reverted) {
proposalEntity.executed = proposal.value.value0;
proposalEntity.approvals = proposal.value.value1;

// ProposalParameters
let parameters = vote.value.value2;
let parameters = proposal.value.value2;
proposalEntity.minApprovals = parameters.minApprovals;
proposalEntity.snapshotBlock = parameters.snapshotBlock;

// if minApproval is 1, the proposal is always executable
if (parameters.minApprovals == 1) {
proposalEntity.potentiallyExecutable = true;
} else {
proposalEntity.potentiallyExecutable = false;
}
proposalEntity.approvalReached = false;

// Actions
let actions = vote.value.value3;
let actions = proposal.value.value3;
for (let index = 0; index < actions.length; index++) {
const action = actions[index];

Expand All @@ -81,6 +75,7 @@ export function _handleProposalCreated(
actionEntity.proposal = proposalId;
actionEntity.save();
}
proposalEntity.isSignaling = actions.length == 0;
}

proposalEntity.save();
Expand Down Expand Up @@ -129,9 +124,9 @@ export function handleApproved(event: Approved): void {

if (
approvals >= minApprovalsStruct.minApprovals &&
!proposalEntity.potentiallyExecutable
!proposalEntity.approvalReached
) {
proposalEntity.potentiallyExecutable = true;
proposalEntity.approvalReached = true;
}

proposalEntity.save();
Expand All @@ -145,7 +140,7 @@ export function handleProposalExecuted(event: ProposalExecuted): void {

let proposalEntity = MultisigProposal.load(proposalId);
if (proposalEntity) {
proposalEntity.potentiallyExecutable = false;
proposalEntity.approvalReached = false;
proposalEntity.executed = true;
proposalEntity.executionDate = event.block.timestamp;
proposalEntity.executionBlockNumber = event.block.number;
Expand Down
7 changes: 4 additions & 3 deletions packages/subgraph/src/packages/token/token-voting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function _handleProposalCreated(
proposalEntity.createdAt = event.block.timestamp;
proposalEntity.creationBlockNumber = event.block.number;
proposalEntity.allowFailureMap = event.params.allowFailureMap;
proposalEntity.potentiallyExecutable = false;
proposalEntity.approvalReached = false;

let contract = TokenVoting.bind(event.address);
let proposal = contract.try_getProposal(pluginProposalId);
Expand Down Expand Up @@ -89,6 +89,7 @@ export function _handleProposalCreated(
actionEntity.proposal = proposalId;
actionEntity.save();
}
proposalEntity.isSignaling = actions.length == 0;

// totalVotingPower
proposalEntity.totalVotingPower = contract.try_totalVotingPower(
Expand Down Expand Up @@ -198,7 +199,7 @@ export function handleVoteCast(event: VoteCast): void {
let minParticipationReached = castedVotingPower.ge(minVotingPower);

// Used when proposal has ended.
proposalEntity.potentiallyExecutable =
proposalEntity.approvalReached =
supportThresholdReached && minParticipationReached;

// Used when proposal has not ended.
Expand All @@ -219,7 +220,7 @@ export function handleProposalExecuted(event: ProposalExecuted): void {
let proposalEntity = TokenVotingProposal.load(proposalId);
if (proposalEntity) {
proposalEntity.executed = true;
proposalEntity.potentiallyExecutable = false;
proposalEntity.approvalReached = false;
proposalEntity.executionDate = event.block.timestamp;
proposalEntity.executionBlockNumber = event.block.number;
proposalEntity.executionTxHash = event.transaction.hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ test('Run AddresslistVoting (handleVoteCast) mappings with mock event', () => {

// check proposal
assert.fieldEquals('AddresslistVotingProposal', proposal.id, 'yes', '1');
// Check potentiallyExecutable
// Check approvalReached
// abstain: 0, yes: 1, no: 0
// support : 100%
// worstCaseSupport : 33%
// participation : 33%
assert.fieldEquals(
'AddresslistVotingProposal',
proposal.id,
'potentiallyExecutable',
'approvalReached',
'false'
);
// check vote count
Expand Down Expand Up @@ -389,15 +389,15 @@ test('Run AddresslistVoting (handleVoteCast) mappings with mock event', () => {

handleVoteCast(event3);

// Check potentiallyExecutable
// Check approvalReached
// abstain: 0, yes: 2, no: 0
// support : 100%
// worstCaseSupport : 67%
// participation : 67%
assert.fieldEquals(
'AddresslistVotingProposal',
proposal.id,
'potentiallyExecutable',
'approvalReached',
'true'
);

Expand Down
3 changes: 2 additions & 1 deletion packages/subgraph/tests/addresslist-voting/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,14 @@ export function createAddresslistVotingProposalEntityState(
addresslistProposal.startDate = BigInt.fromString(startDate);
addresslistProposal.endDate = BigInt.fromString(endDate);
addresslistProposal.snapshotBlock = BigInt.fromString(snapshotBlock);
addresslistProposal.isSignaling = false;

addresslistProposal.totalVotingPower = BigInt.fromString(totalVotingPower);
addresslistProposal.allowFailureMap = BigInt.fromString(allowFailureMap);

addresslistProposal.createdAt = BigInt.fromString(createdAt);
addresslistProposal.creationBlockNumber = creationBlockNumber;
addresslistProposal.potentiallyExecutable = executable;
addresslistProposal.approvalReached = executable;
addresslistProposal.earlyExecutable = earlyExecutable;

addresslistProposal.save();
Expand Down
3 changes: 2 additions & 1 deletion packages/subgraph/tests/helpers/method-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ class TokenVotingProposalMethods extends TokenVotingProposal {
this.allowFailureMap = BigInt.fromString(ALLOW_FAILURE_MAP);
this.createdAt = BigInt.fromString(CREATED_AT);
this.creationBlockNumber = BigInt.fromString(ZERO);
this.potentiallyExecutable = false;
this.approvalReached = false;
this.isSignaling = false;

return this;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/subgraph/tests/multisig/multisig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ test('Run Multisig (handleApproved) mappings with mock event', () => {
assert.fieldEquals(
'MultisigProposal',
proposal.id,
'potentiallyExecutable',
'approvalReached',
'false'
);

Expand Down Expand Up @@ -254,7 +254,7 @@ test('Run Multisig (handleApproved) mappings with mock event', () => {
assert.fieldEquals(
'MultisigProposal',
proposal.id,
'potentiallyExecutable',
'approvalReached',
'true'
);

Expand Down
3 changes: 2 additions & 1 deletion packages/subgraph/tests/multisig/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ export function createMultisigProposalEntityState(
multisigProposal.creator = Address.fromString(creator);
multisigProposal.startDate = BigInt.fromString(startDate);
multisigProposal.endDate = BigInt.fromString(endDate);
multisigProposal.potentiallyExecutable = executable;
multisigProposal.approvalReached = executable;
multisigProposal.isSignaling = false;
multisigProposal.executed = executed;
multisigProposal.snapshotBlock = BigInt.fromString(snapshotBlock);
multisigProposal.minApprovals = BigInt.fromString(minApprovals).toI32();
Expand Down
6 changes: 3 additions & 3 deletions packages/subgraph/tests/token/token-voting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test('Run TokenVoting (handleVoteCast) mappings with mock event', () => {
// check proposal entity
proposal.assertEntity();

// // create calls
// create calls
proposal.yes = bigInt.fromString(ONE);
proposal.mockCall_getProposal(actions);
proposal.mockCall_totalVotingPower();
Expand Down Expand Up @@ -102,7 +102,7 @@ test('Run TokenVoting (handleVoteCast) mappings with mock event', () => {
// check proposal
// expected changes to the proposal entity
proposal.castedVotingPower = BigInt.fromString(ONE);
proposal.potentiallyExecutable = false;
proposal.approvalReached = false;
// assert proposal entity
proposal.assertEntity();

Expand Down Expand Up @@ -146,7 +146,7 @@ test('Run TokenVoting (handleVoteCast) mappings with mock event', () => {
handleVoteCast(event3);

// expected changes to the proposal entity
proposal.potentiallyExecutable = true;
proposal.approvalReached = true;
proposal.castedVotingPower = BigInt.fromString(TWO);

proposal.assertEntity();
Expand Down
3 changes: 2 additions & 1 deletion packages/subgraph/tests/token/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,13 @@ export function createTokenVotingProposalEntityState(
tokenVotingProposal.startDate = BigInt.fromString(startDate);
tokenVotingProposal.endDate = BigInt.fromString(endDate);
tokenVotingProposal.snapshotBlock = BigInt.fromString(snapshotBlock);
tokenVotingProposal.isSignaling = false;

tokenVotingProposal.totalVotingPower = BigInt.fromString(totalVotingPower);
tokenVotingProposal.allowFailureMap = BigInt.fromString(allowFailureMap);
tokenVotingProposal.createdAt = BigInt.fromString(createdAt);
tokenVotingProposal.creationBlockNumber = creationBlockNumber;
tokenVotingProposal.potentiallyExecutable = executable;
tokenVotingProposal.approvalReached = executable;
tokenVotingProposal.earlyExecutable = earlyExecutable;

tokenVotingProposal.save();
Expand Down
Loading