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

Add hyperbridge #894

Merged
merged 22 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
641 changes: 459 additions & 182 deletions Cargo.lock

Large diffs are not rendered by default.

84 changes: 47 additions & 37 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -271,48 +271,48 @@ sp-state-machine = { git = "https://github.com/paritytech/polkadot-sdk", branch
sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }

# Frontier Client
fc-cli = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
fc-consensus = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407" }
fc-db = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
fc-mapping-sync = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
fc-rpc = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
fc-rpc-core = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407" }
fc-storage = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407" }
fc-api = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
fc-cli = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
fc-consensus = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407" }
fc-db = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
fc-mapping-sync = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
fc-rpc = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
fc-rpc-core = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407" }
fc-storage = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407" }
fc-api = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }

# Frontier Primitive
fp-account = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false, features = [
fp-account = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, features = [
"serde",
] }
fp-consensus = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
fp-dynamic-fee = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
fp-ethereum = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
fp-evm = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false, features = [
fp-consensus = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
fp-dynamic-fee = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
fp-ethereum = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
fp-evm = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, features = [
"serde",
] }
fp-rpc = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
fp-self-contained = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false, features = [
fp-rpc = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
fp-self-contained = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, features = [
"serde",
] }
fp-storage = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
fp-storage = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }

# Frontier FRAME
pallet-base-fee = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-dynamic-fee = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-ethereum = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-evm = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-evm-chain-id = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-evm-precompile-blake2 = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-evm-precompile-bn128 = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-evm-precompile-curve25519 = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-evm-precompile-dispatch = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-evm-precompile-ed25519 = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-evm-precompile-modexp = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-evm-precompile-sha3fips = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-evm-precompile-simple = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-evm-test-vector-support = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407" }
pallet-hotfix-sufficients = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
precompile-utils = { git = "https://github.com/paritytech/frontier.git", branch = "stable2407", default-features = false }
pallet-base-fee = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-dynamic-fee = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-ethereum = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-evm = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-evm-chain-id = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-evm-precompile-blake2 = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-evm-precompile-bn128 = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-evm-precompile-curve25519 = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-evm-precompile-dispatch = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-evm-precompile-ed25519 = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-evm-precompile-modexp = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-evm-precompile-sha3fips = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-evm-precompile-simple = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
pallet-evm-test-vector-support = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407" }
pallet-hotfix-sufficients = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }
precompile-utils = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false }

# Local precompiles
evm-erc20-utils = { path = "precompiles/erc20-utils", default-features = false }
Expand Down Expand Up @@ -375,11 +375,21 @@ rpc-trace = { path = "client/rpc/trace" }
rpc-txpool = { path = "client/rpc/txpool" }
evm-tracer = { path = "evm-tracer", default-features = false }

# Polkadot XCM
xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
polkadot-parachain-primitives = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
# Hyperbridge EVM necessary dependencies
alloy-sol-macro = "0.7.7"
alloy-sol-types = { version = "0.7.7", default-features = false }
alloy-primitives = { version = "0.7.7", default-features = false, features = ["rlp"] }

# Hyperbridge
token-gateway-primitives = { path = "pallets/token-gateway/primitives" }
pallet-token-gateway = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2407-1", default-features = false }
pallet-ismp = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2407-1", default-features = false }
pallet-ismp-rpc = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2407-1" }
pallet-ismp-runtime-api = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2407-1", default-features = false }
ismp-grandpa = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2407-1", default-features = false }
ismp = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2407-1", default-features = false }
pallet-hyperbridge = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2407-1", default-features = false }
anyhow = { version = "1.0.93", default-features = false }

# Subxt
subxt = { version = "0.39.0", default-features = false }
Expand Down
30 changes: 16 additions & 14 deletions runtime/testnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pallet-evm-precompile-sha3fips = { workspace = true }
pallet-evm-precompile-simple = { workspace = true }
pallet-hotfix-sufficients = { workspace = true }

## Tangle precompiles
# Tangle precompiles
pallet-evm-precompile-batch = { workspace = true }
pallet-evm-precompile-call-permit = { workspace = true }
pallet-evm-precompile-democracy = { workspace = true }
Expand All @@ -142,16 +142,18 @@ pallet-evm-precompile-multi-asset-delegation = { workspace = true }
pallet-evm-precompile-services = { workspace = true }
pallet-evm-precompile-tangle-lst = { workspace = true }
precompile-utils = { workspace = true }

evm-tracer = { workspace = true }
rpc-primitives-debug = { workspace = true }
rpc-primitives-txpool = { workspace = true }

