diff --git a/elfpy/eth/accounts/eth_account.py b/elfpy/eth/accounts/eth_account.py index 7dbff639ac..0dc92a5698 100644 --- a/elfpy/eth/accounts/eth_account.py +++ b/elfpy/eth/accounts/eth_account.py @@ -25,7 +25,7 @@ ) # TODO: should be able to infer this from the market -class EthAgent(LocalAccount, Generic[Policy, Market, MarketAction]): +class EthAgent(Generic[Policy, Market, MarketAction]): r"""Enact policies on smart contracts and tracks wallet state""" def __init__(self, policy: Policy | None = None, private_key: str | None = None): @@ -35,35 +35,35 @@ def __init__(self, policy: Policy | None = None, private_key: str | None = None) ---------- policy : Policy Elfpy policy for producing agent actions. - If None, then a policy that executes not actions is used. + If None, then a policy that executes no actions is used. private_key : str | None, optional Private key for constructing the agent's blockchain wallet. - If None, then a random private key is created + If None, then a random private key is created. """ if policy is None: self.policy = NoActionPolicy() else: self.policy = policy if private_key is None: - account: LocalAccount = Account().create() - private_key = account._key_obj # pylint: disable=protected-access + self.account: LocalAccount = Account().create() else: - account: LocalAccount = Account().from_key(private_key) - super().__init__(private_key, account) - self.wallet: EthWallet = EthWallet( - address=HexBytes(self.address), balance=Quantity(amount=self.policy.budget, unit=TokenType.BASE) + self.account: LocalAccount = Account().from_key(private_key) + self.wallet = EthWallet( + address=HexBytes(self.account.address), + balance=Quantity(amount=self.policy.budget, unit=TokenType.BASE), ) + super().__init__() @property def checksum_address(self) -> ChecksumAddress: """Return the checksum address of the account""" - return Web3.to_checksum_address(self.address) + return Web3.to_checksum_address(self.account.address) @property - def _private_key(self) -> str: + def _private_key(self) -> bytes: """Return the private key for the agent""" logging.warning("accessing agent private key") - return str(self._key_obj) # pylint: disable=protected-access + return bytes(self) @property def liquidation_trades(self) -> list[Trade[MarketAction]]: @@ -120,6 +120,10 @@ def liquidation_trades(self) -> list[Trade[MarketAction]]: ) return action_list + def sign_transaction(self, transaction_dict): + """Calls the underlying LocalAccount method""" + return self.account.sign_transaction(transaction_dict) + def get_trades(self, market: Market) -> list[Trade[MarketAction]]: """Helper function for computing a agent trade diff --git a/elfpy/eth/accounts/eth_wallet.py b/elfpy/eth/accounts/eth_wallet.py index 382965ba25..97f9e627de 100644 --- a/elfpy/eth/accounts/eth_wallet.py +++ b/elfpy/eth/accounts/eth_wallet.py @@ -21,8 +21,6 @@ class EthWallet: Arguments ---------- - address : HexBytes - The trader's address. balance : Quantity The base assets that held by the trader. lp_tokens : FixedPoint @@ -150,9 +148,9 @@ def update(self, wallet_deltas: WalletDeltas) -> None: if value_or_dict is None: continue match key: - case ["frozen", "no_new_attribs"]: + case "frozen" | "no_new_attribs" | "borrows": continue - case ["lp_tokens", "withdraw_shares"]: + case "lp_tokens" | "withdraw_shares": logging.debug( "agent #%g %s pre-trade = %.0g\npost-trade = %1g\ndelta = %1g", self.address, diff --git a/examples/eth_bots/eth_bots_config.py b/examples/eth_bots/eth_bots_config.py index 3eea07e0c4..bfd1af7ccb 100644 --- a/examples/eth_bots/eth_bots_config.py +++ b/examples/eth_bots/eth_bots_config.py @@ -35,7 +35,7 @@ def get_eth_bots_config() -> tuple[EnvironmentConfig, list[AgentConfig]]: username_register_url="http://localhost:5002", artifacts_url="http://localhost:8080", rpc_url="http://localhost:8545", - username="changeme", + username="changem3", ) agent_config: list[AgentConfig] = [ diff --git a/examples/eth_bots/get_agent_accounts.py b/examples/eth_bots/get_agent_accounts.py index 3ba2d03034..70c735847c 100644 --- a/examples/eth_bots/get_agent_accounts.py +++ b/examples/eth_bots/get_agent_accounts.py @@ -55,7 +55,7 @@ def get_agent_accounts( key_string = os.environ.get("AGENT_KEYS") if key_string is None: raise ValueError("AGENT_KEYS environment variable must be set") - agent_private_keys = json.loads(key_string) + agent_private_keys: list[str] = json.loads(key_string) # get agent budgets base_budget_string = os.environ.get("AGENT_BASE_BUDGETS") if base_budget_string is None: