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

Feat: Mdbook #143

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ optimized-out
kit/target
target

# Tex
.env
report/main.aux
report/main.pyg
Expand All @@ -19,3 +20,7 @@ report/img/.DS_Store
report/summary.aux
_minted-main/*
report/assets/img/.DS_Store
.vscode/*

# Mdbook
book
5 changes: 5 additions & 0 deletions DFMMBook/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Summary

- [Kit Architecture](./architecture.md)
- [Pools](./pools.md)
- [Behaviors](./behaviors.md)
46 changes: 46 additions & 0 deletions DFMMBook/src/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Dynamic Function Market Maker Arbiter Kit

The high-level goal of the kits is to provide a generic and flexible Rust API for interacting with the DFMM contracts both in mainnet environments and in arbiter simulations.
The DFMM kit is a set of abstractions around the DFMM contracts and user behaviors for the contracts.
The DFMM kit has three top-level modules, one of which is the autogenerated contract bindings.

```
kit
├── Cargo.toml
├── LICENSE
├── README.md
├── configs
│ └── test.toml
├── main.rs
├── src
│ ├── behaviors
│ │ ├── allocate
│ │ │ └── mod.rs
│ │ ├── creator.rs
│ │ ├── deploy.rs
│ │ ├── mod.rs
│ │ ├── swap
│ │ │ └── mod.rs
│ │ ├── token.rs
│ │ └── update
│ │ └── mod.rs
│ ├── bindings
│ │ ├── ...
│ ├── lib.rs
│ └── pool
│ ├── constant_sum.rs
│ ├── geometric_mean.rs
│ ├── log_normal.rs
│ ├── mod.rs
│ └── n_token_geometric_mean.rs
└── tests
├── common.rs
├── creator_integration.rs
├── deploy_integration.rs
├── swap_integration.rs
├── token_integration.rs
└── update_integration.rs
```
The other two modules are the `behaviors` and the `pool` modules.
The `pool` module provides abstractions that every DFMM pool conforms to.
The `behaviors` module consists of generic actions applicable to any pool and any strategy.
30 changes: 30 additions & 0 deletions DFMMBook/src/behaviors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Behaviors
The `behaviors` module contains functionality for agent behaviors for these contracts.
The `behaviors` module in the DFMM kit is designed to encapsulate the various agent behaviors that interact with the DFMM contracts. This module is crucial for automating and managing the interactions between users (or agents) and the different pool strategies defined in the `pool` module. The behaviors are structured around a series of sub-modules, each tailored to specific tasks and operations within the DFMM ecosystem.

## Behaviors Module
Note that we use the unstable Rust [RFC-1210](https://rust-lang.github.io/rfcs/1210-impl-specialization.html) for impl-specialization.
This provides some flexibility in the items each behavior streams and reacts to.
In particular, it allows us to define the process behavior trait for a subset of types to easily specify the type `E` in the stream you would like the behavior to react to.

### 1. Allocate
This `allocate` behavior handles the allocation of resources within the DFMM pools. It defines behaviors for adjusting liquidity allocation based on various strategies and conditions.

### 2. Creator
The `creator` is responsible for the creation of new pool instances. It uses configuration data to set up pools according to specified parameters and strategies.

### 3. Deploy
The `deploy` behavior manages the deployment of contracts related to the DFMM. It handles the initialization and setup of contracts on the blockchain, ensuring that they are ready for interaction.

### 4. Swap
The `swap` behavior facilitates token swaps within the pools. It defines the logic for exchanging tokens based on the current pool state and market conditions.
The swap behavior, in particular, has a `SwapType` trait that can be implemented by any specific instance of a swap type for the swap behavior.
This trait enables users to configure particular triggers for swaps and specific methods to calculate the swap size.

### 5. Token
The `token` sub-module manages token-related operations, such as minting and querying token states. It interacts with the token contracts to perform administrative tasks and queries.

### 6. Update
Finally, the `update` sub-module is responsible for updating the state and configuration of pools. It handles changes to the pool parameters and ensures that the pools adapt to new settings effectively.

Each of these sub-modules is designed to handle specific aspects of the DFMM ecosystem, working together to provide a comprehensive set of behaviors that manage and automate interactions with the DFMM contracts.
27 changes: 27 additions & 0 deletions DFMMBook/src/pools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Pools
The pool module contains a trait `PoolType` that is generic over DFMM strategies.
The `PoolType` trait in the `pool` module is a central abstraction designed for various DFMM strategies.
It defines the necessary operations and types required to interact with different pool strategies.
Here's a brief overview of its capabilities and structure:

- **Generic Types**:
- `Parameters`: Configuration parameters for the pool, which are serializable, deserializable, and can be used in Ethereum ABI decoding.
- `StrategyContract`: Represents the contract that implements the strategy logic.
- `SolverContract`: Represents the contract that handles the solving logic for the pool.
- `AllocationData`: Data related to resource allocation within the pool, which is also serializable and deserializable.

- **Asynchronous Methods**:
- `swap_data`: Asynchronously fetches data required for token swaps within the pool.
- `update_data`: Asynchronously updates the pool's parameters.
- `change_allocation_data`: Asynchronously modifies the allocation data of the pool.

- **Synchronous Methods**:
- `get_contracts`: Retrieves instances of the strategy and solver contracts.
- `get_strategy_address`: Fetches the address of the strategy contract.
- `get_init_data`: Gathers initial configuration data for pool setup.
- `set_controller`: Sets the controller address in the parameters.
- `create_instance`: Instantiates a new pool with the specified contracts and parameters.
- `get_params`: Retrieves the parameters of a pool from its strategy contract.

This trait is crucial for ensuring that different pool strategies can be managed uniformly, providing a consistent interface for operations such as swaps, parameter updates, and resource allocations across any pool on any strategy.
Each strategy implements the pool trait in the rest of the pool module.
7 changes: 7 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[book]
authors = ["Waylon Jepsen"]
language = "en"
multilingual = false
src = "DFMMBook/src"
title = "DFMM Book"

2 changes: 1 addition & 1 deletion kit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "dfmm-kit"
version = "0.0.1"
edition = "2021"
authors = ["Colin Roberts <[email protected]>"]
authors = ["Colin Roberts <[email protected]>, Waylon Jepsen <[email protected]>"]
description = "The Rust kit for the DFMM contracts."
license = "Apache-2.0"
keywords = ["ethereum", "smart-contracts", "automated market makers"]
Expand Down
Loading