Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmonize p2p rate computation #1492

Merged
merged 2 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compound/lens/RatesLens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ abstract contract RatesLens is UsersLens {
// Do not take delta into account as it's already taken into account in p2pSupplyAmount & poolSupplyAmount
uint256 p2pSupplyRate = InterestRatesModel.computeP2PSupplyRatePerBlock(
InterestRatesModel.P2PRateComputeParams({
p2pRate: InterestRatesModel.computeRawP2PRatePerBlock(
p2pRate: PercentageMath.weightedAvg(
poolSupplyRate,
poolBorrowRate,
marketParams.p2pIndexCursor
Expand Down Expand Up @@ -289,7 +289,7 @@ abstract contract RatesLens is UsersLens {
// Do not take delta into account as it's already taken into account in p2pBorrowAmount & poolBorrowAmount
uint256 p2pBorrowRate = InterestRatesModel.computeP2PBorrowRatePerBlock(
InterestRatesModel.P2PRateComputeParams({
p2pRate: InterestRatesModel.computeRawP2PRatePerBlock(
p2pRate: PercentageMath.weightedAvg(
poolSupplyRate,
poolBorrowRate,
marketParams.p2pIndexCursor
Expand Down
17 changes: 0 additions & 17 deletions src/compound/libraries/InterestRatesModel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,6 @@ library InterestRatesModel {
}
}

/// @notice Computes and returns the raw peer-to-peer rate per block of a market given the pool rates.
/// @param _poolSupplyRate The pool supply rate per block.
/// @param _poolBorrowRate The pool borrow rate per block.
/// @param _p2pIndexCursor The market's p2p index cursor.
/// @return The raw peer-to-peer rate per block, without reserve factor, without delta.
function computeRawP2PRatePerBlock(
uint256 _poolSupplyRate,
uint256 _poolBorrowRate,
uint256 _p2pIndexCursor
) internal pure returns (uint256) {
return
((MAX_BASIS_POINTS - _p2pIndexCursor) *
_poolSupplyRate +
_p2pIndexCursor *
_poolBorrowRate) / MAX_BASIS_POINTS;
}

/// @notice Computes and returns the peer-to-peer supply rate per block of a market given its parameters.
/// @param _params The computation parameters.
/// @return p2pSupplyRate The peer-to-peer supply rate per block.
Expand Down