From 27412e49d5ab79a29ddceb5bd90e341025319b82 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 11 Jan 2022 11:32:20 -0800 Subject: [PATCH] chore: import from ethers (#3094) * chore: rm lodash * chore: improve styled-components lint * chore: import from ethers * fix: use provider JsonRpcProvider --- .eslintrc.json | 18 ++++++--------- cypress/support/commands.js | 6 ++--- package.json | 9 ++------ src/components/claim/AddressClaimModal.tsx | 2 +- src/components/claim/ClaimModal.tsx | 2 +- src/components/earn/ClaimRewardModal.tsx | 4 ++-- src/components/earn/StakingModal.tsx | 4 ++-- src/components/earn/UnstakingModal.tsx | 4 ++-- src/components/vote/DelegateModal.tsx | 2 +- src/connectors/index.ts | 6 ++--- src/hooks/Tokens.ts | 3 +-- src/hooks/useActiveWeb3React.ts | 6 ++--- src/hooks/useApproveCallback.ts | 10 ++++---- src/hooks/useContract.ts | 2 +- src/hooks/useCurrentBlockTimestamp.ts | 2 +- src/hooks/useENSAvatar.ts | 5 ++-- src/hooks/useENSName.ts | 2 +- src/hooks/useERC20Permit.ts | 2 +- src/hooks/useMonitoringEventCallback.ts | 6 ++--- src/hooks/usePools.ts | 2 +- src/hooks/usePositionTokenURI.ts | 2 +- src/hooks/useSwapCallback.tsx | 2 +- src/hooks/useTotalSupply.ts | 2 +- src/hooks/useTransactionDeadline.ts | 2 +- src/hooks/useV2Pairs.ts | 2 +- src/hooks/useV3PositionFees.ts | 2 +- src/hooks/useV3Positions.ts | 2 +- src/lib/.eslintrc.json | 10 ++++---- .../components/Swap/Settings/components.tsx | 1 + src/lib/utils/resolveENSContentHash.ts | 10 ++++---- src/pages/AddLiquidity/index.tsx | 6 ++--- src/pages/AddLiquidityV2/index.tsx | 6 ++--- src/pages/CreateProposal/index.tsx | 3 +-- src/pages/MigrateV2/MigrateV2Pair.tsx | 6 ++--- src/pages/MigrateV2/index.tsx | 3 +-- src/pages/Pool/PositionPage.tsx | 6 ++--- src/pages/RemoveLiquidity/V3.tsx | 6 ++--- src/pages/RemoveLiquidity/index.tsx | 7 +++--- src/pages/Vote/VotePage.tsx | 2 +- src/state/claim/hooks.ts | 4 ++-- src/state/governance/hooks.ts | 23 +++++++++++-------- src/state/stake/hooks.tsx | 2 +- src/state/swap/hooks.tsx | 2 +- src/state/transactions/hooks.tsx | 6 ++--- src/state/wallet/hooks.ts | 2 +- src/types/position.d.ts | 2 +- src/utils/approveAmountCalldata.ts | 2 +- src/utils/calculateGasMargin.test.ts | 2 +- src/utils/calculateGasMargin.ts | 2 +- src/utils/calculateSlippageAmount.test.ts | 6 ++--- src/utils/computeUniCirculation.test.ts | 2 +- src/utils/computeUniCirculation.ts | 2 +- src/utils/getLibrary.ts | 6 ++--- src/utils/index.ts | 18 ++++++++------- src/utils/safeNamehash.test.ts | 2 +- src/utils/safeNamehash.ts | 2 +- src/utils/switchToNetwork.ts | 8 +++---- yarn.lock | 5 ---- 58 files changed, 133 insertions(+), 142 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index cb83684f3d..105cc2e0c4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -59,21 +59,13 @@ { "paths": [ { - "name": "lodash", - "message": "Please import from 'lodash/module' directly to support tree-shaking." - }, - { - "name": "ethers", - "message": "Please import from '@ethersproject/module' directly to support tree-shaking." + "name": "@lingui/macro", + "importNames": ["t"], + "message": "Please use instead of t." }, { "name": "styled-components", "message": "Please import from styled-components/macro." - }, - { - "name": "@lingui/macro", - "importNames": ["t"], - "message": "Please use instead of t." } ], "patterns": [ @@ -81,6 +73,10 @@ "group": ["**/dist"], "message": "Do not import from dist/ - this is an implementation detail, and breaks tree-shaking." }, + { + "group": ["@ethersproject"], + "message": "Please import from 'ethers' to support bundling." + }, { "group": ["!styled-components/macro"] } diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 79253627a3..fd56433f40 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -4,9 +4,9 @@ // https://on.cypress.io/custom-commands // *********************************************** +// eslint-disable-next-line no-restricted-imports import { Eip1193Bridge } from '@ethersproject/experimental/lib/eip1193-bridge' -import { JsonRpcProvider } from '@ethersproject/providers' -import { Wallet } from '@ethersproject/wallet' +import { providers, Wallet } from 'ethers' // todo: figure out how env vars actually work in CI // const TEST_PRIVATE_KEY = Cypress.env('INTEGRATION_TEST_PRIVATE_KEY') @@ -81,7 +81,7 @@ Cypress.Commands.overwrite('visit', (original, url, options) => { onBeforeLoad(win) { options && options.onBeforeLoad && options.onBeforeLoad(win) win.localStorage.clear() - const provider = new JsonRpcProvider('https://rinkeby.infura.io/v3/4bf032f2d38a4ed6bb975b80d6340847', 4) + const provider = new providers.JsonRpcProvider('https://rinkeby.infura.io/v3/4bf032f2d38a4ed6bb975b80d6340847', 4) const signer = new Wallet(TEST_PRIVATE_KEY, provider) win.ethereum = new CustomizedBridge(signer, provider) }, diff --git a/package.json b/package.json index b2ce4c9fbb..2e410e803c 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,6 @@ "eslint-plugin-react-hooks": "^4.0.0", "eslint-plugin-simple-import-sort": "^7.0.0", "eslint-plugin-unused-imports": "^2.0.0", - "ethers": "^5.4.6", "firebase": "^9.1.3", "graphql": "^15.5.0", "graphql-request": "^3.4.0", @@ -135,7 +134,7 @@ "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=./custom-test-env.js", - "test:e2e": "start-server-and-test 'serve build -l 3000' http://localhost:3000 'cypress run --record'", + "test:e2e": "start-server-and-test 'serve build -l 3000' http://localhost:3000 'cypress run'", "assets:generate": "yarn assets:svg:generate && yarn assets:font:generate", "assets:svg:generate": "svgr -d src/lib/assets/svg --ext tsx --typescript src/lib/assets/svg && rm src/lib/assets/svg/index.tsx", "assets:font:generate": "sass src/lib/assets/fonts/index.scss src/lib/assets/fonts/index.css --no-source-map -I node_modules", @@ -157,10 +156,6 @@ }, "license": "GPL-3.0-or-later", "dependencies": { - "@ethersproject/contracts": "5.4.1", - "@ethersproject/hash": "5.4.0", - "@ethersproject/address": "5.4.0", - "@ethersproject/constants": "5.4.0", "@fontsource/ibm-plex-mono": "^4.5.1", "@fontsource/inter": "^4.5.1", "@lingui/core": "^3.9.0", @@ -172,9 +167,9 @@ "@uniswap/token-lists": "^1.0.0-beta.27", "ajv": "^6.12.3", "cids": "^1.0.0", + "ethers": "^5.4.6", "immer": "^9.0.6", "jotai": "^1.3.7", - "lodash": "^4.17.21", "make-plural": "^7.0.0", "multicodec": "^3.0.1", "multihashes": "^4.0.2", diff --git a/src/components/claim/AddressClaimModal.tsx b/src/components/claim/AddressClaimModal.tsx index 4b0a29abbc..55437831b5 100644 --- a/src/components/claim/AddressClaimModal.tsx +++ b/src/components/claim/AddressClaimModal.tsx @@ -1,6 +1,6 @@ -import { isAddress } from '@ethersproject/address' import { Trans } from '@lingui/macro' import { CurrencyAmount, Token } from '@uniswap/sdk-core' +import { isAddress } from 'ethers/lib/utils' import { useState } from 'react' import { Text } from 'rebass' import styled from 'styled-components/macro' diff --git a/src/components/claim/ClaimModal.tsx b/src/components/claim/ClaimModal.tsx index 26524d7a39..6c568debff 100644 --- a/src/components/claim/ClaimModal.tsx +++ b/src/components/claim/ClaimModal.tsx @@ -1,6 +1,6 @@ -import { isAddress } from '@ethersproject/address' import { Trans } from '@lingui/macro' import { CurrencyAmount, Token } from '@uniswap/sdk-core' +import { isAddress } from 'ethers/lib/utils' import JSBI from 'jsbi' import { useEffect, useState } from 'react' import { Text } from 'rebass' diff --git a/src/components/earn/ClaimRewardModal.tsx b/src/components/earn/ClaimRewardModal.tsx index 302e3bc57f..fb9a908106 100644 --- a/src/components/earn/ClaimRewardModal.tsx +++ b/src/components/earn/ClaimRewardModal.tsx @@ -1,5 +1,5 @@ -import { TransactionResponse } from '@ethersproject/providers' import { Trans } from '@lingui/macro' +import type { providers } from 'ethers' import { ReactNode, useState } from 'react' import styled from 'styled-components/macro' @@ -47,7 +47,7 @@ export default function ClaimRewardModal({ isOpen, onDismiss, stakingInfo }: Sta setAttempting(true) await stakingContract .getReward({ gasLimit: 350000 }) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { addTransaction(response, { type: TransactionType.CLAIM, recipient: account, diff --git a/src/components/earn/StakingModal.tsx b/src/components/earn/StakingModal.tsx index 8f619ec90d..93ac18dead 100644 --- a/src/components/earn/StakingModal.tsx +++ b/src/components/earn/StakingModal.tsx @@ -1,7 +1,7 @@ -import { TransactionResponse } from '@ethersproject/providers' import { Trans } from '@lingui/macro' import { CurrencyAmount, Token } from '@uniswap/sdk-core' import { Pair } from '@uniswap/v2-sdk' +import type { providers } from 'ethers' import { useCallback, useState } from 'react' import styled from 'styled-components/macro' @@ -105,7 +105,7 @@ export default function StakingModal({ isOpen, onDismiss, stakingInfo, userLiqui signatureData.s, { gasLimit: 350000 } ) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { addTransaction(response, { type: TransactionType.DEPOSIT_LIQUIDITY_STAKING, token0Address: stakingInfo.tokens[0].address, diff --git a/src/components/earn/UnstakingModal.tsx b/src/components/earn/UnstakingModal.tsx index f4144b7d77..26213befaf 100644 --- a/src/components/earn/UnstakingModal.tsx +++ b/src/components/earn/UnstakingModal.tsx @@ -1,5 +1,5 @@ -import { TransactionResponse } from '@ethersproject/providers' import { Trans } from '@lingui/macro' +import type { providers } from 'ethers' import { ReactNode, useState } from 'react' import styled from 'styled-components/macro' @@ -48,7 +48,7 @@ export default function UnstakingModal({ isOpen, onDismiss, stakingInfo }: Staki setAttempting(true) await stakingContract .exit({ gasLimit: 300000 }) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { addTransaction(response, { type: TransactionType.WITHDRAW_LIQUIDITY_STAKING, token0Address: stakingInfo.tokens[0].address, diff --git a/src/components/vote/DelegateModal.tsx b/src/components/vote/DelegateModal.tsx index b971e8173f..091d021289 100644 --- a/src/components/vote/DelegateModal.tsx +++ b/src/components/vote/DelegateModal.tsx @@ -1,5 +1,5 @@ -import { isAddress } from '@ethersproject/address' import { Trans } from '@lingui/macro' +import { isAddress } from 'ethers/lib/utils' import { ReactNode, useState } from 'react' import { X } from 'react-feather' import styled from 'styled-components/macro' diff --git a/src/connectors/index.ts b/src/connectors/index.ts index 2d2814fa42..5b255377a1 100644 --- a/src/connectors/index.ts +++ b/src/connectors/index.ts @@ -1,9 +1,9 @@ -import { Web3Provider } from '@ethersproject/providers' import { SafeAppConnector } from '@gnosis.pm/safe-apps-web3-react' import { InjectedConnector } from '@web3-react/injected-connector' import { PortisConnector } from '@web3-react/portis-connector' import { WalletConnectConnector } from '@web3-react/walletconnect-connector' import { WalletLinkConnector } from '@web3-react/walletlink-connector' +import type { providers } from 'ethers' import UNISWAP_LOGO_URL from '../assets/svg/logo.svg' import { ALL_SUPPORTED_CHAIN_IDS, INFURA_NETWORK_URLS, SupportedChainId } from '../constants/chains' @@ -19,8 +19,8 @@ export const network = new NetworkConnector({ defaultChainId: 1, }) -let networkLibrary: Web3Provider | undefined -export function getNetworkLibrary(): Web3Provider { +let networkLibrary: providers.Web3Provider | undefined +export function getNetworkLibrary(): providers.Web3Provider { return (networkLibrary = networkLibrary ?? getLibrary(network.provider)) } diff --git a/src/hooks/Tokens.ts b/src/hooks/Tokens.ts index 332d6ed54a..05a5c2df49 100644 --- a/src/hooks/Tokens.ts +++ b/src/hooks/Tokens.ts @@ -1,7 +1,6 @@ -import { arrayify } from '@ethersproject/bytes' -import { parseBytes32String } from '@ethersproject/strings' import { Currency, Token } from '@uniswap/sdk-core' import { CHAIN_INFO, L2_CHAIN_IDS, SupportedChainId, SupportedL2ChainId } from 'constants/chains' +import { arrayify, parseBytes32String } from 'ethers/lib/utils' import { useMemo } from 'react' import { createTokenFilterFunction } from '../components/SearchModal/filtering' diff --git a/src/hooks/useActiveWeb3React.ts b/src/hooks/useActiveWeb3React.ts index 8da7d18eff..934cac8365 100644 --- a/src/hooks/useActiveWeb3React.ts +++ b/src/hooks/useActiveWeb3React.ts @@ -1,13 +1,13 @@ -import { Web3Provider } from '@ethersproject/providers' import { useWeb3React } from '@web3-react/core' +import { providers } from 'ethers' import { default as useWidgetsWeb3React } from 'lib/hooks/useActiveWeb3React' import { NetworkContextName } from '../constants/misc' export default function useActiveWeb3React() { const widgetsContext = useWidgetsWeb3React() - const interfaceContext = useWeb3React() - const interfaceNetworkContext = useWeb3React( + const interfaceContext = useWeb3React() + const interfaceNetworkContext = useWeb3React( process.env.REACT_APP_IS_WIDGET ? undefined : NetworkContextName ) diff --git a/src/hooks/useApproveCallback.ts b/src/hooks/useApproveCallback.ts index 4e9ccfadd9..85f35bccb0 100644 --- a/src/hooks/useApproveCallback.ts +++ b/src/hooks/useApproveCallback.ts @@ -1,9 +1,9 @@ -import { MaxUint256 } from '@ethersproject/constants' -import { TransactionResponse } from '@ethersproject/providers' import { Protocol, Trade } from '@uniswap/router-sdk' import { Currency, CurrencyAmount, Percent, TradeType } from '@uniswap/sdk-core' import { Pair, Route as V2Route, Trade as V2Trade } from '@uniswap/v2-sdk' import { Pool, Route as V3Route, Trade as V3Trade } from '@uniswap/v3-sdk' +import type { providers } from 'ethers' +import { constants } from 'ethers' import { useCallback, useMemo } from 'react' import { getTxOptimizedSwapRouter, SwapRouterVersion } from 'utils/getTxOptimizedSwapRouter' @@ -111,17 +111,17 @@ export function useApproveCallback( } let useExact = false - const estimatedGas = await tokenContract.estimateGas.approve(spender, MaxUint256).catch(() => { + const estimatedGas = await tokenContract.estimateGas.approve(spender, constants.MaxUint256).catch(() => { // general fallback for tokens who restrict approval amounts useExact = true return tokenContract.estimateGas.approve(spender, amountToApprove.quotient.toString()) }) return tokenContract - .approve(spender, useExact ? amountToApprove.quotient.toString() : MaxUint256, { + .approve(spender, useExact ? amountToApprove.quotient.toString() : constants.MaxUint256, { gasLimit: calculateGasMargin(estimatedGas), }) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { addTransaction(response, { type: TransactionType.APPROVAL, tokenAddress: token.address, spender }) }) .catch((error: Error) => { diff --git a/src/hooks/useContract.ts b/src/hooks/useContract.ts index b3a12daea0..0b6741d7a0 100644 --- a/src/hooks/useContract.ts +++ b/src/hooks/useContract.ts @@ -1,4 +1,3 @@ -import { Contract } from '@ethersproject/contracts' import { abi as GOVERNANCE_ABI } from '@uniswap/governance/build/GovernorAlpha.json' import { abi as UNI_ABI } from '@uniswap/governance/build/Uni.json' import { abi as STAKING_REWARDS_ABI } from '@uniswap/liquidity-staker/build/StakingRewards.json' @@ -32,6 +31,7 @@ import { V2_ROUTER_ADDRESS, V3_MIGRATOR_ADDRESSES, } from 'constants/addresses' +import { Contract } from 'ethers' import { useMemo } from 'react' import { NonfungiblePositionManager, Quoter, UniswapInterfaceMulticall } from 'types/v3' import { V3Migrator } from 'types/v3/V3Migrator' diff --git a/src/hooks/useCurrentBlockTimestamp.ts b/src/hooks/useCurrentBlockTimestamp.ts index f05d9c04e7..928eb74a62 100644 --- a/src/hooks/useCurrentBlockTimestamp.ts +++ b/src/hooks/useCurrentBlockTimestamp.ts @@ -1,4 +1,4 @@ -import { BigNumber } from '@ethersproject/bignumber' +import { BigNumber } from 'ethers' import { useSingleCallResult } from '../state/multicall/hooks' import { useInterfaceMulticall } from './useContract' diff --git a/src/hooks/useENSAvatar.ts b/src/hooks/useENSAvatar.ts index ef28554efd..281f70893f 100644 --- a/src/hooks/useENSAvatar.ts +++ b/src/hooks/useENSAvatar.ts @@ -1,6 +1,5 @@ -import { BigNumber } from '@ethersproject/bignumber' -import { hexZeroPad } from '@ethersproject/bytes' -import { namehash } from '@ethersproject/hash' +import { BigNumber } from 'ethers' +import { hexZeroPad, namehash } from 'ethers/lib/utils' import uriToHttp from 'lib/utils/uriToHttp' import { useEffect, useMemo, useState } from 'react' import { safeNamehash } from 'utils/safeNamehash' diff --git a/src/hooks/useENSName.ts b/src/hooks/useENSName.ts index 3d4ac2b007..41e75d54bb 100644 --- a/src/hooks/useENSName.ts +++ b/src/hooks/useENSName.ts @@ -1,4 +1,4 @@ -import { namehash } from '@ethersproject/hash' +import { namehash } from 'ethers/lib/utils' import { useMemo } from 'react' import { useSingleCallResult } from '../state/multicall/hooks' diff --git a/src/hooks/useERC20Permit.ts b/src/hooks/useERC20Permit.ts index f5ca9b484d..1d90b32775 100644 --- a/src/hooks/useERC20Permit.ts +++ b/src/hooks/useERC20Permit.ts @@ -1,8 +1,8 @@ -import { splitSignature } from '@ethersproject/bytes' import { Trade } from '@uniswap/router-sdk' import { Currency, CurrencyAmount, Percent, Token, TradeType } from '@uniswap/sdk-core' import { Trade as V2Trade } from '@uniswap/v2-sdk' import { Trade as V3Trade } from '@uniswap/v3-sdk' +import { splitSignature } from 'ethers/lib/utils' import JSBI from 'jsbi' import { useMemo, useState } from 'react' diff --git a/src/hooks/useMonitoringEventCallback.ts b/src/hooks/useMonitoringEventCallback.ts index 9a175e1771..d670fea842 100644 --- a/src/hooks/useMonitoringEventCallback.ts +++ b/src/hooks/useMonitoringEventCallback.ts @@ -1,4 +1,4 @@ -import { TransactionResponse } from '@ethersproject/providers' +import { providers } from 'ethers' import { initializeApp } from 'firebase/app' import { getDatabase, push, ref } from 'firebase/database' import { useCallback } from 'react' @@ -6,7 +6,7 @@ import { TransactionInfo, TransactionType } from 'state/transactions/actions' import { useActiveWeb3React } from './web3' -type PartialTransactionResponse = Pick +type PartialTransactionResponse = Pick const SUPPORTED_TRANSACTION_TYPES = [ TransactionType.ADD_LIQUIDITY_V2_POOL, @@ -61,7 +61,7 @@ export function useTransactionMonitoringEventCallback() { const log = useMonitoringEventCallback() return useCallback( - (info: TransactionInfo, transactionResponse: TransactionResponse) => { + (info: TransactionInfo, transactionResponse: providers.TransactionResponse) => { if (SUPPORTED_TRANSACTION_TYPES.includes(info.type)) { log(TransactionType[info.type], { transactionResponse: (({ hash, v, r, s }: PartialTransactionResponse) => ({ hash, v, r, s }))( diff --git a/src/hooks/usePools.ts b/src/hooks/usePools.ts index d179b1ac54..a913d75104 100644 --- a/src/hooks/usePools.ts +++ b/src/hooks/usePools.ts @@ -1,8 +1,8 @@ -import { Interface } from '@ethersproject/abi' import { Currency, Token } from '@uniswap/sdk-core' import { abi as IUniswapV3PoolStateABI } from '@uniswap/v3-core/artifacts/contracts/interfaces/pool/IUniswapV3PoolState.sol/IUniswapV3PoolState.json' import { computePoolAddress } from '@uniswap/v3-sdk' import { FeeAmount, Pool } from '@uniswap/v3-sdk' +import { Interface } from 'ethers/lib/utils' import { useMemo } from 'react' import { V3_CORE_FACTORY_ADDRESSES } from '../constants/addresses' diff --git a/src/hooks/usePositionTokenURI.ts b/src/hooks/usePositionTokenURI.ts index 2f42eedf8a..0a2608eab9 100644 --- a/src/hooks/usePositionTokenURI.ts +++ b/src/hooks/usePositionTokenURI.ts @@ -1,4 +1,4 @@ -import { BigNumber } from '@ethersproject/bignumber' +import { BigNumber } from 'ethers' import JSBI from 'jsbi' import { useMemo } from 'react' diff --git a/src/hooks/useSwapCallback.tsx b/src/hooks/useSwapCallback.tsx index 8c56838a34..2ed319f206 100644 --- a/src/hooks/useSwapCallback.tsx +++ b/src/hooks/useSwapCallback.tsx @@ -1,10 +1,10 @@ -import { BigNumber } from '@ethersproject/bignumber' // eslint-disable-next-line no-restricted-imports import { t, Trans } from '@lingui/macro' import { SwapRouter, Trade } from '@uniswap/router-sdk' import { Currency, Percent, TradeType } from '@uniswap/sdk-core' import { Router as V2SwapRouter, Trade as V2Trade } from '@uniswap/v2-sdk' import { SwapRouter as V3SwapRouter, Trade as V3Trade } from '@uniswap/v3-sdk' +import { BigNumber } from 'ethers' import { ReactNode, useMemo } from 'react' import { SWAP_ROUTER_ADDRESSES, V3_ROUTER_ADDRESS } from '../constants/addresses' diff --git a/src/hooks/useTotalSupply.ts b/src/hooks/useTotalSupply.ts index 8d424d6d40..4f8bc0679f 100644 --- a/src/hooks/useTotalSupply.ts +++ b/src/hooks/useTotalSupply.ts @@ -1,5 +1,5 @@ -import { BigNumber } from '@ethersproject/bignumber' import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core' +import { BigNumber } from 'ethers' import { useSingleCallResult } from '../state/multicall/hooks' import { useTokenContract } from './useContract' diff --git a/src/hooks/useTransactionDeadline.ts b/src/hooks/useTransactionDeadline.ts index 4ae41cb7f9..ec200bfb1e 100644 --- a/src/hooks/useTransactionDeadline.ts +++ b/src/hooks/useTransactionDeadline.ts @@ -1,6 +1,6 @@ -import { BigNumber } from '@ethersproject/bignumber' import { L2_CHAIN_IDS } from 'constants/chains' import { L2_DEADLINE_FROM_NOW } from 'constants/misc' +import { BigNumber } from 'ethers' import { useMemo } from 'react' import { useAppSelector } from 'state/hooks' diff --git a/src/hooks/useV2Pairs.ts b/src/hooks/useV2Pairs.ts index 946e134e2f..3a92b1296c 100644 --- a/src/hooks/useV2Pairs.ts +++ b/src/hooks/useV2Pairs.ts @@ -1,7 +1,7 @@ -import { Interface } from '@ethersproject/abi' import { Currency, CurrencyAmount } from '@uniswap/sdk-core' import { abi as IUniswapV2PairABI } from '@uniswap/v2-core/build/IUniswapV2Pair.json' import { computePairAddress, Pair } from '@uniswap/v2-sdk' +import { Interface } from 'ethers/lib/utils' import { useMemo } from 'react' import { V2_FACTORY_ADDRESSES } from '../constants/addresses' diff --git a/src/hooks/useV3PositionFees.ts b/src/hooks/useV3PositionFees.ts index 15f98965ea..8a069941bb 100644 --- a/src/hooks/useV3PositionFees.ts +++ b/src/hooks/useV3PositionFees.ts @@ -1,6 +1,6 @@ -import { BigNumber } from '@ethersproject/bignumber' import { Currency, CurrencyAmount } from '@uniswap/sdk-core' import { Pool } from '@uniswap/v3-sdk' +import { BigNumber } from 'ethers' import { useEffect, useState } from 'react' import { useBlockNumber } from 'state/application/hooks' import { useSingleCallResult } from 'state/multicall/hooks' diff --git a/src/hooks/useV3Positions.ts b/src/hooks/useV3Positions.ts index add347aa30..a954d81b80 100644 --- a/src/hooks/useV3Positions.ts +++ b/src/hooks/useV3Positions.ts @@ -1,4 +1,4 @@ -import { BigNumber } from '@ethersproject/bignumber' +import { BigNumber } from 'ethers' import { useMemo } from 'react' import { CallStateResult, useSingleCallResult, useSingleContractMultipleData } from 'state/multicall/hooks' import { PositionDetails } from 'types/position' diff --git a/src/lib/.eslintrc.json b/src/lib/.eslintrc.json index b859374fb8..3404f8b782 100644 --- a/src/lib/.eslintrc.json +++ b/src/lib/.eslintrc.json @@ -7,14 +7,16 @@ "error", { "paths": [ - { - "name": "styled-components/macro", - "message": "Please import styled from lib/theme to get the correct typings." - }, { "name": "react-feather", "message": "Please import from lib/icons to ensure performant usage." } + ], + "patterns": [ + { + "group": ["styled-components"], + "message": "Please import styled from lib/theme to get the correct typings." + } ] } ] diff --git a/src/lib/components/Swap/Settings/components.tsx b/src/lib/components/Swap/Settings/components.tsx index f7a819a49a..cb914bcd9d 100644 --- a/src/lib/components/Swap/Settings/components.tsx +++ b/src/lib/components/Swap/Settings/components.tsx @@ -1,5 +1,6 @@ import styled, { css, ThemedText } from 'lib/theme' import { ReactNode } from 'react' +// eslint-disable-next-line no-restricted-imports import { AnyStyledComponent } from 'styled-components' import Row from '../../Row' diff --git a/src/lib/utils/resolveENSContentHash.ts b/src/lib/utils/resolveENSContentHash.ts index 97e9f5e6aa..cdeb6b1851 100644 --- a/src/lib/utils/resolveENSContentHash.ts +++ b/src/lib/utils/resolveENSContentHash.ts @@ -1,6 +1,6 @@ -import { Provider } from '@ethersproject/abstract-provider' -import { Contract } from '@ethersproject/contracts' -import { namehash } from '@ethersproject/hash' +import type { providers } from 'ethers' +import { Contract } from 'ethers' +import { namehash } from 'ethers/lib/utils' const REGISTRAR_ABI = [ { @@ -50,7 +50,7 @@ const RESOLVER_ABI = [ ] // cache the resolver contracts since most of them are the public resolver -function resolverContract(resolverAddress: string, provider: Provider): Contract { +function resolverContract(resolverAddress: string, provider: providers.Provider): Contract { return new Contract(resolverAddress, RESOLVER_ABI, provider) } @@ -59,7 +59,7 @@ function resolverContract(resolverAddress: string, provider: Provider): Contract * @param ensName to resolve * @param provider provider to use to fetch the data */ -export default async function resolveENSContentHash(ensName: string, provider: Provider): Promise { +export default async function resolveENSContentHash(ensName: string, provider: providers.Provider): Promise { const ensRegistrarContract = new Contract(REGISTRAR_ADDRESS, REGISTRAR_ABI, provider) const hash = namehash(ensName) const resolverAddress = await ensRegistrarContract.resolver(hash) diff --git a/src/pages/AddLiquidity/index.tsx b/src/pages/AddLiquidity/index.tsx index fe97cb0a53..1628cc6100 100644 --- a/src/pages/AddLiquidity/index.tsx +++ b/src/pages/AddLiquidity/index.tsx @@ -1,9 +1,9 @@ -import { BigNumber } from '@ethersproject/bignumber' -import { TransactionResponse } from '@ethersproject/providers' import { Trans } from '@lingui/macro' import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core' import { FeeAmount, NonfungiblePositionManager } from '@uniswap/v3-sdk' import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter' +import type { providers } from 'ethers' +import { BigNumber } from 'ethers' import { useCallback, useContext, useEffect, useState } from 'react' import { AlertTriangle } from 'react-feather' import ReactGA from 'react-ga' @@ -272,7 +272,7 @@ export default function AddLiquidity({ return library .getSigner() .sendTransaction(newTxn) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { setAttemptingTxn(false) addTransaction(response, { type: TransactionType.ADD_LIQUIDITY_V3_POOL, diff --git a/src/pages/AddLiquidityV2/index.tsx b/src/pages/AddLiquidityV2/index.tsx index c52c999059..680e6c539b 100644 --- a/src/pages/AddLiquidityV2/index.tsx +++ b/src/pages/AddLiquidityV2/index.tsx @@ -1,9 +1,9 @@ -import { BigNumber } from '@ethersproject/bignumber' -import { TransactionResponse } from '@ethersproject/providers' import { Trans } from '@lingui/macro' import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core' import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter' import { SwitchLocaleLink } from 'components/SwitchLocaleLink' +import type { providers } from 'ethers' +import { BigNumber } from 'ethers' import { useCallback, useContext, useState } from 'react' import { Plus } from 'react-feather' import ReactGA from 'react-ga' @@ -147,7 +147,7 @@ export default function AddLiquidity({ } let estimate, - method: (...args: any) => Promise, + method: (...args: any) => Promise, args: Array, value: BigNumber | null if (currencyA.isNative || currencyB.isNative) { diff --git a/src/pages/CreateProposal/index.tsx b/src/pages/CreateProposal/index.tsx index 61674deb79..a0ffcb7243 100644 --- a/src/pages/CreateProposal/index.tsx +++ b/src/pages/CreateProposal/index.tsx @@ -1,10 +1,9 @@ -import { defaultAbiCoder } from '@ethersproject/abi' -import { getAddress, isAddress } from '@ethersproject/address' import { Trans } from '@lingui/macro' import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core' import { ButtonError } from 'components/Button' import { BlueCard } from 'components/Card' import { AutoColumn } from 'components/Column' +import { defaultAbiCoder, getAddress, isAddress } from 'ethers/lib/utils' import { useActiveWeb3React } from 'hooks/web3' import JSBI from 'jsbi' import { Wrapper } from 'pages/Pool/styleds' diff --git a/src/pages/MigrateV2/MigrateV2Pair.tsx b/src/pages/MigrateV2/MigrateV2Pair.tsx index 34eba4cf71..9962b205a1 100644 --- a/src/pages/MigrateV2/MigrateV2Pair.tsx +++ b/src/pages/MigrateV2/MigrateV2Pair.tsx @@ -1,5 +1,3 @@ -import { Contract } from '@ethersproject/contracts' -import { TransactionResponse } from '@ethersproject/providers' import { Trans } from '@lingui/macro' import { CurrencyAmount, Fraction, Percent, Price, Token } from '@uniswap/sdk-core' import { FeeAmount, Pool, Position, priceToClosestTick, TickMath } from '@uniswap/v3-sdk' @@ -12,6 +10,8 @@ import RangeSelector from 'components/RangeSelector' import RateToggle from 'components/RateToggle' import SettingsTab from 'components/Settings' import { Dots } from 'components/swap/styleds' +import type { providers } from 'ethers' +import { Contract } from 'ethers' import { ApprovalState, useApproveCallback } from 'hooks/useApproveCallback' import useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp' import { PoolState, usePool } from 'hooks/usePools' @@ -335,7 +335,7 @@ function V2PairMigration({ .then((gasEstimate) => { return migrator .multicall(data, { gasLimit: calculateGasMargin(gasEstimate) }) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { ReactGA.event({ category: 'Migrate', action: `${isNotUniswap ? 'SushiSwap' : 'V2'}->V3`, diff --git a/src/pages/MigrateV2/index.tsx b/src/pages/MigrateV2/index.tsx index 607fc4dc1d..ebf438504b 100644 --- a/src/pages/MigrateV2/index.tsx +++ b/src/pages/MigrateV2/index.tsx @@ -1,11 +1,10 @@ -import { getCreate2Address } from '@ethersproject/address' -import { keccak256, pack } from '@ethersproject/solidity' import { Trans } from '@lingui/macro' import { Token } from '@uniswap/sdk-core' import { Pair } from '@uniswap/v2-sdk' import MigrateSushiPositionCard from 'components/PositionCard/Sushi' import MigrateV2PositionCard from 'components/PositionCard/V2' import { SwitchLocaleLink } from 'components/SwitchLocaleLink' +import { getCreate2Address, solidityKeccak256 as keccak256, solidityPack as pack } from 'ethers/lib/utils' import { PairState, useV2Pairs } from 'hooks/useV2Pairs' import { ReactNode, useContext, useMemo } from 'react' import { Text } from 'rebass' diff --git a/src/pages/Pool/PositionPage.tsx b/src/pages/Pool/PositionPage.tsx index c957f50100..bbb8a603d8 100644 --- a/src/pages/Pool/PositionPage.tsx +++ b/src/pages/Pool/PositionPage.tsx @@ -1,5 +1,3 @@ -import { BigNumber } from '@ethersproject/bignumber' -import { TransactionResponse } from '@ethersproject/providers' import { Trans } from '@lingui/macro' import { Currency, CurrencyAmount, Fraction, Percent, Price, Token } from '@uniswap/sdk-core' import { NonfungiblePositionManager, Pool, Position } from '@uniswap/v3-sdk' @@ -14,6 +12,8 @@ import { RowBetween, RowFixed } from 'components/Row' import { Dots } from 'components/swap/styleds' import Toggle from 'components/Toggle' import TransactionConfirmationModal, { ConfirmationModalContent } from 'components/TransactionConfirmationModal' +import type { providers } from 'ethers' +import { BigNumber } from 'ethers' import { useToken } from 'hooks/Tokens' import { useV3NFTPositionManagerContract } from 'hooks/useContract' import useIsTickAtLimit from 'hooks/useIsTickAtLimit' @@ -448,7 +448,7 @@ export function PositionPage({ return library .getSigner() .sendTransaction(newTxn) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { setCollectMigrationHash(response.hash) setCollecting(false) diff --git a/src/pages/RemoveLiquidity/V3.tsx b/src/pages/RemoveLiquidity/V3.tsx index 5a09839017..5182a141f6 100644 --- a/src/pages/RemoveLiquidity/V3.tsx +++ b/src/pages/RemoveLiquidity/V3.tsx @@ -1,5 +1,3 @@ -import { BigNumber } from '@ethersproject/bignumber' -import { TransactionResponse } from '@ethersproject/providers' import { Trans } from '@lingui/macro' import { Percent } from '@uniswap/sdk-core' import { NonfungiblePositionManager } from '@uniswap/v3-sdk' @@ -16,6 +14,8 @@ import { AddRemoveTabs } from 'components/NavigationTabs' import { AutoRow, RowBetween, RowFixed } from 'components/Row' import Slider from 'components/Slider' import Toggle from 'components/Toggle' +import type { providers } from 'ethers' +import { BigNumber } from 'ethers' import { useV3NFTPositionManagerContract } from 'hooks/useContract' import useDebouncedChangeHandler from 'hooks/useDebouncedChangeHandler' import useTheme from 'hooks/useTheme' @@ -145,7 +145,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) { return library .getSigner() .sendTransaction(newTxn) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { ReactGA.event({ category: 'Liquidity', action: 'RemoveV3', diff --git a/src/pages/RemoveLiquidity/index.tsx b/src/pages/RemoveLiquidity/index.tsx index a4f27886f2..fca87e4365 100644 --- a/src/pages/RemoveLiquidity/index.tsx +++ b/src/pages/RemoveLiquidity/index.tsx @@ -1,8 +1,7 @@ -import { BigNumber } from '@ethersproject/bignumber' -import { Contract } from '@ethersproject/contracts' -import { TransactionResponse } from '@ethersproject/providers' import { Trans } from '@lingui/macro' import { Currency, Percent } from '@uniswap/sdk-core' +import type { providers } from 'ethers' +import { BigNumber, Contract } from 'ethers' import { useCallback, useContext, useMemo, useState } from 'react' import { ArrowDown, Plus } from 'react-feather' import ReactGA from 'react-ga' @@ -262,7 +261,7 @@ export default function RemoveLiquidity({ await router[methodName](...args, { gasLimit: safeGasEstimate, }) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { setAttemptingTxn(false) addTransaction(response, { diff --git a/src/pages/Vote/VotePage.tsx b/src/pages/Vote/VotePage.tsx index 41f9d16ff3..d0aa0bf2d4 100644 --- a/src/pages/Vote/VotePage.tsx +++ b/src/pages/Vote/VotePage.tsx @@ -1,7 +1,7 @@ -import { BigNumber } from '@ethersproject/bignumber' // eslint-disable-next-line no-restricted-imports import { t, Trans } from '@lingui/macro' import { CurrencyAmount, Token } from '@uniswap/sdk-core' +import { BigNumber } from 'ethers' import { useActiveLocale } from 'hooks/useActiveLocale' import useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp' import JSBI from 'jsbi' diff --git a/src/state/claim/hooks.ts b/src/state/claim/hooks.ts index 7f6cda6ea6..eba367f526 100644 --- a/src/state/claim/hooks.ts +++ b/src/state/claim/hooks.ts @@ -1,5 +1,5 @@ -import { TransactionResponse } from '@ethersproject/providers' import { CurrencyAmount, Token } from '@uniswap/sdk-core' +import type { providers } from 'ethers' import JSBI from 'jsbi' import { useEffect, useState } from 'react' @@ -165,7 +165,7 @@ export function useClaimCallback(account: string | null | undefined): { return distributorContract.estimateGas['claim'](...args, {}).then((estimatedGasLimit) => { return distributorContract .claim(...args, { value: null, gasLimit: calculateGasMargin(estimatedGasLimit) }) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { addTransaction(response, { type: TransactionType.CLAIM, recipient: account, diff --git a/src/state/governance/hooks.ts b/src/state/governance/hooks.ts index 71a10e0898..68cca5a001 100644 --- a/src/state/governance/hooks.ts +++ b/src/state/governance/hooks.ts @@ -1,15 +1,20 @@ -import { defaultAbiCoder, Interface } from '@ethersproject/abi' -import { isAddress } from '@ethersproject/address' -import { Contract } from '@ethersproject/contracts' -import { TransactionResponse } from '@ethersproject/providers' -import { toUtf8String, Utf8ErrorFuncs, Utf8ErrorReason } from '@ethersproject/strings' -import { formatUnits } from '@ethersproject/units' // eslint-disable-next-line no-restricted-imports import { t } from '@lingui/macro' import { abi as GOV_ABI } from '@uniswap/governance/build/GovernorAlpha.json' import { CurrencyAmount, Token } from '@uniswap/sdk-core' import { POLYGON_PROPOSAL_TITLE } from 'constants/proposals/polygon_proposal_title' import { UNISWAP_GRANTS_PROPOSAL_DESCRIPTION } from 'constants/proposals/uniswap_grants_proposal_description' +import type { providers } from 'ethers' +import { Contract } from 'ethers' +import { + defaultAbiCoder, + formatUnits, + Interface, + isAddress, + toUtf8String, + Utf8ErrorFuncs, + Utf8ErrorReason, +} from 'ethers/lib/utils' import { useGovernanceBravoContract, useGovernanceV0Contract, @@ -320,7 +325,7 @@ export function useDelegateCallback(): (delegatee: string | undefined) => undefi return uniContract.estimateGas.delegate(...args, {}).then((estimatedGasLimit) => { return uniContract .delegate(...args, { value: null, gasLimit: calculateGasMargin(estimatedGasLimit) }) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { addTransaction(response, { type: TransactionType.DELEGATE, delegatee, @@ -349,7 +354,7 @@ export function useVoteCallback(): { return latestGovernanceContract.estimateGas.castVote(...args, {}).then((estimatedGasLimit) => { return latestGovernanceContract .castVote(...args, { value: null, gasLimit: calculateGasMargin(estimatedGasLimit) }) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { addTransaction(response, { type: TransactionType.VOTE, decision: voteOption, @@ -389,7 +394,7 @@ export function useCreateProposalCallback(): ( return latestGovernanceContract.estimateGas.propose(...args).then((estimatedGasLimit) => { return latestGovernanceContract .propose(...args, { gasLimit: calculateGasMargin(estimatedGasLimit) }) - .then((response: TransactionResponse) => { + .then((response: providers.TransactionResponse) => { addTransaction(response, { type: TransactionType.SUBMIT_PROPOSAL, }) diff --git a/src/state/stake/hooks.tsx b/src/state/stake/hooks.tsx index 4769e3f980..a7f0d0c9ec 100644 --- a/src/state/stake/hooks.tsx +++ b/src/state/stake/hooks.tsx @@ -1,8 +1,8 @@ -import { Interface } from '@ethersproject/abi' import { Trans } from '@lingui/macro' import { abi as STAKING_REWARDS_ABI } from '@uniswap/liquidity-staker/build/StakingRewards.json' import { CurrencyAmount, Token } from '@uniswap/sdk-core' import { Pair } from '@uniswap/v2-sdk' +import { Interface } from 'ethers/lib/utils' import useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp' import JSBI from 'jsbi' import { ReactNode, useMemo } from 'react' diff --git a/src/state/swap/hooks.tsx b/src/state/swap/hooks.tsx index c1961371d1..848500e4e6 100644 --- a/src/state/swap/hooks.tsx +++ b/src/state/swap/hooks.tsx @@ -1,6 +1,6 @@ -import { parseUnits } from '@ethersproject/units' import { Trans } from '@lingui/macro' import { Currency, CurrencyAmount, Percent, TradeType } from '@uniswap/sdk-core' +import { parseUnits } from 'ethers/lib/utils' import { useBestTrade } from 'hooks/useBestTrade' import JSBI from 'jsbi' import { ParsedQs } from 'qs' diff --git a/src/state/transactions/hooks.tsx b/src/state/transactions/hooks.tsx index c6b1bd5899..edd5f0f880 100644 --- a/src/state/transactions/hooks.tsx +++ b/src/state/transactions/hooks.tsx @@ -1,4 +1,4 @@ -import { TransactionResponse } from '@ethersproject/providers' +import type { providers } from 'ethers' import { useTransactionMonitoringEventCallback } from 'hooks/useMonitoringEventCallback' import { useCallback, useMemo } from 'react' import { useAppDispatch, useAppSelector } from 'state/hooks' @@ -8,14 +8,14 @@ import { addTransaction, TransactionInfo, TransactionType } from './actions' import { TransactionDetails } from './reducer' // helper that can take a ethers library transaction response and add it to the list of transactions -export function useTransactionAdder(): (response: TransactionResponse, info: TransactionInfo) => void { +export function useTransactionAdder(): (response: providers.TransactionResponse, info: TransactionInfo) => void { const { chainId, account } = useActiveWeb3React() const dispatch = useAppDispatch() const logMonitoringEvent = useTransactionMonitoringEventCallback() return useCallback( - (response: TransactionResponse, info: TransactionInfo) => { + (response: providers.TransactionResponse, info: TransactionInfo) => { if (!account) return if (!chainId) return diff --git a/src/state/wallet/hooks.ts b/src/state/wallet/hooks.ts index 9eaa67f6bc..d27cdc8ac0 100644 --- a/src/state/wallet/hooks.ts +++ b/src/state/wallet/hooks.ts @@ -1,7 +1,7 @@ -import { Interface } from '@ethersproject/abi' import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core' import ERC20ABI from 'abis/erc20.json' import { Erc20Interface } from 'abis/types/Erc20' +import { Interface } from 'ethers/lib/utils' import JSBI from 'jsbi' import { useMemo } from 'react' diff --git a/src/types/position.d.ts b/src/types/position.d.ts index bce78b196c..a86aa9134b 100644 --- a/src/types/position.d.ts +++ b/src/types/position.d.ts @@ -1,4 +1,4 @@ -import { BigNumber } from '@ethersproject/bignumber' +import { BigNumber } from 'ethers' export interface PositionDetails { nonce: BigNumber diff --git a/src/utils/approveAmountCalldata.ts b/src/utils/approveAmountCalldata.ts index cdb77db920..45469581c8 100644 --- a/src/utils/approveAmountCalldata.ts +++ b/src/utils/approveAmountCalldata.ts @@ -1,6 +1,6 @@ -import { Interface } from '@ethersproject/abi' import { Currency, CurrencyAmount } from '@uniswap/sdk-core' import { toHex } from '@uniswap/v3-sdk' +import { Interface } from 'ethers/lib/utils' import { Erc20Interface } from '../abis/types/Erc20' diff --git a/src/utils/calculateGasMargin.test.ts b/src/utils/calculateGasMargin.test.ts index 82da8c6cd2..10ac8c92c2 100644 --- a/src/utils/calculateGasMargin.test.ts +++ b/src/utils/calculateGasMargin.test.ts @@ -1,4 +1,4 @@ -import { BigNumber } from '@ethersproject/bignumber' +import { BigNumber } from 'ethers' import { calculateGasMargin } from './calculateGasMargin' diff --git a/src/utils/calculateGasMargin.ts b/src/utils/calculateGasMargin.ts index 67ef2dc936..8aa88e8746 100644 --- a/src/utils/calculateGasMargin.ts +++ b/src/utils/calculateGasMargin.ts @@ -1,4 +1,4 @@ -import { BigNumber } from '@ethersproject/bignumber' +import { BigNumber } from 'ethers' /** * Returns the gas value plus a margin for unexpected or variable gas costs diff --git a/src/utils/calculateSlippageAmount.test.ts b/src/utils/calculateSlippageAmount.test.ts index 95167419f5..3e72419050 100644 --- a/src/utils/calculateSlippageAmount.test.ts +++ b/src/utils/calculateSlippageAmount.test.ts @@ -1,11 +1,11 @@ -import { AddressZero } from '@ethersproject/constants' import { CurrencyAmount, Percent, Token } from '@uniswap/sdk-core' +import { constants } from 'ethers' import { calculateSlippageAmount } from './calculateSlippageAmount' describe('#calculateSlippageAmount', () => { it('bounds are correct', () => { - const tokenAmount = CurrencyAmount.fromRawAmount(new Token(1, AddressZero, 0), '100') + const tokenAmount = CurrencyAmount.fromRawAmount(new Token(1, constants.AddressZero, 0), '100') expect(() => calculateSlippageAmount(tokenAmount, new Percent(-1, 10_000))).toThrow('Unexpected slippage') expect(() => calculateSlippageAmount(tokenAmount, new Percent(10_001, 10_000))).toThrow('Unexpected slippage') expect(calculateSlippageAmount(tokenAmount, new Percent(0, 10_000)).map((bound) => bound.toString())).toEqual([ @@ -30,7 +30,7 @@ describe('#calculateSlippageAmount', () => { ]) }) it('works for 18 decimals', () => { - const tokenAmount = CurrencyAmount.fromRawAmount(new Token(1, AddressZero, 18), '100') + const tokenAmount = CurrencyAmount.fromRawAmount(new Token(1, constants.AddressZero, 18), '100') expect(() => calculateSlippageAmount(tokenAmount, new Percent(-1, 10_000))).toThrow('Unexpected slippage') expect(() => calculateSlippageAmount(tokenAmount, new Percent(10_001, 10_000))).toThrow('Unexpected slippage') expect(calculateSlippageAmount(tokenAmount, new Percent(0, 10_000)).map((bound) => bound.toString())).toEqual([ diff --git a/src/utils/computeUniCirculation.test.ts b/src/utils/computeUniCirculation.test.ts index 62adb004dc..778c9a51c4 100644 --- a/src/utils/computeUniCirculation.test.ts +++ b/src/utils/computeUniCirculation.test.ts @@ -1,5 +1,5 @@ -import { BigNumber } from '@ethersproject/bignumber' import { CurrencyAmount, Token } from '@uniswap/sdk-core' +import { BigNumber } from 'ethers' import JSBI from 'jsbi' import { ZERO_ADDRESS } from '../constants/misc' diff --git a/src/utils/computeUniCirculation.ts b/src/utils/computeUniCirculation.ts index adf8812d1e..b97b35f827 100644 --- a/src/utils/computeUniCirculation.ts +++ b/src/utils/computeUniCirculation.ts @@ -1,5 +1,5 @@ -import { BigNumber } from '@ethersproject/bignumber' import { CurrencyAmount, Token } from '@uniswap/sdk-core' +import { BigNumber } from 'ethers' import JSBI from 'jsbi' import { STAKING_GENESIS } from '../state/stake/hooks' diff --git a/src/utils/getLibrary.ts b/src/utils/getLibrary.ts index df23688a07..a875910797 100644 --- a/src/utils/getLibrary.ts +++ b/src/utils/getLibrary.ts @@ -1,4 +1,4 @@ -import { Web3Provider } from '@ethersproject/providers' +import { providers } from 'ethers' import ms from 'ms.macro' import { SupportedChainId } from '../constants/chains' @@ -10,8 +10,8 @@ const NETWORK_POLLING_INTERVALS: { [chainId: number]: number } = { [SupportedChainId.OPTIMISTIC_KOVAN]: ms`1s`, } -export default function getLibrary(provider: any): Web3Provider { - const library = new Web3Provider( +export default function getLibrary(provider: any): providers.Web3Provider { + const library = new providers.Web3Provider( provider, typeof provider.chainId === 'number' ? provider.chainId diff --git a/src/utils/index.ts b/src/utils/index.ts index dccc84a7d9..2ee2c93262 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,9 +1,8 @@ -import { getAddress } from '@ethersproject/address' -import { AddressZero } from '@ethersproject/constants' -import { Contract } from '@ethersproject/contracts' -import { JsonRpcSigner, Web3Provider } from '@ethersproject/providers' import { Token } from '@uniswap/sdk-core' import { FeeAmount } from '@uniswap/v3-sdk' +import type { providers } from 'ethers' +import { constants, Contract } from 'ethers' +import { getAddress } from 'ethers/lib/utils' import { TokenAddressMap } from '../state/lists/hooks' @@ -26,18 +25,21 @@ export function shortenAddress(address: string, chars = 4): string { } // account is not optional -function getSigner(library: Web3Provider, account: string): JsonRpcSigner { +function getSigner(library: providers.Web3Provider, account: string): providers.JsonRpcSigner { return library.getSigner(account).connectUnchecked() } // account is optional -function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner { +function getProviderOrSigner( + library: providers.Web3Provider, + account?: string +): providers.Web3Provider | providers.JsonRpcSigner { return account ? getSigner(library, account) : library } // account is optional -export function getContract(address: string, ABI: any, library: Web3Provider, account?: string): Contract { - if (!isAddress(address) || address === AddressZero) { +export function getContract(address: string, ABI: any, library: providers.Web3Provider, account?: string): Contract { + if (!isAddress(address) || address === constants.AddressZero) { throw Error(`Invalid 'address' parameter '${address}'.`) } diff --git a/src/utils/safeNamehash.test.ts b/src/utils/safeNamehash.test.ts index babcd089cf..f28683e27f 100644 --- a/src/utils/safeNamehash.test.ts +++ b/src/utils/safeNamehash.test.ts @@ -1,4 +1,4 @@ -import { namehash } from '@ethersproject/hash' +import { namehash } from 'ethers/lib/utils' import { safeNamehash } from './safeNamehash' diff --git a/src/utils/safeNamehash.ts b/src/utils/safeNamehash.ts index 0dc17076a5..b4907a452b 100644 --- a/src/utils/safeNamehash.ts +++ b/src/utils/safeNamehash.ts @@ -1,4 +1,4 @@ -import { namehash } from '@ethersproject/hash' +import { namehash } from 'ethers/lib/utils' export function safeNamehash(name?: string): string | undefined { if (name === undefined) return undefined diff --git a/src/utils/switchToNetwork.ts b/src/utils/switchToNetwork.ts index c411b10155..ba9968a158 100644 --- a/src/utils/switchToNetwork.ts +++ b/src/utils/switchToNetwork.ts @@ -1,10 +1,10 @@ -import { BigNumber } from '@ethersproject/bignumber' -import { hexStripZeros } from '@ethersproject/bytes' -import { Web3Provider } from '@ethersproject/providers' import { CHAIN_INFO, SupportedChainId } from 'constants/chains' +import type { providers } from 'ethers' +import { BigNumber } from 'ethers' +import { hexStripZeros } from 'ethers/lib/utils' interface SwitchNetworkArguments { - library: Web3Provider + library: providers.Web3Provider chainId: SupportedChainId } diff --git a/yarn.lock b/yarn.lock index be6e24e485..ba3432fec7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4942,11 +4942,6 @@ resolved "https://registry.yarnpkg.com/@uniswap/default-token-list/-/default-token-list-2.2.0.tgz#d85a5c2520f57f4920bd989dfc9f01e1b701a567" integrity sha512-vFPWoGzDjHP4i2l7yLaober/lZMmzOZXXirVF8XNyfNzRxgmYCWKO6SzKtfEUwxpd3/KUebgdK55II4Mnak62A== -"@uniswap/default-token-list@^3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/@uniswap/default-token-list/-/default-token-list-3.0.0.tgz#427ff2a65bbc77a5a24e60f6158441956773f684" - integrity sha512-t0H96s1Mx2ga6cGMj/wP/3NWdX4c9yZFd0ydiTOWLhWf1i5RjhWWND/ZTdn8QhmNsdHlhrGsWrEU62xoAY11bw== - "@uniswap/governance@^1.0.2": version "1.0.2" resolved "https://registry.npmjs.org/@uniswap/governance/-/governance-1.0.2.tgz"