Skip to content

Commit

Permalink
fix: Changes in rings pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
arrudagates committed Jan 17, 2024
1 parent 652247a commit d83e956
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 46 deletions.
5 changes: 3 additions & 2 deletions INV4/pallet-inv4/src/account_derivation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{Config, Pallet};
use codec::{Compact, Encode};
use frame_support::traits::Get;
use sp_io::hashing::blake2_256;
use xcm::latest::{BodyId, BodyPart, Junction, Junctions};

Expand All @@ -20,7 +21,7 @@ where
blake2_256(
&(
b"SiblingChain",
Compact::<u32>::from(T::PARA_ID),
Compact::<u32>::from(T::ParaId::get()),
(b"Body", BodyId::Index(core_id.into()), BodyPart::Voice).encode(),
)
.encode(),
Expand All @@ -31,7 +32,7 @@ where
fn core_location(core_id: T::CoreId) -> Junctions {
// Core location is defined as a plurality within the parachain.
Junctions::X2(
Junction::Parachain(T::PARA_ID),
Junction::Parachain(T::ParaId::get()),
Junction::Plurality {
id: BodyId::Index(core_id.into()),
part: BodyPart::Voice,
Expand Down
6 changes: 1 addition & 5 deletions INV4/pallet-inv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pub mod pallet {
Perbill,
};
use sp_std::{boxed::Box, convert::TryInto, vec::Vec};
use xcm::latest::NetworkId;

pub use super::{inv4_core, multisig};

Expand Down Expand Up @@ -160,11 +159,8 @@ pub mod pallet {
/// Implementation of the fee handler for both core creation fee and multisig call fees
type FeeCharger: MultisigFeeHandler<Self>;

/// NetworkId for the absolute location of global consensus system, to be used for deriving the core account id
const GLOBAL_NETWORK_ID: NetworkId;

/// ParaId of the parachain, to be used for deriving the core account id
const PARA_ID: u32;
type ParaId: Get<u32>;

/// Maximum size of a multisig proposal call
#[pallet::constant]
Expand Down
4 changes: 1 addition & 3 deletions INV4/pallet-inv4/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use scale_info::TypeInfo;
use sp_core::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};
use sp_std::{convert::TryInto, vec};
use xcm::latest::NetworkId;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand Down Expand Up @@ -331,8 +330,7 @@ impl pallet::Config for Test {

type MaxCallSize = MaxCallSize;

const GLOBAL_NETWORK_ID: NetworkId = NetworkId::Kusama;
const PARA_ID: u32 = 2125;
type ParaId = ConstU32<2125>;
}

pub struct ExtBuilder;
Expand Down
4 changes: 1 addition & 3 deletions OCIF/staking/src/testing/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
AccountId32, Perbill,
};
use xcm::latest::NetworkId;

pub(crate) type AccountId = AccountId32;
pub(crate) type BlockNumber = u64;
Expand Down Expand Up @@ -247,8 +246,7 @@ impl pallet_inv4::Config for Test {
type KSMCoreCreationFee = CoreCreationFee;
type MaxCallSize = ConstU32<51200>;

const GLOBAL_NETWORK_ID: NetworkId = NetworkId::Kusama;
const PARA_ID: u32 = 2125;
type ParaId = ConstU32<2125>;
}

impl pallet_ocif_staking::Config for Test {
Expand Down
43 changes: 12 additions & 31 deletions pallet-rings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ pub mod pallet {
let fee_asset_location = fee_asset.get_asset_location();

let beneficiary: MultiLocation = MultiLocation {
parents: 0,
interior: Junctions::X3(
Junction::GlobalConsensus(<T as pallet_inv4::Config>::GLOBAL_NETWORK_ID),
Junction::Parachain(<T as pallet_inv4::Config>::PARA_ID),
parents: 1,
interior: Junctions::X2(
Junction::Parachain(<T as pallet_inv4::Config>::ParaId::get()),
descend_interior,
),
};
Expand All @@ -165,10 +164,6 @@ pub mod pallet {
};

let message = Xcm(vec![
Instruction::UniversalOrigin(Junction::GlobalConsensus(
<T as pallet_inv4::Config>::GLOBAL_NETWORK_ID,
)),
Instruction::DescendOrigin(descend_interior.into()),
Instruction::WithdrawAsset(fee_multiasset.clone().into()),
Instruction::BuyExecution {
fees: fee_multiasset,
Expand All @@ -186,7 +181,7 @@ pub mod pallet {
},
]);

pallet_xcm::Pallet::<T>::send_xcm(Junctions::Here, dest, message)
pallet_xcm::Pallet::<T>::send_xcm(descend_interior, dest, message)
.map_err(|_| Error::<T>::SendingFailed)?;

Self::deposit_event(Event::CallSent {
Expand Down Expand Up @@ -242,10 +237,9 @@ pub mod pallet {
};

let core_multilocation: MultiLocation = MultiLocation {
parents: 0,
interior: Junctions::X3(
Junction::GlobalConsensus(<T as pallet_inv4::Config>::GLOBAL_NETWORK_ID),
Junction::Parachain(<T as pallet_inv4::Config>::PARA_ID),
parents: 1,
interior: Junctions::X2(
Junction::Parachain(<T as pallet_inv4::Config>::ParaId::get()),
descend_interior,
),
};
Expand All @@ -256,10 +250,6 @@ pub mod pallet {
};

let message = Xcm(vec![
Instruction::UniversalOrigin(Junction::GlobalConsensus(
<T as pallet_inv4::Config>::GLOBAL_NETWORK_ID,
)),
Instruction::DescendOrigin(descend_interior.into()),
// Pay execution fees
Instruction::WithdrawAsset(fee_multiasset.clone().into()),
Instruction::BuyExecution {
Expand All @@ -279,7 +269,7 @@ pub mod pallet {
},
]);

pallet_xcm::Pallet::<T>::send_xcm(Junctions::Here, dest, message)
pallet_xcm::Pallet::<T>::send_xcm(descend_interior, dest, message)
.map_err(|_| Error::<T>::SendingFailed)?;

Self::deposit_event(Event::AssetsTransferred {
Expand Down Expand Up @@ -361,10 +351,9 @@ pub mod pallet {
.map_err(|_| Error::<T>::FailedToReanchorAsset)?;

let core_multilocation: MultiLocation = MultiLocation {
parents: 0,
interior: Junctions::X3(
Junction::GlobalConsensus(<T as pallet_inv4::Config>::GLOBAL_NETWORK_ID),
Junction::Parachain(<T as pallet_inv4::Config>::PARA_ID),
parents: 1,
interior: Junctions::X2(
Junction::Parachain(<T as pallet_inv4::Config>::ParaId::get()),
descend_interior,
),
};
Expand All @@ -382,10 +371,6 @@ pub mod pallet {

let message = if asset_location.starts_with(&dest) {
Xcm(vec![
Instruction::UniversalOrigin(Junction::GlobalConsensus(
<T as pallet_inv4::Config>::GLOBAL_NETWORK_ID,
)),
Instruction::DescendOrigin(descend_interior.into()),
WithdrawAsset(vec![fee_multiasset.clone(), multiasset.clone()].into()),
Instruction::BuyExecution {
fees: fee_multiasset,
Expand Down Expand Up @@ -418,10 +403,6 @@ pub mod pallet {
])
} else {
Xcm(vec![
Instruction::UniversalOrigin(Junction::GlobalConsensus(
<T as pallet_inv4::Config>::GLOBAL_NETWORK_ID,
)),
Instruction::DescendOrigin(descend_interior.into()),
// Pay execution fees
Instruction::WithdrawAsset(fee_multiasset.clone().into()),
Instruction::BuyExecution {
Expand Down Expand Up @@ -452,7 +433,7 @@ pub mod pallet {
])
};

pallet_xcm::Pallet::<T>::send_xcm(Junctions::Here, from_chain_location, message)
pallet_xcm::Pallet::<T>::send_xcm(descend_interior, from_chain_location, message)
.map_err(|_| Error::<T>::SendingFailed)?;

Self::deposit_event(Event::AssetsBridged {
Expand Down
3 changes: 1 addition & 2 deletions pallet-rings/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,7 @@ impl pallet_inv4::Config for Test {
type KSMCoreCreationFee = KSMCoreCreationFee;
type MaxCallSize = ConstU32<51200>;

const GLOBAL_NETWORK_ID: NetworkId = NetworkId::Kusama;
const PARA_ID: u32 = 2125;
type ParaId = ConstU32<2125>;
}

parameter_types! {
Expand Down

0 comments on commit d83e956

Please sign in to comment.