Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arbitrary product metadata #54

Merged
merged 2 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PythConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class PythConnection {
data: productData,
},
}
if (productData.priceAccountKey.toString() !== ONES) {
if (productData.priceAccountKey) {
this.priceAccountKeyToProductAccountKey[productData.priceAccountKey.toString()] = key.toString()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Price.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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]
Expand Down