Created
August 9, 2021 18:17
-
-
Save Turupawn/f87dd8d5588910ea853698f0f3e5a6d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.6; | |
import '@openzeppelin/contracts/token/ERC20/ERC20.sol'; | |
contract Router { | |
function addLiquidity( | |
address tokenA, | |
address tokenB, | |
uint amountADesired, | |
uint amountBDesired, | |
uint amountAMin, | |
uint amountBMin, | |
address to, | |
uint deadline | |
) external returns(uint amountA, uint amountB, uint liquidity) {} | |
function swapExactTokensForTokens( | |
uint amountIn, | |
uint amountOutMin, | |
address[] calldata path, | |
address to, | |
uint deadline | |
) external returns (uint[] memory amounts) {} | |
} | |
contract Liquifier | |
{ | |
//Change this during TESTNET and LIVE | |
Router router = Router(0xD99D1c33F9fC3444f8101754aBC46c52416550D1); //Testnet: 0xD99D1c33F9fC3444f8101754aBC46c52416550D1 Live: 0x10ED43C718714eb63d5aA57B78B54704E256024E | |
ERC20 TokenA = ERC20(0x4639933DDb0Ca005F3dD00bA64aE111c65792609); // Testnet: 0x07bc1BEee6559D4f0900c08525Ca4F2F53Ce9bbC Live WBNB: 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c | |
ERC20 TokenB = ERC20(0x07bc1BEee6559D4f0900c08525Ca4F2F53Ce9bbC); // Testnet: 0x07bc1BEee6559D4f0900c08525Ca4F2F53Ce9bbC Live WBNB: 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c | |
function swapAndLiquify( | |
uint amount | |
) public | |
{ | |
uint256 first_half = amount/2; | |
uint256 other_half = amount - first_half; | |
TokenA.approve(address(router), 999999999999999999999999999999999); | |
TokenB.approve(address(router), 999999999999999999999999999999999); | |
address[] memory path = new address[](2); | |
path[0] = address(TokenA); | |
path[1] = address(TokenB); | |
router.swapExactTokensForTokens( | |
other_half, | |
0, | |
path, | |
address(this), | |
block.timestamp | |
); | |
router.addLiquidity( | |
address(TokenA), | |
address(TokenB), | |
TokenA.balanceOf(address(this)), | |
TokenB.balanceOf(address(this)), | |
0, | |
0, | |
msg.sender, | |
block.timestamp | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment