Skip to content

Commit

Permalink
Remove Assets Config from other pallets (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
HaidarJbeily7 committed May 20, 2024
1 parent 3ecae1b commit da0b88e
Show file tree
Hide file tree
Showing 160 changed files with 1,812 additions and 1,263 deletions.
2 changes: 2 additions & 0 deletions common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ macro_rules! mock_common_config {
impl common::Config for $runtime {
type DEXId = DEXId;
type LstId = LiquiditySourceType;
type MultiCurrency = currencies::Pallet<$runtime>;
type AssetManager = assets::Pallet<$runtime>;
}
};
}
Expand Down
282 changes: 278 additions & 4 deletions common/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,24 @@

use crate::prelude::{ManagementMode, QuoteAmount, SwapAmount, SwapOutcome};
use crate::{
Fixed, LiquiditySourceFilter, LiquiditySourceId, LiquiditySourceType, Oracle, PriceVariant,
PswapRemintInfo, RewardReason,
Amount, AssetId32, AssetName, AssetSymbol, BalancePrecision, ContentSource, Description, Fixed,
LiquiditySourceFilter, LiquiditySourceId, LiquiditySourceType, Oracle, PredefinedAssetId,
PriceVariant, PswapRemintInfo, RewardReason,
};
use frame_support::dispatch::DispatchResult;

use frame_support::dispatch::{DispatchResult, DispatchResultWithPostInfo};
use frame_support::pallet_prelude::MaybeSerializeDeserialize;
use frame_support::sp_runtime::traits::BadOrigin;
use frame_support::sp_runtime::DispatchError;
use frame_support::weights::Weight;
use frame_support::Parameter;
use frame_system::pallet_prelude::OriginFor;
use frame_system::RawOrigin;
use orml_traits::{
MultiCurrency, MultiCurrencyExtended, MultiLockableCurrency, MultiReservableCurrency,
};
use sp_core::{Get, H256};
use sp_runtime::traits::Member;
//FIXME maybe try info or try from is better than From and Option.
//use sp_std::convert::TryInto;
use crate::alt::DiscreteQuotation;
Expand Down Expand Up @@ -522,9 +530,34 @@ pub trait LiquidityRegistry<

pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type DexIdOf<T> = <T as Config>::DEXId;
pub type AssetIdOf<T> = <<T as Config>::AssetManager as AssetManager<
T,
AssetSymbol,
AssetName,
BalancePrecision,
ContentSource,
Description,
>>::AssetId;
pub type CurrencyIdOf<T> = <<T as Config>::MultiCurrency as MultiCurrency<
<T as frame_system::Config>::AccountId,
>>::CurrencyId;
pub type AmountOf<T> = <<T as Config>::MultiCurrency as MultiCurrencyExtended<
<T as frame_system::Config>::AccountId,
>>::Amount;

pub type GetBaseAssetIdOf<T> = <<T as Config>::AssetManager as AssetManager<
T,
AssetSymbol,
AssetName,
BalancePrecision,
ContentSource,
Description,
>>::GetBaseAssetId;

pub type BalanceOf<T> = <<T as Config>::MultiCurrency as MultiCurrency<AccountIdOf<T>>>::Balance;

