sgns::TokenAmount¶
Utility for GNUS token fixed-point parsing, formatting and cost calculation.
#include <TokenAmount.hpp>
Public Functions¶
| Name | |
|---|---|
| outcome::result< std::shared_ptr< TokenAmount > > | New(uint64_t raw_minions) Creates a TokenAmount from already-scaled minion units. |
| outcome::result< std::shared_ptr< TokenAmount > > | New(double value) Creates a TokenAmount from a floating point value. The value is rounded to 6 decimal digits internally. |
| outcome::result< std::shared_ptr< TokenAmount > > | New(const std::string & str) Creates a TokenAmount from a decimal string. |
| outcome::result< uint64_t > | ParseMinions(const std::string & str) Parses a token amount string into raw minion units. |
| std::string | FormatMinions(uint64_t minions) Converts raw minion units to a token string. |
| outcome::result< uint64_t > | CalculateCostMinions(uint64_t total_bytes, double price_usd_per_genius) Calculates token cost for a given byte size and USD price. |
| outcome::result< std::string > | ConvertToChildToken(uint64_t in, std::string ratio) |
| outcome::result< uint64_t > | ConvertFromChildToken(std::string in, std::string ratio) |
| outcome::result< TokenAmount > | Multiply(const TokenAmount & other) const Multiplies this TokenAmount by another. |
| outcome::result< TokenAmount > | Divide(const TokenAmount & other) const Divides this TokenAmount by another. |
| uint64_t | Value() const Returns the raw scaled integer (minion) value. |
Public Attributes¶
| Name | |
|---|---|
| uint64_t | PRECISION Fixed-point precision (1 minion = 10^-6 GNUS). |
| uint64_t | PRICE_PER_FLOP USD per FLOP rate scaled by 10^15. |
| uint64_t | PRICE_PER_FLOP_FRACTIONAL_DIGITS Fractional digits used in USD/FLOP rate. |
| uint64_t | FLOPS_PER_BYTE Estimated number of FLOPs required per byte. |
| uint64_t | MIN_MINION_UNITS Minimum representable non-zero minion units. |
Public Functions Documentation¶
function New¶
Creates a TokenAmount from already-scaled minion units.
Parameters:
- raw_minions Value in 10^6-scaled integer units.
Return: A shared pointer to a TokenAmount instance or error code.
function New¶
Creates a TokenAmount from a floating point value. The value is rounded to 6 decimal digits internally.
Parameters:
- value Floating point value representing token amount.
Return: A shared pointer to a TokenAmount instance or error code.
function New¶
Creates a TokenAmount from a decimal string.
Parameters:
- str String representation of the token amount.
Return: A shared pointer to a TokenAmount instance or error code.
function ParseMinions¶
Parses a token amount string into raw minion units.
Parameters:
- str Decimal string representation (e.g., "0.001000").
Return: Parsed minion value or error.
function FormatMinions¶
Converts raw minion units to a token string.
Parameters:
- minions Raw integer minion units.
Return: Formatted string with fixed-point representation.
Ensures exactly 6 digits of precision in the result.
function CalculateCostMinions¶
static outcome::result< uint64_t > CalculateCostMinions(
uint64_t total_bytes,
double price_usd_per_genius
)
Calculates token cost for a given byte size and USD price.
Parameters:
- total_bytes Total number of bytes processed.
- price_usd_per_genius GNUS token price in USD.
Return: Total cost in minion units, or error on overflow/underflow.
Internally estimates FLOPs based on bytes, applies the FLOP pricing and converts to GNUS token units using the provided USD price.
function ConvertToChildToken¶
function ConvertFromChildToken¶
function Multiply¶
Multiplies this TokenAmount by another.
Parameters:
- other Another TokenAmount instance.
Return: Result of the multiplication or error.
Result is rounded back to fixed 6-digit precision.
function Divide¶
Divides this TokenAmount by another.
Parameters:
- other Another TokenAmount instance.
Return: Result of the division or error.
function Value¶
Returns the raw scaled integer (minion) value.
Return: Value in raw minion units (10^6 scaled).
Public Attributes Documentation¶
variable PRECISION¶
Fixed-point precision (1 minion = 10^-6 GNUS).
variable PRICE_PER_FLOP¶
USD per FLOP rate scaled by 10^15.
variable PRICE_PER_FLOP_FRACTIONAL_DIGITS¶
Fractional digits used in USD/FLOP rate.
variable FLOPS_PER_BYTE¶
Estimated number of FLOPs required per byte.
variable MIN_MINION_UNITS¶
Minimum representable non-zero minion units.
Updated on 2026-03-04 at 13:10:43 -0800