diff --git a/NODE.md b/NODE.md index fce9de68..0a0585e8 100644 --- a/NODE.md +++ b/NODE.md @@ -150,7 +150,7 @@ installed locally. #### Downloading the docker image ```sh -docker pull bitcountry/continuum-collator-node:latest +docker pull bitcountry/continuum-collator-node:b2d0ea7 ``` #### Running the docker image diff --git a/modules/bridge/src/lib.rs b/modules/bridge/src/lib.rs index 616c801e..7be8894e 100644 --- a/modules/bridge/src/lib.rs +++ b/modules/bridge/src/lib.rs @@ -194,16 +194,15 @@ pub mod pallet { ensure!(BridgeFee::::contains_key(&chain_id), Error::::FeeOptionsMissing); let (min_fee, fee_scale) = Self::bridge_fee(chain_id); - let fee_estimated = amount.saturating_mul(fee_scale.into()); + let fee_estimated = currency_id.1 * amount; let fee = if fee_estimated > min_fee { fee_estimated } else { min_fee }; - let mut actual_fee = Zero::zero(); + let mut actual_fee = fee; if currency_id.0 == FungibleTokenId::NativeToken(0) { - actual_fee = fee; T::Currency::transfer( &source, &bridge_id, @@ -211,8 +210,6 @@ pub mod pallet { ExistenceRequirement::AllowDeath, )?; } else { - actual_fee = currency_id.1 * fee; - // Transfer the fee as native token first T::Currency::transfer(&source, &bridge_id, actual_fee.into(), ExistenceRequirement::AllowDeath)?; // Handle the multi currency token transfer diff --git a/pallets/auction/src/lib.rs b/pallets/auction/src/lib.rs index 8620862f..58b7cc44 100644 --- a/pallets/auction/src/lib.rs +++ b/pallets/auction/src/lib.rs @@ -27,7 +27,7 @@ use frame_support::traits::{Currency, ExistenceRequirement, LockableCurrency, ReservableCurrency}; use frame_support::{ensure, pallet_prelude::*, transactional}; -use frame_system::{self as system, ensure_signed, pallet_prelude::BlockNumberFor}; +use frame_system::{self as system, ensure_signed}; use sp_core::sp_std::convert::TryInto; use sp_runtime::SaturatedConversion; use sp_runtime::{ @@ -100,6 +100,7 @@ pub mod migration_v2 { #[frame_support::pallet] pub mod pallet { use frame_support::dispatch::DispatchResultWithPostInfo; + use frame_support::log; use frame_support::sp_runtime::traits::CheckedSub; use frame_system::pallet_prelude::OriginFor; use orml_traits::{MultiCurrency, MultiReservableCurrency}; @@ -799,9 +800,9 @@ pub mod pallet { } #[pallet::hooks] - impl Hooks> for Pallet { + impl Hooks for Pallet { /// Hooks that call every new block is initialized. - fn on_initialize(now: BlockNumberFor) -> Weight { + fn on_initialize(now: T::BlockNumber) -> Weight { let mut total_item = 0; for (auction_id, _) in >::drain_prefix(&now) { total_item += 1; @@ -813,19 +814,19 @@ pub mod pallet { T::WeightInfo::on_finalize().saturating_mul(total_item) } - fn on_runtime_upgrade() -> Weight { - Self::upgrade_auction_item_data_v3(); - Weight::from_parts(0, 0) - } + // fn on_runtime_upgrade() -> Weight { + // Self::upgrade_auction_item_data_v3(); + // Weight::from_(0u64) + // } } - impl Auction> for Pallet { + impl Auction for Pallet { type Balance = BalanceOf; /// Internal update auction extension fn update_auction( id: AuctionId, - info: AuctionInfo>, + info: AuctionInfo, ) -> DispatchResult { let auction = >::get(id).ok_or(Error::::AuctionDoesNotExist)?; if let Some(old_end) = auction.end { @@ -843,10 +844,10 @@ pub mod pallet { fn new_auction( _recipient: T::AccountId, _initial_amount: Self::Balance, - start: BlockNumberFor, - end: Option>, + start: T::BlockNumber, + end: Option, ) -> Result { - let auction: AuctionInfo> = + let auction: AuctionInfo = AuctionInfo { bid: None, start, end }; let auction_id: AuctionId = AuctionsIndex::::try_mutate(|n| -> Result { @@ -869,10 +870,10 @@ pub mod pallet { fn create_auction( auction_type: AuctionType, item_id: ItemId, - _end: Option>, + _end: Option, recipient: T::AccountId, initial_amount: Self::Balance, - _start: BlockNumberFor, + _start: T::BlockNumber, listing_level: ListingLevel, listing_fee: Perbill, currency_id: FungibleTokenId, @@ -1184,7 +1185,7 @@ pub mod pallet { /// Internal auction bid handler fn auction_bid_handler(from: T::AccountId, id: AuctionId, value: Self::Balance) -> DispatchResult { - let auction_item: AuctionItem, BalanceOf> = + let auction_item: AuctionItem> = Self::get_auction_item(id.clone()).ok_or(Error::::AuctionDoesNotExist)?; ensure!( auction_item.auction_type == AuctionType::Auction, @@ -1267,7 +1268,7 @@ pub mod pallet { /// Internal auction bid handler for local marketplace fn local_auction_bid_handler( - _now: BlockNumberFor, + _now: T::BlockNumber, id: AuctionId, new_bid: (T::AccountId, Self::Balance), last_bid: Option<(T::AccountId, Self::Balance)>, @@ -1319,12 +1320,12 @@ pub mod pallet { } /// Internal get auction info - fn auction_info(id: AuctionId) -> Option>> { + fn auction_info(id: AuctionId) -> Option> { Self::auctions(id) } /// Internal get auction info - fn auction_item(id: AuctionId) -> Option, Self::Balance>> { + fn auction_item(id: AuctionId) -> Option> { Self::get_auction_item(id) } @@ -1388,7 +1389,7 @@ pub mod pallet { let block_number = >::block_number(); ensure!(block_number >= auction.start, Error::::AuctionHasNotStarted); if !(auction.end.is_none()) { - let auction_end: BlockNumberFor = auction.end.ok_or(Error::::AuctionIsExpired)?; + let auction_end: T::BlockNumber = auction.end.ok_or(Error::::AuctionIsExpired)?; ensure!(block_number < auction_end, Error::::AuctionIsExpired); } @@ -1576,13 +1577,13 @@ pub mod pallet { } } - impl AuctionHandler, BlockNumberFor, AuctionId> for Pallet { + impl AuctionHandler, T::BlockNumber, AuctionId> for Pallet { fn on_new_bid( - _now: BlockNumberFor, + _now: T::BlockNumber, _id: AuctionId, _new_bid: (T::AccountId, BalanceOf), _last_bid: Option<(T::AccountId, BalanceOf)>, - ) -> OnNewBidResult> { + ) -> OnNewBidResult { OnNewBidResult { accept_bid: true, auction_end_change: Change::NoChange, @@ -1786,7 +1787,7 @@ pub mod pallet { } impl Pallet { - fn check_valid_finality(end: &BlockNumberFor, quantity: u32) -> bool { + fn check_valid_finality(end: &T::BlockNumber, quantity: u32) -> bool { let existing_auctions_same_block: u32 = >::iter_prefix_values(end).count() as u32; let total_auction_in_same_block = existing_auctions_same_block.saturating_add(quantity); @@ -1855,9 +1856,9 @@ pub mod pallet { let mut num_auction_items = 0; AuctionItems::::translate( - |_k, auction_v2: AuctionItemV2, BalanceOf>| { + |_k, auction_v2: AuctionItemV2>| { num_auction_items += 1; - let v3: AuctionItem, BalanceOf> = AuctionItem { + let v3: AuctionItem> = AuctionItem { item_id: auction_v2.item_id, recipient: auction_v2.recipient, initial_amount: auction_v2.initial_amount, @@ -1874,7 +1875,7 @@ pub mod pallet { ); log::info!("{} auction items upgraded:", num_auction_items); - Weight::from_parts(0, 0) + Weight::from_ref_time(0) } pub fn swap_new_bid( @@ -1938,7 +1939,7 @@ pub mod pallet { }) } - fn extend_auction_end_time(id: AuctionId, new_end_block: BlockNumberFor) -> DispatchResult { + fn extend_auction_end_time(id: AuctionId, new_end_block: T::BlockNumber) -> DispatchResult { >::try_mutate_exists(id, |auction_item| -> DispatchResult { let mut auction_item = auction_item.as_mut().ok_or(Error::::AuctionDoesNotExist)?; auction_item.end_time = new_end_block; diff --git a/pallets/crowdloan/src/lib.rs b/pallets/crowdloan/src/lib.rs index eec9d0f8..b6dda0fa 100644 --- a/pallets/crowdloan/src/lib.rs +++ b/pallets/crowdloan/src/lib.rs @@ -131,11 +131,6 @@ pub mod pallet { let who = ensure_signed(origin.clone())?; ensure!(Self::is_accepted_origin(&who), Error::::NoPermission); - let target = T::Lookup::lookup(to.clone())?; - // Get existing vesting schedule - let vesting_info = T::VestingSchedule::vesting_balance(&target); - // Ensure user doesn't have any vested reward - ensure!(vesting_info == None, Error::::UserAlreadyGotExistingVestingInfo); VestingModule::::vested_transfer(origin, to, schedule)?; diff --git a/pallets/economy/src/lib.rs b/pallets/economy/src/lib.rs index 1ff33ffd..626e7389 100644 --- a/pallets/economy/src/lib.rs +++ b/pallets/economy/src/lib.rs @@ -601,10 +601,9 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_. /// - /// `amount`: the unstake amount /// - /// Emit `UnstakedInnovation` event if successful - #[pallet::weight(T::WeightInfo::stake_a())] + /// Emit `ClaimRewards` event if successful + #[pallet::weight(T::WeightInfo::claim_reward())] #[transactional] pub fn claim_reward(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; diff --git a/pallets/economy/src/mock.rs b/pallets/economy/src/mock.rs index 1eec0f8a..ad25c1fa 100644 --- a/pallets/economy/src/mock.rs +++ b/pallets/economy/src/mock.rs @@ -496,13 +496,14 @@ impl ExtBuilder { .unwrap(); pallet_balances::GenesisConfig:: { - balances: vec![(ALICE, 10000)], - } - .assimilate_storage(&mut t) - .unwrap(); - - pallet_balances::GenesisConfig:: { - balances: vec![(BOB, 20000)], + balances: vec![ + (ALICE, 10000), + (BOB, 20000), + ( + ::RewardPayoutAccount::get().into_account_truncating(), + 30000, + ), + ], } .assimilate_storage(&mut t) .unwrap(); @@ -525,6 +526,7 @@ pub fn run_to_block(n: u64) { System::set_block_number(System::block_number() + 1); System::on_initialize(System::block_number()); Mining::on_initialize(System::block_number()); + EconomyModule::on_initialize(System::block_number()); } } diff --git a/pallets/economy/src/tests.rs b/pallets/economy/src/tests.rs index 21410ef5..9100d852 100644 --- a/pallets/economy/src/tests.rs +++ b/pallets/economy/src/tests.rs @@ -19,7 +19,7 @@ use frame_support::{assert_noop, assert_ok}; -use sp_runtime::traits::BadOrigin; +use sp_runtime::traits::{AccountIdConversion, BadOrigin}; use sp_std::default::Default; use core_primitives::{Attributes, CollectionType, TokenType}; @@ -607,3 +607,200 @@ fn unstake_on_innovation_should_work() { ); }); } + +#[test] +fn claim_reward_should_work() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(EconomyModule::stake_on_innovation( + RuntimeOrigin::signed(account(1)), + STAKE_BALANCE, + )); + + /// Account share of pool reward should be == STAKE_BALANCE + let acc_1_shared_rewards = EconomyModule::shares_and_withdrawn_rewards(account(1)); + assert_eq!(acc_1_shared_rewards, (STAKE_BALANCE, Default::default())); + assert_eq!(EconomyModule::get_innovation_staking_info(account(1)), STAKE_BALANCE); + assert_eq!(EconomyModule::total_innovation_staking(), STAKE_BALANCE); + + let reward_amount = 100u128; + let mut reward_map: BTreeMap = BTreeMap::new(); + reward_map.insert(FungibleTokenId::NativeToken(0), reward_amount.clone()); + + PendingRewardsOfStakingInnovation::::insert(account(1), reward_map.clone()); + + run_to_block(2); + + assert_ok!(EconomyModule::claim_reward(RuntimeOrigin::signed(account(1)))); + + assert_eq!( + last_event(), + RuntimeEvent::Economy(crate::Event::ClaimRewards( + account(1), + FungibleTokenId::NativeToken(0), + reward_amount + )) + ); + + assert_eq!(EconomyModule::get_innovation_staking_info(account(1)), STAKE_BALANCE); + assert_eq!(EconomyModule::total_innovation_staking(), STAKE_BALANCE); + assert_eq!( + Balances::free_balance( + &::RewardPayoutAccount::get().into_account_truncating() + ), + 29900u128 + ); + assert_eq!(Balances::free_balance(account(1)), 9100u128); + }); +} + +#[test] +fn claim_reward_with_multiple_stakers_should_work() { + ExtBuilder::default().build().execute_with(|| { + let account_2_stake_balance = STAKE_BALANCE / 4; + let account_1_stake_balance = STAKE_BALANCE - account_2_stake_balance; + + assert_ok!(EconomyModule::stake_on_innovation( + RuntimeOrigin::signed(account(1)), + account_1_stake_balance, + )); + assert_ok!(EconomyModule::stake_on_innovation( + RuntimeOrigin::signed(account(2)), + account_2_stake_balance, + )); + + let acc_1_shared_rewards = EconomyModule::shares_and_withdrawn_rewards(account(1)); + assert_eq!(acc_1_shared_rewards, (account_1_stake_balance, Default::default())); + assert_eq!( + EconomyModule::get_innovation_staking_info(account(1)), + account_1_stake_balance + ); + let acc_2_shared_rewards = EconomyModule::shares_and_withdrawn_rewards(account(2)); + assert_eq!(acc_2_shared_rewards, (account_2_stake_balance, Default::default())); + assert_eq!( + EconomyModule::get_innovation_staking_info(account(2)), + account_2_stake_balance + ); + assert_eq!(EconomyModule::total_innovation_staking(), STAKE_BALANCE); + + EstimatedStakingRewardPerEra::::set(2000u128); + UpdateEraFrequency::::set(1u64); + + run_to_block(2); + + assert_ok!(EconomyModule::claim_reward(RuntimeOrigin::signed(account(1)))); + + assert_eq!( + last_event(), + RuntimeEvent::Economy(crate::Event::ClaimRewards( + account(1), + FungibleTokenId::NativeToken(0), + 3000u128 + )) + ); + + assert_eq!( + EconomyModule::get_innovation_staking_info(account(1)), + account_1_stake_balance + ); + assert_eq!(EconomyModule::total_innovation_staking(), STAKE_BALANCE); + assert_eq!( + Balances::free_balance( + &::RewardPayoutAccount::get().into_account_truncating() + ), + 27000u128 + ); + assert_eq!(Balances::free_balance(account(1)), 12250u128); + + assert_ok!(EconomyModule::claim_reward(RuntimeOrigin::signed(account(2)))); + + assert_eq!( + last_event(), + RuntimeEvent::Economy(crate::Event::ClaimRewards( + account(2), + FungibleTokenId::NativeToken(0), + 1000u128 + )) + ); + + assert_eq!( + EconomyModule::get_innovation_staking_info(account(2)), + account_2_stake_balance + ); + assert_eq!( + Balances::free_balance( + &::RewardPayoutAccount::get().into_account_truncating() + ), + 26000u128 + ); + assert_eq!(Balances::free_balance(account(2)), 20750u128); + }); +} + +#[test] +fn claim_reward_twice_should_not_update_balance_twice() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(EconomyModule::stake_on_innovation( + RuntimeOrigin::signed(account(1)), + STAKE_BALANCE, + )); + + EstimatedStakingRewardPerEra::::set(100u128); + UpdateEraFrequency::::set(3u64); + + run_to_block(4); + + assert_ok!(EconomyModule::claim_reward(RuntimeOrigin::signed(account(1)))); + + assert_eq!( + last_event(), + RuntimeEvent::Economy(crate::Event::ClaimRewards( + account(1), + FungibleTokenId::NativeToken(0), + 100u128 + )) + ); + + assert_ok!(EconomyModule::claim_reward(RuntimeOrigin::signed(account(1)))); + + assert_eq!( + Balances::free_balance( + &::RewardPayoutAccount::get().into_account_truncating() + ), + 29900u128 + ); + assert_eq!(Balances::free_balance(account(1)), 9100u128); + }); +} + +#[test] +fn claim_reward_after_unstaking_should_not_update_balance() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(EconomyModule::stake_on_innovation( + RuntimeOrigin::signed(account(1)), + STAKE_BALANCE, + )); + + EstimatedStakingRewardPerEra::::set(100u128); + UpdateEraFrequency::::set(4u64); + + run_to_block(4); + assert_ok!(EconomyModule::claim_reward(RuntimeOrigin::signed(account(1)))); + + assert_ok!(EconomyModule::unstake_on_innovation( + RuntimeOrigin::signed(account(1)), + STAKE_BALANCE, + )); + + run_to_block(500); + + assert_ok!(EconomyModule::claim_reward(RuntimeOrigin::signed(account(1)))); + + assert_eq!( + Balances::free_balance( + &::RewardPayoutAccount::get().into_account_truncating() + ), + 29900u128 + ); + assert_eq!(Balances::free_balance(account(1)), 9100u128); + }); +} diff --git a/pallets/economy/src/weights.rs b/pallets/economy/src/weights.rs index 72e0f8fa..4b5178d5 100644 --- a/pallets/economy/src/weights.rs +++ b/pallets/economy/src/weights.rs @@ -47,92 +47,223 @@ use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; /// Weight functions needed for economy. -pub trait WeightInfo { fn stake_a() -> Weight; fn stake_b() -> Weight; fn stake_on_innovation() -> Weight; fn unstake_a() -> Weight; fn unstake_b() -> Weight; fn unstake_new_estate_owner() -> Weight; fn unstake_on_innovation() -> Weight; fn withdraw_unreserved() -> Weight;} +pub trait WeightInfo { fn stake_a() -> Weight; fn stake_b() -> Weight; fn stake_on_innovation() -> Weight; fn unstake_a() -> Weight; fn unstake_b() -> Weight; fn unstake_new_estate_owner() -> Weight; fn unstake_on_innovation() -> Weight; fn withdraw_unreserved() -> Weight; fn claim_reward() -> Weight;} /// Weights for economy using the for collator node and recommended hardware. pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { +impl WeightInfo for SubstrateWeight { // Storage: Mining Round (r:1 w:0) + // Proof Skipped: Mining Round (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy ExitQueue (r:1 w:0) + // Proof Skipped: Economy ExitQueue (max_values: None, max_size: None, mode: Measured) + // Storage: Economy StakingInfo (r:1 w:1) + // Proof Skipped: Economy StakingInfo (max_values: None, max_size: None, mode: Measured) + // Storage: Economy TotalStake (r:1 w:1) + // Proof Skipped: Economy TotalStake (max_values: Some(1), max_size: None, mode: Measured) fn stake_a() -> Weight { - Weight::from_parts(52_209_000, 4929) + // Proof Size summary in bytes: + // Measured: `1464` + // Estimated: `4929` + // Minimum execution time: 55_773 nanoseconds. + Weight::from_parts(59_140_000, 4929) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) } + // Storage: Mining Round (r:1 w:0) + // Proof Skipped: Mining Round (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy EstateExitQueue (r:1 w:0) + // Proof Skipped: Economy EstateExitQueue (max_values: None, max_size: None, mode: Measured) + // Storage: Estate Estates (r:1 w:0) + // Proof Skipped: Estate Estates (max_values: None, max_size: None, mode: Measured) + // Storage: Estate EstateOwner (r:1 w:0) + // Proof Skipped: Estate EstateOwner (max_values: None, max_size: None, mode: Measured) + // Storage: OrmlNFT Tokens (r:1 w:0) + // Proof Skipped: OrmlNFT Tokens (max_values: None, max_size: None, mode: Measured) + // Storage: Economy EstateStakingInfo (r:1 w:1) + // Proof Skipped: Economy EstateStakingInfo (max_values: None, max_size: None, mode: Measured) + // Storage: Economy TotalEstateStake (r:1 w:1) + // Proof Skipped: Economy TotalEstateStake (max_values: Some(1), max_size: None, mode: Measured) fn stake_b() -> Weight { - Weight::from_parts(71_491_000, 5545) + // Proof Size summary in bytes: + // Measured: `2080` + // Estimated: `5545` + // Minimum execution time: 91_979 nanoseconds. + Weight::from_parts(117_686_000, 5545) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(2)) } + // Storage: Mining Round (r:1 w:0) + // Proof Skipped: Mining Round (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy InnovationStakingExitQueue (r:1 w:0) + // Proof Skipped: Economy InnovationStakingExitQueue (max_values: None, max_size: None, mode: Measured) + // Storage: Economy InnovationStakingInfo (r:1 w:1) + // Proof Skipped: Economy InnovationStakingInfo (max_values: None, max_size: None, mode: Measured) + // Storage: Economy TotalInnovationStaking (r:1 w:1) + // Proof Skipped: Economy TotalInnovationStaking (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy StakingRewardPoolInfo (r:1 w:1) + // Proof Skipped: Economy StakingRewardPoolInfo (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy SharesAndWithdrawnRewards (r:1 w:1) + // Proof Skipped: Economy SharesAndWithdrawnRewards (max_values: None, max_size: None, mode: Measured) fn stake_on_innovation() -> Weight { - Weight::from_parts(56_832_000, 4929) + // Proof Size summary in bytes: + // Measured: `1464` + // Estimated: `4929` + // Minimum execution time: 59_485 nanoseconds. + Weight::from_parts(60_979_000, 4929) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(4)) } + // Storage: Economy StakingInfo (r:1 w:1) + // Proof Skipped: Economy StakingInfo (max_values: None, max_size: None, mode: Measured) + // Storage: Mining Round (r:1 w:0) + // Proof Skipped: Mining Round (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy ExitQueue (r:1 w:1) + // Proof Skipped: Economy ExitQueue (max_values: None, max_size: None, mode: Measured) + // Storage: Economy TotalStake (r:1 w:1) + // Proof Skipped: Economy TotalStake (max_values: Some(1), max_size: None, mode: Measured) fn unstake_a() -> Weight { - Weight::from_parts(32_069_000, 4698) + // Proof Size summary in bytes: + // Measured: `1233` + // Estimated: `4698` + // Minimum execution time: 34_666 nanoseconds. + Weight::from_parts(36_213_000, 4698) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) } + // Storage: Estate Estates (r:1 w:0) + // Proof Skipped: Estate Estates (max_values: None, max_size: None, mode: Measured) + // Storage: Economy EstateStakingInfo (r:1 w:1) + // Proof Skipped: Economy EstateStakingInfo (max_values: None, max_size: None, mode: Measured) + // Storage: Mining Round (r:1 w:0) + // Proof Skipped: Mining Round (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy EstateExitQueue (r:1 w:1) + // Proof Skipped: Economy EstateExitQueue (max_values: None, max_size: None, mode: Measured) + // Storage: Economy TotalEstateStake (r:1 w:1) + // Proof Skipped: Economy TotalEstateStake (max_values: Some(1), max_size: None, mode: Measured) fn unstake_b() -> Weight { - Weight::from_parts(47_341_000, 4921) + // Proof Size summary in bytes: + // Measured: `1456` + // Estimated: `4921` + // Minimum execution time: 64_725 nanoseconds. + Weight::from_parts(91_945_000, 4921) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(3)) } + // Storage: Estate Estates (r:1 w:0) + // Proof Skipped: Estate Estates (max_values: None, max_size: None, mode: Measured) + // Storage: Estate EstateOwner (r:1 w:0) + // Proof Skipped: Estate EstateOwner (max_values: None, max_size: None, mode: Measured) + // Storage: OrmlNFT Tokens (r:1 w:0) + // Proof Skipped: OrmlNFT Tokens (max_values: None, max_size: None, mode: Measured) + // Storage: Economy EstateStakingInfo (r:1 w:1) + // Proof Skipped: Economy EstateStakingInfo (max_values: None, max_size: None, mode: Measured) + // Storage: Mining Round (r:1 w:0) + // Proof Skipped: Mining Round (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy TotalEstateStake (r:1 w:1) + // Proof Skipped: Economy TotalEstateStake (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy EstateExitQueue (r:0 w:1) + // Proof Skipped: Economy EstateExitQueue (max_values: None, max_size: None, mode: Measured) fn unstake_new_estate_owner() -> Weight { - Weight::from_parts(53_229_000, 5314) + // Proof Size summary in bytes: + // Measured: `1849` + // Estimated: `5314` + // Minimum execution time: 59_124 nanoseconds. + Weight::from_parts(72_456_000, 5314) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) } + // Storage: Economy InnovationStakingInfo (r:1 w:1) + // Proof Skipped: Economy InnovationStakingInfo (max_values: None, max_size: None, mode: Measured) + // Storage: Mining Round (r:1 w:0) + // Proof Skipped: Mining Round (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy InnovationStakingExitQueue (r:1 w:1) + // Proof Skipped: Economy InnovationStakingExitQueue (max_values: None, max_size: None, mode: Measured) + // Storage: Economy TotalInnovationStaking (r:1 w:1) + // Proof Skipped: Economy TotalInnovationStaking (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy SharesAndWithdrawnRewards (r:1 w:1) + // Proof Skipped: Economy SharesAndWithdrawnRewards (max_values: None, max_size: None, mode: Measured) + // Storage: Economy StakingRewardPoolInfo (r:1 w:1) + // Proof Skipped: Economy StakingRewardPoolInfo (max_values: Some(1), max_size: None, mode: Measured) fn unstake_on_innovation() -> Weight { - Weight::from_parts(46_719_000, 4811) + // Proof Size summary in bytes: + // Measured: `1346` + // Estimated: `4811` + // Minimum execution time: 48_186 nanoseconds. + Weight::from_parts(144_041_000, 4811) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(5)) } + // Storage: Economy ExitQueue (r:1 w:1) + // Proof Skipped: Economy ExitQueue (max_values: None, max_size: None, mode: Measured) fn withdraw_unreserved() -> Weight { - Weight::from_parts(58_043_000, 5001) + // Proof Size summary in bytes: + // Measured: `1536` + // Estimated: `5001` + // Minimum execution time: 49_323 nanoseconds. + Weight::from_parts(82_783_000, 5001) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } + // Storage: Economy SharesAndWithdrawnRewards (r:1 w:1) + // Proof Skipped: Economy SharesAndWithdrawnRewards (max_values: None, max_size: None, mode: Measured) + // Storage: Economy StakingRewardPoolInfo (r:1 w:1) + // Proof Skipped: Economy StakingRewardPoolInfo (max_values: Some(1), max_size: None, mode: Measured) + // Storage: Economy PendingRewardsOfStakingInnovation (r:1 w:1) + // Proof Skipped: Economy PendingRewardsOfStakingInnovation (max_values: None, max_size: None, mode: Measured) + fn claim_reward() -> Weight { + // Proof Size summary in bytes: + // Measured: `945` + // Estimated: `4410` + // Minimum execution time: 21_960 nanoseconds. + Weight::from_parts(25_255_000, 4410) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } } // For backwards compatibility and tests impl WeightInfo for () { fn stake_a() -> Weight { - Weight::from_parts(52_209_000, 4929) + Weight::from_parts(59_140_000, 4929) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(2)) } fn stake_b() -> Weight { - Weight::from_parts(71_491_000, 5545) + Weight::from_parts(117_686_000, 5545) .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(2)) } fn stake_on_innovation() -> Weight { - Weight::from_parts(56_832_000, 4929) + Weight::from_parts(60_979_000, 4929) .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(4)) } fn unstake_a() -> Weight { - Weight::from_parts(32_069_000, 4698) + Weight::from_parts(36_213_000, 4698) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(3)) } fn unstake_b() -> Weight { - Weight::from_parts(47_341_000, 4921) + Weight::from_parts(91_945_000, 4921) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(3)) } fn unstake_new_estate_owner() -> Weight { - Weight::from_parts(53_229_000, 5314) + Weight::from_parts(72_456_000, 5314) .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(3)) } fn unstake_on_innovation() -> Weight { - Weight::from_parts(46_719_000, 4811) + Weight::from_parts(144_041_000, 4811) .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(5)) } fn withdraw_unreserved() -> Weight { - Weight::from_parts(58_043_000, 5001) + Weight::from_parts(82_783_000, 5001) .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().writes(1)) } + fn claim_reward() -> Weight { + Weight::from_parts(25_255_000, 4410) + .saturating_add(RocksDbWeight::get().reads(3)) + .saturating_add(RocksDbWeight::get().writes(3)) + } } diff --git a/pallets/nft/src/tests.rs b/pallets/nft/src/tests.rs index 66e8fd01..5edf3628 100644 --- a/pallets/nft/src/tests.rs +++ b/pallets/nft/src/tests.rs @@ -996,7 +996,7 @@ fn validate_signature() { only_account: None, mint_price: None, token_id: None, - expired: 100u64, + expired: 1000u64, }; let encoded_data = Encode::encode(&mint_data); let signature = MultiSignature::Sr25519(alice_pair.sign(&encoded_data)); @@ -1026,7 +1026,7 @@ fn pre_signed_mints_should_work() { only_account: None, mint_price: None, token_id: None, - expired: 100u64, + expired: 1000u64, }; let message = Encode::encode(&mint_data); let signature = MultiSignature::Sr25519(user_1_pair.sign(&message)); @@ -1063,7 +1063,7 @@ fn pre_signed_mint_should_work_with_only_account() { only_account: Some(account(2)), mint_price: None, token_id: None, - expired: 100u64, + expired: 1000u64, }; let message = Encode::encode(&mint_data); let signature = MultiSignature::Sr25519(user_1_pair.sign(&message)); @@ -1109,7 +1109,7 @@ fn pre_signed_mint_should_collect_fee_with_mint_price() { only_account: None, mint_price: Some(50), token_id: None, - expired: 100u64, + expired: 1000u64, }; let message = Encode::encode(&mint_data); let signature = MultiSignature::Sr25519(user_1_pair.sign(&message)); diff --git a/runtime/continuum/src/lib.rs b/runtime/continuum/src/lib.rs index 4e9f5972..898cdeed 100644 --- a/runtime/continuum/src/lib.rs +++ b/runtime/continuum/src/lib.rs @@ -232,7 +232,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("continuum-runtime"), impl_name: create_runtime_str!("continuum-runtime"), authoring_version: 1, - spec_version: 8, + spec_version: 9, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/runtime/continuum/src/weights/module_economy.rs b/runtime/continuum/src/weights/module_economy.rs index caa0899d..5d07e069 100644 --- a/runtime/continuum/src/weights/module_economy.rs +++ b/runtime/continuum/src/weights/module_economy.rs @@ -12,43 +12,48 @@ pub struct WeightInfo(PhantomData); impl economy::WeightInfo for WeightInfo { fn stake_a() -> Weight { - Weight::from_parts(52_209_000, 4929) + Weight::from_parts(59_140_000, 4929) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) } fn stake_b() -> Weight { - Weight::from_parts(71_491_000, 5545) + Weight::from_parts(117_686_000, 5545) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(2)) } fn stake_on_innovation() -> Weight { - Weight::from_parts(56_832_000, 4929) + Weight::from_parts(60_979_000, 4929) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(4)) } fn unstake_a() -> Weight { - Weight::from_parts(32_069_000, 4698) + Weight::from_parts(36_213_000, 4698) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) } fn unstake_b() -> Weight { - Weight::from_parts(47_341_000, 4921) + Weight::from_parts(91_945_000, 4921) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(3)) } fn unstake_new_estate_owner() -> Weight { - Weight::from_parts(53_229_000, 5314) + Weight::from_parts(72_456_000, 5314) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) } fn unstake_on_innovation() -> Weight { - Weight::from_parts(46_719_000, 4811) + Weight::from_parts(144_041_000, 4811) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(5)) } fn withdraw_unreserved() -> Weight { - Weight::from_parts(58_043_000, 5001) + Weight::from_parts(82_783_000, 5001) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } + fn claim_reward() -> Weight { + Weight::from_parts(25_255_000, 4410) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } } diff --git a/runtime/metaverse/src/benchmarking/economy.rs b/runtime/metaverse/src/benchmarking/economy.rs index ad4da9b5..66d1818c 100644 --- a/runtime/metaverse/src/benchmarking/economy.rs +++ b/runtime/metaverse/src/benchmarking/economy.rs @@ -201,6 +201,20 @@ runtime_benchmarks! { ); } + //claim reward + claim_reward{ + let caller: AccountId = whitelisted_caller(); + let caller_lookup = ::Lookup::unlookup(caller.clone()); + set_balance(CURRENCY_ID, &caller, dollar(1000)); + + let min_stake = MinimumStake::get(); + let stake_amount = min_stake + dollar(100); + + Economy::stake_on_innovation(RawOrigin::Signed(caller.clone()).into(), stake_amount); + + run_to_block(100); + }: _(RawOrigin::Signed(caller.clone())) + } #[cfg(test)] diff --git a/runtime/metaverse/src/weights/module_economy.rs b/runtime/metaverse/src/weights/module_economy.rs index caa0899d..5d07e069 100644 --- a/runtime/metaverse/src/weights/module_economy.rs +++ b/runtime/metaverse/src/weights/module_economy.rs @@ -12,43 +12,48 @@ pub struct WeightInfo(PhantomData); impl economy::WeightInfo for WeightInfo { fn stake_a() -> Weight { - Weight::from_parts(52_209_000, 4929) + Weight::from_parts(59_140_000, 4929) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) } fn stake_b() -> Weight { - Weight::from_parts(71_491_000, 5545) + Weight::from_parts(117_686_000, 5545) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(2)) } fn stake_on_innovation() -> Weight { - Weight::from_parts(56_832_000, 4929) + Weight::from_parts(60_979_000, 4929) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(4)) } fn unstake_a() -> Weight { - Weight::from_parts(32_069_000, 4698) + Weight::from_parts(36_213_000, 4698) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) } fn unstake_b() -> Weight { - Weight::from_parts(47_341_000, 4921) + Weight::from_parts(91_945_000, 4921) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(3)) } fn unstake_new_estate_owner() -> Weight { - Weight::from_parts(53_229_000, 5314) + Weight::from_parts(72_456_000, 5314) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) } fn unstake_on_innovation() -> Weight { - Weight::from_parts(46_719_000, 4811) + Weight::from_parts(144_041_000, 4811) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(5)) } fn withdraw_unreserved() -> Weight { - Weight::from_parts(58_043_000, 5001) + Weight::from_parts(82_783_000, 5001) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } + fn claim_reward() -> Weight { + Weight::from_parts(25_255_000, 4410) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } } diff --git a/runtime/pioneer/src/weights/module_economy.rs b/runtime/pioneer/src/weights/module_economy.rs index caa0899d..5d07e069 100644 --- a/runtime/pioneer/src/weights/module_economy.rs +++ b/runtime/pioneer/src/weights/module_economy.rs @@ -12,43 +12,48 @@ pub struct WeightInfo(PhantomData); impl economy::WeightInfo for WeightInfo { fn stake_a() -> Weight { - Weight::from_parts(52_209_000, 4929) + Weight::from_parts(59_140_000, 4929) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) } fn stake_b() -> Weight { - Weight::from_parts(71_491_000, 5545) + Weight::from_parts(117_686_000, 5545) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(2)) } fn stake_on_innovation() -> Weight { - Weight::from_parts(56_832_000, 4929) + Weight::from_parts(60_979_000, 4929) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(4)) } fn unstake_a() -> Weight { - Weight::from_parts(32_069_000, 4698) + Weight::from_parts(36_213_000, 4698) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) } fn unstake_b() -> Weight { - Weight::from_parts(47_341_000, 4921) + Weight::from_parts(91_945_000, 4921) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(3)) } fn unstake_new_estate_owner() -> Weight { - Weight::from_parts(53_229_000, 5314) + Weight::from_parts(72_456_000, 5314) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) } fn unstake_on_innovation() -> Weight { - Weight::from_parts(46_719_000, 4811) + Weight::from_parts(144_041_000, 4811) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(5)) } fn withdraw_unreserved() -> Weight { - Weight::from_parts(58_043_000, 5001) + Weight::from_parts(82_783_000, 5001) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } + fn claim_reward() -> Weight { + Weight::from_parts(25_255_000, 4410) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } }