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 Injective MsgExecuteContractCompat to remove funds when empty #38

Merged
merged 5 commits into from
Jan 17, 2024
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
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
Loading