@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
  # HSX full documentation
4
4
 
@@ -25,7 +25,7 @@ settlement tip = instant_transfer {
25
25
 
26
26
  A port declares a decision that an external caller may supply. The port names the parties allowed to answer and may define a typed input shape. Use a port only when the selected instrument accepts a condition parameter.
27
27
 
28
- After package installation, run `npx @hyperscale0/hsx check product.hsx` while editing and `npx @hyperscale0/hsx build product.hsx --out product.udl.json` when the program passes. In a repository checkout, run `bun install` once, then use `bun run bin/hsx.ts check product.hsx` and `bun run bin/hsx.ts build product.hsx --out product.udl.json`.
28
+ After package installation, run `npx @hyperscale0/hsx check product.hsx` while editing and `npx @hyperscale0/hsx build product.hsx --out product.udl.json` when the program passes. In the full repository checkout, run `bun install` once from the repository root, then use `bun open/hsx/bin/hsx.ts check product.hsx` and `bun open/hsx/bin/hsx.ts build product.hsx --out product.udl.json`. In the standalone HSX package checkout, the entrypoint is `bin/hsx.ts`.
29
29
 
30
30
  # Money
31
31
 
@@ -223,10 +223,14 @@ settlement plan = scheduled {
223
223
  }
224
224
  ```
225
225
 
226
- `scheduled` handles finite installments and obligation schedules. `recurring_collection` records collection periods without inventing money movement. `rotating_pool` expands a fixed roster and cycle count. `settlement_batch` closes on a stored date before calculation, approval, instruction, acknowledgement, and reconciliation actions.
226
+ `scheduled` handles finite installments and obligation schedules. `rotating_pool` expands a fixed roster and cycle count. `settlement_batch` closes on a stored date before calculation, approval, instruction, acknowledgement, and reconciliation actions.
227
227
 
228
228
  General modules may use a comprehension over a compile-time integer or finite list. Runtime-dependent bounds are refused. An expansion may contain at most 256 generated rows.
229
229
 
230
+ Finite obligation counts expand the same lifecycle for each slice. A lifecycle source may be a finite list; `without(states, state)` removes one state before expansion. This preserves rejection of a repeated delinquency marker for its current slice.
231
+
232
+ Use `advance` with `dated: true` when each repayment has a signed date. `repayment_source` separates the borrower from the capital recipient; `profit_to` sends computed profit to a separate account. The caller partitions the principal and profit across stored repayments. These partitions do not enforce equal slices or ordered dates.
233
+
230
234
  # Composition
231
235
 
232
236
  One program can apply several instruments. Each instrument keeps its own lifecycle and fields. References connect them through typed ids instead of shared mutable state.
@@ -318,6 +322,54 @@ Imported exports carry the local declarations they reference. Identical declarat
318
322
 
319
323
  Publish a module only after compiling it directly and through an importing program. Compare the canonical UDL bytes from both paths when the exported application should be identical.
320
324
 
325
+ ## An authored action that moves money
326
+
327
+ Declare each cash movement in `moves` with a unique `key`, an `operation`, and `bind` operands. This complete program comes from [payment.hsx](../../examples/05-authored-instrument/payment.hsx). The docs builder requires the snippet to match that file and compiles it with the packaged cost table.
328
+
329
+ ```hsx source=examples/05-authored-instrument/payment.hsx
330
+ program authored_payment "Authored payment"
331
+
332
+ instrument payment {
333
+ agent_description: "Collect a stored payment once from its payer."
334
+ title: "Payment"
335
+ summary: "A payment with fixed payer and payee accounts"
336
+ fields {
337
+ payerAccountId: account<SAR>;
338
+ payeeAccountId: account<SAR>;
339
+ amount: money<SAR>;
340
+ }
341
+ parties { payer: payerAccountId; beneficiary: payeeAccountId; }
342
+ lifecycle {
343
+ states pending paid;
344
+ initial pending;
345
+ on pay: pending -> paid;
346
+ }
347
+ action create {
348
+ agent_description: "Open a pending payment without moving money."
349
+ steps: [];
350
+ moves: [];
351
+ }
352
+ action pay {
353
+ agent_description: "Move the stored amount from payer to payee."
354
+ steps: [];
355
+ moves: [{
356
+ bind: {
357
+ amount: { from: "instance", path: "fields.amount" }
358
+ currency: { from: "const", value: "SAR" }
359
+ sourceAccountId: { from: "instance", path: "fields.payerAccountId" }
360
+ destinationAccountId: { from: "instance", path: "fields.payeeAccountId" }
361
+ }
362
+ key: "payment_transfer"
363
+ operation: "internal_transfer.create"
364
+ }];
365
+ }
366
+ }
367
+ ```
368
+
369
+ `from: "instance"` reads an immutable stored field. `from: "const"` supplies the literal currency. The four bindings supply the transfer's amount, currency, source account and destination account. `internal_transfer.create` names the transfer operation; `payment_transfer` identifies this move within the action. Account IDs come from account creation or discovery before creating the payment. They are never invented by the program.
370
+
371
+ `create` opens a pending record without cash movement. `pay` moves the stored amount and transitions to `paid`; the lifecycle refuses a second payment under a new action request. The compiler emits these bindings into UDL. Execution still requires an engine that admits the operation and accounts.
372
+
321
373
  # Cost
322
374
 
323
375
  Compilation emits a deterministic cost manifest beside the UDL document. The manifest pins the cost-table version and effective digest. It records fixed structural cost, action effect rows, payer, settlement policy, meters, per-event prices, and any basis-point volume price.
@@ -374,12 +426,12 @@ Exit code `0` means the command accepted the program. Exit code `1` means compil
374
426
  # CLI
375
427
 
376
428
  ```text
377
- hsx 2.1.0, the HSX compiler
429
+ hsx 2.2.0, the HSX compiler
378
430
 
379
431
  Usage:
380
- hsx check <file.hsx> [--strict]
381
- hsx build <file.hsx> [--out <file.json>] [--strict]
382
- hsx cost <file.hsx> [--json] [--out <file.json>] [--strict]
432
+ hsx check <file.hsx> [--catalog <catalog.udl>] [--strict]
433
+ hsx build <file.hsx> [--catalog <catalog.udl>] [--out <file.json>] [--strict]
434
+ hsx cost <file.hsx> [--catalog <catalog.udl>] [--json] [--out <file.json>] [--strict]
383
435
  hsx explain <HSX####>
384
436
  hsx format <file.hsx>
385
437
  hsx lsp
@@ -395,6 +447,7 @@ Commands:
395
447
  lsp Run the language server over stdin and stdout.
396
448
 
397
449
  Options:
450
+ --catalog <file> Read the published instrument catalogue as canonical UDL JSON.
398
451
  --json Print the cost manifest as JSON instead of a table.
399
452
  --out <file> Write build or cost JSON to this path instead of stdout.
400
453
  --strict Treat warning-severity diagnostics as failures.
@@ -444,7 +497,7 @@ instrument probe {
444
497
  agent_description: "Create a probe instance.";
445
498
  steps: [];
446
499
  }
447
-
500
+
448
501
  }
449
502
  program second "Second"
450
503
  ```
@@ -475,7 +528,7 @@ instrument probe {
475
528
  agent_description: "Create a probe instance.";
476
529
  steps: [];
477
530
  }
478
-
531
+
479
532
  }
480
533
  instrument probe { fields {}; lifecycle { states created; initial created; }; action create { steps: []; }; }
481
534
  ```
@@ -527,7 +580,7 @@ instrument probe {
527
580
  agent_description: "Create a probe instance.";
528
581
  steps: [];
529
582
  }
530
-
583
+
531
584
  }
532
585
  subject vehicle { title: "Vehicle"; }
533
586
  ```
@@ -745,7 +798,7 @@ instrument probe {
745
798
  agent_description: "Create a probe instance.";
746
799
  steps: [];
747
800
  }
748
-
801
+
749
802
  }
750
803
  const fee: money<SAR> = USD 1.00
751
804
  ```
@@ -766,7 +819,7 @@ instrument probe {
766
819
  agent_description: "Create a probe instance.";
767
820
  steps: [];
768
821
  }
769
-
822
+
770
823
  }
771
824
  const fee: money<SAR> = SAR 1.001
772
825
  ```
@@ -886,7 +939,7 @@ instrument probe {
886
939
  agent_description: "Create a probe instance.";
887
940
  steps: [];
888
941
  }
889
-
942
+
890
943
  }
891
944
  ```
892
945
 
@@ -922,7 +975,7 @@ instrument probe {
922
975
  agent_description: "Create a probe instance.";
923
976
  steps: [];
924
977
  }
925
-
978
+
926
979
  }
927
980
  ```
928
981
 
@@ -942,7 +995,7 @@ instrument probe {
942
995
  agent_description: "Create a probe instance.";
943
996
  steps: [];
944
997
  }
945
-
998
+
946
999
  }
947
1000
  ```
948
1001
 
@@ -1299,7 +1352,7 @@ The parser is hand-written. This page records the exported lexer vocabulary, the
1299
1352
 
1300
1353
  ## Typed clause spellings
1301
1354
 
1302
- `action library`, `agent description`, `calls`, `capture input`, `commit`, `quote`, `decided amount`, `deadline`, `decision`, `computes distribute`, `description`, `due`, `earnable`, `event name`, `examples`, `input`, `moves`, `payout`, `piece plan`, `piece stage`, `port`, `principal`, `public action`, `reconcile`, `computes remainder`, `requires aggregate`, `requires checks`, `requires drained`, `requires exposure`, `requires refs`, `sandbox failure point`, `sets at`, `computes signed_sum`, `steps`, `summary`, `updates`, `notify`, `agent description`, `aggregate invariants`, `caller parked states`, `description`, `dials`, `distinct parties`, `computes derived`, `computes fees`, `id prefix`, `journeys`, `nav`, `partitions`, `subject`, `summary`, `surface visibility`, `template id`, `title`, `update`
1355
+ `funding`, `receipt distribution`, `requires allocation`, `allocation`, `contributions`, `allocate`, `contribution stage`, `date order`, `unique`, `transitions refs`, `action library`, `agent description`, `calls`, `requires input`, `engine owned`, `capture engine`, `capture input`, `commit`, `quote`, `decided amount`, `deadline`, `decision`, `computes distribute`, `description`, `due`, `earnable`, `event name`, `examples`, `input`, `moves`, `payout`, `piece plan`, `piece stage`, `port`, `principal`, `public action`, `reconcile`, `computes remainder`, `requires aggregate`, `requires checks`, `requires drained`, `requires exposure`, `requires refs`, `sandbox failure point`, `sets at`, `computes signed_sum`, `steps`, `summary`, `updates`, `notify`, `agent description`, `aggregate invariants`, `caller parked states`, `description`, `dials`, `distinct parties`, `computes derived`, `computes fees`, `id prefix`, `nav`, `partitions`, `subject`, `summary`, `surface visibility`, `template binding`, `template id`, `title`, `update`, `request authority`
1303
1356
 
1304
1357
  ## Standard-library modules
1305
1358
 
@@ -1314,7 +1367,6 @@ The parser is hand-written. This page records the exported lexer vocabulary, the
1314
1367
  - `pooled_split`
1315
1368
  - `premium_forward`
1316
1369
  - `reconciled_payout`
1317
- - `recurring_collection`
1318
1370
  - `rotating_pool`
1319
1371
  - `scheduled`
1320
1372
  - `security_deposit`
@@ -1333,14 +1385,91 @@ Source: [`std/money_flows/advance.hsx`](../../../std/money_flows/advance.hsx)
1333
1385
 
1334
1386
  ## Parameters
1335
1387
 
1336
- - `funder: party`
1337
- - `to: party`
1338
- - `amount: money<C>`
1339
- - `fee: optional<percent>`
1340
- - `count: optional<integer>`
1341
- - `every: optional<text>`
1342
- - `first_due: optional<date>`
1343
- - `against: optional<ref>`
1388
+ | Parameter | Type | Required | Meaning |
1389
+ | --- | --- | --- | --- |
1390
+ | `funder` | `party` | Yes | The party providing the upfront capital. |
1391
+ | `to` | `party` | Yes | The party receiving the advance and responsible for repayment. |
1392
+ | `amount` | `money<C>` | Yes | Total advanced principal in minor units of currency `C`. |
1393
+ | `fee` | `optional<percent>` | No | Optional markup percentage fee charged on the advance (basis points precision). |
1394
+ | `count` | `optional<integer>` | No | Optional number of scheduled installment repayments. |
1395
+ | `every` | `optional<text>` | No | Optional recurrence duration between installments (e.g. `"P30D"`). |
1396
+ | `first_due` | `optional<date>` | No | Optional date for the first installment repayment. |
1397
+ | `against` | `optional<ref>` | No | Optional reference to a hold instrument whose release will be carved to repay the advance. |
1398
+ | `repayment_source` | `optional<party>` | No | Optional party repaying when distinct from the capital recipient. |
1399
+ | `profit_to` | `optional<party>` | No | Optional recipient of profit, separated from principal repayments. |
1400
+ | `dated` | `optional<boolean>` | No | Require an explicit signed date for each repayment instead of duration offsets. |
1401
+
1402
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
1403
+
1404
+ ## Module guidance
1405
+
1406
+ Upfront capital disbursement repaid by carving future held payment releases or over scheduled installments.
1407
+
1408
+ ### Purpose
1409
+
1410
+ `advance` provides working capital, merchant cash advances, or contractor pre-funding from a funder to a recipient.
1411
+ Repayment occurs either automatically by intercepting (carving) releases from a linked escrow hold (`against`),
1412
+ or over calendar-anchored installment repayments (`count`, `every`, `first_due`).
1413
+
1414
+ ### Selection guidance
1415
+
1416
+ - vs `credit_facility`: `advance` disburses a single upfront lump-sum principal that is repaid over time.
1417
+ `credit_facility` establishes a reusable revolving credit line with multiple draws up to a limit,
1418
+ where repayments restore available borrowing capacity.
1419
+ - vs `conditional_disbursement`: `advance` expects repayment of the advanced principal plus optional fees.
1420
+ `conditional_disbursement` disburses non-repayable grants, claims, or milestone payments against external evidence.
1421
+ - vs `held_payment`: `held_payment` holds customer funds in escrow until delivery. An `advance` can carve repayments
1422
+ directly out of a `held_payment`'s release using `against`.
1423
+
1424
+ ### Parameters
1425
+
1426
+ - `funder`: The party providing the upfront capital.
1427
+ - `to`: The party receiving the advance and responsible for repayment.
1428
+ - `amount`: Total advanced principal in minor units of currency `C`.
1429
+ - `fee`: Optional markup percentage fee charged on the advance (basis points precision).
1430
+ - `count`: Optional number of scheduled installment repayments.
1431
+ - `every`: Optional recurrence duration between installments (e.g. `"P30D"`).
1432
+ - `first_due`: Optional date for the first installment repayment.
1433
+ - `repayment_source`: Optional party repaying when distinct from the capital recipient.
1434
+ - `profit_to`: Optional recipient of profit, separated from principal repayments.
1435
+ - `dated`: Require an explicit signed date for each repayment instead of duration offsets.
1436
+ - `against`: Optional reference to a hold instrument whose release will be carved to repay the advance.
1437
+
1438
+ ### Decision ports
1439
+
1440
+ None. Repayment is driven by linked hold releases or scheduled calendar dates.
1441
+
1442
+ ### Example
1443
+
1444
+ ```hsx
1445
+ program advance_example "Advance example"
1446
+ import { advance } from "std/money_flows"
1447
+ party funder: business
1448
+ party recipient: business
1449
+ settlement advance_payment = advance {
1450
+ funder: funder
1451
+ to: recipient
1452
+ amount: principal: money(SAR)
1453
+ fee: 2.5%
1454
+ count: 2
1455
+ every: P30D
1456
+ first_due: firstDueAt
1457
+ }
1458
+ ```
1459
+
1460
+ ## Declared clauses
1461
+
1462
+ - `agent description`
1463
+ - `description`
1464
+ - `due`
1465
+ - `id prefix`
1466
+ - `moves`
1467
+ - `partitions`
1468
+ - `steps`
1469
+ - `summary`
1470
+ - `title`
1471
+
1472
+ 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.
1344
1473
 
1345
1474
  ## Decision ports
1346
1475
 
@@ -1348,14 +1477,14 @@ None.
1348
1477
 
1349
1478
  ## Actions and clauses
1350
1479
 
1351
- | Action | Clauses lowered |
1352
- | --------------------- | ------------------------------------------------ |
1353
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1354
- | `disburse` | `agent description`, `moves`, `steps`, `summary` |
1355
- | `settle` | `agent description`, `moves`, `steps`, `summary` |
1356
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1357
- | `disburse` | `agent description`, `moves`, `steps`, `summary` |
1358
- | `collect_repayment_1` | `due`, `moves`, `steps`, `summary` |
1480
+ | Action | Clauses lowered |
1481
+ | --- | --- |
1482
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1483
+ | `disburse` | `agent description`, `moves`, `steps`, `summary` |
1484
+ | `settle` | `agent description`, `moves`, `steps`, `summary` |
1485
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1486
+ | `disburse` | `agent description`, `moves`, `steps`, `summary` |
1487
+ | `collect_repayment_[i]` | `agent description`, `due`, `moves`, `steps`, `summary` |
1359
1488
 
1360
1489
  # cancellable_booking
1361
1490
 
