strategy.strategies.dynamic_lp.states.swap_assets
json
partial
pprint
TYPE_CHECKING
Optional
ETH_ADDRESS
ActionType
ExecutionStatus
SwapSide
TransactionType
Action
ActionBundle
SwapParams
calculate_position
create_approve_1token_action
swap_assets
def swap_assets(strat: "StrategyDynamicLP") -> Optional[ActionBundle]
Executes the necessary asset swaps to maintain the desired token ratio to open a new position based on what was received from closing the previous position.
Will only swap in the direction of the token that needs to be increased to reach the desired ratio.
Arguments:
strat
StrategyDynamicLP - The Strategy instance.
Returns:
ActionBundle or None: An ActionBundle containing the approve and swap actions if a swap is needed.
Notes:
- Swaps are done in the pool in which we are LPing. A better routing will be implemented.
prepare_swap_assets
def prepare_swap_assets(strat: "StrategyDynamicLP") -> Optional[ActionBundle]
Prepares the swap actions.
Returns:
ActionBundle or None: An ActionBundle containing the approve and swap actions if a swap is needed.
validate_swap_assets
def validate_swap_assets(strat: "StrategyDynamicLP") -> 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 state.
sadflow_swap_assets
def sadflow_swap_assets(strat: "StrategyDynamicLP") -> ActionBundle
Handles the sadflow for the swap assets state. Calls the appropriate function based on the status of the actions.
sadflow_retry
def sadflow_retry(strat: "StrategyDynamicLP") -> ActionBundle
Handles the basic retry sadflow.
sadflow_partial_retry
def sadflow_partial_retry(strat: "StrategyDynamicLP") -> 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.