git.delta.rocks / unique-network / refs/commits / 95338e20d6df

difftreelog

fix after rebase

Trubnikov Sergey2023-05-22parent: #5d77792.patch.diff
in: master

4 files changed

modifiedpallets/balances-adapter/src/common.rsdiffbeforeafterboth
--- a/pallets/balances-adapter/src/common.rs
+++ b/pallets/balances-adapter/src/common.rs
@@ -45,7 +45,7 @@
 	}
 
 	fn transfer() -> Weight {
-		<BalancesWeight<T> as WeightInfo>::transfer()
+		<BalancesWeight<T> as WeightInfo>::transfer_allow_death()
 	}
 
 	fn approve() -> Weight {
@@ -57,7 +57,7 @@
 	}
 
 	fn transfer_from() -> Weight {
-		<BalancesWeight<T> as WeightInfo>::transfer()
+		<BalancesWeight<T> as WeightInfo>::transfer_allow_death()
 	}
 
 	fn burn_from() -> Weight {
modifiedpallets/balances-adapter/src/erc.rsdiffbeforeafterboth
--- a/pallets/balances-adapter/src/erc.rs
+++ b/pallets/balances-adapter/src/erc.rs
@@ -54,7 +54,7 @@
 		Ok(total.into())
 	}
 
-	#[weight(<SelfWeightOf<T>>::transfer())]
+	#[weight(<SelfWeightOf<T>>::transfer_allow_death())]
 	fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let to = T::CrossAccountId::from_eth(to);
@@ -68,7 +68,7 @@
 		Ok(true)
 	}
 
-	#[weight(<SelfWeightOf<T>>::transfer())]
+	#[weight(<SelfWeightOf<T>>::transfer_allow_death())]
 	fn transfer_from(
 		&mut self,
 		caller: Caller,
@@ -102,7 +102,7 @@
 		Ok(balance.into())
 	}
 
-	#[weight(<SelfWeightOf<T>>::transfer())]
+	#[weight(<SelfWeightOf<T>>::transfer_allow_death())]
 	fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let to = to.into_sub_cross_account::<T>()?;
@@ -117,7 +117,7 @@
 		Ok(true)
 	}
 
