@hyperscale0/hsx 2.1.0 → 2.2.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 (110) hide show
  1. package/CHANGELOG.md +36 -7
  2. package/dist/src/cli.d.ts +1 -1
  3. package/dist/src/cli.d.ts.map +1 -1
  4. package/dist/src/cli.js +39 -5
  5. package/dist/src/cli.js.map +1 -1
  6. package/dist/src/compile.d.ts +0 -1
  7. package/dist/src/compile.d.ts.map +1 -1
  8. package/dist/src/compile.js +15 -1
  9. package/dist/src/compile.js.map +1 -1
  10. package/dist/src/cost.d.ts +3 -3
  11. package/dist/src/cost.d.ts.map +1 -1
  12. package/dist/src/cost.js +22 -12
  13. package/dist/src/cost.js.map +1 -1
  14. package/dist/src/parse.d.ts.map +1 -1
  15. package/dist/src/parse.js +10 -14
  16. package/dist/src/parse.js.map +1 -1
  17. package/dist/src/std-bundle.d.ts.map +1 -1
  18. package/dist/src/std-bundle.js +20 -84
  19. package/dist/src/std-bundle.js.map +1 -1
  20. package/dist/src/typecheck.d.ts.map +1 -1
  21. package/dist/src/typecheck.js +171 -39
  22. package/dist/src/typecheck.js.map +1 -1
  23. package/dist/src/version.d.ts +1 -1
  24. package/dist/src/version.js +1 -1
  25. package/docs/README.md +8 -2
  26. package/docs/guide/01-first-program.md +1 -1
  27. package/docs/guide/06-schedules.md +5 -1
  28. package/docs/guide/08-writing-a-module.md +48 -0
  29. package/docs/llms-full.txt +1928 -421
  30. package/docs/llms.txt +2 -3
  31. package/docs/piece-plans.md +120 -0
  32. package/docs/reference/cli.md +6 -5
  33. package/docs/reference/diagnostics.md +9 -9
  34. package/docs/reference/grammar.md +2 -3
  35. package/docs/reference/std/advance.md +94 -17
  36. package/docs/reference/std/cancellable_booking.md +138 -17
  37. package/docs/reference/std/captured_payment.md +96 -24
  38. package/docs/reference/std/conditional_disbursement.md +82 -14
  39. package/docs/reference/std/credit_facility.md +89 -16
  40. package/docs/reference/std/held_payment.md +155 -55
  41. package/docs/reference/std/instant_transfer.md +79 -12
  42. package/docs/reference/std/metered.md +71 -9
  43. package/docs/reference/std/pooled_split.md +76 -7
  44. package/docs/reference/std/premium_forward.md +100 -20
  45. package/docs/reference/std/reconciled_payout.md +84 -14
  46. package/docs/reference/std/rotating_pool.md +112 -24
  47. package/docs/reference/std/scheduled.md +117 -32
  48. package/docs/reference/std/security_deposit.md +119 -27
  49. package/docs/reference/std/settlement_batch.md +105 -24
  50. package/docs/reference/std/swap.md +113 -26
  51. package/docs/reference/std/threshold_pool.md +120 -29
  52. package/docs/reference/std/weighted_distribution.md +117 -21
  53. package/docs/reference/types.md +15 -15
  54. package/docs/reference/udl-output.md +6 -6
  55. package/examples/01-first-program/README.md +1 -1
  56. package/examples/{02-imports-and-archetypes → 02-imports-and-modules}/README.md +1 -1
  57. package/examples/{02-imports-and-archetypes → 02-imports-and-modules}/photo-booth.hsx +1 -1
  58. package/examples/04-complete-product/README.md +1 -1
  59. package/examples/05-authored-instrument/README.md +5 -0
  60. package/examples/05-authored-instrument/payment.hsx +37 -0
  61. package/examples/05-watch-club/watch-club.hsx +0 -1
  62. package/examples/README.md +1 -2
  63. package/examples/advance/advance.udl +29 -6
  64. package/examples/cancellable_booking/cancellable_booking.udl +19 -0
  65. package/examples/captured_payment/captured_payment.hsx +0 -4
  66. package/examples/captured_payment/captured_payment.udl +6 -0
  67. package/examples/conditional_disbursement/conditional_disbursement.hsx +0 -2
  68. package/examples/conditional_disbursement/conditional_disbursement.udl +4 -0
  69. package/examples/cost-table.json +136 -8
  70. package/examples/credit_facility/credit_facility.hsx +0 -3
  71. package/examples/credit_facility/credit_facility.udl +17 -1
  72. package/examples/held_payment/held_payment.udl +16 -0
  73. package/examples/instant_transfer/instant_transfer.udl +6 -0
  74. package/examples/metered/metered.udl +5 -1
  75. package/examples/pooled_split/pooled_split.udl +4 -0
  76. package/examples/premium_forward/premium_forward.udl +4 -0
  77. package/examples/reconciled_payout/reconciled_payout.udl +7 -0
  78. package/examples/rotating_pool/rotating_pool.udl +8 -0
  79. package/examples/scheduled/scheduled.udl +18 -3
  80. package/examples/security_deposit/security_deposit.udl +13 -0
  81. package/examples/settlement_batch/settlement_batch.udl +4 -0
  82. package/examples/swap/swap.udl +10 -0
  83. package/examples/threshold_pool/threshold_pool.udl +11 -0
  84. package/examples/weighted_distribution/weighted_distribution.udl +9 -0
  85. package/package.json +10 -10
  86. package/skills/hsx/SKILL.md +2 -36
  87. package/src/cli.ts +41 -5
  88. package/src/compile.ts +14 -6
  89. package/src/cost.ts +13 -16
  90. package/src/parse.ts +15 -10
  91. package/src/std-bundle.ts +21 -88
  92. package/src/typecheck.ts +207 -34
  93. package/src/version.ts +1 -1
  94. package/std/SEMANTICS.md +33 -128
  95. package/std/money_flows/advance.hsx +39 -26
  96. package/std/money_flows/cancellable_booking.hsx +275 -8
  97. package/std/money_flows/captured_payment.hsx +1 -9
  98. package/std/money_flows/conditional_disbursement.hsx +0 -6
  99. package/std/money_flows/credit_facility.hsx +0 -9
  100. package/std/money_flows/held_payment.hsx +39 -1
  101. package/std/money_flows/index.hsx +2 -1
  102. package/std/money_flows/metered.hsx +1 -5
  103. package/std/money_flows/scheduled.hsx +29 -119
  104. package/std/money_flows/threshold_pool.hsx +40 -5
  105. package/std/money_flows/weighted_distribution.hsx +47 -5
  106. package/docs/reference/std/recurring_collection.md +0 -25
  107. package/examples/recurring_collection/README.md +0 -3
  108. package/examples/recurring_collection/recurring_collection.hsx +0 -21
  109. package/examples/recurring_collection/recurring_collection.udl +0 -1135
  110. package/std/money_flows/recurring_collection.hsx +0 -72
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.0. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # swap
4
4
 
