Skip to content

Commit

Permalink
fix: tx copy in get_l1_data_fee and constants
Browse files Browse the repository at this point in the history
Signed-off-by: OjusWiZard <[email protected]>
  • Loading branch information
OjusWiZard committed Jan 31, 2025
1 parent f3f3233 commit 218c4aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
29 changes: 14 additions & 15 deletions plugins/aea-ledger-ethereum/aea_ledger_ethereum/ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@
BASE_FEE_MULTIPLIER = defaultdict(lambda: 1.2, {40: 2.0, 100: 1.6, 200: 1.4})

GAS_PRICE_ORACLE_ADDRESS = "0x420000000000000000000000000000000000000F"
GET_L1_FEE_ABI = [
{
"inputs": [{"internalType": "bytes", "name": "_data", "type": "bytes"}],
"name": "getL1Fee",
"outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
"stateMutability": "view",
"type": "function",
}
]
MAX_OP_L1_FEE_INCREASE_RELATIVE_PER_BLOCK = 1.125

# The tip increase is the minimum required of 10%.
TIP_INCREASE = 1.1
Expand Down Expand Up @@ -197,7 +207,7 @@ def estimate_priority_fee(
[
reward[0]
for reward in fee_history.get("reward", [])
if reward[0] >= min_allowed_tip.get(web3_object.eth.chain_id, 0)
if reward[0] >= min_allowed_tip.get(web3_object.eth.chain_id, 1)
]
)
if len(rewards) == 0:
Expand Down Expand Up @@ -1218,6 +1228,7 @@ def get_l1_data_fee(self, transaction: JSONLike) -> int:
:param transaction: the transaction
:return: the data fee in wei
"""
transaction = deepcopy(transaction)
del transaction["from"]
try:
unsigned_raw_tx = serializable_unsigned_transaction_from_dict(transaction)
Expand All @@ -1228,19 +1239,7 @@ def get_l1_data_fee(self, transaction: JSONLike) -> int:
unsigned_raw_tx_hex = encode_transaction(unsigned_raw_tx, (0, "0", "0"))
gas_oracle = self.api.eth.contract(
address=GAS_PRICE_ORACLE_ADDRESS,
abi=[
{
"inputs": [
{"internalType": "bytes", "name": "_data", "type": "bytes"}
],
"name": "getL1Fee",
"outputs": [
{"internalType": "uint256", "name": "", "type": "uint256"}
],
"stateMutability": "view",
"type": "function",
}
],
abi=GET_L1_FEE_ABI,
)

l1_fee_estimate = gas_oracle.functions.getL1Fee(unsigned_raw_tx_hex).call()
Expand All @@ -1253,7 +1252,7 @@ def get_l1_data_fee(self, transaction: JSONLike) -> int:

# increase it by 12.5% because that's the max it can increase in the next block
# docs: https://docs.optimism.io/builders/app-developers/transactions/fees#mechanism
return int(l1_fee_estimate * 1.125)
return int(l1_fee_estimate * MAX_OP_L1_FEE_INCREASE_RELATIVE_PER_BLOCK)

def send_signed_transaction(
self, tx_signed: JSONLike, raise_on_try: bool = False
Expand Down
8 changes: 4 additions & 4 deletions plugins/aea-ledger-ethereum/tests/test_ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,14 @@ def test_gas_price_strategy_eip1559() -> None:

callable_ = get_gas_price_strategy_eip1559(**DEFAULT_EIP1559_STRATEGY)

web3 = Web3()
web3 = Mock()
base_fee_per_gas_mock = 15e10
get_block_mock = mock.patch.object(
web3.eth,
"get_block",
return_value={"baseFeePerGas": base_fee_per_gas_mock, "number": 1},
)
get_chain_id_mock = mock.patch.object(web3.eth, "chain_id", return_value=1)

mock_hist_data = get_history_data(n_blocks=5)
rewards = [rew[0] for rew in mock_hist_data["reward"]]
Expand All @@ -523,9 +524,8 @@ def test_gas_price_strategy_eip1559() -> None:
return_value=mock_hist_data,
)

with get_block_mock:
with fee_history_mock:
gas_stregy = callable_(web3, "tx_params")
with get_block_mock, fee_history_mock, get_chain_id_mock:
gas_stregy = callable_(web3, "tx_params")

assert all([key in gas_stregy for key in ["maxFeePerGas", "maxPriorityFeePerGas"]])
assert gas_stregy["maxPriorityFeePerGas"] < max(rewards)
Expand Down

0 comments on commit 218c4aa

Please sign in to comment.