Skip to content

Commit

Permalink
Merge pull request #669 from bancorprotocol/revert-662-remove-sei-and…
Browse files Browse the repository at this point in the history
…-tri-complete

Revert "removed Sei and multi_triangle_complete - temporarily"
  • Loading branch information
zavelevsky authored May 22, 2024
2 parents 4124c58 + 866417f commit 8c42d05
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export ETH_PRIVATE_KEY_BE_CAREFUL="0x123-USE-YOUR-OWN-PRIVATE-KEY-HERE"
export WEB3_FANTOM="FANTOM-API-KEY-HERE" // "public" can be used in place of a paid API key
export WEB3_MANTLE="MANTLE-API-KEY-HERE"
export WEB3_LINEA="LINEA-API-KEY-HERE" //
export WEB3_SEI="SEI-API-KEY-HERE" //

#******** For Development - not required to run bot ********#
export ETHERSCAN_TOKEN="ONLY_REQUIRED_IN_DEV"
Expand Down
2 changes: 2 additions & 0 deletions fastlane_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from .modes.pairwise_multi_pol import FindArbitrageMultiPairwisePol
from .modes.pairwise_single import FindArbitrageSinglePairwise
from .modes.triangle_multi import ArbitrageFinderTriangleMulti
from .modes.triangle_multi_complete import ArbitrageFinderTriangleMultiComplete
from .modes.triangle_single import ArbitrageFinderTriangleSingle
from .modes.triangle_bancor_v3_two_hop import ArbitrageFinderTriangleBancor3TwoHop
from .utils import num_format
Expand Down Expand Up @@ -109,6 +110,7 @@ class CarbonBot:
"b3_two_hop": ArbitrageFinderTriangleBancor3TwoHop,
"multi_pairwise_pol": FindArbitrageMultiPairwisePol,
"multi_pairwise_all": FindArbitrageMultiPairwiseAll,
"multi_triangle_complete": ArbitrageFinderTriangleMultiComplete,
}

class NoArbAvailable(Exception):
Expand Down
1 change: 1 addition & 0 deletions fastlane_bot/config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
"fantom": 5000,
"mantle": 0,
"linea": 0,
"sei": 0,
}
41 changes: 40 additions & 1 deletion fastlane_bot/config/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class ConfigNetwork(ConfigBase):
NETWORK_FANTOM = S.NETWORK_FANTOM
NETWORK_MANTLE = S.NETWORK_MANTLE
NETWORK_LINEA = S.NETWORK_LINEA
NETWORK_SEI = S.NETWORK_SEI

# FLAGS
#######################################################################################
Expand Down Expand Up @@ -316,7 +317,9 @@ def new(cls, network=None):
elif network == cls.NETWORK_MANTLE:
return _ConfigNetworkMantle(_direct=False)
elif network == cls.NETWORK_LINEA:
return _ConfigNetworkLinea(_direct=False)
return _ConfigNetworkLinea(_direct=False)
elif network == cls.NETWORK_SEI:
return _ConfigNetworkSei(_direct=False)
elif network == cls.NETWORK_TENDERLY:
return _ConfigNetworkTenderly(_direct=False)
else:
Expand Down Expand Up @@ -782,6 +785,42 @@ class _ConfigNetworkLinea(ConfigNetwork):
# Add any exchanges unique to the chain here
CHAIN_SPECIFIC_EXCHANGES = []

class _ConfigNetworkSei(ConfigNetwork):
"""
Fastlane bot config -- network [Base Mainnet]
"""

NETWORK = S.NETWORK_SEI
NETWORK_ID = "1" # TODO
NETWORK_NAME = "sei"
DEFAULT_PROVIDER = S.PROVIDER_ALCHEMY
RPC_ENDPOINT = "https://evm-rpc.arctic-1.seinetwork.io/" # TODO currently Sei devnet
WEB3_ALCHEMY_PROJECT_ID = os.environ.get("WEB3_SEI")

network_df = get_multichain_addresses(network=NETWORK_NAME)
FASTLANE_CONTRACT_ADDRESS = "0xC7Dd38e64822108446872c5C2105308058c5C55C" #TODO - UPDATE WITH Mainnet
MULTICALL_CONTRACT_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11"

CARBON_CONTROLLER_ADDRESS = "0x59f21012B2E9BA67ce6a7605E74F945D0D4C84EA" #TODO - UPDATE WITH Mainnet
CARBON_CONTROLLER_VOUCHER = "0xe4816658ad10bF215053C533cceAe3f59e1f1087" #TODO - UPDATE WITH Mainnet

NATIVE_GAS_TOKEN_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
WRAPPED_GAS_TOKEN_ADDRESS = "0x57eE725BEeB991c70c53f9642f36755EC6eb2139" # TODO confirm for Mainnet
NATIVE_GAS_TOKEN_SYMBOL = "SEI"
WRAPPED_GAS_TOKEN_SYMBOL = "WSEI"
STABLECOIN_ADDRESS = "0xace5f7Ea93439Af39b46d2748fA1aC19951c8d7C" #TODO USDC on devnet

IS_INJECT_POA_MIDDLEWARE = False
# Balancer
BALANCER_VAULT_ADDRESS = "0x7ccBebeb88696f9c8b061f1112Bb970158e29cA5" # # TODO Jellyswap on devnet

CHAIN_FLASHLOAN_TOKENS = {
"0x57eE725BEeB991c70c53f9642f36755EC6eb2139": "WSEI", #TODO confirm for Mainnet
"0xace5f7Ea93439Af39b46d2748fA1aC19951c8d7C": "USDC", #TODO confirm for Mainnet
}
# Add any exchanges unique to the chain here
CHAIN_SPECIFIC_EXCHANGES = []

class _ConfigNetworkTenderly(ConfigNetwork):
"""
Fastlane bot config -- network [Ethereum Tenderly]
Expand Down
1 change: 1 addition & 0 deletions fastlane_bot/config/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
NETWORK_CANTO = "canto"
NETWORK_FANTOM = "fantom"
NETWORK_LINEA = "linea"
NETWORK_SEI = "sei"
NETWORK_MANTLE = "mantle"
NETWORK_SCROLL = "scroll"
NETWORK_BSC = "binance_smart_chain"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exchange,address
4 changes: 4 additions & 0 deletions fastlane_bot/data/blockchain_data/sei/static_pool_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cid,strategy_id,last_updated,last_updated_block,descr,pair_name,exchange_name,fee,fee_float,address,anchor,tkn0_address,tkn1_address,tkn0_decimals,tkn1_decimals,exchange_id,tkn0_symbol,tkn1_symbol,timestamp,tkn0_balance,tkn1_balance,liquidity,sqrt_price_q96,tick,tick_spacing,exchange,pool_type,tkn0_weight,tkn1_weight,tkn2_address,tkn2_decimals,tkn2_symbol,tkn2_balance,tkn2_weight,tkn3_address,tkn3_decimals,tkn3_symbol,tkn3_balance,tkn3_weight,tkn4_address,tkn4_decimals,tkn4_symbol,tkn4_balance,tkn4_weight,tkn5_address,tkn5_decimals,tkn5_symbol,tkn5_balance,tkn5_weight,tkn6_address,tkn6_decimals,tkn6_symbol,tkn6_balance,tkn6_weight,tkn7_address,tkn7_decimals,tkn7_symbol,tkn7_balance,tkn7_weight
0x1422169ab760ea6994358267b7d3783e8e7fa55c6a74b365b3fd3d17cbf4c6f1,0,,2354,dragonswap 0x027D2E627209f1cebA52ADc8A5aFE9318459b44B/0x7b75109369ACb528d9fa989E227812a6589712b9,0x027D2E627209f1cebA52ADc8A5aFE9318459b44B/0x7b75109369ACb528d9fa989E227812a6589712b9,dragonswap,0.003,0.003,0x01A34Dfa104F020FEE739268679338169945D5B1,,0x027D2E627209f1cebA52ADc8A5aFE9318459b44B,0x7b75109369ACb528d9fa989E227812a6589712b9,18,18,3,WSEI,DSWAP,0,0,0,,,,,dragonswap,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
0xbfd9612b2cb8035908dff18c040f64de75999cefd1020b5ce8a2e533c2ecd5dc,0,,2354,dragonswap 0x027D2E627209f1cebA52ADc8A5aFE9318459b44B/0xace5f7Ea93439Af39b46d2748fA1aC19951c8d7C,0x027D2E627209f1cebA52ADc8A5aFE9318459b44B/0xace5f7Ea93439Af39b46d2748fA1aC19951c8d7C,dragonswap,0.003,0.003,0x85CB6BFd781e1f42f4E79Efb6bf1F1fEfE4E9732,,0x027D2E627209f1cebA52ADc8A5aFE9318459b44B,0xace5f7Ea93439Af39b46d2748fA1aC19951c8d7C,18,6,3,WSEI,USDC,0,0,0,,,,,dragonswap,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
0xe3aead757d877a15316e4896d5c5ab7639adbcba1ff76e3434b4e0af90f6225e,0,,2354,dragonswap 0xace5f7Ea93439Af39b46d2748fA1aC19951c8d7C/0xF983afa393199D6902a1Dd04f8E93465915ffD8B,0xace5f7Ea93439Af39b46d2748fA1aC19951c8d7C/0xF983afa393199D6902a1Dd04f8E93465915ffD8B,dragonswap,0.003,0.003,0x72A788B0A83e18ce1757171321E82c03e4351498,,0xace5f7Ea93439Af39b46d2748fA1aC19951c8d7C,0xF983afa393199D6902a1Dd04f8E93465915ffD8B,6,6,3,USDC,USDT,0,0,0,,,,,dragonswap,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
9 changes: 9 additions & 0 deletions fastlane_bot/data/blockchain_data/sei/tokens.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
address,decimals,symbol
0x26841a0A5D958B128209F4ea9a1DD7E61558c330,18,WSEI
0xace5f7Ea93439Af39b46d2748fA1aC19951c8d7C,6,USDC
0x027D2E627209f1cebA52ADc8A5aFE9318459b44B,18,WSEI
0x7b75109369ACb528d9fa989E227812a6589712b9,18,DSWAP
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,18,SEI
0x9e7A8e558Ce582511f4104465a886b7bEfBC146b,18,JLY
0x57eE725BEeB991c70c53f9642f36755EC6eb2139,18,WSEI
0xF983afa393199D6902a1Dd04f8E93465915ffD8B,6,USDT
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exchange,address
dragonswap,0x01A34Dfa104F020FEE739268679338169945D5B1
dragonswap,0x85CB6BFd781e1f42f4E79Efb6bf1F1fEfE4E9732
dragonswap,0x38BcEBb9A3fbF05B0Ab7ce9b485c9669578409fE
dragonswap,0x72A788B0A83e18ce1757171321E82c03e4351498
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exchange,address
4 changes: 4 additions & 0 deletions fastlane_bot/data/multichain_addresses.csv
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,7 @@ sushiswap_v3,thundercore,uniswap_v3,0xc35DADB65012eC5796536bD9864eD8773aBc74C4,0
pancakeswap_v3,zkevm,uniswap_v3,0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865,0x1b81D678ffb9C0263b24A97847620C99d213eB14,,,
pancakeswap_v3,zksync,uniswap_v3,0x1BB72E0CbbEA93c08f535fc7856E0338D7F7a8aB,0xD70C70AD87aa8D45b8D59600342FB3AEe76E3c68,,,
xfai_v0,linea,solidly_v2,0xa5136eAd459F0E61C99Cec70fe8F5C24cF3ecA26,0xD538be6e9026C13D130C9e17d509E69C8Bb0eF33,,222864,
carbon_v1,sei,carbon_v1,0x59f21012B2E9BA67ce6a7605E74F945D0D4C84EA,0x59f21012B2E9BA67ce6a7605E74F945D0D4C84EA,,17658678,
dragonswap,sei,uniswap_v2,0x5D370a6189F89603FaB67e9C68383e63F7B6A262,0x2346d3A6fb18Ff3ae590Ea31d9e41E6AB8c9f5EB,0.003,1008775,
jellyswap,sei,balancer,BALANCER_VAULT_ADDRESS,0x7ccBebeb88696f9c8b061f1112Bb970158e29cA5,0,222832,
uniswap_v3,sei,uniswap_v3,0x0000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000,,1,
83 changes: 83 additions & 0 deletions fastlane_bot/modes/triangle_multi_complete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""
Defines the Triangular arbitrage finder class
[DOC-TODO-OPTIONAL-longer description in rst format]
---
(c) Copyright Bprotocol foundation 2023-24.
All rights reserved.
Licensed under MIT.
"""
from typing import List, Any, Tuple, Union

