@bolt-liquidity-hq/cosmwasm-client 0.1.0 → 0.3.0
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 +11 -10
- package/dist/index.cjs +34 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -12
- package/dist/index.d.ts +10 -12
- package/dist/index.js +35 -29
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -23,21 +23,22 @@ import { BoltCosmWasmClient } from '@bolt-liquidity-hq/cosmwasm-client';
|
|
|
23
23
|
// Initialize client
|
|
24
24
|
const client = new BoltCosmWasmClient();
|
|
25
25
|
|
|
26
|
-
// Get current price
|
|
26
|
+
// Get current price, in raw units: multiply by 10^(18 - 6) for USDC per ARCH
|
|
27
27
|
const price = await client.getPrice(
|
|
28
28
|
'aarch', // ARCH
|
|
29
29
|
'ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D' // USDC
|
|
30
30
|
);
|
|
31
|
-
console.log(`ARCH/USDC: ${price.price}`);
|
|
32
|
-
|
|
33
|
-
// Execute a swap
|
|
31
|
+
console.log(`ARCH/USDC (raw units): ${price.price}`);
|
|
32
|
+
|
|
33
|
+
// Execute a swap, accepting up to 0.5% less than the simulation expects
|
|
34
|
+
const swap = {
|
|
35
|
+
assetIn: 'aarch', // ARCH
|
|
36
|
+
amountIn: '1000000000000000000', // 1 ARCH
|
|
37
|
+
assetOut: 'ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D', // USDC
|
|
38
|
+
};
|
|
39
|
+
const { amountOut } = await client.simulateSwap(swap);
|
|
34
40
|
const result = await client.swap(
|
|
35
|
-
{
|
|
36
|
-
assetIn: 'aarch',
|
|
37
|
-
amountIn: '1000000000000000000', // 1 ARCH
|
|
38
|
-
assetOut: 'ibc/43897B9739BD63E3A08A88191999C632E052724AB96BD4C74AE31375C991F48D', // USDC
|
|
39
|
-
minimumAmountOut: '1900000', // 1.9 USDC minimum
|
|
40
|
-
},
|
|
41
|
+
{ ...swap, minimumAmountOut: ((BigInt(amountOut) * 995n) / 1000n).toString() },
|
|
41
42
|
signer
|
|
42
43
|
);
|
|
43
44
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
28
|
|
|
29
29
|
// src/lib/client.ts
|
|
30
30
|
var import_arch3 = require("@archwayhq/arch3.js");
|
|
31
|
-
var
|
|
31
|
+
var import_core5 = require("@bolt-liquidity-hq/core");
|
|
32
32
|
var import_cosmwasm_stargate = require("@cosmjs/cosmwasm-stargate");
|
|
33
33
|
|
|
34
34
|
// src/config/archway-mainnet.ts
|
|
@@ -5502,7 +5502,7 @@ var getPrices = async (client) => {
|
|
|
5502
5502
|
var import_core2 = require("@bolt-liquidity-hq/core");
|
|
5503
5503
|
var import_encoding = require("@cosmjs/encoding");
|
|
5504
5504
|
var import_bignumber = require("bignumber.js");
|
|
5505
|
-
var import_tx = require("cosmjs-types/cosmwasm/wasm/v1/tx
|
|
5505
|
+
var import_tx = require("cosmjs-types/cosmwasm/wasm/v1/tx");
|
|
5506
5506
|
|
|
5507
5507
|
// src/lib/helpers/transactions.ts
|
|
5508
5508
|
var import_core = require("@bolt-liquidity-hq/core");
|
|
@@ -5516,6 +5516,8 @@ var getSignerAddress = async (signer) => {
|
|
|
5516
5516
|
|
|
5517
5517
|
// src/lib/router/estimate-swap-exact-in-gas-fees.ts
|
|
5518
5518
|
var estimateSwapExactInGasFees = async (client, { assetIn, amountIn, assetOut, minimumAmountOut, receiver }, signer, gasAdjustment = import_core2.DEFAULT_GAS_ADJUSTMENT) => {
|
|
5519
|
+
const amount = (0, import_core2.toAmount)(amountIn, "amountIn").toString();
|
|
5520
|
+
const minimumBaseOut = minimumAmountOut ? (0, import_core2.toAmount)(minimumAmountOut, "minimumAmountOut").toString() : void 0;
|
|
5519
5521
|
const { signer: finalSigner, signingCosmWasmClient } = await client.getSignerWithSigningClient(signer);
|
|
5520
5522
|
const address = await getSignerAddress(finalSigner);
|
|
5521
5523
|
const message = [
|
|
@@ -5525,7 +5527,7 @@ var estimateSwapExactInGasFees = async (client, { assetIn, amountIn, assetOut, m
|
|
|
5525
5527
|
contract: client.contracts.router,
|
|
5526
5528
|
funds: [
|
|
5527
5529
|
{
|
|
5528
|
-
amount
|
|
5530
|
+
amount,
|
|
5529
5531
|
denom: assetIn
|
|
5530
5532
|
}
|
|
5531
5533
|
],
|
|
@@ -5533,7 +5535,7 @@ var estimateSwapExactInGasFees = async (client, { assetIn, amountIn, assetOut, m
|
|
|
5533
5535
|
JSON.stringify({
|
|
5534
5536
|
swap_exact_in: {
|
|
5535
5537
|
want_out: assetOut,
|
|
5536
|
-
minimum_base_out:
|
|
5538
|
+
minimum_base_out: minimumBaseOut,
|
|
5537
5539
|
receiver
|
|
5538
5540
|
}
|
|
5539
5541
|
})
|
|
@@ -5700,13 +5702,15 @@ var getRouterConfig = async (client) => {
|
|
|
5700
5702
|
};
|
|
5701
5703
|
|
|
5702
5704
|
// src/lib/router/simulate-swap-exact-in.ts
|
|
5705
|
+
var import_core3 = require("@bolt-liquidity-hq/core");
|
|
5703
5706
|
var simulateSwapExactIn = async (client, { assetIn, amountIn, assetOut }) => {
|
|
5707
|
+
const amount = (0, import_core3.toAmount)(amountIn, "amountIn").toString();
|
|
5704
5708
|
const cosmWasmClient = await client.getCosmWasmClient();
|
|
5705
5709
|
const response = await cosmWasmClient.queryContractSmart(client.contracts.router, {
|
|
5706
5710
|
simulate_swap_exact_in: {
|
|
5707
5711
|
amount_in: {
|
|
5708
5712
|
denom: assetIn,
|
|
5709
|
-
amount
|
|
5713
|
+
amount
|
|
5710
5714
|
},
|
|
5711
5715
|
want_out: assetOut
|
|
5712
5716
|
}
|
|
@@ -5715,7 +5719,7 @@ var simulateSwapExactIn = async (client, { assetIn, amountIn, assetOut }) => {
|
|
|
5715
5719
|
};
|
|
5716
5720
|
|
|
5717
5721
|
// src/lib/router/swap-exact-in.ts
|
|
5718
|
-
var
|
|
5722
|
+
var import_core4 = require("@bolt-liquidity-hq/core");
|
|
5719
5723
|
|
|
5720
5724
|
// src/lib/constants/events.ts
|
|
5721
5725
|
var BOLT_SWAP_EVENT_TYPE = "wasm-bolt_swap";
|
|
@@ -5724,6 +5728,8 @@ var BOLT_COIN_RECEIVED_EVENT_AMOUNT_KEY = "amount";
|
|
|
5724
5728
|
|
|
5725
5729
|
// src/lib/router/swap-exact-in.ts
|
|
5726
5730
|
var swapExactIn = async (client, { assetIn, amountIn, assetOut, minimumAmountOut, receiver }, signer) => {
|
|
5731
|
+
const amount = (0, import_core4.toAmount)(amountIn, "amountIn").toString();
|
|
5732
|
+
const minimumBaseOut = minimumAmountOut ? (0, import_core4.toAmount)(minimumAmountOut, "minimumAmountOut").toString() : void 0;
|
|
5727
5733
|
const { signer: finalSigner, signingCosmWasmClient } = await client.getSignerWithSigningClient(signer);
|
|
5728
5734
|
const address = await getSignerAddress(finalSigner);
|
|
5729
5735
|
const txOutput = await signingCosmWasmClient.execute(
|
|
@@ -5732,19 +5738,19 @@ var swapExactIn = async (client, { assetIn, amountIn, assetOut, minimumAmountOut
|
|
|
5732
5738
|
{
|
|
5733
5739
|
swap_exact_in: {
|
|
5734
5740
|
want_out: assetOut,
|
|
5735
|
-
minimum_base_out:
|
|
5741
|
+
minimum_base_out: minimumBaseOut,
|
|
5736
5742
|
receiver
|
|
5737
5743
|
}
|
|
5738
5744
|
},
|
|
5739
5745
|
"auto",
|
|
5740
5746
|
"Swap using Bolt Typescript SDK",
|
|
5741
|
-
[{ amount
|
|
5747
|
+
[{ amount, denom: assetIn }]
|
|
5742
5748
|
);
|
|
5743
5749
|
const boltSwapEventIndex = txOutput.events.findIndex(
|
|
5744
5750
|
(item) => item.type === BOLT_SWAP_EVENT_TYPE
|
|
5745
5751
|
);
|
|
5746
5752
|
if (boltSwapEventIndex === -1) {
|
|
5747
|
-
throw new
|
|
5753
|
+
throw new import_core4.TransactionEventNotFoundError(
|
|
5748
5754
|
BOLT_SWAP_EVENT_TYPE,
|
|
5749
5755
|
"After the transaction was executed, no successful swap event was emitted, the transaction may have failed"
|
|
5750
5756
|
);
|
|
@@ -5757,14 +5763,14 @@ var swapExactIn = async (client, { assetIn, amountIn, assetOut, minimumAmountOut
|
|
|
5757
5763
|
)?.value;
|
|
5758
5764
|
if (amountWithDenomOut) {
|
|
5759
5765
|
try {
|
|
5760
|
-
amountOut = (0,
|
|
5766
|
+
amountOut = (0, import_core4.getCoinFromAmountWithDenomString)(amountWithDenomOut).amount;
|
|
5761
5767
|
break;
|
|
5762
5768
|
} catch {
|
|
5763
5769
|
}
|
|
5764
5770
|
}
|
|
5765
5771
|
}
|
|
5766
5772
|
if (!amountOut) {
|
|
5767
|
-
throw new
|
|
5773
|
+
throw new import_core4.TransactionEventNotFoundError(
|
|
5768
5774
|
BOLT_COIN_RECEIVED_EVENT_TYPE,
|
|
5769
5775
|
"After the transaction was executed, no coin received event was emitted, the transaction may have failed"
|
|
5770
5776
|
);
|
|
@@ -5778,7 +5784,7 @@ var swapExactIn = async (client, { assetIn, amountIn, assetOut, minimumAmountOut
|
|
|
5778
5784
|
};
|
|
5779
5785
|
|
|
5780
5786
|
// src/lib/client.ts
|
|
5781
|
-
var BoltCosmWasmClient = class extends
|
|
5787
|
+
var BoltCosmWasmClient = class extends import_core5.BaseClient {
|
|
5782
5788
|
/**
|
|
5783
5789
|
* Creates a new instance of the BoltCosmWasmClient.
|
|
5784
5790
|
*
|
|
@@ -5874,7 +5880,7 @@ var BoltCosmWasmClient = class extends import_core4.BaseClient {
|
|
|
5874
5880
|
assetsConfig = isEnvironmentMainnet ? ArchwayMainnetAssets : ArchwayTestnetAssets;
|
|
5875
5881
|
break;
|
|
5876
5882
|
default:
|
|
5877
|
-
throw new
|
|
5883
|
+
throw new import_core5.InvalidTypeError("A valid value of CosmWasmChain", chain);
|
|
5878
5884
|
}
|
|
5879
5885
|
const chainConfig = {
|
|
5880
5886
|
id: customOverride?.chainConfig?.id ?? defaultChainConfig.id,
|
|
@@ -5908,15 +5914,15 @@ var BoltCosmWasmClient = class extends import_core4.BaseClient {
|
|
|
5908
5914
|
*/
|
|
5909
5915
|
__publicField(this, "_cosmWasmClient");
|
|
5910
5916
|
/**
|
|
5911
|
-
* Cached instance of the
|
|
5917
|
+
* Cached instance of the signing CosmWasm client for transaction execution
|
|
5912
5918
|
* @private
|
|
5913
5919
|
*/
|
|
5914
|
-
__publicField(this, "
|
|
5920
|
+
__publicField(this, "_signingCosmWasmClient");
|
|
5915
5921
|
/**
|
|
5916
|
-
*
|
|
5922
|
+
* The signer that `_signingCosmWasmClient` signs with
|
|
5917
5923
|
* @private
|
|
5918
5924
|
*/
|
|
5919
|
-
__publicField(this, "
|
|
5925
|
+
__publicField(this, "_signingClientSigner");
|
|
5920
5926
|
/**
|
|
5921
5927
|
* The specific CosmWasm chain this client is connected to
|
|
5922
5928
|
*/
|
|
@@ -5924,8 +5930,9 @@ var BoltCosmWasmClient = class extends import_core4.BaseClient {
|
|
|
5924
5930
|
this.chainConfig = chainConfig;
|
|
5925
5931
|
this.chain = chain;
|
|
5926
5932
|
this._cosmWasmClient = cosmWasmClient;
|
|
5927
|
-
this.
|
|
5933
|
+
this.signer = signer;
|
|
5928
5934
|
this._signingCosmWasmClient = signingCosmWasmClient;
|
|
5935
|
+
this._signingClientSigner = signingCosmWasmClient ? signer : void 0;
|
|
5929
5936
|
}
|
|
5930
5937
|
/**
|
|
5931
5938
|
* Gets or creates a CosmWasm client instance for read-only blockchain operations.
|
|
@@ -5950,14 +5957,13 @@ var BoltCosmWasmClient = class extends import_core4.BaseClient {
|
|
|
5950
5957
|
return this._cosmWasmClient;
|
|
5951
5958
|
}
|
|
5952
5959
|
/**
|
|
5953
|
-
* Gets
|
|
5960
|
+
* Gets the signer, as `getSigner` does, with a signing CosmWasm client for it.
|
|
5954
5961
|
*
|
|
5955
|
-
*
|
|
5956
|
-
* A signer must be provided either on first call or to replace the cached instance.
|
|
5962
|
+
* The signing client is created on first use, and again whenever the signer changes.
|
|
5957
5963
|
* The appropriate client type is selected based on the configured chain.
|
|
5958
5964
|
*
|
|
5959
|
-
* @param newSigner - Optional
|
|
5960
|
-
*
|
|
5965
|
+
* @param newSigner - (Optional) A signer to use from now on. Defaults to the client's signer, as
|
|
5966
|
+
* for `getSigner`
|
|
5961
5967
|
*
|
|
5962
5968
|
* @returns A promise that resolves to an object containing both the signer and signing client
|
|
5963
5969
|
*
|
|
@@ -5965,7 +5971,6 @@ var BoltCosmWasmClient = class extends import_core4.BaseClient {
|
|
|
5965
5971
|
*
|
|
5966
5972
|
* @example
|
|
5967
5973
|
* ```typescript
|
|
5968
|
-
* // First call requires a signer
|
|
5969
5974
|
* const signer = await DirectSecp256k1HdWallet.fromMnemonic("my mnemonic goes here", {
|
|
5970
5975
|
* prefix: 'archway',
|
|
5971
5976
|
* });
|
|
@@ -5976,18 +5981,13 @@ var BoltCosmWasmClient = class extends import_core4.BaseClient {
|
|
|
5976
5981
|
* ```
|
|
5977
5982
|
*/
|
|
5978
5983
|
async getSignerWithSigningClient(newSigner) {
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
}
|
|
5984
|
-
this._signingCosmWasmClient = await (this.chain === "archway" ? import_arch3.SigningArchwayClient : import_cosmwasm_stargate.SigningCosmWasmClient).connectWithSigner(this.chainConfig.rpcEndpoint, this._signer);
|
|
5985
|
-
}
|
|
5986
|
-
if (!this._signer) {
|
|
5987
|
-
throw new import_core4.MissingParameterError("signer");
|
|
5984
|
+
const signer = this.getSigner(newSigner);
|
|
5985
|
+
if (!this._signingCosmWasmClient || this._signingClientSigner !== signer) {
|
|
5986
|
+
this._signingCosmWasmClient = await (this.chain === "archway" ? import_arch3.SigningArchwayClient : import_cosmwasm_stargate.SigningCosmWasmClient).connectWithSigner(this.chainConfig.rpcEndpoint, signer);
|
|
5987
|
+
this._signingClientSigner = signer;
|
|
5988
5988
|
}
|
|
5989
5989
|
return {
|
|
5990
|
-
signer
|
|
5990
|
+
signer,
|
|
5991
5991
|
signingCosmWasmClient: this._signingCosmWasmClient
|
|
5992
5992
|
};
|
|
5993
5993
|
}
|