Skip to content

Commit 29e5861

Browse files
committed
fix: checks in oracle usd conversions for zero amount
1 parent d682b81 commit 29e5861

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/sdk/market/oracle/PriceOracleBaseContract.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ export abstract class PriceOracleBaseContract<
176176
* @param reserve use reserve price feed instead of main
177177
*/
178178
public convertToUSD(from: Address, amount: bigint, reserve = false): bigint {
179+
if (amount === 0n) {
180+
return 0n;
181+
}
179182
const price = reserve ? this.reservePrice(from) : this.mainPrice(from);
180183
const scale = 10n ** BigInt(this.tokensMeta.decimals(from));
181184
return (amount * price) / scale;
@@ -188,6 +191,9 @@ export abstract class PriceOracleBaseContract<
188191
* @param reserve use reserve price feed instead of main
189192
*/
190193
public convertFromUSD(to: Address, amount: bigint, reserve = false): bigint {
194+
if (amount === 0n) {
195+
return 0n;
196+
}
191197
const price = reserve ? this.reservePrice(to) : this.mainPrice(to);
192198
const scale = 10n ** BigInt(this.tokensMeta.decimals(to));
193199
return (amount * scale) / price;

0 commit comments

Comments
 (0)