I'm working on a Substrate pallet, and I have a custom associated type AssetId. I need to convert an AccountId into this AssetId. My Config trait looks like this:
#[pallet::config]
pub trait Config: frame_system::Config + TypeInfo + pallet_contracts::Config {
/// Pallet ID.
#[pallet::constant]
type PalletId: Get<PalletId>;
/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The currency trait.
type Currency: Currency<Self::AccountId>;
/// The balance type for assets (i.e. tokens).
type AssetBalance: Balance
+ FixedPointOperand
+ MaxEncodedLen
+ MaybeSerializeDeserialize
+ TypeInfo;
// Two-way conversion between asset and currency balances
type AssetToCurrencyBalance: Convert<Self::AssetBalance, BalanceOf<Self>>;
type CurrencyToAssetBalance: Convert<BalanceOf<Self>, Self::AssetBalance>;
/// The asset ID type.
type AssetId: MaybeSerializeDeserialize
+ MaxEncodedLen
+ TypeInfo
+ Clone
+ Debug
+ PartialEq
+ EncodeLike
+ Decode;
/// The type for tradable assets.
type Assets: Inspect<Self::AccountId, AssetId = Self::AssetId, Balance = Self::AssetBalance>
+ Transfer<Self::AccountId>;
/// The type for liquidity tokens.
type AssetRegistry: Inspect<Self::AccountId, AssetId = Self::AccountId, Balance = Self::AssetBalance>
+ Mutate<Self::AccountId>
+ Create<Self::AccountId>
+ Destroy<Self::AccountId>;
/// Information on runtime weights.
type WeightInfo: WeightInfo;
/// Provider fee numerator.
#[pallet::constant]
type ProviderFeeNumerator: Get<BalanceOf<Self>>;
/// Provider fee denominator.
#[pallet::constant]
type ProviderFeeDenominator: Get<BalanceOf<Self>>;
/// Minimum currency deposit for a new exchange.
#[pallet::constant]
type MinDeposit: Get<BalanceOf<Self>>;
}
this is the function i need to convert <T as SysConfig>::AccountId to <T as pallet::Config>::AssetId
.
#[pallet::call_index(0)]
#[pallet::weight(<T as Config>::WeightInfo::create_exchange())]
#[transactional]
pub fn create_exchange(
origin: OriginFor<T>,
asset_id: AssetIdOf<T>,
liquidity_token_id: AssetIdOf<T>,
currency_amount: BalanceOf<T>,
token_amount: BalanceOf<T>,
) -> DispatchResult {
// -------------------------- Validation part --------------------------
let caller = ensure_signed(origin)?;
let exchange = Exchange {
asset_id: asset_id.clone(),
currency_reserve: <BalanceOf<T>>::zero(),
token_reserve: <AssetBalanceOf<T>>::zero(),
liquidity_token_id: liquidity_token_id.clone(),
};
Ok(())
}
and this is my strct :
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
pub struct Exchange<T: Config> {
pub asset_id: T::AccountId,
pub currency_reserve: BalanceOf<T>,
pub token_reserve: AssetBalanceOf<T>,
pub liquidity_token_id: T::AccountId,
}
i have to use T::AccountId for call contract for some actions :
let result = pallet_contracts::Pallet::<T>::bare_call(
origin.clone(),
contract_address.clone(),
contracts_value,
gas_limit,
None,
data,
false,
pallet_contracts::Determinism::Deterministic,
);
and use AssetId
for using T::AssetRegistry::mint_into
.
T::AssetRegistry::mint_into(
exchange.liquidity_token_id.clone(),
&provider,
liquidity_minted,
)?;
when i need to rin this code it show me this error :
mismatched types expected associated type
<T as pallet::Config>::AssetId
found associated type<T as SysConfig>::AccountId
how can i sovle this problem ?