pepay-streams-sdk 0.1.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 +405 -0
- package/dist/api/index.d.mts +321 -0
- package/dist/api/index.d.ts +321 -0
- package/dist/api/index.js +312 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/index.mjs +306 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/automation/index.d.mts +140 -0
- package/dist/automation/index.d.ts +140 -0
- package/dist/automation/index.js +331 -0
- package/dist/automation/index.js.map +1 -0
- package/dist/automation/index.mjs +326 -0
- package/dist/automation/index.mjs.map +1 -0
- package/dist/campaigns/index.d.mts +286 -0
- package/dist/campaigns/index.d.ts +286 -0
- package/dist/campaigns/index.js +652 -0
- package/dist/campaigns/index.js.map +1 -0
- package/dist/campaigns/index.mjs +645 -0
- package/dist/campaigns/index.mjs.map +1 -0
- package/dist/claims/index.d.mts +190 -0
- package/dist/claims/index.d.ts +190 -0
- package/dist/claims/index.js +414 -0
- package/dist/claims/index.js.map +1 -0
- package/dist/claims/index.mjs +409 -0
- package/dist/claims/index.mjs.map +1 -0
- package/dist/index-BTG0TRJt.d.mts +555 -0
- package/dist/index-BTG0TRJt.d.ts +555 -0
- package/dist/index.d.mts +170 -0
- package/dist/index.d.ts +170 -0
- package/dist/index.js +2926 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2888 -0
- package/dist/index.mjs.map +1 -0
- package/dist/marketplace/index.d.mts +225 -0
- package/dist/marketplace/index.d.ts +225 -0
- package/dist/marketplace/index.js +529 -0
- package/dist/marketplace/index.js.map +1 -0
- package/dist/marketplace/index.mjs +524 -0
- package/dist/marketplace/index.mjs.map +1 -0
- package/dist/react/index.d.mts +185 -0
- package/dist/react/index.d.ts +185 -0
- package/dist/react/index.js +340 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +333 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/staking/index.d.mts +158 -0
- package/dist/staking/index.d.ts +158 -0
- package/dist/staking/index.js +359 -0
- package/dist/staking/index.js.map +1 -0
- package/dist/staking/index.mjs +354 -0
- package/dist/staking/index.mjs.map +1 -0
- package/package.json +106 -0
- package/src/api/index.ts +577 -0
- package/src/automation/index.ts +436 -0
- package/src/campaigns/index.ts +835 -0
- package/src/claims/index.ts +530 -0
- package/src/client.ts +518 -0
- package/src/index.ts +101 -0
- package/src/marketplace/index.ts +730 -0
- package/src/react/index.ts +498 -0
- package/src/staking/index.ts +449 -0
- package/src/types/index.ts +631 -0
package/src/client.ts
ADDED
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main Pepay Streams SDK Client
|
|
3
|
+
*
|
|
4
|
+
* Unified interface for all Pepay Streams operations:
|
|
5
|
+
* - Campaign creation and management
|
|
6
|
+
* - Token claiming
|
|
7
|
+
* - Staking pools
|
|
8
|
+
* - P2P marketplace
|
|
9
|
+
* - Automation
|
|
10
|
+
* - API queries
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
createPublicClient,
|
|
14
|
+
createWalletClient,
|
|
15
|
+
http,
|
|
16
|
+
custom,
|
|
17
|
+
type PublicClient,
|
|
18
|
+
type WalletClient,
|
|
19
|
+
type Address,
|
|
20
|
+
type Chain,
|
|
21
|
+
erc20Abi,
|
|
22
|
+
} from 'viem';
|
|
23
|
+
|
|
24
|
+
// Browser wallet types
|
|
25
|
+
declare global {
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
27
|
+
interface Window {
|
|
28
|
+
ethereum?: {
|
|
29
|
+
request: (args: { method: string }) => Promise<Address[]>;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
import { DIAMOND_ABI } from '@pepay-streams/abi/diamond';
|
|
34
|
+
import type { PepayStreamsConfig, TransactionResult } from './types';
|
|
35
|
+
import { CampaignsModule } from './campaigns';
|
|
36
|
+
import { ClaimsModule } from './claims';
|
|
37
|
+
import { StakingModule } from './staking';
|
|
38
|
+
import { MarketplaceModule } from './marketplace';
|
|
39
|
+
import { AutomationModule } from './automation';
|
|
40
|
+
import { ApiClient } from './api';
|
|
41
|
+
|
|
42
|
+
// Chain configurations
|
|
43
|
+
const CHAINS: Record<number, Chain> = {
|
|
44
|
+
1: {
|
|
45
|
+
id: 1,
|
|
46
|
+
name: 'Ethereum',
|
|
47
|
+
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
|
|
48
|
+
rpcUrls: { default: { http: ['https://eth.llamarpc.com'] } },
|
|
49
|
+
} as Chain,
|
|
50
|
+
56: {
|
|
51
|
+
id: 56,
|
|
52
|
+
name: 'BNB Smart Chain',
|
|
53
|
+
nativeCurrency: { name: 'BNB', symbol: 'BNB', decimals: 18 },
|
|
54
|
+
rpcUrls: { default: { http: ['https://bsc-dataseed.binance.org'] } },
|
|
55
|
+
} as Chain,
|
|
56
|
+
31337: {
|
|
57
|
+
id: 31337,
|
|
58
|
+
name: 'Anvil Local',
|
|
59
|
+
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
|
|
60
|
+
rpcUrls: { default: { http: ['http://127.0.0.1:8545'] } },
|
|
61
|
+
} as Chain,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Canonical addresses
|
|
65
|
+
const PERMIT2_ADDRESS = '0x000000000022D473030F116dDEE9F6B43aC78BA3' as const;
|
|
66
|
+
const WETH_ADDRESSES: Record<number, Address> = {
|
|
67
|
+
1: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
68
|
+
56: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', // WBNB
|
|
69
|
+
31337: '0x2bdCC0de6bE1f7D2ee689a0342D76F52E8EFABa3', // Local WETH
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Pepay Streams SDK Client
|
|
74
|
+
*
|
|
75
|
+
* The main entry point for interacting with Pepay Streams protocol.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import { PepayStreamsClient } from '@pepay-streams/sdk';
|
|
80
|
+
*
|
|
81
|
+
* // Read-only client
|
|
82
|
+
* const client = new PepayStreamsClient({
|
|
83
|
+
* rpcUrl: 'https://eth.llamarpc.com',
|
|
84
|
+
* diamondAddress: '0x...',
|
|
85
|
+
* chainId: 1,
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* // Client with signer (for transactions)
|
|
89
|
+
* const clientWithSigner = new PepayStreamsClient({
|
|
90
|
+
* rpcUrl: 'https://eth.llamarpc.com',
|
|
91
|
+
* diamondAddress: '0x...',
|
|
92
|
+
* chainId: 1,
|
|
93
|
+
* }).withSigner(walletClient);
|
|
94
|
+
*
|
|
95
|
+
* // Or use browser wallet
|
|
96
|
+
* const browserClient = PepayStreamsClient.fromBrowserWallet({
|
|
97
|
+
* diamondAddress: '0x...',
|
|
98
|
+
* chainId: 1,
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export class PepayStreamsClient {
|
|
103
|
+
readonly publicClient: PublicClient;
|
|
104
|
+
readonly walletClient: WalletClient | undefined;
|
|
105
|
+
readonly diamondAddress: Address;
|
|
106
|
+
readonly chainId: number;
|
|
107
|
+
readonly wethAddress: Address;
|
|
108
|
+
readonly permit2Address: Address;
|
|
109
|
+
|
|
110
|
+
// Modules
|
|
111
|
+
readonly campaigns: CampaignsModule;
|
|
112
|
+
readonly claims: ClaimsModule;
|
|
113
|
+
readonly staking: StakingModule;
|
|
114
|
+
readonly marketplace: MarketplaceModule;
|
|
115
|
+
readonly automation: AutomationModule;
|
|
116
|
+
readonly api: ApiClient | undefined;
|
|
117
|
+
|
|
118
|
+
constructor(config: PepayStreamsConfig) {
|
|
119
|
+
this.diamondAddress = config.diamondAddress;
|
|
120
|
+
this.chainId = config.chainId;
|
|
121
|
+
this.wethAddress = config.wethAddress ?? WETH_ADDRESSES[config.chainId] ?? '0x0000000000000000000000000000000000000000';
|
|
122
|
+
this.permit2Address = config.permit2Address ?? PERMIT2_ADDRESS;
|
|
123
|
+
|
|
124
|
+
// Create public client
|
|
125
|
+
const chain = CHAINS[config.chainId];
|
|
126
|
+
this.publicClient = createPublicClient({
|
|
127
|
+
chain,
|
|
128
|
+
transport: http(config.rpcUrl),
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Initialize modules
|
|
132
|
+
this.campaigns = new CampaignsModule(
|
|
133
|
+
this.publicClient,
|
|
134
|
+
undefined,
|
|
135
|
+
this.diamondAddress
|
|
136
|
+
);
|
|
137
|
+
this.claims = new ClaimsModule(
|
|
138
|
+
this.publicClient,
|
|
139
|
+
undefined,
|
|
140
|
+
this.diamondAddress,
|
|
141
|
+
this.chainId
|
|
142
|
+
);
|
|
143
|
+
this.staking = new StakingModule(
|
|
144
|
+
this.publicClient,
|
|
145
|
+
undefined,
|
|
146
|
+
this.diamondAddress
|
|
147
|
+
);
|
|
148
|
+
this.marketplace = new MarketplaceModule(
|
|
149
|
+
this.publicClient,
|
|
150
|
+
undefined,
|
|
151
|
+
this.diamondAddress
|
|
152
|
+
);
|
|
153
|
+
this.automation = new AutomationModule(
|
|
154
|
+
this.publicClient,
|
|
155
|
+
undefined,
|
|
156
|
+
this.diamondAddress
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// Initialize API client if URL provided
|
|
160
|
+
if (config.apiBaseUrl) {
|
|
161
|
+
this.api = new ApiClient(config.apiBaseUrl, config.chainId);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Create a client with a wallet for signing transactions
|
|
167
|
+
*/
|
|
168
|
+
withSigner(walletClient: WalletClient): PepayStreamsClientWithSigner {
|
|
169
|
+
return new PepayStreamsClientWithSigner(
|
|
170
|
+
this.publicClient,
|
|
171
|
+
walletClient,
|
|
172
|
+
this.diamondAddress,
|
|
173
|
+
this.chainId,
|
|
174
|
+
this.wethAddress,
|
|
175
|
+
this.permit2Address,
|
|
176
|
+
this.api
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Create a client from browser wallet (window.ethereum)
|
|
182
|
+
*/
|
|
183
|
+
static async fromBrowserWallet(config: {
|
|
184
|
+
diamondAddress: Address;
|
|
185
|
+
chainId: number;
|
|
186
|
+
apiBaseUrl?: string;
|
|
187
|
+
}): Promise<PepayStreamsClientWithSigner> {
|
|
188
|
+
if (typeof window === 'undefined' || !window.ethereum) {
|
|
189
|
+
throw new Error('Browser wallet not available');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const ethereum = window.ethereum;
|
|
193
|
+
|
|
194
|
+
// Request account access
|
|
195
|
+
const accounts = await ethereum.request({
|
|
196
|
+
method: 'eth_requestAccounts',
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
if (!accounts[0]) {
|
|
200
|
+
throw new Error('No account available');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const chain = CHAINS[config.chainId];
|
|
204
|
+
if (!chain) {
|
|
205
|
+
throw new Error(`Chain ${config.chainId} not supported`);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const publicClient = createPublicClient({
|
|
209
|
+
chain,
|
|
210
|
+
transport: custom(ethereum),
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const walletClient = createWalletClient({
|
|
214
|
+
chain,
|
|
215
|
+
transport: custom(ethereum),
|
|
216
|
+
account: accounts[0],
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
return new PepayStreamsClientWithSigner(
|
|
220
|
+
publicClient,
|
|
221
|
+
walletClient,
|
|
222
|
+
config.diamondAddress,
|
|
223
|
+
config.chainId,
|
|
224
|
+
WETH_ADDRESSES[config.chainId] ?? '0x0000000000000000000000000000000000000000',
|
|
225
|
+
PERMIT2_ADDRESS,
|
|
226
|
+
config.apiBaseUrl ? new ApiClient(config.apiBaseUrl, config.chainId) : undefined
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Create a client with private key (for Node.js/scripts)
|
|
232
|
+
*/
|
|
233
|
+
static fromPrivateKey(config: PepayStreamsConfig & { privateKey: `0x${string}` }): PepayStreamsClientWithSigner {
|
|
234
|
+
const chain = CHAINS[config.chainId];
|
|
235
|
+
if (!chain) {
|
|
236
|
+
throw new Error(`Chain ${config.chainId} not supported`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const publicClient = createPublicClient({
|
|
240
|
+
chain,
|
|
241
|
+
transport: http(config.rpcUrl),
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// Import account from private key
|
|
245
|
+
const { privateKeyToAccount } = require('viem/accounts');
|
|
246
|
+
const account = privateKeyToAccount(config.privateKey);
|
|
247
|
+
|
|
248
|
+
const walletClient = createWalletClient({
|
|
249
|
+
chain,
|
|
250
|
+
transport: http(config.rpcUrl),
|
|
251
|
+
account,
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
return new PepayStreamsClientWithSigner(
|
|
255
|
+
publicClient,
|
|
256
|
+
walletClient,
|
|
257
|
+
config.diamondAddress,
|
|
258
|
+
config.chainId,
|
|
259
|
+
config.wethAddress ?? WETH_ADDRESSES[config.chainId] ?? '0x0000000000000000000000000000000000000000',
|
|
260
|
+
config.permit2Address ?? PERMIT2_ADDRESS,
|
|
261
|
+
config.apiBaseUrl ? new ApiClient(config.apiBaseUrl, config.chainId) : undefined
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// ============================================================================
|
|
266
|
+
// Read-only utilities
|
|
267
|
+
// ============================================================================
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Get token balance
|
|
271
|
+
*/
|
|
272
|
+
async getTokenBalance(token: Address, account: Address): Promise<bigint> {
|
|
273
|
+
return this.publicClient.readContract({
|
|
274
|
+
address: token,
|
|
275
|
+
abi: erc20Abi,
|
|
276
|
+
functionName: 'balanceOf',
|
|
277
|
+
args: [account],
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Get token allowance for Diamond contract
|
|
283
|
+
*/
|
|
284
|
+
async getTokenAllowance(token: Address, owner: Address): Promise<bigint> {
|
|
285
|
+
return this.publicClient.readContract({
|
|
286
|
+
address: token,
|
|
287
|
+
abi: erc20Abi,
|
|
288
|
+
functionName: 'allowance',
|
|
289
|
+
args: [owner, this.diamondAddress],
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Get token info (symbol, decimals, name)
|
|
295
|
+
*/
|
|
296
|
+
async getTokenInfo(token: Address): Promise<{
|
|
297
|
+
symbol: string;
|
|
298
|
+
decimals: number;
|
|
299
|
+
name: string;
|
|
300
|
+
}> {
|
|
301
|
+
const [symbol, decimals, name] = await Promise.all([
|
|
302
|
+
this.publicClient.readContract({
|
|
303
|
+
address: token,
|
|
304
|
+
abi: erc20Abi,
|
|
305
|
+
functionName: 'symbol',
|
|
306
|
+
}) as Promise<string>,
|
|
307
|
+
this.publicClient.readContract({
|
|
308
|
+
address: token,
|
|
309
|
+
abi: erc20Abi,
|
|
310
|
+
functionName: 'decimals',
|
|
311
|
+
}) as Promise<number>,
|
|
312
|
+
this.publicClient.readContract({
|
|
313
|
+
address: token,
|
|
314
|
+
abi: erc20Abi,
|
|
315
|
+
functionName: 'name',
|
|
316
|
+
}) as Promise<string>,
|
|
317
|
+
]);
|
|
318
|
+
|
|
319
|
+
return { symbol, decimals, name };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Get version of a specific facet
|
|
324
|
+
*
|
|
325
|
+
* @param facetAddress - The address of the facet to query
|
|
326
|
+
*/
|
|
327
|
+
async getFacetVersion(facetAddress: Address): Promise<string> {
|
|
328
|
+
const result = await this.publicClient.readContract({
|
|
329
|
+
address: this.diamondAddress,
|
|
330
|
+
abi: DIAMOND_ABI,
|
|
331
|
+
functionName: 'getVersion',
|
|
332
|
+
args: [facetAddress],
|
|
333
|
+
});
|
|
334
|
+
return result as string;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Get all facet versions
|
|
339
|
+
*/
|
|
340
|
+
async getAllVersions(): Promise<{ facets: Address[]; versions: string[] }> {
|
|
341
|
+
const result = await this.publicClient.readContract({
|
|
342
|
+
address: this.diamondAddress,
|
|
343
|
+
abi: DIAMOND_ABI,
|
|
344
|
+
functionName: 'getAllVersions',
|
|
345
|
+
});
|
|
346
|
+
const [facets, versions] = result as [Address[], string[]];
|
|
347
|
+
return { facets, versions };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Check if Diamond contract is in emergency pause
|
|
352
|
+
*/
|
|
353
|
+
async isEmergencyPaused(): Promise<boolean> {
|
|
354
|
+
const result = await this.publicClient.readContract({
|
|
355
|
+
address: this.diamondAddress,
|
|
356
|
+
abi: DIAMOND_ABI,
|
|
357
|
+
functionName: 'isEmergencyPaused',
|
|
358
|
+
});
|
|
359
|
+
return result as boolean;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Client with signer for write operations
|
|
365
|
+
*/
|
|
366
|
+
export class PepayStreamsClientWithSigner extends PepayStreamsClient {
|
|
367
|
+
override readonly walletClient: WalletClient;
|
|
368
|
+
override readonly campaigns: CampaignsModule;
|
|
369
|
+
override readonly claims: ClaimsModule;
|
|
370
|
+
override readonly staking: StakingModule;
|
|
371
|
+
override readonly marketplace: MarketplaceModule;
|
|
372
|
+
override readonly automation: AutomationModule;
|
|
373
|
+
|
|
374
|
+
constructor(
|
|
375
|
+
publicClient: PublicClient,
|
|
376
|
+
walletClient: WalletClient,
|
|
377
|
+
diamondAddress: Address,
|
|
378
|
+
chainId: number,
|
|
379
|
+
wethAddress: Address,
|
|
380
|
+
permit2Address: Address,
|
|
381
|
+
apiClient?: ApiClient
|
|
382
|
+
) {
|
|
383
|
+
// Create base config
|
|
384
|
+
const config: PepayStreamsConfig = {
|
|
385
|
+
rpcUrl: '', // Not used, we pass clients directly
|
|
386
|
+
diamondAddress,
|
|
387
|
+
chainId,
|
|
388
|
+
wethAddress,
|
|
389
|
+
permit2Address,
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// Call parent with minimal config
|
|
393
|
+
super(config);
|
|
394
|
+
|
|
395
|
+
// Override with provided clients
|
|
396
|
+
(this as { publicClient: PublicClient }).publicClient = publicClient;
|
|
397
|
+
this.walletClient = walletClient;
|
|
398
|
+
if (apiClient) {
|
|
399
|
+
(this as { api: ApiClient }).api = apiClient;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// Reinitialize modules with wallet client
|
|
403
|
+
this.campaigns = new CampaignsModule(
|
|
404
|
+
publicClient,
|
|
405
|
+
walletClient,
|
|
406
|
+
diamondAddress
|
|
407
|
+
);
|
|
408
|
+
this.claims = new ClaimsModule(
|
|
409
|
+
publicClient,
|
|
410
|
+
walletClient,
|
|
411
|
+
diamondAddress,
|
|
412
|
+
chainId
|
|
413
|
+
);
|
|
414
|
+
this.staking = new StakingModule(
|
|
415
|
+
publicClient,
|
|
416
|
+
walletClient,
|
|
417
|
+
diamondAddress
|
|
418
|
+
);
|
|
419
|
+
this.marketplace = new MarketplaceModule(
|
|
420
|
+
publicClient,
|
|
421
|
+
walletClient,
|
|
422
|
+
diamondAddress
|
|
423
|
+
);
|
|
424
|
+
this.automation = new AutomationModule(
|
|
425
|
+
publicClient,
|
|
426
|
+
walletClient,
|
|
427
|
+
diamondAddress
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Get the connected wallet address
|
|
433
|
+
*/
|
|
434
|
+
get address(): Address {
|
|
435
|
+
if (!this.walletClient.account) {
|
|
436
|
+
throw new Error('No account connected');
|
|
437
|
+
}
|
|
438
|
+
return this.walletClient.account.address;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// ============================================================================
|
|
442
|
+
// Token Operations
|
|
443
|
+
// ============================================================================
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Approve tokens for the Diamond contract
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* await client.approve(tokenAddress, parseEther('1000'));
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
async approve(
|
|
454
|
+
token: Address,
|
|
455
|
+
amount: bigint
|
|
456
|
+
): Promise<TransactionResult> {
|
|
457
|
+
const hash = await this.walletClient.writeContract({
|
|
458
|
+
chain: this.walletClient.chain,
|
|
459
|
+
account: this.walletClient.account!,
|
|
460
|
+
address: token,
|
|
461
|
+
abi: erc20Abi,
|
|
462
|
+
functionName: 'approve',
|
|
463
|
+
args: [this.diamondAddress, amount],
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
return {
|
|
467
|
+
hash,
|
|
468
|
+
wait: async () => {
|
|
469
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({
|
|
470
|
+
hash,
|
|
471
|
+
});
|
|
472
|
+
return {
|
|
473
|
+
blockNumber: receipt.blockNumber,
|
|
474
|
+
transactionHash: receipt.transactionHash,
|
|
475
|
+
gasUsed: receipt.gasUsed,
|
|
476
|
+
status: receipt.status,
|
|
477
|
+
logs: receipt.logs,
|
|
478
|
+
};
|
|
479
|
+
},
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Approve max tokens (type(uint256).max)
|
|
485
|
+
*/
|
|
486
|
+
async approveMax(token: Address): Promise<TransactionResult> {
|
|
487
|
+
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
488
|
+
return this.approve(token, MAX_UINT256);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Check and approve if needed
|
|
493
|
+
*/
|
|
494
|
+
async ensureAllowance(
|
|
495
|
+
token: Address,
|
|
496
|
+
requiredAmount: bigint
|
|
497
|
+
): Promise<TransactionResult | null> {
|
|
498
|
+
const currentAllowance = await this.getTokenAllowance(
|
|
499
|
+
token,
|
|
500
|
+
this.address
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
if (currentAllowance >= requiredAmount) {
|
|
504
|
+
return null; // Already approved
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return this.approve(token, requiredAmount);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Get native balance (ETH/BNB)
|
|
512
|
+
*/
|
|
513
|
+
async getNativeBalance(): Promise<bigint> {
|
|
514
|
+
return this.publicClient.getBalance({ address: this.address });
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
export default PepayStreamsClient;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pepay Streams SDK
|
|
3
|
+
*
|
|
4
|
+
* TypeScript SDK for interacting with Pepay Streams protocol:
|
|
5
|
+
* - Token distribution campaigns (airdrops, vesting, locks)
|
|
6
|
+
* - Staking pools
|
|
7
|
+
* - P2P marketplace
|
|
8
|
+
* - Automation
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Main client
|
|
14
|
+
export { PepayStreamsClient, PepayStreamsClientWithSigner } from './client';
|
|
15
|
+
|
|
16
|
+
// Modules
|
|
17
|
+
export { CampaignsModule } from './campaigns';
|
|
18
|
+
export { ClaimsModule } from './claims';
|
|
19
|
+
export { StakingModule } from './staking';
|
|
20
|
+
export { MarketplaceModule } from './marketplace';
|
|
21
|
+
export { AutomationModule } from './automation';
|
|
22
|
+
export { ApiClient, ApiError } from './api';
|
|
23
|
+
|
|
24
|
+
// Types - Core
|
|
25
|
+
export type {
|
|
26
|
+
PepayStreamsConfig,
|
|
27
|
+
TransactionResult,
|
|
28
|
+
TransactionReceipt,
|
|
29
|
+
} from './types';
|
|
30
|
+
|
|
31
|
+
// Types - Recipients
|
|
32
|
+
export type {
|
|
33
|
+
Recipient,
|
|
34
|
+
RecipientWithCliff,
|
|
35
|
+
RecipientStatus,
|
|
36
|
+
} from './types';
|
|
37
|
+
|
|
38
|
+
// Types - Campaigns
|
|
39
|
+
export type {
|
|
40
|
+
BaseCampaignParams,
|
|
41
|
+
InstantAirdropParams,
|
|
42
|
+
VestedAirdropParams,
|
|
43
|
+
LockParams,
|
|
44
|
+
VestingParams,
|
|
45
|
+
CampaignInfo,
|
|
46
|
+
} from './types';
|
|
47
|
+
|
|
48
|
+
// Types - Staking
|
|
49
|
+
export type {
|
|
50
|
+
CreatePoolParams,
|
|
51
|
+
PoolInfo,
|
|
52
|
+
UserStake,
|
|
53
|
+
} from './types';
|
|
54
|
+
|
|
55
|
+
// Types - Marketplace
|
|
56
|
+
export type {
|
|
57
|
+
OrderType,
|
|
58
|
+
CreateInstantOrderParams,
|
|
59
|
+
CreateVestedOrderParams,
|
|
60
|
+
CreateTradableOrderParams,
|
|
61
|
+
OrderInfo,
|
|
62
|
+
OrderQuote,
|
|
63
|
+
} from './types';
|
|
64
|
+
|
|
65
|
+
// Types - Automation
|
|
66
|
+
export type {
|
|
67
|
+
EnableAutoWithdrawParams,
|
|
68
|
+
EnableAutoReleaseParams,
|
|
69
|
+
AutomationStatus,
|
|
70
|
+
} from './types';
|
|
71
|
+
|
|
72
|
+
// Types - Claims
|
|
73
|
+
export type {
|
|
74
|
+
ClaimParams,
|
|
75
|
+
BatchClaimParams,
|
|
76
|
+
MetaClaimParams,
|
|
77
|
+
MerkleClaimParams,
|
|
78
|
+
ClaimResult,
|
|
79
|
+
} from './types';
|
|
80
|
+
|
|
81
|
+
// Types - API
|
|
82
|
+
export type {
|
|
83
|
+
PaginatedResponse,
|
|
84
|
+
ApiCampaign,
|
|
85
|
+
ApiOrder,
|
|
86
|
+
ApiStakingPool,
|
|
87
|
+
} from './types';
|
|
88
|
+
|
|
89
|
+
// Enums from shared
|
|
90
|
+
export {
|
|
91
|
+
CampaignKind,
|
|
92
|
+
DeliveryKind,
|
|
93
|
+
OrderStatus,
|
|
94
|
+
ChangePolicy,
|
|
95
|
+
StartMode,
|
|
96
|
+
Visibility,
|
|
97
|
+
StatusBits,
|
|
98
|
+
} from './types';
|
|
99
|
+
|
|
100
|
+
// Re-export viem Address type for convenience
|
|
101
|
+
export type { Address, Hash, Hex } from 'viem';
|