Skip to content

Commit

Permalink
Merge pull request #36 from etherspot/polygon-gas-fees
Browse files Browse the repository at this point in the history
use-oracle-for-matic
  • Loading branch information
0xSulpiride authored Jun 6, 2023
2 parents 8128da2 + 48345f5 commit 4ce94fd
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.0.5",
"version": "0.0.6",
"stream": "true",
"command": {
"version": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "root",
"private": true,
"version": "0.0.5",
"version": "0.0.6",
"engines": {
"node": ">=12.9.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "0.0.5",
"version": "0.0.6",
"description": "The API module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -35,12 +35,12 @@
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"ethers": "5.7.2",
"executor": "^0.0.5",
"executor": "^0.0.6",
"fastify": "4.14.1",
"pino": "8.11.0",
"pino-pretty": "10.0.0",
"reflect-metadata": "0.1.13",
"types": "^0.0.5"
"types": "^0.0.6"
},
"devDependencies": {
"@types/connect": "3.4.35"
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cli",
"version": "0.0.5",
"version": "0.0.6",
"description": "> TODO: description",
"author": "zincoshine <[email protected]>",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -31,13 +31,13 @@
"url": "https://https://github.com/etherspot/skandha/issues"
},
"dependencies": {
"api": "^0.0.5",
"db": "^0.0.5",
"executor": "^0.0.5",
"api": "^0.0.6",
"db": "^0.0.6",
"executor": "^0.0.6",
"find-up": "5.0.0",
"got": "12.5.3",
"js-yaml": "4.1.0",
"types": "^0.0.5",
"types": "^0.0.6",
"yargs": "17.6.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/db/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "db",
"version": "0.0.5",
"version": "0.0.6",
"description": "The DB module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/etherspot-bundler#readme",
Expand Down Expand Up @@ -37,6 +37,6 @@
"devDependencies": {
"@types/rocksdb": "3.0.1",
"prettier": "^2.8.4",
"types": "^0.0.5"
"types": "^0.0.6"
}
}
6 changes: 3 additions & 3 deletions packages/executor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "executor",
"version": "0.0.5",
"version": "0.0.6",
"description": "The Relayer module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"async-mutex": "0.4.0",
"ethers": "5.7.2",
"params": "^0.0.5",
"types": "^0.0.5"
"params": "^0.0.6",
"types": "^0.0.6"
}
}
7 changes: 4 additions & 3 deletions packages/executor/src/services/BundlingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { MempoolEntry } from "../entities/MempoolEntry";
import { ReputationStatus } from "../entities/interfaces";
import { Config } from "../config";
import { BundlingMode, Logger } from "../interfaces";
import { getGasFee } from "../utils/getGasFee";
import { ReputationService } from "./ReputationService";
import {
UserOpValidationResult,
Expand Down Expand Up @@ -65,7 +66,7 @@ export class BundlingService {
const wallet = this.config.getRelayer(this.network)!;
const beneficiary = await this.selectBeneficiary();
try {
const feeData = await this.provider.getFeeData();
const gasFee = await getGasFee(this.network, this.provider);
const txRequest = entryPointContract.interface.encodeFunctionData(
"handleOps",
[bundle.map((entry) => entry.userOp), beneficiary]
Expand All @@ -74,8 +75,8 @@ export class BundlingService {
to: entryPoint,
data: txRequest,
type: 2,
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? 0,
maxFeePerGas: feeData.maxFeePerGas ?? 0,
maxPriorityFeePerGas: gasFee.maxPriorityFeePerGas ?? 0,
maxFeePerGas: gasFee.maxFeePerGas ?? 0,
});

this.logger.debug(`Sent new bundle ${tx.hash}`);
Expand Down
48 changes: 48 additions & 0 deletions packages/executor/src/utils/getGasFee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { BigNumber, BigNumberish, ethers, providers } from "ethers";
import { NetworkName } from "types/lib";

export type IGetGasFeeResult = {
maxPriorityFeePerGas: BigNumberish | undefined;
maxFeePerGas: BigNumberish | undefined;
};

export const getGasFee = async (
network: NetworkName,
provider: providers.JsonRpcProvider
): Promise<IGetGasFeeResult> => {
if (network === "matic") {
try {
return getMaticGasFee();
} catch (err) {
// eslint-disable-next-line no-console
console.error(`Couldn't fetch fee data for matic: ${err}`);
}
}
try {
const feeData = await provider.getFeeData();
return {
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? 0,
maxFeePerGas: feeData.maxFeePerGas ?? 0,
};
} catch (err) {
// eslint-disable-next-line no-console
console.error(`Couldn't fetch fee data: ${err}`);
}
return {
maxPriorityFeePerGas: undefined,
maxFeePerGas: undefined,
};
};

function parseGwei(num: number): BigNumber {
return ethers.utils.parseUnits(num.toFixed(9), "gwei");
}

export const getMaticGasFee = async (): Promise<IGetGasFeeResult> => {
const oracle = "https://gasstation-mainnet.matic.network/v2";
const data = await (await fetch(oracle)).json();
return {
maxPriorityFeePerGas: parseGwei(data.fast.maxPriorityFee),
maxFeePerGas: parseGwei(data.fast.maxFee),
};
};
4 changes: 2 additions & 2 deletions packages/params/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "params",
"version": "0.0.5",
"version": "0.0.6",
"description": "Various bundler parameters",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/skandha#readme",
Expand All @@ -21,7 +21,7 @@
"url": "https://github.com/etherspot/skandha/issues"
},
"dependencies": {
"types": "^0.0.5"
"types": "^0.0.6"
},
"scripts": {
"clean": "rm -rf lib && rm -f *.tsbuildinfo",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "types",
"version": "0.0.5",
"version": "0.0.6",
"description": "The types of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down

0 comments on commit 4ce94fd

Please sign in to comment.