mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 12:49:23 +00:00
Updates to polkadot-v0.9.40, with a variety of dependency updates accordingly. Substrate thankfully now uses k256 0.13, pathing the way for #256. We couldn't upgrade to polkadot-v0.9.40 without this due to polkadot-v0.9.40 having fundamental changes to syncing. While we could've updated tendermint, it's not worth the continued development effort given its inability to work with multiple validator sets. Purges sc-tendermint. Keeps tendermint-machine for #163. Closes #137, #148, #157, #171. #96 and #99 should be re-scoped/clarified. #134 and #159 also should be clarified. #169 is also no longer a priority since we're only considering temporal deployments of tendermint. #170 also isn't since we're looking at effectively sharded validator sets, so there should be no singular large set needing high performance.
83 lines
2.4 KiB
Rust
83 lines
2.4 KiB
Rust
#![cfg_attr(docsrs, feature(doc_cfg))]
|
|
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
|
#![cfg_attr(not(feature = "std"), no_std)]
|
|
|
|
pub use tokens_primitives as primitives;
|
|
|
|
#[frame_support::pallet]
|
|
pub mod pallet {
|
|
use frame_support::pallet_prelude::*;
|
|
use frame_system::{pallet_prelude::*, RawOrigin};
|
|
|
|
use pallet_assets::{Config as AssetsConfig, Pallet as AssetsPallet};
|
|
|
|
use serai_primitives::{SubstrateAmount, Coin, Balance, PublicKey, SeraiAddress, AccountLookup};
|
|
use primitives::{ADDRESS, OutInstruction};
|
|
|
|
use super::*;
|
|
|
|
#[pallet::config]
|
|
pub trait Config:
|
|
frame_system::Config<AccountId = PublicKey, Lookup = AccountLookup>
|
|
+ AssetsConfig<AssetIdParameter = Coin, Balance = SubstrateAmount>
|
|
{
|
|
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
|
}
|
|
|
|
#[pallet::event]
|
|
#[pallet::generate_deposit(fn deposit_event)]
|
|
pub enum Event<T: Config> {
|
|
// Mint is technically redundant as the assets pallet has the exact same event already
|
|
// Providing our own definition here just helps consolidate code
|
|
Mint { address: SeraiAddress, balance: Balance },
|
|
Burn { address: SeraiAddress, balance: Balance, instruction: OutInstruction },
|
|
}
|
|
|
|
#[pallet::pallet]
|
|
pub struct Pallet<T>(PhantomData<T>);
|
|
|
|
impl<T: Config> Pallet<T> {
|
|
fn burn_internal(
|
|
address: SeraiAddress,
|
|
balance: Balance,
|
|
instruction: OutInstruction,
|
|
) -> DispatchResult {
|
|
AssetsPallet::<T>::burn(
|
|
RawOrigin::Signed(ADDRESS.into()).into(),
|
|
balance.coin,
|
|
address,
|
|
balance.amount.0,
|
|
)?;
|
|
Pallet::<T>::deposit_event(Event::Burn { address, balance, instruction });
|
|
Ok(())
|
|
}
|
|
|
|
pub fn mint(address: SeraiAddress, balance: Balance) {
|
|
// TODO: Prevent minting when it'd cause an amount exceeding the bond
|
|
AssetsPallet::<T>::mint(
|
|
RawOrigin::Signed(ADDRESS.into()).into(),
|
|
balance.coin,
|
|
address,
|
|
balance.amount.0,
|
|
)
|
|
.unwrap();
|
|
Pallet::<T>::deposit_event(Event::Mint { address, balance });
|
|
}
|
|
}
|
|
|
|
#[pallet::call]
|
|
impl<T: Config> Pallet<T> {
|
|
#[pallet::call_index(0)]
|
|
#[pallet::weight((0, DispatchClass::Normal))] // TODO
|
|
pub fn burn(
|
|
origin: OriginFor<T>,
|
|
balance: Balance,
|
|
instruction: OutInstruction,
|
|
) -> DispatchResult {
|
|
Self::burn_internal(ensure_signed(origin)?.into(), balance, instruction)
|
|
}
|
|
}
|
|
}
|
|
|
|
pub use pallet::*;
|