Skip to content

Commit 4b4304f

Browse files
authored
fix: gho user data (#615)
* fix: gho user data * fix: test * fix: rename vars, comments
1 parent afa7d8e commit 4b4304f

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ describe('formatGhoData', () => {
3636
expect(result.userGhoDiscountPercent).toEqual(0.1);
3737
expect(result.userGhoAvailableToBorrowAtDiscount).toEqual(10000);
3838
expect(result.userDiscountTokenBalance).toEqual(100);
39-
expect(result.userGhoBorrowBalance).toEqual(1.1000000063419584);
40-
expect(result.userDiscountedGhoInterest).toEqual(0.9000000570776255);
39+
expect(result.userGhoBorrowBalance).toEqual(1.9000000570776256);
40+
expect(result.userDiscountedGhoInterest).toEqual(0.1000000063419584);
4141
});
4242

4343
it('calculates the amount of GHO available to borrow at discount', () => {
@@ -53,8 +53,8 @@ describe('formatGhoData', () => {
5353
expect(result.userGhoDiscountPercent).toEqual(0.1);
5454
expect(result.userGhoAvailableToBorrowAtDiscount).toEqual(0);
5555
expect(result.userDiscountTokenBalance).toEqual(0.1);
56-
expect(result.userGhoBorrowBalance).toEqual(1.1000000063419584);
57-
expect(result.userDiscountedGhoInterest).toEqual(0.9000000570776255);
56+
expect(result.userGhoBorrowBalance).toEqual(1.9000000570776256);
57+
expect(result.userDiscountedGhoInterest).toEqual(0.1000000063419584);
5858
});
5959

6060
it('properly formats user summary with GHO discount', () => {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,30 @@ export function formatGhoUserData({
122122
userGhoAvailableToBorrowAtDiscount = 0;
123123
}
124124

125-
const userBalancePreDiscount = getCompoundedBalance({
125+
const balance = getCompoundedBalance({
126126
principalBalance: ghoUserData.userGhoScaledBorrowBalance,
127127
reserveIndex: ghoReserveData.ghoCurrentBorrowIndex,
128128
reserveRate: ghoReserveData.ghoBaseVariableBorrowRate,
129129
lastUpdateTimestamp: Number(ghoReserveData.ghoReserveLastUpdateTimestamp),
130130
currentTimestamp,
131131
});
132-
const accruedInterest = userBalancePreDiscount.minus(
132+
const balanceIncrease = balance.minus(
133133
rayMul(
134134
ghoUserData.userGhoScaledBorrowBalance,
135135
ghoUserData.userPreviousGhoBorrowIndex,
136136
),
137137
);
138-
const discount = accruedInterest.multipliedBy(
139-
1 - Number(normalize(ghoUserData.userGhoDiscountPercent, 4)),
140-
);
141-
const userBorrowBalance = userBalancePreDiscount.minus(discount);
138+
const discountedAmount = balanceIncrease
139+
.multipliedBy(ghoUserData.userGhoDiscountPercent)
140+
.dividedBy(10000); // discount is in basis points
141+
const userBorrowBalance = balance.minus(discountedAmount);
142142
return {
143143
userGhoDiscountPercent: Number(
144144
normalize(ghoUserData.userGhoDiscountPercent, 4),
145145
),
146146
userDiscountTokenBalance: formattedUserDiscountTokenBalance,
147147
userGhoBorrowBalance: Number(normalize(userBorrowBalance, 18)),
148-
userDiscountedGhoInterest: Number(normalize(discount, 18)),
148+
userDiscountedGhoInterest: Number(normalize(discountedAmount, 18)),
149149
userGhoAvailableToBorrowAtDiscount,
150150
};
151151
}

0 commit comments

Comments
 (0)