UniswapV2RoutingState#
tradeexecutor.ethereum.uniswap_v2_routing.UniswapV2RoutingState class.
- class UniswapV2RoutingState[source]#
Bases:
RoutingState
Manage transaction building for multiple Uniswap trades.
Lifespan is one rebalance - remembers already made approvals
Web3 connection and hot wallet
Approval tx creation
Swap tx creation
Manage the state of already given approvals here, so that we do not do duplicates.
The approvals are not persistent in the executor state, but are specific for each cycle.
- __init__(pair_universe, tx_builder, swap_gas_limit=2000000)[source]#
- Parameters
pair_universe (PandasPairUniverse) –
tx_builder (TransactionBuilder) –
Methods
__init__
(pair_universe, tx_builder[, ...])check_has_enough_tokens
(erc_20, amount)Check we have enough buy side tokens to do a trade.
ensure_token_approved
(token_address, ...)Make sure we have ERC-20 approve() for the trade
get_uniswap_for_pair
(factory_router_map, ...)Get a router for a trading pair.
is_approved_on_chain
(token_address, ...)is_route_approved
(router_address)mark_router_approved
(token_address, ...)trade_on_router_three_way
(uniswap, ...)Prepare the actual swap for three way trade.
trade_on_router_two_way
(uniswap, ...)Prepare the actual swap.
Attributes
- __init__(pair_universe, tx_builder, swap_gas_limit=2000000)[source]#
- Parameters
pair_universe (PandasPairUniverse) –
tx_builder (TransactionBuilder) –
- get_uniswap_for_pair(factory_router_map, target_pair)[source]#
Get a router for a trading pair.
- Parameters
factory_router_map (dict) –
target_pair (TradingPairIdentifier) –
- Return type
- check_has_enough_tokens(erc_20, amount)[source]#
Check we have enough buy side tokens to do a trade.
This might not be the case if we are preparing transactions ahead of time and sell might have not happened yet.
- ensure_token_approved(token_address, router_address)[source]#
Make sure we have ERC-20 approve() for the trade
Infinite approval on-chain
…or previous approval in this state,
- Parameters
- Returns
Create 0 or 1 transactions if needs to be approved
- Return type
- trade_on_router_two_way(uniswap, target_pair, reserve_asset, reserve_amount, max_slippage, check_balances)[source]#
Prepare the actual swap.
- Parameters
check_balances (False) – Check on-chain balances that the account has enough tokens and raise exception if not.
uniswap (UniswapV2Deployment) –
target_pair (TradingPairIdentifier) –
reserve_asset (AssetIdentifier) –
reserve_amount (int) –
max_slippage (float) –
- trade_on_router_three_way(uniswap, target_pair, intermediary_pair, reserve_asset, reserve_amount, max_slippage, check_balances)[source]#
Prepare the actual swap for three way trade.
- Parameters
check_balances (False) – Check on-chain balances that the account has enough tokens and raise exception if not.
uniswap (UniswapV2Deployment) –
target_pair (TradingPairIdentifier) –
intermediary_pair (TradingPairIdentifier) –
reserve_asset (AssetIdentifier) –
reserve_amount (int) –
max_slippage (float) –