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

Expiry And Withdraw Message Management #34

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contracts/common/oneInch/IOneInchSwap.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

Expand Down
76 changes: 6 additions & 70 deletions contracts/common/oneInch/OneInchDecoder.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

library OneInchDecoder {
struct SwapDescription {
struct SwapDescription {
address srcToken;
address dstToken;
address payable srcReceiver;
Expand All @@ -23,44 +24,16 @@ struct SwapDescription {
"swap(address,(address,address,address,address,uint256,uint256,uint256),bytes,bytes)"
)
);

// Function to identify which function is being called
function identifyFunction(bytes memory data)
public
pure
returns (string memory)
{
require(data.length >= 4, "Data too short for valid call");

// Extract the first 4 bytes from data
bytes4 receivedSelector;
assembly {
// Extract the first 4 bytes directly from the data
// Assuming 'data' starts with the 4-byte function selector
receivedSelector := mload(add(data, 32))
}

if (receivedSelector == selectorUnoswap) {
return "decodeUnoswap";
} else if (receivedSelector == selectorUniswapV3Swap) {
return "decodeUniswapV3Swap";
} else if (receivedSelector == selectorSwap) {
return "decodeSwap";
} else {
return "Unknown function";
}
}


function decodeUnoswap(bytes memory data)
public
pure
returns (
address payable recipient,
address srcToken,
address srcToken,
uint256 amount,
uint256 minReturn,
uint256[] memory pools

)
{
require(data.length >= 4, "Data too short");
Expand All @@ -82,10 +55,10 @@ struct SwapDescription {
address payable recipient,
uint256 amount,
uint256 minReturn,
uint256[] memory pools
uint256[] memory pools
)
{
require(data.length >= 4, "Data too short");
require(data.length >= 4, "Data too short");

// Skip the first 4 bytes (function signature)
bytes memory params = slice(data, 4, data.length - 4);
Expand Down Expand Up @@ -149,41 +122,4 @@ struct SwapDescription {
}
return part;
}

// function decodedInputs(bytes memory data)
// public
// pure
// returns (
// address payable recipient,
// uint256 amount,
// uint256 minReturn,
// uint256[] memory pools
// )
// {
// require(data.length >= 4, "Data too short for valid call");

// // Extract the first 4 bytes from data
// bytes4 receivedSelector;
// assembly {
// // Extract the first 4 bytes directly from the data
// // Assuming 'data' starts with the 4-byte function selector
// receivedSelector := mload(add(data, 32))
// }

// if (receivedSelector == selectorUnoswap) {
// // Call decodeUnoswap and return its values
// (recipient, amount, minReturn, pools) = decodeUnoswap(data);
// } else if (receivedSelector == selectorUniswapV3Swap) {
// // Call decodeUniswapV3Swap and return its values
// (recipient, amount, minReturn, pools) = decodeUniswapV3Swap(data);
// } else if (receivedSelector == selectorSwap) {
// (recipient, amount, minReturn) = decodeSwap2(data);

// }
// Assuming decodeSwap is not needed as per your comment
// else {
// revert("Unknown function selector");
// }
// Implicitly returns recipient, amount, minReturn
// }
}
Loading