GithubHelp home page GithubHelp logo

simple-arbitrage's Introduction

simple-arbitrage

This repository contains a simple, mechanical system for discovering, evaluating, rating, and submitting arbitrage opportunities to the Flashbots bundle endpoint. This script is very unlikely to be profitable, as many users have access to it, and it is targeting well-known Ethereum opportunities.

We hope you will use this repository as an example of how to integrate Flashbots into your own Flashbot searcher (bot). For more information, see the Flashbots Searcher FAQ

Environment Variables

  • ETHEREUM_RPC_URL - Ethereum RPC endpoint. Can not be the same as FLASHBOTS_RPC_URL
  • PRIVATE_KEY - Private key for the Ethereum EOA that will be submitting Flashbots Ethereum transactions
  • FLASHBOTS_RELAY_SIGNING_KEY [Optional, default: random] - Flashbots submissions require an Ethereum private key to sign transaction payloads. This newly-created account does not need to hold any funds or correlate to any on-chain activity, it just needs to be used across multiple Flashbots RPC requests to identify requests related to same searcher. Please see https://docs.flashbots.net/flashbots-auction/searchers/faq#do-i-need-authentication-to-access-the-flashbots-relay
  • HEALTHCHECK_URL [Optional] - Health check URL, hit only after successfully submitting a bundle.
  • MINER_REWARD_PERCENTAGE [Optional, default 80] - 0 -> 100, what percentage of overall profitability to send to miner.

Usage

  1. Generate a new bot wallet address and extract the private key into a raw 32-byte format.
  2. Deploy the included BundleExecutor.sol to Ethereum, from a secured account, with the address of the newly created wallet as the constructor argument
  3. Transfer WETH to the newly deployed BundleExecutor

It is important to keep both the bot wallet private key and bundleExecutor owner private key secure. The bot wallet attempts to not lose WETH inside an arbitrage, but a malicious user would be able to drain the contract.

$ npm install
$ PRIVATE_KEY=__PRIVATE_KEY_FROM_ABOVE__ \
    BUNDLE_EXECUTOR_ADDRESS=__DEPLOYED_ADDRESS_FROM_ABOVE__ \
    FLASHBOTS_RELAY_SIGNING_KEY=__RANDOM_ETHEREUM_PRIVATE_KEY__ \
      npm run start

simple-arbitrage's People

Contributors

epheph avatar obadiaa 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  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

simple-arbitrage's Issues

what should be improved?

I understand that this is simple example code and probably not making any profit, my question is what should be improved to make little profit at least with this bot? i am a dev but im not good at blockchain technology, but i can do my research and make improvements just need suggestions. thanks.

Uniswap query lookup

When the code reaches getPairsByIndexRange, I am getting the following error:
Error: Transaction reverted: function call to a non-contract account

I tried copying the same UniswapQuery code from Etherscan and pasting into my VSCode and running it as a separate contract and test with Hardhat but still getting the same error. But when I enter the 3 parameters in the Read Contract section on Etherscan I successfully get all the pairs.

Does this code from the repo only work on Mainnet or Mainnet-fork? Or should it still work on localhost (for example npx hardhat node)?

With the environment variable what does the Readme note below mean:
ETHEREUM_RPC_URL - Ethereum RPC endpoint. Can not be the same as FLASHBOTS_RPC_URL

I am using localhost:8545 as the ETHEREUM_RPC_URL (through npx hardhat node). But what is FLASHBOTS_RPC_URL? There is no such environment variable inside the code.

Submitting bundle, but no transactions are ever started.

First off, thanks for open-sourcing this. Thought I give it a try and created the contracts. However, no transactions are ever started by the contract.

I see this log, which looks like it is submitted via the relay.

Submitting bundle, profit sent to miner: 0.0003, effective gas price: 2.1664 GWEI

I have these environment variables set.

FLASHBOTS_RELAY_SIGNING_KEY=0x....
PRIVATE_KEY=0x.....
BUNDLE_EXECUTOR_ADDRESS=0xfC54bf73483d28619E43479551140939380B0e1b
ETHEREUM_RPC_URL=https://mainnet.infura.io/v3/mykey
MINER_REWARD_PERCENTAGE=20

I just found the discord, but there's a lot going on there. Figure I'd start here. Any direction or guidance is appreciated! 🙏

About "npm run start"

Hello

How should I run the part below?

For example, should I type the Private Key on the command line? Or should I write it in Index.js?

