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    ///
19    /// Returns the official NEAR RPC endpoint URL for the specified network.
20    ///
21    /// # Returns
22    ///
23    /// Returns a static string slice with the RPC endpoint URL.
24    ///
25    /// # Example
26    ///
27    /// ```rust
28    /// use inf_circle_sdk::near::dto::NearNetwork;
29    ///
30    /// let mainnet = NearNetwork::Mainnet;
31    /// assert_eq!(mainnet.rpc_url(), "https://rpc.mainnet.near.org");
32    ///
33    /// let testnet = NearNetwork::Testnet;
34    /// assert_eq!(testnet.rpc_url(), "https://rpc.testnet.near.org");
35    /// ```
36    pub fn rpc_url(&self) -> &'static str {
37        match self {
38            NearNetwork::Mainnet => "https://rpc.mainnet.near.org",
39            NearNetwork::Testnet => "https://rpc.testnet.near.org",
40        }
41    }
42}
43
44/// NEAR account balance information
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct NearAccountBalance {
47    /// Total account balance in NEAR (as string to preserve precision)
48    pub total: String,
49    /// Available balance in NEAR (total - staked)
50    pub available: String,
51    /// Staked balance in NEAR
52    pub staked: String,
53    /// Account state hash
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub state_hash: Option<String>,
56    /// Block hash when this balance was queried
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub block_hash: Option<CryptoHash>,
59    /// Block height when this balance was queried
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub block_height: Option<u64>,
62}
63
64/// NEAR fungible token (NEP-141) balance information
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct NearTokenBalance {
67    /// Token contract account ID
68    pub contract_id: String,
69    /// Token balance (as string to preserve precision)
70    pub balance: String,
71    /// Token metadata (if available)
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub metadata: Option<NearTokenMetadata>,
74}
75
76/// NEAR fungible token (NEP-141) metadata
77#[derive(Debug, Clone, Serialize, Deserialize)]
78pub struct NearTokenMetadata {
79    /// Token symbol (e.g., "USDC", "USDT")
80    pub symbol: String,
81    /// Token name (e.g., "USD Coin")
82    pub name: String,
83    /// Number of decimals
84    pub decimals: u8,
85    /// Token icon URL (if available)
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub icon: Option<String>,
88    /// Reference URL (if available)
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub reference: Option<String>,
91}