@bolt-liquidity-hq/core 0.1.0-beta.10

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.
@@ -0,0 +1,920 @@
1
+ type Address = string;
2
+ type AssetPairString = string;
3
+ type Timestamp = string;
4
+ type Duration = {
5
+ secs: number;
6
+ nanos: number;
7
+ };
8
+ type Coin = {
9
+ denom: string;
10
+ amount: string;
11
+ };
12
+
13
+ type Environment = 'mainnet' | 'testnet';
14
+ type Asset = {
15
+ symbol: string;
16
+ name: string;
17
+ chainId: string;
18
+ denom: string;
19
+ decimals: number;
20
+ logo?: string;
21
+ coingeckoId?: string;
22
+ };
23
+ type ChainConfig = {
24
+ name: string;
25
+ id: string;
26
+ rpcEndpoint: string;
27
+ };
28
+ type Contracts = {
29
+ oracle: Address;
30
+ router: Address;
31
+ };
32
+ type AssetsConfig = Record<string, Asset>;
33
+
34
+ type ClientConfig<TChainConfig = ChainConfig> = {
35
+ environment?: Environment;
36
+ customOverride?: {
37
+ chainConfig?: Partial<TChainConfig>;
38
+ contracts?: Partial<Contracts>;
39
+ assetsConfig?: AssetsConfig;
40
+ };
41
+ };
42
+
43
+ type OracleConfig = {
44
+ admin: Address;
45
+ priceThresholdRatio: string;
46
+ priceExpireTime: Duration | null;
47
+ };
48
+ type Price = {
49
+ assetPair: AssetPairString;
50
+ price: string;
51
+ expiryTime: Timestamp;
52
+ };
53
+ type InvertiblePrice = Price & {
54
+ isInverse: boolean;
55
+ };
56
+ type OracleAsset = {
57
+ name: string;
58
+ symbol: string;
59
+ precision: number;
60
+ };
61
+ type OracleAssetPair = {
62
+ base: OracleAsset;
63
+ quote: OracleAsset;
64
+ };
65
+
66
+ type AllowanceMode = 'allow' | 'disallow';
67
+ type PoolConfig = {
68
+ priceOracleContract: Address;
69
+ protocolFeeRecipient: Address;
70
+ protocolFee: string;
71
+ lpFee: string;
72
+ allowanceMode: AllowanceMode;
73
+ lps: Address[];
74
+ minBaseOut: string;
75
+ };
76
+ type BaseLiquidityDetails = {
77
+ baseLiquidity: Coin;
78
+ totalShares: string;
79
+ };
80
+
81
+ type RouterConfig = {
82
+ admin: Address;
83
+ defaultPriceOracleContract: Address;
84
+ defaultProtocolFeeRecipient: Address;
85
+ defaultProtocolFee: string;
86
+ defaultLpFee: string;
87
+ };
88
+ type Pool = {
89
+ poolAddress: Address;
90
+ baseDenom: string;
91
+ quoteDenoms: string[];
92
+ };
93
+ type SwapParams = {
94
+ assetIn: string;
95
+ amountIn: string;
96
+ assetOut: string;
97
+ minimumAmountOut?: string;
98
+ receiver?: Address;
99
+ };
100
+ type SwapResult<TTxOutput = unknown> = {
101
+ txOutput: TTxOutput;
102
+ amountOut: string;
103
+ assetOut: string;
104
+ txHash: string;
105
+ };
106
+
107
+ /**
108
+ * Parses a coin string containing both amount and denomination into a structured Coin object.
109
+ *
110
+ * This utility function extracts the numeric amount and denomination from a concatenated string
111
+ * where amounts are represented as a single string
112
+ * (e.g., "1000000uatom", "500000000aarch").
113
+ *
114
+ * @param amountWithDenom - A string containing the amount immediately followed by the denomination,
115
+ * with no spaces or separators. The amount must be a positive integer
116
+ * (no decimals or scientific notation).
117
+ *
118
+ * @returns A Coin object containing:
119
+ * - amount: The numeric portion as a string
120
+ * - denom: The denomination portion as a string
121
+ *
122
+ * @throws {InvalidParameterError} Thrown when the input string doesn't match the expected format
123
+ * or when the amount or denomination cannot be extracted
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * // Parse a standard Cosmos coin string
128
+ * const coin = getCoinFromAmountWithDenomString("1000000uatom");
129
+ * console.log(coin); // { amount: "1000000", denom: "uatom" }
130
+ *
131
+ * // Parse an IBC token
132
+ * const ibcCoin = getCoinFromAmountWithDenomString("500000000ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D");
133
+ * console.log(ibcCoin); // { amount: "500000000", denom: "ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D" }
134
+ *
135
+ * // Parse a custom token
136
+ * const customCoin = getCoinFromAmountWithDenomString("123456789aarch");
137
+ * console.log(customCoin); // { amount: "123456789", denom: "aarch" }
138
+ * ```
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * // Invalid formats that will throw errors
143
+ * try {
144
+ * getCoinFromAmountWithDenomString("1000000"); // Missing denom
145
+ * } catch (error) {
146
+ * console.error("No denomination found");
147
+ * }
148
+ *
149
+ * try {
150
+ * getCoinFromAmountWithDenomString("uatom"); // Missing amount
151
+ * } catch (error) {
152
+ * console.error("No amount found");
153
+ * }
154
+ *
155
+ * try {
156
+ * getCoinFromAmountWithDenomString("1000000 uatom"); // Contains space
157
+ * } catch (error) {
158
+ * console.error("Invalid format");
159
+ * }
160
+ * ```
161
+ */
162
+ declare const getCoinFromAmountWithDenomString: (amountWithDenom: string) => Coin;
163
+
164
+ /**
165
+ * Abstract base client for all implementations of the Bolt SDK for different chains/networks.
166
+ *
167
+ * This class provides the foundation for blockchain-specific implementations,
168
+ * defining the core interface for interacting with oracle and router contracts.
169
+ *
170
+ * @template TSigner - The type of the transaction signer specific to the blockchain implementation
171
+ * @template TTxOutput - The type of the transaction output specific to the blockchain implementation
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * class BoltCosmWasmClient extends BaseClient<OfflineSigner, ExecuteResult> {
176
+ * // Implementation specific to CosmWasm
177
+ * }
178
+ * ```
179
+ */
180
+ declare abstract class BaseClient<TSigner = unknown, TTxOutput = unknown> {
181
+ /**
182
+ * The blockchain network configuration containing chain ID, name, and RPC endpoint
183
+ */
184
+ chainConfig: ChainConfig;
185
+ /**
186
+ * Smart contract addresses for making Bolt queries and transactions in the blockchain
187
+ */
188
+ contracts: Contracts;
189
+ /**
190
+ * Configuration mapping of supported assets indexed by their symbol
191
+ */
192
+ assetsConfig: AssetsConfig;
193
+ /**
194
+ * Creates a new instance of the BaseClient.
195
+ *
196
+ * @param config - (Optional) Configuration object for the client
197
+ * @param config.customOverride - (Optional) Override configuration containing chain settings, contracts, and assets
198
+ * @param config.customOverride.chainConfig - (Optional) Chain configuration object
199
+ * @param config.customOverride.chainConfig.id - (Optional) The chain ID of the blockchain network (e.g., "archway-1")
200
+ * @param config.customOverride.chainConfig.name - (Optional) The human-readable name of the chain (e.g., "Archway")
201
+ * @param config.customOverride.chainConfig.rpcEndpoint - (Optional) RPC endpoint URL for the blockchain network
202
+ * @param config.customOverride.contracts - (Optional) Contract addresses for oracle and router
203
+ * @param config.customOverride.contracts.oracle - (Optional) Oracle contract address
204
+ * @param config.customOverride.contracts.router - (Optional) Router contract address
205
+ * @param config.customOverride.assetsConfig - (Optional) Configuration for supported assets indexed by symbol
206
+ *
207
+ * @throws {InvalidObjectError} Thrown when required configuration fields are missing
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * const client = new ConcreteClient({
212
+ * customOverride: {
213
+ * chainConfig: {
214
+ * id: 'archway-1',
215
+ * name: 'Archway',
216
+ * rpcEndpoint: 'https://rpc.example.com'
217
+ * },
218
+ * contracts: {
219
+ * oracle: 'archway1oracle...',
220
+ * router: 'archway1router...'
221
+ * },
222
+ * assetsConfig: {
223
+ * 'ARCH': {
224
+ * symbol: 'ARCH',
225
+ * name: 'Archway',
226
+ * chainId: 'archway-1',
227
+ * denom: 'aarch',
228
+ * decimals: 18,
229
+ * logo: 'https://...',
230
+ * coingeckoId: 'archway'
231
+ * }
232
+ * }
233
+ * }
234
+ * });
235
+ * ```
236
+ */
237
+ constructor(config?: ClientConfig);
238
+ /**
239
+ * Fetches the oracle configuration from the blockchain.
240
+ *
241
+ * @returns A promise that resolves to the oracle configuration containing
242
+ * settings such as price expiration time and threshold ratio
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * const oracleConfig = await client.getOracleConfig();
247
+ * console.log(`Price expiration: ${oracleConfig.priceExpireTime} seconds`);
248
+ * console.log(`Admin: ${oracleConfig.admin}`);
249
+ * console.log(`Price threshold ratio: ${oracleConfig.priceThresholdRatio}`);
250
+ * ```
251
+ */
252
+ abstract getOracleConfig(): Promise<OracleConfig>;
253
+ /**
254
+ * Fetches all asset pairs supported by the oracle.
255
+ *
256
+ * @returns A promise that resolves to an array of oracle asset pairs,
257
+ * each containing base and quote asset information with name, symbol and precision
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * const pairs = await client.getAllOracleAssetPairs();
262
+ * pairs.forEach(pair => {
263
+ * console.log(`${pair.base.symbol}/${pair.quote.symbol}`);
264
+ * console.log(` Base: ${pair.base.name} (${pair.base.precision} decimals)`);
265
+ * console.log(` Quote: ${pair.quote.name} (${pair.quote.precision} decimals)`);
266
+ * });
267
+ * ```
268
+ */
269
+ abstract getAllOracleAssetPairs(): Promise<OracleAssetPair[]>;
270
+ /**
271
+ * Fetches the current price for a specific base/quote asset pair from the oracle.
272
+ *
273
+ * @param baseDenom - The denom of the base asset (e.g., "aarch", "ibc/...")
274
+ * @param quoteDenom - The denom of the quote asset (e.g., "aarch", "ibc/...")
275
+ *
276
+ * @returns A promise that resolves to an invertible price object containing
277
+ * the current price from the oracle and whether it's inverted
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * // Get price of ARCH in terms of USDC
282
+ * const priceResult = await client.getPrice("aarch", "ibc/...");
283
+ * console.log(`1 ARCH = ${priceResult.price} USDC`);
284
+ * console.log(`Is inverted: ${priceResult.isInverse}`);
285
+ * ```
286
+ */
287
+ abstract getPrice(baseDenom: string, quoteDenom: string): Promise<InvertiblePrice>;
288
+ /**
289
+ * Fetches all available prices from the oracle.
290
+ *
291
+ * @returns A promise that resolves to an array of all current prices
292
+ * available in the oracle with their respective asset pairs and expiry times
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * const prices = await client.getAllPrices();
297
+ * prices.forEach(priceData => {
298
+ * console.log(`${priceData.assetPair}: ${priceData.price}`);
299
+ * console.log(` Expires at: ${new Date(priceData.expiryTime * 1000).toISOString()}`);
300
+ * });
301
+ * ```
302
+ */
303
+ abstract getAllPrices(): Promise<Price[]>;
304
+ /**
305
+ * Fetches the router configuration from the blockchain.
306
+ *
307
+ * @returns A promise that resolves to the router configuration containing
308
+ * settings such as default protocol fees, LP fees, and oracle configuration
309
+ *
310
+ * @example
311
+ * ```typescript
312
+ * const routerConfig = await client.getRouterConfig();
313
+ * console.log(`Default protocol fee: ${routerConfig.defaultProtocolFee * 100}%`);
314
+ * console.log(`Default LP fee: ${routerConfig.defaultLpFee * 100}%`);
315
+ * console.log(`Oracle address: ${routerConfig.priceOracleContract}`);
316
+ * ```
317
+ */
318
+ abstract getRouterConfig(): Promise<RouterConfig>;
319
+ /**
320
+ * Fetches the total liquidity for all base assets across all pools.
321
+ *
322
+ * @returns A promise that resolves to a record mapping pool addresses
323
+ * to their respective base asset liquidity details, including
324
+ * the base liquidity amount and total shares
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * const liquidity = await client.getAllBaseAssetsLiquidity();
329
+ * Object.entries(liquidity).forEach(([poolAddress, details]) => {
330
+ * console.log(`Pool ${poolAddress}:`);
331
+ * console.log(` Base: ${details.baseLiquidity.amount} ${details.baseLiquidity.denom}`);
332
+ * console.log(` Total Shares: ${details.totalShares}`);
333
+ * });
334
+ * ```
335
+ */
336
+ abstract getAllBaseAssetsLiquidity(): Promise<Record<Address, BaseLiquidityDetails>>;
337
+ /**
338
+ * Fetches all withdrawable quote assets for a specific user or liquidity provider.
339
+ *
340
+ * @param address - The blockchain address of the user or liquidity provider
341
+ *
342
+ * @returns A promise that resolves to a record mapping pool addresses
343
+ * to arrays of withdrawable quote asset coins
344
+ *
345
+ * @example
346
+ * ```typescript
347
+ * const quotes = await client.getAllQuotesByUser("archway1...");
348
+ * Object.entries(quotes).forEach(([poolAddress, coins]) => {
349
+ * console.log(`Pool ${poolAddress}:`);
350
+ * coins.forEach(coin => {
351
+ * console.log(` ${coin.amount} ${coin.denom}`);
352
+ * });
353
+ * });
354
+ * ```
355
+ */
356
+ abstract getAllQuotesByUser(address: Address): Promise<Record<Address, Coin[]>>;
357
+ /**
358
+ * Fetches pool information for a specific base asset.
359
+ *
360
+ * @param baseDenom - The denom of the base asset (e.g., "aarch", "ibc/...")
361
+ *
362
+ * @returns A promise that resolves to the pool information for the specified asset
363
+ *
364
+ * @throws Will throw an error if no pool exists for the specified base asset
365
+ *
366
+ * @example
367
+ * ```typescript
368
+ * const pool = await client.getPoolByBaseAsset("aarch");
369
+ * console.log(`Pool address: ${pool.poolAddress}`);
370
+ * console.log(`Base asset: ${pool.baseDenom}`);
371
+ * console.log('Available quote assets:');
372
+ * pool.quoteAssetsSymbols.forEach(symbol => {
373
+ * console.log(` - ${symbol}`);
374
+ * });
375
+ * ```
376
+ */
377
+ abstract getPoolByBaseAsset(baseDenom: string): Promise<Pool>;
378
+ /**
379
+ * Fetches information for all available pools.
380
+ *
381
+ * @returns A promise that resolves to an array containing all pool information
382
+ *
383
+ * @example
384
+ * ```typescript
385
+ * const pools = await client.getAllPools();
386
+ * pools.forEach(pool => {
387
+ * console.log(`Pool ${pool.poolAddress}:`);
388
+ * console.log(` Base: ${pool.baseDenom}`);
389
+ * console.log(` Quotes: ${pool.quoteAssetsSymbols.join(', ')}`);
390
+ * });
391
+ * ```
392
+ */
393
+ abstract getAllPools(): Promise<Pool[]>;
394
+ /**
395
+ * Fetches the configuration settings for a specific liquidity pool.
396
+ *
397
+ * This method retrieves detailed configuration parameters for a pool, including
398
+ * fee structures, oracle settings, liquidity provider information, and trading limits.
399
+ *
400
+ * @param poolContractAddress - The blockchain address of the pool contract
401
+ *
402
+ * @returns A promise that resolves to a pool configuration object
403
+ * containing settings such as fees, oracle address, LP addresses, and minimum trade amounts
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * const poolConfig = await client.getPoolConfig("archway1pool...");
408
+ * console.log(`Oracle: ${poolConfig.priceOracleContract}`);
409
+ * console.log(`Protocol fee: ${poolConfig.protocolFee * 100}%`);
410
+ * console.log(`LP fee: ${poolConfig.lpFee * 100}%`);
411
+ * console.log(`Allowance mode: ${poolConfig.allowanceMode}`);
412
+ * console.log(`LPs: ${poolConfig.lps.join(', ')}`);
413
+ * console.log(`Min base output: ${poolConfig.minBaseOut}`);
414
+ * ```
415
+ */
416
+ abstract getPoolConfig(poolContractAddress: string): Promise<PoolConfig>;
417
+ /**
418
+ * Fetches the configuration settings for a pool identified by its base asset symbol.
419
+ *
420
+ * This is a convenience method that combines pool lookup and configuration retrieval.
421
+ * It first finds the pool associated with the given base asset, then fetches that
422
+ * pool's configuration parameters from its settlement contract.
423
+ *
424
+ * @param baseDenom - The denom of the base asset (e.g., "aarch", "ibc/...")
425
+ *
426
+ * @returns A promise that resolves to a pool configuration object containing
427
+ * settings such as fees, oracle address, LP addresses, and minimum trade amounts
428
+ *
429
+ * @throws Will throw an error if no pool exists for the specified base asset
430
+ *
431
+ * @example
432
+ * ```typescript
433
+ * // Get pool configuration for ARCH base asset
434
+ * const poolConfig = await client.getPoolConfigByBaseAsset("aarch");
435
+ * console.log(`Oracle: ${poolConfig.priceOracleContract}`);
436
+ * console.log(`Protocol fee: ${parseFloat(poolConfig.protocolFee) * 100}%`);
437
+ * console.log(`LP fee: ${parseFloat(poolConfig.lpFee) * 100}%`);
438
+ * console.log(`Allowance mode: ${poolConfig.allowanceMode}`);
439
+ * console.log(`Number of LPs: ${poolConfig.lps.length}`);
440
+ * console.log(`Min base output: ${poolConfig.minBaseOut}`);
441
+ * ```
442
+ */
443
+ abstract getPoolConfigByBaseAsset(baseDenom: string): Promise<PoolConfig>;
444
+ /**
445
+ * Fetches all supported assets across all pools in the Bolt protocol.
446
+ *
447
+ * This method retrieves comprehensive information about all assets that can be traded,
448
+ * including their metadata, chain-specific details, and external identifiers.
449
+ *
450
+ * @returns A promise that resolves to an array of Asset objects, each containing:
451
+ * - symbol: The asset's trading symbol (e.g., "ARCH", "USDC")
452
+ * - name: The full name of the asset (e.g., "Archway", "USD Coin")
453
+ * - chainId: The blockchain network identifier where this asset exists
454
+ * - denom: The chain-specific denomination (e.g., "aarch", "ibc/...")
455
+ * - decimals: The number of decimal places for the asset
456
+ * - logo: Optional URL to the asset's logo image
457
+ * - coingeckoId: Optional CoinGecko identifier for price data
458
+ *
459
+ * @example
460
+ * ```typescript
461
+ * const assets = await client.getAssets();
462
+ *
463
+ * // Display all available assets
464
+ * assets.forEach(asset => {
465
+ * console.log(`${asset.symbol} (${asset.name})`);
466
+ * console.log(` Chain: ${asset.chainId}`);
467
+ * console.log(` Denom: ${asset.denom}`);
468
+ * console.log(` Decimals: ${asset.decimals}`);
469
+ * if (asset.coingeckoId) {
470
+ * console.log(` CoinGecko: ${asset.coingeckoId}`);
471
+ * }
472
+ * });
473
+ *
474
+ * // Find a specific asset
475
+ * const archAsset = assets.find(a => a.symbol === 'ARCH');
476
+ * console.log(`ARCH denom: ${archAsset?.denom}`);
477
+ * ```
478
+ *
479
+ * @remarks
480
+ * Assets returned by this method represent all tokens available for trading
481
+ * in the Bolt protocol. The list may vary between mainnet and testnet environments.
482
+ */
483
+ abstract getAssets(): Promise<Asset[]>;
484
+ /**
485
+ * Executes a swap operation on the blockchain from one asset to another.
486
+ *
487
+ * This method performs a "swap exact in" where the exact input amount is specified, and the output
488
+ * amount varies based on current pool conditions and fees. The transaction includes
489
+ * slippage protection through the optional minimumAmountOut parameter.
490
+ *
491
+ * @param signer - The transaction signer that will authorize the swap operation.
492
+ * Must have sufficient balance of the input asset.
493
+ * @param params - The swap configuration parameters
494
+ * @param params.assetIn - The denom of the asset being sold (e.g., "aarch", "ibc/...")
495
+ * @param params.amountIn - The exact amount of input asset to swap (in minimal denomination)
496
+ * @param params.assetOut - The denom of the asset being bought (e.g., "aarch", "ibc/...")
497
+ * @param params.minimumAmountOut - Optional minimum acceptable amount of output asset.
498
+ * Transaction will fail if actual output would be less.
499
+ * @param params.receiver - Optional recipient address for the swapped assets.
500
+ * If not provided, defaults to the signer's address.
501
+ *
502
+ * @returns A promise that resolves to a SwapResult containing:
503
+ * - txOutput: Transaction execution details (type varies by implementation)
504
+ * - amountOut: The actual amount of output asset received (as a string)
505
+ * - assetOut: The denom of the asset received
506
+ * - txHash: The transaction hash
507
+ *
508
+ * @throws Will throw an error if the swap fails due to insufficient balance,
509
+ * slippage exceeding tolerance, or other transaction errors
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * // Swap exactly 1 ARCH for USDC (output amount varies)
514
+ * const result = await client.swap(signer, {
515
+ * assetIn: "aarch",
516
+ * amountIn: "1000000000000000000", // Exactly 1 ARCH (18 decimals)
517
+ * assetOut: "ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D", // USDC IBC denom
518
+ * minimumAmountOut: "1950000000", // Accept no less than 1950 USDC
519
+ * receiver: "archway1..." // Optional custom receiver
520
+ * });
521
+ *
522
+ * console.log(`Swapped exactly 1 ARCH`);
523
+ * console.log(`Received: ${result.amountOut} ${result.assetOut}`);
524
+ * console.log(`Transaction: ${result.txHash}`);
525
+ * ```
526
+ *
527
+ * @remarks
528
+ * This is a "swap exact in" operation where:
529
+ * - The input amount is exactly what you specify
530
+ * - The output amount depends on pool conditions
531
+ * - Fees are deducted from the output
532
+ * - Use minimumAmountOut to protect against excessive slippage
533
+ *
534
+ * The TTxOutput type parameter represents the transaction execution result type,
535
+ * which varies by blockchain implementation (e.g., ExecuteResult for CosmWasm).
536
+ */
537
+ abstract swap(signer: TSigner, params: SwapParams): Promise<SwapResult<TTxOutput>>;
538
+ }
539
+
540
+ /**
541
+ * Error codes used throughout the Bolt SDK to categorize different types of errors.
542
+ *
543
+ * These codes help in programmatic error handling and provide a consistent way
544
+ * to identify error types across the SDK. Error codes are organized into ranges
545
+ * by category for easier identification and handling.
546
+ *
547
+ * Error Code Ranges:
548
+ * - 1000-1999: Resource & Data Errors
549
+ * - 2000-2999: Blockchain Transaction Errors
550
+ * - 3000-3999: Infrastructure & Network Errors
551
+ * - 4000-4999: Validation & Input Errors
552
+ * - 9000-9999: Unknown & Unexpected Errors
553
+ *
554
+ * @enum {number}
555
+ * @group Errors
556
+ * @category Error Types
557
+ *
558
+ * @example
559
+ * ```typescript
560
+ * import { BoltSdkErrorCode, BoltSdkError } from '@bolt-liquidity-hq/cosmwasm-client';
561
+ *
562
+ * try {
563
+ * await client.swap(signer, params);
564
+ * } catch (error) {
565
+ * if (error instanceof BoltSdkError) {
566
+ * switch (error.code) {
567
+ * case BoltSdkErrorCode.INVALID_ADDRESS:
568
+ * console.error("Invalid address format");
569
+ * break;
570
+ * case BoltSdkErrorCode.TRANSACTION_EVENT_NOT_FOUND:
571
+ * console.error("Transaction event not found");
572
+ * break;
573
+ * case BoltSdkErrorCode.UNEXPECTED_ERROR:
574
+ * console.error("Unexpected error occurred:", error.message);
575
+ * break;
576
+ * default:
577
+ * console.error("Operation failed:", error.message);
578
+ * }
579
+ * }
580
+ * }
581
+ * ```
582
+ */
583
+ declare const enum BoltSdkErrorCode {
584
+ /** Resource not found (pools, assets, configurations) */
585
+ NOT_FOUND = 1000,
586
+ /** Invalid object structure or missing required fields */
587
+ INVALID_OBJECT = 1001,
588
+ /** Type mismatch or invalid type provided */
589
+ INVALID_TYPE = 1002,
590
+ /** Insufficient balance to perform the operation */
591
+ INSUFFICIENT_FUNDS = 2000,
592
+ /** Invalid blockchain address format */
593
+ INVALID_ADDRESS = 2001,
594
+ /** Transaction reverted or failed on-chain */
595
+ TRANSACTION_FAILED = 2002,
596
+ /** Expected transaction event not found in logs */
597
+ TRANSACTION_EVENT_NOT_FOUND = 2003,
598
+ /** Network connectivity or RPC communication failure */
599
+ NETWORK_ERROR = 3000,
600
+ /** Invalid parameter provided to a method */
601
+ INVALID_PARAMETER = 4000,
602
+ /** Required parameter is missing */
603
+ MISSING_PARAMETER = 4001,
604
+ /** Numeric value outside acceptable range */
605
+ PARAMETER_OUT_OF_RANGE = 4002,
606
+ /** Unexpected or unknown error occurred */
607
+ UNEXPECTED_ERROR = 9000
608
+ }
609
+ /**
610
+ * Base interface for all Bolt SDK errors.
611
+ *
612
+ * All custom errors in the SDK implement this interface, providing
613
+ * a consistent error structure with error codes for easy handling.
614
+ *
615
+ * @interface
616
+ * @group Errors
617
+ * @category Error Types
618
+ */
619
+ interface BoltSdkError extends Error {
620
+ /** The error code categorizing this error */
621
+ code: BoltSdkErrorCode;
622
+ /** Optional additional context data that might help debugging */
623
+ context?: Record<string, unknown>;
624
+ }
625
+ /**
626
+ * Base class for all custom errors in the Bolt SDK.
627
+ *
628
+ * This abstract base class provides common functionality for all SDK errors,
629
+ * including error code assignment, proper error name setting, and optional context data.
630
+ *
631
+ * @abstract
632
+ * @group Errors
633
+ * @category Error Classes
634
+ */
635
+ declare class BoltSdkErrorBase extends Error implements BoltSdkError {
636
+ code: BoltSdkErrorCode;
637
+ /** Optional additional context data that might help debugging */
638
+ context?: Record<string, unknown>;
639
+ /**
640
+ * Creates a new BoltSdkErrorBase instance.
641
+ *
642
+ * @param code - The error code categorizing this error
643
+ * @param message - Human-readable error message
644
+ * @param context - Optional additional context or state information
645
+ */
646
+ constructor(code: BoltSdkErrorCode, message: string, context?: Record<string, unknown>);
647
+ }
648
+ /**
649
+ * Error thrown when a requested resource cannot be found.
650
+ *
651
+ * @group Errors
652
+ * @category Error Classes
653
+ */
654
+ declare class NotFoundError extends BoltSdkErrorBase {
655
+ /**
656
+ * Creates a new NotFoundError instance.
657
+ *
658
+ * @param resource - The type of resource that was not found
659
+ * @param details - Optional additional details about what was searched for
660
+ * @param context - Optional additional context or state information
661
+ */
662
+ constructor(resource: string, details?: string, context?: Record<string, unknown>);
663
+ }
664
+ /**
665
+ * Error thrown when an object doesn't have the expected structure.
666
+ *
667
+ * @group Errors
668
+ * @category Error Classes
669
+ */
670
+ declare class InvalidObjectError extends BoltSdkErrorBase {
671
+ /**
672
+ * Creates a new InvalidObjectError instance.
673
+ *
674
+ * @param details - Optional description of what is invalid about the object
675
+ * @param context - Optional additional context or state information
676
+ */
677
+ constructor(details?: string, context?: Record<string, unknown>);
678
+ }
679
+ /**
680
+ * Error thrown when an unexpected type is encountered.
681
+ *
682
+ * @group Errors
683
+ * @category Error Classes
684
+ */
685
+ declare class InvalidTypeError extends BoltSdkErrorBase {
686
+ /**
687
+ * Creates a new InvalidTypeError instance.
688
+ *
689
+ * @param expectedType - The type that was expected
690
+ * @param receivedType - The actual type that was received
691
+ * @param context - Optional additional context or state information
692
+ */
693
+ constructor(expectedType: string, receivedType: string, context?: Record<string, unknown>);
694
+ }
695
+ /**
696
+ * Error thrown when a response cannot be parsed into the expected TypeScript type.
697
+ *
698
+ * This error is used when API responses, JSON data, or other external data
699
+ * cannot be successfully parsed or validated against the expected TypeScript
700
+ * interface or type definition.
701
+ *
702
+ * @group Errors
703
+ * @category Error Classes
704
+ */
705
+ declare class ParseError extends BoltSdkErrorBase {
706
+ /**
707
+ * Creates a new ParseError instance.
708
+ *
709
+ * @param targetType - The TypeScript type or interface name that parsing failed for
710
+ * @param details - Specific details about what failed during parsing
711
+ * @param context - Optional additional context including the raw data that failed to parse
712
+ */
713
+ constructor(targetType: string, details: string, context?: Record<string, unknown>);
714
+ }
715
+ /**
716
+ * Error thrown when an account has insufficient funds for an operation.
717
+ *
718
+ * @group Errors
719
+ * @category Error Classes
720
+ */
721
+ declare class InsufficientFundsError extends BoltSdkErrorBase {
722
+ /**
723
+ * Creates a new InsufficientFundsError instance.
724
+ *
725
+ * @param required - The amount required for the operation
726
+ * @param available - The amount available in the account
727
+ * @param context - Optional additional context or state information
728
+ */
729
+ constructor(required: number, available: number, context?: Record<string, unknown>);
730
+ }
731
+ /**
732
+ * Error thrown when an invalid blockchain address is provided.
733
+ *
734
+ * @group Errors
735
+ * @category Error Classes
736
+ */
737
+ declare class InvalidAddressError extends BoltSdkErrorBase {
738
+ /**
739
+ * Creates a new InvalidAddressError instance.
740
+ *
741
+ * @param address - The invalid address that was provided
742
+ * @param context - Optional additional context or state information
743
+ */
744
+ constructor(address: string, context?: Record<string, unknown>);
745
+ }
746
+ /**
747
+ * Error thrown when a blockchain transaction fails or is reverted.
748
+ *
749
+ * @group Errors
750
+ * @category Error Classes
751
+ */
752
+ declare class TransactionFailedError extends BoltSdkErrorBase {
753
+ /**
754
+ * Creates a new TransactionFailedError instance.
755
+ *
756
+ * @param transactionId - The transaction hash or identifier
757
+ * @param details - Optional details about why the transaction failed
758
+ * @param context - Optional additional context or state information
759
+ */
760
+ constructor(transactionId: string, details?: string, context?: Record<string, unknown>);
761
+ }
762
+ /**
763
+ * Error thrown when an expected transaction event is not found in the logs.
764
+ *
765
+ * @group Errors
766
+ * @category Error Classes
767
+ */
768
+ declare class TransactionEventNotFoundError extends BoltSdkErrorBase {
769
+ /**
770
+ * Creates a new TransactionEventNotFoundError instance.
771
+ *
772
+ * @param eventName - The name of the event that was expected
773
+ * @param details - Optional details about the context
774
+ * @param context - Optional additional context or state information
775
+ */
776
+ constructor(eventName: string, details?: string, context?: Record<string, unknown>);
777
+ }
778
+ /**
779
+ * Error thrown when network communication fails.
780
+ *
781
+ * @group Errors
782
+ * @category Error Classes
783
+ */
784
+ declare class NetworkError extends BoltSdkErrorBase {
785
+ /**
786
+ * Creates a new NetworkError instance.
787
+ *
788
+ * @param details - Optional details about the network failure
789
+ * @param context - Optional additional context or state information
790
+ */
791
+ constructor(details?: string, context?: Record<string, unknown>);
792
+ }
793
+ /**
794
+ * Error thrown when an invalid parameter is provided to a method.
795
+ *
796
+ * @group Errors
797
+ * @category Error Classes
798
+ */
799
+ declare class InvalidParameterError<T = unknown> extends BoltSdkErrorBase {
800
+ /**
801
+ * Creates a new InvalidParameterError instance.
802
+ *
803
+ * @param parameterName - The name of the invalid parameter
804
+ * @param expected - Description of what was expected
805
+ * @param receivedValue - The actual value that was provided
806
+ * @param details - Optional additional details or constraints
807
+ * @param context - Optional additional context or state information
808
+ *
809
+ * @template T - The type of the received value
810
+ */
811
+ constructor(parameterName: string, expected: string, receivedValue: T, details?: string, context?: Record<string, unknown>);
812
+ }
813
+ /**
814
+ * Error thrown when a required parameter is missing.
815
+ *
816
+ * @group Errors
817
+ * @category Error Classes
818
+ */
819
+ declare class MissingParameterError extends BoltSdkErrorBase {
820
+ /**
821
+ * Creates a new MissingParameterError instance.
822
+ *
823
+ * @param parameterName - The name of the missing parameter
824
+ * @param expectedLocation - Optional context about where the parameter was expected to be found
825
+ * @param context - Optional additional context or state information
826
+ */
827
+ constructor(parameterName: string, expectedLocation?: string, context?: Record<string, unknown>);
828
+ }
829
+ /**
830
+ * Error thrown when a numeric parameter is outside the acceptable range.
831
+ *
832
+ * @group Errors
833
+ * @category Error Classes
834
+ */
835
+ declare class ParameterOutOfRangeError extends BoltSdkErrorBase {
836
+ /**
837
+ * Creates a new ParameterOutOfRangeError instance.
838
+ *
839
+ * @param parameterName - The name of the parameter that's out of range
840
+ * @param value - The actual value that was provided
841
+ * @param min - Optional minimum acceptable value (inclusive)
842
+ * @param max - Optional maximum acceptable value (inclusive)
843
+ * @param details - Optional additional details about the constraint
844
+ * @param context - Optional additional context or state information
845
+ */
846
+ constructor(parameterName: string, value: number | bigint, min?: number | bigint, max?: number | bigint, details?: string, context?: Record<string, unknown>);
847
+ }
848
+ /**
849
+ * Error thrown when an unexpected or unhandled error occurs.
850
+ *
851
+ * This error is used as a catch-all for errors that don't fit into any
852
+ * of the specific error categories. It can wrap unknown errors from
853
+ * external libraries or unexpected runtime conditions.
854
+ *
855
+ * @group Errors
856
+ * @category Error Classes
857
+ *
858
+ * @example
859
+ * ```typescript
860
+ * try {
861
+ * // Some operation that might throw unknown errors
862
+ * await someExternalLibraryCall();
863
+ * } catch (error) {
864
+ * if (error instanceof Error) {
865
+ * throw new UnexpectedError(error.message, error);
866
+ * } else {
867
+ * throw new UnexpectedError(String(error));
868
+ * }
869
+ * }
870
+ * ```
871
+ *
872
+ * @example
873
+ * ```typescript
874
+ * // Handle unexpected conditions
875
+ * if (someUnexpectedCondition) {
876
+ * throw new UnexpectedError(
877
+ * "Unexpected state encountered during swap operation",
878
+ * undefined,
879
+ * { poolState, userBalance, timestamp }
880
+ * );
881
+ * }
882
+ * ```
883
+ */
884
+ declare class UnexpectedError extends BoltSdkErrorBase {
885
+ /** The original error that was caught, if any */
886
+ originalError?: Error | unknown;
887
+ /**
888
+ * Creates a new UnexpectedError instance.
889
+ *
890
+ * @param message - A description of the unexpected error
891
+ * @param originalError - Optional original error that was caught
892
+ * @param context - Optional additional context or state information
893
+ */
894
+ constructor(message: string, originalError?: Error | unknown, context?: Record<string, unknown>);
895
+ /**
896
+ * Creates an UnexpectedError from an unknown caught value.
897
+ * This is a convenience method for error handling blocks.
898
+ *
899
+ * @param caught - The value that was caught in a try-catch block
900
+ * @param message - Optional custom message to prepend
901
+ * @param context - Optional additional context
902
+ * @returns A new UnexpectedError instance
903
+ *
904
+ * @example
905
+ * ```typescript
906
+ * try {
907
+ * await riskyOperation();
908
+ * } catch (caught) {
909
+ * throw UnexpectedError.from(
910
+ * caught,
911
+ * "Failed to execute risky operation",
912
+ * { operation: 'riskyOperation', timestamp: Date.now() }
913
+ * );
914
+ * }
915
+ * ```
916
+ */
917
+ static from(caught: unknown, message?: string, context?: Record<string, unknown>): UnexpectedError;
918
+ }
919
+
920
+ export { type Address, type AllowanceMode, type Asset, type AssetPairString, type AssetsConfig, BaseClient, type BaseLiquidityDetails, type BoltSdkError, BoltSdkErrorBase, type ChainConfig, type ClientConfig, type Coin, type Contracts, type Duration, type Environment, InsufficientFundsError, InvalidAddressError, InvalidObjectError, InvalidParameterError, InvalidTypeError, type InvertiblePrice, MissingParameterError, NetworkError, NotFoundError, type OracleAsset, type OracleAssetPair, type OracleConfig, ParameterOutOfRangeError, ParseError, type Pool, type PoolConfig, type Price, type RouterConfig, type SwapParams, type SwapResult, type Timestamp, TransactionEventNotFoundError, TransactionFailedError, UnexpectedError, getCoinFromAmountWithDenomString };