$ PRIVATE_KEY=PRIVATE_KEY_FROM_ABOVE
BUNDLE_EXECUTOR_ADDRESS=DEPLOYED_ADDRESS_FROM_ABOVE
FLASHBOTS_RELAY_SIGNING_KEY=RANDOM_ETHEREUM_PRIVATE_KEY
npm run start


New to Eth - Should be a quick fix: error: could not detect network

I'm using this code as a learning module; however, I receive the following error when running the code.

Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.6.8)

I believe it comes from the following line 10 index.ts

const ETHEREUM_RPC_URL = process.env.ETHEREUM_RPC_URL || "http://127.0.0.1:8545"

Looking around online, I think it could be two things. (1) This is a local host (Like ganache or something), so I wont be able to run this code. Or (2) I am missing a dependency.

ANY help would be great, I have already learned a lot!!!

Kindest,

Carl M.

Use of Smart Contracts

Hey there,
might be a dump question. But can anybody explain why we need to use our own deployed Smart Contracts and don't just connect a wallet with Web3.js or Ethers and call Uniswap etc directly?
Cheers

Only compiling reference contracts to build ?

A Brownie problem potentially.

Mac OS X Big Sur v11.5.1
Node v16.4.2
Python v3.8
Sol v0.8.6
Brownie v1.15.2

I am compiling using Brownie. However the only files that end up 'compiled' and in /build/contracts are:

Compiling contracts...
  Solc version: 0.6.12
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
Generating build data...
 **- FlashBotsMultiCall
 - IERC20
 - IWETH
 - FlashBotsUniswapQuery
 - IUniswapV2Pair
 - UniswapV2Factory**

Thereafter, when I try to deploy from Brownie, BundleExecutor.sol isn't found. This could be PATH related. However, why is Brownie compiling the reference contracts from inside BundleExecutor.sol ?

serverError: Error: connect ETIMEDOUT 172.67.71.234:443

Below is the error information:

  requestMethod: 'POST',
  serverError: Error: connect ETIMEDOUT 172.67.71.234:443
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)
      at TCPConnectWrap.callbackTrampoline (internal/async_hooks.js:126:14) {
    errno: 'ETIMEDOUT',
    code: 'ETIMEDOUT',
    syscall: 'connect',
    address: '172.67.71.234',
    port: 443
  },
  url: 'https://relay.flashbots.net'
}

I pinged "172.67.71.234" and it is unreachable. I do a search: https://check-host.net/check-ping?host=relay.flashbots.net. I found that there are two IPs bond with 'https://relay.flashbots.net'. One is "172.67.71.234" which is unreachable for me and another is "104.26.11.65". Is there a way to set "104.26.11.65" as the entry for 'https://relay.flashbots.net'? Or is there anything wrong with my code?
Many thanks!

>>>>>>>>>>>>>>>>>$ ping 104.26.10.65
PING 104.26.10.65 (104.26.10.65): 56 data bytes
64 bytes from 104.26.10.65: icmp_seq=0 ttl=51 time=382.503 ms
64 bytes from 104.26.10.65: icmp_seq=1 ttl=51 time=238.248 ms
64 bytes from 104.26.10.65: icmp_seq=2 ttl=51 time=425.513 ms
64 bytes from 104.26.10.65: icmp_seq=3 ttl=51 time=258.062 ms
64 bytes from 104.26.10.65: icmp_seq=4 ttl=51 time=264.377 ms
64 bytes from 104.26.10.65: icmp_seq=5 ttl=51 time=278.940 ms
>>>>>>>>>>>>>>>>>$ ping 172.67.71.234
PING 172.67.71.234 (172.67.71.234): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4
Request timeout for icmp_seq 5
Request timeout for icmp_seq 6
Request timeout for icmp_seq 7

.

No longer a problem

Error: call revert exception

I'm getting the following error when I'm running npm run start

/Users/glaksmono/Documents/simple-arbitrage/node_modules/@ethersproject/logger/src.ts/index.ts:205
        const error: any = new Error(message);
                           ^
