code wiki / (root) / nx_fx_lib.nx

nx_fx_lib.nx

buildroot/runtime/nx_fx_lib.nx

4663 B99 linesdepth 7pulls 12 transitivereach 1 importersview sourcekind librarytopic fx
docsdependenciesstructsconstsfunctions

about

nx_fx_lib.nx -- F984: EXACT MULTI-CURRENCY on the sovereign ledger. Every incumbent FX path loses fractions of a cent to rounding and buries it. The sovereign property here is that a conversion LOSES NO VALUE: the truncated remainder is RETURNED and accounted, never silently dropped, so a converted amount can be reconstructed EXACTLY. Money is neither created nor destroyed by crossing a currency boundary -- the same invariant the ledger enforces within one currency, extended across two. A rate is a RATIONAL num/den (integer, exact) -- never a float, because a float rate drifts and an auditor cannot reproduce it. A rate carries PROVENANCE (source + the pair it prices): a conversion can cite exactly which rate, from which source, produced its number. No provenance, no conversion is the honest posture, though the raw fx_convert is available for pure arithmetic. FAIL-CLOSED: a zero or negative denominator is REFUSED (return -1, remainder 0) -- a divide-by-zero rate is a data error, not a silent NaN. SCALE ENVELOPE (declared): fx_convert computes amount*num before dividing, so amount*num must fit i64 (~9.2e18). For cents and realistic rates this is billions of dollars of headroom; a 128-bit widening mul is the rung if a book ever needs trillions-of-minor-units single transactions. Declared, not hidden. DRY: composes nx_matter_lib (reg_put/reg_get/mt_field/canon_encode) for rate storage. license_tier: ORIGINAL LIB.

dependencies 1 imports · 1 importers

nx_matter_lib.nx nx_fx_lib.nx nx_fx_gate.nx

imports: nx_matter_lib.nx

imported by: nx_fx_gate.nx

structs

none

consts

23const FX_MAGIC_1024: i64 = 1024
25const FX_BAD_RATE: i64 = 0 - 1

functions

27func fx_atoi(s: *u8) -> i64
called by 1: fx_rate_get
43func fx_convert(amount: i64, rate_num: i64, rate_den: i64, rem: *i64) -> i64
52func fx_reconstruct(amount_b: i64, rem: i64, rate_num: i64, rate_den: i64) -> i64
called by 1: main
58func fx_rate_put(prefix: *u8, pair_id: *u8, rate_num: i64, rate_den: i64, source: *u8) -> i64
called by 1: main calls 3: mt_catncanon_encodereg_put
79func fx_rate_get(prefix: *u8, pair_id: *u8, num: *i64, den: *i64) -> i64
94func fx_convert_priced(prefix: *u8, pair_id: *u8, amount: i64, rem: *i64) -> i64
called by 1: main calls 2: fx_rate_getfx_convert