From 711b2ca85cf6f12061c93603e2fad0a03dc3e5c1 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 12 Jan 2022 10:06:22 -0800 Subject: [PATCH] chore: import @ethersprojects directly (#3104) * Revert "chore: import from ethers" This reverts commit 6d9c0855d261679c316307ea3f668869c90e63a2. * Revert "fix: use provider JsonRpcProvider" This reverts commit dcbbab5e4d6458a11c38582388a7cb5b12691188. * chore: depend on @ethersprojects directly --- .eslintrc.json | 14 ++++---- cypress/support/commands.js | 6 ++-- package.json | 16 +++++++-- 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/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 | 41 +++++++++++----------- 56 files changed, 157 insertions(+), 146 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 105cc2e0c4..5497c9c6d1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -59,13 +59,17 @@ { "paths": [ { - "name": "@lingui/macro", - "importNames": ["t"], - "message": "Please use instead of t." + "name": "ethers", + "message": "Please import from '@ethersproject/module' directly to support tree-shaking." }, { "name": "styled-components", "message": "Please import from styled-components/macro." + }, + { + "name": "@lingui/macro", + "importNames": ["t"], + "message": "Please use instead of t." } ], "patterns": [ @@ -73,10 +77,6 @@ "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 fd56433f40..79253627a3 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 { providers, Wallet } from 'ethers' +import { JsonRpcProvider } from '@ethersproject/providers' +import { Wallet } from '@ethersproject/wallet' // 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 providers.JsonRpcProvider('https://rinkeby.infura.io/v3/4bf032f2d38a4ed6bb975b80d6340847', 4) + const provider = new 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 8eaf35c032..4ae0f6acd6 100644 --- a/package.json +++ b/package.json @@ -134,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'", + "test:e2e": "start-server-and-test 'serve build -l 3000' http://localhost:3000 'cypress run --record'", "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", @@ -156,6 +156,19 @@ }, "license": "GPL-3.0-or-later", "dependencies": { + "@ethersproject/abi": "^5.4.1", + "@ethersproject/abstract-provider": "^5.4.1", + "@ethersproject/address": "^5.4.0", + "@ethersproject/bignumber": "^5.4.2", + "@ethersproject/bytes": "^5.4.0", + "@ethersproject/constants": "^5.4.0", + "@ethersproject/contracts": "^5.4.1", + "@ethersproject/hash": "^5.4.0", + "@ethersproject/providers": "^5.4.5", + "@ethersproject/solidity": "^5.4.0", + "@ethersproject/strings": "^5.4.0", + "@ethersproject/units": "^5.4.0", + "@ethersproject/wallet": "^5.4.0", "@fontsource/ibm-plex-mono": "^4.5.1", "@fontsource/inter": "^4.5.1", "@lingui/core": "^3.9.0", @@ -167,7 +180,6 @@ "@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", "make-plural": "^7.0.0", diff --git a/src/components/claim/AddressClaimModal.tsx b/src/components/claim/AddressClaimModal.tsx index 55437831b5..4b0a29abbc 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 6c568debff..26524d7a39 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 fb9a908106..302e3bc57f 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: providers.TransactionResponse) => { + .then((response: TransactionResponse) => { addTransaction(response, { type: TransactionType.CLAIM, recipient: account, diff --git a/src/components/earn/StakingModal.tsx b/src/components/earn/StakingModal.tsx index 93ac18dead..8f619ec90d 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: providers.TransactionResponse) => { + .then((response: 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 26213befaf..f4144b7d77 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: providers.TransactionResponse) => { + .then((response: 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 091d021289..b971e8173f 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 2e3e7cf22a..1b3c8f14f5 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: providers.Web3Provider | undefined -export function getNetworkLibrary(): providers.Web3Provider { +let networkLibrary: Web3Provider | undefined +export function getNetworkLibrary(): Web3Provider { return (networkLibrary = networkLibrary ?? getLibrary(network.provider)) } diff --git a/src/hooks/Tokens.ts b/src/hooks/Tokens.ts index 05a5c2df49..332d6ed54a 100644 --- a/src/hooks/Tokens.ts +++ b/src/hooks/Tokens.ts @@ -1,6 +1,7 @@ +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 934cac8365..8da7d18eff 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 85f35bccb0..4e9ccfadd9 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, constants.MaxUint256).catch(() => { + const estimatedGas = await tokenContract.estimateGas.approve(spender, 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() : constants.MaxUint256, { + .approve(spender, useExact ? amountToApprove.quotient.toString() : MaxUint256, { gasLimit: calculateGasMargin(estimatedGas), }) - .then((response: providers.TransactionResponse) => { + .then((response: 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 0b6741d7a0..b3a12daea0 100644 --- a/src/hooks/useContract.ts +++ b/src/hooks/useContract.ts @@ -1,3 +1,4 @@ +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' @@ -31,7 +32,6 @@ 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 928eb74a62..f05d9c04e7 100644 --- a/src/hooks/useCurrentBlockTimestamp.ts +++ b/src/hooks/useCurrentBlockTimestamp.ts @@ -1,4 +1,4 @@ -import { BigNumber } from 'ethers' +import { BigNumber } from '@ethersproject/bignumber' import { useSingleCallResult } from '../state/multicall/hooks' import { useInterfaceMulticall } from './useContract' diff --git a/src/hooks/useENSAvatar.ts b/src/hooks/useENSAvatar.ts index 281f70893f..ef28554efd 100644 --- a/src/hooks/useENSAvatar.ts +++ b/src/hooks/useENSAvatar.ts @@ -1,5 +1,6 @@ -import { BigNumber } from 'ethers' -import { hexZeroPad, namehash } from 'ethers/lib/utils' +import { BigNumber } from '@ethersproject/bignumber' +import { hexZeroPad } from '@ethersproject/bytes' +import { namehash } from '@ethersproject/hash' 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 41e75d54bb..3d4ac2b007 100644 --- a/src/hooks/useENSName.ts +++ b/src/hooks/useENSName.ts @@ -1,4 +1,4 @@ -import { namehash } from 'ethers/lib/utils' +import { namehash } from '@ethersproject/hash' import { useMemo } from 'react' import { useSingleCallResult } from '../state/multicall/hooks' diff --git a/src/hooks/useERC20Permit.ts b/src/hooks/useERC20Permit.ts index 1d90b32775..f5ca9b484d 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 d670fea842..9a175e1771 100644 --- a/src/hooks/useMonitoringEventCallback.ts +++ b/src/hooks/useMonitoringEventCallback.ts @@ -1,4 +1,4 @@ -import { providers } from 'ethers' +import { TransactionResponse } from '@ethersproject/providers' 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: providers.TransactionResponse) => { + (info: TransactionInfo, transactionResponse: 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 a913d75104..d179b1ac54 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 0a2608eab9..2f42eedf8a 100644 --- a/src/hooks/usePositionTokenURI.ts +++ b/src/hooks/usePositionTokenURI.ts @@ -1,4 +1,4 @@ -import { BigNumber } from 'ethers' +import { BigNumber } from '@ethersproject/bignumber' import JSBI from 'jsbi' import { useMemo } from 'react' diff --git a/src/hooks/useSwapCallback.tsx b/src/hooks/useSwapCallback.tsx index 2ed319f206..8c56838a34 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 4f8bc0679f..8d424d6d40 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 ec200bfb1e..4ae41cb7f9 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 3a92b1296c..946e134e2f 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 8a069941bb..15f98965ea 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 a954d81b80..add347aa30 100644 --- a/src/hooks/useV3Positions.ts +++ b/src/hooks/useV3Positions.ts @@ -1,4 +1,4 @@ -import { BigNumber } from 'ethers' +import { BigNumber } from '@ethersproject/bignumber' import { useMemo } from 'react' import { CallStateResult, useSingleCallResult, useSingleContractMultipleData } from 'state/multicall/hooks' import { PositionDetails } from 'types/position' diff --git a/src/lib/utils/resolveENSContentHash.ts b/src/lib/utils/resolveENSContentHash.ts index cdeb6b1851..97e9f5e6aa 100644 --- a/src/lib/utils/resolveENSContentHash.ts +++ b/src/lib/utils/resolveENSContentHash.ts @@ -1,6 +1,6 @@ -import type { providers } from 'ethers' -import { Contract } from 'ethers' -import { namehash } from 'ethers/lib/utils' +import { Provider } from '@ethersproject/abstract-provider' +import { Contract } from '@ethersproject/contracts' +import { namehash } from '@ethersproject/hash' 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: providers.Provider): Contract { +function resolverContract(resolverAddress: string, provider: Provider): Contract { return new Contract(resolverAddress, RESOLVER_ABI, provider) } @@ -59,7 +59,7 @@ function resolverContract(resolverAddress: string, provider: providers.Provider) * @param ensName to resolve * @param provider provider to use to fetch the data */ -export default async function resolveENSContentHash(ensName: string, provider: providers.Provider): Promise { +export default async function resolveENSContentHash(ensName: string, provider: 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 1628cc6100..fe97cb0a53 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: providers.TransactionResponse) => { + .then((response: 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 680e6c539b..c52c999059 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 a0ffcb7243..61674deb79 100644 --- a/src/pages/CreateProposal/index.tsx +++ b/src/pages/CreateProposal/index.tsx @@ -1,9 +1,10 @@ +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 9962b205a1..34eba4cf71 100644 --- a/src/pages/MigrateV2/MigrateV2Pair.tsx +++ b/src/pages/MigrateV2/MigrateV2Pair.tsx @@ -1,3 +1,5 @@ +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' @@ -10,8 +12,6 @@ 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: providers.TransactionResponse) => { + .then((response: 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 ebf438504b..607fc4dc1d 100644 --- a/src/pages/MigrateV2/index.tsx +++ b/src/pages/MigrateV2/index.tsx @@ -1,10 +1,11 @@ +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 bbb8a603d8..c957f50100 100644 --- a/src/pages/Pool/PositionPage.tsx +++ b/src/pages/Pool/PositionPage.tsx @@ -1,3 +1,5 @@ +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' @@ -12,8 +14,6 @@ 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: providers.TransactionResponse) => { + .then((response: TransactionResponse) => { setCollectMigrationHash(response.hash) setCollecting(false) diff --git a/src/pages/RemoveLiquidity/V3.tsx b/src/pages/RemoveLiquidity/V3.tsx index 5182a141f6..5a09839017 100644 --- a/src/pages/RemoveLiquidity/V3.tsx +++ b/src/pages/RemoveLiquidity/V3.tsx @@ -1,3 +1,5 @@ +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' @@ -14,8 +16,6 @@ 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: providers.TransactionResponse) => { + .then((response: TransactionResponse) => { ReactGA.event({ category: 'Liquidity', action: 'RemoveV3', diff --git a/src/pages/RemoveLiquidity/index.tsx b/src/pages/RemoveLiquidity/index.tsx index fca87e4365..a4f27886f2 100644 --- a/src/pages/RemoveLiquidity/index.tsx +++ b/src/pages/RemoveLiquidity/index.tsx @@ -1,7 +1,8 @@ +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' @@ -261,7 +262,7 @@ export default function RemoveLiquidity({ await router[methodName](...args, { gasLimit: safeGasEstimate, }) - .then((response: providers.TransactionResponse) => { + .then((response: TransactionResponse) => { setAttemptingTxn(false) addTransaction(response, { diff --git a/src/pages/Vote/VotePage.tsx b/src/pages/Vote/VotePage.tsx index d0aa0bf2d4..41f9d16ff3 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 eba367f526..7f6cda6ea6 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: providers.TransactionResponse) => { + .then((response: TransactionResponse) => { addTransaction(response, { type: TransactionType.CLAIM, recipient: account, diff --git a/src/state/governance/hooks.ts b/src/state/governance/hooks.ts index 68cca5a001..71a10e0898 100644 --- a/src/state/governance/hooks.ts +++ b/src/state/governance/hooks.ts @@ -1,20 +1,15 @@ +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, @@ -325,7 +320,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: providers.TransactionResponse) => { + .then((response: TransactionResponse) => { addTransaction(response, { type: TransactionType.DELEGATE, delegatee, @@ -354,7 +349,7 @@ export function useVoteCallback(): { return latestGovernanceContract.estimateGas.castVote(...args, {}).then((estimatedGasLimit) => { return latestGovernanceContract .castVote(...args, { value: null, gasLimit: calculateGasMargin(estimatedGasLimit) }) - .then((response: providers.TransactionResponse) => { + .then((response: TransactionResponse) => { addTransaction(response, { type: TransactionType.VOTE, decision: voteOption, @@ -394,7 +389,7 @@ export function useCreateProposalCallback(): ( return latestGovernanceContract.estimateGas.propose(...args).then((estimatedGasLimit) => { return latestGovernanceContract .propose(...args, { gasLimit: calculateGasMargin(estimatedGasLimit) }) - .then((response: providers.TransactionResponse) => { + .then((response: TransactionResponse) => { addTransaction(response, { type: TransactionType.SUBMIT_PROPOSAL, }) diff --git a/src/state/stake/hooks.tsx b/src/state/stake/hooks.tsx index a7f0d0c9ec..4769e3f980 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 848500e4e6..c1961371d1 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 edd5f0f880..c6b1bd5899 100644 --- a/src/state/transactions/hooks.tsx +++ b/src/state/transactions/hooks.tsx @@ -1,4 +1,4 @@ -import type { providers } from 'ethers' +import { TransactionResponse } from '@ethersproject/providers' 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: providers.TransactionResponse, info: TransactionInfo) => void { +export function useTransactionAdder(): (response: TransactionResponse, info: TransactionInfo) => void { const { chainId, account } = useActiveWeb3React() const dispatch = useAppDispatch() const logMonitoringEvent = useTransactionMonitoringEventCallback() return useCallback( - (response: providers.TransactionResponse, info: TransactionInfo) => { + (response: TransactionResponse, info: TransactionInfo) => { if (!account) return if (!chainId) return diff --git a/src/state/wallet/hooks.ts b/src/state/wallet/hooks.ts index d27cdc8ac0..9eaa67f6bc 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 a86aa9134b..bce78b196c 100644 --- a/src/types/position.d.ts +++ b/src/types/position.d.ts @@ -1,4 +1,4 @@ -import { BigNumber } from 'ethers' +import { BigNumber } from '@ethersproject/bignumber' export interface PositionDetails { nonce: BigNumber diff --git a/src/utils/approveAmountCalldata.ts b/src/utils/approveAmountCalldata.ts index 45469581c8..cdb77db920 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 10ac8c92c2..82da8c6cd2 100644 --- a/src/utils/calculateGasMargin.test.ts +++ b/src/utils/calculateGasMargin.test.ts @@ -1,4 +1,4 @@ -import { BigNumber } from 'ethers' +import { BigNumber } from '@ethersproject/bignumber' import { calculateGasMargin } from './calculateGasMargin' diff --git a/src/utils/calculateGasMargin.ts b/src/utils/calculateGasMargin.ts index 8aa88e8746..67ef2dc936 100644 --- a/src/utils/calculateGasMargin.ts +++ b/src/utils/calculateGasMargin.ts @@ -1,4 +1,4 @@ -import { BigNumber } from 'ethers' +import { BigNumber } from '@ethersproject/bignumber' /** * 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 3e72419050..95167419f5 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, constants.AddressZero, 0), '100') + const tokenAmount = CurrencyAmount.fromRawAmount(new Token(1, 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, constants.AddressZero, 18), '100') + const tokenAmount = CurrencyAmount.fromRawAmount(new Token(1, 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 778c9a51c4..62adb004dc 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 b97b35f827..adf8812d1e 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 a875910797..df23688a07 100644 --- a/src/utils/getLibrary.ts +++ b/src/utils/getLibrary.ts @@ -1,4 +1,4 @@ -import { providers } from 'ethers' +import { Web3Provider } from '@ethersproject/providers' 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): providers.Web3Provider { - const library = new providers.Web3Provider( +export default function getLibrary(provider: any): Web3Provider { + const library = new Web3Provider( provider, typeof provider.chainId === 'number' ? provider.chainId diff --git a/src/utils/index.ts b/src/utils/index.ts index 2ee2c93262..dccc84a7d9 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,8 +1,9 @@ +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' @@ -25,21 +26,18 @@ export function shortenAddress(address: string, chars = 4): string { } // account is not optional -function getSigner(library: providers.Web3Provider, account: string): providers.JsonRpcSigner { +function getSigner(library: Web3Provider, account: string): JsonRpcSigner { return library.getSigner(account).connectUnchecked() } // account is optional -function getProviderOrSigner( - library: providers.Web3Provider, - account?: string -): providers.Web3Provider | providers.JsonRpcSigner { +function getProviderOrSigner(library: Web3Provider, account?: string): Web3Provider | JsonRpcSigner { return account ? getSigner(library, account) : library } // account is optional -export function getContract(address: string, ABI: any, library: providers.Web3Provider, account?: string): Contract { - if (!isAddress(address) || address === constants.AddressZero) { +export function getContract(address: string, ABI: any, library: Web3Provider, account?: string): Contract { + if (!isAddress(address) || address === AddressZero) { throw Error(`Invalid 'address' parameter '${address}'.`) } diff --git a/src/utils/safeNamehash.test.ts b/src/utils/safeNamehash.test.ts index f28683e27f..babcd089cf 100644 --- a/src/utils/safeNamehash.test.ts +++ b/src/utils/safeNamehash.test.ts @@ -1,4 +1,4 @@ -import { namehash } from 'ethers/lib/utils' +import { namehash } from '@ethersproject/hash' import { safeNamehash } from './safeNamehash' diff --git a/src/utils/safeNamehash.ts b/src/utils/safeNamehash.ts index b4907a452b..0dc17076a5 100644 --- a/src/utils/safeNamehash.ts +++ b/src/utils/safeNamehash.ts @@ -1,4 +1,4 @@ -import { namehash } from 'ethers/lib/utils' +import { namehash } from '@ethersproject/hash' 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 ba9968a158..c411b10155 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: providers.Web3Provider + library: Web3Provider chainId: SupportedChainId } diff --git a/yarn.lock b/yarn.lock index d7ae4d0ccd..b2cfc76c35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1481,7 +1481,7 @@ "@ethersproject/properties" "^5.4.0" "@ethersproject/strings" "^5.4.0" -"@ethersproject/abi@^5.0.12", "@ethersproject/abi@^5.4.0", "@ethersproject/abi@^5.5.0": +"@ethersproject/abi@^5.0.12", "@ethersproject/abi@^5.4.0", "@ethersproject/abi@^5.4.1", "@ethersproject/abi@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.5.0.tgz#fb52820e22e50b854ff15ce1647cc508d6660613" integrity sha512-loW7I4AohP5KycATvc0MgujU6JyCHPqHdeoo9z3Nr9xEiNioxa65ccdm1+fsoJhkuhdRtfcL8cfyGamz2AxZ5w== @@ -1509,7 +1509,7 @@ "@ethersproject/transactions" "^5.4.0" "@ethersproject/web" "^5.4.0" -"@ethersproject/abstract-provider@^5.4.0", "@ethersproject/abstract-provider@^5.5.0": +"@ethersproject/abstract-provider@^5.4.0", "@ethersproject/abstract-provider@^5.4.1", "@ethersproject/abstract-provider@^5.5.0": version "5.5.1" resolved "https://registry.yarnpkg.com/@ethersproject/abstract-provider/-/abstract-provider-5.5.1.tgz#2f1f6e8a3ab7d378d8ad0b5718460f85649710c5" integrity sha512-m+MA/ful6eKbxpr99xUYeRvLkfnlqzrF8SZ46d/xFB1A7ZVknYc/sXJG0RcufF52Qn2jeFj1hhcoQ7IXjNKUqg== @@ -1605,7 +1605,7 @@ "@ethersproject/logger" "^5.4.0" bn.js "^4.11.9" -"@ethersproject/bignumber@^5.1.1", "@ethersproject/bignumber@^5.4.0", "@ethersproject/bignumber@^5.5.0": +"@ethersproject/bignumber@^5.1.1", "@ethersproject/bignumber@^5.4.0", "@ethersproject/bignumber@^5.4.2", "@ethersproject/bignumber@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/bignumber/-/bignumber-5.5.0.tgz#875b143f04a216f4f8b96245bde942d42d279527" integrity sha512-6Xytlwvy6Rn3U3gKEc1vP7nR92frHkv6wtVr95LFR3jREXiCPzdWxKQ1cx4JGQBXxcguAwjA8murlYN2TSiEbg== @@ -1642,7 +1642,7 @@ dependencies: "@ethersproject/bignumber" "^5.5.0" -"@ethersproject/contracts@5.4.1": +"@ethersproject/contracts@5.4.1", "@ethersproject/contracts@^5.4.1": version "5.4.1" resolved "https://registry.yarnpkg.com/@ethersproject/contracts/-/contracts-5.4.1.tgz#3eb4f35b7fe60a962a75804ada2746494df3e470" integrity sha512-m+z2ZgPy4pyR15Je//dUaymRUZq5MtDajF6GwFbGAVmKz/RF+DNIPwF0k5qEcL3wPGVqUjFg2/krlCRVTU4T5w== @@ -1918,7 +1918,7 @@ elliptic "6.5.4" hash.js "1.1.7" -"@ethersproject/solidity@5.4.0", "@ethersproject/solidity@^5.0.0", "@ethersproject/solidity@^5.0.9": +"@ethersproject/solidity@5.4.0", "@ethersproject/solidity@^5.4.0": version "5.4.0" resolved "https://registry.yarnpkg.com/@ethersproject/solidity/-/solidity-5.4.0.tgz#1305e058ea02dc4891df18b33232b11a14ece9ec" integrity sha512-XFQTZ7wFSHOhHcV1DpcWj7VXECEiSrBuv7JErJvB9Uo+KfCdc3QtUZV+Vjh/AAaYgezUEKbCtE6Khjm44seevQ== @@ -1929,6 +1929,18 @@ "@ethersproject/sha2" "^5.4.0" "@ethersproject/strings" "^5.4.0" +"@ethersproject/solidity@^5.0.0", "@ethersproject/solidity@^5.0.9": + version "5.5.0" + resolved "https://registry.yarnpkg.com/@ethersproject/solidity/-/solidity-5.5.0.tgz#2662eb3e5da471b85a20531e420054278362f93f" + integrity sha512-9NgZs9LhGMj6aCtHXhtmFQ4AN4sth5HuFXVvAQtzmm0jpSCNOTGtrHZJAeYTh7MBjRR8brylWZxBZR9zDStXbw== + dependencies: + "@ethersproject/bignumber" "^5.5.0" + "@ethersproject/bytes" "^5.5.0" + "@ethersproject/keccak256" "^5.5.0" + "@ethersproject/logger" "^5.5.0" + "@ethersproject/sha2" "^5.5.0" + "@ethersproject/strings" "^5.5.0" + "@ethersproject/strings@5.4.0": version "5.4.0" resolved "https://registry.yarnpkg.com/@ethersproject/strings/-/strings-5.4.0.tgz#fb12270132dd84b02906a8d895ae7e7fa3d07d9a" @@ -1977,7 +1989,7 @@ "@ethersproject/rlp" "^5.5.0" "@ethersproject/signing-key" "^5.5.0" -"@ethersproject/units@5.4.0": +"@ethersproject/units@5.4.0", "@ethersproject/units@^5.4.0": version "5.4.0" resolved "https://registry.yarnpkg.com/@ethersproject/units/-/units-5.4.0.tgz#d57477a4498b14b88b10396062c8cbbaf20c79fe" integrity sha512-Z88krX40KCp+JqPCP5oPv5p750g+uU6gopDYRTBGcDvOASh6qhiEYCRatuM/suC4S2XW9Zz90QI35MfSrTIaFg== @@ -1986,7 +1998,7 @@ "@ethersproject/constants" "^5.4.0" "@ethersproject/logger" "^5.4.0" -"@ethersproject/wallet@5.4.0": +"@ethersproject/wallet@5.4.0", "@ethersproject/wallet@^5.4.0": version "5.4.0" resolved "https://registry.yarnpkg.com/@ethersproject/wallet/-/wallet-5.4.0.tgz#fa5b59830b42e9be56eadd45a16a2e0933ad9353" integrity sha512-wU29majLjM6AjCjpat21mPPviG+EpK7wY1+jzKD0fg3ui5fgedf2zEu1RDgpfIMsfn8fJHJuzM4zXZ2+hSHaSQ== @@ -4974,18 +4986,7 @@ resolved "https://registry.yarnpkg.com/@uniswap/redux-multicall/-/redux-multicall-1.0.0.tgz#0cee4448909a788ea4700e5ede75ffeba05b5d75" integrity sha512-zR6tNC3XF6JuI6PjGlZW2Hz7tTzRzzVaPJfZ01BBWBJVt/2ixJY0SH514uffD03NHYiXZA//hlPQLfw3TkIxQg== -"@uniswap/router-sdk@^1.0.3": - version "1.0.3" - resolved "https://registry.yarnpkg.com/@uniswap/router-sdk/-/router-sdk-1.0.3.tgz#378a8cc96a3f17b5627b811e64bfcf1e0e50a551" - integrity sha512-9Nq0+J4+u5cPkZlLjCnV1IbbmPVVDxlwrIuYh/fPTVMH4DnPVVEcP68BArtkSUG0OSC87rWrkEHIZd+L8CO6sQ== - dependencies: - "@ethersproject/abi" "^5.5.0" - "@uniswap/sdk-core" "^3.0.1" - "@uniswap/swap-router-contracts" "1.1.0" - "@uniswap/v2-sdk" "^3.0.1" - "@uniswap/v3-sdk" "^3.7.1" - -"@uniswap/router-sdk@^1.0.5": +"@uniswap/router-sdk@^1.0.3", "@uniswap/router-sdk@^1.0.5": version "1.0.5" resolved "https://registry.yarnpkg.com/@uniswap/router-sdk/-/router-sdk-1.0.5.tgz#59b429327b0d202744db6de958e6b61d5adeec12" integrity sha512-PA/0Ye9u3U5cm/LHrJuOgVSff6W4oFY3h+MUEzdp80SYIQdZZJ+BV06RL0h5KOSH+tuIX72n/qNusuRcf2Tc8Q== @@ -10840,7 +10841,7 @@ ethereumjs-vm@^2.1.0, ethereumjs-vm@^2.3.4, ethereumjs-vm@^2.6.0: rustbn.js "~0.2.0" safe-buffer "^5.1.1" -ethers@^5.1.4, ethers@^5.4.0, ethers@^5.4.6: +ethers@^5.1.4, ethers@^5.4.0: version "5.4.7" resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.4.7.tgz#0fd491a5da7c9793de2d6058d76b41b1e7efba8f" integrity sha512-iZc5p2nqfWK1sj8RabwsPM28cr37Bpq7ehTQ5rWExBr2Y09Sn1lDKZOED26n+TsZMye7Y6mIgQ/1cwpSD8XZew==