yuyasugano / pancake-bakery-arbitrage Goto Github PK
View Code? Open in Web Editor NEWA sample application invokes a flashswap in PancakeSwap and a monitoring tool in Node.js.
A sample application invokes a flashswap in PancakeSwap and a monitoring tool in Node.js.
Hello sir,
This flashswap bot is working at the moment?? Are you running it?
function execute(
address _sender,
uint _amount0,
uint _amount1,
bytes calldata _data
) internal {
// obtain an amount of token that you exchanged, for example BUSD
uint amountToken = **_amount0 == 0 ?** _amount1 : _amount0;
Why the hell would it ever be 0? It's user input... the user has no intention to pass 0 to it ever. Why would the user execute a flash arb passing the amounts of the very first token as 0, or the consequent ones? This makes no sense.
This logic can have place in helper functions, like , check() in flashswap contract quoted above, or in the bot's checker functions naturally, because it's looking for opportunities... calculating, experimenting, simulating. What's the point of having it in the final function of the arb?
It's like saying, oh if my bot comes to the bank to exchange 0 dollars, then tell him X.
My bot won't come to the bank with 0 dollars, because the whole point of the bot is to come only after he has a set amount of flashed funds/amounts pre-calculated from check(). [if check returns 0 js script should handle that]
I get errors at the swap.js(test swap from wbnb to usdc). I have approved WBNB and USDT but still the same error
Can not go further
Halo i got error when oportunity found
https://bscscan.com/tx/0x701296e0790a74125287420f33db8d2bd331ab73afa60031acf52766d084c637
HI. I need to know how to setup this tools.
yuyasugano, can you help?
When i try to execute truffle compile I get the following error:
ImportError: cannot import name 'get_directory_tree' from 'filetools' (c:\users\nejcn\appdata\local\programs\python\python39\lib\site-packages\filetools_init_.py)
Hi firstly great little project.
I am looking at this and getting a feel of how it hangs together and I though it would be great to auto load all available chains, this could be done via scraping the contract addresses from coin market cap.
I have put the contract on the bsc mainnet,but when I run the swap.js, it meet this error Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'address')
When I try to start index.js error I get this error:
C:\Users\elias\Downloads\Kobflish-FlashloanArbitrage\pancake-bakery-arbitrage-main\index.js:38
Flashswap.networks[process.env.NETWORKID].address
^
TypeError: Cannot read property 'address' of undefined
at Object. (C:\Users\elias\Downloads\Kobflish-FlashloanArbitrage\pancake-bakery-arbitrage-main\index.js:38:47)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
I already migrated the contract but it still dosen't work.
Thanks for sharing this repo, it's interesting stuff.
I have deployed the contract via Remix to the BSC main net, but I receive a "Gas Estimation Failed" error when attempting to call startArbitrage as per the below images.
Have you tested this contract and has it worked before? Does the contract itself require a balance of BNB to pay fees for interacting with the PCS and BS contracts?
I have an error when running index.js
**C:\Users\Administrator\pancake-bakery-arbitrage>node index.js
C:\Users\Administrator\pancake-bakery-arbitrage\index.js:38
Flashswap.networks[process.env.NETWORKID].address
^
TypeError: Cannot read property 'address' of undefined
at Object. (C:\Users\Administrator\pancake-bakery-arbitrage\index.js:38:47)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47**
Hello Mr.
How to all this? How to setup.
example here: truffle-config.js
We need deploit contract via remix?
Hey, great work and an awesome post you wrote about this topic. Thanks a lot, appreciate it.
While looking through your code I saw the subscription on newBlockHeaders
event. What is this subscription actually for? Is it just used as a trigger for price monitoring? As far as I can see I could also be replaced by a simple while(true){} loop that sleeps for a couple of seconds every loop, correct? Or do I miss something here?
Hi Yuya, I am trying to run test.js as is from the box, however i encountered the following error "UnhandledPromiseRejectionWarning: Error: Returned error: execution reverted: PancakeLibrary: INSUFFICIENT_LIQUIDITY" what could this error be caused by? Appreciate your time for this. Many thanks.
Deployed Contract on REMIX and getting this error :
Transaction decoding is not available for chainId 56
Hi there,
I was able to setup the smart contracts as well as run the index.js
script.
Most of the times the script returns Arbitrage opportunity not found!
.
I would like to get some insights on which type of tokens (small cap, mid cap, large cap) are best for this type of arbitrage?
Also how do we add checking of multiple pairs ? I have changed the following in index.js
but getting an error
const toTokens = ['SXP', 'BUSD'];
const toToken = [
'0x47BEAd2563dCBf3bF2c9407fEa4dC236fAbA485A', //SXP
'0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56' // BUSD
];
the error I get is
-------------------------------------------------------------
New block received. Block # 12584607
GasLimit: 85269722 and Timestamp: 1636716019
Trading SXP/WBNB ...
pairAddress SXP/WBNB is 0xD8E2F8b6Db204c405543953Ef6359912FE3A88d6
Input amount of WBNB: 10
Buying token at PancakeSwap DEX
=================
tokenIn: 10 WBNB
tokenOut: 2579.732315199861167345 SXP
Buying back token at ApeSwap DEX
=================
tokenOut: 2579.732315199861167345 SXP
tokenIn: 9.820575459476819607 WBNB
Block # 12584607: Arbitrage opportunity not found! Expected profit: -179424540523180393
Trading BUSD/WBNB ...
pairAddress BUSD/WBNB is 0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16
Input amount of WBNB: 10
/Users/user/Desktop/pancake-bakery-arbitrage/node_modules/bignumber.js/bignumber.js:2832
throw Error
^
Error: [BigNumber Error] Argument not an integer: NaN
when iam trying to deploy below error came pls help me
"Migrations" -- invalid sender.
at C:\Users\vkart\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\deployer\src\deployment.js:365:1
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at Migration._deploy (C:\Users\vkart\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:74:1)
at Migration._load (C:\Users\vkart\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:61:1)
at Migration.run (C:\Users\vkart\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:212:1)
at Object.runMigrations (C:\Users\vkart\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
at Object.runFrom (C:\Users\vkart\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
at Object.run (C:\Users\vkart\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:87:1)
at runMigrations (C:\Users\vkart\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:258:1)
at Object.run (C:\Users\vkart\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:223:1)
at Command.run (C:\Users\vkart\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:147:1)
Truffle v5.3.7 (core: 5.3.7)
Node v14.17.6
EDITED
Fixed
√ Fetching solc version list from solc-bin. Attempt #1
√ Fetching solc version list from solc-bin. Attempt #1
Compiling .\contracts\Flashswap.sol
Compiling .\contracts\Migrations.sol
Compiling .\contracts\Swapcontract.sol
Compiling .\contracts\UniswapV2Library.sol
Compiling .\contracts\interfaces\IERC20.sol
Compiling .\contracts\interfaces\IUniswapV2Callee.sol
Compiling .\contracts\interfaces\IUniswapV2Factory.sol
Compiling .\contracts\interfaces\IUniswapV2Pair.sol
Compiling .\contracts\interfaces\IUniswapV2Router01.sol
Compiling .\contracts\interfaces\IUniswapV2Router02.sol
Compiling .\contracts\utils\Context.sol
Compiling .\contracts\utils\Ownable.sol
Compiling .\contracts\utils\SafeMath.sol
Compilation warnings encountered:
project:/contracts/Flashswap.sol:44:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
address _sender,
^-------------^
,project:/contracts/Flashswap.sol:47:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
bytes calldata _data
^------------------^
Artifacts written to D:\github\pancake-bakery-arbitrage\build\contracts
Compiled successfully using:
Network name: 'mainnet'
Network id: 56
Block gas limit: 80312499 (0x4c978b3)
Error: Unhandled error. ({ code: -32000, message: 'header not found' })
at new NodeError (node:internal/errors:371:5)
at Web3ProviderEngine.emit (node:events:379:17)
at D:\github\pancake-bakery-arbitrage\node_modules@trufflesuite\web3-provider-engine\index.js:57:14
at afterRequest (D:\github\pancake-bakery-arbitrage\node_modules@trufflesuite\web3-provider-engine\index.js:151:21)
at D:\github\pancake-bakery-arbitrage\node_modules@trufflesuite\web3-provider-engine\index.js:176:21
at D:\github\pancake-bakery-arbitrage\node_modules@trufflesuite\web3-provider-engine\index.js:238:9
at D:\github\pancake-bakery-arbitrage\node_modules\async\internal\once.js:12:16
at replenish (D:\github\pancake-bakery-arbitrage\node_modules\async\internal\eachOfLimit.js:61:25)
at D:\github\pancake-bakery-arbitrage\node_modules\async\internal\eachOfLimit.js:71:9
at eachLimit (D:\github\pancake-bakery-arbitrage\node_modules\async\eachLimit.js:43:36)
at D:\github\pancake-bakery-arbitrage\node_modules\async\internal\doLimit.js:9:16
at end (D:\github\pancake-bakery-arbitrage\node_modules@trufflesuite\web3-provider-engine\index.js:217:5)
at Request._callback (D:\github\pancake-bakery-arbitrage\node_modules@trufflesuite\web3-provider-engine\subproviders\rpc.js:70:28)
at Request.self.callback (D:\github\pancake-bakery-arbitrage\node_modules\request\request.js:185:22)
at Request.emit (node:events:390:28)
at Request. (D:\github\pancake-bakery-arbitrage\node_modules\request\request.js:1154:10)
at Request.emit (node:events:390:28)
at IncomingMessage. (D:\github\pancake-bakery-arbitrage\node_modules\request\request.js:1076:12)
at Object.onceWrapper (node:events:509:28)
at IncomingMessage.emit (node:events:402:35)
at endReadableNT (node:internal/streams/readable:1343:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Hi,
I think this is not the issue with the code but I'm struggling to get it up and running due to following error and maybe you can help me solve the problem I'm facing.
Error: connection not open on send() at Object.ConnectionError (/pancake-ape-bakery/node_modules/web3-core-helpers/lib/errors.js:66:23) at Object.ConnectionNotOpenError (/pancake-ape-bakery/node_modules/web3-core-helpers/lib/errors.js:49:21) at /pancake-ape-bakery/node_modules/web3-providers-ws/lib/index.js:155:37 at Map.forEach (<anonymous>) at WebsocketProvider._onClose (/pancake-ape-bakery/node_modules/web3-providers-ws/lib/index.js:154:27) at W3CWebSocket._dispatchEvent [as dispatchEvent] (/pancake-ape-bakery/node_modules/yaeti/lib/EventTarget.js:115:12) at W3CWebSocket.onConnectFailed (/pancake-ape-bakery/node_modules/websocket/lib/W3CWebSocket.js:219:14) at WebSocketClient.<anonymous> (/pancake-ape-bakery/node_modules/websocket/lib/W3CWebSocket.js:59:25) at WebSocketClient.emit (events.js:375:28) at WebSocketClient.failHandshake (/pancake-ape-bakery/node_modules/websocket/lib/WebSocketClient.js:339:10) at ClientRequest.<anonymous> (/pancake-ape-bakery/node_modules/websocket/lib/WebSocketClient.js:278:18) at ClientRequest.emit (events.js:375:28) at HTTPParser.parserOnIncomingClient (_http_client.js:647:27) at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17) at Socket.socketOnData (_http_client.js:515:22) at Socket.emit (events.js:375:28) { code: 1006, reason: 'connection failed' }
I went twice over steps for installing but same issue websocket connection fail here
"let subscription = web3.eth.subscribe('newBlockHeaders', (error, result) => {"
i understand how to start ??
BOT only checks one way arbitrage. Like it checks if we buy from pancakeswap and sell on apeswap then what will be profit. But it does not check what will be profit if we buy from apeswap and sell on pancakeswap. Can you please add it? Thanks
Hello Sir. My startarbitrage transaction is failing on testnet.
Arbitrage opportunity is present but transaction is not completing.
https://testnet.bscscan.com/tx/0xa57ebcaaadeeb7b0b862bdeebf887850f5e8d46a3a4a0e3bb90d811dcee622d9
This issue is already raised by someone else but their provided solution is not correct.
I have a question, if i use the code 'as is' it does not work, i always get 'Fail' but don't know if it's a failure in the contract or not, so i tried to add en event, but that's also not shown. Did your code work on mainnet like that, don't you have to sign the transaction or something. Do i have to hex the data first? I am getting desprerate, i've tried so many things...
this is the code, i do a reversal from apefactory to pancakerouter, and added 1 required to see if i see the message and added in the last try this emit event :
I already found out that it is in the pancakeCall function : i found that the error is showed here :
require(msg.sender == UniswapV2Library.pairFor(fromApeFactory, token0, token1), 'message fail 1');
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.6 <0.8.0;
import './utils/SafeMath.sol';
import './UniswapV2Library.sol';
import './interfaces/IERC20.sol';
import './interfaces/IUniswapV2Pair.sol';
import './interfaces/IUniswapV2Factory.sol';
import './interfaces/IUniswapV2Router02.sol';
import './interfaces/IPancakeCallee.sol';
import './interfaces/IApeCallee.sol';
contract EventExample {
using SafeMath for uint;
event DataStored(string val);
uint256 val;
address private owner;
address private constant fromApeFactory = 0x0841BD0B734E4F5853f0dD8d7Ea041c241fb0Da6;
address private constant pancake_router_address = 0x10ED43C718714eb63d5aA57B78B54704E256024E;
IUniswapV2Router02 toPancakeRouter = IUniswapV2Router02(pancake_router_address);
constructor() {
owner = msg.sender;
}
function startArbitrage(
address token0,
address token1,
uint amount0,
uint amount1
) external{
emit DataStored('start');
address pairAddress = IUniswapV2Factory(fromApeFactory).getPair(token0, token1);
require(pairAddress != address(0), 'This pool does not exist');
emit DataStored('step 1');
IUniswapV2Pair(pairAddress).swap(
amount0,
amount1,
address(this),
bytes('not empty')
);
}
function pancakeCall(
address _sender,
uint _amount0,
uint _amount1,
bytes calldata _data
) external override {
address[] memory path = new address[](2);
// obtain an amout of token that you exchanged
uint amountToken = _amount0 == 0 ? _amount1 : _amount0;
address token0 = IUniswapV2Pair(msg.sender).token0();
address token1 = IUniswapV2Pair(msg.sender).token1();
require(msg.sender == UniswapV2Library.pairFor(fromApeFactory, token0, token1), 'message fail 1');
require(_amount0 == 0 || _amount1 == 0, 'message fail 2');
// if _amount0 is zero sell token1 for token0
// else sell token0 for token1 as a result
path[0] = _amount0 == 0 ? token1 : token0;
path[1] = _amount0 == 0 ? token0 : token1;
require(0 != 0, 'Just before approve');
emit DataStored('step 2');
}
receive() external payable {}
}
even only apeswap.js doesn't work if I replace token address to let's say NEWB Token (0x545f90dc35ca1e6129f1fed354b3e2df12034261)
the error is:
New block received. Block # 11687757 GasLimit: 84859370 and Timestamp: 1633980384 Trading BATRI/WBNB ... pairAddress BATRI/WBNB is 0x6Ef8850a890EC929057CBa3332bF7937eF43ad0C Input amount of WBNB: 10 (node:69820) UnhandledPromiseRejectionWarning: Error: Returned error: execution reverted at Object.ErrorResponse (/home/kali/pancake-bakery-arbitrage/node_modules/web3-core-helpers/lib/errors.js:28:19) at Object.callback (/home/kali/pancake-bakery-arbitrage/node_modules/web3-core-requestmanager/lib/index.js:303:36) at /home/kali/pancake-bakery-arbitrage/node_modules/web3-providers-ws/lib/index.js:114:45 at Array.forEach (<anonymous>) at WebsocketProvider._onMessage (/home/kali/pancake-bakery-arbitrage/node_modules/web3-providers-ws/lib/index.js:102:69) at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/kali/pancake-bakery-arbitrage/node_modules/yaeti/lib/EventTarget.js:115:12) at W3CWebSocket.onMessage (/home/kali/pancake-bakery-arbitrage/node_modules/websocket/lib/W3CWebSocket.js:234:14) at WebSocketConnection.<anonymous> (/home/kali/pancake-bakery-arbitrage/node_modules/websocket/lib/W3CWebSocket.js:205:19) at WebSocketConnection.emit (events.js:314:20) at WebSocketConnection.processFrame (/home/kali/pancake-bakery-arbitrage/node_modules/websocket/lib/WebSocketConnection.js:554:26) at /home/kali/pancake-bakery-arbitrage/node_modules/websocket/lib/WebSocketConnection.js:323:40 at processTicksAndRejections (internal/process/task_queues.js:79:11) (node:69820) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 9)
Hello,
I run the apeswap.js file to get in touch with the arbitrage program. I just wanted to get a feeling how often an arbitrage possibility is given.
But with an trading volume of 100 BNB I get a loss of 1 BNB (+/- 10%) every time. I tried the following constellations:
Thank you!
Best regards,
Daniel
Hello, thanks for sharing your tools. I followed your setup steps to configure, but found a deployment error. Can I make any changes to complete the deployment.
Run on MacOS.
# moxiaoxi @ 192 in ~/Desktop/pancake-bakery-arbitrage-main [12:12:52]
$ node -v
v14.17.0
# moxiaoxi @ 192 in ~/Desktop/pancake-bakery-arbitrage-main [12:13:48]
$ truffle version
Truffle v5.3.7 (core: 5.3.7)
Solidity - >=0.6.6 <0.8.0 (solc-js)
Node v14.17.0
Web3.js v1.3.6
$ truffle migrate --network mainnet
Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================
> Network name: 'mainnet'
> Network id: 56
> Block gas limit: 60000000 (0x3938700)
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
Error: *** Deployment Failed ***
"Migrations" -- invalid sender.
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:74:1)
at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:61:1)
at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:212:1)
at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:87:1)
at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:258:1)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:223:1)
at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:147:1)
Truffle v5.3.7 (core: 5.3.7)
Node v14.17.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.