SPB Git

Repository Public

SolanaNetwork.swift 5.2 KB 126 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : Sources/QyvoraSolana/SolanaNetwork.swift8// Module           : Qyvora Solana9// 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 QyvoraCore43import QyvoraNetworking4445/// The Solana clusters QYVORA talks to.46public enum SolanaNetwork: String, Codable, Sendable, CaseIterable {47    case mainnetBeta = "mainnet-beta"48    case devnet49    case testnet5051    public var isTest: Bool { self != .mainnetBeta }5253    public var displayName: String {54        switch self {55        case .mainnetBeta: return "Solana"56        case .devnet: return "Solana Devnet"57        case .testnet: return "Solana Testnet"58        }59    }6061    /// Base58 hash of the genesis block: the identity of the cluster, checked against every endpoint before use62    /// (`SolanaRPC.verifyChain`). Values read from the public RPC of each cluster on 2026-12-05.63    public var genesisHash: String {64        switch self {65        case .mainnetBeta: return "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d"66        case .devnet: return "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG"67        case .testnet: return "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY"68        }69    }7071    /// SLIP-0044 coin type of Solana (the same on every cluster: Solana wallets do not use coin type 1 for tests).72    public static let coinType: UInt32 = 5017374    /// Decimals of the native asset: 1 SOL = 10^9 lamports.75    public static let decimals = 97677    /// Symbol of the native asset.78    public static let symbol = "SOL"79}8081/// The JSON-RPC endpoints of each cluster (key: raw value of `SolanaNetwork`). User-editable: the application stores82/// its own copy and passes it to `SolanaRPC`.83public struct SolanaEndpoints: Codable, Equatable, Sendable {84    public var rpc: [String: [String]]8586    /// Public, keyless endpoints. The Solana Foundation endpoints are rate limited (HTTP 429 under load) and the87    /// mainnet one refuses some heavy methods; a second independent operator is listed for mainnet.88    public static let `default` = SolanaEndpoints(rpc: [89        "mainnet-beta": ["https://api.mainnet-beta.solana.com", "https://solana-rpc.publicnode.com"],90        "devnet": ["https://api.devnet.solana.com"],91        "testnet": ["https://api.testnet.solana.com"],92    ])9394    public init(rpc: [String: [String]]) { self.rpc = rpc }9596    /// The usable URLs of a cluster, in order: https, or http for a local or private host only97    /// (`EndpointConfiguration.isAcceptable`).98    public func urls(for network: SolanaNetwork) -> [URL] {99        (rpc[network.rawValue] ?? []).compactMap { EndpointConfiguration.isAcceptable($0) ? URL(string: $0) : nil }100    }101}102103/// Errors of the Solana module that are not network errors.104public enum SolanaError: Error, Equatable, Sendable {105    /// Not a base58 string of 32 bytes.106    case invalidAddress107    /// The recent blockhash is not 32 bytes.108    case invalidBlockhash109    /// The private seed is not 32 bytes, or the BIP-39 seed has an invalid length.110    case invalidSeed111    /// More than 16 seeds, a seed longer than 32 bytes, or no bump gives an off-curve address.112    case invalidProgramAddressSeeds113    /// The serialized message or transaction is malformed; the text says where.114    case malformed(String)115    /// A message cannot reference more than 256 accounts.116    case tooManyAccounts117    /// An instruction, its accounts or its data exceed what the wire format can carry.118    case invalidInstruction(String)119    /// The serialized transaction exceeds the 1232 bytes a Solana packet can carry.120    case transactionTooLarge(Int)121    /// The key that was asked to sign is not one of the required signers of the message.122    case notASigner123    /// At least one required signature is missing.124    case missingSignature125}126
Files main
Menu

Theme