diff --git a/Cargo.lock b/Cargo.lock
index 276de1227..8f55f93bc 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -8034,7 +8034,7 @@ dependencies = [
[[package]]
name = "setheum-dex"
-version = "0.9.0"
+version = "0.8.0"
dependencies = [
"frame-benchmarking 3.1.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.8)",
"frame-support 3.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.8)",
diff --git a/README.md b/README.md
index f9475a16f..940adde76 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Setheum's Blockchain Network node Implementation in Rust, Substrate FRAME and Se
-[![Setheum version](https://img.shields.io/badge/Setheum-0.8.0-brightgreen?logo=Parity%20Substrate)](https://setheum.xyz/)
+[![Setheum version](https://img.shields.io/badge/Setheum-0.9.0-brightgreen?logo=Parity%20Substrate)](https://setheum.xyz/)
[![Substrate version](https://img.shields.io/badge/Substrate-3.0.0-brightgreen?logo=Parity%20Substrate)](https://substrate.dev/)
[![License](https://img.shields.io/github/license/Setheum-Labs/Setheum?color=green)](https://github.com/Setheum-Labs/Setheum/blob/master/LICENSE)
@@ -39,7 +39,7 @@ DRAM("Setheum Dirham", 12) = 1, // Staking Reward and Governance Token - System
SETR("Setter", 12) = 2,
```
-#### The SetCurrencies - SERP Stablecoins
+#### The SettCurrencies - SERP Stablecoins
```
SETUSD("SetDollar", 12) = 3,
SETEUR("SetEuro", 12) = 4,
@@ -48,7 +48,7 @@ DRAM("Setheum Dirham", 12) = 1, // Staking Reward and Governance Token - System
SETSAR("SetRiyal", 12) = 7,
```
-1. The Setter - The Setter is a basket currency pegged to the Top 10 Strongest and most valuable currencies. It serves as the medium of Exchange and the Defacto stablecoin of the Setheum Ecosystem. All other Setheum system stablecoins orbit around the Setter (SETR) and the SettMint for minting Setheum Currencies (system stablecoins) accepts only the Setter as the Minting Reserve Asset. Only with the Setter (SETR) can a user participate in the DNAR Auctions to stabilize the price of the Setter, while the Setter is Auctioned to stabilize the price of all the other SetCurrencies (system stablecoins). It's the star that brightens many planets - 10 to be exact
+1. The Setter - The Setter is a basket currency pegged to the Top 10 Strongest and most valuable currencies. It serves as the medium of Exchange and the Defacto stablecoin of the Setheum Ecosystem. All other Setheum system stablecoins orbit around the Setter (SETR) and the SettMint for minting Setheum Currencies (system stablecoins) accepts only the Setter as the Minting Reserve Asset. Only with the Setter (SETR) can a user participate in the DNAR Auctions to stabilize the price of the Setter, while the Setter is Auctioned to stabilize the price of all the other SettCurrencies (system stablecoins). It's the star that brightens many planets - 10 to be exact
2. [The SERP](./lib-serp) - The SERP (Setheum Elastic Reserve Protocol) is algorithmically responsible for stabilizing the prices of the Setheum Stable Currencies. No human interferrance is needed for this, it's all algorithmically handled by the SERP. The SERP is the backbone of Setheum, it is based on my TES (Token Elasticity of Supply) algorithm based on PES (Price Elasticity of Supply) such that the demand curve or price of a currency determines the supply serping point, meaning the supply curve of a SetCurrency will be adjusted according to the demand curve of that specific SetCurrency. The result will be burning or minting an amount equivalent to the serping point produced by the SERP-TES, the burning amount will be bought back by the SERP automatically through the built-in-DEX and the bought amount will be burnt to meet the satisfaction of the demand curve to prop the price back up to its peg, the opposite is done to lower the price of an under-supplied currency that is on demand and above its peg on the demand curve, for this the mint amount is divided into receipients including the SettPayTreasury where CashDrops are deposited for users to claim, the System Treasury under Governance, the Charity Fund stewarded by the Setheum Foundation, and the WelfareTreasury, more on the Welfare Treasury below.
diff --git a/lib-serml/dex/dex/Cargo.toml b/lib-serml/dex/dex/Cargo.toml
index 994f1f8b1..101287773 100644
--- a/lib-serml/dex/dex/Cargo.toml
+++ b/lib-serml/dex/dex/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "setheum-dex"
-version = "0.9.0"
+version = "0.8.0"
authors = ["Setheum Labs"]
edition = "2018"
diff --git a/lib-serml/dex/dex/src/lib.rs b/lib-serml/dex/dex/src/lib.rs
index 2fe56f292..b5eaaeb66 100644
--- a/lib-serml/dex/dex/src/lib.rs
+++ b/lib-serml/dex/dex/src/lib.rs
@@ -36,7 +36,7 @@ use orml_traits::{MultiCurrency, MultiCurrencyExtended};
use primitives::{Balance, CurrencyId, TradingPair};
use sp_core::{H160, U256};
use sp_runtime::{
- traits::{AccountIdConversion, Bounded, One, Zero},
+ traits::{AccountIdConversion, One, Zero},
ArithmeticError, DispatchError, DispatchResult, FixedPointNumber, RuntimeDebug, SaturatedConversion,
};
use sp_std::{convert::TryInto, prelude::*, vec};
@@ -144,8 +144,6 @@ pub mod module {
InsufficientTargetAmount,
/// Supply amount is more than max_supply_amount
ExcessiveSupplyAmount,
- /// The swap will cause unacceptable price impact
- ExceedPriceImpactLimit,
/// Liquidity is not enough
InsufficientLiquidity,
/// The supply amount is zero
@@ -307,10 +305,10 @@ pub mod module {
path: Vec
,
#[pallet::compact] supply_amount: Balance,
#[pallet::compact] min_target_amount: Balance,
- ) -> DispatchResultWithPostInfo {
+ ) -> DispatchResult {
let who = ensure_signed(origin)?;
- Self::do_swap_with_exact_supply(&who, &path, supply_amount, min_target_amount, None)?;
- Ok(().into())
+ Self::do_swap_with_exact_supply(&who, &path, supply_amount, min_target_amount)?;
+ Ok(())
}
/// Trading with DEX, swap with exact target amount
@@ -325,10 +323,10 @@ pub mod module {
path: Vec,
#[pallet::compact] target_amount: Balance,
#[pallet::compact] max_supply_amount: Balance,
- ) -> DispatchResultWithPostInfo {
+ ) -> DispatchResult {
let who = ensure_signed(origin)?;
- Self::do_swap_with_exact_target(&who, &path, target_amount, max_supply_amount, None)?;
- Ok(().into())
+ Self::do_swap_with_exact_target(&who, &path, target_amount, max_supply_amount)?;
+ Ok(())
}
/// Add liquidity to Enabled trading pair.
@@ -351,7 +349,7 @@ pub mod module {
#[pallet::compact] max_amount_a: Balance,
#[pallet::compact] max_amount_b: Balance,
#[pallet::compact] min_share_increment: Balance,
- ) -> DispatchResultWithPostInfo {
+ ) -> DispatchResult {
let who = ensure_signed(origin)?;
Self::do_add_liquidity(
&who,
@@ -361,7 +359,7 @@ pub mod module {
max_amount_b,
min_share_increment,
)?;
- Ok(().into())
+ Ok(())
}
/// Add provision to Provisioning trading pair.
@@ -380,10 +378,10 @@ pub mod module {
currency_id_b: CurrencyId,
#[pallet::compact] amount_a: Balance,
#[pallet::compact] amount_b: Balance,
- ) -> DispatchResultWithPostInfo {
+ ) -> DispatchResult {
let who = ensure_signed(origin)?;
Self::do_add_provision(&who, currency_id_a, currency_id_b, amount_a, amount_b)?;
- Ok(().into())
+ Ok(())
}
/// Claim dex share for founders who have participated in trading pair provision.
@@ -398,10 +396,10 @@ pub mod module {
owner: T::AccountId,
currency_id_a: CurrencyId,
currency_id_b: CurrencyId,
- ) -> DispatchResultWithPostInfo {
+ ) -> DispatchResult {
let _ = ensure_signed(origin)?;
Self::do_claim_dex_share(&owner, currency_id_a, currency_id_b)?;
- Ok(().into())
+ Ok(())
}
/// Remove liquidity from specific liquidity pool in the form of burning
@@ -422,7 +420,7 @@ pub mod module {
#[pallet::compact] remove_share: Balance,
#[pallet::compact] min_withdrawn_a: Balance,
#[pallet::compact] min_withdrawn_b: Balance,
- ) -> DispatchResultWithPostInfo {
+ ) -> DispatchResult {
let who = ensure_signed(origin)?;
Self::do_remove_liquidity(
&who,
@@ -432,7 +430,7 @@ pub mod module {
min_withdrawn_a,
min_withdrawn_b,
)?;
- Ok(().into())
+ Ok(())
}
/// List a new provisioning trading pair.
@@ -447,7 +445,7 @@ pub mod module {
target_provision_a: Balance,
target_provision_b: Balance,
not_before: T::BlockNumber,
- ) -> DispatchResultWithPostInfo {
+ ) -> DispatchResult {
T::ListingOrigin::ensure_origin(origin)?;
let trading_pair =
@@ -494,7 +492,7 @@ pub mod module {
}),
);
Self::deposit_event(Event::ListProvisioning(trading_pair));
- Ok(().into())
+ Ok(())
}
/// List a new trading pair, trading pair will become Enabled status
@@ -510,7 +508,7 @@ pub mod module {
target_provision_a: Balance,
target_provision_b: Balance,
not_before: T::BlockNumber,
- ) -> DispatchResultWithPostInfo {
+ ) -> DispatchResult {
T::ListingOrigin::ensure_origin(origin)?;
let trading_pair =
TradingPair::from_currency_ids(currency_id_a, currency_id_b).ok_or(Error::::InvalidCurrencyId)?;
@@ -541,7 +539,7 @@ pub mod module {
_ => return Err(Error::::MustBeProvisioning.into()),
}
- Ok(().into())
+ Ok(())
}
/// Enable a Provisioning trading pair if meet the condition.
@@ -551,7 +549,7 @@ pub mod module {
origin: OriginFor,
currency_id_a: CurrencyId,
currency_id_b: CurrencyId,
- ) -> DispatchResultWithPostInfo {
+ ) -> DispatchResult {
let _ = ensure_signed(origin)?;
let trading_pair =
@@ -618,7 +616,7 @@ pub mod module {
_ => return Err(Error::::MustBeProvisioning.into()),
}
- Ok(().into())
+ Ok(())
}
/// Enable a trading pair
@@ -630,7 +628,7 @@ pub mod module {
origin: OriginFor,
currency_id_a: CurrencyId,
currency_id_b: CurrencyId,
- ) -> DispatchResultWithPostInfo {
+ ) -> DispatchResult {
T::ListingOrigin::ensure_origin(origin)?;
let trading_pair =
TradingPair::from_currency_ids(currency_id_a, currency_id_b).ok_or(Error::::InvalidCurrencyId)?;
@@ -648,7 +646,7 @@ pub mod module {
TradingPairStatuses::::insert(trading_pair, TradingPairStatus::Enabled);
Self::deposit_event(Event::EnableTradingPair(trading_pair));
- Ok(().into())
+ Ok(())
}
/// Disable a `Enabled` trading pair.
@@ -658,7 +656,7 @@ pub mod module {
origin: OriginFor,
currency_id_a: CurrencyId,
currency_id_b: CurrencyId,
- ) -> DispatchResultWithPostInfo {
+ ) -> DispatchResult {
T::ListingOrigin::ensure_origin(origin)?;
let trading_pair =
TradingPair::from_currency_ids(currency_id_a, currency_id_b).ok_or(Error::::InvalidCurrencyId)?;
@@ -672,7 +670,7 @@ pub mod module {
TradingPairStatuses::::insert(trading_pair, TradingPairStatus::Disabled);
Self::deposit_event(Event::DisableTradingPair(trading_pair));
- Ok(().into())
+ Ok(())
}
}
}
@@ -1022,7 +1020,6 @@ impl Pallet {
fn get_target_amounts(
path: &[CurrencyId],
supply_amount: Balance,
- price_impact_limit: Option,
) -> sp_std::result::Result, DispatchError> {
let path_length = path.len();
ensure!(
@@ -1051,13 +1048,6 @@ impl Pallet {
let target_amount = Self::get_target_amount(supply_pool, target_pool, target_amounts[i]);
ensure!(!target_amount.is_zero(), Error::::ZeroTargetAmount);
- // check price impact if limit exists
- if let Some(limit) = price_impact_limit {
- let price_impact =
- Ratio::checked_from_rational(target_amount, target_pool).unwrap_or_else(Ratio::max_value);
- ensure!(price_impact <= limit, Error::::ExceedPriceImpactLimit);
- }
-
target_amounts[i + 1] = target_amount;
i += 1;
}
@@ -1068,7 +1058,6 @@ impl Pallet {
fn get_supply_amounts(
path: &[CurrencyId],
target_amount: Balance,
- price_impact_limit: Option,
) -> sp_std::result::Result, DispatchError> {
let path_length = path.len();
ensure!(
@@ -1097,13 +1086,6 @@ impl Pallet {
let supply_amount = Self::get_supply_amount(supply_pool, target_pool, supply_amounts[i]);
ensure!(!supply_amount.is_zero(), Error::::ZeroSupplyAmount);
- // check price impact if limit exists
- if let Some(limit) = price_impact_limit {
- let price_impact =
- Ratio::checked_from_rational(supply_amounts[i], target_pool).unwrap_or_else(Ratio::max_value);
- ensure!(price_impact <= limit, Error::::ExceedPriceImpactLimit);
- };
-
supply_amounts[i - 1] = supply_amount;
i -= 1;
}
@@ -1164,9 +1146,8 @@ impl Pallet {
path: &[CurrencyId],
supply_amount: Balance,
min_target_amount: Balance,
- price_impact_limit: Option,
) -> sp_std::result::Result {
- let amounts = Self::get_target_amounts(&path, supply_amount, price_impact_limit)?;
+ let amounts = Self::get_target_amounts(&path, supply_amount)?;
ensure!(
amounts[amounts.len() - 1] >= min_target_amount,
Error::::InsufficientTargetAmount
@@ -1194,9 +1175,8 @@ impl Pallet {
path: &[CurrencyId],
target_amount: Balance,
max_supply_amount: Balance,
- price_impact_limit: Option,
) -> sp_std::result::Result {
- let amounts = Self::get_supply_amounts(&path, target_amount, price_impact_limit)?;
+ let amounts = Self::get_supply_amounts(&path, target_amount)?;
ensure!(amounts[0] <= max_supply_amount, Error::::ExcessiveSupplyAmount);
let module_account_id = Self::account_id();
let actual_supply_amount = amounts[0];
@@ -1225,22 +1205,14 @@ impl DEXManager for Pallet {
T::CurrencyIdMapping::encode_evm_address(trading_pair.dex_share_currency_id())
}
- fn get_swap_target_amount(
- path: &[CurrencyId],
- supply_amount: Balance,
- price_impact_limit: Option,
- ) -> Option {
- Self::get_target_amounts(&path, supply_amount, price_impact_limit)
+ fn get_swap_target_amount(path: &[CurrencyId], supply_amount: Balance) -> Option {
+ Self::get_target_amounts(&path, supply_amount)
.ok()
.map(|amounts| amounts[amounts.len() - 1])
}
- fn get_swap_supply_amount(
- path: &[CurrencyId],
- target_amount: Balance,
- price_impact_limit: Option,
- ) -> Option {
- Self::get_supply_amounts(&path, target_amount, price_impact_limit)
+ fn get_swap_supply_amount(path: &[CurrencyId], target_amount: Balance) -> Option {
+ Self::get_supply_amounts(&path, target_amount)
.ok()
.map(|amounts| amounts[0])
}
@@ -1250,9 +1222,8 @@ impl DEXManager for Pallet {
path: &[CurrencyId],
supply_amount: Balance,
min_target_amount: Balance,
- price_impact_limit: Option,
) -> sp_std::result::Result {
- Self::do_swap_with_exact_supply(who, path, supply_amount, min_target_amount, price_impact_limit)
+ Self::do_swap_with_exact_supply(who, path, supply_amount, min_target_amount)
}
fn swap_with_exact_target(
@@ -1260,9 +1231,8 @@ impl DEXManager for Pallet {
path: &[CurrencyId],
target_amount: Balance,
max_supply_amount: Balance,
- price_impact_limit: Option,
) -> sp_std::result::Result {
- Self::do_swap_with_exact_target(who, path, target_amount, max_supply_amount, price_impact_limit)
+ Self::do_swap_with_exact_target(who, path, target_amount, max_supply_amount)
}
// `do_add_liquidity` is used in genesis_build,
diff --git a/lib-serml/dex/dex/src/mock.rs b/lib-serml/dex/dex/src/mock.rs
index e50cdf73a..ae6e2ed99 100644
--- a/lib-serml/dex/dex/src/mock.rs
+++ b/lib-serml/dex/dex/src/mock.rs
@@ -23,7 +23,7 @@
use super::*;
use frame_support::{construct_runtime, ord_parameter_types, parameter_types};
use frame_system::EnsureSignedBy;
-use orml_traits::{parameter_type_with_key, MultiReservableCurrency};
+use orml_traits::parameter_type_with_key;
use primitives::{Amount, TokenSymbol};
use sp_core::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup};
diff --git a/lib-serml/dex/dex/src/tests.rs b/lib-serml/dex/dex/src/tests.rs
index 37a3f86d5..8bc128bab 100644
--- a/lib-serml/dex/dex/src/tests.rs
+++ b/lib-serml/dex/dex/src/tests.rs
@@ -664,31 +664,31 @@ fn get_target_amounts_work() {
LiquidityPool::::insert(SETUSDDRAMPair::get(), (50000, 10000));
LiquidityPool::::insert(SETUSDBTCPair::get(), (100000, 10));
assert_noop!(
- DexModule::get_target_amounts(&vec![DRAM], 10000, None),
+ DexModule::get_target_amounts(&vec![DRAM], 10000),
Error::::InvalidTradingPathLength,
);
assert_noop!(
- DexModule::get_target_amounts(&vec![DRAM, SETUSD, BTC, DRAM], 10000, None),
+ DexModule::get_target_amounts(&vec![DRAM, SETUSD, BTC, DRAM], 10000),
Error::::InvalidTradingPathLength,
);
assert_noop!(
- DexModule::get_target_amounts(&vec![DRAM, SETUSD, DNAR], 10000, None),
+ DexModule::get_target_amounts(&vec![DRAM, SETUSD, DNAR], 10000),
Error::::MustBeEnabled,
);
assert_eq!(
- DexModule::get_target_amounts(&vec![DRAM, SETUSD], 10000, None),
+ DexModule::get_target_amounts(&vec![DRAM, SETUSD], 10000),
Ok(vec![10000, 1652])
);
assert_eq!(
- DexModule::get_target_amounts(&vec![DRAM, SETUSD], 10000, Ratio::checked_from_rational(50, 100)),
+ DexModule::get_target_amounts(&vec![DRAM, SETUSD], 10000),
Ok(vec![10000, 1652])
);
assert_noop!(
- DexModule::get_target_amounts(&vec![DRAM, SETUSD, BTC], 100, None),
+ DexModule::get_target_amounts(&vec![DRAM, SETUSD, BTC], 100),
Error::::ZeroTargetAmount,
);
assert_noop!(
- DexModule::get_target_amounts(&vec![DRAM, BTC], 100, None),
+ DexModule::get_target_amounts(&vec![DRAM, BTC], 100),
Error::::InsufficientLiquidity,
);
});
@@ -729,23 +729,23 @@ fn get_supply_amounts_work() {
LiquidityPool::::insert(SETUSDDRAMPair::get(), (50000, 10000));
LiquidityPool::::insert(SETUSDBTCPair::get(), (100000, 10));
assert_noop!(
- DexModule::get_supply_amounts(&vec![DRAM], 10000, None),
+ DexModule::get_supply_amounts(&vec![DRAM], 10000),
Error::::InvalidTradingPathLength,
);
assert_noop!(
- DexModule::get_supply_amounts(&vec![DRAM, SETUSD, BTC, DRAM], 10000, None),
+ DexModule::get_supply_amounts(&vec![DRAM, SETUSD, BTC, DRAM], 10000),
Error::::InvalidTradingPathLength,
);
assert_noop!(
- DexModule::get_supply_amounts(&vec![DRAM, SETUSD, DNAR], 10000, None),
+ DexModule::get_supply_amounts(&vec![DRAM, SETUSD, DNAR], 10000),
Error::::MustBeEnabled,
);
assert_noop!(
- DexModule::get_supply_amounts(&vec![DRAM, SETUSD, BTC], 10000, None),
+ DexModule::get_supply_amounts(&vec![DRAM, SETUSD, BTC], 10000),
Error::::ZeroSupplyAmount,
);
assert_noop!(
- DexModule::get_supply_amounts(&vec![DRAM, BTC], 10000, None),
+ DexModule::get_supply_amounts(&vec![DRAM, BTC], 10000),
Error::::InsufficientLiquidity,
);
});
@@ -1075,26 +1075,15 @@ fn do_swap_with_exact_supply_work() {
&[DRAM, SETUSD],
100_000_000_000_000,
250_000_000_000_000,
- None
),
Error::::InsufficientTargetAmount
);
assert_noop!(
- DexModule::do_swap_with_exact_supply(
- &BOB,
- &[DRAM, SETUSD],
- 100_000_000_000_000,
- 0,
- Ratio::checked_from_rational(10, 100)
- ),
- Error::::ExceedPriceImpactLimit,
- );
- assert_noop!(
- DexModule::do_swap_with_exact_supply(&BOB, &[DRAM, SETUSD, BTC, DRAM], 100_000_000_000_000, 0, None),
+ DexModule::do_swap_with_exact_supply(&BOB, &[DRAM, SETUSD, BTC, DRAM], 100_000_000_000_000, 0),
Error::::InvalidTradingPathLength,
);
assert_noop!(
- DexModule::do_swap_with_exact_supply(&BOB, &[DRAM, DNAR], 100_000_000_000_000, 0, None),
+ DexModule::do_swap_with_exact_supply(&BOB, &[DRAM, DNAR], 100_000_000_000_000, 0),
Error::::MustBeEnabled,
);
@@ -1103,7 +1092,6 @@ fn do_swap_with_exact_supply_work() {
&[DRAM, SETUSD],
100_000_000_000_000,
200_000_000_000_000,
- None
));
System::assert_last_event(Event::DexModule(crate::Event::Swap(
BOB,
@@ -1134,7 +1122,6 @@ fn do_swap_with_exact_supply_work() {
&[DRAM, SETUSD, BTC],
200_000_000_000_000,
1,
- None
));
System::assert_last_event(Event::DexModule(crate::Event::Swap(
BOB,
@@ -1211,32 +1198,20 @@ fn do_swap_with_exact_target_work() {
&[DRAM, SETUSD],
250_000_000_000_000,
100_000_000_000_000,
- None
),
Error::::ExcessiveSupplyAmount
);
- assert_noop!(
- DexModule::do_swap_with_exact_target(
- &BOB,
- &[DRAM, SETUSD],
- 250_000_000_000_000,
- 200_000_000_000_000,
- Ratio::checked_from_rational(10, 100)
- ),
- Error::::ExceedPriceImpactLimit,
- );
assert_noop!(
DexModule::do_swap_with_exact_target(
&BOB,
&[DRAM, SETUSD, BTC, DRAM],
250_000_000_000_000,
200_000_000_000_000,
- None
),
Error::::InvalidTradingPathLength,
);
assert_noop!(
- DexModule::do_swap_with_exact_target(&BOB, &[DRAM, DNAR], 250_000_000_000_000, 200_000_000_000_000, None),
+ DexModule::do_swap_with_exact_target(&BOB, &[DRAM, DNAR], 250_000_000_000_000, 200_000_000_000_000),
Error::::MustBeEnabled,
);
@@ -1245,7 +1220,6 @@ fn do_swap_with_exact_target_work() {
&[DRAM, SETUSD],
250_000_000_000_000,
200_000_000_000_000,
- None
));
System::assert_last_event(Event::DexModule(crate::Event::Swap(
BOB,
@@ -1276,7 +1250,6 @@ fn do_swap_with_exact_target_work() {
&[DRAM, SETUSD, BTC],
5_000_000_000,
2_000_000_000_000_000,
- None
));
System::assert_last_event(Event::DexModule(crate::Event::Swap(
BOB,
diff --git a/lib-serml/serp/serp-ocw/Cargo.toml b/lib-serml/serp/serp-ocw/Cargo.toml
index ef9a70ff9..710620524 100644
--- a/lib-serml/serp/serp-ocw/Cargo.toml
+++ b/lib-serml/serp/serp-ocw/Cargo.toml
@@ -13,13 +13,14 @@ lite-json = { version = "0.1", default-features = false }
log = { version = "0.4.14", default-features = false }
fixed = { default-features = false, git = "https://github.com/encointer/substrate-fixed", package = "substrate-fixed" }
-frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
-frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
-sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
+# Substrate dependencies
+sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
+frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
+frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
+sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
+sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-keystore = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.8", optional = true }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
-sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
-sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
# orml dependencies
orml-traits = { path = "../../../lib-openrml/traits", default-features = false }
diff --git a/lib-serml/serp/serp-ocw/src/lib.rs b/lib-serml/serp/serp-ocw/src/lib.rs
index 03efd7c68..d482e2e31 100644
--- a/lib-serml/serp/serp-ocw/src/lib.rs
+++ b/lib-serml/serp/serp-ocw/src/lib.rs
@@ -672,24 +672,24 @@ impl Pallet {
}
/// Calculate the `min_target_amount` for `SerpUp` operation.
- fn calculate_min_target_amount(market_price: u64, dinar_price: u64, expand_by: Balance) -> Balance {
- type Fix = FixedU128;
- let expand_by_amount = Fix::from_num(1).saturating_mul_int(expand_by as u128);
- let relative_price = Fix::from_num(market_price) / Fix::from_num(dinar_price);
- let min_target_amount_full = Fix::from_num(expand_by_amount) / Fix::from_num(relative_price);
- let min_target_fraction = Fix::from_num(min_target_amount_full) / Fix::from_num(100);
- min_target_fraction.saturating_mul_int(94 as u128).to_num::()
- }
+ // fn calculate_min_target_amount(market_price: u64, dinar_price: u64, expand_by: Balance) -> Balance {
+ // type Fix = FixedU128;
+ // let expand_by_amount = Fix::from_num(1).saturating_mul_int(expand_by as u128);
+ // let relative_price = Fix::from_num(market_price) / Fix::from_num(dinar_price);
+ // let min_target_amount_full = Fix::from_num(expand_by_amount) / Fix::from_num(relative_price);
+ // let min_target_fraction = Fix::from_num(min_target_amount_full) / Fix::from_num(100);
+ // min_target_fraction.saturating_mul_int(94 as u128).to_num::()
+ // }
/// Calculate the `max_supply_amount` for `SerpUp` operation.
- fn calculate_max_supply_amount(market_price: u64, dinar_price: u64, contract_by: Balance) -> Balance {
- type Fix = FixedU128;
- let contract_by_amount = Fix::from_num(1).saturating_mul_int(contract_by as u128);
- let relative_price = Fix::from_num(market_price) / Fix::from_num(dinar_price);
- let max_supply_amount_full = Fix::from_num(contract_by_amount) / Fix::from_num(relative_price);
- let max_supply_fraction = Fix::from_num(max_supply_amount_full) / Fix::from_num(100);
- max_supply_fraction.saturating_mul_int(106 as u128).to_num::()
- }
+ // fn calculate_max_supply_amount(market_price: u64, dinar_price: u64, contract_by: Balance) -> Balance {
+ // type Fix = FixedU128;
+ // let contract_by_amount = Fix::from_num(1).saturating_mul_int(contract_by as u128);
+ // let relative_price = Fix::from_num(market_price) / Fix::from_num(dinar_price);
+ // let max_supply_amount_full = Fix::from_num(contract_by_amount) / Fix::from_num(relative_price);
+ // let max_supply_fraction = Fix::from_num(max_supply_amount_full) / Fix::from_num(100);
+ // max_supply_fraction.saturating_mul_int(106 as u128).to_num::()
+ // }
/// FETCH SETCURRENCIES COIN PRICES
///
@@ -944,19 +944,13 @@ impl Pallet {
// safe from underflow because `peg_price` is checked to be less than `market_price`
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
- // `min_target_amount` for `SerpUp` operation
- let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
-
- T::SerpTreasury::on_serpup(T::SetterCurrencyId::get(), expand_by, min_target_amount).unwrap();
+ T::SerpTreasury::on_serpup(T::SetterCurrencyId::get(), expand_by).unwrap();
}
market_price if market_price < peg_price => {
// safe from underflow because `peg_price` is checked to be greater than `market_price`
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
- // `max_supply_amount` for `SerpDown` operation
- let max_supply_amount = Self::calculate_max_supply_amount(market_price, dinar_price, contract_by);
-
- T::SerpTreasury::on_serpdown(T::SetterCurrencyId::get(), contract_by, max_supply_amount).unwrap();
+ T::SerpTreasury::on_serpdown(T::SetterCurrencyId::get(), contract_by).unwrap();
}
_ => {}
}
@@ -1073,19 +1067,13 @@ impl Pallet {
// safe from underflow because `peg_price` is checked to be less than `market_price`
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
- // `min_target_amount` for `SerpUp` operation
- let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
-
- T::SerpTreasury::on_serpup(T::GetSetUSDCurrencyId::get(), expand_by, min_target_amount).unwrap();
+ T::SerpTreasury::on_serpup(T::GetSetUSDCurrencyId::get(), expand_by).unwrap();
}
market_price if market_price < peg_price => {
// safe from underflow because `peg_price` is checked to be greater than `market_price`
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
- // `max_supply_amount` for `SerpDown` operation
- let max_supply_amount = Self::calculate_max_supply_amount(market_price, setter_price, contract_by);
-
- T::SerpTreasury::on_serpdown(T::GetSetUSDCurrencyId::get(), contract_by, max_supply_amount).unwrap();
+ T::SerpTreasury::on_serpdown(T::GetSetUSDCurrencyId::get(), contract_by).unwrap();
}
_ => {}
}
@@ -1202,19 +1190,13 @@ impl Pallet {
// safe from underflow because `peg_price` is checked to be less than `market_price`
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
- // `min_target_amount` for `SerpUp` operation
- let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
-
- T::SerpTreasury::on_serpup(T::GetSetEURCurrencyId::get(), expand_by, min_target_amount).unwrap();
+ T::SerpTreasury::on_serpup(T::GetSetEURCurrencyId::get(), expand_by).unwrap();
}
market_price if market_price < peg_price => {
// safe from underflow because `peg_price` is checked to be greater than `market_price`
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
- // `max_supply_amount` for `SerpDown` operation
- let max_supply_amount = Self::calculate_max_supply_amount(market_price, setter_price, contract_by);
-
- T::SerpTreasury::on_serpdown(T::GetSetEURCurrencyId::get(), contract_by, max_supply_amount).unwrap();
+ T::SerpTreasury::on_serpdown(T::GetSetEURCurrencyId::get(), contract_by).unwrap();
}
_ => {}
}
@@ -1331,19 +1313,13 @@ impl Pallet {
// safe from underflow because `peg_price` is checked to be less than `market_price`
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
- // `min_target_amount` for `SerpUp` operation
- let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
-
- T::SerpTreasury::on_serpup(T::GetSetGBPCurrencyId::get(), expand_by, min_target_amount).unwrap();
+ T::SerpTreasury::on_serpup(T::GetSetGBPCurrencyId::get(), expand_by).unwrap();
}
market_price if market_price < peg_price => {
// safe from underflow because `peg_price` is checked to be greater than `market_price`
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
- // `max_supply_amount` for `SerpDown` operation
- let max_supply_amount = Self::calculate_max_supply_amount(market_price, setter_price, contract_by);
-
- T::SerpTreasury::on_serpdown(T::GetSetGBPCurrencyId::get(), contract_by, max_supply_amount).unwrap();
+ T::SerpTreasury::on_serpdown(T::GetSetGBPCurrencyId::get(), contract_by).unwrap();
}
_ => {}
}
@@ -1460,19 +1436,13 @@ impl Pallet {
// safe from underflow because `peg_price` is checked to be less than `market_price`
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
- // `min_target_amount` for `SerpUp` operation
- let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
-
- T::SerpTreasury::on_serpup(T::GetSetCHFCurrencyId::get(), expand_by, min_target_amount).unwrap();
+ T::SerpTreasury::on_serpup(T::GetSetCHFCurrencyId::get(), expand_by).unwrap();
}
market_price if market_price < peg_price => {
// safe from underflow because `peg_price` is checked to be greater than `market_price`
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
- // `max_supply_amount` for `SerpDown` operation
- let max_supply_amount = Self::calculate_max_supply_amount(market_price, setter_price, contract_by);
-
- T::SerpTreasury::on_serpdown(T::GetSetCHFCurrencyId::get(), contract_by, max_supply_amount).unwrap();
+ T::SerpTreasury::on_serpdown(T::GetSetCHFCurrencyId::get(), contract_by).unwrap();
}
_ => {}
}
@@ -1589,19 +1559,13 @@ impl Pallet {
// safe from underflow because `peg_price` is checked to be less than `market_price`
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
- // `min_target_amount` for `SerpUp` operation
- let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
-
- T::SerpTreasury::on_serpup(T::GetSetSARCurrencyId::get(), expand_by, min_target_amount).unwrap();
+ T::SerpTreasury::on_serpup(T::GetSetSARCurrencyId::get(), expand_by).unwrap();
}
market_price if market_price < peg_price => {
// safe from underflow because `peg_price` is checked to be greater than `market_price`
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
- // `max_supply_amount` for `SerpDown` operation
- let max_supply_amount = Self::calculate_max_supply_amount(market_price, setter_price, contract_by);
-
- T::SerpTreasury::on_serpdown(T::GetSetSARCurrencyId::get(), contract_by, max_supply_amount).unwrap();
+ T::SerpTreasury::on_serpdown(T::GetSetSARCurrencyId::get(), contract_by).unwrap();
}
_ => {}
}
diff --git a/lib-serml/serp/serp-ocw/src/tests.rs b/lib-serml/serp/serp-ocw/src/tests.rs
index 4acd6ab46..30a9c6888 100644
--- a/lib-serml/serp/serp-ocw/src/tests.rs
+++ b/lib-serml/serp/serp-ocw/src/tests.rs
@@ -158,7 +158,6 @@ impl DEXManager for MockDEX {
fn get_swap_target_amount(
_path: &[CurrencyId],
_supply_amount: Balance,
- _price_impact_limit: Option,
) -> Option {
unimplemented!()
}
@@ -166,7 +165,6 @@ impl DEXManager for MockDEX {
fn get_swap_supply_amount(
_path: &[CurrencyId],
_target_amount: Balance,
- _price_impact_limit: Option,
) -> Option {
unimplemented!()
}
@@ -176,7 +174,6 @@ impl DEXManager for MockDEX {
_path: &[CurrencyId],
_supply_amount: Balance,
_min_target_amount: Balance,
- _price_impact_limit: Option,
) -> sp_std::result::Result {
unimplemented!()
}
@@ -186,7 +183,6 @@ impl DEXManager for MockDEX {
_path: &[CurrencyId],
_target_amount: Balance,
_max_supply_amount: Balance,
- _price_impact_limit: Option,
) -> sp_std::result::Result {
unimplemented!()
}
@@ -224,7 +220,6 @@ impl SerpTreasury for MockSerpTreasury {
fn get_buyback_serpup(
_amount: Balance,
_currency_id: CurrencyId,
- _min_target_amount: Balance
) -> DispatchResult {
unimplemented!()
}
@@ -259,7 +254,6 @@ impl SerpTreasury for MockSerpTreasury {
fn on_serpup(
_currency_id: CurrencyId,
_amount: Balance,
- _min_target_amount: Balance
) -> DispatchResult {
unimplemented!()
}
@@ -268,7 +262,6 @@ impl SerpTreasury for MockSerpTreasury {
fn on_serpdown(
_currency_id: CurrencyId,
_amount: Balance,
- _max_supply_amount: Balance
) -> DispatchResult {
unimplemented!()
}
diff --git a/lib-serml/serp/serp-prices/src/mock.rs b/lib-serml/serp/serp-prices/src/mock.rs
index b8bd7f42a..cab780616 100644
--- a/lib-serml/serp/serp-prices/src/mock.rs
+++ b/lib-serml/serp/serp-prices/src/mock.rs
@@ -118,7 +118,6 @@ impl DEXManager for MockDEX {
fn get_swap_target_amount(
_path: &[CurrencyId],
_supply_amount: Balance,
- _price_impact_limit: Option,
) -> Option {
unimplemented!()
}
@@ -126,7 +125,6 @@ impl DEXManager for MockDEX {
fn get_swap_supply_amount(
_path: &[CurrencyId],
_target_amount: Balance,
- _price_impact_limit: Option,
) -> Option {
unimplemented!()
}
@@ -136,7 +134,6 @@ impl DEXManager for MockDEX {
_path: &[CurrencyId],
_supply_amount: Balance,
_min_target_amount: Balance,
- _price_impact_limit: Option,
) -> sp_std::result::Result {
unimplemented!()
}
@@ -146,7 +143,6 @@ impl DEXManager for MockDEX {
_path: &[CurrencyId],
_target_amount: Balance,
_max_supply_amount: Balance,
- _price_impact_limit: Option,
) -> sp_std::result::Result {
unimplemented!()
}
diff --git a/lib-serml/serp/serp-treasury/src/lib.rs b/lib-serml/serp/serp-treasury/src/lib.rs
index 0e030c0b0..480f77833 100644
--- a/lib-serml/serp/serp-treasury/src/lib.rs
+++ b/lib-serml/serp/serp-treasury/src/lib.rs
@@ -27,17 +27,27 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::unused_unit)]
-use frame_support::{pallet_prelude::*, PalletId};
+use frame_support::{
+ pallet_prelude::*,
+ PalletId,
+};
use frame_system::pallet_prelude::*;
use orml_traits::{GetByKey, MultiCurrency, MultiCurrencyExtended};
use primitives::{Balance, CurrencyId};
use sp_runtime::{
- traits::{AccountIdConversion, Zero},
DispatchError, DispatchResult,
+ traits::{
+ AccountIdConversion, Bounded, CheckedSub, Convert, DispatchInfoOf, One, PostDispatchInfoOf, SaturatedConversion, Saturating,
+ SignedExtension, UniqueSaturatedInto, Zero,
+ },
+ transaction_validity::{
+ InvalidTransaction, TransactionPriority, TransactionValidity, TransactionValidityError, ValidTransaction,
+ },
+ FixedPointNumber, FixedPointOperand, FixedU128, Perquintill,
};
-use sp_std::prelude::*;
+use sp_std::{convert::TryInto, prelude::*, vec};
use support::{
- DEXManager, Ratio, SerpTreasury, SerpTreasuryExtended
+ DEXManager, PriceProvider, Ratio, SerpTreasury, SerpTreasuryExtended,
};
mod mock;
@@ -47,6 +57,8 @@ pub mod weights;
pub use module::*;
pub use weights::WeightInfo;
+type CurrencyBalanceOf = <::Currency as MultiCurrency<::AccountId>>::Balance;
+
#[frame_support::pallet]
pub mod module {
use super::*;
@@ -98,15 +110,30 @@ pub mod module {
/// CharityFund account.
type CharityFundAccountId: Get;
+ /// Default fee swap path list
+ #[pallet::constant]
+ type DefaultFeeSwapPathList: Get>>;
+
+ /// When swap with DEX, the acceptable max slippage for the price from oracle.
+ #[pallet::constant]
+ type MaxSwapSlippageCompareToOracle: Get;
+
+ /// The limit for length of trading path
+ #[pallet::constant]
+ type TradingPathLimit: Get;
+
+ /// The price source to provider external market price.
+ type PriceSource: PriceProvider;
+
/// Dex manager is used to swap reserve asset (Setter) for propper (SetCurrency).
type Dex: DEXManager;
- /// The max slippage allowed when swap fee with DEX
- type MaxSlippageSwapWithDEX: Get;
-
/// The minimum transfer amounts by currency_id, to secure cashdrop from dusty claims.
type MinimumClaimableTransferAmounts: GetByKey;
+ /// The origin which may update incentive related params
+ type UpdateOrigin: EnsureOrigin;
+
#[pallet::constant]
/// The SERP Treasury's module id, keeps serplus and reserve asset.
type PalletId: Get;
@@ -160,6 +187,12 @@ pub mod module {
#[pallet::getter(fn minimum_claimable_transfer)]
pub type MinimumClaimableTransfer = StorageMap<_, Twox64Concat, CurrencyId, Balance, OptionQuery>;
+ /// The alternative fee swap path of accounts.
+ #[pallet::storage]
+ #[pallet::getter(fn alternative_fee_swap_path)]
+ pub type AlternativeFeeSwapPath =
+ StorageMap<_, Twox64Concat, T::AccountId, BoundedVec, OptionQuery>;
+
#[pallet::pallet]
pub struct Pallet(_);
@@ -192,6 +225,33 @@ pub mod module {
}
}
}
+ /// set alternative swap path for SERP.
+ #[pallet::call]
+ impl Pallet {
+ /// Set fee swap path
+ #[pallet::weight(::WeightInfo::set_alternative_swap_path())]
+ pub fn set_alternative_swap_path(
+ origin: OriginFor,
+ fee_swap_path: Option>,
+ ) -> DispatchResult {
+ T::UpdateOrigin::ensure_origin(origin)?;
+
+ if let Some(path) = fee_swap_path {
+ let path: BoundedVec =
+ path.try_into().map_err(|_| Error::::InvalidSwapPath)?;
+ ensure!(
+ path.len() > 1
+ && path[0] != T::GetNativeCurrencyId::get()
+ && path[path.len() - 1] == T::GetNativeCurrencyId::get(),
+ Error::::InvalidSwapPath
+ );
+ AlternativeFeeSwapPath::::insert(&Self::account_id(), &path);
+ } else {
+ AlternativeFeeSwapPath::::remove(&Self::account_id());
+ }
+ Ok(())
+ }
+ }
}
impl Pallet {
@@ -206,29 +266,27 @@ impl SerpTreasury for Pallet {
type CurrencyId = CurrencyId;
/// SerpUp ratio for BuyBack Swaps to burn Dinar
- fn get_buyback_serpup(amount: Balance, currency_id: Self::CurrencyId, min_target_amount: Balance) -> DispatchResult {
- // Setheum Treasury SerpUp Pool - 30%
- let three: Balance = 3;
- let serping_amount: Balance = three.saturating_mul(amount / 10);
+ fn get_buyback_serpup(amount: Balance, currency_id: Self::CurrencyId) -> DispatchResult {
+ // Setheum Treasury SerpUp Pool - 40%
+ let four: Balance = 4;
+ let serping_amount: Balance = four.saturating_mul(amount / 10);
if currency_id == T::SetterCurrencyId::get() {
+ // Mint stable currency for buyback swap.
+ T::Currency::deposit(currency_id, &Self::account_id(), serping_amount)?;
+
>::swap_exact_setter_to_dinar(
serping_amount,
- min_target_amount,
- None,
- )?;
+ );
} else {
+ // Mint stable currency for buyback swap.
+ T::Currency::deposit(currency_id, &Self::account_id(), serping_amount)?;
>::swap_exact_setcurrency_to_dinar(
currency_id,
serping_amount,
- min_target_amount,
- None,
- )?;
+ );
}
- // Burn Native Reserve asset (Dinar (DNAR))
- T::Currency::withdraw( T::GetNativeCurrencyId::get(), &Self::account_id(), serping_amount)?;
-
>::deposit_event(Event::SerpUpDelivery(amount, currency_id));
Ok(())
}
@@ -249,16 +307,15 @@ impl SerpTreasury for Pallet {
fn get_cashdrop_serpup(amount: Balance, currency_id: Self::CurrencyId) -> DispatchResult {
let settpay_account = &T::SettPayTreasuryAccountId::get();
- // SettPay SerpUp Pool - 60%
- let six: Balance = 6;
- let serping_amount: Balance = six.saturating_mul(amount / 10);
+ // SettPay SerpUp Pool - 50%
+ let five: Balance = 5;
+ let serping_amount: Balance = five.saturating_mul(amount / 10);
// Issue the SerpUp propper to the SettPayVault
Self::issue_standard(currency_id, &settpay_account, serping_amount)?;
>::deposit_event(Event::SerpUpDelivery(amount, currency_id));
Ok(())
}
-
// TODO: Update to 1% per day not 50% per day.
/// Reward SETR cashdrop to vault
fn setter_cashdrop_to_vault() -> DispatchResult {
@@ -274,7 +331,6 @@ impl SerpTreasury for Pallet {
>::deposit_event(Event::CashDropToVault(cashdrop_amount, T::SetterCurrencyId::get()));
Ok(())
}
-
// TODO: Update to 1% per day not 50% per day. and rename `usdj` to `setusd`
/// SerpUp ratio for SettPay Cashdrops
fn usdj_cashdrop_to_vault() -> DispatchResult {
@@ -292,7 +348,7 @@ impl SerpTreasury for Pallet {
}
/// issue serpup surplus(stable currencies) to their destinations according to the serpup_ratio.
- fn on_serpup(currency_id: CurrencyId, amount: Balance, min_target_amount: Balance) -> DispatchResult {
+ fn on_serpup(currency_id: CurrencyId, amount: Balance) -> DispatchResult {
// ensure that the currency is a SetCurrency
ensure!(
T::StableCurrencyIds::get().contains(¤cy_id),
@@ -303,7 +359,7 @@ impl SerpTreasury for Pallet {
!amount.is_zero(),
Error::::InvalidAmount,
);
- Self::get_buyback_serpup(amount, currency_id, min_target_amount)?;
+ Self::get_buyback_serpup(amount, currency_id)?;
Self::get_cashdrop_serpup(amount, currency_id)?;
Self::get_charity_fund_serpup(amount, currency_id)?;
@@ -316,7 +372,7 @@ impl SerpTreasury for Pallet {
//
// TODO: Update to add the burning of the stablecoins!
//
- fn on_serpdown(currency_id: CurrencyId, amount: Balance, max_supply_amount: Balance) -> DispatchResult {
+ fn on_serpdown(currency_id: CurrencyId, amount: Balance) -> DispatchResult {
// ensure that the currency is a SetCurrency
ensure!(
T::StableCurrencyIds::get().contains(¤cy_id),
@@ -333,16 +389,12 @@ impl SerpTreasury for Pallet {
if currency_id == T::SetterCurrencyId::get() {
>::swap_dinar_to_exact_setter(
amount,
- max_supply_amount,
- None,
- )?;
+ );
} else {
>::swap_setter_to_exact_setcurrency(
currency_id,
amount,
- max_supply_amount,
- None,
- )?;
+ );
}
>::deposit_event(Event::SerpDown(amount, currency_id));
@@ -420,34 +472,59 @@ impl SerpTreasuryExtended for Pallet {
/// return actual supply Dinar amount
fn swap_dinar_to_exact_setter(
target_amount: Balance,
- max_supply_amount: Balance,
- maybe_path: Option<&[CurrencyId]>,
- ) -> sp_std::result::Result {
+ ) {
+ let native_currency_id = T::GetNativeCurrencyId::get();
let dinar_currency_id = T::GetNativeCurrencyId::get();
-
let setter_currency_id = T::SetterCurrencyId::get();
- let default_swap_path = &[dinar_currency_id, setter_currency_id];
- let swap_path = match maybe_path {
- None => default_swap_path,
- Some(path) => {
- let path_length = path.len();
- ensure!(
- path_length >= 2 && path[0] == dinar_currency_id && path[path_length - 1] == setter_currency_id,
- Error::::InvalidSwapPath
- );
- path
+
+ let default_fee_swap_path_list = T::DefaultFeeSwapPathList::get();
+ let swap_path: Vec> =
+ if let Some(path) = AlternativeFeeSwapPath::::get(&Self::account_id()) {
+ vec![vec![path.into_inner()], default_fee_swap_path_list].concat()
+ } else {
+ default_fee_swap_path_list
+ };
+
+ for path in swap_path {
+ match path.last() {
+ Some(setter_currency_id) if *setter_currency_id == native_currency_id => {
+ let dinar_currency_id = *path.first().expect("these's first guaranteed by match");
+ // calculate the supply limit according to oracle price and the slippage limit,
+ // if oracle price is not avalible, do not limit
+ let max_supply_limit = if let Some(target_price) =
+ T::PriceSource::get_relative_price(*setter_currency_id, dinar_currency_id)
+ {
+ Ratio::one()
+ .saturating_sub(T::MaxSwapSlippageCompareToOracle::get())
+ .reciprocal()
+ .unwrap_or_else(Ratio::max_value)
+ .saturating_mul_int(target_price.saturating_mul_int(target_amount))
+ } else {
+ CurrencyBalanceOf::::max_value()
+ };
+
+ T::Currency::deposit(
+ dinar_currency_id,
+ &Self::account_id(),
+ max_supply_limit.unique_saturated_into()
+ );
+
+ if T::Dex::swap_with_exact_target(
+ &Self::account_id(),
+ &path,
+ target_amount.unique_saturated_into(),
+ ::Currency::free_balance(dinar_currency_id, &Self::account_id())
+ .min(max_supply_limit.unique_saturated_into()),
+ )
+ .is_ok()
+ {
+ // successfully swap, break iteration
+ break;
+ }
+ }
+ _ => {}
}
- };
- let price_impact_limit = Some(T::MaxSlippageSwapWithDEX::get());
-
- T::Currency::deposit(dinar_currency_id, &Self::account_id(), max_supply_amount)?;
- T::Dex::swap_with_exact_target(
- &Self::account_id(),
- swap_path,
- target_amount,
- max_supply_amount,
- price_impact_limit,
- )
+ }
}
/// Swap exact amount of Setter to SetCurrency,
@@ -458,33 +535,58 @@ impl SerpTreasuryExtended for Pallet {
fn swap_setter_to_exact_setcurrency(
currency_id: CurrencyId,
target_amount: Balance,
- max_supply_amount: Balance,
- maybe_path: Option<&[CurrencyId]>,
- ) -> sp_std::result::Result {
+ ) {
+ let native_currency_id = T::GetNativeCurrencyId::get();
let setter_currency_id = T::SetterCurrencyId::get();
- let default_swap_path = &[setter_currency_id, currency_id];
- let swap_path = match maybe_path {
- None => default_swap_path,
- Some(path) => {
- let path_length = path.len();
- ensure!(
- path_length >= 2 && path[0] == setter_currency_id && path[path_length - 1] == currency_id,
- Error::::InvalidSwapPath
- );
- path
+ let default_fee_swap_path_list = T::DefaultFeeSwapPathList::get();
+ let swap_path: Vec> =
+ if let Some(path) = AlternativeFeeSwapPath::::get(&Self::account_id()) {
+ vec![vec![path.into_inner()], default_fee_swap_path_list].concat()
+ } else {
+ default_fee_swap_path_list
+ };
+
+ for path in swap_path {
+ match path.last() {
+ Some(currency_id) if *currency_id == native_currency_id => {
+ let setter_currency_id = *path.first().expect("these's first guaranteed by match");
+ // calculate the supply limit according to oracle price and the slippage limit,
+ // if oracle price is not avalible, do not limit
+ let max_supply_limit = if let Some(target_price) =
+ T::PriceSource::get_relative_price(*currency_id, setter_currency_id)
+ {
+ Ratio::one()
+ .saturating_sub(T::MaxSwapSlippageCompareToOracle::get())
+ .reciprocal()
+ .unwrap_or_else(Ratio::max_value)
+ .saturating_mul_int(target_price.saturating_mul_int(target_amount))
+ } else {
+ CurrencyBalanceOf::::max_value()
+ };
+
+ T::Currency::deposit(
+ setter_currency_id,
+ &Self::account_id(),
+ max_supply_limit.unique_saturated_into()
+ );
+
+ if T::Dex::swap_with_exact_target(
+ &Self::account_id(),
+ &path,
+ target_amount.unique_saturated_into(),
+ ::Currency::free_balance(setter_currency_id, &Self::account_id())
+ .min(max_supply_limit.unique_saturated_into()),
+ )
+ .is_ok()
+ {
+ // successfully swap, break iteration
+ break;
+ }
+ }
+ _ => {}
}
- };
- let price_impact_limit = Some(T::MaxSlippageSwapWithDEX::get());
-
- T::Currency::deposit(setter_currency_id, &Self::account_id(), max_supply_amount)?;
- T::Dex::swap_with_exact_target(
- &Self::account_id(),
- swap_path,
- target_amount,
- max_supply_amount,
- price_impact_limit,
- )
+ }
}
/// Swap exact amount of Setter to Dinar,
@@ -494,34 +596,54 @@ impl SerpTreasuryExtended for Pallet {
/// When Setter gets SerpUp
fn swap_exact_setter_to_dinar(
supply_amount: Balance,
- min_target_amount: Balance,
- maybe_path: Option<&[CurrencyId]>,
- ) -> sp_std::result::Result {
- let currency_id = T::SetterCurrencyId::get();
+ ) {
+ let native_currency_id = T::GetNativeCurrencyId::get();
let dinar_currency_id = T::GetNativeCurrencyId::get();
- T::Currency::deposit(currency_id, &Self::account_id(), supply_amount)?;
+ let currency_id = T::SetterCurrencyId::get();
- let default_swap_path = &[currency_id, dinar_currency_id];
- let swap_path = match maybe_path {
- None => default_swap_path,
- Some(path) => {
- let path_length = path.len();
- ensure!(
- path_length >= 2 && path[0] == currency_id && path[path_length - 1] == dinar_currency_id,
- Error::::InvalidSwapPath
- );
- path
+ let default_fee_swap_path_list = T::DefaultFeeSwapPathList::get();
+ let swap_path: Vec> =
+ if let Some(path) = AlternativeFeeSwapPath::::get(&Self::account_id()) {
+ vec![vec![path.into_inner()], default_fee_swap_path_list].concat()
+ } else {
+ default_fee_swap_path_list
+ };
+
+ for path in swap_path {
+ match path.last() {
+ Some(dinar_currency_id) if *dinar_currency_id == native_currency_id => {
+ let currency_id = *path.first().expect("these's first guaranteed by match");
+ // calculate the supply limit according to oracle price and the slippage limit,
+ // if oracle price is not avalible, do not limit
+ let min_target_limit = if let Some(target_price) =
+ T::PriceSource::get_relative_price(*dinar_currency_id, currency_id)
+ {
+ Ratio::one()
+ .saturating_sub(T::MaxSwapSlippageCompareToOracle::get())
+ .reciprocal()
+ .unwrap_or_else(Ratio::max_value)
+ .saturating_mul_int(target_price.saturating_mul_int(supply_amount))
+ } else {
+ CurrencyBalanceOf::::max_value()
+ };
+
+ if T::Dex::swap_with_exact_supply(
+ &Self::account_id(),
+ &path,
+ supply_amount.unique_saturated_into(),
+ min_target_limit.unique_saturated_into(),
+ )
+ .is_ok()
+ {
+ // Burn Native Reserve asset (Dinar (DNAR))
+ T::Currency::withdraw( T::GetNativeCurrencyId::get(), &Self::account_id(), min_target_limit);
+ // successfully swap, break iteration.
+ break;
+ }
+ }
+ _ => {}
}
- };
- let price_impact_limit = Some(T::MaxSlippageSwapWithDEX::get());
-
- T::Dex::swap_with_exact_supply(
- &Self::account_id(),
- swap_path,
- supply_amount,
- min_target_amount,
- price_impact_limit,
- )
+ }
}
/// Swap exact amount of Setter to Dinar,
@@ -532,32 +654,52 @@ impl SerpTreasuryExtended for Pallet {
fn swap_exact_setcurrency_to_dinar(
currency_id: CurrencyId,
supply_amount: Balance,
- min_target_amount: Balance,
- maybe_path: Option<&[CurrencyId]>,
- ) -> sp_std::result::Result {
+ ) {
+ let native_currency_id = T::GetNativeCurrencyId::get();
let dinar_currency_id = T::GetNativeCurrencyId::get();
- T::Currency::deposit(currency_id, &Self::account_id(), supply_amount)?;
- let default_swap_path = &[currency_id, dinar_currency_id];
- let swap_path = match maybe_path {
- None => default_swap_path,
- Some(path) => {
- let path_length = path.len();
- ensure!(
- path_length >= 2 && path[0] == currency_id && path[path_length - 1] == dinar_currency_id,
- Error::::InvalidSwapPath
- );
- path
+ let default_fee_swap_path_list = T::DefaultFeeSwapPathList::get();
+ let swap_path: Vec> =
+ if let Some(path) = AlternativeFeeSwapPath::::get(&Self::account_id()) {
+ vec![vec![path.into_inner()], default_fee_swap_path_list].concat()
+ } else {
+ default_fee_swap_path_list
+ };
+
+ for path in swap_path {
+ match path.last() {
+ Some(dinar_currency_id) if *dinar_currency_id == native_currency_id => {
+ let currency_id = *path.first().expect("these's first guaranteed by match");
+ // calculate the supply limit according to oracle price and the slippage limit,
+ // if oracle price is not avalible, do not limit
+ let min_target_limit = if let Some(target_price) =
+ T::PriceSource::get_relative_price(*dinar_currency_id, currency_id)
+ {
+ Ratio::one()
+ .saturating_sub(T::MaxSwapSlippageCompareToOracle::get())
+ .reciprocal()
+ .unwrap_or_else(Ratio::max_value)
+ .saturating_mul_int(target_price.saturating_mul_int(supply_amount))
+ } else {
+ CurrencyBalanceOf::::max_value()
+ };
+
+ if T::Dex::swap_with_exact_supply(
+ &Self::account_id(),
+ &path,
+ supply_amount.unique_saturated_into(),
+ min_target_limit.unique_saturated_into(),
+ )
+ .is_ok()
+ {
+ // Burn Native Reserve asset (Dinar (DNAR))
+ T::Currency::withdraw( T::GetNativeCurrencyId::get(), &Self::account_id(), min_target_limit);
+ // successfully swap, break iteration
+ break;
+ }
+ }
+ _ => {}
}
- };
- let price_impact_limit = Some(T::MaxSlippageSwapWithDEX::get());
-
- T::Dex::swap_with_exact_supply(
- &Self::account_id(),
- swap_path,
- supply_amount,
- min_target_amount,
- price_impact_limit,
- )
+ }
}
}
diff --git a/lib-serml/serp/serp-treasury/src/mock.rs b/lib-serml/serp/serp-treasury/src/mock.rs
index 3a1b6b412..e3ba17d46 100644
--- a/lib-serml/serp/serp-treasury/src/mock.rs
+++ b/lib-serml/serp/serp-treasury/src/mock.rs
@@ -31,7 +31,7 @@ use sp_runtime::{
traits::{IdentityLookup, One as OneT},
};
use sp_std::cell::RefCell;
-use support::{Price, PriceProvider, Ratio};
+use support::{Price, PriceProvider};
pub type AccountId = u128;
pub type BlockNumber = u64;
@@ -41,6 +41,7 @@ pub const BOB: AccountId = 1;
pub const CHARITY_FUND: AccountId = 2;
pub const SETRPAY: AccountId = 9;
pub const VAULT: AccountId = 10;
+pub const ROOT: AccountId = 11;
// Currencies constants - CurrencyId/TokenSymbol
pub const DNAR: CurrencyId = CurrencyId::Token(TokenSymbol::DNAR);
@@ -213,7 +214,6 @@ parameter_types! {
pub const CashDropVaultAccountId: AccountId = VAULT;
pub CashDropPeriod: BlockNumber = 120;
- pub MaxSlippageSwapWithDEX: Ratio = Ratio::one();
}
parameter_type_with_key! {
@@ -244,6 +244,15 @@ parameter_type_with_key! {
};
}
+parameter_types! {
+ pub MaxSwapSlippageCompareToOracle: Ratio = Ratio::saturating_from_rational(1, 2);
+ pub DefaultFeeSwapPathList: Vec> = vec![vec![SETR, DNAR], vec![SETUSD, SETR, DNAR]];
+}
+
+ord_parameter_types! {
+ pub const Root: AccountId = ROOT;
+}
+
impl Config for Runtime {
type Event = Event;
type Currency = Currencies;
@@ -257,9 +266,13 @@ impl Config for Runtime {
type SettPayTreasuryAccountId = SettPayTreasuryAccountId;
type CashDropVaultAccountId = CashDropVaultAccountId;
type CharityFundAccountId = CharityFundAccountId;
+ type DefaultFeeSwapPathList = DefaultFeeSwapPathList;
type Dex = SetheumDEX;
- type MaxSlippageSwapWithDEX = MaxSlippageSwapWithDEX;
+ type MaxSwapSlippageCompareToOracle = MaxSwapSlippageCompareToOracle;
+ type TradingPathLimit = TradingPathLimit;
+ type PriceSource = MockPriceSource;
type MinimumClaimableTransferAmounts = MinimumClaimableTransferAmounts;
+ type UpdateOrigin = EnsureSignedBy;
type PalletId = SerpTreasuryPalletId;
type WeightInfo = ();
}
@@ -274,7 +287,7 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Storage, Config, Event},
- SerpTreasuryModule: serp_treasury::{Pallet, Storage, Event},
+ SerpTreasuryModule: serp_treasury::{Pallet, Storage, Call, Event},
Currencies: orml_currencies::{Pallet, Call, Event},
Tokens: orml_tokens::{Pallet, Storage, Event, Config},
PalletBalances: pallet_balances::{Pallet, Call, Storage, Event},
diff --git a/lib-serml/serp/serp-treasury/src/tests.rs b/lib-serml/serp/serp-treasury/src/tests.rs
index 790a33c0a..afb42bdf1 100644
--- a/lib-serml/serp/serp-treasury/src/tests.rs
+++ b/lib-serml/serp/serp-treasury/src/tests.rs
@@ -81,7 +81,7 @@ fn deposit_setter_works() {
}
#[test]
-fn swap_dinar_to_exact_setter_works() {
+fn on_serpdown_works() {
ExtBuilder::default().build().execute_with(|| {
assert_ok!(Currencies::deposit(SETR, &ALICE, 10000));
assert_ok!(Currencies::deposit(DNAR, &ALICE, 10000));
@@ -95,51 +95,31 @@ fn swap_dinar_to_exact_setter_works() {
));
assert_ok!(Currencies::deposit(DNAR, &SerpTreasuryModule::account_id(), 10000));
assert_ok!(Currencies::deposit(SETR, &SerpTreasuryModule::account_id(), 10000));
- assert_ok!(SerpTreasuryModule::swap_dinar_to_exact_setter(
- 10, 100, None
- ));
- assert_eq!(Currencies::free_balance(SETR, &SerpTreasuryModule::account_id()), 10010);
+ assert_ok!(SerpTreasuryModule::on_serpdown(SETR, 10));
+ assert_eq!(Currencies::free_balance(SETR, &SerpTreasuryModule::account_id()), 10020);
+ assert_eq!(Currencies::free_balance(DNAR, &SerpTreasuryModule::account_id()), 10000);
});
}
#[test]
-fn swap_exact_setter_to_dinar_work() {
+fn on_serpup_works() {
ExtBuilder::default().build().execute_with(|| {
- assert_ok!(Currencies::deposit(SETR, &BOB, 10000));
- assert_ok!(Currencies::deposit(DNAR, &BOB, 10000));
+ assert_ok!(Currencies::deposit(SETR, &ALICE, 10000));
+ assert_ok!(Currencies::deposit(DNAR, &ALICE, 10000));
assert_ok!(SetheumDEX::add_liquidity(
- Origin::signed(BOB),
+ Origin::signed(ALICE),
SETR,
DNAR,
1000,
- 1000,
+ 100,
0,
));
+ assert_ok!(Currencies::deposit(DNAR, &SerpTreasuryModule::account_id(), 10000));
assert_ok!(Currencies::deposit(SETR, &SerpTreasuryModule::account_id(), 10000));
- assert_ok!(SerpTreasuryModule::swap_exact_setter_to_dinar(
- 100, 20, None
- ));
- assert_eq!(Currencies::free_balance(SETR, &SerpTreasuryModule::account_id()), 10000);
+ assert_ok!(SerpTreasuryModule::on_serpup(SETR, 10));
+ assert_eq!(Currencies::free_balance(SETR, &SerpTreasuryModule::account_id()), 10004);
+ assert_eq!(Currencies::free_balance(SETR, &VAULT), 1000);
+ assert_eq!(Currencies::free_balance(SETR, &CHARITY_FUND), 1001);
+ assert_eq!(Currencies::free_balance(DNAR, &SerpTreasuryModule::account_id()), 10000);
});
}
-
-#[test]
-fn swap_exact_setcurrency_to_dinar_work() {
- ExtBuilder::default().build().execute_with(|| {
- assert_ok!(Currencies::deposit(SETUSD, &BOB, 10000));
- assert_ok!(Currencies::deposit(DNAR, &BOB, 10000));
- assert_ok!(SetheumDEX::add_liquidity(
- Origin::signed(BOB),
- SETUSD,
- DNAR,
- 1000,
- 1000,
- 0,
- ));
- assert_ok!(Currencies::deposit(SETUSD, &SerpTreasuryModule::account_id(), 10000));
- assert_ok!(SerpTreasuryModule::swap_exact_setcurrency_to_dinar(
- SETUSD, 100, 20, None
- ));
- assert_eq!(Currencies::free_balance(SETUSD, &SerpTreasuryModule::account_id()), 10000);
- });
-}
\ No newline at end of file
diff --git a/lib-serml/serp/serp-treasury/src/weights.rs b/lib-serml/serp/serp-treasury/src/weights.rs
index 6748a1c78..08f884f7f 100644
--- a/lib-serml/serp/serp-treasury/src/weights.rs
+++ b/lib-serml/serp/serp-treasury/src/weights.rs
@@ -48,6 +48,7 @@ use sp_std::marker::PhantomData;
/// Weight functions needed for module_cdp_treasury.
pub trait WeightInfo {
fn on_initialize(c: u32) -> Weight;
+ fn set_alternative_swap_path() -> Weight;
}
/// Weights for serp_treasury using the Setheum node and recommended hardware.
@@ -59,6 +60,10 @@ impl WeightInfo for SetheumWeight {
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(c as Weight)))
}
+ fn set_alternative_swap_path() -> Weight {
+ (3_000_000 as Weight)
+ .saturating_add(T::DbWeight::get().writes(1 as Weight))
+ }
}
// For backwards compatibility and tests
@@ -69,4 +74,8 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(c as Weight)))
}
+ fn set_alternative_swap_path() -> Weight {
+ (3_000_000 as Weight)
+ .saturating_add(RocksDbWeight::get().writes(1 as Weight))
+ }
}
diff --git a/lib-serml/settmint/settmint-engine/src/mock.rs b/lib-serml/settmint/settmint-engine/src/mock.rs
index 5ee21a105..9aa125963 100644
--- a/lib-serml/settmint/settmint-engine/src/mock.rs
+++ b/lib-serml/settmint/settmint-engine/src/mock.rs
@@ -42,6 +42,7 @@ pub const CAROL: AccountId = 3;
pub const CHARITY_FUND: AccountId = 4;
pub const SETRPAY: AccountId = 9;
pub const VAULT: AccountId = 10;
+pub const ROOT: AccountId = 11;
// Currencies constants - CurrencyId/TokenSymbol
pub const DNAR: CurrencyId = CurrencyId::Token(TokenSymbol::DNAR);
@@ -179,6 +180,36 @@ impl PriceProvider for MockPriceSource {
fn unlock_price(_currency_id: CurrencyId) {}
}
+parameter_types! {
+ pub const DexPalletId: PalletId = PalletId(*b"set/sdex");
+ pub const GetExchangeFee: (u32, u32) = (1, 1000); // 0.1%
+ pub const TradingPathLimit: u32 = 3;
+ pub EnabledTradingPairs: Vec = vec![
+ TradingPair::from_currency_ids(DNAR, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETCHF, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETEUR, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETGBP, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETSAR, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETUSD, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETCHF, DNAR).unwrap(),
+ TradingPair::from_currency_ids(SETEUR, DNAR).unwrap(),
+ TradingPair::from_currency_ids(SETGBP, DNAR).unwrap(),
+ TradingPair::from_currency_ids(SETSAR, DNAR).unwrap(),
+ TradingPair::from_currency_ids(SETUSD, DNAR).unwrap(),
+ ];
+}
+
+impl setheum_dex::Config for Runtime {
+ type Event = Event;
+ type Currency = Currencies;
+ type GetExchangeFee = GetExchangeFee;
+ type TradingPathLimit = TradingPathLimit;
+ type PalletId = DexPalletId;
+ type CurrencyIdMapping = ();
+ type WeightInfo = ();
+ type ListingOrigin = EnsureSignedBy;
+}
+
parameter_types! {
pub StableCurrencyIds: Vec = vec![
SETR,
@@ -229,6 +260,15 @@ parameter_type_with_key! {
};
}
+parameter_types! {
+ pub MaxSwapSlippageCompareToOracle: Ratio = Ratio::saturating_from_rational(1, 2);
+ pub DefaultFeeSwapPathList: Vec> = vec![vec![SETR, DNAR], vec![SETUSD, SETR, DNAR]];
+}
+
+ord_parameter_types! {
+ pub const Root: AccountId = ROOT;
+}
+
impl serp_treasury::Config for Runtime {
type Event = Event;
type Currency = Currencies;
@@ -242,43 +282,17 @@ impl serp_treasury::Config for Runtime {
type SettPayTreasuryAccountId = SettPayTreasuryAccountId;
type CashDropVaultAccountId = CashDropVaultAccountId;
type CharityFundAccountId = CharityFundAccountId;
+ type DefaultFeeSwapPathList = DefaultFeeSwapPathList;
type Dex = SetheumDEX;
- type MaxSlippageSwapWithDEX = MaxSlippageSwapWithDEX;
+ type MaxSwapSlippageCompareToOracle = MaxSwapSlippageCompareToOracle;
+ type TradingPathLimit = TradingPathLimit;
+ type PriceSource = MockPriceSource;
type MinimumClaimableTransferAmounts = MinimumClaimableTransferAmounts;
+ type UpdateOrigin = EnsureSignedBy;
type PalletId = SerpTreasuryPalletId;
type WeightInfo = ();
}
-parameter_types! {
- pub const DexPalletId: PalletId = PalletId(*b"set/sdex");
- pub const GetExchangeFee: (u32, u32) = (1, 1000); // 0.1%
- pub const TradingPathLimit: u32 = 3;
- pub EnabledTradingPairs: Vec = vec![
- TradingPair::from_currency_ids(DNAR, SETR).unwrap(),
- TradingPair::from_currency_ids(SETCHF, SETR).unwrap(),
- TradingPair::from_currency_ids(SETEUR, SETR).unwrap(),
- TradingPair::from_currency_ids(SETGBP, SETR).unwrap(),
- TradingPair::from_currency_ids(SETSAR, SETR).unwrap(),
- TradingPair::from_currency_ids(SETUSD, SETR).unwrap(),
- TradingPair::from_currency_ids(SETCHF, DNAR).unwrap(),
- TradingPair::from_currency_ids(SETEUR, DNAR).unwrap(),
- TradingPair::from_currency_ids(SETGBP, DNAR).unwrap(),
- TradingPair::from_currency_ids(SETSAR, DNAR).unwrap(),
- TradingPair::from_currency_ids(SETUSD, DNAR).unwrap(),
- ];
-}
-
-impl setheum_dex::Config for Runtime {
- type Event = Event;
- type Currency = Currencies;
- type GetExchangeFee = GetExchangeFee;
- type TradingPathLimit = TradingPathLimit;
- type PalletId = DexPalletId;
- type CurrencyIdMapping = ();
- type WeightInfo = ();
- type ListingOrigin = EnsureSignedBy;
-}
-
ord_parameter_types! {
pub const One: AccountId = 1;
}
diff --git a/lib-serml/settmint/settmint-gateway/src/mock.rs b/lib-serml/settmint/settmint-gateway/src/mock.rs
index 10c33194a..600463b60 100644
--- a/lib-serml/settmint/settmint-gateway/src/mock.rs
+++ b/lib-serml/settmint/settmint-gateway/src/mock.rs
@@ -27,7 +27,7 @@ use orml_traits::parameter_type_with_key;
use primitives::{Balance, Moment, TokenSymbol, TradingPair};
use sp_core::H256;
use sp_runtime::{
- testing::{Header, TestXt},
+ testing::{Header, TestXt}, FixedPointNumber,
traits::{IdentityLookup, One as OneT},
};
use support::{ExchangeRate, Price, PriceProvider, Ratio};
@@ -45,6 +45,7 @@ pub const CAROL: AccountId = 3;
pub const CHARITY_FUND: AccountId = 4;
pub const SETRPAY: AccountId = 9;
pub const VAULT: AccountId = 10;
+pub const ROOT: AccountId = 11;
// Currencies constants - CurrencyId/TokenSymbol
pub const DNAR: CurrencyId = CurrencyId::Token(TokenSymbol::DNAR);
@@ -154,6 +155,36 @@ ord_parameter_types! {
pub const One: AccountId = 1;
}
+parameter_types! {
+ pub const DexPalletId: PalletId = PalletId(*b"set/sdex");
+ pub const GetExchangeFee: (u32, u32) = (1, 1000); // 0.1%
+ pub const TradingPathLimit: u32 = 3;
+ pub EnabledTradingPairs: Vec = vec![
+ TradingPair::from_currency_ids(DNAR, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETCHF, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETEUR, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETGBP, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETSAR, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETUSD, SETR).unwrap(),
+ TradingPair::from_currency_ids(SETCHF, DNAR).unwrap(),
+ TradingPair::from_currency_ids(SETEUR, DNAR).unwrap(),
+ TradingPair::from_currency_ids(SETGBP, DNAR).unwrap(),
+ TradingPair::from_currency_ids(SETSAR, DNAR).unwrap(),
+ TradingPair::from_currency_ids(SETUSD, DNAR).unwrap(),
+ ];
+}
+
+impl setheum_dex::Config for Runtime {
+ type Event = Event;
+ type Currency = Currencies;
+ type GetExchangeFee = GetExchangeFee;
+ type TradingPathLimit = TradingPathLimit;
+ type PalletId = DexPalletId;
+ type CurrencyIdMapping = ();
+ type WeightInfo = ();
+ type ListingOrigin = EnsureSignedBy;
+}
+
parameter_types! {
pub StableCurrencyIds: Vec = vec![
SETR,
@@ -204,6 +235,15 @@ parameter_type_with_key! {
};
}
+parameter_types! {
+ pub MaxSwapSlippageCompareToOracle: Ratio = Ratio::saturating_from_rational(1, 2);
+ pub DefaultFeeSwapPathList: Vec> = vec![vec![SETR, DNAR], vec![SETUSD, SETR, DNAR]];
+}
+
+ord_parameter_types! {
+ pub const Root: AccountId = ROOT;
+}
+
impl serp_treasury::Config for Runtime {
type Event = Event;
type Currency = Currencies;
@@ -217,43 +257,17 @@ impl serp_treasury::Config for Runtime {
type SettPayTreasuryAccountId = SettPayTreasuryAccountId;
type CashDropVaultAccountId = CashDropVaultAccountId;
type CharityFundAccountId = CharityFundAccountId;
+ type DefaultFeeSwapPathList = DefaultFeeSwapPathList;
type Dex = SetheumDEX;
- type MaxSlippageSwapWithDEX = MaxSlippageSwapWithDEX;
+ type MaxSwapSlippageCompareToOracle = MaxSwapSlippageCompareToOracle;
+ type TradingPathLimit = TradingPathLimit;
+ type PriceSource = MockPriceSource;
type MinimumClaimableTransferAmounts = MinimumClaimableTransferAmounts;
+ type UpdateOrigin = EnsureSignedBy;
type PalletId = SerpTreasuryPalletId;
type WeightInfo = ();
}
-parameter_types! {
- pub const DexPalletId: PalletId = PalletId(*b"set/sdex");
- pub const GetExchangeFee: (u32, u32) = (1, 1000); // 0.1%
- pub const TradingPathLimit: u32 = 3;
- pub EnabledTradingPairs: Vec = vec![
- TradingPair::from_currency_ids(DNAR, SETR).unwrap(),
- TradingPair::from_currency_ids(SETCHF, SETR).unwrap(),
- TradingPair::from_currency_ids(SETEUR, SETR).unwrap(),
- TradingPair::from_currency_ids(SETGBP, SETR).unwrap(),
- TradingPair::from_currency_ids(SETSAR, SETR).unwrap(),
- TradingPair::from_currency_ids(SETUSD, SETR).unwrap(),
- TradingPair::from_currency_ids(SETCHF, DNAR).unwrap(),
- TradingPair::from_currency_ids(SETEUR, DNAR).unwrap(),
- TradingPair::from_currency_ids(SETGBP, DNAR).unwrap(),
- TradingPair::from_currency_ids(SETSAR, DNAR).unwrap(),
- TradingPair::from_currency_ids(SETUSD, DNAR).unwrap(),
- ];
-}
-
-impl setheum_dex::Config for Runtime {
- type Event = Event;
- type Currency = Currencies;
- type GetExchangeFee = GetExchangeFee;
- type TradingPathLimit = TradingPathLimit;
- type PalletId = DexPalletId;
- type CurrencyIdMapping = ();
- type WeightInfo = ();
- type ListingOrigin = EnsureSignedBy;
-}
-
parameter_types! {
pub const MinimumPeriod: Moment = 1000;
}
diff --git a/lib-serml/settmint/settmint-manager/src/mock.rs b/lib-serml/settmint/settmint-manager/src/mock.rs
index 02b0f570b..75075edc9 100644
--- a/lib-serml/settmint/settmint-manager/src/mock.rs
+++ b/lib-serml/settmint/settmint-manager/src/mock.rs
@@ -27,7 +27,7 @@ use orml_traits::parameter_type_with_key;
use primitives::{Amount, ReserveIdentifier, TokenSymbol, TradingPair};
use sp_core::H256;
use sp_runtime::{
- testing::Header,
+ testing::Header, FixedPointNumber,
traits::{IdentityLookup, One as OneT},
};
use support::{Price, PriceProvider, Ratio};
@@ -41,6 +41,7 @@ pub const BOB: AccountId = 2;
pub const CHARITY_FUND: AccountId = 3;
pub const SETRPAY: AccountId = 9;
pub const VAULT: AccountId = 10;
+pub const ROOT: AccountId = 11;
// Currencies constants - CurrencyId/TokenSymbol
pub const DNAR: CurrencyId = CurrencyId::Token(TokenSymbol::DNAR);
@@ -244,6 +245,15 @@ parameter_type_with_key! {
};
}
+parameter_types! {
+ pub MaxSwapSlippageCompareToOracle: Ratio = Ratio::saturating_from_rational(1, 2);
+ pub DefaultFeeSwapPathList: Vec> = vec![vec![SETR, DNAR], vec![SETUSD, SETR, DNAR]];
+}
+
+ord_parameter_types! {
+ pub const Root: AccountId = ROOT;
+}
+
impl serp_treasury::Config for Runtime {
type Event = Event;
type Currency = Currencies;
@@ -257,9 +267,13 @@ impl serp_treasury::Config for Runtime {
type SettPayTreasuryAccountId = SettPayTreasuryAccountId;
type CashDropVaultAccountId = CashDropVaultAccountId;
type CharityFundAccountId = CharityFundAccountId;
+ type DefaultFeeSwapPathList = DefaultFeeSwapPathList;
type Dex = SetheumDEX;
- type MaxSlippageSwapWithDEX = MaxSlippageSwapWithDEX;
+ type MaxSwapSlippageCompareToOracle = MaxSwapSlippageCompareToOracle;
+ type TradingPathLimit = TradingPathLimit;
+ type PriceSource = MockPriceSource;
type MinimumClaimableTransferAmounts = MinimumClaimableTransferAmounts;
+ type UpdateOrigin = EnsureSignedBy;
type PalletId = SerpTreasuryPalletId;
type WeightInfo = ();
}
diff --git a/lib-serml/support/src/lib.rs b/lib-serml/support/src/lib.rs
index 9fb207736..b9dba5da7 100644
--- a/lib-serml/support/src/lib.rs
+++ b/lib-serml/support/src/lib.rs
@@ -75,24 +75,15 @@ pub trait DEXManager {
fn get_liquidity_token_address(currency_id_a: CurrencyId, currency_id_b: CurrencyId) -> Option;
- fn get_swap_target_amount(
- path: &[CurrencyId],
- supply_amount: Balance,
- price_impact_limit: Option,
- ) -> Option;
+ fn get_swap_target_amount(path: &[CurrencyId], supply_amount: Balance) -> Option