Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@

// Substrate
use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId;
use frame_support::PalletId;
use grandpa::AuthorityId as GrandpaId;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::{sr25519, storage::Storage, Pair, Public};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
traits::{AccountIdConversion, IdentifyAccount, Verify},
BuildStorage, MultiSignature, Perbill,
};

// Cumulus
use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance, BlockNumber};
use polkadot_primitives::{AssignmentId, ValidatorId};
Expand Down Expand Up @@ -70,6 +70,10 @@ pub mod accounts {
pub const FERDIE_STASH: &str = "Ferdie//stash";
pub const FERDIE_BEEFY: &str = "Ferdie//stash";

pub fn get_treasury_address() -> AccountId {
PalletId(*b"py/trsry").into_account_truncating()
Comment thread
samelamin marked this conversation as resolved.
Outdated
}

pub fn init_balances() -> Vec<AccountId> {
vec![
get_account_id_from_seed::<sr25519::Public>(ALICE),
Expand All @@ -84,6 +88,7 @@ pub mod accounts {
get_account_id_from_seed::<sr25519::Public>(DAVE_STASH),
get_account_id_from_seed::<sr25519::Public>(EVE_STASH),
get_account_id_from_seed::<sr25519::Public>(FERDIE_STASH),
get_treasury_address(),
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/xcm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub use location_conversion::{
ChildParachainConvertsVia, DescribeAccountId32Terminal, DescribeAccountIdTerminal,
DescribeAccountKey20Terminal, DescribeAllTerminal, DescribeBodyTerminal, DescribeFamily,
Comment thread
samelamin marked this conversation as resolved.
DescribeLocation, DescribePalletTerminal, DescribeTerminus, GlobalConsensusConvertsFor,
GlobalConsensusParachainConvertsFor, HashedDescription, ParentIsPreset,
SiblingParachainConvertsVia,
GlobalConsensusParachainConvertsFor, HashedDescription, LocalTreasuryVoiceConvertsVia,
ParentIsPreset, SiblingParachainConvertsVia,
};

mod origin_conversion;
Expand Down
55 changes: 55 additions & 0 deletions 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(("Treasury").encode()),
Comment thread
samelamin marked this conversation as resolved.
Outdated
_ => return None,
Comment thread
samelamin marked this conversation as resolved.
Outdated
}
}
}

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> {
let id: [u8; 32] = match *location {
Comment thread
samelamin marked this conversation as resolved.
Outdated
MultiLocation {
Comment thread
samelamin marked this conversation as resolved.
Outdated
parents: 0,
interior: X1(Plurality { id: BodyId::Treasury, part: BodyPart::Voice }),
} => TreasuryAccount::get().into(),
_ => return None,
};
Some(id.into())
}
}

/// 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 @@ -446,6 +480,9 @@ mod tests {
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,22 @@ mod tests {
};
assert!(ForeignChainAliasAccount::<[u8; 32]>::convert_location(&mul).is_none());
}

#[test]
fn remote_account_convert_on_para_sending_relay_treasury() {

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.

probably I am missing some context here, I can understand remote_account_convert_on_para - that this converter will be used as a part of LocationToAccountId converter on parachain,
but what does exactly mean sending_relay_treasury?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a badly named test i think, but its meant to be remote treasury on a parachain to another parachain

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.

hmm, because from the parachain's point of view this:

        MultiLocation {
			parents: 1,
			interior: X1(Plurality { id: BodyId::Treasury, part: BodyPart::Voice }),
		};

represents Plurality-Treasury-Voice location on relay chain (because parents: 1).

From the parachain's point-of-view a relay chain plurality looks like:

MultiLocation { parents: 1, interior: X1(Plurality { .. }

From the parachain's point-of-view an other parachain plurality looks like:

MultiLocation { parents: 1, interior: X2(Parachain(other_parachain_para_id), Plurality { .. }

So I would suggest to cover at least these two case in this test, to be sure that it works as expected.
Ideally, it should maybe cover more cases:
DescribeTreasuryVoiceTerminal is deployed on relay chain and local treasury location.
DescribeTreasuryVoiceTerminal is deployed on relay chain and parachain treasury location? (not sure about this case)
DescribeTreasuryVoiceTerminal is deployed on parachain and local treasury location.
DescribeTreasuryVoiceTerminal is deployed on parachain and relay chain treasury location.
DescribeTreasuryVoiceTerminal is deployed on parachain and other parachain treasury location.

(but as I said, I dont have full context here)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bkontur thanks for this, I've renamed the tests and added another test to cover the para to para treasury conversion

I think the DescribeFamily covers all the other cases but please correct me if I am mistaken.

let location = MultiLocation {
parents: 1,
interior: X1(Plurality { id: BodyId::Treasury, part: BodyPart::Voice }),
};
let actual_description =
ForeignChainAliasTreasuryAccount::<[u8; 32]>::convert_location(&location).unwrap();

assert_eq!(
[
103, 157, 82, 57, 235, 216, 82, 162, 31, 148, 162, 21, 44, 34, 218, 173, 202, 123,
235, 14, 186, 214, 16, 211, 10, 13, 72, 194, 254, 71, 87, 96
],
actual_description
);
}
}