@bolt-liquidity-hq/cosmwasm-client 0.1.0-beta.2 → 0.1.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +87 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +170 -76
- package/dist/index.d.ts +170 -76
- package/dist/index.js +87 -25
- package/dist/index.js.map +1 -1
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ const price = await client.getPrice(
|
|
|
24
24
|
console.log(`ARCH/USDC: ${price.price}`);
|
|
25
25
|
|
|
26
26
|
// Execute a swap
|
|
27
|
-
const result = await client.
|
|
27
|
+
const result = await client.swap(signer, {
|
|
28
28
|
assetIn: 'aarch',
|
|
29
29
|
amountIn: '1000000000000000000', // 1 ARCH
|
|
30
30
|
assetOut: 'ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D', // USDC
|
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,8 @@ 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
|
+
AllowanceMode: () => AllowanceMode,
|
|
26
|
+
BaseClient: () => BaseClient,
|
|
25
27
|
BoltCosmWasmClient: () => BoltCosmWasmClient,
|
|
26
28
|
BoltSdkErrorBase: () => BoltSdkErrorBase,
|
|
27
29
|
BoltSdkErrorCode: () => BoltSdkErrorCode,
|
|
@@ -255,12 +257,12 @@ var BaseClient = class {
|
|
|
255
257
|
/**
|
|
256
258
|
* Creates a new instance of the BaseClient.
|
|
257
259
|
*
|
|
258
|
-
* @param config - Optional
|
|
259
|
-
* @param config.
|
|
260
|
-
* @param config.
|
|
261
|
-
* @param config.
|
|
262
|
-
* @param config.
|
|
263
|
-
* @param config.
|
|
260
|
+
* @param config - (Optional) Configuration object for the client
|
|
261
|
+
* @param config.customOverride - (Optional) Override configuration for RPC endpoint and contract addresses
|
|
262
|
+
* @param config.customOverride.rpcEndpoint - (Optional) Custom RPC endpoint URL for the blockchain network
|
|
263
|
+
* @param config.customOverride.contracts - (Optional) Custom contract addresses
|
|
264
|
+
* @param config.customOverride.contracts.oracle - (Optional) Custom oracle contract address
|
|
265
|
+
* @param config.customOverride.contracts.router - (Optional) Custom router contract address
|
|
264
266
|
*
|
|
265
267
|
* @throws {InvalidObjectError} Thrown when required configuration fields are missing
|
|
266
268
|
*
|
|
@@ -286,7 +288,7 @@ var BaseClient = class {
|
|
|
286
288
|
* Smart contract addresses for making Bolt queries and transactions in the blockchain
|
|
287
289
|
*/
|
|
288
290
|
__publicField(this, "contracts");
|
|
289
|
-
const {
|
|
291
|
+
const { customOverride: { rpcEndpoint, contracts } = {} } = config ?? {};
|
|
290
292
|
if (!rpcEndpoint || !contracts?.oracle || !contracts.router) {
|
|
291
293
|
throw new InvalidObjectError("ClientConfig is missing fields");
|
|
292
294
|
}
|
|
@@ -305,6 +307,13 @@ var Environment = /* @__PURE__ */ ((Environment2) => {
|
|
|
305
307
|
return Environment2;
|
|
306
308
|
})(Environment || {});
|
|
307
309
|
|
|
310
|
+
// src/common/types/pool.ts
|
|
311
|
+
var AllowanceMode = /* @__PURE__ */ ((AllowanceMode2) => {
|
|
312
|
+
AllowanceMode2["Allow"] = "allow";
|
|
313
|
+
AllowanceMode2["Disallow"] = "disallow";
|
|
314
|
+
return AllowanceMode2;
|
|
315
|
+
})(AllowanceMode || {});
|
|
316
|
+
|
|
308
317
|
// src/config/archway-mainnet.json
|
|
309
318
|
var archway_mainnet_default = {
|
|
310
319
|
chain: {
|
|
@@ -313,8 +322,8 @@ var archway_mainnet_default = {
|
|
|
313
322
|
restEndpoint: "https://api.mainnet.archway.io"
|
|
314
323
|
},
|
|
315
324
|
contracts: {
|
|
316
|
-
oracle: "
|
|
317
|
-
router: "
|
|
325
|
+
oracle: "archway1cr5l0tvhqsdjfzun4jkwqfzv7fadu598hultcra4jrljgwl639wsksmd28",
|
|
326
|
+
router: "archway199r5vm4yzww5hct2z58tz9v3chfcvkpln34sqcav3ldqs7nkwktqc7aeju"
|
|
318
327
|
}
|
|
319
328
|
};
|
|
320
329
|
|
|
@@ -326,8 +335,8 @@ var archway_testnet_default = {
|
|
|
326
335
|
restEndpoint: "https://api.constantine.archway.io"
|
|
327
336
|
},
|
|
328
337
|
contracts: {
|
|
329
|
-
oracle: "
|
|
330
|
-
router: "
|
|
338
|
+
oracle: "archway1ehpghtr0v95kfx648dck7pvs08d6ah97l99xkx87t2zx8tcyen0s9n90x4",
|
|
339
|
+
router: "archway1h5x6upghew9xkfek85q48let2twdxq33sgsnzze5weshla46xd8sttps44"
|
|
331
340
|
}
|
|
332
341
|
};
|
|
333
342
|
|
|
@@ -387,6 +396,30 @@ var parseQueryRouterConfigResponse = (response) => {
|
|
|
387
396
|
settlementCodeId: response.settlement_code_id
|
|
388
397
|
};
|
|
389
398
|
};
|
|
399
|
+
var parseQuerySettlementConfigResponse = (response) => {
|
|
400
|
+
return {
|
|
401
|
+
priceOracleContract: response.price_oracle_contract,
|
|
402
|
+
protocolFeeRecipient: response.protocol_fee_recipient,
|
|
403
|
+
protocolFee: response.protocol_fee,
|
|
404
|
+
lpFee: response.lp_fee,
|
|
405
|
+
allowanceMode: response.allowance_mode,
|
|
406
|
+
lps: response.lps,
|
|
407
|
+
minBaseOut: response.min_base_out
|
|
408
|
+
};
|
|
409
|
+
};
|
|
410
|
+
var parseQueryBaseLiquidityResponse = (response) => {
|
|
411
|
+
return {
|
|
412
|
+
baseLiquidity: response.base_liquidity,
|
|
413
|
+
totalShares: response.total_shares
|
|
414
|
+
};
|
|
415
|
+
};
|
|
416
|
+
var parseQueryBaseLiquidityAllResponse = (response) => {
|
|
417
|
+
const newMapping = {};
|
|
418
|
+
for (const [key, value] of Object.entries(response.liquidity)) {
|
|
419
|
+
newMapping[key] = parseQueryBaseLiquidityResponse(value);
|
|
420
|
+
}
|
|
421
|
+
return newMapping;
|
|
422
|
+
};
|
|
390
423
|
|
|
391
424
|
// src/lib/helpers/transactions.ts
|
|
392
425
|
var getSignerAddress = async (signer) => {
|
|
@@ -430,7 +463,7 @@ var getAllBaseLiquidity = async (client) => {
|
|
|
430
463
|
const response = await cosmWasmClient.queryContractSmart(client.contracts.router, {
|
|
431
464
|
base_liquidity_all: {}
|
|
432
465
|
});
|
|
433
|
-
return response
|
|
466
|
+
return parseQueryBaseLiquidityAllResponse(response);
|
|
434
467
|
};
|
|
435
468
|
|
|
436
469
|
// src/lib/router/get-all-quotes-for-user.ts
|
|
@@ -474,7 +507,7 @@ var BOLT_SWAP_EVENT_TYPE = "wasm-bolt_swap";
|
|
|
474
507
|
var BOLT_COIN_RECEIVED_EVENT_TYPE = "coin_received";
|
|
475
508
|
var BOLT_COIN_RECEIVED_EVENT_AMOUNT_KEY = "amount";
|
|
476
509
|
|
|
477
|
-
// src/lib/router/swap.ts
|
|
510
|
+
// src/lib/router/swap-exact-in.ts
|
|
478
511
|
var swapExactIn = async (client, signer, { assetIn, amountIn, assetOut, minimumAmountOut, receiver }) => {
|
|
479
512
|
const signingCosmWasmClient = await client.getSigningCosmWasmClient(signer);
|
|
480
513
|
const address = await getSignerAddress(signer);
|
|
@@ -535,6 +568,21 @@ var CosmWasmChain = /* @__PURE__ */ ((CosmWasmChain2) => {
|
|
|
535
568
|
return CosmWasmChain2;
|
|
536
569
|
})(CosmWasmChain || {});
|
|
537
570
|
|
|
571
|
+
// src/lib/settlement/get-settlement-config.ts
|
|
572
|
+
var getSettlementConfig = async (client, contractAddress) => {
|
|
573
|
+
const cosmWasmClient = await client.getCosmWasmClient();
|
|
574
|
+
const response = await cosmWasmClient.queryContractSmart(contractAddress, {
|
|
575
|
+
config: {}
|
|
576
|
+
});
|
|
577
|
+
return parseQuerySettlementConfigResponse(response);
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
// src/lib/settlement/get-settlement-config-for-base.ts
|
|
581
|
+
var getSettlementConfigForBase = async (client, baseAssetSymbol) => {
|
|
582
|
+
const pool = await getPoolForBase(client, baseAssetSymbol);
|
|
583
|
+
return await getSettlementConfig(client, pool.poolAddress);
|
|
584
|
+
};
|
|
585
|
+
|
|
538
586
|
// src/lib/client.ts
|
|
539
587
|
var BoltCosmWasmClient = class extends BaseClient {
|
|
540
588
|
/**
|
|
@@ -546,11 +594,13 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
546
594
|
* @param config - (Optional) Configuration for the client
|
|
547
595
|
* @param config.environment - (Optional) The deployment environment (Mainnet or Testnet). Defaults to Mainnet
|
|
548
596
|
* @param config.chain - (Optional) The specific CosmWasm chain to connect to. Defaults to Archway
|
|
549
|
-
* @param config.
|
|
550
|
-
* @param config.
|
|
551
|
-
* @param config.
|
|
552
|
-
* @param config.
|
|
553
|
-
* @param config.
|
|
597
|
+
* @param config.customOverride - (Optional) Overrides for RPC endpoint and contract addresses
|
|
598
|
+
* @param config.customOverride.rpcEndpoint - (Optional) Custom RPC endpoint URL
|
|
599
|
+
* @param config.customOverride.contracts - (Optional) Custom contract addresses
|
|
600
|
+
* @param config.customOverride.contracts.oracle - (Optional) Custom oracle contract address
|
|
601
|
+
* @param config.customOverride.contracts.router - (Optional) Custom router contract address
|
|
602
|
+
* @param config.customOverride.cosmWasmClient - (Optional) Custom CosmWasmClient to use for blockchain queries
|
|
603
|
+
* @param config.customOverride.signingCosmWasmClient - (Optional) Custom SigningCosmWasmClient to use for blockchain transactions
|
|
554
604
|
*
|
|
555
605
|
* @throws {InvalidTypeError} Thrown when an unsupported chain is specified
|
|
556
606
|
*
|
|
@@ -576,7 +626,9 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
576
626
|
const {
|
|
577
627
|
environment = "mainnet" /* Mainnet */,
|
|
578
628
|
chain = "archway" /* Archway */,
|
|
579
|
-
|
|
629
|
+
customOverride,
|
|
630
|
+
cosmWasmClient,
|
|
631
|
+
signingCosmWasmClient
|
|
580
632
|
} = config ?? {};
|
|
581
633
|
let configJson;
|
|
582
634
|
switch (chain) {
|
|
@@ -587,11 +639,11 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
587
639
|
throw new InvalidTypeError("A valid value of CosmWasmChain", chain);
|
|
588
640
|
}
|
|
589
641
|
super({
|
|
590
|
-
|
|
591
|
-
rpcEndpoint:
|
|
642
|
+
customOverride: {
|
|
643
|
+
rpcEndpoint: customOverride?.rpcEndpoint ?? configJson.chain.rpcEndpoint,
|
|
592
644
|
contracts: {
|
|
593
|
-
oracle:
|
|
594
|
-
router:
|
|
645
|
+
oracle: customOverride?.contracts?.oracle ?? configJson.contracts.oracle,
|
|
646
|
+
router: customOverride?.contracts?.router ?? configJson.contracts.router
|
|
595
647
|
}
|
|
596
648
|
}
|
|
597
649
|
});
|
|
@@ -610,6 +662,8 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
610
662
|
*/
|
|
611
663
|
__publicField(this, "chain");
|
|
612
664
|
this.chain = chain;
|
|
665
|
+
this._cosmWasmClient = cosmWasmClient;
|
|
666
|
+
this._signingCosmWasmClient = signingCosmWasmClient;
|
|
613
667
|
}
|
|
614
668
|
/**
|
|
615
669
|
* Gets or creates a CosmWasm client instance for read-only blockchain operations.
|
|
@@ -700,12 +754,20 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
700
754
|
}
|
|
701
755
|
/** @inheritdoc */
|
|
702
756
|
async getPoolByBaseAsset(baseAssetSymbol) {
|
|
703
|
-
return getPoolForBase(this, baseAssetSymbol);
|
|
757
|
+
return await getPoolForBase(this, baseAssetSymbol);
|
|
704
758
|
}
|
|
705
759
|
/** @inheritdoc */
|
|
706
760
|
async getAllPools() {
|
|
707
761
|
return await getPools(this);
|
|
708
762
|
}
|
|
763
|
+
/** @inheritdoc */
|
|
764
|
+
async getPoolConfig(poolContractAddress) {
|
|
765
|
+
return await getSettlementConfig(this, poolContractAddress);
|
|
766
|
+
}
|
|
767
|
+
/** @inheritdoc */
|
|
768
|
+
async getPoolConfigByBaseAsset(baseAssetSymbol) {
|
|
769
|
+
return await getSettlementConfigForBase(this, baseAssetSymbol);
|
|
770
|
+
}
|
|
709
771
|
/**
|
|
710
772
|
* @inheritdoc
|
|
711
773
|
*
|
|
@@ -729,7 +791,7 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
729
791
|
* console.log(`Gas used: ${result.gasUsed}`);
|
|
730
792
|
* ```
|
|
731
793
|
*/
|
|
732
|
-
async
|
|
794
|
+
async swap(signer, params) {
|
|
733
795
|
return await swapExactIn(this, signer, params);
|
|
734
796
|
}
|
|
735
797
|
};
|