Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fe2d626
Test for create and transfer `TrustBackedAssets` with AssetTransactor
bkontur Feb 3, 2023
8e3f62c
Test for transfer `local Currency` with AssetTransactor
bkontur Feb 6, 2023
766abea
Test for create foreign assets (covers foreign relaychain currency)
bkontur Feb 7, 2023
12d61db
Added `ForeignFungiblesTransactor` and test for transfer `ForeignAsse…
bkontur Feb 8, 2023
778f80f
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Feb 13, 2023
7772da9
Removed unused `pub const Local: MultiLocation`
bkontur Feb 13, 2023
40ccf5f
Changed `ParaId -> Sibling` for `SiblingParachainConvertsVia`
bkontur Feb 13, 2023
990e255
Test for create foreign assets (covers local sibling parachain assets)
bkontur Feb 13, 2023
a83d680
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Feb 23, 2023
2c11d66
Reverted stuff for ForeignCreators from different global consensus (m…
bkontur Feb 24, 2023
96379c3
Refactor `weight_limit` for `execute_xcm`
bkontur Feb 27, 2023
5bd9983
Added test for `set_metadata` by ForeignCreator with `xcm::Transact(s…
bkontur Feb 27, 2023
1fb6f90
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
bkontur Feb 28, 2023
457f87f
Renamed `receive_teleported_asset_works` -> `receive_teleported_asset…
bkontur Feb 28, 2023
7e1da40
Allow `ForeignCreators` only for sibling parachains
bkontur Feb 28, 2023
449ba70
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
bkontur Mar 3, 2023
80756d1
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Mar 3, 2023
03915e2
Unify ReservedDmpWeight/ReservedXcmpWeight usage
bkontur Mar 3, 2023
cabf0f9
Removed hack - replaced with `MatchedConvertedConcreteId`
bkontur Mar 3, 2023
92fee37
Refactor `ForeignCreators` to assets-common
bkontur Mar 3, 2023
e7cd1f5
Add `ReceiveTeleportedAsset` test
bkontur Mar 1, 2023
2aa0c8a
Change test - `Utility::batch` -> Multiple `xcm::Transact`
bkontur Mar 6, 2023
3310cd1
Reusing the same deposits as for TrustBackedAssets
bkontur Mar 6, 2023
24d0274
missing `try_successful_origin` ?
bkontur Mar 6, 2023
afbfeb0
Finished `ForeignAssets` for westmint (converter, FungiblesApi, tests)
bkontur Mar 8, 2023
ed97007
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Mar 8, 2023
47ba115
Refactoring tests - receive_teleported_asset_for_native_asset_works
bkontur Mar 9, 2023
0748e97
ForeignAssets for statemine + refactored `receive_teleported_asset_fr…
bkontur Mar 9, 2023
30acc18
Add `ForeignAssets` to statemine `FungiblesApi`
bkontur Mar 9, 2023
4fb2f85
Add `asset_transactor_transfer_with_local_consensus_currency_works` t…
bkontur Mar 9, 2023
2695886
Added `asset_transactor_transfer_with_trust_backed_assets_works` test
bkontur Mar 10, 2023
c181e0c
Added `asset_transactor_transfer_with_foreign_assets_works`
bkontur Mar 10, 2023
16ad4a4
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Mar 10, 2023
913504c
Fix `missing `try_successful_origin` in implementation`
bkontur Mar 12, 2023
4245b2f
Added `create_and_manage_foreign_assets_for_local_consensus_parachain…
bkontur Mar 13, 2023
79f9b30
Added `ExpectTransactStatus` check
bkontur Mar 13, 2023
5c97727
Small rename
bkontur Mar 13, 2023
c615788
Extended `test_assets_balances_api_works` with ForeignAssets for `sta…
bkontur Mar 13, 2023
0460e76
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-for…
Mar 15, 2023
ece1905
PR fixes
bkontur Mar 16, 2023
4b354a4
Update parachains/runtimes/assets/test-utils/src/test_cases.rs
joepetrowski Mar 16, 2023
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
Prev Previous commit
Next Next commit
Reverted stuff for ForeignCreators from different global consensus (m…
…oved to transfer asset branch)
  • Loading branch information
bkontur committed Feb 24, 2023
commit 2c11d66ac999141c929b648ca88f1a266a66aa56
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use xcm::latest::MultiAsset;
use xcm_executor::traits::{Error, MatchesFungibles};

// TODO:check-parameter - workaround for ConvertedConcreteId/MatchesFungibles and multiple FungiblesAdapter for AssetTransactor tuple (find a nicer way)
// TODO:check-parameter - waiting for https://github.com/paritytech/polkadot/pull/6739
//
// Problem is combination [`(FungiblesAdapter<Assets1, ConvertedConcreteId<..>, ...>, FungiblesAdapter<Assets2, ConvertedConcreteId<..>, ...>)`]
// where ConvertedConcreteId for ConvertAssetId returns AssetIdConversionFailed,
Expand Down
128 changes: 0 additions & 128 deletions parachains/runtimes/assets/westmint/src/foreign_conversions.rs

This file was deleted.

1 change: 0 additions & 1 deletion parachains/runtimes/assets/westmint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

mod asset_conversions;
pub mod constants;
mod foreign_conversions;
mod weights;
pub mod xcm_config;

Expand Down
3 changes: 1 addition & 2 deletions parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ impl<Call> XcmWeightInfo<Call> for WestmintXcmWeight<Call> {
XcmGeneric::<Runtime>::clear_transact_status()
}
fn universal_origin(_: &Junction) -> Weight {
// TODO:check-parameter - temporary fix - replace with correct weight for benchmark (set UniversalAliases)
XcmGeneric::<Runtime>::unpaid_execution()
Weight::MAX
}
fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
Weight::MAX
Expand Down
47 changes: 6 additions & 41 deletions parachains/runtimes/assets/westmint/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ use super::{
Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
RuntimeOrigin, TrustBackedAssetsInstance, WeightToFee, XcmpQueue,
};
use crate::{
asset_conversions::AssetIdConversionFailedToAssetNotFoundWrapper,
foreign_conversions::{
BridgedUniversalAliases, GlobalConsensusAsAccountId, GlobalConsensusConvertsVia,
IsTrustedGlobalConsensus,
},
ForeignAssets,
};
use crate::{asset_conversions::AssetIdConversionFailedToAssetNotFoundWrapper, ForeignAssets};
use frame_support::{
match_types, parameter_types,
traits::{ConstU32, Contains, EnsureOrigin, EnsureOriginWithArg, Everything, PalletInfoAccess},
traits::{
ConstU32, Contains, EnsureOrigin, EnsureOriginWithArg, Everything, Nothing,
PalletInfoAccess,
},
};
use pallet_xcm::{EnsureXcm, XcmPassthrough};
use parachains_common::{
Expand Down Expand Up @@ -295,8 +291,6 @@ pub type Barrier = DenyThenTry<
AllowExplicitUnpaidExecutionFrom<ParentOrParentsPlurality>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<Everything>,
// Specific barrier for calls from different globalConsensus/network
ForeignGlobalConsensusExecutionBarrier,
),
UniversalLocation,
ConstU32<8>,
Expand Down Expand Up @@ -362,7 +356,7 @@ impl xcm_executor::Config for XcmConfig {
type AssetExchanger = ();
type FeeManager = ();
type MessageExporter = ();
type UniversalAliases = TrustedBridgedNetworks;
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
type SafeCallFilter = SafeCallFilter;
}
Expand Down Expand Up @@ -424,11 +418,6 @@ pub type ForeignCreatorsSovereignAccountOf = (
SiblingParachainConvertsVia<Sibling, AccountId>,
AccountId32Aliases<RelayNetwork, AccountId>,
ParentIsPreset<AccountId>,
GlobalConsensusConvertsVia<
IsTrustedGlobalConsensus<TrustedBridgedNetworks>,
GlobalConsensusAsAccountId,
AccountId,
>,
);

// `EnsureOriginWithArg` impl for `CreateOrigin` that allows only XCM origins that are locations
Expand Down Expand Up @@ -464,27 +453,3 @@ impl BenchmarkHelper<MultiLocation> for XcmBenchmarkHelper {
MultiLocation { parents: 1, interior: X1(Parachain(id)) }
}
}

