diff --git a/src/app.module.ts b/src/app.module.ts index c9d6cd9..d37f629 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -67,6 +67,7 @@ import { RsethPagingController } from './controller/paging/rseth.controller'; provide: APP_PIPE, useClass: ValidationPipe, }, + PointsController, AppService, Points, PointsHistory, diff --git a/src/controller/nova.controller.ts b/src/controller/nova.controller.ts index 7dd2617..91a545a 100644 --- a/src/controller/nova.controller.ts +++ b/src/controller/nova.controller.ts @@ -18,6 +18,7 @@ import { NovaPointsWithoutDecimalsDto } from 'src/nova/novaPointsWithoutDecimals import { NovaService } from 'src/nova/nova.service'; import { NovaApiService, NovaPoints } from 'src/nova/novaapi.service'; import { BigNumber } from 'bignumber.js'; +import { PointsController } from './points.controller'; const options = { // how long to live in ms @@ -39,7 +40,8 @@ export class NovaController { constructor( private novaService: NovaService, - private novaApiService: NovaApiService + private novaApiService: NovaApiService, + private pointController: PointsController ) {} @Get('/points') @@ -117,6 +119,55 @@ export class NovaController { return this.getReturnData(finalPoints, finalTotalPoints, points.novaPoint); } + @Get('/points/puffer') + @ApiOperation({ summary: 'Get puffer personal points' }) + @ApiBadRequestResponse({ + description: '{ "errno": 1, "errmsg": "Service exception" }', + }) + @ApiNotFoundResponse({ + description: '{ "errno": 1, "errmsg": "not found" }', + }) + public async getNovaPufferPoints( + @Query('address', new ParseAddressPipe()) address: string, + @Query('tokenAddress', new ParseAddressPipe()) tokenAddress: string, + ): Promise { + let finalPoints: any[], finalTotalPoints: bigint; + try{ + const pointData = await this.novaService.getPoints(tokenAddress, address); + finalPoints = pointData.finalPoints; + finalTotalPoints = pointData.finalTotalPoints; + } catch (err) { + this.logger.error('Get nova all points failed', err.stack); + return SERVICE_EXCEPTION; + } + if(!finalPoints || !finalTotalPoints){ + return NOT_FOUND_EXCEPTION + } + + // Get real points. + let points: BigNumber; + try{ + const [allPufferPoints, totalPufferPoints, realPufferPoints] = this.pointController.getPointsAndTotalPoints(); + const point = allPufferPoints.filter( + (p) => p.address.toLowerCase() === tokenAddress.toLowerCase(), + ); + if (point.length === 0) { + return NOT_FOUND_EXCEPTION; + } + points = new BigNumber(point[0].points.toString()) + .multipliedBy(realPufferPoints) + .div(totalPufferPoints.toString()); + } catch (err) { + this.logger.error('Get nova real points failed', err.stack); + return SERVICE_EXCEPTION; + } + if(!points){ + return NOT_FOUND_EXCEPTION; + } + + return this.getReturnData(finalPoints, finalTotalPoints, points.toNumber()); + } + @Get('/all/points') @ApiOperation({ summary: diff --git a/src/controller/points.controller.ts b/src/controller/points.controller.ts index b3d318d..ee63ab0 100644 --- a/src/controller/points.controller.ts +++ b/src/controller/points.controller.ts @@ -435,7 +435,7 @@ export class PointsController implements OnModuleInit { return res; } - private getPointsAndTotalPoints(): [Points[], string, string]{ + public getPointsAndTotalPoints(): [Points[], string, string]{ return [this.allPoints, this.totalPoints.toString(), this.realPufferPoints]; } diff --git a/src/nova/nova.service.ts b/src/nova/nova.service.ts index 2741624..8452565 100644 --- a/src/nova/nova.service.ts +++ b/src/nova/nova.service.ts @@ -216,7 +216,7 @@ export class NovaService { new BigNumber(points.toString()) .multipliedBy(new BigNumber(realTotalPoint)) .dividedBy(new BigNumber(totalPoint.toString())) - .toFixed(18) + .toFixed(6) ); } }