Skip to content

Commit

Permalink
Remove dynamic eth-contract imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers committed Aug 1, 2022
1 parent 5388190 commit f1d9903
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 62 deletions.
16 changes: 4 additions & 12 deletions libs/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
],
Expand Down Expand Up @@ -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' }]
Expand All @@ -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' }]
Expand All @@ -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' }]
}),
Expand Down
15 changes: 15 additions & 0 deletions libs/src/AudiusLibs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -491,13 +493,15 @@ 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,
hedgehog: this.hedgehog
})
}
if (this.web3Config && this.identityService && this.hedgehog) {
console.log('web 3 man')
this.web3Manager = new Web3Manager({
web3Config: this.web3Config,
identityService: this.identityService,
Expand All @@ -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,
Expand All @@ -522,6 +528,7 @@ export class AudiusLibs {
this.solanaAudiusDataConfig &&
this.web3Manager
) {
console.log('aud data')
this.solanaAudiusData = new SolanaAudiusData(
this.solanaAudiusDataConfig,
this.solanaWeb3Manager,
Expand All @@ -540,6 +547,8 @@ export class AudiusLibs {
wormholeContractAddress
} = this.ethWeb3Config

console.log('eth cons')

this.ethContracts = new EthContracts({
ethWeb3Manager: this.ethWeb3Manager,
tokenContractAddress: tokenAddress,
Expand All @@ -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,
Expand All @@ -571,6 +581,7 @@ export class AudiusLibs {
this.identityService &&
this.solanaWeb3Manager
) {
console.log('wormy!')
this.wormholeClient = new Wormhole(
this.hedgehog,
this.ethWeb3Manager,
Expand All @@ -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,
Expand All @@ -606,6 +618,7 @@ export class AudiusLibs {
this.creatorNodeConfig.fallbackUrl
: this.creatorNodeConfig.fallbackUrl

console.log('creator node')
this.creatorNode = new CreatorNode(
this.web3Manager,
creatorNodeEndpoint,
Expand All @@ -623,6 +636,7 @@ export class AudiusLibs {

/** Comstock */
if (this.comstockConfig) {
console.log('comstock!')
this.comstock = new Comstock(this.comstockConfig.url)
}

Expand All @@ -643,6 +657,7 @@ export class AudiusLibs {
this.comstock &&
this.captcha
) {
console.log('getting into services!')
// Initialize apis
const services = [
this.userStateManager,
Expand Down
1 change: 1 addition & 0 deletions libs/src/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
52 changes: 27 additions & 25 deletions libs/src/services/ethContracts/EthContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
)
Expand All @@ -131,6 +123,7 @@ export class EthContracts {

this.StakingProxyClient = new StakingProxyClient(
this.ethWeb3Manager,
// @ts-ignore
StakingABI,
StakingProxyKey,
this.getRegistryAddressForContract,
Expand All @@ -140,6 +133,7 @@ export class EthContracts {

this.GovernanceClient = new GovernanceClient(
this.ethWeb3Manager,
// @ts-ignore
GovernanceABI,
GovernanceRegistryKey,
this.getRegistryAddressForContract,
Expand All @@ -150,6 +144,7 @@ export class EthContracts {

this.ClaimsManagerClient = new ClaimsManagerClient(
this.ethWeb3Manager,
// @ts-ignore
ClaimsManagerABI,
ClaimsManagerProxyKey,
this.getRegistryAddressForContract,
Expand All @@ -158,6 +153,7 @@ export class EthContracts {

this.EthRewardsManagerClient = new EthRewardsManagerClient(
this.ethWeb3Manager,
// @ts-ignore
EthRewardsManagerABI,
EthRewardsManagerProxyKey,
this.getRegistryAddressForContract,
Expand All @@ -166,6 +162,7 @@ export class EthContracts {

this.ServiceTypeManagerClient = new ServiceTypeManagerClient(
this.ethWeb3Manager,
// @ts-ignore
ServiceTypeManagerABI,
ServiceTypeManagerProxyKey,
this.getRegistryAddressForContract,
Expand All @@ -175,6 +172,7 @@ export class EthContracts {

this.ServiceProviderFactoryClient = new ServiceProviderFactoryClient(
this.ethWeb3Manager,
// @ts-ignore
ServiceProviderFactoryABI,
ServiceProviderFactoryRegistryKey,
this.getRegistryAddressForContract,
Expand All @@ -187,6 +185,7 @@ export class EthContracts {

this.DelegateManagerClient = new DelegateManagerClient(
this.ethWeb3Manager,
// @ts-ignore
DelegateManagerABI,
DelegateManagerRegistryKey,
this.getRegistryAddressForContract,
Expand All @@ -199,6 +198,7 @@ export class EthContracts {
if (this.claimDistributionContractAddress) {
this.ClaimDistributionClient = new ClaimDistributionClient(
this.ethWeb3Manager,
// @ts-ignore
ClaimDistributionABI,
ClaimDistributionRegistryKey,
this.getRegistryAddressForContract,
Expand All @@ -209,13 +209,15 @@ export class EthContracts {

this.WormholeClient = new WormholeClient(
this.ethWeb3Manager,
// @ts-ignore
WormholeClientABI,
this.wormholeContractAddress,
this.AudiusTokenClient
)

this.TrustedNotifierManagerClient = new TrustedNotifierManagerClient(
this.ethWeb3Manager,
// @ts-ignore
TrustedNotifierManagerABI,
TrustedNotifierManagerProxyKey,
this.getRegistryAddressForContract,
Expand Down
8 changes: 0 additions & 8 deletions libs/src/utils/importContractABI.d.ts

This file was deleted.

11 changes: 0 additions & 11 deletions libs/src/utils/importContractABI.js

This file was deleted.

1 change: 0 additions & 1 deletion libs/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export * from './promiseFight'
export * from './signatures'
export * from './uuid'
export * from './network'
export * from './importContractABI'
export * from './types'
11 changes: 6 additions & 5 deletions libs/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
Expand Down

0 comments on commit f1d9903

Please sign in to comment.