@zkp2p/cash 0.1.3 → 0.1.4
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/AGENTS.md +89 -26
- package/README.md +66 -24
- package/dist/chunk-P3KYZ2FX.js +373 -0
- package/dist/{createCashClient-iHuGgjH_.d.cts → createCashClient-BbkfxILl.d.cts} +37 -8
- package/dist/{createCashClient-iHuGgjH_.d.ts → createCashClient-BbkfxILl.d.ts} +37 -8
- package/dist/index.cjs +1081 -245
- package/dist/index.d.cts +1554 -74
- package/dist/index.d.ts +1554 -74
- package/dist/index.js +868 -239
- package/dist/react.cjs +239 -59
- package/dist/react.d.cts +6 -4
- package/dist/react.d.ts +6 -4
- package/dist/react.js +236 -59
- package/dist/tools.cjs +36 -36
- package/dist/tools.d.cts +282 -3
- package/dist/tools.d.ts +282 -3
- package/dist/tools.js +36 -36
- package/docs/lifecycle-and-recovery.md +278 -0
- package/examples/agent-tool-use.ts +122 -0
- package/examples/node-cashout.ts +79 -0
- package/llms.txt +23 -5
- package/package.json +51 -21
- package/skills/peer-cash-integration/SKILL.md +79 -17
- package/dist/chunk-FKVPZVFH.js +0 -188
- package/dist/chunk-FKVPZVFH.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/react.cjs.map +0 -1
- package/dist/react.js.map +0 -1
- package/dist/tools.cjs.map +0 -1
- package/dist/tools.js.map +0 -1
package/dist/react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCashError, CASH_ORDER_POLL_INTERVAL_MS } from './chunk-
|
|
1
|
+
import { isCashError, CASH_ORDER_POLL_INTERVAL_MS } from './chunk-P3KYZ2FX.js';
|
|
2
2
|
import { useState, useRef, useCallback, useEffect, useMemo } from 'react';
|
|
3
3
|
|
|
4
4
|
function useEstimate({
|
|
@@ -13,14 +13,32 @@ function useEstimate({
|
|
|
13
13
|
const [isLoading, setIsLoading] = useState(false);
|
|
14
14
|
const [error, setError] = useState(null);
|
|
15
15
|
const mountedRef = useRef(true);
|
|
16
|
+
const latestRequestRef = useRef(0);
|
|
16
17
|
const timerRef = useRef(null);
|
|
18
|
+
const estimateIdentityRef = useRef(null);
|
|
19
|
+
const loadingIdentityRef = useRef(null);
|
|
20
|
+
const errorIdentityRef = useRef(null);
|
|
17
21
|
const refresh = useCallback(async () => {
|
|
22
|
+
const requestId = ++latestRequestRef.current;
|
|
23
|
+
const isCurrent = () => mountedRef.current && requestId === latestRequestRef.current;
|
|
18
24
|
if (!client || !currency || !amount || amount <= 0n) {
|
|
19
|
-
if (
|
|
25
|
+
if (isCurrent()) {
|
|
26
|
+
estimateIdentityRef.current = null;
|
|
27
|
+
loadingIdentityRef.current = null;
|
|
28
|
+
errorIdentityRef.current = null;
|
|
29
|
+
setEstimate(null);
|
|
30
|
+
setIsLoading(false);
|
|
31
|
+
setError(null);
|
|
32
|
+
}
|
|
20
33
|
return;
|
|
21
34
|
}
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
const identity = { client, amount, currency, platform, source };
|
|
36
|
+
if (isCurrent()) {
|
|
37
|
+
loadingIdentityRef.current = identity;
|
|
38
|
+
errorIdentityRef.current = null;
|
|
39
|
+
setIsLoading(true);
|
|
40
|
+
setError(null);
|
|
41
|
+
}
|
|
24
42
|
try {
|
|
25
43
|
const result = await client.estimate({
|
|
26
44
|
amount,
|
|
@@ -28,17 +46,31 @@ function useEstimate({
|
|
|
28
46
|
...platform ? { platform } : {},
|
|
29
47
|
...source ? { source } : {}
|
|
30
48
|
});
|
|
31
|
-
if (
|
|
49
|
+
if (isCurrent()) {
|
|
50
|
+
estimateIdentityRef.current = identity;
|
|
51
|
+
setEstimate(result);
|
|
52
|
+
}
|
|
32
53
|
} catch (err) {
|
|
33
54
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
34
|
-
if (
|
|
55
|
+
if (isCurrent()) {
|
|
56
|
+
estimateIdentityRef.current = null;
|
|
57
|
+
errorIdentityRef.current = identity;
|
|
35
58
|
setEstimate(null);
|
|
36
59
|
setError(e);
|
|
37
60
|
}
|
|
38
61
|
} finally {
|
|
39
|
-
if (
|
|
62
|
+
if (isCurrent()) setIsLoading(false);
|
|
40
63
|
}
|
|
41
64
|
}, [client, currency, amount, platform, source]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
latestRequestRef.current += 1;
|
|
67
|
+
estimateIdentityRef.current = null;
|
|
68
|
+
loadingIdentityRef.current = null;
|
|
69
|
+
errorIdentityRef.current = null;
|
|
70
|
+
setEstimate(null);
|
|
71
|
+
setIsLoading(false);
|
|
72
|
+
setError(null);
|
|
73
|
+
}, [client, amount, currency, platform, source]);
|
|
42
74
|
useEffect(() => {
|
|
43
75
|
mountedRef.current = true;
|
|
44
76
|
void refresh();
|
|
@@ -47,10 +79,38 @@ function useEstimate({
|
|
|
47
79
|
}
|
|
48
80
|
return () => {
|
|
49
81
|
mountedRef.current = false;
|
|
82
|
+
latestRequestRef.current += 1;
|
|
50
83
|
if (timerRef.current) clearInterval(timerRef.current);
|
|
51
84
|
};
|
|
52
85
|
}, [refresh, refreshIntervalMs]);
|
|
53
|
-
|
|
86
|
+
const matchesCurrentIdentity = (identity) => identity?.client === client && identity.amount === amount && identity.currency === currency && identity.platform === platform && identity.source === source;
|
|
87
|
+
return {
|
|
88
|
+
estimate: matchesCurrentIdentity(estimateIdentityRef.current) ? estimate : null,
|
|
89
|
+
isLoading: matchesCurrentIdentity(loadingIdentityRef.current) ? isLoading : false,
|
|
90
|
+
error: matchesCurrentIdentity(errorIdentityRef.current) ? error : null,
|
|
91
|
+
refresh
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function useMountedRef() {
|
|
95
|
+
const mounted = useRef(true);
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
mounted.current = true;
|
|
98
|
+
return () => {
|
|
99
|
+
mounted.current = false;
|
|
100
|
+
};
|
|
101
|
+
}, []);
|
|
102
|
+
return mounted;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/react/useCashout.ts
|
|
106
|
+
function matchesIdentity(identity, client, signer, sourceSigner) {
|
|
107
|
+
return identity?.client === client && identity.signer === signer && identity.sourceSigner === sourceSigner;
|
|
108
|
+
}
|
|
109
|
+
function notifyObserver(observer, value) {
|
|
110
|
+
try {
|
|
111
|
+
observer?.(value);
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
54
114
|
}
|
|
55
115
|
function useCashout({
|
|
56
116
|
client,
|
|
@@ -61,16 +121,35 @@ function useCashout({
|
|
|
61
121
|
onError
|
|
62
122
|
}) {
|
|
63
123
|
const [pending, setPending] = useState(null);
|
|
124
|
+
const pendingRef = useRef(null);
|
|
64
125
|
const [result, setResult] = useState(null);
|
|
65
126
|
const [error, setError] = useState(null);
|
|
127
|
+
const resultIdentityRef = useRef(null);
|
|
128
|
+
const errorIdentityRef = useRef(null);
|
|
129
|
+
const mounted = useMountedRef();
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
pendingRef.current = null;
|
|
132
|
+
resultIdentityRef.current = null;
|
|
133
|
+
errorIdentityRef.current = null;
|
|
134
|
+
setPending(null);
|
|
135
|
+
setResult(null);
|
|
136
|
+
setError(null);
|
|
137
|
+
}, [client, signer, sourceSigner]);
|
|
66
138
|
const cashout = useCallback(
|
|
67
139
|
async (input) => {
|
|
140
|
+
const identity = { client, signer, sourceSigner };
|
|
68
141
|
if (!client || !signer) {
|
|
69
142
|
const err = new Error("Cash client or signer is not ready");
|
|
70
|
-
|
|
71
|
-
|
|
143
|
+
if (mounted.current) {
|
|
144
|
+
errorIdentityRef.current = identity;
|
|
145
|
+
setError(err);
|
|
146
|
+
}
|
|
147
|
+
notifyObserver(onError, err);
|
|
72
148
|
return null;
|
|
73
149
|
}
|
|
150
|
+
if (matchesIdentity(pendingRef.current, client, signer, sourceSigner)) return null;
|
|
151
|
+
const active = { ...identity, kind: "cashout" };
|
|
152
|
+
pendingRef.current = active;
|
|
74
153
|
setPending("cashout");
|
|
75
154
|
setError(null);
|
|
76
155
|
setResult(null);
|
|
@@ -80,28 +159,44 @@ function useCashout({
|
|
|
80
159
|
...sourceSigner ? { sourceSigner } : {},
|
|
81
160
|
...onSourceProgress ? { onSourceProgress } : {}
|
|
82
161
|
});
|
|
83
|
-
|
|
84
|
-
|
|
162
|
+
if (mounted.current && pendingRef.current === active) {
|
|
163
|
+
resultIdentityRef.current = identity;
|
|
164
|
+
setResult(cashoutResult);
|
|
165
|
+
}
|
|
166
|
+
notifyObserver(onCashout, cashoutResult);
|
|
85
167
|
return cashoutResult;
|
|
86
168
|
} catch (err) {
|
|
87
169
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
88
|
-
|
|
89
|
-
|
|
170
|
+
if (mounted.current && pendingRef.current === active) {
|
|
171
|
+
errorIdentityRef.current = identity;
|
|
172
|
+
setError(e);
|
|
173
|
+
}
|
|
174
|
+
notifyObserver(onError, e);
|
|
90
175
|
return null;
|
|
91
176
|
} finally {
|
|
92
|
-
|
|
177
|
+
if (mounted.current && pendingRef.current === active) {
|
|
178
|
+
pendingRef.current = null;
|
|
179
|
+
setPending(null);
|
|
180
|
+
}
|
|
93
181
|
}
|
|
94
182
|
},
|
|
95
183
|
[client, signer, sourceSigner, onSourceProgress, onCashout, onError]
|
|
96
184
|
);
|
|
97
185
|
const withdraw = useCallback(
|
|
98
186
|
async (depositId, amount) => {
|
|
187
|
+
const identity = { client, signer, sourceSigner };
|
|
99
188
|
if (!client || !signer) {
|
|
100
189
|
const err = new Error("Cash client or signer is not ready");
|
|
101
|
-
|
|
102
|
-
|
|
190
|
+
if (mounted.current) {
|
|
191
|
+
errorIdentityRef.current = identity;
|
|
192
|
+
setError(err);
|
|
193
|
+
}
|
|
194
|
+
notifyObserver(onError, err);
|
|
103
195
|
return null;
|
|
104
196
|
}
|
|
197
|
+
if (matchesIdentity(pendingRef.current, client, signer, sourceSigner)) return null;
|
|
198
|
+
const active = { ...identity, kind: "withdraw" };
|
|
199
|
+
pendingRef.current = active;
|
|
105
200
|
setPending("withdraw");
|
|
106
201
|
setError(null);
|
|
107
202
|
try {
|
|
@@ -111,41 +206,70 @@ function useCashout({
|
|
|
111
206
|
});
|
|
112
207
|
} catch (err) {
|
|
113
208
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
114
|
-
|
|
115
|
-
|
|
209
|
+
if (mounted.current && pendingRef.current === active) {
|
|
210
|
+
errorIdentityRef.current = identity;
|
|
211
|
+
setError(e);
|
|
212
|
+
}
|
|
213
|
+
notifyObserver(onError, e);
|
|
116
214
|
return null;
|
|
117
215
|
} finally {
|
|
118
|
-
|
|
216
|
+
if (mounted.current && pendingRef.current === active) {
|
|
217
|
+
pendingRef.current = null;
|
|
218
|
+
setPending(null);
|
|
219
|
+
}
|
|
119
220
|
}
|
|
120
221
|
},
|
|
121
|
-
[client, signer, onError]
|
|
222
|
+
[client, signer, sourceSigner, onError]
|
|
122
223
|
);
|
|
123
224
|
const topUp = useCallback(
|
|
124
225
|
async (depositId, amount) => {
|
|
226
|
+
const identity = { client, signer, sourceSigner };
|
|
125
227
|
if (!client || !signer) {
|
|
126
228
|
const err = new Error("Cash client or signer is not ready");
|
|
127
|
-
|
|
128
|
-
|
|
229
|
+
if (mounted.current) {
|
|
230
|
+
errorIdentityRef.current = identity;
|
|
231
|
+
setError(err);
|
|
232
|
+
}
|
|
233
|
+
notifyObserver(onError, err);
|
|
129
234
|
return null;
|
|
130
235
|
}
|
|
236
|
+
if (matchesIdentity(pendingRef.current, client, signer, sourceSigner)) return null;
|
|
237
|
+
const active = { ...identity, kind: "topUp" };
|
|
238
|
+
pendingRef.current = active;
|
|
131
239
|
setPending("topUp");
|
|
132
240
|
setError(null);
|
|
133
241
|
try {
|
|
134
242
|
return await client.topUp(depositId, amount, { signer });
|
|
135
243
|
} catch (err) {
|
|
136
244
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
137
|
-
|
|
138
|
-
|
|
245
|
+
if (mounted.current && pendingRef.current === active) {
|
|
246
|
+
errorIdentityRef.current = identity;
|
|
247
|
+
setError(e);
|
|
248
|
+
}
|
|
249
|
+
notifyObserver(onError, e);
|
|
139
250
|
return null;
|
|
140
251
|
} finally {
|
|
141
|
-
|
|
252
|
+
if (mounted.current && pendingRef.current === active) {
|
|
253
|
+
pendingRef.current = null;
|
|
254
|
+
setPending(null);
|
|
255
|
+
}
|
|
142
256
|
}
|
|
143
257
|
},
|
|
144
|
-
[client, signer, onError]
|
|
258
|
+
[client, signer, sourceSigner, onError]
|
|
145
259
|
);
|
|
260
|
+
const visiblePending = matchesIdentity(pendingRef.current, client, signer, sourceSigner) ? pending : null;
|
|
261
|
+
const visibleResult = matchesIdentity(resultIdentityRef.current, client, signer, sourceSigner) ? result : null;
|
|
262
|
+
const visibleError = matchesIdentity(errorIdentityRef.current, client, signer, sourceSigner) ? error : null;
|
|
146
263
|
return useMemo(
|
|
147
|
-
() => ({
|
|
148
|
-
|
|
264
|
+
() => ({
|
|
265
|
+
cashout,
|
|
266
|
+
topUp,
|
|
267
|
+
withdraw,
|
|
268
|
+
pending: visiblePending,
|
|
269
|
+
result: visibleResult,
|
|
270
|
+
error: visibleError
|
|
271
|
+
}),
|
|
272
|
+
[cashout, topUp, withdraw, visiblePending, visibleResult, visibleError]
|
|
149
273
|
);
|
|
150
274
|
}
|
|
151
275
|
function usePoll(enabled, intervalMs, tick) {
|
|
@@ -166,16 +290,6 @@ function usePoll(enabled, intervalMs, tick) {
|
|
|
166
290
|
};
|
|
167
291
|
}, [enabled, intervalMs, tick]);
|
|
168
292
|
}
|
|
169
|
-
function useMountedRef() {
|
|
170
|
-
const mounted = useRef(true);
|
|
171
|
-
useEffect(() => {
|
|
172
|
-
mounted.current = true;
|
|
173
|
-
return () => {
|
|
174
|
-
mounted.current = false;
|
|
175
|
-
};
|
|
176
|
-
}, []);
|
|
177
|
-
return mounted;
|
|
178
|
-
}
|
|
179
293
|
|
|
180
294
|
// src/react/useOrder.ts
|
|
181
295
|
function useOrder({
|
|
@@ -188,27 +302,52 @@ function useOrder({
|
|
|
188
302
|
const [isLoading, setIsLoading] = useState(false);
|
|
189
303
|
const [error, setError] = useState(null);
|
|
190
304
|
const mounted = useMountedRef();
|
|
305
|
+
const latestRequest = useRef(0);
|
|
306
|
+
const orderIdentity = useRef(null);
|
|
307
|
+
const loadingIdentity = useRef(null);
|
|
308
|
+
const errorIdentity = useRef(null);
|
|
309
|
+
useEffect(() => {
|
|
310
|
+
latestRequest.current += 1;
|
|
311
|
+
orderIdentity.current = null;
|
|
312
|
+
loadingIdentity.current = null;
|
|
313
|
+
errorIdentity.current = null;
|
|
314
|
+
setOrder(null);
|
|
315
|
+
setIsLoading(false);
|
|
316
|
+
setError(null);
|
|
317
|
+
}, [client, depositId]);
|
|
191
318
|
const fetchOrder = useCallback(
|
|
192
319
|
async (isActive = () => true) => {
|
|
193
320
|
if (!client || !depositId) return null;
|
|
194
|
-
|
|
195
|
-
|
|
321
|
+
const requestId = ++latestRequest.current;
|
|
322
|
+
const identity = { client, depositId };
|
|
323
|
+
const isCurrent = () => mounted.current && isActive() && requestId === latestRequest.current;
|
|
324
|
+
if (isCurrent()) {
|
|
325
|
+
loadingIdentity.current = identity;
|
|
326
|
+
errorIdentity.current = null;
|
|
327
|
+
setIsLoading(true);
|
|
328
|
+
setError(null);
|
|
329
|
+
}
|
|
196
330
|
try {
|
|
197
331
|
const derived = await client.order(depositId);
|
|
198
|
-
if (
|
|
332
|
+
if (!isCurrent()) return null;
|
|
333
|
+
orderIdentity.current = identity;
|
|
334
|
+
setOrder(derived);
|
|
199
335
|
return derived;
|
|
200
336
|
} catch (err) {
|
|
201
337
|
if (isCashError(err) && err.code === "ORDER_NOT_FOUND") {
|
|
202
338
|
return null;
|
|
203
339
|
}
|
|
204
340
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
205
|
-
if (
|
|
341
|
+
if (isCurrent()) {
|
|
342
|
+
errorIdentity.current = identity;
|
|
343
|
+
setError(e);
|
|
344
|
+
}
|
|
206
345
|
return null;
|
|
207
346
|
} finally {
|
|
208
|
-
if (
|
|
347
|
+
if (isCurrent()) setIsLoading(false);
|
|
209
348
|
}
|
|
210
349
|
},
|
|
211
|
-
[client, depositId]
|
|
350
|
+
[client, depositId, mounted]
|
|
212
351
|
);
|
|
213
352
|
usePoll(
|
|
214
353
|
Boolean(client && depositId && !paused),
|
|
@@ -222,7 +361,13 @@ function useOrder({
|
|
|
222
361
|
)
|
|
223
362
|
);
|
|
224
363
|
const refresh = useCallback(() => fetchOrder(() => mounted.current), [fetchOrder, mounted]);
|
|
225
|
-
|
|
364
|
+
const matchesCurrentIdentity = (identity) => identity?.client === client && identity.depositId === depositId;
|
|
365
|
+
return {
|
|
366
|
+
order: matchesCurrentIdentity(orderIdentity.current) ? order : null,
|
|
367
|
+
isLoading: matchesCurrentIdentity(loadingIdentity.current) ? isLoading : false,
|
|
368
|
+
error: matchesCurrentIdentity(errorIdentity.current) ? error : null,
|
|
369
|
+
refresh
|
|
370
|
+
};
|
|
226
371
|
}
|
|
227
372
|
function useOrders({
|
|
228
373
|
client,
|
|
@@ -235,42 +380,74 @@ function useOrders({
|
|
|
235
380
|
const [isLoading, setIsLoading] = useState(false);
|
|
236
381
|
const [error, setError] = useState(null);
|
|
237
382
|
const mounted = useMountedRef();
|
|
383
|
+
const latestRequest = useRef(0);
|
|
384
|
+
const ordersIdentity = useRef(null);
|
|
385
|
+
const loadingIdentity = useRef(null);
|
|
386
|
+
const errorIdentity = useRef(null);
|
|
387
|
+
useEffect(() => {
|
|
388
|
+
latestRequest.current += 1;
|
|
389
|
+
ordersIdentity.current = null;
|
|
390
|
+
loadingIdentity.current = null;
|
|
391
|
+
errorIdentity.current = null;
|
|
392
|
+
setOrders([]);
|
|
393
|
+
setIsLoading(false);
|
|
394
|
+
setError(null);
|
|
395
|
+
}, [client, owner, limit]);
|
|
238
396
|
const fetchOrders = useCallback(
|
|
239
397
|
async (isActive = () => true) => {
|
|
240
398
|
if (!client || !owner) return [];
|
|
241
|
-
|
|
242
|
-
|
|
399
|
+
const requestId = ++latestRequest.current;
|
|
400
|
+
const identity = { client, owner, limit };
|
|
401
|
+
const isCurrent = () => mounted.current && isActive() && requestId === latestRequest.current;
|
|
402
|
+
if (isCurrent()) {
|
|
403
|
+
loadingIdentity.current = identity;
|
|
404
|
+
errorIdentity.current = null;
|
|
405
|
+
setIsLoading(true);
|
|
406
|
+
setError(null);
|
|
407
|
+
}
|
|
243
408
|
try {
|
|
244
409
|
const derived = await client.orders(owner, { limit });
|
|
245
|
-
if (
|
|
410
|
+
if (!isCurrent()) return [];
|
|
411
|
+
ordersIdentity.current = identity;
|
|
412
|
+
setOrders(derived);
|
|
246
413
|
return derived;
|
|
247
414
|
} catch (err) {
|
|
248
415
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
249
|
-
if (
|
|
416
|
+
if (isCurrent()) {
|
|
417
|
+
errorIdentity.current = identity;
|
|
418
|
+
setError(e);
|
|
419
|
+
}
|
|
250
420
|
return [];
|
|
251
421
|
} finally {
|
|
252
|
-
if (
|
|
422
|
+
if (isCurrent()) setIsLoading(false);
|
|
253
423
|
}
|
|
254
424
|
},
|
|
255
|
-
[client, owner, limit]
|
|
425
|
+
[client, owner, limit, mounted]
|
|
256
426
|
);
|
|
257
427
|
usePoll(
|
|
258
428
|
Boolean(client && owner && !paused),
|
|
259
429
|
pollIntervalMs,
|
|
260
430
|
useCallback(
|
|
261
431
|
async (isActive) => {
|
|
262
|
-
|
|
263
|
-
return
|
|
432
|
+
await fetchOrders(isActive);
|
|
433
|
+
return true;
|
|
264
434
|
},
|
|
265
435
|
[fetchOrders]
|
|
266
436
|
)
|
|
267
437
|
);
|
|
268
438
|
const refresh = useCallback(() => fetchOrders(() => mounted.current), [fetchOrders, mounted]);
|
|
269
|
-
const
|
|
270
|
-
const
|
|
271
|
-
|
|
439
|
+
const matchesCurrentIdentity = (identity) => identity?.client === client && identity.owner === owner && identity.limit === limit;
|
|
440
|
+
const visibleOrders = matchesCurrentIdentity(ordersIdentity.current) ? orders : [];
|
|
441
|
+
const inFlightCount = visibleOrders.filter((o) => o.isInFlight).length;
|
|
442
|
+
const totalCashedOut = visibleOrders.reduce((sum, o) => sum + o.filledAmount, 0n);
|
|
443
|
+
return {
|
|
444
|
+
orders: visibleOrders,
|
|
445
|
+
inFlightCount,
|
|
446
|
+
totalCashedOut,
|
|
447
|
+
isLoading: matchesCurrentIdentity(loadingIdentity.current) ? isLoading : false,
|
|
448
|
+
error: matchesCurrentIdentity(errorIdentity.current) ? error : null,
|
|
449
|
+
refresh
|
|
450
|
+
};
|
|
272
451
|
}
|
|
273
452
|
|
|
274
453
|
export { useCashout, useEstimate, useOrder, useOrders };
|
|
275
|
-
//# sourceMappingURL=react.js.map
|
|
276
|
-
//# sourceMappingURL=react.js.map
|
package/dist/tools.cjs
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// package.json
|
|
4
|
+
var package_default = {
|
|
5
|
+
version: "0.1.4"};
|
|
6
|
+
|
|
3
7
|
// src/tools/index.ts
|
|
4
8
|
var bigintString = {
|
|
5
9
|
type: "string",
|
|
6
|
-
pattern: "^[0-9]
|
|
10
|
+
pattern: "^0*[1-9][0-9]*$",
|
|
7
11
|
description: "Base units as a decimal string. For the default path this is USDC 6 decimals; with source it is source-token base units."
|
|
8
12
|
};
|
|
9
13
|
var depositId = {
|
|
10
14
|
type: "string",
|
|
15
|
+
pattern: "^0x[0-9a-fA-F]{40}_[0-9]+$",
|
|
11
16
|
description: "Composite deposit id (escrow_onchainId) returned by cash_cashout - the resume key"
|
|
12
17
|
};
|
|
13
|
-
var
|
|
18
|
+
var address = {
|
|
19
|
+
type: "string",
|
|
20
|
+
pattern: "^0x[0-9a-fA-F]{40}$"
|
|
21
|
+
};
|
|
22
|
+
var chainId = {
|
|
23
|
+
type: "integer",
|
|
24
|
+
minimum: 1,
|
|
25
|
+
maximum: Number.MAX_SAFE_INTEGER
|
|
26
|
+
};
|
|
27
|
+
var builtInCashTools = [
|
|
14
28
|
{
|
|
15
29
|
name: "cash_capabilities",
|
|
16
30
|
description: "Discover what Peer Cash can do: payout platforms, oracle-priced currencies per platform, Base USDC destination, default Base USDC source, payee handle hints, and amount bounds. Set includeRelaySources=true to fetch live Relay-supported EVM source chains/tokens through the Relay SDK.",
|
|
@@ -27,23 +41,23 @@ var cashTools = [
|
|
|
27
41
|
},
|
|
28
42
|
{
|
|
29
43
|
name: "cash_source_quote",
|
|
30
|
-
description: "Quote any Relay-supported EVM source asset into Base USDC through @relayprotocol/relay-sdk.
|
|
44
|
+
description: "Quote any Relay-supported EVM source asset into Base USDC through @relayprotocol/relay-sdk. A custody-capable host must submit the returned route, poll cash_source_status to success, then call Base-USDC cash_cashout with the guaranteed output amount. Never submit the route twice.",
|
|
31
45
|
inputSchema: {
|
|
32
46
|
type: "object",
|
|
33
47
|
properties: {
|
|
34
|
-
user: {
|
|
48
|
+
user: { ...address, description: "Source wallet submitting the Relay transaction." },
|
|
35
49
|
amount: bigintString,
|
|
36
50
|
source: {
|
|
37
51
|
type: "object",
|
|
38
52
|
properties: {
|
|
39
|
-
chainId: {
|
|
40
|
-
currency: {
|
|
53
|
+
chainId: { ...chainId, description: "Relay-supported EVM source chain id." },
|
|
54
|
+
currency: { ...address, description: "Source token/native address." }
|
|
41
55
|
},
|
|
42
56
|
required: ["chainId", "currency"],
|
|
43
57
|
additionalProperties: false
|
|
44
58
|
},
|
|
45
59
|
recipient: {
|
|
46
|
-
|
|
60
|
+
...address,
|
|
47
61
|
description: "Base recipient for Relay-delivered USDC. Defaults to user."
|
|
48
62
|
},
|
|
49
63
|
tradeType: {
|
|
@@ -75,14 +89,14 @@ var cashTools = [
|
|
|
75
89
|
type: "object",
|
|
76
90
|
description: "Optional Relay EVM source asset. Omit for the Base USDC default path.",
|
|
77
91
|
properties: {
|
|
78
|
-
chainId: {
|
|
79
|
-
currency: {
|
|
92
|
+
chainId: { ...chainId, description: "Relay-supported EVM source chain id." },
|
|
93
|
+
currency: { ...address, description: "Source token/native address." },
|
|
80
94
|
user: {
|
|
81
|
-
|
|
95
|
+
...address,
|
|
82
96
|
description: "Source wallet submitting the Relay transaction."
|
|
83
97
|
},
|
|
84
98
|
recipient: {
|
|
85
|
-
|
|
99
|
+
...address,
|
|
86
100
|
description: "Base recipient for Relay-delivered USDC. Defaults to user."
|
|
87
101
|
},
|
|
88
102
|
tradeType: {
|
|
@@ -100,29 +114,11 @@ var cashTools = [
|
|
|
100
114
|
},
|
|
101
115
|
{
|
|
102
116
|
name: "cash_cashout",
|
|
103
|
-
description: "Start a cash-out
|
|
117
|
+
description: "Start a Base-USDC cash-out using the custody-separated prepare path. Returns UNSIGNED transactions plus same-index steps [approve, createDeposit]; signing and ordered submission stay host-side. For another source asset, complete cash_source_quote and cash_source_status first, then pass the guaranteed Base USDC output amount here.",
|
|
104
118
|
inputSchema: {
|
|
105
119
|
type: "object",
|
|
106
120
|
properties: {
|
|
107
121
|
amount: bigintString,
|
|
108
|
-
source: {
|
|
109
|
-
type: "object",
|
|
110
|
-
description: "Optional Relay EVM source asset. Omit for the Base USDC default path.",
|
|
111
|
-
properties: {
|
|
112
|
-
chainId: { type: "number", description: "Relay-supported EVM source chain id." },
|
|
113
|
-
currency: { type: "string", description: "Source token/native address." },
|
|
114
|
-
recipient: {
|
|
115
|
-
type: "string",
|
|
116
|
-
description: "Base recipient for Relay-delivered USDC. Defaults to signer."
|
|
117
|
-
},
|
|
118
|
-
tradeType: {
|
|
119
|
-
type: "string",
|
|
120
|
-
enum: ["EXACT_INPUT", "EXACT_OUTPUT", "EXPECTED_OUTPUT"]
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
required: ["chainId", "currency"],
|
|
124
|
-
additionalProperties: false
|
|
125
|
-
},
|
|
126
122
|
receive: {
|
|
127
123
|
type: "object",
|
|
128
124
|
description: "Where the fiat should arrive",
|
|
@@ -169,12 +165,17 @@ var cashTools = [
|
|
|
169
165
|
inputSchema: {
|
|
170
166
|
type: "object",
|
|
171
167
|
properties: {
|
|
172
|
-
owner: {
|
|
168
|
+
owner: { ...address, description: "The maker wallet address (0x...)" },
|
|
173
169
|
inFlight: {
|
|
174
170
|
type: "boolean",
|
|
175
171
|
description: "Only awaiting-buyer / matched / delivering orders"
|
|
176
172
|
},
|
|
177
|
-
limit: {
|
|
173
|
+
limit: {
|
|
174
|
+
type: "integer",
|
|
175
|
+
minimum: 1,
|
|
176
|
+
maximum: 1e3,
|
|
177
|
+
description: "Max deposits to scan (default 100)"
|
|
178
|
+
}
|
|
178
179
|
},
|
|
179
180
|
required: ["owner"],
|
|
180
181
|
additionalProperties: false
|
|
@@ -186,7 +187,7 @@ var cashTools = [
|
|
|
186
187
|
inputSchema: {
|
|
187
188
|
type: "object",
|
|
188
189
|
properties: {
|
|
189
|
-
address: {
|
|
190
|
+
address: { ...address, description: "The buyer (taker) wallet address (0x...)" }
|
|
190
191
|
},
|
|
191
192
|
required: ["address"],
|
|
192
193
|
additionalProperties: false
|
|
@@ -231,14 +232,13 @@ var cashTools = [
|
|
|
231
232
|
}
|
|
232
233
|
}
|
|
233
234
|
];
|
|
235
|
+
var cashTools = [...builtInCashTools];
|
|
234
236
|
var cashToolManifest = {
|
|
235
237
|
name: "@zkp2p/cash",
|
|
236
|
-
version:
|
|
238
|
+
version: package_default.version,
|
|
237
239
|
description: "Peer Cash - offramp-only: route any Relay-supported EVM source asset to Base USDC, then cash out to fiat at the live oracle market rate (0% spread). Mutating protocol tools return unsigned transactions plus step labels with ERC-8021 peer-cash attribution.",
|
|
238
240
|
tools: cashTools
|
|
239
241
|
};
|
|
240
242
|
|
|
241
243
|
exports.cashToolManifest = cashToolManifest;
|
|
242
244
|
exports.cashTools = cashTools;
|
|
243
|
-
//# sourceMappingURL=tools.cjs.map
|
|
244
|
-
//# sourceMappingURL=tools.cjs.map
|