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/api/index.ts
ADDED
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Client Module
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for querying indexed blockchain data:
|
|
5
|
+
* - Campaign queries
|
|
6
|
+
* - Order queries
|
|
7
|
+
* - Wallet activity
|
|
8
|
+
* - Token information
|
|
9
|
+
* - Staking pool queries
|
|
10
|
+
*/
|
|
11
|
+
import type { Address } from 'viem';
|
|
12
|
+
import type {
|
|
13
|
+
ApiCampaign,
|
|
14
|
+
ApiOrder,
|
|
15
|
+
ApiStakingPool,
|
|
16
|
+
PaginatedResponse,
|
|
17
|
+
} from '../types';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Query parameters for campaigns
|
|
21
|
+
*/
|
|
22
|
+
export interface CampaignQueryParams {
|
|
23
|
+
/** Filter by campaign kind */
|
|
24
|
+
kind?: 'instant_airdrop' | 'vested_airdrop' | 'lock' | 'vesting';
|
|
25
|
+
/** Filter by creator address */
|
|
26
|
+
creator?: Address;
|
|
27
|
+
/** Filter by token address */
|
|
28
|
+
token?: Address;
|
|
29
|
+
/** Filter by status */
|
|
30
|
+
status?: 'active' | 'paused' | 'finalized';
|
|
31
|
+
/** Page number (1-indexed) */
|
|
32
|
+
page?: number;
|
|
33
|
+
/** Items per page */
|
|
34
|
+
pageSize?: number;
|
|
35
|
+
/** Sort field */
|
|
36
|
+
sortBy?: 'createdAt' | 'totalAllocated' | 'recipientCount';
|
|
37
|
+
/** Sort direction */
|
|
38
|
+
sortOrder?: 'asc' | 'desc';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Query parameters for orders
|
|
43
|
+
*/
|
|
44
|
+
export interface OrderQueryParams {
|
|
45
|
+
/** Filter by order type */
|
|
46
|
+
orderType?: 'instant' | 'vested' | 'tradable';
|
|
47
|
+
/** Filter by seller */
|
|
48
|
+
seller?: Address;
|
|
49
|
+
/** Filter by sell token */
|
|
50
|
+
sellToken?: Address;
|
|
51
|
+
/** Filter by pay token */
|
|
52
|
+
payToken?: Address;
|
|
53
|
+
/** Filter by status */
|
|
54
|
+
status?: 'open' | 'filled' | 'canceled' | 'expired';
|
|
55
|
+
/** Filter by campaign (for tradable) */
|
|
56
|
+
campaignId?: string;
|
|
57
|
+
/** Page number */
|
|
58
|
+
page?: number;
|
|
59
|
+
/** Items per page */
|
|
60
|
+
pageSize?: number;
|
|
61
|
+
/** Sort field */
|
|
62
|
+
sortBy?: 'createdAt' | 'totalPrice' | 'expiresAt';
|
|
63
|
+
/** Sort direction */
|
|
64
|
+
sortOrder?: 'asc' | 'desc';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Query parameters for staking pools
|
|
69
|
+
*/
|
|
70
|
+
export interface PoolQueryParams {
|
|
71
|
+
/** Filter by stake token */
|
|
72
|
+
stakeToken?: Address;
|
|
73
|
+
/** Filter by reward token */
|
|
74
|
+
rewardToken?: Address;
|
|
75
|
+
/** Filter by creator */
|
|
76
|
+
creator?: Address;
|
|
77
|
+
/** Filter by active status */
|
|
78
|
+
isActive?: boolean;
|
|
79
|
+
/** Page number */
|
|
80
|
+
page?: number;
|
|
81
|
+
/** Items per page */
|
|
82
|
+
pageSize?: number;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Wallet activity summary
|
|
87
|
+
*/
|
|
88
|
+
export interface WalletActivity {
|
|
89
|
+
address: Address;
|
|
90
|
+
/** Campaigns where wallet is a recipient */
|
|
91
|
+
campaigns: {
|
|
92
|
+
id: string;
|
|
93
|
+
kind: string;
|
|
94
|
+
allocated: string;
|
|
95
|
+
claimed: string;
|
|
96
|
+
due: string;
|
|
97
|
+
}[];
|
|
98
|
+
/** Open orders created by wallet */
|
|
99
|
+
openOrders: ApiOrder[];
|
|
100
|
+
/** Staking positions */
|
|
101
|
+
stakes: {
|
|
102
|
+
poolId: string;
|
|
103
|
+
amount: string;
|
|
104
|
+
pendingRewards: string;
|
|
105
|
+
}[];
|
|
106
|
+
/** Total value across all positions (in USD if available) */
|
|
107
|
+
totalValue?: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Token information from enrichment
|
|
112
|
+
*/
|
|
113
|
+
export interface TokenInfo {
|
|
114
|
+
address: Address;
|
|
115
|
+
chainId: number;
|
|
116
|
+
symbol: string;
|
|
117
|
+
name: string;
|
|
118
|
+
decimals: number;
|
|
119
|
+
logoUrl?: string;
|
|
120
|
+
priceUsd?: string;
|
|
121
|
+
marketCap?: string;
|
|
122
|
+
volume24h?: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* API client for indexed blockchain data
|
|
127
|
+
*/
|
|
128
|
+
export class ApiClient {
|
|
129
|
+
private readonly baseUrl: string;
|
|
130
|
+
private readonly chainId: number;
|
|
131
|
+
|
|
132
|
+
constructor(baseUrl: string, chainId: number) {
|
|
133
|
+
this.baseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
|
|
134
|
+
this.chainId = chainId;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ============================================================================
|
|
138
|
+
// Campaign Queries
|
|
139
|
+
// ============================================================================
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Get campaigns with optional filtering
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const campaigns = await sdk.api.getCampaigns({
|
|
147
|
+
* kind: 'vested_airdrop',
|
|
148
|
+
* status: 'active',
|
|
149
|
+
* page: 1,
|
|
150
|
+
* pageSize: 20,
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
async getCampaigns(
|
|
155
|
+
params: CampaignQueryParams = {}
|
|
156
|
+
): Promise<PaginatedResponse<ApiCampaign>> {
|
|
157
|
+
const searchParams = new URLSearchParams();
|
|
158
|
+
|
|
159
|
+
if (params.kind) searchParams.set('kind', params.kind);
|
|
160
|
+
if (params.creator) searchParams.set('creator', params.creator);
|
|
161
|
+
if (params.token) searchParams.set('token', params.token);
|
|
162
|
+
if (params.status) searchParams.set('status', params.status);
|
|
163
|
+
if (params.page) searchParams.set('page', String(params.page));
|
|
164
|
+
if (params.pageSize) searchParams.set('pageSize', String(params.pageSize));
|
|
165
|
+
if (params.sortBy) searchParams.set('sortBy', params.sortBy);
|
|
166
|
+
if (params.sortOrder) searchParams.set('sortOrder', params.sortOrder);
|
|
167
|
+
|
|
168
|
+
searchParams.set('chainId', String(this.chainId));
|
|
169
|
+
|
|
170
|
+
return this.fetch<PaginatedResponse<ApiCampaign>>(
|
|
171
|
+
`/v1/campaigns?${searchParams.toString()}`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Get a single campaign by ID
|
|
177
|
+
*/
|
|
178
|
+
async getCampaign(campaignId: string): Promise<ApiCampaign> {
|
|
179
|
+
return this.fetch<ApiCampaign>(
|
|
180
|
+
`/v1/campaigns/${campaignId}?chainId=${this.chainId}`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get campaign recipients
|
|
186
|
+
*/
|
|
187
|
+
async getCampaignRecipients(
|
|
188
|
+
campaignId: string,
|
|
189
|
+
params: { page?: number; pageSize?: number } = {}
|
|
190
|
+
): Promise<
|
|
191
|
+
PaginatedResponse<{
|
|
192
|
+
address: Address;
|
|
193
|
+
allocated: string;
|
|
194
|
+
claimed: string;
|
|
195
|
+
blocked: boolean;
|
|
196
|
+
}>
|
|
197
|
+
> {
|
|
198
|
+
const searchParams = new URLSearchParams();
|
|
199
|
+
searchParams.set('chainId', String(this.chainId));
|
|
200
|
+
if (params.page) searchParams.set('page', String(params.page));
|
|
201
|
+
if (params.pageSize) searchParams.set('pageSize', String(params.pageSize));
|
|
202
|
+
|
|
203
|
+
return this.fetch(
|
|
204
|
+
`/v1/campaigns/${campaignId}/recipients?${searchParams.toString()}`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Get campaign activity/claims
|
|
210
|
+
*/
|
|
211
|
+
async getCampaignActivity(
|
|
212
|
+
campaignId: string,
|
|
213
|
+
params: { page?: number; pageSize?: number } = {}
|
|
214
|
+
): Promise<
|
|
215
|
+
PaginatedResponse<{
|
|
216
|
+
recipient: Address;
|
|
217
|
+
amount: string;
|
|
218
|
+
timestamp: string;
|
|
219
|
+
txHash: string;
|
|
220
|
+
}>
|
|
221
|
+
> {
|
|
222
|
+
const searchParams = new URLSearchParams();
|
|
223
|
+
searchParams.set('chainId', String(this.chainId));
|
|
224
|
+
if (params.page) searchParams.set('page', String(params.page));
|
|
225
|
+
if (params.pageSize) searchParams.set('pageSize', String(params.pageSize));
|
|
226
|
+
|
|
227
|
+
return this.fetch(
|
|
228
|
+
`/v1/campaigns/${campaignId}/activity?${searchParams.toString()}`
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// ============================================================================
|
|
233
|
+
// Order Queries
|
|
234
|
+
// ============================================================================
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Get marketplace orders with optional filtering
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const orders = await sdk.api.getOrders({
|
|
242
|
+
* orderType: 'tradable',
|
|
243
|
+
* status: 'open',
|
|
244
|
+
* sortBy: 'totalPrice',
|
|
245
|
+
* sortOrder: 'asc',
|
|
246
|
+
* });
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
async getOrders(
|
|
250
|
+
params: OrderQueryParams = {}
|
|
251
|
+
): Promise<PaginatedResponse<ApiOrder>> {
|
|
252
|
+
const searchParams = new URLSearchParams();
|
|
253
|
+
|
|
254
|
+
if (params.orderType) searchParams.set('orderType', params.orderType);
|
|
255
|
+
if (params.seller) searchParams.set('seller', params.seller);
|
|
256
|
+
if (params.sellToken) searchParams.set('sellToken', params.sellToken);
|
|
257
|
+
if (params.payToken) searchParams.set('payToken', params.payToken);
|
|
258
|
+
if (params.status) searchParams.set('status', params.status);
|
|
259
|
+
if (params.campaignId) searchParams.set('campaignId', params.campaignId);
|
|
260
|
+
if (params.page) searchParams.set('page', String(params.page));
|
|
261
|
+
if (params.pageSize) searchParams.set('pageSize', String(params.pageSize));
|
|
262
|
+
if (params.sortBy) searchParams.set('sortBy', params.sortBy);
|
|
263
|
+
if (params.sortOrder) searchParams.set('sortOrder', params.sortOrder);
|
|
264
|
+
|
|
265
|
+
searchParams.set('chainId', String(this.chainId));
|
|
266
|
+
|
|
267
|
+
return this.fetch<PaginatedResponse<ApiOrder>>(
|
|
268
|
+
`/v1/marketplace/orders?${searchParams.toString()}`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Get a single order by ID
|
|
274
|
+
*/
|
|
275
|
+
async getOrder(orderId: string): Promise<ApiOrder> {
|
|
276
|
+
return this.fetch<ApiOrder>(
|
|
277
|
+
`/v1/marketplace/orders/${orderId}?chainId=${this.chainId}`
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Get order price quote
|
|
283
|
+
*/
|
|
284
|
+
async getOrderQuote(orderId: string): Promise<{
|
|
285
|
+
totalPrice: string;
|
|
286
|
+
protocolFee: string;
|
|
287
|
+
sellerReceives: string;
|
|
288
|
+
isValid: boolean;
|
|
289
|
+
}> {
|
|
290
|
+
return this.fetch(
|
|
291
|
+
`/v1/marketplace/orders/${orderId}/quote?chainId=${this.chainId}`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ============================================================================
|
|
296
|
+
// Staking Queries
|
|
297
|
+
// ============================================================================
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Get staking pools with optional filtering
|
|
301
|
+
*/
|
|
302
|
+
async getStakingPools(
|
|
303
|
+
params: PoolQueryParams = {}
|
|
304
|
+
): Promise<PaginatedResponse<ApiStakingPool>> {
|
|
305
|
+
const searchParams = new URLSearchParams();
|
|
306
|
+
|
|
307
|
+
if (params.stakeToken) searchParams.set('stakeToken', params.stakeToken);
|
|
308
|
+
if (params.rewardToken) searchParams.set('rewardToken', params.rewardToken);
|
|
309
|
+
if (params.creator) searchParams.set('creator', params.creator);
|
|
310
|
+
if (params.isActive !== undefined)
|
|
311
|
+
searchParams.set('isActive', String(params.isActive));
|
|
312
|
+
if (params.page) searchParams.set('page', String(params.page));
|
|
313
|
+
if (params.pageSize) searchParams.set('pageSize', String(params.pageSize));
|
|
314
|
+
|
|
315
|
+
searchParams.set('chainId', String(this.chainId));
|
|
316
|
+
|
|
317
|
+
return this.fetch<PaginatedResponse<ApiStakingPool>>(
|
|
318
|
+
`/v1/staking/pools?${searchParams.toString()}`
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Get a single staking pool by ID
|
|
324
|
+
*/
|
|
325
|
+
async getStakingPool(poolId: string): Promise<ApiStakingPool> {
|
|
326
|
+
return this.fetch<ApiStakingPool>(
|
|
327
|
+
`/v1/staking/pools/${poolId}?chainId=${this.chainId}`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Get stakers for a pool
|
|
333
|
+
*/
|
|
334
|
+
async getPoolStakers(
|
|
335
|
+
poolId: string,
|
|
336
|
+
params: { page?: number; pageSize?: number } = {}
|
|
337
|
+
): Promise<
|
|
338
|
+
PaginatedResponse<{
|
|
339
|
+
address: Address;
|
|
340
|
+
amount: string;
|
|
341
|
+
pendingRewards: string;
|
|
342
|
+
}>
|
|
343
|
+
> {
|
|
344
|
+
const searchParams = new URLSearchParams();
|
|
345
|
+
searchParams.set('chainId', String(this.chainId));
|
|
346
|
+
if (params.page) searchParams.set('page', String(params.page));
|
|
347
|
+
if (params.pageSize) searchParams.set('pageSize', String(params.pageSize));
|
|
348
|
+
|
|
349
|
+
return this.fetch(
|
|
350
|
+
`/v1/staking/pools/${poolId}/stakers?${searchParams.toString()}`
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// ============================================================================
|
|
355
|
+
// Wallet Queries
|
|
356
|
+
// ============================================================================
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Get wallet activity summary
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```typescript
|
|
363
|
+
* const activity = await sdk.api.getWalletActivity(address);
|
|
364
|
+
* console.log('Campaigns:', activity.campaigns.length);
|
|
365
|
+
* console.log('Open orders:', activity.openOrders.length);
|
|
366
|
+
* console.log('Stakes:', activity.stakes.length);
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
async getWalletActivity(address: Address): Promise<WalletActivity> {
|
|
370
|
+
return this.fetch<WalletActivity>(
|
|
371
|
+
`/v1/wallets/${address}?chainId=${this.chainId}`
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Get wallet claims history
|
|
377
|
+
*/
|
|
378
|
+
async getWalletClaims(
|
|
379
|
+
address: Address,
|
|
380
|
+
params: { page?: number; pageSize?: number } = {}
|
|
381
|
+
): Promise<
|
|
382
|
+
PaginatedResponse<{
|
|
383
|
+
campaignId: string;
|
|
384
|
+
amount: string;
|
|
385
|
+
timestamp: string;
|
|
386
|
+
txHash: string;
|
|
387
|
+
}>
|
|
388
|
+
> {
|
|
389
|
+
const searchParams = new URLSearchParams();
|
|
390
|
+
searchParams.set('chainId', String(this.chainId));
|
|
391
|
+
if (params.page) searchParams.set('page', String(params.page));
|
|
392
|
+
if (params.pageSize) searchParams.set('pageSize', String(params.pageSize));
|
|
393
|
+
|
|
394
|
+
return this.fetch(
|
|
395
|
+
`/v1/wallets/${address}/claims?${searchParams.toString()}`
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Get wallet positions (campaigns where wallet has allocations)
|
|
401
|
+
*/
|
|
402
|
+
async getWalletPositions(
|
|
403
|
+
address: Address
|
|
404
|
+
): Promise<
|
|
405
|
+
{
|
|
406
|
+
campaignId: string;
|
|
407
|
+
kind: string;
|
|
408
|
+
token: Address;
|
|
409
|
+
allocated: string;
|
|
410
|
+
claimed: string;
|
|
411
|
+
due: string;
|
|
412
|
+
vestingProgress: number;
|
|
413
|
+
}[]
|
|
414
|
+
> {
|
|
415
|
+
return this.fetch(
|
|
416
|
+
`/v1/wallets/${address}/positions?chainId=${this.chainId}`
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// ============================================================================
|
|
421
|
+
// Token Queries
|
|
422
|
+
// ============================================================================
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Search for tokens
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* const tokens = await sdk.api.searchTokens('USDC');
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
async searchTokens(query: string): Promise<TokenInfo[]> {
|
|
433
|
+
return this.fetch<TokenInfo[]>(
|
|
434
|
+
`/v1/tokens?q=${encodeURIComponent(query)}&chainId=${this.chainId}`
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Get token information by address
|
|
440
|
+
*/
|
|
441
|
+
async getToken(address: Address): Promise<TokenInfo> {
|
|
442
|
+
return this.fetch<TokenInfo>(
|
|
443
|
+
`/v1/tokens/${address}?chainId=${this.chainId}`
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Get token price
|
|
449
|
+
*/
|
|
450
|
+
async getTokenPrice(address: Address): Promise<{
|
|
451
|
+
priceUsd: string;
|
|
452
|
+
priceChange24h: string;
|
|
453
|
+
timestamp: string;
|
|
454
|
+
}> {
|
|
455
|
+
return this.fetch(
|
|
456
|
+
`/v1/tokens/${address}/price?chainId=${this.chainId}`
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// ============================================================================
|
|
461
|
+
// Health & Status
|
|
462
|
+
// ============================================================================
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Check API health
|
|
466
|
+
*/
|
|
467
|
+
async health(): Promise<{
|
|
468
|
+
status: 'ok' | 'degraded' | 'down';
|
|
469
|
+
indexerBlockHeight: number;
|
|
470
|
+
chainBlockHeight: number;
|
|
471
|
+
lag: number;
|
|
472
|
+
}> {
|
|
473
|
+
return this.fetch('/health');
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Get supported chains
|
|
478
|
+
*/
|
|
479
|
+
async getChains(): Promise<
|
|
480
|
+
{
|
|
481
|
+
chainId: number;
|
|
482
|
+
name: string;
|
|
483
|
+
rpcUrl: string;
|
|
484
|
+
diamondAddress: Address;
|
|
485
|
+
}[]
|
|
486
|
+
> {
|
|
487
|
+
return this.fetch('/v1/chains');
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// ============================================================================
|
|
491
|
+
// Actions (Transaction Preparation)
|
|
492
|
+
// ============================================================================
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Prepare a claim transaction
|
|
496
|
+
*
|
|
497
|
+
* Returns the calldata for a claim transaction.
|
|
498
|
+
*/
|
|
499
|
+
async prepareClaimTx(params: {
|
|
500
|
+
campaignId: string;
|
|
501
|
+
recipient: Address;
|
|
502
|
+
}): Promise<{
|
|
503
|
+
to: Address;
|
|
504
|
+
data: `0x${string}`;
|
|
505
|
+
value: string;
|
|
506
|
+
estimatedGas: string;
|
|
507
|
+
}> {
|
|
508
|
+
return this.fetch('/v1/actions/claim', {
|
|
509
|
+
method: 'POST',
|
|
510
|
+
body: JSON.stringify({
|
|
511
|
+
...params,
|
|
512
|
+
chainId: this.chainId,
|
|
513
|
+
}),
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Prepare a fill order transaction
|
|
519
|
+
*/
|
|
520
|
+
async prepareFillOrderTx(params: {
|
|
521
|
+
orderId: string;
|
|
522
|
+
}): Promise<{
|
|
523
|
+
to: Address;
|
|
524
|
+
data: `0x${string}`;
|
|
525
|
+
value: string;
|
|
526
|
+
estimatedGas: string;
|
|
527
|
+
}> {
|
|
528
|
+
return this.fetch('/v1/actions/fill-order', {
|
|
529
|
+
method: 'POST',
|
|
530
|
+
body: JSON.stringify({
|
|
531
|
+
...params,
|
|
532
|
+
chainId: this.chainId,
|
|
533
|
+
}),
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// ============================================================================
|
|
538
|
+
// Helpers
|
|
539
|
+
// ============================================================================
|
|
540
|
+
|
|
541
|
+
private async fetch<T>(
|
|
542
|
+
endpoint: string,
|
|
543
|
+
options: RequestInit = {}
|
|
544
|
+
): Promise<T> {
|
|
545
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
546
|
+
|
|
547
|
+
const response = await fetch(url, {
|
|
548
|
+
...options,
|
|
549
|
+
headers: {
|
|
550
|
+
'Content-Type': 'application/json',
|
|
551
|
+
...options.headers,
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
if (!response.ok) {
|
|
556
|
+
const error = await response.text();
|
|
557
|
+
throw new ApiError(response.status, error);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
return response.json() as Promise<T>;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* API error class
|
|
566
|
+
*/
|
|
567
|
+
export class ApiError extends Error {
|
|
568
|
+
constructor(
|
|
569
|
+
public readonly status: number,
|
|
570
|
+
message: string
|
|
571
|
+
) {
|
|
572
|
+
super(`API Error (${status}): ${message}`);
|
|
573
|
+
this.name = 'ApiError';
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export default ApiClient;
|