@zkp2p/cash 0.1.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +131 -0
- package/LICENSE +21 -0
- package/README.md +138 -0
- package/dist/chunk-4DRZRWWS.js +176 -0
- package/dist/chunk-4DRZRWWS.js.map +1 -0
- package/dist/createCashClient-DpAx9A1A.d.cts +449 -0
- package/dist/createCashClient-DpAx9A1A.d.ts +449 -0
- package/dist/index.cjs +1572 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1367 -0
- package/dist/index.d.ts +1367 -0
- package/dist/index.js +1322 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +292 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +97 -0
- package/dist/react.d.ts +97 -0
- package/dist/react.js +258 -0
- package/dist/react.js.map +1 -0
- package/dist/tools.cjs +148 -0
- package/dist/tools.cjs.map +1 -0
- package/dist/tools.d.cts +31 -0
- package/dist/tools.d.ts +31 -0
- package/dist/tools.js +145 -0
- package/dist/tools.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { Address, WalletClient, Hash, Transport } from 'viem';
|
|
2
|
+
import { IndexerIntentStatus, Zkp2pClient, IndexerIntent, CurrencyType, RuntimeEnv, PreparedTransaction } from '@zkp2p/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Name-mapping shim over the published `@zkp2p/sdk` (^0.8).
|
|
6
|
+
*
|
|
7
|
+
* The reference implementation imported these from internal SDK paths; the
|
|
8
|
+
* published package exports them under indexer-prefixed names, and one type
|
|
9
|
+
* (`CuratorPayeeDataInput`) is not exported at all - it is recovered here from
|
|
10
|
+
* the `registerPayeeDetails` method signature. Everything else in this package
|
|
11
|
+
* imports SDK types from this module so the mapping lives in exactly one place.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
type IntentStatus = IndexerIntentStatus;
|
|
15
|
+
type IntentEntity = IndexerIntent;
|
|
16
|
+
type CuratorPayeeDataInput = NonNullable<Parameters<Zkp2pClient['registerPayeeDetails']>[0]['payeeData']>[number];
|
|
17
|
+
type CreateDepositParamsArg = Parameters<Zkp2pClient['createDeposit']>[0];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Peer Cash - public domain types for the engine.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The lifecycle state of a cash-out, derived purely from on-chain-observable
|
|
25
|
+
* intent events against the user's deposit.
|
|
26
|
+
*
|
|
27
|
+
* - `awaiting-buyer` - deposit is live, no buyer has signaled yet.
|
|
28
|
+
* - `matched` - a buyer signaled an intent (`SIGNALED`); fiat not yet proven.
|
|
29
|
+
* - `delivering` - partial fill in progress (some intents fulfilled, some still signaled).
|
|
30
|
+
* - `delivered` - fiat paid + proven, escrow released (`FULFILLED`).
|
|
31
|
+
* - `returned` - buyer didn't deliver; intent pruned, deposit recoverable/recovered.
|
|
32
|
+
*/
|
|
33
|
+
type CashOrderState = 'awaiting-buyer' | 'matched' | 'delivering' | 'delivered' | 'returned';
|
|
34
|
+
/** What the caller can do next. The lifecycle is self-driving - no consumer heuristics. */
|
|
35
|
+
type CashNextAction = 'wait' | 'withdraw';
|
|
36
|
+
/**
|
|
37
|
+
* One buyer's intent against the deposit (one "fill"). The order id is the
|
|
38
|
+
* `intentHash`. Hashes are decoded to human units wherever the protocol
|
|
39
|
+
* catalogs know them; the raw values stay available for anything unknown.
|
|
40
|
+
*/
|
|
41
|
+
interface CashFill {
|
|
42
|
+
/** The order id once a buyer has signaled. */
|
|
43
|
+
intentHash: string;
|
|
44
|
+
status: IntentStatus;
|
|
45
|
+
/** Intent amount in USDC base units (6 decimals). */
|
|
46
|
+
amount: bigint;
|
|
47
|
+
/** The buyer (taker) address. */
|
|
48
|
+
buyer: string;
|
|
49
|
+
/** Decoded fiat currency code the buyer pays in, e.g. `'EUR'`. */
|
|
50
|
+
currency?: string;
|
|
51
|
+
/** Raw on-chain currency hash (bytes32), for anything the catalog can't decode. */
|
|
52
|
+
currencyHash?: string;
|
|
53
|
+
/** Fiat per USDC locked at signal time - the binding rate for THIS fill. */
|
|
54
|
+
rate?: number;
|
|
55
|
+
/** Raw locked conversion rate (1e18 precision). */
|
|
56
|
+
conversionRate?: bigint;
|
|
57
|
+
/** Fiat the buyer must send: `amount × rate`, rounded up to the cent. */
|
|
58
|
+
fiatOwed?: number;
|
|
59
|
+
/** Verified receipt - actual fiat paid, from the payment proof. */
|
|
60
|
+
fiatPaid?: number;
|
|
61
|
+
/** Verified receipt - decoded currency actually paid (may differ from `currency`). */
|
|
62
|
+
paidCurrency?: string;
|
|
63
|
+
/** Verified receipt - the platform's external payment id. */
|
|
64
|
+
paymentId?: string;
|
|
65
|
+
/** Verified receipt - unix seconds the fiat payment was made. */
|
|
66
|
+
paidAt?: number;
|
|
67
|
+
/** USDC actually released from escrow for this fill (gross, base units). */
|
|
68
|
+
releasedAmount?: bigint;
|
|
69
|
+
/** Seconds from buyer signal to proven delivery. */
|
|
70
|
+
fillLatencySeconds?: number;
|
|
71
|
+
/** Indexer reconciler flag: the intent's window has lapsed on-chain. */
|
|
72
|
+
isExpired?: boolean;
|
|
73
|
+
/** Unix seconds - when the buyer signaled (matched). */
|
|
74
|
+
signaledAt?: number;
|
|
75
|
+
/** Unix seconds - when the signaled intent expires and becomes prunable. */
|
|
76
|
+
expiresAt?: number;
|
|
77
|
+
/** Unix seconds - when fiat was proven and escrow released (delivered). */
|
|
78
|
+
fulfilledAt?: number;
|
|
79
|
+
/** Unix seconds - when the intent expired and was pruned (returned). */
|
|
80
|
+
prunedAt?: number;
|
|
81
|
+
}
|
|
82
|
+
/** Pricing state of one payout tuple - the zero-spread claim, verifiable from indexed data. */
|
|
83
|
+
interface CashPayoutPricing {
|
|
84
|
+
/** Depositor-configured spread markup in basis points (0 for every cash order). */
|
|
85
|
+
spreadBps?: number;
|
|
86
|
+
/** Oracle kind, e.g. `'oracle_chainlink'`. */
|
|
87
|
+
kind?: string;
|
|
88
|
+
/** Which source currently binds the rate: `ORACLE` | `MANAGER` | `ESCROW_FLOOR` | …. */
|
|
89
|
+
rateSource?: string;
|
|
90
|
+
/** Current oracle rate (fiat per USDC), decoded from 1e18. */
|
|
91
|
+
oracleRate?: number;
|
|
92
|
+
/** Unix seconds of the last accepted oracle snapshot. */
|
|
93
|
+
lastOracleUpdatedAt?: number;
|
|
94
|
+
/** True when the tuple is priced by an oracle at zero spread - the Peer Cash invariant. */
|
|
95
|
+
marketRate: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** One payout leg reconstructed from the chain - platform, currency, payee hash, pricing. */
|
|
98
|
+
interface CashPayoutInfo {
|
|
99
|
+
/** Decoded platform id, e.g. `'venmo'` (undefined if the catalog doesn't know the hash). */
|
|
100
|
+
platform?: string;
|
|
101
|
+
/** Raw payment method hash (bytes32). */
|
|
102
|
+
platformHash: string;
|
|
103
|
+
/** Decoded fiat currency code, e.g. `'USD'`. */
|
|
104
|
+
currency?: string;
|
|
105
|
+
/** Raw currency hash (bytes32). */
|
|
106
|
+
currencyHash?: string;
|
|
107
|
+
/** Hashed payee details (the handle itself never touches the chain). */
|
|
108
|
+
payeeHash: string;
|
|
109
|
+
/** Whether the method still accepts new intents. */
|
|
110
|
+
active: boolean;
|
|
111
|
+
pricing: CashPayoutPricing;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The full, resumable view of a cash-out order, reconstructed from the indexer
|
|
115
|
+
* by `depositId` alone - survives a closed tab, new device, or wallet reconnect.
|
|
116
|
+
*/
|
|
117
|
+
interface CashOrder {
|
|
118
|
+
/** Composite deposit id (`escrow_onchainId`) - the resume key. */
|
|
119
|
+
depositId: string;
|
|
120
|
+
state: CashOrderState;
|
|
121
|
+
/** Every buyer intent against the deposit (>1 only for partial fills). */
|
|
122
|
+
fills: CashFill[];
|
|
123
|
+
/** Deposit amount in USDC base units. */
|
|
124
|
+
totalAmount: bigint;
|
|
125
|
+
/** Sum of fulfilled (delivered) intent amounts. */
|
|
126
|
+
filledAmount: bigint;
|
|
127
|
+
/** Sum of signaled-but-not-yet-fulfilled intent amounts. */
|
|
128
|
+
pendingAmount: bigint;
|
|
129
|
+
/** Sum returned (withdrawn) to the maker. */
|
|
130
|
+
returnedAmount: bigint;
|
|
131
|
+
/** Self-driving lifecycle - what the caller can do right now. */
|
|
132
|
+
nextActions: CashNextAction[];
|
|
133
|
+
/** The primary order id (first/active intent's `intentHash`) once matched. */
|
|
134
|
+
primaryIntentHash?: string;
|
|
135
|
+
/** Unix seconds - earliest signal (first match). */
|
|
136
|
+
matchedAt?: number;
|
|
137
|
+
/** Unix seconds - latest fulfilment (delivery). */
|
|
138
|
+
deliveredAt?: number;
|
|
139
|
+
/** Unix seconds - when the deposit last changed on-chain. */
|
|
140
|
+
updatedAt?: number;
|
|
141
|
+
/** Total number of buyer intents against the deposit (from the indexer aggregate). */
|
|
142
|
+
intentCount?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Payout legs reconstructed from the chain (platform, currency, payee hash,
|
|
145
|
+
* pricing proof). Present on `order()`; absent on `orders()` list rows.
|
|
146
|
+
*/
|
|
147
|
+
payouts?: CashPayoutInfo[];
|
|
148
|
+
/** Deposit quality signal takers see (basis points, 0–10000; new deposits start at 10000). */
|
|
149
|
+
successRateBps?: number;
|
|
150
|
+
/** True while the order still needs the user's attention / a buyer to act. */
|
|
151
|
+
isInFlight: boolean;
|
|
152
|
+
/** Whether the deposit has been withdrawn on-chain (terminal return). */
|
|
153
|
+
withdrawn?: boolean;
|
|
154
|
+
/** One honest sentence from live data - never a fake countdown. */
|
|
155
|
+
explain(): string;
|
|
156
|
+
}
|
|
157
|
+
/** A buyer's protocol track record, aggregated from their full intent history. */
|
|
158
|
+
interface CashBuyerProfile {
|
|
159
|
+
address: string;
|
|
160
|
+
/** Lifetime intents this buyer has signaled (all statuses). */
|
|
161
|
+
totalIntents: number;
|
|
162
|
+
/** Intents completed: fiat paid, proven, escrow released. */
|
|
163
|
+
fulfilled: number;
|
|
164
|
+
/** Intents that expired unpaid and were pruned. */
|
|
165
|
+
pruned: number;
|
|
166
|
+
/** Intents currently open. */
|
|
167
|
+
signaled: number;
|
|
168
|
+
/** fulfilled / (fulfilled + pruned) in basis points; undefined until they have history. */
|
|
169
|
+
successRateBps?: number;
|
|
170
|
+
/** Unix seconds of the buyer's first and latest signal. */
|
|
171
|
+
firstSeenAt?: number;
|
|
172
|
+
lastSeenAt?: number;
|
|
173
|
+
}
|
|
174
|
+
/** A single payout leg of a cash-out (one platform + currency + payee). */
|
|
175
|
+
interface CashPayout {
|
|
176
|
+
/** Payment platform / processor name, e.g. `'venmo'`, `'revolut'`, `'wise'`. */
|
|
177
|
+
processorName: string;
|
|
178
|
+
/** Fiat currency the user wants to receive. */
|
|
179
|
+
currency: CurrencyType;
|
|
180
|
+
/** The user's payee handle for that platform (e.g. a Venmo username, Wisetag). */
|
|
181
|
+
payeeData: CuratorPayeeDataInput;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Input to create a market-rate (0% spread) cash-out deposit.
|
|
185
|
+
*
|
|
186
|
+
* Deliberately narrow: no rate/spread knobs, no vault/DRM delegate, no
|
|
187
|
+
* retain-on-empty override - a cash-out is a one-shot order that cleans up
|
|
188
|
+
* when fully filled. The API cannot express what Peer Cash does not offer.
|
|
189
|
+
*/
|
|
190
|
+
interface CashDepositInput {
|
|
191
|
+
/** Deposit asset - Base USDC (defaults to {@link BASE_USDC_ADDRESS}). */
|
|
192
|
+
token?: Address;
|
|
193
|
+
/** Total amount to cash out, in USDC base units (6 decimals). */
|
|
194
|
+
amount: bigint;
|
|
195
|
+
/** One or more payout legs (platform + currency + payee). */
|
|
196
|
+
payouts: CashPayout[];
|
|
197
|
+
/** Per-order min/max in USDC base units. Defaults derive from {@link buildIntentAmountRange}. */
|
|
198
|
+
intentAmountRange?: {
|
|
199
|
+
min: bigint;
|
|
200
|
+
max: bigint;
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Hard floor: below one cent a deposit is dust and can never fill. */
|
|
205
|
+
declare const MIN_CASHOUT_AMOUNT = 10000n;
|
|
206
|
+
/** Recommended floor: sub-1-USDC deposits force min==max fills and starve matching. */
|
|
207
|
+
declare const RECOMMENDED_MIN_CASHOUT_AMOUNT = 1000000n;
|
|
208
|
+
interface CashPlatformCapability {
|
|
209
|
+
/** Platform id, e.g. `'venmo'` - the value `receive.platform` accepts. */
|
|
210
|
+
platform: string;
|
|
211
|
+
/** Market-rate (oracle-priced) currencies this platform can pay out. */
|
|
212
|
+
currencies: CurrencyType[];
|
|
213
|
+
/** Human hint for the payee handle format. */
|
|
214
|
+
payeeHint: string;
|
|
215
|
+
/**
|
|
216
|
+
* When true, registering a payee for this platform requires a signed maker
|
|
217
|
+
* identity attestation the SDK cannot produce - register the payee via the
|
|
218
|
+
* ZKP2P app/extension first. A bare-handle `cashout()` throws
|
|
219
|
+
* `PAYEE_VERIFICATION_REQUIRED`.
|
|
220
|
+
*/
|
|
221
|
+
requiresIdentityAttestation: boolean;
|
|
222
|
+
}
|
|
223
|
+
interface CashCapabilities {
|
|
224
|
+
chainId: number;
|
|
225
|
+
token: {
|
|
226
|
+
address: string;
|
|
227
|
+
symbol: 'USDC';
|
|
228
|
+
decimals: number;
|
|
229
|
+
};
|
|
230
|
+
environment: RuntimeEnv;
|
|
231
|
+
/** Every payout corridor: platform × oracle-priced currencies. */
|
|
232
|
+
platforms: CashPlatformCapability[];
|
|
233
|
+
/** All oracle-priced (market-rate) currencies across platforms. */
|
|
234
|
+
currencies: CurrencyType[];
|
|
235
|
+
/** Amount bounds in USDC base units. */
|
|
236
|
+
amount: {
|
|
237
|
+
min: bigint;
|
|
238
|
+
recommendedMin: bigint;
|
|
239
|
+
max: null;
|
|
240
|
+
};
|
|
241
|
+
/** Pricing is always the live oracle at fill time - never a committed quote. */
|
|
242
|
+
pricing: {
|
|
243
|
+
kind: 'oracle-market-rate';
|
|
244
|
+
spreadBps: 0;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
declare function buildCapabilities(environment: RuntimeEnv): CashCapabilities;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Estimate - currency + amount only. No payee, no side effects, no expiry,
|
|
251
|
+
* idempotent, cacheable. "≈ at whatever the oracle says when a buyer fills."
|
|
252
|
+
*
|
|
253
|
+
* Reads the same Chainlink feed the protocol prices the deposit against, so
|
|
254
|
+
* there is no external FX dependency. USD is a zero-address passthrough
|
|
255
|
+
* (USDC ≈ USD). The binding rate resolves on-chain at fill time.
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
interface EstimateInput {
|
|
259
|
+
/** Amount to cash out, USDC base units (6 decimals). Use `usdc()` to build it. */
|
|
260
|
+
amount: bigint;
|
|
261
|
+
/** Target fiat currency. */
|
|
262
|
+
currency: CurrencyType;
|
|
263
|
+
}
|
|
264
|
+
interface CashEstimate {
|
|
265
|
+
/** Always `'oracle-estimate'` - there is no committed quote in Peer Cash. */
|
|
266
|
+
kind: 'oracle-estimate';
|
|
267
|
+
currency: CurrencyType;
|
|
268
|
+
/** The input amount, USDC base units. */
|
|
269
|
+
amount: bigint;
|
|
270
|
+
/** Target-currency units per 1 USDC at the time of the read. */
|
|
271
|
+
rate: number;
|
|
272
|
+
/** `amount × rate` in target-currency units. */
|
|
273
|
+
receiveAmount: number;
|
|
274
|
+
/** Unix seconds when the oracle was read. */
|
|
275
|
+
asOf: number;
|
|
276
|
+
/** Unix seconds the Chainlink feed last updated (absent for the USD passthrough). */
|
|
277
|
+
oracleUpdatedAt?: number;
|
|
278
|
+
/** True when the feed reading is older than a day - treat the rate with caution. */
|
|
279
|
+
stale?: boolean;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* `createCashClient` - the eight-verb facade over a read-only `Zkp2pClient`.
|
|
284
|
+
*
|
|
285
|
+
* The facade keeps the outward surface tiny (capabilities / estimate / cashout
|
|
286
|
+
* / order / orders / watch / withdraw / topUp) while reusing the published
|
|
287
|
+
* SDK's battle-tested internals. A React app, a Node service, and an AI agent
|
|
288
|
+
* are equal consumers: every mutating verb has an unsigned `prepare` path,
|
|
289
|
+
* every wire type is serializable, and every transaction carries ERC-8021
|
|
290
|
+
* attribution ({@link CASH_ATTRIBUTION_CODE}).
|
|
291
|
+
*/
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* ERC-8021 attribution code stamped on every transaction this package
|
|
295
|
+
* produces (signed and prepare paths, including approves). Integrator codes
|
|
296
|
+
* from `CashClientOptions.referrer` are appended after it; the SDK always
|
|
297
|
+
* appends the Base builder code last.
|
|
298
|
+
*/
|
|
299
|
+
declare const CASH_ATTRIBUTION_CODE = "peer-cash";
|
|
300
|
+
interface CashClientOptions {
|
|
301
|
+
/** `'production' | 'preproduction' | 'staging'` - selects contracts, curator, and indexer. */
|
|
302
|
+
environment: RuntimeEnv;
|
|
303
|
+
/** viem transport for RPC reads; defaults to the public Base RPC. */
|
|
304
|
+
transport?: Transport;
|
|
305
|
+
/** Convenience alternative to `transport`. */
|
|
306
|
+
rpcUrl?: string;
|
|
307
|
+
/** Indexer URL override. */
|
|
308
|
+
indexerUrl?: string;
|
|
309
|
+
/** Curator (ZKP2P API) URL override. */
|
|
310
|
+
curatorUrl?: string;
|
|
311
|
+
/** Optional ZKP2P API key. */
|
|
312
|
+
apiKey?: string;
|
|
313
|
+
/**
|
|
314
|
+
* Your own ERC-8021 attribution code(s), appended after
|
|
315
|
+
* {@link CASH_ATTRIBUTION_CODE} on every transaction (e.g. `'acme-app'`).
|
|
316
|
+
*/
|
|
317
|
+
referrer?: string | string[];
|
|
318
|
+
}
|
|
319
|
+
/** One payout leg: platform + currency + payee handle. */
|
|
320
|
+
interface CashLeg {
|
|
321
|
+
/** Platform id from `capabilities()`, e.g. `'venmo'`. */
|
|
322
|
+
platform: string;
|
|
323
|
+
/** Fiat currency to receive. */
|
|
324
|
+
currency: CurrencyType;
|
|
325
|
+
/** Payee details, e.g. `{ offchainId: '@andrew' }`. */
|
|
326
|
+
payee: CuratorPayeeDataInput;
|
|
327
|
+
}
|
|
328
|
+
interface CashoutInput {
|
|
329
|
+
/** Amount to cash out, USDC base units. Use `usdc()` to build it. */
|
|
330
|
+
amount: bigint;
|
|
331
|
+
/** Where the fiat should arrive. Multi-payout is a deliberate v1 cut. */
|
|
332
|
+
receive: CashLeg;
|
|
333
|
+
/** Per-order min/max override (USDC base units). */
|
|
334
|
+
intentAmountRange?: {
|
|
335
|
+
min: bigint;
|
|
336
|
+
max: bigint;
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
interface SignerOptions {
|
|
340
|
+
/** A viem WalletClient with an account, on Base. */
|
|
341
|
+
signer: WalletClient;
|
|
342
|
+
}
|
|
343
|
+
interface WithdrawOptions extends SignerOptions {
|
|
344
|
+
/**
|
|
345
|
+
* Partial amount to withdraw (USDC base units). Only unlocked funds are
|
|
346
|
+
* withdrawable partially - a live buyer intent does not block it. Omit to
|
|
347
|
+
* close the order fully (prunes expired intents first when needed).
|
|
348
|
+
*/
|
|
349
|
+
amount?: bigint;
|
|
350
|
+
}
|
|
351
|
+
interface TopUpResult {
|
|
352
|
+
depositId: string;
|
|
353
|
+
txHash: Hash;
|
|
354
|
+
}
|
|
355
|
+
type CashPreparedStepKind = 'approve' | 'createDeposit' | 'pruneExpiredIntents' | 'withdrawDeposit' | 'removeFunds' | 'addFunds';
|
|
356
|
+
interface CashPreparedStep {
|
|
357
|
+
/** Stable action label for the transaction at the same index in `txs[]`. */
|
|
358
|
+
kind: CashPreparedStepKind;
|
|
359
|
+
/** Human-readable reason to show in approval UIs, logs, or policy reviews. */
|
|
360
|
+
description: string;
|
|
361
|
+
}
|
|
362
|
+
interface CashoutResult {
|
|
363
|
+
/** Composite deposit id (`escrow_onchainId`) - the resume key. Bind it to your user. */
|
|
364
|
+
depositId: string;
|
|
365
|
+
txHash: Hash;
|
|
366
|
+
escrowAddress: string;
|
|
367
|
+
onchainDepositId: bigint;
|
|
368
|
+
/** Optimistic snapshot (`awaiting-buyer`); poll `order(depositId)` for live state. */
|
|
369
|
+
order: CashOrder;
|
|
370
|
+
}
|
|
371
|
+
interface PrepareResult {
|
|
372
|
+
/**
|
|
373
|
+
* Unsigned transactions in submission order: `[approve, createDeposit]`.
|
|
374
|
+
* Submit with any signer - agent wallet, AA bundler, server key. Drop the
|
|
375
|
+
* approve when the escrow already has sufficient allowance.
|
|
376
|
+
*/
|
|
377
|
+
txs: PreparedTransaction[];
|
|
378
|
+
/** One label per transaction in `txs[]`, same order. */
|
|
379
|
+
steps: CashPreparedStep[];
|
|
380
|
+
/** Curator payee registration output - the payee hashes now live on the deposit params. */
|
|
381
|
+
register: {
|
|
382
|
+
hashedOnchainIds: string[];
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
interface WithdrawResult {
|
|
386
|
+
depositId: string;
|
|
387
|
+
/** Present when expired intents had to be pruned before withdrawal. */
|
|
388
|
+
pruneTxHash?: Hash;
|
|
389
|
+
withdrawTxHash: Hash;
|
|
390
|
+
}
|
|
391
|
+
interface WatchOptions {
|
|
392
|
+
signal?: AbortSignal;
|
|
393
|
+
pollIntervalMs?: number;
|
|
394
|
+
timeoutMs?: number;
|
|
395
|
+
}
|
|
396
|
+
interface OrdersOptions {
|
|
397
|
+
/** Only orders still needing attention (`awaiting-buyer` / `matched` / `delivering`). */
|
|
398
|
+
inFlight?: boolean;
|
|
399
|
+
/** Max deposits to scan (default 100). */
|
|
400
|
+
limit?: number;
|
|
401
|
+
}
|
|
402
|
+
interface CashClient {
|
|
403
|
+
/** 0 - Discovery: sync, static. */
|
|
404
|
+
capabilities(): CashCapabilities;
|
|
405
|
+
/** 1 - Estimate: currency + amount only. No payee, no side effects, no expiry. */
|
|
406
|
+
estimate(input: EstimateInput): Promise<CashEstimate>;
|
|
407
|
+
/** 2 - Cash out: payee registration + deposit params + submission happen here. */
|
|
408
|
+
cashout(input: CashoutInput, opts: SignerOptions): Promise<CashoutResult>;
|
|
409
|
+
/** 2b - Unsigned path: `txs[]` for agent wallets, AA, server keys, policy layers. */
|
|
410
|
+
prepare(input: CashoutInput): Promise<PrepareResult>;
|
|
411
|
+
/** 3 - Observe: resumable from `depositId` alone; no session state anywhere. */
|
|
412
|
+
order(depositId: string): Promise<CashOrder>;
|
|
413
|
+
/**
|
|
414
|
+
* 3b - Observe helper: a buyer's protocol track record from their full
|
|
415
|
+
* intent history. Answers "who just matched my order?" during `matched`.
|
|
416
|
+
*/
|
|
417
|
+
buyer(address: string): Promise<CashBuyerProfile>;
|
|
418
|
+
/** 4 - List: indexer-native. A cash order IS a deposit; the chain is the database. */
|
|
419
|
+
orders(owner: string, opts?: OrdersOptions): Promise<CashOrder[]>;
|
|
420
|
+
/** 5 - Watch: yields on change; ends at a terminal state, abort, or timeout. */
|
|
421
|
+
watch(depositId: string, opts?: WatchOptions): AsyncGenerator<CashOrder, void, void>;
|
|
422
|
+
/**
|
|
423
|
+
* 6 - Withdraw: ONE unwind verb. With `amount`, withdraws that much of the
|
|
424
|
+
* unlocked balance (partial; a live buyer intent does not block it).
|
|
425
|
+
* Without, closes the order fully - pruning expired intents first when
|
|
426
|
+
* needed.
|
|
427
|
+
*/
|
|
428
|
+
withdraw(depositId: string, opts: WithdrawOptions): Promise<WithdrawResult>;
|
|
429
|
+
/**
|
|
430
|
+
* 6b - Unsigned path for the unwind verb (agent surface): the same state
|
|
431
|
+
* checks as `withdraw()`, returning `txs[]` for host-side signing.
|
|
432
|
+
*/
|
|
433
|
+
prepareWithdraw(depositId: string, opts?: {
|
|
434
|
+
amount?: bigint;
|
|
435
|
+
}): Promise<{
|
|
436
|
+
txs: PreparedTransaction[];
|
|
437
|
+
steps: CashPreparedStep[];
|
|
438
|
+
}>;
|
|
439
|
+
/** 7 - Top up: add USDC to a live order (same payee, same market rate). */
|
|
440
|
+
topUp(depositId: string, amount: bigint, opts: SignerOptions): Promise<TopUpResult>;
|
|
441
|
+
/** 7b - Unsigned path: `[approve, addFunds]` for host-side signing. */
|
|
442
|
+
prepareTopUp(depositId: string, amount: bigint): Promise<{
|
|
443
|
+
txs: PreparedTransaction[];
|
|
444
|
+
steps: CashPreparedStep[];
|
|
445
|
+
}>;
|
|
446
|
+
}
|
|
447
|
+
declare function createCashClient(options: CashClientOptions): CashClient;
|
|
448
|
+
|
|
449
|
+
export { type CashPayoutInfo as C, type EstimateInput as E, type IntentStatus as I, MIN_CASHOUT_AMOUNT as M, type OrdersOptions as O, type PrepareResult as P, RECOMMENDED_MIN_CASHOUT_AMOUNT as R, type SignerOptions as S, type TopUpResult as T, type WithdrawResult as W, type IntentEntity as a, type CashBuyerProfile as b, type CashDepositInput as c, type CreateDepositParamsArg as d, type CashOrder as e, type CashFill as f, type CashCapabilities as g, type CashoutResult as h, type CashEstimate as i, type CashPreparedStep as j, CASH_ATTRIBUTION_CODE as k, type CashClient as l, type CashClientOptions as m, type CashLeg as n, type CashNextAction as o, type CashOrderState as p, type CashPayout as q, type CashPayoutPricing as r, type CashPlatformCapability as s, type CashPreparedStepKind as t, type CashoutInput as u, type CuratorPayeeDataInput as v, type WatchOptions as w, type WithdrawOptions as x, buildCapabilities as y, createCashClient as z };
|