mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
rename estimateGas() to calculateEstimatedGas()
This commit is contained in:
parent
d435d3c2be
commit
2cbb3c3ba8
@ -2,7 +2,12 @@ import Web3 from 'web3'
|
||||
import { TransactionReceipt } from 'web3-core'
|
||||
import { AbiItem } from 'web3-utils'
|
||||
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||
import { LoggerInstance, generateDtName, estimateGas, ZERO_ADDRESS } from '../../utils'
|
||||
import {
|
||||
LoggerInstance,
|
||||
generateDtName,
|
||||
calculateEstimatedGas,
|
||||
ZERO_ADDRESS
|
||||
} from '../../utils'
|
||||
import {
|
||||
FreCreationParams,
|
||||
DatatokenCreateParams,
|
||||
@ -22,27 +27,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return ERC721Factory.abi as AbiItem[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Get estimated gas cost for deployERC721Contract value
|
||||
* @param {String} address
|
||||
* @param {String} nftData
|
||||
* @return {Promise<string>} NFT datatoken address
|
||||
*/
|
||||
public async estGasCreateNFT(address: string, nftData: NftCreateData): Promise<string> {
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.deployERC721Contract,
|
||||
nftData.name,
|
||||
nftData.symbol,
|
||||
nftData.templateIndex,
|
||||
ZERO_ADDRESS,
|
||||
ZERO_ADDRESS,
|
||||
nftData.tokenURI,
|
||||
nftData.transferable,
|
||||
nftData.owner
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new NFT
|
||||
* @param {String} address
|
||||
@ -67,7 +51,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
if ((await this.getNFTTemplate(nftData.templateIndex)).isActive === false) {
|
||||
throw new Error(`Template is not active`)
|
||||
}
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.deployERC721Contract,
|
||||
nftData.name,
|
||||
@ -190,23 +174,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return confirmAddress
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for add721TokenTemplate method
|
||||
* @param {String} address
|
||||
* @param {String} templateAddress template address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async estGasAddNFTTemplate(
|
||||
address: string,
|
||||
templateAddress: string
|
||||
): Promise<any> {
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.add721TokenTemplate,
|
||||
templateAddress
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new NFT token template - only factory Owner
|
||||
* @param {String} address
|
||||
@ -224,7 +191,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
throw new Error(`Template cannot be ZERO address`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.add721TokenTemplate,
|
||||
templateAddress
|
||||
@ -242,23 +209,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for disable721TokenTemplate method
|
||||
* @param {String} address
|
||||
* @param {Number} templateIndex index of the template we want to disable
|
||||
* @return {Promise<TransactionReceipt>} current token template count
|
||||
*/
|
||||
public async estGasDisableNFTTemplate(
|
||||
address: string,
|
||||
templateIndex: number
|
||||
): Promise<any> {
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.disable721TokenTemplate,
|
||||
templateIndex
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable token template - only factory Owner
|
||||
* @param {String} address
|
||||
@ -279,7 +229,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
if (templateIndex === 0) {
|
||||
throw new Error(`Template index cannot be ZERO`)
|
||||
}
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.disable721TokenTemplate,
|
||||
templateIndex
|
||||
@ -297,23 +247,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
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 estGasReactivateNFTTemplate(
|
||||
address: string,
|
||||
templateIndex: number
|
||||
): Promise<any> {
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.reactivate721TokenTemplate,
|
||||
templateIndex
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reactivate a previously disabled token template - only factory Owner
|
||||
* @param {String} address
|
||||
@ -335,7 +268,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
throw new Error(`Template index cannot be ZERO`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.reactivate721TokenTemplate,
|
||||
templateIndex
|
||||
@ -353,19 +286,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for addTokenTemplate method
|
||||
* @param {String} address
|
||||
* @param {String} templateAddress template address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async estGasAddTokenTemplate(
|
||||
address: string,
|
||||
templateAddress: string
|
||||
): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.addTokenTemplate, templateAddress)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new NFT token template - only factory Owner
|
||||
* @param {String} address
|
||||
@ -383,7 +303,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
throw new Error(`Template cannot be address ZERO`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.addTokenTemplate,
|
||||
templateAddress
|
||||
@ -401,19 +321,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for disableTokenTemplate method
|
||||
* @param {String} address
|
||||
* @param {Number} templateIndex index of the template we want to disable
|
||||
* @return {Promise<TransactionReceipt>} current token template count
|
||||
*/
|
||||
public async estGasDisableTokenTemplate(
|
||||
address: string,
|
||||
templateIndex: number
|
||||
): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.disableTokenTemplate, templateIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable token template - only factory Owner
|
||||
* @param {String} address
|
||||
@ -437,7 +344,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
if ((await this.getTokenTemplate(templateIndex)).isActive === false) {
|
||||
throw new Error(`Template is already disabled`)
|
||||
}
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.disableTokenTemplate,
|
||||
templateIndex
|
||||
@ -455,23 +362,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for reactivateTokenTemplate method
|
||||
* @param {String} address
|
||||
* @param {Number} templateIndex index of the template we want to reactivate
|
||||
* @return {Promise<TransactionReceipt>} current token template count
|
||||
*/
|
||||
public async estGasReactivateTokenTemplate(
|
||||
address: string,
|
||||
templateIndex: number
|
||||
): Promise<any> {
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.reactivateTokenTemplate,
|
||||
templateIndex
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reactivate a previously disabled token template - only factory Owner
|
||||
* @param {String} address
|
||||
@ -496,7 +386,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
throw new Error(`Template is already active`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.reactivateTokenTemplate,
|
||||
templateIndex
|
||||
@ -514,18 +404,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Estimate gas cost for startMultipleTokenOrder method
|
||||
* @param address Caller address
|
||||
* @param orders an array of struct tokenOrder
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
public async estGasStartMultipleTokenOrder(
|
||||
address: string,
|
||||
orders: TokenOrder[]
|
||||
): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.startMultipleTokenOrder, orders)
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev startMultipleTokenOrder
|
||||
* Used as a proxy to order multiple services
|
||||
@ -546,7 +424,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
throw new Error(`Too many orders`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.startMultipleTokenOrder,
|
||||
orders
|
||||
@ -562,28 +440,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for createNftWithDatatoken method
|
||||
* @param address Caller address
|
||||
* @param _NftCreateData input data for NFT creation
|
||||
* @param _ErcCreateData input data for Datatoken creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
|
||||
public async estGasCreateNftWithDatatoken(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: DatatokenCreateParams
|
||||
): Promise<any> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.createNftWithErc20,
|
||||
nftCreateData,
|
||||
ercCreateData
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev createNftWithDatatoken
|
||||
* Creates a new NFT, then a Datatoken,all in one call
|
||||
@ -600,7 +456,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
): Promise<TransactionReceipt> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.createNftWithErc20,
|
||||
nftCreateData,
|
||||
@ -619,31 +475,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for createNftWithDatatokenWithPool method
|
||||
* @param address Caller address
|
||||
* @param nftCreateData input data for NFT Creation
|
||||
* @param ercParams input data for Datatoken Creation
|
||||
* @param poolParams input data for Pool Creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
public async estGasCreateNftWithDatatokenWithPool(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: DatatokenCreateParams,
|
||||
poolParams: PoolCreationParams
|
||||
): Promise<any> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const poolData = await this.getPoolCreationParams(this.web3, poolParams)
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.createNftWithErc20WithPool,
|
||||
nftCreateData,
|
||||
ercCreateData,
|
||||
poolData
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev createNftWithDatatokenWithPool
|
||||
* Creates a new NFT, then a Datatoken, then a Pool, all in one call
|
||||
@ -663,7 +494,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const poolData = await this.getPoolCreationParams(this.web3, poolParams)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.createNftWithErc20WithPool,
|
||||
nftCreateData,
|
||||
@ -683,30 +514,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Estimate gas cost for createNftWithDatatokenWithFixedRate method
|
||||
* @param address Caller address
|
||||
* @param nftCreateData input data for NFT Creation
|
||||
* @param ercParams input data for Datatoken Creation
|
||||
* @param freParams input data for FixedRate Creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
public async estGasCreateNftWithDatatokenWithFixedRate(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: DatatokenCreateParams,
|
||||
freParams: FreCreationParams
|
||||
): Promise<any> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const fixedData = await this.getFreCreationParams(freParams)
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.createNftWithErc20WithFixedRate,
|
||||
nftCreateData,
|
||||
ercCreateData,
|
||||
fixedData
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev createNftWithDatatokenWithFixedRate
|
||||
* Creates a new NFT, then a Datatoken, then a FixedRateExchange, all in one call
|
||||
@ -726,7 +533,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
const fixedData = this.getFreCreationParams(freParams)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.createNftWithErc20WithFixedRate,
|
||||
nftCreateData,
|
||||
@ -746,29 +553,6 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Estimate gas cost for estGasCreateNftWithDatatokenWithDispenser method
|
||||
* @param address Caller address
|
||||
* @param nftCreateData input data for NFT Creation
|
||||
* @param ercParams input data for Datatoken Creation
|
||||
* @param dispenserParams input data for Dispenser Creation
|
||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||
*/
|
||||
public async estGasCreateNftWithDatatokenWithDispenser(
|
||||
address: string,
|
||||
nftCreateData: NftCreateData,
|
||||
ercParams: DatatokenCreateParams,
|
||||
dispenserParams: DispenserCreationParams
|
||||
): Promise<any> {
|
||||
const ercCreateData = this.getErcCreationParams(ercParams)
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.createNftWithErc20WithDispenser,
|
||||
nftCreateData,
|
||||
ercCreateData,
|
||||
dispenserParams
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev createNftWithDatatokenWithDispenser
|
||||
* Creates a new NFT, then a Datatoken, then a Dispenser, all in one call
|
||||
@ -790,7 +574,7 @@ export class NftFactory extends SmartContractWithAddress {
|
||||
dispenserParams.maxBalance = Web3.utils.toWei(dispenserParams.maxBalance)
|
||||
dispenserParams.maxTokens = Web3.utils.toWei(dispenserParams.maxTokens)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.createNftWithErc20WithDispenser,
|
||||
nftCreateData,
|
||||
|
@ -2,7 +2,7 @@ import { AbiItem } from 'web3-utils'
|
||||
import { TransactionReceipt } from 'web3-eth'
|
||||
import Decimal from 'decimal.js'
|
||||
import DispenserAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
|
||||
import { LoggerInstance, estimateGas } from '../../utils/'
|
||||
import { LoggerInstance, calculateEstimatedGas } from '../../utils/'
|
||||
import { Datatoken, SmartContractWithAddress } from '..'
|
||||
import { DispenserToken } from '../../@types'
|
||||
|
||||
@ -29,33 +29,6 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for create method
|
||||
* @param {String} dtAddress Datatoken address
|
||||
* @param {String} address Owner address
|
||||
* @param {String} maxTokens max tokens to dispense
|
||||
* @param {String} maxBalance max balance of requester
|
||||
* @param {String} allowedSwapper if !=0, only this address can request DTs
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasCreate(
|
||||
dtAddress: string,
|
||||
address: string,
|
||||
maxTokens: string,
|
||||
maxBalance: string,
|
||||
allowedSwapper: string
|
||||
): Promise<any> {
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.create,
|
||||
dtAddress,
|
||||
this.web3.utils.toWei(maxTokens),
|
||||
this.web3.utils.toWei(maxBalance),
|
||||
address,
|
||||
allowedSwapper
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Dispenser
|
||||
* @param {String} dtAddress Datatoken address
|
||||
@ -72,7 +45,7 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
maxBalance: string,
|
||||
allowedSwapper: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.create,
|
||||
dtAddress,
|
||||
@ -99,29 +72,6 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas for activate method
|
||||
* @param {String} dtAddress
|
||||
* @param {Number} maxTokens max amount of tokens to dispense
|
||||
* @param {Number} maxBalance max balance of user. If user balance is >, then dispense will be rejected
|
||||
* @param {String} address User address (must be owner of the datatoken)
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasActivate(
|
||||
dtAddress: string,
|
||||
maxTokens: string,
|
||||
maxBalance: string,
|
||||
address: string
|
||||
): Promise<any> {
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.activate,
|
||||
dtAddress,
|
||||
this.web3.utils.toWei(maxTokens),
|
||||
this.web3.utils.toWei(maxBalance)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates a new dispener.
|
||||
* @param {String} dtAddress refers to datatoken address.
|
||||
@ -137,7 +87,7 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
address: string
|
||||
): Promise<TransactionReceipt> {
|
||||
try {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.activate,
|
||||
dtAddress,
|
||||
@ -163,16 +113,6 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas for deactivate method
|
||||
* @param {String} dtAddress
|
||||
* @param {String} address User address (must be owner of the datatoken)
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasDeactivate(dtAddress: string, address: string): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.deactivate, dtAddress)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate an existing dispenser.
|
||||
* @param {String} dtAddress refers to datatoken address.
|
||||
@ -184,7 +124,7 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
address: string
|
||||
): Promise<TransactionReceipt> {
|
||||
try {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.deactivate,
|
||||
dtAddress
|
||||
@ -202,26 +142,6 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas for setAllowedSwapper method
|
||||
* @param {String} dtAddress refers to datatoken address.
|
||||
* @param {String} address User address (must be owner of the datatoken)
|
||||
* @param {String} newAllowedSwapper refers to the new allowedSwapper
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasSetAllowedSwapper(
|
||||
dtAddress: string,
|
||||
address: string,
|
||||
newAllowedSwapper: string
|
||||
): Promise<any> {
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.setAllowedSwapper,
|
||||
dtAddress,
|
||||
newAllowedSwapper
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new allowedSwapper.
|
||||
* @param {String} dtAddress refers to datatoken address.
|
||||
@ -235,7 +155,7 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
newAllowedSwapper: string
|
||||
): Promise<TransactionReceipt> {
|
||||
try {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.setAllowedSwapper,
|
||||
dtAddress,
|
||||
@ -256,28 +176,6 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas for dispense method
|
||||
* @param {String} dtAddress refers to datatoken address.
|
||||
* @param {String} address User address (must be owner of the datatoken)
|
||||
* @param {String} newAllowedSwapper refers to the new allowedSwapper
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasDispense(
|
||||
dtAddress: string,
|
||||
address: string,
|
||||
amount: string = '1',
|
||||
destination: string
|
||||
): Promise<any> {
|
||||
return estimateGas(
|
||||
address,
|
||||
this.contract.methods.dispense,
|
||||
dtAddress,
|
||||
this.web3.utils.toWei(amount),
|
||||
destination
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispense datatokens to caller.
|
||||
* The dispenser must be active, hold enough DT (or be able to mint more)
|
||||
@ -294,7 +192,7 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
amount: string = '1',
|
||||
destination: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.dispense,
|
||||
dtAddress,
|
||||
@ -317,17 +215,6 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas for ownerWithdraw method
|
||||
* @param {String} dtAddress refers to datatoken address.
|
||||
* @param {String} address User address (must be owner of the datatoken)
|
||||
* @param {String} newAllowedSwapper refers to the new allowedSwapper
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasOwnerWithdraw(dtAddress: string, address: string): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.ownerWithdraw, dtAddress)
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdraw all tokens from the dispenser
|
||||
* @param {String} dtAddress refers to datatoken address.
|
||||
@ -338,7 +225,7 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
dtAddress: string,
|
||||
address: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.ownerWithdraw,
|
||||
dtAddress
|
||||
|
@ -2,7 +2,7 @@ import FixedRateExchangeAbi from '@oceanprotocol/contracts/artifacts/contracts/p
|
||||
import { TransactionReceipt } from 'web3-core'
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import { AbiItem } from 'web3-utils/types'
|
||||
import { LoggerInstance, estimateGas, ZERO_ADDRESS } from '../../utils'
|
||||
import { LoggerInstance, calculateEstimatedGas, ZERO_ADDRESS } from '../../utils'
|
||||
import { PriceAndFees, FeesInfo, FixedPriceExchange } from '../../@types'
|
||||
import { SmartContractWithAddress } from '..'
|
||||
|
||||
@ -45,7 +45,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.buyDT,
|
||||
datatokenAddress,
|
||||
@ -87,7 +87,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
+exchange.btDecimals
|
||||
)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.buyDT,
|
||||
exchangeId,
|
||||
@ -138,7 +138,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.sellDT,
|
||||
datatokenAddress,
|
||||
@ -179,7 +179,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
minBaseTokenAmount,
|
||||
+exchange.btDecimals
|
||||
)
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.sellDT,
|
||||
exchangeId,
|
||||
@ -236,7 +236,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.setRate,
|
||||
exchangeId,
|
||||
@ -256,7 +256,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
exchangeId: string,
|
||||
newRate: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.setRate,
|
||||
exchangeId,
|
||||
@ -288,7 +288,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.setAllowedSwapper,
|
||||
exchangeId,
|
||||
@ -308,7 +308,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
exchangeId: string,
|
||||
newAllowedSwapper: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.setAllowedSwapper,
|
||||
exchangeId,
|
||||
@ -338,7 +338,11 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.toggleExchangeState,
|
||||
exchangeId
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -354,7 +358,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
const exchange = await this.getExchange(exchangeId)
|
||||
if (!exchange) return null
|
||||
if (exchange.active === true) return null
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.toggleExchangeState,
|
||||
exchangeId
|
||||
@ -381,7 +385,11 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.toggleExchangeState,
|
||||
exchangeId
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -398,7 +406,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
if (!exchange) return null
|
||||
if (exchange.active === false) return null
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.toggleExchangeState,
|
||||
exchangeId
|
||||
@ -628,7 +636,12 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(account, fixedRate.methods.toggleMintState, exchangeId, true)
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.toggleMintState,
|
||||
exchangeId,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -645,7 +658,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
if (!exchange) return null
|
||||
if (exchange.withMint === true) return null
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.toggleMintState,
|
||||
exchangeId,
|
||||
@ -675,7 +688,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.toggleMintState(exchangeId, false),
|
||||
exchangeId,
|
||||
@ -697,7 +710,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
if (!exchange) return null
|
||||
if (exchange.withMint === false) return null
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.toggleMintState,
|
||||
exchangeId,
|
||||
@ -738,7 +751,12 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
amount,
|
||||
+fixedrate.btDecimals
|
||||
)
|
||||
return estimateGas(account, fixedRate.methods.collectBT, exchangeId, amountWei)
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.collectBT,
|
||||
exchangeId,
|
||||
amountWei
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -765,7 +783,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
+fixedrate.btDecimals
|
||||
)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.collectBT,
|
||||
exchangeId,
|
||||
@ -804,7 +822,12 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
amount,
|
||||
+fixedrate.dtDecimals
|
||||
)
|
||||
return estimateGas(account, fixedRate.methods.collectDT, exchangeId, amountWei)
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.collectDT,
|
||||
exchangeId,
|
||||
amountWei
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -831,7 +854,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
+fixedrate.dtDecimals
|
||||
)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.collectDT,
|
||||
exchangeId,
|
||||
@ -860,7 +883,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
||||
return calculateEstimatedGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -876,7 +899,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
const exchange = await this.getExchange(exchangeId)
|
||||
if (!exchange) return null
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.collectMarketFee,
|
||||
exchangeId
|
||||
@ -903,7 +926,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
||||
return calculateEstimatedGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -919,7 +942,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
const exchange = await this.getExchange(exchangeId)
|
||||
if (!exchange) return null
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.collectOceanFee,
|
||||
exchangeId
|
||||
@ -991,7 +1014,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.updateMarketFee,
|
||||
exchangeId,
|
||||
@ -1011,7 +1034,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
exchangeId: string,
|
||||
newMarketFee: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.updateMarketFee,
|
||||
exchangeId,
|
||||
@ -1043,7 +1066,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
): Promise<number> {
|
||||
const fixedRate = contractInstance || this.contract
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
fixedRate.methods.updateMarketFeeCollector,
|
||||
exchangeId,
|
||||
@ -1063,7 +1086,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
||||
exchangeId: string,
|
||||
newMarketFeeCollector: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.updateMarketFeeCollector,
|
||||
exchangeId,
|
||||
|
@ -6,7 +6,7 @@ import BigNumber from 'bignumber.js'
|
||||
import Bpool from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
||||
import {
|
||||
LoggerInstance,
|
||||
estimateGas,
|
||||
calculateEstimatedGas,
|
||||
MAX_UINT_256,
|
||||
decimals,
|
||||
calcMaxExactOut,
|
||||
@ -65,7 +65,7 @@ export class Pool extends SmartContract {
|
||||
): Promise<number> {
|
||||
const poolContract = contractInstance || this.getContract(poolAddress)
|
||||
|
||||
return estimateGas(account, poolContract.methods.setSwapFee, fee)
|
||||
return calculateEstimatedGas(account, poolContract.methods.setSwapFee, fee)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +81,7 @@ export class Pool extends SmartContract {
|
||||
): Promise<TransactionReceipt> {
|
||||
const pool = this.getContract(poolAddress, account)
|
||||
let result = null
|
||||
const estGas = await estimateGas(account, pool.methods.setSwapFee, fee)
|
||||
const estGas = await calculateEstimatedGas(account, pool.methods.setSwapFee, fee)
|
||||
|
||||
try {
|
||||
result = await pool.methods.setSwapFee(this.web3.utils.toWei(fee)).send({
|
||||
@ -486,7 +486,7 @@ export class Pool extends SmartContract {
|
||||
): Promise<number> {
|
||||
const poolContract = contractInstance || this.getContract(poolAddress)
|
||||
|
||||
return estimateGas(address, poolContract.methods.collectOPC)
|
||||
return calculateEstimatedGas(address, poolContract.methods.collectOPC)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -498,7 +498,7 @@ export class Pool extends SmartContract {
|
||||
async collectOPC(address: string, poolAddress: string): Promise<TransactionReceipt> {
|
||||
const pool = this.getContract(poolAddress)
|
||||
let result = null
|
||||
const estGas = await estimateGas(address, pool.methods.collectOPC)
|
||||
const estGas = await calculateEstimatedGas(address, pool.methods.collectOPC)
|
||||
|
||||
try {
|
||||
result = await pool.methods.collectOPC().send({
|
||||
@ -527,7 +527,7 @@ export class Pool extends SmartContract {
|
||||
): Promise<number> {
|
||||
const poolContract = contractInstance || this.getContract(poolAddress)
|
||||
|
||||
return estimateGas(address, poolContract.methods.collectMarketFee)
|
||||
return calculateEstimatedGas(address, poolContract.methods.collectMarketFee)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -546,7 +546,7 @@ export class Pool extends SmartContract {
|
||||
}
|
||||
const pool = this.getContract(poolAddress)
|
||||
let result = null
|
||||
const estGas = await estimateGas(address, pool.methods.collectMarketFee)
|
||||
const estGas = await calculateEstimatedGas(address, pool.methods.collectMarketFee)
|
||||
|
||||
try {
|
||||
result = await pool.methods.collectMarketFee().send({
|
||||
@ -578,7 +578,7 @@ export class Pool extends SmartContract {
|
||||
): Promise<number> {
|
||||
const poolContract = contractInstance || this.getContract(poolAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
poolContract.methods.updatePublishMarketFee,
|
||||
newPublishMarketAddress,
|
||||
@ -606,7 +606,7 @@ export class Pool extends SmartContract {
|
||||
const pool = this.getContract(poolAddress)
|
||||
let result = null
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
pool.methods.updatePublishMarketFee,
|
||||
newPublishMarketAddress,
|
||||
@ -666,7 +666,7 @@ export class Pool extends SmartContract {
|
||||
)
|
||||
: MAX_UINT_256
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
poolContract.methods.swapExactAmountIn,
|
||||
[
|
||||
@ -728,7 +728,7 @@ export class Pool extends SmartContract {
|
||||
)
|
||||
: MAX_UINT_256
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
pool.methods.swapExactAmountIn,
|
||||
[
|
||||
@ -809,7 +809,7 @@ export class Pool extends SmartContract {
|
||||
)
|
||||
: MAX_UINT_256
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
poolContract.methods.swapExactAmountOut,
|
||||
[
|
||||
@ -867,7 +867,7 @@ export class Pool extends SmartContract {
|
||||
)
|
||||
: MAX_UINT_256
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
account,
|
||||
pool.methods.swapExactAmountOut,
|
||||
[
|
||||
@ -928,7 +928,7 @@ export class Pool extends SmartContract {
|
||||
): Promise<number> {
|
||||
const poolContract = contractInstance || this.getContract(poolAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
poolContract.methods.joinswapExternAmountIn,
|
||||
tokenAmountIn,
|
||||
@ -967,7 +967,7 @@ export class Pool extends SmartContract {
|
||||
tokenAmountIn,
|
||||
tokenInDecimals
|
||||
)
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
account,
|
||||
pool.methods.joinswapExternAmountIn,
|
||||
amountInFormatted,
|
||||
@ -1010,7 +1010,7 @@ export class Pool extends SmartContract {
|
||||
): Promise<number> {
|
||||
const poolContract = contractInstance || this.getContract(poolAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
poolContract.methods.exitswapPoolAmountIn,
|
||||
poolAmountIn,
|
||||
@ -1056,7 +1056,7 @@ export class Pool extends SmartContract {
|
||||
minTokenAmountOut,
|
||||
poolDecimals
|
||||
)
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
account,
|
||||
pool.methods.exitswapPoolAmountIn,
|
||||
this.web3.utils.toWei(poolAmountIn),
|
||||
|
@ -2,7 +2,7 @@ import { Contract } from 'web3-eth-contract'
|
||||
import { TransactionReceipt } from 'web3-core'
|
||||
import { AbiItem } from 'web3-utils'
|
||||
import FactoryRouter from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
|
||||
import { estimateGas } from '../../utils'
|
||||
import { calculateEstimatedGas } from '../../utils'
|
||||
import { Operation } from '../../@types'
|
||||
import { SmartContractWithAddress } from '..'
|
||||
|
||||
@ -21,7 +21,7 @@ export class Router extends SmartContractWithAddress {
|
||||
* @return {Promise<TransactionReceipt>} Transaction receipt
|
||||
*/
|
||||
public async estGasBuyDTBatch(address: string, operations: Operation[]): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.buyDTBatch, operations)
|
||||
return calculateEstimatedGas(address, this.contract.methods.buyDTBatch, operations)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,7 +34,7 @@ export class Router extends SmartContractWithAddress {
|
||||
address: string,
|
||||
operations: Operation[]
|
||||
): Promise<TransactionReceipt> {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.buyDTBatch,
|
||||
operations
|
||||
@ -104,7 +104,11 @@ export class Router extends SmartContractWithAddress {
|
||||
tokenAddress: string,
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.addApprovedToken, tokenAddress)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.addApprovedToken,
|
||||
tokenAddress
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,7 +125,7 @@ export class Router extends SmartContractWithAddress {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.addApprovedToken,
|
||||
tokenAddress
|
||||
@ -149,7 +153,11 @@ export class Router extends SmartContractWithAddress {
|
||||
tokenAddress: string,
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.removeApprovedToken, tokenAddress)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.removeApprovedToken,
|
||||
tokenAddress
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,7 +174,7 @@ export class Router extends SmartContractWithAddress {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.removeApprovedToken,
|
||||
tokenAddress
|
||||
@ -191,7 +199,11 @@ export class Router extends SmartContractWithAddress {
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async estGasAddSSContract(address: string, tokenAddress: string): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.addSSContract, tokenAddress)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.addSSContract,
|
||||
tokenAddress
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -208,7 +220,7 @@ export class Router extends SmartContractWithAddress {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.addSSContract,
|
||||
tokenAddress
|
||||
@ -234,7 +246,11 @@ export class Router extends SmartContractWithAddress {
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.removeSSContract, tokenAddress)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.removeSSContract,
|
||||
tokenAddress
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,7 +267,7 @@ export class Router extends SmartContractWithAddress {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.removeSSContract,
|
||||
tokenAddress
|
||||
@ -277,7 +293,11 @@ export class Router extends SmartContractWithAddress {
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.addFixedRateContract, tokenAddress)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.addFixedRateContract,
|
||||
tokenAddress
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,7 +314,7 @@ export class Router extends SmartContractWithAddress {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.addFixedRateContract,
|
||||
tokenAddress
|
||||
@ -322,7 +342,7 @@ export class Router extends SmartContractWithAddress {
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<any> {
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.removeFixedRateContract,
|
||||
tokenAddress
|
||||
@ -343,7 +363,7 @@ export class Router extends SmartContractWithAddress {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.removeFixedRateContract,
|
||||
tokenAddress
|
||||
@ -371,7 +391,11 @@ export class Router extends SmartContractWithAddress {
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.addDispenserContract, tokenAddress)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.addDispenserContract,
|
||||
tokenAddress
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -388,7 +412,7 @@ export class Router extends SmartContractWithAddress {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.addDispenserContract,
|
||||
tokenAddress
|
||||
@ -416,7 +440,7 @@ export class Router extends SmartContractWithAddress {
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<any> {
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.removeDispenserContract,
|
||||
tokenAddress
|
||||
@ -437,7 +461,7 @@ export class Router extends SmartContractWithAddress {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.removeDispenserContract,
|
||||
tokenAddress
|
||||
@ -482,7 +506,7 @@ export class Router extends SmartContractWithAddress {
|
||||
newConsumeFee: number,
|
||||
newProviderFee: number
|
||||
): Promise<any> {
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.updateOPCFee,
|
||||
newSwapOceanFee,
|
||||
@ -512,7 +536,7 @@ export class Router extends SmartContractWithAddress {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.updateOPCFee,
|
||||
newSwapOceanFee,
|
||||
@ -543,7 +567,11 @@ export class Router extends SmartContractWithAddress {
|
||||
address: string,
|
||||
templateAddress: string
|
||||
): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.addPoolTemplate, templateAddress)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.addPoolTemplate,
|
||||
templateAddress
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -560,7 +588,7 @@ export class Router extends SmartContractWithAddress {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.addPoolTemplate,
|
||||
templateAddress
|
||||
@ -586,7 +614,11 @@ export class Router extends SmartContractWithAddress {
|
||||
address: string,
|
||||
templateAddress: string
|
||||
): Promise<any> {
|
||||
return estimateGas(address, this.contract.methods.removePoolTemplate, templateAddress)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.removePoolTemplate,
|
||||
templateAddress
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -603,7 +635,7 @@ export class Router extends SmartContractWithAddress {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.removePoolTemplate,
|
||||
templateAddress
|
||||
|
@ -2,7 +2,7 @@ import { AbiItem } from 'web3-utils/types'
|
||||
import { TransactionReceipt } from 'web3-core'
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import SideStakingAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
||||
import { LoggerInstance, estimateGas } from '../../utils'
|
||||
import { LoggerInstance, calculateEstimatedGas } from '../../utils'
|
||||
import { SmartContract } from '..'
|
||||
|
||||
export class SideStaking extends SmartContract {
|
||||
@ -251,7 +251,11 @@ export class SideStaking extends SmartContract {
|
||||
): Promise<number> {
|
||||
const sideStaking = contractInstance || this.getContract(ssAddress)
|
||||
|
||||
return estimateGas(account, sideStaking.methods.getVesting, datatokenAddress)
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
sideStaking.methods.getVesting,
|
||||
datatokenAddress
|
||||
)
|
||||
}
|
||||
|
||||
/** Send vested tokens available to the publisher address, can be called by anyone
|
||||
@ -269,7 +273,7 @@ export class SideStaking extends SmartContract {
|
||||
const sideStaking = this.getContract(ssAddress)
|
||||
let result = null
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
account,
|
||||
sideStaking.methods.getVesting,
|
||||
datatokenAddress
|
||||
@ -305,7 +309,7 @@ export class SideStaking extends SmartContract {
|
||||
): Promise<number> {
|
||||
const sideStaking = contractInstance || this.getContract(ssAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
account,
|
||||
sideStaking.methods.setPoolSwapFee,
|
||||
datatokenAddress,
|
||||
@ -331,7 +335,7 @@ export class SideStaking extends SmartContract {
|
||||
const sideStaking = this.getContract(ssAddress)
|
||||
let result = null
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
account,
|
||||
sideStaking.methods.setPoolSwapFee,
|
||||
datatokenAddress,
|
||||
|
@ -5,7 +5,7 @@ import { Contract } from 'web3-eth-contract'
|
||||
import Decimal from 'decimal.js'
|
||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||
import ERC20TemplateEnterprise from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json'
|
||||
import { LoggerInstance, estimateGas, ZERO_ADDRESS } from '../../utils'
|
||||
import { LoggerInstance, calculateEstimatedGas, ZERO_ADDRESS } from '../../utils'
|
||||
import {
|
||||
ConsumeMarketFee,
|
||||
FreOrderParams,
|
||||
@ -63,7 +63,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.approve,
|
||||
spender,
|
||||
@ -87,7 +87,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.approve,
|
||||
spender,
|
||||
@ -123,7 +123,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.mint,
|
||||
toAddress || address,
|
||||
@ -151,7 +151,7 @@ export class Datatoken extends SmartContract {
|
||||
if (!fixedRateParams.allowedConsumer) fixedRateParams.allowedConsumer = ZERO_ADDRESS
|
||||
const withMint = fixedRateParams.withMint ? 1 : 0
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.createFixedRate,
|
||||
fixedRateParams.fixedRateAddress,
|
||||
@ -194,7 +194,7 @@ export class Datatoken extends SmartContract {
|
||||
|
||||
// should check DatatokenDeployer role using NFT level ..
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.createFixedRate,
|
||||
fixedRateParams.fixedRateAddress,
|
||||
@ -261,7 +261,7 @@ export class Datatoken extends SmartContract {
|
||||
|
||||
if (!dispenserParams.withMint) dispenserParams.withMint = false
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.createDispenser,
|
||||
dispenserAddress,
|
||||
@ -298,7 +298,7 @@ export class Datatoken extends SmartContract {
|
||||
|
||||
// should check DatatokenDeployer role using NFT level ..
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.createDispenser,
|
||||
dispenserAddress,
|
||||
@ -347,7 +347,7 @@ export class Datatoken extends SmartContract {
|
||||
|
||||
const capAvailble = await this.getCap(dtAddress)
|
||||
if (new Decimal(capAvailble).gte(amount)) {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.mint,
|
||||
toAddress || address,
|
||||
@ -384,7 +384,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
return estimateGas(address, dtContract.methods.addMinter, minter)
|
||||
return calculateEstimatedGas(address, dtContract.methods.addMinter, minter)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -406,7 +406,11 @@ export class Datatoken extends SmartContract {
|
||||
throw new Error(`Caller is not DatatokenDeployer`)
|
||||
}
|
||||
// Estimate gas cost for addMinter method
|
||||
const estGas = await estimateGas(address, dtContract.methods.addMinter, minter)
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.addMinter,
|
||||
minter
|
||||
)
|
||||
|
||||
// Call addMinter function of the contract
|
||||
const trxReceipt = await dtContract.methods.addMinter(minter).send({
|
||||
@ -436,7 +440,7 @@ export class Datatoken extends SmartContract {
|
||||
|
||||
// should check DatatokenDeployer role using NFT level ..
|
||||
|
||||
return estimateGas(address, dtContract.methods.removeMinter, minter)
|
||||
return calculateEstimatedGas(address, dtContract.methods.removeMinter, minter)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -459,7 +463,11 @@ export class Datatoken extends SmartContract {
|
||||
throw new Error(`Caller is not DatatokenDeployer`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(address, dtContract.methods.removeMinter, minter)
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.removeMinter,
|
||||
minter
|
||||
)
|
||||
|
||||
// Call dtContract function of the contract
|
||||
const trxReceipt = await dtContract.methods.removeMinter(minter).send({
|
||||
@ -487,7 +495,11 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
return estimateGas(address, dtContract.methods.addPaymentManager, paymentManager)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.addPaymentManager,
|
||||
paymentManager
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -509,7 +521,7 @@ export class Datatoken extends SmartContract {
|
||||
throw new Error(`Caller is not DatatokenDeployer`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.addPaymentManager,
|
||||
paymentManager
|
||||
@ -541,7 +553,11 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
return estimateGas(address, dtContract.methods.removePaymentManager, paymentManager)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.removePaymentManager,
|
||||
paymentManager
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -563,7 +579,7 @@ export class Datatoken extends SmartContract {
|
||||
throw new Error(`Caller is not DatatokenDeployer`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.removePaymentManager,
|
||||
paymentManager
|
||||
@ -597,7 +613,11 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
return estimateGas(address, dtContract.methods.setPaymentCollector, paymentCollector)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.setPaymentCollector,
|
||||
paymentCollector
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -626,7 +646,7 @@ export class Datatoken extends SmartContract {
|
||||
throw new Error(`Caller is not Fee Manager, owner or Datatoken Deployer`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.setPaymentCollector,
|
||||
paymentCollector
|
||||
@ -690,7 +710,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
return estimateGas(address, dtContract.methods.transfer, toAddress, amount)
|
||||
return calculateEstimatedGas(address, dtContract.methods.transfer, toAddress, amount)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -709,7 +729,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
try {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.transfer,
|
||||
toAddress,
|
||||
@ -749,7 +769,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.startOrder,
|
||||
consumer,
|
||||
@ -785,7 +805,7 @@ export class Datatoken extends SmartContract {
|
||||
}
|
||||
}
|
||||
try {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.startOrder,
|
||||
consumer,
|
||||
@ -825,7 +845,12 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
return estimateGas(address, dtContract.methods.reuseOrder, orderTxId, providerFees)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.reuseOrder,
|
||||
orderTxId,
|
||||
providerFees
|
||||
)
|
||||
}
|
||||
|
||||
/** Reuse Order: called by payer or consumer having a valid order, but with expired provider access.
|
||||
@ -845,7 +870,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
try {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.reuseOrder,
|
||||
orderTxId,
|
||||
@ -884,7 +909,7 @@ export class Datatoken extends SmartContract {
|
||||
const dtContract =
|
||||
contractInstance || this.getContract(dtAddress, null, this.abiEnterprise)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.buyFromFreAndOrder,
|
||||
orderParams,
|
||||
@ -909,7 +934,7 @@ export class Datatoken extends SmartContract {
|
||||
try {
|
||||
const freContractParams = this.getFreOrderParams(freParams)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.buyFromFreAndOrder,
|
||||
orderParams,
|
||||
@ -948,7 +973,7 @@ export class Datatoken extends SmartContract {
|
||||
const dtContract =
|
||||
contractInstance || this.getContract(dtAddress, null, this.abiEnterprise)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.buyFromDispenserAndOrder,
|
||||
orderParams,
|
||||
@ -971,7 +996,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = this.getContract(dtAddress, null, this.abiEnterprise)
|
||||
try {
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.buyFromDispenserAndOrder,
|
||||
orderParams,
|
||||
@ -1007,7 +1032,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
return estimateGas(address, dtContract.methods.setData, value)
|
||||
return calculateEstimatedGas(address, dtContract.methods.setData, value)
|
||||
}
|
||||
|
||||
/** setData
|
||||
@ -1029,7 +1054,7 @@ export class Datatoken extends SmartContract {
|
||||
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
|
||||
const estGas = await estimateGas(address, dtContract.methods.setData, value)
|
||||
const estGas = await calculateEstimatedGas(address, dtContract.methods.setData, value)
|
||||
|
||||
// Call setData function of the contract
|
||||
const trxReceipt = await dtContract.methods.setData(value).send({
|
||||
@ -1054,7 +1079,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<any> {
|
||||
const dtContract = contractInstance || this.getContract(dtAddress)
|
||||
|
||||
return estimateGas(address, dtContract.methods.cleanPermissions)
|
||||
return calculateEstimatedGas(address, dtContract.methods.cleanPermissions)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1073,7 +1098,10 @@ export class Datatoken extends SmartContract {
|
||||
}
|
||||
const dtContract = this.getContract(dtAddress)
|
||||
|
||||
const estGas = await estimateGas(address, dtContract.methods.cleanPermissions)
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.cleanPermissions
|
||||
)
|
||||
|
||||
// Call cleanPermissions function of the contract
|
||||
const trxReceipt = await dtContract.methods.cleanPermissions().send({
|
||||
@ -1170,7 +1198,7 @@ export class Datatoken extends SmartContract {
|
||||
): Promise<number> {
|
||||
// Estimate gas cost for publishMarketFeeAddress method
|
||||
const dtContract = this.getContract(datatokenAddress, address)
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
dtContract.methods.setPublishingMarketFee,
|
||||
publishMarketFeeAddress,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { AbiItem } from 'web3-utils'
|
||||
import { TransactionReceipt } from 'web3-eth'
|
||||
import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
|
||||
import { LoggerInstance, generateDtName, estimateGas } from '../../utils'
|
||||
import { LoggerInstance, generateDtName, calculateEstimatedGas } from '../../utils'
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import { MetadataProof, MetadataAndTokenURI, NftRoles } from '../../@types'
|
||||
import { SmartContract } from '..'
|
||||
@ -42,7 +42,7 @@ export class Nft extends SmartContract {
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.createERC20,
|
||||
templateIndex,
|
||||
@ -94,7 +94,7 @@ export class Nft extends SmartContract {
|
||||
// Create 721contract object
|
||||
const nftContract = this.getContract(nftAddress)
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.createERC20,
|
||||
templateIndex,
|
||||
@ -144,7 +144,7 @@ export class Nft extends SmartContract {
|
||||
) {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
|
||||
return estimateGas(address, nftContract.methods.addManager, manager)
|
||||
return calculateEstimatedGas(address, nftContract.methods.addManager, manager)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,7 +161,11 @@ export class Nft extends SmartContract {
|
||||
throw new Error(`Caller is not NFT Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(address, nftContract.methods.addManager, manager)
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.addManager,
|
||||
manager
|
||||
)
|
||||
|
||||
// Invoke addManager function of the contract
|
||||
const trxReceipt = await nftContract.methods.addManager(manager).send({
|
||||
@ -188,7 +192,7 @@ export class Nft extends SmartContract {
|
||||
contractInstance?: Contract
|
||||
) {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
return estimateGas(address, nftContract.methods.removeManager, manager)
|
||||
return calculateEstimatedGas(address, nftContract.methods.removeManager, manager)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -205,7 +209,11 @@ export class Nft extends SmartContract {
|
||||
throw new Error(`Caller is not NFT Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(address, nftContract.methods.removeManager, manager)
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.removeManager,
|
||||
manager
|
||||
)
|
||||
|
||||
// Invoke removeManager function of the contract
|
||||
const trxReceipt = await nftContract.methods.removeManager(manager).send({
|
||||
@ -232,7 +240,7 @@ export class Nft extends SmartContract {
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.addToCreateERC20List,
|
||||
datatokenDeployer
|
||||
@ -258,7 +266,7 @@ export class Nft extends SmartContract {
|
||||
}
|
||||
|
||||
// Estimate gas for addToCreateERC20List method
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.addToCreateERC20List,
|
||||
datatokenDeployer
|
||||
@ -292,7 +300,7 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.removeFromCreateERC20List,
|
||||
datatokenDeployer
|
||||
@ -320,7 +328,7 @@ export class Nft extends SmartContract {
|
||||
) {
|
||||
throw new Error(`Caller is not Manager nor DatatokenDeployer`)
|
||||
}
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.removeFromCreateERC20List,
|
||||
datatokenDeployer
|
||||
@ -354,7 +362,11 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
|
||||
return estimateGas(address, nftContract.methods.addToMetadataList, metadataUpdater)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.addToMetadataList,
|
||||
metadataUpdater
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -375,7 +387,7 @@ export class Nft extends SmartContract {
|
||||
throw new Error(`Caller is not Manager`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.addToMetadataList,
|
||||
metadataUpdater
|
||||
@ -407,7 +419,7 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.removeFromMetadataList,
|
||||
metadataUpdater
|
||||
@ -471,7 +483,11 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
|
||||
return estimateGas(address, nftContract.methods.addTo725StoreList, storeUpdater)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.addTo725StoreList,
|
||||
storeUpdater
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -492,7 +508,7 @@ export class Nft extends SmartContract {
|
||||
throw new Error(`Caller is not Manager`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.addTo725StoreList,
|
||||
storeUpdater
|
||||
@ -524,7 +540,11 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
|
||||
return estimateGas(address, nftContract.methods.removeFrom725StoreList, storeUpdater)
|
||||
return calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.removeFrom725StoreList,
|
||||
storeUpdater
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -549,7 +569,7 @@ export class Nft extends SmartContract {
|
||||
throw new Error(`Caller is not Manager nor storeUpdater`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.removeFrom725StoreList,
|
||||
storeUpdater
|
||||
@ -581,7 +601,7 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
|
||||
return estimateGas(address, nftContract.methods.cleanPermissions)
|
||||
return calculateEstimatedGas(address, nftContract.methods.cleanPermissions)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -604,7 +624,10 @@ export class Nft extends SmartContract {
|
||||
throw new Error(`Caller is not NFT Owner`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(address, nftContract.methods.cleanPermissions)
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.cleanPermissions
|
||||
)
|
||||
|
||||
// Call cleanPermissions function of the contract
|
||||
const trxReceipt = await nftContract.methods.cleanPermissions().send({
|
||||
@ -634,7 +657,7 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
nftOwner,
|
||||
nftContract.methods.transferFrom,
|
||||
nftOwner,
|
||||
@ -666,7 +689,7 @@ export class Nft extends SmartContract {
|
||||
|
||||
const tokenIdentifier = tokenId || 1
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
nftOwner,
|
||||
nftContract.methods.transferFrom,
|
||||
nftOwner,
|
||||
@ -704,7 +727,7 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
nftOwner,
|
||||
nftContract.methods.safeTransferFrom,
|
||||
nftOwner,
|
||||
@ -736,7 +759,7 @@ export class Nft extends SmartContract {
|
||||
|
||||
const tokenIdentifier = tokenId || 1
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
nftOwner,
|
||||
nftContract.methods.safeTransferFrom,
|
||||
nftOwner,
|
||||
@ -781,7 +804,7 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
if (!metadataProofs) metadataProofs = []
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
metadataUpdater,
|
||||
nftContract.methods.setMetaData,
|
||||
metadataState,
|
||||
@ -817,7 +840,7 @@ export class Nft extends SmartContract {
|
||||
if (!(await this.getNftPermissions(nftAddress, address)).updateMetadata) {
|
||||
throw new Error(`Caller is not Metadata updater`)
|
||||
}
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.setMetaData,
|
||||
metadataState,
|
||||
@ -866,7 +889,7 @@ export class Nft extends SmartContract {
|
||||
...metadataAndTokenURI,
|
||||
metadataProofs: metadataAndTokenURI.metadataProofs || []
|
||||
}
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
metadataUpdater,
|
||||
nftContract.methods.setMetaDataAndTokenURI,
|
||||
sanitizedMetadataAndTokenURI
|
||||
@ -893,7 +916,7 @@ export class Nft extends SmartContract {
|
||||
...metadataAndTokenURI,
|
||||
metadataProofs: metadataAndTokenURI.metadataProofs || []
|
||||
}
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
metadataUpdater,
|
||||
nftContract.methods.setMetaDataAndTokenURI,
|
||||
sanitizedMetadataAndTokenURI
|
||||
@ -925,7 +948,7 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
||||
|
||||
return estimateGas(
|
||||
return calculateEstimatedGas(
|
||||
metadataUpdater,
|
||||
nftContract.methods.setMetaDataState,
|
||||
metadataState
|
||||
@ -950,7 +973,7 @@ export class Nft extends SmartContract {
|
||||
throw new Error(`Caller is not Metadata updater`)
|
||||
}
|
||||
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.setMetaDataState,
|
||||
metadataState
|
||||
@ -979,7 +1002,7 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = this.getContract(nftAddress)
|
||||
|
||||
return estimateGas(address, nftContract.methods.setTokenURI, '1', data)
|
||||
return calculateEstimatedGas(address, nftContract.methods.setTokenURI, '1', data)
|
||||
}
|
||||
|
||||
/** set TokenURI on an nft
|
||||
@ -995,7 +1018,12 @@ export class Nft extends SmartContract {
|
||||
): Promise<any> {
|
||||
const nftContract = this.getContract(nftAddress)
|
||||
|
||||
const estGas = await estimateGas(address, nftContract.methods.setTokenURI, '1', data)
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
nftContract.methods.setTokenURI,
|
||||
'1',
|
||||
data
|
||||
)
|
||||
const trxReceipt = await nftContract.methods.setTokenURI('1', data).send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
|
@ -81,7 +81,7 @@ export async function amountToUnits(
|
||||
* @param {...any[]} args arguments of the function
|
||||
* @return {Promise<number>} gas cost of the function
|
||||
*/
|
||||
export async function estimateGas(
|
||||
export async function calculateEstimatedGas(
|
||||
from: string,
|
||||
functionToEstimateGas: Function,
|
||||
...args: any[]
|
||||
|
@ -4,7 +4,7 @@ import { TransactionReceipt } from 'web3-core'
|
||||
import Web3 from 'web3'
|
||||
import {
|
||||
amountToUnits,
|
||||
estimateGas,
|
||||
calculateEstimatedGas,
|
||||
getFairGasPrice,
|
||||
unitsToAmount,
|
||||
minAbi,
|
||||
@ -31,7 +31,7 @@ export async function estApprove(
|
||||
): Promise<number> {
|
||||
const tokenContract = contractInstance || new web3.eth.Contract(minAbi, tokenAddress)
|
||||
|
||||
return estimateGas(account, tokenContract.methods.approve, spender, amount)
|
||||
return calculateEstimatedGas(account, tokenContract.methods.approve, spender, amount)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +61,7 @@ export async function approve(
|
||||
}
|
||||
let result = null
|
||||
const amountFormatted = await amountToUnits(web3, tokenAddress, amount, tokenDecimals)
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
account,
|
||||
tokenContract.methods.approve,
|
||||
spender,
|
||||
@ -102,7 +102,7 @@ export async function estTransfer(
|
||||
): Promise<number> {
|
||||
const tokenContract = contractInstance || new web3.eth.Contract(minAbi, tokenAddress)
|
||||
|
||||
return estimateGas(account, tokenContract.methods.transfer, recipient, amount)
|
||||
return calculateEstimatedGas(account, tokenContract.methods.transfer, recipient, amount)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,7 +124,7 @@ export async function transfer(
|
||||
|
||||
let result = null
|
||||
const amountFormatted = await amountToUnits(web3, tokenAddress, amount)
|
||||
const estGas = await estimateGas(
|
||||
const estGas = await calculateEstimatedGas(
|
||||
account,
|
||||
tokenContract.methods.transfer,
|
||||
recipient,
|
||||
|
Loading…
x
Reference in New Issue
Block a user