diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index c315395..e0dce07 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -4,6 +4,7 @@ ** xref:guides/async_backing.adoc[Async Backing] ** xref:guides/hrmp_channels.adoc[Sending XCM between Parachains] ** xref:guides/pallet_abstractions.adoc[OpenZeppelin Pallet Abstractions] +** xref:guides/pay_dot_as_a_fee.adoc[Pay DOT as a Fee] * EVM Template Guides ** xref:guides/contract_migration.adoc[Contract Migration] ** xref:guides/predeployed_contracts.adoc[Predeployed Contracts] diff --git a/docs/modules/ROOT/pages/guides/pay_dot_as_a_fee.adoc b/docs/modules/ROOT/pages/guides/pay_dot_as_a_fee.adoc new file mode 100644 index 0000000..811bb29 --- /dev/null +++ b/docs/modules/ROOT/pages/guides/pay_dot_as_a_fee.adoc @@ -0,0 +1,99 @@ +:source-highlighter: highlight.js +:highlightjs-languages: rust +:github-icon: pass:[] + += Pay DOT as a Fee + +This feature allows you to set DOT (or any other registered asset) as a fee for transaction execution. Here are the steps that you will need to execute to support it. + +== Configuration + +All you need to configure to start using this feature is an Oracle. You can use some service from any oracle service (like Chainlink, Pyth and others who support Substrate runtimes) or set up a development-mode solution. + +=== 1. Add Oracle Members + +To add oracle members, you'll need to submit transactions with sudo or root privileges: + +[source,bash] +---- +# Add a member (replace with actual address) +subxt tx --url "ws://localhost:9944" \ + --suri "" \ + pallet-membership add_member \ + --account "" + +# Verify members +subxt query --url "ws://localhost:9944" \ + pallet-membership members +---- + +=== 2. Format Oracle Values + +Oracle values should be formatted according to your runtime's `OracleValue` type. Here's an example for price data: + +// TODO: fix values +[source,rust] +---- +// Example price format +type Price = FixedU128; // price with 18 decimals +type CurrencyId = u32; // for generic template, for EVM we use u128 +---- + +=== 3. Submit Oracle Data + +Here's how to submit oracle data using the CLI: + +[source,bash] +---- +# Submit price feed for DOT/USD +subxt tx --url "ws://localhost:9944" \ + --suri "" \ + orml-oracle feed_values \ + --values '[[1, "12000000000000000000"]]' # replace the CurrencyId with DOT's AssetId and the number with price of native DOT in native tokens +---- + +=== 4. Query Oracle Data + +To verify the submitted data: + +[source,bash] +---- +# Query latest price +subxt query --url "ws://localhost:9944" \ + orml-oracle get \ + --key 1 # CurrencyId +---- + +== Development Testing + +For development purposes, you can set up automated price feeds: + +[source,bash] +---- +#!/bin/bash + +while true; do + # Generate random price between $10-15 + PRICE=$((RANDOM % 5000 + 10000)) + PRICE_WITH_DECIMALS="${PRICE}000000000000000" + + subxt tx --url "ws://localhost:9944" \ + --suri "" \ + orml-oracle feed_values \ + --values "[[1, \"$PRICE_WITH_DECIMALS\"]]" + + sleep 60 # Wait 1 minute before next update +done +---- + +== Opting out + +If you want to opt out of this feature, then you can just replace the `pallet_asset_tx_payment` with `pallet_transaction_payment` piece in `SignedExtra`: + +[source,patch] +pub type SignedExtra = ( +... +- pallet_asset_tx_payment::ChargeAssetTxPayment, ++ pallet_transaction_payment::ChargeTransactionPayment, +... +); \ No newline at end of file diff --git a/evm-template/Cargo.lock b/evm-template/Cargo.lock index 302606c..0ec1930 100644 --- a/evm-template/Cargo.lock +++ b/evm-template/Cargo.lock @@ -3224,10 +3224,13 @@ dependencies = [ "nimbus-primitives", "openzeppelin-pallet-abstractions", "openzeppelin-pallet-abstractions-proc", + "orml-oracle", + "orml-oracle-runtime-api", "orml-traits", "orml-xcm-support", "orml-xtokens", "pallet-asset-manager", + "pallet-asset-tx-payment", "pallet-assets", "pallet-aura", "pallet-author-inherent", @@ -3244,6 +3247,7 @@ dependencies = [ "pallet-evm-precompile-modexp", "pallet-evm-precompile-sha3fips", "pallet-evm-precompile-simple", + "pallet-membership", "pallet-message-queue", "pallet-multisig", "pallet-preimage", @@ -7025,7 +7029,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate 3.2.0", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 2.0.87", @@ -7154,7 +7158,7 @@ dependencies = [ [[package]] name = "openzeppelin-pallet-abstractions" version = "0.1.0" -source = "git+https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions?tag=v0.1-rc3#130bff8b34d6d4f10885e0691614f57a59f3ecab" +source = "git+https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions?branch=dot-as-a-fee-fixes#2e88d23d3d336d4c65b039c431ea3219e8e3b856" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -7167,7 +7171,7 @@ dependencies = [ [[package]] name = "openzeppelin-pallet-abstractions-proc" version = "0.1.0" -source = "git+https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions?tag=v0.1-rc3#130bff8b34d6d4f10885e0691614f57a59f3ecab" +source = "git+https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions?branch=dot-as-a-fee-fixes#2e88d23d3d336d4c65b039c431ea3219e8e3b856" dependencies = [ "darling", "openzeppelin-pallet-abstractions", @@ -7224,6 +7228,35 @@ dependencies = [ "num-traits", ] +[[package]] +name = "orml-oracle" +version = "0.10.0" +source = "git+https://github.com/OpenZeppelin/open-runtime-module-library?branch=polkadot-stable2407-1#aafe9077c9ec61dd8b3a42e899ef8353b2b050c0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "orml-traits", + "orml-utilities", + "parity-scale-codec", + "scale-info", + "serde", + "sp-application-crypto", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "orml-oracle-runtime-api" +version = "0.10.0" +source = "git+https://github.com/OpenZeppelin/open-runtime-module-library?branch=polkadot-stable2407-1#aafe9077c9ec61dd8b3a42e899ef8353b2b050c0" +dependencies = [ + "parity-scale-codec", + "sp-api", + "sp-std", +] + [[package]] name = "orml-traits" version = "0.10.0" diff --git a/evm-template/Cargo.toml b/evm-template/Cargo.toml index e8cb9c7..44b66fa 100644 --- a/evm-template/Cargo.toml +++ b/evm-template/Cargo.toml @@ -28,8 +28,8 @@ serde_json = "1.0.121" smallvec = "1.11.0" # TODO: update to release -openzeppelin-pallet-abstractions = { git = "https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions", default-features = false, tag = "v0.1-rc3" } -openzeppelin-pallet-abstractions-proc = { git = "https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions", default-features = false, tag = "v0.1-rc3" } +openzeppelin-pallet-abstractions = { git = "https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions", branch = "dot-as-a-fee-fixes", default-features = false } +openzeppelin-pallet-abstractions-proc = { git = "https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions", branch = "dot-as-a-fee-fixes", default-features = false } # Substrate frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } @@ -41,11 +41,13 @@ frame-system = { git = "https://github.com/paritytech/polkadot-sdk", default-fea frame-system-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } +pallet-asset-tx-payment = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-conviction-voting = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } +pallet-membership = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-multisig = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-preimage = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } @@ -171,6 +173,8 @@ pallet-evm-precompile-sha3fips = { git = "https://github.com/OpenZeppelin/fronti pallet-evm-precompile-simple = { git = "https://github.com/OpenZeppelin/frontier", branch = "polkadot-stable2407-1", default-features = false } # ORML +orml-oracle = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } +orml-oracle-runtime-api = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } orml-traits = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } orml-xcm-support = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } orml-xtokens = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } diff --git a/evm-template/runtime/Cargo.toml b/evm-template/runtime/Cargo.toml index dd067de..ca5a366 100644 --- a/evm-template/runtime/Cargo.toml +++ b/evm-template/runtime/Cargo.toml @@ -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", diff --git a/evm-template/runtime/src/configs/mod.rs b/evm-template/runtime/src/configs/mod.rs index 21b0cca..d499ab4 100644 --- a/evm-template/runtime/src/configs/mod.rs +++ b/evm-template/runtime/src/configs/mod.rs @@ -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(PhantomData<(R, I)>); +impl HandleCredit, pallet_assets::Pallet> for AssetsToBlockAuthor +where + I: 'static, + R: pallet_authorship::Config + pallet_assets::Config, +{ + fn handle_credit(credit: Credit, pallet_assets::Pallet>) { + use frame_support::traits::fungibles::Balanced; + if let Some(author) = pallet_authorship::Pallet::::author() { + // In case of error: Will drop the result triggering the `OnDrop` of the imbalance. + let _ = pallet_assets::Pallet::::resolve(&author, credit); + } + } +} + impl AssetsConfig for OpenZeppelinRuntime { + type AccountId = AccountId; type ApprovalDeposit = ConstU128; 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; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = BenchmarkHelper; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = EnsureRoot; type ForeignAssetModifierOrigin = EnsureRoot; + type FungiblesToAccount = TreasuryAccount; + type RootOperatorAccountId = RootOperatorAccountId; + type Timestamp = Timestamp; type WeightToFee = WeightToFee; } #[cfg(feature = "tanssi")] @@ -283,6 +312,77 @@ impl fp_rpc::ConvertTransaction 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::::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::::handle_credit(credit); + }); + } + + fn new_test_ext() -> sp_io::TestExternalities { + use sp_runtime::BuildStorage; + frame_system::GenesisConfig::::default().build_storage().unwrap().into() + } + } mod transaction_converter { use core::str::FromStr; diff --git a/evm-template/runtime/src/configs/weight.rs b/evm-template/runtime/src/configs/weight.rs index a76ed3d..329a676 100644 --- a/evm-template/runtime/src/configs/weight.rs +++ b/evm-template/runtime/src/configs/weight.rs @@ -33,6 +33,9 @@ impl ConsensusWeight for OpenZeppelinRuntime { impl AssetsWeight for OpenZeppelinRuntime { type AssetManager = weights::pallet_asset_manager::WeightInfo; type Assets = weights::pallet_assets::WeightInfo; + // TODO: fix weight + type OracleMembership = (); + type OrmlOracle = (); // TODO: fix weight } impl GovernanceWeight for OpenZeppelinRuntime { diff --git a/evm-template/runtime/src/lib.rs b/evm-template/runtime/src/lib.rs index 96c4f1d..b66a7e1 100644 --- a/evm-template/runtime/src/lib.rs +++ b/evm-template/runtime/src/lib.rs @@ -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 { diff --git a/evm-template/runtime/src/types.rs b/evm-template/runtime/src/types.rs index 4253b17..ec191d0 100644 --- a/evm-template/runtime/src/types.rs +++ b/evm-template/runtime/src/types.rs @@ -83,7 +83,7 @@ pub type SignedExtra = ( frame_system::CheckEra, frame_system::CheckNonce, frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, + pallet_asset_tx_payment::ChargeAssetTxPayment, frame_metadata_hash_extension::CheckMetadataHash, cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, ); diff --git a/generic-template/Cargo.lock b/generic-template/Cargo.lock index aa4defe..09cde92 100644 --- a/generic-template/Cargo.lock +++ b/generic-template/Cargo.lock @@ -3870,10 +3870,13 @@ dependencies = [ "nimbus-primitives", "openzeppelin-pallet-abstractions", "openzeppelin-pallet-abstractions-proc", + "orml-oracle", + "orml-oracle-runtime-api", "orml-traits", "orml-xcm-support", "orml-xtokens", "pallet-asset-manager", + "pallet-asset-tx-payment", "pallet-assets", "pallet-aura", "pallet-author-inherent", @@ -3882,6 +3885,7 @@ dependencies = [ "pallet-cc-authorities-noting", "pallet-collator-selection", "pallet-conviction-voting", + "pallet-membership", "pallet-message-queue", "pallet-multisig", "pallet-preimage", @@ -6790,7 +6794,7 @@ dependencies = [ [[package]] name = "openzeppelin-pallet-abstractions" version = "0.1.0" -source = "git+https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions?tag=v0.1-rc3#130bff8b34d6d4f10885e0691614f57a59f3ecab" +source = "git+https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions?branch=dot-as-a-fee-fixes#2e88d23d3d336d4c65b039c431ea3219e8e3b856" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -6803,7 +6807,7 @@ dependencies = [ [[package]] name = "openzeppelin-pallet-abstractions-proc" version = "0.1.0" -source = "git+https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions?tag=v0.1-rc3#130bff8b34d6d4f10885e0691614f57a59f3ecab" +source = "git+https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions?branch=dot-as-a-fee-fixes#2e88d23d3d336d4c65b039c431ea3219e8e3b856" dependencies = [ "darling", "openzeppelin-pallet-abstractions", @@ -6860,6 +6864,35 @@ dependencies = [ "num-traits", ] +[[package]] +name = "orml-oracle" +version = "0.10.0" +source = "git+https://github.com/OpenZeppelin/open-runtime-module-library?branch=polkadot-stable2407-1#aafe9077c9ec61dd8b3a42e899ef8353b2b050c0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "orml-traits", + "orml-utilities", + "parity-scale-codec", + "scale-info", + "serde", + "sp-application-crypto", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "orml-oracle-runtime-api" +version = "0.10.0" +source = "git+https://github.com/OpenZeppelin/open-runtime-module-library?branch=polkadot-stable2407-1#aafe9077c9ec61dd8b3a42e899ef8353b2b050c0" +dependencies = [ + "parity-scale-codec", + "sp-api", + "sp-std", +] + [[package]] name = "orml-traits" version = "0.10.0" diff --git a/generic-template/Cargo.toml b/generic-template/Cargo.toml index 5720b34..1e06650 100644 --- a/generic-template/Cargo.toml +++ b/generic-template/Cargo.toml @@ -26,8 +26,8 @@ serde_json = "1.0.121" smallvec = "1.11.0" # TODO: update to release -openzeppelin-pallet-abstractions = { git = "https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions", default-features = false, tag = "v0.1-rc3" } -openzeppelin-pallet-abstractions-proc = { git = "https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions", default-features = false, tag = "v0.1-rc3" } +openzeppelin-pallet-abstractions = { git = "https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions", branch = "dot-as-a-fee-fixes", default-features = false } +openzeppelin-pallet-abstractions-proc = { git = "https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions", branch = "dot-as-a-fee-fixes", default-features = false } # Substrate frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } @@ -39,11 +39,13 @@ frame-system = { git = "https://github.com/paritytech/polkadot-sdk", default-fea frame-system-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } +pallet-asset-tx-payment = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-conviction-voting = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } +pallet-membership = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-multisig = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } pallet-preimage = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" } @@ -145,6 +147,8 @@ pallet-xcm-weight-trader = { git = "https://github.com/OpenZeppelin/moonbeam.git xcm-primitives = { git = "https://github.com/OpenZeppelin/moonbeam.git", branch = "polkadot-stable2407-1", default-features = false } # ORML +orml-oracle = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } +orml-oracle-runtime-api = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } orml-traits = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } orml-xcm-support = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } orml-xtokens = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } diff --git a/generic-template/runtime/Cargo.toml b/generic-template/runtime/Cargo.toml index 67e7caf..dc8d81f 100644 --- a/generic-template/runtime/Cargo.toml +++ b/generic-template/runtime/Cargo.toml @@ -29,9 +29,11 @@ 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-balances = { workspace = true } pallet-conviction-voting = { workspace = true } +pallet-membership = { workspace = true } pallet-message-queue = { workspace = true } pallet-multisig = { workspace = true } pallet-preimage = { workspace = true } @@ -96,6 +98,8 @@ xcm-primitives = { workspace = true } # ORML dp-consensus = { workspace = true } nimbus-primitives = { workspace = true } +orml-oracle = { workspace = true } +orml-oracle-runtime-api = { workspace = true } orml-traits = { workspace = true } orml-xcm-support = { workspace = true } orml-xtokens = { workspace = true } @@ -137,8 +141,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", @@ -147,6 +154,7 @@ std = [ "pallet-cc-authorities-noting/std", "pallet-collator-selection/std", "pallet-conviction-voting/std", + "pallet-membership/std", "pallet-message-queue/std", "pallet-multisig/std", "pallet-preimage/std", @@ -202,12 +210,15 @@ 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", "pallet-cc-authorities-noting/runtime-benchmarks", "pallet-conviction-voting/runtime-benchmarks", + "pallet-membership/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", @@ -240,8 +251,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", @@ -249,6 +262,7 @@ try-runtime = [ "pallet-cc-authorities-noting/try-runtime", "pallet-collator-selection/try-runtime", "pallet-conviction-voting/try-runtime", + "pallet-membership/try-runtime", "pallet-message-queue/try-runtime", "pallet-multisig/try-runtime", "pallet-preimage/try-runtime", diff --git a/generic-template/runtime/src/apis.rs b/generic-template/runtime/src/apis.rs index 0463f1c..f43fd99 100644 --- a/generic-template/runtime/src/apis.rs +++ b/generic-template/runtime/src/apis.rs @@ -11,8 +11,8 @@ use crate::{ use crate::{constants::SLOT_DURATION, types::ConsensusHook}; use crate::{ constants::VERSION, - types::{AccountId, Balance, Block, Executive, Nonce}, - InherentDataExt, ParachainSystem, Runtime, RuntimeBlockWeights, RuntimeCall, + types::{AccountId, AssetId, Balance, Block, Executive, Nonce}, + InherentDataExt, Oracle, ParachainSystem, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeGenesisConfig, SessionKeys, System, TransactionPayment, }; @@ -29,6 +29,8 @@ mod apis { type RuntimeCall = RuntimeCall; type TransactionPayment = TransactionPayment; type Balance = Balance; + type Oracle = Oracle; + type OracleKey = AssetId; } mod consensus { @@ -83,6 +85,8 @@ mod apis { type RuntimeCall = RuntimeCall; type TransactionPayment = TransactionPayment; type Balance = Balance; + type Oracle = Oracle; + type OracleKey = AssetId; } mod tanssi { diff --git a/generic-template/runtime/src/configs/mod.rs b/generic-template/runtime/src/configs/mod.rs index fc12c45..d95da97 100644 --- a/generic-template/runtime/src/configs/mod.rs +++ b/generic-template/runtime/src/configs/mod.rs @@ -82,10 +82,10 @@ use crate::{ TreasuryAccount, TreasuryInteriorLocation, TreasuryPalletId, TreasuryPaymaster, Version, }, weights::{BlockExecutionWeight, ExtrinsicBaseWeight}, - AllPalletsWithSystem, AssetManager, Balances, MessageQueue, OriginCaller, PalletInfo, - ParachainInfo, ParachainSystem, PolkadotXcm, Preimage, Referenda, Runtime, RuntimeCall, - RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask, Scheduler, - System, Treasury, WeightToFee, XcmpQueue, + AllPalletsWithSystem, AssetManager, Balances, MessageQueue, Oracle, OracleMembership, + OriginCaller, PalletInfo, ParachainInfo, ParachainSystem, PolkadotXcm, Preimage, Referenda, + Runtime, RuntimeCall, RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, + RuntimeTask, Scheduler, System, Timestamp, Treasury, WeightToFee, XcmpQueue, }; #[cfg(not(feature = "tanssi"))] use crate::{Aura, CollatorSelection, Session}; @@ -176,7 +176,13 @@ impl XcmConfig for OpenZeppelinRuntime { type XcmpQueueMaxInboundSuspended = ConstU32<1000>; type XtokensReserveProviders = ReserveProviders; } + +parameter_types! { + pub RootOperatorAccountId: AccountId = AccountId::from([0xffu8; 32]); +} + impl AssetsConfig for OpenZeppelinRuntime { + type AccountId = AccountId; type ApprovalDeposit = ConstU128; type AssetAccountDeposit = ConstU128<{ deposit(1, 16) }>; type AssetDeposit = ConstU128<{ 10 * CENTS }>; @@ -184,11 +190,16 @@ impl AssetsConfig for OpenZeppelinRuntime { type AssetRegistrar = AssetRegistrar; type AssetRegistrarMetadata = AssetRegistrarMetadata; type AssetType = AssetType; + type AssetsToBlockAuthor = parachains_common::impls::AssetsToBlockAuthor; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = EnsureRoot; type ForeignAssetModifierOrigin = EnsureRoot; + type FungiblesToAccount = TreasuryAccount; + type RootOperatorAccountId = RootOperatorAccountId; + type Timestamp = Timestamp; type WeightToFee = WeightToFee; } + #[cfg(feature = "tanssi")] impl TanssiConfig for OpenZeppelinRuntime { type AuthorInherent = pallet_author_inherent::weights::SubstrateWeight; diff --git a/generic-template/runtime/src/configs/weight.rs b/generic-template/runtime/src/configs/weight.rs index 8b72cff..904a45c 100644 --- a/generic-template/runtime/src/configs/weight.rs +++ b/generic-template/runtime/src/configs/weight.rs @@ -31,6 +31,9 @@ impl ConsensusWeight for OpenZeppelinRuntime { impl AssetsWeight for OpenZeppelinRuntime { type AssetManager = weights::pallet_asset_manager::WeightInfo; type Assets = weights::pallet_assets::WeightInfo; + // TODO: fix weight on release + type OracleMembership = (); + type OrmlOracle = (); // TODO: fix weight } impl GovernanceWeight for OpenZeppelinRuntime { diff --git a/generic-template/runtime/src/types.rs b/generic-template/runtime/src/types.rs index 61a1088..4a31bfc 100644 --- a/generic-template/runtime/src/types.rs +++ b/generic-template/runtime/src/types.rs @@ -81,7 +81,7 @@ pub type SignedExtra = ( frame_system::CheckEra, frame_system::CheckNonce, frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, + pallet_asset_tx_payment::ChargeAssetTxPayment, frame_metadata_hash_extension::CheckMetadataHash, cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, );