Skip to content

Commit

Permalink
add getDTMaxBuyQuantity & getOceanMaxBuyQuantity
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Oct 12, 2020
1 parent f856ef7 commit a148ae7
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/balancer/OceanPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,24 @@ export class OceanPool extends Pool {
return String(parseFloat(balance) / 3)
}

/**
* Returns max amount of OCEAN that you can buy.
* @param poolAddress
* @param tokenAddress
*/
public async getOceanMaxBuyQuantity(poolAddress: string): Promise<string> {
return this.getMaxBuyQuantity(poolAddress, this.oceanAddress)
}

/**
* Returns max amount of DT that you can buy.
* @param poolAddress
* @param tokenAddress
*/
public async getDTMaxBuyQuantity(poolAddress: string): Promise<string> {
return this.getMaxBuyQuantity(poolAddress, await this.getDTAddress(poolAddress))
}

/**
* Returns tokenInAmount required to get tokenOutAmount
* @param poolAddress
Expand Down Expand Up @@ -438,8 +456,7 @@ export class OceanPool extends Pool {
}
const dtAddress = await this.getDTAddress(poolAddress)
if (
parseFloat(dtAmountWanted) >
parseFloat(await this.getMaxBuyQuantity(poolAddress, dtAddress))
parseFloat(dtAmountWanted) > parseFloat(await this.getDTMaxBuyQuantity(poolAddress))
) {
console.error('Buy quantity exceeds quantity allowed')
return null
Expand Down Expand Up @@ -495,7 +512,7 @@ export class OceanPool extends Pool {
const dtAddress = await this.getDTAddress(poolAddress)
if (
parseFloat(oceanAmountWanted) >
parseFloat(await this.getMaxBuyQuantity(poolAddress, this.oceanAddress))
parseFloat(await this.getOceanMaxBuyQuantity(poolAddress))
) {
console.error('Buy quantity exceeds quantity allowed')
return null
Expand Down Expand Up @@ -572,7 +589,7 @@ export class OceanPool extends Pool {
}
if (
parseFloat(maximumPoolShares) <
parseFloat(await this.calcPoolInGivenSingleOut(poolAddress, dtAddress, amount))
parseFloat(await this.getPoolSharesRequiredToRemoveDT(poolAddress, amount))
) {
console.error('Not enough poolShares')
return null
Expand Down Expand Up @@ -652,9 +669,7 @@ export class OceanPool extends Pool {
}
if (
parseFloat(maximumPoolShares) <
parseFloat(
await this.calcPoolInGivenSingleOut(poolAddress, this.oceanAddress, amount)
)
parseFloat(await this.getPoolSharesRequiredToRemoveOcean(poolAddress, amount))
) {
console.error('Not enough poolShares')
return null
Expand Down

0 comments on commit a148ae7

Please sign in to comment.