Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Oct 10, 2024
2 parents 72fd5eb + 2a501e7 commit 49642f1
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 10 deletions.
60 changes: 56 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ packages = [
{ include = "tradeexecutor" },
]
[tool.poetry.dependencies]
python = ">=3.11,<=3.12"
python = ">=3.10,<=3.12"


# Use these during development
Expand Down
10 changes: 9 additions & 1 deletion tradeexecutor/ethereum/ethereum_protocol_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,16 @@ def create_uniswap_v2_adapter(
TradeRouting.quickswap_usdc,
ReserveCurrency.usdc,
)
elif exchange.exchange_slug == "sushi":
routing_model = create_uniswap_v2_compatible_routing(
TradeRouting.sushi_usdc,
ReserveCurrency.usdc
)
else:
raise NotImplementedError(f"Exchange not yet supported: {exchange}")
routing_model = create_uniswap_v2_compatible_routing(
TradeRouting.uniswap_v2_usdc,
ReserveCurrency.usdc
)

pricing_model = UniswapV2LivePricing(
web3,
Expand Down
64 changes: 64 additions & 0 deletions tradeexecutor/ethereum/routing_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,60 @@ def get_quickswap_default_routing_parameters(
}


def get_sushi_default_routing_parameters(
reserve_currency: ReserveCurrency,
) -> RoutingData:
"""Generate routing using Sushi router. For Polygon chain.
TODO: Polish the interface of this function when we have more strategies
"""
if reserve_currency == ReserveCurrency.usdc:
# https://tradingstrategy.ai/trading-view/ethereum/tokens/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
reserve_token_address = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48".lower()

# For three way trades, which pools we can use
allowed_intermediary_pairs = {
# Route WETH through WETH/USDC pool,
# https://tradingstrategy.ai/trading-view/ethereum/sushi/eth-usdc
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": "0x397ff1542f962076d0bfe58ea045ffa2d347aca0",
}
elif reserve_currency == ReserveCurrency.usdt:
# https://tradingstrategy.ai/trading-view/ethereum/tokens/0xdac17f958d2ee523a2206206994597c13d831ec7
reserve_token_address = "0xdac17f958d2ee523a2206206994597c13d831ec7".lower()

# For three way trades, which pools we can use
allowed_intermediary_pairs = {
# Route WETH through WETH/USDT pool,
# https://tradingstrategy.ai/trading-view/ethereum/sushi/eth-usdt
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": "0x06da0fd433c1a5d7a4faa01111c044910a184553",
}
else:
raise NotImplementedError()

# Allowed exchanges as factory -> router pairs,
# by their smart contract addresses
# init_code_hash: https://etherscan.io/address/0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F#code#L103
factory_router_map = {
"0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac": (
"0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F",
"e18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303",
)
}

return {
"chain_id": ChainId.ethereum,
"factory_router_map": factory_router_map,
"allowed_intermediary_pairs": allowed_intermediary_pairs,
"reserve_token_address": reserve_token_address,
"quote_token_addresses": {
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", # USDC
"0xdac17f958d2ee523a2206206994597c13d831ec7", # USDT
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", # WETH
},
"trading_fee": UNISWAP_V2_FEE,
}


def get_trader_joe_default_routing_parameters(
reserve_currency: ReserveCurrency,
) -> RoutingData:
Expand Down Expand Up @@ -544,6 +598,8 @@ def get_uniswap_v2_compatible_routing_types():
TradeRouting.quickswap_dai,
TradeRouting.trader_joe_usdt,
TradeRouting.trader_joe_usdc,
TradeRouting.sushi_usdc,
TradeRouting.sushi_usdt,
}


Expand All @@ -565,6 +621,7 @@ def validate_reserve_currency(
TradeRouting.pancakeswap_usdc,
TradeRouting.quickswap_usdc,
TradeRouting.trader_joe_usdc,
TradeRouting.sushi_usdc,
TradeRouting.uniswap_v2_usdc,
TradeRouting.uniswap_v3_usdc,
TradeRouting.uniswap_v3_usdc_poly,
Expand All @@ -582,6 +639,7 @@ def validate_reserve_currency(
TradeRouting.pancakeswap_usdt,
TradeRouting.quickswap_usdt,
TradeRouting.trader_joe_usdt,
TradeRouting.sushi_usdt,
TradeRouting.uniswap_v2_usdt,
TradeRouting.uniswap_v3_usdt,
TradeRouting.uniswap_v3_usdt_poly,
Expand Down Expand Up @@ -673,6 +731,12 @@ def create_uniswap_v2_compatible_routing(
}:
# quickswap on polygon
params = get_quickswap_default_routing_parameters(reserve_currency)
elif routing_type in {
TradeRouting.sushi_usdc,
TradeRouting.sushi_usdt,
}:
# sushi on ethereum mainnet
params = get_sushi_default_routing_parameters(reserve_currency)
elif routing_type in {TradeRouting.trader_joe_usdc, TradeRouting.trader_joe_usdt}:
# trader joe on avalanche
params = get_trader_joe_default_routing_parameters(reserve_currency)
Expand Down
18 changes: 14 additions & 4 deletions tradeexecutor/strategy/default_routing_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ class TradeRouting(enum.Enum):
#: - Open positions with WAVAX quote token.
trader_joe_usdt = "trader_joe_usdt"

#: Two or three legged trades on Sushiswap on Ethereum mainnet
#:
#: - Open positions with USDC quote token.
#:
#: - Open positions with WETH quote token.
sushi_usdc = "sushi_usdc"

#: Two or three legged trades on Sushiswap on Ethereum mainnet
#:
#: - Open positions with USDT quote token.
#:
#: - Open positions with WETH quote token.
sushi_usdt = "sushi_usdt"

#: Two or three legged trades on Uniswap v2 on Ethereum mainnet
#:
#: - Open positions with USDC quote token.
Expand Down Expand Up @@ -114,17 +128,13 @@ class TradeRouting(enum.Enum):
#: - Open positions with USDT quote token.
#:
#: - Open positions with WETH quote token.
#:
#: - Open positions with USDC quote token.
uniswap_v3_usdt = "uniswap_v3_usdt"

#: Two or three legged trades on Uniswap v3 on Ethereum mainnet
#:
#: - Open positions with DAI quote token.
#:
#: - Open positions with WETH quote token.
#:
#: - Open positions with USDC quote token.
uniswap_v3_dai = "uniswap_v3_dai"

#: Two or three legged trades on Uniswap v3 on Ethereum mainnet
Expand Down

0 comments on commit 49642f1

Please sign in to comment.