Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmishra2005 committed Jan 10, 2025
1 parent 57df98f commit cefb400
Show file tree
Hide file tree
Showing 8 changed files with 935 additions and 167 deletions.
464 changes: 444 additions & 20 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ resolver = "2"

[workspace.dependencies]
# 3rd-party dependencies
anyhow = { version = "1.0", default-features = false }
base64ct = { version = "1.6.0" }
blake2 = { version = "0.10.6", default-features = false }
byte-unit = { version = "4.0.19", default-features = false, features = ["u128"] }
Expand Down Expand Up @@ -60,6 +61,7 @@ frame-benchmarking = { version = "37.0.0", default-features = false }
frame-benchmarking-cli = { version = "42.0.0", default-features = false }
frame-election-provider-support = { version = "37.0.0", default-features = false }
frame-executive = { version = "37.0.0", default-features = false }
frame-metadata-hash-extension = { default-features = false, version = "0.5.0" }
frame-support = { version = "37.0.0", default-features = false, features = ["tuples-96"] }
frame-system = { version = "37.0.0", default-features = false }
frame-system-benchmarking = { version = "37.0.0", default-features = false }
Expand Down Expand Up @@ -152,6 +154,7 @@ sp-core = { version = "34.0.0", default-features = false, features = ["serde"] }
sp-inherents = { version = "34.0.0", default-features = false }
sp-io = { version = "38.0.0", default-features = false }
sp-keystore = { version = "0.40.0", default-features = false }
sp-mmr-primitives = { default-features = false, version = "34.0.0" }
sp-offchain = { version = "34.0.0", default-features = false }
sp-rpc = { version = "32.0.0", default-features = false }
sp-rpc-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2407", default-features = false }
Expand Down Expand Up @@ -192,15 +195,14 @@ pallet-erc20 = { path = "pallets/erc20", default-features = false }
pallet-erc721 = { path = "pallets/erc721", default-features = false }
pallet-origins = { path = "pallets/origins", default-features = false }

# Hyperbridge
ismp = { default-features = false, version = "0.2.2" }
ismp-grandpa = { default-features = false, version = "1.15.4" }
pallet-hyperbridge = { default-features = false, version = "1.15.3" }
pallet-ismp = { default-features = false, version = "1.15.3" }
pallet-ismp-rpc = { default-features = false, version = "1.15.3" }
pallet-ismp-runtime-api = { default-features = false, version = "1.15.3" }
pallet-hyperbridge = { default-features = false, version = "1.15.3" }
ismp-grandpa = { default-features = false, version = "1.15.4" }
frame-metadata-hash-extension = { default-features = false, version = "0.5.0" }
sp-mmr-primitives = { default-features = false, version = "34.0.0" }
anyhow = { version = "1.0", default-features = false }
pallet-token-gateway = { default-features = false, version = "1.15.3" }

[profile.release]
panic = "unwind"
3 changes: 3 additions & 0 deletions runtime/cere-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ ismp-grandpa = { workspace = true }
pallet-hyperbridge = { workspace = true }
pallet-ismp = { workspace = true, features = ["unsigned"] }
pallet-ismp-runtime-api = { workspace = true }
pallet-token-gateway = { workspace = true }
sp-mmr-primitives = { workspace = true }

[build-dependencies]
Expand Down Expand Up @@ -209,6 +210,7 @@ std = [
"ismp-grandpa/std",
"anyhow/std",
"frame-metadata-hash-extension/std",
"pallet-token-gateway/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down Expand Up @@ -318,4 +320,5 @@ try-runtime = [
"pallet-ismp/try-runtime",
"pallet-hyperbridge/try-runtime",
"ismp-grandpa/try-runtime",
"pallet-token-gateway/try-runtime",
]
227 changes: 227 additions & 0 deletions runtime/cere-dev/src/hyperbridge_ismp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
use frame_support::parameter_types;
use frame_system::EnsureRoot;
use ismp::{error::Error, host::StateMachine, module::IsmpModule, router::IsmpRouter};
use ismp_grandpa::consensus::GrandpaConsensusClient;

use super::*;

parameter_types! {
// The hyperbridge parachain on Polkadot
pub const Coprocessor: Option<StateMachine> = Some(StateMachine::Polkadot(4009));
// The host state machine of this pallet, this must be unique to all every solochain
pub const HostStateMachine: StateMachine = StateMachine::Substrate(*b"cere"); // your unique chain id here
}

