Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akildemir committed Nov 28, 2023
1 parent ad3af04 commit ba74589
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions substrate/dex/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ pub mod pallet {
#[pallet::getter(fn oracle_prices)]
pub type OraclePrices<T: Config> = StorageMap<_, Identity, [u8; 8], u16, OptionQuery>;
impl<T: Config> Pallet<T> {
// TODO: make sure this is correct
/// Get the highest sustained(lowest) value of the window
pub fn highest_sustained_price() -> Amount {
let mut iter = OraclePrices::<T>::iter_keys();
iter.set_last_raw_key(0u64.to_be_bytes().to_vec());
// we can unwrap because we will always have at least 1 key in this map
// before this function is called.
Amount(u64::from_be_bytes(iter.next().unwrap()))
}
}
Expand All @@ -181,7 +181,7 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A successful call of the `CretaPool` extrinsic will create this event.
/// A successful call of the `CreatePool` extrinsic will create this event.
PoolCreated {
/// The pool id associated with the pool. Note that the order of the coins may not be
/// the same as the order specified in the create pool extrinsic.
Expand Down Expand Up @@ -338,7 +338,7 @@ pub mod pallet {
for coin in Pools::<T>::iter_keys() {
// insert the new price to our oracle window
let last = Self::quote_price_exact_tokens_for_tokens(coin, Coin::native(), 1, false)
.unwrap()
.unwrap_or(0)
.to_be_bytes();
LastQuoteForBlock::<T>::set(n, coin, last);
let observed = OraclePrices::<T>::get(last).unwrap_or(0);
Expand Down
2 changes: 1 addition & 1 deletion substrate/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ construct_runtime!(

TransactionPayment: transaction_payment,

Dex: dex,
Coins: coins,
LiquidityTokens: coins::<Instance1>::{Pallet, Call, Storage, Event<T>},
Dex: dex,

ValidatorSets: validator_sets,

Expand Down
15 changes: 6 additions & 9 deletions substrate/validator-sets/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,11 @@ pub mod pallet {
// of each session since we have to wait for that block to end to update the window and
// the oracle value accordingly.
let price = Dex::<T>::oracle_value(balance.coin).unwrap_or(Amount(0));
let total_coin_value = balance.amount.0.saturating_mul(price.0);
let mut total_coin_value = balance.amount.0.saturating_mul(price.0);

// required stake formula (COIN_VALUE * 1.5) + margin(20%)
total_coin_value.saturating_mul(3).saturating_div(2).saturating_div(5)
total_coin_value = total_coin_value.saturating_mul(3).saturating_div(2);
total_coin_value.saturating_add(total_coin_value.saturating_div(5))
}

/// Returns the current total required stake for a given `network`.
Expand Down Expand Up @@ -884,13 +885,9 @@ pub mod pallet {
let current_required = Self::required_stake_for_network(balance.coin.network());
let new_required = current_required.saturating_add(Self::required_stake(balance));

// get the total stake for the network
let staked = Self::total_allocated_stake(balance.coin.network());
if staked.is_none() {
return false;
}

staked.unwrap().0 >= new_required
// get the total stake for the network & compare.
let staked = Self::total_allocated_stake(balance.coin.network()).unwrap_or(Amount(0));
staked.0 >= new_required
}
}

Expand Down

0 comments on commit ba74589

Please sign in to comment.