-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
correctly calculate liquidity using LiquidityMath library
- Loading branch information
1 parent
5ec532e
commit 49af007
Showing
2 changed files
with
19 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity >=0.5.0; | ||
|
||
/// @title Math library for liquidity | ||
library LiquidityMath { | ||
/// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows | ||
/// @param x The liquidity before change | ||
/// @param y The delta by which liquidity should be changed | ||
/// @return z The liquidity delta | ||
function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { | ||
if (y < 0) { | ||
require((z = x - uint128(-y)) < x, 'LS'); | ||
} else { | ||
require((z = x + uint128(y)) >= x, 'LA'); | ||
} | ||
} | ||
} |