Skip to content

Commit

Permalink
Guarded vault deployment event (#194)
Browse files Browse the repository at this point in the history
- Allow track to vault deployments
- Have a production flag to signal open deployments
  • Loading branch information
miohtama authored Jan 26, 2024
1 parent 064c006 commit df5419c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
23 changes: 22 additions & 1 deletion contracts/in-house/src/GuardedGenericAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ contract GuardedGenericAdapter is AdapterBase {
// Guard implementation associated with this vault
IGuard public guard;

// Is this vault intended for the production usage
//
// Should the vault to be indexed in DeFi explorers
//
bool public production;

// Post an event to track what are Trading Strategy vaults.
//
// We can use these protoc events to track vaults that belong to
// the protocol, as currently Enzyme does not allow
// to add easy metadata to its vaults.
//
// Also this event with production flag can be used to signal
// DeFi explorers.
//
event GuardedGenericAdapterDeployed(address vault, bool production, string meta);

// Tell enzyme what is our selector when we call this adapter
bytes4 public constant EXECUTE_CALLS_SELECTOR = bytes4(
keccak256("executeCalls(address,bytes,bytes)")
Expand All @@ -64,12 +81,16 @@ contract GuardedGenericAdapter is AdapterBase {
// Because this is called only once and damage cannot be done
// except maybe screwing up the deployment, we do not track ownership here.
//
function bindVault(IVaultMock _vault) external {
function bindVault(IVaultMock _vault, bool _production, string calldata meta) external {
require(address(vault) == address(0x0), "Can be initialised only once");
require(address(_vault) != address(0x0), "Null address encountered");
// Sanity check for smart contract integration - mainly checks vault providers getCreator() as an interface check
require(_vault.getCreator() != address(0x0), "Encountered funny vault");
vault = _vault;

production = _production;

emit GuardedGenericAdapterDeployed(address(vault), production, meta);
}

// EXTERNAL FUNCTIONS
Expand Down
2 changes: 1 addition & 1 deletion eth_defi/abi/GuardedGenericAdapter.json

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion eth_defi/enzyme/generic_adapter_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def deploy_vault_with_generic_adapter(
fund_symbol="EXAMPLE",
whitelisted_assets: Collection[TokenDetails] | None = None,
etherscan_api_key: str | None = None,
production=False,
meta: str = "",
) -> Vault:
"""Deploy an Enzyme vault and make it secure.
Expand Down Expand Up @@ -93,6 +95,12 @@ def deploy_vault_with_generic_adapter(
:param etherscan_api_key:
Needed to verify deployed contracts.
:param production:
Production flag set on `GuardedGenericAdapterDeployed` event.
:param meta:
Metadata for `GuardedGenericAdapterDeployed` event.
:return:
Freshly deployed vault
"""
Expand Down Expand Up @@ -196,7 +204,11 @@ def deploy_vault_with_generic_adapter(

# Give generic adapter back reference to the vault
assert vault.functions.getCreator().call() != ZERO_ADDRESS, f"Bad vault creator {vault.functions.getCreator().call()}"
tx_hash = generic_adapter.functions.bindVault(vault.address).transact({"from": deployer.address})
tx_hash = generic_adapter.functions.bindVault(
vault.address,
production,
meta,
).transact({"from": deployer.address})
assert_transaction_success_with_explanation(web3, tx_hash)

receipt = web3.eth.get_transaction_receipt(tx_hash)
Expand Down
4 changes: 4 additions & 0 deletions scripts/enzyme/deploy-vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
.. code-block:: shell
export SIMULATE=true
# Set production=true flag - affects GuardedGenericAdapterDeployed event
export PRODUCTION=true
export FUND_NAME="TradingStrategy.ai ETH Breakpoint I"
export FUND_SYMBOL=TS1
export TERMS_OF_SERVICE=0xDCD7C644a6AA72eb2f86781175b18ADc30Aa4f4d
Expand Down Expand Up @@ -94,6 +96,7 @@ def main():
fund_symbol = os.environ["FUND_SYMBOL"]
etherscan_api_key = os.environ.get("ETHERSCAN_API_KEY")
simulate = True if os.environ.get("SIMULATE", "").strip() else False
production = True if os.environ.get("PRODUCTION", "").strip() else False

if simulate:
logger.info("Simulating deployment")
Expand Down Expand Up @@ -179,6 +182,7 @@ def main():
fund_name=fund_name,
fund_symbol=fund_symbol,
whitelisted_assets=whitelisted_assets,
production=production,
)

if anvil:
Expand Down

0 comments on commit df5419c

Please sign in to comment.