From 1d711500b8a7743b2348fafcfbfbae851acfd80f Mon Sep 17 00:00:00 2001 From: Sarmat Date: Mon, 19 Aug 2024 21:57:20 +0300 Subject: [PATCH] feat: remove liquidity tests --- fixtures/mira-amm/mira_amm_contract.bin | Bin 56920 -> 56320 bytes libraries/interfaces/src/mira_amm.sw | 2 +- .../tests/cases/mod.rs | 1 + .../tests/cases/revert.rs | 60 ++++++++++ .../tests/cases/success.rs | 109 +++++++++++++++++- 5 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 scripts/remove_liquidity_script/tests/cases/revert.rs diff --git a/fixtures/mira-amm/mira_amm_contract.bin b/fixtures/mira-amm/mira_amm_contract.bin index ebf1cabd8d98b7fa3a5a70f0fb19ec0ded065f3a..1d0acb3ef68f40065751e9599fcc469b0043165a 100644 GIT binary patch delta 16042 zcmaKT3w%`7x$oXP4<-+iosdk1o!5{TLjV~dgj}Gw<4nwiBxLhY!Xsov)Cef!CLpzF zMnyzL4J^diT8)aDR(hN;0U`*Dw?1O!YJ6R>_1wl*d%`hXb56AfTYvWa*JF~I!QaX6 zm#n?kUh7-m`rhBScFw;V=kJeGwNaw9k#Yy1O4^7a?U&~Dn7Xv2^`aze zx>stwm`GY&$4N_VKsG&+CAX$TSF7W7j32`IA?<=BMZ-;9t+@v2x-Pu$GHL^Mz=}8Z zVyEirlPC;Fb(Y_BPq(SHeLCxtQaNK&;z7(mh<(_ch;=Q zY!&(xdw0eqI!^QlZK>^2>OwJjn9NYL@?xFOkyJ-@iEg?}t0G~vxJDb*YAIxTrrU{6 zDJTf)W&@jwp-F9OeV?E8>#{&zbiW z-+rbc_OWwZ(Py~k3`dWv!*rZD;Ir#38+^unAq>Ny5Iyvj{i#p|X%$H$@5 z6=1twu159UPH)t%?)=WkzTrC6MOjjwF@+;v?hvnq5N+sAvR~b!byd*T+x<2LqX!T%O!%Uyr)E6=h z$?j+@1q;z<(*m7*EJ11=k*r3w)4}@H*%Ih232J#9)fG^hTn{^b17OsYgpB%r57kR; z;x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Oz~!O-QT~op5Vfao$@sBdWHGqd7}L`vjnZ-Ou23Td z8q30v%@LBr_^&AUC`lK2b$Vy-rO+;I4Naw>9o-zCDUv7n39XnCzj+ z^<&}e`mv_jR#j&S`k-wa0if5;)s!xOe7zpL!-SF%LJ67bK4m|G-Rf-vVz6612ugXDsyPF{mXorBg1n z$>!JvkMUc`)l2T9k5zw;7%SPvC!^|b} z7zg{6#O+^#?{CPait}I$Hq>rapj?F73)xU)Y4cG&DY7>8nIL%3v*EF@wX+8n$pYQn zpc{z)`_4(UOZX3AQcn>h5o*qDg&v2mx|crw$H{{jlkryt0;OVbfYs0)Z_b%ECIQn#oWAzbW6vA+8XYU63j z{zd3tjP?@QADfTx^~5De3^y?(EfXawv6)m4>lT4hUQlXP-KOqqtevMitlK+lx7^;T zSa;#Q^-hFRcSe-UrU9hmpA}fZ@(0(|k9GU3w@**_IW(@V#w_2d4gg;O;Kf$;NecZM z=~7h4ybdZ5oG@g*X%b@2C$JXz@u^yPq}n^i1)>TcGV%`~ZZ%QZq+30(1BzDarr3^( zG^CU(p_HqTz_;P#?NsRe;>m6DMg_+DQ&aksnV;Wqi9PxDz05O=bbr|GzI)%cCIo28 z-S^yi^If|XrTMPrZM*8X-F^41&398j8yI%Ewuf%r)_iMy(_J(J|1R)0~Ke~+iYpTlEl`gEbl*YU6+R4}QKW|6G`x{~TbjhbKp09r> zp8sZv=a8H~)Fs-lxyAE>cqp$Fi-DJdEztie9k7G zKbGys_lx!+x$z;n@qN=o|9x`)or zyGA0kR#L)}2;9&i#(lA8yJ%n6FP{>@YqCZA8h+4LMOpct=veuNc&_lsr&~OiH^^tL zcrKME%jN(S#kEEBJI~0c>~|a!ZHGKS#-M0tNW?N4(4LL|sdC~}xp9&%CMIOV diff --git a/libraries/interfaces/src/mira_amm.sw b/libraries/interfaces/src/mira_amm.sw index 853efe8..87b35ba 100644 --- a/libraries/interfaces/src/mira_amm.sw +++ b/libraries/interfaces/src/mira_amm.sw @@ -26,7 +26,7 @@ abi MiraAMM { #[payable] #[storage(read, write)] - fn burn(pool_id: PoolId, lp_asset_id: AssetId, liquidity: u64, to: Identity) -> (u64, u64); + fn burn(pool_id: PoolId, to: Identity) -> (u64, u64); #[payable] #[storage(read, write)] diff --git a/scripts/remove_liquidity_script/tests/cases/mod.rs b/scripts/remove_liquidity_script/tests/cases/mod.rs index 4d8e510..1449806 100644 --- a/scripts/remove_liquidity_script/tests/cases/mod.rs +++ b/scripts/remove_liquidity_script/tests/cases/mod.rs @@ -1 +1,2 @@ +pub mod revert; pub mod success; diff --git a/scripts/remove_liquidity_script/tests/cases/revert.rs b/scripts/remove_liquidity_script/tests/cases/revert.rs new file mode 100644 index 0000000..5cbe52d --- /dev/null +++ b/scripts/remove_liquidity_script/tests/cases/revert.rs @@ -0,0 +1,60 @@ +use crate::utils::setup; +use fuels::programs::call_utils::TxDependencyExtension; +use test_harness::utils::common::to_9_decimal; +use test_harness::wallet::get_transaction_inputs_outputs; + +#[tokio::test] +#[ignore] +#[should_panic(expected = "ZeroInputAmount")] +async fn removes_all_liquidity_passing_exact_a_and_b_values() { + let ( + add_liquidity_script_instance, + remove_liquidity_script_instance, + amm, + _token_contract, + _provider, + pool_id, + wallet, + transaction_parameters, + deadline, + ) = setup().await; + + let token_0_amount: u64 = to_9_decimal(1); + let token_1_amount: u64 = to_9_decimal(1); + + // adds initial liquidity + let added_liquidity = add_liquidity_script_instance + .main( + pool_id, + token_0_amount, + token_1_amount, + 0, + 0, + wallet.address().into(), + deadline, + ) + .with_contracts(&[&amm.instance]) + .with_inputs(transaction_parameters.inputs) + .with_outputs(transaction_parameters.outputs) + .call() + .await + .unwrap() + .value; + + let transaction_parameters = get_transaction_inputs_outputs( + &wallet, + &vec![added_liquidity.id], + &vec![added_liquidity.amount], + ) + .await; + + remove_liquidity_script_instance + .main(pool_id, 0, 0, 0, wallet.address().into(), deadline) + .with_contracts(&[&amm.instance]) + .with_inputs(transaction_parameters.0) + .with_outputs(transaction_parameters.1) + .append_variable_outputs(2) + .call() + .await + .unwrap(); +} diff --git a/scripts/remove_liquidity_script/tests/cases/success.rs b/scripts/remove_liquidity_script/tests/cases/success.rs index 728334b..ed4b36e 100644 --- a/scripts/remove_liquidity_script/tests/cases/success.rs +++ b/scripts/remove_liquidity_script/tests/cases/success.rs @@ -1,14 +1,13 @@ use crate::utils::setup; use fuels::programs::call_utils::TxDependencyExtension; use test_harness::interface::amm::pool_metadata; -use test_harness::interface::BurnEvent; +use test_harness::interface::{Asset, BurnEvent}; use test_harness::utils::common::{ to_9_decimal, wallet_balances_for_pool_asset, MINIMUM_LIQUIDITY, }; use test_harness::wallet::get_transaction_inputs_outputs; #[tokio::test] -#[ignore] async fn removes_all_liquidity_passing_exact_a_and_b_values() { let ( add_liquidity_script_instance, @@ -45,6 +44,9 @@ async fn removes_all_liquidity_passing_exact_a_and_b_values() { .unwrap() .value; + let lp_token_amount = added_liquidity.amount; + assert_eq!(lp_token_amount, expected_liquidity); + let initial_pool_metadata = pool_metadata(&amm.instance, pool_id).await.value.unwrap(); let initial_wallet_balances = wallet_balances_for_pool_asset(&wallet, &(pool_id.0, pool_id.1), &added_liquidity.id).await; @@ -98,11 +100,11 @@ async fn removes_all_liquidity_passing_exact_a_and_b_values() { ); assert_eq!( final_pool_metadata.reserve_0, - initial_pool_metadata.reserve_0 - token_0_amount + initial_pool_metadata.reserve_0 - token_0_amount + MINIMUM_LIQUIDITY ); assert_eq!( final_pool_metadata.reserve_1, - initial_pool_metadata.reserve_1 - token_1_amount + initial_pool_metadata.reserve_1 - token_1_amount + MINIMUM_LIQUIDITY ); assert_eq!( final_pool_metadata.liquidity.amount, @@ -111,7 +113,6 @@ async fn removes_all_liquidity_passing_exact_a_and_b_values() { } #[tokio::test] -#[ignore] async fn removes_all_liquidity_passing_exact_a_but_not_exact_b_values() { let ( add_liquidity_script_instance, @@ -205,3 +206,101 @@ async fn removes_all_liquidity_passing_exact_a_but_not_exact_b_values() { initial_wallet_balances.asset_b + token_1_amount - 2000 ); } + +#[tokio::test] +async fn removes_partial_liquidity() { + let ( + add_liquidity_script_instance, + remove_liquidity_script_instance, + amm, + _token_contract, + _provider, + pool_id, + wallet, + transaction_parameters, + deadline, + ) = setup().await; + + let token_0_amount: u64 = to_9_decimal(1); + let token_1_amount: u64 = to_9_decimal(1); + let expected_liquidity: u64 = to_9_decimal(1) - MINIMUM_LIQUIDITY; + + // adds initial liquidity + let added_liquidity = add_liquidity_script_instance + .main( + pool_id, + token_0_amount, + token_1_amount, + 1, + 1, + wallet.address().into(), + deadline, + ) + .with_contracts(&[&amm.instance]) + .with_inputs(transaction_parameters.inputs) + .with_outputs(transaction_parameters.outputs) + .call() + .await + .unwrap() + .value; + + let lp_token_amount = added_liquidity.amount; + assert_eq!(lp_token_amount, expected_liquidity); + + let initial_wallet_balances = + wallet_balances_for_pool_asset(&wallet, &(pool_id.0, pool_id.1), &added_liquidity.id).await; + + let transaction_parameters = get_transaction_inputs_outputs( + &wallet, + &vec![added_liquidity.id], + &vec![expected_liquidity], + ) + .await; + + let removed_liquidity = remove_liquidity_script_instance + .main( + pool_id, + added_liquidity.amount / 2, + 0, + 0, + wallet.address().into(), + deadline, + ) + .with_contracts(&[&amm.instance]) + .with_inputs(transaction_parameters.0) + .with_outputs(transaction_parameters.1) + .append_variable_outputs(2) + .call() + .await + .unwrap(); + + let log = removed_liquidity + .decode_logs_with_type::() + .unwrap(); + let event = log.first().unwrap(); + + let final_wallet_balances = + wallet_balances_for_pool_asset(&wallet, &(pool_id.0, pool_id.1), &added_liquidity.id).await; + + assert_eq!( + *event, + BurnEvent { + pool_id, + recipient: wallet.address().into(), + liquidity: Asset { + amount: added_liquidity.amount / 2, + id: added_liquidity.id + }, + asset_0_out: removed_liquidity.value.0, + asset_1_out: removed_liquidity.value.1, + } + ); + assert_eq!( + final_wallet_balances.asset_a, + initial_wallet_balances.asset_a + (token_0_amount / 2) - 500 + ); + assert_eq!( + final_wallet_balances.asset_b, + initial_wallet_balances.asset_b + (token_1_amount / 2) - 500 + ); +}