Dex improvements (#422)

* remove dex traits&balance types

* remove liq tokens pallet in favor of coins-pallet instance

* fix tests & benchmarks

* remove liquidity tokens trait

* fix CI

* fix pr comments

* Slight renamings

* Add burn_with_instruction as a negative to LiquidityTokens CallFilter

* Remove use of One, Zero, Saturating taits in dex pallet

---------

Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
akildemir
2023-11-12 14:37:31 +03:00
committed by GitHub
parent a43815f101
commit d015ee96a3
30 changed files with 1063 additions and 2162 deletions

View File

@@ -40,14 +40,12 @@ frame-executive = { git = "https://github.com/serai-dex/substrate", default-feat
frame-benchmarking = { git = "https://github.com/serai-dex/substrate", default-features = false, optional = true }
serai-primitives = { path = "../primitives", default-features = false }
serai-dex-primitives = { path = "../dex/primitives", default-features = false }
pallet-timestamp = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-transaction-payment = { git = "https://github.com/serai-dex/substrate", default-features = false }
coins-pallet = { package = "serai-coins-pallet", path = "../coins/pallet", default-features = false }
liquidity-tokens-pallet = { package = "serai-liquidity-tokens-pallet", path = "../liquidity-tokens/pallet", default-features = false }
dex-pallet = { package = "serai-dex-pallet", path = "../dex/pallet", default-features = false }
validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../validator-sets/pallet", default-features = false }
@@ -97,14 +95,12 @@ std = [
"frame-executive/std",
"serai-primitives/std",
"serai-dex-primitives/std",
"pallet-timestamp/std",
"pallet-transaction-payment/std",
"coins-pallet/std",
"liquidity-tokens-pallet/std",
"dex-pallet/std",
"validator-sets-pallet/std",
@@ -132,8 +128,6 @@ runtime-benchmarks = [
"pallet-timestamp/runtime-benchmarks",
"dex-pallet/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
]

View File

@@ -17,7 +17,6 @@ pub use pallet_timestamp as timestamp;
pub use pallet_transaction_payment as transaction_payment;
pub use coins_pallet as coins;
pub use liquidity_tokens_pallet as liquidity_tokens;
pub use dex_pallet as dex;
pub use validator_sets_pallet as validator_sets;
@@ -47,7 +46,7 @@ use sp_runtime::{
ApplyExtrinsicResult, Perbill,
};
use primitives::{PublicKey, SeraiAddress, Coin, AccountLookup, Signature, SubstrateAmount};
use primitives::{PublicKey, SeraiAddress, AccountLookup, Signature, SubstrateAmount};
use support::{
traits::{ConstU8, ConstU32, ConstU64, Contains},
@@ -157,6 +156,12 @@ impl Contains<RuntimeCall> for CallFilter {
// All of these pallets are our own, and all of their written calls are intended to be called
RuntimeCall::Coins(call) => !matches!(call, coins::Call::__Ignore(_, _)),
RuntimeCall::LiquidityTokens(call) => match call {
coins::Call::transfer { .. } => true,
coins::Call::burn { .. } => true,
coins::Call::burn_with_instruction { .. } => false,
coins::Call::__Ignore(_, _) => false,
},
RuntimeCall::Dex(call) => !matches!(call, dex::Call::__Ignore(_, _)),
RuntimeCall::ValidatorSets(call) => !matches!(call, validator_sets::Call::__Ignore(_, _)),
RuntimeCall::InInstructions(call) => !matches!(call, in_instructions::Call::__Ignore(_, _)),
@@ -234,25 +239,12 @@ impl coins::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}
impl liquidity_tokens::Config for Runtime {
impl coins::Config<coins::Instance1> for Runtime {
type RuntimeEvent = RuntimeEvent;
}
impl dex::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Coins;
type Balance = SubstrateAmount;
type CoinBalance = SubstrateAmount;
// TODO: Review if this should be u64/u128 or u64/u256 (and rounding in general).
type HigherPrecisionBalance = u128;
type CoinId = Coin;
type MultiCoinId = Coin;
type MultiCoinIdConverter = serai_dex_primitives::CoinConverter;
type PoolCoinId = u32;
type Coins = Coins;
type PoolCoins = LiquidityTokens;
type LPFee = ConstU32<3>; // 0.3%
type MintMinLiquidity = ConstU64<10000>;
@@ -260,9 +252,6 @@ impl dex::Config for Runtime {
type MaxSwapPathLength = ConstU32<3>; // coin1 -> SRI -> coin2
type WeightInfo = dex::weights::SubstrateWeight<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
impl validator_sets::Config for Runtime {
@@ -364,7 +353,7 @@ construct_runtime!(
TransactionPayment: transaction_payment,
Coins: coins,
LiquidityTokens: liquidity_tokens,
LiquidityTokens: coins::<Instance1>::{Pallet, Call, Storage, Event<T>},
Dex: dex,
ValidatorSets: validator_sets,