From 0e4b26280d687eea01c6e6c094f0d29ce26e9c5e Mon Sep 17 00:00:00 2001 From: Aaron Choo Date: Wed, 17 Jan 2024 11:58:02 +0800 Subject: [PATCH 1/5] fix: ensure funds is undefined if empty --- package.json | 2 +- src/client/models/MsgExecuteContractInjective.ts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 1b985cae..f516593e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cosmes", - "version": "0.0.50", + "version": "0.0.51-rc.0", "private": false, "packageManager": "pnpm@8.3.0", "sideEffects": false, diff --git a/src/client/models/MsgExecuteContractInjective.ts b/src/client/models/MsgExecuteContractInjective.ts index db72e946..984fac71 100644 --- a/src/client/models/MsgExecuteContractInjective.ts +++ b/src/client/models/MsgExecuteContractInjective.ts @@ -1,4 +1,4 @@ -import { PlainMessage } from "@bufbuild/protobuf"; +import { PartialMessage } from "@bufbuild/protobuf"; import { InjectiveWasmxV1MsgExecuteContractCompat as ProtoMsgExecuteContractCompat } from "cosmes/protobufs"; import { Adapter } from "./Adapter"; @@ -12,16 +12,20 @@ type Data = ConstructorParameters>[0]; * MetaMask or EVM wallets. Otherwise, use `MsgExecuteContract` instead! */ export class MsgExecuteContractInjective implements Adapter { - private readonly data: PlainMessage; + private readonly data: PartialMessage; constructor(data: Data) { this.data = { - ...data, + sender: data.sender, + contract: data.contract, msg: JSON.stringify(data.msg), - funds: data.funds - .map(({ amount, denom }) => `${amount}${denom}`) - .join(","), }; + // Bug in Injective where `funds` MUST be `undefined` if it is an empty array + if (data.funds.length > 0) { + this.data.funds = data.funds + .map(({ amount, denom }) => `${amount}${denom}`) + .join(","); + } } public toProto() { From 3a7ae5930fbd7cd36e4a1b90498ef3f1204b9e64 Mon Sep 17 00:00:00 2001 From: Aaron Choo Date: Wed, 17 Jan 2024 12:14:35 +0800 Subject: [PATCH 2/5] fix: remove funds in metamask msg --- src/client/models/MsgExecuteContractInjective.ts | 2 +- .../metamask-injective/MetamaskInjectiveExtension.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/client/models/MsgExecuteContractInjective.ts b/src/client/models/MsgExecuteContractInjective.ts index 984fac71..2e48d671 100644 --- a/src/client/models/MsgExecuteContractInjective.ts +++ b/src/client/models/MsgExecuteContractInjective.ts @@ -20,7 +20,7 @@ export class MsgExecuteContractInjective implements Adapter { contract: data.contract, msg: JSON.stringify(data.msg), }; - // Bug in Injective where `funds` MUST be `undefined` if it is an empty array + // Bug in Injective where `funds` can only exist if it is present if (data.funds.length > 0) { this.data.funds = data.funds .map(({ amount, denom }) => `${amount}${denom}`) diff --git a/src/wallet/wallets/metamask-injective/MetamaskInjectiveExtension.ts b/src/wallet/wallets/metamask-injective/MetamaskInjectiveExtension.ts index c2790777..28b38852 100644 --- a/src/wallet/wallets/metamask-injective/MetamaskInjectiveExtension.ts +++ b/src/wallet/wallets/metamask-injective/MetamaskInjectiveExtension.ts @@ -151,8 +151,8 @@ export class MetamaskInjectiveExtension extends ConnectedWallet { // Only adding types for the first message likely means txs with different // messages cannot be executed, but this is similar to Injective's behaviour. // See: https://github.com/InjectiveLabs/injective-ts/blob/cd1e67f7fd039c93dd4c5134d2d8dbfe5d009d79/packages/sdk-ts/src/core/modules/tx/eip712/eip712.ts#L27 - const aminoType = stdSignDoc.msgs[0].type; - switch (aminoType) { + const { type, value } = stdSignDoc.msgs[0]; + switch (type) { case "cosmos-sdk/MsgSend": types.MsgValue = [ { name: "from_address", type: "string" }, @@ -169,8 +169,11 @@ export class MetamaskInjectiveExtension extends ConnectedWallet { { name: "sender", type: "string" }, { name: "contract", type: "string" }, { name: "msg", type: "string" }, - { name: "funds", type: "string" }, ]; + // Bug in Injective where `funds` can only exist if it is present + if ("funds" in value) { + types.MsgValue.push({ name: "funds", type: "string" }); + } break; default: // TODO: support other amino types From e105f8257c3f5a40d6a6d3084fcf58c6068ad311 Mon Sep 17 00:00:00 2001 From: Aaron Choo Date: Wed, 17 Jan 2024 12:15:24 +0800 Subject: [PATCH 3/5] chore: bump ver --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f516593e..0335ea10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cosmes", - "version": "0.0.51-rc.0", + "version": "0.0.51-rc.1", "private": false, "packageManager": "pnpm@8.3.0", "sideEffects": false, From 76c54de76035e1d25fa18847558ee69dc9a7161e Mon Sep 17 00:00:00 2001 From: Aaron Choo Date: Wed, 17 Jan 2024 12:19:41 +0800 Subject: [PATCH 4/5] docs: update comments --- src/client/models/MsgExecuteContractInjective.ts | 2 +- .../wallets/metamask-injective/MetamaskInjectiveExtension.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/models/MsgExecuteContractInjective.ts b/src/client/models/MsgExecuteContractInjective.ts index 2e48d671..66710c08 100644 --- a/src/client/models/MsgExecuteContractInjective.ts +++ b/src/client/models/MsgExecuteContractInjective.ts @@ -20,7 +20,7 @@ export class MsgExecuteContractInjective implements Adapter { contract: data.contract, msg: JSON.stringify(data.msg), }; - // Bug in Injective where `funds` can only exist if it is present + // Bug in Injective where `funds` must be removed if it is "empty" if (data.funds.length > 0) { this.data.funds = data.funds .map(({ amount, denom }) => `${amount}${denom}`) diff --git a/src/wallet/wallets/metamask-injective/MetamaskInjectiveExtension.ts b/src/wallet/wallets/metamask-injective/MetamaskInjectiveExtension.ts index 28b38852..71807bd1 100644 --- a/src/wallet/wallets/metamask-injective/MetamaskInjectiveExtension.ts +++ b/src/wallet/wallets/metamask-injective/MetamaskInjectiveExtension.ts @@ -170,7 +170,7 @@ export class MetamaskInjectiveExtension extends ConnectedWallet { { name: "contract", type: "string" }, { name: "msg", type: "string" }, ]; - // Bug in Injective where `funds` can only exist if it is present + // Bug in Injective where `funds` must be removed if it is "empty" if ("funds" in value) { types.MsgValue.push({ name: "funds", type: "string" }); } From 519f3db797d4ce0fa176983545e2835cb39ff92e Mon Sep 17 00:00:00 2001 From: Aaron Choo Date: Wed, 17 Jan 2024 13:43:13 +0800 Subject: [PATCH 5/5] docs: update --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e1b6b93..08a71e73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## `v0.0.51` + +### Fixes + +- Fixed MetaMask on Injective to work correctly with `MsgExecuteContractCompat` when `funds` are empty + ## `v0.0.50` ### Fixes diff --git a/package.json b/package.json index 0335ea10..11888dbe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cosmes", - "version": "0.0.51-rc.1", + "version": "0.0.51", "private": false, "packageManager": "pnpm@8.3.0", "sideEffects": false,