赞
踩
该脚本用途:一键可以完成与dex的所有交互,包括2次swap,添加/移除流动性,以及farm和提取LP。一次运行可以有6条交易记录。 无论是个人单刷还是羊毛党批量地址刷交互都完美适配。当然反女巫方案不在这次文章的讨论范围内。
const amount = '0.1'
const main = async () => { const kcsBalance = await wallet.getBalance() const usdtBalance = await usdtContract.balanceOf(wallet.address) // // swap twice times if (Number(ethers.utils.formatEther(kcsBalance)) > Number(amount) * 1.5 && Number(ethers.utils.formatEther(usdtBalance)) > Number(amount)) { // amount times 150% in order to confirm that the balance is sufficient, no exact value, just > 100% await approveLP2Router(); await swapKCS2USDT(); await swapUSDT2KCS(); } else { console.log(chalk.red(`KCS or USDT balance is not enough, please check your wallet`)); } // add liquidity await addLiquidity(tokens["kcc-testnet"].USDT, '0.0001', '0.1'); // deposit LP token & withdraw await depositLP2MasterChef(); await withdrawLP2MasterChef(); // remove liquidity await removeLPFromRouter(); console.log('Done: 2 swap, 1 add liquidity, 1 deposit, 1 withdraw, 1 remove liquidity') };
运行结果:
有朋友可能在数值的设定上有疑惑。这里扩展讲解一下 uniswapV2 的 addLiquidityETH 这个方法
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
那么到此为止,我们掌握了一键和dex交互的方式。希望各位撸羊毛愉快。
欢迎大哥们 follow 我的代码仓库(https://github.com/Bot80926/ethers-scripts)
完全开源,不留后门。只为Web3布道。希望各位看的开心,用得开心。声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/791367
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。