mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
94 lines
2.9 KiB
TypeScript
94 lines
2.9 KiB
TypeScript
import Config from '../models/Config'
|
|
import { Logger } from '../lib'
|
|
import fs from 'fs'
|
|
|
|
export declare type ConfigHelperNetworkName =
|
|
| 'mainnet'
|
|
| 'rinkeby'
|
|
| 'development'
|
|
| string
|
|
|
|
export declare type ConfigHelperNetworkId = 1 | 4 | number
|
|
|
|
export interface ConfigHelperConfig extends Config {
|
|
chainId: ConfigHelperNetworkId
|
|
network: ConfigHelperNetworkName
|
|
}
|
|
|
|
const configs: ConfigHelperConfig[] = [
|
|
{
|
|
chainId: null,
|
|
network: 'development',
|
|
nodeUri: 'http://localhost:8545',
|
|
factoryAddress: null,
|
|
metadataStoreUri: 'http://127.0.0.1:5000',
|
|
providerUri: 'http://127.0.0.1:8030',
|
|
poolFactoryAddress: null,
|
|
fixedRateExchangeAddress: null,
|
|
DDOContractAddress: null
|
|
},
|
|
{
|
|
chainId: 4,
|
|
network: 'rinkeby',
|
|
nodeUri: 'https://rinkeby.infura.io/v3',
|
|
factoryAddress: '0x3ECd1429101f93149D799Ef257C07a2B1Dc30897',
|
|
oceanTokenAddress: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07',
|
|
metadataStoreUri: 'https://aquarius.rinkeby.v3.dev-ocean.com',
|
|
providerUri: 'https://provider.rinkeby.v3.dev-ocean.com',
|
|
poolFactoryAddress: '0x9B90A1358fbeEC1C4bB1DA7D4E85C708f87556Ec',
|
|
fixedRateExchangeAddress: '0x991c08bD00761A299d3126a81a985329096896D4',
|
|
DDOContractAddress: '0xEfA25E39192b3175d451D79C1c0a41Fa3C32c87d'
|
|
},
|
|
{
|
|
chainId: 1,
|
|
network: 'mainnet',
|
|
nodeUri: 'https://mainnet.infura.io/v3',
|
|
factoryAddress: '0x1234',
|
|
oceanTokenAddress: '0x7AFeBBB46fDb47ed17b22ed075Cde2447694fB9e',
|
|
metadataStoreUri: null,
|
|
providerUri: null,
|
|
poolFactoryAddress: null,
|
|
fixedRateExchangeAddress: null,
|
|
DDOContractAddress: null
|
|
}
|
|
]
|
|
|
|
export class ConfigHelper {
|
|
/* Load config from env ADDRESS_FILE (generated by ocean-contracts) */
|
|
public loadAddressesFromEnv() {
|
|
try {
|
|
const data = JSON.parse(fs.readFileSync(process.env.ADDRESS_FILE, 'utf8'))
|
|
if (data) {
|
|
if (data.ganache) {
|
|
if (data.ganache.DTFactory) configs[0].factoryAddress = data.ganache.DTFactory
|
|
if (data.ganache.BFactory) configs[0].poolFactoryAddress = data.ganache.BFactory
|
|
if (data.ganache.FixedRateExchange)
|
|
configs[0].fixedRateExchangeAddress = data.ganache.FixedRateExchange
|
|
if (data.ganache.DDO) configs[0].DDOContractAddress = data.ganache.DDO
|
|
}
|
|
}
|
|
if (process.env.AQUARIUS_URI) configs[0].metadataStoreUri = process.env.AQUARIUS_URI
|
|
} catch (e) {}
|
|
}
|
|
|
|
public getConfig(
|
|
network: ConfigHelperNetworkName | ConfigHelperNetworkId,
|
|
infuraProjectId?: string
|
|
): Config {
|
|
if (network === 'development') this.loadAddressesFromEnv()
|
|
const filterBy = typeof network === 'string' ? 'network' : 'chainId'
|
|
const config = configs.find((c) => c[filterBy] === network)
|
|
|
|
if (!config) {
|
|
Logger.error(`No config found for given network '${network}'`)
|
|
return null
|
|
}
|
|
|
|
const nodeUri = infuraProjectId
|
|
? `${config.nodeUri}/${infuraProjectId}`
|
|
: config.nodeUri
|
|
|
|
return { ...config, nodeUri }
|
|
}
|
|
}
|