2021-03-17 11:44:26 +01:00
|
|
|
import {
|
2021-04-13 15:13:55 +02:00
|
|
|
Account,
|
|
|
|
Logger,
|
|
|
|
Ocean,
|
2021-03-17 11:44:26 +01:00
|
|
|
ConfigHelper,
|
|
|
|
ConfigHelperConfig,
|
|
|
|
ConfigHelperNetworkId,
|
|
|
|
ConfigHelperNetworkName
|
2021-04-13 15:13:55 +02:00
|
|
|
} from '@oceanprotocol/lib'
|
|
|
|
import contractAddresses from '@oceanprotocol/contracts/artifacts/address.json'
|
|
|
|
|
2021-03-17 11:44:26 +01:00
|
|
|
import { UserBalance } from '../@types/TokenBalance'
|
|
|
|
|
|
|
|
export function getOceanConfig(
|
|
|
|
network: ConfigHelperNetworkName | ConfigHelperNetworkId
|
2021-03-22 12:48:28 +01:00
|
|
|
): ConfigHelperConfig {
|
2021-05-28 14:47:47 +02:00
|
|
|
const config = new ConfigHelper().getConfig(
|
2021-03-17 11:44:26 +01:00
|
|
|
network,
|
2021-04-29 14:48:57 +02:00
|
|
|
network === 'polygon' ||
|
|
|
|
network === 137 ||
|
|
|
|
network === 'moonbeamalpha' ||
|
|
|
|
network === 1287
|
2021-04-13 10:57:59 +02:00
|
|
|
? undefined
|
|
|
|
: process.env.GATSBY_INFURA_PROJECT_ID
|
2021-05-28 14:47:47 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
return {
|
|
|
|
...config,
|
|
|
|
// TODO: remove faking one Aquarius for all networks
|
|
|
|
metadataCacheUri: 'https://aquarius.mainnet.oceanprotocol.com'
|
|
|
|
} as ConfigHelperConfig
|
2021-03-17 11:44:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getDevelopmentConfig(): Partial<ConfigHelperConfig> {
|
|
|
|
return {
|
|
|
|
factoryAddress: contractAddresses.development?.DTFactory,
|
|
|
|
poolFactoryAddress: contractAddresses.development?.BFactory,
|
|
|
|
fixedRateExchangeAddress: contractAddresses.development?.FixedRateExchange,
|
|
|
|
metadataContractAddress: contractAddresses.development?.Metadata,
|
|
|
|
oceanTokenAddress: contractAddresses.development?.Ocean,
|
|
|
|
// There is no subgraph in barge so we hardcode the Rinkeby one for now
|
|
|
|
subgraphUri: 'https://subgraph.rinkeby.oceanprotocol.com'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getUserInfo(
|
|
|
|
ocean: Ocean
|
|
|
|
): Promise<{ account: Account; balance: UserBalance }> {
|
|
|
|
if (!ocean) return { account: null, balance: { eth: '0', ocean: '0' } }
|
|
|
|
|
|
|
|
const account = (await ocean.accounts.list())[0]
|
|
|
|
Logger.log('[ocean] Account: ', account)
|
|
|
|
|
|
|
|
const balance = {
|
|
|
|
eth: await account.getEtherBalance(),
|
|
|
|
ocean: await account.getOceanBalance()
|
|
|
|
}
|
|
|
|
Logger.log('[ocean] Balance: ', JSON.stringify(balance))
|
|
|
|
|
|
|
|
return { account, balance }
|
|
|
|
}
|