mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
inherit FixedRateExchange from SmartContract
This commit is contained in:
parent
d12b669f65
commit
2c8832e22c
@ -1,67 +1,14 @@
|
|||||||
import defaultFixedRateExchangeAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
|
import FixedRateExchangeAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import Web3 from 'web3'
|
import { LoggerInstance, getFairGasPrice, estimateGas, ZERO_ADDRESS } from '../../utils'
|
||||||
import {
|
|
||||||
LoggerInstance,
|
|
||||||
getFairGasPrice,
|
|
||||||
setContractDefaults,
|
|
||||||
amountToUnits,
|
|
||||||
unitsToAmount,
|
|
||||||
estimateGas,
|
|
||||||
ZERO_ADDRESS
|
|
||||||
} from '../../utils'
|
|
||||||
import { Config, ConfigHelper } from '../../config'
|
|
||||||
import { PriceAndFees, FeesInfo, FixedPriceExchange } from '../../@types'
|
import { PriceAndFees, FeesInfo, FixedPriceExchange } from '../../@types'
|
||||||
|
import { SmartContractWithAddress } from '..'
|
||||||
|
|
||||||
export class FixedRateExchange {
|
export class FixedRateExchange extends SmartContractWithAddress {
|
||||||
/** Ocean related functions */
|
getDefaultAbi(): AbiItem | AbiItem[] {
|
||||||
public fixedRateAddress: string
|
return FixedRateExchangeAbi.abi as AbiItem[]
|
||||||
public fixedRateExchangeAbi: AbiItem | AbiItem[]
|
|
||||||
public web3: Web3
|
|
||||||
public fixedRateContract: Contract = null
|
|
||||||
|
|
||||||
public config: Config
|
|
||||||
public ssAbi: AbiItem | AbiItem[]
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiate FixedRateExchange
|
|
||||||
* @param {any} web3
|
|
||||||
* @param {any} fixedRateExchangeAbi
|
|
||||||
*/
|
|
||||||
constructor(
|
|
||||||
web3: Web3,
|
|
||||||
fixedRateAddress: string,
|
|
||||||
network?: string | number,
|
|
||||||
fixedRateExchangeAbi: AbiItem | AbiItem[] = null,
|
|
||||||
config?: Config
|
|
||||||
) {
|
|
||||||
this.web3 = web3
|
|
||||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
|
||||||
this.fixedRateExchangeAbi =
|
|
||||||
fixedRateExchangeAbi || (defaultFixedRateExchangeAbi.abi as AbiItem[])
|
|
||||||
this.fixedRateAddress = fixedRateAddress
|
|
||||||
this.fixedRateContract = setContractDefaults(
|
|
||||||
new this.web3.eth.Contract(this.fixedRateExchangeAbi, this.fixedRateAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async amountToUnits(
|
|
||||||
token: string,
|
|
||||||
amount: string,
|
|
||||||
tokenDecimals: number
|
|
||||||
): Promise<string> {
|
|
||||||
return amountToUnits(this.web3, token, amount, tokenDecimals)
|
|
||||||
}
|
|
||||||
|
|
||||||
async unitsToAmount(
|
|
||||||
token: string,
|
|
||||||
amount: string,
|
|
||||||
tokenDecimals: number
|
|
||||||
): Promise<string> {
|
|
||||||
return unitsToAmount(this.web3, token, amount, tokenDecimals)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +18,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<string>} exchangeId
|
* @return {Promise<string>} exchangeId
|
||||||
*/
|
*/
|
||||||
public async generateExchangeId(baseToken: string, datatoken: string): Promise<string> {
|
public async generateExchangeId(baseToken: string, datatoken: string): Promise<string> {
|
||||||
const exchangeId = await this.fixedRateContract.methods
|
const exchangeId = await this.contract.methods
|
||||||
.generateExchangeId(baseToken, datatoken)
|
.generateExchangeId(baseToken, datatoken)
|
||||||
.call()
|
.call()
|
||||||
return exchangeId
|
return exchangeId
|
||||||
@ -96,7 +43,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFee: string,
|
consumeMarketFee: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -142,7 +89,7 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.buyDT,
|
this.contract.methods.buyDT,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
maxBtFormatted,
|
maxBtFormatted,
|
||||||
@ -150,7 +97,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFeeFormatted
|
consumeMarketFeeFormatted
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.buyDT(
|
.buyDT(
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
@ -189,7 +136,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFee: string,
|
consumeMarketFee: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -234,7 +181,7 @@ export class FixedRateExchange {
|
|||||||
)
|
)
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.sellDT,
|
this.contract.methods.sellDT,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
minBtFormatted,
|
minBtFormatted,
|
||||||
@ -242,7 +189,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFeeFormatted
|
consumeMarketFeeFormatted
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.sellDT(
|
.sellDT(
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
@ -269,9 +216,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<Number>} no of available exchanges
|
* @return {Promise<Number>} no of available exchanges
|
||||||
*/
|
*/
|
||||||
public async getNumberOfExchanges(): Promise<number> {
|
public async getNumberOfExchanges(): Promise<number> {
|
||||||
const numExchanges = await this.fixedRateContract.methods
|
const numExchanges = await this.contract.methods.getNumberOfExchanges().call()
|
||||||
.getNumberOfExchanges()
|
|
||||||
.call()
|
|
||||||
return numExchanges
|
return numExchanges
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +234,7 @@ export class FixedRateExchange {
|
|||||||
newRate: string,
|
newRate: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -313,11 +258,11 @@ export class FixedRateExchange {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.setRate,
|
this.contract.methods.setRate,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
this.web3.utils.toWei(newRate)
|
this.web3.utils.toWei(newRate)
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.setRate(exchangeId, this.web3.utils.toWei(newRate))
|
.setRate(exchangeId, this.web3.utils.toWei(newRate))
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -341,7 +286,7 @@ export class FixedRateExchange {
|
|||||||
newAllowedSwapper: string,
|
newAllowedSwapper: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -365,11 +310,11 @@ export class FixedRateExchange {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.setAllowedSwapper,
|
this.contract.methods.setAllowedSwapper,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
newAllowedSwapper
|
newAllowedSwapper
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.setAllowedSwapper(exchangeId, newAllowedSwapper)
|
.setAllowedSwapper(exchangeId, newAllowedSwapper)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -391,7 +336,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
||||||
}
|
}
|
||||||
@ -411,16 +356,14 @@ export class FixedRateExchange {
|
|||||||
if (exchange.active === true) return null
|
if (exchange.active === true) return null
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.toggleExchangeState,
|
this.contract.methods.toggleExchangeState,
|
||||||
exchangeId
|
exchangeId
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
||||||
.toggleExchangeState(exchangeId)
|
from: address,
|
||||||
.send({
|
gas: estGas + 1,
|
||||||
from: address,
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
gas: estGas + 1,
|
})
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
|
||||||
})
|
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,7 +379,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
||||||
}
|
}
|
||||||
@ -457,17 +400,15 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.toggleExchangeState,
|
this.contract.methods.toggleExchangeState,
|
||||||
exchangeId
|
exchangeId
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
||||||
.toggleExchangeState(exchangeId)
|
from: address,
|
||||||
.send({
|
gas: estGas + 1,
|
||||||
from: address,
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
gas: estGas + 1,
|
})
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
|
||||||
})
|
|
||||||
|
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
@ -478,7 +419,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<string>} Rate (converted from wei)
|
* @return {Promise<string>} Rate (converted from wei)
|
||||||
*/
|
*/
|
||||||
public async getRate(exchangeId: string): Promise<string> {
|
public async getRate(exchangeId: string): Promise<string> {
|
||||||
const weiRate = await this.fixedRateContract.methods.getRate(exchangeId).call()
|
const weiRate = await this.contract.methods.getRate(exchangeId).call()
|
||||||
const rate = await this.web3.utils.fromWei(weiRate)
|
const rate = await this.web3.utils.fromWei(weiRate)
|
||||||
return rate
|
return rate
|
||||||
}
|
}
|
||||||
@ -489,7 +430,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<string>} dt supply formatted
|
* @return {Promise<string>} dt supply formatted
|
||||||
*/
|
*/
|
||||||
public async getDTSupply(exchangeId: string): Promise<string> {
|
public async getDTSupply(exchangeId: string): Promise<string> {
|
||||||
const dtSupply = await this.fixedRateContract.methods.getDTSupply(exchangeId).call()
|
const dtSupply = await this.contract.methods.getDTSupply(exchangeId).call()
|
||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
return await this.unitsToAmount(exchange.datatoken, dtSupply, +exchange.dtDecimals)
|
return await this.unitsToAmount(exchange.datatoken, dtSupply, +exchange.dtDecimals)
|
||||||
}
|
}
|
||||||
@ -500,7 +441,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<string>} dt supply formatted
|
* @return {Promise<string>} dt supply formatted
|
||||||
*/
|
*/
|
||||||
public async getBTSupply(exchangeId: string): Promise<string> {
|
public async getBTSupply(exchangeId: string): Promise<string> {
|
||||||
const btSupply = await this.fixedRateContract.methods.getBTSupply(exchangeId).call()
|
const btSupply = await this.contract.methods.getBTSupply(exchangeId).call()
|
||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
return await this.unitsToAmount(exchange.baseToken, btSupply, +exchange.btDecimals)
|
return await this.unitsToAmount(exchange.baseToken, btSupply, +exchange.btDecimals)
|
||||||
}
|
}
|
||||||
@ -511,7 +452,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<string>} address of allowedSwapper
|
* @return {Promise<string>} address of allowedSwapper
|
||||||
*/
|
*/
|
||||||
public async getAllowedSwapper(exchangeId: string): Promise<string> {
|
public async getAllowedSwapper(exchangeId: string): Promise<string> {
|
||||||
return await this.fixedRateContract.methods.getAllowedSwapper(exchangeId).call()
|
return await this.contract.methods.getAllowedSwapper(exchangeId).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -527,7 +468,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFee: string = '0'
|
consumeMarketFee: string = '0'
|
||||||
): Promise<PriceAndFees> {
|
): Promise<PriceAndFees> {
|
||||||
const fixedRateExchange = await this.getExchange(exchangeId)
|
const fixedRateExchange = await this.getExchange(exchangeId)
|
||||||
const result = await this.fixedRateContract.methods
|
const result = await this.contract.methods
|
||||||
.calcBaseInGivenOutDT(
|
.calcBaseInGivenOutDT(
|
||||||
exchangeId,
|
exchangeId,
|
||||||
await this.amountToUnits(
|
await this.amountToUnits(
|
||||||
@ -577,7 +518,7 @@ export class FixedRateExchange {
|
|||||||
consumeMarketFee: string = '0'
|
consumeMarketFee: string = '0'
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
const result = await this.fixedRateContract.methods
|
const result = await this.contract.methods
|
||||||
.calcBaseOutGivenInDT(
|
.calcBaseOutGivenInDT(
|
||||||
exchangeId,
|
exchangeId,
|
||||||
await this.amountToUnits(
|
await this.amountToUnits(
|
||||||
@ -598,7 +539,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<FixedPricedExchange>} Exchange details
|
* @return {Promise<FixedPricedExchange>} Exchange details
|
||||||
*/
|
*/
|
||||||
public async getExchange(exchangeId: string): Promise<FixedPriceExchange> {
|
public async getExchange(exchangeId: string): Promise<FixedPriceExchange> {
|
||||||
const result: FixedPriceExchange = await this.fixedRateContract.methods
|
const result: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
result.dtDecimals = result.dtDecimals.toString()
|
result.dtDecimals = result.dtDecimals.toString()
|
||||||
@ -634,9 +575,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<FixedPricedExchange>} Exchange details
|
* @return {Promise<FixedPricedExchange>} Exchange details
|
||||||
*/
|
*/
|
||||||
public async getFeesInfo(exchangeId: string): Promise<FeesInfo> {
|
public async getFeesInfo(exchangeId: string): Promise<FeesInfo> {
|
||||||
const result: FeesInfo = await this.fixedRateContract.methods
|
const result: FeesInfo = await this.contract.methods.getFeesInfo(exchangeId).call()
|
||||||
.getFeesInfo(exchangeId)
|
|
||||||
.call()
|
|
||||||
result.opcFee = this.web3.utils.fromWei(result.opcFee.toString())
|
result.opcFee = this.web3.utils.fromWei(result.opcFee.toString())
|
||||||
result.marketFee = this.web3.utils.fromWei(result.marketFee.toString())
|
result.marketFee = this.web3.utils.fromWei(result.marketFee.toString())
|
||||||
|
|
||||||
@ -662,7 +601,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<String[]>} Exchanges list
|
* @return {Promise<String[]>} Exchanges list
|
||||||
*/
|
*/
|
||||||
public async getExchanges(): Promise<string[]> {
|
public async getExchanges(): Promise<string[]> {
|
||||||
return await this.fixedRateContract.methods.getExchanges().call()
|
return await this.contract.methods.getExchanges().call()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -671,7 +610,7 @@ export class FixedRateExchange {
|
|||||||
* @return {Promise<Boolean>} Result
|
* @return {Promise<Boolean>} Result
|
||||||
*/
|
*/
|
||||||
public async isActive(exchangeId: string): Promise<boolean> {
|
public async isActive(exchangeId: string): Promise<boolean> {
|
||||||
const result = await this.fixedRateContract.methods.isActive(exchangeId).call()
|
const result = await this.contract.methods.isActive(exchangeId).call()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,7 +626,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(account, fixedRate.methods.toggleMintState, exchangeId, true)
|
return estimateGas(account, fixedRate.methods.toggleMintState, exchangeId, true)
|
||||||
}
|
}
|
||||||
@ -708,11 +647,11 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.toggleMintState,
|
this.contract.methods.toggleMintState,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.toggleMintState(exchangeId, true)
|
.toggleMintState(exchangeId, true)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -734,7 +673,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -760,12 +699,12 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.toggleMintState,
|
this.contract.methods.toggleMintState,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.toggleMintState(exchangeId, false)
|
.toggleMintState(exchangeId, false)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -790,8 +729,8 @@ export class FixedRateExchange {
|
|||||||
amount: string,
|
amount: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
const amountWei = await this.amountToUnits(
|
const amountWei = await this.amountToUnits(
|
||||||
@ -817,7 +756,7 @@ export class FixedRateExchange {
|
|||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
|
|
||||||
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
const amountWei = await this.amountToUnits(
|
const amountWei = await this.amountToUnits(
|
||||||
@ -828,18 +767,16 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.collectBT,
|
this.contract.methods.collectBT,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
amountWei
|
amountWei
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.collectBT(exchangeId, amountWei).send({
|
||||||
.collectBT(exchangeId, amountWei)
|
from: address,
|
||||||
.send({
|
gas: estGas + 1,
|
||||||
from: address,
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
gas: estGas + 1,
|
})
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
|
||||||
})
|
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -857,8 +794,8 @@ export class FixedRateExchange {
|
|||||||
amount: string,
|
amount: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
@ -885,7 +822,7 @@ export class FixedRateExchange {
|
|||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
|
|
||||||
const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
const amountWei = await this.amountToUnits(
|
const amountWei = await this.amountToUnits(
|
||||||
@ -896,18 +833,16 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.collectDT,
|
this.contract.methods.collectDT,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
amountWei
|
amountWei
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.collectDT(exchangeId, amountWei).send({
|
||||||
.collectDT(exchangeId, amountWei)
|
from: address,
|
||||||
.send({
|
gas: estGas + 1,
|
||||||
from: address,
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
gas: estGas + 1,
|
})
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
|
||||||
})
|
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -923,7 +858,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
||||||
}
|
}
|
||||||
@ -943,16 +878,14 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.collectMarketFee,
|
this.contract.methods.collectMarketFee,
|
||||||
exchangeId
|
exchangeId
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.collectMarketFee(exchangeId).send({
|
||||||
.collectMarketFee(exchangeId)
|
from: address,
|
||||||
.send({
|
gas: estGas + 1,
|
||||||
from: address,
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
gas: estGas + 1,
|
})
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
|
||||||
})
|
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -968,7 +901,7 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
||||||
}
|
}
|
||||||
@ -988,16 +921,14 @@ export class FixedRateExchange {
|
|||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.collectOceanFee,
|
this.contract.methods.collectOceanFee,
|
||||||
exchangeId
|
exchangeId
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods.collectOceanFee(exchangeId).send({
|
||||||
.collectOceanFee(exchangeId)
|
from: address,
|
||||||
.send({
|
gas: estGas + 1,
|
||||||
from: address,
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
gas: estGas + 1,
|
})
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
|
||||||
})
|
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1008,7 +939,7 @@ export class FixedRateExchange {
|
|||||||
async getOPCCollector(): Promise<string> {
|
async getOPCCollector(): Promise<string> {
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await this.fixedRateContract.methods.opcCollector().call()
|
result = await this.contract.methods.opcCollector().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get OPC Collector address: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get OPC Collector address: ${e.message}`)
|
||||||
}
|
}
|
||||||
@ -1022,7 +953,7 @@ export class FixedRateExchange {
|
|||||||
async getRouter(): Promise<string> {
|
async getRouter(): Promise<string> {
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await this.fixedRateContract.methods.router().call()
|
result = await this.contract.methods.router().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get Router address: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get Router address: ${e.message}`)
|
||||||
}
|
}
|
||||||
@ -1058,7 +989,7 @@ export class FixedRateExchange {
|
|||||||
newMarketFee: string,
|
newMarketFee: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -1082,11 +1013,11 @@ export class FixedRateExchange {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.updateMarketFee,
|
this.contract.methods.updateMarketFee,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
this.web3.utils.toWei(newMarketFee)
|
this.web3.utils.toWei(newMarketFee)
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.updateMarketFee(exchangeId, this.web3.utils.toWei(newMarketFee))
|
.updateMarketFee(exchangeId, this.web3.utils.toWei(newMarketFee))
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -1110,7 +1041,7 @@ export class FixedRateExchange {
|
|||||||
newMarketFeeCollector: string,
|
newMarketFeeCollector: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.contract
|
||||||
|
|
||||||
return estimateGas(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -1134,11 +1065,11 @@ export class FixedRateExchange {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
this.fixedRateContract.methods.updateMarketFeeCollector,
|
this.contract.methods.updateMarketFeeCollector,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
newMarketFeeCollector
|
newMarketFeeCollector
|
||||||
)
|
)
|
||||||
const trxReceipt = await this.fixedRateContract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.updateMarketFeeCollector(exchangeId, newMarketFeeCollector)
|
.updateMarketFeeCollector(exchangeId, newMarketFeeCollector)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
|
@ -614,7 +614,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
|
|
||||||
it('7.3 Marketplace displays fixed rate asset for sale', async () => {
|
it('7.3 Marketplace displays fixed rate asset for sale', async () => {
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
const fixedRate = new FixedRateExchange(web3, freAddress)
|
const fixedRate = new FixedRateExchange(freAddress, web3)
|
||||||
const oceanAmount = await (
|
const oceanAmount = await (
|
||||||
await fixedRate.calcBaseInGivenOutDT(freId, '1')
|
await fixedRate.calcBaseInGivenOutDT(freId, '1')
|
||||||
).baseTokenAmount
|
).baseTokenAmount
|
||||||
@ -655,7 +655,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
DATATOKEN_AMOUNT
|
DATATOKEN_AMOUNT
|
||||||
)
|
)
|
||||||
|
|
||||||
const fixedRate = new FixedRateExchange(web3, freAddress)
|
const fixedRate = new FixedRateExchange(freAddress, web3)
|
||||||
/// ```
|
/// ```
|
||||||
/// Now we can make the contract call
|
/// Now we can make the contract call
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
|
@ -100,7 +100,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
// user1 has no dt1
|
// user1 has no dt1
|
||||||
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
||||||
|
|
||||||
fixedRate = new FixedRateExchange(web3, contracts.fixedRateAddress, 8996)
|
fixedRate = new FixedRateExchange(contracts.fixedRateAddress, web3, 8996)
|
||||||
assert(fixedRate != null)
|
assert(fixedRate != null)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -409,7 +409,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
// user1 has no dt1
|
// user1 has no dt1
|
||||||
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
||||||
|
|
||||||
fixedRate = new FixedRateExchange(web3, contracts.fixedRateAddress, 8996)
|
fixedRate = new FixedRateExchange(contracts.fixedRateAddress, web3, 8996)
|
||||||
assert(fixedRate != null)
|
assert(fixedRate != null)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user