Skip to content

Commit

Permalink
chore(SC-940): Move extensions to separate folder (#278)
Browse files Browse the repository at this point in the history
* chore: move files to extension, and add some comments

* chore: AmountCalculator to libraries to have consistent order structure

* chore: apply suggestions on comments from code review

Co-authored-by: zZoMROT <[email protected]>

* chore: Apply suggestions on comments from code review

---------

Co-authored-by: zZoMROT <[email protected]>
  • Loading branch information
artall64 and zZoMROT authored Oct 16, 2023
1 parent 033d094 commit 97eff07
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions contracts/OrderLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "@1inch/solidity-utils/contracts/libraries/AddressLib.sol";
import "./interfaces/IOrderMixin.sol";
import "./libraries/MakerTraitsLib.sol";
import "./libraries/ExtensionLib.sol";
import "./helpers/AmountCalculator.sol";
import "./libraries/AmountCalculatorLib.sol";
import "./interfaces/IAmountGetter.sol";

/**
Expand Down Expand Up @@ -96,7 +96,7 @@ import "./interfaces/IAmountGetter.sol";
bytes calldata data = extension.makingAmountData();
if (data.length == 0) {
// Linear proportion
return AmountCalculator.getMakingAmount(order.makingAmount, order.takingAmount, requestedTakingAmount);
return AmountCalculatorLib.getMakingAmount(order.makingAmount, order.takingAmount, requestedTakingAmount);
}
return IAmountGetter(address(bytes20(data))).getMakingAmount(
order,
Expand Down Expand Up @@ -130,7 +130,7 @@ import "./interfaces/IAmountGetter.sol";
bytes calldata data = extension.takingAmountData();
if (data.length == 0) {
// Linear proportion
return AmountCalculator.getTakingAmount(order.makingAmount, order.takingAmount, requestedMakingAmount);
return AmountCalculatorLib.getTakingAmount(order.makingAmount, order.takingAmount, requestedMakingAmount);
}
return IAmountGetter(address(bytes20(data))).getTakingAmount(
order,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pragma solidity 0.8.19;
import "@openzeppelin/contracts/utils/math/Math.sol";
import "../interfaces/IAmountGetter.sol";

/// @title A helper that implements price decay over time from max to min
/// @notice The contract implements Dutch auction price calculation for 1inch limit orders, it is used by 1inch Fusion
contract DutchAuctionCalculator is IAmountGetter {
using Math for uint256;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "@1inch/solidity-utils/contracts/OnlyWethReceiver.sol";
import "../interfaces/IPostInteraction.sol";
import "../OrderLib.sol";

/// @title ETH limit orders contract
/// @title Extension that will allow to create limit order that sell ETH. ETH must be deposited into the contract.
contract ETHOrders is IPostInteraction, OnlyWethReceiver {
using SafeERC20 for IWETH;
using OrderLib for IOrderMixin.Order;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "@1inch/solidity-utils/contracts/OnlyWethReceiver.sol";
import "@1inch/solidity-utils/contracts/interfaces/IWETH.sol";
import "@1inch/solidity-utils/contracts/libraries/SafeERC20.sol";

/// @title The extension to unwrap WETH and do payout in ETH in limit order postInteraction
/// @notice The feature was embedded into TakerTraits, so it is obsolete and will be removed
contract WethUnwrapper is OnlyWethReceiver {
using SafeERC20 for IWETH;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

pragma solidity 0.8.19;

/// @title A helper contract for calculations related to order amounts
library AmountCalculator {
/// @title The helper library to calculate linearly taker amount from maker amount and vice versa.
library AmountCalculatorLib {
/// @notice Calculates maker amount
/// @return Result Floored maker amount
function getMakingAmount(uint256 orderMakerAmount, uint256 orderTakerAmount, uint256 swapTakerAmount) internal pure returns(uint256) {
Expand Down

0 comments on commit 97eff07

Please sign in to comment.