@bolt-liquidity-hq/cosmwasm-client 0.1.0-beta.7 → 0.1.0-beta.9

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.cjs CHANGED
@@ -22,302 +22,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22
22
  // src/index.ts
23
23
  var index_exports = {};
24
24
  __export(index_exports, {
25
- BaseClient: () => BaseClient,
26
- BoltCosmWasmClient: () => BoltCosmWasmClient,
27
- BoltSdkErrorBase: () => BoltSdkErrorBase,
28
- BoltSdkErrorCode: () => BoltSdkErrorCode,
29
- InsufficientFundsError: () => InsufficientFundsError,
30
- InvalidAddressError: () => InvalidAddressError,
31
- InvalidObjectError: () => InvalidObjectError,
32
- InvalidParameterError: () => InvalidParameterError,
33
- InvalidTypeError: () => InvalidTypeError,
34
- MissingParameterError: () => MissingParameterError,
35
- NetworkError: () => NetworkError,
36
- NotFoundError: () => NotFoundError,
37
- ParameterOutOfRangeError: () => ParameterOutOfRangeError,
38
- TransactionEventNotFoundError: () => TransactionEventNotFoundError,
39
- TransactionFailedError: () => TransactionFailedError
25
+ BoltCosmWasmClient: () => BoltCosmWasmClient
40
26
  });
41
27
  module.exports = __toCommonJS(index_exports);
42
28
 
43
29
  // src/lib/client.ts
44
30
  var import_arch3 = require("@archwayhq/arch3.js");
31
+ var import_core3 = require("@bolt-liquidity-hq/core");
45
32
  var import_cosmwasm_stargate = require("@cosmjs/cosmwasm-stargate");
46
33
 
