Skip to content

Commit

Permalink
Merge pull request #31 from rainprotocol/2023-10-26-flashbot-rpc
Browse files Browse the repository at this point in the history
Added FlashBot RPC option
  • Loading branch information
Siddharth2207 authored Oct 26, 2023
2 parents a69d58a + 92cb11d commit 96876a2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions arb-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const DEFAULT_OPTIONS = {
rpc : process?.env?.RPC_URL
? Array.from(process?.env?.RPC_URL.matchAll(/[^,\s]+/g)).map(v => v[0])
: undefined,
flashBotRpc : process?.env?.FLASHBOT_RPC,
subgraph : process?.env?.SUBGRAPH
? Array.from(process?.env?.SUBGRAPH.matchAll(/[^,\s]+/g)).map(v => v[0])
: undefined
Expand All @@ -58,6 +59,7 @@ const getOptions = async argv => {
.option("--sleep <integer>", "Seconds to wait between each arb round, default is 10, Will override the 'SLEPP' in env variables")
.option("--max-profit", "Option to maximize profit for 'srouter' mode, comes at the cost of more RPC calls, Will override the 'MAX_PROFIT' in env variables")
.option("--max-ratio", "Option to maximize maxIORatio for 'srouter' mode, Will override the 'MAX_RATIO' in env variables")
.option("--flash-bot-rpc <flashbot url>", "Optional flashbot url to submit transaction to.")
.option("--use-public-rpcs", "Option to use public rpcs as fallback option for 'srouter' and 'router' mode, Will override the 'USE_PUBLIC_RPCS' in env variables")
.description([
"A NodeJS app to find and take arbitrage trades for Rain Orderbook orders against some DeFi liquidity providers, requires NodeJS v18 or higher.",
Expand Down Expand Up @@ -89,6 +91,7 @@ const getOptions = async argv => {
cmdOptions.maxProfit = cmdOptions.maxProfit || DEFAULT_OPTIONS.maxProfit;
cmdOptions.maxRatio = cmdOptions.maxRatio || DEFAULT_OPTIONS.maxRatio;
cmdOptions.usePublicRpcs = cmdOptions.usePublicRpcs || DEFAULT_OPTIONS.usePublicRpcs;
cmdOptions.flashBotRpc = cmdOptions.flashBotRpc || DEFAULT_OPTIONS.flashBotRpc;

return cmdOptions;
};
Expand All @@ -113,6 +116,7 @@ const arbRound = async options => {
maxProfit : options.maxProfit,
maxRatio : options.maxRatio,
usePublicRpcs : options.usePublicRpcs,
flashBotRpc : options.flashBotRpc,
hideSensitiveData : false,
shortenLargeLogs : false,
liquidityProviders : options.lps
Expand Down
5 changes: 4 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ BOT_WALLET_PRIVATEKEY="123..."

# RPC URL(s) that will be provider for interacting with evm, use different providers if more than 1 is specified to prevent banning.
# for specifying more than 1 RPC in the env, separate them by a comma and a space
RPC_URL="https://polygon-mainnet.g.alchemy.com/v2/{API_KEY}, https://rpc.ankr.com/polygon/{API_KEY}"
RPC_URL="https://polygon-mainnet.g.alchemy.com/v2/{API_KEY}, https://rpc.ankr.com/polygon/{API_KEY}"

# Option to submit transactions to the flashbot RPC.
FLASHBOT_RPC=""

# bot running mode, one of "router", "0x", "curve", "crouter", "srouter"
MODE="router"
Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const configOptions = {
* List of liquidity providers for router contract tomoperate on
*/
liquidityProviders: undefined,
/**
* Flashbot rpc url
*/
flashBotRpc: undefined,
/**
* 0x monthly rate limit number, if not specified will not respect 0x monthly rate limit
*/
Expand Down Expand Up @@ -167,7 +171,9 @@ const getConfig = async(
const AddressPattern = /^0x[a-fA-F0-9]{40}$/;
if (!/^(0x)?[a-fA-F0-9]{64}$/.test(walletPrivateKey)) throw "invalid wallet private key";

const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const provider = options.flashBotRpc ?
new ethers.providers.JsonRpcProvider(options.flashBotRpc) :
new ethers.providers.JsonRpcProvider(rpcUrl);
const signer = new ethers.Wallet(walletPrivateKey, provider);
const chainId = await signer.getChainId();
const config = CONFIG.find(v => v.chainId === chainId);
Expand Down

0 comments on commit 96876a2

Please sign in to comment.