@provex/utils 1.0.16 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/src/chain.d.ts +436 -4
  2. package/dist/src/chain.js +80 -0
  3. package/dist/src/chain.test.d.ts +1 -0
  4. package/dist/src/chain.test.js +112 -0
  5. package/dist/src/contracts.d.ts +196 -20
  6. package/dist/src/contracts.js +245 -17
  7. package/dist/src/contracts.test.d.ts +1 -0
  8. package/dist/src/contracts.test.js +243 -0
  9. package/dist/src/conversionRates.d.ts +99 -8
  10. package/dist/src/conversionRates.js +74 -4
  11. package/dist/src/conversionRates.test.d.ts +1 -0
  12. package/dist/src/conversionRates.test.js +473 -0
  13. package/dist/src/currencies.d.ts +113 -9
  14. package/dist/src/currencies.js +119 -38
  15. package/dist/src/currencies.test.d.ts +1 -0
  16. package/dist/src/currencies.test.js +343 -0
  17. package/dist/src/data/countries.json +166 -166
  18. package/dist/src/deposit.d.ts +69 -1
  19. package/dist/src/deposit.js +52 -1
  20. package/dist/src/depositKeys.d.ts +154 -0
  21. package/dist/src/depositKeys.js +104 -0
  22. package/dist/src/depositKeys.test.d.ts +1 -0
  23. package/dist/src/depositKeys.test.js +231 -0
  24. package/dist/src/endpoints.d.ts +51 -0
  25. package/dist/src/endpoints.js +70 -0
  26. package/dist/src/endpoints.test.d.ts +1 -0
  27. package/dist/src/endpoints.test.js +54 -0
  28. package/dist/src/events.d.ts +40 -2
  29. package/dist/src/events.js +86 -10
  30. package/dist/src/events.test.d.ts +1 -0
  31. package/dist/src/events.test.js +111 -0
  32. package/dist/src/fees.d.ts +136 -0
  33. package/dist/src/fees.js +178 -0
  34. package/dist/src/fees.test.d.ts +1 -0
  35. package/dist/src/fees.test.js +165 -0
  36. package/dist/src/ids.d.ts +125 -22
  37. package/dist/src/ids.js +211 -61
  38. package/dist/src/ids.test.d.ts +1 -0
  39. package/dist/src/ids.test.js +607 -0
  40. package/dist/src/index.d.ts +30 -1
  41. package/dist/src/index.js +30 -1
  42. package/dist/src/input.d.ts +23 -4
  43. package/dist/src/input.js +23 -4
  44. package/dist/src/intent.d.ts +38 -2
  45. package/dist/src/intent.js +28 -1
  46. package/dist/src/intent.test.d.ts +1 -0
  47. package/dist/src/intent.test.js +119 -0
  48. package/dist/src/json.d.ts +38 -1
  49. package/dist/src/json.js +38 -2
  50. package/dist/src/normalization.d.ts +224 -0
  51. package/dist/src/normalization.js +119 -0
  52. package/dist/src/normalization.test.d.ts +1 -0
  53. package/dist/src/normalization.test.js +284 -0
  54. package/dist/src/participants.d.ts +19 -4
  55. package/dist/src/participants.js +19 -4
  56. package/dist/src/payment.d.ts +333 -16
  57. package/dist/src/payment.js +768 -58
  58. package/dist/src/payment.test.d.ts +1 -0
  59. package/dist/src/payment.test.js +272 -0
  60. package/dist/src/peer-types.d.ts +327 -0
  61. package/dist/src/peer-types.js +169 -0
  62. package/dist/src/profit.d.ts +26 -5
  63. package/dist/src/profit.js +31 -8
  64. package/dist/src/profit.test.d.ts +1 -0
  65. package/dist/src/profit.test.js +315 -0
  66. package/dist/src/reputation.d.ts +125 -0
  67. package/dist/src/reputation.js +188 -0
  68. package/dist/src/reputation.test.d.ts +1 -0
  69. package/dist/src/reputation.test.js +156 -0
  70. package/dist/src/sort.d.ts +49 -10
  71. package/dist/src/sort.js +40 -9
  72. package/dist/src/sort.test.d.ts +1 -0
  73. package/dist/src/sort.test.js +216 -0
  74. package/dist/src/stateKey.d.ts +35 -0
  75. package/dist/src/stateKey.js +36 -0
  76. package/dist/src/stats.d.ts +55 -1
  77. package/dist/src/stats.js +46 -1
  78. package/dist/src/stats.test.d.ts +1 -0
  79. package/dist/src/stats.test.js +104 -0
  80. package/dist/src/time.d.ts +59 -9
  81. package/dist/src/time.js +71 -15
  82. package/dist/src/time.test.d.ts +1 -0
  83. package/dist/src/time.test.js +231 -0
  84. package/dist/src/tokens.d.ts +11972 -145
  85. package/dist/src/tokens.js +98 -17
  86. package/dist/src/tokens.test.d.ts +1 -0
  87. package/dist/src/tokens.test.js +193 -0
  88. package/dist/src/units.d.ts +183 -0
  89. package/dist/src/units.js +206 -6
  90. package/dist/src/units.test.d.ts +1 -0
  91. package/dist/src/units.test.js +327 -0
  92. package/dist/src/zkp2p-types.d.ts +273 -4
  93. package/dist/src/zkp2p-types.js +169 -1
  94. package/dist/tsconfig.tsbuildinfo +1 -1
  95. package/package.json +116 -26
  96. package/scripts/convert-svg.ts +0 -22
  97. package/src/chain.ts +0 -27
  98. package/src/contracts.ts +0 -89
  99. package/src/conversionRates.ts +0 -356
  100. package/src/currencies.ts +0 -286
  101. package/src/data/countries.json +0 -1099
  102. package/src/deposit.ts +0 -2
  103. package/src/events.ts +0 -21
  104. package/src/flags/eur.svg +0 -4
  105. package/src/flags/usd.svg +0 -25
  106. package/src/flags.ts +0 -4
  107. package/src/global.d.ts +0 -9
  108. package/src/ids.ts +0 -137
  109. package/src/index.ts +0 -16
  110. package/src/input.ts +0 -35
  111. package/src/intent.ts +0 -15
  112. package/src/json.ts +0 -42
  113. package/src/participants.ts +0 -14
  114. package/src/payment.ts +0 -573
  115. package/src/profit.ts +0 -55
  116. package/src/sort.ts +0 -49
  117. package/src/stats.ts +0 -10
  118. package/src/time.ts +0 -123
  119. package/src/tokens.ts +0 -159
  120. package/src/units.ts +0 -120
  121. package/src/zkp2p-types.ts +0 -55
  122. package/tsconfig.json +0 -18
