diff --git a/packages/core/src/utils/fees.ts b/packages/core/src/utils/fees.ts index 53c5639b..ccbe6b02 100644 --- a/packages/core/src/utils/fees.ts +++ b/packages/core/src/utils/fees.ts @@ -1,6 +1,6 @@ import type { EncodeObject } from '@cosmjs/proto-signing'; -import { calculateFee, GasPrice } from '@cosmjs/stargate'; import { assertIsDefined } from './asserts'; +import type { GasPrice } from '@cosmjs/stargate'; import type { SigningSimulatorClient } from '../types'; import type { Chain } from '@nabla-studio/chain-registry'; @@ -11,7 +11,8 @@ import type { Chain } from '@nabla-studio/chain-registry'; * @param feeDenom ex. uosmo * @returns */ -export const getGasPrice = (chain: Chain, feeDenom?: string) => { +export const getGasPrice = async (chain: Chain, feeDenom?: string) => { + const GasPrice = (await import('@cosmjs/stargate')).GasPrice; let gasPrice: GasPrice | undefined = undefined; if (chain.fees && chain.fees.fee_tokens.length > 0) { @@ -31,7 +32,7 @@ export const getGasPrice = (chain: Chain, feeDenom?: string) => { if (averageGasPrice && denom && !denom.startsWith('ibc/')) { gasPrice = GasPrice.fromString(`${averageGasPrice}${denom}`); } else { - gasPrice = GasPrice.fromString(`1${denom}`); + GasPrice.fromString(`1${denom}`); } } @@ -53,5 +54,7 @@ export const estimateFee = async ( const gasEstimation = await client.simulate(sender, messages, memo); + const calculateFee = (await import('@cosmjs/stargate')).calculateFee; + return calculateFee(Math.round(gasEstimation * multiplier), gasPrice); }; diff --git a/packages/store/src/cosmjs/sign.ts b/packages/store/src/cosmjs/sign.ts index b16fd600..64a85b2d 100644 --- a/packages/store/src/cosmjs/sign.ts +++ b/packages/store/src/cosmjs/sign.ts @@ -7,15 +7,8 @@ import { getEndpoint, getGasPrice, } from '@quirks/core'; -import { - SigningStargateClient, - SigningStargateClientOptions, - StargateClient, -} from '@cosmjs/stargate'; -import { - SigningCosmWasmClient, - SigningCosmWasmClientOptions, -} from '@cosmjs/cosmwasm-stargate'; +import type { SigningStargateClientOptions } from '@cosmjs/stargate'; +import type { SigningCosmWasmClientOptions } from '@cosmjs/cosmwasm-stargate'; import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; /** @@ -84,6 +77,8 @@ export const broadcast = async ( clientOptions = stargate(chain); } + const StargateClient = (await import('@cosmjs/stargate')).StargateClient; + const client = await StargateClient.connect( endpoint.rpc.address, clientOptions, @@ -120,6 +115,8 @@ export const broadcastSync = async (chainName: string, txRaw: TxRaw) => { clientOptions = stargate(chain); } + const StargateClient = (await import('@cosmjs/stargate')).StargateClient; + const client = await StargateClient.connect( endpoint.rpc.address, clientOptions, @@ -168,6 +165,9 @@ export const sign = async ( clientOptions = signingStargate(chain); } + const SigningStargateClient = (await import('@cosmjs/stargate')) + .SigningStargateClient; + const client = await SigningStargateClient.connectWithSigner( endpoint.rpc.address, offlineSigner, @@ -177,7 +177,7 @@ export const sign = async ( if (fee === 'auto') { const gasPrice = clientOptions?.gasPrice ? clientOptions.gasPrice - : getGasPrice(chain); + : await getGasPrice(chain); fee = await estimateFee(client, sender, messages, gasPrice, memo); } @@ -225,6 +225,9 @@ export const signCW = async ( clientOptions = signingCosmwasm(chain); } + const SigningCosmWasmClient = (await import('@cosmjs/cosmwasm-stargate')) + .SigningCosmWasmClient; + const client = await SigningCosmWasmClient.connectWithSigner( endpoint.rpc.address, offlineSigner, @@ -234,7 +237,7 @@ export const signCW = async ( if (fee === 'auto') { const gasPrice = clientOptions?.gasPrice ? clientOptions.gasPrice - : getGasPrice(chain); + : await getGasPrice(chain); fee = await estimateFee(client, sender, messages, gasPrice, memo); }