Skip to content

Commit

Permalink
Feature: Add actions to proposal queries (#300)
Browse files Browse the repository at this point in the history
* add actions to proposal queries

* update changelog and package.json

* update changelog and package.json
  • Loading branch information
josemarinas authored Nov 6, 2023
1 parent 72938d7 commit 7cd47bd
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 28 deletions.
6 changes: 6 additions & 0 deletions modules/client-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ TEMPLATE:
-->

## [UPCOMING]

### Added

- Added `actions` to `SubgraphListItem` type

## [1.10.0]
### Added

- Add support for arbitrum network
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.10.0",
"version": "1.11.0",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client-common.esm.js",
Expand Down
1 change: 1 addition & 0 deletions modules/client-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export type ProposalListItemBase = {
startDate: Date;
endDate: Date;
status: ProposalStatus;
actions: DaoAction[];
};

export type PrepareUpdateParams = {
Expand Down
3 changes: 3 additions & 0 deletions modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ TEMPLATE:
- `isMember` function to `TokenVotingClient`
- `isMember` function to `AddresslistVotingClient`
- `isMember` function to `Client`
- Add `actions` to `MultisigProposalListItem`
- Add `actions` to `TokenVotingProposalListItem`
- Add `actions` to `AddresslistVotingProposalListItem`

## [1.18.2]
### Fixed
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.18.2",
"version": "1.19.0",
"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.10.0",
"@aragon/sdk-client-common": "^1.11.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 @@ -50,6 +50,11 @@ query AddresslistVotingProposals($where: AddresslistVotingProposal_filter!, $lim
id
subdomain
}
actions {
to
value
data
}
creator
metadata
yes
Expand Down
2 changes: 0 additions & 2 deletions modules/client/src/addresslistVoting/internal/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
ContractVotingSettings,
SubgraphAction,
SubgraphProposalBase,
SubgraphVoterListItemBase,
VotingMode,
Expand All @@ -22,7 +21,6 @@ export type SubgraphAddresslistVotingProposalListItem = SubgraphProposalBase & {

export type SubgraphAddresslistVotingProposal = SubgraphProposalBase & {
createdAt: string;
actions: SubgraphAction[];
supportThreshold: string;
minVotingPower: string;
voters: SubgraphAddresslistVotingVoterListItem[];
Expand Down
9 changes: 9 additions & 0 deletions modules/client/src/addresslistVoting/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ export function toAddresslistVotingProposalListItem(
no: proposal.no ? parseInt(proposal.no) : 0,
abstain: proposal.abstain ? parseInt(proposal.abstain) : 0,
},
actions: proposal.actions.map(
(action: SubgraphAction): DaoAction => {
return {
data: hexToBytes(action.data),
to: action.to,
value: BigInt(action.value),
};
},
),
votes: proposal.voters.map(
(voter: SubgraphAddresslistVotingVoterListItem) => {
return {
Expand Down
1 change: 1 addition & 0 deletions modules/client/src/client-common/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export type SubgraphProposalBase = {
endDate: string;
executed: boolean;
potentiallyExecutable: boolean;
actions: SubgraphAction[]
};

export type ProposalQueryParams = Pagination & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ query MultisigProposals($where: MultisigProposal_filter!, $limit:Int!, $skip: In
approvers {
id
}
actions {
to
value
data
}
minApprovals
plugin{
onlyListed
Expand Down
19 changes: 2 additions & 17 deletions modules/client/src/multisig/internal/types.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
import { SubgraphAction } from "../../client-common";

/* Subgraph types */
type SubgraphProposalBase = {
id: string;
dao: {
id: string;
subdomain: string;
};
creator: string;
metadata: string;
executed: boolean;
createdAt: string;
startDate: string;
endDate: string;
};
import { SubgraphProposalBase } from "../../client-common";

export type SubgraphMultisigProposalBase = SubgraphProposalBase & {
plugin: SubgraphMultisigVotingSettings;
Expand All @@ -27,7 +12,7 @@ export type SubgraphMultisigProposalBase = SubgraphProposalBase & {
export type SubgraphMultisigProposalListItem = SubgraphMultisigProposalBase;

export type SubgraphMultisigProposal = SubgraphMultisigProposalBase & {
actions: SubgraphAction[];
createdAt: string;
executionTxHash: string;
executionDate: string;
executionBlockNumber: string;
Expand Down
9 changes: 9 additions & 0 deletions modules/client/src/multisig/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ export function toMultisigProposalListItem(
approvals: proposal.approvers.map(
(approver) => approver.id.slice(0, 42),
),
actions: proposal.actions.map(
(action: SubgraphAction): DaoAction => {
return {
data: hexToBytes(action.data),
to: action.to,
value: BigInt(action.value),
};
},
),
settings: {
onlyListed: proposal.plugin.onlyListed,
minApprovals: proposal.minApprovals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ query TokenVotingProposals($where: TokenVotingProposal_filter!, $limit:Int!, $sk
supportThreshold
minVotingPower
totalVotingPower
actions {
to
value
data
}
voters{
voter{
address
Expand Down
9 changes: 9 additions & 0 deletions modules/client/src/tokenVoting/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ export function toTokenVotingProposalListItem(
};
},
),
actions: proposal.actions.map(
(action: SubgraphAction): DaoAction => {
return {
data: hexToBytes(action.data),
to: action.to,
value: BigInt(action.value),
};
},
),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
ADDRESS_ONE,
ADDRESS_TWO,
contextParamsLocalChain,
SUBGRAPH_ACTIONS,
SUBGRAPH_PLUGIN_INSTALLATION,
SUBGRAPH_PROPOSAL_BASE,
SUBGRAPH_VOTERS,
Expand Down Expand Up @@ -54,6 +53,7 @@ import {
SubgraphAddresslistVotingProposalListItem,
} from "../../../src/addresslistVoting/internal/types";
import {
bytesToHex,
Context,
getExtendedProposalId,
InvalidAddressOrEnsError,
Expand Down Expand Up @@ -832,7 +832,6 @@ describe("Client Address List", () => {

const subgraphProposal: SubgraphAddresslistVotingProposal = {
createdAt: Math.round(Date.now() / 1000).toString(),
actions: SUBGRAPH_ACTIONS,
supportThreshold: "1000000",
minVotingPower: "20",
voters: SUBGRAPH_VOTERS,
Expand Down Expand Up @@ -1009,6 +1008,15 @@ describe("Client Address List", () => {
expect(proposals[0].creatorAddress).toBe(SUBGRAPH_PROPOSAL_BASE.creator);
expect(proposals[0].metadata.title).toBe(ipfsMetadata.title);
expect(proposals[0].metadata.summary).toBe(ipfsMetadata.summary);
for (const [index, action] of proposals[0].actions.entries()) {
expect(action.value).toBe(
BigInt(SUBGRAPH_PROPOSAL_BASE.actions[index].value),
);
expect(action.to).toBe(SUBGRAPH_PROPOSAL_BASE.actions[index].to);
expect(bytesToHex(action.data)).toBe(
SUBGRAPH_PROPOSAL_BASE.actions[index].data.toLowerCase(),
);
}
expect(proposals[0].startDate.getTime()).toBe(
parseInt(SUBGRAPH_PROPOSAL_BASE.startDate) * 1000,
);
Expand Down
1 change: 1 addition & 0 deletions modules/client/test/integration/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export const SUBGRAPH_VOTERS: SubgraphVoterListItemBase[] = [

export const SUBGRAPH_PROPOSAL_BASE: SubgraphProposalBase = {
id: TEST_ADDRESSLIST_PROPOSAL_ID,
actions: SUBGRAPH_ACTIONS,
dao: {
id: ADDRESS_ONE,
subdomain: "test",
Expand Down
21 changes: 19 additions & 2 deletions modules/client/test/integration/multisig-client/methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
ADDRESS_ONE,
ADDRESS_TWO,
contextParamsLocalChain,
SUBGRAPH_ACTIONS,
SUBGRAPH_PLUGIN_INSTALLATION,
SUBGRAPH_PROPOSAL_BASE,
TEST_INVALID_ADDRESS,
Expand All @@ -46,6 +45,7 @@ import {
} from "../../../src/multisig/internal/graphql-queries/members";
import { SubgraphMultisigProposal } from "../../../src/multisig/internal/types";
import {
bytesToHex,
Context,
getExtendedProposalId,
InvalidAddressOrEnsError,
Expand Down Expand Up @@ -609,7 +609,6 @@ describe("Client Multisig", () => {

const subgraphProposal: SubgraphMultisigProposal = {
createdAt: Math.round(Date.now() / 1000).toString(),
actions: SUBGRAPH_ACTIONS,
creationBlockNumber: "40",
executionDate: Math.round(Date.now() / 1000).toString(),
executionBlockNumber: "50",
Expand Down Expand Up @@ -655,6 +654,15 @@ describe("Client Multisig", () => {
expect(proposal.creationDate.getTime()).toBe(
parseInt(subgraphProposal.createdAt) * 1000,
);
for (const [index, action] of proposal.actions.entries()) {
expect(action.value).toBe(
BigInt(subgraphProposal.actions[index].value),
);
expect(action.to).toBe(subgraphProposal.actions[index].to);
expect(bytesToHex(action.data)).toBe(
subgraphProposal.actions[index].data.toLowerCase(),
);
}
expect(proposal.actions).toMatchObject(proposal.actions);

expect(proposal.executionTxHash).toMatch(
Expand Down Expand Up @@ -762,6 +770,15 @@ describe("Client Multisig", () => {
expect(proposals[0].approvals).toMatchObject([ADDRESS_ONE, ADDRESS_TWO]);
expect(proposals[0].settings.minApprovals).toBe(5);
expect(proposals[0].settings.onlyListed).toBe(true);
for (const [index, action] of proposals[0].actions.entries()) {
expect(action.value).toBe(
BigInt(SUBGRAPH_PROPOSAL_BASE.actions[index].value),
);
expect(action.to).toBe(SUBGRAPH_PROPOSAL_BASE.actions[index].to);
expect(bytesToHex(action.data)).toBe(
SUBGRAPH_PROPOSAL_BASE.actions[index].data.toLowerCase(),
);
}

expect(mockedClient.request).toHaveBeenCalledWith(
QueryMultisigProposals,
Expand Down
12 changes: 10 additions & 2 deletions modules/client/test/integration/tokenVoting-client/methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
ADDRESS_THREE,
ADDRESS_TWO,
contextParamsLocalChain,
SUBGRAPH_ACTIONS,
SUBGRAPH_PLUGIN_INSTALLATION,
SUBGRAPH_PROPOSAL_BASE,
TEST_INVALID_ADDRESS,
Expand Down Expand Up @@ -81,6 +80,7 @@ import {
} from "@aragon/osx-ethers";
import { BigNumber } from "@ethersproject/bignumber";
import {
bytesToHex,
Context,
getExtendedProposalId,
InvalidAddressError,
Expand Down Expand Up @@ -1081,7 +1081,6 @@ describe("Token Voting Client", () => {

const subgraphProposal: SubgraphTokenVotingProposal = {
createdAt: Math.round(Date.now() / 1000).toString(),
actions: SUBGRAPH_ACTIONS,
supportThreshold: "1000000",
totalVotingPower: "3000000",
votingMode: VotingMode.EARLY_EXECUTION,
Expand Down Expand Up @@ -1326,6 +1325,15 @@ describe("Token Voting Client", () => {
expect(proposals.length).toBe(2);
for (const [index, proposal] of proposals.entries()) {
expect(proposal.id).toBe(subgraphProposals[index].id);
for (const [actionIndex, action] of proposal.actions.entries()) {
expect(action.value).toBe(
BigInt(subgraphProposals[index].actions[actionIndex].value),
);
expect(action.to).toBe(subgraphProposals[index].actions[actionIndex].to);
expect(bytesToHex(action.data)).toBe(
subgraphProposals[index].actions[actionIndex].data.toLowerCase(),
);
}
expect(proposal.dao.address).toBe(subgraphProposals[index].dao.id);
expect(proposal.dao.name).toBe(
subgraphProposals[index].dao.subdomain,
Expand Down

0 comments on commit 7cd47bd

Please sign in to comment.