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

EVM foreign assets #2869

Merged
merged 75 commits into from
Jul 25, 2024
Merged

EVM foreign assets #2869

merged 75 commits into from
Jul 25, 2024

Conversation

librelois
Copy link
Collaborator

@librelois librelois commented Jul 16, 2024

⚠️ Breaking changes ⚠️

New way to create foreign asset

You need to call evmForeignAssets.createForeignAsset(assetId, xcmLocation, decimals, symbol, name).

Allowed origins: FastGeneralAdmin, 5/9 of OpenTechCommittee, Root

Parameters

  • assetId: u128 arbitrary unique integer
  • xcmLocation: xcm::v4::Location scale encoded xcm v4 location of asset reserve relative to moonbeam
  • decimals: u8 metadata that will be returned by ERC20.decimals()
  • symbol: Boundedvec<u8, ConstU32<256>> metadata that will be returned by ERC20.symbol() (max 256 characters)
  • name: Boundedvec<u8, ConstU32<256>> metadata that will be returned by ERC20.name() (max 256 characters)

Substrate event

evmForeignAssets.ForeignAssetCreated(contractAddress, assetId, xcmLocation)

New way to update foreign asset XCM Location

You need to call evmForeignAssets.changeXcmLocation(assetId, newXcmLocation).

Allowed origins: FastGeneralAdmin, 5/9 of OpenTechCommittee, Root

Parameters

  • assetId: u128 unique identifier of the asset
  • newXcmLocation: xcm::v4::Location scale encoded xcm v4 location of asset reserve relative to moonbeam

Substrate event

evmForeignAssets.ForeignAssetXcmLocationChanged(assetId, newXcmLocation)

New way to freeze a foreign asset (freeze all accounts)

You need to call evmForeignAssets.freezeForeignAsset(assetId, allowXcmDeposit).

Parameters

  • assetId: u128 unique identifier of the asset
  • allowXcmDeposit: bool if set to true XCM deposit will still work and mint tokens, if set to false XCM deposit will fail (no mint).

Substrate event

evmForeignAssets.ForeignAssetFrozen(assetId, xcmLocation)


What does it do?

Add a new pallet "pallet-moonbeam-foreign-assets".

The purpose of this new pallet is to manage XCM derivative assets on moonbeam through EVM smart contracts.

Prior to this PR, XCM derivatives assets (aka. "foreign assets") were managed by the pallet asset-manager and the pallet substrate pallet "pallet-asset". The long-term goal is to remove these two pallets from moon$ runtimes (asset-manager and pallet-asset), but before doing so we will first have to migrate all existing foreign assets in production.

This PR only implements the first stage of the plan: creating future foreign assets according to the new design. Subsequent PRs will manage the migration of existing foreign assets and the removal of the two depreciated pallets.

Replacing pallet-asset with evm smart contracts offers several advantages:

  1. Protocols that use foreign assets will be able to use the tools of the ethereum ecosystem (especially foundry)
  2. Some operations will b cheaper in gas (e.g. approve).
  3. It will reduce the runtime size (as two less pallets)
  4. It will reduce the complexity of the runtime code (enabling better maintenance).

What important points reviewers should know?

The new design take care of the compatiblity with existing foreign assets, in particular it identify each foreign assets the same way (with an integer named "AssetId").

Each foreign asset is implemented by an evm smart contract that is deployed by the new pallet.
The evm smart contract for each asset is trusted by the runtime, and must be deployed only by the runtime itself.

The runtime made several assumptions on theses evm smarts contracts:

  • Only the runtime should be able to mint and burn tokens
  • The following selectors should be exposed and callable only by this a "runtime account":
  • burnFrom(address, uint256)
  • mintInto(address, uint256)
  • pause(address, uint256)
  • unpause(address, uint256)
  • The smart contract should expose the ERC20.transfer selector

Is there something left for follow-up PRs?

Subsequent PRs will manage the migration of existing foreign assets and the removal of the two depreciated pallets.

What alternative implementations were considered?

Are there relevant PRs or issues in other repositories (Substrate, Polkadot, Frontier, Cumulus)?

moonbeam-foundation/frontier#221

TODO

  • add more rust-tests on the pallet level
  • adapt and complete benchmarks
  • adapt rust tests on the runtime level
  • adapt existing dev-tests about foreign assets

@librelois librelois added B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes D9-needsaudit👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited breaking Needs to be mentioned in breaking changes labels Jul 16, 2024
@librelois librelois requested a review from Agusrodri July 24, 2024 07:54
Copy link
Contributor

@Agusrodri Agusrodri left a comment

Choose a reason for hiding this comment

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

LGTM. Great work @librelois!

@librelois librelois merged commit 3b954cf into master Jul 25, 2024
37 checks passed
@librelois librelois deleted the elois-native-foreign-assets branch July 25, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes breaking Needs to be mentioned in breaking changes D9-needsaudit👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants