@hyperscale0/hsx 2.0.0 → 2.0.2
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 +25 -0
- package/dist/src/cli.d.ts +1 -1
- package/dist/src/diagnostics.d.ts.map +1 -1
- package/dist/src/diagnostics.js +7 -0
- package/dist/src/diagnostics.js.map +1 -1
- package/dist/src/std-bundle.js +19 -19
- package/dist/src/std-bundle.js.map +1 -1
- package/dist/src/typecheck.js +89 -1
- 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/guide/01-first-program.md +1 -1
- package/docs/guide/09-cost.md +1 -1
- package/docs/llms-full.txt +64 -39
- package/docs/llms.txt +2 -2
- package/docs/reference/cli.md +2 -2
- package/docs/reference/diagnostics.md +21 -1
- package/docs/reference/grammar.md +1 -1
- package/docs/reference/std/advance.md +1 -1
- package/docs/reference/std/cancellable_booking.md +1 -1
- package/docs/reference/std/captured_payment.md +1 -1
- package/docs/reference/std/conditional_disbursement.md +1 -1
- package/docs/reference/std/credit_facility.md +1 -1
- package/docs/reference/std/held_payment.md +41 -36
- package/docs/reference/std/instant_transfer.md +1 -1
- package/docs/reference/std/metered.md +1 -1
- package/docs/reference/std/pooled_split.md +1 -1
- package/docs/reference/std/premium_forward.md +1 -1
- package/docs/reference/std/reconciled_payout.md +1 -1
- package/docs/reference/std/recurring_collection.md +1 -1
- package/docs/reference/std/rotating_pool.md +1 -1
- package/docs/reference/std/scheduled.md +1 -1
- package/docs/reference/std/security_deposit.md +1 -1
- package/docs/reference/std/settlement_batch.md +1 -1
- package/docs/reference/std/swap.md +1 -1
- package/docs/reference/std/threshold_pool.md +1 -1
- package/docs/reference/std/weighted_distribution.md +1 -1
- package/docs/reference/types.md +1 -1
- package/docs/reference/udl-output.md +1 -1
- package/examples/advance/advance.udl +6 -6
- package/examples/cancellable_booking/cancellable_booking.udl +10 -10
- package/examples/captured_payment/captured_payment.udl +6 -6
- package/examples/conditional_disbursement/conditional_disbursement.udl +2 -2
- package/examples/cost-table.json +18 -78
- package/examples/credit_facility/credit_facility.udl +10 -10
- package/examples/held_payment/held_payment.udl +23 -12
- package/examples/instant_transfer/instant_transfer.udl +6 -6
- package/examples/metered/metered.udl +4 -4
- package/examples/pooled_split/pooled_split.udl +10 -10
- package/examples/premium_forward/premium_forward.udl +12 -12
- package/examples/recurring_collection/recurring_collection.udl +8 -8
- package/examples/rotating_pool/rotating_pool.udl +78 -78
- package/examples/scheduled/scheduled.udl +6 -6
- package/examples/security_deposit/security_deposit.udl +2 -2
- package/examples/swap/swap.udl +22 -22
- package/examples/threshold_pool/threshold_pool.udl +10 -10
- package/examples/weighted_distribution/weighted_distribution.udl +2 -2
- package/package.json +3 -3
- package/skills/hsx/SKILL.md +2 -2
- package/src/diagnostics.ts +10 -0
- package/src/std-bundle.ts +19 -19
- package/src/typecheck.ts +105 -1
- package/src/version.ts +1 -1
- package/std/money_flows/advance.hsx +45 -0
- package/std/money_flows/cancellable_booking.hsx +45 -0
- package/std/money_flows/captured_payment.hsx +55 -0
- package/std/money_flows/conditional_disbursement.hsx +46 -0
- package/std/money_flows/credit_facility.hsx +57 -0
- package/std/money_flows/held_payment.hsx +152 -3
- package/std/money_flows/instant_transfer.hsx +42 -0
- package/std/money_flows/metered.hsx +41 -0
- package/std/money_flows/pooled_split.hsx +41 -0
- package/std/money_flows/premium_forward.hsx +51 -0
- package/std/money_flows/reconciled_payout.hsx +42 -0
- package/std/money_flows/recurring_collection.hsx +45 -0
- package/std/money_flows/rotating_pool.hsx +51 -0
- package/std/money_flows/scheduled.hsx +53 -0
- package/std/money_flows/security_deposit.hsx +58 -0
- package/std/money_flows/settlement_batch.hsx +51 -0
- package/std/money_flows/swap.hsx +53 -0
- package/std/money_flows/threshold_pool.hsx +51 -0
- package/std/money_flows/weighted_distribution.hsx +54 -0
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
module std.money_flows.metered
|
|
2
2
|
|
|
3
|
+
// Usage-based billing against a committed rate card over an open period until a stored close date.
|
|
4
|
+
//
|
|
5
|
+
// ### Purpose
|
|
6
|
+
// `metered` bills customers for variable resource consumption such as API requests, compute hours,
|
|
7
|
+
// storage gigabytes, or utility consumption. The rate card is fixed when the period opens, and individual
|
|
8
|
+
// usage events are charged incrementally until the billing period closes on `close_by`.
|
|
9
|
+
//
|
|
10
|
+
// ### Selection guidance
|
|
11
|
+
// - vs `scheduled`: `metered` charges variable amounts per event calculated from consumed units and committed
|
|
12
|
+
// rate card prices. `scheduled` executes transfers on fixed calendar recurrence intervals (`every`, `first_due`)
|
|
13
|
+
// with predetermined amounts or installments.
|
|
14
|
+
// - vs `recurring_collection`: `metered` calculates and executes real ledger transfers for each usage charge.
|
|
15
|
+
// `recurring_collection` is a lightweight status tracker for collection runs without balance transfers or rate cards.
|
|
16
|
+
// - vs `instant_transfer`: `instant_transfer` executes a single immediate payment. `metered` manages a stateful
|
|
17
|
+
// open billing cycle accepting multiple usage charges under a fixed rate card.
|
|
18
|
+
//
|
|
19
|
+
// ### Parameters
|
|
20
|
+
// - `payer`: The customer being billed for usage.
|
|
21
|
+
// - `payee`: The service provider receiving usage revenue.
|
|
22
|
+
// - `close_by`: Date when the metering period closes, preventing further usage charges.
|
|
23
|
+
// - `rates`: Block mapping rate metric names to their per-unit money prices committed at period open.
|
|
24
|
+
//
|
|
25
|
+
// ### Decision ports
|
|
26
|
+
// None. Charges are driven by caller billing actions and period closure.
|
|
27
|
+
//
|
|
28
|
+
// ### Example
|
|
29
|
+
// ```hsx
|
|
30
|
+
// program metered_example "Metered example"
|
|
31
|
+
// import { metered } from "std/money_flows"
|
|
32
|
+
// party customer: business
|
|
33
|
+
// party provider: business
|
|
34
|
+
// settlement usage = metered {
|
|
35
|
+
// payer: customer
|
|
36
|
+
// payee: provider
|
|
37
|
+
// close_by: periodEnd
|
|
38
|
+
// rates {
|
|
39
|
+
// api_call: callRate: money(SAR)
|
|
40
|
+
// storage_gib: storageRate: money(SAR)
|
|
41
|
+
// }
|
|
42
|
+
// }
|
|
43
|
+
// ```
|
|
3
44
|
export instrument metered(
|
|
4
45
|
payer: party,
|
|
5
46
|
payee: party,
|
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
module std.money_flows.pooled_split
|
|
2
2
|
|
|
3
|
+
// Fixed multi-recipient revenue or period pool funded share-by-share and released automatically on a due date.
|
|
4
|
+
//
|
|
5
|
+
// ### Purpose
|
|
6
|
+
// `pooled_split` pools a period total from one payer and splits it across a fixed roster of recipients
|
|
7
|
+
// according to predetermined percentage shares (with integer division remainder assigned to `remainder_to`).
|
|
8
|
+
// Callers fund the pool share-by-share, and payouts disburse automatically to each recipient on `payout_due`.
|
|
9
|
+
//
|
|
10
|
+
// ### Selection guidance
|
|
11
|
+
// - vs `weighted_distribution`: `pooled_split` hardcodes a fixed set of recipients and static percentage shares
|
|
12
|
+
// directly in the contract. `weighted_distribution` handles dynamic recipient counts where arbitrary weights
|
|
13
|
+
// are recorded as child records and frozen via a snapshot port before distribution.
|
|
14
|
+
// - vs `settlement_batch`: `settlement_batch` aggregates multiple payments from many sources into one net payout.
|
|
15
|
+
// `pooled_split` takes one period total from one payer and partitions it out to multiple recipients.
|
|
16
|
+
//
|
|
17
|
+
// ### Parameters
|
|
18
|
+
// - `payer`: The funding party providing the pooled amount.
|
|
19
|
+
// - `amount`: Total pooled amount in minor units of currency `C`.
|
|
20
|
+
// - `payout_due`: Stored payout date when the pool distributes to all recipients.
|
|
21
|
+
// - `split`: Block declaring each recipient's percentage share and `remainder_to` recipient for rounding remainders.
|
|
22
|
+
//
|
|
23
|
+
// ### Decision ports
|
|
24
|
+
// None. Payout distribution triggers automatically from the stored `payout_due` date.
|
|
25
|
+
//
|
|
26
|
+
// ### Example
|
|
27
|
+
// ```hsx
|
|
28
|
+
// program pooled_split_example "Pooled split example"
|
|
29
|
+
// import { pooled_split } from "std/money_flows"
|
|
30
|
+
// party payer: business
|
|
31
|
+
// party first_recipient: business
|
|
32
|
+
// party second_recipient: business
|
|
33
|
+
// settlement pool = pooled_split {
|
|
34
|
+
// payer: payer
|
|
35
|
+
// amount: poolAmount: money(SAR)
|
|
36
|
+
// payout_due: payoutDueAt
|
|
37
|
+
// split {
|
|
38
|
+
// first_recipient: 60%
|
|
39
|
+
// second_recipient: 40%
|
|
40
|
+
// remainder_to: first_recipient
|
|
41
|
+
// }
|
|
42
|
+
// }
|
|
43
|
+
// ```
|
|
3
44
|
export instrument pooled_split<C>(payer: party, amount: money<C>, payout_due: date, split: block) {
|
|
4
45
|
let(recipients): keys_except(split, "remainder_to");
|
|
5
46
|
let(recipient_count): len(recipients);
|
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
module std.money_flows.premium_forward
|
|
2
2
|
|
|
3
|
+
// Insurance premium escrow holding customer funds until policy binding, then partitioning net carrier premium and commission.
|
|
4
|
+
//
|
|
5
|
+
// ### Purpose
|
|
6
|
+
// `premium_forward` manages insurance premium collection, broker commission retention, and carrier remittance.
|
|
7
|
+
// A policyholder funds the premium into dedicated escrow. The funds remain held until the policy binds via the `bind` port.
|
|
8
|
+
// Upon binding, the gross premium is automatically partitioned: the platform fee/commission is retained, and the net
|
|
9
|
+
// balance forwards to the carrier. It also supports policy endorsements and renewal schedules.
|
|
10
|
+
//
|
|
11
|
+
// ### Selection guidance
|
|
12
|
+
// - vs `held_payment`: `premium_forward` is tailored for insurance lifecycles, featuring automatic commission splits
|
|
13
|
+
// upon binding and policy endorsement tracking. `held_payment` is general commercial escrow without insurance
|
|
14
|
+
// underwriting binding semantics or gross-to-net fee partitioning.
|
|
15
|
+
// - vs `conditional_disbursement`: `premium_forward` collects and forwards inbound policy premiums to carriers.
|
|
16
|
+
// `conditional_disbursement` pays outbound claim settlements to claimants against stored evidence.
|
|
17
|
+
//
|
|
18
|
+
// ### Parameters
|
|
19
|
+
// - `payer`: The policyholder paying the insurance premium.
|
|
20
|
+
// - `carrier`: The insurance carrier underwriting the policy.
|
|
21
|
+
// - `amount`: Total gross premium in minor units of currency `C`.
|
|
22
|
+
// - `bind`: Condition port triggering policy binding and premium forwarding.
|
|
23
|
+
// - `commission`: Platform commission percentage retained from the gross premium.
|
|
24
|
+
// - `policy_ref`: Optional policy identifier string.
|
|
25
|
+
// - `renewal_due`: Optional date anchor when the policy is due for renewal.
|
|
26
|
+
// - `endorsement`: Optional condition port for recording policy endorsements.
|
|
27
|
+
//
|
|
28
|
+
// ### Decision ports
|
|
29
|
+
// - `bind`: Port authorizing policy binding, triggering carrier payout and commission retention.
|
|
30
|
+
// - `endorsement`: Port allowing carrier endorsement evidence to be recorded.
|
|
31
|
+
//
|
|
32
|
+
// ### Example
|
|
33
|
+
// ```hsx
|
|
34
|
+
// program premium_forward_example "Premium forward example"
|
|
35
|
+
// import { premium_forward } from "std/money_flows"
|
|
36
|
+
// party policyholder: person
|
|
37
|
+
// party carrier: business
|
|
38
|
+
// settlement premium = premium_forward {
|
|
39
|
+
// payer: policyholder
|
|
40
|
+
// carrier: carrier
|
|
41
|
+
// amount: premiumAmount: money(SAR)
|
|
42
|
+
// commission: 2%
|
|
43
|
+
// bind: port bind_policy
|
|
44
|
+
// policy_ref: policyReference
|
|
45
|
+
// renewal_due: renewalDueAt
|
|
46
|
+
// endorsement: port record_endorsement
|
|
47
|
+
// }
|
|
48
|
+
// port bind_policy { allowed: [policyholder, carrier] }
|
|
49
|
+
// port record_endorsement {
|
|
50
|
+
// allowed: [carrier]
|
|
51
|
+
// shape: { evidenceReference: text }
|
|
52
|
+
// }
|
|
53
|
+
// ```
|
|
3
54
|
export instrument premium_forward<C>(
|
|
4
55
|
payer: party,
|
|
5
56
|
carrier: party,
|
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
module std.money_flows.reconciled_payout
|
|
2
2
|
|
|
3
|
+
// Outbound bank payout instruction with end-to-end reconciliation against external bank statement feeds.
|
|
4
|
+
//
|
|
5
|
+
// ### Purpose
|
|
6
|
+
// `reconciled_payout` manages high-assurance payouts to external suppliers, partners, or customers where payment
|
|
7
|
+
// is not complete until confirmed by bank statement data. An instruction is dispatched to the beneficiary and an expectation
|
|
8
|
+
// record is opened. Incoming statement debit lines match against the expectation within configurable tolerance thresholds
|
|
9
|
+
// (`matched_within`, `matched_ceiling`). If the statement debit does not match before `settle_by`, a formal break row is raised.
|
|
10
|
+
//
|
|
11
|
+
// ### Selection guidance
|
|
12
|
+
// - vs `settlement_batch`: `reconciled_payout` executes and reconciles an individual bank payout instruction.
|
|
13
|
+
// `settlement_batch` aggregates periodic captures, fees, and signed adjustments to calculate a net payable batch.
|
|
14
|
+
// - vs `instant_transfer`: `instant_transfer` executes an immediate internal ledger transfer between platform accounts.
|
|
15
|
+
// `reconciled_payout` dispatches funds across external banking rails with reconciliation tolerances and break tracking.
|
|
16
|
+
//
|
|
17
|
+
// ### Parameters
|
|
18
|
+
// - `payer`: The funding party providing the payout.
|
|
19
|
+
// - `beneficiary`: The beneficiary party receiving the external payout.
|
|
20
|
+
// - `amount`: Instructed payout amount in minor units of currency `C`.
|
|
21
|
+
// - `beneficiary_ref`: Registered external beneficiary ID for bank routing.
|
|
22
|
+
// - `settle_by`: Cut-off date when unmatched expectation amounts become formal break records.
|
|
23
|
+
// - `matched_within`: Match tolerance window in basis points or minor units.
|
|
24
|
+
// - `matched_ceiling`: Maximum acceptable tolerance ceiling between instructed amount and settled debit.
|
|
25
|
+
//
|
|
26
|
+
// ### Decision ports
|
|
27
|
+
// None. Payout dispatch and settlement matching follow the declared schedule, bank statement lines, and tolerance rules.
|
|
28
|
+
//
|
|
29
|
+
// ### Example
|
|
30
|
+
// ```hsx
|
|
31
|
+
// program reconciled_payout_example "Reconciled payout example"
|
|
32
|
+
// import { reconciled_payout } from "std/money_flows"
|
|
33
|
+
// party treasury: business
|
|
34
|
+
// party supplier: business
|
|
35
|
+
// settlement supplier_payout = reconciled_payout {
|
|
36
|
+
// payer: treasury
|
|
37
|
+
// beneficiary: supplier
|
|
38
|
+
// amount: netPayable: money(SAR)
|
|
39
|
+
// beneficiary_ref: supplierBeneficiaryId
|
|
40
|
+
// settle_by: settleBy
|
|
41
|
+
// matched_within: 100
|
|
42
|
+
// matched_ceiling: 500
|
|
43
|
+
// }
|
|
44
|
+
// ```
|
|
3
45
|
export instrument reconciled_payout<C>(
|
|
4
46
|
payer: party,
|
|
5
47
|
beneficiary: party,
|
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
module std.money_flows.recurring_collection
|
|
2
2
|
|
|
3
|
+
// Bounded lifecycle state tracker for recurring collections without direct balance movement.
|
|
4
|
+
//
|
|
5
|
+
// ### Purpose
|
|
6
|
+
// `recurring_collection` tracks the ongoing execution state of a series of recurring collections.
|
|
7
|
+
// It carries no money amount and no account bindings; each `collect` call records that an installment
|
|
8
|
+
// occurred, and `end` closes the series permanently. It is typically paired with an external billing
|
|
9
|
+
// engine or a separate debt obligation instrument.
|
|
10
|
+
//
|
|
11
|
+
// ### Selection guidance
|
|
12
|
+
// - vs `scheduled`: `recurring_collection` moves no money and has no ledger accounts or amount partitioning.
|
|
13
|
+
// It is a pure lifecycle tracker. Choose `scheduled` when the platform itself must calculate installment amounts,
|
|
14
|
+
// enforce calendar intervals, or debit customer accounts.
|
|
15
|
+
// - vs `metered`: `metered` bills variable usage against a rate card with real balance movements.
|
|
16
|
+
// `recurring_collection` only records collection lifecycle steps.
|
|
17
|
+
//
|
|
18
|
+
// ### Parameters
|
|
19
|
+
// - `marker`: Optional descriptive text marker stored on the recurring collection record.
|
|
20
|
+
//
|
|
21
|
+
// ### Decision ports
|
|
22
|
+
// None. State transitions are controlled directly by API actions (`collect`, `end`).
|
|
23
|
+
//
|
|
24
|
+
// ### Example
|
|
25
|
+
// ```hsx
|
|
26
|
+
// program recurring_collection_example "Recurring collection example"
|
|
27
|
+
// import { recurring_collection, scheduled } from "std/money_flows"
|
|
28
|
+
// party debtor: person
|
|
29
|
+
// party repayment_source: business
|
|
30
|
+
// party recipient: business
|
|
31
|
+
// settlement obligation = scheduled {
|
|
32
|
+
// mode: obligation
|
|
33
|
+
// payer: repayment_source
|
|
34
|
+
// payee: recipient
|
|
35
|
+
// debtor: debtor
|
|
36
|
+
// amount: principal: money(SAR)
|
|
37
|
+
// count: 2
|
|
38
|
+
// every: P30D
|
|
39
|
+
// first_due: firstDueAt
|
|
40
|
+
// mandate: port mandate_evidence
|
|
41
|
+
// }
|
|
42
|
+
// settlement collection = recurring_collection {}
|
|
43
|
+
// port mandate_evidence {
|
|
44
|
+
// allowed: [repayment_source]
|
|
45
|
+
// shape: { evidenceReference: text }
|
|
46
|
+
// }
|
|
47
|
+
// ```
|
|
3
48
|
export instrument recurring_collection(marker: optional<text>) {
|
|
4
49
|
agent_description: concat("Reach for ", words(instrument), " to track a bounded run of scheduled collections, one call per recorded installment. It carries no amount and no account, and every action only advances its own state. A settlement that debits an account on a schedule is a different shape.");
|
|
5
50
|
fields {}
|
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
module std.money_flows.rotating_pool
|
|
2
2
|
|
|
3
|
+
// Rotating savings and credit association (ROSCA) pool where members contribute fixed amounts and take turns receiving the pot.
|
|
4
|
+
//
|
|
5
|
+
// ### Purpose
|
|
6
|
+
// `rotating_pool` coordinates peer savings circles, chit funds, tandas, and committee savings groups.
|
|
7
|
+
// A fixed group of members contributes an identical contribution amount each cycle. In each cycle, one designated member
|
|
8
|
+
// receives the entire pooled pot according to a predefined `payout_order` until all members have taken their turn.
|
|
9
|
+
//
|
|
10
|
+
// ### Selection guidance
|
|
11
|
+
// - vs `threshold_pool`: `rotating_pool` coordinates recurring multi-party peer savings with rotating payouts.
|
|
12
|
+
// `threshold_pool` is all-or-nothing capital accumulation toward a single threshold for one beneficiary.
|
|
13
|
+
// - vs `scheduled`: `scheduled` coordinates a single payer to a single payee. `rotating_pool` orchestrates
|
|
14
|
+
// a closed circular group of members taking sequential turns.
|
|
15
|
+
//
|
|
16
|
+
// ### Parameters
|
|
17
|
+
// - `members`: List of parties belonging to the rotating group.
|
|
18
|
+
// - `contribution`: Fixed contribution amount required from each member per cycle in minor units of currency `C`.
|
|
19
|
+
// - `count`: Total number of cycles in the rotation (matching the member count).
|
|
20
|
+
// - `every`: Recurrence interval between contribution cycles (e.g. `"P30D"`).
|
|
21
|
+
// - `first_due`: Due date for the first cycle's contribution.
|
|
22
|
+
// - `payout_order`: Ordered list of member parties defining the cycle payout sequence.
|
|
23
|
+
// - `default_policy`: Policy for handling missed contributions (`due_condition`).
|
|
24
|
+
// - `guarantee_policy`: Policy for backing defaulted contributions (`funded_only`).
|
|
25
|
+
// - `guarantor`: Optional guarantor party covering member defaults.
|
|
26
|
+
// - `exit_policy`: Policy governing member departures (`before_activation_only`).
|
|
27
|
+
// - `memo`: Optional memo text stored on the pool.
|
|
28
|
+
// - `membership`: Optional custom membership configuration block.
|
|
29
|
+
//
|
|
30
|
+
// ### Decision ports
|
|
31
|
+
// None. Cycle advancement and pot payouts follow the declared schedule and membership actions.
|
|
32
|
+
//
|
|
33
|
+
// ### Example
|
|
34
|
+
// ```hsx
|
|
35
|
+
// program rotating_pool_example "Rotating pool example"
|
|
36
|
+
// import { rotating_pool } from "std/money_flows"
|
|
37
|
+
// party member_a: person
|
|
38
|
+
// party member_b: person
|
|
39
|
+
// party member_c: person
|
|
40
|
+
// party guarantor: business
|
|
41
|
+
// settlement pool = rotating_pool {
|
|
42
|
+
// members: [member_a, member_b, member_c]
|
|
43
|
+
// contribution: contributionAmount: money(SAR)
|
|
44
|
+
// count: 3
|
|
45
|
+
// every: P30D
|
|
46
|
+
// first_due: firstContributionAt
|
|
47
|
+
// payout_order: [member_b, member_c, member_a]
|
|
48
|
+
// default_policy: due_condition
|
|
49
|
+
// guarantee_policy: funded_only
|
|
50
|
+
// guarantor: guarantor
|
|
51
|
+
// exit_policy: before_activation_only
|
|
52
|
+
// }
|
|
53
|
+
// ```
|
|
3
54
|
export instrument rotating_pool<C>(members: optional<list<party>>, contribution: money<C>, count: integer, every: optional<text>, first_due: date, payout_order: optional<list<party>>, default_policy: optional<text>, guarantee_policy: optional<text>, guarantor: optional<party>, exit_policy: optional<text>, memo: optional<text>, membership: optional<block>) {
|
|
4
55
|
when_not(membership) {
|
|
5
56
|
let(member_fields): suffix_each(members, "AccountId");
|
|
@@ -1,5 +1,58 @@
|
|
|
1
1
|
module std.money_flows.scheduled
|
|
2
2
|
|
|
3
|
+
// Calendar-anchored payments supporting fixed installment plans, recurring subscriptions, or debt obligations.
|
|
4
|
+
//
|
|
5
|
+
// ### Purpose
|
|
6
|
+
// `scheduled` automates time-anchored payment series between one payer and one payee.
|
|
7
|
+
// It supports three modes:
|
|
8
|
+
// 1. Installment plan: Partitions a fixed total amount into `count` installments, each collected on its own stored date.
|
|
9
|
+
// 2. Open recurring subscription: Charges a recurring amount on an interval `every` until an `until` port fires.
|
|
10
|
+
// 3. Debt obligation: Manages legally binding multi-installment debt with delinquency tracking, mandate evidence, and child payment records.
|
|
11
|
+
//
|
|
12
|
+
// ### Selection guidance
|
|
13
|
+
// - vs `metered`: `scheduled` executes calendar-based recurring charges or fixed installment plans.
|
|
14
|
+
// `metered` bills variable usage per event based on a committed rate card.
|
|
15
|
+
// - vs `recurring_collection`: `scheduled` actively moves ledger balances and partitions amounts.
|
|
16
|
+
// `recurring_collection` is a lightweight status tracker for collection runs without balance transfers.
|
|
17
|
+
// - vs `rotating_pool`: `scheduled` coordinates one payer to one payee on a calendar.
|
|
18
|
+
// `rotating_pool` coordinates a multi-party peer circle where members rotate turns receiving the entire pot.
|
|
19
|
+
//
|
|
20
|
+
// ### Parameters
|
|
21
|
+
// - `payer`: The paying party (or repayment source).
|
|
22
|
+
// - `payee`: The beneficiary party receiving installment funds.
|
|
23
|
+
// - `amount`: Total amount to partition into installments or recurring charge amount in minor units of currency `C`.
|
|
24
|
+
// - `count`: Optional number of installments for installment or obligation modes.
|
|
25
|
+
// - `every`: Recurrence cadence duration string (e.g. `"P30D"`, `"P1M"`).
|
|
26
|
+
// - `first_due`: Stored date anchor for the first installment or charge.
|
|
27
|
+
// - `mode`: Optional mode selector (`obligation`). Omit for standard installment plans.
|
|
28
|
+
// - `debtor`: Optional debtor party when distinct from the payment source in obligation mode.
|
|
29
|
+
// - `advance_to`: Optional third-party receiving upfront advance disbursements in obligation mode.
|
|
30
|
+
// - `until`: Optional condition port triggering cancellation of recurring subscription runs.
|
|
31
|
+
// - `month_end`: Optional handling policy for calendar month-end adjustments.
|
|
32
|
+
// - `period_liability`: Optional liability policy for billing periods.
|
|
33
|
+
// - `termination_drain`: Optional policy for draining balances on early termination.
|
|
34
|
+
// - `mandate`: Optional condition port supplying formal debit mandate evidence.
|
|
35
|
+
// - `derived_amount`: Optional calculated markup or fee rules.
|
|
36
|
+
//
|
|
37
|
+
// ### Decision ports
|
|
38
|
+
// - `until`: Port terminating recurring subscriptions.
|
|
39
|
+
// - `mandate`: Port supplying mandate verification evidence for direct debit obligations.
|
|
40
|
+
//
|
|
41
|
+
// ### Example
|
|
42
|
+
// ```hsx
|
|
43
|
+
// program scheduled_example "Scheduled example"
|
|
44
|
+
// import { scheduled } from "std/money_flows"
|
|
45
|
+
// party payer: business
|
|
46
|
+
// party payee: business
|
|
47
|
+
// settlement installments = scheduled {
|
|
48
|
+
// payer: payer
|
|
49
|
+
// payee: payee
|
|
50
|
+
// amount: totalAmount: money(SAR)
|
|
51
|
+
// count: 3
|
|
52
|
+
// every: P30D
|
|
53
|
+
// first_due: firstDueAt
|
|
54
|
+
// }
|
|
55
|
+
// ```
|
|
3
56
|
export instrument scheduled<C>(
|
|
4
57
|
payer: party,
|
|
5
58
|
payee: party,
|
|
@@ -1,5 +1,63 @@
|
|
|
1
1
|
module std.money_flows.security_deposit
|
|
2
2
|
|
|
3
|
+
// Collateral deposit reserved against a payer's account in favor of a holder, returned in full or claimed against damages.
|
|
4
|
+
//
|
|
5
|
+
// ### Purpose
|
|
6
|
+
// `security_deposit` reserves collateral funds for vehicle rentals, property leasing, equipment hire, and security bonds.
|
|
7
|
+
// Funds remain held until the rental or lease concludes. The holder can either return the deposit in full
|
|
8
|
+
// or assess damages, claim a decided partial amount, and return the exact unspent remainder.
|
|
9
|
+
//
|
|
10
|
+
// ### Selection guidance
|
|
11
|
+
// - vs `held_payment`: `security_deposit` holds collateral where the standard outcome is returning 100% of the funds
|
|
12
|
+
// to the payer, and claims are partial damage assessments. `held_payment` holds payment consideration where the
|
|
13
|
+
// standard outcome is releasing 100% of the funds to the payee upon delivery.
|
|
14
|
+
// - vs `cancellable_booking`: `cancellable_booking` holds booking fees and applies time-based cancellation penalties.
|
|
15
|
+
// `security_deposit` holds damage collateral and supports arbitrary damage claims with remainder refund.
|
|
16
|
+
//
|
|
17
|
+
// ### Parameters
|
|
18
|
+
// - `payer`: The customer providing the deposit collateral.
|
|
19
|
+
// - `holder`: The merchant or owner holding the deposit rights.
|
|
20
|
+
// - `amount`: Total reserved deposit amount in minor units of currency `C`.
|
|
21
|
+
// - `claim`: Optional condition port triggering a damage claim.
|
|
22
|
+
// - `return`: Optional condition port triggering full return of the deposit.
|
|
23
|
+
// - `claim_amount`: Optional block defining partial claim logic (`field`, `bound`, `remainder`).
|
|
24
|
+
// - `deadline`: Optional stored date anchor for automatic deposit release or expiry.
|
|
25
|
+
// - `claim_to`: Optional alternate destination for claimed funds.
|
|
26
|
+
// - `return_to`: Optional alternate destination for returned funds.
|
|
27
|
+
// - `memo`: Optional memo text stored on the deposit record.
|
|
28
|
+
// - `claim_input`: Optional custom input schema for the claim action.
|
|
29
|
+
// - `claim_capture`: Optional capture mappings for claim evidence.
|
|
30
|
+
// - `fund_failure_point`: Optional configuration for deposit funding failure.
|
|
31
|
+
// - `id_prefix_override`: Optional custom prefix for generated instrument IDs.
|
|
32
|
+
//
|
|
33
|
+
// ### Decision ports
|
|
34
|
+
// - `claim`: Port permitting the holder to submit a damage claim.
|
|
35
|
+
// - `return`: Port permitting the holder to return the deposit to the payer.
|
|
36
|
+
//
|
|
37
|
+
// ### Example
|
|
38
|
+
// ```hsx
|
|
39
|
+
// program deposit_example "Deposit example"
|
|
40
|
+
// import { security_deposit } from "std/money_flows"
|
|
41
|
+
// party renter: person
|
|
42
|
+
// party owner: business
|
|
43
|
+
// settlement security_deposit = security_deposit {
|
|
44
|
+
// payer: renter
|
|
45
|
+
// holder: owner
|
|
46
|
+
// amount: depositAmount: money(SAR)
|
|
47
|
+
// claim: port assess_damage
|
|
48
|
+
// claim_amount: decided {
|
|
49
|
+
// field: damageAmount
|
|
50
|
+
// bound: depositAmount
|
|
51
|
+
// remainder: return
|
|
52
|
+
// }
|
|
53
|
+
// return: port return_deposit
|
|
54
|
+
// }
|
|
55
|
+
// port assess_damage {
|
|
56
|
+
// allowed: [owner]
|
|
57
|
+
// shape: { damageAmount: money(SAR), evidence: text }
|
|
58
|
+
// }
|
|
59
|
+
// port return_deposit { allowed: [owner] }
|
|
60
|
+
// ```
|
|
3
61
|
export instrument security_deposit<C>(payer: party, holder: party, amount: money<C>, claim: optional<condition>, return: optional<condition>, claim_amount: optional<block>, deadline: optional<date>, claim_to: optional<party>, return_to: optional<party>, memo: optional<text>, claim_input: optional<block>, claim_capture: optional<block>, fund_failure_point: optional<text>, id_prefix_override: optional<text>) {
|
|
4
62
|
let(claim_name): claim;
|
|
5
63
|
let(return_name): return;
|
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
module std.money_flows.settlement_batch
|
|
2
2
|
|
|
3
|
+
// Periodic aggregation of capture lineage, fee entries, and adjustments into a single net calculated payout.
|
|
4
|
+
//
|
|
5
|
+
// ### Purpose
|
|
6
|
+
// `settlement_batch` settles merchant balances, marketplace vendor earnings, and partner clearing accounts.
|
|
7
|
+
// Individual payment captures, platform fees, and reversal adjustments accumulate into an open batch over a period.
|
|
8
|
+
// On `close_trigger`, the batch freezes. The platform calculates the signed net payable from gross captures plus credit
|
|
9
|
+
// adjustments minus debit adjustments. If positive, an outbound bank payout is instructed and acknowledged.
|
|
10
|
+
//
|
|
11
|
+
// ### Selection guidance
|
|
12
|
+
// - vs `reconciled_payout`: `settlement_batch` aggregates multiple transactions and adjustments over a billing cycle
|
|
13
|
+
// to compute a single net payable. `reconciled_payout` manages bank instruction dispatch and statement line reconciliation
|
|
14
|
+
// for an individual payout amount.
|
|
15
|
+
// - vs `weighted_distribution`: `settlement_batch` consolidates many inbound transactions into one net outbound payout.
|
|
16
|
+
// `weighted_distribution` splits one funding pool into many recipient payouts.
|
|
17
|
+
//
|
|
18
|
+
// ### Parameters
|
|
19
|
+
// - `settlement_account`: The source clearing account holding captured funds and paying the batch.
|
|
20
|
+
// - `source_capture_refs`: Binding name for gross capture references included in the batch.
|
|
21
|
+
// - `fee_entries`: Binding name for fee deductions applied to the batch.
|
|
22
|
+
// - `external_reversal_offsets`: Binding name for reversal adjustments applied to the batch.
|
|
23
|
+
// - `close_trigger`: Date when the batch closes and ceases accepting new transaction entries.
|
|
24
|
+
// - `payout_destination`: The merchant or partner account receiving the net payout.
|
|
25
|
+
// - `negative_position`: Policy when calculated net payable is zero or negative (`reject`).
|
|
26
|
+
// - `payout_acknowledgement`: Condition port confirming bank receipt of the payout.
|
|
27
|
+
// - `payout_beneficiary_ref`: Beneficiary identifier for external bank dispatch.
|
|
28
|
+
//
|
|
29
|
+
// ### Decision ports
|
|
30
|
+
// - `payout_acknowledgement`: Port recording external bank or partner receipt confirmation.
|
|
31
|
+
//
|
|
32
|
+
// ### Example
|
|
33
|
+
// ```hsx
|
|
34
|
+
// program settlement_batch_example "Settlement batch example"
|
|
35
|
+
// import { settlement_batch } from "std/money_flows"
|
|
36
|
+
// party settlement_account: business
|
|
37
|
+
// party payout_destination: business
|
|
38
|
+
// settlement batch = settlement_batch {
|
|
39
|
+
// settlement_account: settlement_account
|
|
40
|
+
// source_capture_refs: captureReference
|
|
41
|
+
// fee_entries: feeReference
|
|
42
|
+
// external_reversal_offsets: reversalReference
|
|
43
|
+
// close_trigger: closeAt
|
|
44
|
+
// payout_destination: payout_destination
|
|
45
|
+
// negative_position: reject
|
|
46
|
+
// payout_acknowledgement: port acknowledge_payout
|
|
47
|
+
// payout_beneficiary_ref: payoutBeneficiaryId
|
|
48
|
+
// }
|
|
49
|
+
// port acknowledge_payout {
|
|
50
|
+
// allowed: [payout_destination]
|
|
51
|
+
// shape: { acknowledgementReference: text }
|
|
52
|
+
// }
|
|
53
|
+
// ```
|
|
3
54
|
export instrument settlement_batch<C>(
|
|
4
55
|
settlement_account: party,
|
|
5
56
|
source_capture_refs: text,
|
package/std/money_flows/swap.hsx
CHANGED
|
@@ -1,4 +1,57 @@
|
|
|
1
1
|
module std.money_flows.swap;
|
|
2
|
+
|
|
3
|
+
// Atomic two-sided trade between two parties where neither leg settles alone.
|
|
4
|
+
//
|
|
5
|
+
// ### Purpose
|
|
6
|
+
// `swap` executes atomic delivery-versus-payment (DvP) or payment-versus-payment (PvP) exchanges between two named parties.
|
|
7
|
+
// Both sides fund their declared principal amounts and platform fees into a shared escrow. The exchange settles atomically
|
|
8
|
+
// upon triggering the `release` condition port, paying each party the other's funded amount. If a `dispute` occurs,
|
|
9
|
+
// both legs unwind and refund simultaneously. Half-funded or half-released states cannot occur.
|
|
10
|
+
//
|
|
11
|
+
// ### Selection guidance
|
|
12
|
+
// - vs `held_payment`: `swap` is a bilateral trade where both sides must deposit funds into escrow and receive each other's
|
|
13
|
+
// disbursements simultaneously. `held_payment` is unilateral escrow where a single payer funds a payment held for a payee.
|
|
14
|
+
// - vs `instant_transfer`: `instant_transfer` executes an immediate one-way transfer. `swap` coordinates two reciprocal transfers
|
|
15
|
+
// held atomically in escrow until release confirmation.
|
|
16
|
+
//
|
|
17
|
+
// ### Parameters
|
|
18
|
+
// - `between`: List containing exactly two trade participant parties (`[side_a, side_b]`).
|
|
19
|
+
// - `amounts`: Block declaring the principal money amounts for each party.
|
|
20
|
+
// - `fees`: Block declaring the platform fee money amounts for each party.
|
|
21
|
+
// - `release`: Condition port required to execute the atomic swap release.
|
|
22
|
+
// - `dispute`: Condition port triggering unwinding and refunding of both trade legs.
|
|
23
|
+
// - `side_names`: Optional custom naming block for the two sides (`first`, `second`).
|
|
24
|
+
// - `lifecycle_state_order`: Optional custom ordering for lifecycle states.
|
|
25
|
+
// - `action_bindings`: Optional custom action names.
|
|
26
|
+
// - `parked_states`: Optional configuration for parked states.
|
|
27
|
+
// - `fixed_prefix`: Optional custom prefix for generated instrument IDs.
|
|
28
|
+
//
|
|
29
|
+
// ### Decision ports
|
|
30
|
+
// - `release`: Port authorizing atomic settlement of both trade legs.
|
|
31
|
+
// - `dispute`: Port triggering atomic cancellation and refund of both parties.
|
|
32
|
+
//
|
|
33
|
+
// ### Example
|
|
34
|
+
// ```hsx
|
|
35
|
+
// program swap_example "Swap example"
|
|
36
|
+
// import { swap } from "std/money_flows"
|
|
37
|
+
// party buyer: business
|
|
38
|
+
// party seller: business
|
|
39
|
+
// settlement exchange = swap {
|
|
40
|
+
// between: [buyer, seller]
|
|
41
|
+
// amounts {
|
|
42
|
+
// buyer: buyerAmount: money(SAR)
|
|
43
|
+
// seller: sellerAmount: money(SAR)
|
|
44
|
+
// }
|
|
45
|
+
// fees {
|
|
46
|
+
// buyer: buyerFee: money(SAR)
|
|
47
|
+
// seller: sellerFee: money(SAR)
|
|
48
|
+
// }
|
|
49
|
+
// release: port release_exchange
|
|
50
|
+
// dispute: port dispute_exchange within P7D
|
|
51
|
+
// }
|
|
52
|
+
// port release_exchange { allowed: [buyer, seller] }
|
|
53
|
+
// port dispute_exchange { allowed: [buyer, seller] }
|
|
54
|
+
// ```
|
|
2
55
|
export instrument swap<C>(between: list<party>, amounts: block, fees: block, release: condition, dispute: condition, side_names: optional<block>, lifecycle_state_order: optional<list<text>>, action_bindings: optional<block>, parked_states: optional<block>, fixed_prefix: optional<text>) {
|
|
3
56
|
let(side_a): at(between, 1);
|
|
4
57
|
let(side_b): at(between, 2);
|
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
module std.money_flows.threshold_pool
|
|
2
2
|
|
|
3
|
+
// All-or-nothing capital accumulation pool collecting commitments toward a target amount before a close deadline.
|
|
4
|
+
//
|
|
5
|
+
// ### Purpose
|
|
6
|
+
// `threshold_pool` powers all-or-nothing crowdfunding, capital calls, collective purchasing, and consortium rounds.
|
|
7
|
+
// Multiple contributors pledge commitments toward a monetary `target`. Commitments sit in escrow until the pool
|
|
8
|
+
// reaches the target before `close_by` (activating and settling funds to the beneficiary), or fails (triggering full refunds).
|
|
9
|
+
//
|
|
10
|
+
// ### Selection guidance
|
|
11
|
+
// - vs `rotating_pool`: `threshold_pool` is all-or-nothing fundraising where many contributors fund a single beneficiary.
|
|
12
|
+
// `rotating_pool` is a peer savings circle where members contribute identically in each cycle and rotate who receives the pot.
|
|
13
|
+
// - vs `weighted_distribution`: `threshold_pool` pools funds inward from many contributors to one beneficiary.
|
|
14
|
+
// `weighted_distribution` pays funds outward from one source pool to many weighted recipients.
|
|
15
|
+
//
|
|
16
|
+
// ### Parameters
|
|
17
|
+
// - `contributor`: The archetype party representing individual contributors.
|
|
18
|
+
// - `beneficiary`: The beneficiary party receiving the settled pool if the target is met.
|
|
19
|
+
// - `target`: Total target funding threshold in minor units of currency `C`.
|
|
20
|
+
// - `commitment`: Binding name for individual contributor commitment amounts.
|
|
21
|
+
// - `max_contributors`: Optional maximum count of admitted contributors.
|
|
22
|
+
// - `close_by`: Stored date deadline by which the target must be met.
|
|
23
|
+
// - `close_policy`: Policy determining pool close behavior (`threshold`).
|
|
24
|
+
// - `overfund_policy`: Policy on commitments exceeding the target (`reject`).
|
|
25
|
+
// - `cancel_policy`: Contributor withdrawal policy before close (`before_close`).
|
|
26
|
+
// - `fail_policy`: Refund policy if the pool fails to hit target (`whole_commitment_refund`).
|
|
27
|
+
// - `beneficiary_account`: Optional direct account reference for the beneficiary.
|
|
28
|
+
// - `memo`: Optional memo text stored on the pool.
|
|
29
|
+
// - `contribution_instrument`: Optional custom contribution child instrument block.
|
|
30
|
+
// - `wording`: Optional custom UI wording block.
|
|
31
|
+
//
|
|
32
|
+
// ### Decision ports
|
|
33
|
+
// None. Lifecycle transitions (`activate`, `fail`, `close`) are driven by target threshold evaluation and the `close_by` date.
|
|
34
|
+
//
|
|
35
|
+
// ### Example
|
|
36
|
+
// ```hsx
|
|
37
|
+
// program capital_pool_example "Capital pool example"
|
|
38
|
+
// import { threshold_pool } from "std/money_flows"
|
|
39
|
+
// party contributor: person
|
|
40
|
+
// party company: business
|
|
41
|
+
// settlement round = threshold_pool {
|
|
42
|
+
// contributor: contributor
|
|
43
|
+
// beneficiary: company
|
|
44
|
+
// target: targetAmount: money(SAR)
|
|
45
|
+
// commitment: commitmentAmount: money(SAR)
|
|
46
|
+
// max_contributors: 100
|
|
47
|
+
// close_by: closeBy
|
|
48
|
+
// close_policy: threshold
|
|
49
|
+
// overfund_policy: reject
|
|
50
|
+
// cancel_policy: before_close
|
|
51
|
+
// fail_policy: whole_commitment_refund
|
|
52
|
+
// }
|
|
53
|
+
// ```
|
|
3
54
|
export instrument threshold_pool<C>(
|
|
4
55
|
contributor: optional<party>,
|
|
5
56
|
beneficiary: optional<party>,
|