diff --git a/packages/caviarnine-v1-adapter-v1/src/lib.rs b/packages/caviarnine-v1-adapter-v1/src/lib.rs index 58daa4c6..d15dd20c 100644 --- a/packages/caviarnine-v1-adapter-v1/src/lib.rs +++ b/packages/caviarnine-v1-adapter-v1/src/lib.rs @@ -604,14 +604,6 @@ fn calculate_bin_amounts_due_to_price_action( bin_amount.resource_x == Decimal::ZERO, bin_amount.resource_y == Decimal::ZERO, ) { - // TODO: I think that this is impossible? I believe that - // it is impossible since we only capture the bins that - // we have contributed to and THEN store the reserves in - // the bin. If we contributed to it, how come its empty - // of both resources? - // - // If this is somehow possible, what do we want to do - // in this case? (true, true) => return None, (true, false) => Composition::EntirelyY, (false, true) => Composition::EntirelyX, diff --git a/packages/ociswap-v1-adapter-v1/src/lib.rs b/packages/ociswap-v1-adapter-v1/src/lib.rs index c4ac0613..e1d07163 100644 --- a/packages/ociswap-v1-adapter-v1/src/lib.rs +++ b/packages/ociswap-v1-adapter-v1/src/lib.rs @@ -77,7 +77,6 @@ pub mod adapter { ) -> OpenLiquidityPositionOutput { let mut pool = Self::pool(pool_address); - // TODO: Is this actually pool units and change? let (pool_units, change) = pool.add_liquidity(buckets.0, buckets.1); let user_share = pool_units diff --git a/tests/tests/protocol.rs b/tests/tests/protocol.rs index c6c9ae31..f625a866 100644 --- a/tests/tests/protocol.rs +++ b/tests/tests/protocol.rs @@ -336,7 +336,6 @@ pub fn can_open_liquidity_position_when_oracle_price_is_lower_than_pool_but_with Ok(()) } -// TODO: Similar test is required for closing of a position. #[test] #[allow(unused_must_use)] fn oracle_price_cutoffs_for_opening_liquidity_positions_are_implemented_correctly( @@ -403,6 +402,77 @@ fn test_open_position_oracle_price_cutoffs( ) } +#[test] +#[allow(unused_must_use)] +fn oracle_price_cutoffs_for_closing_liquidity_positions_are_implemented_correctly( +) { + const SMALL_DECIMAL: Decimal = dec!(0.000000000000000010); + + test_close_position_oracle_price_cutoffs(dec!(1) / dec!(1.01), dec!(0.01)) + .expect("Should succeed!"); + test_close_position_oracle_price_cutoffs(dec!(1) / dec!(0.99), dec!(0.01)) + .expect("Should succeed!"); + test_close_position_oracle_price_cutoffs( + dec!(1) / dec!(0.99) - SMALL_DECIMAL, + dec!(0.01), + ) + .expect("Should succeed!"); + test_close_position_oracle_price_cutoffs( + dec!(1) / dec!(1.01) + SMALL_DECIMAL, + dec!(0.01), + ) + .expect("Should succeed!"); + + assert_is_ignition_relative_price_difference_larger_than_allowed_error( + &test_close_position_oracle_price_cutoffs( + dec!(1) / dec!(0.99) + SMALL_DECIMAL, + dec!(0.01), + ), + ); + assert_is_ignition_relative_price_difference_larger_than_allowed_error( + &test_close_position_oracle_price_cutoffs( + dec!(1) / dec!(1.01) - SMALL_DECIMAL, + dec!(0.01), + ), + ); +} + +fn test_close_position_oracle_price_cutoffs( + oracle_price: Decimal, + allowed_price_difference: Decimal, +) -> Result, RuntimeError> { + let Environment { + environment: ref mut env, + mut protocol, + ociswap_v1, + resources, + .. + } = ScryptoTestEnv::new_with_configuration(Configuration { + maximum_allowed_relative_price_difference: allowed_price_difference, + ..Default::default() + })?; + + let bitcoin_bucket = + ResourceManager(resources.bitcoin).mint_fungible(dec!(100), env)?; + + // Act + let (receipt, ..) = protocol.ignition.open_liquidity_position( + FungibleBucket(bitcoin_bucket), + ociswap_v1.pools.bitcoin.try_into().unwrap(), + LockupPeriod::from_months(6).unwrap(), + env, + )?; + + let current_time = env.get_current_time(); + env.set_current_time(current_time.add_days(12 * 30).unwrap()); + + protocol + .oracle + .set_price(resources.bitcoin, XRD, oracle_price, env)?; + + protocol.ignition.close_liquidity_position(receipt, env) +} + #[test] fn cant_open_a_liquidity_position_with_an_invalid_lockup_period( ) -> Result<(), RuntimeError> {