@@ -1367,14 +1496,124 @@ Source: [`std/money_flows/cancellable_booking.hsx`](../../../std/money_flows/can
1367
1496
 
1368
1497
  ## Parameters
1369
1498
 
1370
- - `guest: party`
1371
- - `host: party`
1372
- - `amount: money<C>`
1373
- - `starts_at: date`
1374
- - `late_penalty_bps: integer`
1375
- - `late_within: text`
1376
- - `early_penalty_bps: integer`
1377
- - `offer_life: text`
1499
+ | Parameter | Type | Required | Meaning |
1500
+ | --- | --- | --- | --- |
1501
+ | `guest` | `optional<party>` | No | The booking customer paying the fee and receiving refunds. |
1502
+ | `host` | `optional<party>` | No | The service provider receiving the payout or retained cancellation penalty. |
1503
+ | `amount` | `optional<money<C>>` | No | Total booking price in minor units of currency `C`. |
1504
+ | `starts_at` | `optional<date>` | No | Stored ISO 8601 date when the booking begins. |
1505
+ | `late_penalty_bps` | `optional<integer>` | No | Penalty in basis points applied when cancelling within the late window. |
1506
+ | `late_within` | `optional<text>` | No | ISO 8601 duration defining the late window before `starts_at` (e.g. `"P2D"` for 2 days). |
1507
+ | `early_penalty_bps` | `optional<integer>` | No | Penalty in basis points applied when cancelling before the late window. |
1508
+ | `offer_life` | `optional<text>` | No | ISO 8601 duration defining how long a quoted cancellation offer remains valid (e.g. `"PT30M"`). |
1509
+ | `cancel_bands` | `optional<list<block>>` | No | Supply cancel_bands to select deposit/balance custody instead of quoted cancellation. |
1510
+ | `price_value` | `optional<text>` | No | price_value and supplier_cost fix the price; deposit_bps derives the deposit. |
1511
+ | `supplier_cost` | `optional<text>` | No | price_value and supplier_cost fix the price; deposit_bps derives the deposit. |
1512
+ | `departure` | `optional<text>` | No | balance_before and confirmation_window are positive fixed durations relative to departure. |
1513
+ | `balance_before` | `optional<text>` | No | balance_before and confirmation_window are positive fixed durations relative to departure. |
1514
+ | `confirmation_window` | `optional<text>` | No | balance_before and confirmation_window are positive fixed durations relative to departure. |
1515
+ | `unpaid_band` | `optional<integer>` | No | The unpaid_band index selects a retained deposit policy. |
1516
+ | `acceptance` | `optional<block>` | No | acceptance optionally supplies an aggregate gate. |
1517
+ | `deposit_bps` | `optional<integer>` | No | price_value and supplier_cost fix the price; deposit_bps derives the deposit. |
1518
+ | `tax_bps` | `optional<integer>` | No | tax_bps applies to margin after the supplier share. |
1519
+ | `authority_type` | `optional<text>` | No | authority_type and supplier_role bind release to a consumed confirmation decision. |
1520
+ | `supplier_role` | `optional<text>` | No | authority_type and supplier_role bind release to a consumed confirmation decision. |
1521
+
1522
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
1523
+
1524
+ ## Module guidance
1525
+
1526
+ Time-anchored reservation holding booking funds in escrow with dynamically quoted cancellation penalties.
1527
+
1528
+ ### Purpose
1529
+
1530
+ `cancellable_booking` holds booking fees in escrow from a guest for a host until a scheduled start date.
1531
+ It fits hospitality, travel reservations, studio rentals, event tickets, and appointments where guests
1532
+ can cancel prior to start, but cancellation penalties depend on how close to the start date cancellation occurs.
1533
+
1534
+ ### Selection guidance
1535
+
1536
+ - vs `held_payment`: Both hold money in escrow and both quote a cancellation before it is spent.
1537
+ `cancellable_booking` prices the penalty against the time left before `starts_at`, so the charge moves
1538
+ as the start approaches; `held_payment` has no start date and quotes one flat charge.
1539
+ Choose `cancellable_booking` whenever cancellation fees are time-sensitive.
1540
+ - vs `security_deposit`: `security_deposit` holds funds to cover damages claimed by the holder.
1541
+ `cancellable_booking` holds the service fee itself and releases to the host upon `starts_at` or refunds net of penalty.
1542
+
1543
+ ### Parameters
1544
+
1545
+ - `guest`: The booking customer paying the fee and receiving refunds.
1546
+ - `host`: The service provider receiving the payout or retained cancellation penalty.
1547
+ - `amount`: Total booking price in minor units of currency `C`.
1548
+ - `starts_at`: Stored ISO 8601 date when the booking begins.
1549
+ - `late_penalty_bps`: Penalty in basis points applied when cancelling within the late window.
1550
+ - `late_within`: ISO 8601 duration defining the late window before `starts_at` (e.g. `"P2D"` for 2 days).
1551
+ - `early_penalty_bps`: Penalty in basis points applied when cancelling before the late window.
1552
+ - `offer_life`: ISO 8601 duration defining how long a quoted cancellation offer remains valid (e.g. `"PT30M"`).
1553
+
1554
+ ### Decision ports
1555
+
1556
+ None. Action transitions are driven by guest API calls (`take`, `cancel`, `confirm`) and scheduled completion (`complete` due at `starts_at`).
1557
+
1558
+ ### Example
1559
+
1560
+ ```hsx
1561
+ program studio_booking "Studio booking"
1562
+ import { cancellable_booking } from "std/money_flows"
1563
+ party guest: person
1564
+ party studio: business
1565
+ settlement studio_session = cancellable_booking {
1566
+ guest: guest
1567
+ host: studio
1568
+ amount: sessionPrice: money(SAR)
1569
+ starts_at: startsAt
1570
+ late_penalty_bps: 5000
1571
+ late_within: "P2D"
1572
+ early_penalty_bps: 1000
1573
+ offer_life: "PT30M"
1574
+ }
1575
+ ```
1576
+
1577
+ ### Finite cancellation bands
1578
+
1579
+ Supply cancel_bands to select deposit/balance custody instead of quoted cancellation.
1580
+ Each band has name, refund (full, balance or none), starts_at after the first band,
1581
+ and supplier_bps when money is retained. The unpaid_band index selects a retained
1582
+ deposit policy. Omit it to return the deposit; a full-refund band also returns it. price_value and supplier_cost fix the price; deposit_bps derives
1583
+ the deposit. balance_before and confirmation_window are positive fixed durations
1584
+ relative to departure. tax_bps applies to margin after the supplier share.
1585
+ authority_type and supplier_role bind release to a consumed confirmation decision.
1586
+ acceptance optionally supplies an aggregate gate. All actions are private until
1587
+ expose selects them. Ordered band starts and deadlines prevent a late sweep from
1588
+ extending an earlier band's cancellation rights. Full timeout refund returns price.
1589
+ Seven derivations suffice for three bands; larger finite policies use up to the
1590
+ UDL bound of 64 derived amounts. shift_date(date, duration, "before") subtracts a
1591
+ fixed duration; omitting the direction adds it. Invalid dates or durations refuse.
1592
+
1593
+ ## Declared clauses
1594
+
1595
+ - `agent description`
1596
+ - `caller parked states`
1597
+ - `commit`
1598
+ - `deadline`
1599
+ - `description`
1600
+ - `distinct parties`
1601
+ - `due`
1602
+ - `id prefix`
1603
+ - `input`
1604
+ - `moves`
1605
+ - `partitions`
1606
+ - `port`
1607
+ - `quote`
1608
+ - `requires drained`
1609
+ - `sandbox failure point`
1610
+ - `steps`
1611
+ - `summary`
1612
+ - `title`
1613
+ - `unique`
1614
+ - `updates`
1615
+
1616
+ 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.
1378
1617
 
1379
1618
  ## Decision ports
1380
1619
 
@@ -1382,14 +1621,25 @@ None.
1382
1621
 
1383
1622
  ## Actions and clauses
1384
1623
 
1385
- | Action | Clauses lowered |
1386
- | ---------- | ------------------------------------------------------------------------- |
1387
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1388
- | `take` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1389
- | `complete` | `due`, `moves`, `steps`, `summary` |
1390
- | `cancel` | `agent description`, `moves`, `quote`, `steps`, `summary` |
1391
- | `confirm` | `agent description`, `commit`, `moves`, `steps`, `summary` |
1392
- | `retain` | `agent description`, `moves`, `steps`, `summary` |
1624
+ | Action | Clauses lowered |
1625
+ | --- | --- |
1626
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1627
+ | `take` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1628
+ | `complete` | `due`, `moves`, `steps`, `summary` |
1629
+ | `cancel` | `agent description`, `moves`, `quote`, `steps`, `summary` |
1630
+ | `confirm` | `agent description`, `commit`, `moves`, `steps`, `summary` |
1631
+ | `retain` | `agent description`, `moves`, `steps`, `summary` |
1632
+ | `create` | `agent description`, `deadline`, `steps`, `unique` |
1633
+ | `deposit` | `agent description`, `deadline`, `moves`, `port`, `steps` |
1634
+ | `expire` | `agent description`, `due`, `requires drained`, `steps` |
1635
+ | `[balance_action]` | `agent description`, `deadline`, `moves`, `port`, `steps` |
1636
+ | `[open_action]` | `agent description`, `due`, `steps` |
1637
+ | `[cancel_action]` | `agent description`, `deadline`, `moves`, `port`, `steps` |
1638
+ | `cancel_unpaid` | `agent description`, `due`, `moves`, `steps` |
1639
+ | `await_confirmation` | `agent description`, `due`, `steps` |
1640
+ | `confirm` | `agent description`, `deadline`, `input`, `steps`, `updates` |
1641
+ | `release` | `agent description`, `moves`, `steps` |
1642
+ | `refund_unconfirmed` | `agent description`, `due`, `moves`, `steps` |
1393
1643
 
1394
1644
  # captured_payment
1395
1645
 
@@ -1401,17 +1651,89 @@ Source: [`std/money_flows/captured_payment.hsx`](../../../std/money_flows/captur
1401
1651
 
1402
1652
  ## Parameters
1403
1653
 
1404
- - `payer: party`
1405
- - `payee: party`
1406
- - `amount: money<C>`
1407
- - `reserve_until: date`
1408
- - `correction: condition`
1409
- - `external_reversal: condition`
1410
- - `capture_mode: text`
1411
- - `correction_mode: text`
1412
- - `negative_position: text`
1413
- - `timeout: text`
1414
- - `derived_amount: optional<block>`
1654
+ | Parameter | Type | Required | Meaning |
1655
+ | --- | --- | --- | --- |
1656
+ | `payer` | `party` | Yes | Party whose account balance is reserved during authorization. |
1657
+ | `payee` | `party` | Yes | Beneficiary party capturing authorized funds. |
1658
+ | `amount` | `money<C>` | Yes | Maximum authorized reservation in minor units of currency `C`. |
1659
+ | `reserve_until` | `date` | Yes | Expiration date for the authorization hold. |
1660
+ | `correction` | `condition` | Yes | Condition port allowing post-settlement amount corrections. |
1661
+ | `external_reversal` | `condition` | Yes | Condition port allowing external processor chargebacks/reversals. |
1662
+ | `derived_amount` | `optional<block>` | No | Optional block declaring percentage fee calculation. |
1663
+
1664
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
1665
+
1666
+ ## Module guidance
1667
+
1668
+ Two-phase authorization and capture payment flow for card and merchant processing.
1669
+
1670
+ ### Purpose
1671
+
1672
+ `captured_payment` reserves funds against a payer's account and allows the payee to capture the authorized
1673
+ balance in one or multiple slices before a reservation expiry date (`reserve_until`). It fits ecommerce checkouts,
1674
+ card processing, hotel authorizations, and pay-at-pump fuel payments where final amounts vary or settle later.
1675
+
1676
+ ### Selection guidance
1677
+
1678
+ - vs `instant_transfer`: `instant_transfer` immediately transfers money from payer to payee in a single irreversible
1679
+ step without reservation or settlement delays. `captured_payment` separates authorization from capture, allowing
1680
+ incremental captures, voids, amount corrections via the `correction` port, and external network reversals via `external_reversal`.
1681
+ - vs `held_payment`: `held_payment` holds the full amount in third-party escrow pending release. `captured_payment`
1682
+ reserves funds directly on payer balance and settles incrementally directly to payee.
1683
+
1684
+ ### Parameters
1685
+
1686
+ - `payer`: Party whose account balance is reserved during authorization.
1687
+ - `payee`: Beneficiary party capturing authorized funds.
1688
+ - `amount`: Maximum authorized reservation in minor units of currency `C`.
1689
+ - `reserve_until`: Expiration date for the authorization hold.
1690
+ - `correction`: Condition port allowing post-settlement amount corrections.
1691
+ - `external_reversal`: Condition port allowing external processor chargebacks/reversals.
1692
+ - `derived_amount`: Optional block declaring percentage fee calculation.
1693
+
1694
+ ### Decision ports
1695
+
1696
+ - `correction`: Condition allowing payee or processor to submit an amount correction after settlement.
1697
+ - `external_reversal`: Condition allowing bank or card network to execute an external reversal.
1698
+
1699
+ ### Example
1700
+
1701
+ ```hsx
1702
+ program captured_payment_example "Captured payment example"
1703
+ import { captured_payment } from "std/money_flows"
1704
+ party payer: person
1705
+ party payee: business
1706
+ settlement card_payment = captured_payment {
1707
+ payer: payer
1708
+ payee: payee
1709
+ amount: authorizedAmount: money(SAR)
1710
+ reserve_until: reserveUntil
1711
+ correction: port correct_capture
1712
+ external_reversal: port reverse_capture within P14D
1713
+ }
1714
+ port correct_capture { allowed: [payee] }
1715
+ port reverse_capture {
1716
+ allowed: [payee]
1717
+ shape: { externalReference: text }
1718
+ }
1719
+ ```
1720
+
1721
+ ## Declared clauses
1722
+
1723
+ - `agent description`
1724
+ - `capture input`
1725
+ - `deadline`
1726
+ - `description`
1727
+ - `due`
1728
+ - `input`
1729
+ - `moves`
1730
+ - `port`
1731
+ - `sandbox failure point`
1732
+ - `steps`
1733
+ - `summary`
1734
+ - `title`
1735
+
1736
+ 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.
1415
1737
 
1416
1738
  ## Decision ports
1417
1739
 
@@ -1420,18 +1742,18 @@ Source: [`std/money_flows/captured_payment.hsx`](../../../std/money_flows/captur
1420
1742
 
1421
1743
  ## Actions and clauses
1422
1744
 
1423
- | Action | Clauses lowered |
1424
- | ------------------ | ------------------------------------------------------------------------------------------------------------- |
1425
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1426
- | `authorize` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1427
- | `capture` | `agent description`, `deadline`, `description`, `input`, `moves`, `sandbox failure point`, `steps`, `summary` |
1428
- | `capture_more` | `agent description`, `deadline`, `description`, `input`, `moves`, `steps`, `summary` |
1429
- | `settle` | `agent description`, `deadline`, `moves`, `steps`, `summary` |
1430
- | `void` | `agent description`, `moves`, `steps`, `summary` |
1431
- | `expire` | `due`, `moves`, `steps`, `summary` |
1432
- | `settle_on_expiry` | `due`, `moves`, `steps`, `summary` |
1433
- | `correction_name` | `agent description`, `capture input`, `input`, `moves`, `port`, `steps`, `summary` |
1434
- | `reversal_name` | `agent description`, `capture input`, `deadline`, `input`, `moves`, `port`, `steps`, `summary` |
1745
+ | Action | Clauses lowered |
1746
+ | --- | --- |
1747
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1748
+ | `authorize` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1749
+ | `capture` | `agent description`, `deadline`, `description`, `input`, `moves`, `sandbox failure point`, `steps`, `summary` |
1750
+ | `capture_more` | `agent description`, `deadline`, `description`, `input`, `moves`, `steps`, `summary` |
1751
+ | `settle` | `agent description`, `deadline`, `moves`, `steps`, `summary` |
1752
+ | `void` | `agent description`, `moves`, `steps`, `summary` |
1753
+ | `expire` | `due`, `moves`, `steps`, `summary` |
1754
+ | `settle_on_expiry` | `due`, `moves`, `steps`, `summary` |
1755
+ | `[correction_name]` | `agent description`, `capture input`, `input`, `moves`, `port`, `steps`, `summary` |
1756
+ | `[reversal_name]` | `agent description`, `capture input`, `deadline`, `input`, `moves`, `port`, `steps`, `summary` |
1435
1757
 
1436
1758
  # conditional_disbursement
1437
1759
 
@@ -1443,13 +1765,81 @@ Source: [`std/money_flows/conditional_disbursement.hsx`](../../../std/money_flow
1443
1765
 
1444
1766
  ## Parameters
1445
1767
 
1446
- - `source: party`
1447
- - `destination: party`
1448
- - `cap: money<C>`
1449
- - `amount: money<C>`
1450
- - `decision: condition`
1451
- - `reopen_policy: text`
1452
- - `recovery_policy: text`
1768
+ | Parameter | Type | Required | Meaning |
1769
+ | --- | --- | --- | --- |
1770
+ | `source` | `party` | Yes | The funding party providing the money. |
1771
+ | `destination` | `party` | Yes | The beneficiary party receiving approved disbursements. |
1772
+ | `cap` | `money<C>` | Yes | Maximum total amount that can be disbursed across all child approvals in minor units of currency `C`. |
1773
+ | `amount` | `money<C>` | Yes | Binding name for child approval amount values. |
1774
+ | `decision` | `condition` | Yes | Port conditioning approval, requiring evidence reference. |
1775
+
1776
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
1777
+
1778
+ ## Module guidance
1779
+
1780
+ Capped disbursement from a source party to a destination party gated on stored external decision evidence.
1781
+
1782
+ ### Purpose
1783
+
1784
+ `conditional_disbursement` manages evidence-contingent payouts subject to a cumulative cap.
1785
+ It fits insurance claim settlements, grant tranches, subsidy distributions, and escrow milestones
1786
+ where each approved payment requires explicit external evidence and the total paid must not exceed `cap`.
1787
+
1788
+ ### Selection guidance
1789
+
1790
+ - vs `advance`: `conditional_disbursement` disburses non-repayable funds against external evidence
1791
+ up to a declared cap. `advance` pays money up front with the expectation of repayment through carved
1792
+ hold releases or scheduled installments.
1793
+ - vs `instant_transfer`: `instant_transfer` moves money immediately with no evidence gate or cap.
1794
+ `conditional_disbursement` requires an external decision port and evidence reference before any child amount moves.
1795
+
1796
+ ### Parameters
1797
+
1798
+ - `source`: The funding party providing the money.
1799
+ - `destination`: The beneficiary party receiving approved disbursements.
1800
+ - `cap`: Maximum total amount that can be disbursed across all child approvals in minor units of currency `C`.
1801
+ - `amount`: Binding name for child approval amount values.
1802
+ - `decision`: Port conditioning approval, requiring evidence reference.
1803
+
1804
+ ### Decision ports
1805
+
1806
+ - `decision`: External port providing decision evidence required to approve child disbursement amounts.
1807
+
1808
+ ### Example
1809
+
1810
+ ```hsx
1811
+ program conditional_disbursement_example "Conditional disbursement example"
1812
+ import { conditional_disbursement } from "std/money_flows"
1813
+ party source: business
1814
+ party claimant: person
1815
+ settlement claim_payment = conditional_disbursement {
1816
+ source: source
1817
+ destination: claimant
1818
+ cap: policyLimit: money(SAR)
1819
+ amount: approvedAmount: money(SAR)
1820
+ decision: port approve_claim
1821
+ }
1822
+ port approve_claim {
1823
+ allowed: [source]
1824
+ shape: { evidenceReference: text }
1825
+ }
1826
+ ```
1827
+
1828
+ ## Declared clauses
1829
+
1830
+ - `agent description`
1831
+ - `capture input`
1832
+ - `description`
1833
+ - `id prefix`
1834
+ - `input`
1835
+ - `moves`
1836
+ - `port`
1837
+ - `steps`
1838
+ - `summary`
1839
+ - `title`
1840
+ - `unique`
1841
+
1842
+ 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.
1453
1843
 
1454
1844
  ## Decision ports
1455
1845
 
@@ -1457,13 +1847,13 @@ Source: [`std/money_flows/conditional_disbursement.hsx`](../../../std/money_flow
1457
1847
 
1458
1848
  ## Actions and clauses
1459
1849
 
1460
- | Action | Clauses lowered |
1461
- | --------- | ------------------------------------------------------------------------------------------------- |
1462
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1463
- | `deny` | `agent description`, `capture input`, `input`, `moves`, `port`, `steps`, `summary` |
1464
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1850
+ | Action | Clauses lowered |
1851
+ | --- | --- |
1852
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1853
+ | `deny` | `agent description`, `capture input`, `input`, `moves`, `port`, `steps`, `summary` |
1854
+ | `create` | `agent description`, `moves`, `steps`, `summary`, `unique` |
1465
1855
  | `approve` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1466
- | `pay` | `agent description`, `moves`, `steps`, `summary` |
1856
+ | `pay` | `agent description`, `moves`, `steps`, `summary` |
1467
1857
 
1468
1858
  # credit_facility
1469
1859
 
@@ -1475,15 +1865,88 @@ Source: [`std/money_flows/credit_facility.hsx`](../../../std/money_flows/credit_
1475
1865
 
1476
1866
  ## Parameters
1477
1867
 
1478
- - `lender: party`
1479
- - `borrower: party`
1480
- - `draw_destination: party`
1481
- - `limit: money<C>`
1482
- - `expires_at: date`
1483
- - `obligation: ref`
1484
- - `availability_policy: text`
1485
- - `expiry_policy: text`
1486
- - `close_policy: text`
1868
+ | Parameter | Type | Required | Meaning |
1869
+ | --- | --- | --- | --- |
1870
+ | `lender` | `party` | Yes | The financing institution or party providing the credit capacity. |
1871
+ | `borrower` | `party` | Yes | The borrowing party authorized to draw against the facility limit. |
1872
+ | `draw_destination` | `party` | Yes | Account or party receiving disbursed draw proceeds. |
1873
+ | `limit` | `money<C>` | Yes | Total revolving borrowing limit in minor units of currency `C`. |
1874
+ | `expires_at` | `date` | Yes | Expiration date after which new draws cannot be opened. |
1875
+ | `obligation` | `ref` | Yes | Reference to a scheduled obligation instrument handling draw repayments. |
1876
+
1877
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
1878
+
1879
+ ## Module guidance
1880
+
1881
+ Revolving credit line providing reusable borrowing capacity up to a limit backed by scheduled obligations.
1882
+
1883
+ ### Purpose
1884
+
1885
+ `credit_facility` manages revolving commercial credit, inventory financing, and overdraft facilities.
1886
+ A borrower can draw funds multiple times up to `limit` into `draw_destination`. Each draw creates a child
1887
+ record linked to a scheduled `obligation`. Repayments restore available borrowing capacity until `expires_at`.
1888
+
1889
+ ### Selection guidance
1890
+
1891
+ - vs `advance`: `credit_facility` provides revolving, reusable credit lines where multiple draws can occur
1892
+ and repayments restore capacity. `advance` is a single upfront lump-sum disbursement with a fixed repayment plan.
1893
+ - vs `scheduled`: `scheduled` defines repayment installments or recurring transfers. `credit_facility` delegates
1894
+ draw repayments to a `scheduled` obligation while tracking total facility utilization and limit compliance.
1895
+
1896
+ ### Parameters
1897
+
1898
+ - `lender`: The financing institution or party providing the credit capacity.
1899
+ - `borrower`: The borrowing party authorized to draw against the facility limit.
1900
+ - `draw_destination`: Account or party receiving disbursed draw proceeds.
1901
+ - `limit`: Total revolving borrowing limit in minor units of currency `C`.
1902
+ - `expires_at`: Expiration date after which new draws cannot be opened.
1903
+ - `obligation`: Reference to a scheduled obligation instrument handling draw repayments.
1904
+
1905
+ ### Decision ports
1906
+
1907
+ None on the facility itself. Mandates and decision ports are declared on the linked `obligation` instrument.
1908
+
1909
+ ### Example
1910
+
1911
+ ```hsx
1912
+ program credit_facility_example "Credit facility example"
1913
+ import { credit_facility, scheduled } from "std/money_flows"
1914
+ party lender: business
1915
+ party borrower: business
1916
+ party draw_destination: business
1917
+ party repayment_source: business
1918
+ settlement repayment = scheduled {
1919
+ mode: obligation
1920
+ payer: repayment_source
1921
+ payee: lender
1922
+ debtor: borrower
1923
+ amount: principal: money(SAR)
1924
+ count: 2
1925
+ every: P30D
1926
+ first_due: firstDueAt
1927
+ }
1928
+ settlement facility = credit_facility {
1929
+ lender: lender
1930
+ borrower: borrower
1931
+ draw_destination: draw_destination
1932
+ limit: facilityLimit: money(SAR)
1933
+ expires_at: expiresAt
1934
+ obligation: repayment.obligation
1935
+ }
1936
+ ```
1937
+
1938
+ ## Declared clauses
1939
+
1940
+ - `agent description`
1941
+ - `description`
1942
+ - `due`
1943
+ - `id prefix`
1944
+ - `moves`
1945
+ - `steps`
1946
+ - `summary`
1947
+ - `title`
1948
+
1949
+ 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.
1487
1950
 
1488
1951
  ## Decision ports
1489
1952
 
@@ -1491,12 +1954,12 @@ None.
1491
1954
 
1492
1955
  ## Actions and clauses
1493
1956
 
1494
- | Action | Clauses lowered |
1495
- | --------- | ------------------------------------------------ |
1496
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1497
- | `freeze` | `due`, `moves`, `steps`, `summary` |
1498
- | `close` | `agent description`, `moves`, `steps`, `summary` |
1499
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1957
+ | Action | Clauses lowered |
1958
+ | --- | --- |
1959
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1960
+ | `freeze` | `due`, `moves`, `steps`, `summary` |
1961
+ | `close` | `agent description`, `moves`, `steps`, `summary` |
1962
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1500
1963
  | `resolve` | `agent description`, `moves`, `steps`, `summary` |
1501
1964
 
1502
1965
  # held_payment
@@ -1509,22 +1972,122 @@ Source: [`std/money_flows/held_payment.hsx`](../../../std/money_flows/held_payme
1509
1972
 
1510
1973
  ## Parameters
1511
1974
 
1512
- - `payer: party`
1513
- - `payee: party`
1514
- - `amount: money<C>`
1515
- - `release: condition`
1516
- - `fees: optional<block>`
1517
- - `on_cancel: optional<block>`
1518
- - `derived_amount: optional<block>`
1519
- - `release_to: optional<party>`
1520
- - `whole_amount: optional<block>`
1521
- - `release_action: optional<text>`
1522
- - `whole_fee: optional<money<C>>`
1523
- - `reference: optional<text>`
1524
- - `upstream: optional<ref>`
1525
- - `id_prefix_override: optional<text>`
1526
- - `cancel_charge_bps: optional<integer>`
1527
- - `cancel_offer_life: optional<text>`
1975
+ | Parameter | Type | Required | Meaning |
1976
+ | --- | --- | --- | --- |
1977
+ | `payer` | `party` | Yes | The funding party providing the money. |
1978
+ | `payee` | `party` | Yes | The beneficiary party receiving the released funds. |
1979
+ | `amount` | `money<C>` | Yes | Total amount in minor units of currency `C`. |
1980
+ | `release` | `condition` | Yes | Condition required to release funds. Supports decision ports (`port <name>`), date deadlines (`at(<date>)`), or disjunctions (`port <name> &#124; at(<date>)`). |
1981
+ | `fees` | `optional<block>` | No | Optional block declaring percentage or fixed fee cuts, e.g. `{ buyer: 1%, seller: 2% }`. |
1982
+ | `on_cancel` | `optional<block>` | No | Optional block defining refund splits if cancelled while funded, e.g. `(funded) { buyer: 90%, seller: 10% }`. |
1983
+ | `derived_amount` | `optional<block>` | No | Optional block declaring machine-derived fees calculated as a percentage of another field. |
1984
+ | `release_to` | `optional<party>` | No | Optional third-party destination for release. |
1985
+ | `whole_amount` | `optional<block>` | No | Optional block enabling single-action funding and release of principal plus on-top fee. |
1986
+ | `release_action` | `optional<text>` | No | Optional custom name for the release action. |
1987
+ | `whole_fee` | `optional<money<C>>` | No | Optional money amount for the whole-amount fee. |
1988
+ | `reference` | `optional<text>` | No | Optional string reference stored on the instance. |
1989
+ | `upstream` | `optional<ref>` | No | Optional reference to a parent instrument. |
1990
+ | `id_prefix_override` | `optional<text>` | No | Optional custom prefix for generated instrument IDs. |
1991
+ | `cancel_charge_bps` | `optional<integer>` | No | Optional cancellation charge in basis points. Declaring it gives the settlement a quoted cancellation: `quote_cancellation` prices the charge and the refund and freezes both, `cancel` pays the refund to the payer, and `retain_cancellation_charge` pays the charge to the payee. A zero charge keeps the flow with a zero fee. |
1992
+ | `cancel_offer_life` | `optional<text>` | No | ISO 8601 duration a cancellation quote stays open, required with `cancel_charge_bps`. |
1993
+ | `private_actions` | `optional<boolean>` | No | Suppress automatic aliases. Publish chosen actions with `expose`. |
1994
+
1995
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
1996
+
1997
+ ## Module guidance
1998
+
1999
+ Escrow settlement holding funds from a payer before releasing to a payee upon a verified condition or deadline.
2000
+
2001
+ ### Purpose
2002
+
2003
+ `held_payment` holds customer funds in a dedicated product escrow account away from both payer and payee.
2004
+ It fits milestone-gated commerce, vehicle escrow, contractor holdbacks, and goods purchases where funds
2005
+ must remain reserved until delivery confirmation or inspection.
2006
+
2007
+ ### Selection guidance
2008
+
2009
+ - vs `cancellable_booking`: Both hold funds in custody and both can quote a cancellation before it is
2010
+ spent. `held_payment` quotes one flat charge declared by `cancel_charge_bps`, because it has no scheduled
2011
+ start to price against, and `on_cancel` remains the way to unwind it on static splits instead.
2012
+ Choose `cancellable_booking` when the charge must follow the time left before a scheduled start date.
2013
+ - vs `security_deposit`: `held_payment` releases or cancels the principal according to predefined splits.
2014
+ Choose `security_deposit` when the holder must assess damages and claim an arbitrary partial amount
2015
+ via a `decided amount` clause while returning the unspent remainder to the payer.
2016
+ - vs `swap`: `held_payment` is a one-way transfer from payer to payee. Choose `swap` for bilateral or
2017
+ multi-party atomic exchanges where all parties must fund their legs into escrow before simultaneous release.
2018
+ - vs `premium_forward`: Choose `premium_forward` for insurance premium collection requiring carrier policy
2019
+ binding conditions, broker commission retention, policy endorsements, and lapse schedules.
2020
+
2021
+ ### Parameters
2022
+
2023
+ - `payer`: The funding party providing the money.
2024
+ - `payee`: The beneficiary party receiving the released funds.
2025
+ - `amount`: Total amount in minor units of currency `C`.
2026
+ - `release`: Condition required to release funds. Supports decision ports (`port <name>`), date deadlines
2027
+ (`at(<date>)`), or disjunctions (`port <name> | at(<date>)`).
2028
+ - `fees`: Optional block declaring percentage or fixed fee cuts, e.g. `{ buyer: 1%, seller: 2% }`.
2029
+ - `on_cancel`: Optional block defining refund splits if cancelled while funded, e.g. `(funded) { buyer: 90%, seller: 10% }`.
2030
+ - `derived_amount`: Optional block declaring machine-derived fees calculated as a percentage of another field.
2031
+ - `release_to`: Optional third-party destination for release.
2032
+ - `whole_amount`: Optional block enabling single-action funding and release of principal plus on-top fee.
2033
+ - `release_action`: Optional custom name for the release action.
2034
+ - `whole_fee`: Optional money amount for the whole-amount fee.
2035
+ - `reference`: Optional string reference stored on the instance.
2036
+ - `upstream`: Optional reference to a parent instrument.
2037
+ - `id_prefix_override`: Optional custom prefix for generated instrument IDs.
2038
+ - `cancel_charge_bps`: Optional cancellation charge in basis points. Declaring it gives the settlement a
2039
+ quoted cancellation: `quote_cancellation` prices the charge and the refund and freezes both,
2040
+ `cancel` pays the refund to the payer, and `retain_cancellation_charge` pays the charge to the payee.
2041
+ A zero charge keeps the flow with a zero fee.
2042
+ - `cancel_offer_life`: ISO 8601 duration a cancellation quote stays open, required with `cancel_charge_bps`.
2043
+
2044
+ - `private_actions`: Suppress automatic aliases. Publish chosen actions with `expose`.
2045
+
2046
+ ### Decision ports
2047
+
2048
+ - `release`: Port deciding release authorization, answered by allowed parties declared in the port.
2049
+
2050
+ ### Example
2051
+
2052
+ ```hsx
2053
+ program held_payment_example "Held payment example"
2054
+ import { held_payment } from "std/money_flows"
2055
+ party buyer: person
2056
+ party seller: business
2057
+ settlement sale = held_payment {
2058
+ payer: buyer
2059
+ payee: seller
2060
+ amount: price: money(SAR)
2061
+ fees { buyer: 1% }
2062
+ on_cancel(funded) { buyer: 100% }
2063
+ release: port confirm_delivery | at(releaseDueAt)
2064
+ }
2065
+ port confirm_delivery { allowed: [buyer] }
2066
+ ```
2067
+
2068
+ ## Declared clauses
2069
+
2070
+ - `agent description`
2071
+ - `caller parked states`
2072
+ - `commit`
2073
+ - `deadline`
2074
+ - `description`
2075
+ - `distinct parties`
2076
+ - `due`
2077
+ - `event name`
2078
+ - `id prefix`
2079
+ - `input`
2080
+ - `moves`
2081
+ - `partitions`
2082
+ - `port`
2083
+ - `quote`
2084
+ - `requires drained`
2085
+ - `sandbox failure point`
2086
+ - `steps`
2087
+ - `summary`
2088
+ - `title`
2089
+
2090
+ 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.
1528
2091
 
1529
2092
  ## Decision ports
1530
2093
 
@@ -1532,44 +2095,44 @@ Source: [`std/money_flows/held_payment.hsx`](../../../std/money_flows/held_payme
1532
2095
 
1533
2096
  ## Actions and clauses
1534
2097
 
1535
- | Action | Clauses lowered |
1536
- | ---------------------------- | ------------------------------------------------------------------------------------------------------ |
1537
- | `fund_piece_2` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1538
- | `fund_piece_3` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1539
- | `collect_service_fee` | `agent description`, `moves`, `steps`, `summary` |
1540
- | `release_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1541
- | `release_piece_3` | `agent description`, `moves`, `steps`, `summary` |
1542
- | `refund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1543
- | `refund_piece_3` | `agent description`, `moves`, `steps`, `summary` |
1544
- | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
1545
- | `unfund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1546
- | `unfund_piece_3` | `agent description`, `moves`, `steps`, `summary` |
1547
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1548
- | `fund_piece_1` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1549
- | `release_name` | `agent description`, `deadline`, `input`, `moves`, `port`, `sandbox failure point`, `steps`, `summary` |
1550
- | `release_on_deadline` | `due`, `moves`, `steps`, `summary` |
1551
- | `cancel` | `agent description`, `deadline`, `moves`, `steps`, `summary` |
1552
- | `quote_cancellation` | `agent description`, `deadline`, `moves`, `quote`, `steps`, `summary` |
1553
- | `cancel` | `agent description`, `commit`, `deadline`, `moves`, `steps`, `summary` |
1554
- | `retain_cancellation_charge` | `agent description`, `moves`, `steps`, `summary` |
1555
- | `fund_piece_2` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1556
- | `release_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1557
- | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
1558
- | `fund_piece_2` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1559
- | `release_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1560
- | `refund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1561
- | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
1562
- | `abandon` | `agent description`, `moves`, `steps`, `summary` |
1563
- | `dispute` | `agent description`, `deadline`, `description`, `moves`, `steps`, `summary` |
1564
- | `resume` | `agent description`, `description`, `moves`, `steps`, `summary` |
1565
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1566
- | `fund` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1567
- | `release_action` | `agent description`, `deadline`, `moves`, `port`, `sandbox failure point`, `steps`, `summary` |
1568
- | `release_on_deadline` | `due`, `event name`, `moves`, `steps`, `summary` |
1569
- | `cancel` | `agent description`, `deadline`, `event name`, `moves`, `steps`, `summary` |
1570
- | `abandon` | `agent description`, `moves`, `steps`, `summary` |
1571
- | `dispute` | `agent description`, `deadline`, `description`, `moves`, `steps`, `summary` |
1572
- | `resume` | `agent description`, `description`, `moves`, `steps`, `summary` |
2098
+ | Action | Clauses lowered |
2099
+ | --- | --- |
2100
+ | `fund_piece_2` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
2101
+ | `fund_piece_3` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
2102
+ | `collect_service_fee` | `agent description`, `moves`, `steps`, `summary` |
2103
+ | `release_piece_2` | `agent description`, `moves`, `steps`, `summary` |
2104
+ | `release_piece_3` | `agent description`, `moves`, `steps`, `summary` |
2105
+ | `refund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
2106
+ | `refund_piece_3` | `agent description`, `moves`, `steps`, `summary` |
2107
+ | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
2108
+ | `unfund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
2109
+ | `unfund_piece_3` | `agent description`, `moves`, `steps`, `summary` |
2110
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
2111
+ | `fund_piece_1` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
2112
+ | `[release_name]` | `agent description`, `deadline`, `input`, `moves`, `port`, `sandbox failure point`, `steps`, `summary` |
2113
+ | `release_on_deadline` | `due`, `moves`, `steps`, `summary` |
2114
+ | `cancel` | `agent description`, `deadline`, `moves`, `steps`, `summary` |
2115
+ | `quote_cancellation` | `agent description`, `deadline`, `moves`, `quote`, `steps`, `summary` |
2116
+ | `cancel` | `agent description`, `commit`, `deadline`, `moves`, `steps`, `summary` |
2117
+ | `retain_cancellation_charge` | `agent description`, `moves`, `steps`, `summary` |
2118
+ | `fund_piece_2` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
2119
+ | `release_piece_2` | `agent description`, `moves`, `steps`, `summary` |
2120
+ | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
2121
+ | `fund_piece_2` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
2122
+ | `release_piece_2` | `agent description`, `moves`, `steps`, `summary` |
2123
+ | `refund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
2124
+ | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
2125
+ | `abandon` | `agent description`, `moves`, `steps`, `summary` |
2126
+ | `dispute` | `agent description`, `deadline`, `description`, `moves`, `steps`, `summary` |
2127
+ | `resume` | `agent description`, `description`, `moves`, `steps`, `summary` |
2128
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
2129
+ | `fund` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
2130
+ | `[release_action]` | `agent description`, `deadline`, `moves`, `port`, `sandbox failure point`, `steps`, `summary` |
2131
+ | `release_on_deadline` | `due`, `event name`, `moves`, `steps`, `summary` |
2132
+ | `cancel` | `agent description`, `deadline`, `event name`, `moves`, `steps`, `summary` |
2133
+ | `abandon` | `agent description`, `moves`, `requires drained`, `steps`, `summary` |
2134
+ | `dispute` | `agent description`, `deadline`, `description`, `moves`, `steps`, `summary` |
2135
+ | `resume` | `agent description`, `description`, `moves`, `steps`, `summary` |
1573
2136
 
1574
2137
  # instant_transfer
1575
2138
 
@@ -1581,11 +2144,78 @@ Source: [`std/money_flows/instant_transfer.hsx`](../../../std/money_flows/instan
1581
2144
 
1582
2145
  ## Parameters
1583
2146
 
1584
- - `payer: party`
1585
- - `payee: party`
1586
- - `amount: money<C>`
1587
- - `fees: optional<block>`
1588
- - `derived_amount: optional<block>`
2147
+ | Parameter | Type | Required | Meaning |
2148
+ | --- | --- | --- | --- |
2149
+ | `payer` | `party` | Yes | Funding party whose account is debited. |
2150
+ | `payee` | `party` | Yes | Recipient party whose account is credited. |
2151
+ | `amount` | `money<C>` | Yes | Transfer amount in minor units of currency `C`. |
2152
+ | `fees` | `optional<block>` | No | Optional fee configuration block specifying flat fees, percentage fees, or bracketed fee tiers for payer and/or payee. |
2153
+ | `derived_amount` | `optional<block>` | No | Optional block declaring derived platform fees calculated from the transfer amount. |
2154
+
2155
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
2156
+
2157
+ ## Module guidance
2158
+
2159
+ Direct, single-step push transfer from payer to payee with optional tiered or percentage fees.
2160
+
2161
+ ### Purpose
2162
+
2163
+ `instant_transfer` debits a payer and credits a payee immediately in a single execution step.
2164
+ It fits peer-to-peer transfers, direct disbursements, instant payouts, wallet reloads, and simple point-of-sale payments.
2165
+
2166
+ ### Selection guidance
2167
+
2168
+ - vs `captured_payment`: `instant_transfer` moves money in one atomic step without prior authorization holds,
2169
+ incremental captures, voids, or post-settlement correction ports. Use `captured_payment` when authorization must precede capture.
2170
+ - vs `conditional_disbursement`: `instant_transfer` executes immediately without external decision evidence
2171
+ or cumulative cap tracking. Use `conditional_disbursement` when payments require evidence submission or aggregate milestone caps.
2172
+ - vs `held_payment`: `instant_transfer` never holds funds in an intermediary escrow account.
2173
+
2174
+ ### Parameters
2175
+
2176
+ - `payer`: Funding party whose account is debited.
2177
+ - `payee`: Recipient party whose account is credited.
2178
+ - `amount`: Transfer amount in minor units of currency `C`.
2179
+ - `fees`: Optional fee configuration block specifying flat fees, percentage fees, or bracketed fee tiers for payer and/or payee.
2180
+ - `derived_amount`: Optional block declaring derived platform fees calculated from the transfer amount.
2181
+
2182
+ ### Decision ports
2183
+
2184
+ None. Transfers execute immediately upon invocation.
2185
+
2186
+ ### Example
2187
+
2188
+ ```hsx
2189
+ program instant_transfer_example "Instant transfer example"
2190
+ import { instant_transfer } from "std/money_flows"
2191
+ party customer: person
2192
+ party merchant: business
2193
+ settlement transfer = instant_transfer {
2194
+ payer: customer
2195
+ payee: merchant
2196
+ amount: transferAmount: money(SAR)
2197
+ fees {
2198
+ customer: checkoutFee: money(SAR)
2199
+ merchant {
2200
+ tier { from: 0, to: 10000, fee: 1% }
2201
+ tier { from: 10000, fee: highValueFee: money(SAR) }
2202
+ }
2203
+ }
2204
+ }
2205
+ ```
2206
+
2207
+ ## Declared clauses
2208
+
2209
+ - `agent description`
2210
+ - `description`
2211
+ - `moves`
2212
+ - `partitions`
2213
+ - `sandbox failure point`
2214
+ - `steps`
2215
+ - `summary`
2216
+ - `title`
2217
+
2218
+ 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.
1589
2219
 
1590
2220
  ## Decision ports
1591
2221
 
@@ -1593,12 +2223,12 @@ None.
1593
2223
 
1594
2224
  ## Actions and clauses
1595
2225
 
1596
- | Action | Clauses lowered |
1597
- | --------------------- | ------------------------------------------------------------------------- |
1598
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1599
- | `pay_piece_1` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1600
- | `pay_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1601
- | `collect_service_fee` | `agent description`, `moves`, `steps`, `summary` |
2226
+ | Action | Clauses lowered |
2227
+ | --- | --- |
2228
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
2229
+ | `pay_piece_1` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
2230
+ | `pay_piece_2` | `agent description`, `moves`, `steps`, `summary` |
2231
+ | `collect_service_fee` | `agent description`, `moves`, `steps`, `summary` |
1602
2232
 
1603
2233
  # metered
1604
2234
 
@@ -1610,10 +2240,71 @@ Source: [`std/money_flows/metered.hsx`](../../../std/money_flows/metered.hsx)
1610
2240
 
1611
2241
  ## Parameters
1612
2242
 
1613
- - `payer: party`
1614
- - `payee: party`
1615
- - `close_by: date`
1616
- - `rates: unknown`
2243
+ | Parameter | Type | Required | Meaning |
2244
+ | --- | --- | --- | --- |
2245
+ | `payer` | `party` | Yes | The customer being billed for usage. |
2246
+ | `payee` | `party` | Yes | The service provider receiving usage revenue. |
2247
+ | `close_by` | `date` | Yes | Date when the metering period closes, preventing further usage charges. |
2248
+ | `rates` | `unknown` | Yes | Block mapping rate metric names to their per-unit money prices committed at period open. |
2249
+
2250
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
2251
+
2252
+ ## Module guidance
2253
+
2254
+ Usage-based billing against a committed rate card over an open period until a stored close date.
2255
+
2256
+ ### Purpose
2257
+
2258
+ `metered` bills customers for variable resource consumption such as API requests, compute hours,
2259
+ storage gigabytes, or utility consumption. The rate card is fixed when the period opens, and individual
2260
+ usage events are charged incrementally until the billing period closes on `close_by`.
2261
+
2262
+ ### Selection guidance
2263
+
2264
+ - vs `scheduled`: `metered` charges variable amounts per event calculated from consumed units and committed
2265
+ rate card prices. `scheduled` executes transfers on fixed calendar recurrence intervals (`every`, `first_due`)
2266
+ with predetermined amounts or installments.
2267
+
2268
+ ### Parameters
2269
+
2270
+ - `payer`: The customer being billed for usage.
2271
+ - `payee`: The service provider receiving usage revenue.
2272
+ - `close_by`: Date when the metering period closes, preventing further usage charges.
2273
+ - `rates`: Block mapping rate metric names to their per-unit money prices committed at period open.
2274
+
2275
+ ### Decision ports
2276
+
2277
+ None. Charges are driven by caller billing actions and period closure.
2278
+
2279
+ ### Example
2280
+
2281
+ ```hsx
2282
+ program metered_example "Metered example"
2283
+ import { metered } from "std/money_flows"
2284
+ party customer: business
2285
+ party provider: business
2286
+ settlement usage = metered {
2287
+ payer: customer
2288
+ payee: provider
2289
+ close_by: periodEnd
2290
+ rates {
2291
+ api_call: callRate: money(SAR)
2292
+ storage_gib: storageRate: money(SAR)
2293
+ }
2294
+ }
2295
+ ```
2296
+
2297
+ ## Declared clauses
2298
+
2299
+ - `agent description`
2300
+ - `description`
2301
+ - `due`
2302
+ - `moves`
2303
+ - `steps`
2304
+ - `summary`
2305
+ - `title`
2306
+
2307
+ 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.
1617
2308
 
1618
2309
  ## Decision ports
1619
2310
 
@@ -1621,10 +2312,11 @@ None.
1621
2312
 
1622
2313
  ## Actions and clauses
1623
2314
 
1624
- | Action | Clauses lowered |
1625
- | -------------- | --------------------------------------- |
1626
- | `create` | `agent description`, `steps`, `summary` |
1627
- | `close_period` | `due`, `steps`, `summary` |
2315
+ | Action | Clauses lowered |
2316
+ | --- | --- |
2317
+ | `create` | `agent description`, `steps`, `summary` |
2318
+ | `charge_[item]` | `agent description`, `moves`, `steps`, `summary` |
2319
+ | `close_period` | `due`, `steps`, `summary` |
1628
2320
 
1629
2321
  # pooled_split
1630
2322
 
@@ -1636,10 +2328,77 @@ Source: [`std/money_flows/pooled_split.hsx`](../../../std/money_flows/pooled_spl
1636
2328
 
1637
2329
  ## Parameters
1638
2330
 
1639
- - `payer: party`
1640
- - `amount: money<C>`
1641
- - `payout_due: date`
1642
- - `split: block`
2331
+ | Parameter | Type | Required | Meaning |
2332
+ | --- | --- | --- | --- |
2333
+ | `payer` | `party` | Yes | The funding party providing the pooled amount. |
2334
+ | `amount` | `money<C>` | Yes | Total pooled amount in minor units of currency `C`. |
2335
+ | `payout_due` | `date` | Yes | Stored payout date when the pool distributes to all recipients. |
2336
+ | `split` | `block` | Yes | Block declaring each recipient's percentage share and `remainder_to` recipient for rounding remainders. |
2337
+
2338
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
2339
+
2340
+ ## Module guidance
2341
+
2342
+ Fixed multi-recipient revenue or period pool funded share-by-share and released automatically on a due date.
2343
+
2344
+ ### Purpose
2345
+
2346
+ `pooled_split` pools a period total from one payer and splits it across a fixed roster of recipients
2347
+ according to predetermined percentage shares (with integer division remainder assigned to `remainder_to`).
2348
+ Callers fund the pool share-by-share, and payouts disburse automatically to each recipient on `payout_due`.
2349
+
2350
+ ### Selection guidance
2351
+
2352
+ - vs `weighted_distribution`: `pooled_split` hardcodes a fixed set of recipients and static percentage shares
2353
+ directly in the contract. `weighted_distribution` handles dynamic recipient counts where arbitrary weights
2354
+ are recorded as child records and frozen via a snapshot port before distribution.
2355
+ - vs `settlement_batch`: `settlement_batch` aggregates multiple payments from many sources into one net payout.
2356
+ `pooled_split` takes one period total from one payer and partitions it out to multiple recipients.
2357
+
2358
+ ### Parameters
2359
+
2360
+ - `payer`: The funding party providing the pooled amount.
2361
+ - `amount`: Total pooled amount in minor units of currency `C`.
2362
+ - `payout_due`: Stored payout date when the pool distributes to all recipients.
2363
+ - `split`: Block declaring each recipient's percentage share and `remainder_to` recipient for rounding remainders.
2364
+
2365
+ ### Decision ports
2366
+
2367
+ None. Payout distribution triggers automatically from the stored `payout_due` date.
2368
+
2369
+ ### Example
2370
+
2371
+ ```hsx
2372
+ program pooled_split_example "Pooled split example"
2373
+ import { pooled_split } from "std/money_flows"
2374
+ party payer: business
2375
+ party first_recipient: business
2376
+ party second_recipient: business
2377
+ settlement pool = pooled_split {
2378
+ payer: payer
2379
+ amount: poolAmount: money(SAR)
2380
+ payout_due: payoutDueAt
2381
+ split {
2382
+ first_recipient: 60%
2383
+ second_recipient: 40%
2384
+ remainder_to: first_recipient
2385
+ }
2386
+ }
2387
+ ```
2388
+
2389
+ ## Declared clauses
2390
+
2391
+ - `agent description`
2392
+ - `description`
2393
+ - `due`
2394
+ - `id prefix`
2395
+ - `moves`
2396
+ - `partitions`
2397
+ - `steps`
2398
+ - `summary`
2399
+ - `title`
2400
+
2401
+ 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.
1643
2402
 
1644
2403
  ## Decision ports
1645
2404
 
@@ -1647,9 +2406,11 @@ None.
1647
2406
 
1648
2407
  ## Actions and clauses
1649
2408
 
1650
- | Action | Clauses lowered |
1651
- | -------- | ------------------------------------------------ |
2409
+ | Action | Clauses lowered |
2410
+ | --- | --- |
1652
2411
  | `create` | `agent description`, `moves`, `steps`, `summary` |
2412
+ | `fund_share_[index]` | `agent description`, `moves`, `steps`, `summary` |
2413
+ | `distribute_share_[index]` | `due`, `moves`, `steps`, `summary` |
1653
2414
 
1654
2415
  # premium_forward
1655
2416
 
@@ -1661,14 +2422,94 @@ Source: [`std/money_flows/premium_forward.hsx`](../../../std/money_flows/premium
1661
2422
 
1662
2423
  ## Parameters
1663
2424
 
1664
- - `payer: party`
1665
- - `carrier: party`
1666
- - `amount: money<C>`
1667
- - `bind: condition`
1668
- - `commission: percent`
1669
- - `policy_ref: optional<text>`
1670
- - `renewal_due: optional<date>`
1671
- - `endorsement: optional<condition>`
2425
+ | Parameter | Type | Required | Meaning |
2426
+ | --- | --- | --- | --- |
2427
+ | `payer` | `party` | Yes | The policyholder paying the insurance premium. |
2428
+ | `carrier` | `party` | Yes | The insurance carrier underwriting the policy. |
2429
+ | `amount` | `money<C>` | Yes | Total gross premium in minor units of currency `C`. |
2430
+ | `bind` | `condition` | Yes | Condition port triggering policy binding and premium forwarding. |
2431
+ | `commission` | `percent` | Yes | Platform commission percentage retained from the gross premium. |
2432
+ | `policy_ref` | `optional<text>` | No | Optional policy identifier string. |
2433
+ | `renewal_due` | `optional<date>` | No | Optional date anchor when the policy is due for renewal. |
2434
+ | `endorsement` | `optional<condition>` | No | Optional condition port for recording policy endorsements. |
2435
+
2436
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
2437
+
2438
+ ## Module guidance
2439
+
2440
+ Insurance premium escrow holding customer funds until policy binding, then partitioning net carrier premium and commission.
2441
+
2442
+ ### Purpose
2443
+
2444
+ `premium_forward` manages insurance premium collection, broker commission retention, and carrier remittance.
2445
+ A policyholder funds the premium into dedicated escrow. The funds remain held until the policy binds via the `bind` port.
2446
+ Upon binding, the gross premium is automatically partitioned: the platform fee/commission is retained, and the net
2447
+ balance forwards to the carrier. It also supports policy endorsements and renewal schedules.
2448
+
2449
+ ### Selection guidance
2450
+
2451
+ - vs `held_payment`: `premium_forward` is tailored for insurance lifecycles, featuring automatic commission splits
2452
+ upon binding and policy endorsement tracking. `held_payment` is general commercial escrow without insurance
2453
+ underwriting binding semantics or gross-to-net fee partitioning.
2454
+ - vs `conditional_disbursement`: `premium_forward` collects and forwards inbound policy premiums to carriers.
2455
+ `conditional_disbursement` pays outbound claim settlements to claimants against stored evidence.
2456
+
2457
+ ### Parameters
2458
+
2459
+ - `payer`: The policyholder paying the insurance premium.
2460
+ - `carrier`: The insurance carrier underwriting the policy.
2461
+ - `amount`: Total gross premium in minor units of currency `C`.
2462
+ - `bind`: Condition port triggering policy binding and premium forwarding.
2463
+ - `commission`: Platform commission percentage retained from the gross premium.
2464
+ - `policy_ref`: Optional policy identifier string.
2465
+ - `renewal_due`: Optional date anchor when the policy is due for renewal.
2466
+ - `endorsement`: Optional condition port for recording policy endorsements.
2467
+
2468
+ ### Decision ports
2469
+
2470
+ - `bind`: Port authorizing policy binding, triggering carrier payout and commission retention.
2471
+ - `endorsement`: Port allowing carrier endorsement evidence to be recorded.
2472
+
2473
+ ### Example
2474
+
2475
+ ```hsx
2476
+ program premium_forward_example "Premium forward example"
2477
+ import { premium_forward } from "std/money_flows"
2478
+ party policyholder: person
2479
+ party carrier: business
2480
+ settlement premium = premium_forward {
2481
+ payer: policyholder
2482
+ carrier: carrier
2483
+ amount: premiumAmount: money(SAR)
2484
+ commission: 2%
2485
+ bind: port bind_policy
2486
+ policy_ref: policyReference
2487
+ renewal_due: renewalDueAt
2488
+ endorsement: port record_endorsement
2489
+ }
2490
+ port bind_policy { allowed: [policyholder, carrier] }
2491
+ port record_endorsement {
2492
+ allowed: [carrier]
2493
+ shape: { evidenceReference: text }
2494
+ }
2495
+ ```
2496
+
2497
+ ## Declared clauses
2498
+
2499
+ - `agent description`
2500
+ - `capture input`
2501
+ - `description`
2502
+ - `due`
2503
+ - `input`
2504
+ - `moves`
2505
+ - `partitions`
2506
+ - `port`
2507
+ - `sandbox failure point`
2508
+ - `steps`
2509
+ - `summary`
2510
+ - `title`
2511
+
2512
+ 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.
1672
2513
 
1673
2514
  ## Decision ports
1674
2515
 
@@ -1677,17 +2518,17 @@ Source: [`std/money_flows/premium_forward.hsx`](../../../std/money_flows/premium
1677
2518
 
1678
2519
  ## Actions and clauses
1679
2520
 
1680
- | Action | Clauses lowered |
1681
- | ----------------- | ------------------------------------------------------------------------------------------ |
1682
- | `create` | `agent description`, `steps`, `summary` |
1683
- | `fund_piece_1` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1684
- | `fund_piece_2` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1685
- | `bind` | `agent description`, `input`, `moves`, `port`, `sandbox failure point`, `steps`, `summary` |
1686
- | `forward_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1687
- | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
1688
- | `abandon` | `agent description`, `steps`, `summary` |
1689
- | `endorsement` | `agent description`, `capture input`, `input`, `port`, `steps`, `summary` |
1690
- | `lapse` | `due`, `steps`, `summary` |
2521
+ | Action | Clauses lowered |
2522
+ | --- | --- |
2523
+ | `create` | `agent description`, `steps`, `summary` |
2524
+ | `fund_piece_1` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
2525
+ | `fund_piece_2` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
2526
+ | `[bind]` | `agent description`, `input`, `moves`, `port`, `sandbox failure point`, `steps`, `summary` |
2527
+ | `forward_piece_2` | `agent description`, `moves`, `steps`, `summary` |
2528
+ | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
2529
+ | `abandon` | `agent description`, `steps`, `summary` |
2530
+ | `[endorsement]` | `agent description`, `capture input`, `input`, `port`, `steps`, `summary` |
2531
+ | `lapse` | `due`, `steps`, `summary` |
1691
2532
 
1692
2533
  # reconciled_payout
1693
2534
 
@@ -1699,39 +2540,83 @@ Source: [`std/money_flows/reconciled_payout.hsx`](../../../std/money_flows/recon
1699
2540
 
1700
2541
  ## Parameters
1701
2542
 
1702
- - `payer: party`
1703
- - `beneficiary: party`
1704
- - `amount: money<C>`
1705
- - `beneficiary_ref: text`
1706
- - `settle_by: date`
1707
- - `matched_within: integer`
1708
- - `matched_ceiling: integer`
2543
+ | Parameter | Type | Required | Meaning |
2544
+ | --- | --- | --- | --- |
2545
+ | `payer` | `party` | Yes | The funding party providing the payout. |
2546
+ | `beneficiary` | `party` | Yes | The beneficiary party receiving the external payout. |
2547
+ | `amount` | `money<C>` | Yes | Instructed payout amount in minor units of currency `C`. |
2548
+ | `beneficiary_ref` | `text` | Yes | Registered external beneficiary ID for bank routing. |
2549
+ | `settle_by` | `date` | Yes | Cut-off date when unmatched expectation amounts become formal break records. |
2550
+ | `matched_within` | `integer` | Yes | Match tolerance window in basis points or minor units. |
2551
+ | `matched_ceiling` | `integer` | Yes | Maximum acceptable tolerance ceiling between instructed amount and settled debit. |
1709
2552
 
1710
- ## Decision ports
2553
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
1711
2554
 
1712
- None.
2555
+ ## Module guidance
1713
2556
 
1714
- ## Actions and clauses
2557
+ Outbound bank payout instruction with end-to-end reconciliation against external bank statement feeds.
1715
2558
 
1716
- | Action | Clauses lowered |
1717
- | ---------- | ---------------------------------------------------------- |
1718
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1719
- | `instruct` | `agent description`, `moves`, `payout`, `steps`, `summary` |
1720
- | `settle` | `due`, `moves`, `reconcile`, `steps`, `summary` |
1721
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1722
- | `carry` | `agent description`, `moves`, `steps`, `summary` |
2559
+ ### Purpose
1723
2560
 
1724
- # recurring_collection
2561
+ `reconciled_payout` manages high-assurance payouts to external suppliers, partners, or customers where payment
2562
+ is not complete until confirmed by bank statement data. An instruction is dispatched to the beneficiary and an expectation
2563
+ record is opened. Incoming statement debit lines match against the expectation within configurable tolerance thresholds
2564
+ (`matched_within`, `matched_ceiling`). If the statement debit does not match before `settle_by`, a formal break row is raised.
1725
2565
 
1726
- Source: [`std/money_flows/recurring_collection.hsx`](../../../std/money_flows/recurring_collection.hsx)
2566
+ ### Selection guidance
1727
2567
 
1728
- ## Export
2568
+ - vs `settlement_batch`: `reconciled_payout` executes and reconciles an individual bank payout instruction.
2569
+ `settlement_batch` aggregates periodic captures, fees, and signed adjustments to calculate a net payable batch.
2570
+ - vs `instant_transfer`: `instant_transfer` executes an immediate internal ledger transfer between platform accounts.
2571
+ `reconciled_payout` dispatches funds across external banking rails with reconciliation tolerances and break tracking.
1729
2572
 
1730
- `recurring_collection`
2573
+ ### Parameters
1731
2574
 
1732
- ## Parameters
2575
+ - `payer`: The funding party providing the payout.
2576
+ - `beneficiary`: The beneficiary party receiving the external payout.
2577
+ - `amount`: Instructed payout amount in minor units of currency `C`.
2578
+ - `beneficiary_ref`: Registered external beneficiary ID for bank routing.
2579
+ - `settle_by`: Cut-off date when unmatched expectation amounts become formal break records.
2580
+ - `matched_within`: Match tolerance window in basis points or minor units.
2581
+ - `matched_ceiling`: Maximum acceptable tolerance ceiling between instructed amount and settled debit.
2582
+
2583
+ ### Decision ports
2584
+
2585
+ None. Payout dispatch and settlement matching follow the declared schedule, bank statement lines, and tolerance rules.
2586
+
2587
+ ### Example
2588
+
2589
+ ```hsx
2590
+ program reconciled_payout_example "Reconciled payout example"
2591
+ import { reconciled_payout } from "std/money_flows"
2592
+ party treasury: business
2593
+ party supplier: business
2594
+ settlement supplier_payout = reconciled_payout {
2595
+ payer: treasury
2596
+ beneficiary: supplier
2597
+ amount: netPayable: money(SAR)
2598
+ beneficiary_ref: supplierBeneficiaryId
2599
+ settle_by: settleBy
2600
+ matched_within: 100
2601
+ matched_ceiling: 500
2602
+ }
2603
+ ```
1733
2604
 
1734
- - `marker: optional<text>`
2605
+ ## Declared clauses
2606
+
2607
+ - `agent description`
2608
+ - `description`
2609
+ - `dials`
2610
+ - `due`
2611
+ - `id prefix`
2612
+ - `moves`
2613
+ - `payout`
2614
+ - `reconcile`
2615
+ - `steps`
2616
+ - `summary`
2617
+ - `title`
2618
+
2619
+ 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.
1735
2620
 
1736
2621
  ## Decision ports
1737
2622
 
@@ -1739,11 +2624,13 @@ None.
1739
2624
 
1740
2625
  ## Actions and clauses
1741
2626
 
1742
- | Action | Clauses lowered |
1743
- | --------- | --------------------------------------- |
1744
- | `create` | `agent description`, `steps`, `summary` |
1745
- | `collect` | `agent description`, `steps`, `summary` |
1746
- | `end` | `agent description`, `steps`, `summary` |
2627
+ | Action | Clauses lowered |
2628
+ | --- | --- |
2629
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
2630
+ | `instruct` | `agent description`, `moves`, `payout`, `steps`, `summary` |
2631
+ | `settle` | `due`, `moves`, `reconcile`, `steps`, `summary` |
2632
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
2633
+ | `carry` | `agent description`, `moves`, `steps`, `summary` |
1747
2634
 
1748
2635
  # rotating_pool
1749
2636
 
@@ -1755,18 +2642,99 @@ Source: [`std/money_flows/rotating_pool.hsx`](../../../std/money_flows/rotating_
1755
2642
 
1756
2643
  ## Parameters
1757
2644
 
1758
- - `members: optional<list<party>>`
1759
- - `contribution: money<C>`
1760
- - `count: integer`
1761
- - `every: optional<text>`
1762
- - `first_due: date`
1763
- - `payout_order: optional<list<party>>`
1764
- - `default_policy: optional<text>`
1765
- - `guarantee_policy: optional<text>`
1766
- - `guarantor: optional<party>`
1767
- - `exit_policy: optional<text>`
1768
- - `memo: optional<text>`
1769
- - `membership: optional<block>`
2645
+ | Parameter | Type | Required | Meaning |
2646
+ | --- | --- | --- | --- |
2647
+ | `members` | `optional<list<party>>` | No | List of parties belonging to the rotating group. |
2648
+ | `contribution` | `money<C>` | Yes | Fixed contribution amount required from each member per cycle in minor units of currency `C`. |
2649
+ | `count` | `integer` | Yes | Total number of cycles in the rotation (matching the member count). |
2650
+ | `every` | `optional<text>` | No | Recurrence interval between contribution cycles (e.g. `"P30D"`). |
2651
+ | `first_due` | `date` | Yes | Due date for the first cycle's contribution. |
2652
+ | `payout_order` | `optional<list<party>>` | No | Ordered list of member parties defining the cycle payout sequence. |
2653
+ | `default_policy` | `optional<text>` | No | Policy for handling missed contributions (`due_condition`). |
2654
+ | `guarantee_policy` | `optional<text>` | No | Policy for backing defaulted contributions (`funded_only`). |
2655
+ | `guarantor` | `optional<party>` | No | Optional guarantor party covering member defaults. |
2656
+ | `exit_policy` | `optional<text>` | No | Policy governing member departures (`before_activation_only`). |
2657
+ | `memo` | `optional<text>` | No | Optional memo text stored on the pool. |
2658
+ | `membership` | `optional<block>` | No | Optional custom membership configuration block. |
2659
+
2660
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
2661
+
2662
+ ## Module guidance
2663
+
2664
+ Rotating savings and credit association (ROSCA) pool where members contribute fixed amounts and take turns receiving the pot.
2665
+
2666
+ ### Purpose
2667
+
2668
+ `rotating_pool` coordinates peer savings circles, chit funds, tandas, and committee savings groups.
2669
+ A fixed group of members contributes an identical contribution amount each cycle. In each cycle, one designated member
2670
+ receives the entire pooled pot according to a predefined `payout_order` until all members have taken their turn.
2671
+
2672
+ ### Selection guidance
2673
+
2674
+ - vs `threshold_pool`: `rotating_pool` coordinates recurring multi-party peer savings with rotating payouts.
2675
+ `threshold_pool` is all-or-nothing capital accumulation toward a single threshold for one beneficiary.
2676
+ - vs `scheduled`: `scheduled` coordinates a single payer to a single payee. `rotating_pool` orchestrates
2677
+ a closed circular group of members taking sequential turns.
2678
+
2679
+ ### Parameters
2680
+
2681
+ - `members`: List of parties belonging to the rotating group.
2682
+ - `contribution`: Fixed contribution amount required from each member per cycle in minor units of currency `C`.
2683
+ - `count`: Total number of cycles in the rotation (matching the member count).
2684
+ - `every`: Recurrence interval between contribution cycles (e.g. `"P30D"`).
2685
+ - `first_due`: Due date for the first cycle's contribution.
2686
+ - `payout_order`: Ordered list of member parties defining the cycle payout sequence.
2687
+ - `default_policy`: Policy for handling missed contributions (`due_condition`).
2688
+ - `guarantee_policy`: Policy for backing defaulted contributions (`funded_only`).
2689
+ - `guarantor`: Optional guarantor party covering member defaults.
2690
+ - `exit_policy`: Policy governing member departures (`before_activation_only`).
2691
+ - `memo`: Optional memo text stored on the pool.
2692
+ - `membership`: Optional custom membership configuration block.
2693
+
2694
+ ### Decision ports
2695
+
2696
+ None. Cycle advancement and pot payouts follow the declared schedule and membership actions.
2697
+
2698
+ ### Example
2699
+
2700
+ ```hsx
2701
+ program rotating_pool_example "Rotating pool example"
2702
+ import { rotating_pool } from "std/money_flows"
2703
+ party member_a: person
2704
+ party member_b: person
2705
+ party member_c: person
2706
+ party guarantor: business
2707
+ settlement pool = rotating_pool {
2708
+ members: [member_a, member_b, member_c]
2709
+ contribution: contributionAmount: money(SAR)
2710
+ count: 3
2711
+ every: P30D
2712
+ first_due: firstContributionAt
2713
+ payout_order: [member_b, member_c, member_a]
2714
+ default_policy: due_condition
2715
+ guarantee_policy: funded_only
2716
+ guarantor: guarantor
2717
+ exit_policy: before_activation_only
2718
+ }
2719
+ ```
2720
+
2721
+ ## Declared clauses
2722
+
2723
+ - `agent description`
2724
+ - `aggregate invariants`
2725
+ - `caller parked states`
2726
+ - `description`
2727
+ - `due`
2728
+ - `examples`
2729
+ - `id prefix`
2730
+ - `moves`
2731
+ - `sandbox failure point`
2732
+ - `steps`
2733
+ - `summary`
2734
+ - `title`
2735
+ - `unique`
2736
+
2737
+ 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.
1770
2738
 
1771
2739
  ## Decision ports
1772
2740
 
@@ -1774,17 +2742,24 @@ None.
1774
2742
 
1775
2743
  ## Actions and clauses
1776
2744
 
1777
- | Action | Clauses lowered |
1778
- | ---------- | ------------------------------------------------- |
1779
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1780
- | `cancel` | `agent description`, `moves`, `steps`, `summary` |
1781
- | `activate` | `agent description`, `moves`, `steps`, `summary` |
1782
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1783
- | `close` | `agent description`, `moves`, `steps`, `summary` |
1784
- | `create` | `agent description`, `examples`, `moves`, `steps` |
1785
- | `activate` | `due`, `examples`, `moves`, `steps` |
1786
- | `disband` | `agent description`, `examples`, `moves`, `steps` |
1787
- | `close` | `agent description`, `examples`, `moves`, `steps` |
2745
+ | Action | Clauses lowered |
2746
+ | --- | --- |
2747
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
2748
+ | `cancel` | `agent description`, `moves`, `steps`, `summary` |
2749
+ | `activate` | `agent description`, `moves`, `steps`, `summary` |
2750
+ | `ready_cycle_[cycle]` | `agent description`, `moves`, `steps`, `summary` |
2751
+ | `advance_cycle_[cycle]` | `agent description`, `moves`, `steps`, `summary` |
2752
+ | `create` | `agent description`, `moves`, `steps`, `summary`, `unique` |
2753
+ | `contribute_cycle_[cycle]` | `due`, `moves`, `sandbox failure point`, `steps`, `summary` |
2754
+ | `mark_default_cycle_[cycle]` | `due`, `moves`, `steps`, `summary` |
2755
+ | `guarantee_cycle_[cycle]` | `agent description`, `moves`, `steps`, `summary` |
2756
+ | `pay_cycle_[cycle]` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
2757
+ | `pay_guaranteed_cycle_[cycle]` | `agent description`, `moves`, `steps`, `summary` |
2758
+ | `close` | `agent description`, `moves`, `steps`, `summary` |
2759
+ | `create` | `agent description`, `examples`, `moves`, `steps` |
2760
+ | `activate` | `due`, `examples`, `moves`, `steps` |
2761
+ | `disband` | `agent description`, `examples`, `moves`, `steps` |
2762
+ | `close` | `agent description`, `examples`, `moves`, `steps` |
1788
2763
 
1789
2764
  # scheduled
1790
2765
 
@@ -1796,21 +2771,104 @@ Source: [`std/money_flows/scheduled.hsx`](../../../std/money_flows/scheduled.hsx
1796
2771
 
1797
2772
  ## Parameters
1798
2773
 
1799
- - `payer: party`
1800
- - `payee: party`
1801
- - `amount: money<C>`
1802
- - `count: optional<integer>`
1803
- - `every: text`
1804
- - `first_due: date`
1805
- - `mode: optional<text>`
1806
- - `debtor: optional<party>`
1807
- - `advance_to: optional<party>`
1808
- - `until: optional<condition>`
1809
- - `month_end: optional<text>`
1810
- - `period_liability: optional<text>`
1811
- - `termination_drain: optional<text>`
1812
- - `mandate: optional<condition>`
1813
- - `derived_amount: optional<unknown>`
2774
+ | Parameter | Type | Required | Meaning |
2775
+ | --- | --- | --- | --- |
2776
+ | `payer` | `party` | Yes | The paying party (or repayment source). |
2777
+ | `payee` | `party` | Yes | The beneficiary party receiving installment funds. |
2778
+ | `amount` | `money<C>` | Yes | Total amount to partition into installments or recurring charge amount in minor units of currency `C`. |
2779
+ | `count` | `optional<integer>` | No | Optional number of installments for installment or obligation modes. |
2780
+ | `every` | `text` | Yes | Recurrence cadence duration string (e.g. `"P30D"`, `"P1M"`). |
2781
+ | `first_due` | `date` | Yes | Stored date anchor for the first installment or charge. |
2782
+ | `mode` | `optional<text>` | No | Optional mode selector (`obligation`). Omit for standard installment plans. |
2783
+ | `debtor` | `optional<party>` | No | Optional debtor party when distinct from the payment source in obligation mode. |
2784
+ | `advance_to` | `optional<party>` | No | Optional third-party receiving upfront advance disbursements in obligation mode. |
2785
+ | `until` | `optional<condition>` | No | Optional condition port triggering cancellation of recurring subscription runs. |
2786
+ | `month_end` | `optional<text>` | No | Optional handling policy for calendar month-end adjustments. |
2787
+ | `period_liability` | `optional<text>` | No | Optional liability policy for billing periods. |
2788
+ | `termination_drain` | `optional<text>` | No | Optional policy for draining balances on early termination. |
2789
+ | `mandate` | `optional<condition>` | No | Optional condition port supplying formal debit mandate evidence. |
2790
+ | `derived_amount` | `optional<unknown>` | No | Optional calculated markup or fee rules. |
2791
+
2792
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
2793
+
2794
+ ## Module guidance
2795
+
2796
+ Calendar-anchored payments supporting fixed installment plans, recurring subscriptions, or debt obligations.
2797
+
2798
+ ### Purpose
2799
+
2800
+ `scheduled` automates time-anchored payment series between one payer and one payee.
2801
+ It supports three modes:
2802
+
2803
+ 1. Installment plan: Partitions a fixed total amount into `count` installments, each collected on its own stored date.
2804
+ 2. Open recurring subscription: Charges a recurring amount on an interval `every` until an `until` port fires.
2805
+ 3. Debt obligation: Manages legally binding multi-installment debt with delinquency tracking, mandate evidence, and child payment records.
2806
+
2807
+ ### Selection guidance
2808
+
2809
+ - vs `metered`: `scheduled` executes calendar-based recurring charges or fixed installment plans.
2810
+ `metered` bills variable usage per event based on a committed rate card.
2811
+ - vs `rotating_pool`: `scheduled` coordinates one payer to one payee on a calendar.
2812
+ `rotating_pool` coordinates a multi-party peer circle where members rotate turns receiving the entire pot.
2813
+
2814
+ ### Parameters
2815
+
2816
+ - `payer`: The paying party (or repayment source).
2817
+ - `payee`: The beneficiary party receiving installment funds.
2818
+ - `amount`: Total amount to partition into installments or recurring charge amount in minor units of currency `C`.
2819
+ - `count`: Optional number of installments for installment or obligation modes.
2820
+ - `every`: Recurrence cadence duration string (e.g. `"P30D"`, `"P1M"`).
2821
+ - `first_due`: Stored date anchor for the first installment or charge.
2822
+ - `mode`: Optional mode selector (`obligation`). Omit for standard installment plans.
2823
+ - `debtor`: Optional debtor party when distinct from the payment source in obligation mode.
2824
+ - `advance_to`: Optional third-party receiving upfront advance disbursements in obligation mode.
2825
+ - `until`: Optional condition port triggering cancellation of recurring subscription runs.
2826
+ - `month_end`: Optional handling policy for calendar month-end adjustments.
2827
+ - `period_liability`: Optional liability policy for billing periods.
2828
+ - `termination_drain`: Optional policy for draining balances on early termination.
2829
+ - `mandate`: Optional condition port supplying formal debit mandate evidence.
2830
+ - `derived_amount`: Optional calculated markup or fee rules.
2831
+
2832
+ ### Decision ports
2833
+
2834
+ - `until`: Port terminating recurring subscriptions.
2835
+ - `mandate`: Port supplying mandate verification evidence for direct debit obligations.
2836
+
2837
+ ### Example
2838
+
2839
+ ```hsx
2840
+ program scheduled_example "Scheduled example"
2841
+ import { scheduled } from "std/money_flows"
2842
+ party payer: business
2843
+ party payee: business
2844
+ settlement installments = scheduled {
2845
+ payer: payer
2846
+ payee: payee
2847
+ amount: totalAmount: money(SAR)
2848
+ count: 3
2849
+ every: P30D
2850
+ first_due: firstDueAt
2851
+ }
2852
+ ```
2853
+
2854
+ ## Declared clauses
2855
+
2856
+ - `agent description`
2857
+ - `aggregate invariants`
2858
+ - `capture input`
2859
+ - `description`
2860
+ - `due`
2861
+ - `input`
2862
+ - `moves`
2863
+ - `partitions`
2864
+ - `port`
2865
+ - `sandbox failure point`
2866
+ - `sets at`
2867
+ - `steps`
2868
+ - `summary`
2869
+ - `title`
2870
+
2871
+ 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.
1814
2872
 
1815
2873
  ## Decision ports
1816
2874
 
@@ -1819,22 +2877,24 @@ Source: [`std/money_flows/scheduled.hsx`](../../../std/money_flows/scheduled.hsx
1819
2877
 
1820
2878
  ## Actions and clauses
1821
2879
 
1822
- | Action | Clauses lowered |
1823
- | ------------------- | -------------------------------------------------------------------------------------------------------------------------- |
1824
- | `create` | `agent description`, `steps`, `summary` |
1825
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1826
- | `approve` | `agent description`, `steps`, `summary` |
1827
- | `advance` | `agent description`, `moves`, `steps`, `summary` |
1828
- | `delinquent_action` | `due`, `sets at`, `steps`, `summary` |
1829
- | `complete` | `due`, `steps`, `summary` |
1830
- | `write_off` | `agent description`, `steps`, `summary` |
1831
- | `create` | `agent description`, `steps`, `summary` |
1832
- | `repay` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1833
- | `refund` | `agent description`, `moves`, `steps`, `summary` |
1834
- | `create` | `agent description`, `steps`, `summary` |
1835
- | `open_period` | `due`, `steps`, `summary` |
1836
- | `collect_period` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `sandbox failure point`, `steps`, `summary` |
1837
- | `until` | `agent description`, `capture input`, `input`, `port`, `steps`, `summary` |
2880
+ | Action | Clauses lowered |
2881
+ | --- | --- |
2882
+ | `create` | `agent description`, `steps`, `summary` |
2883
+ | `pay_installment_[i]` | `due`, `moves`, `sandbox failure point`, `steps`, `summary` |
2884
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
2885
+ | `approve` | `agent description`, `steps`, `summary` |
2886
+ | `advance` | `agent description`, `moves`, `steps`, `summary` |
2887
+ | `collect_installment_[i]` | `due`, `steps`, `summary` |
2888
+ | `[delinquent_action]` | `due`, `sets at`, `steps`, `summary` |
2889
+ | `complete` | `due`, `steps`, `summary` |
2890
+ | `write_off` | `agent description`, `steps`, `summary` |
2891
+ | `create` | `agent description`, `steps`, `summary` |
2892
+ | `repay` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
2893
+ | `refund` | `agent description`, `moves`, `steps`, `summary` |
2894
+ | `create` | `agent description`, `steps`, `summary` |
2895
+ | `open_period` | `due`, `steps`, `summary` |
2896
+ | `collect_period` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `sandbox failure point`, `steps`, `summary` |
2897
+ | `[until]` | `agent description`, `capture input`, `input`, `port`, `steps`, `summary` |
1838
2898
 
1839
2899
  # security_deposit
1840
2900
 
@@ -1846,20 +2906,112 @@ Source: [`std/money_flows/security_deposit.hsx`](../../../std/money_flows/securi
1846
2906
 
1847
2907
  ## Parameters
1848
2908
 
1849
- - `payer: party`
1850
- - `holder: party`
1851
- - `amount: money<C>`
1852
- - `claim: optional<condition>`
1853
- - `return: optional<condition>`
1854
- - `claim_amount: optional<block>`
1855
- - `deadline: optional<date>`
1856
- - `claim_to: optional<party>`
1857
- - `return_to: optional<party>`
1858
- - `memo: optional<text>`
1859
- - `claim_input: optional<block>`
1860
- - `claim_capture: optional<block>`
1861
- - `fund_failure_point: optional<text>`
1862
- - `id_prefix_override: optional<text>`
2909
+ | Parameter | Type | Required | Meaning |
2910
+ | --- | --- | --- | --- |
2911
+ | `payer` | `party` | Yes | The customer providing the deposit collateral. |
2912
+ | `holder` | `party` | Yes | The merchant or owner holding the deposit rights. |
2913
+ | `amount` | `money<C>` | Yes | Total reserved deposit amount in minor units of currency `C`. |
2914
+ | `claim` | `optional<condition>` | No | Optional condition port triggering a damage claim. |
2915
+ | `return` | `optional<condition>` | No | Optional condition port triggering full return of the deposit. |
2916
+ | `claim_amount` | `optional<block>` | No | Optional block defining partial claim logic (`field`, `bound`, `remainder`). |
2917
+ | `deadline` | `optional<date>` | No | Optional stored date anchor for automatic deposit release or expiry. |
2918
+ | `claim_to` | `optional<party>` | No | Optional alternate destination for claimed funds. |
2919
+ | `return_to` | `optional<party>` | No | Optional alternate destination for returned funds. |
2920
+ | `memo` | `optional<text>` | No | Optional memo text stored on the deposit record. |
2921
+ | `claim_input` | `optional<block>` | No | Optional custom input schema for the claim action. |
2922
+ | `claim_capture` | `optional<block>` | No | Optional capture mappings for claim evidence. |
2923
+ | `fund_failure_point` | `optional<text>` | No | Optional configuration for deposit funding failure. |
2924
+ | `id_prefix_override` | `optional<text>` | No | Optional custom prefix for generated instrument IDs. |
2925
+
2926
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
2927
+
2928
+ ## Module guidance
2929
+
2930
+ Collateral deposit reserved against a payer's account in favor of a holder, returned in full or claimed against damages.
2931
+
2932
+ ### Purpose
2933
+
2934
+ `security_deposit` reserves collateral funds for vehicle rentals, property leasing, equipment hire, and security bonds.
2935
+ Funds remain held until the rental or lease concludes. The holder can either return the deposit in full
2936
+ or assess damages, claim a decided partial amount, and return the exact unspent remainder.
2937
+
2938
+ ### Selection guidance
2939
+
2940
+ - vs `held_payment`: `security_deposit` holds collateral where the standard outcome is returning 100% of the funds
2941
+ to the payer, and claims are partial damage assessments. `held_payment` holds payment consideration where the
2942
+ standard outcome is releasing 100% of the funds to the payee upon delivery.
2943
+ - vs `cancellable_booking`: `cancellable_booking` holds booking fees and applies time-based cancellation penalties.
2944
+ `security_deposit` holds damage collateral and supports arbitrary damage claims with remainder refund.
2945
+
2946
+ ### Parameters
2947
+
2948
+ - `payer`: The customer providing the deposit collateral.
2949
+ - `holder`: The merchant or owner holding the deposit rights.
2950
+ - `amount`: Total reserved deposit amount in minor units of currency `C`.
2951
+ - `claim`: Optional condition port triggering a damage claim.
2952
+ - `return`: Optional condition port triggering full return of the deposit.
2953
+ - `claim_amount`: Optional block defining partial claim logic (`field`, `bound`, `remainder`).
2954
+ - `deadline`: Optional stored date anchor for automatic deposit release or expiry.
2955
+ - `claim_to`: Optional alternate destination for claimed funds.
2956
+ - `return_to`: Optional alternate destination for returned funds.
2957
+ - `memo`: Optional memo text stored on the deposit record.
2958
+ - `claim_input`: Optional custom input schema for the claim action.
2959
+ - `claim_capture`: Optional capture mappings for claim evidence.
2960
+ - `fund_failure_point`: Optional configuration for deposit funding failure.
2961
+ - `id_prefix_override`: Optional custom prefix for generated instrument IDs.
2962
+
2963
+ ### Decision ports
2964
+
2965
+ - `claim`: Port permitting the holder to submit a damage claim.
2966
+ - `return`: Port permitting the holder to return the deposit to the payer.
2967
+
2968
+ ### Example
2969
+
2970
+ ```hsx
2971
+ program deposit_example "Deposit example"
2972
+ import { security_deposit } from "std/money_flows"
2973
+ party renter: person
2974
+ party owner: business
2975
+ settlement security_deposit = security_deposit {
2976
+ payer: renter
2977
+ holder: owner
2978
+ amount: depositAmount: money(SAR)
2979
+ claim: port assess_damage
2980
+ claim_amount: decided {
2981
+ field: damageAmount
2982
+ bound: depositAmount
2983
+ remainder: return
2984
+ }
2985
+ return: port return_deposit
2986
+ }
2987
+ port assess_damage {
2988
+ allowed: [owner]
2989
+ shape: { damageAmount: money(SAR), evidence: text }
2990
+ }
2991
+ port return_deposit { allowed: [owner] }
2992
+ ```
2993
+
2994
+ ## Declared clauses
2995
+
2996
+ - `agent description`
2997
+ - `caller parked states`
2998
+ - `capture input`
2999
+ - `deadline`
3000
+ - `decided amount`
3001
+ - `description`
3002
+ - `dials`
3003
+ - `distinct parties`
3004
+ - `due`
3005
+ - `id prefix`
3006
+ - `input`
3007
+ - `moves`
3008
+ - `port`
3009
+ - `sandbox failure point`
3010
+ - `steps`
3011
+ - `summary`
3012
+ - `title`
3013
+
3014
+ 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.
1863
3015
 
1864
3016
  ## Decision ports
1865
3017
 
@@ -1868,18 +3020,18 @@ Source: [`std/money_flows/security_deposit.hsx`](../../../std/money_flows/securi
1868
3020
 
1869
3021
  ## Actions and clauses
1870
3022
 
1871
- | Action | Clauses lowered |
1872
- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
1873
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1874
- | `place_deposit` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1875
- | `claim_name` | `agent description`, `input`, `moves`, `port`, `steps`, `summary` |
1876
- | `return_name` | `agent description`, `capture input`, `input`, `moves`, `port`, `steps`, `summary` |
1877
- | `create` | `agent description`, `deadline`, `moves`, `steps`, `summary` |
1878
- | `fund` | `agent description`, `deadline`, `moves`, `sandbox failure point`, `steps`, `summary` |
1879
- | `claim` | `agent description`, `capture input`, `deadline`, `decided amount`, `input`, `moves`, `port`, `sandbox failure point`, `steps`, `summary` |
1880
- | `return` | `agent description`, `deadline`, `moves`, `port`, `steps`, `summary` |
1881
- | `expire` | `due`, `moves`, `steps`, `summary` |
1882
- | `cancel` | `agent description`, `moves`, `steps`, `summary` |
3023
+ | Action | Clauses lowered |
3024
+ | --- | --- |
3025
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
3026
+ | `place_deposit` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
3027
+ | `[claim_name]` | `agent description`, `input`, `moves`, `port`, `steps`, `summary` |
3028
+ | `[return_name]` | `agent description`, `capture input`, `input`, `moves`, `port`, `steps`, `summary` |
3029
+ | `create` | `agent description`, `deadline`, `moves`, `steps`, `summary` |
3030
+ | `fund` | `agent description`, `deadline`, `moves`, `sandbox failure point`, `steps`, `summary` |
3031
+ | `claim` | `agent description`, `capture input`, `deadline`, `decided amount`, `input`, `moves`, `port`, `sandbox failure point`, `steps`, `summary` |
3032
+ | `return` | `agent description`, `deadline`, `moves`, `port`, `steps`, `summary` |
3033
+ | `expire` | `due`, `moves`, `steps`, `summary` |
3034
+ | `cancel` | `agent description`, `moves`, `steps`, `summary` |
1883
3035
 
1884
3036
  # settlement_batch
1885
3037
 
@@ -1891,15 +3043,96 @@ Source: [`std/money_flows/settlement_batch.hsx`](../../../std/money_flows/settle
1891
3043
 
1892
3044
  ## Parameters
1893
3045
 
1894
- - `settlement_account: party`
1895
- - `source_capture_refs: text`
1896
- - `fee_entries: text`
1897
- - `external_reversal_offsets: text`
1898
- - `close_trigger: date`
1899
- - `payout_destination: party`
1900
- - `negative_position: text`
1901
- - `payout_acknowledgement: condition`
1902
- - `payout_beneficiary_ref: text`
3046
+ | Parameter | Type | Required | Meaning |
3047
+ | --- | --- | --- | --- |
3048
+ | `settlement_account` | `party` | Yes | The source clearing account holding captured funds and paying the batch. |
3049
+ | `source_capture_refs` | `text` | Yes | Binding name for gross capture references included in the batch. |
3050
+ | `fee_entries` | `text` | Yes | Binding name for fee deductions applied to the batch. |
3051
+ | `external_reversal_offsets` | `text` | Yes | Binding name for reversal adjustments applied to the batch. |
3052
+ | `close_trigger` | `date` | Yes | Date when the batch closes and ceases accepting new transaction entries. |
3053
+ | `payout_destination` | `party` | Yes | The merchant or partner account receiving the net payout. |
3054
+ | `negative_position` | `text` | Yes | Policy when calculated net payable is zero or negative (`reject`). |
3055
+ | `payout_acknowledgement` | `condition` | Yes | Condition port confirming bank receipt of the payout. |
3056
+ | `payout_beneficiary_ref` | `text` | Yes | Beneficiary identifier for external bank dispatch. |
3057
+
3058
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
3059
+
3060
+ ## Module guidance
3061
+
3062
+ Periodic aggregation of capture lineage, fee entries, and adjustments into a single net calculated payout.
3063
+
3064
+ ### Purpose
3065
+
3066
+ `settlement_batch` settles merchant balances, marketplace vendor earnings, and partner clearing accounts.
3067
+ Individual payment captures, platform fees, and reversal adjustments accumulate into an open batch over a period.
3068
+ On `close_trigger`, the batch freezes. The platform calculates the signed net payable from gross captures plus credit
3069
+ adjustments minus debit adjustments. If positive, an outbound bank payout is instructed and acknowledged.
3070
+
3071
+ ### Selection guidance
3072
+
3073
+ - vs `reconciled_payout`: `settlement_batch` aggregates multiple transactions and adjustments over a billing cycle
3074
+ to compute a single net payable. `reconciled_payout` manages bank instruction dispatch and statement line reconciliation
3075
+ for an individual payout amount.
3076
+ - vs `weighted_distribution`: `settlement_batch` consolidates many inbound transactions into one net outbound payout.
3077
+ `weighted_distribution` splits one funding pool into many recipient payouts.
3078
+
3079
+ ### Parameters
3080
+
3081
+ - `settlement_account`: The source clearing account holding captured funds and paying the batch.
3082
+ - `source_capture_refs`: Binding name for gross capture references included in the batch.
3083
+ - `fee_entries`: Binding name for fee deductions applied to the batch.
3084
+ - `external_reversal_offsets`: Binding name for reversal adjustments applied to the batch.
3085
+ - `close_trigger`: Date when the batch closes and ceases accepting new transaction entries.
3086
+ - `payout_destination`: The merchant or partner account receiving the net payout.
3087
+ - `negative_position`: Policy when calculated net payable is zero or negative (`reject`).
3088
+ - `payout_acknowledgement`: Condition port confirming bank receipt of the payout.
3089
+ - `payout_beneficiary_ref`: Beneficiary identifier for external bank dispatch.
3090
+
3091
+ ### Decision ports
3092
+
3093
+ - `payout_acknowledgement`: Port recording external bank or partner receipt confirmation.
3094
+
3095
+ ### Example
3096
+
3097
+ ```hsx
3098
+ program settlement_batch_example "Settlement batch example"
3099
+ import { settlement_batch } from "std/money_flows"
3100
+ party settlement_account: business
3101
+ party payout_destination: business
3102
+ settlement batch = settlement_batch {
3103
+ settlement_account: settlement_account
3104
+ source_capture_refs: captureReference
3105
+ fee_entries: feeReference
3106
+ external_reversal_offsets: reversalReference
3107
+ close_trigger: closeAt
3108
+ payout_destination: payout_destination
3109
+ negative_position: reject
3110
+ payout_acknowledgement: port acknowledge_payout
3111
+ payout_beneficiary_ref: payoutBeneficiaryId
3112
+ }
3113
+ port acknowledge_payout {
3114
+ allowed: [payout_destination]
3115
+ shape: { acknowledgementReference: text }
3116
+ }
3117
+ ```
3118
+
3119
+ ## Declared clauses
3120
+
3121
+ - `agent description`
3122
+ - `capture input`
3123
+ - `description`
3124
+ - `due`
3125
+ - `id prefix`
3126
+ - `input`
3127
+ - `moves`
3128
+ - `payout`
3129
+ - `port`
3130
+ - `reconcile`
3131
+ - `steps`
3132
+ - `summary`
3133
+ - `title`
3134
+
3135
+ 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.
1903
3136
 
1904
3137
  ## Decision ports
1905
3138
 
@@ -1907,20 +3140,20 @@ Source: [`std/money_flows/settlement_batch.hsx`](../../../std/money_flows/settle
1907
3140
 
1908
3141
  ## Actions and clauses
1909
3142
 
1910
- | Action | Clauses lowered |
1911
- | ------------------------ | ------------------------------------------------------------------------------------------------- |
1912
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1913
- | `close` | `due`, `moves`, `steps`, `summary` |
1914
- | `calculate` | `agent description`, `computes signed_sum`, `moves`, `steps`, `summary` |
1915
- | `approve` | `agent description`, `moves`, `steps`, `summary` |
1916
- | `instruct` | `agent description`, `moves`, `payout`, `steps`, `summary` |
1917
- | `payout_acknowledgement` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1918
- | `reconcile` | `due`, `moves`, `reconcile`, `steps`, `summary` |
1919
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1920
- | `accrue` | `agent description`, `moves`, `steps`, `summary` |
1921
- | `create` | `agent description`, `moves`, `steps`, `summary` |
1922
- | `adjust` | `agent description`, `moves`, `steps`, `summary` |
1923
- | `correct` | `agent description`, `moves`, `steps`, `summary` |
3143
+ | Action | Clauses lowered |
3144
+ | --- | --- |
3145
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
3146
+ | `close` | `due`, `moves`, `steps`, `summary` |
3147
+ | `calculate` | `agent description`, `moves`, `steps`, `summary` |
3148
+ | `approve` | `agent description`, `moves`, `steps`, `summary` |
3149
+ | `instruct` | `agent description`, `moves`, `payout`, `steps`, `summary` |
3150
+ | `[payout_acknowledgement]` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
3151
+ | `reconcile` | `due`, `moves`, `reconcile`, `steps`, `summary` |
3152
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
3153
+ | `accrue` | `agent description`, `moves`, `steps`, `summary` |
3154
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
3155
+ | `adjust` | `agent description`, `moves`, `steps`, `summary` |
3156
+ | `correct` | `agent description`, `moves`, `steps`, `summary` |
1924
3157
 
1925
3158
  # swap
1926
3159
 
@@ -1932,16 +3165,103 @@ Source: [`std/money_flows/swap.hsx`](../../../std/money_flows/swap.hsx)
1932
3165
 
1933
3166
  ## Parameters
1934
3167
 
1935
- - `between: list<party>`
1936
- - `amounts: block`
1937
- - `fees: block`
1938
- - `release: condition`
1939
- - `dispute: condition`
1940
- - `side_names: optional<block>`
1941
- - `lifecycle_state_order: optional<list<text>>`
1942
- - `action_bindings: optional<block>`
1943
- - `parked_states: optional<block>`
1944
- - `fixed_prefix: optional<text>`
3168
+ | Parameter | Type | Required | Meaning |
3169
+ | --- | --- | --- | --- |
3170
+ | `between` | `list<party>` | Yes | List containing exactly two trade participant parties (`[side_a, side_b]`). |
3171
+ | `amounts` | `block` | Yes | Block declaring the principal money amounts for each party. |
3172
+ | `fees` | `block` | Yes | Block declaring the platform fee money amounts for each party. |
3173
+ | `release` | `condition` | Yes | Condition port required to execute the atomic swap release. |
3174
+ | `dispute` | `condition` | Yes | Condition port triggering unwinding and refunding of both trade legs. |
3175
+ | `side_names` | `optional<block>` | No | Optional custom naming block for the two sides (`first`, `second`). |
3176
+ | `lifecycle_state_order` | `optional<list<text>>` | No | Optional custom ordering for lifecycle states. |
3177
+ | `action_bindings` | `optional<block>` | No | Optional custom action names. |
3178
+ | `parked_states` | `optional<block>` | No | Optional configuration for parked states. |
3179
+ | `fixed_prefix` | `optional<text>` | No | Optional custom prefix for generated instrument IDs. |
3180
+
3181
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
3182
+
3183
+ ## Module guidance
3184
+
3185
+ Atomic two-sided trade between two parties where neither leg settles alone.
3186
+
3187
+ ### Purpose
3188
+
3189
+ `swap` executes atomic delivery-versus-payment (DvP) or payment-versus-payment (PvP) exchanges between two named parties.
3190
+ Both sides fund their declared principal amounts and platform fees into a shared escrow. The exchange settles atomically
3191
+ upon triggering the `release` condition port, paying each party the other's funded amount. If a `dispute` occurs,
3192
+ both legs unwind and refund simultaneously. Half-funded or half-released states cannot occur.
3193
+
3194
+ ### Selection guidance
3195
+
3196
+ - vs `held_payment`: `swap` is a bilateral trade where both sides must deposit funds into escrow and receive each other's
3197
+ disbursements simultaneously. `held_payment` is unilateral escrow where a single payer funds a payment held for a payee.
3198
+ - vs `instant_transfer`: `instant_transfer` executes an immediate one-way transfer. `swap` coordinates two reciprocal transfers
3199
+ held atomically in escrow until release confirmation.
3200
+
3201
+ ### Parameters
3202
+
3203
+ - `between`: List containing exactly two trade participant parties (`[side_a, side_b]`).
3204
+ - `amounts`: Block declaring the principal money amounts for each party.
3205
+ - `fees`: Block declaring the platform fee money amounts for each party.
3206
+ - `release`: Condition port required to execute the atomic swap release.
3207
+ - `dispute`: Condition port triggering unwinding and refunding of both trade legs.
3208
+ - `side_names`: Optional custom naming block for the two sides (`first`, `second`).
3209
+ - `lifecycle_state_order`: Optional custom ordering for lifecycle states.
3210
+ - `action_bindings`: Optional custom action names.
3211
+ - `parked_states`: Optional configuration for parked states.
3212
+ - `fixed_prefix`: Optional custom prefix for generated instrument IDs.
3213
+
3214
+ ### Decision ports
3215
+
3216
+ - `release`: Port authorizing atomic settlement of both trade legs.
3217
+ - `dispute`: Port triggering atomic cancellation and refund of both parties.
3218
+
3219
+ ### Example
3220
+
3221
+ ```hsx
3222
+ program swap_example "Swap example"
3223
+ import { swap } from "std/money_flows"
3224
+ party buyer: business
3225
+ party seller: business
3226
+ settlement exchange = swap {
3227
+ between: [buyer, seller]
3228
+ amounts {
3229
+ buyer: buyerAmount: money(SAR)
3230
+ seller: sellerAmount: money(SAR)
3231
+ }
3232
+ fees {
3233
+ buyer: buyerFee: money(SAR)
3234
+ seller: sellerFee: money(SAR)
3235
+ }
3236
+ release: port release_exchange
3237
+ dispute: port dispute_exchange within P7D
3238
+ }
3239
+ port release_exchange { allowed: [buyer, seller] }
3240
+ port dispute_exchange { allowed: [buyer, seller] }
3241
+ ```
3242
+
3243
+ ## Declared clauses
3244
+
3245
+ - `agent description`
3246
+ - `caller parked states`
3247
+ - `capture input`
3248
+ - `deadline`
3249
+ - `description`
3250
+ - `distinct parties`
3251
+ - `due`
3252
+ - `event name`
3253
+ - `id prefix`
3254
+ - `input`
3255
+ - `moves`
3256
+ - `port`
3257
+ - `public action`
3258
+ - `sandbox failure point`
3259
+ - `sets at`
3260
+ - `steps`
3261
+ - `summary`
3262
+ - `title`
3263
+
3264
+ 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.
1945
3265
 
1946
3266
  ## Decision ports
1947
3267
 
@@ -1950,22 +3270,22 @@ Source: [`std/money_flows/swap.hsx`](../../../std/money_flows/swap.hsx)
1950
3270
 
1951
3271
  ## Actions and clauses
1952
3272
 
1953
- | Action | Clauses lowered |
1954
- | --------- | ----------------------------------------------------------------------------------------------------------------------------- |
1955
- | `abandon` | `agent description`, `moves`, `public action`, `steps`, `summary` |
1956
- | `cancel` | `agent description`, `moves`, `public action`, `steps`, `summary` |
1957
- | `create` | `agent description`, `moves`, `public action`, `steps`, `summary` |
1958
- | `dispute` | `agent description`, `capture input`, `deadline`, `input`, `moves`, `port`, `public action`, `steps`, `summary` |
1959
- | `fund` | `agent description`, `moves`, `public action`, `sandbox failure point`, `steps`, `summary` |
1960
- | `post` | `due`, `moves`, `steps`, `summary` |
1961
- | `release` | `agent description`, `moves`, `port`, `public action`, `sandbox failure point`, `sets at`, `steps`, `summary` |
1962
- | `create` | `agent description`, `moves`, `public action`, `steps`, `summary` |
1963
- | `fund` | `agent description`, `event name`, `moves`, `public action`, `sandbox failure point`, `steps`, `summary` |
1964
- | `release` | `agent description`, `event name`, `moves`, `port`, `public action`, `sandbox failure point`, `sets at`, `steps`, `summary` |
1965
- | `post` | `due`, `event name`, `moves`, `steps`, `summary` |
3273
+ | Action | Clauses lowered |
3274
+ | --- | --- |
3275
+ | `abandon` | `agent description`, `moves`, `public action`, `steps`, `summary` |
3276
+ | `cancel` | `agent description`, `moves`, `public action`, `steps`, `summary` |
3277
+ | `create` | `agent description`, `moves`, `public action`, `steps`, `summary` |
3278
+ | `dispute` | `agent description`, `capture input`, `deadline`, `input`, `moves`, `port`, `public action`, `steps`, `summary` |
3279
+ | `fund` | `agent description`, `moves`, `public action`, `sandbox failure point`, `steps`, `summary` |
3280
+ | `post` | `due`, `moves`, `steps`, `summary` |
3281
+ | `release` | `agent description`, `moves`, `port`, `public action`, `sandbox failure point`, `sets at`, `steps`, `summary` |
3282
+ | `create` | `agent description`, `moves`, `public action`, `steps`, `summary` |
3283
+ | `fund` | `agent description`, `event name`, `moves`, `public action`, `sandbox failure point`, `steps`, `summary` |
3284
+ | `release` | `agent description`, `event name`, `moves`, `port`, `public action`, `sandbox failure point`, `sets at`, `steps`, `summary` |
3285
+ | `post` | `due`, `event name`, `moves`, `steps`, `summary` |
1966
3286
  | `dispute` | `agent description`, `capture input`, `deadline`, `event name`, `input`, `moves`, `port`, `public action`, `steps`, `summary` |
1967
- | `cancel` | `agent description`, `event name`, `moves`, `public action`, `steps`, `summary` |
1968
- | `abandon` | `agent description`, `event name`, `moves`, `public action`, `steps`, `summary` |
3287
+ | `cancel` | `agent description`, `event name`, `moves`, `public action`, `steps`, `summary` |
3288
+ | `abandon` | `agent description`, `event name`, `moves`, `public action`, `steps`, `summary` |
1969
3289
 
1970
3290
  # threshold_pool
1971
3291
 
@@ -1977,20 +3297,111 @@ Source: [`std/money_flows/threshold_pool.hsx`](../../../std/money_flows/threshol
1977
3297
 
1978
3298
  ## Parameters
1979
3299
 
1980
- - `contributor: optional<party>`
1981
- - `beneficiary: optional<party>`
1982
- - `target: money<C>`
1983
- - `commitment: money<C>`
1984
- - `max_contributors: optional<integer>`
1985
- - `close_by: date`
1986
- - `close_policy: optional<text>`
1987
- - `overfund_policy: optional<text>`
1988
- - `cancel_policy: optional<text>`
1989
- - `fail_policy: optional<text>`
1990
- - `beneficiary_account: optional<account<C>>`
1991
- - `memo: optional<text>`
1992
- - `contribution_instrument: optional<block>`
1993
- - `wording: optional<block>`
3300
+ | Parameter | Type | Required | Meaning |
3301
+ | --- | --- | --- | --- |
3302
+ | `contributor` | `optional<party>` | No | The party representing individual contributors. |
3303
+ | `beneficiary` | `optional<party>` | No | The beneficiary party receiving the settled pool if the target is met. |
3304
+ | `target` | `money<C>` | Yes | Total target funding threshold in minor units of currency `C`. |
3305
+ | `commitment` | `money<C>` | Yes | Binding name for individual contributor commitment amounts. |
3306
+ | `max_contributors` | `optional<integer>` | No | Optional maximum count of admitted contributors. |
3307
+ | `close_by` | `date` | Yes | Stored date deadline by which the target must be met. |
3308
+ | `close_policy` | `optional<text>` | No | Policy determining pool close behavior (`threshold`). |
3309
+ | `overfund_policy` | `optional<text>` | No | Policy on commitments exceeding the target (`reject`). |
3310
+ | `cancel_policy` | `optional<text>` | No | Contributor withdrawal policy before close (`before_close`). |
3311
+ | `fail_policy` | `optional<text>` | No | Refund policy if the pool fails to hit target (`whole_commitment_refund`). |
3312
+ | `beneficiary_account` | `optional<account<C>>` | No | Optional direct account reference for the beneficiary. |
3313
+ | `memo` | `optional<text>` | No | Optional memo text stored on the pool. |
3314
+ | `contribution_instrument` | `optional<block>` | No | Optional custom contribution child instrument block. |
3315
+ | `wording` | `optional<block>` | No | Optional custom UI wording block. |
3316
+ | `funding_join` | `optional<block>` | No | funding_join configures the flat contribution-instrument mode for a priced obligation. |
3317
+
3318
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
3319
+
3320
+ ## Module guidance
3321
+
3322
+ All-or-nothing capital accumulation pool collecting commitments toward a target amount before a close deadline.
3323
+
3324
+ ### Purpose
3325
+
3326
+ `threshold_pool` powers all-or-nothing crowdfunding, capital calls, collective purchasing, and consortium rounds.
3327
+ Multiple contributors pledge commitments toward a monetary `target`. Commitments sit in escrow until the pool
3328
+ reaches the target before `close_by` (activating and settling funds to the beneficiary), or fails (triggering full refunds).
3329
+
3330
+ ### Selection guidance
3331
+
3332
+ - vs `rotating_pool`: `threshold_pool` is all-or-nothing fundraising where many contributors fund a single beneficiary.
3333
+ `rotating_pool` is a peer savings circle where members contribute identically in each cycle and rotate who receives the pot.
3334
+ - vs `weighted_distribution`: `threshold_pool` pools funds inward from many contributors to one beneficiary.
3335
+ `weighted_distribution` pays funds outward from one source pool to many weighted recipients.
3336
+
3337
+ ### Parameters
3338
+
3339
+ - `contributor`: The party representing individual contributors.
3340
+ - `beneficiary`: The beneficiary party receiving the settled pool if the target is met.
3341
+ - `target`: Total target funding threshold in minor units of currency `C`.
3342
+ - `commitment`: Binding name for individual contributor commitment amounts.
3343
+ - `max_contributors`: Optional maximum count of admitted contributors.
3344
+ - `close_by`: Stored date deadline by which the target must be met.
3345
+ - `close_policy`: Policy determining pool close behavior (`threshold`).
3346
+ - `overfund_policy`: Policy on commitments exceeding the target (`reject`).
3347
+ - `cancel_policy`: Contributor withdrawal policy before close (`before_close`).
3348
+ - `fail_policy`: Refund policy if the pool fails to hit target (`whole_commitment_refund`).
3349
+ - `beneficiary_account`: Optional direct account reference for the beneficiary.
3350
+ - `memo`: Optional memo text stored on the pool.
3351
+ - `contribution_instrument`: Optional custom contribution child instrument block.
3352
+ - `wording`: Optional custom UI wording block.
3353
+
3354
+ ### Decision ports
3355
+
3356
+ None. Lifecycle transitions (`activate`, `fail`, `close`) are driven by target threshold evaluation and the `close_by` date.
3357
+
3358
+ ### Example
3359
+
3360
+ ```hsx
3361
+ program capital_pool_example "Capital pool example"
3362
+ import { threshold_pool } from "std/money_flows"
3363
+ party contributor: person
3364
+ party company: business
3365
+ settlement round = threshold_pool {
3366
+ contributor: contributor
3367
+ beneficiary: company
3368
+ target: targetAmount: money(SAR)
3369
+ commitment: commitmentAmount: money(SAR)
3370
+ max_contributors: 100
3371
+ close_by: closeBy
3372
+ close_policy: threshold
3373
+ overfund_policy: reject
3374
+ cancel_policy: before_close
3375
+ fail_policy: whole_commitment_refund
3376
+ }
3377
+ ```
3378
+
3379
+ ### Funding join
3380
+
3381
+ funding_join configures the flat contribution-instrument mode for a priced
3382
+ obligation. Opening freezes minimum ticket, investor cap, profit and schedule
3383
+ terms. Closing binds the obligation, freezes committed ticket identities and
3384
+ moves the principal once into its funding account. A ticket's engine-owned
3385
+ collection action has no independent payment or clock trigger.
3386
+
3387
+ ## Declared clauses
3388
+
3389
+ - `agent description`
3390
+ - `aggregate invariants`
3391
+ - `caller parked states`
3392
+ - `description`
3393
+ - `due`
3394
+ - `examples`
3395
+ - `funding`
3396
+ - `id prefix`
3397
+ - `input`
3398
+ - `moves`
3399
+ - `steps`
3400
+ - `summary`
3401
+ - `title`
3402
+ - `updates`
3403
+
3404
+ 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.
1994
3405
 
1995
3406
  ## Decision ports
1996
3407
 
@@ -1998,20 +3409,20 @@ None.
1998
3409
 
1999
3410
  ## Actions and clauses
2000
3411
 
2001
- | Action | Clauses lowered |
2002
- | ---------- | ------------------------------------------------- |
2003
- | `create` | `agent description`, `moves`, `steps`, `summary` |
2004
- | `activate` | `due`, `moves`, `steps`, `summary` |
2005
- | `fail` | `due`, `moves`, `steps`, `summary` |
2006
- | `close` | `agent description`, `moves`, `steps`, `summary` |
2007
- | `create` | `agent description`, `moves`, `steps`, `summary` |
2008
- | `cancel` | `agent description`, `moves`, `steps`, `summary` |
2009
- | `collect` | `agent description`, `moves`, `steps`, `summary` |
2010
- | `refund` | `agent description`, `moves`, `steps`, `summary` |
2011
- | `create` | `agent description`, `examples`, `moves`, `steps` |
2012
- | `activate` | `due`, `examples`, `moves`, `steps` |
2013
- | `fail` | `due`, `examples`, `moves`, `steps` |
2014
- | `close` | `agent description`, `examples`, `moves`, `steps` |
3412
+ | Action | Clauses lowered |
3413
+ | --- | --- |
3414
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
3415
+ | `activate` | `due`, `moves`, `steps`, `summary` |
3416
+ | `fail` | `due`, `moves`, `steps`, `summary` |
3417
+ | `close` | `agent description`, `moves`, `steps`, `summary` |
3418
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
3419
+ | `cancel` | `agent description`, `moves`, `steps`, `summary` |
3420
+ | `collect` | `agent description`, `moves`, `steps`, `summary` |
3421
+ | `refund` | `agent description`, `moves`, `steps`, `summary` |
3422
+ | `create` | `agent description`, `examples`, `moves`, `steps` |
3423
+ | `activate` | `due`, `examples`, `moves`, `steps` |
3424
+ | `fail` | `due`, `examples`, `moves`, `steps` |
3425
+ | `close` | `agent description`, `examples`, `funding`, `input`, `moves`, `steps`, `updates` |
2015
3426
 
2016
3427
  # weighted_distribution
2017
3428
 
@@ -2023,18 +3434,113 @@ Source: [`std/money_flows/weighted_distribution.hsx`](../../../std/money_flows/w
2023
3434
 
2024
3435
  ## Parameters
2025
3436
 
2026
- - `source: party`
2027
- - `recipient: party`
2028
- - `amount: money<C>`
2029
- - `record_at: date`
2030
- - `weight: optional<money<C>>`
2031
- - `max_recipients: optional<integer>`
2032
- - `snapshot: optional<condition>`
2033
- - `rounding_policy: optional<text>`
2034
- - `withholding_policy: optional<text>`
2035
- - `correction_policy: optional<text>`
2036
- - `flat: optional<block>`
2037
- - `id_prefix_override: optional<text>`
3437
+ | Parameter | Type | Required | Meaning |
3438
+ | --- | --- | --- | --- |
3439
+ | `source` | `optional<party>` | No | The funding party providing the distribution pool. |
3440
+ | `recipient` | `optional<party>` | No | The party representing entitled recipients. |
3441
+ | `amount` | `optional<money<C>>` | No | Total distribution pool in minor units of currency `C`. |
3442
+ | `record_at` | `optional<date>` | No | Date when entitlement eligibility is established. |
3443
+ | `weight` | `optional<money<C>>` | No | Binding name for individual recipient weight amounts. |
3444
+ | `max_recipients` | `optional<integer>` | No | Exact number of entitlement rows required before snapshotting. |
3445
+ | `snapshot` | `optional<condition>` | No | Port freezing the entitlement set against stored decision evidence. |
3446
+ | `rounding_policy` | `optional<text>` | No | Mathematical rounding policy (`largest_remainder`). |
3447
+ | `withholding_policy` | `optional<text>` | No | Tax or withholding policy (`refuse`). |
3448
+ | `correction_policy` | `optional<text>` | No | Error correction policy (`new_distribution`). |
3449
+ | `flat` | `optional<block>` | No | Optional flat distribution configuration block. |
3450
+ | `receipts` | `optional<block>` | No | receipts selects repeated distributions from immutable allocation receipts. |
3451
+ | `id_prefix_override` | `optional<text>` | No | Optional custom prefix for generated instrument IDs. |
3452
+
3453
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
3454
+
3455
+ ## Module guidance
3456
+
3457
+ Frozen largest-remainder distribution splitting one pool across dynamic recipients by recorded weights.
3458
+
3459
+ ### Purpose
3460
+
3461
+ `weighted_distribution` distributes dividend pools, creator royalties, liquidation proceeds, and investment returns.
3462
+ Child entitlement rows are recorded for each recipient with their respective weight. Once all recipients are recorded,
3463
+ an evidence-backed snapshot freezes the entitlement set. Each recipient is then paid their exact largest-remainder
3464
+ share such that all payouts sum exactly to `amount` without rounding leaks.
3465
+
3466
+ ### Selection guidance
3467
+
3468
+ - vs `pooled_split`: `weighted_distribution` handles dynamic recipient rosters recorded as child rows and frozen
3469
+ via snapshot. `pooled_split` hardcodes a fixed set of recipients and static percentages at definition time.
3470
+ - vs `settlement_batch`: `weighted_distribution` splits one funding pool out to many recipients.
3471
+ `settlement_batch` aggregates many inbound charges and adjustments into a single net payout.
3472
+
3473
+ ### Parameters
3474
+
3475
+ - `source`: The funding party providing the distribution pool.
3476
+ - `recipient`: The party representing entitled recipients.
3477
+ - `amount`: Total distribution pool in minor units of currency `C`.
3478
+ - `record_at`: Date when entitlement eligibility is established.
3479
+ - `weight`: Binding name for individual recipient weight amounts.
3480
+ - `max_recipients`: Exact number of entitlement rows required before snapshotting.
3481
+ - `snapshot`: Port freezing the entitlement set against stored decision evidence.
3482
+ - `rounding_policy`: Mathematical rounding policy (`largest_remainder`).
3483
+ - `withholding_policy`: Tax or withholding policy (`refuse`).
3484
+ - `correction_policy`: Error correction policy (`new_distribution`).
3485
+ - `flat`: Optional flat distribution configuration block.
3486
+ - `id_prefix_override`: Optional custom prefix for generated instrument IDs.
3487
+
3488
+ ### Decision ports
3489
+
3490
+ - `snapshot`: Port freezing the entitlement set with an evidence reference, preventing further entries.
3491
+
3492
+ ### Example
3493
+
3494
+ ```hsx
3495
+ program weighted_distribution_example "Weighted distribution example"
3496
+ import { weighted_distribution } from "std/money_flows"
3497
+ party distribution_source: business
3498
+ party recipient: business
3499
+ settlement proceeds = weighted_distribution {
3500
+ source: distribution_source
3501
+ recipient: recipient
3502
+ amount: distributableAmount: money(SAR)
3503
+ weight: entitlementWeight: money(SAR)
3504
+ max_recipients: 12
3505
+ record_at: recordAt
3506
+ snapshot: port snapshot_entitlements
3507
+ rounding_policy: largest_remainder
3508
+ withholding_policy: refuse
3509
+ correction_policy: new_distribution
3510
+ }
3511
+ port snapshot_entitlements {
3512
+ allowed: [distribution_source]
3513
+ shape: { evidenceReference: text }
3514
+ }
3515
+ ```
3516
+
3517
+ ### Receipt-backed distributions
3518
+
3519
+ receipts selects repeated distributions from immutable allocation receipts.
3520
+ It names round, receipt, path, mode (cash or loss), fee_bps and vat_bps.
3521
+ The funding snapshot owns ticket weights and original wallet destinations.
3522
+ Cash floors each ratio after fee and fee VAT; a named account receives residual.
3523
+ Loss assigns principal by largest remainder without cash, fee or VAT.
3524
+ Each receipt is consumed once; a new receipt may fund a new distribution record.
3525
+ This mode does not use caller-entered weights or a once-only settled principal pool.
3526
+
3527
+ ## Declared clauses
3528
+
3529
+ - `agent description`
3530
+ - `aggregate invariants`
3531
+ - `capture input`
3532
+ - `description`
3533
+ - `due`
3534
+ - `id prefix`
3535
+ - `input`
3536
+ - `moves`
3537
+ - `port`
3538
+ - `requires refs`
3539
+ - `steps`
3540
+ - `summary`
3541
+ - `title`
3542
+
3543
+ 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.
2038
3544
 
2039
3545
  ## Decision ports
2040
3546
 
@@ -2042,42 +3548,43 @@ Source: [`std/money_flows/weighted_distribution.hsx`](../../../std/money_flows/w
2042
3548
 
2043
3549
  ## Actions and clauses
2044
3550
 
2045
- | Action | Clauses lowered |
2046
- | ---------- | ------------------------------------------------------------------------------------------------- |
2047
- | `create` | `agent description`, `moves`, `steps`, `summary` |
2048
- | `snapshot` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
2049
- | `create` | `agent description`, `moves`, `steps`, `summary` |
2050
- | `payout` | `agent description`, `computes distribute`, `moves`, `steps`, `summary` |
2051
- | `create` | `agent description`, `moves`, `requires refs`, `steps`, `summary` |
2052
- | `payout` | `computes distribute`, `due`, `moves`, `steps`, `summary` |
3551
+ | Action | Clauses lowered |
3552
+ | --- | --- |
3553
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
3554
+ | `[snapshot]` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
3555
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
3556
+ | `payout` | `agent description`, `moves`, `steps`, `summary` |
3557
+ | `create` | `agent description`, `moves`, `requires refs`, `steps`, `summary` |
3558
+ | `payout` | `due`, `moves`, `steps`, `summary` |
3559
+ | `create` | `agent description`, `steps` |
2053
3560
 
2054
3561
  # Types
2055
3562
 
2056
3563
  HSX checks types before it emits UDL. Money and account values carry a currency parameter, and no implicit currency conversion exists.
2057
3564
 
2058
- | Kind | Meaning |
2059
- | ----------- | -------------------------------------------------------------------- |
2060
- | `account` | A currency-indexed ledger account reference. |
2061
- | `boolean` | A compile-time or stored true or false value. |
2062
- | `bps` | An integer basis-point value. |
2063
- | `condition` | A declared decision port. |
2064
- | `date` | A stored date-time string checked by UDL. |
2065
- | `integer` | A bounded whole number. |
2066
- | `money` | A currency-indexed minor-unit amount. |
2067
- | `party` | A declared program party. |
2068
- | `percent` | An exact percentage with basis-point precision. |
2069
- | `ref` | A typed reference to another instrument. |
2070
- | `text` | A finite string value. |
2071
- | `unknown` | An internal checker result that source must resolve before lowering. |
3565
+ | Kind | Meaning |
3566
+ | --- | --- |
3567
+ | `account` | A currency-indexed ledger account reference. |
3568
+ | `boolean` | A compile-time or stored true or false value. |
3569
+ | `bps` | An integer basis-point value. |
3570
+ | `condition` | A declared decision port. |
3571
+ | `date` | A stored date-time string checked by UDL. |
3572
+ | `integer` | A bounded whole number. |
3573
+ | `money` | A currency-indexed minor-unit amount. |
3574
+ | `party` | A declared program party. |
3575
+ | `percent` | An exact percentage with basis-point precision. |
3576
+ | `ref` | A typed reference to another instrument. |
3577
+ | `text` | A finite string value. |
3578
+ | `unknown` | An internal checker result that source must resolve before lowering. |
2072
3579
 
2073
3580
  # UDL output
2074
3581
 
2075
3582
  An accepted compile returns three artifacts.
2076
3583
 
2077
- | Artifact | Contents |
2078
- | -------------- | ----------------------------------------------------------------------------------- |
2079
- | `document` | The canonical UDL object. Serialize it with `serializeUdl` from `@hyperscale0/udl`. |
2080
- | `originMap` | Canonical UDL paths mapped to authored HSX spans. |
2081
- | `costManifest` | The deterministic manifest pinned to the supplied rate card. |
3584
+ | Artifact | Contents |
3585
+ | --- | --- |
3586
+ | `document` | The canonical UDL object. Serialize it with `serializeUdl` from `@hyperscale0/udl`. |
3587
+ | `originMap` | Canonical UDL paths mapped to authored HSX spans. |
3588
+ | `costManifest` | The deterministic manifest pinned to the supplied rate card. |
2082
3589
 
2083
3590
  Canonical UDL sorts object keys, preserves array order, uses two-space JSON indentation, and ends with one line feed.