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

fix: fixes after ChainSec and ABDK audits #152

Merged
merged 55 commits into from
Nov 4, 2023
Merged

fix: fixes after ChainSec and ABDK audits #152

merged 55 commits into from
Nov 4, 2023

Conversation

lekhovitsky
Copy link
Collaborator

@lekhovitsky lekhovitsky commented Oct 27, 2023

In this PR:

  • CreditManagerV3, CreditFacadeV3:
    • allow immediate withdrawals via withdrawCollateral in multicall
    • introduce safe collateral check (all the same but uses more strict pricing strategy when evaluating collateral), activate it after immediate withdrawals or if account has enabled forbidden tokens
    • closeCreditAccount now requires account owner to repay debt via decreaseDebt and withdraw remaining funds via withdrawCollateral, the function exists primarily to return account to the factory
    • liquidateCreditAccount is reworked:
      • account remains open after liquidation with remaining funds
      • all transfers to/from liquidator are removed in favour of addCollateral and withdrawCollateral
      • liquidator now has a choice over tokens that would cover funds due to borrower (that prevents borrower from protecting against liquidation by having huge amount of illiquid token with $\mathrm{LT} = 0$ or above quota that liquidator must swap into underying in order to cover min remaining funds)
    • added externalCall and approveToken (currently without entry-points in the facade)
    • add collateralHints validation in fullCollateralCheck
  • BotListV3:
    • remove payments completely as now they can be performed via withdrawCollateral
    • bot's forbidden status is now global instead of per-manager
  • PriceOracleV3:
    • add safeConvertToUSD that for untrusted feeds uses minimum price of main and reserve feeds
  • WithdrawalManagerV3:
    • deprecated completely:
      • scheduled withdrawals removed in favour of withdrawCollateral
      • immediate withdrawals are no longer needed as blacklisted underlying can no longer block liquidation
      • WETH unwrapping is removed

lekhovitsky and others added 10 commits October 24, 2023 14:10
Now collateral check ensures that number of enabled _non-underlying_ tokens doesn't exceed the limit
Some additional `tokensToTransfer` validation is needed.

Besides, USDT credit manager doesn't fit into max contract size.
* use mapping instead of fixed-length array to store queued accounts in `AccountFactoryV3`
* ensure successor compatibility in `GearStakingV3`
* add collateral hints validation
* fix `creditAccounts(uint256 offset, uint256 limit)`
* `getLTRampParamsHash` returns `bytes32` instead of `uint256`
* tiny performance improvements
* add some missing events and comments
lekhovitsky and others added 19 commits October 28, 2023 11:44
* refactor liquidation
* fix credit logic library (namely, interest accrual functions when debt is 0)
* fix tests related to account closure
`liquidateCreditAccount` ensures that remaining tokens balances don't increase during the multicall

`BalancesLogic` library is reworked a bit:
* it no longer mentions forbidden tokens (this is handled in the credit facade)
* `compareBalances` functions received a `greater` parameter that dictates the direction
Bot's forbidden status is now global instead of per-manager.
Due to this, it was more convenient to merge multiple mappings into a single `BotInfo` struct.

There are also minor performance improvements and bug fixes (see older version of `setBotDAOFee`).

Other changes are mostly refactoring, renaming and cosmetics.
@0xmikko 0xmikko merged commit 605e89d into main Nov 4, 2023
2 checks passed
Copy link

github-actions bot commented Nov 4, 2023

🎉 This PR is included in version 1.44.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lekhovitsky lekhovitsky deleted the audits-fixes branch November 5, 2023 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants