From a7ee8fb2c001275b15dec0ab978a73e3e9253023 Mon Sep 17 00:00:00 2001 From: riordanp Date: Thu, 16 Mar 2023 09:10:52 +0000 Subject: [PATCH] Fix null checks on getters for PerpMarket and Bank (#505) * Export OracleProvider * Fix null checks on getters --- ts/client/src/accounts/bank.ts | 8 ++++---- ts/client/src/accounts/perp.ts | 8 ++++---- ts/client/src/index.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ts/client/src/accounts/bank.ts b/ts/client/src/accounts/bank.ts index 9dd09ec8b..bd0029996 100644 --- a/ts/client/src/accounts/bank.ts +++ b/ts/client/src/accounts/bank.ts @@ -337,7 +337,7 @@ export class Bank implements BankForHealth { } get price(): I80F48 { - if (!this._price) { + if (this._price === undefined) { throw new Error( `Undefined price for bank ${this.publicKey} with tokenIndex ${this.tokenIndex}!`, ); @@ -346,7 +346,7 @@ export class Bank implements BankForHealth { } get uiPrice(): number { - if (!this._uiPrice) { + if (this._uiPrice === undefined) { throw new Error( `Undefined uiPrice for bank ${this.publicKey} with tokenIndex ${this.tokenIndex}!`, ); @@ -355,7 +355,7 @@ export class Bank implements BankForHealth { } get oracleLastUpdatedSlot(): number { - if (!this._oracleLastUpdatedSlot) { + if (this._oracleLastUpdatedSlot === undefined) { throw new Error( `Undefined oracleLastUpdatedSlot for bank ${this.publicKey} with tokenIndex ${this.tokenIndex}!`, ); @@ -364,7 +364,7 @@ export class Bank implements BankForHealth { } get oracleProvider(): OracleProvider { - if (!this._oracleProvider) { + if (this._oracleProvider === undefined) { throw new Error( `Undefined oracleProvider for bank ${this.publicKey} with tokenIndex ${this.tokenIndex}!`, ); diff --git a/ts/client/src/accounts/perp.ts b/ts/client/src/accounts/perp.ts index a0aec6891..fee65b3c0 100644 --- a/ts/client/src/accounts/perp.ts +++ b/ts/client/src/accounts/perp.ts @@ -242,7 +242,7 @@ export class PerpMarket { } get price(): I80F48 { - if (!this._price) { + if (this._price === undefined) { throw new Error( `Undefined price for perpMarket ${this.publicKey} with marketIndex ${this.perpMarketIndex}!`, ); @@ -251,7 +251,7 @@ export class PerpMarket { } get uiPrice(): number { - if (!this._uiPrice) { + if (this._uiPrice === undefined) { throw new Error( `Undefined price for perpMarket ${this.publicKey} with marketIndex ${this.perpMarketIndex}!`, ); @@ -260,7 +260,7 @@ export class PerpMarket { } get oracleLastUpdatedSlot(): number { - if (!this._oracleLastUpdatedSlot) { + if (this._oracleLastUpdatedSlot === undefined) { throw new Error( `Undefined oracleLastUpdatedSlot for perpMarket ${this.publicKey} with marketIndex ${this.perpMarketIndex}!`, ); @@ -269,7 +269,7 @@ export class PerpMarket { } get oracleProvider(): OracleProvider { - if (!this._oracleProvider) { + if (this._oracleProvider === undefined) { throw new Error( `Undefined oracleProvider for perpMarket ${this.publicKey} with marketIndex ${this.perpMarketIndex}!`, ); diff --git a/ts/client/src/index.ts b/ts/client/src/index.ts index e3576f6f1..5b8994b84 100644 --- a/ts/client/src/index.ts +++ b/ts/client/src/index.ts @@ -1,5 +1,5 @@ import { Group } from './accounts/group'; -import { StubOracle } from './accounts/oracle'; +import { OracleProvider, StubOracle } from './accounts/oracle'; import { MangoClient } from './client'; import { MANGO_V4_ID } from './constants'; @@ -22,4 +22,4 @@ export * from './constants'; export * from './numbers/I80F48'; export * from './utils'; export * from './types'; -export { Group, StubOracle, MangoClient, MANGO_V4_ID }; +export { Group, OracleProvider, StubOracle, MangoClient, MANGO_V4_ID };