Skip to content

Commit

Permalink
feat: add polygon and xdai chains when pulling DAO membership
Browse files Browse the repository at this point in the history
This uses two new subgraphs to pull DAO memberships for Ethereum, xDai,
and Polygon mainnets. The pulls are in parallel. The underlying data is
structured the same way but seems to be missing some information, see
HausDAO/daohaus-supergraph#44
  • Loading branch information
Matthew Cantelon authored and dan13ram committed Jun 14, 2021
1 parent c6b659c commit 0b3b254
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
10 changes: 10 additions & 0 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ interface IConfig {
port: number;
graphqlURL: string;
daoHausGraphqlURL: string;
daoHausPolygonGraphqlURL: string;
daoHausXdaiGraphqlURL: string;
seedGraphqlURL: string;
githubApiToken: string;
adminKey: string;
Expand Down Expand Up @@ -44,6 +46,14 @@ export const CONFIG: IConfig = {
process.env.DAOHAUS_GRAPHQL_URL,
'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus',
),
daoHausPolygonGraphqlURL: parseEnv(
process.env.DAOUHAUS_POLYGON_GRAPHQL_URL,
'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-matic',
),
daoHausXdaiGraphqlURL: parseEnv(
process.env.DAOUHAUS_XDAI_GRAPHQL_URL,
'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-xdai',
),
adminKey: parseEnv(
process.env.HASURA_GRAPHQL_ADMIN_SECRET,
'metagame_secret',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
import { daoHausClient } from '../../../../lib/daoHausClient';
import { QueryResolvers } from '../../autogen/types';
import { clientFactory } from '../../../../lib/daoHausClient';
import { Member, QueryResolvers } from '../../autogen/types';

const addChain = (memberAddress: string) => async (chain: string) => {
const client = clientFactory(chain);
const members = <Member[]>(
(await client.GetDaoHausMemberships({ memberAddress })).members
);

return members.map((member: Member) => {
const updatedMember: Member = { ...member };
updatedMember.moloch.chain = chain;
return updatedMember;
});
};

export const getDaoHausMemberships: QueryResolvers['getDaoHausMemberships'] = async (
_,
{ memberAddress },
) => {
if (!memberAddress) return [];
const res = await daoHausClient.GetDaoHausMemberships({ memberAddress });

return res.members;
const membershipsOn = addChain(memberAddress);

const res = await Promise.all([
membershipsOn('ethereum'),
membershipsOn('polygon'),
membershipsOn('xdai'),
]);

const members: Member[] = res.reduce(
(allMembers, networkMembers) => [...allMembers, ...networkMembers],
<Member[]>[],
);

return members;
};
1 change: 1 addition & 0 deletions packages/backend/src/handlers/remote-schemas/typeDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const typeDefs = gql`
version: String
totalShares: String!
totalLoot: String!
chain: String!
}
type Member {
Expand Down
15 changes: 11 additions & 4 deletions packages/backend/src/lib/daoHausClient.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { GraphQLClient } from 'graphql-request';

import { CONFIG } from '../config';
import { getSdk } from './autogen/daohaus-sdk';
import { getSdk, Sdk } from './autogen/daohaus-sdk';

export const daoHausClient = getSdk(
new GraphQLClient(CONFIG.daoHausGraphqlURL),
);
export function clientFactory(chain: string): Sdk {
switch (chain) {
case 'polygon':
return getSdk(new GraphQLClient(CONFIG.daoHausPolygonGraphqlURL));
case 'xdai':
return getSdk(new GraphQLClient(CONFIG.daoHausXdaiGraphqlURL));
default:
return getSdk(new GraphQLClient(CONFIG.daoHausGraphqlURL));
}
}
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2096,6 +2096,7 @@ type Member {
}

type Moloch {
chain: String!
id: ID!
summoner: String!
title: String
Expand Down

0 comments on commit 0b3b254

Please sign in to comment.