Skip to content

Commit

Permalink
Add xcm action (#982)
Browse files Browse the repository at this point in the history
* Add bifrost xcm-action

* Refactor xcm-action

* Support xcm-action moonbeam

* Match moonbeam account

* Add xcm-action to bifrost kusama

* Support xcm-action

* Add tuples-96 feature

* Fix conditional compile

* Update

* Remove conditional compile

* Fix ASTAR MaxWeightInValid

* Remove tuples-96 feature and fix bug
  • Loading branch information
hqwangningbo authored Jun 7, 2023
1 parent 8986511 commit 400f989
Show file tree
Hide file tree
Showing 27 changed files with 2,215 additions and 36 deletions.
56 changes: 56 additions & 0 deletions Cargo.lock

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

19 changes: 0 additions & 19 deletions node/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,22 +222,3 @@ impl Default for RedeemType {
Self::Native
}
}

impl RedeemType {
#[cfg(feature = "with-bifrost-kusama-runtime")]
pub fn get_parachain_id(self) -> u32 {
match self {
RedeemType::Native => 2001,
RedeemType::Astar => 2007,
RedeemType::Moonbeam(_) => 2023,
}
}
#[cfg(not(feature = "with-bifrost-kusama-runtime"))]
pub fn get_parachain_id(self) -> u32 {
match self {
RedeemType::Native => 2030,
RedeemType::Astar => 2006,
RedeemType::Moonbeam(_) => 2004,
}
}
}
4 changes: 4 additions & 0 deletions node/primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ pub trait VtokenMintingOperator<CurrencyId, Balance, AccountId, TimeUnit> {
currency_id: CurrencyId,
index: u32,
) -> Option<(AccountId, Balance, TimeUnit, RedeemType)>;
fn get_astar_parachain_id() -> u32;
fn get_moonbeam_parachain_id() -> u32;
}

/// Trait for Vtoken-Minting module to check whether accept redeeming or not.
Expand Down Expand Up @@ -328,6 +330,8 @@ pub trait VtokenMintingInterface<AccountId, CurrencyId, Balance> {
fn vtoken_id(token_id: CurrencyId) -> Option<CurrencyId>;
fn token_id(vtoken_id: CurrencyId) -> Option<CurrencyId>;
fn get_minimums_redeem(vtoken_id: CurrencyId) -> Balance;
fn get_astar_parachain_id() -> u32;
fn get_moonbeam_parachain_id() -> u32;
}

