Skip to content

Commit

Permalink
execTransactionFromModule() gas hot fix
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Dec 5, 2024
1 parent 5094e35 commit ad2c1f4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions eth_defi/safe/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from eth_defi.trace import trace_evm_transaction, print_symbolic_trace, TraceMethod


def assert_safe_success(
def assert_execute_module_success(
web3: Web3,
tx_hash: HexBytes,
verbose=True,
Expand All @@ -36,7 +36,7 @@ def assert_safe_success(
failure += 1

if success == 0 and failure == 0:
raise AssertionError(f"Does not look like a Gnosis Safe transction")
raise AssertionError(f"Does not look like a Gnosis Safe transaction, no ExecutionFromModuleSuccess or ExecutionFromModuleFailure events detected:\n{receipt}")
elif success + failure > 1:
raise AssertionError(f"Too many success and failures in tx. Some weird nested case?")
elif failure == 1:
Expand Down
6 changes: 3 additions & 3 deletions tests/lagoon/test_lagoon_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from eth_defi.uniswap_v2.deployment import fetch_deployment
from eth_defi.uniswap_v2.swap import swap_with_slippage_protection
from eth_defi.vault.base import TradingUniverse
from eth_defi.safe.trace import assert_safe_success
from eth_defi.safe.trace import assert_execute_module_success


@pytest.fixture()
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_lagoon_swap(
approve_call = base_usdc.contract.functions.approve(uniswap_v2.router.address, amount)
moduled_tx = vault.transact_through_module(approve_call)
tx_hash = moduled_tx.transact({"from": asset_manager})
assert_safe_success(web3, tx_hash)
assert_execute_module_success(web3, tx_hash)

# Creat a bound contract function instance
# that presents Uniswap swap from the vault
Expand All @@ -77,7 +77,7 @@ def test_lagoon_swap(

moduled_tx = vault.transact_through_module(swap_call)
tx_hash = moduled_tx.transact({"from": asset_manager})
assert_safe_success(web3, tx_hash)
assert_execute_module_success(web3, tx_hash)

# Check that vault balances are updated,
# from what we have at the starting point at test_lagoon_fetch_portfolio
Expand Down
21 changes: 15 additions & 6 deletions tests/lagoon/test_lagoon_valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from eth_defi.lagoon.vault import LagoonVault
from eth_defi.provider.broken_provider import get_almost_latest_block_number
from eth_defi.safe.trace import assert_safe_success
from eth_defi.safe.trace import assert_execute_module_success
from eth_defi.token import TokenDetails
from eth_defi.trace import assert_transaction_success_with_explanation
from eth_defi.uniswap_v2.constants import UNISWAP_V2_DEPLOYMENTS
Expand Down Expand Up @@ -267,9 +267,18 @@ def test_lagoon_post_valuation(
# Then settle the valuation as the vault owner (Safe multisig) in this case
settle_call = vault.settle()
moduled_tx = vault.transact_through_module(settle_call)
tx_hash = moduled_tx.transact({"from": asset_manager})
assert_safe_success(web3, tx_hash)

# Check value after update
tx_data = moduled_tx.build_transaction({
"from": asset_manager,
})
# Normal estimate_gas does not give enough gas for
# Safe execTransactionFromModule() transaction for some reason
gnosis_gas_fix = 1_000_000
tx_data["gas"] = web3.eth.estimate_gas(tx_data) + gnosis_gas_fix
tx_hash = web3.eth.send_transaction(tx_data)
assert_execute_module_success(web3, tx_hash)

# Check value after update.
# We should have USDC value of the vault readable
# from NAV smart contract endpoint
nav = vault.fetch_nav()
assert nav == pytest.approx(Decimal(0.1))
assert nav > Decimal(30) # Changes every day as we need to test live mainnet

0 comments on commit ad2c1f4

Please sign in to comment.