Skip to content

Commit

Permalink
Merge branch 'master' into feat/improve-event-kwargs-recommendation
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper authored Jan 1, 2025
2 parents fe34000 + a29b49d commit def7bcb
Show file tree
Hide file tree
Showing 95 changed files with 4,706 additions and 642 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
# docs: documentation
# test: test suite
# lang: language changes
# stdlib: changes to the stdlib
# ux: language changes (UX)
# tool: integration
# ir: (old) IR/codegen changes
Expand All @@ -43,6 +44,7 @@ jobs:
docs
test
lang
stdlib
ux
tool
ir
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ jobs:
# modes across all python versions - one is enough
- python-version: ["3.10", "310"]
- python-version: ["3.12", "312"]
- python-version: ["3.13", "313"]

# os-specific rules
- os: windows
Expand Down
24 changes: 22 additions & 2 deletions docs/control-structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ External functions (marked with the ``@external`` decorator) are a part of the c
A Vyper contract cannot call directly between two external functions. If you must do this, you can use an :ref:`interface <interfaces>`.

.. note::
For external functions with default arguments like ``def my_function(x: uint256, b: uint256 = 1)`` the Vyper compiler will generate ``N+1`` overloaded function selectors based on ``N`` default arguments.
For external functions with default arguments like ``def my_function(x: uint256, b: uint256 = 1)`` the Vyper compiler will generate ``N+1`` overloaded function selectors based on ``N`` default arguments. Consequently, the ABI signature for a function (this includes interface functions) excludes optional arguments when their default values are used in the function call.

.. code-block:: vyper
from ethereum.ercs import IERC4626
@external
def foo(x: IERC4626):
extcall x.withdraw(0, self, self) # keccak256("withdraw(uint256,address,address)")[:4] = 0xb460af94
extcall x.withdraw(0) # keccak256("withdraw(uint256)")[:4] = 0x2e1a7d4d
.. _structure-functions-internal:

Expand All @@ -75,6 +84,14 @@ Or for internal functions which are defined in :ref:`imported modules <modules>`
def calculate(amount: uint256) -> uint256:
return calculator_library._times_two(amount)
Marking an internal function as ``payable`` specifies that the function can interact with ``msg.value``. A ``nonpayable`` internal function can be called from an external ``payable`` function, but it cannot access ``msg.value``.

.. code-block:: vyper
@payable
def _foo() -> uint256:
return msg.value % 2
.. note::
As of v0.4.0, the ``@internal`` decorator is optional. That is, functions with no visibility decorator default to being ``internal``.

Expand Down Expand Up @@ -110,7 +127,7 @@ You can optionally declare a function's mutability by using a :ref:`decorator <f
* ``@pure``: does not read from the contract state or any environment variables.
* ``@view``: may read from the contract state, but does not alter it.
* ``@nonpayable`` (default): may read from and write to the contract state, but cannot receive Ether.
* ``@payable``: may read from and write to the contract state, and can receive Ether.
* ``@payable``: may read from and write to the contract state, and can receive and access Ether via ``msg.value``.

.. code-block:: vyper
Expand All @@ -132,6 +149,9 @@ Functions marked with ``@view`` cannot call mutable (``payable`` or ``nonpayable

Functions marked with ``@pure`` cannot call non-``pure`` functions.

.. note::
The ``@nonpayable`` decorator is not strictly enforced on ``internal`` functions when they are invoked through an ``external`` ``payable`` function. As a result, an ``external`` ``payable`` function can invoke an ``internal`` ``nonpayable`` function. However, the ``nonpayable`` ``internal`` function cannot have access to ``msg.value``.

Re-entrancy Locks
-----------------

Expand Down
4 changes: 4 additions & 0 deletions docs/interfaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ This imports the defined interface from the vyper file at ``an_interface.vyi`` (

Prior to v0.4.0, ``implements`` required that events defined in an interface were re-defined in the "implementing" contract. As of v0.4.0, this is no longer required because events can be used just by importing them. Any events used in a contract will automatically be exported in the ABI output.

.. note::

An interface function with default parameters (e.g. ``deposit(assets: uint256, receiver: address = msg.sender)``) implies that the contract being interfaced with supports these default arguments via the ABI-encoded function signatures (e.g. ``keccak256("deposit(uint256,address)")[:4]`` and ``keccak256("deposit(uint256)")[:4]``). It is the responsibility of the callee to implement the behavior associated with these defaults.

Standalone Interfaces
=====================

Expand Down
15 changes: 15 additions & 0 deletions docs/using-modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ The ``_times_two()`` helper function in the above module can be immediately used
The other functions cannot be used yet, because they touch the ``ownable`` module's state. There are two ways to declare a module so that its state can be used.

Using a module as an interface
==============================

A module can be used as an interface with the ``__at__`` syntax.

.. code-block:: vyper
import ownable
an_ownable: ownable.__interface__
def call_ownable(addr: address):
self.an_ownable = ownable.__at__(addr)
self.an_ownable.transfer_ownership(...)
Initializing a module
=====================

Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def _global_version(version):
"asttokens>=2.0.5,<3",
"pycryptodome>=3.5.1,<4",
"packaging>=23.1,<24",
"lark>=1.0.0,<2",
"importlib-metadata",
"wheel",
],
Expand All @@ -105,6 +106,7 @@ def _global_version(version):
"vyper=vyper.cli.vyper_compile:_parse_cli_args",
"fang=vyper.cli.vyper_ir:_parse_cli_args",
"vyper-json=vyper.cli.vyper_json:_parse_cli_args",
"venom=vyper.cli.venom_main:_parse_cli_args",
]
},
classifiers=[
Expand All @@ -113,6 +115,7 @@ def _global_version(version):
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
],
package_data={"vyper.ast": ["grammar.lark"]},
data_files=[("", [hash_file_rel_path])],
Expand Down
Loading

0 comments on commit def7bcb

Please sign in to comment.