@bolt-liquidity-hq/cosmwasm-client 0.1.0-beta.2 → 0.1.0-beta.20

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.cts CHANGED
@@ -1,684 +1,140 @@
1
1
  import { ArchwayClient, SigningArchwayClient } from '@archwayhq/arch3.js';
2
+ import { ChainConfig, ClientConfig, Address, Duration, Timestamp, OracleAssetPair, Coin, AllowanceMode, RouterConfig, BaseClient, OracleConfig, InvertiblePrice, Price, BaseLiquidityDetails, Pool, PoolConfig, Asset, SwapParams, SwapResult, SwapRequiredParams, SimulateSwapResult } from '@bolt-liquidity-hq/core';
2
3
  import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from '@cosmjs/cosmwasm-stargate';
3
4
  import { OfflineSigner } from '@cosmjs/proto-signing';
4
5
 
5
- /**
6
- * Error codes used throughout the Bolt SDK to categorize different types of errors.
7
- *
8
- * These codes help in programmatic error handling and provide a consistent way
9
- * to identify error types across the SDK.
10
- *
11
- * @enum {number}
12
- * @group Errors
13
- * @category Error Types
14
- *
15
- * @example
16
- * ```typescript
17
- * import { BoltSdkErrorCode, BoltSdkError } from '@bolt-liquidity-hq/cosmwasm-client';
18
- *
19
- * try {
20
- * await client.swapExactIn(signer, params);
21
- * } catch (error) {
22
- * if (error instanceof BoltSdkError) {
23
- * switch (error.code) {
24
- * case BoltSdkErrorCode.INVALID_ADDRESS:
25
- * console.error("Invalid address format");
26
- * break;
27
- * case BoltSdkErrorCode.TRANSACTION_EVENT_NOT_FOUND:
28
- * console.error("Transaction event not found");
29
- * break;
30
- * default:
31
- * console.error("Operation failed:", error.message);
32
- * }
33
- * }
34
- * }
35
- * ```
36
- */
37
- declare enum BoltSdkErrorCode {
38
- /** Resource not found (pools, assets, configurations) */
39
- NOT_FOUND = 0,
40
- /** Invalid object structure or missing required fields */
41
- INVALID_OBJECT = 1,
42
- /** Type mismatch or invalid type provided */
43
- INVALID_TYPE = 2,
44
- /** Insufficient balance to perform the operation */
45
- INSUFFICIENT_FUNDS = 3,
46
- /** Invalid blockchain address format */
47
- INVALID_ADDRESS = 4,
48
- /** Transaction reverted or failed on-chain */
49
- TRANSACTION_FAILED = 5,
50
- /** Expected transaction event not found in logs */
51
- TRANSACTION_EVENT_NOT_FOUND = 6,
52
- /** Network connectivity or RPC communication failure */
53
- NETWORK_ERROR = 7,
54
- /** Invalid parameter provided to a method */
55
- INVALID_PARAMETER = 8,
56
- /** Required parameter is missing */
57
- MISSING_PARAMETER = 9,
58
- /** Numeric value outside acceptable range */
59
- PARAMETER_OUT_OF_RANGE = 10
60
- }
61
- /**
62
- * Base interface for all Bolt SDK errors.
63
- *
64
- * All custom errors in the SDK implement this interface, providing
65
- * a consistent error structure with error codes for easy handling.
66
- *
67
- * @interface
68
- * @group Errors
69
- * @category Error Types
70
- */
71
- interface BoltSdkError extends Error {
72
- /** The error code categorizing this error */
73
- code: BoltSdkErrorCode;
74
- }
75
- /**
76
- * Base class for all custom errors in the Bolt SDK.
77
- *
78
- * This abstract base class provides common functionality for all SDK errors,
79
- * including error code assignment and proper error name setting.
80
- *
81
- * @abstract
82
- * @group Errors
83
- * @category Error Classes
84
- */
85
- declare class BoltSdkErrorBase extends Error implements BoltSdkError {
86
- code: BoltSdkErrorCode;
87
- /**
88
- * Creates a new BoltSdkErrorBase instance.
89
- *
90
- * @param code - The error code categorizing this error
91
- * @param message - Human-readable error message
92
- */
93
- constructor(code: BoltSdkErrorCode, message: string);
94
- }
95
- /**
96
- * Error thrown when a requested resource cannot be found.
97
- *
98
- * @group Errors
99
- * @category Error Classes
100
- */
101
- declare class NotFoundError extends BoltSdkErrorBase {
102
- /**
103
- * Creates a new NotFoundError instance.
104
- *
105
- * @param resource - The type of resource that was not found
106
- * @param details - Optional additional details about what was searched for
107
- */
108
- constructor(resource: string, details?: string);
109
- }
110
- /**
111
- * Error thrown when an object doesn't have the expected structure.
112
- *
113
- * @group Errors
114
- * @category Error Classes
115
- */
116
- declare class InvalidObjectError extends BoltSdkErrorBase {
117
- /**
118
- * Creates a new InvalidObjectError instance.
119
- *
120
- * @param details - Optional description of what is invalid about the object
121
- */
122
- constructor(details?: string);
123
- }
124
- /**
125
- * Error thrown when an unexpected type is encountered.
126
- *
127
- * @group Errors
128
- * @category Error Classes
129
- */
130
- declare class InvalidTypeError extends BoltSdkErrorBase {
131
- /**
132
- * Creates a new InvalidTypeError instance.
133
- *
134
- * @param expectedType - The type that was expected
135
- * @param receivedType - The actual type that was received
136
- */
137
- constructor(expectedType: string, receivedType: string);
138
- }
139
- /**
140
- * Error thrown when an account has insufficient funds for an operation.
141
- *
142
- * @group Errors
143
- * @category Error Classes
144
- */
145
- declare class InsufficientFundsError extends BoltSdkErrorBase {
146
- /**
147
- * Creates a new InsufficientFundsError instance.
148
- *
149
- * @param required - The amount required for the operation
150
- * @param available - The amount available in the account
151
- */
152
- constructor(required: number, available: number);
153
- }
154
- /**
155
- * Error thrown when an invalid blockchain address is provided.
156
- *
157
- * @group Errors
158
- * @category Error Classes
159
- */
160
- declare class InvalidAddressError extends BoltSdkErrorBase {
161
- /**
162
- * Creates a new InvalidAddressError instance.
163
- *
164
- * @param address - The invalid address that was provided
165
- */
166
- constructor(address: string);
167
- }
168
- /**
169
- * Error thrown when a blockchain transaction fails or is reverted.
170
- *
171
- * @group Errors
172
- * @category Error Classes
173
- */
174
- declare class TransactionFailedError extends BoltSdkErrorBase {
175
- /**
176
- * Creates a new TransactionFailedError instance.
177
- *
178
- * @param transactionId - The transaction hash or identifier
179
- * @param details - Optional details about why the transaction failed
180
- */
181
- constructor(transactionId: string, details?: string);
182
- }
183
- /**
184
- * Error thrown when an expected transaction event is not found in the logs.
185
- *
186
- * @group Errors
187
- * @category Error Classes
188
- */
189
- declare class TransactionEventNotFoundError extends BoltSdkErrorBase {
190
- /**
191
- * Creates a new TransactionEventNotFoundError instance.
192
- *
193
- * @param eventName - The name of the event that was expected
194
- * @param details - Optional details about the context
195
- */
196
- constructor(eventName: string, details?: string);
197
- }
198
- /**
199
- * Error thrown when network communication fails.
200
- *
201
- * @group Errors
202
- * @category Error Classes
203
- */
204
- declare class NetworkError extends BoltSdkErrorBase {
205
- /**
206
- * Creates a new NetworkError instance.
207
- *
208
- * @param details - Optional details about the network failure
209
- */
210
- constructor(details?: string);
211
- }
212
- /**
213
- * Error thrown when an invalid parameter is provided to a method.
214
- *
215
- * @group Errors
216
- * @category Error Classes
217
- */
218
- declare class InvalidParameterError<T = unknown> extends BoltSdkErrorBase {
219
- /**
220
- * Creates a new InvalidParameterError instance.
221
- *
222
- * @param parameterName - The name of the invalid parameter
223
- * @param expected - Description of what was expected
224
- * @param receivedValue - The actual value that was provided
225
- * @param details - Optional additional details or constraints
226
- *
227
- * @template T - The type of the received value
228
- */
229
- constructor(parameterName: string, expected: string, receivedValue: T, details?: string);
230
- }
231
- /**
232
- * Error thrown when a required parameter is missing.
233
- *
234
- * @group Errors
235
- * @category Error Classes
236
- */
237
- declare class MissingParameterError extends BoltSdkErrorBase {
238
- /**
239
- * Creates a new MissingParameterError instance.
240
- *
241
- * @param parameterName - The name of the missing parameter
242
- * @param context - Optional context about where the parameter was expected
243
- */
244
- constructor(parameterName: string, context?: string);
245
- }
246
- /**
247
- * Error thrown when a numeric parameter is outside the acceptable range.
248
- *
249
- * @group Errors
250
- * @category Error Classes
251
- */
252
- declare class ParameterOutOfRangeError extends BoltSdkErrorBase {
253
- /**
254
- * Creates a new ParameterOutOfRangeError instance.
255
- *
256
- * @param parameterName - The name of the parameter that's out of range
257
- * @param value - The actual value that was provided
258
- * @param min - Optional minimum acceptable value (inclusive)
259
- * @param max - Optional maximum acceptable value (inclusive)
260
- * @param details - Optional additional details about the constraint
261
- */
262
- constructor(parameterName: string, value: number | bigint, min?: number | bigint, max?: number | bigint, details?: string);
263
- }
264
-
265
- declare enum Environment {
266
- Mainnet = "mainnet",
267
- Testnet = "testnet"
268
- }
269
-
270
- type Address = string;
271
- type AssetPairString = string;
272
- type Timestamp = string;
273
- interface Duration {
274
- secs: string;
275
- nanos: number;
276
- }
277
- interface Coin {
278
- denom: string;
279
- amount: string;
280
- }
281
-
282
- interface ClientConfig {
283
- environment?: Environment;
284
- override?: {
285
- rpcEndpoint?: string;
286
- contracts?: Partial<Contracts>;
287
- };
288
- }
289
- interface Contracts {
290
- oracle: Address;
291
- router: Address;
292
- }
293
-
294
- interface OracleConfig {
295
- admin: Address;
296
- priceThresholdRatio: string;
297
- priceExpireTime: Duration | null;
298
- }
299
- interface Price {
300
- assetPair: AssetPairString;
301
- price: string;
302
- expiryTime: Timestamp;
303
- }
304
- interface InvertiblePrice extends Price {
305
- isInverse: boolean;
306
- }
307
- interface OracleAsset {
308
- name: string;
309
- symbol: string;
310
- precision: number;
311
- }
312
- interface OracleAssetPair {
313
- base: OracleAsset;
314
- quote: OracleAsset;
315
- }
6
+ type CosmWasmChainConfig = ChainConfig & {
7
+ restEndpoint: string;
8
+ };
316
9
 
