Skip to content

Commit

Permalink
update to develop latest
Browse files Browse the repository at this point in the history
  • Loading branch information
akildemir authored and akildemir committed Aug 15, 2024
2 parents 49ea38b + ab7df0f commit 3c6eefc
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 34 deletions.
2 changes: 2 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ exceptions = [

{ allow = ["AGPL-3.0"], name = "serai-genesis-liquidity-pallet" },
{ allow = ["AGPL-3.0"], name = "serai-emissions-pallet" },

{ allow = ["AGPL-3.0"], name = "serai-economic-security-pallet" },

{ allow = ["AGPL-3.0"], name = "serai-in-instructions-pallet" },

Expand Down
5 changes: 2 additions & 3 deletions substrate/client/src/serai/genesis_liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ impl<'a> SeraiGenesisLiquidity<'a> {
Ok(self.0.storage(PALLET, "Supply", coin).await?.unwrap_or(LiquidityAmount::zero()))
}

pub async fn genesis_complete(&self) -> Result<bool, SeraiError> {
let result: Option<()> = self.0.storage(PALLET, "GenesisComplete", ()).await?;
Ok(result.is_some())
pub async fn genesis_complete_block(&self) -> Result<Option<u64>, SeraiError> {
self.0.storage(PALLET, "GenesisCompleteBlock", ()).await
}
}
22 changes: 11 additions & 11 deletions substrate/client/tests/emissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ async fn test_emissions(serai: Serai) {
let (_, mut batch_ids) = set_up_genesis(&serai, &coins, &values).await;

// wait until genesis is complete
while !serai
.as_of_latest_finalized_block()
.await
.unwrap()
.genesis_liquidity()
.genesis_complete()
.await
.unwrap()
{
let mut genesis_complete_block = None;
while genesis_complete_block.is_none() {
tokio::time::sleep(Duration::from_secs(1)).await;
genesis_complete_block = serai
.as_of_latest_finalized_block()
.await
.unwrap()
.genesis_liquidity()
.genesis_complete_block()
.await
.unwrap();
}
let genesis_complete_block = serai.latest_finalized_block().await.unwrap().number();

for _ in 0 .. 3 {
// get current stakes
Expand Down Expand Up @@ -99,7 +99,7 @@ async fn test_emissions(serai: Serai) {

// calculate how much reward in this session
let reward_this_epoch =
if change_block_number < (genesis_complete_block + FAST_EPOCH_INITIAL_PERIOD) {
if change_block_number < (genesis_complete_block.unwrap() + FAST_EPOCH_INITIAL_PERIOD) {
block_count * INITIAL_REWARD_PER_BLOCK
} else {
let blocks_until = SECURE_BY - change_block_number;
Expand Down
5 changes: 3 additions & 2 deletions substrate/client/tests/genesis_liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ pub async fn test_genesis_liquidity(serai: Serai) {
let (accounts, _) = set_up_genesis(&serai, &coins, &values).await;

// wait until genesis is complete
while !serai
while serai
.as_of_latest_finalized_block()
.await
.unwrap()
.genesis_liquidity()
.genesis_complete()
.genesis_complete_block()
.await
.unwrap()
.is_none()
{
tokio::time::sleep(Duration::from_secs(1)).await;
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/emissions/pallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
description = "Emissions pallet for Serai"
license = "AGPL-3.0-only"
repository = "https://github.com/serai-dex/serai/tree/develop/substrate/emissions/pallet"
authors = ["Akil Demir <aeg_asd@hotmail.com>"]
authors = ["Akil Demir <akildemir72@gmail.com>"]
edition = "2021"
rust-version = "1.77"

Expand Down
15 changes: 3 additions & 12 deletions substrate/emissions/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ pub mod pallet {
#[pallet::getter(fn session)]
pub type CurrentSession<T: Config> = StorageMap<_, Identity, NetworkId, u32, ValueQuery>;

// TODO: Find a better place for this
#[pallet::storage]
pub(crate) type GenesisCompleteBlock<T: Config> = StorageValue<_, u64, OptionQuery>;

#[pallet::storage]
pub(crate) type LastSwapVolume<T: Config> = StorageMap<_, Identity, Coin, u64, OptionQuery>;

Expand All @@ -103,12 +99,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
if GenesisCompleteBlock::<T>::get().is_none() &&
GenesisLiquidity::<T>::genesis_complete().is_some()
{
GenesisCompleteBlock::<T>::set(Some(n.saturated_into::<u64>()));
}
let genesis_ended = GenesisLiquidity::<T>::genesis_complete().is_some();
let genesis_ended = GenesisLiquidity::<T>::genesis_complete_block().is_some();

// check if we got a new session
let mut session_changed = false;
Expand Down Expand Up @@ -297,7 +288,7 @@ pub mod pallet {

// TODO: we have the past session participants here in the emissions pallet so that we can
// distribute rewards to them in the next session. Ideally we should be able to fetch this
// information from valiadtor sets pallet.
// information from validator sets pallet.
Self::update_participants();
Weight::zero() // TODO
}
Expand All @@ -316,7 +307,7 @@ pub mod pallet {
#[cfg(not(feature = "fast-epoch"))]
let initial_period_duration = 2 * MONTHS;

let genesis_complete_block = GenesisCompleteBlock::<T>::get();
let genesis_complete_block = GenesisLiquidity::<T>::genesis_complete_block();
genesis_complete_block.is_some() &&
(n.saturated_into::<u64>() < (genesis_complete_block.unwrap() + initial_period_duration))
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/emissions/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
description = "Serai emissions primitives"
license = "MIT"
repository = "https://github.com/serai-dex/serai/tree/develop/substrate/emissions/primitives"
authors = ["Akil Demir <aeg_asd@hotmail.com>"]
authors = ["Akil Demir <akildemir72@gmail.com>"]
edition = "2021"
rust-version = "1.77"

Expand Down
8 changes: 4 additions & 4 deletions substrate/genesis-liquidity/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub mod pallet {
pub(crate) type Oracle<T: Config> = StorageMap<_, Identity, Coin, u64, OptionQuery>;

#[pallet::storage]
#[pallet::getter(fn genesis_complete)]
pub(crate) type GenesisComplete<T: Config> = StorageValue<_, (), OptionQuery>;
#[pallet::getter(fn genesis_complete_block)]
pub(crate) type GenesisCompleteBlock<T: Config> = StorageValue<_, u64, OptionQuery>;

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
Expand All @@ -85,7 +85,7 @@ pub mod pallet {
// Distribute the genesis sri to pools after a month
if (n.saturated_into::<u64>() >= final_block) &&
Self::oraclization_is_done() &&
GenesisComplete::<T>::get().is_none()
GenesisCompleteBlock::<T>::get().is_none()
{
// mint the SRI
Coins::<T>::mint(
Expand Down Expand Up @@ -165,7 +165,7 @@ pub mod pallet {
assert_eq!(Coins::<T>::balance(GENESIS_LIQUIDITY_ACCOUNT.into(), coin), Amount(0));
}

GenesisComplete::<T>::set(Some(()));
GenesisCompleteBlock::<T>::set(Some(n.saturated_into::<u64>()));
}

Weight::zero() // TODO
Expand Down

0 comments on commit 3c6eefc

Please sign in to comment.