@zkp2p/cash 0.2.0 → 0.3.0-rc.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 +21 -3
- package/README.md +51 -5
- package/dist/{chunk-TR6JVYYF.js → chunk-5VBP3IWK.js} +59 -2
- package/dist/{createCashClient-CTEXn9FF.d.cts → createCashClient-DGMd8Swr.d.cts} +50 -19
- package/dist/{createCashClient-CTEXn9FF.d.ts → createCashClient-DGMd8Swr.d.ts} +50 -19
- package/dist/index.cjs +243 -38
- package/dist/index.d.cts +18 -10
- package/dist/index.d.ts +18 -10
- package/dist/index.js +186 -40
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +1 -1
- package/dist/tools.cjs +26 -10
- package/dist/tools.d.cts +29 -10
- package/dist/tools.d.ts +29 -10
- package/dist/tools.js +26 -10
- package/docs/lifecycle-and-recovery.md +8 -2
- package/llms.txt +5 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as IntentStatus, C as CashPayoutInfo, a as IntentEntity, b as CashBuyerProfile, c as CashDepositInput, d as CreateDepositParamsArg, e as CashOrder, f as CashFill, g as CashCapabilities, h as CashoutResult, i as CashEstimate, j as CashFillStats, P as PrepareResult, k as CashPreparedStep, R as RelayExecutionResult, l as RelayQuote, m as RelayStatus, n as CashSourceCapabilities, T as TopUpResult, W as WithdrawResult } from './createCashClient-
|
|
2
|
-
export { o as CASH_ATTRIBUTION_CODE, p as CashAsset, q as CashChain, r as CashClient, s as CashClientOptions, t as CashFillEta, u as CashLeg, v as
|
|
1
|
+
import { I as IntentStatus, C as CashPayoutInfo, a as IntentEntity, b as CashBuyerProfile, c as CashDepositInput, d as CreateDepositParamsArg, e as CashOrder, f as CashFill, g as CashCapabilities, h as CashoutResult, i as CashEstimate, j as CashFillStats, P as PrepareResult, k as CashPreparedStep, R as RelayExecutionResult, l as RelayQuote, m as RelayStatus, n as CashSourceCapabilities, T as TopUpResult, W as WithdrawResult } from './createCashClient-DGMd8Swr.js';
|
|
2
|
+
export { o as CASH_ATTRIBUTION_CODE, p as CashAsset, q as CashChain, r as CashClient, s as CashClientOptions, t as CashFillEta, u as CashLeg, v as CashMultiCurrencyLeg, w as CashNextAction, x as CashOrderState, y as CashPairFillStats, z as CashPayeeInput, A as CashPayout, B as CashPayoutPricing, D as CashPlatformCapability, E as CashPreparedStepKind, F as CashoutInput, G as CashoutOptions, H as CuratorPayeeDataInput, J as EstimateInput, K as EstimateOptions, M as MIN_CASHOUT_AMOUNT, O as OrdersOptions, L as PreparedCashoutReceipt, N as RECOMMENDED_MIN_CASHOUT_AMOUNT, Q as RelayOptions, S as RelayQuoteInput, U as RelaySourceInput, V as RelayTransaction, X as SignerOptions, Y as WatchOptions, Z as WithdrawOptions, _ as buildCapabilities, $ as createCashClient, a0 as normalizeCashPayee } from './createCashClient-DGMd8Swr.js';
|
|
3
3
|
import { PaymentMethodCatalog, CurrencyType, OracleAdapterOverrides, OnchainCurrency, Zkp2pClient, PreparedTransaction } from '@zkp2p/sdk';
|
|
4
4
|
export { CurrencyType, PreparedTransaction, RuntimeEnv } from '@zkp2p/sdk';
|
|
5
5
|
import { Log, Abi } from 'viem';
|
|
@@ -10,7 +10,7 @@ import '@relayprotocol/relay-sdk';
|
|
|
10
10
|
* Typed errors - every failure carries a `code`, whether it is `retryable`,
|
|
11
11
|
* and a `remediation` sentence so agents can self-drive recovery.
|
|
12
12
|
*/
|
|
13
|
-
type CashErrorCode = 'ORACLE_UNSUPPORTED_CURRENCY' | 'ORACLE_READ_FAILED' | 'UNSUPPORTED_PLATFORM' | 'UNSUPPORTED_PLATFORM_CURRENCY' | 'AMOUNT_BELOW_MINIMUM' | 'INVALID_INTENT_AMOUNT_RANGE' | 'ACTIVE_INTENT_BLOCKS_WITHDRAWAL' | 'NOTHING_TO_WITHDRAW' | 'INSUFFICIENT_AVAILABLE_FUNDS' | 'INSUFFICIENT_TOKEN_BALANCE' | 'ORDER_NOT_ACTIVE' | 'INVALID_DEPOSIT_ID' | 'ESCROW_PAUSED' | 'INDEXER_LAG' | 'INDEXER_UNAVAILABLE' | 'ORDER_NOT_FOUND' | 'PAYEE_REGISTRATION_FAILED' | 'PAYEE_VERIFICATION_REQUIRED' | 'SOURCE_ROUTE_UNSUPPORTED_IN_PREPARE' | 'SOURCE_RECIPIENT_MISMATCH' | 'SOURCE_CAPABILITIES_FAILED' | 'SOURCE_QUOTE_FAILED' | 'SOURCE_NONCE_MANAGER_REQUIRED' | 'SOURCE_EXECUTION_FAILED' | 'SOURCE_STATUS_FAILED' | 'SOURCE_ROUTE_COMPLETED_CASHOUT_FAILED' | 'SOURCE_CASHOUT_SUBMISSION_UNKNOWN' | 'SOURCE_CASHOUT_STATUS_UNKNOWN' | 'DEPOSIT_RESOLUTION_FAILED' | 'ALLOWANCE_NOT_VISIBLE' | 'SIGNER_REQUIRED' | 'SIGNER_CHAIN_MISMATCH' | 'SIGNER_CHAIN_UNAVAILABLE' | 'WATCH_TIMEOUT' | 'TRANSACTION_FAILED' | 'TRANSACTION_SUBMISSION_UNKNOWN' | 'TRANSACTION_STATUS_UNKNOWN';
|
|
13
|
+
type CashErrorCode = 'ORACLE_UNSUPPORTED_CURRENCY' | 'ORACLE_READ_FAILED' | 'UNSUPPORTED_PLATFORM' | 'UNSUPPORTED_PLATFORM_CURRENCY' | 'AMOUNT_BELOW_MINIMUM' | 'INVALID_INTENT_AMOUNT_RANGE' | 'INVALID_PAYOUT_CURRENCIES' | 'ACTIVE_INTENT_BLOCKS_WITHDRAWAL' | 'NOTHING_TO_WITHDRAW' | 'INSUFFICIENT_AVAILABLE_FUNDS' | 'INSUFFICIENT_TOKEN_BALANCE' | 'ORDER_NOT_ACTIVE' | 'INVALID_DEPOSIT_ID' | 'ESCROW_PAUSED' | 'INDEXER_LAG' | 'INDEXER_UNAVAILABLE' | 'ORDER_NOT_FOUND' | 'PAYEE_REGISTRATION_FAILED' | 'PAYEE_VERIFICATION_REQUIRED' | 'SOURCE_ROUTE_UNSUPPORTED_IN_PREPARE' | 'SOURCE_RECIPIENT_MISMATCH' | 'SOURCE_CAPABILITIES_FAILED' | 'SOURCE_QUOTE_FAILED' | 'SOURCE_NONCE_MANAGER_REQUIRED' | 'SOURCE_EXECUTION_FAILED' | 'SOURCE_STATUS_FAILED' | 'SOURCE_ROUTE_COMPLETED_CASHOUT_FAILED' | 'SOURCE_CASHOUT_SUBMISSION_UNKNOWN' | 'SOURCE_CASHOUT_STATUS_UNKNOWN' | 'DEPOSIT_RESOLUTION_FAILED' | 'ALLOWANCE_NOT_VISIBLE' | 'SIGNER_REQUIRED' | 'SIGNER_CHAIN_MISMATCH' | 'SIGNER_CHAIN_UNAVAILABLE' | 'WATCH_TIMEOUT' | 'TRANSACTION_REJECTED' | 'TRANSACTION_FAILED' | 'TRANSACTION_SUBMISSION_UNKNOWN' | 'TRANSACTION_STATUS_UNKNOWN';
|
|
14
14
|
interface CashErrorShape {
|
|
15
15
|
code: CashErrorCode;
|
|
16
16
|
message: string;
|
|
@@ -77,6 +77,7 @@ declare const errors: {
|
|
|
77
77
|
unsupportedPlatformCurrency: (platform: string, currency: string) => CashError;
|
|
78
78
|
amountBelowMinimum: (amount: bigint, min: bigint) => CashError;
|
|
79
79
|
invalidIntentAmountRange: (amount: bigint, min: bigint, max: bigint) => CashError;
|
|
80
|
+
invalidPayoutCurrencies: (platform: string, reason: string) => CashError;
|
|
80
81
|
activeIntentBlocksWithdrawal: (depositId: string) => CashError;
|
|
81
82
|
insufficientAvailableFunds: (depositId: string, requested: bigint, available: bigint) => CashError;
|
|
82
83
|
insufficientTokenBalance: (requiredAmount?: bigint) => CashError;
|
|
@@ -124,12 +125,15 @@ declare const errors: {
|
|
|
124
125
|
signerChainUnavailable: (verb: string, expectedChainId: number, cause?: unknown) => CashError;
|
|
125
126
|
watchTimeout: (depositId: string, timeoutMs: number) => CashError;
|
|
126
127
|
transactionFailed: (txHash: string, cause?: unknown) => CashError;
|
|
128
|
+
transactionRejected: (verb: string, cause?: unknown) => CashError;
|
|
127
129
|
transactionSubmissionUnknown: (operation: string, cause?: unknown, recovery?: CashErrorRecovery) => CashError;
|
|
128
130
|
transactionStatusUnknown: (txHash: string, cause?: unknown, operation?: string) => CashError;
|
|
129
131
|
escrowPaused: () => CashError;
|
|
130
132
|
/** Generic fallback for an on-chain call that failed for an unrecognized reason. */
|
|
131
133
|
chainCallFailed: (verb: string, cause?: unknown) => CashError;
|
|
132
134
|
};
|
|
135
|
+
/** Detect EIP-1193 and viem wallet cancellations, including nested provider causes. */
|
|
136
|
+
declare function isUserRejectedError(value: unknown): boolean;
|
|
133
137
|
|
|
134
138
|
/**
|
|
135
139
|
* Convert a human USDC amount to base units (6 decimals).
|
|
@@ -325,10 +329,14 @@ interface ResolvedCashDeposit {
|
|
|
325
329
|
onchainDepositId: bigint;
|
|
326
330
|
escrowAddress: string;
|
|
327
331
|
compositeId: string;
|
|
332
|
+
/** Base-unit amount emitted by the canonical DepositReceived event. */
|
|
333
|
+
amount?: bigint;
|
|
328
334
|
}
|
|
329
335
|
declare function resolveCashDepositId(params: {
|
|
330
|
-
logs: Log[];
|
|
336
|
+
logs: readonly Log[];
|
|
331
337
|
abi: Abi;
|
|
338
|
+
expectedEscrowAddress?: string;
|
|
339
|
+
expectedToken?: string;
|
|
332
340
|
}): ResolvedCashDeposit | null;
|
|
333
341
|
/** Split a composite deposit id (`escrow_onchainId`) back into its parts. */
|
|
334
342
|
declare function parseCompositeDepositId(compositeId: string): {
|
|
@@ -2710,8 +2718,8 @@ declare const cashCapabilitiesJsonSchema: z.ZodObject<{
|
|
|
2710
2718
|
decimals: number;
|
|
2711
2719
|
};
|
|
2712
2720
|
};
|
|
2713
|
-
environment: "production" | "preproduction" | "staging";
|
|
2714
2721
|
currencies: string[];
|
|
2722
|
+
environment: "production" | "preproduction" | "staging";
|
|
2715
2723
|
platforms: {
|
|
2716
2724
|
platform: string;
|
|
2717
2725
|
currencies: string[];
|
|
@@ -2781,8 +2789,8 @@ declare const cashCapabilitiesJsonSchema: z.ZodObject<{
|
|
|
2781
2789
|
decimals: number;
|
|
2782
2790
|
};
|
|
2783
2791
|
};
|
|
2784
|
-
environment: "production" | "preproduction" | "staging";
|
|
2785
2792
|
currencies: string[];
|
|
2793
|
+
environment: "production" | "preproduction" | "staging";
|
|
2786
2794
|
platforms: {
|
|
2787
2795
|
platform: string;
|
|
2788
2796
|
currencies: string[];
|
|
@@ -3176,7 +3184,7 @@ declare const cashErrorRecoveryJsonSchema: z.ZodDiscriminatedUnion<"kind", [z.Zo
|
|
|
3176
3184
|
operation: string;
|
|
3177
3185
|
}>]>;
|
|
3178
3186
|
declare const cashErrorJsonSchema: z.ZodObject<{
|
|
3179
|
-
code: z.ZodEnum<["ORACLE_UNSUPPORTED_CURRENCY", "ORACLE_READ_FAILED", "UNSUPPORTED_PLATFORM", "UNSUPPORTED_PLATFORM_CURRENCY", "AMOUNT_BELOW_MINIMUM", "INVALID_INTENT_AMOUNT_RANGE", "ACTIVE_INTENT_BLOCKS_WITHDRAWAL", "NOTHING_TO_WITHDRAW", "INSUFFICIENT_AVAILABLE_FUNDS", "INSUFFICIENT_TOKEN_BALANCE", "ORDER_NOT_ACTIVE", "INVALID_DEPOSIT_ID", "ESCROW_PAUSED", "INDEXER_LAG", "INDEXER_UNAVAILABLE", "ORDER_NOT_FOUND", "PAYEE_REGISTRATION_FAILED", "PAYEE_VERIFICATION_REQUIRED", "SOURCE_ROUTE_UNSUPPORTED_IN_PREPARE", "SOURCE_RECIPIENT_MISMATCH", "SOURCE_CAPABILITIES_FAILED", "SOURCE_QUOTE_FAILED", "SOURCE_NONCE_MANAGER_REQUIRED", "SOURCE_EXECUTION_FAILED", "SOURCE_STATUS_FAILED", "SOURCE_ROUTE_COMPLETED_CASHOUT_FAILED", "SOURCE_CASHOUT_SUBMISSION_UNKNOWN", "SOURCE_CASHOUT_STATUS_UNKNOWN", "DEPOSIT_RESOLUTION_FAILED", "ALLOWANCE_NOT_VISIBLE", "SIGNER_REQUIRED", "SIGNER_CHAIN_MISMATCH", "SIGNER_CHAIN_UNAVAILABLE", "WATCH_TIMEOUT", "TRANSACTION_FAILED", "TRANSACTION_SUBMISSION_UNKNOWN", "TRANSACTION_STATUS_UNKNOWN"]>;
|
|
3187
|
+
code: z.ZodEnum<["ORACLE_UNSUPPORTED_CURRENCY", "ORACLE_READ_FAILED", "UNSUPPORTED_PLATFORM", "UNSUPPORTED_PLATFORM_CURRENCY", "AMOUNT_BELOW_MINIMUM", "INVALID_INTENT_AMOUNT_RANGE", "INVALID_PAYOUT_CURRENCIES", "ACTIVE_INTENT_BLOCKS_WITHDRAWAL", "NOTHING_TO_WITHDRAW", "INSUFFICIENT_AVAILABLE_FUNDS", "INSUFFICIENT_TOKEN_BALANCE", "ORDER_NOT_ACTIVE", "INVALID_DEPOSIT_ID", "ESCROW_PAUSED", "INDEXER_LAG", "INDEXER_UNAVAILABLE", "ORDER_NOT_FOUND", "PAYEE_REGISTRATION_FAILED", "PAYEE_VERIFICATION_REQUIRED", "SOURCE_ROUTE_UNSUPPORTED_IN_PREPARE", "SOURCE_RECIPIENT_MISMATCH", "SOURCE_CAPABILITIES_FAILED", "SOURCE_QUOTE_FAILED", "SOURCE_NONCE_MANAGER_REQUIRED", "SOURCE_EXECUTION_FAILED", "SOURCE_STATUS_FAILED", "SOURCE_ROUTE_COMPLETED_CASHOUT_FAILED", "SOURCE_CASHOUT_SUBMISSION_UNKNOWN", "SOURCE_CASHOUT_STATUS_UNKNOWN", "DEPOSIT_RESOLUTION_FAILED", "ALLOWANCE_NOT_VISIBLE", "SIGNER_REQUIRED", "SIGNER_CHAIN_MISMATCH", "SIGNER_CHAIN_UNAVAILABLE", "WATCH_TIMEOUT", "TRANSACTION_REJECTED", "TRANSACTION_FAILED", "TRANSACTION_SUBMISSION_UNKNOWN", "TRANSACTION_STATUS_UNKNOWN"]>;
|
|
3180
3188
|
message: z.ZodString;
|
|
3181
3189
|
retryable: z.ZodBoolean;
|
|
3182
3190
|
remediation: z.ZodString;
|
|
@@ -3563,7 +3571,7 @@ declare const cashErrorJsonSchema: z.ZodObject<{
|
|
|
3563
3571
|
}>]>>;
|
|
3564
3572
|
}, "strict", z.ZodTypeAny, {
|
|
3565
3573
|
message: string;
|
|
3566
|
-
code: "ORACLE_UNSUPPORTED_CURRENCY" | "ORACLE_READ_FAILED" | "UNSUPPORTED_PLATFORM" | "UNSUPPORTED_PLATFORM_CURRENCY" | "AMOUNT_BELOW_MINIMUM" | "INVALID_INTENT_AMOUNT_RANGE" | "ACTIVE_INTENT_BLOCKS_WITHDRAWAL" | "NOTHING_TO_WITHDRAW" | "INSUFFICIENT_AVAILABLE_FUNDS" | "INSUFFICIENT_TOKEN_BALANCE" | "ORDER_NOT_ACTIVE" | "INVALID_DEPOSIT_ID" | "ESCROW_PAUSED" | "INDEXER_LAG" | "INDEXER_UNAVAILABLE" | "ORDER_NOT_FOUND" | "PAYEE_REGISTRATION_FAILED" | "PAYEE_VERIFICATION_REQUIRED" | "SOURCE_ROUTE_UNSUPPORTED_IN_PREPARE" | "SOURCE_RECIPIENT_MISMATCH" | "SOURCE_CAPABILITIES_FAILED" | "SOURCE_QUOTE_FAILED" | "SOURCE_NONCE_MANAGER_REQUIRED" | "SOURCE_EXECUTION_FAILED" | "SOURCE_STATUS_FAILED" | "SOURCE_ROUTE_COMPLETED_CASHOUT_FAILED" | "SOURCE_CASHOUT_SUBMISSION_UNKNOWN" | "SOURCE_CASHOUT_STATUS_UNKNOWN" | "DEPOSIT_RESOLUTION_FAILED" | "ALLOWANCE_NOT_VISIBLE" | "SIGNER_REQUIRED" | "SIGNER_CHAIN_MISMATCH" | "SIGNER_CHAIN_UNAVAILABLE" | "WATCH_TIMEOUT" | "TRANSACTION_FAILED" | "TRANSACTION_SUBMISSION_UNKNOWN" | "TRANSACTION_STATUS_UNKNOWN";
|
|
3574
|
+
code: "ORACLE_UNSUPPORTED_CURRENCY" | "ORACLE_READ_FAILED" | "UNSUPPORTED_PLATFORM" | "UNSUPPORTED_PLATFORM_CURRENCY" | "AMOUNT_BELOW_MINIMUM" | "INVALID_INTENT_AMOUNT_RANGE" | "INVALID_PAYOUT_CURRENCIES" | "ACTIVE_INTENT_BLOCKS_WITHDRAWAL" | "NOTHING_TO_WITHDRAW" | "INSUFFICIENT_AVAILABLE_FUNDS" | "INSUFFICIENT_TOKEN_BALANCE" | "ORDER_NOT_ACTIVE" | "INVALID_DEPOSIT_ID" | "ESCROW_PAUSED" | "INDEXER_LAG" | "INDEXER_UNAVAILABLE" | "ORDER_NOT_FOUND" | "PAYEE_REGISTRATION_FAILED" | "PAYEE_VERIFICATION_REQUIRED" | "SOURCE_ROUTE_UNSUPPORTED_IN_PREPARE" | "SOURCE_RECIPIENT_MISMATCH" | "SOURCE_CAPABILITIES_FAILED" | "SOURCE_QUOTE_FAILED" | "SOURCE_NONCE_MANAGER_REQUIRED" | "SOURCE_EXECUTION_FAILED" | "SOURCE_STATUS_FAILED" | "SOURCE_ROUTE_COMPLETED_CASHOUT_FAILED" | "SOURCE_CASHOUT_SUBMISSION_UNKNOWN" | "SOURCE_CASHOUT_STATUS_UNKNOWN" | "DEPOSIT_RESOLUTION_FAILED" | "ALLOWANCE_NOT_VISIBLE" | "SIGNER_REQUIRED" | "SIGNER_CHAIN_MISMATCH" | "SIGNER_CHAIN_UNAVAILABLE" | "WATCH_TIMEOUT" | "TRANSACTION_REJECTED" | "TRANSACTION_FAILED" | "TRANSACTION_SUBMISSION_UNKNOWN" | "TRANSACTION_STATUS_UNKNOWN";
|
|
3567
3575
|
retryable: boolean;
|
|
3568
3576
|
remediation: string;
|
|
3569
3577
|
recovery?: {
|
|
@@ -3645,7 +3653,7 @@ declare const cashErrorJsonSchema: z.ZodObject<{
|
|
|
3645
3653
|
} | undefined;
|
|
3646
3654
|
}, {
|
|
3647
3655
|
message: string;
|
|
3648
|
-
code: "ORACLE_UNSUPPORTED_CURRENCY" | "ORACLE_READ_FAILED" | "UNSUPPORTED_PLATFORM" | "UNSUPPORTED_PLATFORM_CURRENCY" | "AMOUNT_BELOW_MINIMUM" | "INVALID_INTENT_AMOUNT_RANGE" | "ACTIVE_INTENT_BLOCKS_WITHDRAWAL" | "NOTHING_TO_WITHDRAW" | "INSUFFICIENT_AVAILABLE_FUNDS" | "INSUFFICIENT_TOKEN_BALANCE" | "ORDER_NOT_ACTIVE" | "INVALID_DEPOSIT_ID" | "ESCROW_PAUSED" | "INDEXER_LAG" | "INDEXER_UNAVAILABLE" | "ORDER_NOT_FOUND" | "PAYEE_REGISTRATION_FAILED" | "PAYEE_VERIFICATION_REQUIRED" | "SOURCE_ROUTE_UNSUPPORTED_IN_PREPARE" | "SOURCE_RECIPIENT_MISMATCH" | "SOURCE_CAPABILITIES_FAILED" | "SOURCE_QUOTE_FAILED" | "SOURCE_NONCE_MANAGER_REQUIRED" | "SOURCE_EXECUTION_FAILED" | "SOURCE_STATUS_FAILED" | "SOURCE_ROUTE_COMPLETED_CASHOUT_FAILED" | "SOURCE_CASHOUT_SUBMISSION_UNKNOWN" | "SOURCE_CASHOUT_STATUS_UNKNOWN" | "DEPOSIT_RESOLUTION_FAILED" | "ALLOWANCE_NOT_VISIBLE" | "SIGNER_REQUIRED" | "SIGNER_CHAIN_MISMATCH" | "SIGNER_CHAIN_UNAVAILABLE" | "WATCH_TIMEOUT" | "TRANSACTION_FAILED" | "TRANSACTION_SUBMISSION_UNKNOWN" | "TRANSACTION_STATUS_UNKNOWN";
|
|
3656
|
+
code: "ORACLE_UNSUPPORTED_CURRENCY" | "ORACLE_READ_FAILED" | "UNSUPPORTED_PLATFORM" | "UNSUPPORTED_PLATFORM_CURRENCY" | "AMOUNT_BELOW_MINIMUM" | "INVALID_INTENT_AMOUNT_RANGE" | "INVALID_PAYOUT_CURRENCIES" | "ACTIVE_INTENT_BLOCKS_WITHDRAWAL" | "NOTHING_TO_WITHDRAW" | "INSUFFICIENT_AVAILABLE_FUNDS" | "INSUFFICIENT_TOKEN_BALANCE" | "ORDER_NOT_ACTIVE" | "INVALID_DEPOSIT_ID" | "ESCROW_PAUSED" | "INDEXER_LAG" | "INDEXER_UNAVAILABLE" | "ORDER_NOT_FOUND" | "PAYEE_REGISTRATION_FAILED" | "PAYEE_VERIFICATION_REQUIRED" | "SOURCE_ROUTE_UNSUPPORTED_IN_PREPARE" | "SOURCE_RECIPIENT_MISMATCH" | "SOURCE_CAPABILITIES_FAILED" | "SOURCE_QUOTE_FAILED" | "SOURCE_NONCE_MANAGER_REQUIRED" | "SOURCE_EXECUTION_FAILED" | "SOURCE_STATUS_FAILED" | "SOURCE_ROUTE_COMPLETED_CASHOUT_FAILED" | "SOURCE_CASHOUT_SUBMISSION_UNKNOWN" | "SOURCE_CASHOUT_STATUS_UNKNOWN" | "DEPOSIT_RESOLUTION_FAILED" | "ALLOWANCE_NOT_VISIBLE" | "SIGNER_REQUIRED" | "SIGNER_CHAIN_MISMATCH" | "SIGNER_CHAIN_UNAVAILABLE" | "WATCH_TIMEOUT" | "TRANSACTION_REJECTED" | "TRANSACTION_FAILED" | "TRANSACTION_SUBMISSION_UNKNOWN" | "TRANSACTION_STATUS_UNKNOWN";
|
|
3649
3657
|
retryable: boolean;
|
|
3650
3658
|
remediation: string;
|
|
3651
3659
|
recovery?: {
|
|
@@ -3791,4 +3799,4 @@ declare function capabilitiesFromJson(json: unknown): CashCapabilities;
|
|
|
3791
3799
|
declare function cashErrorToJson(error: CashErrorShape): CashErrorJson;
|
|
3792
3800
|
declare function cashErrorFromJson(json: unknown): CashError;
|
|
3793
3801
|
|
|
3794
|
-
export { BASE_CHAIN_ID, BASE_USDC_ADDRESS, CASH_ORDER_POLL_INTERVAL_MS, CASH_ORDER_STATUSES, CASH_RETAIN_ON_EMPTY, type CashAssetJson, CashBuyerProfile, type CashBuyerProfileJson, CashCapabilities, type CashCapabilitiesJson, type CashChainJson, CashDepositInput, CashError, type CashErrorCode, type CashErrorJson, type CashErrorRecovery, type CashErrorRecoveryJson, type CashErrorShape, CashEstimate, type CashEstimateJson, CashFill, type CashFillJson, CashFillStats, type CashFillStatsJson, CashOrder, type CashOrderData, type CashOrderJson, CashPayoutInfo, type CashPayoutInfoJson, CashPreparedStep, type CashPreparedStepJson, CashSourceCapabilities, type CashSourceCapabilitiesJson, CashoutResult, type CashoutResultJson, type DeriveCashOrderOptions, MARKET_SPREAD_BPS, type MethodCurrencyLike, ORACLE_MIN_CONVERSION_RATE_SENTINEL, type PaymentMethodLike, PrepareResult, type PrepareResultJson, type PreparedTransactionJson, RATE_PRECISION, RelayExecutionResult, type RelayExecutionResultJson, RelayQuote, type RelayQuoteJson, RelayStatus, type RelayStatusJson, type RelayTransactionJson, type RelayTransactionsJson, type ResolvedCashDeposit, TopUpResult, type TopUpResultJson, USDC_DECIMALS, WithdrawResult, type WithdrawResultJson, bigintString, buildIntentAmountRange, buildMarketRateCurrencyOverride, buyerProfileFromJson, buyerProfileToJson, capabilitiesFromJson, capabilitiesToJson, cashAssetJsonSchema, cashBuyerProfileJsonSchema, cashCapabilitiesJsonSchema, cashChainJsonSchema, cashErrorFromJson, cashErrorJsonSchema, cashErrorRecoveryJsonSchema, cashErrorToJson, cashEstimateJsonSchema, cashFillJsonSchema, cashFillStatsJsonSchema, cashNextActionSchema, cashOrderJsonSchema, cashOrderStateSchema, cashPairFillStatsJsonSchema, cashPayoutInfoJsonSchema, cashPayoutPricingJsonSchema, cashPreparedStepJsonSchema, cashSourceCapabilitiesJsonSchema, cashoutResultFromJson, cashoutResultJsonSchema, cashoutResultToJson, centsToNumber, deriveBuyerProfile, deriveCashOrder, derivePayouts, errors, estimateFromJson, estimateToJson, explainOrder, fiatFromUsdc, fiatToNumber, fillFromJson, fillStatsFromJson, fillStatsToJson, fillToJson, formatUsdc, intentStatusSchema, isCashError, isFillLive, isMarketRateSupported, nonNegativeBigintString, orderFromJson, orderToJson, parseCompositeDepositId, prepareCashDepositParams, prepareResultFromJson, prepareResultJsonSchema, prepareResultToJson, preparedStepFromJson, preparedStepToJson, preparedTransactionJsonSchema, preparedTxFromJson, preparedTxToJson, rateToNumber, relayExecutionResultFromJson, relayExecutionResultJsonSchema, relayExecutionResultToJson, relayQuoteFromJson, relayQuoteJsonSchema, relayQuoteToJson, relayStatusFromJson, relayStatusJsonSchema, relayStatusToJson, relayTransactionJsonSchema, relayTransactionsJsonSchema, resolveCashDepositId, sourceCapabilitiesFromJson, sourceCapabilitiesToJson, topUpResultFromJson, topUpResultJsonSchema, topUpResultToJson, usdc, withExplain, withdrawResultFromJson, withdrawResultJsonSchema, withdrawResultToJson };
|
|
3802
|
+
export { BASE_CHAIN_ID, BASE_USDC_ADDRESS, CASH_ORDER_POLL_INTERVAL_MS, CASH_ORDER_STATUSES, CASH_RETAIN_ON_EMPTY, type CashAssetJson, CashBuyerProfile, type CashBuyerProfileJson, CashCapabilities, type CashCapabilitiesJson, type CashChainJson, CashDepositInput, CashError, type CashErrorCode, type CashErrorJson, type CashErrorRecovery, type CashErrorRecoveryJson, type CashErrorShape, CashEstimate, type CashEstimateJson, CashFill, type CashFillJson, CashFillStats, type CashFillStatsJson, CashOrder, type CashOrderData, type CashOrderJson, CashPayoutInfo, type CashPayoutInfoJson, CashPreparedStep, type CashPreparedStepJson, CashSourceCapabilities, type CashSourceCapabilitiesJson, CashoutResult, type CashoutResultJson, type DeriveCashOrderOptions, MARKET_SPREAD_BPS, type MethodCurrencyLike, ORACLE_MIN_CONVERSION_RATE_SENTINEL, type PaymentMethodLike, PrepareResult, type PrepareResultJson, type PreparedTransactionJson, RATE_PRECISION, RelayExecutionResult, type RelayExecutionResultJson, RelayQuote, type RelayQuoteJson, RelayStatus, type RelayStatusJson, type RelayTransactionJson, type RelayTransactionsJson, type ResolvedCashDeposit, TopUpResult, type TopUpResultJson, USDC_DECIMALS, WithdrawResult, type WithdrawResultJson, bigintString, buildIntentAmountRange, buildMarketRateCurrencyOverride, buyerProfileFromJson, buyerProfileToJson, capabilitiesFromJson, capabilitiesToJson, cashAssetJsonSchema, cashBuyerProfileJsonSchema, cashCapabilitiesJsonSchema, cashChainJsonSchema, cashErrorFromJson, cashErrorJsonSchema, cashErrorRecoveryJsonSchema, cashErrorToJson, cashEstimateJsonSchema, cashFillJsonSchema, cashFillStatsJsonSchema, cashNextActionSchema, cashOrderJsonSchema, cashOrderStateSchema, cashPairFillStatsJsonSchema, cashPayoutInfoJsonSchema, cashPayoutPricingJsonSchema, cashPreparedStepJsonSchema, cashSourceCapabilitiesJsonSchema, cashoutResultFromJson, cashoutResultJsonSchema, cashoutResultToJson, centsToNumber, deriveBuyerProfile, deriveCashOrder, derivePayouts, errors, estimateFromJson, estimateToJson, explainOrder, fiatFromUsdc, fiatToNumber, fillFromJson, fillStatsFromJson, fillStatsToJson, fillToJson, formatUsdc, intentStatusSchema, isCashError, isFillLive, isMarketRateSupported, isUserRejectedError, nonNegativeBigintString, orderFromJson, orderToJson, parseCompositeDepositId, prepareCashDepositParams, prepareResultFromJson, prepareResultJsonSchema, prepareResultToJson, preparedStepFromJson, preparedStepToJson, preparedTransactionJsonSchema, preparedTxFromJson, preparedTxToJson, rateToNumber, relayExecutionResultFromJson, relayExecutionResultJsonSchema, relayExecutionResultToJson, relayQuoteFromJson, relayQuoteJsonSchema, relayQuoteToJson, relayStatusFromJson, relayStatusJsonSchema, relayStatusToJson, relayTransactionJsonSchema, relayTransactionsJsonSchema, resolveCashDepositId, sourceCapabilitiesFromJson, sourceCapabilitiesToJson, topUpResultFromJson, topUpResultJsonSchema, topUpResultToJson, usdc, withExplain, withdrawResultFromJson, withdrawResultJsonSchema, withdrawResultToJson };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MARKET_SPREAD_BPS, ORACLE_MIN_CONVERSION_RATE_SENTINEL, CASH_RETAIN_ON_EMPTY, BASE_USDC_ADDRESS, USDC_DECIMALS, BASE_CHAIN_ID, errors, isCashError, CASH_ORDER_STATUSES, mapChainError, CashError } from './chunk-
|
|
2
|
-
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 } from './chunk-
|
|
1
|
+
import { MARKET_SPREAD_BPS, ORACLE_MIN_CONVERSION_RATE_SENTINEL, CASH_RETAIN_ON_EMPTY, BASE_USDC_ADDRESS, USDC_DECIMALS, BASE_CHAIN_ID, errors, isCashError, CASH_ORDER_STATUSES, mapChainError, CashError } from './chunk-5VBP3IWK.js';
|
|
2
|
+
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, isUserRejectedError } from './chunk-5VBP3IWK.js';
|
|
3
3
|
import { parseAbi, parseEventLogs, isAddress, http, createWalletClient, encodeFunctionData } from 'viem';
|
|
4
4
|
import { base } from 'viem/chains';
|
|
5
5
|
import { getSpreadOracleConfig, currencyInfo, getPaymentMethodsCatalog, getGatingServiceAddress, resolvePaymentMethodHashFromCatalog, resolvePaymentMethodNameFromHash, getCurrencyCodeFromHash, createCompositeDepositId, appendAttributionToCalldata, Zkp2pClient, CHAINLINK_ORACLE_FEEDS } from '@zkp2p/sdk';
|
|
@@ -7,6 +7,12 @@ import { createClient, MAINNET_RELAY_API } from '@relayprotocol/relay-sdk';
|
|
|
7
7
|
import { fetchChainConfigs, configureDynamicChains } from '@relayprotocol/relay-sdk/chain-utils';
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
|
|
10
|
+
function payoutCurrencies(payout) {
|
|
11
|
+
if (payout.currency === void 0 === (payout.currencies === void 0)) {
|
|
12
|
+
throw new Error("Pass exactly one of payout currency or currencies");
|
|
13
|
+
}
|
|
14
|
+
return payout.currencies ?? [payout.currency];
|
|
15
|
+
}
|
|
10
16
|
function isMarketRateSupported(currency, adapters) {
|
|
11
17
|
return getSpreadOracleConfig(currency, adapters) != null;
|
|
12
18
|
}
|
|
@@ -38,14 +44,32 @@ async function prepareCashDepositParams(client, input, adapters) {
|
|
|
38
44
|
const runtimeEnv = client.runtimeEnv;
|
|
39
45
|
const catalog = getPaymentMethodsCatalog(chainId, runtimeEnv);
|
|
40
46
|
const intentGatingService = getGatingServiceAddress(chainId, runtimeEnv);
|
|
47
|
+
const processorNames = payouts.map((p) => p.processorName);
|
|
48
|
+
const paymentMethodsOverride = processorNames.map(
|
|
49
|
+
(name) => resolvePaymentMethodHashFromCatalog(name, catalog)
|
|
50
|
+
);
|
|
41
51
|
for (const payout of payouts) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
const currencies = payoutCurrencies(payout);
|
|
53
|
+
if (currencies.length === 0 || new Set(currencies).size !== currencies.length) {
|
|
54
|
+
throw new Error("Payout currencies must be non-empty and unique");
|
|
55
|
+
}
|
|
56
|
+
const supportedCurrencyHashes = new Set(
|
|
57
|
+
(catalog[payout.processorName.toLowerCase()]?.currencies ?? []).map(
|
|
58
|
+
(hash) => hash.toLowerCase()
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
for (const currency of currencies) {
|
|
62
|
+
if (!isMarketRateSupported(currency, adapters)) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`${currency} has no live market-rate oracle feed; Peer Cash supports market-rate currencies only.`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
const currencyHash = currencyInfo[currency]?.currencyCodeHash;
|
|
68
|
+
if (!currencyHash || !supportedCurrencyHashes.has(currencyHash.toLowerCase())) {
|
|
69
|
+
throw new Error(`${payout.processorName} does not support ${currency}`);
|
|
70
|
+
}
|
|
46
71
|
}
|
|
47
72
|
}
|
|
48
|
-
const processorNames = payouts.map((p) => p.processorName);
|
|
49
73
|
const { hashedOnchainIds } = await client.registerPayeeDetails({
|
|
50
74
|
processorNames,
|
|
51
75
|
payeeData: payouts.map((p) => p.payeeData)
|
|
@@ -53,22 +77,24 @@ async function prepareCashDepositParams(client, input, adapters) {
|
|
|
53
77
|
if (hashedOnchainIds.length !== payouts.length) {
|
|
54
78
|
throw new Error("Payee registration returned an unexpected number of hashes");
|
|
55
79
|
}
|
|
56
|
-
const paymentMethodsOverride = processorNames.map(
|
|
57
|
-
(name) => resolvePaymentMethodHashFromCatalog(name, catalog)
|
|
58
|
-
);
|
|
59
80
|
const paymentMethodDataOverride = hashedOnchainIds.map((hid) => ({
|
|
60
81
|
intentGatingService,
|
|
61
82
|
payeeDetails: hid,
|
|
62
83
|
data: "0x"
|
|
63
84
|
}));
|
|
64
|
-
const currenciesOverride = payouts.map(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
85
|
+
const currenciesOverride = payouts.map(
|
|
86
|
+
(payout) => payoutCurrencies(payout).map((currency) => {
|
|
87
|
+
const tuple = buildMarketRateCurrencyOverride(currency, adapters);
|
|
88
|
+
if (!tuple) throw new Error(`Failed to build market-rate config for ${currency}`);
|
|
89
|
+
return tuple;
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
const conversionRates = payouts.map(
|
|
93
|
+
(payout) => payoutCurrencies(payout).map((currency) => ({
|
|
94
|
+
currency,
|
|
95
|
+
conversionRate: ORACLE_MIN_CONVERSION_RATE_SENTINEL.toString()
|
|
96
|
+
}))
|
|
97
|
+
);
|
|
72
98
|
const intentAmountRange = input.intentAmountRange ?? buildIntentAmountRange(input.amount);
|
|
73
99
|
return {
|
|
74
100
|
token: input.token ?? BASE_USDC_ADDRESS,
|
|
@@ -365,21 +391,33 @@ function resolveCashDepositId(params) {
|
|
|
365
391
|
events = parseEventLogs({
|
|
366
392
|
abi: params.abi,
|
|
367
393
|
eventName: "DepositReceived",
|
|
368
|
-
logs: params.logs
|
|
394
|
+
logs: [...params.logs]
|
|
369
395
|
});
|
|
370
396
|
} catch {
|
|
371
397
|
return null;
|
|
372
398
|
}
|
|
373
|
-
const
|
|
374
|
-
|
|
399
|
+
const matchingEvents = events.filter((event2) => {
|
|
400
|
+
if (params.expectedEscrowAddress !== void 0 && event2.address.toLowerCase() !== params.expectedEscrowAddress.toLowerCase()) {
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
if (params.expectedToken !== void 0 && String(event2.args.token ?? "").toLowerCase() !== params.expectedToken.toLowerCase()) {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
return true;
|
|
407
|
+
});
|
|
408
|
+
if (matchingEvents.length !== 1) return null;
|
|
409
|
+
const event = matchingEvents[0];
|
|
375
410
|
const rawId = event.args.depositId;
|
|
376
411
|
if (rawId === void 0 || rawId === null) return null;
|
|
377
412
|
const onchainDepositId = BigInt(rawId);
|
|
413
|
+
const rawAmount = event.args.amount;
|
|
414
|
+
const amount = rawAmount === void 0 || rawAmount === null ? void 0 : BigInt(rawAmount);
|
|
378
415
|
const escrowAddress = event.address.toLowerCase();
|
|
379
416
|
return {
|
|
380
417
|
onchainDepositId,
|
|
381
418
|
escrowAddress,
|
|
382
|
-
compositeId: createCompositeDepositId(escrowAddress, onchainDepositId)
|
|
419
|
+
compositeId: createCompositeDepositId(escrowAddress, onchainDepositId),
|
|
420
|
+
...amount === void 0 ? {} : { amount }
|
|
383
421
|
};
|
|
384
422
|
}
|
|
385
423
|
function parseCompositeDepositId(compositeId) {
|
|
@@ -485,6 +523,26 @@ function computeFillStatsSample(deposits, nowSeconds, environment) {
|
|
|
485
523
|
const createdAt = toUnixSeconds2(deposit.createdAt ?? deposit.timestamp);
|
|
486
524
|
const firstFillByPair = /* @__PURE__ */ new Map();
|
|
487
525
|
const firstFillByCurrency = /* @__PURE__ */ new Map();
|
|
526
|
+
const offeredCurrenciesByMethod = /* @__PURE__ */ new Map();
|
|
527
|
+
for (const offered of deposit.currencies ?? []) {
|
|
528
|
+
let method;
|
|
529
|
+
try {
|
|
530
|
+
method = offered.paymentMethodHash ? resolvePaymentMethodNameFromHash(offered.paymentMethodHash, catalog) : void 0;
|
|
531
|
+
} catch {
|
|
532
|
+
method = void 0;
|
|
533
|
+
}
|
|
534
|
+
const currency = normalizeCurrencyCode(offered.currencyCode);
|
|
535
|
+
if (!method || !currency) continue;
|
|
536
|
+
const currencies = offeredCurrenciesByMethod.get(method) ?? /* @__PURE__ */ new Set();
|
|
537
|
+
currencies.add(currency);
|
|
538
|
+
offeredCurrenciesByMethod.set(method, currencies);
|
|
539
|
+
}
|
|
540
|
+
const multiCurrencyKeyByMethod = /* @__PURE__ */ new Map();
|
|
541
|
+
for (const [method, currencies] of offeredCurrenciesByMethod) {
|
|
542
|
+
if (currencies.size > 1) {
|
|
543
|
+
multiCurrencyKeyByMethod.set(method, `${method}:${[...currencies].sort().join("+")}`);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
488
546
|
for (const intent of deposit.intents ?? []) {
|
|
489
547
|
const fulfilledAt = toUnixSeconds2(intent.fulfillTimestamp);
|
|
490
548
|
if (fulfilledAt === void 0 || fulfilledAt < windowStart) continue;
|
|
@@ -498,11 +556,25 @@ function computeFillStatsSample(deposits, nowSeconds, environment) {
|
|
|
498
556
|
if (!method || !currency) continue;
|
|
499
557
|
const pair = `${method}:${currency}`;
|
|
500
558
|
fillCounts.set(pair, (fillCounts.get(pair) ?? 0) + 1);
|
|
559
|
+
const multiCurrencyKey = multiCurrencyKeyByMethod.get(method);
|
|
560
|
+
const matchingMultiCurrencyKey = multiCurrencyKey && offeredCurrenciesByMethod.get(method)?.has(currency) ? multiCurrencyKey : void 0;
|
|
561
|
+
if (matchingMultiCurrencyKey) {
|
|
562
|
+
fillCounts.set(
|
|
563
|
+
matchingMultiCurrencyKey,
|
|
564
|
+
(fillCounts.get(matchingMultiCurrencyKey) ?? 0) + 1
|
|
565
|
+
);
|
|
566
|
+
}
|
|
501
567
|
if (createdAt === void 0 || createdAt < windowStart || fulfilledAt < createdAt) continue;
|
|
502
568
|
const previousPairFill = firstFillByPair.get(pair);
|
|
503
569
|
if (previousPairFill === void 0 || fulfilledAt < previousPairFill) {
|
|
504
570
|
firstFillByPair.set(pair, fulfilledAt);
|
|
505
571
|
}
|
|
572
|
+
if (matchingMultiCurrencyKey) {
|
|
573
|
+
const previousMultiCurrencyFill = firstFillByPair.get(matchingMultiCurrencyKey);
|
|
574
|
+
if (previousMultiCurrencyFill === void 0 || fulfilledAt < previousMultiCurrencyFill) {
|
|
575
|
+
firstFillByPair.set(matchingMultiCurrencyKey, fulfilledAt);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
506
578
|
const previousCurrencyFill = firstFillByCurrency.get(currency);
|
|
507
579
|
if (previousCurrencyFill === void 0 || fulfilledAt < previousCurrencyFill) {
|
|
508
580
|
firstFillByCurrency.set(currency, fulfilledAt);
|
|
@@ -1124,6 +1196,36 @@ async function readEstimate(publicClient, input, context = {}) {
|
|
|
1124
1196
|
return estimate;
|
|
1125
1197
|
}
|
|
1126
1198
|
|
|
1199
|
+
// src/client/payee.ts
|
|
1200
|
+
function normalizePaypalHandle(value) {
|
|
1201
|
+
const withoutProtocol = value.replace(/^https?:\/\//i, "").replace(/^www\./i, "");
|
|
1202
|
+
if (/^paypal\.me(?:[?#].*)?$/i.test(withoutProtocol)) return "";
|
|
1203
|
+
const withoutDomain = withoutProtocol.replace(/^paypal\.me\//i, "");
|
|
1204
|
+
const [pathWithoutQuery = ""] = withoutDomain.split(/[?#]/, 1);
|
|
1205
|
+
const [username = ""] = pathWithoutQuery.replace(/^\/+/, "").split("/", 1);
|
|
1206
|
+
return username.replace(/^@+/, "").trim().toLowerCase();
|
|
1207
|
+
}
|
|
1208
|
+
function normalizeCashPayee(platform, payee) {
|
|
1209
|
+
if (typeof payee !== "string") return payee;
|
|
1210
|
+
const trimmed = payee.trim();
|
|
1211
|
+
switch (platform) {
|
|
1212
|
+
case "venmo":
|
|
1213
|
+
return { offchainId: trimmed.replace(/^@+/, "") };
|
|
1214
|
+
case "cashapp":
|
|
1215
|
+
return { offchainId: trimmed.replace(/^\$+/, "") };
|
|
1216
|
+
case "chime":
|
|
1217
|
+
return { offchainId: trimmed.toLowerCase() };
|
|
1218
|
+
case "n26":
|
|
1219
|
+
return { offchainId: trimmed.replace(/\s/g, "") };
|
|
1220
|
+
case "paypal":
|
|
1221
|
+
return { offchainId: normalizePaypalHandle(trimmed) };
|
|
1222
|
+
case "zelle":
|
|
1223
|
+
return { offchainId: trimmed.toLowerCase() };
|
|
1224
|
+
default:
|
|
1225
|
+
return { offchainId: trimmed };
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1127
1229
|
// src/client/createCashClient.ts
|
|
1128
1230
|
var DEFAULT_RPC_URL = "https://mainnet.base.org";
|
|
1129
1231
|
var FILL_STATS_CACHE_MS = 15 * 60 * 1e3;
|
|
@@ -1165,7 +1267,7 @@ async function submitAndConfirm(client, verb, send) {
|
|
|
1165
1267
|
hash = await send();
|
|
1166
1268
|
} catch (err) {
|
|
1167
1269
|
const mapped = mapChainError(verb, err);
|
|
1168
|
-
if (isKnownPreBroadcastFailure(
|
|
1270
|
+
if (isKnownPreBroadcastFailure(mapped)) throw mapped;
|
|
1169
1271
|
throw errors.transactionSubmissionUnknown(verb, err, {
|
|
1170
1272
|
kind: "inspect-base-operation-submission",
|
|
1171
1273
|
operation: verb
|
|
@@ -1180,12 +1282,8 @@ async function submitAndConfirm(client, verb, send) {
|
|
|
1180
1282
|
if (receipt.status === "reverted") throw errors.transactionFailed(hash);
|
|
1181
1283
|
return hash;
|
|
1182
1284
|
}
|
|
1183
|
-
function isKnownPreBroadcastFailure(
|
|
1184
|
-
|
|
1185
|
-
return true;
|
|
1186
|
-
}
|
|
1187
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
1188
|
-
return /user rejected|user denied|rejected request|action_rejected/i.test(message);
|
|
1285
|
+
function isKnownPreBroadcastFailure(mapped) {
|
|
1286
|
+
return mapped.code === "TRANSACTION_REJECTED" || mapped.code === "INSUFFICIENT_TOKEN_BALANCE" || mapped.code === "ALLOWANCE_NOT_VISIBLE" || mapped.code === "ESCROW_PAUSED";
|
|
1189
1287
|
}
|
|
1190
1288
|
function depositOrderOptions(deposit) {
|
|
1191
1289
|
const remaining = toBigIntOrUndefined(deposit.remainingDeposits);
|
|
@@ -1262,18 +1360,33 @@ function createCashClient(options) {
|
|
|
1262
1360
|
(capability) => capability.platform === receive.platform
|
|
1263
1361
|
);
|
|
1264
1362
|
if (!platform) throw errors.unsupportedPlatform(receive.platform);
|
|
1265
|
-
if (
|
|
1266
|
-
throw errors.
|
|
1363
|
+
if (receive.currency === void 0 === (receive.currencies === void 0)) {
|
|
1364
|
+
throw errors.invalidPayoutCurrencies(
|
|
1365
|
+
receive.platform,
|
|
1366
|
+
"pass exactly one of currency or currencies"
|
|
1367
|
+
);
|
|
1267
1368
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1369
|
+
const currencies = receive.currencies !== void 0 ? [...receive.currencies] : [receive.currency];
|
|
1370
|
+
if (currencies.length === 0) {
|
|
1371
|
+
throw errors.invalidPayoutCurrencies(receive.platform, "at least one currency is required");
|
|
1372
|
+
}
|
|
1373
|
+
if (new Set(currencies).size !== currencies.length) {
|
|
1374
|
+
throw errors.invalidPayoutCurrencies(receive.platform, "currencies must be unique");
|
|
1375
|
+
}
|
|
1376
|
+
for (const currency of currencies) {
|
|
1377
|
+
if (!isMarketRateSupported(currency)) {
|
|
1378
|
+
throw errors.oracleUnsupportedCurrency(currency);
|
|
1379
|
+
}
|
|
1380
|
+
if (!platform.currencies.includes(currency)) {
|
|
1381
|
+
throw errors.unsupportedPlatformCurrency(receive.platform, currency);
|
|
1382
|
+
}
|
|
1270
1383
|
}
|
|
1271
1384
|
return {
|
|
1272
1385
|
payouts: [
|
|
1273
1386
|
{
|
|
1274
1387
|
processorName: receive.platform,
|
|
1275
|
-
currency:
|
|
1276
|
-
payeeData: receive.payee
|
|
1388
|
+
...currencies.length === 1 ? { currency: currencies[0] } : { currencies },
|
|
1389
|
+
payeeData: normalizeCashPayee(receive.platform, receive.payee)
|
|
1277
1390
|
}
|
|
1278
1391
|
]
|
|
1279
1392
|
};
|
|
@@ -1293,7 +1406,12 @@ function createCashClient(options) {
|
|
|
1293
1406
|
};
|
|
1294
1407
|
}
|
|
1295
1408
|
function isCashPayoutSet(payouts) {
|
|
1296
|
-
|
|
1409
|
+
const first = payouts[0];
|
|
1410
|
+
return Boolean(
|
|
1411
|
+
first && payouts.every(
|
|
1412
|
+
(payout) => payout.platformHash.toLowerCase() === first.platformHash.toLowerCase() && payout.payeeHash.toLowerCase() === first.payeeHash.toLowerCase() && payout.pricing.marketRate && payout.pricing.spreadBps === 0
|
|
1413
|
+
)
|
|
1414
|
+
);
|
|
1297
1415
|
}
|
|
1298
1416
|
async function buildDepositParams(client, depositInput) {
|
|
1299
1417
|
try {
|
|
@@ -1566,9 +1684,9 @@ function createCashClient(options) {
|
|
|
1566
1684
|
}
|
|
1567
1685
|
},
|
|
1568
1686
|
async cashout(input, opts) {
|
|
1687
|
+
const payoutInput = validatePayout(input);
|
|
1569
1688
|
const client = await signingClient("cashout", opts);
|
|
1570
1689
|
const owner = opts.signer.account.address;
|
|
1571
|
-
const payoutInput = validatePayout(input);
|
|
1572
1690
|
let sourceResult;
|
|
1573
1691
|
let cashoutAmount = input.amount;
|
|
1574
1692
|
if (input.source) {
|
|
@@ -1644,7 +1762,7 @@ function createCashClient(options) {
|
|
|
1644
1762
|
const mapped = mapChainError("createDeposit", err, {
|
|
1645
1763
|
requiredAmount: depositInput2.amount
|
|
1646
1764
|
});
|
|
1647
|
-
if (isKnownPreBroadcastFailure(
|
|
1765
|
+
if (isKnownPreBroadcastFailure(mapped)) {
|
|
1648
1766
|
throw errors.sourceRouteCompletedCashoutFailed(routedSource, mapped);
|
|
1649
1767
|
}
|
|
1650
1768
|
throw errors.sourceCashoutSubmissionUnknown(routedSource, owner, mapped);
|
|
@@ -1700,7 +1818,7 @@ function createCashClient(options) {
|
|
|
1700
1818
|
const mapped = mapChainError("createDeposit", err, {
|
|
1701
1819
|
requiredAmount: depositInput.amount
|
|
1702
1820
|
});
|
|
1703
|
-
if (isKnownPreBroadcastFailure(
|
|
1821
|
+
if (isKnownPreBroadcastFailure(mapped)) throw mapped;
|
|
1704
1822
|
throw errors.transactionSubmissionUnknown("cashout", err, {
|
|
1705
1823
|
kind: "inspect-base-cashout-submission",
|
|
1706
1824
|
amount: depositInput.amount.toString(),
|
|
@@ -1768,6 +1886,32 @@ function createCashClient(options) {
|
|
|
1768
1886
|
register: { hashedOnchainIds }
|
|
1769
1887
|
};
|
|
1770
1888
|
},
|
|
1889
|
+
finalizePreparedCashout(receipt) {
|
|
1890
|
+
if (receipt.status === "reverted") {
|
|
1891
|
+
throw errors.transactionFailed(receipt.transactionHash);
|
|
1892
|
+
}
|
|
1893
|
+
const abi = readClient.escrowV2Abi ?? readClient.escrowAbi;
|
|
1894
|
+
const expectedEscrowAddress = readClient.escrowV2Address ?? readClient.escrowAddress;
|
|
1895
|
+
const resolved = resolveCashDepositId({
|
|
1896
|
+
logs: receipt.logs,
|
|
1897
|
+
abi,
|
|
1898
|
+
expectedEscrowAddress,
|
|
1899
|
+
expectedToken: BASE_USDC_ADDRESS
|
|
1900
|
+
});
|
|
1901
|
+
if (!resolved || resolved.amount === void 0) {
|
|
1902
|
+
throw errors.depositResolutionFailed(receipt.transactionHash);
|
|
1903
|
+
}
|
|
1904
|
+
return {
|
|
1905
|
+
depositId: resolved.compositeId,
|
|
1906
|
+
txHash: receipt.transactionHash,
|
|
1907
|
+
escrowAddress: resolved.escrowAddress,
|
|
1908
|
+
onchainDepositId: resolved.onchainDepositId,
|
|
1909
|
+
order: deriveCashOrder(resolved.compositeId, [], {
|
|
1910
|
+
remainingAmount: resolved.amount,
|
|
1911
|
+
status: "ACTIVE"
|
|
1912
|
+
})
|
|
1913
|
+
};
|
|
1914
|
+
},
|
|
1771
1915
|
async order(depositId) {
|
|
1772
1916
|
return fetchOrder(depositId);
|
|
1773
1917
|
},
|
|
@@ -2284,6 +2428,7 @@ var CASH_ERROR_CODES = defineCashErrorCodes([
|
|
|
2284
2428
|
"UNSUPPORTED_PLATFORM_CURRENCY",
|
|
2285
2429
|
"AMOUNT_BELOW_MINIMUM",
|
|
2286
2430
|
"INVALID_INTENT_AMOUNT_RANGE",
|
|
2431
|
+
"INVALID_PAYOUT_CURRENCIES",
|
|
2287
2432
|
"ACTIVE_INTENT_BLOCKS_WITHDRAWAL",
|
|
2288
2433
|
"NOTHING_TO_WITHDRAW",
|
|
2289
2434
|
"INSUFFICIENT_AVAILABLE_FUNDS",
|
|
@@ -2312,6 +2457,7 @@ var CASH_ERROR_CODES = defineCashErrorCodes([
|
|
|
2312
2457
|
"SIGNER_CHAIN_MISMATCH",
|
|
2313
2458
|
"SIGNER_CHAIN_UNAVAILABLE",
|
|
2314
2459
|
"WATCH_TIMEOUT",
|
|
2460
|
+
"TRANSACTION_REJECTED",
|
|
2315
2461
|
"TRANSACTION_FAILED",
|
|
2316
2462
|
"TRANSACTION_SUBMISSION_UNKNOWN",
|
|
2317
2463
|
"TRANSACTION_STATUS_UNKNOWN"
|
|
@@ -2765,4 +2911,4 @@ function cashErrorFromJson(json) {
|
|
|
2765
2911
|
});
|
|
2766
2912
|
}
|
|
2767
2913
|
|
|
2768
|
-
export { CASH_ATTRIBUTION_CODE, MIN_CASHOUT_AMOUNT, RATE_PRECISION, RECOMMENDED_MIN_CASHOUT_AMOUNT, bigintString, buildCapabilities, buildIntentAmountRange, buildMarketRateCurrencyOverride, buyerProfileFromJson, buyerProfileToJson, capabilitiesFromJson, capabilitiesToJson, cashAssetJsonSchema, cashBuyerProfileJsonSchema, cashCapabilitiesJsonSchema, cashChainJsonSchema, cashErrorFromJson, cashErrorJsonSchema, cashErrorRecoveryJsonSchema, cashErrorToJson, cashEstimateJsonSchema, cashFillJsonSchema, cashFillStatsJsonSchema, cashNextActionSchema, cashOrderJsonSchema, cashOrderStateSchema, cashPairFillStatsJsonSchema, cashPayoutInfoJsonSchema, cashPayoutPricingJsonSchema, cashPreparedStepJsonSchema, cashSourceCapabilitiesJsonSchema, cashoutResultFromJson, cashoutResultJsonSchema, cashoutResultToJson, centsToNumber, createCashClient, deriveBuyerProfile, deriveCashOrder, derivePayouts, estimateFromJson, estimateToJson, explainOrder, fiatFromUsdc, fiatToNumber, fillFromJson, fillStatsFromJson, fillStatsToJson, fillToJson, formatUsdc, intentStatusSchema, isFillLive, isMarketRateSupported, nonNegativeBigintString, orderFromJson, orderToJson, parseCompositeDepositId, prepareCashDepositParams, prepareResultFromJson, prepareResultJsonSchema, prepareResultToJson, preparedStepFromJson, preparedStepToJson, preparedTransactionJsonSchema, preparedTxFromJson, preparedTxToJson, rateToNumber, relayExecutionResultFromJson, relayExecutionResultJsonSchema, relayExecutionResultToJson, relayQuoteFromJson, relayQuoteJsonSchema, relayQuoteToJson, relayStatusFromJson, relayStatusJsonSchema, relayStatusToJson, relayTransactionJsonSchema, relayTransactionsJsonSchema, resolveCashDepositId, sourceCapabilitiesFromJson, sourceCapabilitiesToJson, topUpResultFromJson, topUpResultJsonSchema, topUpResultToJson, usdc, withExplain, withdrawResultFromJson, withdrawResultJsonSchema, withdrawResultToJson };
|
|
2914
|
+
export { CASH_ATTRIBUTION_CODE, MIN_CASHOUT_AMOUNT, RATE_PRECISION, RECOMMENDED_MIN_CASHOUT_AMOUNT, bigintString, buildCapabilities, buildIntentAmountRange, buildMarketRateCurrencyOverride, buyerProfileFromJson, buyerProfileToJson, capabilitiesFromJson, capabilitiesToJson, cashAssetJsonSchema, cashBuyerProfileJsonSchema, cashCapabilitiesJsonSchema, cashChainJsonSchema, cashErrorFromJson, cashErrorJsonSchema, cashErrorRecoveryJsonSchema, cashErrorToJson, cashEstimateJsonSchema, cashFillJsonSchema, cashFillStatsJsonSchema, cashNextActionSchema, cashOrderJsonSchema, cashOrderStateSchema, cashPairFillStatsJsonSchema, cashPayoutInfoJsonSchema, cashPayoutPricingJsonSchema, cashPreparedStepJsonSchema, cashSourceCapabilitiesJsonSchema, cashoutResultFromJson, cashoutResultJsonSchema, cashoutResultToJson, centsToNumber, createCashClient, deriveBuyerProfile, deriveCashOrder, derivePayouts, estimateFromJson, estimateToJson, explainOrder, fiatFromUsdc, fiatToNumber, fillFromJson, fillStatsFromJson, fillStatsToJson, fillToJson, formatUsdc, intentStatusSchema, isFillLive, isMarketRateSupported, nonNegativeBigintString, normalizeCashPayee, orderFromJson, orderToJson, parseCompositeDepositId, prepareCashDepositParams, prepareResultFromJson, prepareResultJsonSchema, prepareResultToJson, preparedStepFromJson, preparedStepToJson, preparedTransactionJsonSchema, preparedTxFromJson, preparedTxToJson, rateToNumber, relayExecutionResultFromJson, relayExecutionResultJsonSchema, relayExecutionResultToJson, relayQuoteFromJson, relayQuoteJsonSchema, relayQuoteToJson, relayStatusFromJson, relayStatusJsonSchema, relayStatusToJson, relayTransactionJsonSchema, relayTransactionsJsonSchema, resolveCashDepositId, sourceCapabilitiesFromJson, sourceCapabilitiesToJson, topUpResultFromJson, topUpResultJsonSchema, topUpResultToJson, usdc, withExplain, withdrawResultFromJson, withdrawResultJsonSchema, withdrawResultToJson };
|
package/dist/react.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CurrencyType } from '@zkp2p/sdk';
|
|
2
|
-
import { r as CashClient,
|
|
2
|
+
import { r as CashClient, J as EstimateInput, i as CashEstimate, G as CashoutOptions, h as CashoutResult, F as CashoutInput, T as TopUpResult, W as WithdrawResult, e as CashOrder } from './createCashClient-DGMd8Swr.cjs';
|
|
3
3
|
import { WalletClient } from 'viem';
|
|
4
4
|
import '@relayprotocol/relay-sdk';
|
|
5
5
|
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CurrencyType } from '@zkp2p/sdk';
|
|
2
|
-
import { r as CashClient,
|
|
2
|
+
import { r as CashClient, J as EstimateInput, i as CashEstimate, G as CashoutOptions, h as CashoutResult, F as CashoutInput, T as TopUpResult, W as WithdrawResult, e as CashOrder } from './createCashClient-DGMd8Swr.js';
|
|
3
3
|
import { WalletClient } from 'viem';
|
|
4
4
|
import '@relayprotocol/relay-sdk';
|
|
5
5
|
|
package/dist/react.js
CHANGED
package/dist/tools.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// package.json
|
|
4
4
|
var package_default = {
|
|
5
|
-
version: "0.
|
|
5
|
+
version: "0.3.0-rc.0"};
|
|
6
6
|
|
|
7
7
|
// src/tools/index.ts
|
|
8
8
|
var bigintString = {
|
|
@@ -137,20 +137,36 @@ var builtInCashTools = [
|
|
|
137
137
|
description: 'Platform id from cash_capabilities, e.g. "venmo"'
|
|
138
138
|
},
|
|
139
139
|
currency: { type: "string", description: 'Fiat currency code, e.g. "USD"' },
|
|
140
|
+
currencies: {
|
|
141
|
+
type: "array",
|
|
142
|
+
minItems: 1,
|
|
143
|
+
uniqueItems: true,
|
|
144
|
+
items: { type: "string" },
|
|
145
|
+
description: 'Fiat currency choices for one payment method, e.g. ["EUR", "GBP"]'
|
|
146
|
+
},
|
|
140
147
|
payee: {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
offchainId: {
|
|
148
|
+
description: "Raw payee handle or structured curator payee data",
|
|
149
|
+
oneOf: [
|
|
150
|
+
{
|
|
145
151
|
type: "string",
|
|
146
|
-
description: '
|
|
152
|
+
description: 'User-entered handle, e.g. "@andrew" for Venmo; Peer Cash normalizes it for the selected platform'
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
type: "object",
|
|
156
|
+
properties: {
|
|
157
|
+
offchainId: {
|
|
158
|
+
type: "string",
|
|
159
|
+
description: "Already-normalized handle for the platform"
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
required: ["offchainId"],
|
|
163
|
+
additionalProperties: true
|
|
147
164
|
}
|
|
148
|
-
|
|
149
|
-
required: ["offchainId"],
|
|
150
|
-
additionalProperties: true
|
|
165
|
+
]
|
|
151
166
|
}
|
|
152
167
|
},
|
|
153
|
-
required: ["platform", "
|
|
168
|
+
required: ["platform", "payee"],
|
|
169
|
+
oneOf: [{ required: ["currency"] }, { required: ["currencies"] }],
|
|
154
170
|
additionalProperties: false
|
|
155
171
|
}
|
|
156
172
|
},
|