Skip to content

Commit

Permalink
fix: ensure 0 deltaFlow doesn't update state (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
philbow61 authored Nov 25, 2024
1 parent ea5d779 commit 161ec08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contracts/libraries/TradingLimits.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ library TradingLimits {
int256 _deltaFlow,
uint8 decimals
) internal view returns (ITradingLimits.State memory) {
if (_deltaFlow == 0) {
return self;
}

int256 _deltaFlowUnits = _deltaFlow / int256((10 ** uint256(decimals)));
require(_deltaFlowUnits <= MAX_INT48, "dFlow too large");
require(_deltaFlowUnits >= MIN_INT48, "dFlow too small");
Expand Down
7 changes: 7 additions & 0 deletions test/unit/libraries/TradingLimits.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ contract TradingLimitsTest is Test {
assertEq(state.netflowGlobal, 0);
}

function test_update_withZeroDeltaFlow_doesNotUpdate() public {
state = harness.update(state, configL0L1LG(300, 1000, 1 days, 10000, 1000000), 0, 18);
assertEq(state.netflow0, 0);
assertEq(state.netflow1, 0);
assertEq(state.netflowGlobal, 0);
}

function test_update_withL0_updatesActive() public {
state = harness.update(state, configL0(500, 1000), 100 * 1e18, 18);
assertEq(state.netflow0, 100);
Expand Down

0 comments on commit 161ec08

Please sign in to comment.