implement block emissions

This commit is contained in:
akildemir
2024-04-09 11:14:07 +03:00
parent 8be0538eba
commit 1cd9868433
15 changed files with 545 additions and 6 deletions

View File

@@ -194,6 +194,11 @@ pub mod pallet {
#[pallet::getter(fn security_oracle_value)]
pub type SecurityOracleValue<T: Config> = StorageMap<_, Identity, Coin, Amount, OptionQuery>;
/// Current length of the `SpotPrices` map.
#[pallet::storage]
#[pallet::getter(fn swap_volume)]
pub type SwapVolume<T: Config> = StorageMap<_, Identity, Coin, u64, OptionQuery>;
impl<T: Config> Pallet<T> {
fn restore_median(
coin: Coin,
@@ -890,6 +895,20 @@ pub mod pallet {
}
i += 1;
}
// update the volume, SRI amount is always at index 1 if the path len is 2 or 3.
// path len 1 is not allowed and 3 is already the maximum.
let swap_volume = amounts.get(1).ok_or(Error::<T>::CorrespondenceError)?;
let existing = SwapVolume::<T>::get(coin1).unwrap_or(0);
let new_volume = existing.saturating_add(*swap_volume);
SwapVolume::<T>::set(coin1, Some(new_volume));
// if we did 2 pools, update the volume for second coin as well.
if u32::try_from(path.len()).unwrap() == T::MaxSwapPathLength::get() {
let existing = SwapVolume::<T>::get(path.last().unwrap()).unwrap_or(0);
let new_volume = existing.saturating_add(*swap_volume);
SwapVolume::<T>::set(path.last().unwrap(), Some(new_volume));
}
Self::deposit_event(Event::SwapExecuted {
who: sender,
send_to,