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

[Runtime] Enable feeless, walletless transactions on selected accounts #428

Merged
merged 12 commits into from
Oct 30, 2024
Merged
Changes from 11 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
516 changes: 339 additions & 177 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -50,9 +50,14 @@ kusama-runtime-constants = { default-features = false, path = "runtime/kusama-ru
runtime-common = { default-features = false, path = "runtime/common" }

# Frame Contrib
fc-traits-memberships = { git = "https://github.com/virto-network/frame-contrib", branch = "main", default-features = false }
fc-traits-tracks = { git = "https://github.com/virto-network/frame-contrib", branch = "main", default-features = false }
pallet-referenda-tracks = { git = "https://github.com/virto-network/frame-contrib", branch = "main", package = "fc-pallet-referenda-tracks", default-features = false }
fc-traits-authn = { git = "https://github.com/virto-network/frame-contrib", default-features = false }
fc-traits-gas-tank = { git = "https://github.com/virto-network/frame-contrib", default-features = false }
fc-traits-memberships = { git = "https://github.com/virto-network/frame-contrib", default-features = false }
fc-traits-tracks = { git = "https://github.com/virto-network/frame-contrib", default-features = false }
pallet-gas-transaction-payment = { git = "https://github.com/virto-network/frame-contrib", package = "fc-pallet-gas-transaction-payment", default-features = false }
pallet-pass = { git = "https://github.com/virto-network/frame-contrib", package = "fc-pallet-pass", default-features = false }
pallet-referenda-tracks = { git = "https://github.com/virto-network/frame-contrib", package = "fc-pallet-referenda-tracks", default-features = false }
pass-webauthn = { git = "https://github.com/virto-network/webauthn", default-features = false }

# Substrate std
pallet-transaction-payment-rpc = { git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-stable2409" }
@@ -113,6 +118,7 @@ pallet-referenda = { default-features = false, git = "https://github.com/virto-n
pallet-remark = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-stable2409" }
pallet-scheduler = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-stable2409" }
pallet-session = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-stable2409" }
pallet-skip-feeless-payment = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-stable2409" }
pallet-sudo = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-stable2409" }
pallet-timestamp = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-stable2409" }
pallet-transaction-payment = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-stable2409" }
2 changes: 1 addition & 1 deletion chain-spec-generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ homepage.workspace = true
license.workspace = true
name = "chain-spec-generator"
repository.workspace = true
version = "0.13.3"
version = "0.14.0"

[dependencies]
clap = { workspace = true, features = ["derive"] }
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ bump mode="minor":
#!/usr/bin/env nu
let ver = '{{ ver }}' | inc --{{ mode }}
open -r runtime/kreivo/Cargo.toml | str replace -m '^version = "(.+)"$' $'version = "($ver)"' | save -f runtime/kreivo/Cargo.toml
open -r node/Cargo.toml | str replace -m '^version = "(.+)"$' $'version = "($ver)"' | save -f node/Cargo.toml
open -r chain-spec-generator/Cargo.toml | str replace -m '^version = "(.+)"$' $'version = "($ver)"' | save -f chain-spec-generator/Cargo.toml
# bump spec version
const SRC = 'runtime/kreivo/src/lib.rs'
let src = open $SRC
22 changes: 21 additions & 1 deletion runtime/kreivo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ homepage.workspace = true
license.workspace = true
name = "kreivo-runtime"
repository.workspace = true
version = "0.13.3"
version = "0.14.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
@@ -56,6 +56,7 @@ pallet-ranked-collective.workspace = true
pallet-referenda.workspace = true
pallet-scheduler.workspace = true
pallet-session.workspace = true
pallet-skip-feeless-payment.workspace = true
pallet-sudo.workspace = true
pallet-timestamp.workspace = true
pallet-transaction-payment.workspace = true
@@ -105,8 +106,13 @@ parachain-info.workspace = true
parachains-common.workspace = true

# Frame Contrib
fc-traits-authn.workspace = true
fc-traits-gas-tank.workspace = true
fc-traits-memberships.workspace = true
pallet-gas-transaction-payment.workspace = true
pallet-pass.workspace = true
pallet-referenda-tracks.workspace = true
pass-webauthn = { workspace = true, features = ["runtime"] }

[features]
default = ["std"]
@@ -129,6 +135,8 @@ std = [
"frame-system-rpc-runtime-api/std",
"frame-try-runtime/std",
"frame-system/std",
"fc-traits-authn/std",
"fc-traits-gas-tank/std",
"fc-traits-memberships/std",
"log/std",
"kusama-runtime-constants/std",
@@ -142,9 +150,11 @@ std = [
"pallet-communities-manager/std",
"pallet-communities/std",
"pallet-collator-selection/std",
"pallet-gas-transaction-payment/std",
"pallet-message-queue/std",
"pallet-multisig/std",
"pallet-nfts/std",
"pallet-pass/std",
"pallet-payments/std",
"pallet-preimage/std",
"pallet-proxy/std",
@@ -153,6 +163,7 @@ std = [
"pallet-referenda-tracks/std",
"pallet-scheduler/std",
"pallet-session/std",
"pallet-skip-feeless-payment/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
@@ -164,6 +175,7 @@ std = [
"parachain-info/std",
"parachains-common/std",
"parity-scale-codec/std",
"pass-webauthn/std",
"polkadot-core-primitives/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
@@ -209,22 +221,26 @@ runtime-benchmarks = [
"pallet-communities-manager/runtime-benchmarks",
"pallet-communities/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"pallet-gas-transaction-payment/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pallet-payments/runtime-benchmarks",
"pallet-pass/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-ranked-collective/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-referenda-tracks/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-skip-feeless-payment/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"pass-webauthn/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
@@ -254,9 +270,11 @@ try-runtime = [
"pallet-communities-manager/try-runtime",
"pallet-communities/try-runtime",
"pallet-collator-selection/try-runtime",
"pallet-gas-transaction-payment/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-nfts/try-runtime",
"pallet-multisig/try-runtime",
"pallet-pass/try-runtime",
"pallet-payments/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
@@ -265,12 +283,14 @@ try-runtime = [
"pallet-referenda-tracks/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-session/try-runtime",
"pallet-skip-feeless-payment/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-utility/try-runtime",
"pallet-xcm/try-runtime",
"pass-webauthn/try-runtime",
"parachain-info/try-runtime",
"polkadot-runtime-common/try-runtime",
"runtime-common/try-runtime",
12 changes: 12 additions & 0 deletions runtime/kreivo/src/configuration/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Configure FRAME pallets to include in runtime.

use super::*;

pub mod monetary_stuff;
pub mod system_support;

pub use monetary_stuff::{
ExistentialDeposit, KreivoAssetsCall, KreivoAssetsInstance, MetadataDepositBase, MetadataDepositPerByte,
TransactionByteFee,
};
pub use system_support::RuntimeBlockWeights;
142 changes: 142 additions & 0 deletions runtime/kreivo/src/configuration/monetary_stuff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
use super::*;

use fc_traits_gas_tank::NonFungibleGasBurner;

use pallet_asset_tx_payment::FungiblesAdapter;
use pallet_assets::BalanceToAssetBalance;
use pallet_transaction_payment::FungibleAdapter;
use runtime_common::impls::AssetsToBlockAuthor;

// #[runtime::pallet_index(10)]
// pub type Balances
parameter_types! {
pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
}

impl pallet_balances::Config for Runtime {
type MaxLocks = ConstU32<50>;
/// The type for recording an account's balance.
type Balance = Balance;
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
type MaxReserves = ConstU32<50>;
type ReserveIdentifier = [u8; 8];
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<256>;
type RuntimeFreezeReason = RuntimeFreezeReason;
}

// #[runtime::pallet_index(11)]
// pub type TransactionPayment
parameter_types! {
/// Relay Chain `TransactionByteFee` / 10
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}

impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = FungibleAdapter<Balances, ResolveTo<TreasuryAccount, Balances>>;
type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
type OperationalFeeMultiplier = ConstU8<5>;
}

// #[runtime::pallet_index(12)]
// pub type AssetsFreezer
impl pallet_assets_freezer::Config<KreivoAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeFreezeReason = RuntimeFreezeReason;
}

// #[runtime::pallet_index(13)]
// pub type Assets
parameter_types! {
pub const AssetDeposit: Balance = UNITS / 10; // 1 / 10 UNITS deposit to create asset
pub const AssetAccountDeposit: Balance = deposit(1, 16);
pub const ApprovalDeposit: Balance = EXISTENTIAL_DEPOSIT;
pub const AssetsStringLimit: u32 = 50;
/// Key = 32 bytes, Value = 36 bytes (32+1+1+1+1)
// https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271
pub const MetadataDepositBase: Balance = deposit(1, 68);
pub const MetadataDepositPerByte: Balance = deposit(0, 1);
}

/// We allow root to execute privileged asset operations.
pub type AssetsForceOrigin = EnsureRoot<AccountId>;
pub type KreivoAssetsInstance = pallet_assets::Instance1;
pub type KreivoAssetsCall = pallet_assets::Call<Runtime, KreivoAssetsInstance>;

impl pallet_assets::Config<KreivoAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = FungibleAssetLocation;
type AssetIdParameter = FungibleAssetLocation;
type Currency = Balances;
/// Only root can create assets and force state changes.
type CreateOrigin = AsEnsureOriginWithArg<NeverEnsureOrigin<AccountId>>;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
type MetadataDepositBase = MetadataDepositBase;
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type Freezer = AssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets::WeightInfo<Runtime>;
type CallbackHandle = ();
type AssetAccountDeposit = AssetAccountDeposit;
type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
type MaxHolds = frame_support::traits::ConstU32<50>;
type RuntimeHoldReason = RuntimeHoldReason;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

// #[runtime::pallet_index(14)]
// pub type AssetsTxPayment
impl pallet_asset_tx_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Fungibles = Assets;
type OnChargeAssetTransaction = FungiblesAdapter<
BalanceToAssetBalance<Balances, Runtime, ConvertInto, KreivoAssetsInstance>,
AssetsToBlockAuthor<Runtime, KreivoAssetsInstance>,
>;
}

// #[runtime::pallet_index(15)]
// pub type Vesting
parameter_types! {
pub const MinVestedTransfer: Balance = 100 * CENTS;
pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
}

impl pallet_vesting::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
type MinVestedTransfer = MinVestedTransfer;
type WeightInfo = pallet_vesting::weights::SubstrateWeight<Runtime>;
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
type BlockNumberProvider = System;
const MAX_VESTING_SCHEDULES: u32 = 28;
}

// #[runtime::pallet_index(16)]
// pub type SkipFeeless
impl pallet_skip_feeless_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

// #[runtime::pallet_index(17)]
// pub type GasTxPayment
impl pallet_gas_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type GasBurner = NonFungibleGasBurner<Runtime, CommunityMemberships, pallet_nfts::ItemConfig>;
}
Loading