use hardhat's provider's signer (#114)

* use hardhat's provider's signer

* Fix linter issues

---------

Co-authored-by: Andreas Papageorgiou <andreas@btblock.io>
Co-authored-by: MakisChristou <makis_christou@protonmail.com>
This commit is contained in:
andreas-papageorgiou
2023-07-28 00:18:04 +03:00
committed by GitHub
parent 623991115d
commit ba29f67567
3 changed files with 14 additions and 11 deletions

View File

@@ -2,7 +2,7 @@ import bodyParser from 'body-parser'
import cors from 'cors'
import express, { Express, Response, Request } from 'express'
import { Provider } from '@ethersproject/providers'
import { Wallet, utils } from 'ethers'
import { Signer, utils } from 'ethers'
import { parseEther } from 'ethers/lib/utils'
import { AddressZero, deepHexlify, erc4337RuntimeVersion } from '@account-abstraction/utils'
@@ -26,7 +26,7 @@ export class BundlerServer {
readonly debugHandler: DebugMethodHandler,
readonly config: BundlerConfig,
readonly provider: Provider,
readonly wallet: Wallet
readonly wallet: Signer
) {
this.app = express()
this.app.use(cors())
@@ -77,8 +77,9 @@ export class BundlerServer {
if (err?.errorName !== 'FailedOp') {
this.fatal(`Invalid entryPoint contract at ${this.config.entryPoint}. wrong version?`)
}
const bal = await this.provider.getBalance(this.wallet.address)
console.log('signer', this.wallet.address, 'balance', utils.formatEther(bal))
const signerAddress = await this.wallet.getAddress()
const bal = await this.provider.getBalance(signerAddress)
console.log('signer', signerAddress, 'balance', utils.formatEther(bal))
if (bal.eq(0)) {
this.fatal('cannot run with zero balance')
} else if (bal.lt(parseEther(this.config.minBalance))) {

View File

@@ -2,7 +2,7 @@ import ow from 'ow'
import fs from 'fs'
import { BundlerConfig, bundlerConfigDefault, BundlerConfigShape } from './BundlerConfig'
import { Wallet } from 'ethers'
import { Wallet, Signer } from 'ethers'
import { BaseProvider, JsonRpcProvider } from '@ethersproject/providers'
function getCommandLineParams (programOpts: any): Partial<BundlerConfig> {
@@ -33,7 +33,7 @@ export function getNetworkProvider (url: string): JsonRpcProvider {
return new JsonRpcProvider(url)
}
export async function resolveConfiguration (programOpts: any): Promise<{ config: BundlerConfig, provider: BaseProvider, wallet: Wallet }> {
export async function resolveConfiguration (programOpts: any): Promise<{ config: BundlerConfig, provider: BaseProvider, wallet: Signer }> {
const commandLineParams = getCommandLineParams(programOpts)
let fileConfig: Partial<BundlerConfig> = {}
const configFileName = programOpts.config
@@ -43,11 +43,13 @@ export async function resolveConfiguration (programOpts: any): Promise<{ config:
const config = mergeConfigs(bundlerConfigDefault, fileConfig, commandLineParams)
console.log('Merged configuration:', JSON.stringify(config))
const provider: BaseProvider = config.network === 'hardhat'
if (config.network === 'hardhat') {
// eslint-disable-next-line
? require('hardhat').ethers.provider
: getNetworkProvider(config.network)
const provider: JsonRpcProvider = require('hardhat').ethers.provider
return { config, provider, wallet: provider.getSigner() }
}
const provider: BaseProvider = getNetworkProvider(config.network)
let mnemonic: string
let wallet: Wallet
try {

View File

@@ -2,7 +2,7 @@ import fs from 'fs'
import { Command } from 'commander'
import { erc4337RuntimeVersion } from '@account-abstraction/utils'
import { ethers, Wallet } from 'ethers'
import { ethers, Wallet, Signer } from 'ethers'
import { BundlerServer } from './BundlerServer'
import { UserOpMethodHandler } from './UserOpMethodHandler'
@@ -29,7 +29,7 @@ const CONFIG_FILE_NAME = 'workdir/bundler.config.json'
export let showStackTraces = false
export async function connectContracts (
wallet: Wallet,
wallet: Signer,
entryPointAddress: string): Promise<{ entryPoint: EntryPoint }> {
const entryPoint = EntryPoint__factory.connect(entryPointAddress, wallet)
return {