Skip to content

[FRE-1448] injective bundle size improvements #980

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

Draft
wants to merge 7 commits into
base: staging
Choose a base branch
from
Draft
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/new-humans-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@skip-go/client": patch
---

update injective depdencies to reduce bundle size
3 changes: 1 addition & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"@cosmjs/proto-signing": "0.33.1",
"@cosmjs/stargate": "0.33.1",
"@cosmjs/tendermint-rpc": "0.33.1",
"@injectivelabs/core-proto-ts": "0.0.21",
"@injectivelabs/sdk-ts": "1.14.5",
"@injectivelabs/sdk-ts": "1.14.50",
"@keplr-wallet/unit": "^0.12.143",
"@solana/wallet-adapter-base": "^0.9.23",
"axios": "1.x",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { accountParser } from "./registry";
import {
ChainRestAuthApi,
ChainRestTendermintApi,
} from "@injectivelabs/sdk-ts/dist/cjs/client/chain/rest";
} from "@injectivelabs/sdk-ts";
import {
BigNumberInBase,
DEFAULT_BLOCK_TIMEOUT_HEIGHT,
Expand Down
85 changes: 11 additions & 74 deletions packages/client/src/injective/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
import { StdFee } from "@cosmjs/amino";
import {
CosmosTxSigningV1Beta1Signing,
CosmosTxV1Beta1Tx,
} from "@injectivelabs/core-proto-ts/cjs";
import {
createAuthInfo,
createBody,
createFee,
createSignDoc,
createSigners,
} from "@injectivelabs/sdk-ts/dist/cjs/core/modules/tx/utils/tx";
createTransactionWithSigners,
CreateTransactionArgs as CreateTransactionArgsInjective,
} from "@injectivelabs/sdk-ts";
import { DEFAULT_STD_FEE } from "@injectivelabs/utils";

import createKeccakHash from 'keccak';

