mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #1430 from oceanprotocol/issue-1425-use-proper-config-in-constructors
Issue-#1425: Use proper config in constructors
This commit is contained in:
commit
9cb1ea51a8
@ -10,9 +10,9 @@ import {
|
||||
getFreCreationParams,
|
||||
getErcCreationParams,
|
||||
getPoolCreationParams,
|
||||
configHelperNetworks,
|
||||
setContractDefaults,
|
||||
ZERO_ADDRESS
|
||||
ZERO_ADDRESS,
|
||||
ConfigHelper
|
||||
} from '../utils'
|
||||
import { Config } from '../models/index.js'
|
||||
import {
|
||||
@ -66,13 +66,14 @@ export class NftFactory {
|
||||
constructor(
|
||||
factory721Address: string,
|
||||
web3: Web3,
|
||||
network?: string | number,
|
||||
factory721Abi?: AbiItem | AbiItem[],
|
||||
config?: Config
|
||||
) {
|
||||
this.factory721Address = factory721Address
|
||||
this.factory721Abi = factory721Abi || (defaultFactory721Abi.abi as AbiItem[])
|
||||
this.web3 = web3
|
||||
this.config = config || configHelperNetworks[0]
|
||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
||||
this.factory721 = setContractDefaults(
|
||||
new this.web3.eth.Contract(this.factory721Abi, this.factory721Address),
|
||||
this.config
|
||||
|
@ -3,7 +3,7 @@ import Web3 from 'web3'
|
||||
import { TransactionReceipt } from 'web3-core'
|
||||
import { AbiItem } from 'web3-utils'
|
||||
import defaultRouter from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
|
||||
import { getFairGasPrice, setContractDefaults, configHelperNetworks } from '../utils'
|
||||
import { getFairGasPrice, setContractDefaults, ConfigHelper } from '../utils'
|
||||
import { Operation } from '../@types/Router'
|
||||
import { Config } from '../models/index.js'
|
||||
|
||||
@ -27,13 +27,14 @@ export class Router {
|
||||
constructor(
|
||||
routerAddress: string,
|
||||
web3: Web3,
|
||||
network?: string | number,
|
||||
RouterAbi?: AbiItem | AbiItem[],
|
||||
config?: Config
|
||||
) {
|
||||
this.routerAddress = routerAddress
|
||||
this.RouterAbi = RouterAbi || (defaultRouter.abi as AbiItem[])
|
||||
this.web3 = web3
|
||||
this.config = config || configHelperNetworks[0]
|
||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
||||
this.router = setContractDefaults(
|
||||
new this.web3.eth.Contract(this.RouterAbi, this.routerAddress),
|
||||
this.config
|
||||
|
@ -4,11 +4,11 @@ import { TransactionReceipt } from 'web3-core'
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import {
|
||||
getFairGasPrice,
|
||||
configHelperNetworks,
|
||||
setContractDefaults,
|
||||
unitsToAmount,
|
||||
amountToUnits,
|
||||
LoggerInstance
|
||||
LoggerInstance,
|
||||
ConfigHelper
|
||||
} from '../../utils'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
||||
@ -40,11 +40,16 @@ export class Pool {
|
||||
public GASLIMIT_DEFAULT = 1000000
|
||||
private config: Config
|
||||
|
||||
constructor(web3: Web3, poolAbi: AbiItem | AbiItem[] = null, config?: Config) {
|
||||
constructor(
|
||||
web3: Web3,
|
||||
network?: string | number,
|
||||
poolAbi: AbiItem | AbiItem[] = null,
|
||||
config?: Config
|
||||
) {
|
||||
if (poolAbi) this.poolAbi = poolAbi
|
||||
else this.poolAbi = PoolTemplate.abi as AbiItem[]
|
||||
this.web3 = web3
|
||||
this.config = config || configHelperNetworks[0]
|
||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,8 +7,8 @@ import defaultDispenserAbi from '@oceanprotocol/contracts/artifacts/contracts/po
|
||||
import {
|
||||
LoggerInstance as logger,
|
||||
getFairGasPrice,
|
||||
configHelperNetworks,
|
||||
setContractDefaults
|
||||
setContractDefaults,
|
||||
ConfigHelper
|
||||
} from '../../utils/'
|
||||
import { Datatoken } from '../../tokens'
|
||||
import { Config } from '../../models/index.js'
|
||||
@ -39,6 +39,7 @@ export class Dispenser {
|
||||
*/
|
||||
constructor(
|
||||
web3: Web3,
|
||||
network?: string | number,
|
||||
dispenserAddress: string = null,
|
||||
dispenserAbi: AbiItem | AbiItem[] = null,
|
||||
config?: Config
|
||||
@ -46,7 +47,7 @@ export class Dispenser {
|
||||
this.web3 = web3
|
||||
this.dispenserAddress = dispenserAddress
|
||||
this.dispenserAbi = dispenserAbi || (defaultDispenserAbi.abi as AbiItem[])
|
||||
this.config = config || configHelperNetworks[0]
|
||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
||||
if (web3)
|
||||
this.dispenserContract = setContractDefaults(
|
||||
new this.web3.eth.Contract(this.dispenserAbi, this.dispenserAddress),
|
||||
|
@ -6,11 +6,11 @@ import Web3 from 'web3'
|
||||
import {
|
||||
LoggerInstance,
|
||||
getFairGasPrice,
|
||||
configHelperNetworks,
|
||||
setContractDefaults,
|
||||
amountToUnits,
|
||||
unitsToAmount,
|
||||
ZERO_ADDRESS
|
||||
ZERO_ADDRESS,
|
||||
ConfigHelper
|
||||
} from '../../utils'
|
||||
import { Config } from '../../models/index.js'
|
||||
import { PriceAndFees } from '../..'
|
||||
@ -75,12 +75,13 @@ export class FixedRateExchange {
|
||||
constructor(
|
||||
web3: Web3,
|
||||
fixedRateAddress: string,
|
||||
network?: string | number,
|
||||
fixedRateExchangeAbi: AbiItem | AbiItem[] = null,
|
||||
oceanAddress: string = null,
|
||||
config?: Config
|
||||
) {
|
||||
this.web3 = web3
|
||||
this.config = config || configHelperNetworks[0]
|
||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
||||
this.fixedRateExchangeAbi =
|
||||
fixedRateExchangeAbi || (defaultFixedRateExchangeAbi.abi as AbiItem[])
|
||||
this.oceanAddress = oceanAddress
|
||||
|
@ -2,7 +2,7 @@ import Web3 from 'web3'
|
||||
import { AbiItem } from 'web3-utils/types'
|
||||
import { TransactionReceipt } from 'web3-core'
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import { LoggerInstance, getFairGasPrice, configHelperNetworks } from '../../utils'
|
||||
import { LoggerInstance, getFairGasPrice, ConfigHelper } from '../../utils'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import SideStakingTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
||||
import defaultErc20Abi from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||
@ -14,11 +14,16 @@ export class SideStaking {
|
||||
public GASLIMIT_DEFAULT = 1000000
|
||||
public config: Config
|
||||
|
||||
constructor(web3: Web3, ssAbi: AbiItem | AbiItem[] = null, config?: Config) {
|
||||
constructor(
|
||||
web3: Web3,
|
||||
network?: string | number,
|
||||
ssAbi: AbiItem | AbiItem[] = null,
|
||||
config?: Config
|
||||
) {
|
||||
if (ssAbi) this.ssAbi = ssAbi
|
||||
else this.ssAbi = SideStakingTemplate.abi as AbiItem[]
|
||||
this.web3 = web3
|
||||
this.config = config || configHelperNetworks[0]
|
||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
||||
}
|
||||
|
||||
async amountToUnits(token: string, amount: string): Promise<string> {
|
||||
|
@ -9,9 +9,9 @@ import {
|
||||
LoggerInstance,
|
||||
getFairGasPrice,
|
||||
setContractDefaults,
|
||||
configHelperNetworks,
|
||||
getFreOrderParams,
|
||||
ZERO_ADDRESS
|
||||
ZERO_ADDRESS,
|
||||
ConfigHelper
|
||||
} from '../utils'
|
||||
import {
|
||||
ConsumeMarketFee,
|
||||
@ -61,6 +61,7 @@ export class Datatoken {
|
||||
*/
|
||||
constructor(
|
||||
web3: Web3,
|
||||
network?: string | number,
|
||||
datatokensAbi?: AbiItem | AbiItem[],
|
||||
datatokensEnterpriseAbi?: AbiItem | AbiItem[],
|
||||
config?: Config
|
||||
@ -69,7 +70,7 @@ export class Datatoken {
|
||||
this.datatokensAbi = datatokensAbi || (defaultDatatokensAbi.abi as AbiItem[])
|
||||
this.datatokensEnterpriseAbi =
|
||||
datatokensEnterpriseAbi || (defaultDatatokensEnterpriseAbi.abi as AbiItem[])
|
||||
this.config = config || configHelperNetworks[0]
|
||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
||||
this.nft = new Nft(this.web3)
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
getFairGasPrice,
|
||||
generateDtName,
|
||||
setContractDefaults,
|
||||
configHelperNetworks
|
||||
ConfigHelper
|
||||
} from '../utils'
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import { MetadataProof } from '../../src/@types'
|
||||
@ -33,10 +33,15 @@ export class Nft {
|
||||
public startBlock: number
|
||||
public config: Config
|
||||
|
||||
constructor(web3: Web3, nftAbi?: AbiItem | AbiItem[], config?: Config) {
|
||||
constructor(
|
||||
web3: Web3,
|
||||
network?: string | number,
|
||||
nftAbi?: AbiItem | AbiItem[],
|
||||
config?: Config
|
||||
) {
|
||||
this.nftAbi = nftAbi || (defaultNftAbi.abi as AbiItem[])
|
||||
this.web3 = web3
|
||||
this.config = config || configHelperNetworks[0]
|
||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,7 @@ describe('Pool unit test', () => {
|
||||
contracts = await deployContracts(web3, factoryOwner)
|
||||
|
||||
// initialize Pool instance
|
||||
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])
|
||||
pool = new Pool(web3, 8996, PoolTemplate.abi as AbiItem[])
|
||||
assert(pool != null)
|
||||
|
||||
daiContract = new web3.eth.Contract(MockERC20.abi as AbiItem[], contracts.daiAddress)
|
||||
@ -143,6 +143,7 @@ describe('Pool unit test', () => {
|
||||
const nftFactory = new NftFactory(
|
||||
contracts.erc721FactoryAddress,
|
||||
web3,
|
||||
8996,
|
||||
ERC721Factory.abi as AbiItem[]
|
||||
)
|
||||
|
||||
@ -572,6 +573,7 @@ describe('Pool unit test', () => {
|
||||
const nftFactory = new NftFactory(
|
||||
contracts.erc721FactoryAddress,
|
||||
web3,
|
||||
8996,
|
||||
ERC721Factory.abi as AbiItem[]
|
||||
)
|
||||
|
||||
|
@ -43,6 +43,7 @@ describe('Dispenser flow', () => {
|
||||
it('should initialize Dispenser class', async () => {
|
||||
DispenserClass = new Dispenser(
|
||||
web3,
|
||||
8996,
|
||||
contracts.dispenserAddress,
|
||||
DispenserTemplate.abi as AbiItem[]
|
||||
)
|
||||
@ -87,7 +88,7 @@ describe('Dispenser flow', () => {
|
||||
})
|
||||
|
||||
it('Make user2 minter', async () => {
|
||||
datatoken = new Datatoken(web3, ERC20Template.abi as AbiItem[])
|
||||
datatoken = new Datatoken(web3, 8996, ERC20Template.abi as AbiItem[])
|
||||
await datatoken.addMinter(dtAddress, factoryOwner, user2)
|
||||
assert((await datatoken.getDTPermissions(dtAddress, user2)).minter === true)
|
||||
})
|
||||
|
@ -118,6 +118,7 @@ describe('Fixed Rate unit test', () => {
|
||||
fixedRate = new FixedRateExchange(
|
||||
web3,
|
||||
fixedRateAddress,
|
||||
8996,
|
||||
FixedRate.abi as AbiItem[],
|
||||
contracts.oceanAddress
|
||||
)
|
||||
@ -438,6 +439,7 @@ describe('Fixed Rate unit test', () => {
|
||||
fixedRate = new FixedRateExchange(
|
||||
web3,
|
||||
fixedRateAddress,
|
||||
8996,
|
||||
FixedRate.abi as AbiItem[],
|
||||
contracts.oceanAddress
|
||||
)
|
||||
|
@ -59,10 +59,10 @@ describe('SideStaking unit test', () => {
|
||||
sideStakingAddress = contracts.sideStakingAddress
|
||||
|
||||
// initialize Pool instance
|
||||
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])
|
||||
pool = new Pool(web3, 8996, PoolTemplate.abi as AbiItem[])
|
||||
assert(pool != null)
|
||||
//
|
||||
sideStaking = new SideStaking(web3, SSContract.abi as AbiItem[])
|
||||
sideStaking = new SideStaking(web3, 8996, SSContract.abi as AbiItem[])
|
||||
assert(sideStaking != null)
|
||||
|
||||
daiContract = new web3.eth.Contract(MockERC20.abi as AbiItem[], contracts.daiAddress)
|
||||
|
@ -62,6 +62,7 @@ describe('Datatoken', () => {
|
||||
nftFactory = new NftFactory(
|
||||
contracts.erc721FactoryAddress,
|
||||
web3,
|
||||
8996,
|
||||
ERC721Factory.abi as AbiItem[]
|
||||
)
|
||||
const nftData: NftCreateData = {
|
||||
@ -74,7 +75,7 @@ describe('Datatoken', () => {
|
||||
}
|
||||
|
||||
nftAddress = await nftFactory.createNFT(nftOwner, nftData)
|
||||
nftDatatoken = new Nft(web3, ERC721Template.abi as AbiItem[])
|
||||
nftDatatoken = new Nft(web3, 8996, ERC721Template.abi as AbiItem[])
|
||||
})
|
||||
|
||||
it('#createERC20 - should create a new ERC20 DT from NFT contract', async () => {
|
||||
@ -98,6 +99,7 @@ describe('Datatoken', () => {
|
||||
it('should initialize DT20 Instance', async () => {
|
||||
datatoken = new Datatoken(
|
||||
web3,
|
||||
8996,
|
||||
ERC20Template.abi as AbiItem[],
|
||||
ERC20TemplateEnterprise.abi as AbiItem[]
|
||||
)
|
||||
|
@ -39,6 +39,7 @@ describe('NFT', () => {
|
||||
nftFactory = new NftFactory(
|
||||
contracts.erc721FactoryAddress,
|
||||
web3,
|
||||
8996,
|
||||
ERC721Factory.abi as AbiItem[]
|
||||
)
|
||||
const nftData: NftCreateData = {
|
||||
@ -51,7 +52,7 @@ describe('NFT', () => {
|
||||
}
|
||||
|
||||
nftAddress = await nftFactory.createNFT(nftOwner, nftData)
|
||||
nftDatatoken = new Nft(web3, ERC721Template.abi as AbiItem[])
|
||||
nftDatatoken = new Nft(web3, 8996, ERC721Template.abi as AbiItem[])
|
||||
})
|
||||
it('#getTokenURI', async () => {
|
||||
const tokenURI = await nftDatatoken.getTokenURI(nftAddress, 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user