Skip to content

Commit

Permalink
Merge pull request #169 from rainlanguage/2024-07-23-update-sg-query
Browse files Browse the repository at this point in the history
update sg query
  • Loading branch information
rouzwelt authored Jul 23, 2024
2 parents e1f2fb5 + c9ac1ac commit f67322e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 58 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ This app requires NodeJS v18 or higher to run and is docker ready.
This app can also be run in Github Actions with a cron job, please read below for more details.

## The Case for Profitability
Profitablity can be adjusted by using an integer ≥0 for `--gas-coverage` as the percentage of the gas cost of the transaction, denominated in receiving ERC20 token, the cost of the transaction is calculated in the receiving ERC20 token unit with current market best price.
Profitablity can be adjusted by using an integer ≥0 for `--gas-coverage` arg as the percentage of the gas cost of the transaction, denominated in receiving ERC20 token, the cost of the transaction is calculated in the receiving ERC20 token unit with current market price of that token against chain's native token.

- If set to 100, the receiving profit must be at least equal or greater than gas cost.
- If set above 100, the receiving profit must be more than the amount of gas cost, for example a transaction costs 0.01 USDT (calculated from network's gas token i.e. ETH to receiving ERC20 token i.e. USDT or USDC or ...) and a value of 500 means the profit must be at least 5x the amount of gas used i.e. ≥0.05 USDT for the transaction to be successfull.
for example:
- If set to 100, the receiving profit must be at least equal or greater than tx gas cost.
- If set above 100, the receiving profit must be more than the amount of gas cost, for example a transaction costs 0.01 USDT (calculated by current market price of ETH/USDT) and a value of 500 means the profit must be at least 5x the amount of gas used i.e. ≥0.05 USDT for the transaction to be successfull, so at least 0.04 USDT profit will be guaranteed.
- If set to 0, profitablity becomes irrevelant meaning any match will be submitted irrespective of whether or not the transaction will be profitable.

## Tutorial
Expand Down Expand Up @@ -71,7 +72,6 @@ Other optional arguments are:
- `--repetitions`, Option to run `number` of times, if unset will run for infinte number of times
- `--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
- `--order-interpreter`, Option to filter the subgraph query results with a specific order's interpreter address, Will override the 'ORDER_INTERPRETER' in env variables
- `--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
Expand Down Expand Up @@ -180,9 +180,6 @@ ORDER_HASH=""
# Option to filter the subgraph query results with a specific order owner address
ORDER_OWNER=""

# Option to filter the subgraph query results with a specific order interpreter address
ORDER_INTERPRETER=""

# Seconds to wait between each arb round, default is 10, Will override the 'SLEPP' in env variables
SLEEP=10

Expand Down Expand Up @@ -249,7 +246,7 @@ const subgraphs = ["https://api.thegraph.com/subgraphs/name/xxx/yyy"] // arr
const sgFilters = { // filters for subgraph query (each filter is optional)
orderHash : "0x1234...",
orderOwner : "0x1234...",
orderInterpreter : "0x1234..."
orderbook : "0x1234..."
}

// get the order details from the sources
Expand Down
9 changes: 3 additions & 6 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const ENV_OPTIONS = {
repetitions : process?.env?.REPETITIONS,
orderHash : process?.env?.ORDER_HASH,
orderOwner : process?.env?.ORDER_OWNER,
orderInterpreter : process?.env?.ORDER_INTERPRETER,
sleep : process?.env?.SLEEP,
maxRatio : process?.env?.MAX_RATIO?.toLowerCase() === "true" ? true : false,
bundle : process?.env?.NO_BUNDLE?.toLowerCase() === "true" ? false : true,
Expand Down Expand Up @@ -55,7 +54,6 @@ const getOptions = async argv => {
.option("--repetitions <integer>", "Option to run `number` of times, if unset will run for infinte number of times")
.option("--order-hash <hash>", "Option to filter the subgraph query results with a specific order hash, Will override the 'ORDER_HASH' 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")
.option("--order-interpreter <address>", "Option to filter the subgraph query results with a specific order's interpreter address, Will override the 'ORDER_INTERPRETER' in env variables")
.option("--sleep <integer>", "Seconds to wait between each arb round, default is 10, Will override the 'SLEPP' in env variables")
.option("--flashbot-rpc <url>", "Optional flashbot rpc url to submit transaction to, Will override the 'FLASHBOT_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 @@ -87,7 +85,6 @@ const getOptions = async argv => {
cmdOptions.orderHash = cmdOptions.orderHash || ENV_OPTIONS.orderHash;
cmdOptions.orderOwner = cmdOptions.orderOwner || ENV_OPTIONS.orderOwner;
cmdOptions.sleep = cmdOptions.sleep || ENV_OPTIONS.sleep;
cmdOptions.orderInterpreter = cmdOptions.orderInterpreter || ENV_OPTIONS.orderInterpreter;
cmdOptions.maxRatio = cmdOptions.maxRatio || ENV_OPTIONS.maxRatio;
cmdOptions.flashbotRpc = cmdOptions.flashbotRpc || ENV_OPTIONS.flashbotRpc;
cmdOptions.timeout = cmdOptions.timeout || ENV_OPTIONS.timeout;
Expand Down Expand Up @@ -139,9 +136,9 @@ const arbRound = async (tracer, roundCtx, options) => {
options.orders,
config.signer,
{
orderHash : options.orderHash,
orderOwner : options.orderOwner,
orderInterpreter: options.orderInterpreter
orderHash: options.orderHash,
orderOwner: options.orderOwner,
orderbook: options.orderbookAddress,
},
span
);
Expand Down
3 changes: 0 additions & 3 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ ORDER_HASH=""
# Option to filter the subgraph query results with a specific order owner address
ORDER_OWNER=""

# Option to filter the subgraph query results with a specific order interpreter address
ORDER_INTERPRETER=""

# Seconds to wait between each arb round, default is 10, Will override the 'SLEPP' in env variables
SLEEP=10

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const getOrderDetails = async(sgs, json, signer, sgFilters, span) => {
query: getQuery(
sgFilters?.orderHash,
sgFilters?.orderOwner,
sgFilters?.orderInterpreter
sgFilters?.orderbook
)
},
{ headers: { "Content-Type": "application/json" } }
Expand Down
44 changes: 4 additions & 40 deletions src/query.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,15 @@
/**
* The default query used in the matchmaker bot to fetch the orders from subgraph
*/
const DefaultQuery = `{
orders(where: {active: true}) {
id
owner
orderHash
orderBytes
active
nonce
inputs {
id
balance
vaultId
token {
address
decimals
name
symbol
}
}
outputs {
id
balance
vaultId
token {
address
decimals
name
symbol
}
}
}
}`;

/**
* Method to get the subgraph query body with optional filters
* @param {string} orderHash - The order hash to apply as filter
* @param {string} owner - The order owner to apply as filter
* @param {string} orderbook - The orderbook address
* @returns the query string
*/
const getQuery = (orderHash, owner) => {
const getQuery = (orderHash, owner, orderbook) => {
const ownerFilter = owner ? `, owner :"${owner.toLowerCase()}"` : "";
const orderHashFilter = orderHash ? `, orderHash :"${orderHash.toLowerCase()}"` : "";
return `{
orders(where: {active: true${orderHashFilter}${ownerFilter}}) {
orders(where: {active: true, orderbook: "${orderbook.toLowerCase()}"${orderHashFilter}${ownerFilter}}) {
id
owner
orderHash
Expand Down Expand Up @@ -82,7 +47,6 @@ const statusCheckQuery = `{
}`;

module.exports = {
DefaultQuery,
getQuery,
statusCheckQuery
};
};

0 comments on commit f67322e

Please sign in to comment.