@hyperscale0/hsx 2.4.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/CHANGELOG.md +2 -408
  2. package/README.md +3 -92
  3. package/dist/src/ast.d.ts +99 -310
  4. package/dist/src/ast.d.ts.map +1 -1
  5. package/dist/src/ast.js +16 -69
  6. package/dist/src/ast.js.map +1 -1
  7. package/dist/src/cli.d.ts +6 -19
  8. package/dist/src/cli.d.ts.map +1 -1
  9. package/dist/src/cli.js +76 -315
  10. package/dist/src/cli.js.map +1 -1
  11. package/dist/src/compile.d.ts +23 -73
  12. package/dist/src/compile.d.ts.map +1 -1
  13. package/dist/src/compile.js +1113 -148
  14. package/dist/src/compile.js.map +1 -1
  15. package/dist/src/cost.d.ts +8 -77
  16. package/dist/src/cost.d.ts.map +1 -1
  17. package/dist/src/cost.js +13 -422
  18. package/dist/src/cost.js.map +1 -1
  19. package/dist/src/format.d.ts +8 -7
  20. package/dist/src/format.d.ts.map +1 -1
  21. package/dist/src/format.js +9 -175
  22. package/dist/src/format.js.map +1 -1
  23. package/dist/src/headers.d.ts +35 -0
  24. package/dist/src/headers.d.ts.map +1 -0
  25. package/dist/src/headers.js +108 -0
  26. package/dist/src/headers.js.map +1 -0
  27. package/dist/src/index.d.ts +6 -12
  28. package/dist/src/index.d.ts.map +1 -1
  29. package/dist/src/index.js +4 -9
  30. package/dist/src/index.js.map +1 -1
  31. package/dist/src/lex.d.ts +8 -28
  32. package/dist/src/lex.d.ts.map +1 -1
  33. package/dist/src/lex.js +88 -146
  34. package/dist/src/lex.js.map +1 -1
  35. package/dist/src/parse.d.ts +4 -17
  36. package/dist/src/parse.d.ts.map +1 -1
  37. package/dist/src/parse.js +402 -1040
  38. package/dist/src/parse.js.map +1 -1
  39. package/dist/src/std-bundle.d.ts.map +1 -1
  40. package/dist/src/std-bundle.js +12 -20
  41. package/dist/src/std-bundle.js.map +1 -1
  42. package/dist/src/std-library.d.ts +1 -1
  43. package/dist/src/std-library.d.ts.map +1 -1
  44. package/dist/src/std-library.js +1 -5
  45. package/dist/src/std-library.js.map +1 -1
  46. package/dist/src/tunables.d.ts +7 -0
  47. package/dist/src/tunables.d.ts.map +1 -0
  48. package/dist/src/tunables.js +26 -0
  49. package/dist/src/tunables.js.map +1 -0
  50. package/dist/src/version.d.ts +2 -4
  51. package/dist/src/version.d.ts.map +1 -1
  52. package/dist/src/version.js +2 -4
  53. package/dist/src/version.js.map +1 -1
  54. package/docs/README.md +179 -41
  55. package/docs/headers.md +44 -0
  56. package/examples/cost-table.json +99 -751
  57. package/examples/library.hsx +59 -0
  58. package/package.json +9 -17
  59. package/src/ast.ts +82 -441
  60. package/src/cli.ts +77 -362
  61. package/src/compile.ts +1535 -247
  62. package/src/cost.ts +28 -671
  63. package/src/format.ts +12 -256
  64. package/src/headers.ts +126 -0
  65. package/src/index.ts +7 -39
  66. package/src/lex.ts +99 -195
  67. package/src/parse.ts +403 -1209
  68. package/src/std-bundle.ts +12 -20
  69. package/src/std-library.ts +2 -7
  70. package/src/tunables.ts +31 -0
  71. package/src/version.ts +2 -5
  72. package/std/approvals.hsx +17 -0
  73. package/std/cards.hsx +63 -0
  74. package/std/collections.hsx +31 -0
  75. package/std/escrow.hsx +43 -0
  76. package/std/financing.hsx +372 -0
  77. package/std/insurance.hsx +59 -0
  78. package/std/lending.hsx +115 -0
  79. package/std/marketplace.hsx +24 -0
  80. package/std/money.hsx +195 -0
  81. package/std/savings.hsx +44 -0
  82. package/std/travel.hsx +98 -0
  83. package/std/wallet.hsx +41 -0
  84. package/dist/src/diagnostics.d.ts +0 -13
  85. package/dist/src/diagnostics.d.ts.map +0 -1
  86. package/dist/src/diagnostics.js +0 -587
  87. package/dist/src/diagnostics.js.map +0 -1
  88. package/dist/src/emit.d.ts +0 -51
  89. package/dist/src/emit.d.ts.map +0 -1
  90. package/dist/src/emit.js +0 -192
  91. package/dist/src/emit.js.map +0 -1
  92. package/dist/src/entry-overrides.d.ts +0 -58
  93. package/dist/src/entry-overrides.d.ts.map +0 -1
  94. package/dist/src/entry-overrides.js +0 -284
  95. package/dist/src/entry-overrides.js.map +0 -1
  96. package/dist/src/ir.d.ts +0 -73
  97. package/dist/src/ir.d.ts.map +0 -1
  98. package/dist/src/ir.js +0 -15
  99. package/dist/src/ir.js.map +0 -1
  100. package/dist/src/limits.d.ts +0 -23
  101. package/dist/src/limits.d.ts.map +0 -1
  102. package/dist/src/limits.js +0 -23
  103. package/dist/src/limits.js.map +0 -1
  104. package/dist/src/lsp/server.d.ts +0 -32
  105. package/dist/src/lsp/server.d.ts.map +0 -1
  106. package/dist/src/lsp/server.js +0 -391
  107. package/dist/src/lsp/server.js.map +0 -1
  108. package/dist/src/modules.d.ts +0 -38
  109. package/dist/src/modules.d.ts.map +0 -1
  110. package/dist/src/modules.js +0 -372
  111. package/dist/src/modules.js.map +0 -1
  112. package/dist/src/typecheck.d.ts +0 -8
  113. package/dist/src/typecheck.d.ts.map +0 -1
  114. package/dist/src/typecheck.js +0 -4160
  115. package/dist/src/typecheck.js.map +0 -1
  116. package/docs/guide/01-first-program.md +0 -24
  117. package/docs/guide/02-money.md +0 -25
  118. package/docs/guide/03-instruments.md +0 -93
  119. package/docs/guide/04-lifecycles.md +0 -40
  120. package/docs/guide/05-fees-and-splits.md +0 -45
  121. package/docs/guide/06-schedules.md +0 -26
  122. package/docs/guide/07-composition.md +0 -52
  123. package/docs/guide/08-writing-a-module.md +0 -85
  124. package/docs/guide/09-cost.md +0 -24
  125. package/docs/guide/10-diagnostics.md +0 -27
  126. package/docs/llms-full.txt +0 -3684
  127. package/docs/llms.txt +0 -44
  128. package/docs/piece-plans.md +0 -120
  129. package/docs/playground.md +0 -55
  130. package/docs/reference/cli.md +0 -36
  131. package/docs/reference/diagnostics.md +0 -901
  132. package/docs/reference/grammar.md +0 -38
  133. package/docs/reference/std/advance.md +0 -112
  134. package/docs/reference/std/cancellable_booking.md +0 -159
  135. package/docs/reference/std/captured_payment.md +0 -115
  136. package/docs/reference/std/conditional_disbursement.md +0 -101
  137. package/docs/reference/std/credit_facility.md +0 -108
  138. package/docs/reference/std/held_payment.md +0 -173
  139. package/docs/reference/std/instant_transfer.md +0 -97
  140. package/docs/reference/std/metered.md +0 -89
  141. package/docs/reference/std/pooled_split.md +0 -95
  142. package/docs/reference/std/premium_forward.md +0 -119
  143. package/docs/reference/std/reconciled_payout.md +0 -103
  144. package/docs/reference/std/rotating_pool.md +0 -130
  145. package/docs/reference/std/scheduled.md +0 -136
  146. package/docs/reference/std/security_deposit.md +0 -138
  147. package/docs/reference/std/settlement_batch.md +0 -123
  148. package/docs/reference/std/swap.md +0 -133
  149. package/docs/reference/std/threshold_pool.md +0 -138
  150. package/docs/reference/std/weighted_distribution.md +0 -135
  151. package/docs/reference/types.md +0 -61
  152. package/docs/reference/udl-output.md +0 -13
  153. package/examples/01-first-program/README.md +0 -45
  154. package/examples/01-first-program/tip-jar.hsx +0 -17
  155. package/examples/02-imports-and-modules/README.md +0 -96
  156. package/examples/02-imports-and-modules/photo-booth.hsx +0 -37
  157. package/examples/03-diagnostics/README.md +0 -68
  158. package/examples/03-diagnostics/corner-shop-fixed.hsx +0 -22
  159. package/examples/03-diagnostics/corner-shop.hsx +0 -19
  160. package/examples/04-complete-product/README.md +0 -84
  161. package/examples/04-complete-product/study-hall.hsx +0 -67
  162. package/examples/05-authored-instrument/README.md +0 -5
  163. package/examples/05-authored-instrument/payment.hsx +0 -37
  164. package/examples/05-watch-club/README.md +0 -6
  165. package/examples/05-watch-club/watch-club.hsx +0 -123
  166. package/examples/README.md +0 -48
  167. package/examples/advance/README.md +0 -3
  168. package/examples/advance/advance.hsx +0 -13
  169. package/examples/advance/advance.udl +0 -367
  170. package/examples/cancellable_booking/README.md +0 -3
  171. package/examples/cancellable_booking/cancellable_booking.hsx +0 -14
  172. package/examples/cancellable_booking/cancellable_booking.udl +0 -413
  173. package/examples/captured_payment/README.md +0 -3
  174. package/examples/captured_payment/captured_payment.hsx +0 -17
  175. package/examples/captured_payment/captured_payment.udl +0 -686
  176. package/examples/conditional_disbursement/README.md +0 -3
  177. package/examples/conditional_disbursement/conditional_disbursement.hsx +0 -15
  178. package/examples/conditional_disbursement/conditional_disbursement.udl +0 -418
  179. package/examples/credit_facility/README.md +0 -3
  180. package/examples/credit_facility/credit_facility.hsx +0 -24
  181. package/examples/credit_facility/credit_facility.udl +0 -1396
  182. package/examples/held_payment/README.md +0 -3
  183. package/examples/held_payment/held_payment.hsx +0 -13
  184. package/examples/held_payment/held_payment.udl +0 -569
  185. package/examples/instant_transfer/README.md +0 -3
  186. package/examples/instant_transfer/instant_transfer.hsx +0 -16
  187. package/examples/instant_transfer/instant_transfer.udl +0 -376
  188. package/examples/metered/README.md +0 -3
  189. package/examples/metered/metered.hsx +0 -13
  190. package/examples/metered/metered.udl +0 -253
  191. package/examples/pooled_split/README.md +0 -3
  192. package/examples/pooled_split/pooled_split.hsx +0 -15
  193. package/examples/pooled_split/pooled_split.udl +0 -432
  194. package/examples/premium_forward/README.md +0 -3
  195. package/examples/premium_forward/premium_forward.hsx +0 -19
  196. package/examples/premium_forward/premium_forward.udl +0 -604
  197. package/examples/reconciled_payout/README.md +0 -3
  198. package/examples/reconciled_payout/reconciled_payout.hsx +0 -13
  199. package/examples/reconciled_payout/reconciled_payout.udl +0 -312
  200. package/examples/rotating_pool/README.md +0 -3
  201. package/examples/rotating_pool/rotating_pool.hsx +0 -18
  202. package/examples/rotating_pool/rotating_pool.udl +0 -4370
  203. package/examples/scheduled/README.md +0 -3
  204. package/examples/scheduled/scheduled.hsx +0 -12
  205. package/examples/scheduled/scheduled.udl +0 -355
  206. package/examples/security_deposit/README.md +0 -3
  207. package/examples/security_deposit/security_deposit.hsx +0 -21
  208. package/examples/security_deposit/security_deposit.udl +0 -320
  209. package/examples/settlement_batch/README.md +0 -3
  210. package/examples/settlement_batch/settlement_batch.hsx +0 -19
  211. package/examples/settlement_batch/settlement_batch.udl +0 -757
  212. package/examples/swap/README.md +0 -3
  213. package/examples/swap/swap.hsx +0 -19
  214. package/examples/swap/swap.udl +0 -892
  215. package/examples/threshold_pool/README.md +0 -3
  216. package/examples/threshold_pool/threshold_pool.hsx +0 -16
  217. package/examples/threshold_pool/threshold_pool.udl +0 -680
  218. package/examples/weighted_distribution/README.md +0 -3
  219. package/examples/weighted_distribution/weighted_distribution.hsx +0 -20
  220. package/examples/weighted_distribution/weighted_distribution.udl +0 -348
  221. package/skills/hsx/SKILL.md +0 -449
  222. package/src/diagnostics.ts +0 -620
  223. package/src/emit.ts +0 -282
  224. package/src/entry-overrides.ts +0 -428
  225. package/src/ir.ts +0 -113
  226. package/src/limits.ts +0 -22
  227. package/src/lsp/server.ts +0 -460
  228. package/src/modules.ts +0 -452
  229. package/src/typecheck.ts +0 -5515
  230. package/std/SEMANTICS.md +0 -44
  231. package/std/money_flows/advance.hsx +0 -235
  232. package/std/money_flows/cancellable_booking.hsx +0 -402
  233. package/std/money_flows/captured_payment.hsx +0 -220
  234. package/std/money_flows/conditional_disbursement.hsx +0 -226
  235. package/std/money_flows/credit_facility.hsx +0 -214
  236. package/std/money_flows/held_payment.hsx +0 -812
  237. package/std/money_flows/index.hsx +0 -4
  238. package/std/money_flows/instant_transfer.hsx +0 -231
  239. package/std/money_flows/metered.hsx +0 -104
  240. package/std/money_flows/pooled_split.hsx +0 -109
  241. package/std/money_flows/premium_forward.hsx +0 -307
  242. package/std/money_flows/reconciled_payout.hsx +0 -119
  243. package/std/money_flows/rotating_pool.hsx +0 -305
  244. package/std/money_flows/scheduled.hsx +0 -599
  245. package/std/money_flows/security_deposit.hsx +0 -248
  246. package/std/money_flows/settlement_batch.hsx +0 -173
  247. package/std/money_flows/swap.hsx +0 -1192
  248. package/std/money_flows/threshold_pool.hsx +0 -307
  249. package/std/money_flows/weighted_distribution.hsx +0 -237
