Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
3302020
Reorganize XCM configuration
sea212 Jun 4, 2022
2bae5e5
Comment XcmConfig and mark necessary changes
sea212 Jun 4, 2022
f172dc4
Implement and configure AssetTransactor
sea212 Jun 5, 2022
a09a350
Configure and comment XCM Barrier
sea212 Jun 16, 2022
8c5f164
Configure XCM IsReserve
sea212 Jun 16, 2022
47179af
Prepare Trader implementation for XcmConfig
sea212 Jun 16, 2022
829491a
Merge branch 'main' into sea212-integrate-aUSD
sea212 Aug 17, 2022
62c05d9
Rename Asset::Ztg -> Asset::ZTG (merge artifact)
sea212 Aug 17, 2022
a204b9a
Merge artifacts, work on XCM impl
sea212 Aug 19, 2022
c735f24
Use MultiAssetTransactor and latest orml pallets
sea212 Sep 25, 2022
15153e8
Add asset registry and AssetProcessor implementation
sea212 Sep 25, 2022
071e50d
Integrate asset-registry, implement fee structure
sea212 Sep 25, 2022
dd80b26
Finalize: XCM Weight/Fee, Trader, Treasury
sea212 Sep 26, 2022
9f2ef67
Fix key conversion & GenesisConfig
sea212 Sep 26, 2022
28517a8
Comment + Cargo fmt
sea212 Sep 26, 2022
45a887a
Merge branch 'main' into sea212-integrate-aUSD
sea212 Sep 26, 2022
49030cb
Include xTokens
sea212 Oct 11, 2022
4f5ab0f
Add integration test environment & XCM test setup
sea212 Oct 31, 2022
c1e2b96
Finalize simulated network preparation
sea212 Nov 1, 2022
49d468e
Add currency conversion tests
sea212 Nov 1, 2022
31933cd
Finalize CurrencyID<>MultiLocation tests
sea212 Nov 2, 2022
208c862
Add helper functions and sibling currency<>location conversion test
sea212 Nov 2, 2022
78b1018
Add relative view trader for ZTG
sea212 Nov 2, 2022
bb30dfa
Extend XCM transfer tests
sea212 Nov 4, 2022
b28542b
Add ZTG -> Sibling -> ZTG test
sea212 Nov 4, 2022
b6a7d92
Read ParaId from ParachainInfo + fix tests
sea212 Nov 5, 2022
5a079b6
Fix KSM <> ZTG XCM tests
sea212 Nov 5, 2022
4e67549
Fix Fee (off by 2000x)
sea212 Nov 5, 2022
a708fb1
Increase ExistentialDeposit & Add Treasury to dust whitelist
sea212 Nov 5, 2022
b7b665b
Fix custom fee calculation
sea212 Nov 5, 2022
d31dcc6
Add custom fee test
sea212 Nov 5, 2022
6cee15d
Finalize XCM integration tests
sea212 Nov 5, 2022
e914d54
Remove unused modules
sea212 Nov 7, 2022
ec00ef2
Add XCM related pallets to common runtime
sea212 Nov 7, 2022
0d460a1
Cleanup code
sea212 Nov 7, 2022
d990634
Add proper XCM configuration to Zeitgeist runtime
sea212 Nov 7, 2022
3e84785
Use ExistentialDeposit directly in integration test
sea212 Nov 8, 2022
857cf74
Add integration tests to Zeitgeist runtime
sea212 Nov 8, 2022
d6030ac
Allow only Kusama as parent on Zeitgeist + Cleanup
sea212 Nov 8, 2022
0ff4e5f
Remove dead code
sea212 Nov 9, 2022
e170adb
Update changelog_for_devs.md
sea212 Nov 9, 2022
a5ed076
Use correct treasury pallet id (as before)
sea212 Nov 17, 2022
7ebe84a
Use unambiguous names for setters
sea212 Nov 17, 2022
fc6ae19
Convert comment to docstring
sea212 Nov 17, 2022
354de95
Fix wrong comment
sea212 Nov 17, 2022
b2c1e1f
Reset emulated testnet in any case
sea212 Nov 22, 2022
0f59db0
Remove unnecessary commas
sea212 Nov 23, 2022
49b54ac
Improve readability of numbers
sea212 Nov 23, 2022
391fc02
Fix docstring
sea212 Nov 23, 2022
b6ef8cc
Remove invalid initial balance (integration test)
sea212 Nov 23, 2022
dab6d11
Improve style
sea212 Nov 24, 2022
884a32d
Use more descriptive function name
sea212 Nov 24, 2022
fdfa04b
Add additional balance guard to xcm tests
sea212 Nov 24, 2022
54d3889
Use ::parachain_id() instead of ::get()
sea212 Nov 24, 2022
37a1536
Reduce nested match depth
sea212 Nov 24, 2022
b503c34
Update changelog
sea212 Nov 24, 2022
b20e13f
Add missing crates to runtime-benchmarks feature
sea212 Nov 24, 2022
21a76e4
Merge branch 'main' into sea212-integrate-aUSD
sea212 Nov 24, 2022
77495ed
Repair build
sea212 Nov 24, 2022
1d31ae0
Satisfy cargo fmt and taplo
sea212 Nov 24, 2022
e153330
Update XCM weight in tests
sea212 Nov 24, 2022
c003dda
Satisfy Clippy
sea212 Nov 24, 2022
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
Implement and configure AssetTransactor
  • Loading branch information
