Documentation
¶
Overview ¶
Package amounts converts between SOVR display amounts and usovr base units with exact integer arithmetic (FR-017/FR-018). math/big only — no float64 on any path. Behavior is pinned by test-vectors/amounts.json; the TypeScript library mirrors every error code and check order exactly.
Index ¶
- Constants
- func BaseToDisplayUnits(base string) (string, error)
- func BaseToDisplayUnitsWithMax(base, maxBaseUnits string) (string, error)
- func CodeOf(err error) string
- func DisplayToBaseUnits(display string) (string, error)
- func DisplayToBaseUnitsWithMax(display, maxBaseUnits string) (string, error)
- type Error
Constants ¶
const ( // DisplayDecimals is the display exponent: 1 SOVR = 10^6 usovr. DisplayDecimals = 6 // DefaultMaxBaseUnits is the 1,000,000,000-SOVR hard cap in usovr. DefaultMaxBaseUnits = "1000000000000000" )
const ( CodeTooManyDecimals = "AMOUNT_TOO_MANY_DECIMALS" CodeNegative = "AMOUNT_NEGATIVE" CodeScientificNotation = "AMOUNT_SCIENTIFIC_NOTATION" CodeCommas = "AMOUNT_COMMAS" CodeEmpty = "AMOUNT_EMPTY" CodeNotNumeric = "AMOUNT_NOT_NUMERIC" CodeExceedsMax = "AMOUNT_EXCEEDS_MAX" )
FR-018 error codes. Stable API: exchanges branch on these strings.
Variables ¶
This section is empty.
Functions ¶
func BaseToDisplayUnits ¶
BaseToDisplayUnits converts base units ("10250000") to the canonical display amount ("10.25") under the default 1B-SOVR maximum. Output is round-trip exact: DisplayToBaseUnits(BaseToDisplayUnits(x)) == x.
func BaseToDisplayUnitsWithMax ¶
BaseToDisplayUnitsWithMax is BaseToDisplayUnits with a caller-configured maximum (inclusive) in base units.
func DisplayToBaseUnits ¶
DisplayToBaseUnits converts a display amount ("10.25") to base units ("10250000") under the default 1B-SOVR maximum.
func DisplayToBaseUnitsWithMax ¶
DisplayToBaseUnitsWithMax is DisplayToBaseUnits with a caller-configured maximum (inclusive), itself expressed in base units.