erc_4626.vault_protocol.lagoon.deployment
Documentation for eth_defi.erc_4626.vault_protocol.lagoon.deployment Python module.
Deploy new Lagoon vaults.
Lagoon automatised vault consists of
Safe multisig - we use 1.4.1 here
Vault module
Lagoon protocol smart contracts
TradingStrategyModuleV0 module enabling guarded automated trade executor for the Safe
Support deployments with Forge and Etherscan verification
Any Safe must be deployed as 1-of-1 deployer address multisig and multisig holders changed after the deployment.
Module Attributes
Default minimum delay between non-zero asset-manager Lagoon settlements. |
|
Earliest GuardV0 internal ABI version with the complete Lagoon v0.5 asset-manager settlement safety policy: gross cap plus enforced cooldown. |
|
Safety multiplier applied to the node |
|
Packaged ABI for the only Lagoon version whose settlement balance invariant is currently enforced by LagoonLib. |
|
Packaged ABI for the unsupported pre-v0.5 Lagoon deployment path. |
|
https://basescan.org/address/0xC953Fd298FdfA8Ed0D38ee73772D3e21Bf19c61b#writeContract https://docs.lagoon.finance/vault/create-your-vault |
Functions
|
Deploy a full Lagoon setup with a guard. |
|
Deploy a fresh Lagoon implementation from the scratch. |
|
Deploy a new Lagoon vault. |
|
Deploy a fee registry contract. |
|
Deploy Lagoon vaults across multiple chains with a shared deterministic Safe. |
|
Deploy TradingStrategyModuleV0 for Safe and Lagoon. |
|
Set up a TradingStrategyModuleV0 guard for its paired Lagoon vault and Safe. |
|
Should Hypercore guard support be enabled for this deployment. |
Classes
Capture information of the lagoon automated deployment. |
|
Configuration for Lagoon vault deployment. |
|
Capture core parameters needed to deploy a Lagoon vault |
|
Result of deploying Lagoon vaults across multiple chains with a shared deterministic Safe. |
|
A single guard whitelist entry recorded during deployment. |
- DEFAULT_LAGOON_SETTLEMENT_COOLDOWN = 86400
Default minimum delay between non-zero asset-manager Lagoon settlements.
The maximum gross settlement amount is a safety feature, so it must also rate-limit repeated below-cap calls. Twenty-four hours gives governance time to observe and respond to each automated movement while retaining a direct Safe recovery path.
- LAGOON_SETTLEMENT_LIMIT_INTERNAL_VERSION = 3
Earliest GuardV0 internal ABI version with the complete Lagoon v0.5 asset-manager settlement safety policy: gross cap plus enforced cooldown.
- DEFAULT_DEPLOYMENT_GAS_MULTIPLIER = 2.0
Safety multiplier applied to the node
eth_estimateGasresult for guard setup / deployment broadcasts.Some L2s — Arbitrum in particular — under-estimate
eth_estimateGasfor simple guard-configuration calls (e.g.allowReceiver), causing the transaction to revert on-chain with “out of gas” even though the estimate was accepted. A multiplier on the estimate avoids this; the sender is still only charged for gas actually used, so over-provisioning the limit is free.
- DEFAULT_LAGOON_VAULT_JSON = 'lagoon/v0.5.0/Vault.json'
Packaged ABI for the only Lagoon version whose settlement balance invariant is currently enforced by LagoonLib.
- LEGACY_LAGOON_VAULT_JSON = 'lagoon/Vault.json'
Packaged ABI for the unsupported pre-v0.5 Lagoon deployment path.
- should_enable_hypercore_guard(*, chain_id, any_asset, hypercore_vaults)
Should Hypercore guard support be enabled for this deployment.
any_asset=Trueintentionally bypasses per-vault Hypercore address checks, but Hypercore deposits and withdrawals still require CoreWriter actions and CoreDepositWallet approval/target validation to be whitelisted.
- class LagoonDeploymentParameters
Bases:
objectCapture core parameters needed to deploy a Lagoon vault
- wrappedNativeToken: Optional[eth_typing.evm.HexAddress]
If set None, then autoresolve
- as_abi_encoded_bytes()
Return Lagoon vault initialization struct ABI encoded.
Before was passed as is, was changed to ABI encoded bytes in Lagoon v0.5.0.
Does not include wrappedNativeToken
Does not include feeRegistry, as it is passed separately.
- Return type
hexbytes.main.HexBytes
- __init__(underlying, name, symbol, safe=None, whitelistManager=None, valuationManager=None, admin=None, feeReceiver=None, feeRegistry=None, managementRate=200, performanceRate=2000, enableWhitelist=False, rateUpdateCooldown=86400, wrappedNativeToken=None)
- Parameters
- Return type
None
- class LagoonConfig
Bases:
objectConfiguration for Lagoon vault deployment.
Captures all parameters needed to deploy a Lagoon vault except the chain connection (
web3) and deployer account.Can be passed to
deploy_automated_lagoon_vault()(single chain) ordeploy_multichain_lagoon_vault()(multiple chains).The optional
max_settlement_amountis a Guard safety policy, not a Lagoon vault initialisation parameter. It is therefore kept on this deployment configuration instead ofLagoonDeploymentParameters. When configured, deployment binds the Guard to the stock Lagoon v0.5 vault’s underlying token and pending-deposit Silo, and enables atomic post-call validation inTradingStrategyModuleV0.The safety feature controls gross underlying-token movement in one asset-manager settlement transaction and rate-limits non-zero calls. Deposit assets moving from the Silo to the Safe and redemption assets moving from the Safe to the vault are added rather than netted. The paired
settlement_cooldowndefaults to 24 hours so an asset manager cannot drain the vault with repeated individually valid non-zero calls. Empty settlements neither start nor wait for cooldown. The policy does not validate the NAV supplied to Lagoon. Safe governance can still settle directly without going through the asset-manager module.- parameters: eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonDeploymentParameters
Vault parameters (name, symbol, underlying token, fees)
- safe_owners: list[eth_typing.evm.HexAddress | str]
Addresses of Safe multisig owners
- asset_manager: Optional[eth_typing.evm.HexAddress]
Primary asset manager kept for backwards compatibility.
Deprecated in favour of
asset_managers. When both are provided,asset_managerswins.
- asset_managers: Optional[list[eth_typing.evm.HexAddress | str]]
Addresses that manage vault assets and execute trades.
All entries are whitelisted as guard senders. The first entry becomes the primary asset manager and is used as the Lagoon valuation manager unless
parameters.valuationManagerwas explicitly set.The main use case today is splitting permissions between FreqTrade and GMX trading keys while keeping the same Guard rights. Future automated trading or operational workflows may reuse the same mechanism.
- uniswap_v2: Optional[eth_defi.uniswap_v2.deployment.UniswapV2Deployment]
Uniswap V2 deployment for router whitelisting
- uniswap_v3: Optional[eth_defi.uniswap_v3.deployment.UniswapV3Deployment]
Uniswap V3 deployment for router/quoter whitelisting
- aave_v3: Optional[eth_defi.aave_v3.deployment.AaveV3Deployment]
Aave V3 deployment for lending whitelisting
- gmx_deployment: Optional[eth_defi.gmx.whitelist.GMXDeployment]
GMX perpetuals deployment for whitelisting
- lighter_deployment: Optional[eth_defi.lighter.deployment.LighterDeployment]
Lighter (zk-rollup perps DEX, Ethereum L1) deployment for whitelisting
- cctp_deployment: Optional[eth_defi.cctp.whitelist.CCTPDeployment]
CCTP V2 deployment for cross-chain USDC transfers
- verifier: Optional[Literal['etherscan', 'blockscout', 'sourcify', 'oklink']]
Block explorer for contract verification
- between_contracts_delay_seconds: float
Delay between contract deployments (seconds) for nonce propagation
- erc_4626_vaults: Optional[list[eth_defi.erc_4626.vault.ERC4626Vault]]
ERC-4626 vaults to whitelist for deposit/withdrawal
- existing_vault_address: Optional[Union[eth_typing.evm.HexAddress, str]]
Reuse an existing vault (requires guard_only=True)
- existing_safe_address: Optional[Union[eth_typing.evm.HexAddress, str]]
Reuse an existing Safe instead of deploying a new one
- from_the_scratch: bool
Deploy fresh Lagoon protocol (fee registry + vault implementation + factory)
- max_settlement_amount: Optional[decimal.Decimal]
Maximum gross Lagoon v0.5 settlement per asset-manager transaction.
Expressed as a
Decimalin human-readable underlying token units; for example,Decimal("10000")means 10,000 USDC for a USDC vault. Deployment converts this value to raw token units using the underlying token’s onchaindecimals()value.Noneis the backwards-compatible default and keeps Lagoon settlement unlimited. Zero is a valid strict cap which permits only a settlement with zero measured asset movement.The cap is supported only for a stock Lagoon v0.5 vault executed through its paired
TradingStrategyModuleV0. It must not be set for a legacy Lagoon ABI or a satellite-chain configuration, because neither has the execution-aware vault settlement path needed to enforce the post-call balance check.
- settlement_cooldown: int
Minimum delay between non-zero asset-manager Lagoon settlements.
Expressed in seconds and enforced only when
max_settlement_amountis configured. The default is 24 hours. Empty settlements do not start or extend the cooldown and remain callable while it is active. The value must be positive because a zero cooldown would allow repeated non-zero below-cap calls and defeat the safety feature. Direct Safe governance calls bypass this module policy.
- hypercore_vaults: Optional[list[eth_typing.evm.HexAddress | str]]
Hypercore native vault addresses to whitelist (HyperEVM only). When set, also whitelists CoreWriter and CoreDepositWallet.
- assets: Optional[list[eth_typing.evm.HexAddress | str]]
ERC-20 token addresses to whitelist
- safe_proxy_factory_address: Optional[Union[eth_typing.evm.HexAddress, str]]
Override Safe ProxyFactory address (default: v1.4.1 canonical). See Safe canonical deployments and Safe contract deployment docs.
- forge_cache_dir: Optional[pathlib.Path]
Isolated directory for forge cache and output artifacts. Allows concurrent forge deployments from the same source tree.
- deploy_retries: int
Number of forge deploy retries on
"contract was not deployed"errors. Only allowed on testnets. Default: 1 (no retries).
- satellite_chain: bool
When True, deploy only Safe + TradingStrategyModuleV0 guard (no vault). Used for satellite chains in multichain deployments where only the source chain needs a vault contract.
- __init__(parameters, safe_owners, safe_threshold, asset_manager=None, asset_managers=None, uniswap_v2=None, uniswap_v3=None, aave_v3=None, cowswap=False, velora=False, gmx_deployment=None, lighter_deployment=None, cctp_deployment=None, any_asset=False, etherscan_api_key=None, verifier=None, verifier_url=None, use_forge=False, between_contracts_delay_seconds=5.0, erc_4626_vaults=None, guard_only=False, existing_vault_address=None, existing_safe_address=None, vault_abi='lagoon/v0.5.0/Vault.json', factory_contract=True, from_the_scratch=False, max_settlement_amount=None, settlement_cooldown=86400, hypercore_vaults=None, assets=None, safe_salt_nonce=None, safe_proxy_factory_address=None, forge_cache_dir=None, deploy_retries=1, satellite_chain=False)
- Parameters
parameters (eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonDeploymentParameters) –
safe_owners (list[eth_typing.evm.HexAddress | str]) –
safe_threshold (int) –
asset_manager (Optional[eth_typing.evm.HexAddress]) –
asset_managers (Optional[list[eth_typing.evm.HexAddress | str]]) –
uniswap_v2 (Optional[eth_defi.uniswap_v2.deployment.UniswapV2Deployment]) –
uniswap_v3 (Optional[eth_defi.uniswap_v3.deployment.UniswapV3Deployment]) –
aave_v3 (Optional[eth_defi.aave_v3.deployment.AaveV3Deployment]) –
cowswap (bool) –
velora (bool) –
gmx_deployment (Optional[eth_defi.gmx.whitelist.GMXDeployment]) –
lighter_deployment (Optional[eth_defi.lighter.deployment.LighterDeployment]) –
cctp_deployment (Optional[eth_defi.cctp.whitelist.CCTPDeployment]) –
any_asset (bool) –
verifier (Optional[Literal['etherscan', 'blockscout', 'sourcify', 'oklink']]) –
use_forge (bool) –
between_contracts_delay_seconds (float) –
erc_4626_vaults (Optional[list[eth_defi.erc_4626.vault.ERC4626Vault]]) –
guard_only (bool) –
existing_vault_address (Optional[Union[eth_typing.evm.HexAddress, str]]) –
existing_safe_address (Optional[Union[eth_typing.evm.HexAddress, str]]) –
vault_abi (str) –
factory_contract (bool) –
from_the_scratch (bool) –
max_settlement_amount (Optional[decimal.Decimal]) –
settlement_cooldown (int) –
hypercore_vaults (Optional[list[eth_typing.evm.HexAddress | str]]) –
assets (Optional[list[eth_typing.evm.HexAddress | str]]) –
safe_proxy_factory_address (Optional[Union[eth_typing.evm.HexAddress, str]]) –
forge_cache_dir (Optional[pathlib.Path]) –
deploy_retries (int) –
satellite_chain (bool) –
- Return type
None
- class WhitelistEntry
Bases:
objectA single guard whitelist entry recorded during deployment.
- address: Union[eth_typing.evm.HexAddress, str]
On-chain address, or empty string for non-address entries
- class LagoonAutomatedDeployment
Bases:
objectCapture information of the lagoon automated deployment.
Have the deployment report for the users for diagnostics
- vault: Union[eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault, eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonSatelliteVault]
The deployed Lagoon vault, or
LagoonSatelliteVaultfor satellite chains.
- safe_address: eth_typing.evm.HexAddress
The Safe multisig address, stored explicitly so it is available even on satellite chains where there is no vault contract.
- old_trading_strategy_module: Optional[web3.contract.contract.Contract]
In redeploy guard, the old module
- beacon_proxy_factory: Optional[eth_typing.evm.HexAddress]
Address of beacon proxy factory
- gas_used: Optional[decimal.Decimal]
How much ETH deployment used
- safe_salt_nonce: Optional[int]
Salt nonce used for deterministic Safe proxy deployment.
Recorded so the deployment can be reproduced or debugged later.
Nonewhen deployed without a deterministic address (e.g. from-scratch testnet).
- whitelisted_items: tuple[eth_defi.erc_4626.vault_protocol.lagoon.deployment.WhitelistEntry, ...]
Items whitelisted on the guard during deployment.
- property asset_manager: eth_typing.evm.HexAddress
Get the primary asset manager.
Kept for backwards compatibility with single-key deployments.
- property is_satellite: bool
Whether this deployment is a satellite chain (Safe + guard only, no vault).
- get_deployment_data()
Get JSON data describing the deployment.
Store all addresses etc.
- Return type
- as_json_friendly_dict()
Get JSON-serialisable deployment data.
LagoonAutomatedDeploymentcontains live Web3 contract and vault objects that cannot be written to JSON directly. This method captures the deployment as plain JSON values, keeping enough addresses and parameters to reconstruct the deployment object withfrom_json_friendly_dict().
- classmethod from_json_friendly_dict(web3, data)
Recreate deployment information from JSON data.
This recreates the live Web3 contract and vault reader objects from addresses stored by
as_json_friendly_dict(). The JSON payload does not contain private keys or signed transactions.- Parameters
web3 (web3.main.Web3) – Web3 connection for the deployment chain.
data (dict[str, Any]) – JSON data produced by
as_json_friendly_dict().
- Returns
Hydrated Lagoon deployment information.
- Return type
eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonAutomatedDeployment
- format_whitelisted_items(indent=' ')
Format whitelisted items as a human-readable string.
- __init__(chain_id, vault, trading_strategy_module, asset_managers, valuation_manager, multisig_owners, deployer, block_number, parameters, vault_abi, safe_address=None, old_trading_strategy_module=None, beacon_proxy_factory=None, gas_used=None, safe_salt_nonce=None, whitelisted_items=())
- Parameters
chain_id (int) –
vault (Union[eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault, eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonSatelliteVault]) –
trading_strategy_module (web3.contract.contract.Contract) –
asset_managers (tuple[eth_typing.evm.HexAddress, ...]) –
valuation_manager (eth_typing.evm.HexAddress) –
multisig_owners (list[eth_typing.evm.HexAddress]) –
deployer (eth_typing.evm.HexAddress) –
block_number (eth_typing.evm.BlockNumber) –
parameters (eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonDeploymentParameters) –
vault_abi (str) –
safe_address (eth_typing.evm.HexAddress) –
old_trading_strategy_module (Optional[web3.contract.contract.Contract]) –
beacon_proxy_factory (Optional[eth_typing.evm.HexAddress]) –
gas_used (Optional[decimal.Decimal]) –
whitelisted_items (tuple[eth_defi.erc_4626.vault_protocol.lagoon.deployment.WhitelistEntry, ...]) –
- Return type
None
- class LagoonMultichainDeployment
Bases:
objectResult of deploying Lagoon vaults across multiple chains with a shared deterministic Safe.
All vaults share the same deterministic Safe address created via CREATE2 with the same salt nonce on each chain.
- safe_address: eth_typing.evm.HexAddress
The deterministic Safe address shared by all chains
- deployments: dict[str, eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonAutomatedDeployment]
Per-chain deployment results keyed by chain name (lowercase)
- __init__(safe_address, deployments, safe_salt_nonce)
- Parameters
safe_address (eth_typing.evm.HexAddress) –
deployments (dict[str, eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonAutomatedDeployment]) –
safe_salt_nonce (int) –
- Return type
None
- deploy_lagoon_protocol_registry(web3, deployer, safe, broadcast_func, etherscan_api_key=None, verifier=None, verifier_url=None, cache_dir=None, deploy_retries=1)
Deploy a fee registry contract.
This is referred by all Lagoon deployments
- Parameters
web3 (web3.main.Web3) –
deployer (eth_defi.hotwallet.HotWallet) –
safe (safe_eth.safe.safe.Safe) –
broadcast_func (Callable) –
etherscan_api_key (str) –
verifier (Optional[Literal['etherscan', 'blockscout', 'sourcify', 'oklink']]) –
cache_dir (Optional[pathlib.Path]) –
deploy_retries (int) –
- Return type
web3.contract.contract.Contract
- deploy_fresh_lagoon_protocol(web3, deployer, safe, broadcast_func, etherscan_api_key=None, verifier=None, verifier_url=None, forge_sync_delay=4.0, cache_dir=None, deploy_retries=1, use_forge=True)
Deploy a fresh Lagoon implementation from the scratch.
Fee registry contract
Vault implementation
Beacon proxy factory contract
- Parameters
cache_dir (Optional[pathlib.Path]) – Isolated directory for forge cache and output artifacts. Allows concurrent deployments from the same source tree.
use_forge – Use Forge source deployment for the vault implementation. Set to
Falsein local testing when packaged ABI artefacts are enough.web3 (web3.main.Web3) –
deployer (eth_defi.hotwallet.HotWallet) –
safe (safe_eth.safe.safe.Safe) –
broadcast_func (Callable) –
etherscan_api_key (str) –
verifier (Optional[Literal['etherscan', 'blockscout', 'sourcify', 'oklink']]) –
deploy_retries (int) –
- Return type
web3.contract.contract.Contract
- deploy_lagoon(web3, deployer, safe, asset_manager, parameters, owner, gas=2000000, etherscan_api_key=None, use_forge=False, beacon_proxy=False, factory_contract=True, beacon_address='0x652716FaD571f04D26a3c8fFd9E593F17123Ab20', beacon_proxy_factory_address=None, beacon_proxy_factory_abi='lagoon/BeaconProxyFactory.json', vault_abi='lagoon/v0.5.0/Vault.json', deploy_fee_registry=True, fee_registry_address=None, legacy=False, salt=b'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01', optin_proxy_delay=259200)
Deploy a new Lagoon vault.
Create a new Safe
Create a new Lagoon vault
Set guard policies
Set owership
This is a low-level Lagoon protocol deployment helper. It deploys the vault contract but does not deploy or configure
TradingStrategyModuleV0, so it cannot establish the asset-manager settlement safety policy by itself. Applications needing the settlement security policy must usedeploy_automated_lagoon_vault()and passmax_settlement_amount=Decimal(...)or useLagoonConfig.For Foundry recipe see https://github.com/hopperlabsxyz/lagoon-v0/blob/main/script/deploy_vault.s.sol
- Parameters
deployer (Union[eth_account.signers.local.LocalAccount, eth_defi.hotwallet.HotWallet]) – The initial account used to deploy smart contracts
owner (Optional[eth_typing.evm.HexAddress]) –
All transfership is transferred to this user after.
Usually defaults to newly deployed Safe the vault is associated with.
asset_manager (eth_typing.evm.HexAddress) – Able to perform trades, valuations
beacon_address – Vault beacon on base.
use_forge – Deploy a new vault contract from source with Forge and Etherscan verification.
etherscan_api_key (str) – For Forge.
vault_abi –
Which Lagoon vault version we deploy.
Use
LEGACY_LAGOON_VAULT_JSONfor the legacy version. Warning: unsafe.beacon_proxy – TODO
deploy_fee_registry (bool) –
Deploy a fee registry contract needed for deployment.
Set the fee receiver as the owner.
web3 (web3.main.Web3) –
safe (safe_eth.safe.safe.Safe) –
parameters (eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonDeploymentParameters) –
fee_registry_address (Optional[eth_typing.evm.HexAddress]) –
legacy (bool) –
- Returns
Vault contract.
Is a proxy contract.
- Return type
web3.contract.contract.Contract
- deploy_safe_trading_strategy_module(web3, deployer, safe, use_forge=False, etherscan_api_key=None, verifier=None, verifier_url=None, enable_on_safe=True, uniswap_v2=None, uniswap_v3=None, cowswap=False, velora=False, gmx_deployment=None, lighter_deployment=None, lagoon=True)
Deploy TradingStrategyModuleV0 for Safe and Lagoon.
On HyperEVM chains, automatically enables big blocks only for the TradingStrategyModuleV0 deployment (~5.4M gas). Library deployments (CowSwapLib, GmxLib, HypercoreVaultLib, VeloraLib) fit in small blocks and are deployed without toggling.
This function only deploys and links the execution module. When
lagoonis true it linksLagoonLib, making settlement-safety calls available, but it does not know the vault, underlying asset, Silo or desired amount and therefore does not configure a limit. Usedeploy_automated_lagoon_vault()for the public human-readable API, or callsetup_guard()with raw token units in lower-level integrations.- Parameters
deployer (Union[eth_account.signers.local.LocalAccount, eth_defi.hotwallet.HotWallet]) – Deployer account. When a
HotWalletis passed, nonces are managed internally (avoids stale RPC nonce reads on load-balanced public endpoints).use_forge – Deploy Etherscan verified build with Forge
enable_on_safe – Automatically enable this module on the Safe multisig. Must be 1-of-1 deployer address multisig.
lagoon (bool) – Deploy and link
LagoonLib. Satellite modules without a Lagoon vault link the zero address and fail closed on Lagoon calls.safe (safe_eth.safe.safe.Safe) –
etherscan_api_key (str) –
verifier (Optional[Literal['etherscan', 'blockscout', 'sourcify', 'oklink']]) –
uniswap_v2 (Optional[eth_defi.uniswap_v2.deployment.UniswapV2Deployment]) –
uniswap_v3 (Optional[eth_defi.uniswap_v3.deployment.UniswapV3Deployment]) –
cowswap (bool) –
velora (bool) –
gmx_deployment (Optional[eth_defi.gmx.whitelist.GMXDeployment]) –
lighter_deployment (Optional[eth_defi.lighter.deployment.LighterDeployment]) –
- Returns
TradingStrategyModuleV0 instance
- Return type
web3.contract.contract.Contract
- setup_guard(*, web3, safe, deployer, owner, asset_managers, vault, module, broadcast_func, any_asset=False, uniswap_v2=None, uniswap_v3=None, aave_v3=None, erc_4626_vaults=None, cowswap=False, velora=False, gmx_deployment=None, lighter_deployment=None, cctp_deployment=None, hypercore_vaults=None, hack_sleep=20.0, assets=None, multicall_chunk_size=40, underlying_token_address=None, lagoon_pending_silo_address=None, lagoon_max_settlement_amount_raw=None, lagoon_settlement_cooldown=86400)
Set up a TradingStrategyModuleV0 guard for its paired Lagoon vault and Safe.
This function applies the onchain policy after the module has been deployed and enabled on the Safe. The deployment topology is one Lagoon vault, one Safe, and one
TradingStrategyModuleV0; the module’savatarandtargetmust both be the supplied Safe.Lagoon settlement safety requires an execution-aware module because it compares token balances before and after the Safe call in the same atomic transaction. A standalone
GuardV0.validateCall()can perform only the pre-call half and must never be used to configure this guarantee. This function verifies the module/Safe pairing before broadcasting any policy transactions whenever a limit is requested.lagoon_max_settlement_amount_rawis deliberately a lower-level raw-unit argument. Public deployment callers normally usedeploy_automated_lagoon_vault()orLagoonConfig, which accept a human-readableDecimaland perform the token-decimal conversion.Noneselects the legacy unlimited allowlist call; zero is a valid strict cap. Every enabled cap also requires a positive cooldown;lagoon_settlement_cooldowndefaults to 24 hours.- Parameters
vault (Optional[web3.contract.contract.Contract]) – The stock Lagoon v0.5 vault paired with
safeandmodule.Noneis accepted only on satellite chains, where no Lagoon settlement selectors or settlement safety controls are configured.underlying_token_address (Optional[eth_typing.evm.HexAddress]) – Address returned by the Lagoon vault’s
asset()function. It is also used for Hypercore whitelisting whenvaultisNone. The onchain Lagoon configuration call verifies that this address matches the vault.lagoon_pending_silo_address (Optional[eth_typing.evm.HexAddress]) – Stock Lagoon v0.5 pending-deposit Silo whose underlying-token decrease measures the deposit side of a settlement. The onchain configuration call verifies that the Silo has approved the vault to pull the asset.
lagoon_max_settlement_amount_raw (Optional[int]) – Maximum gross asset-manager settlement in the underlying ERC-20’s smallest units. This is a safety limit, not a partial-settlement size. Gross settlement is
Silo decrease + vault increasefor one asset-managerperformCall()transaction.Nonepreserves the unlimited legacy policy;0enables a zero-movement-only policy.lagoon_settlement_cooldown (int) – Minimum seconds between non-zero capped asset-manager settlements. Defaults to 24 hours. A repeated non-zero call inside this window reverts during atomic post-call validation; empty and direct Safe governance transactions remain available.
web3 (web3.main.Web3) –
safe (safe_eth.safe.safe.Safe) –
deployer (eth_defi.hotwallet.HotWallet) –
owner (eth_typing.evm.HexAddress) –
asset_managers (Union[list[eth_typing.evm.HexAddress], tuple[eth_typing.evm.HexAddress, ...]]) –
module (web3.contract.contract.Contract) –
broadcast_func (Callable[[web3.contract.contract.ContractFunction], hexbytes.main.HexBytes]) –
any_asset (bool) –
uniswap_v2 (Optional[eth_defi.uniswap_v2.deployment.UniswapV2Deployment]) –
uniswap_v3 (Optional[eth_defi.uniswap_v3.deployment.UniswapV3Deployment]) –
aave_v3 (Optional[eth_defi.aave_v3.deployment.AaveV3Deployment]) –
erc_4626_vaults (Optional[list[eth_defi.erc_4626.vault.ERC4626Vault]]) –
cowswap (bool) –
velora (bool) –
gmx_deployment (Optional[eth_defi.gmx.whitelist.GMXDeployment]) –
lighter_deployment (Optional[eth_defi.lighter.deployment.LighterDeployment]) –
cctp_deployment (Optional[eth_defi.cctp.whitelist.CCTPDeployment]) –
hypercore_vaults (Optional[list[eth_typing.evm.HexAddress | str]]) –
assets (Optional[list[eth_typing.evm.HexAddress | str]]) –
- Returns
List of
WhitelistEntryrecording everything that was whitelisted.- Return type
list[eth_defi.erc_4626.vault_protocol.lagoon.deployment.WhitelistEntry]
- deploy_automated_lagoon_vault(*, web3, deployer, config=None, asset_manager=None, asset_managers=None, parameters=None, safe_owners=None, safe_threshold=None, uniswap_v2=None, uniswap_v3=None, aave_v3=None, cowswap=False, velora=False, gmx_deployment=None, lighter_deployment=None, cctp_deployment=None, hypercore_vaults=None, any_asset=False, etherscan_api_key=None, verifier=None, verifier_url=None, use_forge=False, between_contracts_delay_seconds=5.0, erc_4626_vaults=None, guard_only=False, existing_vault_address=None, existing_safe_address=None, vault_abi='lagoon/v0.5.0/Vault.json', factory_contract=True, from_the_scratch=False, assets=None, safe_salt_nonce=None, safe_proxy_factory_address=None, max_settlement_amount=None, settlement_cooldown=86400)
Deploy a full Lagoon setup with a guard.
Lagoon automatised vault consists of
Safe multisig - we use 1.4.1 here
Vault module
Lagoon protocol smart contracts
TradingStrategyModuleV0 module enabling guarded automated trade executor for the Safe
For roles - The primary asset manager and Valuation Manager (Lagoon) are the same role - Multiple asset-manager keys may share the same Guard rights; today this
mainly supports separate FreqTrade and GMX trading keys, but other workflows may use the same pattern in the future
Any Safe must be deployed as 1-of-1 deployer address multisig and multisig holders changed after the deployment.
Warning
Because we need to mix Forge, Safe lib and Web3.py transaction nonce management becomes a madness.
Note
Deployer account must be manually removed from the Safe by new owners.
Set
max_settlement_amountto opt into the Lagoon v0.5 asset-manager settlement safety feature. The value is aDecimalin human-readable underlying-token units. Deployment discovers the stock v0.5 pending Silo, converts the value with the token’s actualdecimals(), configures the paired module, and reads the complete onchain configuration back before continuing.The cap is enforced atomically around an asset-manager call through
TradingStrategyModuleV0. It measures the gross sum of deposits and redemptions, so opposite flows cannot evade the limit by netting. A rejected settlement reverts the complete Lagoon transaction.Nonepreserves the historical unlimited settlement behaviour, whileDecimal(0)permits only zero measured movement. Every successful non-zero call startssettlement_cooldown, which defaults to 24 hours, so the asset manager cannot drain the vault through repeated below-cap settlements. Empty settlements do not start, extend or wait for cooldown.The amount check is per transaction and the cooldown rate-limits those transactions over time. It does not validate the NAV passed to Lagoon or restrict transactions signed directly by Safe governance. It requires the stock Lagoon v0.5 ABI and is unavailable on satellite chains, which have no Lagoon vault.
See the canonical Lagoon smart contract source for the underlying v0.5 settlement implementation.
- Parameters
config (Optional[eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonConfig]) – Pass a
LagoonConfigobject instead of individual kwargs. When provided, all individual deployment kwargs, includingmax_settlement_amountandsettlement_cooldown, are ignored in favour of the values on the configuration object.max_settlement_amount (Optional[decimal.Decimal]) – Optional maximum gross Lagoon settlement for one asset-manager module transaction, expressed in human-readable underlying-token units as a
Decimal.Nonekeeps unlimited backwards-compatible behaviour. SeeLagoonConfig.max_settlement_amountfor security semantics and supported topology.settlement_cooldown (int) – Positive minimum delay in seconds between non-zero capped asset-manager settlements. Defaults to 24 hours. Empty settlements do not start or wait for it. Ignored when the maximum amount safety feature is disabled.
guard_only (bool) – Deploy a new version of the guard smart contract and skip deploying the actual vault.
from_the_scratch (bool) –
Need to deloy a fee registry contract as well.
A new chain deployment.
safe_salt_nonce (Optional[int]) – If set, deploy the Safe using CREATE2 via the canonical SafeProxyFactory for a deterministic address. Use the same value across chains to get the same Safe address everywhere.
safe_proxy_factory_address (Optional[Union[eth_typing.evm.HexAddress, str]]) – Override the Safe ProxyFactory address. Defaults to the canonical v1.4.1 factory (
0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67). See Safe canonical deployments and Safe contract deployment docs.web3 (web3.main.Web3) –
deployer (Union[eth_account.signers.local.LocalAccount, eth_defi.hotwallet.HotWallet]) –
asset_manager (Optional[eth_typing.evm.HexAddress]) –
asset_managers (Optional[list[eth_typing.evm.HexAddress | str]]) –
parameters (Optional[eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonDeploymentParameters]) –
safe_owners (Optional[list[eth_typing.evm.HexAddress | str]]) –
uniswap_v2 (Optional[eth_defi.uniswap_v2.deployment.UniswapV2Deployment]) –
uniswap_v3 (Optional[eth_defi.uniswap_v3.deployment.UniswapV3Deployment]) –
aave_v3 (Optional[eth_defi.aave_v3.deployment.AaveV3Deployment]) –
cowswap (bool) –
velora (bool) –
gmx_deployment (Optional[eth_defi.gmx.whitelist.GMXDeployment]) –
lighter_deployment (Optional[eth_defi.lighter.deployment.LighterDeployment]) –
cctp_deployment (Optional[eth_defi.cctp.whitelist.CCTPDeployment]) –
hypercore_vaults (Optional[list[eth_typing.evm.HexAddress | str]]) –
any_asset (bool) –
etherscan_api_key (str) –
verifier (Optional[Literal['etherscan', 'blockscout', 'sourcify', 'oklink']]) –
erc_4626_vaults (Optional[list[eth_defi.erc_4626.vault.ERC4626Vault]]) –
existing_vault_address (Optional[Union[eth_typing.evm.HexAddress, str]]) –
existing_safe_address (Optional[Union[eth_typing.evm.HexAddress, str]]) –
assets (Optional[list[eth_typing.evm.HexAddress | str]]) –
- Return type
eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonAutomatedDeployment
- LAGOON_BEACON_PROXY_FACTORIES = {1: {'abi': 'lagoon/OptinProxyFactory.json', 'address': '0x8D6f5479B14348186faE9BC7E636e947c260f9B1'}, 143: {'abi': 'lagoon/OptinProxyFactory.json', 'address': '0xcCdC4d06cA12A29C47D5d105fED59a6D07E9cf70'}, 957: {'abi': 'lagoon/BeaconProxyFactory.json', 'address': '0x4058140097F313886536bd64a7C1D25FF7356931'}, 999: {'abi': 'lagoon/OptinProxyFactory.json', 'address': '0x90beB507A1BA7D64633540cbce615B574224CD84'}, 8453: {'abi': 'lagoon/BeaconProxyFactory.json', 'address': '0xC953Fd298FdfA8Ed0D38ee73772D3e21Bf19c61b'}, 42161: {'abi': 'lagoon/OptinProxyFactory.json', 'address': '0xb1ee4f77a1691696a737ab9852e389cf4cb1f1f5'}}
https://basescan.org/address/0xC953Fd298FdfA8Ed0D38ee73772D3e21Bf19c61b#writeContract https://docs.lagoon.finance/vault/create-your-vault
- deploy_multichain_lagoon_vault(*, chain_web3, deployer, chain_configs, max_workers=None)
Deploy Lagoon vaults across multiple chains with a shared deterministic Safe.
Uses CREATE2 via the canonical Safe v1.4.1 ProxyFactory to produce the same Safe address on every chain. Every chain gets a distinct Safe contract and guard module at matching addresses. Non-satellite chains additionally get a Lagoon vault paired with that chain’s Safe.
Deploys all chains in parallel using threads to minimise wall-clock time.
Each chain receives its own
LagoonConfigwith chain-specific whitelisting (ERC-4626 vaults, Hypercore vaults, CCTP, CowSwap, etc.) and an optional chain-specific Lagoon settlement safety policy. All configs must share the samesafe_salt_nonceto ensure deterministic Safe addresses.LagoonConfig.max_settlement_amountand its cooldown are forwarded to the public single-chain deployment API and is converted using that chain’s underlying token decimals. Configure it only for chains which deploy or reuse a Lagoon vault. Satellite chains contain only a Safe and guard module and therefore reject settlement-safety configuration instead of silently ignoring it.- Parameters
chain_web3 (dict[str, web3.main.Web3]) – Mapping of chain names (lowercase, matching
eth_defi.chain.CHAIN_NAMES) to Web3 instances. Example:{"ethereum": w3_eth, "arbitrum": w3_arb}.deployer (eth_account.signers.local.LocalAccount) – The deployer account. A separate
HotWalletis created per chain for nonce management.chain_configs (dict[str, eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonConfig]) – Per-chain
LagoonConfiginstances. Keys must matchchain_web3keys. All configs must have the samesafe_salt_nonceset. Theparameters.underlyingfield is auto-resolved per chain frometh_defi.token.USDC_NATIVE_TOKENif set to a zero/empty address. Setmax_settlement_amountindependently on each non-satellite config to enable the atomic gross-settlement cap and cooldown safety feature for that chain’s Lagoon vault.max_workers (Optional[int]) – Maximum number of parallel deployment threads. Defaults to the number of chains.
- Returns
LagoonMultichainDeploymentwith per-chain results.- Return type
eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonMultichainDeployment