Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Asset System - Implement asset-router #1189

Merged
merged 88 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
360f282
Add new asset types
sea212 Oct 31, 2023
6056a22
Add custom assets to runtime
sea212 Nov 1, 2023
8aa10a4
Add market assets to runtime
sea212 Nov 1, 2023
af23bd2
Add pallet_assets benchmark and weights
sea212 Nov 1, 2023
45ede95
Expose MarketAssets call enum
sea212 Nov 1, 2023
f35b626
Update todo comment to incluse issue number
sea212 Nov 1, 2023
5da2fe5
Add campaign assets instance to runtime
sea212 Nov 2, 2023
e61b6aa
Cargo fmt
sea212 Nov 2, 2023
cb4bfe8
Taplo fmt
sea212 Nov 2, 2023
0cb34be
Refine asset class types
sea212 Nov 6, 2023
5494862
Use efficient asset types
sea212 Nov 6, 2023
84e0a48
Add all variants to overarching Asset enum
sea212 Nov 6, 2023
48e64a9
Make MarketId compactable
sea212 Nov 6, 2023
31e0742
Adjust SerdeWrapper
sea212 Nov 6, 2023
ee8c902
Make Battery Station compileable
sea212 Nov 6, 2023
d7b7208
Make Zeitgeist compileable
sea212 Nov 6, 2023
a814a22
Cleanup code
sea212 Nov 6, 2023
910b18d
Remove NewForeignAsset
sea212 Nov 7, 2023
ee48d28
Implement asset type conversions
sea212 Nov 7, 2023
ef1a64a
Add Currency asset class
sea212 Nov 8, 2023
6ec09b5
Remove deprecated SerdeWrapper
sea212 Nov 8, 2023
623d203
Add Currencies asset class
sea212 Nov 8, 2023
2d6f46e
Add scale codec index matching tests
sea212 Nov 8, 2023
bf8edff
Add asset conversion tests
sea212 Nov 8, 2023
270313f
Update docstring
sea212 Nov 8, 2023
fe13122
Improve assets module structure
sea212 Nov 8, 2023
a0c4584
Update license
sea212 Nov 8, 2023
8be41b8
Create asset-router pallet scaffold
sea212 Nov 10, 2023
f730f0d
Start implementing all traits
sea212 Nov 10, 2023
aafc603
Implement MultiCurrency partially for asset-router
sea212 Nov 16, 2023
aca80c2
Implement MultiCurrency for asset-router
sea212 Nov 20, 2023
bfc6cae
Implement MultiCurrencyExtended
sea212 Nov 21, 2023
a15564b
MultiLockableCurrency
sea212 Nov 21, 2023
7e467ec
Implement MultiReservableCurrency
sea212 Nov 21, 2023
e83ff56
Implement NamedMultiReservableCurrency
sea212 Nov 21, 2023
f0136a8
Fix runtime
sea212 Nov 21, 2023
e85884d
Integrate asset-router in runtime
sea212 Nov 21, 2023
2cc33d6
Fix a couple of bugs
sea212 Nov 21, 2023
de4fa90
Prepare asset-router test environment
sea212 Nov 25, 2023
6c896a7
Start MultiCurrency test impl
sea212 Nov 26, 2023
c22597b
Complete MultiCurrency tests
sea212 Nov 27, 2023
5565194
Add MultiCurrencyExtended tests
sea212 Nov 29, 2023
f783037
Implement MultiReserveableCurrency tests
sea212 Nov 30, 2023
ebcb1f8
Implement NamedMultiReserveableCurrency tests
sea212 Nov 30, 2023
626751e
Implement MultiLockableCurrency tests
sea212 Nov 30, 2023
fea51dc
Improve test structure
sea212 Nov 30, 2023
eea1f42
Undo unnecessary change
sea212 Nov 30, 2023
c01b106
Format code
sea212 Nov 30, 2023
3fbb71d
Implement fungibles::{Create, Destroy, Inspect}
sea212 Dec 1, 2023
f0a8dc6
Remove comment
sea212 Dec 1, 2023
ccdf373
Add tests for Inspect impl
sea212 Dec 1, 2023
994e6c7
Add tests for Create impl
sea212 Dec 1, 2023
6f5f58e
Add tests for Destroy impl
sea212 Dec 1, 2023
628eb7a
Make asset types configurable
sea212 Dec 2, 2023
7e9423e
Use less restricitve traits for pm AssetManager
sea212 Dec 4, 2023
3ebe79c
Make project compilable
sea212 Dec 4, 2023
13f8123
Merge branch 'sea212-new-asset-system' into sea212-new-asset-system-p…
sea212 Jan 12, 2024
5139e1f
Update licenses
sea212 Jan 12, 2024
0c4cbb7
Merge branch 'sea212-new-asset-system' into sea212-new-asset-system-p…
sea212 Jan 12, 2024
d59ba4b
Repair tests partially
sea212 Jan 12, 2024
2c84931
Comment out irrelevant test
sea212 Jan 12, 2024
f98bf6c
Partially satisfy Clippy
sea212 Jan 12, 2024
0b019e0
Adjust XCM to use Currencies
sea212 Jan 16, 2024
a3339eb
Adjust XCM to use Currencies (zeitgeist runtime)
sea212 Jan 16, 2024
0a76d86
Adjust prediction markets tests
sea212 Jan 16, 2024
bc4f5f4
Adjust neo-swaps mock
sea212 Jan 16, 2024
14aa375
Satisfy Clippy
sea212 Jan 16, 2024
e78d0e2
Format code
sea212 Jan 16, 2024
20c1618
Update licenses
sea212 Jan 16, 2024
0d543ed
Remove pallet-asset benchmark helper from mock
sea212 Jan 16, 2024
5c1d02d
Format code
sea212 Jan 16, 2024
09d46f6
Repair tests with runtime-benchmarks
sea212 Jan 16, 2024
25b963b
Format code
sea212 Jan 16, 2024
0f13743
Remove TODO comment
sea212 Jan 17, 2024
eeb43e3
Implement log for unhandled errors in asset-router
sea212 Jan 17, 2024
e7c982a
Use log target
sea212 Jan 17, 2024
ff059c1
Improve and prettify readmes
sea212 Jan 22, 2024
62a1bd9
Use assert_noop! in favor of asset_err!
sea212 Jan 22, 2024
afe49bc
Make sea212 codeowner of zrml/asset-router
sea212 Jan 22, 2024
b038088
Fix typo
sea212 Jan 22, 2024
10f62f6
Rename variable
sea212 Jan 22, 2024
b4d365c
Better abs() overflow handling
sea212 Jan 22, 2024
bcaef0e
Check Bob's balance in MultiCurrency tests
sea212 Jan 22, 2024
5ebca55
Fix Create test for Currencies
sea212 Jan 23, 2024
396fed6
Improve test precision
sea212 Jan 23, 2024
f82addf
Verify total issuance via direct pallet invocation
sea212 Jan 23, 2024
cf6af07
Implement Inspect for Currencies
sea212 Jan 23, 2024
c317942
Satisfy Clippy
sea212 Jan 23, 2024
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
22 changes: 22 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ default-members = [
"runtime/battery-station",
"runtime/zeitgeist",
"zrml/authorized",
"zrml/asset-router",
"zrml/court",
"zrml/global-disputes",
"zrml/liquidity-mining",
Expand All @@ -29,6 +30,7 @@ members = [
"runtime/battery-station",
"runtime/zeitgeist",
"zrml/authorized",
"zrml/asset-router",
"zrml/court",
"zrml/global-disputes",
"zrml/liquidity-mining",
Expand Down Expand Up @@ -229,6 +231,7 @@ zrml-swaps-rpc = { path = "zrml/swaps/rpc" }
# Zeitgeist (wasm)
common-runtime = { path = "runtime/common", default-features = false }
zeitgeist-primitives = { path = "primitives", default-features = false }
zrml-asset-router = { path = "zrml/asset-router", default-features = false }
zrml-authorized = { path = "zrml/authorized", default-features = false }
zrml-court = { path = "zrml/court", default-features = false }
zrml-global-disputes = { path = "zrml/global-disputes", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/assets/campaign_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use super::*;
#[derive(
Clone, CompactAs, Copy, Debug, Decode, Default, Eq, Encode, MaxEncodedLen, PartialEq, TypeInfo,
)]
pub struct CampaignAssetClass(#[codec(compact)] pub(super) CampaignAssetId);
pub struct CampaignAssetClass(#[codec(compact)] pub CampaignAssetId);

impl From<Compact<CampaignAssetId>> for CampaignAssetClass {
fn from(value: Compact<CampaignAssetId>) -> CampaignAssetClass {
Expand Down
7 changes: 5 additions & 2 deletions primitives/src/assets/currencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

use super::*;

/// The `CurrencyClass` enum represents all non-ztg currencies.
/// The `CurrencyClass` enum represents all non-ztg CurrencyClass
// used in orml-tokens
maltekliemann marked this conversation as resolved.
Show resolved Hide resolved
#[cfg_attr(feature = "std", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
#[derive(Clone, Copy, Debug, Decode, Eq, Encode, MaxEncodedLen, PartialEq, TypeInfo)]
#[derive(
Clone, Copy, Debug, Decode, Eq, Encode, MaxEncodedLen, Ord, PartialEq, PartialOrd, TypeInfo,
)]
pub enum CurrencyClass<MI> {
// All "Old" variants will be removed once the lazy migration from
// orml-tokens to pallet-assets is complete
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/assets/custom_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::*;
#[derive(
Clone, CompactAs, Copy, Debug, Decode, Default, Eq, Encode, MaxEncodedLen, PartialEq, TypeInfo,
)]
pub struct CustomAssetClass(#[codec(compact)] pub(super) CustomAssetId);
pub struct CustomAssetClass(#[codec(compact)] pub CustomAssetId);

impl From<Compact<CustomAssetId>> for CustomAssetClass {
fn from(value: Compact<CustomAssetId>) -> CustomAssetClass {
Expand Down
19 changes: 18 additions & 1 deletion primitives/src/constants/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@
pub use super::*;
use crate::{
assets::Asset,
types::{Assets, Balance, Moment},
types::{Assets, Balance, Currencies, Moment},
};
use frame_support::{parameter_types, traits::LockIdentifier, PalletId};
use orml_traits::parameter_type_with_key;
use sp_arithmetic::Perbill;

// Assets
parameter_types! {
pub const AssetsAccountDeposit: Balance = 0;
pub const AssetsApprovalDeposit: Balance = 0;
pub const AssetsDeposit: Balance = 0;
pub const AssetsStringLimit: u32 = 256;
pub const AssetsMetadataDepositBase: Balance = 0;
pub const AssetsMetadataDepositPerByte: Balance = 0;
}

// Authorized
parameter_types! {
pub const AuthorizedPalletId: PalletId = PalletId(*b"zge/atzd");
Expand Down Expand Up @@ -164,6 +174,7 @@ parameter_types! {
pub const GetNativeCurrencyId: Assets = Asset::Ztg;
}

// Will be removed once asset-system is completely integerated
parameter_type_with_key! {
pub ExistentialDeposits: |currency_id: Assets| -> Balance {
match currency_id {
Expand All @@ -173,6 +184,12 @@ parameter_type_with_key! {
};
}

parameter_type_with_key! {
pub ExistentialDepositsNew: |_currency_id: Currencies| -> Balance {
1
};
}

// System
parameter_types! {
pub const BlockHashCount: u64 = 250;
Expand Down
7 changes: 2 additions & 5 deletions primitives/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ pub type Assets = Asset<MarketId>;
/// Asset type representing campaign assets
pub type CampaignAsset = CampaignAssetClass;

// ID type for campaign asset class
// ID type of the campaign asset class
pub type CampaignAssetId = u128;

/// Asset type representing custom assets
pub type CustomAsset = CustomAssetClass;

// ID type for campaign asset class
// ID type of the custom asset class
pub type CustomAssetId = u128;

// Asset type representing currencies (excluding ZTG)
Expand All @@ -102,9 +102,6 @@ pub type Currencies = CurrencyClass<MarketId>;
/// Asset type representing assets used by prediction markets
pub type MarketAsset = MarketAssetClass<MarketId>;

/// ID type for asset classes that anyone can create
pub type AssetId = u128;

/// The asset id specifically used for pallet_assets_tx_payment for
/// paying transaction fees in different assets.
/// Since the polkadot extension and wallets can't handle custom asset ids other than just u32,
Expand Down
2 changes: 2 additions & 0 deletions runtime/battery-station/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ xcm-executor = { workspace = true, optional = true }

common-runtime = { workspace = true }
zeitgeist-primitives = { workspace = true }
zrml-asset-router = { workspace = true }
zrml-authorized = { workspace = true }
zrml-court = { workspace = true }
zrml-global-disputes = { workspace = true, optional = true }
Expand Down Expand Up @@ -382,6 +383,7 @@ try-runtime = [
"orml-xtokens?/try-runtime",

# Zeitgeist runtime pallets
"zrml-asset-router/try-runtime",
"zrml-authorized/try-runtime",
"zrml-court/try-runtime",
"zrml-liquidity-mining/try-runtime",
Expand Down
13 changes: 8 additions & 5 deletions runtime/battery-station/src/integration_tests/xcm/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use xcm::{
latest::{Junction::Parachain, Junctions::X2, MultiLocation},
VersionedMultiLocation,
};
use zeitgeist_primitives::types::{Asset, CustomMetadata};
use zeitgeist_primitives::types::{Currencies, CustomMetadata};

pub(super) struct ExtBuilder {
balances: Vec<(AccountId, Assets, Balance)>,
Expand Down Expand Up @@ -71,6 +71,9 @@ impl ExtBuilder {
.balances
.into_iter()
.filter(|(_, currency_id, _)| *currency_id != native_currency_id)
.map(|(account_id, currency_id, initial_balance)| {
(account_id, currency_id.try_into().unwrap(), initial_balance)
})
.collect::<Vec<_>>(),
}
.assimilate_storage(&mut t)
Expand Down Expand Up @@ -103,10 +106,10 @@ pub const BOB: AccountId32 = AccountId32::new([1u8; 32]);
pub const PARA_ID_SIBLING: u32 = 3000;

/// IDs that are used to represent tokens from other chains
pub const FOREIGN_ZTG_ID: Asset<u128> = Assets::ForeignAsset(0);
pub const FOREIGN_PARENT_ID: Asset<u128> = Assets::ForeignAsset(1);
pub const FOREIGN_SIBLING_ID: Asset<u128> = Assets::ForeignAsset(2);
pub const BTC_ID: Asset<u128> = Assets::ForeignAsset(3);
pub const FOREIGN_ZTG_ID: Currencies = Currencies::ForeignAsset(0);
pub const FOREIGN_PARENT_ID: Currencies = Currencies::ForeignAsset(1);
pub const FOREIGN_SIBLING_ID: Currencies = Currencies::ForeignAsset(2);
pub const BTC_ID: Currencies = Currencies::ForeignAsset(3);

#[inline]
pub(super) const fn ztg(amount: Balance) -> Balance {
Expand Down
4 changes: 2 additions & 2 deletions runtime/battery-station/src/integration_tests/xcm/test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ pub(super) fn para_ext(parachain_id: u32) -> sp_io::TestExternalities {
ExtBuilder::default()
.set_balances(vec![
(ALICE, Assets::Ztg, ztg(10)),
(ALICE, FOREIGN_PARENT_ID, roc(10)),
(ZeitgeistTreasuryAccount::get(), FOREIGN_PARENT_ID, roc(1)),
(ALICE, FOREIGN_PARENT_ID.into(), roc(10)),
(ZeitgeistTreasuryAccount::get(), FOREIGN_PARENT_ID.into(), roc(1)),
])
.set_parachain_id(parachain_id)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ fn convert_any_registered_parent_multilocation() {
foreign_parent_multilocation()
);

assert_eq!(<AssetConvert as C2<_, _>>::convert(FOREIGN_PARENT_ID), None);
assert_eq!(<AssetConvert as C2<_, _>>::convert(Assets::from(FOREIGN_PARENT_ID)), None);

// Register parent as foreign asset in the Zeitgeist parachain
register_foreign_parent(None);

assert_eq!(
<AssetConvert as C1<_, _>>::convert(foreign_parent_multilocation()),
Ok(FOREIGN_PARENT_ID),
Ok(FOREIGN_PARENT_ID.into()),
);

assert_eq!(
<AssetConvert as C2<_, _>>::convert(FOREIGN_PARENT_ID),
<AssetConvert as C2<_, _>>::convert(Assets::from(FOREIGN_PARENT_ID)),
Some(foreign_parent_multilocation())
);
});
Expand All @@ -87,18 +87,18 @@ fn convert_any_registered_sibling_multilocation() {
foreign_sibling_multilocation()
);

assert_eq!(<AssetConvert as C2<_, _>>::convert(FOREIGN_SIBLING_ID), None);
assert_eq!(<AssetConvert as C2<_, _>>::convert(Assets::from(FOREIGN_SIBLING_ID)), None);

// Register sibling as foreign asset in the Zeitgeist parachain
register_foreign_sibling(None);

assert_eq!(
<AssetConvert as C1<_, _>>::convert(foreign_sibling_multilocation()),
Ok(FOREIGN_SIBLING_ID),
Ok(FOREIGN_SIBLING_ID.into()),
);

assert_eq!(
<AssetConvert as C2<_, _>>::convert(FOREIGN_SIBLING_ID),
<AssetConvert as C2<_, _>>::convert(Assets::from(FOREIGN_SIBLING_ID)),
Some(foreign_sibling_multilocation())
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn transfer_ztg_sibling_to_zeitgeist() {
assert_eq!(Tokens::free_balance(FOREIGN_ZTG_ID, &BOB), bob_initial_balance);
assert_ok!(XTokens::transfer(
RuntimeOrigin::signed(BOB),
FOREIGN_ZTG_ID,
FOREIGN_ZTG_ID.into(),
transfer_amount,
Box::new(
MultiLocation::new(
Expand Down Expand Up @@ -250,7 +250,7 @@ fn transfer_btc_zeitgeist_to_sibling() {
Zeitgeist::execute_with(|| {
assert_ok!(XTokens::transfer(
RuntimeOrigin::signed(ALICE),
BTC_ID,
BTC_ID.into(),
transfer_amount,
Box::new(
MultiLocation::new(
Expand Down Expand Up @@ -328,7 +328,7 @@ fn transfer_roc_to_relay_chain() {

assert_ok!(XTokens::transfer(
RuntimeOrigin::signed(ALICE),
FOREIGN_PARENT_ID,
FOREIGN_PARENT_ID.into(),
transfer_amount,
Box::new(
MultiLocation::new(1, X1(Junction::AccountId32 { id: BOB.into(), network: None }))
Expand Down
25 changes: 8 additions & 17 deletions runtime/battery-station/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,16 +497,17 @@ parameter_type_with_key! {
// are cleaned up automatically. In case of scalar outcomes, the market account can have dust.
// Unless LPs use `pool_exit_with_exact_asset_amount`, there can be some dust pool shares remaining.
// Explicit match arms are used to ensure new asset types are respected.
pub ExistentialDeposits: |currency_id: Assets| -> Balance {
pub ExistentialDeposits: |currency_id: Currencies| -> Balance {
match currency_id {
Asset::CategoricalOutcome(_,_) => ExistentialDeposit::get(),
Asset::PoolShare(_) => ExistentialDeposit::get(),
Asset::ScalarOutcome(_,_) => ExistentialDeposit::get(),
Currencies::OldCategoricalOutcome(_,_) => ExistentialDeposit::get(),
Currencies::OldParimutuelShare(_,_) => ExistentialDeposit::get(),
Currencies::OldPoolShare(_) => ExistentialDeposit::get(),
Currencies::OldScalarOutcome(_,_) => ExistentialDeposit::get(),
#[cfg(feature = "parachain")]
Asset::ForeignAsset(id) => {
Currencies::ForeignAsset(id) => {
let maybe_metadata = <
orml_asset_registry::Pallet<Runtime> as orml_traits::asset_registry::Inspect
>::metadata(&Asset::ForeignAsset(*id));
>::metadata(&Currencies::ForeignAsset(*id));

if let Some(metadata) = maybe_metadata {
return metadata.existential_deposit;
Expand All @@ -515,17 +516,7 @@ parameter_type_with_key! {
1
}
#[cfg(not(feature = "parachain"))]
Asset::ForeignAsset(_) => ExistentialDeposit::get(),
Asset::Ztg => ExistentialDeposit::get(),
Asset::ParimutuelShare(_,_) => ExistentialDeposit::get(),

// The following assets are irrelevant, as they are managed by pallet-assets
Asset::NewParimutuelShare(_,_)
| Asset::NewCategoricalOutcome(_, _)
| Asset::NewScalarOutcome(_,_)
| Asset::NewPoolShare(_)
| Asset::CustomAssetClass(_)
| Asset::CampaignAssetClass(_) => ExistentialDeposit::get(),
Currencies::ForeignAsset(_) => ExistentialDeposit::get(),
}
};
}
Expand Down
10 changes: 5 additions & 5 deletions runtime/battery-station/src/xcm_config/asset_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

use crate::{Assets, Balance};
use crate::{Balance, Currencies};
use orml_traits::asset_registry::{AssetMetadata, AssetProcessor};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
Expand All @@ -29,19 +29,19 @@ use zeitgeist_primitives::types::CustomMetadata;
/// Only pre check is to ensure an asset id was passed.
pub struct CustomAssetProcessor;

impl AssetProcessor<Assets, AssetMetadata<Balance, CustomMetadata>> for CustomAssetProcessor {
impl AssetProcessor<Currencies, AssetMetadata<Balance, CustomMetadata>> for CustomAssetProcessor {
fn pre_register(
id: Option<Assets>,
id: Option<Currencies>,
metadata: AssetMetadata<Balance, CustomMetadata>,
) -> Result<(Assets, AssetMetadata<Balance, CustomMetadata>), DispatchError> {
) -> Result<(Currencies, AssetMetadata<Balance, CustomMetadata>), DispatchError> {
match id {
Some(id) => Ok((id, metadata)),
None => Err(DispatchError::Other("asset-registry: AssetId is required")),
}
}

fn post_register(
_id: Assets,
_id: Currencies,
_asset_metadata: AssetMetadata<Balance, CustomMetadata>,
) -> Result<(), DispatchError> {
Ok(())
Expand Down
Loading
Loading