Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bridges/snowbridge/pallets/inbound-queue-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ frame-benchmarking = { workspace = true, default-features = true }
sp-keyring = { workspace = true, default-features = true }
snowbridge-pallet-ethereum-client = { workspace = true, default-features = true }
hex-literal = { workspace = true, default-features = true }
hex = { workspace = true, default-features = true }

[features]
default = ["std"]
Expand Down
34 changes: 34 additions & 0 deletions bridges/snowbridge/pallets/inbound-queue-v2/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "snowbridge-inbound-queue-v2-runtime-api"
description = "Snowbridge Inbound Queue V2 Runtime API"
version = "0.2.0"
authors = ["Snowfork <[email protected]>"]
edition.workspace = true
repository.workspace = true
license = "Apache-2.0"
categories = ["cryptography::cryptocurrencies"]

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
sp-std = { workspace = true }
sp-api = { workspace = true }
frame-support = { workspace = true }
snowbridge-merkle-tree = { workspace = true }
snowbridge-core = { workspace = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"snowbridge-core/std",
"snowbridge-merkle-tree/std",
"sp-api/std",
"sp-std/std",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ethereum Inbound Queue V2 Runtime API

Provides an API to dry-run inbound messages to get the XCM (and its execution cost) that will be executed on AssetHub.
17 changes: 17 additions & 0 deletions bridges/snowbridge/pallets/inbound-queue-v2/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::traits::tokens::Balance as BalanceT;
use snowbridge_core::{
inbound::v2::InboundMessage,
PricingParameters,
};

sp_api::decl_runtime_apis! {
pub trait InboundQueueApi<Balance> where Balance: BalanceT
{
/// Dry runs the provided message on AH to provide the XCM payload and execution cost.
fn dry_run(message: InboundMessage, proof: ) -> (Xcm, u128);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@ mod benchmarks {
create_message.block_roots_root,
);

let sovereign_account = sibling_sovereign_account::<T>(1000u32.into());

let minimum_balance = T::Token::minimum_balance();

// So that the receiving account exists
assert_ok!(T::Token::mint_into(&caller, minimum_balance));
// Fund the sovereign account (parachain sovereign account) so it can transfer a reward
// fee to the caller account
assert_ok!(T::Token::mint_into(
&sovereign_account,
3_000_000_000_000u128
.try_into()
.unwrap_or_else(|_| panic!("unable to cast sovereign account balance")),
));

#[block]
{
assert_ok!(InboundQueue::<T>::submit(
Expand Down
15 changes: 6 additions & 9 deletions bridges/snowbridge/pallets/inbound-queue-v2/src/envelope.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
use snowbridge_core::{inbound::Log, ChannelId};
use snowbridge_core::inbound::Log;

use sp_core::{RuntimeDebug, H160, H256};
use sp_core::{RuntimeDebug, H160};
use sp_std::prelude::*;

use alloy_primitives::B256;
use alloy_sol_types::{sol, SolEvent};

sol! {
event OutboundMessageAccepted(bytes32 indexed channel_id, uint64 nonce, bytes32 indexed message_id, bytes payload);
event OutboundMessageAccepted(uint64 indexed nonce, uint128 fee, bytes payload);
}

/// An inbound message that has had its outer envelope decoded.
#[derive(Clone, RuntimeDebug)]
pub struct Envelope {
/// The address of the outbound queue on Ethereum that emitted this message as an event log
pub gateway: H160,
/// The message Channel
pub channel_id: ChannelId,
/// A nonce for enforcing replay protection and ordering.
pub nonce: u64,
/// An id for tracing the message on its route (has no role in bridge consensus)
pub message_id: H256,
/// Total fee paid in Ether on Ethereum, should cover all the cost
pub fee: u128,
/// The inner payload generated from the source application.
pub payload: Vec<u8>,
}
Expand All @@ -41,9 +39,8 @@ impl TryFrom<&Log> for Envelope {

Ok(Self {
gateway: log.address,
channel_id: ChannelId::from(event.channel_id.as_ref()),
nonce: event.nonce,
message_id: H256::from(event.message_id.as_ref()),
fee: event.fee,
payload: event.payload,
})
}
Expand Down
Loading