-
Notifications
You must be signed in to change notification settings - Fork 4
feat: solana balances #19
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,8 @@ const commonFields = { | |
| transaction: { type: new GraphQLNonNull(GraphQLString) }, | ||
| } | ||
|
|
||
| export const ERC20TransferEvent = new GraphQLObjectType({ | ||
| name: 'ERC20TransferEvent', | ||
| export const TransferEvent = new GraphQLObjectType({ | ||
| name: 'TransferEvent', | ||
| fields: { | ||
| ...commonFields, | ||
| from: { type: new GraphQLNonNull(GraphQLString) }, | ||
|
|
@@ -27,17 +27,37 @@ export const ERC20TransferEvent = new GraphQLObjectType({ | |
| }, | ||
| }) | ||
|
|
||
| export const ERC20TransferEventList = new GraphQLList(ERC20TransferEvent) | ||
| export const TransferEventList = new GraphQLList(TransferEvent) | ||
|
|
||
| export const ERC20Balance = new GraphQLObjectType({ | ||
| name: 'ERC20Balance', | ||
| export const Balance = new GraphQLObjectType({ | ||
| name: 'Balance', | ||
| fields: { | ||
| account: { type: new GraphQLNonNull(GraphQLString) }, | ||
| balance: { type: new GraphQLNonNull(GraphQLBigNumber) }, | ||
| balanceNum: { type: GraphQLFloat }, | ||
| }, | ||
| }) | ||
|
|
||
| export const ERC20BalanceList = new GraphQLList(ERC20Balance) | ||
| export const BalanceList = new GraphQLList(Balance) | ||
|
|
||
| export const types = [ERC20TransferEvent, ERC20Balance] | ||
| export const SolanaBalance = new GraphQLObjectType({ | ||
| name: 'SolanaBalance', | ||
| fields: { | ||
| account: { type: new GraphQLNonNull(GraphQLString) }, | ||
| owner: { type: new GraphQLNonNull(GraphQLString) }, | ||
|
||
| balance: { type: new GraphQLNonNull(GraphQLBigNumber) }, | ||
| balanceNum: { type: GraphQLFloat }, | ||
| }, | ||
| }) | ||
|
|
||
| export const SolanaBalanceList = new GraphQLList(SolanaBalance) | ||
|
|
||
| export const Snapshot = new GraphQLObjectType({ | ||
| name: 'Snapshot', | ||
| fields: { | ||
| timestamp: { type: new GraphQLNonNull(GraphQLString) }, | ||
| balances: { type: new GraphQLNonNull(SolanaBalanceList) }, | ||
| }, | ||
| }) | ||
|
|
||
| export const types = [TransferEvent, Balance, Snapshot] | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ export enum BalanceDALIndex { | |
|
|
||
| const accountKey = { | ||
| get: (e: Balance) => e.account, | ||
| length: EntityStorage.EthereumAddressLength, | ||
| length: EntityStorage.AddressLength, | ||
| } | ||
|
|
||
| const blockchainKey = { | ||
|
|
@@ -49,7 +49,7 @@ const mapValueFn = async (value: any) => { | |
|
|
||
| export function createBalanceDAL(path: string): BalanceStorage { | ||
| return new EntityStorage<Balance>({ | ||
| name: 'erc20_balance', | ||
| name: 'balance', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we are storing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The snapshot taken is stored on the snapshot dal |
||
| path, | ||
| key: [blockchainKey, accountKey], | ||
| indexes: [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { EntityStorage } from '@aleph-indexer/core' | ||
| import { Snapshot } from '../types.js' | ||
|
|
||
| export type SnapshotStorage = EntityStorage<Snapshot> | ||
|
|
||
| const timestampKey = { | ||
| get: (e: Snapshot) => e.timestamp, | ||
| length: EntityStorage.TimestampLength, | ||
| } | ||
|
|
||
| export function createSnapshotDAL(path: string): SnapshotStorage { | ||
| return new EntityStorage<Snapshot>({ | ||
| name: 'snapshot', | ||
| path, | ||
| key: [timestampKey], | ||
| }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be still a ERC20Balance, as we have a Solana specific implementation down below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
balance query also can return solana balances from snapshot db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now where the problem in this discussion lies.
What you can do is make
Balancea union of two types,ERC20BalanceandSolanaBalance:This will allow you to keep all the relevant info for Solana-related balances, while not having to deal with undefined values for ERC20Balances. This style also comes in handy later, when you might want to filter balances based on which type they are.