Skip to content

Conversation

@0xRVE
Copy link
Contributor

@0xRVE 0xRVE commented Jan 22, 2026

fixes #8659

Adds ForeignAssetIdExtractor which converts a u32 asset id to an XCM Location type.

@0xRVE 0xRVE requested a review from a team as a code owner January 22, 2026 09:46
@0xRVE 0xRVE requested review from acatangiu and bkchr January 22, 2026 09:49
@0xRVE
Copy link
Contributor Author

0xRVE commented Jan 22, 2026

/cmd prdoc --audience runtime_dev --bump minor

@0xRVE 0xRVE added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Jan 22, 2026
@0xRVE 0xRVE changed the title [WIP][pallet-assets] ad ForeignAssetIdExtractor to assets precompile [WIP][pallet-assets] add ForeignAssetIdExtractor to assets precompile Jan 22, 2026
@0xRVE 0xRVE added the T7-smart_contracts This PR/Issue is related to smart contracts. label Jan 22, 2026
@acatangiu
Copy link
Contributor

Another general comment is that it needs more tests (easy to use Claude for writing tests fast).

@0xRVE 0xRVE force-pushed the rve/8659-assets-precompile branch from 27ff790 to 06b9f65 Compare January 23, 2026 07:52
@0xRVE 0xRVE requested review from acatangiu and pgherveou January 23, 2026 15:08
@0xRVE
Copy link
Contributor Author

0xRVE commented Jan 23, 2026

Another general comment is that it needs more tests (easy to use Claude for writing tests fast).

done

@0xRVE
Copy link
Contributor Author

0xRVE commented Jan 29, 2026

/cmd bench --runtime dev --pallet pallet_assets_precompiles

@github-actions
Copy link
Contributor

Command "bench --runtime dev --pallet pallet_assets_precompiles" has started 🚀 See logs here

@github-actions
Copy link
Contributor

Command "bench --runtime dev --pallet pallet_assets_precompiles" has failed ❌! See logs here

@0xRVE
Copy link
Contributor Author

0xRVE commented Jan 30, 2026

/cmd bench --runtime dev --pallet pallet_assets_precompiles

@github-actions
Copy link
Contributor

Command "bench --runtime dev --pallet pallet_assets_precompiles" has started 🚀 See logs here

@github-actions
Copy link
Contributor

Command "bench --runtime dev --pallet pallet_assets_precompiles" has finished ✅ See logs here

Details

Subweight results:
File Extrinsic Old New Change [%]
substrate/frame/assets/precompiles/src/weights.rs migrate_asset_step_skip 7.70us Added
substrate/frame/assets/precompiles/src/weights.rs migrate_asset_step_migrate 8.63us Added
substrate/frame/assets/precompiles/src/weights.rs migrate_asset_step_finished 4.59us Added
Command output:

✅ Successful benchmarks of runtimes/pallets:
-- dev: ['pallet_assets_precompiles']

///
/// # Safety
///
/// - Idempotent: Skips assets that already have mappings
Copy link
Contributor

Choose a reason for hiding this comment

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

the mapping didn't exist before the migration, so I don't see why we need to specify this?

Copy link
Contributor Author

@0xRVE 0xRVE Jan 30, 2026

Choose a reason for hiding this comment

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

Maybe I dont understand the way migrations work, but this is what I thought:
The migration runs on runtime upgrades. Which means this migration will run several time in the future. So running it twice on the same set of foreign assets should not change anything. So it is required to be idempotent.

Copy link
Contributor

Choose a reason for hiding this comment

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

no once they are passed they don't re-run

see

//! ### Design Goals
//!
//! 1. Must automatically execute migrations over multiple blocks.
//! 2. Must expose information about whether migrations are ongoing.
//! 3. Must respect pessimistic weight bounds of migrations.
//! 4. Must execute migrations in order. Skipping is not allowed; migrations are run on a
//! all-or-nothing basis.
//! 5. Must prevent re-execution of past migrations.
//! 6. Must provide transactional storage semantics for migrations.
//! 7. Must guarantee progress.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
}

/// Benchmark the case when there are no more assets to iterate.
Copy link
Contributor

