foreword
It has been a week since the last test video was released. During this week, I have upgraded the purchase method of the robot, which has significantly improved the speed and stability.
Upgrade technical details
The first version directly calls the PancakeRouter interface to purchase
The first-generation purchase method, after listening to adding pools, the script directly calls the purchase interface of PancakeRouter through web3 to purchase. However, the uplink speed of txpool is much slower than the internal transaction of the contract, so it needs to be upgraded.
That is, the pancake rush robot test video_Satoshi Light's Blog-CSDN Blog
The method of purchase used in this article.
if token['USECUSTOMBASEPAIR'].lower() == 'true':
transaction = routerContract.functions.swapExactTokensForTokens(
'''
).buildTransaction({
'''
})
else:
transaction = routerContract.functions.swapExactETHForTokens(
'''
).buildTransaction({
'''
})
The second version of the original contract purchase version
After monitoring the addition of the pool, the script will pass the currency used for purchase into the contract, and the contract will call PancakeRouter to purchase
Because the contract needs to call transferFrom to withdraw coins from the wallet before executing the purchase operation, and then call approve to allow pancake to withdraw coins from the contract, so it has a certain impact on the speed, and the optimization effect is not obvious at this time.
The contract code is as follows:
function swap(address _tokenIn, address _tokenOut, uint256 _amountIn, uint256 _amountOutMin, address _to) external {
IERC20(_tokenIn).transferFrom(msg.sender, address(this), _amountIn);
IERC20(_tokenIn).approve(UNISWAP_V2_ROUTER, _amountIn);
address[] memory path;
if (_tokenIn == WETH || _tokenOut == WETH) {
path = new address[](2);
path[0] = _tokenIn;
path[1] = _tokenOut;
} else {
path = new address[](3);
path[0] = _tokenIn;
path[1] = WETH;
path[2] = _tokenOut;
}
IUniswapV2Router(UNISWAP_V2_ROUTER).swapExactTokensForTokens(_amountIn, _amountOutMin, path, _to, block.timestamp);
}
The web3 calling code is as follows:
transaction = tokenSwapContract.functions.swap(
''')
The third version of the contract deposit currency version
Before the robot starts monitoring, deposit the coins used for the purchase into the contract and complete the approve operation, so that when the script calls the purchase function of the contract, it can immediately send a purchase request to PancakeRouter without other operations.
The performance of this version has been significantly improved. In the case of using a public node, you can successfully buy in the next block of the pool (for example, 1731551 to add the pool, you can buy in 1731552). If you use a private high-speed node, you can add the pool In the same block, but it is easy to be killed.
The whole process test video is as follows:
The smart contract version snaps up the robot, supports uniswap/pancake, etc.
Digression: I watched a lot of other robot videos on station B, and none of them dared to release the running process and transaction tx_hash, so I won’t say whether they are scammers or not.
next step of the work plan
After research, I plan to switch to a third-party monitoring pending transaction service
Add the ability to detect Pixiu for robots
Contact information
vx satoshi_light
tg @zhongbendeng