From 1673b3697174460add9c138b44fffba1e80c7bce Mon Sep 17 00:00:00 2001 From: Ben Griffin Date: Thu, 4 Apr 2024 10:38:21 -0400 Subject: [PATCH 1/5] Switching to use ethers and accept RPC url for token gating validation --- package.json | 7 +- src/modules/utils/index.ts | 15 ++- src/modules/utils/ownershipABIs.ts | 109 ++++++++-------- .../utils/validateTokenOwnership.spec.ts | 74 ++++------- test/tsconfig.json | 9 +- tsconfig.json | 5 +- yarn.lock | 123 +++++++++++++----- 7 files changed, 199 insertions(+), 143 deletions(-) diff --git a/package.json b/package.json index ef00792..43d1459 100644 --- a/package.json +++ b/package.json @@ -52,16 +52,13 @@ "ts-jest": "^27.1.3", "ts-node": "^10.2.0", "tslint": "~5.20.1", - "typescript": "^5.3.3", - "web3": "^4.6.0" + "typescript": "^5.3.3" }, "dependencies": { "ethereum-cryptography": "^1.0.1", + "ethers": "^6.11.1", "node-fetch": "^2.6.7" }, - "peerDependencies": { - "web3": "^4.6.0" - }, "husky": { "hooks": { "pre-commit": "lint-staged" diff --git a/src/modules/utils/index.ts b/src/modules/utils/index.ts index a79fe21..16d4070 100644 --- a/src/modules/utils/index.ts +++ b/src/modules/utils/index.ts @@ -1,4 +1,4 @@ -import Web3 from 'web3'; +import { ethers } from "ethers"; import { BaseModule } from '../base-module'; import {createExpectedBearerStringError} from '../../core/sdk-exceptions'; import { ValidateTokenOwnershipResponse } from '../../types'; @@ -22,7 +22,7 @@ export class UtilsModule extends BaseModule { didToken: string, contractAddress: string, contractType: 'ERC721' | 'ERC1155', - web3: Web3, + rpcURL: string, tokenId?: string, ): Promise { // Make sure if ERC1155 has a tokenId @@ -56,12 +56,15 @@ export class UtilsModule extends BaseModule { // Check on-chain if user owns NFT by calling contract with web3 let balance = BigInt(0); + const provider = new ethers.JsonRpcProvider(); if (contractType === 'ERC721') { - const contract = new web3.eth.Contract(ERC721ContractABI, contractAddress); - balance = BigInt(await contract.methods.balanceOf(walletAddress).call()); + const contract = new ethers.Contract(contractAddress, ERC721ContractABI, provider); + // const contract = new web3.eth.Contract(ERC721ContractABI, contractAddress); + balance = BigInt(await contract.balanceOf(walletAddress)); } else { - const contract = new web3.eth.Contract(ERC1155ContractABI, contractAddress); - balance = BigInt(await contract.methods.balanceOf(walletAddress, tokenId).call()); + const contract = new ethers.Contract(contractAddress, ERC1155ContractABI, provider); + // const contract = new web3.eth.Contract(ERC1155ContractABI, contractAddress); + balance = BigInt(await contract.balanceOf(walletAddress, tokenId)); } if (balance > BigInt(0)) { return { diff --git a/src/modules/utils/ownershipABIs.ts b/src/modules/utils/ownershipABIs.ts index 0ef7360..6bc89f0 100644 --- a/src/modules/utils/ownershipABIs.ts +++ b/src/modules/utils/ownershipABIs.ts @@ -1,53 +1,60 @@ -// Reduced ABI for ERC1155 with just balanceOf -export const ERC1155ContractABI = [ - { - "constant": true, - "inputs": [ - { - "name": "_owner", - "type": "address" - }, - { - "name": "_id", - "type": "uint256" - } - ], - "name": "balanceOf", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - } -]; +// // Reduced ABI for ERC1155 with just balanceOf +// export const ERC1155ContractABI = [ +// { +// "constant": true, +// "inputs": [ +// { +// "name": "_owner", +// "type": "address" +// }, +// { +// "name": "_id", +// "type": "uint256" +// } +// ], +// "name": "balanceOf", +// "outputs": [ +// { +// "name": "", +// "type": "uint256" +// } +// ], +// "payable": false, +// "stateMutability": "view", +// "type": "function" +// } +// ]; + +// // Reduced ABI for ERC721 with just balanceOf +// export const ERC721ContractABI = [ +// { +// "constant": true, +// "inputs": [ +// { +// "name": "_owner", +// "type": "address" +// }, +// { +// "name": "_id", +// "type": "uint256" +// } +// ], +// "name": "balanceOf", +// "outputs": [ +// { +// "name": "", +// "type": "uint256" +// } +// ], +// "payable": false, +// "stateMutability": "view", +// "type": "function" +// } +// ]; -// Reduced ABI for ERC721 with just balanceOf export const ERC721ContractABI = [ - { - "constant": true, - "inputs": [ - { - "name": "_owner", - "type": "address" - }, - { - "name": "_id", - "type": "uint256" - } - ], - "name": "balanceOf", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - } -]; \ No newline at end of file + "function balanceOf(address) view returns (uint)", +] +export const ERC1155ContractABI = [ + "function balanceOf(address, id) view returns (uint)", +] \ No newline at end of file diff --git a/test/spec/modules/utils/validateTokenOwnership.spec.ts b/test/spec/modules/utils/validateTokenOwnership.spec.ts index f100f18..97072a4 100644 --- a/test/spec/modules/utils/validateTokenOwnership.spec.ts +++ b/test/spec/modules/utils/validateTokenOwnership.spec.ts @@ -1,23 +1,40 @@ -import Web3 from 'web3'; import { createMagicAdminSDK } from '../../../lib/factories'; +jest.mock('ethers', () => { + const originalModule = jest.requireActual('ethers'); + return { + ...originalModule, + ethers: { + ...originalModule.ethers, + Contract: jest.fn(() => ({ + balanceOf: jest.fn().mockImplementation((walletAddress: string, tokenId?: string) => { + if (tokenId === '2') { + return BigInt(1); // User owns token + } else { + return BigInt(0); // User doesn't own token + } + }), + })), + }, + }; +}); + + test('Throws an error if ERC1155 and no token provided', async () => { const sdk = createMagicAdminSDK('https://example.com'); - const web3 = new Web3('https://example.com'); - await expect(sdk.utils.validateTokenOwnership('did:ethr:0x123', '0xfoo', 'ERC1155', web3)).rejects.toThrow( + await expect(sdk.utils.validateTokenOwnership('did:ethr:0x123', '0xfoo', 'ERC1155', 'https://example.com')).rejects.toThrow( 'ERC1155 requires a tokenId', ); }); test('Returns an error if DID token is malformed', async () => { const sdk = createMagicAdminSDK('https://example.com'); - const web3 = new Web3('https://example.com'); // Mock the magic token validation by setting the code to ERROR_MALFORMED_TOKEN sdk.token.validate = jest.fn().mockRejectedValue({ code: 'ERROR_MALFORMED_TOKEN' }); - await expect(sdk.utils.validateTokenOwnership('did:ethr:0x123', '0xfoo', 'ERC1155', web3, '1')).resolves.toEqual({ + await expect(sdk.utils.validateTokenOwnership('did:ethr:0x123', '0xfoo', 'ERC1155', 'https://example.com', '1')).resolves.toEqual({ valid: false, error_code: 'UNAUTHORIZED', message: 'Invalid DID token: ERROR_MALFORMED_TOKEN', @@ -26,12 +43,11 @@ test('Returns an error if DID token is malformed', async () => { test('Returns an error if DID token is expired', async () => { const sdk = createMagicAdminSDK('https://example.com'); - const web3 = new Web3('https://example.com'); // Mock the magic token validation by setting the code to ERROR_DIDT_EXPIRED sdk.token.validate = jest.fn().mockRejectedValue({ code: 'ERROR_DIDT_EXPIRED' }); - await expect(sdk.utils.validateTokenOwnership('did:ethr:0x123', '0xfoo', 'ERC1155', web3, '1')).resolves.toEqual({ + await expect(sdk.utils.validateTokenOwnership('did:ethr:0x123', '0xfoo', 'ERC1155', 'https://example.com', '1')).resolves.toEqual({ valid: false, error_code: 'UNAUTHORIZED', message: 'Invalid DID token: ERROR_DIDT_EXPIRED', @@ -40,12 +56,11 @@ test('Returns an error if DID token is expired', async () => { test('Throws an error if DID token validation returns unexpected error code', async () => { const sdk = createMagicAdminSDK('https://example.com'); - const web3 = new Web3('https://example.com'); // Mock the magic token validation by setting the code to ERROR_MALFORMED_TOKEN sdk.token.validate = jest.fn().mockRejectedValue({ code: 'UNKNOWN' }); - await expect(sdk.utils.validateTokenOwnership('did:ethr:0x123', '0xfoo', 'ERC1155', web3, '1')).rejects.toThrow(); + await expect(sdk.utils.validateTokenOwnership('did:ethr:0x123', '0xfoo', 'ERC1155', 'https://example.com', '1')).rejects.toThrow(); }); test('Returns an error if ERC721 token is not owned by user', async () => { @@ -55,24 +70,13 @@ test('Returns an error if ERC721 token is not owned by user', async () => { sdk.token.validate = jest.fn().mockResolvedValue({}); // Mock the getPublicAddress to return valid email and wallet sdk.token.getPublicAddress = jest.fn().mockReturnValue('0x610dcb8fd5cf7f544b85290889a456916fbeaba2'); - // Mock the web3 contract.methods.balanceOf to return 0 - const callStub = jest.fn().mockResolvedValue(BigInt(0)); - // Mock the contract instance - const contractMock: any = { - methods: { - balanceOf: jest.fn().mockReturnValue({ call: callStub }), - }, - }; - // Mock web3.eth.Contract - const web3 = new Web3('https://example.com'); - jest.spyOn(web3.eth, 'Contract').mockReturnValue(contractMock); await expect( sdk.utils.validateTokenOwnership( 'did:ethr:0x123', '0x610dcb8fd5cf7f544b85290889a456916fbeaba2', 'ERC721', - web3, + 'https://example.com', '1', ), ).resolves.toEqual({ @@ -89,24 +93,13 @@ test('Returns an error if ERC1155 token is not owned by user', async () => { sdk.token.validate = jest.fn().mockResolvedValue({}); // Mock the getPublicAddress to return valid email and wallet sdk.token.getPublicAddress = jest.fn().mockReturnValue('0x610dcb8fd5cf7f544b85290889a456916fbeaba2'); - // Mock the web3 contract.methods.balanceOf to return 0 - const callStub = jest.fn().mockResolvedValue(BigInt(0)); - // Mock the contract instance - const contractMock: any = { - methods: { - balanceOf: jest.fn().mockReturnValue({ call: callStub }), - }, - }; - // Mock web3.eth.Contract - const web3 = new Web3('https://example.com'); - jest.spyOn(web3.eth, 'Contract').mockReturnValue(contractMock); await expect( sdk.utils.validateTokenOwnership( 'did:ethr:0x123', '0x610dcb8fd5cf7f544b85290889a456916fbeaba2', 'ERC1155', - web3, + 'https://example.com', '1', ), ).resolves.toEqual({ @@ -123,25 +116,14 @@ test('Returns success if ERC1155 token is owned by user', async () => { sdk.token.validate = jest.fn().mockResolvedValue({}); // Mock the getPublicAddress to return valid email and wallet sdk.token.getPublicAddress = jest.fn().mockReturnValue('0x610dcb8fd5cf7f544b85290889a456916fbeaba2'); - // Mock the web3 contract.methods.balanceOf to return 0 - const callStub = jest.fn().mockResolvedValue(BigInt(1)); - // Mock the contract instance - const contractMock: any = { - methods: { - balanceOf: jest.fn().mockReturnValue({ call: callStub }), - }, - }; - // Mock web3.eth.Contract - const web3 = new Web3('https://example.com'); - jest.spyOn(web3.eth, 'Contract').mockReturnValue(contractMock); await expect( sdk.utils.validateTokenOwnership( 'did:ethr:0x123', '0x610dcb8fd5cf7f544b85290889a456916fbeaba2', 'ERC1155', - web3, - '1', + 'https://example.com', + '2', ), ).resolves.toEqual({ valid: true, diff --git a/test/tsconfig.json b/test/tsconfig.json index f416863..32ab7f5 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,3 +1,10 @@ { - "extends": "../config/tsconfig.test.json" + "extends": "../config/tsconfig.test.json", + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "strict": true, + "skipLibCheck": true, + "esModuleInterop": true, + } } diff --git a/tsconfig.json b/tsconfig.json index 317fff1..c1f2895 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,6 @@ { - "extends": "./config/tsconfig.base.json" + "extends": "./config/tsconfig.base.json", + "compilerOptions": { + "esModuleInterop": true, + } } diff --git a/yarn.lock b/yarn.lock index 5a21789..d5ee672 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7,7 +7,7 @@ resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf" integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA== -"@adraffy/ens-normalize@^1.8.8": +"@adraffy/ens-normalize@1.10.1", "@adraffy/ens-normalize@^1.8.8": version "1.10.1" resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.1.tgz#63430d04bd8c5e74f8d7d049338f1cd9d4f02069" integrity sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw== @@ -760,6 +760,13 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" +"@noble/curves@1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35" + integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw== + dependencies: + "@noble/hashes" "1.3.2" + "@noble/curves@1.3.0", "@noble/curves@~1.3.0": version "1.3.0" resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.3.0.tgz#01be46da4fd195822dab821e72f71bf4aeec635e" @@ -772,6 +779,11 @@ resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.0.0.tgz#d5e38bfbdaba174805a4e649f13be9a9ed3351ae" integrity sha512-DZVbtY62kc3kkBtMHqwCOfXrT/hnoORy5BJ4+HU1IR59X0KWAOqsfzQPcUl/lQLlG7qXbe/fZ3r/emxtAl+sqg== +"@noble/hashes@1.3.2": + version "1.3.2" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39" + integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ== + "@noble/hashes@1.3.3", "@noble/hashes@~1.3.2": version "1.3.3" resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.3.tgz#39908da56a4adc270147bb07968bf3b16cfe1699" @@ -1156,16 +1168,28 @@ "@types/node" "*" form-data "^3.0.0" -"@types/node@*", "@types/node@^13.1.2": - version "13.7.7" - resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.7.tgz#1628e6461ba8cc9b53196dfeaeec7b07fa6eea99" - integrity sha512-Uo4chgKbnPNlxQwoFmYIwctkQVkMMmsAoGGU4JKwLuvBefF0pCq4FybNSnfkfRCpC7ZW7kttcC/TrRtAJsvGtg== +"@types/node@*": + version "20.12.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.12.4.tgz#af5921bd75ccdf3a3d8b3fa75bf3d3359268cd11" + integrity sha512-E+Fa9z3wSQpzgYQdYmme5X3OTuejnnTx88A6p6vkkJosR3KBz+HpE3kqNm98VE6cfLFcISx7zW7MsJkH6KwbTw== + dependencies: + undici-types "~5.26.4" + +"@types/node@18.15.13": + version "18.15.13" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.13.tgz#f64277c341150c979e42b00e4ac289290c9df469" + integrity sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q== "@types/node@>= 8": version "14.14.3" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.3.tgz#e1c09064121f894baaad2bd9f12ce4a41bffb274" integrity sha512-33/L34xS7HVUx23e0wOT2V1qPF1IrHgQccdJVm9uXGTB9vFBrrzBtkQymT8VskeKOxjz55MSqMv0xuLq+u98WQ== +"@types/node@^13.1.2": + version "13.7.7" + resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.7.tgz#1628e6461ba8cc9b53196dfeaeec7b07fa6eea99" + integrity sha512-Uo4chgKbnPNlxQwoFmYIwctkQVkMMmsAoGGU4JKwLuvBefF0pCq4FybNSnfkfRCpC7ZW7kttcC/TrRtAJsvGtg== + "@types/parse-json@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" @@ -1418,6 +1442,11 @@ acorn@^8.4.1, acorn@^8.9.0: resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.3.tgz#71e0b14e13a4ec160724b38fb7b0f233b1b81d7a" integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg== +aes-js@4.0.0-beta.5: + version "4.0.0-beta.5" + resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-4.0.0-beta.5.tgz#8d2452c52adedebc3a3e28465d858c11ca315873" + integrity sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q== + agent-base@6: version "6.0.2" resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" @@ -2357,7 +2386,7 @@ deepmerge@^4.0.0, deepmerge@^4.2.2: resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955" integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg== -define-data-property@^1.0.1, define-data-property@^1.1.2, define-data-property@^1.1.4: +define-data-property@^1.0.1, define-data-property@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/define-data-property/-/define-data-property-1.1.4.tgz#894dc141bb7d3060ae4366f6a0107e68fbe48c5e" integrity sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A== @@ -3200,6 +3229,19 @@ ethereum-cryptography@^2.0.0: "@scure/bip32" "1.3.3" "@scure/bip39" "1.2.2" +ethers@^6.11.1: + version "6.11.1" + resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.11.1.tgz#96aae00b627c2e35f9b0a4d65c7ab658259ee6af" + integrity sha512-mxTAE6wqJQAbp5QAe/+o+rXOID7Nw91OZXvgpjDa1r4fAbq2Nu314oEZSbjoRLacuCzs7kUC3clEvkCQowffGg== + dependencies: + "@adraffy/ens-normalize" "1.10.1" + "@noble/curves" "1.2.0" + "@noble/hashes" "1.3.2" + "@types/node" "18.15.13" + aes-js "4.0.0-beta.5" + tslib "2.4.0" + ws "8.5.0" + eventemitter3@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4" @@ -3701,7 +3743,7 @@ has-flag@^4.0.0: resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== -has-property-descriptors@^1.0.0, has-property-descriptors@^1.0.1, has-property-descriptors@^1.0.2: +has-property-descriptors@^1.0.0, has-property-descriptors@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz#963ed7d071dc7bf5f084c5bfbe0d1b6222586854" integrity sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg== @@ -3737,20 +3779,20 @@ has@^1.0.3: dependencies: function-bind "^1.1.1" -hasown@^2.0.0, hasown@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.1.tgz#26f48f039de2c0f8d3356c223fb8d50253519faa" - integrity sha512-1/th4MHjnwncwXsIW6QMzlvYL9kG5e/CpVvLRZe4XPa8TOUNbCELqmvhDmnkNsAjwaG4+I8gJJL0JBvTTLO9qA== - dependencies: - function-bind "^1.1.2" - -hasown@^2.0.2: +hasown@^2.0.0, hasown@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.2.tgz#003eaf91be7adc372e84ec59dc37252cedb80003" integrity sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ== dependencies: function-bind "^1.1.2" +hasown@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.1.tgz#26f48f039de2c0f8d3356c223fb8d50253519faa" + integrity sha512-1/th4MHjnwncwXsIW6QMzlvYL9kG5e/CpVvLRZe4XPa8TOUNbCELqmvhDmnkNsAjwaG4+I8gJJL0JBvTTLO9qA== + dependencies: + function-bind "^1.1.2" + hosted-git-info@^2.1.4: version "2.8.9" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9" @@ -6139,16 +6181,16 @@ semver@^7.5.4: lru-cache "^6.0.0" set-function-length@^1.2.1: - version "1.2.1" - resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.2.1.tgz#47cc5945f2c771e2cf261c6737cf9684a2a5e425" - integrity sha512-j4t6ccc+VsKwYHso+kElc5neZpjtq9EnRICFZtWyBsLojhmeF/ZBd/elqm22WJh/BziDe/SBiOeAt0m2mfLD0g== + version "1.2.2" + resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.2.2.tgz#aac72314198eaed975cf77b2c3b6b880695e5449" + integrity sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg== dependencies: - define-data-property "^1.1.2" + define-data-property "^1.1.4" es-errors "^1.3.0" function-bind "^1.1.2" - get-intrinsic "^1.2.3" + get-intrinsic "^1.2.4" gopd "^1.0.1" - has-property-descriptors "^1.0.1" + has-property-descriptors "^1.0.2" set-function-name@^2.0.1, set-function-name@^2.0.2: version "2.0.2" @@ -6774,6 +6816,11 @@ tslib@2.1.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a" integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A== +tslib@2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3" + integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ== + tslib@^1.14.1, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" @@ -6927,6 +6974,11 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + universal-user-agent@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-6.0.0.tgz#3381f8503b251c0d9cd21bc1de939ec9df5480ee" @@ -7306,18 +7358,7 @@ which-collection@^1.0.1: is-weakmap "^2.0.1" is-weakset "^2.0.1" -which-typed-array@^1.1.14, which-typed-array@^1.1.9: - version "1.1.14" - resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.14.tgz#1f78a111aee1e131ca66164d8bdc3ab062c95a06" - integrity sha512-VnXFiIW8yNn9kIHN88xvZ4yOWchftKDsRJ8fEPacX/wl1lOvBrhsJ/OeJCXq7B0AaijRuqgzSKalJoPk+D8MPg== - dependencies: - available-typed-arrays "^1.0.6" - call-bind "^1.0.5" - for-each "^0.3.3" - gopd "^1.0.1" - has-tostringtag "^1.0.1" - -which-typed-array@^1.1.15, which-typed-array@^1.1.2: +which-typed-array@^1.1.14, which-typed-array@^1.1.15, which-typed-array@^1.1.2: version "1.1.15" resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.15.tgz#264859e9b11a649b388bfaaf4f767df1f779b38d" integrity sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA== @@ -7328,6 +7369,17 @@ which-typed-array@^1.1.15, which-typed-array@^1.1.2: gopd "^1.0.1" has-tostringtag "^1.0.2" +which-typed-array@^1.1.9: + version "1.1.14" + resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.14.tgz#1f78a111aee1e131ca66164d8bdc3ab062c95a06" + integrity sha512-VnXFiIW8yNn9kIHN88xvZ4yOWchftKDsRJ8fEPacX/wl1lOvBrhsJ/OeJCXq7B0AaijRuqgzSKalJoPk+D8MPg== + dependencies: + available-typed-arrays "^1.0.6" + call-bind "^1.0.5" + for-each "^0.3.3" + gopd "^1.0.1" + has-tostringtag "^1.0.1" + which@^1.2.9: version "1.3.1" resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" @@ -7394,6 +7446,11 @@ write-file-atomic@^3.0.0: signal-exit "^3.0.2" typedarray-to-buffer "^3.1.5" +ws@8.5.0: + version "8.5.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.5.0.tgz#bfb4be96600757fe5382de12c670dab984a1ed4f" + integrity sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg== + ws@^7.4.6: version "7.5.7" resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.7.tgz#9e0ac77ee50af70d58326ecff7e85eb3fa375e67" From ceea22d685f61be21b9535dee24158daf571359c Mon Sep 17 00:00:00 2001 From: Ben Griffin Date: Thu, 4 Apr 2024 10:41:01 -0400 Subject: [PATCH 2/5] Removing commented out code --- src/modules/utils/index.ts | 2 -- src/modules/utils/ownershipABIs.ts | 56 +----------------------------- test/tsconfig.json | 9 +---- tsconfig.json | 5 +-- 4 files changed, 3 insertions(+), 69 deletions(-) diff --git a/src/modules/utils/index.ts b/src/modules/utils/index.ts index 16d4070..9a65696 100644 --- a/src/modules/utils/index.ts +++ b/src/modules/utils/index.ts @@ -59,11 +59,9 @@ export class UtilsModule extends BaseModule { const provider = new ethers.JsonRpcProvider(); if (contractType === 'ERC721') { const contract = new ethers.Contract(contractAddress, ERC721ContractABI, provider); - // const contract = new web3.eth.Contract(ERC721ContractABI, contractAddress); balance = BigInt(await contract.balanceOf(walletAddress)); } else { const contract = new ethers.Contract(contractAddress, ERC1155ContractABI, provider); - // const contract = new web3.eth.Contract(ERC1155ContractABI, contractAddress); balance = BigInt(await contract.balanceOf(walletAddress, tokenId)); } if (balance > BigInt(0)) { diff --git a/src/modules/utils/ownershipABIs.ts b/src/modules/utils/ownershipABIs.ts index 6bc89f0..ed4ee7d 100644 --- a/src/modules/utils/ownershipABIs.ts +++ b/src/modules/utils/ownershipABIs.ts @@ -1,60 +1,6 @@ -// // Reduced ABI for ERC1155 with just balanceOf -// export const ERC1155ContractABI = [ -// { -// "constant": true, -// "inputs": [ -// { -// "name": "_owner", -// "type": "address" -// }, -// { -// "name": "_id", -// "type": "uint256" -// } -// ], -// "name": "balanceOf", -// "outputs": [ -// { -// "name": "", -// "type": "uint256" -// } -// ], -// "payable": false, -// "stateMutability": "view", -// "type": "function" -// } -// ]; - -// // Reduced ABI for ERC721 with just balanceOf -// export const ERC721ContractABI = [ -// { -// "constant": true, -// "inputs": [ -// { -// "name": "_owner", -// "type": "address" -// }, -// { -// "name": "_id", -// "type": "uint256" -// } -// ], -// "name": "balanceOf", -// "outputs": [ -// { -// "name": "", -// "type": "uint256" -// } -// ], -// "payable": false, -// "stateMutability": "view", -// "type": "function" -// } -// ]; - export const ERC721ContractABI = [ "function balanceOf(address) view returns (uint)", ] export const ERC1155ContractABI = [ "function balanceOf(address, id) view returns (uint)", -] \ No newline at end of file +] diff --git a/test/tsconfig.json b/test/tsconfig.json index 32ab7f5..f416863 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,10 +1,3 @@ { - "extends": "../config/tsconfig.test.json", - "compilerOptions": { - "target": "es5", - "module": "commonjs", - "strict": true, - "skipLibCheck": true, - "esModuleInterop": true, - } + "extends": "../config/tsconfig.test.json" } diff --git a/tsconfig.json b/tsconfig.json index c1f2895..317fff1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,3 @@ { - "extends": "./config/tsconfig.base.json", - "compilerOptions": { - "esModuleInterop": true, - } + "extends": "./config/tsconfig.base.json" } From 1075410d46b0c44cc25c0a3c838ce35518df6901 Mon Sep 17 00:00:00 2001 From: Ben Griffin Date: Thu, 4 Apr 2024 10:44:50 -0400 Subject: [PATCH 3/5] Updating tsconfig to use specific complier --- test/tsconfig.json | 5 ++++- tsconfig.json | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/tsconfig.json b/test/tsconfig.json index f416863..cced447 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,3 +1,6 @@ { - "extends": "../config/tsconfig.test.json" + "extends": "../config/tsconfig.test.json", + "compilerOptions": { + "target": "es5" + } } diff --git a/tsconfig.json b/tsconfig.json index 317fff1..b54f4fb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,6 @@ { - "extends": "./config/tsconfig.base.json" + "extends": "./config/tsconfig.base.json", + "compilerOptions": { + "target": "es5" + } } From b8198539f69980508edfd5c79450457cca914c42 Mon Sep 17 00:00:00 2001 From: Ben Griffin Date: Thu, 4 Apr 2024 11:37:46 -0400 Subject: [PATCH 4/5] overriding target in build tsconfig --- config/tsconfig.sdk.esm.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/tsconfig.sdk.esm.json b/config/tsconfig.sdk.esm.json index 10f5841..0fb670c 100644 --- a/config/tsconfig.sdk.esm.json +++ b/config/tsconfig.sdk.esm.json @@ -2,8 +2,8 @@ "extends": "./tsconfig.base.json", "compilerOptions": { "lib": ["es2020", "dom"], - "target": "esnext", - "module": "esnext", + "target": "es2020", + "module": "es2020", "outDir": "../dist/esm" }, "include": ["../src/**/*.ts"] From bf394ebcfdba689f09f7250f2ba2477101e33bfe Mon Sep 17 00:00:00 2001 From: ethella Date: Thu, 4 Apr 2024 13:22:57 -0700 Subject: [PATCH 5/5] bump node version set compiler target to es6 --- .github/workflows/publish.yml | 2 +- config/tsconfig.base.json | 2 +- package.json | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c1bd38b..8b18619 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -20,7 +20,7 @@ jobs: - name: Setup node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 20 cache: 'yarn' - run: | yarn -v diff --git a/config/tsconfig.base.json b/config/tsconfig.base.json index 673ec01..7a7a1e9 100644 --- a/config/tsconfig.base.json +++ b/config/tsconfig.base.json @@ -3,7 +3,7 @@ "lib": ["es2018", "dom"], "module": "commonjs", "moduleResolution": "node", - "target": "es5", + "target": "es6", "strict": true, "allowSyntheticDefaultImports": true, "experimentalDecorators": true, diff --git a/package.json b/package.json index ef00792..89ce480 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "clean": "npm-run-all -s clean:*", "clean:test-artifacts": "rimraf coverage", "clean:build": "rimraf dist", - "clean_node_modules": "rimraf node_modules" + "clean_node_modules": "rimraf node_modules", + "prepare": "husky install" }, "devDependencies": { "@ikscodes/eslint-config": "^8.4.1", @@ -62,11 +63,6 @@ "peerDependencies": { "web3": "^4.6.0" }, - "husky": { - "hooks": { - "pre-commit": "lint-staged" - } - }, "lint-staged": { "*.{ts,tsx}": "eslint --fix" },