Giter Club home page Giter Club logo

pancake-bakery-arbitrage's Introduction

Pancake & BakerySwap arbitrage

A sample application invokes a flashloan with Flash Swaps and a monitoring tool in Node.js. To know details about Flash Swaps: visit https://uniswap.org/docs/v2/core-concepts/flash-swaps/

Article: visit https://yuyasugano.medium.com/arbitrage-party-between-pancakeswap-and-bakeryswap-apeswap-b055af13e4fc

Disclaimer

This repo is not either an investment advice or a recommendation or solicitation to buy or sell any investment and should not be used in the evaluation of the merits of making any investment decision. It should not be relied upon for accounting, legal or tax advice or investment recommendations. The contents reflected herein are subject to change without being updated.

The codes are written for informational and educational purpose only, https and websocket endpoints might not work well if those endpoint have been depreciated. Please find other available endpoints in that case. Thanks for your understanding.

Links

Infrastructure

Basically arbitrage opportunity dont last long, your transaction must make it into the next block. So you have <3 seconds watching for opportunities, decide and execute transaction. Sometimes there are also a chance to 2-3 have block, see example below. BLOCKNUMBER in the environmental variables can be configured within how many blocks a transaction should be processed.

[7920960] [6/1/2021, 5:50:37 PM]: alive (bsc-ws-node.nariox.org) - took 308.42 ms
[7920991] [6/1/2021, 5:52:09 PM]: [bsc-ws-node.nariox.org] [BAKE/BNB ape>bakery] Arbitrage opportunity found! Expected profit: 0.007 $2.43 - 0.10%
[7920991] [6/1/2021, 5:52:09 PM] [bsc-ws-node.nariox.org]: [BAKE/BNB ape>bakery] and go:  {"profit":"$1.79","profitWithoutGasCost":"$2.43","gasCost":"$0.64","duration":"539.35 ms","provider":"bsc-ws-node.nariox.org"}
[7920992] [6/1/2021, 5:52:13 PM]: [bsc-ws-node.nariox.org] [BAKE/BNB ape>bakery] Arbitrage opportunity found! Expected profit: 0.007 $2.43 - 0.10%
[7920992] [6/1/2021, 5:52:13 PM] [bsc-ws-node.nariox.org]: [BAKE/BNB ape>bakery] and go:  {"profit":"$1.76","profitWithoutGasCost":"$2.43","gasCost":"$0.67","duration":"556.28 ms","provider":"bsc-ws-node.nariox.org"}
[7921000] [6/1/2021, 5:52:37 PM]: alive (bsc-ws-node.nariox.org) - took 280.54 ms

software version

Ensure your node and truffle version is higher than these:

$ node -v
v14.17.6
$ truffle version
Truffle v5.3.7 (core: 5.3.7)
Solidity - >=0.6.6 <0.8.0 (solc-js)
Node v14.17.6
Web3.js v1.3.6

environment variables

TEST_AMOUNT=0.005
BNB_AMOUNT=1000
WALLET_ADDRESS=<your wallet address>
PRIVATE_KEY=<your private key>
PRIVATE_TEST_KEY=<your test private key>
NETWORKID=56
BLOCKNUMBER=3
BSC_WSS=wss://bsc-ws-node.nariox.org:443
BSC_HTTPS=https://bsc-dataseed.binance.org/
BSC_TEST_HTTPS=https://data-seed-prebsc-1-s1.binance.org:8545/
MORALIS_BSC=https://speedy-nodes-nyc.moralis.io/<your account>/bsc/mainnet
WSS_BLOCKS=wss://bsc-ws-node.nariox.org:443

setup steps

  1. Rename .env.template to .env and fill out required information
  2. Configure truffle-config.js with appropriate parameters (if you deploy a contract)
  3. Install node.js packages and compile a smart contract code
npm install
truffle compile
  1. Migrate the contract to the network (confirm if you do this in BSC mainnet)
truffle migrate --network mainnet

License

This library is licensed under the MIT License.

pancake-bakery-arbitrage's People

Contributors

warmachineai avatar yuyasugano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pancake-bakery-arbitrage's Issues

Load all available coins rather than hard coded ones

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.

Flashswap

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 {}    

}

doesn't work with coins other than popular ones

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)

Import error when trying to execute truffle compile

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)

"Migrations" -- invalid sender.

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

Cannot establish websocket connection with web3

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) => {"

error when running indes.js

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**

Unnecessary 0 condition [flashswap.sol]

    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]

somebody can help?

HI. I need to know how to setup this tools.
yuyasugano, can you help?

Deployment Failed :invalid sender.

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

Websocket issue

image

Hi thanks for the repo! When trying it out, the websocket does not seem to connect. Got an idea on how to resolve this issue?
Kr

"Gas Estimation Failed" - Remix

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?

image

image

Full setup

Hello Mr.
How to all this? How to setup.
example here: truffle-config.js
We need deploit contract via remix?

About the bot

Hello sir,

This flashswap bot is working at the moment?? Are you running it?

BOT only checks one way arbitrage

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

What is the newBlockHeaders subscription for?

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?

Getting 'header not found' Error on truffle migrate --network mainnet

Compiling your contracts...

√ 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:

  • solc: 0.7.6+commit.7338295f.Emscripten.clang

Starting migrations...

Network name: 'mainnet'
Network id: 56
Block gas limit: 80312499 (0x4c978b3)

1_initial_migration.js

Deploying 'Migrations'

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)

Cannot read property address of undefined

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.

Multiple Pairs for Arbitrage

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

Finding Arbitrage

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:

  1. Sell BNB on pancakeswap for BUSD and then sell all the busd for BNB on apeswap
  2. Sell BNB on apeswap for BUSD and then sell all the busd for BNB on pancakeswap
    The loss is 1 BNB for both ways.
    As I can see in the code, there aren't any gas costs included, so the net loss would be even more in reality. Can someone explain me, why there is al loss of 1 BNB every time? Maybe a reaseon can be, that the Spreads are very high.

Thank you!

Best regards,
Daniel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.