Skip to content
Merged
Show file tree
Hide file tree
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 Sep 7, 2023
0cb9bd8
fix for feature-propagation test
samelamin Sep 7, 2023
6950232
fix for fmt-manifest
samelamin Sep 7, 2023
6edfe8c
Update polkadot/runtime/kusama/src/xcm_config.rs
samelamin Sep 7, 2023
1c39018
pr comments
samelamin Sep 7, 2023
cd1a317
remove treasury match from AccountId32Aliases
samelamin Sep 7, 2023
92c19e4
Use TreasuryAccount: Get<AccountId>
samelamin Sep 8, 2023
bc47444
fix for failing builds
samelamin Sep 8, 2023
b0a32df
Update polkadot/runtime/kusama/src/xcm_config.rs
samelamin Sep 12, 2023
fd36d62
PR comments
samelamin Sep 12, 2023
8967478
remove unused variable
samelamin Sep 13, 2023
0900cf6
second round of comments
samelamin Sep 14, 2023
97919f2
Standardize DescribeLocation usage
franciscoaguirre Sep 14, 2023
a20fcf6
build fixes
samelamin Sep 15, 2023
d692513
Merge branch 'master' into allow_treasury_to_send_xcm
samelamin Sep 29, 2023
c43e583
fmt
samelamin Sep 29, 2023
b0bb2b5
Merge branch 'master' into allow_treasury_to_send_xcm
franciscoaguirre Sep 29, 2023
3ed9509
pr comment: rename variable
samelamin Oct 9, 2023
b666a1c
Update polkadot/xcm/xcm-builder/src/location_conversion.rs
samelamin Oct 9, 2023
25da765
Merge branch 'master' into allow_treasury_to_send_xcm
bkchr Oct 9, 2023
6410078
Update polkadot/xcm/xcm-builder/src/location_conversion.rs
samelamin Oct 9, 2023
4ae6087
Update polkadot/xcm/xcm-builder/src/location_conversion.rs
samelamin Oct 9, 2023
920b3ea
Update polkadot/xcm/xcm-builder/src/location_conversion.rs
samelamin Oct 9, 2023
cc1fbc5
pr comments
samelamin Oct 9, 2023
7ce71d1
remove from setup
samelamin Oct 9, 2023
20abdf0
pr comments
samelamin Oct 10, 2023
558e585
add para to para treasury test
samelamin Oct 10, 2023
8d478b9
Merge branch 'master' into allow_treasury_to_send_xcm
samelamin Oct 10, 2023
4de166a
add DescribeTreasuryVoiceTerminal to imports
samelamin Oct 10, 2023
5a42734
revert imports
samelamin Oct 10, 2023
aee64f5
Merge branch 'master' into allow_treasury_to_send_xcm
samelamin Oct 10, 2023
28b4f9e
Merge branch 'master' into allow_treasury_to_send_xcm
samelamin Oct 11, 2023
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
6 changes: 3 additions & 3 deletions polkadot/xcm/xcm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pub use location_conversion::{
Account32Hash, AccountId32Aliases, AccountKey20Aliases, AliasesIntoAccountId32,
ChildParachainConvertsVia, DescribeAccountId32Terminal, DescribeAccountIdTerminal,
DescribeAccountKey20Terminal, DescribeAllTerminal, DescribeBodyTerminal, DescribeFamily,
DescribeLocation, DescribePalletTerminal, DescribeTerminus, GlobalConsensusConvertsFor,
GlobalConsensusParachainConvertsFor, HashedDescription, ParentIsPreset,
SiblingParachainConvertsVia,
DescribeLocation, DescribePalletTerminal, DescribeTerminus, DescribeTreasuryVoiceTerminal,
GlobalConsensusConvertsFor, GlobalConsensusParachainConvertsFor, HashedDescription,
LocalTreasuryVoiceConvertsVia, ParentIsPreset, SiblingParachainConvertsVia,
};

mod origin_conversion;
Expand Down
105 changes: 104 additions & 1 deletion polkadot/xcm/xcm-builder/src/location_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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;
Expand All @@ -101,6 +115,7 @@ pub type DescribeAllTerminal = (
DescribePalletTerminal,
DescribeAccountId32Terminal,
DescribeAccountKey20Terminal,
DescribeTreasuryVoiceTerminal,
DescribeBodyTerminal,
);

Expand Down Expand Up @@ -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>(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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`.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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(
&para_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
);
}
}