-
Notifications
You must be signed in to change notification settings - Fork 1.2k
allow treasury to do reserve asset transfers #1447
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
Merged
bkchr
merged 32 commits into
paritytech:master
from
samelamin:allow_treasury_to_send_xcm
Oct 12, 2023
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f97b8b4
allow treasury to do reserve asset transfers
samelamin 0cb9bd8
fix for feature-propagation test
samelamin 6950232
fix for fmt-manifest
samelamin 6edfe8c
Update polkadot/runtime/kusama/src/xcm_config.rs
samelamin 1c39018
pr comments
samelamin cd1a317
remove treasury match from AccountId32Aliases
samelamin 92c19e4
Use TreasuryAccount: Get<AccountId>
samelamin bc47444
fix for failing builds
samelamin b0a32df
Update polkadot/runtime/kusama/src/xcm_config.rs
samelamin fd36d62
PR comments
samelamin 8967478
remove unused variable
samelamin 0900cf6
second round of comments
samelamin 97919f2
Standardize DescribeLocation usage
franciscoaguirre a20fcf6
build fixes
samelamin d692513
Merge branch 'master' into allow_treasury_to_send_xcm
samelamin c43e583
fmt
samelamin b0bb2b5
Merge branch 'master' into allow_treasury_to_send_xcm
franciscoaguirre 3ed9509
pr comment: rename variable
samelamin b666a1c
Update polkadot/xcm/xcm-builder/src/location_conversion.rs
samelamin 25da765
Merge branch 'master' into allow_treasury_to_send_xcm
bkchr 6410078
Update polkadot/xcm/xcm-builder/src/location_conversion.rs
samelamin 4ae6087
Update polkadot/xcm/xcm-builder/src/location_conversion.rs
samelamin 920b3ea
Update polkadot/xcm/xcm-builder/src/location_conversion.rs
samelamin cc1fbc5
pr comments
samelamin 7ce71d1
remove from setup
samelamin 20abdf0
pr comments
samelamin 558e585
add para to para treasury test
samelamin 8d478b9
Merge branch 'master' into allow_treasury_to_send_xcm
samelamin 4de166a
add DescribeTreasuryVoiceTerminal to imports
samelamin 5a42734
revert imports
samelamin aee64f5
Merge branch 'master' into allow_treasury_to_send_xcm
samelamin 28b4f9e
Merge branch 'master' into allow_treasury_to_send_xcm
samelamin 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
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -84,6 +84,20 @@ impl DescribeLocation for DescribeAccountKey20Terminal { | |
| } | ||
| } | ||
|
|
||
| /// Create a description of the remote treasury `location` if possible. No two locations should have | ||
| /// the same descriptor. | ||
| pub struct DescribeTreasuryVoiceTerminal; | ||
|
Contributor
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. very cute name. |
||
|
|
||
| impl DescribeLocation for DescribeTreasuryVoiceTerminal { | ||
| fn describe_location(l: &MultiLocation) -> Option<Vec<u8>> { | ||
| match (l.parents, &l.interior) { | ||
| (0, X1(Plurality { id: BodyId::Treasury, part: BodyPart::Voice })) => | ||
| Some((b"Treasury", b"Voice").encode()), | ||
| _ => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub type DescribeAccountIdTerminal = (DescribeAccountId32Terminal, DescribeAccountKey20Terminal); | ||
|
|
||
| pub struct DescribeBodyTerminal; | ||
|
|
@@ -101,6 +115,7 @@ pub type DescribeAllTerminal = ( | |
| DescribePalletTerminal, | ||
| DescribeAccountId32Terminal, | ||
| DescribeAccountKey20Terminal, | ||
| DescribeTreasuryVoiceTerminal, | ||
| DescribeBodyTerminal, | ||
| ); | ||
|
|
||
|
|
@@ -328,6 +343,25 @@ impl<Network: Get<Option<NetworkId>>, AccountId: From<[u8; 32]> + Into<[u8; 32]> | |
| } | ||
| } | ||
|
|
||
| /// Returns specified `TreasuryAccount` as `AccountId32` if passed `location` matches Treasury | ||
| /// plurality. | ||
| pub struct LocalTreasuryVoiceConvertsVia<TreasuryAccount, AccountId>( | ||
|
Contributor
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. it would be nice to add here simple test for this converter |
||
| PhantomData<(TreasuryAccount, AccountId)>, | ||
| ); | ||
| impl<TreasuryAccount: Get<AccountId>, AccountId: From<[u8; 32]> + Into<[u8; 32]> + Clone> | ||
| ConvertLocation<AccountId> for LocalTreasuryVoiceConvertsVia<TreasuryAccount, AccountId> | ||
| { | ||
| fn convert_location(location: &MultiLocation) -> Option<AccountId> { | ||
| match *location { | ||
| MultiLocation { | ||
| parents: 0, | ||
| interior: X1(Plurality { id: BodyId::Treasury, part: BodyPart::Voice }), | ||
| } => Some((TreasuryAccount::get().into() as [u8; 32]).into()), | ||
| _ => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Conversion implementation which converts from a `[u8; 32]`-based `AccountId` into a | ||
| /// `MultiLocation` consisting solely of a `AccountId32` junction with a fixed value for its | ||
| /// network (provided by `Network`) and the `AccountId`'s `[u8; 32]` datum for the `id`. | ||
|
|
@@ -442,10 +476,13 @@ impl<UniversalLocation, AccountId> | |
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| use primitives::AccountId; | ||
| pub type ForeignChainAliasAccount<AccountId> = | ||
| HashedDescription<AccountId, LegacyDescribeForeignChainAccount>; | ||
|
|
||
| pub type ForeignChainAliasTreasuryAccount<AccountId> = | ||
| HashedDescription<AccountId, DescribeFamily<DescribeTreasuryVoiceTerminal>>; | ||
|
|
||
| use frame_support::parameter_types; | ||
| use xcm::latest::Junction; | ||
|
|
||
|
|
@@ -936,4 +973,70 @@ mod tests { | |
| }; | ||
| assert!(ForeignChainAliasAccount::<[u8; 32]>::convert_location(&mul).is_none()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn remote_account_convert_on_para_sending_from_remote_para_treasury() { | ||
| let relay_treasury_to_para_location = MultiLocation { | ||
| parents: 1, | ||
| interior: X1(Plurality { id: BodyId::Treasury, part: BodyPart::Voice }), | ||
| }; | ||
| let actual_description = ForeignChainAliasTreasuryAccount::<[u8; 32]>::convert_location( | ||
| &relay_treasury_to_para_location, | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert_eq!( | ||
| [ | ||
| 18, 84, 93, 74, 187, 212, 254, 71, 192, 127, 112, 51, 3, 42, 54, 24, 220, 185, 161, | ||
| 67, 205, 154, 108, 116, 108, 166, 226, 211, 29, 11, 244, 115 | ||
| ], | ||
| actual_description | ||
| ); | ||
|
|
||
| let para_to_para_treasury_location = MultiLocation { | ||
| parents: 1, | ||
| interior: X2( | ||
| Parachain(1001), | ||
| Plurality { id: BodyId::Treasury, part: BodyPart::Voice }, | ||
| ), | ||
| }; | ||
| let actual_description = ForeignChainAliasTreasuryAccount::<[u8; 32]>::convert_location( | ||
| ¶_to_para_treasury_location, | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert_eq!( | ||
| [ | ||
| 202, 52, 249, 30, 7, 99, 135, 128, 153, 139, 176, 141, 138, 234, 163, 150, 7, 36, | ||
| 204, 92, 220, 137, 87, 57, 73, 91, 243, 189, 245, 200, 217, 204 | ||
| ], | ||
| actual_description | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn local_account_convert_on_para_from_relay_treasury() { | ||
| let location = MultiLocation { | ||
| parents: 0, | ||
| interior: X1(Plurality { id: BodyId::Treasury, part: BodyPart::Voice }), | ||
| }; | ||
|
|
||
| parameter_types! { | ||
| pub TreasuryAccountId: AccountId = AccountId::new([42u8; 32]); | ||
| } | ||
|
|
||
| let actual_description = | ||
| LocalTreasuryVoiceConvertsVia::<TreasuryAccountId, [u8; 32]>::convert_location( | ||
| &location, | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert_eq!( | ||
| [ | ||
| 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, | ||
| 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42 | ||
| ], | ||
| actual_description | ||
| ); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.