Coins pallet (#399)

* initial implementation

* add function to get a balance of an account

* add support for multiple coins

* rename pallet to "coins-pallet"

* replace balances, assets and tokens pallet with coins pallet in runtime

* add total supply info

* update client side for new Coins pallet

* handle fees

* bug fixes

* Update FeeAccount test

* Fmt

* fix pr comments

* remove extraneous Imbalance type

* Minor tweaks

---------

Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
akildemir
2023-10-19 13:22:21 +03:00
committed by GitHub
parent 3255c0ace5
commit fdfce9e207
32 changed files with 535 additions and 445 deletions

View File

@@ -28,7 +28,7 @@ frame-support = { git = "https://github.com/serai-dex/substrate", default-featur
serai-primitives = { path = "../../primitives", default-features = false }
in-instructions-primitives = { package = "serai-in-instructions-primitives", path = "../primitives", default-features = false }
tokens-pallet = { package = "serai-tokens-pallet", path = "../../tokens/pallet", default-features = false }
coins-pallet = { package = "serai-coins-pallet", path = "../../coins/pallet", default-features = false }
validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../../validator-sets/pallet", default-features = false }
[features]
@@ -49,7 +49,7 @@ std = [
"serai-primitives/std",
"in-instructions-primitives/std",
"tokens-pallet/std",
"coins-pallet/std",
"validator-sets-pallet/std",
]
default = ["std"]

View File

@@ -30,7 +30,7 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use tokens_pallet::{Config as TokensConfig, Pallet as Tokens};
use coins_pallet::{Config as CoinsConfig, Pallet as Coins};
use validator_sets_pallet::{
primitives::{Session, ValidatorSet},
Config as ValidatorSetsConfig, Pallet as ValidatorSets,
@@ -39,7 +39,7 @@ pub mod pallet {
use super::*;
#[pallet::config]
pub trait Config: frame_system::Config + ValidatorSetsConfig + TokensConfig {
pub trait Config: frame_system::Config + ValidatorSetsConfig + CoinsConfig {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
@@ -73,10 +73,11 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
fn execute(instruction: InInstructionWithBalance) -> Result<(), ()> {
match instruction.instruction {
InInstruction::Transfer(address) => Tokens::<T>::mint(address, instruction.balance),
InInstruction::Transfer(address) => {
Coins::<T>::mint(&address.into(), instruction.balance).map_err(|_| ())
}
_ => panic!("unsupported instruction"),
}
Ok(())
}
}