VaultRouting#
API documentation for tradeexecutor.ethereum.vault.vault_routing.VaultRouting Python class in Trading Strategy framework.
- class VaultRouting[source]#
- Bases: - RoutingModel- ERC-4626 routing. - Do trades for ERC-4626 and other vaults 
 - __init__(reserve_token_address, profitability_estimation_lookback_window=datetime.timedelta(days=7), epsilon=Decimal('9.99999999999999954748111825886258685613938723690807819366455078125E-7'), redeem_epsilon=0.025)[source]#
- Parameters:
- addresses – - Defines router smart contracts to be used with each DEX. - Each Uniswap v2 is uniquely identified by its factory contract. Addresses always lowercase. Factory Router map - For Uniswap V3, addresses is a dict of factory, router, position_manager, and quoter addresses 
- allowed_intermediary_pairs – - Quote token address -> pair smart contract address mapping. - Because we hold our reserves only in one currecy e.g. BUSD and we want to trade e.g. Cake/BNB pairs, we need to whitelist BNB as an allowed intermediary token. This makes it possible to do BUSD -> BNB -> Cake trade. This set is the list of pair smart contract addresses that are allowed to be used as a hop. 
- chain_id – Store the chain id for which these routes were generated for. 
- reserve_token_address (str) – Token address of our reserve currency. Relevent for buy/sell routing. Lowercase. 
 
 
 - Methods - __init__(reserve_token_address[, ...])- param addresses:
 - check_enter_position(routing_state, trading_pair)- Check if a pair is tradeable. - convert_address_dict_to_lower(address_dict)- Convert all key addresses to lowercase to avoid mix up with Ethereum address checksums - create_routing_state(universe, execution_details)- Create a new routing state for this cycle. - deposit_or_redeem(state, routing_state, trade)- Prepare vault flow transactions. - get_default_trading_fee()- Get the trading/LP fee applied to all trading pairs. - get_reserve_asset(pair_universe)- Translate our reserve token address tok an asset description. - "Checks the integrity of the routing. - pre_trade_assertions(reserve_asset_amount, ...)- Some basic assertions made at the beginning of the trade() method on child class. - route_pair(pair_universe, trading_pair[, ...])- Return Uniswap routing information (path components) for a trading pair. - settle_trade(web3, state, trade, receipts[, ...])- Post-trade executed price analysis. - setup_trades(state, routing_state, trades[, ...])- See test_velvet_e2e for tests. - __init__(reserve_token_address, profitability_estimation_lookback_window=datetime.timedelta(days=7), epsilon=Decimal('9.99999999999999954748111825886258685613938723690807819366455078125E-7'), redeem_epsilon=0.025)[source]#
- Parameters:
- addresses – - Defines router smart contracts to be used with each DEX. - Each Uniswap v2 is uniquely identified by its factory contract. Addresses always lowercase. Factory Router map - For Uniswap V3, addresses is a dict of factory, router, position_manager, and quoter addresses 
- allowed_intermediary_pairs – - Quote token address -> pair smart contract address mapping. - Because we hold our reserves only in one currecy e.g. BUSD and we want to trade e.g. Cake/BNB pairs, we need to whitelist BNB as an allowed intermediary token. This makes it possible to do BUSD -> BNB -> Cake trade. This set is the list of pair smart contract addresses that are allowed to be used as a hop. 
- chain_id – Store the chain id for which these routes were generated for. 
- reserve_token_address (str) – Token address of our reserve currency. Relevent for buy/sell routing. Lowercase. 
 
 
 - create_routing_state(universe, execution_details)[source]#
- Create a new routing state for this cycle. - Parameters:
- execution_details (dict) – A dict of whatever connects live execution to routing. 
- universe (StrategyExecutionUniverse) – 
 
- Return type:
 
 - perform_preflight_checks_and_logging(pair_universe)[source]#
- “Checks the integrity of the routing. - Called from check-wallet to see our routing and balances are good 
 - Parameters:
- pair_universe (PandasPairUniverse) – 
 
 - deposit_or_redeem(state, routing_state, trade)[source]#
- Prepare vault flow transactions. - Parameters:
- state (State) – 
- routing_state (VaultRoutingState) – 
- trade (TradeExecution) – 
 
- Return type:
- list[tradeexecutor.state.blockhain_transaction.BlockchainTransaction] 
 
 - setup_trades(state, routing_state, trades, check_balances=False, rebroadcast=False)[source]#
- See test_velvet_e2e for tests. - Error codes: - Revert reason: execution reverted: custom error 0xe2f23246 
- 2Po: Enso slippage error, or out of funds 
 - Parameters:
- state (State) – 
- routing_state (VaultRoutingState) – 
- trades (list[tradeexecutor.state.trade.TradeExecution]) – 
 
 
 - settle_trade(web3, state, trade, receipts, stop_on_execution_failure=False)[source]#
- Post-trade executed price analysis. - Read on-chain data about the tx receipt of Enso swap 
 - Parameters:
- state (State) – Strategy state 
- web3 (Web3) – Web3 connection. 
- trade (TradeExecution) – Trade executed in this execution batch 
- Blockchain receipts we received in this execution batch. - Hash -> receipt mapping. 
- stop_on_execution_failure – - Raise an error if the trade failed. - Used in unit testing.