@xochi/client 0.0.0-stage → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +21 -0
  3. package/README.md +120 -2
  4. package/dist/cjs/claim.d.ts +33 -0
  5. package/dist/cjs/claim.js +44 -0
  6. package/dist/cjs/fee.d.ts +247 -0
  7. package/dist/cjs/fee.js +295 -0
  8. package/dist/cjs/index.d.ts +18 -0
  9. package/dist/cjs/index.js +33 -0
  10. package/dist/cjs/machine/claimInfo.d.ts +29 -0
  11. package/dist/cjs/machine/claimInfo.js +26 -0
  12. package/dist/cjs/machine/decisions.d.ts +452 -0
  13. package/dist/cjs/machine/decisions.js +665 -0
  14. package/dist/cjs/machine/deposit.d.ts +113 -0
  15. package/dist/cjs/machine/deposit.js +265 -0
  16. package/dist/cjs/machine/index.d.ts +23 -0
  17. package/dist/cjs/machine/index.js +53 -0
  18. package/dist/cjs/machine/machine.d.ts +411 -0
  19. package/dist/cjs/machine/machine.js +1627 -0
  20. package/dist/cjs/machine/phase.d.ts +24 -0
  21. package/dist/cjs/machine/phase.js +45 -0
  22. package/dist/cjs/machine/quoteChecks.d.ts +41 -0
  23. package/dist/cjs/machine/quoteChecks.js +82 -0
  24. package/dist/cjs/machine/receipt.d.ts +151 -0
  25. package/dist/cjs/machine/receipt.js +69 -0
  26. package/dist/cjs/machine/recipientEcho.d.ts +16 -0
  27. package/dist/cjs/machine/recipientEcho.js +27 -0
  28. package/dist/cjs/machine/solverPin.d.ts +110 -0
  29. package/dist/cjs/machine/solverPin.js +214 -0
  30. package/dist/cjs/machine/state.d.ts +167 -0
  31. package/dist/cjs/machine/state.js +31 -0
  32. package/dist/cjs/machine/transition.d.ts +15 -0
  33. package/dist/cjs/machine/transition.js +20 -0
  34. package/dist/cjs/machine/validateRequest.d.ts +15 -0
  35. package/dist/cjs/machine/validateRequest.js +127 -0
  36. package/dist/cjs/machine/view.d.ts +3 -0
  37. package/dist/cjs/machine/view.js +74 -0
  38. package/dist/cjs/machine/wire.d.ts +527 -0
  39. package/dist/cjs/machine/wire.js +280 -0
  40. package/dist/cjs/package.json +1 -0
  41. package/dist/cjs/shared/api.d.ts +9 -0
  42. package/dist/cjs/shared/api.js +5 -0
  43. package/dist/cjs/shared/chains.d.ts +243 -0
  44. package/dist/cjs/shared/chains.js +250 -0
  45. package/dist/cjs/shared/eip712.d.ts +44 -0
  46. package/dist/cjs/shared/eip712.js +64 -0
  47. package/dist/cjs/shared/index.d.ts +16 -0
  48. package/dist/cjs/shared/index.js +32 -0
  49. package/dist/cjs/shared/intentStream.d.ts +74 -0
  50. package/dist/cjs/shared/intentStream.js +59 -0
  51. package/dist/cjs/shared/intents.d.ts +88 -0
  52. package/dist/cjs/shared/intents.js +227 -0
  53. package/dist/cjs/shared/schemas.d.ts +928 -0
  54. package/dist/cjs/shared/schemas.js +524 -0
  55. package/dist/cjs/shared/shieldedPreview.d.ts +841 -0
  56. package/dist/cjs/shared/shieldedPreview.js +128 -0
  57. package/dist/cjs/shared/stealth.d.ts +53 -0
  58. package/dist/cjs/shared/stealth.js +68 -0
  59. package/dist/cjs/shared/trading.d.ts +153 -0
  60. package/dist/cjs/shared/trading.js +185 -0
  61. package/dist/cjs/shared/types.d.ts +37 -0
  62. package/dist/cjs/shared/types.js +7 -0
  63. package/dist/cjs/shared/validators.d.ts +30 -0
  64. package/dist/cjs/shared/validators.js +79 -0
  65. package/dist/cjs/transport/client.d.ts +234 -0
  66. package/dist/cjs/transport/client.js +1456 -0
  67. package/dist/esm/claim.d.ts +33 -0
  68. package/dist/esm/claim.js +41 -0
  69. package/dist/esm/fee.d.ts +247 -0
  70. package/dist/esm/fee.js +285 -0
  71. package/dist/esm/index.d.ts +18 -0
  72. package/dist/esm/index.js +17 -0
  73. package/dist/esm/machine/claimInfo.d.ts +29 -0
  74. package/dist/esm/machine/claimInfo.js +23 -0
  75. package/dist/esm/machine/decisions.d.ts +452 -0
  76. package/dist/esm/machine/decisions.js +640 -0
  77. package/dist/esm/machine/deposit.d.ts +113 -0
  78. package/dist/esm/machine/deposit.js +260 -0
  79. package/dist/esm/machine/index.d.ts +23 -0
  80. package/dist/esm/machine/index.js +23 -0
  81. package/dist/esm/machine/machine.d.ts +411 -0
  82. package/dist/esm/machine/machine.js +1621 -0
  83. package/dist/esm/machine/phase.d.ts +24 -0
  84. package/dist/esm/machine/phase.js +42 -0
  85. package/dist/esm/machine/quoteChecks.d.ts +41 -0
  86. package/dist/esm/machine/quoteChecks.js +78 -0
  87. package/dist/esm/machine/receipt.d.ts +151 -0
  88. package/dist/esm/machine/receipt.js +64 -0
  89. package/dist/esm/machine/recipientEcho.d.ts +16 -0
  90. package/dist/esm/machine/recipientEcho.js +24 -0
  91. package/dist/esm/machine/solverPin.d.ts +110 -0
  92. package/dist/esm/machine/solverPin.js +210 -0
  93. package/dist/esm/machine/state.d.ts +167 -0
  94. package/dist/esm/machine/state.js +28 -0
  95. package/dist/esm/machine/transition.d.ts +15 -0
  96. package/dist/esm/machine/transition.js +17 -0
  97. package/dist/esm/machine/validateRequest.d.ts +15 -0
  98. package/dist/esm/machine/validateRequest.js +123 -0
  99. package/dist/esm/machine/view.d.ts +3 -0
  100. package/dist/esm/machine/view.js +71 -0
  101. package/dist/esm/machine/wire.d.ts +527 -0
  102. package/dist/esm/machine/wire.js +266 -0
  103. package/dist/esm/shared/api.d.ts +9 -0
  104. package/dist/esm/shared/api.js +4 -0
  105. package/dist/esm/shared/chains.d.ts +243 -0
  106. package/dist/esm/shared/chains.js +236 -0
  107. package/dist/esm/shared/eip712.d.ts +44 -0
  108. package/dist/esm/shared/eip712.js +61 -0
  109. package/dist/esm/shared/index.d.ts +16 -0
  110. package/dist/esm/shared/index.js +16 -0
  111. package/dist/esm/shared/intentStream.d.ts +74 -0
  112. package/dist/esm/shared/intentStream.js +55 -0
  113. package/dist/esm/shared/intents.d.ts +88 -0
  114. package/dist/esm/shared/intents.js +213 -0
  115. package/dist/esm/shared/schemas.d.ts +928 -0
  116. package/dist/esm/shared/schemas.js +521 -0
  117. package/dist/esm/shared/shieldedPreview.d.ts +841 -0
  118. package/dist/esm/shared/shieldedPreview.js +124 -0
  119. package/dist/esm/shared/stealth.d.ts +53 -0
  120. package/dist/esm/shared/stealth.js +64 -0
  121. package/dist/esm/shared/trading.d.ts +153 -0
  122. package/dist/esm/shared/trading.js +182 -0
  123. package/dist/esm/shared/types.d.ts +37 -0
  124. package/dist/esm/shared/types.js +6 -0
  125. package/dist/esm/shared/validators.d.ts +30 -0
  126. package/dist/esm/shared/validators.js +74 -0
  127. package/dist/esm/transport/client.d.ts +234 -0
  128. package/dist/esm/transport/client.js +1447 -0
  129. package/package.json +61 -4
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ /**
3
+ * Intent Types
4
+ *
5
+ * Status types, order types, and state machine transitions
6
+ * for the cross-chain intent system.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.LIMIT_ORDER_EXPIRY_PRESETS = exports.LIMIT_ORDER_STATUS_TRANSITIONS = exports.LIMIT_ORDER_STATUSES = exports.INTENT_STATUS_TRANSITIONS = exports.NOT_EXECUTED_SUBSTATUS = exports.INTENT_STATUSES = void 0;
10
+ exports.isSettlementType = isSettlementType;
11
+ exports.isOrderType = isOrderType;
12
+ exports.isTriggerCondition = isTriggerCondition;
13
+ exports.isIntentStatus = isIntentStatus;
14
+ exports.canTransitionTo = canTransitionTo;
15
+ exports.getStatusLabel = getStatusLabel;
16
+ exports.getRefundReasonLabel = getRefundReasonLabel;
17
+ exports.isLimitOrderStatus = isLimitOrderStatus;
18
+ exports.canLimitOrderTransitionTo = canLimitOrderTransitionTo;
19
+ exports.getLimitOrderStatusLabel = getLimitOrderStatusLabel;
20
+ exports.isDestinationType = isDestinationType;
21
+ function isSettlementType(value) {
22
+ return value === "public" || value === "shielded" || value === "stealth";
23
+ }
24
+ function isOrderType(value) {
25
+ return value === "market" || value === "limit";
26
+ }
27
+ function isTriggerCondition(value) {
28
+ return value === "gte" || value === "lte";
29
+ }
30
+ /** All valid intent statuses */
31
+ exports.INTENT_STATUSES = [
32
+ "idle",
33
+ "pending",
34
+ "quoting",
35
+ "quoted",
36
+ "signing",
37
+ "awaiting_deposit",
38
+ "executing",
39
+ "bridging",
40
+ "settling",
41
+ "completed",
42
+ "refunded",
43
+ "failed",
44
+ "expired",
45
+ ];
46
+ function isIntentStatus(value) {
47
+ return typeof value === "string" && exports.INTENT_STATUSES.includes(value);
48
+ }
49
+ /**
50
+ * The `substatus` the worker puts on a `failed` it wrote knowing nothing
51
+ * moved. The one list of its sources is docs/contracts/xochi-intent-api.md,
52
+ * "The worker's `not_executed` marker"; this mirrors it. Writers:
53
+ * 1. an intent read (`GET /api/intent/{id}`, the status poll) of an unsigned
54
+ * market `quoted` row (never a Tron deposit route or a limit order; never
55
+ * claimed, or every claim undone) past its signed deadline +
56
+ * `QUOTED_EXPIRY_GRACE_SECS`;
57
+ * 2. the quote sweep's finish of a touched `quoted` row past its 30 s quote
58
+ * expiry + 60 s;
59
+ * 3. the resend budget's finish after the solver's not-accepted refusals;
60
+ * 4. a not-accepted refusal finished because its un-claim's write failed
61
+ * (`NOT_ACCEPTED_FAULT_FINISH_ERROR`);
62
+ * 5. an execute refused because no solver is configured;
63
+ * 6. a solver refusal of the execute whose body says
64
+ * `details.funds_moved === false` (refused before this request's claim and
65
+ * before any pull).
66
+ * Served on every intent read, the history list, the stream frame of that
67
+ * transition, the execute 502 of writers 3-6, and echoed from the row by the
68
+ * execute's lost-race 502 and in-doubt 200. Any other solver-reported
69
+ * `failed` (which may follow an origin pull) never carries it, and neither
70
+ * does a `failed` nothing vouches for, such as a solver refusal without that
71
+ * body. A client that sent an execute may offer Retry on a `failed` with this
72
+ * marker; any other `failed` may follow moved funds (`@xochi/client` holds it
73
+ * as "may have moved"; the app and widget do not read the marker yet,
74
+ * xochi#691).
75
+ *
76
+ * Writers 1-4 and 6, and the sweep's deletion of an untouched `quoted` row
77
+ * (which a client holding the intent as not sent reads as nothing moved),
78
+ * rest on one premise: the worker is the only caller of the solver's execute
79
+ * for its quotes, which the solver enforces (its execute refuses a caller
80
+ * other than the one the quote was issued to, Riddler#1346).
81
+ *
82
+ * Mirrors `NOT_EXECUTED_SUBSTATUS` in xochi's `@xochi/shared` `intents.ts`
83
+ * verbatim (the doc path above is in xochi). In this package: README "Fund
84
+ * safety" (Retry only on this marker, or on a 404 while "not sent yet" past
85
+ * the Worker's finish).
86
+ */
87
+ exports.NOT_EXECUTED_SUBSTATUS = "not_executed";
88
+ /** Status transitions for the market order intent state machine */
89
+ exports.INTENT_STATUS_TRANSITIONS = {
90
+ idle: ["quoting", "pending"],
91
+ pending: ["quoting", "failed"],
92
+ quoting: ["quoted", "failed", "idle", "quoting"],
93
+ quoted: [
94
+ "signing",
95
+ "awaiting_deposit",
96
+ "executing",
97
+ "completed",
98
+ "expired",
99
+ "quoting",
100
+ "failed",
101
+ "idle",
102
+ ],
103
+ signing: ["executing", "completed", "failed", "quoted"],
104
+ // Deposit route: from waiting-for-deposit the solver settles (in-flight ->
105
+ // terminal), or the user resets / it expires.
106
+ awaiting_deposit: [
107
+ "executing",
108
+ "bridging",
109
+ "settling",
110
+ "completed",
111
+ "refunded",
112
+ "failed",
113
+ "expired",
114
+ "quoting",
115
+ "idle",
116
+ ],
117
+ executing: ["bridging", "settling", "completed", "refunded", "failed"],
118
+ bridging: ["settling", "completed", "refunded", "failed"],
119
+ settling: ["completed", "refunded", "failed"],
120
+ completed: ["idle", "quoting"],
121
+ // A refund is terminal + fund-safe; reset or re-quote from it like completed.
122
+ refunded: ["idle", "quoting"],
123
+ failed: ["idle", "quoting"],
124
+ expired: ["quoting", "idle"],
125
+ };
126
+ /** Check if a status transition is valid */
127
+ function canTransitionTo(from, to) {
128
+ return exports.INTENT_STATUS_TRANSITIONS[from]?.includes(to) ?? false;
129
+ }
130
+ /** Get human-readable status label */
131
+ function getStatusLabel(status) {
132
+ const labels = {
133
+ idle: "Ready",
134
+ pending: "Pending",
135
+ quoting: "Getting quote...",
136
+ quoted: "Quote ready",
137
+ signing: "Awaiting signature...",
138
+ awaiting_deposit: "Waiting for your deposit...",
139
+ executing: "Submitting...",
140
+ bridging: "Bridging...",
141
+ settling: "Settling...",
142
+ completed: "Complete",
143
+ refunded: "Refunded",
144
+ failed: "Failed",
145
+ expired: "Quote expired",
146
+ };
147
+ return labels[status];
148
+ }
149
+ /**
150
+ * Plain-language copy for a deposit refund. Riddler returns a machine-readable
151
+ * `refundReason` code on a `refunded` status; map it to something a
152
+ * non-technical user understands. Every case reassures that funds are safe.
153
+ * Unknown codes fall back to the generic line rather than leaking the raw code.
154
+ */
155
+ function getRefundReasonLabel(code) {
156
+ switch (code) {
157
+ case "quote_expired":
158
+ return "The quote expired before your deposit arrived, so it was sent back.";
159
+ case "wrong_token":
160
+ return "A different token arrived than the quote was for, so it was sent back.";
161
+ case "deposit_shortfall":
162
+ return "The deposit was smaller than the quote, so it was sent back.";
163
+ case "duplicate_deposit":
164
+ return "This looked like a repeat of a deposit already handled, so it was sent back.";
165
+ default:
166
+ return "Your deposit was sent back to you.";
167
+ }
168
+ }
169
+ /** All valid limit order statuses */
170
+ exports.LIMIT_ORDER_STATUSES = [
171
+ "idle",
172
+ "limit_quoting",
173
+ "limit_quoted",
174
+ "signing",
175
+ "waiting",
176
+ "triggered",
177
+ "executing",
178
+ "completed",
179
+ "cancelled",
180
+ "expired",
181
+ ];
182
+ function isLimitOrderStatus(value) {
183
+ return typeof value === "string" && exports.LIMIT_ORDER_STATUSES.includes(value);
184
+ }
185
+ /** Status transitions for limit order state machine */
186
+ exports.LIMIT_ORDER_STATUS_TRANSITIONS = {
187
+ idle: ["limit_quoting"],
188
+ limit_quoting: ["limit_quoted", "expired"],
189
+ limit_quoted: ["signing", "expired", "limit_quoting"],
190
+ signing: ["waiting", "limit_quoted"],
191
+ waiting: ["triggered", "cancelled", "expired"],
192
+ triggered: ["executing", "cancelled"],
193
+ executing: ["completed", "cancelled"],
194
+ completed: ["idle"],
195
+ cancelled: ["idle"],
196
+ expired: ["idle", "limit_quoting"],
197
+ };
198
+ /** Check if a limit order status transition is valid */
199
+ function canLimitOrderTransitionTo(from, to) {
200
+ return exports.LIMIT_ORDER_STATUS_TRANSITIONS[from]?.includes(to) ?? false;
201
+ }
202
+ /** Get human-readable status label for limit orders */
203
+ function getLimitOrderStatusLabel(status) {
204
+ const labels = {
205
+ idle: "Ready",
206
+ limit_quoting: "Getting quote...",
207
+ limit_quoted: "Quote ready",
208
+ signing: "Awaiting signature...",
209
+ waiting: "Waiting for price...",
210
+ triggered: "Price reached",
211
+ executing: "Executing...",
212
+ completed: "Filled",
213
+ cancelled: "Cancelled",
214
+ expired: "Expired",
215
+ };
216
+ return labels[status];
217
+ }
218
+ /** Expiry presets for limit orders (in milliseconds) */
219
+ exports.LIMIT_ORDER_EXPIRY_PRESETS = {
220
+ "1h": 60 * 60 * 1000,
221
+ "24h": 24 * 60 * 60 * 1000,
222
+ "7d": 7 * 24 * 60 * 60 * 1000,
223
+ "30d": 30 * 24 * 60 * 60 * 1000,
224
+ };
225
+ function isDestinationType(value) {
226
+ return value === "chain" || value === "aztec" || value === "stealth";
227
+ }