From f105dbbdc77ddcbc5ff04a94d7277d73c1c00f09 Mon Sep 17 00:00:00 2001 From: emmdim Date: Tue, 30 Jan 2024 12:20:09 +0100 Subject: [PATCH] Implements getDelegatee funtion --- .../src/internal/graphql-queries/member.ts | 23 +++++++++++ packages/js-client/src/internal/interfaces.ts | 39 ++++++++----------- .../js-client/src/internal/modules/methods.ts | 31 +++++++++++++++ 3 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 packages/js-client/src/internal/graphql-queries/member.ts diff --git a/packages/js-client/src/internal/graphql-queries/member.ts b/packages/js-client/src/internal/graphql-queries/member.ts new file mode 100644 index 00000000..02013e39 --- /dev/null +++ b/packages/js-client/src/internal/graphql-queries/member.ts @@ -0,0 +1,23 @@ +import { gql } from 'graphql-request'; + +export const QueryMemberInfo = gql` + query PluginMembers($address: String!, $block: Block_height) { + pluginMembers(block: $block, where: { address: : $address }) { + address + balance + votingPower + delegatee { + address + } + delegators { + address + } + } + } +`; + +// query MyQuery { +// pluginMembers(where: {address: "0x05c1abef7664f65b0a8d5b3fe8e6b817ea9d3d90"}) { +// address +// } +// } diff --git a/packages/js-client/src/internal/interfaces.ts b/packages/js-client/src/internal/interfaces.ts index 392f232e..b52f1e7b 100644 --- a/packages/js-client/src/internal/interfaces.ts +++ b/packages/js-client/src/internal/interfaces.ts @@ -50,13 +50,12 @@ export interface IGaslessVotingClientMethods { getProposal( proposalId: string, daoName?: string, - daoAddress?: string, + daoAddress?: string ): Promise; // - getProposals(params: - ProposalQueryParams & { pluginAddress: string }): Promise< - GaslessVotingProposalListItem[] - > + getProposals( + params: ProposalQueryParams & { pluginAddress: string } + ): Promise; // getVotingSettings( pluginAddress: string, @@ -72,9 +71,7 @@ export interface IGaslessVotingClientMethods { pluginAddress: string, memberAddress: string ): Promise; - approve( - proposalId: string, - ): Promise>; + approve(proposalId: string): Promise>; setTally( proposalId: string, results: bigint[][] @@ -83,9 +80,11 @@ export interface IGaslessVotingClientMethods { proposalId: string, tryExecutio: boolean ): AsyncGenerator; - executeProposal( - proposalId: string - ): AsyncGenerator; + executeProposal(proposalId: string): AsyncGenerator; + getDelegatee( + memberAddress: string, + blockNumber?: number + ): Promise; pinMetadata(params: ProposalMetadata): Promise; } export interface IGaslessVotingClientEstimation { @@ -96,12 +95,12 @@ export interface IGaslessVotingClientEstimation { createProposal( params: CreateGasslessProposalParams ): Promise; - setTally( + setTally(proposalId: string, results: bigint[][]): Promise; + approve(proposalId: string): Promise; + approveTally( proposalId: string, - results: bigint[][] + tryExecution: boolean ): Promise; - approve(proposalId: string): Promise; - approveTally(proposalId: string, tryExecution: boolean): Promise; executeProposal(proposalId: string): Promise; // Add any estimation methods that you need } @@ -116,19 +115,15 @@ export interface IGaslessVotingClientEncoding { pluginAddress: string, params: GaslessPluginVotingSettings ): DaoAction; - addAddressesAction( - params: AddAddressesParams, - ): DaoAction; - removeAddressesAction( - params: RemoveAddressesParams, - ): DaoAction; + addAddressesAction(params: AddAddressesParams): DaoAction; + removeAddressesAction(params: RemoveAddressesParams): DaoAction; } export interface IGaslessVotingClientDecoding { // Fill with methods that encode actions that can be passed to a proposal // encodeAction(data: Uint8Array): params; findInterface(data: Uint8Array): InterfaceParams | null; addAddressesAction(data: Uint8Array): string[]; - removeAddressesAction(data: Uint8Array): string[] + removeAddressesAction(data: Uint8Array): string[]; updatePluginSettingsAction(data: Uint8Array): GaslessPluginVotingSettings; mintTokenAction(data: Uint8Array): MintTokenParams; } diff --git a/packages/js-client/src/internal/modules/methods.ts b/packages/js-client/src/internal/modules/methods.ts index 189b707d..e2e2903a 100644 --- a/packages/js-client/src/internal/modules/methods.ts +++ b/packages/js-client/src/internal/modules/methods.ts @@ -18,6 +18,7 @@ import { QueryPluginProposals, QueryPluginSettings, } from '../graphql-queries'; +import { QueryMemberInfo } from '../graphql-queries/member'; import { IGaslessVotingClientMethods } from '../interfaces'; import { initParamsToContract, @@ -640,6 +641,36 @@ export class GaslessVotingClientMethods ); } + /** + * Retrieves the delegatee address for a given member address. + * @param {string} memberAddress - The address of the member. + * @param {number} blockNumber - Optional block number to query the delegatee at a specific block. + * @returns A Promise that resolves to the delegatee address or null if not found. + */ + public async getDelegatee( + memberAddress: string, + blockNumber?: number + ): Promise { + if (!isAddress(memberAddress)) { + Promise.reject(new InvalidAddressError()); + } + const query = QueryMemberInfo; + const params = { + address: memberAddress.toLowerCase(), + block: blockNumber ? { number: blockNumber } : null, + }; + const name = 'GaslessVoting members'; + type T = { pluginMembers: SubgraphVotingMember[] }; + const { pluginMembers } = await this.graphql.request({ + query, + params, + name, + }); + if (pluginMembers.length == 0) return null; + if (pluginMembers[0].delegatee) return pluginMembers[0].delegatee.address; + return null; + } + /** * Checks whether the current proposal can be executed *