mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
contract updates
This commit is contained in:
parent
fc78f6553c
commit
fdb3c05ca5
@ -278,6 +278,54 @@ export class Router {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for removeSSContract method
|
||||
* @param {String} address caller address
|
||||
* @param {String} tokenAddress contract address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async estGasRemoveSSContract(
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<any> {
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.router.methods
|
||||
.removeSSContract(tokenAddress)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
return estGas
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a new contract from ssContract list
|
||||
* @param {String} address caller address
|
||||
* @param {String} tokenAddress contract address to removed
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async removeSSContract(
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<TransactionReceipt> {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await this.estGasRemoveSSContract(address, tokenAddress)
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await this.router.methods.removeSSContract(tokenAddress).send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for addFixedRateContract method
|
||||
* @param {String} address
|
||||
@ -327,6 +375,157 @@ export class Router {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for addFixedRateContract method
|
||||
* @param {String} address
|
||||
* @param {String} tokenAddress contract address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async estGasRemoveFixedRateContract(
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<any> {
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.router.methods
|
||||
.removeFixedRateContract(tokenAddress)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
return estGas
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a contract from fixedRate list
|
||||
* @param {String} address
|
||||
* @param {String} tokenAddress contract address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async removeFixedRateContract(
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<TransactionReceipt> {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await this.estGasRemoveFixedRateContract(address, tokenAddress)
|
||||
|
||||
// Invoke removeFixedRateContract function of the contract
|
||||
const trxReceipt = await this.router.methods
|
||||
.removeFixedRateContract(tokenAddress)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for addDispenserContract method
|
||||
* @param {String} address
|
||||
* @param {String} tokenAddress contract address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async estGasAddDispenserContract(
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<any> {
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.router.methods
|
||||
.addDispenserContract(tokenAddress)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
return estGas
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new contract to dispenser list, after is added, can be used when deploying a new pool
|
||||
* @param {String} address
|
||||
* @param {String} tokenAddress contract address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async addDispenserContract(
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<TransactionReceipt> {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await this.estGasAddDispenserContract(address, tokenAddress)
|
||||
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await this.router.methods.addDispenserContract(tokenAddress).send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for addDispenserContract method
|
||||
* @param {String} address
|
||||
* @param {String} tokenAddress contract address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async estGasRemoveDispenserContract(
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<any> {
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.router.methods
|
||||
.removeDispenserContract(tokenAddress)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
return estGas
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new contract to dispenser list, after is added, can be used when deploying a new pool
|
||||
* @param {String} address
|
||||
* @param {String} tokenAddress contract address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async removeDispenserContract(
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<TransactionReceipt> {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Router Owner`)
|
||||
}
|
||||
|
||||
const estGas = await this.estGasRemoveDispenserContract(address, tokenAddress)
|
||||
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await this.router.methods
|
||||
.removeDispenserContract(tokenAddress)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Get OPF Fee per token
|
||||
* @return {Promise<number>} OPF fee for a specific baseToken
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user