Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Make ERC721 Module-Friendly #237

Merged
merged 6 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
378 changes: 189 additions & 189 deletions .gas-snapshot

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
architecture:
- x64
python_version:
- 3.11
- 3.12

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-test-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
architecture:
- x64
python_version:
- 3.11
- 3.12

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
architecture:
- x64
python_version:
- 3.11
- 3.12
node_version:
- 20

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [`TimelockController`](https://github.com/pcaversaccio/snekmate/blob/v0.1.0/src/snekmate/governance/TimelockController.vy): Make `TimelockController` module-friendly. ([#220](https://github.com/pcaversaccio/snekmate/pull/220))
- **Tokens**
- [`ERC20`](https://github.com/pcaversaccio/snekmate/blob/v0.1.0/src/snekmate/tokens/ERC20.vy): Make `ERC20` module-friendly. ([#234](https://github.com/pcaversaccio/snekmate/pull/234))
- [`ERC721`](https://github.com/pcaversaccio/snekmate/blob/v0.1.0/src/snekmate/tokens/ERC721.vy): Make `ERC721` module-friendly. ([#237](https://github.com/pcaversaccio/snekmate/pull/237))
- **Utility Functions**
- [`Base64`](https://github.com/pcaversaccio/snekmate/blob/v0.1.0/src/snekmate/utils/Base64.vy): Make `Base64` module-friendly. ([#222](https://github.com/pcaversaccio/snekmate/pull/222))
- [`BatchDistributor`](https://github.com/pcaversaccio/snekmate/blob/v0.1.0/src/snekmate/utils/BatchDistributor.vy): Make `BatchDistributor` module-friendly. ([#223](https://github.com/pcaversaccio/snekmate/pull/223))
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ src
│ │ ├── IERC1155Receiver — "EIP-1155 Token Receiver Interface Definition"
│ │ └── IERC4906 — "EIP-4906 Interface Definition"
│ └── mocks
│ └── ERC20Mock — "ERC20 Module Reference Implementation"
│ ├── ERC20Mock — "ERC20 Module Reference Implementation"
│ └── ERC721Mock — "ERC721 Module Reference Implementation"
└── utils
├── Base64 — "Base64 Encoding and Decoding Functions"
├── BatchDistributor — "Batch Sending Both Native and ERC-20 Tokens"
Expand Down
2 changes: 1 addition & 1 deletion src/snekmate/extensions/mocks/ERC2981Mock.vy
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports: (
# @external
# @view
# def supportsInterface(interface_id: bytes4) -> bool:
# return (interface_id in erc2981._SUPPORTED_INTERFACES) or (interface_id in [0x..., ...])
# return ((interface_id in erc2981._SUPPORTED_INTERFACES) or (interface_id in [0x..., ...]))
# ```
erc2981.supportsInterface,
erc2981.owner,
Expand Down
16 changes: 8 additions & 8 deletions src/snekmate/governance/TimelockController.vy
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def schedule_batch(targets: DynArray[address, _DYNARRAY_BOUND], amounts: DynArra
Must be greater than or equal to the minimum delay.
"""
access_control._check_role(PROPOSER_ROLE, msg.sender)
assert len(targets) == len(amounts) and len(targets) == len(payloads), "TimelockController: length mismatch"
assert ((len(targets) == len(amounts)) and (len(targets) == len(payloads))), "TimelockController: length mismatch"
pcaversaccio marked this conversation as resolved.
Show resolved Hide resolved
id: bytes32 = self._hash_operation_batch(targets, amounts, payloads, predecessor, salt)

self._schedule(id, delay)
Expand Down Expand Up @@ -522,7 +522,7 @@ def execute_batch(targets: DynArray[address, _DYNARRAY_BOUND], amounts: DynArray
the operation during reentrancy are caught.
"""
self._only_role_or_open_role(EXECUTOR_ROLE)
assert len(targets) == len(amounts) and len(targets) == len(payloads), "TimelockController: length mismatch"
assert ((len(targets) == len(amounts)) and (len(targets) == len(payloads))), "TimelockController: length mismatch"
id: bytes32 = self._hash_operation_batch(targets, amounts, payloads, predecessor, salt)

self._before_call(id, predecessor)
Expand Down Expand Up @@ -655,7 +655,7 @@ def _is_operation_pending(id: bytes32) -> bool:
is pending or not.
"""
state: OperationState = self._get_operation_state(id)
return state == OperationState.WAITING or state == OperationState.READY
return ((state == OperationState.WAITING) or (state == OperationState.READY))


@internal
Expand Down Expand Up @@ -700,8 +700,8 @@ def _get_operation_state(id: bytes32) -> OperationState:
return OperationState.DONE
elif (timestamp > block.timestamp):
return OperationState.WAITING
else:
return OperationState.READY

return OperationState.READY


@internal
Expand Down Expand Up @@ -777,8 +777,8 @@ def _execute(target: address, amount: uint256, payload: Bytes[1_024]):
if (len(return_data) != empty(uint256)):
# Bubble up the revert reason.
raw_revert(return_data)
else:
raise "TimelockController: underlying transaction reverted"

raise "TimelockController: underlying transaction reverted"


@internal
Expand All @@ -792,7 +792,7 @@ def _before_call(id: bytes32, predecessor: bytes32):
operation.
"""
assert self._is_operation_ready(id), "TimelockController: operation is not ready"
assert predecessor == empty(bytes32) or self._is_operation_done(predecessor), "TimelockController: missing dependency"
assert ((predecessor == empty(bytes32)) or (self._is_operation_done(predecessor))), "TimelockController: missing dependency"


@internal
Expand Down
20 changes: 10 additions & 10 deletions src/snekmate/tokens/ERC1155.vy
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def safeTransferFrom(owner: address, to: address, id: uint256, amount: uint256,
@param data The maximum 1,024-byte additional data
with no specified format.
"""
assert owner == msg.sender or self.isApprovedForAll[owner][msg.sender], "ERC1155: caller is not token owner or approved"
assert ((owner == msg.sender) or (self.isApprovedForAll[owner][msg.sender])), "ERC1155: caller is not token owner or approved"
self._safe_transfer_from(owner, to, id, amount, data)


Expand Down Expand Up @@ -256,7 +256,7 @@ def safeBatchTransferFrom(owner: address, to: address, ids: DynArray[uint256, _B
@param data The maximum 1,024-byte additional data
with no specified format.
"""
assert owner == msg.sender or self.isApprovedForAll[owner][msg.sender], "ERC1155: caller is not token owner or approved"
assert ((owner == msg.sender) or (self.isApprovedForAll[owner][msg.sender])), "ERC1155: caller is not token owner or approved"
self._safe_batch_transfer_from(owner, to, ids, amounts, data)


Expand Down Expand Up @@ -376,7 +376,7 @@ def burn(owner: address, id: uint256, amount: uint256):
@param id The 32-byte identifier of the token.
@param amount The 32-byte token amount to be destroyed.
"""
assert owner == msg.sender or self.isApprovedForAll[owner][msg.sender], "ERC1155: caller is not token owner or approved"
assert ((owner == msg.sender) or (self.isApprovedForAll[owner][msg.sender])), "ERC1155: caller is not token owner or approved"
self._burn(owner, id, amount)


Expand All @@ -394,7 +394,7 @@ def burn_batch(owner: address, ids: DynArray[uint256, _BATCH_SIZE], amounts: Dyn
being destroyed. Note that the order and length must
match the 32-byte `ids` array.
"""
assert owner == msg.sender or self.isApprovedForAll[owner][msg.sender], "ERC1155: caller is not token owner or approved"
assert ((owner == msg.sender) or (self.isApprovedForAll[owner][msg.sender])), "ERC1155: caller is not token owner or approved"
self._burn_batch(owner, ids, amounts)


Expand Down Expand Up @@ -768,8 +768,8 @@ def _uri(id: uint256) -> String[512]:
# concatenation and simply return `_BASE_URI`
# for easier off-chain handling.
return concat(_BASE_URI, uint2str(id))
else:
return ""

return ""


@internal
Expand Down Expand Up @@ -872,9 +872,9 @@ def _check_on_erc1155_received(owner: address, to: address, id: uint256, amount:
assert return_value == method_id("onERC1155Received(address,address,uint256,uint256,bytes)", output_type=bytes4),\
"ERC1155: transfer to non-ERC1155Receiver implementer"
return True

# EOA case.
else:
return True
return True


@internal
Expand All @@ -901,9 +901,9 @@ def _check_on_erc1155_batch_received(owner: address, to: address, ids: DynArray[
assert return_value == method_id("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)", output_type=bytes4),\
"ERC1155: transfer to non-ERC1155Receiver implementer"
return True

# EOA case.
else:
return True
return True


@internal
Expand Down
Loading