Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce Import Order #47

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"tabWidth": 2,
"useTabs": false,
"endOfLine": "lf"
}
}
14 changes: 14 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const tsPlugin = require("@typescript-eslint/eslint-plugin");
const tsParser = require("@typescript-eslint/parser");
const js = require("@eslint/js");
const importPlugin = require("eslint-plugin-import");


module.exports = Object.assign({}, js.configs.recommended, {
files: ["**/*.ts", "**/*.tsx"],
Expand All @@ -15,6 +17,7 @@ module.exports = Object.assign({}, js.configs.recommended, {
},
plugins: {
"@typescript-eslint": tsPlugin,
"import": importPlugin, // Add import plugin
},
ignores: ["node_modules/*"],
rules: Object.assign({}, tsPlugin.configs.rules, {
Expand All @@ -29,5 +32,16 @@ module.exports = Object.assign({}, js.configs.recommended, {
allowTypedFunctionExpressions: true,
},
],
"import/order": [
"error",
{
"groups": [
["builtin", "external"],
["internal", "parent", "sibling", "index"]
],
"newlines-between": "always",
"alphabetize": { "order": "asc", "caseInsensitive": true }
}
],
}),
});
1 change: 1 addition & 0 deletions examples/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import yargs from "yargs";
import { hideBin } from "yargs/helpers";

import { UserOptions } from "../src";

interface ScriptEnv {
Expand Down
3 changes: 2 additions & 1 deletion examples/send-tx.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import dotenv from "dotenv";
import { ethers } from "ethers";
import { setupAdapter } from "near-ca";

import { loadArgs, loadEnv } from "./cli";
import { TransactionManager } from "../src";
import { setupAdapter } from "near-ca";

dotenv.config();

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"example": "tsx examples/send-tx.ts",
"lint": "eslint . --ignore-pattern dist/",
"test": "jest",
"fmt": "prettier --write '{src,examples,tests}/**/*.{js,jsx,ts,tsx}'",
"fmt": "prettier --write '{src,examples,tests}/**/*.{js,jsx,ts,tsx}' && yarn lint --fix",
"all": "yarn fmt && yarn lint && yarn build"
},
"dependencies": {
Expand All @@ -56,6 +56,7 @@
"@typescript-eslint/parser": "^8.1.0",
"dotenv": "^16.4.5",
"eslint": "^9.6.0",
"eslint-plugin-import": "^2.30.0",
"jest": "^29.7.0",
"prettier": "^3.3.2",
"ts-jest": "^29.1.5",
Expand Down
7 changes: 4 additions & 3 deletions src/lib/bundler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// TODO: Ethers dependency is only for Generic HTTP Provider
import { ethers } from "ethers";
import { toHex } from "viem";

import {
GasPrices,
PaymasterData,
UnsignedUserOperation,
UserOperation,
UserOperationReceipt,
} from "../types.js";
import { PLACEHOLDER_SIG } from "../util.js";
import { toHex } from "viem";
} from "../types";
import { PLACEHOLDER_SIG } from "../util";

function bundlerUrl(chainId: number, apikey: string): string {
return `https://api.pimlico.io/v2/${chainId}/rpc?apikey=${apikey}`;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/multisend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
parseAbi,
size,
} from "viem";

import { MetaTransaction, OperationType } from "../types";

export const MULTI_SEND_ABI = ["function multiSend(bytes memory transactions)"];
Expand All @@ -31,7 +32,7 @@ const encodeMetaTx = (tx: MetaTransaction): Hex =>
]
);

const remove0x = (hexString: Hex) => hexString.slice(2);
const remove0x = (hexString: Hex): string => hexString.slice(2);

// Encodes a batch of module transactions into a single multiSend module transaction.
// A module transaction is an object with fields corresponding to a Gnosis Safe's (i.e., Zodiac IAvatar's) `execTransactionFromModule` method parameters.
Expand Down
7 changes: 4 additions & 3 deletions src/lib/safe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ethers } from "ethers";
import {
getProxyFactoryDeployment,
getSafeL2SingletonDeployment,
Expand All @@ -7,14 +6,16 @@ import {
getSafe4337ModuleDeployment,
getSafeModuleSetupDeployment,
} from "@safe-global/safe-modules-deployments";
import { PLACEHOLDER_SIG, packGas, packPaymasterData } from "../util";
import { ethers } from "ethers";
import { Address, Hash, Hex } from "viem";

import {
GasPrice,
MetaTransaction,
UnsignedUserOperation,
UserOperation,
} from "../types";
import { Address, Hash, Hex } from "viem";
import { PLACEHOLDER_SIG, packGas, packPaymasterData } from "../util";

/**
* All contracts used in account creation & execution
Expand Down
11 changes: 6 additions & 5 deletions src/tx-manager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FinalExecutionOutcome } from "near-api-js/lib/providers";
import {
NearEthAdapter,
NearEthTxData,
Expand All @@ -6,13 +7,13 @@ import {
setupAdapter,
signatureFromOutcome,
} from "near-ca";
import { Erc4337Bundler } from "./lib/bundler";
import { packSignature } from "./util";
import { MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
import { ContractSuite } from "./lib/safe";
import { Address, Hash, Hex, serializeSignature } from "viem";
import { FinalExecutionOutcome } from "near-api-js/lib/providers";

import { Erc4337Bundler } from "./lib/bundler";
import { encodeMulti } from "./lib/multisend";
import { ContractSuite } from "./lib/safe";
import { MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
import { packSignature } from "./util";

export class TransactionManager {
readonly nearAdapter: NearEthAdapter;
Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PaymasterData, MetaTransaction } from "./types.js";
import { Hex, concatHex, encodePacked, toHex } from "viem";

import { PaymasterData, MetaTransaction } from "./types";

export const PLACEHOLDER_SIG = encodePacked(["uint48", "uint48"], [0, 0]);

type IntLike = Hex | bigint | string | number;
Expand Down
3 changes: 2 additions & 1 deletion tests/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ethers } from "ethers";

import { PaymasterData } from "../src";
import {
PLACEHOLDER_SIG,
containsValue,
packGas,
packPaymasterData,
packSignature,
} from "../src/util";
import { PaymasterData } from "../src";

describe("Utility Functions (mostly byte packing)", () => {
it("PLACE_HOLDER_SIG", () => {
Expand Down
Loading