diff --git a/Cargo.lock b/Cargo.lock index 75c8c1b1aa..9f5fc6610c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6966,6 +6966,19 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-bitacross-mimic" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-bounties" version = "4.0.0-dev" @@ -10500,6 +10513,7 @@ dependencies = [ "pallet-authorship", "pallet-balances", "pallet-bitacross", + "pallet-bitacross-mimic", "pallet-bounties", "pallet-bridge", "pallet-bridge-transfer", diff --git a/Cargo.toml b/Cargo.toml index e58f43e961..0fd12672cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ 'node', 'pallets/account-fix', 'pallets/bitacross', + 'pallets/bitacrossmimic', 'pallets/bridge', 'pallets/bridge-transfer', 'pallets/drop3', @@ -244,6 +245,7 @@ rococo-parachain-runtime = { path = "runtime/rococo", default-features = false } pallet-account-fix = { path = "pallets/account-fix", default-features = false } pallet-asset-manager = { path = "pallets/xcm-asset-manager", default-features = false } pallet-bitacross = { path = "pallets/bitacross", default-features = false } +pallet-bitacross-mimic = { path = "pallets/bitacrossmimic", default-features = false } pallet-bridge = { path = "pallets/bridge", default-features = false } pallet-bridge-transfer = { path = "pallets/bridge-transfer", default-features = false } pallet-drop3 = { path = "pallets/drop3", default-features = false } diff --git a/pallets/bitacrossmimic/Cargo.toml b/pallets/bitacrossmimic/Cargo.toml new file mode 100644 index 0000000000..27384a6b01 --- /dev/null +++ b/pallets/bitacrossmimic/Cargo.toml @@ -0,0 +1,34 @@ +[package] +authors = ['Trust Computing GmbH '] +edition = '2021' +homepage = 'https://litentry.com' +name = "pallet-bitacross-mimic" +repository = 'https://github.com/litentry/litentry-parachain' +version = '0.1.0' + +[dependencies] +parity-scale-codec = { workspace = true } +scale-info = { workspace = true } + +frame-support = { workspace = true } +frame-system = { workspace = true } +sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } + +[features] +default = ["std"] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", +] +std = [ + "parity-scale-codec/std", + "scale-info/std", + "sp-std/std", + "sp-runtime/std", + "sp-core/std", + "frame-support/std", + "frame-system/std", +] +try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/bitacrossmimic/src/custodial_type.rs b/pallets/bitacrossmimic/src/custodial_type.rs new file mode 100644 index 0000000000..ba678fe872 --- /dev/null +++ b/pallets/bitacrossmimic/src/custodial_type.rs @@ -0,0 +1,49 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry 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. +// +// Litentry 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 Litentry. If not, see . + +extern crate alloc; +use alloc::string::String; +use parity_scale_codec::{Decode, Encode}; +use scale_info::TypeInfo; +use sp_core::{H160, H256, U256}; +pub type PubKey = [u8; 33]; + +/// custodial bit cross record of a full single tx from BTC to ETH +#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo)] +pub struct BtcToEth { + pub tx_index: u64, + pub btc_tx_hash: H256, + pub ethereum_receiver: H160, + pub ethereum_tx_hash: H256, + pub eth_tx_status: bool, + pub symbol: String, + pub amount: U256, + pub tx_timestamp: u64, +} + +/// custodial bit cross record of a full single tx from ETH to BTC +#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo)] +pub struct EthToBtc { + pub tx_index: u64, + pub btc_tx_hash: H256, + pub btc_receiver: PubKey, + pub btc_receiver_length: u32, + pub ethereum_tx_hash: H256, + pub eth_tx_status: bool, + pub symbol: String, + pub amount: U256, + pub tx_timestamp: u64, +} diff --git a/pallets/bitacrossmimic/src/lib.rs b/pallets/bitacrossmimic/src/lib.rs new file mode 100644 index 0000000000..769315e99d --- /dev/null +++ b/pallets/bitacrossmimic/src/lib.rs @@ -0,0 +1,87 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry 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. +// +// Litentry 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 Litentry. If not, see . + +#![cfg_attr(not(feature = "std"), no_std)] + +use frame_support::{dispatch::DispatchResult, pallet_prelude::*}; +use frame_system::pallet_prelude::*; +use sp_core::H160; + +pub use pallet::*; + +mod custodial_type; +pub use custodial_type::*; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(PhantomData); + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::storage] + #[pallet::getter(fn mimic_btc_to_eth_storage)] + pub type MimicBtcToEthStorage = + StorageDoubleMap<_, Blake2_256, PubKey, Blake2_256, u64, BtcToEth>; + + #[pallet::storage] + #[pallet::getter(fn mimic_eth_to_btc_storage)] + pub type MimicEthToBtcStorage = + StorageDoubleMap<_, Blake2_256, H160, Blake2_256, u64, EthToBtc>; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + BtcToEthSaved { btc: PubKey, tx_index: u64 }, + EthToBtcSaved { eth: H160, tx_index: u64 }, + } + + #[pallet::call] + impl Pallet { + /// Set the admin account + /// + /// Weights should be 2 DB writes: 1 for mode and 1 for event + #[pallet::call_index(0)] + #[pallet::weight({195_000_000})] + pub fn write_btc_to_eth( + _origin: OriginFor, + btc_sender: PubKey, + data: BtcToEth, + ) -> DispatchResult { + Self::deposit_event(Event::BtcToEthSaved { btc: btc_sender, tx_index: data.tx_index }); + >::insert(btc_sender, data.tx_index, data); + Ok(()) + } + + #[pallet::call_index(1)] + #[pallet::weight({195_000_000})] + pub fn write_eth_to_btc( + _origin: OriginFor, + eth_sender: H160, + data: EthToBtc, + ) -> DispatchResult { + Self::deposit_event(Event::EthToBtcSaved { eth: eth_sender, tx_index: data.tx_index }); + >::insert(eth_sender, data.tx_index, data); + Ok(()) + } + } +} diff --git a/runtime/rococo/Cargo.toml b/runtime/rococo/Cargo.toml index 2e34709884..91134fd18b 100644 --- a/runtime/rococo/Cargo.toml +++ b/runtime/rococo/Cargo.toml @@ -79,6 +79,7 @@ core-primitives = { workspace = true } pallet-account-fix = { workspace = true } pallet-asset-manager = { workspace = true } pallet-bitacross = { workspace = true } +pallet-bitacross-mimic = { workspace = true } pallet-bridge = { workspace = true } pallet-bridge-transfer = { workspace = true } pallet-drop3 = { workspace = true } @@ -253,6 +254,7 @@ std = [ "moonbeam-rpc-primitives-debug/std", "moonbeam-rpc-primitives-txpool/std", "pallet-bitacross/std", + "pallet-bitacross-mimic/std", ] try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", @@ -303,4 +305,5 @@ try-runtime = [ "parachain-info/try-runtime", "pallet-account-fix/try-runtime", "pallet-bitacross/try-runtime", + "pallet-bitacross-mimic/try-runtime", ] diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 1153fb63e7..61051df476 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1000,6 +1000,11 @@ impl pallet_bitacross::Config for Runtime { type SetAdminOrigin = EnsureRootOrAllCouncil; } +// Temporary for bitacross team to test +impl pallet_bitacross_mimic::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + impl pallet_group::Config for Runtime { type RuntimeEvent = RuntimeEvent; type GroupManagerOrigin = EnsureRootOrAllCouncil; @@ -1218,6 +1223,8 @@ construct_runtime! { IMPExtrinsicWhitelist: pallet_group:: = 67, VCMPExtrinsicWhitelist: pallet_group:: = 68, Bitacross: pallet_bitacross = 70, + // Temporary for bitacross team to test + BitacrossMimic: pallet_bitacross_mimic = 71, // TEE Teebag: pallet_teebag = 93, @@ -1316,7 +1323,8 @@ impl Contains for NormalModeFilter { RuntimeCall::Ethereum(_) | // AccountFix RuntimeCall::AccountFix(_) | - RuntimeCall::Bitacross(_) + RuntimeCall::Bitacross(_) | + RuntimeCall::BitacrossMimic(_) ) } }