import { SwapHistoryItem } from '../../types'; import { splitAddress } from './utils'; export const ORDER_FILLED_HISTORY_QUERY = `query swapV1Histories($limit: Int, $offset: Int, $address: Bytes!) { swapV1Histories( first: $limit skip: $offset orderBy: createdAt orderDirection: desc where: {swapper: $address} ) { id reactor token { id } swapper { id name } amount outputs { id token { id } amount recipient { id name } } createdAt txHash } }`; export interface OrderFilledHistoryEntity { swapV1Histories: { id: string; reactor: string; token: { id: string; }; swapper: { id: string; name: string; }; amount: string; outputs: { id: string; token: { id: string; }; amount: string; recipient: { id: string; name: string; }; }[]; createdAt: string; txHash: string; }[]; } export function transform( entities: OrderFilledHistoryEntity ): SwapHistoryItem[] { return entities.swapV1Histories.map((entity) => ({ id: entity.id, reactor: entity.reactor, token: entity.token.id, swapper: entity.swapper.id, swapperName: entity.swapper.name || splitAddress(entity.swapper.id), amount: BigInt(entity.amount), outputs: entity.outputs.map((output) => ({ id: output.id, token: output.token.id, amount: BigInt(output.amount), recipient: output.recipient.id, recipientName: output.recipient.name || splitAddress(output.recipient.id), })), createdAt: Number(entity.createdAt), txHash: entity.txHash, })); }