diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 9511148c..00000000 --- a/.eslintrc.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "env": { - "browser": true, - "es6": true - }, - "extends": "eslint:recommended", - "parser": "vue-eslint-parser", - "parserOptions": { - "parser": "babel-eslint", - "sourceType": "module", - "allowImportExportEverywhere": false - }, - "rules": { - "func-names": 0, - "no-nested-ternary": 0, - "max-len": 0, - "arrow-parens": ["error", "always"], - "no-underscore-dangle": 0, - "comma-dangle": ["error", { - "arrays": "always-multiline", - "objects": "always-multiline", - "imports": "always-multiline", - "exports": "always-multiline", - "functions": "never" - }], - "no-use-before-define": ["error", "nofunc"], - "no-empty": ["error", { "allowEmptyCatch": true }], - "no-mixed-operators": ["error", { "allowSamePrecedence": true }], - "indent": ["error", 4, { "flatTernaryExpressions": true, "SwitchCase": 1 }] - }, - "overrides": [{ - "files": ["**/*.ts"], - "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint"], - "extends": ["plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended"], - "rules": { - "@typescript-eslint/ban-ts-comment": "off" - } - }] -} \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 00000000..a3595a1b --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,86 @@ +import globals from "globals"; +import parser from "vue-eslint-parser"; +import typescriptEslint from "@typescript-eslint/eslint-plugin"; +import tsParser from "@typescript-eslint/parser"; +import path from "node:path"; +import {fileURLToPath} from "node:url"; +import js from "@eslint/js"; +import {FlatCompat} from "@eslint/eslintrc"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all +}); + +export default [...compat.extends("eslint:recommended"), { + languageOptions: { + globals: { + ...globals.browser, + }, + + parser: parser, + ecmaVersion: 5, + sourceType: "module", + + parserOptions: { + parser: "babel-eslint", + allowImportExportEverywhere: false, + }, + }, + + rules: { + "func-names": 0, + "no-nested-ternary": 0, + "max-len": 0, + "arrow-parens": ["error", "always"], + "no-underscore-dangle": 0, + + "comma-dangle": ["error", { + arrays: "always-multiline", + objects: "always-multiline", + imports: "always-multiline", + exports: "always-multiline", + functions: "never", + }], + + "no-use-before-define": ["error", "nofunc"], + + "no-empty": ["error", { + allowEmptyCatch: true, + }], + + "no-mixed-operators": ["error", { + allowSamePrecedence: true, + }], + + indent: ["error", 4, { + flatTernaryExpressions: true, + SwitchCase: 1, + }], + }, +}, ...compat.extends( + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", +).map(config => ({ + ...config, + files: ["**/*.ts"], +})), { + files: ["**/*.ts"], + + plugins: { + "@typescript-eslint": typescriptEslint, + }, + + languageOptions: { + parser: tsParser, + }, + + rules: { + "@typescript-eslint/ban-ts-comment": "warn", + "@typescript-eslint/no-unused-vars": "warn", + "@typescript-eslint/no-explicit-any": "warn", + }, +}]; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index e252fdac..53641559 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ }, "devDependencies": { "@babel/eslint-parser": "^7.25.1", - "@nomicfoundation/hardhat-ethers": "^3.0.8", + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "^9.9.1", "@types/chai": "^4.3.18", "@types/memoizee": "^0.4.11", "@types/mocha": "^10.0.7", @@ -25,6 +26,7 @@ "@typescript-eslint/parser": "^8.2.0", "chai": "^5.1.1", "eslint": "^9.9.1", + "globals": "^15.9.0", "hardhat": "^2.22.10", "mocha": "^10.7.3", "typescript": "^5.5.4", @@ -332,6 +334,17 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/traverse/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/types": { "version": "7.25.6", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.6.tgz", @@ -1343,21 +1356,6 @@ "setimmediate": "^1.0.5" } }, - "node_modules/@nomicfoundation/hardhat-ethers": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/@nomicfoundation/hardhat-ethers/-/hardhat-ethers-3.0.8.tgz", - "integrity": "sha512-zhOZ4hdRORls31DTOqg+GmEZM0ujly8GGIuRY7t7szEk2zW/arY1qDug/py8AEktT00v5K+b6RvbVog+va51IA==", - "dev": true, - "license": "MIT", - "dependencies": { - "debug": "^4.1.1", - "lodash.isequal": "^4.5.0" - }, - "peerDependencies": { - "ethers": "^6.1.0", - "hardhat": "^2.0.0" - } - }, "node_modules/@nomicfoundation/solidity-analyzer": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer/-/solidity-analyzer-0.1.2.tgz", @@ -3755,14 +3753,16 @@ } }, "node_modules/globals": { - "version": "11.12.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", - "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "version": "15.9.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.9.0.tgz", + "integrity": "sha512-SmSKyLLKFbSr6rptvP8izbyxJL4ILwqO9Jg23UA0sDlGlu58V59D1//I3vlc0KJphVdUR7vMjHIplYnzBxorQA==", "dev": true, "license": "MIT", - "peer": true, "engines": { - "node": ">=4" + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/graceful-fs": { @@ -4379,13 +4379,6 @@ "dev": true, "license": "MIT" }, - "node_modules/lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==", - "dev": true, - "license": "MIT" - }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", diff --git a/package.json b/package.json index d4aacbe7..5bef852d 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,13 @@ "scripts": { "build": "rm -rf lib && tsc -p tsconfig.build.json", "test": "tsc && mocha dist/test", - "lint": "eslint src --ext .ts" + "lint": "eslint src" }, "type": "module", "devDependencies": { "@babel/eslint-parser": "^7.25.1", + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "^9.9.1", "@types/chai": "^4.3.18", "@types/memoizee": "^0.4.11", "@types/mocha": "^10.0.7", @@ -29,6 +31,7 @@ "@typescript-eslint/parser": "^8.2.0", "chai": "^5.1.1", "eslint": "^9.9.1", + "globals": "^15.9.0", "hardhat": "^2.22.10", "mocha": "^10.7.3", "typescript": "^5.5.4", diff --git a/src/external-api.ts b/src/external-api.ts index 67907433..f86f6288 100644 --- a/src/external-api.ts +++ b/src/external-api.ts @@ -95,7 +95,7 @@ export const _getFactoryAPYs = memoize( const [{data: data0}, {data: data1}] = await Promise.all([ fetch(urlStable), fetch(urlCrypto), - ].map(r => r.then(r => r.json() as any))); + ].map((r) => r.then((r) => r.json() as any))); const stableVolume = data0.totalVolumeUsd || data0.totalVolume || 0; const cryptoVolume = data1.totalVolumeUsd || data1.totalVolume || 0; @@ -104,12 +104,12 @@ export const _getFactoryAPYs = memoize( address: item.poolAddress, volumeUSD: item.totalVolumeUsd ?? 0, day: item.apy ?? 0, - week: item.apy * 7 ?? 0, //Because api does not return week apy + week: (item.apy ?? 0) * 7, //Because api does not return week apy })) return { poolsData: poolsData ?? [], - totalVolume: stableVolume + cryptoVolume ?? 0, + totalVolume: stableVolume + cryptoVolume, cryptoVolume: cryptoVolume ?? 0, cryptoShare: 100*cryptoVolume/(stableVolume + cryptoVolume) || 0, }; diff --git a/src/router.ts b/src/router.ts index 9fac396f..85ca42e8 100644 --- a/src/router.ts +++ b/src/router.ts @@ -259,7 +259,7 @@ const _getBestRoute = memoize( const [gasAmounts, outputCoinUsdRate, {data: gasData}, ethUsdRate] = await Promise.all([ _estimateGasForDifferentRoutes(routes.map((r) => r.route), inputCoinAddress, outputCoinAddress, _amount), _getUsdRate(outputCoinAddress), - fetch("https://api.curve.fi/api/getGas").then(r => r.json() as any), + fetch("https://api.curve.fi/api/getGas").then((r) => r.json() as any), _getUsdRate(ETH_ADDRESS), ]); const gasPrice = gasData.gas.standard;