From 220261cada63aedc5e7f71fb41f17a73838fd657 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Sun, 30 Aug 2020 23:56:25 -0700 Subject: [PATCH] update to contracts 0.4.0 --- package-lock.json | 6 ++--- package.json | 2 +- src/balancer/OceanPool.ts | 2 +- src/balancer/Pool.ts | 2 +- src/balancer/PoolFactory.ts | 6 ++--- src/datatokens/Datatokens.ts | 25 +++++++++++++------ src/ocean/Assets.ts | 16 ++++++++++-- test/TestContractHandler.ts | 10 ++++---- test/integration/ComputeFlow.test.ts | 8 +++++- test/integration/Marketplaceflow.test.ts | 8 +++++- test/integration/Simpleflow.test.ts | 2 +- test/unit/Datatokens.test.ts | 2 +- test/unit/balancer/Balancer.test.ts | 14 ++++++++--- .../unit/exchanges/FixedPriceExchange.test.ts | 16 ++++++++++-- 14 files changed, 86 insertions(+), 33 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7b74d69e..59001c18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index d4952dc6..6df9d8fe 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/balancer/OceanPool.ts b/src/balancer/OceanPool.ts index a9cb2493..b4ec95cd 100644 --- a/src/balancer/OceanPool.ts +++ b/src/balancer/OceanPool.ts @@ -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' diff --git a/src/balancer/Pool.ts b/src/balancer/Pool.ts index 2c76f194..f57b738e 100644 --- a/src/balancer/Pool.ts +++ b/src/balancer/Pool.ts @@ -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' /** diff --git a/src/balancer/PoolFactory.ts b/src/balancer/PoolFactory.ts index c7c77c70..bf363bc1 100644 --- a/src/balancer/PoolFactory.ts +++ b/src/balancer/PoolFactory.ts @@ -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) } diff --git a/src/datatokens/Datatokens.ts b/src/datatokens/Datatokens.ts index 719f6cbc..b033c95e 100644 --- a/src/datatokens/Datatokens.ts +++ b/src/datatokens/Datatokens.ts @@ -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} datatoken address */ - public async create(metaDataStoreURI: string, address: string): Promise { + public async create( + metaDataStoreURI: string, + name: string, + symbol: string, + cap: string, + address: string + ): Promise { // 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 { diff --git a/src/ocean/Assets.ts b/src/ocean/Assets.ts index dd55d687..491dd5b1 100644 --- a/src/ocean/Assets.ts +++ b/src/ocean/Assets.ts @@ -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 { 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) } diff --git a/test/TestContractHandler.ts b/test/TestContractHandler.ts index 6a4cf090..c017de8e 100644 --- a/test/TestContractHandler.ts +++ b/test/TestContractHandler.ts @@ -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, diff --git a/test/integration/ComputeFlow.test.ts b/test/integration/ComputeFlow.test.ts index 8330a4fc..3ae5e799 100644 --- a/test/integration/ComputeFlow.test.ts +++ b/test/integration/ComputeFlow.test.ts @@ -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) }) diff --git a/test/integration/Marketplaceflow.test.ts b/test/integration/Marketplaceflow.test.ts index a70aa8a6..480f6ece 100644 --- a/test/integration/Marketplaceflow.test.ts +++ b/test/integration/Marketplaceflow.test.ts @@ -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) }) diff --git a/test/integration/Simpleflow.test.ts b/test/integration/Simpleflow.test.ts index 27086427..bddfacc5 100644 --- a/test/integration/Simpleflow.test.ts +++ b/test/integration/Simpleflow.test.ts @@ -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) diff --git a/test/unit/Datatokens.test.ts b/test/unit/Datatokens.test.ts index bdd39fb3..2e1a9dfe 100644 --- a/test/unit/Datatokens.test.ts +++ b/test/unit/Datatokens.test.ts @@ -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) }) diff --git a/test/unit/balancer/Balancer.test.ts b/test/unit/balancer/Balancer.test.ts index c8cf83d0..936f54b6 100644 --- a/test/unit/balancer/Balancer.test.ts +++ b/test/unit/balancer/Balancer.test.ts @@ -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( diff --git a/test/unit/exchanges/FixedPriceExchange.test.ts b/test/unit/exchanges/FixedPriceExchange.test.ts index a7a18c08..8d59e5d4 100644 --- a/test/unit/exchanges/FixedPriceExchange.test.ts +++ b/test/unit/exchanges/FixedPriceExchange.test.ts @@ -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) })