Skip to content

Commit

Permalink
Add annual/monthly rewards calculation (#1862)
Browse files Browse the repository at this point in the history
Add expectedMonthlyRewards and expectedAnnualRewards in wei to Native Staking Transaction Confirmation View
  • Loading branch information
hectorgomezv authored Aug 27, 2024
1 parent 109d153 commit a0aef80
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export class NativeStakingDepositConfirmationView
@ApiProperty()
value: number;

@ApiProperty()
expectedAnnualReward: number;

@ApiProperty()
expectedMonthlyReward: number;

@ApiProperty()
tokenInfo: TokenInfo;

Expand All @@ -62,6 +68,8 @@ export class NativeStakingDepositConfirmationView
monthlyNrr: number;
annualNrr: number;
value: number;
expectedAnnualReward: number;
expectedMonthlyReward: number;
tokenInfo: TokenInfo;
}) {
this.method = args.method;
Expand All @@ -74,6 +82,8 @@ export class NativeStakingDepositConfirmationView
this.monthlyNrr = args.monthlyNrr;
this.annualNrr = args.annualNrr;
this.value = args.value;
this.expectedAnnualReward = args.expectedAnnualReward;
this.expectedMonthlyReward = args.expectedMonthlyReward;
this.tokenInfo = args.tokenInfo;
}
}
11 changes: 11 additions & 0 deletions src/routes/transactions/transactions-view.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,15 @@ describe('TransactionsViewController tests', () => {
dedicatedStakingStats.gross_apy.last_30d *
(1 - +deployment.product_fee!),
value: Number(value),
expectedMonthlyReward:
((dedicatedStakingStats.gross_apy.last_30d *
(1 - +deployment.product_fee!)) /
12) *
Number(value),
expectedAnnualReward:
dedicatedStakingStats.gross_apy.last_30d *
(1 - +deployment.product_fee!) *
Number(value),
tokenInfo: {
address: NULL_ADDRESS,
decimals: chain.nativeCurrency.decimals,
Expand Down Expand Up @@ -734,6 +743,8 @@ describe('TransactionsViewController tests', () => {
dedicatedStakingStats.gross_apy.last_30d *
(1 - +deployment.product_fee!),
value: 0, // defaults to 0 if not provided in the request
expectedMonthlyReward: 0, // 0 as value is 0
expectedAnnualReward: 0, // 0 as value is 0
tokenInfo: {
address: NULL_ADDRESS,
decimals: chain.nativeCurrency.decimals,
Expand Down
5 changes: 4 additions & 1 deletion src/routes/transactions/transactions-view.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,13 @@ export class TransactionsViewService {
isConfirmed: false,
depositExecutionDate: null,
});
const value = args.value ? Number(args.value) : 0;
return new NativeStakingDepositConfirmationView({
method: args.dataDecoded.method,
parameters: args.dataDecoded.parameters,
value: args.value ? Number(args.value) : 0,
value,
expectedMonthlyReward: depositInfo.monthlyNrr * value,
expectedAnnualReward: depositInfo.annualNrr * value,
...depositInfo,
});
}
Expand Down

0 comments on commit a0aef80

Please sign in to comment.