Skip to content

Commit

Permalink
Add Foundry and Etherscan to the API documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Feb 1, 2024
1 parent cb55744 commit 4aba3b0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 12 deletions.
18 changes: 18 additions & 0 deletions docs/source/api/etherscan/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Etherscan API
-------------

This is documentation for Web3.py and Etherscan integration.

.. note ::
Currently there does not exist direct Etherscan APIs that would be relevant for web3.py.
For verying contracts on Etherscan and others see :py:func:`eth_defi.foundry.forge.deploy_contract_with_forge`

.. autosummary::
:toctree: _autosummary_etherscan
:recursive:

eth_defi.etherscan.verify


19 changes: 19 additions & 0 deletions docs/source/api/foundry/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Foundry API
-----------

Integration Foundry smart contract development toolchain with Web3.py.

- Use `forge` to build, deploy and verify smart contracts with Web3.py

- Anvil integration is in a separate module :py:mod:`eth_defi.rpc.anvil`

- See `Foundry book <https://book.getfoundry.sh/>`__ for more information.


.. autosummary::
:toctree: _autosummary_forge
:recursive:

eth_defi.foundry.forge


2 changes: 2 additions & 0 deletions docs/source/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ API documentation
one_delta/index
enzyme/index
chainlink/index
foundry/index
etherscan/index
event_reader/index
price_oracle/index
data_research/index
Expand Down
7 changes: 6 additions & 1 deletion eth_defi/etherscan/verify.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""Etherscan integration.
Currently TODO. Meanwhile use :py:func:`eth_defi.deploy.deploy_contract_with_forge` to deploy contracts that are verified on Etherscan.
.. note ::
Currently no Web3.py direct integration available.
Use :py:func:`eth_defi.foundry.forge.deploy_contract_with_forge` to deploy contracts that are verified on Etherscan.
"""
36 changes: 25 additions & 11 deletions eth_defi/foundry/forge.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""Forge toolchain integration.
"""Forge smart contracte development toolchain integration.
- Compile and deploy smart contracts using Forge
- Verify smart contracts on Etherscan
- See `Foundry book <https://book.getfoundry.sh/>`__ for more information.
"""
import contextlib
import datetime
import io
import logging
import os

from pathlib import Path
from shutil import which
from subprocess import DEVNULL, PIPE
from typing import Collection, Tuple
from typing import Tuple

import psutil
from eth_typing import ChecksumAddress, HexAddress, HexStr
Expand All @@ -22,11 +22,11 @@
from web3.contract import Contract

from eth_defi.abi import get_deployed_contract
from eth_defi.confirmation import wait_transactions_to_complete
from eth_defi.deploy import register_contract
from eth_defi.hotwallet import HotWallet
from eth_defi.trace import assert_transaction_success_with_explanation


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -101,7 +101,9 @@ def deploy_contract_with_forge(
timeout=DEFAULT_TIMEOUT,
wait_for_block_confirmations=0,
) -> Tuple[Contract, HexBytes]:
"""Deploys a new contract using Forge command from Foundry.
"""Deploy and verify smart contract with Forge.
- The smart contracts must be developed with Foundry tool chain and its `forge` command
- Uses Forge to verify the contract on Etherscan
Expand All @@ -111,11 +113,23 @@ def deploy_contract_with_forge(
.. code-block:: python
token = deploy_contract(web3, deployer, "ERC20Mock.json", name, symbol, supply)
print(f"Deployed ERC-20 token at {token.address}")
guard, tx_hash = deploy_contract_with_forge(
web3,
CONTRACTS_ROOT / "guard", # Foundry projec path
"GuardV0.sol", # src/GuardV0.sol
f"GuardV0", # GuardV0 is the smart contract name
deployer, # Local account with a private key we use for the deployment
etherscan_api_key=etherscan_api_key, # Etherscan API key we use for the verification
)
logger.info("GuardV0 is %s deployed at %s", guard.address, tx_hash.hex())
# Test the deployed contract
assert guard.functions.getInternalVersion().call() == 1
Assumes standard Foundry project layout with foundry.toml, src and out.
See `Foundry book <https://book.getfoundry.sh/>`__ for more information.
:param web3:
Web3 instance
Expand All @@ -125,17 +139,17 @@ def deploy_contract_with_forge(
We need to be able to manually track the nonce across multiple contract deployments.
:param project_folder:
Foundry project with ``foundry.toml` in the root.
Foundry project with `foundry.toml` in the root.
:param contract_file:
Contract path relative to the project folder.
E.g. `ermsOfService.sol`.
E.g. `TermsOfService.sol`.
:param contract_name:
The smart contract name within the file.
E.g. `TermsOfServce`.
E.g. `TermsOfService`.
:param constructor_args:
Other arguments to pass to the contract's constructor.
Expand Down

0 comments on commit 4aba3b0

Please sign in to comment.