1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

Remove try...catch from Pool

This commit is contained in:
Miquel A. Cabot 2022-06-21 12:19:42 +02:00
parent 6bd2913fe8
commit a3a2c157df

View File

@ -35,14 +35,9 @@ export class Pool extends SmartContract {
* @return {String} * @return {String}
*/ */
async sharesBalance(account: string, poolAddress: string): Promise<string> { async sharesBalance(account: string, poolAddress: string): Promise<string> {
let shares = null
try {
const token = this.getContract(poolAddress) const token = this.getContract(poolAddress)
const balance = await token.methods.balanceOf(account).call() const balance = await token.methods.balanceOf(account).call()
shares = this.web3.utils.fromWei(balance) const shares = this.web3.utils.fromWei(balance)
} catch (e) {
LoggerInstance.error(`ERROR: Failed to get shares of pool : ${e.message}`)
}
return shares return shares
} }
@ -59,19 +54,15 @@ export class Pool extends SmartContract {
estimateGas?: G estimateGas?: G
): Promise<G extends false ? TransactionReceipt : number> { ): Promise<G extends false ? TransactionReceipt : number> {
const pool = this.getContract(poolAddress, account) const pool = this.getContract(poolAddress, account)
let trxReceipt = null
const estGas = await calculateEstimatedGas(account, pool.methods.setSwapFee, fee) const estGas = await calculateEstimatedGas(account, pool.methods.setSwapFee, fee)
if (estimateGas) return estGas if (estimateGas) return estGas
try { const trxReceipt = await pool.methods.setSwapFee(this.web3.utils.toWei(fee)).send({
trxReceipt = await pool.methods.setSwapFee(this.web3.utils.toWei(fee)).send({
from: account, from: account,
gas: estGas, gas: estGas,
gasPrice: await this.getFairGasPrice() gasPrice: await this.getFairGasPrice()
}) })
} catch (e) {
LoggerInstance.error(`ERROR: Failed to set pool swap fee: ${e.message}`)
}
return trxReceipt return trxReceipt
} }
@ -82,12 +73,7 @@ export class Pool extends SmartContract {
*/ */
async getNumTokens(poolAddress: string): Promise<string> { async getNumTokens(poolAddress: string): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let tokens = null const tokens = await pool.methods.getNumTokens().call()
try {
tokens = await pool.methods.getNumTokens().call()
} catch (e) {
LoggerInstance.error(`ERROR: Failed to get number of tokens: ${e.message}`)
}
return tokens return tokens
} }
@ -98,15 +84,8 @@ export class Pool extends SmartContract {
*/ */
async getPoolSharesTotalSupply(poolAddress: string): Promise<string> { async getPoolSharesTotalSupply(poolAddress: string): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let amount = null
try {
const supply = await pool.methods.totalSupply().call() const supply = await pool.methods.totalSupply().call()
amount = this.web3.utils.fromWei(supply) const amount = this.web3.utils.fromWei(supply)
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to get total supply of pool shares: ${e.message}`
)
}
return amount return amount
} }
@ -118,14 +97,7 @@ export class Pool extends SmartContract {
*/ */
async getCurrentTokens(poolAddress: string): Promise<string[]> { async getCurrentTokens(poolAddress: string): Promise<string[]> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let tokens = null const tokens = await pool.methods.getCurrentTokens().call()
try {
tokens = await pool.methods.getCurrentTokens().call()
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to get tokens composing this pool: ${e.message}`
)
}
return tokens return tokens
} }
@ -137,14 +109,7 @@ export class Pool extends SmartContract {
*/ */
async getFinalTokens(poolAddress: string): Promise<string[]> { async getFinalTokens(poolAddress: string): Promise<string[]> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let tokens = null const tokens = await pool.methods.getFinalTokens().call()
try {
tokens = await pool.methods.getFinalTokens().call()
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to get the final tokens composing this pool ${e.message}`
)
}
return tokens return tokens
} }
@ -155,12 +120,7 @@ export class Pool extends SmartContract {
*/ */
async getController(poolAddress: string): Promise<string> { async getController(poolAddress: string): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let address = null const address = await pool.methods.getController().call()
try {
address = await pool.methods.getController().call()
} catch (e) {
LoggerInstance.error(`ERROR: Failed to get pool controller address: ${e.message}`)
}
return address return address
} }
@ -171,12 +131,7 @@ export class Pool extends SmartContract {
*/ */
async getBasetoken(poolAddress: string): Promise<string> { async getBasetoken(poolAddress: string): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let address = null const address = await pool.methods.getBaseTokenAddress().call()
try {
address = await pool.methods.getBaseTokenAddress().call()
} catch (e) {
LoggerInstance.error(`ERROR: Failed to get baseToken address: ${e.message}`)
}
return address return address
} }
@ -187,12 +142,7 @@ export class Pool extends SmartContract {
*/ */
async getDatatoken(poolAddress: string): Promise<string> { async getDatatoken(poolAddress: string): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let address = null const address = await pool.methods.getDatatokenAddress().call()
try {
address = await pool.methods.getDatatokenAddress().call()
} catch (e) {
LoggerInstance.error(`ERROR: Failed to get datatoken address: ${e.message}`)
}
return address return address
} }
@ -203,12 +153,7 @@ export class Pool extends SmartContract {
*/ */
async getMarketFee(poolAddress: string): Promise<string> { async getMarketFee(poolAddress: string): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let fee = null const fee = await pool.methods.getMarketFee().call()
try {
fee = await pool.methods.getMarketFee().call()
} catch (e) {
LoggerInstance.error(`ERROR: Failed to get getMarketFee: ${e.message}`)
}
return this.web3.utils.fromWei(fee).toString() return this.web3.utils.fromWei(fee).toString()
} }
@ -219,14 +164,7 @@ export class Pool extends SmartContract {
*/ */
async getMarketFeeCollector(poolAddress: string): Promise<string> { async getMarketFeeCollector(poolAddress: string): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let address = null const address = await pool.methods._publishMarketCollector().call()
try {
address = await pool.methods._publishMarketCollector().call()
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to get marketFeeCollector address: ${e.message}`
)
}
return address return address
} }
@ -239,13 +177,7 @@ export class Pool extends SmartContract {
*/ */
async isBound(poolAddress: string, token: string): Promise<boolean> { async isBound(poolAddress: string, token: string): Promise<boolean> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let isBound = null const isBound = await pool.methods.isBound(token).call()
try {
isBound = await pool.methods.isBound(token).call()
} catch (e) {
LoggerInstance.error(`ERROR: Failed to check whether a token \
bounded to a pool. ${e.message}`)
}
return isBound return isBound
} }
@ -261,15 +193,9 @@ export class Pool extends SmartContract {
token: string, token: string,
tokenDecimals?: number tokenDecimals?: number
): Promise<string> { ): Promise<string> {
let amount = null
try {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
const balance = await pool.methods.getBalance(token).call() const balance = await pool.methods.getBalance(token).call()
amount = await this.unitsToAmount(token, balance, tokenDecimals) const amount = await this.unitsToAmount(token, balance, tokenDecimals)
} catch (e) {
LoggerInstance.error(`ERROR: Failed to get how many tokens \
are in the pool: ${e.message}`)
}
return amount.toString() return amount.toString()
} }
@ -281,14 +207,7 @@ export class Pool extends SmartContract {
*/ */
async isFinalized(poolAddress: string): Promise<boolean> { async isFinalized(poolAddress: string): Promise<boolean> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let isFinalized = null const isFinalized = await pool.methods.isFinalized().call()
try {
isFinalized = await pool.methods.isFinalized().call()
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to check whether pool is finalized: ${e.message}`
)
}
return isFinalized return isFinalized
} }
@ -299,13 +218,8 @@ export class Pool extends SmartContract {
*/ */
async getSwapFee(poolAddress: string): Promise<string> { async getSwapFee(poolAddress: string): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let fee = null
try {
const swapFee = await pool.methods.getSwapFee().call() const swapFee = await pool.methods.getSwapFee().call()
fee = this.web3.utils.fromWei(swapFee) const fee = this.web3.utils.fromWei(swapFee)
} catch (e) {
LoggerInstance.error(`ERROR: Failed to get pool fee: ${e.message}`)
}
return fee return fee
} }
@ -319,15 +233,8 @@ export class Pool extends SmartContract {
*/ */
async getNormalizedWeight(poolAddress: string, token: string): Promise<string> { async getNormalizedWeight(poolAddress: string, token: string): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let weight = null
try {
const normalizedWeight = await pool.methods.getNormalizedWeight(token).call() const normalizedWeight = await pool.methods.getNormalizedWeight(token).call()
weight = this.web3.utils.fromWei(normalizedWeight) const weight = this.web3.utils.fromWei(normalizedWeight)
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to get normalized weight of a token: ${e.message}`
)
}
return weight return weight
} }
@ -339,15 +246,8 @@ export class Pool extends SmartContract {
*/ */
async getDenormalizedWeight(poolAddress: string, token: string): Promise<string> { async getDenormalizedWeight(poolAddress: string, token: string): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let weight = null
try {
const denormalizedWeight = await pool.methods.getDenormalizedWeight(token).call() const denormalizedWeight = await pool.methods.getDenormalizedWeight(token).call()
weight = this.web3.utils.fromWei(denormalizedWeight) const weight = this.web3.utils.fromWei(denormalizedWeight)
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to get denormalized weight of a token in pool ${e.message}`
)
}
return weight return weight
} }
@ -359,15 +259,8 @@ export class Pool extends SmartContract {
*/ */
async getTotalDenormalizedWeight(poolAddress: string): Promise<string> { async getTotalDenormalizedWeight(poolAddress: string): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let weight = null
try {
const denormalizedWeight = await pool.methods.getTotalDenormalizedWeight().call() const denormalizedWeight = await pool.methods.getTotalDenormalizedWeight().call()
weight = this.web3.utils.fromWei(denormalizedWeight) const weight = this.web3.utils.fromWei(denormalizedWeight)
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to get total denormalized weight in pool ${e.message}`
)
}
return weight return weight
} }
@ -385,13 +278,8 @@ export class Pool extends SmartContract {
tokenDecimals?: number tokenDecimals?: number
): Promise<string> { ): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let weight = null
try {
const fee = await pool.methods.publishMarketFees(token).call() const fee = await pool.methods.publishMarketFees(token).call()
weight = await this.unitsToAmount(token, fee, tokenDecimals) const weight = await this.unitsToAmount(token, fee, tokenDecimals)
} catch (e) {
LoggerInstance.error(`ERROR: Failed to get market fees for a token: ${e.message}`)
}
return weight return weight
} }
@ -401,14 +289,8 @@ export class Pool extends SmartContract {
*/ */
async getCurrentMarketFees(poolAddress: string): Promise<CurrentFees> { async getCurrentMarketFees(poolAddress: string): Promise<CurrentFees> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
try {
const currentMarketFees = await pool.methods.getCurrentOPCFees().call() const currentMarketFees = await pool.methods.getCurrentOPCFees().call()
return currentMarketFees return currentMarketFees
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to get community fees for a token: ${e.message}`
)
}
} }
/** /**
@ -417,14 +299,8 @@ export class Pool extends SmartContract {
*/ */
async getCurrentOPCFees(poolAddress: string): Promise<CurrentFees> { async getCurrentOPCFees(poolAddress: string): Promise<CurrentFees> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
try {
const currentMarketFees = await pool.methods.getCurrentOPCFees().call() const currentMarketFees = await pool.methods.getCurrentOPCFees().call()
return currentMarketFees return currentMarketFees
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to get community fees for a token: ${e.message}`
)
}
} }
/** /**
@ -440,15 +316,8 @@ export class Pool extends SmartContract {
tokenDecimals?: number tokenDecimals?: number
): Promise<string> { ): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let weight = null
try {
const fee = await pool.methods.communityFees(token).call() const fee = await pool.methods.communityFees(token).call()
weight = await this.unitsToAmount(token, fee, tokenDecimals) const weight = await this.unitsToAmount(token, fee, tokenDecimals)
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to get community fees for a token: ${e.message}`
)
}
return weight return weight
} }
@ -464,19 +333,15 @@ export class Pool extends SmartContract {
estimateGas?: G estimateGas?: G
): Promise<G extends false ? TransactionReceipt : number> { ): Promise<G extends false ? TransactionReceipt : number> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let trxReceipt = null
const estGas = await calculateEstimatedGas(address, pool.methods.collectOPC) const estGas = await calculateEstimatedGas(address, pool.methods.collectOPC)
if (estimateGas) return estGas if (estimateGas) return estGas
try { const trxReceipt = await pool.methods.collectOPC().send({
trxReceipt = await pool.methods.collectOPC().send({
from: address, from: address,
gas: estGas + 1, gas: estGas + 1,
gasPrice: await this.getFairGasPrice() gasPrice: await this.getFairGasPrice()
}) })
} catch (e) {
LoggerInstance.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
}
return trxReceipt return trxReceipt
} }
@ -496,19 +361,15 @@ export class Pool extends SmartContract {
throw new Error(`Caller is not MarketFeeCollector`) throw new Error(`Caller is not MarketFeeCollector`)
} }
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let trxReceipt = null
const estGas = await calculateEstimatedGas(address, pool.methods.collectMarketFee) const estGas = await calculateEstimatedGas(address, pool.methods.collectMarketFee)
if (estimateGas) return estGas if (estimateGas) return estGas
try { const trxReceipt = await pool.methods.collectMarketFee().send({
trxReceipt = await pool.methods.collectMarketFee().send({
from: address, from: address,
gas: estGas + 1, gas: estGas + 1,
gasPrice: await this.getFairGasPrice() gasPrice: await this.getFairGasPrice()
}) })
} catch (e) {
LoggerInstance.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
}
return trxReceipt return trxReceipt
} }
@ -531,7 +392,6 @@ export class Pool extends SmartContract {
throw new Error(`Caller is not MarketFeeCollector`) throw new Error(`Caller is not MarketFeeCollector`)
} }
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let trxReceipt = null
const estGas = await calculateEstimatedGas( const estGas = await calculateEstimatedGas(
address, address,
@ -541,8 +401,7 @@ export class Pool extends SmartContract {
) )
if (estimateGas) return estGas if (estimateGas) return estGas
try { const trxReceipt = await pool.methods
trxReceipt = await pool.methods
.updatePublishMarketFee( .updatePublishMarketFee(
newPublishMarketAddress, newPublishMarketAddress,
this.web3.utils.toWei(newPublishMarketSwapFee) this.web3.utils.toWei(newPublishMarketSwapFee)
@ -552,9 +411,6 @@ export class Pool extends SmartContract {
gas: estGas + 1, gas: estGas + 1,
gasPrice: await this.getFairGasPrice() gasPrice: await this.getFairGasPrice()
}) })
} catch (e) {
LoggerInstance.error(`ERROR: Failed to updatePublishMarketFee : ${e.message}`)
}
return trxReceipt return trxReceipt
} }
@ -621,9 +477,7 @@ export class Pool extends SmartContract {
) )
if (estimateGas) return estGas if (estimateGas) return estGas
let trxReceipt = null const trxReceipt = await pool.methods
try {
trxReceipt = await pool.methods
.swapExactAmountIn( .swapExactAmountIn(
[ [
tokenInOutMarket.tokenIn, tokenInOutMarket.tokenIn,
@ -642,9 +496,6 @@ export class Pool extends SmartContract {
gas: estGas + 1, gas: estGas + 1,
gasPrice: await this.getFairGasPrice() gasPrice: await this.getFairGasPrice()
}) })
} catch (e) {
LoggerInstance.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
}
return trxReceipt return trxReceipt
} }
@ -665,7 +516,6 @@ export class Pool extends SmartContract {
estimateGas?: G estimateGas?: G
): Promise<G extends false ? TransactionReceipt : number> { ): Promise<G extends false ? TransactionReceipt : number> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let trxReceipt = null
const maxSwap = await this.getMaxSwapExactOut(poolAddress, tokenInOutMarket.tokenOut) const maxSwap = await this.getMaxSwapExactOut(poolAddress, tokenInOutMarket.tokenOut)
if (new Decimal(amountsInOutMaxFee.tokenAmountOut).greaterThan(maxSwap)) { if (new Decimal(amountsInOutMaxFee.tokenAmountOut).greaterThan(maxSwap)) {
@ -708,8 +558,7 @@ export class Pool extends SmartContract {
) )
if (estimateGas) return estGas if (estimateGas) return estGas
try { const trxReceipt = await pool.methods
trxReceipt = await pool.methods
.swapExactAmountOut( .swapExactAmountOut(
[ [
tokenInOutMarket.tokenIn, tokenInOutMarket.tokenIn,
@ -728,9 +577,6 @@ export class Pool extends SmartContract {
gas: estGas + 1, gas: estGas + 1,
gasPrice: await this.getFairGasPrice() gasPrice: await this.getFairGasPrice()
}) })
} catch (e) {
LoggerInstance.error(`ERROR: Failed to swap exact amount out: ${e.message}`)
}
return trxReceipt return trxReceipt
} }
@ -754,7 +600,7 @@ export class Pool extends SmartContract {
estimateGas?: G estimateGas?: G
): Promise<G extends false ? TransactionReceipt : number> { ): Promise<G extends false ? TransactionReceipt : number> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let trxReceipt = null
const tokenIn = await this.getBasetoken(poolAddress) const tokenIn = await this.getBasetoken(poolAddress)
const maxSwap = await this.getMaxAddLiquidity(poolAddress, tokenIn) const maxSwap = await this.getMaxAddLiquidity(poolAddress, tokenIn)
if (new Decimal(tokenAmountIn).greaterThan(maxSwap)) { if (new Decimal(tokenAmountIn).greaterThan(maxSwap)) {
@ -774,21 +620,13 @@ export class Pool extends SmartContract {
) )
if (estimateGas) return estGas if (estimateGas) return estGas
try { const trxReceipt = await pool.methods
trxReceipt = await pool.methods .joinswapExternAmountIn(amountInFormatted, this.web3.utils.toWei(minPoolAmountOut))
.joinswapExternAmountIn(
amountInFormatted,
this.web3.utils.toWei(minPoolAmountOut)
)
.send({ .send({
from: account, from: account,
gas: estGas + 1, gas: estGas + 1,
gasPrice: await this.getFairGasPrice() gasPrice: await this.getFairGasPrice()
}) })
} catch (e) {
LoggerInstance.error(`ERROR: Failed to pay tokens in order to \
join the pool: ${e.message}`)
}
return trxReceipt return trxReceipt
} }
@ -812,7 +650,7 @@ export class Pool extends SmartContract {
estimateGas?: G estimateGas?: G
): Promise<G extends false ? TransactionReceipt : number> { ): Promise<G extends false ? TransactionReceipt : number> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let trxReceipt = null
const tokenOut = await this.getBasetoken(poolAddress) const tokenOut = await this.getBasetoken(poolAddress)
const tokenAmountOut = await this.calcSingleOutGivenPoolIn( const tokenAmountOut = await this.calcSingleOutGivenPoolIn(
@ -839,17 +677,13 @@ export class Pool extends SmartContract {
) )
if (estimateGas) return estGas if (estimateGas) return estGas
try { const trxReceipt = await pool.methods
trxReceipt = await pool.methods
.exitswapPoolAmountIn(this.web3.utils.toWei(poolAmountIn), minTokenOutFormatted) .exitswapPoolAmountIn(this.web3.utils.toWei(poolAmountIn), minTokenOutFormatted)
.send({ .send({
from: account, from: account,
gas: estGas + 1, gas: estGas + 1,
gasPrice: await this.getFairGasPrice() gasPrice: await this.getFairGasPrice()
}) })
} catch (e) {
LoggerInstance.error(`ERROR: Failed to pay pool shares into the pool: ${e.message}`)
}
return trxReceipt return trxReceipt
} }
@ -882,17 +716,10 @@ export class Pool extends SmartContract {
LoggerInstance.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18 ${e.message}`) LoggerInstance.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18 ${e.message}`)
} }
let price = null let price = await pool.methods
try {
price = await pool.methods
.getSpotPrice(tokenIn, tokenOut, this.web3.utils.toWei(swapMarketFee)) .getSpotPrice(tokenIn, tokenOut, this.web3.utils.toWei(swapMarketFee))
.call() .call()
price = new BigNumber(price.toString()) price = new BigNumber(price.toString())
} catch (e) {
LoggerInstance.error(
'ERROR: Failed to get spot price of swapping tokenIn to tokenOut'
)
}
let decimalsDiff let decimalsDiff
if (decimalsTokenIn > decimalsTokenOut) { if (decimalsTokenIn > decimalsTokenOut) {
@ -942,9 +769,6 @@ export class Pool extends SmartContract {
tokenOutDecimals tokenOutDecimals
) )
let amount = null
try {
const amountIn = await pool.methods const amountIn = await pool.methods
.getAmountInExactOut( .getAmountInExactOut(
tokenIn, tokenIn,
@ -953,7 +777,7 @@ export class Pool extends SmartContract {
this.web3.utils.toWei(swapMarketFee) this.web3.utils.toWei(swapMarketFee)
) )
.call() .call()
amount = { const amount = {
tokenAmount: await this.unitsToAmount( tokenAmount: await this.unitsToAmount(
tokenOut, tokenOut,
amountIn.tokenAmountIn, amountIn.tokenAmountIn,
@ -980,9 +804,6 @@ export class Pool extends SmartContract {
tokenInDecimals tokenInDecimals
) )
} }
} catch (e) {
LoggerInstance.error(`ERROR: Failed to calcInGivenOut ${e.message}`)
}
return amount return amount
} }
@ -1018,9 +839,6 @@ export class Pool extends SmartContract {
tokenInDecimals tokenInDecimals
) )
let amount = null
try {
const amountOut = await pool.methods const amountOut = await pool.methods
.getAmountOutExactIn( .getAmountOutExactIn(
tokenIn, tokenIn,
@ -1030,7 +848,7 @@ export class Pool extends SmartContract {
) )
.call() .call()
amount = { const amount = {
tokenAmount: await this.unitsToAmount( tokenAmount: await this.unitsToAmount(
tokenOut, tokenOut,
amountOut.tokenAmountOut, amountOut.tokenAmountOut,
@ -1057,9 +875,6 @@ export class Pool extends SmartContract {
tokenInDecimals tokenInDecimals
) )
} }
} catch (e) {
LoggerInstance.error(`ERROR: Failed to calcOutGivenIn ${e.message}`)
}
return amount return amount
} }
@ -1078,9 +893,7 @@ export class Pool extends SmartContract {
tokenInDecimals?: number tokenInDecimals?: number
): Promise<string> { ): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let amount = null
try {
const poolOut = await pool.methods const poolOut = await pool.methods
.calcPoolOutSingleIn( .calcPoolOutSingleIn(
tokenIn, tokenIn,
@ -1088,12 +901,7 @@ export class Pool extends SmartContract {
) )
.call() .call()
amount = await this.unitsToAmount(poolAddress, poolOut, poolDecimals) const amount = await this.unitsToAmount(poolAddress, poolOut, poolDecimals)
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to calculate PoolOutGivenSingleIn : ${e.message}`
)
}
return amount return amount
} }
@ -1112,23 +920,17 @@ export class Pool extends SmartContract {
tokenInDecimals?: number tokenInDecimals?: number
): Promise<string> { ): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let amount = null
const amountFormatted = await this.amountToUnits( const amountFormatted = await this.amountToUnits(
poolAddress, poolAddress,
poolAmountOut, poolAmountOut,
poolDecimals poolDecimals
) )
try {
const singleIn = await pool.methods const singleIn = await pool.methods
.calcSingleInPoolOut(tokenIn, amountFormatted) .calcSingleInPoolOut(tokenIn, amountFormatted)
.call() .call()
amount = await this.unitsToAmount(tokenIn, singleIn, tokenInDecimals) const amount = await this.unitsToAmount(tokenIn, singleIn, tokenInDecimals)
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to calculate SingleInGivenPoolOut : ${e.message}`
)
}
return amount return amount
} }
@ -1147,19 +949,14 @@ export class Pool extends SmartContract {
tokenOutDecimals?: number tokenOutDecimals?: number
): Promise<string> { ): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let amount = null
try {
const singleOut = await pool.methods const singleOut = await pool.methods
.calcSingleOutPoolIn( .calcSingleOutPoolIn(
tokenOut, tokenOut,
await this.amountToUnits(poolAddress, poolAmountIn, poolDecimals) await this.amountToUnits(poolAddress, poolAmountIn, poolDecimals)
) )
.call() .call()
amount = await this.unitsToAmount(tokenOut, singleOut, tokenOutDecimals) const amount = await this.unitsToAmount(tokenOut, singleOut, tokenOutDecimals)
} catch (e) {
LoggerInstance.error(`ERROR: Failed to calculate SingleOutGivenPoolIn : ${e}`)
}
return amount return amount
} }
@ -1178,9 +975,7 @@ export class Pool extends SmartContract {
tokenOutDecimals?: number tokenOutDecimals?: number
): Promise<string> { ): Promise<string> {
const pool = this.getContract(poolAddress) const pool = this.getContract(poolAddress)
let amount = null
try {
const poolIn = await pool.methods const poolIn = await pool.methods
.calcPoolInSingleOut( .calcPoolInSingleOut(
tokenOut, tokenOut,
@ -1188,12 +983,7 @@ export class Pool extends SmartContract {
) )
.call() .call()
amount = await this.unitsToAmount(poolAddress, poolIn, poolDecimals) const amount = await this.unitsToAmount(poolAddress, poolIn, poolDecimals)
} catch (e) {
LoggerInstance.error(
`ERROR: Failed to calculate PoolInGivenSingleOut : ${e.message}`
)
}
return amount return amount
} }