@zkp2p/sdk 0.1.0 → 0.2.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/README.md +382 -120
- package/dist/{chunk-JH74HXTS.mjs → chunk-J33LUXNA.mjs} +7 -24
- package/dist/chunk-J33LUXNA.mjs.map +1 -0
- package/dist/{chunk-YLITJ7SI.mjs → chunk-LPJE2MN7.mjs} +11 -48
- package/dist/chunk-LPJE2MN7.mjs.map +1 -0
- package/dist/index.cjs +274 -300
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +5 -16
- package/dist/index.d.ts +5 -16
- package/dist/index.mjs +276 -270
- package/dist/index.mjs.map +1 -1
- package/dist/protocolViewerParsers-VVASNOXW.mjs +4 -0
- package/dist/{protocolViewerParsers-QVG4JP23.mjs.map → protocolViewerParsers-VVASNOXW.mjs.map} +1 -1
- package/dist/react.cjs +9 -54
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.mjs +2 -2
- package/dist/{vaultUtils-J1WboG1T.d.mts → vaultUtils-zw4Xgu-G.d.mts} +27 -38
- package/dist/{vaultUtils-J1WboG1T.d.ts → vaultUtils-zw4Xgu-G.d.ts} +27 -38
- package/package.json +18 -18
- package/dist/chunk-JH74HXTS.mjs.map +0 -1
- package/dist/chunk-YLITJ7SI.mjs.map +0 -1
- package/dist/protocolViewerParsers-QVG4JP23.mjs +0 -4
package/dist/react.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Z as Zkp2pClient, i as SignalIntentMethodParams, ac as PreparedTransaction, af as TakerTier, f as GetTakerTierRequest, g as GetTakerTierResponse, F as FulfillIntentMethodParams,
|
|
2
|
-
export {
|
|
1
|
+
import { Z as Zkp2pClient, i as SignalIntentMethodParams, ac as PreparedTransaction, af as TakerTier, f as GetTakerTierRequest, g as GetTakerTierResponse, F as FulfillIntentMethodParams, bv as SendTransactionFn, bw as SendBatchFn, bt as DelegationDepositTarget, bu as BatchResult } from './vaultUtils-zw4Xgu-G.mjs';
|
|
2
|
+
export { br as DelegationRoute, bs as DelegationState, bx as VAULT_ZERO_ADDRESS, bl as ZERO_RATE_MANAGER_ID, by as asErrorMessage, bz as assertDelegationMethodSupport, bq as classifyDelegationState, bp as getDelegationRoute, bm as isZeroRateManagerId, bn as normalizeRateManagerId, bo as normalizeRegistry } from './vaultUtils-zw4Xgu-G.mjs';
|
|
3
3
|
import { Hash, Address, Hex } from 'viem';
|
|
4
4
|
import '@zkp2p/indexer-schema';
|
|
5
5
|
import 'abitype';
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Z as Zkp2pClient, i as SignalIntentMethodParams, ac as PreparedTransaction, af as TakerTier, f as GetTakerTierRequest, g as GetTakerTierResponse, F as FulfillIntentMethodParams,
|
|
2
|
-
export {
|
|
1
|
+
import { Z as Zkp2pClient, i as SignalIntentMethodParams, ac as PreparedTransaction, af as TakerTier, f as GetTakerTierRequest, g as GetTakerTierResponse, F as FulfillIntentMethodParams, bv as SendTransactionFn, bw as SendBatchFn, bt as DelegationDepositTarget, bu as BatchResult } from './vaultUtils-zw4Xgu-G.js';
|
|
2
|
+
export { br as DelegationRoute, bs as DelegationState, bx as VAULT_ZERO_ADDRESS, bl as ZERO_RATE_MANAGER_ID, by as asErrorMessage, bz as assertDelegationMethodSupport, bq as classifyDelegationState, bp as getDelegationRoute, bm as isZeroRateManagerId, bn as normalizeRateManagerId, bo as normalizeRegistry } from './vaultUtils-zw4Xgu-G.js';
|
|
3
3
|
import { Hash, Address, Hex } from 'viem';
|
|
4
4
|
import '@zkp2p/indexer-schema';
|
|
5
5
|
import 'abitype';
|
package/dist/react.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { asErrorMessage, ZERO_ADDRESS, getDelegationRoute, assertDelegationMethodSupport, prepareClearDelegationTx, normalizeRateManagerId, normalizeRegistry, isZeroRateManagerId, assertAtomicDelegationSwitchSupport, prepareSetDelegationTx } from './chunk-
|
|
2
|
-
export { ZERO_ADDRESS as VAULT_ZERO_ADDRESS, ZERO_RATE_MANAGER_ID, asErrorMessage, assertDelegationMethodSupport, classifyDelegationState, getDelegationRoute, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-
|
|
1
|
+
import { asErrorMessage, ZERO_ADDRESS, getDelegationRoute, assertDelegationMethodSupport, prepareClearDelegationTx, normalizeRateManagerId, normalizeRegistry, isZeroRateManagerId, assertAtomicDelegationSwitchSupport, prepareSetDelegationTx } from './chunk-LPJE2MN7.mjs';
|
|
2
|
+
export { ZERO_ADDRESS as VAULT_ZERO_ADDRESS, ZERO_RATE_MANAGER_ID, asErrorMessage, assertDelegationMethodSupport, classifyDelegationState, getDelegationRoute, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-LPJE2MN7.mjs';
|
|
3
3
|
import { useState, useCallback, useMemo, useEffect } from 'react';
|
|
4
4
|
import { formatUnits } from 'viem';
|
|
5
5
|
|
|
@@ -170,13 +170,13 @@ type V2ContractAddresses = {
|
|
|
170
170
|
escrow: `0x${string}`;
|
|
171
171
|
/** EscrowV2 contract (supports native rate-manager delegation) */
|
|
172
172
|
escrowV2?: `0x${string}`;
|
|
173
|
-
/** All supported escrow addresses (
|
|
173
|
+
/** All supported upgraded escrow addresses (current first, then historical) */
|
|
174
174
|
escrowAddresses?: `0x${string}`[];
|
|
175
175
|
/** Orchestrator contract (handles intent signaling and fulfillment) */
|
|
176
176
|
orchestrator?: `0x${string}`;
|
|
177
177
|
/** OrchestratorV2 contract (queries EscrowV2 effective rates) */
|
|
178
178
|
orchestratorV2?: `0x${string}`;
|
|
179
|
-
/** All supported orchestrator addresses (
|
|
179
|
+
/** All supported upgraded orchestrator addresses (current first, then historical) */
|
|
180
180
|
orchestratorAddresses?: `0x${string}`[];
|
|
181
181
|
/** UnifiedPaymentVerifier contract (verifies payment proofs) */
|
|
182
182
|
unifiedPaymentVerifier?: `0x${string}`;
|
|
@@ -481,7 +481,9 @@ interface RateManagerDelegationEntity {
|
|
|
481
481
|
createdAt: string;
|
|
482
482
|
updatedAt: string;
|
|
483
483
|
}
|
|
484
|
-
type ManagerAggregateStatsEntity = ManagerAggregateStats
|
|
484
|
+
type ManagerAggregateStatsEntity = WithOverrides<ManagerAggregateStats, {
|
|
485
|
+
rateManagerAddress?: string | null;
|
|
486
|
+
}>;
|
|
485
487
|
type ManagerStatsEntity = ManagerStats;
|
|
486
488
|
type ManagerDailySnapshotEntity = ManagerDailySnapshot;
|
|
487
489
|
interface ManualRateUpdateEntity {
|
|
@@ -632,10 +634,14 @@ type RateManagerDelegationPaginationOptions = Partial<{
|
|
|
632
634
|
orderDirection: OrderDirection;
|
|
633
635
|
rateManagerAddress: string;
|
|
634
636
|
}>;
|
|
637
|
+
declare function compareEventCursorIdsByRecency(leftId?: string | null, rightId?: string | null): number;
|
|
635
638
|
declare class IndexerRateManagerService {
|
|
636
639
|
private client;
|
|
637
640
|
constructor(client: IndexerClient);
|
|
641
|
+
private buildRateManagerScopeWhere;
|
|
638
642
|
private buildWhere;
|
|
643
|
+
private buildAggregateWhere;
|
|
644
|
+
private buildLegacyAggregateWhere;
|
|
639
645
|
private buildOrderBy;
|
|
640
646
|
private toRateManagerListItems;
|
|
641
647
|
private applyHookFilter;
|
|
@@ -734,11 +740,15 @@ type TimeoutConfig = {
|
|
|
734
740
|
type AuthorizationTokenProvider = () => string | null | undefined | Promise<string | null | undefined>;
|
|
735
741
|
type Zkp2pClientOptions = {
|
|
736
742
|
walletClient: WalletClient;
|
|
737
|
-
|
|
743
|
+
/** Curator API key for authenticated endpoints (optional for basic deposit/payee flows) */
|
|
744
|
+
apiKey?: string;
|
|
738
745
|
chainId: number;
|
|
746
|
+
/** Runtime environment (defaults to 'production') */
|
|
747
|
+
runtimeEnv?: 'production' | 'preproduction' | 'staging';
|
|
748
|
+
/**
|
|
749
|
+
* @deprecated Use `runtimeEnv` instead. Kept for backward compatibility.
|
|
750
|
+
*/
|
|
739
751
|
environment?: 'production' | 'staging';
|
|
740
|
-
/** Optional default routing preference when both legacy and V2 contracts are available */
|
|
741
|
-
preferV2ByDefault?: boolean;
|
|
742
752
|
baseApiUrl?: string;
|
|
743
753
|
witnessUrl?: string;
|
|
744
754
|
rpcUrl?: string;
|
|
@@ -746,6 +756,10 @@ type Zkp2pClientOptions = {
|
|
|
746
756
|
authorizationToken?: string;
|
|
747
757
|
/** Optional async token provider for indexer auth in long-lived clients */
|
|
748
758
|
getAuthorizationToken?: AuthorizationTokenProvider;
|
|
759
|
+
/** Optional API key for indexer proxy authentication */
|
|
760
|
+
indexerApiKey?: string;
|
|
761
|
+
/** Optional indexer URL override */
|
|
762
|
+
indexerUrl?: string;
|
|
749
763
|
/** Optional timeout configuration */
|
|
750
764
|
timeouts?: TimeoutConfig;
|
|
751
765
|
};
|
|
@@ -1331,16 +1345,6 @@ type Zkp2pNextOptions = {
|
|
|
1331
1345
|
rpcUrl?: string;
|
|
1332
1346
|
/** Runtime environment: 'production', 'preproduction', or 'staging' (defaults to 'production') */
|
|
1333
1347
|
runtimeEnv?: RuntimeEnv;
|
|
1334
|
-
/**
|
|
1335
|
-
* Controls which contract stack is treated as the default when both legacy and V2
|
|
1336
|
-
* contracts are available.
|
|
1337
|
-
*
|
|
1338
|
-
* - `true`: default to EscrowV2/OrchestratorV2
|
|
1339
|
-
* - `false`: default to legacy Escrow/Orchestrator
|
|
1340
|
-
* - `undefined`: default to the runtime rollout baseline
|
|
1341
|
-
* (`staging` => V2, `production`/`preproduction` => legacy)
|
|
1342
|
-
*/
|
|
1343
|
-
preferV2ByDefault?: boolean;
|
|
1344
1348
|
/** Optional indexer URL override */
|
|
1345
1349
|
indexerUrl?: string;
|
|
1346
1350
|
/** Base API URL for ZKP2P services (defaults to https://api.zkp2p.xyz) */
|
|
@@ -1554,29 +1558,21 @@ declare class Zkp2pClient {
|
|
|
1554
1558
|
readonly escrowAddress: Address;
|
|
1555
1559
|
/** Escrow contract ABI */
|
|
1556
1560
|
readonly escrowAbi: Abi;
|
|
1557
|
-
/** Legacy escrow contract address (if deployed) */
|
|
1558
|
-
readonly legacyEscrowAddress?: Address;
|
|
1559
|
-
/** Legacy escrow ABI */
|
|
1560
|
-
readonly legacyEscrowAbi?: Abi;
|
|
1561
1561
|
/** EscrowV2 contract address (if deployed) */
|
|
1562
1562
|
readonly escrowV2Address?: Address;
|
|
1563
1563
|
/** EscrowV2 ABI */
|
|
1564
1564
|
readonly escrowV2Abi?: Abi;
|
|
1565
|
-
/** All supported escrow addresses (
|
|
1565
|
+
/** All supported upgraded escrow addresses (current first, then historical) */
|
|
1566
1566
|
readonly escrowAddresses: Address[];
|
|
1567
1567
|
/** Orchestrator contract address (handles intent signaling/fulfillment) */
|
|
1568
1568
|
readonly orchestratorAddress?: Address;
|
|
1569
1569
|
/** Orchestrator contract ABI */
|
|
1570
1570
|
readonly orchestratorAbi?: Abi;
|
|
1571
|
-
/** Legacy orchestrator address (if deployed) */
|
|
1572
|
-
readonly legacyOrchestratorAddress?: Address;
|
|
1573
|
-
/** Legacy orchestrator ABI */
|
|
1574
|
-
readonly legacyOrchestratorAbi?: Abi;
|
|
1575
1571
|
/** OrchestratorV2 address (if deployed) */
|
|
1576
1572
|
readonly orchestratorV2Address?: Address;
|
|
1577
1573
|
/** OrchestratorV2 ABI */
|
|
1578
1574
|
readonly orchestratorV2Abi?: Abi;
|
|
1579
|
-
/** All supported orchestrator addresses (
|
|
1575
|
+
/** All supported upgraded orchestrator addresses (current first, then historical) */
|
|
1580
1576
|
readonly orchestratorAddresses: Address[];
|
|
1581
1577
|
/** UnifiedPaymentVerifier contract address */
|
|
1582
1578
|
readonly unifiedPaymentVerifier?: Address;
|
|
@@ -2891,11 +2887,9 @@ declare class Zkp2pClient {
|
|
|
2891
2887
|
escrow: Address;
|
|
2892
2888
|
escrowV2?: Address;
|
|
2893
2889
|
escrowAddresses: Address[];
|
|
2894
|
-
legacyEscrow?: Address;
|
|
2895
2890
|
orchestrator?: Address;
|
|
2896
2891
|
orchestratorV2?: Address;
|
|
2897
2892
|
orchestratorAddresses: Address[];
|
|
2898
|
-
legacyOrchestrator?: Address;
|
|
2899
2893
|
protocolViewer?: Address;
|
|
2900
2894
|
protocolViewerEntries: Address[];
|
|
2901
2895
|
unifiedPaymentVerifier?: Address;
|
|
@@ -2942,17 +2936,12 @@ type DelegationState = 'delegated_here' | 'delegated_elsewhere' | 'not_delegated
|
|
|
2942
2936
|
* @param targetRegistry The vault's registry address we're comparing against
|
|
2943
2937
|
*/
|
|
2944
2938
|
declare const classifyDelegationState: (currentRateManagerId: string | null | undefined, currentRegistry: string | null | undefined, targetRateManagerId: string, targetRegistry: string | null | undefined) => DelegationState;
|
|
2945
|
-
type DelegationRoute = 'v2'
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
escrowV2Address?: Address;
|
|
2949
|
-
legacyEscrowAddress?: Address;
|
|
2950
|
-
}
|
|
2951
|
-
declare const getDelegationRoute: (client: RoutingClientShape, escrow: Address) => DelegationRoute;
|
|
2952
|
-
type DelegationMethodSupportClient = Partial<Record<'setRateManager' | 'clearRateManager' | 'setDepositRateManager' | 'clearDepositRateManager', {
|
|
2939
|
+
type DelegationRoute = 'v2';
|
|
2940
|
+
declare const getDelegationRoute: (_client: unknown, _escrow: Address) => DelegationRoute;
|
|
2941
|
+
type DelegationMethodSupportClient = Partial<Record<'setRateManager' | 'clearRateManager', {
|
|
2953
2942
|
prepare?: unknown;
|
|
2954
2943
|
}>>;
|
|
2955
|
-
declare const assertDelegationMethodSupport: (client: DelegationMethodSupportClient,
|
|
2944
|
+
declare const assertDelegationMethodSupport: (client: DelegationMethodSupportClient, _route: DelegationRoute, action: "set" | "clear") => void;
|
|
2956
2945
|
interface DelegationDepositTarget {
|
|
2957
2946
|
compositeDepositId: string;
|
|
2958
2947
|
escrow: Address;
|
|
@@ -2987,4 +2976,4 @@ type SendBatchFn = (txs: Array<{
|
|
|
2987
2976
|
value?: bigint;
|
|
2988
2977
|
}>) => Promise<string>;
|
|
2989
2978
|
|
|
2990
|
-
export { type GetDepositByIdResponse as $, type AuthorizationTokenProvider as A, type QuoteResponseObject as B, type CurrencyType as C, type DepositWithRelations as D, type QuoteSingleResponse as E, type FulfillIntentMethodParams as F, type GetPayeeDetailsRequest as G, type QuoteIntentResponse as H, type IntentEntity as I, type QuoteFeesResponse as J, type FiatResponse as K, type TokenResponse as L, type NearbySuggestions as M, type NearbyQuote as N, type ApiDeposit as O, type PostDepositDetailsRequest as P, type QuoteRequest as Q, type ReferrerFeeConfig as R, type SignalIntentReferralFee as S, type TxOverrides as T, type DepositVerifier as U, type ValidatePayeeDetailsRequest as V, type WithdrawDepositParams as W, type DepositVerifierCurrency as X, type DepositStatus as Y, Zkp2pClient as Z, type GetDepositByIdRequest as _, type ValidatePayeeDetailsResponse as a,
|
|
2979
|
+
export { type GetDepositByIdResponse as $, type AuthorizationTokenProvider as A, type QuoteResponseObject as B, type CurrencyType as C, type DepositWithRelations as D, type QuoteSingleResponse as E, type FulfillIntentMethodParams as F, type GetPayeeDetailsRequest as G, type QuoteIntentResponse as H, type IntentEntity as I, type QuoteFeesResponse as J, type FiatResponse as K, type TokenResponse as L, type NearbySuggestions as M, type NearbyQuote as N, type ApiDeposit as O, type PostDepositDetailsRequest as P, type QuoteRequest as Q, type ReferrerFeeConfig as R, type SignalIntentReferralFee as S, type TxOverrides as T, type DepositVerifier as U, type ValidatePayeeDetailsRequest as V, type WithdrawDepositParams as W, type DepositVerifierCurrency as X, type DepositStatus as Y, Zkp2pClient as Z, type GetDepositByIdRequest as _, type ValidatePayeeDetailsResponse as a, getCurrencyInfoFromCountryCode as a$, type Intent as a0, type ApiIntentStatus as a1, type GetOwnerIntentsRequest as a2, type GetOwnerIntentsResponse as a3, type GetIntentsByDepositRequest as a4, type GetIntentsByDepositResponse as a5, type GetIntentByHashRequest as a6, type GetIntentByHashResponse as a7, type RegisterPayeeDetailsRequest as a8, type RegisterPayeeDetailsResponse as a9, type ManagerStatsEntity as aA, type ManagerDailySnapshotEntity as aB, type RateManagerListItem as aC, type RateManagerDetail as aD, type ManualRateUpdateEntity as aE, type OracleConfigUpdateEntity as aF, type DepositFundActivityEntity as aG, type DepositDailySnapshotEntity as aH, type DepositFundActivityType as aI, type DepositFilter as aJ, type PaginationOptions as aK, type DepositOrderField as aL, type OrderDirection$1 as aM, type RateManagerFilter as aN, type RateManagerPaginationOptions as aO, type RateManagerDelegationPaginationOptions as aP, type RateManagerOrderField as aQ, type OrderDirection as aR, type DeploymentEnv as aS, type FulfillmentRecord as aT, type PaymentVerifiedRecord as aU, type FulfillmentAndPaymentResponse as aV, PAYMENT_PLATFORMS as aW, type PaymentPlatformType as aX, Currency as aY, currencyInfo as aZ, getCurrencyInfoFromHash as a_, type OnchainCurrency as aa, type DepositVerifierData as ab, type PreparedTransaction as ac, type OrderStats as ad, type DepositIntentStatistics as ae, type TakerTier as af, type TakerTierStats as ag, type TakerTierLevel as ah, type PlatformLimit as ai, type PlatformRiskLevel as aj, IndexerClient as ak, defaultIndexerEndpoint as al, IndexerDepositService as am, IndexerRateManagerService as an, compareEventCursorIdsByRecency as ao, fetchFulfillmentAndPayment as ap, type DepositEntity as aq, type IntentFulfilledEntity as ar, type IntentFulfillmentAmountsEntity as as, type DepositPaymentMethodEntity as at, type MethodCurrencyEntity as au, type IntentStatus as av, type RateManagerEntity as aw, type RateManagerRateEntity as ax, type RateManagerDelegationEntity as ay, type ManagerAggregateStatsEntity as az, type PostDepositDetailsResponse as b, getCurrencyCodeFromHash as b0, isSupportedCurrencyHash as b1, mapConversionRatesToOnchainMinRate as b2, type CurrencyData as b3, getContracts as b4, getRateManagerContracts as b5, getPaymentMethodsCatalog as b6, getGatingServiceAddress as b7, HISTORICAL_ESCROW_ADDRESSES as b8, type RuntimeEnv as b9, parseDepositView as ba, parseIntentView as bb, enrichPvDepositView as bc, enrichPvIntentView as bd, type PV_DepositView as be, type PV_Deposit as bf, type PV_PaymentMethodData as bg, type PV_Currency as bh, type PV_ReferralFee as bi, type PV_IntentView as bj, type PV_Intent as bk, ZERO_RATE_MANAGER_ID as bl, isZeroRateManagerId as bm, normalizeRateManagerId as bn, normalizeRegistry as bo, getDelegationRoute as bp, classifyDelegationState as bq, type DelegationRoute as br, type DelegationState as bs, type DelegationDepositTarget as bt, type BatchResult as bu, type SendTransactionFn as bv, type SendBatchFn as bw, ZERO_ADDRESS as bx, asErrorMessage as by, assertDelegationMethodSupport as bz, type GetPayeeDetailsResponse as c, type GetOwnerDepositsRequest as d, type GetOwnerDepositsResponse as e, type GetTakerTierRequest as f, type GetTakerTierResponse as g, type PaymentMethodCatalog as h, type SignalIntentMethodParams as i, type CancelIntentMethodParams as j, type Zkp2pClientOptions as k, type TimeoutConfig as l, type ActionCallback as m, type CreateDepositParams as n, type CreateDepositConversionRate as o, type Range as p, type SignalIntentParams as q, type FulfillIntentParams as r, type ReleaseFundsToPayerParams as s, type CancelIntentParams as t, type GetNearbyQuote as u, type GetNearbySuggestions as v, type GetQuoteResponse as w, type GetQuoteResponseObject as x, type GetQuoteSingleResponse as y, type QuoteResponse as z };
|
|
@@ -170,13 +170,13 @@ type V2ContractAddresses = {
|
|
|
170
170
|
escrow: `0x${string}`;
|
|
171
171
|
/** EscrowV2 contract (supports native rate-manager delegation) */
|
|
172
172
|
escrowV2?: `0x${string}`;
|
|
173
|
-
/** All supported escrow addresses (
|
|
173
|
+
/** All supported upgraded escrow addresses (current first, then historical) */
|
|
174
174
|
escrowAddresses?: `0x${string}`[];
|
|
175
175
|
/** Orchestrator contract (handles intent signaling and fulfillment) */
|
|
176
176
|
orchestrator?: `0x${string}`;
|
|
177
177
|
/** OrchestratorV2 contract (queries EscrowV2 effective rates) */
|
|
178
178
|
orchestratorV2?: `0x${string}`;
|
|
179
|
-
/** All supported orchestrator addresses (
|
|
179
|
+
/** All supported upgraded orchestrator addresses (current first, then historical) */
|
|
180
180
|
orchestratorAddresses?: `0x${string}`[];
|
|
181
181
|
/** UnifiedPaymentVerifier contract (verifies payment proofs) */
|
|
182
182
|
unifiedPaymentVerifier?: `0x${string}`;
|
|
@@ -481,7 +481,9 @@ interface RateManagerDelegationEntity {
|
|
|
481
481
|
createdAt: string;
|
|
482
482
|
updatedAt: string;
|
|
483
483
|
}
|
|
484
|
-
type ManagerAggregateStatsEntity = ManagerAggregateStats
|
|
484
|
+
type ManagerAggregateStatsEntity = WithOverrides<ManagerAggregateStats, {
|
|
485
|
+
rateManagerAddress?: string | null;
|
|
486
|
+
}>;
|
|
485
487
|
type ManagerStatsEntity = ManagerStats;
|
|
486
488
|
type ManagerDailySnapshotEntity = ManagerDailySnapshot;
|
|
487
489
|
interface ManualRateUpdateEntity {
|
|
@@ -632,10 +634,14 @@ type RateManagerDelegationPaginationOptions = Partial<{
|
|
|
632
634
|
orderDirection: OrderDirection;
|
|
633
635
|
rateManagerAddress: string;
|
|
634
636
|
}>;
|
|
637
|
+
declare function compareEventCursorIdsByRecency(leftId?: string | null, rightId?: string | null): number;
|
|
635
638
|
declare class IndexerRateManagerService {
|
|
636
639
|
private client;
|
|
637
640
|
constructor(client: IndexerClient);
|
|
641
|
+
private buildRateManagerScopeWhere;
|
|
638
642
|
private buildWhere;
|
|
643
|
+
private buildAggregateWhere;
|
|
644
|
+
private buildLegacyAggregateWhere;
|
|
639
645
|
private buildOrderBy;
|
|
640
646
|
private toRateManagerListItems;
|
|
641
647
|
private applyHookFilter;
|
|
@@ -734,11 +740,15 @@ type TimeoutConfig = {
|
|
|
734
740
|
type AuthorizationTokenProvider = () => string | null | undefined | Promise<string | null | undefined>;
|
|
735
741
|
type Zkp2pClientOptions = {
|
|
736
742
|
walletClient: WalletClient;
|
|
737
|
-
|
|
743
|
+
/** Curator API key for authenticated endpoints (optional for basic deposit/payee flows) */
|
|
744
|
+
apiKey?: string;
|
|
738
745
|
chainId: number;
|
|
746
|
+
/** Runtime environment (defaults to 'production') */
|
|
747
|
+
runtimeEnv?: 'production' | 'preproduction' | 'staging';
|
|
748
|
+
/**
|
|
749
|
+
* @deprecated Use `runtimeEnv` instead. Kept for backward compatibility.
|
|
750
|
+
*/
|
|
739
751
|
environment?: 'production' | 'staging';
|
|
740
|
-
/** Optional default routing preference when both legacy and V2 contracts are available */
|
|
741
|
-
preferV2ByDefault?: boolean;
|
|
742
752
|
baseApiUrl?: string;
|
|
743
753
|
witnessUrl?: string;
|
|
744
754
|
rpcUrl?: string;
|
|
@@ -746,6 +756,10 @@ type Zkp2pClientOptions = {
|
|
|
746
756
|
authorizationToken?: string;
|
|
747
757
|
/** Optional async token provider for indexer auth in long-lived clients */
|
|
748
758
|
getAuthorizationToken?: AuthorizationTokenProvider;
|
|
759
|
+
/** Optional API key for indexer proxy authentication */
|
|
760
|
+
indexerApiKey?: string;
|
|
761
|
+
/** Optional indexer URL override */
|
|
762
|
+
indexerUrl?: string;
|
|
749
763
|
/** Optional timeout configuration */
|
|
750
764
|
timeouts?: TimeoutConfig;
|
|
751
765
|
};
|
|
@@ -1331,16 +1345,6 @@ type Zkp2pNextOptions = {
|
|
|
1331
1345
|
rpcUrl?: string;
|
|
1332
1346
|
/** Runtime environment: 'production', 'preproduction', or 'staging' (defaults to 'production') */
|
|
1333
1347
|
runtimeEnv?: RuntimeEnv;
|
|
1334
|
-
/**
|
|
1335
|
-
* Controls which contract stack is treated as the default when both legacy and V2
|
|
1336
|
-
* contracts are available.
|
|
1337
|
-
*
|
|
1338
|
-
* - `true`: default to EscrowV2/OrchestratorV2
|
|
1339
|
-
* - `false`: default to legacy Escrow/Orchestrator
|
|
1340
|
-
* - `undefined`: default to the runtime rollout baseline
|
|
1341
|
-
* (`staging` => V2, `production`/`preproduction` => legacy)
|
|
1342
|
-
*/
|
|
1343
|
-
preferV2ByDefault?: boolean;
|
|
1344
1348
|
/** Optional indexer URL override */
|
|
1345
1349
|
indexerUrl?: string;
|
|
1346
1350
|
/** Base API URL for ZKP2P services (defaults to https://api.zkp2p.xyz) */
|
|
@@ -1554,29 +1558,21 @@ declare class Zkp2pClient {
|
|
|
1554
1558
|
readonly escrowAddress: Address;
|
|
1555
1559
|
/** Escrow contract ABI */
|
|
1556
1560
|
readonly escrowAbi: Abi;
|
|
1557
|
-
/** Legacy escrow contract address (if deployed) */
|
|
1558
|
-
readonly legacyEscrowAddress?: Address;
|
|
1559
|
-
/** Legacy escrow ABI */
|
|
1560
|
-
readonly legacyEscrowAbi?: Abi;
|
|
1561
1561
|
/** EscrowV2 contract address (if deployed) */
|
|
1562
1562
|
readonly escrowV2Address?: Address;
|
|
1563
1563
|
/** EscrowV2 ABI */
|
|
1564
1564
|
readonly escrowV2Abi?: Abi;
|
|
1565
|
-
/** All supported escrow addresses (
|
|
1565
|
+
/** All supported upgraded escrow addresses (current first, then historical) */
|
|
1566
1566
|
readonly escrowAddresses: Address[];
|
|
1567
1567
|
/** Orchestrator contract address (handles intent signaling/fulfillment) */
|
|
1568
1568
|
readonly orchestratorAddress?: Address;
|
|
1569
1569
|
/** Orchestrator contract ABI */
|
|
1570
1570
|
readonly orchestratorAbi?: Abi;
|
|
1571
|
-
/** Legacy orchestrator address (if deployed) */
|
|
1572
|
-
readonly legacyOrchestratorAddress?: Address;
|
|
1573
|
-
/** Legacy orchestrator ABI */
|
|
1574
|
-
readonly legacyOrchestratorAbi?: Abi;
|
|
1575
1571
|
/** OrchestratorV2 address (if deployed) */
|
|
1576
1572
|
readonly orchestratorV2Address?: Address;
|
|
1577
1573
|
/** OrchestratorV2 ABI */
|
|
1578
1574
|
readonly orchestratorV2Abi?: Abi;
|
|
1579
|
-
/** All supported orchestrator addresses (
|
|
1575
|
+
/** All supported upgraded orchestrator addresses (current first, then historical) */
|
|
1580
1576
|
readonly orchestratorAddresses: Address[];
|
|
1581
1577
|
/** UnifiedPaymentVerifier contract address */
|
|
1582
1578
|
readonly unifiedPaymentVerifier?: Address;
|
|
@@ -2891,11 +2887,9 @@ declare class Zkp2pClient {
|
|
|
2891
2887
|
escrow: Address;
|
|
2892
2888
|
escrowV2?: Address;
|
|
2893
2889
|
escrowAddresses: Address[];
|
|
2894
|
-
legacyEscrow?: Address;
|
|
2895
2890
|
orchestrator?: Address;
|
|
2896
2891
|
orchestratorV2?: Address;
|
|
2897
2892
|
orchestratorAddresses: Address[];
|
|
2898
|
-
legacyOrchestrator?: Address;
|
|
2899
2893
|
protocolViewer?: Address;
|
|
2900
2894
|
protocolViewerEntries: Address[];
|
|
2901
2895
|
unifiedPaymentVerifier?: Address;
|
|
@@ -2942,17 +2936,12 @@ type DelegationState = 'delegated_here' | 'delegated_elsewhere' | 'not_delegated
|
|
|
2942
2936
|
* @param targetRegistry The vault's registry address we're comparing against
|
|
2943
2937
|
*/
|
|
2944
2938
|
declare const classifyDelegationState: (currentRateManagerId: string | null | undefined, currentRegistry: string | null | undefined, targetRateManagerId: string, targetRegistry: string | null | undefined) => DelegationState;
|
|
2945
|
-
type DelegationRoute = 'v2'
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
escrowV2Address?: Address;
|
|
2949
|
-
legacyEscrowAddress?: Address;
|
|
2950
|
-
}
|
|
2951
|
-
declare const getDelegationRoute: (client: RoutingClientShape, escrow: Address) => DelegationRoute;
|
|
2952
|
-
type DelegationMethodSupportClient = Partial<Record<'setRateManager' | 'clearRateManager' | 'setDepositRateManager' | 'clearDepositRateManager', {
|
|
2939
|
+
type DelegationRoute = 'v2';
|
|
2940
|
+
declare const getDelegationRoute: (_client: unknown, _escrow: Address) => DelegationRoute;
|
|
2941
|
+
type DelegationMethodSupportClient = Partial<Record<'setRateManager' | 'clearRateManager', {
|
|
2953
2942
|
prepare?: unknown;
|
|
2954
2943
|
}>>;
|
|
2955
|
-
declare const assertDelegationMethodSupport: (client: DelegationMethodSupportClient,
|
|
2944
|
+
declare const assertDelegationMethodSupport: (client: DelegationMethodSupportClient, _route: DelegationRoute, action: "set" | "clear") => void;
|
|
2956
2945
|
interface DelegationDepositTarget {
|
|
2957
2946
|
compositeDepositId: string;
|
|
2958
2947
|
escrow: Address;
|
|
@@ -2987,4 +2976,4 @@ type SendBatchFn = (txs: Array<{
|
|
|
2987
2976
|
value?: bigint;
|
|
2988
2977
|
}>) => Promise<string>;
|
|
2989
2978
|
|
|
2990
|
-
export { type GetDepositByIdResponse as $, type AuthorizationTokenProvider as A, type QuoteResponseObject as B, type CurrencyType as C, type DepositWithRelations as D, type QuoteSingleResponse as E, type FulfillIntentMethodParams as F, type GetPayeeDetailsRequest as G, type QuoteIntentResponse as H, type IntentEntity as I, type QuoteFeesResponse as J, type FiatResponse as K, type TokenResponse as L, type NearbySuggestions as M, type NearbyQuote as N, type ApiDeposit as O, type PostDepositDetailsRequest as P, type QuoteRequest as Q, type ReferrerFeeConfig as R, type SignalIntentReferralFee as S, type TxOverrides as T, type DepositVerifier as U, type ValidatePayeeDetailsRequest as V, type WithdrawDepositParams as W, type DepositVerifierCurrency as X, type DepositStatus as Y, Zkp2pClient as Z, type GetDepositByIdRequest as _, type ValidatePayeeDetailsResponse as a,
|
|
2979
|
+
export { type GetDepositByIdResponse as $, type AuthorizationTokenProvider as A, type QuoteResponseObject as B, type CurrencyType as C, type DepositWithRelations as D, type QuoteSingleResponse as E, type FulfillIntentMethodParams as F, type GetPayeeDetailsRequest as G, type QuoteIntentResponse as H, type IntentEntity as I, type QuoteFeesResponse as J, type FiatResponse as K, type TokenResponse as L, type NearbySuggestions as M, type NearbyQuote as N, type ApiDeposit as O, type PostDepositDetailsRequest as P, type QuoteRequest as Q, type ReferrerFeeConfig as R, type SignalIntentReferralFee as S, type TxOverrides as T, type DepositVerifier as U, type ValidatePayeeDetailsRequest as V, type WithdrawDepositParams as W, type DepositVerifierCurrency as X, type DepositStatus as Y, Zkp2pClient as Z, type GetDepositByIdRequest as _, type ValidatePayeeDetailsResponse as a, getCurrencyInfoFromCountryCode as a$, type Intent as a0, type ApiIntentStatus as a1, type GetOwnerIntentsRequest as a2, type GetOwnerIntentsResponse as a3, type GetIntentsByDepositRequest as a4, type GetIntentsByDepositResponse as a5, type GetIntentByHashRequest as a6, type GetIntentByHashResponse as a7, type RegisterPayeeDetailsRequest as a8, type RegisterPayeeDetailsResponse as a9, type ManagerStatsEntity as aA, type ManagerDailySnapshotEntity as aB, type RateManagerListItem as aC, type RateManagerDetail as aD, type ManualRateUpdateEntity as aE, type OracleConfigUpdateEntity as aF, type DepositFundActivityEntity as aG, type DepositDailySnapshotEntity as aH, type DepositFundActivityType as aI, type DepositFilter as aJ, type PaginationOptions as aK, type DepositOrderField as aL, type OrderDirection$1 as aM, type RateManagerFilter as aN, type RateManagerPaginationOptions as aO, type RateManagerDelegationPaginationOptions as aP, type RateManagerOrderField as aQ, type OrderDirection as aR, type DeploymentEnv as aS, type FulfillmentRecord as aT, type PaymentVerifiedRecord as aU, type FulfillmentAndPaymentResponse as aV, PAYMENT_PLATFORMS as aW, type PaymentPlatformType as aX, Currency as aY, currencyInfo as aZ, getCurrencyInfoFromHash as a_, type OnchainCurrency as aa, type DepositVerifierData as ab, type PreparedTransaction as ac, type OrderStats as ad, type DepositIntentStatistics as ae, type TakerTier as af, type TakerTierStats as ag, type TakerTierLevel as ah, type PlatformLimit as ai, type PlatformRiskLevel as aj, IndexerClient as ak, defaultIndexerEndpoint as al, IndexerDepositService as am, IndexerRateManagerService as an, compareEventCursorIdsByRecency as ao, fetchFulfillmentAndPayment as ap, type DepositEntity as aq, type IntentFulfilledEntity as ar, type IntentFulfillmentAmountsEntity as as, type DepositPaymentMethodEntity as at, type MethodCurrencyEntity as au, type IntentStatus as av, type RateManagerEntity as aw, type RateManagerRateEntity as ax, type RateManagerDelegationEntity as ay, type ManagerAggregateStatsEntity as az, type PostDepositDetailsResponse as b, getCurrencyCodeFromHash as b0, isSupportedCurrencyHash as b1, mapConversionRatesToOnchainMinRate as b2, type CurrencyData as b3, getContracts as b4, getRateManagerContracts as b5, getPaymentMethodsCatalog as b6, getGatingServiceAddress as b7, HISTORICAL_ESCROW_ADDRESSES as b8, type RuntimeEnv as b9, parseDepositView as ba, parseIntentView as bb, enrichPvDepositView as bc, enrichPvIntentView as bd, type PV_DepositView as be, type PV_Deposit as bf, type PV_PaymentMethodData as bg, type PV_Currency as bh, type PV_ReferralFee as bi, type PV_IntentView as bj, type PV_Intent as bk, ZERO_RATE_MANAGER_ID as bl, isZeroRateManagerId as bm, normalizeRateManagerId as bn, normalizeRegistry as bo, getDelegationRoute as bp, classifyDelegationState as bq, type DelegationRoute as br, type DelegationState as bs, type DelegationDepositTarget as bt, type BatchResult as bu, type SendTransactionFn as bv, type SendBatchFn as bw, ZERO_ADDRESS as bx, asErrorMessage as by, assertDelegationMethodSupport as bz, type GetPayeeDetailsResponse as c, type GetOwnerDepositsRequest as d, type GetOwnerDepositsResponse as e, type GetTakerTierRequest as f, type GetTakerTierResponse as g, type PaymentMethodCatalog as h, type SignalIntentMethodParams as i, type CancelIntentMethodParams as j, type Zkp2pClientOptions as k, type TimeoutConfig as l, type ActionCallback as m, type CreateDepositParams as n, type CreateDepositConversionRate as o, type Range as p, type SignalIntentParams as q, type FulfillIntentParams as r, type ReleaseFundsToPayerParams as s, type CancelIntentParams as t, type GetNearbyQuote as u, type GetNearbySuggestions as v, type GetQuoteResponse as w, type GetQuoteResponseObject as x, type GetQuoteSingleResponse as y, type QuoteResponse as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zkp2p/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "ZKP2P Client SDK - TypeScript SDK for deposit management, liquidity provision, and onramping",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -36,19 +36,6 @@
|
|
|
36
36
|
]
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "tsup",
|
|
41
|
-
"clean": "rimraf dist",
|
|
42
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
43
|
-
"lint": "eslint . --ext .ts,.tsx",
|
|
44
|
-
"format": "prettier --check .",
|
|
45
|
-
"format:write": "prettier --write .",
|
|
46
|
-
"test": "vitest run",
|
|
47
|
-
"test:coverage": "vitest run --coverage",
|
|
48
|
-
"test:watch": "vitest",
|
|
49
|
-
"release": "release-it",
|
|
50
|
-
"docs": "typedoc"
|
|
51
|
-
},
|
|
52
39
|
"files": [
|
|
53
40
|
"dist",
|
|
54
41
|
"README.md",
|
|
@@ -87,14 +74,13 @@
|
|
|
87
74
|
},
|
|
88
75
|
"dependencies": {
|
|
89
76
|
"@zkp2p/indexer-schema": "0.2.2",
|
|
90
|
-
"@zkp2p/contracts-v2": "0.2.0
|
|
77
|
+
"@zkp2p/contracts-v2": "0.2.0",
|
|
91
78
|
"ethers": "^6.0.0",
|
|
92
79
|
"ox": "^0.11.1"
|
|
93
80
|
},
|
|
94
81
|
"devDependencies": {
|
|
95
82
|
"@testing-library/react": "^16.1.0",
|
|
96
83
|
"@vitest/coverage-v8": "^1.6.1",
|
|
97
|
-
"@zkp2p/core": "workspace:*",
|
|
98
84
|
"@release-it/conventional-changelog": "^9.0.4",
|
|
99
85
|
"@types/node": "^20.10.0",
|
|
100
86
|
"@types/react": "^19.1.11",
|
|
@@ -113,7 +99,8 @@
|
|
|
113
99
|
"typedoc": "^0.25.12",
|
|
114
100
|
"typescript": "^5.4.0",
|
|
115
101
|
"typescript-eslint": "^8.50.1",
|
|
116
|
-
"vitest": "^1.5.0"
|
|
102
|
+
"vitest": "^1.5.0",
|
|
103
|
+
"@zkp2p/core": "0.0.1"
|
|
117
104
|
},
|
|
118
105
|
"peerDependencies": {
|
|
119
106
|
"react": ">=16.8.0",
|
|
@@ -123,5 +110,18 @@
|
|
|
123
110
|
"react": {
|
|
124
111
|
"optional": true
|
|
125
112
|
}
|
|
113
|
+
},
|
|
114
|
+
"scripts": {
|
|
115
|
+
"build": "tsup",
|
|
116
|
+
"clean": "rimraf dist",
|
|
117
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
118
|
+
"lint": "eslint . --ext .ts,.tsx",
|
|
119
|
+
"format": "prettier --check .",
|
|
120
|
+
"format:write": "prettier --write .",
|
|
121
|
+
"test": "vitest run",
|
|
122
|
+
"test:coverage": "vitest run --coverage",
|
|
123
|
+
"test:watch": "vitest",
|
|
124
|
+
"release": "release-it",
|
|
125
|
+
"docs": "typedoc"
|
|
126
126
|
}
|
|
127
|
-
}
|
|
127
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/bigint.ts","../src/contracts.ts","../src/utils/bytes32.ts","../src/utils/paymentMethodHashes.ts","../src/utils/paymentResolution.ts","../src/utils/protocolViewerParsers.ts"],"names":["baseStagingPaymentMethods"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAO,SAAS,eAAA,CACd,KAAA,EACA,YAAA,GAAe,2BAAA,EACP;AACR,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,EAAU,OAAO,KAAA;AACtC,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,EAAU,OAAO,OAAO,KAAK,CAAA;AAClD,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,MAAM,UAAA,GAAa,MAAM,IAAA,EAAK;AAC9B,IAAA,IAAI,CAAC,UAAA,EAAY,MAAM,IAAI,MAAM,YAAY,CAAA;AAC7C,IAAA,OAAO,OAAO,UAAU,CAAA;AAAA,EAC1B;AAEA,EAAA,IAAI,KAAA,IAAS,OAAQ,KAAA,CAAsC,QAAA,KAAa,UAAA,EAAY;AAClF,IAAA,MAAM,UAAA,GAAc,KAAA,CAAqC,QAAA,EAAS,CAAE,IAAA,EAAK;AACzE,IAAA,IAAI,CAAC,UAAA,EAAY,MAAM,IAAI,MAAM,YAAY,CAAA;AAC7C,IAAA,OAAO,OAAO,UAAU,CAAA;AAAA,EAC1B;AAEA,EAAA,MAAM,IAAI,MAAM,YAAY,CAAA;AAC9B;AC6BA,SAAS,gBAAgB,GAAA,EAIvB;A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M,OAAA,GAAU,wBAAA,CAAyB,OAAA,EAAS,GAAG,CAAA;AACrD,EAAA,OAAO;AAAA,IACL,GAAG,IAAA;AAAA,IACH,MAAA,EAAQ;AAAA,MACN,GAAG,IAAA,CAAK,MAAA;AAAA,MACR,aAAA,EAAe,gCAAA,CAAiC,IAAA,CAAK,MAAA,CAAO,eAAe,OAAO,CAAA;AAAA,MAClF,YAAA,EAAc,uBAAA,CAAwB,IAAA,CAAK,MAAA,CAAO,YAAY;AAAA,KAChE;AAAA,IACA,OAAA,EAAS,mBAAA,CAAoB,IAAA,CAAK,OAAA,EAAgB,SAAS,GAAG;AAAA,GAChE;AACF","file":"chunk-JH74HXTS.mjs","sourcesContent":["export function parseBigIntLike(\n value: unknown,\n errorMessage = 'Unsupported numeric value',\n): bigint {\n if (typeof value === 'bigint') return value;\n if (typeof value === 'number') return BigInt(value);\n if (typeof value === 'string') {\n const normalized = value.trim();\n if (!normalized) throw new Error(errorMessage);\n return BigInt(normalized);\n }\n\n if (value && typeof (value as { toString?: () => string }).toString === 'function') {\n const normalized = (value as { toString: () => string }).toString().trim();\n if (!normalized) throw new Error(errorMessage);\n return BigInt(normalized);\n }\n\n throw new Error(errorMessage);\n}\n","/**\n * Contract resolution utilities for the SDK.\n *\n * Provides access to deployed contract addresses and ABIs for different\n * networks (Base) and environments (production, staging).\n *\n * @module contracts\n */\n\nimport type { Abi } from 'abitype';\n\n// Typed imports from @zkp2p/contracts-v2 (module declarations provided in src/@types)\n// Use *Raw suffix for imports that need runtime normalization (addresses, constants)\nimport baseAddressesRaw from '@zkp2p/contracts-v2/addresses/base';\nimport baseStagingAddressesRaw from '@zkp2p/contracts-v2/addresses/baseStaging';\nimport * as baseAbisRaw from '@zkp2p/contracts-v2/abis/base';\nimport * as baseStagingAbisRaw from '@zkp2p/contracts-v2/abis/baseStaging';\n\nimport EscrowBase from '@zkp2p/contracts-v2/abis/base/Escrow.json';\nimport OrchestratorBase from '@zkp2p/contracts-v2/abis/base/Orchestrator.json';\nimport ProtocolViewerBase from '@zkp2p/contracts-v2/abis/base/ProtocolViewer.json';\nimport UnifiedPaymentVerifierBase from '@zkp2p/contracts-v2/abis/base/UnifiedPaymentVerifier.json';\n\nimport EscrowBaseStaging from '@zkp2p/contracts-v2/abis/baseStaging/Escrow.json';\nimport OrchestratorBaseStaging from '@zkp2p/contracts-v2/abis/baseStaging/Orchestrator.json';\nimport UnifiedPaymentVerifierBaseStaging from '@zkp2p/contracts-v2/abis/baseStaging/UnifiedPaymentVerifier.json';\nimport ProtocolViewerBaseStaging from '@zkp2p/contracts-v2/abis/baseStaging/ProtocolViewer.json';\n\nimport baseConstantsRaw from '@zkp2p/contracts-v2/constants/base';\nimport baseStagingConstantsRaw from '@zkp2p/contracts-v2/constants/baseStaging';\n// Payment methods catalogs (JSON). Import statically so ESM bundlers include the data.\n// These modules are present in @zkp2p/contracts-v2; tsconfig sets resolveJsonModule: true\nimport basePaymentMethodsRaw from '@zkp2p/contracts-v2/paymentMethods/base.json';\nimport baseStagingPaymentMethodsRaw from '@zkp2p/contracts-v2/paymentMethods/baseStaging.json';\n\n// ---------------------------------------------------------------------------\n// Runtime normalization helpers for ESM/CJS interoperability\n// ---------------------------------------------------------------------------\n// In certain runtimes (tsx, Node ESM), deep imports from @zkp2p/contracts-v2\n// resolve as { default: [Getter] } or { default: { contracts: {...} } } instead\n// of the expected shape. These helpers unwrap the actual data regardless of shape.\n\n/**\n * Normalize address module shape. Handles:\n * - { contracts: {...} } (direct)\n * - { default: { contracts: {...} } } (wrapped)\n * - { default: [Getter] } (lazy)\n */\nfunction unwrapAddresses(mod: unknown): {\n name?: string;\n chainId?: number;\n contracts?: Record<string, `0x${string}`>;\n} {\n if (!mod) return {} as ReturnType<typeof unwrapAddresses>;\n const m = mod as Record<string, unknown>;\n // Direct shape\n if (m.contracts) return m as ReturnType<typeof unwrapAddresses>;\n // Wrapped shape\n if ((m.default as Record<string, unknown>)?.contracts)\n return m.default as ReturnType<typeof unwrapAddresses>;\n // Lazy getter shape\n try {\n const d = typeof m.default === 'function' ? (m.default as () => unknown)() : m.default;\n if ((d as Record<string, unknown>)?.contracts) return d as ReturnType<typeof unwrapAddresses>;\n } catch {\n // ignore\n }\n return m as ReturnType<typeof unwrapAddresses>;\n}\n\n/**\n * Normalize payment methods module shape. Handles:\n * - { methods: {...} } (direct)\n * - { default: { methods: {...} } } (wrapped)\n * - { default: [Getter] } (lazy)\n */\nfunction unwrapMethods(mod: unknown): {\n methods?: Record<string, { paymentMethodHash: `0x${string}`; currencies?: `0x${string}`[] }>;\n} {\n if (!mod) return {} as ReturnType<typeof unwrapMethods>;\n const m = mod as Record<string, unknown>;\n if (m.methods) return m as ReturnType<typeof unwrapMethods>;\n if ((m.default as Record<string, unknown>)?.methods)\n return m.default as ReturnType<typeof unwrapMethods>;\n try {\n const d = typeof m.default === 'function' ? (m.default as () => unknown)() : m.default;\n if ((d as Record<string, unknown>)?.methods) return d as ReturnType<typeof unwrapMethods>;\n } catch {\n // ignore\n }\n return m as ReturnType<typeof unwrapMethods>;\n}\n\n/**\n * Normalize constants module shape (for USDC address, etc.)\n */\nfunction unwrapConstants(mod: unknown): Record<string, unknown> {\n if (!mod) return {};\n const m = mod as Record<string, unknown>;\n if (m.USDC) return m;\n if ((m.default as Record<string, unknown>)?.USDC) return m.default as Record<string, unknown>;\n try {\n const d = typeof m.default === 'function' ? (m.default as () => unknown)() : m.default;\n if ((d as Record<string, unknown>)?.USDC) return d as Record<string, unknown>;\n } catch {\n // ignore\n }\n return m;\n}\n\n// ---------------------------------------------------------------------------\n// Historical escrow addresses\n// ---------------------------------------------------------------------------\n// Escrow addresses from prior deployments. Merged into escrowAddresses so\n// deposits from retired escrows remain queryable. Current addresses come from\n// contracts-v2 dynamically.\n// Source of truth for what the indexer indexes:\n// STAGING: zkp2p-indexer releases/staging config.base_staging.yaml\n// PROD: zkp2p-indexer main config.base_prod.yaml\n\nexport const HISTORICAL_ESCROW_ADDRESSES: Record<string, `0x${string}`[]> = {\n base: [\n '0x2f121CDDCA6d652f35e8B3E560f9760898888888', // EscrowV2 production (contracts-v2 0.2.0-rc.6)\n ],\n base_staging: [\n '0x5C2a8D9246777eE4501B6C426a8B8C7635C7b5b5', // EscrowV2 staging (contracts-v2 0.2.0-rc.5)\n '0x18EAcBf3FF19528ABe8035CF5cA266F31A2e3f14', // EscrowV2 staging (contracts-v2 0.1.11-rc.3)\n '0x07Cc97c254A5Fb0957553E9F58E4040699357f28', // EscrowV2 staging (contracts-v2 0.1.11-rc.2)\n '0x8455b9a31041125C785044f45458eCf2cbB12eF7', // v2.1 staging Escrow (2025-10-18, PR #83)\n '0x21f007107269ea1c8Fe0730736548090F4945736', // v2.1 staging Escrow (2025-10-04, PR #71)\n ],\n};\n\nexport const HISTORICAL_ORCHESTRATOR_ADDRESSES: Record<string, `0x${string}`[]> = {\n base: [\n '0x88888883Ed048FF0a415271B28b2F52d431810D0', // OrchestratorV2 production (contracts-v2 0.2.0-rc.6)\n ],\n base_staging: [\n '0xF9b9CD27Deea496B960b3cb5221b514705fCaF5e', // OrchestratorV2 staging (contracts-v2 0.2.0-rc.5)\n '0xC0389b3d7A4E6B823e361e562C4a29F04B6C4fB5', // OrchestratorV2 staging (contracts-v2 0.1.11-rc.3)\n ],\n};\n\nconst STAGING_ESCROW_V2_FALLBACK = '0x77e8f808FE201075e0bD651CD46fdF239fc83265';\nconst STAGING_ORCHESTRATOR_V2_FALLBACK = '0xc17a59227B136c45fAa153086a15EF87ED14bE00';\n\nconst ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';\n\nfunction isValidAddress(value?: string | null): value is `0x${string}` {\n return (\n typeof value === 'string' &&\n /^0x[a-fA-F0-9]{40}$/.test(value) &&\n value.toLowerCase() !== ZERO_ADDRESS\n );\n}\n\nfunction pickAddress(\n contracts: Record<string, string> | undefined,\n keys: string[],\n): `0x${string}` | undefined {\n if (!contracts) return undefined;\n for (const key of keys) {\n const candidate = contracts[key];\n if (isValidAddress(candidate)) return candidate;\n }\n return undefined;\n}\n\nfunction pickAbi(source: Record<string, unknown>, names: string[]): Abi | undefined {\n for (const name of names) {\n const candidate = source[name];\n if (Array.isArray(candidate)) return candidate as unknown as Abi;\n }\n return undefined;\n}\n\nfunction uniqueAddresses(...values: Array<string | undefined>): `0x${string}`[] {\n const seen = new Set<string>();\n const addresses: `0x${string}`[] = [];\n for (const value of values) {\n if (!isValidAddress(value)) continue;\n const normalized = value.toLowerCase();\n if (seen.has(normalized)) continue;\n seen.add(normalized);\n addresses.push(value);\n }\n return addresses;\n}\n\nfunction addressesEqual(left?: string, right?: string): boolean {\n return Boolean(left && right && left.toLowerCase() === right.toLowerCase());\n}\n\nfunction firstDistinctAddress(\n candidates: Array<`0x${string}` | undefined>,\n current?: `0x${string}`,\n): `0x${string}` | undefined {\n for (const candidate of candidates) {\n if (!isValidAddress(candidate)) continue;\n if (addressesEqual(candidate, current)) continue;\n return candidate;\n }\n return undefined;\n}\n\nfunction readRuntimeEnv(key: string): string | undefined {\n try {\n const meta = import.meta as { env?: Record<string, string | undefined> };\n const fromVite = meta?.env?.[key];\n if (fromVite) return fromVite;\n } catch {\n // ignore\n }\n try {\n const proc = (\n globalThis as {\n process?: { env?: Record<string, string | undefined> };\n }\n ).process;\n return proc?.env?.[key];\n } catch {\n // ignore\n }\n return undefined;\n}\n\nfunction resolveRuntimeAddressOverride(envKeys: string[]): `0x${string}` | undefined {\n for (const key of envKeys) {\n const candidate = readRuntimeEnv(key);\n if (isValidAddress(candidate)) return candidate;\n }\n return undefined;\n}\n\n// Apply runtime normalization to all imports\nconst baseAddresses = unwrapAddresses(baseAddressesRaw);\nconst baseStagingAddresses = unwrapAddresses(baseStagingAddressesRaw);\nconst basePaymentMethods = unwrapMethods(basePaymentMethodsRaw);\nconst baseStagingPaymentMethods = unwrapMethods(baseStagingPaymentMethodsRaw);\nconst baseConstants = unwrapConstants(baseConstantsRaw);\nconst baseStagingConstants = unwrapConstants(baseStagingConstantsRaw);\n\n/**\n * Contract addresses for a specific deployment.\n */\nexport type V2ContractAddresses = {\n /** Escrow contract (holds deposits and manages intents) */\n escrow: `0x${string}`;\n /** EscrowV2 contract (supports native rate-manager delegation) */\n escrowV2?: `0x${string}`;\n /** All supported escrow addresses (V2 first, then legacy) */\n escrowAddresses?: `0x${string}`[];\n /** Orchestrator contract (handles intent signaling and fulfillment) */\n orchestrator?: `0x${string}`;\n /** OrchestratorV2 contract (queries EscrowV2 effective rates) */\n orchestratorV2?: `0x${string}`;\n /** All supported orchestrator addresses (V2 first, then legacy) */\n orchestratorAddresses?: `0x${string}`[];\n /** UnifiedPaymentVerifier contract (verifies payment proofs) */\n unifiedPaymentVerifier?: `0x${string}`;\n /** UnifiedPaymentVerifierV2 contract (updated verifier) */\n unifiedPaymentVerifierV2?: `0x${string}`;\n /** ProtocolViewer contract (batch read operations) */\n protocolViewer?: `0x${string}`;\n /** Ordered list of all ProtocolViewer instances (primary first, legacy fallback after) */\n protocolViewerEntries?: Array<{ address: `0x${string}`; abi: Abi }>;\n /** USDC token address */\n usdc?: `0x${string}`;\n /** RateManagerV1 contract */\n rateManagerV1?: `0x${string}`;\n /** OrchestratorRegistry contract */\n orchestratorRegistry?: `0x${string}`;\n /** DepositRateManagerRegistryV1 contract */\n rateManagerRegistry?: `0x${string}`;\n /** DepositRateManagerController contract */\n rateManagerController?: `0x${string}`;\n /** ChainlinkOracleAdapter contract */\n chainlinkOracleAdapter?: `0x${string}`;\n /** PythOracleAdapter contract */\n pythOracleAdapter?: `0x${string}`;\n};\n\n/**\n * Contract ABIs for a specific deployment.\n */\nexport type V2ContractAbis = {\n escrow: Abi;\n escrowV2?: Abi;\n orchestrator?: Abi;\n orchestratorV2?: Abi;\n unifiedPaymentVerifier?: Abi;\n unifiedPaymentVerifierV2?: Abi;\n protocolViewer?: Abi;\n rateManagerV1?: Abi;\n orchestratorRegistry?: Abi;\n rateManagerRegistry?: Abi;\n rateManagerController?: Abi;\n};\n\n/**\n * Runtime environment: 'production' for mainnet, 'preproduction' for preprod\n * (production contracts + preprod indexer), 'staging' for testnet/dev.\n */\nexport type RuntimeEnv = 'production' | 'preproduction' | 'staging';\n\n/**\n * Converts a chain ID to its network key.\n * @internal\n */\nexport function networkKeyFromChainId(_chainId: number): 'base' {\n return 'base';\n}\n\n/**\n * Retrieves deployed contract addresses and ABIs for a given chain and environment.\n *\n * @param chainId - The chain ID (8453 for Base)\n * @param env - Runtime environment ('production' or 'staging')\n * @returns Object containing addresses and ABIs\n *\n * @example\n * ```typescript\n * import { getContracts } from '@zkp2p/sdk';\n *\n * const { addresses, abis } = getContracts(8453, 'production');\n * console.log(addresses.escrow); // \"0x...\"\n * console.log(addresses.usdc); // \"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913\"\n * ```\n */\nexport function getContracts(\n chainId: number,\n env: RuntimeEnv = 'production',\n): { addresses: V2ContractAddresses; abis: V2ContractAbis } {\n const key = networkKeyFromChainId(chainId);\n const baseContracts = (baseAddresses.contracts ?? {}) as Record<string, string>;\n const baseV2ProtocolViewerAbi = pickAbi(baseAbisRaw as unknown as Record<string, unknown>, [\n 'ProtocolViewerV2',\n ]);\n const baseV2ProtocolViewerAddress = pickAddress(baseContracts, ['ProtocolViewerV2']);\n const baseV1ProtocolViewerAddress = pickAddress(baseContracts, ['ProtocolViewer']);\n const baseProtocolViewerEntries = (() => {\n const entries: Array<{ address: `0x${string}`; abi: Abi }> = [];\n if (baseV2ProtocolViewerAddress && baseV2ProtocolViewerAbi) {\n entries.push({ address: baseV2ProtocolViewerAddress, abi: baseV2ProtocolViewerAbi });\n }\n if (\n baseV1ProtocolViewerAddress &&\n !addressesEqual(baseV1ProtocolViewerAddress, baseV2ProtocolViewerAddress)\n ) {\n entries.push({ address: baseV1ProtocolViewerAddress, abi: ProtocolViewerBase as Abi });\n }\n return entries.length > 0 ? entries : undefined;\n })();\n\n const addressesByKey: Record<'base', V2ContractAddresses> = {\n base: {\n escrow:\n pickAddress(baseContracts, ['EscrowV2', 'Escrow_V2']) ??\n pickAddress(baseContracts, ['Escrow']) ??\n ('' as `0x${string}`),\n escrowV2: pickAddress(baseContracts, ['EscrowV2', 'Escrow_V2']),\n escrowAddresses: uniqueAddresses(\n pickAddress(baseContracts, ['EscrowV2', 'Escrow_V2']),\n pickAddress(baseContracts, ['Escrow']),\n ...HISTORICAL_ESCROW_ADDRESSES.base,\n ),\n orchestrator:\n pickAddress(baseContracts, ['OrchestratorV2', 'Orchestrator_V2']) ??\n pickAddress(baseContracts, ['Orchestrator']),\n orchestratorV2: pickAddress(baseContracts, ['OrchestratorV2', 'Orchestrator_V2']),\n orchestratorAddresses: uniqueAddresses(\n pickAddress(baseContracts, ['OrchestratorV2', 'Orchestrator_V2']),\n pickAddress(baseContracts, ['Orchestrator']),\n ...HISTORICAL_ORCHESTRATOR_ADDRESSES.base,\n ),\n unifiedPaymentVerifier: pickAddress(baseContracts, [\n 'UnifiedPaymentVerifierV2',\n 'UnifiedPaymentVerifier',\n ]),\n unifiedPaymentVerifierV2: pickAddress(baseContracts, ['UnifiedPaymentVerifierV2']),\n protocolViewer:\n baseProtocolViewerEntries?.[0]?.address ??\n baseV1ProtocolViewerAddress ??\n baseV2ProtocolViewerAddress,\n protocolViewerEntries: baseProtocolViewerEntries,\n usdc: baseConstants.USDC as `0x${string}` | undefined,\n rateManagerV1: pickAddress(baseContracts, ['RateManagerV1', 'DepositRateManagerRegistryV1']),\n orchestratorRegistry: pickAddress(baseContracts, ['OrchestratorRegistry']),\n rateManagerRegistry: pickAddress(baseContracts, [\n 'DepositRateManagerRegistryV1',\n 'RateManagerV1',\n ]),\n rateManagerController: pickAddress(baseContracts, ['DepositRateManagerController']),\n chainlinkOracleAdapter: pickAddress(baseContracts, ['ChainlinkOracleAdapter']),\n pythOracleAdapter: pickAddress(baseContracts, ['PythOracleAdapter']),\n },\n };\n\n const abisByKey: Record<'base', V2ContractAbis> = {\n base: {\n escrow: EscrowBase as unknown as Abi,\n escrowV2: (pickAbi(baseAbisRaw as unknown as Record<string, unknown>, ['EscrowV2']) ??\n (EscrowBase as unknown as Abi)) as Abi,\n orchestrator: OrchestratorBase as unknown as Abi,\n orchestratorV2: (pickAbi(baseAbisRaw as unknown as Record<string, unknown>, [\n 'OrchestratorV2',\n ]) ?? (OrchestratorBase as unknown as Abi)) as Abi,\n unifiedPaymentVerifier: (pickAbi(baseAbisRaw as unknown as Record<string, unknown>, [\n 'UnifiedPaymentVerifierV2',\n ]) ?? (UnifiedPaymentVerifierBase as unknown as Abi)) as Abi,\n unifiedPaymentVerifierV2: pickAbi(baseAbisRaw as unknown as Record<string, unknown>, [\n 'UnifiedPaymentVerifierV2',\n ]),\n protocolViewer: (baseProtocolViewerEntries?.[0]?.abi ??\n (ProtocolViewerBase as unknown as Abi)) as Abi,\n rateManagerV1: pickAbi(baseAbisRaw as unknown as Record<string, unknown>, [\n 'RateManagerV1',\n 'DepositRateManagerRegistryV1',\n ]),\n orchestratorRegistry: pickAbi(baseAbisRaw as unknown as Record<string, unknown>, [\n 'OrchestratorRegistry',\n ]),\n rateManagerRegistry: pickAbi(baseAbisRaw as unknown as Record<string, unknown>, [\n 'DepositRateManagerRegistryV1',\n 'RateManagerV1',\n ]),\n rateManagerController: pickAbi(baseAbisRaw as unknown as Record<string, unknown>, [\n 'DepositRateManagerController',\n ]),\n },\n };\n\n // Staging overrides (addresses/abis from contracts-v2 baseStaging deployment)\n if (env === 'staging') {\n const sc = baseStagingAddresses.contracts as Record<string, string> | undefined;\n const stagingEscrowV2Override = resolveRuntimeAddressOverride([\n 'VITE_BASE_STAGING_ESCROW_V2_ADDRESS',\n 'VITE_ESCROW_V2_ADDRESS',\n ]);\n const stagingEscrowCurrent =\n stagingEscrowV2Override ??\n pickAddress(sc, ['EscrowV2', 'Escrow_V2']) ??\n pickAddress(sc, ['Escrow']) ??\n STAGING_ESCROW_V2_FALLBACK;\n const stagingEscrowLegacy = firstDistinctAddress(\n [pickAddress(sc, ['Escrow']), ...HISTORICAL_ESCROW_ADDRESSES.base_staging],\n stagingEscrowCurrent,\n );\n\n const stagingOrchestratorV2Override = resolveRuntimeAddressOverride([\n 'VITE_BASE_STAGING_ORCHESTRATOR_V2_ADDRESS',\n 'VITE_ORCHESTRATOR_V2_ADDRESS',\n 'VITE_ORCHESTRATORV2_ADDRESS',\n ]);\n const stagingOrchestratorCurrent =\n stagingOrchestratorV2Override ??\n pickAddress(sc, ['OrchestratorV2', 'Orchestrator_V2']) ??\n pickAddress(sc, ['Orchestrator']) ??\n STAGING_ORCHESTRATOR_V2_FALLBACK;\n const stagingOrchestratorLegacy = firstDistinctAddress(\n [pickAddress(sc, ['Orchestrator']), ...HISTORICAL_ORCHESTRATOR_ADDRESSES.base_staging],\n stagingOrchestratorCurrent,\n );\n const stagingRateManagerV1 = pickAddress(sc, ['RateManagerV1', 'DepositRateManagerRegistryV1']);\n\n return {\n addresses: {\n escrow: (stagingEscrowCurrent ?? stagingEscrowLegacy ?? '') as `0x${string}`,\n escrowV2: stagingEscrowCurrent,\n escrowAddresses: uniqueAddresses(\n stagingEscrowCurrent,\n stagingEscrowLegacy,\n ...HISTORICAL_ESCROW_ADDRESSES.base_staging,\n ),\n orchestrator: stagingOrchestratorCurrent ?? stagingOrchestratorLegacy,\n orchestratorV2: stagingOrchestratorCurrent,\n orchestratorAddresses: uniqueAddresses(\n stagingOrchestratorCurrent,\n stagingOrchestratorLegacy,\n ...HISTORICAL_ORCHESTRATOR_ADDRESSES.base_staging,\n ),\n unifiedPaymentVerifier: pickAddress(sc, [\n 'UnifiedPaymentVerifierV2',\n 'UnifiedPaymentVerifier',\n ]),\n unifiedPaymentVerifierV2: pickAddress(sc, ['UnifiedPaymentVerifierV2']),\n protocolViewer: pickAddress(sc, ['ProtocolViewerV2', 'ProtocolViewer']),\n protocolViewerEntries: (() => {\n const entries: Array<{ address: `0x${string}`; abi: Abi }> = [];\n // Primary: V2 PV (reads from V2 orchestrator)\n const pvV2Address = pickAddress(sc, ['ProtocolViewerV2']);\n const pvV2Abi = pickAbi(baseStagingAbisRaw as unknown as Record<string, unknown>, [\n 'ProtocolViewerV2',\n ]) as Abi | undefined;\n if (pvV2Address && pvV2Abi) {\n entries.push({ address: pvV2Address, abi: pvV2Abi });\n }\n // Fallback: V1 PV (reads V1 orchestrator intents via 1-input functions)\n const pvV1Address = pickAddress(sc, ['ProtocolViewer']);\n const pvV1Abi = ProtocolViewerBaseStaging as unknown as Abi;\n if (pvV1Address && !addressesEqual(pvV1Address, pvV2Address) && pvV1Abi) {\n entries.push({ address: pvV1Address, abi: pvV1Abi });\n }\n return entries.length > 0 ? entries : undefined;\n })(),\n usdc: baseStagingConstants.USDC as `0x${string}` | undefined,\n rateManagerV1: stagingRateManagerV1,\n orchestratorRegistry: pickAddress(sc, ['OrchestratorRegistry']),\n rateManagerRegistry: (pickAddress(sc, ['DepositRateManagerRegistryV1']) ??\n stagingRateManagerV1) as `0x${string}` | undefined,\n rateManagerController: pickAddress(sc, ['DepositRateManagerController']),\n chainlinkOracleAdapter: pickAddress(sc, ['ChainlinkOracleAdapter']),\n pythOracleAdapter: pickAddress(sc, ['PythOracleAdapter']),\n },\n abis: {\n escrow: EscrowBaseStaging as unknown as Abi,\n escrowV2: (addressesEqual(stagingEscrowCurrent, pickAddress(sc, ['Escrow']))\n ? (EscrowBaseStaging as unknown as Abi)\n : (pickAbi(baseStagingAbisRaw as unknown as Record<string, unknown>, ['EscrowV2']) ??\n (EscrowBaseStaging as unknown as Abi))) as Abi,\n orchestrator: OrchestratorBaseStaging as unknown as Abi,\n orchestratorV2: (addressesEqual(\n stagingOrchestratorCurrent,\n pickAddress(sc, ['Orchestrator']),\n )\n ? (OrchestratorBaseStaging as unknown as Abi)\n : (pickAbi(baseStagingAbisRaw as unknown as Record<string, unknown>, [\n 'OrchestratorV2',\n ]) ?? (OrchestratorBaseStaging as unknown as Abi))) as Abi,\n unifiedPaymentVerifier: (pickAbi(baseStagingAbisRaw as unknown as Record<string, unknown>, [\n 'UnifiedPaymentVerifierV2',\n ]) ?? (UnifiedPaymentVerifierBaseStaging as unknown as Abi)) as Abi,\n unifiedPaymentVerifierV2: pickAbi(\n baseStagingAbisRaw as unknown as Record<string, unknown>,\n ['UnifiedPaymentVerifierV2'],\n ),\n protocolViewer: (pickAbi(baseStagingAbisRaw as unknown as Record<string, unknown>, [\n 'ProtocolViewerV2',\n ]) ?? (ProtocolViewerBaseStaging as unknown as Abi)) as Abi,\n rateManagerV1: pickAbi(baseStagingAbisRaw as unknown as Record<string, unknown>, [\n 'RateManagerV1',\n 'DepositRateManagerRegistryV1',\n ]),\n orchestratorRegistry: pickAbi(baseStagingAbisRaw as unknown as Record<string, unknown>, [\n 'OrchestratorRegistry',\n ]),\n rateManagerRegistry: pickAbi(baseStagingAbisRaw as unknown as Record<string, unknown>, [\n 'DepositRateManagerRegistryV1',\n 'RateManagerV1',\n ]),\n rateManagerController: pickAbi(baseStagingAbisRaw as unknown as Record<string, unknown>, [\n 'DepositRateManagerController',\n ]),\n },\n };\n }\n\n const result = { addresses: addressesByKey[key], abis: abisByKey[key] };\n\n return result;\n}\n\n/**\n * Catalog of payment methods with their hashes and supported currencies.\n */\nexport type PaymentMethodCatalog = Record<\n string,\n { paymentMethodHash: `0x${string}`; currencies?: `0x${string}`[] }\n>;\n\n/**\n * Retrieves the payment methods catalog for a given chain and environment.\n *\n * The catalog maps payment platform names (e.g., 'wise', 'revolut') to their\n * on-chain hashes and supported currency hashes.\n *\n * @param chainId - The chain ID\n * @param env - Runtime environment\n * @returns Payment method catalog keyed by platform name\n *\n * @example\n * ```typescript\n * import { getPaymentMethodsCatalog } from '@zkp2p/sdk';\n *\n * const catalog = getPaymentMethodsCatalog(8453, 'production');\n * console.log(Object.keys(catalog)); // ['wise', 'venmo', 'revolut', ...]\n * console.log(catalog.wise.paymentMethodHash); // \"0x...\"\n * console.log(catalog.wise.currencies); // [\"0x...\", \"0x...\"] (currency hashes)\n * ```\n */\nexport function getPaymentMethodsCatalog(\n _chainId: number,\n env: RuntimeEnv = 'production',\n): PaymentMethodCatalog {\n const src = env === 'staging' ? baseStagingPaymentMethods : basePaymentMethods;\n const methods = (src?.methods ?? {}) as PaymentMethodCatalog;\n return methods;\n}\n\n/**\n * Returns the gating service address for a given chain and environment.\n *\n * The gating service signs intent parameters before they can be submitted\n * on-chain, providing an additional validation layer.\n *\n * @param chainId - The chain ID\n * @param env - Runtime environment\n * @returns Gating service signer address\n */\nexport function getGatingServiceAddress(\n _chainId: number,\n env: RuntimeEnv = 'production',\n): `0x${string}` {\n // Base Staging & Production share the same gating service in current deployments\n if (env === 'staging') {\n return '0x396D31055Db28C0C6f36e8b36f18FE7227248a97' as `0x${string}`;\n }\n // Base mainnet (production)\n return '0x396D31055Db28C0C6f36e8b36f18FE7227248a97' as `0x${string}`;\n}\n\nexport function getRateManagerContracts(\n chainId: number,\n env: RuntimeEnv = 'production',\n): {\n addresses: { registry: `0x${string}`; controller?: `0x${string}` };\n abis: { registry: Abi; controller?: Abi };\n} {\n const { addresses, abis } = getContracts(chainId, env);\n const registryAddress = addresses.rateManagerV1 ?? addresses.rateManagerRegistry;\n const registryAbi = abis.rateManagerV1 ?? abis.rateManagerRegistry;\n if (!registryAddress || !registryAbi) {\n throw new Error(`Rate manager contracts not available for chainId=${chainId}, env=${env}`);\n }\n const controllerAddress = addresses.rateManagerController;\n const controllerAbi = controllerAddress ? abis.rateManagerController : undefined;\n\n return {\n addresses: {\n registry: registryAddress,\n ...(controllerAddress ? { controller: controllerAddress } : {}),\n },\n abis: {\n registry: registryAbi,\n ...(controllerAbi ? { controller: controllerAbi } : {}),\n },\n };\n}\n","import { keccak256, toBytes, hexToBytes, bytesToHex } from 'viem';\n\n/**\n * Ensure a value is 32 bytes hex (0x + 64 nibbles). If ascii, keccak256 by default when hash=true.\n */\nexport function ensureBytes32(\n value: string,\n { hashIfAscii = false }: { hashIfAscii?: boolean } = {},\n): `0x${string}` {\n if (value.startsWith('0x')) {\n const bytes = hexToBytes(value as `0x${string}`);\n if (bytes.length !== 32) throw new Error('Expected 32-byte hex value');\n return value as `0x${string}`;\n }\n if (!hashIfAscii)\n throw new Error('Expected 32-byte hex; received ascii string. Pass hashIfAscii=true to hash.');\n const hashed = keccak256(toBytes(value));\n return hashed as `0x${string}`;\n}\n\n/**\n * Encode ASCII (<=32 chars) left-aligned, right-padded with zeros to 32 bytes.\n */\nexport function asciiToBytes32(value: string): `0x${string}` {\n const b = toBytes(value);\n if (b.length > 32) throw new Error('ASCII input exceeds 32 bytes');\n const padded = new Uint8Array(32);\n padded.set(b);\n return bytesToHex(padded);\n}\n","import lookups from '@zkp2p/contracts-v2/paymentMethods/lookups.json';\n\n/**\n * Canonical payment-method hash map sourced from contracts.\n */\nexport const METHOD_NAME_TO_HASH = lookups.nameToHash;\n","/**\n * Payment method resolution utilities.\n *\n * These functions convert between human-readable payment platform names\n * (e.g., 'wise', 'revolut') and their on-chain bytes32 hashes.\n *\n * @module paymentResolution\n */\n\nimport { ensureBytes32 } from './bytes32';\nimport { currencyKeccak256 } from './currencyKeccak256';\nimport { METHOD_NAME_TO_HASH } from './paymentMethodHashes';\nimport type { PaymentMethodCatalog } from '../contracts';\n\n// Optional JSON maps from @zkp2p/contracts-v2 (only provided on some envs)\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport baseStagingPaymentMethods from '@zkp2p/contracts-v2/paymentMethods/baseStaging';\n\ntype NetworkKey = 'base';\ntype RuntimeEnv = 'production' | 'preproduction' | 'staging';\n\nfunction getPaymentMethodMap(\n env: RuntimeEnv,\n _network: NetworkKey,\n): Record<string, { paymentMethodHash: `0x${string}` }> | null {\n if (env === 'staging') {\n const m = (baseStagingPaymentMethods?.methods ?? {}) as Record<\n string,\n { paymentMethodHash: `0x${string}` }\n >;\n return m && Object.keys(m).length ? m : null;\n }\n return null;\n}\n\n/**\n * Resolves a payment method hash from a human-readable name.\n *\n * First attempts to look up the hash from contracts-v2 payment method maps.\n * Falls back to keccak256(name) when maps are unavailable.\n *\n * **Warning**: The fallback may not match on-chain mappings. Prefer using\n * `resolvePaymentMethodHashFromCatalog` with an explicit catalog.\n *\n * @param nameOrBytes - Payment method name ('wise') or existing bytes32 hash\n * @param opts.env - Runtime environment ('production' | 'staging')\n * @param opts.network - Network key ('base')\n * @returns bytes32 payment method hash\n *\n * @example\n * ```typescript\n * const hash = resolvePaymentMethodHash('wise', { env: 'production' });\n * ```\n */\nexport function resolvePaymentMethodHash(\n nameOrBytes: string,\n opts: { env?: RuntimeEnv; network?: NetworkKey } = {},\n): `0x${string}` {\n const { env = 'production', network = 'base' } = opts;\n if (nameOrBytes.startsWith('0x')) return ensureBytes32(nameOrBytes) as `0x${string}`;\n const mapping = getPaymentMethodMap(env, network);\n if (mapping) {\n const key = nameOrBytes.toLowerCase();\n const entry = mapping[key];\n if (entry?.paymentMethodHash) return entry.paymentMethodHash;\n }\n // Fallback: hash ascii name to bytes32\n return ensureBytes32(nameOrBytes, { hashIfAscii: true });\n}\n\n/**\n * Encodes a fiat currency code into bytes32 format (keccak256 hash).\n *\n * If the input is already a hex string (0x-prefixed), it's normalized to bytes32.\n * Otherwise, the currency code is hashed using keccak256.\n *\n * @param codeOrBytes - Currency code ('USD') or existing bytes32 hash\n * @returns bytes32 keccak256 hash of the currency code\n *\n * @example\n * ```typescript\n * const bytes = resolveFiatCurrencyBytes32('USD');\n * // Returns: 0xc4ae21aac0c6549d71dd96035b7e0bdb6c79ebdba8891b666115bc976d16a29e\n * ```\n */\nexport function resolveFiatCurrencyBytes32(codeOrBytes: string): `0x${string}` {\n if (codeOrBytes.startsWith('0x')) return ensureBytes32(codeOrBytes) as `0x${string}`;\n return currencyKeccak256(codeOrBytes.toUpperCase()) as `0x${string}`;\n}\n\n/**\n * Resolves a payment method hash from a provided catalog.\n *\n * This is the recommended method for resolving payment methods as it uses\n * the exact catalog from `getPaymentMethodsCatalog()`, ensuring consistency\n * with on-chain registrations.\n *\n * If the processor is not found in the catalog, falls back to the known\n * protocol payment method hashes before throwing an error.\n *\n * @param processorName - Payment platform name ('wise', 'revolut', etc.)\n * @param catalog - Payment method catalog from `getPaymentMethodsCatalog()`\n * @returns bytes32 payment method hash\n * @throws Error with available processors if not found in catalog or fallback\n *\n * @example\n * ```typescript\n * import { getPaymentMethodsCatalog, resolvePaymentMethodHashFromCatalog } from '@zkp2p/sdk';\n *\n * const catalog = getPaymentMethodsCatalog(8453, 'production');\n * const hash = resolvePaymentMethodHashFromCatalog('wise', catalog);\n * ```\n */\nexport function resolvePaymentMethodHashFromCatalog(\n processorName: string,\n catalog: Record<string, { paymentMethodHash: `0x${string}`; currencies?: `0x${string}`[] }>,\n): `0x${string}` {\n if (!processorName) {\n throw new Error('processorName is required to resolve paymentMethodHash');\n }\n if (processorName.startsWith('0x')) {\n return ensureBytes32(processorName) as `0x${string}`;\n }\n const key = processorName.toLowerCase();\n const entry = catalog?.[key];\n if (entry?.paymentMethodHash) return entry.paymentMethodHash;\n\n // Fallback to known protocol payment method hashes when catalog is missing the entry\n const fallbackHash = METHOD_NAME_TO_HASH[key as keyof typeof METHOD_NAME_TO_HASH];\n if (fallbackHash) return fallbackHash as `0x${string}`;\n\n const available = Object.keys(catalog || {})\n .sort()\n .join(', ');\n throw new Error(\n available\n ? `Unknown processorName: ${processorName}. Available: ${available}`\n : `Unknown processorName: ${processorName}. The payment methods catalog is empty or unavailable.`,\n );\n}\n\n/**\n * Reverse-lookup: converts a payment method hash back to its name.\n *\n * @param hash - The payment method hash (bytes32)\n * @param catalog - Payment method catalog from `getPaymentMethodsCatalog()`\n * @returns Payment platform name (e.g., 'wise') or undefined if not found\n *\n * @example\n * ```typescript\n * const name = resolvePaymentMethodNameFromHash('0x...', catalog);\n * console.log(name); // \"wise\"\n * ```\n */\nexport function resolvePaymentMethodNameFromHash(\n hash: string,\n catalog: PaymentMethodCatalog,\n): string | undefined {\n if (!hash) return undefined;\n const target = ensureBytes32(hash) as `0x${string}`;\n for (const [name, entry] of Object.entries(catalog || {})) {\n if (entry?.paymentMethodHash?.toLowerCase() === target.toLowerCase()) return name;\n }\n return undefined;\n}\n","import { parseBigIntLike as toBigInt } from './bigint';\n\nexport type PV_ReferralFee = {\n recipient: `0x${string}`;\n fee: bigint;\n};\n\nexport type PV_Deposit = {\n depositor: string;\n delegate: string;\n token: string;\n amount: bigint;\n intentAmountRange: { min: bigint; max: bigint };\n acceptingIntents: boolean;\n remainingDeposits: bigint;\n outstandingIntentAmount: bigint;\n makerProtocolFee: bigint;\n reservedMakerFees: bigint;\n accruedMakerFees: bigint;\n accruedReferrerFees: bigint;\n intentGuardian: string;\n retainOnEmpty: boolean;\n referrer: string;\n referrerFee: bigint;\n};\n\nexport type PV_Currency = { code: string; minConversionRate: bigint };\nexport type PV_PaymentMethodData = {\n paymentMethod: string; // bytes32\n verificationData: {\n intentGatingService: string;\n payeeDetails: string; // bytes32\n data: string; // bytes\n };\n currencies: PV_Currency[];\n};\n\nexport type PV_DepositView = {\n depositId: bigint;\n deposit: PV_Deposit;\n availableLiquidity: bigint;\n paymentMethods: PV_PaymentMethodData[];\n intentHashes: string[];\n};\n\nexport type PV_Intent = {\n owner: string;\n to: string;\n escrow: string;\n depositId: bigint;\n amount: bigint;\n timestamp: bigint;\n paymentMethod: string; // bytes32\n fiatCurrency: string; // bytes32\n conversionRate: bigint;\n referralFees: PV_ReferralFee[];\n postIntentHook: string;\n data: string;\n};\n\nexport type PV_IntentView = {\n intentHash: string;\n intent: PV_Intent;\n deposit: Omit<PV_DepositView, 'intentHashes'>;\n};\n\nfunction parseReferralFees(rawIntent: any): PV_ReferralFee[] {\n if (Array.isArray(rawIntent?.referralFees)) {\n return rawIntent.referralFees.map((fee: any) => ({\n recipient: (fee.recipient ?? '') as `0x${string}`,\n fee: toBigInt(fee.fee ?? 0),\n }));\n }\n\n const legacyRecipient = rawIntent?.referrer ?? '';\n const legacyFee = toBigInt(rawIntent?.referrerFee ?? 0);\n if (\n typeof legacyRecipient === 'string' &&\n legacyRecipient !== '' &&\n legacyRecipient !== '0x0000000000000000000000000000000000000000' &&\n legacyFee > 0n\n ) {\n return [{ recipient: legacyRecipient as `0x${string}`, fee: legacyFee }];\n }\n\n return [];\n}\n\nexport function parseDepositView(raw: any): PV_DepositView {\n return {\n depositId: toBigInt(raw.depositId),\n deposit: {\n depositor: raw.deposit.depositor,\n delegate: raw.deposit.delegate,\n token: raw.deposit.token,\n amount: toBigInt(raw.deposit.amount ?? 0),\n intentAmountRange: {\n min: toBigInt(raw.deposit.intentAmountRange?.min ?? 0),\n max: toBigInt(raw.deposit.intentAmountRange?.max ?? 0),\n },\n acceptingIntents: raw.deposit.acceptingIntents ?? false,\n remainingDeposits: toBigInt(raw.deposit.remainingDeposits ?? 0),\n outstandingIntentAmount: toBigInt(raw.deposit.outstandingIntentAmount ?? 0),\n makerProtocolFee: toBigInt(raw.deposit.makerProtocolFee ?? 0),\n reservedMakerFees: toBigInt(raw.deposit.reservedMakerFees ?? 0),\n accruedMakerFees: toBigInt(raw.deposit.accruedMakerFees ?? 0),\n accruedReferrerFees: toBigInt(raw.deposit.accruedReferrerFees ?? 0),\n intentGuardian: raw.deposit.intentGuardian ?? '',\n retainOnEmpty: raw.deposit.retainOnEmpty ?? false,\n referrer: raw.deposit.referrer ?? '',\n referrerFee: toBigInt(raw.deposit.referrerFee ?? 0),\n },\n availableLiquidity: toBigInt(raw.availableLiquidity),\n paymentMethods: (raw.paymentMethods || []).map((pm: any) => ({\n paymentMethod: pm.paymentMethod,\n verificationData: {\n intentGatingService: pm.verificationData.intentGatingService,\n payeeDetails: pm.verificationData.payeeDetails,\n data: pm.verificationData.data,\n },\n currencies: (pm.currencies || []).map((c: any) => ({\n code: c.code,\n minConversionRate: toBigInt(c.minConversionRate),\n })),\n })),\n intentHashes: raw.intentHashes || [],\n };\n}\n\nexport function parseIntentView(raw: any): PV_IntentView {\n const parsedDeposit = parseDepositView(raw.deposit);\n const deposit: Omit<PV_DepositView, 'intentHashes'> = {\n depositId: parsedDeposit.depositId,\n deposit: parsedDeposit.deposit,\n availableLiquidity: parsedDeposit.availableLiquidity,\n paymentMethods: parsedDeposit.paymentMethods,\n };\n return {\n intentHash: raw.intentHash,\n intent: {\n owner: raw.intent.owner,\n to: raw.intent.to,\n escrow: raw.intent.escrow,\n depositId: toBigInt(raw.intent.depositId),\n amount: toBigInt(raw.intent.amount),\n timestamp: toBigInt(raw.intent.timestamp),\n paymentMethod: raw.intent.paymentMethod,\n fiatCurrency: raw.intent.fiatCurrency,\n conversionRate: toBigInt(raw.intent.conversionRate),\n referralFees: parseReferralFees(raw.intent),\n postIntentHook: raw.intent.postIntentHook,\n data: raw.intent.data,\n },\n deposit,\n };\n}\n\n// Enrichment helpers for dashboards/explorers\nimport { getPaymentMethodsCatalog, type RuntimeEnv } from '../contracts';\nimport { resolvePaymentMethodNameFromHash } from './paymentResolution';\nimport { getCurrencyInfoFromHash } from './currency';\n\nexport function enrichPvDepositView(\n view: PV_DepositView,\n chainId: number,\n env: RuntimeEnv = 'production',\n) {\n const catalog = getPaymentMethodsCatalog(chainId, env);\n return {\n ...view,\n paymentMethods: view.paymentMethods.map((pm) => ({\n ...pm,\n processorName: resolvePaymentMethodNameFromHash(pm.paymentMethod, catalog),\n currencies: pm.currencies.map((c) => ({\n ...c,\n currencyInfo: getCurrencyInfoFromHash(c.code),\n })),\n })),\n };\n}\n\nexport function enrichPvIntentView(\n view: PV_IntentView,\n chainId: number,\n env: RuntimeEnv = 'production',\n) {\n const catalog = getPaymentMethodsCatalog(chainId, env);\n return {\n ...view,\n intent: {\n ...view.intent,\n processorName: resolvePaymentMethodNameFromHash(view.intent.paymentMethod, catalog),\n currencyInfo: getCurrencyInfoFromHash(view.intent.fiatCurrency),\n },\n deposit: enrichPvDepositView(view.deposit as any, chainId, env),\n } as any;\n}\n"]}
|