Skip to content

Commit

Permalink
Adding stake manager
Browse files Browse the repository at this point in the history
  • Loading branch information
shahafn committed Aug 25, 2024
1 parent 62d4f2d commit a7b1163
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions packages/bundler/src/modules/initServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { JsonRpcProvider } from '@ethersproject/providers'
import { Signer } from 'ethers'
import { parseEther } from 'ethers/lib/utils'

import { IEntryPoint__factory } from '@account-abstraction/utils'
import { IEntryPoint__factory, IStakeManager__factory } from '@account-abstraction/utils'

import { ExecutionManager } from './ExecutionManager'
import { BundlerReputationParams, ReputationManager } from './ReputationManager'
Expand All @@ -11,7 +11,7 @@ import { BundleManager } from './BundleManager'
import {
ValidationManager,
ValidationManagerRIP7560,
IValidationManager
IValidationManager, AA_STAKE_MANAGER
} from '@account-abstraction/validation-manager'
import { BundlerConfig } from '../BundlerConfig'
import { EventsManager } from './EventsManager'
Expand All @@ -38,7 +38,8 @@ export function initServer (config: BundlerConfig, signer: Signer): [ExecutionMa
bundleManager = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, signer, eventsManager, mempoolManager, validationManager, reputationManager,
config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, config.conditionalRpc)
} else {
validationManager = new ValidationManagerRIP7560(entryPoint.provider as JsonRpcProvider, config.unsafe)
const stakeManager = IStakeManager__factory.connect(AA_STAKE_MANAGER, signer)
validationManager = new ValidationManagerRIP7560(stakeManager, entryPoint.provider as JsonRpcProvider, config.unsafe)
bundleManager = new BundleManagerRIP7560(entryPoint.provider as JsonRpcProvider, signer, eventsManager, mempoolManager, validationManager, reputationManager,
config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, config.conditionalRpc, false)
}
Expand Down
2 changes: 2 additions & 0 deletions packages/bundler/src/runBundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { parseEther } from 'ethers/lib/utils'
import { MethodHandlerRIP7560 } from './MethodHandlerRIP7560'
import { JsonRpcProvider } from '@ethersproject/providers'
import { deployNonceManager } from '@account-abstraction/utils/dist/src/RIP7712NonceManagerUtils'
import { deployStakeManager } from '@account-abstraction/utils/dist/src/deployStakeManager'

// this is done so that console.log outputs BigNumber as hex string instead of unreadable object
export const inspectCustomSymbol = Symbol.for('nodejs.util.inspect.custom')
Expand Down Expand Up @@ -137,6 +138,7 @@ export async function runBundler (argv: string[], overrideExit = true): Promise<

if (config.rip7560) {
await deployNonceManager(provider, wallet as any)
await deployStakeManager(provider, wallet as any)
}

