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

Merge pull request #431 from oceanprotocol/bug/fix_DTPrice

fix DTPrice if amount is too high
This commit is contained in:
Matthias Kretschmann 2020-10-30 13:54:12 +01:00 committed by GitHub
commit 45912fe105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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')