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

emit events on swap success #18

Merged
merged 2 commits into from
Jan 23, 2025
Merged
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
15 changes: 14 additions & 1 deletion AxelarHandler/src/AxelarHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ contract AxelarHandler is AxelarExecutableUpgradeable, Ownable2StepUpgradeable,
error Reentrancy();
error FunctionCodeNotSupported();

event SwapSuccess(address tokenIn, address tokenOut, uint256 amountIn, uint256 amountOut);
event SwapFailed();

enum Commands {
SendToken,
SendNative,
Expand Down Expand Up @@ -256,6 +259,8 @@ contract AxelarHandler is AxelarExecutableUpgradeable, Ownable2StepUpgradeable,
(bool ethSuccess,) = msg.sender.call{value: dust}("");
if (!ethSuccess) revert ETHSendFailed();
}

emit SwapSuccess(inputToken, address(outputToken), amount, outputAmount);
} else {
// ERC20 Token
if (gasPaymentAmount != msg.value) revert();
Expand Down Expand Up @@ -290,6 +295,8 @@ contract AxelarHandler is AxelarExecutableUpgradeable, Ownable2StepUpgradeable,
// Revoke approval
token.safeApprove(address(swapRouter), 0);
}

emit SwapSuccess(inputToken, address(outputToken), amount, outputAmount);
}

// Pay the gas for the GMP transfer
Expand Down Expand Up @@ -390,11 +397,14 @@ contract AxelarHandler is AxelarExecutableUpgradeable, Ownable2StepUpgradeable,
) {
if (unwrapOut) {
_sendNative(address(tokenOut), amountOut, destination);
emit SwapSuccess(address(tokenIn), address(0), amount, amountOut);
} else {
_sendToken(address(tokenOut), amountOut, destination);
emit SwapSuccess(address(tokenIn), address(tokenOut), amount, amountOut);
}
} catch {
_sendToken(token, amount, destination);
emit SwapFailed();
}
} else if (command == Commands.MultiSwap) {
(address destination, bool unwrapOut, bytes[] memory swaps) = abi.decode(data, (address, bool, bytes[]));
Expand All @@ -404,11 +414,14 @@ contract AxelarHandler is AxelarExecutableUpgradeable, Ownable2StepUpgradeable,
) {
if (unwrapOut) {
_sendNative(address(tokenOut), amountOut, destination);
emit SwapSuccess(address(tokenIn), address(0), amount, amountOut);
} else {
_sendToken(address(tokenOut), amountOut, destination);
emit SwapSuccess(address(tokenIn), address(tokenOut), amount, amountOut);
}
} catch {
_sendToken(token, amount, destination);
emit SwapFailed();
}
} else {
revert FunctionCodeNotSupported();
Expand All @@ -427,4 +440,4 @@ contract AxelarHandler is AxelarExecutableUpgradeable, Ownable2StepUpgradeable,
}

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
}
}
Loading