47
- // src/common/errors.ts
48
- var BoltSdkErrorCode = /* @__PURE__ */ ((BoltSdkErrorCode2) => {
49
- BoltSdkErrorCode2[BoltSdkErrorCode2["NOT_FOUND"] = 1e3] = "NOT_FOUND";
50
- BoltSdkErrorCode2[BoltSdkErrorCode2["INVALID_OBJECT"] = 1001] = "INVALID_OBJECT";
51
- BoltSdkErrorCode2[BoltSdkErrorCode2["INVALID_TYPE"] = 1002] = "INVALID_TYPE";
52
- BoltSdkErrorCode2[BoltSdkErrorCode2["INSUFFICIENT_FUNDS"] = 2e3] = "INSUFFICIENT_FUNDS";
53
- BoltSdkErrorCode2[BoltSdkErrorCode2["INVALID_ADDRESS"] = 2001] = "INVALID_ADDRESS";
54
- BoltSdkErrorCode2[BoltSdkErrorCode2["TRANSACTION_FAILED"] = 2002] = "TRANSACTION_FAILED";
55
- BoltSdkErrorCode2[BoltSdkErrorCode2["TRANSACTION_EVENT_NOT_FOUND"] = 2003] = "TRANSACTION_EVENT_NOT_FOUND";
56
- BoltSdkErrorCode2[BoltSdkErrorCode2["NETWORK_ERROR"] = 3e3] = "NETWORK_ERROR";
57
- BoltSdkErrorCode2[BoltSdkErrorCode2["INVALID_PARAMETER"] = 4e3] = "INVALID_PARAMETER";
58
- BoltSdkErrorCode2[BoltSdkErrorCode2["MISSING_PARAMETER"] = 4001] = "MISSING_PARAMETER";
59
- BoltSdkErrorCode2[BoltSdkErrorCode2["PARAMETER_OUT_OF_RANGE"] = 4002] = "PARAMETER_OUT_OF_RANGE";
60
- return BoltSdkErrorCode2;
61
- })(BoltSdkErrorCode || {});
62
- var BoltSdkErrorBase = class extends Error {
63
- /**
64
- * Creates a new BoltSdkErrorBase instance.
65
- *
66
- * @param code - The error code categorizing this error
67
- * @param message - Human-readable error message
68
- */
69
- constructor(code, message) {
70
- super(message);
71
- this.code = code;
72
- this.name = this.constructor.name;
73
- }
74
- };
75
- var NotFoundError = class extends BoltSdkErrorBase {
76
- /**
77
- * Creates a new NotFoundError instance.
78
- *
79
- * @param resource - The type of resource that was not found
80
- * @param details - Optional additional details about what was searched for
81
- */
82
- constructor(resource, details) {
83
- super(
84
- 1e3 /* NOT_FOUND */,
85
- `Resource not found: ${resource}.${details ? ` Details: ${details}` : ""}`
86
- );
87
- }
88
- };
89
- var InvalidObjectError = class extends BoltSdkErrorBase {
90
- /**
91
- * Creates a new InvalidObjectError instance.
92
- *
93
- * @param details - Optional description of what is invalid about the object
94
- */
95
- constructor(details) {
96
- super(
97
- 1001 /* INVALID_OBJECT */,
98
- `Invalid object or data structure!${details ? ` Details: ${details}` : ""}`
99
- );
100
- }
101
- };
102
- var InvalidTypeError = class extends BoltSdkErrorBase {
103
- /**
104
- * Creates a new InvalidTypeError instance.
105
- *
106
- * @param expectedType - The type that was expected
107
- * @param receivedType - The actual type that was received
108
- */
109
- constructor(expectedType, receivedType) {
110
- super(
111
- 1002 /* INVALID_TYPE */,
112
- `Invalid object type! Expected: ${expectedType}, Received: ${receivedType}`
113
- );
114
- }
115
- };
116
- var InsufficientFundsError = class extends BoltSdkErrorBase {
117
- /**
118
- * Creates a new InsufficientFundsError instance.
119
- *
120
- * @param required - The amount required for the operation
121
- * @param available - The amount available in the account
122
- */
123
- constructor(required, available) {
124
- super(
125
- 2e3 /* INSUFFICIENT_FUNDS */,
126
- `Insufficient funds to complete the transaction! Required: ${required}, Available: ${available}`
127
- );
128
- }
129
- };
130
- var InvalidAddressError = class extends BoltSdkErrorBase {
131
- /**
132
- * Creates a new InvalidAddressError instance.
133
- *
134
- * @param address - The invalid address that was provided
135
- */
136
- constructor(address) {
137
- super(2001 /* INVALID_ADDRESS */, `Invalid blockchain address provided: ${address}`);
138
- }
139
- };
140
- var TransactionFailedError = class extends BoltSdkErrorBase {
141
- /**
142
- * Creates a new TransactionFailedError instance.
143
- *
144
- * @param transactionId - The transaction hash or identifier
145
- * @param details - Optional details about why the transaction failed
146
- */
147
- constructor(transactionId, details) {
148
- super(
149
- 2002 /* TRANSACTION_FAILED */,
150
- `Transaction failed or was reverted! Transaction ID: ${transactionId}.${details ? ` Details: ${details}` : ""}`
151
- );
152
- }
153
- };
154
- var TransactionEventNotFoundError = class extends BoltSdkErrorBase {
155
- /**
156
- * Creates a new TransactionEventNotFoundError instance.
157
- *
158
- * @param eventName - The name of the event that was expected
159
- * @param details - Optional details about the context
160
- */
161
- constructor(eventName, details) {
162
- super(
163
- 2003 /* TRANSACTION_EVENT_NOT_FOUND */,
164
- `Transaction Event not found: ${eventName}.${details ? ` Details: ${details}` : ""}`
165
- );
166
- }
167
- };
168
- var NetworkError = class extends BoltSdkErrorBase {
169
- /**
170
- * Creates a new NetworkError instance.
171
- *
172
- * @param details - Optional details about the network failure
173
- */
174
- constructor(details) {
175
- super(
176
- 3e3 /* NETWORK_ERROR */,
177
- `Network error occurred!${details ? ` Details: ${details}` : ""}`
178
- );
179
- }
180
- };
181
- var InvalidParameterError = class extends BoltSdkErrorBase {
182
- /**
183
- * Creates a new InvalidParameterError instance.
184
- *
185
- * @param parameterName - The name of the invalid parameter
186
- * @param expected - Description of what was expected
187
- * @param receivedValue - The actual value that was provided
188
- * @param details - Optional additional details or constraints
189
- *
190
- * @template T - The type of the received value
191
- */
192
- constructor(parameterName, expected, receivedValue, details) {
193
- super(
194
- 4e3 /* INVALID_PARAMETER */,
195
- `Invalid parameter '${parameterName}': expected ${expected}, received ${typeof receivedValue}${details ? `. ${details}` : ""}`
196
- );
197
- }
198
- };
199
- var MissingParameterError = class extends BoltSdkErrorBase {
200
- /**
201
- * Creates a new MissingParameterError instance.
202
- *
203
- * @param parameterName - The name of the missing parameter
204
- * @param context - Optional context about where the parameter was expected
205
- */
206
- constructor(parameterName, context) {
207
- super(
208
- 4001 /* MISSING_PARAMETER */,
209
- `Required parameter '${parameterName}' is missing${context ? ` in ${context}` : ""}`
210
- );
211
- }
212
- };
213
- var ParameterOutOfRangeError = class extends BoltSdkErrorBase {
214
- /**
215
- * Creates a new ParameterOutOfRangeError instance.
216
- *
217
- * @param parameterName - The name of the parameter that's out of range
218
- * @param value - The actual value that was provided
219
- * @param min - Optional minimum acceptable value (inclusive)
220
- * @param max - Optional maximum acceptable value (inclusive)
221
- * @param details - Optional additional details about the constraint
222
- */
223
- constructor(parameterName, value, min, max, details) {
224
- let rangeMessage = "";
225
- if (min !== void 0 && max !== void 0) {
226
- rangeMessage = ` Expected value between ${min} and ${max}, but received ${value}`;
227
- } else if (min !== void 0) {
228
- rangeMessage = ` Expected value >= ${min}, but received ${value}`;
229
- } else if (max !== void 0) {
230
- rangeMessage = ` Expected value <= ${max}, but received ${value}`;
231
- }
232
- super(
233
- 4002 /* PARAMETER_OUT_OF_RANGE */,
234
- `Parameter '${parameterName}' is out of range.${rangeMessage}${details ? `. ${details}` : ""}`
235
- );
236
- }
237
- };
238
-
239
- // src/common/helpers/asset.ts
240
- var getCoinFromAmountWithDenomString = (amountWithDenom) => {
241
- const match = amountWithDenom.match(/^(\d+)(.+)$/);
242
- if (!match || !match[1] || !match[2]) {
243
- throw new InvalidParameterError(
244
- "amountWithDenom",
245
- "a string with the amount followed by the denom",
246
- amountWithDenom
247
- );
248
- }
249
- return { amount: match[1], denom: match[2] };
250
- };
251
-
252
- // src/common/lib/client.ts
253
- var BaseClient = class {
254
- /**
255
- * Creates a new instance of the BaseClient.
256
- *
257
- * @param config - (Optional) Configuration object for the client
258
- * @param config.customOverride - (Optional) Override configuration containing chain settings, contracts, and assets
259
- * @param config.customOverride.chainConfig - (Optional) Chain configuration object
260
- * @param config.customOverride.chainConfig.id - (Optional) The chain ID of the blockchain network (e.g., "archway-1")
261
- * @param config.customOverride.chainConfig.name - (Optional) The human-readable name of the chain (e.g., "Archway")
262
- * @param config.customOverride.chainConfig.rpcEndpoint - (Optional) RPC endpoint URL for the blockchain network
263
- * @param config.customOverride.contracts - (Optional) Contract addresses for oracle and router
264
- * @param config.customOverride.contracts.oracle - (Optional) Oracle contract address
265
- * @param config.customOverride.contracts.router - (Optional) Router contract address
266
- * @param config.customOverride.assetsConfig - (Optional) Configuration for supported assets indexed by symbol
267
- *
268
- * @throws {InvalidObjectError} Thrown when required configuration fields are missing
269
- *
270
- * @example
271
- * ```typescript
272
- * const client = new ConcreteClient({
273
- * customOverride: {
274
- * chainConfig: {
275
- * id: 'archway-1',
276
- * name: 'Archway',
277
- * rpcEndpoint: 'https://rpc.example.com'
278
- * },
279
- * contracts: {
280
- * oracle: 'archway1oracle...',
281
- * router: 'archway1router...'
282
- * },
283
- * assetsConfig: {
284
- * 'ARCH': {
285
- * symbol: 'ARCH',
286
- * name: 'Archway',
287
- * chainId: 'archway-1',
288
- * denom: 'aarch',
289
- * decimals: 18,
290
- * logo: 'https://...',
291
- * coingeckoId: 'archway'
292
- * }
293
- * }
294
- * }
295
- * });
296
- * ```
297
- */
298
- constructor(config) {
299
- /**
300
- * The blockchain network configuration containing chain ID, name, and RPC endpoint
301
- */
302
- __publicField(this, "chainConfig");
303
- /**
304
- * Smart contract addresses for making Bolt queries and transactions in the blockchain
305
- */
306
- __publicField(this, "contracts");
307
- /**
308
- * Configuration mapping of supported assets indexed by their symbol
309
- */
310
- __publicField(this, "assetsConfig");
311
- const { customOverride: { chainConfig, contracts, assetsConfig } = {} } = config ?? {};
312
- if (!chainConfig || !chainConfig?.id || !chainConfig?.name || !chainConfig?.rpcEndpoint || !contracts?.oracle || !contracts?.router || !assetsConfig) {
313
- throw new InvalidObjectError("ClientConfig is missing fields");
314
- }
315
- this.chainConfig = chainConfig;
316
- this.contracts = contracts;
317
- this.assetsConfig = assetsConfig;
318
- }
319
- };
320
-
321
34
  // src/config/archway-mainnet.ts