317
- interface RouterConfig {
318
- admin: Address;
319
- defaultPriceOracleContract: Address;
320
- defaultProtocolFeeRecipient: Address;
321
- defaultProtocolFee: string;
322
- defaultLpFee: string;
323
- settlementCodeId: number;
324
- }
325
- interface Pool {
326
- poolAddress: Address;
327
- baseAssetSymbol: string;
328
- quoteAssetsSymbols: string[];
329
- }
330
- interface SwapParams {
331
- assetIn: string;
332
- amountIn: string;
333
- assetOut: string;
334
- minimumAmountOut?: string;
335
- receiver?: Address;
336
- }
337
- interface SwapResult<TTxOutput = unknown> {
338
- txOutput: TTxOutput;
339
- amountOut: string;
340
- assetOut: string;
341
- txHash: string;
342
- }
343
-
344
- /**
345
- * Abstract base client for all implementations of the Bolt SDK for different chains/networks.
346
- *
347
- * This class provides the foundation for blockchain-specific implementations,
348
- * defining the core interface for interacting with oracle and router contracts.
349
- *
350
- * @template TSigner - The type of the transaction signer specific to the blockchain implementation
351
- *
352
- * @example
353
- * ```typescript
354
- * class BoltCosmWasmClient extends BaseClient<OfflineSigner> {
355
- * // Implementation specific to CosmWasm
356
- * }
357
- * ```
358
- */
359
- declare abstract class BaseClient<TSigner = unknown> {
360
- /**
361
- * The RPC endpoint URL for connecting to the blockchain network
362
- */
363
- rpcEndpoint: Address;
364
- /**
365
- * Smart contract addresses for making Bolt queries and transactions in the blockchain
366
- */
367
- contracts: Contracts;
368
- /**
369
- * Creates a new instance of the BaseClient.
370
- *
371
- * @param config - Optional configuration object for the client
372
- * @param config.override - Override configuration for RPC endpoint and contract addresses
373
- * @param config.override.rpcEndpoint - The RPC endpoint URL for the blockchain network
374
- * @param config.override.contracts - Contract addresses for oracle and router
375
- * @param config.override.contracts.oracle - Address of the price oracle contract
376
- * @param config.override.contracts.router - Address of the swap router contract
377
- *
378
- * @throws {InvalidObjectError} Thrown when required configuration fields are missing
379
- *
380
- * @example
381
- * ```typescript
382
- * const client = new ConcreteClient({
383
- * override: {
384
- * rpcEndpoint: 'https://rpc.example.com',
385
- * contracts: {
386
- * oracle: 'archway1...',
387
- * router: 'archway1...'
388
- * }
389
- * }
390
- * });
391
- * ```
392
- */
393
- constructor(config?: ClientConfig);
394
- /**
395
- * Fetches the oracle configuration from the blockchain.
396
- *
397
- * @returns A promise that resolves to the oracle configuration containing
398
- * settings such as price expiration time and threshold ratio
399
- *
400
- * @example
401
- * ```typescript
402
- * const oracleConfig = await client.getOracleConfig();
403
- * console.log(`Price expiration: ${oracleConfig.priceExpireTime} seconds`);
404
- * ```
405
- */
406
- abstract getOracleConfig(): Promise<OracleConfig>;
407
- /**
408
- * Fetches all asset pairs supported by the oracle.
409
- *
410
- * @returns A promise that resolves to an array of oracle asset pairs,
411
- * each containing base and quote asset information with name, symbol and precision
412
- *
413
- * @example
414
- * ```typescript
415
- * const pairs = await client.getAllOracleAssetPairs();
416
- * pairs.forEach(pair => {
417
- * console.log(`${pair.base.symbol}/${pair.quote.symbol}`);
418
- * console.log(` Base: ${pair.base.name}`);
419
- * console.log(` Quote: ${pair.quote.name}`);
420
- * });
421
- * ```
422
- */
423
- abstract getAllOracleAssetPairs(): Promise<OracleAssetPair[]>;
424
- /**
425
- * Fetches the current price for a specific base/quote asset pair.
426
- *
427
- * @param baseAssetSymbol - The chain symbol of the base asset (e.g., "aarch", "ibc/...")
428
- * @param quoteAssetSymbol - The chain symbol of the quote asset (e.g., "aarch", "ibc/...")
429
- *
430
- * @returns A promise that resolves to an invertible price object containing
431
- * the current price from the oracle
432
- *
433
- * @example
434
- * ```typescript
435
- * // Get price of ARCH in terms of USDC
436
- * const priceResult = await client.getPrice("aarch", "ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D");
437
- * console.log(`1 ARCH = ${priceResult.price} USDC`);
438
- * ```
439
- */
440
- abstract getPrice(baseAssetSymbol: string, quoteAssetSymbol: string): Promise<InvertiblePrice>;
441
- /**
442
- * Fetches all available prices from the oracle.
443
- *
444
- * @returns A promise that resolves to an array of all current prices
445
- * available in the oracle with their respective asset pairs
446
- *
447
- * @example
448
- * ```typescript
449
- * const prices = await client.getAllPrices();
450
- * prices.forEach(priceData => {
451
- * console.log(`${priceData.assetPair}: ${priceData.price}`);
452
- * console.log(` Expires on: ${priceData.expiryTime}`);
453
- * });
454
- * ```
455
- */
456
- abstract getAllPrices(): Promise<Price[]>;
457
- /**
458
- * Fetches the router configuration from the blockchain.
459
- *
460
- * @returns A promise that resolves to the router configuration containing
461
- * settings such as default protocol fees, LP fees, and oracle configuration
462
- *
463
- * @example
464
- * ```typescript
465
- * const routerConfig = await client.getRouterConfig();
466
- * console.log(`Default protocol fee: ${routerConfig.defaultProtocolFee * 100}%`);
467
- * console.log(`Default LP fee: ${routerConfig.defaultLpFee * 100}%`);
468
- * ```
469
- */
470
- abstract getRouterConfig(): Promise<RouterConfig>;
471
- /**
472
- * Fetches the total liquidity for all base assets across all pools.
473
- *
474
- * @returns A promise that resolves to a record mapping pool addresses
475
- * to their respective base asset liquidity amounts
476
- *
477
- * @example
478
- * ```typescript
479
- * const liquidity = await client.getAllBaseAssetsLiquidity();
480
- * Object.entries(liquidity).forEach(([poolAddress, coin]) => {
481
- * console.log(`Pool ${poolAddress}: ${coin.amount} ${coin.denom}`);
482
- * });
483
- * ```
484
- */
485
- abstract getAllBaseAssetsLiquidity(): Promise<Record<Address, Coin>>;
486
- /**
487
- * Fetches all withdrawable quote assets for a specific user or liquidity provider.
488
- *
489
- * @param address - The blockchain address of the user or liquidity provider
490
- *
491
- * @returns A promise that resolves to a record mapping pool addresses
492
- * to arrays of withdrawable quote asset coins
493
- *
494
- * @example
495
- * ```typescript
496
- * const quotes = await client.getAllQuotesByUser("archway1...");
497
- * Object.entries(quotes).forEach(([poolAddress, coins]) => {
498
- * console.log(`Pool ${poolAddress}:`);
499
- * coins.forEach(coin => {
500
- * console.log(` ${coin.amount} ${coin.symbol}`);
501
- * });
502
- * });
503
- * ```
504
- */
505
- abstract getAllQuotesByUser(address: Address): Promise<Record<Address, Coin[]>>;
506
- /**
507
- * Fetches pool information for a specific base asset.
508
- *
509
- * @param baseAssetSymbol - The symbol of the base asset (e.g., "aarch", "ibc/...")
510
- *
511
- * @returns A promise that resolves to the pool information for the specified asset
512
- *
513
- * @example
514
- * ```typescript
515
- * const pool = await client.getPoolByBaseAsset("aarch");
516
- * console.log(`Pool address: ${pool.poolAddress}`);
517
- * console.log(`Base asset: ${pool.baseAssetSymbol}`);
518
- * console.log('Available quote assets:');
519
- * pool.quoteAssetsSymbols.forEach(symbol => {
520
- * console.log(` - ${symbol}`);
521
- * });
522
- * ```
523
- */
524
- abstract getPoolByBaseAsset(baseAssetSymbol: string): Promise<Pool>;
525
- /**
526
- * Fetches information for all available pools.
527
- *
528
- * @returns A promise that resolves to an array containing all pool information
529
- *
530
- * @example
531
- * ```typescript
532
- * const pools = await client.getAllPools();
533
- * pools.forEach(pool => {
534
- * console.log(`Pool ${pool.poolAddress}:`);
535
- * console.log(` Base: ${pool.baseAssetSymbol}`);
536
- * console.log(` Quotes: ${pool.quoteAssetsSymbols.join(', ')}`);
537
- * });
538
- * ```
539
- */
540
- abstract getAllPools(): Promise<Pool[]>;
541
- /**
542
- * Executes a "swap exact in" operation on the blockchain from one asset to another.
543
- *
544
- * This method performs a swap where the exact input amount is specified, and the output
545
- * amount varies based on current pool conditions and fees. The transaction includes
546
- * slippage protection through the optional minimumAmountOut parameter.
547
- *
548
- * @param signer - The transaction signer that will authorize the swap operation.
549
- * Must have sufficient balance of the input asset.
550
- * @param params - The swap configuration parameters
551
- * @param params.assetIn - The denom of the asset being sold (e.g., "aarch", "ibc/...")
552
- * @param params.amountIn - The exact amount of input asset to swap (in minimal denomination)
553
- * @param params.assetOut - The denom of the asset being bought (e.g., "aarch", "ibc/...")
554
- * @param params.minimumAmountOut - Optional minimum acceptable amount of output asset.
555
- * Transaction will fail if actual output would be less.
556
- * @param params.receiver - Optional recipient address for the swapped assets.
557
- * If not provided, defaults to the signer's address.
558
- *
559
- * @returns A promise that resolves to the swap result containing transaction
560
- * details and the actual amount of output asset received
561
- *
562
- * @throws Will throw an error if the swap fails due to insufficient balance,
563
- * slippage exceeding tolerance, or other transaction errors
564
- *
565
- * @example
566
- * ```typescript
567
- * // Swap exactly 1 ARCH for USDC (output amount varies)
568
- * const result = await client.swapExactIn(signer, {
569
- * assetIn: "aarch",
570
- * amountIn: "1000000000000000000", // Exactly 1 ARCH (18 decimals)
571
- * assetOut: "ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D", // USDC IBC denom
572
- * minimumAmountOut: "1950000000", // Accept no less than 1950 USDC
573
- * receiver: "archway1..." // Optional custom receiver
574
- * });
575
- *
576
- * console.log(`Swapped exactly 1 ARCH`);
577
- * console.log(`Received: ${result.amountOut} USDC`);
578
- * console.log(`Transaction: ${result.txHash}`);
579
- * ```
580
- *
581
- * @remarks
582
- * This is a "swap exact in" operation where:
583
- * - The input amount is exactly what you specify
584
- * - The output amount depends on pool conditions
585
- * - Fees are deducted from the output
586
- * - Use minimumAmountOut to protect against excessive slippage
587
- */
588
- abstract swapExactIn(signer: TSigner, params: SwapParams): Promise<SwapResult>;
589
- }
590
-
591
- interface CosmWasmClientConfig extends ClientConfig {
10
+ type CosmWasmClientConfig = ClientConfig<CosmWasmChainConfig> & {
592
11
  chain?: CosmWasmChain;
593
- }
594
- declare enum CosmWasmChain {
595
- Archway = "archway"
596
- }
12
+ cosmWasmClient?: CosmWasmClient | ArchwayClient;
13
+ signer?: OfflineSigner;
14
+ signingCosmWasmClient?: SigningCosmWasmClient | SigningArchwayClient;
15
+ };
16
+ type CosmWasmChain = 'archway';
17
+ type SignerWithSigningClient = {
18
+ signer: OfflineSigner;
19
+ signingCosmWasmClient: SigningCosmWasmClient | SigningArchwayClient;
20
+ };
597
21
 
