diff --git a/packages/optimism-networks/package.json b/packages/optimism-networks/package.json index a810846ce..4e8f19e63 100644 --- a/packages/optimism-networks/package.json +++ b/packages/optimism-networks/package.json @@ -35,8 +35,9 @@ "url": "https://github.com/Synthetixio/js-monorepo/issues" }, "dependencies": { - "@metamask/providers": "^8.1.1", - "ethers": "^5.5.3" + "@ethersproject/bignumber": "^5.6.2", + "@ethersproject/bytes": "^5.6.1", + "@metamask/providers": "^8.1.1" }, "devDependencies": { "@babel/core": "^7.11.0", diff --git a/packages/optimism-networks/src/index.ts b/packages/optimism-networks/src/index.ts index 84f1c2dcd..0080175c5 100644 --- a/packages/optimism-networks/src/index.ts +++ b/packages/optimism-networks/src/index.ts @@ -1,5 +1,6 @@ import type { MetaMaskInpageProvider } from '@metamask/providers'; -import { ethers, BigNumber } from 'ethers'; +import { hexStripZeros } from '@ethersproject/bytes'; +import { BigNumber } from '@ethersproject/bignumber'; import { OPTIMISM_NETWORKS, @@ -42,7 +43,7 @@ const switchToL1 = async ({ ethereum }: { ethereum: MetaMaskInpageProvider }): P const networkId = L2_TO_L1_NETWORK_MAPPER[Number(ethereum.chainId)] || L2_TO_L1_NETWORK_MAPPER[DEFAULT_LAYER2_NETWORK]; - const formattedChainId = ethers.utils.hexStripZeros(BigNumber.from(networkId).toHexString()); + const formattedChainId = hexStripZeros(BigNumber.from(networkId).toHexString()); await ethereum.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: formattedChainId }], @@ -55,7 +56,7 @@ const switchToL2 = async ({ ethereum }: { ethereum: MetaMaskInpageProvider }): P L1_TO_L2_NETWORK_MAPPER[Number(ethereum.chainId)] || L1_TO_L2_NETWORK_MAPPER[DEFAULT_MAINNET_NETWORK]; - const formattedChainId = ethers.utils.hexStripZeros(BigNumber.from(networkId).toHexString()); + const formattedChainId = hexStripZeros(BigNumber.from(networkId).toHexString()); await ethereum.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: formattedChainId }], diff --git a/packages/providers/package.json b/packages/providers/package.json index 36b55da66..d59b8ee7a 100644 --- a/packages/providers/package.json +++ b/packages/providers/package.json @@ -35,10 +35,11 @@ "url": "https://github.com/Synthetixio/js-monorepo/issues" }, "dependencies": { + "@ethersproject/bignumber": "^5.6.2", + "@ethersproject/bytes": "^5.6.1", "@ethersproject/providers": "^5.6.8", "@synthetixio/contracts-interface": "workspace:*", - "@synthetixio/optimism-networks": "workspace:*", - "ethers": "^5.5.3" + "@synthetixio/optimism-networks": "workspace:*" }, "devDependencies": { "@babel/core": "^7.11.0", diff --git a/packages/providers/src/index.ts b/packages/providers/src/index.ts index e84006484..1b6c3f49a 100644 --- a/packages/providers/src/index.ts +++ b/packages/providers/src/index.ts @@ -1,4 +1,6 @@ -import { BigNumber, providers as ethersProviders, utils } from 'ethers'; +import { BigNumber } from '@ethersproject/bignumber'; +import { Web3Provider, InfuraProvider, StaticJsonRpcProvider } from '@ethersproject/providers'; +import { hexStripZeros } from '@ethersproject/bytes'; import { L1_TO_L2_NETWORK_MAPPER, L2_TO_L1_NETWORK_MAPPER, @@ -10,25 +12,21 @@ import { NetworkIdByName } from '@synthetixio/contracts-interface'; const loadProvider = ({ networkId = 1, infuraId, provider }: ProviderConfig): SynthetixProvider => { if (provider) { - return new ethersProviders.Web3Provider(provider); + return new Web3Provider(provider); } if (infuraId) { - return new ethersProviders.InfuraProvider(networkId, infuraId); + return new InfuraProvider(networkId, infuraId); } throw new Error(ERRORS.noWeb3Provider); }; -const getOptimismProvider = ({ - networkId, -}: { - networkId: number; -}): ethersProviders.StaticJsonRpcProvider => { +const getOptimismProvider = ({ networkId }: { networkId: number }): StaticJsonRpcProvider => { if (!networkId) throw new Error(ERRORS.noNetworkId); const ovmNetworkId = L1_TO_L2_NETWORK_MAPPER[networkId] || networkId; if (!OPTIMISM_NETWORKS[networkId]) throw new Error(ERRORS.wrongNetworkId); - return new ethersProviders.StaticJsonRpcProvider(OPTIMISM_NETWORKS[ovmNetworkId].rpcUrls[0]); + return new StaticJsonRpcProvider(OPTIMISM_NETWORKS[ovmNetworkId].rpcUrls[0]); }; /** @@ -36,13 +34,10 @@ const getOptimismProvider = ({ * @param web3Provider * @param isOVM */ -const handleSwitchChain = async ( - web3Provider: ethersProviders.Web3Provider, - isOVM: boolean -): Promise => { +const handleSwitchChain = async (web3Provider: Web3Provider, isOVM: boolean): Promise => { if (!web3Provider.provider?.request) return false; const newNetworkId = getCorrespondingNetwork(isOVM); - const formattedChainId = utils.hexStripZeros(BigNumber.from(newNetworkId).toHexString()); + const formattedChainId = hexStripZeros(BigNumber.from(newNetworkId).toHexString()); const success = await web3Provider.provider.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: formattedChainId }], diff --git a/packages/queries/__tests__/debt.test.ts b/packages/queries/__tests__/debt.test.ts index aa7d6f6f2..f463a568e 100644 --- a/packages/queries/__tests__/debt.test.ts +++ b/packages/queries/__tests__/debt.test.ts @@ -2,20 +2,16 @@ import { getFakeQueryContext, getWrapper } from '../testUtils'; import { renderHook } from '@testing-library/react-hooks'; import useGetDebtL2 from '../src/queries/debt/useGetDebtL2'; import { useGetDebtL1 } from '../generated/queryFuncs'; -import { providers } from 'ethers'; - +import { getDefaultProvider } from '@ethersproject/providers'; jest.setTimeout(20000); describe('@synthetixio/queries debt', () => { it.skip('useGetDebtL2', async () => { const ctx = getFakeQueryContext(); const wrapper = getWrapper(); - const { result, waitFor } = renderHook( - () => useGetDebtL2(ctx, providers.getDefaultProvider()), - { - wrapper, - } - ); + const { result, waitFor } = renderHook(() => useGetDebtL2(ctx, getDefaultProvider()), { + wrapper, + }); await waitFor(() => !!result.current.data?.length, { timeout: 20000 }); // uncomment for current state of debt on L2 /* result.current.data?.forEach((synth) => @@ -27,12 +23,9 @@ describe('@synthetixio/queries debt', () => { it.skip('useGetDebtL1', async () => { const ctx = getFakeQueryContext(); const wrapper = getWrapper(); - const { result, waitFor } = renderHook( - () => useGetDebtL1(ctx, providers.getDefaultProvider()), - { - wrapper, - } - ); + const { result, waitFor } = renderHook(() => useGetDebtL1(ctx, getDefaultProvider()), { + wrapper, + }); await waitFor(() => !!result.current.data?.length, { timeout: 20000 }); // uncomment for current state of debt on L1 diff --git a/packages/queries/__tests__/network.test.ts b/packages/queries/__tests__/network.test.ts index ba36f391f..135116926 100644 --- a/packages/queries/__tests__/network.test.ts +++ b/packages/queries/__tests__/network.test.ts @@ -1,7 +1,8 @@ import { NetworkIdByName } from '@synthetixio/contracts-interface'; import { wei } from '@synthetixio/wei'; import { renderHook } from '@testing-library/react-hooks'; -import { ethers, BigNumber } from 'ethers'; +import { BigNumber } from '@ethersproject/bignumber'; +import { JsonRpcProvider } from '@ethersproject/providers'; import { set } from 'lodash'; import useEthGasPriceQuery, { computeGasFee } from '../src/queries/network/useEthGasPriceQuery'; import { getFakeQueryContext, getWrapper } from '../testUtils'; @@ -14,7 +15,7 @@ describe('@synthetixio/queries network useEthGasPriceQuery', () => { // set to 0.015 gwei const defaultGasPrice = wei(0.015, 9).toBN(); //mock provider - set(ctx.provider as ethers.providers.JsonRpcProvider, 'getGasPrice', async () => + set(ctx.provider as JsonRpcProvider, 'getGasPrice', async () => Promise.resolve(defaultGasPrice) ); @@ -36,7 +37,7 @@ describe('@synthetixio/queries network useEthGasPriceQuery', () => { // set to 0.015 gwei const defaultGasPrice = wei(0.015, 9).toBN(); //mock provider - set(ctx.provider as ethers.providers.JsonRpcProvider, 'getGasPrice', async () => + set(ctx.provider as JsonRpcProvider, 'getGasPrice', async () => Promise.resolve(defaultGasPrice) ); @@ -87,7 +88,7 @@ describe('@synthetixio/queries network useEthGasPriceQuery', () => { // set to 100 gwei const defaultBaseFeePerGas = wei(100, 9).toBN(); //mock provider - set(ctx.provider as ethers.providers.JsonRpcProvider, 'getBlock', async () => + set(ctx.provider as JsonRpcProvider, 'getBlock', async () => Promise.resolve({ baseFeePerGas: defaultBaseFeePerGas }) ); diff --git a/packages/queries/__tests__/rates.test.ts b/packages/queries/__tests__/rates.test.ts index 5367156a4..49b475f6c 100644 --- a/packages/queries/__tests__/rates.test.ts +++ b/packages/queries/__tests__/rates.test.ts @@ -5,7 +5,7 @@ import { renderHook } from '@testing-library/react-hooks'; import { set } from 'lodash'; import { wei } from '@synthetixio/wei'; -import { ethers } from 'ethers'; +import { formatBytes32String } from '@ethersproject/strings'; describe('@synthetixio/queries rates', () => { const ctx = getFakeQueryContext(); @@ -14,7 +14,7 @@ describe('@synthetixio/queries rates', () => { const wrapper = getWrapper(); set(ctx.snxjs as any, 'contracts.SynthUtil.synthsRates', async () => [ - [ethers.utils.formatBytes32String('sETH'), ethers.utils.formatBytes32String('sBTC')], + [formatBytes32String('sETH'), formatBytes32String('sBTC')], [wei(1000).toBN(), wei(10000).toBN()], ]); set(ctx.snxjs as any, 'contracts.ExchangeRates.ratesForCurrencies', async () => [ diff --git a/packages/queries/__tests__/walletBalances.test.ts b/packages/queries/__tests__/walletBalances.test.ts index 43567f864..7dc615fbe 100644 --- a/packages/queries/__tests__/walletBalances.test.ts +++ b/packages/queries/__tests__/walletBalances.test.ts @@ -1,6 +1,7 @@ import { wei } from '@synthetixio/wei'; import { renderHook } from '@testing-library/react-hooks'; -import { ethers } from 'ethers'; +import { formatBytes32String } from '@ethersproject/strings'; +import { AddressZero } from '@ethersproject/constants'; import { set } from 'lodash'; import useSynthsBalancesQuery from '../src/queries/walletBalances/useSynthsBalancesQuery'; import { getFakeQueryContext, getWrapper } from '../testUtils'; @@ -15,15 +16,14 @@ describe('@synthetixio/queries walletBalances', () => { const fakeETHValue = wei(1000); set(ctx.snxjs as any, 'contracts.SynthUtil.synthsBalances', async () => [ - ['sUSD', 'sETH', 'sBTC'].map(ethers.utils.formatBytes32String), + ['sUSD', 'sETH', 'sBTC'].map(formatBytes32String), [wei(100), wei(1), wei(0.2)].map((v) => v.toBN()), [wei(100), wei(1).mul(fakeETHValue), wei(0.2).mul(fakeBTCValue)].map((v) => v.toBN()), ]); - const { result, waitFor } = renderHook( - () => useSynthsBalancesQuery(ctx, ethers.constants.AddressZero), - { wrapper } - ); + const { result, waitFor } = renderHook(() => useSynthsBalancesQuery(ctx, AddressZero), { + wrapper, + }); await waitFor(() => result.current.isSuccess); expect(result.current.data).toEqual({ diff --git a/packages/queries/package.json b/packages/queries/package.json index 49261e2d5..56cb7ebb7 100644 --- a/packages/queries/package.json +++ b/packages/queries/package.json @@ -36,14 +36,22 @@ "url": "https://github.com/Synthetixio/js-monorepo/issues" }, "dependencies": { - "@snapshot-labs/snapshot.js": "^0.3.22", + "@ethersproject/abstract-signer": "^5.6.2", + "@ethersproject/address": "^5.6.1", + "@ethersproject/bignumber": "^5.6.2", + "@ethersproject/constants": "^5.6.1", + "@ethersproject/contracts": "^5.6.2", + "@ethersproject/providers": "^5.6.8", + "@ethersproject/strings": "^5.6.1", + "@ethersproject/transactions": "^5.6.2", + "@ethersproject/units": "^5.6.1", + "@snapshot-labs/snapshot.js": "^0.4.13", "@synthetixio/codegen-graph-ts": "workspace:*", "@synthetixio/contracts-interface": "workspace:*", "@synthetixio/optimism-networks": "workspace:*", "@synthetixio/wei": "workspace:*", "axios": "^0.21.4", "date-fns": "^2.19.0", - "ethers": "^5.5.3", "graphql": "^15.5.0", "graphql-request": "^3.4.0", "lodash": "^4.17.21" diff --git a/packages/queries/src/context.ts b/packages/queries/src/context.ts index 6d0885218..b064a42a1 100644 --- a/packages/queries/src/context.ts +++ b/packages/queries/src/context.ts @@ -1,4 +1,5 @@ -import { ethers } from 'ethers'; +import { Signer } from '@ethersproject/abstract-signer'; +import { Provider } from '@ethersproject/providers'; import { SynthetixJS, NetworkId } from '@synthetixio/contracts-interface'; export interface SubgraphEndpoints { @@ -10,8 +11,8 @@ export interface SubgraphEndpoints { export interface QueryContext { networkId: NetworkId | null; - provider: ethers.providers.Provider | null; - signer: ethers.Signer | null; + provider: Provider | null; + signer: Signer | null; snxjs: SynthetixJS | null; subgraphEndpoints: SubgraphEndpoints; } diff --git a/packages/queries/src/index.ts b/packages/queries/src/index.ts index 8717cedec..f3003c38d 100644 --- a/packages/queries/src/index.ts +++ b/packages/queries/src/index.ts @@ -1,7 +1,8 @@ import clone from 'lodash/clone'; import partial from 'lodash/partial'; -import ethers from 'ethers'; +import { Signer } from '@ethersproject/abstract-signer'; +import { Provider } from '@ethersproject/providers'; import { QueryContext, SubgraphEndpoints } from './context'; import { synthetix, NetworkId } from '@synthetixio/contracts-interface'; @@ -14,7 +15,7 @@ import * as issuance from '../generated/issuanceSubgraphQueries'; import * as subgraph from '../generated/mainSubgraphQueries'; import * as FUNCS from '../generated/queryFuncs'; -import React from 'react'; +import { createContext, useContext } from 'react'; import { DEFAULT_SUBGRAPH_ENDPOINTS } from './constants'; @@ -66,8 +67,8 @@ export function createQueryContext({ subgraphEndpoints, }: { networkId: NetworkId | null; - provider?: ethers.providers.Provider; - signer?: ethers.Signer; + provider?: Provider; + signer?: Signer; subgraphEndpoints?: SubgraphEndpoints; }): SynthetixQueryContextContent { const ctx: QueryContext = { @@ -133,11 +134,11 @@ export function createQueryContext({ return { context: ctx, queries: allFuncs }; } -export const SynthetixQueryContext = React.createContext(null); +export const SynthetixQueryContext = createContext(null); export const SynthetixQueryContextProvider = SynthetixQueryContext.Provider; export default function useSynthetixQueries(): SynthetixQueries { - const ctx = React.useContext(SynthetixQueryContext); + const ctx = useContext(SynthetixQueryContext); if (!ctx) { throw new Error('No QueryClient set, use QueryClientProvider to set one'); } diff --git a/packages/queries/src/mutations/useContractTxn.ts b/packages/queries/src/mutations/useContractTxn.ts index ad3e9dda1..827ed1b3a 100644 --- a/packages/queries/src/mutations/useContractTxn.ts +++ b/packages/queries/src/mutations/useContractTxn.ts @@ -1,14 +1,16 @@ -import { ethers } from 'ethers'; +import { BigNumber } from '@ethersproject/bignumber'; +import { TransactionRequest } from '@ethersproject/providers'; +import { Contract } from '@ethersproject/contracts'; import { QueryContext } from '../context'; import useEVMTxn, { UseEVMTxnOptions } from './useEVMTxn'; const useContractTxn = ( ctx: QueryContext, - contract: ethers.Contract | null, + contract: Contract | null, method: string | null, args: any[] = [], - txnOptions: Partial = {}, + txnOptions: Partial = {}, options?: UseEVMTxnOptions ) => { const hasSigner = Boolean(ctx.signer); @@ -18,7 +20,7 @@ const useContractTxn = ( { to: contract.address, data: contract.interface.encodeFunctionData(method, args), - value: txnOptions.value || ethers.BigNumber.from(0), + value: txnOptions.value || BigNumber.from(0), ...txnOptions, }, options diff --git a/packages/queries/src/mutations/useEVMTxn.test.ts b/packages/queries/src/mutations/useEVMTxn.test.ts index 9ffe6098c..4136a1b36 100644 --- a/packages/queries/src/mutations/useEVMTxn.test.ts +++ b/packages/queries/src/mutations/useEVMTxn.test.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { renderHook } from '@testing-library/react-hooks'; -import { BigNumber } from 'ethers'; +import { BigNumber } from '@ethersproject/bignumber'; import { getWrapper } from '../../testUtils'; import useEVMTxn from './useEVMTxn'; diff --git a/packages/queries/src/mutations/useEVMTxn.ts b/packages/queries/src/mutations/useEVMTxn.ts index e0ab06b8b..436999f67 100644 --- a/packages/queries/src/mutations/useEVMTxn.ts +++ b/packages/queries/src/mutations/useEVMTxn.ts @@ -1,9 +1,12 @@ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { useEffect, useState } from 'react'; import { UseMutationOptions, useMutation } from 'react-query'; import Wei, { wei } from '@synthetixio/wei/build/node/wei'; -import { ethers } from 'ethers'; -import { useEffect, useState } from 'react'; +import { BigNumber } from '@ethersproject/bignumber'; +import { TransactionRequest } from '@ethersproject/providers'; +import { Contract } from '@ethersproject/contracts'; +import { serialize, UnsignedTransaction } from '@ethersproject/transactions'; + import { QueryContext } from '../context'; import clone from 'lodash/clone'; import omit from 'lodash/omit'; @@ -23,10 +26,10 @@ export interface UseEVMTxnOptions extends UseMutationOptions { const useEVMTxn = ( ctx: QueryContext, - txn: ethers.providers.TransactionRequest | null, + txn: TransactionRequest | null, options?: UseEVMTxnOptions ) => { - const [gasLimit, setGasLimit] = useState(null); + const [gasLimit, setGasLimit] = useState(null); const [optimismLayerOneFee, setOptimismLayerOneFee] = useState(null); const [errorMessage, setErrorMessage] = useState(null); const [hash, setHash] = useState(null); @@ -41,16 +44,14 @@ const useEVMTxn = ( return null; } - const OptimismGasPriceOracleContract = new ethers.Contract( + const OptimismGasPriceOracleContract = new Contract( optimismOracleContract.address, optimismOracleContract.abi, ctx.provider ); // If user initialized the transaction on mainnet and then switched to optimism we need to manually remove EIP1559 fields const cleanedTxn = omit(txn, ['maxPriorityFeePerGas', 'maxFeePerGas']); - const serializedTxn = ethers.utils.serializeTransaction( - cleanedTxn as ethers.UnsignedTransaction - ); + const serializedTxn = serialize(cleanedTxn as UnsignedTransaction); return wei(await OptimismGasPriceOracleContract.getL1Fee(serializedTxn)); }; diff --git a/packages/queries/src/mutations/useSynthetixTxn.ts b/packages/queries/src/mutations/useSynthetixTxn.ts index 6a238309b..9e9ec341f 100644 --- a/packages/queries/src/mutations/useSynthetixTxn.ts +++ b/packages/queries/src/mutations/useSynthetixTxn.ts @@ -1,5 +1,4 @@ -import { ethers } from 'ethers'; - +import { TransactionRequest } from '@ethersproject/providers'; import { QueryContext } from '../context'; import useContractTxn from './useContractTxn'; import useEVMTxn, { UseEVMTxnOptions } from './useEVMTxn'; @@ -9,7 +8,7 @@ const useSynthetixTxn = ( contract: string, method: string, args: any[] = [], - txnOptions: Partial = {}, + txnOptions: Partial = {}, options?: UseEVMTxnOptions ) => { if (ctx.snxjs != null) { diff --git a/packages/queries/src/queries/debt/useGetDebtL1.ts b/packages/queries/src/queries/debt/useGetDebtL1.ts index 85abcbf2c..1af212915 100644 --- a/packages/queries/src/queries/debt/useGetDebtL1.ts +++ b/packages/queries/src/queries/debt/useGetDebtL1.ts @@ -1,7 +1,11 @@ +import { useEffect, useState } from 'react'; import { useQuery, UseQueryOptions } from 'react-query'; import Wei, { wei } from '@synthetixio/wei'; import { QueryContext } from '../../context'; -import { BigNumber, providers, utils } from 'ethers'; +import { BaseProvider } from '@ethersproject/providers'; +import { BigNumber } from '@ethersproject/bignumber'; +import { parseBytes32String } from '@ethersproject/strings'; + import { useGetLoans, useGetShorts, @@ -9,14 +13,12 @@ import { useGetWrappers, } from '../../../generated/mainSubgraphQueries'; import { DEFAULT_SUBGRAPH_ENDPOINTS } from '../../constants'; -import { useEffect, useState } from 'react'; import { Debt, DebtData } from './useGetDebtL2'; -import synthetix from '@synthetixio/contracts-interface'; -import { NetworkIdByName } from '@synthetixio/contracts-interface'; +import synthetix, { NetworkIdByName } from '@synthetixio/contracts-interface'; const useGetDebtL1 = ( _: QueryContext, - L1Provider: providers.BaseProvider, + L1Provider: BaseProvider, options?: UseQueryOptions ) => { const [debtData, setDebtData] = useState(null); @@ -123,8 +125,8 @@ const useGetDebtL1 = ( } return { ...short, - synthBorrowed: utils.parseBytes32String(short.synthBorrowed), - collateralLocked: utils.parseBytes32String(short.collateralLocked), + synthBorrowed: parseBytes32String(short.synthBorrowed), + collateralLocked: parseBytes32String(short.collateralLocked), }; }) .reduce((acc, short) => { diff --git a/packages/queries/src/queries/debt/useGetDebtL2.ts b/packages/queries/src/queries/debt/useGetDebtL2.ts index 362233a64..688a3c1ee 100644 --- a/packages/queries/src/queries/debt/useGetDebtL2.ts +++ b/packages/queries/src/queries/debt/useGetDebtL2.ts @@ -1,7 +1,9 @@ import { useQuery, UseQueryOptions } from 'react-query'; import Wei, { wei } from '@synthetixio/wei'; import { QueryContext } from '../../context'; -import { BigNumber, providers, utils } from 'ethers'; +import { BaseProvider } from '@ethersproject/providers'; +import { BigNumber } from '@ethersproject/bignumber'; +import { parseBytes32String } from '@ethersproject/strings'; import { useGetLoans, useGetShorts, @@ -30,7 +32,7 @@ export interface DebtData { const useGetDebtL2 = ( _: QueryContext, - L2Provider: providers.BaseProvider, + L2Provider: BaseProvider, options?: UseQueryOptions ) => { const [debtData, setDebtData] = useState(null); @@ -116,8 +118,8 @@ const useGetDebtL2 = ( } return { ...short, - synthBorrowed: utils.parseBytes32String(short.synthBorrowed), - collateralLocked: utils.parseBytes32String(short.collateralLocked), + synthBorrowed: parseBytes32String(short.synthBorrowed), + collateralLocked: parseBytes32String(short.collateralLocked), }; }) .reduce((acc, short) => { diff --git a/packages/queries/src/queries/escrow/useEscrowDataQuery.ts b/packages/queries/src/queries/escrow/useEscrowDataQuery.ts index c7b3591ef..914fb97eb 100644 --- a/packages/queries/src/queries/escrow/useEscrowDataQuery.ts +++ b/packages/queries/src/queries/escrow/useEscrowDataQuery.ts @@ -2,7 +2,7 @@ import { useQuery, UseQueryOptions } from 'react-query'; import chunk from 'lodash/chunk'; import orderBy from 'lodash/orderBy'; import flatten from 'lodash/flatten'; -import { ethers } from 'ethers'; +import { BigNumber } from '@ethersproject/bignumber'; import { QueryContext } from '../../context'; import Wei, { wei } from '@synthetixio/wei'; import { OPTIMISM_NETWORKS } from '@synthetixio/optimism-networks'; @@ -34,7 +34,7 @@ const useEscrowDataQuery = ( RewardEscrowV2.balanceOf(walletAddress), RewardEscrowV2.totalVestedAccountBalance(walletAddress), OPTIMISM_NETWORKS[ctx.networkId!] != null - ? ethers.BigNumber.from(0) + ? BigNumber.from(0) : RewardEscrowV2.totalBalancePendingMigration(walletAddress), ]); diff --git a/packages/queries/src/queries/gov/useGetElectionsPeriodStatus.ts b/packages/queries/src/queries/gov/useGetElectionsPeriodStatus.ts index 1a601d56a..f607abb0a 100644 --- a/packages/queries/src/queries/gov/useGetElectionsPeriodStatus.ts +++ b/packages/queries/src/queries/gov/useGetElectionsPeriodStatus.ts @@ -1,4 +1,6 @@ -import { BigNumber, Contract, providers } from 'ethers'; +import { BaseProvider } from '@ethersproject/providers'; +import { BigNumber } from '@ethersproject/bignumber'; +import { Contract } from '@ethersproject/contracts'; import { useQuery, UseQueryOptions } from 'react-query'; import { isObjKey } from '../../utils'; import { QueryContext } from '../../context'; @@ -6,7 +8,7 @@ import { COUNCIL_CONTRACTS_V3, ELECTION_MODULE_PERIODS } from './constants'; const useGetElectionsPeriodStatus = ( _ctx: QueryContext, - optimismProvider: providers.BaseProvider, + optimismProvider: BaseProvider, options?: UseQueryOptions<{ currentPeriodLabel: string; code: number }[]> ) => { return useQuery( diff --git a/packages/queries/src/queries/gov/useGetSpartanCouncil.ts b/packages/queries/src/queries/gov/useGetSpartanCouncil.ts index 6f01d11a5..0284bc620 100644 --- a/packages/queries/src/queries/gov/useGetSpartanCouncil.ts +++ b/packages/queries/src/queries/gov/useGetSpartanCouncil.ts @@ -1,5 +1,6 @@ import axios from 'axios'; -import { Contract, providers } from 'ethers'; +import { Contract } from '@ethersproject/contracts'; +import { BaseProvider } from '@ethersproject/providers'; import { useQuery, UseQueryOptions } from 'react-query'; import { QueryContext } from '../../context'; import { Spartan } from '../../contracts'; @@ -38,7 +39,7 @@ const getUsersDetails = async (walletAddresses: string[]) => { const useGetSpartanCouncil = ( _ctx: QueryContext, - optimismProvider?: providers.BaseProvider, + optimismProvider?: BaseProvider, options?: UseQueryOptions ) => { return useQuery( diff --git a/packages/queries/src/queries/gov/useHasVotedForElectionsQuery.ts b/packages/queries/src/queries/gov/useHasVotedForElectionsQuery.ts index a4d359df5..8fc99877a 100644 --- a/packages/queries/src/queries/gov/useHasVotedForElectionsQuery.ts +++ b/packages/queries/src/queries/gov/useHasVotedForElectionsQuery.ts @@ -3,7 +3,7 @@ import snapshot from '@snapshot-labs/snapshot.js'; import request, { gql } from 'graphql-request'; import { Proposal, SpaceStrategy, Vote } from '../../types'; -import { getAddress } from 'ethers/lib/utils'; +import { getAddress } from '@ethersproject/address'; import { electionAuthor, SPACE_KEY } from './constants'; import { QueryContext } from '../../context'; diff --git a/packages/queries/src/queries/gov/useProposalQuery.ts b/packages/queries/src/queries/gov/useProposalQuery.ts index 5387c390e..26efd05b2 100644 --- a/packages/queries/src/queries/gov/useProposalQuery.ts +++ b/packages/queries/src/queries/gov/useProposalQuery.ts @@ -1,7 +1,7 @@ import { useQuery, UseQueryOptions } from 'react-query'; import snapshot from '@snapshot-labs/snapshot.js'; -import { ethers } from 'ethers'; +import { getAddress } from '@ethersproject/address'; import { uniqBy } from 'lodash'; import { Vote, SpaceStrategy, Proposal, ProposalResults } from '../../types'; import request, { gql } from 'graphql-request'; @@ -19,8 +19,6 @@ const useProposalQuery = ( return useQuery( ['gov', 'proposal', snapshotEndpoint, spaceKey, hash, walletAddress], async () => { - const { getAddress } = ethers.utils; - const { proposal }: { proposal: Proposal } = await request( snapshotEndpoint, gql` @@ -99,7 +97,7 @@ const useProposalQuery = ( // { proposal: proposal.id } // ); - const voterAddresses = votes.map((e: Vote) => ethers.utils.getAddress(e.voter)); + const voterAddresses = votes.map((e: Vote) => getAddress(e.voter)); interface MappedVotes extends Vote { scores: number[]; diff --git a/packages/queries/src/queries/gov/useProposalsQuery.ts b/packages/queries/src/queries/gov/useProposalsQuery.ts index b7201ab0c..777d66b00 100644 --- a/packages/queries/src/queries/gov/useProposalsQuery.ts +++ b/packages/queries/src/queries/gov/useProposalsQuery.ts @@ -1,6 +1,6 @@ import { useQuery, UseQueryOptions } from 'react-query'; -import { ethers } from 'ethers'; +import { Contract } from '@ethersproject/contracts'; import request, { gql } from 'graphql-request'; import { councilNominationsJson, SPACE_KEY } from './constants'; import { Proposal } from '../../types'; @@ -14,11 +14,7 @@ const useProposalsQuery = ( spaceKey: SPACE_KEY, options?: UseQueryOptions ) => { - const contract = new ethers.Contract( - CouncilDilution.address, - CouncilDilution.abi, - getOVMProvider() - ); + const contract = new Contract(CouncilDilution.address, CouncilDilution.abi, getOVMProvider()); return useQuery( ['gov', 'proposals', snapshotEndpoint, spaceKey], async () => { diff --git a/packages/queries/src/queries/gov/useVotingWeightQuery.ts b/packages/queries/src/queries/gov/useVotingWeightQuery.ts index 9f3b61d3f..a5bc0ca23 100644 --- a/packages/queries/src/queries/gov/useVotingWeightQuery.ts +++ b/packages/queries/src/queries/gov/useVotingWeightQuery.ts @@ -1,7 +1,7 @@ import { useQuery, UseQueryOptions } from 'react-query'; import snapshot from '@snapshot-labs/snapshot.js'; -import { ethers } from 'ethers'; +import { getAddress } from '@ethersproject/address'; import request, { gql } from 'graphql-request'; import { electionAuthor, SPACE_KEY } from './constants'; import { Proposal, SpaceStrategy, Vote } from '../../types'; @@ -17,8 +17,6 @@ const useVotingWeightQuery = ( return useQuery( ['gov', 'votingWeight', snapshotEndpoint, spaceKey, walletAddress], async () => { - const { getAddress } = ethers.utils; - const { proposals }: { proposals: Proposal[] } = await request( snapshotEndpoint, gql` diff --git a/packages/queries/src/queries/gov/utils.ts b/packages/queries/src/queries/gov/utils.ts index f1f5a1a17..abccb8f09 100644 --- a/packages/queries/src/queries/gov/utils.ts +++ b/packages/queries/src/queries/gov/utils.ts @@ -1,8 +1,4 @@ -import { ethers } from 'ethers'; - -const { - providers: { JsonRpcProvider }, -} = ethers; +import { JsonRpcProvider } from '@ethersproject/providers'; export const getOVMProvider = () => { return new JsonRpcProvider('https://mainnet.optimism.io'); diff --git a/packages/queries/src/queries/network/useEthGasPriceQuery.ts b/packages/queries/src/queries/network/useEthGasPriceQuery.ts index 7a7462e46..bd862771f 100644 --- a/packages/queries/src/queries/network/useEthGasPriceQuery.ts +++ b/packages/queries/src/queries/network/useEthGasPriceQuery.ts @@ -4,11 +4,12 @@ import { GasPrices } from '../../types'; import { wei } from '@synthetixio/wei'; import { NetworkIdByName } from '@synthetixio/contracts-interface'; -import { ethers } from 'ethers'; +import { BigNumber } from '@ethersproject/bignumber'; +import { Provider } from '@ethersproject/providers'; const MULTIPLIER = wei(2); -export const computeGasFee = (baseFeePerGas: ethers.BigNumber, maxPriorityFeePerGas: number) => { +export const computeGasFee = (baseFeePerGas: BigNumber, maxPriorityFeePerGas: number) => { return { maxPriorityFeePerGas: wei(maxPriorityFeePerGas, 9).toBN(), maxFeePerGas: wei(baseFeePerGas, 9).mul(MULTIPLIER).add(wei(maxPriorityFeePerGas, 9)).toBN(), @@ -16,7 +17,7 @@ export const computeGasFee = (baseFeePerGas: ethers.BigNumber, maxPriorityFeePer }; }; -const getGasPriceFromProvider = async (provider: ethers.providers.Provider) => { +const getGasPriceFromProvider = async (provider: Provider) => { try { const gasPrice = await provider.getGasPrice(); return { diff --git a/packages/queries/src/queries/rates/useExchangeRatesQuery.ts b/packages/queries/src/queries/rates/useExchangeRatesQuery.ts index ebe9b3467..2aaa49a29 100644 --- a/packages/queries/src/queries/rates/useExchangeRatesQuery.ts +++ b/packages/queries/src/queries/rates/useExchangeRatesQuery.ts @@ -1,5 +1,7 @@ import { useQuery, UseQueryOptions } from 'react-query'; -import { BigNumberish, ethers } from 'ethers'; +import { BigNumberish } from '@ethersproject/bignumber'; +import { formatBytes32String, parseBytes32String } from '@ethersproject/strings'; +import { formatEther } from '@ethersproject/units'; import { CurrencyKey } from '@synthetixio/contracts-interface'; import { CRYPTO_CURRENCY_MAP, iStandardSynth, synthToAsset } from '../../currency'; @@ -11,7 +13,7 @@ type CurrencyRate = BigNumberish; type SynthRatesTuple = [string[], CurrencyRate[]]; // Additional commonly used currencies to fetch, besides the one returned by the SynthUtil.synthsRates -const additionalCurrencies = [CRYPTO_CURRENCY_MAP.SNX].map(ethers.utils.formatBytes32String); +const additionalCurrencies = [CRYPTO_CURRENCY_MAP.SNX].map(formatBytes32String); const useExchangeRatesQuery = (ctx: QueryContext, options?: UseQueryOptions) => { return useQuery( @@ -28,8 +30,8 @@ const useExchangeRatesQuery = (ctx: QueryContext, options?: UseQueryOptions { - const currencyKey = ethers.utils.parseBytes32String(currencyKeyBytes32) as CurrencyKey; - const rate = Number(ethers.utils.formatEther(rates[idx])); + const currencyKey = parseBytes32String(currencyKeyBytes32) as CurrencyKey; + const rate = Number(formatEther(rates[idx])); exchangeRates[currencyKey] = wei(rate); // only interested in the standard synths (sETH -> ETH, etc) diff --git a/packages/queries/src/queries/rates/utils.ts b/packages/queries/src/queries/rates/utils.ts index 2a5575bb9..4d609278e 100644 --- a/packages/queries/src/queries/rates/utils.ts +++ b/packages/queries/src/queries/rates/utils.ts @@ -1,6 +1,6 @@ import Wei, { wei } from '@synthetixio/wei'; import subHours from 'date-fns/subHours'; -import { ethers } from 'ethers'; +import { MaxUint256 } from '@ethersproject/constants'; import { RateUpdateResult } from '../../../generated/exchangesSubgraphQueries'; import { BaseRateUpdate } from '../../types'; @@ -16,7 +16,7 @@ export const getMinAndMaxRate = (rates: RateUpdateResult[]): [Wei, Wei] => { return [newMin, newMax]; }, - [wei(ethers.constants.MaxUint256), wei(0)] + [wei(MaxUint256), wei(0)] ); }; diff --git a/packages/queries/src/queries/staking/useClaimableRewardsQuery.ts b/packages/queries/src/queries/staking/useClaimableRewardsQuery.ts index 68fe77317..c731db726 100644 --- a/packages/queries/src/queries/staking/useClaimableRewardsQuery.ts +++ b/packages/queries/src/queries/staking/useClaimableRewardsQuery.ts @@ -1,6 +1,6 @@ import { UseQueryOptions, useQuery } from 'react-query'; -import Wei, { wei } from '@synthetixio/wei'; +import { wei } from '@synthetixio/wei'; import { QueryContext } from '../../context'; import { StakingClaimableRewards } from '../../types'; @@ -14,7 +14,6 @@ const useClaimableRewards = ( async () => { const { contracts: { FeePool }, - utils, } = ctx.snxjs!; const feesAvailable = await FeePool.feesAvailable(walletAddress); return { diff --git a/packages/queries/src/queries/staking/useGlobalStakingInfoQuery.ts b/packages/queries/src/queries/staking/useGlobalStakingInfoQuery.ts index 48452edcb..4e6d90aee 100644 --- a/packages/queries/src/queries/staking/useGlobalStakingInfoQuery.ts +++ b/packages/queries/src/queries/staking/useGlobalStakingInfoQuery.ts @@ -1,10 +1,10 @@ import { useQuery, UseQueryOptions } from 'react-query'; -import { ethers } from 'ethers'; import Wei, { wei } from '@synthetixio/wei'; import { QueryContext } from '../../context'; import { GlobalStakingInfo } from '../../types'; import { useGetSNXHolders } from '../../../generated/mainSubgraphQueries'; +import { formatBytes32String } from '@ethersproject/strings'; /** * @deprecated Use useLockedSnxQuery instead @@ -37,14 +37,14 @@ const useGlobalStakingInfoQuery = ( unformattedTotalIssuedSynths, unformattedIssuanceRatio, ] = await Promise.all([ - ctx.snxjs!.contracts.ExchangeRates.rateForCurrency(ethers.utils.formatBytes32String('SNX')), + ctx.snxjs!.contracts.ExchangeRates.rateForCurrency(formatBytes32String('SNX')), ctx.snxjs!.contracts.Synthetix.totalSupply(), ctx.snxjs!.contracts.SynthetixState.lastDebtLedgerEntry(), ctx.snxjs!.contracts.Synthetix[ ctx.snxjs!.contracts.Synthetix.totalIssuedSynthsExcludeOtherCollateral ? 'totalIssuedSynthsExcludeOtherCollateral' : 'totalIssuedSynths' - ](ethers.utils.formatBytes32String('sUSD')), + ](formatBytes32String('sUSD')), ctx.snxjs!.contracts.SystemSettings.issuanceRatio(), ]); diff --git a/packages/queries/src/queries/staking/useSNXData.ts b/packages/queries/src/queries/staking/useSNXData.ts index e2ebb9816..30108f037 100644 --- a/packages/queries/src/queries/staking/useSNXData.ts +++ b/packages/queries/src/queries/staking/useSNXData.ts @@ -1,7 +1,8 @@ import { useQuery, UseQueryOptions } from 'react-query'; import { QueryContext } from '../../context'; import Wei, { wei } from '@synthetixio/wei'; -import { ethers, providers } from 'ethers'; +import { BaseProvider } from '@ethersproject/providers'; +import { formatBytes32String } from '@ethersproject/strings'; import { useGetSNXHolders } from '../../../generated/mainSubgraphQueries'; import synthetix, { NetworkIdByName, NetworkNameById } from '@synthetixio/contracts-interface'; import { DEFAULT_SUBGRAPH_ENDPOINTS } from '../../constants'; @@ -15,7 +16,7 @@ const ONE_HOUR_MS = 1000 * 60 * 60; const useSNXData = ( ctx: QueryContext, - L1Provider?: providers.BaseProvider, + L1Provider?: BaseProvider, options?: UseQueryOptions ) => { const snxHoldersQueryL1 = useGetSNXHolders( @@ -92,7 +93,7 @@ const useSNXData = ( async () => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const snxPriceP = ctx.snxjs!.contracts.ExchangeRates.rateForCurrency( - ethers.utils.formatBytes32String('SNX') + formatBytes32String('SNX') ); const totalSNXSupplyP = snxJSL1.contracts.Synthetix.totalSupply(); diff --git a/packages/queries/src/queries/synths/useExchangeFeeRateQuery.ts b/packages/queries/src/queries/synths/useExchangeFeeRateQuery.ts index 5309365cd..3e3f1bb4a 100644 --- a/packages/queries/src/queries/synths/useExchangeFeeRateQuery.ts +++ b/packages/queries/src/queries/synths/useExchangeFeeRateQuery.ts @@ -1,5 +1,6 @@ import { useQuery, UseQueryOptions } from 'react-query'; -import { ethers } from 'ethers'; +import { BigNumber } from '@ethersproject/bignumber'; +import { formatBytes32String } from '@ethersproject/strings'; import Wei, { wei } from '@synthetixio/wei'; @@ -17,9 +18,9 @@ const useExchangeFeeRate = ( ['synths', 'exchangeFeeRate', ctx.networkId, quoteCurrencyKey, baseCurrencyKey], async () => { const feeRateForExchange = (await ctx.snxjs!.contracts.Exchanger.feeRateForExchange( - ethers.utils.formatBytes32String(quoteCurrencyKey!), - ethers.utils.formatBytes32String(baseCurrencyKey!) - )) as ethers.BigNumber; + formatBytes32String(quoteCurrencyKey!), + formatBytes32String(baseCurrencyKey!) + )) as BigNumber; return wei(feeRateForExchange); }, diff --git a/packages/queries/src/queries/synths/useFeeReclaimPeriodQuery.ts b/packages/queries/src/queries/synths/useFeeReclaimPeriodQuery.ts index c7c9dcda8..b005dcb78 100644 --- a/packages/queries/src/queries/synths/useFeeReclaimPeriodQuery.ts +++ b/packages/queries/src/queries/synths/useFeeReclaimPeriodQuery.ts @@ -1,5 +1,6 @@ import { useQuery, UseQueryOptions } from 'react-query'; -import { ethers } from 'ethers'; +import { formatBytes32String } from '@ethersproject/strings'; +import { BigNumberish } from '@ethersproject/bignumber'; import { CurrencyKey } from '@synthetixio/contracts-interface'; import { QueryContext } from '../../context'; @@ -16,8 +17,8 @@ const useFeeReclaimPeriodQuery = ( const maxSecsLeftInWaitingPeriod = (await ctx.snxjs!.contracts.Exchanger.maxSecsLeftInWaitingPeriod( walletAddress, - ethers.utils.formatBytes32String(currencyKey!) - )) as ethers.BigNumberish; + formatBytes32String(currencyKey!) + )) as BigNumberish; return Number(maxSecsLeftInWaitingPeriod); }, diff --git a/packages/queries/src/queries/synths/useFeeReclaimPeriodsQuery.ts b/packages/queries/src/queries/synths/useFeeReclaimPeriodsQuery.ts index 4da5a6ecc..bdfd43389 100644 --- a/packages/queries/src/queries/synths/useFeeReclaimPeriodsQuery.ts +++ b/packages/queries/src/queries/synths/useFeeReclaimPeriodsQuery.ts @@ -1,7 +1,9 @@ import { useQuery, UseQueryOptions } from 'react-query'; -import { ethers } from 'ethers'; +import { formatBytes32String } from '@ethersproject/strings'; import { CurrencyKey, Synth } from '@synthetixio/contracts-interface'; import { wei } from '@synthetixio/wei'; +import { formatEther } from '@ethersproject/units'; +import { BigNumberish } from '@ethersproject/bignumber'; import { QueryContext } from '../../context'; import { SynthFeeAndWaitingPeriod } from '../../types'; @@ -24,8 +26,8 @@ const useFeeReclaimPeriodsQuery = ( const loadWaitingPeriod = async (currencyKey: Synth) => { const maxSecsLeftInWaitingPeriod = (await Exchanger.maxSecsLeftInWaitingPeriod( walletAddress, - ethers.utils.formatBytes32String(currencyKey.name) - )) as ethers.BigNumberish; + formatBytes32String(currencyKey.name) + )) as BigNumberish; return Number(maxSecsLeftInWaitingPeriod); }; @@ -33,10 +35,10 @@ const useFeeReclaimPeriodsQuery = ( const loadFee = async (currencyKey: Synth) => { const [rebate, reclaim, noOfTrades] = await Exchanger.settlementOwing( walletAddress, - ethers.utils.formatBytes32String(currencyKey.name) + formatBytes32String(currencyKey.name) ); return { - fee: wei(ethers.utils.formatEther(rebate.sub(reclaim))), + fee: wei(formatEther(rebate.sub(reclaim))), noOfTrades: Number(noOfTrades.toString()), }; }; diff --git a/packages/queries/src/queries/synths/useSynthSuspensionQuery.ts b/packages/queries/src/queries/synths/useSynthSuspensionQuery.ts index 05fe9c2a8..927294d16 100644 --- a/packages/queries/src/queries/synths/useSynthSuspensionQuery.ts +++ b/packages/queries/src/queries/synths/useSynthSuspensionQuery.ts @@ -1,5 +1,6 @@ import { useQuery, UseQueryOptions } from 'react-query'; -import { ethers } from 'ethers'; +import { formatBytes32String } from '@ethersproject/strings'; +import { BigNumber } from '@ethersproject/bignumber'; import { CurrencyKey } from '@synthetixio/contracts-interface'; import { QueryContext } from '../../context'; @@ -43,8 +44,8 @@ const useSynthSuspensionQuery = ( async () => { const [isSuspended, reason] = (await ctx.snxjs!.contracts.SystemStatus.synthExchangeSuspension( - ethers.utils.formatBytes32String(currencyKey!) - )) as [boolean, ethers.BigNumber]; + formatBytes32String(currencyKey!) + )) as [boolean, BigNumber]; const reasonCode = Number(reason); return { diff --git a/packages/queries/src/queries/synths/useSynthsTotalSupplyQuery.ts b/packages/queries/src/queries/synths/useSynthsTotalSupplyQuery.ts index 8eaa32191..49e02b4e9 100644 --- a/packages/queries/src/queries/synths/useSynthsTotalSupplyQuery.ts +++ b/packages/queries/src/queries/synths/useSynthsTotalSupplyQuery.ts @@ -1,5 +1,6 @@ -import { ethers } from 'ethers'; import { useQuery, UseQueryOptions } from 'react-query'; +import { formatBytes32String, parseBytes32String } from '@ethersproject/strings'; +import { formatEther } from '@ethersproject/units'; import { NetworkIdByName, Synths } from '@synthetixio/contracts-interface'; import { wei } from '@synthetixio/wei'; @@ -18,10 +19,6 @@ const useSynthsTotalSupplyQuery = ( contracts: { SynthUtil, ExchangeRates, CollateralManagerState, EtherWrapper }, } = ctx.snxjs!; - const { - utils: { formatBytes32String, parseBytes32String, formatEther }, - } = ethers; - const [sETHKey, sBTCKey, sUSDKey] = [Synths.sETH, Synths.sBTC, Synths.sUSD].map( formatBytes32String ); diff --git a/packages/queries/src/queries/synths/useTotalIssuedSynthsExcludeOtherCollateralQuery.ts b/packages/queries/src/queries/synths/useTotalIssuedSynthsExcludeOtherCollateralQuery.ts index 3c2bd17b9..8841ef33f 100644 --- a/packages/queries/src/queries/synths/useTotalIssuedSynthsExcludeOtherCollateralQuery.ts +++ b/packages/queries/src/queries/synths/useTotalIssuedSynthsExcludeOtherCollateralQuery.ts @@ -1,4 +1,3 @@ -import { NetworkId } from '@synthetixio/contracts-interface'; import Wei, { wei } from '@synthetixio/wei'; import { useQuery, UseQueryOptions } from 'react-query'; import { QueryContext } from '../../context'; diff --git a/packages/queries/src/queries/walletBalances/useSynthsBalancesQuery.ts b/packages/queries/src/queries/walletBalances/useSynthsBalancesQuery.ts index 4483c70e7..9d025021a 100644 --- a/packages/queries/src/queries/walletBalances/useSynthsBalancesQuery.ts +++ b/packages/queries/src/queries/walletBalances/useSynthsBalancesQuery.ts @@ -1,5 +1,6 @@ import { useQuery, UseQueryOptions } from 'react-query'; -import { ethers } from 'ethers'; +import { parseBytes32String } from '@ethersproject/strings'; +import { BigNumber } from '@ethersproject/bignumber'; import orderBy from 'lodash/orderBy'; import { wei } from '@synthetixio/wei'; @@ -7,7 +8,7 @@ import { CurrencyKey } from '@synthetixio/contracts-interface'; import { QueryContext } from '../../context'; import { Balances, SynthBalancesMap } from '../../types'; -type SynthBalancesTuple = [string[], ethers.BigNumber[], ethers.BigNumber[]]; +type SynthBalancesTuple = [string[], BigNumber[], BigNumber[]]; const useSynthsBalancesQuery = ( ctx: QueryContext, @@ -32,7 +33,7 @@ const useSynthsBalancesQuery = ( // discard empty balances if (balance.gt(0)) { - const synthName = ethers.utils.parseBytes32String(currencyKeyBytes32) as CurrencyKey; + const synthName = parseBytes32String(currencyKeyBytes32) as CurrencyKey; const usdBalance = wei(synthsUSDBalances[idx]); balancesMap[synthName] = { diff --git a/packages/queries/src/queries/walletBalances/useTokensBalancesQuery.ts b/packages/queries/src/queries/walletBalances/useTokensBalancesQuery.ts index e9555e5ce..9a4fdb5b8 100644 --- a/packages/queries/src/queries/walletBalances/useTokensBalancesQuery.ts +++ b/packages/queries/src/queries/walletBalances/useTokensBalancesQuery.ts @@ -1,7 +1,8 @@ import { useQuery, UseQueryOptions, UseQueryResult } from 'react-query'; import { wei } from '@synthetixio/wei'; import erc20Abi from '../../abis/ERC20.json'; -import { BigNumber, ethers } from 'ethers'; +import { Contract } from '@ethersproject/contracts'; +import { BigNumber } from '@ethersproject/bignumber'; import { CRYPTO_CURRENCY_MAP } from '../../currency'; import { QueryContext } from '../../context'; import { Token, TokenBalances } from '../../types'; @@ -16,12 +17,12 @@ const useTokensBalancesQuery = ( return useQuery( ['walletBalances', 'tokens', ctx.networkId, walletAddress, tokens.join()], async () => { - const getBalance = ({ address, symbol }: Token): Promise => { + const getBalance = ({ address, symbol }: Token): Promise => { if (!ctx.provider || !walletAddress) return Promise.resolve(BigNumber.from(0)); if (symbol === CRYPTO_CURRENCY_MAP.ETH) { return ctx.provider.getBalance(walletAddress); } else { - const tokenContract = new ethers.Contract(address, erc20Abi, ctx.provider); + const tokenContract = new Contract(address, erc20Abi, ctx.provider); return tokenContract.balanceOf(walletAddress); } }; diff --git a/packages/queries/src/types.ts b/packages/queries/src/types.ts index 6b776dee0..9c1fdd89a 100644 --- a/packages/queries/src/types.ts +++ b/packages/queries/src/types.ts @@ -1,6 +1,6 @@ import Wei from '@synthetixio/wei'; import { CurrencyKey, NetworkId, NetworkName } from '@synthetixio/contracts-interface'; -import { BigNumber } from 'ethers'; +import { BigNumber } from '@ethersproject/bignumber'; export type GasPrice = { baseFeePerGas?: BigNumber; // Note that this is used for estimating price and should not be included in the transaction diff --git a/packages/queries/src/utils.ts b/packages/queries/src/utils.ts index 1f6a7dafb..3f2b03d6f 100644 --- a/packages/queries/src/utils.ts +++ b/packages/queries/src/utils.ts @@ -1,9 +1,10 @@ -import { ethers } from 'ethers'; +import { Provider } from '@ethersproject/providers'; +import { Contract } from '@ethersproject/contracts'; export const formatGwei = (wei: number) => wei / 1e8 / 10; -export const getProxySynthSymbol = (provider: ethers.providers.Provider, address: string) => { - const c = new ethers.Contract( +export const getProxySynthSymbol = (provider: Provider, address: string) => { + const c = new Contract( address, [ { diff --git a/packages/queries/testUtils.ts b/packages/queries/testUtils.ts index 9a4e10b2a..8a95c944f 100644 --- a/packages/queries/testUtils.ts +++ b/packages/queries/testUtils.ts @@ -1,9 +1,10 @@ -import React, { ReactNode } from 'react'; +import { ReactNode } from 'react'; import { QueryClient, QueryClientProvider } from 'react-query'; import { QueryContext } from './src/context'; import { NetworkIdByName, SynthetixJS, NetworkId } from '@synthetixio/contracts-interface'; -import { ethers } from 'ethers'; +import { Provider } from '@ethersproject/providers'; +import { Signer } from '@ethersproject/abstract-signer'; // simple query client wrapper which allows for testing of a // query function hook, see https://react-query.tanstack.com/guides/testing @@ -18,8 +19,8 @@ export function getFakeQueryContext(networkId: NetworkId = NetworkIdByName.mainn return { networkId, subgraphEndpoints: { exchanger: '', issuance: '', exchanges: '', subgraph: '' }, - signer: {} as ethers.Signer, - provider: {} as ethers.providers.Provider, + signer: {} as Signer, + provider: {} as Provider, snxjs: {} as SynthetixJS, }; } diff --git a/packages/transaction-notifier/package.json b/packages/transaction-notifier/package.json index b747062c2..51e7dbea7 100644 --- a/packages/transaction-notifier/package.json +++ b/packages/transaction-notifier/package.json @@ -35,9 +35,10 @@ "url": "https://github.com/Synthetixio/js-monorepo/issues" }, "dependencies": { + "@ethersproject/properties": "^5.6.0", "@ethersproject/providers": "^5.6.8", - "@synthetixio/providers": "workspace:*", - "ethers": "^5.5.3" + "@ethersproject/strings": "^5.6.1", + "@synthetixio/providers": "workspace:*" }, "devDependencies": { "@babel/core": "^7.11.0", diff --git a/packages/transaction-notifier/src/ethRevertReason.ts b/packages/transaction-notifier/src/ethRevertReason.ts index aa57fc958..e3ab90e73 100644 --- a/packages/transaction-notifier/src/ethRevertReason.ts +++ b/packages/transaction-notifier/src/ethRevertReason.ts @@ -1,5 +1,6 @@ import type { TransactionRequest } from '@ethersproject/providers'; -import { ethers } from 'ethers'; +import { toUtf8String } from '@ethersproject/strings'; +import { Deferrable } from '@ethersproject/properties'; import { RevertReasonParams } from './types'; @@ -19,10 +20,7 @@ const getRevertReason = async ({ try { const tx = await provider.getTransaction(txHash); - const code = await provider.call( - tx as ethers.utils.Deferrable, - blockNumber - ); + const code = await provider.call(tx as Deferrable, blockNumber); return decodeMessage(code); } catch (err) { return 'Unable to decode revert reason'; @@ -60,7 +58,7 @@ function decodeMessage(code: string) { codeString += '0'; } - return ethers.utils.toUtf8String(codeString); + return toUtf8String(codeString); } export default getRevertReason; diff --git a/yarn.lock b/yarn.lock index a54aad4f2..3eaf7da7f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1393,7 +1393,7 @@ __metadata: languageName: node linkType: hard -"@ethersproject/abi@npm:5.6.3, @ethersproject/abi@npm:^5.0.4, @ethersproject/abi@npm:^5.6.3": +"@ethersproject/abi@npm:5.6.3, @ethersproject/abi@npm:^5.6.3": version: 5.6.3 resolution: "@ethersproject/abi@npm:5.6.3" dependencies: @@ -1410,6 +1410,23 @@ __metadata: languageName: node linkType: hard +"@ethersproject/abi@npm:^5.6.4": + version: 5.6.4 + resolution: "@ethersproject/abi@npm:5.6.4" + dependencies: + "@ethersproject/address": ^5.6.1 + "@ethersproject/bignumber": ^5.6.2 + "@ethersproject/bytes": ^5.6.1 + "@ethersproject/constants": ^5.6.1 + "@ethersproject/hash": ^5.6.1 + "@ethersproject/keccak256": ^5.6.1 + "@ethersproject/logger": ^5.6.0 + "@ethersproject/properties": ^5.6.0 + "@ethersproject/strings": ^5.6.1 + checksum: b5e70fa13a29e1143131a0ed25053a3d355c07353e13d436f42add33f40753b5541a088cf31a1ccca6448bb1d773a41ece0bf8367490d3f2ad394a4c26f4876f + languageName: node + linkType: hard + "@ethersproject/abstract-provider@npm:5.6.1, @ethersproject/abstract-provider@npm:^5.6.1": version: 5.6.1 resolution: "@ethersproject/abstract-provider@npm:5.6.1" @@ -1481,7 +1498,7 @@ __metadata: languageName: node linkType: hard -"@ethersproject/bytes@npm:5.6.1, @ethersproject/bytes@npm:^5.0.4, @ethersproject/bytes@npm:^5.0.8, @ethersproject/bytes@npm:^5.6.1": +"@ethersproject/bytes@npm:5.6.1, @ethersproject/bytes@npm:^5.0.4, @ethersproject/bytes@npm:^5.6.1": version: 5.6.1 resolution: "@ethersproject/bytes@npm:5.6.1" dependencies: @@ -1499,7 +1516,7 @@ __metadata: languageName: node linkType: hard -"@ethersproject/contracts@npm:5.6.2, @ethersproject/contracts@npm:^5.0.3": +"@ethersproject/contracts@npm:5.6.2, @ethersproject/contracts@npm:^5.6.2": version: 5.6.2 resolution: "@ethersproject/contracts@npm:5.6.2" dependencies: @@ -1517,7 +1534,7 @@ __metadata: languageName: node linkType: hard -"@ethersproject/hash@npm:5.6.1, @ethersproject/hash@npm:^5.0.4, @ethersproject/hash@npm:^5.0.9, @ethersproject/hash@npm:^5.6.1": +"@ethersproject/hash@npm:5.6.1, @ethersproject/hash@npm:^5.0.4, @ethersproject/hash@npm:^5.6.1": version: 5.6.1 resolution: "@ethersproject/hash@npm:5.6.1" dependencies: @@ -1619,7 +1636,7 @@ __metadata: languageName: node linkType: hard -"@ethersproject/providers@npm:5.6.8, @ethersproject/providers@npm:^5.3.1, @ethersproject/providers@npm:^5.6.8": +"@ethersproject/providers@npm:5.6.8, @ethersproject/providers@npm:^5.6.8": version: 5.6.8 resolution: "@ethersproject/providers@npm:5.6.8" dependencies: @@ -1734,7 +1751,7 @@ __metadata: languageName: node linkType: hard -"@ethersproject/units@npm:5.6.1": +"@ethersproject/units@npm:5.6.1, @ethersproject/units@npm:^5.6.1": version: 5.6.1 resolution: "@ethersproject/units@npm:5.6.1" dependencies: @@ -1745,7 +1762,7 @@ __metadata: languageName: node linkType: hard -"@ethersproject/wallet@npm:5.6.2, @ethersproject/wallet@npm:^5.4.0": +"@ethersproject/wallet@npm:5.6.2, @ethersproject/wallet@npm:^5.6.2": version: 5.6.2 resolution: "@ethersproject/wallet@npm:5.6.2" dependencies: @@ -2205,23 +2222,23 @@ __metadata: languageName: node linkType: hard -"@snapshot-labs/snapshot.js@npm:^0.3.22": - version: 0.3.92 - resolution: "@snapshot-labs/snapshot.js@npm:0.3.92" +"@snapshot-labs/snapshot.js@npm:^0.4.13": + version: 0.4.13 + resolution: "@snapshot-labs/snapshot.js@npm:0.4.13" dependencies: "@ensdomains/eth-ens-namehash": ^2.0.15 - "@ethersproject/abi": ^5.0.4 - "@ethersproject/bytes": ^5.0.8 - "@ethersproject/contracts": ^5.0.3 - "@ethersproject/hash": ^5.0.9 - "@ethersproject/providers": ^5.3.1 - "@ethersproject/wallet": ^5.4.0 - ajv: ^8.6.0 - ajv-formats: ^2.1.0 - cross-fetch: ^3.0.6 - json-to-graphql-query: ^2.0.0 + "@ethersproject/abi": ^5.6.4 + "@ethersproject/bytes": ^5.6.1 + "@ethersproject/contracts": ^5.6.2 + "@ethersproject/hash": ^5.6.1 + "@ethersproject/providers": ^5.6.8 + "@ethersproject/wallet": ^5.6.2 + ajv: ^8.11.0 + ajv-formats: ^2.1.1 + cross-fetch: ^3.1.5 + json-to-graphql-query: ^2.2.4 lodash.set: ^4.3.2 - checksum: b874a01e2dbaf02f3697a10e664656802f282f3945fff75c0e5a9c35093e1c9879126f9324d28e24a120abc7eb9247ec05b4b4fb7b939a7124db2a3cee2dc867 + checksum: d2b64acaaaedd5faff75615c7ac668c015b99a3c5b1ecddd09dbdcb8fc6b3dd0de6791fedeb6943cbac4c91f2c1de81c34f51af92a9ed53ed61023f7de238d6f languageName: node linkType: hard @@ -2296,10 +2313,11 @@ __metadata: "@babel/plugin-transform-runtime": ^7.13.10 "@babel/preset-env": ^7.13.10 "@babel/preset-typescript": ^7.13.0 + "@ethersproject/bignumber": ^5.6.2 + "@ethersproject/bytes": ^5.6.1 "@metamask/providers": ^8.1.1 "@types/node": ^17.0.43 eslint: ^7.26.0 - ethers: ^5.5.3 jest: ^27.0.6 ts-loader: ^8.0.2 ts-node: ^10.2.1 @@ -2317,12 +2335,13 @@ __metadata: "@babel/plugin-transform-runtime": ^7.13.10 "@babel/preset-env": ^7.13.10 "@babel/preset-typescript": ^7.13.0 + "@ethersproject/bignumber": ^5.6.2 + "@ethersproject/bytes": ^5.6.1 "@ethersproject/providers": ^5.6.8 "@synthetixio/contracts-interface": "workspace:*" "@synthetixio/optimism-networks": "workspace:*" "@types/node": ^17.0.43 eslint: ^7.26.0 - ethers: ^5.5.3 jest: ^27.0.6 ts-loader: ^8.0.2 ts-node: ^10.2.1 @@ -2340,7 +2359,16 @@ __metadata: "@babel/plugin-transform-runtime": ^7.13.10 "@babel/preset-env": ^7.13.10 "@babel/preset-typescript": ^7.13.0 - "@snapshot-labs/snapshot.js": ^0.3.22 + "@ethersproject/abstract-signer": ^5.6.2 + "@ethersproject/address": ^5.6.1 + "@ethersproject/bignumber": ^5.6.2 + "@ethersproject/constants": ^5.6.1 + "@ethersproject/contracts": ^5.6.2 + "@ethersproject/providers": ^5.6.8 + "@ethersproject/strings": ^5.6.1 + "@ethersproject/transactions": ^5.6.2 + "@ethersproject/units": ^5.6.1 + "@snapshot-labs/snapshot.js": ^0.4.13 "@synthetixio/codegen-graph-ts": "workspace:*" "@synthetixio/contracts-interface": "workspace:*" "@synthetixio/optimism-networks": "workspace:*" @@ -2352,7 +2380,6 @@ __metadata: axios: ^0.21.4 date-fns: ^2.19.0 eslint: ^7.26.0 - ethers: ^5.5.3 graphql: ^15.5.0 graphql-request: ^3.4.0 jest: ^27.0.6 @@ -2389,11 +2416,12 @@ __metadata: "@babel/plugin-transform-runtime": ^7.13.10 "@babel/preset-env": ^7.13.10 "@babel/preset-typescript": ^7.13.0 + "@ethersproject/properties": ^5.6.0 "@ethersproject/providers": ^5.6.8 + "@ethersproject/strings": ^5.6.1 "@synthetixio/providers": "workspace:*" "@types/node": ^17.0.43 eslint: ^7.26.0 - ethers: ^5.5.3 jest: ^27.0.6 ts-loader: ^8.0.2 ts-node: ^10.2.1 @@ -3282,7 +3310,7 @@ __metadata: languageName: node linkType: hard -"ajv-formats@npm:^2.1.0": +"ajv-formats@npm:^2.1.1": version: 2.1.1 resolution: "ajv-formats@npm:2.1.1" dependencies: @@ -3317,7 +3345,7 @@ __metadata: languageName: node linkType: hard -"ajv@npm:^8.0.0, ajv@npm:^8.0.1, ajv@npm:^8.6.0": +"ajv@npm:^8.0.0, ajv@npm:^8.0.1, ajv@npm:^8.11.0": version: 8.11.0 resolution: "ajv@npm:8.11.0" dependencies: @@ -4682,7 +4710,7 @@ __metadata: languageName: node linkType: hard -"cross-fetch@npm:^3.0.6": +"cross-fetch@npm:^3.0.6, cross-fetch@npm:^3.1.5": version: 3.1.5 resolution: "cross-fetch@npm:3.1.5" dependencies: @@ -8046,7 +8074,7 @@ __metadata: languageName: node linkType: hard -"json-to-graphql-query@npm:^2.0.0": +"json-to-graphql-query@npm:^2.2.4": version: 2.2.4 resolution: "json-to-graphql-query@npm:2.2.4" checksum: 3caced3bfc59c4aa26632f8a96fa8cc356dd4b82a6cc9c64a16d2eb262d8ac539ed584ca51552a9cde24beb2735f15feaf611619e10182098bdb33d63b2bf5df