Skip to content

Commit a1ab68b

Browse files
authored
fix: gho debt amount (#2346)
1 parent dfa50cc commit a1ab68b

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"test:coverage": "jest --coverage"
3232
},
3333
"dependencies": {
34-
"@aave/contract-helpers": "1.31.1",
35-
"@aave/math-utils": "1.31.1",
34+
"@aave/contract-helpers": "1.32.1",
35+
"@aave/math-utils": "1.32.1",
3636
"@bgd-labs/aave-address-book": "4.10.0",
3737
"@emotion/cache": "11.10.3",
3838
"@emotion/react": "11.10.4",

src/hooks/app-data-provider/useAppDataProvider.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2+
ComputedUserReserve,
23
FormattedGhoReserveData,
34
FormattedGhoUserData,
45
formatUserSummaryWithDiscount,
56
USD_DECIMALS,
67
UserReserveData,
78
} from '@aave/math-utils';
9+
import { AaveV3Ethereum } from '@bgd-labs/aave-address-book';
810
import { formatUnits } from 'ethers/lib/utils';
911
import React, { PropsWithChildren, useContext } from 'react';
1012
import { EmodeCategory } from 'src/helpers/types';
@@ -140,9 +142,42 @@ export const AppDataProvider: React.FC<PropsWithChildren> = ({ children }) => {
140142
formatUnits(baseCurrencyData.marketReferenceCurrencyPriceInUsd, USD_DECIMALS)
141143
),
142144
});
145+
146+
const userGhoReserve = user.userReservesData.find(
147+
(r) => r.reserve.underlyingAsset === AaveV3Ethereum.ASSETS.GHO.UNDERLYING.toLowerCase()
148+
);
149+
150+
if (!userGhoReserve) {
151+
throw new Error('GHO reserve not found in user reserves data');
152+
}
153+
154+
const mergeUserReserves = (reserve: ComputedUserReserve<FormattedReservesAndIncentives>) => {
155+
if (reserve.underlyingAsset !== AaveV3Ethereum.ASSETS.GHO.UNDERLYING.toLowerCase()) {
156+
return reserve;
157+
}
158+
159+
if (reserve.variableBorrows === '0') {
160+
return reserve;
161+
}
162+
163+
// This amount takes into account the discount applied on the accrued interest.
164+
const userGhoDebtBalance = formattedGhoUserData.userGhoBorrowBalance.toString();
165+
166+
// Merge with the user reserves so the correct debt balance can be shown throughout the app.
167+
return {
168+
...reserve,
169+
variableBorrows: userGhoDebtBalance,
170+
variableBorrowsUSD: userGhoDebtBalance,
171+
totalBorrowsUSD: userGhoDebtBalance,
172+
totalBorrows: userGhoDebtBalance,
173+
totalBorrowsMarketReferenceCurrency: userGhoDebtBalance,
174+
};
175+
};
176+
143177
user = {
144178
...user,
145179
...userSummaryWithDiscount,
180+
userReservesData: user.userReservesData.map(mergeUserReserves),
146181
};
147182
}
148183
}

src/hooks/pool/useUserYield.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const useUserYields = (
155155
) => {
156156
return formatUserYield(formattedPoolReserves, undefined, undefined, user, marketData.market);
157157
};
158-
if (GHO_MINTING_MARKETS.includes(marketData.marketTitle))
158+
if (GHO_MINTING_MARKETS.includes(marketData.market))
159159
return combineQueries(
160160
[
161161
elem,

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
# yarn lockfile v1
33

44

5-
"@aave/contract-helpers@1.31.1":
6-
version "1.31.1"
7-
resolved "https://registry.yarnpkg.com/@aave/contract-helpers/-/contract-helpers-1.31.1.tgz#e0464847f18b7daa063cd5f1a1926c4b7ffce767"
8-
integrity sha512-68/RIxOSZXpAJ0CbzN25tPDGF0QUoVbJQ6c7UDtA1hT2aL5g06URqHKhdIg1+Jvnz4VU8Qu0YYC26F5K+lVUcQ==
5+
"@aave/contract-helpers@1.32.1":
6+
version "1.32.1"
7+
resolved "https://registry.yarnpkg.com/@aave/contract-helpers/-/contract-helpers-1.32.1.tgz#ad3e216118f282f450b7ab160bd270930ccf5fa4"
8+
integrity sha512-iYkopRnzbfnW7Pxa/qNmqVJVSCWKqF14FNK9SKpmLAkndH8P0UZqSkIdcnvW/ekNx6cyGIc506gKc00j5OnegQ==
99
dependencies:
1010
isomorphic-unfetch "^3.1.0"
1111

12-
"@aave/math-utils@1.31.1":
13-
version "1.31.1"
14-
resolved "https://registry.yarnpkg.com/@aave/math-utils/-/math-utils-1.31.1.tgz#f465a316c1b59b75b112b772236118541e14b716"
15-
integrity sha512-thdudjGLygOhvDlhhndhSZjVcwglWfYROv1z6qfx9c4LsyiVITAxfz1FLUXbjEOI3kirHitl060Ng4rNuYjT1Q==
12+
"@aave/math-utils@1.32.1":
13+
version "1.32.1"
14+
resolved "https://registry.yarnpkg.com/@aave/math-utils/-/math-utils-1.32.1.tgz#9cd4bb9343f2fabb078b6ca61b5845c7044fe643"
15+
integrity sha512-uLjwGNEOilWWguW7CX6Dwsk9uP4aT9HmOCzXpHqDrPbR2oGSLV8BlvHWx/8wzY9Cdt5Jr4ofP0vm/Xs4lrgDNg==
1616

1717
"@adobe/css-tools@^4.0.1":
1818
version "4.4.1"

0 commit comments

Comments
 (0)