From c4cc83943b468828e763ea307431836ca7484c82 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Fri, 4 Oct 2024 22:38:02 -0400 Subject: [PATCH 01/15] feat[ux]: improve hint for events kwarg upgrade follow-on commit to ebe3c0ccfc2a6935d. the hint in ebe3c0ccfc2a6935d is not specific to the user's source code, and it's a bit laborious for the user to match the call-site to the event def. this commit auto-generates the new call expression for the user to use. --- vyper/semantics/types/user.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/vyper/semantics/types/user.py b/vyper/semantics/types/user.py index 73fa4878c7..948c0145e1 100644 --- a/vyper/semantics/types/user.py +++ b/vyper/semantics/types/user.py @@ -295,10 +295,15 @@ def _ctor_call_return(self, node: vy_ast.Call) -> None: return validate_kwargs(node, self.arguments, self.typeclass) # warn about positional argument depreciation - msg = "Instantiating events with positional arguments is " - msg += "deprecated as of v0.4.1 and will be disallowed " - msg += "in a future release. Use kwargs instead eg. " - msg += "Foo(a=1, b=2)" + rec0 = ", ".join( + f"{argname}={val.node_source_code}" + for argname, val in zip(self.arguments.keys(), node.args) + ) + recommendation = f"{node.func.node_source_code}({rec0})" + msg = "Instantiating events with positional arguments is" + msg += " deprecated as of v0.4.1 and will be disallowed" + msg += " in a future release. Use kwargs instead e.g.:" + msg += f"\n {recommendation}" vyper_warn(msg, node) From cf949f52c7544c8bfee136a7bd6bfbcbda4d0ce6 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Mon, 18 Nov 2024 09:18:03 +0100 Subject: [PATCH 02/15] update warning --- vyper/semantics/types/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vyper/semantics/types/user.py b/vyper/semantics/types/user.py index 948c0145e1..9f342e116a 100644 --- a/vyper/semantics/types/user.py +++ b/vyper/semantics/types/user.py @@ -303,7 +303,7 @@ def _ctor_call_return(self, node: vy_ast.Call) -> None: msg = "Instantiating events with positional arguments is" msg += " deprecated as of v0.4.1 and will be disallowed" msg += " in a future release. Use kwargs instead e.g.:" - msg += f"\n {recommendation}" + msg += f"\n ```\n{recommendation}\n```" vyper_warn(msg, node) From 2044e94491675b3a2bb04d27e3146b0e89904ce2 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Mon, 18 Nov 2024 09:18:08 +0100 Subject: [PATCH 03/15] update some examples --- examples/tokens/ERC20.vy | 12 ++++++------ examples/tokens/ERC4626.vy | 14 +++++++------- examples/tokens/ERC721.vy | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/tokens/ERC20.vy b/examples/tokens/ERC20.vy index 2d70fd670a..86a9c42880 100644 --- a/examples/tokens/ERC20.vy +++ b/examples/tokens/ERC20.vy @@ -39,7 +39,7 @@ def __init__(_name: String[32], _symbol: String[32], _decimals: uint8, _supply: self.balanceOf[msg.sender] = init_supply self.totalSupply = init_supply self.minter = msg.sender - log IERC20.Transfer(empty(address), msg.sender, init_supply) + log IERC20.Transfer(sender=empty(address), receiver=msg.sender, value=init_supply) @@ -54,7 +54,7 @@ def transfer(_to : address, _value : uint256) -> bool: # so the following subtraction would revert on insufficient balance self.balanceOf[msg.sender] -= _value self.balanceOf[_to] += _value - log IERC20.Transfer(msg.sender, _to, _value) + log IERC20.Transfer(sender=msg.sender, receiver=_to, value=_value) return True @@ -73,7 +73,7 @@ def transferFrom(_from : address, _to : address, _value : uint256) -> bool: # NOTE: vyper does not allow underflows # so the following subtraction would revert on insufficient allowance self.allowance[_from][msg.sender] -= _value - log IERC20.Transfer(_from, _to, _value) + log IERC20.Transfer(sender=_from, receiver=_to, value=_value) return True @@ -89,7 +89,7 @@ def approve(_spender : address, _value : uint256) -> bool: @param _value The amount of tokens to be spent. """ self.allowance[msg.sender][_spender] = _value - log IERC20.Approval(msg.sender, _spender, _value) + log IERC20.Approval(owner=msg.sender, spender=_spender, value=_value) return True @@ -106,7 +106,7 @@ def mint(_to: address, _value: uint256): assert _to != empty(address) self.totalSupply += _value self.balanceOf[_to] += _value - log IERC20.Transfer(empty(address), _to, _value) + log IERC20.Transfer(sender=empty(address), receiver=_to, value=_value) @internal @@ -120,7 +120,7 @@ def _burn(_to: address, _value: uint256): assert _to != empty(address) self.totalSupply -= _value self.balanceOf[_to] -= _value - log IERC20.Transfer(_to, empty(address), _value) + log IERC20.Transfer(sender=_to, receiver=empty(address), value=_value) @external diff --git a/examples/tokens/ERC4626.vy b/examples/tokens/ERC4626.vy index 2dc4656746..313d99ed4c 100644 --- a/examples/tokens/ERC4626.vy +++ b/examples/tokens/ERC4626.vy @@ -56,14 +56,14 @@ def decimals() -> uint8: def transfer(receiver: address, amount: uint256) -> bool: self.balanceOf[msg.sender] -= amount self.balanceOf[receiver] += amount - log IERC20.Transfer(msg.sender, receiver, amount) + log IERC20.Transfer(sender=msg.sender, receiver=receiver, value=amount) return True @external def approve(spender: address, amount: uint256) -> bool: self.allowance[msg.sender][spender] = amount - log IERC20.Approval(msg.sender, spender, amount) + log IERC20.Approval(owner=msg.sender, spender=spender, value=amount) return True @@ -72,7 +72,7 @@ def transferFrom(sender: address, receiver: address, amount: uint256) -> bool: self.allowance[sender][msg.sender] -= amount self.balanceOf[sender] -= amount self.balanceOf[receiver] += amount - log IERC20.Transfer(sender, receiver, amount) + log IERC20.Transfer(sender=sender, receiver=receiver, value=amount) return True @@ -137,7 +137,7 @@ def deposit(assets: uint256, receiver: address=msg.sender) -> uint256: self.totalSupply += shares self.balanceOf[receiver] += shares - log IERC4626.Deposit(msg.sender, receiver, assets, shares) + log IERC4626.Deposit(sender=msg.sender, owner=receiver, assets=assets, shares=shares) return shares @@ -170,7 +170,7 @@ def mint(shares: uint256, receiver: address=msg.sender) -> uint256: self.totalSupply += shares self.balanceOf[receiver] += shares - log IERC4626.Deposit(msg.sender, receiver, assets, shares) + log IERC4626.Deposit(sender=msg.sender, owner=receiver, assets=assets, shares=shares) return assets @@ -207,7 +207,7 @@ def withdraw(assets: uint256, receiver: address=msg.sender, owner: address=msg.s self.balanceOf[owner] -= shares extcall self.asset.transfer(receiver, assets) - log IERC4626.Withdraw(msg.sender, receiver, owner, assets, shares) + log IERC4626.Withdraw(sender=msg.sender, receiver=receiver, owner=owner, assets=assets, shares=shares) return shares @@ -233,7 +233,7 @@ def redeem(shares: uint256, receiver: address=msg.sender, owner: address=msg.sen self.balanceOf[owner] -= shares extcall self.asset.transfer(receiver, assets) - log IERC4626.Withdraw(msg.sender, receiver, owner, assets, shares) + log IERC4626.Withdraw(sender=msg.sender, receiver=receiver, owner=owner, assets=assets, shares=shares) return assets diff --git a/examples/tokens/ERC721.vy b/examples/tokens/ERC721.vy index d57088b5aa..acb445bd57 100644 --- a/examples/tokens/ERC721.vy +++ b/examples/tokens/ERC721.vy @@ -201,7 +201,7 @@ def _transferFrom(_from: address, _to: address, _tokenId: uint256, _sender: addr # Add NFT self._addTokenTo(_to, _tokenId) # Log the transfer - log IERC721.Transfer(_from, _to, _tokenId) + log IERC721.Transfer(sender=_from, receiver=_to, token_id=_tokenId) ### TRANSFER FUNCTIONS ### @@ -275,7 +275,7 @@ def approve(_approved: address, _tokenId: uint256): assert (senderIsOwner or senderIsApprovedForAll) # Set the approval self.idToApprovals[_tokenId] = _approved - log IERC721.Approval(owner, _approved, _tokenId) + log IERC721.Approval(owner=owner, approved=_approved, token_id=_tokenId) @external @@ -291,7 +291,7 @@ def setApprovalForAll(_operator: address, _approved: bool): # Throws if `_operator` is the `msg.sender` assert _operator != msg.sender self.ownerToOperators[msg.sender][_operator] = _approved - log IERC721.ApprovalForAll(msg.sender, _operator, _approved) + log IERC721.ApprovalForAll(owner=msg.sender, operator=_operator, approved=_approved) ### MINT & BURN FUNCTIONS ### @@ -313,7 +313,7 @@ def mint(_to: address, _tokenId: uint256) -> bool: assert _to != empty(address) # Add NFT. Throws if `_tokenId` is owned by someone self._addTokenTo(_to, _tokenId) - log IERC721.Transfer(empty(address), _to, _tokenId) + log IERC721.Transfer(sender=empty(address), receiver=_to, token_id=_tokenId) return True @@ -333,7 +333,7 @@ def burn(_tokenId: uint256): assert owner != empty(address) self._clearApproval(owner, _tokenId) self._removeTokenFrom(owner, _tokenId) - log IERC721.Transfer(owner, empty(address), _tokenId) + log IERC721.Transfer(sender=owner, receiver=empty(address), token_id=_tokenId) @view From 85fec8e9a38893522707a63c27e0ac46beedd93a Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Mon, 18 Nov 2024 10:31:15 +0100 Subject: [PATCH 04/15] fix stray whitespace --- vyper/semantics/types/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vyper/semantics/types/user.py b/vyper/semantics/types/user.py index 9f342e116a..ef2dcaaac0 100644 --- a/vyper/semantics/types/user.py +++ b/vyper/semantics/types/user.py @@ -303,7 +303,7 @@ def _ctor_call_return(self, node: vy_ast.Call) -> None: msg = "Instantiating events with positional arguments is" msg += " deprecated as of v0.4.1 and will be disallowed" msg += " in a future release. Use kwargs instead e.g.:" - msg += f"\n ```\n{recommendation}\n```" + msg += f"\n```\n{recommendation}\n```" vyper_warn(msg, node) From 6550ac693cb357212fe13b0b16ade7c8a72a1e67 Mon Sep 17 00:00:00 2001 From: cyberthirst Date: Fri, 6 Dec 2024 11:26:16 +0100 Subject: [PATCH 05/15] add tests for event kwargs hint --- .../syntax/test_event_kwarg_hint.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/functional/syntax/test_event_kwarg_hint.py diff --git a/tests/functional/syntax/test_event_kwarg_hint.py b/tests/functional/syntax/test_event_kwarg_hint.py new file mode 100644 index 0000000000..7ef6d4f333 --- /dev/null +++ b/tests/functional/syntax/test_event_kwarg_hint.py @@ -0,0 +1,48 @@ +import warnings + +import pytest + +from vyper.compiler import compile_code + + +def test_event_kwarg_hint(): + code = """ +from ethereum.ercs import IERC20 + +def foo(): + log IERC20.Transfer(msg.sender, msg.sender, 123) + """ + + with warnings.catch_warnings(record=True) as w: + assert compile_code(code) is not None + + expected = "Instantiating events with positional arguments is deprecated " + expected += "as of v0.4.1 and will be disallowed in a future release. " + expected += "Use kwargs instead e.g.:\n" + expected += "```\nIERC20.Transfer(sender=msg.sender, receiver=msg.sender, value=123)\n```" + + assert len(w) == 1, [s.message for s in w] + assert str(w[0].message).startswith(expected) + + +# https://github.com/vyperlang/vyper/pull/4275#issuecomment-2394910693 +# explains the xfail +@pytest.mark.xfail(raises=AssertionError) +def test_event_hint_single_char_argument(): + code = """ +from ethereum.ercs import IERC20 + +def foo(): + log IERC20.Transfer(msg.sender, msg.sender, 1) + """ + + with warnings.catch_warnings(record=True) as w: + assert compile_code(code) is not None + + expected = "Instantiating events with positional arguments is deprecated " + expected += "as of v0.4.1 and will be disallowed in a future release. " + expected += "Use kwargs instead e.g.:\n" + expected += "```\nIERC20.Transfer(sender=msg.sender, receiver=msg.sender, value=1)\n```" + + assert len(w) == 1, [s.message for s in w] + assert str(w[0].message).startswith(expected) From 9e1830755f7085d3434168692a7785621c361ec9 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 12 Jan 2025 12:05:40 -0500 Subject: [PATCH 06/15] tmp rollback --- examples/tokens/ERC20.vy | 12 ++++++------ examples/tokens/ERC4626.vy | 14 +++++++------- examples/tokens/ERC721.vy | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/tokens/ERC20.vy b/examples/tokens/ERC20.vy index 86a9c42880..2d70fd670a 100644 --- a/examples/tokens/ERC20.vy +++ b/examples/tokens/ERC20.vy @@ -39,7 +39,7 @@ def __init__(_name: String[32], _symbol: String[32], _decimals: uint8, _supply: self.balanceOf[msg.sender] = init_supply self.totalSupply = init_supply self.minter = msg.sender - log IERC20.Transfer(sender=empty(address), receiver=msg.sender, value=init_supply) + log IERC20.Transfer(empty(address), msg.sender, init_supply) @@ -54,7 +54,7 @@ def transfer(_to : address, _value : uint256) -> bool: # so the following subtraction would revert on insufficient balance self.balanceOf[msg.sender] -= _value self.balanceOf[_to] += _value - log IERC20.Transfer(sender=msg.sender, receiver=_to, value=_value) + log IERC20.Transfer(msg.sender, _to, _value) return True @@ -73,7 +73,7 @@ def transferFrom(_from : address, _to : address, _value : uint256) -> bool: # NOTE: vyper does not allow underflows # so the following subtraction would revert on insufficient allowance self.allowance[_from][msg.sender] -= _value - log IERC20.Transfer(sender=_from, receiver=_to, value=_value) + log IERC20.Transfer(_from, _to, _value) return True @@ -89,7 +89,7 @@ def approve(_spender : address, _value : uint256) -> bool: @param _value The amount of tokens to be spent. """ self.allowance[msg.sender][_spender] = _value - log IERC20.Approval(owner=msg.sender, spender=_spender, value=_value) + log IERC20.Approval(msg.sender, _spender, _value) return True @@ -106,7 +106,7 @@ def mint(_to: address, _value: uint256): assert _to != empty(address) self.totalSupply += _value self.balanceOf[_to] += _value - log IERC20.Transfer(sender=empty(address), receiver=_to, value=_value) + log IERC20.Transfer(empty(address), _to, _value) @internal @@ -120,7 +120,7 @@ def _burn(_to: address, _value: uint256): assert _to != empty(address) self.totalSupply -= _value self.balanceOf[_to] -= _value - log IERC20.Transfer(sender=_to, receiver=empty(address), value=_value) + log IERC20.Transfer(_to, empty(address), _value) @external diff --git a/examples/tokens/ERC4626.vy b/examples/tokens/ERC4626.vy index 313d99ed4c..2dc4656746 100644 --- a/examples/tokens/ERC4626.vy +++ b/examples/tokens/ERC4626.vy @@ -56,14 +56,14 @@ def decimals() -> uint8: def transfer(receiver: address, amount: uint256) -> bool: self.balanceOf[msg.sender] -= amount self.balanceOf[receiver] += amount - log IERC20.Transfer(sender=msg.sender, receiver=receiver, value=amount) + log IERC20.Transfer(msg.sender, receiver, amount) return True @external def approve(spender: address, amount: uint256) -> bool: self.allowance[msg.sender][spender] = amount - log IERC20.Approval(owner=msg.sender, spender=spender, value=amount) + log IERC20.Approval(msg.sender, spender, amount) return True @@ -72,7 +72,7 @@ def transferFrom(sender: address, receiver: address, amount: uint256) -> bool: self.allowance[sender][msg.sender] -= amount self.balanceOf[sender] -= amount self.balanceOf[receiver] += amount - log IERC20.Transfer(sender=sender, receiver=receiver, value=amount) + log IERC20.Transfer(sender, receiver, amount) return True @@ -137,7 +137,7 @@ def deposit(assets: uint256, receiver: address=msg.sender) -> uint256: self.totalSupply += shares self.balanceOf[receiver] += shares - log IERC4626.Deposit(sender=msg.sender, owner=receiver, assets=assets, shares=shares) + log IERC4626.Deposit(msg.sender, receiver, assets, shares) return shares @@ -170,7 +170,7 @@ def mint(shares: uint256, receiver: address=msg.sender) -> uint256: self.totalSupply += shares self.balanceOf[receiver] += shares - log IERC4626.Deposit(sender=msg.sender, owner=receiver, assets=assets, shares=shares) + log IERC4626.Deposit(msg.sender, receiver, assets, shares) return assets @@ -207,7 +207,7 @@ def withdraw(assets: uint256, receiver: address=msg.sender, owner: address=msg.s self.balanceOf[owner] -= shares extcall self.asset.transfer(receiver, assets) - log IERC4626.Withdraw(sender=msg.sender, receiver=receiver, owner=owner, assets=assets, shares=shares) + log IERC4626.Withdraw(msg.sender, receiver, owner, assets, shares) return shares @@ -233,7 +233,7 @@ def redeem(shares: uint256, receiver: address=msg.sender, owner: address=msg.sen self.balanceOf[owner] -= shares extcall self.asset.transfer(receiver, assets) - log IERC4626.Withdraw(sender=msg.sender, receiver=receiver, owner=owner, assets=assets, shares=shares) + log IERC4626.Withdraw(msg.sender, receiver, owner, assets, shares) return assets diff --git a/examples/tokens/ERC721.vy b/examples/tokens/ERC721.vy index acb445bd57..d57088b5aa 100644 --- a/examples/tokens/ERC721.vy +++ b/examples/tokens/ERC721.vy @@ -201,7 +201,7 @@ def _transferFrom(_from: address, _to: address, _tokenId: uint256, _sender: addr # Add NFT self._addTokenTo(_to, _tokenId) # Log the transfer - log IERC721.Transfer(sender=_from, receiver=_to, token_id=_tokenId) + log IERC721.Transfer(_from, _to, _tokenId) ### TRANSFER FUNCTIONS ### @@ -275,7 +275,7 @@ def approve(_approved: address, _tokenId: uint256): assert (senderIsOwner or senderIsApprovedForAll) # Set the approval self.idToApprovals[_tokenId] = _approved - log IERC721.Approval(owner=owner, approved=_approved, token_id=_tokenId) + log IERC721.Approval(owner, _approved, _tokenId) @external @@ -291,7 +291,7 @@ def setApprovalForAll(_operator: address, _approved: bool): # Throws if `_operator` is the `msg.sender` assert _operator != msg.sender self.ownerToOperators[msg.sender][_operator] = _approved - log IERC721.ApprovalForAll(owner=msg.sender, operator=_operator, approved=_approved) + log IERC721.ApprovalForAll(msg.sender, _operator, _approved) ### MINT & BURN FUNCTIONS ### @@ -313,7 +313,7 @@ def mint(_to: address, _tokenId: uint256) -> bool: assert _to != empty(address) # Add NFT. Throws if `_tokenId` is owned by someone self._addTokenTo(_to, _tokenId) - log IERC721.Transfer(sender=empty(address), receiver=_to, token_id=_tokenId) + log IERC721.Transfer(empty(address), _to, _tokenId) return True @@ -333,7 +333,7 @@ def burn(_tokenId: uint256): assert owner != empty(address) self._clearApproval(owner, _tokenId) self._removeTokenFrom(owner, _tokenId) - log IERC721.Transfer(sender=owner, receiver=empty(address), token_id=_tokenId) + log IERC721.Transfer(owner, empty(address), _tokenId) @view From 40c6c41b066dca118f4753b5b95f268e7073a72f Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 12 Jan 2025 12:29:07 -0500 Subject: [PATCH 07/15] better recommendation --- vyper/semantics/types/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vyper/semantics/types/user.py b/vyper/semantics/types/user.py index f92c4c92ec..bed5542785 100644 --- a/vyper/semantics/types/user.py +++ b/vyper/semantics/types/user.py @@ -302,7 +302,7 @@ def _ctor_call_return(self, node: vy_ast.Call) -> None: f"{argname}={val.node_source_code}" for argname, val in zip(self.arguments.keys(), node.args) ) - recommendation = f"{node.func.node_source_code}({rec0})" + recommendation = f"log {node.func.node_source_code}({rec0})" msg = "Instantiating events with positional arguments is" msg += " deprecated as of v0.4.1 and will be disallowed" msg += " in a future release. Use kwargs instead e.g.:" From 54200c78d02139e95fab2936423f7ae443698518 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 12 Jan 2025 12:32:48 -0500 Subject: [PATCH 08/15] update ERC20.vy --- examples/tokens/ERC20.vy | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/tokens/ERC20.vy b/examples/tokens/ERC20.vy index 2d70fd670a..f16cbb73f2 100644 --- a/examples/tokens/ERC20.vy +++ b/examples/tokens/ERC20.vy @@ -39,8 +39,7 @@ def __init__(_name: String[32], _symbol: String[32], _decimals: uint8, _supply: self.balanceOf[msg.sender] = init_supply self.totalSupply = init_supply self.minter = msg.sender - log IERC20.Transfer(empty(address), msg.sender, init_supply) - + log IERC20.Transfer(sender=empty(address), receiver=msg.sender, value=init_supply) @external @@ -54,7 +53,7 @@ def transfer(_to : address, _value : uint256) -> bool: # so the following subtraction would revert on insufficient balance self.balanceOf[msg.sender] -= _value self.balanceOf[_to] += _value - log IERC20.Transfer(msg.sender, _to, _value) + log IERC20.Transfer(sender=msg.sender, receiver=_to, value=_value) return True @@ -73,7 +72,7 @@ def transferFrom(_from : address, _to : address, _value : uint256) -> bool: # NOTE: vyper does not allow underflows # so the following subtraction would revert on insufficient allowance self.allowance[_from][msg.sender] -= _value - log IERC20.Transfer(_from, _to, _value) + log IERC20.Transfer(sender=_from, receiver=_to, value=_value) return True @@ -89,7 +88,7 @@ def approve(_spender : address, _value : uint256) -> bool: @param _value The amount of tokens to be spent. """ self.allowance[msg.sender][_spender] = _value - log IERC20.Approval(msg.sender, _spender, _value) + log IERC20.Approval(owner=msg.sender, spender=_spender, value=_value) return True @@ -106,7 +105,7 @@ def mint(_to: address, _value: uint256): assert _to != empty(address) self.totalSupply += _value self.balanceOf[_to] += _value - log IERC20.Transfer(empty(address), _to, _value) + log IERC20.Transfer(sender=empty(address), receiver=_to, value=_value) @internal @@ -120,7 +119,7 @@ def _burn(_to: address, _value: uint256): assert _to != empty(address) self.totalSupply -= _value self.balanceOf[_to] -= _value - log IERC20.Transfer(_to, empty(address), _value) + log IERC20.Transfer(sender=_to, receiver=empty(address), value=_value) @external From d4dd8427df281ed49a4fecdbcaa55674f89050c4 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 12 Jan 2025 12:32:58 -0500 Subject: [PATCH 09/15] update ERC721.vy --- examples/tokens/ERC721.vy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/tokens/ERC721.vy b/examples/tokens/ERC721.vy index d57088b5aa..acb445bd57 100644 --- a/examples/tokens/ERC721.vy +++ b/examples/tokens/ERC721.vy @@ -201,7 +201,7 @@ def _transferFrom(_from: address, _to: address, _tokenId: uint256, _sender: addr # Add NFT self._addTokenTo(_to, _tokenId) # Log the transfer - log IERC721.Transfer(_from, _to, _tokenId) + log IERC721.Transfer(sender=_from, receiver=_to, token_id=_tokenId) ### TRANSFER FUNCTIONS ### @@ -275,7 +275,7 @@ def approve(_approved: address, _tokenId: uint256): assert (senderIsOwner or senderIsApprovedForAll) # Set the approval self.idToApprovals[_tokenId] = _approved - log IERC721.Approval(owner, _approved, _tokenId) + log IERC721.Approval(owner=owner, approved=_approved, token_id=_tokenId) @external @@ -291,7 +291,7 @@ def setApprovalForAll(_operator: address, _approved: bool): # Throws if `_operator` is the `msg.sender` assert _operator != msg.sender self.ownerToOperators[msg.sender][_operator] = _approved - log IERC721.ApprovalForAll(msg.sender, _operator, _approved) + log IERC721.ApprovalForAll(owner=msg.sender, operator=_operator, approved=_approved) ### MINT & BURN FUNCTIONS ### @@ -313,7 +313,7 @@ def mint(_to: address, _tokenId: uint256) -> bool: assert _to != empty(address) # Add NFT. Throws if `_tokenId` is owned by someone self._addTokenTo(_to, _tokenId) - log IERC721.Transfer(empty(address), _to, _tokenId) + log IERC721.Transfer(sender=empty(address), receiver=_to, token_id=_tokenId) return True @@ -333,7 +333,7 @@ def burn(_tokenId: uint256): assert owner != empty(address) self._clearApproval(owner, _tokenId) self._removeTokenFrom(owner, _tokenId) - log IERC721.Transfer(owner, empty(address), _tokenId) + log IERC721.Transfer(sender=owner, receiver=empty(address), token_id=_tokenId) @view From d42ae0d888f5e05280a817bac5acb0824dace996 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 12 Jan 2025 12:36:32 -0500 Subject: [PATCH 10/15] update ERC1155Ownable.vy --- examples/tokens/ERC1155ownable.vy | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/tokens/ERC1155ownable.vy b/examples/tokens/ERC1155ownable.vy index b8513243d4..a8e9b4c327 100644 --- a/examples/tokens/ERC1155ownable.vy +++ b/examples/tokens/ERC1155ownable.vy @@ -69,7 +69,7 @@ event unPaused: event OwnershipTransferred: # Emits smart contract ownership transfer from current to new owner - previouwOwner: address + previousOwner: address newOwner: address event TransferSingle: @@ -150,7 +150,7 @@ def pause(): assert self.owner == msg.sender, "Ownable: caller is not the owner" assert not self.paused, "the contract is already paused" self.paused = True - log Paused(msg.sender) + log Paused(account=msg.sender) @external def unpause(): @@ -162,7 +162,7 @@ def unpause(): assert self.owner == msg.sender, "Ownable: caller is not the owner" assert self.paused, "the contract is not paused" self.paused = False - log unPaused(msg.sender) + log unPaused(account=msg.sender) ## ownership ## @external @@ -179,7 +179,7 @@ def transferOwnership(newOwner: address): assert newOwner != empty(address), "Transfer to the zero address not allowed. Use renounceOwnership() instead." oldOwner: address = self.owner self.owner = newOwner - log OwnershipTransferred(oldOwner, newOwner) + log OwnershipTransferred(previousOwner=oldOwner, newOwner=newOwner) @external def renounceOwnership(): @@ -191,7 +191,7 @@ def renounceOwnership(): assert self.owner == msg.sender, "Ownable: caller is not the owner" oldOwner: address = self.owner self.owner = empty(address) - log OwnershipTransferred(oldOwner, empty(address)) + log OwnershipTransferred(previousOwner=oldOwner, newOwner=empty(address)) @external @view @@ -226,7 +226,7 @@ def mint(receiver: address, id: uint256, amount:uint256): assert receiver != empty(address), "Can not mint to ZERO ADDRESS" operator: address = msg.sender self.balanceOf[receiver][id] += amount - log TransferSingle(operator, empty(address), receiver, id, amount) + log TransferSingle(operator=operator, fromAddress=empty(address), to=receiver, id=id, value=amount) @external @@ -249,7 +249,7 @@ def mintBatch(receiver: address, ids: DynArray[uint256, BATCH_SIZE], amounts: Dy break self.balanceOf[receiver][ids[i]] += amounts[i] - log TransferBatch(operator, empty(address), receiver, ids, amounts) + log TransferBatch(operator=operator, fromAddress=empty(address), to=receiver, ids=ids, values=amounts) ## burn ## @external @@ -263,7 +263,7 @@ def burn(id: uint256, amount: uint256): assert not self.paused, "The contract has been paused" assert self.balanceOf[msg.sender][id] > 0 , "caller does not own this ID" self.balanceOf[msg.sender][id] -= amount - log TransferSingle(msg.sender, msg.sender, empty(address), id, amount) + log TransferSingle(operator=msg.sender, fromAddress=msg.sender, to=empty(address), id=id, value=amount) @external def burnBatch(ids: DynArray[uint256, BATCH_SIZE], amounts: DynArray[uint256, BATCH_SIZE]): @@ -283,7 +283,7 @@ def burnBatch(ids: DynArray[uint256, BATCH_SIZE], amounts: DynArray[uint256, BAT break self.balanceOf[msg.sender][ids[i]] -= amounts[i] - log TransferBatch(msg.sender, msg.sender, empty(address), ids, amounts) + log TransferBatch(operator=msg.sender, fromAddress=msg.sender, to=empty(address), ids=ids, values=amounts) ## approval ## @external @@ -298,7 +298,7 @@ def setApprovalForAll(owner: address, operator: address, approved: bool): assert not self.paused, "The contract has been paused" assert owner != operator, "ERC1155: setting approval status for self" self.isApprovedForAll[owner][operator] = approved - log ApprovalForAll(owner, operator, approved) + log ApprovalForAll(account=owner, operator=operator, approved=approved) @external def safeTransferFrom(sender: address, receiver: address, id: uint256, amount: uint256, bytes: bytes32): @@ -317,7 +317,7 @@ def safeTransferFrom(sender: address, receiver: address, id: uint256, amount: ui operator: address = msg.sender self.balanceOf[sender][id] -= amount self.balanceOf[receiver][id] += amount - log TransferSingle(operator, sender, receiver, id, amount) + log TransferSingle(operator=operator, fromAddress=sender, to=receiver, id=id, value=amount) @external def safeBatchTransferFrom(sender: address, receiver: address, ids: DynArray[uint256, BATCH_SIZE], amounts: DynArray[uint256, BATCH_SIZE], _bytes: bytes32): @@ -342,7 +342,7 @@ def safeBatchTransferFrom(sender: address, receiver: address, ids: DynArray[uint self.balanceOf[sender][id] -= amount self.balanceOf[receiver][id] += amount - log TransferBatch(operator, sender, receiver, ids, amounts) + log TransferBatch(operator=operator, fromAddress=sender, to=receiver, ids=ids, values=amounts) # URI # @external @@ -355,7 +355,7 @@ def setURI(uri: String[MAX_URI_LENGTH]): assert self.baseuri != uri, "new and current URI are identical" assert msg.sender == self.owner, "Only the contract owner can update the URI" self.baseuri = uri - log URI(uri, 0) + log URI(value=uri, id=0) @external def toggleDynUri(status: bool): @@ -391,7 +391,7 @@ def setContractURI(contractUri: String[MAX_URI_LENGTH]): assert self.contractURI != contractUri, "new and current URI are identical" assert msg.sender == self.owner, "Only the contract owner can update the URI" self.contractURI = contractUri - log URI(contractUri, 0) + log URI(value=contractUri, id=0) @view @external From d591d08aab985a9004a176d7c130fa624e427eea Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 12 Jan 2025 12:38:04 -0500 Subject: [PATCH 11/15] update ERC4626.vy --- examples/tokens/ERC4626.vy | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/tokens/ERC4626.vy b/examples/tokens/ERC4626.vy index 2dc4656746..313d99ed4c 100644 --- a/examples/tokens/ERC4626.vy +++ b/examples/tokens/ERC4626.vy @@ -56,14 +56,14 @@ def decimals() -> uint8: def transfer(receiver: address, amount: uint256) -> bool: self.balanceOf[msg.sender] -= amount self.balanceOf[receiver] += amount - log IERC20.Transfer(msg.sender, receiver, amount) + log IERC20.Transfer(sender=msg.sender, receiver=receiver, value=amount) return True @external def approve(spender: address, amount: uint256) -> bool: self.allowance[msg.sender][spender] = amount - log IERC20.Approval(msg.sender, spender, amount) + log IERC20.Approval(owner=msg.sender, spender=spender, value=amount) return True @@ -72,7 +72,7 @@ def transferFrom(sender: address, receiver: address, amount: uint256) -> bool: self.allowance[sender][msg.sender] -= amount self.balanceOf[sender] -= amount self.balanceOf[receiver] += amount - log IERC20.Transfer(sender, receiver, amount) + log IERC20.Transfer(sender=sender, receiver=receiver, value=amount) return True @@ -137,7 +137,7 @@ def deposit(assets: uint256, receiver: address=msg.sender) -> uint256: self.totalSupply += shares self.balanceOf[receiver] += shares - log IERC4626.Deposit(msg.sender, receiver, assets, shares) + log IERC4626.Deposit(sender=msg.sender, owner=receiver, assets=assets, shares=shares) return shares @@ -170,7 +170,7 @@ def mint(shares: uint256, receiver: address=msg.sender) -> uint256: self.totalSupply += shares self.balanceOf[receiver] += shares - log IERC4626.Deposit(msg.sender, receiver, assets, shares) + log IERC4626.Deposit(sender=msg.sender, owner=receiver, assets=assets, shares=shares) return assets @@ -207,7 +207,7 @@ def withdraw(assets: uint256, receiver: address=msg.sender, owner: address=msg.s self.balanceOf[owner] -= shares extcall self.asset.transfer(receiver, assets) - log IERC4626.Withdraw(msg.sender, receiver, owner, assets, shares) + log IERC4626.Withdraw(sender=msg.sender, receiver=receiver, owner=owner, assets=assets, shares=shares) return shares @@ -233,7 +233,7 @@ def redeem(shares: uint256, receiver: address=msg.sender, owner: address=msg.sen self.balanceOf[owner] -= shares extcall self.asset.transfer(receiver, assets) - log IERC4626.Withdraw(msg.sender, receiver, owner, assets, shares) + log IERC4626.Withdraw(sender=msg.sender, receiver=receiver, owner=owner, assets=assets, shares=shares) return assets From 8681e71af435c26dda71b4c85b7f47d63fedb474 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 12 Jan 2025 12:40:10 -0500 Subject: [PATCH 12/15] update blind_auction.vy --- examples/auctions/blind_auction.vy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/auctions/blind_auction.vy b/examples/auctions/blind_auction.vy index 143206ccb4..f102bdcfbc 100644 --- a/examples/auctions/blind_auction.vy +++ b/examples/auctions/blind_auction.vy @@ -172,7 +172,7 @@ def auctionEnd(): assert not self.ended # Log auction ending and set flag - log AuctionEnded(self.highestBidder, self.highestBid) + log AuctionEnded(highestBidder=self.highestBidder, highestBid=self.highestBid) self.ended = True # Transfer funds to beneficiary From aa7c7bd7bae6a5b7b08591c0a764edafa6d71532 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 12 Jan 2025 12:44:24 -0500 Subject: [PATCH 13/15] update advanced_storage.vy --- examples/storage/advanced_storage.vy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/storage/advanced_storage.vy b/examples/storage/advanced_storage.vy index 42a455cbf1..397bf6b97c 100644 --- a/examples/storage/advanced_storage.vy +++ b/examples/storage/advanced_storage.vy @@ -15,7 +15,7 @@ def set(_x: int128): assert _x >= 0, "No negative values" assert self.storedData < 100, "Storage is locked when 100 or more is stored" self.storedData = _x - log DataChange(msg.sender, _x) + log DataChange(setter=msg.sender, value=_x) @external def reset(): From 9408dcf29783a4bad2c8eee150ad23f754cf8d37 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 12 Jan 2025 12:46:10 -0500 Subject: [PATCH 14/15] update company.vy --- examples/stock/company.vy | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/stock/company.vy b/examples/stock/company.vy index 7739959e92..dda88c9798 100644 --- a/examples/stock/company.vy +++ b/examples/stock/company.vy @@ -63,7 +63,7 @@ def buyStock(): self.holdings[msg.sender] += buy_order # Log the buy event. - log Buy(msg.sender, buy_order) + log Buy(buyer=msg.sender, buy_order=buy_order) # Public function to allow external access to _getHolding @view @@ -94,7 +94,7 @@ def sellStock(sell_order: uint256): send(msg.sender, sell_order * self.price) # Log the sell event. - log Sell(msg.sender, sell_order) + log Sell(seller=msg.sender, sell_order=sell_order) # Transfer stock from one stockholder to another. (Assume that the # receiver is given some compensation, but this is not enforced.) @@ -109,7 +109,7 @@ def transferStock(receiver: address, transfer_order: uint256): self.holdings[receiver] += transfer_order # Log the transfer event. - log Transfer(msg.sender, receiver, transfer_order) + log Transfer(sender=msg.sender, receiver=receiver, value=transfer_order) # Allow the company to pay someone for services rendered. @external @@ -123,7 +123,8 @@ def payBill(vendor: address, amount: uint256): send(vendor, amount) # Log the payment event. - log Pay(vendor, amount) + log Pay(vendor=vendor, amount=amount) + # Public function to allow external access to _debt @view From fd15d4bb2dd0fa49a232699e3816d207b78aac72 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 12 Jan 2025 13:11:37 -0500 Subject: [PATCH 15/15] update tests --- tests/functional/syntax/test_event_kwarg_hint.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/functional/syntax/test_event_kwarg_hint.py b/tests/functional/syntax/test_event_kwarg_hint.py index 7ef6d4f333..6bbd01f23e 100644 --- a/tests/functional/syntax/test_event_kwarg_hint.py +++ b/tests/functional/syntax/test_event_kwarg_hint.py @@ -1,7 +1,5 @@ import warnings -import pytest - from vyper.compiler import compile_code @@ -19,15 +17,12 @@ def foo(): expected = "Instantiating events with positional arguments is deprecated " expected += "as of v0.4.1 and will be disallowed in a future release. " expected += "Use kwargs instead e.g.:\n" - expected += "```\nIERC20.Transfer(sender=msg.sender, receiver=msg.sender, value=123)\n```" + expected += "```\nlog IERC20.Transfer(sender=msg.sender, receiver=msg.sender, value=123)\n```" assert len(w) == 1, [s.message for s in w] assert str(w[0].message).startswith(expected) -# https://github.com/vyperlang/vyper/pull/4275#issuecomment-2394910693 -# explains the xfail -@pytest.mark.xfail(raises=AssertionError) def test_event_hint_single_char_argument(): code = """ from ethereum.ercs import IERC20 @@ -42,7 +37,7 @@ def foo(): expected = "Instantiating events with positional arguments is deprecated " expected += "as of v0.4.1 and will be disallowed in a future release. " expected += "Use kwargs instead e.g.:\n" - expected += "```\nIERC20.Transfer(sender=msg.sender, receiver=msg.sender, value=1)\n```" + expected += "```\nlog IERC20.Transfer(sender=msg.sender, receiver=msg.sender, value=1)\n```" assert len(w) == 1, [s.message for s in w] assert str(w[0].message).startswith(expected)