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

Bug fix: kickWithDeposit likely push LUP below HTP affecting healthy loans #894

Merged
merged 17 commits into from
Jun 18, 2023
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
89 changes: 42 additions & 47 deletions docs/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,27 @@

### transferLP
external libraries call:
- LenderActions.transferLP()
- LPActions.transferLP()

write state:
- LenderActions.transferLP():
- LPActions.transferLP():
- delete allowance mapping
- increment new lender.lps accumulator and lender.depositTime state
- delete old lender from bucket -> lender mapping

reverts on:
- LenderActions.transferLP():
- LPActions.transferLP():
- invalid index InvalidIndex()
- no allowance NoAllowance()

emit events:
- LenderActions.transferLP():
- LPActions.transferLP():
- TransferLP

### kick
external libraries call:
- PoolCommons.accrueInterest()
- Auctions.kick()
- KickerActions.kick()
- PoolCommons.updateInterestRate()

write state:
Expand All @@ -143,7 +143,7 @@
- Deposits.mult() (scale Fenwick tree with new interest accrued):
- update scaling array state
- increment reserveAuction.totalInterestEarned accumulator
- Auctions.kick():
- KickerActions.kick():
- _kick():
- _recordAuction():
- borrower -> liquidation mapping update
Expand All @@ -164,20 +164,20 @@
- pool inflator and inflatorUpdate state

reverts on:
- Auctions.kick():
- KickerActions.kick():
- borrower collateralized BorrowerOk()
- auction active AuctionActive()

emit events:
- Auctions.kick():
- KickerActions.kick():
- Kick
- PoolCommons.updateInterestRate():
- UpdateInterestRate

### kickWithDeposit
### lenderKick
external libraries call:
- PoolCommons.accrueInterest()
- Auctions.kickWithDeposit()
- KickerActions.lenderKick()
- PoolCommons.updateInterestRate()

write state:
Expand All @@ -186,7 +186,7 @@
- Deposits.mult() (scale Fenwick tree with new interest accrued):
- update scaling array state
- increment reserveAuction.totalInterestEarned accumulator
- Auctions.kickWithDeposit():
- KickerActions.lenderKick():
- _kick():
- _recordAuction():
- borrower -> liquidation mapping update
Expand All @@ -198,10 +198,6 @@
- Loans.remove():
- delete borrower from indices => borrower address mapping
- remove loan from loans array
- Deposits.unscaledRemove() (remove amount in Fenwick tree, from index):
- update values array state
- decrement lender.lps accumulator
- decrement bucket.lps accumulator
- increment poolBalances.t0DebtInAuction and poolBalances.t0Debt accumulators
- _updateInterestState():
- PoolCommons.updateInterestRate():
Expand All @@ -210,15 +206,14 @@
- pool inflator and inflatorUpdate state

reverts on:
- Auctions.kickWithDeposit():
- auction active AuctionActive()
- KickerActions.lenderKick():
- bucket price below current pool LUP PriceBelowLUP()
- borrower collateralized BorrowerOk()
- insuficient amount InsufficientLiquidity()

emit events:
- Auctions.kickWithDeposit():
- KickerActions.lenderKick():
- Kick
- RemoveQuoteToken
- PoolCommons.updateInterestRate():
- UpdateInterestRate

Expand All @@ -235,41 +230,41 @@

### kickReserveAuction
external libraries call:
- Auctions.kickReserveAuction()
- KickerActions.kickReserveAuction()

write state:
- Auctions.kickReserveAuction():
- KickerActions.kickReserveAuction():
- update reserveAuction.unclaimed accumulator
- update reserveAuction.kicked timestamp state
- increment latestBurnEpoch counter
- update reserveAuction.latestBurnEventEpoch and burn event timestamp state

reverts on:
- 2 weeks not passed ReserveAuctionTooSoon()
- Auctions.kickReserveAuction():
- KickerActions.kickReserveAuction():
- no reserves to claim NoReserves()

emit events:
- Auctions.kickReserveAuction():
- KickerActions.kickReserveAuction():
- KickReserveAuction


### takeReserves
external libraries call:
- Auctions.takeReserves()
- TakerActions.takeReserves()

write state:
- Auctions.takeReserves():
- TakerActions.takeReserves():
- decrement reserveAuction.unclaimed accumulator
- increment reserveAuction.totalAjnaBurned accumulator
- update burn event totalInterest and totalBurned accumulators

reverts on:
- Auctions.takeReserves():
- TakerActions.takeReserves():
- not kicked or 72 hours didn't pass NoReservesAuction()

emit events:
- Auctions.takeReserves():
- TakerActions.takeReserves():
- ReserveAuction

### stampLoan
Expand Down Expand Up @@ -387,7 +382,7 @@
- update scaling array state
- increment reserveAuction.totalInterestEarned accumulator
- BorrowerActions.drawDebt():
- Auctions._settleAuction():
- SettlerActions._settleAuction():
- _removeAuction():
- decrement kicker locked accumulator, increment kicker claimable accumumlator
- decrement auctions count accumulator
Expand Down Expand Up @@ -417,7 +412,7 @@

emit events:
- BorrowerActions.drawDebt():
- Auctions._settleAuction():
- SettlerActions._settleAuction():
- AuctionNFTSettle or AuctionSettle
- DrawDebt
- PoolCommons.updateInterestRate():
Expand All @@ -436,7 +431,7 @@
- update scaling array state
- increment reserveAuction.totalInterestEarned accumulator
- BorrowerActions.repayDebt():
- Auctions._settleAuction():
- SettlerActions._settleAuction():
- _removeAuction():
- decrement kicker locked accumulator, increment kicker claimable accumumlator
- decrement auctions count accumulator
Expand Down Expand Up @@ -466,7 +461,7 @@

emit events:
- BorrowerActions.repayDebt():
- Auctions._settleAuction:
- SettlerActions._settleAuction:
- AuctionNFTSettle or AuctionSettle
- RepayDebt
- PoolCommons.updateInterestRate():
Expand All @@ -475,7 +470,7 @@
### settle
external libraries call:
- PoolCommons.accrueInterest()
- Auctions.settlePoolDebt()
- SettlerActions.settlePoolDebt()
- PoolCommons.updateInterestRate()

write state:
Expand All @@ -484,14 +479,14 @@
- Deposits.mult() (scale Fenwick tree with new interest accrued):
- update scaling array state
- increment reserveAuction.totalInterestEarned accumulator
- Auctions.settlePoolDebt():
- SettlerActions.settlePoolDebt():
- Deposits.unscaledRemove() (remove amount in Fenwick tree, from index):
- update values array state
- Buckets.addCollateral():
- increment bucket.collateral and bucket.lps accumulator
- addLenderLP():
- increment lender.lps accumulator and lender.depositTime state
- Auctions._settleAuction():
- SettlerActions._settleAuction():
- _removeAuction():
- decrement kicker locked accumulator, increment kicker claimable accumumlator
- decrement auctions count accumulator
Expand All @@ -508,14 +503,14 @@
- pool inflator and inflatorUpdate state

reverts on:
- Auctions.settlePoolDebt():
- SettlerActions.settlePoolDebt():
- loan not kicked NoAuction()
- 72 hours didn't pass and auction still has collateral AuctionNotClearable()

emit events:
- Auctions.settlePoolDebt():
- SettlerActions.settlePoolDebt():
- Settle
- Auctions._settleAuction():
- SettlerActions._settleAuction():
- AuctionNFTSettle or AuctionSettle
- BucketBankruptcy
- PoolCommons.updateInterestRate():
Expand All @@ -524,7 +519,7 @@
### take
external libraries call:
- PoolCommons.accrueInterest()
- Auctions.take()
- TakerActions.take()
- PoolCommons.updateInterestRate()

write state:
Expand All @@ -533,7 +528,7 @@
- Deposits.mult (scale Fenwick tree with new interest accrued):
- update scaling array state
- increment reserveAuction.totalInterestEarned accumulator
- Auctions.take():
- TakerActions.take():
- _take():
- _prepareTake():
- update liquidation.alreadyTaken state
Expand All @@ -542,7 +537,7 @@
- update kicker's locked balance accumulator
- update auctions.totalBondEscrowed accumulator
- _takeLoan():
- Auctions._settleAuction():
- SettlerActions._settleAuction():
- _removeAuction():
- decrement kicker locked accumulator, increment kicker claimable accumumlator
- decrement auctions count accumulator
Expand All @@ -564,7 +559,7 @@
- pool inflator and inflatorUpdate state

