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

🎨 Enforce PEP 8 Code Style Conventions #287

Merged
merged 5 commits into from
Nov 6, 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
224 changes: 112 additions & 112 deletions .gas-snapshot

Large diffs are not rendered by default.

268 changes: 134 additions & 134 deletions .gas-snapshot-venom

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Use relative `interfaces` `import`s. ([#263](https://github.com/pcaversaccio/snekmate/pull/263))
- Use `bytes1` literal in `eip712Domain` function. ([#283](https://github.com/pcaversaccio/snekmate/pull/283))
- [`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))
- [`multicall`](https://github.com/pcaversaccio/snekmate/blob/v0.1.1/src/snekmate/utils/multicall.vy): Optimise `Batch`-based `for` loops. ([#287](https://github.com/pcaversaccio/snekmate/pull/287))

### πŸ₯’ Test Coverage

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ When you propose a new feature, you should provide as much detail as possible, e

## πŸ›  Submitting a Pull Request (PR)

As a contributor, you are expected to fork the `main` branch of this repository, work on your own fork, and then submit pull requests. The pull requests are reviewed and eventually merged into the `main` repository. See ["Fork-a-Repo"](https://help.github.com/articles/fork-a-repo) for how this works.
As a contributor, you are expected to fork the `main` branch of this repository, work on your own fork, and then submit pull requests. The pull requests are reviewed and eventually merged into the `main` repository. See ["Fork a repository"](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) for how this works.

Ensure you read and follow our [Engineering Guidelines](./GUIDELINES.md). Run prettier, linter, and tests to make sure your PR is sound before submitting it.

Expand Down
3 changes: 2 additions & 1 deletion GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ def _as_singleton_array(element: uint256) -> DynArray[uint256, 1]:
- `external` functions
- `internal` functions
- There should be two line breaks between each variable or event declaration or function.
- Code comments should have a maximum line length of 80 characters including blank spaces.
- Each line of code should be limited to a maximum of 120 characters, including spaces.
- Code comments should be confined to a maximum of 80 characters per line, including spaces, with an allowed exception for comments with long URL links.
- For any undocumented behavior, please refer to [🐍Vyper's Official Style Guide](https://docs.vyperlang.org/en/latest/style-guide.html) and/or [PEP 8 – Style Guide for Python Code](https://peps.python.org/pep-0008).
2 changes: 1 addition & 1 deletion lib/create-util
Submodule create-util updated 2 files
+1 βˆ’1 package.json
+51 βˆ’51 pnpm-lock.yaml
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 2 files
+65 βˆ’0 src/Vm.sol
+1 βˆ’1 test/Vm.t.sol
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/generate_gas_snapshot.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# Set the default values.
OUTPUT_FILE=".gas-snapshot"
Expand Down
4 changes: 2 additions & 2 deletions src/snekmate/auth/access_control.vy
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _grant_role(role: bytes32, account: address):
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
"""
if (not(self.hasRole[role][account])):
if not self.hasRole[role][account]:
self.hasRole[role][account] = True
log IAccessControl.RoleGranted(role=role, account=account, sender=msg.sender)

Expand All @@ -236,6 +236,6 @@ def _revoke_role(role: bytes32, account: address):
@param role The 32-byte role definition.
@param account The 20-byte address of the account.
"""
if (self.hasRole[role][account]):
if self.hasRole[role][account]:
self.hasRole[role][account] = False
log IAccessControl.RoleRevoked(role=role, account=account, sender=msg.sender)
2 changes: 1 addition & 1 deletion src/snekmate/extensions/erc2981.vy
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def royaltyInfo(token_id: uint256, sale_price: uint256) -> (address, uint256):
`sale_price`.
"""
royalty: RoyaltyInfo = self._token_royalty_info[token_id]
if (royalty.receiver == empty(address)):
if royalty.receiver == empty(address):
royalty = self._default_royalty_info

# The following line uses intentionally checked arithmetic to
Expand Down
35 changes: 26 additions & 9 deletions src/snekmate/extensions/erc4626.vy
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ _UNDERLYING_DECIMALS: immutable(uint8)

@deploy
@payable
def __init__(name_: String[25], symbol_: String[5], asset_: IERC20, decimals_offset_: uint8, name_eip712_: String[50], version_eip712_: String[20]):
def __init__(
name_: String[25],
symbol_: String[5],
asset_: IERC20,
decimals_offset_: uint8,
name_eip712_: String[50],
version_eip712_: String[20],
):
"""
@dev To omit the opcodes for checking the `msg.value`
in the creation-time EVM bytecode, the constructor
Expand Down Expand Up @@ -324,7 +331,7 @@ def previewMint(shares: uint256) -> uint256:


@external
def mint(shares: uint256, receiver:address) -> uint256:
def mint(shares: uint256, receiver: address) -> uint256:
"""
@dev Mints exactly `shares` vault shares to `receiver` by
depositing `assets` of underlying tokens.
Expand Down Expand Up @@ -459,8 +466,10 @@ def _try_get_underlying_decimals(underlying: IERC20) -> (bool, uint8):
# successful with return data `0x`). Furthermore, it is important
# to note that an external call via `raw_call` does not perform an
# external code size check on the target address.
success, return_data = raw_call(underlying.address, method_id("decimals()"), max_outsize=32, is_static_call=True, revert_on_failure=False)
if (success and (len(return_data) == 32) and (convert(return_data, uint256) <= convert(max_value(uint8), uint256))):
success, return_data = raw_call(
underlying.address, method_id("decimals()"), max_outsize=32, is_static_call=True, revert_on_failure=False
)
if success and len(return_data) == 32 and convert(return_data, uint256) <= convert(max_value(uint8), uint256):
return (True, convert(return_data, uint8))
return (False, empty(uint8))

Expand Down Expand Up @@ -489,7 +498,9 @@ def _convert_to_shares(assets: uint256, roundup: bool) -> uint256:
to round up or not. The default `False` is round down.
@return uint256 The converted 32-byte shares amount.
"""
return math._mul_div(assets, erc20.totalSupply + 10 ** convert(_DECIMALS_OFFSET, uint256), self._total_assets() + 1, roundup)
return math._mul_div(
assets, erc20.totalSupply + 10 ** convert(_DECIMALS_OFFSET, uint256), self._total_assets() + 1, roundup
)


@internal
Expand All @@ -503,7 +514,9 @@ def _convert_to_assets(shares: uint256, roundup: bool) -> uint256:
to round up or not. The default `False` is round down.
@return uint256 The converted 32-byte assets amount.
"""
return math._mul_div(shares, self._total_assets() + 1, erc20.totalSupply + 10 ** convert(_DECIMALS_OFFSET, uint256), roundup)
return math._mul_div(
shares, self._total_assets() + 1, erc20.totalSupply + 10 ** convert(_DECIMALS_OFFSET, uint256), roundup
)


@internal
Expand Down Expand Up @@ -656,7 +669,9 @@ def _deposit(sender: address, receiver: address, assets: uint256, shares: uint25
# always performs an external code size check on the target address unless
# 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.transferFrom(sender, self, assets, default_return_value=True), "erc4626: transferFrom operation did not succeed"
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=sender, owner=receiver, assets=assets, shares=shares)

Expand All @@ -672,7 +687,7 @@ def _withdraw(sender: address, receiver: address, owner: address, assets: uint25
@param assets The 32-byte assets amount.
@param shares The 32-byte shares amount.
"""
if (sender != owner):
if sender != owner:
erc20._spend_allowance(owner, sender, shares)

# If `asset` is an ERC-777, `transfer` can trigger a reentrancy
Expand All @@ -696,5 +711,7 @@ def _withdraw(sender: address, receiver: address, owner: address, assets: uint25
# always performs an external code size check on the target address unless
# 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"
assert extcall _ASSET.transfer(
receiver, assets, default_return_value=True
), "erc4626: transfer operation did not succeed"
log IERC4626.Withdraw(sender=sender, receiver=receiver, owner=owner, assets=assets, shares=shares)
9 changes: 8 additions & 1 deletion src/snekmate/extensions/mocks/erc4626_mock.vy
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ exports: erc4626.__interface__

@deploy
@payable
def __init__(name_: String[25], symbol_: String[5], asset_: IERC20, decimals_offset_: uint8, name_eip712_: String[50], version_eip712_: String[20]):
def __init__(
name_: String[25],
symbol_: String[5],
asset_: IERC20,
decimals_offset_: uint8,
name_eip712_: String[50],
version_eip712_: String[20],
):
"""
@dev To omit the opcodes for checking the `msg.value`
in the creation-time EVM bytecode, the constructor
Expand Down
7 changes: 6 additions & 1 deletion src/snekmate/governance/mocks/timelock_controller_mock.vy
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ exports: tc.__interface__

@deploy
@payable
def __init__(minimum_delay_: uint256, proposers_: DynArray[address, tc._DYNARRAY_BOUND], executors_: DynArray[address, tc._DYNARRAY_BOUND], admin_: address):
def __init__(
minimum_delay_: uint256,
proposers_: DynArray[address, tc._DYNARRAY_BOUND],
executors_: DynArray[address, tc._DYNARRAY_BOUND],
admin_: address,
):
"""
@dev Initialises the contract with the following parameters:
- `minimum_delay_`: The initial minimum delay in seconds
Expand Down
Loading