Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reserve asset transfer of relaychain token to parachain and back #260

Closed
wants to merge 14 commits into from
43 changes: 41 additions & 2 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ futures = "0.3.25"
hex-literal = "0.4.1"
log = { version = "0.4.20", default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.188", features = ["derive"] }
serde = { version = "1.0.188", default-features = false, features = ["derive"] }
serde_json = "1.0"
smallvec = "1.11.0"

Expand Down Expand Up @@ -48,7 +48,9 @@ frame-system = { version = "25.0.0", default-features = false }
frame-system-benchmarking = { version = "25.0.0", default-features = false }
frame-system-rpc-runtime-api = { version = "23.0.0", default-features = false }
frame-try-runtime = { version = "0.31.0", default-features = false }
orml-currencies = { version = "0.6.7", default-features = false }
orml-traits = { version = "0.6.7", default-features = false }
orml-tokens = { version = "0.6.7", default-features = false }
orml-xcm = { version = "0.6.7", default-features = false }
orml-xcm-support = { version = "0.6.7", default-features = false }
orml-xtokens = { version = "0.6.7", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions polkadot-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "integritee-collator"
description = "The Integritee parachain collator binary"
# align major.minor revision with the runtimes. bump patch revision ad lib. make this the github release tag
version = "1.8.0"
version = "1.8.1"
authors = ["Integritee AG <[email protected]>"]
homepage = "https://integritee.network/"
repository = "https://github.com/integritee-network/parachain"
Expand All @@ -20,7 +20,7 @@ futures = { workspace = true, features = ["std"] }
hex-literal = { workspace = true }
log = { workspace = true, features = ["std"] }
parity-scale-codec = { workspace = true, features = ["std"] }
serde = { workspace = true }
serde = { workspace = true, features = ["std"] }
serde_json = { workspace = true }

# Parachain runtimes
Expand Down
3 changes: 3 additions & 0 deletions polkadot-parachains/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ mod types {
/// Balance of an account.
pub type Balance = u128;

/// Amount is signed version of Balance
pub type Amount = i128;

/// Nonce of a transaction in the chain.
pub type Nonce = u32;

Expand Down
11 changes: 10 additions & 1 deletion polkadot-parachains/integritee-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "integritee-runtime"
description = "The Integritee parachain runtime"
# patch revision must match runtime spec_version
version = "1.8.45"
version = "1.8.46"
authors = ["Integritee AG <[email protected]>"]
homepage = "https://integritee.network/"
repository = "https://github.com/integritee-network/parachain"
Expand All @@ -12,6 +12,7 @@ edition = "2021"
log = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
serde = { workspace = true }

parachains-common = { path = "../common", default-features = false }

Expand All @@ -31,7 +32,9 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
frame-system-rpc-runtime-api = { workspace = true }
frame-try-runtime = { workspace = true, optional = true }
orml-currencies = { workspace = true }
orml-traits = { workspace = true }
orml-tokens = { workspace = true }
orml-xcm = { workspace = true }
orml-xcm-support = { workspace = true }
orml-xtokens = { workspace = true }
Expand Down Expand Up @@ -114,7 +117,9 @@ std = [
"frame-system/std",
"frame-try-runtime?/std",
"log/std",
"orml-currencies/std",
"orml-traits/std",
"orml-tokens/std",
"orml-xcm-support/std",
"orml-xcm/std",
"orml-xtokens/std",
Expand Down Expand Up @@ -146,6 +151,7 @@ std = [
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"scale-info/std",
"serde/std",
"sp-api/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
Expand Down Expand Up @@ -176,6 +182,7 @@ runtime-benchmarks = [
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"orml-tokens/runtime-benchmarks",
"orml-xtokens/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-bounties/runtime-benchmarks",
Expand Down Expand Up @@ -213,6 +220,8 @@ try-runtime = [
"frame-executive/try-runtime",
"frame-system/try-runtime",
"frame-try-runtime/try-runtime",
"orml-currencies/try-runtime",
"orml-tokens/try-runtime",
"orml-xcm/try-runtime",
"orml-xtokens/try-runtime",
"pallet-aura/try-runtime",
Expand Down
71 changes: 64 additions & 7 deletions polkadot-parachains/integritee-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
// A few exports that help ease life for downstream crates.
use core::marker::PhantomData;
pub use frame_support::{
construct_runtime,
dispatch::DispatchClass,
Expand All @@ -67,6 +68,7 @@ use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureWithSuccess,
};
use orml_traits::{currency::MutationHooks, parameter_type_with_key};
pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall;
use parachains_common::{
Expand All @@ -75,7 +77,8 @@ use parachains_common::{
NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
pub use parachains_common::{
AccountId, Address, Balance, BlockNumber, Hash, Header, Nonce, Signature, MILLISECS_PER_BLOCK,
AccountId, Address, Amount, Balance, BlockNumber, Hash, Header, Nonce, Signature,
MILLISECS_PER_BLOCK,
};
use scale_info::TypeInfo;
#[cfg(any(feature = "std", test))]
Expand All @@ -94,6 +97,7 @@ mod helpers;
mod weights;

pub mod xcm_config;
use xcm_config::CurrencyId;

pub type SessionHandlers = ();

Expand All @@ -116,7 +120,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("integritee-parachain"),
impl_name: create_runtime_str!("integritee-full"),
authoring_version: 2,
spec_version: 45,
spec_version: 46,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 6,
Expand All @@ -135,6 +139,8 @@ pub const fn deposit(items: u32, bytes: u32) -> Balance {
/// A timestamp: milliseconds since the unix epoch.
pub type Moment = u64;

pub type ReserveIdentifier = [u8; 8];

/// The version information used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
Expand Down Expand Up @@ -249,7 +255,7 @@ impl pallet_balances::Config for Runtime {
type AccountStore = System;
type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
type ReserveIdentifier = ReserveIdentifier;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = ();
type FreezeIdentifier = ();
Expand Down Expand Up @@ -761,6 +767,58 @@ impl orml_xcm::Config for Runtime {
type SovereignOrigin = EnsureRoot<AccountId>;
}

parameter_type_with_key! {
pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
match currency_id {
CurrencyId::TEER => MILLITEER,
CurrencyId::RelayNative => 3_333_333u128.into() // keep this with asset hub ED
Copy link
Collaborator Author

@brenzi brenzi Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nicer to call this KSM, but as we want to have one runtime for KSM and DOT, we may keep it generic RelayNative

}
};
}

pub struct CurrencyHooks<T, DustAccount>(PhantomData<T>, DustAccount);
impl<T, DustAccount> MutationHooks<T::AccountId, T::CurrencyId, T::Balance>
for CurrencyHooks<T, DustAccount>
where
T: orml_tokens::Config,
DustAccount: Get<<T as frame_system::Config>::AccountId>,
{
type OnDust = orml_tokens::TransferDust<T, DustAccount>;
type OnSlash = ();
type PreDeposit = ();
type PostDeposit = ();
type PreTransfer = ();
type PostTransfer = ();
type OnNewTokenAccount = ();
type OnKilledTokenAccount = ();
}

impl orml_tokens::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type Amount = Amount;
type CurrencyId = CurrencyId;
type WeightInfo = weights::orml_tokens::WeightInfo<Runtime>;
type ExistentialDeposits = ExistentialDeposits;
type CurrencyHooks = CurrencyHooks<Runtime, TreasuryAccount>;
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type ReserveIdentifier = ReserveIdentifier;
type DustRemovalWhitelist = Nothing;
}

parameter_types! {
pub const GetNativeCurrencyId: CurrencyId = CurrencyId::TEER;
}

impl orml_currencies::Config for Runtime {
type MultiCurrency = Tokens;
type NativeCurrency =
orml_currencies::BasicCurrencyAdapter<Runtime, Balances, Amount, BlockNumber>;
type GetNativeCurrencyId = GetNativeCurrencyId;
type WeightInfo = ();
}

construct_runtime!(
pub enum Runtime
{
Expand Down Expand Up @@ -802,6 +860,8 @@ construct_runtime!(
XTokens: orml_xtokens = 34,
OrmlXcm: orml_xcm = 35,
XcmTransactor: pallet_xcm_transactor = 36,
Tokens: orml_tokens exclude_parts { Call } = 41,
Currencies: orml_currencies = 42,

// Integritee pallets.
Teerex: pallet_teerex = 50,
Expand Down Expand Up @@ -861,10 +921,6 @@ mod benches {
[pallet_child_bounties, ChildBounties]
[pallet_claims, Claims]
[pallet_collective, Council]
// Fixme #177: For some reason the benchmarks write both to the same pallet_collective weight
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no reason to fix this. of course the benchmark is the same for two instances of the same pallet

// file. No reason to run both before we fix that, as the pallet_collective benchmark
// takes the longest.
// [pallet_collective, TechnicalCommittee]
[pallet_democracy, Democracy]
[pallet_multisig, Multisig]
[pallet_preimage, Preimage]
Expand All @@ -880,6 +936,7 @@ mod benches {
[pallet_xcm, PolkadotXcm]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[pallet_utility, Utility]
[orml_tokens, Tokens]
);
}

Expand Down
2 changes: 2 additions & 0 deletions polkadot-parachains/integritee-runtime/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ pub mod pallet_treasury;
pub mod pallet_utility;
pub mod pallet_vesting;
pub mod pallet_xcm;

pub mod orml_tokens;
Loading
Loading