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