-	#[weight(<SelfWeightOf<T>>::transfer())]
+	#[weight(<SelfWeightOf<T>>::transfer_allow_death())]
 	fn transfer_from_cross(
 		&mut self,
 		caller: Caller,
modifiedpallets/balances-adapter/src/lib.rsdiffbeforeafterboth
before · pallets/balances-adapter/src/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]23extern crate alloc;4use core::ops::Deref;56use frame_support::sp_runtime::DispatchResult;7use pallet_evm_coder_substrate::{WithRecorder, SubstrateRecorder};8pub use pallet::*;910pub mod common;11pub mod erc;1213pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;1415/// Handle for native fungible collection16pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);17impl<T: Config> NativeFungibleHandle<T> {18	/// Creates a handle19	pub fn new() -> NativeFungibleHandle<T> {20		Self(SubstrateRecorder::new(u64::MAX))21	}2223	/// Creates a handle24	pub fn new_with_gas_limit(gas_limit: u64) -> NativeFungibleHandle<T> {25		Self(SubstrateRecorder::new(gas_limit))26	}2728	/// Check if the collection is internal29	pub fn check_is_internal(&self) -> DispatchResult {30		Ok(())31	}32}3334impl<T: Config> WithRecorder<T> for NativeFungibleHandle<T> {35	fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {36		&self.037	}38	fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {39		self.040	}41}4243impl<T: Config> Deref for NativeFungibleHandle<T> {44	type Target = SubstrateRecorder<T>;4546	fn deref(&self) -> &Self::Target {47		&self.048	}49}50#[frame_support::pallet]51pub mod pallet {52	use super::*;53	use alloc::string::String;54	use frame_support::{55		dispatch::PostDispatchInfo,56		ensure,57		pallet_prelude::{DispatchResultWithPostInfo, Pays},58		traits::{Currency, ExistenceRequirement, Get},59	};60	use pallet_balances::WeightInfo;61	use pallet_common::{erc::CrossAccountId, Error as CommonError, Pallet as PalletCommon};62	use pallet_structure::Pallet as PalletStructure;63	use sp_core::U256;64	use sp_runtime::DispatchError;65	use up_data_structs::{budget::Budget, mapping::TokenAddressMapping};6667	#[pallet::config]68	pub trait Config:69		frame_system::Config70		+ pallet_evm_coder_substrate::Config71		+ pallet_common::Config72		+ pallet_structure::Config73	{74		/// Currency from `pallet_balances`75		type Currency: frame_support::traits::Currency<76			Self::AccountId,77			Balance = Self::CurrencyBalance,78		>;79		/// Balance type of chain80		type CurrencyBalance: Into<U256> + TryFrom<U256> + TryFrom<u128> + Into<u128>;8182		/// Decimals of balance83		type Decimals: Get<u8>;84		/// Collection name85		type Name: Get<String>;86		/// Collection symbol87		type Symbol: Get<String>;8889		/// Weight information90		type WeightInfo: WeightInfo;91	}92	#[pallet::pallet]93	pub struct Pallet<T>(_);9495	impl<T: Config> Pallet<T> {96		/// Checks if a non-owner has (enough) allowance from the owner to perform operations on the tokens.97		/// Returns the expected remaining allowance - it should be set manually if the transaction proceeds.98		///99		/// - `spender`: CrossAccountId who has the allowance rights.100		/// - `from`: The owner of the tokens who sets the allowance.101		/// - `nesting_budget`: Limit for searching parents in-depth to check ownership.102		fn check_allowed(103			spender: &T::CrossAccountId,104			from: &T::CrossAccountId,105			nesting_budget: &dyn Budget,106		) -> Result<u128, DispatchError> {107			if let Some((collection_id, token_id)) =108				T::CrossTokenAddressMapping::address_to_token(from)109			{110				ensure!(111					<PalletStructure<T>>::check_indirectly_owned(112						spender.clone(),113						collection_id,114						token_id,115						None,116						nesting_budget117					)?,118					<CommonError<T>>::ApprovedValueTooLow,119				);120			} else if !spender.conv_eq(from) {121				return Ok(0);122			}123124			Ok(<T as Config>::Currency::free_balance(from.as_sub()).into())125		}126127		/// Transfers the specified amount of tokens. Will check that128		/// the transfer is allowed for the token.129		///130		/// - `collection`: Collection that contains the token.131		/// - `from`: Owner of tokens to transfer.132		/// - `to`: Recepient of transfered tokens.133		/// - `amount`: Amount of tokens to transfer.134		/// - `nesting_budget`: Limit for searching parents in-depth to check ownership.135		pub fn transfer(136			_collection: &NativeFungibleHandle<T>,137			from: &T::CrossAccountId,138			to: &T::CrossAccountId,139			amount: u128,140			_nesting_budget: &dyn Budget,141		) -> DispatchResultWithPostInfo {142			<PalletCommon<T>>::ensure_correct_receiver(to)?;143144			if from != to && amount != 0 {145				<T as Config>::Currency::transfer(146					from.as_sub(),147					to.as_sub(),148					amount149						.try_into()150						.map_err(|_| sp_runtime::ArithmeticError::Overflow)?,151					ExistenceRequirement::AllowDeath,152				)?;153			};154155			Ok(PostDispatchInfo {156				actual_weight: Some(<SelfWeightOf<T>>::transfer()),157				pays_fee: Pays::Yes,158			})159		}160161		/// Transfer NFT token from one account to another.162		///163		/// Same as the [`Self::transfer`] but spender doesn't needs to be the owner of the token.164		/// The owner should set allowance for the spender to transfer token.165		///166		/// - `collection`: Collection that contains the token.167		/// - `spender`: Account that spend the money.168		/// - `from`: Owner of tokens to transfer.169		/// - `to`: Recepient of transfered tokens.170		/// - `amount`: Amount of tokens to transfer.171		/// - `nesting_budget`: Limit for searching parents in-depth to check ownership.172		pub fn transfer_from(173			collection: &NativeFungibleHandle<T>,174			spender: &T::CrossAccountId,175			from: &T::CrossAccountId,176			to: &T::CrossAccountId,177			amount: u128,178			nesting_budget: &dyn Budget,179		) -> DispatchResultWithPostInfo {180			let allowance = Self::check_allowed(spender, from, nesting_budget)?;181			if allowance < amount {182				return Err(<CommonError<T>>::ApprovedValueTooLow.into());183			}184			Self::transfer(collection, from, to, amount, nesting_budget)185		}186	}187}
modifiedruntime/common/config/pallets/app_promotion.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/app_promotion.rs
+++ b/runtime/common/config/pallets/app_promotion.rs
@@ -31,6 +31,7 @@
 	pub const RecalculationInterval: BlockNumber = RELAY_DAYS;
 	pub const PendingInterval: BlockNumber = 7 * DAYS;
 	pub const Nominal: Balance = UNIQUE;
+	pub const HoldAndFreezeIdentifier: [u8; 16] = *b"appstakeappstake";
 	pub IntervalIncome: Perbill = Perbill::from_rational(5u32, 10_000);
 }
 
@@ -47,4 +48,5 @@
 	type Nominal = Nominal;
 	type IntervalIncome = IntervalIncome;
 	type RuntimeEvent = RuntimeEvent;
+	type FreezeIdentifier = HoldAndFreezeIdentifier;
 }