mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-14 15:09:23 +00:00
misc fixes
This commit is contained in:
@@ -12,7 +12,7 @@ use tokio::{
|
|||||||
use borsh::BorshSerialize;
|
use borsh::BorshSerialize;
|
||||||
use sp_application_crypto::RuntimePublic;
|
use sp_application_crypto::RuntimePublic;
|
||||||
use serai_client::{
|
use serai_client::{
|
||||||
primitives::{ExternalNetworkId, NetworkId, Signature, EXTERNAL_NETWORKS, NETWORKS},
|
primitives::{ExternalNetworkId, Signature, EXTERNAL_NETWORKS},
|
||||||
validator_sets::primitives::{ExternalValidatorSet, Session},
|
validator_sets::primitives::{ExternalValidatorSet, Session},
|
||||||
Serai, SeraiError, TemporalSerai,
|
Serai, SeraiError, TemporalSerai,
|
||||||
};
|
};
|
||||||
@@ -204,11 +204,9 @@ impl<D: Db> CosignEvaluator<D> {
|
|||||||
|
|
||||||
let mut total_stake = 0;
|
let mut total_stake = 0;
|
||||||
let mut total_on_distinct_chain = 0;
|
let mut total_on_distinct_chain = 0;
|
||||||
for network in NETWORKS {
|
// TODO: `network` isn't being used in the following loop. is this a bug?
|
||||||
if network == NetworkId::Serai {
|
// why are we going through the networks here?
|
||||||
continue;
|
for _network in EXTERNAL_NETWORKS {
|
||||||
}
|
|
||||||
|
|
||||||
// Get the current set for this network
|
// Get the current set for this network
|
||||||
let set_with_keys = {
|
let set_with_keys = {
|
||||||
let mut res;
|
let mut res;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use serai_primitives::NetworkId;
|
use serai_primitives::ExternalNetworkId;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
|
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
|
||||||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
EconomicSecurityReached { network: NetworkId },
|
EconomicSecurityReached { network: ExternalNetworkId },
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,5 +17,4 @@ pub enum Event {
|
|||||||
GenesisLiquidityAdded { by: SeraiAddress, balance: ExternalBalance },
|
GenesisLiquidityAdded { by: SeraiAddress, balance: ExternalBalance },
|
||||||
GenesisLiquidityRemoved { by: SeraiAddress, balance: ExternalBalance },
|
GenesisLiquidityRemoved { by: SeraiAddress, balance: ExternalBalance },
|
||||||
GenesisLiquidityAddedToPool { coin: ExternalBalance, sri: Amount },
|
GenesisLiquidityAddedToPool { coin: ExternalBalance, sri: Amount },
|
||||||
EconomicSecurityReached { network: NetworkId },
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use scale::Encode;
|
use scale::Encode;
|
||||||
|
|
||||||
use serai_abi::primitives::{SeraiAddress, Amount, Coin, Balance};
|
use serai_abi::primitives::{Amount, ExternalBalance, ExternalCoin, SeraiAddress};
|
||||||
|
|
||||||
use crate::{TemporalSerai, SeraiError};
|
use crate::{TemporalSerai, SeraiError};
|
||||||
|
|
||||||
@@ -9,13 +9,13 @@ const PALLET: &str = "LiquidityTokens";
|
|||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct SeraiLiquidityTokens<'a>(pub(crate) &'a TemporalSerai<'a>);
|
pub struct SeraiLiquidityTokens<'a>(pub(crate) &'a TemporalSerai<'a>);
|
||||||
impl<'a> SeraiLiquidityTokens<'a> {
|
impl<'a> SeraiLiquidityTokens<'a> {
|
||||||
pub async fn token_supply(&self, coin: Coin) -> Result<Amount, SeraiError> {
|
pub async fn token_supply(&self, coin: ExternalCoin) -> Result<Amount, SeraiError> {
|
||||||
Ok(self.0.storage(PALLET, "Supply", coin).await?.unwrap_or(Amount(0)))
|
Ok(self.0.storage(PALLET, "Supply", coin).await?.unwrap_or(Amount(0)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn token_balance(
|
pub async fn token_balance(
|
||||||
&self,
|
&self,
|
||||||
coin: Coin,
|
coin: ExternalCoin,
|
||||||
address: SeraiAddress,
|
address: SeraiAddress,
|
||||||
) -> Result<Amount, SeraiError> {
|
) -> Result<Amount, SeraiError> {
|
||||||
Ok(
|
Ok(
|
||||||
@@ -31,11 +31,16 @@ impl<'a> SeraiLiquidityTokens<'a> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transfer(to: SeraiAddress, balance: Balance) -> serai_abi::Call {
|
pub fn transfer(to: SeraiAddress, balance: ExternalBalance) -> serai_abi::Call {
|
||||||
serai_abi::Call::LiquidityTokens(serai_abi::liquidity_tokens::Call::transfer { to, balance })
|
serai_abi::Call::LiquidityTokens(serai_abi::liquidity_tokens::Call::transfer {
|
||||||
|
to,
|
||||||
|
balance: balance.into(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn burn(balance: Balance) -> serai_abi::Call {
|
pub fn burn(balance: ExternalBalance) -> serai_abi::Call {
|
||||||
serai_abi::Call::LiquidityTokens(serai_abi::liquidity_tokens::Call::burn { balance })
|
serai_abi::Call::LiquidityTokens(serai_abi::liquidity_tokens::Call::burn {
|
||||||
|
balance: balance.into(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ mod tests;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod mock;
|
mod mock;
|
||||||
|
|
||||||
use frame_support::ensure;
|
use frame_support::{ensure, pallet_prelude::*, BoundedBTreeSet};
|
||||||
use frame_system::{
|
use frame_system::{
|
||||||
pallet_prelude::{BlockNumberFor, OriginFor},
|
pallet_prelude::{BlockNumberFor, OriginFor},
|
||||||
ensure_signed,
|
ensure_signed,
|
||||||
@@ -86,9 +86,12 @@ use frame_system::{
|
|||||||
|
|
||||||
pub use pallet::*;
|
pub use pallet::*;
|
||||||
|
|
||||||
use sp_runtime::{traits::TrailingZeroInput, DispatchError};
|
use sp_runtime::{
|
||||||
|
traits::{TrailingZeroInput, IntegerSquareRoot},
|
||||||
|
DispatchError,
|
||||||
|
};
|
||||||
|
|
||||||
use serai_primitives::{Coin, ExternalCoin, SubstrateAmount};
|
use serai_primitives::*;
|
||||||
|
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
pub use types::*;
|
pub use types::*;
|
||||||
@@ -103,15 +106,11 @@ pub use weights::WeightInfo;
|
|||||||
#[frame_support::pallet]
|
#[frame_support::pallet]
|
||||||
pub mod pallet {
|
pub mod pallet {
|
||||||
use super::*;
|
use super::*;
|
||||||
use frame_support::{pallet_prelude::*, BoundedBTreeSet};
|
|
||||||
|
|
||||||
use sp_core::sr25519::Public;
|
use sp_core::sr25519::Public;
|
||||||
use sp_runtime::traits::IntegerSquareRoot;
|
|
||||||
|
|
||||||
use coins_pallet::{Pallet as CoinsPallet, Config as CoinsConfig};
|
use coins_pallet::{Pallet as CoinsPallet, Config as CoinsConfig};
|
||||||
|
|
||||||
use serai_primitives::{NetworkId, *};
|
|
||||||
|
|
||||||
/// Pool ID.
|
/// Pool ID.
|
||||||
///
|
///
|
||||||
/// The pool's `AccountId` is derived from this type. Any changes to the type may necessitate a
|
/// The pool's `AccountId` is derived from this type. Any changes to the type may necessitate a
|
||||||
|
|||||||
@@ -18,7 +18,10 @@
|
|||||||
// It has been forked into a crate distributed under the AGPL 3.0.
|
// It has been forked into a crate distributed under the AGPL 3.0.
|
||||||
// Please check the current distribution for up-to-date copyright and licensing information.
|
// Please check the current distribution for up-to-date copyright and licensing information.
|
||||||
|
|
||||||
use crate::{mock::*, *};
|
use crate::{
|
||||||
|
mock::{*, MEDIAN_PRICE_WINDOW_LENGTH},
|
||||||
|
*,
|
||||||
|
};
|
||||||
use frame_support::{assert_noop, assert_ok};
|
use frame_support::{assert_noop, assert_ok};
|
||||||
|
|
||||||
pub use coins_pallet as coins;
|
pub use coins_pallet as coins;
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ pub mod pallet {
|
|||||||
// we accept we reached economic security once we can mint smallest amount of a network's coin
|
// we accept we reached economic security once we can mint smallest amount of a network's coin
|
||||||
for coin in EXTERNAL_COINS {
|
for coin in EXTERNAL_COINS {
|
||||||
let existing = EconomicSecurityBlock::<T>::get(coin.network());
|
let existing = EconomicSecurityBlock::<T>::get(coin.network());
|
||||||
// TODO: we don't need this if is_allowed returns false when there is no coin value
|
// TODO: we don't need to check for oracle value if is_allowed returns false when there is
|
||||||
|
// no coin value
|
||||||
if existing.is_none() &&
|
if existing.is_none() &&
|
||||||
Dex::<T>::security_oracle_value(coin).is_some() &&
|
Dex::<T>::security_oracle_value(coin).is_some() &&
|
||||||
<T as CoinsConfig>::AllowMint::is_allowed(&ExternalBalance { coin, amount: Amount(1) })
|
<T as CoinsConfig>::AllowMint::is_allowed(&ExternalBalance { coin, amount: Amount(1) })
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use serde::{Serialize, Deserialize};
|
|||||||
use scale::{Encode, Decode, MaxEncodedLen};
|
use scale::{Encode, Decode, MaxEncodedLen};
|
||||||
use scale_info::TypeInfo;
|
use scale_info::TypeInfo;
|
||||||
|
|
||||||
use serai_primitives::{Coin, Amount, SeraiAddress, ExternalAddress};
|
use serai_primitives::{Amount, ExternalAddress, ExternalCoin, SeraiAddress};
|
||||||
|
|
||||||
use coins_primitives::OutInstruction;
|
use coins_primitives::OutInstruction;
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ pub enum Shorthand {
|
|||||||
Raw(RefundableInInstruction),
|
Raw(RefundableInInstruction),
|
||||||
Swap {
|
Swap {
|
||||||
origin: Option<ExternalAddress>,
|
origin: Option<ExternalAddress>,
|
||||||
coin: Coin,
|
coin: ExternalCoin,
|
||||||
minimum: Amount,
|
minimum: Amount,
|
||||||
out: OutInstruction,
|
out: OutInstruction,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -215,7 +215,6 @@ impl Coin {
|
|||||||
|
|
||||||
pub fn decimals(&self) -> u32 {
|
pub fn decimals(&self) -> u32 {
|
||||||
match self {
|
match self {
|
||||||
// Ether and DAI have 18 decimals, yet we only track 8 in order to fit them within u64s
|
|
||||||
Coin::Serai => 8,
|
Coin::Serai => 8,
|
||||||
Coin::External(c) => c.decimals(),
|
Coin::External(c) => c.decimals(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,8 +53,9 @@ use sp_runtime::{
|
|||||||
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use primitives::{
|
use primitives::{
|
||||||
NetworkId, PublicKey, AccountLookup, SubstrateAmount, Coin, NETWORKS, MEDIAN_PRICE_WINDOW_LENGTH,
|
NetworkId, PublicKey, AccountLookup, SubstrateAmount, Coin, EXTERNAL_NETWORKS,
|
||||||
HOURS, DAYS, MINUTES, TARGET_BLOCK_TIME, BLOCK_SIZE, FAST_EPOCH_DURATION,
|
MEDIAN_PRICE_WINDOW_LENGTH, HOURS, DAYS, MINUTES, TARGET_BLOCK_TIME, BLOCK_SIZE,
|
||||||
|
FAST_EPOCH_DURATION,
|
||||||
};
|
};
|
||||||
|
|
||||||
use support::{
|
use support::{
|
||||||
@@ -570,10 +571,7 @@ sp_api::impl_runtime_apis! {
|
|||||||
.map(|(id, _)| id.into_inner().0)
|
.map(|(id, _)| id.into_inner().0)
|
||||||
.collect::<hashbrown::HashSet<_>>();
|
.collect::<hashbrown::HashSet<_>>();
|
||||||
let mut all = serai_validators;
|
let mut all = serai_validators;
|
||||||
for network in NETWORKS {
|
for network in EXTERNAL_NETWORKS {
|
||||||
if network == NetworkId::Serai {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Returning the latest-decided, not latest and active, means the active set
|
// Returning the latest-decided, not latest and active, means the active set
|
||||||
// may fail to peer find if there isn't sufficient overlap. If a large amount reboot,
|
// may fail to peer find if there isn't sufficient overlap. If a large amount reboot,
|
||||||
// forcing some validators to successfully peer find in order for the threshold to become
|
// forcing some validators to successfully peer find in order for the threshold to become
|
||||||
@@ -581,7 +579,7 @@ sp_api::impl_runtime_apis! {
|
|||||||
//
|
//
|
||||||
// This is assumed not to matter in real life, yet an interesting note.
|
// This is assumed not to matter in real life, yet an interesting note.
|
||||||
let participants =
|
let participants =
|
||||||
ValidatorSets::participants_for_latest_decided_set(network)
|
ValidatorSets::participants_for_latest_decided_set(NetworkId::from(network))
|
||||||
.map_or(vec![], BoundedVec::into_inner);
|
.map_or(vec![], BoundedVec::into_inner);
|
||||||
for (participant, _) in participants {
|
for (participant, _) in participants {
|
||||||
all.insert(participant.0);
|
all.insert(participant.0);
|
||||||
|
|||||||
@@ -171,6 +171,7 @@ pub mod pallet {
|
|||||||
///
|
///
|
||||||
/// This will still include participants which were removed from the DKG.
|
/// This will still include participants which were removed from the DKG.
|
||||||
pub fn in_set(network: NetworkId, account: Public) -> bool {
|
pub fn in_set(network: NetworkId, account: Public) -> bool {
|
||||||
|
// TODO: should InSet only work for `ExternalNetworkId`?
|
||||||
if InSet::<T>::contains_key(network, account) {
|
if InSet::<T>::contains_key(network, account) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -743,6 +744,9 @@ pub mod pallet {
|
|||||||
// Serai doesn't set keys and network slashes are handled by BABE/GRANDPA
|
// Serai doesn't set keys and network slashes are handled by BABE/GRANDPA
|
||||||
if let NetworkId::External(n) = set.network {
|
if let NetworkId::External(n) = set.network {
|
||||||
// If the prior prior set didn't report, emit they're retired now
|
// If the prior prior set didn't report, emit they're retired now
|
||||||
|
// TODO: we will emit the events 1 session late if there was no call to report_slashes.
|
||||||
|
// Also report_slashes calls must be made after the set publishes its first batch for this
|
||||||
|
// flow to work as expected.
|
||||||
if PendingSlashReport::<T>::get(n).is_some() {
|
if PendingSlashReport::<T>::get(n).is_some() {
|
||||||
Self::deposit_event(Event::SetRetired {
|
Self::deposit_event(Event::SetRetired {
|
||||||
set: ValidatorSet { network: set.network, session: Session(set.session.0 - 1) },
|
set: ValidatorSet { network: set.network, session: Session(set.session.0 - 1) },
|
||||||
@@ -754,6 +758,9 @@ pub mod pallet {
|
|||||||
let keys =
|
let keys =
|
||||||
Keys::<T>::take(ExternalValidatorSet { network: n, session: set.session }).unwrap();
|
Keys::<T>::take(ExternalValidatorSet { network: n, session: set.session }).unwrap();
|
||||||
PendingSlashReport::<T>::set(n, Some(keys.0));
|
PendingSlashReport::<T>::set(n, Some(keys.0));
|
||||||
|
} else {
|
||||||
|
// emit the event for serai network
|
||||||
|
Self::deposit_event(Event::SetRetired { set });
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're retiring this set because the set after it accepted the handover
|
// We're retiring this set because the set after it accepted the handover
|
||||||
|
|||||||
Reference in New Issue
Block a user