diff --git a/packages/bundler/src/BundlerServer.ts b/packages/bundler/src/BundlerServer.ts index de17bbda..4775437a 100644 --- a/packages/bundler/src/BundlerServer.ts +++ b/packages/bundler/src/BundlerServer.ts @@ -214,6 +214,9 @@ export class BundlerServer { result = 'ok' } break + case 'debug_bundler_getAddressStakeStatus': + result = await this.debugHandler.getAddressStakeStatus(params[0], params[1]) + break default: throw new RpcError(`Method ${method} is not supported`, -32601) } diff --git a/packages/bundler/src/DebugMethodHandler.ts b/packages/bundler/src/DebugMethodHandler.ts index 3027b986..3ea7535d 100644 --- a/packages/bundler/src/DebugMethodHandler.ts +++ b/packages/bundler/src/DebugMethodHandler.ts @@ -3,6 +3,7 @@ import { ReputationDump, ReputationManager } from './modules/ReputationManager' import { MempoolManager } from './modules/MempoolManager' import { SendBundleReturn } from './modules/BundleManager' import { EventsManager } from './modules/EventsManager' +import { StakeInfo } from './modules/Types' export class DebugMethodHandler { constructor ( @@ -65,4 +66,14 @@ export class DebugMethodHandler { clearReputation (): void { this.repManager.clearState() } + + async getAddressStakeStatus ( + address: string, + entryPoint: string + ): Promise<{ + stakeInfo: StakeInfo + isStaked: boolean + }> { + return await this.repManager.getStakeStatus(address, entryPoint) + } } diff --git a/packages/bundler/src/modules/ReputationManager.ts b/packages/bundler/src/modules/ReputationManager.ts index b9f79dc2..6450a27e 100644 --- a/packages/bundler/src/modules/ReputationManager.ts +++ b/packages/bundler/src/modules/ReputationManager.ts @@ -1,7 +1,10 @@ import Debug from 'debug' import { requireCond, tostr } from '../utils' import { BigNumber } from 'ethers' +import { Provider } from '@ethersproject/providers' + import { StakeInfo, ValidationErrors } from './Types' +import { IStakeManager__factory } from '../types' const debug = Debug('aa.rep') @@ -42,6 +45,7 @@ export type ReputationDump = ReputationEntry[] export class ReputationManager { constructor ( + readonly provider: Provider, readonly params: ReputationParams, readonly minStake: BigNumber, readonly minUnstakeDelay: number) { @@ -149,6 +153,25 @@ export class ReputationManager { } } + async getStakeStatus (address: string, entryPointAddress: string): Promise<{ + stakeInfo: StakeInfo + isStaked: boolean + }> { + const sm = IStakeManager__factory.connect(entryPointAddress, this.provider) + const info = await sm.getDepositInfo(address) + const isStaked = + BigNumber.from(info.stake).gte(this.minStake) && + BigNumber.from(info.unstakeDelaySec).gte(this.minUnstakeDelay) + return { + stakeInfo: { + addr: address, + stake: info.stake.toString(), + unstakeDelaySec: info.unstakeDelaySec.toString() + }, + isStaked + } + } + /** * an entity that caused handleOps to revert, which requires re-building the bundle from scratch. * should be banned immediately, by increasing its opSeen counter diff --git a/packages/bundler/src/modules/initServer.ts b/packages/bundler/src/modules/initServer.ts index d1ce6f3d..ef60e04b 100644 --- a/packages/bundler/src/modules/initServer.ts +++ b/packages/bundler/src/modules/initServer.ts @@ -8,6 +8,7 @@ import { parseEther } from 'ethers/lib/utils' import { Signer } from 'ethers' import { BundlerConfig } from '../BundlerConfig' import { EventsManager } from './EventsManager' +import { getNetworkProvider } from '../Config' /** * initialize server modules. @@ -17,7 +18,7 @@ import { EventsManager } from './EventsManager' */ export function initServer (config: BundlerConfig, signer: Signer): [ExecutionManager, EventsManager, ReputationManager, MempoolManager] { const entryPoint = EntryPoint__factory.connect(config.entryPoint, signer) - const reputationManager = new ReputationManager(BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay) + const reputationManager = new ReputationManager(getNetworkProvider(config.network), BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay) const mempoolManager = new MempoolManager(reputationManager) const validationManager = new ValidationManager(entryPoint, reputationManager, config.unsafe) const eventsManager = new EventsManager(entryPoint, mempoolManager, reputationManager)