@@ -10,16 +10,103 @@ Source: [`std/money_flows/swap.hsx`](../../../std/money_flows/swap.hsx)
10
10
 
11
11
  ## Parameters
12
12
 
13
- - `between: list<party>`
14
- - `amounts: block`
15
- - `fees: block`
16
- - `release: condition`
17
- - `dispute: condition`
18
- - `side_names: optional<block>`
19
- - `lifecycle_state_order: optional<list<text>>`
20
- - `action_bindings: optional<block>`
21
- - `parked_states: optional<block>`
22
- - `fixed_prefix: optional<text>`
13
+ | Parameter | Type | Required | Meaning |
14
+ | --- | --- | --- | --- |
15
+ | `between` | `list<party>` | Yes | List containing exactly two trade participant parties (`[side_a, side_b]`). |
16
+ | `amounts` | `block` | Yes | Block declaring the principal money amounts for each party. |
17
+ | `fees` | `block` | Yes | Block declaring the platform fee money amounts for each party. |
18
+ | `release` | `condition` | Yes | Condition port required to execute the atomic swap release. |
19
+ | `dispute` | `condition` | Yes | Condition port triggering unwinding and refunding of both trade legs. |
20
+ | `side_names` | `optional<block>` | No | Optional custom naming block for the two sides (`first`, `second`). |
21
+ | `lifecycle_state_order` | `optional<list<text>>` | No | Optional custom ordering for lifecycle states. |
22
+ | `action_bindings` | `optional<block>` | No | Optional custom action names. |
23
+ | `parked_states` | `optional<block>` | No | Optional configuration for parked states. |
24
+ | `fixed_prefix` | `optional<text>` | No | Optional custom prefix for generated instrument IDs. |
25
+
26
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
27
+
28
+ ## Module guidance
29
+
30
+ Atomic two-sided trade between two parties where neither leg settles alone.
31
+
32
+ ### Purpose
33
+
34
+ `swap` executes atomic delivery-versus-payment (DvP) or payment-versus-payment (PvP) exchanges between two named parties.
35
+ Both sides fund their declared principal amounts and platform fees into a shared escrow. The exchange settles atomically
36
+ upon triggering the `release` condition port, paying each party the other's funded amount. If a `dispute` occurs,
37
+ both legs unwind and refund simultaneously. Half-funded or half-released states cannot occur.
38
+
39
+ ### Selection guidance
40
+
41
+ - vs `held_payment`: `swap` is a bilateral trade where both sides must deposit funds into escrow and receive each other's
42
+ disbursements simultaneously. `held_payment` is unilateral escrow where a single payer funds a payment held for a payee.
43
+ - vs `instant_transfer`: `instant_transfer` executes an immediate one-way transfer. `swap` coordinates two reciprocal transfers
44
+ held atomically in escrow until release confirmation.
45
+
46
+ ### Parameters
47
+
48
+ - `between`: List containing exactly two trade participant parties (`[side_a, side_b]`).
49
+ - `amounts`: Block declaring the principal money amounts for each party.
50
+ - `fees`: Block declaring the platform fee money amounts for each party.
51
+ - `release`: Condition port required to execute the atomic swap release.
52
+ - `dispute`: Condition port triggering unwinding and refunding of both trade legs.
53
+ - `side_names`: Optional custom naming block for the two sides (`first`, `second`).
54
+ - `lifecycle_state_order`: Optional custom ordering for lifecycle states.
55
+ - `action_bindings`: Optional custom action names.
56
+ - `parked_states`: Optional configuration for parked states.
57
+ - `fixed_prefix`: Optional custom prefix for generated instrument IDs.
58
+
59
+ ### Decision ports
60
+
61
+ - `release`: Port authorizing atomic settlement of both trade legs.
62
+ - `dispute`: Port triggering atomic cancellation and refund of both parties.
63
+
64
+ ### Example
65
+
66
+ ```hsx
67
+ program swap_example "Swap example"
68
+ import { swap } from "std/money_flows"
69
+ party buyer: business
70
+ party seller: business
71
+ settlement exchange = swap {
72
+ between: [buyer, seller]
73
+ amounts {
74
+ buyer: buyerAmount: money(SAR)
75
+ seller: sellerAmount: money(SAR)
76
+ }
77
+ fees {
78
+ buyer: buyerFee: money(SAR)
79
+ seller: sellerFee: money(SAR)
80
+ }
81
+ release: port release_exchange
82
+ dispute: port dispute_exchange within P7D
83
+ }
84
+ port release_exchange { allowed: [buyer, seller] }
85
+ port dispute_exchange { allowed: [buyer, seller] }
86
+ ```
87
+
88
+ ## Declared clauses
89
+
90
+ - `agent description`
91
+ - `caller parked states`
92
+ - `capture input`
93
+ - `deadline`
94
+ - `description`
95
+ - `distinct parties`
96
+ - `due`
97
+ - `event name`
98
+ - `id prefix`
99
+ - `input`
100
+ - `moves`
101
+ - `port`
102
+ - `public action`
103
+ - `sandbox failure point`
104
+ - `sets at`
105
+ - `steps`
106
+ - `summary`
107
+ - `title`
108
+
109
+ This inventory covers all branches and nested instruments in the module. The selected parameters determine which clauses and actions the compiler emits. Indexed action names expand over the declared finite list.
23
110
 
