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

fix DTPrice if amount is too high

This commit is contained in:
alexcos20 2020-10-30 04:09:12 -07:00
parent 0a0ce63580
commit 336054a663
2 changed files with 13 additions and 2 deletions

View File

@ -840,7 +840,7 @@ export class OceanPool extends Pool {
public async getDTPrice(poolAddress: string): Promise<string> {
if (this.oceanAddress == null) {
this.logger.error('ERROR: oceanAddress is not defined')
return null
return '0'
}
return this.getOceanNeeded(poolAddress, '1')
}
@ -868,6 +868,11 @@ export class OceanPool extends Pool {
public async getOceanNeeded(poolAddress: string, dtRequired: string): Promise<string> {
const dtAddress = await this.getDTAddress(poolAddress)
if (
parseFloat(dtRequired) > parseFloat(await this.getDTMaxBuyQuantity(poolAddress))
) {
return '0'
}
return this.calcInGivenOut(poolAddress, this.oceanAddress, dtAddress, dtRequired)
}
@ -878,6 +883,12 @@ export class OceanPool extends Pool {
public async getDTNeeded(poolAddress: string, OceanRequired: string): Promise<string> {
const dtAddress = await this.getDTAddress(poolAddress)
if (
parseFloat(OceanRequired) >
parseFloat(await this.getOceanMaxBuyQuantity(poolAddress))
) {
return '0'
}
return this.calcInGivenOut(poolAddress, dtAddress, this.oceanAddress, OceanRequired)
}

View File

@ -195,7 +195,7 @@ describe('Balancer flow', () => {
alicePoolAddress,
await Pool.getDTReserve(alicePoolAddress)
)
assert(requiredOcean === null)
assert(requiredOcean === '0')
})
it('Get amount of Ocean needed to buy 1 dtToken', async () => {
const requiredOcean = await Pool.getOceanNeeded(alicePoolAddress, '1')