diff --git a/Cargo.toml b/Cargo.toml index 954b516..dd190f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,8 @@ members = [ "substrate-node/node", "substrate-node/runtime", "parachain-info", - "bridge-forwarder" + "bridge-forwarder", + "xcm-bridge" ] exclude = [ diff --git a/bridge-forwarder/src/lib.rs b/bridge-forwarder/src/lib.rs index 8c90b95..48e2b31 100644 --- a/bridge-forwarder/src/lib.rs +++ b/bridge-forwarder/src/lib.rs @@ -8,7 +8,7 @@ pub mod pallet { use frame_system::pallet_prelude::*; use frame_support::transactional; use frame_support::traits::StorageVersion; - use sygma_traits::{TransactorForwarder, OtherWorldBridge, InnerWorldBridge}; + use sygma_traits::{TransactorForwarder, Bridge}; use xcm::latest::{prelude::*, MultiAsset, MultiLocation}; const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); @@ -20,14 +20,13 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type SygmaBridge: OtherWorldBridge; - type XCMBridge: InnerWorldBridge; + type SygmaBridge: Bridge; + type XCMBridge: Bridge; } #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { - /// Assets being withdrawn from somewhere. XCMTransferForward {}, OtherWorldTransferForward {}, } @@ -37,16 +36,15 @@ pub mod pallet { #[pallet::call_index(0)] #[pallet::weight(Weight::from_parts(195_000_000, 0))] #[transactional] - pub fn xcm_transactor_forwarder(origin: OriginFor, what: MultiAsset, who: MultiLocation) -> DispatchResult { - T::XCMBridge::create_message()?; - T::XCMBridge::execute_message()? + fn xcm_transactor_forwarder(origin: OriginFor, what: MultiAsset, who: MultiLocation) -> DispatchResult { + T::XCMBridge::transfer(origin.into(), what, who)?; } #[pallet::call_index(1)] #[pallet::weight(Weight::from_parts(195_000_000, 0))] #[transactional] - pub fn other_world_transactor_forwarder(origin: OriginFor, what: MultiAsset, who: MultiLocation) -> DispatchResult { - T::SygmaBridge::deposit(origin.into(), what, who)? + fn other_world_transactor_forwarder(origin: OriginFor, what: MultiAsset, who: MultiLocation) -> DispatchResult { + T::SygmaBridge::transfer(origin.into(), what, who)? } } } diff --git a/bridge/src/lib.rs b/bridge/src/lib.rs index 73db766..f161d1f 100644 --- a/bridge/src/lib.rs +++ b/bridge/src/lib.rs @@ -51,7 +51,7 @@ pub mod pallet { use sp_std::collections::btree_map::BTreeMap; use sygma_traits::{ ChainID, DecimalConverter, DepositNonce, DomainID, ExtractDestinationData, FeeHandler, - MpcAddress, ResourceId, TransferType, VerifyingContractAddress, OtherWorldBridge, + MpcAddress, ResourceId, TransferType, VerifyingContractAddress, Bridge, }; #[allow(dead_code)] @@ -683,10 +683,10 @@ pub mod pallet { } } - impl OtherWorldBridge for Pallet { - fn do_deposit(sender: [u8; 32], - asset: MultiAsset, - dest: MultiLocation) -> DispatchResult { + impl Bridge for Pallet { + fn transfer(sender: [u8; 32], + asset: MultiAsset, + dest: MultiLocation) -> DispatchResult { &Self::deposit(sender, asset, dest)? } } diff --git a/traits/src/lib.rs b/traits/src/lib.rs index e1df7e8..1063be8 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -75,15 +75,10 @@ pub trait TransactorForwarder { fn other_world_transactor_forwarder(sender: [u8; 32], what: MultiAsset, who: MultiLocation) -> DispatchResult; } -pub trait OtherWorldBridge { - fn do_deposit( +pub trait Bridge { + fn transfer( sender: [u8; 32], asset: MultiAsset, dest: MultiLocation, ) -> DispatchResult; } - -pub trait InnerWorldBridge { - fn create_message() -> DispatchResult; - fn execute_message() -> DispatchResult; -} diff --git a/xcm-bridge/Cargo.toml b/xcm-bridge/Cargo.toml new file mode 100644 index 0000000..28bb014 --- /dev/null +++ b/xcm-bridge/Cargo.toml @@ -0,0 +1,52 @@ +[package] +name = "sygma-xcm-bridge" +version = "0.3.0" +edition = "2021" +license = "LGPL-3.0" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } +scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde", "decode"] } + +# Substrate +frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0", default-features = false } +frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0", default-features = false } +sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0", default-features = false } + +# Polkadot +xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0", default-features = false } +xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0", default-features = false } +xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0", default-features = false } + +# Local +sygma-traits = { path = "../traits", default-features = false } + +[dev-dependencies] +# Substrate +sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0" } +sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0" } +frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0" } +frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0" } +pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0" } +pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0" } + +sygma-traits = { path = "../traits" } + +[features] +default = ["std"] +std = [ + "codec/std", + "scale-info/std", + "frame-support/std", + "frame-system/std", + "sp-std/std", + "xcm/std", + "xcm-builder/std", + "xcm-executor/std", + "sygma-traits/std", +] +runtime-benchmarks = [ + 'frame-support/runtime-benchmarks', + 'frame-system/runtime-benchmarks', +] +try-runtime = ["frame-support/try-runtime"] diff --git a/xcm-bridge/src/lib.rs b/xcm-bridge/src/lib.rs new file mode 100644 index 0000000..1eb334a --- /dev/null +++ b/xcm-bridge/src/lib.rs @@ -0,0 +1,38 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +pub use self::pallet::*; + +#[frame_support::pallet] +pub mod pallet { + use sygma_traits::{Bridge}; + + const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); + + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + XCMTransferSend {}, + } + + #[pallet::call] + impl Bridge for Pallet { + #[pallet::call_index(0)] + #[pallet::weight(Weight::from_parts(195_000_000, 0))] + #[transactional] + fn transfer(sender: [u8; 32], + asset: MultiAsset, + dest: MultiLocation) -> DispatchResult { + // TODO: create xcm message + // TODO: execute xcm message + } + } +}