code wiki / _hdl_build / nx_landed_cost.nx

nx_landed_cost.nx

buildroot/runtime/_hdl_build/nx_landed_cost.nx

30264 B572 linesdepth 5pulls 6 transitivereach 6 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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 · 2 importers

nx_syscalls.nx nx_seg_store.nx nx_store_seed_lib.nx nx_landed_cost.nx nx_lcimport_test.nx nx_sourcing_path.nx

imports: nx_syscalls.nxnx_seg_store.nxnx_store_seed_lib.nx

imported by: nx_lcimport_test.nxnx_sourcing_path.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main lc_emit_catalog sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ lc_lit lc_corridors_all sys_mmap ↻ lc_load_regime sts_load sts_gen_note sts_pfxhash ss_max_segid ss_open_cached ssc_init ssc_sig_of ssc_streq ss_open ssc_retire_handle sts_mm sys_mmap ↻ sts_werr sys_exit ↻ ss_hget sys_mmap ↻ ss_len ss_hlocate ss_r32

structs

none

consts

30const LC_MAGIC_10000: i64 = 10000
31const LC_MAGIC_1000000: i64 = 1000000
32const LC_MAGIC_4096: i64 = 4096
33const LC_MAGIC_4000000: i64 = 4000000
34const LC_MAGIC_380000: i64 = 380000
35const LC_MAGIC_42000: i64 = 42000
36const LC_MAGIC_2000: i64 = 2000
37const LC_MAGIC_3500: i64 = 3500
38const LC_MAGIC_3800: i64 = 3800
39const LC_MAGIC_183500: i64 = 183500
40const LC_MAGIC_1400000: i64 = 1400000
41const LC_MAGIC_13856: i64 = 13856
42const LC_MAGIC_3464: i64 = 3464
43const LC_MAGIC_5000: i64 = 5000
44const LC_MAGIC_1418856: i64 = 1418856
45const LC_MAGIC_6024356: i64 = 6024356
46const LC_MAGIC_148000: i64 = 148000
47const LC_MAGIC_166856: i64 = 166856
49const LC_MPF_PPM: i64 = 3464 // 0.3464%
50const LC_MPF_MIN_C: i64 = 3358 // $33.58
51const LC_MPF_MAX_C: i64 = 65150 // $651.50
52const LC_HMF_PPM: i64 = 1250 // 0.125% (ocean only)
53const LC_S122_BPS: i64 = 1000 // 10%
54const LC_CARDBUF: i64 = 2048 // corridor-card JSON buffer
55const LC_REGBUF: i64 = 65536 // seg-store regime plane load buffer
56const LC_NOTEBUF: i64 = 2048 // corridor note field buffer
57const LC_MAXC: i64 = 64 // max corridors ranked in one call

functions

59func 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 }
called by 2: lc_selftestmain calls 1: sys_write
60func lc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
62func lc_eq(a: *u8, b: *u8) -> i64
70func lc_atoi(s: *u8) -> i64
84func 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 }
85func lc_num(out: *u8, o: i64, v: i64) -> i64
104func lc_field0_eq(buf: *u8, n: i64, rs: i64, cc: *u8) -> i64
called by 1: lc_field
117func lc_extract(buf: *u8, n: i64, rs: i64, idx: i64, out: *u8, outcap: i64) -> i64
138func lc_field(buf: *u8, n: i64, cc: *u8, idx: i64, out: *u8, outcap: i64) -> i64
154func lc_load_regime(rbuf: *u8) -> i64 { return sts_load("knowledge/store/corridor-" as *u8, rbuf, LC_REGBUF) }
155func lc_is_col2(rbuf: *u8, rn: i64, cc: *u8) -> i64
162func lc_exim_closed(rbuf: *u8, rn: i64, cc: *u8) -> i64
173func lc_is_domestic(rbuf: *u8, rn: i64, cc: *u8) -> i64
182func lc_pref_ok(rbuf: *u8, rn: i64, cc: *u8, col2f: i64) -> i64
193func lc_s301_applies(rbuf: *u8, rn: i64, cc: *u8) -> i64
201func 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
287func lc_selftest() -> i64
called by 1: main calls 5: sys_mmaplc_calclc_litlc_numlw
348func lc_eq3(cc: *u8, a: *u8, b: *u8, c: *u8) -> i64
called by 1: lc_corridor calls 1: lc_eq
354func lc_corridor(out: *u8, cc: *u8) -> i64
399func lc_corridors_all(out: *u8) -> i64
433func 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
500func lc_emit_catalog(outpath: *u8) -> i64
523func main(argc: i64, argv: *i64) -> i64