Skip to content

Commit

Permalink
Fixed multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
SamvelRaja Sakthivel authored and SamvelRaja Sakthivel committed Sep 2, 2023
1 parent a815bdb commit 5bb5404
Show file tree
Hide file tree
Showing 4 changed files with 971 additions and 895 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
"start:snap": "yarn workspace snap start",
"test": "yarn workspace @leapwallet/metamask-cosmos-snap test"
},
"dependencies": {
"long": "^5.2.3"
},
"devDependencies": {
"@metamask/eslint-config": "^10.0.0",
"@metamask/eslint-config-jest": "^10.0.0",
Expand Down
14 changes: 10 additions & 4 deletions packages/cosmos-snap-provider/src/cosmjs-offline-signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
/* eslint require-atomic-updates: 0 */ // --> OFF

import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
import { AccountData, AminoSignResponse, StdSignDoc } from '@cosmjs/amino';
import { AccountData, AminoSignResponse } from '@cosmjs/amino';
import { DirectSignResponse, OfflineDirectSigner } from '@cosmjs/proto-signing';
import BigNumber from 'bignumber.js';
import { getKey, requestSignAmino, requestSignature } from './snap';
import { getGasPriceForChainName, toSmall } from './helper/gas';
import { SignAminoOptions } from './types';
import { getGasPriceForChainName } from './helper/gas';
import { SignAminoOptions, StdSignDoc } from './types';
import Chains from './constants/chainInfo';

export class CosmjsOfflineSigner implements OfflineDirectSigner {
Expand Down Expand Up @@ -68,10 +69,15 @@ export class CosmjsOfflineSigner implements OfflineDirectSigner {
const gasPriceFromRegistry = await getGasPriceForChainName(
chain.chainName,
);
const gas: any =
'gasLimit' in signDoc.fee ? signDoc.fee.gasLimit : signDoc.fee.gas;
if (gasPriceFromRegistry) {
const amount = [
{
amount: toSmall(gasPriceFromRegistry, chain?.decimals),
amount: new BigNumber(gasPriceFromRegistry)
.multipliedBy(new BigNumber(gas))
.decimalPlaces(0, 1)
.toString(),
denom: chain.denom,
},
];
Expand Down
19 changes: 19 additions & 0 deletions packages/cosmos-snap-provider/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AminoMsg, Coin } from '@cosmjs/amino';

export type GetSnapsResponse = Record<string, Snap>;

export type Snap = {
Expand Down Expand Up @@ -75,3 +77,20 @@ export type ChainInfo = {
export type SignAminoOptions = {
preferNoSetFee?: boolean;
};

export type StdFee = {
amount: readonly Coin[];
readonly gas: string;
/** The granter address that is used for paying with feegrants */
readonly granter?: string;
/** The fee payer address. The payer must have signed the transaction. */
readonly payer?: string;
};
export type StdSignDoc = {
readonly chain_id: string;
readonly account_number: string;
readonly sequence: string;
fee: StdFee;
readonly msgs: readonly AminoMsg[];
readonly memo: string;
};
Loading

0 comments on commit 5bb5404

Please sign in to comment.