mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 04:09:23 +00:00
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:
@@ -19,7 +19,7 @@ use serai_client::{
|
||||
},
|
||||
coins::{
|
||||
primitives::{OutInstruction, OutInstructionWithBalance},
|
||||
TokensEvent,
|
||||
CoinsEvent,
|
||||
},
|
||||
in_instructions::primitives::{InInstruction, InInstructionWithBalance, Batch},
|
||||
SeraiCoins,
|
||||
@@ -206,12 +206,13 @@ async fn sign_test() {
|
||||
let address = SeraiAddress::from(pair.public());
|
||||
|
||||
// Fund the new account to pay for fees
|
||||
let balance = Balance { coin: Coin::Serai, amount: Amount(1_000_000_000) };
|
||||
serai
|
||||
.publish(
|
||||
&serai
|
||||
.sign(
|
||||
&PairSigner::new(insecure_pair_from_name("Ferdie")),
|
||||
&SeraiCoins::transfer_sri(address, Amount(1_000_000_000)),
|
||||
&SeraiCoins::transfer(address, balance),
|
||||
0,
|
||||
Default::default(),
|
||||
)
|
||||
@@ -249,29 +250,32 @@ async fn sign_test() {
|
||||
serai.block_by_number(block_included_in).await.unwrap().unwrap().hash();
|
||||
|
||||
let serai = serai.as_of(block_included_in_hash).coins();
|
||||
assert_eq!(serai.sri_balance(serai_addr).await.unwrap(), 1_000_000_000);
|
||||
assert_eq!(
|
||||
serai.coin_balance(Coin::Serai, serai_addr).await.unwrap(),
|
||||
Amount(1_000_000_000)
|
||||
);
|
||||
|
||||
// Verify the mint occurred as expected
|
||||
assert_eq!(
|
||||
serai.mint_events().await.unwrap(),
|
||||
vec![TokensEvent::Mint { address: serai_addr, balance }]
|
||||
vec![CoinsEvent::Mint { address: serai_addr, balance }]
|
||||
);
|
||||
assert_eq!(serai.token_supply(Coin::Bitcoin).await.unwrap(), amount);
|
||||
assert_eq!(serai.token_balance(Coin::Bitcoin, serai_addr).await.unwrap(), amount);
|
||||
assert_eq!(serai.coin_supply(Coin::Bitcoin).await.unwrap(), amount);
|
||||
assert_eq!(serai.coin_balance(Coin::Bitcoin, serai_addr).await.unwrap(), amount);
|
||||
}
|
||||
|
||||
// Trigger a burn
|
||||
let out_instruction =
|
||||
OutInstruction { address: ExternalAddress::new(b"external".to_vec()).unwrap(), data: None };
|
||||
let out_instruction = OutInstructionWithBalance {
|
||||
balance,
|
||||
instruction: OutInstruction {
|
||||
address: ExternalAddress::new(b"external".to_vec()).unwrap(),
|
||||
data: None,
|
||||
},
|
||||
};
|
||||
serai
|
||||
.publish(
|
||||
&serai
|
||||
.sign(
|
||||
&serai_pair,
|
||||
&SeraiCoins::burn(balance, out_instruction.clone()),
|
||||
0,
|
||||
Default::default(),
|
||||
)
|
||||
.sign(&serai_pair, &SeraiCoins::burn(out_instruction.clone()), 0, Default::default())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
@@ -297,11 +301,7 @@ async fn sign_test() {
|
||||
assert_eq!(burn_events.len(), 1);
|
||||
assert_eq!(
|
||||
burn_events[0],
|
||||
TokensEvent::Burn {
|
||||
address: serai_addr,
|
||||
balance,
|
||||
instruction: out_instruction.clone()
|
||||
}
|
||||
CoinsEvent::Burn { address: serai_addr, instruction: out_instruction.clone() }
|
||||
);
|
||||
break 'outer;
|
||||
}
|
||||
@@ -312,8 +312,8 @@ async fn sign_test() {
|
||||
let last_serai_block = serai.block_by_number(last_serai_block).await.unwrap().unwrap();
|
||||
let last_serai_block_hash = last_serai_block.hash();
|
||||
let serai = serai.as_of(last_serai_block_hash).coins();
|
||||
assert_eq!(serai.token_supply(Coin::Bitcoin).await.unwrap(), Amount(0));
|
||||
assert_eq!(serai.token_balance(Coin::Bitcoin, serai_addr).await.unwrap(), Amount(0));
|
||||
assert_eq!(serai.coin_supply(Coin::Bitcoin).await.unwrap(), Amount(0));
|
||||
assert_eq!(serai.coin_balance(Coin::Bitcoin, serai_addr).await.unwrap(), Amount(0));
|
||||
|
||||
let mut plan_id = [0; 32];
|
||||
OsRng.fill_bytes(&mut plan_id);
|
||||
@@ -331,10 +331,7 @@ async fn sign_test() {
|
||||
},
|
||||
network: NetworkId::Bitcoin,
|
||||
block: last_serai_block.number(),
|
||||
burns: vec![OutInstructionWithBalance {
|
||||
instruction: out_instruction.clone(),
|
||||
balance: Balance { coin: Coin::Bitcoin, amount }
|
||||
}],
|
||||
burns: vec![out_instruction.clone()],
|
||||
batches: vec![],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ use serai_client::{
|
||||
},
|
||||
validator_sets::primitives::{Session, ValidatorSet},
|
||||
in_instructions::primitives::Shorthand,
|
||||
coins::primitives::OutInstruction,
|
||||
coins::primitives::{OutInstruction, OutInstructionWithBalance},
|
||||
PairTrait, PairSigner, SeraiCoins,
|
||||
};
|
||||
|
||||
@@ -236,12 +236,13 @@ async fn mint_and_burn_test() {
|
||||
let address = SeraiAddress::from(pair.public());
|
||||
|
||||
// Fund the new account to pay for fees
|
||||
let balance = Balance { coin: Coin::Serai, amount: Amount(1_000_000_000) };
|
||||
serai
|
||||
.publish(
|
||||
&serai
|
||||
.sign(
|
||||
&PairSigner::new(insecure_pair_from_name("Ferdie")),
|
||||
&SeraiCoins::transfer_sri(address, Amount(1_000_000_000)),
|
||||
&SeraiCoins::transfer(address, balance),
|
||||
0,
|
||||
Default::default(),
|
||||
)
|
||||
@@ -488,17 +489,15 @@ async fn mint_and_burn_test() {
|
||||
let serai = &serai;
|
||||
let serai_pair = &serai_pair;
|
||||
move |nonce, coin, amount, address| async move {
|
||||
let out_instruction = OutInstruction { address, data: None };
|
||||
let out_instruction = OutInstructionWithBalance {
|
||||
balance: Balance { coin, amount: Amount(amount) },
|
||||
instruction: OutInstruction { address, data: None },
|
||||
};
|
||||
|
||||
serai
|
||||
.publish(
|
||||
&serai
|
||||
.sign(
|
||||
serai_pair,
|
||||
&SeraiCoins::burn(Balance { coin, amount: Amount(amount) }, out_instruction),
|
||||
nonce,
|
||||
Default::default(),
|
||||
)
|
||||
.sign(serai_pair, &SeraiCoins::burn(out_instruction), nonce, Default::default())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user