Skip to content

Commit c343d69

Browse files
committed
feat: add total-deposited-pool-fees endpoint
1 parent 1917a2f commit c343d69

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

packages/fasset-indexer-api/src/analytics/dashboard.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ export class DashboardAnalytics extends SharedAnalytics {
219219
return this.totalClaimedPoolFeesAt(this.orm.em.fork(), pool, user)
220220
}
221221

222+
async totalDepositedPoolFees(): Promise<FAssetValueResult> {
223+
return this.totalDepositedPoolFeesAt(this.orm.em.fork())
224+
}
225+
222226
///////////////////////////////////////////////////////////////
223227
// timespans
224228

@@ -381,6 +385,28 @@ export class DashboardAnalytics extends SharedAnalytics {
381385
return this.convertOrmResultToFAssetValueResult(enteredFees, 'fees')
382386
}
383387

388+
protected async totalDepositedPoolFeesAt(
389+
em: EntityManager, timestamp?: number
390+
): Promise<FAssetValueResult> {
391+
const mintPoolFees = await this.filterEnterOrExitQueryBy(
392+
em.createQueryBuilder(Entities.MintingExecuted, 'me')
393+
.select(['me.fasset', raw('sum(me.pool_fee_uba) as fees')])
394+
.groupBy('me.fasset'),
395+
'me', undefined, undefined, timestamp
396+
).execute() as { fasset: number, fees: bigint }[]
397+
const redeemPoolFees = await this.filterEnterOrExitQueryBy(
398+
em.createQueryBuilder(Entities.RedemptionPoolFeeMintedEvent, 'rpfme')
399+
.select(['rpfme.fasset', raw('sum(rpfme.pool_fee_uba) as fees')])
400+
.groupBy('rpfme.fasset'),
401+
'rpfme', undefined, undefined, timestamp
402+
).execute() as { fasset: number, fees: bigint }[]
403+
return this.transformFAssetValueResults(
404+
this.convertOrmResultToFAssetValueResult(mintPoolFees, 'fees'),
405+
this.convertOrmResultToFAssetValueResult(redeemPoolFees, 'fees'),
406+
add
407+
)
408+
}
409+
384410
protected async tokenSupplyAt(
385411
em: EntityManager, tokenId: number, timestamp: number, zeroAddressId: number
386412
): Promise<bigint> {

packages/fasset-indexer-api/src/controllers/dashboard.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ export class DashboardController {
133133
return apiResponse(this.service.totalClaimedPoolFees(pool, user), 200)
134134
}
135135

136+
@Get('total-deposited-pool-fees?')
137+
@ApiOperation({ summary: 'Total deposited collateral pool fees' })
138+
getTotalDepositedPoolFees(): Promise<ApiResponse<FAssetValueResult>> {
139+
return apiResponse(this.service.totalDepositedPoolFees(), 200)
140+
}
141+
136142
//////////////////////////////////////////////////////////////////////
137143
// timespan
138144

0 commit comments

Comments
 (0)