Skip to content

Commit

Permalink
Girazoki local assets (#1279)
Browse files Browse the repository at this point in the history
* Add new instance of pallet-assets

* start building allowance for local asset creation

* Local Asset creator implementation

* Add local asset transactor

* Add local asset

* Add dual support in moonbase

* Add tests for proving both representations are handled

* Typescript tests for reanchoring

* Cleaning and documenting

* More docu

* fix docu of teleports

* EditorConfig

* more editorconfig

* Add selfreserve cross chain possibility to moonriver

* Fix compilation error after cleanup

* Add MOVR cross chain transferring to moonriver

* clean more

* Adapt to new schema with local and foreign assets

* wip

* Add small test

* wip working with assetId as nonce+account

* wip test asset

* Re-use same precompiles for foreign and local assets but prevent someone from calling non-local methods for foreign assets

* Mint test

* check balance too

* All functions written

* Test every single precompile func

* First typescript tests working

* Keep adding tests that work

* First test suite ready

* more and more tests

* Local assets final typescript tests

* Adapt to prefixes and fill moonriver too

* Add back foreign assets tests

* unused import

* Remove hash dependency

* Make moonbeam compile

* Adapt xcm tests and integration tests in moonbase

* Tests and removal of is_sufficient for local assets

* Add couple of tests receiving local assets

* fmt and asset-manager unitests

* Fix also asset precompile tests

* Fix all unitests for moonbeam and moonriver runtimeS

* Modify moonriver tests

* Use extrinsic index and parent hash to calculate asset id

* remove unused var

* Prettier

* Make benchmark compile

* Fix tests

* Remove unwraps and update comment

* Comments

* Remove it.only

* Remove authorization once registered

* Benchmark authorize local asset creation

* Creation of local asset benchmarks

* Benchmarked new instructions

* Use new function maybe_total_supply

* Update typescript tests

* Improve comments

* uncomment evm

* More doc

* Fix benchmarking

* prettier

* currency::MOVR

* Fix typo in LocalAssetCreationAuthorization

* Fix typo in authorize_local_assset

* Fix typo

* Leave weight of register_foreign_asset equal

* Fix conflicts

* Benchmark compile

* Editorconfig

* Editorconfig sources.ts

* Editorconfig mock hrmp

* Editorconfig test precompile local assets

* Moonbase: add more integration tests

* Moonriver: more tests

* More tests

* Fix test glmr cannot be sent through xcm

* FMT

* Clean and fix typescript tests

* start usign the local counter!

* Change runtime and tests

* Update typescript

* Update typescript test

* Start

* More version bumps

* Bump toolchain version

* Incremental progress

* Start working on this

* Make things a bit cleaner and include the evm removal

* Further check in assets

* Fix integration tests

* FMT

* Unitest the new destroy asset

* editorconfig

* Test asset manager prettier

* FMT

* Better doc

* Doc better runtime parameters

* fmt and editorconfig

* change asset account deposit

* Merge left overs from destroy asset

* Prevent local assets from calling destroy directly

* Default unimplemented for trait, making moonbeam runtime a bit cleaner

* Add test destroy local asset

* Create local asset to asset-manager typescript test

* Use v0.9.18 branches

* Update Cargo.lock

* Update ethereum crate to 0.12

* Integration test for asset destroy local

* More updated doc

* More cleanup: use ConstBool from substrate

* change rocksdb weight for the proper associated type in frame system

* Update Cargo.lock

* Update nimbus

* Update Cargo.lock

* Bump ORML

* Import Reserve from xcm_primitives instead of orml_traits

* Bump crowdloan-rewards

* Remove u32_trait

* Minimal orml_xtokens config

* Update Cargo.lock

* Remove creator from creation of local asset id

* FMT

* Comment why we dont need to store additioanl info in the case of local assets

* add copy for destroy witness associated type

* Add weight annotation explanation

* FMT

* Add comment on why we prevent calling destroy

* More comments related to old reanchoring

* Add IsLocal and IsFOreign types

* asset config for moonbase

* Separate asset config for moonriver

* Separate asset config in moonbeam runtime

* Increase deposits for local assets

* Remove ExecutiveBody

* ERC20 local extended interface

* Import parameter_types again

* Remove unused xcm dep

* Fix integration tests

* Creation deposit of 0 to run bechmark

* Update weights and value of deposit used for benchmark

* Update error in weights

* Correct fixing this time

* Add build_inprocess_relay_chain fn

* Update Cargo.lock

* Bump scale-info (again)

* Use build_inprocess_relay_chain

* Fix typo

* Use blank CollatorOptions in StartFulLNodeParams

* Bump nimbus to 46c43d8

* Bump nimbus to d68bf7

* Add sync params to MappingSyncWorker

* Incremental work to make tests build

* Add orml-traits crate for tests

* Explicit integer types

* Comment out xtokens tests for now

* Add some WeightInfo, remove some WeightInfo

* More mock fixes

* Remove TransactionStorageMode

* Reflect EthBlockDataCacheTask changes in Frontier and plumb prometheus_registry

* Restore pallet_evm WeightInfo in mocks

* Update Cargo.lock

* Bump frontier from 3e9d2b8 c65ff27

* Use purestake evm branch moonbeam-polkadot-v0.9.18

* Updates to use custom evm branch

* Put reserve stuff in asset-manager

* Start adapting runtimes to new sufficient local asset design

* Adapt moonriver too

* adapt all runtimes and tests

* Asset as sufficients in typescript tests

* Fix benchmark

* Fix unitests

* Add more comments

* Assetinfo tests

* FMT

* Editorconfig

* Update weights

* Add back wrongly removed Statemine test

* Use built-in xcmp_queue weights

* Remove unused dependency

* Point to fixed frontier version with-code evm

* Add orml-traits again but without default-features

* Fix xtokens precompiles tests

* More graceful error plus removal of unused imports

* Chop long line

* Move write to inside branch

* Toml sort

* Assert ts test storage with deposit

* cargo fmt

* Clippy suggestions

* Optimize other extrinsic too

* Bump polkadot from 721282d to f0dc95a

* Construct staking GenesisConfig without recursion

* Another clippy suggestion

* Add reads and writes from benchmarking to register-local-asset

* Add comments to address PR reviews

* Change hasher of LocalAssetDeposit

* Remove duplicate definition

* Comment about reverting in EVM code remove

* Add better test description

* Test asset manager

Co-authored-by: Stephen Shelton <[email protected]>
  • Loading branch information
girazoki and notlesh authored Apr 4, 2022
1 parent f8435f4 commit 01b01b1
Show file tree
Hide file tree
Showing 47 changed files with 37,166 additions and 1,002 deletions.
117 changes: 95 additions & 22 deletions pallets/asset-manager/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,39 @@

#![cfg(feature = "runtime-benchmarks")]

use crate::{Call, Config, Pallet};
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};
use crate::{pallet::LocalAssetIdCreator, Call, Config, DepositBalanceOf, Pallet};
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
use frame_support::traits::{Currency, Get};
use frame_system::RawOrigin;
use xcm::latest::prelude::*;

