diff --git a/src/balancer/OceanPool.ts b/src/balancer/OceanPool.ts index 501740ee..4a95e98b 100644 --- a/src/balancer/OceanPool.ts +++ b/src/balancer/OceanPool.ts @@ -840,7 +840,7 @@ export class OceanPool extends Pool { public async getDTPrice(poolAddress: string): Promise { 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 { 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 { const dtAddress = await this.getDTAddress(poolAddress) + if ( + parseFloat(OceanRequired) > + parseFloat(await this.getOceanMaxBuyQuantity(poolAddress)) + ) { + return '0' + } return this.calcInGivenOut(poolAddress, dtAddress, this.oceanAddress, OceanRequired) } diff --git a/test/unit/balancer/Balancer.test.ts b/test/unit/balancer/Balancer.test.ts index 9a866de4..cf92e5ba 100644 --- a/test/unit/balancer/Balancer.test.ts +++ b/test/unit/balancer/Balancer.test.ts @@ -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')