From 081d4117e25bbe612b70a5f2a1afba6c16369927 Mon Sep 17 00:00:00 2001 From: Waylon Jepsen Date: Fri, 26 Apr 2024 14:18:46 -0700 Subject: [PATCH 1/3] chore: mdbook init --- .gitignore | 5 +++++ DFMMBook/src/SUMMARY.md | 3 +++ DFMMBook/src/chapter_1.md | 1 + book.toml | 7 +++++++ kit/Cargo.toml | 2 +- 5 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 DFMMBook/src/SUMMARY.md create mode 100644 DFMMBook/src/chapter_1.md create mode 100644 book.toml 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..7390c828 --- /dev/null +++ b/DFMMBook/src/SUMMARY.md @@ -0,0 +1,3 @@ +# Summary + +- [Chapter 1](./chapter_1.md) diff --git a/DFMMBook/src/chapter_1.md b/DFMMBook/src/chapter_1.md new file mode 100644 index 00000000..b743fda3 --- /dev/null +++ b/DFMMBook/src/chapter_1.md @@ -0,0 +1 @@ +# Chapter 1 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"] From 6168bccfa88a9ae7fb5d9e4782545c68f74dffca Mon Sep 17 00:00:00 2001 From: Waylon Jepsen Date: Fri, 26 Apr 2024 14:57:55 -0700 Subject: [PATCH 2/3] feat: mdbook draft --- DFMMBook/src/SUMMARY.md | 4 +++- DFMMBook/src/architecture.md | 46 ++++++++++++++++++++++++++++++++++++ DFMMBook/src/behaviors.md | 30 +++++++++++++++++++++++ DFMMBook/src/chapter_1.md | 1 - DFMMBook/src/pools.md | 27 +++++++++++++++++++++ 5 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 DFMMBook/src/architecture.md create mode 100644 DFMMBook/src/behaviors.md delete mode 100644 DFMMBook/src/chapter_1.md create mode 100644 DFMMBook/src/pools.md diff --git a/DFMMBook/src/SUMMARY.md b/DFMMBook/src/SUMMARY.md index 7390c828..7ce6f839 100644 --- a/DFMMBook/src/SUMMARY.md +++ b/DFMMBook/src/SUMMARY.md @@ -1,3 +1,5 @@ # Summary -- [Chapter 1](./chapter_1.md) +- [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..4313b02b --- /dev/null +++ b/DFMMBook/src/architecture.md @@ -0,0 +1,46 @@ +# Dynamic Function Market Maker Arbiter Kit + +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 is for the pool abstractions that every dfmm pool fits into. +The behaviors are actions generic of pools allowing them to work for any pool for any strategy. \ No newline at end of file diff --git a/DFMMBook/src/behaviors.md b/DFMMBook/src/behaviors.md new file mode 100644 index 00000000..73f9f114 --- /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 gives us some flexibility of the items each behavior streams and reacts to. +In particular is allows us to define the proccess 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 a 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 makes it easy to make 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 or 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/chapter_1.md b/DFMMBook/src/chapter_1.md deleted file mode 100644 index b743fda3..00000000 --- a/DFMMBook/src/chapter_1.md +++ /dev/null @@ -1 +0,0 @@ -# Chapter 1 diff --git a/DFMMBook/src/pools.md b/DFMMBook/src/pools.md new file mode 100644 index 00000000..4fc8101b --- /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 different DFMM strategies. +It defines the necessary operations and types required to interact with various 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 like 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. From 7d6ca9e58fbb71768b7ce906e38bcfc03049b15d Mon Sep 17 00:00:00 2001 From: Waylon Jepsen Date: Fri, 26 Apr 2024 15:02:39 -0700 Subject: [PATCH 3/3] chore: Spelling + Grammar --- DFMMBook/src/architecture.md | 8 ++++---- DFMMBook/src/behaviors.md | 14 +++++++------- DFMMBook/src/pools.md | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/DFMMBook/src/architecture.md b/DFMMBook/src/architecture.md index 4313b02b..1ba0d9e1 100644 --- a/DFMMBook/src/architecture.md +++ b/DFMMBook/src/architecture.md @@ -1,7 +1,8 @@ # 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. +The DFMM kit has three top-level modules, one of which is the autogenerated contract bindings. ``` kit @@ -40,7 +41,6 @@ kit ├── token_integration.rs └── update_integration.rs ``` - The other two modules are the `behaviors` and the `pool` modules. -The pool module is for the pool abstractions that every dfmm pool fits into. -The behaviors are actions generic of pools allowing them to work for any pool for any strategy. \ No newline at end of file +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 index 73f9f114..6251286a 100644 --- a/DFMMBook/src/behaviors.md +++ b/DFMMBook/src/behaviors.md @@ -3,12 +3,12 @@ The `behaviors` module contains functionality for agent behaviors for these cont 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 gives us some flexibility of the items each behavior streams and reacts to. -In particular is allows us to define the proccess behavior trait for a subset of types to easily specify the type `E` in the stream you would like the behavior to react to. +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 a behaviors for adjusting liquidity allocation based on various strategies and conditions. +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. @@ -17,9 +17,9 @@ The `creator` is responsible for the creation of new pool instances. It uses con 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 makes it easy to make 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 or specific methods to calculate the swap size. +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. diff --git a/DFMMBook/src/pools.md b/DFMMBook/src/pools.md index 4fc8101b..af1fbb05 100644 --- a/DFMMBook/src/pools.md +++ b/DFMMBook/src/pools.md @@ -1,7 +1,7 @@ # 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 different DFMM strategies. -It defines the necessary operations and types required to interact with various pool strategies. +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**: @@ -23,5 +23,5 @@ Here's a brief overview of its capabilities and structure: - `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 like swaps, parameter updates, and resource allocations across any pool on any strategy. +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.