From 2ea86432689a1f55207738d59bb5f3eb248b78e6 Mon Sep 17 00:00:00 2001 From: barak manos <> Date: Mon, 27 May 2024 23:32:06 +0300 Subject: [PATCH 1/2] Support legacy transactions --- fastlane_bot/config/network.py | 22 ++++++++++++++++------ fastlane_bot/helpers/txhelpers.py | 12 +++++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/fastlane_bot/config/network.py b/fastlane_bot/config/network.py index f893d4380..651a15ede 100644 --- a/fastlane_bot/config/network.py +++ b/fastlane_bot/config/network.py @@ -203,6 +203,7 @@ class ConfigNetwork(ConfigBase): # LINK_KEY = "LINK-86CA" # USDT_KEY = "USDT-1ec7" SELF_FUND = False + TX_TYPE = 2 # ACCOUNTS SECTION ####################################################################################### @@ -285,13 +286,19 @@ class ConfigNetwork(ConfigBase): # HOOKS ####################################################################################### @staticmethod - def gas_strategy(web3): + def gas_strategy(web3, tx_type): 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 - } + if tx_type < 2: + return { + "gasPrice": gas_price + } + if tx_type == 2: + max_priority_fee = web3.eth.max_priority_fee # send `eth_maxPriorityFeePerGas` request + return { + "maxFeePerGas": gas_price + max_priority_fee, + "maxPriorityFeePerGas": max_priority_fee + } + raise Exception(f"Transaction type {tx_type} not supported") @classmethod def new(cls, network=None): @@ -797,6 +804,8 @@ class _ConfigNetworkSei(ConfigNetwork): RPC_ENDPOINT = "https://evm-rpc.sei-apis.com/?x-apikey=" WEB3_ALCHEMY_PROJECT_ID = os.environ.get("WEB3_SEI") + TX_TYPE = 0 + network_df = get_multichain_addresses(network=NETWORK_NAME) FASTLANE_CONTRACT_ADDRESS = "0xC56Eb3d03C5D7720DAf33a3718affb9BcAb03FBc" MULTICALL_CONTRACT_ADDRESS = "0xe033Bed7cae4114Af84Be1e9F1CA7DEa07Dfe1Cf" @@ -811,6 +820,7 @@ class _ConfigNetworkSei(ConfigNetwork): STABLECOIN_ADDRESS = "0xace5f7Ea93439Af39b46d2748fA1aC19951c8d7C" #TODO USDC on devnet IS_INJECT_POA_MIDDLEWARE = False + # Balancer BALANCER_VAULT_ADDRESS = "0x7ccBebeb88696f9c8b061f1112Bb970158e29cA5" # # TODO Jellyswap on devnet diff --git a/fastlane_bot/helpers/txhelpers.py b/fastlane_bot/helpers/txhelpers.py index 0fdf166fc..1f18fb41a 100644 --- a/fastlane_bot/helpers/txhelpers.py +++ b/fastlane_bot/helpers/txhelpers.py @@ -31,6 +31,12 @@ MAX_UINT256 = 2 ** 256 - 1 ETH_RESOLUTION = 10 ** 18 +GAS_PRICE_KEY = { + 0: "gasPrice", + 1: "gasPrice", + 2: "maxFeePerGas", +} + @dataclass class TxHelpers: """ @@ -110,7 +116,7 @@ def validate_and_submit_transaction( raw_tx = self._sign_transaction(tx) - gas_cost_wei = tx["gas"] * tx["maxFeePerGas"] + gas_cost_wei = tx["gas"] * tx[GAS_PRICE_KEY[self.cfg.network.TX_TYPE]] if self.cfg.network.GAS_ORACLE_ADDRESS: gas_cost_wei += self.cfg.GAS_ORACLE_CONTRACT.caller.getL1Fee(raw_tx) @@ -158,7 +164,7 @@ def check_and_approve_tokens(self, tokens: List): def _create_transaction(self, contract, fn_name: str, args: list, value: int) -> dict: return { - "type": 2, + "type": self.cfg.network.TX_TYPE, "value": value, "chainId": self.chain_id, "from": self.wallet_address, @@ -174,7 +180,7 @@ def _update_transaction(self, tx: dict): if tx["gas"] > result["gasUsed"] and "error" not in result: tx["gas"] = result["gasUsed"] tx["accessList"] = loads(self.cfg.w3.to_json(result["accessList"])) - tx.update(self.cfg.network.gas_strategy(self.cfg.w3)) + tx.update(self.cfg.network.gas_strategy(self.cfg.w3, self.cfg.network.TX_TYPE)) def _sign_transaction(self, tx: dict) -> str: return self.cfg.w3.eth.account.sign_transaction(tx, self.cfg.ETH_PRIVATE_KEY_BE_CAREFUL).rawTransaction.hex() From 0fc30c8cca0900e0c97d21ea244160794d51f78b Mon Sep 17 00:00:00 2001 From: Nicholas Welch Date: Tue, 28 May 2024 09:31:04 +1000 Subject: [PATCH 2/2] tx_type 1 for SEI --- fastlane_bot/config/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastlane_bot/config/network.py b/fastlane_bot/config/network.py index 651a15ede..a82553775 100644 --- a/fastlane_bot/config/network.py +++ b/fastlane_bot/config/network.py @@ -804,7 +804,7 @@ class _ConfigNetworkSei(ConfigNetwork): RPC_ENDPOINT = "https://evm-rpc.sei-apis.com/?x-apikey=" WEB3_ALCHEMY_PROJECT_ID = os.environ.get("WEB3_SEI") - TX_TYPE = 0 + TX_TYPE = 1 network_df = get_multichain_addresses(network=NETWORK_NAME) FASTLANE_CONTRACT_ADDRESS = "0xC56Eb3d03C5D7720DAf33a3718affb9BcAb03FBc"