Skip to content

Commit

Permalink
chore: forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed May 9, 2024
1 parent 81577dc commit bbab92a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 48 deletions.
15 changes: 8 additions & 7 deletions contracts/src/StabilityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -333,26 +333,27 @@ contract StabilityPool is LiquityBase, Ownable, CheckContract, IStabilityPool {
assert(getDepositorETHGain(msg.sender) == 0);
}

function _stashOrSendETHGains(address _depositor, uint256 _currentETHGain, uint256 _boldLoss, bool _doClaim) internal {
function _stashOrSendETHGains(address _depositor, uint256 _currentETHGain, uint256 _boldLoss, bool _doClaim)
internal
{
if (_doClaim) {
// Get the total gain (stashed + current), zero the stashed balance, send total gain to depositor
uint ETHToSend = _getTotalETHGainAndZeroStash(_depositor, _currentETHGain);
uint256 ETHToSend = _getTotalETHGainAndZeroStash(_depositor, _currentETHGain);

emit ETHGainWithdrawn(msg.sender, ETHToSend, _boldLoss); // Bold Loss required for event log
_sendETHGainToDepositor(ETHToSend);

} else {
// Just stash the current gain
stashedETH[_depositor] += _currentETHGain;
}
}

function _getTotalETHGainAndZeroStash(address _depositor, uint256 _currentETHGain) internal returns (uint256) {
uint256 stashedETHGain = stashedETH[_depositor];
uint256 stashedETHGain = stashedETH[_depositor];
uint256 totalETHGain = stashedETHGain + _currentETHGain;

// TODO: Gas - saves gas when stashedETHGain == 0?
if (stashedETHGain > 0) {stashedETH[_depositor] = 0;}
if (stashedETHGain > 0) stashedETH[_depositor] = 0;

return totalETHGain;
}
Expand All @@ -368,15 +369,15 @@ contract StabilityPool is LiquityBase, Ownable, CheckContract, IStabilityPool {

// If they have a deposit, update it and update its snapshots
if (initialDeposit > 0) {
currentETHGain = getDepositorETHGain(msg.sender); // Only active deposits can have a current ETH gain
currentETHGain = getDepositorETHGain(msg.sender); // Only active deposits can have a current ETH gain

uint256 compoundedBoldDeposit = getCompoundedBoldDeposit(msg.sender);
boldLoss = initialDeposit - compoundedBoldDeposit; // Needed only for event log

_updateDepositAndSnapshots(msg.sender, compoundedBoldDeposit);
}

uint256 ETHToSend = _getTotalETHGainAndZeroStash(msg.sender, currentETHGain);
uint256 ETHToSend = _getTotalETHGainAndZeroStash(msg.sender, currentETHGain);

_sendETHGainToDepositor(ETHToSend);
assert(getDepositorETHGain(msg.sender) == 0);
Expand Down
10 changes: 4 additions & 6 deletions contracts/src/TroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,10 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager {
// --- Inner single liquidation functions ---

// Liquidate one trove, in Normal Mode.
function _liquidateNormalMode(
IDefaultPool _defaultPool,
uint256 _troveId,
uint256 _boldInStabPool,
uint256 _price
) internal returns (LiquidationValues memory singleLiquidation) {
function _liquidateNormalMode(IDefaultPool _defaultPool, uint256 _troveId, uint256 _boldInStabPool, uint256 _price)
internal
returns (LiquidationValues memory singleLiquidation)
{
address owner = ownerOf(_troveId);

LocalVariables_InnerSingleLiquidateFunction memory vars;
Expand Down
3 changes: 1 addition & 2 deletions contracts/src/test/TestContracts/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,12 @@ contract BaseTest is Test {
vm.stopPrank();
}

function claimAllETHGains(address _account) public {
function claimAllETHGains(address _account) public {
vm.startPrank(_account);
stabilityPool.claimAllETHGains();
vm.stopPrank();
}


function closeTrove(address _account, uint256 _troveId) public {
vm.startPrank(_account);
borrowerOperations.closeTrove(_troveId);
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/test/TestContracts/DevTestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ contract DevTestSetup is BaseTest {

function _setupForSPDepositAdjustments() internal returns (TroveIDs memory) {
TroveIDs memory troveIDs;
(troveIDs.A, troveIDs.B, troveIDs.C, troveIDs.D) = _setupForBatchLiquidateTrovesPureOffset();
(troveIDs.A, troveIDs.B, troveIDs.C, troveIDs.D) = _setupForBatchLiquidateTrovesPureOffset();

// A liquidates C
liquidate(A, troveIDs.C);
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/test/interestRateAggregate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ contract InterestRateAggregate is DevTestSetup {
}

function testClaimAllETHGainsReducesPendingAggInterestTo0() public {
_setupForSPDepositAdjustments();
_setupForSPDepositAdjustments();

// A stashes first gain
makeSPDepositNoClaim(A, 1e18);
Expand Down
60 changes: 29 additions & 31 deletions contracts/src/test/stabilityPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ pragma solidity 0.8.18;
import "./TestContracts/DevTestSetup.sol";

contract SPTest is DevTestSetup {

function _setupStashedAndCurrentETHGains() internal {
function _setupStashedAndCurrentETHGains() internal {
TroveIDs memory troveIDs = _setupForSPDepositAdjustments();

// A stashes first gain
Expand All @@ -20,7 +19,6 @@ contract SPTest is DevTestSetup {
assertGt(stashedETHGain_A, 0);
assertGt(currentETHGain_A, 0);


// Check B has only current gains, no stashed
uint256 stashedETHGain_B = stabilityPool.stashedETH(B);
uint256 currentETHGain_B = stabilityPool.getDepositorETHGain(B);
Expand All @@ -46,21 +44,21 @@ contract SPTest is DevTestSetup {
assertEq(WETH.balanceOf(A), ETHBal_A + currentETHGain);
}

function testProvideToSPWithClaim_WithOnlyCurrentGainsDoesntChangeStashedGain() public {
function testProvideToSPWithClaim_WithOnlyCurrentGainsDoesntChangeStashedGain() public {
_setupForSPDepositAdjustments();

uint256 currentETHGain = stabilityPool.getDepositorETHGain(A);
assertGt(currentETHGain, 0);

assertEq( stabilityPool.stashedETH(A), 0);
assertEq(stabilityPool.stashedETH(A), 0);

makeSPDepositAndClaim(A, 1e18);

assertEq( stabilityPool.stashedETH(A), 0);
assertEq(stabilityPool.stashedETH(A), 0);
}

function testProvideToSPWithClaim_WithCurrentAndStashedGainsSendsTotalETHGainToDepositor() public {
// A has stashed & current gains, B has only current
// A has stashed & current gains, B has only current
_setupStashedAndCurrentETHGains();

// Check A has both stashed and current gains
Expand All @@ -86,7 +84,7 @@ contract SPTest is DevTestSetup {
makeSPDepositAndClaim(A, 1e18);

// Check A's stashed balance reduced to 0
assertEq(stabilityPool.stashedETH(A),0);
assertEq(stabilityPool.stashedETH(A), 0);
}

function testProvideToSPWithClaim_WithOnlyStashedGainsSendsStashedETHGainToDepositor() public {
Expand Down Expand Up @@ -125,13 +123,13 @@ contract SPTest is DevTestSetup {
makeSPDepositAndClaim(A, 1e18);

// Check A's stashed balance reduced to 0
assertEq(stabilityPool.stashedETH(A),0);
assertEq(stabilityPool.stashedETH(A), 0);
}

// --- provideToSP, doClaim == false ---
// --- provideToSP, doClaim == false ---

function testProvideToSPNoClaim_WithOnlyCurrentGainsDoesntChangeDepositorETHBalance() public {
_setupForSPDepositAdjustments();
_setupForSPDepositAdjustments();

uint256 currentETHGain = stabilityPool.getDepositorETHGain(A);
assertGt(currentETHGain, 0);
Expand All @@ -151,7 +149,7 @@ contract SPTest is DevTestSetup {
assertGt(currentETHGain, 0);

// Check A has no stashed gains
assertEq( stabilityPool.stashedETH(A), 0);
assertEq(stabilityPool.stashedETH(A), 0);

makeSPDepositNoClaim(A, 1e18);

Expand All @@ -171,7 +169,7 @@ contract SPTest is DevTestSetup {
}

function testProvideToSPNoClaim_WithCurrentAndStashedGainsIncreasedStashedGainByCurrentGain() public {
// A has stashed & current gains, B has only current
// A has stashed & current gains, B has only current
_setupStashedAndCurrentETHGains();

// Check A has both stashed and current gains
Expand Down Expand Up @@ -222,7 +220,7 @@ contract SPTest is DevTestSetup {
assertEq(stabilityPool.stashedETH(A), stashedETHGain);
}

// --- withdrawFromSP, doClaim == true ---
// --- withdrawFromSP, doClaim == true ---
function testWithdrawFromSPWithClaim_WithOnlyCurrentGainsSendsTotalETHGainToDepositor() public {
_setupForSPDepositAdjustments();

Expand All @@ -240,17 +238,17 @@ contract SPTest is DevTestSetup {
assertEq(WETH.balanceOf(A), ETHBal_A + currentETHGain);
}

function testWithdrawFromSPWithClaim_WithOnlyCurrentGainsDoesntChangeStashedGain() public {
function testWithdrawFromSPWithClaim_WithOnlyCurrentGainsDoesntChangeStashedGain() public {
_setupForSPDepositAdjustments();

uint256 currentETHGain = stabilityPool.getDepositorETHGain(A);
assertGt(currentETHGain, 0);

assertEq( stabilityPool.stashedETH(A), 0);
assertEq(stabilityPool.stashedETH(A), 0);

makeSPWithdrawalAndClaim(A, 1e18);

assertEq( stabilityPool.stashedETH(A), 0);
assertEq(stabilityPool.stashedETH(A), 0);
}

function testWithdrawFromSPWithClaim_WithCurrentAndStashedGainsSendsTotalETHGainToDepositor() public {
Expand Down Expand Up @@ -280,7 +278,7 @@ contract SPTest is DevTestSetup {
makeSPWithdrawalAndClaim(A, 1e18);

// Check A's stashed balance reduced to 0
assertEq(stabilityPool.stashedETH(A),0);
assertEq(stabilityPool.stashedETH(A), 0);
}

function testWithdrawFromSPPWithClaim_WithOnlyStashedGainsSendsStashedETHGainToDepositor() public {
Expand Down Expand Up @@ -319,10 +317,10 @@ contract SPTest is DevTestSetup {
makeSPWithdrawalAndClaim(A, 1e18);

// Check A's stashed balance reduced to 0
assertEq(stabilityPool.stashedETH(A),0);
assertEq(stabilityPool.stashedETH(A), 0);
}

// --- withdrawFromSP, doClaim == false ---
// --- withdrawFromSP, doClaim == false ---

function testWithdrawFromSPNoClaim_WithOnlyCurrentGainsDoesntChangeDepositorETHBalance() public {
_setupForSPDepositAdjustments();
Expand All @@ -345,7 +343,7 @@ contract SPTest is DevTestSetup {
assertGt(currentETHGain, 0);

// Check A has no stashed gains
assertEq( stabilityPool.stashedETH(A), 0);
assertEq(stabilityPool.stashedETH(A), 0);

makeSPWithdrawalNoClaim(A, 1e18);

Expand All @@ -360,7 +358,7 @@ contract SPTest is DevTestSetup {
// Check A has both stashed and current gains
stabilityPool.stashedETH(A);
stabilityPool.getDepositorETHGain(A);

uint256 ETHBal_A = WETH.balanceOf(A);
assertGt(ETHBal_A, 0);

Expand All @@ -370,7 +368,7 @@ contract SPTest is DevTestSetup {
}

function testWithdrawFromSPNoClaim_WithCurrentAndStashedGainsIncreasedStashedGainByCurrentGain() public {
// A has stashed & current gains, B has only current
// A has stashed & current gains, B has only current
_setupStashedAndCurrentETHGains();

uint256 stashedETHGain = stabilityPool.stashedETH(A);
Expand Down Expand Up @@ -467,12 +465,12 @@ contract SPTest is DevTestSetup {
assertEq(stabilityPool.stashedETH(B), 0);
}

function testClaimAllETHGainsForOnlyCurrentETHGainIncreasesUserBalanceByCurrentETHGain() public {
function testClaimAllETHGainsForOnlyCurrentETHGainIncreasesUserBalanceByCurrentETHGain() public {
// A has stashed & current gains, B has only current
_setupStashedAndCurrentETHGains();

uint256 currentETHGain_B = stabilityPool.getDepositorETHGain(B);

uint256 ETHBal_B = WETH.balanceOf(B);
assertGt(ETHBal_B, 0);

Expand Down Expand Up @@ -525,9 +523,9 @@ contract SPTest is DevTestSetup {
assertEq(WETH.balanceOf(A), ETHBal_A + stashedGain_A + currentGain_A);
}

function testClaimAllETHGainsForOnlyStashedETHGainDoesntChangeETHGain() public {
function testClaimAllETHGainsForOnlyStashedETHGainDoesntChangeETHGain() public {
_setupForSPDepositAdjustments();

// A stashes first gain
makeSPDepositNoClaim(A, 1e18);

Expand All @@ -544,7 +542,7 @@ contract SPTest is DevTestSetup {

function testClaimAllETHGainsForOnlyStashedETHGainZerosStashedETHGain() public {
_setupForSPDepositAdjustments();

// A stashes first gain
makeSPDepositNoClaim(A, 1e18);

Expand All @@ -560,8 +558,8 @@ contract SPTest is DevTestSetup {
}

function testClaimAllETHGainsForOnlyStashedETHGainIncreasesUserBalanceByStashedETHGain() public {
_setupForSPDepositAdjustments();
_setupForSPDepositAdjustments();

// A stashes first gain
makeSPDepositNoClaim(A, 1e18);

Expand All @@ -583,7 +581,7 @@ contract SPTest is DevTestSetup {

// TODO:
// 1) claim tests for withdrawETHGainToTrove (if we don't remove it)
//
//
// 2) tests for claimAllETHGains (requires deposit data & getter refactor):
// - updates recorded deposit value
// - updates deposit snapshots

0 comments on commit bbab92a

Please sign in to comment.