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

Replace borrow index #1375

Merged
merged 4 commits into from
Nov 7, 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 contracts/compound/MatchingEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ abstract contract MatchingEngine is MorphoUtils {
if (_maxGasForMatching == 0) return (0, 0);

MatchVars memory vars;
vars.poolIndex = ICToken(_poolToken).borrowIndex();
vars.poolIndex = lastPoolIndexes[_poolToken].lastBorrowPoolIndex;
vars.p2pIndex = p2pBorrowIndex[_poolToken];
address firstPoolBorrower;
vars.gasLeftAtTheBeginning = gasleft();
Expand Down Expand Up @@ -263,7 +263,7 @@ abstract contract MatchingEngine is MorphoUtils {
if (_maxGasForMatching == 0) return 0;

UnmatchVars memory vars;
vars.poolIndex = ICToken(_poolToken).borrowIndex();
vars.poolIndex = lastPoolIndexes[_poolToken].lastBorrowPoolIndex;
vars.p2pIndex = p2pBorrowIndex[_poolToken];
address firstP2PBorrower;
uint256 remainingToUnmatch = _amount;
Expand Down
2 changes: 1 addition & 1 deletion contracts/compound/MorphoUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ abstract contract MorphoUtils is MorphoStorage {
Types.BorrowBalance memory userBorrowBalance = borrowBalanceInOf[_poolToken][_user];
return
userBorrowBalance.inP2P.mul(p2pBorrowIndex[_poolToken]) +
userBorrowBalance.onPool.mul(ICToken(_poolToken).borrowIndex());
userBorrowBalance.onPool.mul(lastPoolIndexes[_poolToken].lastBorrowPoolIndex);
}

/// @dev Returns the underlying ERC20 token related to the pool token.
Expand Down
8 changes: 4 additions & 4 deletions contracts/compound/PositionsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ contract PositionsManager is IPositionsManager, MatchingEngine {

Types.Delta storage delta = deltas[_poolToken];
SupplyVars memory vars;
vars.poolBorrowIndex = ICToken(_poolToken).borrowIndex();
vars.poolBorrowIndex = lastPoolIndexes[_poolToken].lastBorrowPoolIndex;
vars.remainingToSupply = _amount;

/// Peer-to-peer supply ///
Expand Down Expand Up @@ -381,7 +381,7 @@ contract PositionsManager is IPositionsManager, MatchingEngine {
// Borrow on pool.
if (remainingToBorrow > 0) {
borrowerBorrowBalance.onPool += remainingToBorrow.div(
ICToken(_poolToken).borrowIndex()
lastPoolIndexes[_poolToken].lastBorrowPoolIndex
); // In cdUnit.
_borrowFromPool(_poolToken, remainingToBorrow);
}
Expand Down Expand Up @@ -675,7 +675,7 @@ contract PositionsManager is IPositionsManager, MatchingEngine {
// Increase the peer-to-peer borrow delta.
if (unmatched < vars.remainingToWithdraw) {
delta.p2pBorrowDelta += (vars.remainingToWithdraw - unmatched).div(
ICToken(_poolToken).borrowIndex()
lastPoolIndexes[_poolToken].lastBorrowPoolIndex
);
emit P2PBorrowDeltaUpdated(_poolToken, delta.p2pBorrowDelta);
}
Expand Down Expand Up @@ -721,7 +721,7 @@ contract PositionsManager is IPositionsManager, MatchingEngine {
RepayVars memory vars;
vars.remainingToRepay = _amount;
vars.remainingGasForMatching = _maxGasForMatching;
vars.poolBorrowIndex = ICToken(_poolToken).borrowIndex();
vars.poolBorrowIndex = lastPoolIndexes[_poolToken].lastBorrowPoolIndex;

Types.BorrowBalance storage borrowerBorrowBalance = borrowBalanceInOf[_poolToken][
_onBehalf
Expand Down