diff --git a/src/PythConnection.ts b/src/PythConnection.ts index e1dba03..4812dfd 100644 --- a/src/PythConnection.ts +++ b/src/PythConnection.ts @@ -46,7 +46,7 @@ export class PythConnection { data: productData, }, } - if (productData.priceAccountKey.toString() !== ONES) { + if (productData.priceAccountKey) { this.priceAccountKeyToProductAccountKey[productData.priceAccountKey.toString()] = key.toString() } } diff --git a/src/__tests__/Example.test.ts b/src/__tests__/Example.test.ts index cf784af..ca9803e 100644 --- a/src/__tests__/Example.test.ts +++ b/src/__tests__/Example.test.ts @@ -20,7 +20,7 @@ test('Mapping', (done) => { return } const { product, priceAccountKey } = parseProductData(accountInfo.data) - connection.getAccountInfo(priceAccountKey).then((accountInfo) => { + connection.getAccountInfo(priceAccountKey!).then((accountInfo) => { if (!accountInfo) { done('No price accountInfo') return diff --git a/src/__tests__/Price.test.ts b/src/__tests__/Price.test.ts index ab3b8a6..ac44103 100644 --- a/src/__tests__/Price.test.ts +++ b/src/__tests__/Price.test.ts @@ -23,7 +23,7 @@ test('Price', (done) => { connection.getAccountInfo(mapping.productAccountKeys[0]).then((accountInfo) => { if (accountInfo && accountInfo.data) { const product = parseProductData(accountInfo.data) - connection.getAccountInfo(product.priceAccountKey).then((accountInfo) => { + connection.getAccountInfo(product.priceAccountKey!).then((accountInfo) => { if (accountInfo && accountInfo.data) { const price = parsePriceData(accountInfo.data) console.log(product.product.symbol) diff --git a/src/index.ts b/src/index.ts index 2bfbb28..05883c4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,16 +56,11 @@ export interface MappingData extends Base { } export interface Product { - symbol: string - asset_type: string - quote_currency: string - tenor: string - price_account: string [index: string]: string } export interface ProductData extends Base { - priceAccountKey: PublicKey + priceAccountKey: PublicKey | null product: Product } @@ -203,9 +198,9 @@ export const parseProductData = (data: Buffer): ProductData => { const size = data.readUInt32LE(12) // first price account in list const priceAccountBytes = data.slice(16, 48) - const priceAccountKey = new PublicKey(priceAccountBytes) + const priceAccountKey = PKorNull(priceAccountBytes) const product = {} as Product - product.price_account = priceAccountKey.toBase58() + if (priceAccountKey) product.price_account = priceAccountKey.toBase58() let idx = 48 while (idx < size) { const keyLength = data[idx]