DELV repo for market simulation and analysis
This docs page can be found via https://agent0.readthedocs.io/en/latest/.
This repo contains general purpose code for interacting with Ethereum smart contracts. However, it was bulit for the primary use case of trading on Hyperdrive markets.
First, install Foundry and Docker.
Next, using a Python 3.10 environment, you can install agent0 via pip:
pip install --upgrade agent0
Finally, you can execute Hyperdrive trades in a simulated blockchain environment:
import datetime
from fixedpointmath import FixedPoint
from agent0 import LocalHyperdrive, LocalChain
# Initialize
chain = LocalChain()
hyperdrive = LocalHyperdrive(chain)
hyperdrive_agent0 = chain.init_agent(base=FixedPoint(100_000), eth=FixedPoint(10), pool=hyperdrive)
# Run trades
chain.advance_time(datetime.timedelta(weeks=1))
open_long_event = hyperdrive_agent0.open_long(base=FixedPoint(100), eth=FixedPoint(10))
chain.advance_time(datetime.timedelta(weeks=5))
close_event = hyperdrive_agent0.close_long(
maturity_time=open_long_event.maturity_time, bonds=open_long_event.bond_amount
)
# Analyze
pool_info = hyperdrive.get_pool_info(coerce_float=True)
pool_info.plot(x="block_number", y="longs_outstanding", kind="line")
See our tutorial notebook and examples notebook for more information, including details on executing trades on remote chains.
Please refer to INSTALL.md for more advanced install options.
Please refer to BUILD.md.
We deploy a local anvil chain to run system tests. Therefore, you must install foundry as a prerequisite for running tests.
Testing is achieved with py.test.
You can run all tests from the repository root directory by running python -m pytest
, or you can pick a specific test with python -m pytest {path/to/test_file.py}
.
General integration-level tests are in the tests
folder, while more isolated or unit tests are colocated with the files they are testing and end with a _test.py
suffix.
Please refer to CONTRIBUTING.md.
To run coverage locally you can follow these steps:
pip install coverage
coverage run -m pytest
coverage html
then just open htmlcov/index.html
to view the report!
We frequently use 18-decimal fixed-point precision numbers for arithmetic.
This project is a work-in-progress. The language used in this code and documentation is not intended to, and does not, have any particular financial, legal, or regulatory significance.
Copyright © 2024 DELV
Licensed under the Apache License, Version 2.0 (the "OSS License").
By accessing or using this code, you signify that you have read, understand and agree to be bound by and to comply with the OSS License and DELV's Terms of Service. If you do not agree to those terms, you are prohibited from accessing or using this code.
Unless required by applicable law or agreed to in writing, software distributed under the OSS License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the OSS License and the DELV Terms of Service for the specific language governing permissions and limitations.