Skip to content

Commit

Permalink
Merge pull request #542 from bancorprotocol/Class-TxHelpers-Revision-…
Browse files Browse the repository at this point in the history
…April-11

Class TxHelpers Revision (April 11)
  • Loading branch information
barakman authored Apr 19, 2024
2 parents 464ad61 + 292dd58 commit 765fdc1
Show file tree
Hide file tree
Showing 21 changed files with 304 additions and 1,570 deletions.
448 changes: 101 additions & 347 deletions fastlane_bot/bot.py

Large diffs are not rendered by default.

26 changes: 11 additions & 15 deletions fastlane_bot/config/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,25 +263,10 @@ class ConfigNetwork(ConfigBase):

# DEFAULT VALUES SECTION
#######################################################################################
UNIV3_FEE_LIST = [8, 10, 40, 80, 100, 250, 300, 450, 500, 1000, 2500, 3000, 10000]
MIN_BNT_LIQUIDITY = 2_000_000_000_000_000_000
DEFAULT_GAS = 950_000
DEFAULT_GAS_PRICE = 0
DEFAULT_GAS_PRICE_OFFSET = 1.09
DEFAULT_GAS_SAFETY_OFFSET = 25_000
DEFAULT_POLL_INTERVAL = 12
DEFAULT_BLOCKTIME_DEVIATION = 13 * 500 * 100 # 10 block time deviation
DEFAULT_MAX_SLIPPAGE = Decimal("1") # 1%
_PROJECT_PATH = os.path.normpath(f"{os.getcwd()}") # TODO: FIX THIS
DEFAULT_CURVES_DATAFILE = os.path.normpath(
f"{_PROJECT_PATH}/carbon/data/curves.csv.gz"
)
CARBON_STRATEGY_CHUNK_SIZE = 200
Q96 = Decimal("2") ** Decimal("96")
DEFAULT_TIMEOUT = 60
CARBON_FEE = Decimal("0.002")
BANCOR_V3_FEE = Decimal("0.0")
DEFAULT_REWARD_PERCENT = Decimal("0.5")
LIMIT_BANCOR3_FLASHLOAN_TOKENS = True
DEFAULT_MIN_PROFIT_GAS_TOKEN = Decimal("0.02")

Expand All @@ -307,6 +292,17 @@ class ConfigNetwork(ConfigBase):
GAS_TKN_IN_FLASHLOAN_TOKENS = None
IS_NO_FLASHLOAN_AVAILABLE = False

# HOOKS
#######################################################################################
@staticmethod
def gas_strategy(web3):
gas_price = web3.eth.gas_price # send `eth_gasPrice` request
max_priority_fee = web3.eth.max_priority_fee # send `eth_maxPriorityFeePerGas` request
return {
"maxFeePerGas": gas_price + max_priority_fee,
"maxPriorityFeePerGas": max_priority_fee
}

