Skip to content

Commit 7d44984

Browse files
authored
Revert "Add multication to currency data (#346)" (#348)
This reverts commit 4026994.
1 parent 8c23cb7 commit 7d44984

File tree

10 files changed

+40
-218
lines changed

10 files changed

+40
-218
lines changed

node/src/chain_spec/neumann.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ use crate::chain_spec::{
1212
get_account_id_from_seed, get_collator_keys_from_seed, inflation_config, DummyChainSpec,
1313
Extensions,
1414
};
15-
use codec::Encode;
1615
use common_runtime::constants::currency::{DOLLAR, TOKEN_DECIMALS};
1716
use neumann_runtime::{
1817
CouncilConfig, PolkadotXcmConfig, SudoConfig, TechnicalMembershipConfig, ValveConfig,
1918
VestingConfig, XcmpHandlerConfig,
2019
};
2120
use pallet_xcmp_handler::XcmFlow;
2221
use primitives::{AccountId, AuraId, Balance, TokenId};
23-
use xcm::VersionedMultiLocation;
2422

2523
static TOKEN_SYMBOL: &str = "NEU";
2624
const SS_58_FORMAT: u32 = 51;
@@ -102,7 +100,6 @@ pub fn development_config() -> ChainSpec {
102100
419_000_000_000,
103101
1_000_000_000,
104102
XcmFlow::Normal,
105-
Option::<VersionedMultiLocation>::encode(&None),
106103
)],
107104
)
108105
},
@@ -317,7 +314,7 @@ fn testnet_genesis(
317314
vesting_schedule: Vec<(u64, Vec<(AccountId, Balance)>)>,
318315
general_councils: Vec<AccountId>,
319316
technical_memberships: Vec<AccountId>,
320-
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow, Vec<u8>)>,
317+
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow)>,
321318
) -> neumann_runtime::GenesisConfig {
322319
neumann_runtime::GenesisConfig {
323320
system: neumann_runtime::SystemConfig {

node/src/chain_spec/oak.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ use crate::chain_spec::{
1212
test::{validate_allocation, validate_vesting},
1313
Extensions,
1414
};
15-
use codec::Encode;
1615
use common_runtime::constants::currency::{DOLLAR, EXISTENTIAL_DEPOSIT, TOKEN_DECIMALS};
1716
use oak_runtime::{
1817
CouncilConfig, PolkadotXcmConfig, SudoConfig, TechnicalMembershipConfig, ValveConfig,
1918
VestingConfig, XcmpHandlerConfig,
2019
};
2120
use pallet_xcmp_handler::XcmFlow;
2221
use primitives::{AccountId, AuraId, Balance, TokenId};
23-
use xcm::VersionedMultiLocation;
2422

2523
const TOKEN_SYMBOL: &str = "OAK";
2624
const SS_58_FORMAT: u32 = 51;
@@ -96,7 +94,6 @@ pub fn oak_development_config() -> ChainSpec {
9694
419_000_000_000,
9795
1_000_000_000,
9896
XcmFlow::Normal,
99-
Option::<VersionedMultiLocation>::encode(&None),
10097
)],
10198
)
10299
},
@@ -355,7 +352,7 @@ fn testnet_genesis(
355352
vesting_schedule: Vec<(u64, Vec<(AccountId, Balance)>)>,
356353
general_councils: Vec<AccountId>,
357354
technical_memberships: Vec<AccountId>,
358-
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow, Vec<u8>)>,
355+
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow)>,
359356
) -> oak_runtime::GenesisConfig {
360357
let candidate_stake =
361358
std::cmp::max(oak_runtime::MinCollatorStk::get(), oak_runtime::MinCandidateStk::get());

node/src/chain_spec/turing.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use xcm::{
1919
latest::prelude::{X1, X2},
2020
opaque::latest::{Junctions::Here, MultiLocation},
2121
v1::Junction::{PalletInstance, Parachain},
22-
VersionedMultiLocation,
2322
VersionedMultiLocation::V1,
2423
};
2524

@@ -97,7 +96,6 @@ pub fn turing_development_config() -> ChainSpec {
9796
419_000_000_000,
9897
1_000_000_000,
9998
XcmFlow::Normal,
100-
Option::<VersionedMultiLocation>::encode(&None),
10199
),
102100
(
103101
2110,
@@ -106,7 +104,6 @@ pub fn turing_development_config() -> ChainSpec {
106104
5_376_000_000_000,
107105
1_000_000_000,
108106
XcmFlow::Normal,
109-
Option::<VersionedMultiLocation>::encode(&None),
110107
),
111108
(
112109
2000,
@@ -115,7 +112,6 @@ pub fn turing_development_config() -> ChainSpec {
115112
10_000_000_000_000_000_000,
116113
1_000_000_000,
117114
XcmFlow::Alternate,
118-
Option::<VersionedMultiLocation>::encode(&None),
119115
),
120116
(
121117
1000,
@@ -124,9 +120,6 @@ pub fn turing_development_config() -> ChainSpec {
124120
10_000_000_000_000_000_000,
125121
1_000_000_000,
126122
XcmFlow::Alternate,
127-
Option::<VersionedMultiLocation>::encode(&Some(
128-
MultiLocation::new(0, X1(PalletInstance(3))).into(),
129-
)),
130123
),
131124
],
132125
vec![
@@ -244,7 +237,7 @@ fn testnet_genesis(
244237
vesting_schedule: Vec<(u64, Vec<(AccountId, Balance)>)>,
245238
general_councils: Vec<AccountId>,
246239
technical_memberships: Vec<AccountId>,
247-
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow, Vec<u8>)>,
240+
xcmp_handler_data: Vec<(u32, TokenId, bool, u128, u64, XcmFlow)>,
248241
additional_assets: Vec<(TokenId, Vec<u8>)>,
249242
) -> turing_runtime::GenesisConfig {
250243
let candidate_stake = std::cmp::max(

pallets/xcmp-handler/src/benchmarking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ benchmarks! {
2828
let currency_id = T::GetNativeCurrencyId::get();
2929
let para_id: u32 = 1000;
3030
let xcm_data =
31-
XcmCurrencyData { native: false, fee_per_second: 100, instruction_weight: 1_000, flow: XcmFlow::Normal, location: None };
31+
XcmCurrencyData { native: false, fee_per_second: 100, instruction_weight: 1_000, flow: XcmFlow::Normal };
3232

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

4545
}: remove_chain_currency_data(RawOrigin::Root, para_id, currency_id)

pallets/xcmp-handler/src/lib.rs

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub mod pallet {
5858
use polkadot_parachain::primitives::Sibling;
5959
use sp_runtime::traits::{AccountIdConversion, Convert, SaturatedConversion};
6060
use sp_std::prelude::*;
61-
use xcm::{latest::prelude::*, VersionedMultiLocation};
61+
use xcm::latest::prelude::*;
6262
use xcm_executor::traits::{InvertLocation, WeightBounds};
6363

6464
type ParachainId = u32;
@@ -157,13 +157,11 @@ pub mod pallet {
157157
ErrorGettingCallWeight,
158158
/// Currency not supported
159159
CurrencyNotSupported,
160-
/// The version of the `VersionedMultiLocation` value used is not able
161-
/// to be interpreted.
162-
BadVersion,
163160
}
164161

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

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

240-
let (_, target_instructions) =
241-
Self::xcm_instruction_skeleton(para_id, xcm_data.clone())?;
237+
let (_, target_instructions) = Self::xcm_instruction_skeleton(para_id, xcm_data)?;
242238
let weight = xcm_data
243-
.clone()
244239
.instruction_weight
245240
.checked_mul(target_instructions.len() as u64)
246241
.ok_or(Error::<T>::WeightOverflow)?
@@ -286,29 +281,21 @@ pub mod pallet {
286281
.try_into()
287282
.map_err(|_| Error::<T>::FailedMultiLocationToJunction)?;
288283

289-
let location = match xcm_data.location {
290-
Some(loc) => loc.clone().try_into().map_err(|()| Error::<T>::BadVersion)?,
291-
_ => MultiLocation::new(0, Here),
292-
};
293-
294-
let target_asset =
295-
MultiAsset { id: Concrete(location), fun: Fungibility::Fungible(fee) };
296-
297284
let instructions = match xcm_data.flow {
298285
XcmFlow::Normal => Self::get_local_currency_instructions(
299286
para_id,
300-
target_asset,
301287
descend_location,
302288
transact_encoded_call,
303289
transact_encoded_call_weight,
304290
weight,
291+
fee,
305292
)?,
306293
XcmFlow::Alternate => Self::get_alternate_flow_instructions(
307-
target_asset,
308294
descend_location,
309295
transact_encoded_call,
310296
transact_encoded_call_weight,
311297
weight,
298+
fee,
312299
)?,
313300
};
314301

@@ -330,15 +317,21 @@ pub mod pallet {
330317
/// - DepositAsset
331318
pub fn get_local_currency_instructions(
332319
para_id: ParachainId,
333-
local_asset: MultiAsset,
334320
descend_location: Junctions,
335321
transact_encoded_call: Vec<u8>,
336322
transact_encoded_call_weight: u64,
337323
xcm_weight: u64,
324+
fee: u128,
338325
) -> Result<
339326
(xcm::latest::Xcm<<T as pallet::Config>::Call>, xcm::latest::Xcm<()>),
340327
DispatchError,
341328
> {
329+
// XCM for local chain
330+
let local_asset = MultiAsset {
331+
id: Concrete(MultiLocation::new(0, Here)),
332+
fun: Fungibility::Fungible(fee),
333+
};
334+
342335
let local_xcm = Xcm(vec![
343336
WithdrawAsset::<<T as pallet::Config>::Call>(local_asset.clone().into()),
344337
DepositAsset::<<T as pallet::Config>::Call> {
@@ -391,15 +384,21 @@ pub mod pallet {
391384
/// - RefundSurplus
392385
/// - DepositAsset
393386
fn get_alternate_flow_instructions(
394-
target_asset: MultiAsset,
395387
descend_location: Junctions,
396388
transact_encoded_call: Vec<u8>,
397389
transact_encoded_call_weight: u64,
398390
xcm_weight: u64,
391+
fee: u128,
399392
) -> Result<
400393
(xcm::latest::Xcm<<T as pallet::Config>::Call>, xcm::latest::Xcm<()>),
401394
DispatchError,
402395
> {
396+
// Default to native currency of target chain
397+
let target_asset = MultiAsset {
398+
id: Concrete(MultiLocation::new(0, Here)),
399+
fun: Fungibility::Fungible(fee),
400+
};
401+
403402
let target_xcm = Xcm(vec![
404403
DescendOrigin::<()>(descend_location.clone()),
405404
WithdrawAsset::<()>(target_asset.clone().into()),
@@ -540,37 +539,29 @@ pub mod pallet {
540539
.try_into()
541540
.map_err(|_| Error::<T>::FailedMultiLocationToJunction)?;
542541

543-
let location = match xcm_data.location {
544-
Some(loc) => loc.clone().try_into().map_err(|()| Error::<T>::BadVersion)?,
545-
_ => MultiLocation::new(0, Here),
546-
};
547-
548-
let target_asset =
549-
MultiAsset { id: Concrete(location), fun: Fungibility::Fungible(0u128) };
550-
551542
match xcm_data.flow {
552543
XcmFlow::Normal => Self::get_local_currency_instructions(
553544
para_id,
554-
target_asset,
555545
nobody,
556546
Default::default(),
557547
0u64,
558548
0u64,
549+
0u128,
559550
),
560551
XcmFlow::Alternate => Self::get_alternate_flow_instructions(
561-
target_asset,
562552
nobody,
563553
Default::default(),
564554
0u64,
565555
0u64,
556+
0u128,
566557
),
567558
}
568559
}
569560
}
570561

571562
#[pallet::genesis_config]
572563
pub struct GenesisConfig<T: Config> {
573-
pub chain_data: Vec<(u32, T::CurrencyId, bool, u128, u64, XcmFlow, Vec<u8>)>,
564+
pub chain_data: Vec<(u32, T::CurrencyId, bool, u128, u64, XcmFlow)>,
574565
}
575566

576567
#[cfg(feature = "std")]
@@ -583,18 +574,9 @@ pub mod pallet {
583574
#[pallet::genesis_build]
584575
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
585576
fn build(&self) {
586-
for (
587-
para_id,
588-
currency_id,
589-
native,
590-
fee_per_second,
591-
instruction_weight,
592-
flow,
593-
location_encoded,
594-
) in self.chain_data.iter()
577+
for (para_id, currency_id, native, fee_per_second, instruction_weight, flow) in
578+
self.chain_data.iter()
595579
{
596-
let location = Option::<VersionedMultiLocation>::decode(&mut &location_encoded[..])
597-
.expect("Error decoding VersionedMultiLocation");
598580
XcmChainCurrencyData::<T>::insert(
599581
para_id,
600582
currency_id,
@@ -603,7 +585,6 @@ pub mod pallet {
603585
fee_per_second: *fee_per_second,
604586
instruction_weight: *instruction_weight,
605587
flow: *flow,
606-
location,
607588
},
608589
);
609590
}
@@ -688,7 +669,6 @@ impl<T: Config> XcmpTransactor<T::AccountId, T::CurrencyId> for Pallet<T> {
688669
fee_per_second: 416_000_000_000,
689670
instruction_weight: 600_000_000,
690671
flow: XcmFlow::Normal,
691-
location: None,
692672
};
693673

694674
XcmChainCurrencyData::<T>::insert(para_id, currency_id, xcm_data);

0 commit comments

Comments
 (0)