Skip to content

Commit

Permalink
fix: use network specific delegation subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekhmet committed Jan 23, 2025
1 parent 92a0c35 commit f468c98
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
6 changes: 2 additions & 4 deletions apps/ui/src/components/SpaceDelegates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getNames } from '@/helpers/stamp';
import { _n, _p, _vp, shorten } from '@/helpers/utils';
import { getNetwork, supportsNullCurrent } from '@/networks';
import { SNAPSHOT_URLS } from '@/networks/offchain';
import { DelegationType, Space, SpaceMetadataDelegation } from '@/types';
import { RequiredProperty, Space, SpaceMetadataDelegation } from '@/types';
const props = defineProps<{
space: Space;
Expand Down Expand Up @@ -44,9 +44,7 @@ const {
getDelegates,
getDelegation
} = useDelegates(
props.delegation.apiType as DelegationType,
props.delegation.apiUrl as string,
props.delegation.contractAddress as string,
props.delegation as RequiredProperty<typeof props.delegation>,
props.space
);
const { getDelegatee } = useActions();
Expand Down
46 changes: 35 additions & 11 deletions apps/ui/src/composables/useDelegates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import {
import gql from 'graphql-tag';
import { getNames } from '@/helpers/stamp';
import { getNetwork, metadataNetwork as metadataNetworkId } from '@/networks';
import { DelegationType, Space, Statement } from '@/types';
import {
RequiredProperty,
Space,
SpaceMetadataDelegation,
Statement
} from '@/types';

type ApiDelegate = {
id: string;
Expand Down Expand Up @@ -48,6 +53,22 @@ const DEFAULT_ORDER = 'delegatedVotes-desc';

const DELEGATES_LIMIT = 40;

const DELEGATION_SUBGRAPHS = {
'1': 'https://subgrapher.snapshot.org/delegation/1',
'10': 'https://subgrapher.snapshot.org/delegation/10',
'56': 'https://subgrapher.snapshot.org/delegation/56',
'100': 'https://subgrapher.snapshot.org/delegation/100',
'137': 'https://subgrapher.snapshot.org/delegation/137',
'146': 'https://subgrapher.snapshot.org/delegation/146',
'250': 'https://subgrapher.snapshot.org/delegation/250',
'8453': 'https://subgrapher.snapshot.org/delegation/8453',
'42161': 'https://subgrapher.snapshot.org/delegation/42161',
'59144': 'https://subgrapher.snapshot.org/delegation/59144',
'81457': 'https://subgrapher.snapshot.org/delegation/81457',
'84532': 'https://subgrapher.snapshot.org/delegation/84532',
'11155111': 'https://subgrapher.snapshot.org/delegation/11155111'
};

const DELEGATES_QUERY = gql`
query (
$first: Int!
Expand Down Expand Up @@ -104,9 +125,7 @@ function convertUrl(apiUrl: string) {
}

export function useDelegates(
delegationType: DelegationType,
delegationApiUrl: string,
governance: string,
delegation: RequiredProperty<SpaceMetadataDelegation>,
space: Space
) {
const delegates: Ref<Delegate[]> = ref([]);
Expand All @@ -118,7 +137,7 @@ export function useDelegates(
const errorCode = ref<'initializing' | null>(null);

const httpLink = createHttpLink({
uri: convertUrl(delegationApiUrl)
uri: convertUrl(delegation.apiUrl)
});

const apollo = new ApolloClient({
Expand Down Expand Up @@ -176,7 +195,7 @@ export function useDelegates(
): Promise<Delegate[]> {
const where = {
tokenHoldersRepresentedAmount_gte: 0,
governance: governance.toLowerCase(),
governance: delegation.contractAddress.toLowerCase(),
...filter.where
};

Expand All @@ -189,15 +208,20 @@ export function useDelegates(
}

async function getDelegation(delegator: string) {
if (delegation.apiType !== 'delegate-registry') {
throw new Error('getDelegation is only supported for delegate-registry');
}

const delegationSubgraph = DELEGATION_SUBGRAPHS[delegation.chainId];
if (!delegationSubgraph) {
throw new Error('Delegation subgraph not found');
}

const client = new ApolloClient({
uri: 'https://api.studio.thegraph.com/query/23545/snapshot/version/latest',
uri: delegationSubgraph,
cache: new InMemoryCache()
});

if (delegationType !== 'delegate-registry') {
throw new Error('getDelegation is only supported for delegate-registry');
}

const { data } = await client.query({
query: DELEGATIONS_QUERY,
variables: { space: space.id, delegator }
Expand Down

0 comments on commit f468c98

Please sign in to comment.