@hyperscale0/hsx 1.0.0-alpha.6 → 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.
Files changed (234) hide show
  1. package/CHANGELOG.md +48 -10
  2. package/LICENSING.md +3 -3
  3. package/README.md +37 -149
  4. package/TRADEMARKS.md +4 -4
  5. package/dist/src/ast.d.ts +129 -10
  6. package/dist/src/ast.d.ts.map +1 -1
  7. package/dist/src/cli.d.ts +2 -1
  8. package/dist/src/cli.d.ts.map +1 -1
  9. package/dist/src/cli.js +148 -12
  10. package/dist/src/cli.js.map +1 -1
  11. package/dist/src/compile.d.ts +41 -4
  12. package/dist/src/compile.d.ts.map +1 -1
  13. package/dist/src/compile.js +82 -15
  14. package/dist/src/compile.js.map +1 -1
  15. package/dist/src/cost.d.ts +78 -0
  16. package/dist/src/cost.d.ts.map +1 -0
  17. package/dist/src/cost.js +369 -0
  18. package/dist/src/cost.js.map +1 -0
  19. package/dist/src/diagnostics.d.ts +11 -0
  20. package/dist/src/diagnostics.d.ts.map +1 -0
  21. package/dist/src/diagnostics.js +420 -0
  22. package/dist/src/diagnostics.js.map +1 -0
  23. package/dist/src/emit.d.ts +35 -0
  24. package/dist/src/emit.d.ts.map +1 -0
  25. package/dist/src/emit.js +359 -0
  26. package/dist/src/emit.js.map +1 -0
  27. package/dist/src/entry-overrides.d.ts +17 -3
  28. package/dist/src/entry-overrides.d.ts.map +1 -1
  29. package/dist/src/entry-overrides.js +180 -35
  30. package/dist/src/entry-overrides.js.map +1 -1
  31. package/dist/src/format.d.ts +10 -0
  32. package/dist/src/format.d.ts.map +1 -0
  33. package/dist/src/format.js +183 -0
  34. package/dist/src/format.js.map +1 -0
  35. package/dist/src/index.d.ts +10 -4
  36. package/dist/src/index.d.ts.map +1 -1
  37. package/dist/src/index.js +8 -3
  38. package/dist/src/index.js.map +1 -1
  39. package/dist/src/ir.d.ts +66 -0
  40. package/dist/src/ir.d.ts.map +1 -0
  41. package/dist/src/ir.js +15 -0
  42. package/dist/src/ir.js.map +1 -0
  43. package/dist/src/lex.d.ts +9 -1
  44. package/dist/src/lex.d.ts.map +1 -1
  45. package/dist/src/lex.js +50 -4
  46. package/dist/src/lex.js.map +1 -1
  47. package/dist/src/limits.d.ts +2 -3
  48. package/dist/src/limits.d.ts.map +1 -1
  49. package/dist/src/limits.js +2 -3
  50. package/dist/src/limits.js.map +1 -1
  51. package/dist/src/modules.d.ts +36 -0
  52. package/dist/src/modules.d.ts.map +1 -0
  53. package/dist/src/modules.js +372 -0
  54. package/dist/src/modules.js.map +1 -0
  55. package/dist/src/parse.d.ts.map +1 -1
  56. package/dist/src/parse.js +590 -17
  57. package/dist/src/parse.js.map +1 -1
  58. package/dist/src/typecheck.d.ts +8 -0
  59. package/dist/src/typecheck.d.ts.map +1 -0
  60. package/dist/src/typecheck.js +2958 -0
  61. package/dist/src/typecheck.js.map +1 -0
  62. package/dist/src/version.d.ts +4 -15
  63. package/dist/src/version.d.ts.map +1 -1
  64. package/dist/src/version.js +4 -15
  65. package/dist/src/version.js.map +1 -1
  66. package/docs/README.md +23 -0
  67. package/docs/guide/01-first-program.md +24 -0
  68. package/docs/guide/02-money.md +25 -0
  69. package/docs/guide/03-instruments.md +22 -0
  70. package/docs/guide/04-lifecycles.md +25 -0
  71. package/docs/guide/05-fees-and-splits.md +45 -0
  72. package/docs/guide/06-schedules.md +22 -0
  73. package/docs/guide/07-composition.md +46 -0
  74. package/docs/guide/08-writing-a-module.md +26 -0
  75. package/docs/guide/09-cost.md +24 -0
  76. package/docs/guide/10-diagnostics.md +27 -0
  77. package/docs/llms-full.txt +1738 -0
  78. package/docs/llms.txt +45 -0
  79. package/docs/reference/cli.md +33 -0
  80. package/docs/reference/diagnostics.md +619 -0
  81. package/docs/reference/grammar.md +39 -0
  82. package/docs/reference/std/advance.md +35 -0
  83. package/docs/reference/std/cancellable_booking.md +35 -0
  84. package/docs/reference/std/captured_payment.md +43 -0
  85. package/docs/reference/std/conditional_disbursement.md +33 -0
  86. package/docs/reference/std/credit_facility.md +35 -0
  87. package/docs/reference/std/held_payment.md +64 -0
  88. package/docs/reference/std/instant_transfer.md +30 -0
  89. package/docs/reference/std/metered.md +27 -0
  90. package/docs/reference/std/pooled_split.md +26 -0
  91. package/docs/reference/std/premium_forward.md +39 -0
  92. package/docs/reference/std/reconciled_payout.md +33 -0
  93. package/docs/reference/std/recurring_collection.md +25 -0
  94. package/docs/reference/std/rotating_pool.md +42 -0
  95. package/docs/reference/std/scheduled.md +51 -0
  96. package/docs/reference/std/security_deposit.md +46 -0
  97. package/docs/reference/std/settlement_batch.md +42 -0
  98. package/docs/reference/std/swap.md +46 -0
  99. package/docs/reference/std/threshold_pool.md +47 -0
  100. package/docs/reference/std/weighted_distribution.md +39 -0
  101. package/docs/reference/types.md +20 -0
  102. package/docs/reference/udl-output.md +14 -0
  103. package/docs/sessions/2026-09-02-two-instruments.hsx +21 -0
  104. package/docs/sessions/2026-09-02-two-instruments.md +41 -0
  105. package/examples/01-first-program/README.md +45 -0
  106. package/examples/01-first-program/tip-jar.hsx +17 -0
  107. package/examples/02-imports-and-archetypes/README.md +99 -0
  108. package/examples/02-imports-and-archetypes/photo-booth.hsx +37 -0
  109. package/examples/03-diagnostics/README.md +68 -0
  110. package/examples/03-diagnostics/corner-shop-fixed.hsx +22 -0
  111. package/examples/03-diagnostics/corner-shop.hsx +19 -0
  112. package/examples/04-complete-product/README.md +87 -0
  113. package/examples/04-complete-product/study-hall.hsx +67 -0
  114. package/examples/05-watch-club/README.md +9 -0
  115. package/examples/05-watch-club/watch-club.hsx +124 -0
  116. package/examples/README.md +18 -0
  117. package/examples/advance/README.md +3 -0
  118. package/examples/advance/advance.hsx +13 -0
  119. package/examples/advance/advance.udl +339 -0
  120. package/examples/cancellable_booking/README.md +3 -0
  121. package/examples/cancellable_booking/cancellable_booking.hsx +14 -0
  122. package/examples/cancellable_booking/cancellable_booking.udl +391 -0
  123. package/examples/captured_payment/README.md +3 -0
  124. package/examples/captured_payment/captured_payment.hsx +21 -0
  125. package/examples/captured_payment/captured_payment.udl +677 -0
  126. package/examples/conditional_disbursement/README.md +3 -0
  127. package/examples/conditional_disbursement/conditional_disbursement.hsx +17 -0
  128. package/examples/conditional_disbursement/conditional_disbursement.udl +412 -0
  129. package/examples/cost-table.json +386 -0
  130. package/examples/credit_facility/README.md +3 -0
  131. package/examples/credit_facility/credit_facility.hsx +27 -0
  132. package/examples/credit_facility/credit_facility.udl +1373 -0
  133. package/examples/held_payment/README.md +3 -0
  134. package/examples/held_payment/held_payment.hsx +13 -0
  135. package/examples/held_payment/held_payment.udl +507 -0
  136. package/examples/instant_transfer/README.md +3 -0
  137. package/examples/instant_transfer/instant_transfer.hsx +16 -0
  138. package/examples/instant_transfer/instant_transfer.udl +364 -0
  139. package/examples/metered/README.md +3 -0
  140. package/examples/metered/metered.hsx +13 -0
  141. package/examples/metered/metered.udl +247 -0
  142. package/examples/pooled_split/README.md +3 -0
  143. package/examples/pooled_split/pooled_split.hsx +15 -0
  144. package/examples/pooled_split/pooled_split.udl +425 -0
  145. package/examples/premium_forward/README.md +3 -0
  146. package/examples/premium_forward/premium_forward.hsx +19 -0
  147. package/examples/premium_forward/premium_forward.udl +594 -0
  148. package/examples/reconciled_payout/README.md +3 -0
  149. package/examples/reconciled_payout/reconciled_payout.hsx +13 -0
  150. package/examples/reconciled_payout/reconciled_payout.udl +303 -0
  151. package/examples/recurring_collection/README.md +3 -0
  152. package/examples/recurring_collection/recurring_collection.hsx +21 -0
  153. package/examples/recurring_collection/recurring_collection.udl +1130 -0
  154. package/examples/rotating_pool/README.md +3 -0
  155. package/examples/rotating_pool/rotating_pool.hsx +18 -0
  156. package/examples/rotating_pool/rotating_pool.udl +4352 -0
  157. package/examples/scheduled/README.md +3 -0
  158. package/examples/scheduled/scheduled.hsx +12 -0
  159. package/examples/scheduled/scheduled.udl +335 -0
  160. package/examples/security_deposit/README.md +3 -0
  161. package/examples/security_deposit/security_deposit.hsx +21 -0
  162. package/examples/security_deposit/security_deposit.udl +293 -0
  163. package/examples/settlement_batch/README.md +3 -0
  164. package/examples/settlement_batch/settlement_batch.hsx +19 -0
  165. package/examples/settlement_batch/settlement_batch.udl +753 -0
  166. package/examples/swap/README.md +3 -0
  167. package/examples/swap/swap.hsx +19 -0
  168. package/examples/swap/swap.udl +876 -0
  169. package/examples/threshold_pool/README.md +3 -0
  170. package/examples/threshold_pool/threshold_pool.hsx +16 -0
  171. package/examples/threshold_pool/threshold_pool.udl +667 -0
  172. package/examples/weighted_distribution/README.md +3 -0
  173. package/examples/weighted_distribution/weighted_distribution.hsx +20 -0
  174. package/examples/weighted_distribution/weighted_distribution.udl +337 -0
  175. package/package.json +19 -6
  176. package/skills/hsx/SKILL.md +483 -0
  177. package/src/ast.ts +163 -9
  178. package/src/cli.ts +164 -12
  179. package/src/compile.ts +160 -20
  180. package/src/cost.ts +579 -0
  181. package/src/diagnostics.ts +442 -0
  182. package/src/emit.ts +447 -0
  183. package/src/entry-overrides.ts +263 -48
  184. package/src/format.ts +261 -0
  185. package/src/index.ts +32 -4
  186. package/src/ir.ts +99 -0
  187. package/src/lex.ts +59 -4
  188. package/src/limits.ts +2 -3
  189. package/src/modules.ts +444 -0
  190. package/src/parse.ts +655 -21
  191. package/src/typecheck.ts +3876 -0
  192. package/src/version.ts +4 -16
  193. package/std/SEMANTICS.md +130 -0
  194. package/std/settlements/advance.hsx +177 -0
  195. package/std/settlements/cancellable_booking.hsx +87 -0
  196. package/std/settlements/captured_payment.hsx +144 -0
  197. package/std/settlements/conditional_disbursement.hsx +185 -0
  198. package/std/settlements/credit_facility.hsx +167 -0
  199. package/std/settlements/held_payment.hsx +578 -0
  200. package/std/settlements/index.hsx +3 -0
  201. package/std/settlements/instant_transfer.hsx +190 -0
  202. package/std/settlements/metered.hsx +67 -0
  203. package/std/settlements/pooled_split.hsx +68 -0
  204. package/std/settlements/premium_forward.hsx +257 -0
  205. package/std/settlements/reconciled_payout.hsx +77 -0
  206. package/std/settlements/recurring_collection.hsx +27 -0
  207. package/std/settlements/rotating_pool.hsx +252 -0
  208. package/std/settlements/scheduled.hsx +641 -0
  209. package/std/settlements/security_deposit.hsx +166 -0
  210. package/std/settlements/settlement_batch.hsx +122 -0
  211. package/std/settlements/swap.hsx +1114 -0
  212. package/std/settlements/threshold_pool.hsx +221 -0
  213. package/std/settlements/weighted_distribution.hsx +141 -0
  214. package/dist/src/archetypes.d.ts +0 -17
  215. package/dist/src/archetypes.d.ts.map +0 -1
  216. package/dist/src/archetypes.js +0 -327
  217. package/dist/src/archetypes.js.map +0 -1
  218. package/dist/src/check.d.ts +0 -12
  219. package/dist/src/check.d.ts.map +0 -1
  220. package/dist/src/check.js +0 -1910
  221. package/dist/src/check.js.map +0 -1
  222. package/dist/src/lower.d.ts +0 -146
  223. package/dist/src/lower.d.ts.map +0 -1
  224. package/dist/src/lower.js +0 -4570
  225. package/dist/src/lower.js.map +0 -1
  226. package/dist/src/model.d.ts +0 -467
  227. package/dist/src/model.d.ts.map +0 -1
  228. package/dist/src/model.js +0 -15
  229. package/dist/src/model.js.map +0 -1
  230. package/spec/hsx-ir.schema.json +0 -920
  231. package/src/archetypes.ts +0 -340
  232. package/src/check.ts +0 -2938
  233. package/src/lower.ts +0 -5416
  234. package/src/model.ts +0 -519
