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

Add ESLint rule for BN imports #197

Merged
merged 5 commits into from
Sep 20, 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
15 changes: 0 additions & 15 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,4 @@

. "$(dirname -- "$0")/_/husky.sh"

TARGET_FOLDER="packages/distributor/solana/generated"

OS=$(uname)

echo "Replacing 'BN' with 'BigNumber' in $TARGET_FOLDER and its subfolders"
if [ "$OS" = "Darwin" ]; then
SED_NO_BACKUP=( -i '' )
else
SED_NO_BACKUP=( -i )
fi

find "$TARGET_FOLDER" -type f -name "*.ts" -exec sed "${SED_NO_BACKUP[@]}" -e 's/BN/BigNumber/g' -e 's/bn/bignumber/g' {} +

git add $TARGET_FOLDER

npm run lint
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"packages": [
"packages/*"
],
"version": "7.0.0-alpha.2",
"version": "7.0.0-alpha.3",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"local-publish": "lerna publish --no-git-tag-version --no-push --registry=\"http://localhost:4873/\" from-package --yes",
"local-unpublish": "lerna exec -- npm unpublish --registry=\"http://localhost:4873/\" \"\\${LERNA_PACKAGE_NAME}@\\$(npm view \\$LERNA_PACKAGE_NAME version)\"",
"local-unpublish-all": "lerna exec -- npm unpublish -f --registry=\"http://localhost:4873/\" \"\\${LERNA_PACKAGE_NAME}\"",
"prepare": "husky install"
"prepare": "husky install",
"convert-bn": "./scripts/convertBN.sh"
},
"devDependencies": {
"@types/eslint": "^8.56.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/common",
"version": "7.0.0-alpha.2",
"version": "7.0.0-alpha.3",
"description": "Common utilities and types used by streamflow packages.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "./dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/distributor/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as StreamflowDistributorSolana from "./solana";
export * as StreamflowDistributorSolana from "./solana/index.js";
2 changes: 1 addition & 1 deletion packages/distributor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/distributor",
"version": "7.0.0-alpha.2",
"version": "7.0.0-alpha.3",
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/esm/index.js",
Expand Down
12 changes: 6 additions & 6 deletions packages/distributor/solana/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export { default as SolanaDistributorClient } from "./client";

export * from "./generated/accounts";
export * from "./generated/accounts/index.js";

export * from "./generated/errors";
export * from "./generated/errors/index.js";

export * from "./generated/instructions";
export * from "./generated/instructions/index.js";

export * from "./utils";
export * from "./utils.js";

export * from "./types";
export * from "./types.js";

export * as constants from "./constants";
export * as constants from "./constants.js";
7 changes: 4 additions & 3 deletions packages/distributor/solana/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
import { Keypair } from "@solana/web3.js";
import { ITransactionResult } from "@streamflow/common";
import { ITransactionSolanaExt } from "@streamflow/common/solana";
import BigNumber from "bignumber.js";

export interface IInteractSolanaExt extends ITransactionSolanaExt {
invoker: SignerWalletAdapter | Keypair;
Expand All @@ -16,7 +17,7 @@ export interface ICreateDistributorData {
version: number;

root: Array<number>;
maxTotalClaim: number | string;
maxTotalClaim: BigNumber;
maxNumNodes: number | string;
unlockPeriod: number;
startVestingTs: number;
Expand All @@ -28,8 +29,8 @@ export interface ICreateDistributorData {
export interface IClaimData {
id: string;

amountUnlocked: number | string;
amountLocked: number | string;
amountUnlocked: BigNumber;
amountLocked: BigNumber;
proof: Array<Array<number>>;
}

Expand Down
7 changes: 7 additions & 0 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ module.exports = {
},
ignorePatterns: ["**/dist/**/*"],
rules: {
"no-restricted-imports": [
"error",
{
name: "bn.js",
message: "We no longer use BN.js for big number calculations. Switch to using bignumber.js instead. Run pnpm run convert-bn to automatically switch BN to BigNumber in all folders"
}
],
"prettier/prettier": [
"error",
{
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/eslint-config",
"version": "7.0.0-alpha.2",
"version": "7.0.0-alpha.3",
"license": "ISC",
"main": "index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/stream/__tests__/aptos/streamClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("AptosStreamClient", () => {
recipient: "0xtest",
amount: BigNumber(1000),
name: "test name",
cliffAmount: 1,
cliffAmount: BigNumber(1),
amountPerPeriod: BigNumber(1),
};
const mockData = {
Expand Down
6 changes: 3 additions & 3 deletions packages/stream/aptos/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { default, default as AptosStreamClient } from "./StreamClient.js";

export * from "./utils";
export * from "./utils.js";

export * from "./types";
export * from "./types.js";

export * as constants from "./constants";
export * as constants from "./constants.js";
13 changes: 9 additions & 4 deletions packages/stream/common/GenericStreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ import {
IGetFeesData,
} from "./types.js";
import { handleContractError } from "./utils.js";
import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos";
import { EvmStreamClient } from "../evm";
import { SolanaStreamClient, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana";
import { ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters, SuiStreamClient } from "../sui";
import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos/index.js";
import { EvmStreamClient } from "../evm/index.js";
import {
SolanaStreamClient,
ICreateStreamSolanaExt,
IInteractStreamSolanaExt,
ITopUpStreamSolanaExt,
} from "../solana/index.js";
import { ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters, SuiStreamClient } from "../sui/index.js";
import { WITHDRAW_AVAILABLE_AMOUNT } from "./constants.js";

export interface SolanaStreamClientOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/stream/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IRecipient {
recipient: string;
amount: BigNumber;
name: string;
cliffAmount: string | number;
cliffAmount: BigNumber;
amountPerPeriod: BigNumber;
}

Expand Down
18 changes: 9 additions & 9 deletions packages/stream/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export * as StreamflowAptos from "./aptos";
export * as StreamflowEVM from "./evm";
export * as StreamflowSolana from "./solana";
export * as StreamflowSui from "./sui";
export * as StreamflowAptos from "./aptos/index.js";
export * as StreamflowEVM from "./evm/index.js";
export * as StreamflowSolana from "./solana/index.js";
export * as StreamflowSui from "./sui/index.js";

export * from "./common/types";
export * from "./common/utils";
export * from "./common/constants";
export * from "./common/contractUtils";
export * from "./common/types.js";
export * from "./common/utils.js";
export * from "./common/constants.js";
export * from "./common/contractUtils.js";

export { default as GenericStreamClient } from "./common/GenericStreamClient";
export { default as GenericStreamClient } from "./common/GenericStreamClient.js";
2 changes: 1 addition & 1 deletion packages/stream/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/stream",
"version": "7.0.0-alpha.2",
"version": "7.0.0-alpha.3",
"description": "JavaScript SDK to interact with Streamflow protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "./dist/esm/index.js",
Expand Down
21 changes: 21 additions & 0 deletions scripts/convertBN.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

if [ $# -eq 0 ]; then
TARGET_FOLDERS="packages"
else
TARGET_FOLDERS=$@
fi

OS=$(uname)

if [ "$OS" = "Darwin" ]; then
SED_NO_BACKUP=( -i '' )
else
SED_NO_BACKUP=( -i )
fi

for FOLDER in $TARGET_FOLDERS
do
echo "Replacing 'BN' with 'BigNumber' in $FOLDER and its subfolders"
find "$FOLDER" -type f -name "*.ts[x]" -exec sed "${SED_NO_BACKUP[@]}" -e 's/BN/BigNumber/g' -e 's/bn/bignumber/g' {} +
done
Loading