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

Support legacy transactions #682

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 16 additions & 6 deletions fastlane_bot/config/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class ConfigNetwork(ConfigBase):
# LINK_KEY = "LINK-86CA"
# USDT_KEY = "USDT-1ec7"
SELF_FUND = False
TX_TYPE = 2

# ACCOUNTS SECTION
#######################################################################################
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 = 1

network_df = get_multichain_addresses(network=NETWORK_NAME)
FASTLANE_CONTRACT_ADDRESS = "0xC56Eb3d03C5D7720DAf33a3718affb9BcAb03FBc"
MULTICALL_CONTRACT_ADDRESS = "0xe033Bed7cae4114Af84Be1e9F1CA7DEa07Dfe1Cf"
Expand All @@ -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

Expand Down
12 changes: 9 additions & 3 deletions fastlane_bot/helpers/txhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down
Loading