From b1225218bfc03675a8b21e1106166cc86443f5e4 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Tue, 25 Jun 2024 11:19:00 +0200 Subject: [PATCH] Set migration user to Multilocation --- Cargo.lock | 1 + pallets/funding/src/functions/6_settlement.rs | 7 +++++-- .../funding/src/instantiator/chain_interactions.rs | 3 ++- pallets/polimec-receiver/Cargo.toml | 1 + pallets/polimec-receiver/src/lib.rs | 12 ++++++++---- polimec-common/common/src/lib.rs | 3 ++- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3f7d1b7d5..42d1488a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8458,6 +8458,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", + "staging-xcm", ] [[package]] diff --git a/pallets/funding/src/functions/6_settlement.rs b/pallets/funding/src/functions/6_settlement.rs index 9943b1ed9..524846841 100644 --- a/pallets/funding/src/functions/6_settlement.rs +++ b/pallets/funding/src/functions/6_settlement.rs @@ -448,8 +448,11 @@ impl Pallet { vesting_time: BlockNumberFor, ) -> DispatchResult { UserMigrations::::try_mutate(project_id, origin, |maybe_migrations| -> DispatchResult { - let migration_origin = - MigrationOrigin { user: T::AccountId32Conversion::convert(origin.clone()), id, participation_type }; + let multilocation_user = MultiLocation::new( + 0, + X1(AccountId32 { network: None, id: T::AccountId32Conversion::convert(origin.clone()) }), + ); + let migration_origin = MigrationOrigin { user: multilocation_user, id, participation_type }; let vesting_time: u64 = vesting_time.try_into().map_err(|_| Error::::BadMath)?; let migration_info: MigrationInfo = (ct_amount.into(), vesting_time.into()).into(); let migration = Migration::new(migration_origin, migration_info); diff --git a/pallets/funding/src/instantiator/chain_interactions.rs b/pallets/funding/src/instantiator/chain_interactions.rs index 4d2e283d8..1ec1182e2 100644 --- a/pallets/funding/src/instantiator/chain_interactions.rs +++ b/pallets/funding/src/instantiator/chain_interactions.rs @@ -917,7 +917,8 @@ impl< (_, Some((_, migrations))) => { let maybe_migration = migrations.into_iter().find(|migration| { let user = T::AccountId32Conversion::convert(account.clone()); - matches!(migration.origin, MigrationOrigin { user: m_user, id: m_id, participation_type: m_participation_type } if m_user == user && m_id == id && m_participation_type == participation_type) + let multilocation_user = MultiLocation{parents: 0, interior: X1(AccountId32 {network: None, id: user})}; + matches!(migration.origin, MigrationOrigin { user: m_user, id: m_id, participation_type: m_participation_type } if m_user == multilocation_user && m_id == id && m_participation_type == participation_type) }); match maybe_migration { // Migration exists so we check if the amount is correct and if it should exist diff --git a/pallets/polimec-receiver/Cargo.toml b/pallets/polimec-receiver/Cargo.toml index b09904b3c..aca3e8dee 100644 --- a/pallets/polimec-receiver/Cargo.toml +++ b/pallets/polimec-receiver/Cargo.toml @@ -25,6 +25,7 @@ cumulus-pallet-xcm.workspace = true polkadot-parachain-primitives.workspace = true polimec-common.workspace = true sp-runtime.workspace = true +xcm.workspace = true [dev-dependencies] serde.workspace = true diff --git a/pallets/polimec-receiver/src/lib.rs b/pallets/polimec-receiver/src/lib.rs index ea5e79c4b..54f32ecae 100644 --- a/pallets/polimec-receiver/src/lib.rs +++ b/pallets/polimec-receiver/src/lib.rs @@ -31,6 +31,7 @@ pub mod pallet { use polkadot_parachain_primitives::primitives::{Id as ParaId, Sibling}; use sp_runtime::traits::{AccountIdConversion, Convert}; use sp_std::prelude::*; + use xcm::v3::{Junction::AccountId32, Junctions::X1, MultiLocation}; type MomentOf = <::Vesting as VestingSchedule<::AccountId>>::Moment; @@ -57,11 +58,10 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn something)] - // pub type ExecutedMigrations = StorageNMap<_, BoundedVec>; pub type ExecutedMigrations = StorageNMap< _, ( - NMapKey, + NMapKey, NMapKey, NMapKey, ), @@ -109,6 +109,10 @@ pub mod pallet { .. } in migrations.clone().inner() { + let user_32 = match user { + MultiLocation { parents: 0, interior: X1(AccountId32 { network: _, id }) } => Ok(id), + _ => Err(Error::::NoneValue), + }?; let already_executed = ExecutedMigrations::::get((user, participation_type, id)); if already_executed { Self::deposit_event(Event::DuplicatedMigrationSkipped { migration }); @@ -116,12 +120,12 @@ pub mod pallet { } T::Balances::transfer( &polimec_soverign_account, - &user.into(), + &user_32.into(), contribution_token_amount.into(), KeepAlive, )?; T::Vesting::add_vesting_schedule( - &user.into(), + &user_32.into(), contribution_token_amount.into(), T::MigrationInfoToPerBlockBalance::convert(migration.info.clone()), T::GenesisMoment::get(), diff --git a/polimec-common/common/src/lib.rs b/polimec-common/common/src/lib.rs index f4a8fb0de..188614437 100644 --- a/polimec-common/common/src/lib.rs +++ b/polimec-common/common/src/lib.rs @@ -101,10 +101,11 @@ pub trait ReleaseSchedule { pub mod migration_types { use super::*; + use xcm::v3::MultiLocation; #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct MigrationOrigin { - pub user: [u8; 32], + pub user: MultiLocation, pub id: u32, pub participation_type: ParticipationType, }