Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multisig signing #1174

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading