Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support paying DOT as a fee #404

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions evm-template/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions evm-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
Expand Down Expand Up @@ -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 }
Expand Down
14 changes: 14 additions & 0 deletions evm-template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
43 changes: 36 additions & 7 deletions evm-template/runtime/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand All @@ -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"))]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -198,19 +202,44 @@ 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 }>;
type AssetId = AssetId;
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")]
Expand Down
3 changes: 3 additions & 0 deletions evm-template/runtime/src/configs/weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions evm-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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};
Expand Down Expand Up @@ -240,6 +241,8 @@ mod apis {
type RuntimeCall = RuntimeCall;
type TransactionPayment = TransactionPayment;
type Balance = Balance;
type Oracle = Oracle;
type OracleKey = AssetId;
}

mod consensus {
Expand Down Expand Up @@ -294,6 +297,8 @@ mod apis {
type RuntimeCall = RuntimeCall;
type Executive = Executive;
type Ethereum = Ethereum;
type Oracle = Oracle;
type OracleKey = AssetId;
}

mod assets {
Expand Down
2 changes: 1 addition & 1 deletion evm-template/runtime/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
);
Expand Down
Loading
Loading