Skip to content

Bridging: Add pallet-assets #2354

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

Merged

Conversation

mattheworris
Copy link
Collaborator

@mattheworris mattheworris commented Apr 22, 2025

Description

In order to teleport Frequency tokens to AssetHub, we need a way to pay the execution fee on AssetHub otherwise it will reject the request and treat the tokens as trapped assets.

Since AssetHub does not accept Frequency as payment for execution fees, we must also include DOT in the message to cover those fees.

To support this, Frequency must be able to handle DOT as an asset — both to receive DOT from AssetHub and to send DOT back out.

Acceptance Criteria

  • Add the ability to send and receive DOT on Frequency
  • Store DOT as a Multilocation on Frequency
  • Decide who should be allowed to create assets on Frequency
  • Generate Weights
  • Feature Flag frequency-bridging

Implementation suggestions

  • User Pallet Assets
  • Config
pallet-assets = { workspace = true, default-features = false }
assets-common = { workspace = true, default-features = false }
parameter_types! {
	pub const AssetDeposit: Balance = 0;
	pub const AssetAccountDeposit: Balance = 0;
	pub const ApprovalDeposit: Balance = 0;
	pub const AssetsStringLimit: u32 = 50;
	pub const MetadataDepositBase: Balance = 0;
	pub const MetadataDepositPerByte: Balance = 0;
}

parameter_types! {
	// we just reuse the same deposits
	pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get();
	pub const ForeignAssetsAssetAccountDeposit: Balance = AssetAccountDeposit::get();
	pub const ForeignAssetsApprovalDeposit: Balance = ApprovalDeposit::get();
	pub const ForeignAssetsAssetsStringLimit: u32 = AssetsStringLimit::get();
	pub const ForeignAssetsMetadataDepositBase: Balance = MetadataDepositBase::get();
	pub const ForeignAssetsMetadataDepositPerByte: Balance = MetadataDepositPerByte::get();
}
use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin, ForeignAssetsAssetId};
impl pallet_assets::Config  for Runtime {
	type RuntimeEvent = RuntimeEvent;
	type Balance = Balance;
////
	type AssetId = ForeignAssetsAssetId;
	type AssetIdParameter = ForeignAssetsAssetId;
	type Currency = Balances;
	// This is to allow any other remote location to create foreign assets. Used in tests, not
	// recommended on real chains.
	type **CreateOrigin** =
		**ForeignCreators**<Everything, LocationToAccountId, AccountId, xcm::latest::Location>;
	type ForceOrigin = EnsureRoot<AccountId>;
	type AssetDeposit = ForeignAssetsAssetDeposit;
	type MetadataDepositBase = ForeignAssetsMetadataDepositBase;
	type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
	type ApprovalDeposit = ForeignAssetsApprovalDeposit;
	type StringLimit = ForeignAssetsAssetsStringLimit;
	type Freezer = ();
	type Extra = ();
	type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
	type CallbackHandle = ();
	type AssetAccountDeposit = ForeignAssetsAssetAccountDeposit;
	type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
	#[cfg(feature = "runtime-benchmarks")]
	type BenchmarkHelper = xcm_config::XcmBenchmarkHelper;
	type Holder = ();
}

Checklist

  • Updated Pallet Readme?
  • Updated js/api-augment for Custom RPC APIs?
  • Design doc(s) updated?
  • Unit Tests added?
  • e2e Tests added?
  • Benchmarks added?
  • Spec version incremented?

@mattheworris mattheworris linked an issue Apr 22, 2025 that may be closed by this pull request
5 tasks
@mattheworris mattheworris self-assigned this Apr 22, 2025
@mattheworris mattheworris added enhancement New feature or request change/major Major Changes in this PR labels Apr 22, 2025
@mattheworris mattheworris added this to the Bridge milestone Apr 22, 2025
Copy link

codecov bot commented Apr 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Added `pallet-assets` and `assets-common` as optional dependencies in Cargo.toml.
- Introduced types and parameters for foreign assets in lib.rs, enabled with the `frequency-bridging` feature.
- Configured the assets pallet within the runtime, allowing for asset creation and management.
- Updated various comments for clarity and corrected minor typos.
…hmark script

