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

spike foreign fungibles v2 #474

Draft
wants to merge 3 commits into
base: main
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
8 changes: 6 additions & 2 deletions pallets/api/src/fungibles/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
assert_ok,
traits::{
fungibles::{
approvals::{Inspect as ApprovalInspect, Mutate},

Check warning on line 8 in pallets/api/src/fungibles/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `Inspect`

warning: unused import: `Inspect` --> pallets/api/src/fungibles/benchmarking.rs:8:16 | 8 | approvals::{Inspect as ApprovalInspect, Mutate}, | ^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
Create, Inspect,
},
Currency,
Expand All @@ -15,7 +15,7 @@
use sp_runtime::traits::Zero;

use super::{
AccountIdOf, AssetsInstanceOf, AssetsOf, BalanceOf, Call, Config, Pallet, Read, TokenIdOf,

Check failure on line 18 in pallets/api/src/fungibles/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

unresolved imports `super::AssetsInstanceOf`, `super::AssetsOf`

error[E0432]: unresolved imports `super::AssetsInstanceOf`, `super::AssetsOf` --> pallets/api/src/fungibles/benchmarking.rs:18:15 | 18 | AccountIdOf, AssetsInstanceOf, AssetsOf, BalanceOf, Call, Config, Pallet, Read, TokenIdOf, | ^^^^^^^^^^^^^^^^ ^^^^^^^^ no `AssetsOf` in `fungibles` | | | no `AssetsInstanceOf` in `fungibles`
};
use crate::Read as _;

Expand All @@ -41,11 +41,11 @@
#[benchmark]
fn approve(a: Linear<0, 1>, c: Linear<0, 1>) -> Result<(), BenchmarkError> {
let token_id = TokenIdOf::<T>::zero();
let min_balance = <BalanceOf<T>>::from(1u32);

Check failure on line 44 in pallets/api/src/fungibles/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the trait bound `<T as fungibles::pallet::Config>::Balance: std::convert::From<u32>` is not satisfied

error[E0277]: the trait bound `<T as fungibles::pallet::Config>::Balance: std::convert::From<u32>` is not satisfied --> pallets/api/src/fungibles/benchmarking.rs:44:22 | 44 | let min_balance = <BalanceOf<T>>::from(1u32); | ^^^^^^^^^^^^ the trait `std::convert::From<u32>` is not implemented for `<T as fungibles::pallet::Config>::Balance`
let owner: AccountIdOf<T> = account("Alice", 0, SEED);
let spender: AccountIdOf<T> = account("Bob", 0, SEED);
let current_allowance = <BalanceOf<T>>::from(u32::MAX / 2);

Check failure on line 47 in pallets/api/src/fungibles/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the trait bound `<T as fungibles::pallet::Config>::Balance: std::convert::From<u32>` is not satisfied

error[E0277]: the trait bound `<T as fungibles::pallet::Config>::Balance: std::convert::From<u32>` is not satisfied --> pallets/api/src/fungibles/benchmarking.rs:47:28 | 47 | let current_allowance = <BalanceOf<T>>::from(u32::MAX / 2); | ^^^^^^^^^^^^ the trait `std::convert::From<u32>` is not implemented for `<T as fungibles::pallet::Config>::Balance`
T::Currency::make_free_balance_be(&owner, u32::MAX.into());

Check failure on line 48 in pallets/api/src/fungibles/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

ambiguous associated type `Currency` in bounds of `T`

error[E0221]: ambiguous associated type `Currency` in bounds of `T` --> pallets/api/src/fungibles/benchmarking.rs:48:3 | 48 | T::Currency::make_free_balance_be(&owner, u32::MAX.into()); | ^^^^^^^^^^^ ambiguous associated type `Currency` | = note: associated type `Currency` could derive from `pallet_assets::Config<<T as fungibles::pallet::Config>::TrustBackedAssetsInstance>` = note: associated type `Currency` could derive from `pallet_assets::Config<<T as fungibles::pallet::Config>::ForeignAssetsInstance>`
// Set the `current_allowance`.
assert_ok!(<AssetsOf<T> as Create<AccountIdOf<T>>>::create(
token_id.clone(),
Expand Down Expand Up @@ -90,7 +90,7 @@
// When the allowance was cancelled and then approved with the new value.
1 => approval_value,
// When the allowance was increased.
0 => approval_value - current_allowance,

Check failure on line 93 in pallets/api/src/fungibles/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot subtract `<T as fungibles::pallet::Config>::Balance` from `<T as fungibles::pallet::Config>::Balance`

error[E0369]: cannot subtract `<T as fungibles::pallet::Config>::Balance` from `<T as fungibles::pallet::Config>::Balance` --> pallets/api/src/fungibles/benchmarking.rs:93:25 | 93 | 0 => approval_value - current_allowance, | -------------- ^ ----------------- <T as fungibles::pallet::Config>::Balance | | | <T as fungibles::pallet::Config>::Balance
_ => unreachable!("`c` can only be 0 or 1"),
};
assert_has_event::<T>(
Expand All @@ -108,10 +108,14 @@

#[benchmark]
// Storage: `Assets`
fn total_supply() {
fn total_supply(a: Linear<0, 1>) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not tested but I was thinking to implement it this way if we went this route.

#[block]
{
Pallet::<T>::read(Read::TotalSupply(TokenIdOf::<T>::zero()));
match a {
0 => Pallet::<T>::read(Read::TotalSupply(TokenIdOf::<T>::TrustBacked(0))),

Check failure on line 115 in pallets/api/src/fungibles/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

mismatched types

error[E0308]: mismatched types --> pallets/api/src/fungibles/benchmarking.rs:115:74 | 115 | 0 => Pallet::<T>::read(Read::TotalSupply(TokenIdOf::<T>::TrustBacked(0))), | --------------------------- ^ expected associated type, found integer | | | arguments to this enum variant are incorrect | = note: expected associated type `<T as pallet_assets::Config<<T as fungibles::pallet::Config>::TrustBackedAssetsInstance>>::AssetId` found type `{integer}` = help: consider constraining the associated type `<T as pallet_assets::Config<<T as fungibles::pallet::Config>::TrustBackedAssetsInstance>>::AssetId` to `{integer}` or calling a method that returns `<T as pallet_assets::Config<<T as fungibles::pallet::Config>::TrustBackedAssetsInstance>>::AssetId` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html note: tuple variant defined here --> pallets/api/src/fungibles/mod.rs:44:2 | 44 | TrustBacked(TrustId), | ^^^^^^^^^^^
1 =>
Pallet::<T>::read(Read::TotalSupply(TokenIdOf::<T>::Foreign(Location::Parent))),

Check failure on line 117 in pallets/api/src/fungibles/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `Location`

error[E0433]: failed to resolve: use of undeclared type `Location` --> pallets/api/src/fungibles/benchmarking.rs:117:66 | 117 | Pallet::<T>::read(Read::TotalSupply(TokenIdOf::<T>::Foreign(Location::Parent))), | ^^^^^^^^ use of undeclared type `Location` | help: consider importing this struct | 36 + use std::panic::Location; |
}

Check failure on line 118 in pallets/api/src/fungibles/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

mismatched types

error[E0308]: mismatched types --> pallets/api/src/fungibles/benchmarking.rs:114:4 | 114 | / match a { 115 | | 0 => Pallet::<T>::read(Read::TotalSupply(TokenIdOf::<T>::TrustBacked(0))), 116 | | 1 => 117 | | Pallet::<T>::read(Read::TotalSupply(TokenIdOf::<T>::Foreign(Location::Parent))), 118 | | } | | ^- help: consider using a semicolon here: `;` | |_____________| | expected `()`, found `ReadResult<T>` | = note: expected unit type `()` found enum `fungibles::pallet::ReadResult<T>`
}
}
#[benchmark]
Expand Down
254 changes: 218 additions & 36 deletions pallets/api/src/fungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
//! goal is to provide a simplified, consistent API that adheres to standards in the smart contract
//! space.

use frame_support::traits::fungibles::{metadata::Inspect as MetadataInspect, Inspect};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
__private::RuntimeDebug,
pallet_prelude::TypeInfo,
traits::fungibles::{metadata::Inspect as MetadataInspect, Inspect},
};
pub use pallet::*;
use pallet_assets::WeightInfo as AssetsWeightInfoTrait;
use weights::WeightInfo;
Expand All @@ -13,16 +18,49 @@
mod tests;
pub mod weights;

type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
type TokenIdOf<T> = <AssetsOf<T> as Inspect<<T as frame_system::Config>::AccountId>>::AssetId;
type TokenIdParameterOf<T> = <T as pallet_assets::Config<AssetsInstanceOf<T>>>::AssetIdParameter;
type AssetsOf<T> = pallet_assets::Pallet<T, AssetsInstanceOf<T>>;
type AssetsErrorOf<T> = pallet_assets::Error<T, AssetsInstanceOf<T>>;
type AssetsInstanceOf<T> = <T as Config>::AssetsInstance;
type AssetsWeightInfoOf<T> = <T as pallet_assets::Config<AssetsInstanceOf<T>>>::WeightInfo;
type BalanceOf<T> = <AssetsOf<T> as Inspect<<T as frame_system::Config>::AccountId>>::Balance;
type TrustBackedTokenIdParameterOf<T> =
<T as pallet_assets::Config<TrustBackedAssetsInstanceOf<T>>>::AssetIdParameter;
type ForeignTokenIdParameterOf<T> =
<T as pallet_assets::Config<ForeignAssetsInstanceOf<T>>>::AssetIdParameter;

type TrustBackedAssetsOf<T> = pallet_assets::Pallet<T, TrustBackedAssetsInstanceOf<T>>;
type ForeignAssetsOf<T> = pallet_assets::Pallet<T, ForeignAssetsInstanceOf<T>>;

type TrustBackedAssetsErrorOf<T> = pallet_assets::Error<T, TrustBackedAssetsInstanceOf<T>>;
type ForeignAssetsErrorOf<T> = pallet_assets::Error<T, ForeignAssetsInstanceOf<T>>;

type TrustBackedAssetsInstanceOf<T> = <T as Config>::TrustBackedAssetsInstance;
type ForeignAssetsInstanceOf<T> = <T as Config>::ForeignAssetsInstance;

type TrustBackedAssetsWeightInfoOf<T> =
<T as pallet_assets::Config<TrustBackedAssetsInstanceOf<T>>>::WeightInfo;
type ForeignAssetsWeightInfoOf<T> =
<T as pallet_assets::Config<ForeignAssetsInstanceOf<T>>>::WeightInfo;
type WeightOf<T> = <T as Config>::WeightInfo;

// Our unified asset identifier type. The variant determines which asset instance to call.
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub enum MultiAssetId<TrustId, ForeignId> {
TrustBacked(TrustId),
Foreign(ForeignId),
}

/// Renamed to TokenIdOf for minimal changes.
/// It wraps the asset ID from:
/// - the trust‑backed instance (using `TrustBackedAssetsInstanceOf<T>`), and
/// - the foreign instance (using `ForeignAssetsInstanceOf<T>`).
type TokenIdOf<T> = MultiAssetId<
<pallet_assets::Pallet<T, TrustBackedAssetsInstanceOf<T>> as Inspect<
<T as frame_system::Config>::AccountId,
>>::AssetId,
<pallet_assets::Pallet<T, ForeignAssetsInstanceOf<T>> as Inspect<
<T as frame_system::Config>::AccountId,
>>::AssetId,
>;

type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
type BalanceOf<T> = <T as Config>::Balance;

#[frame_support::pallet]
pub mod pallet {
use core::cmp::Ordering::*;
Expand All @@ -42,13 +80,44 @@
use super::*;

/// Configure the pallet by specifying the parameters and types on which it depends.
///
/// It now requires two asset instances:
/// - `TrustBackedAssetsInstance`: used for trust‑backed assets (formerly the sole instance),
/// - `ForeignAssetsInstance`: used for foreign assets.
#[pallet::config]
pub trait Config: frame_system::Config + pallet_assets::Config<Self::AssetsInstance> {
pub trait Config:
frame_system::Config
+ pallet_assets::Config<Self::TrustBackedAssetsInstance>
+ pallet_assets::Config<Self::ForeignAssetsInstance>
{
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The instance of pallet-assets.
type AssetsInstance;
/// Weight information for dispatchables in this pallet.
/// The asset instance for trust‑backed assets (renamed from the old AssetsInstance).
type TrustBackedAssetsInstance;
/// The asset instance for foreign assets.
type ForeignAssetsInstance;
type Balance: Parameter
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complex Balance type unfortunately

+ MaybeSerializeDeserialize
+ Default
+ Copy
+ Into<
<pallet_assets::Pallet<Self, Self::TrustBackedAssetsInstance> as Inspect<
<Self as frame_system::Config>::AccountId,
>>::Balance,
> + From<
<pallet_assets::Pallet<Self, Self::TrustBackedAssetsInstance> as Inspect<
<Self as frame_system::Config>::AccountId,
>>::Balance,
> + Into<
<pallet_assets::Pallet<Self, Self::ForeignAssetsInstance> as Inspect<
<Self as frame_system::Config>::AccountId,
>>::Balance,
> + From<
<pallet_assets::Pallet<Self, Self::ForeignAssetsInstance> as Inspect<
<Self as frame_system::Config>::AccountId,
>>::Balance,
>;
/// Weight information for dispatchable functions in this pallet.
type WeightInfo: WeightInfo;
}

Expand Down Expand Up @@ -94,6 +163,14 @@
},
}

// A helper function to compute the weight parameter based on the token variant.
fn weight_param<T: Config>(token: &TokenIdOf<T>) -> u32 {
match token {
MultiAssetId::TrustBacked(_) => 0,
MultiAssetId::Foreign(_) => 1,
}
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Transfers `value` amount of tokens from the caller's account to account `to`.
Expand All @@ -103,20 +180,38 @@
/// - `to` - The recipient account.
/// - `value` - The number of tokens to transfer.
#[pallet::call_index(3)]
#[pallet::weight(AssetsWeightInfoOf::<T>::transfer_keep_alive())]
#[pallet::weight(
if weight_param::<T> (& token) == 0 {
TrustBackedAssetsWeightInfoOf::<T>::transfer_keep_alive()
} else {
ForeignAssetsWeightInfoOf::<T>::transfer_keep_alive()
}
)]
pub fn transfer(
origin: OriginFor<T>,
token: TokenIdOf<T>,
to: AccountIdOf<T>,
value: BalanceOf<T>,
) -> DispatchResult {
let from = ensure_signed(origin.clone())?;
AssetsOf::<T>::transfer_keep_alive(
origin,
token.clone().into(),
T::Lookup::unlookup(to.clone()),
value,
)?;
match token.clone() {
MultiAssetId::TrustBacked(id) => {
TrustBackedAssetsOf::<T>::transfer_keep_alive(
origin,
id.into(),
T::Lookup::unlookup(to.clone()),
value.into(),
)?;
},
MultiAssetId::Foreign(id) => {
ForeignAssetsOf::<T>::transfer_keep_alive(
origin,
id.into(),
T::Lookup::unlookup(to.clone()),
value.into(),
)?;
},
}
Self::deposit_event(Event::Transfer { token, from: Some(from), to: Some(to), value });
Ok(())
}
Expand All @@ -130,7 +225,7 @@
/// - `to` - The recipient account.
/// - `value` - The number of tokens to transfer.
#[pallet::call_index(4)]
#[pallet::weight(AssetsWeightInfoOf::<T>::transfer_approved())]

Check failure on line 228 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsWeightInfoOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsWeightInfoOf` --> pallets/api/src/fungibles/mod.rs:228:20 | 228 | #[pallet::weight(AssetsWeightInfoOf::<T>::transfer_approved())] | ^^^^^^^^^^^^^^^^^^ | | | use of undeclared type `AssetsWeightInfoOf` | help: a trait with a similar name exists: `AssetsWeightInfoTrait`
pub fn transfer_from(
origin: OriginFor<T>,
token: TokenIdOf<T>,
Expand All @@ -138,7 +233,7 @@
to: AccountIdOf<T>,
value: BalanceOf<T>,
) -> DispatchResult {
AssetsOf::<T>::transfer_approved(

Check failure on line 236 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:236:4 | 236 | AssetsOf::<T>::transfer_approved( | ^^^^^^^^ use of undeclared type `AssetsOf`
origin,
token.clone().into(),
T::Lookup::unlookup(from.clone()),
Expand All @@ -165,19 +260,19 @@
) -> DispatchResultWithPostInfo {
let owner = ensure_signed(origin.clone())
.map_err(|e| e.with_weight(WeightOf::<T>::approve(0, 0)))?;
let current_allowance = AssetsOf::<T>::allowance(token.clone(), &owner, &spender);

Check failure on line 263 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:263:28 | 263 | let current_allowance = AssetsOf::<T>::allowance(token.clone(), &owner, &spender); | ^^^^^^^^ use of undeclared type `AssetsOf`

let weight = match value.cmp(&current_allowance) {

Check failure on line 265 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

`<T as fungibles::pallet::Config>::Balance` is not an iterator

error[E0599]: `<T as fungibles::pallet::Config>::Balance` is not an iterator --> pallets/api/src/fungibles/mod.rs:265:29 | 265 | let weight = match value.cmp(&current_allowance) { | ^^^ `<T as fungibles::pallet::Config>::Balance` is not an iterator | = note: the following trait bounds were not satisfied: `<T as fungibles::pallet::Config>::Balance: std::iter::Iterator` which is required by `&mut <T as fungibles::pallet::Config>::Balance: std::iter::Iterator`
// If the new value is equal to the current allowance, do nothing.
Equal => WeightOf::<T>::approve(0, 0),
// If the new value is greater than the current allowance, approve the difference
// because `approve_transfer` works additively (see `pallet-assets`).
Greater => {
AssetsOf::<T>::approve_transfer(

Check failure on line 271 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:271:6 | 271 | AssetsOf::<T>::approve_transfer( | ^^^^^^^^ use of undeclared type `AssetsOf`
origin,
token.clone().into(),
T::Lookup::unlookup(spender.clone()),
value.saturating_sub(current_allowance),

Check failure on line 275 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

the method `saturating_sub` exists for associated type `<T as Config>::Balance`, but its trait bounds were not satisfied

error[E0599]: the method `saturating_sub` exists for associated type `<T as Config>::Balance`, but its trait bounds were not satisfied --> pallets/api/src/fungibles/mod.rs:275:13 | 275 | value.saturating_sub(current_allowance), | ^^^^^^^^^^^^^^ method cannot be called on `<T as Config>::Balance` due to unsatisfied trait bounds | = note: the following trait bounds were not satisfied: `<T as fungibles::pallet::Config>::Balance: frame_support::pallet_prelude::Zero` which is required by `<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `<T as fungibles::pallet::Config>::Balance: frame_support::pallet_prelude::One` which is required by `<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `<T as fungibles::pallet::Config>::Balance: std::cmp::PartialOrd` which is required by `<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `<T as fungibles::pallet::Config>::Balance: frame_support::pallet_prelude::CheckedMul` which is required by `<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `<T as fungibles::pallet::Config>::Balance: sp_runtime::traits::Bounded` which is required by `<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `<T as fungibles::pallet::Config>::Balance: num_traits::ops::saturating::Saturating` which is required by `<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&<T as fungibles::pallet::Config>::Balance: frame_support::pallet_prelude::Zero` which is required by `&<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&<T as fungibles::pallet::Config>::Balance: frame_support::pallet_prelude::One` which is required by `&<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&<T as fungibles::pallet::Config>::Balance: std::cmp::PartialOrd` which is required by `&<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&<T as fungibles::pallet::Config>::Balance: frame_support::pallet_prelude::CheckedMul` which is required by `&<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&<T as fungibles::pallet::Config>::Balance: sp_runtime::traits::Bounded` which is required by `&<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&<T as fungibles::pallet::Config>::Balance: num_traits::ops::saturating::Saturating` which is required by `&<T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&mut <T as fungibles::pallet::Config>::Balance: std::clone::Clone` which is required by `&mut <T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&mut <T as fungibles::pallet::Config>::Balance: frame_support::pallet_prelude::Zero` which is required by `&mut <T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&mut <T as fungibles::pallet::Config>::Balance: frame_support::pallet_prelude::One` which is required by `&mut <T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&mut <T as fungibles::pallet::Config>::Balance: std::cmp::PartialOrd` which is required by `&mut <T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&mut <T as fungibles::pallet::Config>::Balance: frame_support::pallet_prelude::CheckedMul` which is required by `&mut <T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&mut <T as fungibles::pallet::Config>::Balance: sp_runtime::traits::Bounded` which is required by `&mut <T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating` `&mut <T as fungibles::pallet::Config>::Balance: num_traits::ops::saturating::Saturating` which is required by `&mut <T as fungibles::pallet::Config>::Balance: sp_runtime::Saturating`
)
.map_err(|e| e.with_weight(WeightOf::<T>::approve(1, 0)))?;
WeightOf::<T>::approve(1, 0)
Expand All @@ -185,18 +280,18 @@
// If the new value is less than the current allowance, cancel the approval and
// set the new value.
Less => {
let token_param: TokenIdParameterOf<T> = token.clone().into();

Check failure on line 283 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find type `TokenIdParameterOf` in this scope

error[E0412]: cannot find type `TokenIdParameterOf` in this scope --> pallets/api/src/fungibles/mod.rs:283:23 | 283 | let token_param: TokenIdParameterOf<T> = token.clone().into(); | ^^^^^^^^^^^^^^^^^^ not found in this scope
let spender_source = T::Lookup::unlookup(spender.clone());
AssetsOf::<T>::cancel_approval(

Check failure on line 285 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:285:6 | 285 | AssetsOf::<T>::cancel_approval( | ^^^^^^^^ use of undeclared type `AssetsOf`
origin.clone(),
token_param.clone(),
spender_source.clone(),
)
.map_err(|e| e.with_weight(WeightOf::<T>::approve(0, 1)))?;
if value.is_zero() {

Check failure on line 291 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

no method named `is_zero` found for associated type `<T as fungibles::pallet::Config>::Balance` in the current scope

error[E0599]: no method named `is_zero` found for associated type `<T as fungibles::pallet::Config>::Balance` in the current scope --> pallets/api/src/fungibles/mod.rs:291:15 | 291 | if value.is_zero() { | ^^^^^^^ method not found in `<T as Config>::Balance`
WeightOf::<T>::approve(0, 1)
} else {
AssetsOf::<T>::approve_transfer(

Check failure on line 294 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:294:7 | 294 | AssetsOf::<T>::approve_transfer( | ^^^^^^^^ use of undeclared type `AssetsOf`
origin,
token_param,
spender_source,
Expand Down Expand Up @@ -226,14 +321,14 @@
) -> DispatchResultWithPostInfo {
let owner = ensure_signed(origin.clone())
.map_err(|e| e.with_weight(WeightOf::<T>::approve(0, 0)))?;
AssetsOf::<T>::approve_transfer(

Check failure on line 324 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:324:4 | 324 | AssetsOf::<T>::approve_transfer( | ^^^^^^^^ use of undeclared type `AssetsOf`
origin,
token.clone().into(),
T::Lookup::unlookup(spender.clone()),
value,
)
.map_err(|e| e.with_weight(AssetsWeightInfoOf::<T>::approve_transfer()))?;

Check failure on line 330 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsWeightInfoOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsWeightInfoOf` --> pallets/api/src/fungibles/mod.rs:330:31 | 330 | .map_err(|e| e.with_weight(AssetsWeightInfoOf::<T>::approve_transfer()))?; | ^^^^^^^^^^^^^^^^^^ | | | use of undeclared type `AssetsWeightInfoOf` | help: a trait with a similar name exists: `AssetsWeightInfoTrait`
let value = AssetsOf::<T>::allowance(token.clone(), &owner, &spender);

Check failure on line 331 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:331:16 | 331 | let value = AssetsOf::<T>::allowance(token.clone(), &owner, &spender); | ^^^^^^^^ use of undeclared type `AssetsOf`
Self::deposit_event(Event::Approval { token, owner, spender, value });
Ok(().into())
}
Expand All @@ -254,17 +349,17 @@
) -> DispatchResultWithPostInfo {
let owner = ensure_signed(origin.clone())
.map_err(|e| e.with_weight(WeightOf::<T>::approve(0, 0)))?;
if value.is_zero() {

Check failure on line 352 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

no method named `is_zero` found for associated type `<T as fungibles::pallet::Config>::Balance` in the current scope

error[E0599]: no method named `is_zero` found for associated type `<T as fungibles::pallet::Config>::Balance` in the current scope --> pallets/api/src/fungibles/mod.rs:352:13 | 352 | if value.is_zero() { | ^^^^^^^ method not found in `<T as Config>::Balance`
return Ok(Some(WeightOf::<T>::approve(0, 0)).into());
}
let current_allowance = AssetsOf::<T>::allowance(token.clone(), &owner, &spender);

Check failure on line 355 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:355:28 | 355 | let current_allowance = AssetsOf::<T>::allowance(token.clone(), &owner, &spender); | ^^^^^^^^ use of undeclared type `AssetsOf`
let spender_source = T::Lookup::unlookup(spender.clone());
let token_param: TokenIdParameterOf<T> = token.clone().into();

Check failure on line 357 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find type `TokenIdParameterOf` in this scope

error[E0412]: cannot find type `TokenIdParameterOf` in this scope --> pallets/api/src/fungibles/mod.rs:357:21 | 357 | let token_param: TokenIdParameterOf<T> = token.clone().into(); | ^^^^^^^^^^^^^^^^^^ not found in this scope

// Cancel the approval and approve `new_allowance` if difference is more than zero.
let new_allowance =
current_allowance.checked_sub(&value).ok_or(AssetsErrorOf::<T>::Unapproved)?;

Check failure on line 361 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsErrorOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsErrorOf` --> pallets/api/src/fungibles/mod.rs:361:49 | 361 | current_allowance.checked_sub(&value).ok_or(AssetsErrorOf::<T>::Unapproved)?; | ^^^^^^^^^^^^^ use of undeclared type `AssetsErrorOf`
AssetsOf::<T>::cancel_approval(

Check failure on line 362 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:362:4 | 362 | AssetsOf::<T>::cancel_approval( | ^^^^^^^^ use of undeclared type `AssetsOf`
origin.clone(),
token_param.clone(),
spender_source.clone(),
Expand All @@ -273,7 +368,7 @@
let weight = if new_allowance.is_zero() {
WeightOf::<T>::approve(0, 1)
} else {
AssetsOf::<T>::approve_transfer(

Check failure on line 371 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:371:5 | 371 | AssetsOf::<T>::approve_transfer( | ^^^^^^^^ use of undeclared type `AssetsOf`
origin,
token_param,
spender_source,
Expand All @@ -292,7 +387,7 @@
/// - `admin` - The account that will administer the token.
/// - `min_balance` - The minimum balance required for accounts holding this token.
#[pallet::call_index(11)]
#[pallet::weight(AssetsWeightInfoOf::<T>::create())]

Check failure on line 390 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsWeightInfoOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsWeightInfoOf` --> pallets/api/src/fungibles/mod.rs:390:20 | 390 | #[pallet::weight(AssetsWeightInfoOf::<T>::create())] | ^^^^^^^^^^^^^^^^^^ | | | use of undeclared type `AssetsWeightInfoOf` | help: a trait with a similar name exists: `AssetsWeightInfoTrait`
pub fn create(
origin: OriginFor<T>,
id: TokenIdOf<T>,
Expand All @@ -300,7 +395,7 @@
min_balance: BalanceOf<T>,
) -> DispatchResult {
let creator = ensure_signed(origin.clone())?;
AssetsOf::<T>::create(

Check failure on line 398 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:398:4 | 398 | AssetsOf::<T>::create( | ^^^^^^^^ use of undeclared type `AssetsOf`
origin,
id.clone().into(),
T::Lookup::unlookup(admin.clone()),
Expand All @@ -319,9 +414,9 @@
// - `destroy_approvals`
// - `finish_destroy`
#[pallet::call_index(12)]
#[pallet::weight(AssetsWeightInfoOf::<T>::start_destroy())]

Check failure on line 417 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsWeightInfoOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsWeightInfoOf` --> pallets/api/src/fungibles/mod.rs:417:20 | 417 | #[pallet::weight(AssetsWeightInfoOf::<T>::start_destroy())] | ^^^^^^^^^^^^^^^^^^ | | | use of undeclared type `AssetsWeightInfoOf` | help: a trait with a similar name exists: `AssetsWeightInfoTrait`
pub fn start_destroy(origin: OriginFor<T>, token: TokenIdOf<T>) -> DispatchResult {
AssetsOf::<T>::start_destroy(origin, token.into())

Check failure on line 419 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:419:4 | 419 | AssetsOf::<T>::start_destroy(origin, token.into()) | ^^^^^^^^ use of undeclared type `AssetsOf`
}

/// Set the metadata for a token.
Expand All @@ -332,7 +427,7 @@
/// - `symbol`: The exchange symbol for this token.
/// - `decimals`: The number of decimals this token uses to represent one unit.
#[pallet::call_index(16)]
#[pallet::weight(AssetsWeightInfoOf::<T>::set_metadata(name.len() as u32, symbol.len() as u32))]

Check failure on line 430 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsWeightInfoOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsWeightInfoOf` --> pallets/api/src/fungibles/mod.rs:430:20 | 430 | #[pallet::weight(AssetsWeightInfoOf::<T>::set_metadata(name.len() as u32, symbol.len() as u32))] | ^^^^^^^^^^^^^^^^^^ | | | use of undeclared type `AssetsWeightInfoOf` | help: a trait with a similar name exists: `AssetsWeightInfoTrait`
pub fn set_metadata(
origin: OriginFor<T>,
token: TokenIdOf<T>,
Expand All @@ -340,7 +435,7 @@
symbol: Vec<u8>,
decimals: u8,
) -> DispatchResult {
AssetsOf::<T>::set_metadata(origin, token.into(), name, symbol, decimals)

Check failure on line 438 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:438:4 | 438 | AssetsOf::<T>::set_metadata(origin, token.into(), name, symbol, decimals) | ^^^^^^^^ use of undeclared type `AssetsOf`
}

/// Clear the metadata for a token.
Expand All @@ -348,9 +443,9 @@
/// # Parameters
/// - `token` - The token to update.
#[pallet::call_index(17)]
#[pallet::weight(AssetsWeightInfoOf::<T>::clear_metadata())]

Check failure on line 446 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsWeightInfoOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsWeightInfoOf` --> pallets/api/src/fungibles/mod.rs:446:20 | 446 | #[pallet::weight(AssetsWeightInfoOf::<T>::clear_metadata())] | ^^^^^^^^^^^^^^^^^^ | | | use of undeclared type `AssetsWeightInfoOf` | help: a trait with a similar name exists: `AssetsWeightInfoTrait`
pub fn clear_metadata(origin: OriginFor<T>, token: TokenIdOf<T>) -> DispatchResult {
AssetsOf::<T>::clear_metadata(origin, token.into())

Check failure on line 448 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:448:4 | 448 | AssetsOf::<T>::clear_metadata(origin, token.into()) | ^^^^^^^^ use of undeclared type `AssetsOf`
}

/// Creates `value` amount of tokens and assigns them to `account`, increasing the total
Expand All @@ -361,14 +456,14 @@
/// - `account` - The account to be credited with the created tokens.
/// - `value` - The number of tokens to mint.
#[pallet::call_index(19)]
#[pallet::weight(AssetsWeightInfoOf::<T>::mint())]

Check failure on line 459 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsWeightInfoOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsWeightInfoOf` --> pallets/api/src/fungibles/mod.rs:459:20 | 459 | #[pallet::weight(AssetsWeightInfoOf::<T>::mint())] | ^^^^^^^^^^^^^^^^^^ | | | use of undeclared type `AssetsWeightInfoOf` | help: a trait with a similar name exists: `AssetsWeightInfoTrait`
pub fn mint(
origin: OriginFor<T>,
token: TokenIdOf<T>,
account: AccountIdOf<T>,
value: BalanceOf<T>,
) -> DispatchResult {
AssetsOf::<T>::mint(

Check failure on line 466 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:466:4 | 466 | AssetsOf::<T>::mint( | ^^^^^^^^ use of undeclared type `AssetsOf`
origin,
token.clone().into(),
T::Lookup::unlookup(account.clone()),
Expand All @@ -385,19 +480,19 @@
/// - `account` - The account from which the tokens will be destroyed.
/// - `value` - The number of tokens to destroy.
#[pallet::call_index(20)]
#[pallet::weight(<T as Config>::WeightInfo::balance_of() + AssetsWeightInfoOf::<T>::burn())]

Check failure on line 483 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsWeightInfoOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsWeightInfoOf` --> pallets/api/src/fungibles/mod.rs:483:62 | 483 | #[pallet::weight(<T as Config>::WeightInfo::balance_of() + AssetsWeightInfoOf::<T>::burn())] | ^^^^^^^^^^^^^^^^^^ | | | use of undeclared type `AssetsWeightInfoOf` | help: a trait with a similar name exists: `AssetsWeightInfoTrait`
pub fn burn(
origin: OriginFor<T>,
token: TokenIdOf<T>,
account: AccountIdOf<T>,
value: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
let current_balance = AssetsOf::<T>::balance(token.clone(), &account);

Check failure on line 490 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:490:26 | 490 | let current_balance = AssetsOf::<T>::balance(token.clone(), &account); | ^^^^^^^^ use of undeclared type `AssetsOf`
if current_balance < value {
return Err(AssetsErrorOf::<T>::BalanceLow

Check failure on line 492 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsErrorOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsErrorOf` --> pallets/api/src/fungibles/mod.rs:492:16 | 492 | return Err(AssetsErrorOf::<T>::BalanceLow | ^^^^^^^^^^^^^ use of undeclared type `AssetsErrorOf`
.with_weight(<T as Config>::WeightInfo::balance_of()));
}
AssetsOf::<T>::burn(

Check failure on line 495 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `AssetsOf`

error[E0433]: failed to resolve: use of undeclared type `AssetsOf` --> pallets/api/src/fungibles/mod.rs:495:4 | 495 | AssetsOf::<T>::burn( | ^^^^^^^^ use of undeclared type `AssetsOf`
origin,
token.clone().into(),
T::Lookup::unlookup(account.clone()),
Expand Down Expand Up @@ -499,7 +594,7 @@
fn weight(request: &Self::Read) -> Weight {
use Read::*;
match request {
TotalSupply(_) => <T as Config>::WeightInfo::total_supply(),
TotalSupply(id) => <T as Config>::WeightInfo::total_supply(weight_param(id)),

Check failure on line 597 in pallets/api/src/fungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function takes 0 arguments but 1 argument was supplied

error[E0061]: this function takes 0 arguments but 1 argument was supplied --> pallets/api/src/fungibles/mod.rs:597:24 | 597 | TotalSupply(id) => <T as Config>::WeightInfo::total_supply(weight_param(id)), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ---------------- unexpected argument of type `u32` | note: associated function defined here --> pallets/api/src/fungibles/weights.rs:36:5 | 36 | fn total_supply() -> Weight; | ^^^^^^^^^^^^ help: remove the extra argument | 597 - TotalSupply(id) => <T as Config>::WeightInfo::total_supply(weight_param(id)), 597 + TotalSupply(id) => <T as Config>::WeightInfo::total_supply(), |
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hasn't been tested but applied to show how the weight can be handled for the read functions.

BalanceOf { .. } => <T as Config>::WeightInfo::balance_of(),
Allowance { .. } => <T as Config>::WeightInfo::allowance(),
TokenName(_) => <T as Config>::WeightInfo::token_name(),
Expand All @@ -516,23 +611,110 @@
fn read(request: Self::Read) -> Self::Result {
use Read::*;
match request {
TotalSupply(token) => ReadResult::TotalSupply(AssetsOf::<T>::total_supply(token)),
BalanceOf { token, owner } =>
ReadResult::BalanceOf(AssetsOf::<T>::balance(token, owner)),
Allowance { token, owner, spender } =>
ReadResult::Allowance(AssetsOf::<T>::allowance(token, &owner, &spender)),
TokenName(token) => ReadResult::TokenName(
Some(<AssetsOf<T> as MetadataInspect<AccountIdOf<T>>>::name(token))
TotalSupply(token) => {
let total = match token {
MultiAssetId::TrustBacked(id) =>
TrustBackedAssetsOf::<T>::total_supply(id).into(),
MultiAssetId::Foreign(id) => ForeignAssetsOf::<T>::total_supply(id).into(),
};
ReadResult::TotalSupply(total)
},
BalanceOf { token, owner } => {
let bal = match token {
MultiAssetId::TrustBacked(id) => pallet_assets::Pallet::<
T,
TrustBackedAssetsInstanceOf<T>,
>::balance(id, &owner)
.into(),
MultiAssetId::Foreign(id) => pallet_assets::Pallet::<
T,
ForeignAssetsInstanceOf<T>,
>::balance(id, &owner)
.into(),
};
ReadResult::BalanceOf(bal)
},
Allowance { token, owner, spender } => {
let allow = match token {
MultiAssetId::TrustBacked(id) => pallet_assets::Pallet::<
T,
TrustBackedAssetsInstanceOf<T>,
>::allowance(id, &owner, &spender)
.into(),
MultiAssetId::Foreign(id) => pallet_assets::Pallet::<
T,
ForeignAssetsInstanceOf<T>,
>::allowance(id, &owner, &spender)
.into(),
};
ReadResult::Allowance(allow)
},
TokenName(token) => {
let name = match token {
MultiAssetId::TrustBacked(id) => Some(<pallet_assets::Pallet<
T,
TrustBackedAssetsInstanceOf<T>,
> as MetadataInspect<AccountIdOf<T>>>::name(
id
))
.filter(|v| !v.is_empty()),
MultiAssetId::Foreign(id) => Some(<pallet_assets::Pallet<
T,
ForeignAssetsInstanceOf<T>,
> as MetadataInspect<AccountIdOf<T>>>::name(
id
))
.filter(|v| !v.is_empty()),
};
ReadResult::TokenName(name)
},
TokenSymbol(token) => {
let symbol = match token {
MultiAssetId::TrustBacked(id) => Some(<pallet_assets::Pallet<
T,
TrustBackedAssetsInstanceOf<T>,
> as MetadataInspect<AccountIdOf<T>>>::symbol(
id
))
.filter(|v| !v.is_empty()),
),
TokenSymbol(token) => ReadResult::TokenSymbol(
Some(<AssetsOf<T> as MetadataInspect<AccountIdOf<T>>>::symbol(token))
MultiAssetId::Foreign(id) => Some(<pallet_assets::Pallet<
T,
ForeignAssetsInstanceOf<T>,
> as MetadataInspect<AccountIdOf<T>>>::symbol(
id
))
.filter(|v| !v.is_empty()),
),
TokenDecimals(token) => ReadResult::TokenDecimals(
<AssetsOf<T> as MetadataInspect<AccountIdOf<T>>>::decimals(token),
),
TokenExists(token) => ReadResult::TokenExists(AssetsOf::<T>::asset_exists(token)),
};
ReadResult::TokenSymbol(symbol)
},
TokenDecimals(token) => {
let decimals = match token {
MultiAssetId::TrustBacked(id) => <pallet_assets::Pallet<
T,
TrustBackedAssetsInstanceOf<T>,
> as MetadataInspect<AccountIdOf<T>>>::decimals(
id
),
MultiAssetId::Foreign(id) => <pallet_assets::Pallet<
T,
ForeignAssetsInstanceOf<T>,
> as MetadataInspect<AccountIdOf<T>>>::decimals(
id
),
};
ReadResult::TokenDecimals(decimals)
},
TokenExists(token) => {
let exists = match token {
MultiAssetId::TrustBacked(id) => pallet_assets::Pallet::<
T,
TrustBackedAssetsInstanceOf<T>,
>::asset_exists(id),
MultiAssetId::Foreign(id) =>
pallet_assets::Pallet::<T, ForeignAssetsInstanceOf<T>>::asset_exists(id),
};
ReadResult::TokenExists(exists)
},
}
}
}
Expand Down
1 change: 1 addition & 0 deletions pop-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ path = "src/lib.rs"

[features]
default = [ "std" ]
foreign_fungibles = [ ]
fungibles = [ ]
nonfungibles = [ ]
std = [
Expand Down
2 changes: 1 addition & 1 deletion pop-api/integration-tests/contracts/fungibles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "0.1.0"

[dependencies]
ink = { version = "5.1.0", default-features = false }
pop-api = { path = "../../../../pop-api", default-features = false, features = [ "fungibles" ] }
pop-api = { path = "../../../../pop-api", default-features = false, features = [ "foreign_fungibles", "fungibles" ] }

[lib]
path = "lib.rs"
Expand Down
Loading
Loading