const {
Expand Down
2 changes: 2 additions & 0 deletions packages/utils/contracts/Imports.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ import "@account-abstraction/contracts/samples/SimpleAccountFactory.sol";
import "@account-abstraction/contracts/samples/TokenPaymaster.sol";

import {NonceManager as NonceManagerRIP7712} from "@account-abstraction/rip7560/contracts/predeploys/NonceManager.sol";
import {StakeManager as StakeManagerRIP7560} from "@account-abstraction/rip7560/contracts/predeploys/StakeManager.sol";
import {IStakeManager as IStakeManagerRIP7560} from "@account-abstraction/rip7560/contracts/interfaces/IStakeManager.sol";
3 changes: 2 additions & 1 deletion packages/utils/src/RIP7712NonceManagerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { JsonRpcProvider } from '@ethersproject/providers'
import { bytecode as nonceManagerByteCode } from '../artifacts/@account-abstraction/rip7560/contracts/predeploys/NonceManager.sol/NonceManager.json'
import { DeterministicDeployer } from './DeterministicDeployer'
import { NonceManager__factory } from './types/factories/@account-abstraction/rip7560/contracts/predeploys'
import { NonceManager } from './types/@account-abstraction/rip7560/contracts/predeploys'

export const entryPointSalt = '0x90d8084deab30c2a37c45e8d47f49f2f7965183cb6990a98943ef94940681de3'

export async function deployNonceManager (provider: JsonRpcProvider, signer = provider.getSigner()): Promise<any> {
export async function deployNonceManager (provider: JsonRpcProvider, signer = provider.getSigner()): Promise<NonceManager> {
const addr = await new DeterministicDeployer(provider, signer).deterministicDeploy(nonceManagerByteCode, entryPointSalt)
return NonceManager__factory.connect(addr, signer)
}
Expand Down
17 changes: 17 additions & 0 deletions packages/utils/src/deployStakeManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { JsonRpcProvider } from '@ethersproject/providers'

import { bytecode as stakeManagerByteCode } from '../artifacts/@account-abstraction/rip7560/contracts/predeploys/StakeManager.sol/StakeManager.json'
import { DeterministicDeployer } from './DeterministicDeployer'
import { StakeManager__factory } from './types/factories/@account-abstraction/rip7560/contracts/predeploys'
import { StakeManager } from './types/@account-abstraction/rip7560/contracts/predeploys'

export const stakeManagerSalt = '0x90d8084deab30c2a37c45e8d47f49f2f7965183cb6990a98943ef94940681de3'

export async function deployStakeManager (provider: JsonRpcProvider, signer = provider.getSigner()): Promise<StakeManager> {
const addr = await new DeterministicDeployer(provider, signer).deterministicDeploy(stakeManagerByteCode, stakeManagerSalt)
return StakeManager__factory.connect(addr, signer)
}

export function getStakeManagerAddress (): string {
return DeterministicDeployer.getAddress(stakeManagerByteCode, stakeManagerSalt)
}
48 changes: 43 additions & 5 deletions packages/validation-manager/src/ValidationManagerRIP7560.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import {
OperationBase,
OperationRIP7560,
ReferencedCodeHashes,
getRIP7560TransactionHash
getRIP7560TransactionHash, IStakeManager, StakeInfo
} from '@account-abstraction/utils'

import { IValidationManager, ValidateUserOpResult, ValidationResult } from './IValidationManager'
import { eth_traceRip7560Validation } from './GethTracer'
import { tracerResultParser } from './TracerResultParser'
import debug from 'debug'
import { isAddress } from 'ethers/lib/utils'

export const AA_ENTRY_POINT = '0x0000000000000000000000000000000000007560'
export const AA_STAKE_MANAGER = '0x5271A07b4516A6408E27395941b3D8FC04d96353'

export class ValidationManagerRIP7560 implements IValidationManager {
constructor (
readonly stakeManager: IStakeManager,
readonly provider: JsonRpcProvider,
readonly unsafe: boolean
) {
Expand All @@ -25,6 +28,43 @@ export class ValidationManagerRIP7560 implements IValidationManager {
// TODO
}

async _getStakesInfo (operation: OperationBase): Promise<{ senderInfo: StakeInfo, paymasterInfo: StakeInfo, factoryInfo: StakeInfo }> {
const senderTMI = await this.stakeManager.getDepositInfo(operation.sender)
const senderInfo = {
addr: operation.sender,
...senderTMI
}
let paymasterInfo: StakeInfo = {
addr: '',
stake: 0,
unstakeDelaySec: 0
}
if (operation.paymaster != null && isAddress(operation.paymaster)) {
const paymasterTMI = await this.stakeManager.getDepositInfo(operation.paymaster)
paymasterInfo = {
addr: operation.paymaster,
...paymasterTMI
}
}
let factoryInfo: StakeInfo = {
addr: '',
stake: 0,
unstakeDelaySec: 0
}
if (operation.factory != null && isAddress(operation.factory)) {
const factoryTMI = await this.stakeManager.getDepositInfo(operation.factory)
factoryInfo = {
addr: operation.factory,
...factoryTMI
}
}
return {
factoryInfo,
paymasterInfo,
senderInfo
}
}

async validateUserOp (operation: OperationBase, previousCodeHashes?: ReferencedCodeHashes): Promise<ValidateUserOpResult> {
const transaction = operation as OperationRIP7560
// let storageMap: StorageMap = {}
Expand All @@ -36,12 +76,10 @@ export class ValidationManagerRIP7560 implements IValidationManager {
const traceResult = await this.traceValidation(transaction).catch(e => {
throw e
})
// TODO alex shahaf add staked entities support
const stakesInfo = await this._getStakesInfo(operation)
const validationResult: ValidationResult = {
returnInfo: { sigFailed: false, validAfter: 0, validUntil: 0 },
factoryInfo: { stake: 0, addr: operation.factory ?? '', unstakeDelaySec: 0 },
paymasterInfo: { stake: 0, addr: operation.paymaster ?? '', unstakeDelaySec: 0 },
senderInfo: { stake: 0, addr: operation.sender, unstakeDelaySec: 0 }
...stakesInfo
}
debug(`traceResult= ${JSON.stringify(traceResult)}`)
// this.parseValidationTracingResult(traceResult)
Expand Down
2 changes: 1 addition & 1 deletion submodules/rip7560

0 comments on commit a7b1163

Please sign in to comment.