mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #1080 from oceanprotocol/feature/ERC721Factory
Integrated erc721factory contract methods
This commit is contained in:
commit
358ec3fdd1
39478
package-lock.json
generated
39478
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,7 @@
|
||||
"release": "release-it --non-interactive",
|
||||
"changelog": "auto-changelog -p",
|
||||
"prepublishOnly": "npm run build",
|
||||
"test": "npm run lint && npm run test:unit:cover && npm run test:integration:cover",
|
||||
"test:pool": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/NFTFactory.test.ts'",
|
||||
"test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/**/*.test.ts'",
|
||||
"test:unit:cover": "nyc --report-dir coverage/unit npm run test:unit",
|
||||
"test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/**/*.test.ts'",
|
||||
@ -46,7 +46,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@ethereum-navigator/navigator": "^0.5.3",
|
||||
"@oceanprotocol/contracts": "^0.6.9",
|
||||
"@oceanprotocol/contracts": "https://github.com/oceanprotocol/contracts#v4main",
|
||||
"cross-fetch": "^3.1.4",
|
||||
"crypto-js": "^4.0.0",
|
||||
"decimal.js": "^10.2.1",
|
||||
@ -55,7 +55,7 @@
|
||||
"node-abort-controller": "^2.0.0",
|
||||
"save-file": "^2.3.1",
|
||||
"uuid": "^8.3.2",
|
||||
"web3": "^1.6.0",
|
||||
"web3": ">=1.3.5",
|
||||
"web3-core": "^1.5.3",
|
||||
"web3-eth-contract": "^1.5.2"
|
||||
},
|
||||
|
108
src/data/address.json
Normal file
108
src/data/address.json
Normal file
@ -0,0 +1,108 @@
|
||||
{
|
||||
"rinkeby": {
|
||||
"DTFactory": "0x3fd7A00106038Fb5c802c6d63fa7147Fe429E83a",
|
||||
"BFactory": "0x53eDF9289B0898e1652Ce009AACf8D25fA9A42F8",
|
||||
"FixedRateExchange": "0xeD1DfC5F3a589CfC4E8B91C1fbfC18FC6699Fbde",
|
||||
"Metadata": "0xFD8a7b6297153397B7eb4356C47dbd381d58bFF4",
|
||||
"Ocean": "0x8967BCF84170c91B0d24D4302C2376283b0B3a07",
|
||||
"Dispenser": "0x623744Cd25Ed553d3b4722667697F926cf99658B",
|
||||
"chainId": 4,
|
||||
"startBlock": 7294090
|
||||
},
|
||||
"ropsten": {
|
||||
"DTFactory": "0x6ebcCa6df2CAba986FCF44E64Ee82251c1455Dcc",
|
||||
"BFactory": "0x75be6e18c80A487C8b49663bf14f80A6495045B2",
|
||||
"FixedRateExchange": "0xA7a711A09396DF82D9be46A26B48BafdB9BB4fA6",
|
||||
"Metadata": "0x3cd7Ef1F207E1a46AAd7D5d7F5f0A5cF081Fc726",
|
||||
"Ocean": "0x5e8DCB2AfA23844bcc311B00Ad1A0C30025aADE9",
|
||||
"Dispenser": "0xc37F8341Ac6e4a94538302bCd4d49Cf0852D30C0",
|
||||
"chainId": 3,
|
||||
"startBlock": 9227563
|
||||
},
|
||||
"development": {
|
||||
"Ocean": "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB",
|
||||
"OPFCommunityFeeCollector": "0x9E545E3C0baAB3E08CdfD552C960A1050f373042",
|
||||
"chainId": 31337,
|
||||
"startBlock": 0,
|
||||
"v4": {
|
||||
"Metadata": "0x851356ae760d987E095750cCeb3bC6014560891C",
|
||||
"ERC721Factory": "0x95401dc811bb5740090279Ba06cfA8fcF6113778",
|
||||
"ERC20Template": "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
|
||||
"ERC721Template": "0xf5059a5D33d5853360D16C683c16e67980206f36",
|
||||
"Router": "0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690",
|
||||
"FixedPrice": "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB",
|
||||
"Staking": "0x9E545E3C0baAB3E08CdfD552C960A1050f373042",
|
||||
"poolTemplate": "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E"
|
||||
},
|
||||
"v3": {}
|
||||
},
|
||||
"mainnet": {
|
||||
"DTFactory": "0x57317f97E9EA49eBd19f7c9bB7c180b8cDcbDeB9",
|
||||
"BFactory": "0xbe0083053744ECb871510C88dC0f6b77Da162706",
|
||||
"FixedRateExchange": "0x608d05214E42722B94a54cF6114d4840FCfF84e1",
|
||||
"Metadata": "0x1a4b70d8c9DcA47cD6D0Fb3c52BB8634CA1C0Fdf",
|
||||
"Ocean": "0x967da4048cD07aB37855c090aAF366e4ce1b9F48",
|
||||
"Dispenser": "0xDEfD0018969cd2d4E648209F876ADe184815f038",
|
||||
"chainId": 1,
|
||||
"startBlock": 11005222
|
||||
},
|
||||
"polygon": {
|
||||
"DTFactory": "0xF6410bf5d773C7a41ebFf972f38e7463FA242477",
|
||||
"BFactory": "0x69B6E54Ad2b3c2801d11d8Ad56ea1d892555b776",
|
||||
"FixedRateExchange": "0x2112Eb973af1DBf83a4f11eda82f7a7527D7Fde5",
|
||||
"Metadata": "0x80E63f73cAc60c1662f27D2DFd2EA834acddBaa8",
|
||||
"Ocean": "0x282d8efCe846A88B159800bd4130ad77443Fa1A1",
|
||||
"Dispenser": "0x30E4CC2C7A9c6aA2b2Ce93586E3Df24a3A00bcDD",
|
||||
"chainId": 137,
|
||||
"startBlock": 11005222
|
||||
},
|
||||
"moonbeamalpha": {
|
||||
"DTFactory": "0x80E63f73cAc60c1662f27D2DFd2EA834acddBaa8",
|
||||
"BFactory": "0x30E4CC2C7A9c6aA2b2Ce93586E3Df24a3A00bcDD",
|
||||
"FixedRateExchange": "0xDEfD0018969cd2d4E648209F876ADe184815f038",
|
||||
"Metadata": "0x9C9eE07b8Ce907D2f9244F8317C1Ed29A3193bAe",
|
||||
"Ocean": "0x3c21a90599b5B7f37014cA5Bf30d3f1b73d7e391",
|
||||
"Dispenser": "0x042D709b72B437d7d387F2679bD4ac060e561c9f",
|
||||
"chainId": 1287,
|
||||
"startBlock": 90707
|
||||
},
|
||||
"undefined": {
|
||||
"DTFactory": "0xC54b688d81b6B3bab9834D9D7afd8655641EEdA7",
|
||||
"BFactory": "0x082DD8b8A6eD335364739004280bD4eF41cB6Bd9",
|
||||
"FixedRateExchange": "0x19dcb303B4b56e7983b7F441696B326264c9008c",
|
||||
"Metadata": "0x5F71F2ffF1639D927d43e4965C2EC6cCe9505222",
|
||||
"Dispenser": "0xA4eD47bCAAe977fB1AE39A5DF905AC7420a5e095",
|
||||
"chainId": 0,
|
||||
"startBlock": 0
|
||||
},
|
||||
"gaiaxtestnet": {
|
||||
"DTFactory": "0x2720d405ef7cDC8a2E2e5AeBC8883C99611d893C",
|
||||
"BFactory": "0xc37F8341Ac6e4a94538302bCd4d49Cf0852D30C0",
|
||||
"FixedRateExchange": "0x3c21a90599b5B7f37014cA5Bf30d3f1b73d7e391",
|
||||
"Metadata": "0xCfDdA22C9837aE76E0faA845354f33C62E03653a",
|
||||
"Dispenser": "0x4E6058dC00e90C0DCA47A5d0D3346F409939A5ab",
|
||||
"Ocean": "0x80E63f73cAc60c1662f27D2DFd2EA834acddBaa8",
|
||||
"chainId": 2021000,
|
||||
"startBlock": 177644
|
||||
},
|
||||
"mumbai": {
|
||||
"DTFactory": "0x4E6058dC00e90C0DCA47A5d0D3346F409939A5ab",
|
||||
"BFactory": "0x159924ca0F47D6F704B97E29099b89e518A17B5E",
|
||||
"FixedRateExchange": "0xc313e19146Fc9a04470689C9d41a4D3054693531",
|
||||
"Metadata": "0x98679D582AB3398C03D3308dEB9c7AeC50B52ded",
|
||||
"Dispenser": "0x1d535147a97bd87c8443125376E6671B60556E07",
|
||||
"Ocean": "0xd8992Ed72C445c35Cb4A2be468568Ed1079357c8",
|
||||
"chainId": 80001,
|
||||
"startBlock": 14791845
|
||||
},
|
||||
"bsc": {
|
||||
"DTFactory": "0xE9397625Df9B63f0C152f975234b7988b54710B8",
|
||||
"BFactory": "0xc313e19146Fc9a04470689C9d41a4D3054693531",
|
||||
"FixedRateExchange": "0x98679D582AB3398C03D3308dEB9c7AeC50B52ded",
|
||||
"Metadata": "0x1d535147a97bd87c8443125376E6671B60556E07",
|
||||
"Dispenser": "0xFe7967A5176fDAFa8DE109b3507016B885a82D6e",
|
||||
"Ocean": "0xdce07662ca8ebc241316a15b611c89711414dd1a",
|
||||
"chainId": 56,
|
||||
"startBlock": 8114772
|
||||
}
|
||||
}
|
@ -1,9 +1,14 @@
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import Web3 from 'web3'
|
||||
import { TransactionReceipt } from 'web3-core'
|
||||
import { AbiItem } from 'web3-utils'
|
||||
import defaultFactory721ABI from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||
import { Logger, getFairGasPrice, generateDtName } from '../utils'
|
||||
|
||||
interface Template {
|
||||
templateAddress: string
|
||||
isActive: boolean
|
||||
}
|
||||
/**
|
||||
* Provides an interface for NFT DataTokens
|
||||
*/
|
||||
@ -88,4 +93,278 @@ export class NFTFactory {
|
||||
}
|
||||
return tokenAddress
|
||||
}
|
||||
|
||||
/** Get Current NFT Count (NFT created)
|
||||
* @return {Promise<number>} Number of NFT created from this factory
|
||||
*/
|
||||
public async getCurrentNFTCount(): Promise<number> {
|
||||
const trxReceipt = await this.factory721.methods.getCurrentNFTCount().call()
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Get Current Datatoken Count
|
||||
* @return {Promise<number>} Number of DTs created from this factory
|
||||
*/
|
||||
public async getCurrentTokenCount(): Promise<number> {
|
||||
const trxReceipt = await this.factory721.methods.getCurrentTokenCount().call()
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Get Factory Owner
|
||||
* @return {Promise<string>} Factory Owner address
|
||||
*/
|
||||
public async getOwner(): Promise<string> {
|
||||
const trxReceipt = await this.factory721.methods.owner().call()
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Get Current NFT Template Count
|
||||
* @return {Promise<number>} Number of NFT Template added to this factory
|
||||
*/
|
||||
public async getCurrentNFTTemplateCount(): Promise<number> {
|
||||
const count = await this.factory721.methods.getCurrentNFTTemplateCount().call()
|
||||
return count
|
||||
}
|
||||
|
||||
/** Get Current Template Datatoken (ERC20) Count
|
||||
* @return {Promise<number>} Number of ERC20 Template added to this factory
|
||||
*/
|
||||
public async getCurrentTokenTemplateCount(): Promise<number> {
|
||||
const count = await this.factory721.methods.getCurrentTemplateCount().call()
|
||||
return count
|
||||
}
|
||||
|
||||
/** Get NFT Template
|
||||
* @param {Number} index Template index
|
||||
* @return {Promise<Template>} Number of Template added to this factory
|
||||
*/
|
||||
public async getNFTTemplate(index: number): Promise<Template> {
|
||||
const template = await this.factory721.methods.getNFTTemplate(index).call()
|
||||
return template
|
||||
}
|
||||
|
||||
/** Get Datatoken(erc20) Template
|
||||
* @param {Number} index Template index
|
||||
* @return {Promise<Template>} DT Template info
|
||||
*/
|
||||
public async getTokenTemplate(index: number): Promise<Template> {
|
||||
const template = await this.factory721.methods.getTokenTemplate(index).call()
|
||||
return template
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new erc721 token template - only factory Owner
|
||||
* @param {String} address
|
||||
* @param {String} templateAddress template address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async addNFTTemplate(
|
||||
address: string,
|
||||
templateAddress: string
|
||||
): Promise<TransactionReceipt> {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Factory Owner`)
|
||||
}
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.factory721.methods
|
||||
.add721TokenTemplate(templateAddress)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await this.factory721.methods
|
||||
.add721TokenTemplate(templateAddress)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable token template - only factory Owner
|
||||
* @param {String} address
|
||||
* @param {Number} templateIndex index of the template we want to disable
|
||||
* @return {Promise<TransactionReceipt>} current token template count
|
||||
*/
|
||||
public async disableNFTTemplate(
|
||||
address: string,
|
||||
templateIndex: number
|
||||
): Promise<TransactionReceipt> {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Factory Owner`)
|
||||
}
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.factory721.methods
|
||||
.disable721TokenTemplate(templateIndex)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await this.factory721.methods
|
||||
.disable721TokenTemplate(templateIndex)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Reactivate a previously disabled token template - only factory Owner
|
||||
* @param {String} address
|
||||
* @param {Number} templateIndex index of the template we want to reactivate
|
||||
* @return {Promise<TransactionReceipt>} current token template count
|
||||
*/
|
||||
public async reactivateNFTTemplate(
|
||||
address: string,
|
||||
templateIndex: number
|
||||
): Promise<TransactionReceipt> {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Factory Owner`)
|
||||
}
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.factory721.methods
|
||||
.reactivate721TokenTemplate(templateIndex)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await this.factory721.methods
|
||||
.reactivate721TokenTemplate(templateIndex)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new erc721 token template - only factory Owner
|
||||
* @param {String} address
|
||||
* @param {String} templateAddress template address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async addTokenTemplate(
|
||||
address: string,
|
||||
templateAddress: string
|
||||
): Promise<TransactionReceipt> {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Factory Owner`)
|
||||
}
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.factory721.methods
|
||||
.addTokenTemplate(templateAddress)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await this.factory721.methods
|
||||
.addTokenTemplate(templateAddress)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable token template - only factory Owner
|
||||
* @param {String} address
|
||||
* @param {Number} templateIndex index of the template we want to disable
|
||||
* @return {Promise<TransactionReceipt>} current token template count
|
||||
*/
|
||||
public async disableTokenTemplate(
|
||||
address: string,
|
||||
templateIndex: number
|
||||
): Promise<TransactionReceipt> {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Factory Owner`)
|
||||
}
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.factory721.methods
|
||||
.disableTokenTemplate(templateIndex)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await this.factory721.methods
|
||||
.disableTokenTemplate(templateIndex)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Reactivate a previously disabled token template - only factory Owner
|
||||
* @param {String} address
|
||||
* @param {Number} templateIndex index of the template we want to reactivate
|
||||
* @return {Promise<TransactionReceipt>} current token template count
|
||||
*/
|
||||
public async reactivateTokenTemplate(
|
||||
address: string,
|
||||
templateIndex: number
|
||||
): Promise<TransactionReceipt> {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Factory Owner`)
|
||||
}
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.factory721.methods
|
||||
.reactivateTokenTemplate(templateIndex)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await this.factory721.methods
|
||||
.reactivateTokenTemplate(templateIndex)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import defaultERC20ABI from '@oceanprotocol/contracts/artifacts/contracts/interf
|
||||
import { PoolFactory } from './PoolFactory'
|
||||
import { Logger } from '../../utils'
|
||||
|
||||
export class OceanPoolV4 extends PoolFactory {
|
||||
export class OceanPool extends PoolFactory {
|
||||
public oceanAddress: string = null
|
||||
public dtAddress: string = null
|
||||
public startBlock: number
|
||||
|
@ -37,7 +37,7 @@ export class PoolFactory {
|
||||
public async deployPool(
|
||||
account: string,
|
||||
tokens: string[],
|
||||
weights: string[],
|
||||
weightsInWei: string[],
|
||||
swapFeePercentage: number,
|
||||
swapMarketFee: number,
|
||||
owner: string
|
||||
@ -53,5 +53,6 @@ export class PoolFactory {
|
||||
this.logger.log(e)
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
return estGas
|
||||
}
|
||||
}
|
||||
|
6
src/pools/dispenser/Dispenser.ts
Normal file
6
src/pools/dispenser/Dispenser.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import Web3 from 'web3'
|
||||
|
||||
export class Dispenser {
|
||||
public GASLIMIT_DEFAULT = 1000000
|
||||
public web3: Web3 = null
|
||||
}
|
@ -0,0 +1 @@
|
||||
export * from './Dispenser'
|
6
src/pools/fixedRate/FixedRateExchange.ts
Normal file
6
src/pools/fixedRate/FixedRateExchange.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import Web3 from 'web3'
|
||||
|
||||
export class FixedRateExchange {
|
||||
public GASLIMIT_DEFAULT = 1000000
|
||||
public web3: Web3 = null
|
||||
}
|
@ -0,0 +1 @@
|
||||
export * from './FixedRateExchange'
|
@ -1,3 +1,3 @@
|
||||
export * from './balancer'
|
||||
export * from './dispencer'
|
||||
export * from './dispenser'
|
||||
export * from './fixedRate'
|
||||
|
@ -2,7 +2,7 @@ import Config from '../models/Config'
|
||||
import fs from 'fs'
|
||||
import { homedir } from 'os'
|
||||
// eslint-disable-next-line import/no-named-default
|
||||
import { default as DefaultContractsAddresses } from '@oceanprotocol/contracts/artifacts/address.json'
|
||||
import { default as DefaultContractsAddresses } from '../data/address.json' // temporary untill we can get them from the contract arficats
|
||||
import Logger from './Logger'
|
||||
|
||||
export interface ConfigHelperConfig extends Config {
|
||||
|
296
test/TestContractHandler.ts
Normal file
296
test/TestContractHandler.ts
Normal file
@ -0,0 +1,296 @@
|
||||
import Web3 from 'web3'
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import { AbiItem } from 'web3-utils/types'
|
||||
|
||||
// TODO: add OPF deployment
|
||||
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
||||
const oceanAddress = '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
||||
export class TestContractHandler {
|
||||
public accounts: string[]
|
||||
public ERC721Factory: Contract
|
||||
public ERC20Template: Contract
|
||||
public ERC721Template: Contract
|
||||
public Router: Contract
|
||||
public SideStaking: Contract
|
||||
public FixedRate: Contract
|
||||
public Dispenser: Contract
|
||||
public OPFCollector: Contract
|
||||
public PoolTemplate: Contract
|
||||
|
||||
public ERC721FactoryBytecode: string
|
||||
public ERC20TemplateBytecode: string
|
||||
public ERC721TemplateBytecode: string
|
||||
public RouterBytecode: string
|
||||
public SideStakingBytecode: string
|
||||
public FixedRateBytecode: string
|
||||
public DispenserBytecode: string
|
||||
public PoolTemplateBytecode: string
|
||||
public OPFCollectorBytecode: string
|
||||
|
||||
public factory721Address: string
|
||||
public template721Address: string
|
||||
public template20Address: string
|
||||
public routerAddress: string
|
||||
public sideStakingAddress: string
|
||||
public fixedRateAddress: string
|
||||
public dispenserAddress: string
|
||||
public poolTemplateAddress: string
|
||||
public opfCollectorAddress: string
|
||||
|
||||
public web3: Web3
|
||||
|
||||
constructor(
|
||||
web3: Web3,
|
||||
ERC721TemplateABI: AbiItem | AbiItem[],
|
||||
ERC20TemplateABI: AbiItem | AbiItem[],
|
||||
PoolTemplateABI?: AbiItem | AbiItem[],
|
||||
ERC721FactoryABI?: AbiItem | AbiItem[],
|
||||
RouterABI?: AbiItem | AbiItem[],
|
||||
SideStakingABI?: AbiItem | AbiItem[],
|
||||
FixedRateABI?: AbiItem | AbiItem[],
|
||||
DispenserABI?: AbiItem | AbiItem[],
|
||||
|
||||
template721Bytecode?: string,
|
||||
template20Bytecode?: string,
|
||||
poolTemplateBytecode?: string,
|
||||
factory721Bytecode?: string,
|
||||
routerBytecode?: string,
|
||||
sideStakingBytecode?: string,
|
||||
fixedRateBytecode?: string,
|
||||
dispenserBytecode?: string
|
||||
) {
|
||||
this.web3 = web3
|
||||
this.ERC721Template = new this.web3.eth.Contract(ERC721TemplateABI)
|
||||
this.ERC20Template = new this.web3.eth.Contract(ERC20TemplateABI)
|
||||
this.PoolTemplate = new this.web3.eth.Contract(PoolTemplateABI)
|
||||
this.ERC721Factory = new this.web3.eth.Contract(ERC721FactoryABI)
|
||||
this.Router = new this.web3.eth.Contract(RouterABI)
|
||||
this.SideStaking = new this.web3.eth.Contract(SideStakingABI)
|
||||
this.FixedRate = new this.web3.eth.Contract(FixedRateABI)
|
||||
this.Dispenser = new this.web3.eth.Contract(DispenserABI)
|
||||
|
||||
this.ERC721FactoryBytecode = factory721Bytecode
|
||||
this.ERC20TemplateBytecode = template20Bytecode
|
||||
this.PoolTemplateBytecode = poolTemplateBytecode
|
||||
this.ERC721TemplateBytecode = template721Bytecode
|
||||
this.RouterBytecode = routerBytecode
|
||||
this.SideStakingBytecode = sideStakingBytecode
|
||||
this.FixedRateBytecode = fixedRateBytecode
|
||||
this.DispenserBytecode = dispenserBytecode
|
||||
}
|
||||
|
||||
public async getAccounts(): Promise<string[]> {
|
||||
this.accounts = await this.web3.eth.getAccounts()
|
||||
return this.accounts
|
||||
}
|
||||
|
||||
public async deployContracts(owner: string, routerABI?: AbiItem | AbiItem[]) {
|
||||
let estGas
|
||||
|
||||
// DEPLOY POOL TEMPLATE
|
||||
// get est gascost
|
||||
estGas = await this.PoolTemplate.deploy({
|
||||
data: this.PoolTemplateBytecode,
|
||||
arguments: []
|
||||
}).estimateGas(function (err, estGas) {
|
||||
if (err) console.log('DeployContracts: ' + err)
|
||||
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) {
|
||||
return contract.options.address
|
||||
})
|
||||
|
||||
// DEPLOY ERC20 TEMPLATE
|
||||
// get est gascost
|
||||
estGas = await this.ERC20Template.deploy({
|
||||
data: this.ERC20TemplateBytecode,
|
||||
arguments: []
|
||||
}).estimateGas(function (err, estGas) {
|
||||
if (err) console.log('DeployContracts: ' + err)
|
||||
return estGas
|
||||
})
|
||||
// deploy the contract and get it's address
|
||||
this.template20Address = await this.ERC20Template.deploy({
|
||||
data: this.ERC20TemplateBytecode,
|
||||
arguments: []
|
||||
})
|
||||
.send({
|
||||
from: owner,
|
||||
gas: estGas + 1,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
.then(function (contract) {
|
||||
return contract.options.address
|
||||
})
|
||||
|
||||
// DEPLOY ERC721 TEMPLATE
|
||||
// get est gascost
|
||||
estGas = await this.ERC721Template.deploy({
|
||||
data: this.ERC721TemplateBytecode,
|
||||
arguments: []
|
||||
}).estimateGas(function (err, estGas) {
|
||||
if (err) console.log('DeployContracts: ' + err)
|
||||
return estGas
|
||||
})
|
||||
// deploy the contract and get it's address
|
||||
this.template721Address = await this.ERC721Template.deploy({
|
||||
data: this.ERC721TemplateBytecode,
|
||||
arguments: []
|
||||
})
|
||||
.send({
|
||||
from: owner,
|
||||
gas: estGas + 1,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
.then(function (contract) {
|
||||
return contract.options.address
|
||||
})
|
||||
|
||||
// DEPLOY ROUTER
|
||||
estGas = await this.Router.deploy({
|
||||
data: this.RouterBytecode,
|
||||
arguments: [owner, oceanAddress, this.poolTemplateAddress, communityCollector, []]
|
||||
}).estimateGas(function (err, estGas) {
|
||||
if (err) console.log('DeployContracts: ' + err)
|
||||
return estGas
|
||||
})
|
||||
// deploy the contract and get it's address
|
||||
this.routerAddress = await this.Router.deploy({
|
||||
data: this.RouterBytecode,
|
||||
arguments: [owner, oceanAddress, this.poolTemplateAddress, communityCollector, []]
|
||||
})
|
||||
.send({
|
||||
from: owner,
|
||||
gas: estGas + 1,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
.then(function (contract) {
|
||||
return contract.options.address
|
||||
})
|
||||
|
||||
// DEPLOY SIDE STAKING
|
||||
estGas = await this.SideStaking.deploy({
|
||||
data: this.SideStakingBytecode,
|
||||
arguments: [this.routerAddress]
|
||||
}).estimateGas(function (err, estGas) {
|
||||
if (err) console.log('DeployContracts: ' + err)
|
||||
return estGas
|
||||
})
|
||||
// deploy the contract and get it's address
|
||||
this.sideStakingAddress = await this.SideStaking.deploy({
|
||||
data: this.SideStakingBytecode,
|
||||
arguments: [this.routerAddress]
|
||||
})
|
||||
.send({
|
||||
from: owner,
|
||||
gas: estGas + 1,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
.then(function (contract) {
|
||||
return contract.options.address
|
||||
})
|
||||
|
||||
// DEPLOY FIXED RATE
|
||||
estGas = await this.FixedRate.deploy({
|
||||
data: this.FixedRateBytecode,
|
||||
arguments: [this.routerAddress, communityCollector]
|
||||
}).estimateGas(function (err, estGas) {
|
||||
if (err) console.log('DeployContracts: ' + err)
|
||||
return estGas
|
||||
})
|
||||
// deploy the contract and get it's address
|
||||
this.fixedRateAddress = await this.FixedRate.deploy({
|
||||
data: this.FixedRateBytecode,
|
||||
arguments: [this.routerAddress, communityCollector]
|
||||
})
|
||||
.send({
|
||||
from: owner,
|
||||
gas: estGas + 1,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
.then(function (contract) {
|
||||
return contract.options.address
|
||||
})
|
||||
|
||||
// DEPLOY Dispenser
|
||||
estGas = await this.Dispenser.deploy({
|
||||
data: this.DispenserBytecode,
|
||||
arguments: [this.routerAddress]
|
||||
}).estimateGas(function (err, estGas) {
|
||||
if (err) console.log('DeployContracts: ' + err)
|
||||
return estGas
|
||||
})
|
||||
// deploy the contract and get it's address
|
||||
this.dispenserAddress = await this.Dispenser.deploy({
|
||||
data: this.DispenserBytecode,
|
||||
arguments: [this.routerAddress]
|
||||
})
|
||||
.send({
|
||||
from: owner,
|
||||
gas: estGas + 1,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
.then(function (contract) {
|
||||
return contract.options.address
|
||||
})
|
||||
|
||||
// DEPLOY ERC721 FACTORY
|
||||
estGas = await this.ERC721Factory.deploy({
|
||||
data: this.ERC721FactoryBytecode,
|
||||
arguments: [
|
||||
this.template721Address,
|
||||
this.template20Address,
|
||||
communityCollector,
|
||||
this.routerAddress
|
||||
]
|
||||
}).estimateGas(function (err, estGas) {
|
||||
if (err) console.log('DeployContracts: ' + err)
|
||||
return estGas
|
||||
})
|
||||
// deploy the contract and get it's address
|
||||
this.factory721Address = await this.ERC721Factory.deploy({
|
||||
data: this.ERC721FactoryBytecode,
|
||||
arguments: [
|
||||
this.template721Address,
|
||||
this.template20Address,
|
||||
communityCollector,
|
||||
this.routerAddress
|
||||
]
|
||||
})
|
||||
.send({
|
||||
from: owner,
|
||||
gas: estGas + 1,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
.then(function (contract) {
|
||||
return contract.options.address
|
||||
})
|
||||
|
||||
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 })
|
||||
}
|
||||
}
|
9
test/integration/tsconfig.json
Normal file
9
test/integration/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"lib": ["es6", "es7"],
|
||||
"noUnusedLocals": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
}
|
||||
}
|
11
test/unit/.mocharc.json
Normal file
11
test/unit/.mocharc.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"require": [
|
||||
"ts-node/register",
|
||||
"source-map-support/register",
|
||||
"mock-local-storage"
|
||||
],
|
||||
"full-trace": true,
|
||||
"bail": true,
|
||||
"exit": true,
|
||||
"timeout": "20000"
|
||||
}
|
152
test/unit/NFTFactory.test.ts
Normal file
152
test/unit/NFTFactory.test.ts
Normal file
@ -0,0 +1,152 @@
|
||||
import { assert } from 'chai'
|
||||
import { AbiItem } from 'web3-utils/types'
|
||||
import { TestContractHandler } from '../TestContractHandler'
|
||||
import Web3 from 'web3'
|
||||
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||
import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
|
||||
import SideStaking from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
||||
import Router from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
|
||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.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 PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
||||
import { LoggerInstance } from '../../src/utils'
|
||||
// import { NFTDataToken } from '../../../src/datatokens/NFTDatatoken'
|
||||
import { NFTFactory } from '../../src/factories/NFTFactory'
|
||||
// import { DT20Factory } from '../../../src/factories/DT20Factory'
|
||||
|
||||
const web3 = new Web3('http://127.0.0.1:8545')
|
||||
|
||||
describe('NFT Factory test', () => {
|
||||
let factoryOwner: string
|
||||
let nftOwner: string
|
||||
let user1: string
|
||||
let user2: string
|
||||
let contracts: TestContractHandler
|
||||
let nftFactory: NFTFactory
|
||||
|
||||
const nftName = 'NFT'
|
||||
const nftSymbol = 'NFTSymbol'
|
||||
const nftTemplateIndex = 1
|
||||
const data = web3.utils.asciiToHex('SomeData')
|
||||
const flags = web3.utils.asciiToHex(
|
||||
'f8929916089218bdb4aa78c3ecd16633afd44b8aef89299160'
|
||||
)
|
||||
|
||||
// TODO: complete unit test
|
||||
it('should deploy contracts', async () => {
|
||||
contracts = new TestContractHandler(
|
||||
web3,
|
||||
ERC721Template.abi as AbiItem[],
|
||||
ERC20Template.abi as AbiItem[],
|
||||
PoolTemplate.abi as AbiItem[],
|
||||
ERC721Factory.abi as AbiItem[],
|
||||
Router.abi as AbiItem[],
|
||||
SideStaking.abi as AbiItem[],
|
||||
FixedRate.abi as AbiItem[],
|
||||
Dispenser.abi as AbiItem[],
|
||||
|
||||
ERC721Template.bytecode,
|
||||
ERC20Template.bytecode,
|
||||
PoolTemplate.bytecode,
|
||||
ERC721Factory.bytecode,
|
||||
Router.bytecode,
|
||||
SideStaking.bytecode,
|
||||
FixedRate.bytecode,
|
||||
Dispenser.bytecode
|
||||
)
|
||||
await contracts.getAccounts()
|
||||
factoryOwner = contracts.accounts[0]
|
||||
nftOwner = contracts.accounts[1]
|
||||
user1 = contracts.accounts[2]
|
||||
console.log(factoryOwner)
|
||||
await contracts.deployContracts(factoryOwner, Router.abi as AbiItem[])
|
||||
|
||||
console.log('BOOM')
|
||||
})
|
||||
|
||||
it('should initiate NFTFactory instance', async () => {
|
||||
nftFactory = new NFTFactory(contracts.factory721Address, web3, LoggerInstance)
|
||||
})
|
||||
|
||||
it('#getCurrentNFTCount - should return actual nft count (0)', async () => {
|
||||
const nftCount = await nftFactory.getCurrentNFTCount()
|
||||
assert(nftCount === 0)
|
||||
})
|
||||
|
||||
it('#getCurrentTokenCount - should return actual token count (0)', async () => {
|
||||
const tokenCount = await nftFactory.getCurrentTokenCount()
|
||||
assert(tokenCount === 0)
|
||||
})
|
||||
it('#getOwner - should return actual owner', async () => {
|
||||
const owner = await nftFactory.getOwner()
|
||||
assert(owner === contracts.accounts[0])
|
||||
})
|
||||
it('#getCurrentNFTTemplateCount - should return actual nft template count (1)', async () => {
|
||||
const nftTemplateCount = await nftFactory.getCurrentNFTTemplateCount()
|
||||
assert(nftTemplateCount === 1)
|
||||
})
|
||||
it('#getCurrentTokenTemplateCount - should return actual token template count (1)', async () => {
|
||||
const tokenTemplateCount = await nftFactory.getCurrentTokenTemplateCount()
|
||||
assert(tokenTemplateCount === 1)
|
||||
})
|
||||
it('#getNFTTemplate - should return NFT template struct', async () => {
|
||||
const nftTemplate = await nftFactory.getNFTTemplate(1)
|
||||
assert(nftTemplate.isActive === true)
|
||||
assert(nftTemplate.templateAddress === contracts.template721Address)
|
||||
})
|
||||
it('#getTokenTemplate - should return Token template struct', async () => {
|
||||
const tokenTemplate = await nftFactory.getTokenTemplate(1)
|
||||
assert(tokenTemplate.isActive === true)
|
||||
assert(tokenTemplate.templateAddress === contracts.template20Address)
|
||||
})
|
||||
it('#addNFTTemplate - should add NFT template if factory owner', async () => {
|
||||
await nftFactory.addNFTTemplate(contracts.accounts[0], contracts.fixedRateAddress) // contracts.fixedRateAddress it's just a dummy contract in this case
|
||||
const nftTemplateCount = await nftFactory.getCurrentNFTTemplateCount()
|
||||
assert(nftTemplateCount === 2)
|
||||
const nftTemplate = await nftFactory.getNFTTemplate(2)
|
||||
assert(nftTemplate.isActive === true)
|
||||
assert(nftTemplate.templateAddress === contracts.fixedRateAddress)
|
||||
})
|
||||
it('#disableNFTTemplate - should disable NFT template if factory owner', async () => {
|
||||
let nftTemplate = await nftFactory.getNFTTemplate(2)
|
||||
assert(nftTemplate.isActive === true)
|
||||
await nftFactory.disableNFTTemplate(contracts.accounts[0], 2) // owner disable template index = 2
|
||||
|
||||
nftTemplate = await nftFactory.getNFTTemplate(2)
|
||||
assert(nftTemplate.isActive === false)
|
||||
})
|
||||
it('#reactivateNFTTemplate - should disable NFT template if factory owner', async () => {
|
||||
let nftTemplate = await nftFactory.getNFTTemplate(2)
|
||||
assert(nftTemplate.isActive === false)
|
||||
await nftFactory.reactivateNFTTemplate(contracts.accounts[0], 2) // owner reactivate template index = 2
|
||||
|
||||
nftTemplate = await nftFactory.getNFTTemplate(2)
|
||||
assert(nftTemplate.isActive === true)
|
||||
})
|
||||
it('#addTokenTemplate - should add Datatoken template if factory owner', async () => {
|
||||
await nftFactory.addTokenTemplate(contracts.accounts[0], contracts.fixedRateAddress) // contracts.fixedRateAddress it's just a dummy contract in this case
|
||||
const tokenTemplateCount = await nftFactory.getCurrentTokenTemplateCount()
|
||||
assert(tokenTemplateCount === 2)
|
||||
const nftTemplate = await nftFactory.getTokenTemplate(2)
|
||||
assert(nftTemplate.isActive === true)
|
||||
assert(nftTemplate.templateAddress === contracts.fixedRateAddress)
|
||||
})
|
||||
|
||||
it('#disableTokenTemplate - should disable Token template if factory owner', async () => {
|
||||
let tokenTemplate = await nftFactory.getTokenTemplate(2)
|
||||
assert(tokenTemplate.isActive === true)
|
||||
await nftFactory.disableTokenTemplate(contracts.accounts[0], 2) // owner disable template index = 2
|
||||
|
||||
tokenTemplate = await nftFactory.getTokenTemplate(2)
|
||||
assert(tokenTemplate.isActive === false)
|
||||
})
|
||||
it('#reactivateTokenTemplate - should disable Token template if factory owner', async () => {
|
||||
let tokenTemplate = await nftFactory.getTokenTemplate(2)
|
||||
assert(tokenTemplate.isActive === false)
|
||||
await nftFactory.reactivateTokenTemplate(contracts.accounts[0], 2) // owner reactivate template index = 2
|
||||
|
||||
tokenTemplate = await nftFactory.getTokenTemplate(2)
|
||||
assert(tokenTemplate.isActive === true)
|
||||
})
|
||||
})
|
9
test/unit/tsconfig.json
Normal file
9
test/unit/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"lib": ["es6", "es7"],
|
||||
"noUnusedLocals": false,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user