Skip to content

Commit

Permalink
fixed merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Harvey committed Jan 2, 2024
2 parents 842f90e + e39f93a commit dcae802
Show file tree
Hide file tree
Showing 10 changed files with 425 additions and 29 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/slither.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ jobs:
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Install and set solc version
run: |
pip install solc-select && solc-select install 0.8.18 && solc-select use 0.8.18
Expand Down Expand Up @@ -46,7 +51,7 @@ jobs:

- name: Analyze Libraries
run: |
slither src/libraries/external/.
slither src/libraries/external/
continue-on-error: true
id: libraries-analyzer

Expand Down
1 change: 1 addition & 0 deletions src/base/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
* @dev increment `latestBurnEpoch` counter
* @dev update `reserveAuction.latestBurnEventEpoch` and burn event `timestamp` state
* @dev === Reverts on ===
* @dev no reserves to claim `NoReserves()`
* @dev 5 days not passed `ReserveAuctionTooSoon()`
* @dev unsettled liquidation `AuctionActive()`
* @dev === Emit events ===
Expand Down
6 changes: 0 additions & 6 deletions src/interfaces/pool/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ interface IERC20Token {
function balanceOf(address account) external view returns (uint256);
function burn(uint256 amount) external;
function decimals() external view returns (uint8);
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}