598
- interface QueryOracleConfigResponse {
22
+ type AssetPairString = string;
23
+ type QueryOracleConfigResponse = {
599
24
  admin: Address;
600
25
  price_threshold_ratio: string;
601
26
  price_expire_time: Duration | null;
602
- }
603
- interface PriceRepresentation {
27
+ };
28
+ type PriceRepresentation = {
604
29
  asset_pair: AssetPairString;
605
30
  price: string;
606
31
  expiry_time: Timestamp;
607
- }
608
- interface InvertiblePriceRepresentation extends PriceRepresentation {
32
+ };
33
+ type InvertiblePriceRepresentation = PriceRepresentation & {
609
34
  is_inverse: boolean;
610
- }
611
- interface QueryPriceResponse {
35
+ };
36
+ type QueryPriceResponse = {
612
37
  pair_data: InvertiblePriceRepresentation;
613
- }
614
- interface QueryPricesResponse {
38
+ };
39
+ type QueryPricesResponse = {
615
40
  prices: PriceRepresentation[];
616
- }
617
- interface QueryAssetPairsResponse {
41
+ };
42
+ type QueryAssetPairsResponse = {
618
43
  list: OracleAssetPair[];
619
- }
44
+ };
620
45
 
621
- interface QueryRouterConfigResponse {
46
+ type QuerySettlementConfigResponse = {
47
+ price_oracle_contract: Address;
48
+ protocol_fee_recipient: Address;
49
+ protocol_fee: string;
50
+ lp_fee: string;
51
+ allowance_mode: AllowanceMode;
52
+ lps: Address[];
53
+ min_base_out: string;
54
+ };
55
+ type QueryBaseLiquidityResponse = {
56
+ base_liquidity: Coin;
57
+ total_shares: string;
58
+ };
59
+
60
+ type QueryRouterConfigResponse = {
622
61
  admin: Address;
623
62
  default_price_oracle_contract: Address;
624
63
  default_protocol_fee_recipient: Address;
625
64
  default_protocol_fee: string;
626
65
  default_lp_fee: string;
627
66
  settlement_code_id: number;
628
- }
629
- interface MarketRepresentation {
67
+ };
68
+ type CosmWasmRouterConfig = RouterConfig & {
69
+ settlementCodeId: number;
70
+ };
71
+ type MarketRepresentation = {
630
72
  market_address: Address;
631
73
  base_asset_symbol: string;
632
74
  quote_assets_symbols: string[];
633
- }
634
- interface QueryMarketsResponse {
75
+ };
76
+ type QueryMarketsResponse = {
635
77
  markets: MarketRepresentation[];
636
- }
637
- interface QueryBaseLiquidityAllResponse {
638
- liquidity: Record<Address, Coin>;
639
- }
640
- interface QueryQuotesForUserAllResponse {
78
+ };
79
+ type QueryBaseLiquidityAllResponse = {
80
+ liquidity: Record<Address, QueryBaseLiquidityResponse>;
81
+ };
82
+ type QueryQuotesForUserAllResponse = {
641
83
  quotes: Record<Address, Coin[]>;
642
- }
84
+ };
85
+ type QuerySimulateSwapExactInResponse = {
86
+ from_pool: Address;
87
+ quote_in: Coin;
88
+ base_out: Coin;
89
+ protocol_fee: string;
90
+ lp_fee: string;
91
+ };
643
92
 
