Skip to content

support native eth in swapAndTransfer #25

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

Merged
merged 2 commits into from
Apr 11, 2025
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
112 changes: 112 additions & 0 deletions EurekaHandler/broadcast/Upgrade.s.sol/1/run-1744276806.json

Large diffs are not rendered by default.

112 changes: 112 additions & 0 deletions EurekaHandler/broadcast/Upgrade.s.sol/1/run-1744276827.json

Large diffs are not rendered by default.

84 changes: 42 additions & 42 deletions EurekaHandler/broadcast/Upgrade.s.sol/1/run-latest.json

Large diffs are not rendered by default.

112 changes: 112 additions & 0 deletions EurekaHandler/broadcast/Upgrade.s.sol/11155111/run-1744277065.json

Large diffs are not rendered by default.

112 changes: 112 additions & 0 deletions EurekaHandler/broadcast/Upgrade.s.sol/11155111/run-1744277173.json

Large diffs are not rendered by default.

84 changes: 42 additions & 42 deletions EurekaHandler/broadcast/Upgrade.s.sol/11155111/run-latest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion EurekaHandler/script/Upgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract DeploymentScript is Script {

vm.startBroadcast();

EurekaHandler handler = EurekaHandler(0xFc2d0487A0ae42ae7329a80dc269916A9184cF7C);
EurekaHandler handler = EurekaHandler(0x46914a36365EC16600D81880903f3e95dcea3e5D);

EurekaHandler newHandlerImplementation = new EurekaHandler();

Expand Down
33 changes: 30 additions & 3 deletions EurekaHandler/src/EurekaHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,20 @@ contract EurekaHandler is IEurekaHandler, Initializable, UUPSUpgradeable, Ownabl
bytes memory swapCalldata,
TransferParams memory transferParams,
Fees memory fees
) external {
) external payable {
require(block.timestamp < fees.quoteExpiry, "Fee quote expired");

IERC20(swapInputToken).safeTransferFrom(msg.sender, address(this), swapInputAmount);
uint256 amountOut;
if (swapInputToken == address(0)) {
require(msg.value == swapInputAmount, "Insufficient native token");

amountOut = _swapNative(transferParams.token, swapInputAmount, swapCalldata);
} else {
IERC20(swapInputToken).safeTransferFrom(msg.sender, address(this), swapInputAmount);

amountOut = _swap(swapInputToken, transferParams.token, swapInputAmount, swapCalldata);
}

uint256 amountOut = _swap(swapInputToken, transferParams.token, swapInputAmount, swapCalldata);

if (amountOut <= _totalFees(fees)) {
revert("Insufficient amount out to cover fees");
Expand Down Expand Up @@ -178,6 +186,25 @@ contract EurekaHandler is IEurekaHandler, Initializable, UUPSUpgradeable, Ownabl
return amountOut;
}

function _swapNative(address tokenOut, uint256 amountIn, bytes memory swapCalldata)
internal
returns (uint256 amountOut)
{
uint256 tokenOutBalanceBefore = IERC20(tokenOut).balanceOf(address(this));

(bool success,) = swapRouter.call{value: amountIn}(swapCalldata);
if (!success) {
assembly {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
}

amountOut = IERC20(tokenOut).balanceOf(address(this)) - tokenOutBalanceBefore;

return amountOut;
}

function _totalFees(Fees memory fees) internal pure returns (uint256) {
return fees.relayFee;
}
Expand Down
2 changes: 1 addition & 1 deletion EurekaHandler/src/interfaces/IEurekaHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface IEurekaHandler {
bytes memory swapCalldata,
TransferParams memory transferParams,
Fees memory fees
) external;
) external payable;

function lombardTransfer(
uint256 amount,
Expand Down
Loading