@dvmkit/sdk 0.10.1 → 0.11.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-3Q6FTZDB.js → chunk-3YFFZLW7.js} +2 -2
- package/dist/{chunk-YOSZIWC3.js → chunk-55DVLBCD.js} +135 -8
- package/dist/{chunk-VMHYGKWT.js → chunk-566CFXGU.js} +9 -1
- package/dist/chunk-5H7P3ORL.js +92 -0
- package/dist/{chunk-3R7NQA3Z.js → chunk-7KQLPVV7.js} +1 -1
- package/dist/{chunk-SYBFMHXQ.js → chunk-AIQGF52I.js} +242 -38
- package/dist/{chunk-JNECYURT.js → chunk-D4FFS3IS.js} +1 -1
- package/dist/{chunk-VTHYQCDB.js → chunk-E7ZBCT5U.js} +1 -1
- package/dist/{chunk-MMGSYMIC.js → chunk-EP7OVWI5.js} +1 -1
- package/dist/{chunk-LDIPVPKI.js → chunk-FFRTAQUW.js} +1 -1
- package/dist/chunk-H3GGFEE5.js +57 -0
- package/dist/{chunk-M3T5JYDJ.js → chunk-HNXMWHLU.js} +1 -1
- package/dist/{chunk-2OGBZPPJ.js → chunk-HQPQ4PFI.js} +1 -1
- package/dist/{chunk-UKD3R2KU.js → chunk-HW2UCOOC.js} +4 -55
- package/dist/{chunk-FFXXGCVG.js → chunk-ITRSITFP.js} +1 -1
- package/dist/{chunk-MU3IE434.js → chunk-JLT2YIBS.js} +267 -52
- package/dist/{chunk-STJBBVNL.js → chunk-K2ZNIQZP.js} +458 -69
- package/dist/{chunk-KFCEXCZM.js → chunk-KJZVTWMX.js} +1 -1
- package/dist/{chunk-W3VGCNG6.js → chunk-LDKV4UHI.js} +1 -1
- package/dist/{chunk-AJ6UHXUA.js → chunk-M4NFYEEY.js} +1 -1
- package/dist/{chunk-MB6R4XPZ.js → chunk-NS2OMIU7.js} +15 -3
- package/dist/{chunk-VUGEEMLT.js → chunk-RPUFWIT4.js} +11 -89
- package/dist/{chunk-EWZFANHJ.js → chunk-VWIMQ5H5.js} +1 -1
- package/dist/{chunk-2XQLL6N6.js → chunk-WFCVS6QB.js} +2 -2
- package/dist/{chunk-QGNXYVBO.js → chunk-Z4FOPROB.js} +17 -0
- package/dist/{content-retention-CrILCNxk.d.ts → content-retention-ySTD1wwZ.d.ts} +1 -1
- package/dist/{credit-ledger-4PZNAMDT.js → credit-ledger-4CBYLSLY.js} +6 -3
- package/dist/{credit-menu-BWsVqMh-.d.ts → credit-menu-BYySnZBk.d.ts} +4 -4
- package/dist/{fx-BM5h4o5S.d.ts → fx-DVTNs9q1.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +6 -5
- package/dist/internal/caller.d.ts +6 -6
- package/dist/internal/caller.js +26 -22
- package/dist/internal/server.d.ts +7 -7
- package/dist/internal/server.js +24 -22
- package/dist/{job-store-92v8e1LQ.d.ts → job-store-DRwXCJDI.d.ts} +1 -1
- package/dist/{lightning-backend-9oky_wJi.d.ts → lightning-backend-BX5YvjnM.d.ts} +1 -1
- package/dist/memory-credit-ledger-DKCN7FY2.js +14 -0
- package/dist/{mpp-setup-FURD45LI.js → mpp-setup-JU3MT7QX.js} +3 -3
- package/dist/{payout-reporter-HVJ6WUF3.js → payout-reporter-NXWQVKXW.js} +2 -2
- package/dist/{postgres-consumed-credential-store-WO6OCFXZ.js → postgres-consumed-credential-store-WXJLM6J7.js} +1 -1
- package/dist/{postgres-job-store-H45PRBLA.js → postgres-job-store-WIIVRZPD.js} +2 -2
- package/dist/{postgres-replay-store-XXJSA457.js → postgres-replay-store-QJ4FG6AR.js} +2 -2
- package/dist/{pricing-X4XU5HXY.js → pricing-KCLENT2C.js} +3 -3
- package/dist/{revenue-reporter-EV3K5L6B.js → revenue-reporter-HD4GMXGD.js} +2 -2
- package/dist/server/index.d.ts +28 -12
- package/dist/server/index.js +31 -29
- package/dist/{step-cache--7yA5Ihr.d.ts → step-cache-d-VKen4K.d.ts} +147 -13
- package/dist/{tempo-charge-store-5JOIYUIH.js → tempo-charge-store-7LTUAQHQ.js} +2 -2
- package/dist/{tempo-session-store-S6QMLQUA.js → tempo-session-store-LYAIDR2B.js} +3 -3
- package/dist/testing/index.d.ts +3 -3
- package/dist/testing/index.js +6 -6
- package/dist/{usd-C7lvLvLk.d.ts → usd-DSroMJ--.d.ts} +1 -1
- package/dist/{x402-EN5LSOVM.js → x402-RUJ4LUKF.js} +3 -3
- package/package.json +1 -1
- package/recipes/postgres/financial-export-v1.sql +19 -5
- package/dist/memory-credit-ledger-RP7DT5IY.js +0 -11
|
@@ -1268,6 +1268,7 @@ declare class HostedSettlementReportObligations {
|
|
|
1268
1268
|
obligationId: string;
|
|
1269
1269
|
};
|
|
1270
1270
|
all?: boolean;
|
|
1271
|
+
channelId?: string;
|
|
1271
1272
|
}): Promise<{
|
|
1272
1273
|
id: string;
|
|
1273
1274
|
channelId: string;
|
|
@@ -1687,6 +1688,8 @@ interface FundingLot {
|
|
|
1687
1688
|
rail: NonChannelBitcoinRail;
|
|
1688
1689
|
/** Sats this funding delivered. `0` on a credit funded before a rail basis was recorded. */
|
|
1689
1690
|
satsFunded: number;
|
|
1691
|
+
/** Explicit original-asset evidence, including a refund whose integer share is zero sats. */
|
|
1692
|
+
satsBasisKnown?: boolean;
|
|
1690
1693
|
/** Credit micro this funding bought — the lot's denominator, never depleted. */
|
|
1691
1694
|
creditedMicro: number;
|
|
1692
1695
|
remainingMicro: number;
|
|
@@ -2356,6 +2359,20 @@ interface CreditDepositPayload {
|
|
|
2356
2359
|
*/
|
|
2357
2360
|
repaired?: boolean;
|
|
2358
2361
|
}
|
|
2362
|
+
/** Completed-draw reversal posted to /_internal/credit-draw-refund. */
|
|
2363
|
+
interface CreditDrawRefundPayload {
|
|
2364
|
+
dvmId: string;
|
|
2365
|
+
creditId: string;
|
|
2366
|
+
drawId: string;
|
|
2367
|
+
jobId: string;
|
|
2368
|
+
refundId: string;
|
|
2369
|
+
amountMicro: number;
|
|
2370
|
+
creditCurrency: string;
|
|
2371
|
+
ledgerSeq: number;
|
|
2372
|
+
refundedAt: number;
|
|
2373
|
+
reason?: string;
|
|
2374
|
+
}
|
|
2375
|
+
type CreditDrawRefundEnqueue = (tx: RevenueReporterQuerier, payload: CreditDrawRefundPayload) => Promise<void>;
|
|
2359
2376
|
/**
|
|
2360
2377
|
* JSON wire shape POSTed to the platform's `/_internal/credit-draw-release`
|
|
2361
2378
|
* endpoint. A released hold leaves the credit balance intact, but
|
|
@@ -2651,6 +2668,8 @@ declare class RevenueReporter {
|
|
|
2651
2668
|
* rail transaction commits, including after a process restart.
|
|
2652
2669
|
*/
|
|
2653
2670
|
enqueueDeposit(tx: RevenueReporterQuerier, payload: CreditDepositPayload): Promise<void>;
|
|
2671
|
+
/** Persist without network delivery before the refund accounting transaction commits. */
|
|
2672
|
+
enqueueCreditDrawRefund(tx: RevenueReporterQuerier, payload: CreditDrawRefundPayload): Promise<void>;
|
|
2654
2673
|
/** Join a released draw to the transaction that made the hold terminal. */
|
|
2655
2674
|
enqueueCreditDrawRelease(tx: RevenueReporterQuerier, payload: CreditDrawReleasePayload): Promise<void>;
|
|
2656
2675
|
/**
|
|
@@ -2738,6 +2757,40 @@ declare class RevenueReporter {
|
|
|
2738
2757
|
private markStale;
|
|
2739
2758
|
}
|
|
2740
2759
|
|
|
2760
|
+
type CreditDrawRefundArgs = {
|
|
2761
|
+
refundId: string;
|
|
2762
|
+
amountMicro?: number;
|
|
2763
|
+
reason?: string;
|
|
2764
|
+
outbox: {
|
|
2765
|
+
dvmId: string;
|
|
2766
|
+
enqueue: CreditDrawRefundEnqueue;
|
|
2767
|
+
};
|
|
2768
|
+
/** DVM receipt key from trusted server configuration, never from job content or the request. */
|
|
2769
|
+
trustedReceiptPubkey?: string;
|
|
2770
|
+
nowMs?: number;
|
|
2771
|
+
} & ({
|
|
2772
|
+
jobId: string;
|
|
2773
|
+
creditId?: never;
|
|
2774
|
+
drawId?: never;
|
|
2775
|
+
} | {
|
|
2776
|
+
creditId: string;
|
|
2777
|
+
drawId: string;
|
|
2778
|
+
jobId?: never;
|
|
2779
|
+
});
|
|
2780
|
+
interface CreditDrawRefundResult {
|
|
2781
|
+
refundId: string;
|
|
2782
|
+
creditId: string;
|
|
2783
|
+
drawId: string;
|
|
2784
|
+
jobId: string;
|
|
2785
|
+
amountMicro: number;
|
|
2786
|
+
currency: string;
|
|
2787
|
+
ledgerSeq: number;
|
|
2788
|
+
refundedAt: number;
|
|
2789
|
+
/** Persisted balance immediately after this refund, not a current balance read. */
|
|
2790
|
+
balanceAfterMicro: number;
|
|
2791
|
+
replayed: boolean;
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2741
2794
|
interface TempoSessionSettlementStore {
|
|
2742
2795
|
withDrawPlacement<value>(channelId: string, operation: (tx: CreditLedgerQuerier, lifecycle: TempoSessionLifecycle$1) => Promise<value>, tx?: CreditLedgerQuerier): Promise<value>;
|
|
2743
2796
|
withTerminalConsumption<value>(channelId: string, operation: (tx: CreditLedgerQuerier, lifecycle: TempoSessionLifecycle$1) => Promise<{
|
|
@@ -2759,6 +2812,9 @@ interface TempoCreditLossEvidence {
|
|
|
2759
2812
|
settledOnChainNative: bigint;
|
|
2760
2813
|
highestVoucherNative: bigint;
|
|
2761
2814
|
consumedNative: bigint;
|
|
2815
|
+
/** Exact same-close cooperative refund. Omission preserves the caller's loss assertion without proving zero. */
|
|
2816
|
+
refundedToPayerNative?: bigint;
|
|
2817
|
+
closeKind?: "cooperative_close" | "payer_exit";
|
|
2762
2818
|
observedAt?: number;
|
|
2763
2819
|
}
|
|
2764
2820
|
interface TempoCreditLoss {
|
|
@@ -2771,6 +2827,9 @@ interface TempoCreditLoss {
|
|
|
2771
2827
|
highestVoucherNative: bigint;
|
|
2772
2828
|
consumedServiceMicro: number;
|
|
2773
2829
|
consumedNative: bigint;
|
|
2830
|
+
refundedToPayerNative?: bigint | null;
|
|
2831
|
+
lossNative?: bigint | null;
|
|
2832
|
+
lossBasis?: "cooperative_close" | "payer_exit" | "caller_asserted" | null;
|
|
2774
2833
|
observedAt: number;
|
|
2775
2834
|
}
|
|
2776
2835
|
/** Chain-proven evidence that an x402 channel no longer backs its bound credit. */
|
|
@@ -2798,7 +2857,7 @@ interface X402CreditLoss {
|
|
|
2798
2857
|
*
|
|
2799
2858
|
* The ledger is host-wide: credit_id and caller_pubkey identify rows, without a per-mount
|
|
2800
2859
|
* dvm_id. Draws hold funds until settlement or release, and share a gap-free per-credit
|
|
2801
|
-
* ledger_seq with drains.
|
|
2860
|
+
* ledger_seq with drains and completed-draw refunds.
|
|
2802
2861
|
*/
|
|
2803
2862
|
declare class CreditLedger {
|
|
2804
2863
|
private readonly pool;
|
|
@@ -2808,6 +2867,7 @@ declare class CreditLedger {
|
|
|
2808
2867
|
* fleet, so this DVM may advertise credit.
|
|
2809
2868
|
*/
|
|
2810
2869
|
readonly durable = true;
|
|
2870
|
+
readonly tempoCreditLossEvidenceVersion = 1;
|
|
2811
2871
|
private x402Settlements?;
|
|
2812
2872
|
private expiryReleaseOutbox?;
|
|
2813
2873
|
private hostingCleanupFence?;
|
|
@@ -2964,6 +3024,8 @@ declare class CreditLedger {
|
|
|
2964
3024
|
tx?: CreditLedgerQuerier;
|
|
2965
3025
|
nowMs?: number;
|
|
2966
3026
|
}): Promise<GrownDrawResult>;
|
|
3027
|
+
/** Restore a completed draw and its report under one durable transaction. */
|
|
3028
|
+
refundDraw(args: CreditDrawRefundArgs): Promise<CreditDrawRefundResult>;
|
|
2967
3029
|
/**
|
|
2968
3030
|
* Finalize a pending draw: the hold becomes a real debit
|
|
2969
3031
|
* (`balance_micro −= amount`). Available balance is unchanged — the amount
|
|
@@ -3217,7 +3279,8 @@ declare class CreditLedger {
|
|
|
3217
3279
|
private terminalizeTempoCreditsLocked;
|
|
3218
3280
|
listTempoCreditLosses(args?: {
|
|
3219
3281
|
limit?: number;
|
|
3220
|
-
|
|
3282
|
+
channelId?: string;
|
|
3283
|
+
}, tx?: CreditLedgerQuerier): Promise<TempoCreditLoss[]>;
|
|
3221
3284
|
/**
|
|
3222
3285
|
* Reconcile the credit bound to a chain-proven empty x402 channel.
|
|
3223
3286
|
*
|
|
@@ -3284,8 +3347,8 @@ declare class CreditLedger {
|
|
|
3284
3347
|
*/
|
|
3285
3348
|
listPendingDrains(): Promise<CreditDrainRecord[]>;
|
|
3286
3349
|
/**
|
|
3287
|
-
* Page
|
|
3288
|
-
* age-bounded
|
|
3350
|
+
* Page held Tempo-channel drains by (created_at, credit_id, drain_id), optionally
|
|
3351
|
+
* age-bounded. Audit reads also include terminal operator decisions. Accept the legacy mpp stored method as well as
|
|
3289
3352
|
* tempo so pre-migration drains remain repairable. Use the compound key for both ordering
|
|
3290
3353
|
* and continuation.
|
|
3291
3354
|
*/
|
|
@@ -3295,6 +3358,7 @@ declare class CreditLedger {
|
|
|
3295
3358
|
createdBeforeMs: number;
|
|
3296
3359
|
rail: "tempo";
|
|
3297
3360
|
includeResolved?: boolean;
|
|
3361
|
+
includeWrittenOff?: boolean;
|
|
3298
3362
|
}): Promise<CreditDrainRecord[]>;
|
|
3299
3363
|
/**
|
|
3300
3364
|
* Record that an operator reviewed a floor-refused channel drain and is not
|
|
@@ -3334,18 +3398,39 @@ declare class CreditLedger {
|
|
|
3334
3398
|
drainId: string;
|
|
3335
3399
|
tx?: CreditLedgerQuerier;
|
|
3336
3400
|
}): Promise<DrainTransitionResult>;
|
|
3401
|
+
/** Retain an exact receipt-derived refund; a later missing/zero read cannot erase payment. */
|
|
3402
|
+
recordTempoDrainRefund(args: {
|
|
3403
|
+
creditId: string;
|
|
3404
|
+
drainId: string;
|
|
3405
|
+
refundedNative: string | bigint;
|
|
3406
|
+
}): Promise<void>;
|
|
3407
|
+
/** Retain trusted proof that some refund was paid, without claiming an exact amount. */
|
|
3408
|
+
recordTempoDrainPayment(args: {
|
|
3409
|
+
creditId: string;
|
|
3410
|
+
drainId: string;
|
|
3411
|
+
}): Promise<void>;
|
|
3412
|
+
private recordTempoDrainRefundEvidence;
|
|
3413
|
+
/** Record the latest established proof refusal without changing the held debit. */
|
|
3414
|
+
recordTempoDrainHold(args: {
|
|
3415
|
+
creditId: string;
|
|
3416
|
+
drainId: string;
|
|
3417
|
+
reason: TempoDrainHoldReason;
|
|
3418
|
+
}): Promise<void>;
|
|
3337
3419
|
/**
|
|
3338
|
-
*
|
|
3339
|
-
*
|
|
3340
|
-
*
|
|
3341
|
-
*
|
|
3420
|
+
* An operator attests a full off-path refund or restores the exact unpaid debit. The
|
|
3421
|
+
* channel lock precedes the credit and drain locks; automatic booking shares the drain
|
|
3422
|
+
* CAS, so only one terminal outcome can commit. No channel lifecycle state is reopened.
|
|
3423
|
+
* Direct callers own reporting: hosted booking must join the caller's drain outbox transaction.
|
|
3342
3424
|
*/
|
|
3425
|
+
decideTempoDrain(args: TempoDrainDecisionArgs): Promise<TempoDrainDecisionResult>;
|
|
3426
|
+
/** Restore an unpaid pending drain; operator decisions also admit exit_required. */
|
|
3343
3427
|
releaseDrain(args: {
|
|
3344
3428
|
creditId: string;
|
|
3345
3429
|
drainId: string;
|
|
3346
3430
|
tx?: CreditLedgerQuerier;
|
|
3347
3431
|
nowMs?: number;
|
|
3348
3432
|
}): Promise<DrainReleaseResult>;
|
|
3433
|
+
private releaseDrainLocked;
|
|
3349
3434
|
/**
|
|
3350
3435
|
* Attach the parked Cashu token to a pending drain (`pending → parked`).
|
|
3351
3436
|
* A single-statement CAS on `status = 'pending'` — no credit lock needed;
|
|
@@ -3475,6 +3560,8 @@ interface CreditLedgerLike {
|
|
|
3475
3560
|
* would get `credit_not_found`, so advertising credit there misadvertises.
|
|
3476
3561
|
*/
|
|
3477
3562
|
readonly durable: boolean;
|
|
3563
|
+
/** Close-aware loss arithmetic, truthful refund evidence, atomic mutation, and transaction-aware loss reads. */
|
|
3564
|
+
readonly tempoCreditLossEvidenceVersion?: 1;
|
|
3478
3565
|
/**
|
|
3479
3566
|
* Bind the durable x402 settlement state spending is gated on.
|
|
3480
3567
|
*
|
|
@@ -3550,6 +3637,7 @@ interface CreditLedgerLike {
|
|
|
3550
3637
|
tx?: CreditLedgerQuerier;
|
|
3551
3638
|
nowMs?: number;
|
|
3552
3639
|
}): Promise<GrownDrawResult>;
|
|
3640
|
+
refundDraw(args: CreditDrawRefundArgs): Promise<CreditDrawRefundResult>;
|
|
3553
3641
|
settle(args: {
|
|
3554
3642
|
creditId: string;
|
|
3555
3643
|
drawId: string;
|
|
@@ -3681,7 +3769,8 @@ interface CreditLedgerLike {
|
|
|
3681
3769
|
terminalizeTempoCredits(evidence: TempoCreditLossEvidence, tx?: CreditLedgerQuerier): Promise<TempoCreditLoss[]>;
|
|
3682
3770
|
listTempoCreditLosses(args?: {
|
|
3683
3771
|
limit?: number;
|
|
3684
|
-
|
|
3772
|
+
channelId?: string;
|
|
3773
|
+
}, tx?: CreditLedgerQuerier): Promise<TempoCreditLoss[]>;
|
|
3685
3774
|
terminalizeX402Credit(evidence: X402CreditLossEvidence, tx?: CreditLedgerQuerier): Promise<X402CreditLoss[]>;
|
|
3686
3775
|
listX402CreditLosses(args?: {
|
|
3687
3776
|
limit?: number;
|
|
@@ -3710,6 +3799,7 @@ interface CreditLedgerLike {
|
|
|
3710
3799
|
createdBeforeMs: number;
|
|
3711
3800
|
rail: "tempo";
|
|
3712
3801
|
includeResolved?: boolean;
|
|
3802
|
+
includeWrittenOff?: boolean;
|
|
3713
3803
|
}): Promise<CreditDrainRecord[]>;
|
|
3714
3804
|
writeOffDrain(args: {
|
|
3715
3805
|
creditId: string;
|
|
@@ -3722,6 +3812,21 @@ interface CreditLedgerLike {
|
|
|
3722
3812
|
drainId: string;
|
|
3723
3813
|
tx?: CreditLedgerQuerier;
|
|
3724
3814
|
}): Promise<void>;
|
|
3815
|
+
decideTempoDrain?(args: TempoDrainDecisionArgs): Promise<TempoDrainDecisionResult>;
|
|
3816
|
+
recordTempoDrainPayment?(args: {
|
|
3817
|
+
creditId: string;
|
|
3818
|
+
drainId: string;
|
|
3819
|
+
}): Promise<void>;
|
|
3820
|
+
recordTempoDrainRefund?(args: {
|
|
3821
|
+
creditId: string;
|
|
3822
|
+
drainId: string;
|
|
3823
|
+
refundedNative: string | bigint;
|
|
3824
|
+
}): Promise<void>;
|
|
3825
|
+
recordTempoDrainHold?(args: {
|
|
3826
|
+
creditId: string;
|
|
3827
|
+
drainId: string;
|
|
3828
|
+
reason: TempoDrainHoldReason;
|
|
3829
|
+
}): Promise<void>;
|
|
3725
3830
|
requireTempoDrainExit?(args: {
|
|
3726
3831
|
creditId: string;
|
|
3727
3832
|
drainId: string;
|
|
@@ -3900,6 +4005,29 @@ interface DrainFulfilment {
|
|
|
3900
4005
|
/** Lightning routing the sending wallet reported, where it reported any. */
|
|
3901
4006
|
routingFeeMsats: number | null;
|
|
3902
4007
|
}
|
|
4008
|
+
/** Latest established refund-proof refusal; transient read failures do not replace it. */
|
|
4009
|
+
type TempoDrainHoldReason = "close_history_unmatched" | "collateral_missing" | "close_evidence_missing" | "refund_short";
|
|
4010
|
+
/** Immutable full-refund attestation or unpaid-release decision, independent of chain proof. */
|
|
4011
|
+
interface TempoDrainDecision {
|
|
4012
|
+
source: "operator";
|
|
4013
|
+
decision: "book_refunded" | "release";
|
|
4014
|
+
reason: string;
|
|
4015
|
+
evidence?: string;
|
|
4016
|
+
decidedAt: number;
|
|
4017
|
+
}
|
|
4018
|
+
interface TempoDrainDecisionArgs {
|
|
4019
|
+
creditId: string;
|
|
4020
|
+
drainId: string;
|
|
4021
|
+
decision: TempoDrainDecision["decision"];
|
|
4022
|
+
reason: string;
|
|
4023
|
+
evidence?: string;
|
|
4024
|
+
nowMs?: number;
|
|
4025
|
+
tx?: CreditLedgerQuerier;
|
|
4026
|
+
}
|
|
4027
|
+
interface TempoDrainDecisionResult extends DrainReleaseResult {
|
|
4028
|
+
/** Effective new-draw availability, including channel lifecycle and expiry restrictions. */
|
|
4029
|
+
spendableMicro: number;
|
|
4030
|
+
}
|
|
3903
4031
|
/**
|
|
3904
4032
|
* One drain liability, camel-cased, joined with its credit's `currency` and
|
|
3905
4033
|
* `callerPubkey` so consumers (route, admin surface, batch job) never need a
|
|
@@ -3983,6 +4111,12 @@ interface CreditDrainRecord {
|
|
|
3983
4111
|
*/
|
|
3984
4112
|
writeOffNote: string | null;
|
|
3985
4113
|
writtenOffAt: number | null;
|
|
4114
|
+
operatorDecision?: TempoDrainDecision | null;
|
|
4115
|
+
holdReason?: TempoDrainHoldReason | null;
|
|
4116
|
+
/** Exact retained refund evidence; null/absent means unknown, not zero. */
|
|
4117
|
+
provenRefundNative?: string | null;
|
|
4118
|
+
/** Sticky proof that some refund was paid; false/absent does not prove zero. */
|
|
4119
|
+
refundPaymentProven?: boolean;
|
|
3986
4120
|
}
|
|
3987
4121
|
/**
|
|
3988
4122
|
* Keyset cursor for {@link CreditLedger.listChannelDrains} — the last row of
|
|
@@ -4056,7 +4190,7 @@ interface CreditSnapshot {
|
|
|
4056
4190
|
expired: boolean;
|
|
4057
4191
|
status: CreditStatus;
|
|
4058
4192
|
/**
|
|
4059
|
-
* High-water sequence shared by draw placements and
|
|
4193
|
+
* High-water sequence shared by draw placements, drains, and completed-draw refunds.
|
|
4060
4194
|
*/
|
|
4061
4195
|
lastLedgerSeq: number;
|
|
4062
4196
|
createdAt: number;
|
|
@@ -4081,7 +4215,7 @@ interface DrawResult {
|
|
|
4081
4215
|
*/
|
|
4082
4216
|
balanceAfterMicro: number;
|
|
4083
4217
|
/**
|
|
4084
|
-
* Per-credit gap-free sequence shared with drains; growth keeps the original value.
|
|
4218
|
+
* Per-credit gap-free sequence shared with drains and refunds; growth keeps the original value.
|
|
4085
4219
|
*/
|
|
4086
4220
|
ledgerSeq: number;
|
|
4087
4221
|
status: DrawStatus;
|
|
@@ -4355,7 +4489,7 @@ interface BlockedInvoiceCursor {
|
|
|
4355
4489
|
creditId: string;
|
|
4356
4490
|
fundId: string;
|
|
4357
4491
|
}
|
|
4358
|
-
type CreditLedgerErrorCode = "credit_not_found" | "credit_expired" | "credit_unbacked" | "tempo_channel_closing" | "tempo_settlement_pending" | "settlement_pending" | "insufficient_credit" | "draw_conflict" | "draw_not_found" | "invalid_draw_state" | "funding_replayed" | "currency_mismatch" | "caller_mismatch" | "rail_mismatch" | "invalid_amount" | "invalid_expiry" | "invalid_basis" | "nothing_to_drain" | "drain_below_dust" | "drain_not_found" | "drain_conflict" | "invalid_drain_state" | "invoice_not_found" | "invoice_conflict" | "invoice_not_blocked" | "below_rail_minimum";
|
|
4492
|
+
type CreditLedgerErrorCode = "credit_not_found" | "credit_expired" | "credit_unbacked" | "tempo_channel_closing" | "tempo_settlement_pending" | "settlement_pending" | "insufficient_credit" | "draw_conflict" | "invalid_refund" | "draw_not_completed" | "refund_conflict" | "refund_exceeds_draw" | "credit_not_open" | "credit_refund_channel_unsupported" | "credit_refund_basis_unavailable" | "credit_refund_state_unavailable" | "draw_not_found" | "invalid_draw_state" | "funding_replayed" | "currency_mismatch" | "caller_mismatch" | "rail_mismatch" | "invalid_amount" | "invalid_expiry" | "invalid_basis" | "nothing_to_drain" | "drain_below_dust" | "drain_not_found" | "drain_conflict" | "invalid_drain_state" | "tempo_drain_close_pending" | "tempo_drain_refund_paid" | "tempo_drain_refund_unknown" | "invalid_drain_decision" | "drain_not_repairable" | "drain_decision_conflict" | "invoice_not_found" | "invoice_conflict" | "invoice_not_blocked" | "below_rail_minimum";
|
|
4359
4493
|
/**
|
|
4360
4494
|
* Structured drain_conflict reasons select caller instructions without matching prose. A
|
|
4361
4495
|
* refund_floor shortfall needs operator resolution, unlike duplicate payout; foreign_credit
|
|
@@ -6029,4 +6163,4 @@ declare class StepCache {
|
|
|
6029
6163
|
static deserialize(records: StepRecord[]): StepCache;
|
|
6030
6164
|
}
|
|
6031
6165
|
|
|
6032
|
-
export { type FundingReceipt as $, type ApprovalContent as A, type SignedRequestDomain as B, type Currency as C, type DVMConfig as D, SignedRequestError as E, type SignedRequestFailure as F, type SignedRequestReplayStore as G, type SignedRequestSignOpts as H, type IncomingMessage as I, type JobCost as J, type KVStore as K, type Logger as L, type SignedRequestStatementHeader as M, type SignedRequestVerifier as N, createSignedRequestVerifier as O, type PaymentContent as P, type QuoteConfig as Q, type ResolvedCreditConfig as R, type SDKJobContext as S, isZodSchema as T, UnsupportedCurrencyError as U, signedRequestStatementHeader as V, validateCurrency as W, type JsonValue as X, X402_BATCH_SETTLEMENT_SCHEME as Y, type ZodLike as Z, X402_EXACT_SCHEME as _, type DVMDescriptor as a, isCompleteMessage as a$, type JobReceipt as a0, type MessageType as a1, type X402Version as a2, type MppxCredential as a3, type PaymentRequired as a4, type Message as a5, type MppxChallenge as a6, type ReceiptCredit as a7, type DrainReceipt as a8, type X402Wallet as a9, type UnsignedDrainReceipt as aA, type UnsignedFundingReceipt as aB, type UnsignedJobReceipt as aC, type VerifyResponse as aD, type WorkingContent as aE, type X402Config$1 as aF, type X402ResponseBody as aG, type X402SelfRelayRpcFailureReason as aH, X402_DEFAULT_NETWORK as aI, X402_V1_VERSION as aJ, X402_VERSION as aK, buildPaymentRequiredV2 as aL, buildPaymentRequirements as aM, caip2ToX402Network as aN, canonicalRequestPath as aO, canonicaliseForSigning as aP, canonicalize as aQ, chainIdFromCaip2 as aR, computeResultHash as aS, decodePayment as aT, decodePaymentRequiredHeader as aU, encodePayment as aV, encodePaymentRequiredHeader as aW, encodeSettleResponseHeader as aX, exactEvmAuthorization as aY, isArtifactMessage as aZ, isCancelMessage as a_, type PaymentRequirementsV1 as aa, type PaymentRequirementsV2 as ab, type BuildPaymentRequirementsOpts as ac, type CapabilityDescriptor as ad, type CashuMode as ae, type CompleteContent as af, type DrainReceiptEvent as ag, type ExactEvmPayload as ah, type ExactEvmPayloadAuthorization as ai, type FundingMethod as aj, type MessageFrom as ak, type PaymentPayload as al, type PaymentPayloadV1 as am, type PaymentPayloadV2 as an, type PaymentRequestContent as ao, type PaymentRequiredV2 as ap, type PaymentRequirements as aq, type PromptContent as ar, RAIL_REFUNDABLE as as, type ReceiptOutcome as at, type ReceiptPayment as au, type ResourceInfo as av, type SettleResponse as aw, StepCache as ax, type StepRecord as ay, type TextContent as az, type ArtifactContent as b, type
|
|
6166
|
+
export { type FundingReceipt as $, type ApprovalContent as A, type SignedRequestDomain as B, type Currency as C, type DVMConfig as D, SignedRequestError as E, type SignedRequestFailure as F, type SignedRequestReplayStore as G, type SignedRequestSignOpts as H, type IncomingMessage as I, type JobCost as J, type KVStore as K, type Logger as L, type SignedRequestStatementHeader as M, type SignedRequestVerifier as N, createSignedRequestVerifier as O, type PaymentContent as P, type QuoteConfig as Q, type ResolvedCreditConfig as R, type SDKJobContext as S, isZodSchema as T, UnsupportedCurrencyError as U, signedRequestStatementHeader as V, validateCurrency as W, type JsonValue as X, X402_BATCH_SETTLEMENT_SCHEME as Y, type ZodLike as Z, X402_EXACT_SCHEME as _, type DVMDescriptor as a, isCompleteMessage as a$, type JobReceipt as a0, type MessageType as a1, type X402Version as a2, type MppxCredential as a3, type PaymentRequired as a4, type Message as a5, type MppxChallenge as a6, type ReceiptCredit as a7, type DrainReceipt as a8, type X402Wallet as a9, type UnsignedDrainReceipt as aA, type UnsignedFundingReceipt as aB, type UnsignedJobReceipt as aC, type VerifyResponse as aD, type WorkingContent as aE, type X402Config$1 as aF, type X402ResponseBody as aG, type X402SelfRelayRpcFailureReason as aH, X402_DEFAULT_NETWORK as aI, X402_V1_VERSION as aJ, X402_VERSION as aK, buildPaymentRequiredV2 as aL, buildPaymentRequirements as aM, caip2ToX402Network as aN, canonicalRequestPath as aO, canonicaliseForSigning as aP, canonicalize as aQ, chainIdFromCaip2 as aR, computeResultHash as aS, decodePayment as aT, decodePaymentRequiredHeader as aU, encodePayment as aV, encodePaymentRequiredHeader as aW, encodeSettleResponseHeader as aX, exactEvmAuthorization as aY, isArtifactMessage as aZ, isCancelMessage as a_, type PaymentRequirementsV1 as aa, type PaymentRequirementsV2 as ab, type BuildPaymentRequirementsOpts as ac, type CapabilityDescriptor as ad, type CashuMode as ae, type CompleteContent as af, type DrainReceiptEvent as ag, type ExactEvmPayload as ah, type ExactEvmPayloadAuthorization as ai, type FundingMethod as aj, type MessageFrom as ak, type PaymentPayload as al, type PaymentPayloadV1 as am, type PaymentPayloadV2 as an, type PaymentRequestContent as ao, type PaymentRequiredV2 as ap, type PaymentRequirements as aq, type PromptContent as ar, RAIL_REFUNDABLE as as, type ReceiptOutcome as at, type ReceiptPayment as au, type ResourceInfo as av, type SettleResponse as aw, StepCache as ax, type StepRecord as ay, type TextContent as az, type ArtifactContent as b, type InvoiceSettlement as b$, isDrainReceipt as b0, isFundingReceipt as b1, isPaymentRequestMessage as b2, isPromptMessage as b3, isSignedJobReceipt as b4, isTextMessage as b5, isWorkingMessage as b6, paymentRequiredV2FromV1 as b7, signDrainReceipt as b8, signFundingReceipt as b9, type X402TrackedChannel as bA, _testing as bB, createDefaultReplayStore as bC, depleteLots as bD, fifoOrder as bE, inKindDrawMsats as bF, isInKindDepletion as bG, isNonChannelBitcoinRail as bH, lotOwedSats as bI, netOwedSats as bJ, wrapMppx as bK, type CreditLedgerQuerier as bL, type CreditDrainEnqueue as bM, HostedSettlementReportObligations as bN, type DVMAuthScheme as bO, type CreditLedgerLike as bP, type X402RefundSettlementGate as bQ, type CreditSnapshot as bR, type CreditDrawRefundArgs as bS, type CreditDrawRefundResult as bT, type DrawResult as bU, type X402SettlementStatus as bV, type X402UnresolvedRefund as bW, type GrownDrawResult as bX, type DrawResolution as bY, type FundingRecord as bZ, type CreditInvoiceRecord as b_, signReceipt as ba, usdcContractByCaip2 as bb, usdcContractFor as bc, usdcDomainNameFor as bd, usdcDomainVersionFor as be, verifyDrainReceipt as bf, verifyFundingReceipt as bg, verifyReceipt as bh, x402NetworkToCaip2 as bi, type X402ExactVersionSupport as bj, type X402Receipt as bk, type TransactionalPayoutHook as bl, type CashuMeltCompleted as bm, type CreditDepositPayload as bn, type CreditDrainPayload as bo, type FundingLot as bp, type LotDebit as bq, type LotDepletion as br, type MppxServer as bs, NON_CHANNEL_BITCOIN_RAILS as bt, type NonChannelBitcoinRail as bu, PayoutReporter as bv, PostgresTempoSessionStore as bw, RevenueReporter as bx, SIGNED_ENVELOPE_FIELDS as by, SIGNED_ENVELOPE_TYPES as bz, type CancelContent as c, retryHostedTempoCloseReport as c$, type BlockedInvoiceCursor as c0, type InvoiceReconciliation as c1, type InvoiceWriteOff as c2, type DrawRecord as c3, type StalePendingDrawCursor as c4, type TempoCreditLossEvidence as c5, type TempoCreditLoss as c6, type X402CreditLossEvidence as c7, type X402CreditLoss as c8, type DrainMethod as c9, type DrawRailValue as cA, type DrawStatus as cB, type HostedTempoCloseReportWriteOff as cC, type JobCostReportPayload as cD, type JobTerminalReportPayload as cE, PostgresX402ChannelStorage as cF, type ReplayStoreBackend as cG, type RevenueSkippedNoRailPayload as cH, type RevenueSkippedNoRailReason as cI, type Secp256k1AuthOpts as cJ, type TempoDrainDecision as cK, type TempoDrainDecisionArgs as cL, type TempoDrainDecisionResult as cM, type TempoDrainHoldReason as cN, type X402ChannelStorageOpts as cO, type X402RelayLockHolder as cP, type X402RelaySubmissionLock as cQ, X402RelaySubmissionLockError as cR, allocateDrawValue as cS, clientCompatibilityAttributes as cT, clientCompatibilityMiddleware as cU, clientUpgradeRequired as cV, parseClientCapabilities as cW, parseClientCompatibility as cX, parseDvmClient as cY, parseProtocolVersion as cZ, requireClientCompatibility as c_, type DrainRequestResult as ca, type BitcoinDepositLiability as cb, type CreditDrainRecord as cc, type ChannelDrainCursor as cd, type DrainWriteOff as ce, type DrainTransitionResult as cf, type DrainReleaseResult as cg, type DrainFulfilment as ch, HostingCleanupFence as ci, CLIENT_COMPATIBILITY_HEADERS as cj, type ClientCompatibility as ck, type ClientCompatibilityEnv as cl, type ClientCompatibilityGate as cm, type ClientCompatibilityRequirement as cn, type ClientSemVer as co, type CreditFundingBasis as cp, type CreditInvoiceStatus as cq, CreditLedger as cr, CreditLedgerError as cs, type CreditLedgerErrorCode as ct, type CreditLedgerErrorDetails as cu, type CreditLedgerPool as cv, type CreditStatus as cw, DRAIN_DELIVERY_RESERVE_SATS as cx, DVM_PROTOCOL_VERSION as cy, type DrainConflictReason as cz, type CanonicalEnvelope as d, secp256k1Auth as d0, signedRequestInput as d1, writeOffHostedTempoCloseReport as d2, type HostedIntent as d3, type X402SettlementIntent as d4, type HostedFundingReservation as d5, type X402SettlementCursor as d6, type X402SettlementWriteOff as d7, type X402FacilitatorAuth as d8, type X402BatchSettlementConfig as d9, type X402PayoutObserver as da, type CreditDepositEnqueue as db, type X402SettlementReconciliationReason as dc, type CreditDrawReleaseEnqueue as dd, type CapabilityRate as e, type CreateSignedRequestVerifierOpts as f, type CreditConfig as g, type CreditView as h, DEFAULT_CREDIT_MAX as i, DEFAULT_CREDIT_MIN as j, DEFAULT_CREDIT_TTL_SECONDS as k, DEFAULT_JOB_RETENTION_DAYS as l, type DVMRouteContext as m, type InputType as n, InvalidCurrencyError as o, type PaymentMethod as p, type PriceValue as q, type ProgressContent as r, type PromptOpts as s, type QuoteContext as t, type QuoteResult as u, type ResponseContent as v, type SDKPaymentRequestOpts as w, SIGNED_REQUEST_AUTH_ID as x, SIGNED_REQUEST_STATEMENT_VERSION as y, type SignedRequestAudience as z };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PostgresTempoChargeStore
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FFRTAQUW.js";
|
|
4
4
|
import "./chunk-YG7G4DPZ.js";
|
|
5
5
|
import "./chunk-COYKJRMM.js";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-Z4FOPROB.js";
|
|
7
7
|
export {
|
|
8
8
|
PostgresTempoChargeStore
|
|
9
9
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PostgresTempoSessionStore,
|
|
3
3
|
assertMonotonicTransition
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NS2OMIU7.js";
|
|
5
5
|
import "./chunk-YG7G4DPZ.js";
|
|
6
6
|
import "./chunk-COYKJRMM.js";
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-EP7OVWI5.js";
|
|
8
|
+
import "./chunk-Z4FOPROB.js";
|
|
9
9
|
export {
|
|
10
10
|
PostgresTempoSessionStore,
|
|
11
11
|
assertMonotonicTransition
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as ContentHoldHistory, a as ContentHoldMutation } from '../content-retention-
|
|
2
|
-
import { a0 as JobReceipt, a5 as Message, a1 as MessageType, K as KVStore, L as Logger, v as ResponseContent, P as PaymentContent, S as SDKJobContext } from '../step-cache
|
|
3
|
-
import { c as StreamableJobStore, R as ReceiptIssuingStore, J as JobRecord, d as RequestIdClaim, e as RequestIdClaimResult, f as JobRetentionCursor, O as OutgoingMessage, A as AppendOutgoingOptions, P as PaymentCreditDelta, V as VerifyAndCreditResult, g as JobCounters } from '../job-store-
|
|
1
|
+
import { C as ContentHoldHistory, a as ContentHoldMutation } from '../content-retention-ySTD1wwZ.js';
|
|
2
|
+
import { a0 as JobReceipt, a5 as Message, a1 as MessageType, K as KVStore, L as Logger, v as ResponseContent, P as PaymentContent, S as SDKJobContext } from '../step-cache-d-VKen4K.js';
|
|
3
|
+
import { c as StreamableJobStore, R as ReceiptIssuingStore, J as JobRecord, d as RequestIdClaim, e as RequestIdClaimResult, f as JobRetentionCursor, O as OutgoingMessage, A as AppendOutgoingOptions, P as PaymentCreditDelta, V as VerifyAndCreditResult, g as JobCounters } from '../job-store-DRwXCJDI.js';
|
|
4
4
|
import 'hono';
|
|
5
5
|
import 'mppx';
|
|
6
6
|
import '@x402/core/server';
|
package/dist/testing/index.js
CHANGED
|
@@ -4,22 +4,22 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
MemoryJobStore,
|
|
6
6
|
createInstrumentedFetch
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-KJZVTWMX.js";
|
|
8
8
|
import {
|
|
9
9
|
JobCancelledError
|
|
10
10
|
} from "../chunk-AFV77S4C.js";
|
|
11
11
|
import {
|
|
12
12
|
createNoopLogger
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-7KQLPVV7.js";
|
|
14
14
|
import "../chunk-FUJ36YDV.js";
|
|
15
15
|
import "../chunk-BQJIFRAZ.js";
|
|
16
|
-
import "../chunk-
|
|
16
|
+
import "../chunk-D4FFS3IS.js";
|
|
17
17
|
import {
|
|
18
18
|
validateCurrency
|
|
19
|
-
} from "../chunk-
|
|
20
|
-
import "../chunk-
|
|
19
|
+
} from "../chunk-LDKV4UHI.js";
|
|
20
|
+
import "../chunk-HNXMWHLU.js";
|
|
21
21
|
import "../chunk-66HGCPBU.js";
|
|
22
|
-
import "../chunk-
|
|
22
|
+
import "../chunk-Z4FOPROB.js";
|
|
23
23
|
|
|
24
24
|
// src/sdk/testing/test-context.ts
|
|
25
25
|
function createTestContext(opts) {
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
} from "./chunk-WMGXJQI3.js";
|
|
7
7
|
import {
|
|
8
8
|
verifyX402Payment
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-3YFFZLW7.js";
|
|
10
|
+
import "./chunk-E7ZBCT5U.js";
|
|
11
11
|
import {
|
|
12
12
|
X402_DEFAULT_FACILITATOR,
|
|
13
13
|
X402_DEFAULT_NETWORK,
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
x402SupportedNetworksHint
|
|
38
38
|
} from "./chunk-BPYMEMQX.js";
|
|
39
39
|
import "./chunk-66HGCPBU.js";
|
|
40
|
-
import "./chunk-
|
|
40
|
+
import "./chunk-Z4FOPROB.js";
|
|
41
41
|
export {
|
|
42
42
|
X402_DEFAULT_FACILITATOR,
|
|
43
43
|
X402_DEFAULT_NETWORK,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dvmkit/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0-rc.1",
|
|
4
4
|
"description": "SDK for building Digital Vending Machines: pay-per-use HTTPS services AI agents can find, pay, and call with no account or API key",
|
|
5
5
|
"author": "DVM Technologies Ltd",
|
|
6
6
|
"keywords": [
|
|
@@ -50,6 +50,15 @@ CREATE OR REPLACE FUNCTION pg_temp.scalars_v1(value jsonb, strings text[], numbe
|
|
|
50
50
|
OR (key=ANY(numbers) AND (jsonb_typeof(val) IN ('number','null') OR (jsonb_typeof(val)='string' AND val #>> '{}' ~ '^-?[0-9]+$')))
|
|
51
51
|
OR (key=ANY(booleans) AND jsonb_typeof(val) IN ('boolean','null'))) END
|
|
52
52
|
$$;
|
|
53
|
+
CREATE OR REPLACE FUNCTION pg_temp.draw_refund_result_v1(value jsonb) RETURNS jsonb LANGUAGE sql IMMUTABLE AS $$
|
|
54
|
+
SELECT pg_temp.scalars_v1(value, ARRAY['refundId','creditId','drawId','jobId','currency'],
|
|
55
|
+
ARRAY['amountMicro','ledgerSeq','refundedAt','balanceAfterMicro'])
|
|
56
|
+
$$;
|
|
57
|
+
CREATE OR REPLACE FUNCTION pg_temp.drain_decision_v1(value jsonb) RETURNS jsonb LANGUAGE sql IMMUTABLE AS $$
|
|
58
|
+
SELECT pg_temp.scalars_v1(value, ARRAY[]::text[], ARRAY['decidedAt'])
|
|
59
|
+
|| CASE WHEN value->>'source'='operator' THEN jsonb_build_object('source','operator') ELSE '{}'::jsonb END
|
|
60
|
+
|| CASE WHEN value->>'decision' IN ('book_refunded','release') THEN jsonb_build_object('decision',value->'decision') ELSE '{}'::jsonb END
|
|
61
|
+
$$;
|
|
53
62
|
CREATE OR REPLACE FUNCTION pg_temp.settlement_v1(value jsonb) RETURNS jsonb LANGUAGE sql IMMUTABLE AS $$
|
|
54
63
|
SELECT pg_temp.scalars_v1(value,
|
|
55
64
|
ARRAY['tx_hash','transaction','channel_id','network','repair_kind','payer'],
|
|
@@ -100,6 +109,10 @@ BEGIN
|
|
|
100
109
|
EXECUTE format('SELECT COALESCE(jsonb_agg(projected ORDER BY projected::text), ''[]''::jsonb) FROM (
|
|
101
110
|
SELECT (SELECT COALESCE(jsonb_object_agg(key,
|
|
102
111
|
CASE WHEN key=ANY(ARRAY[''sent_ref'',''settle_response'']) THEN pg_temp.settlement_v1(value)
|
|
112
|
+
WHEN key=ANY(ARRAY[''proven_refund_native'',''refunded_to_payer_native'',''loss_native'']) THEN CASE WHEN value #>> ''{}'' ~ ''^[0-9]+$'' THEN to_jsonb(value #>> ''{}'') ELSE NULL END
|
|
113
|
+
WHEN key=''loss_basis'' THEN CASE WHEN value #>> ''{}'' IN (''cooperative_close'',''payer_exit'',''caller_asserted'') THEN value ELSE NULL END
|
|
114
|
+
WHEN key=''operator_decision'' THEN pg_temp.drain_decision_v1(value)
|
|
115
|
+
WHEN key=''result'' THEN pg_temp.draw_refund_result_v1(value)
|
|
103
116
|
WHEN key=''fulfilment'' THEN pg_temp.fulfilment_v1(value)
|
|
104
117
|
WHEN key=''lot_debits'' THEN pg_temp.lot_debits_v1(value)
|
|
105
118
|
WHEN key=''state_json'' THEN pg_temp.tempo_state_v1(value)
|
|
@@ -117,11 +130,12 @@ BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY;
|
|
|
117
130
|
SELECT jsonb_build_object(
|
|
118
131
|
'format', 'dvmkit-financial-evidence', 'version', 1,
|
|
119
132
|
'jobs', pg_temp.financial_rows_v1('jobs', ARRAY['id','dvm_id','request_id','requester_pubkey','capability','status','created_at','last_activity_at','terminal_at_ms','ended_by','receipt','receipt_seq','paid_msats','payment_rail','payment_tx_hash','payment_transaction_hash','native_amount','native_asset','credit_id','draw_id','cost_amount_micro','cost_currency']),
|
|
120
|
-
'credits', pg_temp.financial_rows_v1('credits', ARRAY['credit_id','caller_pubkey','currency','balance_micro','expiry_ms','status','last_ledger_seq','created_at','rail','native_asset','funding_ref','tempo_channel_id','x402_channel_id','msats_remaining','native_remaining']),
|
|
133
|
+
'credits', pg_temp.financial_rows_v1('credits', ARRAY['credit_id','caller_pubkey','currency','balance_micro','expiry_ms','status','last_ledger_seq','last_funding_ledger_seq','created_at','rail','native_asset','funding_ref','tempo_channel_id','x402_channel_id','msats_remaining','native_remaining']),
|
|
121
134
|
'fundings', pg_temp.financial_rows_v1('credit_fundings', ARRAY['credit_id','fund_id','caller_pubkey','amount_micro','rail','created_at','balance_after_micro','ledger_seq','receipt']),
|
|
122
|
-
'funding_lots', pg_temp.financial_rows_v1('credit_funding_lots', ARRAY['lot_id','credit_id','rail','sats_funded','credited_micro','remaining_micro','funding_ref','created_at']),
|
|
123
|
-
'draws', pg_temp.financial_rows_v1('credit_draws', ARRAY['credit_id','draw_id','job_id','amount_micro','ledger_seq','status','balance_after_micro','created_at','resolved_at','draw_msats','allocated_msats','draw_native','grown_micro']),
|
|
124
|
-
'
|
|
135
|
+
'funding_lots', pg_temp.financial_rows_v1('credit_funding_lots', ARRAY['lot_id','credit_id','rail','sats_funded','sats_basis_known','credited_micro','remaining_micro','funding_ref','created_at']),
|
|
136
|
+
'draws', pg_temp.financial_rows_v1('credit_draws', ARRAY['credit_id','draw_id','job_id','amount_micro','ledger_seq','status','balance_after_micro','created_at','resolved_at','draw_msats','allocated_msats','settled_sats','refund_dvm_id','draw_native','grown_micro']),
|
|
137
|
+
'draw_refunds', pg_temp.financial_rows_v1('credit_draw_refunds', ARRAY['refund_id','credit_id','draw_id','amount_micro','restored_sats','result']),
|
|
138
|
+
'drains', pg_temp.financial_rows_v1('credit_drains', ARRAY['credit_id','drain_id','method','amount_micro','balance_after_micro','drained_msats','drained_native','owed_sats','ledger_seq','status','receipts','sent_ref','fulfilment','lot_debits','created_at','parked_at','picked_up_at','sent_at','released_at','written_off_at','operator_decision','hold_reason','proven_refund_native','refund_payment_proven']),
|
|
125
139
|
'invoices', pg_temp.financial_rows_v1('credit_invoices', ARRAY['credit_id','fund_id','caller_pubkey','currency','amount_micro','amount_msats','payment_hash','status','expires_at','created_at','settled_at','reconciled_credit_id','reconciled_fund_id','resolved_at']),
|
|
126
140
|
'expiry_releases', pg_temp.financial_rows_v1('credit_expiry_releases', ARRAY['credit_id','release_id','caller_pubkey','currency','rail','amount_micro','expiry_ms','released_at','reversed_at']),
|
|
127
141
|
'tempo_channels', pg_temp.financial_rows_v1('mpp_tempo_channels', ARRAY['channel_key','state_json','updated_at']),
|
|
@@ -131,7 +145,7 @@ SELECT jsonb_build_object(
|
|
|
131
145
|
'x402_channel_tombstones', pg_temp.financial_rows_v1('x402_batch_channel_tombstones', ARRAY['channel_id','charged_cumulative_amount','signed_max_claimable','refund_nonce','deleted_at_ms']),
|
|
132
146
|
'x402_batch_settlements', pg_temp.financial_rows_v1('x402_batch_settlements', ARRAY['settlement_id','channel_id','operation','effect_id','payment_id','status','submission_block','settle_response','created_at','updated_at','resolved_at']),
|
|
133
147
|
'x402_exact_settlements', pg_temp.financial_rows_v1('x402_exact_settlement_intents', ARRAY['dvm_id','intent_id','network','asset','authorizer','recipient','value','status','effect','submission_block','transaction','settle_response','last_outcome','created_at','updated_at','resolved_at']),
|
|
134
|
-
'tempo_losses', pg_temp.financial_rows_v1('tempo_credit_losses', ARRAY['credit_id','channel_id','caller_pubkey','currency','former_balance_micro','settled_on_chain_native','highest_voucher_native','consumed_service_micro','consumed_native','observed_at']),
|
|
148
|
+
'tempo_losses', pg_temp.financial_rows_v1('tempo_credit_losses', ARRAY['credit_id','channel_id','caller_pubkey','currency','former_balance_micro','settled_on_chain_native','highest_voucher_native','consumed_service_micro','consumed_native','observed_at','refunded_to_payer_native','loss_native','loss_basis']),
|
|
135
149
|
'x402_losses', pg_temp.financial_rows_v1('x402_credit_losses', ARRAY['credit_id','channel_id','caller_pubkey','currency','former_balance_micro','channel_balance_native','total_claimed_native','consumed_service_micro','observed_at'])
|
|
136
150
|
);
|
|
137
151
|
ROLLBACK;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MemoryCreditLedger
|
|
3
|
-
} from "./chunk-YOSZIWC3.js";
|
|
4
|
-
import "./chunk-STJBBVNL.js";
|
|
5
|
-
import "./chunk-COYKJRMM.js";
|
|
6
|
-
import "./chunk-MMGSYMIC.js";
|
|
7
|
-
import "./chunk-BPYMEMQX.js";
|
|
8
|
-
import "./chunk-QGNXYVBO.js";
|
|
9
|
-
export {
|
|
10
|
-
MemoryCreditLedger
|
|
11
|
-
};
|