This repository was archived by the owner on Aug 15, 2025. It is now read-only.
forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
Transact from eth to sub #114
Open
yrong
wants to merge
50
commits into
bridge-next-gen
Choose a base branch
from
transact-from-eth-to-sub
base: bridge-next-gen
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 36 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
d68c3d6
Fix for unit test
yrong 307ecd6
Update for transact
yrong 7c493bd
Penpal config for transact
yrong e55cfd1
Fix import
yrong 45c3372
Fix taplo
yrong 26df807
Fix for breaking emulated tests
yrong c4fe031
Remove unused
yrong 51b76fe
Tranfer fees to BH for transact
yrong 3ed7260
Remove the teleport config
yrong 772fa46
Enable create agent/channel by xcm
yrong 540a791
Refund surplus
yrong 051b3b6
Fix format
yrong e523185
Replace hardcode value
yrong a8b8435
Leave to user to prefund sovereign account on the destination chain t…
yrong b10d19e
Update import path
yrong cbd2e19
Merge branch 'snowbridge' into transact-from-eth-to-sub
yrong e363918
Unit test for transact
yrong 13217f1
DescendOrigin to inbound-queue first
yrong 257e75d
Fix breaking test
yrong e03942a
First match RegisterToken or SendToken
yrong 698a9e9
Remove deprecated
yrong 9968a37
Use SetAppendix and refund surplus when transact fail
yrong 40ea01a
Ignore parents which is meaningless for GlobalConsensus locations
yrong 004afd2
Reuse weight type
yrong 85d2c03
Update sender consistent with smoke test
yrong 626ec76
Update Cargo.toml
yrong 0686fcd
Fix breaking test
yrong 7cc0d59
Improve tests
yrong 050585c
Merge branch 'snowbridge' into transact-from-eth-to-sub
yrong ece8a96
Merge branch 'snowbridge' into transact-from-eth-to-sub
yrong 7b916e5
Add TransactFeeMode
yrong 15759a4
Improve convert logic
yrong 04a339e
Fix UniversalLocation
yrong c18f771
AllowUnpaidExecutionFromSnowBridgeWithFeeChecked
yrong e49f077
Merge branch 'snowbridge' into transact-from-eth-to-sub
yrong 362e414
Remove feeMode and fully charge all cost on Ethereum
yrong 6fb78fe
Merge branch 'snowbridge' into transact-from-eth-to-sub
yrong 9d0af91
Fix build error
yrong 68abf04
Make network specific types as storage which can be changed
yrong 76b01b2
Remove the fund steps unnecessary
yrong 87ed097
Move Transact after Origin operations
yrong 0ea24a4
Fix breaking test
yrong b85e362
Merge branch 'bridge-next-gen' into transact-from-eth-to-sub
yrong cd7a64a
Fix compile error
yrong 966abdf
Use native token of destination chain to pay fee from a pre-funded so…
yrong 1cab94c
Use native token or DOT based on whether its a system parachain or not
yrong 5a22972
Make fee asset as configuration parameter of the Channel
yrong 9829de7
Zero fee for transact
yrong 2f30d46
Remove unused
yrong ee6bdc5
Deposit any left over fees back into the pre-funded account
yrong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
bridges/snowbridge/pallets/inbound-queue/fixtures/src/send_call_to_penpal.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
| // Generated, do not edit! | ||
| // See ethereum client README.md for instructions to generate | ||
|
|
||
| use crate::InboundQueueFixture; | ||
| use hex_literal::hex; | ||
| use snowbridge_beacon_primitives::CompactExecutionHeader; | ||
| use snowbridge_core::inbound::{Log, Message, Proof}; | ||
| use sp_std::vec; | ||
|
|
||
| pub fn make_send_call_to_penpal_message() -> InboundQueueFixture { | ||
| InboundQueueFixture { | ||
| execution_header: CompactExecutionHeader{ | ||
| parent_hash: hex!("e0fa68ceff08e6f024c84f408540372801b209ff8f11481a9dc6bc5db3ce92d3").into(), | ||
| block_number: 831, | ||
| state_root: hex!("ccc30635f32d558620d45ead60eabbe70dbf179b475fa9cec5a3791fd5be2b78").into(), | ||
| receipts_root: hex!("6bba8f0093461e22cd265bc0de44bf7a596db58ecbf44432e6de8b3490deb077").into(), | ||
| }, | ||
| message: Message { | ||
| event_log: Log { | ||
| address: hex!("eda338e4dc46038493b885327842fd3e301cab39").into(), | ||
| topics: vec![ | ||
| hex!("7153f9357c8ea496bba60bf82e67143e27b64462b49041f8e689e1b05728f84f").into(), | ||
| hex!("a69fbbae90bb6096d59b1930bbcfc8a3ef23959d226b1861deb7ad8fb06c6fa3").into(), | ||
| hex!("c9ad11f6e2d2b770f52e7cbe22ba779eb8e5e000e0db4e5032488898bd3529ec").into(), | ||
| ], | ||
| data: hex!("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003e00a736aa00000000000290a987b944cb1dcce5564e5fdecd7a54d3de27fe0100902f5009000000000000000000000002688909017d2000071468656c6c6f0000").into(), | ||
| }, | ||
| proof: Proof { | ||
| block_hash: hex!("be15f3cdf217baad8cc5c40d7e2dc1f173ab3bdaa58e5819905bb0c73f46cf78").into(), | ||
| tx_index: 0, | ||
| data: (vec![ | ||
| hex!("6bba8f0093461e22cd265bc0de44bf7a596db58ecbf44432e6de8b3490deb077").to_vec(), | ||
| ], vec![ | ||
| hex!("f90234822080b9022e02f9022a0183016e01b9010000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000200000000000000000020000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000010000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002004000000000000000000000200000000000000f9011ff9011c94eda338e4dc46038493b885327842fd3e301cab39f863a07153f9357c8ea496bba60bf82e67143e27b64462b49041f8e689e1b05728f84fa0a69fbbae90bb6096d59b1930bbcfc8a3ef23959d226b1861deb7ad8fb06c6fa3a0c9ad11f6e2d2b770f52e7cbe22ba779eb8e5e000e0db4e5032488898bd3529ecb8a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003e00a736aa00000000000290a987b944cb1dcce5564e5fdecd7a54d3de27fe0100902f5009000000000000000000000002688909017d2000071468656c6c6f0000").to_vec(), | ||
| ]), | ||
| }, | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,13 @@ | |
| // SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
| use super::*; | ||
|
|
||
| use frame_support::{assert_noop, assert_ok}; | ||
| use frame_support::{assert_noop, assert_ok, weights::Weight}; | ||
| use hex_literal::hex; | ||
| use snowbridge_core::{inbound::Proof, ChannelId}; | ||
| use sp_keyring::AccountKeyring as Keyring; | ||
| use sp_runtime::DispatchError; | ||
| use sp_std::convert::From; | ||
| use xcm::prelude::{OriginKind, Transact}; | ||
|
|
||
| use crate::{Error, Event as InboundQueueEvent}; | ||
|
|
||
|
|
@@ -251,3 +252,34 @@ fn test_submit_no_funds_to_reward_relayers_and_ed_preserved() { | |
| assert_eq!(amount, ExistentialDeposit::get()); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_convert_transact() { | ||
| new_tester().execute_with(|| { | ||
| let message_id: H256 = [1; 32].into(); | ||
| let sender: H160 = hex!("ee9170abfbf9421ad6dd07f6bdec9d89f2b581e0").into(); | ||
| let fee: u128 = 40_000_000_000; | ||
| let weight_at_most = Weight::from_parts(40_000_000, 8_000); | ||
| let origin_kind = OriginKind::SovereignAccount; | ||
| let payload = hex!("00071468656c6c6f").to_vec(); | ||
| let message = VersionedMessage::V1(MessageV1 { | ||
| chain_id: 11155111, | ||
| command: Command::Transact { | ||
| sender, | ||
| fee, | ||
| weight_at_most, | ||
| origin_kind, | ||
| payload: payload.clone(), | ||
| }, | ||
| }); | ||
| // Convert the message to XCM | ||
| let (xcm, dest_fee) = InboundQueue::do_convert(message_id, message).unwrap(); | ||
| let instructions = xcm.into_inner(); | ||
| assert_eq!(instructions.len(), 7); | ||
| assert_eq!(dest_fee, fee.into()); | ||
| let transact = instructions.get(2).unwrap().clone(); | ||
| let expected = | ||
| Transact { origin_kind, require_weight_at_most: weight_at_most, call: payload.into() }; | ||
| assert_eq!(transact, expected); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,19 @@ pub enum Command { | |
| /// XCM execution fee on AssetHub | ||
| fee: u128, | ||
| }, | ||
| /// call arbitrary transact on dest chain | ||
| Transact { | ||
| /// The address of the sender | ||
| sender: H160, | ||
| /// OriginKind | ||
| origin_kind: OriginKind, | ||
| /// XCM execution fee on dest chain | ||
| fee: u128, | ||
| /// The weight required at most on dest chain | ||
| weight_at_most: Weight, | ||
| /// The payload of the transact | ||
| payload: Vec<u8>, | ||
| }, | ||
| } | ||
|
|
||
| /// Destination for bridged tokens | ||
|
|
@@ -146,6 +159,17 @@ impl<CreateAssetCall, CreateAssetDeposit, InboundQueuePalletInstance, AccountId, | |
| Ok(Self::convert_register_token(chain_id, token, fee)), | ||
| V1(MessageV1 { chain_id, command: SendToken { token, destination, amount, fee } }) => | ||
| Ok(Self::convert_send_token(chain_id, token, destination, amount, fee)), | ||
| V1(MessageV1 { | ||
| chain_id, | ||
| command: Transact { sender, origin_kind, fee, weight_at_most, payload }, | ||
| }) => Ok(Self::convert_transact( | ||
| chain_id, | ||
| sender, | ||
| origin_kind, | ||
| fee, | ||
| weight_at_most, | ||
| payload, | ||
| )), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -289,6 +313,33 @@ where | |
| [GlobalConsensus(network), AccountKey20 { network: None, key: token.into() }], | ||
| ) | ||
| } | ||
|
|
||
| fn convert_transact( | ||
| chain_id: u64, | ||
| sender: H160, | ||
| origin_kind: OriginKind, | ||
| fee: u128, | ||
| weight_at_most: Weight, | ||
| payload: Vec<u8>, | ||
| ) -> (Xcm<()>, Balance) { | ||
| let xcm_fee: Asset = (Location::parent(), fee).into(); | ||
|
|
||
| let message = vec![ | ||
| UnpaidExecution { weight_limit: Unlimited, check_origin: None }, | ||
| // Actually BurnAsset does nothing on dest chain, included here only for | ||
| // the dest chain to implement a custom Barrier which inspect the fee as | ||
| // expected(i.e. can cover the transact cost to avoid spamming) | ||
| BurnAsset(xcm_fee.clone().into()), | ||
claravanstaden marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Transact { origin_kind, require_weight_at_most: weight_at_most, call: payload.into() }, | ||
| // Only our inbound-queue pallet is allowed to invoke `UniversalOrigin` | ||
| DescendOrigin(PalletInstance(InboundQueuePalletInstance::get()).into()), | ||
| // Change origin to the bridge. | ||
| UniversalOrigin(GlobalConsensus(Ethereum { chain_id })), | ||
| // DescendOrigin to the sender. | ||
| DescendOrigin(AccountKey20 { network: None, key: sender.into() }.into()), | ||
| ]; | ||
| (message.into(), fee.into()) | ||
|
||
| } | ||
| } | ||
|
|
||
| pub struct GlobalConsensusEthereumConvertsFor<AccountId>(PhantomData<AccountId>); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
| // Generated, do not edit! | ||
| // See ethereum client README.md for instructions to generate | ||
|
|
||
| use crate::InboundQueueFixture; | ||
| use hex_literal::hex; | ||
| use snowbridge_beacon_primitives::CompactExecutionHeader; | ||
| use snowbridge_core::inbound::{Log, Message, Proof}; | ||
| use sp_std::vec; | ||
|
|
||
| pub fn make_send_call_to_penpal_message() -> InboundQueueFixture { | ||
| InboundQueueFixture { | ||
| execution_header: CompactExecutionHeader{ | ||
| parent_hash: hex!("{{InboundMessageTest.ExecutionHeader.ParentHash}}").into(), | ||
| block_number: {{InboundMessageTest.ExecutionHeader.BlockNumber}}, | ||
| state_root: hex!("{{InboundMessageTest.ExecutionHeader.StateRoot}}").into(), | ||
| receipts_root: hex!("{{InboundMessageTest.ExecutionHeader.ReceiptsRoot}}").into(), | ||
| }, | ||
| message: Message { | ||
| event_log: Log { | ||
| address: hex!("{{InboundMessageTest.Message.EventLog.Address}}").into(), | ||
| topics: vec![ | ||
| {{#InboundMessageTest.Message.EventLog.Topics}} | ||
| hex!("{{.}}").into(), | ||
| {{/InboundMessageTest.Message.EventLog.Topics}} | ||
| ], | ||
| data: hex!("{{InboundMessageTest.Message.EventLog.Data}}").into(), | ||
| }, | ||
| proof: Proof { | ||
| block_hash: hex!("{{InboundMessageTest.Message.Proof.BlockHash}}").into(), | ||
| tx_index: {{InboundMessageTest.Message.Proof.TxIndex}}, | ||
| data: (vec![ | ||
| {{#InboundMessageTest.Message.Proof.Data.Keys}} | ||
| hex!("{{.}}").to_vec(), | ||
| {{/InboundMessageTest.Message.Proof.Data.Keys}} | ||
| ], vec![ | ||
| {{#InboundMessageTest.Message.Proof.Data.Values}} | ||
| hex!("{{.}}").to_vec(), | ||
| {{/InboundMessageTest.Message.Proof.Data.Values}} | ||
| ]), | ||
| }, | ||
| }, | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
bridges/snowbridge/templates/send_token_to_penpal.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
| // Generated, do not edit! | ||
| // See ethereum client README.md for instructions to generate | ||
|
|
||
| use crate::InboundQueueFixture; | ||
| use hex_literal::hex; | ||
| use snowbridge_beacon_primitives::CompactExecutionHeader; | ||
| use snowbridge_core::inbound::{Log, Message, Proof}; | ||
| use sp_std::vec; | ||
|
|
||
| pub fn make_send_token_to_penpal_message() -> InboundQueueFixture { | ||
| InboundQueueFixture { | ||
| execution_header: CompactExecutionHeader{ | ||
| parent_hash: hex!("{{InboundMessageTest.ExecutionHeader.ParentHash}}").into(), | ||
| block_number: {{InboundMessageTest.ExecutionHeader.BlockNumber}}, | ||
| state_root: hex!("{{InboundMessageTest.ExecutionHeader.StateRoot}}").into(), | ||
| receipts_root: hex!("{{InboundMessageTest.ExecutionHeader.ReceiptsRoot}}").into(), | ||
| }, | ||
| message: Message { | ||
| event_log: Log { | ||
| address: hex!("{{InboundMessageTest.Message.EventLog.Address}}").into(), | ||
| topics: vec![ | ||
| {{#InboundMessageTest.Message.EventLog.Topics}} | ||
| hex!("{{.}}").into(), | ||
| {{/InboundMessageTest.Message.EventLog.Topics}} | ||
| ], | ||
| data: hex!("{{InboundMessageTest.Message.EventLog.Data}}").into(), | ||
| }, | ||
| proof: Proof { | ||
| block_hash: hex!("{{InboundMessageTest.Message.Proof.BlockHash}}").into(), | ||
| tx_index: {{InboundMessageTest.Message.Proof.TxIndex}}, | ||
| data: (vec![ | ||
| {{#InboundMessageTest.Message.Proof.Data.Keys}} | ||
| hex!("{{.}}").to_vec(), | ||
| {{/InboundMessageTest.Message.Proof.Data.Keys}} | ||
| ], vec![ | ||
| {{#InboundMessageTest.Message.Proof.Data.Values}} | ||
| hex!("{{.}}").to_vec(), | ||
| {{/InboundMessageTest.Message.Proof.Data.Values}} | ||
| ]), | ||
| }, | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.