mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
18 lines
622 B
Solidity
18 lines
622 B
Solidity
|
// 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');
|
||
|
}
|
||
|
}
|
||
|
}
|