@hyperscale0/hsx 2.4.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -408
- 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 +76 -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 +77 -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
package/std/money_flows/swap.hsx
DELETED
|
@@ -1,1192 +0,0 @@
|
|
|
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
|
-
// ```
|
|
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>) {
|
|
56
|
-
let(side_a): at(between, 1);
|
|
57
|
-
let(side_b): at(between, 2);
|
|
58
|
-
let(side_a_amount): get(amounts, side_a);
|
|
59
|
-
let(side_b_amount): get(amounts, side_b);
|
|
60
|
-
let(side_a_fee): get(fees, side_a);
|
|
61
|
-
let(side_b_fee): get(fees, side_b);
|
|
62
|
-
when(side_names) {
|
|
63
|
-
let(side_a_name): get(side_names, "first");
|
|
64
|
-
let(side_b_name): get(side_names, "second");
|
|
65
|
-
}
|
|
66
|
-
when_not(side_names) {
|
|
67
|
-
let(side_a_name): side_a;
|
|
68
|
-
let(side_b_name): side_b;
|
|
69
|
-
}
|
|
70
|
-
let(side_a_account): concat(camel(side_a_name), "AccountId");
|
|
71
|
-
let(side_b_account): concat(camel(side_b_name), "AccountId");
|
|
72
|
-
agent_description: "Reach for swap when two named parties pay each other in one atomic trade and neither leg may settle alone. Both principals fund one escrow together, both cross-payments reserve together, and one dispute unwinds both. A single payer paying a single payee is instant transfer instead.";
|
|
73
|
-
title: sentence(instrument);
|
|
74
|
-
when(fixed_prefix) {
|
|
75
|
-
id_prefix: fixed_prefix;
|
|
76
|
-
}
|
|
77
|
-
when_not(fixed_prefix) {
|
|
78
|
-
id_prefix: prefix(instrument);
|
|
79
|
-
}
|
|
80
|
-
summary: concat("Two-party atomic trade between ", words(side_a), " and ", words(side_b));
|
|
81
|
-
description: concat("Atomic swap between ", words(side_a), " and ", words(side_b), "; half-funded and half-released states do not exist");
|
|
82
|
-
distinct_parties: true;
|
|
83
|
-
when(side_names) {
|
|
84
|
-
parties {
|
|
85
|
-
payer: { party: side_a; account: side_a_account; };
|
|
86
|
-
beneficiary: { party: side_b; account: side_b_account; };
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
when_not(side_names) {
|
|
90
|
-
parties {
|
|
91
|
-
payer: side_a;
|
|
92
|
-
beneficiary: side_b;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
required: [side_a_account, side_b_account, platformAccountId, concat(side_a_amount), concat(side_b_amount), concat(side_a_fee), concat(side_b_fee), currency];
|
|
96
|
-
when_not(side_names) {
|
|
97
|
-
computes fees {
|
|
98
|
-
amountField: concat(side_a_fee);
|
|
99
|
-
baseField: concat(side_a_amount);
|
|
100
|
-
bearerField: side_a_account;
|
|
101
|
-
position: on_top;
|
|
102
|
-
rule {
|
|
103
|
-
currencyField: currency;
|
|
104
|
-
field: concat(side_a_fee);
|
|
105
|
-
kind: exact;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
computes fees {
|
|
109
|
-
amountField: concat(side_b_fee);
|
|
110
|
-
baseField: concat(side_b_amount);
|
|
111
|
-
bearerField: side_b_account;
|
|
112
|
-
position: on_top;
|
|
113
|
-
rule {
|
|
114
|
-
currencyField: currency;
|
|
115
|
-
field: concat(side_b_fee);
|
|
116
|
-
kind: exact;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
when(parked_states) {
|
|
121
|
-
caller_parked_states: parked_states;
|
|
122
|
-
}
|
|
123
|
-
fields {
|
|
124
|
-
when(side_names) {
|
|
125
|
-
clawbackAt {
|
|
126
|
-
type: date;
|
|
127
|
-
description: "Machine-owned absolute end of the release clawback window";
|
|
128
|
-
optional: true;
|
|
129
|
-
}
|
|
130
|
-
currency {
|
|
131
|
-
type: text;
|
|
132
|
-
description: "One currency for both trade legs and both fees";
|
|
133
|
-
const: C;
|
|
134
|
-
}
|
|
135
|
-
"[side_a_account]" {
|
|
136
|
-
type: account<C>;
|
|
137
|
-
description: "First trade party and funder";
|
|
138
|
-
"x-hyperscale-reference-filter" {
|
|
139
|
-
column: role;
|
|
140
|
-
values: [customer_balance];
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
"[side_a_amount]" {
|
|
144
|
-
type: get(amounts, side_a);
|
|
145
|
-
description: concat("Amount side A holds against the whole exchange, in ", C, " minor units");
|
|
146
|
-
}
|
|
147
|
-
"[side_a_fee]" {
|
|
148
|
-
type: get(fees, side_a);
|
|
149
|
-
description: "Side A custody fee charged on top and never placed in escrow";
|
|
150
|
-
}
|
|
151
|
-
"[side_b_account]" {
|
|
152
|
-
type: account<C>;
|
|
153
|
-
description: "Second trade party and funder";
|
|
154
|
-
"x-hyperscale-reference-filter" {
|
|
155
|
-
column: role;
|
|
156
|
-
values: [customer_balance];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
"[side_b_amount]" {
|
|
160
|
-
type: get(amounts, side_b);
|
|
161
|
-
description: concat("Amount side B holds against the whole exchange, in ", C, " minor units");
|
|
162
|
-
}
|
|
163
|
-
"[side_b_fee]" {
|
|
164
|
-
type: get(fees, side_b);
|
|
165
|
-
description: "Side B custody fee charged on top and never placed in escrow";
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
when_not(side_names) {
|
|
169
|
-
clawbackAt {
|
|
170
|
-
type: date;
|
|
171
|
-
description: concat("Machine-owned end of the ", dispute_within, " whole-trade dispute window");
|
|
172
|
-
}
|
|
173
|
-
"[side_a_amount]" {
|
|
174
|
-
type: get(amounts, side_a);
|
|
175
|
-
description: "Side A amount in SAR minor units, held against the whole trade";
|
|
176
|
-
}
|
|
177
|
-
"[side_b_amount]" {
|
|
178
|
-
type: get(amounts, side_b);
|
|
179
|
-
description: "Side B amount in SAR minor units, held against the whole trade";
|
|
180
|
-
}
|
|
181
|
-
"[side_a_fee]" {
|
|
182
|
-
type: get(fees, side_a);
|
|
183
|
-
description: concat("Immutable exact ", words(side_a), " service fee in SAR minor units");
|
|
184
|
-
}
|
|
185
|
-
"[side_b_fee]" {
|
|
186
|
-
type: get(fees, side_b);
|
|
187
|
-
description: concat("Immutable exact ", words(side_b), " service fee in SAR minor units");
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
platformAccountId {
|
|
191
|
-
type: account<C>;
|
|
192
|
-
when(side_names) {
|
|
193
|
-
description: "Product revenue or customer balance account collecting trade service fees";
|
|
194
|
-
}
|
|
195
|
-
when_not(side_names) {
|
|
196
|
-
description: "The product fee collection account";
|
|
197
|
-
}
|
|
198
|
-
"x-hyperscale-fee-collection-port": true;
|
|
199
|
-
"x-hyperscale-reference-filter" {
|
|
200
|
-
column: role;
|
|
201
|
-
values: [customer_balance, product_revenue];
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
when(lifecycle_state_order) {
|
|
206
|
-
let(states_key): "states";
|
|
207
|
-
lifecycle {
|
|
208
|
-
"[states_key]": lifecycle_state_order;
|
|
209
|
-
initial created;
|
|
210
|
-
on abandon: created -> abandoned;
|
|
211
|
-
on cancel: funded -> cancelled;
|
|
212
|
-
on dispute: released -> clawed_back;
|
|
213
|
-
on fund: created -> funded;
|
|
214
|
-
on post: released -> settled;
|
|
215
|
-
on release: funded -> released;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
when_not(lifecycle_state_order) {
|
|
219
|
-
lifecycle {
|
|
220
|
-
states created abandoned funded cancelled released settled clawed_back;
|
|
221
|
-
initial created;
|
|
222
|
-
on abandon: created -> abandoned;
|
|
223
|
-
on cancel: funded -> cancelled;
|
|
224
|
-
on dispute: released -> clawed_back;
|
|
225
|
-
on fund: created -> funded;
|
|
226
|
-
on post: released -> settled;
|
|
227
|
-
on release: funded -> released;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
when_not(action_bindings) {
|
|
231
|
-
action abandon {
|
|
232
|
-
agent_description: "Walk away from a trade that never funded. Only a created trade abandons, and its escrow account must hold nothing, so there is nothing to refund. No money moves.";
|
|
233
|
-
summary: "Abandon the trade before its atomic funding batch";
|
|
234
|
-
public_action: concat("abandon", title(camel(instrument)));
|
|
235
|
-
requires drained {
|
|
236
|
-
path: "refs.escrowAccountId";
|
|
237
|
-
}
|
|
238
|
-
moves: [];
|
|
239
|
-
steps: [];
|
|
240
|
-
}
|
|
241
|
-
action cancel {
|
|
242
|
-
agent_description: "Unwind a funded trade before release. Both principals return from escrow to their own sides in one batch. The trade must be funded and not yet released. The service fees taken at funding stay with the platform.";
|
|
243
|
-
summary: "Cancel and return both trade principals atomically";
|
|
244
|
-
public_action: concat("cancel", title(camel(instrument)));
|
|
245
|
-
moves: [{
|
|
246
|
-
amount: concat(side_a_amount);
|
|
247
|
-
from: "refs.escrowAccountId";
|
|
248
|
-
to: side_a;
|
|
249
|
-
key: side_a_refund;
|
|
250
|
-
}, {
|
|
251
|
-
amount: concat(side_b_amount);
|
|
252
|
-
from: "refs.escrowAccountId";
|
|
253
|
-
to: side_b;
|
|
254
|
-
key: side_b_refund;
|
|
255
|
-
}];
|
|
256
|
-
steps: [];
|
|
257
|
-
}
|
|
258
|
-
action create {
|
|
259
|
-
agent_description: "Open a trade and provision its escrow account. No money moves. Both principals and both exact service fees are fixed here and cannot change afterwards.";
|
|
260
|
-
summary: concat("Create a ", words(instrument), " atomic trade");
|
|
261
|
-
public_action: concat("create", title(camel(instrument)));
|
|
262
|
-
moves: [];
|
|
263
|
-
steps: [{
|
|
264
|
-
operation: "account.escrow.provision";
|
|
265
|
-
bind {
|
|
266
|
-
currency {
|
|
267
|
-
from: instance;
|
|
268
|
-
path: "fields.currency";
|
|
269
|
-
}
|
|
270
|
-
"owner.id" {
|
|
271
|
-
from: instance;
|
|
272
|
-
path: productId;
|
|
273
|
-
}
|
|
274
|
-
"owner.type" {
|
|
275
|
-
from: const;
|
|
276
|
-
value: product;
|
|
277
|
-
}
|
|
278
|
-
productId {
|
|
279
|
-
from: instance;
|
|
280
|
-
path: productId;
|
|
281
|
-
}
|
|
282
|
-
role {
|
|
283
|
-
from: const;
|
|
284
|
-
value: product_escrow;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
capture {
|
|
288
|
-
escrowAccountId: accountId;
|
|
289
|
-
}
|
|
290
|
-
}];
|
|
291
|
-
}
|
|
292
|
-
action dispute {
|
|
293
|
-
agent_description: "Claw back a released trade inside its dispute window. Both cross-payment reservations void and both principals return from escrow in one batch. The trade must be released and the clawback moment must not have passed. The dispute port's declared parties may call it.";
|
|
294
|
-
summary: "Void both reservations, then refund both principals atomically";
|
|
295
|
-
public_action: concat("dispute", title(camel(instrument)));
|
|
296
|
-
deadline {
|
|
297
|
-
field: clawbackAt;
|
|
298
|
-
}
|
|
299
|
-
when(dispute_fields) {
|
|
300
|
-
input {
|
|
301
|
-
type: object;
|
|
302
|
-
additional_properties: false;
|
|
303
|
-
properties {
|
|
304
|
-
for input_name in keys(dispute_fields) {
|
|
305
|
-
[input_name]: get(dispute_fields, input_name);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
required: keys(dispute_fields);
|
|
309
|
-
}
|
|
310
|
-
capture_input: {
|
|
311
|
-
for item in keys(dispute_fields) { [item]: item; }
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
port { allowedParties: dispute_allowed; }
|
|
315
|
-
moves: [{
|
|
316
|
-
bind {
|
|
317
|
-
reason {
|
|
318
|
-
from: const;
|
|
319
|
-
value: "Whole trade disputed inside the clawback window";
|
|
320
|
-
}
|
|
321
|
-
transferId {
|
|
322
|
-
from: instance;
|
|
323
|
-
path: "refs.releaseSideATransferId";
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
key: side_a_void;
|
|
327
|
-
operation: "internal_transfer.void";
|
|
328
|
-
}, {
|
|
329
|
-
bind {
|
|
330
|
-
reason {
|
|
331
|
-
from: const;
|
|
332
|
-
value: "Whole trade disputed inside the clawback window";
|
|
333
|
-
}
|
|
334
|
-
transferId {
|
|
335
|
-
from: instance;
|
|
336
|
-
path: "refs.releaseSideBTransferId";
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
key: side_b_void;
|
|
340
|
-
operation: "internal_transfer.void";
|
|
341
|
-
}, {
|
|
342
|
-
bind {
|
|
343
|
-
amount {
|
|
344
|
-
from: instance;
|
|
345
|
-
path: concat("fields.", side_a_amount);
|
|
346
|
-
}
|
|
347
|
-
currency {
|
|
348
|
-
from: instance;
|
|
349
|
-
path: "fields.currency";
|
|
350
|
-
}
|
|
351
|
-
destinationAccountId {
|
|
352
|
-
from: instance;
|
|
353
|
-
path: concat("fields.", side_a_account);
|
|
354
|
-
}
|
|
355
|
-
"metadata.clawbackOfTransferId" {
|
|
356
|
-
from: instance;
|
|
357
|
-
path: "refs.releaseSideATransferId";
|
|
358
|
-
}
|
|
359
|
-
"metadata.instrumentId" {
|
|
360
|
-
from: const;
|
|
361
|
-
value: instrument;
|
|
362
|
-
}
|
|
363
|
-
"metadata.instrumentInstanceId" {
|
|
364
|
-
from: instance;
|
|
365
|
-
path: instrumentInstanceId;
|
|
366
|
-
}
|
|
367
|
-
"metadata.phase" {
|
|
368
|
-
from: const;
|
|
369
|
-
value: "dispute";
|
|
370
|
-
}
|
|
371
|
-
productId {
|
|
372
|
-
from: instance;
|
|
373
|
-
path: productId;
|
|
374
|
-
}
|
|
375
|
-
sourceAccountId {
|
|
376
|
-
from: instance;
|
|
377
|
-
path: "refs.escrowAccountId";
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
capture {
|
|
381
|
-
disputeSideARefundTransferId: transferId;
|
|
382
|
-
}
|
|
383
|
-
key: side_a_refund;
|
|
384
|
-
operation: "internal_transfer.create";
|
|
385
|
-
}, {
|
|
386
|
-
bind {
|
|
387
|
-
amount {
|
|
388
|
-
from: instance;
|
|
389
|
-
path: concat("fields.", side_b_amount);
|
|
390
|
-
}
|
|
391
|
-
currency {
|
|
392
|
-
from: instance;
|
|
393
|
-
path: "fields.currency";
|
|
394
|
-
}
|
|
395
|
-
destinationAccountId {
|
|
396
|
-
from: instance;
|
|
397
|
-
path: concat("fields.", side_b_account);
|
|
398
|
-
}
|
|
399
|
-
"metadata.clawbackOfTransferId" {
|
|
400
|
-
from: instance;
|
|
401
|
-
path: "refs.releaseSideBTransferId";
|
|
402
|
-
}
|
|
403
|
-
"metadata.instrumentId" {
|
|
404
|
-
from: const;
|
|
405
|
-
value: instrument;
|
|
406
|
-
}
|
|
407
|
-
"metadata.instrumentInstanceId" {
|
|
408
|
-
from: instance;
|
|
409
|
-
path: instrumentInstanceId;
|
|
410
|
-
}
|
|
411
|
-
"metadata.phase" {
|
|
412
|
-
from: const;
|
|
413
|
-
value: "dispute";
|
|
414
|
-
}
|
|
415
|
-
productId {
|
|
416
|
-
from: instance;
|
|
417
|
-
path: productId;
|
|
418
|
-
}
|
|
419
|
-
sourceAccountId {
|
|
420
|
-
from: instance;
|
|
421
|
-
path: "refs.escrowAccountId";
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
capture {
|
|
425
|
-
disputeSideBRefundTransferId: transferId;
|
|
426
|
-
}
|
|
427
|
-
key: side_b_refund;
|
|
428
|
-
operation: "internal_transfer.create";
|
|
429
|
-
}];
|
|
430
|
-
steps: [];
|
|
431
|
-
}
|
|
432
|
-
action fund {
|
|
433
|
-
agent_description: "Fund both sides at once. Each side pays its principal into escrow and its service fee to the platform account, four transfers in one batch. The trade must be created and unfunded. This moves real money from both parties.";
|
|
434
|
-
summary: "Fund both trade sides and collect on-top fees atomically";
|
|
435
|
-
public_action: concat("fund", title(camel(instrument)));
|
|
436
|
-
sandbox_failure_point: "funding";
|
|
437
|
-
moves: [{
|
|
438
|
-
amount: concat(side_a_amount);
|
|
439
|
-
from: side_a;
|
|
440
|
-
to: "refs.escrowAccountId";
|
|
441
|
-
key: side_a_principal;
|
|
442
|
-
}, {
|
|
443
|
-
amount: concat(side_b_amount);
|
|
444
|
-
from: side_b;
|
|
445
|
-
to: "refs.escrowAccountId";
|
|
446
|
-
key: side_b_principal;
|
|
447
|
-
}, {
|
|
448
|
-
amount: concat(side_a_fee);
|
|
449
|
-
from: side_a;
|
|
450
|
-
to: platformAccountId;
|
|
451
|
-
key: side_a_service_fee;
|
|
452
|
-
}, {
|
|
453
|
-
amount: concat(side_b_fee);
|
|
454
|
-
from: side_b;
|
|
455
|
-
to: platformAccountId;
|
|
456
|
-
key: side_b_service_fee;
|
|
457
|
-
}];
|
|
458
|
-
steps: [];
|
|
459
|
-
}
|
|
460
|
-
action post {
|
|
461
|
-
summary: "Post both trade reservations when the clawback window matures";
|
|
462
|
-
due {
|
|
463
|
-
field: clawbackAt;
|
|
464
|
-
}
|
|
465
|
-
moves: [{
|
|
466
|
-
bind {
|
|
467
|
-
transferId {
|
|
468
|
-
from: instance;
|
|
469
|
-
path: "refs.releaseSideATransferId";
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
key: "side_a";
|
|
473
|
-
operation: "internal_transfer.post";
|
|
474
|
-
}, {
|
|
475
|
-
bind {
|
|
476
|
-
transferId {
|
|
477
|
-
from: instance;
|
|
478
|
-
path: "refs.releaseSideBTransferId";
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
key: "side_b";
|
|
482
|
-
operation: "internal_transfer.post";
|
|
483
|
-
}];
|
|
484
|
-
steps: [];
|
|
485
|
-
}
|
|
486
|
-
action release {
|
|
487
|
-
agent_description: "Reserve each side's principal for the other side and start the dispute window. The trade must be funded. Money is reserved, not settled. It posts on its own when the window matures, and dispute unwinds it before then. The release port's declared parties may call it.";
|
|
488
|
-
summary: "Reserve both cross-payments for the whole-trade clawback window";
|
|
489
|
-
public_action: concat("release", title(camel(instrument)));
|
|
490
|
-
port {
|
|
491
|
-
allowedParties: release_allowed;
|
|
492
|
-
}
|
|
493
|
-
sandbox_failure_point: "release";
|
|
494
|
-
sets_at {
|
|
495
|
-
field: clawbackAt;
|
|
496
|
-
offset: dispute_within;
|
|
497
|
-
}
|
|
498
|
-
moves: [{
|
|
499
|
-
bind {
|
|
500
|
-
amount {
|
|
501
|
-
from: instance;
|
|
502
|
-
path: concat("fields.", side_a_amount);
|
|
503
|
-
}
|
|
504
|
-
currency {
|
|
505
|
-
from: instance;
|
|
506
|
-
path: "fields.currency";
|
|
507
|
-
}
|
|
508
|
-
destinationAccountId {
|
|
509
|
-
from: instance;
|
|
510
|
-
path: concat("fields.", side_b_account);
|
|
511
|
-
}
|
|
512
|
-
"metadata.clawbackAt" {
|
|
513
|
-
from: instance;
|
|
514
|
-
path: "fields.clawbackAt";
|
|
515
|
-
}
|
|
516
|
-
"metadata.instrumentId" {
|
|
517
|
-
from: const;
|
|
518
|
-
value: instrument;
|
|
519
|
-
}
|
|
520
|
-
"metadata.instrumentInstanceId" {
|
|
521
|
-
from: instance;
|
|
522
|
-
path: instrumentInstanceId;
|
|
523
|
-
}
|
|
524
|
-
"metadata.phase" {
|
|
525
|
-
from: const;
|
|
526
|
-
value: "release";
|
|
527
|
-
}
|
|
528
|
-
productId {
|
|
529
|
-
from: instance;
|
|
530
|
-
path: productId;
|
|
531
|
-
}
|
|
532
|
-
sourceAccountId {
|
|
533
|
-
from: instance;
|
|
534
|
-
path: "refs.escrowAccountId";
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
capture {
|
|
538
|
-
releaseSideATransferId: transferId;
|
|
539
|
-
}
|
|
540
|
-
key: "side_a";
|
|
541
|
-
operation: "internal_transfer.reserve";
|
|
542
|
-
}, {
|
|
543
|
-
bind {
|
|
544
|
-
amount {
|
|
545
|
-
from: instance;
|
|
546
|
-
path: concat("fields.", side_b_amount);
|
|
547
|
-
}
|
|
548
|
-
currency {
|
|
549
|
-
from: instance;
|
|
550
|
-
path: "fields.currency";
|
|
551
|
-
}
|
|
552
|
-
destinationAccountId {
|
|
553
|
-
from: instance;
|
|
554
|
-
path: concat("fields.", side_a_account);
|
|
555
|
-
}
|
|
556
|
-
"metadata.clawbackAt" {
|
|
557
|
-
from: instance;
|
|
558
|
-
path: "fields.clawbackAt";
|
|
559
|
-
}
|
|
560
|
-
"metadata.instrumentId" {
|
|
561
|
-
from: const;
|
|
562
|
-
value: instrument;
|
|
563
|
-
}
|
|
564
|
-
"metadata.instrumentInstanceId" {
|
|
565
|
-
from: instance;
|
|
566
|
-
path: instrumentInstanceId;
|
|
567
|
-
}
|
|
568
|
-
"metadata.phase" {
|
|
569
|
-
from: const;
|
|
570
|
-
value: "release";
|
|
571
|
-
}
|
|
572
|
-
productId {
|
|
573
|
-
from: instance;
|
|
574
|
-
path: productId;
|
|
575
|
-
}
|
|
576
|
-
sourceAccountId {
|
|
577
|
-
from: instance;
|
|
578
|
-
path: "refs.escrowAccountId";
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
capture {
|
|
582
|
-
releaseSideBTransferId: transferId;
|
|
583
|
-
}
|
|
584
|
-
key: "side_b";
|
|
585
|
-
operation: "internal_transfer.reserve";
|
|
586
|
-
}];
|
|
587
|
-
steps: [];
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
when(action_bindings) {
|
|
591
|
-
let(event_prefix): get(action_bindings, "event_prefix");
|
|
592
|
-
let(fund_principal_capture): get(action_bindings, "fund_principal_capture");
|
|
593
|
-
let(fund_fee_capture): get(action_bindings, "fund_fee_capture");
|
|
594
|
-
let(fund_principal_phase): get(action_bindings, "fund_principal_phase");
|
|
595
|
-
let(fund_fee_phase): get(action_bindings, "fund_fee_phase");
|
|
596
|
-
let(release_capture): get(action_bindings, "release_capture");
|
|
597
|
-
let(release_phase): get(action_bindings, "release_phase");
|
|
598
|
-
let(release_key): get(action_bindings, "release_key");
|
|
599
|
-
let(post_key): get(action_bindings, "post_key");
|
|
600
|
-
let(dispute_capture): get(action_bindings, "dispute_capture");
|
|
601
|
-
let(dispute_phase): get(action_bindings, "dispute_phase");
|
|
602
|
-
let(dispute_reason): get(action_bindings, "dispute_reason");
|
|
603
|
-
let(cancel_capture): get(action_bindings, "cancel_capture");
|
|
604
|
-
let(cancel_phase): get(action_bindings, "cancel_phase");
|
|
605
|
-
let(side_a_fund_capture): camel(concat(side_a_name, "_", fund_principal_capture, "_transfer_id"));
|
|
606
|
-
let(side_b_fund_capture): camel(concat(side_b_name, "_", fund_principal_capture, "_transfer_id"));
|
|
607
|
-
let(side_a_fee_capture): camel(concat(side_a_name, "_", fund_fee_capture, "_transfer_id"));
|
|
608
|
-
let(side_b_fee_capture): camel(concat(side_b_name, "_", fund_fee_capture, "_transfer_id"));
|
|
609
|
-
let(side_a_release_capture): camel(concat(side_a_name, "_", release_capture, "_id"));
|
|
610
|
-
let(side_b_release_capture): camel(concat(side_b_name, "_", release_capture, "_id"));
|
|
611
|
-
let(side_a_release_ref): concat("refs.", side_a_release_capture);
|
|
612
|
-
let(side_b_release_ref): concat("refs.", side_b_release_capture);
|
|
613
|
-
let(side_a_dispute_capture): camel(concat(side_a_name, "_", dispute_capture, "_transfer_id"));
|
|
614
|
-
let(side_b_dispute_capture): camel(concat(side_b_name, "_", dispute_capture, "_transfer_id"));
|
|
615
|
-
let(side_a_cancel_capture): camel(concat(side_a_name, "_", cancel_capture, "_transfer_id"));
|
|
616
|
-
let(side_b_cancel_capture): camel(concat(side_b_name, "_", cancel_capture, "_transfer_id"));
|
|
617
|
-
action create {
|
|
618
|
-
agent_description: "Open a trade and provision its escrow account. No money moves. Both principals and both exact service fees are fixed here and cannot change afterwards.";
|
|
619
|
-
summary: concat("Create a ", words(instrument), " atomic trade");
|
|
620
|
-
public_action: concat("create", title(camel(instrument)));
|
|
621
|
-
moves: [];
|
|
622
|
-
steps: [{
|
|
623
|
-
operation: "account.escrow.provision";
|
|
624
|
-
bind {
|
|
625
|
-
currency {
|
|
626
|
-
from: instance;
|
|
627
|
-
path: "fields.currency";
|
|
628
|
-
}
|
|
629
|
-
"owner.id" {
|
|
630
|
-
from: instance;
|
|
631
|
-
path: productId;
|
|
632
|
-
}
|
|
633
|
-
"owner.type" {
|
|
634
|
-
from: const;
|
|
635
|
-
value: product;
|
|
636
|
-
}
|
|
637
|
-
productId {
|
|
638
|
-
from: instance;
|
|
639
|
-
path: productId;
|
|
640
|
-
}
|
|
641
|
-
role {
|
|
642
|
-
from: const;
|
|
643
|
-
value: product_escrow;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
capture {
|
|
647
|
-
escrowAccountId: accountId;
|
|
648
|
-
}
|
|
649
|
-
}];
|
|
650
|
-
}
|
|
651
|
-
action fund {
|
|
652
|
-
agent_description: "Fund both sides at once. Each side pays its principal into escrow and its service fee to the platform account, four transfers in one batch. The trade must be created and unfunded. This moves real money from both parties.";
|
|
653
|
-
summary: "Fund both trade sides and collect on-top fees atomically";
|
|
654
|
-
public_action: concat("fund", title(camel(instrument)));
|
|
655
|
-
event_name: concat(event_prefix, ".funded");
|
|
656
|
-
sandbox_failure_point: "funding";
|
|
657
|
-
moves: [{
|
|
658
|
-
bind {
|
|
659
|
-
amount {
|
|
660
|
-
from: instance;
|
|
661
|
-
path: concat("fields.", side_a_amount);
|
|
662
|
-
}
|
|
663
|
-
currency {
|
|
664
|
-
from: instance;
|
|
665
|
-
path: "fields.currency";
|
|
666
|
-
}
|
|
667
|
-
destinationAccountId {
|
|
668
|
-
from: instance;
|
|
669
|
-
path: "refs.escrowAccountId";
|
|
670
|
-
}
|
|
671
|
-
"metadata.instrumentId" {
|
|
672
|
-
from: const;
|
|
673
|
-
value: instrument;
|
|
674
|
-
}
|
|
675
|
-
"metadata.instrumentInstanceId" {
|
|
676
|
-
from: instance;
|
|
677
|
-
path: instrumentInstanceId;
|
|
678
|
-
}
|
|
679
|
-
"metadata.phase" {
|
|
680
|
-
from: const;
|
|
681
|
-
value: fund_principal_phase;
|
|
682
|
-
}
|
|
683
|
-
productId {
|
|
684
|
-
from: instance;
|
|
685
|
-
path: productId;
|
|
686
|
-
}
|
|
687
|
-
sourceAccountId {
|
|
688
|
-
from: instance;
|
|
689
|
-
path: concat("fields.", side_a_account);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
capture {
|
|
693
|
-
"[side_a_fund_capture]": transferId;
|
|
694
|
-
}
|
|
695
|
-
key: side_a_principal;
|
|
696
|
-
operation: "internal_transfer.create";
|
|
697
|
-
}, {
|
|
698
|
-
bind {
|
|
699
|
-
amount {
|
|
700
|
-
from: instance;
|
|
701
|
-
path: concat("fields.", side_b_amount);
|
|
702
|
-
}
|
|
703
|
-
currency {
|
|
704
|
-
from: instance;
|
|
705
|
-
path: "fields.currency";
|
|
706
|
-
}
|
|
707
|
-
destinationAccountId {
|
|
708
|
-
from: instance;
|
|
709
|
-
path: "refs.escrowAccountId";
|
|
710
|
-
}
|
|
711
|
-
"metadata.instrumentId" {
|
|
712
|
-
from: const;
|
|
713
|
-
value: instrument;
|
|
714
|
-
}
|
|
715
|
-
"metadata.instrumentInstanceId" {
|
|
716
|
-
from: instance;
|
|
717
|
-
path: instrumentInstanceId;
|
|
718
|
-
}
|
|
719
|
-
"metadata.phase" {
|
|
720
|
-
from: const;
|
|
721
|
-
value: fund_principal_phase;
|
|
722
|
-
}
|
|
723
|
-
productId {
|
|
724
|
-
from: instance;
|
|
725
|
-
path: productId;
|
|
726
|
-
}
|
|
727
|
-
sourceAccountId {
|
|
728
|
-
from: instance;
|
|
729
|
-
path: concat("fields.", side_b_account);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
capture {
|
|
733
|
-
"[side_b_fund_capture]": transferId;
|
|
734
|
-
}
|
|
735
|
-
key: side_b_principal;
|
|
736
|
-
operation: "internal_transfer.create";
|
|
737
|
-
}, {
|
|
738
|
-
bind {
|
|
739
|
-
amount {
|
|
740
|
-
from: instance;
|
|
741
|
-
path: concat("fields.", side_a_fee);
|
|
742
|
-
}
|
|
743
|
-
currency {
|
|
744
|
-
from: instance;
|
|
745
|
-
path: "fields.currency";
|
|
746
|
-
}
|
|
747
|
-
destinationAccountId {
|
|
748
|
-
from: instance;
|
|
749
|
-
path: "fields.platformAccountId";
|
|
750
|
-
}
|
|
751
|
-
"metadata.instrumentId" {
|
|
752
|
-
from: const;
|
|
753
|
-
value: instrument;
|
|
754
|
-
}
|
|
755
|
-
"metadata.instrumentInstanceId" {
|
|
756
|
-
from: instance;
|
|
757
|
-
path: instrumentInstanceId;
|
|
758
|
-
}
|
|
759
|
-
"metadata.phase" {
|
|
760
|
-
from: const;
|
|
761
|
-
value: fund_fee_phase;
|
|
762
|
-
}
|
|
763
|
-
productId {
|
|
764
|
-
from: instance;
|
|
765
|
-
path: productId;
|
|
766
|
-
}
|
|
767
|
-
sourceAccountId {
|
|
768
|
-
from: instance;
|
|
769
|
-
path: concat("fields.", side_a_account);
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
capture {
|
|
773
|
-
"[side_a_fee_capture]": transferId;
|
|
774
|
-
}
|
|
775
|
-
key: side_a_service_fee;
|
|
776
|
-
operation: "internal_transfer.create";
|
|
777
|
-
}, {
|
|
778
|
-
bind {
|
|
779
|
-
amount {
|
|
780
|
-
from: instance;
|
|
781
|
-
path: concat("fields.", side_b_fee);
|
|
782
|
-
}
|
|
783
|
-
currency {
|
|
784
|
-
from: instance;
|
|
785
|
-
path: "fields.currency";
|
|
786
|
-
}
|
|
787
|
-
destinationAccountId {
|
|
788
|
-
from: instance;
|
|
789
|
-
path: "fields.platformAccountId";
|
|
790
|
-
}
|
|
791
|
-
"metadata.instrumentId" {
|
|
792
|
-
from: const;
|
|
793
|
-
value: instrument;
|
|
794
|
-
}
|
|
795
|
-
"metadata.instrumentInstanceId" {
|
|
796
|
-
from: instance;
|
|
797
|
-
path: instrumentInstanceId;
|
|
798
|
-
}
|
|
799
|
-
"metadata.phase" {
|
|
800
|
-
from: const;
|
|
801
|
-
value: fund_fee_phase;
|
|
802
|
-
}
|
|
803
|
-
productId {
|
|
804
|
-
from: instance;
|
|
805
|
-
path: productId;
|
|
806
|
-
}
|
|
807
|
-
sourceAccountId {
|
|
808
|
-
from: instance;
|
|
809
|
-
path: concat("fields.", side_b_account);
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
capture {
|
|
813
|
-
"[side_b_fee_capture]": transferId;
|
|
814
|
-
}
|
|
815
|
-
key: side_b_service_fee;
|
|
816
|
-
operation: "internal_transfer.create";
|
|
817
|
-
}];
|
|
818
|
-
steps: [];
|
|
819
|
-
}
|
|
820
|
-
action release {
|
|
821
|
-
agent_description: "Reserve each side's principal for the other side and start the dispute window. The trade must be funded. Money is reserved, not settled. It posts on its own when the window matures, and dispute unwinds it before then. The release port's declared parties may call it.";
|
|
822
|
-
summary: "Reserve both cross-payments for the whole-trade clawback window";
|
|
823
|
-
public_action: concat("release", title(camel(instrument)));
|
|
824
|
-
event_name: concat(event_prefix, ".released");
|
|
825
|
-
port {
|
|
826
|
-
allowedParties: release_allowed;
|
|
827
|
-
}
|
|
828
|
-
sandbox_failure_point: "release";
|
|
829
|
-
sets_at {
|
|
830
|
-
field: clawbackAt;
|
|
831
|
-
offset: dispute_within;
|
|
832
|
-
}
|
|
833
|
-
moves: [{
|
|
834
|
-
bind {
|
|
835
|
-
amount {
|
|
836
|
-
from: instance;
|
|
837
|
-
path: concat("fields.", side_a_amount);
|
|
838
|
-
}
|
|
839
|
-
currency {
|
|
840
|
-
from: instance;
|
|
841
|
-
path: "fields.currency";
|
|
842
|
-
}
|
|
843
|
-
destinationAccountId {
|
|
844
|
-
from: instance;
|
|
845
|
-
path: concat("fields.", side_b_account);
|
|
846
|
-
}
|
|
847
|
-
"metadata.clawbackAt" {
|
|
848
|
-
from: instance;
|
|
849
|
-
path: "fields.clawbackAt";
|
|
850
|
-
}
|
|
851
|
-
"metadata.instrumentId" {
|
|
852
|
-
from: const;
|
|
853
|
-
value: instrument;
|
|
854
|
-
}
|
|
855
|
-
"metadata.instrumentInstanceId" {
|
|
856
|
-
from: instance;
|
|
857
|
-
path: instrumentInstanceId;
|
|
858
|
-
}
|
|
859
|
-
"metadata.phase" {
|
|
860
|
-
from: const;
|
|
861
|
-
value: release_phase;
|
|
862
|
-
}
|
|
863
|
-
productId {
|
|
864
|
-
from: instance;
|
|
865
|
-
path: productId;
|
|
866
|
-
}
|
|
867
|
-
sourceAccountId {
|
|
868
|
-
from: instance;
|
|
869
|
-
path: "refs.escrowAccountId";
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
capture {
|
|
873
|
-
"[side_a_release_capture]": transferId;
|
|
874
|
-
}
|
|
875
|
-
key: concat("side_a_", release_key);
|
|
876
|
-
operation: "internal_transfer.reserve";
|
|
877
|
-
}, {
|
|
878
|
-
bind {
|
|
879
|
-
amount {
|
|
880
|
-
from: instance;
|
|
881
|
-
path: concat("fields.", side_b_amount);
|
|
882
|
-
}
|
|
883
|
-
currency {
|
|
884
|
-
from: instance;
|
|
885
|
-
path: "fields.currency";
|
|
886
|
-
}
|
|
887
|
-
destinationAccountId {
|
|
888
|
-
from: instance;
|
|
889
|
-
path: concat("fields.", side_a_account);
|
|
890
|
-
}
|
|
891
|
-
"metadata.clawbackAt" {
|
|
892
|
-
from: instance;
|
|
893
|
-
path: "fields.clawbackAt";
|
|
894
|
-
}
|
|
895
|
-
"metadata.instrumentId" {
|
|
896
|
-
from: const;
|
|
897
|
-
value: instrument;
|
|
898
|
-
}
|
|
899
|
-
"metadata.instrumentInstanceId" {
|
|
900
|
-
from: instance;
|
|
901
|
-
path: instrumentInstanceId;
|
|
902
|
-
}
|
|
903
|
-
"metadata.phase" {
|
|
904
|
-
from: const;
|
|
905
|
-
value: release_phase;
|
|
906
|
-
}
|
|
907
|
-
productId {
|
|
908
|
-
from: instance;
|
|
909
|
-
path: productId;
|
|
910
|
-
}
|
|
911
|
-
sourceAccountId {
|
|
912
|
-
from: instance;
|
|
913
|
-
path: "refs.escrowAccountId";
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
capture {
|
|
917
|
-
"[side_b_release_capture]": transferId;
|
|
918
|
-
}
|
|
919
|
-
key: concat("side_b_", release_key);
|
|
920
|
-
operation: "internal_transfer.reserve";
|
|
921
|
-
}];
|
|
922
|
-
steps: [];
|
|
923
|
-
}
|
|
924
|
-
action post {
|
|
925
|
-
summary: "Post both trade reservations when the clawback window matures";
|
|
926
|
-
event_name: concat(event_prefix, ".posted");
|
|
927
|
-
due {
|
|
928
|
-
field: clawbackAt;
|
|
929
|
-
}
|
|
930
|
-
moves: [{
|
|
931
|
-
bind {
|
|
932
|
-
transferId {
|
|
933
|
-
from: instance;
|
|
934
|
-
path: side_a_release_ref;
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
key: concat("side_a_", post_key);
|
|
938
|
-
operation: "internal_transfer.post";
|
|
939
|
-
}, {
|
|
940
|
-
bind {
|
|
941
|
-
transferId {
|
|
942
|
-
from: instance;
|
|
943
|
-
path: side_b_release_ref;
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
key: concat("side_b_", post_key);
|
|
947
|
-
operation: "internal_transfer.post";
|
|
948
|
-
}];
|
|
949
|
-
steps: [];
|
|
950
|
-
}
|
|
951
|
-
action dispute {
|
|
952
|
-
agent_description: "Claw back a released trade inside its dispute window. Both cross-payment reservations void and both principals return from escrow in one batch. The trade must be released and the clawback moment must not have passed. The dispute port's declared parties may call it.";
|
|
953
|
-
summary: "Void both reservations, then refund both principals atomically";
|
|
954
|
-
public_action: concat("dispute", title(camel(instrument)));
|
|
955
|
-
event_name: concat(event_prefix, ".clawed_back");
|
|
956
|
-
deadline {
|
|
957
|
-
field: clawbackAt;
|
|
958
|
-
}
|
|
959
|
-
when(dispute_fields) {
|
|
960
|
-
input {
|
|
961
|
-
type: object;
|
|
962
|
-
additional_properties: false;
|
|
963
|
-
properties {
|
|
964
|
-
for input_name in keys(dispute_fields) {
|
|
965
|
-
[input_name]: get(dispute_fields, input_name);
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
required: keys(dispute_fields);
|
|
969
|
-
}
|
|
970
|
-
capture_input: {
|
|
971
|
-
for item in keys(dispute_fields) { [item]: item; }
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
port { allowedParties: dispute_allowed; }
|
|
975
|
-
moves: [{
|
|
976
|
-
bind {
|
|
977
|
-
reason {
|
|
978
|
-
from: const;
|
|
979
|
-
value: dispute_reason;
|
|
980
|
-
}
|
|
981
|
-
transferId {
|
|
982
|
-
from: instance;
|
|
983
|
-
path: side_a_release_ref;
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
key: side_a_void;
|
|
987
|
-
operation: "internal_transfer.void";
|
|
988
|
-
}, {
|
|
989
|
-
bind {
|
|
990
|
-
reason {
|
|
991
|
-
from: const;
|
|
992
|
-
value: dispute_reason;
|
|
993
|
-
}
|
|
994
|
-
transferId {
|
|
995
|
-
from: instance;
|
|
996
|
-
path: side_b_release_ref;
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
key: side_b_void;
|
|
1000
|
-
operation: "internal_transfer.void";
|
|
1001
|
-
}, {
|
|
1002
|
-
bind {
|
|
1003
|
-
amount {
|
|
1004
|
-
from: instance;
|
|
1005
|
-
path: concat("fields.", side_a_amount);
|
|
1006
|
-
}
|
|
1007
|
-
currency {
|
|
1008
|
-
from: instance;
|
|
1009
|
-
path: "fields.currency";
|
|
1010
|
-
}
|
|
1011
|
-
destinationAccountId {
|
|
1012
|
-
from: instance;
|
|
1013
|
-
path: concat("fields.", side_a_account);
|
|
1014
|
-
}
|
|
1015
|
-
"metadata.clawbackOfTransferId" {
|
|
1016
|
-
from: instance;
|
|
1017
|
-
path: side_a_release_ref;
|
|
1018
|
-
}
|
|
1019
|
-
"metadata.instrumentId" {
|
|
1020
|
-
from: const;
|
|
1021
|
-
value: instrument;
|
|
1022
|
-
}
|
|
1023
|
-
"metadata.instrumentInstanceId" {
|
|
1024
|
-
from: instance;
|
|
1025
|
-
path: instrumentInstanceId;
|
|
1026
|
-
}
|
|
1027
|
-
"metadata.phase" {
|
|
1028
|
-
from: const;
|
|
1029
|
-
value: dispute_phase;
|
|
1030
|
-
}
|
|
1031
|
-
productId {
|
|
1032
|
-
from: instance;
|
|
1033
|
-
path: productId;
|
|
1034
|
-
}
|
|
1035
|
-
sourceAccountId {
|
|
1036
|
-
from: instance;
|
|
1037
|
-
path: "refs.escrowAccountId";
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
capture {
|
|
1041
|
-
"[side_a_dispute_capture]": transferId;
|
|
1042
|
-
}
|
|
1043
|
-
key: side_a_refund;
|
|
1044
|
-
operation: "internal_transfer.create";
|
|
1045
|
-
}, {
|
|
1046
|
-
bind {
|
|
1047
|
-
amount {
|
|
1048
|
-
from: instance;
|
|
1049
|
-
path: concat("fields.", side_b_amount);
|
|
1050
|
-
}
|
|
1051
|
-
currency {
|
|
1052
|
-
from: instance;
|
|
1053
|
-
path: "fields.currency";
|
|
1054
|
-
}
|
|
1055
|
-
destinationAccountId {
|
|
1056
|
-
from: instance;
|
|
1057
|
-
path: concat("fields.", side_b_account);
|
|
1058
|
-
}
|
|
1059
|
-
"metadata.clawbackOfTransferId" {
|
|
1060
|
-
from: instance;
|
|
1061
|
-
path: side_b_release_ref;
|
|
1062
|
-
}
|
|
1063
|
-
"metadata.instrumentId" {
|
|
1064
|
-
from: const;
|
|
1065
|
-
value: instrument;
|
|
1066
|
-
}
|
|
1067
|
-
"metadata.instrumentInstanceId" {
|
|
1068
|
-
from: instance;
|
|
1069
|
-
path: instrumentInstanceId;
|
|
1070
|
-
}
|
|
1071
|
-
"metadata.phase" {
|
|
1072
|
-
from: const;
|
|
1073
|
-
value: dispute_phase;
|
|
1074
|
-
}
|
|
1075
|
-
productId {
|
|
1076
|
-
from: instance;
|
|
1077
|
-
path: productId;
|
|
1078
|
-
}
|
|
1079
|
-
sourceAccountId {
|
|
1080
|
-
from: instance;
|
|
1081
|
-
path: "refs.escrowAccountId";
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
capture {
|
|
1085
|
-
"[side_b_dispute_capture]": transferId;
|
|
1086
|
-
}
|
|
1087
|
-
key: side_b_refund;
|
|
1088
|
-
operation: "internal_transfer.create";
|
|
1089
|
-
}];
|
|
1090
|
-
steps: [];
|
|
1091
|
-
}
|
|
1092
|
-
action cancel {
|
|
1093
|
-
agent_description: "Unwind a funded trade before release. Both principals return from escrow to their own sides in one batch. The trade must be funded and not yet released. The service fees taken at funding stay with the platform.";
|
|
1094
|
-
summary: "Cancel and return both trade principals atomically";
|
|
1095
|
-
public_action: concat("cancel", title(camel(instrument)));
|
|
1096
|
-
event_name: concat(event_prefix, ".cancelled");
|
|
1097
|
-
moves: [{
|
|
1098
|
-
bind {
|
|
1099
|
-
amount {
|
|
1100
|
-
from: instance;
|
|
1101
|
-
path: concat("fields.", side_a_amount);
|
|
1102
|
-
}
|
|
1103
|
-
currency {
|
|
1104
|
-
from: instance;
|
|
1105
|
-
path: "fields.currency";
|
|
1106
|
-
}
|
|
1107
|
-
destinationAccountId {
|
|
1108
|
-
from: instance;
|
|
1109
|
-
path: concat("fields.", side_a_account);
|
|
1110
|
-
}
|
|
1111
|
-
"metadata.instrumentId" {
|
|
1112
|
-
from: const;
|
|
1113
|
-
value: instrument;
|
|
1114
|
-
}
|
|
1115
|
-
"metadata.instrumentInstanceId" {
|
|
1116
|
-
from: instance;
|
|
1117
|
-
path: instrumentInstanceId;
|
|
1118
|
-
}
|
|
1119
|
-
"metadata.phase" {
|
|
1120
|
-
from: const;
|
|
1121
|
-
value: cancel_phase;
|
|
1122
|
-
}
|
|
1123
|
-
productId {
|
|
1124
|
-
from: instance;
|
|
1125
|
-
path: productId;
|
|
1126
|
-
}
|
|
1127
|
-
sourceAccountId {
|
|
1128
|
-
from: instance;
|
|
1129
|
-
path: "refs.escrowAccountId";
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
capture {
|
|
1133
|
-
"[side_a_cancel_capture]": transferId;
|
|
1134
|
-
}
|
|
1135
|
-
key: side_a_refund;
|
|
1136
|
-
operation: "internal_transfer.create";
|
|
1137
|
-
}, {
|
|
1138
|
-
bind {
|
|
1139
|
-
amount {
|
|
1140
|
-
from: instance;
|
|
1141
|
-
path: concat("fields.", side_b_amount);
|
|
1142
|
-
}
|
|
1143
|
-
currency {
|
|
1144
|
-
from: instance;
|
|
1145
|
-
path: "fields.currency";
|
|
1146
|
-
}
|
|
1147
|
-
destinationAccountId {
|
|
1148
|
-
from: instance;
|
|
1149
|
-
path: concat("fields.", side_b_account);
|
|
1150
|
-
}
|
|
1151
|
-
"metadata.instrumentId" {
|
|
1152
|
-
from: const;
|
|
1153
|
-
value: instrument;
|
|
1154
|
-
}
|
|
1155
|
-
"metadata.instrumentInstanceId" {
|
|
1156
|
-
from: instance;
|
|
1157
|
-
path: instrumentInstanceId;
|
|
1158
|
-
}
|
|
1159
|
-
"metadata.phase" {
|
|
1160
|
-
from: const;
|
|
1161
|
-
value: cancel_phase;
|
|
1162
|
-
}
|
|
1163
|
-
productId {
|
|
1164
|
-
from: instance;
|
|
1165
|
-
path: productId;
|
|
1166
|
-
}
|
|
1167
|
-
sourceAccountId {
|
|
1168
|
-
from: instance;
|
|
1169
|
-
path: "refs.escrowAccountId";
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
capture {
|
|
1173
|
-
"[side_b_cancel_capture]": transferId;
|
|
1174
|
-
}
|
|
1175
|
-
key: side_b_refund;
|
|
1176
|
-
operation: "internal_transfer.create";
|
|
1177
|
-
}];
|
|
1178
|
-
steps: [];
|
|
1179
|
-
}
|
|
1180
|
-
action abandon {
|
|
1181
|
-
agent_description: "Walk away from a trade that never funded. Only a created trade abandons, and its escrow account must hold nothing, so there is nothing to refund. No money moves.";
|
|
1182
|
-
summary: "Abandon the trade before its atomic funding batch";
|
|
1183
|
-
public_action: concat("abandon", title(camel(instrument)));
|
|
1184
|
-
event_name: concat(event_prefix, ".abandoned");
|
|
1185
|
-
requires drained {
|
|
1186
|
-
path: "refs.escrowAccountId";
|
|
1187
|
-
}
|
|
1188
|
-
moves: [];
|
|
1189
|
-
steps: [];
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
}
|