|
30 | 30 | "### System Specification\n", |
31 | 31 | "System specification details are available in the Balancer Simulations documentation:\n", |
32 | 32 | "- [Differential Specification](https://app.gitbook.com/@token-engineering-balancer/s/balancer-simulation-portal/v/master/balancer-simulations/nboverview)\n", |
33 | | - "- [Mathematical Specification](https://app.gitbook.com/@token-engineering-balancer/s/balancer-simulation-portal/v/master/additional-code-and-instructions/balancer-the-python-edition/balancer_math.py)\n", |
| 33 | + "- [Mathematical Specification](https://app.gitbook.com/@token-engineering-balancer/s/balancer-simulation-portal/v/master/additional-code-and-instructions/balancer-the-python-edition/)\n", |
34 | 34 | "- [Model Architecture](https://app.gitbook.com/@token-engineering-balancer/s/balancer-simulation-portal/v/master/balancer-simulations/nboverview)\n", |
35 | 35 | "- [Naming Convention](https://app.gitbook.com/@token-engineering-balancer/s/balancer-simulation-portal/v/master/additional-code-and-instructions/naming-convention)" |
36 | 36 | ] |
|
85 | 85 | "pp = pprint.PrettyPrinter(indent=4)\n", |
86 | 86 | "\n", |
87 | 87 | "from decimal import Decimal\n", |
| 88 | + "\n", |
| 89 | + "# Spot prices are needed for relevant notebooks and it's needed in the CadCAD model. Ignore this param here\n", |
| 90 | + "# Spot price reference must be a symbol of a token in the pool in ALL_CAPS\n", |
88 | 91 | "parameters = {\n", |
89 | 92 | " 'spot_price_reference': ['DAI'],\n", |
90 | | - "}\n", |
91 | | - "pp.pprint(parameters)" |
| 93 | + "}\n" |
92 | 94 | ] |
93 | 95 | }, |
94 | 96 | { |
|
99 | 101 | "\n", |
100 | 102 | "Pool Transactions, initial pool state and USD token prices are pulled from on-chain data collected in a .json file that has to be referenced here. \n", |
101 | 103 | "\n", |
102 | | - "Learn more how to create this file using our parsing scripts in the [documentation](https://app.gitbook.com/@token-engineering-balancer/s/balancer-simulation-portal/v/master/additional-code-and-instructions/transactions-pricefeeds).\n", |
103 | | - "(XX - remove spot price reference)" |
| 104 | + "Learn more how to create this file using our parsing scripts in the [documentation](https://app.gitbook.com/@token-engineering-balancer/s/balancer-simulation-portal/v/master/additional-code-and-instructions/transactions-pricefeeds).\n" |
104 | 105 | ] |
105 | 106 | }, |
106 | 107 | { |
|
163 | 164 | "\n", |
164 | 165 | "cadCAD state update functions replicate the following Balancer Pool Transactions (see system policies.py) \n", |
165 | 166 | "\n", |
| 167 | + "\n", |
| 168 | + "\n", |
166 | 169 | "**a) Add Liquidity**\n", |
167 | 170 | "= join policy \n", |
168 | 171 | "- `p_join_pool` (all-asset deposit)\n", |
|
172 | 175 | "**b) Withdraw Liquidity**\n", |
173 | 176 | "= exit policy \n", |
174 | 177 | "- `p_exit_pool` (all-asset withdrawal) \n", |
175 | | - "- `p_exit_swap_extern_amount_out` (single-asset withdrawal) \n", |
| 178 | + "- `p_exit_swap_extern_amount_out` (single-asset withdrawal) # NOTE, next version will use p_exit_swap_pool_amount_in\n", |
176 | 179 | "\n", |
177 | 180 | "**C) Swap**\n", |
178 | 181 | "= swap policy \n", |
179 | 182 | "- `p_swap_exact_amount_in` (out-given-in)\n", |
180 | 183 | "\n", |
181 | 184 | "\n", |
182 | | - "Balancer Pools offer an additional transaction type:\n", |
| 185 | + "Balancer Pools offer additional transaction types:\n", |
183 | 186 | "- `p_swap_exact_amount_out` (in-given-out)\n", |
184 | | - "Which is not applied in Balancer Simulations V1.0\n", |
| 187 | + "- `p_join_swap_pool_amount_out` (pool_out_given_single_in)\n", |
| 188 | + "- `p_exit_swap_pool_amount_in`(single_out_given_pool_in)\n", |
| 189 | + "Which is not applied in Balancer Simulations V1.0 since we are using only data from LOG_JOIN, LOG_EXIT and LOG_SWAP events from BPool contract. This does not provide information of the method selected by pool user.\n", |
| 190 | + "\n", |
| 191 | + "#### Fees\n", |
| 192 | + "\n", |
| 193 | + "Each `swap`, `join_swap` and `exit_swap` will have the pool collect a fee in the token goin into it. This fee is proportional to the `swap_fee` pool variable. We extract the token fee value from BMath methods and store it in `generated_fee_token_XX` state variables\n", |
185 | 194 | "\n", |
186 | | - "(XX - fees??)\n", |
187 | 195 | " \n", |
| 196 | + "\n", |
188 | 197 | "For a detailed description of the transactions, please visit the [Balancer Simulations documentation/Balancer Pool Functions](https://app.gitbook.com/@token-engineering-balancer/s/balancer-simulation-portal/v/master/additional-code-and-instructions/balancer-the-python-edition/balancer-pool-functions)." |
189 | 198 | ] |
190 | 199 | }, |
|
195 | 204 | "### B1.4 Partial State Update Blocks\n", |
196 | 205 | "\n", |
197 | 206 | "Partial State Update Blocks combine the following steps:\n", |
198 | | - "1. Parse actions and update the pool\n", |
| 207 | + "0. Skip initial action (pool creation)\n", |
| 208 | + "1. Parse actions each timestemp and update the pool balances, weights, spot prices\n", |
199 | 209 | "2. Update external USD prices\n", |
200 | | - "3. Calculate metrics\n", |
| 210 | + "3. Store action datetime\n", |
201 | 211 | "\n", |
202 | 212 | "For more information please visit the [Balancer Simulations documentation/V1.0 Model Overview](https://app.gitbook.com/@token-engineering-balancer/s/balancer-simulation-portal/v/master/balancer-simulations/nboverview)." |
203 | 213 | ] |
|
222 | 232 | "### B1.5 Configuration\n", |
223 | 233 | "\n", |
224 | 234 | "A pool's state is updated by\n", |
225 | | - "- **actions** (such as swaps) and\n", |
| 235 | + "- **actions** (such as swaps and external price updates) and\n", |
226 | 236 | "- **price signals** (USD values of tokens)\n", |
227 | 237 | "\n", |
228 | | - "These updates are captured in unique **timesteps**.\n", |
| 238 | + "These updates are captured in unique **timesteps**. 1 Timestep = 1 action (price signal or pool transaction). Each action has a datetime for time related analysis\n", |
| 239 | + "\n", |
| 240 | + "**steps_number** is automatically calculated from action json\n", |
229 | 241 | "\n", |
230 | | - "In most cases you might want to run the simulation across all timesteps included in your .json file - however you can specify any simulation range below." |
| 242 | + "In most cases you might want to run the simulation across all timesteps included in your .json file - however you can specify any simulation range below.\n", |
| 243 | + "\n", |
| 244 | + "### Note: You need to start from the pool creation state, as seen in 0x123..._initial_pool_states.json " |
231 | 245 | ] |
232 | 246 | }, |
233 | 247 | { |
|
271 | 285 | "source": [ |
272 | 286 | "### B1.7 Simulation Output Preparation\n", |
273 | 287 | "\n", |
274 | | - "Post-processing (utils.py) adds metrics to the data frame, such as \n", |
| 288 | + "Post-processing (utils.py) separate complex variables (like pool and token prices) into independent variables, and adds metrics to the data frame, such as \n", |
275 | 289 | "- `token_k_values` \n", |
276 | 290 | "based on\n", |
277 | 291 | "- `token_k_balances`\n", |
|
480 | 494 | "metadata": {}, |
481 | 495 | "outputs": [], |
482 | 496 | "source": [ |
483 | | - "# TODO: use generated_fees instead of price\n", |
484 | | - "# TODO: loop over tokens in a list\n", |
485 | | - "\n", |
486 | 497 | "#balance growth (total observation period)\n", |
487 | 498 | "daib_df = (p_df.iloc[-1][['token_dai_balance']])-(p_df.iloc[0][['token_dai_balance']]).copy()\n", |
488 | 499 | "daib_df = daib_df.reset_index()\n", |
|
611 | 622 | "name": "python", |
612 | 623 | "nbconvert_exporter": "python", |
613 | 624 | "pygments_lexer": "ipython3", |
614 | | - "version": "3.9.1" |
| 625 | + "version": "3.8.5" |
615 | 626 | } |
616 | 627 | }, |
617 | 628 | "nbformat": 4, |
|
0 commit comments