@hyperscale0/hsx 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -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 +8 -2
- package/docs/guide/01-first-program.md +1 -1
- package/docs/guide/06-schedules.md +5 -1
- package/docs/guide/08-writing-a-module.md +48 -0
- package/docs/llms-full.txt +1928 -421
- package/docs/llms.txt +2 -3
- package/docs/piece-plans.md +120 -0
- 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 +15 -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.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<!-- Generated by scripts/docs/build.ts for HSX 2.
|
|
1
|
+
<!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
|
|
2
2
|
|
|
3
3
|
# HSX documentation
|
|
4
4
|
|
|
5
|
-
> Repository guide and generated compiler reference for HSX 2.
|
|
5
|
+
> Repository guide and generated compiler reference for HSX 2.2.0.
|
|
6
6
|
|
|
7
7
|
## Guide
|
|
8
8
|
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
[pooled_split](reference/std/pooled_split.md): Standard-library module.
|
|
36
36
|
[premium_forward](reference/std/premium_forward.md): Standard-library module.
|
|
37
37
|
[reconciled_payout](reference/std/reconciled_payout.md): Standard-library module.
|
|
38
|
-
[recurring_collection](reference/std/recurring_collection.md): Standard-library module.
|
|
39
38
|
[rotating_pool](reference/std/rotating_pool.md): Standard-library module.
|
|
40
39
|
[scheduled](reference/std/scheduled.md): Standard-library module.
|
|
41
40
|
[security_deposit](reference/std/security_deposit.md): Standard-library module.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Compose actions over a piece plan
|
|
2
|
+
|
|
3
|
+
Use `piece_plan` to declare a finite partition and `piece_stage` to select a
|
|
4
|
+
stage of that plan. Use `calls` and `action_library` to share the transfer
|
|
5
|
+
body. These are ordinary clauses; they do not add another HSX grammar or a
|
|
6
|
+
public operation for each private leaf.
|
|
7
|
+
|
|
8
|
+
The clause shapes are defined by the selected UDL vocabulary. HSX checks them
|
|
9
|
+
in [`typecheck.ts`](../src/typecheck.ts) and preserves them in
|
|
10
|
+
[`emit.ts`](../src/emit.ts). The round-trip and private-module examples in
|
|
11
|
+
[`general-language.spec.ts`](../test/general-language.spec.ts) exercise this
|
|
12
|
+
path. The [UDL output reference](reference/udl-output.md) describes the emitted ABI.
|
|
13
|
+
|
|
14
|
+
## Worked sale example
|
|
15
|
+
|
|
16
|
+
This excerpt uses the sale settlement's `price` plan and funding call. It
|
|
17
|
+
belongs inside an instrument that declares the referenced immutable fields,
|
|
18
|
+
its lifecycle, its partition and its escrow-account capture. It is not a
|
|
19
|
+
standalone program. The three money fields partition `price` exactly. For
|
|
20
|
+
example, SAR minor-unit amounts `245000`, `3750` and `1250` sum to `250000`.
|
|
21
|
+
The separate service fee is outside that partition.
|
|
22
|
+
|
|
23
|
+
```hsx
|
|
24
|
+
piece_plan: {
|
|
25
|
+
id: "price";
|
|
26
|
+
total: "price";
|
|
27
|
+
pieces: [
|
|
28
|
+
{ id: "seller"; amount: "piece1Amount";
|
|
29
|
+
release_to: "sellerAccountId"; refund_to: "buyerAccountId"; },
|
|
30
|
+
{ id: "platform_fee"; amount: "piece2Amount";
|
|
31
|
+
release_to: "platformAccountId"; refund_to: "buyerAccountId"; },
|
|
32
|
+
{ id: "seller_cancel_fee"; amount: "piece3Amount";
|
|
33
|
+
release_to: "platformAccountId"; refund_to: "sellerAccountId"; }
|
|
34
|
+
];
|
|
35
|
+
fund_order: ["seller", "platform_fee", "seller_cancel_fee"];
|
|
36
|
+
release_order: ["platform_fee", "seller_cancel_fee"];
|
|
37
|
+
refund_order: ["platform_fee", "seller_cancel_fee"];
|
|
38
|
+
unfund_order: ["seller_cancel_fee", "platform_fee", "seller"];
|
|
39
|
+
};
|
|
40
|
+
action_library: {
|
|
41
|
+
settlement_piece: {
|
|
42
|
+
actionOrder: ["move"];
|
|
43
|
+
actions: {
|
|
44
|
+
move: {
|
|
45
|
+
parameters: {
|
|
46
|
+
piece: { kind: "piece"; };
|
|
47
|
+
source: { kind: "account"; };
|
|
48
|
+
destination: { kind: "account"; };
|
|
49
|
+
};
|
|
50
|
+
principal: "api_key";
|
|
51
|
+
approval: "inherit";
|
|
52
|
+
recovery: "local";
|
|
53
|
+
order: ["transfer"];
|
|
54
|
+
calls: [];
|
|
55
|
+
leaves: [{
|
|
56
|
+
id: "transfer";
|
|
57
|
+
operation: "internal_transfer.create";
|
|
58
|
+
bind: {
|
|
59
|
+
amount: "$piece.amount";
|
|
60
|
+
currency: "$piece.currency";
|
|
61
|
+
sourceAccountId: "$source";
|
|
62
|
+
destinationAccountId: "$destination";
|
|
63
|
+
};
|
|
64
|
+
effects: [{ kind: "moves"; signature: "moves.transfer.internal"; }];
|
|
65
|
+
evidence: "transferId";
|
|
66
|
+
}];
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
action fund_piece {
|
|
72
|
+
public: none;
|
|
73
|
+
piece_stage: { plan: "price"; stage: "fund"; };
|
|
74
|
+
calls: [{
|
|
75
|
+
id: "move_piece";
|
|
76
|
+
action: "settlement_piece.move";
|
|
77
|
+
bind: {
|
|
78
|
+
piece: "$piece";
|
|
79
|
+
source: "$fields.buyerAccountId";
|
|
80
|
+
destination: "$instance.refs.escrowAccountId";
|
|
81
|
+
};
|
|
82
|
+
}];
|
|
83
|
+
steps: [];
|
|
84
|
+
summary: "Fund a piece of a sale settlement";
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The compiler derives `pieceId` from `fund_order`; callers cannot override the
|
|
89
|
+
piece amount or destination. The call binds the buyer and captured escrow
|
|
90
|
+
account into the one transfer leaf. The stage itself adds no movement.
|
|
91
|
+
`public: none` leaves program exposure explicit. Canonical UDL keeps the plan,
|
|
92
|
+
library, calls and action order, while resolved plans carry the expanded leaves
|
|
93
|
+
and their origin paths. An ordinary exported module value can supply the same
|
|
94
|
+
library without publishing another instrument.
|
|
95
|
+
|
|
96
|
+
For the cancellation path, the same private action binds its destination to
|
|
97
|
+
`$piece.refund_to`. `platform_fee` returns to the buyer; `seller_cancel_fee`
|
|
98
|
+
pays the seller. Unfund instead binds the buyer for every funded piece, in
|
|
99
|
+
reverse order. Handover, cancellation and service-fee collection remain
|
|
100
|
+
separate declared actions; a piece plan does not combine their decisions.
|
|
101
|
+
|
|
102
|
+
## Refusals to understand
|
|
103
|
+
|
|
104
|
+
UDL diagnostics retain their codes through HSX diagnostic provenance.
|
|
105
|
+
[`diagnostics.ts`](../src/diagnostics.ts) owns the HSX mapping, and
|
|
106
|
+
[`general-language.spec.ts`](../test/general-language.spec.ts) checks that fatal
|
|
107
|
+
UDL codes survive it.
|
|
108
|
+
|
|
109
|
+
| UDL code | Meaning for this example | Repair |
|
|
110
|
+
| --------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
|
|
111
|
+
| `UDL4001` | The money graph loses or creates value on a lifecycle path, including partial funding | Balance the funded amount on every exit and drain held value |
|
|
112
|
+
| `UDL5013` | A stage names an invalid plan/order or lacks the required call form | Name `price`, use declared unique piece IDs and declare the stage's calls |
|
|
113
|
+
| `UDL2010` | Private calls cycle, name an unresolved action, violate order or exceed bounds | Keep the graph finite and its order lists exact |
|
|
114
|
+
|
|
115
|
+
The partition itself has `UDL4002` diagnostics for incompatible immutable
|
|
116
|
+
fields, amount partition or currency. A stage does not exempt its transfer
|
|
117
|
+
from the independent money proof. Calls across different principals,
|
|
118
|
+
independent approval or external recovery boundaries are refused; model those
|
|
119
|
+
as separate actions. The [diagnostic reference](reference/diagnostics.md) lists the HSX refusal
|
|
120
|
+
codes and their repairs.
|
package/docs/reference/cli.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
<!-- Generated by scripts/docs/build.ts for HSX 2.
|
|
1
|
+
<!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
|
|
2
2
|
|
|
3
3
|
# CLI
|
|
4
4
|
|
|
5
5
|
```text
|
|
6
|
-
hsx 2.
|
|
6
|
+
hsx 2.2.0, the HSX compiler
|
|
7
7
|
|
|
8
8
|
Usage:
|
|
9
|
-
hsx check <file.hsx> [--strict]
|
|
10
|
-
hsx build <file.hsx> [--out <file.json>] [--strict]
|
|
11
|
-
hsx cost <file.hsx> [--json] [--out <file.json>] [--strict]
|
|
9
|
+
hsx check <file.hsx> [--catalog <catalog.udl>] [--strict]
|
|
10
|
+
hsx build <file.hsx> [--catalog <catalog.udl>] [--out <file.json>] [--strict]
|
|
11
|
+
hsx cost <file.hsx> [--catalog <catalog.udl>] [--json] [--out <file.json>] [--strict]
|
|
12
12
|
hsx explain <HSX####>
|
|
13
13
|
hsx format <file.hsx>
|
|
14
14
|
hsx lsp
|
|
@@ -24,6 +24,7 @@ Commands:
|
|
|
24
24
|
lsp Run the language server over stdin and stdout.
|
|
25
25
|
|
|
26
26
|
Options:
|
|
27
|
+
--catalog <file> Read the published instrument catalogue as canonical UDL JSON.
|
|
27
28
|
--json Print the cost manifest as JSON instead of a table.
|
|
28
29
|
--out <file> Write build or cost JSON to this path instead of stdout.
|
|
29
30
|
--strict Treat warning-severity diagnostics as failures.
|
|
@@ -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.0. Do not edit. -->
|
|
2
2
|
|
|
3
3
|
# Diagnostics
|
|
4
4
|
|
|
@@ -39,7 +39,7 @@ instrument probe {
|
|
|
39
39
|
agent_description: "Create a probe instance.";
|
|
40
40
|
steps: [];
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
}
|
|
44
44
|
program second "Second"
|
|
45
45
|
```
|
|
@@ -70,7 +70,7 @@ instrument probe {
|
|
|
70
70
|
agent_description: "Create a probe instance.";
|
|
71
71
|
steps: [];
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
}
|
|
75
75
|
instrument probe { fields {}; lifecycle { states created; initial created; }; action create { steps: []; }; }
|
|
76
76
|
```
|
|
@@ -122,7 +122,7 @@ instrument probe {
|
|
|
122
122
|
agent_description: "Create a probe instance.";
|
|
123
123
|
steps: [];
|
|
124
124
|
}
|
|
125
|
-
|
|
125
|
+
|
|
126
126
|
}
|
|
127
127
|
subject vehicle { title: "Vehicle"; }
|
|
128
128
|
```
|
|
@@ -340,7 +340,7 @@ instrument probe {
|
|
|
340
340
|
agent_description: "Create a probe instance.";
|
|
341
341
|
steps: [];
|
|
342
342
|
}
|
|
343
|
-
|
|
343
|
+
|
|
344
344
|
}
|
|
345
345
|
const fee: money<SAR> = USD 1.00
|
|
346
346
|
```
|
|
@@ -361,7 +361,7 @@ instrument probe {
|
|
|
361
361
|
agent_description: "Create a probe instance.";
|
|
362
362
|
steps: [];
|
|
363
363
|
}
|
|
364
|
-
|
|
364
|
+
|
|
365
365
|
}
|
|
366
366
|
const fee: money<SAR> = SAR 1.001
|
|
367
367
|
```
|
|
@@ -481,7 +481,7 @@ instrument probe {
|
|
|
481
481
|
agent_description: "Create a probe instance.";
|
|
482
482
|
steps: [];
|
|
483
483
|
}
|
|
484
|
-
|
|
484
|
+
|
|
485
485
|
}
|
|
486
486
|
```
|
|
487
487
|
|
|
@@ -517,7 +517,7 @@ instrument probe {
|
|
|
517
517
|
agent_description: "Create a probe instance.";
|
|
518
518
|
steps: [];
|
|
519
519
|
}
|
|
520
|
-
|
|
520
|
+
|
|
521
521
|
}
|
|
522
522
|
```
|
|
523
523
|
|
|
@@ -537,7 +537,7 @@ instrument probe {
|
|
|
537
537
|
agent_description: "Create a probe instance.";
|
|
538
538
|
steps: [];
|
|
539
539
|
}
|
|
540
|
-
|
|
540
|
+
|
|
541
541
|
}
|
|
542
542
|
```
|
|
543
543
|
|
|
@@ -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.0. Do not edit. -->
|
|
2
2
|
|
|
3
3
|
# Grammar vocabulary
|
|
4
4
|
|
|
@@ -14,7 +14,7 @@ The parser is hand-written. This page records the exported lexer vocabulary, the
|
|
|
14
14
|
|
|
15
15
|
## Typed clause spellings
|
|
16
16
|
|
|
17
|
-
`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`, `
|
|
17
|
+
`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`
|
|
18
18
|
|
|
19
19
|
## Standard-library modules
|
|
20
20
|
|
|
@@ -29,7 +29,6 @@ The parser is hand-written. This page records the exported lexer vocabulary, the
|
|
|
29
29
|
- `pooled_split`
|
|
30
30
|
- `premium_forward`
|
|
31
31
|
- `reconciled_payout`
|
|
32
|
-
- `recurring_collection`
|
|
33
32
|
- `rotating_pool`
|
|
34
33
|
- `scheduled`
|
|
35
34
|
- `security_deposit`
|
|
@@ -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.0. Do not edit. -->
|
|
2
2
|
|
|
3
3
|
# advance
|
|
4
4
|
|
|
@@ -10,14 +10,91 @@ Source: [`std/money_flows/advance.hsx`](../../../std/money_flows/advance.hsx)
|
|
|
10
10
|
|
|
11
11
|
## Parameters
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
| Parameter | Type | Required | Meaning |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| `funder` | `party` | Yes | The party providing the upfront capital. |
|
|
16
|
+
| `to` | `party` | Yes | The party receiving the advance and responsible for repayment. |
|
|
17
|
+
| `amount` | `money<C>` | Yes | Total advanced principal in minor units of currency `C`. |
|
|
18
|
+
| `fee` | `optional<percent>` | No | Optional markup percentage fee charged on the advance (basis points precision). |
|
|
19
|
+
| `count` | `optional<integer>` | No | Optional number of scheduled installment repayments. |
|
|
20
|
+
| `every` | `optional<text>` | No | Optional recurrence duration between installments (e.g. `"P30D"`). |
|
|
21
|
+
| `first_due` | `optional<date>` | No | Optional date for the first installment repayment. |
|
|
22
|
+
| `against` | `optional<ref>` | No | Optional reference to a hold instrument whose release will be carved to repay the advance. |
|
|
23
|
+
| `repayment_source` | `optional<party>` | No | Optional party repaying when distinct from the capital recipient. |
|
|
24
|
+
| `profit_to` | `optional<party>` | No | Optional recipient of profit, separated from principal repayments. |
|
|
25
|
+
| `dated` | `optional<boolean>` | No | Require an explicit signed date for each repayment instead of duration offsets. |
|
|
26
|
+
|
|
27
|
+
Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
|
|
28
|
+
|
|
29
|
+
## Module guidance
|
|
30
|
+
|
|
31
|
+
Upfront capital disbursement repaid by carving future held payment releases or over scheduled installments.
|
|
32
|
+
|
|
33
|
+
### Purpose
|
|
34
|
+
|
|
35
|
+
`advance` provides working capital, merchant cash advances, or contractor pre-funding from a funder to a recipient.
|
|
36
|
+
Repayment occurs either automatically by intercepting (carving) releases from a linked escrow hold (`against`),
|
|
37
|
+
or over calendar-anchored installment repayments (`count`, `every`, `first_due`).
|
|
38
|
+
|
|
39
|
+
### Selection guidance
|
|
40
|
+
|
|
41
|
+
- vs `credit_facility`: `advance` disburses a single upfront lump-sum principal that is repaid over time.
|
|
42
|
+
`credit_facility` establishes a reusable revolving credit line with multiple draws up to a limit,
|
|
43
|
+
where repayments restore available borrowing capacity.
|
|
44
|
+
- vs `conditional_disbursement`: `advance` expects repayment of the advanced principal plus optional fees.
|
|
45
|
+
`conditional_disbursement` disburses non-repayable grants, claims, or milestone payments against external evidence.
|
|
46
|
+
- vs `held_payment`: `held_payment` holds customer funds in escrow until delivery. An `advance` can carve repayments
|
|
47
|
+
directly out of a `held_payment`'s release using `against`.
|
|
48
|
+
|
|
49
|
+
### Parameters
|
|
50
|
+
|
|
51
|
+
- `funder`: The party providing the upfront capital.
|
|
52
|
+
- `to`: The party receiving the advance and responsible for repayment.
|
|
53
|
+
- `amount`: Total advanced principal in minor units of currency `C`.
|
|
54
|
+
- `fee`: Optional markup percentage fee charged on the advance (basis points precision).
|
|
55
|
+
- `count`: Optional number of scheduled installment repayments.
|
|
56
|
+
- `every`: Optional recurrence duration between installments (e.g. `"P30D"`).
|
|
57
|
+
- `first_due`: Optional date for the first installment repayment.
|
|
58
|
+
- `repayment_source`: Optional party repaying when distinct from the capital recipient.
|
|
59
|
+
- `profit_to`: Optional recipient of profit, separated from principal repayments.
|
|
60
|
+
- `dated`: Require an explicit signed date for each repayment instead of duration offsets.
|
|
61
|
+
- `against`: Optional reference to a hold instrument whose release will be carved to repay the advance.
|
|
62
|
+
|
|
63
|
+
### Decision ports
|
|
64
|
+
|
|
65
|
+
None. Repayment is driven by linked hold releases or scheduled calendar dates.
|
|
66
|
+
|
|
67
|
+
### Example
|
|
68
|
+
|
|
69
|
+
```hsx
|
|
70
|
+
program advance_example "Advance example"
|
|
71
|
+
import { advance } from "std/money_flows"
|
|
72
|
+
party funder: business
|
|
73
|
+
party recipient: business
|
|
74
|
+
settlement advance_payment = advance {
|
|
75
|
+
funder: funder
|
|
76
|
+
to: recipient
|
|
77
|
+
amount: principal: money(SAR)
|
|
78
|
+
fee: 2.5%
|
|
79
|
+
count: 2
|
|
80
|
+
every: P30D
|
|
81
|
+
first_due: firstDueAt
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Declared clauses
|
|
86
|
+
|
|
87
|
+
- `agent description`
|
|
88
|
+
- `description`
|
|
89
|
+
- `due`
|
|
90
|
+
- `id prefix`
|
|
91
|
+
- `moves`
|
|
92
|
+
- `partitions`
|
|
93
|
+
- `steps`
|
|
94
|
+
- `summary`
|
|
95
|
+
- `title`
|
|
96
|
+
|
|
97
|
+
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.
|
|
21
98
|
|
|
22
99
|
## Decision ports
|
|
23
100
|
|
|
@@ -25,11 +102,11 @@ None.
|
|
|
25
102
|
|
|
26
103
|
## Actions and clauses
|
|
27
104
|
|
|
28
|
-
| Action
|
|
29
|
-
|
|
|
30
|
-
| `create`
|
|
31
|
-
| `disburse`
|
|
32
|
-
| `settle`
|
|
33
|
-
| `create`
|
|
34
|
-
| `disburse`
|
|
35
|
-
| `
|
|
105
|
+
| Action | Clauses lowered |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| `create` | `agent description`, `moves`, `steps`, `summary` |
|
|
108
|
+
| `disburse` | `agent description`, `moves`, `steps`, `summary` |
|
|
109
|
+
| `settle` | `agent description`, `moves`, `steps`, `summary` |
|
|
110
|
+
| `create` | `agent description`, `moves`, `steps`, `summary` |
|
|
111
|
+
| `disburse` | `agent description`, `moves`, `steps`, `summary` |
|
|
112
|
+
| `collect_repayment_[i]` | `agent description`, `due`, `moves`, `steps`, `summary` |
|
|
@@ -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.0. Do not edit. -->
|
|
2
2
|
|
|
3
3
|
# cancellable_booking
|
|
4
4
|
|
|
@@ -10,14 +10,124 @@ Source: [`std/money_flows/cancellable_booking.hsx`](../../../std/money_flows/can
|
|
|
10
10
|
|
|
11
11
|
## Parameters
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
| Parameter | Type | Required | Meaning |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| `guest` | `optional<party>` | No | The booking customer paying the fee and receiving refunds. |
|
|
16
|
+
| `host` | `optional<party>` | No | The service provider receiving the payout or retained cancellation penalty. |
|
|
17
|
+
| `amount` | `optional<money<C>>` | No | Total booking price in minor units of currency `C`. |
|
|
18
|
+
| `starts_at` | `optional<date>` | No | Stored ISO 8601 date when the booking begins. |
|
|
19
|
+
| `late_penalty_bps` | `optional<integer>` | No | Penalty in basis points applied when cancelling within the late window. |
|
|
20
|
+
| `late_within` | `optional<text>` | No | ISO 8601 duration defining the late window before `starts_at` (e.g. `"P2D"` for 2 days). |
|
|
21
|
+
| `early_penalty_bps` | `optional<integer>` | No | Penalty in basis points applied when cancelling before the late window. |
|
|
22
|
+
| `offer_life` | `optional<text>` | No | ISO 8601 duration defining how long a quoted cancellation offer remains valid (e.g. `"PT30M"`). |
|
|
23
|
+
| `cancel_bands` | `optional<list<block>>` | No | Supply cancel_bands to select deposit/balance custody instead of quoted cancellation. |
|
|
24
|
+
| `price_value` | `optional<text>` | No | price_value and supplier_cost fix the price; deposit_bps derives the deposit. |
|
|
25
|
+
| `supplier_cost` | `optional<text>` | No | price_value and supplier_cost fix the price; deposit_bps derives the deposit. |
|
|
26
|
+
| `departure` | `optional<text>` | No | balance_before and confirmation_window are positive fixed durations relative to departure. |
|
|
27
|
+
| `balance_before` | `optional<text>` | No | balance_before and confirmation_window are positive fixed durations relative to departure. |
|
|
28
|
+
| `confirmation_window` | `optional<text>` | No | balance_before and confirmation_window are positive fixed durations relative to departure. |
|
|
29
|
+
| `unpaid_band` | `optional<integer>` | No | The unpaid_band index selects a retained deposit policy. |
|
|
30
|
+
| `acceptance` | `optional<block>` | No | acceptance optionally supplies an aggregate gate. |
|
|
31
|
+
| `deposit_bps` | `optional<integer>` | No | price_value and supplier_cost fix the price; deposit_bps derives the deposit. |
|
|
32
|
+
| `tax_bps` | `optional<integer>` | No | tax_bps applies to margin after the supplier share. |
|
|
33
|
+
| `authority_type` | `optional<text>` | No | authority_type and supplier_role bind release to a consumed confirmation decision. |
|
|
34
|
+
| `supplier_role` | `optional<text>` | No | authority_type and supplier_role bind release to a consumed confirmation decision. |
|
|
35
|
+
|
|
36
|
+
Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
|
|
37
|
+
|
|
38
|
+
## Module guidance
|
|
39
|
+
|
|
40
|
+
Time-anchored reservation holding booking funds in escrow with dynamically quoted cancellation penalties.
|
|
41
|
+
|
|
42
|
+
### Purpose
|
|
43
|
+
|
|
44
|
+
`cancellable_booking` holds booking fees in escrow from a guest for a host until a scheduled start date.
|
|
45
|
+
It fits hospitality, travel reservations, studio rentals, event tickets, and appointments where guests
|
|
46
|
+
can cancel prior to start, but cancellation penalties depend on how close to the start date cancellation occurs.
|
|
47
|
+
|
|
48
|
+
### Selection guidance
|
|
49
|
+
|
|
50
|
+
- vs `held_payment`: Both hold money in escrow and both quote a cancellation before it is spent.
|
|
51
|
+
`cancellable_booking` prices the penalty against the time left before `starts_at`, so the charge moves
|
|
52
|
+
as the start approaches; `held_payment` has no start date and quotes one flat charge.
|
|
53
|
+
Choose `cancellable_booking` whenever cancellation fees are time-sensitive.
|
|
54
|
+
- vs `security_deposit`: `security_deposit` holds funds to cover damages claimed by the holder.
|
|
55
|
+
`cancellable_booking` holds the service fee itself and releases to the host upon `starts_at` or refunds net of penalty.
|
|
56
|
+
|
|
57
|
+
### Parameters
|
|
58
|
+
|
|
59
|
+
- `guest`: The booking customer paying the fee and receiving refunds.
|
|
60
|
+
- `host`: The service provider receiving the payout or retained cancellation penalty.
|
|
61
|
+
- `amount`: Total booking price in minor units of currency `C`.
|
|
62
|
+
- `starts_at`: Stored ISO 8601 date when the booking begins.
|
|
63
|
+
- `late_penalty_bps`: Penalty in basis points applied when cancelling within the late window.
|
|
64
|
+
- `late_within`: ISO 8601 duration defining the late window before `starts_at` (e.g. `"P2D"` for 2 days).
|
|
65
|
+
- `early_penalty_bps`: Penalty in basis points applied when cancelling before the late window.
|
|
66
|
+
- `offer_life`: ISO 8601 duration defining how long a quoted cancellation offer remains valid (e.g. `"PT30M"`).
|
|
67
|
+
|
|
68
|
+
### Decision ports
|
|
69
|
+
|
|
70
|
+
None. Action transitions are driven by guest API calls (`take`, `cancel`, `confirm`) and scheduled completion (`complete` due at `starts_at`).
|
|
71
|
+
|
|
72
|
+
### Example
|
|
73
|
+
|
|
74
|
+
```hsx
|
|
75
|
+
program studio_booking "Studio booking"
|
|
76
|
+
import { cancellable_booking } from "std/money_flows"
|
|
77
|
+
party guest: person
|
|
78
|
+
party studio: business
|
|
79
|
+
settlement studio_session = cancellable_booking {
|
|
80
|
+
guest: guest
|
|
81
|
+
host: studio
|
|
82
|
+
amount: sessionPrice: money(SAR)
|
|
83
|
+
starts_at: startsAt
|
|
84
|
+
late_penalty_bps: 5000
|
|
85
|
+
late_within: "P2D"
|
|
86
|
+
early_penalty_bps: 1000
|
|
87
|
+
offer_life: "PT30M"
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Finite cancellation bands
|
|
92
|
+
|
|
93
|
+
Supply cancel_bands to select deposit/balance custody instead of quoted cancellation.
|
|
94
|
+
Each band has name, refund (full, balance or none), starts_at after the first band,
|
|
95
|
+
and supplier_bps when money is retained. The unpaid_band index selects a retained
|
|
96
|
+
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
|
|
97
|
+
the deposit. balance_before and confirmation_window are positive fixed durations
|
|
98
|
+
relative to departure. tax_bps applies to margin after the supplier share.
|
|
99
|
+
authority_type and supplier_role bind release to a consumed confirmation decision.
|
|
100
|
+
acceptance optionally supplies an aggregate gate. All actions are private until
|
|
101
|
+
expose selects them. Ordered band starts and deadlines prevent a late sweep from
|
|
102
|
+
extending an earlier band's cancellation rights. Full timeout refund returns price.
|
|
103
|
+
Seven derivations suffice for three bands; larger finite policies use up to the
|
|
104
|
+
UDL bound of 64 derived amounts. shift_date(date, duration, "before") subtracts a
|
|
105
|
+
fixed duration; omitting the direction adds it. Invalid dates or durations refuse.
|
|
106
|
+
|
|
107
|
+
## Declared clauses
|
|
108
|
+
|
|
109
|
+
- `agent description`
|
|
110
|
+
- `caller parked states`
|
|
111
|
+
- `commit`
|
|
112
|
+
- `deadline`
|
|
113
|
+
- `description`
|
|
114
|
+
- `distinct parties`
|
|
115
|
+
- `due`
|
|
116
|
+
- `id prefix`
|
|
117
|
+
- `input`
|
|
118
|
+
- `moves`
|
|
119
|
+
- `partitions`
|
|
120
|
+
- `port`
|
|
121
|
+
- `quote`
|
|
122
|
+
- `requires drained`
|
|
123
|
+
- `sandbox failure point`
|
|
124
|
+
- `steps`
|
|
125
|
+
- `summary`
|
|
126
|
+
- `title`
|
|
127
|
+
- `unique`
|
|
128
|
+
- `updates`
|
|
129
|
+
|
|
130
|
+
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.
|
|
21
131
|
|
|
22
132
|
## Decision ports
|
|
23
133
|
|
|
@@ -25,11 +135,22 @@ None.
|
|
|
25
135
|
|
|
26
136
|
## Actions and clauses
|
|
27
137
|
|
|
28
|
-
| Action
|
|
29
|
-
|
|
|
30
|
-
| `create`
|
|
31
|
-
| `take`
|
|
32
|
-
| `complete` | `due`, `moves`, `steps`, `summary`
|
|
33
|
-
| `cancel`
|
|
34
|
-
| `confirm`
|
|
35
|
-
| `retain`
|
|
138
|
+
| Action | Clauses lowered |
|
|
139
|
+
| --- | --- |
|
|
140
|
+
| `create` | `agent description`, `moves`, `steps`, `summary` |
|
|
141
|
+
| `take` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
|
|
142
|
+
| `complete` | `due`, `moves`, `steps`, `summary` |
|
|
143
|
+
| `cancel` | `agent description`, `moves`, `quote`, `steps`, `summary` |
|
|
144
|
+
| `confirm` | `agent description`, `commit`, `moves`, `steps`, `summary` |
|
|
145
|
+
| `retain` | `agent description`, `moves`, `steps`, `summary` |
|
|
146
|
+
| `create` | `agent description`, `deadline`, `steps`, `unique` |
|
|
147
|
+
| `deposit` | `agent description`, `deadline`, `moves`, `port`, `steps` |
|
|
148
|
+
| `expire` | `agent description`, `due`, `requires drained`, `steps` |
|
|
149
|
+
| `[balance_action]` | `agent description`, `deadline`, `moves`, `port`, `steps` |
|
|
150
|
+
| `[open_action]` | `agent description`, `due`, `steps` |
|
|
151
|
+
| `[cancel_action]` | `agent description`, `deadline`, `moves`, `port`, `steps` |
|
|
152
|
+
| `cancel_unpaid` | `agent description`, `due`, `moves`, `steps` |
|
|
153
|
+
| `await_confirmation` | `agent description`, `due`, `steps` |
|
|
154
|
+
| `confirm` | `agent description`, `deadline`, `input`, `steps`, `updates` |
|
|
155
|
+
| `release` | `agent description`, `moves`, `steps` |
|
|
156
|
+
| `refund_unconfirmed` | `agent description`, `due`, `moves`, `steps` |
|