Skip to content

Commit

Permalink
feat(keystore_and_bump): Fixed things
Browse files Browse the repository at this point in the history
  • Loading branch information
akhercha committed Jul 23, 2024
1 parent eaaf1ca commit 470826a
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 37 deletions.
13 changes: 7 additions & 6 deletions checkpointer/checkpointer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging

from pydantic import HttpUrl
from typing import Optional, Literal
from typing import Optional, Literal, Tuple

from pragma_utils.logger import setup_logging
from pragma_utils.cli import load_private_key_from_cli_arg
Expand All @@ -22,15 +22,15 @@ async def main(
network: Literal["mainnet", "sepolia"],
oracle_address: str,
admin_address: str,
private_key: str,
private_key: str | Tuple[str, str],
set_checkpoint_interval: int,
rpc_url: Optional[HttpUrl] = None,
) -> None:
pragma_client = PragmaOnChainClient(
chain_name=network,
network=network if rpc_url is None else rpc_url,
account_contract_address=int(admin_address, 16),
account_private_key=int(private_key, 16),
account_contract_address=admin_address,
account_private_key=private_key,
contract_addresses_config=ContractAddresses(
publisher_registry_address=0x0,
oracle_proxy_addresss=int(oracle_address, 16),
Expand Down Expand Up @@ -133,6 +133,7 @@ def _log_handled_pairs(pairs_config: PairsConfig, set_checkpoint_interval: int)
@click.option(
"-p",
"--private-key",
"raw_private_key",
type=click.STRING,
required=True,
help=(
Expand All @@ -158,14 +159,14 @@ def cli_entrypoint(
rpc_url: Optional[HttpUrl],
oracle_address: str,
admin_address: str,
private_key: str,
raw_private_key: str,
set_checkpoint_interval: int,
) -> None:
"""
Checkpointer entry point.
"""
setup_logging(logger, log_level)
private_key = load_private_key_from_cli_arg(private_key)
private_key = load_private_key_from_cli_arg(raw_private_key)
pairs_config = PairsConfig.from_yaml(config_file)
asyncio.run(
main(
Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/types/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import StrEnum, unique
from typing import Dict

Address = int
Address = int | str
HexStr = str
Decimals = int
UnixTimestamp = int
Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/onchain/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pragma_sdk.onchain.types.contract import Contract
from pragma_sdk.onchain.types.execution_config import ExecutionConfig

from pragma_sdk.onchain.types.types import (
ContractAddresses,
ExecutionConfig,
BlockNumber,
BlockId,
Network,
Expand Down
19 changes: 19 additions & 0 deletions pragma-sdk/pragma_sdk/onchain/types/execution_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from typing import Optional
from dataclasses import dataclass

from pydantic import model_validator
from starknet_py.net.client_models import ResourceBounds


@dataclass(frozen=True)
class ExecutionConfig:
pagination: int = 40
max_fee: int = int(1e18)
enable_strk_fees: bool = False
l1_resource_bounds: Optional[ResourceBounds] = None
auto_estimate: bool = False

@model_validator(mode="after") # type: ignore[misc]
def post_root(self) -> None:
if self.auto_estimate == (self.l1_resource_bounds is not None):
raise ValueError("Either auto_estimate or l1_resource_bounds must be set")
17 changes: 1 addition & 16 deletions pragma-sdk/pragma_sdk/onchain/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from enum import StrEnum, unique
from collections import namedtuple

from pydantic import HttpUrl, model_validator
from starknet_py.net.client_models import ResourceBounds
from pydantic import HttpUrl
from starknet_py.net.client import Tag as BlockTag
from starknet_py.contract import InvokeResult

Expand Down Expand Up @@ -40,20 +39,6 @@
BlockId = Union[BlockTag, BlockNumber]


@dataclass(frozen=True)
class ExecutionConfig:
pagination: int = 40
max_fee: int = int(1e18)
enable_strk_fees: bool = False
l1_resource_bounds: Optional[ResourceBounds] = None
auto_estimate: bool = False

@model_validator(mode="after") # type: ignore[misc]
def post_root(self) -> None:
if self.auto_estimate == (self.l1_resource_bounds is not None):
raise ValueError("Either auto_estimate or l1_resource_bounds must be set")


@unique
class RequestStatus(StrEnum):
UNINITIALIZED = "UNINITIALIZED"
Expand Down
7 changes: 5 additions & 2 deletions pragma-utils/pragma_utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pragma_utils.aws import fetch_aws_private_key


def load_private_key_from_cli_arg(private_key: str) -> Union[str, Tuple[str, str]]:
"""
Load the private key either from AWS, environment variable, from the provided plain value, or return keystore info.
Expand All @@ -12,7 +13,7 @@ def load_private_key_from_cli_arg(private_key: str) -> Union[str, Tuple[str, str
private_key: The private key string, prefixed with 'aws:', 'plain:', 'env:', or 'keystore:'.
Returns:
Union[str, Tuple[str, str]]:
Union[str, Tuple[str, str]]:
- For 'aws:', 'plain:', 'env:': returns the loaded private key as a string.
- For 'keystore:': returns a tuple of (path, password).
Expand All @@ -35,4 +36,6 @@ def load_private_key_from_cli_arg(private_key: str) -> Union[str, Tuple[str, str
except ValueError:
raise ValueError("Keystore format should be 'keystore:PATH:PASSWORD'")
else:
raise ValueError("Private key must be prefixed with either 'aws:', 'plain:', 'env:', or 'keystore:'")
raise ValueError(
"Private key must be prefixed with either 'aws:', 'plain:', 'env:', or 'keystore:'"
)
11 changes: 6 additions & 5 deletions price-pusher/price_pusher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import click
import logging

from typing import Optional, List
from typing import Optional, List, Tuple

from pragma_sdk.common.fetchers.fetcher_client import FetcherClient
from pragma_sdk.common.types.client import PragmaClient
Expand Down Expand Up @@ -32,7 +32,7 @@ async def main(
price_configs: List[PriceConfig],
target: Target,
network: Network,
private_key: str,
private_key: str | Tuple[str, str],
publisher_name: str,
publisher_address: str,
rpc_url: Optional[str] = None,
Expand Down Expand Up @@ -104,7 +104,7 @@ def _create_client(
target: Target,
network: Network,
publisher_address: str,
private_key: str,
private_key: str | Tuple[str, str],
rpc_url: Optional[str] = None,
api_base_url: Optional[str] = None,
api_key: Optional[str] = None,
Expand Down Expand Up @@ -194,6 +194,7 @@ def _create_client(
@click.option(
"-p",
"--private-key",
"raw_private_key",
type=click.STRING,
required=True,
help=(
Expand Down Expand Up @@ -247,7 +248,7 @@ def cli_entrypoint(
target: str,
network: str,
rpc_url: Optional[str],
private_key: str,
raw_private_key: str,
publisher_name: str,
publisher_address: str,
api_base_url: Optional[str],
Expand Down Expand Up @@ -287,7 +288,7 @@ def cli_entrypoint(
sdk_logger.setLevel(log_level)

setup_logging(logger, log_level)
private_key = load_private_key_from_cli_arg(private_key)
private_key = load_private_key_from_cli_arg(raw_private_key)
price_configs: List[PriceConfig] = PriceConfig.from_yaml(config_file)

# Make sure that the API base url does not ends with /
Expand Down
14 changes: 8 additions & 6 deletions vrf-listener/vrf_listener/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ async def main(
client = PragmaOnChainClient(
chain_name=network,
network=network if rpc_url is None else rpc_url,
account_contract_address=int(admin_address, 16),
account_private_key=int(private_key, 16),
account_contract_address=admin_address,
account_private_key=private_key,
contract_addresses_config=ContractAddresses(
publisher_registry_address=0x0,
oracle_proxy_addresss=int(oracle_address, 16),
Expand Down Expand Up @@ -89,14 +89,14 @@ async def main(
@click.option(
"-p",
"--private-key",
"raw_private_key",
type=click.STRING,
required=True,
help=(
"Private key of the signer. Format: "
"aws:secret_name, "
"plain:private_key, "
"env:ENV_VAR_NAME, "
"or keystore:PATH/TO/THE/KEYSTORE:PASSWORD"
"or env:ENV_VAR_NAME"
),
)
@click.option(
Expand All @@ -122,15 +122,17 @@ def cli_entrypoint(
oracle_address: str,
vrf_address: str,
admin_address: str,
private_key: str,
raw_private_key: str,
start_block: int,
check_requests_interval: int,
) -> None:
"""
VRF Listener entry point.
"""
setup_logging(logger, log_level)
private_key = load_private_key_from_cli_arg(private_key)
private_key = load_private_key_from_cli_arg(raw_private_key)
if isinstance(private_key, tuple):
raise ValueError("⛔ KeyStores aren't supported as private key for the vrf-listener!")
asyncio.run(
main(
network=network,
Expand Down

0 comments on commit 470826a

Please sign in to comment.