Skip to content

Commit

Permalink
Set migration user to Multilocation
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Jun 26, 2024
1 parent 1edc79b commit 1b1c897
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pallets/funding/src/functions/6_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ impl<T: Config> Pallet<T> {
vesting_time: BlockNumberFor<T>,
) -> DispatchResult {
UserMigrations::<T>::try_mutate(project_id, origin, |maybe_migrations| -> DispatchResult {
let migration_origin =
MigrationOrigin { user: T::AccountId32Conversion::convert(origin.clone()), id, participation_type };
let multilocation_user = (AccountId32 { network: None, id: T::AccountId32Conversion::convert(origin.clone()) }).into();
let migration_origin = MigrationOrigin { user: multilocation_user, id, participation_type };
let vesting_time: u64 = vesting_time.try_into().map_err(|_| Error::<T>::BadMath)?;
let migration_info: MigrationInfo = (ct_amount.into(), vesting_time.into()).into();
let migration = Migration::new(migration_origin, migration_info);
Expand Down
3 changes: 2 additions & 1 deletion pallets/funding/src/instantiator/chain_interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pallets/polimec-receiver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions pallets/polimec-receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::latest::{Junction::AccountId32, Junctions::X1, MultiLocation};

type MomentOf<T> = <<T as Config>::Vesting as VestingSchedule<<T as frame_system::Config>::AccountId>>::Moment;

Expand All @@ -57,11 +58,10 @@ pub mod pallet {

#[pallet::storage]
#[pallet::getter(fn something)]
// pub type ExecutedMigrations<T> = StorageNMap<_, BoundedVec<MigrationOrigin, T::MaxMigrations>>;
pub type ExecutedMigrations<T> = StorageNMap<
_,
(
NMapKey<Blake2_128Concat, [u8; 32]>,
NMapKey<Blake2_128Concat, xcm::latest::MultiLocation>,
NMapKey<Blake2_128Concat, ParticipationType>,
NMapKey<Blake2_128Concat, u32>,
),
Expand Down Expand Up @@ -109,19 +109,23 @@ pub mod pallet {
..
} in migrations.clone().inner()
{
let user_32 = match user {
MultiLocation { parents: 0, interior: X1(AccountId32 { network: _, id }) } => Ok(id),
_ => Err(Error::<T>::NoneValue),
}?;
let already_executed = ExecutedMigrations::<T>::get((user, participation_type, id));
if already_executed {
Self::deposit_event(Event::DuplicatedMigrationSkipped { migration });
continue;
}
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(),
Expand Down
3 changes: 2 additions & 1 deletion polimec-common/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ pub trait ReleaseSchedule<AccountId, Reason> {

pub mod migration_types {
use super::*;
use xcm::latest::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,
}
Expand Down

0 comments on commit 1b1c897

Please sign in to comment.