pool_state_updates.py

ActionDecoder's decoded actions (signals, in cadCAD lore) get passed here into s_update_pool, which redirects to the actual state update function like s_swap_exact_amount_in. The redirection is performed via a dict lookup:

pool_operation_mappings = {
    JoinSwapExternAmountInInput: s_join_swap_extern_amount_in,
    JoinParamsInput: s_join_pool,
    SwapExactAmountInInput: s_swap_exact_amount_in,
    SwapExactAmountOutInput: s_swap_exact_amount_out,
    ExitPoolInput: s_exit_pool,
    ExitSwapPoolAmountInInput: s_exit_swap_pool_amount_in,
    ExitSwapPoolExternAmountOutInput: s_exit_swap_extern_amount_out
}

Each state update function follows the same structure:

  1. Parse input from the action and get variables from current pool state (related token balances)

  2. Apply related Balancer Math

  3. Update fees if applicable

  4. Update pool balances

  5. Return pool so action decoder can signal updates

Some sanity checks are made, following BPool smart contracts. In REPLAY_OUTPUT mode no sanity checks are performed:

Min/Max limits in prices and token amounts are not included since the model won't late stuck transactions or tx reordering like the actual BPool contract.

Swaps

Join Multi Asset

Join Single Asset

Single Asset Exit

Exit Multi Asset

Last updated

Was this helpful?