Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion modules/delegates/api/fetchChainDelegates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export async function fetchChainDelegates(
address: d.ownerAddress,
voteDelegateAddress: d.address,
skyDelegated: formatEther(BigInt(totalDelegated)),
delegations: d.delegations || [], // Include current delegations from subgraph
lastVoteDate: d.voter?.lastVotedTimestamp ? Number(d.voter.lastVotedTimestamp) : null
};
});
Expand Down
8 changes: 1 addition & 7 deletions modules/delegates/api/fetchDelegates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
skyDelegated: onChainDelegate.skyDelegated,
proposalsSupported: onChainDelegate.proposalsSupported,
execSupported: undefined,
delegations: onChainDelegate.delegations, // Include current delegations from subgraph
blockTimestamp: onChainDelegate.blockTimestamp
};
}
Expand Down Expand Up @@ -183,7 +182,7 @@
page,
orderBy,
orderDirection,
seed,

Check warning on line 185 in modules/delegates/api/fetchDelegates.ts

View workflow job for this annotation

GitHub Actions / unit

'seed' is defined but never used

Check warning on line 185 in modules/delegates/api/fetchDelegates.ts

View workflow job for this annotation

GitHub Actions / unit

'seed' is defined but never used
delegateType,
searchTerm
}: DelegatesValidatedQueryParams): Promise<DelegatesPaginatedAPIResponse> {
Expand Down Expand Up @@ -352,11 +351,6 @@

const lastVoteTimestamp = Math.max(lastVoteMainnet, lastVoteArbitrum);

const totalDelegated: bigint = delegate.delegations.reduce(
(acc, curr) => acc + BigInt(curr?.amount || 0n),
0n
);

return {
name: githubDelegate?.name || 'Shadow Delegate',
voteDelegateAddress: delegateId,
Expand All @@ -366,7 +360,7 @@
picture: githubDelegate?.picture,
communication: githubDelegate?.communication,
combinedParticipation: githubDelegate?.combinedParticipation,
skyDelegated: formatEther(totalDelegated),
skyDelegated: formatEther(BigInt(delegate.totalDelegated || '0')),
delegatorCount: delegate.delegators,
lastVoteDate: lastVoteTimestamp > 0 ? new Date(lastVoteTimestamp * 1000) : null,
proposalsSupported: votedProposals?.length || 0,
Expand Down
48 changes: 17 additions & 31 deletions modules/delegates/api/fetchDelegationMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { gqlRequest } from 'modules/gql/gqlRequest';
import { allDelegationsPaginated } from 'modules/gql/queries/subgraph/allDelegations';
import { allDelegates } from 'modules/gql/queries/subgraph/allDelegates';
import { SupportedNetworks } from 'modules/web3/constants/networks';
import { networkNameToChainId } from 'modules/web3/helpers/chain';
import { formatEther } from 'viem';
Expand All @@ -17,40 +17,26 @@ interface DelegationMetrics {
delegatorCount: number;
}

interface Delegation {
delegator: string;
delegate: {
id: string;
version: string;
};
amount: string;
interface Delegate {
totalDelegated: string;
delegators: number;
}

export async function fetchDelegationMetrics(network: SupportedNetworks): Promise<DelegationMetrics> {
const chainId = networkNameToChainId(network);
const pageSize = 1000;
let skip = 0;
let hasMore = true;
const allDelegations: Delegation[] = [];

// Fetch all delegations using pagination
while (hasMore) {
const res = await gqlRequest<any>({
chainId,
query: allDelegationsPaginated(chainId, pageSize, skip)
});

const delegations = res.delegations || [];
allDelegations.push(...delegations);

// Check if there are more results to fetch
hasMore = delegations.length === pageSize;
skip += pageSize;
}

// Calculate metrics from all delegations
const totalSkyDelegated = formatEther(allDelegations.reduce((acc, cur) => acc + BigInt(cur.amount), 0n));
const delegatorCount = allDelegations.filter(d => BigInt(d.amount) > 0n).length;

const res = await gqlRequest<{ delegates: Delegate[] }>({
chainId,
query: allDelegates(chainId)
});

const delegates = res.delegates || [];

// Sum totalDelegated and delegators across all delegates
const totalSkyDelegated = formatEther(
delegates.reduce((acc, cur) => acc + BigInt(cur.totalDelegated || '0'), 0n)
);
const delegatorCount = delegates.reduce((acc, cur) => acc + (cur.delegators || 0), 0);

return {
totalSkyDelegated,
Expand Down
2 changes: 0 additions & 2 deletions modules/delegates/types/delegate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export type DelegateContractInformation = {
blockTimestamp: string;
skyDelegated: string;
proposalsSupported: number;
delegations?: { delegator: string; amount: string }[]; // current delegations from subgraph
lastVoteDate: number | null;
};

Expand All @@ -72,7 +71,6 @@ export type Delegate = {
skyDelegated: string;
proposalsSupported: number;
execSupported: CMSProposal | undefined;
delegations?: { delegator: string; amount: string }[]; // current delegations from subgraph
blockTimestamp: string;
};

Expand Down
11 changes: 1 addition & 10 deletions modules/gql/queries/subgraph/allDelegates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,10 @@ export const allDelegates = (chainId: number) => /* GraphQL */ `
id
address
totalDelegated
delegators
voter {
lastVotedTimestamp
}
delegations(
limit: 1000
where: { _and: [
{ _and: [{ delegator: { _nilike: "0xce01c90de7fd1bcfa39e237fe6d8d9f569e8a6a3" } }, { delegator: { _nilike: "0xb1fc11f03b084fff8dae95fa08e8d69ad2547ec1" } }] },
{ amount: { _gt: "0" } }
] }
) {
delegator
amount
}
}
}
`;
25 changes: 0 additions & 25 deletions modules/gql/queries/subgraph/allDelegations.ts

This file was deleted.

11 changes: 1 addition & 10 deletions modules/gql/queries/subgraph/delegates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@ const delegateFields = /* GraphQL */ `
blockTimestamp
blockNumber
ownerAddress
delegations(
limit: 1000
where: { _and: [
{ _and: [{ delegator: { _nilike: "0xce01c90de7fd1bcfa39e237fe6d8d9f569e8a6a3" } }, { delegator: { _nilike: "0xb1fc11f03b084fff8dae95fa08e8d69ad2547ec1" } }] },
{ amount: { _gt: "0" } }
] }
) {
delegator
amount
}
totalDelegated
id
address
delegators
Expand Down
Loading