Skip to content

Commit

Permalink
Merge pull request #43 from salmanferrum/develop
Browse files Browse the repository at this point in the history
FillOrderTo 1inch Swap and Allowance Fix in FiberRouter
  • Loading branch information
taha-abbasi committed Feb 20, 2024
2 parents 39be295 + 3abe7ce commit 989c561
Show file tree
Hide file tree
Showing 9 changed files with 957 additions and 283 deletions.
29 changes: 27 additions & 2 deletions contracts/common/oneInch/IOneInchSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IOneInchSwap {
interface IOneInchSwap {
struct SwapDescription {
IERC20 srcToken;
IERC20 dstToken;
Expand All @@ -12,8 +12,33 @@ interface IOneInchSwap {
uint256 minReturnAmount;
uint256 flags;
}
// Define external functions that will be available for interaction

struct Order {
uint256 salt;
address makerAsset; // targetToken
address takerAsset; // foundryToken
address maker;
address receiver;
address allowedSender; // equals to Zero address on public orders
uint256 makingAmount;
uint256 takingAmount;
uint256 offsets;
bytes interactions; // concat(makerAssetData, takerAssetData, getMakingAmount, getTakingAmount, predicate, permit, preIntercation, postInteraction)
}

// Define external functions that will be available for interaction

// fillOrderTo function
function fillOrderTo(
Order calldata order_,
bytes calldata signature,
bytes calldata interaction,
uint256 makingAmount,
uint256 takingAmount, // destinationAmountIn
uint256 skipPermitAndThresholdAmount,
address target // receiverAddress
) external payable returns(uint256 actualMakingAmount, uint256 actualTakingAmount, bytes32 orderHash);

// uniswapV3SwapTo function
function uniswapV3SwapTo(
address payable recipient,
Expand Down
49 changes: 47 additions & 2 deletions contracts/common/oneInch/OneInchDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ library OneInchDecoder {
uint256 minReturnAmount;
uint256 flags;
}
struct Order {
uint256 salt;
address makerAsset; // targetToken
address takerAsset; // foundryToken
address maker;
address receiver;
address allowedSender; // equals to Zero address on public orders
uint256 makingAmount;
uint256 takingAmount; // destinationAmountIn
uint256 offsets;
bytes interactions; // concat(makerAssetData, takerAssetData, getMakingAmount, getTakingAmount, predicate, permit, preIntercation, postInteraction)
}

// Define the function signatures
bytes4 public constant selectorUnoswap =
bytes4(
Expand All @@ -24,7 +37,14 @@ library OneInchDecoder {
"swap(address,(address,address,address,address,uint256,uint256,uint256),bytes,bytes)"
)
);

bytes4 public constant selectorFillOrderTo =
bytes4(
keccak256(
"fillOrderTo((uint256,address,address,address,address,address,uint256,uint256,uint256,bytes),bytes,bytes,uint256,uint256,uint256,address)"
)
);


function decodeUnoswap(bytes memory data)
public
pure
Expand Down Expand Up @@ -70,7 +90,7 @@ library OneInchDecoder {
);
}

function decodeSwap(bytes memory data)
function decodeSwap(bytes memory data)
public
pure
returns (
Expand Down Expand Up @@ -110,6 +130,31 @@ library OneInchDecoder {
return (desc.dstReceiver, desc.amount, desc.minReturnAmount);
}

function decodeFillOrderTo(bytes memory data)
public
pure
returns (
Order memory order_,
bytes memory signature,
bytes memory interaction,
uint256 makingAmount,
uint256 takingAmount, // destinationAmountIn
uint256 skipPermitAndThresholdAmount,
address target // receiverAddress
)
{
require(data.length >= 4, "Data too short");

// Skip the first 4 bytes (function signature)
bytes memory params = slice(data, 4, data.length - 4);

// Decode the parameters
(order_, signature, interaction, makingAmount, takingAmount, skipPermitAndThresholdAmount, target) = abi.decode(
params,
(Order, bytes, bytes, uint256, uint256,uint256, address)
);
}

// Helper function to slice bytes array
function slice(
bytes memory data,
Expand Down

0 comments on commit 989c561

Please sign in to comment.