Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users/market to set own gas contract options & configurable web3 contract params #1214

Merged
merged 5 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/factories/NFTFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import {
generateDtName,
getFreCreationParams,
getErcCreationParams,
getPoolCreationParams
getPoolCreationParams,
configHelperNetworks,
setContractDefaults
} from '../utils'
import {
FreCreationParams,
Erc20CreateParams,
PoolCreationParams,
DispenserCreationParams
} from '../interfaces'
import { Config } from '../models/index.js'
import { ProviderFees } from '../@types/index.js'

interface Template {
Expand Down Expand Up @@ -47,7 +50,7 @@ export class NftFactory {
public factory721Address: string
public factory721Abi: AbiItem | AbiItem[]
public web3: Web3
public startBlock: number
public config: Config
public factory721: Contract

/**
Expand All @@ -60,15 +63,15 @@ export class NftFactory {
factory721Address: string,
web3: Web3,
factory721Abi?: AbiItem | AbiItem[],
startBlock?: number
config?: Config
) {
this.factory721Address = factory721Address
this.factory721Abi = factory721Abi || (defaultFactory721Abi.abi as AbiItem[])
this.web3 = web3
this.startBlock = startBlock || 0
this.factory721 = new this.web3.eth.Contract(
this.factory721Abi,
this.factory721Address
this.config = config || configHelperNetworks[0]
this.factory721 = setContractDefaults(
new this.web3.eth.Contract(this.factory721Abi, this.factory721Address),
this.config
)
}

Expand Down Expand Up @@ -135,7 +138,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

let tokenAddress = null
Expand Down Expand Up @@ -277,7 +280,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -333,7 +336,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -390,7 +393,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -444,7 +447,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -503,7 +506,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -563,7 +566,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -618,7 +621,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -674,7 +677,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -739,7 +742,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -807,7 +810,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -873,7 +876,7 @@ export class NftFactory {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down
24 changes: 24 additions & 0 deletions src/models/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,30 @@ export class Config {
* @type {string}
*/
oceanTokenSymbol: string

/**
* Specify the transaction Block Timeout
* @type {number}
*/
transactionBlockTimeout: number

/**
* Specify the transaction Confirmation Blocks
* @type {number}
*/
transactionConfirmationBlocks: number

/**
* Specify the transaction Polling Blocks Timeout
* @type {number}
*/
transactionPollingTimeout: number

/**
* Specify the multiplier for the gas fee
* @type {number}
*/
gasFeeMultiplier: number
}

export default Config
38 changes: 21 additions & 17 deletions src/pools/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import Web3 from 'web3'
import { TransactionReceipt } from 'web3-core'
import { AbiItem } from 'web3-utils'
import defaultRouter from '../artifacts/pools/FactoryRouter.sol/FactoryRouter.json'
import { getFairGasPrice } from '../utils'
import { getFairGasPrice, setContractDefaults, configHelperNetworks } from '../utils'
import { Operation } from '../interfaces/RouterInterface'
import { Config } from '../models/index.js'

/**
* Provides an interface for FactoryRouter contract
Expand All @@ -14,7 +15,7 @@ export class Router {
public routerAddress: string
public RouterAbi: AbiItem | AbiItem[]
public web3: Web3
public startBlock: number
public config: Config
public router: Contract

/**
Expand All @@ -27,13 +28,16 @@ export class Router {
routerAddress: string,
web3: Web3,
RouterAbi?: AbiItem | AbiItem[],
startBlock?: number
config?: Config
) {
this.routerAddress = routerAddress
this.RouterAbi = RouterAbi || (defaultRouter.abi as AbiItem[])
this.web3 = web3
this.startBlock = startBlock || 0
this.router = new this.web3.eth.Contract(this.RouterAbi, this.routerAddress)
this.config = config || configHelperNetworks[0]
this.router = setContractDefaults(
new this.web3.eth.Contract(this.RouterAbi, this.routerAddress),
this.config
)
}

/**
Expand Down Expand Up @@ -71,7 +75,7 @@ export class Router {
const trxReceipt = await this.router.methods.buyDTBatch(operations).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -165,7 +169,7 @@ export class Router {
const trxReceipt = await this.router.methods.addOceanToken(tokenAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -217,7 +221,7 @@ export class Router {
const trxReceipt = await this.router.methods.removeOceanToken(tokenAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -262,7 +266,7 @@ export class Router {
const trxReceipt = await this.router.methods.addSSContract(tokenAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -310,7 +314,7 @@ export class Router {
const trxReceipt = await this.router.methods.removeSSContract(tokenAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -359,7 +363,7 @@ export class Router {
const trxReceipt = await this.router.methods.addFixedRateContract(tokenAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -410,7 +414,7 @@ export class Router {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -459,7 +463,7 @@ export class Router {
const trxReceipt = await this.router.methods.addDispenserContract(tokenAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -510,7 +514,7 @@ export class Router {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -571,7 +575,7 @@ export class Router {
const trxReceipt = await this.router.methods.updateOPFFee(newFee, newFee).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -620,7 +624,7 @@ export class Router {
const trxReceipt = await this.router.methods.addPoolTemplate(templateAddress).send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down Expand Up @@ -670,7 +674,7 @@ export class Router {
.send({
from: address,
gas: estGas + 1,
gasPrice: await getFairGasPrice(this.web3)
gasPrice: await getFairGasPrice(this.web3, this.config)
})

return trxReceipt
Expand Down
Loading