Skip to main content

strategy.strategies.tutorial_uniswap_swap.states.swap

partial

pprint

sleep

TYPE_CHECKING

Optional

ETH_ADDRESS

ActionType

ExecutionStatus

SwapSide

TransactionType

Action

ActionBundle

ApproveParams

SwapParams

swap

def swap(strat: "StrategyTutorialUniswapSwap") -> Optional[ActionBundle]

Swaps a token from the pool provided in the config.

Arguments:

  • strat StrategyTutorialUniswapSwap - The Strategy instance.

Returns:

ActionBundle or None: An ActionBundle containing the approve and swap.

prepare_swap

def prepare_swap(
strat: "StrategyTutorialUniswapSwap") -> 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

def validate_swap(strat: "StrategyTutorialUniswapSwap") -> 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

def sadflow_swap(strat: "StrategyTutorialUniswapSwap") -> ActionBundle

Handles the sadflow for the swap state. Calls the appropriate function based on the status of the actions.

sadflow_retry

def sadflow_retry(strat: "StrategyTutorialUniswapSwap") -> ActionBundle

Handles the basic retry sadflow.

sadflow_partial_retry

def sadflow_partial_retry(
strat: "StrategyTutorialUniswapSwap") -> 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.