// // Asset.swift // OS Vault // // Author: Simon-Pierre Boucher // Mail: contact@spboucher.ai // import Foundation /// Anything the wallet can send on an EVM chain: the chain's native coin /// (ETH, POL, BNB, AVAX, xDAI… — also the gas currency) or a registered /// ERC-20 stablecoin. Native symbol/name depend on the chain, so they are /// resolved against a Network. public enum Asset: Identifiable, Hashable, Sendable { case native case token(Token) public var id: String { switch self { case .native: return "native" case .token(let token): return "token-\(token.symbol)" } } public func symbol(on network: Network) -> String { switch self { case .native: return network.config.nativeSymbol case .token(let token): return token.symbol } } public func name(on network: Network) -> String { switch self { case .native: return network.config.nativeName case .token(let token): return token.name } } /// All supported natives are 18 decimals (ETH, POL, BNB, AVAX, xDAI). public var decimals: Int { switch self { case .native: return 18 case .token(let token): return token.decimals } } public static func available(on network: Network) -> [Asset] { Token.available(on: network).map(Asset.token) + [.native] } }