@agglayer/sdk 1.0.0-beta.17 → 1.0.0-beta.18
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 +494 -199
- package/dist/index.d.mts +40 -9
- package/dist/index.d.ts +40 -9
- package/dist/index.js +219 -113
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +218 -113
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -202,7 +202,8 @@ interface ProviderMetadata {
|
|
|
202
202
|
readonly transactionRequest?: unknown;
|
|
203
203
|
};
|
|
204
204
|
readonly agglayer?: {
|
|
205
|
-
readonly bridgeAddress: string |
|
|
205
|
+
readonly bridgeAddress: string | undefined;
|
|
206
|
+
readonly claimTransactionRequired: boolean | undefined;
|
|
206
207
|
};
|
|
207
208
|
readonly [key: string]: unknown;
|
|
208
209
|
}
|
|
@@ -235,7 +236,7 @@ interface Route {
|
|
|
235
236
|
readonly feeCosts: FeeCost[];
|
|
236
237
|
readonly gasCosts: GasCost[];
|
|
237
238
|
readonly steps: Step[];
|
|
238
|
-
readonly transactionRequest?: UnsignedTransaction;
|
|
239
|
+
readonly transactionRequest?: UnsignedTransaction | undefined;
|
|
239
240
|
readonly providerMetadata: ProviderMetadata;
|
|
240
241
|
readonly riskFactors: RiskFactors | null;
|
|
241
242
|
readonly createdAt: number;
|
|
@@ -258,7 +259,7 @@ interface RoutesRequestParams {
|
|
|
258
259
|
readonly fromTokenAddress: string;
|
|
259
260
|
readonly toTokenAddress: string;
|
|
260
261
|
readonly amount: string;
|
|
261
|
-
readonly fromAddress
|
|
262
|
+
readonly fromAddress?: string;
|
|
262
263
|
readonly toAddress?: string;
|
|
263
264
|
readonly slippage?: number;
|
|
264
265
|
readonly preferences?: RoutePreferences;
|
|
@@ -495,9 +496,9 @@ declare const SDK_MODES: {
|
|
|
495
496
|
type SDKMode = (typeof SDK_MODES)[keyof typeof SDK_MODES];
|
|
496
497
|
|
|
497
498
|
interface SDKConfig {
|
|
498
|
-
mode
|
|
499
|
-
core
|
|
500
|
-
native
|
|
499
|
+
mode?: SDKMode[];
|
|
500
|
+
core?: CoreConfig;
|
|
501
|
+
native?: NativeConfig;
|
|
501
502
|
}
|
|
502
503
|
|
|
503
504
|
/**
|
|
@@ -778,7 +779,7 @@ declare class NativeClient {
|
|
|
778
779
|
declare class CoreClient {
|
|
779
780
|
private config;
|
|
780
781
|
private arcApiService;
|
|
781
|
-
constructor(config
|
|
782
|
+
constructor(config?: CoreConfig);
|
|
782
783
|
/**
|
|
783
784
|
* Generic pagination helper for chains API calls (limit and offset based pagination)
|
|
784
785
|
* Handles automatic pagination to fetch all available data
|
|
@@ -836,6 +837,36 @@ declare class CoreClient {
|
|
|
836
837
|
getTransactions(transactionsRequestQueryParams: TransactionsRequestQueryParams): Promise<TransactionsResponse>;
|
|
837
838
|
}
|
|
838
839
|
|
|
840
|
+
/**
|
|
841
|
+
* API Error Class
|
|
842
|
+
*
|
|
843
|
+
* Custom error class to preserve API error details
|
|
844
|
+
*/
|
|
845
|
+
|
|
846
|
+
declare class ApiError extends Error {
|
|
847
|
+
readonly code: number;
|
|
848
|
+
readonly name: string;
|
|
849
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
850
|
+
constructor(errorResponse: ErrorResponse);
|
|
851
|
+
/**
|
|
852
|
+
* Create API error from error response
|
|
853
|
+
*/
|
|
854
|
+
static fromErrorResponse(errorResponse: ErrorResponse): ApiError;
|
|
855
|
+
/**
|
|
856
|
+
* Create fallback error when API completely fails
|
|
857
|
+
*/
|
|
858
|
+
static createFallbackError(originalError: Error, operation: string): ApiError;
|
|
859
|
+
/**
|
|
860
|
+
* Convert to plain object for serialization
|
|
861
|
+
*/
|
|
862
|
+
toJSON(): {
|
|
863
|
+
name: string;
|
|
864
|
+
message: string;
|
|
865
|
+
code: number;
|
|
866
|
+
details: Record<string, unknown> | undefined;
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
|
|
839
870
|
/**
|
|
840
871
|
* AggLayer SDK - Main SDK
|
|
841
872
|
*
|
|
@@ -846,7 +877,7 @@ declare class AggLayerSDK {
|
|
|
846
877
|
private config;
|
|
847
878
|
private core?;
|
|
848
879
|
private native?;
|
|
849
|
-
constructor(config
|
|
880
|
+
constructor(config?: SDKConfig);
|
|
850
881
|
/**
|
|
851
882
|
* Get core submodule
|
|
852
883
|
*/
|
|
@@ -857,4 +888,4 @@ declare class AggLayerSDK {
|
|
|
857
888
|
getNative(): NativeClient;
|
|
858
889
|
}
|
|
859
890
|
|
|
860
|
-
export { AggLayerSDK, type ApiResponse, type BaseContractConfig, type BridgeAssetParams, type BridgeConfig, type BridgeMessageParams, type BridgeOptions, type BuildClaimTransactionRequestParam, type BuildClaimTransactionResponse, type BuildTransactionRequestBody, type BuildTransactionResponse, type ChainConfig, type ChainsQueryParams, type ChainsResponse, type ClaimAssetParams, type ClaimMessageParams, type CoreConfig, type CursorPagination, type CustomChainConfig, type ERC20Config, type ErrorResponse, type FeeCost, type GasCost, type IChain, type IsClaimedParams, type NativeConfig, type OffsetPagination, type OriginTokenInfoParams, type Pagination, type PrecalculatedWrapperParams, type ProviderMetadata, type RiskFactors, type RiskLevel, type Route, type RoutePreferences, type RouteStep, type RoutesRequestParams, type RoutesResponse, type SDKConfig, type SDKMode, SDK_MODES, type Step, type StepAction, type StepEstimate, type StepType, type SuccessResponse, type TokenInfo, type TokenReference, type ToolDetails, type Transaction, type TransactionParams, type TransactionsRequestQueryParams, type TransactionsResponse, type WrappedTokenParams };
|
|
891
|
+
export { AggLayerSDK, ApiError, type ApiResponse, type BaseContractConfig, type BridgeAssetParams, type BridgeConfig, type BridgeMessageParams, type BridgeOptions, type BuildClaimTransactionRequestParam, type BuildClaimTransactionResponse, type BuildTransactionRequestBody, type BuildTransactionResponse, type ChainConfig, type ChainsQueryParams, type ChainsResponse, type ClaimAssetParams, type ClaimMessageParams, type CoreConfig, type CursorPagination, type CustomChainConfig, type ERC20Config, type ErrorResponse, type FeeCost, type GasCost, type IChain, type IsClaimedParams, type NativeConfig, type OffsetPagination, type OriginTokenInfoParams, type Pagination, type PrecalculatedWrapperParams, type ProviderMetadata, type RiskFactors, type RiskLevel, type Route, type RoutePreferences, type RouteStep, type RoutesRequestParams, type RoutesResponse, type SDKConfig, type SDKMode, SDK_MODES, type Step, type StepAction, type StepEstimate, type StepType, type SuccessResponse, type TokenInfo, type TokenReference, type ToolDetails, type Transaction, type TransactionParams, type TransactionsRequestQueryParams, type TransactionsResponse, type WrappedTokenParams };
|
package/dist/index.d.ts
CHANGED
|
@@ -202,7 +202,8 @@ interface ProviderMetadata {
|
|
|
202
202
|
readonly transactionRequest?: unknown;
|
|
203
203
|
};
|
|
204
204
|
readonly agglayer?: {
|
|
205
|
-
readonly bridgeAddress: string |
|
|
205
|
+
readonly bridgeAddress: string | undefined;
|
|
206
|
+
readonly claimTransactionRequired: boolean | undefined;
|
|
206
207
|
};
|
|
207
208
|
readonly [key: string]: unknown;
|
|
208
209
|
}
|
|
@@ -235,7 +236,7 @@ interface Route {
|
|
|
235
236
|
readonly feeCosts: FeeCost[];
|
|
236
237
|
readonly gasCosts: GasCost[];
|
|
237
238
|
readonly steps: Step[];
|
|
238
|
-
readonly transactionRequest?: UnsignedTransaction;
|
|
239
|
+
readonly transactionRequest?: UnsignedTransaction | undefined;
|
|
239
240
|
readonly providerMetadata: ProviderMetadata;
|
|
240
241
|
readonly riskFactors: RiskFactors | null;
|
|
241
242
|
readonly createdAt: number;
|
|
@@ -258,7 +259,7 @@ interface RoutesRequestParams {
|
|
|
258
259
|
readonly fromTokenAddress: string;
|
|
259
260
|
readonly toTokenAddress: string;
|
|
260
261
|
readonly amount: string;
|
|
261
|
-
readonly fromAddress
|
|
262
|
+
readonly fromAddress?: string;
|
|
262
263
|
readonly toAddress?: string;
|
|
263
264
|
readonly slippage?: number;
|
|
264
265
|
readonly preferences?: RoutePreferences;
|
|
@@ -495,9 +496,9 @@ declare const SDK_MODES: {
|
|
|
495
496
|
type SDKMode = (typeof SDK_MODES)[keyof typeof SDK_MODES];
|
|
496
497
|
|
|
497
498
|
interface SDKConfig {
|
|
498
|
-
mode
|
|
499
|
-
core
|
|
500
|
-
native
|
|
499
|
+
mode?: SDKMode[];
|
|
500
|
+
core?: CoreConfig;
|
|
501
|
+
native?: NativeConfig;
|
|
501
502
|
}
|
|
502
503
|
|
|
503
504
|
/**
|
|
@@ -778,7 +779,7 @@ declare class NativeClient {
|
|
|
778
779
|
declare class CoreClient {
|
|
779
780
|
private config;
|
|
780
781
|
private arcApiService;
|
|
781
|
-
constructor(config
|
|
782
|
+
constructor(config?: CoreConfig);
|
|
782
783
|
/**
|
|
783
784
|
* Generic pagination helper for chains API calls (limit and offset based pagination)
|
|
784
785
|
* Handles automatic pagination to fetch all available data
|
|
@@ -836,6 +837,36 @@ declare class CoreClient {
|
|
|
836
837
|
getTransactions(transactionsRequestQueryParams: TransactionsRequestQueryParams): Promise<TransactionsResponse>;
|
|
837
838
|
}
|
|
838
839
|
|
|
840
|
+
/**
|
|
841
|
+
* API Error Class
|
|
842
|
+
*
|
|
843
|
+
* Custom error class to preserve API error details
|
|
844
|
+
*/
|
|
845
|
+
|
|
846
|
+
declare class ApiError extends Error {
|
|
847
|
+
readonly code: number;
|
|
848
|
+
readonly name: string;
|
|
849
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
850
|
+
constructor(errorResponse: ErrorResponse);
|
|
851
|
+
/**
|
|
852
|
+
* Create API error from error response
|
|
853
|
+
*/
|
|
854
|
+
static fromErrorResponse(errorResponse: ErrorResponse): ApiError;
|
|
855
|
+
/**
|
|
856
|
+
* Create fallback error when API completely fails
|
|
857
|
+
*/
|
|
858
|
+
static createFallbackError(originalError: Error, operation: string): ApiError;
|
|
859
|
+
/**
|
|
860
|
+
* Convert to plain object for serialization
|
|
861
|
+
*/
|
|
862
|
+
toJSON(): {
|
|
863
|
+
name: string;
|
|
864
|
+
message: string;
|
|
865
|
+
code: number;
|
|
866
|
+
details: Record<string, unknown> | undefined;
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
|
|
839
870
|
/**
|
|
840
871
|
* AggLayer SDK - Main SDK
|
|
841
872
|
*
|
|
@@ -846,7 +877,7 @@ declare class AggLayerSDK {
|
|
|
846
877
|
private config;
|
|
847
878
|
private core?;
|
|
848
879
|
private native?;
|
|
849
|
-
constructor(config
|
|
880
|
+
constructor(config?: SDKConfig);
|
|
850
881
|
/**
|
|
851
882
|
* Get core submodule
|
|
852
883
|
*/
|
|
@@ -857,4 +888,4 @@ declare class AggLayerSDK {
|
|
|
857
888
|
getNative(): NativeClient;
|
|
858
889
|
}
|
|
859
890
|
|
|
860
|
-
export { AggLayerSDK, type ApiResponse, type BaseContractConfig, type BridgeAssetParams, type BridgeConfig, type BridgeMessageParams, type BridgeOptions, type BuildClaimTransactionRequestParam, type BuildClaimTransactionResponse, type BuildTransactionRequestBody, type BuildTransactionResponse, type ChainConfig, type ChainsQueryParams, type ChainsResponse, type ClaimAssetParams, type ClaimMessageParams, type CoreConfig, type CursorPagination, type CustomChainConfig, type ERC20Config, type ErrorResponse, type FeeCost, type GasCost, type IChain, type IsClaimedParams, type NativeConfig, type OffsetPagination, type OriginTokenInfoParams, type Pagination, type PrecalculatedWrapperParams, type ProviderMetadata, type RiskFactors, type RiskLevel, type Route, type RoutePreferences, type RouteStep, type RoutesRequestParams, type RoutesResponse, type SDKConfig, type SDKMode, SDK_MODES, type Step, type StepAction, type StepEstimate, type StepType, type SuccessResponse, type TokenInfo, type TokenReference, type ToolDetails, type Transaction, type TransactionParams, type TransactionsRequestQueryParams, type TransactionsResponse, type WrappedTokenParams };
|
|
891
|
+
export { AggLayerSDK, ApiError, type ApiResponse, type BaseContractConfig, type BridgeAssetParams, type BridgeConfig, type BridgeMessageParams, type BridgeOptions, type BuildClaimTransactionRequestParam, type BuildClaimTransactionResponse, type BuildTransactionRequestBody, type BuildTransactionResponse, type ChainConfig, type ChainsQueryParams, type ChainsResponse, type ClaimAssetParams, type ClaimMessageParams, type CoreConfig, type CursorPagination, type CustomChainConfig, type ERC20Config, type ErrorResponse, type FeeCost, type GasCost, type IChain, type IsClaimedParams, type NativeConfig, type OffsetPagination, type OriginTokenInfoParams, type Pagination, type PrecalculatedWrapperParams, type ProviderMetadata, type RiskFactors, type RiskLevel, type Route, type RoutePreferences, type RouteStep, type RoutesRequestParams, type RoutesResponse, type SDKConfig, type SDKMode, SDK_MODES, type Step, type StepAction, type StepEstimate, type StepType, type SuccessResponse, type TokenInfo, type TokenReference, type ToolDetails, type Transaction, type TransactionParams, type TransactionsRequestQueryParams, type TransactionsResponse, type WrappedTokenParams };
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
AggLayerSDK: () => AggLayerSDK,
|
|
24
|
+
ApiError: () => ApiError,
|
|
24
25
|
SDK_MODES: () => SDK_MODES
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -38,7 +39,33 @@ var ChainRegistry = class _ChainRegistry {
|
|
|
38
39
|
}
|
|
39
40
|
return _ChainRegistry.instance;
|
|
40
41
|
}
|
|
42
|
+
// DEV: if adding new default chains, also update README.md
|
|
41
43
|
initializeDefaultChains() {
|
|
44
|
+
this.registerChain({
|
|
45
|
+
chainId: 1,
|
|
46
|
+
networkId: 0,
|
|
47
|
+
name: "Ethereum",
|
|
48
|
+
rpcUrl: "https://eth.llamarpc.com",
|
|
49
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
50
|
+
blockExplorer: { name: "Etherscan", url: "https://etherscan.io" },
|
|
51
|
+
bridgeAddress: "",
|
|
52
|
+
proofApiUrl: "https://api-gateway.polygon.technology/api/v3/proof/mainnet/",
|
|
53
|
+
isTestnet: false
|
|
54
|
+
});
|
|
55
|
+
this.registerChain({
|
|
56
|
+
chainId: 747474,
|
|
57
|
+
networkId: 20,
|
|
58
|
+
name: "Katana",
|
|
59
|
+
rpcUrl: "https://rpc.katana.network",
|
|
60
|
+
nativeCurrency: { name: "Ethereum", symbol: "ETH", decimals: 18 },
|
|
61
|
+
blockExplorer: {
|
|
62
|
+
name: "Katana Explorer",
|
|
63
|
+
url: "https://katanascan.com"
|
|
64
|
+
},
|
|
65
|
+
bridgeAddress: "",
|
|
66
|
+
proofApiUrl: "https://api-gateway.polygon.technology/api/v3/proof/mainnet/",
|
|
67
|
+
isTestnet: false
|
|
68
|
+
});
|
|
42
69
|
this.registerChain({
|
|
43
70
|
chainId: 11155111,
|
|
44
71
|
networkId: 0,
|
|
@@ -53,20 +80,6 @@ var ChainRegistry = class _ChainRegistry {
|
|
|
53
80
|
proofApiUrl: "https://api-gateway.polygon.technology/api/v3/proof/testnet/",
|
|
54
81
|
isTestnet: true
|
|
55
82
|
});
|
|
56
|
-
this.registerChain({
|
|
57
|
-
chainId: 2442,
|
|
58
|
-
networkId: 1,
|
|
59
|
-
name: "Polygon Cardona",
|
|
60
|
-
rpcUrl: "https://rpc.cardona.zkevm-rpc.com",
|
|
61
|
-
nativeCurrency: { name: "Ethereum", symbol: "ETH", decimals: 18 },
|
|
62
|
-
blockExplorer: {
|
|
63
|
-
name: "Cardona PolygonScan",
|
|
64
|
-
url: "https://cardona-zkevm.polygonscan.com"
|
|
65
|
-
},
|
|
66
|
-
bridgeAddress: "0x528e26b25a34a4A5d0dbDa1d57D318153d2ED582",
|
|
67
|
-
proofApiUrl: "https://api-gateway.polygon.technology/api/v3/proof/testnet/",
|
|
68
|
-
isTestnet: true
|
|
69
|
-
});
|
|
70
83
|
}
|
|
71
84
|
/**
|
|
72
85
|
* Register a new chain
|
|
@@ -1410,14 +1423,16 @@ var ERC20 = class extends BaseContract {
|
|
|
1410
1423
|
var import_viem6 = require("viem");
|
|
1411
1424
|
|
|
1412
1425
|
// src/constants.ts
|
|
1413
|
-
var
|
|
1414
|
-
|
|
1415
|
-
CARDONA: 2442
|
|
1416
|
-
};
|
|
1417
|
-
var DEFAULT_NETWORK = NETWORKS.SEPOLIA;
|
|
1426
|
+
var ARC_API_BASE_URL = "https://arc-api.polygon.technology";
|
|
1427
|
+
var ARC_API_DEFAULT_TIMEOUT = 3e4;
|
|
1418
1428
|
var DEFAULT_CHAINS_PER_PAGE = 100;
|
|
1419
1429
|
var DEFAULT_CHAINS_WITH_TOKENS_PER_PAGE = 1;
|
|
1420
1430
|
var MAX_TRANSACTIONS_PER_PAGE = 100;
|
|
1431
|
+
var NETWORKS = {
|
|
1432
|
+
ETHEREUM: 1,
|
|
1433
|
+
KATANA: 747474
|
|
1434
|
+
};
|
|
1435
|
+
var DEFAULT_NETWORK = NETWORKS.ETHEREUM;
|
|
1421
1436
|
|
|
1422
1437
|
// src/native/index.ts
|
|
1423
1438
|
var NativeClient = class {
|
|
@@ -1607,9 +1622,6 @@ var HttpClient = class {
|
|
|
1607
1622
|
signal: controller.signal
|
|
1608
1623
|
});
|
|
1609
1624
|
clearTimeout(timeoutId);
|
|
1610
|
-
if (!response.ok) {
|
|
1611
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
1612
|
-
}
|
|
1613
1625
|
let data;
|
|
1614
1626
|
const contentType = response.headers.get("content-type");
|
|
1615
1627
|
if (contentType?.includes("application/json")) {
|
|
@@ -1617,6 +1629,12 @@ var HttpClient = class {
|
|
|
1617
1629
|
} else {
|
|
1618
1630
|
data = await response.text();
|
|
1619
1631
|
}
|
|
1632
|
+
if (!response.ok) {
|
|
1633
|
+
if (contentType?.includes("application/json")) {
|
|
1634
|
+
} else {
|
|
1635
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1620
1638
|
return {
|
|
1621
1639
|
data,
|
|
1622
1640
|
status: response.status,
|
|
@@ -1705,7 +1723,7 @@ var ArcApiService = class {
|
|
|
1705
1723
|
);
|
|
1706
1724
|
}
|
|
1707
1725
|
async buildClaimTransaction(sourceNetworkId, depositCount) {
|
|
1708
|
-
return this.httpClient.
|
|
1726
|
+
return this.httpClient.post("/routes/build-transaction-for-claim", {
|
|
1709
1727
|
sourceNetworkId,
|
|
1710
1728
|
depositCount
|
|
1711
1729
|
});
|
|
@@ -1718,20 +1736,63 @@ var ArcApiService = class {
|
|
|
1718
1736
|
}
|
|
1719
1737
|
};
|
|
1720
1738
|
|
|
1739
|
+
// src/core/utils/apiError.ts
|
|
1740
|
+
var ApiError = class _ApiError extends Error {
|
|
1741
|
+
constructor(errorResponse) {
|
|
1742
|
+
super(errorResponse.message);
|
|
1743
|
+
this.name = errorResponse.name;
|
|
1744
|
+
this.code = errorResponse.code;
|
|
1745
|
+
this.details = errorResponse.details;
|
|
1746
|
+
if (Error.captureStackTrace) {
|
|
1747
|
+
Error.captureStackTrace(this, _ApiError);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Create API error from error response
|
|
1752
|
+
*/
|
|
1753
|
+
static fromErrorResponse(errorResponse) {
|
|
1754
|
+
return new _ApiError(errorResponse);
|
|
1755
|
+
}
|
|
1756
|
+
/**
|
|
1757
|
+
* Create fallback error when API completely fails
|
|
1758
|
+
*/
|
|
1759
|
+
static createFallbackError(originalError, operation) {
|
|
1760
|
+
return new _ApiError({
|
|
1761
|
+
status: "error",
|
|
1762
|
+
message: `${operation} failed: ${originalError.message}`,
|
|
1763
|
+
name: "ApiConnectionError",
|
|
1764
|
+
code: 500,
|
|
1765
|
+
details: {
|
|
1766
|
+
originalError: originalError.message,
|
|
1767
|
+
operation
|
|
1768
|
+
}
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* Convert to plain object for serialization
|
|
1773
|
+
*/
|
|
1774
|
+
toJSON() {
|
|
1775
|
+
return {
|
|
1776
|
+
name: this.name,
|
|
1777
|
+
message: this.message,
|
|
1778
|
+
code: this.code,
|
|
1779
|
+
details: this.details
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
};
|
|
1783
|
+
|
|
1721
1784
|
// src/core/index.ts
|
|
1722
1785
|
var CoreClient = class {
|
|
1723
1786
|
constructor(config) {
|
|
1724
|
-
this.config =
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
throw new Error("API base URL is required");
|
|
1730
|
-
}
|
|
1787
|
+
this.config = {
|
|
1788
|
+
...config,
|
|
1789
|
+
apiBaseUrl: config?.apiBaseUrl || ARC_API_BASE_URL,
|
|
1790
|
+
apiTimeout: config?.apiTimeout || ARC_API_DEFAULT_TIMEOUT
|
|
1791
|
+
};
|
|
1731
1792
|
const { apiBaseUrl, apiTimeout } = this.config;
|
|
1732
1793
|
this.arcApiService = new ArcApiService({
|
|
1733
|
-
baseUrl: apiBaseUrl,
|
|
1734
|
-
timeout: apiTimeout
|
|
1794
|
+
baseUrl: apiBaseUrl || ARC_API_BASE_URL,
|
|
1795
|
+
timeout: apiTimeout || ARC_API_DEFAULT_TIMEOUT
|
|
1735
1796
|
});
|
|
1736
1797
|
}
|
|
1737
1798
|
/**
|
|
@@ -1741,57 +1802,64 @@ var CoreClient = class {
|
|
|
1741
1802
|
* @param pageSize - Number of items per page (defaults to DEFAULT_CHAINS_PER_PAGE)
|
|
1742
1803
|
*/
|
|
1743
1804
|
async getAllChainsPaginated(params, pageSize = DEFAULT_CHAINS_PER_PAGE) {
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1805
|
+
try {
|
|
1806
|
+
const firstResponse = await this.arcApiService.chains({
|
|
1807
|
+
...params,
|
|
1808
|
+
limit: pageSize
|
|
1809
|
+
});
|
|
1810
|
+
if (firstResponse.data.status !== "success") {
|
|
1811
|
+
throw ApiError.fromErrorResponse(firstResponse.data);
|
|
1812
|
+
}
|
|
1813
|
+
const firstPageData = firstResponse.data.data;
|
|
1814
|
+
const pagination = firstResponse.data.pagination;
|
|
1815
|
+
const firstPageChains = Array.isArray(firstPageData) ? firstPageData : [];
|
|
1816
|
+
if (!pagination?.total || pagination.total <= pageSize) {
|
|
1817
|
+
return {
|
|
1818
|
+
chains: firstPageChains
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
const totalPages = Math.ceil(pagination.total / pageSize);
|
|
1822
|
+
const remainingPages = totalPages - 1;
|
|
1823
|
+
if (remainingPages === 0) {
|
|
1824
|
+
return {
|
|
1825
|
+
chains: firstPageChains
|
|
1826
|
+
};
|
|
1827
|
+
}
|
|
1828
|
+
const remainingPagePromises = Array.from(
|
|
1829
|
+
{ length: remainingPages },
|
|
1830
|
+
(_, index) => {
|
|
1831
|
+
const offset = (index + 1) * pageSize;
|
|
1832
|
+
return this.arcApiService.chains({
|
|
1833
|
+
...params,
|
|
1834
|
+
limit: pageSize,
|
|
1835
|
+
offset
|
|
1836
|
+
});
|
|
1837
|
+
}
|
|
1838
|
+
);
|
|
1839
|
+
const remainingResponses = await Promise.all(remainingPagePromises);
|
|
1840
|
+
for (const response of remainingResponses) {
|
|
1841
|
+
if (response.data.status !== "success") {
|
|
1842
|
+
throw ApiError.fromErrorResponse(response.data);
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
const allChains = [
|
|
1846
|
+
...firstPageChains,
|
|
1847
|
+
...remainingResponses.flatMap((response) => {
|
|
1848
|
+
if (response.data.status === "success") {
|
|
1849
|
+
return Array.isArray(response.data.data) ? response.data.data : [];
|
|
1850
|
+
}
|
|
1851
|
+
return [];
|
|
1852
|
+
})
|
|
1853
|
+
];
|
|
1762
1854
|
return {
|
|
1763
|
-
chains:
|
|
1855
|
+
chains: allChains
|
|
1764
1856
|
};
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
(_, index) => {
|
|
1769
|
-
const offset = (index + 1) * pageSize;
|
|
1770
|
-
return this.arcApiService.chains({
|
|
1771
|
-
...params,
|
|
1772
|
-
limit: pageSize,
|
|
1773
|
-
offset
|
|
1774
|
-
});
|
|
1775
|
-
}
|
|
1776
|
-
);
|
|
1777
|
-
const remainingResponses = await Promise.all(remainingPagePromises);
|
|
1778
|
-
for (const response of remainingResponses) {
|
|
1779
|
-
if (response.data.status !== "success") {
|
|
1780
|
-
throw new Error(response.data.message);
|
|
1857
|
+
} catch (error) {
|
|
1858
|
+
if (error instanceof ApiError) {
|
|
1859
|
+
throw error;
|
|
1781
1860
|
}
|
|
1861
|
+
throw ApiError.createFallbackError(error, "Get chains metadata");
|
|
1782
1862
|
}
|
|
1783
|
-
const allChains = [
|
|
1784
|
-
...firstPageChains,
|
|
1785
|
-
...remainingResponses.flatMap((response) => {
|
|
1786
|
-
if (response.data.status === "success") {
|
|
1787
|
-
return Array.isArray(response.data.data) ? response.data.data : [];
|
|
1788
|
-
}
|
|
1789
|
-
return [];
|
|
1790
|
-
})
|
|
1791
|
-
];
|
|
1792
|
-
return {
|
|
1793
|
-
chains: allChains
|
|
1794
|
-
};
|
|
1795
1863
|
}
|
|
1796
1864
|
/**
|
|
1797
1865
|
* Get all chains metadata from AggLayer API
|
|
@@ -1835,11 +1903,18 @@ var CoreClient = class {
|
|
|
1835
1903
|
* Get all routes from AggLayer API
|
|
1836
1904
|
*/
|
|
1837
1905
|
async getRoutes(routesRequestParams) {
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1906
|
+
try {
|
|
1907
|
+
const response = await this.arcApiService.routes(routesRequestParams);
|
|
1908
|
+
if (response.data.status === "success") {
|
|
1909
|
+
return response.data.data;
|
|
1910
|
+
}
|
|
1911
|
+
throw ApiError.fromErrorResponse(response.data);
|
|
1912
|
+
} catch (error) {
|
|
1913
|
+
if (error instanceof ApiError) {
|
|
1914
|
+
throw error;
|
|
1915
|
+
}
|
|
1916
|
+
throw ApiError.createFallbackError(error, "Get routes");
|
|
1841
1917
|
}
|
|
1842
|
-
throw new Error(response.data.message);
|
|
1843
1918
|
}
|
|
1844
1919
|
/**
|
|
1845
1920
|
* Get calldata from a route
|
|
@@ -1851,13 +1926,28 @@ var CoreClient = class {
|
|
|
1851
1926
|
return route.transactionRequest;
|
|
1852
1927
|
}
|
|
1853
1928
|
if (route.steps.length === 0 || !route.steps[0]) {
|
|
1854
|
-
throw
|
|
1929
|
+
throw ApiError.createFallbackError(
|
|
1930
|
+
new Error("Route has no steps to build transaction from"),
|
|
1931
|
+
"Get unsigned transaction"
|
|
1932
|
+
);
|
|
1855
1933
|
}
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1934
|
+
try {
|
|
1935
|
+
const response = await this.arcApiService.buildTransaction(
|
|
1936
|
+
route.steps[0]
|
|
1937
|
+
);
|
|
1938
|
+
if (response.data.status === "success") {
|
|
1939
|
+
return response.data.data;
|
|
1940
|
+
}
|
|
1941
|
+
throw ApiError.fromErrorResponse(response.data);
|
|
1942
|
+
} catch (error) {
|
|
1943
|
+
if (error instanceof ApiError) {
|
|
1944
|
+
throw error;
|
|
1945
|
+
}
|
|
1946
|
+
throw ApiError.createFallbackError(
|
|
1947
|
+
error,
|
|
1948
|
+
"Get unsigned transaction"
|
|
1949
|
+
);
|
|
1859
1950
|
}
|
|
1860
|
-
throw new Error(response.data.message);
|
|
1861
1951
|
}
|
|
1862
1952
|
/**
|
|
1863
1953
|
* Get calldata for claim step
|
|
@@ -1869,53 +1959,68 @@ var CoreClient = class {
|
|
|
1869
1959
|
* @param depositCount - The deposit count associated with the transfer.
|
|
1870
1960
|
*/
|
|
1871
1961
|
async getClaimUnsignedTransaction(buildClaimTxParams) {
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1962
|
+
try {
|
|
1963
|
+
const response = await this.arcApiService.buildClaimTransaction(
|
|
1964
|
+
buildClaimTxParams.sourceNetworkId,
|
|
1965
|
+
buildClaimTxParams.depositCount
|
|
1966
|
+
);
|
|
1967
|
+
if (response.data.status === "success") {
|
|
1968
|
+
return response.data.data;
|
|
1969
|
+
}
|
|
1970
|
+
throw ApiError.fromErrorResponse(response.data);
|
|
1971
|
+
} catch (error) {
|
|
1972
|
+
if (error instanceof ApiError) {
|
|
1973
|
+
throw error;
|
|
1974
|
+
}
|
|
1975
|
+
throw ApiError.createFallbackError(
|
|
1976
|
+
error,
|
|
1977
|
+
"Get claim unsigned transaction"
|
|
1978
|
+
);
|
|
1878
1979
|
}
|
|
1879
|
-
throw new Error(response.data.message);
|
|
1880
1980
|
}
|
|
1881
1981
|
/**
|
|
1882
1982
|
* Get all transactions via web sockets
|
|
1883
1983
|
*/
|
|
1884
1984
|
async getTransactions(transactionsRequestQueryParams) {
|
|
1885
1985
|
if (transactionsRequestQueryParams.limit && transactionsRequestQueryParams.limit > MAX_TRANSACTIONS_PER_PAGE) {
|
|
1886
|
-
throw
|
|
1887
|
-
`Limit cannot be greater than ${MAX_TRANSACTIONS_PER_PAGE}`
|
|
1986
|
+
throw ApiError.createFallbackError(
|
|
1987
|
+
new Error(`Limit cannot be greater than ${MAX_TRANSACTIONS_PER_PAGE}`),
|
|
1988
|
+
"Get transactions"
|
|
1888
1989
|
);
|
|
1889
1990
|
}
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1991
|
+
try {
|
|
1992
|
+
const response = await this.arcApiService.transactions(
|
|
1993
|
+
transactionsRequestQueryParams
|
|
1994
|
+
);
|
|
1995
|
+
if (response.data.status === "success") {
|
|
1996
|
+
return response.data.data;
|
|
1997
|
+
}
|
|
1998
|
+
throw ApiError.fromErrorResponse(response.data);
|
|
1999
|
+
} catch (error) {
|
|
2000
|
+
if (error instanceof ApiError) {
|
|
2001
|
+
throw error;
|
|
2002
|
+
}
|
|
2003
|
+
throw ApiError.createFallbackError(error, "Get transactions");
|
|
1895
2004
|
}
|
|
1896
|
-
throw new Error(response.data.message);
|
|
1897
2005
|
}
|
|
1898
2006
|
};
|
|
1899
2007
|
|
|
1900
2008
|
// src/index.ts
|
|
2009
|
+
var defaultConfig = {
|
|
2010
|
+
mode: [SDK_MODES.CORE]
|
|
2011
|
+
};
|
|
1901
2012
|
var AggLayerSDK = class {
|
|
1902
|
-
constructor(config) {
|
|
2013
|
+
constructor(config = defaultConfig) {
|
|
1903
2014
|
this.config = config;
|
|
1904
2015
|
if (!config.mode || config.mode && config.mode.length === 0) {
|
|
1905
2016
|
this.config.mode = ["CORE"];
|
|
1906
2017
|
}
|
|
1907
|
-
if (config.mode
|
|
1908
|
-
|
|
1909
|
-
throw new Error("Core config is required");
|
|
1910
|
-
}
|
|
1911
|
-
this.core = new CoreClient(this.config.core);
|
|
2018
|
+
if (this.config.mode?.includes(SDK_MODES.CORE)) {
|
|
2019
|
+
this.core = new CoreClient(this.config?.core);
|
|
1912
2020
|
}
|
|
1913
2021
|
if (this.config.mode?.includes(SDK_MODES.NATIVE)) {
|
|
1914
|
-
if (!this.config.native) {
|
|
1915
|
-
throw new Error("NATIVE config is required");
|
|
1916
|
-
}
|
|
1917
2022
|
const nativeConfig = {
|
|
1918
|
-
defaultNetwork: this.config.native?.defaultNetwork
|
|
2023
|
+
defaultNetwork: this.config.native?.defaultNetwork ?? DEFAULT_NETWORK,
|
|
1919
2024
|
...this.config.native?.chains && {
|
|
1920
2025
|
chains: this.config.native.chains
|
|
1921
2026
|
},
|
|
@@ -1950,6 +2055,7 @@ var AggLayerSDK = class {
|
|
|
1950
2055
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1951
2056
|
0 && (module.exports = {
|
|
1952
2057
|
AggLayerSDK,
|
|
2058
|
+
ApiError,
|
|
1953
2059
|
SDK_MODES
|
|
1954
2060
|
});
|
|
1955
2061
|
//# sourceMappingURL=index.js.map
|