evm-dex-pool 1.2.2

Reusable EVM DEX pool implementations (UniswapV2, UniswapV3, ERC4626) with traits and math
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use anyhow::{anyhow, Result};

/// Add a signed liquidity delta to liquidity and revert if it overflows or underflows
///
/// ## Arguments
///
/// * `x`: The liquidity before change
/// * `y`: The delta by which liquidity should be changed
///
/// ## Returns
///
/// The liquidity delta
#[inline]
pub fn add_delta(x: u128, y: i128) -> Result<u128> {
    x.checked_add_signed(y)
        .ok_or_else(|| anyhow!("Liquidity delta overflow"))
}