# XCM
xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
polkadot-parachain-primitives = { workspace = true }
# Hyperbridge
pallet-ismp = { workspace = true, features = ["unsigned"] }
pallet-ismp-runtime-api = { workspace = true }
pallet-hyperbridge = { workspace = true }
pallet-token-gateway = { workspace = true }
ismp = { workspace = true }
ismp-grandpa = { workspace = true }
anyhow = { workspace = true }

[features]
runtime-benchmarks = [
Expand All @@ -176,8 +178,6 @@ runtime-benchmarks = [
# Tangle
"pallet-services/runtime-benchmarks",
"pallet-airdrop-claims/runtime-benchmarks",

"xcm-builder/runtime-benchmarks",
"pallet-multi-asset-delegation/runtime-benchmarks",
"pallet-tangle-lst-benchmarking/runtime-benchmarks",
"pallet-rewards/runtime-benchmarks"
Expand Down Expand Up @@ -308,11 +308,13 @@ std = [
"pallet-evm-precompile-services/std",
"pallet-evm-precompile-tangle-lst/std",

# XCM
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
"polkadot-parachain-primitives/std",
# Hyperbridge
"pallet-hyperbridge/std",
"pallet-ismp/std",
"pallet-token-gateway/std",
"ismp/std",
"ismp-grandpa/std",
"pallet-ismp-runtime-api/std",
]
integration-tests = ["tangle-primitives/integration-tests"]
with-rocksdb-weights = []
Expand Down
128 changes: 128 additions & 0 deletions runtime/testnet/src/hyperbridge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// This file is part of Tangle.

// Copyright (C) Tangle Foundation
// Copyright (C) Liebi Technologies PTE. LTD.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
AccountId, Assets, Balances, EnsureRoot, EnsureRootOrHalfCouncil, Get, Ismp, Runtime,
RuntimeEvent, Timestamp, TokenGateway, Treasury, H160,
};
use frame_support::parameter_types;
use ismp::{host::StateMachine, module::IsmpModule, router::IsmpRouter};
use pallet_token_gateway::types::EvmToSubstrate;
use sp_std::boxed::Box;
use sp_std::vec::Vec;
use tangle_primitives::Balance;

impl pallet_hyperbridge::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// pallet-ismp implements the IsmpHost
type IsmpHost = Ismp;
}

parameter_types! {
// The hyperbridge parachain on Polkadot
pub const Coprocessor: Option<StateMachine> = Some(StateMachine::Kusama(4009));
// The host state machine of this pallet, your state machine id goes here
pub const HostStateMachine: StateMachine = StateMachine::Substrate(*b"TNGL");
}

impl pallet_ismp::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// Modify the consensus client's permissions, for example, TechAdmin
type AdminOrigin = EnsureRootOrHalfCouncil;
// The state machine identifier of the chain -- parachain id
type HostStateMachine = HostStateMachine;
type TimestampProvider = Timestamp;
// The router provides the implementation for the IsmpModule as the module id.
type Router = Router;
type Balance = Balance;
// The token used to collect fees, only stablecoins are supported
type Currency = Balances;
// Co-processor
type Coprocessor = Coprocessor;
// A tuple of types implementing the ConsensusClient interface, which defines all consensus algorithms supported by this protocol deployment
type ConsensusClients = (::ismp_grandpa::consensus::GrandpaConsensusClient<Runtime>,);
type WeightProvider = ();
type OffchainDB = ();
}

impl ::ismp_grandpa::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type IsmpHost = pallet_ismp::Pallet<Runtime>;
type WeightInfo = crate::weights::ismp_grandpa::WeightInfo<Runtime>;
}

#[derive(Default)]
pub struct Router;

impl IsmpRouter for Router {
fn module_for_id(&self, id: Vec<u8>) -> Result<Box<dyn IsmpModule>, anyhow::Error> {
match id.as_slice() {
pallet_hyperbridge::PALLET_HYPERBRIDGE_ID => {
Ok(Box::new(pallet_hyperbridge::Pallet::<Runtime>::default()))
},
id if TokenGateway::is_token_gateway(id) => Ok(Box::new(TokenGateway::default())),
_ => Err(ismp::Error::ModuleNotFound(id))?,
}
}
}

pub struct EvmToSubstrateFactory;

impl EvmToSubstrate<Runtime> for EvmToSubstrateFactory {
fn convert(addr: H160) -> AccountId {
let mut account = [0u8; 32];
account[12..].copy_from_slice(&addr.0);
account.into()
}
}

