diff --git a/src/backend/base.ts b/src/backend/base.ts index 2764663..67e6c06 100644 --- a/src/backend/base.ts +++ b/src/backend/base.ts @@ -120,12 +120,12 @@ export abstract class BaseBackend implements IBackend { ): Promise { // Pre hooks for (const hooksController of this.hooksControllers) { - [userOp, hints] = await hooksController.preSubmitUserOperation( + [userOp, hints, extra] = await hooksController.preSubmitUserOperation( userOp, hints, + extra, ); } - // Implemented by subclass let userOpHash = await this._submitUserOperation(userOp, hints, extra); @@ -148,10 +148,13 @@ export abstract class BaseBackend implements IBackend { ): Promise { // Pre hooks for (const hooksController of this.hooksControllers) { - [userOp, userOpHash] = await hooksController.preGetSolverOperations( - userOp, - userOpHash, - ); + [userOp, userOpHash, wait, extra] = + await hooksController.preGetSolverOperations( + userOp, + userOpHash, + wait, + extra, + ); } // Implemented by subclass @@ -176,7 +179,7 @@ export abstract class BaseBackend implements IBackend { async submitBundle(bundle: Bundle, extra?: any): Promise { // Pre hooks for (const hooksController of this.hooksControllers) { - bundle = await hooksController.preSubmitBundle(bundle); + [bundle, extra] = await hooksController.preSubmitBundle(bundle, extra); } // Implemented by subclass @@ -197,7 +200,11 @@ export abstract class BaseBackend implements IBackend { ): Promise { // Pre hooks for (const hooksController of this.hooksControllers) { - userOpHash = await hooksController.preGetBundleHash(userOpHash); + [userOpHash, wait, extra] = await hooksController.preGetBundleHash( + userOpHash, + wait, + extra, + ); } // Implemented by subclass @@ -219,7 +226,8 @@ export abstract class BaseBackend implements IBackend { ): Promise { // Pre hooks for (const hooksController of this.hooksControllers) { - userOp = await hooksController.preGetBundleForUserOp(userOp); + [userOp, hints, wait, extra] = + await hooksController.preGetBundleForUserOp(userOp, hints, wait, extra); } // Implemented by subclass diff --git a/src/backend/hooks/base.ts b/src/backend/hooks/base.ts index f8bf98c..4bf6c3e 100644 --- a/src/backend/hooks/base.ts +++ b/src/backend/hooks/base.ts @@ -5,7 +5,8 @@ export interface IHooksController { preSubmitUserOperation( userOp: UserOperation, hints: string[], - ): Promise<[UserOperation, string[]]>; + extra?: any, + ): Promise<[UserOperation, string[], any]>; postSubmitUserOperation( userOp: UserOperation, @@ -15,22 +16,33 @@ export interface IHooksController { preGetSolverOperations( userOp: UserOperation, userOphash: string, - ): Promise<[UserOperation, string]>; + wait?: boolean, + extra?: any, + ): Promise<[UserOperation, string, boolean, any]>; postGetSolverOperations( userOp: UserOperation, solverOps: SolverOperation[], ): Promise<[UserOperation, SolverOperation[]]>; - preSubmitBundle(bundleOps: Bundle): Promise; + preSubmitBundle(bundle: Bundle, extra?: any): Promise<[Bundle, any]>; postSubmitBundle(result: string): Promise; - preGetBundleHash(userOphash: string): Promise; + preGetBundleHash( + userOphash: string, + wait?: boolean, + extra?: any, + ): Promise<[string, boolean, any]>; postGetBundleHash(atlasTxHash: string): Promise; - preGetBundleForUserOp(userOp: UserOperation): Promise; + preGetBundleForUserOp( + userOp: UserOperation, + hints: string[], + wait?: boolean, + extra?: any, + ): Promise<[UserOperation, string[], boolean | undefined, any]>; postGetBundleForUserOp(bundle: Bundle): Promise; } @@ -48,8 +60,9 @@ export abstract class BaseHooksController implements IHooksController { async preSubmitUserOperation( userOp: UserOperation, hints: string[], - ): Promise<[UserOperation, string[]]> { - return [userOp, hints]; + extra?: any, + ): Promise<[UserOperation, string[], any]> { + return [userOp, hints, extra]; } async postSubmitUserOperation( @@ -62,8 +75,10 @@ export abstract class BaseHooksController implements IHooksController { async preGetSolverOperations( userOp: UserOperation, userOphash: string, - ): Promise<[UserOperation, string]> { - return [userOp, userOphash]; + wait?: boolean, + extra?: any, + ): Promise<[UserOperation, string, boolean, any]> { + return [userOp, userOphash, wait || false, extra]; } async postGetSolverOperations( @@ -73,24 +88,33 @@ export abstract class BaseHooksController implements IHooksController { return [userOp, solverOps]; } - async preSubmitBundle(bundleOps: Bundle): Promise { - return bundleOps; + async preSubmitBundle(bundle: Bundle, extra?: any): Promise<[Bundle, any]> { + return [bundle, extra]; } async postSubmitBundle(result: string): Promise { return result; } - async preGetBundleHash(userOphash: string): Promise { - return userOphash; + async preGetBundleHash( + userOphash: string, + wait: boolean, + extra?: any, + ): Promise<[string, boolean, any]> { + return [userOphash, wait, extra]; } async postGetBundleHash(atlasTxHash: string): Promise { return atlasTxHash; } - async preGetBundleForUserOp(userOp: UserOperation): Promise { - return userOp; + async preGetBundleForUserOp( + userOp: UserOperation, + hints: string[], + wait?: boolean, + extra?: any, + ): Promise<[UserOperation, string[], boolean | undefined, any]> { + return [userOp, hints, wait, extra]; } async postGetBundleForUserOp(bundle: Bundle): Promise { diff --git a/src/backend/hooks/simulation.ts b/src/backend/hooks/simulation.ts index 3679236..943cbbd 100644 --- a/src/backend/hooks/simulation.ts +++ b/src/backend/hooks/simulation.ts @@ -46,7 +46,8 @@ export class SimulationHooksController extends BaseHooksController { async preSubmitUserOperation( userOp: UserOperation, hints: string[], - ): Promise<[UserOperation, string[]]> { + extra?: any, + ): Promise<[UserOperation, string[], any]> { const [success, result, validCallsResult] = await this.simulator .getFunction("simUserOperation") .staticCall(userOp.toStruct()); @@ -57,7 +58,7 @@ export class SimulationHooksController extends BaseHooksController { ); } - return [userOp, hints]; + return [userOp, hints, extra]; } async postGetSolverOperations( @@ -141,7 +142,10 @@ export class SimulationHooksController extends BaseHooksController { return [userOp, simulatedSolverOps]; } - async preSubmitBundle(bundleOps: Bundle): Promise { + async preSubmitBundle( + bundleOps: Bundle, + extra?: any, + ): Promise<[Bundle, any]> { // Simulation will throw if the bundle is invalid await this.atlas .connect( @@ -157,6 +161,6 @@ export class SimulationHooksController extends BaseHooksController { bundleOps.dAppOperation.toStruct(), ); - return bundleOps; + return [bundleOps, extra]; } } diff --git a/test/sdk.test.ts b/test/sdk.test.ts index 75793a7..4c1fdab 100644 --- a/test/sdk.test.ts +++ b/test/sdk.test.ts @@ -358,27 +358,47 @@ describe("Atlas SDK main tests", () => { const mockHooksController = { preSubmitUserOperation: jest .fn() - .mockImplementation(async (userOp, hints) => [userOp, hints]), + .mockImplementation(async (userOp, hints, extra) => [ + userOp, + hints, + extra, + ]), postSubmitUserOperation: jest .fn() .mockImplementation(async (userOp, userOpHash) => [userOp, userOpHash]), preGetSolverOperations: jest .fn() - .mockImplementation(async (userOp, userOpHash) => [userOp, userOpHash]), + .mockImplementation(async (userOp, userOpHash, wait, extra) => [ + userOp, + userOpHash, + wait, + extra, + ]), postGetSolverOperations: jest .fn() .mockImplementation(async (userOp, solverOps) => [userOp, solverOps]), - preSubmitBundle: jest.fn().mockImplementation(async (bundle) => bundle), + preSubmitBundle: jest + .fn() + .mockImplementation(async (bundle, extra) => [bundle, extra]), postSubmitBundle: jest.fn().mockImplementation(async (result) => result), preGetBundleHash: jest .fn() - .mockImplementation(async (userOpHash) => userOpHash), + .mockImplementation(async (userOpHash, wait, extra) => [ + userOpHash, + wait, + extra, + ]), postGetBundleHash: jest .fn() .mockImplementation(async (atlasTxHash) => atlasTxHash), preGetBundleForUserOp: jest .fn() - .mockImplementation(async (userOp) => userOp), + .mockImplementation(async (userOp, hints, wait, extra) => [ + userOp, + hints, + wait, + extra, + ]), postGetBundleForUserOp: jest .fn() .mockImplementation(async (bundle) => bundle), @@ -401,6 +421,9 @@ describe("Atlas SDK main tests", () => { expect(mockHooksController.preGetBundleForUserOp).toHaveBeenCalledWith( userOp, + [], + true, + { chainId: chainId }, ); expect(mockHooksController.postGetBundleForUserOp).toHaveBeenCalled(); });