I'm trying to write something similar to Moonbeam's assets-erc20
precompile.
I'm using Moonbeam's #[precompile]
procedural macros.
pub type AssetIdOf<R> =
<<R as pallet_evm::Config>::Fungibles as Inspect<<R as frame_system::Config>::AccountId>>::AssetId;
pub type BalanceOf<R> =
<<R as pallet_evm::Config>::Fungibles as Inspect<<R as frame_system::Config>::AccountId>>::Balance;
pub struct Fungibles<R>(PhantomData<R>);
#[precompile_utils::precompile]
impl<R> Fungibles<R>
where
R: pallet_evm::Config,
AssetIdOf<R>: EvmData,
BalanceOf<R>: Into<U256>,
{
#[precompile::public("totalSupply()")]
#[precompile::view]
fn total_supply(
handle: &mut impl PrecompileHandle,
asset_id: AssetIdOf<R>,
) -> EvmResult<U256> {
handle.record_cost(RuntimeHelper::<R>::db_read_gas_cost())?;
Ok(R::Fungibles::total_issuance(asset_id).into())
}
// todo: remaining erc20 methods
}
I'm running into this compilation error.
--> frame/evm/precompile/fungibles/src/lib.rs:74:29
|
63 | impl<R> Fungibles<R>
| - help: you might be missing a type parameter: `<R>`
...
74 | asset_id: AssetIdOf<R>,
| ^ not found in this scope
For more information about this error, try `rustc --explain E0412`.
It's quite confusing because <R>
is not missing.
I'm trying to figure out whether:
- this is a Rust syntax error
- I'm misusing the
#[precompile]
macro
Note: my approach is using loose coupling (as opposed to assets-erc20
's tight coupling). I attempted switching to a tight coupling strategy and the issue remained, so that is unlikely to be the root cause.