diff --git a/pallets/thea-executor/src/lib.rs b/pallets/thea-executor/src/lib.rs index 0fd90c017..f7ee4318e 100644 --- a/pallets/thea-executor/src/lib.rs +++ b/pallets/thea-executor/src/lib.rs @@ -49,7 +49,11 @@ pub mod pallet { use frame_support::{ pallet_prelude::*, sp_runtime::SaturatedConversion, - traits::{fungible::Mutate, fungibles::Inspect, tokens::Preservation}, + traits::{ + fungible::Mutate, + fungibles::Inspect, + tokens::{Fortitude, Precision, Preservation}, + }, transactional, }; use frame_system::pallet_prelude::*; @@ -119,6 +123,8 @@ pub mod pallet { type ExistentialDeposit: Get; /// Para Id type ParaId: Get; + /// Governance Origin + type GovernanceOrigin: EnsureOrigin<::RuntimeOrigin>; /// Type representing the weight of this pallet type WeightInfo: WeightInfo; } @@ -181,6 +187,8 @@ pub mod pallet { TheaKeyUpdated(Network, u32), /// Withdrawal Fee Set (NetworkId, Amount) WithdrawalFeeSet(u8, u128), + /// Native Token Burn event + NativeTokenBurned(T::AccountId, u128), } // Errors inform users that something went wrong. @@ -370,6 +378,30 @@ pub mod pallet { Self::deposit_event(Event::::AssetMetadataSet(metadata)); Ok(()) } + + /// Burn Native tokens of an account + /// + /// # Parameters + /// + /// * `who`: AccountId + /// * `amount`: Amount of native tokens to burn. + #[pallet::call_index(5)] + #[pallet::weight(::WeightInfo::parachain_withdraw(1))] // TODO: Update the weights + pub fn burn_native_tokens( + origin: OriginFor, + who: T::AccountId, + amount: u128, + ) -> DispatchResult { + T::GovernanceOrigin::ensure_origin(origin)?; + let burned_amt = ::Currency::burn_from( + &who, + amount.saturated_into(), + Precision::BestEffort, + Fortitude::Force, + )?; + Self::deposit_event(Event::::NativeTokenBurned(who, burned_amt.saturated_into())); + Ok(()) + } } impl Pallet { diff --git a/pallets/thea-executor/src/mock.rs b/pallets/thea-executor/src/mock.rs index 626c42dfd..1ab960b78 100644 --- a/pallets/thea-executor/src/mock.rs +++ b/pallets/thea-executor/src/mock.rs @@ -206,6 +206,7 @@ impl thea_executor::Config for Test { type MultiAssetIdAdapter = AssetId; type AssetBalanceAdapter = u128; type ExistentialDeposit = ExistentialDeposit; + type GovernanceOrigin = EnsureRoot; } impl frame_system::offchain::SendTransactionTypes for Test diff --git a/pallets/thea-message-handler/src/mock.rs b/pallets/thea-message-handler/src/mock.rs index 6c15b2113..6f8fae181 100644 --- a/pallets/thea-message-handler/src/mock.rs +++ b/pallets/thea-message-handler/src/mock.rs @@ -204,6 +204,7 @@ impl thea_executor::Config for Test { type WeightInfo = thea_executor::weights::WeightInfo; type MultiAssetIdAdapter = AssetId; type AssetBalanceAdapter = u128; + type GovernanceOrigin = EnsureRoot; type ExistentialDeposit = ExistentialDeposit; } diff --git a/pallets/thea/src/aggregator.rs b/pallets/thea/src/aggregator.rs index d68265426..8b950d9ae 100644 --- a/pallets/thea/src/aggregator.rs +++ b/pallets/thea/src/aggregator.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{resolver::Resolver, Config}; +use crate::{resolver::Resolver, Config, OutgoingMessages}; use parity_scale_codec::{alloc::string::ToString, Decode, Encode}; use scale_info::prelude::string::String; use sp_std::{marker::PhantomData, prelude::ToOwned, vec, vec::Vec}; @@ -55,18 +55,7 @@ impl AggregatorClient { match destination { Destination::Solochain => { // Get the outgoing message with nonce: `nonce` for network: `network` - let key = Self::create_solo_outgoing_message_key(nonce, network); - match Self::get_storage_at_latest_finalized_head::( - "solo_outgoing_message", - destination, - key, - ) { - Ok(message) => message, - Err(err) => { - log::error!(target:"thea","Unable to get finalized solo head: {:?}",err); - None - }, - } + >::get(network, nonce) }, Destination::Parachain => { // Get the outgoing message with nonce: `nonce` from network @@ -90,23 +79,6 @@ impl AggregatorClient { } } - /// Returns the encoded key for outgoing message for given nonce - /// # Parameters - /// * `nonce`: Nonce of the outgoing message - /// * `network`: Network of the outgoing message - /// # Returns - /// * `Vec`: Encoded key for outgoing message for given nonce - fn create_solo_outgoing_message_key(nonce: u64, network: Network) -> Vec { - let module_name = sp_io::hashing::twox_128(b"Thea"); - let storage_prefix = sp_io::hashing::twox_128(b"OutgoingMessages"); - let mut key = Vec::new(); - key.append(&mut module_name.to_vec()); - key.append(&mut storage_prefix.to_vec()); - key.append(&mut network.encode()); - key.append(&mut nonce.encode()); - key - } - /// Returns the encoded key for outgoing message for given nonce for parachain /// # Parameters /// * `nonce`: Nonce of the outgoing message diff --git a/pallets/thea/src/mock.rs b/pallets/thea/src/mock.rs index 8f5ee901f..d0d526a91 100644 --- a/pallets/thea/src/mock.rs +++ b/pallets/thea/src/mock.rs @@ -201,6 +201,7 @@ impl thea_executor::Config for Test { type Swap = AssetConversion; type MultiAssetIdAdapter = AssetId; type AssetBalanceAdapter = u128; + type GovernanceOrigin = EnsureRoot; type ExistentialDeposit = ExistentialDeposit; } diff --git a/runtimes/mainnet/src/lib.rs b/runtimes/mainnet/src/lib.rs index bf6c56ec4..3342324df 100644 --- a/runtimes/mainnet/src/lib.rs +++ b/runtimes/mainnet/src/lib.rs @@ -122,7 +122,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 316, + spec_version: 317, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, @@ -1367,6 +1367,7 @@ impl thea_executor::Config for Runtime { type Swap = AssetConversion; type MultiAssetIdAdapter = AssetId; type AssetBalanceAdapter = u128; + type GovernanceOrigin = EnsureRootOrHalfCouncil; type ExistentialDeposit = ExistentialDeposit; }