@bolt-liquidity-hq/cosmwasm-client 0.1.0-beta.10 → 0.1.0-beta.12
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 +159 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -20
- package/dist/index.d.ts +64 -20
- package/dist/index.js +151 -34
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var ArchwayMainnetContracts = {
|
|
|
21
21
|
oracle: "archway1cr5l0tvhqsdjfzun4jkwqfzv7fadu598hultcra4jrljgwl639wsksmd28",
|
|
22
22
|
router: "archway1vu2ctevyav3wlka9yn7hmcm0xnlltklnnceqaanpuh0eete80xgsymc3ln"
|
|
23
23
|
};
|
|
24
|
+
var ArchwayMainnetNativeTokenDenom = "aarch";
|
|
24
25
|
var ArchwayMainnetAssets = {
|
|
25
26
|
aarch: {
|
|
26
27
|
symbol: "ARCH",
|
|
@@ -5219,6 +5220,7 @@ var ArchwayTestnetContracts = {
|
|
|
5219
5220
|
oracle: "archway1ehpghtr0v95kfx648dck7pvs08d6ah97l99xkx87t2zx8tcyen0s9n90x4",
|
|
5220
5221
|
router: "archway1rtdlmwgedg2vnsdyp3l23yr8eh7gspndt0x5cv5n9vxnerm374cs8lxk25"
|
|
5221
5222
|
};
|
|
5223
|
+
var ArchwayTestnetNativeTokenDenom = "aconst";
|
|
5222
5224
|
var ArchwayTestnetAssets = {
|
|
5223
5225
|
aconst: {
|
|
5224
5226
|
symbol: "CONST",
|
|
@@ -5427,8 +5429,10 @@ var parseQueryOracleConfigResponse = (response) => {
|
|
|
5427
5429
|
};
|
|
5428
5430
|
};
|
|
5429
5431
|
var parsePriceRepresentation = (priceRepresentation) => {
|
|
5432
|
+
const [baseDenom, quoteDenom] = priceRepresentation.asset_pair.split(":");
|
|
5430
5433
|
return {
|
|
5431
|
-
|
|
5434
|
+
baseDenom: baseDenom ?? "",
|
|
5435
|
+
quoteDenom: quoteDenom ?? "",
|
|
5432
5436
|
price: priceRepresentation.price,
|
|
5433
5437
|
expiryTime: priceRepresentation.expiry_time
|
|
5434
5438
|
};
|
|
@@ -5473,6 +5477,76 @@ var getPrices = async (client) => {
|
|
|
5473
5477
|
return parseQueryPricesResponse(response);
|
|
5474
5478
|
};
|
|
5475
5479
|
|
|
5480
|
+
// src/lib/router/estimate-swap-exact-in-gas-fees.ts
|
|
5481
|
+
import { DEFAULT_GAS_ADJUSTMENT } from "@bolt-liquidity-hq/core";
|
|
5482
|
+
import { toUtf8 } from "@cosmjs/encoding";
|
|
5483
|
+
import { BigNumber } from "bignumber.js";
|
|
5484
|
+
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
|
|
5485
|
+
|
|
5486
|
+
// src/lib/helpers/transactions.ts
|
|
5487
|
+
import { NotFoundError } from "@bolt-liquidity-hq/core";
|
|
5488
|
+
var getSignerAddress = async (signer) => {
|
|
5489
|
+
const accounts = await signer.getAccounts();
|
|
5490
|
+
if (!accounts?.[0]) {
|
|
5491
|
+
throw new NotFoundError("Signer account's address");
|
|
5492
|
+
}
|
|
5493
|
+
return accounts[0].address;
|
|
5494
|
+
};
|
|
5495
|
+
|
|
5496
|
+
// src/lib/router/estimate-swap-exact-in-gas-fees.ts
|
|
5497
|
+
var estimateSwapExactInGasFees = async (client, { assetIn, amountIn, assetOut, minimumAmountOut, receiver }, signer, gasAdjustment = DEFAULT_GAS_ADJUSTMENT) => {
|
|
5498
|
+
const { signer: finalSigner, signingCosmWasmClient } = await client.getSignerWithSigningClient(signer);
|
|
5499
|
+
const address = await getSignerAddress(finalSigner);
|
|
5500
|
+
const message = [
|
|
5501
|
+
{
|
|
5502
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5503
|
+
value: MsgExecuteContract.fromPartial({
|
|
5504
|
+
contract: client.contracts.router,
|
|
5505
|
+
funds: [
|
|
5506
|
+
{
|
|
5507
|
+
amount: amountIn,
|
|
5508
|
+
denom: assetIn
|
|
5509
|
+
}
|
|
5510
|
+
],
|
|
5511
|
+
msg: toUtf8(
|
|
5512
|
+
JSON.stringify({
|
|
5513
|
+
swap_exact_in: {
|
|
5514
|
+
want_out: assetOut,
|
|
5515
|
+
minimum_base_out: minimumAmountOut,
|
|
5516
|
+
receiver
|
|
5517
|
+
}
|
|
5518
|
+
})
|
|
5519
|
+
),
|
|
5520
|
+
sender: address
|
|
5521
|
+
})
|
|
5522
|
+
}
|
|
5523
|
+
];
|
|
5524
|
+
const SIMULATION_MEMO = "Swap simulation from Bolt SDK";
|
|
5525
|
+
if ("calculateFee" in signingCosmWasmClient) {
|
|
5526
|
+
try {
|
|
5527
|
+
const result = await signingCosmWasmClient.calculateFee(
|
|
5528
|
+
address,
|
|
5529
|
+
message,
|
|
5530
|
+
SIMULATION_MEMO,
|
|
5531
|
+
gasAdjustment
|
|
5532
|
+
);
|
|
5533
|
+
return result.amount[0];
|
|
5534
|
+
} catch {
|
|
5535
|
+
return;
|
|
5536
|
+
}
|
|
5537
|
+
} else {
|
|
5538
|
+
try {
|
|
5539
|
+
const result = await signingCosmWasmClient.simulate(address, message, SIMULATION_MEMO);
|
|
5540
|
+
return {
|
|
5541
|
+
amount: BigNumber(result).times(gasAdjustment).toFixed(0),
|
|
5542
|
+
denom: client.nativeTokenDenom
|
|
5543
|
+
};
|
|
5544
|
+
} catch {
|
|
5545
|
+
return;
|
|
5546
|
+
}
|
|
5547
|
+
}
|
|
5548
|
+
};
|
|
5549
|
+
|
|
5476
5550
|
// src/lib/router/parsers.ts
|
|
5477
5551
|
var parseMarketRepresentation = (marketRepresentation) => {
|
|
5478
5552
|
return {
|
|
@@ -5564,20 +5638,10 @@ var BOLT_SWAP_EVENT_TYPE = "wasm-bolt_swap";
|
|
|
5564
5638
|
var BOLT_COIN_RECEIVED_EVENT_TYPE = "coin_received";
|
|
5565
5639
|
var BOLT_COIN_RECEIVED_EVENT_AMOUNT_KEY = "amount";
|
|
5566
5640
|
|
|
5567
|
-
// src/lib/helpers/transactions.ts
|
|
5568
|
-
import { NotFoundError } from "@bolt-liquidity-hq/core";
|
|
5569
|
-
var getSignerAddress = async (signer) => {
|
|
5570
|
-
const accounts = await signer.getAccounts();
|
|
5571
|
-
if (!accounts?.[0]) {
|
|
5572
|
-
throw new NotFoundError("Signer account's address");
|
|
5573
|
-
}
|
|
5574
|
-
return accounts[0].address;
|
|
5575
|
-
};
|
|
5576
|
-
|
|
5577
5641
|
// src/lib/router/swap-exact-in.ts
|
|
5578
|
-
var swapExactIn = async (client,
|
|
5579
|
-
const signingCosmWasmClient = await client.
|
|
5580
|
-
const address = await getSignerAddress(
|
|
5642
|
+
var swapExactIn = async (client, { assetIn, amountIn, assetOut, minimumAmountOut, receiver }, signer) => {
|
|
5643
|
+
const { signer: finalSigner, signingCosmWasmClient } = await client.getSignerWithSigningClient(signer);
|
|
5644
|
+
const address = await getSignerAddress(finalSigner);
|
|
5581
5645
|
const txOutput = await signingCosmWasmClient.execute(
|
|
5582
5646
|
address,
|
|
5583
5647
|
client.contracts.router,
|
|
@@ -5663,12 +5727,13 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5663
5727
|
* Creates a new instance of the BoltCosmWasmClient.
|
|
5664
5728
|
*
|
|
5665
5729
|
* The client automatically configures itself based on the specified chain and environment,
|
|
5666
|
-
* loading the appropriate contract addresses, chain configuration,
|
|
5730
|
+
* loading the appropriate contract addresses, chain configuration, native token denomination,
|
|
5731
|
+
* and assets from configuration files.
|
|
5667
5732
|
*
|
|
5668
5733
|
* @param config - (Optional) Configuration for the client
|
|
5669
5734
|
* @param config.environment - (Optional) The deployment environment ('mainnet' or 'testnet'). Defaults to 'mainnet'
|
|
5670
5735
|
* @param config.chain - (Optional) The specific CosmWasm chain to connect to. Defaults to 'archway'
|
|
5671
|
-
* @param config.customOverride - (Optional) Custom overrides for chain configuration, contracts, and assets
|
|
5736
|
+
* @param config.customOverride - (Optional) Custom overrides for chain configuration, contracts, native token, and assets
|
|
5672
5737
|
* @param config.customOverride.chainConfig - (Optional) Override chain configuration
|
|
5673
5738
|
* @param config.customOverride.chainConfig.id - (Optional) Custom chain ID
|
|
5674
5739
|
* @param config.customOverride.chainConfig.name - (Optional) Custom chain name
|
|
@@ -5677,8 +5742,10 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5677
5742
|
* @param config.customOverride.contracts - (Optional) Override contract addresses
|
|
5678
5743
|
* @param config.customOverride.contracts.oracle - (Optional) Custom oracle contract address
|
|
5679
5744
|
* @param config.customOverride.contracts.router - (Optional) Custom router contract address
|
|
5745
|
+
* @param config.customOverride.nativeTokenDenom - (Optional) Custom native token denomination (e.g., "aarch")
|
|
5680
5746
|
* @param config.customOverride.assetsConfig - (Optional) Custom asset configurations indexed by denom
|
|
5681
5747
|
* @param config.cosmWasmClient - (Optional) Pre-existing CosmWasmClient to use for blockchain queries
|
|
5748
|
+
* @param config.signer - (Optional) Pre-existing OfflineSigner for transaction signing
|
|
5682
5749
|
* @param config.signingCosmWasmClient - (Optional) Pre-existing SigningCosmWasmClient to use for blockchain transactions
|
|
5683
5750
|
*
|
|
5684
5751
|
* @throws {InvalidTypeError} Thrown when an unsupported chain is specified
|
|
@@ -5706,6 +5773,7 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5706
5773
|
* oracle: 'archway1custom_oracle...',
|
|
5707
5774
|
* router: 'archway1custom_router...'
|
|
5708
5775
|
* },
|
|
5776
|
+
* nativeTokenDenom: 'aarch',
|
|
5709
5777
|
* assetsConfig: {
|
|
5710
5778
|
* 'aarch': {
|
|
5711
5779
|
* symbol: 'ARCH',
|
|
@@ -5723,6 +5791,7 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5723
5791
|
* // Use pre-existing CosmWasm clients
|
|
5724
5792
|
* const clientWithCustomClients = new BoltCosmWasmClient({
|
|
5725
5793
|
* cosmWasmClient: myCosmWasmClient,
|
|
5794
|
+
* signer: mySigner,
|
|
5726
5795
|
* signingCosmWasmClient: mySigningClient
|
|
5727
5796
|
* });
|
|
5728
5797
|
* ```
|
|
@@ -5733,15 +5802,18 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5733
5802
|
chain = "archway",
|
|
5734
5803
|
customOverride,
|
|
5735
5804
|
cosmWasmClient,
|
|
5805
|
+
signer,
|
|
5736
5806
|
signingCosmWasmClient
|
|
5737
5807
|
} = config ?? {};
|
|
5738
5808
|
let defaultChainConfig;
|
|
5739
5809
|
let defaultContracts;
|
|
5810
|
+
let defaultNativeTokenDenom;
|
|
5740
5811
|
let assetsConfig;
|
|
5741
5812
|
switch (chain) {
|
|
5742
5813
|
case "archway":
|
|
5743
5814
|
defaultChainConfig = environment === "mainnet" ? ArchwayMainnetChainConfig : ArchwayTestnetChainConfig;
|
|
5744
5815
|
defaultContracts = environment === "mainnet" ? ArchwayMainnetContracts : ArchwayTestnetContracts;
|
|
5816
|
+
defaultNativeTokenDenom = environment === "mainnet" ? ArchwayMainnetNativeTokenDenom : ArchwayTestnetNativeTokenDenom;
|
|
5745
5817
|
assetsConfig = environment === "mainnet" ? ArchwayMainnetAssets : ArchwayTestnetAssets;
|
|
5746
5818
|
break;
|
|
5747
5819
|
default:
|
|
@@ -5757,6 +5829,7 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5757
5829
|
oracle: customOverride?.contracts?.oracle ?? defaultContracts.oracle,
|
|
5758
5830
|
router: customOverride?.contracts?.router ?? defaultContracts.router
|
|
5759
5831
|
};
|
|
5832
|
+
const nativeTokenDenom = customOverride?.nativeTokenDenom ?? defaultNativeTokenDenom;
|
|
5760
5833
|
for (const item of Object.values(customOverride?.assetsConfig ?? {})) {
|
|
5761
5834
|
assetsConfig[item.denom] = item;
|
|
5762
5835
|
}
|
|
@@ -5764,6 +5837,7 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5764
5837
|
customOverride: {
|
|
5765
5838
|
chainConfig,
|
|
5766
5839
|
contracts,
|
|
5840
|
+
nativeTokenDenom,
|
|
5767
5841
|
assetsConfig
|
|
5768
5842
|
}
|
|
5769
5843
|
});
|
|
@@ -5776,6 +5850,11 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5776
5850
|
* @private
|
|
5777
5851
|
*/
|
|
5778
5852
|
__publicField(this, "_cosmWasmClient");
|
|
5853
|
+
/**
|
|
5854
|
+
* Cached instance of the Signer for transaction execution
|
|
5855
|
+
* @private
|
|
5856
|
+
*/
|
|
5857
|
+
__publicField(this, "_signer");
|
|
5779
5858
|
/**
|
|
5780
5859
|
* Cached instance of the signing CosmWasm client for transaction execution
|
|
5781
5860
|
* @private
|
|
@@ -5788,6 +5867,7 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5788
5867
|
this.chainConfig = chainConfig;
|
|
5789
5868
|
this.chain = chain;
|
|
5790
5869
|
this._cosmWasmClient = cosmWasmClient;
|
|
5870
|
+
this._signer = signer;
|
|
5791
5871
|
this._signingCosmWasmClient = signingCosmWasmClient;
|
|
5792
5872
|
}
|
|
5793
5873
|
/**
|
|
@@ -5813,18 +5893,18 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5813
5893
|
return this._cosmWasmClient;
|
|
5814
5894
|
}
|
|
5815
5895
|
/**
|
|
5816
|
-
* Gets or creates a signing CosmWasm client instance for transaction execution.
|
|
5896
|
+
* Gets or creates a signing CosmWasm client instance along with the signer for transaction execution.
|
|
5817
5897
|
*
|
|
5818
|
-
* This method implements lazy initialization and caching of the signing client.
|
|
5898
|
+
* This method implements lazy initialization and caching of both the signing client and signer.
|
|
5819
5899
|
* A signer must be provided either on first call or to replace the cached instance.
|
|
5820
5900
|
* The appropriate client type is selected based on the configured chain.
|
|
5821
5901
|
*
|
|
5822
|
-
* @param
|
|
5823
|
-
*
|
|
5902
|
+
* @param newSigner - Optional offline signer for transaction signing. Required on first call
|
|
5903
|
+
* or to replace the existing signer
|
|
5824
5904
|
*
|
|
5825
|
-
* @returns A promise that resolves to the signing
|
|
5905
|
+
* @returns A promise that resolves to an object containing both the signer and signing client
|
|
5826
5906
|
*
|
|
5827
|
-
* @throws {MissingParameterError} Thrown when no signer is provided and no cached
|
|
5907
|
+
* @throws {MissingParameterError} Thrown when no signer is provided and no cached signer exists
|
|
5828
5908
|
*
|
|
5829
5909
|
* @example
|
|
5830
5910
|
* ```typescript
|
|
@@ -5832,20 +5912,27 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5832
5912
|
* const signer = await DirectSecp256k1HdWallet.fromMnemonic("my mnemonic goes here", {
|
|
5833
5913
|
* prefix: 'archway',
|
|
5834
5914
|
* });
|
|
5835
|
-
* const
|
|
5915
|
+
* const { signer: cachedSigner, signingCosmWasmClient } = await boltClient.getSignerWithSigningClient(signer);
|
|
5836
5916
|
*
|
|
5837
|
-
* // Subsequent calls can reuse the cached client
|
|
5838
|
-
* const
|
|
5917
|
+
* // Subsequent calls can reuse the cached signer and client
|
|
5918
|
+
* const { signer, signingCosmWasmClient: client } = await boltClient.getSignerWithSigningClient();
|
|
5839
5919
|
* ```
|
|
5840
5920
|
*/
|
|
5841
|
-
async
|
|
5842
|
-
if (!this._signingCosmWasmClient ||
|
|
5843
|
-
|
|
5921
|
+
async getSignerWithSigningClient(newSigner) {
|
|
5922
|
+
if (!this._signingCosmWasmClient || !this._signer || newSigner) {
|
|
5923
|
+
this._signer = newSigner ?? this._signer;
|
|
5924
|
+
if (!this._signer) {
|
|
5844
5925
|
throw new MissingParameterError("signer");
|
|
5845
5926
|
}
|
|
5846
|
-
this._signingCosmWasmClient = await (this.chain === "archway" ? SigningArchwayClient : SigningCosmWasmClient).connectWithSigner(this.chainConfig.rpcEndpoint,
|
|
5927
|
+
this._signingCosmWasmClient = await (this.chain === "archway" ? SigningArchwayClient : SigningCosmWasmClient).connectWithSigner(this.chainConfig.rpcEndpoint, this._signer);
|
|
5847
5928
|
}
|
|
5848
|
-
|
|
5929
|
+
if (!this._signer) {
|
|
5930
|
+
throw new MissingParameterError("signer");
|
|
5931
|
+
}
|
|
5932
|
+
return {
|
|
5933
|
+
signer: this._signer,
|
|
5934
|
+
signingCosmWasmClient: this._signingCosmWasmClient
|
|
5935
|
+
};
|
|
5849
5936
|
}
|
|
5850
5937
|
// The following methods inherit their documentation from BaseClient
|
|
5851
5938
|
// Only add documentation here if you need to override or add implementation-specific details
|
|
@@ -5906,13 +5993,13 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5906
5993
|
* const signer = await window.keplr.getOfflineSignerAuto(chainId);
|
|
5907
5994
|
*
|
|
5908
5995
|
* // Execute swap: 1 ARCH for USDC
|
|
5909
|
-
* const result = await client.swap(
|
|
5996
|
+
* const result = await client.swap({
|
|
5910
5997
|
* assetIn: "aarch",
|
|
5911
5998
|
* amountIn: "1000000000000000000", // 1 ARCH (18 decimals)
|
|
5912
5999
|
* assetOut: "ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D", // USDC IBC denom
|
|
5913
6000
|
* minimumAmountOut: "1950000000", // Minimum 1950 USDC expected
|
|
5914
6001
|
* receiver: "archway1..." // Optional custom receiver
|
|
5915
|
-
* });
|
|
6002
|
+
* }, signer);
|
|
5916
6003
|
*
|
|
5917
6004
|
* console.log(`Swap successful!`);
|
|
5918
6005
|
* console.log(`Transaction hash: ${result.txHash}`);
|
|
@@ -5925,8 +6012,38 @@ var BoltCosmWasmClient = class extends BaseClient {
|
|
|
5925
6012
|
* This implementation returns a CosmWasm ExecuteResult as the transaction output,
|
|
5926
6013
|
* which includes details like gas used, block height, transaction hash, and events.
|
|
5927
6014
|
*/
|
|
5928
|
-
async swap(
|
|
5929
|
-
return await swapExactIn(this,
|
|
6015
|
+
async swap(params, signer) {
|
|
6016
|
+
return await swapExactIn(this, params, signer);
|
|
6017
|
+
}
|
|
6018
|
+
/**
|
|
6019
|
+
* @inheritdoc
|
|
6020
|
+
*
|
|
6021
|
+
* @example
|
|
6022
|
+
* ```typescript
|
|
6023
|
+
* // Get signer (e.g., from Keplr wallet)
|
|
6024
|
+
* const signer = await window.keplr.getOfflineSignerAuto(chainId);
|
|
6025
|
+
*
|
|
6026
|
+
* // Estimate gas for swapping 1 ARCH to USDC
|
|
6027
|
+
* const gasEstimate = await client.estimateSwapGasFees({
|
|
6028
|
+
* assetIn: "aarch",
|
|
6029
|
+
* amountIn: "1000000000000000000", // 1 ARCH
|
|
6030
|
+
* assetOut: "ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D", // USDC
|
|
6031
|
+
* minimumAmountOut: "1950000000" // Min 1950 USDC
|
|
6032
|
+
* }, signer, 1.3); // 30% safety margin
|
|
6033
|
+
*
|
|
6034
|
+
* if (gasEstimate) {
|
|
6035
|
+
* console.log(`Estimated gas: ${gasEstimate.amount} ${gasEstimate.denom}`);
|
|
6036
|
+
* }
|
|
6037
|
+
* ```
|
|
6038
|
+
*
|
|
6039
|
+
* @remarks
|
|
6040
|
+
* - For CosmWasm chains, gas is always paid in the native token (e.g., "aarch" for Archway)
|
|
6041
|
+
* - The returned amount is in the smallest denomination (6 decimals for most Cosmos chains)
|
|
6042
|
+
* - Gas estimation uses CosmWasm's simulation capabilities
|
|
6043
|
+
* - The gasAdjustment parameter helps account for variations in actual execution
|
|
6044
|
+
*/
|
|
6045
|
+
async estimateSwapGasFees(params, signer, gasAdjustment) {
|
|
6046
|
+
return await estimateSwapExactInGasFees(this, params, signer, gasAdjustment);
|
|
5930
6047
|
}
|
|
5931
6048
|
};
|
|
5932
6049
|
export {
|