From fec3670e6a23ea4adbaf6a24bba32638a1d9fb18 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Mon, 31 Aug 2020 08:13:58 -0700 Subject: [PATCH] updates --- ...ixRateExchange.ts => FixedRateExchange.ts} | 31 +++++++------------ src/ocean/Ocean.ts | 5 ++- .../unit/exchanges/FixedPriceExchange.test.ts | 2 +- 3 files changed, 16 insertions(+), 22 deletions(-) rename src/exchange/{FixRateExchange.ts => FixedRateExchange.ts} (93%) diff --git a/src/exchange/FixRateExchange.ts b/src/exchange/FixedRateExchange.ts similarity index 93% rename from src/exchange/FixRateExchange.ts rename to src/exchange/FixedRateExchange.ts index 333a9b15..c8cb15a6 100644 --- a/src/exchange/FixRateExchange.ts +++ b/src/exchange/FixedRateExchange.ts @@ -11,6 +11,8 @@ export interface FixedPricedExchange { supply: string } +const DEFAULT_GAS_LIMIT = 200000 + export class OceanFixedRateExchange { /** Ocean related functions */ public oceanAddress: string = null @@ -104,24 +106,14 @@ export class OceanFixedRateExchange { .swap(exchangeId, this.web3.utils.toWei(String(dataTokenAmount))) .estimateGas(function (err, g) { if (err) { - // console.log('FixedPriceExchange: ' + err) - return 200000 + return DEFAULT_GAS_LIMIT } else { return g } }) } catch (e) { - // console.log('FixedPriceExchange: ' + e) - estGas = 200000 + estGas = DEFAULT_GAS_LIMIT } - // console.log('estGas: ' + estGas) - /* const estGas = await this.contract.methods - .swap(exchangeId, this.web3.utils.toWei(String(dataTokenAmount))) - .estimateGas(function (err, estGas) { - if (err) console.log('FixedPriceExchange: ' + err) - return estGas - }) - */ try { const trxReceipt = await this.contract.methods .swap(exchangeId, this.web3.utils.toWei(String(dataTokenAmount))) @@ -166,12 +158,12 @@ export class OceanFixedRateExchange { .estimateGas(function (err, estGas) { if (err) { // console.log('FixedPriceExchange: ' + err) - return 200000 + return DEFAULT_GAS_LIMIT } return estGas }) } catch (e) { - estGas = 200000 + estGas = DEFAULT_GAS_LIMIT } const trxReceipt = await this.contract.methods .setRate(exchangeId, this.web3.utils.toWei(String(newRate))) @@ -196,12 +188,12 @@ export class OceanFixedRateExchange { .estimateGas(function (err, estGas) { if (err) { // console.log('FixedPriceExchange: ' + err) - estGas = 200000 + estGas = DEFAULT_GAS_LIMIT } return estGas }) } catch (e) { - estGas = 200000 + estGas = DEFAULT_GAS_LIMIT } const trxReceipt = await this.contract.methods.activate(exchangeId).send({ from: address, @@ -224,12 +216,12 @@ export class OceanFixedRateExchange { .estimateGas(function (err, estGas) { if (err) { // console.log('FixedPriceExchange: ' + err) - estGas = 200000 + estGas = DEFAULT_GAS_LIMIT } return estGas }) } catch (e) { - estGas = 200000 + estGas = DEFAULT_GAS_LIMIT } const trxReceipt = await this.contract.methods.deactivate(exchangeId).send({ from: address, @@ -292,8 +284,7 @@ export class OceanFixedRateExchange { * @return {Promise} Exchanges list */ public async getExchanges(): Promise { - const result = await this.contract.methods.getExchanges().call() - return result + return await this.contract.methods.getExchanges().call() } /** diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index ad7c7a4a..98e8e5c4 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -13,7 +13,10 @@ import { } from '../Instantiable.abstract' import { Compute } from './Compute' import { OceanPool } from '../balancer/OceanPool' -import { OceanFixedRateExchange, FixedPricedExchange } from '../exchange/FixRateExchange' +import { + OceanFixedRateExchange, + FixedPricedExchange +} from '../exchange/FixedRateExchange' /** * Main interface for Ocean Protocol. diff --git a/test/unit/exchanges/FixedPriceExchange.test.ts b/test/unit/exchanges/FixedPriceExchange.test.ts index 8d59e5d4..95011b03 100644 --- a/test/unit/exchanges/FixedPriceExchange.test.ts +++ b/test/unit/exchanges/FixedPriceExchange.test.ts @@ -6,7 +6,7 @@ import { DataTokens } from '../../../src/datatokens/Datatokens' import { OceanFixedRateExchange, FixedPricedExchange -} from '../../../src/exchange/FixRateExchange' +} from '../../../src/exchange/FixedRateExchange' import Web3 from 'web3' import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'