@hyperscale0/hsx 1.0.0-beta.1 → 1.0.0-rc.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 +41 -9
- package/LICENSING.md +3 -3
- package/README.md +37 -149
- package/TRADEMARKS.md +4 -4
- package/dist/src/ast.d.ts +129 -10
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/cli.d.ts +2 -1
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +148 -12
- package/dist/src/cli.js.map +1 -1
- package/dist/src/compile.d.ts +41 -4
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +82 -15
- package/dist/src/compile.js.map +1 -1
- package/dist/src/cost.d.ts +78 -0
- package/dist/src/cost.d.ts.map +1 -0
- package/dist/src/cost.js +369 -0
- package/dist/src/cost.js.map +1 -0
- package/dist/src/diagnostics.d.ts +11 -0
- package/dist/src/diagnostics.d.ts.map +1 -0
- package/dist/src/diagnostics.js +420 -0
- package/dist/src/diagnostics.js.map +1 -0
- package/dist/src/emit.d.ts +35 -0
- package/dist/src/emit.d.ts.map +1 -0
- package/dist/src/emit.js +359 -0
- package/dist/src/emit.js.map +1 -0
- package/dist/src/entry-overrides.d.ts +17 -3
- package/dist/src/entry-overrides.d.ts.map +1 -1
- package/dist/src/entry-overrides.js +180 -35
- package/dist/src/entry-overrides.js.map +1 -1
- package/dist/src/format.d.ts +10 -0
- package/dist/src/format.d.ts.map +1 -0
- package/dist/src/format.js +183 -0
- package/dist/src/format.js.map +1 -0
- package/dist/src/index.d.ts +10 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/ir.d.ts +66 -0
- package/dist/src/ir.d.ts.map +1 -0
- package/dist/src/ir.js +15 -0
- package/dist/src/ir.js.map +1 -0
- package/dist/src/lex.d.ts +9 -1
- package/dist/src/lex.d.ts.map +1 -1
- package/dist/src/lex.js +50 -4
- package/dist/src/lex.js.map +1 -1
- package/dist/src/limits.d.ts +2 -3
- package/dist/src/limits.d.ts.map +1 -1
- package/dist/src/limits.js +2 -3
- package/dist/src/limits.js.map +1 -1
- package/dist/src/modules.d.ts +36 -0
- package/dist/src/modules.d.ts.map +1 -0
- package/dist/src/modules.js +372 -0
- package/dist/src/modules.js.map +1 -0
- package/dist/src/parse.d.ts.map +1 -1
- package/dist/src/parse.js +590 -17
- package/dist/src/parse.js.map +1 -1
- package/dist/src/typecheck.d.ts +8 -0
- package/dist/src/typecheck.d.ts.map +1 -0
- package/dist/src/typecheck.js +2958 -0
- package/dist/src/typecheck.js.map +1 -0
- package/dist/src/version.d.ts +4 -15
- package/dist/src/version.d.ts.map +1 -1
- package/dist/src/version.js +4 -15
- package/dist/src/version.js.map +1 -1
- package/docs/README.md +23 -0
- package/docs/guide/01-first-program.md +24 -0
- package/docs/guide/02-money.md +25 -0
- package/docs/guide/03-instruments.md +22 -0
- package/docs/guide/04-lifecycles.md +25 -0
- package/docs/guide/05-fees-and-splits.md +45 -0
- package/docs/guide/06-schedules.md +22 -0
- package/docs/guide/07-composition.md +46 -0
- package/docs/guide/08-writing-a-module.md +26 -0
- package/docs/guide/09-cost.md +24 -0
- package/docs/guide/10-diagnostics.md +27 -0
- package/docs/llms-full.txt +1738 -0
- package/docs/llms.txt +45 -0
- package/docs/reference/cli.md +33 -0
- package/docs/reference/diagnostics.md +619 -0
- package/docs/reference/grammar.md +39 -0
- package/docs/reference/std/advance.md +35 -0
- package/docs/reference/std/cancellable_booking.md +35 -0
- package/docs/reference/std/captured_payment.md +43 -0
- package/docs/reference/std/conditional_disbursement.md +33 -0
- package/docs/reference/std/credit_facility.md +35 -0
- package/docs/reference/std/held_payment.md +64 -0
- package/docs/reference/std/instant_transfer.md +30 -0
- package/docs/reference/std/metered.md +27 -0
- package/docs/reference/std/pooled_split.md +26 -0
- package/docs/reference/std/premium_forward.md +39 -0
- package/docs/reference/std/reconciled_payout.md +33 -0
- package/docs/reference/std/recurring_collection.md +25 -0
- package/docs/reference/std/rotating_pool.md +42 -0
- package/docs/reference/std/scheduled.md +51 -0
- package/docs/reference/std/security_deposit.md +46 -0
- package/docs/reference/std/settlement_batch.md +42 -0
- package/docs/reference/std/swap.md +46 -0
- package/docs/reference/std/threshold_pool.md +47 -0
- package/docs/reference/std/weighted_distribution.md +39 -0
- package/docs/reference/types.md +20 -0
- package/docs/reference/udl-output.md +14 -0
- package/docs/sessions/2026-09-02-two-instruments.hsx +21 -0
- package/docs/sessions/2026-09-02-two-instruments.md +41 -0
- package/examples/01-first-program/README.md +45 -0
- package/examples/01-first-program/tip-jar.hsx +17 -0
- package/examples/02-imports-and-archetypes/README.md +99 -0
- package/examples/02-imports-and-archetypes/photo-booth.hsx +37 -0
- package/examples/03-diagnostics/README.md +68 -0
- package/examples/03-diagnostics/corner-shop-fixed.hsx +22 -0
- package/examples/03-diagnostics/corner-shop.hsx +19 -0
- package/examples/04-complete-product/README.md +87 -0
- package/examples/04-complete-product/study-hall.hsx +67 -0
- package/examples/05-watch-club/README.md +9 -0
- package/examples/05-watch-club/watch-club.hsx +124 -0
- package/examples/README.md +18 -0
- package/examples/advance/README.md +3 -0
- package/examples/advance/advance.hsx +13 -0
- package/examples/advance/advance.udl +339 -0
- package/examples/cancellable_booking/README.md +3 -0
- package/examples/cancellable_booking/cancellable_booking.hsx +14 -0
- package/examples/cancellable_booking/cancellable_booking.udl +391 -0
- package/examples/captured_payment/README.md +3 -0
- package/examples/captured_payment/captured_payment.hsx +21 -0
- package/examples/captured_payment/captured_payment.udl +677 -0
- package/examples/conditional_disbursement/README.md +3 -0
- package/examples/conditional_disbursement/conditional_disbursement.hsx +17 -0
- package/examples/conditional_disbursement/conditional_disbursement.udl +412 -0
- package/examples/cost-table.json +386 -0
- package/examples/credit_facility/README.md +3 -0
- package/examples/credit_facility/credit_facility.hsx +27 -0
- package/examples/credit_facility/credit_facility.udl +1373 -0
- package/examples/held_payment/README.md +3 -0
- package/examples/held_payment/held_payment.hsx +13 -0
- package/examples/held_payment/held_payment.udl +507 -0
- package/examples/instant_transfer/README.md +3 -0
- package/examples/instant_transfer/instant_transfer.hsx +16 -0
- package/examples/instant_transfer/instant_transfer.udl +364 -0
- package/examples/metered/README.md +3 -0
- package/examples/metered/metered.hsx +13 -0
- package/examples/metered/metered.udl +247 -0
- package/examples/pooled_split/README.md +3 -0
- package/examples/pooled_split/pooled_split.hsx +15 -0
- package/examples/pooled_split/pooled_split.udl +425 -0
- package/examples/premium_forward/README.md +3 -0
- package/examples/premium_forward/premium_forward.hsx +19 -0
- package/examples/premium_forward/premium_forward.udl +594 -0
- package/examples/reconciled_payout/README.md +3 -0
- package/examples/reconciled_payout/reconciled_payout.hsx +13 -0
- package/examples/reconciled_payout/reconciled_payout.udl +303 -0
- package/examples/recurring_collection/README.md +3 -0
- package/examples/recurring_collection/recurring_collection.hsx +21 -0
- package/examples/recurring_collection/recurring_collection.udl +1130 -0
- package/examples/rotating_pool/README.md +3 -0
- package/examples/rotating_pool/rotating_pool.hsx +18 -0
- package/examples/rotating_pool/rotating_pool.udl +4352 -0
- package/examples/scheduled/README.md +3 -0
- package/examples/scheduled/scheduled.hsx +12 -0
- package/examples/scheduled/scheduled.udl +335 -0
- package/examples/security_deposit/README.md +3 -0
- package/examples/security_deposit/security_deposit.hsx +21 -0
- package/examples/security_deposit/security_deposit.udl +293 -0
- package/examples/settlement_batch/README.md +3 -0
- package/examples/settlement_batch/settlement_batch.hsx +19 -0
- package/examples/settlement_batch/settlement_batch.udl +753 -0
- package/examples/swap/README.md +3 -0
- package/examples/swap/swap.hsx +19 -0
- package/examples/swap/swap.udl +876 -0
- package/examples/threshold_pool/README.md +3 -0
- package/examples/threshold_pool/threshold_pool.hsx +16 -0
- package/examples/threshold_pool/threshold_pool.udl +667 -0
- package/examples/weighted_distribution/README.md +3 -0
- package/examples/weighted_distribution/weighted_distribution.hsx +20 -0
- package/examples/weighted_distribution/weighted_distribution.udl +337 -0
- package/package.json +19 -6
- package/skills/hsx/SKILL.md +483 -0
- package/src/ast.ts +163 -9
- package/src/cli.ts +164 -12
- package/src/compile.ts +160 -20
- package/src/cost.ts +579 -0
- package/src/diagnostics.ts +442 -0
- package/src/emit.ts +447 -0
- package/src/entry-overrides.ts +263 -48
- package/src/format.ts +261 -0
- package/src/index.ts +32 -4
- package/src/ir.ts +99 -0
- package/src/lex.ts +59 -4
- package/src/limits.ts +2 -3
- package/src/modules.ts +444 -0
- package/src/parse.ts +655 -21
- package/src/typecheck.ts +3876 -0
- package/src/version.ts +4 -16
- package/std/SEMANTICS.md +130 -0
- package/std/settlements/advance.hsx +177 -0
- package/std/settlements/cancellable_booking.hsx +87 -0
- package/std/settlements/captured_payment.hsx +144 -0
- package/std/settlements/conditional_disbursement.hsx +185 -0
- package/std/settlements/credit_facility.hsx +167 -0
- package/std/settlements/held_payment.hsx +578 -0
- package/std/settlements/index.hsx +3 -0
- package/std/settlements/instant_transfer.hsx +190 -0
- package/std/settlements/metered.hsx +67 -0
- package/std/settlements/pooled_split.hsx +68 -0
- package/std/settlements/premium_forward.hsx +257 -0
- package/std/settlements/reconciled_payout.hsx +77 -0
- package/std/settlements/recurring_collection.hsx +27 -0
- package/std/settlements/rotating_pool.hsx +252 -0
- package/std/settlements/scheduled.hsx +641 -0
- package/std/settlements/security_deposit.hsx +166 -0
- package/std/settlements/settlement_batch.hsx +122 -0
- package/std/settlements/swap.hsx +1114 -0
- package/std/settlements/threshold_pool.hsx +221 -0
- package/std/settlements/weighted_distribution.hsx +141 -0
- package/dist/src/archetypes.d.ts +0 -17
- package/dist/src/archetypes.d.ts.map +0 -1
- package/dist/src/archetypes.js +0 -327
- package/dist/src/archetypes.js.map +0 -1
- package/dist/src/check.d.ts +0 -12
- package/dist/src/check.d.ts.map +0 -1
- package/dist/src/check.js +0 -1910
- package/dist/src/check.js.map +0 -1
- package/dist/src/lower.d.ts +0 -146
- package/dist/src/lower.d.ts.map +0 -1
- package/dist/src/lower.js +0 -4570
- package/dist/src/lower.js.map +0 -1
- package/dist/src/model.d.ts +0 -467
- package/dist/src/model.d.ts.map +0 -1
- package/dist/src/model.js +0 -15
- package/dist/src/model.js.map +0 -1
- package/spec/hsx-ir.schema.json +0 -920
- package/src/archetypes.ts +0 -340
- package/src/check.ts +0 -2938
- package/src/lower.ts +0 -5416
- package/src/model.ts +0 -519
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
module std.settlements.instant_transfer
|
|
2
|
+
|
|
3
|
+
export instrument instant_transfer<C>(payer: party, payee: party, amount: money<C>, fees: optional<block>, derived_amount: optional<block>) {
|
|
4
|
+
let(payer_fee): get(fees, payer);
|
|
5
|
+
let(payee_fee): get(fees, payee);
|
|
6
|
+
let(payer_fee_kind): kind(payer_fee);
|
|
7
|
+
let(payee_fee_kind): kind(payee_fee);
|
|
8
|
+
let(payer_account_field): camel(concat(payer, "_account_id"));
|
|
9
|
+
let(payee_account_field): camel(concat(payee, "_account_id"));
|
|
10
|
+
let(net_bps): sub(10000, payee_fee);
|
|
11
|
+
let(net_percent): percent_text(net_bps);
|
|
12
|
+
let(payee_bps): basis_points(payee_fee);
|
|
13
|
+
let(payee_tiers): values(payee_fee);
|
|
14
|
+
let(first_tier): at(payee_tiers, 1);
|
|
15
|
+
let(second_tier): at(payee_tiers, 2);
|
|
16
|
+
let(second_tier_fee): get(second_tier, "fee");
|
|
17
|
+
when(derived_amount) {
|
|
18
|
+
let(derived_field): get(derived_amount, "field");
|
|
19
|
+
let(derived_source): get(derived_amount, "source");
|
|
20
|
+
let(derived_rule): get(derived_amount, "rule");
|
|
21
|
+
let(derived_bearer): get(derived_amount, "bearer");
|
|
22
|
+
}
|
|
23
|
+
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.");
|
|
24
|
+
summary: concat("Instant payment from ", words(payer), " to ", words(payee));
|
|
25
|
+
title: sentence(instrument);
|
|
26
|
+
description: concat("Instant transfer: the ", words(payer), " pays ", amount, " straight through to the ", words(payee), ", no custody");
|
|
27
|
+
fields {
|
|
28
|
+
when_not(fees) {
|
|
29
|
+
when(derived_amount) {
|
|
30
|
+
let(fee_collection_key): "x-hyperscale-fee-collection-port";
|
|
31
|
+
let(reference_filter_key): "x-hyperscale-reference-filter";
|
|
32
|
+
platformAccountId {
|
|
33
|
+
type: account<C>;
|
|
34
|
+
description: "The product fee collection account";
|
|
35
|
+
pattern: "^acct_(sandbox|live)_[a-z0-9]{8,64}$";
|
|
36
|
+
[fee_collection_key]: true;
|
|
37
|
+
[reference_filter_key]: { column: role; values: [customer_balance, product_revenue]; };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
when(fees) {
|
|
42
|
+
let(fee_collection_key): "x-hyperscale-fee-collection-port";
|
|
43
|
+
let(reference_filter_key): "x-hyperscale-reference-filter";
|
|
44
|
+
platformAccountId {
|
|
45
|
+
type: account<C>;
|
|
46
|
+
description: "The product fee collection account";
|
|
47
|
+
pattern: "^acct_(sandbox|live)_[a-z0-9]{8,64}$";
|
|
48
|
+
[fee_collection_key]: true;
|
|
49
|
+
[reference_filter_key]: { column: role; values: [customer_balance, product_revenue]; };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
when_not(fees) {
|
|
53
|
+
amount { type: money<C>; description: "The amount in {C} minor units, paid through whole"; }
|
|
54
|
+
}
|
|
55
|
+
when(fees) {
|
|
56
|
+
amount { type: money<C>; description: "The gross amount in {C} minor units; the piece fields below partition it exactly"; }
|
|
57
|
+
when_eq(payee_fee_kind, percent) {
|
|
58
|
+
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}$"; }
|
|
59
|
+
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; }
|
|
60
|
+
}
|
|
61
|
+
when_eq(payee_fee_kind, block) {
|
|
62
|
+
netOfCarvedFeeAmount { type: money<C>; description: "The remainder of {amount} after the carved platform fee"; pattern: "^[1-9][0-9]{0,17}$"; }
|
|
63
|
+
carvedFeeAmount { type: money<C>; description: "The carved platform fee selected from {amount}"; pattern: "^[1-9][0-9]{0,17}$"; optional: true; }
|
|
64
|
+
}
|
|
65
|
+
when_eq(payer_fee_kind, percent) {
|
|
66
|
+
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; }
|
|
67
|
+
}
|
|
68
|
+
when_eq(payer_fee_kind, binding) {
|
|
69
|
+
[payer_fee] { type: payer_fee; description: "Immutable exact {payer} fee in {C} minor units"; pattern: "^[1-9][0-9]{0,17}$"; }
|
|
70
|
+
}
|
|
71
|
+
when_eq(payee_fee_kind, block) {
|
|
72
|
+
[second_tier_fee] { type: second_tier_fee; description: "Immutable exact {payee} fee in {C} minor units"; pattern: "^[1-9][0-9]{0,17}$"; }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
when(derived_amount) {
|
|
76
|
+
[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; }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
lifecycle {
|
|
80
|
+
when_not(fees) { states created paid; }
|
|
81
|
+
when(fees) { states created paying_1 paying_2 paid; }
|
|
82
|
+
initial created;
|
|
83
|
+
when_not(fees) { on pay_piece_1: created -> paid; }
|
|
84
|
+
when(fees) {
|
|
85
|
+
on pay_piece_1: created -> paying_1;
|
|
86
|
+
on pay_piece_2: paying_1 -> paying_2;
|
|
87
|
+
on collect_service_fee: paying_2 -> paid;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
parties {
|
|
91
|
+
payer: payer;
|
|
92
|
+
beneficiary: payee;
|
|
93
|
+
}
|
|
94
|
+
when(derived_amount) {
|
|
95
|
+
computes derived: { field: derived_field; source_field: derived_source; rounding: floor; rule: { kind: percentage_of; bps: derived_rule; }; };
|
|
96
|
+
}
|
|
97
|
+
when(fees) {
|
|
98
|
+
when_eq(payer_fee_kind, percent) {
|
|
99
|
+
computes fees: { amount_field: serviceFeeAmount; base_field: amount; bearer_field: payer_account_field; position: on_top; rule: { kind: bps; bps: payer_fee; }; };
|
|
100
|
+
}
|
|
101
|
+
when_eq(payer_fee_kind, binding) {
|
|
102
|
+
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; }; };
|
|
103
|
+
}
|
|
104
|
+
when_eq(payee_fee_kind, percent) {
|
|
105
|
+
computes fees: { amount_field: piece2Amount; base_field: amount; bearer_field: payee_account_field; position: carved; rule: { kind: bps; bps: payee_fee; }; };
|
|
106
|
+
partitions: { total_field: amount; piece_fields: [piece1Amount, piece2Amount]; };
|
|
107
|
+
}
|
|
108
|
+
when_eq(payee_fee_kind, block) {
|
|
109
|
+
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; }; }]; }; };
|
|
110
|
+
partitions: { total_field: amount; piece_fields: [netOfCarvedFeeAmount, carvedFeeAmount]; };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
action create {
|
|
114
|
+
let(metadata_instrument): "metadata.instrumentId";
|
|
115
|
+
let(metadata_instance): "metadata.instrumentInstanceId";
|
|
116
|
+
let(metadata_phase): "metadata.phase";
|
|
117
|
+
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.";
|
|
118
|
+
summary: concat("Create a ", words(instrument), " payment");
|
|
119
|
+
when(derived_amount) {
|
|
120
|
+
moves: [{
|
|
121
|
+
key: "derived_amount";
|
|
122
|
+
operation: internal_transfer.create;
|
|
123
|
+
bind: {
|
|
124
|
+
amount: { from: instance; path: concat("fields.", derived_field); };
|
|
125
|
+
currency: { from: instance; path: fields.currency; };
|
|
126
|
+
destinationAccountId: { from: instance; path: fields.platformAccountId; };
|
|
127
|
+
[metadata_instrument]: { from: const; value: instrument; };
|
|
128
|
+
[metadata_instance]: { from: instance; path: instrumentInstanceId; };
|
|
129
|
+
[metadata_phase]: { from: const; value: create; };
|
|
130
|
+
productId: { from: instance; path: productId; };
|
|
131
|
+
sourceAccountId: { from: instance; path: concat("fields.", camel(derived_bearer), "AccountId"); };
|
|
132
|
+
};
|
|
133
|
+
capture: { createDerivedAmountTransferId: transferId; };
|
|
134
|
+
}];
|
|
135
|
+
}
|
|
136
|
+
steps: [];
|
|
137
|
+
}
|
|
138
|
+
action pay_piece_1 {
|
|
139
|
+
let(metadata_instrument): "metadata.instrumentId";
|
|
140
|
+
let(metadata_instance): "metadata.instrumentInstanceId";
|
|
141
|
+
let(metadata_phase): "metadata.phase";
|
|
142
|
+
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.");
|
|
143
|
+
summary: "Pay piece 1 of the amount through";
|
|
144
|
+
when_not(fees) {
|
|
145
|
+
moves: [{ key: transfer; amount: amount; from: payer; to: beneficiary; }];
|
|
146
|
+
}
|
|
147
|
+
when(fees) {
|
|
148
|
+
when_eq(payee_fee_kind, none) {
|
|
149
|
+
moves: [{ key: transfer; amount: amount; from: payer; to: beneficiary; }];
|
|
150
|
+
}
|
|
151
|
+
when_eq(payee_fee_kind, percent) {
|
|
152
|
+
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; }; }];
|
|
153
|
+
}
|
|
154
|
+
when_eq(payee_fee_kind, block) {
|
|
155
|
+
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; }; }];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
steps: [];
|
|
159
|
+
}
|
|
160
|
+
when(fees) {
|
|
161
|
+
action pay_piece_2 {
|
|
162
|
+
let(metadata_instrument): "metadata.instrumentId";
|
|
163
|
+
let(metadata_instance): "metadata.instrumentInstanceId";
|
|
164
|
+
let(metadata_phase): "metadata.phase";
|
|
165
|
+
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.");
|
|
166
|
+
summary: "Pay piece 2 of the amount through";
|
|
167
|
+
when_eq(payee_fee_kind, percent) {
|
|
168
|
+
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; }; }];
|
|
169
|
+
}
|
|
170
|
+
when_eq(payee_fee_kind, block) {
|
|
171
|
+
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; }; }];
|
|
172
|
+
}
|
|
173
|
+
steps: [];
|
|
174
|
+
}
|
|
175
|
+
action collect_service_fee {
|
|
176
|
+
let(metadata_instrument): "metadata.instrumentId";
|
|
177
|
+
let(metadata_instance): "metadata.instrumentInstanceId";
|
|
178
|
+
let(metadata_phase): "metadata.phase";
|
|
179
|
+
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.");
|
|
180
|
+
summary: "Collect the payer-side service fee";
|
|
181
|
+
when_eq(payer_fee_kind, percent) {
|
|
182
|
+
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; }; }];
|
|
183
|
+
}
|
|
184
|
+
when_eq(payer_fee_kind, binding) {
|
|
185
|
+
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; }; }];
|
|
186
|
+
}
|
|
187
|
+
steps: [];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module std.settlements.metered
|
|
2
|
+
|
|
3
|
+
export instrument metered(
|
|
4
|
+
payer: party,
|
|
5
|
+
payee: party,
|
|
6
|
+
close_by: date,
|
|
7
|
+
rates: unknown,
|
|
8
|
+
) {
|
|
9
|
+
let(instrument_words): words(instrument);
|
|
10
|
+
title: sentence(instrument);
|
|
11
|
+
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 recurring collection for a flat repeating amount and instant transfer for a one-off payment.";
|
|
12
|
+
summary: "Metered charges from {payer} on a committed rate card";
|
|
13
|
+
description: "Metered usage: the {payer} is charged per unit at the committed rate card until the period closes on its stored end date";
|
|
14
|
+
|
|
15
|
+
fields {
|
|
16
|
+
close_by: {
|
|
17
|
+
type: date;
|
|
18
|
+
description: "End of this metering period; the close makes further charges unreachable";
|
|
19
|
+
}
|
|
20
|
+
for item in keys(rates) {
|
|
21
|
+
let(amount_binding): get(rates, item);
|
|
22
|
+
let(rate_words): words(item);
|
|
23
|
+
[amount_binding]: {
|
|
24
|
+
type: amount_binding;
|
|
25
|
+
description: "Per-unit price of {rate_words} in SAR minor units, committed at period open";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
parties {
|
|
31
|
+
payer: payer;
|
|
32
|
+
beneficiary: payee;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
lifecycle {
|
|
36
|
+
states open closed;
|
|
37
|
+
initial open;
|
|
38
|
+
for item in keys(rates) {
|
|
39
|
+
on charge_[item]: open -> open;
|
|
40
|
+
}
|
|
41
|
+
on close_period: open -> closed;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
action create {
|
|
45
|
+
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.";
|
|
46
|
+
summary: "Open a {instrument_words} period with its committed rate card";
|
|
47
|
+
steps: [];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for item in keys(rates) {
|
|
51
|
+
action charge_[item] {
|
|
52
|
+
let(amount_binding): get(rates, item);
|
|
53
|
+
let(amount_field): concat(amount_binding);
|
|
54
|
+
let(rate_words): words(item);
|
|
55
|
+
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.";
|
|
56
|
+
summary: "Charge one metered {rate_words}; the emission is the transfer itself";
|
|
57
|
+
moves: [{ amount: amount_field; from: payer; to: beneficiary; key: transfer; }];
|
|
58
|
+
steps: [];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
action close_period {
|
|
63
|
+
summary: "Close the metering period; no further usage can be charged";
|
|
64
|
+
due: { field: close_by; };
|
|
65
|
+
steps: [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
module std.settlements.pooled_split
|
|
2
|
+
|
|
3
|
+
export instrument pooled_split<C>(payer: party, amount: money<C>, payout_due: date, split: block) {
|
|
4
|
+
let(recipients): keys_except(split, "remainder_to");
|
|
5
|
+
let(recipient_count): len(recipients);
|
|
6
|
+
let(remainder_recipient): get(split, "remainder_to");
|
|
7
|
+
fields {
|
|
8
|
+
currency { type: text; description: "ISO 4217 currency code"; minLength: 3; maxLength: 3; pattern: "^[A-Z]{3}$"; }
|
|
9
|
+
[payer]AccountId { type: account<C>; description: concat("The ", words(payer), " account"); pattern: "^acct_(sandbox|live)_[a-z0-9]{8,64}$"; "x-hyperscale-reference-filter": { column: role; values: [customer_balance]; }; }
|
|
10
|
+
amount { type: money<C>; description: concat("The pooled period total in {C} minor units; the share fields below partition it exactly"); }
|
|
11
|
+
payout_due { type: date; description: "The period's payout date; the pool distributes from it"; }
|
|
12
|
+
for index in recipient_count {
|
|
13
|
+
let(recipient): at(recipients, index);
|
|
14
|
+
let(share_bps): get(split, recipient);
|
|
15
|
+
[recipient]AccountId { type: account<C>; description: concat("The ", words(recipient), " account"); pattern: "^acct_(sandbox|live)_[a-z0-9]{8,64}$"; "x-hyperscale-reference-filter": { column: role; values: [customer_balance]; }; }
|
|
16
|
+
[recipient]ShareAmount {
|
|
17
|
+
type: money<C>;
|
|
18
|
+
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");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
lifecycle {
|
|
23
|
+
states created;
|
|
24
|
+
initial created;
|
|
25
|
+
for index in sub(recipient_count, 1) { states pooling_[index]; }
|
|
26
|
+
states pooled;
|
|
27
|
+
for index in sub(recipient_count, 1) { states distributing_[index]; }
|
|
28
|
+
states distributed;
|
|
29
|
+
for index in recipient_count {
|
|
30
|
+
let(fund_from): if_eq(index, 1, "created", concat("pooling_", sub(index, 1)));
|
|
31
|
+
let(fund_to): if_eq(index, recipient_count, "pooled", concat("pooling_", index));
|
|
32
|
+
on fund_share_[index]: [fund_from] -> [fund_to];
|
|
33
|
+
let(distribute_from): if_eq(index, 1, "pooled", concat("distributing_", sub(index, 1)));
|
|
34
|
+
let(distribute_to): if_eq(index, recipient_count, "distributed", concat("distributing_", index));
|
|
35
|
+
on distribute_share_[index]: [distribute_from] -> [distribute_to];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
parties { beneficiary: concat(camel(at(recipients, 1)), "AccountId"); payer: concat(camel(payer), "AccountId"); }
|
|
39
|
+
required: concat_lists([concat(camel(payer), "AccountId")], suffix_each(recipients, "AccountId"), [concat("", amount), concat("", payout_due)], suffix_each(recipients, "ShareAmount"), ["currency"]);
|
|
40
|
+
title: sentence(instrument);
|
|
41
|
+
id_prefix: prefix(instrument);
|
|
42
|
+
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.");
|
|
43
|
+
summary: concat("Period pool from ", words(payer), " split ", recipient_count, " ways");
|
|
44
|
+
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");
|
|
45
|
+
partitions { totalField: amount; pieceFields: suffix_each(recipients, "ShareAmount"); }
|
|
46
|
+
action create {
|
|
47
|
+
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.");
|
|
48
|
+
summary: concat("Open a ", words(instrument), " period");
|
|
49
|
+
moves: [];
|
|
50
|
+
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; }; }];
|
|
51
|
+
}
|
|
52
|
+
for index in recipient_count {
|
|
53
|
+
let(recipient): at(recipients, index);
|
|
54
|
+
let(share_field): concat(camel(recipient), "ShareAmount");
|
|
55
|
+
action fund_share_[index] {
|
|
56
|
+
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.");
|
|
57
|
+
summary: concat("Pool share ", index, " of the period total");
|
|
58
|
+
moves: [{ amount: share_field; from: payer; to: refs.escrowAccountId; key: transfer; }];
|
|
59
|
+
steps: [];
|
|
60
|
+
}
|
|
61
|
+
action distribute_share_[index] {
|
|
62
|
+
summary: concat("Distribute the ", words(recipient), "'s share of the pool");
|
|
63
|
+
due { field: payout_due; }
|
|
64
|
+
moves: [{ amount: share_field; from: refs.escrowAccountId; to: recipient; key: transfer; }];
|
|
65
|
+
steps: [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
module std.settlements.premium_forward
|
|
2
|
+
|
|
3
|
+
export instrument premium_forward<C>(
|
|
4
|
+
payer: party,
|
|
5
|
+
carrier: party,
|
|
6
|
+
amount: money<C>,
|
|
7
|
+
bind: condition,
|
|
8
|
+
commission: percent,
|
|
9
|
+
policy_ref: optional<text>,
|
|
10
|
+
renewal_due: optional<date>,
|
|
11
|
+
endorsement: optional<condition>,
|
|
12
|
+
) {
|
|
13
|
+
let(instrument_words): words(instrument);
|
|
14
|
+
let(bind_name): concat(bind);
|
|
15
|
+
let(payer_field): camel(concat(payer, "_account_id"));
|
|
16
|
+
let(carrier_field): camel(concat(carrier, "_account_id"));
|
|
17
|
+
let(amount_field): concat(amount);
|
|
18
|
+
let(net_bps): sub(10000, commission);
|
|
19
|
+
let(fee_bps): add(commission, 0);
|
|
20
|
+
let(net_percent): if_eq(net_bps, 9500, "95%", if_eq(net_bps, 9800, "98%", "87.5%"));
|
|
21
|
+
let(fee_percent): if_eq(fee_bps, 500, "5%", if_eq(fee_bps, 200, "2%", "12.5%"));
|
|
22
|
+
let(bind_roles): if_eq(len(bind_allowed), 2, ["payer", "beneficiary"], ["beneficiary"]);
|
|
23
|
+
let(owner_id_key): "owner.id";
|
|
24
|
+
let(owner_type_key): "owner.type";
|
|
25
|
+
let(metadata_instrument_key): "metadata.instrumentId";
|
|
26
|
+
let(metadata_instance_key): "metadata.instrumentInstanceId";
|
|
27
|
+
let(metadata_phase_key): "metadata.phase";
|
|
28
|
+
let(bind_capture_key): camel(concat(bind, "_transfer_transfer_id"));
|
|
29
|
+
let(fee_port_key): "x-hyperscale-fee-collection-port";
|
|
30
|
+
let(reference_filter_key): "x-hyperscale-reference-filter";
|
|
31
|
+
|
|
32
|
+
title: sentence(instrument);
|
|
33
|
+
agent_description: "Reach for {instrument_words} when the {payer} pays an insurance premium ahead of cover and the {carrier} must not be paid until the policy binds. The {amount_field} sits in this settlement's own escrow until {bind_name} fires. Binding then forwards {net_percent} to the {carrier} and {fee_percent} to the platform.";
|
|
34
|
+
summary: "Premium held for the {carrier} until the policy binds";
|
|
35
|
+
description: "Premium forward: the {payer} funds the {amount_field} into this settlement's own escrow; binding through {bind_name} forwards it to the {carrier} exactly once, minus the platform commission";
|
|
36
|
+
partitions: { total_field: amount_field; piece_fields: [piece1Amount, piece2Amount]; };
|
|
37
|
+
|
|
38
|
+
fields {
|
|
39
|
+
platform_account_id: {
|
|
40
|
+
type: account;
|
|
41
|
+
description: "The product fee collection account";
|
|
42
|
+
pattern: "^acct_(sandbox|live)_[a-z0-9]{8,64}$";
|
|
43
|
+
[fee_port_key]: true;
|
|
44
|
+
[reference_filter_key]: { column: role; values: [customer_balance, product_revenue]; };
|
|
45
|
+
}
|
|
46
|
+
amount: {
|
|
47
|
+
type: money<C>;
|
|
48
|
+
description: "The gross held amount in {C} minor units; the piece fields below partition it exactly";
|
|
49
|
+
}
|
|
50
|
+
piece1_amount: {
|
|
51
|
+
type: money<C>;
|
|
52
|
+
description: "{net_percent} of {amount_field} (carries the integer-division remainder): released to the {carrier}. Computed as floor({amount_field} * {net_bps} / 10000) in {C} minor units";
|
|
53
|
+
}
|
|
54
|
+
piece2_amount: {
|
|
55
|
+
type: money<C>;
|
|
56
|
+
description: "{fee_percent} of {amount_field}: released to the platform. Computed as floor({amount_field} * {fee_bps} / 10000) in {C} minor units";
|
|
57
|
+
}
|
|
58
|
+
when(policy_ref) {
|
|
59
|
+
policy_ref: {
|
|
60
|
+
type: text;
|
|
61
|
+
description: "Immutable external policy reference recorded with this forward";
|
|
62
|
+
max_length: 180;
|
|
63
|
+
min_length: 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
when(renewal_due) {
|
|
67
|
+
renewal_due: {
|
|
68
|
+
type: date;
|
|
69
|
+
description: "Stored renewal due condition for the forwarded policy";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
parties { payer: payer; beneficiary: carrier; }
|
|
75
|
+
|
|
76
|
+
lifecycle {
|
|
77
|
+
states created funding_1 funded releasing_1 released abandoned;
|
|
78
|
+
when(endorsement) { states endorsed lapsed; }
|
|
79
|
+
initial created;
|
|
80
|
+
on fund_piece_1: created -> funding_1;
|
|
81
|
+
on fund_piece_2: funding_1 -> funded;
|
|
82
|
+
on [bind]: funded -> releasing_1;
|
|
83
|
+
on forward_piece_2: releasing_1 -> released;
|
|
84
|
+
on unfund_piece_1: funding_1 -> abandoned;
|
|
85
|
+
on abandon: created -> abandoned;
|
|
86
|
+
when(endorsement) {
|
|
87
|
+
on [endorsement]: released -> endorsed;
|
|
88
|
+
on lapse: released|endorsed -> lapsed;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
action create {
|
|
93
|
+
agent_description: "Open the {instrument_words} and provision the escrow account that holds the funds. This is the first call on the settlement, and funding refuses until it lands. It moves no money.";
|
|
94
|
+
summary: "Create a {instrument_words} settlement";
|
|
95
|
+
steps: [{
|
|
96
|
+
operation: "account.escrow.provision";
|
|
97
|
+
bind: {
|
|
98
|
+
currency: { from: instance; path: fields.currency; };
|
|
99
|
+
[owner_id_key]: { from: instance; path: productId; };
|
|
100
|
+
[owner_type_key]: { from: const; value: product; };
|
|
101
|
+
product_id: { from: instance; path: productId; };
|
|
102
|
+
role: { from: const; value: product_escrow; };
|
|
103
|
+
};
|
|
104
|
+
capture: { escrow_account_id: accountId; };
|
|
105
|
+
}];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
action fund_piece_1 {
|
|
109
|
+
agent_description: "Move the {carrier}'s share of the premium from the {payer} into escrow. The settlement must exist and be unfunded. It debits the {payer} for real, and piece 2 still has to fund before the policy can bind.";
|
|
110
|
+
summary: "Fund piece 1 of the held amount into escrow";
|
|
111
|
+
moves: [{
|
|
112
|
+
key: transfer; operation: "internal_transfer.create";
|
|
113
|
+
bind: {
|
|
114
|
+
amount: { from: instance; path: fields.piece1Amount; };
|
|
115
|
+
currency: { from: instance; path: fields.currency; };
|
|
116
|
+
destination_account_id: { from: instance; path: refs.escrowAccountId; };
|
|
117
|
+
source_account_id: { from: instance; path: concat("fields.", payer_field); };
|
|
118
|
+
[metadata_instrument_key]: { from: const; value: instrument; };
|
|
119
|
+
[metadata_instance_key]: { from: instance; path: instrumentInstanceId; };
|
|
120
|
+
[metadata_phase_key]: { from: const; value: fund_piece_1; };
|
|
121
|
+
product_id: { from: instance; path: productId; };
|
|
122
|
+
};
|
|
123
|
+
capture: { fund_piece_1_transfer_transfer_id: transferId; };
|
|
124
|
+
}];
|
|
125
|
+
steps: [];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
action fund_piece_2 {
|
|
129
|
+
agent_description: "Move the platform commission piece from the {payer} into escrow, which completes funding. Piece 1 must be in escrow first. It debits the {payer} for real, and the premium is then held whole.";
|
|
130
|
+
summary: "Fund piece 2 of the held amount into escrow";
|
|
131
|
+
moves: [{
|
|
132
|
+
key: transfer; operation: "internal_transfer.create";
|
|
133
|
+
bind: {
|
|
134
|
+
amount: { from: instance; path: fields.piece2Amount; };
|
|
135
|
+
currency: { from: instance; path: fields.currency; };
|
|
136
|
+
destination_account_id: { from: instance; path: refs.escrowAccountId; };
|
|
137
|
+
source_account_id: { from: instance; path: concat("fields.", payer_field); };
|
|
138
|
+
[metadata_instrument_key]: { from: const; value: instrument; };
|
|
139
|
+
[metadata_instance_key]: { from: instance; path: instrumentInstanceId; };
|
|
140
|
+
[metadata_phase_key]: { from: const; value: fund_piece_2; };
|
|
141
|
+
product_id: { from: instance; path: productId; };
|
|
142
|
+
};
|
|
143
|
+
capture: { fund_piece_2_transfer_transfer_id: transferId; };
|
|
144
|
+
}];
|
|
145
|
+
steps: [];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
action [bind] {
|
|
149
|
+
agent_description: "Bind the policy through {bind_name} and forward the {carrier}'s share out of escrow. The premium must be fully funded first, and the call carries the decision reference the product asks for. Money leaves escrow here and does not come back.";
|
|
150
|
+
summary: "Confirm through {bind_name} and start the forward payout";
|
|
151
|
+
input: {
|
|
152
|
+
additional_properties: false;
|
|
153
|
+
properties: {
|
|
154
|
+
for item in keys(bind_fields) {
|
|
155
|
+
[item]: {
|
|
156
|
+
description: "Required decision reference retained in the operation receipt";
|
|
157
|
+
max_length: 180; min_length: 1; type: string;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
required: keys(bind_fields);
|
|
162
|
+
type: object;
|
|
163
|
+
};
|
|
164
|
+
port: { allowed_parties: bind_roles; };
|
|
165
|
+
moves: [{
|
|
166
|
+
key: transfer; operation: "internal_transfer.create";
|
|
167
|
+
bind: {
|
|
168
|
+
amount: { from: instance; path: fields.piece1Amount; };
|
|
169
|
+
currency: { from: instance; path: fields.currency; };
|
|
170
|
+
destination_account_id: { from: instance; path: concat("fields.", carrier_field); };
|
|
171
|
+
source_account_id: { from: instance; path: refs.escrowAccountId; };
|
|
172
|
+
[metadata_instrument_key]: { from: const; value: instrument; };
|
|
173
|
+
[metadata_instance_key]: { from: instance; path: instrumentInstanceId; };
|
|
174
|
+
[metadata_phase_key]: { from: const; value: bind; };
|
|
175
|
+
product_id: { from: instance; path: productId; };
|
|
176
|
+
};
|
|
177
|
+
capture: { [bind_capture_key]: transferId; };
|
|
178
|
+
}];
|
|
179
|
+
steps: [];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
action forward_piece_2 {
|
|
183
|
+
agent_description: "Pay the platform commission out of escrow to the fee collection account, which closes the forward. {bind_name} must have run first. Money leaves escrow here and does not come back.";
|
|
184
|
+
summary: "Forward piece 2 of the held amount";
|
|
185
|
+
moves: [{
|
|
186
|
+
key: transfer; operation: "internal_transfer.create";
|
|
187
|
+
bind: {
|
|
188
|
+
amount: { from: instance; path: fields.piece2Amount; };
|
|
189
|
+
currency: { from: instance; path: fields.currency; };
|
|
190
|
+
destination_account_id: { from: instance; path: fields.platformAccountId; };
|
|
191
|
+
source_account_id: { from: instance; path: refs.escrowAccountId; };
|
|
192
|
+
[metadata_instrument_key]: { from: const; value: instrument; };
|
|
193
|
+
[metadata_instance_key]: { from: instance; path: instrumentInstanceId; };
|
|
194
|
+
[metadata_phase_key]: { from: const; value: forward_piece_2; };
|
|
195
|
+
product_id: { from: instance; path: productId; };
|
|
196
|
+
};
|
|
197
|
+
capture: { forward_piece_2_transfer_transfer_id: transferId; };
|
|
198
|
+
}];
|
|
199
|
+
steps: [];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
action unfund_piece_1 {
|
|
203
|
+
agent_description: "Return the {carrier}'s share from escrow to the {payer} and abandon the forward. It runs only while funding stopped after piece 1, before the policy binds. The settlement ends abandoned.";
|
|
204
|
+
summary: "Return piece 1 to the {payer} on abandonment";
|
|
205
|
+
moves: [{
|
|
206
|
+
key: transfer; operation: "internal_transfer.create";
|
|
207
|
+
bind: {
|
|
208
|
+
amount: { from: instance; path: fields.piece1Amount; };
|
|
209
|
+
currency: { from: instance; path: fields.currency; };
|
|
210
|
+
destination_account_id: { from: instance; path: concat("fields.", payer_field); };
|
|
211
|
+
source_account_id: { from: instance; path: refs.escrowAccountId; };
|
|
212
|
+
[metadata_instrument_key]: { from: const; value: instrument; };
|
|
213
|
+
[metadata_instance_key]: { from: instance; path: instrumentInstanceId; };
|
|
214
|
+
[metadata_phase_key]: { from: const; value: unfund_piece_1; };
|
|
215
|
+
product_id: { from: instance; path: productId; };
|
|
216
|
+
};
|
|
217
|
+
capture: { unfund_piece_1_transfer_transfer_id: transferId; };
|
|
218
|
+
}];
|
|
219
|
+
steps: [];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
action abandon {
|
|
223
|
+
agent_description: "Close a {instrument_words} that was never funded. The escrow account must be empty, so this refuses once any piece is in it. It moves no money and the settlement ends here.";
|
|
224
|
+
summary: "Abandon the settlement before any money is held";
|
|
225
|
+
requires drained: { path: refs.escrowAccountId; };
|
|
226
|
+
steps: [];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
when(endorsement) {
|
|
230
|
+
action [endorsement] {
|
|
231
|
+
agent_description: "Record one endorsement against a policy that already forwarded, from evidence the caller supplies. The forward must be released first, and only the {carrier} may call it. It moves no money and it does not change the premium.";
|
|
232
|
+
summary: "Record one non-money endorsement from external evidence";
|
|
233
|
+
input: {
|
|
234
|
+
additional_properties: false;
|
|
235
|
+
properties: {
|
|
236
|
+
for item in keys(endorsement_fields) {
|
|
237
|
+
[item]: {
|
|
238
|
+
description: "Required decision reference retained in the operation receipt";
|
|
239
|
+
max_length: 180; min_length: 1; type: string;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
required: keys(endorsement_fields);
|
|
244
|
+
type: object;
|
|
245
|
+
};
|
|
246
|
+
capture_input: { endorsement_evidence_reference: evidenceReference; };
|
|
247
|
+
port: { allowed_parties: [beneficiary]; };
|
|
248
|
+
steps: [];
|
|
249
|
+
}
|
|
250
|
+
action lapse {
|
|
251
|
+
summary: "Mark the forwarded policy lapsed at its stored renewal due condition";
|
|
252
|
+
due: { field: renewal_due; };
|
|
253
|
+
requires drained: { path: refs.escrowAccountId; };
|
|
254
|
+
steps: [];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|