mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 04:39:24 +00:00
Add Substrate "assets" pallet
While over-engineered for our purposes, it's still usable. Also cleans the runtime a bit.
This commit is contained in:
31
substrate/serai/primitives/src/amount.rs
Normal file
31
substrate/serai/primitives/src/amount.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use core::{ops::{Add, Mul}};
|
||||
|
||||
use scale::{Encode, Decode, MaxEncodedLen};
|
||||
use scale_info::TypeInfo;
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
/// The type used for amounts.
|
||||
#[derive(
|
||||
Clone, Copy, PartialEq, Eq, PartialOrd, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
|
||||
)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub struct Amount(pub u64);
|
||||
|
||||
/// One whole coin with eight decimals.
|
||||
#[allow(clippy::inconsistent_digit_grouping)]
|
||||
pub const COIN: Amount = Amount(1_000_000_00);
|
||||
|
||||
impl Add for Amount {
|
||||
type Output = Amount;
|
||||
fn add(self, other: Amount) -> Amount {
|
||||
Amount(self.0 + other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Amount {
|
||||
type Output = Amount;
|
||||
fn mul(self, other: Amount) -> Amount {
|
||||
Amount(self.0 * other.0)
|
||||
}
|
||||
}
|
||||
19
substrate/serai/primitives/src/coins.rs
Normal file
19
substrate/serai/primitives/src/coins.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use scale::{Encode, Decode, MaxEncodedLen};
|
||||
use scale_info::TypeInfo;
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
/// The type used to identify coins.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub struct Coin(pub u32);
|
||||
impl From<u32> for Coin {
|
||||
fn from(coin: u32) -> Coin {
|
||||
Coin(coin)
|
||||
}
|
||||
}
|
||||
|
||||
pub const BITCOIN: Coin = Coin(0);
|
||||
pub const ETHER: Coin = Coin(1);
|
||||
pub const DAI: Coin = Coin(2);
|
||||
pub const MONERO: Coin = Coin(3);
|
||||
@@ -1,36 +1,7 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use core::ops::{Add, Mul};
|
||||
mod amount;
|
||||
pub use amount::*;
|
||||
|
||||
use scale::{Encode, Decode, MaxEncodedLen};
|
||||
use scale_info::TypeInfo;
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
/// The type used for amounts.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub struct Amount(pub u64);
|
||||
|
||||
impl Add<Amount> for Amount {
|
||||
type Output = Amount;
|
||||
fn add(self, other: Amount) -> Amount {
|
||||
Amount(self.0 + other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<Amount> for Amount {
|
||||
type Output = Amount;
|
||||
fn mul(self, other: Amount) -> Amount {
|
||||
Amount(self.0 * other.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// One whole coin with eight decimals.
|
||||
#[allow(clippy::inconsistent_digit_grouping)]
|
||||
pub const COIN: Amount = Amount(1_000_000_00);
|
||||
|
||||
/// The type used to identify coins.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub struct Coin(pub u32);
|
||||
mod coins;
|
||||
pub use coins::*;
|
||||
|
||||
Reference in New Issue
Block a user