Skip to content

Commit

Permalink
gas optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Oct 26, 2020
1 parent aead7e4 commit 03665f2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/balancer/PoolFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import jsonFactoryABI from '@oceanprotocol/contracts/artifacts/BFactory.json'
import { TransactionReceipt } from 'web3-core'

export class PoolFactory {
public GASLIMIT_DEFAULT = 5000000
public GASLIMIT_DEFAULT = 8000000
public web3: Web3 = null
public factoryABI: AbiItem | AbiItem[]
public factoryAddress: string
Expand Down
20 changes: 15 additions & 5 deletions src/datatokens/Datatokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ export class DataTokens {
.createToken(metadataCacheUri, name, symbol, this.web3.utils.toWei(cap))
.send({
from: address,
gas: estGas + 1,
gasPrice: '3000000000'
gas: estGas + 1
})

let tokenAddress = null
Expand Down Expand Up @@ -167,8 +166,7 @@ export class DataTokens {
.mint(destAddress, this.web3.utils.toWei(amount))
.send({
from: address,
gas: estGas + 1,
gasPrice: '3000000000'
gas: estGas + 1
})

return trxReceipt
Expand Down Expand Up @@ -365,14 +363,26 @@ export class DataTokens {
})
if (!mpFeeAddress) mpFeeAddress = '0x0000000000000000000000000000000000000000'
try {
const estGas = await datatoken.methods
.startOrder(
consumer,
this.web3.utils.toWei(amount),
String(serviceId),
mpFeeAddress
)
.estimateGas(function (err, estGas) {
if (err) console.error(`ERROR: Datatokens : ${err}`)
return estGas
})

const trxReceipt = await datatoken.methods
.startOrder(
consumer,
this.web3.utils.toWei(amount),
String(serviceId),
mpFeeAddress
)
.send({ from: address, gas: 600000 })
.send({ from: address, gas: estGas + 1 })
return trxReceipt
} catch (e) {
this.logger.error(`ERROR: Failed to start order : ${e.message}`)
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/FixedRateExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export enum FixedRateCreateProgressStep {
ApprovingDatatoken
}

const DEFAULT_GAS_LIMIT = 300000
const DEFAULT_GAS_LIMIT = 1000000

export class OceanFixedRateExchange {
/** Ocean related functions */
Expand Down
33 changes: 27 additions & 6 deletions src/metadatacache/OnChainMetaDataCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { didZeroX, Logger } from '../utils'
// Using limited, compress-only version
// See https://github.com/LZMA-JS/LZMA-JS#but-i-dont-want-to-use-web-workers
import { LZMA } from 'lzma/src/lzma-c'

const DEFAULT_GAS_LIMIT = 1000000
/**
* Provides an interface with Metadata Cache.
* Metadata Cache provides an off-chain database store for metadata about data assets.
Expand Down Expand Up @@ -105,17 +105,24 @@ export class OnChainMetadataCache {
this.logger.error('ERROR: Missing DDOContract')
return null
}
let estGas
try {
/* const estGas = await this.DDOContract.methods
estGas = await this.DDOContract.methods
.create(didZeroX(did), flags, data)
.estimateGas(function (err, estGas) {
if (err) console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
if (err) {
// console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
return DEFAULT_GAS_LIMIT
}
return estGas
})
*/
} catch (e) {
estGas = DEFAULT_GAS_LIMIT
}
try {
const trxReceipt = await this.DDOContract.methods
.create(didZeroX(did), flags, data)
.send({ from: consumerAccount })
.send({ from: consumerAccount, gas: estGas + 1 })
return trxReceipt
} catch (e) {
this.logger.error(`ERROR: Failed to publish raw DDO : ${e.message}`)
Expand All @@ -141,10 +148,24 @@ export class OnChainMetadataCache {
this.logger.error('ERROR: Missing DDOContract')
return null
}
let estGas
try {
estGas = await this.DDOContract.methods
.update(didZeroX(did), flags, data)
.estimateGas(function (err, estGas) {
if (err) {
// console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
return DEFAULT_GAS_LIMIT
}
return estGas
})
} catch (e) {
estGas = DEFAULT_GAS_LIMIT
}
try {
const trxReceipt = await this.DDOContract.methods
.update(didZeroX(did), flags, data)
.send({ from: consumerAccount })
.send({ from: consumerAccount, gas: estGas + 1 })
return trxReceipt
} catch (e) {
this.logger.error(`ERROR: Failed to update raw DDO : ${e.message}`)
Expand Down

0 comments on commit 03665f2

Please sign in to comment.