Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Oct 31, 2024
1 parent e17a293 commit dae6ba3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ Other optional arguments are:
- `--sleep`, Seconds to wait between each arb round, default is 10, Will override the 'SLEPP' in env variables
- `--max-ratio`, Option to maximize maxIORatio, Will override the 'MAX_RATIO' in env variables
- `--timeout`, Optional seconds to wait for the transaction to mine before disregarding it, Will override the 'TIMEOUT' in env variables
- `--flashbot-rpc`, Optional flashbot rpc url to submit transaction to, Will override the 'FLASHBOT_RPC' in env variables
- `--write-rpc`, Option to explicitly use these rpc for write transactions, such as flashbots or mev protect rpc to protect against mev attacks, Will override the 'WRITE_RPC' in env variables"
- `--watch-rpc`, RPC URLs to watch for new orders, should support required RPC methods, Will override the 'WATCH_RPC' in env variables"
- `--no-bundle`, Flag for not bundling orders based on pairs and clear each order individually. Will override the 'NO_BUNDLE' in env variables
- `--hops`, Option to specify how many hops the binary search should do, default is 0 if left unspecified, Will override the 'HOPS' in env variables
- `--retries`, Option to specify how many retries should be done for the same order, max value is 3, default is 1 if left unspecified, Will override the 'RETRIES' in env variables
Expand Down Expand Up @@ -159,6 +160,9 @@ RPC_URL="https://polygon-mainnet.g.alchemy.com/v2/{API_KEY}, https://rpc.ankr.co
# Option to explicitly use these rpc for write transactions, such as flashbots or mev protect rpc to protect against mev attacks.
WRITE_RPC=""

# RPC URLs to watch for new orders, should support required RPC methods
WATCH_RPC=""

# arb contract address
ARB_ADDRESS="0x123..."

Expand Down
3 changes: 3 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ RPC_URL="https://polygon-mainnet.g.alchemy.com/v2/{API_KEY}, https://rpc.ankr.co
# Option to explicitly use these rpc for write transactions, such as flashbots or mev protect rpc to protect against mev attacks.
WRITE_RPC=""

# RPC URLs to watch for new orders, should support required RPC methods
WATCH_RPC=""

# arb contract address
ARB_ADDRESS="0x123..."

Expand Down
11 changes: 11 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const ENV_OPTIONS = {
writeRpc: process?.env?.WRITE_RPC
? Array.from(process?.env?.WRITE_RPC.matchAll(/[^,\s]+/g)).map((v) => v[0])
: undefined,
watchRpc: process?.env?.WATCH_RPC
? Array.from(process?.env?.WATCH_RPC.matchAll(/[^,\s]+/g)).map((v) => v[0])
: undefined,
subgraph: process?.env?.SUBGRAPH
? Array.from(process?.env?.SUBGRAPH.matchAll(/[^,\s]+/g)).map((v) => v[0])
: undefined,
Expand Down Expand Up @@ -132,6 +135,10 @@ const getOptions = async (argv: any, version?: string) => {
"--write-rpc <url...>",
"Option to explicitly use these rpc for write transactions, such as flashbots or mev protect rpc to protect against mev attacks, Will override the 'WRITE_RPC' in env variables",
)
.option(
"--watch-rpc <url...>",
"RPC URLs to watch for new orders, should support required RPC methods, Will override the 'WATCH_RPC' in env variables",
)
.option(
"--timeout <integer>",
"Optional seconds to wait for the transaction to mine before disregarding it, Will override the 'TIMEOUT' in env variables",
Expand Down Expand Up @@ -197,6 +204,7 @@ const getOptions = async (argv: any, version?: string) => {
cmdOptions.mnemonic = cmdOptions.mnemonic || getEnv(ENV_OPTIONS.mnemonic);
cmdOptions.rpc = cmdOptions.rpc || getEnv(ENV_OPTIONS.rpc);
cmdOptions.writeRpc = cmdOptions.writeRpc || getEnv(ENV_OPTIONS.writeRpc);
cmdOptions.watchRpc = cmdOptions.watchRpc || getEnv(ENV_OPTIONS.watchRpc);
cmdOptions.arbAddress = cmdOptions.arbAddress || getEnv(ENV_OPTIONS.arbAddress);
cmdOptions.genericArbAddress =
cmdOptions.genericArbAddress || getEnv(ENV_OPTIONS.genericArbAddress);
Expand Down Expand Up @@ -355,6 +363,9 @@ export async function startup(argv: any, version?: string, tracer?: Tracer, ctx?
if (!/^(0x)?[a-fA-F0-9]{64}$/.test(options.key)) throw "invalid wallet private key";
}
if (!options.rpc) throw "undefined RPC URL";
if (!options.watchRpc || !Array.isArray(options.watchRpc) || !options.watchRpc.length) {
throw "undefined watch RPC URL";
}
if (options.writeRpc) {
if (
!Array.isArray(options.writeRpc) ||
Expand Down
13 changes: 11 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
publicActions,
PublicClient,
walletActions,
webSocket,
} from "viem";
import {
STABLES,
Expand Down Expand Up @@ -71,10 +72,18 @@ export async function createViemClient(
): Promise<ViemClient> {
const configuration = { rank: false, retryCount: 6 };
const urls = rpcs?.filter((v) => typeof v === "string") ?? [];
const topRpcs = urls.map((v) => http(v, { timeout }));
const topRpcs = urls.map((v) =>
v.startsWith("http")
? http(v, { timeout })
: webSocket(v, { timeout, keepAlive: true, reconnect: true }),
);
const fallbacks = (fallbackRpcs[chainId] ?? [])
.filter((v) => !urls.includes(v))
.map((v) => http(v, { timeout }));
.map((v) =>
v.startsWith("http")
? http(v, { timeout })
: webSocket(v, { timeout, keepAlive: true, reconnect: true }),
);
const transport = !topRpcs.length
? fallback(fallbacks, configuration)
: useFallbacks
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ export async function getConfig(
);
const watchClient = await createViemClient(
chainId,
rpcUrls,
options.publicRpc,
options.watchRpc,
false,
undefined,
options.timeout,
);
Expand Down Expand Up @@ -177,6 +177,7 @@ export async function getConfig(
config.watchClient = watchClient;
config.publicRpc = options.publicRpc;
config.walletKey = walletKey;
config.watchRpc = options.watchRpc;

// init accounts
const { mainAccount, accounts } = await initAccounts(walletKey, config, options, tracer, ctx);
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type CliOptions = {
key?: string;
mnemonic?: string;
rpc: string[];
watchRpc: string[];
writeRpc?: string[];
arbAddress: string;
genericArbAddress?: string;
Expand Down Expand Up @@ -148,6 +149,7 @@ export type BotConfig = {
key?: string;
mnemonic?: string;
rpc: string[];
watchRpc: string[];
writeRpc?: string[];
arbAddress: string;
genericArbAddress?: string;
Expand Down

0 comments on commit dae6ba3

Please sign in to comment.