Skip to content

Commit

Permalink
Merge pull request #338 from oceanprotocol/fix/pool-dtAddress
Browse files Browse the repository at this point in the history
fix incorrect dtAddress
  • Loading branch information
alexcos20 authored Oct 8, 2020
2 parents 1230f1f + 6ba81c6 commit 169b7bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
33 changes: 14 additions & 19 deletions src/balancer/OceanPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ export class OceanPool extends Pool {
* @return {String}
*/
public async getDTReserve(poolAddress: string): Promise<string> {
await this.getDTAddress(poolAddress)
return super.getReserve(poolAddress, this.dtAddress)
const dtAddress = await this.getDTAddress(poolAddress)
return super.getReserve(poolAddress, dtAddress)
}

/**
Expand All @@ -163,7 +163,7 @@ export class OceanPool extends Pool {
console.error('oceanAddress is not defined')
return null
}
await this.getDTAddress(poolAddress)
const dtAddress = await this.getDTAddress(poolAddress)

// TODO - check balances first
await super.approve(
Expand All @@ -178,7 +178,7 @@ export class OceanPool extends Pool {
poolAddress,
this.oceanAddress,
oceanAmount,
this.dtAddress,
dtAddress,
amount,
maxPrice
)
Expand All @@ -204,11 +204,11 @@ export class OceanPool extends Pool {
console.error('oceanAddress is not defined')
return null
}
await this.getDTAddress(poolAddress)
const dtAddress = await this.getDTAddress(poolAddress)
return this.swapExactAmountOut(
account,
poolAddress,
this.dtAddress,
dtAddress,
amount,
this.oceanAddress,
oceanAmount,
Expand All @@ -228,17 +228,12 @@ export class OceanPool extends Pool {
poolAddress: string,
amount: string
): Promise<TransactionReceipt> {
await this.getDTAddress(poolAddress)
await super.approve(
account,
this.dtAddress,
poolAddress,
this.web3.utils.toWei(amount)
)
const dtAddress = await this.getDTAddress(poolAddress)
await super.approve(account, dtAddress, poolAddress, this.web3.utils.toWei(amount))
const result = await super.joinswapExternAmountIn(
account,
poolAddress,
this.dtAddress,
dtAddress,
amount,
'0'
)
Expand All @@ -258,12 +253,12 @@ export class OceanPool extends Pool {
amount: string,
maximumPoolShares: string
): Promise<TransactionReceipt> {
await this.getDTAddress(poolAddress)
const dtAddress = await this.getDTAddress(poolAddress)
// TODO Check balance of PoolShares before doing exit
return this.exitswapExternAmountOut(
account,
poolAddress,
this.dtAddress,
dtAddress,
amount,
maximumPoolShares
)
Expand Down Expand Up @@ -362,11 +357,11 @@ export class OceanPool extends Pool {
}

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 tokenWeightIn = await this.getDenormalizedWeight(poolAddress, this.oceanAddress)
const tokenBalanceOut = await this.getReserve(poolAddress, this.dtAddress)
const tokenWeightOut = await this.getDenormalizedWeight(poolAddress, this.dtAddress)
const tokenBalanceOut = await this.getReserve(poolAddress, dtAddress)
const tokenWeightOut = await this.getDenormalizedWeight(poolAddress, dtAddress)
const swapFee = await this.getSwapFee(poolAddress)
return super.calcInGivenOut(
tokenBalanceIn,
Expand Down
2 changes: 1 addition & 1 deletion src/balancer/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ export class Pool extends PoolFactory {
* @return {String}
*/
async getReserve(poolAddress: string, token: string): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
let amount = null
try {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
const result = await pool.methods.getBalance(token).call()
amount = this.web3.utils.fromWei(result)
} catch (e) {
Expand Down

0 comments on commit 169b7bf

Please sign in to comment.