mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Restore the coins pallet to the runtime
This commit is contained in:
@@ -34,6 +34,8 @@ frame-system = { git = "https://github.com/serai-dex/polkadot-sdk", branch = "se
|
||||
frame-support = { git = "https://github.com/serai-dex/polkadot-sdk", branch = "serai-next", default-features = false }
|
||||
frame-executive = { git = "https://github.com/serai-dex/polkadot-sdk", branch = "serai-next", default-features = false }
|
||||
|
||||
serai-coins-pallet = { path = "../coins", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
substrate-wasm-builder = { git = "https://github.com/serai-dex/polkadot-sdk", branch = "serai-next" }
|
||||
|
||||
@@ -47,14 +49,32 @@ std = [
|
||||
"sp-runtime/std",
|
||||
"sp-api/std",
|
||||
|
||||
"serai-abi/std",
|
||||
|
||||
"frame-system/std",
|
||||
"frame-support/std",
|
||||
"frame-executive/std",
|
||||
|
||||
"serai-abi/std",
|
||||
"serai-coins-pallet/std",
|
||||
]
|
||||
|
||||
try-runtime = ["sp-runtime/try-runtime", "serai-abi/try-runtime", "frame-system/try-runtime", "frame-support/try-runtime", "frame-executive/try-runtime"]
|
||||
runtime-benchmarks = ["sp-runtime/runtime-benchmarks", "frame-system/runtime-benchmarks", "frame-support/runtime-benchmarks"]
|
||||
try-runtime = [
|
||||
"sp-runtime/try-runtime",
|
||||
|
||||
"serai-abi/try-runtime",
|
||||
|
||||
"frame-system/try-runtime",
|
||||
"frame-support/try-runtime",
|
||||
"frame-executive/try-runtime",
|
||||
|
||||
"serai-coins-pallet/try-runtime",
|
||||
]
|
||||
|
||||
runtime-benchmarks = [
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
|
||||
"frame-system/runtime-benchmarks",
|
||||
"frame-support/runtime-benchmarks",
|
||||
]
|
||||
|
||||
default = ["std"]
|
||||
|
||||
@@ -17,6 +17,8 @@ use serai_abi::{
|
||||
primitives::address::SeraiAddress, SubstrateHeader as Header, SubstrateBlock,
|
||||
};
|
||||
|
||||
use serai_coins_pallet::{CoinsInstance, LiquidityTokensInstance};
|
||||
|
||||
mod core_pallet;
|
||||
|
||||
type Block = SubstrateBlock;
|
||||
@@ -74,6 +76,12 @@ mod runtime {
|
||||
|
||||
#[runtime::pallet_index(1)]
|
||||
pub type Core = core_pallet::Pallet<Runtime>;
|
||||
|
||||
#[runtime::pallet_index(2)]
|
||||
pub type Coins = serai_coins_pallet::Pallet<Runtime, CoinsInstance>;
|
||||
|
||||
#[runtime::pallet_index(3)]
|
||||
pub type LiquidityTokens = serai_coins_pallet::Pallet<Runtime, LiquidityTokensInstance>;
|
||||
}
|
||||
|
||||
impl frame_system::Config for Runtime {
|
||||
@@ -118,6 +126,15 @@ impl frame_system::Config for Runtime {
|
||||
|
||||
impl core_pallet::Config for Runtime {}
|
||||
|
||||
impl serai_coins_pallet::Config<CoinsInstance> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type AllowMint = serai_coins_pallet::AlwaysAllowMint; // TODO
|
||||
}
|
||||
impl serai_coins_pallet::Config<LiquidityTokensInstance> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type AllowMint = serai_coins_pallet::AlwaysAllowMint;
|
||||
}
|
||||
|
||||
impl From<Option<SeraiAddress>> for RuntimeOrigin {
|
||||
fn from(signer: Option<SeraiAddress>) -> Self {
|
||||
match signer {
|
||||
@@ -133,8 +150,14 @@ impl From<serai_abi::Call> for RuntimeCall {
|
||||
serai_abi::Call::Coins(call) => {
|
||||
use serai_abi::coins::Call;
|
||||
match call {
|
||||
Call::transfer { .. } | Call::burn { .. } | Call::burn_with_instruction { .. } => {
|
||||
todo!("TODO")
|
||||
Call::transfer { to, coins } => {
|
||||
RuntimeCall::Coins(serai_coins_pallet::Call::transfer { to: to.into(), balance: coins })
|
||||
}
|
||||
Call::burn { coins } => {
|
||||
RuntimeCall::Coins(serai_coins_pallet::Call::burn { balance: coins })
|
||||
}
|
||||
Call::burn_with_instruction { instruction } => {
|
||||
RuntimeCall::Coins(serai_coins_pallet::Call::burn_with_instruction { instruction })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,8 +185,13 @@ impl From<serai_abi::Call> for RuntimeCall {
|
||||
serai_abi::Call::Dex(call) => {
|
||||
use serai_abi::dex::Call;
|
||||
match call {
|
||||
Call::transfer_liquidity { to, liquidity_tokens } => {
|
||||
RuntimeCall::LiquidityTokens(serai_coins_pallet::Call::transfer {
|
||||
to: to.into(),
|
||||
balance: liquidity_tokens.into(),
|
||||
})
|
||||
}
|
||||
Call::add_liquidity { .. } |
|
||||
Call::transfer_liquidity { .. } |
|
||||
Call::remove_liquidity { .. } |
|
||||
Call::swap_exact { .. } |
|
||||
Call::swap_for_exact { .. } => todo!("TODO"),
|
||||
@@ -236,7 +264,14 @@ impl serai_abi::TransactionContext for Context {
|
||||
signer: &SeraiAddress,
|
||||
fee: serai_abi::primitives::balance::Amount,
|
||||
) -> Result<(), sp_runtime::transaction_validity::TransactionValidityError> {
|
||||
todo!("TODO")
|
||||
use serai_abi::primitives::coin::Coin;
|
||||
if serai_coins_pallet::Pallet::<Runtime, CoinsInstance>::balance(signer, Coin::Serai) >= fee {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(sp_runtime::transaction_validity::TransactionValidityError::Invalid(
|
||||
sp_runtime::transaction_validity::InvalidTransaction::Payment,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn start_transaction(&self) {
|
||||
@@ -252,7 +287,16 @@ impl serai_abi::TransactionContext for Context {
|
||||
signer: &SeraiAddress,
|
||||
fee: serai_abi::primitives::balance::Amount,
|
||||
) -> Result<(), sp_runtime::transaction_validity::TransactionValidityError> {
|
||||
todo!("TODO")
|
||||
use serai_abi::primitives::{coin::*, balance::*};
|
||||
serai_coins_pallet::Pallet::<Runtime, CoinsInstance>::burn(
|
||||
RuntimeOrigin::signed(Public::from(*signer)),
|
||||
Balance { coin: Coin::Serai, amount: fee },
|
||||
)
|
||||
.map_err(|_| {
|
||||
sp_runtime::transaction_validity::TransactionValidityError::Invalid(
|
||||
sp_runtime::transaction_validity::InvalidTransaction::Payment,
|
||||
)
|
||||
})
|
||||
}
|
||||
fn end_transaction(&self, transaction_hash: [u8; 32]) {
|
||||
Core::end_transaction(transaction_hash);
|
||||
|
||||
Reference in New Issue
Block a user