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

Chore: cleanup and upgrade codebase #313

Merged
merged 8 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
branch = v4.9.2
url = https://github.com/OpenZeppelin/openzeppelin-contracts
branch = v5.0.2
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
Expand Down
6 changes: 3 additions & 3 deletions contracts/AllowanceTarget.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.26;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol";
import { Pausable } from "@openzeppelin/contracts/utils/Pausable.sol";

import { Ownable } from "./abstracts/Ownable.sol";
import { IAllowanceTarget } from "./interfaces/IAllowanceTarget.sol";
Expand All @@ -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
4 changes: 2 additions & 2 deletions contracts/CoordinatedTaker.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.26;

import { TokenCollector } from "./abstracts/TokenCollector.sol";
import { AdminManagement } from "./abstracts/AdminManagement.sol";
Expand Down 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
6 changes: 3 additions & 3 deletions contracts/GenericSwap.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.26;

import { TokenCollector } from "./abstracts/TokenCollector.sol";
import { EIP712 } from "./abstracts/EIP712.sol";
Expand All @@ -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
18 changes: 8 additions & 10 deletions contracts/LimitOrderSwap.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.26;

import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

import { TokenCollector } from "./abstracts/TokenCollector.sol";
import { Ownable } from "./abstracts/Ownable.sol";
Expand Down 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
13 changes: 4 additions & 9 deletions contracts/RFQ.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.26;

import { Address } from "@openzeppelin/contracts/utils/Address.sol";

Expand Down 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
4 changes: 2 additions & 2 deletions contracts/SmartOrderStrategy.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.26;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

Expand All @@ -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
6 changes: 2 additions & 4 deletions contracts/abstracts/AdminManagement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ abstract contract AdminManagement is Ownable {
function approveTokens(address[] calldata tokens, address[] calldata spenders) external onlyOwner {
for (uint256 i = 0; i < tokens.length; ++i) {
for (uint256 j = 0; j < spenders.length; ++j) {
IERC20(tokens[i]).safeApprove(spenders[j], type(uint256).max);
IERC20(tokens[i]).forceApprove(spenders[j], type(uint256).max);
}
}
}

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);
}
}
}
35 changes: 0 additions & 35 deletions contracts/abstracts/Multicall.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/abstracts/TokenCollector.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.26;

import { IERC20Permit } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand All @@ -13,7 +13,7 @@

error Permit2DataEmpty();

enum Source {

Check warning on line 16 in contracts/abstracts/TokenCollector.sol

View workflow job for this annotation

GitHub Actions / build (16.x)

Function order is incorrect, enum definition can not go after custom error definition (line 14)

Check warning on line 16 in contracts/abstracts/TokenCollector.sol

View workflow job for this annotation

GitHub Actions / build (16.x)

Function order is incorrect, enum definition can not go after custom error definition (line 14)
TokenlonAllowanceTarget,
Token,
TokenPermit,
Expand All @@ -21,8 +21,8 @@
Permit2SignatureTransfer
}

address public immutable permit2;

Check warning on line 24 in contracts/abstracts/TokenCollector.sol

View workflow job for this annotation

GitHub Actions / build (16.x)

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 24 in contracts/abstracts/TokenCollector.sol

View workflow job for this annotation

GitHub Actions / build (16.x)

Immutable variables name are set to be in capitalized SNAKE_CASE
address public immutable allowanceTarget;

Check warning on line 25 in contracts/abstracts/TokenCollector.sol

View workflow job for this annotation

GitHub Actions / build (16.x)

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 25 in contracts/abstracts/TokenCollector.sol

View workflow job for this annotation

GitHub Actions / build (16.x)

Immutable variables name are set to be in capitalized SNAKE_CASE

constructor(address _permit2, address _allowanceTarget) {
permit2 = _permit2;
Expand All @@ -37,7 +37,7 @@
} else if (src == Source.Token) {
return IERC20(token).safeTransferFrom(from, to, amount);
} else if (src == Source.TokenPermit) {
(bool success, bytes memory result) = token.call(abi.encodePacked(IERC20Permit.permit.selector, data[1:]));

Check warning on line 40 in contracts/abstracts/TokenCollector.sol

View workflow job for this annotation

GitHub Actions / build (16.x)

Avoid to use low level calls

Check warning on line 40 in contracts/abstracts/TokenCollector.sol

View workflow job for this annotation

GitHub Actions / build (16.x)

Avoid to use low level calls
if (!success) {
assembly {
revert(add(result, 32), returndatasize())
Expand Down
44 changes: 0 additions & 44 deletions contracts/interfaces/IAMMStrategy.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/interfaces/IAllowanceTarget.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
pragma solidity ^0.8.0;

/// @title IAllowanceTarget Interface
/// @author imToken Labs
Expand Down
42 changes: 0 additions & 42 deletions contracts/interfaces/IBalancerV2Vault.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/interfaces/ICoordinatedTaker.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
pragma solidity ^0.8.0;

import { LimitOrder } from "../libraries/LimitOrder.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IERC1271Wallet.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
pragma solidity ^0.8.0;

interface IERC1271Wallet {
function isValidSignature(bytes32 _hash, bytes calldata _signature) external view returns (bytes4 magicValue);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IGenericSwap.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
pragma solidity ^0.8.0;

import { GenericSwapData } from "../libraries/GenericSwapData.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ILimitOrderSwap.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
pragma solidity ^0.8.0;

import { LimitOrder } from "../libraries/LimitOrder.sol";

Expand Down
8 changes: 0 additions & 8 deletions contracts/interfaces/IMulticall.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/interfaces/IRFQ.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
pragma solidity ^0.8.0;

import { RFQOffer } from "../libraries/RFQOffer.sol";
import { RFQTx } from "../libraries/RFQTx.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ISmartOrderStrategy.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
pragma solidity ^0.8.0;

import { IStrategy } from "./IStrategy.sol";

Expand Down
Loading
Loading