strategy.strategies.dynamic_lp.states.teardown
json
partial
pprint
TYPE_CHECKING
ETH_ADDRESS
get_address_by_chain_and_network
ActionType
ExecutionStatus
SwapSide
TransactionType
Action
ActionBundle
ClosePositionParams
SwapParams
UnwrapParams
log_close_metrics
log_swap_metrics
log_teardown_metrics
log_unwrap_metrics
create_approve_1token_action
to_readable
teardown
def teardown(strat: "StrategyDynamicLP") -> ActionBundle
Concludes the strategy by closing any active positions and preparing the system for a reset or shutdown. Leaves the system in a state where it can be cleanly initialized again.
- Close Position
- Swap back to Funding Asset.
- Unwrap needed? (if Funding Asset is ETH)
Returns:
Optional[Action]
- An action object configured to close the current liquidity position if one exists, or None if no positions are open.
prepare_close
def prepare_close(strat: "StrategyDynamicLP") -> ActionBundle
validate_close
def validate_close(strat: "StrategyDynamicLP") -> bool
Validates the close position actions and retrieves the amounts from closing the position (liquidity + fees), using transaction receipts. It loads the transaction statuses from the executioner and processes them.
Returns:
bool
- True if the close position actions were successful and the amounts were retrieved correctly.
Notes:
The only possible ExecutionStatus at this point is ExecutionStatus.SUCCESS otherwise should be in sadflow redoing the actions.
sadflow_close
def sadflow_close(strat: "StrategyDynamicLP") -> ActionBundle
Handles the sadflow for the close substate. Calls the appropriate function based on the status of the actions.
sadflow_close_retry
def sadflow_close_retry(strat: "StrategyDynamicLP") -> ActionBundle
Handles the basic retry sadflow.
sadflow_close_partial_retry
def sadflow_close_partial_retry(strat: "StrategyDynamicLP") -> ActionBundle
Handles the complex partial retry sadflow.
Close position with Multicall has no partial sadflow, it's all or nothing.
prepare_swap
def prepare_swap(strat: "StrategyDynamicLP", token_index: int) -> ActionBundle
Prepares the swap actions. Either the swap0 or swap1 based on the token_index. Swaps the assets back to the initial funding token.
Returns:
ActionBundle or None: An ActionBundle containing the approve and swap actions if a swap is needed.
validate_swap
def validate_swap(strat: "StrategyDynamicLP", token_index: int) -> bool
Validates the swap actions and retrieves the executed amounts using the execution details.
Returns:
bool
- True if the swap actions were successful and the amounts were retrieved correctly. and we can move to the next substate.
sadflow_swap
def sadflow_swap(strat: "StrategyDynamicLP", token_index: int) -> ActionBundle
Handles the sadflow for the teardown swap0/1 substates. Calls the appropriate function based on the status of the actions.
sadflow_swap_retry
def sadflow_swap_retry(strat: "StrategyDynamicLP",
token_index: int) -> ActionBundle
Handles the basic retry sadflow.
sadflow_swap_partial_retry
def sadflow_swap_partial_retry(strat: "StrategyDynamicLP",
token_index: int) -> ActionBundle
Handles the complex partial retry sadflow.
The Prepare Action sends: actions=[action_approve, action_swap]
- Failure
1
: The Approves failed -> We retry the same state as is. - Failure
2
: Swap failed -> We check the revert reason. -> For now we simply retry the same state as is (updating values), because we don't care too much double approving. Known revert reasons:- STF: Retry the same state for now.
- Slippage: Retry the same state for now.
prepare_unwrap
def prepare_unwrap(strat: "StrategyDynamicLP") -> ActionBundle
Prepares the unwrap actions for converting WETH back to ETH.
Returns:
ActionBundle or None: An ActionBundle containing the unwrap action if an unwrap is needed.
validate_unwrap
def validate_unwrap(strat: "StrategyDynamicLP") -> bool
Validates the unwrap actions and retrieves the executed amounts using the execution details.
Returns:
bool
- True if the unwrap actions were successful and the amounts were retrieved correctly.
sadflow_unwrap
def sadflow_unwrap(strat: "StrategyDynamicLP") -> ActionBundle
Handles the sadflow for the teardown unwrap substate. Calls the appropriate function based on the status of the actions.
sadflow_unwrap_retry
def sadflow_unwrap_retry(strat: "StrategyDynamicLP") -> ActionBundle
Handles the basic retry sadflow.
sadflow_unwrap_partial_retry
def sadflow_unwrap_partial_retry(strat: "StrategyDynamicLP") -> ActionBundle
Handles the complex partial retry sadflow.
Unwrap has no partial sadflow, it's all or nothing.