parameter_types! {
// TODO:check-parameter - join all together in one on-chain cfg (statemine/t, eth(chain_ids), ...)
// TODO:check-parameter - collect all required cfg also from ReserveAssetDeposited and add new pallet and persist/manage this via governance
// Means, that we accept some `GlobalConsensus` from some `MultiLocation` (e.g. our local bridge-hub)
pub TrustedBridgedNetworks: BridgedUniversalAliases = sp_std::vec![
(MultiLocation { parents: 1, interior: X1(Parachain(1014)) }, GlobalConsensus(NetworkId::Rococo)),
(MultiLocation { parents: 1, interior: X1(Parachain(1014)) }, GlobalConsensus(NetworkId::Kusama)),
(MultiLocation { parents: 1, interior: X1(Parachain(1002)) }, GlobalConsensus(NetworkId::Kusama))
];
}

impl Contains<(MultiLocation, Junction)> for TrustedBridgedNetworks {
fn contains(t: &(MultiLocation, Junction)) -> bool {
Self::get().contains(t)
}
}

/// Barrier dedicated to calls from different global consensus
pub type ForeignGlobalConsensusExecutionBarrier = (
// TODO:check-parameter - change "Contains with trusted BridgeHub configuration" or set BuyExecution
// Configured trusted BridgeHub gets free execution.
AllowExplicitUnpaidExecutionFrom<IsTrustedGlobalConsensus<TrustedBridgedNetworks>>,
);
126 changes: 3 additions & 123 deletions parachains/runtimes/assets/westmint/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,125 +719,6 @@ fn test_asset_transactor_transfer_with_foreign_assets_works() {
})
}

#[test]
fn create_foreign_assets_for_different_consensus_relaychain_token_works() {
// foreign relaychain currency as asset
let foreign_asset_id_multilocation =
MultiLocation { parents: 2, interior: X1(GlobalConsensus(Kusama)) };

// foreign creator, which can be relaychain governance-like origin to match ForeignCreators
let foreign_creator = MultiLocation { parents: 2, interior: X1(GlobalConsensus(Kusama)) };
let foreign_creator_as_account_id =
ForeignCreatorsSovereignAccountOf::convert(foreign_creator).expect("");

ExtBuilder::<Runtime>::default()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
)])
.with_balances(vec![(
foreign_creator_as_account_id.clone(),
ExistentialDeposit::get() + AssetDeposit::get(),
)])
.with_tracing()
.build()
.execute_with(|| {
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
assert_eq!(
Balances::free_balance(&foreign_creator_as_account_id),
ExistentialDeposit::get() + AssetDeposit::get()
);

// execute XCM with Transact to create foreign asset
let foreign_asset_create: RuntimeCall =
RuntimeCall::Utility(pallet_utility::Call::<Runtime>::batch {
calls: vec![
RuntimeCall::ForeignAssets(pallet_assets::Call::<
Runtime,
ForeignAssetsInstance,
>::create {
id: foreign_asset_id_multilocation,
// TODO:check-parameter - how to setup admin account?
admin: foreign_creator_as_account_id.clone().into(),
min_balance: 1,
}),
// TODO:check-parameter - cannot call in one batch, because set_metadata uses just `ensure_signed()`
// RuntimeCall::ForeignAssets(pallet_assets::Call::<
// Runtime,
// ForeignAssetsInstance,
// >::set_metadata {
// id: foreign_asset_id_multilocation,
// name: Default::default(),
// symbol: Default::default(),
// decimals: 12,
// }),
],
});

// lets simulate this was triggered by relay chain from different global consensus
let xcm = Xcm(vec![
UniversalOrigin(GlobalConsensus(Kusama)),
DescendOrigin(Here),
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact {
origin_kind: OriginKind::Xcm,
require_weight_at_most: Weight::from_ref_time(80_000_000_000),
call: foreign_asset_create.encode().into(),
},
]);

// messages with different consensus should go through the local bridge-hub
let local_bridge_hub_origin =
MultiLocation { parents: 1, interior: X1(Parachain(1014)) };
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
let weight_limit = Weight::from_ref_time(100_000_000_000);

// execute xcm as XcmpQueue would do
let outcome = XcmExecutor::<XcmConfig>::execute_xcm(
local_bridge_hub_origin,
xcm,
hash,
weight_limit,
);
assert_eq!(outcome.ensure_complete(), Ok(()));

// check events
let mut events = System::events().into_iter().map(|e| e.event);
assert!(events.any(|e| matches!(
e,
RuntimeEvent::ForeignAssets(pallet_assets::Event::Created { .. })
)));
// TODO:check-parameter - cannot call in one batch, because set_metadata uses just `ensure_signed()`
// assert!(
// events
// .any(|e| matches!(e, RuntimeEvent::ForeignAssets(pallet_assets::Event::MetadataSet { .. })))
// );
assert!(
events.any(|e| e.eq(&RuntimeEvent::Utility(pallet_utility::Event::BatchCompleted)))
);

// check assets after
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
assert!(!ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
use frame_support::traits::tokens::fungibles::roles::Inspect;
assert_eq!(
ForeignAssets::owner(foreign_asset_id_multilocation),
Some(foreign_creator_as_account_id.clone())
);
assert_eq!(
ForeignAssets::admin(foreign_asset_id_multilocation),
Some(foreign_creator_as_account_id.clone())
);
assert_eq!(
Balances::free_balance(foreign_creator_as_account_id),
ExistentialDeposit::get()
);
})
}

#[test]
fn create_foreign_assets_for_local_consensus_parachain_assets_works() {
// foreign parachain with the same consenus currency as asset
Expand Down Expand Up @@ -910,14 +791,14 @@ fn create_foreign_assets_for_local_consensus_parachain_assets_works() {
BuyExecution { fees: buy_execution_fee.into(), weight_limit: Unlimited },
Transact {
origin_kind: OriginKind::Xcm,
require_weight_at_most: Weight::from_ref_time(80_000_000_000),
require_weight_at_most: Weight::from_parts(80_000_000_000, 6000),
call: foreign_asset_create.encode().into(),
},
]);

// messages with different consensus should go through the local bridge-hub
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
let weight_limit = Weight::from_ref_time(100_000_000_000);
let weight_limit = Weight::from_parts(100_000_000_000, 6000);

// execute xcm as XcmpQueue would do
let outcome =
Expand Down Expand Up @@ -958,5 +839,4 @@ fn create_foreign_assets_for_local_consensus_parachain_assets_works() {
})
}

// TODO: fn test_create_foreign_assets_for_different_consensus_parachain_assets_works
// TODO: test that simulates ETH scenario for creating asset wETH on Statemine/t
// TODO: test for create foreign asset and set_metadata + make sufficient