Skip to content

Commit

Permalink
Merge pull request #1267 from morpho-dao/fix/aave-v2-lens-negative-p2…
Browse files Browse the repository at this point in the history
…p-rate

fix(aave-v2)!: fix p2p rate computation of the lens
  • Loading branch information
julien-devatom authored Sep 3, 2022
2 parents 8669ade + 10c30e4 commit 622a800
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions contracts/aave-v2/lens/RatesLens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,13 @@ abstract contract RatesLens is UsersLens {
// Do not take delta into account as it's already taken into account in p2pSupplyAmount & poolSupplyAmount
uint256 p2pSupplyRate = InterestRatesModel.computeP2PSupplyRatePerYear(
InterestRatesModel.P2PRateComputeParams({
p2pRate: PercentageMath.weightedAvg(
poolSupplyRate,
poolBorrowRate,
market.p2pIndexCursor
),
p2pRate: poolBorrowRate < poolSupplyRate
? poolBorrowRate
: PercentageMath.weightedAvg(
poolSupplyRate,
poolBorrowRate,
market.p2pIndexCursor
),
poolRate: poolSupplyRate,
poolIndex: poolSupplyIndex,
p2pIndex: p2pSupplyIndex,
Expand Down Expand Up @@ -268,11 +270,13 @@ abstract contract RatesLens is UsersLens {
// Do not take delta into account as it's already taken into account in p2pBorrowAmount & poolBorrowAmount
uint256 p2pBorrowRate = InterestRatesModel.computeP2PBorrowRatePerYear(
InterestRatesModel.P2PRateComputeParams({
p2pRate: PercentageMath.weightedAvg(
poolSupplyRate,
poolBorrowRate,
market.p2pIndexCursor
),
p2pRate: poolBorrowRate < poolSupplyRate
? poolBorrowRate
: PercentageMath.weightedAvg(
poolSupplyRate,
poolBorrowRate,
market.p2pIndexCursor
),
poolRate: poolBorrowRate,
poolIndex: poolBorrowIndex,
p2pIndex: p2pBorrowIndex,
Expand Down Expand Up @@ -325,11 +329,9 @@ abstract contract RatesLens is UsersLens {
poolBorrowRate = reserve.currentVariableBorrowRate;

Types.Market memory market = morpho.market(_poolToken);
uint256 p2pRate = PercentageMath.weightedAvg(
poolSupplyRate,
poolBorrowRate,
market.p2pIndexCursor
);
uint256 p2pRate = poolBorrowRate < poolSupplyRate
? poolBorrowRate
: PercentageMath.weightedAvg(poolSupplyRate, poolBorrowRate, market.p2pIndexCursor);

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

Expand Down

0 comments on commit 622a800

Please sign in to comment.