Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Quest Chains & Adding A New SEED Graph #1760

Merged
merged 2 commits into from
Jul 3, 2024
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
7 changes: 4 additions & 3 deletions packages/backend/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const config = {
},
},
'src/lib/autogen/seedgraph-sdk.ts': {
schema: 'https://api.thegraph.com/subgraphs/name/tenfinney/polygon-seeds',
// schema: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_API_TOKEN}/subgraphs/id/7LxrQZvdYe1NYKen6wuLtCaZqRTL9PhTQHRaHJPYDeCu`,
schema:
'https://api.studio.thegraph.com/query/42037/metagame-seed-pseed/version/latest',
documents: [
'src/handlers/remote-schemas/resolvers/seedGraph/**/(!(*.d)).ts',
],
Expand All @@ -75,8 +77,7 @@ const config = {
},
},
'src/lib/autogen/balancerpolygon-sdk.ts': {
schema:
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2',
schema: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_API_TOKEN}/subgraphs/id/H9oPAbXnobBRq1cB3HDmbZ1E8MWQyJYQjT1QDJMrdbNp`,
documents: [
'src/handlers/remote-schemas/resolvers/balancerPolygon/**/(!(*.d)).ts',
],
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dev": "tsc --build && concurrently 'tsc --watch --preserveWatchOutput' nodemon",
"typecheck": "tsc --noEmit --pretty",
"precommit": "yarn typecheck",
"generate": "graphql-code-generator && yarn fix:daohaus-types",
"generate": "graphql-code-generator --debug && yarn fix:daohaus-types",
"fix:daohaus-types": "export OUT=src/lib/autogen/daohaus-sdk.ts && awk '!/MolochVersion = .molochVersion/' $OUT > $OUT.filtered && mv $OUT.filtered $OUT",
"fix:lint": "eslint --fix",
"test": "jest --passWithNoTests"
Expand Down
53 changes: 33 additions & 20 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ interface IConfig {
nodeEnv: string;
graphqlURL: string;
frontendURL: string;
theGraphAPIToken?: string;
hasuraAdminURL: string;
daoHausGraphqlURL: string;
daoHausPolygonGraphqlURL: string;
daoHausXdaiGraphqlURL: string;
daoHausMetadataUrl: string;
seedGraphqlURL: string;
daoHausGraphURL: string;
daoHausPolygonGraphURL: string;
daoHausXDAIGraphURL: string;
daoHausMetadataURL: string;
seedGraphURL: string;
balancerPolygonGraphURL: string;
githubAPIToken: string;
adminKey: string;
infuraId: string;
Expand All @@ -21,7 +23,7 @@ interface IConfig {
ceramicURL: string;
}

function parseEnv<T extends string | number>(
function parseEnv<T extends string | number | undefined>(
v: string | undefined,
defaultValue: T,
): T {
Expand All @@ -46,31 +48,42 @@ export const CONFIG: IConfig = {
return 'http://localhost:8080/v1/graphql';
})(),
frontendURL: parseEnv(process.env.FRONTEND_URL, 'http://localhost:3000'),
theGraphAPIToken: parseEnv(process.env.THE_GRAPH_API_TOKEN, undefined),
hasuraAdminURL: parseEnv(
process.env.HASURA_ADMIN_URL,
'https://api.metagame.wtf/console',
),
daoHausGraphqlURL: parseEnv(
process.env.DAOHAUS_GRAPHQL_URL,
`https://gateway.thegraph.com/api/${process.env.THE_GRAPH_API_TOKEN}/subgraphs/id/9uvKq57ZiNCdT9uZ6xaFhp3yYczTM4Fgr7CJHM6tdX9H`,
),
daoHausPolygonGraphqlURL: parseEnv(
process.env.DAOHAUS_POLYGON_GRAPHQL_URL,
get daoHausGraphURL() {
return parseEnv(
process.env.DAOHAUS_GRAPH_URL,
`https://gateway.thegraph.com/api/${this.theGraphAPIToken}/subgraphs/id/9uvKq57ZiNCdT9uZ6xaFhp3yYczTM4Fgr7CJHM6tdX9H`,
);
},
daoHausPolygonGraphURL: parseEnv(
process.env.DAOHAUS_POLYGON_GRAPH_URL,
'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-matic',
),
daoHausXdaiGraphqlURL: parseEnv(
process.env.DAOHAUS_XDAI_GRAPHQL_URL,
daoHausXDAIGraphURL: parseEnv(
process.env.DAOHAUS_XDAI_GRAPH_URL,
'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-xdai',
),
daoHausMetadataUrl: parseEnv(
daoHausMetadataURL: parseEnv(
process.env.DAOHAUS_METADATA_URL,
'https://data.daohaus.club/dao',
),
// See https://thegraph.com/hosted-service/subgraph/tenfinney/polygon-seeds
seedGraphqlURL: parseEnv(
process.env.SEED_GRAPHQL_URL,
'https://api.thegraph.com/subgraphs/name/tenfinney/polygon-seeds',
),
get seedGraphURL() {
return parseEnv(
process.env.SEED_GRAPH_URL,
// 'https://api.studio.thegraph.com/query/42037/metagame-seed-pseed/version/latest',
`https://gateway-arbitrum.network.thegraph.com/api/${this.theGraphAPIToken}/subgraphs/id/7LxrQZvdYe1NYKen6wuLtCaZqRTL9PhTQHRaHJPYDeCu`,
);
},
get balancerPolygonGraphURL() {
return parseEnv(
process.env.BALANCER_POLYGON_GRAPH_URL,
`https://gateway-arbitrum.network.thegraph.com/api/${this.theGraphAPIToken}/subgraphs/id/H9oPAbXnobBRq1cB3HDmbZ1E8MWQyJYQjT1QDJMrdbNp`,
);
},
githubAPIToken: parseEnv(process.env.GITHUB_API_TOKEN, ''),
adminKey: parseEnv(
process.env.HASURA_GRAPHQL_ADMIN_SECRET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const addChain = (memberAddress: string) => async (chain: string) => {

const metadataForDaos = await Promise.all(
members.map(async ({ moloch: { id } }) => {
const response = await fetch(`${CONFIG.daoHausMetadataUrl}/${id}`);
const response = await fetch(`${CONFIG.daoHausMetadataURL}/${id}`);
const metadataArr = response.ok
? ((await response.json()) as DaoMetadata[])
: [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import { gql } from 'graphql-request';

export const GetTokenBalances = gql`
export const GetTokenBalances = /* GraphQL */ `
query GetTokenBalances($address: ID!) {
userToken(id: $address) {
account(id: $address) {
id
seedBalance
pSeedBalance
balances {
amount
token {
symbol
}
}
}
}
`;

export const GetTopPSeedHoldersQuery = gql`
export const GetTopPSeedHoldersQuery = /* GraphQL */ `
query GetTopPSeedHolders($limit: Int) {
userTokens(
orderBy: pSeedBalance
tokenBalances(
orderBy: amount
orderDirection: desc
where: {
pSeedBalance_gt: "0"
# filter out this contract address
address_not: "0xbaf60086da36033b458b892e2432958e219f4ed6"
account_not_in: [
"0x012546d756867d4a88cd3322bbb72d787e49ebf3"
"0xba12222222228d8ba445958a75a0704d566bf2c8"
]
token_: { id: "0x8a8fcd351ed553fc75aecbc566a32f94471f302e" }
}
first: $limit
) {
id
seedBalance
pSeedBalance
account {
id
}
amount
}
}
`;
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
import { Maybe } from '@metafam/utils';

import { seedGraphClient } from '../../../../lib/seedGraphClient.js';
import { QueryResolvers, TokenBalances } from '../../autogen/types.js';

export const getTokenBalances: QueryResolvers['getTokenBalances'] = async (
_,
{ address },
export type Balances = {
id: string;
SEED: number;
pSEED: number;
};

const e18ToFloat = (e18: string | bigint) =>
// 4 decimal points
Number(BigInt(e18) / BigInt(1e14)) / 1e4;

export const getTokenBalances = async (
_: unknown,
{ address }: { address: string },
) => {
if (!address) return null;
const res = await seedGraphClient.GetTokenBalances({
const { account } = await seedGraphClient.GetTokenBalances({
address: address.toLowerCase(),
});

return res.userToken as TokenBalances;
if (!account) return null;
return Object.fromEntries(
account.balances
.map((balance) => [
balance.token.symbol.replace(/seed/i, 'SEED'),
e18ToFloat(balance.amount),
])
.concat([['id', account.id]]),
) as Balances;
};

export const getTopPSeedHolders: QueryResolvers['getTopPSeedHolders'] = async (
_,
{ limit },
export const getTopPSeedHolders = async (
_: unknown,
{ limit }: { limit: number },
) => {
const holdersResult = await seedGraphClient.GetTopPSeedHolders({
const { tokenBalances } = await seedGraphClient.GetTopPSeedHolders({
limit: limit || 50,
});

return holdersResult.userTokens as Array<TokenBalances>;
return tokenBalances.map(({ amount, account: { id } }) => ({
id,
balance: e18ToFloat(amount),
}));
};
15 changes: 9 additions & 6 deletions packages/backend/src/handlers/remote-schemas/typeDefs.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { gql } from 'graphql-request';

export const typeDefs = gql`
export const typeDefs = /* GraphQL */ `
scalar uuid

type Query {
getDaoHausMemberships(memberAddress: String): [Member!]!
getBrightIdStatus(contextId: uuid): BrightIdStatus
getTokenBalances(address: String): TokenBalances
getTopPSeedHolders(limit: Int): [TokenBalances!]
getTopPSeedHolders(limit: Int): [PSeedHolder]
getGuildDiscordRoles(guildDiscordId: String): [DiscordRole!]!
getDiscordServerMemberRoles(
guildId: uuid!
Expand Down Expand Up @@ -55,8 +53,13 @@ export const typeDefs = gql`

type TokenBalances {
id: ID!
seedBalance: String!
pSeedBalance: String!
SEED: Float!
pSEED: Float!
}

type PSeedHolder {
id: ID!
balance: Float!
}

type PSeedInfo {
Expand Down
6 changes: 2 additions & 4 deletions packages/backend/src/lib/balancerPolygonClient.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { GraphQLClient } from 'graphql-request';

import { CONFIG } from '../config.js';
import { getSdk } from './autogen/balancerpolygon-sdk.js';

const balancerPolygonGraphqlURL =
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2';

export const balancerPolygonGraphClient = getSdk(
new GraphQLClient(balancerPolygonGraphqlURL),
new GraphQLClient(CONFIG.balancerPolygonGraphURL),
);
9 changes: 5 additions & 4 deletions packages/backend/src/lib/daoHausClient.ts
Copy link
Contributor

@Innkeeping Innkeeping Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you remove then add the identical thing?

Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import { CONFIG } from '../config.js';
import { getSdk, Sdk } from './autogen/daohaus-sdk.js';

const clients = new Map([
['polygon', new GraphQLClient(CONFIG.daoHausPolygonGraphqlURL)],
['xdai', new GraphQLClient(CONFIG.daoHausXdaiGraphqlURL)],
['ethereum', new GraphQLClient(CONFIG.daoHausGraphqlURL)],
['polygon', new GraphQLClient(CONFIG.daoHausPolygonGraphURL)],
['xdai', new GraphQLClient(CONFIG.daoHausXDAIGraphURL)],
['ethereum', new GraphQLClient(CONFIG.daoHausGraphURL)],
]);

export function getClient(chain: string): Sdk {
const gqlClient = clients.get(chain);
if (!gqlClient)
if (!gqlClient) {
throw new Error(
`The '${chain}' chain is unrecognized, unable to create GQL Client`,
);
}

return getSdk(gqlClient);
}
2 changes: 1 addition & 1 deletion packages/backend/src/lib/seedGraphClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { GraphQLClient } from 'graphql-request';
import { CONFIG } from '../config.js';
import { getSdk } from './autogen/seedgraph-sdk.js';

export const seedGraphClient = getSdk(new GraphQLClient(CONFIG.seedGraphqlURL));
export const seedGraphClient = getSdk(new GraphQLClient(CONFIG.seedGraphURL));
5 changes: 1 addition & 4 deletions packages/web/components/MegaMenu/XPSeedsBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ export const XPSeedsBalance: React.FC<Props> = ({ totalXP }) => {
fontSize={['sm', 'xs']}
fontWeight="bold"
>
{parseInt(
amountToDecimal(pSeedBalance || '0', Constants.PSEED_DECIMALS),
10,
).toLocaleString()}
{pSeedBalance?.toFixed(0).toLocaleString() ?? '¿?'}
</Text>
</HStack>
</Tooltip>
Expand Down
4 changes: 2 additions & 2 deletions packages/web/components/Patron/Join/PerksGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@metafam/ds';
import type { Maybe } from '@metafam/utils';
import BlueArrow from 'assets/patron/blue-arrow.webp';
import { PlayerRank_Enum, TokenBalancesFragment } from 'graphql/autogen/types';
import { PlayerRank_Enum, PSeedHolder } from 'graphql/autogen/types';
import {
getLeagueCount,
getLeagueCutoff,
Expand Down Expand Up @@ -149,7 +149,7 @@ const PerksHeader = ({ title, count, pSeeds, amountUsd }: PerksProps) => {

type Props = {
pSeedPrice: Maybe<number>;
pSeedHolders: TokenBalancesFragment[];
pSeedHolders: Array<PSeedHolder>;
};

const PerksGrid: React.FC<Props> = ({ pSeedPrice, pSeedHolders }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/web/components/Patron/Join/RankedLeagues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Maybe } from '@metafam/utils';
import { LeagueCardItem } from 'components/Patron/Join/LeagueCardItem';
import { PerksCard } from 'components/Patron/Join/PerksCard';
import { PerksHeader } from 'components/Patron/Join/PerksHeader';
import { PlayerRank_Enum, TokenBalancesFragment } from 'graphql/autogen/types';
import { PlayerRank_Enum, PSeedHolder } from 'graphql/autogen/types';
import {
getLeagueCount,
getLeagueCutoff,
Expand Down Expand Up @@ -103,7 +103,7 @@ type PerkType = {

type Props = {
pSeedPrice: Maybe<number>;
pSeedHolders: TokenBalancesFragment[];
pSeedHolders: Array<PSeedHolder>;
};

export const RankedLeagues: React.FC<Props> = ({
Expand Down
5 changes: 3 additions & 2 deletions packages/web/graphql/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ export const QuestCompletionFragment = /* GraphQL */ `

export const TokenBalancesFragment = /* GraphQL */ `
fragment TokenBalancesFragment on TokenBalances {
address: id
pSeedBalance
id
pSEED
SEED
}
`;

Expand Down
Loading
Loading