|
| 1 | +import { Resolver, Query, Arg, Int } from 'type-graphql'; |
| 2 | +import { PnLType } from '../types'; |
| 3 | +import { PnLPerformance } from '../../performance'; |
| 4 | + |
| 5 | +@Resolver(() => PnLType) |
| 6 | +export class PnLResolver { |
| 7 | + @Query(() => [PnLType]) |
| 8 | + async getEpochLeaderboard( |
| 9 | + @Arg('chainId', () => Int) chainId: number, |
| 10 | + @Arg('address', () => String) address: string, |
| 11 | + @Arg('epochId', () => String) epochId: string |
| 12 | + ): Promise<PnLType[]> { |
| 13 | + try { |
| 14 | + const pnlPerformance = PnLPerformance.getInstance(); |
| 15 | + const pnlData = await pnlPerformance.getEpochPnLs( |
| 16 | + chainId, |
| 17 | + address, |
| 18 | + parseInt(epochId) |
| 19 | + ); |
| 20 | + |
| 21 | + return pnlData.map((pnl) => { |
| 22 | + return { |
| 23 | + epochId: parseInt(epochId), |
| 24 | + owner: pnl.owner, |
| 25 | + totalDeposits: pnl.totalDeposits.toString(), |
| 26 | + totalWithdrawals: pnl.totalWithdrawals.toString(), |
| 27 | + openPositionsPnL: pnl.openPositionsPnL.toString(), |
| 28 | + totalPnL: pnl.totalPnL.toString(), |
| 29 | + positions: Array.from(pnl.positionIds), |
| 30 | + positionCount: pnl.positionCount, |
| 31 | + }; |
| 32 | + }); |
| 33 | + } catch (error) { |
| 34 | + console.error('Error fetching epochs:', error); |
| 35 | + throw new Error('Failed to fetch epochs'); |
| 36 | + } |
| 37 | + } |
| 38 | +} |
0 commit comments