1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

fix lint, complete deployment script, add initial instance test

This commit is contained in:
lacoop6tu 2021-10-20 15:29:04 -05:00
parent 3e247d46bf
commit 3c638ab597
5 changed files with 95 additions and 113 deletions

View File

@ -162,7 +162,7 @@ export class NFTFactory {
address: string, address: string,
templateAddress: string templateAddress: string
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
if ((await this.getOwner()) != address) { if ((await this.getOwner()) !== address) {
throw new Error(`Caller is not Factory Owner`) throw new Error(`Caller is not Factory Owner`)
} }
@ -198,7 +198,7 @@ export class NFTFactory {
address: string, address: string,
templateIndex: number templateIndex: number
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
if ((await this.getOwner()) != address) { if ((await this.getOwner()) !== address) {
throw new Error(`Caller is not Factory Owner`) throw new Error(`Caller is not Factory Owner`)
} }
@ -234,7 +234,7 @@ export class NFTFactory {
address: string, address: string,
templateIndex: number templateIndex: number
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
if ((await this.getOwner()) != address) { if ((await this.getOwner()) !== address) {
throw new Error(`Caller is not Factory Owner`) throw new Error(`Caller is not Factory Owner`)
} }
@ -270,7 +270,7 @@ export class NFTFactory {
address: string, address: string,
templateAddress: string templateAddress: string
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
if ((await this.getOwner()) != address) { if ((await this.getOwner()) !== address) {
throw new Error(`Caller is not Factory Owner`) throw new Error(`Caller is not Factory Owner`)
} }
@ -306,7 +306,7 @@ export class NFTFactory {
address: string, address: string,
templateIndex: number templateIndex: number
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
if ((await this.getOwner()) != address) { if ((await this.getOwner()) !== address) {
throw new Error(`Caller is not Factory Owner`) throw new Error(`Caller is not Factory Owner`)
} }
@ -342,7 +342,7 @@ export class NFTFactory {
address: string, address: string,
templateIndex: number templateIndex: number
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
if ((await this.getOwner()) != address) { if ((await this.getOwner()) !== address) {
throw new Error(`Caller is not Factory Owner`) throw new Error(`Caller is not Factory Owner`)
} }

View File

@ -37,7 +37,7 @@ export class PoolFactory {
public async deployPool( public async deployPool(
account: string, account: string,
tokens: string[], tokens: string[],
weights: string[], weightsInWei: string[],
swapFeePercentage: number, swapFeePercentage: number,
swapMarketFee: number, swapMarketFee: number,
owner: string owner: string
@ -53,5 +53,6 @@ export class PoolFactory {
this.logger.log(e) this.logger.log(e)
estGas = gasLimitDefault estGas = gasLimitDefault
} }
return estGas
} }
} }

View File

@ -1,3 +1,3 @@
export * from './balancer' export * from './balancer'
export * from './dispencer' export * from './dispenser'
export * from './fixedRate' export * from './fixedRate'

View File

@ -2,6 +2,7 @@ import Web3 from 'web3'
import { Contract } from 'web3-eth-contract' import { Contract } from 'web3-eth-contract'
import { AbiItem } from 'web3-utils/types' import { AbiItem } from 'web3-utils/types'
// TODO: add OPF deployment
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75' const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
const oceanAddress = '0x967da4048cd07ab37855c090aaf366e4ce1b9f48' const oceanAddress = '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
export class TestContractHandler { export class TestContractHandler {
@ -25,18 +26,16 @@ export class TestContractHandler {
public DispenserBytecode: string public DispenserBytecode: string
public PoolTemplateBytecode: string public PoolTemplateBytecode: string
public OPFCollectorBytecode: string public OPFCollectorBytecode: string
public factory721Address: string public factory721Address: string
public template721Address: string public template721Address: string
public template20Address: string public template20Address: string
public routerAddress:string public routerAddress: string
public sideStakingAddress: string public sideStakingAddress: string
public fixedRateAddress:string public fixedRateAddress: string
public dispenserAddress: string public dispenserAddress: string
public poolTemplateAddress: string public poolTemplateAddress: string
public opfCollectorAddress: string public opfCollectorAddress: string
public web3: Web3 public web3: Web3
@ -50,26 +49,25 @@ export class TestContractHandler {
SideStakingABI?: AbiItem | AbiItem[], SideStakingABI?: AbiItem | AbiItem[],
FixedRateABI?: AbiItem | AbiItem[], FixedRateABI?: AbiItem | AbiItem[],
DispenserABI?: AbiItem | AbiItem[], DispenserABI?: AbiItem | AbiItem[],
template721Bytecode?: string, template721Bytecode?: string,
template20Bytecode?: string, template20Bytecode?: string,
poolTemplateBytecode?: string, poolTemplateBytecode?: string,
factory721Bytecode?: string, factory721Bytecode?: string,
routerBytecode?: string, routerBytecode?: string,
sideStakingBytecode?: string, sideStakingBytecode?: string,
fixedRateBytecode?:string, fixedRateBytecode?: string,
dispenserBytecode?: string, dispenserBytecode?: string
) { ) {
this.web3 = web3 this.web3 = web3
this.ERC721Template = new this.web3.eth.Contract(ERC721TemplateABI) this.ERC721Template = new this.web3.eth.Contract(ERC721TemplateABI)
this.ERC20Template = new this.web3.eth.Contract(ERC20TemplateABI) this.ERC20Template = new this.web3.eth.Contract(ERC20TemplateABI)
this.PoolTemplate = new this.web3.eth.Contract(PoolTemplateABI) this.PoolTemplate = new this.web3.eth.Contract(PoolTemplateABI)
this.ERC721Factory = new this.web3.eth.Contract(ERC721FactoryABI) this.ERC721Factory = new this.web3.eth.Contract(ERC721FactoryABI)
this.Router=new this.web3.eth.Contract(RouterABI) this.Router = new this.web3.eth.Contract(RouterABI)
this.SideStaking = new this.web3.eth.Contract(SideStakingABI) this.SideStaking = new this.web3.eth.Contract(SideStakingABI)
this.FixedRate= new this.web3.eth.Contract(FixedRateABI) this.FixedRate = new this.web3.eth.Contract(FixedRateABI)
this.Dispenser = new this.web3.eth.Contract(DispenserABI) this.Dispenser = new this.web3.eth.Contract(DispenserABI)
this.ERC721FactoryBytecode = factory721Bytecode this.ERC721FactoryBytecode = factory721Bytecode
this.ERC20TemplateBytecode = template20Bytecode this.ERC20TemplateBytecode = template20Bytecode
@ -86,37 +84,34 @@ export class TestContractHandler {
return this.accounts return this.accounts
} }
public async deployContracts(owner: string) { public async deployContracts(owner: string, routerABI?: AbiItem | AbiItem[]) {
let estGas let estGas
// console.log(this.ERC721TemplateBytecode)
// console.log(this.ERC20TemplateBytecode)
// DEPLOY POOL TEMPLATE // DEPLOY POOL TEMPLATE
// get est gascost // get est gascost
estGas = await this.PoolTemplate.deploy({ estGas = await this.PoolTemplate.deploy({
data: this.PoolTemplateBytecode, data: this.PoolTemplateBytecode,
arguments: [] arguments: []
}).estimateGas(function (err, estGas) { }).estimateGas(function (err, estGas) {
if (err) console.log('DeployContracts: ' + err) if (err) console.log('DeployContracts: ' + err)
return estGas return estGas
})
// deploy the contract and get it's address
this.poolTemplateAddress = await this.PoolTemplate.deploy({
data: this.PoolTemplateBytecode,
arguments: []
})
.send({
from: owner,
gas: estGas + 1,
gasPrice: '3000000000'
}) })
.then(function (contract) { // deploy the contract and get it's address
return contract.options.address this.poolTemplateAddress = await this.PoolTemplate.deploy({
data: this.PoolTemplateBytecode,
arguments: []
}) })
.send({
from: owner,
gas: estGas + 1,
gasPrice: '3000000000'
})
.then(function (contract) {
return contract.options.address
})
// DEPLOY ERC20 TEMPLATE
// DEPLOY ERC20 TEMPLATE // get est gascost
// get est gascost
estGas = await this.ERC20Template.deploy({ estGas = await this.ERC20Template.deploy({
data: this.ERC20TemplateBytecode, data: this.ERC20TemplateBytecode,
arguments: [] arguments: []
@ -138,10 +133,7 @@ export class TestContractHandler {
return contract.options.address return contract.options.address
}) })
// DEPLOY ERC721 TEMPLATE
// DEPLOY ERC721 TEMPLATE
// get est gascost // get est gascost
estGas = await this.ERC721Template.deploy({ estGas = await this.ERC721Template.deploy({
data: this.ERC721TemplateBytecode, data: this.ERC721TemplateBytecode,
@ -167,7 +159,7 @@ export class TestContractHandler {
// DEPLOY ROUTER // DEPLOY ROUTER
estGas = await this.Router.deploy({ estGas = await this.Router.deploy({
data: this.RouterBytecode, data: this.RouterBytecode,
arguments: [owner,oceanAddress,this.poolTemplateAddress,communityCollector,[]] arguments: [owner, oceanAddress, this.poolTemplateAddress, communityCollector, []]
}).estimateGas(function (err, estGas) { }).estimateGas(function (err, estGas) {
if (err) console.log('DeployContracts: ' + err) if (err) console.log('DeployContracts: ' + err)
return estGas return estGas
@ -175,7 +167,7 @@ export class TestContractHandler {
// deploy the contract and get it's address // deploy the contract and get it's address
this.routerAddress = await this.Router.deploy({ this.routerAddress = await this.Router.deploy({
data: this.RouterBytecode, data: this.RouterBytecode,
arguments: [owner,oceanAddress,this.poolTemplateAddress,communityCollector,[]] arguments: [owner, oceanAddress, this.poolTemplateAddress, communityCollector, []]
}) })
.send({ .send({
from: owner, from: owner,
@ -186,8 +178,7 @@ export class TestContractHandler {
return contract.options.address return contract.options.address
}) })
// DEPLOY SIDE STAKING
// DEPLOY SIDE STAKING
estGas = await this.SideStaking.deploy({ estGas = await this.SideStaking.deploy({
data: this.SideStakingBytecode, data: this.SideStakingBytecode,
arguments: [this.routerAddress] arguments: [this.routerAddress]
@ -208,8 +199,8 @@ export class TestContractHandler {
.then(function (contract) { .then(function (contract) {
return contract.options.address return contract.options.address
}) })
// DEPLOY FIXED RATE // DEPLOY FIXED RATE
estGas = await this.FixedRate.deploy({ estGas = await this.FixedRate.deploy({
data: this.FixedRateBytecode, data: this.FixedRateBytecode,
arguments: [this.routerAddress, communityCollector] arguments: [this.routerAddress, communityCollector]
@ -231,7 +222,7 @@ export class TestContractHandler {
return contract.options.address return contract.options.address
}) })
// DEPLOY Dispenser // DEPLOY Dispenser
estGas = await this.Dispenser.deploy({ estGas = await this.Dispenser.deploy({
data: this.DispenserBytecode, data: this.DispenserBytecode,
arguments: [this.routerAddress] arguments: [this.routerAddress]
@ -253,10 +244,15 @@ export class TestContractHandler {
return contract.options.address return contract.options.address
}) })
// DEPLOY ERC721 FACTORY // DEPLOY ERC721 FACTORY
estGas = await this.ERC721Factory.deploy({ estGas = await this.ERC721Factory.deploy({
data: this.ERC721FactoryBytecode, data: this.ERC721FactoryBytecode,
arguments: [this.template721Address, this.template20Address, communityCollector,this.routerAddress] arguments: [
this.template721Address,
this.template20Address,
communityCollector,
this.routerAddress
]
}).estimateGas(function (err, estGas) { }).estimateGas(function (err, estGas) {
if (err) console.log('DeployContracts: ' + err) if (err) console.log('DeployContracts: ' + err)
return estGas return estGas
@ -264,7 +260,12 @@ export class TestContractHandler {
// deploy the contract and get it's address // deploy the contract and get it's address
this.factory721Address = await this.ERC721Factory.deploy({ this.factory721Address = await this.ERC721Factory.deploy({
data: this.ERC721FactoryBytecode, data: this.ERC721FactoryBytecode,
arguments: [this.template721Address, this.template20Address, communityCollector,this.routerAddress] arguments: [
this.template721Address,
this.template20Address,
communityCollector,
this.routerAddress
]
}) })
.send({ .send({
from: owner, from: owner,
@ -275,7 +276,21 @@ export class TestContractHandler {
return contract.options.address return contract.options.address
}) })
// // TODO: SET ERC721 Factory address in ERC20 Factory const RouterContract = new this.web3.eth.Contract(routerABI, this.routerAddress)
await RouterContract.methods.addFactory(this.factory721Address).send({ from: owner })
await RouterContract.methods
.addFixedRateContract(this.fixedRateAddress)
.send({ from: owner })
await RouterContract.methods
.addFixedRateContract(this.dispenserAddress)
.send({ from: owner })
await RouterContract.methods
.addSSContract(this.sideStakingAddress)
.send({ from: owner })
// TODO: add OPF deployment and update argument
await RouterContract.methods
.changeRouterOwner(communityCollector)
.send({ from: owner })
} }
} }

View File

@ -10,8 +10,9 @@ import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/template
import Dispenser from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json' import Dispenser from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
import FixedRate from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json' import FixedRate from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json' import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
import { LoggerInstance } from '../../src/utils'
// import { NFTDataToken } from '../../../src/datatokens/NFTDatatoken' // import { NFTDataToken } from '../../../src/datatokens/NFTDatatoken'
// import { NFTFactory } from '../../../src/factories/NFTFactory' import { NFTFactory } from '../../src/factories/NFTFactory'
// import { DT20Factory } from '../../../src/factories/DT20Factory' // import { DT20Factory } from '../../../src/factories/DT20Factory'
const web3 = new Web3('http://127.0.0.1:8545') const web3 = new Web3('http://127.0.0.1:8545')
@ -22,12 +23,7 @@ describe('NFT Factory test', () => {
let user1: string let user1: string
let user2: string let user2: string
let contracts: TestContractHandler let contracts: TestContractHandler
// let nftDatatoken: NFTDataToken let nftFactory: NFTFactory
// let nftFactory: NFTFactory
// let erc20Factory: DT20Factory
// let nftAddress: string
// let newNFTAddress: string
// let newNFTDatatoken: NFTDataToken
const nftName = 'NFT' const nftName = 'NFT'
const nftSymbol = 'NFTSymbol' const nftSymbol = 'NFTSymbol'
@ -40,16 +36,16 @@ describe('NFT Factory test', () => {
// TODO: complete unit test // TODO: complete unit test
it('should deploy contracts', async () => { it('should deploy contracts', async () => {
contracts = new TestContractHandler( contracts = new TestContractHandler(
web3, web3,
ERC721Template.abi as AbiItem[], ERC721Template.abi as AbiItem[],
ERC20Template.abi as AbiItem[], ERC20Template.abi as AbiItem[],
PoolTemplate.abi as AbiItem[], PoolTemplate.abi as AbiItem[],
ERC721Factory.abi as AbiItem[], ERC721Factory.abi as AbiItem[],
Router.abi as AbiItem[], Router.abi as AbiItem[],
SideStaking.abi as AbiItem[], SideStaking.abi as AbiItem[],
FixedRate.abi as AbiItem[], FixedRate.abi as AbiItem[],
Dispenser.abi as AbiItem[], Dispenser.abi as AbiItem[],
ERC721Template.bytecode, ERC721Template.bytecode,
ERC20Template.bytecode, ERC20Template.bytecode,
PoolTemplate.bytecode, PoolTemplate.bytecode,
@ -57,52 +53,22 @@ describe('NFT Factory test', () => {
Router.bytecode, Router.bytecode,
SideStaking.bytecode, SideStaking.bytecode,
FixedRate.bytecode, FixedRate.bytecode,
Dispenser.bytecode, Dispenser.bytecode
) )
await contracts.getAccounts() await contracts.getAccounts()
factoryOwner = contracts.accounts[0] factoryOwner = contracts.accounts[0]
nftOwner = contracts.accounts[1] nftOwner = contracts.accounts[1]
user1 = contracts.accounts[2] user1 = contracts.accounts[2]
console.log(factoryOwner) console.log(factoryOwner)
await contracts.deployContracts(factoryOwner) await contracts.deployContracts(factoryOwner, Router.abi as AbiItem[])
console.log('BOOM') console.log('BOOM')
}) })
it('should initiate NFTFactory instance', async () => {
// it('should set ERC721Factory on ERC20Factory', async () => { nftFactory = new NFTFactory(contracts.factory721Address, web3, LoggerInstance)
// erc20Factory = new DT20Factory(
// contracts.factory20Address,
// //ERC20Factory.abi as AbiItem[],
// web3,
// LoggerInstance
// )
// await erc20Factory.setERC721Factory(factoryOwner, contracts.factory721Address) const nftCount = await nftFactory.getCurrentNFTCount()
// }) assert(nftCount == 0)
})
// it('should initialize NFTFactory instance, create a new NFT and initializing a NFT dt class', async () => { })
// nftFactory = new NFTFactory(
// contracts.factory721Address,
// web3,
// LoggerInstance
// // ERC721Factory.abi as AbiItem[],
// )
// nftAddress = await nftFactory.createNFT(
// nftOwner,
// data,
// flags,
// nftName,
// nftSymbol,
// nftTemplateIndex
// )
// //console.log(newNFTAddress)
// nftDatatoken = new NFTDataToken(
// web3,
// LoggerInstance
// // ERC721Template.abi as AbiItem[],
// )
})