From f1d990310d8ea095a4bc0b317033210b552da82c Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Mon, 1 Aug 2022 16:57:55 -0700 Subject: [PATCH] Remove dynamic eth-contract imports --- libs/rollup.config.js | 16 ++---- libs/src/AudiusLibs.ts | 15 ++++++ libs/src/legacy.ts | 1 + .../src/services/ethContracts/EthContracts.ts | 52 ++++++++++--------- libs/src/utils/importContractABI.d.ts | 8 --- libs/src/utils/importContractABI.js | 11 ---- libs/src/utils/index.ts | 1 - libs/src/utils/utils.ts | 11 ++-- 8 files changed, 53 insertions(+), 62 deletions(-) delete mode 100644 libs/src/utils/importContractABI.d.ts delete mode 100644 libs/src/utils/importContractABI.js diff --git a/libs/rollup.config.js b/libs/rollup.config.js index 5a6ac716c18..7b9d4c84922 100644 --- a/libs/rollup.config.js +++ b/libs/rollup.config.js @@ -32,10 +32,7 @@ const commonConfig = { plugins: [ resolve({ extensions, preferBuiltins: true }), pluginTypescript, - commonjs({ - extensions, - dynamicRequireTargets: ['src/eth-contracts/ABIs/*.json'] - }), + commonjs({ extensions }), babel({ babelHelpers: 'bundled', extensions }), json() ], @@ -64,8 +61,7 @@ const browserConfig = { pluginTypescript, commonjs({ extensions, - transformMixedEsModules: true, - dynamicRequireTargets: ['src/eth-contracts/ABIs/*.json'] + transformMixedEsModules: true }), alias({ entries: [{ find: 'stream', replacement: 'stream-browserify' }] @@ -84,8 +80,7 @@ const browserDistFileConfig = { pluginTypescript, commonjs({ extensions, - transformMixedEsModules: true, - dynamicRequireTargets: ['src/eth-contracts/ABIs/*.json'] + transformMixedEsModules: true }), alias({ entries: [{ find: 'stream', replacement: 'stream-browserify' }] @@ -106,10 +101,7 @@ const browserLegacyConfig = { ignore(['web3', 'graceful-fs', 'node-localstorage']), resolve({ extensions, preferBuiltins: true }), pluginTypescript, - commonjs({ - extensions, - dynamicRequireTargets: ['src/eth-contracts/ABIs/*.json'] - }), + commonjs({ extensions }), alias({ entries: [{ find: 'stream', replacement: 'stream-browserify' }] }), diff --git a/libs/src/AudiusLibs.ts b/libs/src/AudiusLibs.ts index af227139f3b..1be0350abdb 100644 --- a/libs/src/AudiusLibs.ts +++ b/libs/src/AudiusLibs.ts @@ -468,11 +468,13 @@ export class AudiusLibs { /** Captcha */ if (this.captchaConfig) { + console.log('captch') this.captcha = new Captcha(this.captchaConfig) } /** Identity Service */ if (this.identityServiceConfig) { + console.log('id serve') this.identityService = new IdentityService({ identityServiceEndpoint: this.identityServiceConfig.url, captcha: this.captcha @@ -491,6 +493,7 @@ export class AudiusLibs { /** Web3 Managers */ if (this.ethWeb3Config && this.identityService && this.hedgehog) { + console.log('eth web3 man') this.ethWeb3Manager = new EthWeb3Manager({ web3Config: this.ethWeb3Config, identityService: this.identityService, @@ -498,6 +501,7 @@ export class AudiusLibs { }) } if (this.web3Config && this.identityService && this.hedgehog) { + console.log('web 3 man') this.web3Manager = new Web3Manager({ web3Config: this.web3Config, identityService: this.identityService, @@ -506,10 +510,12 @@ export class AudiusLibs { }) await this.web3Manager.init() if (this.identityService) { + console.log('web 3 man id serv') this.identityService.setWeb3Manager(this.web3Manager) } } if (this.solanaWeb3Config && this.identityService && this.web3Manager) { + console.log('sol web3 man') this.solanaWeb3Manager = new SolanaWeb3Manager( this.solanaWeb3Config, this.identityService, @@ -522,6 +528,7 @@ export class AudiusLibs { this.solanaAudiusDataConfig && this.web3Manager ) { + console.log('aud data') this.solanaAudiusData = new SolanaAudiusData( this.solanaAudiusDataConfig, this.solanaWeb3Manager, @@ -540,6 +547,8 @@ export class AudiusLibs { wormholeContractAddress } = this.ethWeb3Config + console.log('eth cons') + this.ethContracts = new EthContracts({ ethWeb3Manager: this.ethWeb3Manager, tokenContractAddress: tokenAddress, @@ -554,6 +563,7 @@ export class AudiusLibs { contractsToInit.push(this.ethContracts.init()) } if (this.web3Manager && this.web3Config) { + console.log('contractions') this.contracts = new AudiusContracts( this.web3Manager, this.web3Config.registryAddress, @@ -571,6 +581,7 @@ export class AudiusLibs { this.identityService && this.solanaWeb3Manager ) { + console.log('wormy!') this.wormholeClient = new Wormhole( this.hedgehog, this.ethWeb3Manager, @@ -588,6 +599,7 @@ export class AudiusLibs { /** Discovery Provider */ if (this.discoveryProviderConfig && this.ethContracts && this.web3Manager) { + console.log('discprov') this.discoveryProvider = new DiscoveryProvider({ userStateManager: this.userStateManager, ethContracts: this.ethContracts, @@ -606,6 +618,7 @@ export class AudiusLibs { this.creatorNodeConfig.fallbackUrl : this.creatorNodeConfig.fallbackUrl + console.log('creator node') this.creatorNode = new CreatorNode( this.web3Manager, creatorNodeEndpoint, @@ -623,6 +636,7 @@ export class AudiusLibs { /** Comstock */ if (this.comstockConfig) { + console.log('comstock!') this.comstock = new Comstock(this.comstockConfig.url) } @@ -643,6 +657,7 @@ export class AudiusLibs { this.comstock && this.captcha ) { + console.log('getting into services!') // Initialize apis const services = [ this.userStateManager, diff --git a/libs/src/legacy.ts b/libs/src/legacy.ts index c8b098cb1fe..1c25ddcc262 100644 --- a/libs/src/legacy.ts +++ b/libs/src/legacy.ts @@ -3,4 +3,5 @@ export { sdk } from './sdk' /** * @deprecated Please migrate to using `sdk` when possible */ +export * from './AudiusLibs' export { AudiusLibs as libs } from './AudiusLibs' diff --git a/libs/src/services/ethContracts/EthContracts.ts b/libs/src/services/ethContracts/EthContracts.ts index 100f3153bc0..e3c8ee3e0c9 100644 --- a/libs/src/services/ethContracts/EthContracts.ts +++ b/libs/src/services/ethContracts/EthContracts.ts @@ -11,34 +11,24 @@ import { ClaimDistributionClient } from './ClaimDistributionClient' import { WormholeClient } from './WormholeClient' import { EthRewardsManagerClient } from './EthRewardsManagerClient' import { TrustedNotifierManagerClient } from './TrustedNotifierManagerClient' -import { Logger, Utils } from '../../utils' +import type { Logger } from '../../utils' import type { EthWeb3Manager } from '../ethWeb3Manager' import type { ContractClient } from '../contracts/ContractClient' -const AudiusTokenABI = Utils.importEthContractABI('AudiusToken.json').abi -const RegistryABI = Utils.importEthContractABI('Registry.json').abi -const GovernanceABI = Utils.importEthContractABI('Governance.json').abi -const ServiceTypeManagerABI = Utils.importEthContractABI( - 'ServiceTypeManager.json' -).abi -const ServiceProviderFactoryABI = Utils.importEthContractABI( - 'ServiceProviderFactory.json' -).abi -const StakingABI = Utils.importEthContractABI('Staking.json').abi -const DelegateManagerABI = Utils.importEthContractABI( - 'DelegateManagerV2.json' -).abi -const ClaimsManagerABI = Utils.importEthContractABI('ClaimsManager.json').abi -const ClaimDistributionABI = Utils.importEthContractABI( - 'AudiusClaimDistributor.json' -).abi -const WormholeClientABI = Utils.importEthContractABI('WormholeClient.json').abi -const EthRewardsManagerABI = Utils.importEthContractABI( - 'EthRewardsManager.json' -).abi -const TrustedNotifierManagerABI = Utils.importEthContractABI( - 'TrustedNotifierManager.json' -).abi +import { abi as AudiusTokenABI } from '../../eth-contracts/ABIs/AudiusToken.json' +import { abi as RegistryABI } from '../../eth-contracts/ABIs/Registry.json' +import { abi as GovernanceABI } from '../../eth-contracts/ABIs/Governance.json' +import { abi as ServiceTypeManagerABI } from '../../eth-contracts/ABIs/ServiceTypeManager.json' +import { abi as ServiceProviderFactoryABI } from '../../eth-contracts/ABIs/ServiceProviderFactory.json' +import { abi as StakingABI } from '../../eth-contracts/ABIs/Staking.json' +import { abi as DelegateManagerABI } from '../../eth-contracts/ABIs/DelegateManagerV2.json' +import { abi as ClaimsManagerABI } from '../../eth-contracts/ABIs/ClaimsManager.json' +import { abi as ClaimDistributionABI } from '../../eth-contracts/ABIs/AudiusClaimDistributor.json' +import { abi as WormholeClientABI } from '../../eth-contracts/ABIs/WormholeClient.json' +import { abi as EthRewardsManagerABI } from '../../eth-contracts/ABIs/EthRewardsManager.json' +import { abi as TrustedNotifierManagerABI } from '../../eth-contracts/ABIs/TrustedNotifierManager.json' + +console.log('AudiusTokenABI!', AudiusTokenABI) const GovernanceRegistryKey = 'Governance' const ServiceTypeManagerProxyKey = 'ServiceTypeManagerProxy' @@ -118,11 +108,13 @@ export class EthContracts { this.AudiusTokenClient = new AudiusTokenClient( this.ethWeb3Manager, + // @ts-ignore AudiusTokenABI, this.tokenContractAddress ) this.RegistryClient = new RegistryClient( this.ethWeb3Manager, + // @ts-ignore RegistryABI, this.registryAddress ) @@ -131,6 +123,7 @@ export class EthContracts { this.StakingProxyClient = new StakingProxyClient( this.ethWeb3Manager, + // @ts-ignore StakingABI, StakingProxyKey, this.getRegistryAddressForContract, @@ -140,6 +133,7 @@ export class EthContracts { this.GovernanceClient = new GovernanceClient( this.ethWeb3Manager, + // @ts-ignore GovernanceABI, GovernanceRegistryKey, this.getRegistryAddressForContract, @@ -150,6 +144,7 @@ export class EthContracts { this.ClaimsManagerClient = new ClaimsManagerClient( this.ethWeb3Manager, + // @ts-ignore ClaimsManagerABI, ClaimsManagerProxyKey, this.getRegistryAddressForContract, @@ -158,6 +153,7 @@ export class EthContracts { this.EthRewardsManagerClient = new EthRewardsManagerClient( this.ethWeb3Manager, + // @ts-ignore EthRewardsManagerABI, EthRewardsManagerProxyKey, this.getRegistryAddressForContract, @@ -166,6 +162,7 @@ export class EthContracts { this.ServiceTypeManagerClient = new ServiceTypeManagerClient( this.ethWeb3Manager, + // @ts-ignore ServiceTypeManagerABI, ServiceTypeManagerProxyKey, this.getRegistryAddressForContract, @@ -175,6 +172,7 @@ export class EthContracts { this.ServiceProviderFactoryClient = new ServiceProviderFactoryClient( this.ethWeb3Manager, + // @ts-ignore ServiceProviderFactoryABI, ServiceProviderFactoryRegistryKey, this.getRegistryAddressForContract, @@ -187,6 +185,7 @@ export class EthContracts { this.DelegateManagerClient = new DelegateManagerClient( this.ethWeb3Manager, + // @ts-ignore DelegateManagerABI, DelegateManagerRegistryKey, this.getRegistryAddressForContract, @@ -199,6 +198,7 @@ export class EthContracts { if (this.claimDistributionContractAddress) { this.ClaimDistributionClient = new ClaimDistributionClient( this.ethWeb3Manager, + // @ts-ignore ClaimDistributionABI, ClaimDistributionRegistryKey, this.getRegistryAddressForContract, @@ -209,6 +209,7 @@ export class EthContracts { this.WormholeClient = new WormholeClient( this.ethWeb3Manager, + // @ts-ignore WormholeClientABI, this.wormholeContractAddress, this.AudiusTokenClient @@ -216,6 +217,7 @@ export class EthContracts { this.TrustedNotifierManagerClient = new TrustedNotifierManagerClient( this.ethWeb3Manager, + // @ts-ignore TrustedNotifierManagerABI, TrustedNotifierManagerProxyKey, this.getRegistryAddressForContract, diff --git a/libs/src/utils/importContractABI.d.ts b/libs/src/utils/importContractABI.d.ts deleted file mode 100644 index db61cd8b782..00000000000 --- a/libs/src/utils/importContractABI.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { AbiItem } from 'web3-utils' - -export type ContractABI = { - abi: AbiItem[] - contractName: string -} - -export const importEthContractABIs: (pathStr: string) => ContractABI diff --git a/libs/src/utils/importContractABI.js b/libs/src/utils/importContractABI.js deleted file mode 100644 index 61d1511184b..00000000000 --- a/libs/src/utils/importContractABI.js +++ /dev/null @@ -1,11 +0,0 @@ -const importEthContractABIs = (pathStr) => { - // need to specify part of path here because of https://github.com/webpack/webpack/issues/4921#issuecomment-357147299 - const importFile = require(`../eth-contracts/ABIs/${pathStr}`) - - if (importFile) return importFile - else throw new Error(`Eth contract ABI not found ${pathStr}`) -} - -module.exports = { - importEthContractABIs -} diff --git a/libs/src/utils/index.ts b/libs/src/utils/index.ts index ad505169bbb..3ec84cbfdeb 100644 --- a/libs/src/utils/index.ts +++ b/libs/src/utils/index.ts @@ -7,5 +7,4 @@ export * from './promiseFight' export * from './signatures' export * from './uuid' export * from './network' -export * from './importContractABI' export * from './types' diff --git a/libs/src/utils/utils.ts b/libs/src/utils/utils.ts index 486d22b51d6..2d63568e42c 100644 --- a/libs/src/utils/utils.ts +++ b/libs/src/utils/utils.ts @@ -4,9 +4,9 @@ import axios, { AxiosResponse } from 'axios' import Hashids from 'hashids' import { MultiProvider } from './multiProvider' import { uuid } from './uuid' -import { importEthContractABIs } from './importContractABI' import { fileHasher } from './fileHasher' import type { ImageHasher, NonImageHasher, HashedImage } from './fileHasher' +import type { AbiItem } from 'web3-utils' // Hashids @@ -18,12 +18,13 @@ const ZeroAddress = '0x0000000000000000000000000000000000000000' export type { ImageHasher, NonImageHasher, HashedImage } +export type ContractABI = { + abi: AbiItem[] + contractName: string +} + // eslint-disable-next-line @typescript-eslint/no-extraneous-class -- this should just be esm export class Utils { - static importEthContractABI(pathStr: string) { - return importEthContractABIs(pathStr) - } - static utf8ToHex(utf8Str: string) { return Web3.utils.utf8ToHex(utf8Str) }