/// Should provide an account that is funded and can be used to pay for asset creation
pub struct AssetAdmin;
impl Get<AccountId> for AssetAdmin {
fn get() -> AccountId {
Treasury::account_id()
}
}

parameter_types! {
// A constant that should represent the native asset id, this id must be unique to the native currency
pub const NativeAssetId: u32 = 0;
// Set the correct decimals for the native currency
pub const Decimals: u8 = 18;
}

impl ::pallet_token_gateway::Config for Runtime {
// configure the runtime event
type RuntimeEvent = RuntimeEvent;
// Configured as Pallet Ismp
type Dispatcher = pallet_hyperbridge::Pallet<Runtime>;
// Configured as Pallet Assets
type Assets = Assets;
// Configured as Pallet balances
type NativeCurrency = Balances;
// AssetAdmin account
type AssetAdmin = AssetAdmin;
// The Native asset Id
type NativeAssetId = NativeAssetId;
// The precision of the native asset
type Decimals = Decimals;
type EvmToSubstrate = EvmToSubstrateFactory;
type WeightInfo = crate::weights::pallet_token_gateway::SubstrateWeight<Runtime>;
type CreateOrigin = EnsureRoot<AccountId>;
}
51 changes: 50 additions & 1 deletion runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

mod filters;
pub mod frontier_evm;
pub mod hyperbridge;
pub mod impls;
pub mod migrations;
pub mod precompiles;
pub mod tangle_services;
pub mod voter_bags;
pub mod weights;

use frame_election_provider_support::{
bounds::{ElectionBounds, ElectionBoundsBuilder},
Expand All @@ -46,6 +48,11 @@ use frame_support::{
use frame_system::EnsureSigned;
use frame_system::EnsureSignedBy;
use frontier_evm::DefaultBaseFeePerGas;
use ismp::{
consensus::{ConsensusClientId, StateMachineHeight, StateMachineId},
host::StateMachine,
router::{Request, Response},
};
use pallet_election_provider_multi_phase::{GeometricDepositBase, SolutionAccuracyOf};
use pallet_evm::GasWeightMapping;
use pallet_grandpa::{
Expand Down Expand Up @@ -185,7 +192,7 @@ pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}

pub const MAXIMUM_BLOCK_LENGTH: u32 = 5 * 1024 * 1024;
pub const MAXIMUM_BLOCK_LENGTH: u32 = 8 * 1024 * 1024;

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
Expand Down Expand Up @@ -1312,6 +1319,10 @@ construct_runtime!(
Lst: pallet_tangle_lst = 52,
Rewards: pallet_rewards = 53,

Ismp: pallet_ismp = 55,
IsmpGrandpa: ismp_grandpa = 56,
Hyperbridge: pallet_hyperbridge = 57,
TokenGateway: pallet_token_gateway = 58,
}
);

Expand Down Expand Up @@ -2270,6 +2281,44 @@ impl_runtime_apis! {
}
}

impl pallet_ismp_runtime_api::IsmpRuntimeApi<Block, <Block as BlockT>::Hash> for Runtime {
fn host_state_machine() -> StateMachine {
<Runtime as pallet_ismp::Config>::HostStateMachine::get()
}

fn challenge_period(state_machine_id: StateMachineId) -> Option<u64> {
pallet_ismp::Pallet::<Runtime>::challenge_period(state_machine_id)
}

fn block_events() -> Vec<::ismp::events::Event> {
pallet_ismp::Pallet::<Runtime>::block_events()
}

fn block_events_with_metadata() -> Vec<(::ismp::events::Event, Option<u32>)> {
pallet_ismp::Pallet::<Runtime>::block_events_with_metadata()
}

fn consensus_state(id: ConsensusClientId) -> Option<Vec<u8>> {
pallet_ismp::Pallet::<Runtime>::consensus_states(id)
}

fn state_machine_update_time(height: StateMachineHeight) -> Option<u64> {
pallet_ismp::Pallet::<Runtime>::state_machine_update_time(height)
}

fn latest_state_machine_height(id: StateMachineId) -> Option<u64> {
pallet_ismp::Pallet::<Runtime>::latest_state_machine_height(id)
}

fn requests(commitments: Vec<H256>) -> Vec<Request> {
pallet_ismp::Pallet::<Runtime>::requests(commitments)
}

fn responses(commitments: Vec<H256>) -> Vec<Response> {
pallet_ismp::Pallet::<Runtime>::responses(commitments)
}
}

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Expand Down
Loading
Loading