diff --git a/Cargo.lock b/Cargo.lock index ad9a6e456d..ca6321d9a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4434,7 +4434,7 @@ dependencies = [ [[package]] name = "framenode" -version = "2.0.0" +version = "2.1.0" dependencies = [ "ansi_term", "assert_cmd", @@ -4534,7 +4534,7 @@ dependencies = [ [[package]] name = "framenode-chain-spec" -version = "2.0.0" +version = "2.1.0" dependencies = [ "common", "faucet", @@ -4564,7 +4564,7 @@ dependencies = [ [[package]] name = "framenode-runtime" -version = "2.0.0" +version = "2.1.0" dependencies = [ "assets", "assets-runtime-api", @@ -4681,7 +4681,6 @@ dependencies = [ "sp-consensus-babe", "sp-core", "sp-inherents", - "sp-keyring", "sp-mmr-primitives", "sp-npos-elections", "sp-offchain", diff --git a/node/Cargo.toml b/node/Cargo.toml index 391051fcde..67824ef58d 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "framenode" -version = "2.0.0" +version = "2.1.0" authors = ["Parity Technologies "] build = "build.rs" edition = "2021" diff --git a/node/chain_spec/Cargo.toml b/node/chain_spec/Cargo.toml index 4eb244fb50..1fcd4d23c8 100644 --- a/node/chain_spec/Cargo.toml +++ b/node/chain_spec/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "framenode-chain-spec" -version = "2.0.0" +version = "2.1.0" authors = ["Parity Technologies "] edition = "2021" diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index e93bede9a4..710aeae107 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -5,7 +5,7 @@ license = "BSD-4-Clause" homepage = "https://sora.org" repository = "https://github.com/sora-xor/sora2-network" name = "framenode-runtime" -version = "2.0.0" +version = "2.1.0" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -170,7 +170,6 @@ env_logger = "0.9.0" framenode-chain-spec = { path = "../node/chain_spec", features = ["test"] } tokio = { version = "1.19.2", features = ["macros"] } sp-tracing = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" } -sp-keyring = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" } frame-remote-externalities = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" } [features] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 692fc6f1be..2dbfab3588 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -62,10 +62,9 @@ use crate::impls::{ use bridge_types::{evm::AdditionalEVMInboundData, types::LeafExtraData, U256}; use common::prelude::constants::{BIG_FEE, SMALL_FEE}; use common::prelude::QuoteAmount; -#[cfg(feature = "wip")] -use common::AssetId32; -use common::{Description, GetMarketInfo, LiquidityProxyTrait, PredefinedAssetId}; -use common::{XOR, XST, XSTUSD}; +use common::PredefinedAssetId; +use common::XOR; +use common::{Description, XSTUSD}; use constants::currency::deposit; use constants::time::*; #[cfg(feature = "wip")] // order-book @@ -259,10 +258,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("sora-substrate"), impl_name: create_runtime_str!("sora-substrate"), authoring_version: 1, - spec_version: 60, + spec_version: 63, impl_version: 1, apis: RUNTIME_API_VERSIONS, - transaction_version: 60, + transaction_version: 63, state_version: 0, }; diff --git a/runtime/src/migrations.rs b/runtime/src/migrations.rs index 14fb6787f3..4e560a9c69 100644 --- a/runtime/src/migrations.rs +++ b/runtime/src/migrations.rs @@ -1,69 +1 @@ -use crate::*; -use common::{DEXId, XOR, XST, XSTUSD}; - -pub struct StakingMigrationV11OldPallet; -impl Get<&'static str> for StakingMigrationV11OldPallet { - fn get() -> &'static str { - "BagsList" - } -} -pub struct EmptyAccountList; - -impl Get> for EmptyAccountList { - fn get() -> Vec { - Default::default() - } -} - -pub struct XYKSyntheticPoolPairs(core::marker::PhantomData); - -impl Get> for XYKSyntheticPoolPairs -where - T: assets::Config + common::Config, -{ - fn get() -> Vec<(T::AssetId, T::AssetId, T::DEXId)> { - vec![ - (XSTUSD.into(), XST.into(), DEXId::PolkaswapXSTUSD.into()), - (XSTUSD.into(), XOR.into(), DEXId::PolkaswapXSTUSD.into()), - (XOR.into(), XSTUSD.into(), DEXId::Polkaswap.into()), - ] - } -} - -pub struct XYKSyntheticPoolAccountList(core::marker::PhantomData); - -impl Get> for XYKSyntheticPoolAccountList -where - T: pool_xyk::Config, -{ - fn get() -> Vec<(T::AccountId, T::AccountId)> { - XYKSyntheticPoolPairs::::get() - .iter() - .map(|(base_asset, target_asset, _)| { - pool_xyk::Properties::::get(base_asset, target_asset) - }) - .filter(|v| v.is_some()) - .map(|v| v.unwrap()) - .collect() - } -} -/// List of block numbers binded to pools with synthetic assets in Farming pallet -/// This list contains block numbers for main, staging, and test environments -pub struct FarmingPoolBlocksToInspect; - -impl Get> for FarmingPoolBlocksToInspect { - fn get() -> Vec { - vec![230, 362, 501, 550, 632, 832, 1025] - } -} - -pub type Migrations = ( - farming::migrations::v3::Migrate< - Runtime, - XYKSyntheticPoolAccountList, - FarmingPoolBlocksToInspect, - >, - pswap_distribution::migrations::v2::Migrate>, - pool_xyk::migrations::v3::XYKPoolUpgrade>, - band::migrations::v2::BandUpdateV2, -); +pub type Migrations = (); diff --git a/runtime/src/tests/xor_fee.rs b/runtime/src/tests/xor_fee.rs index 1977b52ade..ee640f72e8 100644 --- a/runtime/src/tests/xor_fee.rs +++ b/runtime/src/tests/xor_fee.rs @@ -31,12 +31,10 @@ use crate::mock::{ensure_pool_initialized, fill_spot_price}; use crate::xor_fee_impls::{CustomFeeDetails, CustomFees}; use crate::{ - AccountId, AssetId, Assets, Balance, Balances, BlockHashCount, Currencies, Executive, - GetXorFeeAccountId, PoolXYK, Referrals, ReferrerWeight, Runtime, RuntimeCall, RuntimeOrigin, - SignedExtra, SignedPayload, Staking, System, Tokens, UncheckedExtrinsic, Weight, - XorBurnedWeight, XorFee, XorIntoValBurnedWeight, + AccountId, AssetId, Assets, Balance, Balances, Currencies, GetXorFeeAccountId, PoolXYK, + Referrals, ReferrerWeight, Runtime, RuntimeCall, RuntimeOrigin, Staking, System, Tokens, + Weight, XorBurnedWeight, XorFee, XorIntoValBurnedWeight, }; -use codec::Encode; use common::mock::{alice, bob, charlie}; use common::prelude::constants::{BIG_FEE, SMALL_FEE}; use common::prelude::{AssetName, AssetSymbol, FixedWrapper, SwapAmount}; @@ -44,26 +42,17 @@ use common::{balance, fixed_wrapper, AssetInfoProvider, FilterMode, VAL, XOR}; use frame_support::assert_ok; use frame_support::dispatch::{DispatchInfo, PostDispatchInfo}; use frame_support::pallet_prelude::{InvalidTransaction, Pays}; -use frame_support::traits::{Currency, OnFinalize, OnInitialize}; +use frame_support::traits::{OnFinalize, OnInitialize}; use frame_support::unsigned::TransactionValidityError; use frame_support::weights::WeightToFee as WeightToFeeTrait; use frame_system::EventRecord; use framenode_chain_spec::ext; use log::LevelFilter; use pallet_balances::NegativeImbalance; -use pallet_staking::{ - Bonded, CurrentEra, EraRewardPoints, ErasRewardPoints, ErasStakersClipped, ErasValidatorPrefs, - ErasValidatorReward, Exposure, IndividualExposure, Ledger, Payee, RewardDestination, - RewardPoint, StakingLedger, ValidatorPrefs, -}; use pallet_transaction_payment::OnChargeTransaction; use referrals::ReferrerBalances; -use sp_core::Pair; -use sp_runtime::generic::Era; -use sp_runtime::traits::{IdentifyAccount, SaturatedConversion, SignedExtension}; -use sp_runtime::{AccountId32, FixedPointNumber, FixedU128, MultiSignature, MultiSigner}; -use sp_staking::EraIndex; -use sp_std::collections::btree_map::BTreeMap; +use sp_runtime::traits::SignedExtension; +use sp_runtime::{AccountId32, FixedPointNumber, FixedU128}; use traits::MultiCurrency; use xor_fee::extension::ChargeTransactionPayment; use xor_fee::{ApplyCustomFees, LiquidityInfo, XorToVal}; @@ -133,108 +122,6 @@ fn set_weight_to_fee_multiplier(mul: u64) { )); } -fn nominator_account(id: u8) -> AccountId { - AccountId::from([id + 100u8; 32]) -} - -fn setup_staking_pallet( - valdiator: AccountId, - nominators: Vec, - mut eras_reward: Vec<(EraIndex, Balance)>, - validator_stake: Balance, - nominator_stake: Balance, - validator_points_per_era: RewardPoint, - nominator_points_per_era: RewardPoint, -) { - eras_reward.sort_by_key(|(era, _)| *era); - - let current_era = eras_reward - .last() - .expect("Expected to get the most recent era") - .0; - CurrentEra::::put(current_era + 1); - - Bonded::::insert(valdiator.clone(), valdiator.clone()); - Ledger::::insert( - valdiator.clone(), - StakingLedger::default_from(valdiator.clone()), - ); - - let individual_exposures: Vec<_> = nominators - .iter() - .cloned() - .map(|who| IndividualExposure { - who, - value: nominator_stake, - }) - .collect(); - - let total = validator_stake + nominator_stake.saturating_mul(nominators.len() as u128); - let exposure = Exposure { - total, - own: validator_stake, - others: individual_exposures, - }; - let rewards_map: BTreeMap = nominators - .into_iter() - .map(|nom| (nom, nominator_points_per_era)) - .chain(vec![(valdiator.clone(), validator_points_per_era)]) - .collect(); - let total_rewards = rewards_map.iter().map(|(_, reward)| reward).sum(); - - for (era, reward) in eras_reward { - ErasValidatorReward::::insert(era, reward); - ErasStakersClipped::::insert(era, valdiator.clone(), exposure.clone()); - ErasValidatorPrefs::::insert(era, valdiator.clone(), ValidatorPrefs::default()); - - // EraRewardPoints does not implement Clone trait - let reward_points_per_era = EraRewardPoints { - total: total_rewards, - individual: rewards_map.clone(), - }; - ErasRewardPoints::::insert(era, reward_points_per_era); - } - - Payee::::insert(valdiator, RewardDestination::Controller); -} - -fn dispatch_and_process_call(runtime_call: RuntimeCall) { - let pair = sp_keyring::AccountKeyring::Bob.pair(); - let bob_public = MultiSigner::from(pair.public().clone()); - let bob_account = bob_public.clone().into_account(); - - let period = BlockHashCount::get() as u64; - let current_block = System::block_number() - .saturated_into::() - .saturating_sub(1); - - let nonce = System::account(&bob_account).nonce; - - let extra: SignedExtra = ( - frame_system::CheckSpecVersion::::new(), - frame_system::CheckTxVersion::::new(), - frame_system::CheckGenesis::::new(), - frame_system::CheckEra::::from(Era::mortal(period, current_block)), - frame_system::CheckNonce::::from(nonce), - frame_system::CheckWeight::::new(), - ChargeTransactionPayment::::new(), - ); - - let raw_payload = SignedPayload::new(runtime_call.clone(), extra.clone()) - .expect("Expected to create a new signed payload"); - - let signature = raw_payload.using_encoded(|payload| pair.sign(payload)); - - let uxt = UncheckedExtrinsic::new_signed( - runtime_call, - bob_account.clone(), - MultiSignature::Sr25519(signature), - extra, - ); - - let _ = Executive::apply_extrinsic(uxt).expect("Expected to apply extrinsic"); -} - #[test] fn referrer_gets_bonus_from_tx_fee() { ext().execute_with(|| { @@ -1030,62 +917,3 @@ fn it_works_eth_bridge_pays_no() { ); }); } - -#[test] -fn withdraw_fee_during_batch_payout_stakers_works() { - ext().execute_with(|| { - let pair = sp_keyring::AccountKeyring::Bob.pair(); - let bob_account = MultiSigner::from(pair.public()).into_account(); - System::set_block_number(1); - Balances::make_free_balance_be(&bob_account, balance!(100)); - let total_reward = balance!(10); - - let nominators = (0..3).into_iter().map(|id| nominator_account(id)).collect(); - - let eras_reward = (0..50u32) - .into_iter() - .map(|era| (era, total_reward)) - .collect(); - - let validator_stake = balance!(1000); - let nominator_stake = balance!(100); - - let validator_points_per_era = 1000; - let nominator_points_per_era = 100; - - setup_staking_pallet( - alice(), - nominators, - eras_reward, - validator_stake, - nominator_stake, - validator_points_per_era, - nominator_points_per_era, - ); - - let runtime_call = RuntimeCall::Utility(pallet_utility::Call::batch_all { - calls: vec![RuntimeCall::Staking(pallet_staking::Call::payout_stakers { - validator_stash: alice(), - era: 1, - })], - }); - - // simulation of first inherent extrinsic - // without it there would be no ApplyExtrinsic phase in events for the next call - dispatch_and_process_call(RuntimeCall::System(frame_system::Call::remark { - remark: b"a".to_vec(), - })); - - let bob_balance = Balances::free_balance(&bob_account); - - dispatch_and_process_call(runtime_call.clone()); - assert_eq!(Balances::free_balance(&bob_account), bob_balance); - - // invalid duplicate call - dispatch_and_process_call(runtime_call); - assert_eq!( - Balances::free_balance(&bob_account), - bob_balance.saturating_sub(balance!(0.7)) - ); - }); -} diff --git a/runtime/src/xor_fee_impls.rs b/runtime/src/xor_fee_impls.rs index 772f97095b..380b5244e5 100644 --- a/runtime/src/xor_fee_impls.rs +++ b/runtime/src/xor_fee_impls.rs @@ -1,8 +1,7 @@ -use core::cmp::{Eq, PartialEq}; -use pallet_utility::Call as UtilityCall; -use sp_runtime::DispatchResult; - use crate::*; +use common::LiquidityProxyTrait; +use pallet_utility::Call as UtilityCall; +use sp_runtime::traits::Zero; impl RuntimeCall { pub fn swap_count(&self) -> u32 { @@ -73,8 +72,9 @@ impl CustomFees { swap_batches .iter() .map(|x| x.receivers.len() as Balance) - .sum::() - * SMALL_FEE, + .fold(Balance::zero(), |acc, x| acc.saturating_add(x)) + .saturating_mul(SMALL_FEE) + .max(SMALL_FEE), ), RuntimeCall::Assets(assets::Call::register { .. }) | RuntimeCall::EthBridge(eth_bridge::Call::transfer_to_sidechain { .. }) @@ -105,7 +105,6 @@ impl CustomFees { pub enum CustomFeeDetails { /// Regular call with custom fee without any additional logic Regular(Balance), - PayoutStakers(Balance), } // Flat fees implementation for the selected extrinsics. @@ -115,25 +114,8 @@ impl xor_fee::ApplyCustomFees for CustomFees { type FeeDetails = CustomFeeDetails; fn compute_fee(call: &RuntimeCall) -> Option<(Balance, CustomFeeDetails)> { - let fee = Self::base_fee(call); - if let Some(fee) = fee { - Some((fee, CustomFeeDetails::Regular(fee))) - } else { - match call { - RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) - if calls.iter().all(|call| { - matches!( - call, - RuntimeCall::Staking(pallet_staking::Call::payout_stakers { .. }) - ) - }) => - { - let fee = calls.len() as Balance * SMALL_FEE; - Some((fee, CustomFeeDetails::PayoutStakers(fee))) - } - _ => None, - } - } + let fee = Self::base_fee(call)?; + Some((fee, CustomFeeDetails::Regular(fee))) } fn should_be_postponed( @@ -224,19 +206,12 @@ impl xor_fee::ApplyCustomFees for CustomFees { fn compute_actual_fee( _post_info: &sp_runtime::traits::PostDispatchInfoOf, _info: &sp_runtime::traits::DispatchInfoOf, - result: &DispatchResult, + _result: &sp_runtime::DispatchResult, fee_details: Option, ) -> Option { let fee_details = fee_details?; match fee_details { CustomFeeDetails::Regular(fee) => Some(fee), - CustomFeeDetails::PayoutStakers(fee) => { - if result.is_ok() { - Some(0) - } else { - Some(fee) - } - } } }