Skip to content

Commit b941e7c

Browse files
authored
fix and rename publisher program instructions (#46)
* fix: correct the instruction account metadata for pub init * refactor: rename publisher program to price store
1 parent 15e39c3 commit b941e7c

File tree

5 files changed

+43
-47
lines changed

5 files changed

+43
-47
lines changed

program_admin/__init__.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
from program_admin import instructions as pyth_program
1717
from program_admin.keys import load_keypair
1818
from program_admin.parsing import parse_account
19-
from program_admin.publisher_program_instructions import (
20-
config_account_pubkey as publisher_program_config_account_pubkey,
19+
from program_admin.price_store_instructions import (
20+
config_account_pubkey as price_store_config_account_pubkey,
2121
)
22-
from program_admin.publisher_program_instructions import (
22+
from program_admin.price_store_instructions import (
2323
create_buffer_account,
24+
initialize_price_store,
2425
initialize_publisher_config,
25-
initialize_publisher_program,
2626
publisher_config_account_pubkey,
2727
)
2828
from program_admin.types import (
@@ -65,7 +65,7 @@ class ProgramAdmin:
6565
rpc_endpoint: str
6666
key_dir: Path
6767
program_key: PublicKey
68-
publisher_program_key: Optional[PublicKey]
68+
price_store_key: Optional[PublicKey]
6969
authority_permission_account: Optional[PythAuthorityPermissionAccount]
7070
_mapping_accounts: Dict[PublicKey, PythMappingAccount]
7171
_product_accounts: Dict[PublicKey, PythProductAccount]
@@ -76,17 +76,15 @@ def __init__(
7676
network: Network,
7777
key_dir: str,
7878
program_key: str,
79-
publisher_program_key: Optional[str],
79+
price_store_key: Optional[str],
8080
commitment: Literal["confirmed", "finalized"],
8181
rpc_endpoint: str = "",
8282
):
8383
self.network = network
8484
self.rpc_endpoint = rpc_endpoint or RPC_ENDPOINTS[network]
8585
self.key_dir = Path(key_dir)
8686
self.program_key = PublicKey(program_key)
87-
self.publisher_program_key = (
88-
PublicKey(publisher_program_key) if publisher_program_key else None
89-
)
87+
self.price_store_key = PublicKey(price_store_key) if price_store_key else None
9088
self.commitment = Commitment(commitment)
9189
self.authority_permission_account = None
9290
self._mapping_accounts: Dict[PublicKey, PythMappingAccount] = {}
@@ -317,19 +315,19 @@ async def sync(
317315

318316
# Sync publisher program
319317
(
320-
publisher_program_instructions,
321-
publisher_program_signers,
322-
) = await self.sync_publisher_program(ref_publishers)
318+
price_store_instructions,
319+
price_store_signers,
320+
) = await self.sync_price_store(ref_publishers)
323321

324322
logger.debug(
325-
f"Syncing publisher program - {len(publisher_program_instructions)} instructions"
323+
f"Syncing price store program - {len(price_store_instructions)} instructions"
326324
)
327325

328-
if publisher_program_instructions:
329-
instructions.extend(publisher_program_instructions)
326+
if price_store_instructions:
327+
instructions.extend(price_store_instructions)
330328
if send_transactions:
331329
await self.send_transaction(
332-
publisher_program_instructions, publisher_program_signers
330+
price_store_instructions, price_store_signers
333331
)
334332

335333
# Sync publishers
@@ -690,46 +688,44 @@ async def resize_price_accounts_v2(
690688
if send_transactions:
691689
await self.send_transaction(instructions, signers)
692690

693-
async def sync_publisher_program(
691+
async def sync_price_store(
694692
self, ref_publishers: ReferencePublishers
695693
) -> Tuple[List[TransactionInstruction], List[Keypair]]:
696-
if self.publisher_program_key is None:
694+
if self.price_store_key is None:
697695
return [], []
698696

699697
instructions = []
700698

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

703-
publisher_program_config = publisher_program_config_account_pubkey(
704-
self.publisher_program_key
705-
)
701+
price_store_config = price_store_config_account_pubkey(self.price_store_key)
706702

707-
# Initialize the publisher program config if it does not exist
708-
if not (await account_exists(self.rpc_endpoint, publisher_program_config)):
709-
initialize_publisher_program_instruction = initialize_publisher_program(
710-
self.publisher_program_key, authority.public_key
703+
# Initialize the price store program config if it does not exist
704+
if not (await account_exists(self.rpc_endpoint, price_store_config)):
705+
initialize_price_store_instruction = initialize_price_store(
706+
self.price_store_key, authority.public_key
711707
)
712-
instructions.append(initialize_publisher_program_instruction)
708+
instructions.append(initialize_price_store_instruction)
713709

714710
# Initialize publisher config accounts for new publishers
715711
for publisher in ref_publishers["keys"].values():
716712
publisher_config_account = publisher_config_account_pubkey(
717-
publisher, self.publisher_program_key
713+
publisher, self.price_store_key
718714
)
719715

720716
if not (await account_exists(self.rpc_endpoint, publisher_config_account)):
721717
size = 100048 # This size is for a buffer supporting 5000 price updates
722718
lamports = await self.fetch_minimum_balance(size)
723719
buffer_account, create_buffer_instruction = create_buffer_account(
724-
self.publisher_program_key,
720+
self.price_store_key,
725721
authority.public_key,
726722
publisher,
727723
size,
728724
lamports,
729725
)
730726

731727
initialize_publisher_config_instruction = initialize_publisher_config(
732-
self.publisher_program_key,
728+
self.price_store_key,
733729
publisher,
734730
authority.public_key,
735731
buffer_account,

program_admin/cli.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def delete_price(network, rpc_endpoint, program_key, keys, commitment, product,
5656
rpc_endpoint=rpc_endpoint,
5757
key_dir=keys,
5858
program_key=program_key,
59-
publisher_program_key=None,
59+
price_store_key=None,
6060
commitment=commitment,
6161
)
6262
funding_keypair = load_keypair("funding", key_dir=keys)
@@ -237,7 +237,7 @@ def delete_product(
237237
rpc_endpoint=rpc_endpoint,
238238
key_dir=keys,
239239
program_key=program_key,
240-
publisher_program_key=None,
240+
price_store_key=None,
241241
commitment=commitment,
242242
)
243243
funding_keypair = load_keypair("funding", key_dir=keys)
@@ -277,7 +277,7 @@ def list_accounts(network, rpc_endpoint, program_key, keys, publishers, commitme
277277
rpc_endpoint=rpc_endpoint,
278278
key_dir=keys,
279279
program_key=program_key,
280-
publisher_program_key=None,
280+
price_store_key=None,
281281
commitment=commitment,
282282
)
283283

@@ -336,7 +336,7 @@ def restore_links(network, rpc_endpoint, program_key, keys, products, commitment
336336
rpc_endpoint=rpc_endpoint,
337337
key_dir=keys,
338338
program_key=program_key,
339-
publisher_program_key=None,
339+
price_store_key=None,
340340
commitment=commitment,
341341
)
342342
reference_products = parse_products_json(Path(products))
@@ -387,9 +387,9 @@ def restore_links(network, rpc_endpoint, program_key, keys, products, commitment
387387
@click.option("--rpc-endpoint", help="Solana RPC endpoint", envvar="RPC_ENDPOINT")
388388
@click.option("--program-key", help="Pyth program key", envvar="PROGRAM_KEY")
389389
@click.option(
390-
"--publisher-program-key",
391-
help="Publisher program key",
392-
envvar="PUBLISHER_PROGRAM_KEY",
390+
"--price-store-key",
391+
help="Pyth price store program key",
392+
envvar="PRICE_STORE_KEY",
393393
default=None,
394394
)
395395
@click.option("--keys", help="Path to keys directory", envvar="KEYS")
@@ -436,7 +436,7 @@ def sync(
436436
network,
437437
rpc_endpoint,
438438
program_key,
439-
publisher_program_key,
439+
price_store_key,
440440
keys,
441441
products,
442442
publishers,
@@ -453,7 +453,7 @@ def sync(
453453
rpc_endpoint=rpc_endpoint,
454454
key_dir=keys,
455455
program_key=program_key,
456-
publisher_program_key=publisher_program_key,
456+
price_store_key=price_store_key,
457457
commitment=commitment,
458458
)
459459

@@ -507,7 +507,7 @@ def migrate_upgrade_authority(
507507
rpc_endpoint=rpc_endpoint,
508508
key_dir=keys,
509509
program_key=program_key,
510-
publisher_program_key=None,
510+
price_store_key=None,
511511
commitment=commitment,
512512
)
513513
funding_keypair = load_keypair("funding", key_dir=keys)
@@ -557,7 +557,7 @@ def resize_price_accounts_v2(
557557
rpc_endpoint=rpc_endpoint,
558558
key_dir=keys,
559559
program_key=program_key,
560-
publisher_program_key=None,
560+
price_store_key=None,
561561
commitment=commitment,
562562
)
563563

program_admin/publisher_program_instructions.py renamed to program_admin/price_store_instructions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def publisher_config_account_pubkey(
2525
return publisher_config_account
2626

2727

28-
def initialize_publisher_program(
28+
def initialize_price_store(
2929
program_key: PublicKey,
3030
authority: PublicKey,
3131
) -> TransactionInstruction:
3232
"""
33-
Pyth publisher program initialize instruction with the given authority
33+
Pyth price store program initialize instruction with the given authority
3434
3535
accounts:
3636
- payer account (signer, writable) - we pass the authority as the payer
@@ -113,7 +113,7 @@ def initialize_publisher_config(
113113
buffer_account: PublicKey,
114114
) -> TransactionInstruction:
115115
"""
116-
Pyth publisher program initialize publisher config instruction with the given authority
116+
Pyth price store program initialize publisher config instruction with the given authority
117117
118118
accounts:
119119
- authority account (signer, writable)
@@ -153,9 +153,9 @@ def initialize_publisher_config(
153153
data=ix_data,
154154
keys=[
155155
AccountMeta(pubkey=authority, is_signer=True, is_writable=True),
156-
AccountMeta(pubkey=config_account, is_signer=False, is_writable=True),
156+
AccountMeta(pubkey=config_account, is_signer=False, is_writable=False),
157157
AccountMeta(
158-
pubkey=publisher_config_account, is_signer=False, is_writable=False
158+
pubkey=publisher_config_account, is_signer=False, is_writable=True
159159
),
160160
AccountMeta(pubkey=buffer_account, is_signer=False, is_writable=True),
161161
AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False),

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ known_local_folder = ["program_admin"]
99
authors = ["Thomaz <[email protected]>"]
1010
description = "Syncs products and publishers of the Pyth program"
1111
name = "program-admin"
12-
version = "0.1.4"
12+
version = "0.1.5"
1313

1414
[tool.poetry.dependencies]
1515
click = "^8.1.0"

tests/test_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ async def test_sync(
421421
network=network,
422422
key_dir=key_dir,
423423
program_key=pyth_program,
424-
publisher_program_key=None,
424+
price_store_key=None,
425425
commitment="confirmed",
426426
)
427427

0 commit comments

Comments
 (0)