/// @dev `ERC721` token interface.
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/external/KickerActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ library KickerActions {
error AuctionActive();
error BorrowerOk();
error InsufficientLiquidity();
error InsufficientLP();
error InvalidAmount();
error NoReserves();
error PriceBelowLUP();
error ReserveAuctionTooSoon();
Expand Down Expand Up @@ -210,6 +208,7 @@ library KickerActions {
* @dev update `reserveAuction.kicked` timestamp state
* @dev === Reverts on ===
* @dev no reserves to claim `NoReserves()`
* @dev 5 days not passed `ReserveAuctionTooSoon()`
* @dev === Emit events ===
* @dev - `KickReserveAuction`
*/
Expand Down
11 changes: 3 additions & 8 deletions src/libraries/external/LenderActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,7 @@ library LenderActions {
// revert if (due to rounding) the awarded LP is 0
if (bucketLP_ == 0) revert InsufficientLP();

uint256 unscaledAmount = Maths.wdiv(addedAmount_, bucketScale);
// revert if unscaled amount is 0
if (unscaledAmount == 0) revert InvalidAmount();

Deposits.unscaledAdd(deposits_, params_.index, unscaledAmount);
Deposits.unscaledAdd(deposits_, params_.index, Maths.wdiv(addedAmount_, bucketScale));

// update lender LP
Buckets.addLenderLP(bucket, bankruptcyTime, msg.sender, bucketLP_);
Expand Down Expand Up @@ -227,6 +223,7 @@ library LenderActions {
* @dev dust amount `DustAmountNotExceeded()`
* @dev invalid index `InvalidIndex()`
* @dev no LP awarded in to bucket `InsufficientLP()`
* @dev calculated unscaled amount to move is 0 `InvalidAmount()`
* @dev === Emit events ===
* @dev - `BucketBankruptcy`
* @dev - `MoveQuoteToken`
Expand Down Expand Up @@ -735,7 +732,7 @@ library LenderActions {
* @dev update `values` array state
* @dev === Reverts on ===
* @dev no `LP` redeemed `InsufficientLP()`
* @dev no unscaled amount removed` `InvalidAmount()`
* @dev no unscaled amount removed `InvalidAmount()`
* @return removedAmount_ Amount of scaled deposit removed.
* @return redeemedLP_ Amount of bucket `LP` corresponding for calculated scaled deposit amount.
* @return unscaledRemaining_ Amount of unscaled deposit remaining.
Expand Down Expand Up @@ -824,8 +821,6 @@ library LenderActions {

// revert if (due to rounding) required LP is 0
if (redeemedLP_ == 0) revert InsufficientLP();
// revert if calculated amount of quote to remove is 0
if (unscaledRemovedAmount == 0) revert InvalidAmount();

// update FenwickTree
Deposits.unscaledRemove(deposits_, params_.index, unscaledRemovedAmount);
Expand Down
13 changes: 8 additions & 5 deletions src/libraries/external/SettlerActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ library SettlerActions {
vars.hpbUnscaledDeposit -= vars.unscaledDeposit;

// remove amount to settle debt from bucket (could be entire deposit or only the settled debt)
Deposits.unscaledRemove(deposits_, vars.index, vars.unscaledDeposit);
// when unscaledDeposit == 0 the amount of debt is very small and worth forgiving versus having settle revert
if (vars.unscaledDeposit != 0) Deposits.unscaledRemove(deposits_, vars.index, vars.unscaledDeposit);

// check if bucket healthy - set bankruptcy if collateral is 0 and entire deposit was used to settle and there's still LP
if (vars.hpbCollateral == 0 && vars.hpbUnscaledDeposit == 0 && vars.hpbLP != 0) {
Expand Down Expand Up @@ -476,19 +477,21 @@ library SettlerActions {
// no remaining debt to forgive
remainingt0Debt_ = 0;

uint256 depositUsed = Maths.wdiv(debt, scale);
depositRemaining = unscaledDeposit - depositUsed;
uint256 depositUsed = Maths.min(Maths.wdiv(debt, scale), unscaledDeposit);
depositRemaining = unscaledDeposit - depositUsed;

// Remove deposit used to forgive bad debt from bucket
Deposits.unscaledRemove(deposits_, index, depositUsed);
// when depositUsed == 0 the amount of debt is very small and worth forgiving versus having settle revert
if (depositUsed != 0) Deposits.unscaledRemove(deposits_, index, depositUsed);

// 2) loan debt to settle exceeds bucket deposit, bucket deposit is the constraint
} else {
// subtract from remaining debt the corresponding t0 amount of deposit
remainingt0Debt_ -= Maths.floorWdiv(depositToRemove, inflator_);

// Remove all deposit from bucket
Deposits.unscaledRemove(deposits_, index, unscaledDeposit);
// when unscaledDeposit == 0 the amount of debt is very small and worth forgiving versus having settle revert
if (unscaledDeposit != 0) Deposits.unscaledRemove(deposits_, index, unscaledDeposit);
}

Bucket storage hpbBucket = buckets_[index];
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/external/TakerActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ library TakerActions {
error InsufficientCollateral();
error InvalidAmount();
error NoAuction();
error NoReserves();
error NoReservesAuction();
error ReserveAuctionTooSoon();

/***************************/
/*** External Functions ***/
Expand Down Expand Up @@ -273,7 +271,7 @@ library TakerActions {
* @dev === Write state ===
* @dev decrement `reserveAuction.unclaimed` accumulator
* @dev === Reverts on ===
* @dev not kicked or `72` hours didn't pass `NoReservesAuction()`
* @dev not kicked or `72` hours passed `NoReservesAuction()`
* @dev 0 take amount or 0 AJNA burned `InvalidAmount()`
* @dev === Emit events ===
* @dev - `ReserveAuction`
Expand Down Expand Up @@ -592,6 +590,8 @@ library TakerActions {
* @dev - increment `bucket.collateral` and `bucket.lps` accumulator
* @dev === Emit events ===
* @dev - `BucketTakeLPAwarded`
* @dev === Reverts on ===
* @dev calculated unscaled amount to remove is 0 `InvalidAmount()`
* @param auctions_ Struct for pool auctions state.
* @param deposits_ Struct for pool deposits state.
* @param buckets_ Struct for pool buckets state.
Expand Down
19 changes: 19 additions & 0 deletions src/libraries/internal/Deposits.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ library Deposits {
/// @dev Max index supported in the `Fenwick` tree
uint256 internal constant SIZE = 8192;

/**************/
/*** Errors ***/
/**************/

// See `IPoolErrors` for descriptions
error InvalidAmount();

/**
* @notice Increase a value in the FenwickTree at an index.
* @dev Starts at leaf/target and moved up towards root
* @dev === Reverts on ===
* @dev unscaled amount to add is 0 `InvalidAmount()`
* @param deposits_ Deposits state struct.
* @param index_ The deposit index.
* @param unscaledAddAmount_ The unscaled amount to increase deposit by.
Expand All @@ -32,6 +41,10 @@ library Deposits {
uint256 index_,
uint256 unscaledAddAmount_
) internal {

// revert if 0 amount is added.
if (unscaledAddAmount_ == 0) revert InvalidAmount();

// price buckets are indexed starting at 0, Fenwick bit logic is more elegant starting at 1
++index_;

Expand Down Expand Up @@ -289,6 +302,8 @@ library Deposits {
/**
* @notice Decrease a node in the `FenwickTree` at an index.
* @dev Starts at leaf/target and moved up towards root.
* @dev === Reverts on ===
* @dev unscaled amount to remove is 0 `InvalidAmount()`
* @param deposits_ Deposits state struct.
* @param index_ The deposit index.
* @param unscaledRemoveAmount_ Unscaled amount to decrease deposit by.
Expand All @@ -298,6 +313,10 @@ library Deposits {
uint256 index_,
uint256 unscaledRemoveAmount_
) internal {

// revert if 0 amount is removed.
if (unscaledRemoveAmount_ == 0) revert InvalidAmount();

// price buckets are indexed starting at 0, Fenwick bit logic is more elegant starting at 1
++index_;

Expand Down
Loading

0 comments on commit dcae802

Please sign in to comment.