Skip to content

Commit

Permalink
refactor: no need to explicitly pass in the selector into notLocked m…
Browse files Browse the repository at this point in the history
…odifier
  • Loading branch information
amarinkovic committed Aug 30, 2024
1 parent e1cd308 commit 3137ed2
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 32 deletions.
6 changes: 1 addition & 5 deletions src/facets/EntityFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ contract EntityFacet is Modifiers, ReentrancyGuard {
* @param _amount amount of entity tokens to put on sale
* @param _totalPrice total price of the tokens
*/
function startTokenSale(
bytes32 _entityId,
uint256 _amount,
uint256 _totalPrice
) external notLocked(msg.sig) nonReentrant assertPrivilege(_entityId, LC.GROUP_START_TOKEN_SALE) {
function startTokenSale(bytes32 _entityId, uint256 _amount, uint256 _totalPrice) external notLocked nonReentrant assertPrivilege(_entityId, LC.GROUP_START_TOKEN_SALE) {
LibEntity._startTokenSale(_entityId, _amount, _totalPrice);
}

Expand Down
4 changes: 2 additions & 2 deletions src/facets/MarketFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract MarketFacet is Modifiers, ReentrancyGuard {
*
* @param _offerId offer ID
*/
function cancelOffer(uint256 _offerId) external notLocked(msg.sig) nonReentrant assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_CANCEL_OFFER) {
function cancelOffer(uint256 _offerId) external notLocked nonReentrant assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_CANCEL_OFFER) {
require(LibMarket._getOffer(_offerId).state == LC.OFFER_STATE_ACTIVE, "offer not active");

Check warning on line 36 in src/facets/MarketFacet.sol

View workflow job for this annotation

GitHub Actions / Lint contracts

Use Custom Errors instead of require statements
bytes32 creator = LibMarket._getOffer(_offerId).creator;
require(LibObject._getParent(LibHelpers._getSenderId()) == creator, "only member of entity can cancel");

Check warning on line 38 in src/facets/MarketFacet.sol

View workflow job for this annotation

GitHub Actions / Lint contracts

Use Custom Errors instead of require statements
Expand All @@ -57,7 +57,7 @@ contract MarketFacet is Modifiers, ReentrancyGuard {
uint256 _buyAmount
)
external
notLocked(msg.sig)
notLocked
nonReentrant
assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_EXECUTE_LIMIT_OFFER)
returns (uint256 offerId_, uint256 buyTokenCommissionsPaid_, uint256 sellTokenCommissionsPaid_)
Expand Down
10 changes: 5 additions & 5 deletions src/facets/SimplePolicyFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract SimplePolicyFacet is Modifiers {
Stakeholders calldata _stakeholders,
SimplePolicy calldata _simplePolicy,
bytes32 _dataHash
) external notLocked(msg.sig) assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_UNDERWRITERS) assertSimplePolicyEnabled(_entityId) {
) external notLocked assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_UNDERWRITERS) assertSimplePolicyEnabled(_entityId) {
LibSimplePolicy._createSimplePolicy(_policyId, _entityId, _stakeholders, _simplePolicy, _dataHash);
}

