Skip to content

Commit

Permalink
feat: upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 15, 2023
1 parent 669fa22 commit ff0e6dc
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 186 deletions.
1 change: 0 additions & 1 deletion .mdformat.toml

This file was deleted.

4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 23.11.0
rev: 23.12.0
hooks:
- id: black
name: black
Expand All @@ -21,7 +21,7 @@ repos:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.0
rev: v1.7.1
hooks:
- id: mypy
additional_dependencies: [types-requests, types-setuptools, pydantic, types-pkg-resources]
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ solidity:
version: 0.8.14
```
### EVM Versioning
By default, `ape-solidity` will use whatever version of EVM rules are set as default in the compiler version that gets used.
Sometimes, you might want to use a different version, such as deploying on Arbitrum or Optimism where new opcodes are not supported yet.
If you want to require a different version of EVM rules to use in the configuration of the compiler, set it in your `ape-config.yaml` like this:

```yaml
solidity:
evm_version: paris
```

### Dependency Mapping

To configure import remapping, use your project's `ape-config.yaml` file:
Expand Down Expand Up @@ -86,8 +97,8 @@ Use the `add_library()` method from the `ape-solidity` compiler class to add the
A typical flow is:

1. Deploy the library.
2. Call `add_library()` using the Solidity compiler plugin, which will also re-compile contracts that need the library.
3. Deploy and use contracts that require the library.
1. Call `add_library()` using the Solidity compiler plugin, which will also re-compile contracts that need the library.
1. Deploy and use contracts that require the library.

For example:

Expand All @@ -100,7 +111,7 @@ def contract(accounts, project, compilers):
# Deploy the library.
account = accounts[0]
library = project.Set.deploy(sender=account)
# Add the library to Solidity (re-compiles contracts that use the library).
compilers.solidity.add_library(library)
Expand Down
9 changes: 6 additions & 3 deletions ape_solidity/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from pathlib import Path
from typing import Dict, List, Optional, Sequence, Set, Union

from ape._pydantic_compat import BaseModel, validator
from ape.exceptions import CompilerError
from ape.logging import logger
from packaging.specifiers import SpecifierSet
from packaging.version import InvalidVersion
from packaging.version import Version
from packaging.version import Version as _Version
from pydantic import BaseModel, field_validator
from solcx.install import get_executable
from solcx.wrapper import get_solc_version as get_solc_version_from_binary

Expand All @@ -36,7 +36,8 @@ class ImportRemapping(BaseModel):
entry: str
packages_cache: Path

@validator("entry")
@field_validator("entry", mode="before")
@classmethod
def validate_entry(cls, value):
if len((value or "").split("=")) != 2:
raise IncorrectMappingFormatError()
Expand Down Expand Up @@ -93,6 +94,8 @@ def package_id(self) -> Path:

class ImportRemappingBuilder:
def __init__(self, contracts_cache: Path):
# import_map maps import keys like `@openzeppelin/contracts`
# to str paths in the contracts' .cache folder.
self.import_map: Dict[str, str] = {}
self.dependencies_added: Set[Path] = set()
self.contracts_cache = contracts_cache
Expand Down Expand Up @@ -215,7 +218,7 @@ def add_commit_hash(version: Union[str, Version]) -> Version:
return get_solc_version_from_binary(solc, with_commit_hash=True)


def verify_contract_filepaths(contract_filepaths: List[Path]) -> Set[Path]:
def verify_contract_filepaths(contract_filepaths: Sequence[Path]) -> Set[Path]:
invalid_files = [p.name for p in contract_filepaths if p.suffix != Extension.SOL.value]
if not invalid_files:
return set(contract_filepaths)
Expand Down
Loading

0 comments on commit ff0e6dc

Please sign in to comment.