diff --git a/misc/types.json b/misc/types.json index 00b44cfe1..c7ed794ec 100644 --- a/misc/types.json +++ b/misc/types.json @@ -188,11 +188,13 @@ "weights": "Option>" }, "PoolAssetEvent": { + "asset": "Asset", "bound": "Balance", "cpep": "CommonPoolEventParams", "transferred": "Balance" }, "PoolAssetsEvent": { + "assets": "Vec", "bounds": "Vec", "cpep": "CommonPoolEventParams", "transferred": "Vec" @@ -235,6 +237,8 @@ "asset_amount_in": "Balance", "asset_amount_out": "Balance", "asset_bound": "Balance", + "asset_in": "Asset", + "asset_out": "Asset", "cpep": "CommonPoolEventParams", "max_price": "Balance" }, diff --git a/zrml/swaps/src/events.rs b/zrml/swaps/src/events.rs index c234b839d..8bb891d64 100644 --- a/zrml/swaps/src/events.rs +++ b/zrml/swaps/src/events.rs @@ -28,7 +28,8 @@ pub struct CommonPoolEventParams { parity_scale_codec::Decode, parity_scale_codec::Encode, )] -pub struct PoolAssetsEvent { +pub struct PoolAssetsEvent { + pub assets: Vec, pub bounds: Vec, pub cpep: CommonPoolEventParams, pub transferred: Vec, @@ -45,7 +46,8 @@ pub struct PoolAssetsEvent { parity_scale_codec::Decode, parity_scale_codec::Encode, )] -pub struct PoolAssetEvent { +pub struct PoolAssetEvent { + pub asset: AS, pub bound: B, pub cpep: CommonPoolEventParams, pub transferred: B, @@ -62,10 +64,12 @@ pub struct PoolAssetEvent { parity_scale_codec::Decode, parity_scale_codec::Encode, )] -pub struct SwapEvent { +pub struct SwapEvent { pub asset_amount_in: B, pub asset_amount_out: B, pub asset_bound: B, + pub asset_in: AS, + pub asset_out: AS, pub cpep: CommonPoolEventParams, pub max_price: B, } diff --git a/zrml/swaps/src/lib.rs b/zrml/swaps/src/lib.rs index 0f4d73826..26431136f 100644 --- a/zrml/swaps/src/lib.rs +++ b/zrml/swaps/src/lib.rs @@ -220,6 +220,7 @@ mod pallet { } Self::deposit_event(Event::::PoolExitSubsidy(PoolAssetEvent { + asset: base_asset, bound: upper_bound, cpep: CommonPoolEventParams { pool_id, who }, transferred, @@ -408,6 +409,7 @@ mod pallet { }); Self::deposit_event(Event::::PoolJoinSubsidy(PoolAssetEvent { + asset: base_asset, bound: amount, cpep: CommonPoolEventParams { pool_id, who }, transferred: amount, @@ -731,35 +733,79 @@ mod pallet { Pool, T::MarketId>, ), /// Someone has exited a pool. \[PoolAssetsEvent\] - PoolExit(PoolAssetsEvent<::AccountId, BalanceOf>), + PoolExit( + PoolAssetsEvent< + ::AccountId, + Asset, + BalanceOf, + >, + ), /// Someone has (partially) exited a pool by removing subsidy. \[PoolAssetEvent, amount\] - PoolExitSubsidy(PoolAssetEvent<::AccountId, BalanceOf>), + PoolExitSubsidy( + PoolAssetEvent< + ::AccountId, + Asset, + BalanceOf, + >, + ), /// Exits a pool given an exact amount of an asset. \[PoolAssetEvent\] PoolExitWithExactAssetAmount( - PoolAssetEvent<::AccountId, BalanceOf>, + PoolAssetEvent< + ::AccountId, + Asset, + BalanceOf, + >, ), /// Exits a pool given an exact pool's amount. \[PoolAssetEvent\] PoolExitWithExactPoolAmount( - PoolAssetEvent<::AccountId, BalanceOf>, + PoolAssetEvent< + ::AccountId, + Asset, + BalanceOf, + >, ), /// Someone has joined a pool. \[PoolAssetsEvent\] - PoolJoin(PoolAssetsEvent<::AccountId, BalanceOf>), + PoolJoin( + PoolAssetsEvent< + ::AccountId, + Asset, + BalanceOf, + >, + ), /// Someone has joined a pool by providing subsidy. \[PoolAssetEvent, amount\] - PoolJoinSubsidy(PoolAssetEvent<::AccountId, BalanceOf>), + PoolJoinSubsidy( + PoolAssetEvent< + ::AccountId, + Asset, + BalanceOf, + >, + ), /// Joins a pool given an exact amount of an asset. \[PoolAssetEvent\] PoolJoinWithExactAssetAmount( - PoolAssetEvent<::AccountId, BalanceOf>, + PoolAssetEvent< + ::AccountId, + Asset, + BalanceOf, + >, ), /// Joins a pool given an exact pool's amount. \[PoolAssetEvent\] PoolJoinWithExactPoolAmount( - PoolAssetEvent<::AccountId, BalanceOf>, + PoolAssetEvent< + ::AccountId, + Asset, + BalanceOf, + >, ), /// Total subsidy collected for a pool. \[pool_id, subsidy\] SubsidyCollected(PoolId, BalanceOf), /// An exact amount of an asset is entering the pool. \[SwapEvent\] - SwapExactAmountIn(SwapEvent<::AccountId, BalanceOf>), + SwapExactAmountIn( + SwapEvent<::AccountId, Asset, BalanceOf>, + ), /// An exact amount of an asset is leaving the pool. \[SwapEvent\] - SwapExactAmountOut(SwapEvent<::AccountId, BalanceOf>), + SwapExactAmountOut( + SwapEvent<::AccountId, Asset, BalanceOf>, + ), } #[pallet::pallet] diff --git a/zrml/swaps/src/tests.rs b/zrml/swaps/src/tests.rs index 554ea98d9..5245c0466 100644 --- a/zrml/swaps/src/tests.rs +++ b/zrml/swaps/src/tests.rs @@ -539,6 +539,7 @@ fn pool_exit_decreases_correct_pool_parameters() { assert_ok!(Swaps::pool_exit(alice_signed(), 0, _1, vec!(_1, _1, _1, _1),)); assert!(event_exists(crate::Event::PoolExit(PoolAssetsEvent { + assets: vec![ASSET_A, ASSET_B, ASSET_C, ASSET_D], bounds: vec!(_1, _1, _1, _1), cpep: CommonPoolEventParams { pool_id: 0, who: 0 }, transferred: vec!(_1 + 1, _1 + 1, _1 + 1, _1 + 1), @@ -624,6 +625,7 @@ fn pool_exit_with_exact_pool_amount_exchanges_correct_values() { _4 )); assert!(event_exists(crate::Event::PoolExitWithExactPoolAmount(PoolAssetEvent { + asset: ASSET_A, bound: _4, cpep: CommonPoolEventParams { pool_id: 0, who: 0 }, transferred: _5 - 335, @@ -648,6 +650,7 @@ fn pool_exit_with_exact_asset_amount_exchanges_correct_values() { _1 )); assert!(event_exists(crate::Event::PoolExitWithExactAssetAmount(PoolAssetEvent { + asset: ASSET_A, bound: _1, cpep: CommonPoolEventParams { pool_id: 0, who: 0 }, transferred: asset_after_join - 1000, @@ -670,6 +673,7 @@ fn pool_join_increases_correct_pool_parameters() { assert_ok!(Swaps::pool_join(alice_signed(), 0, _5, vec!(_25, _25, _25, _25),)); assert!(event_exists(crate::Event::PoolJoin(PoolAssetsEvent { + assets: vec![ASSET_A, ASSET_B, ASSET_C, ASSET_D], bounds: vec!(_25, _25, _25, _25), cpep: CommonPoolEventParams { pool_id: 0, who: 0 }, transferred: vec!(_5, _5, _5, _5), @@ -718,6 +722,7 @@ fn pool_join_with_exact_asset_amount_exchanges_correct_values() { 0 )); assert!(event_exists(crate::Event::PoolJoinWithExactAssetAmount(PoolAssetEvent { + asset: ASSET_A, bound: 0, cpep: CommonPoolEventParams { pool_id: 0, who: 0 }, transferred: alice_sent @@ -748,6 +753,7 @@ fn pool_join_with_exact_pool_amount_exchanges_correct_values() { )); let asset_amount = alice_initial - Currencies::free_balance(ASSET_A, &ALICE); assert!(event_exists(crate::Event::PoolJoinWithExactPoolAmount(PoolAssetEvent { + asset: ASSET_A, bound: _5, cpep: CommonPoolEventParams { pool_id: 0, who: 0 }, transferred: asset_amount, @@ -862,6 +868,8 @@ fn swap_exact_amount_in_exchanges_correct_values_with_cpmm() { asset_amount_in: _1, asset_amount_out: 9900990100, asset_bound: _1 / 2, + asset_in: ASSET_A, + asset_out: ASSET_B, cpep: CommonPoolEventParams { pool_id: 0, who: 0 }, max_price: _2, }))); @@ -929,6 +937,8 @@ fn swap_exact_amount_out_exchanges_correct_values_with_cpmm() { asset_amount_in: 10101010100, asset_amount_out: _1, asset_bound: _2, + asset_in: ASSET_A, + asset_out: ASSET_B, cpep: CommonPoolEventParams { pool_id: 0, who: 0 }, max_price: _3, }))); diff --git a/zrml/swaps/src/utils.rs b/zrml/swaps/src/utils.rs index fa54fc675..2bb4335d6 100644 --- a/zrml/swaps/src/utils.rs +++ b/zrml/swaps/src/utils.rs @@ -21,7 +21,7 @@ pub(crate) fn pool_exit_with_exact_amount( where F1: FnMut(BalanceOf, BalanceOf) -> Result, DispatchError>, F2: FnMut(BalanceOf) -> DispatchResult, - F3: FnMut(PoolAssetEvent>), + F3: FnMut(PoolAssetEvent, BalanceOf>), F4: FnMut(BalanceOf, BalanceOf) -> Result, DispatchError>, T: Config, { @@ -45,6 +45,7 @@ where T::Shares::transfer(p.asset, &pool_account, &p.who, asset_amount)?; (p.event)(PoolAssetEvent { + asset: p.asset, bound: p.bound, cpep: CommonPoolEventParams { pool_id: p.pool_id, who: p.who }, transferred: asset_amount, @@ -59,7 +60,7 @@ pub(crate) fn pool_join_with_exact_amount( ) -> DispatchResult where F1: FnMut(BalanceOf, BalanceOf) -> Result, DispatchError>, - F2: FnMut(PoolAssetEvent>), + F2: FnMut(PoolAssetEvent, BalanceOf>), F3: FnMut(BalanceOf, BalanceOf) -> Result, DispatchError>, T: Config, { @@ -79,6 +80,7 @@ where T::Shares::transfer(p.asset, &p.who, &pool_account_id, asset_amount)?; (p.event)(PoolAssetEvent { + asset: p.asset, bound: p.bound, cpep: CommonPoolEventParams { pool_id: p.pool_id, who: p.who }, transferred: asset_amount, @@ -90,7 +92,7 @@ where // Common code for `pool_join` and `pool_exit` methods. pub(crate) fn pool(mut p: PoolParams<'_, F1, F2, F3, T>) -> DispatchResult where - F1: FnMut(PoolAssetsEvent>), + F1: FnMut(PoolAssetsEvent, BalanceOf>), F2: FnMut(BalanceOf, BalanceOf, Asset) -> DispatchResult, F3: FnMut(Asset) -> DispatchResult, T: Config, @@ -117,6 +119,7 @@ where (p.transfer_pool)(pool_shares_id)?; (p.event)(PoolAssetsEvent { + assets: p.pool.assets.clone(), bounds: p.asset_bounds, cpep: CommonPoolEventParams { pool_id: p.pool_id, who: p.who }, transferred, @@ -131,7 +134,7 @@ pub(crate) fn swap_exact_amount( ) -> DispatchResult where F1: FnMut() -> Result<[BalanceOf; 2], DispatchError>, - F2: FnMut(SwapEvent>), + F2: FnMut(SwapEvent, BalanceOf>), T: crate::Config, { Pallet::::check_if_pool_is_active(p.pool)?; @@ -202,6 +205,8 @@ where asset_amount_in, asset_amount_out, asset_bound: p.asset_bound, + asset_in: p.asset_in, + asset_out: p.asset_out, cpep: CommonPoolEventParams { pool_id: p.pool_id, who: p.who }, max_price: p.max_price, });