Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
fix asset-registry pallet README
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardoaraujor committed Oct 7, 2022
1 parent fb5769e commit 410acf8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 45 deletions.
49 changes: 5 additions & 44 deletions pallets/asset-registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The `asset-registry` pallet provides a solution to this problem by implementing

This trait is used by a struct (`AsAssetMultiLocation<AssetId, AssetIdInfoGetter>`) that is added to the runtime (as an extra XCM primitive) and used as the `xcm_executor::traits::Convert<MultiLocation, AssetId>` implementor needed by the `ConvertedConcreteAssetId` of `FungiblesAdapter`.

The pallet needs to be used in conjunction with the [`xcm-primitives` crate](https://github.com/paritytech/trappist/tree/master/primitives/xcm) or an equivalent implementation.

## Configuration

### Types
Expand Down Expand Up @@ -51,49 +53,6 @@ Unregister a Reserve Asset.

## How to add `pallet-asset-registry` to a runtime

### XCM Primitives

Create a new crate called `xcm-primitives` with the following contents on its `lib.rs`:
```rust
#![cfg_attr(not(feature = "std"), no_std)]

use sp_std::{borrow::Borrow, marker::PhantomData};
use xcm::latest::MultiLocation;

pub struct AsAssetMultiLocation<AssetId, AssetIdInfoGetter>(
PhantomData<(AssetId, AssetIdInfoGetter)>,
);
impl<AssetId, AssetIdInfoGetter> xcm_executor::traits::Convert<MultiLocation, AssetId>
for AsAssetMultiLocation<AssetId, AssetIdInfoGetter>
where
AssetId: Clone,
AssetIdInfoGetter: AssetMultiLocationGetter<AssetId>,
{
fn convert_ref(asset_multi_location: impl Borrow<MultiLocation>) -> Result<AssetId, ()> {
if let Some(asset_id) = AssetIdInfoGetter::get_asset_id(asset_multi_location.borrow().clone().into()) {
Ok(asset_id)
} else {
Err(())
}
}

fn reverse_ref(asset_id: impl Borrow<AssetId>) -> Result<MultiLocation, ()> {
if let Some(asset_multi_location) =
AssetIdInfoGetter::get_asset_multi_location(asset_id.borrow().clone())
{
Ok(asset_multi_location)
} else {
Err(())
}
}
}

pub trait AssetMultiLocationGetter<AssetId> {
fn get_asset_multi_location(asset_id: AssetId) -> Option<MultiLocation>;
fn get_asset_id(asset_multi_location: MultiLocation) -> Option<AssetId>;
}
```

### Runtime's `Cargo.toml`

Add `pallet-assets`, `pallet-asset-registry` and `xcm-primitives` to the dependencies:
Expand All @@ -111,8 +70,10 @@ git = "https://github.com/paritytech/trappist.git"
branch = "master"

[dependencies.xcm-primitives]
path = "path/to/xcm-primitives/crate"
version = "0.1.0"
default-features = false
git = "https://github.com/paritytech/trappist.git"
branch = "master"
```

Update the runtime's `std` feature:
Expand Down
2 changes: 1 addition & 1 deletion primitives/xcm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xcm-primitives"
version = "0.1.0"
version = "0.0.1"
edition = "2021"

[dependencies]
Expand Down

0 comments on commit 410acf8

Please sign in to comment.