diff --git a/.github/workflows/reusable-build-and-test.yml b/.github/workflows/reusable-build-and-test.yml index 2e76e62f1..b45da468e 100644 --- a/.github/workflows/reusable-build-and-test.yml +++ b/.github/workflows/reusable-build-and-test.yml @@ -602,7 +602,7 @@ jobs: echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV - name: Run benchmarks tests - run: cargo test --release -j8 --features=runtime-benchmarks -p pallet-xyk -p pallet-issuance -p pallet-multipurpose-liquidity -p pallet-fee-lock + run: cargo test --release -j8 --features=runtime-benchmarks -p pallet-xyk -p pallet-issuance -p pallet-multipurpose-liquidity -p pallet-fee-lock -p pallet-market - name: Run benchmarks tests run: cargo test --release -j8 --features=runtime-benchmarks -p pallet-bootstrap # NOTE: MGX-742 diff --git a/rollup/runtime/integration-test/src/market.rs b/rollup/runtime/integration-test/src/market.rs index 23f00abce..863964712 100644 --- a/rollup/runtime/integration-test/src/market.rs +++ b/rollup/runtime/integration-test/src/market.rs @@ -3,14 +3,15 @@ use crate::setup::*; use pallet_market::{AtomicSwap, Event, PoolKind}; use sp_runtime::{traits::Zero, DispatchResult}; -const ASSET_ID_1: u32 = 1; -const ASSET_ID_2: u32 = 2; -const ASSET_ID_3: u32 = 3; -const ASSET_ID_4_DISABLED: u32 = 4; -const ASSET_ID_5_UNREGISTERED: u32 = 5; -const POOL_ID_1: u32 = 6; -const POOL_ID_2: u32 = 7; -const POOL_ID_3: u32 = 8; +const ASSET_ID_1: u32 = NATIVE_ASSET_ID + 1; +const ASSET_ID_2: u32 = ASSET_ID_1 + 1; +const ASSET_ID_3: u32 = ASSET_ID_2 + 1; +const ASSET_ID_4_DISABLED: u32 = ASSET_ID_3 + 1; +const ASSET_ID_5: u32 = ASSET_ID_4_DISABLED + 1; +const ASSET_ID_6: u32 = ASSET_ID_5 + 1; +const POOL_ID_1: u32 = ASSET_ID_6 + 1; +const POOL_ID_2: u32 = POOL_ID_1 + 1; +const POOL_ID_3: u32 = POOL_ID_2 + 1; fn test_env() -> TestExternalities { ExtBuilder { @@ -20,7 +21,8 @@ fn test_env() -> TestExternalities { (AccountId::from(ALICE), ASSET_ID_2, 100 * UNIT), (AccountId::from(ALICE), ASSET_ID_3, 100 * UNIT), (AccountId::from(ALICE), ASSET_ID_4_DISABLED, 100 * UNIT), - (AccountId::from(ALICE), ASSET_ID_5_UNREGISTERED, 100 * UNIT), + (AccountId::from(ALICE), ASSET_ID_5, 100 * UNIT), + (AccountId::from(ALICE), ASSET_ID_6, 100 * UNIT), ], assets: vec![ ( @@ -76,6 +78,26 @@ fn test_env() -> TestExternalities { }, }, ), + ( + ASSET_ID_5, + AssetMetadataOf { + decimals: 10, + name: BoundedVec::truncate_from(b"Asset".to_vec()), + symbol: BoundedVec::truncate_from(b"Asset".to_vec()), + existential_deposit: Default::default(), + additional: Default::default(), + }, + ), + ( + ASSET_ID_6, + AssetMetadataOf { + decimals: 12, + name: BoundedVec::truncate_from(b"Asset".to_vec()), + symbol: BoundedVec::truncate_from(b"Asset".to_vec()), + existential_deposit: Default::default(), + additional: Default::default(), + }, + ), ], ..ExtBuilder::default() } @@ -109,15 +131,15 @@ fn create_pool_works() { assert_ok!(create_pool(PoolKind::Xyk, (NATIVE_ASSET_ID, ASSET_ID_1))); System::assert_has_event(RuntimeEvent::Market(Event::PoolCreated { creator: AccountId::from(ALICE), - pool_id: 6, - lp_token: 6, + pool_id: POOL_ID_1, + lp_token: POOL_ID_1, assets: (0, 1), })); System::assert_has_event(RuntimeEvent::Market(Event::LiquidityMinted { who: AccountId::from(ALICE), - pool_id: 6, + pool_id: POOL_ID_1, amounts_provided: (10000000000000000000, 5000000000000000000), - lp_token: 6, + lp_token: POOL_ID_1, lp_token_minted: 7500000000000000000, total_supply: 7500000000000000000, })); @@ -125,15 +147,15 @@ fn create_pool_works() { assert_ok!(create_pool(PoolKind::StableSwap, (NATIVE_ASSET_ID, ASSET_ID_1))); System::assert_has_event(RuntimeEvent::Market(Event::PoolCreated { creator: AccountId::from(ALICE), - pool_id: 7, - lp_token: 7, + pool_id: POOL_ID_2, + lp_token: POOL_ID_2, assets: (0, 1), })); System::assert_has_event(RuntimeEvent::Market(Event::LiquidityMinted { who: AccountId::from(ALICE), - pool_id: 7, + pool_id: POOL_ID_2, amounts_provided: (10000000000000000000, 5000000000000000000), - lp_token: 7, + lp_token: POOL_ID_2, lp_token_minted: 14999063611862273044, total_supply: 14999063611862273044, })); @@ -154,9 +176,9 @@ fn add_liquidity_works() { assert_ok!(Market::mint_liquidity(origin(), POOL_ID_1, NATIVE_ASSET_ID, UNIT, 10 * UNIT)); System::assert_last_event(RuntimeEvent::Market(Event::LiquidityMinted { who: AccountId::from(ALICE), - pool_id: 6, + pool_id: POOL_ID_1, amounts_provided: (1000000000000000000, expected), - lp_token: 6, + lp_token: POOL_ID_1, lp_token_minted: lp_expected, total_supply: 8250000000000000000, })); @@ -169,9 +191,9 @@ fn add_liquidity_works() { assert_ok!(Market::mint_liquidity(origin(), POOL_ID_2, NATIVE_ASSET_ID, UNIT, 10 * UNIT)); System::assert_last_event(RuntimeEvent::Market(Event::LiquidityMinted { who: AccountId::from(ALICE), - pool_id: 7, + pool_id: POOL_ID_2, amounts_provided: (1000000000000000000, expected), - lp_token: 7, + lp_token: POOL_ID_2, lp_token_minted: lp_expected, total_supply: 16998182477145509576, })); @@ -187,9 +209,9 @@ fn add_liquidity_fixed_works() { assert_ok!(Market::mint_liquidity_fixed_amounts(origin(), POOL_ID_1, (UNIT, 0), 0)); System::assert_last_event(RuntimeEvent::Market(Event::LiquidityMinted { who: AccountId::from(ALICE), - pool_id: 6, + pool_id: POOL_ID_1, amounts_provided: (1000000000000000000, 0), - lp_token: 6, + lp_token: POOL_ID_1, lp_token_minted: 365524961509654622, total_supply: 7865524961509654622, })); @@ -198,9 +220,9 @@ fn add_liquidity_fixed_works() { assert_ok!(Market::mint_liquidity_fixed_amounts(origin(), POOL_ID_2, (UNIT, 5 * UNIT), 0)); System::assert_last_event(RuntimeEvent::Market(Event::LiquidityMinted { who: AccountId::from(ALICE), - pool_id: 7, + pool_id: POOL_ID_2, amounts_provided: (1000000000000000000, 5000000000000000000), - lp_token: 7, + lp_token: POOL_ID_2, lp_token_minted: expected, total_supply: 20990943480975169792, })); @@ -216,7 +238,7 @@ fn remove_liquidity_works() { assert_ok!(Market::burn_liquidity(origin(), POOL_ID_1, UNIT, 0, 0)); System::assert_last_event(RuntimeEvent::Market(Event::LiquidityBurned { who: AccountId::from(ALICE), - pool_id: 6, + pool_id: POOL_ID_1, amounts: (1333333333333333333, 666666666666666666), burned_amount: 1000000000000000000, total_supply: 6500000000000000000, @@ -225,7 +247,7 @@ fn remove_liquidity_works() { assert_ok!(Market::burn_liquidity(origin(), POOL_ID_2, UNIT, 0, 0)); System::assert_last_event(RuntimeEvent::Market(Event::LiquidityBurned { who: AccountId::from(ALICE), - pool_id: 7, + pool_id: POOL_ID_2, amounts: (666708286515387818, 333354143257693909), burned_amount: 1000000000000000000, total_supply: 13999063611862273044, @@ -255,7 +277,7 @@ fn multiswap_should_work_xyk() { who: AccountId::from(ALICE), swaps: vec![ AtomicSwap { - pool_id: 6, + pool_id: POOL_ID_1, kind: PoolKind::Xyk, asset_in: 0, asset_out: 1, @@ -263,7 +285,7 @@ fn multiswap_should_work_xyk() { amount_out: 453305446940074565, }, AtomicSwap { - pool_id: 7, + pool_id: POOL_ID_2, kind: PoolKind::Xyk, asset_in: 1, asset_out: 2, @@ -271,7 +293,7 @@ fn multiswap_should_work_xyk() { amount_out: 216201629292906575, }, AtomicSwap { - pool_id: 8, + pool_id: POOL_ID_3, kind: PoolKind::Xyk, asset_in: 2, asset_out: 3, @@ -317,7 +339,7 @@ fn multiswap_should_work_stable_swap_with_bnb() { who: AccountId::from(ALICE), swaps: vec![ AtomicSwap { - pool_id: 6, + pool_id: POOL_ID_1, kind: PoolKind::StableSwap, asset_in: 0, asset_out: 1, @@ -325,7 +347,7 @@ fn multiswap_should_work_stable_swap_with_bnb() { amount_out: 995595345298031754, }, AtomicSwap { - pool_id: 7, + pool_id: POOL_ID_2, kind: PoolKind::StableSwap, asset_in: 1, asset_out: 2, @@ -333,7 +355,7 @@ fn multiswap_should_work_stable_swap_with_bnb() { amount_out: 991212132384121611, }, AtomicSwap { - pool_id: 8, + pool_id: POOL_ID_3, kind: PoolKind::StableSwap, asset_in: 2, asset_out: 3, @@ -367,7 +389,7 @@ fn multiswap_should_work_mixed() { who: AccountId::from(ALICE), swaps: vec![ AtomicSwap { - pool_id: 6, + pool_id: POOL_ID_1, kind: PoolKind::Xyk, asset_in: 0, asset_out: 1, @@ -375,7 +397,7 @@ fn multiswap_should_work_mixed() { amount_out: 453305446940074565, }, AtomicSwap { - pool_id: 7, + pool_id: POOL_ID_2, kind: PoolKind::StableSwap, asset_in: 1, asset_out: 2, @@ -383,7 +405,7 @@ fn multiswap_should_work_mixed() { amount_out: 451412806019623895, }, AtomicSwap { - pool_id: 8, + pool_id: POOL_ID_3, kind: PoolKind::Xyk, asset_in: 2, asset_out: 3, @@ -396,19 +418,32 @@ fn multiswap_should_work_mixed() { } #[test] -fn multiswap_buy_should_work_mixed() { +fn test_diff_decimals_work() { test_env().execute_with(|| { - assert_ok!(create_pool(PoolKind::Xyk, (NATIVE_ASSET_ID, ASSET_ID_1))); - assert_ok!(create_pool(PoolKind::StableSwap, (ASSET_ID_1, ASSET_ID_2))); - assert_ok!(create_pool(PoolKind::Xyk, (ASSET_ID_2, ASSET_ID_3))); + let unit10 = 10_000_000_000_u128; + let unit12 = 1_000_000_000_000_u128; + assert_ok!(Market::create_pool( + origin(), + PoolKind::StableSwap, + ASSET_ID_5, + 100 * unit10, + ASSET_ID_6, + 100 * unit12 + )); + + let pool = Market::get_pools(Some(POOL_ID_1)); + let price = Market::calculate_sell_price(POOL_ID_1, ASSET_ID_5, 1).unwrap(); + + println!("{:#?}", pool); + println!("{:#?}", price); - assert_ok!(Market::multiswap_asset_buy( + assert_ok!(Market::multiswap_asset( origin(), - vec![POOL_ID_1, POOL_ID_2, POOL_ID_3], - ASSET_ID_3, - UNIT / 100, - NATIVE_ASSET_ID, - UNIT, + vec![POOL_ID_1], + ASSET_ID_5, + 1, + ASSET_ID_6, + 1, )); println!("{:#?}", events()); @@ -417,28 +452,12 @@ fn multiswap_buy_should_work_mixed() { who: AccountId::from(ALICE), swaps: vec![ AtomicSwap { - pool_id: 6, - kind: PoolKind::Xyk, - asset_in: 0, - asset_out: 1, - amount_in: 40648650414565365, - amount_out: 20181563007698743, - }, - AtomicSwap { - pool_id: 7, + pool_id: POOL_ID_1, kind: PoolKind::StableSwap, - asset_in: 1, - asset_out: 2, - amount_in: 20181563007698743, - amount_out: 20100381304233342, - }, - AtomicSwap { - pool_id: 8, - kind: PoolKind::Xyk, - asset_in: 2, - asset_out: 3, - amount_in: 20100381304233342, - amount_out: 10000000000000000, + asset_in: ASSET_ID_5, + asset_out: ASSET_ID_6, + amount_in: 1, + amount_out: 99, }, ], }));