@classmethod
def new(cls, network=None):
"""
Expand Down
73 changes: 17 additions & 56 deletions fastlane_bot/config/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,51 +112,20 @@ def __init__(self, network: ConfigNetwork, **kwargs):
self.connection.connect_network(network.IS_INJECT_POA_MIDDLEWARE)
self.w3 = self.connection.web3
self.w3_async = self.connection.w3_async
self.LOCAL_ACCOUNT = self.w3.eth.account.from_key(ETH_PRIVATE_KEY_BE_CAREFUL)


if network.NETWORK in [N.NETWORK_BASE, N.NETWORK_ETHEREUM, N.NETWORK_FANTOM, N.NETWORK_MANTLE, N.NETWORK_LINEA]:
self.CARBON_CONTROLLER_CONTRACT = self.w3.eth.contract(
address=network.CARBON_CONTROLLER_ADDRESS,
abi=CARBON_CONTROLLER_ABI,
)
self.BANCOR_ARBITRAGE_CONTRACT = self.w3.eth.contract(
address=self.w3.to_checksum_address(network.FASTLANE_CONTRACT_ADDRESS),
abi=FAST_LANE_CONTRACT_ABI,
)

if network.GAS_ORACLE_ADDRESS:
self.GAS_ORACLE_CONTRACT = self.w3_async.eth.contract(
address=network.GAS_ORACLE_ADDRESS,
abi=GAS_ORACLE_ABI
)

self.BANCOR_ARBITRAGE_CONTRACT = self.w3.eth.contract(
address=self.w3.to_checksum_address(N.FASTLANE_CONTRACT_ADDRESS),
abi=FAST_LANE_CONTRACT_ABI,
)

if network.NETWORK in N.NETWORK_ETHEREUM:
self.BANCOR_NETWORK_INFO_CONTRACT = self.w3.eth.contract(
address=network.BANCOR_V3_NETWORK_INFO_ADDRESS,
abi=BANCOR_V3_NETWORK_INFO_ABI,
if N.GAS_ORACLE_ADDRESS:
self.GAS_ORACLE_CONTRACT = self.w3.eth.contract(
address=N.GAS_ORACLE_ADDRESS,
abi=GAS_ORACLE_ABI,
)
self.ARB_CONTRACT_VERSION = self.BANCOR_ARBITRAGE_CONTRACT.caller.version()

else:
self.CARBON_CONTROLLER_CONTRACT = None
self.ARB_CONTRACT_VERSION = 10

if self.BANCOR_ARBITRAGE_CONTRACT is not None:
try:
(
reward_percent,
max_profit,
) = self.BANCOR_ARBITRAGE_CONTRACT.caller.rewards()
self.ARB_REWARD_PERCENTAGE = str(int(reward_percent) / 1000000)
self.ARB_MAX_PROFIT = 1000000 # This is no longer used
except:
self.ARB_REWARD_PERCENTAGE = "0.5"
else:
self.ARB_REWARD_PERCENTAGE = "0.5"

self.EXPECTED_GAS_MODIFIER = "0.85"
self.ARB_CONTRACT_VERSION = self.BANCOR_ARBITRAGE_CONTRACT.caller.version()
self.ARB_REWARDS_PPM = self.BANCOR_ARBITRAGE_CONTRACT.caller.rewards()[0]


class _ConfigProviderTenderly(ConfigProvider):
Expand All @@ -182,26 +151,20 @@ def __init__(self, network: ConfigNetwork, **kwargs):
)
self.connection.connect_network()
self.w3 = self.connection.web3
self.LOCAL_ACCOUNT = self.w3.eth.account.from_key(ETH_PRIVATE_KEY_BE_CAREFUL)

self.BANCOR_NETWORK_INFO_CONTRACT = self.w3.eth.contract(
address=N.BANCOR_V3_NETWORK_INFO_ADDRESS,
abi=BANCOR_V3_NETWORK_INFO_ABI,
)
self.CARBON_CONTROLLER_CONTRACT = self.w3.eth.contract(
address=N.CARBON_CONTROLLER_ADDRESS,
abi=CARBON_CONTROLLER_ABI,
)
self.BANCOR_ARBITRAGE_CONTRACT = self.w3.eth.contract(
address=self.w3.to_checksum_address(N.FASTLANE_CONTRACT_ADDRESS),
abi=FAST_LANE_CONTRACT_ABI,
)
self.ARB_CONTRACT_VERSION = self.BANCOR_ARBITRAGE_CONTRACT.caller.version()

reward_percent, max_profit = self.BANCOR_ARBITRAGE_CONTRACT.caller.rewards()
if N.GAS_ORACLE_ADDRESS:
self.GAS_ORACLE_CONTRACT = self.w3.eth.contract(
address=N.GAS_ORACLE_ADDRESS,
abi=GAS_ORACLE_ABI,
)

self.ARB_REWARD_PERCENTAGE = str(int(reward_percent) / 1000000)
self.ARB_MAX_PROFIT = str(int(max_profit) / (10**18))
self.ARB_CONTRACT_VERSION = self.BANCOR_ARBITRAGE_CONTRACT.caller.version()
self.ARB_REWARDS_PPM = self.BANCOR_ARBITRAGE_CONTRACT.caller.rewards()[0]


class _ConfigProviderInfura(ConfigProvider):
Expand Down Expand Up @@ -232,6 +195,4 @@ def __init__(self, network: ConfigNetwork, **kwargs):
# raise NotImplementedError("Infura not implemented")
self.connection = None
self.w3 = None
self.BANCOR_NETWORK_INFO_CONTRACT = None
self.CARBON_CONTROLLER_CONTRACT = None
self.BANCOR_ARBITRAGE_CONTRACT = None
Loading

0 comments on commit 765fdc1

Please sign in to comment.