Skip to content

Commit 47e714e

Browse files
authored
Merge pull request #508 from Setheum-Labs/0.9.0-runtimes
0.9.0 runtimes
2 parents 383cd5a + 6d028c9 commit 47e714e

File tree

24 files changed

+577
-510
lines changed

24 files changed

+577
-510
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Setheum's Blockchain Network node Implementation in Rust, Substrate FRAME and Se
44

55
<div align="center">
66

7-
[![Setheum version](https://img.shields.io/badge/Setheum-0.8.0-brightgreen?logo=Parity%20Substrate)](https://setheum.xyz/)
7+
[![Setheum version](https://img.shields.io/badge/Setheum-0.9.0-brightgreen?logo=Parity%20Substrate)](https://setheum.xyz/)
88
[![Substrate version](https://img.shields.io/badge/Substrate-3.0.0-brightgreen?logo=Parity%20Substrate)](https://substrate.dev/)
99
[![License](https://img.shields.io/github/license/Setheum-Labs/Setheum?color=green)](https://github.com/Setheum-Labs/Setheum/blob/master/LICENSE)
1010
<br />
@@ -39,7 +39,7 @@ DRAM("Setheum Dirham", 12) = 1, // Staking Reward and Governance Token - System
3939
SETR("Setter", 12) = 2,
4040
```
4141

42-
#### The SetCurrencies - SERP Stablecoins
42+
#### The SettCurrencies - SERP Stablecoins
4343
```
4444
SETUSD("SetDollar", 12) = 3,
4545
SETEUR("SetEuro", 12) = 4,
@@ -48,7 +48,7 @@ DRAM("Setheum Dirham", 12) = 1, // Staking Reward and Governance Token - System
4848
SETSAR("SetRiyal", 12) = 7,
4949
```
5050

51-
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
51+
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
5252

5353
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.
5454

lib-serml/dex/dex/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "setheum-dex"
3-
version = "0.9.0"
3+
version = "0.8.0"
44
authors = ["Setheum Labs"]
55
edition = "2018"
66

lib-serml/dex/dex/src/lib.rs

+33-63
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use orml_traits::{MultiCurrency, MultiCurrencyExtended};
3636
use primitives::{Balance, CurrencyId, TradingPair};
3737
use sp_core::{H160, U256};
3838
use sp_runtime::{
39-
traits::{AccountIdConversion, Bounded, One, Zero},
39+
traits::{AccountIdConversion, One, Zero},
4040
ArithmeticError, DispatchError, DispatchResult, FixedPointNumber, RuntimeDebug, SaturatedConversion,
4141
};
4242
use sp_std::{convert::TryInto, prelude::*, vec};
@@ -144,8 +144,6 @@ pub mod module {
144144
InsufficientTargetAmount,
145145
/// Supply amount is more than max_supply_amount
146146
ExcessiveSupplyAmount,
147-
/// The swap will cause unacceptable price impact
148-
ExceedPriceImpactLimit,
149147
/// Liquidity is not enough
150148
InsufficientLiquidity,
151149
/// The supply amount is zero
@@ -307,10 +305,10 @@ pub mod module {
307305
path: Vec<CurrencyId>,
308306
#[pallet::compact] supply_amount: Balance,
309307
#[pallet::compact] min_target_amount: Balance,
310-
) -> DispatchResultWithPostInfo {
308+
) -> DispatchResult {
311309
let who = ensure_signed(origin)?;
312-
Self::do_swap_with_exact_supply(&who, &path, supply_amount, min_target_amount, None)?;
313-
Ok(().into())
310+
Self::do_swap_with_exact_supply(&who, &path, supply_amount, min_target_amount)?;
311+
Ok(())
314312
}
315313

316314
/// Trading with DEX, swap with exact target amount
@@ -325,10 +323,10 @@ pub mod module {
325323
path: Vec<CurrencyId>,
326324
#[pallet::compact] target_amount: Balance,
327325
#[pallet::compact] max_supply_amount: Balance,
328-
) -> DispatchResultWithPostInfo {
326+
) -> DispatchResult {
329327
let who = ensure_signed(origin)?;
330-
Self::do_swap_with_exact_target(&who, &path, target_amount, max_supply_amount, None)?;
331-
Ok(().into())
328+
Self::do_swap_with_exact_target(&who, &path, target_amount, max_supply_amount)?;
329+
Ok(())
332330
}
333331

334332
/// Add liquidity to Enabled trading pair.
@@ -351,7 +349,7 @@ pub mod module {
351349
#[pallet::compact] max_amount_a: Balance,
352350
#[pallet::compact] max_amount_b: Balance,
353351
#[pallet::compact] min_share_increment: Balance,
354-
) -> DispatchResultWithPostInfo {
352+
) -> DispatchResult {
355353
let who = ensure_signed(origin)?;
356354
Self::do_add_liquidity(
357355
&who,
@@ -361,7 +359,7 @@ pub mod module {
361359
max_amount_b,
362360
min_share_increment,
363361
)?;
364-
Ok(().into())
362+
Ok(())
365363
}
366364

367365
/// Add provision to Provisioning trading pair.
@@ -380,10 +378,10 @@ pub mod module {
380378
currency_id_b: CurrencyId,
381379
#[pallet::compact] amount_a: Balance,
382380
#[pallet::compact] amount_b: Balance,
383-
) -> DispatchResultWithPostInfo {
381+
) -> DispatchResult {
384382
let who = ensure_signed(origin)?;
385383
Self::do_add_provision(&who, currency_id_a, currency_id_b, amount_a, amount_b)?;
386-
Ok(().into())
384+
Ok(())
387385
}
388386

389387
/// Claim dex share for founders who have participated in trading pair provision.
@@ -398,10 +396,10 @@ pub mod module {
398396
owner: T::AccountId,
399397
currency_id_a: CurrencyId,
400398
currency_id_b: CurrencyId,
401-
) -> DispatchResultWithPostInfo {
399+
) -> DispatchResult {
402400
let _ = ensure_signed(origin)?;
403401
Self::do_claim_dex_share(&owner, currency_id_a, currency_id_b)?;
404-
Ok(().into())
402+
Ok(())
405403
}
406404

407405
/// Remove liquidity from specific liquidity pool in the form of burning
@@ -422,7 +420,7 @@ pub mod module {
422420
#[pallet::compact] remove_share: Balance,
423421
#[pallet::compact] min_withdrawn_a: Balance,
424422
#[pallet::compact] min_withdrawn_b: Balance,
425-
) -> DispatchResultWithPostInfo {
423+
) -> DispatchResult {
426424
let who = ensure_signed(origin)?;
427425
Self::do_remove_liquidity(
428426
&who,
@@ -432,7 +430,7 @@ pub mod module {
432430
min_withdrawn_a,
433431
min_withdrawn_b,
434432
)?;
435-
Ok(().into())
433+
Ok(())
436434
}
437435

438436
/// List a new provisioning trading pair.
@@ -447,7 +445,7 @@ pub mod module {
447445
target_provision_a: Balance,
448446
target_provision_b: Balance,
449447
not_before: T::BlockNumber,
450-
) -> DispatchResultWithPostInfo {
448+
) -> DispatchResult {
451449
T::ListingOrigin::ensure_origin(origin)?;
452450

453451
let trading_pair =
@@ -494,7 +492,7 @@ pub mod module {
494492
}),
495493
);
496494
Self::deposit_event(Event::ListProvisioning(trading_pair));
497-
Ok(().into())
495+
Ok(())
498496
}
499497

500498
/// List a new trading pair, trading pair will become Enabled status
@@ -510,7 +508,7 @@ pub mod module {
510508
target_provision_a: Balance,
511509
target_provision_b: Balance,
512510
not_before: T::BlockNumber,
513-
) -> DispatchResultWithPostInfo {
511+
) -> DispatchResult {
514512
T::ListingOrigin::ensure_origin(origin)?;
515513
let trading_pair =
516514
TradingPair::from_currency_ids(currency_id_a, currency_id_b).ok_or(Error::<T>::InvalidCurrencyId)?;
@@ -541,7 +539,7 @@ pub mod module {
541539
_ => return Err(Error::<T>::MustBeProvisioning.into()),
542540
}
543541

544-
Ok(().into())
542+
Ok(())
545543
}
546544

547545
/// Enable a Provisioning trading pair if meet the condition.
@@ -551,7 +549,7 @@ pub mod module {
551549
origin: OriginFor<T>,
552550
currency_id_a: CurrencyId,
553551
currency_id_b: CurrencyId,
554-
) -> DispatchResultWithPostInfo {
552+
) -> DispatchResult {
555553
let _ = ensure_signed(origin)?;
556554

557555
let trading_pair =
@@ -618,7 +616,7 @@ pub mod module {
618616
_ => return Err(Error::<T>::MustBeProvisioning.into()),
619617
}
620618

621-
Ok(().into())
619+
Ok(())
622620
}
623621

624622
/// Enable a trading pair
@@ -630,7 +628,7 @@ pub mod module {
630628
origin: OriginFor<T>,
631629
currency_id_a: CurrencyId,
632630
currency_id_b: CurrencyId,
633-
) -> DispatchResultWithPostInfo {
631+
) -> DispatchResult {
634632
T::ListingOrigin::ensure_origin(origin)?;
635633
let trading_pair =
636634
TradingPair::from_currency_ids(currency_id_a, currency_id_b).ok_or(Error::<T>::InvalidCurrencyId)?;
@@ -648,7 +646,7 @@ pub mod module {
648646

649647
TradingPairStatuses::<T>::insert(trading_pair, TradingPairStatus::Enabled);
650648
Self::deposit_event(Event::EnableTradingPair(trading_pair));
651-
Ok(().into())
649+
Ok(())
652650
}
653651

654652
/// Disable a `Enabled` trading pair.
@@ -658,7 +656,7 @@ pub mod module {
658656
origin: OriginFor<T>,
659657
currency_id_a: CurrencyId,
660658
currency_id_b: CurrencyId,
661-
) -> DispatchResultWithPostInfo {
659+
) -> DispatchResult {
662660
T::ListingOrigin::ensure_origin(origin)?;
663661
let trading_pair =
664662
TradingPair::from_currency_ids(currency_id_a, currency_id_b).ok_or(Error::<T>::InvalidCurrencyId)?;
@@ -672,7 +670,7 @@ pub mod module {
672670

673671
TradingPairStatuses::<T>::insert(trading_pair, TradingPairStatus::Disabled);
674672
Self::deposit_event(Event::DisableTradingPair(trading_pair));
675-
Ok(().into())
673+
Ok(())
676674
}
677675
}
678676
}
@@ -1022,7 +1020,6 @@ impl<T: Config> Pallet<T> {
10221020
fn get_target_amounts(
10231021
path: &[CurrencyId],
10241022
supply_amount: Balance,
1025-
price_impact_limit: Option<Ratio>,
10261023
) -> sp_std::result::Result<Vec<Balance>, DispatchError> {
10271024
let path_length = path.len();
10281025
ensure!(
@@ -1051,13 +1048,6 @@ impl<T: Config> Pallet<T> {
10511048
let target_amount = Self::get_target_amount(supply_pool, target_pool, target_amounts[i]);
10521049
ensure!(!target_amount.is_zero(), Error::<T>::ZeroTargetAmount);
10531050

1054-
// check price impact if limit exists
1055-
if let Some(limit) = price_impact_limit {
1056-
let price_impact =
1057-
Ratio::checked_from_rational(target_amount, target_pool).unwrap_or_else(Ratio::max_value);
1058-
ensure!(price_impact <= limit, Error::<T>::ExceedPriceImpactLimit);
1059-
}
1060-
10611051
target_amounts[i + 1] = target_amount;
10621052
i += 1;
10631053
}
@@ -1068,7 +1058,6 @@ impl<T: Config> Pallet<T> {
10681058
fn get_supply_amounts(
10691059
path: &[CurrencyId],
10701060
target_amount: Balance,
1071-
price_impact_limit: Option<Ratio>,
10721061
) -> sp_std::result::Result<Vec<Balance>, DispatchError> {
10731062
let path_length = path.len();
10741063
ensure!(
@@ -1097,13 +1086,6 @@ impl<T: Config> Pallet<T> {
10971086
let supply_amount = Self::get_supply_amount(supply_pool, target_pool, supply_amounts[i]);
10981087
ensure!(!supply_amount.is_zero(), Error::<T>::ZeroSupplyAmount);
10991088

1100-
// check price impact if limit exists
1101-
if let Some(limit) = price_impact_limit {
1102-
let price_impact =
1103-
Ratio::checked_from_rational(supply_amounts[i], target_pool).unwrap_or_else(Ratio::max_value);
1104-
ensure!(price_impact <= limit, Error::<T>::ExceedPriceImpactLimit);
1105-
};
1106-
11071089
supply_amounts[i - 1] = supply_amount;
11081090
i -= 1;
11091091
}
@@ -1164,9 +1146,8 @@ impl<T: Config> Pallet<T> {
11641146
path: &[CurrencyId],
11651147
supply_amount: Balance,
11661148
min_target_amount: Balance,
1167-
price_impact_limit: Option<Ratio>,
11681149
) -> sp_std::result::Result<Balance, DispatchError> {
1169-
let amounts = Self::get_target_amounts(&path, supply_amount, price_impact_limit)?;
1150+
let amounts = Self::get_target_amounts(&path, supply_amount)?;
11701151
ensure!(
11711152
amounts[amounts.len() - 1] >= min_target_amount,
11721153
Error::<T>::InsufficientTargetAmount
@@ -1194,9 +1175,8 @@ impl<T: Config> Pallet<T> {
11941175
path: &[CurrencyId],
11951176
target_amount: Balance,
11961177
max_supply_amount: Balance,
1197-
price_impact_limit: Option<Ratio>,
11981178
) -> sp_std::result::Result<Balance, DispatchError> {
1199-
let amounts = Self::get_supply_amounts(&path, target_amount, price_impact_limit)?;
1179+
let amounts = Self::get_supply_amounts(&path, target_amount)?;
12001180
ensure!(amounts[0] <= max_supply_amount, Error::<T>::ExcessiveSupplyAmount);
12011181
let module_account_id = Self::account_id();
12021182
let actual_supply_amount = amounts[0];
@@ -1225,22 +1205,14 @@ impl<T: Config> DEXManager<T::AccountId, CurrencyId, Balance> for Pallet<T> {
12251205
T::CurrencyIdMapping::encode_evm_address(trading_pair.dex_share_currency_id())
12261206
}
12271207

1228-
fn get_swap_target_amount(
1229-
path: &[CurrencyId],
1230-
supply_amount: Balance,
1231-
price_impact_limit: Option<Ratio>,
1232-
) -> Option<Balance> {
1233-
Self::get_target_amounts(&path, supply_amount, price_impact_limit)
1208+
fn get_swap_target_amount(path: &[CurrencyId], supply_amount: Balance) -> Option<Balance> {
1209+
Self::get_target_amounts(&path, supply_amount)
12341210
.ok()
12351211
.map(|amounts| amounts[amounts.len() - 1])
12361212
}
12371213

1238-
fn get_swap_supply_amount(
1239-
path: &[CurrencyId],
1240-
target_amount: Balance,
1241-
price_impact_limit: Option<Ratio>,
1242-
) -> Option<Balance> {
1243-
Self::get_supply_amounts(&path, target_amount, price_impact_limit)
1214+
fn get_swap_supply_amount(path: &[CurrencyId], target_amount: Balance) -> Option<Balance> {
1215+
Self::get_supply_amounts(&path, target_amount)
12441216
.ok()
12451217
.map(|amounts| amounts[0])
12461218
}
@@ -1250,19 +1222,17 @@ impl<T: Config> DEXManager<T::AccountId, CurrencyId, Balance> for Pallet<T> {
12501222
path: &[CurrencyId],
12511223
supply_amount: Balance,
12521224
min_target_amount: Balance,
1253-
price_impact_limit: Option<Ratio>,
12541225
) -> sp_std::result::Result<Balance, DispatchError> {
1255-
Self::do_swap_with_exact_supply(who, path, supply_amount, min_target_amount, price_impact_limit)
1226+
Self::do_swap_with_exact_supply(who, path, supply_amount, min_target_amount)
12561227
}
12571228

12581229
fn swap_with_exact_target(
12591230
who: &T::AccountId,
12601231
path: &[CurrencyId],
12611232
target_amount: Balance,
12621233
max_supply_amount: Balance,
1263-
price_impact_limit: Option<Ratio>,
12641234
) -> sp_std::result::Result<Balance, DispatchError> {
1265-
Self::do_swap_with_exact_target(who, path, target_amount, max_supply_amount, price_impact_limit)
1235+
Self::do_swap_with_exact_target(who, path, target_amount, max_supply_amount)
12661236
}
12671237

12681238
// `do_add_liquidity` is used in genesis_build,

lib-serml/dex/dex/src/mock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use super::*;
2424
use frame_support::{construct_runtime, ord_parameter_types, parameter_types};
2525
use frame_system::EnsureSignedBy;
26-
use orml_traits::{parameter_type_with_key, MultiReservableCurrency};
26+
use orml_traits::parameter_type_with_key;
2727
use primitives::{Amount, TokenSymbol};
2828
use sp_core::H256;
2929
use sp_runtime::{testing::Header, traits::IdentityLookup};

0 commit comments

Comments
 (0)