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

feat: add tmp mimic pallet for bitacross #2634

Merged
merged 9 commits into from
Apr 8, 2024
Merged
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
14 changes: 14 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
'node',
'pallets/account-fix',
'pallets/bitacross',
'pallets/bitacrossmimic',
'pallets/bridge',
'pallets/bridge-transfer',
'pallets/drop3',
Expand Down Expand Up @@ -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 }
Expand Down
34 changes: 34 additions & 0 deletions pallets/bitacrossmimic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
authors = ['Trust Computing GmbH <info@litentry.com>']
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"]
49 changes: 49 additions & 0 deletions pallets/bitacrossmimic/src/custodial_type.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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,
}
87 changes: 87 additions & 0 deletions pallets/bitacrossmimic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

#![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<T>(PhantomData<T>);

#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

#[pallet::storage]
#[pallet::getter(fn mimic_btc_to_eth_storage)]
pub type MimicBtcToEthStorage<T: Config> =
StorageDoubleMap<_, Blake2_256, PubKey, Blake2_256, u64, BtcToEth>;

#[pallet::storage]
#[pallet::getter(fn mimic_eth_to_btc_storage)]
pub type MimicEthToBtcStorage<T: Config> =
StorageDoubleMap<_, Blake2_256, H160, Blake2_256, u64, EthToBtc>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
BtcToEthSaved { btc: PubKey, tx_index: u64 },
EthToBtcSaved { eth: H160, tx_index: u64 },
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// 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<T>,
btc_sender: PubKey,
data: BtcToEth,
) -> DispatchResult {
Self::deposit_event(Event::BtcToEthSaved { btc: btc_sender, tx_index: data.tx_index });
<MimicBtcToEthStorage<T>>::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<T>,
eth_sender: H160,
data: EthToBtc,
) -> DispatchResult {
Self::deposit_event(Event::EthToBtcSaved { eth: eth_sender, tx_index: data.tx_index });
<MimicEthToBtcStorage<T>>::insert(eth_sender, data.tx_index, data);
Ok(())
}
}
}
3 changes: 3 additions & 0 deletions runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -303,4 +305,5 @@ try-runtime = [
"parachain-info/try-runtime",
"pallet-account-fix/try-runtime",
"pallet-bitacross/try-runtime",
"pallet-bitacross-mimic/try-runtime",
]
10 changes: 9 additions & 1 deletion runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IMPExtrinsicWhitelistInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type GroupManagerOrigin = EnsureRootOrAllCouncil;
Expand Down Expand Up @@ -1218,6 +1223,8 @@ construct_runtime! {
IMPExtrinsicWhitelist: pallet_group::<Instance1> = 67,
VCMPExtrinsicWhitelist: pallet_group::<Instance2> = 68,
Bitacross: pallet_bitacross = 70,
// Temporary for bitacross team to test
BitacrossMimic: pallet_bitacross_mimic = 71,

// TEE
Teebag: pallet_teebag = 93,
Expand Down Expand Up @@ -1316,7 +1323,8 @@ impl Contains<RuntimeCall> for NormalModeFilter {
RuntimeCall::Ethereum(_) |
// AccountFix
RuntimeCall::AccountFix(_) |
RuntimeCall::Bitacross(_)
RuntimeCall::Bitacross(_) |
RuntimeCall::BitacrossMimic(_)
)
}
}
Expand Down
Loading