644
93
  /**
645
94
  * Client implementation for interacting with the Bolt Liquidity Outpost on CosmWasm-based blockchains.
646
95
  *
647
96
  * This class extends the abstract {@link BaseClient} to provide CosmWasm-specific functionality
648
97
  * for querying and executing transactions on Bolt Protocol's oracle and router smart contracts.
98
+ * It uses ExecuteResult as the transaction output type, providing detailed transaction execution information.
649
99
  *
650
- * @extends {BaseClient<OfflineSigner>}
100
+ * @extends {BaseClient<OfflineSigner, ExecuteResult>}
651
101
  *
652
102
  * @group Bolt API Clients
653
103
  *
654
104
  * @example
655
105
  * ```typescript
656
106
  * // Create a client for Archway mainnet
657
- * const client = new BoltCosmWasmClient({
658
- * environment: Environment.Mainnet,
659
- * chain: CosmWasmChain.Archway
660
- * });
107
+ * const client = new BoltCosmWasmClient();
661
108
  *
662
109
  * // Query oracle prices
663
- * const price = await client.getPrice("aarch", "ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D");
110
+ * const price = await client.getPrice("aarch", "ibc/...");
664
111
  *
665
112
  * // Execute a swap (requires signer)
666
113
  * const signer = await DirectSecp256k1HdWallet.fromMnemonic("my mnemonic goes here", {
667
114
  * prefix: 'archway',
668
115
  * });
669
- * const result = await client.swap(signer, {
116
+ * const result = await client.swap({
670
117
  * assetIn: "aarch",
671
118
  * amountIn: "1000000",
672
119
  * assetOut: "ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D"
673
- * });
120
+ * }, signer);
674
121
  * ```
675
122
  */
