Skip to content

Commit

Permalink
refactor: rename publisher program to price store
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-bahjati committed Sep 12, 2024
1 parent a8aaa3a commit bf9300c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 45 deletions.
54 changes: 25 additions & 29 deletions program_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
from program_admin import instructions as pyth_program
from program_admin.keys import load_keypair
from program_admin.parsing import parse_account
from program_admin.publisher_program_instructions import (
config_account_pubkey as publisher_program_config_account_pubkey,
from program_admin.price_store_instructions import (
config_account_pubkey as price_store_config_account_pubkey,
)
from program_admin.publisher_program_instructions import (
from program_admin.price_store_instructions import (
create_buffer_account,
initialize_price_store,
initialize_publisher_config,
initialize_publisher_program,
publisher_config_account_pubkey,
)
from program_admin.types import (
Expand Down Expand Up @@ -65,7 +65,7 @@ class ProgramAdmin:
rpc_endpoint: str
key_dir: Path
program_key: PublicKey
publisher_program_key: Optional[PublicKey]
price_store_key: Optional[PublicKey]
authority_permission_account: Optional[PythAuthorityPermissionAccount]
_mapping_accounts: Dict[PublicKey, PythMappingAccount]
_product_accounts: Dict[PublicKey, PythProductAccount]
Expand All @@ -76,17 +76,15 @@ def __init__(
network: Network,
key_dir: str,
program_key: str,
publisher_program_key: Optional[str],
price_store_key: Optional[str],
commitment: Literal["confirmed", "finalized"],
rpc_endpoint: str = "",
):
self.network = network
self.rpc_endpoint = rpc_endpoint or RPC_ENDPOINTS[network]
self.key_dir = Path(key_dir)
self.program_key = PublicKey(program_key)
self.publisher_program_key = (
PublicKey(publisher_program_key) if publisher_program_key else None
)
self.price_store_key = PublicKey(price_store_key) if price_store_key else None
self.commitment = Commitment(commitment)
self.authority_permission_account = None
self._mapping_accounts: Dict[PublicKey, PythMappingAccount] = {}
Expand Down Expand Up @@ -317,19 +315,19 @@ async def sync(

# Sync publisher program
(
publisher_program_instructions,
publisher_program_signers,
) = await self.sync_publisher_program(ref_publishers)
price_store_instructions,
price_store_signers,
) = await self.sync_price_store(ref_publishers)

logger.debug(
f"Syncing publisher program - {len(publisher_program_instructions)} instructions"
f"Syncing price store program - {len(price_store_instructions)} instructions"
)

if publisher_program_instructions:
instructions.extend(publisher_program_instructions)
if price_store_instructions:
instructions.extend(price_store_instructions)
if send_transactions:
await self.send_transaction(
publisher_program_instructions, publisher_program_signers
price_store_instructions, price_store_signers
)

# Sync publishers
Expand Down Expand Up @@ -690,46 +688,44 @@ async def resize_price_accounts_v2(
if send_transactions:
await self.send_transaction(instructions, signers)

async def sync_publisher_program(
async def sync_price_store(
self, ref_publishers: ReferencePublishers
) -> Tuple[List[TransactionInstruction], List[Keypair]]:
if self.publisher_program_key is None:
if self.price_store_key is None:
return [], []

instructions = []

authority = load_keypair("funding", key_dir=self.key_dir)

publisher_program_config = publisher_program_config_account_pubkey(
self.publisher_program_key
)
price_store_config = price_store_config_account_pubkey(self.price_store_key)

# Initialize the publisher program config if it does not exist
if not (await account_exists(self.rpc_endpoint, publisher_program_config)):
initialize_publisher_program_instruction = initialize_publisher_program(
self.publisher_program_key, authority.public_key
# Initialize the price store program config if it does not exist
if not (await account_exists(self.rpc_endpoint, price_store_config)):
initialize_price_store_instruction = initialize_price_store(
self.price_store_key, authority.public_key
)
instructions.append(initialize_publisher_program_instruction)
instructions.append(initialize_price_store_instruction)

# Initialize publisher config accounts for new publishers
for publisher in ref_publishers["keys"].values():
publisher_config_account = publisher_config_account_pubkey(
publisher, self.publisher_program_key
publisher, self.price_store_key
)

if not (await account_exists(self.rpc_endpoint, publisher_config_account)):
size = 100048 # This size is for a buffer supporting 5000 price updates
lamports = await self.fetch_minimum_balance(size)
buffer_account, create_buffer_instruction = create_buffer_account(
self.publisher_program_key,
self.price_store_key,
authority.public_key,
publisher,
size,
lamports,
)

initialize_publisher_config_instruction = initialize_publisher_config(
self.publisher_program_key,
self.price_store_key,
publisher,
authority.public_key,
buffer_account,
Expand Down
22 changes: 11 additions & 11 deletions program_admin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def delete_price(network, rpc_endpoint, program_key, keys, commitment, product,
rpc_endpoint=rpc_endpoint,
key_dir=keys,
program_key=program_key,
publisher_program_key=None,
price_store_key=None,
commitment=commitment,
)
funding_keypair = load_keypair("funding", key_dir=keys)
Expand Down Expand Up @@ -237,7 +237,7 @@ def delete_product(
rpc_endpoint=rpc_endpoint,
key_dir=keys,
program_key=program_key,
publisher_program_key=None,
price_store_key=None,
commitment=commitment,
)
funding_keypair = load_keypair("funding", key_dir=keys)
Expand Down Expand Up @@ -277,7 +277,7 @@ def list_accounts(network, rpc_endpoint, program_key, keys, publishers, commitme
rpc_endpoint=rpc_endpoint,
key_dir=keys,
program_key=program_key,
publisher_program_key=None,
price_store_key=None,
commitment=commitment,
)

Expand Down Expand Up @@ -336,7 +336,7 @@ def restore_links(network, rpc_endpoint, program_key, keys, products, commitment
rpc_endpoint=rpc_endpoint,
key_dir=keys,
program_key=program_key,
publisher_program_key=None,
price_store_key=None,
commitment=commitment,
)
reference_products = parse_products_json(Path(products))
Expand Down Expand Up @@ -387,9 +387,9 @@ def restore_links(network, rpc_endpoint, program_key, keys, products, commitment
@click.option("--rpc-endpoint", help="Solana RPC endpoint", envvar="RPC_ENDPOINT")
@click.option("--program-key", help="Pyth program key", envvar="PROGRAM_KEY")
@click.option(
"--publisher-program-key",
help="Publisher program key",
envvar="PUBLISHER_PROGRAM_KEY",
"--price-store-key",
help="Pyth price store program key",
envvar="PRICE_STORE_KEY",
default=None,
)
@click.option("--keys", help="Path to keys directory", envvar="KEYS")
Expand Down Expand Up @@ -436,7 +436,7 @@ def sync(
network,
rpc_endpoint,
program_key,
publisher_program_key,
price_store_key,
keys,
products,
publishers,
Expand All @@ -453,7 +453,7 @@ def sync(
rpc_endpoint=rpc_endpoint,
key_dir=keys,
program_key=program_key,
publisher_program_key=publisher_program_key,
price_store_key=price_store_key,
commitment=commitment,
)

Expand Down Expand Up @@ -507,7 +507,7 @@ def migrate_upgrade_authority(
rpc_endpoint=rpc_endpoint,
key_dir=keys,
program_key=program_key,
publisher_program_key=None,
price_store_key=None,
commitment=commitment,
)
funding_keypair = load_keypair("funding", key_dir=keys)
Expand Down Expand Up @@ -557,7 +557,7 @@ def resize_price_accounts_v2(
rpc_endpoint=rpc_endpoint,
key_dir=keys,
program_key=program_key,
publisher_program_key=None,
price_store_key=None,
commitment=commitment,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def publisher_config_account_pubkey(
return publisher_config_account


def initialize_publisher_program(
def initialize_price_store(
program_key: PublicKey,
authority: PublicKey,
) -> TransactionInstruction:
"""
Pyth publisher program initialize instruction with the given authority
Pyth price store program initialize instruction with the given authority
accounts:
- payer account (signer, writable) - we pass the authority as the payer
Expand Down Expand Up @@ -113,7 +113,7 @@ def initialize_publisher_config(
buffer_account: PublicKey,
) -> TransactionInstruction:
"""
Pyth publisher program initialize publisher config instruction with the given authority
Pyth price store program initialize publisher config instruction with the given authority
accounts:
- authority account (signer, writable)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ known_local_folder = ["program_admin"]
authors = ["Thomaz <[email protected]>"]
description = "Syncs products and publishers of the Pyth program"
name = "program-admin"
version = "0.1.4"
version = "0.1.5"

[tool.poetry.dependencies]
click = "^8.1.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ async def test_sync(
network=network,
key_dir=key_dir,
program_key=pyth_program,
publisher_program_key=None,
price_store_key=None,
commitment="confirmed",
)

Expand Down

0 comments on commit bf9300c

Please sign in to comment.