/// Common DEX trait. Used for DEX-related pallets.
pub trait Config: frame_system::Config + currencies::Config {
pub trait Config: frame_system::Config {
/// DEX identifier.
type DEXId: Parameter
+ MaybeSerializeDeserialize
Expand All @@ -538,6 +571,7 @@ pub trait Config: frame_system::Config + currencies::Config {
+ Eq
+ PartialEq
+ MaxEncodedLen;

type LstId: Clone
+ Copy
+ Encode
Expand All @@ -546,6 +580,24 @@ pub trait Config: frame_system::Config + currencies::Config {
+ PartialEq
+ MaxEncodedLen
+ From<crate::primitives::LiquiditySourceType>;

type AssetManager: AssetManager<
Self,
AssetSymbol,
AssetName,
BalancePrecision,
ContentSource,
Description,
>;

/// Currency to transfer, reserve/unreserve, lock/unlock assets
type MultiCurrency: MultiLockableCurrency<
Self::AccountId,
Moment = Self::BlockNumber,
CurrencyId = AssetIdOf<Self>,
Balance = Balance,
> + MultiReservableCurrency<Self::AccountId, CurrencyId = AssetIdOf<Self>, Balance = Balance>
+ MultiCurrencyExtended<Self::AccountId, Amount = Amount>;
}

/// Definition of a pending atomic swap action. It contains the following three phrases:
Expand Down Expand Up @@ -1097,6 +1149,228 @@ impl<AssetId, AccountId, AssetSymbol, AssetName, BalancePrecision, ContentSource
}
}

pub trait AssetManager<
T: Config,
AssetSymbol,
AssetName,
BalancePrecision,
ContentSource,
Description,
>
{
type AssetId: Parameter
+ Member
+ Copy
+ MaybeSerializeDeserialize
+ Ord
+ Default
+ From<AssetId32<PredefinedAssetId>>
+ From<H256>
+ Into<H256>
+ Into<CurrencyIdOf<T>>
+ MaxEncodedLen;

type GetBaseAssetId: Get<Self::AssetId>;

#[allow(clippy::too_many_arguments)]
fn register_from(
account_id: &T::AccountId,
symbol: AssetSymbol,
name: AssetName,
precision: BalancePrecision,
initial_supply: Balance,
is_mintable: bool,
opt_content_src: Option<ContentSource>,
opt_desc: Option<Description>,
) -> Result<Self::AssetId, DispatchError>;

fn update_balance(
origin: OriginFor<T>,
who: T::AccountId,
currency_id: CurrencyIdOf<T>,
amount: AmountOf<T>,
) -> DispatchResult;

fn gen_asset_id_from_any(value: &impl Encode) -> Self::AssetId;

#[allow(clippy::too_many_arguments)]
fn register_asset_id(
account_id: T::AccountId,
asset_id: Self::AssetId,
symbol: AssetSymbol,
name: AssetName,
precision: BalancePrecision,
initial_supply: Balance,
is_mintable: bool,
opt_content_src: Option<ContentSource>,
opt_desc: Option<Description>,
) -> DispatchResult;

fn burn_from(
asset_id: &Self::AssetId,
issuer: &T::AccountId,
from: &T::AccountId,
amount: Balance,
) -> DispatchResult;

fn transfer_from(
asset_id: &Self::AssetId,
from: &T::AccountId,
to: &T::AccountId,
amount: Balance,
) -> DispatchResult;

fn mint_to(
asset_id: &Self::AssetId,
issuer: &T::AccountId,
to: &T::AccountId,
amount: Balance,
) -> DispatchResult;

fn mint_unchecked(
asset_id: &Self::AssetId,
to: &T::AccountId,
amount: Balance,
) -> DispatchResult;

fn burn(
origin: OriginFor<T>,
asset_id: Self::AssetId,
amount: Balance,
) -> DispatchResultWithPostInfo;

fn mint(
origin: OriginFor<T>,
asset_id: Self::AssetId,
to: T::AccountId,
amount: Balance,
) -> DispatchResultWithPostInfo;

#[allow(clippy::too_many_arguments)]
fn register(
origin: OriginFor<T>,
symbol: AssetSymbol,
name: AssetName,
initial_supply: Balance,
is_mintable: bool,
is_indivisible: bool,
opt_content_src: Option<ContentSource>,
opt_desc: Option<Description>,
) -> DispatchResultWithPostInfo;
}

impl<T: Config, AssetSymbol, AssetName, BalancePrecision, ContentSource, Description>
AssetManager<T, AssetSymbol, AssetName, BalancePrecision, ContentSource, Description> for ()
{
type AssetId = AssetId32<PredefinedAssetId>;
type GetBaseAssetId = ();

fn register_from(
_account_id: &T::AccountId,
_symbol: AssetSymbol,
_name: AssetName,
_precision: BalancePrecision,
_initial_supply: Balance,
_is_mintable: bool,
_opt_content_src: Option<ContentSource>,
_opt_desc: Option<Description>,
) -> Result<Self::AssetId, DispatchError> {
unimplemented!()
}

fn update_balance(
_origin: OriginFor<T>,
_who: T::AccountId,
_currency_id: CurrencyIdOf<T>,
_amount: AmountOf<T>,
) -> DispatchResult {
unimplemented!()
}

fn gen_asset_id_from_any(_value: &impl Encode) -> Self::AssetId {
unimplemented!()
}

fn register_asset_id(
_account_id: T::AccountId,
_asset_id: Self::AssetId,
_symbol: AssetSymbol,
_name: AssetName,
_precision: BalancePrecision,
_initial_supply: Balance,
_is_mintable: bool,
_opt_content_src: Option<ContentSource>,
_opt_desc: Option<Description>,
) -> DispatchResult {
unimplemented!()
}

fn burn_from(
_asset_id: &Self::AssetId,
_issuer: &<T as frame_system::Config>::AccountId,
_from: &<T as frame_system::Config>::AccountId,
_amount: Balance,
) -> DispatchResult {
unimplemented!()
}

fn transfer_from(
_asset_id: &Self::AssetId,
_from: &<T as frame_system::Config>::AccountId,
_to: &<T as frame_system::Config>::AccountId,
_amount: Balance,
) -> DispatchResult {
unimplemented!()
}

fn mint_to(
_asset_id: &Self::AssetId,
_issuer: &<T as frame_system::Config>::AccountId,
_to: &<T as frame_system::Config>::AccountId,
_amount: Balance,
) -> DispatchResult {
unimplemented!()
}

fn mint_unchecked(
_asset_id: &Self::AssetId,
_to: &T::AccountId,
_amount: Balance,
) -> DispatchResult {
unimplemented!()
}

fn burn(
_origin: OriginFor<T>,
_asset_id: Self::AssetId,
_amount: Balance,
) -> DispatchResultWithPostInfo {
unimplemented!()
}

fn mint(
_origin: OriginFor<T>,
_asset_id: Self::AssetId,
_to: <T as frame_system::Config>::AccountId,
_amount: Balance,
) -> DispatchResultWithPostInfo {
unimplemented!()
}

fn register(
_origin: OriginFor<T>,
_symbol: AssetSymbol,
_name: AssetName,
_initial_supply: Balance,
_is_mintable: bool,
_is_indivisible: bool,
_opt_content_src: Option<ContentSource>,
_opt_desc: Option<Description>,
) -> DispatchResultWithPostInfo {
unimplemented!()
}
}

pub trait SyntheticInfoProvider<AssetId> {
fn is_synthetic(asset_id: &AssetId) -> bool;

Expand Down
1 change: 0 additions & 1 deletion pallets/apollo-platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ codec = { package = "parity-scale-codec", version = "3", default-features = fals
scale-info = { version = "2", default-features = false, features = ["derive"] }
frame-support = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false }
frame-system = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false }
assets = { path = "../assets", default-features = false }
common = { path = "../../common", default-features = false }
sp-io = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false }
sp-std = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false }
Expand Down
Loading

0 comments on commit da0b88e

Please sign in to comment.