export interface CreateTransactionArgs {
fee?: StdFee; // the fee to include in the transaction
memo?: string; // the memo to include in the transaction
chainId: string; // the chain id of the chain that the transaction is going to be broadcasted to
export interface CreateTransactionArgs extends CreateTransactionArgsInjective {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
message: any | any[]; // the message that should be packed into the transaction
pubKey: string; // the pubKey of the signer of the transaction in base64
sequence: number; // the sequence (nonce) of the signer of the transaction
accountNumber: number; // the account number of the signer of the transaction
signMode?: CosmosTxSigningV1Beta1Signing.SignMode;
timeoutHeight?: number; // the height at which the transaction should be considered invalid
}

export function createTransaction({
Expand All @@ -44,58 +26,13 @@ export function createTransaction({
sequence: sequence,
};

const actualSigners = Array.isArray(signers) ? signers : [signers];
const [signer] = actualSigners;

const body = createBody({ message, memo, timeoutHeight });

if (!fee.amount[0]) {
throw new Error("createTransaction error: unable to get fee amount");
}

const feeMessage = createFee({
fee: fee.amount[0],
payer: fee.payer,
granter: fee.granter,
gasLimit: parseInt(fee.gas, 10),
});

const signInfo = createSigners({
chainId,
mode: signMode,
signers: actualSigners,
});

const authInfo = createAuthInfo({
signerInfo: signInfo,
fee: feeMessage,
});

const bodyBytes = CosmosTxV1Beta1Tx.TxBody.encode(body).finish();
const authInfoBytes = CosmosTxV1Beta1Tx.AuthInfo.encode(authInfo).finish();

const signDoc = createSignDoc({
return createTransactionWithSigners({
fee,
memo,
message,
signers,
chainId,
bodyBytes: bodyBytes,
authInfoBytes: authInfoBytes,
accountNumber: signer.accountNumber,
signMode,
timeoutHeight,
});

const signDocBytes = CosmosTxV1Beta1Tx.SignDoc.encode(signDoc).finish();
const toSignBytes = Buffer.from(signDocBytes);
const toSignHash = createKeccakHash('keccak256').update(toSignBytes).digest();
const txRaw = CosmosTxV1Beta1Tx.TxRaw.create();
txRaw.authInfoBytes = authInfoBytes;
txRaw.bodyBytes = bodyBytes;

return {
txRaw,
signDoc,
signers,
signer,
signBytes: toSignBytes,
signHashedBytes: toSignHash,
bodyBytes: bodyBytes,
authInfoBytes: authInfoBytes,
};
}
64 changes: 9 additions & 55 deletions packages/client/src/registry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AccountParser, accountFromAny } from "@cosmjs/stargate";
import { assertDefinedAndNotNull } from "@cosmjs/utils";
import { StridePeriodicVestingAccount } from "./stride";
import { EthAccount } from "@injectivelabs/core-proto-ts/cjs/injective/types/v1beta1/account";
import { decodePubkey } from "@cosmjs/proto-signing";
import { accountEthParser } from "@injectivelabs/sdk-ts";
import { BaseAccount } from "cosmjs-types/cosmos/auth/v1beta1/auth";
import { PubKey } from "cosmjs-types/cosmos/crypto/secp256k1/keys";
import { encodeSecp256k1Pubkey } from "@cosmjs/amino";
Expand All @@ -21,60 +21,14 @@ export const accountParser: AccountParser = (acc) => {
sequence: Number(baseAccount.sequence),
};
}
case "/injective.types.v1beta1.EthAccount": {
const injAccount = EthAccount.decode(acc.value as Uint8Array);
const baseInjAccount = injAccount.baseAccount;
assertDefinedAndNotNull(baseInjAccount);

const pubKey = baseInjAccount.pubKey;

return {
address: baseInjAccount.address,
pubkey: pubKey
? {
type: "/injective.crypto.v1beta1.ethsecp256k1.PubKey",
value: Buffer.from(pubKey.value).toString("base64"),
}
: null,
accountNumber: Number(baseInjAccount.accountNumber),
sequence: Number(baseInjAccount.sequence),
};
}
case "/ethermint.types.v1.EthAccount": {
const account = EthAccount.decode(acc.value as Uint8Array);
const baseEthAccount = account.baseAccount;
assertDefinedAndNotNull(baseEthAccount);

const pubKeyEth = baseEthAccount.pubKey;

return {
address: baseEthAccount.address,
pubkey: pubKeyEth
? {
type: "/ethermint.crypto.v1.ethsecp256k1.PubKey",
value: Buffer.from(pubKeyEth.value).toString("base64"),
}
: null,
accountNumber: Number(baseEthAccount.accountNumber),
sequence: Number(baseEthAccount.sequence),
};
}
default: {
if (acc.typeUrl === "/cosmos.auth.v1beta1.BaseAccount") {
const { address, pubKey, accountNumber, sequence } = BaseAccount.decode(
acc.value,
);
if (pubKey?.typeUrl === "/initia.crypto.v1beta1.ethsecp256k1.PubKey") {
const { key } = PubKey.decode(pubKey.value);
const pk = encodeSecp256k1Pubkey(key);
return {
address,
pubkey: pk,
accountNumber: Number(accountNumber),
sequence: Number(sequence),
};
}
}
case "/injective.types.v1beta1.EthAccount":
return accountEthParser(
acc,
"/injective.crypto.v1beta1.ethsecp256k1.PubKey",
);
case "/ethermint.types.v1.EthAccount":
return accountEthParser(acc, "/ethermint.crypto.v1.ethsecp256k1.PubKey");
default:
return accountFromAny(acc);
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/client/src/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { toUtf8 } from "@cosmjs/encoding";
import { EncodeObject } from "@cosmjs/proto-signing";
import MsgTransferInjective from "@injectivelabs/sdk-ts/dist/cjs/core/modules/ibc/msgs/MsgTransfer";
import { Msgs } from "@injectivelabs/sdk-ts/dist/cjs/core/modules/msgs";
import MsgExecuteContractInjective from "@injectivelabs/sdk-ts/dist/cjs/core/modules/wasm/msgs/MsgExecuteContract";
import {
MsgTransfer as MsgTransferInjective,
MsgExecuteContractCompat as MsgExecuteContractInjective,
Msgs,
} from "@injectivelabs/sdk-ts";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
Expand Down
Loading
Loading