From fcc9afb2daf428fd46182880e91734fc3da53684 Mon Sep 17 00:00:00 2001 From: Mikhail Tagirov Date: Tue, 7 Mar 2023 11:38:26 +0300 Subject: [PATCH 1/3] Minor fixes (#304) Signed-off-by: Mikhail Tagirov --- Jenkinsfile | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7850305839..79ad4ae8f0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,7 @@ String contractsEnvFile = 'env.template' String solcVersion = '0.8.14' String nodeVersion = '14.16.1' String gitHubUser = 'sorabot' -String gitHubRepo = 'github.com/soramitsu/sora2-network.git' +String gitHubRepo = 'github.com/sora-xor/sora2-network.git' String gitHubBranch = 'doc' String gitHubEmail = 'admin@soramitsu.co.jp' String cargoDocImage = 'rust:1.62.0-slim-bullseye' diff --git a/README.md b/README.md index b1ea2dd4e6..64213205bc 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ cargo build --release --features private-net access running network via polkadot.js/apps (select Development -> Local Node, e.g. [link](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer)) #### On macOS macOS is shipped with the BSD version of `getopt`. If the script behaves incorrectly and does not parse arguments, -make sure you have installed and set as active the GNU versions of `awk` and `getopt`. +make sure you have installed and set as active the GNU versions of `awk` (or `gawk`) and `getopt`. ### Run benchmarks to generate weights From f9092626e54824ca6b07364d37fa965699facffb Mon Sep 17 00:00:00 2001 From: Nikita Smirnov Date: Thu, 9 Mar 2023 14:33:49 +0400 Subject: [PATCH 2/3] Fix/swap transfer batch slippage hotfix (#320) * fixed swap_transfer_batch extrinsic slippage check * minor fix * added check for empty receivers --- pallets/liquidity-proxy/src/lib.rs | 91 ++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 29 deletions(-) diff --git a/pallets/liquidity-proxy/src/lib.rs b/pallets/liquidity-proxy/src/lib.rs index 3e62bb11cf..a9062fbd6e 100644 --- a/pallets/liquidity-proxy/src/lib.rs +++ b/pallets/liquidity-proxy/src/lib.rs @@ -1784,45 +1784,76 @@ pub mod pallet { receivers, } = swap_batch_info; - let filter = LiquiditySourceFilter::with_mode( - dex_id, - filter_mode.clone(), - selected_source_types.clone(), - ); - - if Self::is_forbidden_filter( - &input_asset_id, - &asset_id, - &selected_source_types, - &filter_mode, - ) { - fail!(Error::::ForbiddenFilter); - } - + // extrinsic fails if there are duplicate output asset ids if !unique_asset_ids.insert(asset_id.clone()) { Err(Error::::AggregationError)? } + if receivers.len() == 0 { + Err(Error::::InvalidReceiversInfo)? + } + let out_amount = receivers.iter().map(|recv| recv.target_amount).sum(); - Self::inner_exchange( - dex_id, - &who, - &who, - &input_asset_id, - &asset_id, - SwapAmount::WithDesiredOutput { - desired_amount_out: out_amount, - max_amount_in: max_input_amount, - }, - filter.clone(), - )?; + let (executed_input_amount, remainder_per_receiver): (Balance, Balance) = + if asset_id != input_asset_id { + let filter = LiquiditySourceFilter::with_mode( + dex_id, + filter_mode.clone(), + selected_source_types.clone(), + ); + + if Self::is_forbidden_filter( + &input_asset_id, + &asset_id, + &selected_source_types, + &filter_mode, + ) { + fail!(Error::::ForbiddenFilter); + } + + let ( + SwapOutcome { + amount: executed_input_amount, + .. + }, + _, + ) = Self::inner_exchange( + dex_id, + &who, + &who, + &input_asset_id, + &asset_id, + SwapAmount::WithDesiredOutput { + desired_amount_out: out_amount, + max_amount_in: max_input_amount, + }, + filter.clone(), + )?; + + let caller_output_asset_balance = + assets::Pallet::::total_balance(&asset_id, &who)?; + let remainder_per_receiver: Balance = + if caller_output_asset_balance < out_amount { + let remainder = + out_amount.saturating_sub(caller_output_asset_balance); + remainder / (receivers.len() as u128) + + remainder % (receivers.len() as u128) + } else { + 0 + }; + (executed_input_amount, remainder_per_receiver) + } else { + (out_amount, 0) + }; + max_input_amount = max_input_amount - .checked_sub(out_amount) + .checked_sub(executed_input_amount) .ok_or(Error::::SlippageNotTolerated)?; let mut unique_batch_receivers: BTreeSet = BTreeSet::new(); fallible_iterator::convert(receivers.into_iter().map(|val| Ok(val))).for_each( |receiver| { + // extrinsic fails if there are duplicate account ids in the same output asset id if !unique_batch_receivers.insert(receiver.account_id.clone()) { Err(Error::::AggregationError)? } @@ -1830,7 +1861,7 @@ pub mod pallet { &asset_id, &who, &receiver.account_id, - receiver.target_amount, + receiver.target_amount - remainder_per_receiver, ) }, ) @@ -1944,5 +1975,7 @@ pub mod pallet { UnableToDisableLiquiditySource, /// Liquidity source is already disabled LiquiditySourceAlreadyDisabled, + // Information about swap batch receivers is invalid + InvalidReceiversInfo, } } From dc719494f2c8d873a04a708e75362bd0c3a73048 Mon Sep 17 00:00:00 2001 From: Vladimir Stepanenko Date: Thu, 9 Mar 2023 13:59:27 +0300 Subject: [PATCH 3/3] Update spec version to 49 --- runtime/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 1f7351b794..370b81a37c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -233,10 +233,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("sora-substrate"), impl_name: create_runtime_str!("sora-substrate"), authoring_version: 1, - spec_version: 48, + spec_version: 49, impl_version: 1, apis: RUNTIME_API_VERSIONS, - transaction_version: 48, + transaction_version: 49, state_version: 0, };