Autoliquidity para Tokens Fuertototes
Toma en cuenta que este material está dirigido para oyentes avanzados por lo que te recomendaría profundizar sobre y desde un smart contract luego de ver este video.
Antes de iniciar
Segurate de instalar Metamask , conectar tu wallet a Polygon Mainnet y conseguir MATIC desde algún exchange. Pero este video es compatible también con cualquier blockchain compatible con la Ethereum Virtual Machine.
Lanzamos 엘 콘트라토
Nota que debes seleccionar la wallet de liquidez (
liquidityWallet
) y el address correcto del router
, este dependsará de dónde deseas lanzar el contrato:0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff
0x10ED43C718714eb63d5aA57B78B54704E256024E
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
0xD99D1c33F9fC3444f8101754aBC46c52416550D1
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
interface IUniswapV2Router02 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
contract MyToken is ERC20
{
address public liquidityWallet;
IUniswapV2Router02 router;
address public pair;
uint public feeDecimal = 2;
uint public feePercentage;
uint256 public minTokensBeforeSwap;
mapping(address => bool) public isTaxless;
bool private isLocked;
constructor () ERC20("My Token", "TKN")
{
router = IUniswapV2Router02(0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff);
pair = IUniswapV2Factory(router.factory()).createPair(address(this), router.WETH());
// Edit here
liquidityWallet = 0x0000000000000000000000000000000000000000;
uint supply = 1_000_000 ether;
feePercentage = 100; // 1.00% tx fee
minTokensBeforeSwap = 10 ether;
// End edit
isTaxless[msg.sender] = true;
isTaxless[liquidityWallet] = true;
isTaxless[address(this)] = true;
isTaxless[address(0)] = true;
_mint(msg.sender, supply);
}
function _beforeTokenTransfer(
address from,
address to,
uint amount
) internal virtual override(ERC20)
{
super._beforeTokenTransfer(from, to, amount);
if(!isLocked)
{
isLocked = true;
if(balanceOf(address(this)) >= minTokensBeforeSwap && from != pair)
autoLiquidity();
isLocked = false;
}
}
function _afterTokenTransfer(
address from,
address to,
uint amount
) internal virtual override(ERC20)
{
super._afterTokenTransfer(from, to, amount);
if(!isLocked)
{
if (!isTaxless[from]) {
uint feesCollected = calculateFee(amount);
if(feesCollected > 0)
{
isLocked = true;
_transfer(to, address(this), feesCollected);
isLocked = false;
}
}
}
}
function autoLiquidity() internal
{
// Let's swap half collected tokens for eth
uint amountToSwap = balanceOf(address(this)) / 2;
address[] memory sellPath = new address[](2);
sellPath[0] = address(this);
sellPath[1] = router.WETH();
_approve(address(this), address(router), amountToSwap);
router.swapExactTokensForETHSupportingFeeOnTransferTokens(
amountToSwap,
0,
sellPath,
address(this),
block.timestamp
);
// Now we are ready to send to LP
uint256 amountETHLiquidity = address(this).balance;
if(balanceOf(address(this)) > 0) {
_approve(address(this), address(router), balanceOf(address(this)));
router.addLiquidityETH{value: amountETHLiquidity}(
address(this),
balanceOf(address(this)),
0,
0,
liquidityWallet,
block.timestamp
);
}
}
function calculateFee(uint amount) internal view returns(uint) {
return (amount * feePercentage) / (10**(feeDecimal + 2));
}
fallback() external payable {}
receive() external payable {}
}
감사합니다 por ver este 튜토리얼!
Sígannos en dev.to y en para todo lo relacionado al desarrollo en Blockchain en Español.
Reference
이 문제에 관하여(Autoliquidity para Tokens Fuertototes), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/turupawn/autoliquidity-para-tokens-fuertototes-4kjk텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)