@@ -0,0 +1,1114 @@
1
+ module std.settlements.swap;
2
+ export instrument swap<C>(between: list<party>, amounts: block, fees: block, release: condition, dispute: condition, side_names: optional<block>, lifecycle_state_order: optional<list<text>>, action_bindings: optional<block>, parked_states: optional<block>, fixed_prefix: optional<text>) {
3
+ let(side_a): at(between, 1);
4
+ let(side_b): at(between, 2);
5
+ let(side_a_amount): get(amounts, side_a);
6
+ let(side_b_amount): get(amounts, side_b);
7
+ let(side_a_fee): get(fees, side_a);
8
+ let(side_b_fee): get(fees, side_b);
9
+ when(side_names) {
10
+ let(side_a_name): get(side_names, "first");
11
+ let(side_b_name): get(side_names, "second");
12
+ }
13
+ when_not(side_names) {
14
+ let(side_a_name): side_a;
15
+ let(side_b_name): side_b;
16
+ }
17
+ let(side_a_account): concat(camel(side_a_name), "AccountId");
18
+ let(side_b_account): concat(camel(side_b_name), "AccountId");
19
+ 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.";
20
+ title: sentence(instrument);
21
+ when(fixed_prefix) {
22
+ id_prefix: fixed_prefix;
23
+ }
24
+ when_not(fixed_prefix) {
25
+ id_prefix: prefix(instrument);
26
+ }
27
+ summary: concat("Two-party atomic trade between ", words(side_a), " and ", words(side_b));
28
+ description: concat("Atomic swap between ", words(side_a), " and ", words(side_b), "; half-funded and half-released states do not exist");
29
+ distinct_parties: true;
30
+ when(side_names) {
31
+ parties {
32
+ payer: side_a_account;
33
+ beneficiary: side_b_account;
34
+ }
35
+ }
36
+ when_not(side_names) {
37
+ parties {
38
+ payer: side_a;
39
+ beneficiary: side_b;
40
+ }
41
+ }
42
+ 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];
43
+ when_not(side_names) {
44
+ computes fees {
45
+ amountField: concat(side_a_fee);
46
+ baseField: concat(side_a_amount);
47
+ bearerField: side_a_account;
48
+ position: on_top;
49
+ rule {
50
+ currencyField: currency;
51
+ field: concat(side_a_fee);
52
+ kind: exact;
53
+ }
54
+ }
55
+ computes fees {
56
+ amountField: concat(side_b_fee);
57
+ baseField: concat(side_b_amount);
58
+ bearerField: side_b_account;
59
+ position: on_top;
60
+ rule {
61
+ currencyField: currency;
62
+ field: concat(side_b_fee);
63
+ kind: exact;
64
+ }
65
+ }
66
+ }
67
+ when(parked_states) {
68
+ caller_parked_states: parked_states;
69
+ }
70
+ fields {
71
+ when(side_names) {
72
+ clawbackAt {
73
+ type: date;
74
+ description: "Machine-owned absolute end of the release clawback window";
75
+ optional: true;
76
+ }
77
+ currency {
78
+ type: text;
79
+ description: "One currency for both trade legs and both fees";
80
+ const: C;
81
+ }
82
+ "[side_a_account]" {
83
+ type: account<C>;
84
+ description: "First trade party and funder";
85
+ pattern: "^acct_(sandbox|live)_[a-z0-9]{8,64}$";
86
+ "x-hyperscale-reference-filter" {
87
+ column: role;
88
+ values: [customer_balance];
89
+ }
90
+ }
91
+ "[side_a_amount]" {
92
+ type: get(amounts, side_a);
93
+ description: concat("Amount side A holds against the whole exchange, in ", C, " minor units");
94
+ }
95
+ "[side_a_fee]" {
96
+ type: get(fees, side_a);
97
+ description: "Side A custody fee charged on top and never placed in escrow";
98
+ }
99
+ "[side_b_account]" {
100
+ type: account<C>;
101
+ description: "Second trade party and funder";
102
+ pattern: "^acct_(sandbox|live)_[a-z0-9]{8,64}$";
103
+ "x-hyperscale-reference-filter" {
104
+ column: role;
105
+ values: [customer_balance];
106
+ }
107
+ }
108
+ "[side_b_amount]" {
109
+ type: get(amounts, side_b);
110
+ description: concat("Amount side B holds against the whole exchange, in ", C, " minor units");
111
+ }
112
+ "[side_b_fee]" {
113
+ type: get(fees, side_b);
114
+ description: "Side B custody fee charged on top and never placed in escrow";
115
+ }
116
+ }
117
+ when_not(side_names) {
118
+ clawbackAt {
119
+ type: date;
120
+ description: concat("Machine-owned end of the ", dispute_within, " whole-trade dispute window");
121
+ }
122
+ "[side_a_amount]" {
123
+ type: get(amounts, side_a);
124
+ description: "Side A amount in SAR minor units, held against the whole trade";
125
+ }
126
+ "[side_b_amount]" {
127
+ type: get(amounts, side_b);
128
+ description: "Side B amount in SAR minor units, held against the whole trade";
129
+ }
130
+ "[side_a_fee]" {
131
+ type: get(fees, side_a);
132
+ description: concat("Immutable exact ", words(side_a), " service fee in SAR minor units");
133
+ }
134
+ "[side_b_fee]" {
135
+ type: get(fees, side_b);
136
+ description: concat("Immutable exact ", words(side_b), " service fee in SAR minor units");
137
+ }
138
+ }
139
+ platformAccountId {
140
+ type: account<C>;
141
+ when(side_names) {
142
+ description: "Product revenue or customer balance account collecting trade service fees";
143
+ }
144
+ when_not(side_names) {
145
+ description: "The product fee collection account";
146
+ }
147
+ pattern: "^acct_(sandbox|live)_[a-z0-9]{8,64}$";
148
+ "x-hyperscale-fee-collection-port": true;
149
+ "x-hyperscale-reference-filter" {
150
+ column: role;
151
+ values: [customer_balance, product_revenue];
152
+ }
153
+ }
154
+ }
155
+ when(lifecycle_state_order) {
156
+ let(states_key): "states";
157
+ lifecycle {
158
+ "[states_key]": lifecycle_state_order;
159
+ initial created;
160
+ on abandon: created -> abandoned;
161
+ on cancel: funded -> cancelled;
162
+ on dispute: released -> clawed_back;
163
+ on fund: created -> funded;
164
+ on post: released -> settled;
165
+ on release: funded -> released;
166
+ }
167
+ }
168
+ when_not(lifecycle_state_order) {
169
+ lifecycle {
170
+ states created abandoned funded cancelled released settled clawed_back;
171
+ initial created;
172
+ on abandon: created -> abandoned;
173
+ on cancel: funded -> cancelled;
174
+ on dispute: released -> clawed_back;
175
+ on fund: created -> funded;
176
+ on post: released -> settled;
177
+ on release: funded -> released;
178
+ }
179
+ }
180
+ when_not(action_bindings) {
181
+ action abandon {
182
+ 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.";
183
+ summary: "Abandon the trade before its atomic funding batch";
184
+ public_action: concat("abandon", title(camel(instrument)));
185
+ requires drained {
186
+ path: "refs.escrowAccountId";
187
+ }
188
+ moves: [];
189
+ steps: [];
190
+ }
191
+ action cancel {
192
+ 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.";
193
+ summary: "Cancel and return both trade principals atomically";
194
+ public_action: concat("cancel", title(camel(instrument)));
195
+ moves: [{
196
+ amount: concat(side_a_amount);
197
+ from: "refs.escrowAccountId";
198
+ to: side_a;
199
+ key: side_a_refund;
200
+ }, {
201
+ amount: concat(side_b_amount);
202
+ from: "refs.escrowAccountId";
203
+ to: side_b;
204
+ key: side_b_refund;
205
+ }];
206
+ steps: [];
207
+ }
208
+ action create {
209
+ 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.";
210
+ summary: concat("Create a ", words(instrument), " atomic trade");
211
+ public_action: concat("create", title(camel(instrument)));
212
+ moves: [];
213
+ steps: [{
214
+ operation: "account.escrow.provision";
215
+ bind {
216
+ currency {
217
+ from: instance;
218
+ path: "fields.currency";
219
+ }
220
+ "owner.id" {
221
+ from: instance;
222
+ path: productId;
223
+ }
224
+ "owner.type" {
225
+ from: const;
226
+ value: product;
227
+ }
228
+ productId {
229
+ from: instance;
230
+ path: productId;
231
+ }
232
+ role {
233
+ from: const;
234
+ value: product_escrow;
235
+ }
236
+ }
237
+ capture {
238
+ escrowAccountId: accountId;
239
+ }
240
+ }];
241
+ }
242
+ action dispute {
243
+ 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. Either trading party may call it.";
244
+ summary: "Void both reservations, then refund both principals atomically";
245
+ public_action: concat("dispute", title(camel(instrument)));
246
+ deadline {
247
+ field: clawbackAt;
248
+ }
249
+ port {
250
+ allowedParties: [payer, beneficiary];
251
+ }
252
+ moves: [{
253
+ bind {
254
+ reason {
255
+ from: const;
256
+ value: "Whole trade disputed inside the clawback window";
257
+ }
258
+ transferId {
259
+ from: instance;
260
+ path: "refs.releaseSideATransferId";
261
+ }
262
+ }
263
+ key: side_a_void;
264
+ operation: "internal_transfer.void";
265
+ }, {
266
+ bind {
267
+ reason {
268
+ from: const;
269
+ value: "Whole trade disputed inside the clawback window";
270
+ }
271
+ transferId {
272
+ from: instance;
273
+ path: "refs.releaseSideBTransferId";
274
+ }
275
+ }
276
+ key: side_b_void;
277
+ operation: "internal_transfer.void";
278
+ }, {
279
+ bind {
280
+ amount {
281
+ from: instance;
282
+ path: concat("fields.", side_a_amount);
283
+ }
284
+ currency {
285
+ from: instance;
286
+ path: "fields.currency";
287
+ }
288
+ destinationAccountId {
289
+ from: instance;
290
+ path: concat("fields.", side_a_account);
291
+ }
292
+ "metadata.clawbackOfTransferId" {
293
+ from: instance;
294
+ path: "refs.releaseSideATransferId";
295
+ }
296
+ "metadata.instrumentId" {
297
+ from: const;
298
+ value: instrument;
299
+ }
300
+ "metadata.instrumentInstanceId" {
301
+ from: instance;
302
+ path: instrumentInstanceId;
303
+ }
304
+ "metadata.phase" {
305
+ from: const;
306
+ value: "dispute";
307
+ }
308
+ productId {
309
+ from: instance;
310
+ path: productId;
311
+ }
312
+ sourceAccountId {
313
+ from: instance;
314
+ path: "refs.escrowAccountId";
315
+ }
316
+ }
317
+ capture {
318
+ disputeSideARefundTransferId: transferId;
319
+ }
320
+ key: side_a_refund;
321
+ operation: "internal_transfer.create";
322
+ }, {
323
+ bind {
324
+ amount {
325
+ from: instance;
326
+ path: concat("fields.", side_b_amount);
327
+ }
328
+ currency {
329
+ from: instance;
330
+ path: "fields.currency";
331
+ }
332
+ destinationAccountId {
333
+ from: instance;
334
+ path: concat("fields.", side_b_account);
335
+ }
336
+ "metadata.clawbackOfTransferId" {
337
+ from: instance;
338
+ path: "refs.releaseSideBTransferId";
339
+ }
340
+ "metadata.instrumentId" {
341
+ from: const;
342
+ value: instrument;
343
+ }
344
+ "metadata.instrumentInstanceId" {
345
+ from: instance;
346
+ path: instrumentInstanceId;
347
+ }
348
+ "metadata.phase" {
349
+ from: const;
350
+ value: "dispute";
351
+ }
352
+ productId {
353
+ from: instance;
354
+ path: productId;
355
+ }
356
+ sourceAccountId {
357
+ from: instance;
358
+ path: "refs.escrowAccountId";
359
+ }
360
+ }
361
+ capture {
362
+ disputeSideBRefundTransferId: transferId;
363
+ }
364
+ key: side_b_refund;
365
+ operation: "internal_transfer.create";
366
+ }];
367
+ steps: [];
368
+ }
369
+ action fund {
370
+ 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.";
371
+ summary: "Fund both trade sides and collect on-top fees atomically";
372
+ public_action: concat("fund", title(camel(instrument)));
373
+ moves: [{
374
+ amount: concat(side_a_amount);
375
+ from: side_a;
376
+ to: "refs.escrowAccountId";
377
+ key: side_a_principal;
378
+ }, {
379
+ amount: concat(side_b_amount);
380
+ from: side_b;
381
+ to: "refs.escrowAccountId";
382
+ key: side_b_principal;
383
+ }, {
384
+ amount: concat(side_a_fee);
385
+ from: side_a;
386
+ to: platformAccountId;
387
+ key: side_a_service_fee;
388
+ }, {
389
+ amount: concat(side_b_fee);
390
+ from: side_b;
391
+ to: platformAccountId;
392
+ key: side_b_service_fee;
393
+ }];
394
+ steps: [];
395
+ }
396
+ action post {
397
+ summary: "Post both trade reservations when the clawback window matures";
398
+ due {
399
+ field: clawbackAt;
400
+ }
401
+ moves: [{
402
+ bind {
403
+ transferId {
404
+ from: instance;
405
+ path: "refs.releaseSideATransferId";
406
+ }
407
+ }
408
+ key: "side_a";
409
+ operation: "internal_transfer.post";
410
+ }, {
411
+ bind {
412
+ transferId {
413
+ from: instance;
414
+ path: "refs.releaseSideBTransferId";
415
+ }
416
+ }
417
+ key: "side_b";
418
+ operation: "internal_transfer.post";
419
+ }];
420
+ steps: [];
421
+ }
422
+ action release {
423
+ 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. Either trading party may call it.";
424
+ summary: "Reserve both cross-payments for the whole-trade clawback window";
425
+ public_action: concat("release", title(camel(instrument)));
426
+ port {
427
+ allowedParties: [payer, beneficiary];
428
+ }
429
+ sets_at {
430
+ field: clawbackAt;
431
+ offset: dispute_within;
432
+ }
433
+ moves: [{
434
+ bind {
435
+ amount {
436
+ from: instance;
437
+ path: concat("fields.", side_a_amount);
438
+ }
439
+ currency {
440
+ from: instance;
441
+ path: "fields.currency";
442
+ }
443
+ destinationAccountId {
444
+ from: instance;
445
+ path: concat("fields.", side_b_account);
446
+ }
447
+ "metadata.clawbackAt" {
448
+ from: instance;
449
+ path: "fields.clawbackAt";
450
+ }
451
+ "metadata.instrumentId" {
452
+ from: const;
453
+ value: instrument;
454
+ }
455
+ "metadata.instrumentInstanceId" {
456
+ from: instance;
457
+ path: instrumentInstanceId;
458
+ }
459
+ "metadata.phase" {
460
+ from: const;
461
+ value: "release";
462
+ }
463
+ productId {
464
+ from: instance;
465
+ path: productId;
466
+ }
467
+ sourceAccountId {
468
+ from: instance;
469
+ path: "refs.escrowAccountId";
470
+ }
471
+ }
472
+ capture {
473
+ releaseSideATransferId: transferId;
474
+ }
475
+ key: "side_a";
476
+ operation: "internal_transfer.reserve";
477
+ }, {
478
+ bind {
479
+ amount {
480
+ from: instance;
481
+ path: concat("fields.", side_b_amount);
482
+ }
483
+ currency {
484
+ from: instance;
485
+ path: "fields.currency";
486
+ }
487
+ destinationAccountId {
488
+ from: instance;
489
+ path: concat("fields.", side_a_account);
490
+ }
491
+ "metadata.clawbackAt" {
492
+ from: instance;
493
+ path: "fields.clawbackAt";
494
+ }
495
+ "metadata.instrumentId" {
496
+ from: const;
497
+ value: instrument;
498
+ }
499
+ "metadata.instrumentInstanceId" {
500
+ from: instance;
501
+ path: instrumentInstanceId;
502
+ }
503
+ "metadata.phase" {
504
+ from: const;
505
+ value: "release";
506
+ }
507
+ productId {
508
+ from: instance;
509
+ path: productId;
510
+ }
511
+ sourceAccountId {
512
+ from: instance;
513
+ path: "refs.escrowAccountId";
514
+ }
515
+ }
516
+ capture {
517
+ releaseSideBTransferId: transferId;
518
+ }
519
+ key: "side_b";
520
+ operation: "internal_transfer.reserve";
521
+ }];
522
+ steps: [];
523
+ }
524
+ }
525
+ when(action_bindings) {
526
+ let(event_prefix): get(action_bindings, "event_prefix");
527
+ let(fund_principal_capture): get(action_bindings, "fund_principal_capture");
528
+ let(fund_fee_capture): get(action_bindings, "fund_fee_capture");
529
+ let(fund_principal_phase): get(action_bindings, "fund_principal_phase");
530
+ let(fund_fee_phase): get(action_bindings, "fund_fee_phase");
531
+ let(release_capture): get(action_bindings, "release_capture");
532
+ let(release_phase): get(action_bindings, "release_phase");
533
+ let(release_key): get(action_bindings, "release_key");
534
+ let(post_key): get(action_bindings, "post_key");
535
+ let(dispute_capture): get(action_bindings, "dispute_capture");
536
+ let(dispute_phase): get(action_bindings, "dispute_phase");
537
+ let(dispute_reason): get(action_bindings, "dispute_reason");
538
+ let(cancel_capture): get(action_bindings, "cancel_capture");
539
+ let(cancel_phase): get(action_bindings, "cancel_phase");
540
+ let(side_a_fund_capture): camel(concat(side_a_name, "_", fund_principal_capture, "_transfer_id"));
541
+ let(side_b_fund_capture): camel(concat(side_b_name, "_", fund_principal_capture, "_transfer_id"));
542
+ let(side_a_fee_capture): camel(concat(side_a_name, "_", fund_fee_capture, "_transfer_id"));
543
+ let(side_b_fee_capture): camel(concat(side_b_name, "_", fund_fee_capture, "_transfer_id"));
544
+ let(side_a_release_capture): camel(concat(side_a_name, "_", release_capture, "_id"));
545
+ let(side_b_release_capture): camel(concat(side_b_name, "_", release_capture, "_id"));
546
+ let(side_a_release_ref): concat("refs.", side_a_release_capture);
547
+ let(side_b_release_ref): concat("refs.", side_b_release_capture);
548
+ let(side_a_dispute_capture): camel(concat(side_a_name, "_", dispute_capture, "_transfer_id"));
549
+ let(side_b_dispute_capture): camel(concat(side_b_name, "_", dispute_capture, "_transfer_id"));
550
+ let(side_a_cancel_capture): camel(concat(side_a_name, "_", cancel_capture, "_transfer_id"));
551
+ let(side_b_cancel_capture): camel(concat(side_b_name, "_", cancel_capture, "_transfer_id"));
552
+ action create {
553
+ 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.";
554
+ summary: concat("Create a ", words(instrument), " atomic trade");
555
+ public_action: concat("create", title(camel(instrument)));
556
+ moves: [];
557
+ steps: [{
558
+ operation: "account.escrow.provision";
559
+ bind {
560
+ currency {
561
+ from: instance;
562
+ path: "fields.currency";
563
+ }
564
+ "owner.id" {
565
+ from: instance;
566
+ path: productId;
567
+ }
568
+ "owner.type" {
569
+ from: const;
570
+ value: product;
571
+ }
572
+ productId {
573
+ from: instance;
574
+ path: productId;
575
+ }
576
+ role {
577
+ from: const;
578
+ value: product_escrow;
579
+ }
580
+ }
581
+ capture {
582
+ escrowAccountId: accountId;
583
+ }
584
+ }];
585
+ }
586
+ action fund {
587
+ 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.";
588
+ summary: "Fund both trade sides and collect on-top fees atomically";
589
+ public_action: concat("fund", title(camel(instrument)));
590
+ event_name: concat(event_prefix, ".funded");
591
+ sandbox_failure_point: "funding";
592
+ moves: [{
593
+ bind {
594
+ amount {
595
+ from: instance;
596
+ path: concat("fields.", side_a_amount);
597
+ }
598
+ currency {
599
+ from: instance;
600
+ path: "fields.currency";
601
+ }
602
+ destinationAccountId {
603
+ from: instance;
604
+ path: "refs.escrowAccountId";
605
+ }
606
+ "metadata.instrumentId" {
607
+ from: const;
608
+ value: instrument;
609
+ }
610
+ "metadata.instrumentInstanceId" {
611
+ from: instance;
612
+ path: instrumentInstanceId;
613
+ }
614
+ "metadata.phase" {
615
+ from: const;
616
+ value: fund_principal_phase;
617
+ }
618
+ productId {
619
+ from: instance;
620
+ path: productId;
621
+ }
622
+ sourceAccountId {
623
+ from: instance;
624
+ path: concat("fields.", side_a_account);
625
+ }
626
+ }
627
+ capture {
628
+ "[side_a_fund_capture]": transferId;
629
+ }
630
+ key: side_a_principal;
631
+ operation: "internal_transfer.create";
632
+ }, {
633
+ bind {
634
+ amount {
635
+ from: instance;
636
+ path: concat("fields.", side_b_amount);
637
+ }
638
+ currency {
639
+ from: instance;
640
+ path: "fields.currency";
641
+ }
642
+ destinationAccountId {
643
+ from: instance;
644
+ path: "refs.escrowAccountId";
645
+ }
646
+ "metadata.instrumentId" {
647
+ from: const;
648
+ value: instrument;
649
+ }
650
+ "metadata.instrumentInstanceId" {
651
+ from: instance;
652
+ path: instrumentInstanceId;
653
+ }
654
+ "metadata.phase" {
655
+ from: const;
656
+ value: fund_principal_phase;
657
+ }
658
+ productId {
659
+ from: instance;
660
+ path: productId;
661
+ }
662
+ sourceAccountId {
663
+ from: instance;
664
+ path: concat("fields.", side_b_account);
665
+ }
666
+ }
667
+ capture {
668
+ "[side_b_fund_capture]": transferId;
669
+ }
670
+ key: side_b_principal;
671
+ operation: "internal_transfer.create";
672
+ }, {
673
+ bind {
674
+ amount {
675
+ from: instance;
676
+ path: concat("fields.", side_a_fee);
677
+ }
678
+ currency {
679
+ from: instance;
680
+ path: "fields.currency";
681
+ }
682
+ destinationAccountId {
683
+ from: instance;
684
+ path: "fields.platformAccountId";
685
+ }
686
+ "metadata.instrumentId" {
687
+ from: const;
688
+ value: instrument;
689
+ }
690
+ "metadata.instrumentInstanceId" {
691
+ from: instance;
692
+ path: instrumentInstanceId;
693
+ }
694
+ "metadata.phase" {
695
+ from: const;
696
+ value: fund_fee_phase;
697
+ }
698
+ productId {
699
+ from: instance;
700
+ path: productId;
701
+ }
702
+ sourceAccountId {
703
+ from: instance;
704
+ path: concat("fields.", side_a_account);
705
+ }
706
+ }
707
+ capture {
708
+ "[side_a_fee_capture]": transferId;
709
+ }
710
+ key: side_a_service_fee;
711
+ operation: "internal_transfer.create";
712
+ }, {
713
+ bind {
714
+ amount {
715
+ from: instance;
716
+ path: concat("fields.", side_b_fee);
717
+ }
718
+ currency {
719
+ from: instance;
720
+ path: "fields.currency";
721
+ }
722
+ destinationAccountId {
723
+ from: instance;
724
+ path: "fields.platformAccountId";
725
+ }
726
+ "metadata.instrumentId" {
727
+ from: const;
728
+ value: instrument;
729
+ }
730
+ "metadata.instrumentInstanceId" {
731
+ from: instance;
732
+ path: instrumentInstanceId;
733
+ }
734
+ "metadata.phase" {
735
+ from: const;
736
+ value: fund_fee_phase;
737
+ }
738
+ productId {
739
+ from: instance;
740
+ path: productId;
741
+ }
742
+ sourceAccountId {
743
+ from: instance;
744
+ path: concat("fields.", side_b_account);
745
+ }
746
+ }
747
+ capture {
748
+ "[side_b_fee_capture]": transferId;
749
+ }
750
+ key: side_b_service_fee;
751
+ operation: "internal_transfer.create";
752
+ }];
753
+ steps: [];
754
+ }
755
+ action release {
756
+ 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. Either trading party may call it.";
757
+ summary: "Reserve both cross-payments for the whole-trade clawback window";
758
+ public_action: concat("release", title(camel(instrument)));
759
+ event_name: concat(event_prefix, ".released");
760
+ port {
761
+ allowedParties: [payer, beneficiary];
762
+ }
763
+ sandbox_failure_point: "release";
764
+ sets_at {
765
+ field: clawbackAt;
766
+ offset: dispute_within;
767
+ }
768
+ moves: [{
769
+ bind {
770
+ amount {
771
+ from: instance;
772
+ path: concat("fields.", side_a_amount);
773
+ }
774
+ currency {
775
+ from: instance;
776
+ path: "fields.currency";
777
+ }
778
+ destinationAccountId {
779
+ from: instance;
780
+ path: concat("fields.", side_b_account);
781
+ }
782
+ "metadata.clawbackAt" {
783
+ from: instance;
784
+ path: "fields.clawbackAt";
785
+ }
786
+ "metadata.instrumentId" {
787
+ from: const;
788
+ value: instrument;
789
+ }
790
+ "metadata.instrumentInstanceId" {
791
+ from: instance;
792
+ path: instrumentInstanceId;
793
+ }
794
+ "metadata.phase" {
795
+ from: const;
796
+ value: release_phase;
797
+ }
798
+ productId {
799
+ from: instance;
800
+ path: productId;
801
+ }
802
+ sourceAccountId {
803
+ from: instance;
804
+ path: "refs.escrowAccountId";
805
+ }
806
+ }
807
+ capture {
808
+ "[side_a_release_capture]": transferId;
809
+ }
810
+ key: concat("side_a_", release_key);
811
+ operation: "internal_transfer.reserve";
812
+ }, {
813
+ bind {
814
+ amount {
815
+ from: instance;
816
+ path: concat("fields.", side_b_amount);
817
+ }
818
+ currency {
819
+ from: instance;
820
+ path: "fields.currency";
821
+ }
822
+ destinationAccountId {
823
+ from: instance;
824
+ path: concat("fields.", side_a_account);
825
+ }
826
+ "metadata.clawbackAt" {
827
+ from: instance;
828
+ path: "fields.clawbackAt";
829
+ }
830
+ "metadata.instrumentId" {
831
+ from: const;
832
+ value: instrument;
833
+ }
834
+ "metadata.instrumentInstanceId" {
835
+ from: instance;
836
+ path: instrumentInstanceId;
837
+ }
838
+ "metadata.phase" {
839
+ from: const;
840
+ value: release_phase;
841
+ }
842
+ productId {
843
+ from: instance;
844
+ path: productId;
845
+ }
846
+ sourceAccountId {
847
+ from: instance;
848
+ path: "refs.escrowAccountId";
849
+ }
850
+ }
851
+ capture {
852
+ "[side_b_release_capture]": transferId;
853
+ }
854
+ key: concat("side_b_", release_key);
855
+ operation: "internal_transfer.reserve";
856
+ }];
857
+ steps: [];
858
+ }
859
+ action post {
860
+ summary: "Post both trade reservations when the clawback window matures";
861
+ event_name: concat(event_prefix, ".posted");
862
+ due {
863
+ field: clawbackAt;
864
+ }
865
+ moves: [{
866
+ bind {
867
+ transferId {
868
+ from: instance;
869
+ path: side_a_release_ref;
870
+ }
871
+ }
872
+ key: concat("side_a_", post_key);
873
+ operation: "internal_transfer.post";
874
+ }, {
875
+ bind {
876
+ transferId {
877
+ from: instance;
878
+ path: side_b_release_ref;
879
+ }
880
+ }
881
+ key: concat("side_b_", post_key);
882
+ operation: "internal_transfer.post";
883
+ }];
884
+ steps: [];
885
+ }
886
+ action dispute {
887
+ 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. Either trading party may call it.";
888
+ summary: "Void both reservations, then refund both principals atomically";
889
+ public_action: concat("dispute", title(camel(instrument)));
890
+ event_name: concat(event_prefix, ".clawed_back");
891
+ deadline {
892
+ field: clawbackAt;
893
+ }
894
+ port {
895
+ allowedParties: [payer, beneficiary];
896
+ }
897
+ moves: [{
898
+ bind {
899
+ reason {
900
+ from: const;
901
+ value: dispute_reason;
902
+ }
903
+ transferId {
904
+ from: instance;
905
+ path: side_a_release_ref;
906
+ }
907
+ }
908
+ key: side_a_void;
909
+ operation: "internal_transfer.void";
910
+ }, {
911
+ bind {
912
+ reason {
913
+ from: const;
914
+ value: dispute_reason;
915
+ }
916
+ transferId {
917
+ from: instance;
918
+ path: side_b_release_ref;
919
+ }
920
+ }
921
+ key: side_b_void;
922
+ operation: "internal_transfer.void";
923
+ }, {
924
+ bind {
925
+ amount {
926
+ from: instance;
927
+ path: concat("fields.", side_a_amount);
928
+ }
929
+ currency {
930
+ from: instance;
931
+ path: "fields.currency";
932
+ }
933
+ destinationAccountId {
934
+ from: instance;
935
+ path: concat("fields.", side_a_account);
936
+ }
937
+ "metadata.clawbackOfTransferId" {
938
+ from: instance;
939
+ path: side_a_release_ref;
940
+ }
941
+ "metadata.instrumentId" {
942
+ from: const;
943
+ value: instrument;
944
+ }
945
+ "metadata.instrumentInstanceId" {
946
+ from: instance;
947
+ path: instrumentInstanceId;
948
+ }
949
+ "metadata.phase" {
950
+ from: const;
951
+ value: dispute_phase;
952
+ }
953
+ productId {
954
+ from: instance;
955
+ path: productId;
956
+ }
957
+ sourceAccountId {
958
+ from: instance;
959
+ path: "refs.escrowAccountId";
960
+ }
961
+ }
962
+ capture {
963
+ "[side_a_dispute_capture]": transferId;
964
+ }
965
+ key: side_a_refund;
966
+ operation: "internal_transfer.create";
967
+ }, {
968
+ bind {
969
+ amount {
970
+ from: instance;
971
+ path: concat("fields.", side_b_amount);
972
+ }
973
+ currency {
974
+ from: instance;
975
+ path: "fields.currency";
976
+ }
977
+ destinationAccountId {
978
+ from: instance;
979
+ path: concat("fields.", side_b_account);
980
+ }
981
+ "metadata.clawbackOfTransferId" {
982
+ from: instance;
983
+ path: side_b_release_ref;
984
+ }
985
+ "metadata.instrumentId" {
986
+ from: const;
987
+ value: instrument;
988
+ }
989
+ "metadata.instrumentInstanceId" {
990
+ from: instance;
991
+ path: instrumentInstanceId;
992
+ }
993
+ "metadata.phase" {
994
+ from: const;
995
+ value: dispute_phase;
996
+ }
997
+ productId {
998
+ from: instance;
999
+ path: productId;
1000
+ }
1001
+ sourceAccountId {
1002
+ from: instance;
1003
+ path: "refs.escrowAccountId";
1004
+ }
1005
+ }
1006
+ capture {
1007
+ "[side_b_dispute_capture]": transferId;
1008
+ }
1009
+ key: side_b_refund;
1010
+ operation: "internal_transfer.create";
1011
+ }];
1012
+ steps: [];
1013
+ }
1014
+ action cancel {
1015
+ 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.";
1016
+ summary: "Cancel and return both trade principals atomically";
1017
+ public_action: concat("cancel", title(camel(instrument)));
1018
+ event_name: concat(event_prefix, ".cancelled");
1019
+ moves: [{
1020
+ bind {
1021
+ amount {
1022
+ from: instance;
1023
+ path: concat("fields.", side_a_amount);
1024
+ }
1025
+ currency {
1026
+ from: instance;
1027
+ path: "fields.currency";
1028
+ }
1029
+ destinationAccountId {
1030
+ from: instance;
1031
+ path: concat("fields.", side_a_account);
1032
+ }
1033
+ "metadata.instrumentId" {
1034
+ from: const;
1035
+ value: instrument;
1036
+ }
1037
+ "metadata.instrumentInstanceId" {
1038
+ from: instance;
1039
+ path: instrumentInstanceId;
1040
+ }
1041
+ "metadata.phase" {
1042
+ from: const;
1043
+ value: cancel_phase;
1044
+ }
1045
+ productId {
1046
+ from: instance;
1047
+ path: productId;
1048
+ }
1049
+ sourceAccountId {
1050
+ from: instance;
1051
+ path: "refs.escrowAccountId";
1052
+ }
1053
+ }
1054
+ capture {
1055
+ "[side_a_cancel_capture]": transferId;
1056
+ }
1057
+ key: side_a_refund;
1058
+ operation: "internal_transfer.create";
1059
+ }, {
1060
+ bind {
1061
+ amount {
1062
+ from: instance;
1063
+ path: concat("fields.", side_b_amount);
1064
+ }
1065
+ currency {
1066
+ from: instance;
1067
+ path: "fields.currency";
1068
+ }
1069
+ destinationAccountId {
1070
+ from: instance;
1071
+ path: concat("fields.", side_b_account);
1072
+ }
1073
+ "metadata.instrumentId" {
1074
+ from: const;
1075
+ value: instrument;
1076
+ }
1077
+ "metadata.instrumentInstanceId" {
1078
+ from: instance;
1079
+ path: instrumentInstanceId;
1080
+ }
1081
+ "metadata.phase" {
1082
+ from: const;
1083
+ value: cancel_phase;
1084
+ }
1085
+ productId {
1086
+ from: instance;
1087
+ path: productId;
1088
+ }
1089
+ sourceAccountId {
1090
+ from: instance;
1091
+ path: "refs.escrowAccountId";
1092
+ }
1093
+ }
1094
+ capture {
1095
+ "[side_b_cancel_capture]": transferId;
1096
+ }
1097
+ key: side_b_refund;
1098
+ operation: "internal_transfer.create";
1099
+ }];
1100
+ steps: [];
1101
+ }
1102
+ action abandon {
1103
+ 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.";
1104
+ summary: "Abandon the trade before its atomic funding batch";
1105
+ public_action: concat("abandon", title(camel(instrument)));
1106
+ event_name: concat(event_prefix, ".abandoned");
1107
+ requires drained {
1108
+ path: "refs.escrowAccountId";
1109
+ }
1110
+ moves: [];
1111
+ steps: [];
1112
+ }
1113
+ }
1114
+ }