Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing agent name in agent object #1596

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/agent0/chainsync/dashboard/usernames.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,32 @@ def map_addresses(key: pd.Series | list | str, user_map: pd.DataFrame, map_colum
return out


def abbreviate_address(addresses: pd.Series) -> pd.Series:
# TODO move this function somewhere else, as agent0's agent also uses this function.
@overload
def abbreviate_address(address: pd.Series) -> pd.Series: ...


@overload
def abbreviate_address(address: str) -> str: ...


def abbreviate_address(address: pd.Series | str) -> pd.Series | str:
"""Given a series of addresses, return the corresponding addresses in a human readable way.

Arguments
---------
addresses: pd.Series
address: pd.Series | str

Returns
-------
pd.Series
The corresponding abbreviated addresses in the same order (with the same indices)
pd.Series | str
The corresponding abbreviated addresses in the same order (with the same indices),
or a single abbreviated address string.
"""
return addresses.str[:6] + "..." + addresses.str[-4:]
if isinstance(address, pd.Series):
out = address.str[:6] + "..." + address.str[-4:]
elif isinstance(address, str):
out = address[:6] + "..." + address[-4:]
else:
raise TypeError(f"Unexpected type {type(address)}")
return out
9 changes: 7 additions & 2 deletions src/agent0/core/hyperdrive/interactive/hyperdrive_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from web3 import Web3

from agent0.chainsync.analysis import fill_pnl_values, snapshot_positions_to_db
from agent0.chainsync.dashboard import abbreviate_address
from agent0.chainsync.db.base import add_addr_to_username
from agent0.chainsync.db.hyperdrive import (
checkpoint_events_to_db,
Expand Down Expand Up @@ -127,9 +128,13 @@ def __init__(
elif public_address is not None:
self.address = Web3.to_checksum_address(public_address)

if name is None:
self.name = abbreviate_address(self.address)
else:
self.name = name

# Register the username if it was provided
if name is not None:
add_addr_to_username(name, [self.address], self.chain.db_session)
add_addr_to_username(self.name, [self.address], self.chain.db_session)

# Expose account and address for type narrowing in local agent
@property
Expand Down
Loading