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.
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. |
|
Setups up TradingStrategyModuleV0 guard on the Lagoon vault. |
|
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. |
- class LagoonAutomatedDeployment
Bases:
objectCapture information of the lagoon automated deployment.
Have the deployment report for the users for diagnostics
- __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
- property asset_manager: eth_typing.evm.HexAddress
Get the primary asset manager.
Kept for backwards compatibility with single-key deployments.
- format_whitelisted_items(indent=' ')
Format whitelisted items as a human-readable string.
- get_deployment_data()
Get JSON data describing the deployment.
Store all addresses etc.
- Return type
- 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).- __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, 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, 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]) –
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) –
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 LagoonDeploymentParameters
Bases:
objectCapture core parameters needed to deploy a Lagoon vault
- __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
- 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
- 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.
- __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_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, 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)
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.
- Parameters
config (Optional[eth_defi.erc_4626.vault_protocol.lagoon.deployment.LagoonConfig]) – Pass a
LagoonConfigobject instead of individual kwargs. When provided, individual kwargs are ignored.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]) –
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
- 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)
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.
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
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 “lagoon/Vault.json” for 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_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_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. Each chain gets its own vault and guard deployment, but all vaults share the same Safe multisig address.
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.). All configs must share the samesafe_salt_nonceto ensure deterministic Safe addresses.- 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.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
- 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)
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.
- 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.
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]) –
- 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, cctp_deployment=None, hypercore_vaults=None, hack_sleep=20.0, assets=None, multicall_chunk_size=40, underlying_token_address=None)
Setups up TradingStrategyModuleV0 guard on the Lagoon vault.
Creates the guard smart contract (TradingStrategyModuleV0) and enables it on the Safe multisig as a module.
Runs through various whitelisting rules as transactions against this contract
- Parameters
vault (Optional[web3.contract.contract.Contract]) – The deployed Lagoon vault contract.
Noneon satellite chains.underlying_token_address (Optional[eth_typing.evm.HexAddress]) – Underlying token address for Hypercore whitelisting when vault is None.
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]) –
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]
- 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.