diff --git a/.circleci/config.yml b/.circleci/config.yml index 989c109..44caca4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -50,4 +50,4 @@ workflows: - test: matrix: parameters: - node-version: ['20.8', '18.12', '16.18'] \ No newline at end of file + node-version: ['18.12', '16.18'] \ No newline at end of file diff --git a/README.md b/README.md index dd3905e..4039dd7 100644 --- a/README.md +++ b/README.md @@ -117,26 +117,12 @@ interface EthersModuleOptions { */ quorum?: number; - /** - * Optional parameter if this option is false, EthersModule won't wait until - * the providers are ready. If this option is true, EthersModule will wait - * until the network has heen established for all the providers. - * @see {@link https://docs.ethers.io/v5/api/providers/provider/#Provider-ready} - */ - waitUntilIsConnected?: boolean; - /** * Optional parameter if this option is false, EthersModule will try to connect * with the credentials provided in options. If you define more than one provider, * EthersModule will use the FallbackProvider to send multiple requests simultaneously. */ useDefaultProvider?: boolean; - - /** - * Optional parameter if this option is true, EthersModule will disable - * the console.log in the ethers.js library. - */ - disableEthersLogger?: boolean /** * Optional parameter to associate a token name to EthersProvider, diff --git a/package-lock.json b/package-lock.json index 946ca38..4171d9f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@nestjs/core": "^10.2.7", "@nestjs/platform-express": "^10.2.7", "@nestjs/platform-fastify": "^10.2.7", - "@types/node": "^20.8.4", + "@types/node": "^18.11.9", "@types/supertest": "^2.0.14", "@typescript-eslint/eslint-plugin": "^6.7.5", "@typescript-eslint/parser": "^6.7.5", @@ -27,11 +27,11 @@ "prettier": "^3.0.3", "rxjs": "^7.8.1", "supertest": "^6.3.3", - "tap": "^18.5.0", + "tap": "^18.5.1", "typescript": "^5.2.2" }, "engines": { - "node": "^16.x || >=18.x || >=20.x" + "node": "^16.x || >=18.x" }, "peerDependencies": { "@nestjs/common": "^10.2.7", @@ -327,6 +327,55 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, + "node_modules/@isaacs/ts-node-temp-fork-for-pr-2009": { + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/@isaacs/ts-node-temp-fork-for-pr-2009/-/ts-node-temp-fork-for-pr-2009-10.9.1.tgz", + "integrity": "sha512-MY4rUonz835NsTbd4dcgKZvZFYX9IkLnYFZV9M7GQV8t39fawafLin/Qw6VXD4yfMs4HcBq8P3ddeU0QHMH1YQ==", + "dev": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node14": "*", + "@tsconfig/node16": "*", + "@tsconfig/node18": "*", + "@tsconfig/node20": "*", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=4.2" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/@isaacs/ts-node-temp-fork-for-pr-2009/node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/@istanbuljs/schema": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz", @@ -911,9 +960,9 @@ } }, "node_modules/@tapjs/after": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/@tapjs/after/-/after-1.1.11.tgz", - "integrity": "sha512-nZrcqm+yaCjzWQSjejiL259ZgI5kg7K4mKIgvGMTwArujjl3fhjCd2TashlO7VViAOPD6TejHpnQ71K3jdIICw==", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/@tapjs/after/-/after-1.1.12.tgz", + "integrity": "sha512-I1p8j3GJdgticIdi/ADYmDnjcpdk+5gXGwcoPoxQXsusXtXf6Icj/rjnVEY8l33DSsQXEG24ZeDmLApskuIFpA==", "dev": true, "dependencies": { "is-actual-promise": "^1.0.0" @@ -922,13 +971,13 @@ "node": ">=16" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/after-each": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/@tapjs/after-each/-/after-each-1.1.11.tgz", - "integrity": "sha512-GomQuVFcV8HlDkqOojlDGdcdEIQwPW6r6YMqJ+IRuH/wjdjtWv8LsxPWqavzkE2VqwJYi6H7Aik2XBLCJnxTaw==", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/@tapjs/after-each/-/after-each-1.1.12.tgz", + "integrity": "sha512-7BNGvx3KlSZ0t6CEHWhHezwAvrF8xWK2tuPqXy1N5TVXdkc0+PQv8tYkKuep0VHcMOI1t8uZ5rdTlzZulpfe8w==", "dev": true, "dependencies": { "function-loop": "^4.0.0" @@ -937,16 +986,16 @@ "node": ">=16" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/asserts": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/@tapjs/asserts/-/asserts-1.1.11.tgz", - "integrity": "sha512-ofV/Z1Ix+PV9Lw6UETicmnJqjFTZe+gG9dlGXJ1o0+Tobm9jV6yiPrcA4OGXCJwEN5C5v/bDXj+Vvgg80o9qMQ==", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/@tapjs/asserts/-/asserts-1.1.12.tgz", + "integrity": "sha512-E8DmpbDiR8xTh098GXwEr7/xPO5/Sm7Ume33KzOvVSTCPEv2fCqegKOh4gNeL3HF0BqhGnndj7mPaOgF0gtrfA==", "dev": true, "dependencies": { - "@tapjs/stack": "1.2.5", + "@tapjs/stack": "1.2.6", "is-actual-promise": "^1.0.0", "tcompare": "6.4.3", "trivial-deferred": "^2.0.0" @@ -958,13 +1007,13 @@ "url": "https://github.com/sponsors/isaacs" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/before": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/@tapjs/before/-/before-1.1.11.tgz", - "integrity": "sha512-YkpLW8JhuNFHTeLaBTAi8nQhQJyVgkah9vL3oVrUt0kANjCXWbU1Nd+NtzUwukn8S/b4h1F2lEM/ZE5R921uqQ==", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/@tapjs/before/-/before-1.1.12.tgz", + "integrity": "sha512-nfwPqwkYWgHr5SI2xK6ExWyX+FsCOIh0DrPp2ZUKT1UrD0+11sREwPD0XMv7TtFJ9AIu00imEmrlYZdaL6cDUA==", "dev": true, "dependencies": { "is-actual-promise": "^1.0.0" @@ -973,13 +1022,13 @@ "node": ">=16" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/before-each": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/@tapjs/before-each/-/before-each-1.1.11.tgz", - "integrity": "sha512-FElvqZvbQ6dwYsK8fxjLTrEema30m8hJWT+hBN37Uu+wvnrqZxyksx+YFH+vvq2seHWkumphjhxwEE0D36dPWA==", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/@tapjs/before-each/-/before-each-1.1.12.tgz", + "integrity": "sha512-9Qa8ykkeklVY4mFirdlZlvDCJvlm6BwU4TqlnTRjWoADBLEOcZi8dcjaLhNsdv1DBcny+aK6Db51gcQkUK4OLA==", "dev": true, "dependencies": { "function-loop": "^4.0.0" @@ -988,17 +1037,17 @@ "node": ">=16" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/config": { - "version": "2.4.7", - "resolved": "https://registry.npmjs.org/@tapjs/config/-/config-2.4.7.tgz", - "integrity": "sha512-R1xWvaCgJEz42MPPTJYobb5froVin259IxaX3Q0lvAz8FV9+Z5+IM0jR/voivADKMMyfw6gz5LoQnujm0bMPBw==", + "version": "2.4.8", + "resolved": "https://registry.npmjs.org/@tapjs/config/-/config-2.4.8.tgz", + "integrity": "sha512-tIQ/nv3Fr2sV7JUtQyHtQV0WS9xJSN25Q85wBfqxsSgz/JuuK46rNubB0MNkJ3nxupCIItc8MYVxNyHB+n+28w==", "dev": true, "dependencies": { - "@tapjs/core": "1.4.0", - "@tapjs/test": "1.3.11", + "@tapjs/core": "1.4.1", + "@tapjs/test": "1.3.12", "chalk": "^5.2.0", "jackspeak": "^2.3.6", "polite-json": "^4.0.1", @@ -1012,8 +1061,8 @@ "url": "https://github.com/sponsors/isaacs" }, "peerDependencies": { - "@tapjs/core": "1.4.0", - "@tapjs/test": "1.3.11" + "@tapjs/core": "1.4.1", + "@tapjs/test": "1.3.12" } }, "node_modules/@tapjs/config/node_modules/chalk": { @@ -1029,14 +1078,14 @@ } }, "node_modules/@tapjs/core": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@tapjs/core/-/core-1.4.0.tgz", - "integrity": "sha512-rbSqasC3rn7tK0UL7/dRPA+QDxz2oWcJ7ImThntsEfQTICoHG+4y2TdPcrRUbX5ntsnYFdUL2RO36nPD0OVCHg==", + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/@tapjs/core/-/core-1.4.1.tgz", + "integrity": "sha512-EApY3r/8bLRmgHF/2V0X0TK2lzbXqYxHsbdoOiDlSB/P98IFDYKVAefu+IhOItvoVM4kT4J7qOCLVKl77eutvA==", "dev": true, "dependencies": { "@tapjs/processinfo": "^3.1.4", - "@tapjs/stack": "1.2.5", - "@tapjs/test": "1.3.11", + "@tapjs/stack": "1.2.6", + "@tapjs/test": "1.3.12", "async-hook-domain": "^4.0.1", "diff": "^5.1.0", "is-actual-promise": "^1.0.0", @@ -1079,9 +1128,9 @@ } }, "node_modules/@tapjs/filter": { - "version": "1.2.11", - "resolved": "https://registry.npmjs.org/@tapjs/filter/-/filter-1.2.11.tgz", - "integrity": "sha512-6PWVQHRtpzFxfz2n03OKCU6NKYpzveIEj0n8kpiCCwK27oHCauoSeeann6HEnVJ8NGKG6sPxruyqtpKRQOPuEg==", + "version": "1.2.12", + "resolved": "https://registry.npmjs.org/@tapjs/filter/-/filter-1.2.12.tgz", + "integrity": "sha512-0Yh9CeAUkoxp/3hl1u8Zh2GaW9x90n2O6IxOWtteuImdgiSBDwcmXtcDz+gkdZmWEexU/QRHct6Y0tZ1X8lXwg==", "dev": true, "engines": { "node": ">=16" @@ -1090,13 +1139,13 @@ "url": "https://github.com/sponsors/isaacs" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/fixture": { - "version": "1.2.11", - "resolved": "https://registry.npmjs.org/@tapjs/fixture/-/fixture-1.2.11.tgz", - "integrity": "sha512-cPJE+q0CHZBs5h9a1ecuG6w/R4fvWLB2zftmgmJs4bi1eEYEz+PE3moWH4W0S1lBwxLEn/0SBGJaZN2uf2CLIw==", + "version": "1.2.12", + "resolved": "https://registry.npmjs.org/@tapjs/fixture/-/fixture-1.2.12.tgz", + "integrity": "sha512-w0cswMM107KfVOHCALF6rH4njxeu8iZghdQuehoYLcW9dONArRFQxMRUUXKZBE+2+2jfs1aZELzZJPYfLojsWA==", "dev": true, "dependencies": { "mkdirp": "^3.0.0", @@ -1109,7 +1158,7 @@ "url": "https://github.com/sponsors/isaacs" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/fixture/node_modules/brace-expansion": { @@ -1192,29 +1241,29 @@ } }, "node_modules/@tapjs/intercept": { - "version": "1.2.11", - "resolved": "https://registry.npmjs.org/@tapjs/intercept/-/intercept-1.2.11.tgz", - "integrity": "sha512-PI9yODUV9epfkUOsEq6juZc/9/WcNgHhdqsdzJ765dcoQGJdtawdGiKy8SmD9ClsBMa0Urbn+v5J7h4MYLHSkg==", + "version": "1.2.12", + "resolved": "https://registry.npmjs.org/@tapjs/intercept/-/intercept-1.2.12.tgz", + "integrity": "sha512-Bbpt7hlbsWdQ9CXxCKJ64ObVriFz3o2/1v3iFQbmIft+5ZtRrSzvz5inetW3LjXr6jgt4Fm07HW3bcZ09Laczg==", "dev": true, "dependencies": { - "@tapjs/after": "1.1.11", - "@tapjs/stack": "1.2.5" + "@tapjs/after": "1.1.12", + "@tapjs/stack": "1.2.6" }, "engines": { "node": ">=16" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/mock": { - "version": "1.2.9", - "resolved": "https://registry.npmjs.org/@tapjs/mock/-/mock-1.2.9.tgz", - "integrity": "sha512-DjDOMZ9+RRoAVbjuTZ8PPIO4Yc98iwKEFy36F9ekSEhv37UqQQMeTB2RGqBRzDeX4er0TDjRBI33rmGaxFg6WA==", + "version": "1.2.10", + "resolved": "https://registry.npmjs.org/@tapjs/mock/-/mock-1.2.10.tgz", + "integrity": "sha512-OU12N9gQ/XpRe0mAvkqyfXSXhoB2j0N2LoL1dQ98ygM/UlGFITqqN9Y74QtJWAEPqF5j2Ny9HV9wW7rVrNUCGg==", "dev": true, "dependencies": { - "@tapjs/after": "1.1.11", - "@tapjs/stack": "1.2.5", + "@tapjs/after": "1.1.12", + "@tapjs/stack": "1.2.6", "resolve-import": "^1.4.4", "walk-up-path": "^3.0.1" }, @@ -1225,17 +1274,17 @@ "url": "https://github.com/sponsors/isaacs" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/node-serialize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@tapjs/node-serialize/-/node-serialize-1.2.0.tgz", - "integrity": "sha512-f+Afvh8WoaVoVRKNyKohuK+SSiyIA+fq+G5tp9v0NJgJXD0drGLurrgSbx7axAWT2N0vWUTUAI5Y9BF5blZfuw==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@tapjs/node-serialize/-/node-serialize-1.2.1.tgz", + "integrity": "sha512-pKuPJhzrGYAzw/aUAftDwIpnetpGBcRi8o8M3LR7PN5Hoo25ABi5JlhQHaTHMK/VLZH/Sdu/MM8zZPbUnMLgxQ==", "dev": true, "dependencies": { "@tapjs/error-serdes": "1.2.0", - "@tapjs/stack": "1.2.5", + "@tapjs/stack": "1.2.6", "tap-parser": "15.3.0" }, "engines": { @@ -1245,7 +1294,7 @@ "url": "https://github.com/sponsors/isaacs" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/processinfo": { @@ -1276,13 +1325,13 @@ } }, "node_modules/@tapjs/reporter": { - "version": "1.3.7", - "resolved": "https://registry.npmjs.org/@tapjs/reporter/-/reporter-1.3.7.tgz", - "integrity": "sha512-mSZaJpIdOKl01/xVmQF08kcuaMsiPH+nhkPki77FYyCKa3mYnsWuehiHYkqZOkQZDcdHwAJdhm1xhx3BWJMxFg==", + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/@tapjs/reporter/-/reporter-1.3.8.tgz", + "integrity": "sha512-cqqF6Sv3FlCybIbE5lK2uQXOa8xPaASR/+mw6HF93e89Rdk2JDw++y45pGo0npAuCHd6fMrIPjF6e7YRTevwkA==", "dev": true, "dependencies": { - "@tapjs/config": "2.4.7", - "@tapjs/stack": "1.2.5", + "@tapjs/config": "2.4.8", + "@tapjs/stack": "1.2.6", "chalk": "^5.2.0", "ink": "^4.4.1", "minipass": "^7.0.3", @@ -1302,7 +1351,7 @@ "url": "https://github.com/sponsors/isaacs" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/reporter/node_modules/chalk": { @@ -1324,19 +1373,19 @@ "dev": true }, "node_modules/@tapjs/run": { - "version": "1.4.7", - "resolved": "https://registry.npmjs.org/@tapjs/run/-/run-1.4.7.tgz", - "integrity": "sha512-h4lg6l6vDDnObzmwb6CMeeA4JUtU3K8u9AKLFkh0OXZojDzp55lUaNnU1gBgbvPd8nC/2Lwjk74ciJv1IkeBDw==", + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/@tapjs/run/-/run-1.4.8.tgz", + "integrity": "sha512-RIAklQxHCQTtxK2QUgvXvrKEoyJVVgOYBMELLVPs+0IRMvkGReQ9tyBqsAMuKH9EvMF85d9dZ/Ali2EM6/5nZw==", "dev": true, "dependencies": { - "@tapjs/after": "1.1.11", - "@tapjs/before": "1.1.11", - "@tapjs/config": "2.4.7", + "@tapjs/after": "1.1.12", + "@tapjs/before": "1.1.12", + "@tapjs/config": "2.4.8", "@tapjs/processinfo": "^3.1.4", - "@tapjs/reporter": "1.3.7", - "@tapjs/spawn": "1.1.11", - "@tapjs/stdin": "1.1.11", - "@tapjs/test": "1.3.11", + "@tapjs/reporter": "1.3.8", + "@tapjs/spawn": "1.1.12", + "@tapjs/stdin": "1.1.12", + "@tapjs/test": "1.3.12", "c8": "^8.0.1", "chalk": "^5.3.0", "chokidar": "^3.5.3", @@ -1366,7 +1415,7 @@ "url": "https://github.com/sponsors/isaacs" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/run/node_modules/brace-expansion": { @@ -1497,9 +1546,9 @@ } }, "node_modules/@tapjs/snapshot": { - "version": "1.2.11", - "resolved": "https://registry.npmjs.org/@tapjs/snapshot/-/snapshot-1.2.11.tgz", - "integrity": "sha512-Jk/kMGyPzRSe9m4G8/pO+v1faTVBG9cnnGWK1GPz0xLXeNN4WJO4jDdG6UGZ+hoJ6A8SMCqYI2xmwy6c7ggKWA==", + "version": "1.2.12", + "resolved": "https://registry.npmjs.org/@tapjs/snapshot/-/snapshot-1.2.12.tgz", + "integrity": "sha512-1+fxWM9kCHdXFbXyyq5veI1ZZvEWbNCmRL9vACM7aQoE21rD9n2TJV7FNpf7TOVT2wdFCIAYTYAYp5BqCNMlrg==", "dev": true, "dependencies": { "is-actual-promise": "^1.0.0", @@ -1513,25 +1562,25 @@ "url": "https://github.com/sponsors/isaacs" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/spawn": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/@tapjs/spawn/-/spawn-1.1.11.tgz", - "integrity": "sha512-bNIeEOSbFmYS5f3UlE0WXVSVJkQzo+KVRIT5ov8TfR1OljknoKjrTrtoWyeRosc7ir6IVldJDdtGqdd0B6z4kg==", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/@tapjs/spawn/-/spawn-1.1.12.tgz", + "integrity": "sha512-xwcx2y/wbR5oyQWM4/VX0/3hHOuUuDQFNguorNYI3I2WDe1MAWdVluhY2EibM1/Wb+z/CiEoZbZBqJg1xDfdJQ==", "dev": true, "engines": { "node": ">=16" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/stack": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@tapjs/stack/-/stack-1.2.5.tgz", - "integrity": "sha512-fJNI6kmqo1FuXzVkQ1cFL5FcWYamiql5lTDbA2VuOkQ7z3/Zoitnq+B9rBf28ltmZYFMsk5lEEW8mlaxvCyHiA==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@tapjs/stack/-/stack-1.2.6.tgz", + "integrity": "sha512-us73FMZytpcvYT/gOSDDKHk/LLZQZ/bBLoz48VcEE5EFQmF0EELhNOlyg4Rrvj8DmuYuFjiliidiV/FB1Fchaw==", "dev": true, "engines": { "node": ">=16" @@ -1541,38 +1590,39 @@ } }, "node_modules/@tapjs/stdin": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/@tapjs/stdin/-/stdin-1.1.11.tgz", - "integrity": "sha512-IWuLUAYtSs/+e/J6zd8qejXPAuZ0B585XmBRUbL4yt20TvlLUxSdAzdagJm5gqL8izdBHheDXC+vdCAWpWpLgA==", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/@tapjs/stdin/-/stdin-1.1.12.tgz", + "integrity": "sha512-K9a+0uKEeAflyfkUI66jqHnyZAfZD/NDVV8vGHx16VnCSe2V4UY1qMDLA6ZbUaS5sPX9Va+kkS7sPl7qxHVsTw==", "dev": true, "engines": { "node": ">=16" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/test": { - "version": "1.3.11", - "resolved": "https://registry.npmjs.org/@tapjs/test/-/test-1.3.11.tgz", - "integrity": "sha512-uKTIsKhIiF0z0FKNcEzsFXqROSK0+e4PnW6Lcc+SN3UkH7j5OXLWeP3fuSL2nYfpk7jMXwOb/FtBIkuNnzSJ4w==", - "dev": true, - "dependencies": { - "@tapjs/after": "1.1.11", - "@tapjs/after-each": "1.1.11", - "@tapjs/asserts": "1.1.11", - "@tapjs/before": "1.1.11", - "@tapjs/before-each": "1.1.11", - "@tapjs/filter": "1.2.11", - "@tapjs/fixture": "1.2.11", - "@tapjs/intercept": "1.2.11", - "@tapjs/mock": "1.2.9", - "@tapjs/node-serialize": "1.2.0", - "@tapjs/snapshot": "1.2.11", - "@tapjs/spawn": "1.1.11", - "@tapjs/stdin": "1.1.11", - "@tapjs/typescript": "1.3.0", - "@tapjs/worker": "1.1.11", + "version": "1.3.12", + "resolved": "https://registry.npmjs.org/@tapjs/test/-/test-1.3.12.tgz", + "integrity": "sha512-j7EPow6xdY7+FwLx8dNCgZcf4E1ffsrsfel7Q6GsQ4IWPgmx+Uw4Z9aCZYsVaPrwjuPG7/WGr+vl94yoYLKGeQ==", + "dev": true, + "dependencies": { + "@isaacs/ts-node-temp-fork-for-pr-2009": "^10.9.1", + "@tapjs/after": "1.1.12", + "@tapjs/after-each": "1.1.12", + "@tapjs/asserts": "1.1.12", + "@tapjs/before": "1.1.12", + "@tapjs/before-each": "1.1.12", + "@tapjs/filter": "1.2.12", + "@tapjs/fixture": "1.2.12", + "@tapjs/intercept": "1.2.12", + "@tapjs/mock": "1.2.10", + "@tapjs/node-serialize": "1.2.1", + "@tapjs/snapshot": "1.2.12", + "@tapjs/spawn": "1.1.12", + "@tapjs/stdin": "1.1.12", + "@tapjs/typescript": "1.3.1", + "@tapjs/worker": "1.1.12", "glob": "^10.3.10", "jackspeak": "^2.3.6", "mkdirp": "^3.0.0", @@ -1580,7 +1630,6 @@ "rimraf": "^5.0.5", "sync-content": "^1.0.1", "tap-parser": "15.3.0", - "ts-node": "npm:@isaacs/ts-node-temp-fork-for-pr-2009@^10.9.1", "tshy": "^1.2.2", "typescript": "5.2" }, @@ -1591,7 +1640,7 @@ "node": ">=16" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/test/node_modules/brace-expansion": { @@ -1674,30 +1723,30 @@ } }, "node_modules/@tapjs/typescript": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@tapjs/typescript/-/typescript-1.3.0.tgz", - "integrity": "sha512-bAIislatZTgJ2nfsNgWLs0rFUjnogt7kRa5de85usN5VMUQAHT0iCn+Es+xI0nm+qwkb2F4k1be7vBKvwrkLbQ==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@tapjs/typescript/-/typescript-1.3.1.tgz", + "integrity": "sha512-RswIFHgSVMPxeFvLE4C8l7MHJCEQfBbmkkkfVYg2asB9++R1wEQVW9TClPCl83McQqL7vuqSsX3PijWu0ylOFA==", "dev": true, "dependencies": { - "ts-node": "npm:@isaacs/ts-node-temp-fork-for-pr-2009@^10.9.1" + "@isaacs/ts-node-temp-fork-for-pr-2009": "^10.9.1" }, "engines": { "node": ">=16" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tapjs/worker": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/@tapjs/worker/-/worker-1.1.11.tgz", - "integrity": "sha512-0C6nKoOON6mf51O60FYNkzzebuUAQh7MxlPUI5Y+RRy28RwlIoRLi1ca0zdjyFzdxeSfjjrHlxkPSEIZS/IHbg==", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/@tapjs/worker/-/worker-1.1.12.tgz", + "integrity": "sha512-NJ9GnibFF/+5QT8F78osEvI74McbLvyM/P7HJD21vca1LQE/c9laXexjCmw8sfV+10FirWltkM/OCPL95zAshA==", "dev": true, "engines": { "node": ">=16" }, "peerDependencies": { - "@tapjs/core": "1.4.0" + "@tapjs/core": "1.4.1" } }, "node_modules/@tootallnate/once": { @@ -1804,13 +1853,10 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.8.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.6.tgz", - "integrity": "sha512-eWO4K2Ji70QzKUqRy6oyJWUeB7+g2cRagT3T/nxYibYcT4y2BDL8lqolRXjTHmkZCdJfIPaY73KbJAZmcryxTQ==", - "dev": true, - "dependencies": { - "undici-types": "~5.25.1" - } + "version": "18.18.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.18.5.tgz", + "integrity": "sha512-4slmbtwV59ZxitY4ixUZdy1uRLf9eSIvBWPQxNjhHYWEtn0FryfKpyS2cvADYXTayWdKEIsJengncrVvkI4I6A==", + "dev": true }, "node_modules/@types/semver": { "version": "7.5.3", @@ -8741,29 +8787,29 @@ } }, "node_modules/tap": { - "version": "18.5.0", - "resolved": "https://registry.npmjs.org/tap/-/tap-18.5.0.tgz", - "integrity": "sha512-qUZVbSPKABe2GVNvUtv39jUechyvaOn0tcPOuoWYi6386kYaBds0/VKd8F5D3fcQsFEkDXTrTpbITiMulsvHXQ==", - "dev": true, - "dependencies": { - "@tapjs/after": "1.1.11", - "@tapjs/after-each": "1.1.11", - "@tapjs/asserts": "1.1.11", - "@tapjs/before": "1.1.11", - "@tapjs/before-each": "1.1.11", - "@tapjs/core": "1.4.0", - "@tapjs/filter": "1.2.11", - "@tapjs/fixture": "1.2.11", - "@tapjs/intercept": "1.2.11", - "@tapjs/mock": "1.2.9", - "@tapjs/node-serialize": "1.2.0", - "@tapjs/run": "1.4.7", - "@tapjs/snapshot": "1.2.11", - "@tapjs/spawn": "1.1.11", - "@tapjs/stdin": "1.1.11", - "@tapjs/test": "1.3.11", - "@tapjs/typescript": "1.3.0", - "@tapjs/worker": "1.1.11", + "version": "18.5.1", + "resolved": "https://registry.npmjs.org/tap/-/tap-18.5.1.tgz", + "integrity": "sha512-PdryPwDpb7LK4ApRLkCCkzQXyZA+A/FmOtWiFoiYI3HV0fBdM9aotyOZ1bYrVWQ9rccNpH2f0xrJQBlGDMdweg==", + "dev": true, + "dependencies": { + "@tapjs/after": "1.1.12", + "@tapjs/after-each": "1.1.12", + "@tapjs/asserts": "1.1.12", + "@tapjs/before": "1.1.12", + "@tapjs/before-each": "1.1.12", + "@tapjs/core": "1.4.1", + "@tapjs/filter": "1.2.12", + "@tapjs/fixture": "1.2.12", + "@tapjs/intercept": "1.2.12", + "@tapjs/mock": "1.2.10", + "@tapjs/node-serialize": "1.2.1", + "@tapjs/run": "1.4.8", + "@tapjs/snapshot": "1.2.12", + "@tapjs/spawn": "1.1.12", + "@tapjs/stdin": "1.1.12", + "@tapjs/test": "1.3.12", + "@tapjs/typescript": "1.3.1", + "@tapjs/worker": "1.1.12", "resolve-import": "^1.4.4" }, "bin": { @@ -8978,56 +9024,6 @@ "typescript": ">=4.2.0" } }, - "node_modules/ts-node": { - "name": "@isaacs/ts-node-temp-fork-for-pr-2009", - "version": "10.9.1", - "resolved": "https://registry.npmjs.org/@isaacs/ts-node-temp-fork-for-pr-2009/-/ts-node-temp-fork-for-pr-2009-10.9.1.tgz", - "integrity": "sha512-MY4rUonz835NsTbd4dcgKZvZFYX9IkLnYFZV9M7GQV8t39fawafLin/Qw6VXD4yfMs4HcBq8P3ddeU0QHMH1YQ==", - "dev": true, - "dependencies": { - "@cspotcode/source-map-support": "^0.8.0", - "@tsconfig/node14": "*", - "@tsconfig/node16": "*", - "@tsconfig/node18": "*", - "@tsconfig/node20": "*", - "acorn": "^8.4.1", - "acorn-walk": "^8.1.1", - "arg": "^4.1.0", - "diff": "^4.0.1", - "make-error": "^1.1.1", - "v8-compile-cache-lib": "^3.0.1" - }, - "bin": { - "ts-node": "dist/bin.js", - "ts-node-cwd": "dist/bin-cwd.js", - "ts-node-esm": "dist/bin-esm.js", - "ts-node-script": "dist/bin-script.js", - "ts-node-transpile-only": "dist/bin-transpile.js" - }, - "peerDependencies": { - "@swc/core": ">=1.2.50", - "@swc/wasm": ">=1.2.50", - "@types/node": "*", - "typescript": ">=4.2" - }, - "peerDependenciesMeta": { - "@swc/core": { - "optional": true - }, - "@swc/wasm": { - "optional": true - } - } - }, - "node_modules/ts-node/node_modules/diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true, - "engines": { - "node": ">=0.3.1" - } - }, "node_modules/tsconfig-paths": { "version": "3.14.2", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz", @@ -9343,12 +9339,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/undici-types": { - "version": "5.25.3", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.25.3.tgz", - "integrity": "sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==", - "dev": true - }, "node_modules/unique-filename": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-3.0.0.tgz", diff --git a/package.json b/package.json index d35568b..3246320 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "main": "dist/index.js", "engineStrict": false, "engines": { - "node": "^16.x || >=18.x || >=20.x" + "node": "^16.x || >=18.x" }, "scripts": { "build": "rm -rf ./dist && tsc --p tsconfig.build.json", @@ -16,7 +16,7 @@ "format": "prettier --write \"src/**/*.ts\"", "lint": "eslint \"{src,apps,libs,test,__tests__}/**/*.ts\" --fix", "lint:ci": "eslint \"{src,apps,libs,test,__tests__}/**/*.ts\"", - "test": "tap --passes test/*.spec.ts", + "test": "tap test/*.spec.ts", "test:cov": "tap test/*.spec.ts --coverage-report=text-summary --coverage-report=lcovonly --allow-incomplete-coverage", "prepublishOnly": "npm run lint:ci && npm run test" }, @@ -47,7 +47,7 @@ "@nestjs/core": "^10.2.7", "@nestjs/platform-express": "^10.2.7", "@nestjs/platform-fastify": "^10.2.7", - "@types/node": "^20.8.4", + "@types/node": "^18.11.9", "@types/supertest": "^2.0.14", "@typescript-eslint/eslint-plugin": "^6.7.5", "@typescript-eslint/parser": "^6.7.5", @@ -61,7 +61,7 @@ "prettier": "^3.0.3", "rxjs": "^7.8.1", "supertest": "^6.3.3", - "tap": "^18.5.0", + "tap": "^18.5.1", "typescript": "^5.2.2" }, "peerDependencies": { @@ -70,7 +70,7 @@ }, "tap": { "diag": true, - "bail": true, + "bail": false, "comments": true, "timeout": 40000 } diff --git a/src/ethers.constants.ts b/src/ethers.constants.ts index a68c217..efe84fb 100644 --- a/src/ethers.constants.ts +++ b/src/ethers.constants.ts @@ -1,151 +1,82 @@ -import type { Network } from 'ethers' +import { Network } from 'ethers' export const DECORATED_PREFIX = 'EthersJS' export const ETHERS_MODULE_OPTIONS = 'EthersModuleOptions' export const DEFAULT_TOKEN = 'default' export const BSCSCAN_DEFAULT_API_KEY = 'EVTS3CU31AATZV72YQ55TPGXGMVIFUQ9M9' export const BINANCE_POCKET_DEFAULT_APP_ID = '6136201a7bad1500343e248d' -export const MAINNET_NETWORK: Network = { - chainId: 1, - name: 'homestead', -} -export const UNSPECIFIED_NETWORK: Network = { - chainId: 0, - name: 'unspecified', -} -export const GOERLI_NETWORK: Network = { - chainId: 5, - name: 'goerli', -} -export const SEPOLIA_NETWORK: Network = { - chainId: 11155111, - name: 'sepolia', -} -export const GNOSIS_NETWORK: Network = { - chainId: 100, - name: 'gnosis', -} -export const POLYGON_NETWORK: Network = { - chainId: 137, - name: 'matic', -} -export const MUMBAI_NETWORK: Network = { - chainId: 80001, - name: 'maticmum', -} -export const BINANCE_NETWORK: Network = { - chainId: 56, - name: 'bnb', -} -export const BINANCE_TESTNET_NETWORK: Network = { - chainId: 97, - name: 'bnbt', -} -export const OPTIMISM_NETWORK: Network = { - chainId: 10, - name: 'optimism', -} -export const OPTIMISM_KOVAN_NETWORK: Network = { - chainId: 69, - name: 'optimism-kovan', -} -export const OPTIMISM_GOERLI_NETWORK: Network = { - chainId: 420, - name: 'optimism-goerli', -} -export const ARBITRUM_NETWORK: Network = { - chainId: 42161, - name: 'arbitrum', -} -export const ARBITRUM_RINKEBY_NETWORK: Network = { - chainId: 421611, - name: 'arbitrum', -} -export const AVALANCHE_NETWORK: Network = { - chainId: 43114, - name: 'avalanche', -} -export const AVALANCHE_FUJI_NETWORK: Network = { - chainId: 43113, - name: 'avalanche-fuji', -} -export const CRONOS_NETWORK: Network = { - chainId: 25, - name: 'cronos', -} -export const CRONOS_TESTNET_NETWORK: Network = { - chainId: 338, - name: 'cronos-testnet', -} -export const FANTOM_NETWORK: Network = { - chainId: 250, - name: 'fantom', -} -export const FANTOM_TESTNET_NETWORK: Network = { - chainId: 4002, - name: 'fantom-testnet', -} -export const AURORA_NETWORK: Network = { - chainId: 1313161554, - name: 'aurora', -} -export const AURORA_BETA_NETWORK: Network = { - chainId: 1313161556, - name: 'aurora-beta', -} -export const AURORA_TESTNET_NETWORK: Network = { - chainId: 1313161555, - name: 'aurora-testnet', -} +export const MAINNET_NETWORK = new Network('mainnet', 1) +export const UNSPECIFIED_NETWORK = new Network('unspecified', 0) +export const GOERLI_NETWORK = new Network('goerli', 5) +export const SEPOLIA_NETWORK = new Network('sepolia', 11155111) +export const GNOSIS_NETWORK = new Network('gnosis', 100) +export const POLYGON_NETWORK = new Network('matic', 137) +export const MUMBAI_NETWORK = new Network('maticmum', 80001) +export const BINANCE_NETWORK = new Network('bnb', 56) +export const BINANCE_TESTNET_NETWORK = new Network('bnbt', 97) +export const OPTIMISM_NETWORK = new Network('optimism', 10) +export const OPTIMISM_KOVAN_NETWORK = new Network('optimism-kovan', 69) +export const OPTIMISM_GOERLI_NETWORK = new Network('optimism-goerli', 420) +export const ARBITRUM_NETWORK = new Network('arbitrum', 42161) +export const ARBITRUM_RINKEBY_NETWORK = new Network('arbitrum', 421611) +export const AVALANCHE_NETWORK = new Network('avalanche', 43114) +export const AVALANCHE_FUJI_NETWORK = new Network('avalanche-fuji', 43113) +export const CRONOS_NETWORK = new Network('cronos', 25) +export const CRONOS_TESTNET_NETWORK = new Network('cronos-testnet', 338) +export const FANTOM_NETWORK = new Network('fantom', 250) +export const FANTOM_TESTNET_NETWORK = new Network('fantom-testnet', 4002) +export const AURORA_NETWORK = new Network('aurora', 1313161554) +export const AURORA_BETA_NETWORK = new Network('aurora-beta', 1313161556) +export const AURORA_TESTNET_NETWORK = new Network('aurora-testnet', 1313161555) -export const NETWORKS_BY_CHAIN_ID: Record = { - [MAINNET_NETWORK.chainId]: MAINNET_NETWORK, - [UNSPECIFIED_NETWORK.chainId]: UNSPECIFIED_NETWORK, - [GOERLI_NETWORK.chainId]: GOERLI_NETWORK, - [SEPOLIA_NETWORK.chainId]: SEPOLIA_NETWORK, - [GNOSIS_NETWORK.chainId]: GNOSIS_NETWORK, - [POLYGON_NETWORK.chainId]: POLYGON_NETWORK, - [MUMBAI_NETWORK.chainId]: MUMBAI_NETWORK, - [BINANCE_NETWORK.chainId]: BINANCE_NETWORK, - [BINANCE_TESTNET_NETWORK.chainId]: BINANCE_TESTNET_NETWORK, - [OPTIMISM_NETWORK.chainId]: OPTIMISM_NETWORK, - [OPTIMISM_KOVAN_NETWORK.chainId]: OPTIMISM_KOVAN_NETWORK, - [OPTIMISM_GOERLI_NETWORK.chainId]: OPTIMISM_GOERLI_NETWORK, - [ARBITRUM_NETWORK.chainId]: ARBITRUM_NETWORK, - [ARBITRUM_RINKEBY_NETWORK.chainId]: ARBITRUM_RINKEBY_NETWORK, - [AVALANCHE_NETWORK.chainId]: AVALANCHE_NETWORK, - [AVALANCHE_FUJI_NETWORK.chainId]: AVALANCHE_FUJI_NETWORK, - [CRONOS_NETWORK.chainId]: CRONOS_NETWORK, - [CRONOS_TESTNET_NETWORK.chainId]: CRONOS_TESTNET_NETWORK, - [FANTOM_NETWORK.chainId]: FANTOM_NETWORK, - [FANTOM_TESTNET_NETWORK.chainId]: FANTOM_TESTNET_NETWORK, - [AURORA_NETWORK.chainId]: AURORA_NETWORK, - [AURORA_BETA_NETWORK.chainId]: AURORA_BETA_NETWORK, - [AURORA_TESTNET_NETWORK.chainId]: AURORA_TESTNET_NETWORK, -} +const NETWORKS_BY_CHAIN_ID: Map = new Map() +NETWORKS_BY_CHAIN_ID.set(MAINNET_NETWORK.chainId, MAINNET_NETWORK) +NETWORKS_BY_CHAIN_ID.set(UNSPECIFIED_NETWORK.chainId, UNSPECIFIED_NETWORK) +NETWORKS_BY_CHAIN_ID.set(GOERLI_NETWORK.chainId, GOERLI_NETWORK) +NETWORKS_BY_CHAIN_ID.set(SEPOLIA_NETWORK.chainId, SEPOLIA_NETWORK) +NETWORKS_BY_CHAIN_ID.set(GNOSIS_NETWORK.chainId, GNOSIS_NETWORK) +NETWORKS_BY_CHAIN_ID.set(POLYGON_NETWORK.chainId, POLYGON_NETWORK) +NETWORKS_BY_CHAIN_ID.set(MUMBAI_NETWORK.chainId, MUMBAI_NETWORK) +NETWORKS_BY_CHAIN_ID.set(BINANCE_NETWORK.chainId, BINANCE_NETWORK) +NETWORKS_BY_CHAIN_ID.set(BINANCE_TESTNET_NETWORK.chainId, BINANCE_TESTNET_NETWORK) +NETWORKS_BY_CHAIN_ID.set(OPTIMISM_NETWORK.chainId, OPTIMISM_NETWORK) +NETWORKS_BY_CHAIN_ID.set(OPTIMISM_KOVAN_NETWORK.chainId, OPTIMISM_KOVAN_NETWORK) +NETWORKS_BY_CHAIN_ID.set(OPTIMISM_GOERLI_NETWORK.chainId, OPTIMISM_GOERLI_NETWORK) +NETWORKS_BY_CHAIN_ID.set(ARBITRUM_NETWORK.chainId, ARBITRUM_NETWORK) +NETWORKS_BY_CHAIN_ID.set(ARBITRUM_RINKEBY_NETWORK.chainId, ARBITRUM_RINKEBY_NETWORK) +NETWORKS_BY_CHAIN_ID.set(AVALANCHE_NETWORK.chainId, AVALANCHE_NETWORK) +NETWORKS_BY_CHAIN_ID.set(AVALANCHE_FUJI_NETWORK.chainId, AVALANCHE_FUJI_NETWORK) +NETWORKS_BY_CHAIN_ID.set(CRONOS_NETWORK.chainId, CRONOS_NETWORK) +NETWORKS_BY_CHAIN_ID.set(CRONOS_TESTNET_NETWORK.chainId, CRONOS_TESTNET_NETWORK) +NETWORKS_BY_CHAIN_ID.set(FANTOM_NETWORK.chainId, FANTOM_NETWORK) +NETWORKS_BY_CHAIN_ID.set(FANTOM_TESTNET_NETWORK.chainId, FANTOM_TESTNET_NETWORK) +NETWORKS_BY_CHAIN_ID.set(AURORA_NETWORK.chainId, AURORA_NETWORK) +NETWORKS_BY_CHAIN_ID.set(AURORA_BETA_NETWORK.chainId, AURORA_BETA_NETWORK) +NETWORKS_BY_CHAIN_ID.set(AURORA_TESTNET_NETWORK.chainId, AURORA_TESTNET_NETWORK) -export const NETWORKS_BY_NAME: Record = { - [MAINNET_NETWORK.name]: MAINNET_NETWORK, - [UNSPECIFIED_NETWORK.name]: UNSPECIFIED_NETWORK, - [GOERLI_NETWORK.name]: GOERLI_NETWORK, - [SEPOLIA_NETWORK.name]: SEPOLIA_NETWORK, - [GNOSIS_NETWORK.name]: GNOSIS_NETWORK, - [POLYGON_NETWORK.name]: POLYGON_NETWORK, - [MUMBAI_NETWORK.name]: MUMBAI_NETWORK, - [BINANCE_NETWORK.name]: BINANCE_NETWORK, - [BINANCE_TESTNET_NETWORK.name]: BINANCE_TESTNET_NETWORK, - [OPTIMISM_NETWORK.name]: OPTIMISM_NETWORK, - [OPTIMISM_KOVAN_NETWORK.name]: OPTIMISM_KOVAN_NETWORK, - [OPTIMISM_GOERLI_NETWORK.name]: OPTIMISM_GOERLI_NETWORK, - [ARBITRUM_NETWORK.name]: ARBITRUM_NETWORK, - [ARBITRUM_RINKEBY_NETWORK.name]: ARBITRUM_RINKEBY_NETWORK, - [AVALANCHE_NETWORK.name]: AVALANCHE_NETWORK, - [AVALANCHE_FUJI_NETWORK.name]: AVALANCHE_FUJI_NETWORK, - [CRONOS_NETWORK.name]: CRONOS_NETWORK, - [CRONOS_TESTNET_NETWORK.name]: CRONOS_TESTNET_NETWORK, - [FANTOM_NETWORK.name]: FANTOM_NETWORK, - [FANTOM_TESTNET_NETWORK.name]: FANTOM_TESTNET_NETWORK, - [AURORA_NETWORK.name]: AURORA_NETWORK, - [AURORA_BETA_NETWORK.name]: AURORA_BETA_NETWORK, - [AURORA_TESTNET_NETWORK.name]: AURORA_TESTNET_NETWORK, -} +const NETWORKS_BY_NAME: Map = new Map() +NETWORKS_BY_NAME.set(MAINNET_NETWORK.name, MAINNET_NETWORK) +NETWORKS_BY_NAME.set(UNSPECIFIED_NETWORK.name, UNSPECIFIED_NETWORK) +NETWORKS_BY_NAME.set(GOERLI_NETWORK.name, GOERLI_NETWORK) +NETWORKS_BY_NAME.set(SEPOLIA_NETWORK.name, SEPOLIA_NETWORK) +NETWORKS_BY_NAME.set(GNOSIS_NETWORK.name, GNOSIS_NETWORK) +NETWORKS_BY_NAME.set(POLYGON_NETWORK.name, POLYGON_NETWORK) +NETWORKS_BY_NAME.set(MUMBAI_NETWORK.name, MUMBAI_NETWORK) +NETWORKS_BY_NAME.set(BINANCE_NETWORK.name, BINANCE_NETWORK) +NETWORKS_BY_NAME.set(BINANCE_TESTNET_NETWORK.name, BINANCE_TESTNET_NETWORK) +NETWORKS_BY_NAME.set(OPTIMISM_NETWORK.name, OPTIMISM_NETWORK) +NETWORKS_BY_NAME.set(OPTIMISM_KOVAN_NETWORK.name, OPTIMISM_KOVAN_NETWORK) +NETWORKS_BY_NAME.set(OPTIMISM_GOERLI_NETWORK.name, OPTIMISM_GOERLI_NETWORK) +NETWORKS_BY_NAME.set(ARBITRUM_NETWORK.name, ARBITRUM_NETWORK) +NETWORKS_BY_NAME.set(ARBITRUM_RINKEBY_NETWORK.name, ARBITRUM_RINKEBY_NETWORK) +NETWORKS_BY_NAME.set(AVALANCHE_NETWORK.name, AVALANCHE_NETWORK) +NETWORKS_BY_NAME.set(AVALANCHE_FUJI_NETWORK.name, AVALANCHE_FUJI_NETWORK) +NETWORKS_BY_NAME.set(CRONOS_NETWORK.name, CRONOS_NETWORK) +NETWORKS_BY_NAME.set(CRONOS_TESTNET_NETWORK.name, CRONOS_TESTNET_NETWORK) +NETWORKS_BY_NAME.set(FANTOM_NETWORK.name, FANTOM_NETWORK) +NETWORKS_BY_NAME.set(FANTOM_TESTNET_NETWORK.name, FANTOM_TESTNET_NETWORK) +NETWORKS_BY_NAME.set(AURORA_NETWORK.name, AURORA_NETWORK) +NETWORKS_BY_NAME.set(AURORA_BETA_NETWORK.name, AURORA_BETA_NETWORK) +NETWORKS_BY_NAME.set(AURORA_TESTNET_NETWORK.name, AURORA_TESTNET_NETWORK) + +export { NETWORKS_BY_CHAIN_ID, NETWORKS_BY_NAME } diff --git a/src/ethers.contract.ts b/src/ethers.contract.ts index f03f2e7..0f66933 100644 --- a/src/ethers.contract.ts +++ b/src/ethers.contract.ts @@ -1,7 +1,4 @@ -import { VoidSigner } from '@ethersproject/abstract-signer' -import { Contract, ContractInterface } from '@ethersproject/contracts' -import { Provider as AbstractProvider } from '@ethersproject/providers' -import { Wallet } from '@ethersproject/wallet' +import { VoidSigner, Wallet, Contract, InterfaceAbi, AbstractProvider } from 'ethers' export class EthersContract { private readonly provider: AbstractProvider @@ -10,7 +7,7 @@ export class EthersContract { this.provider = provider } - create(address: string, abi: ContractInterface, signer?: Wallet | VoidSigner): Contract { + create(address: string, abi: InterfaceAbi, signer?: Wallet | VoidSigner): Contract { return new Contract(address, abi, signer ?? this.provider) } } diff --git a/src/ethers.custom-rpcs.ts b/src/ethers.custom-rpcs.ts index b200ae7..4364a5c 100644 --- a/src/ethers.custom-rpcs.ts +++ b/src/ethers.custom-rpcs.ts @@ -1,14 +1,13 @@ import { - BaseProvider, + AbstractProvider, EtherscanProvider, FallbackProvider, getDefaultProvider, Network, Networkish, - PocketProvider, - UrlJsonRpcProvider, -} from '@ethersproject/providers' -import { ConnectionInfo } from '@ethersproject/web' + JsonRpcProvider, + FetchRequest, +} from 'ethers' import { BINANCE_NETWORK, BINANCE_POCKET_DEFAULT_APP_ID, @@ -18,7 +17,7 @@ import { MAINNET_NETWORK, SEPOLIA_NETWORK, } from './ethers.constants' -import { MoralisProviderOptions, PocketProviderOptions, ProviderOptions } from './ethers.interface' +import { ProviderOptions } from './ethers.interface' import { getNetwork, isBinanceNetwork } from './ethers.utils' export class BscscanProvider extends EtherscanProvider { @@ -29,10 +28,10 @@ export class BscscanProvider extends EtherscanProvider { } getBaseUrl(): string { - switch (this.network.chainId) { - case BINANCE_NETWORK.chainId: + switch (this.network.name) { + case BINANCE_NETWORK.name: return 'https://api.bscscan.com' - case BINANCE_TESTNET_NETWORK.chainId: + case BINANCE_TESTNET_NETWORK.name: return 'https://api-testnet.bscscan.com' } @@ -44,38 +43,61 @@ export class BscscanProvider extends EtherscanProvider { } } -export class BinancePocketProvider extends PocketProvider { - constructor(_network: Networkish, apiKey?: PocketProviderOptions | string) { - const network = getNetwork(_network) +export class BinancePocketProvider extends JsonRpcProvider { + readonly applicationId!: string + readonly applicationSecret!: null | string + + constructor(_network?: Networkish, applicationId?: null | string, applicationSecret?: null | string) { + const network = Network.from(_network) + + if (applicationId == null) { + applicationId = BINANCE_POCKET_DEFAULT_APP_ID + } + + if (applicationSecret == null) { + applicationSecret = null + } - super(network.chainId, apiKey || { applicationId: BINANCE_POCKET_DEFAULT_APP_ID, loadBalancer: true }) + const options = { staticNetwork: network } + + const request = BinancePocketProvider.getRequest(network, applicationId, applicationSecret) + super(request, network, options) + + this.applicationId = applicationId + this.applicationSecret = applicationSecret } - static getUrl(network: Network, apiKey: PocketProviderOptions): ConnectionInfo { - let host: string | null = null - switch (network.chainId) { - case BINANCE_NETWORK.chainId: - host = 'bsc-mainnet.gateway.pokt.network' - break - // Binance Testnet Claimed RelayChain - case BINANCE_TESTNET_NETWORK.chainId: - host = 'bsc-testnet.gateway.pokt.network' - break + static getHost(name: string): string { + switch (name) { + case BINANCE_NETWORK.name: + return 'bsc-mainnet.gateway.pokt.network' + case BINANCE_TESTNET_NETWORK.name: + return 'bsc-testnet.gateway.pokt.network' default: - throw new Error(`unsupported network ${network.name}`) + throw new Error(`unsupported network ${name}`) } + } - const url = `https:/\/${host}/v1/lb/${apiKey.applicationId}` + _getProvider(chainId: number): AbstractProvider { + try { + return new BinancePocketProvider(chainId, this.applicationId, this.applicationSecret) + } catch (error) {} + return super._getProvider(chainId) + } - const connection: ConnectionInfo = { url, headers: {} } + static getRequest(network: Network, applicationId?: null | string, applicationSecret?: null | string): FetchRequest { + if (applicationId == null) { + applicationId = BINANCE_POCKET_DEFAULT_APP_ID + } - // Apply application secret key - if (apiKey.applicationSecretKey != null) { - connection.user = '' - connection.password = apiKey.applicationSecretKey + const request = new FetchRequest(`https:/\/${BinancePocketProvider.getHost(network.name)}/v1/lb/${applicationId}`) + request.allowGzip = true + + if (applicationSecret) { + request.setCredentials('', applicationSecret) } - return connection + return request } isCommunityResource(): boolean { @@ -83,101 +105,88 @@ export class BinancePocketProvider extends PocketProvider { } } -export class MoralisProvider extends UrlJsonRpcProvider { - static getApiKey(apiKey: MoralisProviderOptions | string): MoralisProviderOptions { - const options: MoralisProviderOptions = { - apiKey: typeof apiKey === 'string' ? apiKey : apiKey.apiKey, - region: typeof apiKey === 'string' ? 'nyc' : apiKey.region ?? 'nyc', +export class MoralisProvider extends JsonRpcProvider { + public readonly applicationId: string + public readonly region: string + + constructor(_network?: Networkish, applicationId?: string, region?: string) { + if (!_network) { + _network = 'mainnet' } + const network = Network.from(_network) - if (!options.apiKey) { + if (!applicationId) { throw new Error('Invalid moralis apiKey') } - return options - } - - static getConnectionInfo(options: MoralisProviderOptions, endpoint: string): ConnectionInfo { - return { - url: `https://speedy-nodes-${options.region}.moralis.io/${options.apiKey}/${endpoint}`, - headers: {}, + if (!region) { + region = 'nyc' } - } -} -export class BinanceMoralisProvider extends MoralisProvider { - constructor(_network: Networkish, apiKey?: MoralisProviderOptions | string) { - const network = getNetwork(_network) + const options = { staticNetwork: network } - super(network, apiKey) - } + const request = MoralisProvider.getRequest(network, applicationId, region) - static getUrl(network: Network, apiKey: MoralisProviderOptions): ConnectionInfo { - let endpoint: string - switch (network.chainId) { - case BINANCE_NETWORK.chainId: - endpoint = 'bsc/mainnet' - break - case BINANCE_TESTNET_NETWORK.chainId: - endpoint = 'bsc/testnet' - break - default: - throw new Error(`unsupported network ${network.name}`) - } + super(request, network, options) - return MoralisProvider.getConnectionInfo(MoralisProvider.getApiKey(apiKey), endpoint) + this.applicationId = applicationId + this.region = region } -} -export class EthereumMoralisProvider extends MoralisProvider { - constructor(_network: Networkish, apiKey?: MoralisProviderOptions | string) { - const network = getNetwork(_network) - - super(network, apiKey) + _getProvider(chainId: number): AbstractProvider { + try { + return new MoralisProvider(chainId, this.applicationId, this.region) + } catch (error) {} + return super._getProvider(chainId) } - static getUrl(network: Network, apiKey: MoralisProviderOptions): ConnectionInfo { + static getRequest(network: Network, applicationId: string, region: string): FetchRequest { let endpoint: string - switch (network.chainId) { - case MAINNET_NETWORK.chainId: + + switch (network.name) { + case BINANCE_NETWORK.name: + endpoint = 'bsc/mainnet' + break + case BINANCE_TESTNET_NETWORK.name: + endpoint = 'bsc/testnet' + break + case MAINNET_NETWORK.name: endpoint = 'eth/mainnet' break - case GOERLI_NETWORK.chainId: + case GOERLI_NETWORK.name: endpoint = 'eth/goerli' break - case SEPOLIA_NETWORK.chainId: + case SEPOLIA_NETWORK.name: endpoint = 'eth/sepolia' break default: throw new Error(`unsupported network ${network.name}`) } - return MoralisProvider.getConnectionInfo(MoralisProvider.getApiKey(apiKey), endpoint) + const request = new FetchRequest(`https://speedy-nodes-${region}.moralis.io/${applicationId}/${endpoint}`) + + request.allowGzip = true + + return request } } export async function getFallbackProvider( - providers: BaseProvider[] = [], + providers: AbstractProvider[] = [], quorum = 1, - waitUntilIsConnected = true, -): Promise { +): Promise { if (providers.length < 1) { throw new Error( 'Error in provider creation. The property "useDefaultProvider" is false and the providers supplied are invalid.', ) } - if (waitUntilIsConnected) { - // wait until the node is up and running smoothly. - await Promise.all(providers.map((provider) => provider.ready)) - } - if (providers.length > 1) { /** * FallbackProvider with selected providers. * @see {@link https://docs.ethers.io/v5/api/providers/other/#FallbackProvider} */ - return new FallbackProvider(providers, quorum) + return new FallbackProvider(providers, undefined, { quorum }) } return providers[0] @@ -187,16 +196,16 @@ export async function getBinanceDefaultProvider( network: Network, options?: Pick, ) { - const providers: Array = [ + const providers: Array = [ new BscscanProvider(network, options?.bscscan), - new BinancePocketProvider(network, options?.pocket), + new BinancePocketProvider(network, options?.pocket?.applicationId, options?.pocket?.applicationSecretKey), ] if (options?.moralis) { - providers.push(new BinanceMoralisProvider(network, options.moralis)) + providers.push(new MoralisProvider(network, options?.moralis?.apiKey, options?.moralis?.region)) } - return getFallbackProvider(providers, options?.quorum ?? Math.min(providers.length, 2), true) + return getFallbackProvider(providers, options?.quorum ?? Math.min(providers.length, 2)) } export async function getNetworkDefaultProvider(network: Network, options: ProviderOptions = {}) { diff --git a/src/ethers.interface.ts b/src/ethers.interface.ts index 3cb5079..e47e7f5 100644 --- a/src/ethers.interface.ts +++ b/src/ethers.interface.ts @@ -1,10 +1,5 @@ -import { BytesLike } from '@ethersproject/bytes' -import { Networkish } from '@ethersproject/networks' -import { ConnectionInfo } from '@ethersproject/web' -import { Wordlist } from '@ethersproject/wordlists' import { ModuleMetadata } from '@nestjs/common/interfaces' - -export type WordlistLike = string | Wordlist +import type { Networkish } from 'ethers' export interface InfuraProviderOptions { projectId?: string @@ -21,30 +16,23 @@ export interface MoralisProviderOptions { region?: string } -export interface AnkrProviderOptions { - apiKey?: string - projectSecret?: string -} - export interface ProviderOptions { alchemy?: string | undefined etherscan?: string | undefined bscscan?: string | undefined cloudflare?: boolean | undefined - infura?: InfuraProviderOptions | string | undefined - pocket?: PocketProviderOptions | string | undefined - moralis?: MoralisProviderOptions | string | undefined - ankr?: AnkrProviderOptions | string | undefined - custom?: ConnectionInfo | string | (ConnectionInfo | string)[] | undefined + infura?: InfuraProviderOptions | undefined + pocket?: PocketProviderOptions | undefined + moralis?: MoralisProviderOptions | undefined + ankr?: string | undefined + custom?: string | string[] | undefined quorum?: number | undefined } export interface EthersModuleOptions extends ProviderOptions { network?: Networkish | undefined token?: string | undefined - waitUntilIsConnected?: boolean | undefined useDefaultProvider?: boolean | undefined - disableEthersLogger?: boolean | undefined } export interface EthersModuleAsyncOptions extends Pick { @@ -52,9 +40,3 @@ export interface EthersModuleAsyncOptions extends Pick Omit | Promise> inject?: any[] } - -export interface RandomWalletOptions { - extraEntropy?: BytesLike - locale: WordlistLike - path: string -} diff --git a/src/ethers.providers.ts b/src/ethers.providers.ts index 3a83031..dbbd187 100644 --- a/src/ethers.providers.ts +++ b/src/ethers.providers.ts @@ -1,25 +1,21 @@ -import { Logger, LogLevel } from '@ethersproject/logger' +import { Provider } from '@nestjs/common' import { - Provider as AbstractProvider, - BaseProvider, + AbstractProvider, AlchemyProvider, CloudflareProvider, EtherscanProvider, InfuraProvider, PocketProvider, - StaticJsonRpcProvider, + JsonRpcProvider, AnkrProvider, -} from '@ethersproject/providers' -import { ConnectionInfo } from '@ethersproject/web' -import { Provider } from '@nestjs/common' +} from 'ethers' import { defer, lastValueFrom } from 'rxjs' import { ETHERS_MODULE_OPTIONS, MAINNET_NETWORK } from './ethers.constants' import { EthersContract } from './ethers.contract' import { - BinanceMoralisProvider, + MoralisProvider, BinancePocketProvider, BscscanProvider, - EthereumMoralisProvider, getFallbackProvider, getNetworkDefaultProvider, } from './ethers.custom-rpcs' @@ -27,13 +23,13 @@ import { EthersModuleOptions, EthersModuleAsyncOptions } from './ethers.interfac import { EthersSigner } from './ethers.signer' import { getEthersToken, getContractToken, getSignerToken, getNetwork, isBinanceNetwork } from './ethers.utils' -export async function createBaseProvider(options: EthersModuleOptions): Promise { +export async function createAbstractProvider( + options: EthersModuleOptions, +): Promise { const { network = MAINNET_NETWORK, quorum = 1, - waitUntilIsConnected = true, useDefaultProvider = true, - disableEthersLogger = false, alchemy, etherscan, bscscan, @@ -45,14 +41,10 @@ export async function createBaseProvider(options: EthersModuleOptions): Promise< custom, } = options - if (disableEthersLogger) { - Logger.setLogLevel(LogLevel.OFF) - } - const providerNetwork = getNetwork(network) if (!useDefaultProvider) { - const providers: Array = [] + const providers: Array = [] if (alchemy) { providers.push(new AlchemyProvider(providerNetwork, alchemy)) @@ -67,23 +59,19 @@ export async function createBaseProvider(options: EthersModuleOptions): Promise< } if (infura) { - providers.push(new InfuraProvider(providerNetwork, infura)) + providers.push(new InfuraProvider(providerNetwork, infura?.projectId, infura?.projectSecret)) } if (pocket) { if (isBinanceNetwork(providerNetwork)) { - providers.push(new BinancePocketProvider(providerNetwork, pocket)) + providers.push(new BinancePocketProvider(providerNetwork, pocket?.applicationId, pocket?.applicationSecretKey)) } else { - providers.push(new PocketProvider(providerNetwork, pocket)) + providers.push(new PocketProvider(providerNetwork, pocket?.applicationId, pocket?.applicationSecretKey)) } } if (moralis) { - if (isBinanceNetwork(providerNetwork)) { - providers.push(new BinanceMoralisProvider(providerNetwork, moralis)) - } else { - providers.push(new EthereumMoralisProvider(providerNetwork, moralis)) - } + providers.push(new MoralisProvider(providerNetwork, moralis?.apiKey, moralis?.region)) } if (cloudflare) { @@ -99,14 +87,14 @@ export async function createBaseProvider(options: EthersModuleOptions): Promise< } if (custom) { - const customInfos: (ConnectionInfo | string)[] = !Array.isArray(custom) ? [custom] : custom + const customInfos: string[] = !Array.isArray(custom) ? [custom] : custom customInfos.forEach((customInfo) => { - providers.push(new StaticJsonRpcProvider(customInfo, providerNetwork)) + providers.push(new JsonRpcProvider(customInfo, providerNetwork)) }) } - return getFallbackProvider(providers, quorum, waitUntilIsConnected) + return getFallbackProvider(providers, quorum) } /** @@ -129,8 +117,8 @@ export async function createBaseProvider(options: EthersModuleOptions): Promise< export function createEthersProvider(options: EthersModuleOptions): Provider { return { provide: getEthersToken(options.token), - useFactory: async (): Promise => { - return await lastValueFrom(defer(() => createBaseProvider(options))) + useFactory: async (): Promise => { + return await lastValueFrom(defer(() => createAbstractProvider(options))) }, } } @@ -138,8 +126,8 @@ export function createEthersProvider(options: EthersModuleOptions): Provider { export function createEthersAsyncProvider(token?: string): Provider { return { provide: getEthersToken(token), - useFactory: async (options: EthersModuleOptions): Promise => { - return await lastValueFrom(defer(() => createBaseProvider(options))) + useFactory: async (options: EthersModuleOptions): Promise => { + return await lastValueFrom(defer(() => createAbstractProvider(options))) }, inject: [ETHERS_MODULE_OPTIONS], } diff --git a/src/ethers.signer.ts b/src/ethers.signer.ts index a64ee32..0a11131 100644 --- a/src/ethers.signer.ts +++ b/src/ethers.signer.ts @@ -1,11 +1,13 @@ -import { ExternallyOwnedAccount, VoidSigner } from '@ethersproject/abstract-signer' -import { BytesLike } from '@ethersproject/bytes' -import { ProgressCallback } from '@ethersproject/json-wallets' -import { Provider as AbstractProvider } from '@ethersproject/providers' -import { SigningKey } from '@ethersproject/signing-key' -import { Wallet } from '@ethersproject/wallet' -import { Wordlist } from '@ethersproject/wordlists' -import { RandomWalletOptions } from './ethers.interface' +import { + VoidSigner, + BytesLike, + ProgressCallback, + AbstractProvider, + SigningKey, + Wallet, + HDNodeWallet, + Mnemonic, +} from 'ethers' export class EthersSigner { private readonly provider: AbstractProvider @@ -14,28 +16,26 @@ export class EthersSigner { this.provider = provider } - createWallet(privateKey: BytesLike | ExternallyOwnedAccount | SigningKey): Wallet { + createWallet(privateKey: string | SigningKey): Wallet { return new Wallet(privateKey, this.provider) } - createRandomWallet(options?: RandomWalletOptions): Wallet { - const wallet = Wallet.createRandom(options) as Wallet - - return wallet.connect(this.provider) + createRandomWallet(): HDNodeWallet { + return Wallet.createRandom(this.provider) } async createWalletFromEncryptedJson( jsonString: string, password: BytesLike, progressCallback?: ProgressCallback, - ): Promise { + ): Promise { const wallet = await Wallet.fromEncryptedJson(jsonString, password, progressCallback) return wallet.connect(this.provider) } - createWalletfromMnemonic(mnemonic: string, path?: string, wordlist?: Wordlist): Wallet { - const wallet = Wallet.fromMnemonic(mnemonic, path, wordlist) as Wallet + createWalletfromMnemonic(mnemonic: Mnemonic, path?: string): HDNodeWallet { + const wallet = HDNodeWallet.fromMnemonic(mnemonic, path) return wallet.connect(this.provider) } diff --git a/src/ethers.utils.ts b/src/ethers.utils.ts index 6508295..202807a 100644 --- a/src/ethers.utils.ts +++ b/src/ethers.utils.ts @@ -1,4 +1,4 @@ -import { Network, Networkish } from '@ethersproject/networks' +import { Network, Networkish } from 'ethers' import { BINANCE_NETWORK, BINANCE_TESTNET_NETWORK, @@ -21,30 +21,30 @@ export function getSignerToken(token?: string): string { return `${DECORATED_PREFIX}:Signer:${token || DEFAULT_TOKEN}` } -export function getNetwork(network: Networkish | null | undefined): Network { +export function getNetwork(network?: Networkish): Network { if (!network) { throw new Error(`Invalid value: ${network}`) } - if (typeof network === 'number' && NETWORKS_BY_CHAIN_ID[network]) { - return NETWORKS_BY_CHAIN_ID[network] + if (typeof network === 'number' && NETWORKS_BY_CHAIN_ID.has(BigInt(network))) { + return NETWORKS_BY_CHAIN_ID.get(BigInt(network)) as Network } - if (typeof network === 'string' && NETWORKS_BY_NAME[network]) { - return NETWORKS_BY_NAME[network] + if (typeof network === 'string' && NETWORKS_BY_NAME.has(network)) { + return NETWORKS_BY_NAME.get(network) as Network } - if (typeof network !== 'number' && typeof network !== 'string' && network.chainId) { - return network + if (typeof network !== 'bigint' && typeof network !== 'number' && typeof network !== 'string' && network?.name) { + return Network.from(network) } return UNSPECIFIED_NETWORK } export function isBinanceNetwork(network: Network): boolean { - switch (network.chainId) { - case BINANCE_NETWORK.chainId: - case BINANCE_TESTNET_NETWORK.chainId: + switch (network.name) { + case BINANCE_NETWORK.name: + case BINANCE_TESTNET_NETWORK.name: return true default: return false diff --git a/test/ethers.contract.spec.ts b/test/ethers.contract.spec.ts index 3b84f84..dae5447 100644 --- a/test/ethers.contract.spec.ts +++ b/test/ethers.contract.spec.ts @@ -1,5 +1,5 @@ -import { Contract } from '@ethersproject/contracts' import { Module, Controller, Get, Injectable } from '@nestjs/common' +import { Contract } from 'ethers' import * as nock from 'nock' import t from 'tap' import * as ABI from './utils/ABI.json' @@ -37,11 +37,11 @@ t.test('EthersContract', (t) => { async someMethod(): Promise { const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI) - if (!contract?.provider?.getNetwork()) { + if (!contract?.runner) { throw new Error('No provider injected') } - return contract.address + return contract.getAddress() } } @@ -84,15 +84,11 @@ t.test('EthersContract', (t) => { const wallet = this.signer.createWallet(ETHERS_PRIVATE_KEY) const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI, wallet) - if (!contract?.provider?.getNetwork()) { + if (!contract?.runner) { throw new Error('No provider injected') } - if (!contract?.signer.provider?.getNetwork()) { - throw new Error('No signer injected') - } - - return contract.address + return contract.getAddress() } } @@ -137,11 +133,11 @@ t.test('EthersContract', (t) => { async someMethod(): Promise { const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI) - if (!contract?.provider?.getNetwork()) { + if (!contract?.runner) { throw new Error('No provider injected') } - return contract.address + return contract.getAddress() } } @@ -192,15 +188,11 @@ t.test('EthersContract', (t) => { const wallet = this.signer.createWallet(ETHERS_PRIVATE_KEY) const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI, wallet) - if (!contract?.provider?.getNetwork()) { + if (!contract?.runner) { throw new Error('No provider injected') } - if (!contract?.signer.provider?.getNetwork()) { - throw new Error('No signer injected') - } - - return contract.address + return contract.getAddress() } } diff --git a/test/ethers.custom-rpcs.spec.ts b/test/ethers.custom-rpcs.spec.ts index a2efffb..76927f0 100644 --- a/test/ethers.custom-rpcs.spec.ts +++ b/test/ethers.custom-rpcs.spec.ts @@ -1,11 +1,11 @@ import { AlchemyProvider, - AnkrProvider, CloudflareProvider, EtherscanProvider, FallbackProvider, InfuraProvider, -} from '@ethersproject/providers' + QuickNodeProvider, +} from 'ethers' import * as nock from 'nock' import t from 'tap' import { @@ -16,10 +16,8 @@ import { SEPOLIA_NETWORK, } from '../src/ethers.constants' import { - BinanceMoralisProvider, BinancePocketProvider, BscscanProvider, - EthereumMoralisProvider, getBinanceDefaultProvider, getFallbackProvider, getNetworkDefaultProvider, @@ -86,18 +84,24 @@ t.test('Ethers Custom RPC', (t) => { }) t.test('BinancePocketProvider', (t) => { - t.test('getUrl', (t) => { - t.test('should return a bsc network url', (t) => { - const provider = new BinancePocketProvider(BINANCE_NETWORK) - - t.equal(provider.connection.url, 'https://bsc-mainnet.gateway.pokt.network/v1/lb/6136201a7bad1500343e248d') + t.test('getRequest', (t) => { + t.only('should return a bsc network url', (t) => { + const provider = new BinancePocketProvider(BINANCE_NETWORK.name) + + t.equal( + provider._getConnection().url, + 'https://bsc-mainnet.gateway.pokt.network/v1/lb/6136201a7bad1500343e248d', + ) t.end() }) t.test('should return a bsc testnet network url', (t) => { - const provider = new BinancePocketProvider(BINANCE_TESTNET_NETWORK) + const provider = new BinancePocketProvider(BINANCE_TESTNET_NETWORK.name) - t.equal(provider.connection.url, 'https://bsc-testnet.gateway.pokt.network/v1/lb/6136201a7bad1500343e248d') + t.equal( + provider._getConnection().url, + 'https://bsc-testnet.gateway.pokt.network/v1/lb/6136201a7bad1500343e248d', + ) t.end() }) @@ -107,14 +111,11 @@ t.test('Ethers Custom RPC', (t) => { }) t.test('should use an applicationSecretKey', (t) => { - const provider = new BinancePocketProvider(BINANCE_TESTNET_NETWORK, { - applicationId: '1234', - applicationSecretKey: '4321', - }) - - t.equal(provider.connection.url, 'https://bsc-testnet.gateway.pokt.network/v1/lb/1234') - t.equal(provider.connection.user, '') - t.equal(provider.connection.password, '4321') + const provider = new BinancePocketProvider(BINANCE_TESTNET_NETWORK.name, '1234', '4321') + const credentials = provider._getConnection().credentials + + t.equal(provider._getConnection().url, 'https://bsc-testnet.gateway.pokt.network/v1/lb/1234') + t.equal(credentials, ':4321') t.end() }) @@ -143,94 +144,51 @@ t.test('Ethers Custom RPC', (t) => { }) t.test('MoralisProvider', (t) => { - t.test('getApiKey', (t) => { - t.test('should return the provider options for a string key', (t) => { - t.same(MoralisProvider.getApiKey('1234'), { apiKey: '1234', region: 'nyc' }) - t.end() - }) - - t.test('should return the provider options for a non string key', (t) => { - t.same(MoralisProvider.getApiKey({ apiKey: '1234', region: 'caba' }), { - apiKey: '1234', - region: 'caba', - }) - t.end() - }) - - t.test('should throw an error if the api key is not valid', (t) => { - t.throws(() => MoralisProvider.getApiKey('')) - t.end() - }) - - t.end() - }) - t.test('getConnectionInfo', (t) => { + t.test('getRequest', (t) => { t.test('should return the connection info', (t) => { - t.same(MoralisProvider.getConnectionInfo({ apiKey: '1234', region: 'caba' }, 'test'), { - url: 'https://speedy-nodes-caba.moralis.io/1234/test', - headers: {}, - }) + const provider = new MoralisProvider(BINANCE_NETWORK, '1234', 'caba') + + t.equal(provider._getConnection().url, 'https://speedy-nodes-caba.moralis.io/1234/bsc/mainnet') t.end() }) - t.end() - }) - - t.end() - }) - - t.test('BinanceMoralisProvider', (t) => { - t.test('getUrl', (t) => { t.test('should return a bsc network url', (t) => { - const provider = new BinanceMoralisProvider(BINANCE_NETWORK, { apiKey: '1234' }) + const provider = new MoralisProvider(BINANCE_NETWORK, '1234') - t.equal(provider.connection.url, 'https://speedy-nodes-nyc.moralis.io/1234/bsc/mainnet') + t.equal(provider._getConnection().url, 'https://speedy-nodes-nyc.moralis.io/1234/bsc/mainnet') t.end() }) t.test('should return a bsc testnet network url', (t) => { - const provider = new BinanceMoralisProvider(BINANCE_TESTNET_NETWORK, { apiKey: '1234' }) + const provider = new MoralisProvider(BINANCE_TESTNET_NETWORK, '1234') - t.equal(provider.connection.url, 'https://speedy-nodes-nyc.moralis.io/1234/bsc/testnet') - t.end() - }) - - t.test('should throw an error if the network is not valid', (t) => { - t.throws(() => new BinanceMoralisProvider(1, { apiKey: '1234' })) + t.equal(provider._getConnection().url, 'https://speedy-nodes-nyc.moralis.io/1234/bsc/testnet') t.end() }) - t.end() - }) - - t.end() - }) - - t.test('EthereumMoralisProvider', (t) => { - t.test('getUrl', (t) => { t.test('should return a mainnet network url', (t) => { - const provider = new EthereumMoralisProvider(MAINNET_NETWORK, { apiKey: '1234' }) + const provider = new MoralisProvider(MAINNET_NETWORK, '1234') - t.equal(provider.connection.url, 'https://speedy-nodes-nyc.moralis.io/1234/eth/mainnet') + t.equal(provider._getConnection().url, 'https://speedy-nodes-nyc.moralis.io/1234/eth/mainnet') t.end() }) t.test('should return a goerli network url', (t) => { - const provider = new EthereumMoralisProvider(GOERLI_NETWORK, { apiKey: '1234' }) + const provider = new MoralisProvider(GOERLI_NETWORK, '1234') - t.equal(provider.connection.url, 'https://speedy-nodes-nyc.moralis.io/1234/eth/goerli') + t.equal(provider._getConnection().url, 'https://speedy-nodes-nyc.moralis.io/1234/eth/goerli') t.end() }) t.test('should return a sepolia network url', (t) => { - const provider = new EthereumMoralisProvider(SEPOLIA_NETWORK, { apiKey: '1234' }) + const provider = new MoralisProvider(SEPOLIA_NETWORK, '1234') - t.equal(provider.connection.url, 'https://speedy-nodes-nyc.moralis.io/1234/eth/sepolia') + t.equal(provider._getConnection().url, 'https://speedy-nodes-nyc.moralis.io/1234/eth/sepolia') t.end() }) t.test('should throw an error if the network is not valid', (t) => { - t.throws(() => new EthereumMoralisProvider(97, { apiKey: '1234' })) + t.throws(() => new MoralisProvider(69, '1234')) t.end() }) @@ -275,7 +233,7 @@ t.test('Ethers Custom RPC', (t) => { t.type(provider, FallbackProvider) t.type((provider as FallbackProvider).providerConfigs[0].provider, BscscanProvider) t.type((provider as FallbackProvider).providerConfigs[1].provider, BinancePocketProvider) - t.equal((provider as FallbackProvider).quorum, 2) + t.equal((provider as FallbackProvider).quorum, 1) t.end() }, ) @@ -286,7 +244,7 @@ t.test('Ethers Custom RPC', (t) => { t.type(provider, FallbackProvider) t.type((provider as FallbackProvider).providerConfigs[0].provider, BscscanProvider) t.type((provider as FallbackProvider).providerConfigs[1].provider, BinancePocketProvider) - t.type((provider as FallbackProvider).providerConfigs[2].provider, BinanceMoralisProvider) + t.type((provider as FallbackProvider).providerConfigs[2].provider, MoralisProvider) t.equal((provider as FallbackProvider).quorum, 2) t.end() }) @@ -303,7 +261,7 @@ t.test('Ethers Custom RPC', (t) => { t.type(provider, FallbackProvider) t.type((provider as FallbackProvider).providerConfigs[0].provider, BscscanProvider) t.type((provider as FallbackProvider).providerConfigs[1].provider, BinancePocketProvider) - t.equal((provider as FallbackProvider).quorum, 2) + t.equal((provider as FallbackProvider).quorum, 1) t.end() }, ) @@ -314,10 +272,10 @@ t.test('Ethers Custom RPC', (t) => { const provider = await getNetworkDefaultProvider(GOERLI_NETWORK) t.type(provider, FallbackProvider) - t.type((provider as FallbackProvider).providerConfigs[0].provider, InfuraProvider) + t.type((provider as FallbackProvider).providerConfigs[0].provider, AlchemyProvider) t.type((provider as FallbackProvider).providerConfigs[1].provider, EtherscanProvider) - t.type((provider as FallbackProvider).providerConfigs[2].provider, AlchemyProvider) - t.type((provider as FallbackProvider).providerConfigs[3].provider, AnkrProvider) + t.type((provider as FallbackProvider).providerConfigs[2].provider, InfuraProvider) + t.type((provider as FallbackProvider).providerConfigs[3].provider, QuickNodeProvider) t.equal((provider as FallbackProvider).quorum, 1) t.end() }, diff --git a/test/ethers.decorators.spec.ts b/test/ethers.decorators.spec.ts index aaf0166..10e7735 100644 --- a/test/ethers.decorators.spec.ts +++ b/test/ethers.decorators.spec.ts @@ -1,21 +1,25 @@ -import { Contract } from '@ethersproject/contracts' -import { Network } from '@ethersproject/networks' -import { BaseProvider } from '@ethersproject/providers' import { Module, Controller, Get, Injectable } from '@nestjs/common' +import { Contract, AbstractProvider, Network, FallbackProvider } from 'ethers' import * as nock from 'nock' import t from 'tap' import * as ABI from './utils/ABI.json' import { appRequest } from './utils/appRequest' -import { ETHERS_ADDRESS } from './utils/constants' +import { + ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY, + ETHERS_ADDRESS, + GOERLI_ETHERSCAN_API_KEY, + GOERLI_ETHERSCAN_URL, + PROVIDER_GET_BLOCK_NUMBER_RESPONSE, +} from './utils/constants' import { platforms } from './utils/platforms' import { EthersModule, InjectEthersProvider, InjectContractProvider, InjectSignerProvider, - MAINNET_NETWORK, EthersContract, EthersSigner, + GOERLI_NETWORK, } from '../src' t.test('InjectEthersProvider', (t) => { @@ -36,14 +40,21 @@ t.test('InjectEthersProvider', (t) => { t.test(PlatformAdapter.name, (t) => { t.test('forRoot', (t) => { t.test('should inject ethers provider in a service successfully', async (t) => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Injectable() class TestService { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: FallbackProvider, ) {} async someMethod(): Promise { - return this.ethersProvider.getNetwork() + const data = await this.ethersProvider.getNetwork() + + return data } } @@ -54,12 +65,18 @@ t.test('InjectEthersProvider', (t) => { async get() { const network = await this.service.someMethod() - return { network } + return { name: network.name, chainId: Number(network.chainId) } } } @Module({ - imports: [EthersModule.forRoot()], + imports: [ + EthersModule.forRoot({ + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, + }), + ], controllers: [TestController], providers: [TestService], }) @@ -69,29 +86,40 @@ t.test('InjectEthersProvider', (t) => { t.equal(res.statusCode, 200) t.notHas(res.body, 'network') - t.hasOwnProps(res.body.network, ['name', 'chainId', 'ensAddress']) - t.equal(res.body.network.name, MAINNET_NETWORK.name) - t.equal(res.body.network.chainId, 1) + t.hasOwnProps(res.body, ['name', 'chainId']) + t.equal(res.body.name, GOERLI_NETWORK.name) + t.equal(res.body.chainId, Number(GOERLI_NETWORK.chainId)) t.end() }) t.test('should inject ethers provider in a controller successfully', async (t) => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Controller('/') class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { const network = await this.ethersProvider.getNetwork() - return { network } + return { name: network.name, chainId: Number(network.chainId) } } } @Module({ - imports: [EthersModule.forRoot()], + imports: [ + EthersModule.forRoot({ + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, + }), + ], controllers: [TestController], }) class TestModule {} @@ -100,13 +128,18 @@ t.test('InjectEthersProvider', (t) => { t.equal(res.statusCode, 200) t.notHas(res.body, 'network') - t.hasOwnProps(res.body.network, ['name', 'chainId', 'ensAddress']) - t.equal(res.body.network.name, MAINNET_NETWORK.name) - t.equal(res.body.network.chainId, 1) + t.hasOwnProps(res.body, ['name', 'chainId']) + t.equal(res.body.name, GOERLI_NETWORK.name) + t.equal(res.body.chainId, Number(GOERLI_NETWORK.chainId)) t.end() }) t.test('should inject contract provider in a service successfully', async (t) => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Injectable() class TestService { constructor( @@ -116,7 +149,7 @@ t.test('InjectEthersProvider', (t) => { async someMethod(): Promise { const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI) - return contract.address + return contract.getAddress() } } @@ -132,7 +165,13 @@ t.test('InjectEthersProvider', (t) => { } @Module({ - imports: [EthersModule.forRoot()], + imports: [ + EthersModule.forRoot({ + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, + }), + ], controllers: [TestController], providers: [TestService], }) @@ -146,6 +185,11 @@ t.test('InjectEthersProvider', (t) => { }) t.test('should inject contract provider in a controller successfully', async (t) => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Controller('/') class TestController { constructor( @@ -155,13 +199,20 @@ t.test('InjectEthersProvider', (t) => { @Get() async get() { const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI) + const address = await contract.getAddress() - return { address: contract.address.toLowerCase() } + return { address: address.toLowerCase() } } } @Module({ - imports: [EthersModule.forRoot()], + imports: [ + EthersModule.forRoot({ + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, + }), + ], controllers: [TestController], }) class TestModule {} @@ -174,6 +225,11 @@ t.test('InjectEthersProvider', (t) => { }) t.test('should inject signer provider in a service successfully', async (t) => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Injectable() class TestService { constructor( @@ -199,7 +255,13 @@ t.test('InjectEthersProvider', (t) => { } @Module({ - imports: [EthersModule.forRoot()], + imports: [ + EthersModule.forRoot({ + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, + }), + ], controllers: [TestController], providers: [TestService], }) @@ -213,6 +275,11 @@ t.test('InjectEthersProvider', (t) => { }) t.test('should inject signer provider in a controller successfully', async (t) => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Controller('/') class TestController { constructor( @@ -228,7 +295,13 @@ t.test('InjectEthersProvider', (t) => { } @Module({ - imports: [EthersModule.forRoot()], + imports: [ + EthersModule.forRoot({ + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, + }), + ], controllers: [TestController], }) class TestModule {} @@ -245,14 +318,21 @@ t.test('InjectEthersProvider', (t) => { t.test('forRootAsync', (t) => { t.test('should inject ethers provider in a service successfully', async () => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Injectable() class TestService { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: FallbackProvider, ) {} async someMethod(): Promise { - return this.ethersProvider.getNetwork() + const data = await this.ethersProvider.getNetwork() + + return data } } @@ -263,7 +343,7 @@ t.test('InjectEthersProvider', (t) => { async get() { const network = await this.service.someMethod() - return { network } + return { name: network.name, chainId: Number(network.chainId) } } } @@ -272,7 +352,9 @@ t.test('InjectEthersProvider', (t) => { EthersModule.forRootAsync({ useFactory: () => { return { - useDefaultProvider: true, + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, } }, }), @@ -286,24 +368,29 @@ t.test('InjectEthersProvider', (t) => { t.equal(res.statusCode, 200) t.notHas(res.body, 'network') - t.hasOwnProps(res.body.network, ['name', 'chainId', 'ensAddress']) - t.equal(res.body.network.name, MAINNET_NETWORK.name) - t.equal(res.body.network.chainId, 1) + t.hasOwnProps(res.body, ['name', 'chainId']) + t.equal(res.body.name, GOERLI_NETWORK.name) + t.equal(res.body.chainId, Number(GOERLI_NETWORK.chainId)) t.end() }) t.test('should inject ethers provider in a controller successfully', async () => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Controller('/') class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { const network = await this.ethersProvider.getNetwork() - return { network } + return { name: network.name, chainId: Number(network.chainId) } } } @@ -312,7 +399,9 @@ t.test('InjectEthersProvider', (t) => { EthersModule.forRootAsync({ useFactory: () => { return { - useDefaultProvider: true, + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, } }, }), @@ -325,13 +414,18 @@ t.test('InjectEthersProvider', (t) => { t.equal(res.statusCode, 200) t.notHas(res.body, 'network') - t.hasOwnProps(res.body.network, ['name', 'chainId', 'ensAddress']) - t.equal(res.body.network.name, MAINNET_NETWORK.name) - t.equal(res.body.network.chainId, 1) + t.hasOwnProps(res.body, ['name', 'chainId']) + t.equal(res.body.name, GOERLI_NETWORK.name) + t.equal(res.body.chainId, Number(GOERLI_NETWORK.chainId)) t.end() }) t.test('should inject contract provider in a service successfully', async () => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Injectable() class TestService { constructor( @@ -341,7 +435,7 @@ t.test('InjectEthersProvider', (t) => { async someMethod(): Promise { const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI) - return contract.address + return contract.getAddress() } } @@ -361,7 +455,9 @@ t.test('InjectEthersProvider', (t) => { EthersModule.forRootAsync({ useFactory: () => { return { - useDefaultProvider: true, + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, } }, }), @@ -379,6 +475,11 @@ t.test('InjectEthersProvider', (t) => { }) t.test('should inject contract provider in a controller successfully', async () => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Controller('/') class TestController { constructor( @@ -388,8 +489,9 @@ t.test('InjectEthersProvider', (t) => { @Get() async get() { const contract: Contract = this.contract.create(ETHERS_ADDRESS, ABI) + const address = await contract.getAddress() - return { address: contract.address.toLowerCase() } + return { address: address.toLowerCase() } } } @@ -398,7 +500,9 @@ t.test('InjectEthersProvider', (t) => { EthersModule.forRootAsync({ useFactory: () => { return { - useDefaultProvider: true, + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, } }, }), @@ -415,6 +519,11 @@ t.test('InjectEthersProvider', (t) => { }) t.test('should inject signer provider in a service successfully', async () => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Injectable() class TestService { constructor( @@ -444,7 +553,9 @@ t.test('InjectEthersProvider', (t) => { EthersModule.forRootAsync({ useFactory: () => { return { - useDefaultProvider: true, + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, } }, }), @@ -462,6 +573,11 @@ t.test('InjectEthersProvider', (t) => { }) t.test('should inject signer provider in a controller successfully', async () => { + nock(GOERLI_ETHERSCAN_URL) + .get('') + .query(ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY) + .reply(200, PROVIDER_GET_BLOCK_NUMBER_RESPONSE) + @Controller('/') class TestController { constructor( @@ -481,7 +597,9 @@ t.test('InjectEthersProvider', (t) => { EthersModule.forRootAsync({ useFactory: () => { return { - useDefaultProvider: true, + network: GOERLI_NETWORK, + etherscan: GOERLI_ETHERSCAN_API_KEY, + useDefaultProvider: false, } }, }), diff --git a/test/ethers.module.spec.ts b/test/ethers.module.spec.ts index 0eabb34..c0f8745 100644 --- a/test/ethers.module.spec.ts +++ b/test/ethers.module.spec.ts @@ -1,14 +1,14 @@ -import { BigNumber } from '@ethersproject/bignumber' -import { Network } from '@ethersproject/networks' +import { Module, Controller, Get, Injectable } from '@nestjs/common' +import { NestFactory } from '@nestjs/core' import { - BaseProvider, + Network, + AbstractProvider, FallbackProvider, - StaticJsonRpcProvider, PocketProvider, AlchemyProvider, -} from '@ethersproject/providers' -import { Module, Controller, Get, Injectable } from '@nestjs/common' -import { NestFactory } from '@nestjs/core' + JsonRpcProvider, + FeeData, +} from 'ethers' import * as nock from 'nock' import t from 'tap' import { appRequest } from './utils/appRequest' @@ -17,7 +17,6 @@ import { GOERLI_ALCHEMY_API_KEY, GOERLI_POCKET_URL, GOERLI_POKT_API_KEY, - GOERLI_POKT_SECRET_KEY, GOERLI_ETHERSCAN_URL, GOERLI_ETHERSCAN_API_KEY, GOERLI_INFURA_URL, @@ -80,7 +79,7 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { @@ -114,13 +113,13 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.ethersProvider.getGasPrice() + const data: FeeData = await this.ethersProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @Module({ @@ -151,23 +150,20 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.ethersProvider.getGasPrice() + const data: FeeData = await this.ethersProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @Module({ imports: [ EthersModule.forRoot({ network: GOERLI_NETWORK, - pocket: { - applicationId: GOERLI_POKT_API_KEY, - applicationSecretKey: GOERLI_POKT_SECRET_KEY, - }, + pocket: GOERLI_POKT_API_KEY, useDefaultProvider: false, }), ], @@ -189,13 +185,13 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.ethersProvider.getGasPrice() + const data: FeeData = await this.ethersProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @Module({ @@ -226,13 +222,13 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.ethersProvider.getGasPrice() + const data: FeeData = await this.ethersProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @Module({ @@ -261,13 +257,13 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.ethersProvider.getGasPrice() + const data: FeeData = await this.ethersProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @Module({ @@ -298,23 +294,20 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.ethersProvider.getGasPrice() + const data: FeeData = await this.ethersProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @Module({ imports: [ EthersModule.forRoot({ network: BINANCE_NETWORK, - pocket: { - applicationId: GOERLI_POKT_API_KEY, - applicationSecretKey: GOERLI_POKT_SECRET_KEY, - }, + pocket: GOERLI_POKT_API_KEY, useDefaultProvider: false, }), ], @@ -334,7 +327,7 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { @@ -364,7 +357,7 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { @@ -394,7 +387,7 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { @@ -419,7 +412,7 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { @@ -439,66 +432,6 @@ t.test('Ethers Module Initialization', (t) => { t.end() }) - t.test('should not wait until providers are connected', async (t) => { - @Controller('/') - class TestController { - constructor( - @InjectEthersProvider() - private readonly ethersProvider: FallbackProvider, - ) {} - @Get() - async get() { - const network: Network = await this.ethersProvider.getNetwork() - - return { network } - } - } - @Module({ - imports: [EthersModule.forRoot({ waitUntilIsConnected: false })], - controllers: [TestController], - }) - class TestModule {} - - const res = await appRequest(t, TestModule, PlatformAdapter) - - t.equal(res.statusCode, 200) - t.notHas(res.body, 'network') - t.hasOwnProps(res.body.network, ['name', 'chainId', 'ensAddress']) - t.equal(res.body.network.name, MAINNET_NETWORK.name) - t.equal(res.body.network.chainId, 1) - t.end() - }) - - t.test('should disable ethers logger', async (t) => { - @Controller('/') - class TestController { - constructor( - @InjectEthersProvider() - private readonly ethersProvider: FallbackProvider, - ) {} - @Get() - async get() { - const network: Network = await this.ethersProvider.getNetwork() - - return { network } - } - } - @Module({ - imports: [EthersModule.forRoot({ disableEthersLogger: true })], - controllers: [TestController], - }) - class TestModule {} - - const res = await appRequest(t, TestModule, PlatformAdapter) - - t.equal(res.statusCode, 200) - t.notHas(res.body, 'network') - t.hasOwnProps(res.body.network, ['name', 'chainId', 'ensAddress']) - t.equal(res.body.network.name, MAINNET_NETWORK.name) - t.equal(res.body.network.chainId, 1) - t.end() - }) - t.test('should work with bscscan provider', async (t) => { nock(TESTNET_BSCSCAN_URL) .get('') @@ -513,9 +446,9 @@ t.test('Ethers Module Initialization', (t) => { ) {} @Get() async get() { - const gasPrice: BigNumber = await this.bscProvider.getGasPrice() + const data: FeeData = await this.bscProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -561,9 +494,9 @@ t.test('Ethers Module Initialization', (t) => { ) {} @Get() async get() { - const gasPrice: BigNumber = await this.bscProvider.getGasPrice() + const data: FeeData = await this.bscProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -616,9 +549,9 @@ t.test('Ethers Module Initialization', (t) => { ) {} @Get() async get() { - const gasPrice: BigNumber = await this.bscProvider.getGasPrice() + const data: FeeData = await this.bscProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -645,7 +578,7 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { @@ -678,13 +611,13 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly customProvider: StaticJsonRpcProvider, + private readonly customProvider: JsonRpcProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.customProvider.getGasPrice() + const data: FeeData = await this.customProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -734,9 +667,9 @@ t.test('Ethers Module Initialization', (t) => { ) {} @Get() async get() { - const gasPrice: BigNumber = await this.customProvider.getGasPrice() + const data: FeeData = await this.customProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -778,18 +711,18 @@ t.test('Ethers Module Initialization', (t) => { @InjectEthersProvider('poly') private readonly alchemyProvider: AlchemyProvider, @InjectEthersProvider('bsc') - private readonly customProvider: StaticJsonRpcProvider, + private readonly customProvider: JsonRpcProvider, ) {} @Get() async get() { - const pocketGasPrice: BigNumber = await this.pocketProvider.getGasPrice() - const alchemyGasPrice: BigNumber = await this.alchemyProvider.getGasPrice() - const bscGasPrice: BigNumber = await this.customProvider.getGasPrice() + const pocketGasPrice: FeeData = await this.pocketProvider.getFeeData() + const alchemyGasPrice: FeeData = await this.alchemyProvider.getFeeData() + const bscGasPrice: FeeData = await this.customProvider.getFeeData() return { - pocketGasPrice: pocketGasPrice.toString(), - alchemyGasPrice: alchemyGasPrice.toString(), - bscGasPrice: bscGasPrice.toString(), + pocketGasPrice: pocketGasPrice.gasPrice?.toString(), + alchemyGasPrice: alchemyGasPrice.gasPrice?.toString(), + bscGasPrice: bscGasPrice.gasPrice?.toString(), } } } @@ -798,10 +731,7 @@ t.test('Ethers Module Initialization', (t) => { EthersModule.forRoot({ token: 'eth', network: GOERLI_NETWORK, - pocket: { - applicationId: GOERLI_POKT_API_KEY, - applicationSecretKey: GOERLI_POKT_SECRET_KEY, - }, + pocket: GOERLI_POKT_API_KEY, useDefaultProvider: false, }), EthersModule.forRoot({ @@ -846,13 +776,13 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.ethersProvider.getGasPrice() + const data: FeeData = await this.ethersProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -900,13 +830,13 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.ethersProvider.getGasPrice() + const data: FeeData = await this.ethersProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -950,13 +880,13 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.ethersProvider.getGasPrice() + const data: FeeData = await this.ethersProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -1021,13 +951,13 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.ethersProvider.getGasPrice() + const data: FeeData = await this.ethersProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -1076,7 +1006,7 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { @@ -1121,7 +1051,7 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { @@ -1166,7 +1096,7 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { @@ -1206,7 +1136,7 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { @@ -1241,44 +1171,6 @@ t.test('Ethers Module Initialization', (t) => { t.end() }) - t.test('should not wait until providers are connected', async (t) => { - @Controller('/') - class TestController { - constructor( - @InjectEthersProvider() - private readonly ethersProvider: FallbackProvider, - ) {} - @Get() - async get() { - const network: Network = await this.ethersProvider.getNetwork() - - return { network } - } - } - @Module({ - imports: [ - EthersModule.forRootAsync({ - useFactory: () => { - return { - waitUntilIsConnected: false, - } - }, - }), - ], - controllers: [TestController], - }) - class TestModule {} - - const res = await appRequest(t, TestModule, PlatformAdapter) - - t.equal(res.statusCode, 200) - t.notHas(res.body, 'network') - t.hasOwnProps(res.body.network, ['name', 'chainId', 'ensAddress']) - t.equal(res.body.network.name, MAINNET_NETWORK.name) - t.equal(res.body.network.chainId, 1) - t.end() - }) - t.test('should work with bscscan provider', async (t) => { nock(TESTNET_BSCSCAN_URL) .get('') @@ -1293,9 +1185,9 @@ t.test('Ethers Module Initialization', (t) => { ) {} @Get() async get() { - const gasPrice: BigNumber = await this.bscProvider.getGasPrice() + const data: FeeData = await this.bscProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -1357,9 +1249,9 @@ t.test('Ethers Module Initialization', (t) => { ) {} @Get() async get() { - const gasPrice: BigNumber = await this.bscProvider.getGasPrice() + const data: FeeData = await this.bscProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -1424,9 +1316,9 @@ t.test('Ethers Module Initialization', (t) => { ) {} @Get() async get() { - const gasPrice: BigNumber = await this.bscProvider.getGasPrice() + const data: FeeData = await this.bscProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -1469,7 +1361,7 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly ethersProvider: BaseProvider, + private readonly ethersProvider: AbstractProvider, ) {} @Get() async get() { @@ -1514,13 +1406,13 @@ t.test('Ethers Module Initialization', (t) => { class TestController { constructor( @InjectEthersProvider() - private readonly customProvider: StaticJsonRpcProvider, + private readonly customProvider: JsonRpcProvider, ) {} @Get() async get() { - const gasPrice: BigNumber = await this.customProvider.getGasPrice() + const data: FeeData = await this.customProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -1586,9 +1478,9 @@ t.test('Ethers Module Initialization', (t) => { ) {} @Get() async get() { - const gasPrice: BigNumber = await this.customProvider.getGasPrice() + const data: FeeData = await this.customProvider.getFeeData() - return { gasPrice: gasPrice.toString() } + return { gasPrice: data.gasPrice?.toString() } } } @@ -1646,26 +1538,26 @@ t.test('Ethers Module Initialization', (t) => { @InjectEthersProvider('poly') private readonly alchemyProvider: AlchemyProvider, @InjectEthersProvider('bsc') - private readonly customProvider: StaticJsonRpcProvider, + private readonly customProvider: JsonRpcProvider, ) {} @Get() async get() { - const pocketGasPrice: BigNumber = await this.pocketProvider.getGasPrice() - const alchemyGasPrice: BigNumber = await this.alchemyProvider.getGasPrice() - const bscGasPrice: BigNumber = await this.customProvider.getGasPrice() + const pocketGasPrice: FeeData = await this.pocketProvider.getFeeData() + const alchemyGasPrice: FeeData = await this.alchemyProvider.getFeeData() + const bscGasPrice: FeeData = await this.customProvider.getFeeData() return { - pocketGasPrice: pocketGasPrice.toString(), - alchemyGasPrice: alchemyGasPrice.toString(), - bscGasPrice: bscGasPrice.toString(), + pocketGasPrice: pocketGasPrice.gasPrice?.toString(), + alchemyGasPrice: alchemyGasPrice.gasPrice?.toString(), + bscGasPrice: bscGasPrice.gasPrice?.toString(), } } } @Injectable() class ConfigService { - public readonly applicationId = GOERLI_POKT_API_KEY - public readonly applicationSecretKey = GOERLI_POKT_SECRET_KEY + public readonly applicationId = GOERLI_POKT_API_KEY.applicationId + public readonly applicationSecretKey = GOERLI_POKT_API_KEY.applicationSecretKey public readonly alchemy = GOERLI_ALCHEMY_API_KEY public readonly custom = CUSTOM_BSC_1_URL } diff --git a/test/ethers.signer.spec.ts b/test/ethers.signer.spec.ts index 6612e9f..40a6555 100644 --- a/test/ethers.signer.spec.ts +++ b/test/ethers.signer.spec.ts @@ -1,4 +1,5 @@ import { Module, Controller, Get, Injectable } from '@nestjs/common' +import { Mnemonic } from 'ethers' import * as nock from 'nock' import t from 'tap' import { appRequest } from './utils/appRequest' @@ -169,7 +170,7 @@ t.test('EthersSigner', (t) => { private readonly signer: EthersSigner, ) {} async someMethod(): Promise { - const wallet = this.signer.createWalletfromMnemonic(ETHERS_MNEMONIC) + const wallet = this.signer.createWalletfromMnemonic(Mnemonic.fromPhrase(ETHERS_MNEMONIC)) if (!wallet?.provider?.getNetwork()) { throw new Error('No provider injected') @@ -415,7 +416,7 @@ t.test('EthersSigner', (t) => { private readonly signer: EthersSigner, ) {} async someMethod(): Promise { - const wallet = this.signer.createWalletfromMnemonic(ETHERS_MNEMONIC) + const wallet = this.signer.createWalletfromMnemonic(Mnemonic.fromPhrase(ETHERS_MNEMONIC)) if (!wallet?.provider?.getNetwork()) { throw new Error('No provider injected') diff --git a/test/ethers.utils.spec.ts b/test/ethers.utils.spec.ts index f655c83..c5f467e 100644 --- a/test/ethers.utils.spec.ts +++ b/test/ethers.utils.spec.ts @@ -68,7 +68,7 @@ t.test('getNetwork', (t) => { }) t.test('should throw an error if the network is not defined', (t) => { - t.throws(() => getNetwork(null)) + t.throws(() => getNetwork()) t.end() }) @@ -81,15 +81,14 @@ t.test('getNetwork', (t) => { t.test('should return a valid network for a name', (t) => { const network = getNetwork('sepolia') - - t.equal(network, SEPOLIA_NETWORK) + t.equal(network.name, SEPOLIA_NETWORK.name) t.end() }) t.test('should return a valid network for a Network object', (t) => { const network = getNetwork(SEPOLIA_NETWORK) - t.equal(network, SEPOLIA_NETWORK) + t.equal(network.name, SEPOLIA_NETWORK.name) t.end() }) diff --git a/test/utils/constants.ts b/test/utils/constants.ts index fdb4c81..ca73587 100644 --- a/test/utils/constants.ts +++ b/test/utils/constants.ts @@ -15,13 +15,15 @@ export const CUSTOM_BSC_3_URL = 'https://data-seed-prebsc-2-s2.binance.org:8545' export const MUMBAI_ALCHEMY_URL = 'https://polygon-mumbai.g.alchemy.com/v2/' export const GOERLI_ETHERSCAN_API_KEY = randomBytes(17).toString('hex') export const GOERLI_ALCHEMY_API_KEY = randomBytes(16).toString('hex') -export const GOERLI_POKT_API_KEY = randomBytes(12).toString('hex') -export const GOERLI_POKT_SECRET_KEY = randomBytes(16).toString('hex') +export const GOERLI_POKT_API_KEY = { + applicationId: randomBytes(12).toString('hex'), + applicationSecretKey: randomBytes(16).toString('hex'), +} export const GOERLI_INFURA_PROJECT_ID = randomBytes(16).toString('hex') export const GOERLI_INFURA_PROJECT_SECRET = randomBytes(16).toString('hex') -export const GOERLI_MORALIS_API_KEY = randomBytes(12).toString('hex') +export const GOERLI_MORALIS_API_KEY = { apiKey: randomBytes(12).toString('hex') } export const GOERLI_MORALIS_URL = `https://speedy-nodes-nyc.moralis.io/${GOERLI_MORALIS_API_KEY}/eth/goerli` -export const BINANCE_TESTNET_MORALIS_API_KEY = randomBytes(12).toString('hex') +export const BINANCE_TESTNET_MORALIS_API_KEY = { apiKey: randomBytes(12).toString('hex') } export const BINANCE_TESTNET_MORALIS_URL = `https://speedy-nodes-nyc.moralis.io/${BINANCE_TESTNET_MORALIS_API_KEY}/bsc/testnet` export const GOERLI_ANKR_API_KEY = randomBytes(12).toString('hex') export const GOERLI_ANKR_URL = `https://rpc.ankr.com/eth_goerli/${GOERLI_ANKR_API_KEY}` @@ -41,9 +43,12 @@ export const ETHERSCAN_GET_GAS_PRICE_QUERY = { action: 'eth_gasPrice', apikey: GOERLI_ETHERSCAN_API_KEY, } -export const ETHERSCAN_GET_BLOCK_NUMBER_QUERY = { +export const ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY = { module: 'proxy', action: 'eth_blockNumber', +} +export const ETHERSCAN_GET_BLOCK_NUMBER_QUERY = { + ...ETHERSCAN_GET_BLOCK_NUMBER_QUERY_COMMUNITY, apikey: GOERLI_ETHERSCAN_API_KEY, } export const PROVIDER_GET_BLOCK_NUMBER_BODY = {