Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/eth-rollup-develop' into feature…
Browse files Browse the repository at this point in the history
…/stable-pool-mgx-1307
  • Loading branch information
vanderian committed Nov 18, 2024
2 parents 771e1e4 + 8536917 commit 3d2cef0
Show file tree
Hide file tree
Showing 28 changed files with 2,708 additions and 327 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/reusable-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ jobs:
fast: true
- command: "yarn test-rolldown"
fast: true
- command: "yarn test-rolldownWithdrawal"
fast: true
- command: "yarn test-rolldownPreOperationWithdrawal"
fast: true
- command: "yarn test-sequencerRewards"
fast: true




runs-on: [e2e-gke]
Expand Down
263 changes: 132 additions & 131 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pallets/bootstrap/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl pallet_xyk::Config for Test {
type DisabledTokens = Nothing;
type VestingProvider = Vesting;
type AssetMetadataMutation = AssetMetadataMutation;
type FeeLockWeight = ();
}

impl pallet_proof_of_stake::Config for Test {
Expand Down
86 changes: 86 additions & 0 deletions pallets/fee-lock/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,90 @@ const MGA_TOKEN_ID: u32 = 0;

benchmarks! {

process_fee_lock{

let caller: T::AccountId = whitelisted_caller();
let period_length: BlockNumberFor<T> = 10u32.into();
let fee_lock_amount: BalanceOf<T> = 1000_u32.into();
let queue_position = 10u128;
let token_id = MGA_TOKEN_ID.into();
<frame_system::Pallet<T>>::set_block_number(1u32.into());
let now= <frame_system::Pallet<T>>::block_number();
let mint_amount: BalanceOf<T> = 1_000_000u32.into();
let swap_value_threshold: BalanceOf<T> = 1000_u32.into();

// This should be a while loop
// But this is fine here since token_id is 0
if <T as Config>::Tokens::get_next_currency_id() > token_id {
assert_ok!(<T as Config>::Tokens::mint(token_id, &caller.clone(), mint_amount));
} else {
assert_eq!(<T as Config>::Tokens::create(&caller.clone(), mint_amount).unwrap(), token_id);
}

assert_ok!(FeeLock::<T>::update_fee_lock_metadata(RawOrigin::Root.into(), Some(period_length), Some(fee_lock_amount), Some(swap_value_threshold), None));

FeeLockMetadataQeueuePosition::<T>::insert(caller.clone(), queue_position);
UnlockQueue::<T>::insert(queue_position, caller.clone());


let initial_user_free_balance = <T as Config>::Tokens::free_balance(token_id, &caller.clone());
let initial_user_reserved_balance = <T as Config>::Tokens::reserved_balance(token_id, &caller.clone());
let initial_user_locked_balance = <T as Config>::Tokens::locked_balance(token_id, &caller.clone());

assert_eq!(FeeLock::<T>::get_account_fee_lock_data(caller.clone()), AccountFeeLockDataInfo{
total_fee_lock_amount: Default::default(),
last_fee_lock_block: Default::default(),
});

} : {FeeLock::<T>::process_fee_lock(&caller)}
verify{

assert_eq!(<T as Config>::Tokens::free_balance(token_id, &caller.clone()),
initial_user_free_balance - fee_lock_amount);
assert_eq!(<T as Config>::Tokens::reserved_balance(token_id, &caller.clone()),
initial_user_reserved_balance + fee_lock_amount);
assert_eq!(<T as Config>::Tokens::locked_balance(token_id, &caller.clone()),
initial_user_locked_balance);

assert_eq!(FeeLock::<T>::get_account_fee_lock_data(caller.clone()), AccountFeeLockDataInfo{
total_fee_lock_amount: fee_lock_amount,
last_fee_lock_block: now,
});
}

get_swap_valuation_for_token {

let caller: T::AccountId = whitelisted_caller();
let mint_amount: BalanceOf<T> = 1_000_000u32.into();
let pool_amount: BalanceOf<T> = 100_000u32.into();
let token_id = MGA_TOKEN_ID.into();

// This should be a while loop
// But this is fine here since token_id is 0
if <T as Config>::Tokens::get_next_currency_id() > token_id {
assert_ok!(<T as Config>::Tokens::mint(token_id, &caller.clone(), mint_amount));
} else {
assert_eq!(<T as Config>::Tokens::create(&caller.clone(), mint_amount).unwrap(), token_id);
}

let valuating_token_amount: BalanceOf<T> = 1000_u32.into();
let valuating_token_id = <T as Config>::Tokens::create(&caller.clone(), mint_amount)?;

// Order of tokens in the create_pool call below is important
#[cfg(not(test))]
assert_ok!(<T as Config>::PoolReservesProvider::create_pool(caller, valuating_token_id, pool_amount, token_id, pool_amount.saturating_mul(2u8.into())));

// We want to avoid having the value being 1000, since that is what get_swap_valuation_for_token returns if the valuating_token_id is the native token id
#[cfg(test)]
let value: BalanceOf<T> = 500_u32.into();
#[cfg(not(test))]
let value: BalanceOf<T> = 2000_u32.into();
let mut valuation: Option<BalanceOf<T>> = None;
}: {valuation = FeeLock::<T>::get_swap_valuation_for_token(valuating_token_id, valuating_token_amount);}
verify{
assert_eq!(valuation, Some(value));
}

update_fee_lock_metadata{
let period_length: BlockNumberFor<T> = 1000u32.into();
let fee_lock_amount: BalanceOf<T> = 1000_u32.into();
Expand All @@ -58,6 +142,8 @@ benchmarks! {
let now= <frame_system::Pallet<T>>::block_number();
let token_id = MGA_TOKEN_ID.into();

// This should be a while loop
// But this is fine here since token_id is 0
if <T as Config>::Tokens::get_next_currency_id() > token_id {
assert_ok!(<T as Config>::Tokens::mint(token_id, &caller.clone(), 1_000_000u32.into()));
} else {
Expand Down
18 changes: 17 additions & 1 deletion pallets/fee-lock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use frame_support::{
transactional,
};
use frame_system::{ensure_signed, pallet_prelude::*};
use mangata_support::traits::{FeeLockTriggerTrait, Valuate};
use mangata_support::traits::{FeeLockTriggerTrait, Valuate, XykFunctionsTrait};
use orml_tokens::{MultiTokenCurrencyExtended, MultiTokenReservableCurrency};
use sp_arithmetic::per_things::Rounding;
use sp_runtime::helpers_128bit::multiply_by_rational_with_rounding;
Expand Down Expand Up @@ -225,7 +225,11 @@ pub mod pallet {
type MaxCuratedTokens: Get<u32>;
type Tokens: MultiTokenCurrencyExtended<Self::AccountId>
+ MultiTokenReservableCurrency<Self::AccountId>;
#[cfg(not(all(feature = "runtime-benchmarks", not(test))))]
type PoolReservesProvider: Valuate<BalanceOf<Self>, CurrencyIdOf<Self>>;
#[cfg(all(feature = "runtime-benchmarks", not(test)))]
type PoolReservesProvider: Valuate<BalanceOf<Self>, CurrencyIdOf<Self>>
+ XykFunctionsTrait<Self::AccountId, BalanceOf<Self>, CurrencyIdOf<Self>>;
#[pallet::constant]
type NativeTokenId: Get<CurrencyIdOf<Self>>;
type WeightInfo: WeightInfo;
Expand Down Expand Up @@ -553,3 +557,15 @@ impl<T: Config> FeeLockTriggerTrait<T::AccountId, BalanceOf<T>, CurrencyIdOf<T>>
Ok(())
}
}

pub struct FeeLockWeightProvider<T>(PhantomData<T>);

impl<T: Config> Get<Weight> for FeeLockWeightProvider<T> {
fn get() -> Weight {
// We assume that process_fee_lock is heavier than unlock_fee
// The FeeLockMetadata read is not accounted for since it is called no matter the extrinsic and hence would be accounted for in the ExtrinsicBaseWeight
T::WeightInfo::process_fee_lock()
.saturating_add(T::WeightInfo::get_swap_valuation_for_token())
.saturating_add(Weight::from_parts(40_000_000, 0))
}
}
61 changes: 49 additions & 12 deletions pallets/fee-lock/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Autogenerated weights for pallet_token_timeout
//! Autogenerated weights for pallet_fee_lock
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-09-01, STEPS: `2`, REPEAT: 2, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-11-07, STEPS: `2`, REPEAT: 2, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("rollup-local"), DB CACHE: 1024
// Executed Command:
// /home/striker/work/mangata-ws/mangata-node/scripts/..//target/release/mangata-node
// /home/striker/work/mangata-ws/mangata-node/scripts/..//target/release/rollup-node
// benchmark
// pallet
// --chain
// dev
// rollup-local
// --execution
// wasm
// --wasm-execution
// compiled
// --pallet
// pallet_token_timeout
// pallet_fee_lock
// --extrinsic
// *
// --steps
// 2
// --repeat
// 2
// --output
// ./benchmarks/pallet_token_timeout_weights.rs
// ./benchmarks/pallet_fee_lock_weights.rs
// --template
// ./templates/module-weight-template.hbs

Expand All @@ -55,20 +55,57 @@ use sp_std::marker::PhantomData;

/// Weight functions needed for pallet_fee_lock.
pub trait WeightInfo {
fn process_fee_lock() -> Weight;
fn get_swap_valuation_for_token() -> Weight;
fn update_fee_lock_metadata() -> Weight;
fn unlock_fee() -> Weight;
}

// For backwards compatibility and tests
impl WeightInfo for () {
// Storage: `FeeLock::FeeLockMetadata` (r:1 w:0)
// Proof: `FeeLock::FeeLockMetadata` (`max_values`: Some(1), `max_size`: Some(438), added: 933, mode: `MaxEncodedLen`)
// Storage: `FeeLock::AccountFeeLockData` (r:1 w:1)
// Proof: `FeeLock::AccountFeeLockData` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
// Storage: `Tokens::Accounts` (r:1 w:1)
// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(96), added: 2571, mode: `MaxEncodedLen`)
// Storage: `FeeLock::FeeLockMetadataQeueuePosition` (r:1 w:1)
// Proof: `FeeLock::FeeLockMetadataQeueuePosition` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`)
// Storage: `FeeLock::UnlockQueue` (r:1 w:2)
// Proof: `FeeLock::UnlockQueue` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`)
// Storage: `FeeLock::UnlockQueueEnd` (r:1 w:1)
// Proof: `FeeLock::UnlockQueueEnd` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`)
fn process_fee_lock() -> Weight {
(Weight::from_parts(39_182_000, 0))
.saturating_add(RocksDbWeight::get().reads(6 as u64))
.saturating_add(RocksDbWeight::get().writes(6 as u64))
}
// Storage: `Xyk::Pools` (r:2 w:0)
// Proof: `Xyk::Pools` (`max_values`: None, `max_size`: Some(56), added: 2531, mode: `MaxEncodedLen`)
fn get_swap_valuation_for_token() -> Weight {
(Weight::from_parts(10_686_000, 0))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
}
// Storage: `FeeLock::FeeLockMetadata` (r:1 w:1)
// Proof: `FeeLock::FeeLockMetadata` (`max_values`: Some(1), `max_size`: Some(438), added: 933, mode: `MaxEncodedLen`)
fn update_fee_lock_metadata() -> Weight {
(Weight::from_parts(44_245_000, 0))
(Weight::from_parts(22_559_000, 0))
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: `FeeLock::AccountFeeLockData` (r:1 w:1)
// Proof: `FeeLock::AccountFeeLockData` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
// Storage: `FeeLock::FeeLockMetadata` (r:1 w:0)
// Proof: `FeeLock::FeeLockMetadata` (`max_values`: Some(1), `max_size`: Some(438), added: 933, mode: `MaxEncodedLen`)
// Storage: `Tokens::Accounts` (r:1 w:1)
// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(96), added: 2571, mode: `MaxEncodedLen`)
// Storage: `FeeLock::FeeLockMetadataQeueuePosition` (r:1 w:1)
// Proof: `FeeLock::FeeLockMetadataQeueuePosition` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`)
// Storage: `FeeLock::UnlockQueue` (r:1 w:1)
// Proof: `FeeLock::UnlockQueue` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`)
fn unlock_fee() -> Weight {
(Weight::from_parts(50_286_000, 0))
.saturating_add(RocksDbWeight::get().reads(3 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
(Weight::from_parts(39_182_000, 0))
.saturating_add(RocksDbWeight::get().reads(5 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
}
16 changes: 0 additions & 16 deletions pallets/parachain-staking/src/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
// Copyright 2019-2021 PureStake Inc.
// This file is part of Moonbeam.

// Moonbeam is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Moonbeam is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

#![cfg(feature = "runtime-benchmarks")]

//! Benchmarking
Expand Down
1 change: 1 addition & 0 deletions pallets/proof-of-stake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ impl pallet_xyk::Config for Test {
type DisabledTokens = Nothing;
type VestingProvider = Vesting;
type AssetMetadataMutation = AssetMetadataMutation;
type FeeLockWeight = ();
}

#[cfg(not(feature = "runtime-benchmarks"))]
Expand Down
5 changes: 4 additions & 1 deletion pallets/rolldown/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ sp-crypto-hashing = { workspace = true, default-features = false }

orml-tokens = { workspace = true, default-features = false }

pallet-sequencer-staking = { path = "../sequencer-staking", default-features = false }

[dev-dependencies]
env_logger.workspace = true
lazy_static.workspace = true
Expand Down Expand Up @@ -62,8 +64,9 @@ std = [
"sp-std/std",
"sp-core/std",
"sp-runtime/std",
"pallet-sequencer-staking/std",
]

runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks", "pallet-sequencer-staking/runtime-benchmarks"]

try-runtime = ["frame-support/try-runtime", "frame-system/try-runtime", "orml-tokens/try-runtime", "sp-runtime/try-runtime"]
Loading

0 comments on commit 3d2cef0

Please sign in to comment.