-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,15 +57,26 @@ contract Swap is UniversalContract { | |
params.to = recipient; | ||
} | ||
|
||
swapAndWithdraw(zrc20, amount, params.target, params.to); | ||
uint256 out = handleGasAndSwap(zrc20, amount, params.target); | ||
gateway.withdraw( | ||
params.to, | ||
out, | ||
params.target, | ||
RevertOptions({ | ||
revertAddress: address(this), | ||
callOnRevert: true, | ||
abortAddress: address(0), | ||
revertMessage: abi.encode(context.sender, zrc20), | ||
onRevertGasLimit: 100000 | ||
}) | ||
); | ||
} | ||
|
||
function swapAndWithdraw( | ||
function handleGasAndSwap( | ||
address inputToken, | ||
uint256 amount, | ||
address targetToken, | ||
bytes memory recipient | ||
) internal { | ||
address targetToken | ||
) internal returns (uint256) { | ||
uint256 inputForGas; | ||
address gasZRC20; | ||
uint256 gasFee; | ||
|
@@ -100,13 +111,21 @@ contract Swap is UniversalContract { | |
IZRC20(gasZRC20).approve(address(gateway), gasFee); | ||
IZRC20(targetToken).approve(address(gateway), outputAmount); | ||
} | ||
return outputAmount; | ||
} | ||
Check warning Code scanning / Slither Unused return Medium
Swap.handleGasAndSwap(address,uint256,address) ignores return value by IZRC20(gasZRC20).approve(address(gateway),gasFee)
Check warning Code scanning / Slither Unused return Medium Check warning Code scanning / Slither Unused return Medium |
||
|
||
function onRevert(RevertContext calldata context) external onlyGateway { | ||
(address sender, address zrc20) = abi.decode( | ||
context.revertMessage, | ||
(address, address) | ||
); | ||
uint256 out = handleGasAndSwap(context.asset, context.amount, zrc20); | ||
gateway.withdraw( | ||
recipient, | ||
outputAmount, | ||
targetToken, | ||
abi.encodePacked(sender), | ||
out, | ||
zrc20, | ||
RevertOptions({ | ||
revertAddress: address(0), | ||
revertAddress: sender, | ||
callOnRevert: false, | ||
abortAddress: address(0), | ||
revertMessage: "", | ||
|
@@ -115,7 +134,13 @@ contract Swap is UniversalContract { | |
); | ||
} | ||
|
||
function onRevert( | ||
RevertContext calldata revertContext | ||
) external onlyGateway {} | ||
// // Fallback function that reverts | ||
// fallback() external payable { | ||
// revert("Fallback function triggered"); | ||
// } | ||
|
||
// // Receive function that reverts (for ETH transfers) | ||
// receive() external payable { | ||
// revert("ETH transfers not allowed"); | ||
// } | ||
} |