Skip to content

Commit 1c2139a

Browse files
miguelmtzinfyan-manCheyenneAtapourDhairyaSethi
authored
Rebuild LH and BM based on last design (aave#42)
* feat: Add borrow module code * fix: clean ups * fix: Format IR * test: Add borrow simple test * refactor: rename borrow/repay methods to draw/restore * feat: incorporate hub into borrow module constructor to access it * feat: draw liquidity from BM instead of hub * refactor: directly transfer liquidity so that approval does not need resetting * refactor: remove direct call to onBorrow from hub * refactor: rename method * feat: incorporate interface * fix: fix interface with args * refactor: remove onBorrow * refactor: rename validation method fix: revert methods in bm, add method args for onBehalfOf * feat: add events for bm * fix: revert naming for bm validation * refactor: move interface files test: init mock basic bm credit line * test: add credit line mock * test: add borrow module credit line to base test * test: clean up MockBorrowModuleCreditLine * fix: resolve _accrueReserveInterest calcs * test: test_first_borrow_credit_line * test: resolve test_supply_index_increase * test: test_first_borrow_credit_line * test: init fuzz test for multiple borrow rounds with credit line * test: fuzz test for multiple draws, different IRs * refactor: add comments, re-order methods * Liquidity Hub / Borrow Module Interest Rate Integration (aave#30) * fix: comments for slope units of IR * test: credit line read IR from storage, add setter, update tests * test: incorporate default IR strategy into credit line; rename test errors library to resolve duplication * feat: incorporate IR strategy into bm * test: remove uneeded supply for credit line * fix: resolve calculations of principalBalance and totalDebt in bm * test: send credit line borrow amount to sender * test: resolve * fix: adjust getIR based on assetId, resolve debt calcs, update state in BM, adjust tests * fix: clean up updateState * refactor: set borrow rate during add reserve in bm * fix: user debt calcs * refactor: accrueInterest into updateState test: bm assertions during borrow * fix: don't separate interest from principal * comments: todo for hub * test: test_multi_borrow_credit_line * chore: remove duplicate tests; clean up failed assertion msgs * test: optimize address reference * refactor: rename method test: add assertion on reserve * refactor: move credit line tests to separate file * refactor: remove unneeded; re-order * feat: check hub liquidity, add comments * fix: resolve balance from struct in bm, clean up calcs * comment: add todo around updateState * fix: remove explicit check for balance * test: add test errors * fix: _validateSupply fix * test: add revert tests * test: move to liq hub test * test: tests for emitted events feat: indexed event args * test: bm tests for updateReserve * refactor: original bm to _accrueUserInterest in separate method * refactor: rename vars in credit line for clarity * fix: correct params for calculateCompoundedInterest * chore: clean up comments according to feedback * fix: apply changes to BM, update tests * feat: add method to update IR strategy address * refactor: move getInterestRate from governance-related * comments: notes on credit line case * comments: notes on ray for IR output * feat: update reserve total debt before updating IR * fix: remove onBehalfOf * comments: add dev comments for bps units * fix: remove calculateInterestRates from bm * feat: incorporate borrow rate into reserve struct * feat: update borrow rate on updateState * fix: remove unneeded method for static IR credit line * refactor: keep math operations consistent style * fix: address PR comment * fix: address PR comments * feat: Change basic functions for architectural update * feat: Architecture rework * feat: Change names * fix: Name changes * fix: Misc fixes * fix: Use shares for accounting * feat: Moved supply caps to be per borrow module * fix: Refactor borrow module * Resolve conflicts from Main branch (aave#43) * fix: merge main; resolve contract compile * fix: address PR comments, retain newer changes * fix: clean up comments, remove unneeded * fix: remove updateState from bm * fix: revert previous calcs for debt * chore: comment placement * fix: typo * fix: comment out previous calcs which don't apply * Implementation of Spoke/Liquidity Hub (aave#46) * fix: merge main; resolve contract compile * fix: address PR comments, retain newer changes * fix: clean up comments, remove unneeded * fix: remove updateState from bm * fix: rename borrow module to spoke * feat: skeleton for remaining methods for spoke * fix: rename event so it is consistent * feat: skeleton for method structure in spoke * feat: accounting for borrow/repay methods * feat: implement borrow to * feat: getter functions for shares/asset conversions * test: resolve compile with updated borrow input params * feat: refactor to utilize convertAssetsToShares * fix: transfer tokens to Spoke before calling supply on LH * fix: draw method abstraction onBehalfOf * feat: update ILiquidityHub, validateRepay * fix: rename file to Spoke * refactor: interface method order * feat: implement _validateSupply, pass aggregatedRiskPremium to LH * chore: add comments, move getter up * refactor: maintain consistency - validate before updating state * feat: implement draw onBehalfOf * feat: getter for up-to-date balance * feat: get updated asset balance in shares or in assets * refactor: use the shares conversion getter * refactor: move events to interface, add some todo * chore: comment placement * refactor: consistent naming conventions, data structures * chore: add todo * fix: re-arrange method order * fix: rename method, add todo * fix: split into 2 methods, rename method * fix: update state before validation, to accrue interest first * fix: onBehalfOf -> to * fix: rename method, add some todo * chore: add todo * fix: rename error msg * fix: onBehalfOf -> to * fix: Rename onBehalfOf to to * Finalize first implementation of Spoke/Liquidity Hub - resolve tests (aave#50) * chore: borrow module refs -> spoke * test: resolve test_first_supply, init SpokeTest * test: emitted Supply event * test: resolve test_first_supply * fix: resolve supply cap - on spoke level only * tes: utilize multiple spokes in LH tests as end users * test: resolve test_first_borrow * test: resolve test_revert_draw_cap_exceeded * test: resolve test_revert_draw_not_available_liquidity * test: resolve test_revert_draw_asset_not_active * test: resolve test_withdraw * test: resolve test_withdraw_more_than_supplied_reverts * test: resolve test_supply_index_increase * test: add spoke data assertions to test_withdraw * test: clean up test_first_borrow, spoke assertions * test: resolve test_fuzz_supply_events * test: assertions on draw event * test: assertion on withdraw event * test: SpokeTest test_first_supply * test: spoke test_first_borrow * test: spoke test_withdraw * chore: clean up unused tests * test: LH test_restore * test: assertion cleanup for test_restore * test: spoke test_repay * chore: clean up comments * feat: addAsset, addSpoke to LH interface * chore: add todo * fix: update terminology on utils methods * test: optimize expectEmit * fix: explicit rounding in conversion methods * test: revert expectEmits which were failing * chore: todo comment * feat: update forge-std * chore: add todo comments * test: optimize expectEmit * chore: todo comments * feat: functionality to add multiple spoke configs at once in LH * test: implement addSpokes, unit tests and events * chore: todo comments * fix: token transfer directly from user to LH via spoke during supply * fix: for restore also transfer tokens to hub directly * test: helper function for test setup and LH config * test: helper methods for init LH * fix: clean up console imports --------- Co-authored-by: DhairyaSethi <55102840+DhairyaSethi@users.noreply.github.com> --------- Co-authored-by: YBM <yan@avara.xyz> Co-authored-by: Cheyenne Atapour <cheyenneatapour@gmail.com> Co-authored-by: DhairyaSethi <55102840+DhairyaSethi@users.noreply.github.com>
1 parent f4938c6 commit 1c2139a

18 files changed

Lines changed: 1940 additions & 1245 deletions

src/contracts/BorrowModule.sol

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

src/contracts/DefaultReserveInterestRateStrategy.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ contract DefaultReserveInterestRateStrategy is IDefaultInterestRateStrategy {
4242
/// @inheritdoc IDefaultInterestRateStrategy
4343
function setInterestRateParams(uint256 assetId, InterestRateData calldata rateData) external {
4444
// TODO: Auth
45-
require(assetId != 0, Errors.INVALID_ASSET_ID);
45+
// TODO: resolve assetId, currently preventing it from being 0, but it can be equal 0 in LH
46+
// require(assetId != 0, Errors.INVALID_ASSET_ID);
4647

4748
require(
4849
rateData.optimalUsageRatio <= MAX_OPTIMAL_POINT &&
@@ -113,6 +114,9 @@ contract DefaultReserveInterestRateStrategy is IDefaultInterestRateStrategy {
113114
) external view virtual override returns (uint256) {
114115
InterestRateData memory rateData = _interestRateData[params.assetId];
115116

117+
// TODO need to ensure require(rateData.optimalUsageRatio != 0, Errors.INVALID_OPTIMAL_USAGE_RATIO);
118+
// because division by 0 occurs in the following code potentially
119+
116120
// @note This is a short circuit to allow mintable assets (ex. GHO), which by definition cannot be supplied
117121
// and thus do not use virtual underlying balances.
118122
if (!params.usingVirtualBalance) {

0 commit comments

Comments
 (0)