inf_circle_sdk/near/
dto.rs

1//! NEAR Protocol Data Transfer Objects
2//!
3//! This module contains all data structures used for NEAR protocol operations,
4//! including network identifiers, account balance information, and RPC response types.
5
6use near_primitives::hash::CryptoHash;
7use serde::{Deserialize, Serialize};
8
9/// NEAR network identifier
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum NearNetwork {
12    Mainnet,
13    Testnet,
14}
15
16impl NearNetwork {
17    /// Get the RPC endpoint URL for this network
18    pub fn rpc_url(&self) -> &'static str {
19        match self {
20            NearNetwork::Mainnet => "https://rpc.mainnet.near.org",
21            NearNetwork::Testnet => "https://rpc.testnet.near.org",
22        }
23    }
24}
25
26/// NEAR account balance information
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct NearAccountBalance {
29    /// Total account balance in NEAR (as string to preserve precision)
30    pub total: String,
31    /// Available balance in NEAR (total - staked)
32    pub available: String,
33    /// Staked balance in NEAR
34    pub staked: String,
35    /// Account state hash
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub state_hash: Option<String>,
38    /// Block hash when this balance was queried
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub block_hash: Option<CryptoHash>,
41    /// Block height when this balance was queried
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub block_height: Option<u64>,
44}
45
46/// NEAR fungible token (NEP-141) balance information
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct NearTokenBalance {
49    /// Token contract account ID
50    pub contract_id: String,
51    /// Token balance (as string to preserve precision)
52    pub balance: String,
53    /// Token metadata (if available)
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub metadata: Option<NearTokenMetadata>,
56}
57
58/// NEAR fungible token (NEP-141) metadata
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct NearTokenMetadata {
61    /// Token symbol (e.g., "USDC", "USDT")
62    pub symbol: String,
63    /// Token name (e.g., "USD Coin")
64    pub name: String,
65    /// Number of decimals
66    pub decimals: u8,
67    /// Token icon URL (if available)
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub icon: Option<String>,
70    /// Reference URL (if available)
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub reference: Option<String>,
73}