- Updated Cargo.toml to add "frequency-bridging" to the frequency-lint-check dependencies.
- Modified run_benchmarks.sh to include pallet_assets in the list of ALL_EXTERNAL_PALLETS.
@github-actions github-actions bot added metadata-changed Metadata has changed since the latest full release metadata-version-not-incremented Metadata has changed since the latest full release, but the version has not been incremented labels Apr 24, 2025
@github-actions github-actions bot removed metadata-changed Metadata has changed since the latest full release metadata-version-not-incremented Metadata has changed since the latest full release, but the version has not been incremented labels Apr 24, 2025
@mattheworris mattheworris changed the title 2340 bridge add asset pallet Bridging: Add pallet-assets Apr 24, 2025
@github-actions github-actions bot added the metadata-changed Metadata has changed since the latest full release label Apr 24, 2025
@mattheworris mattheworris marked this pull request as ready for review April 24, 2025 22:48
@mattheworris mattheworris requested a review from wilwade as a code owner April 24, 2025 22:48
@mattheworris mattheworris requested a review from enddynayn April 24, 2025 22:48
@github-actions github-actions bot removed the metadata-changed Metadata has changed since the latest full release label Apr 25, 2025
// ForeignCreators<Everything, LocationToAccountId, AccountId, xcm::latest::Location>;
// Use EnsureSignedBy to specify a single account allowed to create assets.
// The Success type of EnsureSignedBy is AccountId, matching the trait bound.
type CreateOrigin = EnsureSigned<AccountId>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently allows any signed Frequency account to create. This can be assigned to a Council or a specific address, if we need to limit creation.

type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;

#[cfg(feature = "runtime-benchmarks")]
// type BenchmarkHelper = xcm_config::XcmBenchmarkHelper;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some xcm stuff will be brought in when other PRs finish the xcm setup.

…and include pallet-assets in runtime benchmarks
@mattheworris mattheworris requested a review from Copilot April 25, 2025 15:05
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces bridging support for Frequency by integrating the pallet-assets module to handle DOT as a foreign asset. Key changes include:

  • Adding new type definitions (AssetId and AssetBalance) and parameter_types for the foreign assets feature.
  • Configuring pallet-assets for bridging with a new CreateOrigin based on EnsureSigned and integrating it in the runtime.
  • Updating Cargo.toml files to include the necessary bridging feature flags and dependencies.

Reviewed Changes

Copilot reviewed 6 out of 9 changed files in this pull request and generated no comments.

File Description
runtime/frequency/src/lib.rs Introduces type aliases, parameters, and pallet-assets config for bridging
runtime/frequency/Cargo.toml Adds pallet-assets as an optional dependency and bridging feature flag
runtime/common/Cargo.toml Adds the frequency-bridging feature
Cargo.toml Integrates pallet-assets for bridging in the main Cargo configuration
Files not reviewed (3)
  • Makefile: Language not supported
  • scripts/init.sh: Language not supported
  • scripts/run_benchmarks.sh: Language not supported
Comments suppressed due to low confidence (2)

runtime/frequency/src/lib.rs:526

  • The placeholder AssetCreatorAccount is hardcoded; please ensure this account is updated with the proper creator account for production to avoid misconfiguration.
pub const AssetCreatorAccount: AccountId = AccountId::new([0u8; 32]); // TODO: Replace with actual AccountId

runtime/frequency/src/lib.rs:1343

  • No unit tests currently cover the new foreign assets (bridging) configuration; please add tests to verify asset creation and fee handling behavior under the bridging feature.
impl pallet_assets::Config for Runtime {

@github-actions github-actions bot added the metadata-changed Metadata has changed since the latest full release label Apr 25, 2025
@mattheworris mattheworris changed the base branch from main to feat/eth-briding April 25, 2025 15:13
@enddynayn
Copy link
Collaborator

👍 great!

@mattheworris mattheworris merged commit c573340 into feat/eth-bridging-development Apr 28, 2025
@mattheworris mattheworris deleted the 2340-bridge-add-asset-pallet branch April 28, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change/major Major Changes in this PR enhancement New feature or request metadata-changed Metadata has changed since the latest full release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BRIDGE: add asset pallet
2 participants