24
111
  ## Decision ports
25
112
 
@@ -28,19 +115,19 @@ Source: [`std/money_flows/swap.hsx`](../../../std/money_flows/swap.hsx)
28
115
 
29
116
  ## Actions and clauses
30
117
 
31
- | Action | Clauses lowered |
32
- | --------- | ----------------------------------------------------------------------------------------------------------------------------- |
33
- | `abandon` | `agent description`, `moves`, `public action`, `steps`, `summary` |
34
- | `cancel` | `agent description`, `moves`, `public action`, `steps`, `summary` |
35
- | `create` | `agent description`, `moves`, `public action`, `steps`, `summary` |
36
- | `dispute` | `agent description`, `capture input`, `deadline`, `input`, `moves`, `port`, `public action`, `steps`, `summary` |
37
- | `fund` | `agent description`, `moves`, `public action`, `sandbox failure point`, `steps`, `summary` |
38
- | `post` | `due`, `moves`, `steps`, `summary` |
39
- | `release` | `agent description`, `moves`, `port`, `public action`, `sandbox failure point`, `sets at`, `steps`, `summary` |
40
- | `create` | `agent description`, `moves`, `public action`, `steps`, `summary` |
41
- | `fund` | `agent description`, `event name`, `moves`, `public action`, `sandbox failure point`, `steps`, `summary` |
42
- | `release` | `agent description`, `event name`, `moves`, `port`, `public action`, `sandbox failure point`, `sets at`, `steps`, `summary` |
43
- | `post` | `due`, `event name`, `moves`, `steps`, `summary` |
118
+ | Action | Clauses lowered |
119
+ | --- | --- |
120
+ | `abandon` | `agent description`, `moves`, `public action`, `steps`, `summary` |
121
+ | `cancel` | `agent description`, `moves`, `public action`, `steps`, `summary` |
122
+ | `create` | `agent description`, `moves`, `public action`, `steps`, `summary` |
123
+ | `dispute` | `agent description`, `capture input`, `deadline`, `input`, `moves`, `port`, `public action`, `steps`, `summary` |
124
+ | `fund` | `agent description`, `moves`, `public action`, `sandbox failure point`, `steps`, `summary` |
125
+ | `post` | `due`, `moves`, `steps`, `summary` |
126
+ | `release` | `agent description`, `moves`, `port`, `public action`, `sandbox failure point`, `sets at`, `steps`, `summary` |
127
+ | `create` | `agent description`, `moves`, `public action`, `steps`, `summary` |
128
+ | `fund` | `agent description`, `event name`, `moves`, `public action`, `sandbox failure point`, `steps`, `summary` |
129
+ | `release` | `agent description`, `event name`, `moves`, `port`, `public action`, `sandbox failure point`, `sets at`, `steps`, `summary` |
130
+ | `post` | `due`, `event name`, `moves`, `steps`, `summary` |
44
131
  | `dispute` | `agent description`, `capture input`, `deadline`, `event name`, `input`, `moves`, `port`, `public action`, `steps`, `summary` |
