voidai-sdk 0.1.2 → 0.2.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 +1 -1
- package/dist/api/client.d.ts +30 -1
- package/dist/api/client.js +104 -2
- package/dist/config.js +9 -10
- package/dist/core/bridge.d.ts +25 -1
- package/dist/core/bridge.js +72 -0
- package/dist/types/index.d.ts +64 -1
- package/dist-browser/voidai-sdk.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ import { BridgeSDK } from 'voidai-sdk';
|
|
|
42
42
|
|
|
43
43
|
const sdk = new BridgeSDK({
|
|
44
44
|
apiKey: process.env.VOIDAI_API_KEY!,
|
|
45
|
-
environment: '
|
|
45
|
+
environment: 'testnet', // 'devnet' | 'testnet' | 'mainnet'
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
// Wait for authentication & API key validation
|
package/dist/api/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BridgeConfig } from '../config';
|
|
2
|
-
import { Chain, Asset, ApiKeyValidationData, BridgeSwapRequest, BridgeSwapResponse, RouteTransactionRequest, RouteTransactionResponse, BridgeFeeEstimateRequest, BridgeFeeEstimateResponse, RouterSwapFeeEstimateRequest, RouterSwapFeeEstimateResponse } from '../types';
|
|
2
|
+
import { Chain, Asset, ApiKeyValidationData, BridgeSwapRequest, BridgeSwapResponse, RouteTransactionRequest, RouteTransactionResponse, BridgeFeeEstimateRequest, BridgeFeeEstimateResponse, RouterSwapFeeEstimateRequest, RouterSwapFeeEstimateResponse, CancelCcipRequest, CancelRouterSwapRequest, CancelBridgeSwapRequest, CancelOperationResponse, ApiTransactionsResponse, ValidateBurnRequest, ValidateBurnResponse, CcipTxConfirmationRequest, CcipTxConfirmationResponse } from '../types';
|
|
3
3
|
export declare class VoidAIBridgeClient {
|
|
4
4
|
private config;
|
|
5
5
|
private client;
|
|
@@ -47,6 +47,8 @@ export declare class VoidAIBridgeClient {
|
|
|
47
47
|
private getUrl;
|
|
48
48
|
get<T>(path: string, params?: any, retryAttempted?: boolean): Promise<T>;
|
|
49
49
|
post<T>(path: string, data?: any, retryAttempted?: boolean): Promise<T>;
|
|
50
|
+
delete<T>(path: string, params?: any, retryAttempted?: boolean): Promise<T>;
|
|
51
|
+
patch<T>(path: string, data?: any, retryAttempted?: boolean): Promise<T>;
|
|
50
52
|
/**
|
|
51
53
|
* Bridge swap operation
|
|
52
54
|
*/
|
|
@@ -55,6 +57,33 @@ export declare class VoidAIBridgeClient {
|
|
|
55
57
|
* Route transaction operation (SWAP / BRIDGE / CCIP)
|
|
56
58
|
*/
|
|
57
59
|
routeTransaction(payload: RouteTransactionRequest): Promise<RouteTransactionResponse>;
|
|
60
|
+
/**
|
|
61
|
+
* Cancel a CCIP route transaction
|
|
62
|
+
*/
|
|
63
|
+
cancelCcip(params: CancelCcipRequest): Promise<CancelOperationResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* Cancel a router swap transaction
|
|
66
|
+
*/
|
|
67
|
+
cancelRouterSwap(params: CancelRouterSwapRequest): Promise<CancelOperationResponse>;
|
|
68
|
+
/**
|
|
69
|
+
* Cancel a bridge swap transaction
|
|
70
|
+
*/
|
|
71
|
+
cancelBridgeSwap(params: CancelBridgeSwapRequest): Promise<CancelOperationResponse>;
|
|
72
|
+
/**
|
|
73
|
+
* Get recent API transactions (tenant-level)
|
|
74
|
+
*
|
|
75
|
+
* Maps to:
|
|
76
|
+
* POST /api/v1/bridge/api-transactions?page={page}&limit={limit}
|
|
77
|
+
*/
|
|
78
|
+
getApiTransactions(page?: number, limit?: number): Promise<ApiTransactionsResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Manually validate a bridge burn transaction (EVM burn completion)
|
|
81
|
+
*/
|
|
82
|
+
validateBurn(params: ValidateBurnRequest): Promise<ValidateBurnResponse>;
|
|
83
|
+
/**
|
|
84
|
+
* Manually confirm a CCIP transaction
|
|
85
|
+
*/
|
|
86
|
+
confirmCcipTransaction(params: CcipTxConfirmationRequest): Promise<CcipTxConfirmationResponse>;
|
|
58
87
|
/**
|
|
59
88
|
* Get list of supported chains
|
|
60
89
|
* @param options - Optional query parameters
|
package/dist/api/client.js
CHANGED
|
@@ -14,7 +14,6 @@ class VoidAIBridgeClient {
|
|
|
14
14
|
timeout: 10000,
|
|
15
15
|
headers: {
|
|
16
16
|
'Content-Type': 'application/json',
|
|
17
|
-
'api-key': this.config.apiKey,
|
|
18
17
|
},
|
|
19
18
|
});
|
|
20
19
|
// Start auth immediately. Requests will await this promise.
|
|
@@ -235,6 +234,48 @@ class VoidAIBridgeClient {
|
|
|
235
234
|
this.handleError(error);
|
|
236
235
|
}
|
|
237
236
|
}
|
|
237
|
+
async delete(path, params, retryAttempted = false) {
|
|
238
|
+
await this.ready;
|
|
239
|
+
const url = this.getUrl(path);
|
|
240
|
+
try {
|
|
241
|
+
const response = await this.client.delete(url, { params });
|
|
242
|
+
return response.data;
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
const status = error?.response?.status ?? error?.statusCode;
|
|
246
|
+
if (status === 401 && !retryAttempted) {
|
|
247
|
+
try {
|
|
248
|
+
await this.authenticate();
|
|
249
|
+
return await this.delete(path, params, true);
|
|
250
|
+
}
|
|
251
|
+
catch (retryError) {
|
|
252
|
+
this.handleError(retryError);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
this.handleError(error);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async patch(path, data, retryAttempted = false) {
|
|
259
|
+
await this.ready;
|
|
260
|
+
const url = this.getUrl(path);
|
|
261
|
+
try {
|
|
262
|
+
const response = await this.client.patch(url, data);
|
|
263
|
+
return response.data;
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
const status = error?.response?.status ?? error?.statusCode;
|
|
267
|
+
if (status === 401 && !retryAttempted) {
|
|
268
|
+
try {
|
|
269
|
+
await this.authenticate();
|
|
270
|
+
return await this.patch(path, data, true);
|
|
271
|
+
}
|
|
272
|
+
catch (retryError) {
|
|
273
|
+
this.handleError(retryError);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
this.handleError(error);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
238
279
|
/**
|
|
239
280
|
* Bridge swap operation
|
|
240
281
|
*/
|
|
@@ -245,7 +286,68 @@ class VoidAIBridgeClient {
|
|
|
245
286
|
* Route transaction operation (SWAP / BRIDGE / CCIP)
|
|
246
287
|
*/
|
|
247
288
|
async routeTransaction(payload) {
|
|
248
|
-
|
|
289
|
+
// Backend expects amount as a string, but our types use number.
|
|
290
|
+
// Normalize here so callers can continue passing numbers.
|
|
291
|
+
const normalizedPayload = {
|
|
292
|
+
...payload,
|
|
293
|
+
amount: String(payload.amount),
|
|
294
|
+
};
|
|
295
|
+
return this.post('api/v1/bridge/route-transaction', normalizedPayload);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Cancel a CCIP route transaction
|
|
299
|
+
*/
|
|
300
|
+
async cancelCcip(params) {
|
|
301
|
+
const queryParams = {
|
|
302
|
+
operationType: params.operationType,
|
|
303
|
+
fromToken: params.fromToken,
|
|
304
|
+
toToken: params.toToken,
|
|
305
|
+
uuid: params.uuid,
|
|
306
|
+
};
|
|
307
|
+
return this.delete('api/v1/bridge/cancel-ccip', queryParams);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Cancel a router swap transaction
|
|
311
|
+
*/
|
|
312
|
+
async cancelRouterSwap(params) {
|
|
313
|
+
const queryParams = {
|
|
314
|
+
uuid: params.uuid,
|
|
315
|
+
};
|
|
316
|
+
return this.delete('api/v1/bridge/cancel-router-swap', queryParams);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Cancel a bridge swap transaction
|
|
320
|
+
*/
|
|
321
|
+
async cancelBridgeSwap(params) {
|
|
322
|
+
return this.patch('api/v1/bridge/swap/cancel', params);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Get recent API transactions (tenant-level)
|
|
326
|
+
*
|
|
327
|
+
* Maps to:
|
|
328
|
+
* POST /api/v1/bridge/api-transactions?page={page}&limit={limit}
|
|
329
|
+
*/
|
|
330
|
+
async getApiTransactions(page = 1, limit = 20) {
|
|
331
|
+
const path = `api/v1/bridge/api-transactions?page=${encodeURIComponent(String(page))}&limit=${encodeURIComponent(String(limit))}`;
|
|
332
|
+
return this.post(path, undefined);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Manually validate a bridge burn transaction (EVM burn completion)
|
|
336
|
+
*/
|
|
337
|
+
async validateBurn(params) {
|
|
338
|
+
return this.post('api/v1/bridge/validate-burn', params);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Manually confirm a CCIP transaction
|
|
342
|
+
*/
|
|
343
|
+
async confirmCcipTransaction(params) {
|
|
344
|
+
const path = `api/v1/bridge/transactions/${encodeURIComponent(params.transactionId)}/tx`;
|
|
345
|
+
const body = {
|
|
346
|
+
txnHash: params.txnHash,
|
|
347
|
+
operationType: params.operationType,
|
|
348
|
+
txnStatus: params.txnStatus,
|
|
349
|
+
};
|
|
350
|
+
return this.patch(path, body);
|
|
249
351
|
}
|
|
250
352
|
/**
|
|
251
353
|
* Get list of supported chains
|
package/dist/config.js
CHANGED
|
@@ -8,11 +8,11 @@ class BridgeConfig {
|
|
|
8
8
|
}
|
|
9
9
|
this.apiKey = options.apiKey;
|
|
10
10
|
this.secretKey = 'secretKey' in options ? options.secretKey : undefined;
|
|
11
|
-
this.environment = options.environment || '
|
|
12
|
-
// Ensure environment is valid, default to
|
|
13
|
-
const validEnvironments = ['
|
|
11
|
+
this.environment = options.environment || 'mainnet';
|
|
12
|
+
// Ensure environment is valid, default to mainnet if invalid
|
|
13
|
+
const validEnvironments = ['devnet', 'testnet', 'mainnet'];
|
|
14
14
|
if (!validEnvironments.includes(this.environment)) {
|
|
15
|
-
this.environment = '
|
|
15
|
+
this.environment = 'mainnet';
|
|
16
16
|
}
|
|
17
17
|
const defaults = BridgeConfig.DEFAULTS[this.environment];
|
|
18
18
|
// Base URL & bridge contract address are derived from environment;
|
|
@@ -26,17 +26,16 @@ class BridgeConfig {
|
|
|
26
26
|
}
|
|
27
27
|
exports.BridgeConfig = BridgeConfig;
|
|
28
28
|
BridgeConfig.DEFAULTS = {
|
|
29
|
-
|
|
30
|
-
// Local/dev backend
|
|
29
|
+
devnet: {
|
|
31
30
|
baseUrl: 'https://api-sdk-dev.voidai.envistudios.com/',
|
|
32
31
|
bridgeContractAddress: '0x6266ce15aC4f32F096Ff91881dd887a0F4bBa569',
|
|
33
32
|
},
|
|
34
|
-
|
|
33
|
+
testnet: {
|
|
35
34
|
baseUrl: 'https://api-sdk-stage.voidai.envistudios.com/',
|
|
36
|
-
bridgeContractAddress: '
|
|
35
|
+
bridgeContractAddress: '0x4aA4396BfD6F268b427077079800F420dF947b63',
|
|
37
36
|
},
|
|
38
|
-
|
|
37
|
+
mainnet: {
|
|
39
38
|
baseUrl: 'https://api-sdk.voidai.envistudios.com/',
|
|
40
|
-
bridgeContractAddress: '
|
|
39
|
+
bridgeContractAddress: '0x604e8Ef901C0E69E79463D997ba7D0724A909b84',
|
|
41
40
|
},
|
|
42
41
|
};
|
package/dist/core/bridge.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VoidAIBridgeClient } from '../api/client';
|
|
2
|
-
import { BridgeSwapRequest, BridgeSwapResponse, RouteSwapRequest, RouteBridgeRequest, RouteCcipRequest, RouteTransactionResponse, BridgeFeeEstimateRequest, BridgeFeeEstimateResponse, RouterSwapFeeEstimateRequest, RouterSwapFeeEstimateResponse } from '../types';
|
|
2
|
+
import { BridgeSwapRequest, BridgeSwapResponse, RouteSwapRequest, RouteBridgeRequest, RouteCcipRequest, RouteTransactionResponse, BridgeFeeEstimateRequest, BridgeFeeEstimateResponse, RouterSwapFeeEstimateRequest, RouterSwapFeeEstimateResponse, CancelCcipRequest, CancelRouterSwapRequest, CancelBridgeSwapRequest, CancelOperationResponse, ApiTransactionsResponse, ValidateBurnRequest, ValidateBurnResponse, CcipTxConfirmationRequest, CcipTxConfirmationResponse } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Bridge API Methods
|
|
5
5
|
* Provides read-only API methods for bridge operations
|
|
@@ -43,4 +43,28 @@ export declare class Bridge {
|
|
|
43
43
|
* Get router swap fee estimate
|
|
44
44
|
*/
|
|
45
45
|
getRouterSwapFeeEstimate(params: RouterSwapFeeEstimateRequest): Promise<RouterSwapFeeEstimateResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Cancel a CCIP route transaction
|
|
48
|
+
*/
|
|
49
|
+
cancelCcipRoute(params: CancelCcipRequest): Promise<CancelOperationResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Cancel a router swap transaction
|
|
52
|
+
*/
|
|
53
|
+
cancelRouterSwap(params: CancelRouterSwapRequest): Promise<CancelOperationResponse>;
|
|
54
|
+
/**
|
|
55
|
+
* Cancel a bridge swap transaction
|
|
56
|
+
*/
|
|
57
|
+
cancelBridgeSwap(params: CancelBridgeSwapRequest): Promise<CancelOperationResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* Get recent API transactions for the current tenant
|
|
60
|
+
*/
|
|
61
|
+
getRecentTransactions(page?: number, limit?: number): Promise<ApiTransactionsResponse>;
|
|
62
|
+
/**
|
|
63
|
+
* Manually validate a bridge burn transaction
|
|
64
|
+
*/
|
|
65
|
+
validateBurnTransaction(params: ValidateBurnRequest): Promise<ValidateBurnResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* Manually confirm a CCIP transaction
|
|
68
|
+
*/
|
|
69
|
+
confirmCcipTransaction(params: CcipTxConfirmationRequest): Promise<CcipTxConfirmationResponse>;
|
|
46
70
|
}
|
package/dist/core/bridge.js
CHANGED
|
@@ -137,5 +137,77 @@ class Bridge {
|
|
|
137
137
|
throw new Error(message);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Cancel a CCIP route transaction
|
|
142
|
+
*/
|
|
143
|
+
async cancelCcipRoute(params) {
|
|
144
|
+
try {
|
|
145
|
+
return await this.apiClient.cancelCcip(params);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
const message = error?.message || 'Failed to cancel CCIP transaction';
|
|
149
|
+
throw new Error(message);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Cancel a router swap transaction
|
|
154
|
+
*/
|
|
155
|
+
async cancelRouterSwap(params) {
|
|
156
|
+
try {
|
|
157
|
+
return await this.apiClient.cancelRouterSwap(params);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
const message = error?.message || 'Failed to cancel router swap transaction';
|
|
161
|
+
throw new Error(message);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Cancel a bridge swap transaction
|
|
166
|
+
*/
|
|
167
|
+
async cancelBridgeSwap(params) {
|
|
168
|
+
try {
|
|
169
|
+
return await this.apiClient.cancelBridgeSwap(params);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
const message = error?.message || 'Failed to cancel bridge transaction';
|
|
173
|
+
throw new Error(message);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Get recent API transactions for the current tenant
|
|
178
|
+
*/
|
|
179
|
+
async getRecentTransactions(page = 1, limit = 20) {
|
|
180
|
+
try {
|
|
181
|
+
return await this.apiClient.getApiTransactions(page, limit);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
const message = error?.message || 'Failed to fetch recent transactions';
|
|
185
|
+
throw new Error(message);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Manually validate a bridge burn transaction
|
|
190
|
+
*/
|
|
191
|
+
async validateBurnTransaction(params) {
|
|
192
|
+
try {
|
|
193
|
+
return await this.apiClient.validateBurn(params);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
const message = error?.message || 'Failed to validate burn transaction';
|
|
197
|
+
throw new Error(message);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Manually confirm a CCIP transaction
|
|
202
|
+
*/
|
|
203
|
+
async confirmCcipTransaction(params) {
|
|
204
|
+
try {
|
|
205
|
+
return await this.apiClient.confirmCcipTransaction(params);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
const message = error?.message || 'Failed to confirm CCIP transaction';
|
|
209
|
+
throw new Error(message);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
140
212
|
}
|
|
141
213
|
exports.Bridge = Bridge;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type Environment = '
|
|
1
|
+
export type Environment = 'devnet' | 'testnet' | 'mainnet';
|
|
2
2
|
/**
|
|
3
3
|
* Options for BridgeSDK (frontend usage).
|
|
4
4
|
* Use apiKey only; secretKey is not supported for frontend.
|
|
@@ -125,6 +125,12 @@ export interface BridgeSwapRequest {
|
|
|
125
125
|
}
|
|
126
126
|
export interface BridgeSwapResponseBase {
|
|
127
127
|
identifier: string;
|
|
128
|
+
/**
|
|
129
|
+
* Destination address that must receive the bridged funds.
|
|
130
|
+
* For BITTENSOR -> EVM/TAO flows, this is the hot wallet /
|
|
131
|
+
* recipient address returned by the backend.
|
|
132
|
+
*/
|
|
133
|
+
toAddress?: string;
|
|
128
134
|
}
|
|
129
135
|
export interface BridgeSwapResponseWithEncodedData extends BridgeSwapResponseBase {
|
|
130
136
|
encodedData: string;
|
|
@@ -215,3 +221,60 @@ export interface RouterSwapFeeEstimateResponse {
|
|
|
215
221
|
ccipFee: string;
|
|
216
222
|
tenantFee: string;
|
|
217
223
|
}
|
|
224
|
+
export interface CancelCcipRequest {
|
|
225
|
+
operationType: 'CCIP';
|
|
226
|
+
fromToken: string;
|
|
227
|
+
toToken: string;
|
|
228
|
+
uuid: string;
|
|
229
|
+
}
|
|
230
|
+
export interface CancelRouterSwapRequest {
|
|
231
|
+
uuid: string;
|
|
232
|
+
}
|
|
233
|
+
export interface CancelBridgeSwapRequest {
|
|
234
|
+
fromToken: string;
|
|
235
|
+
toToken: string;
|
|
236
|
+
uuid: string;
|
|
237
|
+
}
|
|
238
|
+
export interface CancelOperationResponse {
|
|
239
|
+
success: boolean;
|
|
240
|
+
message: string;
|
|
241
|
+
}
|
|
242
|
+
export interface ValidateBurnRequest {
|
|
243
|
+
transactionHash: string;
|
|
244
|
+
identifier: string;
|
|
245
|
+
}
|
|
246
|
+
export interface ValidateBurnResponse {
|
|
247
|
+
success: boolean;
|
|
248
|
+
message: string;
|
|
249
|
+
identifier: string;
|
|
250
|
+
burnDetails: Record<string, any>;
|
|
251
|
+
}
|
|
252
|
+
export interface CcipTxConfirmationRequest {
|
|
253
|
+
transactionId: string;
|
|
254
|
+
txnHash: string;
|
|
255
|
+
operationType: string;
|
|
256
|
+
txnStatus: string;
|
|
257
|
+
}
|
|
258
|
+
export interface CcipTxConfirmationResponse {
|
|
259
|
+
success: boolean;
|
|
260
|
+
message?: string;
|
|
261
|
+
}
|
|
262
|
+
export interface ApiTransactionItem {
|
|
263
|
+
id: string;
|
|
264
|
+
transactionUuid: string;
|
|
265
|
+
functionName: string;
|
|
266
|
+
feeAmount: string;
|
|
267
|
+
status: string;
|
|
268
|
+
transactionHash: {
|
|
269
|
+
chain_hash?: string;
|
|
270
|
+
completion_hash?: string;
|
|
271
|
+
};
|
|
272
|
+
createdAt: string;
|
|
273
|
+
}
|
|
274
|
+
export interface ApiTransactionsResponse {
|
|
275
|
+
items: ApiTransactionItem[];
|
|
276
|
+
page: number;
|
|
277
|
+
limit: number;
|
|
278
|
+
totalItems: number;
|
|
279
|
+
totalPages: number;
|
|
280
|
+
}
|