Skip to content

Commit

Permalink
Merge branch 'develop' into f/OS-824-add-actions-to-proposals-queries
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarinas authored Nov 6, 2023
2 parents 944611e + 72938d7 commit 39dab17
Show file tree
Hide file tree
Showing 19 changed files with 484 additions and 2 deletions.
6 changes: 6 additions & 0 deletions modules/client-common/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,9 @@ export const ApplyUninstallationSchema = object({
export const ApplyInstallationSchema = ApplyUninstallationSchema.concat(object({
helpers: array(AddressOrEnsSchema).required(),
}));

export const IsMemberSchema = object({
address: AddressOrEnsSchema.required(),
pluginAddress: AddressOrEnsSchema.required(),
blockNumber: number().notRequired(),
});
5 changes: 5 additions & 0 deletions modules/client-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,8 @@ export enum SupportedVersion {
V1_3_0 = "1.3.0",
LATEST = "1.3.0",
}
export type IsMemberParams = {
address: string;
pluginAddress: string;
blockNumber?: number;
};
8 changes: 8 additions & 0 deletions modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ TEMPLATE:
-->

## [UPCOMING]

### Added

- `isMember` function to `TokenVotingClient`
- `isMember` function to `AddresslistVotingClient`
- `isMember` function to `Client`

## [1.18.2]
### Fixed

- Plugin preparations query
Expand Down
31 changes: 31 additions & 0 deletions modules/client/examples/02-multisig-client/15-is-member.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* MARKDOWN
---
title: Is Member
---
### Check if an address is a member of Multisig DAO in a specific block and plugin
The is member function receives the plugin address and the address to check as parameters and returns a boolean value.
*/

import { MultisigClient } from "@aragon/sdk-client";
import { context } from "../index";

// Instantiate the multisig client from the Aragon OSx SDK context.
const client: MultisigClient = new MultisigClient(context);

const isMember = await client.methods.isMember({
pluginAddress: "0x2345678901234567890123456789012345678901",
address: "0x1234567890123456789012345678901234567890",
blockNumber: 12345678,
});

console.log(isMember);

/* MARKDOWN
Returns:
```tsx
true
```
*/
31 changes: 31 additions & 0 deletions modules/client/examples/03-tokenVoting-client/22-is-member.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* MARKDOWN
---
title: Is Member
---
### Check if an address is a member of TokenVoting DAO in a specific block and plugin
The is member function receives the plugin address and the address to check as parameters and returns a boolean value.
*/

import { TokenVotingClient } from "@aragon/sdk-client";
import { context } from "../index";

// Instantiate the token voting client from the Aragon OSx SDK context.
const client: TokenVotingClient = new TokenVotingClient(context);

const isMember = await client.methods.isMember({
pluginAddress: "0x2345678901234567890123456789012345678901",
address: "0x1234567890123456789012345678901234567890",
blockNumber: 12345678,
});

console.log(isMember);

/* MARKDOWN
Returns:
```tsx
true
```
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* MARKDOWN
---
title: Is Member
---
### Check if an address is a member of an Addresslist DAO in a specific block and plugin
The is member function receives the plugin address and the address to check as parameters and returns a boolean value.
*/

import { AddresslistVotingClient } from "@aragon/sdk-client";
import { context } from "../index";

// Instantiate the addresslist voting client from the Aragon OSx SDK context.
const client: AddresslistVotingClient = new AddresslistVotingClient(context);

const isMember = await client.methods.isMember({
pluginAddress: "0x2345678901234567890123456789012345678901",
address: "0x1234567890123456789012345678901234567890",
blockNumber: 12345678,
});

console.log(isMember);

/* MARKDOWN
Returns:
```tsx
true
```
*/
28 changes: 28 additions & 0 deletions modules/client/src/addresslistVoting/internal/client/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
votingSettingsToContract,
} from "../../../client-common";
import {
QueryAddresslistVotingIsMember,
QueryAddresslistVotingMembers,
QueryAddresslistVotingProposal,
QueryAddresslistVotingProposals,
Expand Down Expand Up @@ -55,6 +56,8 @@ import {
InvalidCidError,
InvalidProposalIdError,
IpfsPinError,
IsMemberParams,
IsMemberSchema,
isProposalId,
MULTI_FETCH_TIMEOUT,
NoProviderError,
Expand Down Expand Up @@ -578,4 +581,29 @@ export class AddresslistVotingClientMethods extends ClientCore
votingMode: addresslistVotingPlugin.votingMode,
};
}

/**
* Checks if a given address is a member of the AddresslistVoting contract.
* @param params - The parameters for the isMember method.
* @param params.pluginAddress - The address of the plugin.
* @param params.address - The address to check.
* @param params.blockNumber - The block number for specifying a specific block.
* @returns A boolean indicating whether the address is a member or not.
*/
public async isMember(params: IsMemberParams): Promise<boolean> {
IsMemberSchema.strict().validateSync(params);
const query = QueryAddresslistVotingIsMember;
const name = "AddresslistVoting isMember";
type T = { addresslistVotingVoter: { id: string } };
const { addresslistVotingVoter } = await this.graphql.request<T>({
query,
params: {
id:
`${params.pluginAddress.toLowerCase()}_${params.address.toLowerCase()}`,
blockHeight: params.blockNumber ? { number: params.blockNumber } : null,
},
name,
});
return !!addresslistVotingVoter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ query AddresslistVotingMembers($where: AddresslistVotingVoter_filter!, $block: B
address
}
}`;

export const QueryAddresslistVotingIsMember = gql`
query AddresslistVotingIsMember($id: ID!, $block: Block_height) {
addresslistVotingVoter(
id: $id
block: $block
) {
id
}
}`;
2 changes: 2 additions & 0 deletions modules/client/src/addresslistVoting/internal/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DaoAction,
GasFeeEstimation,
InterfaceParams,
IsMemberParams,
PrepareInstallationStepValue,
PrepareUpdateStepValue,
ProposalMetadata,
Expand Down Expand Up @@ -57,6 +58,7 @@ export interface IAddresslistVotingClientMethods {
pluginAddress: string,
blockNumber?: number,
) => Promise<VotingSettings | null>;
isMember: (params: IsMemberParams) => Promise<boolean>;
}

export interface IAddresslistVotingClientEncoding {
Expand Down
30 changes: 29 additions & 1 deletion modules/client/src/multisig/internal/client/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from "../../../client-common";
import { Multisig__factory } from "@aragon/osx-ethers";
import {
QueryMultisigIsMember,
QueryMultisigMembers,
QueryMultisigProposal,
QueryMultisigProposals,
Expand All @@ -53,6 +54,8 @@ import {
InvalidCidError,
InvalidProposalIdError,
IpfsPinError,
IsMemberParams,
IsMemberSchema,
isProposalId,
MULTI_FETCH_TIMEOUT,
NoProviderError,
Expand Down Expand Up @@ -389,7 +392,7 @@ export class MultisigClientMethods extends ClientCore
skip = 0,
direction = SortDirection.ASC,
sortBy = MembersSortBy.ADDRESS,
}: MembersQueryParams): Promise<string[]>{
}: MembersQueryParams): Promise<string[]> {
// TODO
// update this with yup validation
if (!isAddress(pluginAddress)) {
Expand Down Expand Up @@ -565,4 +568,29 @@ export class MultisigClientMethods extends ClientCore
),
);
}

/**
* Checks if a given address is a member of the tokenVoting contract.
* @param params - The parameters for the isMember method.
* @param params.pluginAddress - The address of the plugin.
* @param params.address - The address to check.
* @param params.blockNumber - The block number for specifying a specific block.
* @returns A boolean indicating whether the address is a member or not.
*/
public async isMember(params: IsMemberParams): Promise<boolean> {
IsMemberSchema.strict().validateSync(params);
const query = QueryMultisigIsMember;
const name = "multisig isMember";
type T = { multisigApprover: { id: string } };
const { multisigApprover } = await this.graphql.request<T>({
query,
params: {
id:
`${params.pluginAddress.toLowerCase()}_${params.address.toLowerCase()}`,
blockHeight: params.blockNumber ? { number: params.blockNumber } : null,
},
name,
});
return !!multisigApprover;
}
}
10 changes: 10 additions & 0 deletions modules/client/src/multisig/internal/graphql-queries/members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ query MultisigMembers($where: MultisigApprover_filter!, $block: Block_height, $l
}
}
`;

export const QueryMultisigIsMember = gql`
query MultisigIsMember($id: ID!, $block: Block_height) {
multisigApprover(
id: $id
block: $block
) {
id
}
}`;
2 changes: 2 additions & 0 deletions modules/client/src/multisig/internal/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DaoAction,
GasFeeEstimation,
InterfaceParams,
IsMemberParams,
PrepareInstallationStepValue,
PrepareUpdateStepValue,
ProposalMetadata,
Expand Down Expand Up @@ -58,6 +59,7 @@ export interface IMultisigClientMethods {
getProposals: (
params: ProposalQueryParams,
) => Promise<MultisigProposalListItem[]>;
isMember: (params: IsMemberParams) => Promise<boolean>;
}

export interface IMultisigClientEncoding {
Expand Down
27 changes: 27 additions & 0 deletions modules/client/src/tokenVoting/internal/client/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
TokenVotingTokenCompatibility,
} from "../types";
import {
QueryTokenVotingIsMember,
QueryTokenVotingMembers,
QueryTokenVotingPlugin,
QueryTokenVotingProposal,
Expand Down Expand Up @@ -112,6 +113,8 @@ import {
import { abi as ERC165_ABI } from "@openzeppelin/contracts/build/contracts/ERC165.json";
import { Contract } from "@ethersproject/contracts";
import { AddressZero } from "@ethersproject/constants";
import { IsMemberSchema } from "@aragon/sdk-client-common";
import { IsMemberParams } from "@aragon/sdk-client-common";

/**
* Methods module the SDK TokenVoting Client
Expand Down Expand Up @@ -832,4 +835,28 @@ export class TokenVotingClientMethods extends ClientCore
return TokenVotingTokenCompatibility.NEEDS_WRAPPING;
}
}
/**
* Checks if a given address is a member of the tokenVoting contract.
* @param params - The parameters for the isMember method.
* @param params.pluginAddress - The address of the plugin.
* @param params.address - The address to check.
* @param params.blockNumber - The block number for specifying a specific block.
* @returns A boolean indicating whether the address is a member or not.
*/
public async isMember(params: IsMemberParams): Promise<boolean> {
IsMemberSchema.strict().validateSync(params);
const query = QueryTokenVotingIsMember;
const name = "TokenVoting isMember";
type T = { tokenVotingMember: { id: string } };
const { tokenVotingMember } = await this.graphql.request<T>({
query,
params: {
id:
`${params.pluginAddress.toLowerCase()}_${params.address.toLowerCase()}`,
blockHeight: params.blockNumber ? { number: params.blockNumber } : null,
},
name,
});
return !!tokenVotingMember;
}
}
10 changes: 10 additions & 0 deletions modules/client/src/tokenVoting/internal/graphql-queries/members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ query TokenVotingMembers($where: TokenVotingMember_filter!, $block: Block_height
}
}
`;

export const QueryTokenVotingIsMember = gql`
query TokenVotingIsMember($id: ID!, $block: Block_height) {
tokenVotingMember(
id: $id
block: $block
) {
id
}
}`;
2 changes: 2 additions & 0 deletions modules/client/src/tokenVoting/internal/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DaoAction,
GasFeeEstimation,
InterfaceParams,
IsMemberParams,
PrepareInstallationStepValue,
PrepareUpdateStepValue,
ProposalMetadata,
Expand Down Expand Up @@ -91,6 +92,7 @@ export interface ITokenVotingClientMethods {
isTokenVotingCompatibleToken: (
tokenAddress: string,
) => Promise<TokenVotingTokenCompatibility>;
isMember: (params: IsMemberParams) => Promise<boolean>;
}

export interface ITokenVotingClientEncoding {
Expand Down
Loading

0 comments on commit 39dab17

Please sign in to comment.