pallet_bridge/
bridged.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::Config;

use scale_codec::{Decode, DecodeWithMemTracking, Encode};

use polkadot_sdk::*;

use frame_support::traits::LockIdentifier;
use sp_core::Get;
use sp_runtime::traits::AccountIdConversion;
use sp_runtime::RuntimeDebug;

#[derive(
	Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, scale_info::TypeInfo,
)]
#[repr(u8)]
pub enum BridgedChain {
	Ethereum,
	Base,
}

impl BridgedChain {
	/// Retrieve sub id used in virtual wallet generation
	pub fn sub_id(&self) -> &'static [u8] {
		use BridgedChain::*;

		match self {
			Ethereum => b"bridged-erc20",
			Base => b"bridged-base",
		}
	}

	/// Compute account id of virtual wallet tracking issuance
	pub fn account_id<T: Config>(&self) -> T::AccountId {
		T::PalletId::get().into_sub_account_truncating(self.sub_id())
	}

	/// Current identifier under which to lock tokens
	pub fn lock_id(&self) -> LockIdentifier {
		use BridgedChain::*;

		match self {
			Ethereum => *b"bridged0",
			Base => *b"bridged1",
		}
	}
}