mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-24 07:51:07 +00:00
Treasury spends various asset kinds (#1333)
### Summary This PR introduces new dispatchables to the treasury pallet, allowing spends of various asset types. The enhanced features of the treasury pallet, in conjunction with the asset-rate pallet, are set up and enabled for Westend and Rococo. ### Westend and Rococo runtimes. Polkadot/Kusams/Rococo Treasury can accept proposals for `spends` of various asset kinds by specifying the asset's location and ID. #### Treasury Instance New Dispatchables: - `spend(AssetKind, AssetBalance, Beneficiary, Option<ValidFrom>)` - propose and approve a spend; - `payout(SpendIndex)` - payout an approved spend or retry a failed payout - `check_payment(SpendIndex)` - check the status of a payout; - `void_spend(SpendIndex)` - void previously approved spend; > existing spend dispatchable renamed to spend_local in this context, the `AssetKind` parameter contains the asset's location and it's corresponding `asset_id`, for example: `USDT` on `AssetHub`, ``` rust location = MultiLocation(0, X1(Parachain(1000))) asset_id = MultiLocation(0, X2(PalletInstance(50), GeneralIndex(1984))) ``` the `Beneficiary` parameter is a `MultiLocation` in the context of the asset's location, for example ``` rust // the Fellowship salary pallet's location / account FellowshipSalaryPallet = MultiLocation(1, X2(Parachain(1001), PalletInstance(64))) // or custom `AccountId` Alice = MultiLocation(0, AccountId32(network: None, id: [1,...])) ``` the `AssetBalance` represents the amount of the `AssetKind` to be transferred to the `Beneficiary`. For permission checks, the asset amount is converted to the native amount and compared against the maximum spendable amount determined by the commanding spend origin. the `spend` dispatchable allows for batching spends with different `ValidFrom` arguments, enabling milestone-based spending. If the expectations tied to an approved spend are not met, it is possible to void the spend later using the `void_spend` dispatchable. Asset Rate Pallet provides the conversion rate from the `AssetKind` to the native balance. #### Asset Rate Instance Dispatchables: - `create(AssetKind, Rate)` - initialize a conversion rate to the native balance for the given asset - `update(AssetKind, Rate)` - update the conversion rate to the native balance for the given asset - `remove(AssetKind)` - remove an existing conversion rate to the native balance for the given asset the pallet's dispatchables can be executed by the Root or Treasurer origins. ### Treasury Pallet Treasury Pallet can accept proposals for `spends` of various asset kinds and pay them out through the implementation of the `Pay` trait. New Dispatchables: - `spend(Config::AssetKind, AssetBalance, Config::Beneficiary, Option<ValidFrom>)` - propose and approve a spend; - `payout(SpendIndex)` - payout an approved spend or retry a failed payout; - `check_payment(SpendIndex)` - check the status of a payout; - `void_spend(SpendIndex)` - void previously approved spend; > existing spend dispatchable renamed to spend_local The parameters' types of the `spend` dispatchable exposed via the pallet's `Config` and allows to propose and accept a spend of a certain amount. An approved spend can be claimed via the `payout` within the `Config::SpendPeriod`. Clients provide an implementation of the `Pay` trait which can pay an asset of the `AssetKind` to the `Beneficiary` in `AssetBalance` units. The implementation of the Pay trait might not have an immediate final payment status, for example if implemented over `XCM` and the actual transfer happens on a remote chain. The `check_status` dispatchable can be executed to update the spend's payment state and retry the `payout` if the payment has failed. --------- Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: command-bot <>
This commit is contained in:
@@ -30,7 +30,10 @@ use primitives::{
|
||||
ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, PARACHAIN_KEY_TYPE_ID,
|
||||
};
|
||||
use runtime_common::{
|
||||
assigned_slots, auctions, claims, crowdloan, impl_runtime_weights, impls::ToAuthor,
|
||||
assigned_slots, auctions, claims, crowdloan, impl_runtime_weights,
|
||||
impls::{
|
||||
LocatableAssetConverter, ToAuthor, VersionedLocatableAsset, VersionedMultiLocationConverter,
|
||||
},
|
||||
paras_registrar, paras_sudo_wrapper, prod_or_fast, slots, BlockHashCount, BlockLength,
|
||||
SlowAdjustingFeeUpdate,
|
||||
};
|
||||
@@ -79,7 +82,8 @@ use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys,
|
||||
traits::{
|
||||
AccountIdLookup, BlakeTwo256, Block as BlockT, ConstU32, ConvertInto,
|
||||
Extrinsic as ExtrinsicT, Keccak256, OpaqueKeys, SaturatedConversion, Verify,
|
||||
Extrinsic as ExtrinsicT, IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion,
|
||||
Verify,
|
||||
},
|
||||
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
|
||||
ApplyExtrinsicResult, FixedU128, KeyTypeId, Perbill, Percent, Permill, RuntimeDebug,
|
||||
@@ -88,7 +92,11 @@ use sp_staking::SessionIndex;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use sp_version::NativeVersion;
|
||||
use sp_version::RuntimeVersion;
|
||||
use xcm::latest::Junction;
|
||||
use xcm::{
|
||||
latest::{InteriorMultiLocation, Junction, Junction::PalletInstance},
|
||||
VersionedMultiLocation,
|
||||
};
|
||||
use xcm_builder::PayOverXcm;
|
||||
|
||||
pub use frame_system::Call as SystemCall;
|
||||
pub use pallet_balances::Call as BalancesCall;
|
||||
@@ -385,6 +393,10 @@ parameter_types! {
|
||||
pub const SpendPeriod: BlockNumber = 6 * DAYS;
|
||||
pub const Burn: Permill = Permill::from_perthousand(2);
|
||||
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
|
||||
pub const PayoutSpendPeriod: BlockNumber = 30 * DAYS;
|
||||
// The asset's interior location for the paying account. This is the Treasury
|
||||
// pallet instance (which sits at index 18).
|
||||
pub TreasuryInteriorLocation: InteriorMultiLocation = PalletInstance(18).into();
|
||||
|
||||
pub const TipCountdown: BlockNumber = 1 * DAYS;
|
||||
pub const TipFindersFee: Percent = Percent::from_percent(20);
|
||||
@@ -394,6 +406,7 @@ parameter_types! {
|
||||
pub const MaxAuthorities: u32 = 100_000;
|
||||
pub const MaxKeys: u32 = 10_000;
|
||||
pub const MaxPeerInHeartbeats: u32 = 10_000;
|
||||
pub const MaxBalance: Balance = Balance::max_value();
|
||||
}
|
||||
|
||||
impl pallet_treasury::Config for Runtime {
|
||||
@@ -413,6 +426,23 @@ impl pallet_treasury::Config for Runtime {
|
||||
type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
|
||||
type SpendFunds = Bounties;
|
||||
type SpendOrigin = TreasurySpender;
|
||||
type AssetKind = VersionedLocatableAsset;
|
||||
type Beneficiary = VersionedMultiLocation;
|
||||
type BeneficiaryLookup = IdentityLookup<Self::Beneficiary>;
|
||||
type Paymaster = PayOverXcm<
|
||||
TreasuryInteriorLocation,
|
||||
crate::xcm_config::XcmRouter,
|
||||
crate::XcmPallet,
|
||||
ConstU32<{ 6 * HOURS }>,
|
||||
Self::Beneficiary,
|
||||
Self::AssetKind,
|
||||
LocatableAssetConverter,
|
||||
VersionedMultiLocationConverter,
|
||||
>;
|
||||
type BalanceConverter = AssetRate;
|
||||
type PayoutPeriod = PayoutSpendPeriod;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkHelper = runtime_common::impls::benchmarks::TreasuryArguments;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -1202,6 +1232,18 @@ impl pallet_sudo::Config for Runtime {
|
||||
type WeightInfo = weights::pallet_sudo::WeightInfo<Runtime>;
|
||||
}
|
||||
|
||||
impl pallet_asset_rate::Config for Runtime {
|
||||
type WeightInfo = weights::pallet_asset_rate::WeightInfo<Runtime>;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type CreateOrigin = EnsureRoot<AccountId>;
|
||||
type RemoveOrigin = EnsureRoot<AccountId>;
|
||||
type UpdateOrigin = EnsureRoot<AccountId>;
|
||||
type Currency = Balances;
|
||||
type AssetKind = <Runtime as pallet_treasury::Config>::AssetKind;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkHelper = runtime_common::impls::benchmarks::AssetRateArguments;
|
||||
}
|
||||
|
||||
construct_runtime! {
|
||||
pub enum Runtime
|
||||
{
|
||||
@@ -1279,6 +1321,9 @@ construct_runtime! {
|
||||
// Preimage registrar.
|
||||
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>, HoldReason} = 32,
|
||||
|
||||
// Asset rate.
|
||||
AssetRate: pallet_asset_rate::{Pallet, Call, Storage, Event<T>} = 39,
|
||||
|
||||
// Bounties modules.
|
||||
Bounties: pallet_bounties::{Pallet, Call, Storage, Event<T>} = 35,
|
||||
ChildBounties: pallet_child_bounties = 40,
|
||||
@@ -1465,6 +1510,7 @@ mod benches {
|
||||
[pallet_treasury, Treasury]
|
||||
[pallet_utility, Utility]
|
||||
[pallet_vesting, Vesting]
|
||||
[pallet_asset_rate, AssetRate]
|
||||
[pallet_whitelist, Whitelist]
|
||||
// XCM
|
||||
[pallet_xcm, XcmPallet]
|
||||
|
||||
Reference in New Issue
Block a user