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

FillOrderTo 1inch Swap and Allowance Fix in FiberRouter #43

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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