@@ -1,30 +1,206 @@
1
+ /**
2
+ * @fileoverview Contract addresses and configuration for the Peer protocol.
3
+ *
4
+ * This module is the single source of truth for all deployed contract addresses
5
+ * across supported chains (Base, Pulsechain) and protocol versions (V2, V3).
6
+ *
7
+ * @remarks
8
+ * **Version Strategy:**
9
+ * - V3 is the active version for all new transactions on both Base and Pulsechain
10
+ * - V2 contracts remain available for historical data access only
11
+ *
12
+ * **Contract Architecture (V3):**
13
+ * - Escrow: Holds depositor funds, manages deposit lifecycle
14
+ * - Orchestrator: Coordinates intents across escrows (read via escrow.orchestrator())
15
+ * - UnifiedPaymentVerifier: Verifies zkTLS proofs for all payment methods
16
+ * - PaymentVerifierRegistry: Maps payment method IDs to verifier contracts
17
+ *
18
+ * **Contract Architecture (V2 - Deprecated):**
19
+ * - Escrow: Simpler escrow without orchestrator
20
+ * - Per-provider verifiers: Separate contracts for Venmo, Zelle, etc.
21
+ *
22
+ * @see {@link chain} for chain configuration
23
+ * @see {@link abis} for contract ABIs
24
+ */
1
25
  import { type Hex } from 'viem';
2
26
  import type { ChainId } from './chain.js';
3
27
  /**
4
- * Contracts for the app
28
+ * Contract type definitions for the app.
5
29
  */
