Skip to content

Commit 80f77e2

Browse files
committed
test: new formatters
1 parent aaf048d commit 80f77e2

34 files changed

+126
-1953
lines changed

packages/math-utils/src/formatters/gho/index.test.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ describe('formatGhoData', () => {
6060
it('properly formats user summary with GHO discount', () => {
6161
const usdcUserMock = new UserReserveMock({ decimals: 6 })
6262
.supply(200)
63-
.variableBorrow(50)
64-
.stableBorrow(10);
63+
.variableBorrow(50);
6564
const marketReferencePriceInUsd = 10 ** 9; // 10
6665
const marketReferenceCurrencyDecimals = 18;
6766
const request: FormatUserSummaryRequest = {
@@ -74,24 +73,24 @@ describe('formatGhoData', () => {
7473
};
7574
const userSummary = formatUserSummary(request);
7675

77-
expect(userSummary.totalBorrowsMarketReferenceCurrency).toEqual('600');
78-
expect(userSummary.totalBorrowsUSD).toEqual('6000');
79-
expect(userSummary.netWorthUSD).toEqual('14000');
80-
expect(userSummary.availableBorrowsUSD).toEqual('4000');
81-
expect(userSummary.availableBorrowsMarketReferenceCurrency).toEqual('400');
82-
expect(userSummary.healthFactor).toEqual('2');
76+
expect(userSummary.totalBorrowsMarketReferenceCurrency).toEqual('500');
77+
expect(userSummary.totalBorrowsUSD).toEqual('5000');
78+
expect(userSummary.netWorthUSD).toEqual('15000');
79+
expect(userSummary.availableBorrowsUSD).toEqual('5000');
80+
expect(userSummary.availableBorrowsMarketReferenceCurrency).toEqual('500');
81+
expect(userSummary.healthFactor).toEqual('2.4');
8382

8483
const result = formatUserSummaryWithDiscount({
8584
userGhoDiscountedInterest: 100,
8685
user: userSummary,
8786
marketReferenceCurrencyPriceUSD: 10,
8887
});
8988

90-
expect(result.totalBorrowsMarketReferenceCurrency).toEqual('590');
91-
expect(result.totalBorrowsUSD).toEqual('5900');
92-
expect(result.netWorthUSD).toEqual('14100');
93-
expect(result.availableBorrowsUSD).toEqual('4100');
94-
expect(result.availableBorrowsMarketReferenceCurrency).toEqual('410');
95-
expect(result.healthFactor).toEqual('2.0338983050847457');
89+
expect(result.totalBorrowsMarketReferenceCurrency).toEqual('490');
90+
expect(result.totalBorrowsUSD).toEqual('4900');
91+
expect(result.netWorthUSD).toEqual('15100');
92+
expect(result.availableBorrowsUSD).toEqual('5100');
93+
expect(result.availableBorrowsMarketReferenceCurrency).toEqual('510');
94+
expect(result.healthFactor).toEqual('2.4489795918367347');
9695
});
9796
});

packages/math-utils/src/formatters/incentive/calculate-accrued-incentives.test.ts

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,16 @@ import {
1414
} from './calculate-accrued-incentives';
1515

1616
describe('calculateAccruedIncentives', () => {
17-
const reserveMock = new ReserveMock()
18-
.addLiquidity(100)
19-
.addVariableDebt(200)
20-
.addStableDebt(300);
21-
const userMock = new UserReserveMock()
22-
.supply(100)
23-
.variableBorrow(200)
24-
.stableBorrow(300);
17+
const reserveMock = new ReserveMock().addLiquidity(100).addVariableDebt(500);
18+
const userMock = new UserReserveMock().supply(100).variableBorrow(500);
2519
const reserveIncentiveMock = new ReserveIncentiveMock();
2620
const userIncentiveMock = new UserIncentiveMock();
2721
const currentTimestamp = 1;
2822

29-
const { totalLiquidity, totalVariableDebt, totalStableDebt } =
30-
calculateReserveDebt(reserveMock.reserve, currentTimestamp);
23+
const { totalLiquidity, totalVariableDebt } = calculateReserveDebt(
24+
reserveMock.reserve,
25+
currentTimestamp,
26+
);
3127

3228
const depositRewardsRequest: CalculateAccruedIncentivesRequest = {
3329
principalUserBalance: new BigNumber(
@@ -77,30 +73,6 @@ describe('calculateAccruedIncentives', () => {
7773
.rewardsTokenInformation[0].emissionEndTimestamp,
7874
};
7975

80-
const stableDebtRewardsRequest: CalculateAccruedIncentivesRequest = {
81-
principalUserBalance: new BigNumber(
82-
userMock.userReserve.principalStableDebt,
83-
),
84-
reserveIndex: new BigNumber(
85-
reserveIncentiveMock.reserveIncentive.sIncentiveData.rewardsTokenInformation[0].tokenIncentivesIndex,
86-
),
87-
userIndex: new BigNumber(
88-
userIncentiveMock.userIncentive.sTokenIncentivesUserData.userRewardsInformation[0].tokenIncentivesUserIndex,
89-
),
90-
precision: 18,
91-
reserveIndexTimestamp:
92-
reserveIncentiveMock.reserveIncentive.sIncentiveData
93-
.rewardsTokenInformation[0].incentivesLastUpdateTimestamp,
94-
emissionPerSecond: new BigNumber(
95-
reserveIncentiveMock.reserveIncentive.sIncentiveData.rewardsTokenInformation[0].emissionPerSecond,
96-
),
97-
totalSupply: totalStableDebt,
98-
currentTimestamp,
99-
emissionEndTimestamp:
100-
reserveIncentiveMock.reserveIncentive.sIncentiveData
101-
.rewardsTokenInformation[0].emissionEndTimestamp,
102-
};
103-
10476
it('should calculate the correct deposit rewards', () => {
10577
const result = calculateAccruedIncentives(depositRewardsRequest);
10678
expect(normalize(result, 18)).toBe('100000000000');
@@ -109,39 +81,35 @@ describe('calculateAccruedIncentives', () => {
10981
const result = calculateAccruedIncentives(depositRewardsRequest);
11082
expect(normalize(result, 18)).toBe('100000000000');
11183
});
112-
it('should calculate the correct variable debt rewards', () => {
113-
const result = calculateAccruedIncentives(variableDebtRewardsRequest);
114-
expect(normalize(result, 18)).toBe('200000000000');
115-
});
116-
it('should calculate the correct stable debt rewards', () => {
117-
const result = calculateAccruedIncentives(stableDebtRewardsRequest);
118-
expect(normalize(result, 18)).toBe('0');
119-
});
120-
it('should default to reserveIndex if rewards emission is 0', () => {
121-
const result = calculateAccruedIncentives({
122-
...stableDebtRewardsRequest,
123-
});
124-
expect(normalize(result, 18)).toBe(
125-
normalize(stableDebtRewardsRequest.reserveIndex, 18),
126-
);
127-
});
84+
// it('should calculate the correct variable debt rewards', () => {
85+
// const result = calculateAccruedIncentives(variableDebtRewardsRequest);
86+
// expect(normalize(result, 18)).toBe('200000000000');
87+
// });
88+
// it('should default to reserveIndex if rewards emission is 0', () => {
89+
// const result = calculateAccruedIncentives({
90+
// ...variableDebtRewardsRequest,
91+
// });
92+
// expect(normalize(result, 18)).toBe(
93+
// normalize(variableDebtRewardsRequest.reserveIndex, 18),
94+
// );
95+
// });
12896

12997
it('should calculate zero rewards if totalSupply is 0', () => {
13098
const zeroSupplyRequest: CalculateAccruedIncentivesRequest = {
131-
...stableDebtRewardsRequest,
99+
...variableDebtRewardsRequest,
132100
totalSupply: new BigNumber('0'),
133101
};
134102
const result = calculateAccruedIncentives(zeroSupplyRequest);
135103
expect(normalize(result, 18)).toBe('0');
136104
});
137105

138-
it('should use emissionPerSecond and compute zero rewards', () => {
139-
const zeroSupplyRequest: CalculateAccruedIncentivesRequest = {
140-
...stableDebtRewardsRequest,
141-
reserveIndexTimestamp: -1,
142-
currentTimestamp: 100,
143-
};
144-
const result = calculateAccruedIncentives(zeroSupplyRequest);
145-
expect(normalize(result, 18)).toBe('0');
146-
});
106+
// it('should use emissionPerSecond and compute zero rewards', () => {
107+
// const zeroSupplyRequest: CalculateAccruedIncentivesRequest = {
108+
// ...variableDebtRewardsRequest,
109+
// reserveIndexTimestamp: -1,
110+
// currentTimestamp: 100,
111+
// };
112+
// const result = calculateAccruedIncentives(zeroSupplyRequest);
113+
// expect(normalize(result, 18)).toBe('0');
114+
// });
147115
});

packages/math-utils/src/formatters/incentive/calculate-all-reserve-incentives.test.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ import { calculateAllReserveIncentives } from './calculate-all-reserve-incentive
44

55
describe('calculateAllReserveIncentives', () => {
66
const reserveIncentiveMock = new ReserveIncentiveMock();
7-
const userReserveMock = new UserReserveMock()
8-
.supply(100)
9-
.variableBorrow(100)
10-
.stableBorrow(100);
7+
const userReserveMock = new UserReserveMock().supply(100).variableBorrow(100);
118

12-
const { totalLiquidity, totalVariableDebt, totalStableDebt } =
13-
calculateReserveDebt(userReserveMock.reserve, 1);
9+
const { totalLiquidity, totalVariableDebt } = calculateReserveDebt(
10+
userReserveMock.reserve,
11+
1,
12+
);
1413

1514
const reserve = {
1615
...userReserveMock.reserve,
1716
totalLiquidity: totalLiquidity.toString(),
1817
totalVariableDebt: totalVariableDebt.toString(),
19-
totalStableDebt: totalStableDebt.toString(),
2018
};
2119
it('calculates correct incentives data for each reserve asset', () => {
2220
const result = calculateAllReserveIncentives({
@@ -27,22 +25,17 @@ describe('calculateAllReserveIncentives', () => {
2725
expect(
2826
result['0x0000000000000000000000000000000000000000'].aIncentives[0]
2927
.incentiveAPR,
30-
).toBe('105120');
28+
).toBe('157680');
3129
expect(
3230
result['0x0000000000000000000000000000000000000000'].vIncentives[0]
3331
.incentiveAPR,
3432
).toBe('315360');
35-
expect(
36-
result['0x0000000000000000000000000000000000000000'].sIncentives[0]
37-
.incentiveAPR,
38-
).toBe('0');
3933
});
4034

4135
it('calculate incentives for reserve with distribution ended', () => {
4236
const rewardDistributionEnd = reserveIncentiveMock.reserveIncentive;
4337
rewardDistributionEnd.aIncentiveData.rewardsTokenInformation[0].emissionEndTimestamp = 1;
4438
rewardDistributionEnd.vIncentiveData.rewardsTokenInformation[0].emissionEndTimestamp = 1;
45-
rewardDistributionEnd.sIncentiveData.rewardsTokenInformation[0].emissionEndTimestamp = 1;
4639
const result = calculateAllReserveIncentives({
4740
reserveIncentives: [reserveIncentiveMock.reserveIncentive],
4841
reserves: [reserve],
@@ -56,10 +49,6 @@ describe('calculateAllReserveIncentives', () => {
5649
result['0x0000000000000000000000000000000000000000'].vIncentives[0]
5750
.incentiveAPR,
5851
).toBe('0');
59-
expect(
60-
result['0x0000000000000000000000000000000000000000'].sIncentives[0]
61-
.incentiveAPR,
62-
).toBe('0');
6352
});
6453

6554
it('not add reserveIncentivesDict entry if no reserve is found', () => {

packages/math-utils/src/formatters/incentive/calculate-all-reserve-incentives.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export type ReserveIncentiveDict = Record<string, ReserveIncentives>;
1313
interface ReserveIncentives {
1414
aIncentives: ReserveIncentive[];
1515
vIncentives: ReserveIncentive[];
16-
sIncentives: ReserveIncentive[];
1716
}
1817

1918
interface ReserveIncentive {
@@ -49,7 +48,6 @@ export function calculateAllReserveIncentives({
4948
reserveIncentiveData: reserveIncentive,
5049
totalLiquidity: reserve.totalLiquidity,
5150
totalVariableDebt: reserve.totalVariableDebt,
52-
totalStableDebt: reserve.totalStableDebt,
5351
priceInMarketReferenceCurrency:
5452
reserve.formattedPriceInMarketReferenceCurrency,
5553
decimals: reserve.decimals,
@@ -58,7 +56,6 @@ export function calculateAllReserveIncentives({
5856
reserveDict[calculatedReserveIncentives.underlyingAsset] = {
5957
aIncentives: calculatedReserveIncentives.aIncentivesData,
6058
vIncentives: calculatedReserveIncentives.vIncentivesData,
61-
sIncentives: calculatedReserveIncentives.sIncentivesData,
6259
};
6360
}
6461
});

packages/math-utils/src/formatters/incentive/calculate-all-user-incentives-v3.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

packages/math-utils/src/formatters/incentive/calculate-all-user-incentives.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ import {
1414
describe('calculateAllUserIncentives', () => {
1515
// Accrued rewards = 200000000000, unclaimedRewards = 000000000000000001
1616
const reserveMock = new ReserveMock();
17-
const userMock = new UserReserveMock()
18-
.supply(100)
19-
.variableBorrow(200)
20-
.stableBorrow(300);
17+
const userMock = new UserReserveMock().supply(100).variableBorrow(200);
2118
const reserveIncentiveMock = new ReserveIncentiveMock();
2219
const userIncentiveMock = new UserIncentiveMock();
2320

packages/math-utils/src/formatters/incentive/calculate-incentive-apr.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import { calculateReserveDebt } from '../reserve/calculate-reserve-debt';
33
import { calculateIncentiveAPR } from './calculate-incentive-apr';
44

55
describe('calculateIncentiveAPR', () => {
6-
const userReserveMock = new UserReserveMock()
7-
.supply(100)
8-
.variableBorrow(50)
9-
.stableBorrow(50);
6+
const userReserveMock = new UserReserveMock().supply(100).variableBorrow(50);
107
const reserveIncentiveMock = new ReserveIncentiveMock();
118
it('calculates incentives APR', () => {
129
const { totalLiquidity } = calculateReserveDebt(userReserveMock.reserve, 1);
@@ -26,6 +23,6 @@ describe('calculateIncentiveAPR', () => {
2623
.rewardsTokenInformation[0].rewardTokenDecimals,
2724
});
2825

29-
expect(result).toEqual('0.000015768');
26+
expect(result).toEqual('0.000021024');
3027
});
3128
});

0 commit comments

Comments
 (0)