Skip to content

Commit

Permalink
add support for signaling
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarinas committed Nov 17, 2023
1 parent 2faccb3 commit 89f4dbb
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 56 deletions.
7 changes: 7 additions & 0 deletions modules/client-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ TEMPLATE:

## [UPCOMING]

### Changed

- Updated subgraph version to 1.3.2


## [1.11.0]

### Added

- Added `actions` to `SubgraphListItem` type
Expand Down
2 changes: 1 addition & 1 deletion modules/client-common/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aragon/sdk-client-common",
"author": "Aragon Association",
"version": "1.11.0",
"version": "1.12.0",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client-common.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion modules/client-common/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const UNAVAILABLE_PROPOSAL_METADATA: ProposalMetadata = {
const getGraphqlNode = (network: SupportedNetwork): string => {
return `https://subgraph.satsuma-prod.com/qHR2wGfc5RLi6/aragon/osx-${
SupportedNetworksToGraphqlNetworks[network]
}/version/v1.3.1/api`;
}/version/v1.3.2/api`;
};

export const GRAPHQL_NODES: { [K in SupportedNetwork]: { url: string }[] } = {
Expand Down
5 changes: 5 additions & 0 deletions modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ TEMPLATE:
-->

## [UPCOMING]
### Fixed

- Compute of proposal status bu adding the `isSignaling`field


## [1.19.0]
### Added

- `isMember` function to `TokenVotingClient`
Expand Down
4 changes: 2 additions & 2 deletions modules/client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aragon/sdk-client",
"author": "Aragon Association",
"version": "1.19.0",
"version": "1.19.1",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client.esm.js",
Expand Down Expand Up @@ -62,7 +62,7 @@
},
"dependencies": {
"@aragon/osx-ethers": "1.3.0-rc0.4",
"@aragon/sdk-client-common": "^1.11.0",
"@aragon/sdk-client-common": "^1.12.0",
"@aragon/sdk-ipfs": "^1.1.0",
"@ethersproject/abstract-signer": "^5.5.0",
"@ethersproject/bignumber": "^5.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ query AddresslistVotingProposal($proposalId: ID!) {
endDate
executed
earlyExecutable
potentiallyExecutable
approvalReached
isSignaling
executionTxHash
voters{
voter{
Expand Down Expand Up @@ -64,7 +65,8 @@ query AddresslistVotingProposals($where: AddresslistVotingProposal_filter!, $lim
endDate
executed
earlyExecutable
potentiallyExecutable
approvalReached
isSignaling
voters{
voter{
address
Expand Down
38 changes: 33 additions & 5 deletions modules/client/src/addresslistVoting/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,41 @@ export function computeProposalStatus(
parseInt(proposal.startDate) * 1000,
);
const endDate = new Date(parseInt(proposal.endDate) * 1000);
// The proposal is executed so the status becomes EXECUTED
// independently of the other conditions
if (proposal.executed) {
return ProposalStatus.EXECUTED;
}
// The proposal is not executed and the start date is in the future
// so the status becomes PENDING
if (startDate >= now) {
return ProposalStatus.PENDING;
}
if (proposal.approvalReached || proposal.earlyExecutable) {
return ProposalStatus.SUCCEEDED;
// The proposal is not executed and the start date is in the past
// So we must check if the proposal reached the approval threshold
// If it reached the approval threshold and it's a signaling proposal
// the status becomes SUCCEEDED
// If it reached the approval threshold and it's not a signaling proposal
// the status becomes SUCCEEDED if the end date is in the past or if the
// proposal is early executable
if (proposal.approvalReached) {
if(proposal.isSignaling) {
return ProposalStatus.SUCCEEDED;
} else {
if (now >= endDate || proposal.earlyExecutable) {
return ProposalStatus.SUCCEEDED;
}
}
}
if (endDate >= now) {
// The proposal is not executed and the start date is in the past
// and the approval threshold is not reached
// If the end date is in the future this means that you can still vote
// so the status becomes ACTIVE
if (now < endDate) {
return ProposalStatus.ACTIVE;
}
return ProposalStatus.DEFEATED;
// If none of the other conditions are met the status becomes DEFEATED
return ProposalStatus.DEFEATED
}

export function computeProposalStatusFilter(status: ProposalStatus) {
Expand All @@ -195,7 +217,13 @@ export function computeProposalStatusFilter(status: ProposalStatus) {
where = { executed: true };
break;
case ProposalStatus.SUCCEEDED:
where = { potentiallyExecutable: true, endDate_lt: now };
where = {
or: [
{ approvalReached: true, endDate_lt: now, isSignaling: false },
{ approvalReached: true, earlyExecutable: true, isSignaling: false },
{ approvalReached: true, isSignaling: true },
],
};
break;
case ProposalStatus.DEFEATED:
where = {
Expand Down
3 changes: 2 additions & 1 deletion modules/client/src/client-common/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export type SubgraphProposalBase = {
startDate: string;
endDate: string;
executed: boolean;
potentiallyExecutable: boolean;
approvalReached: boolean;
isSignaling: boolean;
actions: SubgraphAction[]
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ query MultisigProposal($proposalId: ID!) {
minApprovals
executionTxHash
executed
potentiallyExecutable
approvalReached
isSignaling
approvers{
id
}
Expand All @@ -45,7 +46,8 @@ query MultisigProposals($where: MultisigProposal_filter!, $limit:Int!, $skip: In
creator
metadata
executed
potentiallyExecutable
approvalReached
isSignaling
approvals
startDate
endDate
Expand Down
2 changes: 1 addition & 1 deletion modules/client/src/multisig/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SubgraphProposalBase } from "../../client-common";
export type SubgraphMultisigProposalBase = SubgraphProposalBase & {
plugin: SubgraphMultisigVotingSettings;
minApprovals: number;
potentiallyExecutable: boolean;
approvalReached: boolean;
approvers: { id: string }[];
// TODO change on subgraph fix
// approvers: SubgraphMultisigApproversListItem[];
Expand Down
38 changes: 26 additions & 12 deletions modules/client/src/multisig/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,38 @@ export function computeProposalStatus(
parseInt(proposal.startDate) * 1000,
);
const endDate = new Date(parseInt(proposal.endDate) * 1000);
// The proposal is executed so the status becomes EXECUTED
// independently of the other conditions
if (proposal.executed) {
return ProposalStatus.EXECUTED;
}
if (now < startDate) {
// The proposal is not executed and the start date is in the future
// so the status becomes PENDING
if (startDate >= now) {
return ProposalStatus.PENDING;
}
// The proposal is not executed and the start date is in the past
// So we must check if the proposal reached the approval threshold
// If it reached the approval threshold and it's a signaling proposal
// the status becomes SUCCEEDED
// If it reached the approval threshold and it's not a signaling proposal
// the status becomes SUCCEEDED if if it hasn't reached the end date
if (proposal.approvalReached) {
if(proposal.actions.length === 0){
// Signalling proposals (having an empty actions array) don't need to be executed
// and should remain with `ProposalStatus.SUCCEEDED` after `endDate` has passed
if (proposal.isSignaling) {
return ProposalStatus.SUCCEEDED;
}
if (now <= endDate) {
return ProposalStatus.SUCCEEDED;
} else {

// Conventional proposals become `ProposalStatus.SUCCEEDED` before the `endDate` has passed.
// If they don't get executed afterwards, they will become `ProposalStatus.DEFEATED`
if (now < endDate) {
return ProposalStatus.SUCCEEDED;
}
}
}
// The proposal is not executed and the start date is in the past
// and the approval threshold is not reached
// If the end date is in the future this means that you can still vote
// so the status becomes ACTIVE
if (now < endDate) {
return ProposalStatus.ACTIVE;
}
// If none of the other conditions are met the status becomes DEFEATED
return ProposalStatus.DEFEATED;
}

Expand All @@ -162,7 +171,12 @@ export function computeProposalStatusFilter(status: ProposalStatus) {
where = { executed: true };
break;
case ProposalStatus.SUCCEEDED:
where = { potentiallyExecutable: true, endDate_gte: now }; // TODO rename to
where = {
or: [
{ approvalReached: true, endDate_lt: now, isSignaling: false },
{ approvalReached: true, isSignaling: true },
],
};
break;
case ProposalStatus.DEFEATED:
where = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ query TokenVotingProposal($proposalId: ID!) {
endDate
executed
earlyExecutable
potentiallyExecutable
approvalReached
isSignaling
executionTxHash
voters{
voter{
Expand Down Expand Up @@ -80,7 +81,8 @@ query TokenVotingProposals($where: TokenVotingProposal_filter!, $limit:Int!, $sk
endDate
executed
earlyExecutable
potentiallyExecutable
approvalReached
isSignaling
votingMode
supportThreshold
minVotingPower
Expand Down
38 changes: 33 additions & 5 deletions modules/client/src/tokenVoting/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,41 @@ export function computeProposalStatus(
parseInt(proposal.startDate) * 1000,
);
const endDate = new Date(parseInt(proposal.endDate) * 1000);
// The proposal is executed so the status becomes EXECUTED
// independently of the other conditions
if (proposal.executed) {
return ProposalStatus.EXECUTED;
}
// The proposal is not executed and the start date is in the future
// so the status becomes PENDING
if (startDate >= now) {
return ProposalStatus.PENDING;
}
if (proposal.approvalReached || proposal.earlyExecutable) {
return ProposalStatus.SUCCEEDED;
// The proposal is not executed and the start date is in the past
// So we must check if the proposal reached the approval threshold
// If it reached the approval threshold and it's a signaling proposal
// the status becomes SUCCEEDED
// If it reached the approval threshold and it's not a signaling proposal
// the status becomes SUCCEEDED if the end date is in the past or if the
// proposal is early executable
if (proposal.approvalReached) {
if(proposal.isSignaling) {
return ProposalStatus.SUCCEEDED;
} else {
if (now >= endDate || proposal.earlyExecutable) {
return ProposalStatus.SUCCEEDED;
}
}
}
if (endDate >= now) {
// The proposal is not executed and the start date is in the past
// and the approval threshold is not reached
// If the end date is in the future this means that you can still vote
// so the status becomes ACTIVE
if (now < endDate) {
return ProposalStatus.ACTIVE;
}
return ProposalStatus.DEFEATED;
// If none of the other conditions are met the status becomes DEFEATED
return ProposalStatus.DEFEATED
}

export function computeProposalStatusFilter(status: ProposalStatus) {
Expand All @@ -329,7 +351,13 @@ export function computeProposalStatusFilter(status: ProposalStatus) {
where = { executed: true };
break;
case ProposalStatus.SUCCEEDED:
where = { potentiallyExecutable: true, endDate_lt: now };
where = {
or: [
{ approvalReached: true, endDate_lt: now, isSignaling: false },
{ approvalReached: true, earlyExecutable: true, isSignaling: false },
{ approvalReached: true, isSignaling: true },
],
};
break;
case ProposalStatus.DEFEATED:
where = {
Expand Down
3 changes: 2 additions & 1 deletion modules/client/test/integration/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export const SUBGRAPH_PROPOSAL_BASE: SubgraphProposalBase = {
executed: false,
startDate: Math.round(Date.now() / 1000).toString(),
endDate: Math.round(Date.now() / 1000).toString(),
potentiallyExecutable: false,
approvalReached: false,
isSignaling: false,
metadata: `ipfs://${IPFS_CID}`,
};

