Skip to content

Commit

Permalink
♻️ Use Keyword Arguments for Event Instantiation (#280)
Browse files Browse the repository at this point in the history
### 🕓 Changelog

Vyper changed event instantiation from taking positional arguments to
taking keyword arguments (see PR
[#4257](vyperlang/vyper#4257)). This PR
refactors all 🐍 snekmate event instantiations accordingly (resolves
#277). Furthermore, we configure the tests to use the latest commit from
the `master` branch of Vyper going forward, ensuring we are always
testing against the most up-to-date version of the compiler.

---------

Signed-off-by: Pascal Marco Caversaccio <[email protected]>
  • Loading branch information
pcaversaccio authored Oct 7, 2024
1 parent 3855f73 commit ceb76b5
Show file tree
Hide file tree
Showing 59 changed files with 235 additions and 221 deletions.
206 changes: 103 additions & 103 deletions .gas-snapshot

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/halmos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
architecture: ${{ matrix.architecture }}

- name: Install Vyper
run: pip install vyper
run: pip install git+https://github.com/vyperlang/vyper@master

- name: Show the Vyper version
run: vyper --version
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
python-version: ${{ matrix.python_version }}
architecture: ${{ matrix.architecture }}

- name: Install Vyper
run: pip install git+https://github.com/vyperlang/vyper@master

- name: Show the Vyper version
run: vyper --version

- name: Setup Ape
uses: ApeWorX/github-action@v3
with:
Expand All @@ -42,12 +48,6 @@ jobs:
- name: Check Ape compilation
run: ape compile

- name: Remove Ape Vyper and install latest Vyper
run: pip install --force-reinstall vyper

- name: Show the Vyper version
run: vyper --version

- name: Install pnpm
uses: pnpm/action-setup@v3
with:
Expand Down
21 changes: 17 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,28 @@
### ♻️ Refactoring

- **Authentication**
- [`access_control`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/auth/access_control.vy): Use relative `interfaces` `import`s. ([#263](https://github.com/pcaversaccio/snekmate/pull/263))
- [`ownable`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/auth/ownable.vy): Use keyword arguments for event instantiation. ([#280](https://github.com/pcaversaccio/snekmate/pull/280))
- [`ownable_2step`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/auth/ownable_2step.vy): Use keyword arguments for event instantiation. ([#280](https://github.com/pcaversaccio/snekmate/pull/280))
- [`access_control`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/auth/access_control.vy):
- Use relative `interfaces` `import`s. ([#263](https://github.com/pcaversaccio/snekmate/pull/263))
- Use keyword arguments for event instantiation. ([#280](https://github.com/pcaversaccio/snekmate/pull/280))
- **Extensions**
- [`erc2981`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/extensions/erc2981.vy):
- Use relative `interfaces` `import`s. ([#263](https://github.com/pcaversaccio/snekmate/pull/263))
- Remove unnecessary `denominator` variable declaration. ([#267](https://github.com/pcaversaccio/snekmate/pull/267))
- [`erc4626`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/extensions/erc4626.vy): Use keyword arguments for event instantiation. ([#280](https://github.com/pcaversaccio/snekmate/pull/280))
- **Governance**
- [`timelock_controller`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/governance/timelock_controller.vy): Use keyword arguments for event instantiation. ([#280](https://github.com/pcaversaccio/snekmate/pull/280))
- **Tokens**
- [`erc20`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/tokens/erc20.vy): Use relative `interfaces` `import`s. ([#263](https://github.com/pcaversaccio/snekmate/pull/263))
- [`erc721`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/tokens/erc721.vy): Use relative `interfaces` `import`s. ([#263](https://github.com/pcaversaccio/snekmate/pull/263))
- [`erc1155`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/tokens/erc1155.vy): Use relative `interfaces` `import`s. ([#263](https://github.com/pcaversaccio/snekmate/pull/263))
- [`erc20`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/tokens/erc20.vy):
- Use relative `interfaces` `import`s. ([#263](https://github.com/pcaversaccio/snekmate/pull/263))
- Use keyword arguments for event instantiation. ([#280](https://github.com/pcaversaccio/snekmate/pull/280))
- [`erc721`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/tokens/erc721.vy):
- Use relative `interfaces` `import`s. ([#263](https://github.com/pcaversaccio/snekmate/pull/263))
- Use keyword arguments for event instantiation. ([#280](https://github.com/pcaversaccio/snekmate/pull/280))
- [`erc1155`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/tokens/erc1155.vy):
- Use relative `interfaces` `import`s. ([#263](https://github.com/pcaversaccio/snekmate/pull/263))
- Use keyword arguments for event instantiation. ([#280](https://github.com/pcaversaccio/snekmate/pull/280))
- **Utility Functions**
- [`eip712_domain_separator`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/utils/eip712_domain_separator.vy): Use relative `interfaces` `import`s. ([#263](https://github.com/pcaversaccio/snekmate/pull/263))
- [`math`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/utils/math.vy): Use mutable `internal` function parameters. ([#267](https://github.com/pcaversaccio/snekmate/pull/267))
Expand Down
8 changes: 4 additions & 4 deletions src/snekmate/auth/access_control.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title Multi-Role-Based Access Control Functions
@custom:contract-name access_control
Expand Down Expand Up @@ -210,7 +210,7 @@ def _set_role_admin(role: bytes32, admin_role: bytes32):
"""
previous_admin_role: bytes32 = self.getRoleAdmin[role]
self.getRoleAdmin[role] = admin_role
log IAccessControl.RoleAdminChanged(role, previous_admin_role, admin_role)
log IAccessControl.RoleAdminChanged(role=role, previousAdminRole=previous_admin_role, newAdminRole=admin_role)


@internal
Expand All @@ -224,7 +224,7 @@ def _grant_role(role: bytes32, account: address):
"""
if (not(self.hasRole[role][account])):
self.hasRole[role][account] = True
log IAccessControl.RoleGranted(role, account, msg.sender)
log IAccessControl.RoleGranted(role=role, account=account, sender=msg.sender)


@internal
Expand All @@ -238,4 +238,4 @@ def _revoke_role(role: bytes32, account: address):
"""
if (self.hasRole[role][account]):
self.hasRole[role][account] = False
log IAccessControl.RoleRevoked(role, account, msg.sender)
log IAccessControl.RoleRevoked(role=role, account=account, sender=msg.sender)
2 changes: 1 addition & 1 deletion src/snekmate/auth/interfaces/IAccessControl.vyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title `access_control` Interface Definition
@custom:contract-name IAccessControl
Expand Down
2 changes: 1 addition & 1 deletion src/snekmate/auth/mocks/access_control_mock.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title `access_control` Module Reference Implementation
@custom:contract-name access_control_mock
Expand Down
2 changes: 1 addition & 1 deletion src/snekmate/auth/mocks/ownable_2step_mock.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title `ownable_2step` Module Reference Implementation
@custom:contract-name ownable_2step_mock
Expand Down
2 changes: 1 addition & 1 deletion src/snekmate/auth/mocks/ownable_mock.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title `ownable` Module Reference Implementation
@custom:contract-name ownable_mock
Expand Down
4 changes: 2 additions & 2 deletions src/snekmate/auth/ownable.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title Owner-Based Access Control Functions
@custom:contract-name ownable
Expand Down Expand Up @@ -90,4 +90,4 @@ def _transfer_ownership(new_owner: address):
"""
old_owner: address = self.owner
self.owner = new_owner
log OwnershipTransferred(old_owner, new_owner)
log OwnershipTransferred(previous_owner=old_owner, new_owner=new_owner)
4 changes: 2 additions & 2 deletions src/snekmate/auth/ownable_2step.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title 2-Step Ownership Transfer Functions
@custom:contract-name ownable_2step
Expand Down Expand Up @@ -83,7 +83,7 @@ def transfer_ownership(new_owner: address):
"""
ownable._check_owner()
self.pending_owner = new_owner
log OwnershipTransferStarted(ownable.owner, new_owner)
log OwnershipTransferStarted(previous_owner=ownable.owner, new_owner=new_owner)


@external
Expand Down
2 changes: 1 addition & 1 deletion src/snekmate/extensions/erc2981.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title ERC-721 and ERC-1155 Compatible ERC-2981 Reference Implementation
@custom:contract-name erc2981
Expand Down
6 changes: 3 additions & 3 deletions src/snekmate/extensions/erc4626.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title Modern and Gas-Efficient ERC-4626 Tokenised Vault Implementation
@custom:contract-name erc4626
Expand Down Expand Up @@ -658,7 +658,7 @@ def _deposit(sender: address, receiver: address, assets: uint256, shares: uint25
# the target address is an EOA), the call reverts.
assert extcall _ASSET.transferFrom(sender, self, assets, default_return_value=True), "erc4626: transferFrom operation did not succeed"
erc20._mint(receiver, shares)
log IERC4626.Deposit(sender, receiver, assets, shares)
log IERC4626.Deposit(sender=sender, owner=receiver, assets=assets, shares=shares)


@internal
Expand Down Expand Up @@ -697,4 +697,4 @@ def _withdraw(sender: address, receiver: address, owner: address, assets: uint25
# you add the kwarg `skip_contract_check=True`. If the check fails (i.e.
# the target address is an EOA), the call reverts.
assert extcall _ASSET.transfer(receiver, assets, default_return_value=True), "erc4626: transfer operation did not succeed"
log IERC4626.Withdraw(sender, receiver, owner, assets, shares)
log IERC4626.Withdraw(sender=sender, receiver=receiver, owner=owner, assets=assets, shares=shares)
2 changes: 1 addition & 1 deletion src/snekmate/extensions/interfaces/IERC2981.vyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title EIP-2981 Interface Definition
@custom:contract-name IERC2981
Expand Down
2 changes: 1 addition & 1 deletion src/snekmate/extensions/mocks/erc2981_mock.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title `erc2981` Module Reference Implementation
@custom:contract-name erc2981_mock
Expand Down
2 changes: 1 addition & 1 deletion src/snekmate/extensions/mocks/erc4626_mock.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title `erc4626` Module Reference Implementation
@custom:contract-name erc4626_mock
Expand Down
2 changes: 1 addition & 1 deletion src/snekmate/governance/mocks/timelock_controller_mock.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title `timelock_controller` Module Reference Implementation
@custom:contract-name timelock_controller_mock
Expand Down
20 changes: 10 additions & 10 deletions src/snekmate/governance/timelock_controller.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title Multi-Role-Based Timelock Controller Reference Implementation
@custom:contract-name timelock_controller
Expand Down Expand Up @@ -275,7 +275,7 @@ def __init__(minimum_delay_: uint256, proposers_: DynArray[address, _DYNARRAY_BO

# Set the minimum delay.
self.get_minimum_delay = minimum_delay_
log MinimumDelayChange(empty(uint256), minimum_delay_)
log MinimumDelayChange(old_duration=empty(uint256), new_duration=minimum_delay_)


@external
Expand Down Expand Up @@ -425,9 +425,9 @@ def schedule(target: address, amount: uint256, payload: Bytes[1_024], predecesso
id: bytes32 = self._hash_operation(target, amount, payload, predecessor, salt)

self._schedule(id, delay)
log CallScheduled(id, empty(uint256), target, amount, payload, predecessor, delay)
log CallScheduled(id=id, index=empty(uint256), target=target, amount=amount, payload=payload, predecessor=predecessor, delay=delay)
if (salt != empty(bytes32)):
log CallSalt(id, salt)
log CallSalt(id=id, salt=salt)


@external
Expand Down Expand Up @@ -456,14 +456,14 @@ def schedule_batch(targets: DynArray[address, _DYNARRAY_BOUND], amounts: DynArra
self._schedule(id, delay)
idx: uint256 = empty(uint256)
for target: address in targets:
log CallScheduled(id, idx, target, amounts[idx], payloads[idx], predecessor, delay)
log CallScheduled(id=id, index=idx, target=target, amount=amounts[idx], payload=payloads[idx], predecessor=predecessor, delay=delay)
# The following line cannot overflow because we have
# limited the dynamic array `targets` by the `constant`
# parameter `_DYNARRAY_BOUND`, which is bounded by the
# maximum value of `uint8`.
idx = unsafe_add(idx, 1)
if (salt != empty(bytes32)):
log CallSalt(id, salt)
log CallSalt(id=id, salt=salt)


@external
Expand All @@ -476,7 +476,7 @@ def cancel(id: bytes32):
access_control._check_role(CANCELLER_ROLE, msg.sender)
assert self._is_operation_pending(id), "timelock_controller: operation cannot be cancelled"
self.get_timestamp[id] = empty(uint256)
log Cancelled(id)
log Cancelled(id=id)


@external
Expand All @@ -503,7 +503,7 @@ def execute(target: address, amount: uint256, payload: Bytes[1_024], predecessor

self._before_call(id, predecessor)
self._execute(target, amount, payload)
log CallExecuted(id, empty(uint256), target, amount, payload)
log CallExecuted(id=id, index=empty(uint256), target=target, amount=amount, payload=payload)
self._after_call(id)


Expand Down Expand Up @@ -536,7 +536,7 @@ def execute_batch(targets: DynArray[address, _DYNARRAY_BOUND], amounts: DynArray
idx: uint256 = empty(uint256)
for target: address in targets:
self._execute(target, amounts[idx], payloads[idx])
log CallExecuted(id, idx, target, amounts[idx], payloads[idx])
log CallExecuted(id=id, index=idx, target=target, amount=amounts[idx], payload=payloads[idx])
# The following line cannot overflow because we have
# limited the dynamic array `targets` by the `constant`
# parameter `_DYNARRAY_BOUND`, which is bounded by the
Expand All @@ -558,7 +558,7 @@ def update_delay(new_delay: uint256):
@param new_delay The new 32-byte minimum delay in seconds.
"""
assert msg.sender == self, "timelock_controller: caller must be timelock"
log MinimumDelayChange(self.get_minimum_delay, new_delay)
log MinimumDelayChange(old_duration=self.get_minimum_delay, new_duration=new_delay)
self.get_minimum_delay = new_delay


Expand Down
28 changes: 14 additions & 14 deletions src/snekmate/tokens/erc1155.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pragma version ~=0.4.0
# pragma version ~=0.4.1
"""
@title Modern and Gas-Efficient ERC-1155 Implementation
@custom:contract-name erc1155
Expand Down Expand Up @@ -156,7 +156,7 @@ def __init__(base_uri_: String[80]):
_BASE_URI = base_uri_

self.is_minter[msg.sender] = True
log RoleMinterChanged(msg.sender, True)
log RoleMinterChanged(minter=msg.sender, status=True)


@external
Expand Down Expand Up @@ -419,7 +419,7 @@ def set_minter(minter: address, status: bool):
# that `msg.sender` is the `owner`.
assert minter != msg.sender, "erc1155: minter is owner address"
self.is_minter[minter] = status
log RoleMinterChanged(minter, status)
log RoleMinterChanged(minter=minter, status=status)


@external
Expand All @@ -440,11 +440,11 @@ def transfer_ownership(new_owner: address):
assert new_owner != empty(address), "erc1155: new owner is the zero address"

self.is_minter[msg.sender] = False
log RoleMinterChanged(msg.sender, False)
log RoleMinterChanged(minter=msg.sender, status=False)

ownable._transfer_ownership(new_owner)
self.is_minter[new_owner] = True
log RoleMinterChanged(new_owner, True)
log RoleMinterChanged(minter=new_owner, status=True)


@external
Expand All @@ -466,7 +466,7 @@ def renounce_ownership():
"""
ownable._check_owner()
self.is_minter[msg.sender] = False
log RoleMinterChanged(msg.sender, False)
log RoleMinterChanged(minter=msg.sender, status=False)
ownable._transfer_ownership(empty(address))


Expand All @@ -482,7 +482,7 @@ def _set_approval_for_all(owner: address, operator: address, approved: bool):
"""
assert owner != operator, "erc1155: setting approval status for self"
self.isApprovedForAll[owner][operator] = approved
log IERC1155.ApprovalForAll(owner, operator, approved)
log IERC1155.ApprovalForAll(_owner=owner, _operator=operator, _approved=approved)


@internal
Expand Down Expand Up @@ -522,7 +522,7 @@ def _safe_transfer_from(owner: address, to: address, id: uint256, amount: uint25
# due to an arithmetic check of the entire token
# supply in the functions `_safe_mint` and `_safe_mint_batch`.
self.balanceOf[to][id] = unsafe_add(self.balanceOf[to][id], amount)
log IERC1155.TransferSingle(msg.sender, owner, to, id, amount)
log IERC1155.TransferSingle(_operator=msg.sender, _from=owner, _to=to, _id=id, _value=amount)

self._after_token_transfer(owner, to, self._as_singleton_array(id), self._as_singleton_array(amount), data)

Expand Down Expand Up @@ -578,7 +578,7 @@ def _safe_batch_transfer_from(owner: address, to: address, ids: DynArray[uint256
# maximum value of `uint16`.
idx = unsafe_add(idx, 1)

log IERC1155.TransferBatch(msg.sender, owner, to, ids, amounts)
log IERC1155.TransferBatch(_operator=msg.sender, _from=owner, _to=to, _ids=ids, _values=amounts)

self._after_token_transfer(owner, to, ids, amounts, data)

Expand Down Expand Up @@ -617,7 +617,7 @@ def _safe_mint(owner: address, id: uint256, amount: uint256, data: Bytes[1_024])
# due to an arithmetic check of the entire token
# supply in the function `_before_token_transfer`.
self.balanceOf[owner][id] = unsafe_add(self.balanceOf[owner][id], amount)
log IERC1155.TransferSingle(msg.sender, empty(address), owner, id, amount)
log IERC1155.TransferSingle(_operator=msg.sender, _from=empty(address), _to=owner, _id=id, _value=amount)

self._after_token_transfer(empty(address), owner, self._as_singleton_array(id), self._as_singleton_array(amount), data)

Expand Down Expand Up @@ -667,7 +667,7 @@ def _safe_mint_batch(owner: address, ids: DynArray[uint256, _BATCH_SIZE], amount
# maximum value of `uint16`.
idx = unsafe_add(idx, 1)

log IERC1155.TransferBatch(msg.sender, empty(address), owner, ids, amounts)
log IERC1155.TransferBatch(_operator=msg.sender, _from=empty(address), _to=owner, _ids=ids, _values=amounts)

self._after_token_transfer(empty(address), owner, ids, amounts, data)

Expand Down Expand Up @@ -728,7 +728,7 @@ def _set_uri(id: uint256, token_uri: String[432]):
string URI for computing `uri`.
"""
self._token_uris[id] = token_uri
log IERC1155.URI(self._uri(id), id)
log IERC1155.URI(_value=self._uri(id), _id=id)


@internal
Expand All @@ -750,7 +750,7 @@ def _burn(owner: address, id: uint256, amount: uint256):
owner_balance: uint256 = self.balanceOf[owner][id]
assert owner_balance >= amount, "erc1155: burn amount exceeds balance"
self.balanceOf[owner][id] = unsafe_sub(owner_balance, amount)
log IERC1155.TransferSingle(msg.sender, owner, empty(address), id, amount)
log IERC1155.TransferSingle(_operator=msg.sender, _from=owner, _to=empty(address), _id=id, _value=amount)

self._after_token_transfer(owner, empty(address), self._as_singleton_array(id), self._as_singleton_array(amount), b"")

Expand Down Expand Up @@ -786,7 +786,7 @@ def _burn_batch(owner: address, ids: DynArray[uint256, _BATCH_SIZE], amounts: Dy
# maximum value of `uint16`.
idx = unsafe_add(idx, 1)

log IERC1155.TransferBatch(msg.sender, owner, empty(address), ids, amounts)
log IERC1155.TransferBatch(_operator=msg.sender, _from=owner, _to=empty(address), _ids=ids, _values=amounts)

self._after_token_transfer(owner, empty(address), ids, amounts, b"")

Expand Down
Loading

0 comments on commit ceb76b5

Please sign in to comment.