Skip to content

Commit

Permalink
Fix prettier issues
Browse files Browse the repository at this point in the history
  • Loading branch information
drinkcoffee committed Oct 21, 2024
1 parent 967697d commit d44dcb5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 78 deletions.
42 changes: 18 additions & 24 deletions contracts/staking/StakeHolder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
pragma solidity ^0.8.20;

Check failure on line 3 in contracts/staking/StakeHolder.sol

View workflow job for this annotation

GitHub Actions / Run solhint

Compiler version ^0.8.20 does not satisfy the 0.8.19 semver requirement

import {UUPSUpgradeable} from "openzeppelin-contracts-upgradeable-4.9.3/proxy/utils/UUPSUpgradeable.sol";
import {AccessControlEnumerableUpgradeable, IAccessControlUpgradeable, AccessControlUpgradeable} from
"openzeppelin-contracts-upgradeable-4.9.3/access/AccessControlEnumerableUpgradeable.sol";
import {AccessControlEnumerableUpgradeable, IAccessControlUpgradeable, AccessControlUpgradeable} from "openzeppelin-contracts-upgradeable-4.9.3/access/AccessControlEnumerableUpgradeable.sol";

Check warning on line 6 in contracts/staking/StakeHolder.sol

View workflow job for this annotation

GitHub Actions / Run solhint

Variable "IAccessControlUpgradeable" is unused

Check warning on line 6 in contracts/staking/StakeHolder.sol

View workflow job for this annotation

GitHub Actions / Run solhint

Variable "AccessControlUpgradeable" is unused

