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

connectors: Wrapped token lookup #1393

Merged
merged 28 commits into from Jun 14, 2023
Merged

connectors: Wrapped token lookup #1393

merged 28 commits into from Jun 14, 2023

Conversation

NunoAlexandre
Copy link
Contributor

@NunoAlexandre NunoAlexandre commented Jun 8, 2023

Part 2/2 of #1350

  • Connector-wrapped tokens should have a AssetMetadata.location that encapsulates the EVM chain id and the specific EVM address of said token

    • We, therefore, can implement a lookup for Connector-wrapped assets that knows how to lookup that data from the asset's location

Changes

  • Add ConnectorsWrappedToken, an enum type representing the Connectors Wrapped tokens we handle. At this moment, that's only EVM tokens. As described in the docs of that type, in the future it might be others such as Cosmos or Avalanche.

  • We implement conversion between ConnectorsWrappedToken and MultiLocation

Usage

  • When registering a ConnectorsWrappedToken in the OrmlAssetRegistry, we define the Metadata.location as ConnectorsWrappedTokenConvert<ConnectorsPalletIndex>>::convert(connectors_wrapped_token);

  • In the connectors pallet we add a new type:

ConnectorsWrappedTokenConvert: Convert<ConnectorsWrappedToken, MultiLocation> + Convert<MultiLocation, Result<ConnectorsWrappedToken, ()>
  • In the add_currency extrinsic of the connectors pallet, we will roughly do:
fn add_currency(currency_id: T::CurrencyId, domain: Domain) {
	let meta = T::AssetRegistry::metadata(currency_id).ok_or(Error::CurrencyMetadataNotFound)?;

	ensure!(
		meta.additional.transferability.includes_connectors(),
		Error::NotConnectorsTransferable
	);
	let wrapped_token = ConnectorsWrappedTokenConvert::convert(meta.location)
		.map_err(Error::NotConnectorsWrappedToken)?;

	match wrapped_token {
		ConnectorsWrappedToken::EVM { chain_id, address } => ensure!(
			chain_id == domain.chain_id,
			Error::DifferentWrappedTokenAndDomain
		),
	}

	// send the message
}

Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Added my two cents on the asset registry question and I feel like we are missing at least a Moonbeam derivation?

libs/types/src/tokens.rs Show resolved Hide resolved
libs/types/src/tokens.rs Outdated Show resolved Hide resolved
Base automatically changed from feat/connectors-metadata to main June 12, 2023 15:36
@NunoAlexandre NunoAlexandre marked this pull request as ready for review June 13, 2023 07:27
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Looks good. Just wanted to highlight that we could imlement this purely on the connectors level without moving to the runtime level if we drop the pallet instance. But no blocker.

libs/types/src/tokens.rs Outdated Show resolved Hide resolved
runtime/common/src/lib.rs Show resolved Hide resolved
@NunoAlexandre NunoAlexandre enabled auto-merge (squash) June 14, 2023 08:56
@NunoAlexandre NunoAlexandre merged commit f5db44e into main Jun 14, 2023
11 checks passed
@NunoAlexandre NunoAlexandre deleted the evm-token-lookup branch June 14, 2023 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants