# XCMP Investigation
* [xcm format](https://github.com/paritytech/xcm-format)
* [implementation](https://w3f.github.io/parachain-implementers-guide)
* [examples](https://p-adek.tower.im/p/io5i?)
# workflow

# xcm types
## transact
### call data(pallet & call index required)
```
#[derive(Encode, Decode)]
pub enum RelayTemplatePalletCall {
#[codec(index = 100)] // the index should match the position of the module in `construct_runtime!`
DoSomething(DoSomethingCall),
}
#[derive(Encode, Decode)]
pub enum DoSomethingCall {
#[codec(index = 0)] // the index should match the position of the dispatchable in the target pallet
Something(u32),
}
#[derive(Encode, Decode)]
pub enum CrowdloanPalletCall {
#[codec(index = 27)] // the index should match the position of the module in `construct_runtime!`
CrowdloanContribute(ContributeCall),
}
#[derive(Debug, PartialEq, Encode, Decode)]
pub struct Contribution {
#[codec(compact)]
index: ParaId,
#[codec(compact)]
value: BalanceOf,
signature: Option<MultiSignature>,
}
#[derive(Encode, Decode)]
pub enum ContributeCall {
#[codec(index = 1)] // the index should match the position of the dispatchable in the target pallet
Contribute(Contribution),
}
```
### format
```
let call = RelayTemplatePalletCall::DoSomething(DoSomethingCall::Something(some_value)).encode();
let msg = Xcm::Transact {
origin_type: OriginKind::SovereignAccount,
require_weight_at_most: u64::MAX,
call: call.into(),
};
```
## asset transfer
### DepositReserveAsset
```
Xcm::WithdrawAsset {
assets: vec![MultiAsset::ConcreteFungible {
id: location,
amount: amount.into(),
}],
effects: vec![
Order::BuyExecution {
fees: MultiAsset::All,
weight: 0,
debt,
halt_on_error: false,
xcm: vec![]
},
Order::DepositReserveAsset {
assets: vec![MultiAsset::All],
dest: MultiLocation::X1(
Junction::Parent,
),
effects: vec![
Order::DepositAsset {
assets: vec![MultiAsset::All],
dest: MultiLocation::X1(Junction::AccountId32 {
network: NetworkId::Any,
id: T::AccountId32Converter::convert(account),
}),
}],
}],
}
```
## Teleport
```
let msg = Xcm::WithdrawAsset {
assets:vec![MultiAsset::ConcreteFungible { id: MultiLocation::Null, amount: some_value }],
effects: vec![
Order::BuyExecution {
fees: MultiAsset::All,
weight: 0,
debt,
halt_on_error: false,
xcm: vec![]
},
Order::InitiateTeleport {
assets: vec![MultiAsset::All],
dest: MultiLocation::X1(Junction::Parachain(para_id)),
effects: vec![
Order::BuyExecution {
fees: MultiAsset::All,
weight: 0,
debt,
halt_on_error: false,
xcm: vec![]
},
Order::DepositAsset {
assets: vec![MultiAsset::All],
dest: MultiLocation::X1(account_32.clone()),
},
]
}
]
};
```
## test code
[relax xcm filter](https://github.com/bifrost-finance/bifrost/pull/117)
[callable function](https://github.com/yrong/cumulus/blob/394c41bb72b668177fa5246d239fb681c08a6a56/polkadot-parachains/pallets/ping/src/lib.rs#L245-L449)
## test envirionment
```
host:bifrost-build-machine
relaychain:19944
parachain:19947
```
## todo
* [implement bifrost AssetTransactor](https://github.com/paritytech/cumulus/blob/16b7b72271901a1486e5fdea30723df9eece53b2/polkadot-parachains/rococo-runtime/src/lib.rs#L275-L286)
* integrate with salp
* trace the progress of xcm polkadot
* other xcm type test&hrmp test