Skip to content

Commit

Permalink
refactor: renamed entity
Browse files Browse the repository at this point in the history
  • Loading branch information
heueristik committed Nov 15, 2023
1 parent c2be413 commit 4f55e7d
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 32 deletions.
6 changes: 5 additions & 1 deletion packages/subgraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UPCOMING]

### 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 +86,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
6 changes: 3 additions & 3 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ type TokenVotingProposal implements IProposal @entity {
startDate: BigInt!
endDate: BigInt!
creationBlockNumber: BigInt!
potentiallyExecutable: Boolean!
approvalReached: Boolean!
earlyExecutable: Boolean
executionDate: BigInt
executionBlockNumber: BigInt
Expand Down Expand Up @@ -536,7 +536,7 @@ type AddresslistVotingProposal implements IProposal @entity {
startDate: BigInt!
endDate: BigInt!
creationBlockNumber: BigInt!
potentiallyExecutable: Boolean!
approvalReached: Boolean!
earlyExecutable: Boolean
executionDate: BigInt
executionBlockNumber: BigInt
Expand Down Expand Up @@ -640,7 +640,7 @@ type MultisigProposal implements IProposal @entity {
snapshotBlock: BigInt!
minApprovals: Int!
approvals: Int
potentiallyExecutable: Boolean!
approvalReached: Boolean!
executed: Boolean!
executionDate: BigInt
executionBlockNumber: BigInt
Expand Down
Original file line number Diff line number Diff line change
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 @@ -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
14 changes: 4 additions & 10 deletions packages/subgraph/src/packages/multisig/multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ export function _handleProposalCreated(
let parameters = vote.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;
Expand Down Expand Up @@ -129,9 +123,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 +139,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
6 changes: 3 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 @@ -198,7 +198,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 +219,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
2 changes: 1 addition & 1 deletion packages/subgraph/tests/addresslist-voting/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export function createAddresslistVotingProposalEntityState(

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

addresslistProposal.save();
Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/tests/helpers/method-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ 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;

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
2 changes: 1 addition & 1 deletion packages/subgraph/tests/multisig/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ 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.executed = executed;
multisigProposal.snapshotBlock = BigInt.fromString(snapshotBlock);
multisigProposal.minApprovals = BigInt.fromString(minApprovals).toI32();
Expand Down
4 changes: 2 additions & 2 deletions packages/subgraph/tests/token/token-voting.test.ts
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion packages/subgraph/tests/token/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export function createTokenVotingProposalEntityState(
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

0 comments on commit 4f55e7d

Please sign in to comment.