@kasufinance/kasu-sdk 2.10.2 → 2.10.3

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.
@@ -349,7 +349,12 @@ export async function checkBatchOutcome<R extends ReceiptLike = ReceiptLike>(
349
349
  return 'unknown';
350
350
  }
351
351
  if (read.kind === 'reverted') return 'not-deposited';
352
- if (read.kind !== 'mined' || typeof read.txHash !== 'string') {
352
+ // An empty hash is not an answer — `waitForMined` reads it the same way.
353
+ if (
354
+ read.kind !== 'mined' ||
355
+ typeof read.txHash !== 'string' ||
356
+ read.txHash === ''
357
+ ) {
353
358
  return 'unknown';
354
359
  }
355
360
  try {
@@ -367,9 +372,60 @@ export async function checkBatchOutcome<R extends ReceiptLike = ReceiptLike>(
367
372
  }
368
373
 
369
374
  // ---------------------------------------------------------------------------
370
- // One sponsored call — withdraw, cancel, withdraw at expiry
375
+ // One sponsored call — withdraw, cancel, withdraw at expiry, transfer
371
376
  // ---------------------------------------------------------------------------
372
377
 
378
+ /**
379
+ * `checkBatchOutcome` for ONE sponsored call — ONE status read, no polling —
380
+ * for an app's guard against sending the same request twice (a P2P transfer
381
+ * whose earlier submission ended PENDING, say):
382
+ *
383
+ * - `executed` — mined, and the receipt proves the sender's operation
384
+ * succeeded (`proveUserOperationInReceipt`);
385
+ * - `not-executed` — definitively reverted (vendor status or the operation's
386
+ * own flag);
387
+ * - `unknown` — anything else, including a read or receipt that failed, or a
388
+ * receipt that does not show the sender's operation.
389
+ *
390
+ * Only `not-executed` may let a new attempt proceed unprompted; `executed`
391
+ * means the earlier one landed and the user should be told.
392
+ */
393
+ export async function checkSponsoredCallOutcome<
394
+ R extends ReceiptLike = ReceiptLike,
395
+ >(
396
+ transactionId: string,
397
+ expect: Omit<UserOperationProofExpectation, 'userOperationHash'>,
398
+ ports: Pick<BatchSubmissionPorts<R>, 'getStatus' | 'getReceipt'>,
399
+ ): Promise<'executed' | 'not-executed' | 'unknown'> {
400
+ let read: BatchStatusRead;
401
+ try {
402
+ read = await ports.getStatus(transactionId);
403
+ } catch {
404
+ return 'unknown';
405
+ }
406
+ if (read.kind === 'reverted') return 'not-executed';
407
+ // An empty hash is not an answer — `waitForMined` reads it the same way.
408
+ if (
409
+ read.kind !== 'mined' ||
410
+ typeof read.txHash !== 'string' ||
411
+ read.txHash === ''
412
+ ) {
413
+ return 'unknown';
414
+ }
415
+ try {
416
+ const receipt = await ports.getReceipt(read.txHash);
417
+ const proof = proveUserOperationInReceipt(receipt, {
418
+ ...expect,
419
+ userOperationHash: read.userOperationHash ?? null,
420
+ });
421
+ if (proof.kind === 'executed') return 'executed';
422
+ if (proof.kind === 'reverted') return 'not-executed';
423
+ return 'unknown';
424
+ } catch {
425
+ return 'unknown';
426
+ }
427
+ }
428
+
373
429
  /**
374
430
  * `BatchSubmissionPorts` for ONE sponsored call: the same status, receipt and
375
431
  * clock ports — a relay client written for the deposit batch serves both —
@@ -409,9 +465,9 @@ export interface SponsoredCallSubmission<R extends ReceiptLike = ReceiptLike>
409
465
  }
410
466
 
411
467
  /**
412
- * `submitBatch` for ONE sponsored `LendingPoolManager` call — the body of a
413
- * `WithdrawFlow` `submitCall` port, and of an app's cancel or
414
- * withdraw-at-expiry action. Same post, same polling policy, same outcome
468
+ * `submitBatch` for ONE sponsored call — the body of a `WithdrawFlow`
469
+ * `submitCall` port, of an app's cancel or withdraw-at-expiry action, and of
470
+ * a P2P transfer (`encodeStableTransfer`). Same post, same polling policy, same outcome
415
471
  * table; the proof is `proveUserOperationInReceipt` (the sender's operation
416
472
  * succeeded) instead of the deposit proof, and an unproven receipt is
417
473
  * `call_unproven:<reason>`.
@@ -427,7 +483,8 @@ export interface SponsoredCallSubmission<R extends ReceiptLike = ReceiptLike>
427
483
  * The call is checked against its kind before anything is posted — a known
428
484
  * kind, exactly `{ to, data }`, and `data` opening with that kind's selector —
429
485
  * and a mismatch is `BatchSubmissionError('call_mismatch', 'failed')`: nothing
430
- * was sent. Build calls with `kasu.calls`, and this never fires.
486
+ * was sent. Build calls with `kasu.calls` (or `encodeStableTransfer`), and
487
+ * this never fires.
431
488
  *
432
489
  * As on the deposit path, nothing after the post ever produces `failed`.
433
490
  */
@@ -21,6 +21,7 @@ export type { BatchSubmissionOutcome } from './batch-errors';
21
21
 
22
22
  export {
23
23
  checkBatchOutcome,
24
+ checkSponsoredCallOutcome,
24
25
  DEFAULT_BATCH_POLLING_POLICY,
25
26
  submitBatch,
26
27
  submitSponsoredCall,