Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech/cumul
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.10" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.10" }
kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.10" }

xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", branch = "polkadot-v0.9.10" }

node-service = { path = "../node/service", features = ["with-all-runtime"] }
Expand Down
51 changes: 11 additions & 40 deletions integration-tests/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@
pub use codec::Encode;
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use frame_support::{
assert_noop, assert_ok,
sp_runtime::app_crypto::sp_core::keccak_256,
traits::{
schedule::DispatchTime, Currency, GenesisBuild, OnFinalize, OnInitialize, OriginTrait,
ValidatorSet,
},
assert_ok,
traits::{GenesisBuild, OnFinalize, OnInitialize},
weights::constants::*,
};
use frame_system::RawOrigin;
Expand All @@ -34,38 +30,27 @@ pub use sp_runtime::{
traits::{AccountIdConversion, BadOrigin, Convert, Zero},
DispatchError, DispatchResult, FixedPointNumber, MultiAddress,
};
use xcm::{
opaque::v0::prelude::{BuyExecution, DepositAsset},
v0::{
ExecuteXcm,
Junction::{self, *},
MultiAsset,
MultiLocation::*,
NetworkId, Outcome, Xcm,
},
};
pub const ALICE: [u8; 32] = [0u8; 32];
pub const BOB: [u8; 32] = [1u8; 32];

#[cfg(feature = "with-asgard-runtime")]
pub use asgard_imports::*;
use xcm::v0::MultiLocation;

#[cfg(feature = "with-asgard-runtime")]
mod asgard_imports {
pub use asgard_runtime::{
create_x2_parachain_multilocation, AccountId, Balance, Balances, BifrostCrowdloanId,
BlockNumber, Call, Currencies, CurrencyId, Event, ExistentialDeposit, ExistentialDeposits,
NativeCurrencyId, Origin, OriginCaller, ParachainInfo, ParachainSystem, Perbill, Proxy,
RelayCurrencyId, RelaychainSovereignSubAccount, Runtime, Salp, Scheduler, Session,
SlotLength, System, Tokens, TreasuryPalletId, Utility, Vesting, XTokens, XcmConfig,
constants::currency::DOLLARS, create_x2_multilocation, AccountId, Balance, Balances,
BifrostCrowdloanId, BlockNumber, Call, Currencies, CurrencyId, Event, ExistentialDeposit,
ExistentialDeposits, NativeCurrencyId, Origin, OriginCaller, ParachainInfo,
ParachainSystem, Perbill, Proxy, RelayCurrencyId, RelaychainSovereignSubAccount, Runtime,
Salp, Scheduler, Session, SlotLength, System, Tokens, TreasuryPalletId, Utility, Vesting,
XTokens, XcmConfig,
};
pub use bifrost_runtime_common::constants::{currency::*, time::*};
pub use frame_support::parameter_types;
pub use sp_runtime::traits::AccountIdConversion;
}

fn run_to_block(n: u32) {
fn _run_to_block(n: u32) {
while System::block_number() < n {
Scheduler::on_finalize(System::block_number());
System::set_block_number(System::block_number() + 1);
Expand All @@ -75,7 +60,7 @@ fn run_to_block(n: u32) {
}
}

fn set_relaychain_block_number(number: BlockNumber) {
fn _set_relaychain_block_number(number: BlockNumber) {
ParachainSystem::on_initialize(number);

let (relay_storage_root, proof) =
Expand Down Expand Up @@ -183,21 +168,7 @@ fn parachain_subaccounts_are_unique() {
.into()
);

assert_eq!(RelaychainSovereignSubAccount::get(), create_x2_parachain_multilocation(0));

assert_eq!(
create_x2_parachain_multilocation(0),
MultiLocation::X2(
Junction::Parent,
Junction::AccountId32 {
network: NetworkId::Any,
id: [
90, 83, 115, 109, 142, 150, 241, 192, 7, 207, 13, 99, 10, 207, 82, 9, 178,
6, 17, 97, 122, 242, 60, 233, 36, 200, 226, 83, 40, 235, 93, 40
]
}
)
);
assert_eq!(RelaychainSovereignSubAccount::get(), create_x2_multilocation(0));
});
}

Expand Down
26 changes: 13 additions & 13 deletions integration-tests/src/kusama_cross_chain_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,24 @@

//! Cross-chain transfer tests within Kusama network.

use bifrost_runtime_common::*;
use frame_support::assert_ok;
use orml_traits::MultiCurrency;
use xcm::v0::{
Junction::{self, Parachain, Parent},
MultiAsset::*,
MultiLocation::*,
NetworkId,
};
use xcm::{latest::prelude::*, VersionedMultiAssets, VersionedMultiLocation};
use xcm_emulator::TestExt;

use crate::{integration_tests::*, kusama_test_net::*};

#[test]
fn transfer_from_relay_chain() {
Kusama::execute_with(|| {
KusamaNet::execute_with(|| {
assert_ok!(kusama_runtime::XcmPallet::reserve_transfer_assets(
kusama_runtime::Origin::signed(ALICE.into()),
X1(Parachain(2001)),
X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any }),
vec![ConcreteFungible { id: Null, amount: DOLLARS }],
Box::new(VersionedMultiLocation::V1(X1(Parachain(2001)).into())),
Box::new(VersionedMultiLocation::V1(
X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any }).into()
)),
Box::new(VersionedMultiAssets::V1((Here, DOLLARS).into())),
0,
600_000_000
));
});
Expand All @@ -58,12 +55,15 @@ fn transfer_to_relay_chain() {
Origin::signed(ALICE.into()),
RelayCurrencyId::get(),
DOLLARS,
X2(Parent, Junction::AccountId32 { id: BOB, network: NetworkId::Any }),
Box::new(MultiLocation::new(
1,
X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any })
)),
3_000_000_000
));
});