sea212 committed Jun 5, 2022
commit f172dc4dede418290db22e61e25d45de3dfcaed9
31 changes: 31 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions primitives/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub enum Asset<MI: MaxEncodedLen> {
ScalarOutcome(MI, ScalarPosition),
CombinatorialOutcome,
PoolShare(SerdeWrapper<PoolId>),
Ausd,
Ksm,
Roc,
Ztg,
}

Expand Down
19 changes: 12 additions & 7 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ pallet-author-mapping = { rev = "78db06c0203f61b35059304f7194ed5c10dcfda8", defa
pallet-author-slot-filter = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/nimbus", optional = true }
pallet-crowdloan-rewards = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/crowdloan-rewards", optional = true }
parachain-staking = { rev = "78db06c0203f61b35059304f7194ed5c10dcfda8", default-features = false, git = "https://github.com/purestake/moonbeam", optional = true }
polkadot-parachain = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/polkadot", optional = true }

# Polkadot

# XCM
orml-xcm-support = { branch = "polkadot-0.9.19-latest", default-features = false, git = "https://github.com/zeitgeistpm/open-runtime-module-library", optional = true }
orml-unknown-tokens = { branch = "polkadot-0.9.19-latest", default-features = false, git = "https://github.com/zeitgeistpm/open-runtime-module-library", optional = true }
pallet-xcm = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/polkadot", optional = true }
polkadot-parachain = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/polkadot", optional = true }
xcm = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/polkadot", optional = true }
xcm-builder = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/polkadot", optional = true }
xcm-executor = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/polkadot", optional = true }
Expand Down Expand Up @@ -123,11 +124,13 @@ parachain = [
"pallet-author-slot-filter",
"pallet-crowdloan-rewards",
"parachain-staking",
"polkadot-parachain",

# Polkadot
# XCM

"orml-unknown-tokens",
"orml-xcm-support",
"pallet-xcm",
"polkadot-parachain",
"xcm-builder",
"xcm-executor",
"xcm",
Expand Down Expand Up @@ -239,11 +242,13 @@ std = [
"pallet-author-slot-filter?/std",
"pallet-crowdloan-rewards?/std",
"parachain-staking?/std",
"polkadot-parachain?/std",

# Polkadot
# XCM

"orml-unknown-tokens?/std",
"orml-xcm-support?/std",
"pallet-xcm?/std",
"polkadot-parachain?/std",
"xcm-builder?/std",
"xcm-executor?/std",
"xcm?/std",
Expand Down
7 changes: 6 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use {
frame_system::EnsureSigned,
nimbus_primitives::{CanAuthor, NimbusId},
xcm_builder::{EnsureXcmOrigin, FixedWeightBounds, LocationInverter},
xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin, LocalOriginToLocation, XcmRouter}
xcm_config::{LocalOriginToLocation, XcmConfig, XcmOriginToTransactDispatchOrigin, XcmRouter},
};

pub const VERSION: RuntimeVersion = RuntimeVersion {
Expand Down Expand Up @@ -204,6 +204,7 @@ macro_rules! create_zeitgeist_runtime {
// Third-party
Currency: orml_currencies::{Call, Pallet, Storage} = 40,
Tokens: orml_tokens::{Config<T>, Event<T>, Pallet, Storage} = 41,
UnknownTokens: orml_unknown_tokens::{Pallet, Storage, Event} = 42,

// Zeitgeist
MarketCommons: zrml_market_commons::{Pallet, Storage} = 50,
Expand Down Expand Up @@ -549,6 +550,10 @@ impl orml_tokens::Config for Runtime {
type WeightInfo = weights::orml_tokens::WeightInfo<Runtime>;
}

impl orml_unknown_tokens::Config for Runtime {
type Event = Event;
}

#[cfg(feature = "parachain")]
impl pallet_crowdloan_rewards::Config for Runtime {
type Event = Event;
Expand Down
1 change: 0 additions & 1 deletion runtime/src/parachain_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use sp_runtime::{Perbill, Percent, SaturatedConversion};
use xcm::latest::{Junction, MultiLocation, NetworkId};
use zeitgeist_primitives::{constants::MICRO, types::Balance};


parameter_types! {
// Author-Mapping
/// The amount that should be taken as a security deposit when registering a NimbusId.
Expand Down
1 change: 1 addition & 0 deletions runtime/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ parameter_types! {
pub const ProposalBondMaximum: Balance = 500 * BASE;
pub const SpendPeriod: BlockNumber = 24 * BLOCKS_PER_DAY;
pub const TreasuryPalletId: PalletId = PalletId(*b"zge/tsry");
pub ZeitgeistTreasuryAccount: AccountId = TreasuryPalletId::get().into_account();

// Vesting
pub const MinVestedTransfer: Balance = CENT;
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/weights/pallet_author_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_author_mapping::weights::WeightInfo for WeightInfo<T> {
// Storage: AuthorMapping MappingWithDeposit (r:1 w:1)
// Storage: System Account (r:1 w:1)
#[rustfmt::skip]
#[rustfmt::skip]
fn add_association() -> Weight {
(60_010_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: AuthorMapping MappingWithDeposit (r:2 w:2)
#[rustfmt::skip]
#[rustfmt::skip]
fn update_association() -> Weight {
(45_540_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: AuthorMapping MappingWithDeposit (r:1 w:1)
// Storage: System Account (r:1 w:1)
#[rustfmt::skip]
#[rustfmt::skip]
fn clear_association() -> Weight {
(60_780_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
Expand Down
165 changes: 143 additions & 22 deletions runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
use crate::{
AccountId, Ancestry, Balance, Balances, Call, MaxInstructions, Origin, ParachainSystem,
PolkadotXcm, RelayChainOrigin, RelayLocation, RelayNetwork, UnitWeightCost, XcmpQueue,
AccountId, Ancestry, Balance, Balances, Call, Currency, MaxInstructions, Origin,
ParachainSystem, PolkadotXcm, RelayChainOrigin, RelayLocation, RelayNetwork, Runtime,
UnitWeightCost, UnknownTokens, XcmpQueue, ZeitgeistTreasuryAccount,
};
use frame_support::{match_types, traits::Everything, weights::IdentityFee};
use frame_support::{match_types, parameter_types, traits::Everything, weights::IdentityFee};
use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter};
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::Convert;
use xcm::latest::{
prelude::{Concrete, GeneralKey, MultiAsset, Parachain, X1, X2},
BodyId, Junction, Junctions, MultiLocation,
};
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents,
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,
FixedWeightBounds, LocationInverter, NativeAsset, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
};
use xcm_executor::Config;
use xcm::latest::{BodyId, Junction, Junctions, MultiLocation};
use zeitgeist_primitives::types::Asset;

pub struct XcmConfig;

Expand All @@ -23,12 +29,12 @@ pub struct XcmConfig;
impl Config for XcmConfig {
/// The handler for when there is an instruction to claim assets.
type AssetClaims = PolkadotXcm;
/// TODO: How to withdraw and deposit an asset.
type AssetTransactor = LocalAssetTransactor;
/// How to withdraw and deposit an asset.
type AssetTransactor = MultiAssetTransactor;
/// The general asset trap - handler for when assets are left in the Holding Register at the
/// end of execution.
type AssetTrap = PolkadotXcm;
/// Additional filters that specify whether the XCM call should be executed at all.
/// TODO: Additional filters that specify whether the XCM call should be executed at all.
type Barrier = Barrier;
/// The outer call dispatch type.
type Call = Call;
Expand Down Expand Up @@ -58,21 +64,136 @@ pub type Barrier = (
AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,
// ^^^ Parent and its exec plurality get free execution
);
type AssetT = <Runtime as orml_tokens::Config>::CurrencyId;

parameter_types! {
pub CheckAccount: AccountId = PolkadotXcm::check_account();
}

/// Means for transacting assets on this chain.
pub type LocalAssetTransactor = CurrencyAdapter<
// Use this currency:
Balances,
// Use this currency when it is a fungible asset matching the given location or name:
IsConcrete<RelayLocation>,
// Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:
LocationToAccountId,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
pub type MultiAssetTransactor = MultiCurrencyAdapter<
// All known Assets will be processed by the following MultiCurrency implementation.
Currency,
// Any unknown Assets will be processed by the following implementation.
UnknownTokens,
// This means that this adapter should handle any token that `AssetConvert` can convert
// using Currency and UnknownTokens in all other cases.
IsNativeConcrete<AssetT, AssetConvert>,
// Our chain's account ID type (we can't get away without mentioning it explicitly).
AccountId,
// We don't track any teleports.
(),
// Convert an XCM `MultiLocation` into a local account id.
LocationToAccountId,
// The AssetId that corresponds to the native currency.
AssetT,
// Struct that provides functions to convert `Asset` <=> `MultiLocation`.
AssetConvert,
// In case of deposit failure, known assets will be placed in treasury.
DepositToAlternative<ZeitgeistTreasuryAccount, Currency, AssetT, AccountId, Balance>,
>;

/// Listing of parachains we integrate with.
/// For each parachain, we are interested in stating their parachain ID
/// as well as any of their token key ID that we possibly support in our
/// XCM configuration. These token keys are defined in said parachain
/// and must always match the value there defined, which is expected to
/// never change once defined since they help define the canonical id
/// of said tokens in the network, which is relevant for XCM transfers.
pub mod parachains {
pub mod karura {
pub const ID: u32 = 2000;
pub const AUSD_KEY: &[u8] = &[0, 129];
}

pub mod zeitgeist {
pub const ID: u32 = 2101;
pub const ZTG_KEY: &[u8] = &[0, 1];
}
}

/// AssetConvert
/// This type implements conversions from our `Asset` type into `MultiLocation` and vice-versa.
/// A currency locally is identified with a `Asset` variant but in the network it is identified
/// in the form of a `MultiLocation`, in this case a pair (Para-Id, Currency-Id).
pub struct AssetConvert;
// TODO: Use KSM or ROC depending on runtime that's built
const RELAY_CURRENCY: AssetT = Asset::Roc;

/// Convert our `Asset` type into its `MultiLocation` representation.
/// Other chains need to know how this conversion takes place in order to
/// handle it on their side.
impl Convert<AssetT, Option<MultiLocation>> for AssetConvert {
fn convert(id: AssetT) -> Option<MultiLocation> {
let x = match id {
RELAY_CURRENCY => MultiLocation::parent(),
Asset::Ausd => MultiLocation::new(
1,
X2(
Parachain(parachains::karura::ID),
GeneralKey(parachains::karura::AUSD_KEY.into()),
),
),
Asset::Ztg => MultiLocation::new(
1,
X2(
Parachain(parachains::zeitgeist::ID),
GeneralKey(parachains::zeitgeist::ZTG_KEY.to_vec()),
),
),
_ => return None,
};
Some(x)
}
}

/// Convert an incoming `MultiLocation` into a `Asset` if possible.
/// Here we need to know the canonical representation of all the tokens we handle in order to
/// correctly convert their `MultiLocation` representation into our internal `Asset` type.
impl xcm_executor::traits::Convert<MultiLocation, AssetT> for AssetConvert {
fn convert(location: MultiLocation) -> Result<AssetT, MultiLocation> {
if location == MultiLocation::parent() {
return Ok(RELAY_CURRENCY);
}

match location.clone() {
MultiLocation { parents: 0, interior: X1(GeneralKey(key)) } => match &key[..] {
parachains::zeitgeist::ZTG_KEY => Ok(Asset::Ztg),
_ => Err(location.clone()),
},
MultiLocation { parents: 1, interior: X2(Parachain(para_id), GeneralKey(key)) } => {
match para_id {
parachains::zeitgeist::ID => match &key[..] {
parachains::zeitgeist::ZTG_KEY => Ok(Asset::Ztg),
_ => Err(location.clone()),
},

parachains::karura::ID => match &key[..] {
parachains::karura::AUSD_KEY => Ok(Asset::Ausd),
_ => Err(location.clone()),
},
_ => Err(location.clone()),
}
}
_ => Err(location.clone()),
}
}
}

impl Convert<MultiAsset, Option<AssetT>> for AssetConvert {
fn convert(asset: MultiAsset) -> Option<AssetT> {
if let MultiAsset { id: Concrete(location), .. } = asset {
<AssetConvert as xcm_executor::traits::Convert<_, _>>::convert(location).ok()
} else {
None
}
}
}

impl Convert<MultiLocation, Option<AssetT>> for AssetConvert {
fn convert(location: MultiLocation) -> Option<AssetT> {
<AssetConvert as xcm_executor::traits::Convert<_, _>>::convert(location).ok()
}
}

/// No local origins on this chain are allowed to dispatch XCM sends/executions.
pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RelayNetwork>;

Expand Down