///RLocal asset deposit amount
fn min_candidate_stk<T: Config>() -> DepositBalanceOf<T> {
<<T as Config>::LocalAssetDeposit as Get<DepositBalanceOf<T>>>::get()
}

/// Create a funded user.
/// Used for generating the necessary amount for local assets
fn create_funded_user<T: Config>(
string: &'static str,
n: u32,
extra: DepositBalanceOf<T>,
) -> (T::AccountId, DepositBalanceOf<T>) {
const SEED: u32 = 0;
let user = account(string, n, SEED);
let min_reserve_amount = min_candidate_stk::<T>();
let total = min_reserve_amount + extra;
T::Currency::make_free_balance_be(&user, total);
T::Currency::issue(total);
(user, total)
}

benchmarks! {
// This where clause allows us to create assetTypes
where_clause { where T::AssetType: From<MultiLocation> }
register_asset {
// This where clause allows us to create ForeignAssetTypes
where_clause { where T::ForeignAssetType: From<MultiLocation> }
register_foreign_asset {
// does not really matter what we register
let asset_type = T::AssetType::default();
let asset_type = T::ForeignAssetType::default();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
let asset_id: T::AssetId = asset_type.clone().into();
Expand All @@ -40,19 +62,34 @@ benchmarks! {
// We make it dependent on the number of existing assets already
let x in 5..100;
for i in 0..x {
let asset_type: T::AssetType = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into();
let asset_type: T::ForeignAssetType = MultiLocation::new(
0,
X1(GeneralIndex(i as u128))
).into();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
Pallet::<T>::register_asset(RawOrigin::Root.into(), asset_type.clone(), metadata, amount, true)?;
Pallet::<T>::register_foreign_asset(
RawOrigin::Root.into(),
asset_type.clone(),
metadata,
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}

// does not really matter what we register, as long as it is different than the previous
let asset_type = T::AssetType::default();
let asset_type = T::ForeignAssetType::default();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
let asset_id: T::AssetId = asset_type.clone().into();
Pallet::<T>::register_asset(RawOrigin::Root.into(), asset_type.clone(), metadata, amount, true)?;
Pallet::<T>::register_foreign_asset(
RawOrigin::Root.into(),
asset_type.clone(),
metadata,
amount,
true
)?;

}: _(RawOrigin::Root, asset_type.clone(), 1, x)
verify {
Expand All @@ -64,20 +101,25 @@ benchmarks! {
// We make it dependent on the number of existing assets already
let x in 5..100;
for i in 0..x {
let asset_type: T::AssetType = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into();
let asset_type: T::ForeignAssetType = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
Pallet::<T>::register_asset(RawOrigin::Root.into(), asset_type.clone(), metadata, amount, true)?;
Pallet::<T>::register_foreign_asset(
RawOrigin::Root.into(),
asset_type.clone(),
metadata,
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}

let new_asset_type = T::AssetType::default();
let asset_type_to_be_changed: T::AssetType = MultiLocation::new(
let new_asset_type = T::ForeignAssetType::default();
let asset_type_to_be_changed: T::ForeignAssetType = MultiLocation::new(
0,
X1(GeneralIndex((x-1) as u128))
).into();
let asset_id_to_be_changed = asset_type_to_be_changed.into();

}: _(RawOrigin::Root, asset_id_to_be_changed, new_asset_type.clone(), x)
verify {
assert_eq!(Pallet::<T>::asset_id_type(asset_id_to_be_changed), Some(new_asset_type.clone()));
Expand All @@ -89,13 +131,19 @@ benchmarks! {
// We make it dependent on the number of existing assets already
let x in 5..100;
for i in 0..x {
let asset_type: T::AssetType = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into();
let asset_type: T::ForeignAssetType = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
Pallet::<T>::register_asset(RawOrigin::Root.into(), asset_type.clone(), metadata, amount, true)?;
Pallet::<T>::register_foreign_asset(
RawOrigin::Root.into(),
asset_type.clone(),
metadata,
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}
let asset_type_to_be_removed: T::AssetType = MultiLocation::new(
let asset_type_to_be_removed: T::ForeignAssetType = MultiLocation::new(
0,
X1(GeneralIndex((x-1) as u128))
).into();
Expand All @@ -106,19 +154,45 @@ benchmarks! {
assert_eq!(Pallet::<T>::asset_type_units_per_second(asset_type_to_be_removed), None);
}

register_local_asset {
const USER_SEED: u32 = 1;
let (caller, deposit_amount) = create_funded_user::<T>("caller", USER_SEED, 0u32.into());
let asset_id = T::LocalAssetIdCreator::create_asset_id_from_metadata(0);
let owner: T::AccountId = account("account id", 1u32, 0u32);
let current_local_counter: u128 =Pallet::<T>::local_asset_counter();
let min_balance: T::Balance = 1u32.into();

}: _(
RawOrigin::Root,
caller.clone(),
owner.clone(),
true,
min_balance.clone()
)
verify {
assert_eq!(Pallet::<T>::local_asset_counter(), current_local_counter+1);
assert!(Pallet::<T>::local_asset_deposit(asset_id).is_some());

}
remove_existing_asset_type {
// We make it dependent on the number of existing assets already
// Worst case is we need to remove it from SupportedAAssetsFeePayment too
let x in 5..100;
for i in 0..x {
let asset_type: T::AssetType = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into();
let asset_type: T::ForeignAssetType = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
Pallet::<T>::register_asset(RawOrigin::Root.into(), asset_type.clone(), metadata, amount, true)?;
Pallet::<T>::register_foreign_asset(
RawOrigin::Root.into(),
asset_type.clone(),
metadata,
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}

let asset_type_to_be_removed: T::AssetType = MultiLocation::new(
let asset_type_to_be_removed: T::ForeignAssetType = MultiLocation::new(
0,
X1(GeneralIndex((x-1) as u128))
).into();
Expand All @@ -128,7 +202,6 @@ benchmarks! {
assert!(Pallet::<T>::asset_id_type(asset_id).is_none());
assert!(Pallet::<T>::asset_type_units_per_second(&asset_type_to_be_removed).is_none());
assert!(!Pallet::<T>::supported_fee_payment_assets().contains(&asset_type_to_be_removed));

}
}

Expand Down
Loading

0 comments on commit 01b01b1

Please sign in to comment.