Skip to content

Commit

Permalink
♻️ Implement Dunder __interface__ Method and Remove userdoc and `…
Browse files Browse the repository at this point in the history
…devdoc` Sanity Check (#235)

### 🕓 Changelog

This PR refactors the existing module-friendly contracts to use the new
dunder method `__interface__` (see
vyperlang/vyper#3919), which allows you to
export all functions of a module without specifying the individual
functions.

We apply the following rules:

- Library modules keep the individual list `exports` syntax due to
explicitness (application developers can thus identify faster what is
exported within a library module),
- Mocks might use it if more than one `external` function is exported.
We do not use it in mock contracts if critical code comments for
exported functions would be lost.

Furthermore, we remove the `userdoc` and `devdoc` compilation script &
CI pipeline since it's now computed as part of the standard compilation
pipeline (vyperlang/vyper#3946).

---------

Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
Co-authored-by: sudo rm -rf --no-preserve-root / <pcaversaccio@users.noreply.github.com>
Co-authored-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
  • Loading branch information
3 people authored Apr 15, 2024
1 parent 46c45eb commit b5126de
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 267 deletions.
290 changes: 145 additions & 145 deletions .gas-snapshot

Large diffs are not rendered by default.

16 changes: 1 addition & 15 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ jobs:
- ubuntu-latest
architecture:
- x64
python_version:
- 3.11
node_version:
- 20

Expand Down Expand Up @@ -54,18 +52,6 @@ jobs:
- name: Prettier and lint
run: pnpm lint:check

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
architecture: ${{ matrix.architecture }}

- name: Check formatting with Black
uses: psf/black@stable
with:
options: "--check --verbose"
src: "./scripts"

codespell:
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -108,6 +94,6 @@ jobs:
- name: Validate URLs
run: |
awesome_bot ./*.md src/snekmate/**/*.vy src/snekmate/**/mocks/*.vy src/snekmate/**/interfaces/*.vyi \
test/**/*.sol test/**/interfaces/*.sol test/**/mocks/*.sol test/**/scripts/*.js scripts/*.py \
test/**/*.sol test/**/interfaces/*.sol test/**/mocks/*.sol test/**/scripts/*.js \
--allow-dupe --allow-redirect --request-delay 0.4 \
--white-list https://www.wagmi.xyz,https://github.com/pcaversaccio/snekmate.git@,https://github.com/pcaversaccio/snekmate/releases/tag/v0.1.0,https://github.com/pcaversaccio/snekmate/blob/v0.1.0,https://github.com/pcaversaccio/snekmate/compare/v0.0.5...v0.1.0
1 change: 0 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
- ubuntu-latest
language:
- javascript-typescript
- python

steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
- name: Install Vyper
run: pip install git+https://github.com/vyperlang/vyper.git@master

- name: Check userdoc and devdoc compilation
run: python scripts/compile.py
- name: Show the Vyper version
run: vyper --version

# - name: Setup Ape
# uses: ApeWorX/github-action@v2
Expand Down
9 changes: 0 additions & 9 deletions scripts/compile.py

This file was deleted.

11 changes: 1 addition & 10 deletions src/snekmate/auth/AccessControl.vy
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,7 @@
from snekmate.auth import AccessControl as access_control
initializes: access_control
exports: (
access_control.DEFAULT_ADMIN_ROLE,
access_control.supportsInterface,
access_control.hasRole,
access_control.getRoleAdmin,
access_control.grantRole,
access_control.revokeRole,
access_control.renounceRole,
access_control.set_role_admin,
)
exports: access_control.__interface__
...
Expand Down
20 changes: 9 additions & 11 deletions src/snekmate/auth/mocks/AccessControlMock.vy
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,19 @@ initializes: ac
# @dev We export (i.e. the runtime bytecode exposes these
# functions externally, allowing them to be called using
# the ABI encoding specification) all `external` functions
# from the `AccessControl` module.
# from the `AccessControl` module. The built-in dunder method
# `__interface__` allows you to export all functions of a
# module without specifying the individual functions (see
# https://github.com/vyperlang/vyper/pull/3919). Please take
# note that if you do not know the full interface of a module
# contract, you can get the `.vyi` interface in Vyper by using
# `vyper -f interface yourFileName.vy` or the external interface
# by using `vyper -f external_interface yourFileName.vy`.
# @notice Please note that you must always also export (if
# required by the contract logic) `public` declared `constant`,
# `immutable`, and state variables, for which Vyper automatically
# generates an `external` getter function for the variable.
exports: (
ac.DEFAULT_ADMIN_ROLE,
ac.supportsInterface,
ac.hasRole,
ac.getRoleAdmin,
ac.grantRole,
ac.revokeRole,
ac.renounceRole,
ac.set_role_admin,
)
exports: ac.__interface__


# @dev The 32-byte minter role.
Expand Down
17 changes: 9 additions & 8 deletions src/snekmate/auth/mocks/Ownable2StepMock.vy
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ initializes: o2[ownable := ow]
# @dev We export (i.e. the runtime bytecode exposes these
# functions externally, allowing them to be called using
# the ABI encoding specification) all `external` functions
# from the `Ownable2Step` module.
# from the `Ownable2Step` module. The built-in dunder method
# `__interface__` allows you to export all functions of a
# module without specifying the individual functions (see
# https://github.com/vyperlang/vyper/pull/3919). Please take
# note that if you do not know the full interface of a module
# contract, you can get the `.vyi` interface in Vyper by using
# `vyper -f interface yourFileName.vy` or the external interface
# by using `vyper -f external_interface yourFileName.vy`.
# @notice Please note that you must always also export (if
# required by the contract logic) `public` declared `constant`,
# `immutable`, and state variables, for which Vyper automatically
# generates an `external` getter function for the variable.
exports: (
o2.owner,
o2.pending_owner,
o2.transfer_ownership,
o2.accept_ownership,
o2.renounce_ownership,
)
exports: o2.__interface__


@deploy
Expand Down
15 changes: 9 additions & 6 deletions src/snekmate/auth/mocks/OwnableMock.vy
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ initializes: ow
# @dev We export (i.e. the runtime bytecode exposes these
# functions externally, allowing them to be called using
# the ABI encoding specification) all `external` functions
# from the `Ownable` module.
# from the `Ownable` module. The built-in dunder method
# `__interface__` allows you to export all functions of a
# module without specifying the individual functions (see
# https://github.com/vyperlang/vyper/pull/3919). Please take
# note that if you do not know the full interface of a module
# contract, you can get the `.vyi` interface in Vyper by using
# `vyper -f interface yourFileName.vy` or the external interface
# by using `vyper -f external_interface yourFileName.vy`.
# @notice Please note that you must always also export (if
# required by the contract logic) `public` declared `constant`,
# `immutable`, and state variables, for which Vyper automatically
# generates an `external` getter function for the variable.
exports: (
ow.owner,
ow.transfer_ownership,
ow.renounce_ownership,
)
exports: ow.__interface__


@deploy
Expand Down
45 changes: 9 additions & 36 deletions src/snekmate/governance/mocks/TimelockControllerMock.vy
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,19 @@ initializes: tc[access_control := ac]
# @dev We export (i.e. the runtime bytecode exposes these
# functions externally, allowing them to be called using
# the ABI encoding specification) all `external` functions
# from the `TimelockController` module.
# from the `TimelockController` module. The built-in dunder
# method `__interface__` allows you to export all functions
# of a module without specifying the individual functions (see
# https://github.com/vyperlang/vyper/pull/3919). Please take
# note that if you do not know the full interface of a module
# contract, you can get the `.vyi` interface in Vyper by using
# `vyper -f interface yourFileName.vy` or the external interface
# by using `vyper -f external_interface yourFileName.vy`.
# @notice Please note that you must always also export (if
# required by the contract logic) `public` declared `constant`,
# `immutable`, and state variables, for which Vyper automatically
# generates an `external` getter function for the variable.
exports: (
tc.DEFAULT_ADMIN_ROLE,
tc.PROPOSER_ROLE,
tc.EXECUTOR_ROLE,
tc.CANCELLER_ROLE,
tc.IERC721_TOKENRECEIVER_SELECTOR,
tc.IERC1155_TOKENRECEIVER_SINGLE_SELECTOR,
tc.IERC1155_TOKENRECEIVER_BATCH_SELECTOR,
tc.__default__,
tc.supportsInterface,
tc.onERC721Received,
tc.onERC1155Received,
tc.onERC1155BatchReceived,
tc.hasRole,
tc.getRoleAdmin,
tc.grantRole,
tc.revokeRole,
tc.renounceRole,
tc.set_role_admin,
tc.get_timestamp,
tc.get_minimum_delay,
tc.is_operation,
tc.is_operation_pending,
tc.is_operation_ready,
tc.is_operation_done,
tc.get_operation_state,
tc.hash_operation,
tc.hash_operation_batch,
tc.schedule,
tc.schedule_batch,
tc.cancel,
tc.execute,
tc.execute_batch,
tc.update_delay,
)
exports: tc.__interface__


@deploy
Expand Down
33 changes: 9 additions & 24 deletions src/snekmate/tokens/mocks/ERC20Mock.vy
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,19 @@ initializes: erc20[ownable := ow]
# @dev We export (i.e. the runtime bytecode exposes these
# functions externally, allowing them to be called using
# the ABI encoding specification) all `external` functions
# from the `ERC20` module.
# from the `ERC20` module. The built-in dunder method
# `__interface__` allows you to export all functions of a
# module without specifying the individual functions (see
# https://github.com/vyperlang/vyper/pull/3919). Please take
# note that if you do not know the full interface of a module
# contract, you can get the `.vyi` interface in Vyper by using
# `vyper -f interface yourFileName.vy` or the external interface
# by using `vyper -f external_interface yourFileName.vy`.
# @notice Please note that you must always also export (if
# required by the contract logic) `public` declared `constant`,
# `immutable`, and state variables, for which Vyper automatically
# generates an `external` getter function for the variable.
exports: (
erc20.owner,
erc20.transfer_ownership,
erc20.renounce_ownership,
erc20.totalSupply,
erc20.balanceOf,
erc20.transfer,
erc20.allowance,
erc20.approve,
erc20.transferFrom,
erc20.name,
erc20.symbol,
erc20.decimals,
erc20.permit,
erc20.nonces,
erc20.DOMAIN_SEPARATOR,
erc20.eip712Domain,
erc20.burn,
erc20.burn_from,
erc20.is_minter,
erc20.mint,
erc20.set_minter,
)
exports: erc20.__interface__


@deploy
Expand Down

0 comments on commit b5126de

Please sign in to comment.