Skip to content

Commit

Permalink
Fix Injective MsgExecuteContractCompat to remove funds when empty (
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronCQL authored Jan 17, 2024
1 parent e4f1e1a commit 6f5e44c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cosmes",
"version": "0.0.50",
"version": "0.0.51",
"private": false,
"packageManager": "pnpm@8.3.0",
"sideEffects": false,
Expand Down
16 changes: 10 additions & 6 deletions src/client/models/MsgExecuteContractInjective.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -12,16 +12,20 @@ type Data<T> = ConstructorParameters<typeof MsgExecuteContract<T>>[0];
* MetaMask or EVM wallets. Otherwise, use `MsgExecuteContract` instead!
*/
export class MsgExecuteContractInjective<T> implements Adapter {
private readonly data: PlainMessage<ProtoMsgExecuteContractCompat>;
private readonly data: PartialMessage<ProtoMsgExecuteContractCompat>;

constructor(data: Data<T>) {
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 removed if it is "empty"
if (data.funds.length > 0) {
this.data.funds = data.funds
.map(({ amount, denom }) => `${amount}${denom}`)
.join(",");
}
}

public toProto() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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` must be removed if it is "empty"
if ("funds" in value) {
types.MsgValue.push({ name: "funds", type: "string" });
}
break;
default:
// TODO: support other amino types
Expand Down

0 comments on commit 6f5e44c

Please sign in to comment.