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

update to contracts 0.4.0

This commit is contained in:
alexcos20 2020-08-30 23:56:25 -07:00
parent a4e8315734
commit 220261cada
14 changed files with 86 additions and 33 deletions

6
package-lock.json generated
View File

@ -880,9 +880,9 @@
}
},
"@oceanprotocol/contracts": {
"version": "0.3.5",
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.3.5.tgz",
"integrity": "sha512-z7ziNbRwsPrJi+zGyokgUEKivD90a5/9jjV+WLj1q5U96g60rd5rxox4EKNPNGlHx/m5rWBJhHBV4rseJjtFjg=="
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.4.0.tgz",
"integrity": "sha512-K7enUvVKexr5USpzZC0GRG+RCNH8A9A1bwbKKi4+YR2ClXHfiLqPak2Gf+McrfsOhlPEr7fnYACITgbs0CwrBQ=="
},
"@octokit/auth-token": {
"version": "2.4.2",

View File

@ -40,7 +40,7 @@
},
"dependencies": {
"@ethereum-navigator/navigator": "^0.5.0",
"@oceanprotocol/contracts": "^0.3.5",
"@oceanprotocol/contracts": "^0.4.0",
"decimal.js": "^10.2.0",
"fs": "0.0.1-security",
"node-fetch": "^2.6.0",

View File

@ -321,7 +321,7 @@ export class OceanPool extends Pool {
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
from: account
})
const events = await factory.getPastEvents('SPoolRegistered', {
const events = await factory.getPastEvents('BPoolRegistered', {
filter: {},
fromBlock: 0,
toBlock: 'latest'

View File

@ -1,7 +1,7 @@
import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types'
import Decimal from 'decimal.js'
import jsonpoolABI from '@oceanprotocol/contracts/artifacts/SPool.json'
import jsonpoolABI from '@oceanprotocol/contracts/artifacts/BPool.json'
import { PoolFactory } from './PoolFactory'
/**

View File

@ -1,6 +1,6 @@
import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types'
import jsonFactoryABI from '@oceanprotocol/contracts/artifacts/SFactory.json'
import jsonFactoryABI from '@oceanprotocol/contracts/artifacts/BFactory.json'
export class PoolFactory {
public GASLIMIT_DEFAULT = 5000000
@ -43,13 +43,13 @@ export class PoolFactory {
})
const transactiondata = await factory.methods
.newSPool()
.newBPool()
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
let pooladdress: string
try {
pooladdress = transactiondata.events.SPoolRegistered.returnValues[0]
pooladdress = transactiondata.events.BPoolRegistered.returnValues[0]
} catch (e) {
console.error(e)
}

View File

@ -35,26 +35,37 @@ export class DataTokens {
/**
* Create new datatoken
* @param {String} metaDataStoreURI
* @param {String} name Token name
* @param {String} symbol Token symbol
* @param {String} cap Maximum cap (Number) - will be converted to wei
* @param {String} address
* @return {Promise<string>} datatoken address
*/
public async create(metaDataStoreURI: string, address: string): Promise<string> {
public async create(
metaDataStoreURI: string,
name: string,
symbol: string,
cap: string,
address: string
): Promise<string> {
// Create factory contract object
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
from: address
})
const estGas = await factory.methods
.createToken(metaDataStoreURI)
.createToken(metaDataStoreURI, name, symbol, this.web3.utils.toWei(cap))
.estimateGas(function (err, estGas) {
if (err) console.log('Datatokens: ' + err)
return estGas
})
// Invoke createToken function of the contract
const trxReceipt = await factory.methods.createToken(metaDataStoreURI).send({
from: address,
gas: estGas + 1,
gasPrice: '3000000000'
})
const trxReceipt = await factory.methods
.createToken(metaDataStoreURI, name, symbol, this.web3.utils.toWei(cap))
.send({
from: address,
gas: estGas + 1,
gasPrice: '3000000000'
})
let tokenAddress = null
try {

View File

@ -56,7 +56,10 @@ export class Assets extends Instantiable {
metadata: Metadata,
publisher: Account,
services: Service[] = [],
dtAddress?: string
dtAddress?: string,
name?: string,
symbol?: string,
cap?: string
): SubscribablePromise<CreateProgressStep, DDO> {
this.logger.log('Creating asset')
return new SubscribablePromise(async (observer) => {
@ -65,11 +68,20 @@ export class Assets extends Instantiable {
}
if (!dtAddress) {
this.logger.log('Creating datatoken')
if (!name) name = 'DataToken'
if (!symbol) symbol = 'DT'
if (!cap) cap = '1410000000000000000000000000'
observer.next(CreateProgressStep.CreatingDataToken)
const metadataStoreURI = this.ocean.metadatastore.getURI()
const jsonBlob = { t: 1, url: metadataStoreURI }
const { datatokens } = this.ocean
dtAddress = await datatokens.create(JSON.stringify(jsonBlob), publisher.getId())
dtAddress = await datatokens.create(
JSON.stringify(jsonBlob),
name,
symbol,
cap,
publisher.getId()
)
this.logger.log('DataToken creted')
observer.next(CreateProgressStep.DataTokenCreated)
}

View File

@ -1,7 +1,7 @@
import Web3 from 'web3'
import { Contract } from 'web3-eth-contract'
import { AbiItem } from 'web3-utils/types'
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
export class TestContractHandler {
public factory: Contract
public template: Contract
@ -40,7 +40,7 @@ export class TestContractHandler {
estGas = await this.template
.deploy({
data: this.templateBytecode,
arguments: ['Template Contract', 'TEMPLATE', minter, cap, blob]
arguments: ['Template Contract', 'TEMPLATE', minter, cap, blob, communityCollector]
})
.estimateGas(function (err, estGas) {
if (err) console.log('DeployContracts: ' + err)
@ -50,7 +50,7 @@ export class TestContractHandler {
this.templateAddress = await this.template
.deploy({
data: this.templateBytecode,
arguments: ['Template Contract', 'TEMPLATE', minter, cap, blob]
arguments: ['Template Contract', 'TEMPLATE', minter, cap, blob, communityCollector]
})
.send({
from: minter,
@ -64,7 +64,7 @@ export class TestContractHandler {
estGas = await this.factory
.deploy({
data: this.factoryBytecode,
arguments: [this.templateAddress]
arguments: [this.templateAddress, communityCollector]
})
.estimateGas(function (err, estGas) {
if (err) console.log('DeployContracts: ' + err)
@ -74,7 +74,7 @@ export class TestContractHandler {
this.factoryAddress = await this.factory
.deploy({
data: this.factoryBytecode,
arguments: [this.templateAddress]
arguments: [this.templateAddress, communityCollector]
})
.send({
from: minter,

View File

@ -79,7 +79,13 @@ describe('Compute flow', () => {
datatokensTemplate.abi as AbiItem[],
web3
)
tokenAddress = await datatoken.create(blob, alice.getId())
tokenAddress = await datatoken.create(
blob,
'AliceDT',
'DTA',
'10000000000',
alice.getId()
)
assert(tokenAddress != null)
})

View File

@ -57,7 +57,13 @@ describe('Marketplace flow', () => {
datatokensTemplate.abi as AbiItem[],
web3
)
tokenAddress = await datatoken.create(blob, alice.getId())
tokenAddress = await datatoken.create(
blob,
'AliceDT',
'DTA',
'10000000000',
alice.getId()
)
assert(tokenAddress != null)
})

View File

@ -41,7 +41,7 @@ describe('Simple flow', () => {
datatokensTemplate.abi as AbiItem[],
web3
)
tokenAddress = await datatoken.create(blob, alice)
tokenAddress = await datatoken.create(blob, 'AliceDT', 'DTA', '10000000000', alice)
})
it('Alice mints 100 tokens', async () => {
await datatoken.mint(tokenAddress, alice, tokenAmount)

View File

@ -45,7 +45,7 @@ describe('DataTokens', () => {
})
it('should create datatokens smart contract', async () => {
tokenAddress = await datatoken.create(blob, minter)
tokenAddress = await datatoken.create(blob, 'AliceDT', 'DTA', '10000000000', minter)
assert(tokenAddress !== null)
})

View File

@ -10,8 +10,8 @@ import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
// this will be replaced by our SFactory/SPool
import OceanPoolFactory from '@oceanprotocol/contracts/artifacts/SFactory.json'
import OceanSPool from '@oceanprotocol/contracts/artifacts/SPool.json'
import OceanPoolFactory from '@oceanprotocol/contracts/artifacts/BFactory.json'
import OceanSPool from '@oceanprotocol/contracts/artifacts/BPool.json'
const web3 = new Web3('http://127.0.0.1:8545')
describe('Balancer flow', () => {
@ -74,7 +74,7 @@ describe('Balancer flow', () => {
})
it('should create datatokens smart contract', async () => {
tokenAddress = await datatoken.create(blob, alice)
tokenAddress = await datatoken.create(blob, 'AliceDT', 'DTA', '10000000000', alice)
assert(tokenAddress !== null)
})
it('Create a dummy OceanToken', async () => {
@ -85,7 +85,13 @@ describe('Balancer flow', () => {
datatokensTemplate.abi as AbiItem[],
web3
)
oceanTokenAddress = await oceandatatoken.create(blob, alice)
oceanTokenAddress = await oceandatatoken.create(
blob,
'AliceDT2',
'DTA2',
'10000000000',
alice
)
})
it('should initialize OceanPool class', async () => {
Pool = new OceanPool(

View File

@ -79,7 +79,13 @@ describe('FixedRateExchange flow', () => {
})
it('should create datatokens smart contract', async () => {
tokenAddress = await datatoken.create(blob, alice)
tokenAddress = await datatoken.create(
blob,
'AliceDT',
'DTA',
web3.utils.toWei('1000000000000000'),
alice
)
assert(tokenAddress !== null)
if (consoleDebug) console.log("Alice's address:" + alice)
if (consoleDebug) console.log('data Token address:' + tokenAddress)
@ -92,7 +98,13 @@ describe('FixedRateExchange flow', () => {
datatokensTemplate.abi as AbiItem[],
web3
)
oceanTokenAddress = await oceandatatoken.create(blob, bob)
oceanTokenAddress = await oceandatatoken.create(
blob,
'BobDT',
'DTB',
web3.utils.toWei('1000000000000000'),
bob
)
if (consoleDebug) console.log("Bob's address:" + bob)
if (consoleDebug) console.log('oceanTokenAddress:' + oceanTokenAddress)
})