diff --git a/.gitignore b/.gitignore index 260494d0..b42ab6bd 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ optimized-out kit/target target +# Tex .env report/main.aux report/main.pyg @@ -19,3 +20,7 @@ report/img/.DS_Store report/summary.aux _minted-main/* report/assets/img/.DS_Store +.vscode/* + +# Mdbook +book \ No newline at end of file diff --git a/DFMMBook/src/SUMMARY.md b/DFMMBook/src/SUMMARY.md new file mode 100644 index 00000000..7ce6f839 --- /dev/null +++ b/DFMMBook/src/SUMMARY.md @@ -0,0 +1,5 @@ +# Summary + +- [Kit Architecture](./architecture.md) +- [Pools](./pools.md) +- [Behaviors](./behaviors.md) diff --git a/DFMMBook/src/architecture.md b/DFMMBook/src/architecture.md new file mode 100644 index 00000000..1ba0d9e1 --- /dev/null +++ b/DFMMBook/src/architecture.md @@ -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. diff --git a/DFMMBook/src/behaviors.md b/DFMMBook/src/behaviors.md new file mode 100644 index 00000000..6251286a --- /dev/null +++ b/DFMMBook/src/behaviors.md @@ -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. diff --git a/DFMMBook/src/pools.md b/DFMMBook/src/pools.md new file mode 100644 index 00000000..af1fbb05 --- /dev/null +++ b/DFMMBook/src/pools.md @@ -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. diff --git a/book.toml b/book.toml new file mode 100644 index 00000000..327bfee2 --- /dev/null +++ b/book.toml @@ -0,0 +1,7 @@ +[book] +authors = ["Waylon Jepsen"] +language = "en" +multilingual = false +src = "DFMMBook/src" +title = "DFMM Book" + diff --git a/kit/Cargo.toml b/kit/Cargo.toml index a98bcea8..c0463b17 100644 --- a/kit/Cargo.toml +++ b/kit/Cargo.toml @@ -2,7 +2,7 @@ name = "dfmm-kit" version = "0.0.1" edition = "2021" -authors = ["Colin Roberts "] +authors = ["Colin Roberts , Waylon Jepsen "] description = "The Rust kit for the DFMM contracts." license = "Apache-2.0" keywords = ["ethereum", "smart-contracts", "automated market makers"]