Skip to content

Commit

Permalink
fix: multisig signing (#1174)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
towanTG and github-actions[bot] authored Jan 29, 2025
1 parent c2841b9 commit 0cc3d4a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-ways-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@swapkit/toolbox-cosmos": patch
---

Fixes multisig signing and improves typing
16 changes: 8 additions & 8 deletions packages/toolboxes/cosmos/src/thorchainUtils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type { ThorcahinDepositTxParams, ThorchainTransferTxParams } from "./type

type MsgSend = ReturnType<typeof transferMsgAmino>;
type MsgDeposit = ReturnType<typeof depositMsgAmino>;
type MsgSendForBroadcast = ReturnType<typeof prepareMessageForBroadcast>;
type MsgDepositForBroadcast = ReturnType<typeof prepareMessageForBroadcast>;
type MsgSendForBroadcast = ReturnType<typeof prepareMessageForBroadcast<MsgSend>>;
type MsgDepositForBroadcast = ReturnType<typeof prepareMessageForBroadcast<MsgDeposit>>;

export const THORCHAIN_GAS_VALUE = getDefaultChainFee(Chain.THORChain).gas;
export const MAYA_GAS_VALUE = getDefaultChainFee(Chain.Maya).gas;
Expand All @@ -30,7 +30,7 @@ export const transferMsgAmino = ({
assetValue: AssetValue;
chain: Chain.THORChain | Chain.Maya;
}) => ({
type: `${chain === Chain.Maya ? "mayachain" : "thorchain"}/MsgSend`,
type: `${chain === Chain.Maya ? "mayachain" : "thorchain"}/MsgSend` as const,
value: {
from_address: from,
to_address: recipient,
Expand All @@ -55,7 +55,7 @@ export const depositMsgAmino = ({
chain: Chain.THORChain | Chain.Maya;
}) => {
return {
type: `${chain === Chain.Maya ? "mayachain" : "thorchain"}/MsgDeposit`,
type: `${chain === Chain.Maya ? "mayachain" : "thorchain"}/MsgDeposit` as const,
value: {
coins: [
{
Expand Down Expand Up @@ -156,7 +156,7 @@ export const buildDepositTx =
async ({ from, assetValue, memo = "", chain, asSignable = true }: ThorcahinDepositTxParams) => {
const account = await getAccount({ rpcUrl, from });

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

Expand All @@ -174,8 +174,8 @@ export const buildDepositTx =
return transaction;
};

export const prepareMessageForBroadcast = (msg: MsgDeposit | MsgSend) => {
if (msg.type === "thorchain/MsgSend" || msg.type === "mayachain/MsgSend") return msg;
export function prepareMessageForBroadcast<T extends MsgDeposit | MsgSend>(msg: T) {
if (msg.type === "thorchain/MsgSend" || msg.type === "mayachain/MsgSend") return msg as MsgSend;

return {
...msg,
Expand Down Expand Up @@ -203,7 +203,7 @@ export const prepareMessageForBroadcast = (msg: MsgDeposit | MsgSend) => {
}),
},
};
};
}

export const buildEncodedTxBody = ({
chain,
Expand Down
18 changes: 16 additions & 2 deletions packages/toolboxes/cosmos/src/toolbox/thorchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,21 @@ const signMultisigTx = async (
tx: string,
chain: Chain.THORChain | Chain.Maya,
) => {
const { msgs, accountNumber, sequence, chainId, fee, memo } = JSON.parse(tx);
const {
msgs,
accountNumber,
sequence,
chainId,
fee,
memo,
}: {
msgs: ReturnType<typeof prepareMessageForBroadcast>[];
accountNumber: number;
sequence: number;
chainId: ChainId;
fee: ReturnType<typeof getDefaultChainFee>;
memo: string;
} = JSON.parse(tx);

const address = (await wallet.getAccounts())?.[0]?.address || "";
const aminoTypes = await createDefaultAminoTypes(chain);
Expand All @@ -92,7 +106,7 @@ const signMultisigTx = async (

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

Expand Down

0 comments on commit 0cc3d4a

Please sign in to comment.