erc_4626.vault_protocol.lagoon.testing

Documentation for eth_defi.erc_4626.vault_protocol.lagoon.testing Python module.

Lagoon unit test helpers.

Functions

force_lagoon_settle(vault, asset_manager[, ...])

Force settling of the Lagoon vault.

fund_lagoon_vault(web3, vault_address, ...)

Deposit tokens into a Lagoon vault so the Safe holds funds.

redeem_vault_shares(web3, vault_address, ...)

Request a full redemption of vault shares for a given depositor.

force_lagoon_settle(vault, asset_manager, raw_nav=None, gas_limit=15000000)

Force settling of the Lagoon vault.

  • Used in the testing to move the vault to the next epoch

Parameters
fund_lagoon_vault(web3, vault_address, asset_manager, test_account_with_balance, trading_strategy_module_address, amount=Decimal('500'), nav=Decimal('0'), hot_wallet=None, token_cache=None)

Deposit tokens into a Lagoon vault so the Safe holds funds.

Supports two transaction signing modes:

  • Anvil mode (default): uses .transact({"from": ...}) for unlocked accounts on Anvil forks. This is the mode used by pytest fixtures.

  • HotWallet mode: when hot_wallet is provided, signs and broadcasts each transaction via HotWallet.transact_and_broadcast_with_contract(). Use this for real deployments and scripts.

Example (Anvil mode — pytest):

fund_lagoon_vault(
    web3,
    vault.address,
    asset_manager,
    depositor,
    module.address,
    amount=Decimal(500),
)

Example (HotWallet mode — deploy script):

deployer = HotWallet.from_private_key(os.environ["PRIVATE_KEY"])
deployer.sync_nonce(web3)
fund_lagoon_vault(
    web3,
    vault.address,
    deployer.address,
    deployer.address,
    module.address,
    amount=Decimal(2),
    hot_wallet=deployer,
)
Parameters
  • web3 (web3.main.Web3) – Web3 connection to the chain where the vault lives.

  • vault_address (eth_typing.evm.HexAddress) – On-chain address of the Lagoon vault.

  • asset_manager (eth_typing.evm.HexAddress) – Address that has the updateNewTotalAssets + settleDeposit role on the vault.

  • test_account_with_balance (eth_typing.evm.HexAddress) – Address that holds the denomination token and will deposit.

  • trading_strategy_module_address (eth_typing.evm.HexAddress) – Address of the TradingStrategyModuleV0 guard contract.

  • amount – Human-readable amount to deposit (e.g. Decimal(500) for 500 USDC).

  • nav – NAV value to post during settlement (usually Decimal(0) for initial funding).

  • hot_wallet (Optional[eth_defi.hotwallet.HotWallet]) – When provided, all transactions are signed with this wallet instead of using Anvil’s unlocked-account shortcut.

  • token_cache (Optional[eth_defi.token.TokenDiskCache]) –

redeem_vault_shares(web3, vault_address, redeemer, hot_wallet=None, token_cache=None)

Request a full redemption of vault shares for a given depositor.

Initiates Phase 1 of the ERC-7540 async redemption flow:

  1. Approve all shares for the vault

  2. Call requestRedeem() to queue the redemption

After calling this function, the vault must be settled to process the redemption (Phase 2), then the redeemer calls vault.finalise_redeem() to claim their USDC (Phase 3).

Supports two transaction signing modes:

  • Anvil mode (default): uses .transact({"from": ...}) for unlocked accounts on Anvil forks.

  • HotWallet mode: when hot_wallet is provided, signs and broadcasts each transaction via HotWallet.transact_and_broadcast_with_contract().

Example (HotWallet mode):

deployer.sync_nonce(web3)
vault = redeem_vault_shares(
    web3,
    vault_address,
    redeemer=deployer.address,
    hot_wallet=deployer,
)
# Then settle the vault (e.g. via CLI lagoon-settle)
# Then finalise:
tx_hash = deployer.transact_and_broadcast_with_contract(
    vault.finalise_redeem(deployer.address),
)
Parameters
Returns

The LagoonVault instance, which can be used for Phase 3 (vault.finalise_redeem()).

Return type

eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault