Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Upgrade zrml-neo-swaps
  • Loading branch information
sea212 committed Apr 21, 2024
commit 3ece979942e23ac07ce39b160aa0f54babe11d70
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions zrml/neo-swaps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
hydra-dx-math = { workspace = true }
log = { workspace = true }
orml-traits = { workspace = true }
parity-scale-codec = { workspace = true, features = ["derive", "max-encoded-len"] }
scale-info = { workspace = true, features = ["derive"] }
Expand Down
6 changes: 4 additions & 2 deletions zrml/neo-swaps/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ use frame_support::{
};
use frame_system::RawOrigin;
use orml_traits::MultiCurrency;
use sp_runtime::{traits::Get, Perbill, SaturatedConversion};
use sp_runtime::{
traits::{Get, Zero},
Perbill, SaturatedConversion,
};
use zeitgeist_primitives::{
constants::{base_multiples::*, CENT},
math::fixed::{BaseProvider, FixedDiv, FixedMul, ZeitgeistBase},
Expand Down Expand Up @@ -472,7 +475,6 @@ mod benchmarks {

// Mock up some fees. Needs to be large enough to ensure that Bob's share is not smaller
// than the existential deposit.
let pool = Pools::<T>::get(market_id).unwrap();
let max_node_count = LiquidityTreeOf::<T>::max_node_count() as u128;
let fee_amount = (max_node_count * _10).saturated_into();
deposit_fees::<T>(market_id, fee_amount);
Expand Down
12 changes: 7 additions & 5 deletions zrml/neo-swaps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ mod pallet {
pallet_prelude::StorageMap,
require_transactional,
traits::{Get, IsType, StorageVersion},
transactional, PalletError, PalletId, RuntimeDebug, Twox64Concat,
transactional, PalletError, PalletId, Twox64Concat,
};
use frame_system::{
ensure_signed,
pallet_prelude::{BlockNumberFor, OriginFor},
};
use frame_system::{ensure_signed, pallet_prelude::OriginFor};
use orml_traits::MultiCurrency;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{AccountIdConversion, CheckedSub, Saturating, Zero},
DispatchError, DispatchResult, Perbill, SaturatedConversion,
DispatchError, DispatchResult, Perbill, RuntimeDebug, SaturatedConversion,
};
use zeitgeist_primitives::{
constants::{BASE, CENT},
Expand Down Expand Up @@ -120,7 +123,7 @@ mod pallet {
MarketId = MarketIdOf<Self>,
>;

type MarketCommons: MarketCommonsPalletApi<AccountId = Self::AccountId, BlockNumber = Self::BlockNumber>;
type MarketCommons: MarketCommonsPalletApi<AccountId = Self::AccountId, BlockNumber = BlockNumberFor<Self>>;

type MultiCurrency: MultiCurrency<Self::AccountId, CurrencyId = AssetOf<Self>>;

Expand All @@ -142,7 +145,6 @@ mod pallet {

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::storage]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ where
op: UpdateDescendantStakeOperation,
) -> DispatchResult;

/// Mutate each child of the node at `index` using `mutator`.
fn mutate_each_child<F>(&mut self, index: u32, mutator: F) -> DispatchResult
where
F: FnMut(&mut Self::Node) -> DispatchResult;

/// Return the number of nodes in the tree. Note that abandoned nodes are counted.
fn node_count(&self) -> u32;

Expand Down
12 changes: 0 additions & 12 deletions zrml/neo-swaps/src/liquidity_tree/types/liquidity_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,6 @@ where
Ok(())
}

fn mutate_each_child<F>(&mut self, index: u32, mut mutator: F) -> DispatchResult
where
F: FnMut(&mut Self::Node) -> DispatchResult,
{
let child_indices = self.children(index)?;
child_indices.apply(|index| {
self.mutate_node(index, |node| mutator(node))?;
Ok(())
})?;
Ok(())
}

fn node_count(&self) -> u32 {
self.nodes.len() as u32
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

use sp_runtime::DispatchError;

/// Structure for managing children in a liquidity tree.
pub(crate) struct LiquidityTreeChildIndices {
/// Left-hand side child; `None` if there's no left-hand side child (the node is either empty or
Expand All @@ -27,22 +25,6 @@ pub(crate) struct LiquidityTreeChildIndices {
pub(crate) rhs: Option<u32>,
}

impl LiquidityTreeChildIndices {
/// Applies a `mutator` function to each child if it exists.
pub fn apply<F>(&self, mut mutator: F) -> Result<(), DispatchError>
where
F: FnMut(u32) -> Result<(), DispatchError>,
{
if let Some(lhs) = self.lhs {
mutator(lhs)?;
}
if let Some(rhs) = self.rhs {
mutator(rhs)?;
}
Ok(())
}
}

// Implement `From` for destructuring
impl From<LiquidityTreeChildIndices> for (Option<u32>, Option<u32>) {
fn from(child_indices: LiquidityTreeChildIndices) -> (Option<u32>, Option<u32>) {
Expand Down
20 changes: 10 additions & 10 deletions zrml/neo-swaps/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ use crate::{
use alloc::collections::BTreeMap;
use core::marker::PhantomData;
use frame_support::{
dispatch::Weight,
log,
traits::{Get, OnRuntimeUpgrade, StorageVersion},
RuntimeDebug,
weights::Weight,
};
use log;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::Saturating;
use sp_runtime::{RuntimeDebug, Saturating};

cfg_if::cfg_if! {
if #[cfg(feature = "try-runtime")] {
use crate::{MarketIdOf};
use alloc::{format, vec::Vec};
use frame_support::{migration::storage_key_iter, pallet_prelude::Twox64Concat};
use sp_runtime::DispatchError;
}
}

Expand Down Expand Up @@ -111,15 +111,15 @@ where
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
let old_pools =
storage_key_iter::<MarketIdOf<T>, OldPoolOf<T>, Twox64Concat>(NEO_SWAPS, POOLS)
.collect::<BTreeMap<_, _>>();
Ok(old_pools.encode())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(previous_state: Vec<u8>) -> Result<(), &'static str> {
fn post_upgrade(previous_state: Vec<u8>) -> Result<(), DispatchError> {
let old_pools: BTreeMap<MarketIdOf<T>, OldPoolOf<T>> =
Decode::decode(&mut &previous_state[..])
.map_err(|_| "Failed to decode state: Invalid state")?;
Expand Down Expand Up @@ -152,11 +152,11 @@ mod tests {
MarketIdOf, PoolOf, Pools,
};
use alloc::collections::BTreeMap;
use frame_support::{
dispatch::fmt::Debug, migration::put_storage_value, storage_root, StateVersion,
StorageHasher, Twox64Concat,
};
use core::fmt::Debug;
use frame_support::{migration::put_storage_value, StorageHasher, Twox64Concat};
use parity_scale_codec::Encode;
use sp_io::storage::root as storage_root;
use sp_runtime::StateVersion;
use zeitgeist_primitives::types::Asset;

#[test]
Expand Down
Loading