This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Runtime: Treasury spends various asset kinds #7427
Open
muharem
wants to merge
23
commits into
master
Choose a base branch
from
muharem-multi-asset-treasury
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
07ab21f
multi-asset treasury
muharem 6f78c24
weights
muharem 5ba47db
benchmarks fix
muharem bd45a32
enable features for asset-rate pallet
muharem d15bacb
benchmarks impls and weights
muharem d98fcaa
fix runtime commont tests
muharem 9632b1a
benchmarks fixes
muharem cac07bc
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
muharem 9063841
void spend
muharem 5439b9d
use reject origin
muharem 137415e
fix type definition
muharem 8595f44
Add missing features
ggwpez 0bb118c
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
muharem 1d48a86
new fn for LocatableAssetId type
muharem db809d5
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
muharem 9bac3ac
fixes after master merge
muharem 0653c73
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
778f084
pallet-treasury deps in Cargo.lock, docify and sp-core
muharem 3348a45
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
7215bfc
add asset kind type
muharem 7189d45
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
muharem 9c0bf72
remove Balance type from asset-rate pallet config
muharem 533fac0
asset kind rename
muharem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,10 @@ use primitives::{ | |
PARACHAIN_KEY_TYPE_ID, | ||
}; | ||
use runtime_common::{ | ||
auctions, claims, crowdloan, impl_runtime_weights, impls::DealWithFees, paras_registrar, | ||
prod_or_fast, slots, BalanceToU256, BlockHashCount, BlockLength, CurrencyToVote, | ||
SlowAdjustingFeeUpdate, U256ToBalance, | ||
auctions, claims, crowdloan, impl_runtime_weights, | ||
impls::{DealWithFees, LocatableAssetId, LocatableAssetIdConverter}, | ||
paras_registrar, prod_or_fast, slots, BalanceToU256, BlockHashCount, BlockLength, | ||
CurrencyToVote, SlowAdjustingFeeUpdate, U256ToBalance, | ||
}; | ||
use scale_info::TypeInfo; | ||
use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*}; | ||
|
@@ -74,8 +75,8 @@ use sp_mmr_primitives as mmr; | |
use sp_runtime::{ | ||
create_runtime_str, generic, impl_opaque_keys, | ||
traits::{ | ||
AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto, Extrinsic as ExtrinsicT, | ||
OpaqueKeys, SaturatedConversion, Verify, | ||
AccountIdLookup, BlakeTwo256, Block as BlockT, CloneIdentity, ConvertInto, | ||
Extrinsic as ExtrinsicT, IdentityLookup, OpaqueKeys, SaturatedConversion, Verify, | ||
}, | ||
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, | ||
ApplyExtrinsicResult, FixedU128, KeyTypeId, Perbill, Percent, Permill, | ||
|
@@ -84,7 +85,8 @@ 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, MultiLocation}; | ||
use xcm_builder::PayOverXcm; | ||
|
||
pub use frame_system::Call as SystemCall; | ||
pub use pallet_balances::Call as BalancesCall; | ||
|
@@ -613,6 +615,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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of hardcoding |
||
|
||
pub const TipCountdown: BlockNumber = 1 * DAYS; | ||
pub const TipFindersFee: Percent = Percent::from_percent(20); | ||
|
@@ -641,6 +647,23 @@ impl pallet_treasury::Config for Runtime { | |
type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>; | ||
type SpendFunds = Bounties; | ||
type SpendOrigin = TreasurySpender; | ||
type AssetKind = LocatableAssetId; | ||
type Beneficiary = MultiLocation; | ||
type BeneficiaryLookup = IdentityLookup<Self::Beneficiary>; | ||
type Paymaster = PayOverXcm< | ||
TreasuryInteriorLocation, | ||
crate::xcm_config::XcmRouter, | ||
crate::XcmPallet, | ||
ConstU32<{ 6 * HOURS }>, | ||
Self::Beneficiary, | ||
Self::AssetKind, | ||
LocatableAssetIdConverter, | ||
CloneIdentity, | ||
>; | ||
type BalanceConverter = AssetRate; | ||
type PayoutPeriod = PayoutSpendPeriod; | ||
#[cfg(feature = "runtime-benchmarks")] | ||
type BenchmarkHelper = runtime_common::impls::benchmarks::TreasuryArguments; | ||
} | ||
|
||
parameter_types! { | ||
|
@@ -1344,6 +1367,18 @@ impl pallet_nomination_pools::Config for Runtime { | |
type MaxPointsToBalance = MaxPointsToBalance; | ||
} | ||
|
||
impl pallet_asset_rate::Config for Runtime { | ||
type WeightInfo = weights::pallet_asset_rate::WeightInfo<Runtime>; | ||
type RuntimeEvent = RuntimeEvent; | ||
type CreateOrigin = EitherOfDiverse<EnsureRoot<AccountId>, Treasurer>; | ||
type RemoveOrigin = EitherOfDiverse<EnsureRoot<AccountId>, Treasurer>; | ||
type UpdateOrigin = EitherOfDiverse<EnsureRoot<AccountId>, Treasurer>; | ||
type Currency = Balances; | ||
type AssetKind = <Runtime as pallet_treasury::Config>::AssetKind; | ||
#[cfg(feature = "runtime-benchmarks")] | ||
type BenchmarkHelper = runtime_common::impls::benchmarks::AssetRateArguments; | ||
} | ||
|
||
parameter_types! { | ||
// The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high) | ||
pub const MigrationSignedDepositPerItem: Balance = 1 * CENTS; | ||
|
@@ -1456,6 +1491,9 @@ construct_runtime! { | |
// Fast unstake pallet: extension to staking. | ||
FastUnstake: pallet_fast_unstake = 42, | ||
|
||
// Asset rate. | ||
AssetRate: pallet_asset_rate::{Pallet, Call, Storage, Event<T>} = 46, | ||
|
||
// Parachains pallets. Start indices at 50 to leave room. | ||
ParachainsOrigin: parachains_origin::{Pallet, Origin} = 50, | ||
Configuration: parachains_configuration::{Pallet, Call, Storage, Config<T>} = 51, | ||
|
@@ -1610,6 +1648,7 @@ mod benches { | |
[pallet_utility, Utility] | ||
[pallet_vesting, Vesting] | ||
[pallet_whitelist, Whitelist] | ||
[pallet_asset_rate, AssetRate] | ||
// XCM | ||
[pallet_xcm, XcmPallet] | ||
[pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::<Runtime>] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks silly, why can't we just directly reuse
xcm_builder::LocatableAssetId
instead of declaring a newLocatableAssetId
here in this module?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like that a change in an external library can change the signature of the spend dispatchable.
Where
xcm_builder::LocatableAssetId
is not part of XCM protocol, or meant to be used as a dispatchable's type parameter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why you have to prepare for this? If upstream changes, then you can think of creating a new type retaining the old fields, but this now is a bit overoptimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the change to the dispatchable signature will invalidate all spend proposals which has been submitted before and still active.
and such a change might be not noticed (this we can address with a test).
but this why I made it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a better idea: why not have the
spend
dispatchable directly take inBox<VersionedMultiLocation>
andBox<VersionedAssetId>
as parameters? This should have been the proper way of accepting versioned XCM parameters anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea with versioned types, this is probably how we should do it.
We need to combine both type into one type, since it is meant for
pallet_treasury::Config::AssetKind
type parameter. This AssetKind can be justu32
for example.It can be same as
LocatableAssetId
but with versioned versions of MultiLocation and AssetId,or i would better do something like
this way we can control which versions relevant right now specifically for treasury proposals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so what you seem to be saying is the parameters to the
spend
extrinsic is dependent on what the concrete configured type is forpallet_treasury::Config::AssetKind
, so if it ever changes, then the signature of thespend
extrinsic must also necessarily change. Given that's the case, why would we then allowAssetKind
to be configurable? It would seem to me that we should instead make it not configurable, so as to preserve API compatibility across versions.