pub trait TryConvertFrom<CurrencyId> {
Expand Down
2 changes: 2 additions & 0 deletions pallets/fee-share/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ impl bifrost_vtoken_minting::Config for Runtime {
type WeightInfo = ();
type OnRedeemSuccess = ();
type XcmTransfer = XTokens;
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
}

parameter_types! {
Expand Down
3 changes: 1 addition & 2 deletions pallets/liquidity-mining/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
// Ensure we're `no_std` when compiling for Wasm.
#![cfg(feature = "runtime-benchmarks")]
use frame_benchmarking::{
account, benchmarks_instance_pallet, impl_benchmark_test_suite, v1::BenchmarkError,
whitelisted_caller,
account, benchmarks_instance_pallet, impl_benchmark_test_suite, whitelisted_caller,
};
use frame_support::{
assert_ok,
Expand Down
2 changes: 1 addition & 1 deletion pallets/salp-lite/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

// Ensure we're `no_std` when compiling for Wasm.
#[cfg(feature = "runtime-benchmarks")]
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_support::assert_ok;
use frame_system::RawOrigin;
use node_primitives::ParaId;
Expand Down
1 change: 0 additions & 1 deletion pallets/slp/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use frame_benchmarking::{account, benchmarks, v1::BenchmarkError, whitelisted_ca
use frame_support::{assert_ok, dispatch::UnfilteredDispatchable};
use frame_system::RawOrigin;
use sp_runtime::traits::{AccountIdConversion, StaticLookup, UniqueSaturatedFrom};
use xcm::v3::prelude::*;

#[allow(unused_imports)]
pub use crate::{Pallet as Slp, *};
Expand Down
4 changes: 2 additions & 2 deletions pallets/slp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ pub mod pallet {
let dest = MultiLocation {
parents: 1,
interior: X2(
Parachain(redeem_type.get_parachain_id()),
Parachain(T::VtokenMinting::get_astar_parachain_id()),
AccountId32 {
network: None,
id: user_account.encode().try_into().unwrap(),
Expand All @@ -1261,7 +1261,7 @@ pub mod pallet {
let dest = MultiLocation {
parents: 1,
interior: X2(
Parachain(redeem_type.get_parachain_id()),
Parachain(T::VtokenMinting::get_moonbeam_parachain_id()),
AccountKey20 {
network: None,
key: evm_caller.to_fixed_bytes(),
Expand Down
2 changes: 2 additions & 0 deletions pallets/slp/src/mocks/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ impl bifrost_vtoken_minting::Config for Runtime {
type WeightInfo = ();
type OnRedeemSuccess = ();
type XcmTransfer = XTokens;
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
}

parameter_types! {
Expand Down
2 changes: 2 additions & 0 deletions pallets/slp/src/mocks/mock_kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ impl bifrost_vtoken_minting::Config for Runtime {
type WeightInfo = ();
type OnRedeemSuccess = ();
type XcmTransfer = XTokens;
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
}

parameter_types! {
Expand Down
2 changes: 2 additions & 0 deletions pallets/system-maker/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ impl bifrost_vtoken_minting::Config for Runtime {
type WeightInfo = ();
type OnRedeemSuccess = ();
type XcmTransfer = XTokens;
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
}

parameter_types! {
Expand Down
2 changes: 2 additions & 0 deletions pallets/system-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ impl bifrost_vtoken_minting::Config for Runtime {
type WeightInfo = ();
type OnRedeemSuccess = ();
type XcmTransfer = XTokens;
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
}

ord_parameter_types! {
Expand Down
2 changes: 2 additions & 0 deletions pallets/ve-minting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ impl bifrost_vtoken_minting::Config for Runtime {
type WeightInfo = ();
type OnRedeemSuccess = ();
type XcmTransfer = XTokens;
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
}

ord_parameter_types! {
Expand Down
24 changes: 22 additions & 2 deletions pallets/vtoken-minting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ pub mod pallet {
#[pallet::constant]
type RelayChainToken: Get<CurrencyId>;

#[pallet::constant]
type AstarParachainId: Get<u32>;

#[pallet::constant]
type MoonbeamParachainId: Get<u32>;

type BifrostSlp: SlpOperator<CurrencyId>;

type CurrencyIdConversion: CurrencyIdConversion<CurrencyId>;
Expand Down Expand Up @@ -920,7 +926,7 @@ pub mod pallet {
let dest = MultiLocation {
parents: 1,
interior: X2(
Parachain(redeem_type.get_parachain_id()),
Parachain(T::AstarParachainId::get()),
AccountId32 {
network: None,
id: account.encode().try_into().unwrap(),
Expand All @@ -939,7 +945,7 @@ pub mod pallet {
let dest = MultiLocation {
parents: 1,
interior: X2(
Parachain(redeem_type.get_parachain_id()),
Parachain(T::MoonbeamParachainId::get()),
AccountKey20 { network: None, key: evm_caller.to_fixed_bytes() },
),
};
Expand Down Expand Up @@ -1505,6 +1511,13 @@ impl<T: Config> VtokenMintingOperator<CurrencyId, BalanceOf<T>, AccountIdOf<T>,
) -> Option<(AccountIdOf<T>, BalanceOf<T>, TimeUnit, RedeemType)> {
Self::token_unlock_ledger(currency_id, index)
}

fn get_astar_parachain_id() -> u32 {
T::AstarParachainId::get()
}
fn get_moonbeam_parachain_id() -> u32 {
T::MoonbeamParachainId::get()
}
}

impl<T: Config> VtokenMintingInterface<AccountIdOf<T>, CurrencyIdOf<T>, BalanceOf<T>>
Expand Down Expand Up @@ -1562,4 +1575,11 @@ impl<T: Config> VtokenMintingInterface<AccountIdOf<T>, CurrencyIdOf<T>, BalanceO
fn get_minimums_redeem(vtoken_id: CurrencyIdOf<T>) -> BalanceOf<T> {
MinimumRedeem::<T>::get(vtoken_id)
}

fn get_astar_parachain_id() -> u32 {
T::AstarParachainId::get()
}
fn get_moonbeam_parachain_id() -> u32 {
T::MoonbeamParachainId::get()
}
}
2 changes: 2 additions & 0 deletions pallets/vtoken-minting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ impl vtoken_minting::Config for Runtime {
type WeightInfo = ();
type OnRedeemSuccess = ();
type XcmTransfer = XTokens;
type AstarParachainId = ConstU32<2007>;
type MoonbeamParachainId = ConstU32<2023>;
}

ord_parameter_types! {
Expand Down
74 changes: 74 additions & 0 deletions pallets/xcm-action/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[package]
name = "bifrost-xcm-action"
description = "A pallet to manage the execution of XCM messages"
authors = ["hqwangningbo <[email protected]>"]
edition = "2021"
version = "0.8.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
hex-literal = "0.3.4"
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0.152", default-features = false, features = ["derive"] }
frame-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38",default-features = false, optional = true }
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38",default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38",default-features = false }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38",default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38",default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38",default-features = false }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38", default-features = false }
orml-traits = { version = "0.4.1-dev", default-features = false }
orml-xtokens = { version = "0.4.1-dev", default-features = false }
zenlink-protocol = { version = "*", default-features = false }

node-primitives = { path = "../../node/primitives", default-features = false }
xcm-interface = { path = "../xcm-interface", default-features = false }
bifrost-asset-registry = { path = "../asset-registry", default-features = false }

[dev-dependencies]
pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
bifrost-vtoken-minting = { path = "../vtoken-minting" }
bifrost-slp = { path = "../slp" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" }
orml-tokens = "0.4.1-dev"
orml-currencies = "0.4.1-dev"
xcm-executor = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" }
pallet-xcm = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" }
xcm-builder = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" }
xcm-simulator = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" }
bifrost-runtime-common = { package = "bifrost-runtime-common", path = "../../runtime/common", default-features = false }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"serde/std",
"zenlink-protocol/std",
"orml-traits/std",
"orml-xtokens/std",
"node-primitives/std",
"cumulus-primitives-core/std",
"sp-std/std",
"bifrost-slp/std",
"bifrost-runtime-common/std",
"cumulus-pallet-xcm/std",
"sp-core/std",
"sp-runtime/std",
"bifrost-asset-registry/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
with-bifrost-polkadot-runtime = []
Loading

0 comments on commit 400f989

Please sign in to comment.