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