-
Notifications
You must be signed in to change notification settings - Fork 232
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
1 parent
61fa775
commit ddebb80
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
packages/zevm-app-contracts/contracts/withdrawErc20/withdrawErc20.sol
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.7; | ||
|
||
import "@zetachain/protocol-contracts/contracts/zevm/SystemContract.sol"; | ||
import "@zetachain/toolkit/contracts/SwapHelperLib.sol"; | ||
|
||
contract WithdrawERC20 { | ||
SystemContract public immutable systemContract; | ||
|
||
constructor(address systemContractAddress) { | ||
systemContract = SystemContract(systemContractAddress); | ||
} | ||
|
||
function withdraw(address zrc20, uint256 amount, bytes memory to) external virtual { | ||
IZRC20(zrc20).transferFrom(msg.sender, address(this), amount); | ||
|
||
(address gasZRC20, uint256 gasFee) = IZRC20(zrc20).withdrawGasFee(); | ||
|
||
uint256 inputForGas = SwapHelperLib.swapTokensForExactTokens( | ||
systemContract.wZetaContractAddress(), | ||
systemContract.uniswapv2FactoryAddress(), | ||
systemContract.uniswapv2Router02Address(), | ||
zrc20, | ||
gasFee, | ||
gasZRC20, | ||
amount | ||
); | ||
|
||
IZRC20(gasZRC20).approve(zrc20, gasFee); | ||
IZRC20(zrc20).withdraw(to, amount - inputForGas); | ||
} | ||
} |