mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
general renaming in Pool
This commit is contained in:
parent
e80483e5c8
commit
10d07f89dc
@ -35,15 +35,15 @@ 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 result = null
|
let shares = null
|
||||||
try {
|
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()
|
||||||
result = this.web3.utils.fromWei(balance)
|
shares = this.web3.utils.fromWei(balance)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get shares of pool : ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get shares of pool : ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return shares
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,12 +59,12 @@ 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 result = null
|
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 {
|
try {
|
||||||
result = 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()
|
||||||
@ -72,7 +72,7 @@ export class Pool extends SmartContract {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to set pool swap fee: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to set pool swap fee: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,13 +82,13 @@ 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 result = null
|
let tokens = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.getNumTokens().call()
|
tokens = await pool.methods.getNumTokens().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get number of tokens: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get number of tokens: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return tokens
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,8 +100,8 @@ export class Pool extends SmartContract {
|
|||||||
const pool = this.getContract(poolAddress)
|
const pool = this.getContract(poolAddress)
|
||||||
let amount = null
|
let amount = null
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods.totalSupply().call()
|
const supply = await pool.methods.totalSupply().call()
|
||||||
amount = this.web3.utils.fromWei(result)
|
amount = this.web3.utils.fromWei(supply)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to get total supply of pool shares: ${e.message}`
|
`ERROR: Failed to get total supply of pool shares: ${e.message}`
|
||||||
@ -118,15 +118,15 @@ 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 result = null
|
let tokens = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.getCurrentTokens().call()
|
tokens = await pool.methods.getCurrentTokens().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to get tokens composing this pool: ${e.message}`
|
`ERROR: Failed to get tokens composing this pool: ${e.message}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return result
|
return tokens
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,15 +137,15 @@ 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 result = null
|
let tokens = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.getFinalTokens().call()
|
tokens = await pool.methods.getFinalTokens().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to get the final tokens composing this pool ${e.message}`
|
`ERROR: Failed to get the final tokens composing this pool ${e.message}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return result
|
return tokens
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,13 +155,13 @@ 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 result = null
|
let address = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.getController().call()
|
address = await pool.methods.getController().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get pool controller address: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get pool controller address: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return address
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -171,13 +171,13 @@ 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 result = null
|
let address = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.getBaseTokenAddress().call()
|
address = await pool.methods.getBaseTokenAddress().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get baseToken address: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get baseToken address: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return address
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,13 +187,13 @@ 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 result = null
|
let address = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.getDatatokenAddress().call()
|
address = await pool.methods.getDatatokenAddress().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get datatoken address: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get datatoken address: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return address
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -203,13 +203,13 @@ 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 result = null
|
let fee = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.getMarketFee().call()
|
fee = await pool.methods.getMarketFee().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get getMarketFee: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get getMarketFee: ${e.message}`)
|
||||||
}
|
}
|
||||||
return this.web3.utils.fromWei(result).toString()
|
return this.web3.utils.fromWei(fee).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -219,15 +219,15 @@ 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 result = null
|
let address = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods._publishMarketCollector().call()
|
address = await pool.methods._publishMarketCollector().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to get marketFeeCollector address: ${e.message}`
|
`ERROR: Failed to get marketFeeCollector address: ${e.message}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return result
|
return address
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -239,14 +239,14 @@ 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 result = null
|
let isBound = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.isBound(token).call()
|
isBound = await pool.methods.isBound(token).call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to check whether a token \
|
LoggerInstance.error(`ERROR: Failed to check whether a token \
|
||||||
bounded to a pool. ${e.message}`)
|
bounded to a pool. ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return isBound
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -264,8 +264,8 @@ export class Pool extends SmartContract {
|
|||||||
let amount = null
|
let amount = null
|
||||||
try {
|
try {
|
||||||
const pool = this.getContract(poolAddress)
|
const pool = this.getContract(poolAddress)
|
||||||
const result = await pool.methods.getBalance(token).call()
|
const balance = await pool.methods.getBalance(token).call()
|
||||||
amount = await this.unitsToAmount(token, result, tokenDecimals)
|
amount = await this.unitsToAmount(token, balance, tokenDecimals)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get how many tokens \
|
LoggerInstance.error(`ERROR: Failed to get how many tokens \
|
||||||
are in the pool: ${e.message}`)
|
are in the pool: ${e.message}`)
|
||||||
@ -281,15 +281,15 @@ 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 result = null
|
let isFinalized = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.isFinalized().call()
|
isFinalized = await pool.methods.isFinalized().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to check whether pool is finalized: ${e.message}`
|
`ERROR: Failed to check whether pool is finalized: ${e.message}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return result
|
return isFinalized
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -301,8 +301,8 @@ export class Pool extends SmartContract {
|
|||||||
const pool = this.getContract(poolAddress)
|
const pool = this.getContract(poolAddress)
|
||||||
let fee = null
|
let fee = null
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods.getSwapFee().call()
|
const swapFee = await pool.methods.getSwapFee().call()
|
||||||
fee = this.web3.utils.fromWei(result)
|
fee = this.web3.utils.fromWei(swapFee)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get pool fee: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get pool fee: ${e.message}`)
|
||||||
}
|
}
|
||||||
@ -321,8 +321,8 @@ export class Pool extends SmartContract {
|
|||||||
const pool = this.getContract(poolAddress)
|
const pool = this.getContract(poolAddress)
|
||||||
let weight = null
|
let weight = null
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods.getNormalizedWeight(token).call()
|
const normalizedWeight = await pool.methods.getNormalizedWeight(token).call()
|
||||||
weight = this.web3.utils.fromWei(result)
|
weight = this.web3.utils.fromWei(normalizedWeight)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to get normalized weight of a token: ${e.message}`
|
`ERROR: Failed to get normalized weight of a token: ${e.message}`
|
||||||
@ -341,8 +341,8 @@ export class Pool extends SmartContract {
|
|||||||
const pool = this.getContract(poolAddress)
|
const pool = this.getContract(poolAddress)
|
||||||
let weight = null
|
let weight = null
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods.getDenormalizedWeight(token).call()
|
const denormalizedWeight = await pool.methods.getDenormalizedWeight(token).call()
|
||||||
weight = this.web3.utils.fromWei(result)
|
weight = this.web3.utils.fromWei(denormalizedWeight)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to get denormalized weight of a token in pool ${e.message}`
|
`ERROR: Failed to get denormalized weight of a token in pool ${e.message}`
|
||||||
@ -361,8 +361,8 @@ export class Pool extends SmartContract {
|
|||||||
const pool = this.getContract(poolAddress)
|
const pool = this.getContract(poolAddress)
|
||||||
let weight = null
|
let weight = null
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods.getTotalDenormalizedWeight().call()
|
const denormalizedWeight = await pool.methods.getTotalDenormalizedWeight().call()
|
||||||
weight = this.web3.utils.fromWei(result)
|
weight = this.web3.utils.fromWei(denormalizedWeight)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to get total denormalized weight in pool ${e.message}`
|
`ERROR: Failed to get total denormalized weight in pool ${e.message}`
|
||||||
@ -387,8 +387,8 @@ export class Pool extends SmartContract {
|
|||||||
const pool = this.getContract(poolAddress)
|
const pool = this.getContract(poolAddress)
|
||||||
let weight = null
|
let weight = null
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods.publishMarketFees(token).call()
|
const fee = await pool.methods.publishMarketFees(token).call()
|
||||||
weight = await this.unitsToAmount(token, result, tokenDecimals)
|
weight = await this.unitsToAmount(token, fee, tokenDecimals)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to get market fees for a token: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get market fees for a token: ${e.message}`)
|
||||||
}
|
}
|
||||||
@ -442,8 +442,8 @@ export class Pool extends SmartContract {
|
|||||||
const pool = this.getContract(poolAddress)
|
const pool = this.getContract(poolAddress)
|
||||||
let weight = null
|
let weight = null
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods.communityFees(token).call()
|
const fee = await pool.methods.communityFees(token).call()
|
||||||
weight = await this.unitsToAmount(token, result, tokenDecimals)
|
weight = await this.unitsToAmount(token, fee, tokenDecimals)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to get community fees for a token: ${e.message}`
|
`ERROR: Failed to get community fees for a token: ${e.message}`
|
||||||
@ -464,12 +464,12 @@ 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 result = null
|
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 {
|
try {
|
||||||
result = 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()
|
||||||
@ -477,7 +477,7 @@ export class Pool extends SmartContract {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -496,12 +496,12 @@ 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 result = null
|
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 {
|
try {
|
||||||
result = 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()
|
||||||
@ -509,7 +509,7 @@ export class Pool extends SmartContract {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -531,7 +531,7 @@ 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 result = null
|
let trxReceipt = null
|
||||||
|
|
||||||
const estGas = await calculateEstimatedGas(
|
const estGas = await calculateEstimatedGas(
|
||||||
address,
|
address,
|
||||||
@ -542,7 +542,7 @@ export class Pool extends SmartContract {
|
|||||||
if (estimateGas) return estGas
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await pool.methods
|
trxReceipt = await pool.methods
|
||||||
.updatePublishMarketFee(
|
.updatePublishMarketFee(
|
||||||
newPublishMarketAddress,
|
newPublishMarketAddress,
|
||||||
this.web3.utils.toWei(newPublishMarketSwapFee)
|
this.web3.utils.toWei(newPublishMarketSwapFee)
|
||||||
@ -555,7 +555,7 @@ export class Pool extends SmartContract {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to updatePublishMarketFee : ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to updatePublishMarketFee : ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -621,9 +621,9 @@ export class Pool extends SmartContract {
|
|||||||
)
|
)
|
||||||
if (estimateGas) return estGas
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
let result = null
|
let trxReceipt = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods
|
trxReceipt = await pool.methods
|
||||||
.swapExactAmountIn(
|
.swapExactAmountIn(
|
||||||
[
|
[
|
||||||
tokenInOutMarket.tokenIn,
|
tokenInOutMarket.tokenIn,
|
||||||
@ -646,7 +646,7 @@ export class Pool extends SmartContract {
|
|||||||
LoggerInstance.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -665,7 +665,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 result = null
|
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)) {
|
||||||
@ -709,7 +709,7 @@ export class Pool extends SmartContract {
|
|||||||
if (estimateGas) return estGas
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await pool.methods
|
trxReceipt = await pool.methods
|
||||||
.swapExactAmountOut(
|
.swapExactAmountOut(
|
||||||
[
|
[
|
||||||
tokenInOutMarket.tokenIn,
|
tokenInOutMarket.tokenIn,
|
||||||
@ -731,7 +731,7 @@ export class Pool extends SmartContract {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to swap exact amount out: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to swap exact amount out: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -754,7 +754,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 result = null
|
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)) {
|
||||||
@ -775,7 +775,7 @@ export class Pool extends SmartContract {
|
|||||||
if (estimateGas) return estGas
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await pool.methods
|
trxReceipt = await pool.methods
|
||||||
.joinswapExternAmountIn(
|
.joinswapExternAmountIn(
|
||||||
amountInFormatted,
|
amountInFormatted,
|
||||||
this.web3.utils.toWei(minPoolAmountOut)
|
this.web3.utils.toWei(minPoolAmountOut)
|
||||||
@ -789,7 +789,7 @@ export class Pool extends SmartContract {
|
|||||||
LoggerInstance.error(`ERROR: Failed to pay tokens in order to \
|
LoggerInstance.error(`ERROR: Failed to pay tokens in order to \
|
||||||
join the pool: ${e.message}`)
|
join the pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -812,7 +812,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 result = null
|
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(
|
||||||
@ -840,7 +840,7 @@ export class Pool extends SmartContract {
|
|||||||
if (estimateGas) return estGas
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = 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,
|
||||||
@ -850,7 +850,7 @@ export class Pool extends SmartContract {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to pay pool shares into the pool: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to pay pool shares into the pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -945,7 +945,7 @@ export class Pool extends SmartContract {
|
|||||||
let amount = null
|
let amount = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods
|
const amountIn = await pool.methods
|
||||||
.getAmountInExactOut(
|
.getAmountInExactOut(
|
||||||
tokenIn,
|
tokenIn,
|
||||||
tokenOut,
|
tokenOut,
|
||||||
@ -956,27 +956,27 @@ export class Pool extends SmartContract {
|
|||||||
amount = {
|
amount = {
|
||||||
tokenAmount: await this.unitsToAmount(
|
tokenAmount: await this.unitsToAmount(
|
||||||
tokenOut,
|
tokenOut,
|
||||||
result.tokenAmountIn,
|
amountIn.tokenAmountIn,
|
||||||
tokenOutDecimals
|
tokenOutDecimals
|
||||||
),
|
),
|
||||||
liquidityProviderSwapFeeAmount: await this.unitsToAmount(
|
liquidityProviderSwapFeeAmount: await this.unitsToAmount(
|
||||||
tokenIn,
|
tokenIn,
|
||||||
result.lpFeeAmount,
|
amountIn.lpFeeAmount,
|
||||||
tokenInDecimals
|
tokenInDecimals
|
||||||
),
|
),
|
||||||
oceanFeeAmount: await this.unitsToAmount(
|
oceanFeeAmount: await this.unitsToAmount(
|
||||||
tokenIn,
|
tokenIn,
|
||||||
result.oceanFeeAmount,
|
amountIn.oceanFeeAmount,
|
||||||
tokenInDecimals
|
tokenInDecimals
|
||||||
),
|
),
|
||||||
publishMarketSwapFeeAmount: await this.unitsToAmount(
|
publishMarketSwapFeeAmount: await this.unitsToAmount(
|
||||||
tokenIn,
|
tokenIn,
|
||||||
result.publishMarketSwapFeeAmount,
|
amountIn.publishMarketSwapFeeAmount,
|
||||||
tokenInDecimals
|
tokenInDecimals
|
||||||
),
|
),
|
||||||
consumeMarketSwapFeeAmount: await this.unitsToAmount(
|
consumeMarketSwapFeeAmount: await this.unitsToAmount(
|
||||||
tokenIn,
|
tokenIn,
|
||||||
result.consumeMarketSwapFeeAmount,
|
amountIn.consumeMarketSwapFeeAmount,
|
||||||
tokenInDecimals
|
tokenInDecimals
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1021,7 +1021,7 @@ export class Pool extends SmartContract {
|
|||||||
let amount = null
|
let amount = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods
|
const amountOut = await pool.methods
|
||||||
.getAmountOutExactIn(
|
.getAmountOutExactIn(
|
||||||
tokenIn,
|
tokenIn,
|
||||||
tokenOut,
|
tokenOut,
|
||||||
@ -1033,27 +1033,27 @@ export class Pool extends SmartContract {
|
|||||||
amount = {
|
amount = {
|
||||||
tokenAmount: await this.unitsToAmount(
|
tokenAmount: await this.unitsToAmount(
|
||||||
tokenOut,
|
tokenOut,
|
||||||
result.tokenAmountOut,
|
amountOut.tokenAmountOut,
|
||||||
tokenOutDecimals
|
tokenOutDecimals
|
||||||
),
|
),
|
||||||
liquidityProviderSwapFeeAmount: await this.unitsToAmount(
|
liquidityProviderSwapFeeAmount: await this.unitsToAmount(
|
||||||
tokenIn,
|
tokenIn,
|
||||||
result.lpFeeAmount,
|
amountOut.lpFeeAmount,
|
||||||
tokenInDecimals
|
tokenInDecimals
|
||||||
),
|
),
|
||||||
oceanFeeAmount: await this.unitsToAmount(
|
oceanFeeAmount: await this.unitsToAmount(
|
||||||
tokenIn,
|
tokenIn,
|
||||||
result.oceanFeeAmount,
|
amountOut.oceanFeeAmount,
|
||||||
tokenInDecimals
|
tokenInDecimals
|
||||||
),
|
),
|
||||||
publishMarketSwapFeeAmount: await this.unitsToAmount(
|
publishMarketSwapFeeAmount: await this.unitsToAmount(
|
||||||
tokenIn,
|
tokenIn,
|
||||||
result.publishMarketSwapFeeAmount,
|
amountOut.publishMarketSwapFeeAmount,
|
||||||
tokenInDecimals
|
tokenInDecimals
|
||||||
),
|
),
|
||||||
consumeMarketSwapFeeAmount: await this.unitsToAmount(
|
consumeMarketSwapFeeAmount: await this.unitsToAmount(
|
||||||
tokenIn,
|
tokenIn,
|
||||||
result.consumeMarketSwapFeeAmount,
|
amountOut.consumeMarketSwapFeeAmount,
|
||||||
tokenInDecimals
|
tokenInDecimals
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1081,14 +1081,14 @@ export class Pool extends SmartContract {
|
|||||||
let amount = null
|
let amount = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods
|
const poolOut = await pool.methods
|
||||||
.calcPoolOutSingleIn(
|
.calcPoolOutSingleIn(
|
||||||
tokenIn,
|
tokenIn,
|
||||||
await this.amountToUnits(tokenIn, tokenAmountIn, tokenInDecimals)
|
await this.amountToUnits(tokenIn, tokenAmountIn, tokenInDecimals)
|
||||||
)
|
)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
amount = await this.unitsToAmount(poolAddress, result, poolDecimals)
|
amount = await this.unitsToAmount(poolAddress, poolOut, poolDecimals)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to calculate PoolOutGivenSingleIn : ${e.message}`
|
`ERROR: Failed to calculate PoolOutGivenSingleIn : ${e.message}`
|
||||||
@ -1119,11 +1119,11 @@ export class Pool extends SmartContract {
|
|||||||
poolDecimals
|
poolDecimals
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods
|
const singleIn = await pool.methods
|
||||||
.calcSingleInPoolOut(tokenIn, amountFormatted)
|
.calcSingleInPoolOut(tokenIn, amountFormatted)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
amount = await this.unitsToAmount(tokenIn, result, tokenInDecimals)
|
amount = await this.unitsToAmount(tokenIn, singleIn, tokenInDecimals)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to calculate SingleInGivenPoolOut : ${e.message}`
|
`ERROR: Failed to calculate SingleInGivenPoolOut : ${e.message}`
|
||||||
@ -1150,13 +1150,13 @@ export class Pool extends SmartContract {
|
|||||||
let amount = null
|
let amount = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = 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, result, tokenOutDecimals)
|
amount = await this.unitsToAmount(tokenOut, singleOut, tokenOutDecimals)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to calculate SingleOutGivenPoolIn : ${e}`)
|
LoggerInstance.error(`ERROR: Failed to calculate SingleOutGivenPoolIn : ${e}`)
|
||||||
}
|
}
|
||||||
@ -1181,14 +1181,14 @@ export class Pool extends SmartContract {
|
|||||||
let amount = null
|
let amount = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods
|
const poolIn = await pool.methods
|
||||||
.calcPoolInSingleOut(
|
.calcPoolInSingleOut(
|
||||||
tokenOut,
|
tokenOut,
|
||||||
await this.amountToUnits(tokenOut, tokenAmountOut, tokenOutDecimals)
|
await this.amountToUnits(tokenOut, tokenAmountOut, tokenOutDecimals)
|
||||||
)
|
)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
amount = await this.unitsToAmount(poolAddress, result, poolDecimals)
|
amount = await this.unitsToAmount(poolAddress, poolIn, poolDecimals)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERROR: Failed to calculate PoolInGivenSingleOut : ${e.message}`
|
`ERROR: Failed to calculate PoolInGivenSingleOut : ${e.message}`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user