diff --git a/.husky/pre-commit b/.husky/pre-commit index 60dcf560..885180d0 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -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 \ No newline at end of file diff --git a/lerna.json b/lerna.json index 32b8a870..ee419d20 100644 --- a/lerna.json +++ b/lerna.json @@ -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" } diff --git a/package.json b/package.json index 76700cab..a6fa3650 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/common/package.json b/packages/common/package.json index c9704af5..8e274f11 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -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", diff --git a/packages/distributor/index.ts b/packages/distributor/index.ts index 3dbc71c1..8e99b028 100644 --- a/packages/distributor/index.ts +++ b/packages/distributor/index.ts @@ -1 +1 @@ -export * as StreamflowDistributorSolana from "./solana"; +export * as StreamflowDistributorSolana from "./solana/index.js"; diff --git a/packages/distributor/package.json b/packages/distributor/package.json index 076cd325..88341b3a 100644 --- a/packages/distributor/package.json +++ b/packages/distributor/package.json @@ -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", diff --git a/packages/distributor/solana/index.ts b/packages/distributor/solana/index.ts index cf2677fc..7b4364c3 100644 --- a/packages/distributor/solana/index.ts +++ b/packages/distributor/solana/index.ts @@ -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"; diff --git a/packages/distributor/solana/types.ts b/packages/distributor/solana/types.ts index 113b1562..b0bc1ff4 100644 --- a/packages/distributor/solana/types.ts +++ b/packages/distributor/solana/types.ts @@ -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; @@ -16,7 +17,7 @@ export interface ICreateDistributorData { version: number; root: Array; - maxTotalClaim: number | string; + maxTotalClaim: BigNumber; maxNumNodes: number | string; unlockPeriod: number; startVestingTs: number; @@ -28,8 +29,8 @@ export interface ICreateDistributorData { export interface IClaimData { id: string; - amountUnlocked: number | string; - amountLocked: number | string; + amountUnlocked: BigNumber; + amountLocked: BigNumber; proof: Array>; } diff --git a/packages/eslint-config/index.js b/packages/eslint-config/index.js index cf5686c9..3ed32595 100644 --- a/packages/eslint-config/index.js +++ b/packages/eslint-config/index.js @@ -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", { diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index e377acea..d6e334ad 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -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": [ diff --git a/packages/stream/__tests__/aptos/streamClient.spec.ts b/packages/stream/__tests__/aptos/streamClient.spec.ts index 2816dc36..fc57fcf9 100644 --- a/packages/stream/__tests__/aptos/streamClient.spec.ts +++ b/packages/stream/__tests__/aptos/streamClient.spec.ts @@ -42,7 +42,7 @@ describe("AptosStreamClient", () => { recipient: "0xtest", amount: BigNumber(1000), name: "test name", - cliffAmount: 1, + cliffAmount: BigNumber(1), amountPerPeriod: BigNumber(1), }; const mockData = { diff --git a/packages/stream/aptos/index.ts b/packages/stream/aptos/index.ts index 213ed604..791d6914 100644 --- a/packages/stream/aptos/index.ts +++ b/packages/stream/aptos/index.ts @@ -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"; diff --git a/packages/stream/common/GenericStreamClient.ts b/packages/stream/common/GenericStreamClient.ts index 6022e2be..8b2386a3 100644 --- a/packages/stream/common/GenericStreamClient.ts +++ b/packages/stream/common/GenericStreamClient.ts @@ -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 { diff --git a/packages/stream/common/types.ts b/packages/stream/common/types.ts index d41baa72..3a0d8c04 100644 --- a/packages/stream/common/types.ts +++ b/packages/stream/common/types.ts @@ -9,7 +9,7 @@ export interface IRecipient { recipient: string; amount: BigNumber; name: string; - cliffAmount: string | number; + cliffAmount: BigNumber; amountPerPeriod: BigNumber; } diff --git a/packages/stream/index.ts b/packages/stream/index.ts index 3f0a48c4..d5bf6067 100644 --- a/packages/stream/index.ts +++ b/packages/stream/index.ts @@ -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"; diff --git a/packages/stream/package.json b/packages/stream/package.json index b3662455..fe53c3e9 100644 --- a/packages/stream/package.json +++ b/packages/stream/package.json @@ -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", diff --git a/scripts/convertBN.sh b/scripts/convertBN.sh new file mode 100755 index 00000000..22555288 --- /dev/null +++ b/scripts/convertBN.sh @@ -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