322
35
  var ArchwayMainnetChainConfig = {
323
36
  name: "Archway",
@@ -5799,10 +5512,11 @@ var parseQueryBaseLiquidityAllResponse = (response) => {
5799
5512
  };
5800
5513
 
5801
5514
  // src/lib/helpers/transactions.ts
5515
+ var import_core = require("@bolt-liquidity-hq/core");
5802
5516
  var getSignerAddress = async (signer) => {
5803
5517
  const accounts = await signer.getAccounts();
5804
5518
  if (!accounts?.[0]) {
5805
- throw new NotFoundError("Signer account's address");
5519
+ throw new import_core.NotFoundError("Signer account's address");
5806
5520
  }
5807
5521
  return accounts[0].address;
5808
5522
  };
@@ -5879,6 +5593,9 @@ var getRouterConfig = async (client) => {
5879
5593
  return parseQueryRouterConfigResponse(response);
5880
5594
  };
5881
5595
 
5596
+ // src/lib/router/swap-exact-in.ts
5597
+ var import_core2 = require("@bolt-liquidity-hq/core");
5598
+
5882
5599
  // src/lib/constants/events.ts
5883
5600
  var BOLT_SWAP_EVENT_TYPE = "wasm-bolt_swap";
5884
5601
  var BOLT_COIN_RECEIVED_EVENT_TYPE = "coin_received";
@@ -5906,7 +5623,7 @@ var swapExactIn = async (client, signer, { assetIn, amountIn, assetOut, minimumA
5906
5623
  (item) => item.type === BOLT_SWAP_EVENT_TYPE
5907
5624
  );
5908
5625
  if (boltSwapEventIndex === -1) {
5909
- throw new TransactionEventNotFoundError(
5626
+ throw new import_core2.TransactionEventNotFoundError(
5910
5627
  BOLT_SWAP_EVENT_TYPE,
5911
5628
  "After the transaction was executed, no successful swap event was emitted, the transaction may have failed"
5912
5629
  );
@@ -5919,14 +5636,14 @@ var swapExactIn = async (client, signer, { assetIn, amountIn, assetOut, minimumA
5919
5636
  )?.value;
5920
5637
  if (amountWithDenomOut) {
5921
5638
  try {
5922
- amountOut = getCoinFromAmountWithDenomString(amountWithDenomOut).amount;
5639
+ amountOut = (0, import_core2.getCoinFromAmountWithDenomString)(amountWithDenomOut).amount;
5923
5640
  break;
5924
5641
  } catch {
5925
5642
  }
5926
5643
  }
5927
5644
  }
5928
5645
  if (!amountOut) {
5929
- throw new TransactionEventNotFoundError(
5646
+ throw new import_core2.TransactionEventNotFoundError(
5930
5647
  BOLT_COIN_RECEIVED_EVENT_TYPE,
5931
5648
  "After the transaction was executed, no coin received event was emitted, the transaction may have failed"
5932
5649
  );
@@ -5955,7 +5672,7 @@ var getSettlementConfigForBase = async (client, baseAssetSymbol) => {
5955
5672
  };
5956
5673
 
5957
5674
  // src/lib/client.ts
5958
- var BoltCosmWasmClient = class extends BaseClient {
5675
+ var BoltCosmWasmClient = class extends import_core3.BaseClient {
5959
5676
  /**
5960
5677
  * Creates a new instance of the BoltCosmWasmClient.
5961
5678
  *
@@ -6042,7 +5759,7 @@ var BoltCosmWasmClient = class extends BaseClient {
6042
5759
  assetsConfig = environment === "mainnet" ? ArchwayMainnetAssets : ArchwayTestnetAssets;
6043
5760
  break;
6044
5761
  default:
6045
- throw new InvalidTypeError("A valid value of CosmWasmChain", chain);
5762
+ throw new import_core3.InvalidTypeError("A valid value of CosmWasmChain", chain);
6046
5763
  }
6047
5764
  const chainConfig = {
6048
5765
  id: customOverride?.chainConfig?.id ?? defaultChainConfig.id,
@@ -6138,7 +5855,7 @@ var BoltCosmWasmClient = class extends BaseClient {
6138
5855
  async getSigningCosmWasmClient(signer) {
6139
5856
  if (!this._signingCosmWasmClient || signer) {
6140
5857
  if (!signer) {
6141
- throw new MissingParameterError("signer");
5858
+ throw new import_core3.MissingParameterError("signer");
6142
5859
  }
6143
5860
  this._signingCosmWasmClient = await (this.chain === "archway" ? import_arch3.SigningArchwayClient : import_cosmwasm_stargate.SigningCosmWasmClient).connectWithSigner(this.chainConfig.rpcEndpoint, signer);
6144
5861
  }
@@ -6190,32 +5907,7 @@ var BoltCosmWasmClient = class extends BaseClient {
6190
5907
  async getAllAssets() {
6191
5908
  return await getAllAssets(this);
6192
5909
  }
6193
- /**
6194
- * Fetches the configuration settings for a pool identified by its base asset symbol.
6195
- *
6196
- * This is a convenience method that combines pool lookup and configuration retrieval.
6197
- * It first finds the pool associated with the given base asset, then fetches that
6198
- * pool's configuration parameters from its settlement contract.
6199
- *
6200
- * @param baseAssetSymbol - The symbol of the base asset (e.g., "ARCH", "ATOM")
6201
- *
6202
- * @returns A promise that resolves to a pool configuration object containing
6203
- * settings such as fees, oracle address, LP addresses, and minimum trade amounts
6204
- *
6205
- * @throws Will throw an error if no pool exists for the specified base asset
6206
- *
6207
- * @example
6208
- * ```typescript
6209
- * // Get pool configuration for ARCH base asset
6210
- * const poolConfig = await client.getPoolConfigByBaseAsset("ARCH");
6211
- * console.log(`Oracle: ${poolConfig.priceOracleContract}`);
6212
- * console.log(`Protocol fee: ${parseFloat(poolConfig.protocolFee) * 100}%`);
6213
- * console.log(`LP fee: ${parseFloat(poolConfig.lpFee) * 100}%`);
6214
- * console.log(`Allowance mode: ${poolConfig.allowanceMode}`);
6215
- * console.log(`Number of LPs: ${poolConfig.lps.length}`);
6216
- * console.log(`Min base output: ${poolConfig.minBaseOut}`);
6217
- * ```
6218
- */
5910
+ /** @inheritdoc */
6219
5911
  async getPoolConfigByBaseAsset(baseAssetSymbol) {
6220
5912
  return await getSettlementConfigForBase(this, baseAssetSymbol);
6221
5913
  }