Skip to content

Commit 397c690

Browse files
yan-manCheyenneAtapouravniculaemiguelmtzinfDhairyaSethi
authored
feat: migrate hub restore tests (#488)
* refactor: internal methods, errors, resolve tests * test: hub remove * test: debugging test_remove_all_with_interest * test: resolve test_remove_all_with_interest * test: resolve test_remove_fuzz * test: resolve test_remove_fuzz_all_liquidity_with_interest * test: test_remove_fuzz_multi_spoke_with_interest * chore: gas report * fix: hub names * chore: pr comments * chore: pr comments * test: restore test_restore_revertsWith_SurplusAmountRestored * chore: assertEq helpers * test: resolve test_restore_partial_same_block * test: resolve test_restore_revertsWith_SurplusAmountRestored_with_interest * test: resolve * test: resolve test_restore_full_amount_with_interest * test: resolve test_restore_full_amount_with_interest_and_premium * test: resolve test_restore_partial_base * test: resolve test_restore_fuzz_full_amount_with_interest * test: resolve test_restore_fuzz_full_amount_with_interest_and_premium * test: rm unused tests * test: resolve remaining restore tests * fix: rm test struct; clean up * fix: tests with premium debt, unchanged * chore: comments, rm unused * test: cleanup * test: resolve * Fix Hub Restore Tests (#629) * feat: Refactor flags (#553) * feat: remove collateral flag * feat: refactor hub flags * feat: refactor spoke flags * feat: update hub configurator * fix: check spoke active on payFee * fix: order operation nit * fix: comments * fix: nits * fix: gas reports * fix: comments * feat: keep feeReceiver active flag constant in configurator * fix: comments * fix: comments * fix: Address comments * fix: address comments * chore: gas snapshots * fix: Fix draw validation * chore: gas --------- Co-authored-by: miguelmtzinf <[email protected]> Co-authored-by: YBM <[email protected]> * feat: Allow DAO to update any user dynamic risk configuration (#564) * feat: allow dao to upd user dyn config * chore: reorder for readability * fix: pr comments * feat: Add Hub Conversion Functions (#540) * feat: Add previews for basic actions * feat: Add preview shares functions * feat: Adjust conversion functions * fix: Use preview functions in src * fix: Use preview where possible * fix: Remove using preview where unneeded * fix: Internalize previewOffset * fix: Pr comments * fix: Add natspec to _previewOffset * fix: Simplify dev comment * fix: Revert natspec change on previewOffset * fix: Rename other preview getters * fix: fix docs --------- Co-authored-by: miguelmtzinf <[email protected]> * feat: update existing dyn config (#541) * feat: update existing dyn config * wip: config tests cleanup * chore: snapshots * chore: finalise merge * fix: rename and tests * fix: revert to uint16 input, cleanup * chore: reorder * chore: finalise merge * feat: rm safeCast, resolve shadowing in tests * feat: distinguish dyn conf update with new added event * feat: rm abstraction, fix event on add reserve, natspec * fix: apply explicit rounding direction on all math operations (#543) * rft: explicit rounding * fix: round up on getUserDebtInBaseCurrency * chore: finalise merge * fix: pr comments * chore: rm dup * fix: rename wadify -> toWad, dewadify -> fromWad * feat: Add more equivalent fees calc in previewFeeShares (#458) * feat: Add more equivalent fees calc in previewFeeShares * chore: disables gas checks * tmp: skip snapshot check (revert before merging) * fix: separate impl of fee shares * test: multi-user case * fix: test * feat: underestimate treasury fees and fix tests * test: multi spoke * fix: treasury spoke tests * fix: treasury spoke tests * fix: pr comment --------- Co-authored-by: dhairya <[email protected]> Co-authored-by: YBM <[email protected]> * feat: Deficit accounting via dedicated hub method (#472) * feat: simplify restore flow (#574) * feat: simplify restore flow * feat: make restore like its now * feat: emit premium amt * fix: hub._validateRestore after accrual & before state changes * fix: settle premium debt in reportDeficit * test: _checkDeficitReportedEvents * chore: bring back test * chore: consolidate settlePremiumDebt * chore: bring back fee share comment * feat: Eliminate deficit (#583) * feat: clear deficit * fix: pr comments * chore: rename to eliminate deficit * feat: simplify restore flow (#574) * feat: simplify restore flow * feat: make restore like its now * feat: emit premium amt * fix: hub._validateRestore after accrual & before state changes * fix: settle premium debt in reportDeficit * test: _checkDeficitReportedEvents * chore: bring back test * chore: consolidate settlePremiumDebt * chore: bring back fee share comment chore: finalise merge * chore: disallow excess eliminate deficit in, reorder fn * feat: rm reserve accounting on spoke (#468) * feat: rm reserve accounting on spoke * chore: snapshots * chore: snapshot * feat: rm reserve list * chore: finalise merge * fix: rm unnecessary liquidation accounting --------- Co-authored-by: YBM <[email protected]> * feat: spoke/base minimal interfaces (#589) * feat: Transfer added shares between spokes (#590) * feat: rm reserve accounting on spoke * chore: snapshots * chore: snapshot * feat: rm reserve list * chore: finalise merge * fix: rm unnecessary liquidation accounting * feat: Initial implementation * test: Basic tests * test: Basic functionalities and reverts * fix: Address pr comments * fix: Address pr comments * fix: Remove unchecked * fix: pr comments * feat: Internal helper for transfer shares * fix: Move accrue outside helper --------- Co-authored-by: DhairyaSethi <[email protected]> Co-authored-by: YBM <[email protected]> * rft: rename, cleanup (#563) * rft: rename, cleanup * feat: supplied -> added in hub * fix: debt/borrow -> drawn; repay -> restore * feat: baseDebt/premiumDebt rename * fix: pr comments, cleanup * feat: LH -> hub; cleanup * chore: periods on natspec * chore: final clean up * fix: include deficit * fix: more renaming * fix: availableLiquidity -> liquidity * fix: clean up PremiumDelta struct * fix: debtIndex -> drawnIndex * fix: baseDebt -> drawnDebt * fix: base -> drawn; availLiq -> liq * fix: base -> drawn; clarify shares * test: hub -> hub1 * fix: ref correct input hub * fix: rename liqHub * chore: rm comment * fix: pr comments * fix: clean up, address pr comments * fix: pr comments * fix: availableliquidity -> liquidity * fix: use preview conversions * fix: link * fix: base -> drawn, clean up * feat: Pack Hub Structs (#591) * Fix: present tense on events (#595) * feat: Add Inflation Attack Protection (#588) * feat: add inflation attack protection * feat: add rounding test * fix: comments * chore: remove hub rp tests * fix: added share price calculation * fix: add cap tests * fix: comments * feat: Check existence when adding reserve (#593) * test: Add Hub Configurator Tests (#575) * feat: Remove existence check on spokes * fix: Comments * test: Can still withdraw from old fee receiver * fix: Simplify test * test: New fee receiver receiving funds * chore: Clean tests * fix: Pr comments * fix: Keep old fee receiver config * fix: Use existing fee receiver config * fix: Address pr comments * fix: Consistent fuzzing on access control tests * chore: Cleanup test comments * wip: Determine diff * fix: Names and comments * feat: Add natspec to addSpoke * fix: Address pr comments * fix: Address pr comments * feat: Pack Spoke Structs (#602) * feat: pack spoke structs * fix: comments * fix: cleanup * fix: lint * fix: small cleanup * fix: use safecast in tests * fix: lint * fix: tests cleanup * fix: comments * feat: Add remaining configurator functions (#578) * feat: add updateInterestRateData in HubConfigurator * feat: Add updateLiquiationConfig in SpokeConfigurator * feat: add updatePoisitionManager in SpokeConfigurator * fix: change prefix to add for dyn config fns * feat: add granular fns to update existing dyn config * fix: comments * fix: add missing hub configurator fns * fix: comments * feat: Add premiumDelta to Repay event (#610) * fix: Stack too deep error * style: Revert ternary condition change * fix: fee share calc (#606) * fix: fee share calc * chore: cleanup * test: more accurate accrual * chore: rename smt script * doc: AssetLogic.getFeeShares * chore: snapshot * doc: AssetLogic.getFeeShares * feat: reinvestment (adds Sweep & Reclaim on Hub) (#619) * feat: added reinvestment config vars * feat: added sweeped to the shares accounting * feat: updated addAsset() and tests * feat: implemented implemented sweep and reclaim * chore: fixed additional merge changes * feat: fixed validation on sweep and reclaim * refactor: renamed sweeped in swept * chore: removed ILiquidityHub.sol leftover from merge * feat: cleanup, events, upd borrow rate * feat: fix restore preview, minor cleanup * chore: fix failing test * feat: remove reinvestment strat from addAsset * chore: docs * test: addAsset, updateReinvestmentStrategy on configurator * chore: init tests * feat: update borrow rate on hub.refresh, more tests for hub.sweep * feat: disallow resetting reinvestment strategy if there is non zero amount reinvested * chore: napspec, error name * chore: natspec * feat: rm updateBorrowRate on hub.refreshPremium --------- Co-authored-by: [email protected] <[email protected]> * feat: Prevent Liquidations Resulting in Dust Debt (#605) * feat: initial impl of dust * test: resolve current actualDebt, with assumption of no dust * fix: refactor to minimimize internal calls; simplify testing * test: cleanup * test: dust tests * test: test_calculateActualDebtToLiquidate_fuzz_debtToCover_dust * test: dust scenario * test: test_calculateActualDebtToLiquidate_fuzz_debtToRestoreCloseFactor_dust * test: test_calculateActualDebtToLiquidate_fuzz_debtToRestoreCloseFactor_dust_totalBorrowerReserveDebt_lte_minLeftoverAmount * test: test_calculateActualDebtToLiquidate_fuzz_debtToRestoreCloseFactor_dust_revertsWith_MustNotLeaveDust * test: clean up * fix: update liquidation event * test: cleanup and dust tests * test: debug prior tests * test: resolve failing * fix: resolve remaining tests * test: initial fix for specific scenario * test: resolve LiquidationAvailableCollateralToLiquidateTest * test: fix test_calculateAvailableCollateralToLiquidate_fuzz_borrowerCollateralBalance_lt_maxCollateralToLiquidate * chore: gas report * fix: allow for debt reserve dust if collateral side is fully liq * fix: comment * test: initial dust scenarios * test: test_liquidationCall_fuzz_dust_scenario1_revertsWith_MustNotLeaveDust * test: clean up test_liquidationCall_fuzz_dust_scenario1_revertsWith_MustNotLeaveDust * test: test_liquidationCall_fuzz_dust_scenario1_revertsWith_MustNotLeaveDust_debtToRestoreCloseFactor * test: test_liquidationCall_fuzz_dust_scenario1_deficit * test: isolate test scenarios * test: deficits when debt is above the min leftover base threshold * test: reverting on dust * fix: emit reserveIds in event * tests: additional LiquidationAvailableCollateralToLiquidateTest * test: test_liquidationCall_borrowerReserveDebtThreshold_valid * fix: test_calculateAvailableCollateralToLiquidate_fuzz_borrowerCollateralBalance_lt_maxCollateralToLiquidate * test: remaining minLeftoverBase scenarios * chore: clean up, rm logs, add comments * chore: gas snapshot * fix: rm logging * chore: comments, cleanup * fix: tests * fix: comments * fix: replace assume with bound * fix: comments --------- Co-authored-by: Alexandru Niculae <[email protected]> * opt: pack drawnRate within 96 bits (#623) * opt: shrink drawn rate to 96 bits * fix: revert unneeded * chore: avoid caching if read once * feat: Add deficit and swept to IR Strategy (#624) * feat: added reinvestment config vars * feat: added sweeped to the shares accounting * feat: updated addAsset() and tests * feat: implemented implemented sweep and reclaim * chore: fixed additional merge changes * feat: fixed validation on sweep and reclaim * refactor: renamed sweeped in swept * chore: removed ILiquidityHub.sol leftover from merge * feat: cleanup, events, upd borrow rate * feat: fix restore preview, minor cleanup * chore: fix failing test * feat: remove reinvestment strat from addAsset * chore: docs * test: addAsset, updateReinvestmentStrategy on configurator * chore: init tests * feat: update borrow rate on hub.refresh, more tests for hub.sweep * feat: disallow resetting reinvestment strategy if there is non zero amount reinvested * chore: napspec, error name * chore: natspec * feat: rm updateBorrowRate on hub.refreshPremium * wip: Add swept and deficit to ir strategy * chore: fix swept test, minor cleanup * fix: Remove drawn from liquidity in tests * fix: Pr comments * fix: Change test name --------- Co-authored-by: [email protected] <[email protected]> Co-authored-by: DhairyaSethi <[email protected]> * wip: merge in main, debugging tests * wip: Fix more tests * wip: Fix tests * feat: Fix tests * fix: Restore tests --------- Co-authored-by: Alexandru-Vlad Niculae <[email protected]> Co-authored-by: miguelmtzinf <[email protected]> Co-authored-by: YBM <[email protected]> Co-authored-by: dhairya <[email protected]> Co-authored-by: miguelmtz <[email protected]> Co-authored-by: [email protected] <[email protected]> * fix: Rename variables in tests * fix: Namings * test: Paused and frozen restore cases * test: Premium deltas differing * fix: Pr comments * chore: Remove health factor tests * fix: Remove todo comments --------- Co-authored-by: Cheyenne Atapour <[email protected]> Co-authored-by: Alexandru-Vlad Niculae <[email protected]> Co-authored-by: miguelmtzinf <[email protected]> Co-authored-by: dhairya <[email protected]> Co-authored-by: miguelmtz <[email protected]> Co-authored-by: [email protected] <[email protected]>
1 parent 7d9a4aa commit 397c690

File tree

9 files changed

+855
-1594
lines changed

9 files changed

+855
-1594
lines changed

src/contracts/Hub.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,6 @@ contract Hub is IHub, AccessManaged {
610610
spoke.realizedPremium = spoke.realizedPremium.add(premium.realizedDelta).toUint128();
611611

612612
// can increase due to precision loss on premium (drawn unchanged)
613-
// todo mathematically find premium diff ceiling and replace the `2`
614613
require(asset.premium() + premiumAmount - premiumBefore <= 2, InvalidPremiumChange());
615614
}
616615

src/contracts/Spoke.sol

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ contract Spoke is ISpoke, Multicall, AccessManaged {
5858
* @param authority_ The address of the authority contract which manages permissions.
5959
*/
6060
constructor(address authority_) AccessManaged(authority_) {
61-
// todo move to `initialize` when adding upgradeability
6261
_liquidationConfig.closeFactor = Constants.HEALTH_FACTOR_LIQUIDATION_THRESHOLD;
6362
emit LiquidationConfigUpdate(_liquidationConfig);
6463
}
@@ -130,7 +129,6 @@ contract Spoke is ISpoke, Multicall, AccessManaged {
130129
uint256 reserveId,
131130
DataTypes.ReserveConfig calldata config
132131
) external restricted {
133-
// TODO: More sophisticated
134132
require(reserveId < _reserveCount, ReserveNotListed());
135133
DataTypes.Reserve storage reserve = _reserves[reserveId];
136134
_validateReserveConfig(config);
@@ -506,7 +504,6 @@ contract Spoke is ISpoke, Multicall, AccessManaged {
506504
uint256 totalDebtInBaseCurrency
507505
)
508506
{
509-
// todo separate getter with refreshed config for users trying to incrementally build hf?
510507
(
511508
userRiskPremium,
512509
avgCollateralFactor,
@@ -582,12 +579,9 @@ contract Spoke is ISpoke, Multicall, AccessManaged {
582579
// HF checked at the end of borrow action
583580
}
584581

585-
// TODO: Place this and LH equivalent in a generic logic library
586582
function _validateRepay(DataTypes.Reserve storage reserve) internal view {
587583
require(address(reserve.hub) != address(0), ReserveNotListed());
588584
require(!reserve.paused, ReservePaused());
589-
// todo validate user not trying to repay more
590-
// todo NoExplicitAmountToRepayOnBehalf
591585
}
592586

593587
/**
@@ -890,7 +884,6 @@ contract Spoke is ISpoke, Multicall, AccessManaged {
890884
);
891885
}
892886

893-
// todo optimize, merge logic duped borrow/repay, rename
894887
/**
895888
* @dev Trigger risk premium update on all drawn reserves of `user`.
896889
* @param user The address of the user whose risk premium is being updated.
@@ -905,7 +898,6 @@ contract Spoke is ISpoke, Multicall, AccessManaged {
905898
vars.reserveCount = _reserveCount;
906899
DataTypes.PositionStatus storage positionStatus = _positionStatus[user];
907900
while (vars.reserveId < vars.reserveCount) {
908-
// todo keep borrowed assets in transient storage/pass through?
909901
if (positionStatus.isBorrowing(vars.reserveId)) {
910902
DataTypes.UserPosition storage userPosition = _userPositions[user][vars.reserveId];
911903
DataTypes.Reserve storage reserve = _reserves[vars.reserveId];

src/libraries/helpers/KeyValueListInMemory.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pragma solidity ^0.8.0;
33

44
import {Arrays} from 'src/dependencies/openzeppelin/Arrays.sol';
55

6-
// todo: optimize by packing more elements each slot, keep pre-sorted
76
library KeyValueListInMemory {
87
error MaxKeySizeExceeded(uint256);
98
error MaxValueSizeExceeded(uint256);
@@ -43,7 +42,6 @@ library KeyValueListInMemory {
4342

4443
function sortByKey(List memory self) internal pure {
4544
// @dev since `key` is in the MSB, we can sort by the key by sorting the array
46-
// todo consider using Solady's quick sort implementation, it being more gas efficient (cannot use if we pack more than 1 pair per slot)
4745
Arrays.sort(self._inner, ltComparator);
4846
}
4947

src/libraries/logic/AssetLogic.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ library AssetLogic {
1818
using MathUtils for uint256;
1919
using SafeCast for uint256;
2020

21-
// todo: option for cached object
22-
2321
// drawn exchange rate does not include premium to accrue base rate separately
2422
function toDrawnAssetsUp(
2523
DataTypes.Asset storage asset,

tests/Base.t.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ abstract contract Base is Test {
170170
uint256 premium;
171171
}
172172

173+
// TODO: Seems this should be replaced with DrawnAccounting struct
174+
struct Debts {
175+
uint256 drawnDebt;
176+
uint256 premiumDebt;
177+
uint256 totalDebt;
178+
}
179+
173180
struct AssetPosition {
174181
uint256 assetId;
175182
uint256 addedShares;
@@ -1177,6 +1184,15 @@ abstract contract Base is Test {
11771184
return spoke.getUserPosition(reserveId, user);
11781185
}
11791186

1187+
function getUserDebt(
1188+
ISpoke spoke,
1189+
address user,
1190+
uint256 reserveId
1191+
) internal view returns (Debts memory data) {
1192+
(data.drawnDebt, data.premiumDebt) = spoke.getUserDebt(reserveId, user);
1193+
data.totalDebt = data.drawnDebt + data.premiumDebt;
1194+
}
1195+
11801196
function getReserveInfo(
11811197
ISpoke spoke,
11821198
uint256 reserveId

tests/unit/HealthFactor.t.sol

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)