Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Feb 20, 2025
1 parent c7f447b commit a4360fb
Show file tree
Hide file tree
Showing 8 changed files with 476 additions and 88 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ Other optional arguments are:
- `--generic-arb-address`, Address of the deployed generic arb contract to perform inter-orderbook clears, Will override the 'GENERIC_ARB_ADDRESS' in env variables
- `-l` or `--lps`, List of liquidity providers (dex) to use by the router as one quoted string seperated by a comma for each, example: 'SushiSwapV2,UniswapV3', Will override the 'LIQUIDITY_PROVIDERS' in env variables, if unset will use all available liquidty providers
- `-g` or `--gas-coverage`, The percentage of gas to cover to be considered profitable for the transaction to be submitted, an integer greater than equal 0, default is 100 meaning full coverage, Will override the 'GAS_COVER' in env variables
- `--orderbook-address`, Option to filter the subgraph query results with address of the deployed orderbook contract, Will override the 'ORDERBOOK_ADDRESS' in env variables
- `--order-hash`, Option to filter the subgraph query results with a specific order hash, Will override the 'ORDER_HASH' in env variables
- `--order-owner`, Option to filter the subgraph query results with a specific order owner address, Will override the 'ORDER_OWNER' in env variables
- `--include-orders`, Option to only include the specified orders for processing, Will override the 'INCLUDE_ORDERS' in env variables
- `--include-owners`, Option to only include the specified owners' orders for processing, Will override the 'INCLUDE_OWNERS' in env variables
- `--include-orderbooks`, Option to only include the specified orderbooks for processing, Will override the 'INCLUDE_ORDERBOOKS' in env variables
- `--exclude-orders`, Option to exclude the specified orders from processing, Will override the 'EXCLUDE_ORDERS' in env variables
- `--exclude-owners`, Option to exclude the specified owners' orders from processing, Will override the 'EXCLUDE_OWNERS' in env variables
- `--exclude-orderbooks`, Option to exclude the specified orderbooks from processing, Will override the 'EXCLUDE_ORDERBOOKS' in env variables
- `--sleep`, Seconds to wait between each arb round, default is 10, Will override the 'SLEEP' 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
Expand Down Expand Up @@ -197,9 +200,6 @@ ARB_ADDRESS="0x123..."
# generic arb contract address
GENERIC_ARB_ADDRESS="0x123..."

# Option to filter the subgraph query results with orderbook contract address
ORDERBOOK_ADDRESS="0x123..."

# one or more subgraph urls to read orders details from, can be used in combination with ORDERS
# for more than 1 subgraphs, seperate them by comma and a space
SUBGRAPH="https://api.thegraph.com/subgraphs/name/org1/sg1, https://api.thegraph.com/subgraphs/name/org2/sg2"
Expand Down Expand Up @@ -279,6 +279,14 @@ RP_ONLY="true"

# Address of dispair (ExpressionDeployer contract) to use for tasks
DISPAIR="address"

