@zkp2p/cash 0.1.2 → 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 +92 -28
- package/README.md +69 -25
- 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 +1099 -254
- package/dist/index.d.cts +1554 -74
- package/dist/index.d.ts +1554 -74
- package/dist/index.js +886 -248
- 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 +82 -19
- 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
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// src/engine/constants.ts
|
|
2
|
+
var BASE_CHAIN_ID = 8453;
|
|
3
|
+
var BASE_USDC_ADDRESS = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913";
|
|
4
|
+
var USDC_DECIMALS = 6;
|
|
5
|
+
var MARKET_SPREAD_BPS = 0;
|
|
6
|
+
var ORACLE_MIN_CONVERSION_RATE_SENTINEL = 1n;
|
|
7
|
+
var CASH_ORDER_STATUSES = [
|
|
8
|
+
"SIGNALED",
|
|
9
|
+
"FULFILLED",
|
|
10
|
+
"PRUNED",
|
|
11
|
+
"MANUALLY_RELEASED"
|
|
12
|
+
];
|
|
13
|
+
var CASH_ORDER_POLL_INTERVAL_MS = 5e3;
|
|
14
|
+
var CASH_RETAIN_ON_EMPTY = false;
|
|
15
|
+
|
|
16
|
+
// src/client/errors.ts
|
|
17
|
+
var CashError = class extends Error {
|
|
18
|
+
code;
|
|
19
|
+
retryable;
|
|
20
|
+
remediation;
|
|
21
|
+
recovery;
|
|
22
|
+
constructor(shape, options) {
|
|
23
|
+
super(shape.message, options);
|
|
24
|
+
this.name = "CashError";
|
|
25
|
+
this.code = shape.code;
|
|
26
|
+
this.retryable = shape.retryable;
|
|
27
|
+
this.remediation = shape.remediation;
|
|
28
|
+
if (shape.recovery) this.recovery = shape.recovery;
|
|
29
|
+
}
|
|
30
|
+
/** Serializable view (for tool results and logs). */
|
|
31
|
+
toJSON() {
|
|
32
|
+
return {
|
|
33
|
+
code: this.code,
|
|
34
|
+
message: this.message,
|
|
35
|
+
retryable: this.retryable,
|
|
36
|
+
remediation: this.remediation,
|
|
37
|
+
...this.recovery ? { recovery: this.recovery } : {}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
function isCashError(value) {
|
|
42
|
+
return value instanceof CashError;
|
|
43
|
+
}
|
|
44
|
+
var errors = {
|
|
45
|
+
oracleUnsupportedCurrency: (currency) => new CashError({
|
|
46
|
+
code: "ORACLE_UNSUPPORTED_CURRENCY",
|
|
47
|
+
message: `${currency} has no live Chainlink oracle feed; Peer Cash is market-rate only.`,
|
|
48
|
+
retryable: false,
|
|
49
|
+
remediation: `Pick a currency listed in capabilities() - each one is priced by a live oracle feed.`
|
|
50
|
+
}),
|
|
51
|
+
oracleReadFailed: (currency, cause) => new CashError(
|
|
52
|
+
{
|
|
53
|
+
code: "ORACLE_READ_FAILED",
|
|
54
|
+
message: `The ${currency} market-rate oracle could not be read.`,
|
|
55
|
+
retryable: true,
|
|
56
|
+
remediation: `Retry the estimate shortly or use another healthy Base RPC. Do not present a cached value as a live market rate.`
|
|
57
|
+
},
|
|
58
|
+
{ cause }
|
|
59
|
+
),
|
|
60
|
+
unsupportedPlatform: (platform) => new CashError({
|
|
61
|
+
code: "UNSUPPORTED_PLATFORM",
|
|
62
|
+
message: `'${platform}' is not a supported payout platform in this environment.`,
|
|
63
|
+
retryable: false,
|
|
64
|
+
remediation: `Pick a platform listed in capabilities().`
|
|
65
|
+
}),
|
|
66
|
+
unsupportedPlatformCurrency: (platform, currency) => new CashError({
|
|
67
|
+
code: "UNSUPPORTED_PLATFORM_CURRENCY",
|
|
68
|
+
message: `${platform} cannot receive ${currency} in this environment.`,
|
|
69
|
+
retryable: false,
|
|
70
|
+
remediation: `Pick one of the currencies listed for ${platform} in capabilities().`
|
|
71
|
+
}),
|
|
72
|
+
amountBelowMinimum: (amount, min) => new CashError({
|
|
73
|
+
code: "AMOUNT_BELOW_MINIMUM",
|
|
74
|
+
message: `Amount ${amount} is below the minimum cash-out of ${min} USDC base units.`,
|
|
75
|
+
retryable: false,
|
|
76
|
+
remediation: `Increase the amount to at least ${min} base units (${Number(min) / 1e6} USDC).`
|
|
77
|
+
}),
|
|
78
|
+
invalidIntentAmountRange: (amount, min, max) => new CashError({
|
|
79
|
+
code: "INVALID_INTENT_AMOUNT_RANGE",
|
|
80
|
+
message: `Intent amount range ${min}-${max} is invalid for a ${amount} base-unit cash-out.`,
|
|
81
|
+
retryable: false,
|
|
82
|
+
remediation: `Use a positive minimum no greater than the maximum, and a maximum no greater than the cash-out amount.`
|
|
83
|
+
}),
|
|
84
|
+
activeIntentBlocksWithdrawal: (depositId) => new CashError({
|
|
85
|
+
code: "ACTIVE_INTENT_BLOCKS_WITHDRAWAL",
|
|
86
|
+
message: `Order ${depositId} has a live buyer intent; escrow blocks withdrawal while a buyer may still deliver.`,
|
|
87
|
+
retryable: true,
|
|
88
|
+
remediation: `Wait for the buyer to complete or for their intent to expire, then call withdraw() again - it prunes expired intents automatically.`
|
|
89
|
+
}),
|
|
90
|
+
insufficientAvailableFunds: (depositId, requested, available) => new CashError({
|
|
91
|
+
code: "INSUFFICIENT_AVAILABLE_FUNDS",
|
|
92
|
+
message: `Order ${depositId} has ${available} base units available; ${requested} requested.`,
|
|
93
|
+
retryable: true,
|
|
94
|
+
remediation: `Withdraw at most the available (unlocked) amount, or omit the amount to close the order fully once no buyer intent is live.`
|
|
95
|
+
}),
|
|
96
|
+
insufficientTokenBalance: (requiredAmount) => new CashError({
|
|
97
|
+
code: "INSUFFICIENT_TOKEN_BALANCE",
|
|
98
|
+
message: requiredAmount === void 0 ? `The wallet does not hold enough of the source token for this transaction.` : `The wallet does not hold the ${requiredAmount} base units required for this transaction.`,
|
|
99
|
+
retryable: false,
|
|
100
|
+
remediation: requiredAmount === void 0 ? `Fund the wallet with the required token amount, then retry.` : `Fund the wallet to at least ${requiredAmount} token base units, then retry.`
|
|
101
|
+
}),
|
|
102
|
+
orderNotActive: (depositId) => new CashError({
|
|
103
|
+
code: "ORDER_NOT_ACTIVE",
|
|
104
|
+
message: `Order ${depositId} is closed (delivered or returned); it cannot be topped up.`,
|
|
105
|
+
retryable: false,
|
|
106
|
+
remediation: `Start a new cash-out with cashout() instead.`
|
|
107
|
+
}),
|
|
108
|
+
invalidDepositId: (depositId, cause) => new CashError(
|
|
109
|
+
{
|
|
110
|
+
code: "INVALID_DEPOSIT_ID",
|
|
111
|
+
message: `'${depositId}' is not a valid Peer Cash deposit id.`,
|
|
112
|
+
retryable: false,
|
|
113
|
+
remediation: `Use the depositId returned by cashout() (escrowAddress_onchainDepositId) without modifying it.`
|
|
114
|
+
},
|
|
115
|
+
{ cause }
|
|
116
|
+
),
|
|
117
|
+
nothingToWithdraw: (depositId) => new CashError({
|
|
118
|
+
code: "NOTHING_TO_WITHDRAW",
|
|
119
|
+
message: `Order ${depositId} holds no withdrawable funds (already delivered or returned).`,
|
|
120
|
+
retryable: false,
|
|
121
|
+
remediation: `Check order(depositId).state - this order is terminal.`
|
|
122
|
+
}),
|
|
123
|
+
indexerLag: (depositId) => new CashError({
|
|
124
|
+
code: "INDEXER_LAG",
|
|
125
|
+
message: `Order ${depositId} is not indexed yet (the deposit may be seconds old).`,
|
|
126
|
+
retryable: true,
|
|
127
|
+
remediation: `Retry in a few seconds; on-chain state is ahead of the indexer right after a transaction.`
|
|
128
|
+
}),
|
|
129
|
+
orderNotFound: (depositId) => new CashError({
|
|
130
|
+
code: "ORDER_NOT_FOUND",
|
|
131
|
+
message: `No deposit found for id ${depositId}.`,
|
|
132
|
+
retryable: true,
|
|
133
|
+
remediation: `Verify the composite depositId (escrow_onchainId). If the deposit was created seconds ago this is indexer lag - retry shortly.`
|
|
134
|
+
}),
|
|
135
|
+
indexerUnavailable: (operation, cause) => new CashError(
|
|
136
|
+
{
|
|
137
|
+
code: "INDEXER_UNAVAILABLE",
|
|
138
|
+
message: `The protocol indexer could not complete the ${operation} query.`,
|
|
139
|
+
retryable: true,
|
|
140
|
+
remediation: `Retry shortly. Keep the composite depositId or owner address so the read can resume without repeating an on-chain transaction.`
|
|
141
|
+
},
|
|
142
|
+
{ cause }
|
|
143
|
+
),
|
|
144
|
+
payeeRegistrationFailed: (cause) => new CashError(
|
|
145
|
+
{
|
|
146
|
+
code: "PAYEE_REGISTRATION_FAILED",
|
|
147
|
+
message: `Registering payee details with the curator failed.`,
|
|
148
|
+
retryable: true,
|
|
149
|
+
remediation: `Check the payee handle format for the platform (see capabilities() hints) and retry.`
|
|
150
|
+
},
|
|
151
|
+
{ cause }
|
|
152
|
+
),
|
|
153
|
+
payeeVerificationRequired: (platform, cause) => new CashError(
|
|
154
|
+
{
|
|
155
|
+
code: "PAYEE_VERIFICATION_REQUIRED",
|
|
156
|
+
message: `${platform} requires a verified maker identity attestation to register a payee; a bare handle is not accepted.`,
|
|
157
|
+
retryable: false,
|
|
158
|
+
remediation: `Register this ${platform} payee through the ZKP2P app / extension (which produces the signed identity attestation) before cashing out. capabilities() flags such platforms with requiresIdentityAttestation: true.`
|
|
159
|
+
},
|
|
160
|
+
{ cause }
|
|
161
|
+
),
|
|
162
|
+
sourceRouteUnsupportedInPrepare: () => new CashError({
|
|
163
|
+
code: "SOURCE_ROUTE_UNSUPPORTED_IN_PREPARE",
|
|
164
|
+
message: `prepare() cannot execute a Relay source route before creating the Base USDC cash-out.`,
|
|
165
|
+
retryable: false,
|
|
166
|
+
remediation: `Use cashout(inputWithSource, { signer }) for the one-call bridge-then-cashout flow, or call quoteSource()/executeSourceQuote() first and then prepare() a Base USDC cash-out.`
|
|
167
|
+
}),
|
|
168
|
+
sourceRecipientMismatch: (recipient, owner) => new CashError({
|
|
169
|
+
code: "SOURCE_RECIPIENT_MISMATCH",
|
|
170
|
+
message: `Source recipient ${recipient} does not match the cash-out depositor ${owner}.`,
|
|
171
|
+
retryable: false,
|
|
172
|
+
remediation: `For one-call source cashout, deliver Relay output to the depositor address. For a different recipient, bridge first and then cash out from that recipient's signer.`
|
|
173
|
+
}),
|
|
174
|
+
sourceCapabilitiesFailed: (cause) => new CashError(
|
|
175
|
+
{
|
|
176
|
+
code: "SOURCE_CAPABILITIES_FAILED",
|
|
177
|
+
message: `Relay source-chain discovery failed.`,
|
|
178
|
+
retryable: true,
|
|
179
|
+
remediation: `Retry sourceCapabilities() shortly, or use the default Base USDC path.`
|
|
180
|
+
},
|
|
181
|
+
{ cause }
|
|
182
|
+
),
|
|
183
|
+
sourceQuoteFailed: (cause) => new CashError(
|
|
184
|
+
{
|
|
185
|
+
code: "SOURCE_QUOTE_FAILED",
|
|
186
|
+
message: `Relay did not return a valid route to canonical Base USDC.`,
|
|
187
|
+
retryable: true,
|
|
188
|
+
remediation: `Refresh source capabilities and request a new quote. Do not submit transactions from this response.`
|
|
189
|
+
},
|
|
190
|
+
{ cause }
|
|
191
|
+
),
|
|
192
|
+
sourceExecutionFailed: (cause, evidence) => new CashError(
|
|
193
|
+
{
|
|
194
|
+
code: "SOURCE_EXECUTION_FAILED",
|
|
195
|
+
message: `Relay source-route execution did not complete successfully.`,
|
|
196
|
+
retryable: false,
|
|
197
|
+
remediation: `Inspect the wallet transactions and Relay request status before retrying so the source transfer is never submitted twice.`,
|
|
198
|
+
...evidence && (evidence.requestId !== void 0 || evidence.txHashes.length > 0) ? {
|
|
199
|
+
recovery: {
|
|
200
|
+
kind: "inspect-relay-route",
|
|
201
|
+
...evidence.requestId ? { requestId: evidence.requestId } : {},
|
|
202
|
+
txHashes: evidence.txHashes,
|
|
203
|
+
...evidence.transactions ? { transactions: evidence.transactions } : {}
|
|
204
|
+
}
|
|
205
|
+
} : {}
|
|
206
|
+
},
|
|
207
|
+
{ cause }
|
|
208
|
+
),
|
|
209
|
+
sourceStatusFailed: (requestId, cause) => new CashError(
|
|
210
|
+
{
|
|
211
|
+
code: "SOURCE_STATUS_FAILED",
|
|
212
|
+
message: `Relay status is unavailable for request ${requestId}.`,
|
|
213
|
+
retryable: true,
|
|
214
|
+
remediation: `Retry relayStatus(requestId) shortly; keep the request id and transaction hashes for recovery.`
|
|
215
|
+
},
|
|
216
|
+
{ cause }
|
|
217
|
+
),
|
|
218
|
+
sourceRouteCompletedCashoutFailed: (source, cause) => new CashError(
|
|
219
|
+
{
|
|
220
|
+
code: "SOURCE_ROUTE_COMPLETED_CASHOUT_FAILED",
|
|
221
|
+
message: `Relay completed, but the Base USDC cash-out transaction was not created.`,
|
|
222
|
+
retryable: false,
|
|
223
|
+
remediation: `Do not repeat the Relay route. Retry cashout() without source using the recovery amount already delivered on Base.`,
|
|
224
|
+
recovery: {
|
|
225
|
+
kind: "retry-base-usdc-cashout",
|
|
226
|
+
amount: source.amount.toString(),
|
|
227
|
+
...source.requestId ? { requestId: source.requestId } : {},
|
|
228
|
+
txHashes: source.txHashes,
|
|
229
|
+
...source.transactions ? { transactions: source.transactions } : {}
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
{ cause }
|
|
233
|
+
),
|
|
234
|
+
sourceCashoutSubmissionUnknown: (source, depositor, cause) => new CashError(
|
|
235
|
+
{
|
|
236
|
+
code: "SOURCE_CASHOUT_SUBMISSION_UNKNOWN",
|
|
237
|
+
message: `Relay completed, but the Base cash-out submission did not return a transaction hash.`,
|
|
238
|
+
retryable: false,
|
|
239
|
+
remediation: `Do not repeat Relay or submit another cash-out yet. Inspect recent Base transactions and orders(${depositor}) to prove no deposit was broadcast; only then retry Base-USDC-only with the recovery amount.`,
|
|
240
|
+
recovery: {
|
|
241
|
+
kind: "inspect-base-cashout-submission",
|
|
242
|
+
amount: source.amount.toString(),
|
|
243
|
+
...source.requestId ? { requestId: source.requestId } : {},
|
|
244
|
+
txHashes: source.txHashes,
|
|
245
|
+
...source.transactions ? { transactions: source.transactions } : {},
|
|
246
|
+
depositor
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
{ cause }
|
|
250
|
+
),
|
|
251
|
+
sourceCashoutStatusUnknown: (source, depositTxHash, cause) => new CashError(
|
|
252
|
+
{
|
|
253
|
+
code: "SOURCE_CASHOUT_STATUS_UNKNOWN",
|
|
254
|
+
message: `Relay completed and Base cash-out transaction ${depositTxHash} was submitted, but its receipt could not be confirmed.`,
|
|
255
|
+
retryable: false,
|
|
256
|
+
remediation: `Do not repeat the Relay route or submit another cash-out. Inspect the Base transaction; if it succeeded, recover the depositId from its DepositReceived log, and if it reverted, retry a Base-USDC-only cashout with the recovery amount.`,
|
|
257
|
+
recovery: {
|
|
258
|
+
kind: "inspect-base-cashout-transaction",
|
|
259
|
+
amount: source.amount.toString(),
|
|
260
|
+
...source.requestId ? { requestId: source.requestId } : {},
|
|
261
|
+
txHashes: source.txHashes,
|
|
262
|
+
...source.transactions ? { transactions: source.transactions } : {},
|
|
263
|
+
depositTxHash
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
{ cause }
|
|
267
|
+
),
|
|
268
|
+
allowanceNotVisible: (amount, cause) => new CashError(
|
|
269
|
+
{
|
|
270
|
+
code: "ALLOWANCE_NOT_VISIBLE",
|
|
271
|
+
message: `USDC approval for ${amount} base units did not become visible on the read path in time.`,
|
|
272
|
+
retryable: true,
|
|
273
|
+
remediation: `The approve transaction mined but the RPC read path is stale or unavailable. Retry the same call in a few seconds.`
|
|
274
|
+
},
|
|
275
|
+
{ cause }
|
|
276
|
+
),
|
|
277
|
+
depositResolutionFailed: (txHash) => new CashError({
|
|
278
|
+
code: "DEPOSIT_RESOLUTION_FAILED",
|
|
279
|
+
message: `Deposit transaction ${txHash} succeeded but no DepositReceived event was found in the receipt.`,
|
|
280
|
+
retryable: false,
|
|
281
|
+
remediation: `Inspect the transaction on Basescan; recover the depositId from the DepositReceived log manually, then resume with order(depositId).`
|
|
282
|
+
}),
|
|
283
|
+
signerRequired: (verb) => new CashError({
|
|
284
|
+
code: "SIGNER_REQUIRED",
|
|
285
|
+
message: `${verb}() mutates on-chain state and needs a signer.`,
|
|
286
|
+
retryable: false,
|
|
287
|
+
remediation: `Pass { signer } (a viem WalletClient with an account), or use prepare() and submit the returned txs with your own signing infrastructure.`
|
|
288
|
+
}),
|
|
289
|
+
signerChainMismatch: (verb, expectedChainId, actualChainId) => new CashError({
|
|
290
|
+
code: "SIGNER_CHAIN_MISMATCH",
|
|
291
|
+
message: `${verb} requires chain ${expectedChainId}, but the signer is connected to chain ${actualChainId}.`,
|
|
292
|
+
retryable: false,
|
|
293
|
+
remediation: `Switch the wallet to chain ${expectedChainId}, obtain a fresh quote if Relay is involved, and retry before submitting any transaction.`
|
|
294
|
+
}),
|
|
295
|
+
signerChainUnavailable: (verb, expectedChainId, cause) => new CashError(
|
|
296
|
+
{
|
|
297
|
+
code: "SIGNER_CHAIN_UNAVAILABLE",
|
|
298
|
+
message: `${verb} could not verify that the signer is connected to chain ${expectedChainId}.`,
|
|
299
|
+
retryable: true,
|
|
300
|
+
remediation: `Reconnect the wallet, switch it to chain ${expectedChainId}, and retry before submitting any transaction.`
|
|
301
|
+
},
|
|
302
|
+
{ cause }
|
|
303
|
+
),
|
|
304
|
+
watchTimeout: (depositId, timeoutMs) => new CashError({
|
|
305
|
+
code: "WATCH_TIMEOUT",
|
|
306
|
+
message: `watch(${depositId}) exceeded ${timeoutMs}ms without reaching a terminal state.`,
|
|
307
|
+
retryable: true,
|
|
308
|
+
remediation: `The order is still live - resume any time with watch(depositId) or order(depositId).`
|
|
309
|
+
}),
|
|
310
|
+
transactionFailed: (txHash, cause) => new CashError(
|
|
311
|
+
{
|
|
312
|
+
code: "TRANSACTION_FAILED",
|
|
313
|
+
message: `Transaction ${txHash} reverted.`,
|
|
314
|
+
retryable: false,
|
|
315
|
+
remediation: `Inspect the transaction on Basescan; the deposit state is unchanged if the revert happened before escrow accepted funds.`
|
|
316
|
+
},
|
|
317
|
+
{ cause }
|
|
318
|
+
),
|
|
319
|
+
transactionSubmissionUnknown: (operation, cause, recovery) => new CashError(
|
|
320
|
+
{
|
|
321
|
+
code: "TRANSACTION_SUBMISSION_UNKNOWN",
|
|
322
|
+
message: `The Base ${operation} submission did not return a transaction hash.`,
|
|
323
|
+
retryable: false,
|
|
324
|
+
remediation: `Do not submit the operation again until you inspect recent Base wallet activity and protocol state; the first transaction may already exist.`,
|
|
325
|
+
...recovery ? { recovery } : {}
|
|
326
|
+
},
|
|
327
|
+
{ cause }
|
|
328
|
+
),
|
|
329
|
+
transactionStatusUnknown: (txHash, cause, operation = "transaction") => new CashError(
|
|
330
|
+
{
|
|
331
|
+
code: "TRANSACTION_STATUS_UNKNOWN",
|
|
332
|
+
message: `Transaction ${txHash} was submitted, but its receipt could not be confirmed.`,
|
|
333
|
+
retryable: false,
|
|
334
|
+
remediation: `Do not resubmit the operation until you inspect ${txHash} on Base or successfully fetch its receipt; the transaction may already have succeeded.`,
|
|
335
|
+
recovery: {
|
|
336
|
+
kind: "inspect-base-transaction",
|
|
337
|
+
transactionHash: txHash,
|
|
338
|
+
operation
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
{ cause }
|
|
342
|
+
),
|
|
343
|
+
escrowPaused: () => new CashError({
|
|
344
|
+
code: "ESCROW_PAUSED",
|
|
345
|
+
message: `The escrow contract is paused; deposits are temporarily disabled.`,
|
|
346
|
+
retryable: true,
|
|
347
|
+
remediation: `Wait for the protocol to unpause and retry. Existing funds remain withdrawable.`
|
|
348
|
+
}),
|
|
349
|
+
/** Generic fallback for an on-chain call that failed for an unrecognized reason. */
|
|
350
|
+
chainCallFailed: (verb, cause) => new CashError(
|
|
351
|
+
{
|
|
352
|
+
code: "TRANSACTION_FAILED",
|
|
353
|
+
message: `The on-chain ${verb} call failed.`,
|
|
354
|
+
retryable: false,
|
|
355
|
+
remediation: `Inspect the error cause and the wallet on Basescan. Deposit state is unchanged if the call reverted before escrow accepted funds.`
|
|
356
|
+
},
|
|
357
|
+
{ cause }
|
|
358
|
+
)
|
|
359
|
+
};
|
|
360
|
+
function mapChainError(verb, err, context = {}) {
|
|
361
|
+
if (isCashError(err)) return err;
|
|
362
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
363
|
+
if (/\bpaused\b/i.test(message)) return errors.escrowPaused();
|
|
364
|
+
if (/exceeds balance|insufficient token balance/i.test(message)) {
|
|
365
|
+
return errors.insufficientTokenBalance(context.requiredAmount);
|
|
366
|
+
}
|
|
367
|
+
if (/exceeds allowance|insufficient allowance/i.test(message)) {
|
|
368
|
+
return errors.allowanceNotVisible(context.requiredAmount ?? 0n);
|
|
369
|
+
}
|
|
370
|
+
return errors.chainCallFailed(verb, err);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export { BASE_CHAIN_ID, BASE_USDC_ADDRESS, CASH_ORDER_POLL_INTERVAL_MS, CASH_ORDER_STATUSES, CASH_RETAIN_ON_EMPTY, CashError, MARKET_SPREAD_BPS, ORACLE_MIN_CONVERSION_RATE_SENTINEL, USDC_DECIMALS, errors, isCashError, mapChainError };
|
|
@@ -239,6 +239,7 @@ interface RelaySourceInput {
|
|
|
239
239
|
}
|
|
240
240
|
interface RelayQuoteInput {
|
|
241
241
|
user: string;
|
|
242
|
+
/** Interpreted according to `tradeType`; defaults to exact source input. */
|
|
242
243
|
amount: bigint;
|
|
243
244
|
source: RelaySourceInput;
|
|
244
245
|
recipient?: string;
|
|
@@ -248,7 +249,9 @@ interface RelayQuote {
|
|
|
248
249
|
requestId?: string;
|
|
249
250
|
source: CashAsset;
|
|
250
251
|
destination: CashAsset;
|
|
252
|
+
/** Source amount Relay expects the route to consume. */
|
|
251
253
|
inputAmount: bigint;
|
|
254
|
+
/** Conservative Base USDC output (Relay minimum output when supplied). */
|
|
252
255
|
outputAmount: bigint;
|
|
253
256
|
rate?: number;
|
|
254
257
|
timeEstimateSeconds?: number;
|
|
@@ -259,8 +262,17 @@ interface RelayQuote {
|
|
|
259
262
|
interface RelayExecutionResult {
|
|
260
263
|
requestId?: string;
|
|
261
264
|
txHashes: string[];
|
|
265
|
+
/** Chain-aware evidence (emitted by 0.1.4+; optional for wire compatibility). */
|
|
266
|
+
transactions?: {
|
|
267
|
+
origin: RelayTransaction[];
|
|
268
|
+
destination: RelayTransaction[];
|
|
269
|
+
};
|
|
262
270
|
quote: Execute;
|
|
263
271
|
}
|
|
272
|
+
interface RelayTransaction {
|
|
273
|
+
hash: string;
|
|
274
|
+
chainId: number;
|
|
275
|
+
}
|
|
264
276
|
interface RelayStatus {
|
|
265
277
|
requestId: string;
|
|
266
278
|
status: 'refund' | 'waiting' | 'depositing' | 'failure' | 'pending' | 'submitted' | 'success';
|
|
@@ -360,7 +372,10 @@ interface CashFillEta {
|
|
|
360
372
|
*/
|
|
361
373
|
|
|
362
374
|
interface EstimateInput {
|
|
363
|
-
/**
|
|
375
|
+
/**
|
|
376
|
+
* Without `source`, Base USDC base units. With `source`, Relay interprets
|
|
377
|
+
* this according to `tradeType`; default `EXACT_INPUT` uses source-token units.
|
|
378
|
+
*/
|
|
364
379
|
amount: bigint;
|
|
365
380
|
/** Target fiat currency. */
|
|
366
381
|
currency: CurrencyType;
|
|
@@ -372,6 +387,7 @@ interface EstimateInput {
|
|
|
372
387
|
user: string;
|
|
373
388
|
/** Base recipient for bridged USDC; defaults to `user`. */
|
|
374
389
|
recipient?: string;
|
|
390
|
+
/** Relay amount mode. Omit for the recommended exact source-input estimate. */
|
|
375
391
|
tradeType?: 'EXACT_INPUT' | 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT';
|
|
376
392
|
};
|
|
377
393
|
}
|
|
@@ -408,9 +424,10 @@ interface CashEstimate {
|
|
|
408
424
|
* The facade keeps the outward surface tiny (capabilities / estimate / cashout
|
|
409
425
|
* / order / orders / watch / withdraw / topUp) while reusing the published
|
|
410
426
|
* SDK's battle-tested internals. A React app, a Node service, and an AI agent
|
|
411
|
-
* are equal consumers:
|
|
412
|
-
* every wire type is serializable,
|
|
413
|
-
*
|
|
427
|
+
* are equal consumers: Base-USDC mutations have unsigned `prepare` paths,
|
|
428
|
+
* Relay execution is explicitly signer-backed, every wire type is serializable,
|
|
429
|
+
* and every protocol transaction carries ERC-8021 attribution
|
|
430
|
+
* ({@link CASH_ATTRIBUTION_CODE}).
|
|
414
431
|
*/
|
|
415
432
|
|
|
416
433
|
/**
|
|
@@ -452,14 +469,16 @@ interface CashLeg {
|
|
|
452
469
|
}
|
|
453
470
|
interface CashoutInput {
|
|
454
471
|
/**
|
|
455
|
-
* Amount to cash out.
|
|
456
|
-
*
|
|
472
|
+
* Amount to cash out. Without `source`, this is Base USDC base units. With
|
|
473
|
+
* `source`, Relay interprets it according to `tradeType`; the default
|
|
474
|
+
* `EXACT_INPUT` treats it as source-token base units.
|
|
457
475
|
*/
|
|
458
476
|
amount: bigint;
|
|
459
477
|
/** Optional Relay source asset. Omit for the Base USDC default path. */
|
|
460
478
|
source?: RelaySourceInput & {
|
|
461
479
|
/** Base recipient for bridged USDC; defaults to the signer address. */
|
|
462
480
|
recipient?: string;
|
|
481
|
+
/** Relay amount mode. Omit for the recommended exact source-input flow. */
|
|
463
482
|
tradeType?: 'EXACT_INPUT' | 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT';
|
|
464
483
|
};
|
|
465
484
|
/** Where the fiat should arrive. Multi-payout is a deliberate v1 cut. */
|
|
@@ -511,9 +530,15 @@ interface CashoutResult {
|
|
|
511
530
|
order: CashOrder;
|
|
512
531
|
/** Present when `cashout()` first routed a source asset through Relay. */
|
|
513
532
|
source?: {
|
|
533
|
+
/** Conservative Base USDC amount deposited (Relay's guaranteed minimum output). */
|
|
514
534
|
amount: bigint;
|
|
515
535
|
requestId?: string;
|
|
516
536
|
txHashes: string[];
|
|
537
|
+
/** Chain-aware evidence (emitted by 0.1.4+; optional for wire compatibility). */
|
|
538
|
+
transactions?: {
|
|
539
|
+
origin: RelayTransaction[];
|
|
540
|
+
destination: RelayTransaction[];
|
|
541
|
+
};
|
|
517
542
|
};
|
|
518
543
|
}
|
|
519
544
|
interface PrepareResult {
|
|
@@ -559,7 +584,11 @@ interface CashClient {
|
|
|
559
584
|
/** Quote any Relay-supported EVM source asset into Base USDC. */
|
|
560
585
|
quoteSource(input: RelayQuoteInput): Promise<RelayQuote>;
|
|
561
586
|
/** Execute a Relay SDK quote into Base USDC before starting the Peer Cash order. */
|
|
562
|
-
executeSourceQuote(quote: Execute, opts:
|
|
587
|
+
executeSourceQuote(quote: RelayQuote | Execute, opts: {
|
|
588
|
+
/** Wallet signer on the quote's source chain. */
|
|
589
|
+
signer: WalletClient;
|
|
590
|
+
/** Expected Base recipient. Defaults to the source signer. */
|
|
591
|
+
recipient?: string;
|
|
563
592
|
onProgress?: (data: ProgressData) => void;
|
|
564
593
|
disableCapabilitiesCheck?: boolean;
|
|
565
594
|
}): Promise<RelayExecutionResult>;
|
|
@@ -609,4 +638,4 @@ interface CashClient {
|
|
|
609
638
|
}
|
|
610
639
|
declare function createCashClient(options: CashClientOptions): CashClient;
|
|
611
640
|
|
|
612
|
-
export { type
|
|
641
|
+
export { type CashoutInput as A, type CashoutOptions as B, type CashPayoutInfo as C, type CuratorPayeeDataInput as D, type EstimateInput as E, RECOMMENDED_MIN_CASHOUT_AMOUNT as F, type RelayOptions as G, type RelayQuoteInput as H, type IntentStatus as I, type RelaySourceInput as J, type RelayTransaction as K, type WatchOptions as L, MIN_CASHOUT_AMOUNT as M, type WithdrawOptions as N, type OrdersOptions as O, type PrepareResult as P, buildCapabilities as Q, type RelayExecutionResult as R, type SignerOptions as S, type TopUpResult as T, createCashClient as U, 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, type RelayQuote as k, type RelayStatus as l, type CashSourceCapabilities as m, CASH_ATTRIBUTION_CODE as n, type CashAsset as o, type CashChain as p, type CashClient as q, type CashClientOptions as r, type CashFillEta as s, type CashLeg as t, type CashNextAction as u, type CashOrderState as v, type CashPayout as w, type CashPayoutPricing as x, type CashPlatformCapability as y, type CashPreparedStepKind as z };
|
|
@@ -239,6 +239,7 @@ interface RelaySourceInput {
|
|
|
239
239
|
}
|
|
240
240
|
interface RelayQuoteInput {
|
|
241
241
|
user: string;
|
|
242
|
+
/** Interpreted according to `tradeType`; defaults to exact source input. */
|
|
242
243
|
amount: bigint;
|
|
243
244
|
source: RelaySourceInput;
|
|
244
245
|
recipient?: string;
|
|
@@ -248,7 +249,9 @@ interface RelayQuote {
|
|
|
248
249
|
requestId?: string;
|
|
249
250
|
source: CashAsset;
|
|
250
251
|
destination: CashAsset;
|
|
252
|
+
/** Source amount Relay expects the route to consume. */
|
|
251
253
|
inputAmount: bigint;
|
|
254
|
+
/** Conservative Base USDC output (Relay minimum output when supplied). */
|
|
252
255
|
outputAmount: bigint;
|
|
253
256
|
rate?: number;
|
|
254
257
|
timeEstimateSeconds?: number;
|
|
@@ -259,8 +262,17 @@ interface RelayQuote {
|
|
|
259
262
|
interface RelayExecutionResult {
|
|
260
263
|
requestId?: string;
|
|
261
264
|
txHashes: string[];
|
|
265
|
+
/** Chain-aware evidence (emitted by 0.1.4+; optional for wire compatibility). */
|
|
266
|
+
transactions?: {
|
|
267
|
+
origin: RelayTransaction[];
|
|
268
|
+
destination: RelayTransaction[];
|
|
269
|
+
};
|
|
262
270
|
quote: Execute;
|
|
263
271
|
}
|
|
272
|
+
interface RelayTransaction {
|
|
273
|
+
hash: string;
|
|
274
|
+
chainId: number;
|
|
275
|
+
}
|
|
264
276
|
interface RelayStatus {
|
|
265
277
|
requestId: string;
|
|
266
278
|
status: 'refund' | 'waiting' | 'depositing' | 'failure' | 'pending' | 'submitted' | 'success';
|
|
@@ -360,7 +372,10 @@ interface CashFillEta {
|
|
|
360
372
|
*/
|
|
361
373
|
|
|
362
374
|
interface EstimateInput {
|
|
363
|
-
/**
|
|
375
|
+
/**
|
|
376
|
+
* Without `source`, Base USDC base units. With `source`, Relay interprets
|
|
377
|
+
* this according to `tradeType`; default `EXACT_INPUT` uses source-token units.
|
|
378
|
+
*/
|
|
364
379
|
amount: bigint;
|
|
365
380
|
/** Target fiat currency. */
|
|
366
381
|
currency: CurrencyType;
|
|
@@ -372,6 +387,7 @@ interface EstimateInput {
|
|
|
372
387
|
user: string;
|
|
373
388
|
/** Base recipient for bridged USDC; defaults to `user`. */
|
|
374
389
|
recipient?: string;
|
|
390
|
+
/** Relay amount mode. Omit for the recommended exact source-input estimate. */
|
|
375
391
|
tradeType?: 'EXACT_INPUT' | 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT';
|
|
376
392
|
};
|
|
377
393
|
}
|
|
@@ -408,9 +424,10 @@ interface CashEstimate {
|
|
|
408
424
|
* The facade keeps the outward surface tiny (capabilities / estimate / cashout
|
|
409
425
|
* / order / orders / watch / withdraw / topUp) while reusing the published
|
|
410
426
|
* SDK's battle-tested internals. A React app, a Node service, and an AI agent
|
|
411
|
-
* are equal consumers:
|
|
412
|
-
* every wire type is serializable,
|
|
413
|
-
*
|
|
427
|
+
* are equal consumers: Base-USDC mutations have unsigned `prepare` paths,
|
|
428
|
+
* Relay execution is explicitly signer-backed, every wire type is serializable,
|
|
429
|
+
* and every protocol transaction carries ERC-8021 attribution
|
|
430
|
+
* ({@link CASH_ATTRIBUTION_CODE}).
|
|
414
431
|
*/
|
|
415
432
|
|
|
416
433
|
/**
|
|
@@ -452,14 +469,16 @@ interface CashLeg {
|
|
|
452
469
|
}
|
|
453
470
|
interface CashoutInput {
|
|
454
471
|
/**
|
|
455
|
-
* Amount to cash out.
|
|
456
|
-
*
|
|
472
|
+
* Amount to cash out. Without `source`, this is Base USDC base units. With
|
|
473
|
+
* `source`, Relay interprets it according to `tradeType`; the default
|
|
474
|
+
* `EXACT_INPUT` treats it as source-token base units.
|
|
457
475
|
*/
|
|
458
476
|
amount: bigint;
|
|
459
477
|
/** Optional Relay source asset. Omit for the Base USDC default path. */
|
|
460
478
|
source?: RelaySourceInput & {
|
|
461
479
|
/** Base recipient for bridged USDC; defaults to the signer address. */
|
|
462
480
|
recipient?: string;
|
|
481
|
+
/** Relay amount mode. Omit for the recommended exact source-input flow. */
|
|
463
482
|
tradeType?: 'EXACT_INPUT' | 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT';
|
|
464
483
|
};
|
|
465
484
|
/** Where the fiat should arrive. Multi-payout is a deliberate v1 cut. */
|
|
@@ -511,9 +530,15 @@ interface CashoutResult {
|
|
|
511
530
|
order: CashOrder;
|
|
512
531
|
/** Present when `cashout()` first routed a source asset through Relay. */
|
|
513
532
|
source?: {
|
|
533
|
+
/** Conservative Base USDC amount deposited (Relay's guaranteed minimum output). */
|
|
514
534
|
amount: bigint;
|
|
515
535
|
requestId?: string;
|
|
516
536
|
txHashes: string[];
|
|
537
|
+
/** Chain-aware evidence (emitted by 0.1.4+; optional for wire compatibility). */
|
|
538
|
+
transactions?: {
|
|
539
|
+
origin: RelayTransaction[];
|
|
540
|
+
destination: RelayTransaction[];
|
|
541
|
+
};
|
|
517
542
|
};
|
|
518
543
|
}
|
|
519
544
|
interface PrepareResult {
|
|
@@ -559,7 +584,11 @@ interface CashClient {
|
|
|
559
584
|
/** Quote any Relay-supported EVM source asset into Base USDC. */
|
|
560
585
|
quoteSource(input: RelayQuoteInput): Promise<RelayQuote>;
|
|
561
586
|
/** Execute a Relay SDK quote into Base USDC before starting the Peer Cash order. */
|
|
562
|
-
executeSourceQuote(quote: Execute, opts:
|
|
587
|
+
executeSourceQuote(quote: RelayQuote | Execute, opts: {
|
|
588
|
+
/** Wallet signer on the quote's source chain. */
|
|
589
|
+
signer: WalletClient;
|
|
590
|
+
/** Expected Base recipient. Defaults to the source signer. */
|
|
591
|
+
recipient?: string;
|
|
563
592
|
onProgress?: (data: ProgressData) => void;
|
|
564
593
|
disableCapabilitiesCheck?: boolean;
|
|
565
594
|
}): Promise<RelayExecutionResult>;
|
|
@@ -609,4 +638,4 @@ interface CashClient {
|
|
|
609
638
|
}
|
|
610
639
|
declare function createCashClient(options: CashClientOptions): CashClient;
|
|
611
640
|
|
|
612
|
-
export { type
|
|
641
|
+
export { type CashoutInput as A, type CashoutOptions as B, type CashPayoutInfo as C, type CuratorPayeeDataInput as D, type EstimateInput as E, RECOMMENDED_MIN_CASHOUT_AMOUNT as F, type RelayOptions as G, type RelayQuoteInput as H, type IntentStatus as I, type RelaySourceInput as J, type RelayTransaction as K, type WatchOptions as L, MIN_CASHOUT_AMOUNT as M, type WithdrawOptions as N, type OrdersOptions as O, type PrepareResult as P, buildCapabilities as Q, type RelayExecutionResult as R, type SignerOptions as S, type TopUpResult as T, createCashClient as U, 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, type RelayQuote as k, type RelayStatus as l, type CashSourceCapabilities as m, CASH_ATTRIBUTION_CODE as n, type CashAsset as o, type CashChain as p, type CashClient as q, type CashClientOptions as r, type CashFillEta as s, type CashLeg as t, type CashNextAction as u, type CashOrderState as v, type CashPayout as w, type CashPayoutPricing as x, type CashPlatformCapability as y, type CashPreparedStepKind as z };
|