essential-eth 0.4.6 → 0.4.9-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/..eslintrc.js.un~ +0 -0
- package/..npmignore.un~ +0 -0
- package/.env +1 -0
- package/.eslintignore +4 -0
- package/.eslintrc.js +34 -0
- package/.gitattributes +1 -0
- package/.github/workflows/.test.yml.un~ +0 -0
- package/.github/workflows/test.yml +29 -0
- package/.package.json.un~ +0 -0
- package/.prettierignore +7 -0
- package/.travis.yml +5 -0
- package/jest.config.js +9 -0
- package/package.json +34 -20
- package/readme.md +1 -2
- package/scripts/build-website.sh +4 -0
- package/scripts/bump-minor.sh +4 -0
- package/scripts/bump-patch.sh +4 -0
- package/scripts/fetch-chains-info.ts +70 -0
- package/scripts/pre-commit.sh +5 -0
- package/src/classes/Contract.ts +161 -0
- package/src/classes/test/Contract/crv-abi.ts +488 -0
- package/src/classes/test/Contract/crv.test.ts +56 -0
- package/src/classes/test/Contract/ens-abi.ts +452 -0
- package/src/classes/test/Contract/ens.test.ts +39 -0
- package/src/classes/test/Contract/fei-abi.ts +526 -0
- package/src/classes/test/Contract/fei.test.ts +86 -0
- package/src/classes/test/Contract/foo-abi.ts +42 -0
- package/src/classes/test/Contract/foo.test.ts +33 -0
- package/src/classes/test/Contract/uni.test.ts +72 -0
- package/src/classes/test/Contract/uniswap-abi.ts +121 -0
- package/src/classes/utils/clean-block.ts +49 -0
- package/src/classes/utils/clean-transaction.ts +35 -0
- package/src/classes/utils/encode-decode-transaction.ts +126 -0
- package/src/classes/utils/fetchers.ts +27 -0
- package/{lib/cjs/classes/utils/hex-to-decimal.d.ts → src/classes/utils/hex-to-decimal.ts} +3 -1
- package/src/index.ts +27 -0
- package/src/providers/JsonRpcProvider.ts +94 -0
- package/src/providers/test/get-block.test.ts +63 -0
- package/src/providers/test/get-network.test.ts +34 -0
- package/src/providers/utils/chains-info.ts +1079 -0
- package/src/shared/tiny-big/helpers.test.ts +30 -0
- package/src/shared/tiny-big/helpers.ts +89 -0
- package/src/shared/tiny-big/tiny-big.test.ts +10 -0
- package/src/shared/tiny-big/tiny-big.ts +36 -0
- package/src/shared/validate-type.ts +20 -0
- package/src/types/.Contract.types.ts.un~ +0 -0
- package/src/types/Block.types.ts +50 -0
- package/src/types/Contract.types.ts +67 -0
- package/src/types/Network.types.ts +8 -0
- package/src/types/Transaction.types.ts +35 -0
- package/{lib/cjs/utils/ether-to-wei.d.ts → src/utils/ether-to-wei.ts} +10 -2
- package/src/utils/index.ts +6 -0
- package/src/utils/is-address.ts +16 -0
- package/src/utils/tests/ether-to-wei.test.ts +65 -0
- package/src/utils/tests/is-address.test.ts +52 -0
- package/src/utils/tests/to-checksum-address.test.ts +43 -0
- package/src/utils/tests/wei-to-ether.test.ts +72 -0
- package/src/utils/to-checksum-address.ts +47 -0
- package/{lib/cjs/utils/wei-to-ether.d.ts → src/utils/wei-to-ether.ts} +8 -1
- package/test/global-setup.js +8 -0
- package/test/global-teardown.js +5 -0
- package/test/jest.setup-after-env.js +1 -0
- package/test/server.js +24 -0
- package/tsconfig-cjs.json +8 -0
- package/tsconfig.json +25 -0
- package/typedoc/options-new-version.js +8 -0
- package/typedoc/options.js +9 -0
- package/types/just-omit.d.ts +1 -0
- package/website/.nojekyll +1 -0
- package/website/assets/highlight.css +71 -0
- package/website/assets/icons.css +1043 -0
- package/website/assets/icons.png +0 -0
- package/website/assets/icons@2x.png +0 -0
- package/website/assets/main.js +52 -0
- package/website/assets/search.js +1 -0
- package/website/assets/style.css +1413 -0
- package/website/assets/widgets.png +0 -0
- package/website/assets/widgets@2x.png +0 -0
- package/website/classes/Contract.html +13 -0
- package/website/classes/JsonRpcProvider.html +8 -0
- package/website/classes/TinyBig.html +161 -0
- package/website/index.html +207 -0
- package/website/interfaces/Block.html +1 -0
- package/website/interfaces/JSONABIArgument.html +1 -0
- package/website/interfaces/Network.html +3 -0
- package/website/interfaces/Transaction.html +1 -0
- package/website/modules.html +32 -0
- package/website/versions/0.1.2/assets/highlight.css +57 -0
- package/website/versions/0.1.2/assets/icons.css +1043 -0
- package/website/versions/0.1.2/assets/icons.png +0 -0
- package/website/versions/0.1.2/assets/icons@2x.png +0 -0
- package/website/versions/0.1.2/assets/main.js +52 -0
- package/website/versions/0.1.2/assets/search.js +1 -0
- package/website/versions/0.1.2/assets/style.css +1341 -0
- package/website/versions/0.1.2/assets/widgets.png +0 -0
- package/website/versions/0.1.2/assets/widgets@2x.png +0 -0
- package/website/versions/0.1.2/classes/TinyBig.html +4 -0
- package/website/versions/0.1.2/index.html +20 -0
- package/website/versions/0.1.2/modules.html +23 -0
- package/website/versions/0.1.3/assets/highlight.css +64 -0
- package/website/versions/0.1.3/assets/icons.css +1043 -0
- package/website/versions/0.1.3/assets/icons.png +0 -0
- package/website/versions/0.1.3/assets/icons@2x.png +0 -0
- package/website/versions/0.1.3/assets/main.js +52 -0
- package/website/versions/0.1.3/assets/search.js +1 -0
- package/website/versions/0.1.3/assets/style.css +1341 -0
- package/website/versions/0.1.3/assets/widgets.png +0 -0
- package/website/versions/0.1.3/assets/widgets@2x.png +0 -0
- package/website/versions/0.1.3/classes/TinyBig.html +4 -0
- package/website/versions/0.1.3/index.html +53 -0
- package/website/versions/0.1.3/modules.html +23 -0
- package/website/versions/0.1.4/assets/highlight.css +64 -0
- package/website/versions/0.1.4/assets/icons.css +1043 -0
- package/website/versions/0.1.4/assets/icons.png +0 -0
- package/website/versions/0.1.4/assets/icons@2x.png +0 -0
- package/website/versions/0.1.4/assets/main.js +52 -0
- package/website/versions/0.1.4/assets/search.js +1 -0
- package/website/versions/0.1.4/assets/style.css +1341 -0
- package/website/versions/0.1.4/assets/widgets.png +0 -0
- package/website/versions/0.1.4/assets/widgets@2x.png +0 -0
- package/website/versions/0.1.4/classes/EssentialEth.html +1 -0
- package/website/versions/0.1.4/classes/TinyBig.html +4 -0
- package/website/versions/0.1.4/index.html +58 -0
- package/website/versions/0.1.4/modules.html +23 -0
- package/website/versions/0.2.0/assets/highlight.css +64 -0
- package/website/versions/0.2.0/assets/icons.css +1043 -0
- package/website/versions/0.2.0/assets/icons.png +0 -0
- package/website/versions/0.2.0/assets/icons@2x.png +0 -0
- package/website/versions/0.2.0/assets/main.js +52 -0
- package/website/versions/0.2.0/assets/search.js +1 -0
- package/website/versions/0.2.0/assets/style.css +1341 -0
- package/website/versions/0.2.0/assets/widgets.png +0 -0
- package/website/versions/0.2.0/assets/widgets@2x.png +0 -0
- package/website/versions/0.2.0/classes/EssentialEth.html +5 -0
- package/website/versions/0.2.0/classes/TinyBig.html +146 -0
- package/website/versions/0.2.0/index.html +89 -0
- package/website/versions/0.2.0/modules.html +25 -0
- package/website/versions/0.2.1/assets/highlight.css +64 -0
- package/website/versions/0.2.1/assets/icons.css +1043 -0
- package/website/versions/0.2.1/assets/icons.png +0 -0
- package/website/versions/0.2.1/assets/icons@2x.png +0 -0
- package/website/versions/0.2.1/assets/main.js +52 -0
- package/website/versions/0.2.1/assets/search.js +1 -0
- package/website/versions/0.2.1/assets/style.css +1341 -0
- package/website/versions/0.2.1/assets/widgets.png +0 -0
- package/website/versions/0.2.1/assets/widgets@2x.png +0 -0
- package/website/versions/0.2.1/classes/EssentialEth.html +5 -0
- package/website/versions/0.2.1/classes/TinyBig.html +146 -0
- package/website/versions/0.2.1/index.html +96 -0
- package/website/versions/0.2.1/modules.html +29 -0
- package/website/versions/0.2.2/assets/highlight.css +64 -0
- package/website/versions/0.2.2/assets/icons.css +1043 -0
- package/website/versions/0.2.2/assets/icons.png +0 -0
- package/website/versions/0.2.2/assets/icons@2x.png +0 -0
- package/website/versions/0.2.2/assets/main.js +52 -0
- package/website/versions/0.2.2/assets/search.js +1 -0
- package/website/versions/0.2.2/assets/style.css +1341 -0
- package/website/versions/0.2.2/assets/widgets.png +0 -0
- package/website/versions/0.2.2/assets/widgets@2x.png +0 -0
- package/website/versions/0.2.2/classes/EssentialEth.html +5 -0
- package/website/versions/0.2.2/classes/TinyBig.html +146 -0
- package/website/versions/0.2.2/index.html +96 -0
- package/website/versions/0.2.2/modules.html +29 -0
- package/website/versions/0.3.0/.nojekyll +1 -0
- package/website/versions/0.3.0/assets/highlight.css +71 -0
- package/website/versions/0.3.0/assets/icons.css +1043 -0
- package/website/versions/0.3.0/assets/icons.png +0 -0
- package/website/versions/0.3.0/assets/icons@2x.png +0 -0
- package/website/versions/0.3.0/assets/main.js +52 -0
- package/website/versions/0.3.0/assets/search.js +1 -0
- package/website/versions/0.3.0/assets/style.css +1384 -0
- package/website/versions/0.3.0/assets/widgets.png +0 -0
- package/website/versions/0.3.0/assets/widgets@2x.png +0 -0
- package/website/versions/0.3.0/classes/Contract.html +15 -0
- package/website/versions/0.3.0/classes/TinyBig.html +156 -0
- package/website/versions/0.3.0/index.html +123 -0
- package/website/versions/0.3.0/modules.html +32 -0
- package/website/versions/0.3.1/.nojekyll +1 -0
- package/website/versions/0.3.1/assets/highlight.css +71 -0
- package/website/versions/0.3.1/assets/icons.css +1043 -0
- package/website/versions/0.3.1/assets/icons.png +0 -0
- package/website/versions/0.3.1/assets/icons@2x.png +0 -0
- package/website/versions/0.3.1/assets/main.js +52 -0
- package/website/versions/0.3.1/assets/search.js +1 -0
- package/website/versions/0.3.1/assets/style.css +1384 -0
- package/website/versions/0.3.1/assets/widgets.png +0 -0
- package/website/versions/0.3.1/assets/widgets@2x.png +0 -0
- package/website/versions/0.3.1/classes/Contract.html +15 -0
- package/website/versions/0.3.1/classes/TinyBig.html +156 -0
- package/website/versions/0.3.1/index.html +123 -0
- package/website/versions/0.3.1/modules.html +32 -0
- package/website/versions/0.3.2/.nojekyll +1 -0
- package/website/versions/0.3.2/assets/highlight.css +71 -0
- package/website/versions/0.3.2/assets/icons.css +1043 -0
- package/website/versions/0.3.2/assets/icons.png +0 -0
- package/website/versions/0.3.2/assets/icons@2x.png +0 -0
- package/website/versions/0.3.2/assets/main.js +52 -0
- package/website/versions/0.3.2/assets/search.js +1 -0
- package/website/versions/0.3.2/assets/style.css +1384 -0
- package/website/versions/0.3.2/assets/widgets.png +0 -0
- package/website/versions/0.3.2/assets/widgets@2x.png +0 -0
- package/website/versions/0.3.2/classes/Contract.html +15 -0
- package/website/versions/0.3.2/classes/JsonRpcProvider.html +5 -0
- package/website/versions/0.3.2/classes/TinyBig.html +156 -0
- package/website/versions/0.3.2/index.html +123 -0
- package/website/versions/0.3.2/modules.html +32 -0
- package/website/versions/0.3.3/.nojekyll +1 -0
- package/website/versions/0.3.3/assets/highlight.css +71 -0
- package/website/versions/0.3.3/assets/icons.css +1043 -0
- package/website/versions/0.3.3/assets/icons.png +0 -0
- package/website/versions/0.3.3/assets/icons@2x.png +0 -0
- package/website/versions/0.3.3/assets/main.js +52 -0
- package/website/versions/0.3.3/assets/search.js +1 -0
- package/website/versions/0.3.3/assets/style.css +1384 -0
- package/website/versions/0.3.3/assets/widgets.png +0 -0
- package/website/versions/0.3.3/assets/widgets@2x.png +0 -0
- package/website/versions/0.3.3/classes/Contract.html +15 -0
- package/website/versions/0.3.3/classes/JsonRpcProvider.html +5 -0
- package/website/versions/0.3.3/classes/TinyBig.html +156 -0
- package/website/versions/0.3.3/index.html +123 -0
- package/website/versions/0.3.3/interfaces/Block.html +1 -0
- package/website/versions/0.3.3/interfaces/Transaction.html +1 -0
- package/website/versions/0.3.3/modules.html +32 -0
- package/website/versions/0.4.0/.nojekyll +1 -0
- package/website/versions/0.4.0/assets/highlight.css +71 -0
- package/website/versions/0.4.0/assets/icons.css +1043 -0
- package/website/versions/0.4.0/assets/icons.png +0 -0
- package/website/versions/0.4.0/assets/icons@2x.png +0 -0
- package/website/versions/0.4.0/assets/main.js +52 -0
- package/website/versions/0.4.0/assets/search.js +1 -0
- package/website/versions/0.4.0/assets/style.css +1384 -0
- package/website/versions/0.4.0/assets/widgets.png +0 -0
- package/website/versions/0.4.0/assets/widgets@2x.png +0 -0
- package/website/versions/0.4.0/classes/Contract.html +15 -0
- package/website/versions/0.4.0/classes/JsonRpcProvider.html +6 -0
- package/website/versions/0.4.0/classes/TinyBig.html +156 -0
- package/website/versions/0.4.0/index.html +148 -0
- package/website/versions/0.4.0/interfaces/Block.html +1 -0
- package/website/versions/0.4.0/interfaces/Transaction.html +1 -0
- package/website/versions/0.4.0/modules.html +32 -0
- package/website/versions/0.4.1/.nojekyll +1 -0
- package/website/versions/0.4.1/assets/highlight.css +71 -0
- package/website/versions/0.4.1/assets/icons.css +1043 -0
- package/website/versions/0.4.1/assets/icons.png +0 -0
- package/website/versions/0.4.1/assets/icons@2x.png +0 -0
- package/website/versions/0.4.1/assets/main.js +52 -0
- package/website/versions/0.4.1/assets/search.js +1 -0
- package/website/versions/0.4.1/assets/style.css +1384 -0
- package/website/versions/0.4.1/assets/widgets.png +0 -0
- package/website/versions/0.4.1/assets/widgets@2x.png +0 -0
- package/website/versions/0.4.1/classes/Contract.html +15 -0
- package/website/versions/0.4.1/classes/JsonRpcProvider.html +6 -0
- package/website/versions/0.4.1/classes/TinyBig.html +156 -0
- package/website/versions/0.4.1/index.html +148 -0
- package/website/versions/0.4.1/interfaces/Block.html +1 -0
- package/website/versions/0.4.1/interfaces/Transaction.html +1 -0
- package/website/versions/0.4.1/modules.html +32 -0
- package/website/versions/0.4.2/.nojekyll +1 -0
- package/website/versions/0.4.2/assets/highlight.css +71 -0
- package/website/versions/0.4.2/assets/icons.css +1043 -0
- package/website/versions/0.4.2/assets/icons.png +0 -0
- package/website/versions/0.4.2/assets/icons@2x.png +0 -0
- package/website/versions/0.4.2/assets/main.js +52 -0
- package/website/versions/0.4.2/assets/search.js +1 -0
- package/website/versions/0.4.2/assets/style.css +1384 -0
- package/website/versions/0.4.2/assets/widgets.png +0 -0
- package/website/versions/0.4.2/assets/widgets@2x.png +0 -0
- package/website/versions/0.4.2/classes/Contract.html +15 -0
- package/website/versions/0.4.2/classes/JsonRpcProvider.html +8 -0
- package/website/versions/0.4.2/classes/TinyBig.html +156 -0
- package/website/versions/0.4.2/index.html +199 -0
- package/website/versions/0.4.2/interfaces/Block.html +1 -0
- package/website/versions/0.4.2/interfaces/Transaction.html +1 -0
- package/website/versions/0.4.2/modules.html +34 -0
- package/website/versions/0.4.3/.nojekyll +1 -0
- package/website/versions/0.4.3/assets/highlight.css +71 -0
- package/website/versions/0.4.3/assets/icons.css +1043 -0
- package/website/versions/0.4.3/assets/icons.png +0 -0
- package/website/versions/0.4.3/assets/icons@2x.png +0 -0
- package/website/versions/0.4.3/assets/main.js +52 -0
- package/website/versions/0.4.3/assets/search.js +1 -0
- package/website/versions/0.4.3/assets/style.css +1384 -0
- package/website/versions/0.4.3/assets/widgets.png +0 -0
- package/website/versions/0.4.3/assets/widgets@2x.png +0 -0
- package/website/versions/0.4.3/classes/Contract.html +15 -0
- package/website/versions/0.4.3/classes/JsonRpcProvider.html +8 -0
- package/website/versions/0.4.3/classes/TinyBig.html +159 -0
- package/website/versions/0.4.3/index.html +199 -0
- package/website/versions/0.4.3/interfaces/Block.html +1 -0
- package/website/versions/0.4.3/interfaces/Transaction.html +1 -0
- package/website/versions/0.4.3/modules.html +34 -0
- package/website/versions/0.4.6/.nojekyll +1 -0
- package/website/versions/0.4.6/assets/highlight.css +71 -0
- package/website/versions/0.4.6/assets/icons.css +1043 -0
- package/website/versions/0.4.6/assets/icons.png +0 -0
- package/website/versions/0.4.6/assets/icons@2x.png +0 -0
- package/website/versions/0.4.6/assets/main.js +52 -0
- package/website/versions/0.4.6/assets/search.js +1 -0
- package/website/versions/0.4.6/assets/style.css +1413 -0
- package/website/versions/0.4.6/assets/widgets.png +0 -0
- package/website/versions/0.4.6/assets/widgets@2x.png +0 -0
- package/website/versions/0.4.6/classes/Contract.html +15 -0
- package/website/versions/0.4.6/classes/JsonRpcProvider.html +8 -0
- package/website/versions/0.4.6/classes/TinyBig.html +159 -0
- package/website/versions/0.4.6/index.html +207 -0
- package/website/versions/0.4.6/interfaces/Block.html +1 -0
- package/website/versions/0.4.6/interfaces/Transaction.html +1 -0
- package/website/versions/0.4.6/modules.html +34 -0
- package/website/versions/0.4.8/.nojekyll +1 -0
- package/website/versions/0.4.8/assets/highlight.css +71 -0
- package/website/versions/0.4.8/assets/icons.css +1043 -0
- package/website/versions/0.4.8/assets/icons.png +0 -0
- package/website/versions/0.4.8/assets/icons@2x.png +0 -0
- package/website/versions/0.4.8/assets/main.js +52 -0
- package/website/versions/0.4.8/assets/search.js +1 -0
- package/website/versions/0.4.8/assets/style.css +1413 -0
- package/website/versions/0.4.8/assets/widgets.png +0 -0
- package/website/versions/0.4.8/assets/widgets@2x.png +0 -0
- package/website/versions/0.4.8/classes/Contract.html +15 -0
- package/website/versions/0.4.8/classes/JsonRpcProvider.html +8 -0
- package/website/versions/0.4.8/classes/TinyBig.html +161 -0
- package/website/versions/0.4.8/index.html +207 -0
- package/website/versions/0.4.8/interfaces/Block.html +1 -0
- package/website/versions/0.4.8/interfaces/Transaction.html +1 -0
- package/website/versions/0.4.8/modules.html +34 -0
- package/website/versions/0.4.9-beta.0/.nojekyll +1 -0
- package/website/versions/0.4.9-beta.0/assets/highlight.css +71 -0
- package/website/versions/0.4.9-beta.0/assets/icons.css +1043 -0
- package/website/versions/0.4.9-beta.0/assets/icons.png +0 -0
- package/website/versions/0.4.9-beta.0/assets/icons@2x.png +0 -0
- package/website/versions/0.4.9-beta.0/assets/main.js +52 -0
- package/website/versions/0.4.9-beta.0/assets/search.js +1 -0
- package/website/versions/0.4.9-beta.0/assets/style.css +1413 -0
- package/website/versions/0.4.9-beta.0/assets/widgets.png +0 -0
- package/website/versions/0.4.9-beta.0/assets/widgets@2x.png +0 -0
- package/website/versions/0.4.9-beta.0/classes/Contract.html +13 -0
- package/website/versions/0.4.9-beta.0/classes/JsonRpcProvider.html +8 -0
- package/website/versions/0.4.9-beta.0/classes/TinyBig.html +161 -0
- package/website/versions/0.4.9-beta.0/index.html +207 -0
- package/website/versions/0.4.9-beta.0/interfaces/Block.html +1 -0
- package/website/versions/0.4.9-beta.0/interfaces/JSONABIArgument.html +1 -0
- package/website/versions/0.4.9-beta.0/interfaces/Network.html +3 -0
- package/website/versions/0.4.9-beta.0/interfaces/Transaction.html +1 -0
- package/website/versions/0.4.9-beta.0/modules.html +32 -0
- package/website/versions/versions/0.1.2/assets/highlight.css +57 -0
- package/website/versions/versions/0.1.2/assets/icons.css +1043 -0
- package/website/versions/versions/0.1.2/assets/icons.png +0 -0
- package/website/versions/versions/0.1.2/assets/icons@2x.png +0 -0
- package/website/versions/versions/0.1.2/assets/main.js +52 -0
- package/website/versions/versions/0.1.2/assets/search.js +1 -0
- package/website/versions/versions/0.1.2/assets/style.css +1341 -0
- package/website/versions/versions/0.1.2/assets/widgets.png +0 -0
- package/website/versions/versions/0.1.2/assets/widgets@2x.png +0 -0
- package/website/versions/versions/0.1.2/classes/TinyBig.html +4 -0
- package/website/versions/versions/0.1.2/index.html +20 -0
- package/website/versions/versions/0.1.2/modules.html +23 -0
- package/website/versions/versions/0.1.3/assets/highlight.css +64 -0
- package/website/versions/versions/0.1.3/assets/icons.css +1043 -0
- package/website/versions/versions/0.1.3/assets/icons.png +0 -0
- package/website/versions/versions/0.1.3/assets/icons@2x.png +0 -0
- package/website/versions/versions/0.1.3/assets/main.js +52 -0
- package/website/versions/versions/0.1.3/assets/search.js +1 -0
- package/website/versions/versions/0.1.3/assets/style.css +1341 -0
- package/website/versions/versions/0.1.3/assets/widgets.png +0 -0
- package/website/versions/versions/0.1.3/assets/widgets@2x.png +0 -0
- package/website/versions/versions/0.1.3/classes/TinyBig.html +4 -0
- package/website/versions/versions/0.1.3/index.html +53 -0
- package/website/versions/versions/0.1.3/modules.html +23 -0
- package/website/versions/versions/0.1.4/assets/highlight.css +64 -0
- package/website/versions/versions/0.1.4/assets/icons.css +1043 -0
- package/website/versions/versions/0.1.4/assets/icons.png +0 -0
- package/website/versions/versions/0.1.4/assets/icons@2x.png +0 -0
- package/website/versions/versions/0.1.4/assets/main.js +52 -0
- package/website/versions/versions/0.1.4/assets/search.js +1 -0
- package/website/versions/versions/0.1.4/assets/style.css +1341 -0
- package/website/versions/versions/0.1.4/assets/widgets.png +0 -0
- package/website/versions/versions/0.1.4/assets/widgets@2x.png +0 -0
- package/website/versions/versions/0.1.4/classes/TinyBig.html +4 -0
- package/website/versions/versions/0.1.4/index.html +58 -0
- package/website/versions/versions/0.1.4/modules.html +23 -0
- package/lib/cjs/classes/Contract.d.ts +0 -72
- package/lib/cjs/classes/Contract.js +0 -126
- package/lib/cjs/classes/test/Contract/crv-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/crv-abi.js +0 -488
- package/lib/cjs/classes/test/Contract/ens-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/ens-abi.js +0 -453
- package/lib/cjs/classes/test/Contract/fei-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/fei-abi.js +0 -526
- package/lib/cjs/classes/test/Contract/foo-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/foo-abi.js +0 -42
- package/lib/cjs/classes/test/Contract/uniswap-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/uniswap-abi.js +0 -121
- package/lib/cjs/classes/utils/clean-block.d.ts +0 -6
- package/lib/cjs/classes/utils/clean-block.js +0 -46
- package/lib/cjs/classes/utils/clean-transaction.d.ts +0 -5
- package/lib/cjs/classes/utils/clean-transaction.js +0 -38
- package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +0 -3
- package/lib/cjs/classes/utils/encode-decode-transaction.js +0 -113
- package/lib/cjs/classes/utils/fetchers.d.ts +0 -9
- package/lib/cjs/classes/utils/fetchers.js +0 -33
- package/lib/cjs/classes/utils/hex-to-decimal.js +0 -11
- package/lib/cjs/index.d.ts +0 -12
- package/lib/cjs/index.js +0 -19
- package/lib/cjs/providers/JsonRpcProvider.d.ts +0 -22
- package/lib/cjs/providers/JsonRpcProvider.js +0 -69
- package/lib/cjs/providers/utils/chains-info.d.ts +0 -338
- package/lib/cjs/providers/utils/chains-info.js +0 -1015
- package/lib/cjs/shared/tiny-big/helpers.d.ts +0 -1
- package/lib/cjs/shared/tiny-big/helpers.js +0 -71
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +0 -19
- package/lib/cjs/shared/tiny-big/tiny-big.js +0 -41
- package/lib/cjs/shared/validate-type.d.ts +0 -3
- package/lib/cjs/shared/validate-type.js +0 -9
- package/lib/cjs/types/Block.types.d.ts +0 -47
- package/lib/cjs/types/Block.types.js +0 -2
- package/lib/cjs/types/Contract.types.d.ts +0 -24
- package/lib/cjs/types/Contract.types.js +0 -2
- package/lib/cjs/types/Network.types.d.ts +0 -8
- package/lib/cjs/types/Network.types.js +0 -2
- package/lib/cjs/types/Transaction.types.d.ts +0 -34
- package/lib/cjs/types/Transaction.types.js +0 -2
- package/lib/cjs/utils/ether-to-wei.js +0 -32
- package/lib/cjs/utils/is-address.d.ts +0 -5
- package/lib/cjs/utils/is-address.js +0 -20
- package/lib/cjs/utils/to-checksum-address.d.ts +0 -17
- package/lib/cjs/utils/to-checksum-address.js +0 -46
- package/lib/cjs/utils/wei-to-ether.js +0 -34
- package/lib/esm/classes/Contract.d.ts +0 -12
- package/lib/esm/classes/Contract.js +0 -63
- package/lib/esm/classes/test/Contract/crv-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/crv-abi.js +0 -470
- package/lib/esm/classes/test/Contract/ens-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/ens-abi.js +0 -435
- package/lib/esm/classes/test/Contract/fei-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/fei-abi.js +0 -521
- package/lib/esm/classes/test/Contract/foo-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/foo-abi.js +0 -33
- package/lib/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/uniswap-abi.js +0 -116
- package/lib/esm/classes/utils/clean-block.d.ts +0 -3
- package/lib/esm/classes/utils/clean-block.js +0 -35
- package/lib/esm/classes/utils/clean-transaction.d.ts +0 -2
- package/lib/esm/classes/utils/clean-transaction.js +0 -29
- package/lib/esm/classes/utils/encode-decode-transaction.d.ts +0 -3
- package/lib/esm/classes/utils/encode-decode-transaction.js +0 -98
- package/lib/esm/classes/utils/fetchers.d.ts +0 -9
- package/lib/esm/classes/utils/fetchers.js +0 -25
- package/lib/esm/classes/utils/hex-to-decimal.d.ts +0 -1
- package/lib/esm/classes/utils/hex-to-decimal.js +0 -3
- package/lib/esm/index.d.ts +0 -12
- package/lib/esm/index.js +0 -8
- package/lib/esm/providers/JsonRpcProvider.d.ts +0 -9
- package/lib/esm/providers/JsonRpcProvider.js +0 -49
- package/lib/esm/providers/utils/chains-info.d.ts +0 -338
- package/lib/esm/providers/utils/chains-info.js +0 -1011
- package/lib/esm/shared/tiny-big/helpers.d.ts +0 -1
- package/lib/esm/shared/tiny-big/helpers.js +0 -58
- package/lib/esm/shared/tiny-big/tiny-big.d.ts +0 -8
- package/lib/esm/shared/tiny-big/tiny-big.js +0 -22
- package/lib/esm/shared/validate-type.d.ts +0 -3
- package/lib/esm/shared/validate-type.js +0 -5
- package/lib/esm/types/Block.types.d.ts +0 -47
- package/lib/esm/types/Block.types.js +0 -1
- package/lib/esm/types/Contract.types.d.ts +0 -24
- package/lib/esm/types/Contract.types.js +0 -1
- package/lib/esm/types/Network.types.d.ts +0 -5
- package/lib/esm/types/Network.types.js +0 -1
- package/lib/esm/types/Transaction.types.d.ts +0 -34
- package/lib/esm/types/Transaction.types.js +0 -1
- package/lib/esm/utils/ether-to-wei.d.ts +0 -3
- package/lib/esm/utils/ether-to-wei.js +0 -7
- package/lib/esm/utils/is-address.d.ts +0 -1
- package/lib/esm/utils/is-address.js +0 -12
- package/lib/esm/utils/to-checksum-address.d.ts +0 -1
- package/lib/esm/utils/to-checksum-address.js +0 -25
- package/lib/esm/utils/wei-to-ether.d.ts +0 -3
- package/lib/esm/utils/wei-to-ether.js +0 -7
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Contract as EthersContract } from '@ethersproject/contracts';
|
|
2
|
+
import { StaticJsonRpcProvider } from '@ethersproject/providers';
|
|
3
|
+
import { JsonRpcProvider } from '../../../providers/JsonRpcProvider';
|
|
4
|
+
import { Contract as EssentialEthContract } from '../../Contract';
|
|
5
|
+
import { uniswapABI } from './uniswap-abi';
|
|
6
|
+
|
|
7
|
+
// The JSONABI
|
|
8
|
+
const JSONABI = uniswapABI;
|
|
9
|
+
|
|
10
|
+
const rpcURL = `${process.env.RPC_ORIGIN}/api/eth`;
|
|
11
|
+
const ethersProvider = new StaticJsonRpcProvider(rpcURL);
|
|
12
|
+
const essentialEthProvider = new JsonRpcProvider(rpcURL);
|
|
13
|
+
|
|
14
|
+
// The UNI airdrop merkle address
|
|
15
|
+
// https://etherscan.io/address/0x090D4613473dEE047c3f2706764f49E0821D256e#readContract
|
|
16
|
+
const contractAddress = '0x090D4613473dEE047c3f2706764f49E0821D256e';
|
|
17
|
+
|
|
18
|
+
const smartContractIsUniClaimed = async (contract: any, index: number) => {
|
|
19
|
+
const isClaimed = (await contract.isClaimed(index)) as boolean;
|
|
20
|
+
return isClaimed;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const smartContractGetUniMerkleRoot = async (contract: any) => {
|
|
24
|
+
const merkleRoot = (await contract.merkleRoot()) as string;
|
|
25
|
+
return merkleRoot;
|
|
26
|
+
};
|
|
27
|
+
const smartContractGetUniTokenAddress = async (contract: any) => {
|
|
28
|
+
const merkleRoot = (await contract.token()) as string;
|
|
29
|
+
return merkleRoot;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const ethersContract = new EthersContract(
|
|
33
|
+
contractAddress,
|
|
34
|
+
JSONABI as any,
|
|
35
|
+
ethersProvider,
|
|
36
|
+
);
|
|
37
|
+
const essentialEthContract = new EssentialEthContract(
|
|
38
|
+
contractAddress,
|
|
39
|
+
JSONABI,
|
|
40
|
+
essentialEthProvider,
|
|
41
|
+
);
|
|
42
|
+
describe('uNI contract', () => {
|
|
43
|
+
it('should fetch "address" data-type', async () => {
|
|
44
|
+
const [ethersResponse, essentialEthResponse] = await Promise.all([
|
|
45
|
+
smartContractGetUniTokenAddress(ethersContract),
|
|
46
|
+
smartContractGetUniTokenAddress(essentialEthContract),
|
|
47
|
+
]);
|
|
48
|
+
/* 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984 */
|
|
49
|
+
expect(ethersResponse).toStrictEqual(essentialEthResponse);
|
|
50
|
+
});
|
|
51
|
+
it('should fetch "bytes32" merkle root', async () => {
|
|
52
|
+
const [ethersResponse, essentialEthResponse] = await Promise.all([
|
|
53
|
+
smartContractGetUniMerkleRoot(ethersContract),
|
|
54
|
+
smartContractGetUniMerkleRoot(essentialEthContract),
|
|
55
|
+
]);
|
|
56
|
+
/* 0xc8500f8e2fcf3c9a32880e1b973fb28acc88be35787a8abcf9981b2b65dbdeb5 */
|
|
57
|
+
expect(ethersResponse).toStrictEqual(essentialEthResponse);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should fetch isClaimed "boolean" for random airdrop indexes', async () => {
|
|
61
|
+
/* indexes of addresses in the merkle tree */
|
|
62
|
+
const randomIndexes = [0, 4, 102, 999, 999999];
|
|
63
|
+
|
|
64
|
+
for (const i of randomIndexes) {
|
|
65
|
+
const [ethersClaimed, essentialEthClaimed] = await Promise.all([
|
|
66
|
+
smartContractIsUniClaimed(ethersContract, i),
|
|
67
|
+
smartContractIsUniClaimed(essentialEthContract, i),
|
|
68
|
+
]);
|
|
69
|
+
expect(ethersClaimed).toStrictEqual(essentialEthClaimed);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { JSONABI } from '../../../types/Contract.types';
|
|
2
|
+
|
|
3
|
+
export const uniswapABI: JSONABI =
|
|
4
|
+
// http://api.etherscan.io/api?module=contract&action=getabi&address=0x090d4613473dee047c3f2706764f49e0821d256e&format=raw
|
|
5
|
+
|
|
6
|
+
[
|
|
7
|
+
{
|
|
8
|
+
inputs: [
|
|
9
|
+
{
|
|
10
|
+
internalType: 'address',
|
|
11
|
+
name: 'token_',
|
|
12
|
+
type: 'address',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
internalType: 'bytes32',
|
|
16
|
+
name: 'merkleRoot_',
|
|
17
|
+
type: 'bytes32',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
stateMutability: 'nonpayable',
|
|
21
|
+
type: 'constructor',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
anonymous: false,
|
|
25
|
+
inputs: [
|
|
26
|
+
{
|
|
27
|
+
indexed: false,
|
|
28
|
+
internalType: 'uint256',
|
|
29
|
+
name: 'index',
|
|
30
|
+
type: 'uint256',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
indexed: false,
|
|
34
|
+
internalType: 'address',
|
|
35
|
+
name: 'account',
|
|
36
|
+
type: 'address',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
indexed: false,
|
|
40
|
+
internalType: 'uint256',
|
|
41
|
+
name: 'amount',
|
|
42
|
+
type: 'uint256',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
name: 'Claimed',
|
|
46
|
+
type: 'event',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
inputs: [
|
|
50
|
+
{
|
|
51
|
+
internalType: 'uint256',
|
|
52
|
+
name: 'index',
|
|
53
|
+
type: 'uint256',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
internalType: 'address',
|
|
57
|
+
name: 'account',
|
|
58
|
+
type: 'address',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
internalType: 'uint256',
|
|
62
|
+
name: 'amount',
|
|
63
|
+
type: 'uint256',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
internalType: 'bytes32[]',
|
|
67
|
+
name: 'merkleProof',
|
|
68
|
+
type: 'bytes32[]',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
name: 'claim',
|
|
72
|
+
outputs: [],
|
|
73
|
+
stateMutability: 'nonpayable',
|
|
74
|
+
type: 'function',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
inputs: [
|
|
78
|
+
{
|
|
79
|
+
internalType: 'uint256',
|
|
80
|
+
name: 'index',
|
|
81
|
+
type: 'uint256',
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
name: 'isClaimed',
|
|
85
|
+
outputs: [
|
|
86
|
+
{
|
|
87
|
+
internalType: 'bool',
|
|
88
|
+
name: '',
|
|
89
|
+
type: 'bool',
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
stateMutability: 'view',
|
|
93
|
+
type: 'function',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
inputs: [],
|
|
97
|
+
name: 'merkleRoot',
|
|
98
|
+
outputs: [
|
|
99
|
+
{
|
|
100
|
+
internalType: 'bytes32',
|
|
101
|
+
name: '',
|
|
102
|
+
type: 'bytes32',
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
stateMutability: 'view',
|
|
106
|
+
type: 'function',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
inputs: [],
|
|
110
|
+
name: 'token',
|
|
111
|
+
outputs: [
|
|
112
|
+
{
|
|
113
|
+
internalType: 'address',
|
|
114
|
+
name: '',
|
|
115
|
+
type: 'address',
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
stateMutability: 'view',
|
|
119
|
+
type: 'function',
|
|
120
|
+
},
|
|
121
|
+
];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Block, toChecksumAddress } from '../..';
|
|
2
|
+
import { RPCBlock } from '../../types/Block.types';
|
|
3
|
+
import { RPCTransaction } from '../../types/Transaction.types';
|
|
4
|
+
import { cleanTransaction } from './clean-transaction';
|
|
5
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Converts hex to decimal and checksum-addresses all addresses
|
|
9
|
+
*/
|
|
10
|
+
export function cleanBlock(
|
|
11
|
+
block: RPCBlock,
|
|
12
|
+
returnTransactionObjects: boolean,
|
|
13
|
+
): Block {
|
|
14
|
+
const cleanedBlock: any = { ...block };
|
|
15
|
+
(Object.keys(block) as Array<keyof RPCBlock>).forEach((key) => {
|
|
16
|
+
// pending blocks have null instead of a difficulty
|
|
17
|
+
// pending blocks have null instead of a miner address
|
|
18
|
+
if (!block[key]) return;
|
|
19
|
+
switch (key) {
|
|
20
|
+
case 'gasLimit':
|
|
21
|
+
case 'gasUsed':
|
|
22
|
+
case 'number':
|
|
23
|
+
case 'size':
|
|
24
|
+
case 'timestamp':
|
|
25
|
+
case 'baseFeePerGas':
|
|
26
|
+
cleanedBlock[key] = Number(hexToDecimal(block[key]));
|
|
27
|
+
break;
|
|
28
|
+
case 'difficulty':
|
|
29
|
+
case 'totalDifficulty':
|
|
30
|
+
cleanedBlock[key] = hexToDecimal(block[key]);
|
|
31
|
+
break;
|
|
32
|
+
case 'miner':
|
|
33
|
+
if (block[key]) {
|
|
34
|
+
cleanedBlock[key] = toChecksumAddress(block[key]);
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
// for all full transactions
|
|
40
|
+
if (returnTransactionObjects) {
|
|
41
|
+
// could be renamed "cleanTransaction" in the future
|
|
42
|
+
(cleanedBlock.transactions as RPCTransaction[]).forEach(
|
|
43
|
+
(transaction, index) => {
|
|
44
|
+
cleanedBlock.transactions[index] = cleanTransaction(transaction);
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return cleanedBlock;
|
|
49
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { toChecksumAddress } from '../..';
|
|
2
|
+
import { RPCTransaction, Transaction } from '../../types/Transaction.types';
|
|
3
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts hex to decimal and checksum-addresses all addresses
|
|
7
|
+
*/
|
|
8
|
+
export function cleanTransaction(transaction: RPCTransaction): Transaction {
|
|
9
|
+
const cleanedTransaction: any = { ...transaction };
|
|
10
|
+
(Object.keys(transaction) as Array<keyof RPCTransaction>).forEach((key) => {
|
|
11
|
+
// pending blocks have null instead of a difficulty
|
|
12
|
+
// pending blocks have null instead of a miner address
|
|
13
|
+
if (!transaction[key]) return;
|
|
14
|
+
switch (key) {
|
|
15
|
+
case 'blockNumber':
|
|
16
|
+
case 'gas':
|
|
17
|
+
case 'nonce':
|
|
18
|
+
case 'transactionIndex':
|
|
19
|
+
case 'type':
|
|
20
|
+
cleanedTransaction[key] = Number(hexToDecimal(transaction[key]));
|
|
21
|
+
break;
|
|
22
|
+
case 'gasPrice':
|
|
23
|
+
case 'value':
|
|
24
|
+
cleanedTransaction[key] = hexToDecimal(transaction[key]);
|
|
25
|
+
break;
|
|
26
|
+
case 'from':
|
|
27
|
+
case 'to':
|
|
28
|
+
if (transaction[key]) {
|
|
29
|
+
cleanedTransaction[key] = toChecksumAddress(transaction[key]);
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return cleanedTransaction;
|
|
35
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Keccak } from 'sha3';
|
|
2
|
+
import { tinyBig, toChecksumAddress } from '../..';
|
|
3
|
+
import { ContractTypes, JSONABIArgument } from '../../types/Contract.types';
|
|
4
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
5
|
+
|
|
6
|
+
const hexTrue =
|
|
7
|
+
'0000000000000000000000000000000000000000000000000000000000000001';
|
|
8
|
+
const hexFalse =
|
|
9
|
+
'0000000000000000000000000000000000000000000000000000000000000000';
|
|
10
|
+
|
|
11
|
+
function expandType(type: ContractTypes) {
|
|
12
|
+
// https://docs.soliditylang.org/en/v0.8.7/types.html#integers
|
|
13
|
+
if (type === 'uint[]') {
|
|
14
|
+
return 'uint256[]';
|
|
15
|
+
} else if (type === 'int[]') {
|
|
16
|
+
return 'int256[]';
|
|
17
|
+
}
|
|
18
|
+
return type;
|
|
19
|
+
}
|
|
20
|
+
export function encodeData(jsonABIArgument: JSONABIArgument, args: any[]) {
|
|
21
|
+
const hash = new Keccak(256);
|
|
22
|
+
/* first 4 bytes will create the data parameter */
|
|
23
|
+
const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map(
|
|
24
|
+
(input) => expandType(input.type),
|
|
25
|
+
)})`;
|
|
26
|
+
|
|
27
|
+
// encoding learnt from https://ethereum.stackexchange.com/questions/3514/how-to-call-a-contract-method-using-the-eth-call-json-rpc-api
|
|
28
|
+
const functionHash = hash.update(functionString).digest('hex');
|
|
29
|
+
// no arrays
|
|
30
|
+
const jsonABIInputsLength = jsonABIArgument.inputs.length;
|
|
31
|
+
let shouldValidateInputLength = true;
|
|
32
|
+
|
|
33
|
+
// inputs contains 1 or more arrays
|
|
34
|
+
if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
|
|
35
|
+
shouldValidateInputLength = false;
|
|
36
|
+
}
|
|
37
|
+
if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const argsWithTypes: [arg: any, type: ContractTypes][] = (
|
|
44
|
+
jsonABIArgument.inputs || []
|
|
45
|
+
).reduce((acc, input, i) => {
|
|
46
|
+
if (input.type.includes('[')) {
|
|
47
|
+
// strip array and length like "[2]" from type
|
|
48
|
+
const basicType = /([^[]*)\[.*$/g.exec(input.type)?.[1] as string;
|
|
49
|
+
args.forEach((arg: any) => {
|
|
50
|
+
acc = acc.concat([[arg, basicType]]);
|
|
51
|
+
});
|
|
52
|
+
return acc;
|
|
53
|
+
} else {
|
|
54
|
+
return acc.concat([[args[i], input.type]]);
|
|
55
|
+
}
|
|
56
|
+
}, [] as [arg: any, type: ContractTypes][]);
|
|
57
|
+
|
|
58
|
+
const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
|
|
59
|
+
let rawArg = arg;
|
|
60
|
+
switch (inputType) {
|
|
61
|
+
case 'bool':
|
|
62
|
+
return arg ? hexTrue : hexFalse;
|
|
63
|
+
case 'address':
|
|
64
|
+
// remove leading "0x"
|
|
65
|
+
rawArg = arg.replace(/^0x/g, '').toLowerCase();
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
if (inputType.startsWith('bytes')) {
|
|
69
|
+
// encode each character to hex
|
|
70
|
+
const argEncoded = rawArg
|
|
71
|
+
.split('')
|
|
72
|
+
.map((character: string) => character.charCodeAt(0).toString(16))
|
|
73
|
+
.join('');
|
|
74
|
+
const paddedEncodedArg = argEncoded.padEnd(64, '0');
|
|
75
|
+
return paddedEncodedArg;
|
|
76
|
+
} else if (inputType === 'uint256') {
|
|
77
|
+
const argEncoded = BigInt(arg).toString(16);
|
|
78
|
+
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
79
|
+
return paddedEncodedArg;
|
|
80
|
+
} else if (inputType.startsWith('uint')) {
|
|
81
|
+
break;
|
|
82
|
+
} else {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const argEncoded = rawArg.toString(16) as string;
|
|
89
|
+
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
90
|
+
return paddedEncodedArg;
|
|
91
|
+
});
|
|
92
|
+
const functionEncoded = functionHash.slice(0, 8);
|
|
93
|
+
const data = `0x${functionEncoded}${encodedArgs.join('')}`;
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function decodeRPCResponse(
|
|
98
|
+
jsonABIArgument: JSONABIArgument,
|
|
99
|
+
nodeResponse: string,
|
|
100
|
+
) {
|
|
101
|
+
const rawOutputs = jsonABIArgument.outputs;
|
|
102
|
+
// chunk response every 64 characters
|
|
103
|
+
const encodedOutputs = nodeResponse.slice(2).match(/.{1,64}/g);
|
|
104
|
+
const outputs = (encodedOutputs || []).map((output: string, i: number) => {
|
|
105
|
+
const outputType = (rawOutputs || [])[i].type;
|
|
106
|
+
switch (outputType) {
|
|
107
|
+
case 'bool':
|
|
108
|
+
return output === hexTrue;
|
|
109
|
+
case 'address':
|
|
110
|
+
/* address types have 26 leading zeroes to remove */
|
|
111
|
+
return toChecksumAddress(`0x${output.slice(24)}`);
|
|
112
|
+
case 'uint256':
|
|
113
|
+
return tinyBig(hexToDecimal(`0x${output}`));
|
|
114
|
+
case 'bytes32':
|
|
115
|
+
return `0x${output}`;
|
|
116
|
+
case 'uint8':
|
|
117
|
+
return Number(hexToDecimal(`0x${output}`));
|
|
118
|
+
default:
|
|
119
|
+
throw new Error(
|
|
120
|
+
`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return outputs.length === 1 ? outputs[0] : outputs;
|
|
126
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import unfetch from 'isomorphic-unfetch';
|
|
2
|
+
export function post(url: string, body: Record<string, unknown>) {
|
|
3
|
+
return unfetch(url, {
|
|
4
|
+
method: 'POST',
|
|
5
|
+
headers: {
|
|
6
|
+
'Content-Type': 'application/json',
|
|
7
|
+
},
|
|
8
|
+
body: JSON.stringify(body),
|
|
9
|
+
})
|
|
10
|
+
.then((r) => r.json())
|
|
11
|
+
.then((response) => {
|
|
12
|
+
if (response.error) {
|
|
13
|
+
throw new Error(response.error);
|
|
14
|
+
}
|
|
15
|
+
return response.result;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type RPCMethodName = 'eth_getBlockByNumber' | 'eth_call' | 'eth_chainId';
|
|
20
|
+
export function buildRPCPostBody(method: RPCMethodName, params: any[]) {
|
|
21
|
+
return {
|
|
22
|
+
jsonrpc: '2.0',
|
|
23
|
+
id: 1,
|
|
24
|
+
method,
|
|
25
|
+
params,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -2,4 +2,6 @@
|
|
|
2
2
|
* Converts a hexadecimal string it's decimal equivalent.
|
|
3
3
|
* This is needed instead of parseInt because parseInt loses precision
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export function hexToDecimal(hex: string) {
|
|
6
|
+
return BigInt(hex).toString();
|
|
7
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Contract } from './classes/Contract';
|
|
2
|
+
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
3
|
+
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
4
|
+
import { Block } from './types/Block.types';
|
|
5
|
+
import {
|
|
6
|
+
ContractTypes,
|
|
7
|
+
JSONABI,
|
|
8
|
+
JSONABIArgument,
|
|
9
|
+
} from './types/Contract.types';
|
|
10
|
+
import { Network } from './types/Network.types';
|
|
11
|
+
import { Transaction } from './types/Transaction.types';
|
|
12
|
+
export * from './utils';
|
|
13
|
+
export {
|
|
14
|
+
jsonRpcProvider,
|
|
15
|
+
JsonRpcProvider,
|
|
16
|
+
tinyBig,
|
|
17
|
+
/* classes */
|
|
18
|
+
Contract,
|
|
19
|
+
TinyBig,
|
|
20
|
+
/* types */
|
|
21
|
+
Block,
|
|
22
|
+
ContractTypes,
|
|
23
|
+
JSONABI,
|
|
24
|
+
JSONABIArgument,
|
|
25
|
+
Network,
|
|
26
|
+
Transaction,
|
|
27
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { cleanBlock } from '../classes/utils/clean-block';
|
|
2
|
+
import { buildRPCPostBody, post } from '../classes/utils/fetchers';
|
|
3
|
+
import { hexToDecimal } from '../classes/utils/hex-to-decimal';
|
|
4
|
+
import { Block, RPCBlock } from '../types/Block.types';
|
|
5
|
+
import { Network } from '../types/Network.types';
|
|
6
|
+
import chainsInfo from './utils/chains-info';
|
|
7
|
+
export class JsonRpcProvider {
|
|
8
|
+
/**
|
|
9
|
+
* The URL to your Eth node. Consider POKT or Infura
|
|
10
|
+
*/
|
|
11
|
+
readonly _rpcUrl: Array<string>;
|
|
12
|
+
_rpcUrlCounter: number;
|
|
13
|
+
constructor(rpcUrl?: string | Array<string>) {
|
|
14
|
+
this._rpcUrl = ((): Array<string> => {
|
|
15
|
+
if (!rpcUrl) {
|
|
16
|
+
return ['https://free-eth-node.com/api/eth'];
|
|
17
|
+
} else if (!Array.isArray(rpcUrl)) {
|
|
18
|
+
return [rpcUrl];
|
|
19
|
+
}
|
|
20
|
+
return rpcUrl;
|
|
21
|
+
})();
|
|
22
|
+
this._rpcUrlCounter = 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns the block requested
|
|
27
|
+
* Same as `web3.eth.getBlock`
|
|
28
|
+
*/
|
|
29
|
+
public async getBlock(
|
|
30
|
+
timeFrame:
|
|
31
|
+
| 'latest'
|
|
32
|
+
| 'earliest'
|
|
33
|
+
| 'pending'
|
|
34
|
+
| number /* block number as integer */,
|
|
35
|
+
returnTransactionObjects = false,
|
|
36
|
+
): Promise<Block> {
|
|
37
|
+
let rpcTimeFrame: string;
|
|
38
|
+
if (typeof timeFrame === 'number') {
|
|
39
|
+
// exact block numbers require hex string format
|
|
40
|
+
rpcTimeFrame = `0x${timeFrame.toString(16)}`;
|
|
41
|
+
} else {
|
|
42
|
+
// "latest", "earliest", and "pending" require no manipulation
|
|
43
|
+
rpcTimeFrame = timeFrame;
|
|
44
|
+
}
|
|
45
|
+
const req = async (): Promise<RPCBlock> => {
|
|
46
|
+
return await post(
|
|
47
|
+
this._rpcUrl[this._rpcUrlCounter],
|
|
48
|
+
buildRPCPostBody('eth_getBlockByNumber', [
|
|
49
|
+
rpcTimeFrame,
|
|
50
|
+
returnTransactionObjects,
|
|
51
|
+
]),
|
|
52
|
+
).catch((e) => {
|
|
53
|
+
if (e.code === 'ENOTFOUND') {
|
|
54
|
+
this._rpcUrlCounter++;
|
|
55
|
+
return req();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
const nodeResponse = (await req()) as RPCBlock;
|
|
60
|
+
|
|
61
|
+
return cleanBlock(nodeResponse, returnTransactionObjects);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns the network this provider is connected to
|
|
65
|
+
*/
|
|
66
|
+
public async getNetwork(): Promise<Network> {
|
|
67
|
+
const req = async (): Promise<string> => {
|
|
68
|
+
return await post(
|
|
69
|
+
this._rpcUrl[this._rpcUrlCounter],
|
|
70
|
+
buildRPCPostBody('eth_chainId', []),
|
|
71
|
+
).catch((e) => {
|
|
72
|
+
if (e.code === 'ENOTFOUND') {
|
|
73
|
+
this._rpcUrlCounter++;
|
|
74
|
+
return req();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const nodeResponse = (await req()) as string;
|
|
79
|
+
const chainId = hexToDecimal(nodeResponse);
|
|
80
|
+
const info = (chainsInfo as any)[chainId];
|
|
81
|
+
return {
|
|
82
|
+
chainId: Number(chainId),
|
|
83
|
+
name: info[0] || 'unknown',
|
|
84
|
+
ensAddress: info[1] || null, // only send ensAddress if it exists
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Helper function to avoid "new"
|
|
91
|
+
*/
|
|
92
|
+
export function jsonRpcProvider(rpcUrl?: string) {
|
|
93
|
+
return new JsonRpcProvider(rpcUrl);
|
|
94
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import omit from 'just-omit';
|
|
3
|
+
import Web3 from 'web3';
|
|
4
|
+
import { Block, JsonRpcProvider } from '../..';
|
|
5
|
+
|
|
6
|
+
const rpcUrl = `${process.env.RPC_ORIGIN}/api/eth`;
|
|
7
|
+
|
|
8
|
+
describe('matches web3', () => {
|
|
9
|
+
function testBlockEquality(block1: Block, block2: Block) {
|
|
10
|
+
// slight mis-timing in eth node responses
|
|
11
|
+
expect(
|
|
12
|
+
(omit as any)(block1, ['totalDifficulty', 'difficulty']),
|
|
13
|
+
).toStrictEqual((omit as any)(block2, ['totalDifficulty', 'difficulty']));
|
|
14
|
+
|
|
15
|
+
// validate that difficulty and totalDifficulty are still very close
|
|
16
|
+
expect(
|
|
17
|
+
Big(block1.difficulty).minus(block2.difficulty).abs().toNumber(),
|
|
18
|
+
).toBeLessThan(3);
|
|
19
|
+
|
|
20
|
+
expect(
|
|
21
|
+
Big(block1.totalDifficulty)
|
|
22
|
+
.minus(block2.totalDifficulty)
|
|
23
|
+
.abs()
|
|
24
|
+
.toNumber(),
|
|
25
|
+
).toBeLessThan(5000000 /* 2616793 and 1187442 on recent tests */);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
it('should get latest block', async () => {
|
|
29
|
+
const essentialEth = new JsonRpcProvider(rpcUrl);
|
|
30
|
+
const web3 = new Web3(rpcUrl);
|
|
31
|
+
const [eeLatestBlock, web3LatestBlock] = await Promise.all([
|
|
32
|
+
essentialEth.getBlock('latest'),
|
|
33
|
+
web3.eth.getBlock('latest'),
|
|
34
|
+
]);
|
|
35
|
+
testBlockEquality(eeLatestBlock, web3LatestBlock as unknown as Block);
|
|
36
|
+
});
|
|
37
|
+
it('should get latest block, uses fallback when first URL fails', async () => {
|
|
38
|
+
const essentialEth = new JsonRpcProvider([
|
|
39
|
+
'https://invalid-url.test',
|
|
40
|
+
rpcUrl,
|
|
41
|
+
]);
|
|
42
|
+
await essentialEth.getBlock('latest');
|
|
43
|
+
});
|
|
44
|
+
it('should get earliest block', async () => {
|
|
45
|
+
const essentialEth = new JsonRpcProvider(rpcUrl);
|
|
46
|
+
const web3 = new Web3(rpcUrl);
|
|
47
|
+
const [eeEarliestBlock, web3EarliestBlock] = await Promise.all([
|
|
48
|
+
essentialEth.getBlock('earliest'),
|
|
49
|
+
web3.eth.getBlock('earliest'),
|
|
50
|
+
]);
|
|
51
|
+
testBlockEquality(eeEarliestBlock, web3EarliestBlock as unknown as Block);
|
|
52
|
+
});
|
|
53
|
+
const blockNumber = Math.floor(Math.random() * 13250630);
|
|
54
|
+
it(`should get random block as decimal integer. (block #${blockNumber})`, async () => {
|
|
55
|
+
const essentialEth = new JsonRpcProvider(rpcUrl);
|
|
56
|
+
const web3 = new Web3(rpcUrl);
|
|
57
|
+
const [eeRandomBlock, web3RandomBlock] = await Promise.all([
|
|
58
|
+
essentialEth.getBlock(blockNumber, true),
|
|
59
|
+
web3.eth.getBlock(blockNumber, true),
|
|
60
|
+
]);
|
|
61
|
+
testBlockEquality(eeRandomBlock, web3RandomBlock as unknown as Block);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { JsonRpcProvider } from '../..';
|
|
3
|
+
|
|
4
|
+
const xdaiRPCUrl = `${process.env.RPC_ORIGIN}/api/xdai`;
|
|
5
|
+
const bscRPCUrl = `${process.env.RPC_ORIGIN}/api/bsc`;
|
|
6
|
+
// const kovanRPCUrl = `${process.env.RPC_ORIGIN}/api/kovan`;
|
|
7
|
+
|
|
8
|
+
describe('get-network', () => {
|
|
9
|
+
async function testNetwork(rpcUrl: string) {
|
|
10
|
+
const essentialEth = new JsonRpcProvider(rpcUrl);
|
|
11
|
+
const ethersProvider = new ethers.providers.StaticJsonRpcProvider(rpcUrl);
|
|
12
|
+
const [eeNetwork, ethersNetwork] = await Promise.all([
|
|
13
|
+
essentialEth.getNetwork(),
|
|
14
|
+
ethersProvider.getNetwork(),
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
expect(eeNetwork.chainId).toBe(ethersNetwork.chainId);
|
|
18
|
+
expect(eeNetwork.ensAddress).toBe(ethersNetwork.ensAddress);
|
|
19
|
+
expect(eeNetwork.name).toBe(
|
|
20
|
+
// xdai was renamed to gnosis but ethers is still out-of-date
|
|
21
|
+
ethersNetwork.name === 'xdai' ? 'gno' : ethersNetwork.name,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
it('xdai should match ethers', async () => {
|
|
25
|
+
await testNetwork(xdaiRPCUrl);
|
|
26
|
+
});
|
|
27
|
+
it('bsc should match ethers', async () => {
|
|
28
|
+
await testNetwork(bscRPCUrl);
|
|
29
|
+
});
|
|
30
|
+
/* ethers returns "kovan", essential-eth returns "kov" */
|
|
31
|
+
// it('kovan should match ethers', async () => {
|
|
32
|
+
// await testNetwork(kovanRPCUrl);
|
|
33
|
+
// });
|
|
34
|
+
});
|