Skip to content

Commit

Permalink
chore: fix ms signing
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 31, 2025
1 parent 7119015 commit 1fa663b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-needles-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@swapkit/toolbox-cosmos": patch
---

Fixes return type of tx creation if not signable
28 changes: 15 additions & 13 deletions packages/toolboxes/cosmos/src/thorchainUtils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const buildAminoMsg = ({
return msg;
};

// TODO I think the msg typing is wrong it should be not prepared for broadcast
export const convertToSignable = (
msg: MsgDepositForBroadcast | MsgSendForBroadcast,
chain: Chain.THORChain | Chain.Maya,
Expand Down Expand Up @@ -128,16 +129,17 @@ export const buildTransferTx =
asSignable = true,
}: ThorchainTransferTxParams) => {
const account = await getAccount({ rpcUrl, from });
const preparedMessage = prepareMessageForBroadcast(
transferMsgAmino({
from,
recipient,
assetValue,
chain,
}),
);

const msg = asSignable ? convertToSignable(preparedMessage, chain) : preparedMessage;
const transferMsg = transferMsgAmino({
from,
recipient,
assetValue,
chain,
});

const msg = asSignable
? convertToSignable(prepareMessageForBroadcast(transferMsg), chain)
: transferMsg;

const transaction = {
chainId: ChainToChainId[chain],
Expand All @@ -156,11 +158,11 @@ export const buildDepositTx =
async ({ from, assetValue, memo = "", chain, asSignable = true }: ThorcahinDepositTxParams) => {
const account = await getAccount({ rpcUrl, from });

const preparedMessage = prepareMessageForBroadcast<MsgDeposit>(
depositMsgAmino({ from, assetValue, memo, chain }),
);
const depositMsg = depositMsgAmino({ from, assetValue, memo, chain });

const msg = asSignable ? convertToSignable(preparedMessage, chain) : preparedMessage;
const msg = asSignable
? convertToSignable(prepareMessageForBroadcast<MsgDeposit>(depositMsg), chain)
: depositMsg;

const transaction = {
chainId: ChainToChainId[chain],
Expand Down
5 changes: 3 additions & 2 deletions packages/toolboxes/cosmos/src/toolbox/thorchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const signMultisigTx = async (
fee,
memo,
}: {
msgs: ReturnType<typeof prepareMessageForBroadcast>[];
msgs: ReturnType<typeof buildAminoMsg>[];
accountNumber: number;
sequence: number;
chainId: ChainId;
Expand All @@ -92,6 +92,7 @@ const signMultisigTx = async (
const msgForSigning = [];

for (const msg of msgs) {
// @ts-expect-error wrong typing of convertToSignable - investigation needed
const signMsg = await convertToSignable(msg, chain);
msgForSigning.push(signMsg);
}
Expand All @@ -106,7 +107,7 @@ const signMultisigTx = async (

const bodyBytes = await buildEncodedTxBody({
chain,
msgs,
msgs: msgs.map(prepareMessageForBroadcast),
memo,
});

Expand Down

0 comments on commit 1fa663b

Please sign in to comment.