Shawn Tabrizi's xcm workshop and video are a good start for learning how to implement XCM. I've also found that compiling and opening polkadots docs to access public documentation for XCM to be very useful too. It helps to make sense of all the different traits and components used in different xcm configurations. (I'm not sure there's a public site that hosts this documentation yet).
The LocalAssetTransactor
type is an abstraction for the xcm-executor to transact assets on a local chain. This includes things like depositing assets, withdrawing assests, transferring assets, etc.
The documentation on the AssetTransactor
type describes it as
How to withdraw and deposit an asset.
And the trait, TransactAsset
required for the type AssetTransactor
is described with
Facility for asset transacting.
This should work with as many asset/location combinations as possible. Locations to support may include non-account locations such as a MultiLocation::X1(Junction::Parachain). Different chains may handle them in different ways.
Can be amalgamated as a tuple of items that implement this trait. In such executions, if any of the transactors returns Ok(()), then it will short circuit. Else, execution is passed to the next transactor.
The CurrencyAdapter
struct present in both the parachain-template
and darwinia
setup you're referencing implements this TransactAsset
trait.
We can then learn that the second generic on the struct CurrencyAdapter
implements a trait MatchesFungible
which returns an Option<Balance>
if there is a fungible asset matching IsConcrete
on the system. The IsConcrete
describes which asset we want to match. In parachain_template
's case, IsConcrete
is matching against the Relay chain asset (DOT/KSM/ROC), in Darwinia's case it is matching against Darwinias native asset. Therefore, the currency transactor will transact in Darwinia native currency on Darwinia, or in the relay chain's currency on parachain-template. If the currency in the MultiAsset
does not match in either cases (i.e it's not Dot/Roc/Ksm or not Darwinia), the xcm transaction will error out.
Relay Chain location for parachain-templates 'isConcrete':
pub const RelayLocation: MultiLocation = MultiLocation::parent();
Darwinia Location:
pub AnchoringSelfReserve: MultiLocation = MultiLocation::new(
0,
X1(PalletInstance(<Balances as PalletInfoAccess>::index() as u8))
);
Darwinia location has 0 parents and describes it's own balances
pallet, which deals with operations for the native token. The naming for Darwinia's location may be a bit confusing, but it's referencing that Darwinia chain is the reserve ("Self Reserve") for it's own Darwinia token. "Anchoring" refers to the relative location type, as in the location from the perspective of Darwinia.
You can also learn a bunch by reading through docs other parachains have created for XCM. Moonbeams documentation is pretty good and i'm sure there are other parachain team docs out there too