Kusama::execute_with(|| {
KusamaNet::execute_with(|| {
assert_eq!(kusama_runtime::Balances::free_balance(&AccountId::from(BOB)), 999_920_000_005);
});
}
9 changes: 4 additions & 5 deletions integration-tests/src/kusama_test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain
use crate::integration_tests::*;

decl_test_relay_chain! {
pub struct Kusama {
pub struct KusamaNet {
Runtime = kusama_runtime::Runtime,
XcmConfig = kusama_runtime::XcmConfig,
new_ext = kusama_ext(),
Expand All @@ -45,7 +45,7 @@ decl_test_parachain! {

decl_test_network! {
pub struct TestNet {
relay_chain = Kusama,
relay_chain = KusamaNet,
parachains = vec![
(2001, Bifrost),
],
Expand All @@ -69,7 +69,6 @@ fn default_parachains_host_configuration() -> HostConfiguration<BlockNumber> {
ump_service_total_weight: 4 * 1_000_000_000,
max_upward_message_size: 1024 * 1024,
max_upward_message_num_per_candidate: 5,
hrmp_open_request_ttl: 5,
hrmp_sender_deposit: 0,
hrmp_recipient_deposit: 0,
hrmp_channel_max_capacity: 8,
Expand Down Expand Up @@ -97,8 +96,8 @@ pub fn kusama_ext() -> sp_io::TestExternalities {

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![
(AccountId::from(ALICE), 1000 * DOLLARS),
(ParaId::from(2001).into_account(), 1000 * DOLLARS),
(AccountId::from(ALICE), 2002 * DOLLARS),
(ParaId::from(2001).into_account(), 2 * DOLLARS),
],
}
.assimilate_storage(&mut t)
Expand Down
2 changes: 1 addition & 1 deletion pallets/salp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ orml-tokens = "0.4.1-dev"
orml-currencies = "0.4.1-dev"
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10" }
bifrost-bancor = { path = "../../pallets/bancor" }
bifrost-runtime-common = { package = "bifrost-runtime-common", path = "../../runtime/common" }
bifrost-runtime = { path = "../../runtime/bifrost" }

[features]
default = ["std"]
Expand Down
5 changes: 2 additions & 3 deletions pallets/salp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// Ensure we're `no_std` when compiling for Wasm.

use bifrost_runtime_common::create_x2_multilocation;
use bifrost_runtime::create_x2_multilocation;
use frame_support::{
construct_runtime, parameter_types,
traits::{EnsureOrigin, GenesisBuild},
Expand Down Expand Up @@ -203,7 +202,7 @@ parameter_types! {
BRUCE,
CATHI
],2);
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(ALICE);
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(0);
pub SalpTransactProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived;
pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm;
}
Expand Down
16 changes: 12 additions & 4 deletions runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ use bifrost_flexible_fee::{
};
use bifrost_runtime_common::{
constants::parachains,
create_x2_multilocation,
xcm_impl::{
BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert,
BifrostFilteredAssets, BifrostXcmTransactFilter,
Expand Down Expand Up @@ -1152,6 +1151,16 @@ impl EnsureOrigin<Origin> for EnsureConfirmAsMultiSig {
}
}

pub fn create_x2_multilocation(index: u16) -> MultiLocation {
MultiLocation::new(
1,
X1(AccountId32 {
network: NetworkId::Any,
id: Utility::derivative_account_id(ParachainInfo::get().into_account(), index).into(),
}),
)
}

parameter_types! {
pub const MinContribution: Balance = DOLLARS / 10;
pub const RemoveKeysLimit: u32 = 500;
Expand All @@ -1169,15 +1178,14 @@ parameter_types! {
hex!["8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"].into(), // bob
hex!["90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22"].into(), // charlie
],2);
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(Utility::derivative_account_id(ParachainInfo::get().into_account(), ParachainDerivedProxyAccountType::Salp as u16));
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(ParachainDerivedProxyAccountType::Salp as u16);
pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm;
pub SalpProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived;
}

impl bifrost_salp::Config for Runtime {
type BancorPool = Bancor;
type BifrostXcmExecutor =
BifrostXcmAdaptor<XcmRouter, XcmWeight, IdentityFee<Balance>, SelfParaId>;
type BifrostXcmExecutor = BifrostXcmAdaptor<XcmRouter, XcmWeight, WeightToFee, SelfParaId>;
type Event = Event;
type LeasePeriod = LeasePeriod;
type MinContribution = MinContribution;
Expand Down
23 changes: 21 additions & 2 deletions runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ use bifrost_flexible_fee::{
};
use bifrost_runtime_common::{
constants::parachains,
create_x2_multilocation,
xcm_impl::{
BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert,
BifrostFilteredAssets, BifrostXcmTransactFilter,
Expand Down Expand Up @@ -766,6 +765,16 @@ pub type Trader = (
FixedRateOfFungible<KusdPerSecond, ToTreasury>,
);

pub fn create_x2_parachain_multilocation(index: u16) -> MultiLocation {
MultiLocation::new(
1,
X1(AccountId32 {
network: NetworkId::Any,
id: Utility::derivative_account_id(ParachainInfo::get().into_account(), index).into(),
}),
)
}

pub struct XcmConfig;
impl Config for XcmConfig {
type AssetTransactor = BifrostAssetTransactor;
Expand Down Expand Up @@ -1062,6 +1071,16 @@ impl EnsureOrigin<Origin> for EnsureConfirmAsMultiSig {
}
}

pub fn create_x2_multilocation(index: u16) -> MultiLocation {
MultiLocation::new(
1,
X1(AccountId32 {
network: NetworkId::Any,
id: Utility::derivative_account_id(ParachainInfo::get().into_account(), index).into(),
}),
)
}

parameter_types! {
pub const MinContribution: Balance = DOLLARS / 10;
pub const RemoveKeysLimit: u32 = 500;
Expand All @@ -1075,7 +1094,7 @@ parameter_types! {
pub ContributionWeight:XcmBaseWeight = 893125000.into();
pub AddProxyWeight:XcmBaseWeight = XCM_WEIGHT.into();
pub ConfirmMuitiSigAccount: AccountId = hex!["e4da05f08e89bf6c43260d96f26fffcfc7deae5b465da08669a9d008e64c2c63"].into();
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(Utility::derivative_account_id(ParachainInfo::get().into_account(), ParachainDerivedProxyAccountType::Salp as u16));
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(ParachainDerivedProxyAccountType::Salp as u16);
pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm;
pub SalpProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived;
}
Expand Down
5 changes: 0 additions & 5 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use node_primitives::{AccountId, BlockNumber};
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use sp_core::u32_trait::{_1, _2};
use sp_runtime::{FixedPointNumber, Perquintill};
use xcm::latest::prelude::*;

pub mod constants;
pub mod xcm_impl;
Expand Down Expand Up @@ -74,7 +73,3 @@ pub type EnsureRootOrAllTechnicalCommittee = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>,
>;

pub fn create_x2_multilocation(account: AccountId) -> MultiLocation {
MultiLocation::new(1, X1(AccountId32 { network: NetworkId::Any, id: account.into() }))
}
13 changes: 11 additions & 2 deletions runtime/dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ use bifrost_flexible_fee::{
};
use bifrost_runtime_common::{
constants::parachains,
create_x2_multilocation,
xcm_impl::{
BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert,
BifrostFilteredAssets, BifrostXcmTransactFilter,
Expand Down Expand Up @@ -1058,6 +1057,16 @@ impl EnsureOrigin<Origin> for EnsureConfirmAsMultiSig {
}
}

pub fn create_x2_multilocation(index: u16) -> MultiLocation {
MultiLocation::new(
1,
X1(AccountId32 {
network: NetworkId::Any,
id: Utility::derivative_account_id(ParachainInfo::get().into_account(), index).into(),
}),
)
}

parameter_types! {
pub const MinContribution: Balance = 1 * DOLLARS;
pub const BifrostCrowdloanId: PalletId = PalletId(*b"bf/salp#");
Expand All @@ -1075,7 +1084,7 @@ parameter_types! {
"ce6072037670ca8e974fd571eae4f215a58d0bf823b998f619c3f87a911c3541"
]
.into();
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(Utility::derivative_account_id(ParachainInfo::get().into_account(), ParachainDerivedProxyAccountType::Salp as u16));
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(ParachainDerivedProxyAccountType::Salp as u16);
pub SalpTransactProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived;
pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm;
}
Expand Down
4 changes: 2 additions & 2 deletions xcm-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<
relay: bool,
nonce: u32,
) -> Result<MessageId, XcmError> {
let SovereignAccount: AccountId = ParaId::from(SelfParaId::get()).into_account();
let sovereign_account: AccountId = ParaId::from(SelfParaId::get()).into_account();

let asset: MultiAsset = MultiAsset {
id: Concrete(MultiLocation::here()),
Expand All @@ -118,7 +118,7 @@ impl<
max_assets: u32::max_value(),
beneficiary: X1(Junction::AccountId32 {
network: NetworkId::Any,
id: SovereignAccount.into(),
id: sovereign_account.into(),
})
.into(),
},
Expand Down