# Filters for inc/exc orders, multiple items can be separated by a comma
INCLUDE_ORDERS=
INCLUDE_OWNERS=
INCLUDE_ORDERBOOKS=
EXCLUDE_ORDERS=
EXCLUDE_OWNERS=
EXCLUDE_ORDERBOOKS=
```
If both env variables and CLI argument are set, the CLI arguments will be prioritized and override the env variables.

Expand Down
11 changes: 8 additions & 3 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ ARB_ADDRESS="0x123..."
# generic arb contract address
GENERIC_ARB_ADDRESS="0x123..."

# Option to filter the subgraph query results with orderbook contract address
ORDERBOOK_ADDRESS="0x123..."

# one or more subgraph urls to read orders details from, can be used in combination with ORDERS
# for more than 1 subgraphs, seperate them by comma and a space
SUBGRAPH="https://api.thegraph.com/subgraphs/name/org1/sg1, https://api.thegraph.com/subgraphs/name/org2/sg2"
Expand Down Expand Up @@ -103,6 +100,14 @@ RP_ONLY="true"
# Address of dispair (ExpressionDeployer contract) to use for tasks
DISPAIR="address"

# Filters for inc/exc orders, multiple items can be separated by a comma
INCLUDE_ORDERS=
INCLUDE_OWNERS=
INCLUDE_ORDERBOOKS=
EXCLUDE_ORDERS=
EXCLUDE_OWNERS=
EXCLUDE_ORDERBOOKS=


# test rpcs vars
TEST_POLYGON_RPC=
Expand Down
129 changes: 99 additions & 30 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ const ENV_OPTIONS = {
mnemonic: process?.env?.MNEMONIC,
arbAddress: process?.env?.ARB_ADDRESS,
genericArbAddress: process?.env?.GENERIC_ARB_ADDRESS,
orderbookAddress: process?.env?.ORDERBOOK_ADDRESS,
lps: process?.env?.LIQUIDITY_PROVIDERS,
gasCoverage: process?.env?.GAS_COVER || "100",
orderHash: process?.env?.ORDER_HASH,
orderOwner: process?.env?.ORDER_OWNER,
sleep: process?.env?.SLEEP,
maxRatio: process?.env?.MAX_RATIO?.toLowerCase() === "true" ? true : false,
publicRpc: process?.env?.PUBLIC_RPC?.toLowerCase() === "true" ? true : false,
Expand All @@ -85,18 +82,16 @@ const ENV_OPTIONS = {
route: process?.env?.ROUTE,
dispair: process?.env?.DISPAIR,
rpOnly: process?.env?.RP_ONLY?.toLowerCase() === "true" ? true : false,
ownerProfile: process?.env?.OWNER_PROFILE
? Array.from(process?.env?.OWNER_PROFILE.matchAll(/[^,\s]+/g)).map((v) => v[0])
: undefined,
rpc: process?.env?.RPC_URL
? Array.from(process?.env?.RPC_URL.matchAll(/[^,\s]+/g)).map((v) => v[0])
: undefined,
writeRpc: process?.env?.WRITE_RPC
? Array.from(process?.env?.WRITE_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,
ownerProfile: parseArrayFromEnv(process?.env?.OWNER_PROFILE),
rpc: parseArrayFromEnv(process?.env?.RPC_URL),
writeRpc: parseArrayFromEnv(process?.env?.WRITE_RPC),
subgraph: parseArrayFromEnv(process?.env?.SUBGRAPH),
includeOrders: parseArrayFromEnv(process?.env?.INCLUDE_ORDERS),
includeOwners: parseArrayFromEnv(process?.env?.INCLUDE_OWNERS),
includeOrderbooks: parseArrayFromEnv(process?.env?.INCLUDE_ORDERBOOKS),
excludeOrders: parseArrayFromEnv(process?.env?.EXCLUDE_ORDERS),
excludeOwners: parseArrayFromEnv(process?.env?.EXCLUDE_OWNERS),
excludeOrderbooks: parseArrayFromEnv(process?.env?.EXCLUDE_ORDERBOOKS),
};

const getOptions = async (argv: any, version?: string) => {
Expand All @@ -117,10 +112,6 @@ const getOptions = async (argv: any, version?: string) => {
"-s, --subgraph <url...>",
"Subgraph URL(s) to read orders details from, can be used in combination with --orders, Will override the 'SUBGRAPH' in env variables",
)
.option(
"--orderbook-address <address>",
"Option to filter the subgraph query results with address of the deployed orderbook contract, Will override the 'ORDERBOOK_ADDRESS' in env variables",
)
.option(
"--arb-address <address>",
"Address of the deployed arb contract, Will override the 'ARB_ADDRESS' in env variables",
Expand All @@ -142,12 +133,28 @@ const getOptions = async (argv: any, version?: string) => {
"The percentage of gas to cover to be considered profitable for the transaction to be submitted, an integer greater than equal 0, default is 100 meaning full coverage, Will override the 'GAS_COVER' in env variables",
)
.option(
"--order-hash <hash>",
"Option to filter the subgraph query results with a specific order hash, Will override the 'ORDER_HASH' in env variables",
"--include-orders <orderhash...>",
"Option to only include the specified orders for processing, Will override the 'INCLUDE_ORDERS' in env variables",
)
.option(
"--include-owners <address...>",
"Option to only include the specified owners' orders for processing, Will override the 'INCLUDE_OWNERS' in env variables",
)
.option(
"--include-orderbooks <address...>",
"Option to only include the specified orderbooks for processing, Will override the 'INCLUDE_ORDERBOOKS' in env variables",
)
.option(
"--exclude-orders <orderhash...>",
"Option to exclude the specified orders from processing, Will override the 'EXCLUDE_ORDERS' in env variables",
)
.option(
"--order-owner <address>",
"Option to filter the subgraph query results with a specific order owner address, Will override the 'ORDER_OWNER' in env variables",
"--exclude-owners <address...>",
"Option to exclude the specified owners' orders from processing, Will override the 'EXCLUDE_OWNERS' in env variables",
)
.option(
"--exclude-orderbooks <address...>",
"Option to exclude the specified orderbooks from processing, Will override the 'EXCLUDE_ORDERBOOKS' in env variables",
)
.option(
"--sleep <integer>",
Expand Down Expand Up @@ -245,13 +252,17 @@ const getOptions = async (argv: any, version?: string) => {
cmdOptions.arbAddress = cmdOptions.arbAddress || getEnv(ENV_OPTIONS.arbAddress);
cmdOptions.genericArbAddress =
cmdOptions.genericArbAddress || getEnv(ENV_OPTIONS.genericArbAddress);
cmdOptions.orderbookAddress =
cmdOptions.orderbookAddress || getEnv(ENV_OPTIONS.orderbookAddress);
cmdOptions.subgraph = cmdOptions.subgraph || getEnv(ENV_OPTIONS.subgraph);
cmdOptions.lps = cmdOptions.lps || getEnv(ENV_OPTIONS.lps);
cmdOptions.gasCoverage = cmdOptions.gasCoverage || getEnv(ENV_OPTIONS.gasCoverage);
cmdOptions.orderHash = cmdOptions.orderHash || getEnv(ENV_OPTIONS.orderHash);
cmdOptions.orderOwner = cmdOptions.orderOwner || getEnv(ENV_OPTIONS.orderOwner);
cmdOptions.includeOrders = cmdOptions.includeOrders || getEnv(ENV_OPTIONS.includeOrders);
cmdOptions.includeOwners = cmdOptions.includeOwners || getEnv(ENV_OPTIONS.includeOwners);
cmdOptions.includeOrderbooks =
cmdOptions.includeOrderbooks || getEnv(ENV_OPTIONS.includeOrderbooks);
cmdOptions.excludeOrders = cmdOptions.excludeOrders || getEnv(ENV_OPTIONS.excludeOrders);
cmdOptions.excludeOwners = cmdOptions.excludeOwners || getEnv(ENV_OPTIONS.excludeOwners);
cmdOptions.excludeOrderbooks =
cmdOptions.excludeOrderbooks || getEnv(ENV_OPTIONS.excludeOrderbooks);
cmdOptions.sleep = cmdOptions.sleep || getEnv(ENV_OPTIONS.sleep);
cmdOptions.maxRatio = cmdOptions.maxRatio || getEnv(ENV_OPTIONS.maxRatio);
cmdOptions.timeout = cmdOptions.timeout || getEnv(ENV_OPTIONS.timeout);
Expand Down Expand Up @@ -316,6 +327,54 @@ const getOptions = async (argv: any, version?: string) => {
};
});
}
if (cmdOptions.includeOrders) {
cmdOptions.includeOrders = cmdOptions.includeOrders.map((v: string) => {
if (!/^(0x)?[a-fA-F0-9]{64}$/.test(v)) {
throw `${v} is not a valid order hash`;
}
return v.toLowerCase();
});
}
if (cmdOptions.excludeOrders) {
cmdOptions.excludeOrders = cmdOptions.excludeOrders.map((v: string) => {
if (!/^(0x)?[a-fA-F0-9]{64}$/.test(v)) {
throw `${v} is not a valid order hash`;
}
return v.toLowerCase();
});
}
if (cmdOptions.includeOwners) {
cmdOptions.includeOwners = cmdOptions.includeOwners.map((v: string) => {
if (!ethers.utils.isAddress(v)) {
throw `${v} is not a valid address`;
}
return v.toLowerCase();
});
}
if (cmdOptions.excludeOwners) {
cmdOptions.excludeOwners = cmdOptions.excludeOwners.map((v: string) => {
if (!ethers.utils.isAddress(v)) {
throw `${v} is not a valid address`;
}
return v.toLowerCase();
});
}
if (cmdOptions.includeOrderbooks) {
cmdOptions.includeOrderbooks = cmdOptions.includeOrderbooks.map((v: string) => {
if (!ethers.utils.isAddress(v)) {
throw `${v} is not a valid address`;
}
return v.toLowerCase();
});
}
if (cmdOptions.excludeOrderbooks) {
cmdOptions.excludeOrderbooks = cmdOptions.excludeOrderbooks.map((v: string) => {
if (!ethers.utils.isAddress(v)) {
throw `${v} is not a valid address`;
}
return v.toLowerCase();
});
}
return cmdOptions;
};

Expand Down Expand Up @@ -402,6 +461,9 @@ export async function startup(argv: any, version?: string, tracer?: Tracer, ctx?
throw "undefined wallet, only one of key or mnemonic should be specified";
}
if (options.mnemonic) {
if (!ethers.utils.isValidMnemonic(options.mnemonic)) {
throw "provided mnemonic key is not valid";
}
if (!options.walletCount || !options.topupAmount) {
throw "--wallet-count and --toptup-amount are required when using mnemonic option";
}
Expand Down Expand Up @@ -505,9 +567,12 @@ export async function startup(argv: any, version?: string, tracer?: Tracer, ctx?
for (let i = 0; i < 3; i++) {
try {
ordersDetails = await getOrderDetails(options.subgraph, {
orderHash: options.orderHash,
orderOwner: options.orderOwner,
orderbook: options.orderbookAddress,
includeOrders: options.includeOrders,
includeOwners: options.includeOwners,
excludeOrders: options.excludeOrders,
excludeOwners: options.excludeOwners,
includeOrderbooks: options.includeOrderbooks,
excludeOrderbooks: options.excludeOrderbooks,
});
break;
} catch (e) {
Expand Down Expand Up @@ -949,3 +1014,7 @@ function getEnv(value: any): any {
}
return undefined;
}

function parseArrayFromEnv(value?: string): string[] | undefined {
return value ? Array.from(value.matchAll(/[^,\s]+/g)).map((v) => v[0]) : undefined;
}
10 changes: 1 addition & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,7 @@ export async function getOrderDetails(
({ availableSgs } = checkSgStatus(validSgs, statusResult, span, hasjson));

availableSgs.forEach((v) => {
if (v && typeof v === "string")
promises.push(
querySgOrders(
v,
sgFilters?.orderHash,
sgFilters?.orderOwner,
sgFilters?.orderbook,
),
);
if (v && typeof v === "string") promises.push(querySgOrders(v, sgFilters));
});
}

Expand Down
Loading

0 comments on commit a4360fb

Please sign in to comment.