Error: call revert exception (method="getPairsByIndexRange(address,uint256,uint256)", errorSignature=null, errorArgs=[null], reason=null, code=CALL_EXCEPTION, version=abi/5.0.9)
    at Logger.makeError (/Users/glaksmono/Documents/simple-arbitrage/node_modules/@ethersproject/logger/src.ts/index.ts:205:28)
    at Logger.throwError (/Users/glaksmono/Documents/simple-arbitrage/node_modules/@ethersproject/logger/src.ts/index.ts:217:20)
    at Interface.decodeFunctionResult (/Users/glaksmono/Documents/simple-arbitrage/node_modules/@ethersproject/abi/src.ts/interface.ts:326:23)
    at Object.<anonymous> (/Users/glaksmono/Documents/simple-arbitrage/node_modules/@ethersproject/contracts/src.ts/index.ts:309:44)
    at step (/Users/glaksmono/Documents/simple-arbitrage/node_modules/@ethersproject/contracts/lib/index.js:46:23)
    at Object.next (/Users/glaksmono/Documents/simple-arbitrage/node_modules/@ethersproject/contracts/lib/index.js:27:53)
    at fulfilled (/Users/glaksmono/Documents/simple-arbitrage/node_modules/@ethersproject/contracts/lib/index.js:18:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Any ideas what do I need to do?

It would also be great if someone can improve the README so that there's step by step instructions on what to do to get this code up and running

Unable to compile Typescript when npm run start

I embedded environmental variables in .env and ran npm run start. Here's the error I encountered "Unable to compile TypeScript". Is there any defects in the current code?? Thanks.

$ npm run start
> @flashbots/[email protected] start /home/ether/work/javascript/simple-arbitrage
> npx ts-node --project tsconfig.json src/index.ts

? Unable to compile TypeScript:
src/index.ts:56:49 - error TS2339: Property 'getUniswapMarketsByToken' does not exist on type 'typeof UniswappyV2EthPair'.

56   const markets: any = await UniswappyV2EthPair.getUniswapMarketsByToken(provider, FACTORY_ADDRESSES);
                                                   ~~~~~~~~~~~~~~~~~~~~~~~~
src/index.ts:58:30 - error TS2339: Property 'updateReserves' does not exist on type 'typeof UniswappyV2EthPair'.

58     await UniswappyV2EthPair.updateReserves(provider, markets.allMarketPairs);
                                ~~~~~~~~~~~~~~

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @flashbots/[email protected] start: `npx ts-node --project tsconfig.json src/index.ts`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @flashbots/[email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/.npm/_logs/2021-08-09T05_29_01_383Z-debug.log

Length of targets and payloads is not equal

Hi Everyone, thanks for sparing your precious time to help me.
Actually the length of my targets and payloads is not matching. I tried since more than a week but could’nt solve it. Can someone please help me come out of this issue. I would be very very happy if someone help me please. Thanking you


async takeCrossedMarkets(
bestCrossedMarkets: CrossedMarketDetails,
blockNumber: number,
minerRewardPercentage: number
): Promise {
for (const bestCrossedMarket of bestCrossedMarkets) {
const buyCalls =
await bestCrossedMarket.buyFromMarket.sellTokensToNextMarket(
WETH_ADDRESS,
bestCrossedMarket.volume,
bestCrossedMarket.sellToMarket
);
const inter = bestCrossedMarket.buyFromMarket.getTokensOut(
WETH_ADDRESS,
bestCrossedMarket.tokenAddress,
bestCrossedMarket.volume
);
const sellCallData = await bestCrossedMarket.sellToMarket.sellTokens(
bestCrossedMarket.tokenAddress,
inter,
this.bundleExecutorContract.address
);

const targets: Array = [
...buyCalls.targets,
bestCrossedMarket.sellToMarket.marketAddress,
];
const payloads: Array = [...buyCalls.data, sellCallData];

I don’t know whether the problem is in this part of code or somewhere else. I’ve also deployed a contract on the Ethereum Mainnet.
Please someone guide me please.

Clarifications

Hi can someone please clarify how funds can be or are withdrawn from BundleExecutor.Sol ?

do the profits of the trade stay within the contract and can they be withdrawn?

ethers provider

i'm trying a local light client.

(node:2216808) UnhandledPromiseRejectionWarning: Error: missing provider (operation="estimateGas", code=UNSUPPORTED_OPERATION, version=abstract-signer/5.3.0)

should i be using infura for ETHEREUM_RPC_URL?

PRIVATE_KEY definition

Hi !

What do you mean by 'raw 32-byte format' ?
The private key from metamask has a length of 64 char, how can i convert it to 32bytes ?

I'm missing something here

Thanks a lot !

Example of successful execution

Could somebody please point to any successful execution of this simple-arbitrage project against Ethereum Mainnet?

As I test, I would like to fork Mainnet at that block and try this project locally.

test on remix

Hi,

Is it possible to test smart contract on remix?

function getPairsByIndexRange
is not working when i take a test using Ropsten Test network.

image

Any guide appreciatively, thanks

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.