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

EthereumTokenTransfers pallet #835

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

Agusrodri
Copy link
Contributor

@Agusrodri Agusrodri commented Jan 29, 2025

What does it do?

This PR introduces the pallet-ethereum-token-transfers and adds it to Dancelight runtime, alongside:

  • Benchmarking and weights
  • Rust unit and integration tests
  • Typescript integration tests

Pallet's structure

The purpose of this pallet is to send the native Starlight token from Starlight to Ethereum. It does this by sending a MintForeignToken command to Ethereum through a specific channel_id (which is also stored in this pallet).

Config types

  • Currency: type to manage the internal transfers of native balance.
  • OutboundQueue: implementation that takes care of validating and send the message to Ethereum.
  • EthereumSystemHandler: Hook that manages the insertion of channel information inside EthereumSystem pallet.
  • EthereumSovereignAccount: Sovereign account of Ethereum in Starlight chain. This is the account in which we store and track how much tokens are transferred from Starlight to Ethereum as a whole.
  • FeesAccount: the account in which we deposit fees (calculated at the moment of delivering the message).
  • TokenLocationReanchored: the Starlight token location seen from the external chain's (Ethereum) point of view. This is the location that should be stored in EthereumSystem pallet prior to transfer the token using the EthereumTokenTransfers pallet.
  • TokenIdFromLocation: this is how we convert a Location object to a TokenId, used inside the MintForeignToken command. If the previous TokenLocationReanchored is not found in EthereumSystem, this conversion fails.

Extrinsics

set_token_transfer_channel: only callable by root. Used to specify which channel_id will be used to send the tokens through. It also receives the para_id and agent_id params corresponding to the channel specified.

transfer_native_token: used to perform the actual sending of the tokens, it requires to specify an amount and a recipient, which is a H160 account on the Ethereum side.

Storage

Inside the pallet we group and store the channel information using the ChannelInfo struct:

    pub struct ChannelInfo {
        pub channel_id: ChannelId,
        pub para_id: ParaId,
        pub agent_id: AgentId,
    }
    #[pallet::storage]
    pub type CurrentChannelInfo<T: Config> = StorageValue<_, ChannelInfo, OptionQuery>;

Events

  • ChannelInfoSet: information for the channel was set properly.
  • NativeTokenTransferred: some native token was successfully transferred to Ethereum.

Errors

  • ChannelIdAlreadyExists: the requested ChannelId is already present in this pallet.
  • ChannelInfoNotSet: the channel's information has not been set on this pallet yet.
  • ParaIdAlreadyExists: the requested ParaId is already present in this pallet.
  • AgentIdAlreadyExists: the requested AgentId is already present in this pallet.
  • UnknownLocationForToken: conversion from Location to TokenId failed.
  • InvalidMessage: the outbound message is invalid prior to send.
  • TransferMessageNotSent: the outbound message could not be sent.

@Agusrodri Agusrodri added 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 labels Jan 29, 2025
Copy link
Contributor

github-actions bot commented Jan 29, 2025

WASM runtime size check:

Compared to target branch

dancebox runtime: 1412 KB (no changes) ✅

flashbox runtime: 824 KB (no changes) ✅

dancelight runtime: 2180 KB (+2180 KB) ⚠️

container chain template simple runtime: 1116 KB (-4300 KB) ✅

container chain template frontier runtime: 1404 KB (-5156 KB) ✅

Copy link
Contributor

github-actions bot commented Jan 30, 2025

Coverage Report

(master)

@@                             Coverage Diff                             @@
##           master   agustin-ethereum-token-transfers-pallet      +/-   ##
===========================================================================
+ Coverage   66.04%                                    66.10%   +0.06%     
+ Files         335                                       339       +4     
+ Lines       58858                                     59175     +317     
===========================================================================
+ Hits        38869                                     39116     +247     
+ Misses      19989                                     20059      +70     
Files Changed Coverage
/chains/orchestrator-relays/runtime/dancelight/src/bridge_to_ethereum_config.rs 77.27% (+20.13%)
/chains/orchestrator-relays/runtime/dancelight/src/lib.rs 68.63% (+0.02%)

Coverage generated Tue Feb 4 22:49:43 UTC 2025

@Agusrodri Agusrodri marked this pull request as ready for review January 30, 2025 14:48
#[cfg(feature = "runtime-benchmarks")]
impl<T: snowbridge_pallet_outbound_queue::Config> TicketInfo for Ticket<T> {
fn message_id(&self) -> H256 {
H256::default()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because in benchmarks we need to check the message_id value thrown by the NativeTokenTransferred event. If we return the default, we don't need to worry about reading the entropy (which I don't know if it's possible inside benchmarks) to calculate the actual message_id.

I can take another look, but in my opinion we are fine by just returning the default here.

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.

2 participants