@zkp2p/sdk 0.0.15 → 0.1.0-rc.2
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 +122 -574
- package/dist/chunk-2SCPG3VZ.mjs +408 -0
- package/dist/chunk-2SCPG3VZ.mjs.map +1 -0
- package/dist/chunk-456CSWDT.mjs +112 -0
- package/dist/chunk-456CSWDT.mjs.map +1 -0
- package/dist/chunk-5P4AUJOP.mjs +489 -0
- package/dist/chunk-5P4AUJOP.mjs.map +1 -0
- package/dist/chunk-PQQWQF3C.mjs +375 -0
- package/dist/chunk-PQQWQF3C.mjs.map +1 -0
- package/dist/{chunk-RNJWFEXN.mjs → chunk-Z7ZE2T2D.mjs} +6 -3
- package/dist/chunk-Z7ZE2T2D.mjs.map +1 -0
- package/dist/constants-DSAL6TGM.mjs +5 -0
- package/dist/{constants-JKQSE4SG.mjs.map → constants-DSAL6TGM.mjs.map} +1 -1
- package/dist/{currency-P4HY7S34.mjs → currency-5RZ6VCEA.mjs} +3 -3
- package/dist/{currency-P4HY7S34.mjs.map → currency-5RZ6VCEA.mjs.map} +1 -1
- package/dist/index.cjs +4441 -368
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +138 -5
- package/dist/index.d.ts +138 -5
- package/dist/index.mjs +3631 -417
- package/dist/index.mjs.map +1 -1
- package/dist/{paymentResolution-2MMBIGI5.mjs → paymentResolution-TLSKPZ4W.mjs} +3 -3
- package/dist/{paymentResolution-2MMBIGI5.mjs.map → paymentResolution-TLSKPZ4W.mjs.map} +1 -1
- package/dist/protocolViewerParsers-EZURPKHP.mjs +6 -0
- package/dist/{protocolViewerParsers-QSUXBGWT.mjs.map → protocolViewerParsers-EZURPKHP.mjs.map} +1 -1
- package/dist/react.cjs +830 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.mts +124 -3
- package/dist/react.d.ts +124 -3
- package/dist/react.mjs +707 -2
- package/dist/react.mjs.map +1 -1
- package/dist/{Zkp2pClient-ccA0cKOA.d.mts → vaultUtils-Uzpp9N7r.d.mts} +865 -48
- package/dist/{Zkp2pClient-ccA0cKOA.d.ts → vaultUtils-Uzpp9N7r.d.ts} +865 -48
- package/package.json +16 -16
- package/dist/chunk-MDLTLKWK.mjs +0 -126
- package/dist/chunk-MDLTLKWK.mjs.map +0 -1
- package/dist/chunk-MMPINPEZ.mjs +0 -209
- package/dist/chunk-MMPINPEZ.mjs.map +0 -1
- package/dist/chunk-RFTOKPSA.mjs +0 -186
- package/dist/chunk-RFTOKPSA.mjs.map +0 -1
- package/dist/chunk-RNJWFEXN.mjs.map +0 -1
- package/dist/constants-JKQSE4SG.mjs +0 -5
- package/dist/protocolViewerParsers-QSUXBGWT.mjs +0 -6
package/README.md
CHANGED
|
@@ -2,129 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@zkp2p/sdk)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
|
-
[](https://www.typescriptlang.org/)
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
TypeScript SDK for ZKP2P liquidity providers and integrators.
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
The staging protocol-upgrade surfaces are included in this package line (`0.0.x`): V1/V2 contract routing, vault/delegated rate-management (DRM) operations, oracle/spread configuration, and expanded indexer helpers.
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
## Who This Is For
|
|
12
11
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
12
|
+
- maker/liquidity-provider applications
|
|
13
|
+
- internal client apps (web, extension)
|
|
14
|
+
- tools that need contract-safe deposit/intent operations
|
|
15
|
+
- dashboard/reporting services that query `client.indexer.*`
|
|
17
16
|
|
|
18
|
-
##
|
|
17
|
+
## Core Capabilities
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
| Feature | Description |
|
|
31
|
-
| ------------------- | ---------------------------------------------------------------- |
|
|
32
|
-
| **Create Deposits** | Lock USDC and define accepted payment methods |
|
|
33
|
-
| **Configure Rates** | Set conversion rates per currency and payment platform |
|
|
34
|
-
| **Manage Funds** | Add/remove funds, withdraw deposits |
|
|
35
|
-
| **Payment Methods** | Wise, Venmo, Revolut, CashApp, PayPal, Zelle, Monzo, MercadoPago |
|
|
36
|
-
| **Multi-Currency** | Support USD, EUR, GBP, and 25+ fiat currencies |
|
|
37
|
-
| **Query Deposits** | Real-time on-chain queries via ProtocolViewer |
|
|
38
|
-
| **React Hooks** | Full suite of React hooks for frontend integration |
|
|
39
|
-
|
|
40
|
-
## Supporting Features
|
|
41
|
-
|
|
42
|
-
The SDK also includes supporting functionality for the broader ZKP2P ecosystem:
|
|
43
|
-
|
|
44
|
-
- **Intent Operations**: `signalIntent()`, `fulfillIntent()`, `cancelIntent()` (typically used by takers/buyers)
|
|
45
|
-
- **Quote API**: `getQuote()` (used by frontends to display available liquidity)
|
|
46
|
-
- **Indexer Queries**: Historical data, pagination, and advanced filtering via `client.indexer.*`
|
|
47
|
-
|
|
48
|
-
## Peer Extension SDK
|
|
49
|
-
|
|
50
|
-
If your app integrates with the Peer browser extension, you can use the SDK wrappers around `window.peer`:
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
import { peerExtensionSdk } from '@zkp2p/sdk';
|
|
54
|
-
|
|
55
|
-
const state = await peerExtensionSdk.getState();
|
|
56
|
-
if (state === 'needs_install') {
|
|
57
|
-
peerExtensionSdk.openInstallPage();
|
|
58
|
-
} else if (state === 'needs_connection') {
|
|
59
|
-
await peerExtensionSdk.requestConnection();
|
|
60
|
-
} else {
|
|
61
|
-
const version = await peerExtensionSdk.getVersion();
|
|
62
|
-
peerExtensionSdk.openSidebar('/buy');
|
|
63
|
-
peerExtensionSdk.onramp({
|
|
64
|
-
referrer: 'Polymarket',
|
|
65
|
-
inputCurrency: 'USD',
|
|
66
|
-
inputAmount: 25,
|
|
67
|
-
paymentPlatform: 'venmo',
|
|
68
|
-
amountUsdc: '100000000',
|
|
69
|
-
recipientAddress: '0x1111111111111111111111111111111111111111',
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Intent Hash Deeplink
|
|
75
|
-
|
|
76
|
-
Open the extension directly to a specific intent (skips quote flow):
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
peerExtensionSdk.onramp({
|
|
80
|
-
intentHash: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
81
|
-
});
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Proof Completion Callbacks
|
|
85
|
-
|
|
86
|
-
Subscribe to proof completion events to know when a proof succeeds, fails, or is cancelled:
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
const unsubscribe = peerExtensionSdk.onProofComplete((result) => {
|
|
90
|
-
switch (result.status) {
|
|
91
|
-
case 'success':
|
|
92
|
-
console.log('Proof completed!', result.proof);
|
|
93
|
-
// result.proof: { attestation, signature, timestamp, platform }
|
|
94
|
-
break;
|
|
95
|
-
case 'failure':
|
|
96
|
-
console.error('Proof failed:', result.error);
|
|
97
|
-
// result.error: { code, message }
|
|
98
|
-
break;
|
|
99
|
-
case 'cancelled':
|
|
100
|
-
console.log('User cancelled');
|
|
101
|
-
break;
|
|
102
|
-
case 'timeout':
|
|
103
|
-
console.log('Proof timed out');
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// Clean up when done
|
|
109
|
-
unsubscribe();
|
|
110
|
-
```
|
|
19
|
+
| Area | Highlights |
|
|
20
|
+
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
21
|
+
| Deposit lifecycle | `createDeposit`, `addFunds`, `removeFunds`, `withdrawDeposit` |
|
|
22
|
+
| Intent lifecycle | `signalIntent`, `fulfillIntent`, `cancelIntent`, `releaseFundsToPayer` |
|
|
23
|
+
| Vault/DRM | `createRateManager`, `setRateManager`, `clearRateManager`, `setVaultFee`, `setVaultMinRate`, `setDepositorFloor`, `setVaultConfig` |
|
|
24
|
+
| Oracle config | `setOracleRateConfig`, `setOracleRateConfigBatch` |
|
|
25
|
+
| RPC-first reads | `getDeposits`, `getDeposit`, `getIntents`, `getIntent` |
|
|
26
|
+
| Indexer services | `client.indexer.*`, `IndexerRateManagerService`, `getIntentFulfillmentAmounts` |
|
|
27
|
+
| React hooks | `@zkp2p/sdk/react` hooks for deposit/intent/vault operations |
|
|
111
28
|
|
|
112
29
|
## Installation
|
|
113
30
|
|
|
114
31
|
```bash
|
|
115
32
|
npm install @zkp2p/sdk viem
|
|
116
33
|
# or
|
|
117
|
-
yarn add @zkp2p/sdk viem
|
|
118
|
-
# or
|
|
119
34
|
pnpm add @zkp2p/sdk viem
|
|
35
|
+
# or
|
|
36
|
+
yarn add @zkp2p/sdk viem
|
|
120
37
|
```
|
|
121
38
|
|
|
122
39
|
## Quick Start
|
|
123
40
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
import { OfframpClient } from '@zkp2p/sdk';
|
|
41
|
+
```ts
|
|
42
|
+
import { Zkp2pClient } from '@zkp2p/sdk';
|
|
128
43
|
import { createWalletClient, custom } from 'viem';
|
|
129
44
|
import { base } from 'viem/chains';
|
|
130
45
|
|
|
@@ -133,536 +48,169 @@ const walletClient = createWalletClient({
|
|
|
133
48
|
transport: custom(window.ethereum),
|
|
134
49
|
});
|
|
135
50
|
|
|
136
|
-
const client = new
|
|
51
|
+
const client = new Zkp2pClient({
|
|
137
52
|
walletClient,
|
|
138
53
|
chainId: base.id,
|
|
139
|
-
|
|
140
|
-
|
|
54
|
+
runtimeEnv: 'staging', // 'production' | 'staging'
|
|
55
|
+
apiKey: 'YOUR_CURATOR_API_KEY',
|
|
56
|
+
indexerApiKey: 'YOUR_INDEXER_API_KEY',
|
|
141
57
|
});
|
|
58
|
+
```
|
|
142
59
|
|
|
143
|
-
|
|
144
|
-
const getFreshAuthToken = async () => {
|
|
145
|
-
return await yourAuthProvider.getAccessToken();
|
|
146
|
-
};
|
|
60
|
+
## Routing Defaults
|
|
147
61
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
getAuthorizationToken: getFreshAuthToken, // Bearer token per indexer request
|
|
152
|
-
});
|
|
153
|
-
```
|
|
62
|
+
- SDK methods are capability-based and do not enforce product rollout flags.
|
|
63
|
+
- SDK defaults to V2 routing when V2 contracts are deployed, with legacy fallback when not.
|
|
64
|
+
- Apply phase/rollout gating in app layers above the SDK (web/extension/backend).
|
|
154
65
|
|
|
155
|
-
|
|
66
|
+
## Authentication
|
|
156
67
|
|
|
157
|
-
-
|
|
158
|
-
-
|
|
159
|
-
|
|
160
|
-
- **Indexer API key** — set via `indexerApiKey`. Sent as `x-api-key: <key>`. Separate from the curator `apiKey`.
|
|
161
|
-
- `authorizationToken` is also used by API adapter methods like `getQuote()`, `getTakerTier()`, and API-backed deposit flows.
|
|
162
|
-
- `getAuthorizationToken` is used by indexer requests (`client.indexer.*`) and is called per request.
|
|
163
|
-
- If both bearer and indexer API key are provided, both headers are sent.
|
|
164
|
-
- If `getAuthorizationToken` throws, indexer requests continue without an `Authorization` header.
|
|
165
|
-
- Authenticated requests may receive different limits or entitlements depending on backend policy.
|
|
68
|
+
- `apiKey` is used for curator API endpoints (for example quote/deposit helper endpoints).
|
|
69
|
+
- `authorizationToken` and `getAuthorizationToken` support bearer auth.
|
|
70
|
+
- `indexerApiKey` adds `x-api-key` for indexer proxy auth.
|
|
166
71
|
|
|
167
|
-
|
|
72
|
+
If you provide both bearer and indexer API key, both headers are sent.
|
|
168
73
|
|
|
169
|
-
|
|
170
|
-
- Production/Preproduction: `https://indexer.zkp2p.xyz/v1/graphql`
|
|
171
|
-
- Staging: `https://indexer-staging.zkp2p.xyz/v1/graphql`
|
|
172
|
-
- Indexer HTTP `429` handling:
|
|
173
|
-
- Honors `Retry-After` in seconds or HTTP-date format.
|
|
174
|
-
- Total attempts are capped at `max(retries, rateLimitRetries) + 1`.
|
|
74
|
+
## Indexer Defaults
|
|
175
75
|
|
|
176
|
-
|
|
76
|
+
- Production: `https://indexer.zkp2p.xyz/v1/graphql`
|
|
77
|
+
- Preproduction: `https://indexer-preprod.zkp2p.xyz/v1/graphql`
|
|
78
|
+
- Staging: `https://indexer-staging.zkp2p.xyz/v1/graphql`
|
|
177
79
|
|
|
178
|
-
|
|
80
|
+
## Common Operations
|
|
179
81
|
|
|
180
|
-
|
|
82
|
+
### Create a Deposit
|
|
181
83
|
|
|
182
|
-
```
|
|
84
|
+
```ts
|
|
183
85
|
import { Currency } from '@zkp2p/sdk';
|
|
184
86
|
|
|
185
87
|
await client.createDeposit({
|
|
186
88
|
token: '0xUSDC_ADDRESS',
|
|
187
|
-
amount:
|
|
188
|
-
intentAmountRange: { min:
|
|
189
|
-
processorNames: ['wise'
|
|
190
|
-
depositData: [
|
|
191
|
-
|
|
192
|
-
{ tag: '@maker' }, // Revolut payment details
|
|
193
|
-
],
|
|
194
|
-
conversionRates: [
|
|
195
|
-
[{ currency: Currency.USD, conversionRate: '1020000000000000000' }], // 1.02 (18 decimals)
|
|
196
|
-
[{ currency: Currency.EUR, conversionRate: '950000000000000000' }], // 0.95 (18 decimals)
|
|
197
|
-
],
|
|
198
|
-
onSuccess: ({ hash }) => console.log('Deposit created:', hash),
|
|
89
|
+
amount: 10_000_000n,
|
|
90
|
+
intentAmountRange: { min: 100_000n, max: 5_000_000n },
|
|
91
|
+
processorNames: ['wise'],
|
|
92
|
+
depositData: [{ email: 'maker@example.com' }],
|
|
93
|
+
conversionRates: [[{ currency: Currency.USD, conversionRate: '1020000000000000000' }]],
|
|
199
94
|
});
|
|
200
95
|
```
|
|
201
96
|
|
|
202
|
-
###
|
|
203
|
-
|
|
204
|
-
```typescript
|
|
205
|
-
// Toggle accepting intents
|
|
206
|
-
await client.setAcceptingIntents({ depositId: 1n, accepting: true });
|
|
97
|
+
### Configure Oracle Spread (EscrowV2)
|
|
207
98
|
|
|
208
|
-
|
|
209
|
-
await client.
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
99
|
+
```ts
|
|
100
|
+
await client.setOracleRateConfig({
|
|
101
|
+
depositId: 42n,
|
|
102
|
+
paymentMethodHash: '0x...',
|
|
103
|
+
currencyHash: '0x...',
|
|
104
|
+
config: {
|
|
105
|
+
adapter: '0x...',
|
|
106
|
+
adapterConfig: '0x',
|
|
107
|
+
spreadBps: 50,
|
|
108
|
+
maxStaleness: 180,
|
|
109
|
+
},
|
|
217
110
|
});
|
|
218
111
|
```
|
|
219
112
|
|
|
220
|
-
###
|
|
221
|
-
|
|
222
|
-
```typescript
|
|
223
|
-
// Add more funds to your deposit
|
|
224
|
-
await client.addFunds({ depositId: 1n, amount: 5000000n });
|
|
225
|
-
|
|
226
|
-
// Remove funds from deposit
|
|
227
|
-
await client.removeFunds({ depositId: 1n, amount: 1000000n });
|
|
228
|
-
|
|
229
|
-
// Withdraw entire deposit
|
|
230
|
-
await client.withdrawDeposit({ depositId: 1n });
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
### Querying Deposits (RPC-first)
|
|
234
|
-
|
|
235
|
-
```typescript
|
|
236
|
-
// Get all your deposits (instant on-chain query)
|
|
237
|
-
const deposits = await client.getDeposits();
|
|
238
|
-
|
|
239
|
-
// Get deposits for any address
|
|
240
|
-
const ownerDeposits = await client.getAccountDeposits('0xOwnerAddress');
|
|
241
|
-
|
|
242
|
-
// Get a specific deposit by ID
|
|
243
|
-
const deposit = await client.getDeposit(42n);
|
|
244
|
-
console.log(`Available liquidity: ${deposit.availableLiquidity}`);
|
|
245
|
-
console.log(`Payment methods: ${deposit.paymentMethods.length}`);
|
|
246
|
-
|
|
247
|
-
// Get multiple deposits by ID
|
|
248
|
-
const batch = await client.getDepositsById([1n, 2n, 3n]);
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### Querying Intents (RPC-first)
|
|
252
|
-
|
|
253
|
-
```typescript
|
|
254
|
-
// Get all your intents
|
|
255
|
-
const intents = await client.getIntents();
|
|
256
|
-
|
|
257
|
-
// Get intents for any address
|
|
258
|
-
const ownerIntents = await client.getAccountIntents('0xOwnerAddress');
|
|
259
|
-
|
|
260
|
-
// Get a specific intent by hash
|
|
261
|
-
const intent = await client.getIntent('0xIntentHash...');
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### Advanced Indexer Queries
|
|
113
|
+
### Vault / DRM Operations
|
|
265
114
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
{ status: 'ACTIVE' },
|
|
278
|
-
{ limit: 50 },
|
|
279
|
-
{ includeIntents: true, intentStatuses: ['SIGNALED'] },
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
// Historical fulfillment records
|
|
283
|
-
const fulfillments = await client.indexer.getFulfilledIntentEvents(['0x...']);
|
|
284
|
-
|
|
285
|
-
// Find deposits by payee
|
|
286
|
-
const payeeDeposits = await client.indexer.getDepositsByPayeeHash('0x...');
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
### Supporting: Intent Operations
|
|
290
|
-
|
|
291
|
-
> **Note**: These methods are typically used by takers/buyers, not liquidity providers.
|
|
292
|
-
|
|
293
|
-
```typescript
|
|
294
|
-
// Signal an intent to use a deposit
|
|
295
|
-
await client.signalIntent({
|
|
296
|
-
depositId: 1n,
|
|
297
|
-
amount: 1000000n,
|
|
298
|
-
toAddress: '0xRecipient',
|
|
299
|
-
processorName: 'wise',
|
|
300
|
-
fiatCurrencyCode: 'USD',
|
|
301
|
-
conversionRate: 1020000n,
|
|
302
|
-
payeeDetails: '0xPayeeHash',
|
|
115
|
+
```ts
|
|
116
|
+
// Create a vault (rate manager)
|
|
117
|
+
await client.createRateManager({
|
|
118
|
+
config: {
|
|
119
|
+
manager: '0xManager',
|
|
120
|
+
feeRecipient: '0xFeeRecipient',
|
|
121
|
+
maxFee: 50_000_000_000_000_000n,
|
|
122
|
+
fee: 10_000_000_000_000_000n,
|
|
123
|
+
name: 'My Vault',
|
|
124
|
+
uri: 'ipfs://...',
|
|
125
|
+
},
|
|
303
126
|
});
|
|
304
127
|
|
|
305
|
-
//
|
|
306
|
-
await client.
|
|
307
|
-
|
|
308
|
-
|
|
128
|
+
// Delegate a deposit to a vault
|
|
129
|
+
await client.setRateManager({
|
|
130
|
+
depositId: 42n,
|
|
131
|
+
rateManagerAddress: '0xVaultAddress',
|
|
132
|
+
rateManagerId: '0xVaultId',
|
|
309
133
|
});
|
|
310
134
|
|
|
311
|
-
//
|
|
312
|
-
await client.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
135
|
+
// Update vault fee and config
|
|
136
|
+
await client.setVaultFee({ rateManagerId: '0xVaultId', newFee: 20_000_000_000_000_000n });
|
|
137
|
+
await client.setVaultConfig({
|
|
138
|
+
rateManagerId: '0xVaultId',
|
|
139
|
+
newManager: '0xNewManager',
|
|
140
|
+
newFeeRecipient: '0xNewFeeRecipient',
|
|
141
|
+
newName: 'Updated Vault',
|
|
142
|
+
newUri: 'ipfs://updated',
|
|
143
|
+
});
|
|
316
144
|
```
|
|
317
145
|
|
|
318
|
-
###
|
|
146
|
+
### Query Indexer Data
|
|
319
147
|
|
|
320
|
-
|
|
148
|
+
```ts
|
|
149
|
+
const deposits = await client.indexer.getDeposits(
|
|
150
|
+
{ status: 'ACTIVE', depositor: '0xYourAddress' },
|
|
151
|
+
{ limit: 25 },
|
|
152
|
+
);
|
|
321
153
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
paymentPlatforms: ['wise', 'revolut'],
|
|
325
|
-
fiatCurrency: 'USD',
|
|
326
|
-
user: '0xUserAddress',
|
|
327
|
-
recipient: '0xRecipientAddress',
|
|
328
|
-
destinationChainId: 8453,
|
|
329
|
-
destinationToken: '0xUSDC',
|
|
330
|
-
amount: '100',
|
|
331
|
-
});
|
|
154
|
+
const amounts = await client.indexer.getIntentFulfillmentAmounts('0xIntentHash');
|
|
155
|
+
// amounts?.releasedAmount, amounts?.takerAmountNetFees
|
|
332
156
|
```
|
|
333
157
|
|
|
334
158
|
## React Hooks
|
|
335
159
|
|
|
336
|
-
The SDK provides React hooks for all deposit and intent operations via a dedicated subpath:
|
|
337
|
-
|
|
338
160
|
```tsx
|
|
339
161
|
import {
|
|
340
162
|
useCreateDeposit,
|
|
341
|
-
useAddFunds,
|
|
342
|
-
useRemoveFunds,
|
|
343
|
-
useWithdrawDeposit,
|
|
344
|
-
useSetAcceptingIntents,
|
|
345
|
-
useSetIntentRange,
|
|
346
|
-
useSetCurrencyMinRate,
|
|
347
|
-
useAddPaymentMethods,
|
|
348
|
-
useRemovePaymentMethod,
|
|
349
|
-
useAddCurrencies,
|
|
350
163
|
useSignalIntent,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
useRemoveDelegate,
|
|
164
|
+
useCreateVault,
|
|
165
|
+
useVaultDelegation,
|
|
166
|
+
useSetVaultFee,
|
|
167
|
+
useSetDepositorFloor,
|
|
356
168
|
} from '@zkp2p/sdk/react';
|
|
357
|
-
|
|
358
|
-
function DepositManager({ client }) {
|
|
359
|
-
const { createDeposit, isLoading, error } = useCreateDeposit({ client });
|
|
360
|
-
const { addFunds } = useAddFunds({ client });
|
|
361
|
-
const { setAcceptingIntents } = useSetAcceptingIntents({ client });
|
|
362
|
-
|
|
363
|
-
const handleCreate = async () => {
|
|
364
|
-
const result = await createDeposit({
|
|
365
|
-
token: '0xUSDC_ADDRESS',
|
|
366
|
-
amount: 10000000000n,
|
|
367
|
-
intentAmountRange: { min: 100000n, max: 1000000000n },
|
|
368
|
-
processorNames: ['wise'],
|
|
369
|
-
depositData: [{ email: 'maker@example.com' }],
|
|
370
|
-
conversionRates: [[{ currency: 'USD', conversionRate: '1020000000000000000' }]], // 1.02 (18 decimals)
|
|
371
|
-
});
|
|
372
|
-
console.log('Created deposit:', result.hash);
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
return (
|
|
376
|
-
<div>
|
|
377
|
-
<button disabled={isLoading} onClick={handleCreate}>
|
|
378
|
-
{isLoading ? 'Creating...' : 'Create Deposit'}
|
|
379
|
-
</button>
|
|
380
|
-
{error && <p>Error: {error.message}</p>}
|
|
381
|
-
</div>
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
169
|
```
|
|
385
170
|
|
|
386
|
-
##
|
|
387
|
-
|
|
388
|
-
Supported payment platforms:
|
|
389
|
-
|
|
390
|
-
| Platform | Key | Currencies |
|
|
391
|
-
| ----------- | ------------- | ------------------- |
|
|
392
|
-
| Wise | `wise` | USD, EUR, GBP, etc. |
|
|
393
|
-
| Venmo | `venmo` | USD |
|
|
394
|
-
| Revolut | `revolut` | USD, EUR, GBP, etc. |
|
|
395
|
-
| CashApp | `cashapp` | USD |
|
|
396
|
-
| PayPal | `paypal` | USD, EUR, etc. |
|
|
397
|
-
| Zelle | `zelle` | USD |
|
|
398
|
-
| Monzo | `monzo` | GBP |
|
|
399
|
-
| Chime | `chime` | USD |
|
|
400
|
-
| Luxon | `luxon` | USD, EUR, GBP |
|
|
401
|
-
| N26 | `n26` | EUR |
|
|
402
|
-
| MercadoPago | `mercadopago` | BRL, ARS, MXN |
|
|
403
|
-
|
|
404
|
-
```typescript
|
|
405
|
-
import { getPaymentMethodsCatalog, PLATFORM_METADATA, PAYMENT_PLATFORMS } from '@zkp2p/sdk';
|
|
406
|
-
|
|
407
|
-
// Available payment platforms
|
|
408
|
-
console.log(PAYMENT_PLATFORMS); // ['wise', 'venmo', 'revolut', 'cashapp', 'mercadopago', 'zelle', 'paypal', 'monzo', 'chime', 'luxon', 'n26']
|
|
409
|
-
|
|
410
|
-
// Get payment method hashes
|
|
411
|
-
const methods = getPaymentMethodsCatalog(8453, 'production');
|
|
412
|
-
const wiseHash = methods['wise'].paymentMethodHash;
|
|
413
|
-
|
|
414
|
-
// Get platform metadata
|
|
415
|
-
const wiseInfo = PLATFORM_METADATA['wise'];
|
|
416
|
-
console.log(wiseInfo.displayName); // "Wise"
|
|
417
|
-
```
|
|
171
|
+
## Contracts and Catalog Helpers
|
|
418
172
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
```typescript
|
|
173
|
+
```ts
|
|
422
174
|
import {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
175
|
+
getContracts,
|
|
176
|
+
getRateManagerContracts,
|
|
177
|
+
getPaymentMethodsCatalog,
|
|
426
178
|
resolveFiatCurrencyBytes32,
|
|
179
|
+
resolvePaymentMethodHash,
|
|
427
180
|
} from '@zkp2p/sdk';
|
|
428
181
|
|
|
429
|
-
|
|
430
|
-
const
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
// Get currency info
|
|
434
|
-
const info = currencyInfo[Currency.USD];
|
|
435
|
-
console.log(info.currencySymbol); // "$"
|
|
436
|
-
|
|
437
|
-
// Convert to bytes32 for on-chain use
|
|
438
|
-
const usdBytes = resolveFiatCurrencyBytes32('USD');
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
## Contract Helpers
|
|
442
|
-
|
|
443
|
-
```typescript
|
|
444
|
-
import { getContracts, getPaymentMethodsCatalog } from '@zkp2p/sdk';
|
|
445
|
-
|
|
446
|
-
// Get contract addresses and ABIs
|
|
447
|
-
const { addresses, abis } = getContracts(8453, 'production');
|
|
448
|
-
console.log(addresses.escrow); // Contract addresses use camelCase
|
|
449
|
-
console.log(addresses.orchestrator);
|
|
450
|
-
|
|
451
|
-
// Get payment methods catalog
|
|
452
|
-
const catalog = getPaymentMethodsCatalog(8453, 'production');
|
|
453
|
-
```
|
|
454
|
-
|
|
455
|
-
## Supported Networks
|
|
456
|
-
|
|
457
|
-
| Network | Chain ID | Environment |
|
|
458
|
-
| ------------ | -------- | ------------ |
|
|
459
|
-
| Base Mainnet | 8453 | `production` |
|
|
460
|
-
| Base Sepolia | 84532 | `staging` |
|
|
461
|
-
|
|
462
|
-
## API Reference
|
|
463
|
-
|
|
464
|
-
### Query Methods (RPC-first)
|
|
465
|
-
|
|
466
|
-
**Deposits (instant on-chain reads):**
|
|
467
|
-
|
|
468
|
-
- `getDeposits()` - Get connected wallet's deposits
|
|
469
|
-
- `getAccountDeposits(owner)` - Get deposits for any address
|
|
470
|
-
- `getDeposit(depositId)` - Get single deposit by ID
|
|
471
|
-
- `getDepositsById(ids)` - Batch fetch deposits
|
|
472
|
-
|
|
473
|
-
**Intents (instant on-chain reads):**
|
|
474
|
-
|
|
475
|
-
- `getIntents()` - Get connected wallet's intents
|
|
476
|
-
- `getAccountIntents(owner)` - Get intents for any address
|
|
477
|
-
- `getIntent(intentHash)` - Get single intent by hash
|
|
478
|
-
|
|
479
|
-
**Utilities:**
|
|
480
|
-
|
|
481
|
-
- `resolvePayeeHash(depositId, paymentMethodHash)` - Get payee details hash
|
|
482
|
-
|
|
483
|
-
**Token Allowance:**
|
|
484
|
-
|
|
485
|
-
- `ensureAllowance(params)` - Check/set ERC20 allowance for deposits
|
|
486
|
-
|
|
487
|
-
### Core Methods (Deposit Management)
|
|
488
|
-
|
|
489
|
-
**Creating & Managing Deposits:**
|
|
490
|
-
|
|
491
|
-
- `createDeposit(params)` - Create a new liquidity deposit
|
|
492
|
-
- `addFunds(params)` - Add funds to deposit
|
|
493
|
-
- `removeFunds(params)` - Remove funds from deposit
|
|
494
|
-
- `withdrawDeposit(params)` - Withdraw entire deposit
|
|
495
|
-
|
|
496
|
-
**Configuring Deposits:**
|
|
497
|
-
|
|
498
|
-
- `setAcceptingIntents(params)` - Toggle intent acceptance
|
|
499
|
-
- `setIntentRange(params)` - Set min/max intent amounts
|
|
500
|
-
- `setCurrencyMinRate(params)` - Set minimum conversion rate
|
|
501
|
-
- `setDelegate(params)` / `removeDelegate(params)` - Manage delegates
|
|
502
|
-
- `addPaymentMethods(params)` - Add payment platforms (requires `currencies` array per method)
|
|
503
|
-
- `setPaymentMethodActive(params)` - Enable/disable payment methods
|
|
504
|
-
- `addCurrencies(params)` / `deactivateCurrency(params)` - Manage currencies
|
|
505
|
-
|
|
506
|
-
### Indexer Methods (`client.indexer.*`)
|
|
507
|
-
|
|
508
|
-
For historical data, pagination, and advanced filtering:
|
|
509
|
-
|
|
510
|
-
- `indexer.getDeposits(filter?, pagination?)` - Query deposits with filters
|
|
511
|
-
- `indexer.getDepositsWithRelations(filter?, pagination?, options?)` - Include payment methods/intents
|
|
512
|
-
- `indexer.getDepositById(compositeId, options?)` - Get by composite ID
|
|
513
|
-
- `indexer.getDepositsByPayeeHash(hash, options?)` - Find by payee
|
|
514
|
-
- `indexer.getOwnerIntents(owner, statuses?)` - Get owner's intents
|
|
515
|
-
- `indexer.getExpiredIntents(params)` - Find expired intents
|
|
516
|
-
- `indexer.getFulfilledIntentEvents(intentHashes)` - Historical fulfillments
|
|
517
|
-
- `indexer.getFulfillmentAndPayment(intentHash)` - Verification records
|
|
518
|
-
- `indexer.client.query(request, { retries?, rateLimitRetries? })` - Raw GraphQL query with retry controls
|
|
519
|
-
|
|
520
|
-
### Supporting Methods
|
|
521
|
-
|
|
522
|
-
**Intent Operations** (typically used by takers, not liquidity providers):
|
|
523
|
-
|
|
524
|
-
- `signalIntent(params)` - Signal an intent to use a deposit
|
|
525
|
-
- `fulfillIntent(params)` - Fulfill with attestation proof
|
|
526
|
-
- `cancelIntent(params)` - Cancel an intent
|
|
527
|
-
- `releaseFundsToPayer(params)` - Release funds back to deposit
|
|
528
|
-
- `pruneExpiredIntents(params)` - Clean up expired intents
|
|
529
|
-
|
|
530
|
-
**Quote API** (used by frontends):
|
|
531
|
-
|
|
532
|
-
- `getQuote(params)` - Get available exchange quotes
|
|
533
|
-
|
|
534
|
-
## Token Allowance Management
|
|
535
|
-
|
|
536
|
-
Before creating deposits or adding funds, you may need to approve the escrow contract to spend your tokens:
|
|
537
|
-
|
|
538
|
-
```typescript
|
|
539
|
-
// Check and set allowance if needed
|
|
540
|
-
const result = await client.ensureAllowance({
|
|
541
|
-
token: '0xUSDC_ADDRESS',
|
|
542
|
-
amount: 10000000000n, // Amount to approve
|
|
543
|
-
spender: addresses.escrow, // Optional: defaults to escrow contract
|
|
544
|
-
maxApprove: false, // Optional: set to true for unlimited approval
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
if (result.hadAllowance) {
|
|
548
|
-
console.log('Already had sufficient allowance');
|
|
549
|
-
} else {
|
|
550
|
-
console.log('Approval transaction:', result.hash);
|
|
551
|
-
}
|
|
182
|
+
const { addresses } = getContracts(8453, 'staging');
|
|
183
|
+
const rateManager = getRateManagerContracts(8453, 'staging');
|
|
184
|
+
const catalog = getPaymentMethodsCatalog(8453, 'staging');
|
|
552
185
|
```
|
|
553
186
|
|
|
554
|
-
##
|
|
555
|
-
|
|
556
|
-
For methods that interact directly with on-chain data, parameters use bytes32 hex strings:
|
|
557
|
-
|
|
558
|
-
```typescript
|
|
559
|
-
// addPaymentMethods - Add payment methods with required currency lists
|
|
560
|
-
await client.addPaymentMethods({
|
|
561
|
-
depositId: 1n,
|
|
562
|
-
paymentMethods: ['0x...'], // bytes32 payment method hashes
|
|
563
|
-
paymentMethodData: [{ intentGatingService: '0x...', payeeDetails: '0x...', data: '0x' }],
|
|
564
|
-
// currencies is required and must align with paymentMethods by index
|
|
565
|
-
currencies: [[{ code: '0x...', minConversionRate: 1020000000000000000n }]],
|
|
566
|
-
});
|
|
187
|
+
## Supported Payment Platforms
|
|
567
188
|
|
|
568
|
-
|
|
569
|
-
await client.addCurrencies({
|
|
570
|
-
depositId: 1n,
|
|
571
|
-
paymentMethod: '0x...', // bytes32 payment method hash
|
|
572
|
-
currencies: [
|
|
573
|
-
{ code: '0x...', minConversionRate: 1020000000000000000n }, // bytes32 currency code, 18 decimals
|
|
574
|
-
],
|
|
575
|
-
});
|
|
189
|
+
`wise`, `venmo`, `revolut`, `cashapp`, `mercadopago`, `zelle`, `paypal`, `monzo`, `chime`, `luxon`, `n26`
|
|
576
190
|
|
|
577
|
-
|
|
578
|
-
await client.deactivateCurrency({
|
|
579
|
-
depositId: 1n,
|
|
580
|
-
paymentMethod: '0x...', // bytes32 payment method hash
|
|
581
|
-
currencyCode: '0x...', // bytes32 currency code
|
|
582
|
-
});
|
|
191
|
+
## Extension SDK Helpers
|
|
583
192
|
|
|
584
|
-
|
|
585
|
-
await client.setPaymentMethodActive({
|
|
586
|
-
depositId: 1n,
|
|
587
|
-
paymentMethod: '0x...', // bytes32 payment method hash (not paymentMethodHash)
|
|
588
|
-
isActive: true,
|
|
589
|
-
});
|
|
193
|
+
If you integrate with the Peer extension:
|
|
590
194
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
depositId: 1n,
|
|
594
|
-
paymentMethod: '0x...', // bytes32 payment method hash
|
|
595
|
-
fiatCurrency: '0x...', // bytes32 currency code (not currencyCode)
|
|
596
|
-
minConversionRate: 1020000000000000000n, // 18 decimals
|
|
597
|
-
});
|
|
598
|
-
```
|
|
599
|
-
|
|
600
|
-
## Error Handling
|
|
601
|
-
|
|
602
|
-
```typescript
|
|
603
|
-
import { ValidationError, NetworkError, ContractError } from '@zkp2p/sdk';
|
|
604
|
-
|
|
605
|
-
try {
|
|
606
|
-
await client.createDeposit({
|
|
607
|
-
/* ... */
|
|
608
|
-
});
|
|
609
|
-
} catch (error) {
|
|
610
|
-
if (error instanceof ValidationError) {
|
|
611
|
-
console.error('Invalid parameters:', error.message);
|
|
612
|
-
} else if (error instanceof NetworkError) {
|
|
613
|
-
console.error('Network issue:', error.message);
|
|
614
|
-
} else if (error instanceof ContractError) {
|
|
615
|
-
console.error('Contract error:', error.message);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
```
|
|
619
|
-
|
|
620
|
-
## Logging
|
|
621
|
-
|
|
622
|
-
```typescript
|
|
623
|
-
import { setLogLevel } from '@zkp2p/sdk';
|
|
624
|
-
|
|
625
|
-
// Set log level: 'debug' | 'info' | 'warn' | 'error' | 'none'
|
|
626
|
-
setLogLevel('debug');
|
|
627
|
-
```
|
|
628
|
-
|
|
629
|
-
## TypeScript Support
|
|
630
|
-
|
|
631
|
-
Full TypeScript support with exported types:
|
|
195
|
+
```ts
|
|
196
|
+
import { peerExtensionSdk } from '@zkp2p/sdk';
|
|
632
197
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
CreateDepositParams,
|
|
636
|
-
SignalIntentParams,
|
|
637
|
-
FulfillIntentParams,
|
|
638
|
-
IndexerDeposit,
|
|
639
|
-
IndexerIntent,
|
|
640
|
-
CurrencyType,
|
|
641
|
-
PaymentPlatformType,
|
|
642
|
-
} from '@zkp2p/sdk';
|
|
198
|
+
const state = await peerExtensionSdk.getState();
|
|
199
|
+
if (state === 'needs_install') peerExtensionSdk.openInstallPage();
|
|
643
200
|
```
|
|
644
201
|
|
|
645
|
-
##
|
|
202
|
+
## Development
|
|
646
203
|
|
|
647
204
|
```bash
|
|
648
205
|
cd packages/sdk
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
206
|
+
pnpm build
|
|
207
|
+
pnpm test
|
|
208
|
+
pnpm typecheck
|
|
209
|
+
pnpm lint
|
|
653
210
|
```
|
|
654
211
|
|
|
655
|
-
## License
|
|
656
|
-
|
|
657
|
-
MIT License - see [LICENSE](LICENSE) for details.
|
|
658
|
-
|
|
659
212
|
## Links
|
|
660
213
|
|
|
661
|
-
-
|
|
662
|
-
-
|
|
663
|
-
-
|
|
664
|
-
|
|
665
|
-
## Support
|
|
666
|
-
|
|
667
|
-
- GitHub Issues: [Create an issue](https://github.com/zkp2p/zkp2p-clients/issues)
|
|
668
|
-
- Email: support@zkp2p.xyz
|
|
214
|
+
- NPM: https://www.npmjs.com/package/@zkp2p/sdk
|
|
215
|
+
- Monorepo: https://github.com/zkp2p/zkp2p-clients
|
|
216
|
+
- Docs: https://docs.zkp2p.xyz
|