diff --git a/program_admin/__init__.py b/program_admin/__init__.py index e7aa1fd..99cdb2d 100644 --- a/program_admin/__init__.py +++ b/program_admin/__init__.py @@ -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 ( @@ -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] @@ -76,7 +76,7 @@ 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 = "", ): @@ -84,9 +84,7 @@ def __init__( 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] = {} @@ -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 @@ -690,38 +688,36 @@ 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, @@ -729,7 +725,7 @@ async def sync_publisher_program( ) initialize_publisher_config_instruction = initialize_publisher_config( - self.publisher_program_key, + self.price_store_key, publisher, authority.public_key, buffer_account, diff --git a/program_admin/cli.py b/program_admin/cli.py index 344a56d..0431de0 100644 --- a/program_admin/cli.py +++ b/program_admin/cli.py @@ -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) @@ -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) @@ -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, ) @@ -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)) @@ -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") @@ -436,7 +436,7 @@ def sync( network, rpc_endpoint, program_key, - publisher_program_key, + price_store_key, keys, products, publishers, @@ -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, ) @@ -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) @@ -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, ) diff --git a/program_admin/publisher_program_instructions.py b/program_admin/price_store_instructions.py similarity index 95% rename from program_admin/publisher_program_instructions.py rename to program_admin/price_store_instructions.py index b37ad80..c1911a0 100644 --- a/program_admin/publisher_program_instructions.py +++ b/program_admin/price_store_instructions.py @@ -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 @@ -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) diff --git a/pyproject.toml b/pyproject.toml index dc43cfd..4b527e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ known_local_folder = ["program_admin"] authors = ["Thomaz "] 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" diff --git a/tests/test_sync.py b/tests/test_sync.py index 95641f1..67aa4bd 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -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", )