From b17c6377bbe9d63b01be6000e6be90f4d9b70fbb Mon Sep 17 00:00:00 2001 From: 0xNotMe Date: Tue, 8 Oct 2024 17:07:58 +1100 Subject: [PATCH 1/3] chore: remove ts warnings --- test/sdk.test.ts | 54 +++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/test/sdk.test.ts b/test/sdk.test.ts index cbacf62..8c2837f 100644 --- a/test/sdk.test.ts +++ b/test/sdk.test.ts @@ -3,14 +3,12 @@ import { toUtf8Bytes, HDNodeWallet, ZeroAddress, - keccak256, } from "ethers"; import { AtlasSdk } from "../src"; import { MockBackend } from "../src/backend"; import { OperationBuilder, ZeroBytes } from "../src/operation"; import { validateBytes32, - flagTrustedOpHash, CallConfigIndex, } from "../src/utils"; import { chainConfig } from "../src/config"; @@ -45,7 +43,7 @@ describe("Atlas SDK main tests", () => { }; const userOpParamsWithCallConfigFlag = (flagIndex: CallConfigIndex) => { - let uop = { ...userOpParams }; + const uop = { ...userOpParams }; uop.callConfig |= 1n << BigInt(flagIndex); return uop; }; @@ -115,7 +113,7 @@ describe("Atlas SDK main tests", () => { }); test("submitUserOperation with invalid session key", async () => { - let userOp = OperationBuilder.newUserOperation(userOpParams); + const userOp = OperationBuilder.newUserOperation(userOpParams); // Set sessionKey manually (not generated by Atlas) userOp.setField("sessionKey", "0x1111111111111111111111111111111111111111"); @@ -127,7 +125,7 @@ describe("Atlas SDK main tests", () => { }); test("submitUserOperation with invalid hints", async () => { - let userOp = OperationBuilder.newUserOperation(userOpParams); + const userOp = OperationBuilder.newUserOperation(userOpParams); // Invalid hints const invalidHints = ["0x01"]; @@ -137,7 +135,7 @@ describe("Atlas SDK main tests", () => { }); test("submitUserOperation", async () => { - let userOp = OperationBuilder.newUserOperation(userOpParams); + const userOp = OperationBuilder.newUserOperation(userOpParams); // Submit user operation const solverOps = await sdk.submitUserOperation(userOp); @@ -150,8 +148,8 @@ describe("Atlas SDK main tests", () => { const userOpParams = userOpParamsWithCallConfigFlag( CallConfigIndex.ExPostBids ); - let userOp = OperationBuilder.newUserOperation(userOpParams); - let solverOps = await sdk.submitUserOperation(userOp); + const userOp = OperationBuilder.newUserOperation(userOpParams); + const solverOps = await sdk.submitUserOperation(userOp); const lengthBefore = solverOps.length; @@ -159,15 +157,15 @@ describe("Atlas SDK main tests", () => { expect(lengthBefore).toBeGreaterThan(0); // Sort solver operations - solverOps = await sdk.sortSolverOperations(userOp, solverOps); + const sortedSolverOps = await sdk.sortSolverOperations(userOp, solverOps); // solverOps untouched - expect(solverOps.length).toBe(lengthBefore); + expect(sortedSolverOps.length).toBe(lengthBefore); }); test("sortSolverOperations - 0 ops returned without flag zeroSolvers", async () => { - let userOp = OperationBuilder.newUserOperation(userOpParams); - let solverOps = await sdk.submitUserOperation(userOp); + const userOp = OperationBuilder.newUserOperation(userOpParams); + const solverOps = await sdk.submitUserOperation(userOp); // solverOps non-empty expect(solverOps.length).toBeGreaterThan(0); @@ -182,41 +180,41 @@ describe("Atlas SDK main tests", () => { const userOpParams = userOpParamsWithCallConfigFlag( CallConfigIndex.ZeroSolvers ); - let userOp = OperationBuilder.newUserOperation(userOpParams); - let solverOps = await sdk.submitUserOperation(userOp); + const userOp = OperationBuilder.newUserOperation(userOpParams); + const solverOps = await sdk.submitUserOperation(userOp); // solverOps non-empty expect(solverOps.length).toBeGreaterThan(0); // Sort solver operations - solverOps = await sdk.sortSolverOperations(userOp, solverOps); + const sortedSolverOps = await sdk.sortSolverOperations(userOp, solverOps); // solverOps empty - expect(solverOps.length).toBe(0); + expect(sortedSolverOps.length).toBe(0); }); test("sortSolverOperations", async () => { - let userOp = OperationBuilder.newUserOperation(userOpParams); + const userOp = OperationBuilder.newUserOperation(userOpParams); // Tweak the user operation so solutions won't get discarded by the sorter userOp.setField("gas", 0n); userOp.setField("maxFeePerGas", 0n); - let solverOps = await sdk.submitUserOperation(userOp); + const solverOps = await sdk.submitUserOperation(userOp); // solverOps non-empty expect(solverOps.length).toBeGreaterThan(0); // Sort solver operations - solverOps = await sdk.sortSolverOperations(userOp, solverOps); + const sortedSolverOps = await sdk.sortSolverOperations(userOp, solverOps); // Sorted solverOps non-empty - expect(solverOps.length).toBeGreaterThan(0); + expect(sortedSolverOps.length).toBeGreaterThan(0); // Ensure solverOps are sorted let prevBidAmount = 0n; - for (let i = 0; i < solverOps.length; i++) { - const bidAmount = solverOps[i].getField("bidAmount").value as bigint; + for (let i = 0; i < sortedSolverOps.length; i++) { + const bidAmount = sortedSolverOps[i].getField("bidAmount").value as bigint; if (i === 0) { prevBidAmount = bidAmount; continue; @@ -227,8 +225,8 @@ describe("Atlas SDK main tests", () => { }); test("createDAppOperation session key not found", async () => { - let userOp = OperationBuilder.newUserOperation(userOpParams); - let solverOps = await sdk.submitUserOperation(userOp); + const userOp = OperationBuilder.newUserOperation(userOpParams); + const solverOps = await sdk.submitUserOperation(userOp); // Set sessionKey manually (not generated by Atlas) userOp.setField("sessionKey", "0x1111111111111111111111111111111111111111"); @@ -245,7 +243,7 @@ describe("Atlas SDK main tests", () => { // Generate session key userOp = sdk.generateSessionKey(userOp); - let solverOps = await sdk.submitUserOperation(userOp); + const solverOps = await sdk.submitUserOperation(userOp); // Generate dApp operation const dAppOp = await sdk.createDAppOperation(userOp, solverOps); @@ -267,7 +265,7 @@ describe("Atlas SDK main tests", () => { // Generate session key userOp = sdk.generateSessionKey(userOp); - let solverOps = await sdk.submitUserOperation(userOp); + const solverOps = await sdk.submitUserOperation(userOp); // Generate dApp operation const dAppOp = await sdk.createDAppOperation(userOp, solverOps); @@ -285,7 +283,7 @@ describe("Atlas SDK main tests", () => { // Generate session key userOp = sdk.generateSessionKey(userOp); - let solverOps = await sdk.submitUserOperation(userOp); + const solverOps = await sdk.submitUserOperation(userOp); // Generate dApp operation const dAppOp = await sdk.createDAppOperation(userOp, solverOps); @@ -310,7 +308,7 @@ describe("Atlas SDK main tests", () => { // Sign user operation userOp = await sdk.signUserOperation(userOp, signer); - let solverOps = await sdk.submitUserOperation(userOp); + const solverOps = await sdk.submitUserOperation(userOp); // Generate dApp operation const dAppOp = await sdk.createDAppOperation(userOp, solverOps); From fa224c1912f23c7c9978e4acaf5d160551666334 Mon Sep 17 00:00:00 2001 From: 0xNotMe Date: Tue, 8 Oct 2024 17:32:32 +1100 Subject: [PATCH 2/3] fix: prettier errors --- .eslintrc.json | 25 ++++++------------------- .prettierrc | 7 +++++++ package.json | 4 +++- src/backend/fastlane.ts | 10 +++++----- src/backend/hooks/simulation.ts | 4 ++-- src/backend/mock.ts | 12 +++++++++++- 6 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 .prettierrc diff --git a/.eslintrc.json b/.eslintrc.json index 9a0144b..8e48598 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,7 +5,8 @@ }, "extends": [ "eslint:recommended", - "plugin:@typescript-eslint/recommended" + "plugin:@typescript-eslint/recommended", + "plugin:prettier/recommended" ], "parser": "@typescript-eslint/parser", "parserOptions": { @@ -13,25 +14,11 @@ "sourceType": "module" }, "plugins": [ - "@typescript-eslint" + "@typescript-eslint", + "prettier" ], "rules": { - "indent": [ - "error", - 2 - ], - "linebreak-style": [ - "error", - "unix" - ], - "quotes": [ - "error", - "double" - ], - "semi": [ - "error", - "always" - ], - "@typescript-eslint/no-explicit-any": "off" + "@typescript-eslint/no-explicit-any": "off", + "prettier/prettier": "error" } } diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..227df76 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "semi": true, + "trailingComma": "all", + "singleQuote": false, + "printWidth": 80, + "tabWidth": 2 +} \ No newline at end of file diff --git a/package.json b/package.json index fee7ebe..b4cec72 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "main": "dist/index.js", "scripts": { "test": "jest", - "build": "tsc" + "build": "tsc", + "prettier": "prettier --write .", + "prettier:check": "prettier --check ." }, "repository": { "type": "git", diff --git a/src/backend/fastlane.ts b/src/backend/fastlane.ts index 5549b91..00d9f14 100644 --- a/src/backend/fastlane.ts +++ b/src/backend/fastlane.ts @@ -192,7 +192,7 @@ const FastlaneApiFetchParamCreator = function () { hints: string[], options: any = {} ): FetchArgs { - let body: any = { + const body: any = { userOperation: userOp.toStruct(), }; if (hints.length > 0) { @@ -229,8 +229,8 @@ const FastlaneApiFetchParamCreator = function () { localVarRequestOptions.headers["Content-Type"] === "application/json"; localVarRequestOptions.body = needsSerialization ? JSON.stringify(body || {}, (_, v) => - typeof v === "bigint" ? toQuantity(v) : v - ) + typeof v === "bigint" ? toQuantity(v) : v + ) : body || ""; return { @@ -335,8 +335,8 @@ const FastlaneApiFetchParamCreator = function () { localVarRequestOptions.headers["Content-Type"] === "application/json"; localVarRequestOptions.body = needsSerialization ? JSON.stringify(bundleStruct || {}, (_, v) => - typeof v === "bigint" ? toQuantity(v) : v - ) + typeof v === "bigint" ? toQuantity(v) : v + ) : bundleStruct || ""; return { diff --git a/src/backend/hooks/simulation.ts b/src/backend/hooks/simulation.ts index 29f2d81..3d57796 100644 --- a/src/backend/hooks/simulation.ts +++ b/src/backend/hooks/simulation.ts @@ -47,7 +47,7 @@ export class SimulationHooksController extends BaseHooksController { userOp: UserOperation, hints: string[] ): Promise<[UserOperation, string[]]> { - let [success, result, validCallsResult] = await this.simulator + const [success, result, validCallsResult] = await this.simulator .getFunction("simUserOperation") .staticCall(userOp.toStruct()); @@ -123,7 +123,7 @@ export class SimulationHooksController extends BaseHooksController { }; }); results = await this.multicall3.getFunction("aggregate3").staticCall(calls); - let simulatedSolverOps: SolverOperation[] = []; + const simulatedSolverOps: SolverOperation[] = []; for (let i = 0; i < results.length; i++) { if (!results[i].success) { continue; diff --git a/src/backend/mock.ts b/src/backend/mock.ts index 8d39fd1..d9798fc 100644 --- a/src/backend/mock.ts +++ b/src/backend/mock.ts @@ -24,7 +24,9 @@ export class MockBackend extends BaseBackend { */ public async _submitUserOperation( userOp: UserOperation, + // eslint-disable-next-line @typescript-eslint/no-unused-vars hints: string[], + // eslint-disable-next-line @typescript-eslint/no-unused-vars extra?: any ): Promise { return userOp.hash( @@ -45,7 +47,9 @@ export class MockBackend extends BaseBackend { public async _getSolverOperations( userOp: UserOperation, userOpHash: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars wait?: boolean, + // eslint-disable-next-line @typescript-eslint/no-unused-vars extra?: any ): Promise { const solverOps: SolverOperation[] = []; @@ -79,7 +83,11 @@ export class MockBackend extends BaseBackend { * @param {*} [extra] Extra parameters * @returns {Promise} The result message */ - public async _submitBundle(bundle: Bundle, extra?: any): Promise { + public async _submitBundle( + bundle: Bundle, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + extra?: any + ): Promise { const userOpHash = bundle.userOperation.hash( chainConfig[chainId].eip712Domain, flagTrustedOpHash(bundle.userOperation.callConfig()) @@ -98,7 +106,9 @@ export class MockBackend extends BaseBackend { */ public async _getBundleHash( userOpHash: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars wait?: boolean, + // eslint-disable-next-line @typescript-eslint/no-unused-vars extra?: any ): Promise { const bundle = this.submittedBundles[userOpHash]; From 31b8291d03d80c2c52d82142be06bafd39379936 Mon Sep 17 00:00:00 2001 From: 0xNotMe Date: Tue, 8 Oct 2024 19:07:26 +1100 Subject: [PATCH 3/3] run: prettier --- .eslintrc.json | 41 +++++++++---------- .prettierrc => .prettierrc.json | 2 +- package-lock.json | 17 ++++++++ package.json | 1 + src/backend/base.ts | 34 ++++++++-------- src/backend/fastlane.ts | 70 ++++++++++++++++----------------- src/backend/hooks/base.ts | 18 ++++----- src/backend/hooks/simulation.ts | 22 +++++------ src/backend/mock.ts | 14 +++---- src/operation/base.ts | 12 +++--- src/operation/builder.ts | 6 +-- src/operation/bundle.ts | 2 +- src/operation/solver.ts | 2 +- src/operation/user.ts | 4 +- src/sdk.ts | 56 +++++++++++++------------- src/utils/compute.ts | 4 +- test/sdk.test.ts | 34 ++++++++-------- test/unit.test.ts | 28 ++++++------- tsconfig.json | 18 ++++----- 19 files changed, 199 insertions(+), 186 deletions(-) rename .prettierrc => .prettierrc.json (98%) diff --git a/.eslintrc.json b/.eslintrc.json index 8e48598..3d8a297 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,24 +1,21 @@ { - "env": { - "browser": true, - "es2021": true - }, - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:prettier/recommended" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module" - }, - "plugins": [ - "@typescript-eslint", - "prettier" - ], - "rules": { - "@typescript-eslint/no-explicit-any": "off", - "prettier/prettier": "error" - } + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:prettier/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": ["@typescript-eslint", "prettier"], + "rules": { + "@typescript-eslint/no-explicit-any": "off", + "prettier/prettier": "error" + } } diff --git a/.prettierrc b/.prettierrc.json similarity index 98% rename from .prettierrc rename to .prettierrc.json index 227df76..a64f001 100644 --- a/.prettierrc +++ b/.prettierrc.json @@ -4,4 +4,4 @@ "singleQuote": false, "printWidth": 80, "tabWidth": 2 -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index e83f2af..c41c6d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", "eslint": "^8.56.0", + "prettier": "^3.3.3", "ts-jest": "^29.1.2", "ts-node": "^10.9.2", "typescript": "^5.3.3" @@ -4527,6 +4528,22 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", diff --git a/package.json b/package.json index b4cec72..39302fb 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", "eslint": "^8.56.0", + "prettier": "^3.3.3", "ts-jest": "^29.1.2", "ts-node": "^10.9.2", "typescript": "^5.3.3" diff --git a/src/backend/base.ts b/src/backend/base.ts index 6fe93bd..d59a40d 100644 --- a/src/backend/base.ts +++ b/src/backend/base.ts @@ -15,13 +15,13 @@ export interface IBackend { submitUserOperation( userOp: UserOperation, hints: string[], - extra?: any + extra?: any, ): Promise; _submitUserOperation( userOp: UserOperation, hints: string[], - extra?: any + extra?: any, ): Promise; /** @@ -37,14 +37,14 @@ export interface IBackend { userOp: UserOperation, userOpHash: string, wait?: boolean, - extra?: any + extra?: any, ): Promise; _getSolverOperations( userOp: UserOperation, userOpHash: string, wait?: boolean, - extra?: any + extra?: any, ): Promise; /** @@ -69,13 +69,13 @@ export interface IBackend { getBundleHash( userOpHash: string, wait?: boolean, - extra?: any + extra?: any, ): Promise; _getBundleHash( userOpHash: string, wait?: boolean, - extra?: any + extra?: any, ): Promise; } @@ -91,13 +91,13 @@ export abstract class BaseBackend implements IBackend { async submitUserOperation( userOp: UserOperation, hints: string[], - extra?: any + extra?: any, ): Promise { // Pre hooks for (const hooksController of this.hooksControllers) { [userOp, hints] = await hooksController.preSubmitUserOperation( userOp, - hints + hints, ); } @@ -108,7 +108,7 @@ export abstract class BaseBackend implements IBackend { for (const hooksController of this.hooksControllers) { [userOp, userOpHash] = await hooksController.postSubmitUserOperation( userOp, - userOpHash + userOpHash, ); } @@ -119,13 +119,13 @@ export abstract class BaseBackend implements IBackend { userOp: UserOperation, userOpHash: string, wait?: boolean, - extra?: any + extra?: any, ): Promise { // Pre hooks for (const hooksController of this.hooksControllers) { [userOp, userOpHash] = await hooksController.preGetSolverOperations( userOp, - userOpHash + userOpHash, ); } @@ -134,14 +134,14 @@ export abstract class BaseBackend implements IBackend { userOp, userOpHash, wait, - extra + extra, ); // Post hooks for (const hooksController of this.hooksControllers) { [userOp, solverOps] = await hooksController.postGetSolverOperations( userOp, - solverOps + solverOps, ); } @@ -168,7 +168,7 @@ export abstract class BaseBackend implements IBackend { async getBundleHash( userOpHash: string, wait?: boolean, - extra?: any + extra?: any, ): Promise { // Pre hooks for (const hooksController of this.hooksControllers) { @@ -189,7 +189,7 @@ export abstract class BaseBackend implements IBackend { async _submitUserOperation( userOp: UserOperation, hints: string[], - extra?: any + extra?: any, ): Promise { throw new Error("Method not implemented."); } @@ -198,7 +198,7 @@ export abstract class BaseBackend implements IBackend { userOp: UserOperation, userOpHash: string, wait?: boolean, - extra?: any + extra?: any, ): Promise { throw new Error("Method not implemented."); } @@ -210,7 +210,7 @@ export abstract class BaseBackend implements IBackend { async _getBundleHash( userOpHash: string, wait?: boolean, - extra?: any + extra?: any, ): Promise { throw new Error("Method not implemented."); } diff --git a/src/backend/fastlane.ts b/src/backend/fastlane.ts index 00d9f14..3cffb3a 100644 --- a/src/backend/fastlane.ts +++ b/src/backend/fastlane.ts @@ -68,13 +68,13 @@ export class FastlaneBackend extends BaseBackend { public async _submitUserOperation( userOp: UserOperation, hints: string[], - extra?: any + extra?: any, ): Promise { const localVarFetchArgs = FastlaneApiFetchParamCreator().submitUserOperation(userOp, hints, extra); const response = await fetch( this.params["basePath"] + localVarFetchArgs.url, - localVarFetchArgs.options + localVarFetchArgs.options, ); if (response.status >= 200 && response.status < 300) { return await response.json(); @@ -97,25 +97,25 @@ export class FastlaneBackend extends BaseBackend { _: UserOperation, userOpHash: string, wait?: boolean, - extra?: any + extra?: any, ): Promise { const localVarFetchArgs = FastlaneApiFetchParamCreator().getSolverOperations( userOpHash, wait, - extra + extra, ); const response = await fetch( this.params["basePath"] + localVarFetchArgs.url, - localVarFetchArgs.options + localVarFetchArgs.options, ); if (response.status >= 200 && response.status < 300) { const solverOpsWithScore = await response.json(); return solverOpsWithScore.map((solverOpWithScore: any) => OperationBuilder.newSolverOperation( solverOpWithScore.solverOperation, - solverOpWithScore.score - ) + solverOpWithScore.score, + ), ); } else { const reponseBody = await response.json(); @@ -133,11 +133,11 @@ export class FastlaneBackend extends BaseBackend { public async _submitBundle(bundle: Bundle, extra?: any): Promise { const localVarFetchArgs = FastlaneApiFetchParamCreator().submitBundle( bundle, - extra + extra, ); const response = await fetch( this.params["basePath"] + localVarFetchArgs.url, - localVarFetchArgs.options + localVarFetchArgs.options, ); if (response.status >= 200 && response.status < 300) { return await response.json(); @@ -158,16 +158,16 @@ export class FastlaneBackend extends BaseBackend { public async _getBundleHash( userOpHash: string, wait?: boolean, - extra?: any + extra?: any, ): Promise { const localVarFetchArgs = FastlaneApiFetchParamCreator().getBundleHash( userOpHash, wait, - extra + extra, ); const response = await fetch( this.params["basePath"] + localVarFetchArgs.url, - localVarFetchArgs.options + localVarFetchArgs.options, ); if (response.status >= 200 && response.status < 300) { return await response.json(); @@ -190,7 +190,7 @@ const FastlaneApiFetchParamCreator = function () { submitUserOperation( userOp: UserOperation, hints: string[], - options: any = {} + options: any = {}, ): FetchArgs { const body: any = { userOperation: userOp.toStruct(), @@ -200,11 +200,11 @@ const FastlaneApiFetchParamCreator = function () { } const localVarUrlObj = url.parse( ROUTES.get("submitUserOperation")?.path as string, - true + true, ); const localVarRequestOptions = Object.assign( { method: ROUTES.get("submitUserOperation")?.method as string }, - options + options, ); const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -215,22 +215,22 @@ const FastlaneApiFetchParamCreator = function () { {}, localVarUrlObj.query, localVarQueryParameter, - options.query + options.query, ); // fix override query string Detail: https://stackoverflow.com/a/7517673/1077943 localVarUrlObj.search = null; localVarRequestOptions.headers = Object.assign( {}, localVarHeaderParameter, - options.headers + options.headers, ); const needsSerialization = "UserOperation" !== "string" || localVarRequestOptions.headers["Content-Type"] === "application/json"; localVarRequestOptions.body = needsSerialization ? JSON.stringify(body || {}, (_, v) => - typeof v === "bigint" ? toQuantity(v) : v - ) + typeof v === "bigint" ? toQuantity(v) : v, + ) : body || ""; return { @@ -248,7 +248,7 @@ const FastlaneApiFetchParamCreator = function () { getSolverOperations( userOpHash: string, wait?: boolean, - options: any = {} + options: any = {}, ): FetchArgs { // verify required parameter 'userOpHash' is not null or undefined if (userOpHash === null || userOpHash === undefined) { @@ -256,11 +256,11 @@ const FastlaneApiFetchParamCreator = function () { } const localVarUrlObj = url.parse( ROUTES.get("getSolverOperations")?.path as string, - true + true, ); const localVarRequestOptions = Object.assign( { method: ROUTES.get("getSolverOperations")?.method as string }, - options + options, ); const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -277,14 +277,14 @@ const FastlaneApiFetchParamCreator = function () { {}, localVarUrlObj.query, localVarQueryParameter, - options.query + options.query, ); // fix override query string Detail: https://stackoverflow.com/a/7517673/1077943 localVarUrlObj.search = null; localVarRequestOptions.headers = Object.assign( {}, localVarHeaderParameter, - options.headers + options.headers, ); return { @@ -306,11 +306,11 @@ const FastlaneApiFetchParamCreator = function () { }; const localVarUrlObj = url.parse( ROUTES.get("submitBundle")?.path as string, - true + true, ); const localVarRequestOptions = Object.assign( { method: ROUTES.get("submitBundle")?.method as string }, - options + options, ); const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -321,22 +321,22 @@ const FastlaneApiFetchParamCreator = function () { {}, localVarUrlObj.query, localVarQueryParameter, - options.query + options.query, ); // fix override query string Detail: https://stackoverflow.com/a/7517673/1077943 localVarUrlObj.search = null; localVarRequestOptions.headers = Object.assign( {}, localVarHeaderParameter, - options.headers + options.headers, ); const needsSerialization = "Bundle" !== "string" || localVarRequestOptions.headers["Content-Type"] === "application/json"; localVarRequestOptions.body = needsSerialization ? JSON.stringify(bundleStruct || {}, (_, v) => - typeof v === "bigint" ? toQuantity(v) : v - ) + typeof v === "bigint" ? toQuantity(v) : v, + ) : bundleStruct || ""; return { @@ -354,7 +354,7 @@ const FastlaneApiFetchParamCreator = function () { getBundleHash( userOpHash: string, wait?: boolean, - options: any = {} + options: any = {}, ): FetchArgs { // verify required parameter 'userOpHash' is not null or undefined if (userOpHash === null || userOpHash === undefined) { @@ -362,11 +362,11 @@ const FastlaneApiFetchParamCreator = function () { } const localVarUrlObj = url.parse( ROUTES.get("getBundleHash")?.path as string, - true + true, ); const localVarRequestOptions = Object.assign( { method: ROUTES.get("getBundleHash")?.method as string }, - options + options, ); const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; @@ -383,14 +383,14 @@ const FastlaneApiFetchParamCreator = function () { {}, localVarUrlObj.query, localVarQueryParameter, - options.query + options.query, ); // fix override query string Detail: https://stackoverflow.com/a/7517673/1077943 localVarUrlObj.search = null; localVarRequestOptions.headers = Object.assign( {}, localVarHeaderParameter, - options.headers + options.headers, ); return { diff --git a/src/backend/hooks/base.ts b/src/backend/hooks/base.ts index 0741051..c5ac559 100644 --- a/src/backend/hooks/base.ts +++ b/src/backend/hooks/base.ts @@ -4,22 +4,22 @@ import { UserOperation, SolverOperation, Bundle } from "../../operation"; export interface IHooksController { preSubmitUserOperation( userOp: UserOperation, - hints: string[] + hints: string[], ): Promise<[UserOperation, string[]]>; postSubmitUserOperation( userOp: UserOperation, - userOphash: string + userOphash: string, ): Promise<[UserOperation, string]>; preGetSolverOperations( userOp: UserOperation, - userOphash: string + userOphash: string, ): Promise<[UserOperation, string]>; postGetSolverOperations( userOp: UserOperation, - solverOps: SolverOperation[] + solverOps: SolverOperation[], ): Promise<[UserOperation, SolverOperation[]]>; preSubmitBundle(bundleOps: Bundle): Promise; @@ -38,33 +38,33 @@ export interface IHooksControllerConstructable { export abstract class BaseHooksController implements IHooksController { constructor( protected provider: AbstractProvider, - protected chainId: number + protected chainId: number, ) {} async preSubmitUserOperation( userOp: UserOperation, - hints: string[] + hints: string[], ): Promise<[UserOperation, string[]]> { return [userOp, hints]; } async postSubmitUserOperation( userOp: UserOperation, - userOphash: string + userOphash: string, ): Promise<[UserOperation, string]> { return [userOp, userOphash]; } async preGetSolverOperations( userOp: UserOperation, - userOphash: string + userOphash: string, ): Promise<[UserOperation, string]> { return [userOp, userOphash]; } async postGetSolverOperations( userOp: UserOperation, - solverOps: SolverOperation[] + solverOps: SolverOperation[], ): Promise<[UserOperation, SolverOperation[]]> { return [userOp, solverOps]; } diff --git a/src/backend/hooks/simulation.ts b/src/backend/hooks/simulation.ts index 3d57796..3679236 100644 --- a/src/backend/hooks/simulation.ts +++ b/src/backend/hooks/simulation.ts @@ -29,23 +29,23 @@ export class SimulationHooksController extends BaseHooksController { this.atlas = new Contract( chainConfig[chainId].contracts.atlas.address, atlasAbi, - provider + provider, ); this.simulator = new Contract( chainConfig[chainId].contracts.simulator.address, simulatorAbi, - provider + provider, ); this.multicall3 = new Contract( chainConfig[chainId].contracts.multicall3.address, multicall3Abi, - provider + provider, ); } async preSubmitUserOperation( userOp: UserOperation, - hints: string[] + hints: string[], ): Promise<[UserOperation, string[]]> { const [success, result, validCallsResult] = await this.simulator .getFunction("simUserOperation") @@ -53,7 +53,7 @@ export class SimulationHooksController extends BaseHooksController { if (!success) { throw new Error( - `user operation failed simulation, result: ${result}, validCallsResult: ${validCallsResult}` + `user operation failed simulation, result: ${result}, validCallsResult: ${validCallsResult}`, ); } @@ -62,7 +62,7 @@ export class SimulationHooksController extends BaseHooksController { async postGetSolverOperations( userOp: UserOperation, - solverOps: SolverOperation[] + solverOps: SolverOperation[], ): Promise<[UserOperation, SolverOperation[]]> { let sortedSolverOps: SolverOperation[] = solverOps.slice(); const atlasAddress = await this.atlas.getAddress(); @@ -84,7 +84,7 @@ export class SimulationHooksController extends BaseHooksController { for (let i = 0; i < results.length; i++) { const stats = this.atlas.interface.decodeFunctionResult( "accessData", - results[i].returnData + results[i].returnData, ); const auctionWins = Number(stats[2]); const auctionFails = Number(stats[3]); @@ -130,7 +130,7 @@ export class SimulationHooksController extends BaseHooksController { } const [success, ,] = this.simulator.interface.decodeFunctionResult( "simSolverCall", - results[i].returnData + results[i].returnData, ); if (!success) { continue; @@ -147,14 +147,14 @@ export class SimulationHooksController extends BaseHooksController { .connect( new VoidSigner( bundleOps.dAppOperation.getField("bundler").value as string, - this.provider - ) + this.provider, + ), ) .getFunction("metacall") .staticCall( bundleOps.userOperation.toStruct(), bundleOps.solverOperations.map((solverOp) => solverOp.toStruct()), - bundleOps.dAppOperation.toStruct() + bundleOps.dAppOperation.toStruct(), ); return bundleOps; diff --git a/src/backend/mock.ts b/src/backend/mock.ts index d9798fc..e5d25b4 100644 --- a/src/backend/mock.ts +++ b/src/backend/mock.ts @@ -27,11 +27,11 @@ export class MockBackend extends BaseBackend { // eslint-disable-next-line @typescript-eslint/no-unused-vars hints: string[], // eslint-disable-next-line @typescript-eslint/no-unused-vars - extra?: any + extra?: any, ): Promise { return userOp.hash( chainConfig[chainId].eip712Domain, - flagTrustedOpHash(userOp.callConfig()) + flagTrustedOpHash(userOp.callConfig()), ); } @@ -50,7 +50,7 @@ export class MockBackend extends BaseBackend { // eslint-disable-next-line @typescript-eslint/no-unused-vars wait?: boolean, // eslint-disable-next-line @typescript-eslint/no-unused-vars - extra?: any + extra?: any, ): Promise { const solverOps: SolverOperation[] = []; for (let i = 0; i < Math.floor(Math.random() * 5 + 1); i++) { @@ -69,7 +69,7 @@ export class MockBackend extends BaseBackend { bidAmount: BigInt(30000 * (i + 1)), data: ZeroBytes, signature: ZeroBytes, - }) + }), ); } @@ -86,11 +86,11 @@ export class MockBackend extends BaseBackend { public async _submitBundle( bundle: Bundle, // eslint-disable-next-line @typescript-eslint/no-unused-vars - extra?: any + extra?: any, ): Promise { const userOpHash = bundle.userOperation.hash( chainConfig[chainId].eip712Domain, - flagTrustedOpHash(bundle.userOperation.callConfig()) + flagTrustedOpHash(bundle.userOperation.callConfig()), ); this.submittedBundles[userOpHash] = bundle; return userOpHash; @@ -109,7 +109,7 @@ export class MockBackend extends BaseBackend { // eslint-disable-next-line @typescript-eslint/no-unused-vars wait?: boolean, // eslint-disable-next-line @typescript-eslint/no-unused-vars - extra?: any + extra?: any, ): Promise { const bundle = this.submittedBundles[userOpHash]; if (bundle === undefined) { diff --git a/src/operation/base.ts b/src/operation/base.ts index aca733c..e242fa6 100644 --- a/src/operation/base.ts +++ b/src/operation/base.ts @@ -64,7 +64,7 @@ export abstract class BaseOperation { tdDomain, this.toTypedDataTypes(), this.toTypedDataValues(), - f.value as string + f.value as string, ); if (signer !== this.getField("from").value) { throw new Error("Invalid signature"); @@ -116,21 +116,21 @@ export abstract class BaseOperation { const f = Array.from(this.fields.values()); return this.abiCoder.encode( [`tuple(${f.map((f) => f.solType).join(", ")})`], - [f.map((f) => f.value)] + [f.map((f) => f.value)], ); } public toStruct(): { [key: string]: OpFieldType } { return Array.from(this.fields.values()).reduce( (acc, f) => ({ ...acc, [f.name]: f.value }), - {} + {}, ); } public toTypedDataTypes(): { [key: string]: TypedDataField[] } { return this.toTypedDataTypesCustomFields( // All fields except the last one (signature) - Array.from(this.fields.keys()).slice(0, -1) + Array.from(this.fields.keys()).slice(0, -1), ); } @@ -150,7 +150,7 @@ export abstract class BaseOperation { public toTypedDataValues(): { [key: string]: OpFieldType } { return this.toTypedDataValuesCustomFields( // All fields except the last one (signature) - Array.from(this.fields.keys()).slice(0, -1) + Array.from(this.fields.keys()).slice(0, -1), ); } @@ -164,7 +164,7 @@ export abstract class BaseOperation { ...acc, [f.name]: f.value, }), - {} + {}, ); } } diff --git a/src/operation/builder.ts b/src/operation/builder.ts index d477d00..9036eeb 100644 --- a/src/operation/builder.ts +++ b/src/operation/builder.ts @@ -58,7 +58,7 @@ export abstract class OperationBuilder { data: string; signature: string; }, - score?: number + score?: number, ): SolverOperation { const solverOp = new SolverOperation(score); solverOp.setFields({ @@ -114,7 +114,7 @@ export abstract class OperationBuilder { userOp: UserOperation, solverOps: SolverOperation[], signer: HDNodeWallet, - bundler: string = ZeroAddress + bundler: string = ZeroAddress, ): DAppOperation { const userTo = userOp.getField("to").value; if (userTo === undefined) { @@ -147,7 +147,7 @@ export abstract class OperationBuilder { public static newBundle( userOp: UserOperation, solverOps: SolverOperation[], - dAppOp: DAppOperation + dAppOp: DAppOperation, ): Bundle { return new Bundle(userOp, solverOps, dAppOp); } diff --git a/src/operation/bundle.ts b/src/operation/bundle.ts index 9836ecb..c167f57 100644 --- a/src/operation/bundle.ts +++ b/src/operation/bundle.ts @@ -9,7 +9,7 @@ export class Bundle { constructor( userOp: UserOperation, solverOps: SolverOperation[], - dAppOp: DAppOperation + dAppOp: DAppOperation, ) { this.userOperation = userOp; this.solverOperations = solverOps; diff --git a/src/operation/solver.ts b/src/operation/solver.ts index 1dd229a..e9803ed 100644 --- a/src/operation/solver.ts +++ b/src/operation/solver.ts @@ -29,7 +29,7 @@ export class SolverOperation extends BaseOperation { const f = Array.from(s.fields.values()); return s.abiCoder.encode( [`tuple(${f.map((f) => f.solType).join(", ")})[]`], - [solverOps.map((op) => f.map((f) => op.fields.get(f.name)?.value))] + [solverOps.map((op) => f.map((f) => op.fields.get(f.name)?.value))], ); } } diff --git a/src/operation/user.ts b/src/operation/user.ts index d20ebe6..c0525ba 100644 --- a/src/operation/user.ts +++ b/src/operation/user.ts @@ -37,10 +37,10 @@ export class UserOperation extends BaseOperation { if (trusted) { typedDataTypes = this.toTypedDataTypesCustomFields( - this.trustedOperationHashFields + this.trustedOperationHashFields, ); typedDataValues = this.toTypedDataValuesCustomFields( - this.trustedOperationHashFields + this.trustedOperationHashFields, ); } else { typedDataTypes = this.toTypedDataTypes(); diff --git a/src/sdk.ts b/src/sdk.ts index 49a1edc..02fc870 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -54,23 +54,23 @@ export class AtlasSdk { provider: AbstractProvider, chainId: number, backend: IBackend, - hooksControllers: IHooksControllerConstructable[] = [] + hooksControllers: IHooksControllerConstructable[] = [], ) { this.chainId = chainId; this.iAtlas = new Interface(atlasAbi); this.atlasVerification = new Contract( chainConfig[chainId].contracts.atlasVerification.address, atlasVerificationAbi, - provider + provider, ); this.dAppControl = new Contract(ZeroAddress, dAppControlAbi, provider); this.sorter = new Contract( chainConfig[chainId].contracts.sorter.address, sorterAbi, - provider + provider, ); const _hooksControllers = hooksControllers.map( - (HookController) => new HookController(provider, chainId) + (HookController) => new HookController(provider, chainId), ); this.backend = backend; this.backend.addHooksControllers(_hooksControllers); @@ -84,7 +84,7 @@ export class AtlasSdk { */ public async newUserOperation( userOpParams: UserOperationParams, - generateSessionKey = false + generateSessionKey = false, ): Promise { let userOp = OperationBuilder.newUserOperation({ from: userOpParams.from, @@ -113,7 +113,7 @@ export class AtlasSdk { userOp.setField("callConfig", dConfig.callConfig); } else if (dConfig.callConfig !== userOpParams.callConfig) { throw new Error( - "UserOperation callConfig does not match dApp callConfig" + "UserOperation callConfig does not match dApp callConfig", ); } @@ -140,7 +140,7 @@ export class AtlasSdk { public getUserOperationHash(userOp: UserOperation): string { return userOp.hash( chainConfig[this.chainId].eip712Domain, - flagTrustedOpHash(userOp.callConfig()) + flagTrustedOpHash(userOp.callConfig()), ); } @@ -150,7 +150,7 @@ export class AtlasSdk { * @returns the user operation with a valid nonce field */ public async setUserOperationNonce( - userOp: UserOperation + userOp: UserOperation, ): Promise { const user = userOp.getField("from").value as string; let nonce: bigint; @@ -161,7 +161,7 @@ export class AtlasSdk { if (this.usersLastNonSequentialNonce.has(user)) { nonce = await this.atlasVerification.getUserNextNonSeqNonceAfter( user, - this.usersLastNonSequentialNonce.get(user) as bigint + this.usersLastNonSequentialNonce.get(user) as bigint, ); } else { nonce = await this.atlasVerification.getUserNextNonce(user, false); @@ -193,15 +193,15 @@ export class AtlasSdk { */ public async signUserOperation( userOp: UserOperation, - signer: AbstractSigner + signer: AbstractSigner, ): Promise { userOp.setField( "signature", await signer.signTypedData( chainConfig[this.chainId].eip712Domain, userOp.toTypedDataTypes(), - userOp.toTypedDataValues() - ) + userOp.toTypedDataValues(), + ), ); userOp.validateSignature(chainConfig[this.chainId].eip712Domain); return userOp; @@ -215,7 +215,7 @@ export class AtlasSdk { */ public async submitUserOperation( userOp: UserOperation, - hints: string[] = [] + hints: string[] = [], ): Promise { const sessionKey = userOp.getField("sessionKey").value as string; if (sessionKey !== ZeroAddress && !this.sessionKeys.has(sessionKey)) { @@ -238,12 +238,12 @@ export class AtlasSdk { // Submit the user operation to the backend const remoteUserOphash: string = await this.backend.submitUserOperation( userOp, - hints + hints, ); const userOpHash = userOp.hash( chainConfig[this.chainId].eip712Domain, - flagTrustedOpHash(userOp.callConfig()) + flagTrustedOpHash(userOp.callConfig()), ); if (userOpHash !== remoteUserOphash) { @@ -254,7 +254,7 @@ export class AtlasSdk { const solverOps: SolverOperation[] = await this.backend.getSolverOperations( userOp, userOpHash, - true + true, ); if (solverOps.length === 0 && !flagZeroSolvers(userOp.callConfig())) { @@ -272,7 +272,7 @@ export class AtlasSdk { */ public async sortSolverOperations( userOp: UserOperation, - solverOps: SolverOperation[] + solverOps: SolverOperation[], ): Promise { const callConfig = userOp.callConfig(); @@ -283,11 +283,11 @@ export class AtlasSdk { const sortedSolverOpsResp: any[] = await this.sorter.sortBids( userOp.toStruct(), - solverOps.map((solverOp) => solverOp.toStruct()) + solverOps.map((solverOp) => solverOp.toStruct()), ); const sortedSolverOps: SolverOperation[] = sortedSolverOpsResp.map((op) => - OperationBuilder.newSolverOperation(op) + OperationBuilder.newSolverOperation(op), ); if (sortedSolverOps.length === 0 && !flagZeroSolvers(callConfig)) { @@ -307,7 +307,7 @@ export class AtlasSdk { public async createDAppOperation( userOp: UserOperation, solverOps: SolverOperation[], - bundler: string = ZeroAddress + bundler: string = ZeroAddress, ): Promise { const sessionKey = userOp.getField("sessionKey").value as string; @@ -327,7 +327,7 @@ export class AtlasSdk { const userOpHash = userOp.hash( chainConfig[this.chainId].eip712Domain, - flagTrustedOpHash(callConfig) + flagTrustedOpHash(callConfig), ); const dAppOp: DAppOperation = @@ -336,13 +336,13 @@ export class AtlasSdk { userOp, solverOps, sessionAccount, - bundler + bundler, ); const signature = await sessionAccount.signTypedData( chainConfig[this.chainId].eip712Domain, dAppOp.toTypedDataTypes(), - dAppOp.toTypedDataValues() + dAppOp.toTypedDataValues(), ); dAppOp.setField("signature", signature); @@ -361,7 +361,7 @@ export class AtlasSdk { public getMetacallCalldata( userOp: UserOperation, solverOps: SolverOperation[], - dAppOp: DAppOperation + dAppOp: DAppOperation, ): string { return this.iAtlas.encodeFunctionData("metacall", [ userOp.toStruct(), @@ -380,7 +380,7 @@ export class AtlasSdk { public async submitBundle( userOp: UserOperation, solverOps: SolverOperation[], - dAppOp: DAppOperation + dAppOp: DAppOperation, ): Promise { const sessionKey = userOp.getField("sessionKey").value as string; if ( @@ -388,7 +388,7 @@ export class AtlasSdk { sessionKey !== dAppOp.getField("from").value ) { throw new Error( - "User operation session key does not match dApp operation" + "User operation session key does not match dApp operation", ); } @@ -399,7 +399,7 @@ export class AtlasSdk { const userOpHash = userOp.hash( chainConfig[this.chainId].eip712Domain, - flagTrustedOpHash(userOp.callConfig()) + flagTrustedOpHash(userOp.callConfig()), ); if (userOpHash !== remoteUserOpHash) { @@ -408,7 +408,7 @@ export class AtlasSdk { const atlasTxHash: string = await this.backend.getBundleHash( userOpHash, - true + true, ); return atlasTxHash; diff --git a/src/utils/compute.ts b/src/utils/compute.ts index 073b0c1..cdd8a80 100644 --- a/src/utils/compute.ts +++ b/src/utils/compute.ts @@ -11,11 +11,11 @@ import { UserOperation, SolverOperation } from "../operation"; */ export function getCallChainHash( userOp: UserOperation, - solverOps: SolverOperation[] + solverOps: SolverOperation[], ): string { const callSequence = solidityPacked( ["bytes", "bytes"], - [userOp.abiEncode(), SolverOperation.abiEncodeArray(solverOps)] + [userOp.abiEncode(), SolverOperation.abiEncodeArray(solverOps)], ); return keccak256(callSequence); diff --git a/test/sdk.test.ts b/test/sdk.test.ts index 8c2837f..f10dd55 100644 --- a/test/sdk.test.ts +++ b/test/sdk.test.ts @@ -7,10 +7,7 @@ import { import { AtlasSdk } from "../src"; import { MockBackend } from "../src/backend"; import { OperationBuilder, ZeroBytes } from "../src/operation"; -import { - validateBytes32, - CallConfigIndex, -} from "../src/utils"; +import { validateBytes32, CallConfigIndex } from "../src/utils"; import { chainConfig } from "../src/config"; describe("Atlas SDK main tests", () => { @@ -18,13 +15,13 @@ describe("Atlas SDK main tests", () => { const sdk = new AtlasSdk( new JsonRpcProvider("https://rpc.sepolia.org/", chainId), chainId, - new MockBackend() + new MockBackend(), ); const testDAppControl = "0x60d7B59c6743C25b29a7aEe6F5a37c07B1A6Cff3"; const signer = HDNodeWallet.fromSeed( - toUtf8Bytes("bad seed used for this test only") + toUtf8Bytes("bad seed used for this test only"), ); let nonSequentialNonceTracker = 0n; @@ -108,7 +105,7 @@ describe("Atlas SDK main tests", () => { // Validate signature expect(() => - userOp.validateSignature(chainConfig[chainId].eip712Domain) + userOp.validateSignature(chainConfig[chainId].eip712Domain), ).not.toThrow(); }); @@ -120,7 +117,7 @@ describe("Atlas SDK main tests", () => { // Invalid session key expect(async () => await sdk.submitUserOperation(userOp)).rejects.toThrow( - "Session key not found" + "Session key not found", ); }); @@ -130,7 +127,7 @@ describe("Atlas SDK main tests", () => { // Invalid hints const invalidHints = ["0x01"]; expect( - async () => await sdk.submitUserOperation(userOp, invalidHints) + async () => await sdk.submitUserOperation(userOp, invalidHints), ).rejects.toThrow("Invalid hint address: 0x01"); }); @@ -146,7 +143,7 @@ describe("Atlas SDK main tests", () => { test("sortSolverOperations with flag exPostBids", async () => { const userOpParams = userOpParamsWithCallConfigFlag( - CallConfigIndex.ExPostBids + CallConfigIndex.ExPostBids, ); const userOp = OperationBuilder.newUserOperation(userOpParams); const solverOps = await sdk.submitUserOperation(userOp); @@ -172,13 +169,13 @@ describe("Atlas SDK main tests", () => { // Sort solver operations expect(async () => - sdk.sortSolverOperations(userOp, solverOps) + sdk.sortSolverOperations(userOp, solverOps), ).rejects.toThrow("No solver operations returned"); }); test("sortSolverOperations - 0 ops returned with flag zeroSolvers", async () => { const userOpParams = userOpParamsWithCallConfigFlag( - CallConfigIndex.ZeroSolvers + CallConfigIndex.ZeroSolvers, ); const userOp = OperationBuilder.newUserOperation(userOpParams); const solverOps = await sdk.submitUserOperation(userOp); @@ -214,7 +211,8 @@ describe("Atlas SDK main tests", () => { // Ensure solverOps are sorted let prevBidAmount = 0n; for (let i = 0; i < sortedSolverOps.length; i++) { - const bidAmount = sortedSolverOps[i].getField("bidAmount").value as bigint; + const bidAmount = sortedSolverOps[i].getField("bidAmount") + .value as bigint; if (i === 0) { prevBidAmount = bidAmount; continue; @@ -233,7 +231,7 @@ describe("Atlas SDK main tests", () => { // Invalid session key expect( - async () => await sdk.createDAppOperation(userOp, solverOps) + async () => await sdk.createDAppOperation(userOp, solverOps), ).rejects.toThrow("Session key not found"); }); @@ -250,12 +248,12 @@ describe("Atlas SDK main tests", () => { // Validate dApp operation expect(dAppOp.getField("from").value).toBe( - userOp.getField("sessionKey").value + userOp.getField("sessionKey").value, ); // Validate signature expect(() => - dAppOp.validateSignature(chainConfig[chainId].eip712Domain) + dAppOp.validateSignature(chainConfig[chainId].eip712Domain), ).not.toThrow(); }); @@ -293,9 +291,9 @@ describe("Atlas SDK main tests", () => { // Invalid session key expect( - async () => await sdk.submitBundle(userOp, solverOps, dAppOp) + async () => await sdk.submitBundle(userOp, solverOps, dAppOp), ).rejects.toThrow( - "User operation session key does not match dApp operation" + "User operation session key does not match dApp operation", ); }); diff --git a/test/unit.test.ts b/test/unit.test.ts index b0d3fb4..6e53810 100644 --- a/test/unit.test.ts +++ b/test/unit.test.ts @@ -53,25 +53,25 @@ describe("Atlas SDK unit tests", () => { test("abi encode user operation", () => { expect(testUserOperation.abiEncode()).toBe( - "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000000c80000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000012c0000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000258000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000004646174610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000097369676e61747572650000000000000000000000000000000000000000000000" + "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000000c80000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000012c0000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000258000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000004646174610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000097369676e61747572650000000000000000000000000000000000000000000000", ); }); test("abi encode solver operation", () => { expect(testSolverOperation.abiEncode()).toBe( - "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000c8000000000000000000000000000000000000000000000000000000000000012c0000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000049999999999999999999999999999999999999999999999999999999999999999000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000004646174610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000097369676e61747572650000000000000000000000000000000000000000000000" + "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000c8000000000000000000000000000000000000000000000000000000000000012c0000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000049999999999999999999999999999999999999999999999999999999999999999000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000004646174610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000097369676e61747572650000000000000000000000000000000000000000000000", ); }); test("user operation hash default", () => { expect(testUserOperation.hash(chainConfig[0].eip712Domain, false)).toBe( - "0x021a7f3f62347f1f3d1163aa8eb9fc965e87556aede03c7182ec05bc60311b64" + "0x021a7f3f62347f1f3d1163aa8eb9fc965e87556aede03c7182ec05bc60311b64", ); }); test("user operation hash trusted", () => { expect(testUserOperation.hash(chainConfig[0].eip712Domain, true)).toBe( - "0x96aa1212cae2645ba1b8bf8014abccdfe9a60c16f86e21f82753d4cecc0b6089" + "0x96aa1212cae2645ba1b8bf8014abccdfe9a60c16f86e21f82753d4cecc0b6089", ); }); @@ -83,7 +83,7 @@ describe("Atlas SDK unit tests", () => { ]); expect(callChainHash).toBe( - "0x8a71f907fe61688772ede6e7bb91efa992fe86c27917862adf533984dd56a2b8" + "0x8a71f907fe61688772ede6e7bb91efa992fe86c27917862adf533984dd56a2b8", ); }); @@ -91,23 +91,23 @@ describe("Atlas SDK unit tests", () => { const callChainHash = getCallChainHash(testUserOperation, []); expect(callChainHash).toBe( - "0x1feca496343f60c6fd5bfa97ec935fed62285b814ef720ac633dabb1c6e25777" + "0x1feca496343f60c6fd5bfa97ec935fed62285b814ef720ac633dabb1c6e25777", ); }); test("user operation EIP712 signature", async () => { const signer = HDNodeWallet.fromSeed( - toUtf8Bytes("bad seed used for this test only") + toUtf8Bytes("bad seed used for this test only"), ); const signature = await signer.signTypedData( chainConfig[0].eip712Domain, testUserOperation.toTypedDataTypes(), - testUserOperation.toTypedDataValues() + testUserOperation.toTypedDataValues(), ); expect(signature).toBe( - "0x986094e219f2be26c49bb641ad43a35a7d8b1adf61adf99b21bc85cd72cc562c5fff66b7f7a4241bdea26366ea49e873fb1521bfda86e01e16a778be5c5cce591c" + "0x986094e219f2be26c49bb641ad43a35a7d8b1adf61adf99b21bc85cd72cc562c5fff66b7f7a4241bdea26366ea49e873fb1521bfda86e01e16a778be5c5cce591c", ); }); @@ -119,23 +119,23 @@ describe("Atlas SDK unit tests", () => { }); expect(() => - testUserOperation.validateSignature(chainConfig[0].eip712Domain) + testUserOperation.validateSignature(chainConfig[0].eip712Domain), ).not.toThrow(); }); test("dApp operation EIP712 signature", async () => { const signer = HDNodeWallet.fromSeed( - toUtf8Bytes("bad seed used for this test only") + toUtf8Bytes("bad seed used for this test only"), ); const signature = await signer.signTypedData( chainConfig[0].eip712Domain, testDAppOperation.toTypedDataTypes(), - testDAppOperation.toTypedDataValues() + testDAppOperation.toTypedDataValues(), ); expect(signature).toBe( - "0x32ec3b06562e1180b8755e4fba47111a879c2d22f99141379bf0a34adcce73a75140677b50fa599adbdd8324de927460fd83f5f8658e6771df75e36597da86e41c" + "0x32ec3b06562e1180b8755e4fba47111a879c2d22f99141379bf0a34adcce73a75140677b50fa599adbdd8324de927460fd83f5f8658e6771df75e36597da86e41c", ); }); @@ -147,7 +147,7 @@ describe("Atlas SDK unit tests", () => { }); expect(() => - testDAppOperation.validateSignature(chainConfig[0].eip712Domain) + testDAppOperation.validateSignature(chainConfig[0].eip712Domain), ).not.toThrow(); }); }); diff --git a/tsconfig.json b/tsconfig.json index 81bf6ab..1aa2192 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "target": "es2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ @@ -26,7 +26,7 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ + "module": "commonjs" /* Specify what module code is generated. */, // "rootDir": "./", /* Specify the root folder within your source files. */ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ @@ -40,7 +40,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ - "resolveJsonModule": true, /* Enable importing .json files. */ + "resolveJsonModule": true /* Enable importing .json files. */, // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ @@ -50,13 +50,13 @@ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ /* Emit */ - "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */, // "declarationMap": true, /* Create sourcemaps for d.ts files. */ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - "outDir": "./dist", /* Specify an output folder for all emitted files. */ + "outDir": "./dist" /* Specify an output folder for all emitted files. */, // "removeComments": true, /* Disable emitting comments. */ // "noEmit": true, /* Disable emitting files from a compilation. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ @@ -78,12 +78,12 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ + "strict": true /* Enable all strict type-checking options. */, // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ @@ -105,6 +105,6 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ } }