diff --git a/packages/bridge/src/axelar/index.ts b/packages/bridge/src/axelar/index.ts index d61d6b8f4d..f9a1338e5f 100644 --- a/packages/bridge/src/axelar/index.ts +++ b/packages/bridge/src/axelar/index.ts @@ -594,7 +594,7 @@ export class AxelarBridgeProvider implements BridgeProvider { ); } - const { typeUrl, value: msg } = makeIBCTransferMsg({ + const { typeUrl, value: msg } = await makeIBCTransferMsg({ receiver: depositAddress, sender: fromAddress, sourceChannel: ibcTransferMethod.chain.channelId, diff --git a/packages/bridge/src/ibc/index.ts b/packages/bridge/src/ibc/index.ts index c746fb6872..e75220ff1a 100644 --- a/packages/bridge/src/ibc/index.ts +++ b/packages/bridge/src/ibc/index.ts @@ -149,7 +149,7 @@ export class IbcBridgeProvider implements BridgeProvider { chainId: params.toChain.chainId.toString(), }); - const { typeUrl, value: msg } = makeIBCTransferMsg({ + const { typeUrl, value: msg } = await makeIBCTransferMsg({ receiver: params.toAddress, sender: params.fromAddress, sourceChannel, diff --git a/packages/bridge/src/skip/index.ts b/packages/bridge/src/skip/index.ts index e9a8e98914..ea87874416 100644 --- a/packages/bridge/src/skip/index.ts +++ b/packages/bridge/src/skip/index.ts @@ -485,7 +485,7 @@ export class SkipBridgeProvider implements BridgeProvider { }[]; }; - const { typeUrl, value: msg } = makeExecuteCosmwasmContractMsg({ + const { typeUrl, value: msg } = await makeExecuteCosmwasmContractMsg({ sender: cosmwasmData.sender, contract: cosmwasmData.contract, msg: Buffer.from(JSON.stringify(cosmwasmData.msg)), @@ -510,7 +510,7 @@ export class SkipBridgeProvider implements BridgeProvider { : { destinationAddress: messageData.receiver } ); - const { typeUrl, value } = makeIBCTransferMsg({ + const { typeUrl, value } = await makeIBCTransferMsg({ sourcePort: messageData.source_port, sourceChannel: messageData.source_channel, token: { diff --git a/packages/bridge/src/squid/index.ts b/packages/bridge/src/squid/index.ts index 5fa649514f..97bc691d32 100644 --- a/packages/bridge/src/squid/index.ts +++ b/packages/bridge/src/squid/index.ts @@ -545,7 +545,7 @@ export class SquidBridgeProvider implements BridgeProvider { : { destinationAddress: ibcData.msg.receiver } ); - const { typeUrl, value: msg } = makeIBCTransferMsg({ + const { typeUrl, value: msg } = await makeIBCTransferMsg({ memo: ibcData.msg.memo, receiver: ibcData.msg.receiver, sender: ibcData.msg.sender, @@ -578,7 +578,7 @@ export class SquidBridgeProvider implements BridgeProvider { }; }; - const { typeUrl, value: msg } = makeExecuteCosmwasmContractMsg({ + const { typeUrl, value: msg } = await makeExecuteCosmwasmContractMsg({ sender: fromAddress, contract: cosmwasmData.msg.wasm.contract, msg: Buffer.from(JSON.stringify(cosmwasmData.msg.wasm.msg)), diff --git a/packages/stores/src/account/cosmos.ts b/packages/stores/src/account/cosmos.ts index 2badaaa112..bdc0affe85 100644 --- a/packages/stores/src/account/cosmos.ts +++ b/packages/stores/src/account/cosmos.ts @@ -115,7 +115,7 @@ export class CosmosAccountImpl { destinationInfo.network ).version.toString(); - const msg = makeIBCTransferMsg({ + const msg = await makeIBCTransferMsg({ sourcePort: channel.portId, sourceChannel: channel.channelId, token: { diff --git a/packages/stores/src/account/cosmwasm.ts b/packages/stores/src/account/cosmwasm.ts index 5855db3c8d..2791f63bcc 100644 --- a/packages/stores/src/account/cosmwasm.ts +++ b/packages/stores/src/account/cosmwasm.ts @@ -79,7 +79,7 @@ export class CosmwasmAccountImpl { onFulfill?: (tx: DeliverTxResponse) => void; } ) { - const msg = makeExecuteCosmwasmContractMsg({ + const msg = await makeExecuteCosmwasmContractMsg({ sender: this.address, contract: contractAddress, msg: obj, @@ -117,14 +117,16 @@ export class CosmwasmAccountImpl { onFulfill?: (tx: DeliverTxResponse) => void; } ) { - const mappedMsgs = msgs.map(({ msg, funds, contractAddress }) => { - return makeExecuteCosmwasmContractMsg({ - sender: this.address, - contract: contractAddress, - msg, - funds, - }); - }); + const mappedMsgs = await Promise.all( + msgs.map(async ({ msg, funds, contractAddress }) => { + return await makeExecuteCosmwasmContractMsg({ + sender: this.address, + contract: contractAddress, + msg, + funds, + }); + }) + ); await this.base.signAndBroadcast( this.chainId, diff --git a/packages/stores/src/account/osmosis/index.ts b/packages/stores/src/account/osmosis/index.ts index 00bfc050bf..724dec2f37 100644 --- a/packages/stores/src/account/osmosis/index.ts +++ b/packages/stores/src/account/osmosis/index.ts @@ -142,7 +142,7 @@ export class OsmosisAccountImpl { }); } - const msg = makeCreateBalancerPoolMsg({ + const msg = await makeCreateBalancerPoolMsg({ futurePoolGovernor: "24h", poolAssets, sender: this.address, @@ -204,7 +204,7 @@ export class OsmosisAccountImpl { memo: string = "", onFulfill?: (tx: DeliverTxResponse) => void ) { - const msg = makeCreateConcentratedPoolMsg({ + const msg = await makeCreateConcentratedPoolMsg({ denom0, denom1, sender: this.address, @@ -310,7 +310,7 @@ export class OsmosisAccountImpl { sortedScalingFactors.push(BigInt(scalingFactor.toString())); }); - const msg = makeCreateStableswapPoolMsg({ + const msg = await makeCreateStableswapPoolMsg({ sender: this.address, futurePoolGovernor: "24h", scalingFactors: sortedScalingFactors, @@ -424,7 +424,7 @@ export class OsmosisAccountImpl { }; }); - const msg = makeJoinPoolMsg({ + const msg = await makeJoinPoolMsg({ poolId: BigInt(poolId), sender: this.address, shareOutAmount: new Dec(shareOutAmount) @@ -546,7 +546,7 @@ export class OsmosisAccountImpl { .mul(outRatio) .truncate(); - const msg = makeJoinSwapExternAmountInMsg({ + const msg = await makeJoinSwapExternAmountInMsg({ poolId: BigInt(poolId), sender: this.address, tokenIn: { @@ -649,7 +649,7 @@ export class OsmosisAccountImpl { let msg; if (superfluidValidatorAddress) { // send superfluid delegate version (full range only) - msg = makeCreateFullRangePositionAndSuperfluidDelegateMsg({ + msg = await makeCreateFullRangePositionAndSuperfluidDelegateMsg({ valAddr: superfluidValidatorAddress, coins: sortedCoins, poolId: BigInt(poolId), @@ -712,7 +712,7 @@ export class OsmosisAccountImpl { } // create position message with custom price range - msg = makeCreatePositionMsg({ + msg = await makeCreatePositionMsg({ poolId: BigInt(poolId), lowerTick: BigInt(lowerTick.toString()), upperTick: BigInt(upperTick.toString()), @@ -797,7 +797,7 @@ export class OsmosisAccountImpl { .toString(), })); - const msg = makeCreatePositionMsg({ + const msg = await makeCreatePositionMsg({ poolId: BigInt(poolId), lowerTick: BigInt(minTick.toString()), upperTick: BigInt(maxTick.toString()), @@ -849,7 +849,7 @@ export class OsmosisAccountImpl { if (!fullLiquidityAmount) throw new Error("No liquidity amount found"); if (!poolId) throw new Error("No pool ID found"); - const withdrawPositionMsg = makeWithdrawPositionMsg({ + const withdrawPositionMsg = await makeWithdrawPositionMsg({ positionId: BigInt(positionId), sender: this.address, liquidityAmount: fullLiquidityAmount.toString(), @@ -859,7 +859,7 @@ export class OsmosisAccountImpl { throw new Error("No assets found in position"); const createAndSfDelegateMsg = - makeCreateFullRangePositionAndSuperfluidDelegateMsg({ + await makeCreateFullRangePositionAndSuperfluidDelegateMsg({ poolId: BigInt(poolId), coins: [ queryPosition.baseAsset.toCoin(), @@ -933,7 +933,7 @@ export class OsmosisAccountImpl { queryDelegatedPositions.delegatedPositionIds.includes(positionId); const msg = isSuperfluidStaked - ? makeAddToConcentratedLiquiditySuperfluidPositionMsg({ + ? await makeAddToConcentratedLiquiditySuperfluidPositionMsg({ positionId: BigInt(positionId), sender: this.address, tokenDesired0: { @@ -945,7 +945,7 @@ export class OsmosisAccountImpl { amount: amount1WithSlippage, }, }) - : makeAddToPositionMsg({ + : await makeAddToPositionMsg({ amount0: coin0.amount, amount1: coin1.amount, positionId: BigInt(positionId), @@ -1011,7 +1011,7 @@ export class OsmosisAccountImpl { memo: string = "", onFulfill?: (tx: DeliverTxResponse) => void ) { - const msg = makeWithdrawPositionMsg({ + const msg = await makeWithdrawPositionMsg({ liquidityAmount: liquidityAmount.toString(), positionId: BigInt(positionId), sender: this.address, @@ -1075,11 +1075,11 @@ export class OsmosisAccountImpl { memo: string = "", onFulfill?: (tx: DeliverTxResponse) => void ) { - const spreadRewardsMsg = makeCollectSpreadRewardsMsg({ + const spreadRewardsMsg = await makeCollectSpreadRewardsMsg({ positionIds: positionIdsWithSpreadRewards.map((val) => BigInt(val)), sender: this.address, }); - const incentiveRewardsMsg = makeCollectIncentivesMsg({ + const incentiveRewardsMsg = await makeCollectIncentivesMsg({ positionIds: positionIdsWithIncentiveRewards.map((val) => BigInt(val)), sender: this.address, }); @@ -1159,7 +1159,7 @@ export class OsmosisAccountImpl { signOptions?: SignOptions & { fee?: StdFee }, onFulfill?: (tx: DeliverTxResponse) => void ) { - const msg = makeSplitRoutesSwapExactAmountInMsg({ + const msg = await makeSplitRoutesSwapExactAmountInMsg({ routes, tokenIn, tokenOutMinAmount, @@ -1231,7 +1231,7 @@ export class OsmosisAccountImpl { signOptions?: SignOptions & { fee?: StdFee }, onFulfill?: (tx: DeliverTxResponse) => void ) { - const msg = makeSwapExactAmountInMsg({ + const msg = await makeSwapExactAmountInMsg({ pools, tokenIn, tokenOutMinAmount, @@ -1309,7 +1309,7 @@ export class OsmosisAccountImpl { .truncate(); const coin = new Coin(tokenOut.currency.coinMinimalDenom, outUAmount); - const msg = makeSwapExactAmountOutMsg({ + const msg = await makeSwapExactAmountOutMsg({ sender: this.address, tokenInMaxAmount, tokenOut: { @@ -1415,7 +1415,7 @@ export class OsmosisAccountImpl { }; }); - const msg = makeExitPoolMsg({ + const msg = await makeExitPoolMsg({ poolId: BigInt(poolId), sender: this.address, shareInAmount: new Dec(shareInAmount) @@ -1476,7 +1476,7 @@ export class OsmosisAccountImpl { }; }); - const msg = makeLockTokensMsg({ + const msg = await makeLockTokensMsg({ owner: this.address, coins: primitiveTokens, duration: Duration.fromPartial({ @@ -1524,13 +1524,15 @@ export class OsmosisAccountImpl { ) { if (lockIds.length === 0) throw new Error("No locks to delegate"); - const msgs = lockIds.map((lockId) => { - return makeSuperfluidDelegateMsg({ - sender: this.address, - lockId: BigInt(lockId), - valAddr: validatorAddress, - }); - }); + const msgs = await Promise.all( + lockIds.map(async (lockId) => { + return await makeSuperfluidDelegateMsg({ + sender: this.address, + lockId: BigInt(lockId), + valAddr: validatorAddress, + }); + }) + ); await this.base.signAndBroadcast( this.chainId, @@ -1587,7 +1589,7 @@ export class OsmosisAccountImpl { }; }); - const msg = makeLockAndSuperfluidDelegateMsg({ + const msg = await makeLockAndSuperfluidDelegateMsg({ sender: this.address, coins: primitiveTokens, valAddr: validatorAddress, @@ -1637,13 +1639,15 @@ export class OsmosisAccountImpl { memo: string = "", onFulfill?: (tx: DeliverTxResponse) => void ) { - const msgs = lockIds.map((lockId) => { - return makeBeginUnlockingMsg({ - owner: this.address, - ID: BigInt(lockId), - coins: [], - }); - }); + const msgs = await Promise.all( + lockIds.map(async (lockId) => { + return makeBeginUnlockingMsg({ + owner: this.address, + ID: BigInt(lockId), + coins: [], + }); + }) + ); await this.base.signAndBroadcast( this.chainId, @@ -1688,11 +1692,12 @@ export class OsmosisAccountImpl { memo: string = "", onFulfill?: (tx: DeliverTxResponse) => void ) { - const msgs = locks.reduce((msgs, lock) => { + const msgs = await locks.reduce(async (msgsPromise, lock) => { + const msgs = await msgsPromise; if (!lock.isSynthetic) { // normal unlock msgs.push( - makeBeginUnlockingMsg({ + await makeBeginUnlockingMsg({ owner: this.address, ID: BigInt(lock.lockId), coins: [], @@ -1701,18 +1706,18 @@ export class OsmosisAccountImpl { } else { // unbond and unlock msgs.push( - makeSuperfluidUndelegateMsg({ + await makeSuperfluidUndelegateMsg({ sender: this.address, lockId: BigInt(lock.lockId), }), - makeSuperfluidUnbondLockMsg({ + await makeSuperfluidUnbondLockMsg({ sender: this.address, lockId: BigInt(lock.lockId), }) ); } return msgs; - }, [] as EncodeObject[]); + }, Promise.resolve([] as EncodeObject[])); await this.base.signAndBroadcast( this.chainId, @@ -1779,7 +1784,7 @@ export class OsmosisAccountImpl { this.chainId, "undelegateFromValidatorSet", [ - makeUndelegateFromRebalancedValidatorSetMsg({ + await makeUndelegateFromRebalancedValidatorSetMsg({ delegator: this.address, coin: { denom: coin.denom.coinMinimalDenom, @@ -1829,7 +1834,7 @@ export class OsmosisAccountImpl { this.chainId, "undelegateFromValidatorSet", [ - makeUndelegateFromValidatorSetMsg({ + await makeUndelegateFromValidatorSetMsg({ delegator: this.address, coin: { denom: coin.denom.coinMinimalDenom, @@ -1879,7 +1884,7 @@ export class OsmosisAccountImpl { this.chainId, "delegateToValidatorSet", [ - makeDelegateToValidatorSetMsg({ + await makeDelegateToValidatorSetMsg({ delegator: this.address, coin: { denom: coin.denom.coinMinimalDenom, @@ -1924,7 +1929,7 @@ export class OsmosisAccountImpl { this.chainId, "withdrawDelegationRewards", [ - makeWithdrawDelegationRewardsMsg({ + await makeWithdrawDelegationRewardsMsg({ delegator: this.address, }), ], @@ -1974,7 +1979,7 @@ export class OsmosisAccountImpl { this.chainId, "setValidatorSetPreference", [ - makeSetValidatorSetPreferenceMsg({ + await makeSetValidatorSetPreferenceMsg({ delegator: this.address, preferences: validators.map((validator) => ({ weight, @@ -2029,15 +2034,17 @@ export class OsmosisAccountImpl { "Please provide 1 or more validator address to set as preference" ); - const setValidatorSetPreferenceMsg = makeSetValidatorSetPreferenceMsg({ - delegator: this.address, - preferences: validators.map((validator) => ({ - weight, - valOperAddress: validator, - })), - }); + const setValidatorSetPreferenceMsg = await makeSetValidatorSetPreferenceMsg( + { + delegator: this.address, + preferences: validators.map((validator) => ({ + weight, + valOperAddress: validator, + })), + } + ); - const setDelegateToValidatorSetMsg = makeDelegateToValidatorSetMsg({ + const setDelegateToValidatorSetMsg = await makeDelegateToValidatorSetMsg({ delegator: this.address, coin: { denom: coin.denom.coinMinimalDenom, @@ -2091,11 +2098,13 @@ export class OsmosisAccountImpl { memo: string = "", onFulfill?: (tx: DeliverTxResponse) => void ) { - const withdrawDelegationRewardsMsg = makeWithdrawDelegationRewardsMsg({ - delegator: this.address, - }); + const withdrawDelegationRewardsMsg = await makeWithdrawDelegationRewardsMsg( + { + delegator: this.address, + } + ); - const delegateToValidatorSetMsg = makeDelegateToValidatorSetMsg({ + const delegateToValidatorSetMsg = await makeDelegateToValidatorSetMsg({ delegator: this.address, coin: { denom: coin.denom.coinMinimalDenom, @@ -2160,7 +2169,10 @@ export class OsmosisAccountImpl { sender: this.address, }) ); - const msgs = [...removeAuthenticatorMsgs, ...addAuthenticatorMsgs]; + const msgs = await Promise.all([ + ...removeAuthenticatorMsgs, + ...addAuthenticatorMsgs, + ]); await this.base.signAndBroadcast( this.chainId, @@ -2199,12 +2211,14 @@ export class OsmosisAccountImpl { memo: string = "", onFulfill?: (tx: DeliverTxResponse) => void ) { - const addAuthenticatorMsgs = authenticators.map((authenticator) => - makeAddAuthenticatorMsg({ - type: authenticator.type, - data: authenticator.data, - sender: this.address, - }) + const addAuthenticatorMsgs = await Promise.all( + authenticators.map((authenticator) => + makeAddAuthenticatorMsg({ + type: authenticator.type, + data: authenticator.data, + sender: this.address, + }) + ) ); await this.base.signAndBroadcast( @@ -2241,7 +2255,7 @@ export class OsmosisAccountImpl { memo: string = "", onFulfill?: (tx: DeliverTxResponse) => void ) { - const removeAuthenticatorMsg = makeRemoveAuthenticatorMsg({ + const removeAuthenticatorMsg = await makeRemoveAuthenticatorMsg({ id: id, sender: this.address, }); diff --git a/packages/stores/src/tests/test-env.ts b/packages/stores/src/tests/test-env.ts index 97daa136c4..2c8742990c 100644 --- a/packages/stores/src/tests/test-env.ts +++ b/packages/stores/src/tests/test-env.ts @@ -69,7 +69,6 @@ export class RootStore { OsmosisAccount.use({ queriesStore: this.queriesStore }), CosmosAccount.use({ queriesStore: this.queriesStore, - msgOptsCreator: () => ({ ibcTransfer: { gas: 130000 } }), }), CosmwasmAccount.use({ queriesStore: this.queriesStore }) ); diff --git a/packages/tx/src/codec.ts b/packages/tx/src/codec.ts index 401b5d4bda..7fb2020edf 100644 --- a/packages/tx/src/codec.ts +++ b/packages/tx/src/codec.ts @@ -1,5 +1,5 @@ import { Buffer } from "buffer/"; -import { Any } from "cosmjs-types/google/protobuf/any"; +import type { Any } from "cosmjs-types/google/protobuf/any"; export function encodeAnyBase64({ typeUrl, value }: Any): { typeUrl: string; @@ -25,3 +25,15 @@ export function decodeAnyBase64({ value: Buffer.from(value, "base64"), }; } + +export async function getOsmosisCodec() { + return import("@osmosis-labs/proto-codecs").then((module) => module.osmosis); +} + +export async function getCosmwasmCodec() { + return import("@osmosis-labs/proto-codecs").then((module) => module.cosmwasm); +} + +export async function getIbcCodec() { + return import("@osmosis-labs/proto-codecs").then((module) => module.ibc); +} diff --git a/packages/tx/src/index.ts b/packages/tx/src/index.ts index 3e3fc590ce..f5ece960ec 100644 --- a/packages/tx/src/index.ts +++ b/packages/tx/src/index.ts @@ -3,6 +3,5 @@ export * from "./error"; export * from "./events"; export * from "./gas"; export * from "./message-composers"; -export * from "./msg"; export * from "./poll-status"; export * from "./tracer"; diff --git a/packages/tx/src/message-composers/cosmos.ts b/packages/tx/src/message-composers/cosmos.ts index e9abebc755..143d2a4611 100644 --- a/packages/tx/src/message-composers/cosmos.ts +++ b/packages/tx/src/message-composers/cosmos.ts @@ -1,8 +1,9 @@ -import { ibc } from "@osmosis-labs/proto-codecs"; import { Coin } from "@osmosis-labs/proto-codecs/build/codegen/cosmos/base/v1beta1/coin"; import { Height } from "@osmosis-labs/proto-codecs/build/codegen/ibc/core/client/v1/client"; -export function makeIBCTransferMsg({ +import { getIbcCodec } from "../codec"; + +export async function makeIBCTransferMsg({ sourcePort, sourceChannel, token, @@ -35,19 +36,22 @@ export function makeIBCTransferMsg({ /** optional memo */ memo: string; }) { - return ibc.applications.transfer.v1.MessageComposer.withTypeUrl.transfer({ - sourcePort, - sourceChannel, - token, - receiver, - sender, - // Revision number can be undefined, but our proto makes it required - // so we need to cast it to Partial to make it optional - // @ts-expect-error - timeoutHeight, - timeoutTimestamp, - memo, - }); + const ibcCodec = await getIbcCodec(); + return ibcCodec.applications.transfer.v1.MessageComposer.withTypeUrl.transfer( + { + sourcePort, + sourceChannel, + token, + receiver, + sender, + // Revision number can be undefined, but our proto makes it required + // so we need to cast it to Partial to make it optional + // @ts-expect-error + timeoutHeight, + timeoutTimestamp, + memo, + } + ); } makeIBCTransferMsg.gas = 250_000; diff --git a/packages/tx/src/message-composers/cosmwasm.ts b/packages/tx/src/message-composers/cosmwasm.ts index 6a8945c1c6..2fc5db2d90 100644 --- a/packages/tx/src/message-composers/cosmwasm.ts +++ b/packages/tx/src/message-composers/cosmwasm.ts @@ -1,7 +1,10 @@ -import { cosmwasm } from "@osmosis-labs/proto-codecs"; import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin"; -export function makeExecuteCosmwasmContractMsg>({ +import { getCosmwasmCodec } from "../codec"; + +export async function makeExecuteCosmwasmContractMsg< + Obj extends Record +>({ sender, contract, msg, @@ -12,6 +15,7 @@ export function makeExecuteCosmwasmContractMsg>({ msg: Obj; funds: Coin[]; }) { + const cosmwasm = await getCosmwasmCodec(); return cosmwasm.wasm.v1.MessageComposer.withTypeUrl.executeContract({ sender, contract, diff --git a/packages/tx/src/message-composers/osmosis/authenticator.ts b/packages/tx/src/message-composers/osmosis/authenticator.ts index f11db45e53..e620fa6156 100644 --- a/packages/tx/src/message-composers/osmosis/authenticator.ts +++ b/packages/tx/src/message-composers/osmosis/authenticator.ts @@ -1,6 +1,6 @@ -import { osmosis } from "@osmosis-labs/proto-codecs"; +import { getOsmosisCodec } from "../../codec"; -export function makeAddAuthenticatorMsg({ +export async function makeAddAuthenticatorMsg({ type, data, sender, @@ -9,6 +9,7 @@ export function makeAddAuthenticatorMsg({ data: Uint8Array; sender: string; }) { + const osmosis = await getOsmosisCodec(); return osmosis.smartaccount.v1beta1.MessageComposer.withTypeUrl.addAuthenticator( { data, @@ -18,13 +19,14 @@ export function makeAddAuthenticatorMsg({ ); } -export function makeRemoveAuthenticatorMsg({ +export async function makeRemoveAuthenticatorMsg({ id, sender, }: { id: bigint; sender: string; }) { + const osmosis = await getOsmosisCodec(); return osmosis.smartaccount.v1beta1.MessageComposer.withTypeUrl.removeAuthenticator( { id, diff --git a/packages/tx/src/message-composers/osmosis/balancer.ts b/packages/tx/src/message-composers/osmosis/balancer.ts index 315acfef9d..6be2ea068d 100644 --- a/packages/tx/src/message-composers/osmosis/balancer.ts +++ b/packages/tx/src/message-composers/osmosis/balancer.ts @@ -1,12 +1,14 @@ -import { osmosis } from "@osmosis-labs/proto-codecs"; import { MsgCreateBalancerPool } from "@osmosis-labs/proto-codecs/build/codegen/osmosis/gamm/poolmodels/balancer/v1beta1/tx"; -export function makeCreateBalancerPoolMsg({ +import { getOsmosisCodec } from "../../codec"; + +export async function makeCreateBalancerPoolMsg({ futurePoolGovernor, poolAssets, sender, poolParams, }: MsgCreateBalancerPool) { + const osmosis = await getOsmosisCodec(); return osmosis.gamm.poolmodels.balancer.v1beta1.MessageComposer.withTypeUrl.createBalancerPool( { futurePoolGovernor, diff --git a/packages/tx/src/message-composers/osmosis/concentrated.ts b/packages/tx/src/message-composers/osmosis/concentrated.ts index 0b76c694f5..51797ed040 100644 --- a/packages/tx/src/message-composers/osmosis/concentrated.ts +++ b/packages/tx/src/message-composers/osmosis/concentrated.ts @@ -1,4 +1,3 @@ -import { osmosis } from "@osmosis-labs/proto-codecs"; import { MsgCreateConcentratedPool } from "@osmosis-labs/proto-codecs/build/codegen/osmosis/concentratedliquidity/poolmodel/concentrated/v1beta1/tx"; import { MsgAddToPosition, @@ -8,13 +7,16 @@ import { MsgWithdrawPosition, } from "@osmosis-labs/proto-codecs/build/codegen/osmosis/concentratedliquidity/v1beta1/tx"; -export function makeCreateConcentratedPoolMsg({ +import { getOsmosisCodec } from "../../codec"; + +export async function makeCreateConcentratedPoolMsg({ denom0, denom1, sender, spreadFactor, tickSpacing, }: MsgCreateConcentratedPool) { + const osmosis = await getOsmosisCodec(); return osmosis.concentratedliquidity.poolmodel.concentrated.v1beta1.MessageComposer.withTypeUrl.createConcentratedPool( { denom0, @@ -26,7 +28,7 @@ export function makeCreateConcentratedPoolMsg({ ); } -export function makeCreatePositionMsg({ +export async function makeCreatePositionMsg({ poolId, sender, lowerTick, @@ -35,6 +37,7 @@ export function makeCreatePositionMsg({ tokenMinAmount0, tokenMinAmount1, }: MsgCreatePosition) { + const osmosis = await getOsmosisCodec(); return osmosis.concentratedliquidity.v1beta1.MessageComposer.withTypeUrl.createPosition( { poolId, @@ -50,10 +53,11 @@ export function makeCreatePositionMsg({ makeCreatePositionMsg.gas = 3_000_000 as const; -export function makeCollectSpreadRewardsMsg({ +export async function makeCollectSpreadRewardsMsg({ positionIds, sender, }: MsgCollectSpreadRewards) { + const osmosis = await getOsmosisCodec(); return osmosis.concentratedliquidity.v1beta1.MessageComposer.withTypeUrl.collectSpreadRewards( { positionIds, @@ -62,10 +66,11 @@ export function makeCollectSpreadRewardsMsg({ ); } -export function makeCollectIncentivesMsg({ +export async function makeCollectIncentivesMsg({ positionIds, sender, }: MsgCollectIncentives) { + const osmosis = await getOsmosisCodec(); return osmosis.concentratedliquidity.v1beta1.MessageComposer.withTypeUrl.collectIncentives( { positionIds, @@ -74,11 +79,12 @@ export function makeCollectIncentivesMsg({ ); } -export function makeWithdrawPositionMsg({ +export async function makeWithdrawPositionMsg({ positionId, sender, liquidityAmount, }: MsgWithdrawPosition) { + const osmosis = await getOsmosisCodec(); return osmosis.concentratedliquidity.v1beta1.MessageComposer.withTypeUrl.withdrawPosition( { positionId, @@ -88,7 +94,7 @@ export function makeWithdrawPositionMsg({ ); } -export function makeAddToPositionMsg({ +export async function makeAddToPositionMsg({ positionId, sender, amount0, @@ -96,6 +102,7 @@ export function makeAddToPositionMsg({ tokenMinAmount0, tokenMinAmount1, }: MsgAddToPosition) { + const osmosis = await getOsmosisCodec(); return osmosis.concentratedliquidity.v1beta1.MessageComposer.withTypeUrl.addToPosition( { positionId, diff --git a/packages/tx/src/message-composers/osmosis/gamm.ts b/packages/tx/src/message-composers/osmosis/gamm.ts index e4f8266aa7..cc947ac84d 100644 --- a/packages/tx/src/message-composers/osmosis/gamm.ts +++ b/packages/tx/src/message-composers/osmosis/gamm.ts @@ -1,16 +1,18 @@ -import { osmosis } from "@osmosis-labs/proto-codecs"; import { MsgExitPool, MsgJoinPool, MsgJoinSwapExternAmountIn, } from "@osmosis-labs/proto-codecs/build/codegen/osmosis/gamm/v1beta1/tx"; -export function makeJoinPoolMsg({ +import { getOsmosisCodec } from "../../codec"; + +export async function makeJoinPoolMsg({ poolId, sender, shareOutAmount, tokenInMaxs, }: MsgJoinPool) { + const osmosis = await getOsmosisCodec(); return osmosis.gamm.v1beta1.MessageComposer.withTypeUrl.joinPool({ poolId, sender, @@ -21,12 +23,13 @@ export function makeJoinPoolMsg({ makeJoinPoolMsg.shareCoinDecimals = 18; -export function makeJoinSwapExternAmountInMsg({ +export async function makeJoinSwapExternAmountInMsg({ poolId, sender, tokenIn, shareOutMinAmount, }: MsgJoinSwapExternAmountIn) { + const osmosis = await getOsmosisCodec(); return osmosis.gamm.v1beta1.MessageComposer.withTypeUrl.joinSwapExternAmountIn( { poolId, @@ -39,12 +42,13 @@ export function makeJoinSwapExternAmountInMsg({ makeJoinSwapExternAmountInMsg.shareCoinDecimals = 18; -export function makeExitPoolMsg({ +export async function makeExitPoolMsg({ poolId, sender, shareInAmount, tokenOutMins, }: MsgExitPool) { + const osmosis = await getOsmosisCodec(); return osmosis.gamm.v1beta1.MessageComposer.withTypeUrl.exitPool({ poolId, sender, diff --git a/packages/tx/src/message-composers/osmosis/lockup.ts b/packages/tx/src/message-composers/osmosis/lockup.ts index eec61d3b97..31b95f176f 100644 --- a/packages/tx/src/message-composers/osmosis/lockup.ts +++ b/packages/tx/src/message-composers/osmosis/lockup.ts @@ -1,10 +1,16 @@ -import { osmosis } from "@osmosis-labs/proto-codecs"; import { MsgBeginUnlocking, MsgLockTokens, } from "@osmosis-labs/proto-codecs/build/codegen/osmosis/lockup/tx"; -export function makeLockTokensMsg({ owner, coins, duration }: MsgLockTokens) { +import { getOsmosisCodec } from "../../codec"; + +export async function makeLockTokensMsg({ + owner, + coins, + duration, +}: MsgLockTokens) { + const osmosis = await getOsmosisCodec(); return osmosis.lockup.MessageComposer.withTypeUrl.lockTokens({ owner, coins, @@ -12,7 +18,12 @@ export function makeLockTokensMsg({ owner, coins, duration }: MsgLockTokens) { }); } -export function makeBeginUnlockingMsg({ owner, ID, coins }: MsgBeginUnlocking) { +export async function makeBeginUnlockingMsg({ + owner, + ID, + coins, +}: MsgBeginUnlocking) { + const osmosis = await getOsmosisCodec(); return osmosis.lockup.MessageComposer.withTypeUrl.beginUnlocking({ owner, ID, diff --git a/packages/tx/src/message-composers/osmosis/poolmanager.ts b/packages/tx/src/message-composers/osmosis/poolmanager.ts index 120c296a8e..7531053fb7 100644 --- a/packages/tx/src/message-composers/osmosis/poolmanager.ts +++ b/packages/tx/src/message-composers/osmosis/poolmanager.ts @@ -1,14 +1,15 @@ -import { osmosis } from "@osmosis-labs/proto-codecs"; import { MsgSwapExactAmountOut } from "@osmosis-labs/proto-codecs/build/codegen/osmosis/gamm/v1beta1/tx"; import { Currency } from "@osmosis-labs/types"; +import { getOsmosisCodec } from "../../codec"; + /** * Constructs a message for performing a split route swap with an exact input amount across * multiple routes. This function allows users to swap a specific amount of one token * for another through a series of split routes, specifying the minimum amount of * the output token they are willing to accept. */ -export function makeSplitRoutesSwapExactAmountInMsg({ +export async function makeSplitRoutesSwapExactAmountInMsg({ routes, tokenIn, tokenOutMinAmount, @@ -25,6 +26,7 @@ export function makeSplitRoutesSwapExactAmountInMsg({ tokenOutMinAmount: string; userOsmoAddress: string; }) { + const osmosis = await getOsmosisCodec(); return osmosis.poolmanager.v1beta1.MessageComposer.withTypeUrl.splitRouteSwapExactAmountIn( { sender: userOsmoAddress, @@ -47,7 +49,7 @@ export function makeSplitRoutesSwapExactAmountInMsg({ * amount of one token for another through specified liquidity pools, with a minimum * acceptable amount of the output token. */ -export function makeSwapExactAmountInMsg({ +export async function makeSwapExactAmountInMsg({ pools, tokenIn, tokenOutMinAmount, @@ -61,6 +63,7 @@ export function makeSwapExactAmountInMsg({ tokenOutMinAmount: string; userOsmoAddress: string; }) { + const osmosis = await getOsmosisCodec(); return osmosis.poolmanager.v1beta1.MessageComposer.withTypeUrl.swapExactAmountIn( { sender: userOsmoAddress, @@ -79,12 +82,13 @@ export function makeSwapExactAmountInMsg({ ); } -export function makeSwapExactAmountOutMsg({ +export async function makeSwapExactAmountOutMsg({ sender, routes, tokenInMaxAmount, tokenOut, }: MsgSwapExactAmountOut) { + const osmosis = await getOsmosisCodec(); return osmosis.poolmanager.v1beta1.MessageComposer.withTypeUrl.swapExactAmountOut( { sender, diff --git a/packages/tx/src/message-composers/osmosis/stableswap.ts b/packages/tx/src/message-composers/osmosis/stableswap.ts index e412c6b425..aa05fd9404 100644 --- a/packages/tx/src/message-composers/osmosis/stableswap.ts +++ b/packages/tx/src/message-composers/osmosis/stableswap.ts @@ -1,7 +1,8 @@ -import { osmosis } from "@osmosis-labs/proto-codecs"; import { MsgCreateStableswapPool } from "@osmosis-labs/proto-codecs/build/codegen/osmosis/gamm/poolmodels/stableswap/v1beta1/tx"; -export function makeCreateStableswapPoolMsg({ +import { getOsmosisCodec } from "../../codec"; + +export async function makeCreateStableswapPoolMsg({ sender, poolParams, initialPoolLiquidity, @@ -9,6 +10,7 @@ export function makeCreateStableswapPoolMsg({ scalingFactorController, futurePoolGovernor, }: MsgCreateStableswapPool) { + const osmosis = await getOsmosisCodec(); return osmosis.gamm.poolmodels.stableswap.v1beta1.MessageComposer.withTypeUrl.createStableswapPool( { sender, diff --git a/packages/tx/src/message-composers/osmosis/superfluid.ts b/packages/tx/src/message-composers/osmosis/superfluid.ts index eac3148e17..027606257b 100644 --- a/packages/tx/src/message-composers/osmosis/superfluid.ts +++ b/packages/tx/src/message-composers/osmosis/superfluid.ts @@ -1,4 +1,3 @@ -import { osmosis } from "@osmosis-labs/proto-codecs"; import { MsgAddToConcentratedLiquiditySuperfluidPosition, MsgCreateFullRangePositionAndSuperfluidDelegate, @@ -8,11 +7,14 @@ import { MsgSuperfluidUndelegate, } from "@osmosis-labs/proto-codecs/build/codegen/osmosis/superfluid/tx"; -export function makeSuperfluidDelegateMsg({ +import { getOsmosisCodec } from "../../codec"; + +export async function makeSuperfluidDelegateMsg({ sender, lockId, valAddr, }: MsgSuperfluidDelegate) { + const osmosis = await getOsmosisCodec(); return osmosis.superfluid.MessageComposer.withTypeUrl.superfluidDelegate({ sender, lockId, @@ -20,11 +22,12 @@ export function makeSuperfluidDelegateMsg({ }); } -export function makeLockAndSuperfluidDelegateMsg({ +export async function makeLockAndSuperfluidDelegateMsg({ sender, coins, valAddr, }: MsgLockAndSuperfluidDelegate) { + const osmosis = await getOsmosisCodec(); return osmosis.superfluid.MessageComposer.withTypeUrl.lockAndSuperfluidDelegate( { sender, @@ -34,32 +37,35 @@ export function makeLockAndSuperfluidDelegateMsg({ ); } -export function makeSuperfluidUndelegateMsg({ +export async function makeSuperfluidUndelegateMsg({ sender, lockId, }: MsgSuperfluidUndelegate) { + const osmosis = await getOsmosisCodec(); return osmosis.superfluid.MessageComposer.withTypeUrl.superfluidUndelegate({ sender, lockId, }); } -export function makeSuperfluidUnbondLockMsg({ +export async function makeSuperfluidUnbondLockMsg({ sender, lockId, }: MsgSuperfluidUnbondLock) { + const osmosis = await getOsmosisCodec(); return osmosis.superfluid.MessageComposer.withTypeUrl.superfluidUnbondLock({ sender, lockId, }); } -export function makeCreateFullRangePositionAndSuperfluidDelegateMsg({ +export async function makeCreateFullRangePositionAndSuperfluidDelegateMsg({ poolId, sender, valAddr, coins, }: MsgCreateFullRangePositionAndSuperfluidDelegate) { + const osmosis = await getOsmosisCodec(); return osmosis.superfluid.MessageComposer.withTypeUrl.createFullRangePositionAndSuperfluidDelegate( { poolId, @@ -70,12 +76,13 @@ export function makeCreateFullRangePositionAndSuperfluidDelegateMsg({ ); } -export function makeAddToConcentratedLiquiditySuperfluidPositionMsg({ +export async function makeAddToConcentratedLiquiditySuperfluidPositionMsg({ positionId, sender, tokenDesired0, tokenDesired1, }: MsgAddToConcentratedLiquiditySuperfluidPosition) { + const osmosis = await getOsmosisCodec(); return osmosis.superfluid.MessageComposer.withTypeUrl.addToConcentratedLiquiditySuperfluidPosition( { positionId, diff --git a/packages/tx/src/message-composers/osmosis/valsetpref.ts b/packages/tx/src/message-composers/osmosis/valsetpref.ts index 93adad2166..3d927b898f 100644 --- a/packages/tx/src/message-composers/osmosis/valsetpref.ts +++ b/packages/tx/src/message-composers/osmosis/valsetpref.ts @@ -1,4 +1,3 @@ -import { osmosis } from "@osmosis-labs/proto-codecs"; import { MsgDelegateToValidatorSet, MsgSetValidatorSetPreference, @@ -7,10 +6,13 @@ import { MsgWithdrawDelegationRewards, } from "@osmosis-labs/proto-codecs/build/codegen/osmosis/valsetpref/v1beta1/tx"; -export function makeUndelegateFromValidatorSetMsg({ +import { getOsmosisCodec } from "../../codec"; + +export async function makeUndelegateFromValidatorSetMsg({ delegator, coin, }: MsgUndelegateFromValidatorSet) { + const osmosis = await getOsmosisCodec(); return osmosis.valsetpref.v1beta1.MessageComposer.withTypeUrl.undelegateFromValidatorSet( { delegator, @@ -19,10 +21,11 @@ export function makeUndelegateFromValidatorSetMsg({ ); } -export function makeDelegateToValidatorSetMsg({ +export async function makeDelegateToValidatorSetMsg({ delegator, coin, }: MsgDelegateToValidatorSet) { + const osmosis = await getOsmosisCodec(); return osmosis.valsetpref.v1beta1.MessageComposer.withTypeUrl.delegateToValidatorSet( { delegator, @@ -33,9 +36,10 @@ export function makeDelegateToValidatorSetMsg({ makeDelegateToValidatorSetMsg.gas = 500_000 as const; -export function makeWithdrawDelegationRewardsMsg({ +export async function makeWithdrawDelegationRewardsMsg({ delegator, }: MsgWithdrawDelegationRewards) { + const osmosis = await getOsmosisCodec(); return osmosis.valsetpref.v1beta1.MessageComposer.withTypeUrl.withdrawDelegationRewards( { delegator, @@ -43,10 +47,11 @@ export function makeWithdrawDelegationRewardsMsg({ ); } -export function makeSetValidatorSetPreferenceMsg({ +export async function makeSetValidatorSetPreferenceMsg({ delegator, preferences, }: MsgSetValidatorSetPreference) { + const osmosis = await getOsmosisCodec(); return osmosis.valsetpref.v1beta1.MessageComposer.withTypeUrl.setValidatorSetPreference( { delegator, @@ -55,10 +60,11 @@ export function makeSetValidatorSetPreferenceMsg({ ); } -export function makeUndelegateFromRebalancedValidatorSetMsg({ +export async function makeUndelegateFromRebalancedValidatorSetMsg({ delegator, coin, }: MsgUndelegateFromRebalancedValidatorSet) { + const osmosis = await getOsmosisCodec(); return osmosis.valsetpref.v1beta1.MessageComposer.withTypeUrl.undelegateFromRebalancedValidatorSet( { delegator, diff --git a/packages/tx/tsconfig.json b/packages/tx/tsconfig.json index f94b2526a2..11f48d2cf5 100644 --- a/packages/tx/tsconfig.json +++ b/packages/tx/tsconfig.json @@ -4,7 +4,7 @@ "outDir": "build", "declaration": true, "rootDir": "src", - "module": "ES6" + "module": "esnext" }, "include": ["src/**/*"] } diff --git a/packages/web/components/earn/rewards/index.tsx b/packages/web/components/earn/rewards/index.tsx index f147eb63c5..ebc541f898 100644 --- a/packages/web/components/earn/rewards/index.tsx +++ b/packages/web/components/earn/rewards/index.tsx @@ -45,18 +45,18 @@ export const EarnRewards = ({ if (!account) return; - filteredUnclaimedRewards.forEach(({ id, platform }) => { + for (const { id, platform } of filteredUnclaimedRewards) { switch (platform) { case "Osmosis": messages.push( - makeWithdrawDelegationRewardsMsg({ + await makeWithdrawDelegationRewardsMsg({ delegator: account.address ?? "", }) ); break; case "Quasar": messages.push( - makeExecuteCosmwasmContractMsg({ + await makeExecuteCosmwasmContractMsg({ contract: id, msg: Buffer.from( JSON.stringify({ @@ -72,7 +72,7 @@ export const EarnRewards = ({ break; case "Levana": messages.push( - makeExecuteCosmwasmContractMsg({ + await makeExecuteCosmwasmContractMsg({ contract: id.split("-")[0], // this strips the -x|lp part of the contract id msg: Buffer.from( JSON.stringify({ @@ -85,7 +85,7 @@ export const EarnRewards = ({ ); break; } - }); + } try { await accountStore.signAndBroadcast( diff --git a/packages/web/components/one-click-trading/one-click-trading-settings.tsx b/packages/web/components/one-click-trading/one-click-trading-settings.tsx index bdc3fa3fbc..6fe836252a 100644 --- a/packages/web/components/one-click-trading/one-click-trading-settings.tsx +++ b/packages/web/components/one-click-trading/one-click-trading-settings.tsx @@ -131,8 +131,8 @@ export const OneClickTradingSettings = ({ const { data: estimateRemoveTxData, isLoading: isLoadingEstimateRemoveTx } = useEstimateTxFees({ messages: oneClickTradingInfo - ? [ - makeRemoveAuthenticatorMsg({ + ? async () => [ + await makeRemoveAuthenticatorMsg({ id: BigInt(oneClickTradingInfo.authenticatorId), sender: oneClickTradingInfo.userOsmoAddress, }), diff --git a/packages/web/hooks/limit-orders/use-place-limit.ts b/packages/web/hooks/limit-orders/use-place-limit.ts index 4fdf187eb4..2b1068a93b 100644 --- a/packages/web/hooks/limit-orders/use-place-limit.ts +++ b/packages/web/hooks/limit-orders/use-place-limit.ts @@ -524,7 +524,7 @@ export const usePlaceLimit = ({ error: limitGasError, } = useEstimateTxFees({ chainId: accountStore.osmosisChainId, - messages: encodedMsg && !isMarket ? [encodedMsg] : [], + messages: encodedMsg && !isMarket ? async () => [await encodedMsg] : [], enabled: shouldEstimateLimitGas, }); diff --git a/packages/web/hooks/use-estimate-tx-fees.ts b/packages/web/hooks/use-estimate-tx-fees.ts index 9a4ce3fc57..3a51598106 100644 --- a/packages/web/hooks/use-estimate-tx-fees.ts +++ b/packages/web/hooks/use-estimate-tx-fees.ts @@ -11,7 +11,7 @@ import { SignOptions, } from "@osmosis-labs/stores"; import { QuoteStdFee } from "@osmosis-labs/tx"; -import { isNil } from "@osmosis-labs/utils"; +import { isFunction, isNil } from "@osmosis-labs/utils"; import { useQuery } from "@tanstack/react-query"; import cachified, { CacheEntry } from "cachified"; import { LRUCache } from "lru-cache"; @@ -79,7 +79,7 @@ export function useEstimateTxFees({ signOptions, enabled = true, }: { - messages: EncodeObject[] | undefined; + messages: EncodeObject[] | (() => Promise) | undefined; chainId: string; enabled?: boolean; signOptions?: SignOptions; @@ -91,8 +91,17 @@ export function useEstimateTxFees({ const queryResult = useQuery({ queryKey: ["estimate-tx-fees", superjson.stringify(messages)], - queryFn: () => { + queryFn: async () => { if (!wallet) throw new Error(`No wallet found for chain ID: ${chainId}`); + + if (isFunction(messages)) { + messages = await messages(); + } + + if (messages === undefined || messages.length === 0) { + throw new Error("Messages are undefined"); + } + return estimateTxFeesQueryFn({ wallet, accountStore, @@ -107,8 +116,8 @@ export function useEstimateTxFees({ enabled: enabled && !isNil(messages) && - Array.isArray(messages) && - messages.length > 0 && + ((Array.isArray(messages) && messages.length > 0) || + isFunction(messages)) && wallet?.address !== undefined && typeof wallet?.address === "string", }); diff --git a/packages/web/hooks/use-swap.tsx b/packages/web/hooks/use-swap.tsx index 7d5f564b41..1127f30945 100644 --- a/packages/web/hooks/use-swap.tsx +++ b/packages/web/hooks/use-swap.tsx @@ -210,7 +210,10 @@ export function useSwap( isLoading: isLoadingNetworkFee_, } = useEstimateTxFees({ chainId: chainStore.osmosis.chainId, - messages: quote?.messages, + messages: async () => { + const msgs = await quote?.messages; + return msgs ? Promise.all(msgs) : []; + }, enabled: networkFeeQueryEnabled, signOptions: { useOneClickTrading: isOneClickTradingEnabled, @@ -274,7 +277,7 @@ export function useSwap( const messageCanBeSignedWithOneClickTrading = !isNil(quote?.messages) ? isOneClickTradingEnabled && (await accountStore.shouldBeSignedWithOneClickTrading({ - messages: quote.messages, + messages: await Promise.all(quote.messages), })) : false; @@ -812,7 +815,11 @@ export function useSwapAmountInput({ error: currentBalanceNetworkFeeError, } = useEstimateTxFees({ chainId: chainStore.osmosis.chainId, - messages: quoteForCurrentBalance?.messages, + messages: async () => { + const messages = await quoteForCurrentBalance?.messages; + if (!messages) return []; + return Promise.all(messages); + }, enabled: networkFeeQueryEnabled, signOptions: { useOneClickTrading: isOneClickTradingEnabled,