Skip to content

Commit bc9c629

Browse files
author
Jeff Schroeder
committed
Add PythPriceAccount.min_accounts
1 parent 879054b commit bc9c629

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pythclient/pythaccounts.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ def __init__(self, key: SolanaPublicKey, solana: SolanaClient, *, product: Optio
477477
self.aggregate_price_info: Optional[PythPriceInfo] = None
478478
self.price_components: List[PythPriceComponent] = []
479479
self.derivations: Dict[TwEmaType, int] = {}
480+
self.min_publishers: Optional[int] = None
480481

481482
@property
482483
def aggregate_price(self) -> Optional[float]:
@@ -501,7 +502,8 @@ def update_from(self, buffer: bytes, *, version: int, offset: int = 0) -> None:
501502
unused (u32)
502503
currently accumulating price slot (u64)
503504
slot of current aggregate price (u64)
504-
derivations (u64[8] - array index corresponds to (DeriveType - 1) - v2 only)
505+
derivations (u64[6] - array index corresponds to (DeriveType - 1) - v2 only)
506+
unused derivation values and minimum publishers (u64[2], i32[2], )
505507
product account key (char[32])
506508
next price account key (char[32])
507509
account key of quoter who computed last aggregate price (char[32])
@@ -510,12 +512,15 @@ def update_from(self, buffer: bytes, *, version: int, offset: int = 0) -> None:
510512
"""
511513
if version == _VERSION_2:
512514
price_type, exponent, num_components = struct.unpack_from("<IiI", buffer, offset)
513-
offset += 16 # struct.calcsize("IiII") (last I unused)
515+
offset += 16 # struct.calcsize("IiII") (last I is the number of quoters that make up the aggregate)
514516
last_slot, valid_slot = struct.unpack_from("<QQ", buffer, offset)
515517
offset += 16 # QQ
516-
derivations = list(struct.unpack_from("<8q", buffer, offset))
518+
derivations = list(struct.unpack_from("<6q", buffer, offset))
517519
self.derivations = dict((type_, derivations[type_.value - 1]) for type_ in [TwEmaType.TWACVALUE, TwEmaType.TWAPVALUE])
518-
offset += 64 # 8q
520+
offset += 48 # 6q
521+
# All drv*_ fields sans min_publishers are currently unused
522+
_, min_publishers = struct.unpack_from("<qQ", buffer, offset)
523+
offset += 16 # <qQ
519524
product_account_key_bytes, next_price_account_key_bytes = struct.unpack_from("32s32s", buffer, offset)
520525
offset += 96 # 32s32s32s
521526
elif version == _VERSION_1:
@@ -552,6 +557,7 @@ def update_from(self, buffer: bytes, *, version: int, offset: int = 0) -> None:
552557
next_price_account_key_bytes)
553558
self.aggregate_price_info = aggregate_price_info
554559
self.price_components = price_components
560+
self.min_publishers = min_publishers
555561

556562
def __str__(self) -> str:
557563
if self.product:

0 commit comments

Comments
 (0)