Skip to content

Commit

Permalink
chore: remove redundant logic and modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
alex0207s committed Jul 2, 2024
1 parent 6b0dd6d commit 019650b
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 27 deletions.
2 changes: 1 addition & 1 deletion contracts/AllowanceTarget.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract AllowanceTarget is IAllowanceTarget, Pausable, Ownable {
}

/// @inheritdoc IAllowanceTarget
function spendFromUserTo(address from, address token, address to, uint256 amount) external override whenNotPaused {
function spendFromUserTo(address from, address token, address to, uint256 amount) external whenNotPaused {
if (!authorized[msg.sender]) revert NotAuthorized();
IERC20(token).safeTransferFrom(from, to, amount);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/CoordinatedTaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract CoordinatedTaker is ICoordinatedTaker, AdminManagement, TokenCollector,
bytes calldata extraAction,
bytes calldata userTokenPermit,
CoordinatorParams calldata crdParams
) external payable override {
) external payable {
// validate fill permission
{
if (crdParams.expiry < block.timestamp) revert ExpiredPermission();
Expand Down
4 changes: 2 additions & 2 deletions contracts/GenericSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract GenericSwap is IGenericSwap, TokenCollector, EIP712 {

/// @param swapData Swap data
/// @return returnAmount Output amount of the swap
function executeSwap(GenericSwapData calldata swapData, bytes calldata takerTokenPermit) external payable override returns (uint256 returnAmount) {
function executeSwap(GenericSwapData calldata swapData, bytes calldata takerTokenPermit) external payable returns (uint256 returnAmount) {
returnAmount = _executeSwap(swapData, msg.sender, takerTokenPermit);

_emitGSExecuted(getGSDataHash(swapData), swapData, msg.sender, returnAmount);
Expand All @@ -35,7 +35,7 @@ contract GenericSwap is IGenericSwap, TokenCollector, EIP712 {
bytes calldata takerTokenPermit,
address taker,
bytes calldata takerSig
) external payable override returns (uint256 returnAmount) {
) external payable returns (uint256 returnAmount) {
bytes32 swapHash = getGSDataHash(swapData);
bytes32 gs712Hash = getEIP712Hash(swapHash);
if (filledSwap[swapHash]) revert AlreadyFilled();
Expand Down
14 changes: 6 additions & 8 deletions contracts/LimitOrderSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract LimitOrderSwap is ILimitOrderSwap, Ownable, TokenCollector, EIP712, Ree
}

/// @inheritdoc ILimitOrderSwap
function fillLimitOrder(LimitOrder calldata order, bytes calldata makerSignature, TakerParams calldata takerParams) external payable override nonReentrant {
function fillLimitOrder(LimitOrder calldata order, bytes calldata makerSignature, TakerParams calldata takerParams) external payable nonReentrant {
_fillLimitOrder(order, makerSignature, takerParams, false);
}

Expand All @@ -60,7 +60,7 @@ contract LimitOrderSwap is ILimitOrderSwap, Ownable, TokenCollector, EIP712, Ree
LimitOrder calldata order,
bytes calldata makerSignature,
TakerParams calldata takerParams
) external payable override nonReentrant {
) external payable nonReentrant {
_fillLimitOrder(order, makerSignature, takerParams, true);
}

Expand All @@ -70,7 +70,7 @@ contract LimitOrderSwap is ILimitOrderSwap, Ownable, TokenCollector, EIP712, Ree
bytes[] calldata makerSignatures,
uint256[] calldata makerTokenAmounts,
address[] calldata profitTokens
) external payable override nonReentrant {
) external payable nonReentrant {
if (orders.length != makerSignatures.length || orders.length != makerTokenAmounts.length) revert InvalidParams();

// validate orders and calculate takingAmounts
Expand Down Expand Up @@ -130,7 +130,7 @@ contract LimitOrderSwap is ILimitOrderSwap, Ownable, TokenCollector, EIP712, Ree
}

/// @inheritdoc ILimitOrderSwap
function cancelOrder(LimitOrder calldata order) external override nonReentrant {
function cancelOrder(LimitOrder calldata order) external nonReentrant {
if (order.expiry < uint64(block.timestamp)) revert ExpiredOrder();
if (msg.sender != order.maker) revert NotOrderMaker();
bytes32 orderHash = getLimitOrderHash(order);
Expand All @@ -143,7 +143,7 @@ contract LimitOrderSwap is ILimitOrderSwap, Ownable, TokenCollector, EIP712, Ree
emit OrderCanceled(orderHash, order.maker);
}

function isOrderCanceled(bytes32 orderHash) external view override returns (bool) {
function isOrderCanceled(bytes32 orderHash) external view returns (bool) {
uint256 orderFilledAmount = orderHashToMakerTokenFilledAmount[orderHash];
return (orderFilledAmount & ORDER_CANCEL_AMOUNT_MASK) != 0;
}
Expand Down Expand Up @@ -175,9 +175,7 @@ contract LimitOrderSwap is ILimitOrderSwap, Ownable, TokenCollector, EIP712, Ree
if (msg.value != takerParams.takerTokenAmount) revert InvalidMsgValue();
Asset.transferTo(Constant.ETH_ADDRESS, order.maker, takerSpendingAmount);
uint256 ethRefund = takerParams.takerTokenAmount - takerSpendingAmount;
if (ethRefund > 0) {
Asset.transferTo(Constant.ETH_ADDRESS, payable(msg.sender), ethRefund);
}
Asset.transferTo(Constant.ETH_ADDRESS, payable(msg.sender), ethRefund);
} else {
if (msg.value != 0) revert InvalidMsgValue();
_collect(order.takerToken, msg.sender, order.maker, takerSpendingAmount, takerParams.takerTokenPermit);
Expand Down
11 changes: 3 additions & 8 deletions contracts/RFQ.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ contract RFQ is IRFQ, Ownable, TokenCollector, EIP712 {
emit SetFeeCollector(_newFeeCollector);
}

function fillRFQ(
RFQTx calldata rfqTx,
bytes calldata makerSignature,
bytes calldata makerTokenPermit,
bytes calldata takerTokenPermit
) external payable override {
function fillRFQ(RFQTx calldata rfqTx, bytes calldata makerSignature, bytes calldata makerTokenPermit, bytes calldata takerTokenPermit) external payable {
_fillRFQ(rfqTx, makerSignature, makerTokenPermit, takerTokenPermit, bytes(""));
}

Expand All @@ -69,11 +64,11 @@ contract RFQ is IRFQ, Ownable, TokenCollector, EIP712 {
bytes calldata makerTokenPermit,
bytes calldata takerTokenPermit,
bytes calldata takerSignature
) external override {
) external {
_fillRFQ(rfqTx, makerSignature, makerTokenPermit, takerTokenPermit, takerSignature);
}

function cancelRFQOffer(RFQOffer calldata rfqOffer) external override {
function cancelRFQOffer(RFQOffer calldata rfqOffer) external {
if (msg.sender != rfqOffer.maker) revert NotOfferMaker();
bytes32 rfqOfferHash = getRFQOfferHash(rfqOffer);
if (filledOffer[rfqOfferHash]) revert FilledRFQOffer();
Expand Down
2 changes: 1 addition & 1 deletion contracts/SmartOrderStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract SmartOrderStrategy is ISmartOrderStrategy, AdminManagement {
}

/// @inheritdoc IStrategy
function executeStrategy(address inputToken, address outputToken, uint256 inputAmount, bytes calldata data) external payable override onlyGenericSwap {
function executeStrategy(address inputToken, address outputToken, uint256 inputAmount, bytes calldata data) external payable onlyGenericSwap {
if (inputAmount == 0) revert ZeroInput();

Operation[] memory ops = abi.decode(data, (Operation[]));
Expand Down
4 changes: 1 addition & 3 deletions contracts/abstracts/AdminManagement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ abstract contract AdminManagement is Ownable {
function rescueTokens(address[] calldata tokens, address recipient) external onlyOwner {
for (uint256 i = 0; i < tokens.length; ++i) {
uint256 selfBalance = Asset.getBalance(tokens[i], address(this));
if (selfBalance > 0) {
Asset.transferTo(tokens[i], payable(recipient), selfBalance);
}
Asset.transferTo(tokens[i], payable(recipient), selfBalance);
}
}
}
5 changes: 2 additions & 3 deletions contracts/libraries/Asset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ library Asset {
}

function transferTo(address asset, address payable to, uint256 amount) internal {
if (to == address(this) || amount == 0) {
return;
}
if (to == address(this) || amount == 0) return;

if (isETH(asset)) {
// @dev forward all available gas and may cause reentrancy
if (address(this).balance < amount) revert InsufficientBalance();
Expand Down

0 comments on commit 019650b

Please sign in to comment.