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

@@ -7,6 +7,7 @@ use blake2::{
use scale::Encode;
use serai_runtime::coins::primitives::OutInstructionWithBalance;
use sp_core::Pair;
use serai_client::{
@@ -19,7 +20,7 @@ use serai_client::{
InInstructionsEvent,
primitives::{InInstruction, InInstructionWithBalance, Batch},
},
coins::{primitives::OutInstruction, TokensEvent},
coins::{primitives::OutInstruction, CoinsEvent},
PairSigner, Serai, SeraiCoins,
};
@@ -69,10 +70,10 @@ serai_test!(
assert_eq!(
serai.coins().mint_events().await.unwrap(),
vec![TokensEvent::Mint { address, balance }]
vec![CoinsEvent::Mint { address, balance }]
);
assert_eq!(serai.coins().token_supply(coin).await.unwrap(), amount);
assert_eq!(serai.coins().token_balance(coin, address).await.unwrap(), amount);
assert_eq!(serai.coins().coin_supply(coin).await.unwrap(), amount);
assert_eq!(serai.coins().coin_balance(coin, address).await.unwrap(), amount);
// Now burn it
let mut rand_bytes = vec![0; 32];
@@ -83,13 +84,16 @@ serai_test!(
OsRng.fill_bytes(&mut rand_bytes);
let data = Data::new(rand_bytes).unwrap();
let out = OutInstruction { address: external_address, data: Some(data) };
let instruction = OutInstructionWithBalance {
balance,
instruction: OutInstruction { address: external_address, data: Some(data) },
};
let serai = serai.into_inner();
let block = publish_tx(
&serai
.sign(
&PairSigner::new(pair),
&SeraiCoins::burn(balance, out.clone()),
&SeraiCoins::burn(instruction.clone()),
0,
BaseExtrinsicParamsBuilder::new(),
)
@@ -99,8 +103,8 @@ serai_test!(
let serai = serai.as_of(block).coins();
let events = serai.burn_events().await.unwrap();
assert_eq!(events, vec![TokensEvent::Burn { address, balance, instruction: out }]);
assert_eq!(serai.token_supply(coin).await.unwrap(), Amount(0));
assert_eq!(serai.token_balance(coin, address).await.unwrap(), Amount(0));
assert_eq!(events, vec![CoinsEvent::Burn { address, instruction }]);
assert_eq!(serai.coin_supply(coin).await.unwrap(), Amount(0));
assert_eq!(serai.coin_balance(coin, address).await.unwrap(), Amount(0));
}
);