reverts on:
- Auctions.take():
- TakerActions.take():
- insufficient collateral InsufficientCollateral()
- _prepareTake():
- loan is not in auction NoAuction()
Expand All @@ -573,15 +568,15 @@
- borrower debt less than pool min debt AmountLTMinDebt()

emit events:
- Auctions.take():
- TakerActions.take():
- Take
- PoolCommons.updateInterestRate():
- UpdateInterestRate

### bucketTake
external libraries call:
- PoolCommons.accrueInterest()
- Auctions.bucketTake()
- TakerActions.bucketTake()
- PoolCommons.updateInterestRate()

write state:
Expand All @@ -590,7 +585,7 @@
- Deposits.mult (scale Fenwick tree with new interest accrued):
- update scaling array state
- increment reserveAuction.totalInterestEarned accumulator
- Auctions.bucketTake():
- TakerActions.bucketTake():
- _takeBucket():
- _prepareTake():
- update liquidation.alreadyTaken state
Expand All @@ -605,7 +600,7 @@
- update values array state
- increment bucket.collateral and bucket.lps accumulator
- _takeLoan():
- Auctions._settleAuction():
- SettlerActions._settleAuction():
- _removeAuction():
- decrement kicker locked accumulator, increment kicker claimable accumumlator
- decrement auctions count accumulator
Expand All @@ -627,7 +622,7 @@
- pool inflator and inflatorUpdate state

reverts on:
- Auctions.bucketTake():
- TakerActions.bucketTake():
- insufficient collateral InsufficientCollateral()
- _prepareTake():
- loan is not in auction NoAuction()
Expand All @@ -636,7 +631,7 @@
- borrower debt less than pool min debt AmountLTMinDebt()

emit events:
- Auctions.bucketTake():
- TakerActions.bucketTake():
- _rewardBucketTake():
- BucketTakeLPAwarded
- BucketTake
Expand Down
8 changes: 4 additions & 4 deletions src/base/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
);

// update in memory pool state struct
poolState.debt = Maths.wmul(result.t0PoolDebt, poolState.inflator);
poolState.debt = result.poolDebt;
poolState.t0Debt = result.t0PoolDebt;
poolState.t0DebtInAuction += result.t0KickedDebt;

Expand All @@ -318,14 +318,14 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
* @dev increment `poolBalances.t0DebtInAuction` and `poolBalances.t0Debt` accumulators
* @dev update `t0Debt2ToCollateral` ratio, debt and collateral post action are considered 0
*/
function kickWithDeposit(
function lenderKick(
uint256 index_,
uint256 npLimitIndex_
) external override nonReentrant {
PoolState memory poolState = _accruePoolInterest();

// kick auctions
KickResult memory result = KickerActions.kickWithDeposit(
KickResult memory result = KickerActions.lenderKick(
auctions,
deposits,
buckets,
Expand All @@ -336,7 +336,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
);

// update in memory pool state struct
poolState.debt = Maths.wmul(result.t0PoolDebt, poolState.inflator);
poolState.debt = result.poolDebt;
poolState.t0Debt = result.t0PoolDebt;
poolState.t0DebtInAuction += result.t0KickedDebt;

Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/pool/commons/IPoolInternals.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ struct KickResult {
uint256 amountToCoverBond; // [WAD] amount of bond that needs to be covered
uint256 t0PoolDebt; // [WAD] t0 debt in pool after kick
uint256 t0KickedDebt; // [WAD] new t0 debt after kick
uint256 lup; // [WAD] current lup
uint256 debtPreAction; // [WAD] The amount of borrower t0 debt before kick
uint256 collateralPreAction; // [WAD] The amount of borrower collateral before kick, same as the one after kick
uint256 poolDebt; // [WAD] current debt in pool after kick
uint256 lup; // [WAD] current LUP in pool after kick
}

/// @dev Struct used to hold parameters for `SettlerAction.settlePoolDebt` action.
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/pool/commons/IPoolKickerActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ interface IPoolKickerActions {
) external;

/**
* @notice Called by lenders to liquidate the top loan using their deposits.
* @notice Called by lenders to liquidate the top loan.
* @param index_ The deposit index to use for kicking the top loan.
* @param npLimitIndex_ Index of the lower bound of `NP` tolerated when kicking the auction.
*/
function kickWithDeposit(
function lenderKick(
uint256 index_,
uint256 npLimitIndex_
) external;
Expand Down
Loading