From b69b08faeb0293d803a5f431b78c93a08d67b5b7 Mon Sep 17 00:00:00 2001 From: "Muhammad-Jibril B.A. (Khalifa MBA)" Date: Sun, 3 Mar 2024 17:59:55 +0800 Subject: [PATCH] Remove `stake_increment_share`, add `Fees` type for Edfis NEW, rename `Position` to `ECDPPosition`. Remove `stake_increment_share`, add `Fees` type for Edfis NEW, rename `Position` to `ECDPPosition`. --- blockchain/modules/edfis-swap/src/lib.rs | 21 +- blockchain/modules/support/src/ecdp.rs | 4 +- blockchain/modules/support/src/edfis.rs | 230 +++++++++ .../support/src/{dex.rs => edfis_legacy.rs} | 446 +++++++++--------- blockchain/modules/support/src/lib.rs | 8 +- blockchain/primitives/src/lib.rs | 5 +- blockchain/resources/types.json | 2 +- 7 files changed, 469 insertions(+), 247 deletions(-) create mode 100644 blockchain/modules/support/src/edfis.rs rename blockchain/modules/support/src/{dex.rs => edfis_legacy.rs} (96%) diff --git a/blockchain/modules/edfis-swap/src/lib.rs b/blockchain/modules/edfis-swap/src/lib.rs index d7fa574b..6c9850e7 100644 --- a/blockchain/modules/edfis-swap/src/lib.rs +++ b/blockchain/modules/edfis-swap/src/lib.rs @@ -38,7 +38,7 @@ use frame_system::pallet_prelude::*; use module_support::{SwapDexIncentives, SwapManager, Erc20InfoMapping, ExchangeRate, Ratio, SwapLimit}; use orml_traits::{Happened, MultiCurrency, MultiCurrencyExtended}; use parity_scale_codec::MaxEncodedLen; -use primitives::{Balance, CurrencyId, TradingPair}; +use primitives::{Balance, CurrencyId, Fees, TradingPair}; use scale_info::TypeInfo; use sp_core::{H160, U256}; use sp_runtime::{ @@ -63,6 +63,8 @@ pub struct ProvisioningParameters { target_provision: (Balance, Balance), /// accumulated provision amount for this Provisioning trading pair. accumulated_provision: (Balance, Balance), + /// accumulated provision amount for this Provisioning trading pair. + trading_fee: (u32, u32), /// The number of block that status can be converted to Enabled. not_before: BlockNumber, } @@ -391,14 +393,8 @@ pub mod module { /// - `max_amount_b`: maximum amount of currency_id_b is allowed to inject to liquidity /// pool. /// - `min_share_increment`: minimum acceptable share amount. - /// - `stake_increment_share`: indicates whether to stake increased dex share to earn - /// incentives #[pallet::call_index(2)] - #[pallet::weight(if *stake_increment_share { - ::WeightInfo::add_liquidity_and_stake() - } else { - ::WeightInfo::add_liquidity() - })] + #[pallet::weight(::WeightInfo::add_liquidity())] pub fn add_liquidity( origin: OriginFor, currency_id_a: CurrencyId, @@ -406,7 +402,6 @@ pub mod module { #[pallet::compact] max_amount_a: Balance, #[pallet::compact] max_amount_b: Balance, #[pallet::compact] min_share_increment: Balance, - stake_increment_share: bool, ) -> DispatchResult { let who = ensure_signed(origin)?; Self::do_add_liquidity( @@ -416,7 +411,6 @@ pub mod module { max_amount_a, max_amount_b, min_share_increment, - stake_increment_share, )?; Ok(()) } @@ -987,7 +981,6 @@ impl Pallet { max_amount_a: Balance, max_amount_b: Balance, min_share_increment: Balance, - stake_increment_share: bool, ) -> sp_std::result::Result<(Balance, Balance, Balance), DispatchError> { let trading_pair = TradingPair::from_currency_ids(currency_id_a, currency_id_b).ok_or(Error::::InvalidCurrencyId)?; @@ -1080,10 +1073,6 @@ impl Pallet { *pool_0 = pool_0.checked_add(pool_0_increment).ok_or(ArithmeticError::Overflow)?; *pool_1 = pool_1.checked_add(pool_1_increment).ok_or(ArithmeticError::Overflow)?; - if stake_increment_share { - T::SwapDexIncentives::do_deposit_dex_share(who, dex_share_currency_id, share_increment)?; - } - Self::deposit_event(Event::AddLiquidity { who: who.clone(), currency_0: trading_pair.first(), @@ -1511,7 +1500,6 @@ impl SwapManager for Pallet { max_amount_a: Balance, max_amount_b: Balance, min_share_increment: Balance, - stake_increment_share: bool, ) -> sp_std::result::Result<(Balance, Balance, Balance), DispatchError> { Self::do_add_liquidity( who, @@ -1520,7 +1508,6 @@ impl SwapManager for Pallet { max_amount_a, max_amount_b, min_share_increment, - stake_increment_share, ) } diff --git a/blockchain/modules/support/src/ecdp.rs b/blockchain/modules/support/src/ecdp.rs index b54a6b1c..7967456e 100644 --- a/blockchain/modules/support/src/ecdp.rs +++ b/blockchain/modules/support/src/ecdp.rs @@ -19,7 +19,7 @@ // along with this program. If not, see . use parity_scale_codec::FullCodec; -use primitives::Position; +use primitives::ECDPPosition; use sp_core::U256; use sp_runtime::{DispatchError, DispatchResult}; use sp_std::{ @@ -199,7 +199,7 @@ pub trait SlickUsdEcdpManager { /// Close ECDP loan using DEX fn close_loan_by_dex(who: AccountId, currency_id: CurrencyId, max_collateral_amount: Balance) -> DispatchResult; /// Get open ECDP corresponding to an account and collateral `CurrencyId` - fn get_position(who: &AccountId, currency_id: CurrencyId) -> Position; + fn get_position(who: &AccountId, currency_id: CurrencyId) -> ECDPPosition; /// Get liquidation ratio for collateral `CurrencyId` fn get_collateral_parameters(currency_id: CurrencyId) -> Vec; /// Get current ratio of collateral to debit of open ECDP diff --git a/blockchain/modules/support/src/edfis.rs b/blockchain/modules/support/src/edfis.rs new file mode 100644 index 00000000..fc9206e8 --- /dev/null +++ b/blockchain/modules/support/src/edfis.rs @@ -0,0 +1,230 @@ +// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم + +// This file is part of Setheum. + +// Copyright (C) 2019-Present Setheum Labs. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use frame_support::{ensure, traits::Get}; +use parity_scale_codec::{Decode, Encode}; +use scale_info::TypeInfo; +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; +use sp_core::H160; +use sp_runtime::{DispatchError, DispatchResult, RuntimeDebug}; +use sp_std::{cmp::PartialEq, prelude::*, result::Result}; + +#[derive(RuntimeDebug, Encode, Decode, Clone, Copy, PartialEq, Eq, TypeInfo)] +pub enum SwapLimit { + /// use exact amount supply amount to swap. (exact_supply_amount, minimum_target_amount) + ExactSupply(Balance, Balance), + /// swap to get exact amount target. (maximum_supply_amount, exact_target_amount) + ExactTarget(Balance, Balance), +} + +pub trait SwapManager { + fn get_liquidity_pool( + currency_id_a: CurrencyId, + currency_id_b: CurrencyId + ) -> (Balance, Balance); + + fn get_liquidity_token_address( + currency_id_a: CurrencyId, + currency_id_b: CurrencyId + ) -> Option; + + fn get_swap_amount( + path: &[CurrencyId], + limit: SwapLimit + ) -> Option<(Balance, Balance)>; + + fn get_best_price_swap_path( + supply_currency_id: CurrencyId, + target_currency_id: CurrencyId, + limit: SwapLimit, + alternative_path_joint_list: Vec>, + ) -> Option<(Vec, Balance, Balance)>; + + fn swap_with_specific_path( + who: &AccountId, + path: &[CurrencyId], + limit: SwapLimit, + ) -> Result<(Balance, Balance), DispatchError>; + + fn add_liquidity( + who: &AccountId, + currency_id_a: CurrencyId, + currency_id_b: CurrencyId, + max_amount_a: Balance, + max_amount_b: Balance, + min_share_increment: Balance, + ) -> Result<(Balance, Balance, Balance), DispatchError>; + + fn remove_liquidity( + who: &AccountId, + currency_id_a: CurrencyId, + currency_id_b: CurrencyId, + remove_share: Balance, + min_withdrawn_a: Balance, + min_withdrawn_b: Balance, + by_unstake: bool, + ) -> Result<(Balance, Balance), DispatchError>; +} + +pub trait Swap +where + CurrencyId: Clone, +{ + fn get_swap_amount( + supply_currency_id: CurrencyId, + target_currency_id: CurrencyId, + limit: SwapLimit, + ) -> Option<(Balance, Balance)>; + + fn swap( + who: &AccountId, + supply_currency_id: CurrencyId, + target_currency_id: CurrencyId, + limit: SwapLimit, + ) -> Result<(Balance, Balance), DispatchError>; + + fn swap_by_path( + who: &AccountId, + swap_path: &[CurrencyId], + limit: SwapLimit, + ) -> Result<(Balance, Balance), DispatchError>; +} + +#[derive(Eq, PartialEq, RuntimeDebug)] +pub enum SwapError { + CannotSwap, +} + +impl Into for SwapError { + fn into(self) -> DispatchError { + DispatchError::Other("Cannot swap") + } +} + +// Dex wrapper of Swap implementation +pub struct SpecificJointsSwap(sp_std::marker::PhantomData<(Dex, Joints)>); + +impl Swap + for SpecificJointsSwap +where + Dex: SwapManager, + Joints: Get>>, + Balance: Clone, + CurrencyId: Clone, +{ + fn get_swap_amount( + supply_currency_id: CurrencyId, + target_currency_id: CurrencyId, + limit: SwapLimit, + ) -> Option<(Balance, Balance)> { + >::get_best_price_swap_path( + supply_currency_id, + target_currency_id, + limit, + Joints::get(), + ) + .map(|(_, supply_amount, target_amount)| (supply_amount, target_amount)) + } + + fn swap( + who: &AccountId, + supply_currency_id: CurrencyId, + target_currency_id: CurrencyId, + limit: SwapLimit, + ) -> sp_std::result::Result<(Balance, Balance), DispatchError> { + let path = >::get_best_price_swap_path( + supply_currency_id, + target_currency_id, + limit.clone(), + Joints::get(), + ) + .ok_or_else(|| Into::::into(SwapError::CannotSwap))? + .0; + + >::swap_with_specific_path(who, &path, limit) + } + + fn swap_by_path( + who: &AccountId, + swap_path: &[CurrencyId], + limit: SwapLimit, + ) -> Result<(Balance, Balance), DispatchError> { + >::swap_with_specific_path(who, swap_path, limit) + } +} + +#[cfg(feature = "std")] +impl SwapManager for () +where + Balance: Default, +{ + fn get_liquidity_pool(_currency_id_a: CurrencyId, _currency_id_b: CurrencyId) -> (Balance, Balance) { + Default::default() + } + + fn get_liquidity_token_address(_currency_id_a: CurrencyId, _currency_id_b: CurrencyId) -> Option { + Some(Default::default()) + } + + fn get_swap_amount(_path: &[CurrencyId], _limit: SwapLimit) -> Option<(Balance, Balance)> { + Some(Default::default()) + } + + fn get_best_price_swap_path( + _supply_currency_id: CurrencyId, + _target_currency_id: CurrencyId, + _limit: SwapLimit, + _alternative_path_joint_list: Vec>, + ) -> Option<(Vec, Balance, Balance)> { + Some(Default::default()) + } + + fn swap_with_specific_path( + _who: &AccountId, + _path: &[CurrencyId], + _limit: SwapLimit, + ) -> Result<(Balance, Balance), DispatchError> { + Ok(Default::default()) + } + + fn add_liquidity( + _who: &AccountId, + _currency_id_a: CurrencyId, + _currency_id_b: CurrencyId, + _max_amount_a: Balance, + _max_amount_b: Balance, + _min_share_increment: Balance, + ) -> Result<(Balance, Balance, Balance), DispatchError> { + Ok(Default::default()) + } + + fn remove_liquidity( + _who: &AccountId, + _currency_id_a: CurrencyId, + _currency_id_b: CurrencyId, + _remove_share: Balance, + _min_withdrawn_a: Balance, + _min_withdrawn_b: Balance, + _by_unstake: bool, + ) -> Result<(Balance, Balance), DispatchError> { + Ok(Default::default()) + } +} diff --git a/blockchain/modules/support/src/dex.rs b/blockchain/modules/support/src/edfis_legacy.rs similarity index 96% rename from blockchain/modules/support/src/dex.rs rename to blockchain/modules/support/src/edfis_legacy.rs index aea21420..e9848cdc 100644 --- a/blockchain/modules/support/src/dex.rs +++ b/blockchain/modules/support/src/edfis_legacy.rs @@ -1,223 +1,223 @@ -// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم - -// This file is part of Setheum. - -// Copyright (C) 2019-Present Setheum Labs. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -use frame_support::{ensure, traits::Get}; -use parity_scale_codec::{Decode, Encode}; -use scale_info::TypeInfo; -#[cfg(feature = "std")] -use serde::{Deserialize, Serialize}; -use sp_core::H160; -use sp_runtime::{DispatchError, RuntimeDebug}; -use sp_std::{cmp::PartialEq, prelude::*, result::Result}; - -#[derive(RuntimeDebug, Encode, Decode, Clone, Copy, PartialEq, Eq, TypeInfo)] -pub enum SwapLimit { - /// use exact amount supply amount to swap. (exact_supply_amount, minimum_target_amount) - ExactSupply(Balance, Balance), - /// swap to get exact amount target. (maximum_supply_amount, exact_target_amount) - ExactTarget(Balance, Balance), -} - -pub trait SwapManager { - fn get_liquidity_pool(currency_id_a: CurrencyId, currency_id_b: CurrencyId) -> (Balance, Balance); - - fn get_liquidity_token_address(currency_id_a: CurrencyId, currency_id_b: CurrencyId) -> Option; - - fn get_swap_amount(path: &[CurrencyId], limit: SwapLimit) -> Option<(Balance, Balance)>; - - fn get_best_price_swap_path( - supply_currency_id: CurrencyId, - target_currency_id: CurrencyId, - limit: SwapLimit, - alternative_path_joint_list: Vec>, - ) -> Option<(Vec, Balance, Balance)>; - - fn swap_with_specific_path( - who: &AccountId, - path: &[CurrencyId], - limit: SwapLimit, - ) -> Result<(Balance, Balance), DispatchError>; - - fn add_liquidity( - who: &AccountId, - currency_id_a: CurrencyId, - currency_id_b: CurrencyId, - max_amount_a: Balance, - max_amount_b: Balance, - min_share_increment: Balance, - stake_increment_share: bool, - ) -> Result<(Balance, Balance, Balance), DispatchError>; - - fn remove_liquidity( - who: &AccountId, - currency_id_a: CurrencyId, - currency_id_b: CurrencyId, - remove_share: Balance, - min_withdrawn_a: Balance, - min_withdrawn_b: Balance, - by_unstake: bool, - ) -> Result<(Balance, Balance), DispatchError>; -} - -pub trait Swap -where - CurrencyId: Clone, -{ - fn get_swap_amount( - supply_currency_id: CurrencyId, - target_currency_id: CurrencyId, - limit: SwapLimit, - ) -> Option<(Balance, Balance)>; - - fn swap( - who: &AccountId, - supply_currency_id: CurrencyId, - target_currency_id: CurrencyId, - limit: SwapLimit, - ) -> Result<(Balance, Balance), DispatchError>; - - fn swap_by_path( - who: &AccountId, - swap_path: &[CurrencyId], - limit: SwapLimit, - ) -> Result<(Balance, Balance), DispatchError>; -} - -#[derive(Eq, PartialEq, RuntimeDebug)] -pub enum SwapError { - CannotSwap, -} - -impl Into for SwapError { - fn into(self) -> DispatchError { - DispatchError::Other("Cannot swap") - } -} - -// Dex wrapper of Swap implementation -pub struct SpecificJointsSwap(sp_std::marker::PhantomData<(Dex, Joints)>); - -impl Swap - for SpecificJointsSwap -where - Dex: SwapManager, - Joints: Get>>, - Balance: Clone, - CurrencyId: Clone, -{ - fn get_swap_amount( - supply_currency_id: CurrencyId, - target_currency_id: CurrencyId, - limit: SwapLimit, - ) -> Option<(Balance, Balance)> { - >::get_best_price_swap_path( - supply_currency_id, - target_currency_id, - limit, - Joints::get(), - ) - .map(|(_, supply_amount, target_amount)| (supply_amount, target_amount)) - } - - fn swap( - who: &AccountId, - supply_currency_id: CurrencyId, - target_currency_id: CurrencyId, - limit: SwapLimit, - ) -> sp_std::result::Result<(Balance, Balance), DispatchError> { - let path = >::get_best_price_swap_path( - supply_currency_id, - target_currency_id, - limit.clone(), - Joints::get(), - ) - .ok_or_else(|| Into::::into(SwapError::CannotSwap))? - .0; - - >::swap_with_specific_path(who, &path, limit) - } - - fn swap_by_path( - who: &AccountId, - swap_path: &[CurrencyId], - limit: SwapLimit, - ) -> Result<(Balance, Balance), DispatchError> { - >::swap_with_specific_path(who, swap_path, limit) - } -} - -#[cfg(feature = "std")] -impl SwapManager for () -where - Balance: Default, -{ - fn get_liquidity_pool(_currency_id_a: CurrencyId, _currency_id_b: CurrencyId) -> (Balance, Balance) { - Default::default() - } - - fn get_liquidity_token_address(_currency_id_a: CurrencyId, _currency_id_b: CurrencyId) -> Option { - Some(Default::default()) - } - - fn get_swap_amount(_path: &[CurrencyId], _limit: SwapLimit) -> Option<(Balance, Balance)> { - Some(Default::default()) - } - - fn get_best_price_swap_path( - _supply_currency_id: CurrencyId, - _target_currency_id: CurrencyId, - _limit: SwapLimit, - _alternative_path_joint_list: Vec>, - ) -> Option<(Vec, Balance, Balance)> { - Some(Default::default()) - } - - fn swap_with_specific_path( - _who: &AccountId, - _path: &[CurrencyId], - _limit: SwapLimit, - ) -> Result<(Balance, Balance), DispatchError> { - Ok(Default::default()) - } - - fn add_liquidity( - _who: &AccountId, - _currency_id_a: CurrencyId, - _currency_id_b: CurrencyId, - _max_amount_a: Balance, - _max_amount_b: Balance, - _min_share_increment: Balance, - _stake_increment_share: bool, - ) -> Result<(Balance, Balance, Balance), DispatchError> { - Ok(Default::default()) - } - - fn remove_liquidity( - _who: &AccountId, - _currency_id_a: CurrencyId, - _currency_id_b: CurrencyId, - _remove_share: Balance, - _min_withdrawn_a: Balance, - _min_withdrawn_b: Balance, - _by_unstake: bool, - ) -> Result<(Balance, Balance), DispatchError> { - Ok(Default::default()) - } -} +// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم + +// This file is part of Setheum. + +// Copyright (C) 2019-Present Setheum Labs. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use frame_support::{ensure, traits::Get}; +use parity_scale_codec::{Decode, Encode}; +use scale_info::TypeInfo; +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; +use sp_core::H160; +use sp_runtime::{DispatchError, RuntimeDebug}; +use sp_std::{cmp::PartialEq, prelude::*, result::Result}; + +#[derive(RuntimeDebug, Encode, Decode, Clone, Copy, PartialEq, Eq, TypeInfo)] +pub enum SwapLimit { + /// use exact amount supply amount to swap. (exact_supply_amount, minimum_target_amount) + ExactSupply(Balance, Balance), + /// swap to get exact amount target. (maximum_supply_amount, exact_target_amount) + ExactTarget(Balance, Balance), +} + +pub trait SwapManager { + fn get_liquidity_pool(currency_id_a: CurrencyId, currency_id_b: CurrencyId) -> (Balance, Balance); + + fn get_liquidity_token_address(currency_id_a: CurrencyId, currency_id_b: CurrencyId) -> Option; + + fn get_swap_amount(path: &[CurrencyId], limit: SwapLimit) -> Option<(Balance, Balance)>; + + fn get_best_price_swap_path( + supply_currency_id: CurrencyId, + target_currency_id: CurrencyId, + limit: SwapLimit, + alternative_path_joint_list: Vec>, + ) -> Option<(Vec, Balance, Balance)>; + + fn swap_with_specific_path( + who: &AccountId, + path: &[CurrencyId], + limit: SwapLimit, + ) -> Result<(Balance, Balance), DispatchError>; + + fn add_liquidity( + who: &AccountId, + currency_id_a: CurrencyId, + currency_id_b: CurrencyId, + max_amount_a: Balance, + max_amount_b: Balance, + min_share_increment: Balance, + stake_increment_share: bool, + ) -> Result<(Balance, Balance, Balance), DispatchError>; + + fn remove_liquidity( + who: &AccountId, + currency_id_a: CurrencyId, + currency_id_b: CurrencyId, + remove_share: Balance, + min_withdrawn_a: Balance, + min_withdrawn_b: Balance, + by_unstake: bool, + ) -> Result<(Balance, Balance), DispatchError>; +} + +pub trait Swap +where + CurrencyId: Clone, +{ + fn get_swap_amount( + supply_currency_id: CurrencyId, + target_currency_id: CurrencyId, + limit: SwapLimit, + ) -> Option<(Balance, Balance)>; + + fn swap( + who: &AccountId, + supply_currency_id: CurrencyId, + target_currency_id: CurrencyId, + limit: SwapLimit, + ) -> Result<(Balance, Balance), DispatchError>; + + fn swap_by_path( + who: &AccountId, + swap_path: &[CurrencyId], + limit: SwapLimit, + ) -> Result<(Balance, Balance), DispatchError>; +} + +#[derive(Eq, PartialEq, RuntimeDebug)] +pub enum SwapError { + CannotSwap, +} + +impl Into for SwapError { + fn into(self) -> DispatchError { + DispatchError::Other("Cannot swap") + } +} + +// Dex wrapper of Swap implementation +pub struct SpecificJointsSwap(sp_std::marker::PhantomData<(Dex, Joints)>); + +impl Swap + for SpecificJointsSwap +where + Dex: SwapManager, + Joints: Get>>, + Balance: Clone, + CurrencyId: Clone, +{ + fn get_swap_amount( + supply_currency_id: CurrencyId, + target_currency_id: CurrencyId, + limit: SwapLimit, + ) -> Option<(Balance, Balance)> { + >::get_best_price_swap_path( + supply_currency_id, + target_currency_id, + limit, + Joints::get(), + ) + .map(|(_, supply_amount, target_amount)| (supply_amount, target_amount)) + } + + fn swap( + who: &AccountId, + supply_currency_id: CurrencyId, + target_currency_id: CurrencyId, + limit: SwapLimit, + ) -> sp_std::result::Result<(Balance, Balance), DispatchError> { + let path = >::get_best_price_swap_path( + supply_currency_id, + target_currency_id, + limit.clone(), + Joints::get(), + ) + .ok_or_else(|| Into::::into(SwapError::CannotSwap))? + .0; + + >::swap_with_specific_path(who, &path, limit) + } + + fn swap_by_path( + who: &AccountId, + swap_path: &[CurrencyId], + limit: SwapLimit, + ) -> Result<(Balance, Balance), DispatchError> { + >::swap_with_specific_path(who, swap_path, limit) + } +} + +#[cfg(feature = "std")] +impl SwapManager for () +where + Balance: Default, +{ + fn get_liquidity_pool(_currency_id_a: CurrencyId, _currency_id_b: CurrencyId) -> (Balance, Balance) { + Default::default() + } + + fn get_liquidity_token_address(_currency_id_a: CurrencyId, _currency_id_b: CurrencyId) -> Option { + Some(Default::default()) + } + + fn get_swap_amount(_path: &[CurrencyId], _limit: SwapLimit) -> Option<(Balance, Balance)> { + Some(Default::default()) + } + + fn get_best_price_swap_path( + _supply_currency_id: CurrencyId, + _target_currency_id: CurrencyId, + _limit: SwapLimit, + _alternative_path_joint_list: Vec>, + ) -> Option<(Vec, Balance, Balance)> { + Some(Default::default()) + } + + fn swap_with_specific_path( + _who: &AccountId, + _path: &[CurrencyId], + _limit: SwapLimit, + ) -> Result<(Balance, Balance), DispatchError> { + Ok(Default::default()) + } + + fn add_liquidity( + _who: &AccountId, + _currency_id_a: CurrencyId, + _currency_id_b: CurrencyId, + _max_amount_a: Balance, + _max_amount_b: Balance, + _min_share_increment: Balance, + _stake_increment_share: bool, + ) -> Result<(Balance, Balance, Balance), DispatchError> { + Ok(Default::default()) + } + + fn remove_liquidity( + _who: &AccountId, + _currency_id_a: CurrencyId, + _currency_id_b: CurrencyId, + _remove_share: Balance, + _min_withdrawn_a: Balance, + _min_withdrawn_b: Balance, + _by_unstake: bool, + ) -> Result<(Balance, Balance), DispatchError> { + Ok(Default::default()) + } +} diff --git a/blockchain/modules/support/src/lib.rs b/blockchain/modules/support/src/lib.rs index 77c2c72e..4bff5e59 100644 --- a/blockchain/modules/support/src/lib.rs +++ b/blockchain/modules/support/src/lib.rs @@ -24,7 +24,7 @@ #![allow(clippy::type_complexity)] use frame_support::pallet_prelude::{DispatchClass, Pays, Weight}; -use primitives::{task::TaskResult, Balance, CurrencyId, Multiplier, Nonce, ReserveIdentifier}; +use primitives::{task::TaskResult, Balance, CurrencyId, Fees, Multiplier, Nonce, ReserveIdentifier}; use sp_runtime::{ traits::CheckedDiv, transaction_validity::TransactionValidityError, DispatchError, DispatchResult, FixedU128, }; @@ -32,7 +32,8 @@ use sp_std::{prelude::*, result::Result}; use xcm::prelude::*; pub mod bounded; -pub mod dex; +pub mod edfis; +pub mod edfis_legacy; pub mod evm; pub mod liquid_staking; pub mod ecdp; @@ -40,7 +41,8 @@ pub mod incentives; pub mod mocks; pub use crate::bounded::*; -pub use crate::dex::*; +pub use crate::edfis::*; +pub use crate::edfis_legacy::*; pub use crate::evm::*; pub use crate::liquid_staking::*; pub use crate::ecdp::*; diff --git a/blockchain/primitives/src/lib.rs b/blockchain/primitives/src/lib.rs index ed211209..60b87042 100644 --- a/blockchain/primitives/src/lib.rs +++ b/blockchain/primitives/src/lib.rs @@ -91,6 +91,9 @@ pub type Balance = u128; /// Signed version of Balance pub type Amount = i128; +/// Fees type primarily for Edfis `ExchangeFee` and `TradingFee`. +pub type Fees = u128; + /// Auction ID pub type AuctionId = u32; @@ -180,7 +183,7 @@ impl Decode for TradingPair { } #[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, Default, MaxEncodedLen, TypeInfo)] -pub struct Position { +pub struct ECDPPosition { /// The amount of collateral. pub collateral: Balance, /// The amount of debit. diff --git a/blockchain/resources/types.json b/blockchain/resources/types.json index a430a99e..e109ca78 100644 --- a/blockchain/resources/types.json +++ b/blockchain/resources/types.json @@ -211,7 +211,7 @@ "Dex": "CurrencyId" } }, - "Position": { + "ECDPPosition": { "collateral": "Balance", "debit": "Balance" },