6
- export type Contracts = {
30
+ type NonEmptyArray<T> = [T, ...T[]];
31
+ export type V2Contracts = {
7
32
  gatingService: Hex;
8
33
  usdc: Hex;
9
- escrow: Hex[];
10
- venmoReclaimVerifier: Hex[];
11
- revolutReclaimVerifier: Hex[];
12
- cashappReclaimVerifier: Hex[];
13
- wiseReclaimVerifier: Hex[];
14
- mercadopagoReclaimVerifier: Hex[];
15
- zelleBaseVerifier: Hex[];
16
- zelleBoAReclaimVerifier: Hex[];
17
- zelleChaseReclaimVerifier: Hex[];
18
- zelleCitiReclaimVerifier: Hex[];
19
- paypalReclaimVerifier: Hex[];
20
- monzoReclaimVerifier: Hex[];
34
+ escrow: NonEmptyArray<Hex>;
35
+ venmoReclaimVerifier: NonEmptyArray<Hex>;
36
+ revolutReclaimVerifier: NonEmptyArray<Hex>;
37
+ cashappReclaimVerifier: NonEmptyArray<Hex>;
38
+ wiseReclaimVerifier: NonEmptyArray<Hex>;
39
+ mercadopagoReclaimVerifier: NonEmptyArray<Hex>;
40
+ zelleBaseVerifier: NonEmptyArray<Hex>;
41
+ zelleBoAReclaimVerifier: NonEmptyArray<Hex>;
42
+ zelleChaseReclaimVerifier: NonEmptyArray<Hex>;
43
+ zelleCitiReclaimVerifier: NonEmptyArray<Hex>;
44
+ paypalReclaimVerifier: NonEmptyArray<Hex>;
45
+ monzoReclaimVerifier: NonEmptyArray<Hex>;
46
+ };
47
+ export type V3Contracts = {
48
+ usdc: Hex;
49
+ gatingService: Hex;
50
+ escrow: NonEmptyArray<Hex>;
51
+ unifiedPaymentVerifier: NonEmptyArray<Hex>;
21
52
  };
53
+ export type ContractKey = keyof V2Contracts | keyof V3Contracts;
22
54
  export declare const reclaimSigners: {
23
- readonly zkp2pWitnessSigner: "0x0636c417755E3ae25C6c166D181c0607F4C572A3";
55
+ readonly peerWitnessSigner: "0x0636c417755E3ae25C6c166D181c0607F4C572A3";
24
56
  readonly reclaimWitnessSigner: "0x244897572368eadf65bfbc5aec98d8e5443a9072";
25
57
  };
26
- export declare const baseContracts: Contracts;
27
- export declare const pulsechainContracts: Contracts;
28
- export declare const contractsByChainId: Map<number, Contracts>;
29
- export declare const getContracts: (chainId: ChainId) => Contracts | null;
30
- export declare const getLatestContract: (chainId: ChainId, key: keyof Contracts) => `0x${string}` | null;
58
+ export declare const v2BaseContracts: V2Contracts;
59
+ export declare const v2PulsechainContracts: V2Contracts;
60
+ export declare const v3BaseContracts: V3Contracts;
61
+ /**
62
+ * V3 contracts deployed to Pulsechain (Chain ID 369)
63
+ * Deployed: 2026-01-12
64
+ * Deployer: 0xC3c7e05D1BA19563693D891e5c38f0FC988A5d11
65
+ * MultiSig: 0x948eB6D3A08BEb29Dc1D08d09753862573A94122
66
+ */
67
+ export declare const v3PulsechainContracts: V3Contracts;
68
+ /**
69
+ * V3 Pulsechain protocol contract addresses - FOR REFERENCE ONLY
70
+ *
71
+ * DO NOT use these directly in code. The orchestrator and paymentVerifierRegistry
72
+ * addresses should be read dynamically from the escrow contract at runtime.
73
+ * See ponder.config.ts `callEach()` for the correct pattern.
74
+ */
75
+ export declare const V3_PULSECHAIN_DEPLOYMENT_REFERENCE: {
76
+ readonly orchestrator: "0x742d48639F44701Bff5A0A441600AD6DA4A3b080";
77
+ readonly paymentVerifierRegistry: "0x6a4fF1950Be05995dEe75920cf27CD8FEbB6597A";
78
+ readonly protocolViewer: "0x31dD72E1a385F98F4e6A94330c8121d2Ed62Ab72";
79
+ readonly escrowRegistry: "0x7238d0B6a28a3a6e3DfCd281D7Cb9b3250B30EA6";
80
+ readonly postIntentHookRegistry: "0x94F510fa245843Ff5eDa2d18479FE63ac51F8fE6";
81
+ readonly relayerRegistry: "0x689F82b4078aA07F443af9ae308534bD2Ff545D3";
82
+ readonly nullifierRegistry: "0x4AeA2288ec542963256b66D70EfddF4cB8754f82";
83
+ readonly simpleAttestationVerifier: "0x49DAd1f29a3FE2E4D90a59e6687d9f7A2836B4a8";
84
+ };
85
+ export declare const versions: {
86
+ readonly V2: "v2";
87
+ readonly V3: "v3";
88
+ };
89
+ export declare const versionKeys: ("v2" | "v3")[];
90
+ export type Version = (typeof versionKeys)[number];
91
+ /**
92
+ * Contract addresses organized by version and chain.
93
+ *
94
+ * @important v3 on Base is the active version for the buy/sell UI.
95
+ * v2 contracts are deprecated but remain for historical data access.
96
+ */
97
+ export declare const contracts: {
98
+ v2: {
99
+ 8453: V2Contracts;
100
+ 369: V2Contracts;
101
+ };
102
+ v3: {
103
+ 8453: V3Contracts;
104
+ 369: V3Contracts;
105
+ };
106
+ };
107
+ /**
108
+ * Get contracts for a specific version and chain.
109
+ * @param version - The contract version (v2 or v3)
110
+ * @param chainId - The chain ID
111
+ * @returns The contracts for that version and chain, or null if not found
112
+ */
113
+ export declare const getContracts: (version: Version, chainId: ChainId) => V2Contracts | V3Contracts;
114
+ /**
115
+ * Get the latest deployed contract address for a given key.
116
+ *
117
+ * @important This function defaults to Base v3 contracts for the buy/sell UI.
118
+ * v2 contracts are deprecated for new transactions.
119
+ *
120
+ * When contracts are upgraded, the latest version is at the end of the array.
121
+ *
122
+ * @param chainId - The chain ID
123
+ * @param key - The contract key (e.g., 'escrow', 'usdc', 'unifiedPaymentVerifier')
124
+ * @param version - Optional version override for accessing historical v2 data
125
+ * @returns The contract address, or null if not found
126
+ *
127
+ * @example
128
+ * // Get Base v3 escrow (default for buy/sell UI)
129
+ * const escrow = getLatestContract(base.id, 'escrow')
130
+ *
131
+ * @example
132
+ * // Explicitly get v2 contract for historical data
133
+ * const v2Escrow = getLatestContract(pulsechain.id, 'escrow', 'v2')
134
+ */
135
+ export declare const getLatestContract: (chainId: ChainId, key: ContractKey, version?: Version) => Hex | null;
136
+ /**
137
+ * Represents a unique escrow location identified by version, chain, and address
138
+ */
139
+ export type EscrowLocation = {
140
+ version: Version;
141
+ chainId: ChainId;
142
+ escrow: Hex;
143
+ };
144
+ /**
145
+ * Get all escrow contracts across all versions and chains.
146
+ * Returns a flat list of all escrow locations for querying deposits.
147
+ *
148
+ * @returns Array of escrow locations with version, chainId, and escrow address
149
+ *
150
+ * @example
151
+ * // Get all escrows to search for a deposit
152
+ * const escrows = getAllEscrowContracts()
153
+ * // [
154
+ * // { version: 'v2', chainId: 8453, escrow: '0xCA38...' },
155
+ * // { version: 'v2', chainId: 369, escrow: '0x2932...' },
156
+ * // { version: 'v3', chainId: 8453, escrow: '0x2f12...' },
157
+ * // ]
158
+ */
159
+ export declare function getAllEscrowContracts(): EscrowLocation[];
160
+ /**
161
+ * Get all V3 escrow contracts across all chains.
162
+ * Used for cross-chain nullifier checking to prevent double-spending.
163
+ *
164
+ * @returns Array of V3 escrow locations with chainId and escrow address
165
+ *
166
+ * @example
167
+ * const v3Escrows = getAllV3EscrowContracts()
168
+ * // [
169
+ * // { version: 'v3', chainId: 8453, escrow: '0x2f12...' },
170
+ * // { version: 'v3', chainId: 369, escrow: '0x0B42...' },
171
+ * // ]
172
+ */
173
+ export declare function getAllV3EscrowContracts(): EscrowLocation[];
174
+ /**
175
+ * Get a short display label for an escrow address (first 6 + last 4 chars)
176
+ * @param escrow - The escrow address
177
+ * @returns Shortened address string
178
+ */
179
+ export declare function shortenEscrowAddress(escrow: Hex): string;
180
+ /**
181
+ * Get the version of an escrow contract by looking up its address.
182
+ *
183
+ * @param escrowAddress - The escrow contract address to look up
184
+ * @param chainId - Optional chain ID to narrow down the search
185
+ * @returns The escrow version ('v2' or 'v3'), or null if not found
186
+ *
187
+ * @example
188
+ * // Determine if escrow supports V3 features
189
+ * const version = getEscrowVersion(deposit.escrow, deposit.chainId)
190
+ * const isV3 = version === 'v3'
191
+ */
192
+ export declare function getEscrowVersion(escrowAddress: Hex, chainId?: ChainId): Version | null;
193
+ /**
194
+ * Check if an escrow address is a V3 contract.
195
+ * Convenience function for feature gating V3-only functionality.
196
+ *
197
+ * @param escrowAddress - The escrow contract address
198
+ * @param chainId - The chain ID
199
+ * @returns true if the escrow is V3, false otherwise
200
+ *
201
+ * @example
202
+ * // Gate V3-only features in UI
203
+ * const showRetainToggle = isV3Escrow(deposit.escrow, deposit.chainId) && isOwner
204
+ */
205
+ export declare function isV3Escrow(escrowAddress: Hex, chainId: ChainId): boolean;
206
+ export {};
@@ -1,10 +1,34 @@
1
+ /**
2
+ * @fileoverview Contract addresses and configuration for the Peer protocol.
3
+ *
4
+ * This module is the single source of truth for all deployed contract addresses
5
+ * across supported chains (Base, Pulsechain) and protocol versions (V2, V3).
6
+ *
7
+ * @remarks
8
+ * **Version Strategy:**
9
+ * - V3 is the active version for all new transactions on both Base and Pulsechain
10
+ * - V2 contracts remain available for historical data access only
11
+ *
12
+ * **Contract Architecture (V3):**
13
+ * - Escrow: Holds depositor funds, manages deposit lifecycle
14
+ * - Orchestrator: Coordinates intents across escrows (read via escrow.orchestrator())
15
+ * - UnifiedPaymentVerifier: Verifies zkTLS proofs for all payment methods
16
+ * - PaymentVerifierRegistry: Maps payment method IDs to verifier contracts
17
+ *
18
+ * **Contract Architecture (V2 - Deprecated):**
19
+ * - Escrow: Simpler escrow without orchestrator
20
+ * - Per-provider verifiers: Separate contracts for Venmo, Zelle, etc.
21
+ *
22
+ * @see {@link chain} for chain configuration
23
+ * @see {@link abis} for contract ABIs
24
+ */
1
25
  import { getAddress } from 'viem';
2
26
  import { base, pulsechain } from 'viem/chains';
3
27
  export const reclaimSigners = {
4
- zkp2pWitnessSigner: '0x0636c417755E3ae25C6c166D181c0607F4C572A3',
28
+ peerWitnessSigner: '0x0636c417755E3ae25C6c166D181c0607F4C572A3',
5
29
  reclaimWitnessSigner: '0x244897572368eadf65bfbc5aec98d8e5443a9072',
6
30
  };
7
- export const baseContracts = {
31
+ export const v2BaseContracts = {
8
32
  gatingService: getAddress('0x396D31055Db28C0C6f36e8b36f18FE7227248a97'),
9
33
  usdc: getAddress('0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'),
10
34
  escrow: [getAddress('0xCA38607D85E8F6294Dc10728669605E6664C2D70')],
@@ -26,7 +50,7 @@ export const baseContracts = {
26
50
  paypalReclaimVerifier: [getAddress('0x03d17E9371C858072E171276979f6B44571C5DeA')],
27
51
  monzoReclaimVerifier: [getAddress('0x0dE46433bD251027f73eD8f28E01eF05DA36a2E0')],
28
52
  };
29
- export const pulsechainContracts = {
53
+ export const v2PulsechainContracts = {
30
54
  gatingService: getAddress('0x4Bd6364FCC4D8A537aBfee33B16E959794fDf9Cf'),
31
55
  usdc: getAddress('0x15D38573d2feeb82e7ad5187aB8c1D52810B1f07'),
32
56
  escrow: [getAddress('0x2932E08BFD212Ef0732257bDd6463BF55E9b97d7')],
@@ -43,22 +67,226 @@ export const pulsechainContracts = {
43
67
  zelleChaseReclaimVerifier: [getAddress('0xB0aA0a58959465bBCf0eCbD62A84B743A5435c99')],
44
68
  zelleCitiReclaimVerifier: [getAddress('0x5624E479924eBFb25B51F36e3FDaE605dADb448b')],
45
69
  };
46
- export const contractsByChainId = new Map([
47
- [base.id, baseContracts],
48
- [pulsechain.id, pulsechainContracts],
49
- ]);
50
- export const getContracts = (chainId) => {
51
- return contractsByChainId.get(chainId) ?? null;
70
+ export const v3BaseContracts = {
71
+ usdc: getAddress('0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'),
72
+ gatingService: getAddress('0x5106a86819ed6bb82c77ccbfc151250e1d369dba'),
73
+ escrow: [
74
+ getAddress('0x2f121CDDCA6d652f35e8B3E560f9760898888888'),
75
+ getAddress('0x777777779d229cdf3110e9de47943791c26300ef'),
76
+ ],
77
+ unifiedPaymentVerifier: [
78
+ getAddress('0x16b3e4a3CA36D3A4bCA281767f15C7ADeF4ab163'),
79
+ getAddress('0x46A58Dc65587D4D7B8198C6A25eEdf5b2535Da94'),
80
+ ],
81
+ };
82
+ /**
83
+ * V3 contracts deployed to Pulsechain (Chain ID 369)
84
+ * Deployed: 2026-01-12
85
+ * Deployer: 0xC3c7e05D1BA19563693D891e5c38f0FC988A5d11
86
+ * MultiSig: 0x948eB6D3A08BEb29Dc1D08d09753862573A94122
87
+ */
88
+ export const v3PulsechainContracts = {
89
+ usdc: getAddress('0x15D38573d2feeb82e7ad5187aB8c1D52810B1f07'),
90
+ gatingService: getAddress('0x4Bd6364FCC4D8A537aBfee33B16E959794fDf9Cf'),
91
+ escrow: [getAddress('0x0B42393d4DBA08892d339b32Cd3064248003f11a')],
92
+ unifiedPaymentVerifier: [getAddress('0x0e73181a60C6a58Eb9298bCf28781E1d46cd81Db')],
93
+ };
94
+ /**
95
+ * V3 Pulsechain protocol contract addresses - FOR REFERENCE ONLY
96
+ *
97
+ * DO NOT use these directly in code. The orchestrator and paymentVerifierRegistry
98
+ * addresses should be read dynamically from the escrow contract at runtime.
99
+ * See ponder.config.ts `callEach()` for the correct pattern.
100
+ */
101
+ export const V3_PULSECHAIN_DEPLOYMENT_REFERENCE = {
102
+ orchestrator: '0x742d48639F44701Bff5A0A441600AD6DA4A3b080', // read via escrow.orchestrator()
103
+ paymentVerifierRegistry: '0x6a4fF1950Be05995dEe75920cf27CD8FEbB6597A', // read via escrow.paymentVerifierRegistry()
104
+ protocolViewer: '0x31dD72E1a385F98F4e6A94330c8121d2Ed62Ab72', // static registry
105
+ escrowRegistry: '0x7238d0B6a28a3a6e3DfCd281D7Cb9b3250B30EA6',
106
+ postIntentHookRegistry: '0x94F510fa245843Ff5eDa2d18479FE63ac51F8fE6',
107
+ relayerRegistry: '0x689F82b4078aA07F443af9ae308534bD2Ff545D3',
108
+ nullifierRegistry: '0x4AeA2288ec542963256b66D70EfddF4cB8754f82',
109
+ simpleAttestationVerifier: '0x49DAd1f29a3FE2E4D90a59e6687d9f7A2836B4a8',
110
+ };
111
+ export const versions = {
112
+ V2: 'v2', // Deprecated: Historical data only
113
+ V3: 'v3', // Active: Primary version for Base buy/sell UI
52
114
  };
53
- export const getLatestContract = (chainId, key) => {
54
- const contracts = getContracts(chainId);
55
- if (!contracts)
115
+ export const versionKeys = Object.values(versions);
116
+ /**
117
+ * Contract addresses organized by version and chain.
118
+ *
119
+ * @important v3 on Base is the active version for the buy/sell UI.
120
+ * v2 contracts are deprecated but remain for historical data access.
121
+ */
122
+ export const contracts = {
123
+ v2: {
124
+ // Deprecated: Historical data only
125
+ [base.id]: v2BaseContracts,
126
+ [pulsechain.id]: v2PulsechainContracts,
127
+ },
128
+ v3: {
129
+ // Active: Primary version for buy/sell UI
130
+ [base.id]: v3BaseContracts,
131
+ [pulsechain.id]: v3PulsechainContracts,
132
+ },
133
+ };
134
+ /**
135
+ * Get the default version for a given chain.
136
+ *
137
+ * @important Both Base and Pulsechain now use v3 as the primary version.
138
+ * v2 contracts are deprecated for new transactions but remain available for historical data.
139
+ *
140
+ * @param chainId - The chain ID
141
+ * @returns The default contract version for the chain
142
+ *
143
+ * Defaults:
144
+ * - Base: v3 (active, used for all new transactions)
145
+ * - PulseChain: v3 (active, deployed 2026-01-12)
146
+ * - All others: v3
147
+ */
148
+ const getDefaultVersion = (_chainId) => {
149
+ // Both Base and Pulsechain use v3 for all new transactions
150
+ return 'v3';
151
+ };
152
+ /**
153
+ * Get contracts for a specific version and chain.
154
+ * @param version - The contract version (v2 or v3)
155
+ * @param chainId - The chain ID
156
+ * @returns The contracts for that version and chain, or null if not found
157
+ */
158
+ export const getContracts = (version, chainId) => {
159
+ return version === 'v2' ? contracts.v2[chainId] : contracts.v3[chainId];
160
+ };
161
+ /**
162
+ * Get the latest deployed contract address for a given key.
163
+ *
164
+ * @important This function defaults to Base v3 contracts for the buy/sell UI.
165
+ * v2 contracts are deprecated for new transactions.
166
+ *
167
+ * When contracts are upgraded, the latest version is at the end of the array.
168
+ *
169
+ * @param chainId - The chain ID
170
+ * @param key - The contract key (e.g., 'escrow', 'usdc', 'unifiedPaymentVerifier')
171
+ * @param version - Optional version override for accessing historical v2 data
172
+ * @returns The contract address, or null if not found
173
+ *
174
+ * @example
175
+ * // Get Base v3 escrow (default for buy/sell UI)
176
+ * const escrow = getLatestContract(base.id, 'escrow')
177
+ *
178
+ * @example
179
+ * // Explicitly get v2 contract for historical data
180
+ * const v2Escrow = getLatestContract(pulsechain.id, 'escrow', 'v2')
181
+ */
182
+ export const getLatestContract = (chainId, key, version) => {
183
+ const v = version ?? getDefaultVersion(chainId);
184
+ const chainContracts = getContracts(v, chainId);
185
+ if (!chainContracts) {
186
+ console.log('No contracts found for chainId', v, chainId);
56
187
  return null;
57
- const target = contracts[key];
188
+ }
189
+ const target = chainContracts[key];
58
190
  if (!target)
59
191
  return null;
60
- if (Array.isArray(target)) {
61
- return target[target.length - 1] ?? null;
62
- }
63
- return target;
192
+ return Array.isArray(target) ? target.at(-1) : target;
64
193
  };
194
+ /**
195
+ * Get all escrow contracts across all versions and chains.
196
+ * Returns a flat list of all escrow locations for querying deposits.
197
+ *
198
+ * @returns Array of escrow locations with version, chainId, and escrow address
199
+ *
200
+ * @example
201
+ * // Get all escrows to search for a deposit
202
+ * const escrows = getAllEscrowContracts()
203
+ * // [
204
+ * // { version: 'v2', chainId: 8453, escrow: '0xCA38...' },
205
+ * // { version: 'v2', chainId: 369, escrow: '0x2932...' },
206
+ * // { version: 'v3', chainId: 8453, escrow: '0x2f12...' },
207
+ * // ]
208
+ */
209
+ export function getAllEscrowContracts() {
210
+ const escrows = [];
211
+ for (const [version, chainContracts] of Object.entries(contracts)) {
212
+ for (const [chainIdStr, c] of Object.entries(chainContracts)) {
213
+ const chainId = Number(chainIdStr);
214
+ const contractsForChain = c;
215
+ if (contractsForChain.escrow) {
216
+ for (const escrow of contractsForChain.escrow) {
217
+ escrows.push({
218
+ version: version,
219
+ chainId,
220
+ escrow,
221
+ });
222
+ }
223
+ }
224
+ }
225
+ }
226
+ return escrows;
227
+ }
228
+ /**
229
+ * Get all V3 escrow contracts across all chains.
230
+ * Used for cross-chain nullifier checking to prevent double-spending.
231
+ *
232
+ * @returns Array of V3 escrow locations with chainId and escrow address
233
+ *
234
+ * @example
235
+ * const v3Escrows = getAllV3EscrowContracts()
236
+ * // [
237
+ * // { version: 'v3', chainId: 8453, escrow: '0x2f12...' },
238
+ * // { version: 'v3', chainId: 369, escrow: '0x0B42...' },
239
+ * // ]
240
+ */
241
+ export function getAllV3EscrowContracts() {
242
+ return getAllEscrowContracts().filter((loc) => loc.version === 'v3');
243
+ }
244
+ /**
245
+ * Get a short display label for an escrow address (first 6 + last 4 chars)
246
+ * @param escrow - The escrow address
247
+ * @returns Shortened address string
248
+ */
249
+ export function shortenEscrowAddress(escrow) {
250
+ return `${escrow.slice(0, 6)}...${escrow.slice(-4)}`;
251
+ }
252
+ /**
253
+ * Get the version of an escrow contract by looking up its address.
254
+ *
255
+ * @param escrowAddress - The escrow contract address to look up
256
+ * @param chainId - Optional chain ID to narrow down the search
257
+ * @returns The escrow version ('v2' or 'v3'), or null if not found
258
+ *
259
+ * @example
260
+ * // Determine if escrow supports V3 features
261
+ * const version = getEscrowVersion(deposit.escrow, deposit.chainId)
262
+ * const isV3 = version === 'v3'
263
+ */
264
+ export function getEscrowVersion(escrowAddress, chainId) {
265
+ const normalizedAddress = escrowAddress.toLowerCase();
266
+ const allEscrows = getAllEscrowContracts();
267
+ for (const location of allEscrows) {
268
+ // If chainId is provided, skip non-matching chains
269
+ if (chainId !== undefined && location.chainId !== chainId) {
270
+ continue;
271
+ }
272
+ if (location.escrow.toLowerCase() === normalizedAddress) {
273
+ return location.version;
274
+ }
275
+ }
276
+ return null;
277
+ }
278
+ /**
279
+ * Check if an escrow address is a V3 contract.
280
+ * Convenience function for feature gating V3-only functionality.
281
+ *
282
+ * @param escrowAddress - The escrow contract address
283
+ * @param chainId - The chain ID
284
+ * @returns true if the escrow is V3, false otherwise
285
+ *
286
+ * @example
287
+ * // Gate V3-only features in UI
288
+ * const showRetainToggle = isV3Escrow(deposit.escrow, deposit.chainId) && isOwner
289
+ */
290
+ export function isV3Escrow(escrowAddress, chainId) {
291
+ return getEscrowVersion(escrowAddress, chainId) === 'v3';
292
+ }
@@ -0,0 +1 @@
1
+ export {};