import { Address } from 'viem'; import { TokenHolder } from '../../types'; import { splitAddress } from './utils'; export const TOKEN_HOLDERS_QUERY = `query tokenHolders($limit: Int, $offset: Int, $token: Bytes!) { tokenHolders( first: $limit skip: $offset orderBy: balance orderDirection: desc where: { token: $token, holder_not_in: ["0x1bdf9c09d05f660c91e334df9ce531b2b3ce6e1d","0x7bb6682bae76b8a394f9ed2812a2968182814804"] } ) { id token { id } holder { id name } balance receivedAmount sentAmount receivedCount sentCount uniqueReceivedCount uniqueSentCount createdAt updatedAt } }`; export interface TokenHoldersEntity { tokenHolders: { id: string; token: { id: string; }; holder: { id: string; name?: string; }; balance: string; receivedAmount: string; sentAmount: string; receivedCount: string; sentCount: string; uniqueReceivedCount: string; uniqueSentCount: string; createdAt: string; updatedAt: string; }[]; } export function transform(entities: TokenHoldersEntity): TokenHolder[] { return entities.tokenHolders.map((entity) => ({ id: entity.id, token: entity.token.id as Address, holderAddress: entity.holder.id as Address, holderName: entity.holder.name || splitAddress(entity.holder.id), balance: BigInt(entity.balance), createdAt: Number(entity.createdAt), updatedAt: Number(entity.updatedAt), receivedAmount: BigInt(entity.receivedAmount), sentAmount: BigInt(entity.sentAmount), receivedCount: Number(entity.receivedCount), sentCount: Number(entity.sentCount), uniqueReceivedCount: Number(entity.uniqueReceivedCount), uniqueSentCount: Number(entity.uniqueSentCount), })); }