diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6c4b9d4..bc093cd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,6 +50,49 @@ jobs: - name: Run tests run: cd js && pnpm test + format_and_lint_js_v1: + name: Format & Lint JS (web3.js v1) + runs-on: ubuntu-latest + steps: + - name: Git Checkout + uses: actions/checkout@v4 + + - name: Setup Environment + uses: ./.github/actions/setup + with: + js: true + + - name: Install Dependencies + run: cd js-v1 && pnpm install --frozen-lockfile + + - name: Format + run: cd js-v1 && pnpm format + + - name: Lint + run: cd js-v1 && pnpm lint + + test_js_v1: + name: Test JS (web3.js v1) + runs-on: ubuntu-latest + needs: format_and_lint_js + steps: + - name: Git Checkout + uses: actions/checkout@v4 + + - name: Setup Environment + uses: ./.github/actions/setup + with: + js: true + + - name: Install Dependencies + run: cd js-v1 && pnpm install --frozen-lockfile + + - name: Build code + run: cd js-v1 && pnpm build + + - name: Run tests + run: cd js-v1 && pnpm test + format_and_lint_rust: name: Format & Lint Rust runs-on: ubuntu-latest diff --git a/web3js-1.0/.eslintrc.cjs b/js-v1/.eslintrc.cjs similarity index 100% rename from web3js-1.0/.eslintrc.cjs rename to js-v1/.eslintrc.cjs diff --git a/web3js-1.0/.prettierrc.json b/js-v1/.prettierrc.json similarity index 100% rename from web3js-1.0/.prettierrc.json rename to js-v1/.prettierrc.json diff --git a/web3js-1.0/env-shim.ts b/js-v1/env-shim.ts similarity index 100% rename from web3js-1.0/env-shim.ts rename to js-v1/env-shim.ts diff --git a/web3js-1.0/examples/example.ts b/js-v1/examples/example.ts similarity index 100% rename from web3js-1.0/examples/example.ts rename to js-v1/examples/example.ts diff --git a/web3js-1.0/package.json b/js-v1/package.json similarity index 96% rename from web3js-1.0/package.json rename to js-v1/package.json index 35001bc..5518c68 100644 --- a/web3js-1.0/package.json +++ b/js-v1/package.json @@ -1,6 +1,6 @@ { "name": "@anza-xyz/solana-rpc-get-stake-activation", - "version": "1.0.0", + "version": "1.0.1", "description": "Client-side replica of Solana RPC's getStakeActivation", "sideEffects": false, "module": "./dist/src/index.mjs", @@ -52,6 +52,7 @@ }, "devDependencies": { "@ava/typescript": "^4.1.0", + "@solana/eslint-config-solana": "^3.0.3", "@types/node": "^20", "@typescript-eslint/eslint-plugin": "^7.16.1", "@typescript-eslint/parser": "^7.16.1", diff --git a/web3js-1.0/pnpm-lock.yaml b/js-v1/pnpm-lock.yaml similarity index 90% rename from web3js-1.0/pnpm-lock.yaml rename to js-v1/pnpm-lock.yaml index 16bba5c..94f79a2 100644 --- a/web3js-1.0/pnpm-lock.yaml +++ b/js-v1/pnpm-lock.yaml @@ -15,6 +15,9 @@ importers: '@ava/typescript': specifier: ^4.1.0 version: 4.1.0 + '@solana/eslint-config-solana': + specifier: ^3.0.3 + version: 3.0.6(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-jest@27.9.0(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-react-hooks@4.6.2(eslint@8.57.0))(eslint-plugin-simple-import-sort@12.1.1(eslint@8.57.0))(eslint-plugin-sort-keys-fix@1.1.2)(eslint-plugin-typescript-sort-keys@3.3.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) '@types/node': specifier: ^20 version: 20.16.1 @@ -375,6 +378,19 @@ packages: resolution: {integrity: sha512-E1ImOIAD1tBZFRdjeM4/pzTiTApC0AOBGwyAMS4fwIodCWArzJ3DWdoh8cKxeFM2fElkxBh2Aqts1BPC373rHA==} engines: {node: '>=5.10'} + '@solana/eslint-config-solana@3.0.6': + resolution: {integrity: sha512-3u024DkukJCfzUfOgN1EmWzVZLaZtgRLJ52FEdQmIG8NYOzLpaIJFgQvjYXWQlnK6ycIcSn/MesHG6sbKkMtTQ==} + peerDependencies: + '@typescript-eslint/eslint-plugin': ^7.0.0 + '@typescript-eslint/parser': ^7.0.0 + eslint: ^8.45.0 + eslint-plugin-jest: ^27.2.3 + eslint-plugin-react-hooks: ^4.6.0 + eslint-plugin-simple-import-sort: ^12.0.0 + eslint-plugin-sort-keys-fix: ^1.1.2 + eslint-plugin-typescript-sort-keys: ^3.2.0 + typescript: ^5.1.6 + '@solana/web3.js@1.95.3': resolution: {integrity: sha512-O6rPUN0w2fkNqx/Z3QJMB9L225Ex10PRDH8bTaIUPZXMPV0QP8ZpPvjQnXK+upUczlRgzHzd6SjKIha1p+I6og==} @@ -387,12 +403,18 @@ packages: '@types/estree@1.0.5': resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==} + '@types/json-schema@7.0.15': + resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} + '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} '@types/node@20.16.1': resolution: {integrity: sha512-zJDo7wEadFtSyNz5QITDfRcrhqDvQI1xQNQ0VoizPjM/dVAODqqIUWbJPkvsxmTI0MYRGRikcdjMPhOssnPejQ==} + '@types/semver@7.5.8': + resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==} + '@types/uuid@8.3.4': resolution: {integrity: sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==} @@ -413,6 +435,12 @@ packages: typescript: optional: true + '@typescript-eslint/experimental-utils@5.62.0': + resolution: {integrity: sha512-RTXpeB3eMkpoclG3ZHft6vG/Z30azNHuqY6wKPBHlVMZFuEvrtlEDe8gMqDb+SO+9hjC/pLekeSCryf9vMZlCw==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + '@typescript-eslint/parser@7.18.0': resolution: {integrity: sha512-4Z+L8I2OqhZV8qA132M4wNL30ypZGYOQVBfMgxDH/K5UX0PNqTu1c6za9ST5r9+tavvHiTWmBnKzpCJ/GlVFtg==} engines: {node: ^18.18.0 || >=20.0.0} @@ -423,6 +451,10 @@ packages: typescript: optional: true + '@typescript-eslint/scope-manager@5.62.0': + resolution: {integrity: sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + '@typescript-eslint/scope-manager@7.18.0': resolution: {integrity: sha512-jjhdIE/FPF2B7Z1uzc6i3oWKbGcHb87Qw7AWj6jmEqNOfDFbJWtjt/XfwCpvNkpGWlcJaog5vTR+VV8+w9JflA==} engines: {node: ^18.18.0 || >=20.0.0} @@ -437,10 +469,23 @@ packages: typescript: optional: true + '@typescript-eslint/types@5.62.0': + resolution: {integrity: sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + '@typescript-eslint/types@7.18.0': resolution: {integrity: sha512-iZqi+Ds1y4EDYUtlOOC+aUmxnE9xS/yCigkjA7XpTKV6nCBd3Hp/PRGGmdwnfkV2ThMyYldP1wRpm/id99spTQ==} engines: {node: ^18.18.0 || >=20.0.0} + '@typescript-eslint/typescript-estree@5.62.0': + resolution: {integrity: sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + '@typescript-eslint/typescript-estree@7.18.0': resolution: {integrity: sha512-aP1v/BSPnnyhMHts8cf1qQ6Q1IFwwRvAQGRvBFkWlo3/lH29OXA3Pts+c10nxRxIBrDnoMqzhgdwVe5f2D6OzA==} engines: {node: ^18.18.0 || >=20.0.0} @@ -450,12 +495,22 @@ packages: typescript: optional: true + '@typescript-eslint/utils@5.62.0': + resolution: {integrity: sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + '@typescript-eslint/utils@7.18.0': resolution: {integrity: sha512-kK0/rNa2j74XuHVcoCZxdFBMF+aq/vH83CXAOHieC+2Gis4mF8jJXT5eAfyD3K0sAxtPuwxaIOIOvhwzVDt/kw==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: eslint: ^8.56.0 + '@typescript-eslint/visitor-keys@5.62.0': + resolution: {integrity: sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + '@typescript-eslint/visitor-keys@7.18.0': resolution: {integrity: sha512-cDF0/Gf81QpY3xYyJKDV14Zwdmid5+uuENhjH2EqFaF0ni+yAyq/LzMaIJdhNJXZI7uLzwIlA+V7oWoyn6Curg==} engines: {node: ^18.18.0 || >=20.0.0} @@ -489,6 +544,11 @@ packages: resolution: {integrity: sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==} engines: {node: '>=0.4.0'} + acorn@7.4.1: + resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==} + engines: {node: '>=0.4.0'} + hasBin: true + acorn@8.12.1: resolution: {integrity: sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==} engines: {node: '>=0.4.0'} @@ -808,10 +868,54 @@ packages: resolution: {integrity: sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==} engines: {node: '>=12'} + eslint-plugin-jest@27.9.0: + resolution: {integrity: sha512-QIT7FH7fNmd9n4se7FFKHbsLKGQiw885Ds6Y/sxKgCZ6natwCsXdgPOADnYVxN2QrRweF0FZWbJ6S7Rsn7llug==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + peerDependencies: + '@typescript-eslint/eslint-plugin': ^5.0.0 || ^6.0.0 || ^7.0.0 + eslint: ^7.0.0 || ^8.0.0 + jest: '*' + peerDependenciesMeta: + '@typescript-eslint/eslint-plugin': + optional: true + jest: + optional: true + + eslint-plugin-react-hooks@4.6.2: + resolution: {integrity: sha512-QzliNJq4GinDBcD8gPB5v0wh6g8q3SUi6EFF0x8N/BL9PoVs0atuGc47ozMRyOWAKdwaZ5OnbOEa3WR+dSGKuQ==} + engines: {node: '>=10'} + peerDependencies: + eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 + + eslint-plugin-simple-import-sort@12.1.1: + resolution: {integrity: sha512-6nuzu4xwQtE3332Uz0to+TxDQYRLTKRESSc2hefVT48Zc8JthmN23Gx9lnYhu0FtkRSL1oxny3kJ2aveVhmOVA==} + peerDependencies: + eslint: '>=5.0.0' + + eslint-plugin-sort-keys-fix@1.1.2: + resolution: {integrity: sha512-DNPHFGCA0/hZIsfODbeLZqaGY/+q3vgtshF85r+YWDNCQ2apd9PNs/zL6ttKm0nD1IFwvxyg3YOTI7FHl4unrw==} + engines: {node: '>=0.10.0'} + + eslint-plugin-typescript-sort-keys@3.3.0: + resolution: {integrity: sha512-bRW3Rc/VNdrSP9OoY5wgjjaXCOOkZKpzvl/Mk6l8Sg8CMehVIcg9K4y33l+ZcZiknpl0aR6rKusxuCJNGZWmVw==} + engines: {node: '>= 16'} + peerDependencies: + '@typescript-eslint/parser': '>=6' + eslint: ^7 || ^8 + typescript: ^3 || ^4 || ^5 + + eslint-scope@5.1.1: + resolution: {integrity: sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==} + engines: {node: '>=8.0.0'} + eslint-scope@7.2.2: resolution: {integrity: sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + eslint-visitor-keys@1.3.0: + resolution: {integrity: sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==} + engines: {node: '>=4'} + eslint-visitor-keys@3.4.3: resolution: {integrity: sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -821,6 +925,10 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} hasBin: true + espree@6.2.1: + resolution: {integrity: sha512-ysCxRQY3WaXJz9tdbWOwuWr5Y/XrPTGX9Kiz3yoUXwW0VZ4w30HTkQLaGx/+ttFjF8i+ACbArnB4ce68a9m5hw==} + engines: {node: '>=6.0.0'} + espree@9.6.1: resolution: {integrity: sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -838,6 +946,10 @@ packages: resolution: {integrity: sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==} engines: {node: '>=4.0'} + estraverse@4.3.0: + resolution: {integrity: sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==} + engines: {node: '>=4.0'} + estraverse@5.3.0: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} @@ -1124,6 +1236,9 @@ packages: json-schema-traverse@0.4.1: resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==} + json-schema@0.4.0: + resolution: {integrity: sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==} + json-stable-stringify-without-jsonify@1.0.1: resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==} @@ -1259,6 +1374,9 @@ packages: mz@2.7.0: resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==} + natural-compare-lite@1.4.0: + resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==} + natural-compare@1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} @@ -1446,6 +1564,10 @@ packages: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} + requireindex@1.2.0: + resolution: {integrity: sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==} + engines: {node: '>=0.10.5'} + resolve-cwd@3.0.0: resolution: {integrity: sha512-OrZaX2Mb+rJCpH/6CpSqt9xFVpN++x01XnN2ie9g6P5/3xelLAkXWVADpdz1IHD/KFfEXyE6V0U01OQ3UO2rEg==} engines: {node: '>=8'} @@ -1645,6 +1767,9 @@ packages: ts-interface-checker@0.1.13: resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} + tslib@1.14.1: + resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} + tslib@2.7.0: resolution: {integrity: sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==} @@ -1667,6 +1792,12 @@ packages: typescript: optional: true + tsutils@3.21.0: + resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} + engines: {node: '>= 6'} + peerDependencies: + typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' + type-check@0.4.0: resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} engines: {node: '>= 0.8.0'} @@ -2048,6 +2179,18 @@ snapshots: dependencies: buffer: 6.0.3 + '@solana/eslint-config-solana@3.0.6(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-jest@27.9.0(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-react-hooks@4.6.2(eslint@8.57.0))(eslint-plugin-simple-import-sort@12.1.1(eslint@8.57.0))(eslint-plugin-sort-keys-fix@1.1.2)(eslint-plugin-typescript-sort-keys@3.3.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4)': + dependencies: + '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + eslint: 8.57.0 + eslint-plugin-jest: 27.9.0(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) + eslint-plugin-react-hooks: 4.6.2(eslint@8.57.0) + eslint-plugin-simple-import-sort: 12.1.1(eslint@8.57.0) + eslint-plugin-sort-keys-fix: 1.1.2 + eslint-plugin-typescript-sort-keys: 3.3.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) + typescript: 5.5.4 + '@solana/web3.js@1.95.3(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: '@babel/runtime': 7.25.4 @@ -2080,12 +2223,16 @@ snapshots: '@types/estree@1.0.5': {} + '@types/json-schema@7.0.15': {} + '@types/node@12.20.55': {} '@types/node@20.16.1': dependencies: undici-types: 6.19.8 + '@types/semver@7.5.8': {} + '@types/uuid@8.3.4': {} '@types/ws@7.4.7': @@ -2114,6 +2261,14 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/experimental-utils@5.62.0(eslint@8.57.0)(typescript@5.5.4)': + dependencies: + '@typescript-eslint/utils': 5.62.0(eslint@8.57.0)(typescript@5.5.4) + eslint: 8.57.0 + transitivePeerDependencies: + - supports-color + - typescript + '@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4)': dependencies: '@typescript-eslint/scope-manager': 7.18.0 @@ -2127,6 +2282,11 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/scope-manager@5.62.0': + dependencies: + '@typescript-eslint/types': 5.62.0 + '@typescript-eslint/visitor-keys': 5.62.0 + '@typescript-eslint/scope-manager@7.18.0': dependencies: '@typescript-eslint/types': 7.18.0 @@ -2144,8 +2304,24 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/types@5.62.0': {} + '@typescript-eslint/types@7.18.0': {} + '@typescript-eslint/typescript-estree@5.62.0(typescript@5.5.4)': + dependencies: + '@typescript-eslint/types': 5.62.0 + '@typescript-eslint/visitor-keys': 5.62.0 + debug: 4.3.6 + globby: 11.1.0 + is-glob: 4.0.3 + semver: 7.6.3 + tsutils: 3.21.0(typescript@5.5.4) + optionalDependencies: + typescript: 5.5.4 + transitivePeerDependencies: + - supports-color + '@typescript-eslint/typescript-estree@7.18.0(typescript@5.5.4)': dependencies: '@typescript-eslint/types': 7.18.0 @@ -2161,6 +2337,21 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/utils@5.62.0(eslint@8.57.0)(typescript@5.5.4)': + dependencies: + '@eslint-community/eslint-utils': 4.4.0(eslint@8.57.0) + '@types/json-schema': 7.0.15 + '@types/semver': 7.5.8 + '@typescript-eslint/scope-manager': 5.62.0 + '@typescript-eslint/types': 5.62.0 + '@typescript-eslint/typescript-estree': 5.62.0(typescript@5.5.4) + eslint: 8.57.0 + eslint-scope: 5.1.1 + semver: 7.6.3 + transitivePeerDependencies: + - supports-color + - typescript + '@typescript-eslint/utils@7.18.0(eslint@8.57.0)(typescript@5.5.4)': dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@8.57.0) @@ -2172,6 +2363,11 @@ snapshots: - supports-color - typescript + '@typescript-eslint/visitor-keys@5.62.0': + dependencies: + '@typescript-eslint/types': 5.62.0 + eslint-visitor-keys: 3.4.3 + '@typescript-eslint/visitor-keys@7.18.0': dependencies: '@typescript-eslint/types': 7.18.0 @@ -2208,6 +2404,10 @@ snapshots: dependencies: acorn: 8.12.1 + acorn-jsx@5.3.2(acorn@7.4.1): + dependencies: + acorn: 7.4.1 + acorn-jsx@5.3.2(acorn@8.12.1): dependencies: acorn: 8.12.1 @@ -2216,6 +2416,8 @@ snapshots: dependencies: acorn: 8.12.1 + acorn@7.4.1: {} + acorn@8.12.1: {} agent-base@6.0.2: @@ -2555,11 +2757,54 @@ snapshots: escape-string-regexp@5.0.0: {} + eslint-plugin-jest@27.9.0(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4): + dependencies: + '@typescript-eslint/utils': 5.62.0(eslint@8.57.0)(typescript@5.5.4) + eslint: 8.57.0 + optionalDependencies: + '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) + transitivePeerDependencies: + - supports-color + - typescript + + eslint-plugin-react-hooks@4.6.2(eslint@8.57.0): + dependencies: + eslint: 8.57.0 + + eslint-plugin-simple-import-sort@12.1.1(eslint@8.57.0): + dependencies: + eslint: 8.57.0 + + eslint-plugin-sort-keys-fix@1.1.2: + dependencies: + espree: 6.2.1 + esutils: 2.0.3 + natural-compare: 1.4.0 + requireindex: 1.2.0 + + eslint-plugin-typescript-sort-keys@3.3.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4): + dependencies: + '@typescript-eslint/experimental-utils': 5.62.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + eslint: 8.57.0 + json-schema: 0.4.0 + natural-compare-lite: 1.4.0 + typescript: 5.5.4 + transitivePeerDependencies: + - supports-color + + eslint-scope@5.1.1: + dependencies: + esrecurse: 4.3.0 + estraverse: 4.3.0 + eslint-scope@7.2.2: dependencies: esrecurse: 4.3.0 estraverse: 5.3.0 + eslint-visitor-keys@1.3.0: {} + eslint-visitor-keys@3.4.3: {} eslint@8.57.0: @@ -2605,6 +2850,12 @@ snapshots: transitivePeerDependencies: - supports-color + espree@6.2.1: + dependencies: + acorn: 7.4.1 + acorn-jsx: 5.3.2(acorn@7.4.1) + eslint-visitor-keys: 1.3.0 + espree@9.6.1: dependencies: acorn: 8.12.1 @@ -2621,6 +2872,8 @@ snapshots: dependencies: estraverse: 5.3.0 + estraverse@4.3.0: {} + estraverse@5.3.0: {} estree-walker@2.0.2: {} @@ -2908,6 +3161,8 @@ snapshots: json-schema-traverse@0.4.1: {} + json-schema@0.4.0: {} + json-stable-stringify-without-jsonify@1.0.1: {} json-stringify-safe@5.0.1: {} @@ -3013,6 +3268,8 @@ snapshots: object-assign: 4.1.1 thenify-all: 1.6.0 + natural-compare-lite@1.4.0: {} + natural-compare@1.4.0: {} node-fetch@2.7.0: @@ -3149,6 +3406,8 @@ snapshots: require-directory@2.1.1: {} + requireindex@1.2.0: {} + resolve-cwd@3.0.0: dependencies: resolve-from: 5.0.0 @@ -3358,6 +3617,8 @@ snapshots: ts-interface-checker@0.1.13: {} + tslib@1.14.1: {} + tslib@2.7.0: {} tsup@8.2.4(typescript@5.5.4): @@ -3386,6 +3647,11 @@ snapshots: - tsx - yaml + tsutils@3.21.0(typescript@5.5.4): + dependencies: + tslib: 1.14.1 + typescript: 5.5.4 + type-check@0.4.0: dependencies: prelude-ls: 1.2.1 diff --git a/web3js-1.0/src/delegation.ts b/js-v1/src/delegation.ts similarity index 97% rename from web3js-1.0/src/delegation.ts rename to js-v1/src/delegation.ts index 0aee1c4..e02328c 100644 --- a/web3js-1.0/src/delegation.ts +++ b/js-v1/src/delegation.ts @@ -1,4 +1,4 @@ -import { Delegation, StakeHistoryEntry } from "./stake"; +import { Delegation, StakeHistoryEntry } from './stake'; export interface StakeActivatingAndDeactivating { effective: bigint; @@ -36,7 +36,7 @@ export function getStakeAndActivating( effective: BigInt(0), activating: BigInt(0), }; - } else if (targetEpoch === delegation.activationEpoch) { + } else if (targetEpoch === delegation.activationEpoch) { // all is activating return { effective: BigInt(0), @@ -172,4 +172,4 @@ export function getStakeActivatingAndDeactivating( deactivating: BigInt(0), }; } -} \ No newline at end of file +} diff --git a/web3js-1.0/src/index.ts b/js-v1/src/index.ts similarity index 100% rename from web3js-1.0/src/index.ts rename to js-v1/src/index.ts diff --git a/js-v1/src/rpc.ts b/js-v1/src/rpc.ts new file mode 100644 index 0000000..2301052 --- /dev/null +++ b/js-v1/src/rpc.ts @@ -0,0 +1,74 @@ +import { Connection, PublicKey } from '@solana/web3.js'; +import { getStakeAccount, getStakeHistory } from './stake'; +import { getStakeActivatingAndDeactivating } from './delegation'; + +export interface StakeActivation { + status: string; + active: bigint; + inactive: bigint; +} + +export async function getStakeActivation( + connection: Connection, + stakeAddress: PublicKey +): Promise { + const SYSVAR_STAKE_HISTORY_ADDRESS = new PublicKey( + 'SysvarStakeHistory1111111111111111111111111' + ); + const [epochInfo, { stakeAccount, stakeAccountLamports }, stakeHistory] = + await Promise.all([ + connection.getEpochInfo(), + (async () => { + const stakeAccountParsed = + await connection.getParsedAccountInfo(stakeAddress); + if (stakeAccountParsed === null || stakeAccountParsed.value === null) { + throw new Error('Account not found'); + } + const stakeAccount = getStakeAccount(stakeAccountParsed); + const stakeAccountLamports = stakeAccountParsed.value.lamports; + return { stakeAccount, stakeAccountLamports }; + })(), + (async () => { + const stakeHistoryParsed = await connection.getParsedAccountInfo( + SYSVAR_STAKE_HISTORY_ADDRESS + ); + if (stakeHistoryParsed === null) { + throw new Error('StakeHistory not found'); + } + return getStakeHistory(stakeHistoryParsed); + })(), + ]); + + const { effective, activating, deactivating } = stakeAccount.stake + ? getStakeActivatingAndDeactivating( + stakeAccount.stake.delegation, + BigInt(epochInfo.epoch), + stakeHistory + ) + : { + effective: BigInt(0), + activating: BigInt(0), + deactivating: BigInt(0), + }; + + let status; + if (deactivating > 0) { + status = 'deactivating'; + } else if (activating > 0) { + status = 'activating'; + } else if (effective > 0) { + status = 'active'; + } else { + status = 'inactive'; + } + const inactive = + BigInt(stakeAccountLamports) - + effective - + stakeAccount.meta.rentExemptReserve; + + return { + status, + active: effective, + inactive, + }; +} diff --git a/js-v1/src/stake.ts b/js-v1/src/stake.ts new file mode 100644 index 0000000..aef6592 --- /dev/null +++ b/js-v1/src/stake.ts @@ -0,0 +1,130 @@ +import { + AccountInfo, + ParsedAccountData, + RpcResponseAndContext, +} from '@solana/web3.js'; + +export type StakeHistoryEntry = { + epoch: bigint; + effective: bigint; + activating: bigint; + deactivating: bigint; +}; + +export type Delegation = { + voterPubkey: Uint8Array; + stake: bigint; + activationEpoch: bigint; + deactivationEpoch: bigint; +}; + +export type StakeAccount = { + discriminant: bigint; + meta: { + rentExemptReserve: bigint; + authorized: { + staker: Uint8Array; + withdrawer: Uint8Array; + }; + lockup: { + unixTimestamp: bigint; + epoch: bigint; + custodian: Uint8Array; + }; + }; + stake: { + delegation: Delegation; + creditsObserved: bigint; + } | null; +}; + +type StakeHistoryEntryRaw = { + epoch: number; + stakeHistory: { + effective: number; + activating: number; + deactivating: number; + }; +}; + +export const getStakeHistory = function ( + parsedData: RpcResponseAndContext | null> +): StakeHistoryEntry[] { + if (parsedData.value === null || parsedData.value.data instanceof Buffer) { + throw new Error('Account not found'); + } + + const stakeHistory: StakeHistoryEntry[] = []; + + parsedData.value.data.parsed.info.forEach((entry: StakeHistoryEntryRaw) => { + stakeHistory.push({ + epoch: BigInt(entry.epoch), + effective: BigInt(entry.stakeHistory.effective), + activating: BigInt(entry.stakeHistory.activating), + deactivating: BigInt(entry.stakeHistory.deactivating), + }); + }); + + return stakeHistory; +}; + +export const getStakeAccount = function ( + parsedData: RpcResponseAndContext | null> +): StakeAccount { + if (parsedData.value === null || parsedData.value.data instanceof Buffer) { + throw new Error('Account not found'); + } + + let discriminant = BigInt(0); + if (parsedData.value.data.parsed.type === 'initialized') { + discriminant = BigInt(1); + } else if (parsedData.value.data.parsed.type === 'delegated') { + discriminant = BigInt(2); + } + + return { + discriminant: discriminant, + meta: { + rentExemptReserve: BigInt( + parsedData.value.data.parsed.info.meta.rentExemptReserve + ), + authorized: { + staker: parsedData.value.data.parsed.info.meta.authorized.staker, + withdrawer: + parsedData.value.data.parsed.info.meta.authorized.withdrawer, + }, + lockup: { + unixTimestamp: BigInt( + parsedData.value.data.parsed.info.meta.lockup.unixTimestamp + ), + epoch: BigInt(parsedData.value.data.parsed.info.meta.lockup.epoch), + custodian: parsedData.value.data.parsed.info.meta.lockup.custodian, + }, + }, + stake: parsedData.value.data.parsed.info.stake + ? { + delegation: { + voterPubkey: + parsedData.value.data.parsed.info.stake.delegation.voterPubkey, + stake: BigInt( + parsedData.value.data.parsed.info.stake.delegation.stake + ), + activationEpoch: BigInt( + parsedData.value.data.parsed.info.stake.delegation.activationEpoch + ), + deactivationEpoch: BigInt( + parsedData.value.data.parsed.info.stake.delegation + .deactivationEpoch + ), + }, + creditsObserved: BigInt( + parsedData.value.data.parsed.info.stake.creditsObserved + ), + } + : null, + }; +}; diff --git a/web3js-1.0/test/delegation.test.ts b/js-v1/test/delegation.test.ts similarity index 100% rename from web3js-1.0/test/delegation.test.ts rename to js-v1/test/delegation.test.ts diff --git a/web3js-1.0/tsconfig.declarations.json b/js-v1/tsconfig.declarations.json similarity index 100% rename from web3js-1.0/tsconfig.declarations.json rename to js-v1/tsconfig.declarations.json diff --git a/web3js-1.0/tsconfig.json b/js-v1/tsconfig.json similarity index 100% rename from web3js-1.0/tsconfig.json rename to js-v1/tsconfig.json diff --git a/web3js-1.0/tsup.config.ts b/js-v1/tsup.config.ts similarity index 100% rename from web3js-1.0/tsup.config.ts rename to js-v1/tsup.config.ts diff --git a/web3js-1.0/src/rpc.ts b/web3js-1.0/src/rpc.ts deleted file mode 100644 index e62e9ac..0000000 --- a/web3js-1.0/src/rpc.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Connection, PublicKey } from "@solana/web3.js"; -import { getStakeAccount, getStakeHistory } from "./stake"; -import { getStakeActivatingAndDeactivating } from "./delegation"; - -export interface StakeActivation { - status: string; - active: bigint; - inactive: bigint; -} - -export async function getStakeActivation( - connection: Connection, - stakeAddress: PublicKey -): Promise { - const SYSVAR_STAKE_HISTORY_ADDRESS = new PublicKey("SysvarStakeHistory1111111111111111111111111"); - const [epochInfo, { stakeAccount, stakeAccountLamports }, stakeHistory] = await Promise.all([ - connection.getEpochInfo(), - (async () => { - const stakeAccountParsed = await connection.getParsedAccountInfo(stakeAddress); - if (stakeAccountParsed === null || stakeAccountParsed.value === null) { - throw new Error("Account not found"); - } - const stakeAccount = getStakeAccount(stakeAccountParsed); - const stakeAccountLamports = stakeAccountParsed.value.lamports; - return { stakeAccount, stakeAccountLamports }; - })(), - (async () => { - const stakeHistoryParsed = await connection.getParsedAccountInfo(SYSVAR_STAKE_HISTORY_ADDRESS); - if (stakeHistoryParsed === null) { - throw new Error("StakeHistory not found"); - } - return getStakeHistory(stakeHistoryParsed); - })(), - ]); - - const { effective, activating, deactivating } = stakeAccount.stake ? - getStakeActivatingAndDeactivating( - stakeAccount.stake.delegation, - BigInt(epochInfo.epoch), - stakeHistory - ) : { - effective: BigInt(0), - activating: BigInt(0), - deactivating: BigInt(0), - }; - - let status; - if (deactivating > 0) { - status = 'deactivating'; - } else if (activating > 0) { - status = 'activating'; - } else if (effective > 0) { - status = 'active'; - } else { - status = 'inactive'; - } - const inactive = BigInt(stakeAccountLamports) - effective - stakeAccount.meta.rentExemptReserve; - - return { - status, - active: effective, - inactive, - }; -} \ No newline at end of file diff --git a/web3js-1.0/src/stake.ts b/web3js-1.0/src/stake.ts deleted file mode 100644 index f620489..0000000 --- a/web3js-1.0/src/stake.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { AccountInfo, ParsedAccountData, RpcResponseAndContext } from "@solana/web3.js" - -export type StakeHistoryEntry = { - epoch: bigint, - effective: bigint, - activating: bigint, - deactivating: bigint -} - -export type Delegation = { - voterPubkey: Uint8Array, - stake: bigint, - activationEpoch: bigint, - deactivationEpoch: bigint, -} - -export type StakeAccount = { - discriminant: bigint, - meta: { - rentExemptReserve: bigint, - authorized: { - staker: Uint8Array, - withdrawer: Uint8Array - }, - lockup: { - unixTimestamp: bigint, - epoch: bigint, - custodian: Uint8Array - } - }, - stake: { - delegation: Delegation, - creditsObserved: bigint - } | null -} - -export const getStakeHistory = function (parsedData: RpcResponseAndContext | null>): StakeHistoryEntry[] { - if (parsedData.value === null || parsedData.value.data instanceof Buffer) { - throw new Error("Account not found"); - } - - let stakeHistory: StakeHistoryEntry[] = []; - - parsedData.value.data.parsed.info.forEach((entry: any) => { - stakeHistory.push({ - epoch: BigInt(entry.epoch), - effective: BigInt(entry.stakeHistory.effective), - activating: BigInt(entry.stakeHistory.activating), - deactivating: BigInt(entry.stakeHistory.deactivating) - }); - }); - - return stakeHistory; -} - -export const getStakeAccount = function (parsedData: RpcResponseAndContext | null>): StakeAccount { - let discriminant = BigInt(0); - if (parsedData.value === null || parsedData.value.data instanceof Buffer) { - throw new Error("Account not found"); - } - - if (parsedData.value.data.parsed.type === "delegated") { - discriminant = BigInt(1); - } - - return { - discriminant: discriminant, - meta: { - rentExemptReserve: BigInt(parsedData.value.data.parsed.info.meta.rentExemptReserve), - authorized: { - staker: parsedData.value.data.parsed.info.meta.authorized.staker, - withdrawer: parsedData.value.data.parsed.info.meta.authorized.withdrawer - }, - lockup: { - unixTimestamp: BigInt(parsedData.value.data.parsed.info.meta.lockup.unixTimestamp), - epoch: BigInt(parsedData.value.data.parsed.info.meta.lockup.epoch), - custodian: parsedData.value.data.parsed.info.meta.lockup.custodian - } - }, - stake: parsedData.value.data.parsed.info.stake ? { - delegation: { - voterPubkey: parsedData.value.data.parsed.info.stake.delegation.voterPubkey, - stake: BigInt(parsedData.value.data.parsed.info.stake.delegation.stake), - activationEpoch: BigInt(parsedData.value.data.parsed.info.stake.delegation.activationEpoch), - deactivationEpoch: BigInt(parsedData.value.data.parsed.info.stake.delegation.deactivationEpoch), - }, - creditsObserved: BigInt(parsedData.value.data.parsed.info.stake.creditsObserved) - } : null - } -} \ No newline at end of file