mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +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:
@@ -18,8 +18,8 @@ serde = { version = "1", default-features = false, features = ["derive", "alloc"
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "2", default-features = false, features = ["derive"] }
|
||||
|
||||
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
|
||||
serai-primitives = { path = "../../primitives", default-features = false }
|
||||
@@ -35,6 +35,7 @@ std = [
|
||||
"scale-info/std",
|
||||
|
||||
"sp-std/std",
|
||||
"sp-application-crypto/std",
|
||||
"sp-runtime/std",
|
||||
|
||||
"serai-primitives/std",
|
||||
|
||||
@@ -16,20 +16,65 @@ use sp_application_crypto::sr25519::Signature;
|
||||
use sp_std::vec::Vec;
|
||||
use sp_runtime::RuntimeDebug;
|
||||
|
||||
use serai_primitives::{BlockHash, Balance, NetworkId, SeraiAddress, ExternalAddress, Data};
|
||||
#[rustfmt::skip]
|
||||
use serai_primitives::{BlockHash, Balance, NetworkId, SeraiAddress, ExternalAddress, system_address};
|
||||
|
||||
mod shorthand;
|
||||
pub use shorthand::*;
|
||||
|
||||
pub const MAX_BATCH_SIZE: usize = 25_000; // ~25kb
|
||||
|
||||
// This is the account which will be the origin for any dispatched `InInstruction`s.
|
||||
pub const IN_INSTRUCTION_EXECUTOR: SeraiAddress = system_address(b"InInstructions-executor");
|
||||
|
||||
#[derive(
|
||||
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
|
||||
)]
|
||||
#[cfg_attr(feature = "std", derive(Zeroize))]
|
||||
pub enum OutAddress {
|
||||
Serai(SeraiAddress),
|
||||
External(ExternalAddress),
|
||||
}
|
||||
|
||||
impl OutAddress {
|
||||
pub fn is_native(&self) -> bool {
|
||||
matches!(self, Self::Serai(_))
|
||||
}
|
||||
|
||||
pub fn as_native(self) -> Option<SeraiAddress> {
|
||||
match self {
|
||||
Self::Serai(addr) => Some(addr),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_external(self) -> Option<ExternalAddress> {
|
||||
match self {
|
||||
Self::External(addr) => Some(addr),
|
||||
Self::Serai(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
|
||||
)]
|
||||
#[cfg_attr(feature = "std", derive(Zeroize))]
|
||||
pub enum DexCall {
|
||||
// address to send the lp tokens to
|
||||
// TODO: Update this per documentation/Shorthand
|
||||
SwapAndAddLiquidity(SeraiAddress),
|
||||
// minimum out balance and out address
|
||||
Swap(Balance, OutAddress),
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
|
||||
)]
|
||||
#[cfg_attr(feature = "std", derive(Zeroize))]
|
||||
pub enum InInstruction {
|
||||
Transfer(SeraiAddress),
|
||||
Dex(Data),
|
||||
Dex(DexCall),
|
||||
}
|
||||
|
||||
#[derive(
|
||||
|
||||
@@ -26,7 +26,7 @@ pub enum Shorthand {
|
||||
minimum: Amount,
|
||||
out: OutInstruction,
|
||||
},
|
||||
AddLiquidity {
|
||||
SwapAndAddLiquidity {
|
||||
origin: Option<ExternalAddress>,
|
||||
minimum: Amount,
|
||||
gas: Amount,
|
||||
@@ -47,7 +47,7 @@ impl TryFrom<Shorthand> for RefundableInInstruction {
|
||||
Ok(match shorthand {
|
||||
Shorthand::Raw(instruction) => instruction,
|
||||
Shorthand::Swap { .. } => todo!(),
|
||||
Shorthand::AddLiquidity { .. } => todo!(),
|
||||
Shorthand::SwapAndAddLiquidity { .. } => todo!(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user