45
- | `cancel` | `agent description`, `event name`, `moves`, `public action`, `steps`, `summary` |
46
- | `abandon` | `agent description`, `event name`, `moves`, `public action`, `steps`, `summary` |
132
+ | `cancel` | `agent description`, `event name`, `moves`, `public action`, `steps`, `summary` |
133
+ | `abandon` | `agent description`, `event name`, `moves`, `public action`, `steps`, `summary` |
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.0. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # threshold_pool
4
4
 
@@ -10,20 +10,111 @@ Source: [`std/money_flows/threshold_pool.hsx`](../../../std/money_flows/threshol
10
10
 
11
11
  ## Parameters
12
12
 
13
- - `contributor: optional<party>`
14
- - `beneficiary: optional<party>`
15
- - `target: money<C>`
16
- - `commitment: money<C>`
17
- - `max_contributors: optional<integer>`
18
- - `close_by: date`
19
- - `close_policy: optional<text>`
20
- - `overfund_policy: optional<text>`
21
- - `cancel_policy: optional<text>`
22
- - `fail_policy: optional<text>`
23
- - `beneficiary_account: optional<account<C>>`
24
- - `memo: optional<text>`
25
- - `contribution_instrument: optional<block>`
26
- - `wording: optional<block>`
13
+ | Parameter | Type | Required | Meaning |
14
+ | --- | --- | --- | --- |
15
+ | `contributor` | `optional<party>` | No | The party representing individual contributors. |
16
+ | `beneficiary` | `optional<party>` | No | The beneficiary party receiving the settled pool if the target is met. |
17
+ | `target` | `money<C>` | Yes | Total target funding threshold in minor units of currency `C`. |
18
+ | `commitment` | `money<C>` | Yes | Binding name for individual contributor commitment amounts. |
19
+ | `max_contributors` | `optional<integer>` | No | Optional maximum count of admitted contributors. |
20
+ | `close_by` | `date` | Yes | Stored date deadline by which the target must be met. |
21
+ | `close_policy` | `optional<text>` | No | Policy determining pool close behavior (`threshold`). |
22
+ | `overfund_policy` | `optional<text>` | No | Policy on commitments exceeding the target (`reject`). |
23
+ | `cancel_policy` | `optional<text>` | No | Contributor withdrawal policy before close (`before_close`). |
24
+ | `fail_policy` | `optional<text>` | No | Refund policy if the pool fails to hit target (`whole_commitment_refund`). |
25
+ | `beneficiary_account` | `optional<account<C>>` | No | Optional direct account reference for the beneficiary. |
26
+ | `memo` | `optional<text>` | No | Optional memo text stored on the pool. |
27
+ | `contribution_instrument` | `optional<block>` | No | Optional custom contribution child instrument block. |
28
+ | `wording` | `optional<block>` | No | Optional custom UI wording block. |
29
+ | `funding_join` | `optional<block>` | No | funding_join configures the flat contribution-instrument mode for a priced obligation. |
30
+
31
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
32
+
33
+ ## Module guidance
34
+
35
+ All-or-nothing capital accumulation pool collecting commitments toward a target amount before a close deadline.
36
+
37
+ ### Purpose
38
+
39
+ `threshold_pool` powers all-or-nothing crowdfunding, capital calls, collective purchasing, and consortium rounds.
40
+ Multiple contributors pledge commitments toward a monetary `target`. Commitments sit in escrow until the pool
41
+ reaches the target before `close_by` (activating and settling funds to the beneficiary), or fails (triggering full refunds).
42
+
43
+ ### Selection guidance
44
+
45
+ - vs `rotating_pool`: `threshold_pool` is all-or-nothing fundraising where many contributors fund a single beneficiary.
46
+ `rotating_pool` is a peer savings circle where members contribute identically in each cycle and rotate who receives the pot.
47
+ - vs `weighted_distribution`: `threshold_pool` pools funds inward from many contributors to one beneficiary.
48
+ `weighted_distribution` pays funds outward from one source pool to many weighted recipients.
49
+
50
+ ### Parameters
51
+
52
+ - `contributor`: The party representing individual contributors.
53
+ - `beneficiary`: The beneficiary party receiving the settled pool if the target is met.
54
+ - `target`: Total target funding threshold in minor units of currency `C`.
55
+ - `commitment`: Binding name for individual contributor commitment amounts.
56
+ - `max_contributors`: Optional maximum count of admitted contributors.
57
+ - `close_by`: Stored date deadline by which the target must be met.
58
+ - `close_policy`: Policy determining pool close behavior (`threshold`).
59
+ - `overfund_policy`: Policy on commitments exceeding the target (`reject`).
60
+ - `cancel_policy`: Contributor withdrawal policy before close (`before_close`).
61
+ - `fail_policy`: Refund policy if the pool fails to hit target (`whole_commitment_refund`).
62
+ - `beneficiary_account`: Optional direct account reference for the beneficiary.
63
+ - `memo`: Optional memo text stored on the pool.
64
+ - `contribution_instrument`: Optional custom contribution child instrument block.
65
+ - `wording`: Optional custom UI wording block.
66
+
67
+ ### Decision ports
68
+
69
+ None. Lifecycle transitions (`activate`, `fail`, `close`) are driven by target threshold evaluation and the `close_by` date.
70
+
71
+ ### Example
72
+
73
+ ```hsx
74
+ program capital_pool_example "Capital pool example"
75
+ import { threshold_pool } from "std/money_flows"
76
+ party contributor: person
77
+ party company: business
78
+ settlement round = threshold_pool {
79
+ contributor: contributor
80
+ beneficiary: company
81
+ target: targetAmount: money(SAR)
82
+ commitment: commitmentAmount: money(SAR)
83
+ max_contributors: 100
84
+ close_by: closeBy
85
+ close_policy: threshold
86
+ overfund_policy: reject
87
+ cancel_policy: before_close
88
+ fail_policy: whole_commitment_refund
89
+ }
90
+ ```
91
+
92
+ ### Funding join
93
+
94
+ funding_join configures the flat contribution-instrument mode for a priced
95
+ obligation. Opening freezes minimum ticket, investor cap, profit and schedule
96
+ terms. Closing binds the obligation, freezes committed ticket identities and
97
+ moves the principal once into its funding account. A ticket's engine-owned
98
+ collection action has no independent payment or clock trigger.
99
+
100
+ ## Declared clauses
101
+
102
+ - `agent description`
103
+ - `aggregate invariants`
104
+ - `caller parked states`
105
+ - `description`
106
+ - `due`
107
+ - `examples`
108
+ - `funding`
109
+ - `id prefix`
110
+ - `input`
111
+ - `moves`
112
+ - `steps`
113
+ - `summary`
114
+ - `title`
115
+ - `updates`
116
+
117
+ This inventory covers all branches and nested instruments in the module. The selected parameters determine which clauses and actions the compiler emits. Indexed action names expand over the declared finite list.
27
118
 
28
119
  ## Decision ports
29
120
 
@@ -31,17 +122,17 @@ None.
31
122
 
32
123
  ## Actions and clauses
33
124
 
34
- | Action | Clauses lowered |
35
- | ---------- | ------------------------------------------------- |
36
- | `create` | `agent description`, `moves`, `steps`, `summary` |
37
- | `activate` | `due`, `moves`, `steps`, `summary` |
38
- | `fail` | `due`, `moves`, `steps`, `summary` |
39
- | `close` | `agent description`, `moves`, `steps`, `summary` |
40
- | `create` | `agent description`, `moves`, `steps`, `summary` |
41
- | `cancel` | `agent description`, `moves`, `steps`, `summary` |
42
- | `collect` | `agent description`, `moves`, `steps`, `summary` |
43
- | `refund` | `agent description`, `moves`, `steps`, `summary` |
44
- | `create` | `agent description`, `examples`, `moves`, `steps` |
45
- | `activate` | `due`, `examples`, `moves`, `steps` |
46
- | `fail` | `due`, `examples`, `moves`, `steps` |
47
- | `close` | `agent description`, `examples`, `moves`, `steps` |
125
+ | Action | Clauses lowered |
126
+ | --- | --- |
127
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
128
+ | `activate` | `due`, `moves`, `steps`, `summary` |
129
+ | `fail` | `due`, `moves`, `steps`, `summary` |
130
+ | `close` | `agent description`, `moves`, `steps`, `summary` |
131
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
132
+ | `cancel` | `agent description`, `moves`, `steps`, `summary` |
133
+ | `collect` | `agent description`, `moves`, `steps`, `summary` |
134
+ | `refund` | `agent description`, `moves`, `steps`, `summary` |
135
+ | `create` | `agent description`, `examples`, `moves`, `steps` |
136
+ | `activate` | `due`, `examples`, `moves`, `steps` |
137
+ | `fail` | `due`, `examples`, `moves`, `steps` |
138
+ | `close` | `agent description`, `examples`, `funding`, `input`, `moves`, `steps`, `updates` |
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.0. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # weighted_distribution
4
4
 
@@ -10,18 +10,113 @@ Source: [`std/money_flows/weighted_distribution.hsx`](../../../std/money_flows/w
10
10
 
11
11
  ## Parameters
12
12
 
13
- - `source: party`
14
- - `recipient: party`
15
- - `amount: money<C>`
16
- - `record_at: date`
17
- - `weight: optional<money<C>>`
18
- - `max_recipients: optional<integer>`
19
- - `snapshot: optional<condition>`
20
- - `rounding_policy: optional<text>`
21
- - `withholding_policy: optional<text>`
22
- - `correction_policy: optional<text>`
23
- - `flat: optional<block>`
24
- - `id_prefix_override: optional<text>`
13
+ | Parameter | Type | Required | Meaning |
14
+ | --- | --- | --- | --- |
15
+ | `source` | `optional<party>` | No | The funding party providing the distribution pool. |
16
+ | `recipient` | `optional<party>` | No | The party representing entitled recipients. |
17
+ | `amount` | `optional<money<C>>` | No | Total distribution pool in minor units of currency `C`. |
18
+ | `record_at` | `optional<date>` | No | Date when entitlement eligibility is established. |
19
+ | `weight` | `optional<money<C>>` | No | Binding name for individual recipient weight amounts. |
20
+ | `max_recipients` | `optional<integer>` | No | Exact number of entitlement rows required before snapshotting. |
21
+ | `snapshot` | `optional<condition>` | No | Port freezing the entitlement set against stored decision evidence. |
22
+ | `rounding_policy` | `optional<text>` | No | Mathematical rounding policy (`largest_remainder`). |
23
+ | `withholding_policy` | `optional<text>` | No | Tax or withholding policy (`refuse`). |
24
+ | `correction_policy` | `optional<text>` | No | Error correction policy (`new_distribution`). |
25
+ | `flat` | `optional<block>` | No | Optional flat distribution configuration block. |
26
+ | `receipts` | `optional<block>` | No | receipts selects repeated distributions from immutable allocation receipts. |
27
+ | `id_prefix_override` | `optional<text>` | No | Optional custom prefix for generated instrument IDs. |
28
+
29
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
30
+
31
+ ## Module guidance
32
+
33
+ Frozen largest-remainder distribution splitting one pool across dynamic recipients by recorded weights.
34
+
35
+ ### Purpose
36
+
37
+ `weighted_distribution` distributes dividend pools, creator royalties, liquidation proceeds, and investment returns.
38
+ Child entitlement rows are recorded for each recipient with their respective weight. Once all recipients are recorded,
39
+ an evidence-backed snapshot freezes the entitlement set. Each recipient is then paid their exact largest-remainder
40
+ share such that all payouts sum exactly to `amount` without rounding leaks.
41
+
42
+ ### Selection guidance
43
+
44
+ - vs `pooled_split`: `weighted_distribution` handles dynamic recipient rosters recorded as child rows and frozen
45
+ via snapshot. `pooled_split` hardcodes a fixed set of recipients and static percentages at definition time.
46
+ - vs `settlement_batch`: `weighted_distribution` splits one funding pool out to many recipients.
47
+ `settlement_batch` aggregates many inbound charges and adjustments into a single net payout.
48
+
49
+ ### Parameters
50
+
51
+ - `source`: The funding party providing the distribution pool.
52
+ - `recipient`: The party representing entitled recipients.
53
+ - `amount`: Total distribution pool in minor units of currency `C`.
54
+ - `record_at`: Date when entitlement eligibility is established.
55
+ - `weight`: Binding name for individual recipient weight amounts.
56
+ - `max_recipients`: Exact number of entitlement rows required before snapshotting.
57
+ - `snapshot`: Port freezing the entitlement set against stored decision evidence.
58
+ - `rounding_policy`: Mathematical rounding policy (`largest_remainder`).
59
+ - `withholding_policy`: Tax or withholding policy (`refuse`).
60
+ - `correction_policy`: Error correction policy (`new_distribution`).
61
+ - `flat`: Optional flat distribution configuration block.
62
+ - `id_prefix_override`: Optional custom prefix for generated instrument IDs.
63
+
64
+ ### Decision ports
65
+
66
+ - `snapshot`: Port freezing the entitlement set with an evidence reference, preventing further entries.
67
+
68
+ ### Example
69
+
70
+ ```hsx
71
+ program weighted_distribution_example "Weighted distribution example"
72
+ import { weighted_distribution } from "std/money_flows"
73
+ party distribution_source: business
74
+ party recipient: business
75
+ settlement proceeds = weighted_distribution {
76
+ source: distribution_source
77
+ recipient: recipient
78
+ amount: distributableAmount: money(SAR)
79
+ weight: entitlementWeight: money(SAR)
80
+ max_recipients: 12
81
+ record_at: recordAt
82
+ snapshot: port snapshot_entitlements
83
+ rounding_policy: largest_remainder
84
+ withholding_policy: refuse
85
+ correction_policy: new_distribution
86
+ }
87
+ port snapshot_entitlements {
88
+ allowed: [distribution_source]
89
+ shape: { evidenceReference: text }
90
+ }
91
+ ```
92
+
93
+ ### Receipt-backed distributions
94
+
95
+ receipts selects repeated distributions from immutable allocation receipts.
96
+ It names round, receipt, path, mode (cash or loss), fee_bps and vat_bps.
97
+ The funding snapshot owns ticket weights and original wallet destinations.
98
+ Cash floors each ratio after fee and fee VAT; a named account receives residual.
99
+ Loss assigns principal by largest remainder without cash, fee or VAT.
100
+ Each receipt is consumed once; a new receipt may fund a new distribution record.
101
+ This mode does not use caller-entered weights or a once-only settled principal pool.
102
+
103
+ ## Declared clauses
104
+
105
+ - `agent description`
106
+ - `aggregate invariants`
107
+ - `capture input`
108
+ - `description`
109
+ - `due`
110
+ - `id prefix`
111
+ - `input`
112
+ - `moves`
113
+ - `port`
114
+ - `requires refs`
115
+ - `steps`
116
+ - `summary`
117
+ - `title`
118
+
119
+ This inventory covers all branches and nested instruments in the module. The selected parameters determine which clauses and actions the compiler emits. Indexed action names expand over the declared finite list.
25
120
 
26
121
  ## Decision ports
27
122
 
@@ -29,11 +124,12 @@ Source: [`std/money_flows/weighted_distribution.hsx`](../../../std/money_flows/w
29
124
 
30
125
  ## Actions and clauses
31
126
 
32
- | Action | Clauses lowered |
33
- | ---------- | ------------------------------------------------------------------------------------------------- |
34
- | `create` | `agent description`, `moves`, `steps`, `summary` |
35
- | `snapshot` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
36
- | `create` | `agent description`, `moves`, `steps`, `summary` |
37
- | `payout` | `agent description`, `computes distribute`, `moves`, `steps`, `summary` |
38
- | `create` | `agent description`, `moves`, `requires refs`, `steps`, `summary` |
39
- | `payout` | `computes distribute`, `due`, `moves`, `steps`, `summary` |
127
+ | Action | Clauses lowered |
128
+ | --- | --- |
129
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
130
+ | `[snapshot]` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
131
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
132
+ | `payout` | `agent description`, `moves`, `steps`, `summary` |
133
+ | `create` | `agent description`, `moves`, `requires refs`, `steps`, `summary` |
134
+ | `payout` | `due`, `moves`, `steps`, `summary` |
135
+ | `create` | `agent description`, `steps` |
@@ -1,20 +1,20 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.0. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # Types
4
4
 
5
5
  HSX checks types before it emits UDL. Money and account values carry a currency parameter, and no implicit currency conversion exists.
6
6
 
7
- | Kind | Meaning |
8
- | ----------- | -------------------------------------------------------------------- |
9
- | `account` | A currency-indexed ledger account reference. |
10
- | `boolean` | A compile-time or stored true or false value. |
11
- | `bps` | An integer basis-point value. |
12
- | `condition` | A declared decision port. |
13
- | `date` | A stored date-time string checked by UDL. |
14
- | `integer` | A bounded whole number. |
15
- | `money` | A currency-indexed minor-unit amount. |
16
- | `party` | A declared program party. |
17
- | `percent` | An exact percentage with basis-point precision. |
18
- | `ref` | A typed reference to another instrument. |
19
- | `text` | A finite string value. |
20
- | `unknown` | An internal checker result that source must resolve before lowering. |
7
+ | Kind | Meaning |
8
+ | --- | --- |
9
+ | `account` | A currency-indexed ledger account reference. |
10
+ | `boolean` | A compile-time or stored true or false value. |
11
+ | `bps` | An integer basis-point value. |
12
+ | `condition` | A declared decision port. |
13
+ | `date` | A stored date-time string checked by UDL. |
14
+ | `integer` | A bounded whole number. |
15
+ | `money` | A currency-indexed minor-unit amount. |
16
+ | `party` | A declared program party. |
17
+ | `percent` | An exact percentage with basis-point precision. |
18
+ | `ref` | A typed reference to another instrument. |
19
+ | `text` | A finite string value. |
20
+ | `unknown` | An internal checker result that source must resolve before lowering. |
@@ -1,13 +1,13 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.0. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # UDL output
4
4
 
5
5
  An accepted compile returns three artifacts.
6
6
 
7
- | Artifact | Contents |
8
- | -------------- | ----------------------------------------------------------------------------------- |
9
- | `document` | The canonical UDL object. Serialize it with `serializeUdl` from `@hyperscale0/udl`. |
10
- | `originMap` | Canonical UDL paths mapped to authored HSX spans. |
11
- | `costManifest` | The deterministic manifest pinned to the supplied rate card. |
7
+ | Artifact | Contents |
8
+ | --- | --- |
9
+ | `document` | The canonical UDL object. Serialize it with `serializeUdl` from `@hyperscale0/udl`. |
10
+ | `originMap` | Canonical UDL paths mapped to authored HSX spans. |
11
+ | `costManifest` | The deterministic manifest pinned to the supplied rate card. |
12
12
 
13
13
  Canonical UDL sorts object keys, preserves array order, uses two-space JSON indentation, and ends with one line feed.
@@ -27,7 +27,7 @@ payee, and both must be declared parties.
27
27
  `payee` name declared parties; `amount: tipAmount: money(SAR)` declares a
28
28
  field the instance stores, called `tipAmount`, holding an amount in SAR.
29
29
 
30
- That doubled colon reads oddly the first time. The archetype's parameter is
30
+ That doubled colon reads oddly the first time. The module's parameter is
31
31
  `amount`; its value is a typed binding, `tipAmount: money(SAR)`, which names
32
32
  the field AND its type. You choose the field name because it shows up in the
33
33
  generated API, and `amount` is HSX's word, not your product's.
@@ -1,4 +1,4 @@
1
- # 2 · Imports, settlement bricks, and the port
1
+ # 2 · Imports, modules, and the port
2
2
 
3
3
  [`photo-booth.hsx`](./photo-booth.hsx) is a photo-booth rental company. The
4
4
  renter pays up front, but the money does not reach the company until the booth
@@ -1,4 +1,4 @@
1
- // Imports, archetypes, and the decision port.
1
+ // Imports, modules, and the decision port.
2
2
  //
3
3
  // A photo-booth rental company. The renter pays up front, but the money sits
4
4
  // in escrow until the booth is delivered. The company's own backend answers
@@ -59,7 +59,7 @@ share does. Nobody's fraction of a halala goes missing, and nobody's is
59
59
  invented.
60
60
 
61
61
  A pool needs at least two recipients, and the funder cannot be one of them. A
62
- pool that distributes to one person is a transfer, and there is an archetype
62
+ pool that distributes to one person is a transfer, and there is an module
63
63
  for that.
64
64
 
65
65
  ## What it compiles to
@@ -0,0 +1,5 @@
1
+ # Authored payment
2
+
3
+ `payment.hsx` declares a payment with a bound internal transfer. The [module guide](../../docs/guide/08-writing-a-module.md#an-authored-action-that-moves-money) contains the same program. The docs builder compares the bytes and compiles it with the packaged cost table.
4
+
5
+ From the full repository root, run `bun open/hsx/bin/hsx.ts check open/hsx/examples/05-authored-instrument/payment.hsx`.
@@ -0,0 +1,37 @@
1
+ program authored_payment "Authored payment"
2
+
3
+ instrument payment {
4
+ agent_description: "Collect a stored payment once from its payer."
5
+ title: "Payment"
6
+ summary: "A payment with fixed payer and payee accounts"
7
+ fields {
8
+ payerAccountId: account<SAR>;
9
+ payeeAccountId: account<SAR>;
10
+ amount: money<SAR>;
11
+ }
12
+ parties { payer: payerAccountId; beneficiary: payeeAccountId; }
13
+ lifecycle {
14
+ states pending paid;
15
+ initial pending;
16
+ on pay: pending -> paid;
17
+ }
18
+ action create {
19
+ agent_description: "Open a pending payment without moving money."
20
+ steps: [];
21
+ moves: [];
22
+ }
23
+ action pay {
24
+ agent_description: "Move the stored amount from payer to payee."
25
+ steps: [];
26
+ moves: [{
27
+ bind: {
28
+ amount: { from: "instance", path: "fields.amount" }
29
+ currency: { from: "const", value: "SAR" }
30
+ sourceAccountId: { from: "instance", path: "fields.payerAccountId" }
31
+ destinationAccountId: { from: "instance", path: "fields.payeeAccountId" }
32
+ }
33
+ key: "payment_transfer"
34
+ operation: "internal_transfer.create"
35
+ }];
36
+ }
37
+ }
@@ -7,7 +7,6 @@ program watch_club "Watch club"
7
7
  import {
8
8
  security_deposit,
9
9
  instant_transfer,
10
- recurring_collection,
11
10
  scheduled,
12
11
  settlement_batch,
13
12
  swap
@@ -8,7 +8,7 @@ document byte for byte.
8
8
  The numbered examples provide end-to-end walkthroughs:
9
9
 
10
10
  - [01 · Your first program](01-first-program/README.md)
11
- - [02 · Imports and modules](02-imports-and-archetypes/README.md)
11
+ - [02 · Imports and modules](02-imports-and-modules/README.md)
12
12
  - [03 · Diagnostics](03-diagnostics/README.md)
13
13
  - [04 · Complete product](04-complete-product/README.md)
14
14
  - [05 · Watch club](05-watch-club/README.md)
@@ -28,7 +28,6 @@ Each money flow has a runnable example directory:
28
28
  - [pooled_split](pooled_split/README.md)
29
29
  - [premium_forward](premium_forward/README.md)
30
30
  - [reconciled_payout](reconciled_payout/README.md)
31
- - [recurring_collection](recurring_collection/README.md)
32
31
  - [rotating_pool](rotating_pool/README.md)
33
32
  - [scheduled](scheduled/README.md)
34
33
  - [security_deposit](security_deposit/README.md)