@provex/utils 1.0.16
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 +287 -0
- package/dist/scripts/convert-svg.d.ts +1 -0
- package/dist/scripts/convert-svg.js +17 -0
- package/dist/src/chain.d.ts +14 -0
- package/dist/src/chain.js +18 -0
- package/dist/src/contracts.d.ts +30 -0
- package/dist/src/contracts.js +64 -0
- package/dist/src/conversionRates.d.ts +124 -0
- package/dist/src/conversionRates.js +219 -0
- package/dist/src/currencies.d.ts +144 -0
- package/dist/src/currencies.js +234 -0
- package/dist/src/data/countries.json +1099 -0
- package/dist/src/deposit.d.ts +1 -0
- package/dist/src/deposit.js +1 -0
- package/dist/src/events.d.ts +3 -0
- package/dist/src/events.js +16 -0
- package/dist/src/flags.d.ts +2 -0
- package/dist/src/flags.js +3 -0
- package/dist/src/ids.d.ts +72 -0
- package/dist/src/ids.js +81 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/index.js +16 -0
- package/dist/src/input.d.ts +7 -0
- package/dist/src/input.js +35 -0
- package/dist/src/intent.d.ts +14 -0
- package/dist/src/intent.js +1 -0
- package/dist/src/json.d.ts +18 -0
- package/dist/src/json.js +44 -0
- package/dist/src/participants.d.ts +7 -0
- package/dist/src/participants.js +13 -0
- package/dist/src/payment.d.ts +164 -0
- package/dist/src/payment.js +439 -0
- package/dist/src/profit.d.ts +28 -0
- package/dist/src/profit.js +34 -0
- package/dist/src/sort.d.ts +36 -0
- package/dist/src/sort.js +39 -0
- package/dist/src/stats.d.ts +7 -0
- package/dist/src/stats.js +8 -0
- package/dist/src/time.d.ts +54 -0
- package/dist/src/time.js +106 -0
- package/dist/src/tokens.d.ts +3675 -0
- package/dist/src/tokens.js +134 -0
- package/dist/src/units.d.ts +17 -0
- package/dist/src/units.js +79 -0
- package/dist/src/zkp2p-types.d.ts +48 -0
- package/dist/src/zkp2p-types.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +45 -0
- package/scripts/convert-svg.ts +22 -0
- package/src/chain.ts +27 -0
- package/src/contracts.ts +89 -0
- package/src/conversionRates.ts +356 -0
- package/src/currencies.ts +286 -0
- package/src/data/countries.json +1099 -0
- package/src/deposit.ts +2 -0
- package/src/events.ts +21 -0
- package/src/flags/eur.svg +4 -0
- package/src/flags/usd.svg +25 -0
- package/src/flags.ts +4 -0
- package/src/global.d.ts +9 -0
- package/src/ids.ts +137 -0
- package/src/index.ts +16 -0
- package/src/input.ts +35 -0
- package/src/intent.ts +15 -0
- package/src/json.ts +42 -0
- package/src/participants.ts +14 -0
- package/src/payment.ts +573 -0
- package/src/profit.ts +55 -0
- package/src/sort.ts +49 -0
- package/src/stats.ts +10 -0
- package/src/time.ts +123 -0
- package/src/tokens.ts +159 -0
- package/src/units.ts +120 -0
- package/src/zkp2p-types.ts +55 -0
- package/tsconfig.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# @provex/utils
|
|
2
|
+
|
|
3
|
+
Shared utility functions, types, and constants for the provex ecosystem. This package provides core business logic for currency operations, payment processing, token management, and blockchain interactions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @provex/utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
The utils package is the foundation of the provex system, providing:
|
|
14
|
+
|
|
15
|
+
- **Currency Management** - Support for multiple fiat currencies with automatic contract ID generation
|
|
16
|
+
- **Payment Provider Integration** - Configuration and utilities for various payment platforms
|
|
17
|
+
- **Token Management** - Blockchain token utilities and amount calculations
|
|
18
|
+
- **Conversion Rate Handling** - Exchange rate processing and currency conversions
|
|
19
|
+
- **Time & Formatting Utilities** - Date/time formatting and number display utilities
|
|
20
|
+
- **Smart Contract Integration** - Contract addresses and blockchain utilities
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Currency Operations
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import {
|
|
28
|
+
getCurrencyInfo,
|
|
29
|
+
Currency,
|
|
30
|
+
formatCurrencyAmount,
|
|
31
|
+
SUPPORTED_CURRENCIES
|
|
32
|
+
} from '@provex/utils/currencies'
|
|
33
|
+
|
|
34
|
+
// Get currency information
|
|
35
|
+
const usdInfo = getCurrencyInfo('USD')
|
|
36
|
+
console.log(usdInfo.symbol) // '$'
|
|
37
|
+
console.log(usdInfo.decimals) // 2
|
|
38
|
+
|
|
39
|
+
// Create new currency
|
|
40
|
+
const customCurrency = new Currency('GBP', '£', 'British Pound', 2)
|
|
41
|
+
|
|
42
|
+
// Format currency amounts
|
|
43
|
+
const formatted = formatCurrencyAmount(1234.56, 'USD') // '$1,234.56'
|
|
44
|
+
|
|
45
|
+
// Check supported currencies
|
|
46
|
+
console.log(Object.keys(SUPPORTED_CURRENCIES)) // ['USD', 'EUR', 'GBP', ...]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Payment Provider Configuration
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import {
|
|
53
|
+
providers,
|
|
54
|
+
subProviders,
|
|
55
|
+
providerKeyToValidationKey
|
|
56
|
+
} from '@provex/utils/payment'
|
|
57
|
+
|
|
58
|
+
// Available providers
|
|
59
|
+
console.log(providers.VENMO) // 'venmo'
|
|
60
|
+
console.log(providers.ZELLE) // 'zelle'
|
|
61
|
+
|
|
62
|
+
// Sub-providers (for Zelle banking partners)
|
|
63
|
+
console.log(subProviders.CHASE) // 'chase'
|
|
64
|
+
|
|
65
|
+
// Validation keys for each provider
|
|
66
|
+
console.log(providerKeyToValidationKey.venmo) // 'venmoUsername'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Token Management
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import {
|
|
73
|
+
allTokensInfo,
|
|
74
|
+
tokenByAddress,
|
|
75
|
+
} from '@provex/utils/tokens'
|
|
76
|
+
|
|
77
|
+
// Get token info
|
|
78
|
+
const usdc = allTokensInfo.BASE.USDC
|
|
79
|
+
console.log(usdc.decimals) // 6
|
|
80
|
+
|
|
81
|
+
// Find token by address
|
|
82
|
+
const token = tokenByAddress('0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913')
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Conversion Rate Processing
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import {
|
|
89
|
+
processConversionRates,
|
|
90
|
+
convertTokenInputToCurrency,
|
|
91
|
+
convertCurrencyToTokenOutput,
|
|
92
|
+
getPrimaryConversionRate
|
|
93
|
+
} from '@provex/utils/conversionRates'
|
|
94
|
+
|
|
95
|
+
// Process conversion rate events
|
|
96
|
+
const providerRates = processConversionRates({
|
|
97
|
+
events: conversionRateEvents,
|
|
98
|
+
sortOrder: 'desc'
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
// Convert token amount to currency
|
|
102
|
+
const currencyAmount = convertTokenInputToCurrency({
|
|
103
|
+
token: { decimals: 6 },
|
|
104
|
+
amountOutInt: parseUnits('100', 6), // 100 USDC
|
|
105
|
+
rate: parseUnits('1', 18) // 1:1 rate
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
// Convert currency to token output
|
|
109
|
+
const tokenAmount = convertCurrencyToTokenOutput({
|
|
110
|
+
token: { decimals: 6 },
|
|
111
|
+
currencyAmountInt: parseUnits('100', 2), // $100
|
|
112
|
+
rate: parseUnits('1', 18)
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Time and Formatting Utilities
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import {
|
|
120
|
+
formatTimestamp,
|
|
121
|
+
formatDuration,
|
|
122
|
+
interval,
|
|
123
|
+
sleep
|
|
124
|
+
} from '@provex/utils/time'
|
|
125
|
+
import {
|
|
126
|
+
formatUnits,
|
|
127
|
+
addThousandsSeparator,
|
|
128
|
+
parseUnits
|
|
129
|
+
} from '@provex/utils/units'
|
|
130
|
+
|
|
131
|
+
// Format timestamps
|
|
132
|
+
const timeAgo = formatTimestamp(Date.now() - interval.hour) // '1h ago'
|
|
133
|
+
|
|
134
|
+
// Format durations
|
|
135
|
+
const duration = formatDuration({
|
|
136
|
+
from: new Date('2023-01-01'),
|
|
137
|
+
to: new Date('2023-01-02')
|
|
138
|
+
}) // '1 day'
|
|
139
|
+
|
|
140
|
+
// Format numbers with separators
|
|
141
|
+
const formatted = addThousandsSeparator('1234567') // '1,234,567'
|
|
142
|
+
|
|
143
|
+
// Format token amounts
|
|
144
|
+
const displayAmount = formatUnits(parseUnits('1234.56', 6), {
|
|
145
|
+
decimals: 6,
|
|
146
|
+
truncateDecimals: 2
|
|
147
|
+
}) // '1,234.56'
|
|
148
|
+
|
|
149
|
+
// Sleep utility
|
|
150
|
+
await sleep(1000) // Wait 1 second
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Smart Contract Integration
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { contracts } from '@provex/utils/contracts'
|
|
157
|
+
|
|
158
|
+
// Contract addresses
|
|
159
|
+
console.log(contracts.usdc) // USDC token contract
|
|
160
|
+
console.log(contracts.escrow) // Main escrow contract
|
|
161
|
+
console.log(contracts.venmoReclaimVerifier) // Venmo proof verifier
|
|
162
|
+
console.log(contracts.zelleBaseVerifier) // Zelle proof verifier
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Intent Management
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import type { IntentStruct } from '@provex/utils/intent'
|
|
169
|
+
|
|
170
|
+
const intent: IntentStruct = {
|
|
171
|
+
owner: '0x...', // Intent creator
|
|
172
|
+
to: '0x...', // Payment recipient
|
|
173
|
+
depositId: 123n, // Associated deposit
|
|
174
|
+
amount: parseUnits('100', 6), // Payment amount
|
|
175
|
+
timestamp: BigInt(Date.now() / 1000), // Creation time
|
|
176
|
+
paymentVerifier: '0x...', // Verifier contract
|
|
177
|
+
fiatCurrency: '0x...', // Currency identifier
|
|
178
|
+
conversionRate: parseUnits('1', 6) // Exchange rate
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Available Modules
|
|
183
|
+
|
|
184
|
+
### Core Modules
|
|
185
|
+
|
|
186
|
+
| Module | Purpose | Key Functions |
|
|
187
|
+
|--------|---------|---------------|
|
|
188
|
+
| `currencies` | Currency management | `getCurrencyInfo`, `formatCurrencyAmount`, `Currency` class |
|
|
189
|
+
| `payment` | Provider configuration | Provider constants, validation utilities |
|
|
190
|
+
| `tokens` | Token operations | `tokenByAddress`, amount comparisons |
|
|
191
|
+
| `conversionRates` | Rate processing | `processConversionRates`, conversion utilities |
|
|
192
|
+
| `time` | Time formatting | `formatTimestamp`, `formatDuration`, `sleep` |
|
|
193
|
+
| `units` | Number formatting | `formatUnits`, `addThousandsSeparator` |
|
|
194
|
+
| `contracts` | Smart contracts | Contract address constants |
|
|
195
|
+
| `intent` | Intent structures | TypeScript interfaces |
|
|
196
|
+
|
|
197
|
+
### Utility Modules
|
|
198
|
+
|
|
199
|
+
| Module | Purpose | Key Functions |
|
|
200
|
+
|--------|---------|---------------|
|
|
201
|
+
| `sort` | Sorting utilities | `orderedSort`, `orderedSortThenById` |
|
|
202
|
+
| `profit` | Profit calculations | `calculateProfit`, `calculateProfits` |
|
|
203
|
+
| `participants` | User identification | `generateParticipantId` |
|
|
204
|
+
| `input` | Input processing | `adjustLowestDecimal` |
|
|
205
|
+
| `json` | JSON handling | `jsonSerializer`, `mapBigIntFields` |
|
|
206
|
+
| `chain` | Blockchain utilities | `getExplorerUrl`, chain configurations |
|
|
207
|
+
|
|
208
|
+
## Supported Currencies
|
|
209
|
+
|
|
210
|
+
The package supports the following fiat currencies:
|
|
211
|
+
|
|
212
|
+
- **USD** (US Dollar) - $
|
|
213
|
+
- **EUR** (Euro) - €
|
|
214
|
+
- **GBP** (British Pound) - £
|
|
215
|
+
- **CAD** (Canadian Dollar) - C$
|
|
216
|
+
- **AUD** (Australian Dollar) - A$
|
|
217
|
+
- **JPY** (Japanese Yen) - ¥
|
|
218
|
+
- **CHF** (Swiss Franc) - Fr
|
|
219
|
+
- **CNY** (Chinese Yuan) - ¥
|
|
220
|
+
- **INR** (Indian Rupee) - ₹
|
|
221
|
+
- **BRL** (Brazilian Real) - R$
|
|
222
|
+
- **MXN** (Mexican Peso) - $
|
|
223
|
+
- **ARS** (Argentine Peso) - $
|
|
224
|
+
|
|
225
|
+
## Supported Payment Providers
|
|
226
|
+
|
|
227
|
+
- **Venmo** (`venmo`)
|
|
228
|
+
- **Zelle** (`zelle`) with sub-providers:
|
|
229
|
+
- Chase (`chase`)
|
|
230
|
+
- Bank of America (`bank_of_america`)
|
|
231
|
+
- Citi (`citi`)
|
|
232
|
+
- **CashApp** (`cashapp`)
|
|
233
|
+
- **Revolut** (`revolut`)
|
|
234
|
+
- **Wise** (`wise`)
|
|
235
|
+
- **MercadoPago** (`mercadopago`)
|
|
236
|
+
- **Manual** (`manual`)
|
|
237
|
+
|
|
238
|
+
## Smart Contract Addresses
|
|
239
|
+
|
|
240
|
+
The package includes contract addresses for:
|
|
241
|
+
|
|
242
|
+
- **Token Contracts**: USDC
|
|
243
|
+
- **Core Contracts**: Escrow, Relay Bridge
|
|
244
|
+
- **Verifier Contracts**: Individual verifiers for each payment provider
|
|
245
|
+
- **Service Contracts**: Gating service, witness signers
|
|
246
|
+
|
|
247
|
+
## TypeScript Support
|
|
248
|
+
|
|
249
|
+
All modules are fully typed with TypeScript interfaces and types exported for use in your applications:
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
import type {
|
|
253
|
+
CurrencyInfo,
|
|
254
|
+
TokenInfo,
|
|
255
|
+
IntentStruct,
|
|
256
|
+
ConversionRateInfo,
|
|
257
|
+
ProviderKey,
|
|
258
|
+
SortDirection
|
|
259
|
+
} from '@provex/utils'
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Build System
|
|
263
|
+
|
|
264
|
+
The package uses TypeScript compilation and ES modules:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
npm run build # Compile TypeScript to JavaScript
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Dependencies
|
|
271
|
+
|
|
272
|
+
- **viem** - Ethereum utilities for address handling and encoding
|
|
273
|
+
- Built-in JSON data for country and currency information
|
|
274
|
+
|
|
275
|
+
## Contributing
|
|
276
|
+
|
|
277
|
+
When adding new utilities:
|
|
278
|
+
|
|
279
|
+
1. Create focused modules for specific functionality
|
|
280
|
+
2. Export functions through the main index file
|
|
281
|
+
3. Include TypeScript types and interfaces
|
|
282
|
+
4. Follow the existing naming conventions
|
|
283
|
+
5. Add comprehensive JSDoc comments
|
|
284
|
+
|
|
285
|
+
## License
|
|
286
|
+
|
|
287
|
+
ISC License
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
const __dirname = import.meta.dirname;
|
|
4
|
+
// Read SVG files and convert to TypeScript constants
|
|
5
|
+
const svgDir = path.join(__dirname, '../src/flags');
|
|
6
|
+
const outputFile = path.join(__dirname, '../src/flags.ts');
|
|
7
|
+
const svgFiles = ['usd.svg', 'eur.svg'];
|
|
8
|
+
let output = '// Auto-generated from SVG files\n\n';
|
|
9
|
+
svgFiles.forEach(filename => {
|
|
10
|
+
const svgPath = path.join(svgDir, filename);
|
|
11
|
+
const svgContent = fs.readFileSync(svgPath, 'utf8');
|
|
12
|
+
const cleanSvg = svgContent.replace(/[\r\n]/g, ' ').replace(/\s+/g, ' ').trim();
|
|
13
|
+
const constName = filename.replace('.svg', '').toUpperCase() + '_FLAG_SVG';
|
|
14
|
+
output += `export const ${constName} = '${cleanSvg}';\n`;
|
|
15
|
+
});
|
|
16
|
+
fs.writeFileSync(outputFile, output);
|
|
17
|
+
console.log('Generated flags.ts from SVG files');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Chain } from 'viem/chains';
|
|
2
|
+
export declare const chains: [Chain, ...Chain[]];
|
|
3
|
+
export declare const chainIds: number[];
|
|
4
|
+
export type ChainId = (typeof chainIds)[number];
|
|
5
|
+
/**
|
|
6
|
+
* Get the explorer URL for a given chain, type, and hash
|
|
7
|
+
* @param chain - The chain to get the explorer URL for
|
|
8
|
+
* @param type - The type of explorer to use (tx or address)
|
|
9
|
+
* @param hash - The hash to get the explorer URL for
|
|
10
|
+
* @returns The explorer URL
|
|
11
|
+
*/
|
|
12
|
+
export declare function getExplorerUrl(chain: Chain, type: 'tx' | 'address', hash: string): string;
|
|
13
|
+
export declare const chainIdToChain: Map<number, Chain>;
|
|
14
|
+
export declare const chainIdToTargetBlockTime: Map<number, number>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { base, pulsechain } from 'viem/chains';
|
|
2
|
+
export const chains = [pulsechain, base];
|
|
3
|
+
export const chainIds = chains.map((chain) => chain.id);
|
|
4
|
+
/**
|
|
5
|
+
* Get the explorer URL for a given chain, type, and hash
|
|
6
|
+
* @param chain - The chain to get the explorer URL for
|
|
7
|
+
* @param type - The type of explorer to use (tx or address)
|
|
8
|
+
* @param hash - The hash to get the explorer URL for
|
|
9
|
+
* @returns The explorer URL
|
|
10
|
+
*/
|
|
11
|
+
export function getExplorerUrl(chain, type, hash) {
|
|
12
|
+
return `${chain.blockExplorers?.default.url}/${type}/${hash}`;
|
|
13
|
+
}
|
|
14
|
+
export const chainIdToChain = new Map(chains.map((chain) => [chain.id, chain]));
|
|
15
|
+
export const chainIdToTargetBlockTime = new Map([
|
|
16
|
+
[369, 10_000],
|
|
17
|
+
[8453, 2_000],
|
|
18
|
+
]);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Hex } from 'viem';
|
|
2
|
+
import type { ChainId } from './chain.js';
|
|
3
|
+
/**
|
|
4
|
+
* Contracts for the app
|
|
5
|
+
*/
|
|
6
|
+
export type Contracts = {
|
|
7
|
+
gatingService: Hex;
|
|
8
|
+
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[];
|
|
21
|
+
};
|
|
22
|
+
export declare const reclaimSigners: {
|
|
23
|
+
readonly zkp2pWitnessSigner: "0x0636c417755E3ae25C6c166D181c0607F4C572A3";
|
|
24
|
+
readonly reclaimWitnessSigner: "0x244897572368eadf65bfbc5aec98d8e5443a9072";
|
|
25
|
+
};
|
|
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;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getAddress } from 'viem';
|
|
2
|
+
import { base, pulsechain } from 'viem/chains';
|
|
3
|
+
export const reclaimSigners = {
|
|
4
|
+
zkp2pWitnessSigner: '0x0636c417755E3ae25C6c166D181c0607F4C572A3',
|
|
5
|
+
reclaimWitnessSigner: '0x244897572368eadf65bfbc5aec98d8e5443a9072',
|
|
6
|
+
};
|
|
7
|
+
export const baseContracts = {
|
|
8
|
+
gatingService: getAddress('0x396D31055Db28C0C6f36e8b36f18FE7227248a97'),
|
|
9
|
+
usdc: getAddress('0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'),
|
|
10
|
+
escrow: [getAddress('0xCA38607D85E8F6294Dc10728669605E6664C2D70')],
|
|
11
|
+
venmoReclaimVerifier: [getAddress('0x9a733B55a875D0DB4915c6B36350b24F8AB99dF5')],
|
|
12
|
+
revolutReclaimVerifier: [getAddress('0xAA5A1B62B01781E789C900d616300717CD9A41aB')],
|
|
13
|
+
cashappReclaimVerifier: [getAddress('0x76D33A33068D86016B806dF02376dDBb23Dd3703')],
|
|
14
|
+
wiseReclaimVerifier: [getAddress('0xFF0149799631D7A5bdE2e7eA9b306c42b3d9a9ca')],
|
|
15
|
+
mercadopagoReclaimVerifier: [
|
|
16
|
+
// getAddress('0x00d003c73eab8feaec04bab976235915fe7641e3'),
|
|
17
|
+
getAddress('0xf2AC5be14F32Cbe6A613CFF8931d95460D6c33A3'),
|
|
18
|
+
],
|
|
19
|
+
zelleBaseVerifier: [
|
|
20
|
+
// getAddress('0x1783f040783c0827fb64d128ece548d9b3613ad5'),
|
|
21
|
+
getAddress('0x431a078A5029146aAB239c768A615CD484519aF7'),
|
|
22
|
+
],
|
|
23
|
+
zelleChaseReclaimVerifier: [getAddress('0xBcD7C6BBcA5869fBefe3E322263EE1090221D7A9')],
|
|
24
|
+
zelleBoAReclaimVerifier: [getAddress('0x809c7A20A2dbBB3210fC73Dd7C01Cd7Fa70C195F')],
|
|
25
|
+
zelleCitiReclaimVerifier: [getAddress('0x3128badc46dbe2e37bdd2d64f33fb3b3a639570e')],
|
|
26
|
+
paypalReclaimVerifier: [getAddress('0x03d17E9371C858072E171276979f6B44571C5DeA')],
|
|
27
|
+
monzoReclaimVerifier: [getAddress('0x0dE46433bD251027f73eD8f28E01eF05DA36a2E0')],
|
|
28
|
+
};
|
|
29
|
+
export const pulsechainContracts = {
|
|
30
|
+
gatingService: getAddress('0x4Bd6364FCC4D8A537aBfee33B16E959794fDf9Cf'),
|
|
31
|
+
usdc: getAddress('0x15D38573d2feeb82e7ad5187aB8c1D52810B1f07'),
|
|
32
|
+
escrow: [getAddress('0x2932E08BFD212Ef0732257bDd6463BF55E9b97d7')],
|
|
33
|
+
cashappReclaimVerifier: [getAddress('0x9224433D6AD9a5A774ca74Ca33c01747FA710A9d')],
|
|
34
|
+
mercadopagoReclaimVerifier: [getAddress('0xc4D0cf4DF12e329f9c951d1D9BB815da6138850A')],
|
|
35
|
+
monzoReclaimVerifier: [getAddress('0xBde2c79c1897459e66C0fdF6764EED0c6839C878')],
|
|
36
|
+
nullifierRegistry: [getAddress('0x471D3c6C9E32CE2556d0117aC161Aa82AEac17d8')],
|
|
37
|
+
paypalReclaimVerifier: [getAddress('0x1DdBfd39a141C5A2329d849CADa6a83404E0Ce4F')],
|
|
38
|
+
revolutReclaimVerifier: [getAddress('0x8234AA463C8B94778f58eA0bFEfcBAC3683341A9')],
|
|
39
|
+
venmoReclaimVerifier: [getAddress('0x0Dd524dA03f610480aF3F433B411b6016cFBDeab')],
|
|
40
|
+
wiseReclaimVerifier: [getAddress('0x7B72d7CfAfDfD397E2460c933e84D16dc121845a')],
|
|
41
|
+
zelleBaseVerifier: [getAddress('0x539566771f9c38c6038aafc1946bf11af9cdb201')],
|
|
42
|
+
zelleBoAReclaimVerifier: [getAddress('0x506a746b8228F9f9d4522105b973Dc7223A64EAC')],
|
|
43
|
+
zelleChaseReclaimVerifier: [getAddress('0xB0aA0a58959465bBCf0eCbD62A84B743A5435c99')],
|
|
44
|
+
zelleCitiReclaimVerifier: [getAddress('0x5624E479924eBFb25B51F36e3FDaE605dADb448b')],
|
|
45
|
+
};
|
|
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;
|
|
52
|
+
};
|
|
53
|
+
export const getLatestContract = (chainId, key) => {
|
|
54
|
+
const contracts = getContracts(chainId);
|
|
55
|
+
if (!contracts)
|
|
56
|
+
return null;
|
|
57
|
+
const target = contracts[key];
|
|
58
|
+
if (!target)
|
|
59
|
+
return null;
|
|
60
|
+
if (Array.isArray(target)) {
|
|
61
|
+
return target[target.length - 1] ?? null;
|
|
62
|
+
}
|
|
63
|
+
return target;
|
|
64
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Hex } from 'viem';
|
|
2
|
+
import { Currency } from './currencies.js';
|
|
3
|
+
import { type ProviderKey } from './payment.js';
|
|
4
|
+
import type { SortDirection } from './sort.js';
|
|
5
|
+
import type { TokenInfo } from './tokens.js';
|
|
6
|
+
import type { ChainId } from './chain.js';
|
|
7
|
+
/**
|
|
8
|
+
* Conversion rate info
|
|
9
|
+
*/
|
|
10
|
+
export interface ConversionRateInfo {
|
|
11
|
+
depositConversionRateUpdatedId: string;
|
|
12
|
+
currency: string;
|
|
13
|
+
verifier: string;
|
|
14
|
+
value: string;
|
|
15
|
+
orderId: string;
|
|
16
|
+
depositId: string;
|
|
17
|
+
transaction: {
|
|
18
|
+
hash: string;
|
|
19
|
+
block: {
|
|
20
|
+
timestamp: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Conversion rate info with current deposit conversion rate updated
|
|
26
|
+
*/
|
|
27
|
+
export interface ConversionRateInfoWithCurrent extends ConversionRateInfo {
|
|
28
|
+
currentDepositConversionRateUpdatedId: string;
|
|
29
|
+
currentDepositConversionRateUpdated: {
|
|
30
|
+
value: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Provider rates
|
|
35
|
+
*/
|
|
36
|
+
export type ProviderRates<RateInfo> = Map<ProviderKey, Map<Hex, RateInfo>>;
|
|
37
|
+
/**
|
|
38
|
+
* Process conversion rates options
|
|
39
|
+
*/
|
|
40
|
+
interface ProcessConversionRatesOptions {
|
|
41
|
+
chainId: ChainId;
|
|
42
|
+
events: ConversionRateInfoWithCurrent[];
|
|
43
|
+
sortOrder?: SortDirection;
|
|
44
|
+
includeHistorical?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get conversion rate options
|
|
48
|
+
*/
|
|
49
|
+
interface GetConversionRateOptions {
|
|
50
|
+
events: ConversionRateInfoWithCurrent[];
|
|
51
|
+
currency: Hex;
|
|
52
|
+
verifier: string;
|
|
53
|
+
chainId: ChainId;
|
|
54
|
+
includeHistory?: boolean;
|
|
55
|
+
fallbackRate?: {
|
|
56
|
+
currency: string;
|
|
57
|
+
value: string;
|
|
58
|
+
verifier: string;
|
|
59
|
+
} | null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Extract currencies options
|
|
63
|
+
*/
|
|
64
|
+
interface ExtractCurrenciesOptions {
|
|
65
|
+
providerRates: ProviderRates<ConversionRateInfo[]>;
|
|
66
|
+
providersOnly?: ProviderKey[];
|
|
67
|
+
currenciesOnly?: string[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Process deposit currency added events into organized conversion rates
|
|
71
|
+
*/
|
|
72
|
+
export declare function processConversionRates(options: ProcessConversionRatesOptions): ProviderRates<ConversionRateInfo[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Get conversion rate for a specific currency and verifier combination
|
|
75
|
+
*/
|
|
76
|
+
export declare function getConversionRate(options: GetConversionRateOptions): ConversionRateInfo | ConversionRateInfo[] | null;
|
|
77
|
+
/**
|
|
78
|
+
* Extract unique currencies from processed provider rates
|
|
79
|
+
*/
|
|
80
|
+
export declare function extractCurrencies(options: ExtractCurrenciesOptions): string[];
|
|
81
|
+
/**
|
|
82
|
+
* Get the latest conversion rate across all providers for a currency
|
|
83
|
+
*/
|
|
84
|
+
export declare function getLatestRateForCurrency(options: {
|
|
85
|
+
providerRates: ProviderRates<ConversionRateInfo>;
|
|
86
|
+
currency: Hex;
|
|
87
|
+
preferredProvider?: ProviderKey;
|
|
88
|
+
}): ConversionRateInfo | null;
|
|
89
|
+
/**
|
|
90
|
+
* Get the primary conversion rate from processed provider rates
|
|
91
|
+
* Returns the first available rate, prioritizing by provider order
|
|
92
|
+
*/
|
|
93
|
+
export declare function getPrimaryConversionRate(providerRates: ProviderRates<ConversionRateInfo>): ConversionRateInfo | null;
|
|
94
|
+
/**
|
|
95
|
+
* Get primary conversion rate for a specific currency across all providers
|
|
96
|
+
*/
|
|
97
|
+
export declare function getPrimaryRateForCurrency(providerRates: ProviderRates<ConversionRateInfo>, currency: Hex): ConversionRateInfo | null;
|
|
98
|
+
/**
|
|
99
|
+
* Get the primary verifier (payment provider) from conversion rates
|
|
100
|
+
*/
|
|
101
|
+
export declare function getPrimaryVerifier(providerRates: ProviderRates<ConversionRateInfo>): string | null;
|
|
102
|
+
/**
|
|
103
|
+
* Get the primary currency from conversion rates
|
|
104
|
+
*/
|
|
105
|
+
export declare function getPrimaryCurrency(providerRates: ProviderRates<ConversionRateInfo>): string | null;
|
|
106
|
+
/**
|
|
107
|
+
* Convert token input to currency
|
|
108
|
+
*/
|
|
109
|
+
export declare const convertTokenInputToCurrency: ({ token, amountOutInt, rate }: {
|
|
110
|
+
token: TokenInfo;
|
|
111
|
+
amountOutInt: bigint;
|
|
112
|
+
rate: bigint;
|
|
113
|
+
}) => bigint;
|
|
114
|
+
/**
|
|
115
|
+
* Convert currency amount to token amount out (inverse of convertTokenInputToCurrency)
|
|
116
|
+
* This accounts for the cent-rounding applied in the original function
|
|
117
|
+
*/
|
|
118
|
+
export declare const convertCurrencyToTokenOutput: ({ token, currency, currencyAmountInt, rate, }: {
|
|
119
|
+
token: TokenInfo;
|
|
120
|
+
currency: Currency;
|
|
121
|
+
currencyAmountInt: bigint;
|
|
122
|
+
rate: bigint;
|
|
123
|
+
}) => bigint;
|
|
124
|
+
export {};
|