From a4b854967e2abb514991414fb68c489c13d6921a Mon Sep 17 00:00:00 2001 From: tyranis0x01 Date: Wed, 1 Oct 2025 11:54:09 -0700 Subject: [PATCH 1/2] feat: Add removeLiquidity External Function Natspec Comments --- src/onchain/TestAMMContract.sol | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/onchain/TestAMMContract.sol b/src/onchain/TestAMMContract.sol index 2d1e6db..9ebed4d 100644 --- a/src/onchain/TestAMMContract.sol +++ b/src/onchain/TestAMMContract.sol @@ -293,6 +293,38 @@ contract Test_AMMContract is Ownable { return (1, uint128(liquidityAdded), _amount0, _amount1); } + /** + * @notice Removes liquidity from a pool and returns tokens to the user + * @dev Calculates proportional token amounts based on user's liquidity share and current reserves. + * Transfers the calculated amounts back to the user and updates tracking. + * + * @param _marketId Unique identifier for the prediction market + * @param _user Address of the user removing liquidity + * @param _liquidity Amount of liquidity to remove from the position + * @param _amount0Min Minimum amount of tokenA to receive (slippage protection) + * @param _amount1Min Minimum amount of tokenB to receive (slippage protection) + * + * @return amount0Decreased Amount of tokenA removed and returned to user + * @return amount1Decreased Amount of tokenB removed and returned to user + * @return amount0Collected Same as amount0Decreased (simplified - no separate fees) + * @return amount1Collected Same as amount1Decreased (simplified - no separate fees) + * + * Requirements: + * - Pool must exist and be initialized + * - User must have sufficient liquidity to remove + * - Calculated amounts must meet minimum thresholds (slippage protection) + * - Pool must have sufficient reserves for the withdrawal + * + * Effects: + * - Calculates proportional token amounts based on liquidity share + * - Updates pool reserves (reserveA -= amount0, reserveB -= amount1) + * - Updates user's liquidity tracking (decreases by _liquidity amount) + * - Transfers calculated token amounts to user + * - Emits LiquidityRemoved event + * + * @custom:proportional Uses simple proportion: userShare = _liquidity / totalLiquidity + * @custom:slippage Includes slippage protection via minimum amount parameters + */ function removeLiquidity( bytes32 _marketId, address _user, From b64c0c704d7b75198eff469e80ebc8e1808fd1d8 Mon Sep 17 00:00:00 2001 From: tyranis0x01 Date: Wed, 1 Oct 2025 11:54:21 -0700 Subject: [PATCH 2/2] feat: forge fmt --- src/onchain/TestAMMContract.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/onchain/TestAMMContract.sol b/src/onchain/TestAMMContract.sol index 9ebed4d..afd2b01 100644 --- a/src/onchain/TestAMMContract.sol +++ b/src/onchain/TestAMMContract.sol @@ -305,7 +305,7 @@ contract Test_AMMContract is Ownable { * @param _amount1Min Minimum amount of tokenB to receive (slippage protection) * * @return amount0Decreased Amount of tokenA removed and returned to user - * @return amount1Decreased Amount of tokenB removed and returned to user + * @return amount1Decreased Amount of tokenB removed and returned to user * @return amount0Collected Same as amount0Decreased (simplified - no separate fees) * @return amount1Collected Same as amount1Decreased (simplified - no separate fees) *