Choose a reason for hiding this comment

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

can be removed as well, it's fine to over-estimate for the last step

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

pub trait Config: frame_system::Config {
/// The foreign asset ID type. This must match the `AssetId` type used by the
/// `pallet_assets` instance for foreign assets.
type ForeignAssetId: Member + Parameter + Clone + MaybeSerializeDeserialize + MaxEncodedLen;
Copy link
Contributor

Choose a reason for hiding this comment

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

I really think we should simplify where we can and not use an associated type here where we can hardcode it to Location, will test what it looks like without it

Copy link
Contributor

Choose a reason for hiding this comment

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

@franciscoaguirre what do you think ? or maybe it's annoying because we need to update the Location version everytime you bump it here

  580  impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
     1 ▎   type RuntimeEvent = RuntimeEvent;
     2 ▎   type Balance = Balance;
     3 ▎   type AssetId = xcm::v5::Location;

Copy link
Contributor

@pgherveou pgherveou Jan 30, 2026

Choose a reason for hiding this comment

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

tasked Claude with it here #10945
also @franciscoaguirre Location encoding is stable ? if AH use v6 in a couple of month would an existing Location encode to the same value (I assume yes)

/// Mapping an asset index (derived from the precompile address) to a `ForeignAssetId`.
#[pallet::storage]
pub type AssetIndexToForeignAssetId<T: Config> =
StorageMap<_, Blake2_128Concat, u32, T::ForeignAssetId, OptionQuery>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use Identity here instead of Blake2_128Concat since the system control the keys (they are incrementing by one for each insert )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

#[pallet::pallet]
pub struct Pallet<T>(_);

/// The next available asset index for foreign assets.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need anything pub in this pallet, all we need is the AssetsCallback and the ForeignAssetIdExtractor that I will keep in that module to keep everything private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was able to remove a few pubs


const PRECOMPILE_MAPPINGS_MIGRATION_ID: &[u8; 32] = b"foreign-asset-precompile-mapping";

/// Progressive states of the precompile mappings migration.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need that
you can just do

type Cursor = <T as pallet_assets::Config>::AssetId;

or Location directly if we stop using generic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean here, can you elaborate?

Copy link
Contributor

Choose a reason for hiding this comment

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

we don't need the MigrationState we can just use A

Comment on lines 55 to 56
pub use migration::{MigrateForeignAssetPrecompileMappings, MigrationState};
pub use weights::{SubstrateWeight, WeightInfo as MigrationWeightInfo};
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure we need all thes extra pub if you have already made the module pub

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@0xRVE 0xRVE requested a review from pgherveou January 30, 2026 16:28
/// Mapping a `ForeignAssetId` to an asset index (used for deriving precompile addresses).
#[pallet::storage]
pub type ForeignAssetIdToAssetIndex<T: Config> =
StorageMap<_, Identity, T::ForeignAssetId, u32, OptionQuery>;
Copy link
Contributor

Choose a reason for hiding this comment

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

this one should probably still need a hash though since you could craft Location that make the trie unbalanced

// Minimum execution time: 8_247_000 picoseconds.
Weight::from_parts(8_630_000, 0)
}
fn migrate_asset_step_skip() -> Weight {
Copy link
Contributor

Choose a reason for hiding this comment

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

re-run the bot to get these methods removed

Copy link
Contributor

@pgherveou pgherveou left a comment

Choose a reason for hiding this comment

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

After addressing last comments.
Would also prefer to not have this Generic since we know that this is targeting Location

@0xRVE
Copy link
Contributor Author

0xRVE commented Jan 30, 2026

/cmd bench --runtime dev --pallet pallet_assets-precompiles

@github-actions
Copy link
Contributor

Command "bench --runtime dev --pallet pallet_assets-precompiles" has started 🚀 See logs here

@github-actions
Copy link
Contributor

Command "bench --runtime dev --pallet pallet_assets-precompiles" has failed ❌! See logs here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T1-FRAME This PR/Issue is related to core FRAME, the framework. T7-smart_contracts This PR/Issue is related to smart contracts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement pallet-asset matcher for Foreign assets

4 participants