Skip to main content

tensora/
types.rs

1//! Shared types for the Tensora SDK
2
3use ethers::types::{Address, U256, H256};
4use serde::{Deserialize, Serialize};
5
6/// Information about a subnet
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct SubnetInfo {
9    /// Unique subnet ID
10    pub id: u32,
11    /// Subnet name
12    pub name: String,
13    /// Subnet owner address
14    pub owner: Address,
15    /// Minimum stake required
16    pub min_stake: U256,
17    /// Number of active validators
18    pub validator_count: u32,
19    /// Number of active miners
20    pub miner_count: u32,
21    /// Subnet status (active, paused, etc.)
22    pub status: SubnetStatus,
23    /// Subnet creation timestamp
24    pub created_at: u64,
25}
26
27/// Subnet status enum
28#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
29#[serde(rename_all = "lowercase")]
30pub enum SubnetStatus {
31    Active,
32    Paused,
33    Inactive,
34}
35
36/// Information about a validator
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct ValidatorInfo {
39    /// Validator address
40    pub address: Address,
41    /// Subnet ID
42    pub subnet_id: u32,
43    /// Staked amount
44    pub stake: U256,
45    /// Validator status
46    pub status: ValidatorStatus,
47    /// Uptime percentage (0-100)
48    pub uptime: u8,
49    /// Last active timestamp
50    pub last_active: u64,
51    /// Total rewards earned
52    pub total_rewards: U256,
53}
54
55/// Validator status enum
56#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
57#[serde(rename_all = "lowercase")]
58pub enum ValidatorStatus {
59    Active,
60    Inactive,
61    Slashed,
62}
63
64/// Information about a miner
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct MinerInfo {
67    /// Miner address
68    pub address: Address,
69    /// Subnet ID
70    pub subnet_id: u32,
71    /// Staked amount
72    pub stake: U256,
73    /// Miner status
74    pub status: MinerStatus,
75    /// Hashrate or compute power
76    pub power: U256,
77    /// Total rewards earned
78    pub total_rewards: U256,
79}
80
81/// Miner status enum
82#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
83#[serde(rename_all = "lowercase")]
84pub enum MinerStatus {
85    Active,
86    Inactive,
87}
88
89/// Bridge deposit information
90#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct BridgeDeposit {
92    /// Transaction hash on L1
93    pub l1_tx_hash: H256,
94    /// From address
95    pub from: Address,
96    /// To address on L2
97    pub to: Address,
98    /// Amount deposited
99    pub amount: U256,
100    /// Token address (WTORA)
101    pub token: Address,
102    /// Deposit status
103    pub status: BridgeStatus,
104    /// Timestamp
105    pub timestamp: u64,
106}
107
108/// Bridge withdrawal information
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct BridgeWithdraw {
111    /// Transaction hash on L2
112    pub l2_tx_hash: H256,
113    /// From address
114    pub from: Address,
115    /// To address on L1
116    pub to: Address,
117    /// Amount withdrawn
118    pub amount: U256,
119    /// Token address (WTORA)
120    pub token: Address,
121    /// Withdrawal status
122    pub status: BridgeStatus,
123    /// Timestamp
124    pub timestamp: u64,
125}
126
127/// Bridge operation status
128#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
129#[serde(rename_all = "lowercase")]
130pub enum BridgeStatus {
131    Pending,
132    Confirmed,
133    Finalized,
134    Failed,
135}
136
137/// Network statistics
138#[derive(Debug, Clone, Serialize, Deserialize)]
139pub struct NetworkStats {
140    /// Current block number
141    pub block_number: u64,
142    /// Total subnets
143    pub total_subnets: u32,
144    /// Total validators
145    pub total_validators: u32,
146    /// Total miners
147    pub total_miners: u32,
148    /// Total staked amount
149    pub total_staked: U256,
150    /// 24h transaction count
151    pub tx_count_24h: u64,
152}
153
154/// Paymaster quote response
155#[derive(Debug, Clone, Serialize, Deserialize)]
156pub struct PaymasterQuote {
157    /// Maximum gas price paymaster will cover
158    pub max_gas_price: U256,
159    /// Maximum gas amount
160    pub max_gas: u64,
161    /// Quote expiry timestamp
162    pub expires_at: u64,
163    /// Paymaster signature
164    pub signature: Vec<u8>,
165}
166
167/// Epoch information
168#[derive(Debug, Clone, Serialize, Deserialize)]
169pub struct EpochInfo {
170    /// Current epoch number
171    pub epoch: u64,
172    /// Epoch start timestamp
173    pub start_time: u64,
174    /// Epoch end timestamp
175    pub end_time: u64,
176    /// Total rewards for this epoch
177    pub total_rewards: U256,
178    /// VRF seed for this epoch
179    pub vrf_seed: H256,
180}
181
182/// Chain configuration constants
183pub mod chains {
184    /// Tensora L2 chain ID
185    pub const TENSORA_CHAIN_ID: u64 = 44444444;
186    
187    /// BSC mainnet chain ID
188    pub const BSC_CHAIN_ID: u64 = 56;
189    
190    /// Tensora L2 RPC endpoint
191    pub const TENSORA_RPC: &str = "https://rpc.tensora.sh";
192    
193    /// BSC mainnet RPC endpoint
194    pub const BSC_RPC: &str = "https://bsc-dataseed.binance.org";
195}
196