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

Migrate pallet-asset-conversion to umbrella crate #6548

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 1 addition & 6 deletions Cargo.lock

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

23 changes: 4 additions & 19 deletions substrate/frame/asset-conversion/ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { workspace = true }
log = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
pallet-asset-conversion = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-arithmetic = { workspace = true }

[dev-dependencies]
Expand All @@ -36,34 +31,24 @@ primitive-types = { features = ["codec", "num-traits", "scale-info"], workspace
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-asset-conversion/std",
"pallet-assets/std",
"pallet-balances/std",
"primitive-types/std",
"scale-info/std",
"sp-arithmetic/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-asset-conversion/try-runtime",
"pallet-assets/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
]
11 changes: 8 additions & 3 deletions substrate/frame/asset-conversion/ops/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@

use super::*;
use crate::Pallet as AssetConversionOps;
use frame::{benchmarking::prelude::*, traits::{fungibles::{Create, Inspect, Mutate}, One}, deps::sp_core::Get};
/*
use frame_benchmarking::{v2::*, whitelisted_caller};
use frame_support::{
assert_ok,
traits::fungibles::{Create, Inspect, Mutate},
};
use frame_system::RawOrigin as SystemOrigin;
*/
use pallet_asset_conversion::{BenchmarkHelper, Pallet as AssetConversion};
/*
use sp_core::Get;
use sp_runtime::traits::One;
*/

/// Provides a pair of amounts expected to serve as sufficient initial liquidity for a pool.
fn valid_liquidity_amount<T: Config>(ed1: T::Balance, ed2: T::Balance) -> (T::Balance, T::Balance)
Expand Down Expand Up @@ -113,7 +118,7 @@ where
mint_setup_fee_asset::<T>(caller, asset1, asset2, &lp_token);

assert_ok!(AssetConversion::<T>::create_pool(
SystemOrigin::Signed(caller.clone()).into(),
RawOrigin::Signed(caller.clone()).into(),
Box::new(asset1.clone()),
Box::new(asset2.clone())
));
Expand Down Expand Up @@ -142,7 +147,7 @@ mod benchmarks {
let (_, liquidity1, liquidity2) = create_asset_and_pool::<T>(&caller, &asset1, &asset2);

assert_ok!(AssetConversion::<T>::add_liquidity(
SystemOrigin::Signed(caller.clone()).into(),
RawOrigin::Signed(caller.clone()).into(),
Box::new(asset1.clone()),
Box::new(asset2.clone()),
liquidity1,
Expand All @@ -153,7 +158,7 @@ mod benchmarks {
));

#[extrinsic_call]
_(SystemOrigin::Signed(caller.clone()), Box::new(asset1.clone()), Box::new(asset2.clone()));
_(RawOrigin::Signed(caller.clone()), Box::new(asset1.clone()), Box::new(asset2.clone()));

let pool_id = T::PoolLocator::pool_id(&asset1, &asset2).unwrap();
let (prior_account, new_account) = AssetConversionOps::<T>::addresses(&pool_id).unwrap();
Expand Down
10 changes: 8 additions & 2 deletions substrate/frame/asset-conversion/ops/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,26 @@ pub use weights::WeightInfo;
extern crate alloc;

use alloc::boxed::Box;
/*
use frame_support::traits::{
fungible::{Inspect as FungibleInspect, Mutate as FungibleMutate},
fungibles::{roles::ResetTeam, Inspect, Mutate, Refund},
tokens::{Fortitude, Precision, Preservation},
AccountTouch,
};
*/
use frame::{prelude::*, traits::{fungible::{Inspect as FungibleInspect, Mutate as FungibleMutate}, fungibles::{roles::ResetTeam, Inspect, Mutate, Refund}, tokens::{Fortitude, Precision, Preservation}, AccountTouch, TryConvert, Zero}};
use pallet_asset_conversion::{PoolLocator, Pools};
use sp_runtime::traits::{TryConvert, Zero};
// use sp_runtime::traits::{TryConvert, Zero};

#[frame_support::pallet]
// #[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;
/*
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
*/

#[pallet::pallet]
pub struct Pallet<T>(_);
Expand Down
12 changes: 8 additions & 4 deletions substrate/frame/asset-conversion/ops/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

use crate as pallet_asset_conversion_ops;
use core::default::Default;
use frame::{prelude::*, testing_prelude::*, hashing::U256, arithmetic::Permill, runtime::{prelude::{construct_runtime, derive_impl, ord_parameter_types, parameter_types, EnsureSigned, EnsureSignedBy}}, traits::{AccountIdConversion, tokens::{fungible::{NativeFromLeft, NativeOrWithId, UnionOf}, imbalance::ResolveAssetTo}, AsEnsureOriginWithArg, ConstU32, ConstU64}, deps::frame_support::{PalletId, instances::{Instance1, Instance2}}};
/*
use frame_support::{
construct_runtime, derive_impl,
instances::{Instance1, Instance2},
Expand All @@ -33,10 +35,12 @@ use frame_support::{
PalletId,
};
use frame_system::{EnsureSigned, EnsureSignedBy};
*/
use pallet_asset_conversion::{self, AccountIdConverter, AccountIdConverterNoSeed, Ascending};
/*
use sp_arithmetic::Permill;
use sp_runtime::{traits::AccountIdConversion, BuildStorage};

*/
type Block = frame_system::mocking::MockBlock<Test>;

construct_runtime!(
Expand Down Expand Up @@ -97,7 +101,7 @@ pub type AscendingLocator = Ascending<u64, NativeOrWithId<u32>, PoolIdToAccountI
impl pallet_asset_conversion::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Balance = <Self as pallet_balances::Config>::Balance;
type HigherPrecisionBalance = sp_core::U256;
type HigherPrecisionBalance = U256;
type AssetKind = NativeOrWithId<u32>;
type Assets = NativeAndAssets;
type PoolId = (Self::AssetKind, Self::AssetKind);
Expand Down Expand Up @@ -130,7 +134,7 @@ impl pallet_asset_conversion_ops::Config for Test {
type WeightInfo = ();
}

pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
pub(crate) fn new_test_ext() -> TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<Test> {
Expand All @@ -139,7 +143,7 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
let mut ext = TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}
3 changes: 3 additions & 0 deletions substrate/frame/asset-conversion/ops/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! Asset Conversion Ops pallet tests.

use crate::{mock::*, *};
/*
use frame_support::{
assert_noop, assert_ok,
traits::{
Expand All @@ -26,6 +27,8 @@ use frame_support::{
Incrementable,
},
};
*/
use frame::{testing_prelude::*, traits::{fungible::{Inspect as FungibleInspect, NativeOrWithId}, fungibles::{Create, Inspect}, Incrementable}};

#[test]
fn migrate_pool_account_id_with_native() {
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/asset-conversion/ops/src/weights.rs

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