Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify class TxHelpers #478

Closed
wants to merge 105 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
2d54504
Cleanup
Mar 22, 2024
4b96bf6
Cleanup
Mar 22, 2024
6b35d93
Remove unused class `TxHelpersBase`
Mar 22, 2024
c767bfe
Cleanup
Mar 22, 2024
d54fc63
Rename internal function `build_transaction` to `_build_transaction`
Mar 22, 2024
0f30ad2
Fix return-value type
Mar 22, 2024
794efb0
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
Mar 22, 2024
fbed797
Remove internal function `get_nonce`, and reduce the number of times …
Mar 22, 2024
6684793
Cleanup
Mar 22, 2024
332ac87
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
Mar 22, 2024
bd6b211
Cleanup
Mar 22, 2024
041e5a1
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
Mar 23, 2024
3cf7eae
Revise the token-approval method, and move it from utils to TxHelpers
Mar 23, 2024
2747b5d
Improve the `check_and_approve_tokens` method
Mar 23, 2024
303dd23
Improve the `check_and_approve_tokens` method
Mar 23, 2024
d5f665d
Cleanup
Mar 23, 2024
dc78426
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
Mar 23, 2024
6343554
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
Mar 23, 2024
b33af5f
Minor cleanup
Mar 23, 2024
c86fd6f
Cleanup
Mar 23, 2024
aa3026e
Improve access-list handling
Mar 23, 2024
cce80c0
Fix float calculation to int
Mar 24, 2024
883b7ba
Cleanup
Mar 24, 2024
8ad019f
Cleanup
Mar 25, 2024
7cdb448
Fix function `_build_transaction`
Mar 25, 2024
ab47c05
Fix TxHelpers
Mar 25, 2024
16596a3
Fix TxHelpers
Mar 25, 2024
aa67531
Cleanup
Mar 25, 2024
aa248dd
Cleanup
Mar 25, 2024
45f43f9
Cleanup
Mar 25, 2024
b9adcc5
Improvements
Mar 25, 2024
7918250
Cleanup
Mar 25, 2024
3691bcf
Fix rewards handling
Mar 25, 2024
0890a93
Minor
Mar 25, 2024
ad0deab
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
Mar 25, 2024
d352435
nothing
Mar 25, 2024
bd18170
Improve logging
Mar 25, 2024
a5a5ddb
Improve the `txhelpers` module
Mar 26, 2024
c47290a
Fix the `last_updated_block` issue
Mar 26, 2024
0901308
Improve the `txhelpers` module
Mar 26, 2024
12cddb2
Improve the `txhelpers` module
Mar 26, 2024
39a854d
Minor
Mar 26, 2024
e14395c
Improve documentation
Mar 27, 2024
4b24b09
Remove the `submit_handler` module, which is used only for submitting…
Mar 27, 2024
a4d1e1a
Cleanup
Mar 27, 2024
ad03e31
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
Mar 28, 2024
e56d9ba
Undo temporary fix committed by mistake as part of the manual merge
Mar 28, 2024
b7cc7ed
Fix the use of constants
Mar 28, 2024
3d91fe6
Variable renaming
Mar 28, 2024
a0f3aa4
Variable renaming
Mar 28, 2024
9335789
Fix usage of the TxHelpers object
Mar 31, 2024
2337739
Fix `EXPECTED_GAS_MODIFIER` from string to number
Mar 31, 2024
9e42d21
Update web3.py version from 6.11.2 to 6.16.0
Mar 31, 2024
c7216e0
1. Fix access-list handling
Mar 31, 2024
3157010
Minor
Mar 31, 2024
a7ac82e
Improve gas-related settings
Apr 1, 2024
d989a3c
Revert "Improve gas-related settings"
Apr 1, 2024
663df65
Improve gas-related settings
Apr 1, 2024
d4c03aa
Remove unused `import` statement
Apr 1, 2024
046f993
Fix gas-related settings again
Apr 1, 2024
f4eb4c4
Minor
Apr 1, 2024
df7ae1c
Simplify gas-fee scheme
Apr 1, 2024
f5f2bd8
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
Apr 1, 2024
3ac50e0
Remove legacy-transactions support
Apr 2, 2024
129f7b7
Remove redundant code
Apr 2, 2024
eda372d
Minor
Apr 2, 2024
bd42ff6
Semantic
Apr 2, 2024
3ddd22d
Minor
Apr 2, 2024
6f5a097
Fix the handling of Tenderly and Ethereum networks
Apr 2, 2024
c0021f1
Minor
Apr 2, 2024
0b99550
Remove the hard-coded BINANCE wallet
Apr 2, 2024
4859156
Semantic
Apr 2, 2024
15c5621
Remove unneeded code if `bot.run_single_mode`
Apr 2, 2024
2045ed4
Improve error-handling
Apr 2, 2024
c269a4e
Create the Gas Oracle contract using a regular web3 object instead of…
Apr 2, 2024
e1c06f0
Improve error-handling (return gracefully when `_build_transaction` f…
Apr 2, 2024
322d076
Improve `TxHelpers` structure
Apr 3, 2024
cf3f297
Minor
Apr 3, 2024
e252683
Minor
Apr 3, 2024
eb8b48e
Cleanup provider.py:
Apr 3, 2024
d2086f5
Cleanup provider.py
Apr 3, 2024
47f9ba7
Undo previous change in tokens.csv committed by mistake
Apr 3, 2024
5a8c8ca
Set function `_send_private_transaction` to return a string
Apr 3, 2024
e5dce66
Fix type hinting
Apr 3, 2024
0f67e76
Send the value of `maxBlockNumber` as a hex-encoded string
Apr 3, 2024
c9fa7a7
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
Apr 4, 2024
7772ead
Fix documentation
Apr 4, 2024
f32ba55
Ensure that the returned `tx_hash` is of typer `str`
Apr 5, 2024
0727941
Fix `tx_hash` comparison
Apr 5, 2024
d72c5ee
Improve logging
Apr 5, 2024
b252b5b
Fix arb contract version reading
Apr 5, 2024
cab6c3f
Fix function `_send_private_transaction`
Apr 6, 2024
d7164e9
Improve the process of building a transaction
Apr 7, 2024
2f8bd87
Undo the most recent fix in provider.py, as the problem appears to be…
Apr 7, 2024
d2ba08d
Improve documentation
Apr 7, 2024
9de5bda
Set the transaction's `maxFeePerGas` and `maxPriorityFeePerGas` attri…
Apr 7, 2024
35ea534
Remove unused constants
Apr 7, 2024
eaa1510
Fix the writing of the tx hash to a file in the logging_path directory
Apr 7, 2024
182f66a
Minor
Apr 7, 2024
0c9f5d3
Add a user-configurable gas-strategy hook function
Apr 8, 2024
81ae405
Fix documentation
Apr 8, 2024
8e74338
Move the `GAS_STRATEGY` implementation to the network module
Apr 9, 2024
46cfba0
Fix documentation
Apr 9, 2024
3309a77
Fix the `gas_strategy` infrastructure
Apr 9, 2024
006861b
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions fastlane_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
from fastlane_bot.helpers import (
TxRouteHandler,
TxHelpers,
TxHelpersBase,
TradeInstruction,
Univ3Calculator,
add_wrap_or_unwrap_trades_to_route,
Expand Down Expand Up @@ -93,7 +92,7 @@ class CarbonBotBase:
the database manager.
TxRouteHandlerClass
ditto (default: TxRouteHandler).
TxHelpersClass: class derived from TxHelpersBase
barakman marked this conversation as resolved.
Show resolved Hide resolved
TxHelpersClass:
ditto (default: TxHelpers).

"""
Expand Down Expand Up @@ -128,9 +127,6 @@ def __post_init__(self):

if self.TxHelpersClass is None:
self.TxHelpersClass = TxHelpers(ConfigObj=self.ConfigObj)
assert issubclass(
self.TxHelpersClass.__class__, TxHelpersBase
), f"TxHelpersClass not derived from TxHelpersBase {self.TxHelpersClass}"

self.db = QueryInterface(ConfigObj=self.ConfigObj)
self.RUN_FLASHLOAN_TOKENS = [*self.ConfigObj.CHAIN_FLASHLOAN_TOKENS.values()]
Expand Down
82 changes: 1 addition & 81 deletions fastlane_bot/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1998,62 +1998,6 @@ def handle_tokens_csv(mgr, prefix_path, read_only: bool = False):
)


def self_funding_warning_sequence(cfg):
Lesigh-3100 marked this conversation as resolved.
Show resolved Hide resolved
"""
This function initiates a warning sequence if the user has specified to use their own funds.

:param cfg: the config object

"""
cfg.logger.info(
f"\n\n*********************************************************************************\n********************************* WARNING *********************************\n\n"
)
cfg.logger.info(
f"Arbitrage bot is set to use its own funds instead of using Flashloans.\n\n***** This could put your funds at risk. ******\nIf you did not mean to use this mode, cancel the bot now.\n\nOtherwise, the bot will submit token approvals IRRESPECTIVE OF CURRENT GAS PRICE for each token specified in Flashloan tokens.\n\n*********************************************************************************"
)
time.sleep(5)
cfg.logger.info(f"Submitting approvals in 15 seconds")
time.sleep(5)
cfg.logger.info(f"Submitting approvals in 10 seconds")
time.sleep(5)
cfg.logger.info(f"Submitting approvals in 5 seconds")
time.sleep(5)
cfg.logger.info(
f"*********************************************************************************\n\nSelf-funding mode activated."
)
cfg.logger.info(
f"""\n\n
_____
|A . | _____
| /.\ ||A ^ | _____
|(_._)|| / \ ||A _ | _____
| | || \ / || ( ) ||A_ _ |
|____V|| . ||(_'_)||( v )|
|____V|| | || \ / |
|____V|| . |
|____V|
\n\n"""
)


def find_unapproved_tokens(tokens: List, cfg, tx_helpers) -> List:
"""
This function checks if tokens have been previously approved from the wallet address to the Arbitrage contract.
If they are not already approved, it will submit approvals for each token specified in Flashloan tokens.
:param tokens: the list of tokens to check/approve
:param cfg: the config object
:param tx_helpers: the TxHelpers instantiated class

returns: List of tokens that have not been approved

"""
unapproved_tokens = []
for tkn in tokens:
if not tx_helpers.check_if_token_approved(token_address=tkn):
unapproved_tokens.append(tkn)
return unapproved_tokens


def check_and_approve_tokens(tokens: List, cfg) -> bool:
"""
This function checks if tokens have been previously approved from the wallet address to the Arbitrage contract.
Expand All @@ -2063,28 +2007,4 @@ def check_and_approve_tokens(tokens: List, cfg) -> bool:
:param cfg: the config object

"""

sklbancor marked this conversation as resolved.
Show resolved Hide resolved
tokens = [tkn for tkn in tokens if tkn != cfg.NATIVE_GAS_TOKEN_ADDRESS]

self_funding_warning_sequence(cfg=cfg)
tx_helpers = TxHelpers(ConfigObj=cfg)
unapproved_tokens = find_unapproved_tokens(
tokens=tokens, cfg=cfg, tx_helpers=tx_helpers
)

if len(unapproved_tokens) == 0:
return True

for _tkn in unapproved_tokens:
tx = tx_helpers.approve_token_for_arb_contract(token_address=_tkn)
if tx is not None:
continue
else:
assert (
False
), f"Failed to approve token: {_tkn}. This can be fixed by approving manually, or restarting the bot to try again."
Lesigh-3100 marked this conversation as resolved.
Show resolved Hide resolved

unapproved_tokens = find_unapproved_tokens(
tokens=unapproved_tokens, cfg=cfg, tx_helpers=tx_helpers
)
return len(unapproved_tokens) == 0
TxHelpers(ConfigObj=cfg).check_and_approve_tokens(tokens=tokens)
4 changes: 0 additions & 4 deletions fastlane_bot/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@
from .univ3calc import Univ3Calculator
from .wrap_unwrap_processor import add_wrap_or_unwrap_trades_to_route
from .carbon_trade_splitter import split_carbon_trades
TxHelpersBase = TxHelpers



Loading
Loading