Skip to content

Commit

Permalink
Implements getDelegatee funtion
Browse files Browse the repository at this point in the history
  • Loading branch information
emmdim committed Jan 30, 2024
1 parent 1c4f61c commit f105dbb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 22 deletions.
23 changes: 23 additions & 0 deletions packages/js-client/src/internal/graphql-queries/member.ts
Original file line number Diff line number Diff line change
@@ -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
// }
// }
39 changes: 17 additions & 22 deletions packages/js-client/src/internal/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ export interface IGaslessVotingClientMethods {
getProposal(
proposalId: string,
daoName?: string,
daoAddress?: string,
daoAddress?: string
): Promise<GaslessVotingProposal | null>;
//
getProposals(params:
ProposalQueryParams & { pluginAddress: string }): Promise<
GaslessVotingProposalListItem[]
>
getProposals(
params: ProposalQueryParams & { pluginAddress: string }
): Promise<GaslessVotingProposalListItem[]>;
//
getVotingSettings(
pluginAddress: string,
Expand All @@ -72,9 +71,7 @@ export interface IGaslessVotingClientMethods {
pluginAddress: string,
memberAddress: string
): Promise<boolean>;
approve(
proposalId: string,
): Promise<AsyncGenerator<ApproveTallyStepValue>>;
approve(proposalId: string): Promise<AsyncGenerator<ApproveTallyStepValue>>;
setTally(
proposalId: string,
results: bigint[][]
Expand All @@ -83,9 +80,11 @@ export interface IGaslessVotingClientMethods {
proposalId: string,
tryExecutio: boolean
): AsyncGenerator<ApproveTallyStepValue>;
executeProposal(
proposalId: string
): AsyncGenerator<ExecuteProposalStepValue>;
executeProposal(proposalId: string): AsyncGenerator<ExecuteProposalStepValue>;
getDelegatee(
memberAddress: string,
blockNumber?: number
): Promise<string | null>;
pinMetadata(params: ProposalMetadata): Promise<string>;
}
export interface IGaslessVotingClientEstimation {
Expand All @@ -96,12 +95,12 @@ export interface IGaslessVotingClientEstimation {
createProposal(
params: CreateGasslessProposalParams
): Promise<GasFeeEstimation>;
setTally(
setTally(proposalId: string, results: bigint[][]): Promise<GasFeeEstimation>;
approve(proposalId: string): Promise<GasFeeEstimation>;
approveTally(
proposalId: string,
results: bigint[][]
tryExecution: boolean
): Promise<GasFeeEstimation>;
approve(proposalId: string): Promise<GasFeeEstimation>;
approveTally(proposalId: string, tryExecution: boolean): Promise<GasFeeEstimation>;
executeProposal(proposalId: string): Promise<GasFeeEstimation>;
// Add any estimation methods that you need
}
Expand All @@ -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;
}
31 changes: 31 additions & 0 deletions packages/js-client/src/internal/modules/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
QueryPluginProposals,
QueryPluginSettings,
} from '../graphql-queries';
import { QueryMemberInfo } from '../graphql-queries/member';
import { IGaslessVotingClientMethods } from '../interfaces';
import {
initParamsToContract,
Expand Down Expand Up @@ -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<string | null> {
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<T>({
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
*
Expand Down

0 comments on commit f105dbb

Please sign in to comment.