diff --git a/package-lock.json b/package-lock.json index e9e65e6c7..2a7528264 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7755,15 +7755,15 @@ "dev": true }, "node_modules/chai": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.5.tgz", - "integrity": "sha512-0gKhNDL29PUlmwz1CG42p/OaBf1v0YD3oH4//YMS1niT7rLH9tC+lqTgk+SvdbhMLd7ToTtxA61orNBmpSO/DA==", + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.6.tgz", + "integrity": "sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==", "dependencies": { "assertion-error": "^1.1.0", "check-error": "^1.0.2", "deep-eql": "^3.0.1", "get-func-name": "^2.0.0", - "loupe": "^2.3.0", + "loupe": "^2.3.1", "pathval": "^1.1.1", "type-detect": "^4.0.5" }, @@ -16280,12 +16280,11 @@ } }, "node_modules/loupe": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.0.tgz", - "integrity": "sha512-b6TVXtF01VErh8IxN/MfdiWLQmttrenN98PPGS01kym8kGycJ9tqBXD6D+4sNEDhgE83+H0Mk1cVSl0mD1nNSg==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.1.tgz", + "integrity": "sha512-EN1D3jyVmaX4tnajVlfbREU4axL647hLec1h/PXAb8CPDMJiYitcWF2UeLVNttRqaIqQs4x+mRvXf+d+TlDrCA==", "dependencies": { - "get-func-name": "^2.0.0", - "type-detect": "^4.0.8" + "get-func-name": "^2.0.0" } }, "node_modules/lowercase-keys": { @@ -30354,15 +30353,15 @@ "dev": true }, "chai": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.5.tgz", - "integrity": "sha512-0gKhNDL29PUlmwz1CG42p/OaBf1v0YD3oH4//YMS1niT7rLH9tC+lqTgk+SvdbhMLd7ToTtxA61orNBmpSO/DA==", + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.6.tgz", + "integrity": "sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==", "requires": { "assertion-error": "^1.1.0", "check-error": "^1.0.2", "deep-eql": "^3.0.1", "get-func-name": "^2.0.0", - "loupe": "^2.3.0", + "loupe": "^2.3.1", "pathval": "^1.1.1", "type-detect": "^4.0.5" } @@ -37095,12 +37094,11 @@ } }, "loupe": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.0.tgz", - "integrity": "sha512-b6TVXtF01VErh8IxN/MfdiWLQmttrenN98PPGS01kym8kGycJ9tqBXD6D+4sNEDhgE83+H0Mk1cVSl0mD1nNSg==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.1.tgz", + "integrity": "sha512-EN1D3jyVmaX4tnajVlfbREU4axL647hLec1h/PXAb8CPDMJiYitcWF2UeLVNttRqaIqQs4x+mRvXf+d+TlDrCA==", "requires": { - "get-func-name": "^2.0.0", - "type-detect": "^4.0.8" + "get-func-name": "^2.0.0" } }, "lowercase-keys": { diff --git a/packages/contracts-interface/__tests__/index.test.ts b/packages/contracts-interface/__tests__/index.test.ts index b72eadb45..2b01889e7 100644 --- a/packages/contracts-interface/__tests__/index.test.ts +++ b/packages/contracts-interface/__tests__/index.test.ts @@ -2,14 +2,14 @@ import { ethers } from 'ethers'; import findIndex from 'lodash/findIndex'; import synthetix, { SynthetixJS } from '../src'; -import { Network, NetworkId } from '../src/types'; +import { NetworkNameById, NetworkIdByName } from '../src/types'; import { ERRORS } from '../src/constants'; describe('@synthetixio/js tests', () => { let snxjs: SynthetixJS; beforeAll(() => { - snxjs = synthetix({ network: Network.Kovan }); + snxjs = synthetix({ network: NetworkNameById[42] }); }); test('should return contracts', () => { @@ -17,8 +17,8 @@ describe('@synthetixio/js tests', () => { }); test('should return different contracts for the OVM', () => { - const snxjsGoerli = synthetix({ network: Network.Goerli }); - const snxjsGoerliOvm = synthetix({ network: Network['Goerli-Ovm'] }); + const snxjsGoerli = synthetix({ network: NetworkNameById[5] }); + const snxjsGoerliOvm = synthetix({ network: NetworkNameById[42] }); const synthetixContractGoerli = snxjsGoerli.contracts['Synthetix']; const synthetixContractGoerliOvm = snxjsGoerliOvm.contracts['Synthetix']; expect(synthetixContractGoerli.address).not.toEqual(synthetixContractGoerliOvm.address); @@ -34,7 +34,7 @@ describe('@synthetixio/js tests', () => { }); test('should have the right mapping with the contracts for the OVM', () => { - const snxjsGoerliOvm = synthetix({ network: Network.Goerli, useOvm: true }); + const snxjsGoerliOvm = synthetix({ network: NetworkNameById[5], useOvm: true }); const synthetixContractGoerliOvm = snxjsGoerliOvm.contracts['Synthetix']; const sUSDContractGoerliOvm = snxjsGoerliOvm.contracts['SynthsUSD']; expect(synthetixContractGoerliOvm.address).toEqual(snxjsGoerliOvm.targets.ProxyERC20.address); @@ -46,14 +46,13 @@ describe('@synthetixio/js tests', () => { }); test('should include the supported networks', () => { - expect(snxjs.networkToChainId[Network.Mainnet]).toBe(NetworkId.Mainnet.toString()); - expect(snxjs.networkToChainId[Network.Kovan]).toBe(NetworkId.Kovan.toString()); - expect(snxjs.networkToChainId[Network.Rinkeby]).not.toBe(NetworkId.Ropsten.toString()); + expect(snxjs.networkToChainId[NetworkNameById[1]]).toBe(NetworkIdByName.mainnet.toString()); + expect(snxjs.networkToChainId[NetworkNameById[42]]).toBe(NetworkIdByName.kovan.toString()); }); test('should include the current network', () => { - expect(snxjs.network.name).toBe(Network.Kovan); - expect(snxjs.network.id).toBe(NetworkId.Kovan); + expect(snxjs.network.name).toBe(NetworkNameById[42]); + expect(snxjs.network.id).toBe(NetworkIdByName.kovan.toString()); }); test('should return users', () => { @@ -87,12 +86,13 @@ describe('@synthetixio/js tests', () => { }); test('should not include invalid synths data', () => { + // @ts-ignore const invalidSynthIndex = findIndex(snxjs.synths, ({ name }) => name === 'mETH1234'); expect(invalidSynthIndex).toBe(-1); }); test('should have a list of staking rewards', () => { - const mainnetSnxjs = synthetix({ network: Network.Mainnet }); + const mainnetSnxjs = synthetix({ network: NetworkNameById[1] }); expect(mainnetSnxjs.stakingRewards[0].name).toBeTruthy(); }); @@ -134,6 +134,7 @@ describe('@synthetixio/js tests', () => { // @ts-ignore synthetix({ network: 'wrongnetwork' }); } catch (e) { + // @ts-ignore expect(e.message).toEqual(ERRORS.badNetworkArg); } }); diff --git a/packages/contracts-interface/src/index.ts b/packages/contracts-interface/src/index.ts index 1e9016b55..9d9e42f6d 100644 --- a/packages/contracts-interface/src/index.ts +++ b/packages/contracts-interface/src/index.ts @@ -14,6 +14,9 @@ import { decode, defaults, getFeeds, + Token, + TargetsRecord, + Target, } from 'synthetix'; import { ethers } from 'ethers'; @@ -21,14 +24,14 @@ import { Config, CurrencyKey, CurrencyCategory, - Network, NetworkId, - Target, - TargetsRecord, + NetworkIdByNameType, ContractsMap, SynthetixJS, Synth, - Token, + NetworkName, + NetworkIdByName, + NetworkNameById, } from './types'; import { Synths } from '../generated/mainnet'; @@ -62,9 +65,12 @@ const synthetix = ({ networkId, network, signer, provider }: Config): SynthetixJ }; }; -const selectNetwork = (networkId?: NetworkId, network?: Network): [Network, NetworkId, boolean] => { - let currentNetwork: Network = Network.Mainnet; - let currentNetworkId: NetworkId = NetworkId.Mainnet; +const selectNetwork = ( + networkId?: NetworkId, + network?: NetworkName +): [NetworkName, NetworkId, boolean] => { + let currentNetworkId: NetworkId; + let currentNetworkName: NetworkName; let useOvm = false; if ( (network && !networkToChainId[network]) || @@ -72,31 +78,34 @@ const selectNetwork = (networkId?: NetworkId, network?: Network): [Network, Netw ) { throw new Error(ERRORS.badNetworkArg); } else if (network && networkToChainId[network]) { - const networkToId = Number(networkToChainId[network]); + const networkToId = NetworkIdByName[network]; const networkFromId = getNetworkFromId({ id: networkToId }); - currentNetworkId = networkToId; - currentNetwork = networkFromId.network; - useOvm = networkFromId.useOvm; + currentNetworkId = networkToChainId[network]; + currentNetworkName = networkFromId.network; + useOvm = !!networkFromId.useOvm; } else if (networkId) { const networkFromId = getNetworkFromId({ id: networkId }); currentNetworkId = networkId; - currentNetwork = networkFromId.network; - useOvm = networkFromId.useOvm; + currentNetworkName = networkFromId.network; + useOvm = Boolean(networkFromId.useOvm); + } else { + currentNetworkId = NetworkIdByName.mainnet; + currentNetworkName = NetworkNameById[1]; } - return [currentNetwork, currentNetworkId, useOvm]; + return [currentNetworkName, currentNetworkId, useOvm]; }; const getSynthetixContracts = ( - network: Network, + network: NetworkName, signer?: ethers.Signer, provider?: ethers.providers.Provider, useOvm?: boolean ): ContractsMap => { const sources = getSource({ network, useOvm }); - const targets: TargetsRecord = getTarget({ network, useOvm }); + const targets = getTarget({ network, useOvm }); return Object.values(targets) - .map((target: Target) => { + .map((target) => { if (target.name === 'Synthetix') { target.address = targets.ProxyERC20.address; } else if (target.name === 'SynthsUSD') { @@ -109,7 +118,7 @@ const getSynthetixContracts = ( } return target; }) - .reduce((acc: ContractsMap, { name, source, address }: Target) => { + .reduce((acc: ContractsMap, { name, source, address }) => { acc[name] = new ethers.Contract( address, sources[source].abi, @@ -121,12 +130,24 @@ const getSynthetixContracts = ( export { synthetix, - Network, - NetworkId, + NetworkNameById, + NetworkIdByName, Synths, CurrencyCategory, networkToChainId, getNetworkFromId, }; -export type { Config, CurrencyKey, Target, TargetsRecord, ContractsMap, SynthetixJS, Synth, Token }; +export type { + Config, + CurrencyKey, + Target, + TargetsRecord, + ContractsMap, + SynthetixJS, + Synth, + Token, + NetworkName, + NetworkId, + NetworkIdByNameType, +}; export default synthetix; diff --git a/packages/contracts-interface/src/missing-types.d.ts b/packages/contracts-interface/src/missing-types.d.ts deleted file mode 100644 index 83334ad51..000000000 --- a/packages/contracts-interface/src/missing-types.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'synthetix'; diff --git a/packages/contracts-interface/src/synthetix.d.ts b/packages/contracts-interface/src/synthetix.d.ts new file mode 100644 index 000000000..86ee5daa4 --- /dev/null +++ b/packages/contracts-interface/src/synthetix.d.ts @@ -0,0 +1,169 @@ +declare module 'synthetix' { + import { NetworkName, NetworkId } from '.'; + import ethers from 'ethers'; + + type SourceData = { + bytecode: string; + abi: ethers.ContractInterface; + }; + type SourceRecord = Record; + type Target = { + name: string; + source: string; + address: string; + link: string; + timestamp: string; + txn: string; + network: NetworkName; + }; + + export type TargetsRecord = Record; + type Feed = { + asset: string; + category: string; + description?: string; + exchange?: string; + feed?: string; + sign: string; + }; + export type FeedRecord = Record; + + export type Token = { + address: string; + asset?: string; + decimals: number; + feed?: string; + index?: Array<{ + asset: string; + category: string; + description: string; + sign: string; + units: number; + weight: number; + }>; + inverted?: { + entryPoint: number; + lowerLimit: number; + upperLimit: number; + }; + name: string; + symbol: string; + }; + export type User = { + name: string; + address: string; + }; + type ContractInfo = { + address: string; + replaced_in: string; + status: string; + }; + export type Version = { + commit: string; + contracts: { [name: string]: ContractInfo }; + date: string; + fulltag: string; + network: string; + release: string; + tag: string; + }; + type VersionRecord = Record; + + type StakingReward = { + name: string; + rewardsToken: string; + stakingToken: string; + }; + + export function getNetworkFromId(arg: { id: NetworkId | number }): { + useOvm?: boolean; + network: NetworkName; + }; + export function getSource< + T extends { network: NetworkName; useOvm?: boolean; contract?: string } + >( + arg: T + ): T extends { network: NetworkName; useOvm?: boolean; contract: string } // If contract is provided we return Source data. If not we return the contracts map + ? SourceData + : SourceRecord; + export function getTarget< + T extends { network: NetworkName; useOvm?: boolean; contract?: string } + >( + arg: T + ): T extends { network: NetworkName; useOvm?: boolean; contract: string } // If contract is provided we return Source data. If not we return the contracts map + ? Target + : TargetsRecord; + + export const chainIdMapping = { + '1': { + useOvm: false, + fork: false, + network: 'mainnet', + }, + '5': { + useOvm: false, + fork: false, + network: 'goerli', + }, + '10': { + useOvm: true, + fork: false, + network: 'mainnet', + }, + '42': { + useOvm: false, + fork: false, + network: 'kovan', + }, + '69': { + useOvm: true, + fork: false, + network: 'kovan', + }, + '31337': { + useOvm: false, + fork: true, + network: 'mainnet', + }, + '-1': { + useOvm: true, + fork: false, + network: 'goerli', + }, + } as const; + export const networkToChainId = { + mainnet: '1', + goerli: '5', + 'mainnet-ovm': '10', + kovan: '42', + 'kovan-ovm': '69', + 'mainnet-fork': '31337', + 'goerli-ovm': '-1', + } as const; + // eslint-disable-next-line + export function getSynths(arg: { network: NetworkName; useOvm?: boolean }): any; // Note contract interface will generate enums for this and return the correct type to consumers + export function getFeeds(arg: { network: NetworkName; useOvm?: boolean }): FeedRecord; + export function getTokens(arg: { network: NetworkName; useOvm?: boolean }): Token[]; + export function getUsers(arg: { network: NetworkName; useOvm?: boolean }): User[]; + export function getVersions(arg: { network: NetworkName; useOvm?: boolean }): VersionRecord; + export function toBytes32(key: string): string; + export function getSuspensionReasons(): { [code: number]: string }; + export function getStakingRewards(arg: { + network: NetworkName; + useOvm?: boolean; + }): StakingReward[]; + export const network: { + id: NetworkId; + name: NetworkName; + useOvm: boolean; + }; + export const networks: NetworkName[]; + export const networkToChainId: Record; + export const decode: (config: { network: NetworkName; data: string; target: Target }) => { + // eslint-disable-next-line + method: { name: string; params: Array }; + contract: string; + }; + // eslint-disable-next-line + export const defaults: { [key: string]: any }; +} diff --git a/packages/contracts-interface/src/types.ts b/packages/contracts-interface/src/types.ts index 94603013d..240feadd3 100644 --- a/packages/contracts-interface/src/types.ts +++ b/packages/contracts-interface/src/types.ts @@ -1,101 +1,54 @@ import { ethers } from 'ethers'; +import { + FeedRecord, + SourceRecord, + StakingReward, + Target, + TargetsRecord, + Token, + User, + Version, + networkToChainId, +} from 'synthetix'; import { Synths } from '../generated/mainnet'; -export enum Network { - Mainnet = 'mainnet', - Ropsten = 'ropsten', - Rinkeby = 'rinkeby', - Goerli = 'goerli', - Kovan = 'kovan', - Local = 'local', - 'Mainnet-Ovm' = 'mainnet-ovm', - 'Kovan-Ovm' = 'kovan-ovm', - 'Goerli-Ovm' = 'goerli-ovm', - 'Local-Ovm' = 'local-ovm', -} - -export enum NetworkId { - Mainnet = 1, - Ropsten = 3, - Rinkeby = 4, - Goerli = 5, - Kovan = 42, - 'Mainnet-Ovm' = 10, - 'Kovan-Ovm' = 69, - 'Local-Ovm' = 420, - 'Local' = 31337, -} - -type ContractInfo = { - address: string; - replaced_in: string; - status: string; -}; - -type Version = { - commit: string; - contracts: { [name: string]: ContractInfo }; - date: string; - fulltag: string; - network: string; - release: string; - tag: string; -}; - -type StakingReward = { - name: string; - rewardsToken: string; - stakingToken: string; -}; - -export type Token = { - address: string; - asset?: string; - decimals: number; - feed?: string; - index?: Array<{ - asset: string; - category: string; - description: string; - sign: string; - units: number; - weight: number; - }>; - inverted?: { - entryPoint: number; - lowerLimit: number; - upperLimit: number; - }; - name: string; - symbol: string; -}; - -type Feed = { - asset: string; - category: string; - description?: string; - exchange?: string; - feed?: string; - sign: string; -}; +export const NetworkIdByName = { + mainnet: '1', + goerli: '5', + kovan: '42', + 'mainnet-ovm': '10', + 'kovan-ovm': '69', +} as const; + +export const NetworkNameById = { + '1': 'mainnet', + '5': 'goerli', + '42': 'kovan', + '10': 'mainnet-ovm', + '69': 'kovan-ovm', +} as const; + +export type NetworkIdByNameType = typeof NetworkIdByName; +export type NetworkName = keyof typeof NetworkIdByName; +export type NetworkId = typeof NetworkIdByName[keyof typeof NetworkIdByName]; export type SynthetixJS = { - networks: Array; - networkToChainId: Record; - decode: (config: { network: Network; data: string; target: Target }) => { + networks: Array; + networkToChainId: typeof networkToChainId; + decode: (config: { network: NetworkName; data: string; target: Target }) => { method: { name: string; params: Array }; contract: string; }; defaults: { [key: string]: any }; - feeds: { [symbol: string]: Feed }; + feeds: FeedRecord; tokens: Array; network: { id: NetworkId; - name: Network; + name: NetworkName; useOvm: boolean; }; - sources: { [name: string]: SourceData }; + sources: SourceRecord; targets: TargetsRecord; synths: Synth[]; versions: { [version: string]: Version }; @@ -107,36 +60,13 @@ export type SynthetixJS = { contracts: ContractsMap; }; -export type SourceData = { - bytecode: string; - abi: ethers.ContractInterface; -}; - -export type Target = { - name: string; - source: string; - address: string; - link: string; - timestamp: string; - txn: string; - network: Network; -}; - -export type TargetsRecord = Record; - -export interface ContractDefinition { - name: string; - abi: ethers.ContractInterface; - address: string; -} - export type ContractsMap = { [name: string]: ethers.Contract; }; export type Config = { networkId?: NetworkId; - network?: Network; + network?: NetworkName; signer?: ethers.Signer; provider?: ethers.providers.Provider; useOvm?: boolean; @@ -169,8 +99,3 @@ export type Synth = { aggregator?: string; subclass?: string; }; - -export type User = { - name: string; - address: string; -}; diff --git a/packages/providers/src/index.ts b/packages/providers/src/index.ts index 7e35b8ba2..6dc82df51 100644 --- a/packages/providers/src/index.ts +++ b/packages/providers/src/index.ts @@ -6,7 +6,7 @@ import { } from '@synthetixio/optimism-networks'; import { ERRORS } from './constants'; import { ProviderConfig, SynthetixProvider, OvmProvider } from './types'; -import { NetworkId } from '@synthetixio/contracts-interface'; +import { NetworkIdByName } from '@synthetixio/contracts-interface'; const loadProvider = ({ networkId = 1, infuraId, provider }: ProviderConfig): SynthetixProvider => { if (!provider && !infuraId) throw new Error(ERRORS.noWeb3Provider); @@ -36,11 +36,10 @@ const getOptimismProvider = ({ */ const handleSwitchChain = async ( web3Provider: ethersProviders.Web3Provider, - network: NetworkId, isOVM: boolean ): Promise => { if (!web3Provider.provider?.request) return; - const newNetworkId = getCorrespondingNetwork(network, isOVM); + const newNetworkId = getCorrespondingNetwork(isOVM); const formattedChainId = utils.hexStripZeros(BigNumber.from(newNetworkId).toHexString()); // If request was successful, null is returned return web3Provider.provider.request({ @@ -49,14 +48,14 @@ const handleSwitchChain = async ( }); }; -const getCorrespondingNetwork = (networkId: NetworkId, isOVM: boolean) => { +const getCorrespondingNetwork = (isOVM: boolean) => { if (isOVM) { - return L2_TO_L1_NETWORK_MAPPER[networkId] || L2_TO_L1_NETWORK_MAPPER[NetworkId['Mainnet-Ovm']]; + return L2_TO_L1_NETWORK_MAPPER[NetworkIdByName['mainnet-ovm']]; } else { - return L1_TO_L2_NETWORK_MAPPER[networkId] || L1_TO_L2_NETWORK_MAPPER[NetworkId.Mainnet]; + return L1_TO_L2_NETWORK_MAPPER[NetworkIdByName.mainnet]; } }; -export { loadProvider, getOptimismProvider, handleSwitchChain, NetworkId }; +export { loadProvider, getOptimismProvider, handleSwitchChain }; export type { ProviderConfig, SynthetixProvider, OvmProvider }; export default loadProvider; diff --git a/packages/queries/__mocks__/@snapshot-labs/snapshot.js.ts b/packages/queries/__mocks__/@snapshot-labs/snapshot.js.ts index 5d254ddb3..bd995d030 100644 --- a/packages/queries/__mocks__/@snapshot-labs/snapshot.js.ts +++ b/packages/queries/__mocks__/@snapshot-labs/snapshot.js.ts @@ -1,4 +1,4 @@ -export = { +const mock = { utils: { getScores: () => [ { '0x0000000000000000000000000000000000000000': 15 }, @@ -8,3 +8,5 @@ export = { subgraphRequest: async () => ({ accounts: [] }), }, }; + +export default mock; diff --git a/packages/queries/__tests__/network.test.ts b/packages/queries/__tests__/network.test.ts index bf5cedf86..ba36f391f 100644 --- a/packages/queries/__tests__/network.test.ts +++ b/packages/queries/__tests__/network.test.ts @@ -1,4 +1,4 @@ -import { NetworkId } from '@synthetixio/contracts-interface'; +import { NetworkIdByName } from '@synthetixio/contracts-interface'; import { wei } from '@synthetixio/wei'; import { renderHook } from '@testing-library/react-hooks'; import { ethers, BigNumber } from 'ethers'; @@ -9,7 +9,7 @@ import { getFakeQueryContext, getWrapper } from '../testUtils'; describe('@synthetixio/queries network useEthGasPriceQuery', () => { test('Should query getGasPrice from provider if network is Optimism', async () => { const ctx = getFakeQueryContext(); - ctx.networkId = NetworkId['Mainnet-Ovm']; + ctx.networkId = NetworkIdByName['mainnet-ovm']; const wrapper = getWrapper(); // set to 0.015 gwei const defaultGasPrice = wei(0.015, 9).toBN(); @@ -31,7 +31,7 @@ describe('@synthetixio/queries network useEthGasPriceQuery', () => { test('Should query getGasPrice from provider if network is Kovan', async () => { const ctx = getFakeQueryContext(); - ctx.networkId = NetworkId['Kovan']; + ctx.networkId = NetworkIdByName.kovan; const wrapper = getWrapper(); // set to 0.015 gwei const defaultGasPrice = wei(0.015, 9).toBN(); @@ -53,7 +53,7 @@ describe('@synthetixio/queries network useEthGasPriceQuery', () => { test('Should throw an error if getGasPrice fails', async () => { const ctx = getFakeQueryContext(); - ctx.networkId = NetworkId['Mainnet-Ovm']; + ctx.networkId = NetworkIdByName['mainnet-ovm']; const wrapper = getWrapper({ defaultOptions: { queries: { @@ -82,7 +82,7 @@ describe('@synthetixio/queries network useEthGasPriceQuery', () => { test('Should use EIP1559 logic if network is Mainnet', async () => { const ctx = getFakeQueryContext(); - ctx.networkId = NetworkId['Mainnet']; + ctx.networkId = NetworkIdByName.mainnet; const wrapper = getWrapper(); // set to 100 gwei const defaultBaseFeePerGas = wei(100, 9).toBN(); diff --git a/packages/queries/__tests__/rates.test.ts b/packages/queries/__tests__/rates.test.ts index 52661a8b9..5367156a4 100644 --- a/packages/queries/__tests__/rates.test.ts +++ b/packages/queries/__tests__/rates.test.ts @@ -3,7 +3,7 @@ import { getFakeQueryContext, getWrapper } from '../testUtils'; import { renderHook } from '@testing-library/react-hooks'; -import { set, mapValues } from 'lodash'; +import { set } from 'lodash'; import { wei } from '@synthetixio/wei'; import { ethers } from 'ethers'; diff --git a/packages/queries/src/context.ts b/packages/queries/src/context.ts index 1b32ba1ab..6d0885218 100644 --- a/packages/queries/src/context.ts +++ b/packages/queries/src/context.ts @@ -1,5 +1,4 @@ import { ethers } from 'ethers'; - import { SynthetixJS, NetworkId } from '@synthetixio/contracts-interface'; export interface SubgraphEndpoints { diff --git a/packages/queries/src/contracts/CouncilDilution.ts b/packages/queries/src/contracts/CouncilDilution.ts index f2cdab89d..a15f27079 100644 --- a/packages/queries/src/contracts/CouncilDilution.ts +++ b/packages/queries/src/contracts/CouncilDilution.ts @@ -1,4 +1,4 @@ -export = { +const Contract = { address: '0x834ef1f87120fbd01e419f279bcfc0ded360d5aa', abi: [ { @@ -337,3 +337,4 @@ export = { }, ], }; +export default Contract; diff --git a/packages/queries/src/mutations/useEVMTxn.ts b/packages/queries/src/mutations/useEVMTxn.ts index eb154bfe4..c096b2eac 100644 --- a/packages/queries/src/mutations/useEVMTxn.ts +++ b/packages/queries/src/mutations/useEVMTxn.ts @@ -8,7 +8,7 @@ import { QueryContext } from '../context'; import clone from 'lodash/clone'; import omit from 'lodash/omit'; import { isString } from 'lodash'; -import { NetworkId } from '@synthetixio/contracts-interface'; +import { NetworkIdByName } from '@synthetixio/contracts-interface'; import optimismOracleContract from '../contracts/OptimismGasPriceOracle'; type TransactionStatus = 'unsent' | 'prompting' | 'pending' | 'confirmed' | 'failed'; @@ -45,7 +45,8 @@ const useEVMTxn = ( const getOptimismLayerOneFees = async () => { if (!txn || !ctx.provider) return null; const isNotOvm = - ctx.networkId !== NetworkId['Mainnet-Ovm'] && ctx.networkId !== NetworkId['Kovan-Ovm']; + ctx.networkId !== NetworkIdByName['mainnet-ovm'] && + ctx.networkId !== NetworkIdByName['kovan-ovm']; if (isNotOvm) { return null; } diff --git a/packages/queries/src/queries/network/useEthGasPriceQuery.ts b/packages/queries/src/queries/network/useEthGasPriceQuery.ts index 70405f8da..7a7462e46 100644 --- a/packages/queries/src/queries/network/useEthGasPriceQuery.ts +++ b/packages/queries/src/queries/network/useEthGasPriceQuery.ts @@ -3,7 +3,7 @@ import { QueryContext } from '../../context'; import { GasPrices } from '../../types'; import { wei } from '@synthetixio/wei'; -import { NetworkId } from '@synthetixio/contracts-interface'; +import { NetworkIdByName } from '@synthetixio/contracts-interface'; import { ethers } from 'ethers'; const MULTIPLIER = wei(2); @@ -35,7 +35,7 @@ const useEthGasPriceQuery = (ctx: QueryContext, options?: UseQueryOptions { try { // If network is Mainnet then we use EIP1559 - if (ctx.networkId === NetworkId.Mainnet) { + if (ctx.networkId === NetworkIdByName.mainnet) { const block = await ctx?.provider?.getBlock('latest'); if (block?.baseFeePerGas) { return { diff --git a/packages/queries/src/queries/ovm-bridge/useGetBridgeDataQuery.ts b/packages/queries/src/queries/ovm-bridge/useGetBridgeDataQuery.ts index 1b4a8b229..286b058e9 100644 --- a/packages/queries/src/queries/ovm-bridge/useGetBridgeDataQuery.ts +++ b/packages/queries/src/queries/ovm-bridge/useGetBridgeDataQuery.ts @@ -25,15 +25,15 @@ const useGetBridgeDataQuery = ( useEffect(() => { if (ctx.networkId && ctx.provider) { - const isFromL1 = !!L1_TO_L2_NETWORK_MAPPER[ctx.networkId?.valueOf()]; - const isFromL2 = !!OPTIMISM_NETWORKS[ctx.networkId!]; + const isFromL1 = !!L1_TO_L2_NETWORK_MAPPER[ctx.networkId]; + const isFromL2 = !!OPTIMISM_NETWORKS[ctx.networkId]; if (isFromL1 || isFromL2) { const l1provider = isFromL2 ? loadProvider({ infuraId }) : ctx.provider; const l2provider = isFromL2 ? ctx.provider : ctx.networkId - ? getOptimismProvider({ networkId: L1_TO_L2_NETWORK_MAPPER[ctx.networkId.valueOf()] }) + ? getOptimismProvider({ networkId: L1_TO_L2_NETWORK_MAPPER[ctx.networkId] }) : null; const watcher = optimismMessengerWatcher({ @@ -42,8 +42,8 @@ const useGetBridgeDataQuery = ( // @ts-ignore layerTwoProvider: l2provider, layerTwoNetworkId: isFromL2 - ? ctx.networkId - : L1_TO_L2_NETWORK_MAPPER[ctx.networkId.valueOf()], + ? parseInt(ctx.networkId) + : L1_TO_L2_NETWORK_MAPPER[ctx.networkId], }); setWatcher(watcher); diff --git a/packages/queries/src/queries/synths/useSynthsTotalSupplyQuery.ts b/packages/queries/src/queries/synths/useSynthsTotalSupplyQuery.ts index ebf37d71b..8eaa32191 100644 --- a/packages/queries/src/queries/synths/useSynthsTotalSupplyQuery.ts +++ b/packages/queries/src/queries/synths/useSynthsTotalSupplyQuery.ts @@ -1,7 +1,7 @@ import { ethers } from 'ethers'; import { useQuery, UseQueryOptions } from 'react-query'; -import { NetworkId, Synths } from '@synthetixio/contracts-interface'; +import { NetworkIdByName, Synths } from '@synthetixio/contracts-interface'; import { wei } from '@synthetixio/wei'; import { QueryContext } from '../../context'; @@ -27,7 +27,8 @@ const useSynthsTotalSupplyQuery = ( ); const isL2 = - NetworkId['Mainnet-Ovm'] === ctx.networkId! || NetworkId['Kovan-Ovm'] === ctx.networkId!; + NetworkIdByName['mainnet-ovm'] === ctx.networkId! || + NetworkIdByName['kovan-ovm'] === ctx.networkId!; const [ synthTotalSupplies, diff --git a/packages/queries/testUtils.ts b/packages/queries/testUtils.ts index 31aacaf22..9a4e10b2a 100644 --- a/packages/queries/testUtils.ts +++ b/packages/queries/testUtils.ts @@ -2,7 +2,7 @@ import React, { ReactNode } from 'react'; import { QueryClient, QueryClientProvider } from 'react-query'; import { QueryContext } from './src/context'; -import { NetworkId, SynthetixJS } from '@synthetixio/contracts-interface'; +import { NetworkIdByName, SynthetixJS, NetworkId } from '@synthetixio/contracts-interface'; import { ethers } from 'ethers'; // simple query client wrapper which allows for testing of a @@ -14,7 +14,7 @@ export function getWrapper(config?: any) { // builds an incomplete query context which should generally pass // blanket `enabled` sections. just mock the functions/data you need -export function getFakeQueryContext(networkId: NetworkId = NetworkId.Mainnet): QueryContext { +export function getFakeQueryContext(networkId: NetworkId = NetworkIdByName.mainnet): QueryContext { return { networkId, subgraphEndpoints: { exchanger: '', issuance: '', exchanges: '', subgraph: '' },