Skip to content

Commit

Permalink
More enzyme deployment (#193)
Browse files Browse the repository at this point in the history
- Create `deploy_contract_with_forge` to be able to do Etherscan verified deployments
- Convert Enzyme vault deployment toolchain to use `deploy_contract_with_forge`
- Add some quality of life improvements to APIs
  • Loading branch information
miohtama authored Jan 26, 2024
1 parent 74478ee commit f70b31d
Show file tree
Hide file tree
Showing 24 changed files with 790 additions and 78 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

steps:
# TODO: we only need contracts/aave-v3-deploy for tests
# but there does not seem to be an option to choose which submodules to checkout
Expand All @@ -33,6 +32,16 @@ jobs:
node-version: 16
cache: 'npm'
cache-dependency-path: contracts/aave-v3-deploy/package-lock.json

# pnpm needed to compile Enzyme
# We need version 7 to be exact.
- name: Install pnpm
run: |
curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=7.27.1 sh -
PNPM_HOME="/home/runner/.local/share/pnpm"
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path
echo $PNPM_HOME >> $GITHUB_PATH
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.12
Expand All @@ -57,6 +66,11 @@ jobs:
run: |
poetry run install-aave-for-testing
# We also work around race condition for setting up Aave NPM packages.
- name: Build needed contracts
run: |
pnpm --version
make guard in-house
# Run tests parallel.
- name: Run test scripts
run: |
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Current

- Bump web3.py to 6.12.x
- Add Foundry and Forge integration: `deploy_contract_with_forge()`
- Add initial Etherscan integration
- Add [Terms of Service acceptance manager integration](https://github.com/tradingstrategy-ai/terms-of-service)
- Add GuardV0 and SimpleVaultV0 implementations for creating safe automated asset managers
- Add support for Enzyme policies
Expand Down
18 changes: 17 additions & 1 deletion contracts/guard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,20 @@ forge build

Because of complex the integrations, tests are part of `eth_defi` package
test suite, which provides fixtures to ramp up various protocols (Enzyme, Uniswap, Aave, 1delta).
Please refer to [eth_defi developer documentation]https://web3-ethereum-defi.readthedocs.io/) how to run tests.
Please refer to [eth_defi developer documentation]https://web3-ethereum-defi.readthedocs.io/) how to run tests.

## Deployment

Example:

```shell
export DEPLOY_PRIVATE_KEY=
export JSON_RPC_POLYGON=
export POLYGONSCAN_API_KEY=
forge create \
--rpc-url $JSON_RPC_POLYGON \
--private-key $DEPLOY_PRIVATE_KEY \
--etherscan-api-key $POLYGONSCAN_API_KEY \
--verify \
src/GuardV0.sol:GuardV0
```
1 change: 1 addition & 0 deletions contracts/guard/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ out = "out"
libs = ["lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
solc_version = "0.8.23"
13 changes: 13 additions & 0 deletions docs/source/tutorials/enzyme-deploy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. meta::
:title: Programmatically deploy Enzyme vault
:description: Tutorial for deploying Enzyme vaults in Python

.. _enzyme-deploy:

Enzyme vault deployment
=======================



.. literalinclude:: ../../../scripts/enzyme/deploy-vault.py
:language: python
2 changes: 1 addition & 1 deletion eth_defi/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def get_linked_contract(

def get_deployed_contract(
web3: Web3,
fname: str,
fname: str | Path,
address: Union[HexAddress, str],
register_for_tracing: bool = True,
) -> Contract:
Expand Down
5 changes: 4 additions & 1 deletion eth_defi/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
`See Github for available contracts <https://github.com/tradingstrategy-ai/web3-ethereum-defi/tree/master/eth_defi/abi>`_.
"""

from pathlib import Path
from shutil import which
from typing import Dict, TypeAlias, Union

from eth_typing import HexAddress
Expand Down Expand Up @@ -92,6 +93,8 @@ def deploy_contract(
return instance




def get_or_create_contract_registry(web3: Web3) -> ContractRegistry:
"""Get a contract registry associated with a Web3 connection.
Expand Down
11 changes: 9 additions & 2 deletions eth_defi/enzyme/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,11 @@ def fetch_vault(self, vault_address: HexAddress | str) -> Tuple[Contract, Contra
return comptroller, vault

@staticmethod
def fetch_deployment(web3: Web3, contract_addresses: dict) -> "EnzymeDeployment":
def fetch_deployment(
web3: Web3,
contract_addresses: dict,
deployer: HexAddress | str | None = None,
) -> "EnzymeDeployment":
"""Fetch enzyme deployment and some of its contract.
Read existing Enzyme deployment from on-chain.
Expand All @@ -570,6 +574,9 @@ def fetch_deployment(web3: Web3, contract_addresses: dict) -> "EnzymeDeployment"
:param contract_addresses:
Dictionary of contract addresses required to resolve Enzyme deployment
:param deployer:
Associate a deployer account with this Enzyme deployment to deploy new vaults.
:return:
Enzyme deployment details
Expand Down Expand Up @@ -608,7 +615,7 @@ def fetch_deployment(web3: Web3, contract_addresses: dict) -> "EnzymeDeployment"

return EnzymeDeployment(
web3,
None,
deployer,
contracts,
mln,
weth,
Expand Down
Loading

0 comments on commit f70b31d

Please sign in to comment.