Skip to content

Commit

Permalink
Revert "Add multication to currency data (#346)" (#348)
Browse files Browse the repository at this point in the history
This reverts commit 4026994.
  • Loading branch information
imstar15 authored Apr 13, 2023
1 parent 8c23cb7 commit 7d44984
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 218 deletions.
5 changes: 1 addition & 4 deletions node/src/chain_spec/neumann.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ use crate::chain_spec::{
get_account_id_from_seed, get_collator_keys_from_seed, inflation_config, DummyChainSpec,
Extensions,
};
use codec::Encode;
use common_runtime::constants::currency::{DOLLAR, TOKEN_DECIMALS};
use neumann_runtime::{
CouncilConfig, PolkadotXcmConfig, SudoConfig, TechnicalMembershipConfig, ValveConfig,
VestingConfig, XcmpHandlerConfig,
};
use pallet_xcmp_handler::XcmFlow;
use primitives::{AccountId, AuraId, Balance, TokenId};
use xcm::VersionedMultiLocation;

static TOKEN_SYMBOL: &str = "NEU";
const SS_58_FORMAT: u32 = 51;
Expand Down Expand Up @@ -102,7 +100,6 @@ pub fn development_config() -> ChainSpec {
419_000_000_000,
1_000_000_000,
XcmFlow::Normal,
Option::<VersionedMultiLocation>::encode(&None),
)],
)
},
Expand Down Expand Up @@ -317,7 +314,7 @@ fn testnet_genesis(
vesting_schedule: Vec<(u64, Vec<(AccountId, Balance)>)>,
general_councils: Vec<AccountId>,
technical_memberships: Vec<AccountId>,
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow, Vec<u8>)>,
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow)>,
) -> neumann_runtime::GenesisConfig {
neumann_runtime::GenesisConfig {
system: neumann_runtime::SystemConfig {
Expand Down
5 changes: 1 addition & 4 deletions node/src/chain_spec/oak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ use crate::chain_spec::{
test::{validate_allocation, validate_vesting},
Extensions,
};
use codec::Encode;
use common_runtime::constants::currency::{DOLLAR, EXISTENTIAL_DEPOSIT, TOKEN_DECIMALS};
use oak_runtime::{
CouncilConfig, PolkadotXcmConfig, SudoConfig, TechnicalMembershipConfig, ValveConfig,
VestingConfig, XcmpHandlerConfig,
};
use pallet_xcmp_handler::XcmFlow;
use primitives::{AccountId, AuraId, Balance, TokenId};
use xcm::VersionedMultiLocation;

const TOKEN_SYMBOL: &str = "OAK";
const SS_58_FORMAT: u32 = 51;
Expand Down Expand Up @@ -96,7 +94,6 @@ pub fn oak_development_config() -> ChainSpec {
419_000_000_000,
1_000_000_000,
XcmFlow::Normal,
Option::<VersionedMultiLocation>::encode(&None),
)],
)
},
Expand Down Expand Up @@ -355,7 +352,7 @@ fn testnet_genesis(
vesting_schedule: Vec<(u64, Vec<(AccountId, Balance)>)>,
general_councils: Vec<AccountId>,
technical_memberships: Vec<AccountId>,
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow, Vec<u8>)>,
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow)>,
) -> oak_runtime::GenesisConfig {
let candidate_stake =
std::cmp::max(oak_runtime::MinCollatorStk::get(), oak_runtime::MinCandidateStk::get());
Expand Down
9 changes: 1 addition & 8 deletions node/src/chain_spec/turing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use xcm::{
latest::prelude::{X1, X2},
opaque::latest::{Junctions::Here, MultiLocation},
v1::Junction::{PalletInstance, Parachain},
VersionedMultiLocation,
VersionedMultiLocation::V1,
};

Expand Down Expand Up @@ -97,7 +96,6 @@ pub fn turing_development_config() -> ChainSpec {
419_000_000_000,
1_000_000_000,
XcmFlow::Normal,
Option::<VersionedMultiLocation>::encode(&None),
),
(
2110,
Expand All @@ -106,7 +104,6 @@ pub fn turing_development_config() -> ChainSpec {
5_376_000_000_000,
1_000_000_000,
XcmFlow::Normal,
Option::<VersionedMultiLocation>::encode(&None),
),
(
2000,
Expand All @@ -115,7 +112,6 @@ pub fn turing_development_config() -> ChainSpec {
10_000_000_000_000_000_000,
1_000_000_000,
XcmFlow::Alternate,
Option::<VersionedMultiLocation>::encode(&None),
),
(
1000,
Expand All @@ -124,9 +120,6 @@ pub fn turing_development_config() -> ChainSpec {
10_000_000_000_000_000_000,
1_000_000_000,
XcmFlow::Alternate,
Option::<VersionedMultiLocation>::encode(&Some(
MultiLocation::new(0, X1(PalletInstance(3))).into(),
)),
),
],
vec![
Expand Down Expand Up @@ -244,7 +237,7 @@ fn testnet_genesis(
vesting_schedule: Vec<(u64, Vec<(AccountId, Balance)>)>,
general_councils: Vec<AccountId>,
technical_memberships: Vec<AccountId>,
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow, Vec<u8>)>,
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow)>,
additional_assets: Vec<(TokenId, Vec<u8>)>,
) -> turing_runtime::GenesisConfig {
let candidate_stake = std::cmp::max(
Expand Down
4 changes: 2 additions & 2 deletions pallets/xcmp-handler/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ benchmarks! {
let currency_id = T::GetNativeCurrencyId::get();
let para_id: u32 = 1000;
let xcm_data =
XcmCurrencyData { native: false, fee_per_second: 100, instruction_weight: 1_000, flow: XcmFlow::Normal, location: None };
XcmCurrencyData { native: false, fee_per_second: 100, instruction_weight: 1_000, flow: XcmFlow::Normal };

}: add_chain_currency_data(RawOrigin::Root, para_id, currency_id, xcm_data.clone())
verify {
Expand All @@ -39,7 +39,7 @@ benchmarks! {
let currency_id = T::GetNativeCurrencyId::get();
let para_id: u32 = 1000;
let xcm_data =
XcmCurrencyData { native: false, fee_per_second: 100, instruction_weight: 1_000, flow: XcmFlow::Normal, location: None };
XcmCurrencyData { native: false, fee_per_second: 100, instruction_weight: 1_000, flow: XcmFlow::Normal };
XcmChainCurrencyData::<T>::insert(para_id, currency_id, xcm_data);

}: remove_chain_currency_data(RawOrigin::Root, para_id, currency_id)
Expand Down
70 changes: 25 additions & 45 deletions pallets/xcmp-handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub mod pallet {
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::{AccountIdConversion, Convert, SaturatedConversion};
use sp_std::prelude::*;
use xcm::{latest::prelude::*, VersionedMultiLocation};
use xcm::latest::prelude::*;
use xcm_executor::traits::{InvertLocation, WeightBounds};

type ParachainId = u32;
Expand Down Expand Up @@ -157,13 +157,11 @@ pub mod pallet {
ErrorGettingCallWeight,
/// Currency not supported
CurrencyNotSupported,
/// The version of the `VersionedMultiLocation` value used is not able
/// to be interpreted.
BadVersion,
}

/// Stores all data needed to send an XCM message for chain/currency pair.
#[derive(Clone, Debug, Encode, Decode, PartialEq, TypeInfo)]
#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct XcmCurrencyData {
/// Is the token native to the chain?
pub native: bool,
Expand All @@ -172,7 +170,6 @@ pub mod pallet {
pub instruction_weight: u64,
/// The desired instruction flow for the target chain
pub flow: XcmFlow,
pub location: Option<VersionedMultiLocation>,
}

/// Stores XCM data for a chain/currency pair.
Expand Down Expand Up @@ -237,10 +234,8 @@ pub mod pallet {
let xcm_data = XcmChainCurrencyData::<T>::get(para_id, currency_id)
.ok_or(Error::<T>::CurrencyChainComboNotFound)?;

let (_, target_instructions) =
Self::xcm_instruction_skeleton(para_id, xcm_data.clone())?;
let (_, target_instructions) = Self::xcm_instruction_skeleton(para_id, xcm_data)?;
let weight = xcm_data
.clone()
.instruction_weight
.checked_mul(target_instructions.len() as u64)
.ok_or(Error::<T>::WeightOverflow)?
Expand Down Expand Up @@ -286,29 +281,21 @@ pub mod pallet {
.try_into()
.map_err(|_| Error::<T>::FailedMultiLocationToJunction)?;

let location = match xcm_data.location {
Some(loc) => loc.clone().try_into().map_err(|()| Error::<T>::BadVersion)?,
_ => MultiLocation::new(0, Here),
};

let target_asset =
MultiAsset { id: Concrete(location), fun: Fungibility::Fungible(fee) };

let instructions = match xcm_data.flow {
XcmFlow::Normal => Self::get_local_currency_instructions(
para_id,
target_asset,
descend_location,
transact_encoded_call,
transact_encoded_call_weight,
weight,
fee,
)?,
XcmFlow::Alternate => Self::get_alternate_flow_instructions(
target_asset,
descend_location,
transact_encoded_call,
transact_encoded_call_weight,
weight,
fee,
)?,
};

Expand All @@ -330,15 +317,21 @@ pub mod pallet {
/// - DepositAsset
pub fn get_local_currency_instructions(
para_id: ParachainId,
local_asset: MultiAsset,
descend_location: Junctions,
transact_encoded_call: Vec<u8>,
transact_encoded_call_weight: u64,
xcm_weight: u64,
fee: u128,
) -> Result<
(xcm::latest::Xcm<<T as pallet::Config>::Call>, xcm::latest::Xcm<()>),
DispatchError,
> {
// XCM for local chain
let local_asset = MultiAsset {
id: Concrete(MultiLocation::new(0, Here)),
fun: Fungibility::Fungible(fee),
};

let local_xcm = Xcm(vec![
WithdrawAsset::<<T as pallet::Config>::Call>(local_asset.clone().into()),
DepositAsset::<<T as pallet::Config>::Call> {
Expand Down Expand Up @@ -391,15 +384,21 @@ pub mod pallet {
/// - RefundSurplus
/// - DepositAsset
fn get_alternate_flow_instructions(
target_asset: MultiAsset,
descend_location: Junctions,
transact_encoded_call: Vec<u8>,
transact_encoded_call_weight: u64,
xcm_weight: u64,
fee: u128,
) -> Result<
(xcm::latest::Xcm<<T as pallet::Config>::Call>, xcm::latest::Xcm<()>),
DispatchError,
> {
// Default to native currency of target chain
let target_asset = MultiAsset {
id: Concrete(MultiLocation::new(0, Here)),
fun: Fungibility::Fungible(fee),
};

let target_xcm = Xcm(vec![
DescendOrigin::<()>(descend_location.clone()),
WithdrawAsset::<()>(target_asset.clone().into()),
Expand Down Expand Up @@ -540,37 +539,29 @@ pub mod pallet {
.try_into()
.map_err(|_| Error::<T>::FailedMultiLocationToJunction)?;

let location = match xcm_data.location {
Some(loc) => loc.clone().try_into().map_err(|()| Error::<T>::BadVersion)?,
_ => MultiLocation::new(0, Here),
};

let target_asset =
MultiAsset { id: Concrete(location), fun: Fungibility::Fungible(0u128) };

match xcm_data.flow {
XcmFlow::Normal => Self::get_local_currency_instructions(
para_id,
target_asset,
nobody,
Default::default(),
0u64,
0u64,
0u128,
),
XcmFlow::Alternate => Self::get_alternate_flow_instructions(
target_asset,
nobody,
Default::default(),
0u64,
0u64,
0u128,
),
}
}
}

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub chain_data: Vec<(u32, T::CurrencyId, bool, u128, u64, XcmFlow, Vec<u8>)>,
pub chain_data: Vec<(u32, T::CurrencyId, bool, u128, u64, XcmFlow)>,
}

#[cfg(feature = "std")]
Expand All @@ -583,18 +574,9 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
for (
para_id,
currency_id,
native,
fee_per_second,
instruction_weight,
flow,
location_encoded,
) in self.chain_data.iter()
for (para_id, currency_id, native, fee_per_second, instruction_weight, flow) in
self.chain_data.iter()
{
let location = Option::<VersionedMultiLocation>::decode(&mut &location_encoded[..])
.expect("Error decoding VersionedMultiLocation");
XcmChainCurrencyData::<T>::insert(
para_id,
currency_id,
Expand All @@ -603,7 +585,6 @@ pub mod pallet {
fee_per_second: *fee_per_second,
instruction_weight: *instruction_weight,
flow: *flow,
location,
},
);
}
Expand Down Expand Up @@ -688,7 +669,6 @@ impl<T: Config> XcmpTransactor<T::AccountId, T::CurrencyId> for Pallet<T> {
fee_per_second: 416_000_000_000,
instruction_weight: 600_000_000,
flow: XcmFlow::Normal,
location: None,
};

XcmChainCurrencyData::<T>::insert(para_id, currency_id, xcm_data);
Expand Down
Loading

0 comments on commit 7d44984

Please sign in to comment.