@zkp2p/cash 0.2.0 → 0.2.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/AGENTS.md +19 -2
- package/README.md +44 -2
- package/dist/{chunk-TR6JVYYF.js → chunk-5VBP3IWK.js} +59 -2
- package/dist/{createCashClient-CTEXn9FF.d.cts → createCashClient-Clg5Fa1H.d.cts} +39 -12
- package/dist/{createCashClient-CTEXn9FF.d.ts → createCashClient-Clg5Fa1H.d.ts} +39 -12
- package/dist/index.cjs +209 -38
- package/dist/index.d.cts +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.js +152 -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 +5 -1
- package/package.json +1 -1
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-Clg5Fa1H.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-Clg5Fa1H.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): {
|
|
@@ -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) {
|
|
@@ -1124,6 +1162,36 @@ async function readEstimate(publicClient, input, context = {}) {
|
|
|
1124
1162
|
return estimate;
|
|
1125
1163
|
}
|
|
1126
1164
|
|
|
1165
|
+
// src/client/payee.ts
|
|
1166
|
+
function normalizePaypalHandle(value) {
|
|
1167
|
+
const withoutProtocol = value.replace(/^https?:\/\//i, "").replace(/^www\./i, "");
|
|
1168
|
+
if (/^paypal\.me(?:[?#].*)?$/i.test(withoutProtocol)) return "";
|
|
1169
|
+
const withoutDomain = withoutProtocol.replace(/^paypal\.me\//i, "");
|
|
1170
|
+
const [pathWithoutQuery = ""] = withoutDomain.split(/[?#]/, 1);
|
|
1171
|
+
const [username = ""] = pathWithoutQuery.replace(/^\/+/, "").split("/", 1);
|
|
1172
|
+
return username.replace(/^@+/, "").trim().toLowerCase();
|
|
1173
|
+
}
|
|
1174
|
+
function normalizeCashPayee(platform, payee) {
|
|
1175
|
+
if (typeof payee !== "string") return payee;
|
|
1176
|
+
const trimmed = payee.trim();
|
|
1177
|
+
switch (platform) {
|
|
1178
|
+
case "venmo":
|
|
1179
|
+
return { offchainId: trimmed.replace(/^@+/, "") };
|
|
1180
|
+
case "cashapp":
|
|
1181
|
+
return { offchainId: trimmed.replace(/^\$+/, "") };
|
|
1182
|
+
case "chime":
|
|
1183
|
+
return { offchainId: trimmed.toLowerCase() };
|
|
1184
|
+
case "n26":
|
|
1185
|
+
return { offchainId: trimmed.replace(/\s/g, "") };
|
|
1186
|
+
case "paypal":
|
|
1187
|
+
return { offchainId: normalizePaypalHandle(trimmed) };
|
|
1188
|
+
case "zelle":
|
|
1189
|
+
return { offchainId: trimmed.toLowerCase() };
|
|
1190
|
+
default:
|
|
1191
|
+
return { offchainId: trimmed };
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1127
1195
|
// src/client/createCashClient.ts
|
|
1128
1196
|
var DEFAULT_RPC_URL = "https://mainnet.base.org";
|
|
1129
1197
|
var FILL_STATS_CACHE_MS = 15 * 60 * 1e3;
|
|
@@ -1165,7 +1233,7 @@ async function submitAndConfirm(client, verb, send) {
|
|
|
1165
1233
|
hash = await send();
|
|
1166
1234
|
} catch (err) {
|
|
1167
1235
|
const mapped = mapChainError(verb, err);
|
|
1168
|
-
if (isKnownPreBroadcastFailure(
|
|
1236
|
+
if (isKnownPreBroadcastFailure(mapped)) throw mapped;
|
|
1169
1237
|
throw errors.transactionSubmissionUnknown(verb, err, {
|
|
1170
1238
|
kind: "inspect-base-operation-submission",
|
|
1171
1239
|
operation: verb
|
|
@@ -1180,12 +1248,8 @@ async function submitAndConfirm(client, verb, send) {
|
|
|
1180
1248
|
if (receipt.status === "reverted") throw errors.transactionFailed(hash);
|
|
1181
1249
|
return hash;
|
|
1182
1250
|
}
|
|
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);
|
|
1251
|
+
function isKnownPreBroadcastFailure(mapped) {
|
|
1252
|
+
return mapped.code === "TRANSACTION_REJECTED" || mapped.code === "INSUFFICIENT_TOKEN_BALANCE" || mapped.code === "ALLOWANCE_NOT_VISIBLE" || mapped.code === "ESCROW_PAUSED";
|
|
1189
1253
|
}
|
|
1190
1254
|
function depositOrderOptions(deposit) {
|
|
1191
1255
|
const remaining = toBigIntOrUndefined(deposit.remainingDeposits);
|
|
@@ -1262,18 +1326,33 @@ function createCashClient(options) {
|
|
|
1262
1326
|
(capability) => capability.platform === receive.platform
|
|
1263
1327
|
);
|
|
1264
1328
|
if (!platform) throw errors.unsupportedPlatform(receive.platform);
|
|
1265
|
-
if (
|
|
1266
|
-
throw errors.
|
|
1329
|
+
if (receive.currency === void 0 === (receive.currencies === void 0)) {
|
|
1330
|
+
throw errors.invalidPayoutCurrencies(
|
|
1331
|
+
receive.platform,
|
|
1332
|
+
"pass exactly one of currency or currencies"
|
|
1333
|
+
);
|
|
1267
1334
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1335
|
+
const currencies = receive.currencies !== void 0 ? [...receive.currencies] : [receive.currency];
|
|
1336
|
+
if (currencies.length === 0) {
|
|
1337
|
+
throw errors.invalidPayoutCurrencies(receive.platform, "at least one currency is required");
|
|
1338
|
+
}
|
|
1339
|
+
if (new Set(currencies).size !== currencies.length) {
|
|
1340
|
+
throw errors.invalidPayoutCurrencies(receive.platform, "currencies must be unique");
|
|
1341
|
+
}
|
|
1342
|
+
for (const currency of currencies) {
|
|
1343
|
+
if (!isMarketRateSupported(currency)) {
|
|
1344
|
+
throw errors.oracleUnsupportedCurrency(currency);
|
|
1345
|
+
}
|
|
1346
|
+
if (!platform.currencies.includes(currency)) {
|
|
1347
|
+
throw errors.unsupportedPlatformCurrency(receive.platform, currency);
|
|
1348
|
+
}
|
|
1270
1349
|
}
|
|
1271
1350
|
return {
|
|
1272
1351
|
payouts: [
|
|
1273
1352
|
{
|
|
1274
1353
|
processorName: receive.platform,
|
|
1275
|
-
currency:
|
|
1276
|
-
payeeData: receive.payee
|
|
1354
|
+
...currencies.length === 1 ? { currency: currencies[0] } : { currencies },
|
|
1355
|
+
payeeData: normalizeCashPayee(receive.platform, receive.payee)
|
|
1277
1356
|
}
|
|
1278
1357
|
]
|
|
1279
1358
|
};
|
|
@@ -1293,7 +1372,12 @@ function createCashClient(options) {
|
|
|
1293
1372
|
};
|
|
1294
1373
|
}
|
|
1295
1374
|
function isCashPayoutSet(payouts) {
|
|
1296
|
-
|
|
1375
|
+
const first = payouts[0];
|
|
1376
|
+
return Boolean(
|
|
1377
|
+
first && payouts.every(
|
|
1378
|
+
(payout) => payout.platformHash.toLowerCase() === first.platformHash.toLowerCase() && payout.payeeHash.toLowerCase() === first.payeeHash.toLowerCase() && payout.pricing.marketRate && payout.pricing.spreadBps === 0
|
|
1379
|
+
)
|
|
1380
|
+
);
|
|
1297
1381
|
}
|
|
1298
1382
|
async function buildDepositParams(client, depositInput) {
|
|
1299
1383
|
try {
|
|
@@ -1566,9 +1650,9 @@ function createCashClient(options) {
|
|
|
1566
1650
|
}
|
|
1567
1651
|
},
|
|
1568
1652
|
async cashout(input, opts) {
|
|
1653
|
+
const payoutInput = validatePayout(input);
|
|
1569
1654
|
const client = await signingClient("cashout", opts);
|
|
1570
1655
|
const owner = opts.signer.account.address;
|
|
1571
|
-
const payoutInput = validatePayout(input);
|
|
1572
1656
|
let sourceResult;
|
|
1573
1657
|
let cashoutAmount = input.amount;
|
|
1574
1658
|
if (input.source) {
|
|
@@ -1644,7 +1728,7 @@ function createCashClient(options) {
|
|
|
1644
1728
|
const mapped = mapChainError("createDeposit", err, {
|
|
1645
1729
|
requiredAmount: depositInput2.amount
|
|
1646
1730
|
});
|
|
1647
|
-
if (isKnownPreBroadcastFailure(
|
|
1731
|
+
if (isKnownPreBroadcastFailure(mapped)) {
|
|
1648
1732
|
throw errors.sourceRouteCompletedCashoutFailed(routedSource, mapped);
|
|
1649
1733
|
}
|
|
1650
1734
|
throw errors.sourceCashoutSubmissionUnknown(routedSource, owner, mapped);
|
|
@@ -1700,7 +1784,7 @@ function createCashClient(options) {
|
|
|
1700
1784
|
const mapped = mapChainError("createDeposit", err, {
|
|
1701
1785
|
requiredAmount: depositInput.amount
|
|
1702
1786
|
});
|
|
1703
|
-
if (isKnownPreBroadcastFailure(
|
|
1787
|
+
if (isKnownPreBroadcastFailure(mapped)) throw mapped;
|
|
1704
1788
|
throw errors.transactionSubmissionUnknown("cashout", err, {
|
|
1705
1789
|
kind: "inspect-base-cashout-submission",
|
|
1706
1790
|
amount: depositInput.amount.toString(),
|
|
@@ -1768,6 +1852,32 @@ function createCashClient(options) {
|
|
|
1768
1852
|
register: { hashedOnchainIds }
|
|
1769
1853
|
};
|
|
1770
1854
|
},
|
|
1855
|
+
finalizePreparedCashout(receipt) {
|
|
1856
|
+
if (receipt.status === "reverted") {
|
|
1857
|
+
throw errors.transactionFailed(receipt.transactionHash);
|
|
1858
|
+
}
|
|
1859
|
+
const abi = readClient.escrowV2Abi ?? readClient.escrowAbi;
|
|
1860
|
+
const expectedEscrowAddress = readClient.escrowV2Address ?? readClient.escrowAddress;
|
|
1861
|
+
const resolved = resolveCashDepositId({
|
|
1862
|
+
logs: receipt.logs,
|
|
1863
|
+
abi,
|
|
1864
|
+
expectedEscrowAddress,
|
|
1865
|
+
expectedToken: BASE_USDC_ADDRESS
|
|
1866
|
+
});
|
|
1867
|
+
if (!resolved || resolved.amount === void 0) {
|
|
1868
|
+
throw errors.depositResolutionFailed(receipt.transactionHash);
|
|
1869
|
+
}
|
|
1870
|
+
return {
|
|
1871
|
+
depositId: resolved.compositeId,
|
|
1872
|
+
txHash: receipt.transactionHash,
|
|
1873
|
+
escrowAddress: resolved.escrowAddress,
|
|
1874
|
+
onchainDepositId: resolved.onchainDepositId,
|
|
1875
|
+
order: deriveCashOrder(resolved.compositeId, [], {
|
|
1876
|
+
remainingAmount: resolved.amount,
|
|
1877
|
+
status: "ACTIVE"
|
|
1878
|
+
})
|
|
1879
|
+
};
|
|
1880
|
+
},
|
|
1771
1881
|
async order(depositId) {
|
|
1772
1882
|
return fetchOrder(depositId);
|
|
1773
1883
|
},
|
|
@@ -2284,6 +2394,7 @@ var CASH_ERROR_CODES = defineCashErrorCodes([
|
|
|
2284
2394
|
"UNSUPPORTED_PLATFORM_CURRENCY",
|
|
2285
2395
|
"AMOUNT_BELOW_MINIMUM",
|
|
2286
2396
|
"INVALID_INTENT_AMOUNT_RANGE",
|
|
2397
|
+
"INVALID_PAYOUT_CURRENCIES",
|
|
2287
2398
|
"ACTIVE_INTENT_BLOCKS_WITHDRAWAL",
|
|
2288
2399
|
"NOTHING_TO_WITHDRAW",
|
|
2289
2400
|
"INSUFFICIENT_AVAILABLE_FUNDS",
|
|
@@ -2312,6 +2423,7 @@ var CASH_ERROR_CODES = defineCashErrorCodes([
|
|
|
2312
2423
|
"SIGNER_CHAIN_MISMATCH",
|
|
2313
2424
|
"SIGNER_CHAIN_UNAVAILABLE",
|
|
2314
2425
|
"WATCH_TIMEOUT",
|
|
2426
|
+
"TRANSACTION_REJECTED",
|
|
2315
2427
|
"TRANSACTION_FAILED",
|
|
2316
2428
|
"TRANSACTION_SUBMISSION_UNKNOWN",
|
|
2317
2429
|
"TRANSACTION_STATUS_UNKNOWN"
|
|
@@ -2765,4 +2877,4 @@ function cashErrorFromJson(json) {
|
|
|
2765
2877
|
});
|
|
2766
2878
|
}
|
|
2767
2879
|
|
|
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 };
|
|
2880
|
+
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-Clg5Fa1H.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-Clg5Fa1H.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.2.
|
|
5
|
+
version: "0.2.1"};
|
|
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
|
},
|
package/dist/tools.d.cts
CHANGED
|
@@ -166,20 +166,39 @@ declare const builtInCashTools: readonly [{
|
|
|
166
166
|
readonly type: "string";
|
|
167
167
|
readonly description: "Fiat currency code, e.g. \"USD\"";
|
|
168
168
|
};
|
|
169
|
+
readonly currencies: {
|
|
170
|
+
readonly type: "array";
|
|
171
|
+
readonly minItems: 1;
|
|
172
|
+
readonly uniqueItems: true;
|
|
173
|
+
readonly items: {
|
|
174
|
+
readonly type: "string";
|
|
175
|
+
};
|
|
176
|
+
readonly description: "Fiat currency choices for one payment method, e.g. [\"EUR\", \"GBP\"]";
|
|
177
|
+
};
|
|
169
178
|
readonly payee: {
|
|
170
|
-
readonly
|
|
171
|
-
readonly
|
|
172
|
-
|
|
173
|
-
readonly
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
readonly description: "Raw payee handle or structured curator payee data";
|
|
180
|
+
readonly oneOf: readonly [{
|
|
181
|
+
readonly type: "string";
|
|
182
|
+
readonly description: "User-entered handle, e.g. \"@andrew\" for Venmo; Peer Cash normalizes it for the selected platform";
|
|
183
|
+
}, {
|
|
184
|
+
readonly type: "object";
|
|
185
|
+
readonly properties: {
|
|
186
|
+
readonly offchainId: {
|
|
187
|
+
readonly type: "string";
|
|
188
|
+
readonly description: "Already-normalized handle for the platform";
|
|
189
|
+
};
|
|
176
190
|
};
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
191
|
+
readonly required: readonly ["offchainId"];
|
|
192
|
+
readonly additionalProperties: true;
|
|
193
|
+
}];
|
|
180
194
|
};
|
|
181
195
|
};
|
|
182
|
-
readonly required: readonly ["platform", "
|
|
196
|
+
readonly required: readonly ["platform", "payee"];
|
|
197
|
+
readonly oneOf: readonly [{
|
|
198
|
+
readonly required: readonly ["currency"];
|
|
199
|
+
}, {
|
|
200
|
+
readonly required: readonly ["currencies"];
|
|
201
|
+
}];
|
|
183
202
|
readonly additionalProperties: false;
|
|
184
203
|
};
|
|
185
204
|
};
|
package/dist/tools.d.ts
CHANGED
|
@@ -166,20 +166,39 @@ declare const builtInCashTools: readonly [{
|
|
|
166
166
|
readonly type: "string";
|
|
167
167
|
readonly description: "Fiat currency code, e.g. \"USD\"";
|
|
168
168
|
};
|
|
169
|
+
readonly currencies: {
|
|
170
|
+
readonly type: "array";
|
|
171
|
+
readonly minItems: 1;
|
|
172
|
+
readonly uniqueItems: true;
|
|
173
|
+
readonly items: {
|
|
174
|
+
readonly type: "string";
|
|
175
|
+
};
|
|
176
|
+
readonly description: "Fiat currency choices for one payment method, e.g. [\"EUR\", \"GBP\"]";
|
|
177
|
+
};
|
|
169
178
|
readonly payee: {
|
|
170
|
-
readonly
|
|
171
|
-
readonly
|
|
172
|
-
|
|
173
|
-
readonly
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
readonly description: "Raw payee handle or structured curator payee data";
|
|
180
|
+
readonly oneOf: readonly [{
|
|
181
|
+
readonly type: "string";
|
|
182
|
+
readonly description: "User-entered handle, e.g. \"@andrew\" for Venmo; Peer Cash normalizes it for the selected platform";
|
|
183
|
+
}, {
|
|
184
|
+
readonly type: "object";
|
|
185
|
+
readonly properties: {
|
|
186
|
+
readonly offchainId: {
|
|
187
|
+
readonly type: "string";
|
|
188
|
+
readonly description: "Already-normalized handle for the platform";
|
|
189
|
+
};
|
|
176
190
|
};
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
191
|
+
readonly required: readonly ["offchainId"];
|
|
192
|
+
readonly additionalProperties: true;
|
|
193
|
+
}];
|
|
180
194
|
};
|
|
181
195
|
};
|
|
182
|
-
readonly required: readonly ["platform", "
|
|
196
|
+
readonly required: readonly ["platform", "payee"];
|
|
197
|
+
readonly oneOf: readonly [{
|
|
198
|
+
readonly required: readonly ["currency"];
|
|
199
|
+
}, {
|
|
200
|
+
readonly required: readonly ["currencies"];
|
|
201
|
+
}];
|
|
183
202
|
readonly additionalProperties: false;
|
|
184
203
|
};
|
|
185
204
|
};
|