diff --git a/zenlink-protocol/src/foreign/mod.rs b/zenlink-protocol/src/foreign/mod.rs index 8b6176a..c3eca4d 100644 --- a/zenlink-protocol/src/foreign/mod.rs +++ b/zenlink-protocol/src/foreign/mod.rs @@ -37,7 +37,12 @@ impl Pallet { Ok(()) })?; - Self::deposit_event(Event::Transferred(id, owner.clone(), target.clone(), amount)); + Self::deposit_event(Event::Transferred { + asset_id: id, + owner: owner.clone(), + target: target.clone(), + amount + }); Ok(()) } @@ -69,7 +74,11 @@ impl Pallet { Ok(()) })?; - Self::deposit_event(Event::Minted(id, owner.clone(), amount)); + Self::deposit_event(Event::Minted { + asset_id: id, + owner: owner.clone(), + amount + }); Ok(()) } @@ -92,7 +101,11 @@ impl Pallet { Ok(()) })?; - Self::deposit_event(Event::Burned(id, owner.clone(), amount)); + Self::deposit_event(Event::Burned { + asset_id: id, + owner: owner.clone(), + amount + }); Ok(()) } diff --git a/zenlink-protocol/src/lib.rs b/zenlink-protocol/src/lib.rs index 0d68b56..e55b5e6 100644 --- a/zenlink-protocol/src/lib.rs +++ b/zenlink-protocol/src/lib.rs @@ -252,111 +252,158 @@ pub mod pallet { pub enum Event { /// Foreign Asset - /// Some assets were transferred. \[asset_id, owner, target, amount\] - Transferred(T::AssetId, T::AccountId, T::AccountId, AssetBalance), - /// Some assets were burned. \[asset_id, owner, amount\] - Burned(T::AssetId, T::AccountId, AssetBalance), - /// Some assets were minted. \[asset_id, owner, amount\] - Minted(T::AssetId, T::AccountId, AssetBalance), + /// Some assets were transferred. + Transferred { + asset_id: T::AssetId, + owner: T::AccountId, + target: T::AccountId, + amount: AssetBalance + }, + /// Some assets were burned. + Burned { + asset_id: T::AssetId, + owner: T::AccountId, + amount: AssetBalance + }, + /// Some assets were minted. + Minted { + asset_id: T::AssetId, + owner: T::AccountId, + amount: AssetBalance + }, /// Swap - /// Create a trading pair. \[asset_0, asset_1\] - PairCreated(T::AssetId, T::AssetId), - /// Add liquidity. \[owner, asset_0, asset_1, add_balance_0, add_balance_1, - /// mint_balance_lp\] - LiquidityAdded( - T::AccountId, - T::AssetId, - T::AssetId, - AssetBalance, - AssetBalance, - AssetBalance, - ), - /// Remove liquidity. \[owner, recipient, asset_0, asset_1, rm_balance_0, rm_balance_1, - /// burn_balance_lp\] - LiquidityRemoved( - T::AccountId, - T::AccountId, - T::AssetId, - T::AssetId, - AssetBalance, - AssetBalance, - AssetBalance, - ), - /// Transact in trading \[owner, recipient, swap_path, balances\] - AssetSwap(T::AccountId, T::AccountId, Vec, Vec), + /// Create a trading pair. + PairCreated { + asset_0: T::AssetId, + asset_1: T::AssetId + }, + /// Add liquidity. + LiquidityAdded { + owner: T::AccountId, + asset_0: T::AssetId, + asset_1: T::AssetId, + add_balance_0: AssetBalance, + add_balance_1: AssetBalance, + mint_balance_lp: AssetBalance + }, + /// Remove liquidity. + LiquidityRemoved { + owner: T::AccountId, + recipient: T::AccountId, + asset_0: T::AssetId, + asset_1: T::AssetId, + rm_balance_0: AssetBalance, + rm_balance_1: AssetBalance, + burn_balance_lp: AssetBalance, + }, + /// Transact in trading. + AssetSwap { + owner: T::AccountId, + recipient: T::AccountId, + swap_path: Vec, + balances: Vec + }, /// Transfer by xcm - /// Transferred to parachain. \[asset_id, src, para_id, dest, amount, used_weight\] - TransferredToParachain(T::AssetId, T::AccountId, ParaId, T::AccountId, AssetBalance, u64), - - /// Contribute to bootstrap pair. \[who, asset_0, asset_0_contribute, asset_1_contribute\] - BootstrapContribute(T::AccountId, T::AssetId, AssetBalance, T::AssetId, AssetBalance), - - /// A bootstrap pair end. \[asset_0, asset_1, asset_0_amount, asset_1_amount, - /// total_lp_supply] - BootstrapEnd(T::AssetId, T::AssetId, AssetBalance, AssetBalance, AssetBalance), - - /// Create a bootstrap pair. \[bootstrap_pair_account, asset_0, asset_1, - /// total_supply_0,total_supply_1, capacity_supply_0,capacity_supply_1, end\] - BootstrapCreated( - T::AccountId, - T::AssetId, - T::AssetId, - AssetBalance, - AssetBalance, - AssetBalance, - AssetBalance, - T::BlockNumber, - ), - - /// Claim a bootstrap pair. \[bootstrap_pair_account, claimer, receiver, asset_0, asset_1, - /// asset_0_refund, asset_1_refund, lp_amount\] - BootstrapClaim( - T::AccountId, - T::AccountId, - T::AccountId, - T::AssetId, - T::AssetId, - AssetBalance, - AssetBalance, - AssetBalance, - ), - - /// Update a bootstrap pair. \[caller, asset_0, asset_1, - /// total_supply_0,total_supply_1, capacity_supply_0,capacity_supply_1\] - BootstrapUpdate( - T::AccountId, - T::AssetId, - T::AssetId, - AssetBalance, - AssetBalance, - AssetBalance, - AssetBalance, - T::BlockNumber, - ), - - /// Refund from disable bootstrap pair. \[bootstrap_pair_account, caller, asset_0, asset_1, - /// asset_0_refund, asset_1_refund\] - BootstrapRefund( - T::AccountId, - T::AccountId, - T::AssetId, - T::AssetId, - AssetBalance, - AssetBalance, - ), + /// Transferred to parachain. + TransferredToParachain { + asset_id: T::AssetId, + src: T::AccountId, + para_id: ParaId, + dest: T::AccountId, + amount: AssetBalance, + used_weight: u64 + }, + + /// Contribute to bootstrap pair. + BootstrapContribute { + who: T::AccountId, + asset_0: T::AssetId, + asset_0_contribute: AssetBalance, + asset_1: T::AssetId, + asset_1_contribute: AssetBalance + }, + + /// A bootstrap pair end. + BootstrapEnd { + asset_0: T::AssetId, + asset_1: T::AssetId, + asset_0_amount: AssetBalance, + asset_1_amount: AssetBalance, + total_lp_supply: AssetBalance + }, + + /// Create a bootstrap pair. + BootstrapCreated { + bootstrap_pair_account: T::AccountId, + asset_0: T::AssetId, + asset_1: T::AssetId, + total_supply_0: AssetBalance, + total_supply_1: AssetBalance, + capacity_supply_0: AssetBalance, + capacity_supply_1: AssetBalance, + end: T::BlockNumber, + }, + + /// Claim a bootstrap pair. + BootstrapClaim { + bootstrap_pair_account: T::AccountId, + claimer: T::AccountId, + receiver: T::AccountId, + asset_0: T::AssetId, + asset_1: T::AssetId, + asset_0_refund: AssetBalance, + asset_1_refund: AssetBalance, + lp_amount: AssetBalance, + }, + + /// Update a bootstrap pair. + BootstrapUpdate { + caller: T::AccountId, + asset_0: T::AssetId, + asset_1: T::AssetId, + total_supply_0: AssetBalance, + total_supply_1: AssetBalance, + capacity_supply_0: AssetBalance, + capacity_supply_1: AssetBalance, + end: T::BlockNumber, + }, + + /// Refund from disable bootstrap pair. + BootstrapRefund { + bootstrap_pair_account: T::AccountId, + caller: T::AccountId, + asset_0: T::AssetId, + asset_1: T::AssetId, + asset_0_refund: AssetBalance, + asset_1_refund: AssetBalance, + }, /// Bootstrap distribute some rewards to contributors. - DistributeReward(T::AssetId, T::AssetId, T::AccountId, Vec<(T::AssetId, AssetBalance)>), + DistributeReward { + asset_0: T::AssetId, + asset_1: T::AssetId, + reward_holder: T::AccountId, + distribute_rewards: Vec<(T::AssetId, AssetBalance)> + }, /// Charge reward into a bootstrap. - ChargeReward(T::AssetId, T::AssetId, T::AccountId, Vec<(T::AssetId, AssetBalance)>), + ChargeReward { + asset_0: T::AssetId, + asset_1: T::AssetId, + who: T::AccountId, + charge_rewards: Vec<(T::AssetId, AssetBalance)> + }, /// Withdraw all reward from a bootstrap. - WithdrawReward(T::AssetId, T::AssetId, T::AccountId), + WithdrawReward { + asset_0: T::AssetId, + asset_1: T::AssetId, + recipient: T::AccountId32 + }, } #[pallet::error] pub enum Error { @@ -555,7 +602,10 @@ pub mod pallet { Self::mutate_lp_pairs(asset_0, asset_1)?; - Self::deposit_event(Event::PairCreated(asset_0, asset_1)); + Self::deposit_event(Event::PairCreated { + asset_0, + asset_1 + }); Ok(()) } @@ -819,16 +869,16 @@ pub mod pallet { }, })?; - Self::deposit_event(Event::BootstrapCreated( - Self::account_id(), - pair.0, - pair.1, - target_supply_0, - target_supply_1, - capacity_supply_1, - capacity_supply_0, + Self::deposit_event(Event::BootstrapCreated { + bootstrap_pair_account: Self::account_id(), + asset_0: pair.0, + asset_1: pair.1, + total_supply_0: target_supply_0, + total_supply_1: target_supply_1, + capacity_supply_0: capacity_supply_1, + capacity_supply_1: capacity_supply_0, end, - )); + }); Ok(()) } @@ -994,16 +1044,16 @@ pub mod pallet { Disable => Err(Error::::NotInBootstrap), })?; - Self::deposit_event(Event::BootstrapUpdate( - pair_account, - pair.0, - pair.1, - target_supply_0, - target_supply_1, + Self::deposit_event(Event::BootstrapUpdate { + caller: pair_account, + asset_0: pair.0, + asset_1: pair.1, + total_supply_0: target_supply_0, + total_supply_1: target_supply_1, capacity_supply_0, capacity_supply_1, end, - )); + }); Ok(()) } @@ -1051,7 +1101,12 @@ pub mod pallet { rewards.insert(*asset_id, new_charge_amount); } - Self::deposit_event(Event::ChargeReward(pair.0, pair.1, who, charge_rewards)); + Self::deposit_event(Event::ChargeReward { + asset_0: pair.0, + asset_1: pair.1, + who, + charge_rewards + }); Ok(()) })?; @@ -1086,7 +1141,11 @@ pub mod pallet { Ok(()) })?; - Self::deposit_event(Event::WithdrawReward(pair.0, pair.1, recipient)); + Self::deposit_event(Event::WithdrawReward { + asset_0: pair.0, + asset_1: pair.1, + recipient + }); Ok(()) } diff --git a/zenlink-protocol/src/swap/mod.rs b/zenlink-protocol/src/swap/mod.rs index f07406a..627ddcb 100644 --- a/zenlink-protocol/src/swap/mod.rs +++ b/zenlink-protocol/src/swap/mod.rs @@ -139,14 +139,14 @@ impl Pallet { } } - Self::deposit_event(Event::LiquidityAdded( - who.clone(), + Self::deposit_event(Event::LiquidityAdded { + owner: who.clone(), asset_0, asset_1, - amount_0, - amount_1, - mint_liquidity, - )); + add_balance_0: amount_0, + add_balance_1: amount_1, + mint_balance_lp: mint_liquidity, + }); Ok(()) } else { @@ -246,15 +246,15 @@ impl Pallet { } } - Self::deposit_event(Event::LiquidityRemoved( - who.clone(), - recipient.clone(), + Self::deposit_event(Event::LiquidityRemoved { + owner: who.clone(), + recipient: recipient.clone(), asset_0, asset_1, - amount_0, - amount_1, - remove_liquidity, - )); + rm_balance_0: amount_0, + rm_balance_1: amount_1, + burn_balance_lp: remove_liquidity, + }); Ok(()) } else { @@ -279,12 +279,12 @@ impl Pallet { T::MultiAssetsHandler::transfer(path[0], who, &pair_account, amount_in)?; Self::swap(&amounts, path, recipient)?; - Self::deposit_event(Event::AssetSwap( - who.clone(), - recipient.clone(), - Vec::from(path), - amounts, - )); + Self::deposit_event(Event::AssetSwap { + owner: who.clone(), + recipient: recipient.clone(), + swap_path: Vec::from(path), + balances: amounts, + }); Ok(()) } @@ -306,12 +306,12 @@ impl Pallet { T::MultiAssetsHandler::transfer(path[0], who, &pair_account, amounts[0])?; Self::swap(&amounts, path, recipient)?; - Self::deposit_event(Event::AssetSwap( - who.clone(), - recipient.clone(), - Vec::from(path), - amounts, - )); + Self::deposit_event(Event::AssetSwap { + owner: who.clone(), + recipient: recipient.clone(), + swap_path: Vec::from(path), + balances: amounts, + }); Ok(()) } @@ -729,13 +729,13 @@ impl Pallet { bootstrap_parameter.accumulated_supply = (accumulated_supply_0, accumulated_supply_1); PairStatuses::::insert(pair, Bootstrap(bootstrap_parameter)); - Self::deposit_event(Event::BootstrapContribute( - who.clone(), - pair.0, - amount_0_contribute, - pair.1, - amount_1_contribute, - )); + Self::deposit_event(Event::BootstrapContribute { + who: who.clone(), + asset_0: pair.0, + asset_0_contribute: amount_0_contribute, + asset_1: pair.1, + asset_1_contribute: amount_1_contribute, + }); Ok(()) }) } @@ -792,13 +792,13 @@ impl Pallet { BootstrapEndStatus::::insert(pair, Bootstrap(bootstrap_parameter.clone())); - Self::deposit_event(Event::BootstrapEnd( - pair.0, - pair.1, - bootstrap_parameter.accumulated_supply.0, - bootstrap_parameter.accumulated_supply.1, + Self::deposit_event(Event::BootstrapEnd { + asset_0: pair.0, + asset_1: pair.1, + asset_0_amount: bootstrap_parameter.accumulated_supply.0, + asset_1_amount: bootstrap_parameter.accumulated_supply.1, total_lp_supply, - )); + }); Ok(()) }, @@ -901,16 +901,16 @@ impl Pallet { bootstrap_total_liquidity, )?; - Self::deposit_event(Event::BootstrapClaim( - pair_account, - who.clone(), - recipient, - pair.0, - pair.1, - amount_0_contribute, - amount_1_contribute, - claim_liquidity, - )); + Self::deposit_event(Event::BootstrapClaim { + bootstrap_pair_account: pair_account, + claimer: who.clone(), + receiver: recipient, + asset_0: pair.0, + asset_1: pair.1, + asset_0_refund: amount_0_contribute, + asset_1_refund: amount_1_contribute, + lp_amount: claim_liquidity, + }); Ok(()) } else { @@ -980,14 +980,14 @@ impl Pallet { *contribution = None; - Self::deposit_event(Event::BootstrapRefund( - pair_account, - who.clone(), - pair.0, - pair.1, - amount_0_contribute, - amount_1_contribute, - )); + Self::deposit_event(Event::BootstrapRefund { + bootstrap_pair_account: pair_account, + caller: who.clone(), + asset_0: pair.0, + asset_1: pair.1, + asset_0_refund: amount_0_contribute, + asset_1_refund: amount_1_contribute, + }); Ok(()) } else { @@ -1055,12 +1055,12 @@ impl Pallet { } if !distribute_rewards.is_empty() { - Self::deposit_event(Event::DistributeReward( - pair.0, - pair.1, - reward_holder.clone(), + Self::deposit_event(Event::DistributeReward { + asset_0: pair.0, + asset_1: pair.1, + reward_holder: reward_holder.clone(), distribute_rewards, - )); + }); } Ok(())