Last active
August 10, 2021 22:25
-
-
Save Turupawn/14a787e7ea703616d4e7f7b57df80225 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
1. Lanzar Liquifier | |
2. Colocar el address de Liquifier en el Token | |
3. Recompilar y lanzar token | |
4. Approve el router en el token | |
5. Proveer liquidez con token B | |
6. Hacer tx a otra wallet | |
Puntos a mejorar: | |
* Usar "Tranfer" en vez de "mint" y "burn"? | |
* Buscar una manera no usar el contrato intermediario? | |
// 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 Factory { | |
mapping(address => mapping(address => address)) public getPair; | |
} | |
contract MyERC20 is ERC20 { | |
// CAMBIAR | |
string TOKEN_NAME = "Token"; | |
string TOKEN_SYMBOL = "TKN"; | |
uint256 TOTAL_SUPPLY = 21000000 ether; | |
address MARKETING_ADDRESS = 0x730bF3B67090511A64ABA060FbD2F7903536321E; | |
uint256 LIQUIDITY_TX_PERCENTAGE_FEE = 700; // 700 = 7,00% | |
uint256 MARKETING_TX_PERCENTAGE_FEE = 500; // 500 = 5,00% | |
ERC20 LIQUIDITY_SECOND_PAIR_TOKEN = ERC20(0x0b92DffE8b74787b02301AF5610f5091d241eDD5); // Testnet: 0x07bc1BEee6559D4f0900c08525Ca4F2F53Ce9bbC Live WBNB: 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c | |
Liquifier liquifier = Liquifier(0xaA6fA469F1017f7F4DA9593255362C7Cc5d1ad2c); | |
// CAMBIAR EN LIVE | |
Router router = Router(0xD99D1c33F9fC3444f8101754aBC46c52416550D1); //Testnet: 0xD99D1c33F9fC3444f8101754aBC46c52416550D1 Live: 0x10ED43C718714eb63d5aA57B78B54704E256024E | |
Factory factory = Factory(0x6725F303b657a9451d8BA641348b6761A6CC7a17); // Testnet: 0x6725F303b657a9451d8BA641348b6761A6CC7a17 Live: 0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73 | |
constructor () ERC20(TOKEN_NAME, TOKEN_SYMBOL) { | |
_mint(msg.sender, TOTAL_SUPPLY); | |
} | |
function getPercentage(uint256 number, uint256 percentage) internal pure returns(uint256 result) | |
{ | |
return number * percentage / 10000; | |
} | |
function _afterTokenTransfer(address from, address to, uint256 amount) internal override | |
{ | |
if(from != address(0) && to != address(0) | |
&& from != factory.getPair(address(this),address(LIQUIDITY_SECOND_PAIR_TOKEN)) | |
&& to != factory.getPair(address(this),address(LIQUIDITY_SECOND_PAIR_TOKEN))) | |
{ | |
uint256 liquidity_amount = getPercentage(amount, LIQUIDITY_TX_PERCENTAGE_FEE); | |
uint256 marketing_amount = getPercentage(amount, MARKETING_TX_PERCENTAGE_FEE); | |
_burn(to, marketing_amount + liquidity_amount); | |
_mint(MARKETING_ADDRESS, marketing_amount); | |
_mint(address(liquifier), liquidity_amount); | |
liquifier.swapAndLiquify(address(this), address(LIQUIDITY_SECOND_PAIR_TOKEN)); | |
} | |
} | |
} | |
contract Liquifier | |
{ | |
// CAMBIAR EN LIVE | |
Router router = Router(0xD99D1c33F9fC3444f8101754aBC46c52416550D1); //Testnet: 0xD99D1c33F9fC3444f8101754aBC46c52416550D1 Live: 0x10ED43C718714eb63d5aA57B78B54704E256024E | |
function swapAndLiquify( | |
address addres_token_a, | |
address addres_token_b | |
) public | |
{ | |
ERC20 TOKEN_A = ERC20(addres_token_a); | |
ERC20 TOKEN_B = ERC20(addres_token_b); | |
uint amount = TOKEN_A.balanceOf(address(this)); | |
uint256 first_half = amount/2; | |
uint256 other_half = amount - first_half; | |
TOKEN_A.approve(address(router), 99999999999999999999999999999); | |
TOKEN_B.approve(address(router), 99999999999999999999999999999); | |
address[] memory path = new address[](2); | |
path[0] = address(TOKEN_A); | |
path[1] = address(TOKEN_B); | |
router.swapExactTokensForTokens( | |
other_half, | |
0, | |
path, | |
address(this), | |
block.timestamp | |
); | |
router.addLiquidity( | |
address(TOKEN_A), | |
address(TOKEN_B), | |
TOKEN_A.balanceOf(address(this)), | |
TOKEN_B.balanceOf(address(this)), | |
0, | |
0, | |
address(this), | |
block.timestamp | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment