From edf4c4745119e6d0b71ae4622ccb2fb0343d6607 Mon Sep 17 00:00:00 2001 From: Jordan Frankfurt Date: Wed, 31 Mar 2021 03:40:13 -0400 Subject: [PATCH] add external abi types (#37) --- .eslintrc.json | 3 +- .gitignore | 1 + package.json | 4 +- .../abis/argent-wallet-detector.json | 0 .../abis/ens-public-resolver.json | 0 src/{constants => }/abis/ens-registrar.json | 0 src/{constants => }/abis/erc20.json | 0 src/{constants => }/abis/erc20_bytes32.json | 0 src/{constants => }/abis/migrator.json | 0 src/{constants => }/abis/staking-rewards.ts | 0 src/{constants => }/abis/unisocks.json | 40 +++++++++---------- src/{constants => }/abis/weth.json | 0 src/constants/abis/argent-wallet-detector.ts | 5 --- src/constants/abis/erc20.ts | 10 ----- src/constants/abis/migrator.ts | 5 --- src/constants/index.ts | 4 ++ src/hooks/useContract.ts | 38 ++++++++++-------- src/pages/MigrateV1/MigrateV1Exchange.tsx | 3 +- src/react-app-env.d.ts | 2 +- src/state/stake/hooks.ts | 2 +- src/state/wallet/hooks.ts | 15 +++---- 21 files changed, 62 insertions(+), 70 deletions(-) rename src/{constants => }/abis/argent-wallet-detector.json (100%) rename src/{constants => }/abis/ens-public-resolver.json (100%) rename src/{constants => }/abis/ens-registrar.json (100%) rename src/{constants => }/abis/erc20.json (100%) rename src/{constants => }/abis/erc20_bytes32.json (100%) rename src/{constants => }/abis/migrator.json (100%) rename src/{constants => }/abis/staking-rewards.ts (100%) rename src/{constants => }/abis/unisocks.json (95%) rename src/{constants => }/abis/weth.json (100%) delete mode 100644 src/constants/abis/argent-wallet-detector.ts delete mode 100644 src/constants/abis/erc20.ts delete mode 100644 src/constants/abis/migrator.ts diff --git a/.eslintrc.json b/.eslintrc.json index 73d09ab21f..ed10a7c401 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -26,6 +26,7 @@ "prettier/prettier": "error", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/ban-ts-comment": "off", - "@typescript-eslint/ban-ts-ignore": "off" + "@typescript-eslint/ban-ts-ignore": "off", + "@typescript-eslint/explicit-module-boundary-types": "off" } } diff --git a/.gitignore b/.gitignore index 05375c4337..e37cd8efc1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # generated contract types /src/types/v3 +/src/abis/types # dependencies /node_modules diff --git a/package.json b/package.json index 189e38e382..e96ccde65c 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,9 @@ "@walletconnect/web3-provider": "1.1.1-alpha.0" }, "scripts": { - "compile-contract-types": "npx typechain --target ethers-v5 --outDir src/types/v3 './node_modules/@uniswap/?(v3-core|v3-periphery)/artifacts/contracts/**/*.json'", + "compile-contract-types": "yarn compile-external-abi-types && yarn compile-v3-contract-types", + "compile-external-abi-types": "npx typechain --target ethers-v5 --outDir src/abis/types './src/abis/**/*.json'", + "compile-v3-contract-types": "npx typechain --target ethers-v5 --outDir src/types/v3 './node_modules/@uniswap/?(v3-core|v3-periphery)/artifacts/contracts/**/*.json'", "build": "yarn compile-contract-types && react-scripts build", "eject": "react-scripts eject", "integration-test": "start-server-and-test 'serve build -l 3000' http://localhost:3000 'cypress run'", diff --git a/src/constants/abis/argent-wallet-detector.json b/src/abis/argent-wallet-detector.json similarity index 100% rename from src/constants/abis/argent-wallet-detector.json rename to src/abis/argent-wallet-detector.json diff --git a/src/constants/abis/ens-public-resolver.json b/src/abis/ens-public-resolver.json similarity index 100% rename from src/constants/abis/ens-public-resolver.json rename to src/abis/ens-public-resolver.json diff --git a/src/constants/abis/ens-registrar.json b/src/abis/ens-registrar.json similarity index 100% rename from src/constants/abis/ens-registrar.json rename to src/abis/ens-registrar.json diff --git a/src/constants/abis/erc20.json b/src/abis/erc20.json similarity index 100% rename from src/constants/abis/erc20.json rename to src/abis/erc20.json diff --git a/src/constants/abis/erc20_bytes32.json b/src/abis/erc20_bytes32.json similarity index 100% rename from src/constants/abis/erc20_bytes32.json rename to src/abis/erc20_bytes32.json diff --git a/src/constants/abis/migrator.json b/src/abis/migrator.json similarity index 100% rename from src/constants/abis/migrator.json rename to src/abis/migrator.json diff --git a/src/constants/abis/staking-rewards.ts b/src/abis/staking-rewards.ts similarity index 100% rename from src/constants/abis/staking-rewards.ts rename to src/abis/staking-rewards.ts diff --git a/src/constants/abis/unisocks.json b/src/abis/unisocks.json similarity index 95% rename from src/constants/abis/unisocks.json rename to src/abis/unisocks.json index c81663825c..661ece2dee 100644 --- a/src/constants/abis/unisocks.json +++ b/src/abis/unisocks.json @@ -89,7 +89,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 22405 + "gas": "22405" }, { "name": "tokenByIndex", @@ -108,7 +108,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 631 + "gas": "631" }, { "name": "tokenOfOwnerByIndex", @@ -131,7 +131,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 1248 + "gas": "1248" }, { "name": "transferFrom", @@ -153,7 +153,7 @@ "constant": false, "payable": false, "type": "function", - "gas": 259486 + "gas": "259486" }, { "name": "safeTransferFrom", @@ -217,7 +217,7 @@ "constant": false, "payable": false, "type": "function", - "gas": 38422 + "gas": "38422" }, { "name": "setApprovalForAll", @@ -235,7 +235,7 @@ "constant": false, "payable": false, "type": "function", - "gas": 38016 + "gas": "38016" }, { "name": "mint", @@ -254,7 +254,7 @@ "constant": false, "payable": false, "type": "function", - "gas": 182636 + "gas": "182636" }, { "name": "changeMinter", @@ -268,7 +268,7 @@ "constant": false, "payable": false, "type": "function", - "gas": 35897 + "gas": "35897" }, { "name": "changeURI", @@ -282,7 +282,7 @@ "constant": false, "payable": false, "type": "function", - "gas": 35927 + "gas": "35927" }, { "name": "name", @@ -296,7 +296,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 6612 + "gas": "6612" }, { "name": "symbol", @@ -310,7 +310,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 6642 + "gas": "6642" }, { "name": "totalSupply", @@ -324,7 +324,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 873 + "gas": "873" }, { "name": "minter", @@ -338,7 +338,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 903 + "gas": "903" }, { "name": "socks", @@ -353,7 +353,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 933 + "gas": "933" }, { "name": "newURI", @@ -367,7 +367,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 963 + "gas": "963" }, { "name": "ownerOf", @@ -386,7 +386,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 1126 + "gas": "1126" }, { "name": "balanceOf", @@ -405,7 +405,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 1195 + "gas": "1195" }, { "name": "getApproved", @@ -424,7 +424,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 1186 + "gas": "1186" }, { "name": "isApprovedForAll", @@ -447,7 +447,7 @@ "constant": true, "payable": false, "type": "function", - "gas": 1415 + "gas": "1415" }, { "name": "supportsInterface", @@ -466,6 +466,6 @@ "constant": true, "payable": false, "type": "function", - "gas": 1246 + "gas": "1246" } ] diff --git a/src/constants/abis/weth.json b/src/abis/weth.json similarity index 100% rename from src/constants/abis/weth.json rename to src/abis/weth.json diff --git a/src/constants/abis/argent-wallet-detector.ts b/src/constants/abis/argent-wallet-detector.ts deleted file mode 100644 index f91091a7e0..0000000000 --- a/src/constants/abis/argent-wallet-detector.ts +++ /dev/null @@ -1,5 +0,0 @@ -import ARGENT_WALLET_DETECTOR_ABI from './argent-wallet-detector.json' - -const ARGENT_WALLET_DETECTOR_MAINNET_ADDRESS = '0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8' - -export { ARGENT_WALLET_DETECTOR_ABI, ARGENT_WALLET_DETECTOR_MAINNET_ADDRESS } diff --git a/src/constants/abis/erc20.ts b/src/constants/abis/erc20.ts deleted file mode 100644 index 66e60d5d13..0000000000 --- a/src/constants/abis/erc20.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Interface } from '@ethersproject/abi' -import ERC20_ABI from './erc20.json' -import ERC20_BYTES32_ABI from './erc20_bytes32.json' - -const ERC20_INTERFACE = new Interface(ERC20_ABI) - -const ERC20_BYTES32_INTERFACE = new Interface(ERC20_BYTES32_ABI) - -export default ERC20_INTERFACE -export { ERC20_ABI, ERC20_BYTES32_INTERFACE, ERC20_BYTES32_ABI } diff --git a/src/constants/abis/migrator.ts b/src/constants/abis/migrator.ts deleted file mode 100644 index a1230156c3..0000000000 --- a/src/constants/abis/migrator.ts +++ /dev/null @@ -1,5 +0,0 @@ -import MIGRATOR_ABI from './migrator.json' - -const MIGRATOR_ADDRESS = '0x16D4F26C15f3658ec65B1126ff27DD3dF2a2996b' - -export { MIGRATOR_ADDRESS, MIGRATOR_ABI } diff --git a/src/constants/index.ts b/src/constants/index.ts index 37528ba376..ef1b773e92 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -214,3 +214,7 @@ export const BLOCKED_ADDRESSES: string[] = [ '0xA7e5d5A720f06526557c513402f2e6B5fA20b008', '0x8576aCC5C05D6Ce88f4e49bf65BdF0C62F91353C', ] + +export const ARGENT_WALLET_DETECTOR_MAINNET_ADDRESS = '0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8' + +export const MIGRATOR_ADDRESS = '0x16D4F26C15f3658ec65B1126ff27DD3dF2a2996b' diff --git a/src/hooks/useContract.ts b/src/hooks/useContract.ts index 2c7dff5c39..50ff5d4a53 100644 --- a/src/hooks/useContract.ts +++ b/src/hooks/useContract.ts @@ -6,24 +6,28 @@ import { abi as MERKLE_DISTRIBUTOR_ABI } from '@uniswap/merkle-distributor/build import { ChainId, WETH9 } from '@uniswap/sdk-core' import { abi as IUniswapV2PairABI } from '@uniswap/v2-core/build/IUniswapV2Pair.json' import { abi as NFTPositionManagerABI } from '@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json' +import ARGENT_WALLET_DETECTOR_ABI from 'abis/argent-wallet-detector.json' +import ENS_PUBLIC_RESOLVER_ABI from 'abis/ens-public-resolver.json' +import ENS_ABI from 'abis/ens-registrar.json' +import ERC20_ABI from 'abis/erc20.json' +import ERC20_BYTES32_ABI from 'abis/erc20_bytes32.json' +import MIGRATOR_ABI from 'abis/migrator.json' +import { Unisocks } from 'abis/types/Unisocks' +import UNISOCKS_ABI from 'abis/unisocks.json' +import WETH_ABI from 'abis/weth.json' +import { + ARGENT_WALLET_DETECTOR_MAINNET_ADDRESS, + GOVERNANCE_ADDRESS, + MERKLE_DISTRIBUTOR_ADDRESS, + MIGRATOR_ADDRESS, + UNI, +} from 'constants/index' +import { MULTICALL_ABI, MULTICALL_NETWORKS } from 'constants/multicall' +import { V1_EXCHANGE_ABI, V1_FACTORY_ABI, V1_FACTORY_ADDRESSES } from 'constants/v1' import { NONFUNGIBLE_POSITION_MANAGER_ADDRESSES } from 'constants/v3' import { useMemo } from 'react' import { NonfungiblePositionManager } from 'types/v3/NonfungiblePositionManager' -import { GOVERNANCE_ADDRESS, MERKLE_DISTRIBUTOR_ADDRESS, UNI } from '../constants' -import { - ARGENT_WALLET_DETECTOR_ABI, - ARGENT_WALLET_DETECTOR_MAINNET_ADDRESS, -} from '../constants/abis/argent-wallet-detector' -import ENS_PUBLIC_RESOLVER_ABI from '../constants/abis/ens-public-resolver.json' -import ENS_ABI from '../constants/abis/ens-registrar.json' -import { ERC20_BYTES32_ABI } from '../constants/abis/erc20' -import ERC20_ABI from '../constants/abis/erc20.json' -import { MIGRATOR_ABI, MIGRATOR_ADDRESS } from '../constants/abis/migrator' -import UNISOCKS_ABI from '../constants/abis/unisocks.json' -import WETH_ABI from '../constants/abis/weth.json' -import { MULTICALL_ABI, MULTICALL_NETWORKS } from '../constants/multicall' -import { V1_EXCHANGE_ABI, V1_FACTORY_ABI, V1_FACTORY_ADDRESSES } from '../constants/v1' -import { getContract } from '../utils' +import { getContract } from 'utils' import { useActiveWeb3React } from './index' // returns null on errors @@ -123,13 +127,13 @@ export function useStakingContract(stakingAddress?: string, withSignerIfPossible return useContract(stakingAddress, STAKING_REWARDS_ABI, withSignerIfPossible) } -export function useSocksController(): Contract | null { +export function useSocksController(): Unisocks | null { const { chainId } = useActiveWeb3React() return useContract( chainId === ChainId.MAINNET ? '0x65770b5283117639760beA3F867b69b3697a91dd' : undefined, UNISOCKS_ABI, false - ) + ) as Unisocks | null } export function useV3NFTPositionManagerContract(): NonfungiblePositionManager | null { diff --git a/src/pages/MigrateV1/MigrateV1Exchange.tsx b/src/pages/MigrateV1/MigrateV1Exchange.tsx index 989ff21a8e..7d60a480ca 100644 --- a/src/pages/MigrateV1/MigrateV1Exchange.tsx +++ b/src/pages/MigrateV1/MigrateV1Exchange.tsx @@ -14,8 +14,7 @@ import FormattedCurrencyAmount from '../../components/FormattedCurrencyAmount' import QuestionHelper from '../../components/QuestionHelper' import { AutoRow, RowBetween, RowFixed } from '../../components/Row' import { Dots } from '../../components/swap/styleds' -import { DEFAULT_DEADLINE_FROM_NOW, INITIAL_ALLOWED_SLIPPAGE } from '../../constants' -import { MIGRATOR_ADDRESS } from '../../constants/abis/migrator' +import { DEFAULT_DEADLINE_FROM_NOW, INITIAL_ALLOWED_SLIPPAGE, MIGRATOR_ADDRESS } from 'constants/index' import { PairState, usePair } from '../../data/Reserves' import { useTotalSupply } from '../../data/TotalSupply' import { useActiveWeb3React } from '../../hooks' diff --git a/src/react-app-env.d.ts b/src/react-app-env.d.ts index 5f4909a8c0..4a467aa4f0 100644 --- a/src/react-app-env.d.ts +++ b/src/react-app-env.d.ts @@ -13,7 +13,7 @@ interface Window { removeListener?: (...args: any[]) => void autoRefreshOnNetworkChange?: boolean } - web3?: {} + web3?: Record } declare module 'content-hash' { diff --git a/src/state/stake/hooks.ts b/src/state/stake/hooks.ts index dd0453e405..a56044179f 100644 --- a/src/state/stake/hooks.ts +++ b/src/state/stake/hooks.ts @@ -3,7 +3,7 @@ import { Pair } from '@uniswap/v2-sdk' import JSBI from 'jsbi' import { useMemo } from 'react' import { DAI, UNI, USDC, USDT, WBTC } from '../../constants' -import { STAKING_REWARDS_INTERFACE } from '../../constants/abis/staking-rewards' +import { STAKING_REWARDS_INTERFACE } from '../../abis/staking-rewards' import { useActiveWeb3React } from '../../hooks' import { NEVER_RELOAD, useMultipleContractSingleData } from '../multicall/hooks' import { tryParseAmount } from '../swap/hooks' diff --git a/src/state/wallet/hooks.ts b/src/state/wallet/hooks.ts index c8d1146599..9f733058f2 100644 --- a/src/state/wallet/hooks.ts +++ b/src/state/wallet/hooks.ts @@ -1,16 +1,17 @@ -import { UNI } from './../../constants/index' import { Currency, CurrencyAmount, ETHER, Token, TokenAmount } from '@uniswap/sdk-core' import { JSBI } from '@uniswap/v2-sdk' import { useMemo } from 'react' -import ERC20_INTERFACE from '../../constants/abis/erc20' -import { useAllTokens } from '../../hooks/Tokens' import { useActiveWeb3React } from '../../hooks' +import { useAllTokens } from '../../hooks/Tokens' import { useMulticallContract } from '../../hooks/useContract' import { isAddress } from '../../utils' -import { useSingleContractMultipleData, useMultipleContractSingleData } from '../multicall/hooks' import { useUserUnclaimedAmount } from '../claim/hooks' +import { useMultipleContractSingleData, useSingleContractMultipleData } from '../multicall/hooks' import { useTotalUniEarned } from '../stake/hooks' - +import { UNI } from './../../constants/index' +import { Interface } from '@ethersproject/abi' +import ERC20ABI from 'abis/erc20.json' +import { Erc20Interface } from 'abis/types/Erc20' /** * Returns a map of the given addresses to their eventually consistent ETH balances. */ @@ -60,8 +61,8 @@ export function useTokenBalancesWithLoadingIndicator( ) const validatedTokenAddresses = useMemo(() => validatedTokens.map((vt) => vt.address), [validatedTokens]) - - const balances = useMultipleContractSingleData(validatedTokenAddresses, ERC20_INTERFACE, 'balanceOf', [address]) + const ERC20Interface = new Interface(ERC20ABI) as Erc20Interface + const balances = useMultipleContractSingleData(validatedTokenAddresses, ERC20Interface, 'balanceOf', [address]) const anyLoading: boolean = useMemo(() => balances.some((callState) => callState.loading), [balances])