impl pallet_ismp::Config for Runtime {
// Configure the runtime event
type RuntimeEvent = RuntimeEvent;
// Permissioned origin who can create or update consensus clients
type AdminOrigin = EnsureRoot<AccountId>;
// The state machine identifier for this state machine
type HostStateMachine = HostStateMachine;
// The pallet_timestamp pallet
type TimestampProvider = Timestamp;
// The currency implementation that is offered to relayers
// this could also be `frame_support::traits::tokens::fungible::ItemOf`
type Currency = Balances;
// The balance type for the currency implementation
type Balance = Balance;
// Router implementation for routing requests/responses to their respective modules
type Router = ModuleRouter;
// Optional coprocessor for incoming requests/responses
type Coprocessor = Coprocessor;
// Supported consensus clients
type ConsensusClients = (
// Add the grandpa consensus client here
GrandpaConsensusClient<Runtime>,
);
// Offchain database implementation. Outgoing requests and responses are
// inserted in this database, while their commitments are stored onchain.
//
// The default implementation for `()` should suffice
type OffchainDB = ();
// Weight provider for local modules
type WeightProvider = ();
}

impl pallet_hyperbridge::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type IsmpHost = Ismp;
}

#[derive(Default)]
pub struct ModuleRouter;

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

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

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 = 10;
}

/// 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()
}
}

pub struct MockAssets;

impl fungibles::metadata::Inspect<AccountId> for MockAssets {
fn name(_asset: Self::AssetId) -> Vec<u8> {
vec![]
}

fn symbol(_asset: Self::AssetId) -> Vec<u8> {
vec![]
}

fn decimals(_asset: Self::AssetId) -> u8 {
0
}
}
impl Unbalanced<AccountId> for MockAssets {
fn handle_dust(_dust: Dust<AccountId, Self>) {}

fn write_balance(
_asset: Self::AssetId,
_who: &AccountId,
_amount: Self::Balance,
) -> Result<Option<Self::Balance>, DispatchError> {
Ok(None)
}

fn set_total_issuance(_asset: Self::AssetId, _amount: Self::Balance) {}
}

impl fungibles::Mutate<AccountId> for MockAssets {}

impl Inspect<AccountId> for MockAssets {
type AssetId = Balance;
type Balance = Balance;

fn total_issuance(_asset: Self::AssetId) -> Self::Balance {
0
}

fn minimum_balance(_asset: Self::AssetId) -> Self::Balance {
0
}

fn total_balance(_asset: Self::AssetId, _who: &AccountId) -> Self::Balance {
0
}

fn balance(_asset: Self::AssetId, _who: &AccountId) -> Self::Balance {
0
}

fn reducible_balance(
_asset: Self::AssetId,
_who: &AccountId,
_preservation: Preservation,
_force: Fortitude,
) -> Self::Balance {
0
}

fn can_deposit(
_asset: Self::AssetId,
_who: &AccountId,
_amount: Self::Balance,
_provenance: Provenance,
) -> DepositConsequence {
DepositConsequence::UnknownAsset
}

fn can_withdraw(
_asset: Self::AssetId,
_who: &AccountId,
_amount: Self::Balance,
) -> WithdrawConsequence<Self::Balance> {
WithdrawConsequence::UnknownAsset
}

fn asset_exists(_asset: Self::AssetId) -> bool {
false
}
}

impl fungibles::Create<AccountId> for MockAssets {
fn create(
_id: Self::AssetId,
_admin: AccountId,
_is_sufficient: bool,
_min_balance: Self::Balance,
) -> DispatchResult {
Ok(())
}
}

impl fungibles::metadata::Mutate<AccountId> for MockAssets {
fn set(
_asset: Self::AssetId,
_from: &AccountId,
_name: Vec<u8>,
_symbol: Vec<u8>,
_decimals: u8,
) -> frame_support::dispatch::DispatchResult {
Ok(())
}
}

impl fungibles::roles::Inspect<AccountId> for MockAssets {
fn owner(_asset: Self::AssetId) -> Option<AccountId> {
None
}

fn issuer(_asset: Self::AssetId) -> Option<AccountId> {
None
}

fn admin(_asset: Self::AssetId) -> Option<AccountId> {
None
}

fn freezer(_asset: Self::AssetId) -> Option<AccountId> {
None
}
}
impl pallet_token_gateway::Config for Runtime {
// configure the runtime event
type RuntimeEvent = RuntimeEvent;
// Configured as Pallet Ismp
type Dispatcher = Ismp;
// Configured as Pallet Assets
type Assets = MockAssets;
// Configured as Pallet balances
type NativeCurrency = Balances;
// AssetAdmin account
type AssetAdmin = AssetAdmin;
// The Native asset Id
type NativeAssetId = NativeAssetId;
// A type that provides a function for creating unique asset ids
// A concrete implementation for your specific runtime is required
type AssetIdFactory = ();
// The precision of the native asset
type Decimals = Decimals;
}
Loading

0 comments on commit cefb400

Please sign in to comment.