Skip to content

Commit

Permalink
Merge pull request #19 from CompassLabs/main
Browse files Browse the repository at this point in the history
Latest changes.
  • Loading branch information
scheuclu authored Apr 4, 2024
2 parents a67e547 + 8006ebe commit 9854d02
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/1_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ If you want your chain or protocol to be integrated with `dojo`, [reach out](mai
## 🥳 Get access to `dojo`
`dojo` is currently in beta testing. Reach out for priority access & feel free to contact us with any questions or feedback:
- [Support via email](mailto:elisabeth@compasslabs.ai)
- [@labs_compass](https://twitter.com/labs_compas) on Twitter
- [@labs_compass](https://twitter.com/labs_compass) on Twitter
- [compasslabs.ai](https://compasslabs.ai/) for general information on Compass Labs

9 changes: 7 additions & 2 deletions docs/2_Getting_Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ sidebar_position: 2

# Getting Started

:::warning warning
`dojo` does **not** currently support Windows!!
:::note supported platforms

We currently support **Linux(x86)** and **Mac(AppleSilicon)**.
You may be able to use dojo in Windows using [WSL](https://learn.microsoft.com/en-us/windows/wsl/install), but we are not actively developing for it.

We aim to always support the latest version of **Python**. Currently we support **3.10+**.

:::

Let's discover `dojo` in **3 simple steps** 🏎️
Expand Down
29 changes: 27 additions & 2 deletions docs/4_environments/1_Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,34 @@ Environments generally provide the following functionality:
Each environment module contains information on the observations, actions and environment object for that environment. For example, to get this information for UniswapV3:

```python
from dojo.environments.uniswapV3 import UniV3Obs, UniV3Action, UniV3Env
from dojo.environments.uniswapV3 import UniV3Obs, UniV3Env
```

## "local" vs "forked" backend

One flag you'll to specify when creating an environment is the `backend_type`. Understanding the difference is critical to get **fast simulations**.

### tl;dr
#### `backend_type = "forked"`
- Quick to start-up
- Slow to run
#### `backend_type = "local"`
- Slow to start up(up to a few mins)
- Runs much faster

:::info
We are working on incorporating more complicated market impact models. Right now, the simulation simply replays the historic transactions.
Typically, you'd want to use the forked backend while you're still developing your strategies (on short simulation periods), and then switch to local backend for the actual backtest.
:::

### How it works

#### `backend_type = "forked"`
This uses an RPC provider to create a forked chain using anvil. It happens almost instantenously, but at one big disadvantage: For every single transaction that is occuring, dojo needs to talk to the RPC provider.
So unless you have a full archive-node on the same machine as dojo is running on, communication over the internet is happening.
If you think about the millions of transcations occuring in a typical backtest, this will slow down the simulation massively.
#### `backend_type = "local"`
In the local backend, we run custom logic to instantiate what is basically a pruned archive node on your local machine.
The main insight here is that on simulation start, you already know what contracts and accounts are relevant.
So, we create a local archive node for you, that has just these contracts and accounts, but for the purpose of the simulation is equivalent to a full archive node. **No communication to an outside RPC provider is required, thus it runs MUCH faster**.

Of course, we do comprehensive CI/CD testing to ensure that the local backend is implemented correctly.
39 changes: 33 additions & 6 deletions docs/4_environments/2_UniswapV3.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,40 @@ It is recommended to read the [whitepaper](https://uniswap.org/whitepaper-v3.pdf
## 🌊 Supported Pools
At the moment, we natively have data for the following pools:

- [DAI/USDC 0.01%](https://info.uniswap.org/#/pools/0x5777d92f208679db4b9778590fa3cab3ac9e2168)
- [USDC/ETH 0.05%](https://info.uniswap.org/#/pools/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640)
- [USDC/ETH 0.3%](https://info.uniswap.org/#/pools/0x8ad599c3a0ff1de082011efddc58f1908eb6e6)
- [WBTC/ETH 0.3%](https://info.uniswap.org/#/pools/0xcbcdf9626bc03e24f779434178a73a0b4bad62ed)
- [WBTC/WETH-0.3](https://info.uniswap.org/#/pools/0xCBCdF9626bC03E24f779434178A73a0B4bad62eD)
- [USDC/WETH-0.05](https://info.uniswap.org/#/pools/0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640)
- [DAI/USDC-0.05](https://info.uniswap.org/#/pools/0x6c6Bc977E13Df9b0de53b251522280BB72383700)
- [USDC/WETH-0.3](https://info.uniswap.org/#/pools/0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8)
- [DAI/USDC-0.01](https://info.uniswap.org/#/pools/0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168)
- [WBTC/WETH-0.05](https://info.uniswap.org/#/pools/0x4585FE77225b41b697C938B018E2Ac67Ac5a20c0)
- [WETH/StETH-0.3](https://info.uniswap.org/#/pools/0x7379e81228514a1D2a6Cf7559203998E20598346)
- [WETH/USDT-0.3](https://info.uniswap.org/#/pools/0x4e68Ccd3E89f51C3074ca5072bbAC773960dFa36)
- [UNI/WETH-0.3](https://info.uniswap.org/#/pools/0x1d42064Fc4Beb5F8aAF85F4617AE8b3b5B8Bd801)
- [MATIC/WETH-0.3](https://info.uniswap.org/#/pools/0x290A6a7460B308ee3F19023D2D00dE604bcf5B42)
- [WBTC/WETH-0.01](https://info.uniswap.org/#/pools/0x6Ab3bba2F41e7eAA262fa5A1A9b3932fA161526F)
- [WBTC/USDC-0.3](https://info.uniswap.org/#/pools/0x99ac8cA7087fA4A2A1FB6357269965A2014ABc35)
- [DAI/WETH-0.3](https://info.uniswap.org/#/pools/0xC2e9F25Be6257c210d7Adf0D4Cd6E3E881ba25f8)
- [USDC/USDT-0.01](https://info.uniswap.org/#/pools/0x3416cF6C708Da44DB2624D63ea0AAef7113527C6)
- [USDC/USDT-0.05](https://info.uniswap.org/#/pools/0x7858E59e0C01EA06Df3aF3D20aC7B0003275D4Bf)
- [DUSK/USDT-0.3](https://info.uniswap.org/#/pools/0xFf29D3E552155180809ea3A877408A4620058086)
- [SKL/WETH-0.01](https://info.uniswap.org/#/pools/0x12CC685eEb95D3fCDfAe0a996e214e51FA6f7548)
- [PRO/WETH-0.01](https://info.uniswap.org/#/pools/0xC7Cf089FB4BC91F1981dF2285ca019Ab09A5dd3B)

- [PEPE/WETH-0.3](https://info.uniswap.org/#/pools/0x11950d141EcB863F01007AdD7D1A342041227b58)
- [PEPE/WETH-1](https://info.uniswap.org/#/pools/0xF239009A101B6B930A527DEaaB6961b6E7deC8a6)
- [PEPE/USDC-1](https://info.uniswap.org/#/pools/0xcEE31C846CbF003F4cEB5Bbd234cBA03C6e940C7)
- [FRAX/USDC-0.05](https://info.uniswap.org/#/pools/0xc63B0708E2F7e69CB8A1df0e1389A98C35A76D52)
- [DAI/FRAX-0.05](https://info.uniswap.org/#/pools/0x97e7d56A0408570bA1a7852De36350f7713906ec)
- [LDO/WETH-0.3](https://info.uniswap.org/#/pools/0xa3f558aebAecAf0e11cA4b2199cC5Ed341edfd74)
- [LDO/WETH-0.05](https://info.uniswap.org/#/pools/0xcFeCC1C9F3cB6190CB1Ff7F65a130BFbE5107D38)
- [LDO/WETH-1](https://info.uniswap.org/#/pools/0xf4aD61dB72f114Be877E87d62DC5e7bd52DF4d9B)
- [SHIB/WETH-0.3](https://info.uniswap.org/#/pools/0x2F62f2B4c5fcd7570a709DeC05D68EA19c82A9ec)
- [SHIB/WETH-1](https://info.uniswap.org/#/pools/0x5764a6F2212D502bC5970f9f129fFcd61e5D7563)



:::success
If you want to do a **simulation outside of these pools**, you can implement your own dataloader **[here](../Dataloaders)**.
If you want to do a **simulation on a different pool**, please [contact us](mailto:elisabeth@compasslabs.ai). **We can add new pools fairly quickly.**.
:::


Expand All @@ -45,7 +72,7 @@ In general, there are 4 actions you can perform on the Uniswap V3 environment:
- **COLLECT**: collect LP fees from an LP position
- **SET FEE PROTOCOL**: set the protocol fee of a pool

Please refer to the [code reference](https://readthedocs.compasslabs.ai/dojo.actions.html) for more details.
Please refer to the [code reference](https://readthedocs.compasslabs.ai/dojo.actions.html#dojo.actions.uniswapV3.UniV3Collect) for more details.


## 🧑‍💻 Example
Expand Down
6 changes: 0 additions & 6 deletions docs/4_environments/3_AAVE.md

This file was deleted.

58 changes: 58 additions & 0 deletions docs/4_environments/3_AAVE.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
sidebar_position: 3
---
import CodeBlock from '../../src/components/CodeBlock';

# AaveV3

You can import the AaveV3 👻 environment by running:
```python
from dojo.environments import AAVEv3Env
```

:::tip
It is recommended to read the [whitepaper](https://github.com/aave/aave-v3-core/blob/master/techpaper/Aave_V3_Technical_Paper.pdf) first.
:::

## 🌊 Supported Tokens
At the moment, we suport the following tokens:

- Wrapped Bitcoin [WBTC](https://etherscan.io/address/0x2260fac5e5542a773aa44fbcfedf7c193bc2c599)
- Wrapped Ether [WETH](https://etherscan.io/address/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2)
- USD Coin [USDC](https://etherscan.io/address/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48)
- Tether USDT [WETH](https://etherscan.io/address/0xdac17f958d2ee523a2206206994597c13d831ec7)
- Chainlink [LINK](https://etherscan.io/address/0x514910771af9ca656af840dff83e8264ecf986ca)
- Dai Stablecoin [DAI](https://etherscan.io/address/0x6b175474e89094c44da98b954eedeac495271d0f)
- Aave Token [AAVE](https://etherscan.io/address/0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9)
- Uniswap Token [UNI](https://etherscan.io/address/0x1f9840a85d5af5bf1d1762f925bdaddc4201f984)
- Balancer [BAL](https://etherscan.io/address/0xba100000625a3754423978a60c9317c58a424e3D)


## 🔎 Observations

An observation refers to the information that the agent receives from the environment at every block.
With AAAVE, the most interesting observation is probably a users [health factor](https://docs.aave.com/risk/asset-risk/risk-parameters#health-factor).

The methods within `AaveV3Obs` can be found [here](https://readthedocs.compasslabs.ai/dojo.observations.html#dojo.observations.AaveV3Obs).


## 🕺 Actions

Actions are the means through which the agent interacts with the environment to achieve goals.

In general, there are 4 actions you can perform on the Uniswap V3 environment:

- **SUPPLY**: Supplying collateral.
- **BORROW**: Borrowing a token from the pool.
- **WITHDRAW**: Withdrawing collateral.
- **REPAY**: Repay borrowed token.
- **LIQUIDATION**: Execute a liquidation on a poistion that slipped below a health factor of 1.0.


:::info
At the moment, we don't yet support Flash Loans.
:::

## 🧑‍💻 Example

<CodeBlock file="snippets/aaveV3_doaction.py" snippet_name={"1"}/>
2 changes: 1 addition & 1 deletion docs/5_Agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ from dojo.agents import BaseAgent
from dojo.environments.uniswapV3 import UniV3Obs

class ETHAgent(BaseAgent):
def __init__(self, initial_portfolio: Portfolio = {"USDC": Decimal(10_000)}) -> None:
def __init__(self, initial_portfolio: Portfolio = {"ETH": Decimal(10), "USDC": Decimal(10_000)}) -> None:
super().__init__(initial_portfolio=initial_portfolio)

def reward(obs: UniV3Obs) -> float:
Expand Down
6 changes: 5 additions & 1 deletion docs/7_Simulation_Loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ This is a screenshot of our upcoming live-simulation dashboard.
</p>

![](/img/simulation_full.png)

</details>


## Saving data
For the moment, the most comprehensive way to store data is by also launching the dashboard.(Will will make that part standalon shortly).
The dashboard allows you to save all data in json-format on a per block basis. You can load it into an empty dashboard later, or read the JSON for further processing.
File renamed without changes.
9 changes: 9 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ h1, h2, h3 {
.button {
background-color: white;
border: 1px solid #1e1c2d7b;
}

.test {
filter: sepia(1) saturate(100);
}


svg {
filter: drop-shadow(2px 2px 4px #1e1c2d );
}
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4676,11 +4676,6 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@~2.3.2:
version "2.3.2"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"
Expand Down

0 comments on commit 9854d02

Please sign in to comment.