-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
244 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 20 additions & 15 deletions
35
packages/backend/src/handlers/remote-schemas/resolvers/seedGraph/queries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
`; |
45 changes: 33 additions & 12 deletions
45
packages/backend/src/handlers/remote-schemas/resolvers/seedGraph/resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
})); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.