mirror of
https://github.com/pezkuwichain/pezkuwi-runtime-templates.git
synced 2026-04-30 12:47:57 +00:00
Support paying DOT as a fee (#404)
* generic template implemented * support pay do as a fee * update locks with latest fixes * docs & tests * fix clippy * fix fmt
This commit is contained in:
@@ -29,11 +29,13 @@ frame-system = { workspace = true }
|
||||
frame-system-benchmarking = { workspace = true, optional = true }
|
||||
frame-system-rpc-runtime-api = { workspace = true }
|
||||
frame-try-runtime = { workspace = true, optional = true }
|
||||
pallet-asset-tx-payment = { workspace = true }
|
||||
pallet-assets = { workspace = true }
|
||||
pallet-aura = { workspace = true }
|
||||
pallet-authorship = { workspace = true }
|
||||
pallet-balances = { workspace = true, features = [ "insecure_zero_ed" ] }
|
||||
pallet-conviction-voting = { workspace = true }
|
||||
pallet-membership = { workspace = true }
|
||||
pallet-message-queue = { workspace = true }
|
||||
pallet-multisig = { workspace = true }
|
||||
pallet-preimage = { workspace = true }
|
||||
@@ -100,6 +102,8 @@ pallet-evm-precompile-sha3fips = { workspace = true }
|
||||
pallet-evm-precompile-simple = { workspace = true }
|
||||
|
||||
# ORML
|
||||
orml-oracle = { workspace = true }
|
||||
orml-oracle-runtime-api = { workspace = true }
|
||||
orml-traits = { workspace = true }
|
||||
orml-xcm-support = { workspace = true }
|
||||
orml-xtokens = { workspace = true }
|
||||
@@ -157,8 +161,11 @@ std = [
|
||||
"log/std",
|
||||
"nimbus-primitives/std",
|
||||
"openzeppelin-pallet-abstractions/std",
|
||||
"orml-oracle-runtime-api/std",
|
||||
"orml-oracle/std",
|
||||
"orml-xtokens/std",
|
||||
"pallet-asset-manager/std",
|
||||
"pallet-asset-tx-payment/std",
|
||||
"pallet-assets/std",
|
||||
"pallet-aura/std",
|
||||
"pallet-author-inherent/std",
|
||||
@@ -172,6 +179,7 @@ std = [
|
||||
"pallet-ethereum/std",
|
||||
"pallet-evm-chain-id/std",
|
||||
"pallet-evm/std",
|
||||
"pallet-membership/std",
|
||||
"pallet-message-queue/std",
|
||||
"pallet-multisig/std",
|
||||
"pallet-preimage/std",
|
||||
@@ -228,7 +236,9 @@ runtime-benchmarks = [
|
||||
"frame-system/runtime-benchmarks",
|
||||
"hex-literal",
|
||||
"nimbus-primitives/runtime-benchmarks",
|
||||
"orml-oracle/runtime-benchmarks",
|
||||
"pallet-asset-manager/runtime-benchmarks",
|
||||
"pallet-asset-tx-payment/runtime-benchmarks",
|
||||
"pallet-assets/runtime-benchmarks",
|
||||
"pallet-author-inherent/runtime-benchmarks",
|
||||
"pallet-balances/runtime-benchmarks",
|
||||
@@ -237,6 +247,7 @@ runtime-benchmarks = [
|
||||
"pallet-conviction-voting/runtime-benchmarks",
|
||||
"pallet-ethereum/runtime-benchmarks",
|
||||
"pallet-evm/runtime-benchmarks",
|
||||
"pallet-membership/runtime-benchmarks",
|
||||
"pallet-message-queue/runtime-benchmarks",
|
||||
"pallet-multisig/runtime-benchmarks",
|
||||
"pallet-preimage/runtime-benchmarks",
|
||||
@@ -270,8 +281,10 @@ try-runtime = [
|
||||
"frame-system/try-runtime",
|
||||
"frame-try-runtime/try-runtime",
|
||||
"nimbus-primitives/try-runtime",
|
||||
"orml-oracle/try-runtime",
|
||||
"orml-xtokens/try-runtime",
|
||||
"pallet-asset-manager/try-runtime",
|
||||
"pallet-asset-tx-payment/try-runtime",
|
||||
"pallet-assets/try-runtime",
|
||||
"pallet-aura/try-runtime",
|
||||
"pallet-author-inherent/try-runtime",
|
||||
@@ -284,6 +297,7 @@ try-runtime = [
|
||||
"pallet-erc20-xcm-bridge/try-runtime",
|
||||
"pallet-ethereum/try-runtime",
|
||||
"pallet-evm-chain-id/try-runtime",
|
||||
"pallet-membership/try-runtime",
|
||||
"pallet-message-queue/try-runtime",
|
||||
"pallet-multisig/try-runtime",
|
||||
"pallet-preimage/try-runtime",
|
||||
|
||||
@@ -18,8 +18,8 @@ use frame_support::{
|
||||
dispatch::DispatchClass,
|
||||
parameter_types,
|
||||
traits::{
|
||||
AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, ConstU64, Contains, EitherOf,
|
||||
EitherOfDiverse, Everything, FindAuthor, Nothing, TransformOrigin,
|
||||
fungibles::Credit, AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, ConstU64,
|
||||
Contains, EitherOf, EitherOfDiverse, Everything, FindAuthor, Nothing, TransformOrigin,
|
||||
},
|
||||
weights::{ConstantMultiplier, Weight},
|
||||
};
|
||||
@@ -43,9 +43,13 @@ use openzeppelin_pallet_abstractions::{
|
||||
};
|
||||
#[cfg(feature = "tanssi")]
|
||||
use openzeppelin_pallet_abstractions::{impl_openzeppelin_tanssi, TanssiConfig, TanssiWeight};
|
||||
use pallet_asset_tx_payment::HandleCredit;
|
||||
use pallet_ethereum::PostLogContent;
|
||||
use pallet_evm::{EVMCurrencyAdapter, EnsureAccountId20, IdentityAddressMapping};
|
||||
use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
|
||||
use parachains_common::{
|
||||
impls::AccountIdOf,
|
||||
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
|
||||
};
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
|
||||
#[cfg(not(feature = "tanssi"))]
|
||||
@@ -93,10 +97,10 @@ use crate::{
|
||||
},
|
||||
weights::{BlockExecutionWeight, ExtrinsicBaseWeight},
|
||||
AllPalletsWithSystem, AssetManager, Balances, BaseFee, EVMChainId, Erc20XcmBridge,
|
||||
MessageQueue, OpenZeppelinPrecompiles, OriginCaller, PalletInfo, ParachainInfo,
|
||||
ParachainSystem, PolkadotXcm, Preimage, Referenda, Runtime, RuntimeCall, RuntimeEvent,
|
||||
RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask, Scheduler, System,
|
||||
Timestamp, Treasury, UncheckedExtrinsic, WeightToFee, XcmpQueue,
|
||||
MessageQueue, OpenZeppelinPrecompiles, Oracle, OracleMembership, OriginCaller, PalletInfo,
|
||||
ParachainInfo, ParachainSystem, PolkadotXcm, Preimage, Referenda, Runtime, RuntimeCall,
|
||||
RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask, Scheduler,
|
||||
System, Timestamp, Treasury, UncheckedExtrinsic, WeightToFee, XcmpQueue,
|
||||
};
|
||||
|
||||
// OpenZeppelin runtime wrappers configuration
|
||||
@@ -198,7 +202,28 @@ impl EvmConfig for OpenZeppelinRuntime {
|
||||
type PrecompilesValue = PrecompilesValue;
|
||||
type WithdrawOrigin = EnsureAccountId20;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub RootOperatorAccountId: AccountId = AccountId::from([0xffu8; 20]);
|
||||
}
|
||||
|
||||
pub struct AssetsToBlockAuthor<R, I>(PhantomData<(R, I)>);
|
||||
impl<R, I> HandleCredit<AccountIdOf<R>, pallet_assets::Pallet<R, I>> for AssetsToBlockAuthor<R, I>
|
||||
where
|
||||
I: 'static,
|
||||
R: pallet_authorship::Config + pallet_assets::Config<I>,
|
||||
{
|
||||
fn handle_credit(credit: Credit<AccountIdOf<R>, pallet_assets::Pallet<R, I>>) {
|
||||
use frame_support::traits::fungibles::Balanced;
|
||||
if let Some(author) = pallet_authorship::Pallet::<R>::author() {
|
||||
// In case of error: Will drop the result triggering the `OnDrop` of the imbalance.
|
||||
let _ = pallet_assets::Pallet::<R, I>::resolve(&author, credit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AssetsConfig for OpenZeppelinRuntime {
|
||||
type AccountId = AccountId;
|
||||
type ApprovalDeposit = ConstU128<MILLICENTS>;
|
||||
type AssetAccountDeposit = ConstU128<{ deposit(1, 16) }>;
|
||||
type AssetDeposit = ConstU128<{ 10 * CENTS }>;
|
||||
@@ -206,11 +231,15 @@ impl AssetsConfig for OpenZeppelinRuntime {
|
||||
type AssetRegistrar = AssetRegistrar;
|
||||
type AssetRegistrarMetadata = AssetRegistrarMetadata;
|
||||
type AssetType = AssetType;
|
||||
type AssetsToBlockAuthor = AssetsToBlockAuthor<Runtime, ()>;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkHelper = BenchmarkHelper;
|
||||
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
|
||||
type ForceOrigin = EnsureRoot<AccountId>;
|
||||
type ForeignAssetModifierOrigin = EnsureRoot<AccountId>;
|
||||
type FungiblesToAccount = TreasuryAccount;
|
||||
type RootOperatorAccountId = RootOperatorAccountId;
|
||||
type Timestamp = Timestamp;
|
||||
type WeightToFee = WeightToFee;
|
||||
}
|
||||
#[cfg(feature = "tanssi")]
|
||||
@@ -283,6 +312,77 @@ impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConve
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
mod assets_to_block_author {
|
||||
use frame_support::traits::fungibles::Balanced;
|
||||
use pallet_asset_tx_payment::HandleCredit;
|
||||
use parity_scale_codec::Encode;
|
||||
use sp_runtime::{
|
||||
testing::{Digest, DigestItem},
|
||||
ConsensusEngineId,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
configs::AssetsToBlockAuthor, AccountId, Assets, Balance, Runtime, RuntimeOrigin,
|
||||
};
|
||||
|
||||
pub const MOCK_ENGINE_ID: ConsensusEngineId = [b'M', b'O', b'C', b'K'];
|
||||
#[test]
|
||||
fn handle_credit_works_when_author_exists() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Setup
|
||||
let data = [0u8; 32];
|
||||
let author: AccountId = AccountId::from(data);
|
||||
const ASSET_ID: u128 = 1;
|
||||
const AMOUNT: Balance = 100;
|
||||
|
||||
let mut digest = Digest::default();
|
||||
digest.push(DigestItem::PreRuntime(MOCK_ENGINE_ID, author.encode()));
|
||||
// For unit tests we are updating storage of author in a straightforward way
|
||||
frame_support::storage::unhashed::put(
|
||||
&frame_support::storage::storage_prefix(b"Authorship", b"Author"),
|
||||
&author,
|
||||
);
|
||||
// Create asset and mint initial supply
|
||||
assert!(Assets::force_create(
|
||||
RuntimeOrigin::root(),
|
||||
ASSET_ID.into(),
|
||||
author,
|
||||
true,
|
||||
1
|
||||
)
|
||||
.is_ok());
|
||||
|
||||
// Create credit using issue
|
||||
let credit = Assets::issue(ASSET_ID, AMOUNT);
|
||||
|
||||
// Handle credit
|
||||
AssetsToBlockAuthor::<Runtime, ()>::handle_credit(credit);
|
||||
|
||||
// Verify author received the assets
|
||||
assert_eq!(Assets::balance(ASSET_ID, author), AMOUNT);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handle_credit_drops_when_no_author() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Setup
|
||||
const ASSET_ID: u128 = 1;
|
||||
const AMOUNT: Balance = 100;
|
||||
|
||||
// Create credit using issue
|
||||
let credit = Assets::issue(ASSET_ID, AMOUNT);
|
||||
|
||||
// Handle credit (should not panic)
|
||||
AssetsToBlockAuthor::<Runtime, ()>::handle_credit(credit);
|
||||
});
|
||||
}
|
||||
|
||||
fn new_test_ext() -> sp_io::TestExternalities {
|
||||
use sp_runtime::BuildStorage;
|
||||
frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap().into()
|
||||
}
|
||||
}
|
||||
mod transaction_converter {
|
||||
use core::str::FromStr;
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ impl ConsensusWeight for OpenZeppelinRuntime {
|
||||
impl AssetsWeight for OpenZeppelinRuntime {
|
||||
type AssetManager = weights::pallet_asset_manager::WeightInfo<Runtime>;
|
||||
type Assets = weights::pallet_assets::WeightInfo<Runtime>;
|
||||
// TODO: fix weight
|
||||
type OracleMembership = ();
|
||||
type OrmlOracle = (); // TODO: fix weight
|
||||
}
|
||||
|
||||
impl GovernanceWeight for OpenZeppelinRuntime {
|
||||
|
||||
@@ -40,7 +40,8 @@ use crate::{
|
||||
pub use crate::{
|
||||
configs::RuntimeBlockWeights,
|
||||
types::{
|
||||
AccountId, Balance, Block, BlockNumber, Executive, Nonce, Signature, UncheckedExtrinsic,
|
||||
AccountId, AssetId, Balance, Block, BlockNumber, Executive, Nonce, Signature,
|
||||
UncheckedExtrinsic,
|
||||
},
|
||||
};
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
@@ -50,7 +51,7 @@ use crate::{
|
||||
XcmExecutorConfig,
|
||||
},
|
||||
constants::currency::{CENTS, EXISTENTIAL_DEPOSIT},
|
||||
types::{Address, AssetId},
|
||||
types::Address,
|
||||
};
|
||||
#[cfg(feature = "async-backing")]
|
||||
use crate::{constants::SLOT_DURATION, types::ConsensusHook};
|
||||
@@ -240,6 +241,8 @@ mod apis {
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type TransactionPayment = TransactionPayment;
|
||||
type Balance = Balance;
|
||||
type Oracle = Oracle;
|
||||
type OracleKey = AssetId;
|
||||
}
|
||||
|
||||
mod consensus {
|
||||
@@ -294,6 +297,8 @@ mod apis {
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Executive = Executive;
|
||||
type Ethereum = Ethereum;
|
||||
type Oracle = Oracle;
|
||||
type OracleKey = AssetId;
|
||||
}
|
||||
|
||||
mod assets {
|
||||
|
||||
@@ -83,7 +83,7 @@ pub type SignedExtra = (
|
||||
frame_system::CheckEra<Runtime>,
|
||||
frame_system::CheckNonce<Runtime>,
|
||||
frame_system::CheckWeight<Runtime>,
|
||||
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
|
||||
pallet_asset_tx_payment::ChargeAssetTxPayment<Runtime>,
|
||||
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
|
||||
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim<Runtime>,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user