Skip to content
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

feat: config rpc #88

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
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.43",
"version": "0.0.44",
"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.43",
"version": "0.0.44",
"engines": {
"node": ">=18.0.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.43",
"version": "0.0.44",
"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.43",
"executor": "^0.0.44",
"fastify": "4.14.1",
"pino": "8.11.0",
"pino-pretty": "10.0.0",
"reflect-metadata": "0.1.13",
"types": "^0.0.43"
"types": "^0.0.44"
},
"devDependencies": {
"@types/connect": "3.4.35"
Expand Down
8 changes: 8 additions & 0 deletions packages/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ export class ApiApp {
newestBlock: params[2],
});
break;
case CustomRPCMethods.skandha_config:
result = await skandhaApi.getConfig();
// skip hexlify for this particular rpc
return res.status(200).send({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pls avoid hardcoding and move the http status codes and messages to a common constants file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

jsonrpc,
id,
result,
});
default:
throw new RpcError(
`Method ${method} is not supported`,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const CustomRPCMethods = {
skandha_validateUserOperation: "skandha_validateUserOperation",
skandha_getGasPrice: "skandha_getGasPrice",
skandha_config: "skandha_config",
skandha_feeHistory: "skandha_feeHistory",
};

Expand Down
5 changes: 5 additions & 0 deletions packages/api/src/modules/skandha.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Eth } from "executor/lib/modules/eth";
import {
GetConfigResponse,
GetFeeHistoryResponse,
GetGasPriceResponse,
} from "types/lib/api/interfaces";
Expand Down Expand Up @@ -46,4 +47,8 @@ export class SkandhaAPI {
async getGasPrice(): Promise<GetGasPriceResponse> {
return await this.skandhaModule.getGasPrice();
}

async getConfig(): Promise<GetConfigResponse> {
return await this.skandhaModule.getConfig();
}
}
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.43",
"version": "0.0.44",
"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.43",
"db": "^0.0.43",
"executor": "^0.0.43",
"api": "^0.0.44",
"db": "^0.0.44",
"executor": "^0.0.44",
"find-up": "5.0.0",
"got": "12.5.3",
"js-yaml": "4.1.0",
"types": "^0.0.43",
"types": "^0.0.44",
"yargs": "17.6.2"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/cmds/start/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ export async function bundlerHandler(
networks: configOptions.networks,
testingMode,
unsafeMode,
redirectRpc,
});
} catch (err) {
logger.debug("Config file not found. Proceeding with env vars...");
config = new Config({
networks: {},
testingMode,
unsafeMode,
redirectRpc,
});
}

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.43",
"version": "0.0.44",
"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.43"
"types": "^0.0.44"
}
}
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.43",
"version": "0.0.44",
"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.43",
"types": "^0.0.43"
"params": "^0.0.44",
"types": "^0.0.44"
}
}
2 changes: 2 additions & 0 deletions packages/executor/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export class Config {
networks: Networks;
testingMode: boolean;
unsafeMode: boolean;
redirectRpc: boolean;

constructor(private config: ConfigOptions) {
this.supportedNetworks = this.parseSupportedNetworks();
this.networks = this.parseNetworkConfigs();
this.testingMode = config.testingMode ?? false;
this.unsafeMode = config.unsafeMode ?? false;
this.redirectRpc = config.redirectRpc ?? false;
}

getNetworkProvider(network: NetworkName): providers.JsonRpcProvider | null {
Expand Down
2 changes: 1 addition & 1 deletion packages/executor/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Executor {
this.skandha = new Skandha(
this.network,
this.provider,
this.networkConfig,
this.config,
this.logger
);

Expand Down
1 change: 1 addition & 0 deletions packages/executor/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export interface ConfigOptions {
networks: Networks;
testingMode?: boolean;
unsafeMode: boolean;
redirectRpc: boolean;
}

export interface SlotMap {
Expand Down
64 changes: 60 additions & 4 deletions packages/executor/src/modules/skandha.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BigNumber, BigNumberish, ethers } from "ethers";
import { NetworkName } from "types/lib";
import {
GetConfigResponse,
GetFeeHistoryResponse,
GetGasPriceResponse,
} from "types/lib/api/interfaces";
Expand All @@ -11,22 +12,31 @@ import { getGasFee } from "params/lib";
import { IEntryPoint__factory } from "types/lib/executor/contracts";
import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint";
import { Logger, NetworkConfig } from "../interfaces";
import { Config } from "../config";

// custom features of Skandha
export class Skandha {
networkConfig: NetworkConfig;

constructor(
private networkName: NetworkName,
private provider: ethers.providers.JsonRpcProvider,
private config: NetworkConfig,
private config: Config,
private logger: Logger
) {}
) {
const networkConfig = this.config.getNetworkConfig(this.networkName);
if (!networkConfig) {
throw new Error("No network config");
}
this.networkConfig = networkConfig;
}

async getGasPrice(): Promise<GetGasPriceResponse> {
const multiplier = this.config.gasPriceMarkup;
const multiplier = this.networkConfig.gasPriceMarkup;
const gasFee = await getGasFee(
this.networkName,
this.provider,
this.config.etherscanApiKey
this.networkConfig.etherscanApiKey
);
let { maxPriorityFeePerGas, maxFeePerGas } = gasFee;

Expand Down Expand Up @@ -57,6 +67,52 @@ export class Skandha {
};
}

async getConfig(): Promise<GetConfigResponse> {
const wallet = this.config.getRelayer(this.networkName);
const hasEtherscanApiKey = Boolean(this.networkConfig.etherscanApiKey);
const hasExecutionRpc = Boolean(this.networkConfig.rpcEndpointSubmit);
return {
flags: {
unsafeMode: this.config.unsafeMode,
testingMode: this.config.testingMode,
redirectRpc: this.config.redirectRpc,
},
entryPoints: this.networkConfig.entryPoints,
beneficiary: this.networkConfig.beneficiary,
relayer: wallet ? await wallet.getAddress() : "",
minInclusionDenominator: BigNumber.from(
this.networkConfig.minInclusionDenominator
).toNumber(),
throttlingSlack: BigNumber.from(
this.networkConfig.throttlingSlack
).toNumber(),
banSlack: BigNumber.from(this.networkConfig.banSlack).toNumber(),
minSignerBalance: `${ethers.utils.formatEther(
this.networkConfig.minSignerBalance
)} eth`,
multicall: this.networkConfig.multicall,
estimationStaticBuffer: BigNumber.from(
this.networkConfig.estimationStaticBuffer
).toNumber(),
validationGasLimit: BigNumber.from(
this.networkConfig.validationGasLimit
).toNumber(),
receiptLookupRange: BigNumber.from(
this.networkConfig.receiptLookupRange
).toNumber(),
etherscanApiKey: hasEtherscanApiKey,
conditionalTransactions: this.networkConfig.conditionalTransactions,
rpcEndpointSubmit: hasExecutionRpc,
gasPriceMarkup: BigNumber.from(
this.networkConfig.gasPriceMarkup
).toNumber(),
enforceGasPrice: this.networkConfig.enforceGasPrice,
enforceGasPriceThreshold: BigNumber.from(
this.networkConfig.enforceGasPriceThreshold
).toNumber(),
};
}

/**
* see eth_feeHistory
* @param entryPoint Entry Point contract
Expand Down
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.43",
"version": "0.0.44",
"description": "Various bundler parameters",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/skandha#readme",
Expand All @@ -25,7 +25,7 @@
"@eth-optimism/sdk": "3.0.0",
"@mantleio/sdk": "0.2.1",
"ethers": "5.7.2",
"types": "^0.0.43"
"types": "^0.0.44"
},
"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.43",
"version": "0.0.44",
"description": "The types of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down
25 changes: 25 additions & 0 deletions packages/types/src/api/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ export type UserOperationReceipt = {
receipt: providers.TransactionReceipt;
};

export type GetConfigResponse = {
flags: {
redirectRpc: boolean;
testingMode: boolean;
unsafeMode: boolean;
};
entryPoints: string[];
beneficiary: string;
relayer: string;
minInclusionDenominator: number;
throttlingSlack: number;
banSlack: number;
minSignerBalance: string;
multicall: string;
estimationStaticBuffer: number;
validationGasLimit: number;
receiptLookupRange: number;
etherscanApiKey: boolean; // true if set
conditionalTransactions: boolean;
rpcEndpointSubmit: boolean; // true if not empty string
gasPriceMarkup: number;
enforceGasPrice: boolean;
enforceGasPriceThreshold: number;
};

export type SupportedEntryPoints = string[];

export type EthChainIdResponse = { chainId: number };
Expand Down