code wiki / _hdl_build / nx_landed_cost.nx
nx_landed_cost.nx
buildroot/runtime/_hdl_build/nx_landed_cost.nx
about
nx_landed_cost.nx -- SOVEREIGN LANDED-COST ENGINE for the import/export corridor program.
The API/MCP/agentic tier of the /trade.html calculator (operator: "an emitting calculator for
these import exports ... we want to do it with russia and lots of other countries ... it needs
to scale"). The HTML page prices ONE shipment for a human; THIS organ prices ANY shipment for
an AGENT or WORKFLOW -- one tools/call returns the full 2026 US duty stack as structured JSON,
so a workflow can fan out over a whole supplier catalog x many corridors and rank by margin.
INTEGER-EXACT, NO FLOAT (sovereign law): money in CENTS, duty rates in BASIS POINTS (1% = 100bps),
fees in PPM, margins in PERMIL. Every figure is a pure integer transform of the inputs -- no
rounding drift, reproducible, gate-checkable against hand arithmetic.
REGIME LAYER (the researched, stable part -- 2026-07, verify before a real transaction):
* PNTR/NTR status picks Column 1 vs Column 2. Belarus + Russia = PNTR SUSPENDED = Column 2
(punitive) + they are the only col2 corridors here. All others = Column 1.
* EXIM Country Limitation Schedule: CLOSED for Belarus + Russia; open elsewhere.
* Section 122 (the 10% global surcharge) EXPIRED 2026-07-24 by operation of law -> default OFF;
pass s122=1 only to model a replacement surcharge. Section 232/301 are product-specific inputs.
The PRODUCT duty rates (col1/col2/232/301 bps) are INPUTS -- they are HTS-line-specific and must
come from a licensed broker; the organ supplies the regime logic + fee math around them.
VERBS:
nx_landed_cost calc <cc> <fob_c> <freight_c> <ins_c> <units> <col1bps> <col2bps> <s232bps>
<s301bps> <unitprice_c> <ocean01> <s122_01> <pref01> <other_c> -> JSON
nx_landed_cost selftest -> known-value gate (Belarus + Central-Asia reference shipments) -> VERDICT
license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_seg_store.nxnx_store_seed_lib.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 30 | const LC_MAGIC_10000: i64 = 10000 |
| 31 | const LC_MAGIC_1000000: i64 = 1000000 |
| 32 | const LC_MAGIC_4096: i64 = 4096 |
| 33 | const LC_MAGIC_4000000: i64 = 4000000 |
| 34 | const LC_MAGIC_380000: i64 = 380000 |
| 35 | const LC_MAGIC_42000: i64 = 42000 |
| 36 | const LC_MAGIC_2000: i64 = 2000 |
| 37 | const LC_MAGIC_3500: i64 = 3500 |
| 38 | const LC_MAGIC_3800: i64 = 3800 |
| 39 | const LC_MAGIC_183500: i64 = 183500 |
| 40 | const LC_MAGIC_1400000: i64 = 1400000 |
| 41 | const LC_MAGIC_13856: i64 = 13856 |
| 42 | const LC_MAGIC_3464: i64 = 3464 |
| 43 | const LC_MAGIC_5000: i64 = 5000 |
| 44 | const LC_MAGIC_1418856: i64 = 1418856 |
| 45 | const LC_MAGIC_6024356: i64 = 6024356 |
| 46 | const LC_MAGIC_148000: i64 = 148000 |
| 47 | const LC_MAGIC_166856: i64 = 166856 |
| 49 | const LC_MPF_PPM: i64 = 3464 // 0.3464% |
| 50 | const LC_MPF_MIN_C: i64 = 3358 // $33.58 |
| 51 | const LC_MPF_MAX_C: i64 = 65150 // $651.50 |
| 52 | const LC_HMF_PPM: i64 = 1250 // 0.125% (ocean only) |
| 53 | const LC_S122_BPS: i64 = 1000 // 10% |
| 54 | const LC_CARDBUF: i64 = 2048 // corridor-card JSON buffer |
| 55 | const LC_REGBUF: i64 = 65536 // seg-store regime plane load buffer |
| 56 | const LC_NOTEBUF: i64 = 2048 // corridor note field buffer |
| 57 | const LC_MAXC: i64 = 64 // max corridors ranked in one call |
functions
| 59 | func lw(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } |
| 60 | func lc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 62 | func lc_eq(a: *u8, b: *u8) -> i64 |
| 70 | func lc_atoi(s: *u8) -> i64 |
| 84 | func lc_lit(out: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { out[o + i] = s[i]; i = i + 1 } return o + i } |
| 85 | func lc_num(out: *u8, o: i64, v: i64) -> i64 |
| 104 | func lc_field0_eq(buf: *u8, n: i64, rs: i64, cc: *u8) -> i64 called by 1: lc_field |
| 117 | func lc_extract(buf: *u8, n: i64, rs: i64, idx: i64, out: *u8, outcap: i64) -> i64 |
| 138 | func lc_field(buf: *u8, n: i64, cc: *u8, idx: i64, out: *u8, outcap: i64) -> i64 |
| 154 | func lc_load_regime(rbuf: *u8) -> i64 { return sts_load("knowledge/store/corridor-" as *u8, rbuf, LC_REGBUF) } |
| 155 | func lc_is_col2(rbuf: *u8, rn: i64, cc: *u8) -> i64 |
| 162 | func lc_exim_closed(rbuf: *u8, rn: i64, cc: *u8) -> i64 |
| 171 | func lc_calc(out: *u8, cc: *u8, fob: i64, freight: i64, ins: i64, units: i64, col1: i64, col2: i64, s232: i64, s301: i64, price: i64, ocean: i64, s122: i64, pref: i64, other: i64, k: *i64) -> i64 called by 3: lc_selftestlc_rankmain calls 6: sys_mmaplc_load_regimelc_is_col2lc_litlc_numlc_exim_closed |
| 248 | func lc_selftest() -> i64 |
| 286 | func lc_eq3(cc: *u8, a: *u8, b: *u8, c: *u8) -> i64 |
| 292 | func lc_corridor(out: *u8, cc: *u8) -> i64 |
| 337 | func lc_corridors_all(out: *u8) -> i64 |
| 371 | func lc_rank(out: *u8, fob: i64, freight: i64, ins: i64, units: i64, col1: i64, col2: i64, s232: i64, s301: i64, price: i64, ocean: i64, s122: i64, pref: i64, other: i64) -> i64 |
| 438 | func lc_emit_catalog(outpath: *u8) -> i64 |
| 461 | func main(argc: i64, argv: *i64) -> i64 |