@@ -1,449 +0,0 @@
1
- ---
2
- name: hsx
3
- description: Write, review, and repair HSX programs that compile financial-product rules to canonical UDL.
4
- ---
5
-
6
- # Write HSX
7
-
8
- Use this skill when a task creates or changes an `.hsx` program, chooses a money flow from the money flows library (open/hsx/std), explains an HSX diagnostic, or reviews authored money rules. Do not use it to hand-edit canonical UDL or runtime state.
9
-
10
- ## Program shape
11
-
12
- One file declares one `program`. Declare parties and assets before using them. Import money flows from `std/money_flows`. Apply each selected instrument as a `settlement`, and declare every decision port it names. A program may also declare general instruments and subjects.
13
-
14
- Start with [the first-program guide](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/guide/01-first-program.md). Read the [instruments](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/guide/03-instruments.md), [lifecycles](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/guide/04-lifecycles.md), [composition](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/guide/07-composition.md), and [writing a module](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/guide/08-writing-a-module.md) chapters for instrument architecture. Read the generated [grammar](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/reference/grammar.md), [types](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/reference/types.md), and [money flows reference](https://github.com/hyperscale0/hyperscale-hsx/tree/main/docs/reference/std) for the exact surface.
15
-
16
- ## Choose a money flow
17
-
18
- Choose the module whose lifecycle and money path already match the product. Do not copy its emitted mechanics into a custom instrument.
19
-
20
- - `instant_transfer` sends money without custody.
21
- - `held_payment` holds money until a decision or deadline.
22
- - `security_deposit` reserves value for a bounded claim or return.
23
- - `cancellable_booking` quotes a cancellation penalty before commitment.
24
- - `captured_payment` reserves, captures, settles, voids, or corrects a payment.
25
- - `scheduled` expands finite installments or a bounded obligation.
26
- - `advance` disburses now against finite repayment or a referenced release.
27
- - `credit_facility` controls draws against a referenced obligation.
28
- - `conditional_disbursement` releases a capped amount on stored evidence.
29
- - `pooled_split`, `weighted_distribution`, and `rotating_pool` divide bounded pools.
30
- - `threshold_pool` closes a bounded contribution campaign.
31
- - `premium_forward` holds and forwards an insurance premium.
32
- - `reconciled_payout` matches an instructed payout against bank evidence.
33
- - `metered` commits a finite usage rate card for a period.
34
- - `settlement_batch` closes, calculates, approves, instructs, acknowledges, and reconciles a batch.
35
- - `swap` exchanges two independently typed sides.
36
-
37
- The money flows are demonstrated below. The marker before each program lets the repository test read the module list from disk and compile one matching example per module.
38
-
39
- ## Diagnostic loop
40
-
41
- Run `hsx check` after each coherent edit. Read the first error code, open the [diagnostics guide](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/guide/10-diagnostics.md) and [diagnostics reference](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/reference/diagnostics.md), apply the catalog fix, and compile again. Match tools on the stable `HSX####` code, not the message. Never patch emitted UDL to bypass a refusal.
42
-
43
- ## Money rules
44
-
45
- - Money uses integer minor units and carries a currency type.
46
- - Money in different currencies never unifies.
47
- - Percent literals have basis-point precision.
48
- - Every percentage partition totals 100 percent.
49
- - Every computed amount is consumed exactly once.
50
- - Every held balance drains on each reachable exit.
51
- - Schedules and comprehensions have compile-time finite bounds.
52
- - A port supplies typed evidence or a bounded decision. It cannot invent money or a new route.
53
-
54
- The [money](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/guide/02-money.md), [fees and splits](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/guide/05-fees-and-splits.md), [schedules](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/guide/06-schedules.md), and [cost](https://github.com/hyperscale0/hyperscale-hsx/blob/main/docs/guide/09-cost.md) chapters explain these rules.
55
-
56
- ## Money flow witnesses
57
-
58
- <!-- hsx-brick: advance -->
59
-
60
- ```hsx
61
- program advance_example "Advance example"
62
- import { advance } from "std/money_flows"
63
- party funder: business
64
- party recipient: business
65
- settlement advance_payment = advance {
66
- funder: funder
67
- to: recipient
68
- amount: principal: money(SAR)
69
- fee: 2.5%
70
- count: 2
71
- every: P30D
72
- first_due: firstDueAt
73
- }
74
- ```
75
-
76
- <!-- hsx-brick: cancellable_booking -->
77
-
78
- ```hsx
79
- program cancellable_booking_example "Cancellable booking example"
80
- import { cancellable_booking } from "std/money_flows"
81
- party guest: person
82
- party studio: business
83
- settlement studio_session = cancellable_booking {
84
- guest: guest
85
- host: studio
86
- amount: sessionPrice: money(SAR)
87
- starts_at: startsAt
88
- late_penalty_bps: 5000
89
- late_within: P2D
90
- early_penalty_bps: 1000
91
- offer_life: PT30M
92
- }
93
- ```
94
-
95
- <!-- hsx-brick: captured_payment -->
96
-
97
- ```hsx
98
- program captured_payment_example "Captured payment example"
99
- import { captured_payment } from "std/money_flows"
100
- party payer: person
101
- party payee: business
102
- settlement card_payment = captured_payment {
103
- payer: payer
104
- payee: payee
105
- amount: authorizedAmount: money(SAR)
106
- reserve_until: reserveUntil
107
- correction: port correct_capture
108
- external_reversal: port reverse_capture within P14D
109
- }
110
- port correct_capture { allowed: [payee] }
111
- port reverse_capture {
112
- allowed: [payee]
113
- shape: { externalReference: text }
114
- }
115
- ```
116
-
117
- <!-- hsx-brick: conditional_disbursement -->
118
-
119
- ```hsx
120
- program conditional_disbursement_example "Conditional disbursement example"
121
- import { conditional_disbursement } from "std/money_flows"
122
- party source: business
123
- party claimant: person
124
- settlement claim_payment = conditional_disbursement {
125
- source: source
126
- destination: claimant
127
- cap: policyLimit: money(SAR)
128
- amount: approvedAmount: money(SAR)
129
- decision: port approve_claim
130
- }
131
- port approve_claim {
132
- allowed: [source]
133
- shape: { evidenceReference: text }
134
- }
135
- ```
136
-
137
- <!-- hsx-brick: credit_facility -->
138
-
139
- ```hsx
140
- program credit_facility_example "Credit facility example"
141
- import { credit_facility, scheduled } from "std/money_flows"
142
- party lender: business
143
- party borrower: business
144
- party draw_destination: business
145
- party repayment_source: business
146
- settlement repayment = scheduled {
147
- mode: obligation
148
- payer: repayment_source
149
- payee: lender
150
- debtor: borrower
151
- amount: principal: money(SAR)
152
- count: 2
153
- every: P30D
154
- first_due: firstDueAt
155
- }
156
- settlement facility = credit_facility {
157
- lender: lender
158
- borrower: borrower
159
- draw_destination: draw_destination
160
- limit: facilityLimit: money(SAR)
161
- expires_at: expiresAt
162
- obligation: repayment.obligation
163
- }
164
- ```
165
-
166
- <!-- hsx-brick: security_deposit -->
167
-
168
- ```hsx
169
- program deposit_example "Deposit example"
170
- import { security_deposit } from "std/money_flows"
171
- party renter: person
172
- party owner: business
173
- settlement security_deposit = security_deposit {
174
- payer: renter
175
- holder: owner
176
- amount: depositAmount: money(SAR)
177
- claim: port assess_damage
178
- claim_amount: decided {
179
- field: damageAmount
180
- bound: depositAmount
181
- remainder: return
182
- }
183
- return: port return_deposit
184
- }
185
- port assess_damage {
186
- allowed: [owner]
187
- shape: { damageAmount: money(SAR), evidence: text }
188
- }
189
- port return_deposit { allowed: [owner] }
190
- ```
191
-
192
- <!-- hsx-brick: threshold_pool -->
193
-
194
- ```hsx
195
- program capital_pool_example "Capital pool example"
196
- import { threshold_pool } from "std/money_flows"
197
- party contributor: person
198
- party company: business
199
- settlement round = threshold_pool {
200
- contributor: contributor
201
- beneficiary: company
202
- target: targetAmount: money(SAR)
203
- commitment: commitmentAmount: money(SAR)
204
- max_contributors: 100
205
- close_by: closeBy
206
- close_policy: threshold
207
- overfund_policy: reject
208
- cancel_policy: before_close
209
- fail_policy: whole_commitment_refund
210
- }
211
- ```
212
-
213
- <!-- hsx-brick: held_payment -->
214
-
215
- ```hsx
216
- program held_payment_example "Held payment example"
217
- import { held_payment } from "std/money_flows"
218
- party buyer: person
219
- party seller: business
220
- settlement sale = held_payment {
221
- payer: buyer
222
- payee: seller
223
- amount: price: money(SAR)
224
- fees { buyer: 1% }
225
- on_cancel(funded) { buyer: 100% }
226
- release: port confirm_delivery | at(releaseDueAt)
227
- }
228
- port confirm_delivery { allowed: [buyer] }
229
- ```
230
-
231
- <!-- hsx-brick: instant_transfer -->
232
-
233
- ```hsx
234
- program instant_transfer_example "Instant transfer example"
235
- import { instant_transfer } from "std/money_flows"
236
- party customer: person
237
- party merchant: business
238
- settlement transfer = instant_transfer {
239
- payer: customer
240
- payee: merchant
241
- amount: transferAmount: money(SAR)
242
- fees {
243
- customer: checkoutFee: money(SAR)
244
- merchant {
245
- tier { from: 0, to: 10000, fee: 1% }
246
- tier { from: 10000, fee: highValueFee: money(SAR) }
247
- }
248
- }
249
- }
250
- ```
251
-
252
- <!-- hsx-brick: metered -->
253
-
254
- ```hsx
255
- program metered_example "Metered example"
256
- import { metered } from "std/money_flows"
257
- party customer: business
258
- party provider: business
259
- settlement usage = metered {
260
- payer: customer
261
- payee: provider
262
- close_by: periodEnd
263
- rates {
264
- api_call: callRate: money(SAR)
265
- storage_gib: storageRate: money(SAR)
266
- }
267
- }
268
- ```
269
-
270
- <!-- hsx-brick: pooled_split -->
271
-
272
- ```hsx
273
- program pooled_split_example "Pooled split example"
274
- import { pooled_split } from "std/money_flows"
275
- party payer: business
276
- party first_recipient: business
277
- party second_recipient: business
278
- settlement pool = pooled_split {
279
- payer: payer
280
- amount: poolAmount: money(SAR)
281
- payout_due: payoutDueAt
282
- split {
283
- first_recipient: 60%
284
- second_recipient: 40%
285
- remainder_to: first_recipient
286
- }
287
- }
288
- ```
289
-
290
- <!-- hsx-brick: premium_forward -->
291
-
292
- ```hsx
293
- program premium_forward_example "Premium forward example"
294
- import { premium_forward } from "std/money_flows"
295
- party policyholder: person
296
- party carrier: business
297
- settlement premium = premium_forward {
298
- payer: policyholder
299
- carrier: carrier
300
- amount: premiumAmount: money(SAR)
301
- commission: 2%
302
- bind: port bind_policy
303
- policy_ref: policyReference
304
- renewal_due: renewalDueAt
305
- endorsement: port record_endorsement
306
- }
307
- port bind_policy { allowed: [policyholder, carrier] }
308
- port record_endorsement {
309
- allowed: [carrier]
310
- shape: { evidenceReference: text }
311
- }
312
- ```
313
-
314
- <!-- hsx-brick: reconciled_payout -->
315
-
316
- ```hsx
317
- program reconciled_payout_example "Reconciled payout example"
318
- import { reconciled_payout } from "std/money_flows"
319
- party treasury: business
320
- party supplier: business
321
- settlement supplier_payout = reconciled_payout {
322
- payer: treasury
323
- beneficiary: supplier
324
- amount: netPayable: money(SAR)
325
- beneficiary_ref: supplierBeneficiaryId
326
- settle_by: settleBy
327
- matched_within: 100
328
- matched_ceiling: 500
329
- }
330
- ```
331
-
332
- <!-- hsx-brick: rotating_pool -->
333
-
334
- ```hsx
335
- program rotating_pool_example "Rotating pool example"
336
- import { rotating_pool } from "std/money_flows"
337
- party member_a: person
338
- party member_b: person
339
- party member_c: person
340
- party guarantor: business
341
- settlement pool = rotating_pool {
342
- members: [member_a, member_b, member_c]
343
- contribution: contributionAmount: money(SAR)
344
- count: 3
345
- every: P30D
346
- first_due: firstContributionAt
347
- payout_order: [member_b, member_c, member_a]
348
- default_policy: due_condition
349
- guarantee_policy: funded_only
350
- guarantor: guarantor
351
- exit_policy: before_activation_only
352
- }
353
- ```
354
-
355
- <!-- hsx-brick: scheduled -->
356
-
357
- ```hsx
358
- program scheduled_example "Scheduled example"
359
- import { scheduled } from "std/money_flows"
360
- party payer: business
361
- party payee: business
362
- settlement installments = scheduled {
363
- payer: payer
364
- payee: payee
365
- amount: totalAmount: money(SAR)
366
- count: 3
367
- every: P30D
368
- first_due: firstDueAt
369
- }
370
- ```
371
-
372
- <!-- hsx-brick: settlement_batch -->
373
-
374
- ```hsx
375
- program settlement_batch_example "Settlement batch example"
376
- import { settlement_batch } from "std/money_flows"
377
- party settlement_account: business
378
- party payout_destination: business
379
- settlement batch = settlement_batch {
380
- settlement_account: settlement_account
381
- source_capture_refs: captureReference
382
- fee_entries: feeReference
383
- external_reversal_offsets: reversalReference
384
- close_trigger: closeAt
385
- payout_destination: payout_destination
386
- negative_position: reject
387
- payout_acknowledgement: port acknowledge_payout
388
- payout_beneficiary_ref: payoutBeneficiaryId
389
- }
390
- port acknowledge_payout {
391
- allowed: [payout_destination]
392
- shape: { acknowledgementReference: text }
393
- }
394
- ```
395
-
396
- <!-- hsx-brick: swap -->
397
-
398
- ```hsx
399
- program swap_example "Swap example"
400
- import { swap } from "std/money_flows"
401
- party buyer: business
402
- party seller: business
403
- settlement exchange = swap {
404
- between: [buyer, seller]
405
- amounts {
406
- buyer: buyerAmount: money(SAR)
407
- seller: sellerAmount: money(SAR)
408
- }
409
- fees {
410
- buyer: buyerFee: money(SAR)
411
- seller: sellerFee: money(SAR)
412
- }
413
- release: port release_exchange
414
- dispute: port dispute_exchange within P7D
415
- }
416
- port release_exchange { allowed: [buyer, seller] }
417
- port dispute_exchange { allowed: [buyer, seller] }
418
- ```
419
-
420
- <!-- hsx-brick: weighted_distribution -->
421
-
422
- ```hsx
423
- program weighted_distribution_example "Weighted distribution example"
424
- import { weighted_distribution } from "std/money_flows"
425
- party distribution_source: business
426
- party recipient: business
427
- settlement proceeds = weighted_distribution {
428
- source: distribution_source
429
- recipient: recipient
430
- amount: distributableAmount: money(SAR)
431
- weight: entitlementWeight: money(SAR)
432
- max_recipients: 12
433
- record_at: recordAt
434
- snapshot: port snapshot_entitlements
435
- rounding_policy: largest_remainder
436
- withholding_policy: refuse
437
- correction_policy: new_distribution
438
- }
439
- port snapshot_entitlements {
440
- allowed: [distribution_source]
441
- shape: { evidenceReference: text }
442
- }
443
- ```
444
-
445
- ## Output boundary
446
-
447
- Use `compile` or the Hyperscale CLI to obtain canonical UDL, the origin map, and the cost manifest. The engine reads UDL and never HSX. When a task needs direct UDL work, use the UDL skill instead.
448
-
449
- Programs that `use` published instruments need the selected catalogue when checked outside the engine: `hsx check --strict --catalog catalog.udl company.hsx`. Obtain that canonical UDL from the catalogue publisher. The CLI does not fetch or choose a revision.