/// @notice Struct to combine an account and an amount.
struct AccountAmount {
Expand Down Expand Up @@ -56,17 +55,17 @@ contract StakeHolder is AccessControlEnumerableUpgradeable, UUPSUpgradeable {
/// @notice Holds staking information for a single staker.
struct StakeInfo {
/// @notice Amount of stake.
uint256 stake;
uint256 stake;
/// @notice True if this account has ever staked.
bool hasStaked;
bool hasStaked;
}

/// @notice The amount of value owned by each staker
// solhint-disable-next-line private-vars-leading-underscore
mapping(address staker => StakeInfo stakeInfo) private balances;

/// @notice A list of all stakers who have ever staked.
/// @dev The list make contain stakers who have completely unstaked (that is, have
/// @dev The list make contain stakers who have completely unstaked (that is, have
/// a balance of 0). This array is never re-ordered. As such, off-chain services
/// could cache the results of getStakers().
// solhint-disable-next-line private-vars-leading-underscore
Expand All @@ -91,11 +90,11 @@ contract StakeHolder is AccessControlEnumerableUpgradeable, UUPSUpgradeable {
/**
* @notice Function to be called when upgrading this contract.
* @dev Call this function as part of upgradeToAndCall().
* This initial version of this function reverts. There is no situation
* This initial version of this function reverts. There is no situation
* in which it makes sense to upgrade to the V0 storage layout.
* Note that this function is permissionless. Future versions must
* compare the code version and the storage version and upgrade
* appropriately. As such, the code will revert if an attacker calls
* Note that this function is permissionless. Future versions must
* compare the code version and the storage version and upgrade
* appropriately. As such, the code will revert if an attacker calls
* this function attempting a malicious upgrade.
* @ param _data ABI encoded data to be used as part of the contract storage upgrade.
*/
Expand Down Expand Up @@ -139,15 +138,12 @@ contract StakeHolder is AccessControlEnumerableUpgradeable, UUPSUpgradeable {
/**
* @notice Any account can distribute tokens to any set of accounts.
* @dev The total amount to distribute must match msg.value.
* This function does not need re-entrancy guard as the distribution mechanism
* This function does not need re-entrancy guard as the distribution mechanism
* does not call out to another contract.
* @param _recipientsAndAmounts An array of recipients to distribute value to and
* @param _recipientsAndAmounts An array of recipients to distribute value to and
* amounts to be distributed to each recipient.
*/
function distributeRewards(AccountAmount[] calldata _recipientsAndAmounts)
external
payable
{
function distributeRewards(AccountAmount[] calldata _recipientsAndAmounts) external payable {
// Initial validity checks
if (msg.value == 0) {
revert MustDistributeMoreThanZero();
Expand All @@ -160,7 +156,7 @@ contract StakeHolder is AccessControlEnumerableUpgradeable, UUPSUpgradeable {
AccountAmount calldata accountAmount = _recipientsAndAmounts[i];
uint256 amount = accountAmount.amount;
// Add stake, but require the acount to either currently be staking or have
// previously staked.
// previously staked.
_addStake(accountAmount.account, amount, true);
total += amount;
}
Expand Down Expand Up @@ -192,9 +188,9 @@ contract StakeHolder is AccessControlEnumerableUpgradeable, UUPSUpgradeable {

/**
* @notice Get the length of the stakers array.
* @dev This will be equal to the number of staker accounts that have ever staked.
* @dev This will be equal to the number of staker accounts that have ever staked.
* Some of the accounts might have a zero balance, having staked and then
* unstaked.
* unstaked.
* @return _len The length of the stakers array.
*/
function getNumStakers() external view returns (uint256 _len) {
Expand All @@ -213,11 +209,10 @@ contract StakeHolder is AccessControlEnumerableUpgradeable, UUPSUpgradeable {
* @param _numberToReturn The number of accounts to return.
* @return _stakers A subset of the stakers array.
*/
function getStakers(uint256 _startOffset, uint256 _numberToReturn)
external
view
returns (address[] memory _stakers)
{
function getStakers(
uint256 _startOffset,
uint256 _numberToReturn
) external view returns (address[] memory _stakers) {
address[] memory stakerPartialArray = new address[](_numberToReturn);
for (uint256 i = 0; i < _numberToReturn; i++) {
stakerPartialArray[i] = stakers[_startOffset + i];
Expand Down Expand Up @@ -251,7 +246,6 @@ contract StakeHolder is AccessControlEnumerableUpgradeable, UUPSUpgradeable {
// solhint-disable-next-line no-empty-blocks
function _authorizeUpgrade(address newImplementation) internal override onlyRole(UPGRADE_ROLE) {}


/**
* @notice Prevent revoke or renounce role for the last DEFAULT_ADMIN_ROLE / the last role admin.
* @param _role The role to be renounced.
Expand Down
53 changes: 14 additions & 39 deletions contracts/token/erc1155/abstract/ERC1155Permit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ import "./IERC1155Permit.sol";
import {IImmutableERC1155Errors} from "../../../errors/Errors.sol";

abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImmutableERC1155Errors {

bytes32 private immutable _PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,bool approved,uint256 nonce,uint256 deadline)");

mapping(address => uint256) private _nonces;

constructor(string memory name, string memory uri)
ERC1155(uri)
EIP712(name, "1")
{}
constructor(string memory name, string memory uri) ERC1155(uri) EIP712(name, "1") {}

function permit(address owner, address spender, bool approved, uint256 deadline, bytes memory sig) external {
if (deadline < block.timestamp) {
Expand All @@ -30,7 +26,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm

// smart contract signature validation
if (_isValidERC1271Signature(owner, digest, sig)) {
_setApprovalForAll(owner, spender, approved);
_setApprovalForAll(owner, spender, approved);
return;
}

Expand Down Expand Up @@ -63,9 +59,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
* @param owner The address for which to retrieve the nonce.
* @return Current nonce of the given token.
*/
function nonces(
address owner
) external view returns (uint256) {
function nonces(address owner) external view returns (uint256) {
return _nonces[owner];
}

Expand All @@ -82,16 +76,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
* @param interfaceId The interface identifier, which is a 4-byte selector.
* @return True if the contract implements `interfaceId` and the call doesn't revert, otherwise false.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC1155)
returns (bool)
{
return
interfaceId == type(IERC1155Permit).interfaceId || // 0x9e3ae8e4
super.supportsInterface(interfaceId);
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155) returns (bool) {
return
interfaceId == type(IERC1155Permit).interfaceId || // 0x9e3ae8e4
super.supportsInterface(interfaceId);
}

/**
Expand All @@ -107,18 +95,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
bool approved,
uint256 deadline
) internal returns (bytes32) {
return _hashTypedDataV4(
keccak256(
abi.encode(
_PERMIT_TYPEHASH,
owner,
spender,
approved,
_nonces[owner]++,
deadline
)
)
);
return
_hashTypedDataV4(
keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, approved, _nonces[owner]++, deadline))
);
}

/**
Expand All @@ -128,14 +108,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
* @param sig The actual signature bytes.
* @return True if the signature is valid according to EIP-1271, otherwise false.
*/
function _isValidERC1271Signature(address spender, bytes32 digest, bytes memory sig) private view returns(bool) {
function _isValidERC1271Signature(address spender, bytes32 digest, bytes memory sig) private view returns (bool) {
// slither-disable-next-line low-level-calls
(bool success, bytes memory res) = spender.staticcall(
abi.encodeWithSelector(
IERC1271.isValidSignature.selector,
digest,
sig
)
abi.encodeWithSelector(IERC1271.isValidSignature.selector, digest, sig)
);

if (success && res.length == 32) {
Expand All @@ -154,8 +130,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
* @param owner The owner of the tokens.
* @return True if the signature is from an approved operator or owner, otherwise false.
*/
function _isValidEOASignature(address recoveredSigner, address owner) private pure returns(bool) {
function _isValidEOASignature(address recoveredSigner, address owner) private pure returns (bool) {
return recoveredSigner != address(0) && recoveredSigner == owner;
}

}
1 change: 0 additions & 1 deletion contracts/token/erc1155/abstract/ImmutableERC1155Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {OperatorAllowlistEnforced} from "../../../allowlist/OperatorAllowlistEnf

import {AccessControlEnumerable, MintingAccessControl} from "../../../access/MintingAccessControl.sol";


abstract contract ImmutableERC1155Base is OperatorAllowlistEnforced, ERC1155Permit, ERC2981, MintingAccessControl {
/// @dev Contract level metadata
string public contractURI;
Expand Down
8 changes: 1 addition & 7 deletions contracts/token/erc721/abstract/ImmutableERC721Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,7 @@ abstract contract ImmutableERC721Base is OperatorAllowlistEnforced, MintingAcces
*/
function supportsInterface(
bytes4 interfaceId
)
public
view
virtual
override(ERC721Permit, ERC2981, AccessControlEnumerable)
returns (bool)
{
) public view virtual override(ERC721Permit, ERC2981, AccessControlEnumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ abstract contract ImmutableERC721HybridBase is
/// @dev Returns the supported interfaces
function supportsInterface(
bytes4 interfaceId
)
public
view
virtual
override(ERC721HybridPermit, ERC2981, AccessControlEnumerable)
returns (bool)
{
) public view virtual override(ERC721HybridPermit, ERC2981, AccessControlEnumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}

Expand Down

0 comments on commit d44dcb5

Please sign in to comment.