676
- declare class BoltCosmWasmClient extends BaseClient<OfflineSigner> {
123
+ declare class BoltCosmWasmClient extends BaseClient<OfflineSigner, ExecuteResult> {
124
+ /**
125
+ * The CosmWasm-specific chain configuration including REST endpoint
126
+ */
127
+ chainConfig: CosmWasmChainConfig;
677
128
  /**
678
129
  * Cached instance of the CosmWasm client for read-only operations
679
130
  * @private
680
131
  */
681
132
  private _cosmWasmClient?;
133
+ /**
134
+ * Cached instance of the Signer for transaction execution
135
+ * @private
136
+ */
137
+ private _signer?;
682
138
  /**
683
139
  * Cached instance of the signing CosmWasm client for transaction execution
684
140
  * @private
@@ -692,16 +148,26 @@ declare class BoltCosmWasmClient extends BaseClient<OfflineSigner> {
692
148
  * Creates a new instance of the BoltCosmWasmClient.
693
149
  *
694
150
  * The client automatically configures itself based on the specified chain and environment,
695
- * loading the appropriate contract addresses and RPC endpoints from configuration files.
151
+ * loading the appropriate contract addresses, chain configuration, native token denomination,
152
+ * and assets from configuration files.
696
153
  *
697
154
  * @param config - (Optional) Configuration for the client
698
- * @param config.environment - (Optional) The deployment environment (Mainnet or Testnet). Defaults to Mainnet
699
- * @param config.chain - (Optional) The specific CosmWasm chain to connect to. Defaults to Archway
700
- * @param config.override - (Optional) Overrides for RPC endpoint and contract addresses
701
- * @param config.override.rpcEndpoint - (Optional) Custom RPC endpoint URL
702
- * @param config.override.contracts - (Optional) Custom contract addresses
703
- * @param config.override.contracts.oracle - (Optional) Custom oracle contract address
704
- * @param config.override.contracts.router - (Optional) Custom router contract address
155
+ * @param config.environment - (Optional) The deployment environment ('mainnet' or 'testnet'). Defaults to 'mainnet'
156
+ * @param config.chain - (Optional) The specific CosmWasm chain to connect to. Defaults to 'archway'
157
+ * @param config.customOverride - (Optional) Custom overrides for chain configuration, contracts, native token, and assets
158
+ * @param config.customOverride.chainConfig - (Optional) Override chain configuration
159
+ * @param config.customOverride.chainConfig.id - (Optional) Custom chain ID
160
+ * @param config.customOverride.chainConfig.name - (Optional) Custom chain name
161
+ * @param config.customOverride.chainConfig.rpcEndpoint - (Optional) Custom RPC endpoint URL
162
+ * @param config.customOverride.chainConfig.restEndpoint - (Optional) Custom REST endpoint URL
163
+ * @param config.customOverride.contracts - (Optional) Override contract addresses
164
+ * @param config.customOverride.contracts.oracle - (Optional) Custom oracle contract address
165
+ * @param config.customOverride.contracts.router - (Optional) Custom router contract address
166
+ * @param config.customOverride.nativeTokenDenom - (Optional) Custom native token denomination (e.g., "aarch")
167
+ * @param config.customOverride.assetsConfig - (Optional) Custom asset configurations indexed by denom
168
+ * @param config.cosmWasmClient - (Optional) Pre-existing CosmWasmClient to use for blockchain queries
169
+ * @param config.signer - (Optional) Pre-existing OfflineSigner for transaction signing
170
+ * @param config.signingCosmWasmClient - (Optional) Pre-existing SigningCosmWasmClient to use for blockchain transactions
705
171
  *
706
172
  * @throws {InvalidTypeError} Thrown when an unsupported chain is specified
707
173
  *
@@ -712,15 +178,43 @@ declare class BoltCosmWasmClient extends BaseClient<OfflineSigner> {
712
178
  *
713
179
  * // Use testnet configuration
714
180
  * const testnetClient = new BoltCosmWasmClient({
715
- * environment: Environment.Testnet
181
+ * environment: 'testnet'
716
182
  * });
717
183
  *
718
- * // Use custom RPC endpoint
184
+ * // Use custom chain configuration
719
185
  * const customClient = new BoltCosmWasmClient({
720
- * override: {
721
- * rpcEndpoint: 'https://custom-rpc.example.com'
186
+ * customOverride: {
187
+ * chainConfig: {
188
+ * id: 'archway-custom-1',
189
+ * name: 'Archway Custom',
190
+ * rpcEndpoint: 'https://custom-rpc.example.com',
191
+ * restEndpoint: 'https://custom-rest.example.com'
192
+ * },
193
+ * contracts: {
194
+ * oracle: 'archway1custom_oracle...',
195
+ * router: 'archway1custom_router...'
196
+ * },
197
+ * nativeTokenDenom: 'aarch',
198
+ * assetsConfig: {
199
+ * 'aarch': {
200
+ * symbol: 'ARCH',
201
+ * name: 'Archway',
202
+ * chainId: 'archway-custom-1',
203
+ * denom: 'aarch',
204
+ * decimals: 18,
205
+ * logo: 'https://example.com/arch.png',
206
+ * coingeckoId: 'archway'
207
+ * }
208
+ * }
722
209
  * }
723
210
  * });
211
+ *
212
+ * // Use pre-existing CosmWasm clients
213
+ * const clientWithCustomClients = new BoltCosmWasmClient({
214
+ * cosmWasmClient: myCosmWasmClient,
215
+ * signer: mySigner,
216
+ * signingCosmWasmClient: mySigningClient
217
+ * });
724
218
  * ```
725
219
  */
726
220
  constructor(config?: CosmWasmClientConfig);
@@ -742,18 +236,18 @@ declare class BoltCosmWasmClient extends BaseClient<OfflineSigner> {
742
236
  */
743
237
  getCosmWasmClient(): Promise<CosmWasmClient | ArchwayClient>;
744
238
  /**
745
- * Gets or creates a signing CosmWasm client instance for transaction execution.
239
+ * Gets or creates a signing CosmWasm client instance along with the signer for transaction execution.
746
240
  *
747
- * This method implements lazy initialization and caching of the signing client.
241
+ * This method implements lazy initialization and caching of both the signing client and signer.
748
242
  * A signer must be provided either on first call or to replace the cached instance.
749
243
  * The appropriate client type is selected based on the configured chain.
750
244
  *
751
- * @param signer - Optional offline signer for transaction signing. Required on first call
752
- * or to replace the existing signer
245
+ * @param newSigner - Optional offline signer for transaction signing. Required on first call
246
+ * or to replace the existing signer
753
247
  *
754
- * @returns A promise that resolves to the signing CosmWasm client instance
248
+ * @returns A promise that resolves to an object containing both the signer and signing client
755
249
  *
756
- * @throws {MissingParameterError} Thrown when no signer is provided and no cached client exists
250
+ * @throws {MissingParameterError} Thrown when no signer is provided and no cached signer exists
757
251
  *
758
252
  * @example
759
253
  * ```typescript
@@ -761,31 +255,51 @@ declare class BoltCosmWasmClient extends BaseClient<OfflineSigner> {
761
255
  * const signer = await DirectSecp256k1HdWallet.fromMnemonic("my mnemonic goes here", {
762
256
  * prefix: 'archway',
763
257
  * });
764
- * const signingClient = await boltClient.getSigningCosmWasmClient(signer);
258
+ * const { signer: cachedSigner, signingCosmWasmClient } = await boltClient.getSignerWithSigningClient(signer);
765
259
  *
766
- * // Subsequent calls can reuse the cached client
767
- * const cachedClient = await boltClient.getSigningCosmWasmClient();
260
+ * // Subsequent calls can reuse the cached signer and client
261
+ * const { signer, signingCosmWasmClient: client } = await boltClient.getSignerWithSigningClient();
768
262
  * ```
769
263
  */
770
- getSigningCosmWasmClient(signer?: OfflineSigner): Promise<SigningCosmWasmClient | SigningArchwayClient>;
264
+ getSignerWithSigningClient(newSigner?: OfflineSigner): Promise<SignerWithSigningClient>;
771
265
  /** @inheritdoc */
772
266
  getOracleConfig(): Promise<OracleConfig>;
773
267
  /** @inheritdoc */
774
268
  getAllOracleAssetPairs(): Promise<OracleAssetPair[]>;
775
269
  /** @inheritdoc */
776
- getPrice(baseAssetSymbol: string, quoteAssetSymbol: string): Promise<InvertiblePrice>;
270
+ getPrice(baseDenom: string, quoteDenom: string): Promise<InvertiblePrice>;
777
271
  /** @inheritdoc */
778
272
  getAllPrices(): Promise<Price[]>;
779
273
  /** @inheritdoc */
780
274
  getRouterConfig(): Promise<RouterConfig>;
781
275
  /** @inheritdoc */
782
- getAllBaseAssetsLiquidity(): Promise<Record<Address, Coin>>;
276
+ getAllBaseAssetsLiquidity(): Promise<Record<Address, BaseLiquidityDetails>>;
783
277
  /** @inheritdoc */
784
278
  getAllQuotesByUser(address: Address): Promise<Record<Address, Coin[]>>;
785
- /** @inheritdoc */
786
- getPoolByBaseAsset(baseAssetSymbol: string): Promise<Pool>;
279
+ /**
280
+ * @inheritdoc
281
+ *
282
+ * @remarks
283
+ * In the CosmWasm implementation, this method only uses the `baseDenom` parameter.
284
+ * The optional `quoteDenom` parameter is ignored as pools are uniquely identified
285
+ * by their base asset in the current CosmWasm architecture.
286
+ */
287
+ getPoolByDenom(baseDenom: string): Promise<Pool>;
787
288
  /** @inheritdoc */
788
289
  getAllPools(): Promise<Pool[]>;
290
+ /** @inheritdoc */
291
+ getPoolConfig(poolContractAddress: Address): Promise<PoolConfig>;
292
+ /** @inheritdoc */
293
+ getAssets(): Promise<Asset[]>;
294
+ /**
295
+ * @inheritdoc
296
+ *
297
+ * @remarks
298
+ * In the CosmWasm implementation, this method only uses the `baseDenom` parameter.
299
+ * The optional `quoteDenom` parameter is ignored as pools are uniquely identified
300
+ * by their base asset in the current CosmWasm architecture.
301
+ */
302
+ getPoolConfigByDenom(baseDenom: string): Promise<PoolConfig>;
789
303
  /**
790
304
  * @inheritdoc
791
305
  *
@@ -795,21 +309,56 @@ declare class BoltCosmWasmClient extends BaseClient<OfflineSigner> {
795
309
  * const signer = await window.keplr.getOfflineSignerAuto(chainId);
796
310
  *
797
311
  * // Execute swap: 1 ARCH for USDC
798
- * const result = await client.swap(signer, {
312
+ * const result = await client.swap({
799
313
  * assetIn: "aarch",
800
314
  * amountIn: "1000000000000000000", // 1 ARCH (18 decimals)
801
315
  * assetOut: "ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D", // USDC IBC denom
802
316
  * minimumAmountOut: "1950000000", // Minimum 1950 USDC expected
803
317
  * receiver: "archway1..." // Optional custom receiver
804
- * });
318
+ * }, signer);
805
319
  *
806
320
  * console.log(`Swap successful!`);
807
321
  * console.log(`Transaction hash: ${result.txHash}`);
808
322
  * console.log(`Received: ${result.amountOut} ${result.assetOut}`);
809
- * console.log(`Gas used: ${result.gasUsed}`);
323
+ * console.log(`Gas used: ${result.txOutput.gasUsed}`);
324
+ * console.log(`Block height: ${result.txOutput.height}`);
325
+ * ```
326
+ *
327
+ * @remarks
328
+ * This implementation returns a CosmWasm ExecuteResult as the transaction output,
329
+ * which includes details like gas used, block height, transaction hash, and events.
330
+ */
331
+ swap(params: SwapParams, signer?: OfflineSigner): Promise<SwapResult<ExecuteResult>>;
332
+ /**
333
+ * @inheritdoc
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * // Get signer (e.g., from Keplr wallet)
338
+ * const signer = await window.keplr.getOfflineSignerAuto(chainId);
339
+ *
340
+ * // Estimate gas for swapping 1 ARCH to USDC
341
+ * const gasEstimate = await client.estimateSwapGasFees({
342
+ * assetIn: "aarch",
343
+ * amountIn: "1000000000000000000", // 1 ARCH
344
+ * assetOut: "ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D", // USDC
345
+ * minimumAmountOut: "1950000000" // Min 1950 USDC
346
+ * }, signer, 1.3); // 30% safety margin
347
+ *
348
+ * if (gasEstimate) {
349
+ * console.log(`Estimated gas: ${gasEstimate.amount} ${gasEstimate.denom}`);
350
+ * }
810
351
  * ```
352
+ *
353
+ * @remarks
354
+ * - For CosmWasm chains, gas is always paid in the native token (e.g., "aarch" for Archway)
355
+ * - The returned amount is in the smallest denomination (6 decimals for most Cosmos chains)
356
+ * - Gas estimation uses CosmWasm's simulation capabilities
357
+ * - The gasAdjustment parameter helps account for variations in actual execution
811
358
  */
812
- swapExactIn(signer: OfflineSigner, params: SwapParams): Promise<SwapResult<ExecuteResult>>;
359
+ estimateSwapGasFees(params: SwapParams, signer: OfflineSigner, gasAdjustment?: number): Promise<Coin | undefined>;
360
+ /** @inheritdoc */
361
+ simulateSwap(params: SwapRequiredParams): Promise<SimulateSwapResult>;
813
362
  }
814
363
 
815
- export { type Address, type AssetPairString, BoltCosmWasmClient, type BoltSdkError, BoltSdkErrorBase, BoltSdkErrorCode, type ClientConfig, type Coin, type Contracts, CosmWasmChain, type CosmWasmClientConfig, type Duration, Environment, InsufficientFundsError, InvalidAddressError, InvalidObjectError, InvalidParameterError, InvalidTypeError, type InvertiblePrice, type InvertiblePriceRepresentation, type MarketRepresentation, MissingParameterError, NetworkError, NotFoundError, type OracleAsset, type OracleAssetPair, type OracleConfig, ParameterOutOfRangeError, type Pool, type Price, type PriceRepresentation, type QueryAssetPairsResponse, type QueryBaseLiquidityAllResponse, type QueryMarketsResponse, type QueryOracleConfigResponse, type QueryPriceResponse, type QueryPricesResponse, type QueryQuotesForUserAllResponse, type QueryRouterConfigResponse, type RouterConfig, type SwapParams, type SwapResult, type Timestamp, TransactionEventNotFoundError, TransactionFailedError };
364
+ export { type AssetPairString, BoltCosmWasmClient, type CosmWasmChain, type CosmWasmChainConfig, type CosmWasmClientConfig, type CosmWasmRouterConfig, type InvertiblePriceRepresentation, type MarketRepresentation, type PriceRepresentation, type QueryAssetPairsResponse, type QueryBaseLiquidityAllResponse, type QueryBaseLiquidityResponse, type QueryMarketsResponse, type QueryOracleConfigResponse, type QueryPriceResponse, type QueryPricesResponse, type QueryQuotesForUserAllResponse, type QueryRouterConfigResponse, type QuerySettlementConfigResponse, type QuerySimulateSwapExactInResponse, type SignerWithSigningClient };