@injectivelabs/utils 1.16.13-alpha.2 → 1.16.13-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,23 +37,23 @@ export declare const getStdFeeFromObject: (args?: {
37
37
  feePayer?: string;
38
38
  }) => {
39
39
  amount: {
40
- amount: string;
41
40
  denom: string;
41
+ amount: string;
42
42
  }[];
43
43
  gas: string;
44
- payer: string;
45
- granter: string;
46
- feePayer: string;
44
+ payer: string | undefined; /** for Web3Gateway fee delegation */
45
+ granter: string | undefined;
46
+ feePayer: string | undefined;
47
47
  };
48
48
  export declare const getStdFeeFromString: (gasPrice: string) => {
49
49
  amount: {
50
- amount: string;
51
50
  denom: string;
51
+ amount: string;
52
52
  }[];
53
53
  gas: string;
54
- payer: string;
55
- granter: string;
56
- feePayer: string;
54
+ payer: string | undefined; /** for Web3Gateway fee delegation */
55
+ granter: string | undefined;
56
+ feePayer: string | undefined;
57
57
  };
58
58
  export declare const getStdFee: (args?: string | {
59
59
  payer?: string;
@@ -63,11 +63,11 @@ export declare const getStdFee: (args?: string | {
63
63
  gasPrice?: string | number;
64
64
  }) => {
65
65
  amount: {
66
- amount: string;
67
66
  denom: string;
67
+ amount: string;
68
68
  }[];
69
69
  gas: string;
70
- payer: string;
71
- granter: string;
72
- feePayer: string;
70
+ payer: string | undefined; /** for Web3Gateway fee delegation */
71
+ granter: string | undefined;
72
+ feePayer: string | undefined;
73
73
  };
@@ -106,21 +106,20 @@ const getStdFeeFromObject = (args) => {
106
106
  if (!args) {
107
107
  return (0, constants_js_1.getDefaultStdFee)();
108
108
  }
109
- const gasPriceInBase = args.gasPrice || (0, BigNumber_js_1.toHumanReadable)(constants_js_1.DEFAULT_GAS_PRICE, 18);
110
- const gasPriceScaled = (0, BigNumber_js_1.toChainFormat)(gasPriceInBase, 18).toFixed(0);
109
+ const { payer, granter, feePayer, gasPrice = constants_js_1.DEFAULT_GAS_PRICE, gas = constants_js_1.DEFAULT_GAS_LIMIT.toString(), } = args;
110
+ const gasNormalized = (0, BigNumber_js_1.toBigNumber)(gas).toFixed(0);
111
+ const gasPriceNormalized = (0, BigNumber_js_1.toBigNumber)(gasPrice).toFixed(0);
111
112
  return {
112
113
  amount: [
113
114
  {
114
115
  denom: 'inj',
115
- amount: new BigNumber_js_1.default(args.gas || constants_js_1.DEFAULT_GAS_LIMIT)
116
- .times(gasPriceScaled)
117
- .toFixed(0),
116
+ amount: (0, BigNumber_js_1.toBigNumber)(gasNormalized).times(gasPriceNormalized).toFixed(),
118
117
  },
119
118
  ],
120
- gas: new BigNumber_js_1.default(args.gas || constants_js_1.DEFAULT_GAS_LIMIT).toFixed(),
121
- payer: args.payer || '',
122
- granter: args.granter || '',
123
- feePayer: args.feePayer || '',
119
+ gas: (0, BigNumber_js_1.toBigNumber)(gasNormalized).toFixed(),
120
+ payer /** for Web3Gateway fee delegation */,
121
+ granter,
122
+ feePayer,
124
123
  };
125
124
  };
126
125
  exports.getStdFeeFromObject = getStdFeeFromObject;
@@ -130,7 +129,7 @@ const getStdFeeFromString = (gasPrice) => {
130
129
  throw new Error('Invalid gas price string');
131
130
  }
132
131
  const [_, amount] = matchResult;
133
- const gas = (0, BigNumber_js_1.toChainFormat)(amount).dividedBy(constants_js_1.DEFAULT_GAS_PRICE).toFixed(0);
132
+ const gas = (0, BigNumber_js_1.toChainFormat)(amount, 18).dividedBy(constants_js_1.DEFAULT_GAS_PRICE).toFixed(0);
134
133
  return (0, exports.getStdFeeFromObject)({ gas, gasPrice: constants_js_1.DEFAULT_GAS_PRICE });
135
134
  };
136
135
  exports.getStdFeeFromString = getStdFeeFromString;
@@ -37,23 +37,23 @@ export declare const getStdFeeFromObject: (args?: {
37
37
  feePayer?: string;
38
38
  }) => {
39
39
  amount: {
40
- amount: string;
41
40
  denom: string;
41
+ amount: string;
42
42
  }[];
43
43
  gas: string;
44
- payer: string;
45
- granter: string;
46
- feePayer: string;
44
+ payer: string | undefined; /** for Web3Gateway fee delegation */
45
+ granter: string | undefined;
46
+ feePayer: string | undefined;
47
47
  };
48
48
  export declare const getStdFeeFromString: (gasPrice: string) => {
49
49
  amount: {
50
- amount: string;
51
50
  denom: string;
51
+ amount: string;
52
52
  }[];
53
53
  gas: string;
54
- payer: string;
55
- granter: string;
56
- feePayer: string;
54
+ payer: string | undefined; /** for Web3Gateway fee delegation */
55
+ granter: string | undefined;
56
+ feePayer: string | undefined;
57
57
  };
58
58
  export declare const getStdFee: (args?: string | {
59
59
  payer?: string;
@@ -63,11 +63,11 @@ export declare const getStdFee: (args?: string | {
63
63
  gasPrice?: string | number;
64
64
  }) => {
65
65
  amount: {
66
- amount: string;
67
66
  denom: string;
67
+ amount: string;
68
68
  }[];
69
69
  gas: string;
70
- payer: string;
71
- granter: string;
72
- feePayer: string;
70
+ payer: string | undefined; /** for Web3Gateway fee delegation */
71
+ granter: string | undefined;
72
+ feePayer: string | undefined;
73
73
  };
@@ -1,5 +1,5 @@
1
1
  import { getDefaultStdFee, DEFAULT_GAS_LIMIT, DEFAULT_GAS_PRICE, } from './constants.js';
2
- import { toChainFormat, toHumanReadable, default as BigNumber, } from './classes/BigNumber.js';
2
+ import { toBigNumber, toChainFormat, toHumanReadable, default as BigNumber, } from './classes/BigNumber.js';
3
3
  export const sleep = (timeout) => new Promise((resolve) => setTimeout(resolve, timeout));
4
4
  /**
5
5
  * When we want to execute the promises in batch
@@ -64,21 +64,20 @@ export const getStdFeeFromObject = (args) => {
64
64
  if (!args) {
65
65
  return getDefaultStdFee();
66
66
  }
67
- const gasPriceInBase = args.gasPrice || toHumanReadable(DEFAULT_GAS_PRICE, 18);
68
- const gasPriceScaled = toChainFormat(gasPriceInBase, 18).toFixed(0);
67
+ const { payer, granter, feePayer, gasPrice = DEFAULT_GAS_PRICE, gas = DEFAULT_GAS_LIMIT.toString(), } = args;
68
+ const gasNormalized = toBigNumber(gas).toFixed(0);
69
+ const gasPriceNormalized = toBigNumber(gasPrice).toFixed(0);
69
70
  return {
70
71
  amount: [
71
72
  {
72
73
  denom: 'inj',
73
- amount: new BigNumber(args.gas || DEFAULT_GAS_LIMIT)
74
- .times(gasPriceScaled)
75
- .toFixed(0),
74
+ amount: toBigNumber(gasNormalized).times(gasPriceNormalized).toFixed(),
76
75
  },
77
76
  ],
78
- gas: new BigNumber(args.gas || DEFAULT_GAS_LIMIT).toFixed(),
79
- payer: args.payer || '',
80
- granter: args.granter || '',
81
- feePayer: args.feePayer || '',
77
+ gas: toBigNumber(gasNormalized).toFixed(),
78
+ payer /** for Web3Gateway fee delegation */,
79
+ granter,
80
+ feePayer,
82
81
  };
83
82
  };
84
83
  export const getStdFeeFromString = (gasPrice) => {
@@ -87,7 +86,7 @@ export const getStdFeeFromString = (gasPrice) => {
87
86
  throw new Error('Invalid gas price string');
88
87
  }
89
88
  const [_, amount] = matchResult;
90
- const gas = toChainFormat(amount).dividedBy(DEFAULT_GAS_PRICE).toFixed(0);
89
+ const gas = toChainFormat(amount, 18).dividedBy(DEFAULT_GAS_PRICE).toFixed(0);
91
90
  return getStdFeeFromObject({ gas, gasPrice: DEFAULT_GAS_PRICE });
92
91
  };
93
92
  export const getStdFee = (args) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/utils",
3
3
  "description": "List of utils and helper functions that can be reused throughout Injective's projects.",
4
- "version": "1.16.13-alpha.2",
4
+ "version": "1.16.13-alpha.4",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -79,9 +79,9 @@
79
79
  },
80
80
  "dependencies": {
81
81
  "@bangjelkoski/store2": "^2.14.3",
82
- "@injectivelabs/exceptions": "1.16.13-alpha.2",
83
- "@injectivelabs/networks": "1.16.13-alpha.2",
84
- "@injectivelabs/ts-types": "1.16.13-alpha.2",
82
+ "@injectivelabs/exceptions": "1.16.13-alpha.4",
83
+ "@injectivelabs/networks": "1.16.13-alpha.4",
84
+ "@injectivelabs/ts-types": "1.16.13-alpha.4",
85
85
  "axios": "^1.8.1",
86
86
  "bignumber.js": "^9.1.2",
87
87
  "http-status-codes": "^2.3.0"
@@ -89,5 +89,5 @@
89
89
  "devDependencies": {
90
90
  "shx": "^0.3.4"
91
91
  },
92
- "gitHead": "c60f210698d2ee266855a6bb7342d0147964bad4"
92
+ "gitHead": "38872f985bdce134a3e6f9f7b7e0e3e5c5cd36b1"
93
93
  }