Skip to content

Commit

Permalink
Merge pull request #340 from consenlabs/style/format-imports
Browse files Browse the repository at this point in the history
specify dependency version in import paths and organize imports by sorting
  • Loading branch information
alex0207s authored Jan 24, 2025
2 parents ded59b3 + 37cc0c8 commit b01d556
Show file tree
Hide file tree
Showing 47 changed files with 208 additions and 160 deletions.
9 changes: 5 additions & 4 deletions contracts/AllowanceTarget.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
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/utils/Pausable.sol";
import { IERC20 } from "@openzeppelin/contracts@v5.0.2/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts@v5.0.2/token/ERC20/utils/SafeERC20.sol";
import { Pausable } from "@openzeppelin/contracts@v5.0.2/utils/Pausable.sol";

import { Ownable } from "./abstracts/Ownable.sol";

import { IAllowanceTarget } from "./interfaces/IAllowanceTarget.sol";

/// @title AllowanceTarget Contract
Expand All @@ -22,7 +23,7 @@ contract AllowanceTarget is IAllowanceTarget, Pausable, Ownable {
/// @param trustedCaller An array of addresses that are initially authorized to call spendFromUserTo.
constructor(address _owner, address[] memory trustedCaller) Ownable(_owner) {
uint256 callerCount = trustedCaller.length;
for (uint256 i = 0; i < callerCount; ++i) {
for (uint256 i; i < callerCount; ++i) {
authorized[trustedCaller[i]] = true;
}
}
Expand Down
8 changes: 5 additions & 3 deletions contracts/CoordinatedTaker.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { TokenCollector } from "./abstracts/TokenCollector.sol";
import { AdminManagement } from "./abstracts/AdminManagement.sol";
import { EIP712 } from "./abstracts/EIP712.sol";
import { IWETH } from "./interfaces/IWETH.sol";
import { TokenCollector } from "./abstracts/TokenCollector.sol";

import { ICoordinatedTaker } from "./interfaces/ICoordinatedTaker.sol";
import { ILimitOrderSwap } from "./interfaces/ILimitOrderSwap.sol";
import { LimitOrder, getLimitOrderHash } from "./libraries/LimitOrder.sol";
import { IWETH } from "./interfaces/IWETH.sol";

import { AllowFill, getAllowFillHash } from "./libraries/AllowFill.sol";
import { Asset } from "./libraries/Asset.sol";
import { LimitOrder, getLimitOrderHash } from "./libraries/LimitOrder.sol";
import { SignatureValidator } from "./libraries/SignatureValidator.sol";

/// @title CoordinatedTaker Contract
Expand Down
6 changes: 4 additions & 2 deletions contracts/GenericSwap.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { TokenCollector } from "./abstracts/TokenCollector.sol";
import { EIP712 } from "./abstracts/EIP712.sol";
import { TokenCollector } from "./abstracts/TokenCollector.sol";

import { IGenericSwap } from "./interfaces/IGenericSwap.sol";
import { IStrategy } from "./interfaces/IStrategy.sol";
import { GenericSwapData, getGSDataHash } from "./libraries/GenericSwapData.sol";

import { Asset } from "./libraries/Asset.sol";
import { GenericSwapData, getGSDataHash } from "./libraries/GenericSwapData.sol";
import { SignatureValidator } from "./libraries/SignatureValidator.sol";

/// @title GenericSwap Contract
Expand Down
18 changes: 10 additions & 8 deletions contracts/LimitOrderSwap.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

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

import { TokenCollector } from "./abstracts/TokenCollector.sol";
import { Ownable } from "./abstracts/Ownable.sol";
import { EIP712 } from "./abstracts/EIP712.sol";
import { IWETH } from "./interfaces/IWETH.sol";
import { Ownable } from "./abstracts/Ownable.sol";
import { TokenCollector } from "./abstracts/TokenCollector.sol";

import { ILimitOrderSwap } from "./interfaces/ILimitOrderSwap.sol";
import { IStrategy } from "./interfaces/IStrategy.sol";
import { IWETH } from "./interfaces/IWETH.sol";

import { Asset } from "./libraries/Asset.sol";
import { Constant } from "./libraries/Constant.sol";
import { LimitOrder, getLimitOrderHash } from "./libraries/LimitOrder.sol";
import { Asset } from "./libraries/Asset.sol";
import { SignatureValidator } from "./libraries/SignatureValidator.sol";

/// @title LimitOrderSwap Contract
Expand Down Expand Up @@ -88,7 +90,7 @@ contract LimitOrderSwap is ILimitOrderSwap, Ownable, TokenCollector, EIP712, Ree
uint256[] memory takerTokenAmounts = new uint256[](orders.length);
uint256 wethToPay;
address payable _feeCollector = feeCollector;
for (uint256 i = 0; i < orders.length; ++i) {
for (uint256 i; i < orders.length; ++i) {
LimitOrder calldata order = orders[i];
uint256 makingAmount = makerTokenAmounts[i];
if (makingAmount == 0) revert ZeroMakerSpendingAmount();
Expand Down Expand Up @@ -133,13 +135,13 @@ contract LimitOrderSwap is ILimitOrderSwap, Ownable, TokenCollector, EIP712, Ree
}
}

for (uint256 i = 0; i < orders.length; ++i) {
for (uint256 i; i < orders.length; ++i) {
LimitOrder calldata order = orders[i];
order.takerToken.transferTo(order.maker, takerTokenAmounts[i]);
}

// any token left is considered as profit
for (uint256 i = 0; i < profitTokens.length; ++i) {
for (uint256 i; i < profitTokens.length; ++i) {
uint256 profit = profitTokens[i].getBalance(address(this));
profitTokens[i].transferTo(payable(msg.sender), profit);
}
Expand Down
12 changes: 7 additions & 5 deletions contracts/RFQ.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

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

import { TokenCollector } from "./abstracts/TokenCollector.sol";
import { Ownable } from "./abstracts/Ownable.sol";
import { EIP712 } from "./abstracts/EIP712.sol";
import { IWETH } from "./interfaces/IWETH.sol";
import { Ownable } from "./abstracts/Ownable.sol";
import { TokenCollector } from "./abstracts/TokenCollector.sol";

import { IRFQ } from "./interfaces/IRFQ.sol";
import { IWETH } from "./interfaces/IWETH.sol";
import { Asset } from "./libraries/Asset.sol";

import { Constant } from "./libraries/Constant.sol";
import { RFQOffer, getRFQOfferHash } from "./libraries/RFQOffer.sol";
import { RFQTx, getRFQTxHash } from "./libraries/RFQTx.sol";
import { Constant } from "./libraries/Constant.sol";
import { SignatureValidator } from "./libraries/SignatureValidator.sol";

/// @title RFQ Contract
Expand Down
10 changes: 6 additions & 4 deletions contracts/SmartOrderStrategy.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

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

import { AdminManagement } from "./abstracts/AdminManagement.sol";
import { Asset } from "./libraries/Asset.sol";
import { IWETH } from "./interfaces/IWETH.sol";

import { ISmartOrderStrategy } from "./interfaces/ISmartOrderStrategy.sol";
import { IStrategy } from "./interfaces/IStrategy.sol";
import { IWETH } from "./interfaces/IWETH.sol";

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

/// @title SmartOrderStrategy Contract
/// @author imToken Labs
Expand Down Expand Up @@ -52,7 +54,7 @@ contract SmartOrderStrategy is ISmartOrderStrategy, AdminManagement {
}

uint256 opsCount = ops.length;
for (uint256 i = 0; i < opsCount; ++i) {
for (uint256 i; i < opsCount; ++i) {
Operation memory op = ops[i];
_call(op.dest, op.inputToken, op.ratioNumerator, op.ratioDenominator, op.dataOffset, op.value, op.data);
}
Expand Down
13 changes: 7 additions & 6 deletions contracts/abstracts/AdminManagement.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

import { Ownable } from "./Ownable.sol";
import { Asset } from "../libraries/Asset.sol";

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

/// @title AdminManagement Contract
/// @author imToken Labs
/// @notice This contract provides administrative functions for token management.
Expand All @@ -22,8 +23,8 @@ abstract contract AdminManagement is Ownable {
/// @param tokens The array of token addresses to approve.
/// @param spenders The array of spender addresses to approve for each token.
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) {
for (uint256 i; i < tokens.length; ++i) {
for (uint256 j; j < spenders.length; ++j) {
IERC20(tokens[i]).forceApprove(spenders[j], type(uint256).max);
}
}
Expand All @@ -34,7 +35,7 @@ abstract contract AdminManagement is Ownable {
/// @param tokens An array of token addresses to rescue.
/// @param recipient The address to which rescued tokens will be transferred.
function rescueTokens(address[] calldata tokens, address recipient) external onlyOwner {
for (uint256 i = 0; i < tokens.length; ++i) {
for (uint256 i; i < tokens.length; ++i) {
uint256 selfBalance = Asset.getBalance(tokens[i], address(this));
Asset.transferTo(tokens[i], payable(recipient), selfBalance);
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/abstracts/TokenCollector.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { IERC20Permit } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts@v5.0.2/token/ERC20/IERC20.sol";
import { IERC20Permit } from "@openzeppelin/contracts@v5.0.2/token/ERC20/extensions/IERC20Permit.sol";
import { SafeERC20 } from "@openzeppelin/contracts@v5.0.2/token/ERC20/utils/SafeERC20.sol";

import { IUniswapPermit2 } from "../interfaces/IUniswapPermit2.sol";
import { IAllowanceTarget } from "../interfaces/IAllowanceTarget.sol";
import { IUniswapPermit2 } from "../interfaces/IUniswapPermit2.sol";

/// @title TokenCollector Contract
/// @author imToken Labs
Expand Down
36 changes: 18 additions & 18 deletions contracts/interfaces/ICoordinatedTaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ import { LimitOrder } from "../libraries/LimitOrder.sol";
/// @title ICoordinatedTaker Interface
/// @author imToken Labs
interface ICoordinatedTaker {
/// @title Coordinator Parameters
/// @dev Contains the signature, salt, and expiry for coordinator authorization.
struct CoordinatorParams {
bytes sig;
uint256 salt;
uint256 expiry;
}

/// @notice Emitted when a limit order is filled by the coordinator.
/// @param user The address of the user.
/// @param orderHash The hash of the order.
/// @param allowFillHash The hash of the allowed fill.
event CoordinatorFill(address indexed user, bytes32 indexed orderHash, bytes32 indexed allowFillHash);

/// @notice Emitted when the coordinator address is updated.
/// @param newCoordinator The address of the new coordinator.
event SetCoordinator(address newCoordinator);

/// @notice Error to be thrown when a permission is reused.
/// @dev This error is used to prevent the reuse of permissions.
error ReusedPermission();
Expand All @@ -26,24 +44,6 @@ interface ICoordinatedTaker {
/// @dev This error is used to ensure that a valid address is provided.
error ZeroAddress();

/// @title Coordinator Parameters
/// @dev Contains the signature, salt, and expiry for coordinator authorization.
struct CoordinatorParams {
bytes sig;
uint256 salt;
uint256 expiry;
}

/// @notice Emitted when a limit order is filled by the coordinator.
/// @param user The address of the user.
/// @param orderHash The hash of the order.
/// @param allowFillHash The hash of the allowed fill.
event CoordinatorFill(address indexed user, bytes32 indexed orderHash, bytes32 indexed allowFillHash);

/// @notice Emitted when the coordinator address is updated.
/// @param newCoordinator The address of the new coordinator.
event SetCoordinator(address newCoordinator);

/// @notice Submits a limit order fill with additional coordination parameters..
/// @param order The limit order to be filled.
/// @param makerSignature The signature of the maker.
Expand Down
4 changes: 2 additions & 2 deletions contracts/libraries/Asset.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

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

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

import { RFQOffer, getRFQOfferHash, RFQ_OFFER_TYPESTRING } from "./RFQOffer.sol";
import { RFQOffer, RFQ_OFFER_TYPESTRING, getRFQOfferHash } from "./RFQOffer.sol";

string constant RFQ_TX_TYPESTRING = string(abi.encodePacked("RFQTx(RFQOffer rfqOffer,address recipient,uint256 takerRequestAmount)", RFQ_OFFER_TYPESTRING));

Expand Down
4 changes: 2 additions & 2 deletions contracts/libraries/SignatureValidator.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { Address } from "@openzeppelin/contracts@v5.0.2/utils/Address.sol";
import { ECDSA } from "@openzeppelin/contracts@v5.0.2/utils/cryptography/ECDSA.sol";

import { IERC1271Wallet } from "../interfaces/IERC1271Wallet.sol";

Expand Down
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@openzeppelin/=lib/openzeppelin-contracts/
@openzeppelin/[email protected]=lib/openzeppelin-contracts/contracts/
forge-std/=lib/forge-std/src
11 changes: 6 additions & 5 deletions test/AllowanceTarget.t.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// SPDX-License-Identifier: MIT
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/utils/Pausable.sol";
import { IERC20 } from "@openzeppelin/contracts@v5.0.2/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts@v5.0.2/token/ERC20/utils/SafeERC20.sol";
import { Pausable } from "@openzeppelin/contracts@v5.0.2/utils/Pausable.sol";

import { IAllowanceTarget } from "contracts/interfaces/IAllowanceTarget.sol";
import { AllowanceTarget } from "contracts/AllowanceTarget.sol";
import { Ownable } from "contracts/abstracts/Ownable.sol";
import { MockERC20 } from "test/mocks/MockERC20.sol";
import { IAllowanceTarget } from "contracts/interfaces/IAllowanceTarget.sol";

import { MockDeflationaryERC20 } from "test/mocks/MockDeflationaryERC20.sol";
import { MockERC20 } from "test/mocks/MockERC20.sol";
import { MockNoReturnERC20 } from "test/mocks/MockNoReturnERC20.sol";
import { MockNoRevertERC20 } from "test/mocks/MockNoRevertERC20.sol";
import { BalanceSnapshot, Snapshot } from "test/utils/BalanceSnapshot.sol";
Expand Down
7 changes: 4 additions & 3 deletions test/Signing.t.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { AllowFill, ALLOWFILL_DATA_TYPEHASH } from "contracts/libraries/AllowFill.sol";
import { GenericSwapData, GS_DATA_TYPEHASH } from "contracts/libraries/GenericSwapData.sol";
import { LimitOrder, LIMITORDER_DATA_TYPEHASH } from "contracts/libraries/LimitOrder.sol";
import { ALLOWFILL_DATA_TYPEHASH, AllowFill } from "contracts/libraries/AllowFill.sol";
import { GS_DATA_TYPEHASH, GenericSwapData } from "contracts/libraries/GenericSwapData.sol";
import { LIMITORDER_DATA_TYPEHASH, LimitOrder } from "contracts/libraries/LimitOrder.sol";
import { RFQOffer, RFQ_OFFER_DATA_TYPEHASH } from "contracts/libraries/RFQOffer.sol";
import { RFQTx, RFQ_TX_TYPEHASH } from "contracts/libraries/RFQTx.sol";

import { SigHelper } from "test/utils/SigHelper.sol";

contract testEIP712Signing is SigHelper {
Expand Down
3 changes: 2 additions & 1 deletion test/abstracts/AdminManagement.t.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

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

import { AdminManagement } from "contracts/abstracts/AdminManagement.sol";
import { Ownable } from "contracts/abstracts/Ownable.sol";

import { MockERC20 } from "test/mocks/MockERC20.sol";
import { BalanceUtil } from "test/utils/BalanceUtil.sol";

Expand Down
1 change: 1 addition & 0 deletions test/abstracts/EIP712.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.26;

import { Test } from "forge-std/Test.sol";

import { EIP712 } from "contracts/abstracts/EIP712.sol";

contract EIP712Test is Test {
Expand Down
1 change: 1 addition & 0 deletions test/abstracts/Ownable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.26;

import { Test } from "forge-std/Test.sol";

import { Ownable } from "contracts/abstracts/Ownable.sol";

contract OwnableTest is Test {
Expand Down
Loading

0 comments on commit b01d556

Please sign in to comment.