Skip to content

Commit

Permalink
Resolved the issue of incorrect PufferPoint calculations in LayerBank.
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zklink committed Apr 14, 2024
1 parent bbd158c commit 87b0f54
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { RsethPagingController } from './controller/paging/rseth.controller';
provide: APP_PIPE,
useClass: ValidationPipe,
},
PointsController,
AppService,
Points,
PointsHistory,
Expand Down
53 changes: 52 additions & 1 deletion src/controller/nova.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,7 +40,8 @@ export class NovaController {

constructor(
private novaService: NovaService,
private novaApiService: NovaApiService
private novaApiService: NovaApiService,
private pointController: PointsController
) {}

@Get('/points')
Expand Down Expand Up @@ -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<NovaPointsWithoutDecimalsDto> {
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:
Expand Down
2 changes: 1 addition & 1 deletion src/controller/points.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
2 changes: 1 addition & 1 deletion src/nova/nova.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class NovaService {
new BigNumber(points.toString())
.multipliedBy(new BigNumber(realTotalPoint))
.dividedBy(new BigNumber(totalPoint.toString()))
.toFixed(18)
.toFixed(6)
);
}
}

0 comments on commit 87b0f54

Please sign in to comment.