Skip to content
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

Set migration user to Multilocation #338

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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.

2 changes: 1 addition & 1 deletion chain-specs/paseo/polimec-paseo.genesis.state
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x0000000000000000000000000000000000000000000000000000000000000000003e577f4d515d83e76679dee1ef5f4bb909dfdf89a2c706996ff1bedcfa3d405903170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
0x000000000000000000000000000000000000000000000000000000000000000000f14253e01290511c5c35fcdf2b61898534af6f9d30f7d867dcec6f4f9d2f87ca03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
2 changes: 1 addition & 1 deletion chain-specs/paseo/polimec-paseo.genesis.wasm

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion chain-specs/paseo/polimec-paseo.spec.plain.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions chain-specs/paseo/polimec-paseo.spec.raw.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion nodes/parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
// Original live Polimec runtimes
"polimec" => Box::new(chain_spec::common::ChainSpec::from_json_bytes(polimec_chain_spec)?),
"rolimec" => Box::new(chain_spec::common::ChainSpec::from_json_bytes(rolimec_chain_spec)?),
"polimec-paseo" => Box::new(chain_spec::common::ChainSpec::from_json_bytes(polimec_paseo_spec)?),
// "polimec-paseo" => Box::new(chain_spec::common::ChainSpec::from_json_bytes(polimec_paseo_spec)?),
"polimec-paseo" => Box::new(chain_spec::polimec_paseo::get_live_chain_spec()),

// Testing runtimes
"polimec-paseo-local" => Box::new(chain_spec::polimec_paseo::get_local_chain_spec()),
Expand Down
7 changes: 5 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,11 @@ 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 = MultiLocation::new(
0,
X1(AccountId32 { network: None, id: T::AccountId32Conversion::convert(origin.clone()) }),
);
JuaniRios marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion scripts/zombienet/polimec-paseo-local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ chain_spec_path = "./scripts/zombienet/relay-chain-specs/paseo-local.plain.json"

[[parachains]]
id = 3344
chain = "polimec-paseo-local"
chain = "polimec-paseo"

[[parachains.collators]]
name = "collator1"
Expand Down