from fastlane_bot.modes.base_triangle import ArbitrageFinderTriangleBase
from fastlane_bot.tools.cpc import CPCContainer
from fastlane_bot.tools.optimizer import MargPOptimizer


class ArbitrageFinderTriangleMultiComplete(ArbitrageFinderTriangleBase):
"""
Triangular arbitrage finder mode
"""

arb_mode = "multi_triangle_complete"

def find_arbitrage(self, candidates: List[Any] = None, ops: Tuple = None, best_profit: float = 0, profit_src: float = 0) -> Union[List, Tuple]:
"""
see base.py
"""

if candidates is None:
candidates = []

combos = self.get_comprehensive_triangles(self.flashloan_tokens, self.CCm)

for src_token, miniverse in combos:
try:
CC_cc = CPCContainer(miniverse)
O = MargPOptimizer(CC_cc)
pstart = self.build_pstart(CC_cc, CC_cc.tokens(), src_token)
r = O.optimize(src_token, params=dict(pstart=pstart))
trade_instructions_dic = r.trade_instructions(O.TIF_DICTS)
if trade_instructions_dic is None or len(trade_instructions_dic) < 3:
# Failed to converge
continue
trade_instructions_df = r.trade_instructions(O.TIF_DFAGGR)
trade_instructions = r.trade_instructions()

