Skip to content

Commit 46cb52e

Browse files
authoredAug 21, 2024··
Merge pull request #149 from lidofinance/feature/si-1559-apr-percent-in-rewards
apr percent in rewards

File tree

5 files changed

+149
-132
lines changed

5 files changed

+149
-132
lines changed
 

‎packages/sdk/CHANGELOG.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
# 3.4.0
2+
3+
## SDK
4+
5+
### Fixed
6+
7+
- `apr` in `getRewardsFromChain` and `getRewardsFromSubgraph` is now in percents e.g 3.14 and not 0.314
8+
- package is build with ts@5.4.5 with changes in bundle
9+
- `LidoSDKApr.calculateAprFromRebaseEvent` has increased precision
10+
11+
## Playground
12+
13+
### Fixed
14+
15+
- updated version of `reef-knot` package with `wagmi@2`
16+
17+
# 3.3.0
18+
19+
No changes
20+
121
# 3.2.2
222

323
## SDK
@@ -7,8 +27,6 @@
727
- fixed edge-case in `withdraw.views.findCheckpointHints` where last finalized request would fail assertion with `Cannot find hints for unfinalized request...`
828
- subsequently fixed same error in `withdraw.request-info`, `withdraw.claim` modules
929

10-
# 3.2.0
11-
1230
# 3.2.1
1331

1432
## SDK

‎packages/sdk/src/rewards/__tests__/__snapshots__/rewards.test.ts.snap

+114-114
Large diffs are not rendered by default.

‎packages/sdk/src/rewards/rewards.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class LidoSDKRewards extends LidoSDKModule {
228228
return {
229229
type: 'rebase',
230230
change,
231-
apr: LidoSDKApr.calculateAprFromRebaseEvent(event.args) / 100,
231+
apr: LidoSDKApr.calculateAprFromRebaseEvent(event.args),
232232
changeShares: 0n,
233233
balance: newBalance,
234234
balanceShares: prevSharesBalance,
@@ -442,7 +442,6 @@ export class LidoSDKRewards extends LidoSDKModule {
442442
const totalEther = BigInt(totalPooledEtherAfter);
443443
const totalShares = BigInt(totalSharesAfter);
444444

445-
const apr = Number(eventApr) / 100;
446445
const newBalance = sharesToSteth(
447446
prevBalanceShares,
448447
totalEther,
@@ -456,7 +455,7 @@ export class LidoSDKRewards extends LidoSDKModule {
456455
return {
457456
type: 'rebase',
458457
change,
459-
apr,
458+
apr: Number(eventApr),
460459
changeShares: 0n,
461460
balance: newBalance,
462461
balanceShares: prevBalanceShares,

‎packages/sdk/src/statistics/__tests__/stats.test.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const APR_SPEC: Array<[AprRebaseEvent, number]> = [
2121
postTotalShares: 380434280124073199943710n,
2222
postTotalEther: 381570076199165808306368n,
2323
},
24-
1.7,
24+
1.7497,
2525
],
2626
[
2727
{
@@ -31,7 +31,7 @@ const APR_SPEC: Array<[AprRebaseEvent, number]> = [
3131
postTotalShares: 380434280124073199943710n,
3232
timeElapsed: 96768n,
3333
},
34-
1.7,
34+
1.7918,
3535
],
3636
[
3737
{
@@ -41,7 +41,7 @@ const APR_SPEC: Array<[AprRebaseEvent, number]> = [
4141
postTotalShares: 380434280124073199943710n,
4242
timeElapsed: 188928n,
4343
},
44-
1.7,
44+
1.7613,
4545
],
4646
[
4747
{
@@ -51,7 +51,7 @@ const APR_SPEC: Array<[AprRebaseEvent, number]> = [
5151
preTotalShares: 8066681860242338824295513n,
5252
timeElapsed: 950400n,
5353
},
54-
3.8,
54+
3.8393,
5555
],
5656
[
5757
{
@@ -61,7 +61,7 @@ const APR_SPEC: Array<[AprRebaseEvent, number]> = [
6161
preTotalShares: 7381214257921691114069196n,
6262
timeElapsed: 9244800n,
6363
},
64-
3.7,
64+
3.7196,
6565
],
6666
[
6767
{
@@ -71,37 +71,37 @@ const APR_SPEC: Array<[AprRebaseEvent, number]> = [
7171
preTotalShares: 352884611916239405037988n,
7272
timeElapsed: 12009600n,
7373
},
74-
4.5,
74+
4.5775,
7575
],
7676
];
7777

7878
const APR_SPEC_BLOCK: Record<string, { block: bigint; apr: number }[]> = {
7979
'17000': [
8080
{
8181
block: 500726n,
82-
apr: 1.7,
82+
apr: 1.7265,
8383
},
8484
{
8585
block: 493967n,
86-
apr: 1.9,
86+
apr: 1.9044,
8787
},
8888
{
8989
block: 491753n,
90-
apr: 1.5,
90+
apr: 1.5673,
9191
},
9292
{
9393
block: 94120n,
94-
apr: 1.3,
94+
apr: 1.3987,
9595
},
9696

9797
{
9898
block: 103607n,
99-
apr: 6.3,
99+
apr: 6.3928,
100100
},
101101

102102
{
103103
block: 77212n,
104-
apr: 1.3,
104+
apr: 1.3269,
105105
},
106106
],
107107
};

‎packages/sdk/src/statistics/apr.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class LidoSDKApr extends LidoSDKModule {
2424
}: AprRebaseEvent): number {
2525
const preShareRate = (preTotalEther * BigInt(10 ** 27)) / preTotalShares;
2626
const postShareRate = (postTotalEther * BigInt(10 ** 27)) / postTotalShares;
27-
const mulForPrecision = 1000;
27+
const mulForPrecision = 1000000;
2828

2929
const secondsInYear = 31536000n;
3030
const userAPR =

0 commit comments

Comments
 (0)
Please sign in to comment.