@hyperscale0/hsx 2.4.1 → 3.0.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 +4 -406
- package/README.md +3 -92
- package/dist/src/ast.d.ts +99 -310
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/ast.js +16 -69
- package/dist/src/ast.js.map +1 -1
- package/dist/src/cli.d.ts +6 -19
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +77 -315
- package/dist/src/cli.js.map +1 -1
- package/dist/src/compile.d.ts +23 -73
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +1113 -148
- package/dist/src/compile.js.map +1 -1
- package/dist/src/cost.d.ts +8 -77
- package/dist/src/cost.d.ts.map +1 -1
- package/dist/src/cost.js +13 -422
- package/dist/src/cost.js.map +1 -1
- package/dist/src/format.d.ts +8 -7
- package/dist/src/format.d.ts.map +1 -1
- package/dist/src/format.js +9 -175
- package/dist/src/format.js.map +1 -1
- package/dist/src/headers.d.ts +35 -0
- package/dist/src/headers.d.ts.map +1 -0
- package/dist/src/headers.js +108 -0
- package/dist/src/headers.js.map +1 -0
- package/dist/src/index.d.ts +6 -12
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -9
- package/dist/src/index.js.map +1 -1
- package/dist/src/lex.d.ts +8 -28
- package/dist/src/lex.d.ts.map +1 -1
- package/dist/src/lex.js +88 -146
- package/dist/src/lex.js.map +1 -1
- package/dist/src/parse.d.ts +4 -17
- package/dist/src/parse.d.ts.map +1 -1
- package/dist/src/parse.js +402 -1040
- package/dist/src/parse.js.map +1 -1
- package/dist/src/std-bundle.d.ts.map +1 -1
- package/dist/src/std-bundle.js +12 -20
- package/dist/src/std-bundle.js.map +1 -1
- package/dist/src/std-library.d.ts +1 -1
- package/dist/src/std-library.d.ts.map +1 -1
- package/dist/src/std-library.js +1 -5
- package/dist/src/std-library.js.map +1 -1
- package/dist/src/tunables.d.ts +7 -0
- package/dist/src/tunables.d.ts.map +1 -0
- package/dist/src/tunables.js +26 -0
- package/dist/src/tunables.js.map +1 -0
- package/dist/src/version.d.ts +2 -4
- package/dist/src/version.d.ts.map +1 -1
- package/dist/src/version.js +2 -4
- package/dist/src/version.js.map +1 -1
- package/docs/README.md +179 -41
- package/docs/headers.md +44 -0
- package/examples/cost-table.json +99 -751
- package/examples/library.hsx +59 -0
- package/package.json +9 -17
- package/src/ast.ts +82 -441
- package/src/cli.ts +78 -362
- package/src/compile.ts +1535 -247
- package/src/cost.ts +28 -671
- package/src/format.ts +12 -256
- package/src/headers.ts +126 -0
- package/src/index.ts +7 -39
- package/src/lex.ts +99 -195
- package/src/parse.ts +403 -1209
- package/src/std-bundle.ts +12 -20
- package/src/std-library.ts +2 -7
- package/src/tunables.ts +31 -0
- package/src/version.ts +2 -5
- package/std/approvals.hsx +17 -0
- package/std/cards.hsx +63 -0
- package/std/collections.hsx +31 -0
- package/std/escrow.hsx +43 -0
- package/std/financing.hsx +372 -0
- package/std/insurance.hsx +59 -0
- package/std/lending.hsx +115 -0
- package/std/marketplace.hsx +24 -0
- package/std/money.hsx +195 -0
- package/std/savings.hsx +44 -0
- package/std/travel.hsx +98 -0
- package/std/wallet.hsx +41 -0
- package/dist/src/diagnostics.d.ts +0 -13
- package/dist/src/diagnostics.d.ts.map +0 -1
- package/dist/src/diagnostics.js +0 -587
- package/dist/src/diagnostics.js.map +0 -1
- package/dist/src/emit.d.ts +0 -51
- package/dist/src/emit.d.ts.map +0 -1
- package/dist/src/emit.js +0 -192
- package/dist/src/emit.js.map +0 -1
- package/dist/src/entry-overrides.d.ts +0 -58
- package/dist/src/entry-overrides.d.ts.map +0 -1
- package/dist/src/entry-overrides.js +0 -284
- package/dist/src/entry-overrides.js.map +0 -1
- package/dist/src/ir.d.ts +0 -73
- package/dist/src/ir.d.ts.map +0 -1
- package/dist/src/ir.js +0 -15
- package/dist/src/ir.js.map +0 -1
- package/dist/src/limits.d.ts +0 -23
- package/dist/src/limits.d.ts.map +0 -1
- package/dist/src/limits.js +0 -23
- package/dist/src/limits.js.map +0 -1
- package/dist/src/lsp/server.d.ts +0 -32
- package/dist/src/lsp/server.d.ts.map +0 -1
- package/dist/src/lsp/server.js +0 -391
- package/dist/src/lsp/server.js.map +0 -1
- package/dist/src/modules.d.ts +0 -38
- package/dist/src/modules.d.ts.map +0 -1
- package/dist/src/modules.js +0 -372
- package/dist/src/modules.js.map +0 -1
- package/dist/src/typecheck.d.ts +0 -8
- package/dist/src/typecheck.d.ts.map +0 -1
- package/dist/src/typecheck.js +0 -4160
- package/dist/src/typecheck.js.map +0 -1
- package/docs/guide/01-first-program.md +0 -24
- package/docs/guide/02-money.md +0 -25
- package/docs/guide/03-instruments.md +0 -93
- package/docs/guide/04-lifecycles.md +0 -40
- package/docs/guide/05-fees-and-splits.md +0 -45
- package/docs/guide/06-schedules.md +0 -26
- package/docs/guide/07-composition.md +0 -52
- package/docs/guide/08-writing-a-module.md +0 -85
- package/docs/guide/09-cost.md +0 -24
- package/docs/guide/10-diagnostics.md +0 -27
- package/docs/llms-full.txt +0 -3684
- package/docs/llms.txt +0 -44
- package/docs/piece-plans.md +0 -120
- package/docs/playground.md +0 -55
- package/docs/reference/cli.md +0 -36
- package/docs/reference/diagnostics.md +0 -901
- package/docs/reference/grammar.md +0 -38
- package/docs/reference/std/advance.md +0 -112
- package/docs/reference/std/cancellable_booking.md +0 -159
- package/docs/reference/std/captured_payment.md +0 -115
- package/docs/reference/std/conditional_disbursement.md +0 -101
- package/docs/reference/std/credit_facility.md +0 -108
- package/docs/reference/std/held_payment.md +0 -173
- package/docs/reference/std/instant_transfer.md +0 -97
- package/docs/reference/std/metered.md +0 -89
- package/docs/reference/std/pooled_split.md +0 -95
- package/docs/reference/std/premium_forward.md +0 -119
- package/docs/reference/std/reconciled_payout.md +0 -103
- package/docs/reference/std/rotating_pool.md +0 -130
- package/docs/reference/std/scheduled.md +0 -136
- package/docs/reference/std/security_deposit.md +0 -138
- package/docs/reference/std/settlement_batch.md +0 -123
- package/docs/reference/std/swap.md +0 -133
- package/docs/reference/std/threshold_pool.md +0 -138
- package/docs/reference/std/weighted_distribution.md +0 -135
- package/docs/reference/types.md +0 -61
- package/docs/reference/udl-output.md +0 -13
- package/examples/01-first-program/README.md +0 -45
- package/examples/01-first-program/tip-jar.hsx +0 -17
- package/examples/02-imports-and-modules/README.md +0 -96
- package/examples/02-imports-and-modules/photo-booth.hsx +0 -37
- package/examples/03-diagnostics/README.md +0 -68
- package/examples/03-diagnostics/corner-shop-fixed.hsx +0 -22
- package/examples/03-diagnostics/corner-shop.hsx +0 -19
- package/examples/04-complete-product/README.md +0 -84
- package/examples/04-complete-product/study-hall.hsx +0 -67
- package/examples/05-authored-instrument/README.md +0 -5
- package/examples/05-authored-instrument/payment.hsx +0 -37
- package/examples/05-watch-club/README.md +0 -6
- package/examples/05-watch-club/watch-club.hsx +0 -123
- package/examples/README.md +0 -48
- package/examples/advance/README.md +0 -3
- package/examples/advance/advance.hsx +0 -13
- package/examples/advance/advance.udl +0 -367
- package/examples/cancellable_booking/README.md +0 -3
- package/examples/cancellable_booking/cancellable_booking.hsx +0 -14
- package/examples/cancellable_booking/cancellable_booking.udl +0 -413
- package/examples/captured_payment/README.md +0 -3
- package/examples/captured_payment/captured_payment.hsx +0 -17
- package/examples/captured_payment/captured_payment.udl +0 -686
- package/examples/conditional_disbursement/README.md +0 -3
- package/examples/conditional_disbursement/conditional_disbursement.hsx +0 -15
- package/examples/conditional_disbursement/conditional_disbursement.udl +0 -418
- package/examples/credit_facility/README.md +0 -3
- package/examples/credit_facility/credit_facility.hsx +0 -24
- package/examples/credit_facility/credit_facility.udl +0 -1396
- package/examples/held_payment/README.md +0 -3
- package/examples/held_payment/held_payment.hsx +0 -13
- package/examples/held_payment/held_payment.udl +0 -569
- package/examples/instant_transfer/README.md +0 -3
- package/examples/instant_transfer/instant_transfer.hsx +0 -16
- package/examples/instant_transfer/instant_transfer.udl +0 -376
- package/examples/metered/README.md +0 -3
- package/examples/metered/metered.hsx +0 -13
- package/examples/metered/metered.udl +0 -253
- package/examples/pooled_split/README.md +0 -3
- package/examples/pooled_split/pooled_split.hsx +0 -15
- package/examples/pooled_split/pooled_split.udl +0 -432
- package/examples/premium_forward/README.md +0 -3
- package/examples/premium_forward/premium_forward.hsx +0 -19
- package/examples/premium_forward/premium_forward.udl +0 -604
- package/examples/reconciled_payout/README.md +0 -3
- package/examples/reconciled_payout/reconciled_payout.hsx +0 -13
- package/examples/reconciled_payout/reconciled_payout.udl +0 -312
- package/examples/rotating_pool/README.md +0 -3
- package/examples/rotating_pool/rotating_pool.hsx +0 -18
- package/examples/rotating_pool/rotating_pool.udl +0 -4370
- package/examples/scheduled/README.md +0 -3
- package/examples/scheduled/scheduled.hsx +0 -12
- package/examples/scheduled/scheduled.udl +0 -355
- package/examples/security_deposit/README.md +0 -3
- package/examples/security_deposit/security_deposit.hsx +0 -21
- package/examples/security_deposit/security_deposit.udl +0 -320
- package/examples/settlement_batch/README.md +0 -3
- package/examples/settlement_batch/settlement_batch.hsx +0 -19
- package/examples/settlement_batch/settlement_batch.udl +0 -757
- package/examples/swap/README.md +0 -3
- package/examples/swap/swap.hsx +0 -19
- package/examples/swap/swap.udl +0 -892
- package/examples/threshold_pool/README.md +0 -3
- package/examples/threshold_pool/threshold_pool.hsx +0 -16
- package/examples/threshold_pool/threshold_pool.udl +0 -680
- package/examples/weighted_distribution/README.md +0 -3
- package/examples/weighted_distribution/weighted_distribution.hsx +0 -20
- package/examples/weighted_distribution/weighted_distribution.udl +0 -348
- package/skills/hsx/SKILL.md +0 -449
- package/src/diagnostics.ts +0 -620
- package/src/emit.ts +0 -282
- package/src/entry-overrides.ts +0 -428
- package/src/ir.ts +0 -113
- package/src/limits.ts +0 -22
- package/src/lsp/server.ts +0 -460
- package/src/modules.ts +0 -452
- package/src/typecheck.ts +0 -5515
- package/std/SEMANTICS.md +0 -44
- package/std/money_flows/advance.hsx +0 -235
- package/std/money_flows/cancellable_booking.hsx +0 -402
- package/std/money_flows/captured_payment.hsx +0 -220
- package/std/money_flows/conditional_disbursement.hsx +0 -226
- package/std/money_flows/credit_facility.hsx +0 -214
- package/std/money_flows/held_payment.hsx +0 -812
- package/std/money_flows/index.hsx +0 -4
- package/std/money_flows/instant_transfer.hsx +0 -231
- package/std/money_flows/metered.hsx +0 -104
- package/std/money_flows/pooled_split.hsx +0 -109
- package/std/money_flows/premium_forward.hsx +0 -307
- package/std/money_flows/reconciled_payout.hsx +0 -119
- package/std/money_flows/rotating_pool.hsx +0 -305
- package/std/money_flows/scheduled.hsx +0 -599
- package/std/money_flows/security_deposit.hsx +0 -248
- package/std/money_flows/settlement_batch.hsx +0 -173
- package/std/money_flows/swap.hsx +0 -1192
- package/std/money_flows/threshold_pool.hsx +0 -307
- package/std/money_flows/weighted_distribution.hsx +0 -237
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
module std.money_flows.instant_transfer
|
|
2
|
-
|
|
3
|
-
// Direct, single-step push transfer from payer to payee with optional tiered or percentage fees.
|
|
4
|
-
//
|
|
5
|
-
// ### Purpose
|
|
6
|
-
// `instant_transfer` debits a payer and credits a payee immediately in a single execution step.
|
|
7
|
-
// It fits peer-to-peer transfers, direct disbursements, instant payouts, wallet reloads, and simple point-of-sale payments.
|
|
8
|
-
//
|
|
9
|
-
// ### Selection guidance
|
|
10
|
-
// - vs `captured_payment`: `instant_transfer` moves money in one atomic step without prior authorization holds,
|
|
11
|
-
// incremental captures, voids, or post-settlement correction ports. Use `captured_payment` when authorization must precede capture.
|
|
12
|
-
// - vs `conditional_disbursement`: `instant_transfer` executes immediately without external decision evidence
|
|
13
|
-
// or cumulative cap tracking. Use `conditional_disbursement` when payments require evidence submission or aggregate milestone caps.
|
|
14
|
-
// - vs `held_payment`: `instant_transfer` never holds funds in an intermediary escrow account.
|
|
15
|
-
//
|
|
16
|
-
// ### Parameters
|
|
17
|
-
// - `payer`: Funding party whose account is debited.
|
|
18
|
-
// - `payee`: Recipient party whose account is credited.
|
|
19
|
-
// - `amount`: Transfer amount in minor units of currency `C`.
|
|
20
|
-
// - `fees`: Optional fee configuration block specifying flat fees, percentage fees, or bracketed fee tiers for payer and/or payee.
|
|
21
|
-
// - `derived_amount`: Optional block declaring derived platform fees calculated from the transfer amount.
|
|
22
|
-
//
|
|
23
|
-
// ### Decision ports
|
|
24
|
-
// None. Transfers execute immediately upon invocation.
|
|
25
|
-
//
|
|
26
|
-
// ### Example
|
|
27
|
-
// ```hsx
|
|
28
|
-
// program instant_transfer_example "Instant transfer example"
|
|
29
|
-
// import { instant_transfer } from "std/money_flows"
|
|
30
|
-
// party customer: person
|
|
31
|
-
// party merchant: business
|
|
32
|
-
// settlement transfer = instant_transfer {
|
|
33
|
-
// payer: customer
|
|
34
|
-
// payee: merchant
|
|
35
|
-
// amount: transferAmount: money(SAR)
|
|
36
|
-
// fees {
|
|
37
|
-
// customer: checkoutFee: money(SAR)
|
|
38
|
-
// merchant {
|
|
39
|
-
// tier { from: 0, to: 10000, fee: 1% }
|
|
40
|
-
// tier { from: 10000, fee: highValueFee: money(SAR) }
|
|
41
|
-
// }
|
|
42
|
-
// }
|
|
43
|
-
// }
|
|
44
|
-
// ```
|
|
45
|
-
export instrument instant_transfer<C>(payer: party, payee: party, amount: money<C>, fees: optional<block>, derived_amount: optional<block>) {
|
|
46
|
-
let(payer_fee): get(fees, payer);
|
|
47
|
-
let(payee_fee): get(fees, payee);
|
|
48
|
-
let(payer_fee_kind): kind(payer_fee);
|
|
49
|
-
let(payee_fee_kind): kind(payee_fee);
|
|
50
|
-
let(payer_account_field): camel(concat(payer, "_account_id"));
|
|
51
|
-
let(payee_account_field): camel(concat(payee, "_account_id"));
|
|
52
|
-
let(net_bps): sub(10000, payee_fee);
|
|
53
|
-
let(net_percent): percent_text(net_bps);
|
|
54
|
-
let(payee_bps): basis_points(payee_fee);
|
|
55
|
-
let(payee_tiers): values(payee_fee);
|
|
56
|
-
let(first_tier): at(payee_tiers, 1);
|
|
57
|
-
let(second_tier): at(payee_tiers, 2);
|
|
58
|
-
let(second_tier_fee): get(second_tier, "fee");
|
|
59
|
-
when(derived_amount) {
|
|
60
|
-
let(derived_field): get(derived_amount, "field");
|
|
61
|
-
let(derived_source): get(derived_amount, "source");
|
|
62
|
-
let(derived_rule): get(derived_amount, "rule");
|
|
63
|
-
let(derived_bearer): get(derived_amount, "bearer");
|
|
64
|
-
}
|
|
65
|
-
agent_description: concat("Reach for instant transfer when the ", words(payer), " pays the ", words(payee), " straight through with no custody step. The money leaves and lands in one call. Pick deposit when the money must be held first, and captured payment when the payee takes it in slices.");
|
|
66
|
-
summary: concat("Instant payment from ", words(payer), " to ", words(payee));
|
|
67
|
-
title: sentence(instrument);
|
|
68
|
-
description: concat("Instant transfer: the ", words(payer), " pays ", amount, " straight through to the ", words(payee), ", no custody");
|
|
69
|
-
fields {
|
|
70
|
-
when_not(fees) {
|
|
71
|
-
when(derived_amount) {
|
|
72
|
-
let(fee_collection_key): "x-hyperscale-fee-collection-port";
|
|
73
|
-
let(reference_filter_key): "x-hyperscale-reference-filter";
|
|
74
|
-
platformAccountId {
|
|
75
|
-
type: account<C>;
|
|
76
|
-
description: "The product fee collection account";
|
|
77
|
-
[fee_collection_key]: true;
|
|
78
|
-
[reference_filter_key]: { column: role; values: [customer_balance, product_revenue]; };
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
when(fees) {
|
|
83
|
-
let(fee_collection_key): "x-hyperscale-fee-collection-port";
|
|
84
|
-
let(reference_filter_key): "x-hyperscale-reference-filter";
|
|
85
|
-
platformAccountId {
|
|
86
|
-
type: account<C>;
|
|
87
|
-
description: "The product fee collection account";
|
|
88
|
-
[fee_collection_key]: true;
|
|
89
|
-
[reference_filter_key]: { column: role; values: [customer_balance, product_revenue]; };
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
when_not(fees) {
|
|
93
|
-
amount { type: money<C>; description: "The amount in {C} minor units, paid through whole"; }
|
|
94
|
-
}
|
|
95
|
-
when(fees) {
|
|
96
|
-
amount { type: money<C>; description: "The gross amount in {C} minor units; the piece fields below partition it exactly"; }
|
|
97
|
-
when_eq(payee_fee_kind, percent) {
|
|
98
|
-
piece1Amount { type: money<C>; description: concat(net_percent, " of ", amount, " (carries the integer-division remainder): released to the ", payee, ". Computed as floor(", amount, " * ", net_bps, " / 10000) in ", C, " minor units"); pattern: "^[1-9][0-9]{0,17}$"; }
|
|
99
|
-
piece2Amount { type: money<C>; description: concat(payee_fee, " of ", amount, ": released to the platform. Computed as floor(", amount, " * ", payee_bps, " / 10000) in ", C, " minor units"); pattern: "^[1-9][0-9]{0,17}$"; optional: true; }
|
|
100
|
-
}
|
|
101
|
-
when_eq(payee_fee_kind, block) {
|
|
102
|
-
netOfCarvedFeeAmount { type: money<C>; description: "The remainder of {amount} after the carved platform fee"; pattern: "^[1-9][0-9]{0,17}$"; }
|
|
103
|
-
carvedFeeAmount { type: money<C>; description: "The carved platform fee selected from {amount}"; pattern: "^[1-9][0-9]{0,17}$"; optional: true; }
|
|
104
|
-
}
|
|
105
|
-
when_eq(payer_fee_kind, percent) {
|
|
106
|
-
serviceFeeAmount { type: money<C>; description: "Machine-owned {payer_fee} service fee computed from {amount}; charged on top"; pattern: "^[1-9][0-9]{0,17}$"; optional: true; }
|
|
107
|
-
}
|
|
108
|
-
when_eq(payer_fee_kind, binding) {
|
|
109
|
-
[payer_fee] { type: payer_fee; description: "Immutable exact {payer} fee in {C} minor units"; pattern: "^[1-9][0-9]{0,17}$"; }
|
|
110
|
-
}
|
|
111
|
-
when_eq(payee_fee_kind, block) {
|
|
112
|
-
[second_tier_fee] { type: second_tier_fee; description: "Immutable exact {payee} fee in {C} minor units"; pattern: "^[1-9][0-9]{0,17}$"; }
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
when(derived_amount) {
|
|
116
|
-
[derived_field] { type: money<C>; description: "Machine-computed {derived_rule} of {derived_source}; callers never supply it"; pattern: "^[1-9][0-9]{0,17}$"; optional: true; }
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
lifecycle {
|
|
120
|
-
when_not(fees) { states created paid; }
|
|
121
|
-
when(fees) { states created paying_1 paying_2 paid; }
|
|
122
|
-
initial created;
|
|
123
|
-
when_not(fees) { on pay_piece_1: created -> paid; }
|
|
124
|
-
when(fees) {
|
|
125
|
-
on pay_piece_1: created -> paying_1;
|
|
126
|
-
on pay_piece_2: paying_1 -> paying_2;
|
|
127
|
-
on collect_service_fee: paying_2 -> paid;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
parties {
|
|
131
|
-
payer: payer;
|
|
132
|
-
beneficiary: payee;
|
|
133
|
-
}
|
|
134
|
-
when(derived_amount) {
|
|
135
|
-
computes derived: { field: derived_field; source_field: derived_source; rounding: floor; rule: { kind: percentage_of; bps: derived_rule; }; };
|
|
136
|
-
}
|
|
137
|
-
when(fees) {
|
|
138
|
-
when_eq(payer_fee_kind, percent) {
|
|
139
|
-
computes fees: { amount_field: serviceFeeAmount; base_field: amount; bearer_field: payer_account_field; position: on_top; rule: { kind: bps; bps: payer_fee; }; };
|
|
140
|
-
}
|
|
141
|
-
when_eq(payer_fee_kind, binding) {
|
|
142
|
-
computes fees: { amount_field: camel(payer_fee); base_field: amount; bearer_field: payer_account_field; position: on_top; rule: { kind: exact; field: camel(payer_fee); currency_field: currency; }; };
|
|
143
|
-
}
|
|
144
|
-
when_eq(payee_fee_kind, percent) {
|
|
145
|
-
computes fees: { amount_field: piece2Amount; base_field: amount; bearer_field: payee_account_field; position: carved; rule: { kind: bps; bps: payee_fee; }; };
|
|
146
|
-
partitions: { total_field: amount; piece_fields: [piece1Amount, piece2Amount]; };
|
|
147
|
-
}
|
|
148
|
-
when_eq(payee_fee_kind, block) {
|
|
149
|
-
computes fees: { amount_field: carvedFeeAmount; base_field: amount; bearer_field: payee_account_field; position: carved; rule: { kind: tiered; tiers: [{ from_inclusive: concat("", get(first_tier, "from")); to_exclusive: concat("", get(first_tier, "to")); rule: { kind: bps; bps: get(first_tier, "fee"); }; }, { from_inclusive: concat("", get(second_tier, "from")); rule: { kind: exact; field: camel(second_tier_fee); currency_field: currency; }; }]; }; };
|
|
150
|
-
partitions: { total_field: amount; piece_fields: [netOfCarvedFeeAmount, carvedFeeAmount]; };
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
action create {
|
|
154
|
-
let(metadata_instrument): "metadata.instrumentId";
|
|
155
|
-
let(metadata_instance): "metadata.instrumentInstanceId";
|
|
156
|
-
let(metadata_phase): "metadata.phase";
|
|
157
|
-
agent_description: "Open the payment row before anything moves. The caller supplies the {amount}, the currency, and both party accounts. Fee and derived pieces are computed from the {amount}, callers never supply them. Call pay piece 1 to move the money.";
|
|
158
|
-
summary: concat("Create a ", words(instrument), " payment");
|
|
159
|
-
when(derived_amount) {
|
|
160
|
-
moves: [{
|
|
161
|
-
key: "derived_amount";
|
|
162
|
-
operation: internal_transfer.create;
|
|
163
|
-
bind: {
|
|
164
|
-
amount: { from: instance; path: concat("fields.", derived_field); };
|
|
165
|
-
currency: { from: instance; path: fields.currency; };
|
|
166
|
-
destinationAccountId: { from: instance; path: fields.platformAccountId; };
|
|
167
|
-
[metadata_instrument]: { from: const; value: instrument; };
|
|
168
|
-
[metadata_instance]: { from: instance; path: instrumentInstanceId; };
|
|
169
|
-
[metadata_phase]: { from: const; value: create; };
|
|
170
|
-
productId: { from: instance; path: productId; };
|
|
171
|
-
sourceAccountId: { from: instance; path: concat("fields.", camel(derived_bearer), "AccountId"); };
|
|
172
|
-
};
|
|
173
|
-
capture: { createDerivedAmountTransferId: transferId; };
|
|
174
|
-
}];
|
|
175
|
-
}
|
|
176
|
-
steps: [];
|
|
177
|
-
}
|
|
178
|
-
action pay_piece_1 {
|
|
179
|
-
let(metadata_instrument): "metadata.instrumentId";
|
|
180
|
-
let(metadata_instance): "metadata.instrumentInstanceId";
|
|
181
|
-
let(metadata_phase): "metadata.phase";
|
|
182
|
-
agent_description: concat("Move the first piece from the ", words(payer), " to the ", words(payee), ". The payment must be created. This moves the whole amount unless the product carves a payee fee, in which case it moves the net share and pay piece 2 takes the fee.");
|
|
183
|
-
summary: "Pay piece 1 of the amount through";
|
|
184
|
-
when_not(fees) {
|
|
185
|
-
moves: [{ key: transfer; amount: amount; from: payer; to: beneficiary; }];
|
|
186
|
-
}
|
|
187
|
-
when(fees) {
|
|
188
|
-
when_eq(payee_fee_kind, none) {
|
|
189
|
-
moves: [{ key: transfer; amount: amount; from: payer; to: beneficiary; }];
|
|
190
|
-
}
|
|
191
|
-
when_eq(payee_fee_kind, percent) {
|
|
192
|
-
moves: [{ key: transfer; operation: internal_transfer.create; bind: { amount: { from: instance; path: fields.piece1Amount; }; currency: { from: instance; path: fields.currency; }; destinationAccountId: { from: instance; path: concat("fields.", payee_account_field); }; [metadata_instrument]: { from: const; value: instrument; }; [metadata_instance]: { from: instance; path: instrumentInstanceId; }; [metadata_phase]: { from: const; value: pay_piece_1; }; productId: { from: instance; path: productId; }; sourceAccountId: { from: instance; path: concat("fields.", payer_account_field); }; }; capture: { payPiece1TransferTransferId: transferId; }; }];
|
|
193
|
-
}
|
|
194
|
-
when_eq(payee_fee_kind, block) {
|
|
195
|
-
moves: [{ key: transfer; operation: internal_transfer.create; bind: { amount: { from: instance; path: fields.netOfCarvedFeeAmount; }; currency: { from: instance; path: fields.currency; }; destinationAccountId: { from: instance; path: concat("fields.", payee_account_field); }; [metadata_instrument]: { from: const; value: instrument; }; [metadata_instance]: { from: instance; path: instrumentInstanceId; }; [metadata_phase]: { from: const; value: pay_piece_1; }; productId: { from: instance; path: productId; }; sourceAccountId: { from: instance; path: concat("fields.", payer_account_field); }; }; capture: { payPiece1TransferTransferId: transferId; }; }];
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
sandbox_failure_point: funding;
|
|
199
|
-
steps: [];
|
|
200
|
-
}
|
|
201
|
-
when(fees) {
|
|
202
|
-
action pay_piece_2 {
|
|
203
|
-
let(metadata_instrument): "metadata.instrumentId";
|
|
204
|
-
let(metadata_instance): "metadata.instrumentInstanceId";
|
|
205
|
-
let(metadata_phase): "metadata.phase";
|
|
206
|
-
agent_description: concat("Move the carved platform fee out of the amount. Call this after pay piece 1. When the product carves no ", words(payee), " fee this only steps the payment forward and moves nothing.");
|
|
207
|
-
summary: "Pay piece 2 of the amount through";
|
|
208
|
-
when_eq(payee_fee_kind, percent) {
|
|
209
|
-
moves: [{ key: transfer; operation: internal_transfer.create; bind: { amount: { from: instance; path: fields.piece2Amount; }; currency: { from: instance; path: fields.currency; }; destinationAccountId: { from: instance; path: fields.platformAccountId; }; [metadata_instrument]: { from: const; value: instrument; }; [metadata_instance]: { from: instance; path: instrumentInstanceId; }; [metadata_phase]: { from: const; value: pay_piece_2; }; productId: { from: instance; path: productId; }; sourceAccountId: { from: instance; path: concat("fields.", payer_account_field); }; }; capture: { payPiece2TransferTransferId: transferId; }; }];
|
|
210
|
-
}
|
|
211
|
-
when_eq(payee_fee_kind, block) {
|
|
212
|
-
moves: [{ key: transfer; operation: internal_transfer.create; bind: { amount: { from: instance; path: fields.carvedFeeAmount; }; currency: { from: instance; path: fields.currency; }; destinationAccountId: { from: instance; path: fields.platformAccountId; }; [metadata_instrument]: { from: const; value: instrument; }; [metadata_instance]: { from: instance; path: instrumentInstanceId; }; [metadata_phase]: { from: const; value: pay_piece_2; }; productId: { from: instance; path: productId; }; sourceAccountId: { from: instance; path: concat("fields.", payer_account_field); }; }; capture: { payPiece2TransferTransferId: transferId; }; }];
|
|
213
|
-
}
|
|
214
|
-
steps: [];
|
|
215
|
-
}
|
|
216
|
-
action collect_service_fee {
|
|
217
|
-
let(metadata_instrument): "metadata.instrumentId";
|
|
218
|
-
let(metadata_instance): "metadata.instrumentInstanceId";
|
|
219
|
-
let(metadata_phase): "metadata.phase";
|
|
220
|
-
agent_description: concat("Finish the payment and collect the service fee the ", words(payer), " owes on top of the amount. Both pieces must already be paid. When the product charges no payer fee this only closes the payment out.");
|
|
221
|
-
summary: "Collect the payer-side service fee";
|
|
222
|
-
when_eq(payer_fee_kind, percent) {
|
|
223
|
-
moves: [{ key: transfer; operation: internal_transfer.create; bind: { amount: { from: instance; path: fields.serviceFeeAmount; }; currency: { from: instance; path: fields.currency; }; destinationAccountId: { from: instance; path: fields.platformAccountId; }; [metadata_instrument]: { from: const; value: instrument; }; [metadata_instance]: { from: instance; path: instrumentInstanceId; }; [metadata_phase]: { from: const; value: collect_service_fee; }; productId: { from: instance; path: productId; }; sourceAccountId: { from: instance; path: concat("fields.", payer_account_field); }; }; capture: { collectServiceFeeTransferTransferId: transferId; }; }];
|
|
224
|
-
}
|
|
225
|
-
when_eq(payer_fee_kind, binding) {
|
|
226
|
-
moves: [{ key: transfer; operation: internal_transfer.create; bind: { amount: { from: instance; path: concat("fields.", payer_fee); }; currency: { from: instance; path: fields.currency; }; destinationAccountId: { from: instance; path: fields.platformAccountId; }; [metadata_instrument]: { from: const; value: instrument; }; [metadata_instance]: { from: instance; path: instrumentInstanceId; }; [metadata_phase]: { from: const; value: collect_service_fee; }; productId: { from: instance; path: productId; }; sourceAccountId: { from: instance; path: concat("fields.", payer_account_field); }; }; capture: { collectServiceFeeTransferTransferId: transferId; }; }];
|
|
227
|
-
}
|
|
228
|
-
steps: [];
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
module std.money_flows.metered
|
|
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
|
-
//
|
|
15
|
-
// ### Parameters
|
|
16
|
-
// - `payer`: The customer being billed for usage.
|
|
17
|
-
// - `payee`: The service provider receiving usage revenue.
|
|
18
|
-
// - `close_by`: Date when the metering period closes, preventing further usage charges.
|
|
19
|
-
// - `rates`: Block mapping rate metric names to their per-unit money prices committed at period open.
|
|
20
|
-
//
|
|
21
|
-
// ### Decision ports
|
|
22
|
-
// None. Charges are driven by caller billing actions and period closure.
|
|
23
|
-
//
|
|
24
|
-
// ### Example
|
|
25
|
-
// ```hsx
|
|
26
|
-
// program metered_example "Metered example"
|
|
27
|
-
// import { metered } from "std/money_flows"
|
|
28
|
-
// party customer: business
|
|
29
|
-
// party provider: business
|
|
30
|
-
// settlement usage = metered {
|
|
31
|
-
// payer: customer
|
|
32
|
-
// payee: provider
|
|
33
|
-
// close_by: periodEnd
|
|
34
|
-
// rates {
|
|
35
|
-
// api_call: callRate: money(SAR)
|
|
36
|
-
// storage_gib: storageRate: money(SAR)
|
|
37
|
-
// }
|
|
38
|
-
// }
|
|
39
|
-
// ```
|
|
40
|
-
export instrument metered(
|
|
41
|
-
payer: party,
|
|
42
|
-
payee: party,
|
|
43
|
-
close_by: date,
|
|
44
|
-
rates: unknown,
|
|
45
|
-
) {
|
|
46
|
-
let(instrument_words): words(instrument);
|
|
47
|
-
title: sentence(instrument);
|
|
48
|
-
agent_description: "Reach for metered when the {payer} is billed per unit at a rate card fixed when the period opens, and the period closes on {close_by}. Every charge is its own transfer. Pick scheduled for a flat repeating amount and instant transfer for a one-off payment.";
|
|
49
|
-
summary: "Metered charges from {payer} on a committed rate card";
|
|
50
|
-
description: "Metered usage: the {payer} is charged per unit at the committed rate card until the period closes on its stored end date";
|
|
51
|
-
|
|
52
|
-
fields {
|
|
53
|
-
close_by: {
|
|
54
|
-
type: date;
|
|
55
|
-
description: "End of this metering period; the close makes further charges unreachable";
|
|
56
|
-
}
|
|
57
|
-
for item in keys(rates) {
|
|
58
|
-
let(amount_binding): get(rates, item);
|
|
59
|
-
let(rate_words): words(item);
|
|
60
|
-
[amount_binding]: {
|
|
61
|
-
type: amount_binding;
|
|
62
|
-
description: "Per-unit price of {rate_words} in SAR minor units, committed at period open";
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
parties {
|
|
68
|
-
payer: payer;
|
|
69
|
-
beneficiary: payee;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
lifecycle {
|
|
73
|
-
states open closed;
|
|
74
|
-
initial open;
|
|
75
|
-
for item in keys(rates) {
|
|
76
|
-
on charge_[item]: open -> open;
|
|
77
|
-
}
|
|
78
|
-
on close_period: open -> closed;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
action create {
|
|
82
|
-
agent_description: "Open the metering period with its committed rate card. The caller supplies the {close_by} anchor and every per-unit price. The prices are fixed here and no later charge can change them. No money moves.";
|
|
83
|
-
summary: "Open a {instrument_words} period with its committed rate card";
|
|
84
|
-
steps: [];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
for item in keys(rates) {
|
|
88
|
-
action charge_[item] {
|
|
89
|
-
let(amount_binding): get(rates, item);
|
|
90
|
-
let(amount_field): concat(amount_binding);
|
|
91
|
-
let(rate_words): words(item);
|
|
92
|
-
agent_description: "Charge one metered {rate_words} at the committed price. The period must still be open, so charge before {close_by}. The transfer posts from the {payer} to the {payee} at once and there is no reversal action.";
|
|
93
|
-
summary: "Charge one metered {rate_words}; the emission is the transfer itself";
|
|
94
|
-
moves: [{ amount: amount_field; from: payer; to: beneficiary; key: transfer; }];
|
|
95
|
-
steps: [];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
action close_period {
|
|
100
|
-
summary: "Close the metering period; no further usage can be charged";
|
|
101
|
-
due: { field: close_by; };
|
|
102
|
-
steps: [];
|
|
103
|
-
}
|
|
104
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
module std.money_flows.pooled_split
|
|
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
|
-
// ```
|
|
44
|
-
export instrument pooled_split<C>(payer: party, amount: money<C>, payout_due: date, split: block) {
|
|
45
|
-
let(recipients): keys_except(split, "remainder_to");
|
|
46
|
-
let(recipient_count): len(recipients);
|
|
47
|
-
let(remainder_recipient): get(split, "remainder_to");
|
|
48
|
-
fields {
|
|
49
|
-
currency { type: text; description: "ISO 4217 currency code"; minLength: 3; maxLength: 3; pattern: "^[A-Z]{3}$"; }
|
|
50
|
-
[payer]AccountId { type: account<C>; description: concat("The ", words(payer), " account"); "x-hyperscale-reference-filter": { column: role; values: [customer_balance]; }; }
|
|
51
|
-
amount { type: money<C>; description: concat("The pooled period total in {C} minor units; the share fields below partition it exactly"); }
|
|
52
|
-
payout_due { type: date; description: "The period's payout date; the pool distributes from it"; }
|
|
53
|
-
for index in recipient_count {
|
|
54
|
-
let(recipient): at(recipients, index);
|
|
55
|
-
let(share_bps): get(split, recipient);
|
|
56
|
-
[recipient]AccountId { type: account<C>; description: concat("The ", words(recipient), " account"); "x-hyperscale-reference-filter": { column: role; values: [customer_balance]; }; }
|
|
57
|
-
[recipient]ShareAmount {
|
|
58
|
-
type: money<C>;
|
|
59
|
-
description: concat(div_floor(basis_points(share_bps), 100), "% of ", amount, if_eq(recipient, remainder_recipient, " (carries the integer-division remainder): ", ": "), "the ", words(recipient), "'s share. Computed as floor(", amount, " * ", basis_points(share_bps), " / 10000) in {C} minor units");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
lifecycle {
|
|
64
|
-
states created;
|
|
65
|
-
initial created;
|
|
66
|
-
for index in sub(recipient_count, 1) { states pooling_[index]; }
|
|
67
|
-
states pooled;
|
|
68
|
-
for index in sub(recipient_count, 1) { states distributing_[index]; }
|
|
69
|
-
states distributed;
|
|
70
|
-
for index in recipient_count {
|
|
71
|
-
let(fund_from): if_eq(index, 1, "created", concat("pooling_", sub(index, 1)));
|
|
72
|
-
let(fund_to): if_eq(index, recipient_count, "pooled", concat("pooling_", index));
|
|
73
|
-
on fund_share_[index]: [fund_from] -> [fund_to];
|
|
74
|
-
let(distribute_from): if_eq(index, 1, "pooled", concat("distributing_", sub(index, 1)));
|
|
75
|
-
let(distribute_to): if_eq(index, recipient_count, "distributed", concat("distributing_", index));
|
|
76
|
-
on distribute_share_[index]: [distribute_from] -> [distribute_to];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
parties { beneficiary: concat(camel(at(recipients, 1)), "AccountId"); payer: concat(camel(payer), "AccountId"); }
|
|
80
|
-
required: concat_lists([concat(camel(payer), "AccountId")], suffix_each(recipients, "AccountId"), [concat("", amount), concat("", payout_due)], suffix_each(recipients, "ShareAmount"), ["currency"]);
|
|
81
|
-
title: sentence(instrument);
|
|
82
|
-
id_prefix: prefix(instrument);
|
|
83
|
-
agent_description: concat("Reach for ", words(instrument), " when the ", words(payer), " funds one period total that is then split across ", recipient_count, " fixed recipients by stored share amounts. Callers fund the pool one share at a time. Each recipient's payout fires from the stored payout date, not from a call.");
|
|
84
|
-
summary: concat("Period pool from ", words(payer), " split ", recipient_count, " ways");
|
|
85
|
-
description: concat("Pooled split: the ", words(payer), " pools the period's ", amount, " share by share; the pool distributes to every recipient in full on the stored payout date");
|
|
86
|
-
partitions { totalField: amount; pieceFields: suffix_each(recipients, "ShareAmount"); }
|
|
87
|
-
action create {
|
|
88
|
-
agent_description: concat("Open a ", words(instrument), " period and provision the escrow account the pool sits in. This is the first call on the period, and funding a share refuses until it lands. It moves no money.");
|
|
89
|
-
summary: concat("Open a ", words(instrument), " period");
|
|
90
|
-
moves: [];
|
|
91
|
-
steps: [{ operation: "account.escrow.provision"; bind: { currency: { from: instance; path: "fields.currency"; }; "owner.id": { from: instance; path: productId; }; "owner.type": { from: const; value: product; }; productId: { from: instance; path: productId; }; role: { from: const; value: product_escrow; }; }; capture: { escrowAccountId: accountId; }; }];
|
|
92
|
-
}
|
|
93
|
-
for index in recipient_count {
|
|
94
|
-
let(recipient): at(recipients, index);
|
|
95
|
-
let(share_field): concat(camel(recipient), "ShareAmount");
|
|
96
|
-
action fund_share_[index] {
|
|
97
|
-
agent_description: concat("Move share ", index, " of the period total, the ", words(recipient), "'s cut, from the ", words(payer), " into the pool escrow. Shares fund in order, so every earlier share must be in already. It debits the ", words(payer), " for real. The pool pays out from the stored payout date with no release call.");
|
|
98
|
-
summary: concat("Pool share ", index, " of the period total");
|
|
99
|
-
moves: [{ amount: share_field; from: payer; to: refs.escrowAccountId; key: transfer; }];
|
|
100
|
-
steps: [];
|
|
101
|
-
}
|
|
102
|
-
action distribute_share_[index] {
|
|
103
|
-
summary: concat("Distribute the ", words(recipient), "'s share of the pool");
|
|
104
|
-
due { field: payout_due; }
|
|
105
|
-
moves: [{ amount: share_field; from: refs.escrowAccountId; to: recipient; key: transfer; }];
|
|
106
|
-
steps: [];
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|