Skip to content

Commit

Permalink
🎩 Merge branch develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dysbulic committed Jul 4, 2024
2 parents 70fa330 + 3ee077e commit 29240fa
Show file tree
Hide file tree
Showing 28 changed files with 244 additions and 225 deletions.
33 changes: 32 additions & 1 deletion .github/workflows/gcp-deploy-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ jobs:
GOOGLE_CAL_PROJECT_NUMBER: ${{env.GOOGLE_CAL_PROJECT_NUMBER}}
GOOGLE_CAL_CLIENT_EMAIL: ${{env.GOOGLE_CAL_CLIENT_EMAIL}}
GOOGLE_CAL_CALENDAR_ID: ${{env.GOOGLE_CAL_CALENDAR_ID}}
HASURA_HOST: ${{env.HASURA_HOST}}
HASURA_ADMIN_SECRET: ${{env.HASURA_ADMIN_SECRET}}

steps:
- name: First Interpolation of Variables
Expand All @@ -92,10 +94,12 @@ jobs:
echo "APP_ENV=production" >> $GITHUB_ENV
echo "HASURA_HOST=api.metagame.wtf" >> $GITHUB_ENV
echo "FRONTEND_URL=https://metagame.wtf" >> $GITHUB_ENV
echo "HASURA_ADMIN_SECRET=${{secrets.HASURA_PROD_SECRET}}" >> $GITHUB_ENV
else
echo "APP_ENV=test" >> $GITHUB_ENV
echo "HASURA_HOST=api-staging.metagame.wtf" >> $GITHUB_ENV
echo "FRONTEND_URL=https://test.metagame.wtf" >> $GITHUB_ENV
echo "HASURA_ADMIN_SECRET=${{secrets.HASURA_DEV_SECRET}}" >> $GITHUB_ENV
fi
- name: Those Variables May Now Be Interpolated
id: second
Expand All @@ -111,10 +115,37 @@ jobs:
echo "FRONTEND_TAG=\
${{env.DOCKER_PATH}}/frontend:${{github.ref_name}}" >> $GITHUB_ENV
hasura-metadata:
name: Update Hasura Metadata
runs-on: ubuntu-latest
needs: [env]

steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Run `hasura metadata reload` on ${{needs.env.outputs.HASURA_HOST}}
if: ${{github.ref_name == 'master'}}
uses: browniefed/hasura-runner@master
with:
args: metadata reload
env:
HASURA_ENDPOINT: https://${{needs.env.outputs.HASURA_HOST}}
HASURA_GRAPHQL_ADMIN_SECRET: ${{secrets.HASURA_PROD_SECRET}}
PATH_TO_HASURA_PROJECT_ROOT: ./hasura
- name: Run `hasura metadata reload` on ${{needs.env.outputs.HASURA_HOST}}
if: ${{github.ref_name != 'master'}}
uses: browniefed/hasura-runner@master
with:
args: metadata reload
env:
HASURA_ENDPOINT: https://${{needs.env.outputs.HASURA_HOST}}
HASURA_GRAPHQL_ADMIN_SECRET: ${{secrets.HASURA_DEV_SECRET}}
PATH_TO_HASURA_PROJECT_ROOT: ./hasura

build-frontend:
name: Build Frontend Container Image
runs-on: ubuntu-latest
needs: [env]
needs: [env, hasura-metadata]

steps:
- name: Set Up Docker Buildx
Expand Down
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
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
Loading

0 comments on commit 29240fa

Please sign in to comment.