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 rm pause #589

Merged
merged 77 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
ffbda7c
chore: naive impl
GalloDaSballo Aug 22, 2023
a3ef03e
Merge branch 'feat/spearbit-misc' into fix-rm-pause
GalloDaSballo Aug 22, 2023
4f6cbae
feat: sketch of RM checker that is synched with Liquidations and can …
GalloDaSballo Aug 22, 2023
f121c3a
chore: made function public
GalloDaSballo Aug 22, 2023
b7b3bd3
feat: call cdpManager on external interactions
GalloDaSballo Aug 22, 2023
42e42d0
feat: RECHECK - break CEI but update RM status appropriately
GalloDaSballo Aug 22, 2023
8291b06
chore: prettier
GalloDaSballo Aug 22, 2023
05e6306
fix: compilation and interfaces
GalloDaSballo Aug 22, 2023
e914069
chore: prettier
GalloDaSballo Aug 22, 2023
9c1accb
chore: comment
GalloDaSballo Aug 22, 2023
d3dc31c
feat: refactor towards CEI conformity
GalloDaSballo Aug 23, 2023
0dddcf1
feat: 15 minute delay for RM liquidations
GalloDaSballo Aug 23, 2023
0284fa9
chore: prettier
GalloDaSballo Aug 23, 2023
6ad4d60
fix: liquidation test waits for grace period
GalloDaSballo Aug 23, 2023
9a25da5
chore: dry
GalloDaSballo Aug 23, 2023
c99a3fb
fix: view
GalloDaSballo Aug 23, 2023
44e3b8f
fix failing tests by adding RM cooldown check
rayeaster Aug 23, 2023
51405e7
Merge remote-tracking branch 'ebtc/fix-rm-pause' into fix-rm-pause
rayeaster Aug 23, 2023
126dfe6
fix: dork
GalloDaSballo Aug 23, 2023
5805c1b
feat: error messages based on glass
GalloDaSballo Aug 23, 2023
66498fd
fix: test reverts as intended (fixed)
GalloDaSballo Aug 23, 2023
353bb8e
chore: prettier
GalloDaSballo Aug 23, 2023
3882997
Merge branch 'fix-rm-pause' of github.com:Badger-Finance/ebtc into fi…
GalloDaSballo Aug 23, 2023
b490484
fix: assertion
GalloDaSballo Aug 23, 2023
6b0d171
fix: CEI restored in open, adjust and close
GalloDaSballo Aug 23, 2023
7fa37da
add _waitUntilRMColldown() in BaseFixture.sol
rayeaster Aug 23, 2023
921ecab
fix prank order
rayeaster Aug 23, 2023
db9e68d
add CdpManager_RecoveryMode_Cooldown_Test.js
rayeaster Aug 23, 2023
698c87f
fix: nice error message when nothing to liquidate
GalloDaSballo Aug 23, 2023
d440d66
feat: incomplete tests for grace period spec
GalloDaSballo Aug 23, 2023
cdb19f1
chore: prettier
GalloDaSballo Aug 23, 2023
d5e6e5b
valid action test draft
Aug 24, 2023
0c3864d
feat: FSM with regards to liquidations and Grace Period
GalloDaSballo Aug 24, 2023
cededd4
chore: comment
GalloDaSballo Aug 24, 2023
0ccdd13
chore: comment on logic
GalloDaSballo Aug 24, 2023
7123cb3
feat: all external functions (except claiming fee split sync Grace Pe…
GalloDaSballo Aug 24, 2023
d7c69c5
feat: `syncPendingGlobalState` externally
GalloDaSballo Aug 24, 2023
bb3f751
chore: prettier
GalloDaSballo Aug 24, 2023
10e8c73
action tests draft
Aug 24, 2023
159e8aa
Actions that exit RM and reset flag after flag set
Aug 24, 2023
4e4617f
IRmLiquidationsChecker cleanup
Aug 24, 2023
680d8b7
add dedicated tests for RM cooldown switch
rayeaster Aug 24, 2023
dc717af
fix redemption action
Aug 24, 2023
266c079
feat: event with TCR
GalloDaSballo Aug 25, 2023
b761868
feat: redemptions are CEI compliant
GalloDaSballo Aug 25, 2023
05090a3
feat: bodged initial fix for CEI
GalloDaSballo Aug 25, 2023
ea06caf
feat: remove "training wheels" from liquidate library
GalloDaSballo Aug 25, 2023
64bd47d
chore: refactor assume to % to avoid assertion cap
GalloDaSballo Aug 25, 2023
022af5d
feat: initial progress on ensuring TCR is synched
GalloDaSballo Aug 25, 2023
47d56d4
feat: test that works (see commented code)
GalloDaSballo Aug 25, 2023
228ac0a
fix: liquidation math LG
GalloDaSballo Aug 25, 2023
4ad913e
chore: prettier
GalloDaSballo Aug 25, 2023
ef6df37
chore: prettier
GalloDaSballo Aug 25, 2023
6f37b9d
liquidation data dedup read draft
Aug 27, 2023
b3a5696
fix: test works for open adjust close
GalloDaSballo Aug 28, 2023
f612d02
fix: open CDP also tracked
GalloDaSballo Aug 28, 2023
1666667
Merge branch 'fix-rm-pause' of github.com:Badger-Finance/ebtc into fi…
GalloDaSballo Aug 28, 2023
6189138
fix: error messages
GalloDaSballo Aug 28, 2023
5e043c9
fix: convention for error messages
GalloDaSballo Aug 28, 2023
5a06b35
fix single liq path optimization
Aug 28, 2023
e36e608
lint
Aug 28, 2023
57ee143
redemptions grace period opt draft
Aug 28, 2023
2de76b2
redemption collSurplus check test shell
Aug 28, 2023
2f9bac1
clean up optimization code
Aug 28, 2023
d6d601e
add tests for redemption coll suplus
rayeaster Aug 29, 2023
f53de0f
Merge remote-tracking branch 'ebtc/feat/spearbit-misc' into fix-rm-pause
rayeaster Aug 29, 2023
04371f2
fix test_LiqPremiumWithCdpOvercollateralized_AboveMaxPremium()
rayeaster Aug 29, 2023
bcf4ddf
chore: comments
GalloDaSballo Aug 29, 2023
42a1924
feat: cleanup debug
GalloDaSballo Aug 29, 2023
bf25f37
Merge pull request #604 from Badger-Finance/feat-release-candidate-rm
GalloDaSballo Aug 29, 2023
e8491f3
refactor + cleanup
Aug 29, 2023
27c895b
Merge pull request #606 from Badger-Finance/feat/rm-pause-cleanup
dapp-whisperer Aug 29, 2023
d13fbd3
Merge pull request #592 from Badger-Finance/fix-sequence-zero-proper
dapp-whisperer Aug 29, 2023
af0584f
basic setGracePeriod functionality tests
Aug 29, 2023
3e89dcc
Merge branch 'fix-rm-pause' of https://github.com/Badger-Finance/ebtc…
Aug 29, 2023
a887665
setGracePeriod auth test
Aug 29, 2023
03bac6a
fix test error message
Aug 29, 2023
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
10 changes: 5 additions & 5 deletions packages/contracts/contracts/ActivePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ contract ActivePool is IActivePool, ERC3156FlashLender, ReentrancyGuard, BaseMat
uint256 _FeeRecipientColl = FeeRecipientColl;
require(_FeeRecipientColl >= _shares, "ActivePool: Insufficient fee recipient coll");

ICdpManagerData(cdpManagerAddress).applyPendingGlobalState();
ICdpManagerData(cdpManagerAddress).syncPendingGlobalState();

unchecked {
_FeeRecipientColl -= _shares;
Expand All @@ -368,7 +368,7 @@ contract ActivePool is IActivePool, ERC3156FlashLender, ReentrancyGuard, BaseMat
uint256 balance = IERC20(token).balanceOf(address(this));
require(amount <= balance, "ActivePool: Attempt to sweep more than balance");

ICdpManagerData(cdpManagerAddress).applyPendingGlobalState();
ICdpManagerData(cdpManagerAddress).syncPendingGlobalState();

address cachedFeeRecipientAddress = feeRecipientAddress; // Saves an SLOAD

Expand All @@ -383,7 +383,7 @@ contract ActivePool is IActivePool, ERC3156FlashLender, ReentrancyGuard, BaseMat
"ActivePool: Cannot set fee recipient to zero address"
);

ICdpManagerData(cdpManagerAddress).applyPendingGlobalState();
ICdpManagerData(cdpManagerAddress).syncPendingGlobalState();

feeRecipientAddress = _feeRecipientAddress;
emit FeeRecipientAddressChanged(_feeRecipientAddress);
Expand All @@ -392,7 +392,7 @@ contract ActivePool is IActivePool, ERC3156FlashLender, ReentrancyGuard, BaseMat
function setFeeBps(uint _newFee) external requiresAuth {
require(_newFee <= MAX_FEE_BPS, "ERC3156FlashLender: _newFee should <= MAX_FEE_BPS");

ICdpManagerData(cdpManagerAddress).applyPendingGlobalState();
ICdpManagerData(cdpManagerAddress).syncPendingGlobalState();

// set new flash fee
uint _oldFee = feeBps;
Expand All @@ -401,7 +401,7 @@ contract ActivePool is IActivePool, ERC3156FlashLender, ReentrancyGuard, BaseMat
}

function setFlashLoansPaused(bool _paused) external requiresAuth {
ICdpManagerData(cdpManagerAddress).applyPendingGlobalState();
ICdpManagerData(cdpManagerAddress).syncPendingGlobalState();

flashLoansPaused = _paused;
emit FlashLoansPaused(msg.sender, _paused);
Expand Down
56 changes: 47 additions & 9 deletions packages/contracts/contracts/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,28 @@ contract BorrowerOperations is
In normal mode, ICR must be greater thatn MCR
Additionally, the new system TCR after the CDPs addition must be >CCR
*/
uint newTCR = _getNewTCRFromCdpChange(vars.netColl, true, vars.debt, true, vars.price);
if (isRecoveryMode) {
_requireICRisAboveCCR(vars.ICR);

// == Grace Period == //
// We are in RM, Edge case is Depositing Coll could exit RM
// We check with newTCR
if (newTCR < CCR) {
aviggiano marked this conversation as resolved.
Show resolved Hide resolved
// Notify RM
cdpManager.notifyBeginRM(newTCR);
} else {
// Notify Back to Normal Mode
cdpManager.notifyEndRM(newTCR);
}
} else {
_requireICRisAboveMCR(vars.ICR);
uint newTCR = _getNewTCRFromCdpChange(vars.netColl, true, vars.debt, true, vars.price); // bools: coll increase, debt increase
_requireNewTCRisAboveCCR(newTCR);

// == Grace Period == //
// We are not in RM, no edge case, we always stay above RM
// Always Notify Back to Normal Mode
cdpManager.notifyEndRM(newTCR);
}

// Set the cdp struct's properties
Expand Down Expand Up @@ -463,6 +479,10 @@ contract BorrowerOperations is
);
_requireNewTCRisAboveCCR(newTCR);

// == Grace Period == //
// By definition we are not in RM, notify CDPManager to ensure "Glass is on"
cdpManager.notifyEndRM(newTCR);

cdpManager.removeStake(_cdpId);

// We already verified msg.sender is the borrower
Expand Down Expand Up @@ -607,7 +627,7 @@ contract BorrowerOperations is
uint _collWithdrawal,
bool _isDebtIncrease,
LocalVariables_adjustCdp memory _vars
) internal view {
) internal {
/*
*In Recovery Mode, only allow:
*
Expand All @@ -622,23 +642,41 @@ contract BorrowerOperations is
* - The new ICR is above MCR
* - The adjustment won't pull the TCR below CCR
*/

_vars.newTCR = _getNewTCRFromCdpChange(
collateral.getPooledEthByShares(_vars.collChange),
_vars.isCollIncrease,
_vars.netDebtChange,
_isDebtIncrease,
_vars.price
);

if (_isRecoveryMode) {
_requireNoCollWithdrawal(_collWithdrawal);
if (_isDebtIncrease) {
_requireICRisAboveCCR(_vars.newICR);
_requireNewICRisAboveOldICR(_vars.newICR, _vars.oldICR);
}

// == Grace Period == //
// We are in RM, Edge case is Depositing Coll could exit RM
// We check with newTCR
if (_vars.newTCR < CCR) {
aviggiano marked this conversation as resolved.
Show resolved Hide resolved
// Notify RM
cdpManager.notifyBeginRM(_vars.newTCR);
} else {
// Notify Back to Normal Mode
cdpManager.notifyEndRM(_vars.newTCR);
}
} else {
// if Normal Mode
_requireICRisAboveMCR(_vars.newICR);
_vars.newTCR = _getNewTCRFromCdpChange(
collateral.getPooledEthByShares(_vars.collChange),
_vars.isCollIncrease,
_vars.netDebtChange,
_isDebtIncrease,
_vars.price
);
_requireNewTCRisAboveCCR(_vars.newTCR);

// == Grace Period == //
// We are not in RM, no edge case, we always stay above RM
// Always Notify Back to Normal Mode
cdpManager.notifyEndRM(_vars.newTCR);
}
}

Expand Down
Loading