Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 157b92b

Browse files
authored
fix: updated fetchEvmGasPrice fn (#69)
* fix: updated fetchEvmGasPrice fn * fix: renamed to fetchTipPrice * fix: lint
1 parent 5cf0ec0 commit 157b92b

File tree

10 files changed

+18
-57
lines changed

10 files changed

+18
-57
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ Here is the list of functions and their brief explanations:
239239
39. `getEvmGas`: Retrieves the gas price for Ethereum Virtual Machine (EVM) transactions.
240240
40. `getEvmGasCost`: Calculates the cost of gas for a transaction.
241241
41. `formatTip`: Converts the provided fee into ether format.
242-
42. `fetchEvmGasPrice`: Fetches gas price from an API and formats it accordingly.
242+
42. `fetchTipPrice`: Fetches tip price from an API and formats it accordingly.
243243
43. `getUsdBySymbol`: Fetches the price of a token in USD.
244244
44. `calUsdAmount`: Fetches the USD price for a given token symbol and multiplies it by an amount.
245245
45. `mergeTvlArray`: Merges the TVL (Total Value Locked) array based on the base type.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"url": "https://github.com/AstarNetwork/astar.js.git"
1313
},
1414
"sideEffects": false,
15-
"version": "0.2.7",
15+
"version": "0.2.8",
1616
"workspaces": [
1717
"packages/*",
1818
"examples/*"

packages/api-derive/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@astar-network/astar-api-derive",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"description": "Astar JS API",
55
"main": "index.js",
66
"author": "Astar Network <[email protected]>",

packages/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@astar-network/astar-api",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"description": "Astar JS API",
55
"main": "index.js",
66
"author": "Astar Network <[email protected]>",

packages/sdk-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@astar-network/astar-sdk-core",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"description": "the core for astar SDK",
55
"main": "index.js",
66
"author": "Astar Network <[email protected]>",

packages/sdk-core/src/modules/common/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export const objToArray = (obj: any): any[] => {
77
return array;
88
};
99

10+
export const hasProperty = (obj: object, key: string): boolean => {
11+
return !!obj && Object.prototype.hasOwnProperty.call(obj, key);
12+
};
13+
1014
export const checkIsNullOrUndefined = (value: any): boolean => {
1115
return value === null || value === undefined;
1216
};

packages/sdk-core/src/modules/dapp-staking/pending-rewards/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Perbill } from '@polkadot/types/interfaces';
33
import { ApiPromise } from '@polkadot/api';
44
import { ethers } from 'ethers';
55
import { Codec } from '@polkadot/types/types';
6-
import { truncate } from '@astar-network/astar-sdk-core';
6+
import { hasProperty, truncate } from '@astar-network/astar-sdk-core';
77

88
export interface RewardDistributionConfig extends Struct {
99
readonly baseTreasuryPercent: Perbill;
@@ -210,7 +210,7 @@ export const estimatePendingRewards = async ({ api,
210210
api.query.system.number(),
211211
Number(api.consts.dappsStaking.blockPerEra),
212212
String(
213-
Object.prototype.hasOwnProperty.call(api.consts.blockReward, 'maxBlockRewardAmount')
213+
hasProperty(api.consts.blockReward, 'maxBlockRewardAmount')
214214
? api.consts.blockReward.maxBlockRewardAmount
215215
: api.consts.blockReward.rewardAmount
216216
),

packages/sdk-core/src/modules/gas-api/utils/index.ts

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -62,76 +62,33 @@ export const formatTip = (fee: string): string => {
6262
return price;
6363
};
6464

65-
export const fetchEvmGasPrice = async ({ network,
66-
isEip1559,
67-
web3 }: {
68-
network: string;
69-
isEip1559: boolean;
70-
web3: Web3;
71-
}): Promise<{ evmGasPrice: GasPrice; nativeTipPrice: GasPrice }> => {
65+
export const fetchTipPrice = async ({ network }: { network: string }): Promise<{ nativeTipPrice: GasPrice }> => {
7266
try {
7367
const url = `${GAS_API_URL}/gasnow?network=${network}`;
7468
const { data } = await axios.get<ApiGasNow>(url);
7569
if (!data || data.code !== 200) {
7670
throw Error('something went wrong');
7771
}
7872
const { tip } = data.data;
79-
const { priorityFeePerGas } = data.data.eip1559;
8073
const nativeTipPrice = {
8174
slow: formatTip(tip.slow),
8275
average: formatTip(tip.average),
8376
fast: formatTip(tip.fast)
8477
};
8578

86-
if (isEip1559) {
87-
const evmGasPrice = {
88-
slow: priorityFeePerGas.slow,
89-
average: priorityFeePerGas.average,
90-
fast: priorityFeePerGas.fast,
91-
baseFeePerGas: data.data.eip1559.baseFeePerGas
92-
};
93-
return {
94-
evmGasPrice,
95-
nativeTipPrice
96-
};
97-
} else {
98-
const { slow, average, fast } = data.data;
99-
const evmGasPrice = {
100-
slow,
101-
average,
102-
fast,
103-
baseFeePerGas: '0'
104-
};
105-
return {
106-
evmGasPrice,
107-
nativeTipPrice
108-
};
109-
}
79+
return {
80+
nativeTipPrice
81+
};
11082
} catch (error) {
11183
if (network.toLowerCase() !== astarChain.DEVELOPMENT.toLowerCase()) {
11284
console.error(error);
11385
}
114-
const fallbackGasPrice = Number(
115-
await web3.eth.getGasPrice().catch(() => {
116-
const oneGwei = '1000000000';
117-
return oneGwei;
118-
})
119-
);
12086

121-
const slow = fallbackGasPrice;
122-
const average = Math.floor(fallbackGasPrice * 9);
123-
const fast = Math.floor(fallbackGasPrice * 56);
124-
const evmGasPrice = {
125-
slow: String(slow),
126-
average: String(average),
127-
fast: String(fast),
128-
baseFeePerGas: '0'
129-
};
13087
const nativeTipPrice = {
13188
slow: formatTip('10000000000000'),
13289
average: formatTip('50000000000000'),
13390
fast: formatTip('5000000000000000')
13491
};
135-
return { evmGasPrice, nativeTipPrice };
92+
return { nativeTipPrice };
13693
}
13794
};

packages/type-definitions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@astar-network/astar-type-definitions",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"description": "Polkadot.js type definitions for astar Network",
55
"main": "index.js",
66
"author": "Astar Network <[email protected]>",

packages/types/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@astar-network/astar-types",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"description": "Polkadot.js type definitions for Astar Network",
55
"main": "index.js",
66
"author": "Astar Network <[email protected]>",

0 commit comments

Comments
 (0)