Expand Down
14 changes: 7 additions & 7 deletions modules/client/test/unit/addresslistVoting-client/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("addresslistVoting-client utils", () => {
expect(computeProposalStatus({
endDate: endDate.toString(),
startDate: startDate.toString(),
potentiallyExecutable: false,
approvalReached: false,
executed: false,
earlyExecutable: false,
} as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.PENDING);
Expand All @@ -23,7 +23,7 @@ describe("addresslistVoting-client utils", () => {
expect(computeProposalStatus({
endDate: endDate.toString(),
startDate: startDate.toString(),
potentiallyExecutable: false,
approvalReached: false,
executed: true,
earlyExecutable: false,
} as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.EXECUTED);
Expand All @@ -35,19 +35,19 @@ describe("addresslistVoting-client utils", () => {
expect(computeProposalStatus({
endDate: endDate.toString(),
startDate: startDate.toString(),
potentiallyExecutable: false,
approvalReached: false,
executed: false,
earlyExecutable: false,
} as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.ACTIVE);
});
it("should return SUCCEDED if executable = true", () => {
it("should return SUCCEDED if approvalReached = true", () => {
const endDate = Date.now() / 1000;
const startDate = (Date.now() / 1000) - 500;

expect(computeProposalStatus({
endDate: endDate.toString(),
startDate: startDate.toString(),
potentiallyExecutable: true,
approvalReached: true,
executed: false,
earlyExecutable: false,
} as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.SUCCEEDED);
Expand All @@ -59,7 +59,7 @@ describe("addresslistVoting-client utils", () => {
expect(computeProposalStatus({
endDate: endDate.toString(),
startDate: startDate.toString(),
potentiallyExecutable: false,
approvalReached: true,
executed: false,
earlyExecutable: true,
} as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.SUCCEEDED);
Expand All @@ -71,7 +71,7 @@ describe("addresslistVoting-client utils", () => {
expect(computeProposalStatus({
endDate: endDate.toString(),
startDate: startDate.toString(),
potentiallyExecutable: false,
approvalReached: false,
executed: false,
earlyExecutable: false,
} as SubgraphAddresslistVotingProposal)).toBe(ProposalStatus.DEFEATED);
Expand Down
Loading

0 comments on commit 89f4dbb

Please sign in to comment.