paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.com/
1.88k stars 688 forks source link

`pallet-asset-conversion` AssetConversionApi does not update to defined type in polkadot explorer. #5784

Closed AlphaGamingArcade closed 1 month ago

AlphaGamingArcade commented 1 month ago

I'm trying to add pallet_asset_conversion to this solochain template and I have this code under impl_runtime_apis!

// This includes the native and assets type
pub type NativeAndAssetId = NativeOrWithId<u32>;

...
pub type NativeAndAssets = UnionOf<Balances, Assets, NativeFromLeft, NativeAndAssetId, AccountId>;
pub type AscendingLocator = pallet_asset_conversion::Ascending<AccountId, NativeAndAssetId>;
pub type WithFirstAssetLocator = pallet_asset_conversion::WithFirstAsset<Native, AccountId, NativeAndAssetId>;

impl pallet_asset_conversion::Config for Runtime {
    type RuntimeEvent = RuntimeEvent;
    type Balance = <Self as pallet_balances::Config>::Balance;
    type HigherPrecisionBalance = u128;
    type AssetKind = NativeAndAssetId;
    type Assets = NativeAndAssets;
    type PoolId = (Self::AssetKind, Self::AssetKind);
    type PoolLocator = pallet_asset_conversion::Chain<WithFirstAssetLocator, AscendingLocator>;
    type PoolAssetId = u32;
    type PoolAssets = PoolAssets;
    type PoolSetupFee = ConstU128<100>; // should be more or equal to the existential deposit
    type PoolSetupFeeAsset = Native;
    type PoolSetupFeeTarget = ResolveAssetTo<AssetConversionOrigin, Self::Assets>;
    type PalletId = AssetConversionPalletId;
    type WeightInfo = ();
    type LPFee = ConstU32<3>; // means 0.3%
    type LiquidityWithdrawalFee = LiquidityWithdrawalFee;
    type MaxSwapPathLength = ConstU32<4>;
    type MintMinLiquidity = ConstU128<100>; // 100 is good enough when the main currency has 12 decimals.
    #[cfg(feature = "runtime-benchmarks")]
    type BenchmarkHelper = ();
}
...

impl_runtime_apis! {
...
impl pallet_asset_conversion::AssetConversionApi<
        Block,
        Balance,
        NativeAndAssetId,
    > for Runtime
    {
        fn quote_price_exact_tokens_for_tokens(asset1: NativeAndAssetId, asset2: NativeAndAssetId, amount: Balance, include_fee: bool) -> Option<Balance> {
            AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee)
        }

        fn quote_price_tokens_for_exact_tokens(asset1: NativeAndAssetId, asset2: NativeAndAssetId, amount: Balance, include_fee: bool) -> Option<Balance> {
            AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee)
        }

        fn get_reserves(asset1: NativeAndAssetId, asset2: NativeAndAssetId) -> Option<(Balance, Balance)> {
            AssetConversion::get_reserves(asset1, asset2).ok()
        }
    }
...

Why it defaults to asset1: StagingXcmV3MultiLocation and asset2: StagingXcmV3MultiLocation instead of getting Native or WithId just like in extrinsics? image image

bkchr commented 1 month ago

I don't think that this is a SDK issue, I would bet onto pjs.

CC @TarikGul

TarikGul commented 1 month ago

The PR to generate runtime apis' based on the metadata just went in this week. So once the api is released next week this should no longer be an issue for users. Currently the api requires folks to hardcode the runtime api's that is why its not showing up in the UI.

bkchr commented 1 month ago

Ty @TarikGul.