deploy
Documentation for eth_defi.deploy Python module.
Deploy any precompiled contract.
See Github for available contracts.
Module Attributes
Default library addresses for deploying guard contracts (SimpleVaultV0, TradingStrategyModuleV0). |
|
Forge |
|
Forge |
Functions
|
Build |
|
Deploys a new contract from ABI file. |
Get a contract registry associated with a Web3 connection. |
|
|
Get a contract that was deployed with the registry. |
|
Register a contract for tracing. |
Exceptions
Did not get successful tx receipt from a deployment. |
- GUARD_LIBRARIES: dict[str, str] = {'CowSwapLib': '0x0000000000000000000000000000000000000000', 'GmxLib': '0x0000000000000000000000000000000000000000', 'HypercoreVaultLib': '0x0000000000000000000000000000000000000000', 'UniswapLib': '0x0000000000000000000000000000000000000000', 'VeloraLib': '0x0000000000000000000000000000000000000000'}
Default library addresses for deploying guard contracts (SimpleVaultV0, TradingStrategyModuleV0).
All external Forge libraries are linked to
ZERO_ADDRESSso the bytecode resolves cleanly. Tests that exercise a specific library should override the relevant entry with the real deployed address.
- GUARD_FORGE_LIBRARY_SOURCES: dict[str, str] = {'CowSwapLib': 'src/lib/CowSwapLib.sol:CowSwapLib', 'GmxLib': 'src/lib/GmxLib.sol:GmxLib', 'HypercoreVaultLib': 'src/lib/HypercoreVaultLib.sol:HypercoreVaultLib', 'UniswapLib': 'src/lib/UniswapLib.sol:UniswapLib', 'VeloraLib': 'src/lib/VeloraLib.sol:VeloraLib'}
Forge
--librariessource paths for the guard project.Maps library name to
source_path:LibraryNameas seen by the compiler.
- SAFE_INTEGRATION_FORGE_LIBRARY_SOURCES: dict[str, str] = {'CowSwapLib': '../guard/src/lib/CowSwapLib.sol:CowSwapLib', 'GmxLib': '../guard/src/lib/GmxLib.sol:GmxLib', 'HypercoreVaultLib': '../guard/src/lib/HypercoreVaultLib.sol:HypercoreVaultLib', 'UniswapLib': '../guard/src/lib/UniswapLib.sol:UniswapLib', 'VeloraLib': '../guard/src/lib/VeloraLib.sol:VeloraLib'}
Forge
--librariessource paths for the safe-integration project.The guard sources are referenced via
../guard/src/becauseremappings.txtmaps@guard=../guard/src.
- build_guard_forge_libraries(library_addresses=None, project='guard')
Build
forge_librariesmapping foreth_defi.foundry.forge.deploy_contract_with_forge().Returns a dict of
"source_path:LibraryName" -> addresssuitable for the--librariesflag offorge create.- Parameters
library_addresses (dict[str, str] | None) – Overrides for specific libraries. Keys are library names (e.g.
"CowSwapLib"), values are deployed addresses. Libraries not listed default toZERO_ADDRESS.project (str) –
"guard"or"safe-integration", determines source paths.
- Return type
- ContractRegistry
Manage internal registry of deployed contracts
Lower case address -> Contract mapping.
- exception ContractDeploymentFailed
Bases:
ExceptionDid not get successful tx receipt from a deployment.
- __init__(tx_hash, msg)
- __new__(**kwargs)
- add_note()
Exception.add_note(note) – add a note to the exception
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- deploy_contract(web3, contract, deployer, *constructor_args, register_for_tracing=True, gas=None, confirm=True, libraries=None)
Deploys a new contract from ABI file.
A generic helper function to deploy any contract.
Example:
token = deploy_contract(web3, deployer, "ERC20Mock.json", name, symbol, supply) print(f"Deployed ERC-20 token at {token.address}")
For contracts that require Forge library linking:
# Deploy the library first, then link it lib = deploy_contract(web3, "guard/HypercoreVaultLib.json", deployer) vault = deploy_contract( web3, "guard/SimpleVaultV0.json", deployer, asset_manager, libraries={"HypercoreVaultLib": lib.address}, ) # Or link with zero address if the library is never called on this chain from eth_defi.abi import ZERO_ADDRESS vault = deploy_contract( web3, "guard/SimpleVaultV0.json", deployer, asset_manager, libraries={"HypercoreVaultLib": ZERO_ADDRESS}, )
If you need to verify the deployed contract use
eth_defi.foundry.forge.deploy_contract_with_forge().- Parameters
web3 (web3.main.Web3) – Web3 instance
contract (Union[str, web3.contract.contract.Contract]) – Contract file path as string or contract proxy class
deployer (str | eth_account.signers.local.LocalAccount | eth_defi.hotwallet.HotWallet) –
Deployer account.
Either address (use
construct_sign_and_send_raw_middleware) or LocalAccount.constructor_args – Other arguments to pass to the contract’s constructor
register_for_tracing –
Make the symbolic contract information available on web3 instance.
See
get_contract_registry()gas (int) –
Gas limit.
If not set tries to estimate and probably may hit reverts when doing so.
confirm – Confirm the contract deployment.
libraries (dict[str, str] | None) – Forge library linking addresses. Mapping of library name to deployed address for resolving
__$<hash>$__placeholders in Forge-compiled bytecode. UseZERO_ADDRESSfor libraries that are never called on the target chain.
- Raises
ContractDeploymentFailed – In the case we could not deploy the contract.
- Returns
Contract proxy instance or tx_hash if confirm=false.
- Return type
web3.contract.contract.Contract | hexbytes.main.HexBytes
- get_or_create_contract_registry(web3)
Get a contract registry associated with a Web3 connection.
Only relevant for test sessions
Assumes one web3 instance per test
Useful to make traces symbolic in
eth_defi.trace
- register_contract(web3, address, instance)
Register a contract for tracing.
See
deploy_contract().- Parameters
address (eth_typing.evm.HexAddress) –
instance (web3.contract.contract.Contract) –
- get_registered_contract(web3, address)
Get a contract that was deployed with the registry.
Resolve a symbolic contract information based on the contract address and our contract registry
See
eth_defi.deploy.deploy_contract()how to deploy a registered contract
Example:
from eth_defi.deploy import get_registered_contract contract = get_registered_contract(web3, "0x1613beb3b2c4f22ee086b2b38c1476a3ce7f78e8") assert contract.name == "VaultSpecificGenericAdapter"
- Parameters
address (str) – Contract address as a hex string
- Returns
The known Contract instance at the registry or None if the contract was not registered/deployed through registry mechanism.
- Return type
web3.contract.contract.Contract