-
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.
fixing the passthrough for the new SEED subgraph 🥩
- Loading branch information
Showing
16 changed files
with
123 additions
and
143 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
31 changes: 27 additions & 4 deletions
31
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,23 +1,46 @@ | ||
import { Maybe } from '@metafam/utils'; | ||
|
||
import { seedGraphClient } from '../../../../lib/seedGraphClient.js'; | ||
|
||
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 (await res.account?.balances) ?? null; | ||
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 = async ( | ||
_: unknown, | ||
{ limit }: { limit: number }, | ||
) => { | ||
const res = await seedGraphClient.GetTopPSeedHolders({ | ||
const { tokenBalances } = await seedGraphClient.GetTopPSeedHolders({ | ||
limit: limit || 50, | ||
}); | ||
|
||
return res.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
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
Oops, something went wrong.