mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Add Dex pallet (#407)
* Move pallet-asset-conversion * update licensing * initial integration * Integrate Currency & Assets types * integrate liquidity tokens * fmt * integrate dex pallet tests * fmt * compilation error fixes * integrate dex benchmarks * fmt * cargo clippy * replace all occurrences of "asset" with "coin" * add the actual add liq/swap logic to in-instructions * add client side & tests * fix deny * Lint and changes - Renames InInstruction::AddLiquidity to InInstruction::SwapAndAddLiquidity - Makes create_pool an internal function - Makes dex-pallet exclusively create pools against a native coin - Removes various fees - Adds new crates to GH workflow * Fix rebase artifacts * Correct other rebase artifact * Correct CI specification for liquidity-tokens * Correct primitives' test to the standardized pallet account scheme --------- Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
@@ -40,12 +40,15 @@ 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 }
|
||||
pallet-session = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
@@ -94,12 +97,15 @@ 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",
|
||||
"pallet-session/std",
|
||||
@@ -126,6 +132,8 @@ runtime-benchmarks = [
|
||||
|
||||
"pallet-timestamp/runtime-benchmarks",
|
||||
|
||||
"dex-pallet/runtime-benchmarks",
|
||||
|
||||
"pallet-babe/runtime-benchmarks",
|
||||
"pallet-grandpa/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -17,6 +17,8 @@ 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;
|
||||
pub use pallet_session as session;
|
||||
@@ -45,7 +47,7 @@ use sp_runtime::{
|
||||
ApplyExtrinsicResult, Perbill,
|
||||
};
|
||||
|
||||
use primitives::{PublicKey, SeraiAddress, AccountLookup, Signature, SubstrateAmount};
|
||||
use primitives::{PublicKey, SeraiAddress, Coin, AccountLookup, Signature, SubstrateAmount};
|
||||
|
||||
use support::{
|
||||
traits::{ConstU8, ConstU32, ConstU64, Contains},
|
||||
@@ -167,6 +169,7 @@ 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::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(_, _)),
|
||||
RuntimeCall::Signals(call) => !matches!(call, signals::Call::__Ignore(_, _)),
|
||||
@@ -243,6 +246,37 @@ impl coins::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
|
||||
impl liquidity_tokens::Config 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>;
|
||||
|
||||
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 {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
@@ -342,6 +376,8 @@ construct_runtime!(
|
||||
TransactionPayment: transaction_payment,
|
||||
|
||||
Coins: coins,
|
||||
LiquidityTokens: liquidity_tokens,
|
||||
Dex: dex,
|
||||
|
||||
ValidatorSets: validator_sets,
|
||||
Session: session,
|
||||
|
||||
Reference in New Issue
Block a user