Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : Sources/QyvoraTron/TronTokens.swift8// Module : Qyvora Tron9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0512// Last Modified : 2026-12-0513//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Foundation42import QyvoraMath43import QyvoraCore4445/// A TRC-20 token contract known to the wallet. A token is identified by its contract address only: symbols and46/// names are free text that any contract may claim.47public struct TronToken: Equatable, Hashable, Sendable, Codable, Identifiable {48 public let network: TronNetwork49 public let contract: TronAddress50 public let symbol: String51 public let name: String52 public let decimals: Int53 /// A fact the user should know before relying on the token, when there is one.54 public let note: String?55 /// True for a token added by the user, false for the built-in list.56 public let custom: Bool5758 public var id: String { "\(network.rawValue):\(contract.base58)" }5960 public init(network: TronNetwork, contract: TronAddress, symbol: String, name: String, decimals: Int, note: String? = nil, custom: Bool = false) {61 self.network = network62 self.contract = contract63 self.symbol = symbol64 self.name = name65 self.decimals = decimals66 self.note = note67 self.custom = custom68 }69}7071/// Tokens the wallet knows without the user adding them. Mainnet only; the test networks have none built in.72///73/// Each entry was read on chain on 2026-12-05 from two independent nodes (TronGrid and PublicNode): the address is a74/// contract account, and `decimals()`, `symbol()` and `name()` return the values below. `TronClient.verify(token:)`75/// repeats that check; the wallet service should run it before the first use.76public enum TronBuiltInTokens {77 /// One row: contract, symbol, name, decimals, note, and `pegUSD` — true for a token redeemable one for one78 /// against the US dollar, whose dollar ceiling on an unaudited mainnet build is converted at no less than 0.90 USD79 /// (`MainnetPolicy.stablecoinCeilingPrice`, QYV-SVC-087). Read from this table only, never from a stored profile.80 private static let table: [(String, String, String, Int, String?, pegUSD: Bool)] = [81 ("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", "USDT", "Tether USD", 6, nil, pegUSD: true),82 ("TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8", "USDC", "USD Coin", 6,83 "Circle ended its support of USDC on TRON in 2024. The contract still answers on chain.", pegUSD: true),84 ]8586 private static let pegged: Set<TronAddress> = Set(table.filter(\.pegUSD).compactMap { TronAddress($0.0) })8788 /// True when `contract` is, on `network`, a built-in token marked `pegUSD`.89 public static func isDollarPegged(_ contract: TronAddress, on network: TronNetwork) -> Bool {90 network == .mainnet && pegged.contains(contract)91 }9293 public static let mainnet: [TronToken] = table.compactMap { row in94 guard let contract = TronAddress(row.0) else { return nil }95 return TronToken(network: .mainnet, contract: contract, symbol: row.1, name: row.2, decimals: row.3, note: row.4)96 }9798 public static func tokens(for network: TronNetwork) -> [TronToken] { network == .mainnet ? mainnet : [] }99100 /// The built-in token at this contract address, if any.101 public static func token(_ contract: TronAddress, on network: TronNetwork) -> TronToken? {102 tokens(for: network).first { $0.contract == contract }103 }104}105