Skip to content

Commit

Permalink
Removing interactive prefix from interactive objects (#1450)
Browse files Browse the repository at this point in the history
This PR does the following renames:

- ILocalChain -> LocalChain
- IChain -> Chain
- ILocalHyperdrive -> LocalHyperdrive
- IHyperdrive -> Hyperdrive
- EthAgent -> PolicyAgent
- HyperdriveAgent -> HyperdrivePolicyAgent
- IHyperdriveAgent -> HyperdriveAgent
- ILocalHyperdriveAgent -> LocalHyperdriveAgent
  • Loading branch information
slundqui authored Apr 30, 2024
1 parent 1af0f1b commit fd94870
Show file tree
Hide file tree
Showing 61 changed files with 567 additions and 560 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ Finally, you can execute Hyperdrive trades in a simulated blockchain environment
```python
import datetime
from fixedpointmath import FixedPoint
from agent0 import ILocalHyperdrive, ILocalChain
from agent0 import LocalHyperdrive, LocalChain

# Initialize
chain = ILocalChain()
interactive_hyperdrive = ILocalHyperdrive(chain)
hyperdrive_agent0 = interactive_hyperdrive.init_agent(base=FixedPoint(100_000))
chain = LocalChain()
hyperdrive = LocalHyperdrive(chain)
hyperdrive_agent0 = hyperdrive.init_agent(base=FixedPoint(100_000))

# Run trades
chain.advance_time(datetime.timedelta(weeks=1))
Expand All @@ -48,7 +48,7 @@ close_event = hyperdrive_agent0.close_long(
)

# Analyze
pool_state = interactive_hyperdrive.get_pool_state(coerce_float=True)
pool_state = hyperdrive.get_pool_state(coerce_float=True)
pool_state.plot(x="block_number", y="longs_outstanding", kind="line")
```

Expand Down
18 changes: 9 additions & 9 deletions examples/interactive_hyperdrive_forking_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from fixedpointmath import FixedPoint

from agent0 import IHyperdrive, ILocalChain, PolicyZoo
from agent0 import Hyperdrive, LocalChain, PolicyZoo
from agent0.core.base.make_key import make_private_key

# %%
Expand All @@ -23,19 +23,19 @@

# %%
# Launch a local anvil chain forked from the rpc uri.
chain = ILocalChain(fork_uri=rpc_uri, fork_block_number=fork_block_number)
chain = LocalChain(fork_uri=rpc_uri, fork_block_number=fork_block_number)

hyperdrive_address = IHyperdrive.get_hyperdrive_addresses_from_registry(registry_address, chain)["sdai_14_day"]
hyperdrive_address = Hyperdrive.get_hyperdrive_addresses_from_registry(registry_address, chain)["sdai_14_day"]

# Note that we use IHyperdrive here instead of ILocalHyperdrive,
# as ILocalHyperdrive deploys a new pool, whereas we want to connect to an existing pool
# Note that we use Hyperdrive here instead of LocalHyperdrive,
# as LocalHyperdrive deploys a new pool, whereas we want to connect to an existing pool
# on the forked local chain.
# TODO this prevents us from using data tools provided by ILocalHyperdrive, ideally we can
# load a ILocalHyperdrive from an IHyperdrive object that connects to an existing pool and populates
# TODO this prevents us from using data tools provided by LocalHyperdrive, ideally we can
# load a LocalHyperdrive from an Hyperdrive object that connects to an existing pool and populates
# the database. This is blocked by needing an archive node, the fix here would be to
# (1) use event data instead, and (2) build historical data from event data.
hyperdrive_config = IHyperdrive.Config()
hyperdrive_pool = IHyperdrive(chain, hyperdrive_address, hyperdrive_config)
hyperdrive_config = Hyperdrive.Config()
hyperdrive_pool = Hyperdrive(chain, hyperdrive_address, hyperdrive_config)

# %%

Expand Down
10 changes: 5 additions & 5 deletions examples/interactive_local_hyperdrive_advanced_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

from fixedpointmath import FixedPoint

from agent0 import ILocalChain, ILocalHyperdrive, PolicyZoo
from agent0 import LocalChain, LocalHyperdrive, PolicyZoo

# %%
# Parameters for local chain initialization, defines defaults in constructor
local_chain_config = ILocalChain.Config()
local_chain_config = LocalChain.Config()
# Launches a local chain in a subprocess
# This also launches a local postgres docker container for data under the hood, attached to the chain.
# Each hyperdrive pool will have it's own database within this container
# NOTE: LocalChain is a subclass of Chain
# TODO can also implement functionality such as save/load state here
chain = ILocalChain(local_chain_config)
chain = LocalChain(local_chain_config)
# Can connect to a specific existing chain
# existing_chain = Chain("http://localhost:8545")

Expand All @@ -25,9 +25,9 @@
# An "admin" user (as provided by the Chain object) is launched/funded here for deploying hyperdrive

# Parameters for pool initialization. If empty, defaults to default values, allows for custom values if needed
initial_pool_config = ILocalHyperdrive.Config()
initial_pool_config = LocalHyperdrive.Config()
# Launches 2 pools on the same local chain
interactive_hyperdrive = ILocalHyperdrive(chain, initial_pool_config)
interactive_hyperdrive = LocalHyperdrive(chain, initial_pool_config)

# %%
# Generate funded trading agents from the interactive object
Expand Down
32 changes: 16 additions & 16 deletions examples/interactive_local_hyperdrive_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

from fixedpointmath import FixedPoint

from agent0 import ILocalChain, ILocalHyperdrive
from agent0 import LocalChain, LocalHyperdrive

# %%
# Parameters for local chain initialization, defines defaults in constructor
local_chain_config = ILocalChain.Config()
local_chain_config = LocalChain.Config()
# Launches a local chain in a subprocess
# This also launches a local postgres docker container for data under the hood, attached to the chain.
# Each hyperdrive pool will have it's own database within this container
# NOTE: LocalChain is a subclass of Chain
chain = ILocalChain(local_chain_config)
chain = LocalChain(local_chain_config)
# Can connect to a specific existing chain
# existing_chain = Chain("http://localhost:8545")

Expand All @@ -26,18 +26,18 @@
# An "admin" user (as provided by the Chain object) is launched/funded here for deploying hyperdrive

# Parameters for pool initialization. If empty, defaults to default values, allows for custom values if needed
initial_pool_config = ILocalHyperdrive.Config()
initial_pool_config = LocalHyperdrive.Config()
# Launches 2 pools on the same local chain
interactive_hyperdrive = ILocalHyperdrive(chain, initial_pool_config)
interactive_hyperdrive_2 = ILocalHyperdrive(chain, initial_pool_config)
hyperdrive = LocalHyperdrive(chain, initial_pool_config)
hyperdrive_2 = LocalHyperdrive(chain, initial_pool_config)

# %%
# Generate funded trading agents from the interactive object
# Names are reflected on output data frames and plots later
hyperdrive_agent0 = interactive_hyperdrive.init_agent(base=FixedPoint(100000), eth=FixedPoint(100), name="alice")
hyperdrive_agent1 = interactive_hyperdrive_2.init_agent(base=FixedPoint(100000), eth=FixedPoint(100), name="bob")
hyperdrive_agent0 = hyperdrive.init_agent(base=FixedPoint(100000), eth=FixedPoint(100), name="alice")
hyperdrive_agent1 = hyperdrive_2.init_agent(base=FixedPoint(100000), eth=FixedPoint(100), name="bob")
# Omission of name defaults to wallet address
hyperdrive_agent2 = interactive_hyperdrive.init_agent(base=FixedPoint(100000))
hyperdrive_agent2 = hyperdrive.init_agent(base=FixedPoint(100000))

# Add funds to an agent
hyperdrive_agent0.add_funds(base=FixedPoint(100000), eth=FixedPoint(100))
Expand Down Expand Up @@ -93,18 +93,18 @@

# %%
# Get data from database under the hood
pool_config = interactive_hyperdrive.get_pool_config()
pool_config = hyperdrive.get_pool_config()
# The underlying data is in Decimal format, which is lossless. We don't care about precision
# here, and pandas need a numerical float for plotting, so we coerce decimals to floats here
pool_state = interactive_hyperdrive.get_pool_state(coerce_float=True)
pool_state = hyperdrive.get_pool_state(coerce_float=True)
# TODO checkpoint info doesn't play nice with advancing time.
# This is because we don't create checkpoints when we advance time.
checkpoint_info = interactive_hyperdrive.get_checkpoint_info()
checkpoint_info = hyperdrive.get_checkpoint_info()

current_wallet = interactive_hyperdrive.get_current_wallet()
ticker = interactive_hyperdrive.get_ticker()
wallet_positions = interactive_hyperdrive.get_wallet_positions()
total_wallet_pnl_over_time = interactive_hyperdrive.get_total_wallet_pnl_over_time(coerce_float=True)
current_wallet = hyperdrive.get_current_wallet()
ticker = hyperdrive.get_ticker()
wallet_positions = hyperdrive.get_wallet_positions()
total_wallet_pnl_over_time = hyperdrive.get_total_wallet_pnl_over_time(coerce_float=True)

# %%
print(pool_state)
Expand Down
10 changes: 5 additions & 5 deletions examples/interactive_remote_hyperdrive_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

from fixedpointmath import FixedPoint

from agent0 import IChain, IHyperdrive, PolicyZoo
from agent0 import Chain, Hyperdrive, PolicyZoo
from agent0.core.base.make_key import make_private_key

# %%
# Set the rpc_uri to the chain, e.g., to sepolia testnet
rpc_uri = "http://uri.to.sepolia.testnet"
chain = IChain(rpc_uri)
chain = Chain(rpc_uri)

# Set the address of the hyperdrive pool
# hyperdrive_address = "0x0000000000000000000000000000000000000000"
Expand All @@ -24,9 +24,9 @@
# This is the registry address deployed on sepolia.
registry_address = "0xba5156E697d39a03EDA824C19f375383F6b759EA"

hyperdrive_address = IHyperdrive.get_hyperdrive_addresses_from_registry(registry_address, chain)["sdai_14_day"]
hyperdrive_config = IHyperdrive.Config()
hyperdrive_pool = IHyperdrive(chain, hyperdrive_address, hyperdrive_config)
hyperdrive_address = Hyperdrive.get_hyperdrive_addresses_from_registry(registry_address, chain)["sdai_14_day"]
hyperdrive_config = Hyperdrive.Config()
hyperdrive_pool = Hyperdrive(chain, hyperdrive_address, hyperdrive_config)

# %%

Expand Down
Loading

0 comments on commit fd94870

Please sign in to comment.