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

fix incorrect dtAddress

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2020-10-07 13:42:28 +03:00
parent 1230f1f680
commit 6ba81c60f7
No known key found for this signature in database
GPG Key ID: 4FB0C2329B4C6E29
2 changed files with 15 additions and 20 deletions

View File

@ -139,8 +139,8 @@ export class OceanPool extends Pool {
* @return {String} * @return {String}
*/ */
public async getDTReserve(poolAddress: string): Promise<string> { public async getDTReserve(poolAddress: string): Promise<string> {
await this.getDTAddress(poolAddress) const dtAddress = await this.getDTAddress(poolAddress)
return super.getReserve(poolAddress, this.dtAddress) return super.getReserve(poolAddress, dtAddress)
} }
/** /**
@ -163,7 +163,7 @@ export class OceanPool extends Pool {
console.error('oceanAddress is not defined') console.error('oceanAddress is not defined')
return null return null
} }
await this.getDTAddress(poolAddress) const dtAddress = await this.getDTAddress(poolAddress)
// TODO - check balances first // TODO - check balances first
await super.approve( await super.approve(
@ -178,7 +178,7 @@ export class OceanPool extends Pool {
poolAddress, poolAddress,
this.oceanAddress, this.oceanAddress,
oceanAmount, oceanAmount,
this.dtAddress, dtAddress,
amount, amount,
maxPrice maxPrice
) )
@ -204,11 +204,11 @@ export class OceanPool extends Pool {
console.error('oceanAddress is not defined') console.error('oceanAddress is not defined')
return null return null
} }
await this.getDTAddress(poolAddress) const dtAddress = await this.getDTAddress(poolAddress)
return this.swapExactAmountOut( return this.swapExactAmountOut(
account, account,
poolAddress, poolAddress,
this.dtAddress, dtAddress,
amount, amount,
this.oceanAddress, this.oceanAddress,
oceanAmount, oceanAmount,
@ -228,17 +228,12 @@ export class OceanPool extends Pool {
poolAddress: string, poolAddress: string,
amount: string amount: string
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
await this.getDTAddress(poolAddress) const dtAddress = await this.getDTAddress(poolAddress)
await super.approve( await super.approve(account, dtAddress, poolAddress, this.web3.utils.toWei(amount))
account,
this.dtAddress,
poolAddress,
this.web3.utils.toWei(amount)
)
const result = await super.joinswapExternAmountIn( const result = await super.joinswapExternAmountIn(
account, account,
poolAddress, poolAddress,
this.dtAddress, dtAddress,
amount, amount,
'0' '0'
) )
@ -258,12 +253,12 @@ export class OceanPool extends Pool {
amount: string, amount: string,
maximumPoolShares: string maximumPoolShares: string
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
await this.getDTAddress(poolAddress) const dtAddress = await this.getDTAddress(poolAddress)
// TODO Check balance of PoolShares before doing exit // TODO Check balance of PoolShares before doing exit
return this.exitswapExternAmountOut( return this.exitswapExternAmountOut(
account, account,
poolAddress, poolAddress,
this.dtAddress, dtAddress,
amount, amount,
maximumPoolShares maximumPoolShares
) )
@ -362,11 +357,11 @@ export class OceanPool extends Pool {
} }
public async getOceanNeeded(poolAddress: string, dtRequired: string): Promise<string> { public async getOceanNeeded(poolAddress: string, dtRequired: string): Promise<string> {
await this.getDTAddress(poolAddress) const dtAddress = await this.getDTAddress(poolAddress)
const tokenBalanceIn = await this.getReserve(poolAddress, this.oceanAddress) const tokenBalanceIn = await this.getReserve(poolAddress, this.oceanAddress)
const tokenWeightIn = await this.getDenormalizedWeight(poolAddress, this.oceanAddress) const tokenWeightIn = await this.getDenormalizedWeight(poolAddress, this.oceanAddress)
const tokenBalanceOut = await this.getReserve(poolAddress, this.dtAddress) const tokenBalanceOut = await this.getReserve(poolAddress, dtAddress)
const tokenWeightOut = await this.getDenormalizedWeight(poolAddress, this.dtAddress) const tokenWeightOut = await this.getDenormalizedWeight(poolAddress, dtAddress)
const swapFee = await this.getSwapFee(poolAddress) const swapFee = await this.getSwapFee(poolAddress)
return super.calcInGivenOut( return super.calcInGivenOut(
tokenBalanceIn, tokenBalanceIn,

View File

@ -368,9 +368,9 @@ export class Pool extends PoolFactory {
* @return {String} * @return {String}
*/ */
async getReserve(poolAddress: string, token: string): Promise<string> { async getReserve(poolAddress: string, token: string): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
let amount = null let amount = null
try { try {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
const result = await pool.methods.getBalance(token).call() const result = await pool.methods.getBalance(token).call()
amount = this.web3.utils.fromWei(result) amount = this.web3.utils.fromWei(result)
} catch (e) { } catch (e) {