From 7cd47bd67f29610fa80a9e1ec83dd0c3193fb5bd Mon Sep 17 00:00:00 2001 From: josemarinas <36479864+josemarinas@users.noreply.github.com> Date: Mon, 6 Nov 2023 10:16:30 +0100 Subject: [PATCH] Feature: Add actions to proposal queries (#300) * add actions to proposal queries * update changelog and package.json * update changelog and package.json --- modules/client-common/CHANGELOG.md | 6 ++++++ modules/client-common/package.json | 2 +- modules/client-common/src/types.ts | 1 + modules/client/CHANGELOG.md | 3 +++ modules/client/package.json | 4 ++-- .../internal/graphql-queries/proposal.ts | 5 +++++ .../src/addresslistVoting/internal/types.ts | 2 -- .../src/addresslistVoting/internal/utils.ts | 9 ++++++++ .../client/src/client-common/types/plugin.ts | 1 + .../internal/graphql-queries/proposal.ts | 5 +++++ modules/client/src/multisig/internal/types.ts | 19 ++--------------- modules/client/src/multisig/internal/utils.ts | 9 ++++++++ .../internal/graphql-queries/proposal.ts | 5 +++++ .../client/src/tokenVoting/internal/utils.ts | 9 ++++++++ .../addresslistVoting-client/methods.test.ts | 12 +++++++++-- modules/client/test/integration/constants.ts | 1 + .../multisig-client/methods.test.ts | 21 +++++++++++++++++-- .../tokenVoting-client/methods.test.ts | 12 +++++++++-- 18 files changed, 98 insertions(+), 28 deletions(-) diff --git a/modules/client-common/CHANGELOG.md b/modules/client-common/CHANGELOG.md index d6e133049..d89af3c0d 100644 --- a/modules/client-common/CHANGELOG.md +++ b/modules/client-common/CHANGELOG.md @@ -18,6 +18,12 @@ TEMPLATE: --> ## [UPCOMING] + +### Added + +- Added `actions` to `SubgraphListItem` type + +## [1.10.0] ### Added - Add support for arbitrum network diff --git a/modules/client-common/package.json b/modules/client-common/package.json index d6809eaa6..13330eb04 100644 --- a/modules/client-common/package.json +++ b/modules/client-common/package.json @@ -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", diff --git a/modules/client-common/src/types.ts b/modules/client-common/src/types.ts index b47ba6764..eba248d1a 100644 --- a/modules/client-common/src/types.ts +++ b/modules/client-common/src/types.ts @@ -237,6 +237,7 @@ export type ProposalListItemBase = { startDate: Date; endDate: Date; status: ProposalStatus; + actions: DaoAction[]; }; export type PrepareUpdateParams = { diff --git a/modules/client/CHANGELOG.md b/modules/client/CHANGELOG.md index a39c9d8ff..17c3cd996 100644 --- a/modules/client/CHANGELOG.md +++ b/modules/client/CHANGELOG.md @@ -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 diff --git a/modules/client/package.json b/modules/client/package.json index 04bc87469..5a3e78345 100644 --- a/modules/client/package.json +++ b/modules/client/package.json @@ -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", @@ -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", diff --git a/modules/client/src/addresslistVoting/internal/graphql-queries/proposal.ts b/modules/client/src/addresslistVoting/internal/graphql-queries/proposal.ts index 60741ab4f..e827770be 100644 --- a/modules/client/src/addresslistVoting/internal/graphql-queries/proposal.ts +++ b/modules/client/src/addresslistVoting/internal/graphql-queries/proposal.ts @@ -50,6 +50,11 @@ query AddresslistVotingProposals($where: AddresslistVotingProposal_filter!, $lim id subdomain } + actions { + to + value + data + } creator metadata yes diff --git a/modules/client/src/addresslistVoting/internal/types.ts b/modules/client/src/addresslistVoting/internal/types.ts index 3e71420b2..1f220b68d 100644 --- a/modules/client/src/addresslistVoting/internal/types.ts +++ b/modules/client/src/addresslistVoting/internal/types.ts @@ -1,6 +1,5 @@ import { ContractVotingSettings, - SubgraphAction, SubgraphProposalBase, SubgraphVoterListItemBase, VotingMode, @@ -22,7 +21,6 @@ export type SubgraphAddresslistVotingProposalListItem = SubgraphProposalBase & { export type SubgraphAddresslistVotingProposal = SubgraphProposalBase & { createdAt: string; - actions: SubgraphAction[]; supportThreshold: string; minVotingPower: string; voters: SubgraphAddresslistVotingVoterListItem[]; diff --git a/modules/client/src/addresslistVoting/internal/utils.ts b/modules/client/src/addresslistVoting/internal/utils.ts index b55f29264..c5ab09704 100644 --- a/modules/client/src/addresslistVoting/internal/utils.ts +++ b/modules/client/src/addresslistVoting/internal/utils.ts @@ -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 { diff --git a/modules/client/src/client-common/types/plugin.ts b/modules/client/src/client-common/types/plugin.ts index 23b6ff013..a270efb09 100644 --- a/modules/client/src/client-common/types/plugin.ts +++ b/modules/client/src/client-common/types/plugin.ts @@ -128,6 +128,7 @@ export type SubgraphProposalBase = { endDate: string; executed: boolean; potentiallyExecutable: boolean; + actions: SubgraphAction[] }; export type ProposalQueryParams = Pagination & { diff --git a/modules/client/src/multisig/internal/graphql-queries/proposal.ts b/modules/client/src/multisig/internal/graphql-queries/proposal.ts index aea59125e..ab32b2b6e 100644 --- a/modules/client/src/multisig/internal/graphql-queries/proposal.ts +++ b/modules/client/src/multisig/internal/graphql-queries/proposal.ts @@ -55,6 +55,11 @@ query MultisigProposals($where: MultisigProposal_filter!, $limit:Int!, $skip: In approvers { id } + actions { + to + value + data + } minApprovals plugin{ onlyListed diff --git a/modules/client/src/multisig/internal/types.ts b/modules/client/src/multisig/internal/types.ts index 5d5546e21..bc6783278 100644 --- a/modules/client/src/multisig/internal/types.ts +++ b/modules/client/src/multisig/internal/types.ts @@ -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; @@ -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; diff --git a/modules/client/src/multisig/internal/utils.ts b/modules/client/src/multisig/internal/utils.ts index a92056e4f..420aa41cd 100644 --- a/modules/client/src/multisig/internal/utils.ts +++ b/modules/client/src/multisig/internal/utils.ts @@ -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, diff --git a/modules/client/src/tokenVoting/internal/graphql-queries/proposal.ts b/modules/client/src/tokenVoting/internal/graphql-queries/proposal.ts index c4f5f134a..e2d50ff0b 100644 --- a/modules/client/src/tokenVoting/internal/graphql-queries/proposal.ts +++ b/modules/client/src/tokenVoting/internal/graphql-queries/proposal.ts @@ -85,6 +85,11 @@ query TokenVotingProposals($where: TokenVotingProposal_filter!, $limit:Int!, $sk supportThreshold minVotingPower totalVotingPower + actions { + to + value + data + } voters{ voter{ address diff --git a/modules/client/src/tokenVoting/internal/utils.ts b/modules/client/src/tokenVoting/internal/utils.ts index 5f072a1d0..d480fe5b0 100644 --- a/modules/client/src/tokenVoting/internal/utils.ts +++ b/modules/client/src/tokenVoting/internal/utils.ts @@ -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), + }; + }, + ), }; } diff --git a/modules/client/test/integration/addresslistVoting-client/methods.test.ts b/modules/client/test/integration/addresslistVoting-client/methods.test.ts index e67969f5b..03fa9bc0a 100644 --- a/modules/client/test/integration/addresslistVoting-client/methods.test.ts +++ b/modules/client/test/integration/addresslistVoting-client/methods.test.ts @@ -24,7 +24,6 @@ import { ADDRESS_ONE, ADDRESS_TWO, contextParamsLocalChain, - SUBGRAPH_ACTIONS, SUBGRAPH_PLUGIN_INSTALLATION, SUBGRAPH_PROPOSAL_BASE, SUBGRAPH_VOTERS, @@ -54,6 +53,7 @@ import { SubgraphAddresslistVotingProposalListItem, } from "../../../src/addresslistVoting/internal/types"; import { + bytesToHex, Context, getExtendedProposalId, InvalidAddressOrEnsError, @@ -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, @@ -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, ); diff --git a/modules/client/test/integration/constants.ts b/modules/client/test/integration/constants.ts index 6d916f2db..6f67cc8d3 100644 --- a/modules/client/test/integration/constants.ts +++ b/modules/client/test/integration/constants.ts @@ -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", diff --git a/modules/client/test/integration/multisig-client/methods.test.ts b/modules/client/test/integration/multisig-client/methods.test.ts index 1f5c8dd22..43ae00e90 100644 --- a/modules/client/test/integration/multisig-client/methods.test.ts +++ b/modules/client/test/integration/multisig-client/methods.test.ts @@ -21,7 +21,6 @@ import { ADDRESS_ONE, ADDRESS_TWO, contextParamsLocalChain, - SUBGRAPH_ACTIONS, SUBGRAPH_PLUGIN_INSTALLATION, SUBGRAPH_PROPOSAL_BASE, TEST_INVALID_ADDRESS, @@ -46,6 +45,7 @@ import { } from "../../../src/multisig/internal/graphql-queries/members"; import { SubgraphMultisigProposal } from "../../../src/multisig/internal/types"; import { + bytesToHex, Context, getExtendedProposalId, InvalidAddressOrEnsError, @@ -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", @@ -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( @@ -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, diff --git a/modules/client/test/integration/tokenVoting-client/methods.test.ts b/modules/client/test/integration/tokenVoting-client/methods.test.ts index 2852438b6..a92197eea 100644 --- a/modules/client/test/integration/tokenVoting-client/methods.test.ts +++ b/modules/client/test/integration/tokenVoting-client/methods.test.ts @@ -35,7 +35,6 @@ import { ADDRESS_THREE, ADDRESS_TWO, contextParamsLocalChain, - SUBGRAPH_ACTIONS, SUBGRAPH_PLUGIN_INSTALLATION, SUBGRAPH_PROPOSAL_BASE, TEST_INVALID_ADDRESS, @@ -81,6 +80,7 @@ import { } from "@aragon/osx-ethers"; import { BigNumber } from "@ethersproject/bignumber"; import { + bytesToHex, Context, getExtendedProposalId, InvalidAddressError, @@ -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, @@ -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,