@dextopus/api-sdk 0.1.0 → 0.1.1
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/dist/index.d.mts +178 -4
- package/dist/index.d.ts +178 -4
- package/dist/index.js +157 -1
- package/dist/index.mjs +154 -1
- package/package.json +7 -4
package/dist/index.d.mts
CHANGED
|
@@ -217,7 +217,7 @@ type Currency = {
|
|
|
217
217
|
name?: string;
|
|
218
218
|
decimals?: number;
|
|
219
219
|
};
|
|
220
|
-
type Chain = {
|
|
220
|
+
type Chain$1 = {
|
|
221
221
|
chainId?: number;
|
|
222
222
|
name?: string;
|
|
223
223
|
solverCurrencies: Currency[];
|
|
@@ -233,7 +233,7 @@ type DepositToken = {
|
|
|
233
233
|
};
|
|
234
234
|
type DepositTokensResponse = {
|
|
235
235
|
success: boolean;
|
|
236
|
-
chains: Chain[];
|
|
236
|
+
chains: Chain$1[];
|
|
237
237
|
tokens: DepositToken[];
|
|
238
238
|
countChains: number;
|
|
239
239
|
countTokens: number;
|
|
@@ -241,7 +241,7 @@ type DepositTokensResponse = {
|
|
|
241
241
|
/** @deprecated Use Currency instead */
|
|
242
242
|
type RelayCurrency = Currency;
|
|
243
243
|
/** @deprecated Use Chain instead */
|
|
244
|
-
type RelayChain = Chain;
|
|
244
|
+
type RelayChain = Chain$1;
|
|
245
245
|
/** @deprecated Use DepositToken instead */
|
|
246
246
|
type NearToken = {
|
|
247
247
|
assetId: string;
|
|
@@ -356,6 +356,13 @@ declare class ApiError extends Error {
|
|
|
356
356
|
body?: ApiErrorShape | string;
|
|
357
357
|
constructor(status: number, message: string, body?: ApiErrorShape | string);
|
|
358
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* Normalize native token address for API compatibility
|
|
361
|
+
* Convert 0xEeeee... to 0x0000... which is what Relay expects
|
|
362
|
+
* @param address Token address to normalize
|
|
363
|
+
* @returns Normalized address
|
|
364
|
+
*/
|
|
365
|
+
declare function normalizeAddress(address: string): string;
|
|
359
366
|
/**
|
|
360
367
|
* Convert human-readable amount to smallest unit
|
|
361
368
|
* @param amount Human-readable amount (e.g., "10" for 10 USDC)
|
|
@@ -374,6 +381,128 @@ declare function toSmallestUnit(amount: string, decimals: number): string;
|
|
|
374
381
|
* @example fromSmallestUnit("1500000000", 9) // Returns "1.5" for 1.5 SOL
|
|
375
382
|
*/
|
|
376
383
|
declare function fromSmallestUnit(amount: string, decimals: number): string;
|
|
384
|
+
/**
|
|
385
|
+
* Chain type for /api/chains endpoint
|
|
386
|
+
*/
|
|
387
|
+
interface Chain {
|
|
388
|
+
chainId: number;
|
|
389
|
+
name: string;
|
|
390
|
+
symbol: string;
|
|
391
|
+
rpcUrl: string;
|
|
392
|
+
explorerUrl?: string;
|
|
393
|
+
logoUrl?: string;
|
|
394
|
+
icon?: string;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Token type for deposit chains
|
|
398
|
+
*/
|
|
399
|
+
interface Token {
|
|
400
|
+
address: string;
|
|
401
|
+
symbol: string;
|
|
402
|
+
name: string;
|
|
403
|
+
decimals: number;
|
|
404
|
+
chainId: number;
|
|
405
|
+
logoUrl?: string;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Deposit quote request matching widget's interface
|
|
409
|
+
*/
|
|
410
|
+
interface DepositQuoteRequestWidget {
|
|
411
|
+
originChainId: number;
|
|
412
|
+
originAsset: string;
|
|
413
|
+
destinationChainId: number;
|
|
414
|
+
destinationAsset: string;
|
|
415
|
+
recipient: string;
|
|
416
|
+
amount: string;
|
|
417
|
+
slippageBps?: number;
|
|
418
|
+
refundTo?: string;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Deposit quote response matching widget's interface
|
|
422
|
+
*/
|
|
423
|
+
interface DepositQuoteResponseWidget {
|
|
424
|
+
success: boolean;
|
|
425
|
+
depositRequestId: string;
|
|
426
|
+
depositAddress: string;
|
|
427
|
+
isStaticAddress: boolean;
|
|
428
|
+
upstreamRequestId: string;
|
|
429
|
+
upstreamQuoteId: string;
|
|
430
|
+
amountOut: string;
|
|
431
|
+
processingTimeSeconds?: number;
|
|
432
|
+
expiresAt?: string;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Class-based API client for Dextopus Backend
|
|
436
|
+
* Provides the same interface as the widget's api.ts
|
|
437
|
+
*/
|
|
438
|
+
declare class DextopusAPI {
|
|
439
|
+
private baseUrl;
|
|
440
|
+
private apiKey;
|
|
441
|
+
constructor(apiKey: string, baseUrl?: string);
|
|
442
|
+
private fetch;
|
|
443
|
+
/**
|
|
444
|
+
* Get all supported chains
|
|
445
|
+
*/
|
|
446
|
+
getChains(): Promise<Chain[]>;
|
|
447
|
+
/**
|
|
448
|
+
* Get all tokens for a specific chain (only Relay solver currencies)
|
|
449
|
+
*/
|
|
450
|
+
getTokens(chainId: number): Promise<Token[]>;
|
|
451
|
+
/**
|
|
452
|
+
* Get destination chains and tokens reachable from source
|
|
453
|
+
*/
|
|
454
|
+
getDestinations(chainId: number, tokenAddress: string): Promise<{
|
|
455
|
+
chainId: number;
|
|
456
|
+
tokens: Array<{
|
|
457
|
+
tokenAddress: string;
|
|
458
|
+
}>;
|
|
459
|
+
}[]>;
|
|
460
|
+
/**
|
|
461
|
+
* Get source chains and tokens that can bridge to destination
|
|
462
|
+
*/
|
|
463
|
+
getSources(destinationChainId: number, destinationTokenAddress: string): Promise<{
|
|
464
|
+
sourceChainId: number;
|
|
465
|
+
currency: string;
|
|
466
|
+
symbol?: string;
|
|
467
|
+
blockchain?: string;
|
|
468
|
+
decimals?: number;
|
|
469
|
+
addressKind: string | null;
|
|
470
|
+
supportsStaticAddress: boolean;
|
|
471
|
+
}[]>;
|
|
472
|
+
/**
|
|
473
|
+
* Get a deposit quote (generates deposit address and quote)
|
|
474
|
+
*/
|
|
475
|
+
getDepositQuote(request: DepositQuoteRequestWidget): Promise<DepositQuoteResponseWidget>;
|
|
476
|
+
/**
|
|
477
|
+
* Get deposit status by deposit request ID
|
|
478
|
+
*/
|
|
479
|
+
getDepositStatus(depositRequestId: string): Promise<{
|
|
480
|
+
success: boolean;
|
|
481
|
+
depositRequestId: string;
|
|
482
|
+
depositAddress: string;
|
|
483
|
+
isStaticAddress: boolean;
|
|
484
|
+
upstreamRequestId: string;
|
|
485
|
+
status: string;
|
|
486
|
+
executionStatus?: string;
|
|
487
|
+
originTransactionHashes?: string[];
|
|
488
|
+
destinationTransactionHashes?: string[];
|
|
489
|
+
raw?: any;
|
|
490
|
+
}>;
|
|
491
|
+
/**
|
|
492
|
+
* List deposit requests for the API key
|
|
493
|
+
*/
|
|
494
|
+
listDepositRequests(params?: {
|
|
495
|
+
limit?: number;
|
|
496
|
+
offset?: number;
|
|
497
|
+
status?: string;
|
|
498
|
+
}): Promise<any[]>;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Create a new DextopusAPI client instance
|
|
502
|
+
* @param apiKey Your API key
|
|
503
|
+
* @param baseUrl Optional base URL (defaults to http://localhost:3000)
|
|
504
|
+
*/
|
|
505
|
+
declare function createAPIClient(apiKey: string, baseUrl?: string): DextopusAPI;
|
|
377
506
|
declare function createApiClient(options?: ApiClientOptions): {
|
|
378
507
|
quote: (payload: QuoteRequest) => Promise<QuoteResponse>;
|
|
379
508
|
buildTransaction: (payload: BuildTransactionRequest) => Promise<BuildTransactionResponse>;
|
|
@@ -386,6 +515,51 @@ declare function createApiClient(options?: ApiClientOptions): {
|
|
|
386
515
|
depositDestinations: (params: DepositDestinationsParams) => Promise<DepositDestinationsResponse>;
|
|
387
516
|
depositSources: (params: DepositSourcesParams) => Promise<DepositSourcesResponse>;
|
|
388
517
|
depositValidateAddress: (payload: ValidateAddressRequest) => Promise<ValidateAddressResponse>;
|
|
518
|
+
/**
|
|
519
|
+
* Get all supported chains with their metadata
|
|
520
|
+
*/
|
|
521
|
+
getChains: () => Promise<{
|
|
522
|
+
success: boolean;
|
|
523
|
+
chains: Array<{
|
|
524
|
+
chainId: number;
|
|
525
|
+
name: string;
|
|
526
|
+
symbol: string;
|
|
527
|
+
rpcUrl: string;
|
|
528
|
+
explorerUrl?: string;
|
|
529
|
+
}>;
|
|
530
|
+
count: number;
|
|
531
|
+
}>;
|
|
532
|
+
/**
|
|
533
|
+
* Get deposit chains with their Relay solver currencies/tokens
|
|
534
|
+
*/
|
|
535
|
+
depositChains: () => Promise<{
|
|
536
|
+
success: boolean;
|
|
537
|
+
chains: Array<{
|
|
538
|
+
chainId: number;
|
|
539
|
+
name?: string;
|
|
540
|
+
tokens: Array<{
|
|
541
|
+
address: string;
|
|
542
|
+
symbol: string;
|
|
543
|
+
name: string;
|
|
544
|
+
decimals: number;
|
|
545
|
+
chainId: number;
|
|
546
|
+
logoUrl?: string;
|
|
547
|
+
}>;
|
|
548
|
+
}>;
|
|
549
|
+
count: number;
|
|
550
|
+
}>;
|
|
551
|
+
/**
|
|
552
|
+
* List deposit requests for the API key
|
|
553
|
+
*/
|
|
554
|
+
listDepositRequests: (params?: {
|
|
555
|
+
limit?: number;
|
|
556
|
+
offset?: number;
|
|
557
|
+
status?: string;
|
|
558
|
+
}) => Promise<{
|
|
559
|
+
success: boolean;
|
|
560
|
+
requests: Array<Record<string, unknown>>;
|
|
561
|
+
total: number;
|
|
562
|
+
}>;
|
|
389
563
|
};
|
|
390
564
|
|
|
391
|
-
export { type AddressKind, ApiError, type ApiErrorDetail, type ApiErrorShape, type BuildTransactionRequest, type BuildTransactionResponse, type Chain, type Currency, type DepositDestination, type DepositDestinationChain, type DepositDestinationsParams, type DepositDestinationsResponse, type DepositFee, type DepositQuoteRequest, type DepositQuoteResponse, type DepositSource, type DepositSourceChain, type DepositSourcesParams, type DepositSourcesResponse, type DepositStatusParams, type DepositStatusResponse, type DepositSubmitRequest, type DepositSubmitResponse, type DepositToken, type DepositTokensResponse, type EvmTransactionPayload, type FeeBreakdown, type FeeDetails, type HealthResponse, type NearToken, type PartnerFee, type QuoteAlternativeRoute, type QuoteEdge, type QuoteRequest, type QuoteResponse, type QuoteRoute, type RelayChain, type RelayCurrency, type TransactionPayload, type TransactionSimulation, type TransactionSimulationStep, type TransactionStep, type TronTransactionPayload, type UnifiedToken, type ValidateAddressRequest, type ValidateAddressResponse, createApiClient, fromSmallestUnit, toSmallestUnit };
|
|
565
|
+
export { type AddressKind, ApiError, type ApiErrorDetail, type ApiErrorShape, type BuildTransactionRequest, type BuildTransactionResponse, type Chain, type Currency, type DepositDestination, type DepositDestinationChain, type DepositDestinationsParams, type DepositDestinationsResponse, type DepositFee, type DepositQuoteRequest, type DepositQuoteRequestWidget, type DepositQuoteResponse, type DepositQuoteResponseWidget, type DepositSource, type DepositSourceChain, type DepositSourcesParams, type DepositSourcesResponse, type DepositStatusParams, type DepositStatusResponse, type DepositSubmitRequest, type DepositSubmitResponse, type DepositToken, type DepositTokensResponse, DextopusAPI, type EvmTransactionPayload, type FeeBreakdown, type FeeDetails, type HealthResponse, type NearToken, type PartnerFee, type QuoteAlternativeRoute, type QuoteEdge, type QuoteRequest, type QuoteResponse, type QuoteRoute, type RelayChain, type RelayCurrency, type Token, type TransactionPayload, type TransactionSimulation, type TransactionSimulationStep, type TransactionStep, type TronTransactionPayload, type UnifiedToken, type ValidateAddressRequest, type ValidateAddressResponse, createAPIClient, createApiClient, fromSmallestUnit, normalizeAddress, toSmallestUnit };
|
package/dist/index.d.ts
CHANGED
|
@@ -217,7 +217,7 @@ type Currency = {
|
|
|
217
217
|
name?: string;
|
|
218
218
|
decimals?: number;
|
|
219
219
|
};
|
|
220
|
-
type Chain = {
|
|
220
|
+
type Chain$1 = {
|
|
221
221
|
chainId?: number;
|
|
222
222
|
name?: string;
|
|
223
223
|
solverCurrencies: Currency[];
|
|
@@ -233,7 +233,7 @@ type DepositToken = {
|
|
|
233
233
|
};
|
|
234
234
|
type DepositTokensResponse = {
|
|
235
235
|
success: boolean;
|
|
236
|
-
chains: Chain[];
|
|
236
|
+
chains: Chain$1[];
|
|
237
237
|
tokens: DepositToken[];
|
|
238
238
|
countChains: number;
|
|
239
239
|
countTokens: number;
|
|
@@ -241,7 +241,7 @@ type DepositTokensResponse = {
|
|
|
241
241
|
/** @deprecated Use Currency instead */
|
|
242
242
|
type RelayCurrency = Currency;
|
|
243
243
|
/** @deprecated Use Chain instead */
|
|
244
|
-
type RelayChain = Chain;
|
|
244
|
+
type RelayChain = Chain$1;
|
|
245
245
|
/** @deprecated Use DepositToken instead */
|
|
246
246
|
type NearToken = {
|
|
247
247
|
assetId: string;
|
|
@@ -356,6 +356,13 @@ declare class ApiError extends Error {
|
|
|
356
356
|
body?: ApiErrorShape | string;
|
|
357
357
|
constructor(status: number, message: string, body?: ApiErrorShape | string);
|
|
358
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* Normalize native token address for API compatibility
|
|
361
|
+
* Convert 0xEeeee... to 0x0000... which is what Relay expects
|
|
362
|
+
* @param address Token address to normalize
|
|
363
|
+
* @returns Normalized address
|
|
364
|
+
*/
|
|
365
|
+
declare function normalizeAddress(address: string): string;
|
|
359
366
|
/**
|
|
360
367
|
* Convert human-readable amount to smallest unit
|
|
361
368
|
* @param amount Human-readable amount (e.g., "10" for 10 USDC)
|
|
@@ -374,6 +381,128 @@ declare function toSmallestUnit(amount: string, decimals: number): string;
|
|
|
374
381
|
* @example fromSmallestUnit("1500000000", 9) // Returns "1.5" for 1.5 SOL
|
|
375
382
|
*/
|
|
376
383
|
declare function fromSmallestUnit(amount: string, decimals: number): string;
|
|
384
|
+
/**
|
|
385
|
+
* Chain type for /api/chains endpoint
|
|
386
|
+
*/
|
|
387
|
+
interface Chain {
|
|
388
|
+
chainId: number;
|
|
389
|
+
name: string;
|
|
390
|
+
symbol: string;
|
|
391
|
+
rpcUrl: string;
|
|
392
|
+
explorerUrl?: string;
|
|
393
|
+
logoUrl?: string;
|
|
394
|
+
icon?: string;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Token type for deposit chains
|
|
398
|
+
*/
|
|
399
|
+
interface Token {
|
|
400
|
+
address: string;
|
|
401
|
+
symbol: string;
|
|
402
|
+
name: string;
|
|
403
|
+
decimals: number;
|
|
404
|
+
chainId: number;
|
|
405
|
+
logoUrl?: string;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Deposit quote request matching widget's interface
|
|
409
|
+
*/
|
|
410
|
+
interface DepositQuoteRequestWidget {
|
|
411
|
+
originChainId: number;
|
|
412
|
+
originAsset: string;
|
|
413
|
+
destinationChainId: number;
|
|
414
|
+
destinationAsset: string;
|
|
415
|
+
recipient: string;
|
|
416
|
+
amount: string;
|
|
417
|
+
slippageBps?: number;
|
|
418
|
+
refundTo?: string;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Deposit quote response matching widget's interface
|
|
422
|
+
*/
|
|
423
|
+
interface DepositQuoteResponseWidget {
|
|
424
|
+
success: boolean;
|
|
425
|
+
depositRequestId: string;
|
|
426
|
+
depositAddress: string;
|
|
427
|
+
isStaticAddress: boolean;
|
|
428
|
+
upstreamRequestId: string;
|
|
429
|
+
upstreamQuoteId: string;
|
|
430
|
+
amountOut: string;
|
|
431
|
+
processingTimeSeconds?: number;
|
|
432
|
+
expiresAt?: string;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Class-based API client for Dextopus Backend
|
|
436
|
+
* Provides the same interface as the widget's api.ts
|
|
437
|
+
*/
|
|
438
|
+
declare class DextopusAPI {
|
|
439
|
+
private baseUrl;
|
|
440
|
+
private apiKey;
|
|
441
|
+
constructor(apiKey: string, baseUrl?: string);
|
|
442
|
+
private fetch;
|
|
443
|
+
/**
|
|
444
|
+
* Get all supported chains
|
|
445
|
+
*/
|
|
446
|
+
getChains(): Promise<Chain[]>;
|
|
447
|
+
/**
|
|
448
|
+
* Get all tokens for a specific chain (only Relay solver currencies)
|
|
449
|
+
*/
|
|
450
|
+
getTokens(chainId: number): Promise<Token[]>;
|
|
451
|
+
/**
|
|
452
|
+
* Get destination chains and tokens reachable from source
|
|
453
|
+
*/
|
|
454
|
+
getDestinations(chainId: number, tokenAddress: string): Promise<{
|
|
455
|
+
chainId: number;
|
|
456
|
+
tokens: Array<{
|
|
457
|
+
tokenAddress: string;
|
|
458
|
+
}>;
|
|
459
|
+
}[]>;
|
|
460
|
+
/**
|
|
461
|
+
* Get source chains and tokens that can bridge to destination
|
|
462
|
+
*/
|
|
463
|
+
getSources(destinationChainId: number, destinationTokenAddress: string): Promise<{
|
|
464
|
+
sourceChainId: number;
|
|
465
|
+
currency: string;
|
|
466
|
+
symbol?: string;
|
|
467
|
+
blockchain?: string;
|
|
468
|
+
decimals?: number;
|
|
469
|
+
addressKind: string | null;
|
|
470
|
+
supportsStaticAddress: boolean;
|
|
471
|
+
}[]>;
|
|
472
|
+
/**
|
|
473
|
+
* Get a deposit quote (generates deposit address and quote)
|
|
474
|
+
*/
|
|
475
|
+
getDepositQuote(request: DepositQuoteRequestWidget): Promise<DepositQuoteResponseWidget>;
|
|
476
|
+
/**
|
|
477
|
+
* Get deposit status by deposit request ID
|
|
478
|
+
*/
|
|
479
|
+
getDepositStatus(depositRequestId: string): Promise<{
|
|
480
|
+
success: boolean;
|
|
481
|
+
depositRequestId: string;
|
|
482
|
+
depositAddress: string;
|
|
483
|
+
isStaticAddress: boolean;
|
|
484
|
+
upstreamRequestId: string;
|
|
485
|
+
status: string;
|
|
486
|
+
executionStatus?: string;
|
|
487
|
+
originTransactionHashes?: string[];
|
|
488
|
+
destinationTransactionHashes?: string[];
|
|
489
|
+
raw?: any;
|
|
490
|
+
}>;
|
|
491
|
+
/**
|
|
492
|
+
* List deposit requests for the API key
|
|
493
|
+
*/
|
|
494
|
+
listDepositRequests(params?: {
|
|
495
|
+
limit?: number;
|
|
496
|
+
offset?: number;
|
|
497
|
+
status?: string;
|
|
498
|
+
}): Promise<any[]>;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Create a new DextopusAPI client instance
|
|
502
|
+
* @param apiKey Your API key
|
|
503
|
+
* @param baseUrl Optional base URL (defaults to http://localhost:3000)
|
|
504
|
+
*/
|
|
505
|
+
declare function createAPIClient(apiKey: string, baseUrl?: string): DextopusAPI;
|
|
377
506
|
declare function createApiClient(options?: ApiClientOptions): {
|
|
378
507
|
quote: (payload: QuoteRequest) => Promise<QuoteResponse>;
|
|
379
508
|
buildTransaction: (payload: BuildTransactionRequest) => Promise<BuildTransactionResponse>;
|
|
@@ -386,6 +515,51 @@ declare function createApiClient(options?: ApiClientOptions): {
|
|
|
386
515
|
depositDestinations: (params: DepositDestinationsParams) => Promise<DepositDestinationsResponse>;
|
|
387
516
|
depositSources: (params: DepositSourcesParams) => Promise<DepositSourcesResponse>;
|
|
388
517
|
depositValidateAddress: (payload: ValidateAddressRequest) => Promise<ValidateAddressResponse>;
|
|
518
|
+
/**
|
|
519
|
+
* Get all supported chains with their metadata
|
|
520
|
+
*/
|
|
521
|
+
getChains: () => Promise<{
|
|
522
|
+
success: boolean;
|
|
523
|
+
chains: Array<{
|
|
524
|
+
chainId: number;
|
|
525
|
+
name: string;
|
|
526
|
+
symbol: string;
|
|
527
|
+
rpcUrl: string;
|
|
528
|
+
explorerUrl?: string;
|
|
529
|
+
}>;
|
|
530
|
+
count: number;
|
|
531
|
+
}>;
|
|
532
|
+
/**
|
|
533
|
+
* Get deposit chains with their Relay solver currencies/tokens
|
|
534
|
+
*/
|
|
535
|
+
depositChains: () => Promise<{
|
|
536
|
+
success: boolean;
|
|
537
|
+
chains: Array<{
|
|
538
|
+
chainId: number;
|
|
539
|
+
name?: string;
|
|
540
|
+
tokens: Array<{
|
|
541
|
+
address: string;
|
|
542
|
+
symbol: string;
|
|
543
|
+
name: string;
|
|
544
|
+
decimals: number;
|
|
545
|
+
chainId: number;
|
|
546
|
+
logoUrl?: string;
|
|
547
|
+
}>;
|
|
548
|
+
}>;
|
|
549
|
+
count: number;
|
|
550
|
+
}>;
|
|
551
|
+
/**
|
|
552
|
+
* List deposit requests for the API key
|
|
553
|
+
*/
|
|
554
|
+
listDepositRequests: (params?: {
|
|
555
|
+
limit?: number;
|
|
556
|
+
offset?: number;
|
|
557
|
+
status?: string;
|
|
558
|
+
}) => Promise<{
|
|
559
|
+
success: boolean;
|
|
560
|
+
requests: Array<Record<string, unknown>>;
|
|
561
|
+
total: number;
|
|
562
|
+
}>;
|
|
389
563
|
};
|
|
390
564
|
|
|
391
|
-
export { type AddressKind, ApiError, type ApiErrorDetail, type ApiErrorShape, type BuildTransactionRequest, type BuildTransactionResponse, type Chain, type Currency, type DepositDestination, type DepositDestinationChain, type DepositDestinationsParams, type DepositDestinationsResponse, type DepositFee, type DepositQuoteRequest, type DepositQuoteResponse, type DepositSource, type DepositSourceChain, type DepositSourcesParams, type DepositSourcesResponse, type DepositStatusParams, type DepositStatusResponse, type DepositSubmitRequest, type DepositSubmitResponse, type DepositToken, type DepositTokensResponse, type EvmTransactionPayload, type FeeBreakdown, type FeeDetails, type HealthResponse, type NearToken, type PartnerFee, type QuoteAlternativeRoute, type QuoteEdge, type QuoteRequest, type QuoteResponse, type QuoteRoute, type RelayChain, type RelayCurrency, type TransactionPayload, type TransactionSimulation, type TransactionSimulationStep, type TransactionStep, type TronTransactionPayload, type UnifiedToken, type ValidateAddressRequest, type ValidateAddressResponse, createApiClient, fromSmallestUnit, toSmallestUnit };
|
|
565
|
+
export { type AddressKind, ApiError, type ApiErrorDetail, type ApiErrorShape, type BuildTransactionRequest, type BuildTransactionResponse, type Chain, type Currency, type DepositDestination, type DepositDestinationChain, type DepositDestinationsParams, type DepositDestinationsResponse, type DepositFee, type DepositQuoteRequest, type DepositQuoteRequestWidget, type DepositQuoteResponse, type DepositQuoteResponseWidget, type DepositSource, type DepositSourceChain, type DepositSourcesParams, type DepositSourcesResponse, type DepositStatusParams, type DepositStatusResponse, type DepositSubmitRequest, type DepositSubmitResponse, type DepositToken, type DepositTokensResponse, DextopusAPI, type EvmTransactionPayload, type FeeBreakdown, type FeeDetails, type HealthResponse, type NearToken, type PartnerFee, type QuoteAlternativeRoute, type QuoteEdge, type QuoteRequest, type QuoteResponse, type QuoteRoute, type RelayChain, type RelayCurrency, type Token, type TransactionPayload, type TransactionSimulation, type TransactionSimulationStep, type TransactionStep, type TronTransactionPayload, type UnifiedToken, type ValidateAddressRequest, type ValidateAddressResponse, createAPIClient, createApiClient, fromSmallestUnit, normalizeAddress, toSmallestUnit };
|
package/dist/index.js
CHANGED
|
@@ -21,8 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
ApiError: () => ApiError,
|
|
24
|
+
DextopusAPI: () => DextopusAPI,
|
|
25
|
+
createAPIClient: () => createAPIClient,
|
|
24
26
|
createApiClient: () => createApiClient,
|
|
25
27
|
fromSmallestUnit: () => fromSmallestUnit,
|
|
28
|
+
normalizeAddress: () => normalizeAddress,
|
|
26
29
|
toSmallestUnit: () => toSmallestUnit
|
|
27
30
|
});
|
|
28
31
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -43,6 +46,14 @@ function buildHeaders(apiKey) {
|
|
|
43
46
|
if (apiKey) headers["x-api-key"] = apiKey;
|
|
44
47
|
return headers;
|
|
45
48
|
}
|
|
49
|
+
function normalizeAddress(address) {
|
|
50
|
+
const NATIVE_PLACEHOLDER = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
51
|
+
const RELAY_NATIVE = "0x0000000000000000000000000000000000000000";
|
|
52
|
+
if (address.toLowerCase() === NATIVE_PLACEHOLDER.toLowerCase()) {
|
|
53
|
+
return RELAY_NATIVE;
|
|
54
|
+
}
|
|
55
|
+
return address;
|
|
56
|
+
}
|
|
46
57
|
function toSmallestUnit(amount, decimals) {
|
|
47
58
|
const num = parseFloat(amount);
|
|
48
59
|
if (isNaN(num)) {
|
|
@@ -75,6 +86,114 @@ async function requestJson(fetcher, url, options, timeoutMs) {
|
|
|
75
86
|
clearTimeout(timeout);
|
|
76
87
|
}
|
|
77
88
|
}
|
|
89
|
+
var DextopusAPI = class {
|
|
90
|
+
baseUrl;
|
|
91
|
+
apiKey;
|
|
92
|
+
constructor(apiKey, baseUrl = "http://localhost:3000") {
|
|
93
|
+
this.apiKey = apiKey;
|
|
94
|
+
this.baseUrl = baseUrl;
|
|
95
|
+
}
|
|
96
|
+
async fetch(endpoint, options = {}) {
|
|
97
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
98
|
+
const headers = {
|
|
99
|
+
"Content-Type": "application/json",
|
|
100
|
+
"x-api-key": this.apiKey,
|
|
101
|
+
...options.headers
|
|
102
|
+
};
|
|
103
|
+
try {
|
|
104
|
+
const response = await fetch(url, {
|
|
105
|
+
...options,
|
|
106
|
+
headers
|
|
107
|
+
});
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
const errorData = await response.json().catch(() => ({}));
|
|
110
|
+
throw new Error(
|
|
111
|
+
errorData.message || `API request failed: ${response.statusText}`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
return await response.json();
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.error(`API Error (${endpoint}):`, error);
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get all supported chains
|
|
122
|
+
*/
|
|
123
|
+
async getChains() {
|
|
124
|
+
const response = await this.fetch("/api/chains");
|
|
125
|
+
return response.chains;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get all tokens for a specific chain (only Relay solver currencies)
|
|
129
|
+
*/
|
|
130
|
+
async getTokens(chainId) {
|
|
131
|
+
const response = await this.fetch(`/api/deposit/chains`);
|
|
132
|
+
const chain = response.chains.find((c) => c.chainId === chainId);
|
|
133
|
+
return chain?.tokens || [];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get destination chains and tokens reachable from source
|
|
137
|
+
*/
|
|
138
|
+
async getDestinations(chainId, tokenAddress) {
|
|
139
|
+
const response = await this.fetch(
|
|
140
|
+
`/api/destinations?chainId=${chainId}&tokenAddress=${encodeURIComponent(
|
|
141
|
+
tokenAddress
|
|
142
|
+
)}`
|
|
143
|
+
);
|
|
144
|
+
return response.destinations;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get source chains and tokens that can bridge to destination
|
|
148
|
+
*/
|
|
149
|
+
async getSources(destinationChainId, destinationTokenAddress) {
|
|
150
|
+
const response = await this.fetch(
|
|
151
|
+
`/api/deposit/sources?destinationChainId=${destinationChainId}&destinationAddress=${encodeURIComponent(
|
|
152
|
+
destinationTokenAddress
|
|
153
|
+
)}`
|
|
154
|
+
);
|
|
155
|
+
return response.sources;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get a deposit quote (generates deposit address and quote)
|
|
159
|
+
*/
|
|
160
|
+
async getDepositQuote(request) {
|
|
161
|
+
const normalizedRequest = {
|
|
162
|
+
...request,
|
|
163
|
+
originAsset: normalizeAddress(request.originAsset),
|
|
164
|
+
destinationAsset: normalizeAddress(request.destinationAsset)
|
|
165
|
+
};
|
|
166
|
+
const response = await this.fetch(
|
|
167
|
+
"/api/deposit/quote",
|
|
168
|
+
{
|
|
169
|
+
method: "POST",
|
|
170
|
+
body: JSON.stringify(normalizedRequest)
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
return response;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get deposit status by deposit request ID
|
|
177
|
+
*/
|
|
178
|
+
async getDepositStatus(depositRequestId) {
|
|
179
|
+
const response = await this.fetch(`/api/deposit/status?depositRequestId=${encodeURIComponent(depositRequestId)}`);
|
|
180
|
+
return response;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* List deposit requests for the API key
|
|
184
|
+
*/
|
|
185
|
+
async listDepositRequests(params) {
|
|
186
|
+
const queryParams = new URLSearchParams();
|
|
187
|
+
if (params?.limit) queryParams.append("limit", params.limit.toString());
|
|
188
|
+
if (params?.offset) queryParams.append("offset", params.offset.toString());
|
|
189
|
+
if (params?.status) queryParams.append("status", params.status);
|
|
190
|
+
const response = await this.fetch(`/api/deposit/requests?${queryParams}`);
|
|
191
|
+
return response.requests;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
function createAPIClient(apiKey, baseUrl) {
|
|
195
|
+
return new DextopusAPI(apiKey, baseUrl);
|
|
196
|
+
}
|
|
78
197
|
function createApiClient(options = {}) {
|
|
79
198
|
const rawBaseUrl = options.baseUrl || "https://swap-api.dextopus.com";
|
|
80
199
|
const trimmedBaseUrl = rawBaseUrl.replace(/\/+$/, "");
|
|
@@ -171,13 +290,50 @@ function createApiClient(options = {}) {
|
|
|
171
290
|
`${baseUrl}/api/deposit/validate-address`,
|
|
172
291
|
{ method: "POST", headers, body: JSON.stringify(payload) },
|
|
173
292
|
timeoutMs
|
|
174
|
-
)
|
|
293
|
+
),
|
|
294
|
+
/**
|
|
295
|
+
* Get all supported chains with their metadata
|
|
296
|
+
*/
|
|
297
|
+
getChains: () => requestJson(
|
|
298
|
+
fetcher,
|
|
299
|
+
`${baseUrl}/api/chains`,
|
|
300
|
+
{ method: "GET", headers },
|
|
301
|
+
timeoutMs
|
|
302
|
+
),
|
|
303
|
+
/**
|
|
304
|
+
* Get deposit chains with their Relay solver currencies/tokens
|
|
305
|
+
*/
|
|
306
|
+
depositChains: () => requestJson(
|
|
307
|
+
fetcher,
|
|
308
|
+
`${baseUrl}/api/deposit/chains`,
|
|
309
|
+
{ method: "GET", headers },
|
|
310
|
+
timeoutMs
|
|
311
|
+
),
|
|
312
|
+
/**
|
|
313
|
+
* List deposit requests for the API key
|
|
314
|
+
*/
|
|
315
|
+
listDepositRequests: (params) => {
|
|
316
|
+
const query = new URLSearchParams();
|
|
317
|
+
if (params?.limit) query.append("limit", String(params.limit));
|
|
318
|
+
if (params?.offset) query.append("offset", String(params.offset));
|
|
319
|
+
if (params?.status) query.append("status", params.status);
|
|
320
|
+
const queryString = query.toString();
|
|
321
|
+
return requestJson(
|
|
322
|
+
fetcher,
|
|
323
|
+
`${baseUrl}/api/deposit/requests${queryString ? `?${queryString}` : ""}`,
|
|
324
|
+
{ method: "GET", headers },
|
|
325
|
+
timeoutMs
|
|
326
|
+
);
|
|
327
|
+
}
|
|
175
328
|
};
|
|
176
329
|
}
|
|
177
330
|
// Annotate the CommonJS export names for ESM import in node:
|
|
178
331
|
0 && (module.exports = {
|
|
179
332
|
ApiError,
|
|
333
|
+
DextopusAPI,
|
|
334
|
+
createAPIClient,
|
|
180
335
|
createApiClient,
|
|
181
336
|
fromSmallestUnit,
|
|
337
|
+
normalizeAddress,
|
|
182
338
|
toSmallestUnit
|
|
183
339
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,14 @@ function buildHeaders(apiKey) {
|
|
|
14
14
|
if (apiKey) headers["x-api-key"] = apiKey;
|
|
15
15
|
return headers;
|
|
16
16
|
}
|
|
17
|
+
function normalizeAddress(address) {
|
|
18
|
+
const NATIVE_PLACEHOLDER = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
19
|
+
const RELAY_NATIVE = "0x0000000000000000000000000000000000000000";
|
|
20
|
+
if (address.toLowerCase() === NATIVE_PLACEHOLDER.toLowerCase()) {
|
|
21
|
+
return RELAY_NATIVE;
|
|
22
|
+
}
|
|
23
|
+
return address;
|
|
24
|
+
}
|
|
17
25
|
function toSmallestUnit(amount, decimals) {
|
|
18
26
|
const num = parseFloat(amount);
|
|
19
27
|
if (isNaN(num)) {
|
|
@@ -46,6 +54,114 @@ async function requestJson(fetcher, url, options, timeoutMs) {
|
|
|
46
54
|
clearTimeout(timeout);
|
|
47
55
|
}
|
|
48
56
|
}
|
|
57
|
+
var DextopusAPI = class {
|
|
58
|
+
baseUrl;
|
|
59
|
+
apiKey;
|
|
60
|
+
constructor(apiKey, baseUrl = "http://localhost:3000") {
|
|
61
|
+
this.apiKey = apiKey;
|
|
62
|
+
this.baseUrl = baseUrl;
|
|
63
|
+
}
|
|
64
|
+
async fetch(endpoint, options = {}) {
|
|
65
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
66
|
+
const headers = {
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
"x-api-key": this.apiKey,
|
|
69
|
+
...options.headers
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
const response = await fetch(url, {
|
|
73
|
+
...options,
|
|
74
|
+
headers
|
|
75
|
+
});
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
const errorData = await response.json().catch(() => ({}));
|
|
78
|
+
throw new Error(
|
|
79
|
+
errorData.message || `API request failed: ${response.statusText}`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return await response.json();
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error(`API Error (${endpoint}):`, error);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get all supported chains
|
|
90
|
+
*/
|
|
91
|
+
async getChains() {
|
|
92
|
+
const response = await this.fetch("/api/chains");
|
|
93
|
+
return response.chains;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get all tokens for a specific chain (only Relay solver currencies)
|
|
97
|
+
*/
|
|
98
|
+
async getTokens(chainId) {
|
|
99
|
+
const response = await this.fetch(`/api/deposit/chains`);
|
|
100
|
+
const chain = response.chains.find((c) => c.chainId === chainId);
|
|
101
|
+
return chain?.tokens || [];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get destination chains and tokens reachable from source
|
|
105
|
+
*/
|
|
106
|
+
async getDestinations(chainId, tokenAddress) {
|
|
107
|
+
const response = await this.fetch(
|
|
108
|
+
`/api/destinations?chainId=${chainId}&tokenAddress=${encodeURIComponent(
|
|
109
|
+
tokenAddress
|
|
110
|
+
)}`
|
|
111
|
+
);
|
|
112
|
+
return response.destinations;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get source chains and tokens that can bridge to destination
|
|
116
|
+
*/
|
|
117
|
+
async getSources(destinationChainId, destinationTokenAddress) {
|
|
118
|
+
const response = await this.fetch(
|
|
119
|
+
`/api/deposit/sources?destinationChainId=${destinationChainId}&destinationAddress=${encodeURIComponent(
|
|
120
|
+
destinationTokenAddress
|
|
121
|
+
)}`
|
|
122
|
+
);
|
|
123
|
+
return response.sources;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get a deposit quote (generates deposit address and quote)
|
|
127
|
+
*/
|
|
128
|
+
async getDepositQuote(request) {
|
|
129
|
+
const normalizedRequest = {
|
|
130
|
+
...request,
|
|
131
|
+
originAsset: normalizeAddress(request.originAsset),
|
|
132
|
+
destinationAsset: normalizeAddress(request.destinationAsset)
|
|
133
|
+
};
|
|
134
|
+
const response = await this.fetch(
|
|
135
|
+
"/api/deposit/quote",
|
|
136
|
+
{
|
|
137
|
+
method: "POST",
|
|
138
|
+
body: JSON.stringify(normalizedRequest)
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
return response;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get deposit status by deposit request ID
|
|
145
|
+
*/
|
|
146
|
+
async getDepositStatus(depositRequestId) {
|
|
147
|
+
const response = await this.fetch(`/api/deposit/status?depositRequestId=${encodeURIComponent(depositRequestId)}`);
|
|
148
|
+
return response;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* List deposit requests for the API key
|
|
152
|
+
*/
|
|
153
|
+
async listDepositRequests(params) {
|
|
154
|
+
const queryParams = new URLSearchParams();
|
|
155
|
+
if (params?.limit) queryParams.append("limit", params.limit.toString());
|
|
156
|
+
if (params?.offset) queryParams.append("offset", params.offset.toString());
|
|
157
|
+
if (params?.status) queryParams.append("status", params.status);
|
|
158
|
+
const response = await this.fetch(`/api/deposit/requests?${queryParams}`);
|
|
159
|
+
return response.requests;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
function createAPIClient(apiKey, baseUrl) {
|
|
163
|
+
return new DextopusAPI(apiKey, baseUrl);
|
|
164
|
+
}
|
|
49
165
|
function createApiClient(options = {}) {
|
|
50
166
|
const rawBaseUrl = options.baseUrl || "https://swap-api.dextopus.com";
|
|
51
167
|
const trimmedBaseUrl = rawBaseUrl.replace(/\/+$/, "");
|
|
@@ -142,12 +258,49 @@ function createApiClient(options = {}) {
|
|
|
142
258
|
`${baseUrl}/api/deposit/validate-address`,
|
|
143
259
|
{ method: "POST", headers, body: JSON.stringify(payload) },
|
|
144
260
|
timeoutMs
|
|
145
|
-
)
|
|
261
|
+
),
|
|
262
|
+
/**
|
|
263
|
+
* Get all supported chains with their metadata
|
|
264
|
+
*/
|
|
265
|
+
getChains: () => requestJson(
|
|
266
|
+
fetcher,
|
|
267
|
+
`${baseUrl}/api/chains`,
|
|
268
|
+
{ method: "GET", headers },
|
|
269
|
+
timeoutMs
|
|
270
|
+
),
|
|
271
|
+
/**
|
|
272
|
+
* Get deposit chains with their Relay solver currencies/tokens
|
|
273
|
+
*/
|
|
274
|
+
depositChains: () => requestJson(
|
|
275
|
+
fetcher,
|
|
276
|
+
`${baseUrl}/api/deposit/chains`,
|
|
277
|
+
{ method: "GET", headers },
|
|
278
|
+
timeoutMs
|
|
279
|
+
),
|
|
280
|
+
/**
|
|
281
|
+
* List deposit requests for the API key
|
|
282
|
+
*/
|
|
283
|
+
listDepositRequests: (params) => {
|
|
284
|
+
const query = new URLSearchParams();
|
|
285
|
+
if (params?.limit) query.append("limit", String(params.limit));
|
|
286
|
+
if (params?.offset) query.append("offset", String(params.offset));
|
|
287
|
+
if (params?.status) query.append("status", params.status);
|
|
288
|
+
const queryString = query.toString();
|
|
289
|
+
return requestJson(
|
|
290
|
+
fetcher,
|
|
291
|
+
`${baseUrl}/api/deposit/requests${queryString ? `?${queryString}` : ""}`,
|
|
292
|
+
{ method: "GET", headers },
|
|
293
|
+
timeoutMs
|
|
294
|
+
);
|
|
295
|
+
}
|
|
146
296
|
};
|
|
147
297
|
}
|
|
148
298
|
export {
|
|
149
299
|
ApiError,
|
|
300
|
+
DextopusAPI,
|
|
301
|
+
createAPIClient,
|
|
150
302
|
createApiClient,
|
|
151
303
|
fromSmallestUnit,
|
|
304
|
+
normalizeAddress,
|
|
152
305
|
toSmallestUnit
|
|
153
306
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dextopus/api-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Dextopus API SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -8,12 +8,15 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
+
"development": "./src/index.ts",
|
|
11
12
|
"import": "./dist/index.mjs",
|
|
12
|
-
"require": "./dist/index.js"
|
|
13
|
-
"development": "./src/index.ts"
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
17
20
|
"scripts": {
|
|
18
21
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
19
22
|
"test": "vitest run",
|