except Exception as e:
self.ConfigObj.logger.info(f"[triangle multi] {e}")
continue
profit_src = -r.result

# Get the cids
cids = [ti["cid"] for ti in trade_instructions_dic]

# Calculate the profit
profit = self.calculate_profit(src_token, profit_src, self.CCm, cids)
if str(profit) == "nan":
self.ConfigObj.logger.debug("profit is nan, skipping")
continue

# Handle candidates based on conditions
candidates += self.handle_candidates(
best_profit,
profit,
trade_instructions_df,
trade_instructions_dic,
src_token,
trade_instructions,
)

# Find the best operations
best_profit, ops = self.find_best_operations(
best_profit,
ops,
profit,
trade_instructions_df,
trade_instructions_dic,
src_token,
trade_instructions,
)

return candidates if self.result == self.AO_CANDIDATES else ops
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ def run(mgr, args, tenderly_uri=None) -> None:
"multi_triangle",
"b3_two_hop",
"multi_pairwise_pol",
"multi_pairwise_all"
"multi_pairwise_all",
"multi_triangle_complete"
],
)
parser.add_argument(
Expand Down Expand Up @@ -698,7 +699,7 @@ def run(mgr, args, tenderly_uri=None) -> None:
"--blockchain",
default="ethereum",
help="A blockchain from the list. Blockchains not in this list do not have a deployed Fast Lane contract and are not supported.",
choices=["ethereum", "coinbase_base", "fantom", "mantle", "linea"],
choices=["ethereum", "coinbase_base", "fantom", "mantle", "linea", "sei"],
)
parser.add_argument(
"--pool_data_update_frequency",
Expand Down
10 changes: 9 additions & 1 deletion run_blockchain_terraformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async def gather():
FANTOM = "fantom"
MANTLE = "mantle"
LINEA = "linea"
SEI = "sei"

coingecko_network_map = {
"ethereum": "ethereum",
Expand All @@ -66,6 +67,7 @@ async def gather():
"cosmos": "cosmos",
"kava": "kava",
"mantle": "mantle",
"sei": "sei",
}

BLOCK_CHUNK_SIZE_MAP = {
Expand All @@ -78,6 +80,7 @@ async def gather():
"fantom": 5000,
"mantle": 0,
"linea": 0,
"sei": 0,
}

ALCHEMY_KEY_DICT = {
Expand All @@ -90,6 +93,7 @@ async def gather():
"fantom": "WEB3_FANTOM",
"mantle": "WEB3_MANTLE",
"linea": "WEB3_LINEA",
"sei": "WEB3_SEI",
}

ALCHEMY_RPC_LIST = {
Expand All @@ -102,6 +106,7 @@ async def gather():
"fantom": "https://fantom.blockpi.network/v1/rpc/",
"mantle": "https://rpc.mantle.xyz/",
"linea": "https://rpc.linea.build/",
"sei": "https://evm-rpc.arctic-1.seinetwork.io/", # TODO update with mainnet
}

BALANCER_SUBGRAPH_CHAIN_URL = {
Expand All @@ -112,7 +117,9 @@ async def gather():
"optimism": "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-optimism-v2",
"coinbase_base": "https://api.studio.thegraph.com/query/24660/balancer-base-v2/version/latest",
"avalanche": "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-avalanche-v2",
"fantom": "https://api.thegraph.com/subgraphs/name/beethovenxfi/beethovenx"
"fantom": "https://api.thegraph.com/subgraphs/name/beethovenxfi/beethovenx",
"sei": "https://thegraph.dev.mvpworkshop.co/subgraphs/name/jelly" # TODO verify this for mainnet

}

BANCOR_V2_NAME = "bancor_v2"
Expand Down Expand Up @@ -1075,3 +1082,4 @@ def terraform_blockchain(network_name: str):
#terraform_blockchain(network_name=FANTOM)
#terraform_blockchain(network_name=MANTLE)
#terraform_blockchain(network_name=LINEA)
#terraform_blockchain(network_name=SEI)

0 comments on commit 8c42d05

Please sign in to comment.