mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-28 06:29:38 +00:00
cccc1fc7e6
Some checks are pending
Full Stack Tests / build (push) Waiting to run
Lint / fmt (push) Waiting to run
Lint / machete (push) Waiting to run
Lint / clippy (macos-13) (push) Waiting to run
Lint / clippy (macos-14) (push) Waiting to run
Lint / clippy (ubuntu-latest) (push) Waiting to run
Lint / clippy (windows-latest) (push) Waiting to run
Lint / deny (push) Waiting to run
Reproducible Runtime / build (push) Waiting to run
Tests / test-infra (push) Waiting to run
Tests / test-substrate (push) Waiting to run
Tests / test-serai-client (push) Waiting to run
* add genesis liquidity implementation * add missing deposit event * fix CI issues * minor fixes * make math safer * fix fmt * implement block emissions * make remove liquidity an authorized call * implement setting initial values for coins * add genesis liquidity test & misc fixes * updato develop latest * fix rotation test * fix licencing * add fast-epoch feature * only create the pool when adding liquidity first time * add initial reward era test * test whole pre ec security emissions * fix clippy * add swap-to-staked-sri feature * rebase changes * fix tests * Remove accidentally commited ETH ABI files * fix some pr comments * Finish up fixing pr comments * exclude SRI from is_allowed check * Misc changes --------- Co-authored-by: akildemir <aeg_asd@hotmail.com> Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
87 lines
2.3 KiB
Rust
87 lines
2.3 KiB
Rust
use rand_core::{RngCore, OsRng};
|
|
use blake2::{
|
|
digest::{consts::U32, Digest},
|
|
Blake2b,
|
|
};
|
|
|
|
use scale::Encode;
|
|
|
|
use sp_core::Pair;
|
|
|
|
use serai_client::{
|
|
primitives::{insecure_pair_from_name, BlockHash, NetworkId, Balance, SeraiAddress},
|
|
validator_sets::primitives::{ValidatorSet, KeyPair},
|
|
in_instructions::{
|
|
primitives::{Batch, SignedBatch, batch_message, InInstruction, InInstructionWithBalance},
|
|
InInstructionsEvent,
|
|
},
|
|
SeraiInInstructions, Serai,
|
|
};
|
|
|
|
use crate::common::{tx::publish_tx, validator_sets::set_keys};
|
|
|
|
#[allow(dead_code)]
|
|
pub async fn provide_batch(serai: &Serai, batch: Batch) -> [u8; 32] {
|
|
let serai_latest = serai.as_of_latest_finalized_block().await.unwrap();
|
|
let session = serai_latest.validator_sets().session(batch.network).await.unwrap().unwrap();
|
|
let set = ValidatorSet { session, network: batch.network };
|
|
|
|
let pair = insecure_pair_from_name(&format!("ValidatorSet {set:?}"));
|
|
let keys = if let Some(keys) = serai_latest.validator_sets().keys(set).await.unwrap() {
|
|
keys
|
|
} else {
|
|
let keys = KeyPair(pair.public(), vec![].try_into().unwrap());
|
|
set_keys(serai, set, keys.clone(), &[insecure_pair_from_name("Alice")]).await;
|
|
keys
|
|
};
|
|
assert_eq!(keys.0, pair.public());
|
|
|
|
let block = publish_tx(
|
|
serai,
|
|
&SeraiInInstructions::execute_batch(SignedBatch {
|
|
batch: batch.clone(),
|
|
signature: pair.sign(&batch_message(&batch)),
|
|
}),
|
|
)
|
|
.await;
|
|
|
|
let batches = serai.as_of(block).in_instructions().batch_events().await.unwrap();
|
|
// TODO: impl From<Batch> for BatchEvent?
|
|
assert_eq!(
|
|
batches,
|
|
vec![InInstructionsEvent::Batch {
|
|
network: batch.network,
|
|
id: batch.id,
|
|
block: batch.block,
|
|
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
|
}],
|
|
);
|
|
|
|
// TODO: Check the tokens events
|
|
|
|
block
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub async fn mint_coin(
|
|
serai: &Serai,
|
|
balance: Balance,
|
|
network: NetworkId,
|
|
batch_id: u32,
|
|
address: SeraiAddress,
|
|
) -> [u8; 32] {
|
|
let mut block_hash = BlockHash([0; 32]);
|
|
OsRng.fill_bytes(&mut block_hash.0);
|
|
|
|
let batch = Batch {
|
|
network,
|
|
id: batch_id,
|
|
block: block_hash,
|
|
instructions: vec![InInstructionWithBalance {
|
|
instruction: InInstruction::Transfer(address),
|
|
balance,
|
|
}],
|
|
};
|
|
|
|
provide_batch(serai, batch).await
|
|
}
|