Expand All @@ -44,7 +44,7 @@ contract SimplePolicyFacet is Modifiers {
* @param _policyId Id of the simple policy
* @param _amount Amount of the premium
*/
function paySimplePremium(bytes32 _policyId, uint256 _amount) external notLocked(msg.sig) assertPrivilege(_policyId, LC.GROUP_PAY_SIMPLE_PREMIUM) {
function paySimplePremium(bytes32 _policyId, uint256 _amount) external notLocked assertPrivilege(_policyId, LC.GROUP_PAY_SIMPLE_PREMIUM) {
bytes32 senderId = LibHelpers._getSenderId();
bytes32 payerEntityId = LibObject._getParent(senderId);

Expand All @@ -63,7 +63,7 @@ contract SimplePolicyFacet is Modifiers {
bytes32 _policyId,
bytes32 _insuredId,
uint256 _amount
) external notLocked(msg.sig) assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_PAY_SIMPLE_CLAIM) {
) external notLocked assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_PAY_SIMPLE_CLAIM) {
LibSimplePolicy._payClaim(_claimId, _policyId, _insuredId, _amount);
}

Expand Down Expand Up @@ -100,15 +100,15 @@ contract SimplePolicyFacet is Modifiers {
* @dev Check and update simple policy state
* @param _policyId Id of the simple policy
*/
function checkAndUpdateSimplePolicyState(bytes32 _policyId) external notLocked(msg.sig) {
function checkAndUpdateSimplePolicyState(bytes32 _policyId) external notLocked {
LibSimplePolicy._checkAndUpdateState(_policyId);
}

/**
* @dev Cancel a simple policy
* @param _policyId Id of the simple policy
*/
function cancelSimplePolicy(bytes32 _policyId) external notLocked(msg.sig) assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_UNDERWRITERS) {
function cancelSimplePolicy(bytes32 _policyId) external notLocked assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_UNDERWRITERS) {
LibSimplePolicy._cancel(_policyId);
}

Expand Down
13 changes: 4 additions & 9 deletions src/facets/StakingFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ contract StakingFacet is Modifiers {
LibTokenizedVaultStaking._initStaking(_entityId, _config);
}

function stake(bytes32 _entityId, uint256 _amount) external notLocked(msg.sig) {
function stake(bytes32 _entityId, uint256 _amount) external notLocked {
bytes32 parentId = LibObject._getParentFromAddress(msg.sender);
LibTokenizedVaultStaking._stake(parentId, _entityId, _amount);
}

function unstake(bytes32 _entityId) external notLocked(msg.sig) {
function unstake(bytes32 _entityId) external notLocked {
bytes32 parentId = LibObject._getParentFromAddress(msg.sender);
LibTokenizedVaultStaking._unstake(parentId, _entityId);
}
Expand Down Expand Up @@ -63,19 +63,14 @@ contract StakingFacet is Modifiers {
rewardAmounts_ = b.amounts;
}

function collectRewards(bytes32 _entityId) external notLocked(msg.sig) {
function collectRewards(bytes32 _entityId) external notLocked {
bytes32 parentId = LibObject._getParent(msg.sender._getIdForAddress());
uint64 lastPaid = LibTokenizedVaultStaking._lastPaidInterval(_entityId);

LibTokenizedVaultStaking._collectRewards(parentId, _entityId, lastPaid);
}

function payReward(
bytes32 _stakingRewardId,
bytes32 _entityId,
bytes32 _rewardTokenId,
uint256 _amount
) external notLocked(msg.sig) assertPrivilege(_entityId, LC.GROUP_ENTITY_ADMINS) {
function payReward(bytes32 _stakingRewardId, bytes32 _entityId, bytes32 _rewardTokenId, uint256 _amount) external notLocked assertPrivilege(_entityId, LC.GROUP_ENTITY_ADMINS) {
LibTokenizedVaultStaking._payReward(_stakingRewardId, _entityId, _rewardTokenId, _amount);
}

Expand Down
2 changes: 1 addition & 1 deletion src/facets/SystemFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract SystemFacet is Modifiers, ReentrancyGuard {
bytes32 _entityAdmin,
Entity calldata _entityData,
bytes32 _dataHash
) external notLocked(msg.sig) assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_MANAGERS) {
) external notLocked assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_MANAGERS) {
LibEntity._createEntity(_entityId, _entityAdmin, _entityData, _dataHash);
}

Expand Down
12 changes: 6 additions & 6 deletions src/facets/TokenizedVaultFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract TokenizedVaultFacet is Modifiers, ReentrancyGuard {
bytes32 to,
bytes32 tokenId,
uint256 amount
) external notLocked(msg.sig) nonReentrant assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_INTERNAL_TRANSFER_FROM_ENTITY) {
) external notLocked nonReentrant assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_INTERNAL_TRANSFER_FROM_ENTITY) {
bytes32 senderEntityId = LibObject._getParentFromAddress(msg.sender);
LibTokenizedVault._internalTransfer(senderEntityId, to, tokenId, amount);
}
Expand All @@ -63,7 +63,7 @@ contract TokenizedVaultFacet is Modifiers, ReentrancyGuard {
* @param tokenId Internal ID of the token
* @param amount being transferred
*/
function wrapperInternalTransferFrom(bytes32 from, bytes32 to, bytes32 tokenId, uint256 amount) external notLocked(msg.sig) nonReentrant assertERC20Wrapper(tokenId) {
function wrapperInternalTransferFrom(bytes32 from, bytes32 to, bytes32 tokenId, uint256 amount) external notLocked nonReentrant assertERC20Wrapper(tokenId) {
LibTokenizedVault._internalTransfer(from, to, tokenId, amount);
}

Expand All @@ -73,7 +73,7 @@ contract TokenizedVaultFacet is Modifiers, ReentrancyGuard {
* @param tokenId tokenID to be burned internally
* @param amount to be burned
*/
function internalBurn(bytes32 from, bytes32 tokenId, uint256 amount) external notLocked(msg.sig) assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_ADMINS) {
function internalBurn(bytes32 from, bytes32 tokenId, uint256 amount) external notLocked assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_ADMINS) {
LibTokenizedVault._internalBurn(from, tokenId, amount);
}

Expand All @@ -96,7 +96,7 @@ contract TokenizedVaultFacet is Modifiers, ReentrancyGuard {
* @param tokenId Unique ID of token
* @param dividendTokenId Unique ID of dividend token
*/
function withdrawDividend(bytes32 ownerId, bytes32 tokenId, bytes32 dividendTokenId) external notLocked(msg.sig) {
function withdrawDividend(bytes32 ownerId, bytes32 tokenId, bytes32 dividendTokenId) external notLocked {
LibTokenizedVault._withdrawDividend(ownerId, tokenId, dividendTokenId);
}

Expand All @@ -106,7 +106,7 @@ contract TokenizedVaultFacet is Modifiers, ReentrancyGuard {
* @param ownerId Unique ID of the dividend receiver
* @param tokenId Unique ID of token
*/
function withdrawAllDividends(bytes32 ownerId, bytes32 tokenId) external notLocked(msg.sig) {
function withdrawAllDividends(bytes32 ownerId, bytes32 tokenId) external notLocked {
LibTokenizedVault._withdrawAllDividends(ownerId, tokenId);
}

Expand All @@ -119,7 +119,7 @@ contract TokenizedVaultFacet is Modifiers, ReentrancyGuard {
function payDividendFromEntity(
bytes32 guid,
uint256 amount
) external notLocked(msg.sig) assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_PAY_DIVIDEND_FROM_ENTITY) {
) external notLocked assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_PAY_DIVIDEND_FROM_ENTITY) {
bytes32 entityId = LibObject._getParentFromAddress(msg.sender);
bytes32 dividendTokenId = LibEntity._getEntityInfo(entityId).assetId;

Expand Down
4 changes: 2 additions & 2 deletions src/facets/TokenizedVaultIOFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract TokenizedVaultIOFacet is Modifiers, ReentrancyGuard {
function externalDeposit(
address _externalTokenAddress,
uint256 _amount
) external notLocked(msg.sig) nonReentrant assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_EXTERNAL_DEPOSIT) {
) external notLocked nonReentrant assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_EXTERNAL_DEPOSIT) {
// a user can only deposit an approved external ERC20 token
require(LibAdmin._isSupportedExternalTokenAddress(_externalTokenAddress), "extDeposit: invalid ERC20 token");
// a user can only deposit to their valid entity
Expand All @@ -51,7 +51,7 @@ contract TokenizedVaultIOFacet is Modifiers, ReentrancyGuard {
address _receiver,
address _externalTokenAddress,
uint256 _amount
) external notLocked(msg.sig) nonReentrant assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_EXTERNAL_WITHDRAW_FROM_ENTITY) {
) external notLocked nonReentrant assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_EXTERNAL_WITHDRAW_FROM_ENTITY) {
if (!LibACL._hasGroupPrivilege(LibHelpers._getIdForAddress(_receiver), _entityId, LibHelpers._stringToBytes32(LC.GROUP_EXTERNAL_WITHDRAW_FROM_ENTITY)))
revert ExternalWithdrawInvalidReceiver(_receiver);
LibTokenizedVaultIO._externalWithdraw(_entityId, _receiver, _externalTokenAddress, _amount);
Expand Down
4 changes: 2 additions & 2 deletions src/shared/Modifiers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ contract Modifiers {
using LibACL for *;
using LibString for *;

modifier notLocked(bytes4 functionSelector) {
require(!LibAdmin._isFunctionLocked(functionSelector), "function is locked");
modifier notLocked() {
require(!LibAdmin._isFunctionLocked(msg.sig), "function is locked");
_;
}

Expand Down

0 comments on commit 3137ed2

Please sign in to comment.