mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge branch 'main' into fix/logger
This commit is contained in:
commit
57b5f83cbc
@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d
|
||||
|
||||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||
|
||||
#### [v0.7.1](https://github.com/oceanprotocol/ocean.js/compare/v0.7.0...v0.7.1)
|
||||
|
||||
- BestPrice type tweak [`47d3282`](https://github.com/oceanprotocol/ocean.js/commit/47d328219746dd4fb05e364e24492eef0a0c5907)
|
||||
|
||||
#### [v0.7.0](https://github.com/oceanprotocol/ocean.js/compare/v0.6.7...v0.7.0)
|
||||
|
||||
> 21 October 2020
|
||||
|
||||
- make create methods subscribable [`#389`](https://github.com/oceanprotocol/ocean.js/pull/389)
|
||||
- Bump @types/node from 14.11.10 to 14.14.0 [`#383`](https://github.com/oceanprotocol/ocean.js/pull/383)
|
||||
- make pool.create subscribable [`dec9c57`](https://github.com/oceanprotocol/ocean.js/commit/dec9c57c94f777201355c1356c881989002931c1)
|
||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@oceanprotocol/lib",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@oceanprotocol/lib",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.1",
|
||||
"description": "JavaScript client library for Ocean Protocol",
|
||||
"main": "./dist/node/lib.js",
|
||||
"typings": "./dist/node/lib.d.ts",
|
||||
|
@ -1,5 +1,5 @@
|
||||
export interface BestPrice {
|
||||
type: 'pool' | 'exchange'
|
||||
type: 'pool' | 'exchange' | ''
|
||||
address: string
|
||||
value: number
|
||||
ocean?: number
|
||||
|
@ -2,7 +2,7 @@ import Config from '../models/Config'
|
||||
import { Logger } from '../lib'
|
||||
import fs from 'fs'
|
||||
import { homedir } from 'os'
|
||||
|
||||
import * as DefaultContractsAddresses from '@oceanprotocol/contracts/artifacts/address.json'
|
||||
export declare type ConfigHelperNetworkName =
|
||||
| 'mainnet'
|
||||
| 'rinkeby'
|
||||
@ -21,9 +21,10 @@ const configs: ConfigHelperConfig[] = [
|
||||
networkId: null,
|
||||
network: 'unknown',
|
||||
nodeUri: 'http://localhost:8545',
|
||||
factoryAddress: null,
|
||||
metadataCacheUri: 'http://127.0.0.1:5000',
|
||||
providerUri: 'http://127.0.0.1:8030',
|
||||
oceanTokenAddress: null,
|
||||
factoryAddress: '0x1234',
|
||||
poolFactoryAddress: null,
|
||||
fixedRateExchangeAddress: null,
|
||||
metadataContractAddress: null
|
||||
@ -33,9 +34,10 @@ const configs: ConfigHelperConfig[] = [
|
||||
networkId: 8996,
|
||||
network: 'development',
|
||||
nodeUri: 'http://localhost:8545',
|
||||
factoryAddress: null,
|
||||
metadataCacheUri: 'http://127.0.0.1:5000',
|
||||
providerUri: 'http://127.0.0.1:8030',
|
||||
oceanTokenAddress: null,
|
||||
factoryAddress: null,
|
||||
poolFactoryAddress: null,
|
||||
fixedRateExchangeAddress: null,
|
||||
metadataContractAddress: null
|
||||
@ -44,22 +46,22 @@ const configs: ConfigHelperConfig[] = [
|
||||
networkId: 4,
|
||||
network: 'rinkeby',
|
||||
nodeUri: 'https://rinkeby.infura.io/v3',
|
||||
factoryAddress: '0x3fd7A00106038Fb5c802c6d63fa7147Fe429E83a',
|
||||
oceanTokenAddress: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07',
|
||||
metadataCacheUri: 'https://aquarius.rinkeby.v3.dev-ocean.com',
|
||||
providerUri: 'https://provider.rinkeby.v3.dev-ocean.com',
|
||||
poolFactoryAddress: '0x53eDF9289B0898e1652Ce009AACf8D25fA9A42F8',
|
||||
fixedRateExchangeAddress: '0xeD1DfC5F3a589CfC4E8B91C1fbfC18FC6699Fbde',
|
||||
metadataContractAddress: '0xFD8a7b6297153397B7eb4356C47dbd381d58bFF4'
|
||||
oceanTokenAddress: null,
|
||||
factoryAddress: null,
|
||||
poolFactoryAddress: null,
|
||||
fixedRateExchangeAddress: null,
|
||||
metadataContractAddress: null
|
||||
},
|
||||
{
|
||||
networkId: 1,
|
||||
network: 'mainnet',
|
||||
nodeUri: 'https://mainnet.infura.io/v3',
|
||||
factoryAddress: '0x1234',
|
||||
oceanTokenAddress: '0x7AFeBBB46fDb47ed17b22ed075Cde2447694fB9e',
|
||||
metadataCacheUri: null,
|
||||
providerUri: null,
|
||||
oceanTokenAddress: null,
|
||||
factoryAddress: null,
|
||||
poolFactoryAddress: null,
|
||||
fixedRateExchangeAddress: null,
|
||||
metadataContractAddress: null
|
||||
@ -69,18 +71,17 @@ const configs: ConfigHelperConfig[] = [
|
||||
export class ConfigHelper {
|
||||
/* Load contract addresses from env ADDRESS_FILE (generated by ocean-contracts) */
|
||||
public getAddressesFromEnv(network: string): Partial<ConfigHelperConfig> {
|
||||
try {
|
||||
const data = JSON.parse(
|
||||
fs.readFileSync(
|
||||
process.env.ADDRESS_FILE ||
|
||||
`${homedir}/.ocean/ocean-contracts/artifacts/address.json`,
|
||||
'utf8'
|
||||
)
|
||||
)
|
||||
|
||||
const { DTFactory, BFactory, FixedRateExchange, Metadata, Ocean } = data[network]
|
||||
|
||||
const configAddresses: Partial<ConfigHelperConfig> = {
|
||||
// use the defaults first
|
||||
let configAddresses: Partial<ConfigHelperConfig>
|
||||
if (DefaultContractsAddresses[network]) {
|
||||
const {
|
||||
DTFactory,
|
||||
BFactory,
|
||||
FixedRateExchange,
|
||||
Metadata,
|
||||
Ocean
|
||||
} = DefaultContractsAddresses[network]
|
||||
configAddresses = {
|
||||
factoryAddress: DTFactory,
|
||||
poolFactoryAddress: BFactory,
|
||||
fixedRateExchangeAddress: FixedRateExchange,
|
||||
@ -88,12 +89,32 @@ export class ConfigHelper {
|
||||
oceanTokenAddress: Ocean,
|
||||
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI })
|
||||
}
|
||||
|
||||
return configAddresses
|
||||
} catch (e) {
|
||||
Logger.error(`ERROR: Could not load local contract address file: ${e.message}`)
|
||||
return null
|
||||
}
|
||||
// try ADDRESS_FILE env
|
||||
if (fs && process.env.ADDRESS_FILE) {
|
||||
try {
|
||||
const data = JSON.parse(
|
||||
fs.readFileSync(
|
||||
process.env.ADDRESS_FILE ||
|
||||
`${homedir}/.ocean/ocean-contracts/artifacts/address.json`,
|
||||
'utf8'
|
||||
)
|
||||
)
|
||||
const { DTFactory, BFactory, FixedRateExchange, Metadata, Ocean } = data[network]
|
||||
configAddresses = {
|
||||
factoryAddress: DTFactory,
|
||||
poolFactoryAddress: BFactory,
|
||||
fixedRateExchangeAddress: FixedRateExchange,
|
||||
metadataContractAddress: Metadata,
|
||||
oceanTokenAddress: Ocean,
|
||||
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI })
|
||||
}
|
||||
} catch (e) {
|
||||
// console.error(`ERROR: Could not load local contract address file: ${e.message}`)
|
||||
// return null
|
||||
}
|
||||
}
|
||||
return configAddresses
|
||||
}
|
||||
|
||||
public getConfig(
|
||||
|
@ -6,6 +6,7 @@ describe('ConfigHelper', () => {
|
||||
const network = 'rinkeby'
|
||||
const config = new ConfigHelper().getConfig(network)
|
||||
assert(config.nodeUri.includes(network))
|
||||
assert(config.factoryAddress != null)
|
||||
})
|
||||
|
||||
it('should get config based on network name, and add passed Infura ID', () => {
|
||||
@ -13,12 +14,14 @@ describe('ConfigHelper', () => {
|
||||
const infuraId = 'helloInfura'
|
||||
const config = new ConfigHelper().getConfig(network, infuraId)
|
||||
assert(config.nodeUri.includes(infuraId))
|
||||
assert(config.factoryAddress != null)
|
||||
})
|
||||
|
||||
it('should get config based on chain ID', () => {
|
||||
const network = 4
|
||||
const config = new ConfigHelper().getConfig(network)
|
||||
assert(config.nodeUri.includes('rinkeby'))
|
||||
assert(config.factoryAddress != null)
|
||||
})
|
||||
|
||||
it('should return nothing with unknown network', () => {
|
||||
@ -26,4 +29,9 @@ describe('ConfigHelper', () => {
|
||||
const config = new ConfigHelper().getConfig(network)
|
||||
assert(config === null)
|
||||
})
|
||||
it('should get a custom config', () => {
|
||||
const network = 'unknown'
|
||||
const config = new ConfigHelper().getConfig(network)
|
||||
assert(config.factoryAddress === '0x1234')
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user