Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

Commit 622a800

Browse files
Merge pull request #1267 from morpho-dao/fix/aave-v2-lens-negative-p2p-rate
fix(aave-v2)!: fix p2p rate computation of the lens
2 parents 8669ade + 10c30e4 commit 622a800

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

contracts/aave-v2/lens/RatesLens.sol

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,13 @@ abstract contract RatesLens is UsersLens {
213213
// Do not take delta into account as it's already taken into account in p2pSupplyAmount & poolSupplyAmount
214214
uint256 p2pSupplyRate = InterestRatesModel.computeP2PSupplyRatePerYear(
215215
InterestRatesModel.P2PRateComputeParams({
216-
p2pRate: PercentageMath.weightedAvg(
217-
poolSupplyRate,
218-
poolBorrowRate,
219-
market.p2pIndexCursor
220-
),
216+
p2pRate: poolBorrowRate < poolSupplyRate
217+
? poolBorrowRate
218+
: PercentageMath.weightedAvg(
219+
poolSupplyRate,
220+
poolBorrowRate,
221+
market.p2pIndexCursor
222+
),
221223
poolRate: poolSupplyRate,
222224
poolIndex: poolSupplyIndex,
223225
p2pIndex: p2pSupplyIndex,
@@ -268,11 +270,13 @@ abstract contract RatesLens is UsersLens {
268270
// Do not take delta into account as it's already taken into account in p2pBorrowAmount & poolBorrowAmount
269271
uint256 p2pBorrowRate = InterestRatesModel.computeP2PBorrowRatePerYear(
270272
InterestRatesModel.P2PRateComputeParams({
271-
p2pRate: PercentageMath.weightedAvg(
272-
poolSupplyRate,
273-
poolBorrowRate,
274-
market.p2pIndexCursor
275-
),
273+
p2pRate: poolBorrowRate < poolSupplyRate
274+
? poolBorrowRate
275+
: PercentageMath.weightedAvg(
276+
poolSupplyRate,
277+
poolBorrowRate,
278+
market.p2pIndexCursor
279+
),
276280
poolRate: poolBorrowRate,
277281
poolIndex: poolBorrowIndex,
278282
p2pIndex: p2pBorrowIndex,
@@ -325,11 +329,9 @@ abstract contract RatesLens is UsersLens {
325329
poolBorrowRate = reserve.currentVariableBorrowRate;
326330

327331
Types.Market memory market = morpho.market(_poolToken);
328-
uint256 p2pRate = PercentageMath.weightedAvg(
329-
poolSupplyRate,
330-
poolBorrowRate,
331-
market.p2pIndexCursor
332-
);
332+
uint256 p2pRate = poolBorrowRate < poolSupplyRate
333+
? poolBorrowRate
334+
: PercentageMath.weightedAvg(poolSupplyRate, poolBorrowRate, market.p2pIndexCursor);
333335

334336
Types.Delta memory delta = morpho.deltas(_poolToken);
335337

0 commit comments

Comments
 (0)